[llvm] r331396 - [GlobalISel][InstructionSelect] Refactoring buildMatchTable out, NFC
Roman Tereshin via llvm-commits
llvm-commits at lists.llvm.org
Wed May 2 13:08:14 PDT 2018
Author: rtereshin
Date: Wed May 2 13:08:14 2018
New Revision: 331396
URL: http://llvm.org/viewvc/llvm-project?rev=331396&view=rev
Log:
[GlobalISel][InstructionSelect] Refactoring buildMatchTable out, NFC
to share it between the Instruction Selector in optimized and
non-optimized modes both and the Testgen.
Reviewers: dsanders, aemerson
Reviewed By: dsanders
Subscribers: rovka, kristof.beyls, llvm-commits, dsanders
Differential Revision: https://reviews.llvm.org/D46097
Modified:
llvm/trunk/utils/TableGen/GlobalISelEmitter.cpp
Modified: llvm/trunk/utils/TableGen/GlobalISelEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/GlobalISelEmitter.cpp?rev=331396&r1=331395&r2=331396&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/GlobalISelEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/GlobalISelEmitter.cpp Wed May 2 13:08:14 2018
@@ -407,6 +407,8 @@ public:
unsigned size() const { return NumElements; }
};
+class Matcher;
+
/// Holds the contents of a generated MatchTable to enable formatting and the
/// necessary index tracking needed to support GIM_Try.
class MatchTable {
@@ -419,10 +421,9 @@ class MatchTable {
/// The currently defined labels.
DenseMap<unsigned, unsigned> LabelMap;
/// Tracks the sum of MatchTableRecord::NumElements as the table is built.
- unsigned CurrentSize;
-
+ unsigned CurrentSize = 0;
/// A unique identifier for a MatchTable label.
- static unsigned CurrentLabelID;
+ unsigned CurrentLabelID = 0;
public:
static MatchTableRecord LineBreak;
@@ -465,7 +466,9 @@ public:
MatchTableRecord::MTRF_CommaFollows);
}
- MatchTable(unsigned ID) : ID(ID), CurrentSize(0) {}
+ static MatchTable buildTable(ArrayRef<Matcher *> Rules);
+
+ MatchTable(unsigned ID = 0) : ID(ID) {}
void push_back(const MatchTableRecord &Value) {
if (Value.Flags & MatchTableRecord::MTRF_Label)
@@ -474,7 +477,7 @@ public:
CurrentSize += Value.size();
}
- unsigned allocateLabelID() const { return CurrentLabelID++; }
+ unsigned allocateLabelID() { return CurrentLabelID++; }
void defineLabel(unsigned LabelID) {
LabelMap.insert(std::make_pair(LabelID, CurrentSize));
@@ -519,8 +522,6 @@ public:
}
};
-unsigned MatchTable::CurrentLabelID = 0;
-
MatchTableRecord MatchTable::LineBreak = {
None, "" /* Emit String */, 0 /* Elements */,
MatchTableRecord::MTRF_LineBreakFollows};
@@ -577,6 +578,14 @@ public:
virtual std::unique_ptr<PredicateMatcher> forgetFirstCondition() = 0;
};
+MatchTable MatchTable::buildTable(ArrayRef<Matcher *> Rules) {
+ MatchTable Table;
+ for (Matcher *Rule : Rules)
+ Rule->emit(Table);
+
+ return Table << MatchTable::Opcode("GIM_Reject") << MatchTable::LineBreak;
+}
+
class GroupMatcher : public Matcher {
SmallVector<std::unique_ptr<PredicateMatcher>, 8> Conditions;
SmallVector<Matcher *, 8> Rules;
@@ -2686,8 +2695,10 @@ private:
/// # predicate C
/// \endverbatim
std::vector<Matcher *> optimizeRules(
- const std::vector<Matcher *> &Rules,
+ ArrayRef<Matcher *> Rules,
std::vector<std::unique_ptr<GroupMatcher>> &StorageGroupMatcher);
+
+ MatchTable buildMatchTable(MutableArrayRef<RuleMatcher> Rules, bool Optimize);
};
void GlobalISelEmitter::gatherNodeEquivs() {
@@ -3644,7 +3655,7 @@ void GlobalISelEmitter::emitImmPredicate
}
std::vector<Matcher *> GlobalISelEmitter::optimizeRules(
- const std::vector<Matcher *> &Rules,
+ ArrayRef<Matcher *> Rules,
std::vector<std::unique_ptr<GroupMatcher>> &StorageGroupMatcher) {
std::vector<Matcher *> OptRules;
// Start with a stupid grouping for now.
@@ -3675,6 +3686,23 @@ std::vector<Matcher *> GlobalISelEmitter
return OptRules;
}
+MatchTable
+GlobalISelEmitter::buildMatchTable(MutableArrayRef<RuleMatcher> Rules,
+ bool Optimize) {
+ std::vector<Matcher *> InputRules;
+ for (Matcher &Rule : Rules)
+ InputRules.push_back(&Rule);
+
+ if (!Optimize)
+ return MatchTable::buildTable(InputRules);
+
+ std::vector<std::unique_ptr<GroupMatcher>> StorageGroupMatcher;
+ std::vector<Matcher *> OptRules =
+ optimizeRules(InputRules, StorageGroupMatcher);
+
+ return MatchTable::buildTable(OptRules);
+}
+
void GlobalISelEmitter::run(raw_ostream &OS) {
if (!UseCoverageFile.empty()) {
RuleCoverage = CodeGenCoverage();
@@ -3941,21 +3969,6 @@ void GlobalISelEmitter::run(raw_ostream
}
return false;
});
- std::vector<std::unique_ptr<GroupMatcher>> StorageGroupMatcher;
-
- std::vector<Matcher *> InputRules;
- for (Matcher &Rule : Rules)
- InputRules.push_back(&Rule);
-
- std::vector<Matcher *> OptRules =
- OptimizeMatchTable ? optimizeRules(InputRules, StorageGroupMatcher)
- : InputRules;
-
- MatchTable Table(0);
- for (Matcher *Rule : OptRules)
- Rule->emit(Table);
-
- Table << MatchTable::Opcode("GIM_Reject") << MatchTable::LineBreak;
OS << "bool " << Target.getName()
<< "InstructionSelector::selectImpl(MachineInstr &I, CodeGenCoverage "
@@ -3978,6 +3991,7 @@ void GlobalISelEmitter::run(raw_ostream
<< " return false;\n"
<< "}\n\n";
+ const MatchTable Table = buildMatchTable(Rules, OptimizeMatchTable);
OS << "const int64_t *" << Target.getName()
<< "InstructionSelector::getMatchTable() const {\n";
Table.emitDeclaration(OS);
More information about the llvm-commits
mailing list