Close list item tag, to conform with the style in this file. It's optional
[oota-llvm.git] / utils / TableGen / DAGISelEmitter.cpp
index a6e3730ab12fd1b88359c852e1ee81dbe3a49674..43513525579aaed2f8cc5f42fe453b51f73e128b 100644 (file)
@@ -583,11 +583,14 @@ public:
           emitInit("SDValue " + RootName + "1" + " = " +
                    RootName + ".getOperand(" + utostr(1) + ");");
 
-          emitCheck("isa<ConstantSDNode>(" + RootName + "1)");
+          unsigned NTmp = TmpNo++;
+          emitCode("ConstantSDNode *Tmp" + utostr(NTmp) +
+                   " = dyn_cast<ConstantSDNode>(" + RootName + "1);");
+          emitCheck("Tmp" + utostr(NTmp));
           const char *MaskPredicate = N->getOperator()->getName() == "or"
             ? "CheckOrMask(" : "CheckAndMask(";
-          emitCheck(MaskPredicate + RootName + "0, cast<ConstantSDNode>(" +
-                    RootName + "1), INT64_C(" + itostr(II->getValue()) + "))");
+          emitCheck(MaskPredicate + RootName + "0, Tmp" + utostr(NTmp) +
+                    ", INT64_C(" + itostr(II->getValue()) + "))");
           
           EmitChildMatchCode(N->getChild(0), N, RootName + utostr(0), RootName,
                              ChainSuffix + utostr(0), FoundChain);
@@ -610,8 +613,8 @@ public:
       std::string Fn = CP->getSelectFunc();
       unsigned NumOps = CP->getNumOperands();
       for (unsigned i = 0; i < NumOps; ++i) {
-        emitDecl("CPTmp" + utostr(i));
-        emitCode("SDValue CPTmp" + utostr(i) + ";");
+        emitDecl("CPTmp" + RootName + "_" + utostr(i));
+        emitCode("SDValue CPTmp" + RootName + "_" + utostr(i) + ";");
       }
       if (CP->hasProperty(SDNPHasChain)) {
         emitDecl("CPInChain");
@@ -622,7 +625,7 @@ public:
 
       std::string Code = Fn + "(" + RootName + ", " + RootName;
       for (unsigned i = 0; i < NumOps; i++)
-        Code += ", CPTmp" + utostr(i);
+        Code += ", CPTmp" + RootName + "_" + utostr(i);
       if (CP->hasProperty(SDNPHasChain)) {
         ChainName = "Chain" + ChainSuffix;
         Code += ", CPInChain, Chain" + ChainSuffix;
@@ -684,8 +687,8 @@ public:
           std::string Fn = CP->getSelectFunc();
           unsigned NumOps = CP->getNumOperands();
           for (unsigned i = 0; i < NumOps; ++i) {
-            emitDecl("CPTmp" + utostr(i));
-            emitCode("SDValue CPTmp" + utostr(i) + ";");
+            emitDecl("CPTmp" + RootName + "_" + utostr(i));
+            emitCode("SDValue CPTmp" + RootName + "_" + utostr(i) + ";");
           }
           if (CP->hasProperty(SDNPHasChain)) {
             const SDNodeInfo &PInfo = CGP.getSDNodeInfo(Parent->getOperator());
@@ -710,7 +713,7 @@ public:
           }
           Code += RootName;
           for (unsigned i = 0; i < NumOps; i++)
-            Code += ", CPTmp" + utostr(i);
+            Code += ", CPTmp" + RootName + "_" + utostr(i);
           if (CP->hasProperty(SDNPHasChain))
             Code += ", CPInChain, Chain" + ChainSuffix;
           emitCheck(Code + ")");
@@ -738,11 +741,14 @@ public:
                     ".getNode())");
       } else if (IntInit *II =
                  dynamic_cast<IntInit*>(Child->getLeafValue())) {
-        emitCheck("isa<ConstantSDNode>(" + RootName + ")");
+        unsigned NTmp = TmpNo++;
+        emitCode("ConstantSDNode *Tmp"+ utostr(NTmp) +
+                 " = dyn_cast<ConstantSDNode>("+
+                 RootName + ");");
+        emitCheck("Tmp" + utostr(NTmp));
         unsigned CTmp = TmpNo++;
-        emitCode("int64_t CN"+utostr(CTmp)+" = cast<ConstantSDNode>("+
-                 RootName + ")->getSExtValue();");
-        
+        emitCode("int64_t CN"+ utostr(CTmp) +
+                 " = Tmp" + utostr(NTmp) + "->getSExtValue();");
         emitCheck("CN" + utostr(CTmp) + " == "
                   "INT64_C(" +itostr(II->getValue()) + ")");
       } else {
@@ -856,7 +862,7 @@ public:
         NodeOps.push_back(Val);
       } else if (N->isLeaf() && (CP = NodeGetComplexPattern(N, CGP))) {
         for (unsigned i = 0; i < CP->getNumOperands(); ++i) {
-          NodeOps.push_back("CPTmp" + utostr(i));
+          NodeOps.push_back("CPTmp" + Val + "_" + utostr(i));
         }
       } else {
         // This node, probably wrapped in a SDNodeXForm, behaves like a leaf
@@ -919,7 +925,8 @@ public:
       TreePatternNode *InstPatNode =
         isRoot ? (InstPat ? InstPat->getTree(0) : Pattern)
                : (InstPat ? InstPat->getTree(0) : NULL);
-      if (InstPatNode && InstPatNode->getOperator()->getName() == "set") {
+      if (InstPatNode && !InstPatNode->isLeaf() &&
+          InstPatNode->getOperator()->getName() == "set") {
         InstPatNode = InstPatNode->getChild(InstPatNode->getNumChildren()-1);
       }
       bool IsVariadic = isRoot && II.isVariadic;
@@ -971,7 +978,8 @@ public:
           emitCode("}");
         }
         emitCode("InChains.push_back(" + ChainName + ");");
-        emitCode(ChainName + " = CurDAG->getNode(ISD::TokenFactor, MVT::Other, "
+        emitCode(ChainName + " = CurDAG->getNode(ISD::TokenFactor, "
+                 "N.getDebugLoc(), MVT::Other, "
                  "&InChains[0], InChains.size());");
         if (GenDebug) {
           emitCode("CurDAG->setSubgraphColor(" + ChainName +".getNode(), \"yellow\");");
@@ -1052,6 +1060,10 @@ public:
 
       std::string Code = "Opc" + utostr(OpcNo);
 
+      if (!isRoot || (InputHasChain && !NodeHasChain))
+        // For call to "getTargetNode()".
+        Code += ", N.getDebugLoc()";
+
       emitOpcode(II.Namespace + "::" + II.TheDef->getName());
 
       // Output order: results, chain, flags
@@ -1177,16 +1189,13 @@ public:
                           ");");
       }
 
-      if (FoldedChains.size() > 0) {
-        std::string Code;
-        for (unsigned j = 0, e = FoldedChains.size(); j < e; j++) {
-          ReplaceFroms.push_back("SDValue(" +
-                                 FoldedChains[j].first + ".getNode(), " +
-                                 utostr(FoldedChains[j].second) +
-                                 ")");
-          ReplaceTos.push_back("SDValue(ResNode, " +
-                               utostr(NumResults+NumDstRegs) + ")");
-        }
+      for (unsigned j = 0, e = FoldedChains.size(); j < e; j++) {
+        ReplaceFroms.push_back("SDValue(" +
+                               FoldedChains[j].first + ".getNode(), " +
+                               utostr(FoldedChains[j].second) +
+                               ")");
+        ReplaceTos.push_back("SDValue(ResNode, " +
+                             utostr(NumResults+NumDstRegs) + ")");
       }
 
       if (NodeHasOutFlag) {
@@ -1387,6 +1396,7 @@ private:
               }
               std::string Decl = (!ResNodeDecled) ? "SDNode *" : "";
               emitCode(Decl + "ResNode = CurDAG->getCopyToReg(" + ChainName +
+                       ", " + RootName + ".getDebugLoc()" +
                        ", " + getQualifiedName(RR) +
                        ", " +  RootName + utostr(OpNo) + ", InFlag).getNode();");
               ResNodeDecled = true;
@@ -1821,9 +1831,6 @@ void DAGISelEmitter::EmitInstructionSelector(std::ostream &OS) {
       } else
         OpVTI->second.push_back(OpVTStr);
 
-      OS << "SDNode *Select_" << getLegalCName(OpName)
-         << OpVTStr << "(const SDValue &N) {\n";    
-
       // We want to emit all of the matching code now.  However, we want to emit
       // the matches in order of minimal cost.  Sort the patterns so the least
       // cost one is at the start.
@@ -1865,6 +1872,9 @@ void DAGISelEmitter::EmitInstructionSelector(std::ostream &OS) {
       // Next, reverse the list of patterns itself for the same reason.
       std::reverse(CodeForPatterns.begin(), CodeForPatterns.end());
     
+      OS << "SDNode *Select_" << getLegalCName(OpName)
+         << OpVTStr << "(const SDValue &N) {\n";    
+
       // Emit all of the patterns now, grouped together to share code.
       EmitPatterns(CodeForPatterns, 2, OS);
     
@@ -1893,8 +1903,8 @@ void DAGISelEmitter::EmitInstructionSelector(std::ostream &OS) {
      << "  std::vector<MVT> VTs;\n"
      << "  VTs.push_back(MVT::Other);\n"
      << "  VTs.push_back(MVT::Flag);\n"
-     << "  SDValue New = CurDAG->getNode(ISD::INLINEASM, VTs, &Ops[0], "
-                 "Ops.size());\n"
+     << "  SDValue New = CurDAG->getNode(ISD::INLINEASM, N.getDebugLoc(), "
+                 "VTs, &Ops[0], Ops.size());\n"
      << "  return New.getNode();\n"
      << "}\n\n";