New = new TreePatternNode(DI);
} else if (DagInit *DI = dynamic_cast<DagInit*>(Arg)) {
New = ParseTreePattern(DI);
+ } else if (IntInit *II = dynamic_cast<IntInit*>(Arg)) {
+ New = new TreePatternNode(II);
+ if (!Dag->getArgName(0).empty())
+ error("Constant int argument should not have a name!");
} else {
Arg->dump();
error("Unknown leaf value for tree pattern!");
const std::string &RootName,
std::map<std::string,std::string> &VarMap,
unsigned PatternNo, std::ostream &OS) {
- assert(!N->isLeaf() && "Cannot match against a leaf!");
+ if (N->isLeaf()) {
+ if (IntInit *II = dynamic_cast<IntInit*>(N->getLeafValue())) {
+ OS << " if (cast<ConstantSDNode>(" << RootName
+ << ")->getSignExtended() != " << II->getValue() << ")\n"
+ << " goto P" << PatternNo << "Fail;\n";
+ return;
+ }
+ assert(0 && "Cannot match this as a leaf value!");
+ abort();
+ }
// If this node has a name associated with it, capture it in VarMap. If
// we already saw this in the pattern, emit code to verify dagness.
return false;
}
+Record *DAGISelEmitter::getSDNodeNamed(const std::string &Name) const {
+ Record *N = Records.getDef(Name);
+ assert(N && N->isSubClassOf("SDNode") && "Bad argument");
+ return N;
+}
+
/// EmitCodeForPattern - Given a pattern to match, emit code to the specified
/// stream to match the pattern, and generate the code for the match if it
/// succeeds.
std::map<Record*, std::vector<PatternToMatch*>,
CompareByRecordName> PatternsByOpcode;
for (unsigned i = 0, e = PatternsToMatch.size(); i != e; ++i)
- PatternsByOpcode[PatternsToMatch[i].first->getOperator()]
- .push_back(&PatternsToMatch[i]);
+ if (!PatternsToMatch[i].first->isLeaf()) {
+ PatternsByOpcode[PatternsToMatch[i].first->getOperator()]
+ .push_back(&PatternsToMatch[i]);
+ } else {
+ if (IntInit *II =
+ dynamic_cast<IntInit*>(PatternsToMatch[i].first->getLeafValue())) {
+ PatternsByOpcode[getSDNodeNamed("imm")].push_back(&PatternsToMatch[i]);
+ } else {
+ assert(0 && "Unknown leaf value");
+ }
+ }
// Loop over all of the case statements.
for (std::map<Record*, std::vector<PatternToMatch*>,