[llvm-commits] CVS: llvm/utils/TableGen/DAGISelEmitter.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Oct 18 21:41:17 PDT 2005



Changes in directory llvm/utils/TableGen:

DAGISelEmitter.cpp updated: 1.63 -> 1.64
---
Log message:

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.



---
Diffs of the changes:  (+21 -9)

 DAGISelEmitter.cpp |   30 +++++++++++++++++++++---------
 1 files changed, 21 insertions(+), 9 deletions(-)


Index: llvm/utils/TableGen/DAGISelEmitter.cpp
diff -u llvm/utils/TableGen/DAGISelEmitter.cpp:1.63 llvm/utils/TableGen/DAGISelEmitter.cpp:1.64
--- llvm/utils/TableGen/DAGISelEmitter.cpp:1.63	Tue Oct 18 23:30:56 2005
+++ llvm/utils/TableGen/DAGISelEmitter.cpp	Tue Oct 18 23:41:05 2005
@@ -1472,6 +1472,9 @@
     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 @@
       }
       
       // 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!");






More information about the llvm-commits mailing list