#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"
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) {}
}
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.
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: {
}
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";
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";
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";
+
}
if (!N->getName().empty()) {
unsigned &VarMapEntry = VariableMap[N->getName()];
if (VarMapEntry == 0) {
- VarMapEntry = ++NextRecordedOperandNo;
+ VarMapEntry = NextRecordedOperandNo+1;
+
+ unsigned NumRecorded;
// If this is a complex pattern, the match operation for it will
// implicitly record all of the outputs of it (which may be more than
// one).
if (const ComplexPattern *AM = N->getComplexPatternInfo(CGP)) {
// Record the right number of operands.
- // FIXME: Does this include chain?
- VarMapEntry += AM->getNumOperands()-1;
+ NumRecorded = AM->getNumOperands()-1;
+
+ if (AM->hasProperty(SDNPHasChain))
+ NumRecorded += 2; // Input and output chains.
} else {
// If it is a normal named node, we must emit a 'Record' opcode.
AddMatcherNode(new RecordMatcherNode());
+ NumRecorded = 1;
}
+ NextRecordedOperandNo += NumRecorded;
} else {
// If we get here, this is a second reference to a specific name. Since