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

Chris Lattner lattner at cs.uiuc.edu
Tue Nov 1 22:49:25 PST 2005



Changes in directory llvm/utils/TableGen:

DAGISelEmitter.cpp updated: 1.71 -> 1.72
DAGISelEmitter.h updated: 1.35 -> 1.36
---
Log message:

Add support for immediates directly in the pattern, this allows itanium to
define:

def : Pat<(i1 1), (CMPEQ r0, r0)>;



---
Diffs of the changes:  (+33 -3)

 DAGISelEmitter.cpp |   34 +++++++++++++++++++++++++++++++---
 DAGISelEmitter.h   |    2 ++
 2 files changed, 33 insertions(+), 3 deletions(-)


Index: llvm/utils/TableGen/DAGISelEmitter.cpp
diff -u llvm/utils/TableGen/DAGISelEmitter.cpp:1.71 llvm/utils/TableGen/DAGISelEmitter.cpp:1.72
--- llvm/utils/TableGen/DAGISelEmitter.cpp:1.71	Sat Oct 29 11:39:40 2005
+++ llvm/utils/TableGen/DAGISelEmitter.cpp	Wed Nov  2 00:49:14 2005
@@ -621,6 +621,10 @@
       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!");
@@ -1521,7 +1525,16 @@
                                          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.
@@ -1762,6 +1775,12 @@
   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.
@@ -1897,8 +1916,17 @@
   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*>,


Index: llvm/utils/TableGen/DAGISelEmitter.h
diff -u llvm/utils/TableGen/DAGISelEmitter.h:1.35 llvm/utils/TableGen/DAGISelEmitter.h:1.36
--- llvm/utils/TableGen/DAGISelEmitter.h:1.35	Thu Oct 20 20:19:59 2005
+++ llvm/utils/TableGen/DAGISelEmitter.h	Wed Nov  2 00:49:14 2005
@@ -382,6 +382,8 @@
   
   const CodeGenTarget &getTargetInfo() const { return Target; }
   
+  Record *getSDNodeNamed(const std::string &Name) const;
+  
   const SDNodeInfo &getSDNodeInfo(Record *R) const {
     assert(SDNodes.count(R) && "Unknown node!");
     return SDNodes.find(R)->second;






More information about the llvm-commits mailing list