X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=utils%2FTableGen%2FDAGISelEmitter.cpp;h=43513525579aaed2f8cc5f42fe453b51f73e128b;hb=0d52ff1f7b993750a74a5d4432273092de9af069;hp=3f86d2dade3968840e961b80f9efa469c9162b9a;hpb=28c04dab38fa7205fedbc8954f08e2250e84c273;p=oota-llvm.git diff --git a/utils/TableGen/DAGISelEmitter.cpp b/utils/TableGen/DAGISelEmitter.cpp index 3f86d2dade3..43513525579 100644 --- a/utils/TableGen/DAGISelEmitter.cpp +++ b/utils/TableGen/DAGISelEmitter.cpp @@ -522,8 +522,8 @@ public: if (NeedCheck) { std::string ParentName(RootName.begin(), RootName.end()-1); - emitCheck("CanBeFoldedBy(" + RootName + ".getNode(), " + ParentName + - ".getNode(), N.getNode())"); + emitCheck("IsLegalAndProfitableToFold(" + RootName + + ".getNode(), " + ParentName + ".getNode(), N.getNode())"); } } } @@ -583,11 +583,14 @@ public: emitInit("SDValue " + RootName + "1" + " = " + RootName + ".getOperand(" + utostr(1) + ");"); - emitCheck("isa(" + RootName + "1)"); + unsigned NTmp = TmpNo++; + emitCode("ConstantSDNode *Tmp" + utostr(NTmp) + + " = dyn_cast(" + RootName + "1);"); + emitCheck("Tmp" + utostr(NTmp)); const char *MaskPredicate = N->getOperator()->getName() == "or" ? "CheckOrMask(" : "CheckAndMask("; - emitCheck(MaskPredicate + RootName + "0, cast(" + - 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(Child->getLeafValue())) { - emitCheck("isa(" + RootName + ")"); + unsigned NTmp = TmpNo++; + emitCode("ConstantSDNode *Tmp"+ utostr(NTmp) + + " = dyn_cast("+ + RootName + ");"); + emitCheck("Tmp" + utostr(NTmp)); unsigned CTmp = TmpNo++; - emitCode("int64_t CN"+utostr(CTmp)+" = cast("+ - 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 @@ -1097,7 +1109,7 @@ public: // Generate MemOperandSDNodes nodes for each memory accesses covered by // this pattern. - if (II.isSimpleLoad | II.mayLoad | II.mayStore) { + if (II.mayLoad | II.mayStore) { std::vector::const_iterator mi, mie; for (mi = LSI.begin(), mie = LSI.end(); mi != mie; ++mi) { std::string LSIName = "LSI_" + *mi; @@ -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 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";