diff options
author | Chris Lattner <sabre@nondot.org> | 2005-10-19 04:41:05 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2005-10-19 04:41:05 +0000 |
commit | 2f041d49a9750b714a8ceebe28038c78c6c40a4e (patch) | |
tree | 842627a1d95e9843015c849bf0d37e6d3cdbbd49 | |
parent | f6cd147471fb9a89661e2093731d6d40d4f41c7c (diff) |
add support for literal immediates in patterns to match, allowing us to
write things like this:
def : Pat<(add GPRC:$in, 12),
(ADD12 GPRC:$in)>;
Andrew: if this isn't enough or doesn't work for you, please lemme know.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23819 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | utils/TableGen/DAGISelEmitter.cpp | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/utils/TableGen/DAGISelEmitter.cpp b/utils/TableGen/DAGISelEmitter.cpp index af1b564c36..8fbbb05f0f 100644 --- a/utils/TableGen/DAGISelEmitter.cpp +++ b/utils/TableGen/DAGISelEmitter.cpp @@ -1472,6 +1472,9 @@ static unsigned getPatternSize(TreePatternNode *P) { TreePatternNode *Child = P->getChild(i); if (!Child->isLeaf() && Child->getExtType() != MVT::Other) Size += getPatternSize(Child); + else if (Child->isLeaf() && dynamic_cast<IntInit*>(Child->getLeafValue())) { + ++Size; // Matches a ConstantSDNode. + } } return Size; @@ -1562,15 +1565,24 @@ void DAGISelEmitter::EmitMatchForPattern(TreePatternNode *N, } // Handle leaves of various types. - Init *LeafVal = Child->getLeafValue(); - Record *LeafRec = dynamic_cast<DefInit*>(LeafVal)->getDef(); - if (LeafRec->isSubClassOf("RegisterClass")) { - // Handle register references. Nothing to do here. - } else if (LeafRec->isSubClassOf("ValueType")) { - // Make sure this is the specified value type. - OS << " if (cast<VTSDNode>(" << RootName << i << ")->getVT() != " - << "MVT::" << LeafRec->getName() << ") goto P" << PatternNo - << "Fail;\n"; + if (DefInit *DI = dynamic_cast<DefInit*>(Child->getLeafValue())) { + Record *LeafRec = DI->getDef(); + if (LeafRec->isSubClassOf("RegisterClass")) { + // Handle register references. Nothing to do here. + } else if (LeafRec->isSubClassOf("ValueType")) { + // Make sure this is the specified value type. + OS << " if (cast<VTSDNode>(" << RootName << i << ")->getVT() != " + << "MVT::" << LeafRec->getName() << ") goto P" << PatternNo + << "Fail;\n"; + } else { + Child->dump(); + assert(0 && "Unknown leaf type!"); + } + } else if (IntInit *II = dynamic_cast<IntInit*>(Child->getLeafValue())) { + OS << " if (!isa<ConstantSDNode>(" << RootName << i << ") ||\n" + << " cast<ConstantSDNode>(" << RootName << i + << ")->getValue() != " << II->getValue() << ")\n" + << " goto P" << PatternNo << "Fail;\n"; } else { Child->dump(); assert(0 && "Unknown leaf type!"); |