diff options
author | Chris Lattner <sabre@nondot.org> | 2010-02-17 00:31:50 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-02-17 00:31:50 +0000 |
commit | e609a513f3c072bba28412c681465332a2822d9a (patch) | |
tree | d3e4bb34b61b2a87e23001c2a1740d6816900f43 /utils/TableGen/DAGISelMatcherEmitter.cpp | |
parent | 9abe19d0b9b36dc42d5ae94f7ef236f126da55c4 (diff) | |
download | external_llvm-e609a513f3c072bba28412c681465332a2822d9a.zip external_llvm-e609a513f3c072bba28412c681465332a2822d9a.tar.gz external_llvm-e609a513f3c072bba28412c681465332a2822d9a.tar.bz2 |
make the new isel generator plop out a CheckComplexPattern function
for evaluating complex patterns. Some cleanup has to happen before
this can be used though.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96419 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/DAGISelMatcherEmitter.cpp')
-rw-r--r-- | utils/TableGen/DAGISelMatcherEmitter.cpp | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/utils/TableGen/DAGISelMatcherEmitter.cpp b/utils/TableGen/DAGISelMatcherEmitter.cpp index c414918..8e004f3 100644 --- a/utils/TableGen/DAGISelMatcherEmitter.cpp +++ b/utils/TableGen/DAGISelMatcherEmitter.cpp @@ -13,6 +13,7 @@ #include "DAGISelMatcher.h" #include "CodeGenDAGPatterns.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringMap.h" #include "llvm/Support/FormattedStream.h" @@ -69,7 +70,9 @@ class MatcherTableEmitter { StringMap<unsigned> NodePredicateMap, PatternPredicateMap; std::vector<std::string> NodePredicates, PatternPredicates; - + + DenseMap<const ComplexPattern*, unsigned> ComplexPatternMap; + std::vector<const ComplexPattern*> ComplexPatterns; public: MatcherTableEmitter(formatted_raw_ostream &os) : OS(os) {} @@ -95,6 +98,15 @@ private: } return Entry-1; } + + unsigned getComplexPat(const ComplexPattern &P) { + unsigned &Entry = ComplexPatternMap[&P]; + if (Entry == 0) { + ComplexPatterns.push_back(&P); + Entry = ComplexPatterns.size(); + } + return Entry-1; + } }; } // end anonymous namespace. @@ -169,7 +181,9 @@ EmitMatcher(const MatcherNode *N, unsigned Indent) { return 2; case MatcherNode::CheckComplexPat: - OS << "OPC_CheckComplexPat, 0/*XXX*/,\n"; + OS << "OPC_CheckComplexPat, " + << getComplexPat(cast<CheckComplexPatMatcherNode>(N)->getPattern()) + << ",\n"; return 2; case MatcherNode::CheckAndImm: { @@ -238,6 +252,7 @@ EmitMatcherAndChildren(const MatcherNode *N, unsigned Indent) { } void MatcherTableEmitter::EmitPredicateFunctions() { + // Emit pattern predicates. OS << "bool CheckPatternPredicate(unsigned PredNo) const {\n"; OS << " switch (PredNo) {\n"; OS << " default: assert(0 && \"Invalid predicate in table?\");\n"; @@ -246,6 +261,7 @@ void MatcherTableEmitter::EmitPredicateFunctions() { OS << " }\n"; OS << "}\n\n"; + // Emit Node predicates. OS << "bool CheckNodePredicate(SDNode *N, unsigned PredNo) const {\n"; OS << " switch (PredNo) {\n"; OS << " default: assert(0 && \"Invalid predicate in table?\");\n"; @@ -253,6 +269,28 @@ void MatcherTableEmitter::EmitPredicateFunctions() { OS << " case " << i << ": return " << NodePredicates[i] << "(N);\n"; OS << " }\n"; OS << "}\n\n"; + + // Emit CompletePattern matchers. + + OS << "bool CheckComplexPattern(SDNode *Root, SDValue N,\n"; + OS << " unsigned PatternNo, SmallVectorImpl<SDValue> &Result) {\n"; + OS << " switch (PatternNo) {\n"; + OS << " default: assert(0 && \"Invalid pattern # in table?\");\n"; + for (unsigned i = 0, e = ComplexPatterns.size(); i != e; ++i) { + const ComplexPattern &P = *ComplexPatterns[i]; + unsigned NumOps = P.getNumOperands(); + if (P.hasProperty(SDNPHasChain)) + NumOps += 2; // Input and output chains. + OS << " case " << i << ":\n"; + OS << " Result.resize(Result.size()+" << NumOps << ");\n"; + OS << " return " << P.getSelectFunc() << "(Root, N"; + for (unsigned i = 0; i != NumOps; ++i) + OS << ", Result[Result.size()-" << (NumOps-i) << ']'; + OS << ");\n"; + } + OS << " }\n"; + OS << "}\n\n"; + } |