add infrastructure to support forming selectnodeto. Not used yet
authorChris Lattner <sabre@nondot.org>
Sun, 28 Feb 2010 02:31:26 +0000 (02:31 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 28 Feb 2010 02:31:26 +0000 (02:31 +0000)
because I have to go on another detour first.

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

utils/TableGen/DAGISelMatcher.cpp
utils/TableGen/DAGISelMatcher.h
utils/TableGen/DAGISelMatcherEmitter.cpp
utils/TableGen/DAGISelMatcherGen.cpp
utils/TableGen/DAGISelMatcherOpt.cpp

index 3ea5b5d7fbfcc9c064bb5c0ff7d9d8f26f2694eb..d6f4f78876881a53e1b4abb181671656e43e6c86 100644 (file)
@@ -170,8 +170,10 @@ void EmitNodeXFormMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
 }
 
 
-void EmitNodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
-  OS.indent(indent) << "EmitNode: " << OpcodeName << ": <todo flags> ";
+void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, unsigned indent) const {
+  OS.indent(indent);
+  OS << (isSelectNodeTo() ? "SelectNodeTo: " : "EmitNode: ")
+     << OpcodeName << ": <todo flags> ";
 
   for (unsigned i = 0, e = VTs.size(); i != e; ++i)
     OS << ' ' << getEnumName(VTs[i]);
@@ -236,15 +238,15 @@ unsigned EmitMergeInputChainsMatcher::getHashImpl() const {
   return HashUnsigneds(ChainNodes.begin(), ChainNodes.end());
 }
 
-bool EmitNodeMatcher::isEqualImpl(const Matcher *m) const {
-  const EmitNodeMatcher *M = cast<EmitNodeMatcher>(m);
+bool EmitNodeMatcherCommon::isEqualImpl(const Matcher *m) const {
+  const EmitNodeMatcherCommon *M = cast<EmitNodeMatcherCommon>(m);
   return M->OpcodeName == OpcodeName && M->VTs == VTs &&
          M->Operands == Operands && M->HasChain == HasChain &&
          M->HasFlag == HasFlag && M->HasMemRefs == HasMemRefs &&
          M->NumFixedArityOperands == NumFixedArityOperands;
 }
 
-unsigned EmitNodeMatcher::getHashImpl() const {
+unsigned EmitNodeMatcherCommon::getHashImpl() const {
   return (HashString(OpcodeName) << 4) | Operands.size();
 }
 
index d80f19b334608391735f8e47a5cf4d9dbd3a117c..3d73262ef881d8980de4d5c74c1be20b8cdf4c96 100644 (file)
@@ -75,7 +75,8 @@ public:
     EmitNode,             // Create a DAG node
     EmitNodeXForm,        // Run a SDNodeXForm
     MarkFlagResults,      // Indicate which interior nodes have flag results.
-    CompleteMatch         // Finish a match and update the results.
+    CompleteMatch,        // Finish a match and update the results.
+    SelectNodeTo          // Build a node, finish a match and update results.
   };
   const KindTy Kind;
 
@@ -869,8 +870,9 @@ private:
   }
 };
   
-/// EmitNodeMatcher - This signals a successful match and generates a node.
-class EmitNodeMatcher : public Matcher {
+/// EmitNodeMatcherCommon - Common class shared between EmitNode and
+/// SelectNodeTo.
+class EmitNodeMatcherCommon : public Matcher {
   std::string OpcodeName;
   const SmallVector<MVT::SimpleValueType, 3> VTs;
   const SmallVector<unsigned, 6> Operands;
@@ -881,16 +883,18 @@ class EmitNodeMatcher : public Matcher {
   /// operands in the root of the pattern.  The rest are appended to this node.
   int NumFixedArityOperands;
 public:
-  EmitNodeMatcher(const std::string &opcodeName,
-                  const MVT::SimpleValueType *vts, unsigned numvts,
-                  const unsigned *operands, unsigned numops,
-                  bool hasChain, bool hasFlag, bool hasmemrefs,
-                  int numfixedarityoperands)
-    : Matcher(EmitNode), OpcodeName(opcodeName),
+  EmitNodeMatcherCommon(const std::string &opcodeName,
+                        const MVT::SimpleValueType *vts, unsigned numvts,
+                        const unsigned *operands, unsigned numops,
+                        bool hasChain, bool hasFlag, bool hasmemrefs,
+                        int numfixedarityoperands, bool isSelectNodeTo)
+    : Matcher(isSelectNodeTo ? SelectNodeTo : EmitNode), OpcodeName(opcodeName),
       VTs(vts, vts+numvts), Operands(operands, operands+numops),
       HasChain(hasChain), HasFlag(hasFlag), HasMemRefs(hasmemrefs),
       NumFixedArityOperands(numfixedarityoperands) {}
   
+  bool isSelectNodeTo() const { return getKind() == SelectNodeTo; }
+  
   const std::string &getOpcodeName() const { return OpcodeName; }
   
   unsigned getNumVTs() const { return VTs.size(); }
@@ -911,7 +915,7 @@ public:
   int getNumFixedArityOperands() const { return NumFixedArityOperands; }
   
   static inline bool classof(const Matcher *N) {
-    return N->getKind() == EmitNode;
+    return N->getKind() == EmitNode || N->getKind() == SelectNodeTo;
   }
   
 private:
@@ -920,6 +924,44 @@ private:
   virtual unsigned getHashImpl() const;
 };
   
+/// EmitNodeMatcher - This signals a successful match and generates a node.
+class EmitNodeMatcher : public EmitNodeMatcherCommon {
+public:
+  EmitNodeMatcher(const std::string &opcodeName,
+                  const MVT::SimpleValueType *vts, unsigned numvts,
+                  const unsigned *operands, unsigned numops,
+                  bool hasChain, bool hasFlag, bool hasmemrefs,
+                  int numfixedarityoperands)
+  : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
+                          hasFlag, hasmemrefs, numfixedarityoperands, false)
+    {}
+  
+  static inline bool classof(const Matcher *N) {
+    return N->getKind() == EmitNode;
+  }
+  
+};
+  
+class SelectNodeToMatcher : public EmitNodeMatcherCommon {
+  const PatternToMatch &Pattern;
+public:
+  SelectNodeToMatcher(const std::string &opcodeName,
+                      const MVT::SimpleValueType *vts, unsigned numvts,
+                      const unsigned *operands, unsigned numops,
+                      bool hasChain, bool hasFlag, bool hasmemrefs,
+                      int numfixedarityoperands, const PatternToMatch &pattern)
+    : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
+                            hasFlag, hasmemrefs, numfixedarityoperands, true),
+      Pattern(pattern) {
+  }
+  
+  const PatternToMatch &getPattern() const { return Pattern; }
+
+  static inline bool classof(const Matcher *N) {
+    return N->getKind() == SelectNodeTo;
+  }
+};
+  
 /// MarkFlagResultsMatcher - This node indicates which non-root nodes in the
 /// pattern produce flags.  This allows CompleteMatchMatcher to update them
 /// with the output flag of the resultant code.
@@ -976,7 +1018,7 @@ private:
   }
   virtual unsigned getHashImpl() const;
 };
-  
 } // end namespace llvm
 
 #endif
index 450a4575bf6441f6c06dd33fb41b92941304336d..84e33f39235e68783cb6dcf85344bc9641454eba 100644 (file)
@@ -389,9 +389,11 @@ EmitMatcher(const Matcher *N, unsigned Indent, unsigned CurrentIdx,
     return 3;
   }
       
-  case Matcher::EmitNode: {
-    const EmitNodeMatcher *EN = cast<EmitNodeMatcher>(N);
-    OS << "OPC_EmitNode, TARGET_OPCODE(" << EN->getOpcodeName() << "), 0";
+  case Matcher::EmitNode:
+  case Matcher::SelectNodeTo: {
+    const EmitNodeMatcherCommon *EN = cast<EmitNodeMatcherCommon>(N);
+    OS << (EN->isSelectNodeTo() ? "OPC_EmitNode" : "OPC_SelectNodeTo");
+    OS << ", TARGET_OPCODE(" << EN->getOpcodeName() << "), 0";
     
     if (EN->hasChain())   OS << "|OPFL_Chain";
     if (EN->hasFlag())    OS << "|OPFL_Flag";
@@ -564,6 +566,7 @@ void MatcherTableEmitter::EmitHistogram(formatted_raw_ostream &OS) {
     case Matcher::EmitMergeInputChains: OS << "OPC_EmitMergeInputChains"; break;
     case Matcher::EmitCopyToReg: OS << "OPC_EmitCopyToReg"; break;
     case Matcher::EmitNode: OS << "OPC_EmitNode"; break;
+    case Matcher::SelectNodeTo: OS << "OPC_SelectNodeTo"; break;
     case Matcher::EmitNodeXForm: OS << "OPC_EmitNodeXForm"; break;
     case Matcher::MarkFlagResults: OS << "OPC_MarkFlagResults"; break;
     case Matcher::CompleteMatch: OS << "OPC_CompleteMatch"; break;    
index cae2dfbc5960340577502b9b051f0d649e5c1dbe..ee385074a9eb26fb11fd72ecebaef6f88d90d95f 100644 (file)
@@ -746,10 +746,10 @@ EmitResultInstructionAsOperand(const TreePatternNode *N,
   // (add (load)) -> add32rm is ok because result #0 is the result and result #1
   // is new.
   AddMatcher(new EmitNodeMatcher(II.Namespace+"::"+II.TheDef->getName(),
-                                         ResultVTs.data(), ResultVTs.size(),
-                                         InstOps.data(), InstOps.size(),
-                                         NodeHasChain, TreeHasInFlag,
-                                         NodeHasMemRefs,NumFixedArityOperands));
+                                 ResultVTs.data(), ResultVTs.size(),
+                                 InstOps.data(), InstOps.size(),
+                                 NodeHasChain, TreeHasInFlag,
+                                 NodeHasMemRefs, NumFixedArityOperands));
   
   // The non-chain and non-flag results of the newly emitted node get recorded.
   for (unsigned i = 0, e = ResultVTs.size(); i != e; ++i) {
index 1ce573353f2bb47e65dc3b407f2a6c74048b55ab..79534574363c44bde131817acce37c092c2aec90 100644 (file)
@@ -56,6 +56,7 @@ static void ContractNodes(OwningPtr<Matcher> &MatcherPtr) {
     }
   }
   
+  // Zap movechild -> moveparent.
   if (MoveChildMatcher *MC = dyn_cast<MoveChildMatcher>(N))
     if (MoveParentMatcher *MP = 
           dyn_cast<MoveParentMatcher>(MC->getNext())) {
@@ -63,6 +64,14 @@ static void ContractNodes(OwningPtr<Matcher> &MatcherPtr) {
       return ContractNodes(MatcherPtr);
     }
   
+  // Turn EmitNode->CompleteMatch into SelectNodeTo if we can.
+  if (EmitNodeMatcher *EN = dyn_cast<EmitNodeMatcher>(N))
+    if (CompleteMatchMatcher *CM = cast<CompleteMatchMatcher>(EN->getNext())) {
+      (void)CM;
+      
+      
+    }
+  
   ContractNodes(N->getNextPtr());
 }