[llvm-commits] CVS: llvm/utils/TableGen/DAGISelEmitter.cpp

Evan Cheng evan.cheng at apple.com
Thu Feb 2 22:22:53 PST 2006



Changes in directory llvm/utils/TableGen:

DAGISelEmitter.cpp updated: 1.159 -> 1.160
---
Log message:

(store (op (load ...))) folding problem. In the generated matching code,
Chain is initially set to the chain operand of store node, when it reaches
load, if it matches the load then Chain is set to the chain operand of the
load.

However, if the matching code that follows this fails, isel moves on to the
next pattern but it does not restore Chain to the chain operand of the store.
So when it tries to match the next store / op / load pattern it would fail on
the Chain == load.getOperand(0) test.

The solution is for each chain operand to get a unique name. e.g. Chain10.


---
Diffs of the changes:  (+30 -23)

 DAGISelEmitter.cpp |   53 ++++++++++++++++++++++++++++++-----------------------
 1 files changed, 30 insertions(+), 23 deletions(-)


Index: llvm/utils/TableGen/DAGISelEmitter.cpp
diff -u llvm/utils/TableGen/DAGISelEmitter.cpp:1.159 llvm/utils/TableGen/DAGISelEmitter.cpp:1.160
--- llvm/utils/TableGen/DAGISelEmitter.cpp:1.159	Wed Feb  1 00:06:31 2006
+++ llvm/utils/TableGen/DAGISelEmitter.cpp	Fri Feb  3 00:22:41 2006
@@ -1848,6 +1848,7 @@
   /// [when false].
   std::vector<std::pair<bool, std::string> > &GeneratedCode;
 
+  std::string ChainName;
   unsigned TmpNo;
   
   void emitCheck(const std::string &S) {
@@ -1869,7 +1870,8 @@
   /// if the match fails. At this point, we already know that the opcode for N
   /// matches, and the SDNode for the result has the RootName specified name.
   void EmitMatchCode(TreePatternNode *N, const std::string &RootName,
-                     bool &FoundChain, bool isRoot = false) {
+                     const std::string &ChainSuffix, bool &FoundChain,
+                     bool isRoot = false) {
 
     // Emit instruction predicates. Each predicate is just a string for now.
     if (isRoot) {
@@ -1947,13 +1949,13 @@
                     utostr(CInfo.getNumResults()) + "))");
       }
       if (NodeHasChain) {
-        if (!FoundChain) {
-          emitCode("SDOperand Chain = " + RootName + ".getOperand(0);");
-          FoundChain = true;
-        } else {
+        if (FoundChain)
           emitCheck("Chain.Val == " + RootName + ".Val");
-          emitCode("Chain = " + RootName + ".getOperand(0);");
-        }
+        else
+          FoundChain = true;
+        ChainName = "Chain" + ChainSuffix;
+        emitCode("SDOperand " + ChainName + " = " + RootName +
+                 ".getOperand(0);");
       }
     }
 
@@ -1988,7 +1990,8 @@
         const SDNodeInfo &CInfo = ISE.getSDNodeInfo(Child->getOperator());
         emitCheck(RootName + utostr(OpNo) + ".getOpcode() == " +
                   CInfo.getEnumName());
-        EmitMatchCode(Child, RootName + utostr(OpNo), FoundChain);
+        EmitMatchCode(Child, RootName + utostr(OpNo), ChainSuffix + utostr(OpNo),
+                      FoundChain);
         if (NodeHasProperty(Child, SDNodeInfo::SDNPHasChain, ISE))
           FoldedChains.push_back(std::make_pair(RootName + utostr(OpNo),
                                                 CInfo.getNumResults()));
@@ -2225,7 +2228,7 @@
       // Emit all the chain and CopyToReg stuff.
       bool ChainEmitted = HasChain;
       if (HasChain)
-        emitCode("Chain = Select(Chain);");
+        emitCode(ChainName + " = Select(" + ChainName + ");");
       if (HasInFlag || HasOptInFlag || HasImpInputs)
         EmitInFlagSelectCode(Pattern, "N", ChainEmitted, true);
 
@@ -2248,7 +2251,7 @@
         emitCode(Code + ");");
         if (HasChain) {
           // Must have at least one result
-          emitCode("Chain = Tmp" + utostr(LastOp) + ".getValue(" +
+          emitCode(ChainName + " = Tmp" + utostr(LastOp) + ".getValue(" +
                    utostr(NumResults) + ");");
         }
       } else if (HasChain || NodeHasOutFlag) {
@@ -2273,7 +2276,7 @@
           // Inputs.
           for (unsigned i = 0, e = Ops.size(); i != e; ++i)
             Code += ", Tmp" + utostr(Ops[i]);
-          if (HasChain)  Code += ", Chain";
+          if (HasChain)  Code += ", " + ChainName;
           emitCode(Code + ", InFlag);");
 
           emitCode("else");
@@ -2292,7 +2295,7 @@
           // Inputs.
           for (unsigned i = 0, e = Ops.size(); i != e; ++i)
             Code += ", Tmp" + utostr(Ops[i]);
-          if (HasChain) Code += ", Chain);";
+          if (HasChain) Code += ", " + ChainName + ");";
           emitCode(Code);
         } else {
           std::string Code = "SDOperand Result = CurDAG->getTargetNode(" +
@@ -2310,7 +2313,7 @@
           // Inputs.
           for (unsigned i = 0, e = Ops.size(); i != e; ++i)
             Code += ", Tmp" + utostr(Ops[i]);
-          if (HasChain) Code += ", Chain";
+          if (HasChain) Code += ", " + ChainName;
           if (HasInFlag || HasImpInputs) Code += ", InFlag";
           emitCode(Code + ");");
         }
@@ -2323,7 +2326,7 @@
         }
 
         if (HasChain)
-          emitCode("Chain = Result.getValue(" + utostr(ValNo) + ");");
+          emitCode(ChainName + " = Result.getValue(" + utostr(ValNo) + ");");
 
         if (NodeHasOutFlag)
           emitCode("InFlag = Result.getValue(" + 
@@ -2338,14 +2341,15 @@
         // User does not expect that the instruction produces a chain!
         bool AddedChain = HasChain && !NodeHasChain;
         if (NodeHasChain)
-          emitCode("CodeGenMap[N.getValue(" + utostr(ValNo++) + ")] = Chain;");
+          emitCode("CodeGenMap[N.getValue(" + utostr(ValNo++) + ")] = " +
+                   ChainName + ";");
 
         if (FoldedChains.size() > 0) {
           std::string Code;
           for (unsigned j = 0, e = FoldedChains.size(); j < e; j++)
             Code += "CodeGenMap[" + FoldedChains[j].first + ".getValue(" +
               utostr(FoldedChains[j].second) + ")] = ";
-          emitCode(Code + "Chain;");
+          emitCode(Code + ChainName + ";");
         }
 
         if (NodeHasOutFlag)
@@ -2467,14 +2471,16 @@
             } else {
               if (!ChainEmitted) {
                 emitCode("SDOperand Chain = CurDAG->getEntryNode();");
+                ChainName = "Chain";
                 ChainEmitted = true;
               }
               emitCode("SDOperand " + RootName + "CR" + utostr(i) + ";");
               emitCode(RootName + "CR" + utostr(i) +
-                       "  = CurDAG->getCopyToReg(Chain, CurDAG->getRegister(" +
-                       ISE.getQualifiedName(RR) + ", MVT::" + getEnumName(RVT) +
-                       "), Select(" + RootName + utostr(OpNo) + "), InFlag);");
-              emitCode("Chain  = " + RootName + "CR" + utostr(i) + 
+                       "  = CurDAG->getCopyToReg(" + ChainName +
+                       ", CurDAG->getRegister(" + ISE.getQualifiedName(RR) +
+                       ", MVT::" + getEnumName(RVT) + "), Select(" + RootName +
+                       utostr(OpNo) + "), InFlag);");
+              emitCode(ChainName + " = " + RootName + "CR" + utostr(i) + 
                        ".getValue(0);");
               emitCode("InFlag = " + RootName + "CR" + utostr(i) +
                        ".getValue(1);");
@@ -2519,11 +2525,12 @@
             if (!ChainEmitted) {
               emitCode("SDOperand Chain = CurDAG->getEntryNode();");
               ChainEmitted = true;
+              ChainName = "Chain";
             }
-            emitCode("Result = CurDAG->getCopyFromReg(Chain, " +
+            emitCode("Result = CurDAG->getCopyFromReg(" + ChainName + ", " +
                      ISE.getQualifiedName(RR) + ", MVT::" + getEnumName(RVT) +
                      ", InFlag);");
-            emitCode("Chain  = Result.getValue(1);");
+            emitCode(ChainName + " = Result.getValue(1);");
             emitCode("InFlag = Result.getValue(2);");
             RetVal = true;
           }
@@ -2545,7 +2552,7 @@
 
   // Emit the matcher, capturing named arguments in VariableMap.
   bool FoundChain = false;
-  Emitter.EmitMatchCode(Pattern.getSrcPattern(), "N", FoundChain,
+  Emitter.EmitMatchCode(Pattern.getSrcPattern(), "N", "", FoundChain,
                         true /*the root*/);
 
   // TP - Get *SOME* tree pattern, we don't care which.






More information about the llvm-commits mailing list