Allow ComplexExpressions in InstrInfo.td files to be slightly more... complex! Comple...
authorChristopher Lamb <christopher.lamb@gmail.com>
Thu, 31 Jan 2008 07:27:46 +0000 (07:27 +0000)
committerChristopher Lamb <christopher.lamb@gmail.com>
Thu, 31 Jan 2008 07:27:46 +0000 (07:27 +0000)
the pattern when generating matchin code.

The first (and currently, only) attribute causes the immediate parent node of the ComplexPattern operand to be passed into the matching code rather than the node at the root of the entire DAG containing the pattern.

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

lib/Target/TargetSelectionDAG.td
utils/TableGen/CodeGenTarget.cpp
utils/TableGen/CodeGenTarget.h
utils/TableGen/DAGISelEmitter.cpp

index a31ef2d36816c91906268f40de087b5c180e47f8..cdc50fa4b28441aac16b5f38f11f74029492ea0c 100644 (file)
@@ -767,6 +767,12 @@ class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
 //===----------------------------------------------------------------------===//
 // Complex pattern definitions.
 //
+
+class CPAttribute;
+// Pass the parent Operand as root to CP function rather 
+// than the root of the sub-DAG
+def CPAttrParentAsRoot : CPAttribute;
+
 // Complex patterns, e.g. X86 addressing mode, requires pattern matching code
 // in C++. NumOperands is the number of operands returned by the select function;
 // SelectFunc is the name of the function used to pattern match the max. pattern;
@@ -774,12 +780,14 @@ class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
 // e.g. X86 addressing mode - def addr : ComplexPattern<4, "SelectAddr", [add]>;
 //
 class ComplexPattern<ValueType ty, int numops, string fn,
-                     list<SDNode> roots = [], list<SDNodeProperty> props = []> {
+                     list<SDNode> roots = [], list<SDNodeProperty> props = [],
+                     list<CPAttribute> attrs = []> {
   ValueType Ty = ty;
   int NumOperands = numops;
   string SelectFunc = fn;
   list<SDNode> RootNodes = roots;
   list<SDNodeProperty> Properties = props;
+  list<CPAttribute> Attributes = attrs;
 }
 
 //===----------------------------------------------------------------------===//
index cf33fe6b1a6f57a148b576a998b3b6237e411713..bc758b75cdd13c5d7d0d9fc28d24ad0645dbcb8e 100644 (file)
@@ -351,6 +351,18 @@ ComplexPattern::ComplexPattern(Record *R) {
            << "' on ComplexPattern '" << R->getName() << "'!\n";
       exit(1);
     }
+  
+  // Parse the attributes.  
+  Attributes = 0;
+  PropList = R->getValueAsListOfDefs("Attributes");
+  for (unsigned i = 0, e = PropList.size(); i != e; ++i)
+    if (PropList[i]->getName() == "CPAttrParentAsRoot") {
+      Attributes |= 1 << CPAttrParentAsRoot;
+    } else {
+      cerr << "Unsupported pattern attribute '" << PropList[i]->getName()
+           << "' on ComplexPattern '" << R->getName() << "'!\n";
+      exit(1);
+    }
 }
 
 //===----------------------------------------------------------------------===//
index 922c2b41a105065216e69ceb4a052190bac288d9..a14f6303bd5cabb295a1de5897ee92dc83905094 100644 (file)
@@ -42,6 +42,9 @@ enum SDNP {
   SDNPSideEffect
 };
 
+// ComplexPattern attributes.
+enum CPAttr { CPAttrParentAsRoot };
+
 /// getValueType - Return the MVT::ValueType that the specified TableGen record
 /// corresponds to.
 MVT::ValueType getValueType(Record *Rec);
@@ -172,7 +175,8 @@ class ComplexPattern {
   unsigned NumOperands;
   std::string SelectFunc;
   std::vector<Record*> RootNodes;
-  unsigned Properties;
+  unsigned Properties; // Node properties
+  unsigned Attributes; // Pattern attributes
 public:
   ComplexPattern() : NumOperands(0) {};
   ComplexPattern(Record *R);
@@ -184,7 +188,7 @@ public:
     return RootNodes;
   }
   bool hasProperty(enum SDNP Prop) const { return Properties & (1 << Prop); }
-
+  bool hasAttribute(enum CPAttr Attr) const { return Attributes & (1 << Attr); }
 };
 
 } // End llvm namespace
index d685f701f0874afda88b661456890fe598135d3a..1f568ad5ee6738522a14f9be42ae6f81b2a7ea3b 100644 (file)
@@ -550,7 +550,7 @@ public:
           emitCheck(MaskPredicate + RootName + "0, cast<ConstantSDNode>(" +
                     RootName + "1), " + itostr(II->getValue()) + ")");
           
-          EmitChildMatchCode(N->getChild(0), N, RootName + utostr(0),
+          EmitChildMatchCode(N->getChild(0), N, RootName + utostr(0), RootName,
                              ChainSuffix + utostr(0), FoundChain);
           return;
         }
@@ -561,7 +561,7 @@ public:
       emitInit("SDOperand " + RootName + utostr(OpNo) + " = " +
                RootName + ".getOperand(" +utostr(OpNo) + ");");
 
-      EmitChildMatchCode(N->getChild(i), N, RootName + utostr(OpNo),
+      EmitChildMatchCode(N->getChild(i), N, RootName + utostr(OpNo), RootName,
                          ChainSuffix + utostr(OpNo), FoundChain);
     }
 
@@ -593,7 +593,8 @@ public:
   }
 
   void EmitChildMatchCode(TreePatternNode *Child, TreePatternNode *Parent,
-                          const std::string &RootName,
+                          const std::string &RootName, 
+                          const std::string &ParentRootName,
                           const std::string &ChainSuffix, bool &FoundChain) {
     if (!Child->isLeaf()) {
       // If it's not a leaf, recursively match.
@@ -649,7 +650,12 @@ public:
             emitCode("SDOperand " + ChainName + ";");
           }
           
-          std::string Code = Fn + "(N, ";
+          std::string Code = Fn + "(";
+          if (CP->hasAttribute(CPAttrParentAsRoot)) {
+            Code += ParentRootName + ", ";
+          } else {
+            Code += "N, ";
+          }
           if (CP->hasProperty(SDNPHasChain)) {
             std::string ParentName(RootName.begin(), RootName.end()-1);
             Code += ParentName + ", ";