Add support for immediates directly in the pattern, this allows itanium to
authorChris Lattner <sabre@nondot.org>
Wed, 2 Nov 2005 06:49:14 +0000 (06:49 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 2 Nov 2005 06:49:14 +0000 (06:49 +0000)
define:

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24149 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/DAGISelEmitter.cpp
utils/TableGen/DAGISelEmitter.h

index 2fc324dff6fd57e5c96439eb806ce2b3321bed80..29206ce3b4cddb80be0065939dcec71fbc95a7ce 100644 (file)
@@ -621,6 +621,10 @@ TreePatternNode *TreePattern::ParseTreePattern(DagInit *Dag) {
       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 @@ void DAGISelEmitter::EmitMatchForPattern(TreePatternNode *N,
                                          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 @@ static bool InsertOneTypeCheck(TreePatternNode *Pat, TreePatternNode *Other,
   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 @@ void DAGISelEmitter::EmitInstructionSelector(std::ostream &OS) {
   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 dc9d1f7d60064d620a710dd6e9c3ef54f43b046c..be307141d82f5d7fc078638f0bd4d4b462c7f10d 100644 (file)
@@ -382,6 +382,8 @@ public:
   
   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;