eliminate the CheckMultiOpcodeMatcher code and have each
ComplexPattern at the root be generated multiple times, once
for each opcode they are part of. This encourages factoring
because the opcode checks get treated just like everything
else in the matcher.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97439 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/utils/TableGen/DAGISelMatcherGen.cpp b/utils/TableGen/DAGISelMatcherGen.cpp
index 5a253e8..95cfa5b 100644
--- a/utils/TableGen/DAGISelMatcherGen.cpp
+++ b/utils/TableGen/DAGISelMatcherGen.cpp
@@ -97,7 +97,7 @@
delete PatWithNoTypes;
}
- void EmitMatcherCode();
+ bool EmitMatcherCode(unsigned Variant);
void EmitResultCode();
Matcher *GetMatcher() const { return TheMatcher; }
@@ -247,20 +247,6 @@
// Handle complex pattern.
const ComplexPattern &CP = CGP.getComplexPattern(LeafRec);
-
- // If we're at the root of the pattern, we have to check that the opcode
- // is a one of the ones requested to be matched.
- if (N == Pattern.getSrcPattern()) {
- const std::vector<Record*> &OpNodes = CP.getRootNodes();
- if (OpNodes.size() == 1) {
- AddMatcher(new CheckOpcodeMatcher(CGP.getSDNodeInfo(OpNodes[0])));
- } else if (!OpNodes.empty()) {
- SmallVector<const SDNodeInfo*, 4> OpNames;
- for (unsigned i = 0, e = OpNodes.size(); i != e; i++)
- OpNames.push_back(&CGP.getSDNodeInfo(OpNodes[i]));
- AddMatcher(new CheckMultiOpcodeMatcher(OpNames.data(), OpNames.size()));
- }
- }
// Emit a CheckComplexPat operation, which does the match (aborting if it
// fails) and pushes the matched operands onto the recorded nodes list.
@@ -495,7 +481,30 @@
EmitOperatorMatchCode(N, NodeNoTypes);
}
-void MatcherGen::EmitMatcherCode() {
+/// EmitMatcherCode - Generate the code that matches the predicate of this
+/// pattern for the specified Variant. If the variant is invalid this returns
+/// true and does not generate code, if it is valid, it returns false.
+bool MatcherGen::EmitMatcherCode(unsigned Variant) {
+ // If the root of the pattern is a ComplexPattern and if it is specified to
+ // match some number of root opcodes, these are considered to be our variants.
+ // Depending on which variant we're generating code for, emit the root opcode
+ // check.
+ if (const ComplexPattern *CP =
+ Pattern.getSrcPattern()->getComplexPatternInfo(CGP)) {
+
+ const std::vector<Record*> &OpNodes = CP->getRootNodes();
+ if (OpNodes.empty()) {
+ // FIXME: Empty OpNodes runs on everything, is this even valid?
+ if (Variant != 0) return true;
+ } else {
+ if (Variant >= OpNodes.size()) return true;
+
+ AddMatcher(new CheckOpcodeMatcher(CGP.getSDNodeInfo(OpNodes[Variant])));
+ }
+ } else {
+ if (Variant != 0) return true;
+ }
+
// If the pattern has a predicate on it (e.g. only enabled when a subtarget
// feature is around, do the check).
// FIXME: This should get emitted after the match code below to encourage
@@ -503,11 +512,11 @@
// dag combine, eliminating the horrible side-effect-full stuff from
// X86's MatchAddress.
if (!Pattern.getPredicateCheck().empty())
- AddMatcher(new
- CheckPatternPredicateMatcher(Pattern.getPredicateCheck()));
-
+ AddMatcher(new CheckPatternPredicateMatcher(Pattern.getPredicateCheck()));
+
// Emit the matcher for the pattern structure and types.
EmitMatchCode(Pattern.getSrcPattern(), PatWithNoTypes);
+ return false;
}
@@ -849,13 +858,16 @@
}
+/// ConvertPatternToMatcher - Create the matcher for the specified pattern with
+/// the specified variant. If the variant number is invalid, this returns null.
Matcher *llvm::ConvertPatternToMatcher(const PatternToMatch &Pattern,
+ unsigned Variant,
const CodeGenDAGPatterns &CGP) {
MatcherGen Gen(Pattern, CGP);
// Generate the code for the matcher.
- Gen.EmitMatcherCode();
-
+ if (Gen.EmitMatcherCode(Variant))
+ return 0;
// FIXME2: Kill extra MoveParent commands at the end of the matcher sequence.
// FIXME2: Split result code out to another table, and make the matcher end