summaryrefslogtreecommitdiffstats
path: root/llvm/utils/TableGen/GlobalISelEmitter.cpp
diff options
context:
space:
mode:
authorDaniel Sanders <daniel_l_sanders@apple.com>2017-07-26 10:20:56 +0000
committerDaniel Sanders <daniel_l_sanders@apple.com>2017-07-26 10:20:56 +0000
commitd83817ad6e10e0a4aba10ae7952dd23dd44f0370 (patch)
tree91fd0c4c80ee0dd199f10daaa16ad3c8b9633d08 /llvm/utils/TableGen/GlobalISelEmitter.cpp
parentddf407dec907a80affaa2b989312ee4d4f10d5ea (diff)
downloadbcm5719-llvm-d83817ad6e10e0a4aba10ae7952dd23dd44f0370.tar.gz
bcm5719-llvm-d83817ad6e10e0a4aba10ae7952dd23dd44f0370.zip
[globalisel][tablegen] Fuse the generated tables together.
Summary: Now that we have control flow in place, fuse the per-rule tables into a single table. This is a compile-time saving at this point. However, this will also enable the optimization of a table so that similar instructions can be tested together, reducing the time spent on the matching the code. This is NFC in terms of externally visible behaviour but some internals have changed slightly. State.MIs is no longer reset between each rule that is attempted because it's not necessary to do so. As a consequence of this the restriction on the order that instructions are added to State.MIs has been relaxed to only affect recorded instructions that require new elements to be added to the vector. GIM_RecordInsn can now write to any element from 1 to State.MIs.size() instead of just State.MIs.size(). Reviewers: ab, t.p.northover, qcolombet, rovka, aditya_nandakumar Reviewed By: rovka Subscribers: kristof.beyls, igorb, llvm-commits Differential Revision: https://reviews.llvm.org/D35681 llvm-svn: 309094
Diffstat (limited to 'llvm/utils/TableGen/GlobalISelEmitter.cpp')
-rw-r--r--llvm/utils/TableGen/GlobalISelEmitter.cpp54
1 files changed, 26 insertions, 28 deletions
diff --git a/llvm/utils/TableGen/GlobalISelEmitter.cpp b/llvm/utils/TableGen/GlobalISelEmitter.cpp
index 2cfcadd5e80..47f974ac5ed 100644
--- a/llvm/utils/TableGen/GlobalISelEmitter.cpp
+++ b/llvm/utils/TableGen/GlobalISelEmitter.cpp
@@ -53,8 +53,6 @@ STATISTIC(NumPatternTotal, "Total number of patterns");
STATISTIC(NumPatternImported, "Number of patterns imported from SelectionDAG");
STATISTIC(NumPatternImportsSkipped, "Number of SelectionDAG imports skipped");
STATISTIC(NumPatternEmitted, "Number of patterns emitted");
-/// A unique identifier for a MatchTable.
-static unsigned CurrentMatchTableID = 0;
cl::OptionCategory GlobalISelEmitterCat("Options for -gen-global-isel");
@@ -303,6 +301,9 @@ class MatchTable {
/// Tracks the sum of MatchTableRecord::NumElements as the table is built.
unsigned CurrentSize;
+ /// A unique identifier for a MatchTable label.
+ static unsigned CurrentLabelID;
+
public:
static MatchTableRecord LineBreak;
static MatchTableRecord Comment(StringRef Comment) {
@@ -338,7 +339,7 @@ public:
MatchTableRecord::MTRF_LineBreakFollows);
}
static MatchTableRecord JumpTarget(unsigned LabelID) {
- return MatchTableRecord(LabelID, "Label " + llvm::to_string(LabelID), 0,
+ return MatchTableRecord(LabelID, "Label " + llvm::to_string(LabelID), 1,
MatchTableRecord::MTRF_JumpTarget |
MatchTableRecord::MTRF_Comment |
MatchTableRecord::MTRF_CommaFollows);
@@ -353,8 +354,10 @@ public:
CurrentSize += Value.size();
}
+ unsigned allocateLabelID() const { return CurrentLabelID++; }
+
void defineLabel(unsigned LabelID) {
- LabelMap.insert(std::make_pair(LabelID, CurrentSize + 1));
+ LabelMap.insert(std::make_pair(LabelID, CurrentSize));
}
unsigned getLabelIndex(unsigned LabelID) const {
@@ -363,7 +366,9 @@ public:
return I->second;
}
- void emit(raw_ostream &OS) const {
+ void emitUse(raw_ostream &OS) const { OS << "MatchTable" << ID; }
+
+ void emitDeclaration(raw_ostream &OS) const {
unsigned Indentation = 4;
OS << " const static int64_t MatchTable" << ID << "[] = {";
LineBreak.emit(OS, true, *this);
@@ -394,6 +399,8 @@ public:
}
};
+unsigned MatchTable::CurrentLabelID = 0;
+
MatchTableRecord MatchTable::LineBreak = {
None, "" /* Emit String */, 0 /* Elements */,
MatchTableRecord::MTRF_LineBreakFollows};
@@ -436,11 +443,6 @@ MatchTable &operator<<(MatchTable &Table, const MatchTableRecord &Value) {
return Table;
}
-raw_ostream &operator<<(raw_ostream &OS, const MatchTable &Table) {
- Table.emit(OS);
- return OS;
-}
-
//===- Matchers -----------------------------------------------------------===//
class OperandMatcher;
@@ -489,7 +491,7 @@ public:
void emitCaptureOpcodes(MatchTable &Table);
- void emit(raw_ostream &OS);
+ void emit(MatchTable &Table);
/// Compare the priority of this object and B.
///
@@ -1548,7 +1550,7 @@ void RuleMatcher::emitCaptureOpcodes(MatchTable &Table) {
Matchers.front()->emitCaptureOpcodes(Table, *this, InsnVarID);
}
-void RuleMatcher::emit(raw_ostream &OS) {
+void RuleMatcher::emit(MatchTable &Table) {
if (Matchers.empty())
llvm_unreachable("Unexpected empty matcher!");
@@ -1563,9 +1565,9 @@ void RuleMatcher::emit(raw_ostream &OS) {
// on some targets but we don't need to make use of that yet.
assert(Matchers.size() == 1 && "Cannot handle multi-root matchers yet");
- MatchTable Table(CurrentMatchTableID);
+ unsigned LabelID = Table.allocateLabelID();
Table << MatchTable::Opcode("GIM_Try", +1)
- << MatchTable::Comment("On fail goto") << MatchTable::JumpTarget(0)
+ << MatchTable::Comment("On fail goto") << MatchTable::JumpTarget(LabelID)
<< MatchTable::LineBreak;
if (!RequiredFeatures.empty()) {
@@ -1639,16 +1641,7 @@ void RuleMatcher::emit(raw_ostream &OS) {
for (const auto &MA : Actions)
MA->emitActionOpcodes(Table, *this, 0);
Table << MatchTable::Opcode("GIR_Done", -1) << MatchTable::LineBreak
- << MatchTable::Label(0) << MatchTable::Opcode("GIM_Reject")
- << MatchTable::LineBreak;
- OS << Table
- << " State.MIs.resize(1);\n"
- << " DEBUG(dbgs() << \"Processing MatchTable" << CurrentMatchTableID
- << "\\n\");\n"
- << " if (executeMatchTable(*this, OutMIs, State, MatcherInfo, MatchTable"
- << CurrentMatchTableID << ", TII, MRI, TRI, RBI, AvailableFeatures)) {\n"
- << " return true;\n"
- << " }\n\n";
+ << MatchTable::Label(LabelID);
}
bool RuleMatcher::isHigherPriorityThan(const RuleMatcher &B) const {
@@ -2498,13 +2491,18 @@ void GlobalISelEmitter::run(raw_ostream &OS) {
<< " State.MIs.clear();\n"
<< " State.MIs.push_back(&I);\n\n";
+ MatchTable Table(0);
for (auto &Rule : Rules) {
- Rule.emit(OS);
- ++CurrentMatchTableID;
+ Rule.emit(Table);
++NumPatternEmitted;
- assert(CurrentMatchTableID == NumPatternEmitted &&
- "Statistic deviates from number of emitted tables");
}
+ Table << MatchTable::Opcode("GIM_Reject") << MatchTable::LineBreak;
+ Table.emitDeclaration(OS);
+ OS << " if (executeMatchTable(*this, OutMIs, State, MatcherInfo, ";
+ Table.emitUse(OS);
+ OS << ", TII, MRI, TRI, RBI, AvailableFeatures)) {\n"
+ << " return true;\n"
+ << " }\n\n";
OS << " return false;\n"
<< "}\n"
OpenPOWER on IntegriCloud