enhance the EmitNode/MorphNodeTo operands to take a bit that
authorChris Lattner <sabre@nondot.org>
Sun, 28 Feb 2010 21:53:42 +0000 (21:53 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 28 Feb 2010 21:53:42 +0000 (21:53 +0000)
specifies whether there is an output flag or not.  Use this
instead of redundantly encoding the chain/flag results in the
output vtlist.

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

include/llvm/CodeGen/DAGISelHeader.h
utils/TableGen/DAGISelMatcher.cpp
utils/TableGen/DAGISelMatcher.h
utils/TableGen/DAGISelMatcherEmitter.cpp
utils/TableGen/DAGISelMatcherGen.cpp
utils/TableGen/DAGISelMatcherOpt.cpp

index 3ffc6e942cd8544830a5348f1eb0007775a65ef6..9aec982229a4e1bcad2c69eda021bf291e9db81b 100644 (file)
@@ -303,17 +303,18 @@ enum BuiltinOpcodes {
 };
 
 enum {
-  OPFL_None      = 0,     // Node has no chain or flag input and isn't variadic.
-  OPFL_Chain     = 1,     // Node has a chain input.
-  OPFL_Flag      = 2,     // Node has a flag input.
-  OPFL_MemRefs   = 4,     // Node gets accumulated MemRefs.
-  OPFL_Variadic0 = 1<<3,  // Node is variadic, root has 0 fixed inputs.
-  OPFL_Variadic1 = 2<<3,  // Node is variadic, root has 1 fixed inputs.
-  OPFL_Variadic2 = 3<<3,  // Node is variadic, root has 2 fixed inputs.
-  OPFL_Variadic3 = 4<<3,  // Node is variadic, root has 3 fixed inputs.
-  OPFL_Variadic4 = 5<<3,  // Node is variadic, root has 4 fixed inputs.
-  OPFL_Variadic5 = 6<<3,  // Node is variadic, root has 5 fixed inputs.
-  OPFL_Variadic6 = 7<<3,  // Node is variadic, root has 6 fixed inputs.
+  OPFL_None       = 0,     // Node has no chain or flag input and isn't variadic.
+  OPFL_Chain      = 1,     // Node has a chain input.
+  OPFL_FlagInput  = 2,     // Node has a flag input.
+  OPFL_FlagOutput = 4,     // Node has a flag output.
+  OPFL_MemRefs    = 8,     // Node gets accumulated MemRefs.
+  OPFL_Variadic0  = 1<<4,  // Node is variadic, root has 0 fixed inputs.
+  OPFL_Variadic1  = 2<<4,  // Node is variadic, root has 1 fixed inputs.
+  OPFL_Variadic2  = 3<<4,  // Node is variadic, root has 2 fixed inputs.
+  OPFL_Variadic3  = 4<<4,  // Node is variadic, root has 3 fixed inputs.
+  OPFL_Variadic4  = 5<<4,  // Node is variadic, root has 4 fixed inputs.
+  OPFL_Variadic5  = 6<<4,  // Node is variadic, root has 5 fixed inputs.
+  OPFL_Variadic6  = 7<<4,  // Node is variadic, root has 6 fixed inputs.
   
   OPFL_VariadicInfo = OPFL_Variadic6
 };
@@ -322,7 +323,7 @@ enum {
 /// number of fixed arity values that should be skipped when copying from the
 /// root.
 static inline int getNumFixedFromVariadicInfo(unsigned Flags) {
-  return ((Flags&OPFL_VariadicInfo) >> 3)-1;
+  return ((Flags&OPFL_VariadicInfo) >> 4)-1;
 }
 
 struct MatchScope {
@@ -793,7 +794,6 @@ SDNode *SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable,
       unsigned EmitNodeInfo = MatcherTable[MatcherIndex++];
       // Get the result VT list.
       unsigned NumVTs = MatcherTable[MatcherIndex++];
-      assert(NumVTs != 0 && "Invalid node result");
       SmallVector<EVT, 4> VTs;
       for (unsigned i = 0; i != NumVTs; ++i) {
         MVT::SimpleValueType VT =
@@ -802,6 +802,11 @@ SDNode *SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable,
         VTs.push_back(VT);
       }
       
+      if (EmitNodeInfo & OPFL_Chain)
+        VTs.push_back(MVT::Other);
+      if (EmitNodeInfo & OPFL_FlagOutput)
+        VTs.push_back(MVT::Flag);
+      
       // FIXME: Use faster version for the common 'one VT' case?
       SDVTList VTList = CurDAG->getVTList(VTs.data(), VTs.size());
 
@@ -837,7 +842,7 @@ SDNode *SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable,
       // If this has chain/flag inputs, add them.
       if (EmitNodeInfo & OPFL_Chain)
         Ops.push_back(InputChain);
-      if ((EmitNodeInfo & OPFL_Flag) && InputFlag.getNode() != 0)
+      if ((EmitNodeInfo & OPFL_FlagInput) && InputFlag.getNode() != 0)
         Ops.push_back(InputFlag);
       
       // Create the node.
index 1f1bb60c37c52393b16202a8476a70cb88e46541..f1bfec0fc3ee5ba2d637e2cd869cf250b879ddbb 100644 (file)
@@ -246,7 +246,8 @@ 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->HasInFlag == HasInFlag && M->HasOutFlag == HasOutFlag &&
+         M->HasMemRefs == HasMemRefs &&
          M->NumFixedArityOperands == NumFixedArityOperands;
 }
 
index 46652d912eca35fe77a5b4f02ef9af235d5d0284..d9c8b2922124afd63c710d564dd283aed766247b 100644 (file)
@@ -876,7 +876,7 @@ class EmitNodeMatcherCommon : public Matcher {
   std::string OpcodeName;
   const SmallVector<MVT::SimpleValueType, 3> VTs;
   const SmallVector<unsigned, 6> Operands;
-  bool HasChain, HasFlag, HasMemRefs;
+  bool HasChain, HasInFlag, HasOutFlag, HasMemRefs;
   
   /// NumFixedArityOperands - If this is a fixed arity node, this is set to -1.
   /// If this is a varidic node, this is set to the number of fixed arity
@@ -886,12 +886,13 @@ public:
   EmitNodeMatcherCommon(const std::string &opcodeName,
                         const MVT::SimpleValueType *vts, unsigned numvts,
                         const unsigned *operands, unsigned numops,
-                        bool hasChain, bool hasFlag, bool hasmemrefs,
+                        bool hasChain, bool hasInFlag, bool hasOutFlag,
+                        bool hasmemrefs,
                         int numfixedarityoperands, bool isMorphNodeTo)
     : Matcher(isMorphNodeTo ? MorphNodeTo : EmitNode), OpcodeName(opcodeName),
       VTs(vts, vts+numvts), Operands(operands, operands+numops),
-      HasChain(hasChain), HasFlag(hasFlag), HasMemRefs(hasmemrefs),
-      NumFixedArityOperands(numfixedarityoperands) {}
+      HasChain(hasChain), HasInFlag(hasInFlag), HasOutFlag(hasOutFlag),
+      HasMemRefs(hasmemrefs), NumFixedArityOperands(numfixedarityoperands) {}
   
   const std::string &getOpcodeName() const { return OpcodeName; }
   
@@ -921,7 +922,8 @@ public:
 
   
   bool hasChain() const { return HasChain; }
-  bool hasFlag() const { return HasFlag; }
+  bool hasInFlag() const { return HasInFlag; }
+  bool hasOutFlag() const { return HasOutFlag; }
   bool hasMemRefs() const { return HasMemRefs; }
   int getNumFixedArityOperands() const { return NumFixedArityOperands; }
   
@@ -942,10 +944,12 @@ public:
   EmitNodeMatcher(const std::string &opcodeName,
                   const MVT::SimpleValueType *vts, unsigned numvts,
                   const unsigned *operands, unsigned numops,
-                  bool hasChain, bool hasFlag, bool hasmemrefs,
+                  bool hasChain, bool hasInFlag, bool hasOutFlag,
+                  bool hasmemrefs,
                   int numfixedarityoperands, unsigned firstresultslot)
   : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
-                          hasFlag, hasmemrefs, numfixedarityoperands, false),
+                          hasInFlag, hasOutFlag, hasmemrefs,
+                          numfixedarityoperands, false),
     FirstResultSlot(firstresultslot) {}
   
   unsigned getFirstResultSlot() const { return FirstResultSlot; }
@@ -962,10 +966,12 @@ public:
   MorphNodeToMatcher(const std::string &opcodeName,
                      const MVT::SimpleValueType *vts, unsigned numvts,
                      const unsigned *operands, unsigned numops,
-                     bool hasChain, bool hasFlag, bool hasmemrefs,
+                     bool hasChain, bool hasInFlag, bool hasOutFlag,
+                     bool hasmemrefs,
                      int numfixedarityoperands, const PatternToMatch &pattern)
     : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
-                            hasFlag, hasmemrefs, numfixedarityoperands, true),
+                            hasInFlag, hasOutFlag, hasmemrefs,
+                            numfixedarityoperands, true),
       Pattern(pattern) {
   }
   
index c4c005cb1d0dd324f48f8fe1dfdc559d25b89ee5..c6addd8b0db4ee713f8ff64e245493ff7b1a30d9 100644 (file)
@@ -396,7 +396,8 @@ EmitMatcher(const Matcher *N, unsigned Indent, unsigned CurrentIdx,
     OS << ", TARGET_OPCODE(" << EN->getOpcodeName() << "), 0";
     
     if (EN->hasChain())   OS << "|OPFL_Chain";
-    if (EN->hasFlag())    OS << "|OPFL_Flag";
+    if (EN->hasInFlag())  OS << "|OPFL_FlagInput";
+    if (EN->hasOutFlag()) OS << "|OPFL_FlagOutput";
     if (EN->hasMemRefs()) OS << "|OPFL_MemRefs";
     if (EN->getNumFixedArityOperands() != -1)
       OS << "|OPFL_Variadic" << EN->getNumFixedArityOperands();
index c558eba9fd5d3d1bba4f2059c9b6ce0ae3b849ff..8f8fcf7cfb9e9fbd9ba2e9420a9c8aa7dd90dfcd 100644 (file)
@@ -713,10 +713,6 @@ EmitResultInstructionAsOperand(const TreePatternNode *N,
       if (Pattern.getDstRegs()[i]->isSubClassOf("Register"))
         ResultVTs.push_back(getRegisterValueType(Pattern.getDstRegs()[i], CGT));
   }
-  if (NodeHasChain)
-    ResultVTs.push_back(MVT::Other);
-  if (TreeHasOutFlag)
-    ResultVTs.push_back(MVT::Flag);
 
   // FIXME2: Instead of using the isVariadic flag on the instruction, we should
   // have an SDNP that indicates variadicism.  The TargetInstrInfo isVariadic
@@ -744,7 +740,7 @@ EmitResultInstructionAsOperand(const TreePatternNode *N,
   AddMatcher(new EmitNodeMatcher(II.Namespace+"::"+II.TheDef->getName(),
                                  ResultVTs.data(), ResultVTs.size(),
                                  InstOps.data(), InstOps.size(),
-                                 NodeHasChain, TreeHasInFlag,
+                                 NodeHasChain, TreeHasInFlag, TreeHasOutFlag,
                                  NodeHasMemRefs, NumFixedArityOperands,
                                  NextRecordedOperandNo));
   
index 65a01fa6b9aaa43149bce52f49e3f5e7a6872e93..01723d3ec84e2b9fa0829162e59fe895d1a5f0b2 100644 (file)
@@ -92,7 +92,7 @@ static void ContractNodes(OwningPtr<Matcher> &MatcherPtr,
       // NOTE: Strictly speaking, we don't have to check for the flag here
       // because the code in the pattern generator doesn't handle it right.  We
       // do it anyway for thoroughness.
-      if (!EN->hasFlag() &&
+      if (!EN->hasOutFlag() &&
           Pattern.getSrcPattern()->NodeHasProperty(SDNPOutFlag, CGP))
         ResultsMatch = false;
       
@@ -110,9 +110,10 @@ static void ContractNodes(OwningPtr<Matcher> &MatcherPtr,
         const SmallVectorImpl<MVT::SimpleValueType> &VTs = EN->getVTList();
         const SmallVectorImpl<unsigned> &Operands = EN->getOperandList();
         MatcherPtr.reset(new MorphNodeToMatcher(EN->getOpcodeName(),
-                                                &VTs[0], VTs.size(),
+                                                VTs.data(), VTs.size(),
                                                 Operands.data(),Operands.size(),
-                                                EN->hasChain(), EN->hasFlag(),
+                                                EN->hasChain(), EN->hasInFlag(),
+                                                EN->hasOutFlag(),
                                                 EN->hasMemRefs(),
                                                 EN->getNumFixedArityOperands(),
                                                 Pattern));