just like they can opt into getting the root of the pattern being
authorChris Lattner <sabre@nondot.org>
Tue, 21 Sep 2010 20:37:12 +0000 (20:37 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 21 Sep 2010 20:37:12 +0000 (20:37 +0000)
matched, allow ComplexPatterns to opt into getting the parent node
of the operand being matched.

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

include/llvm/CodeGen/SelectionDAGISel.h
lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
utils/TableGen/DAGISelMatcherEmitter.cpp

index 51895a6f6a2162ea51bc0b244e8238abc6c1f2e2..9ce8fc4da286a43d205395211ce2b12044279bdf 100644 (file)
@@ -254,7 +254,8 @@ public:
     return 0;
   }
   
-  virtual bool CheckComplexPattern(SDNode *Root, SDValue N, unsigned PatternNo,
+  virtual bool CheckComplexPattern(SDNode *Root, SDNode *Parent, SDValue N,
+                                   unsigned PatternNo,
                                    SmallVectorImpl<SDValue> &Result) {
     assert(0 && "Tblgen should generate the implementation of this!");
     return false;
index dead5d50b72bea03b9769d5bd59f04abb62b6d17..7b2898dcbfb77c5592d85b6e28f8b70f5b35d5fa 100644 (file)
@@ -2086,7 +2086,11 @@ SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable,
       unsigned CPNum = MatcherTable[MatcherIndex++];
       unsigned RecNo = MatcherTable[MatcherIndex++];
       assert(RecNo < RecordedNodes.size() && "Invalid CheckComplexPat");
-      if (!CheckComplexPattern(NodeToMatch, RecordedNodes[RecNo], CPNum,
+      SDNode *Parent = 0;
+      if (NodeStack.size() > 1)
+        Parent = NodeStack[NodeStack.size()-2].getNode();
+      
+      if (!CheckComplexPattern(NodeToMatch, Parent, RecordedNodes[RecNo], CPNum,
                                RecordedNodes))
         break;
       continue;
index 5117737c5f00a20ed32d47215f21acb67efd27c6..3c669dab489fbb60b611edf927c0095f5857d8fe 100644 (file)
@@ -633,7 +633,7 @@ void MatcherTableEmitter::EmitPredicateFunctions(formatted_raw_ostream &OS) {
   // Emit CompletePattern matchers.
   // FIXME: This should be const.
   if (!ComplexPatterns.empty()) {
-    OS << "bool CheckComplexPattern(SDNode *Root, SDValue N,\n";
+    OS << "bool CheckComplexPattern(SDNode *Root, SDNode *Parent, SDValue N,\n";
     OS << "      unsigned PatternNo, SmallVectorImpl<SDValue> &Result) {\n";
     OS << "  unsigned NextRes = Result.size();\n";
     OS << "  switch (PatternNo) {\n";
@@ -655,6 +655,11 @@ void MatcherTableEmitter::EmitPredicateFunctions(formatted_raw_ostream &OS) {
       if (P.hasProperty(SDNPWantRoot))
         OS << "Root, ";
       
+      // If the complex pattern wants the parent of the operand being matched,
+      // pass it in as the next argument.
+      if (P.hasProperty(SDNPWantParent))
+        OS << "Parent, ";
+      
       OS << "N";
       for (unsigned i = 0; i != NumOps; ++i)
         OS << ", Result[NextRes+" << i << ']';