llvm.org GIT mirror llvm / 21ad392
Hoist all SDOperand declarations within a Select_{opcode}() to the top level to reduce stack memory usage. This is intended to work around the gcc bug. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26026 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 13 years ago
2 changed file(s) with 68 addition(s) and 35 deletion(s). Raw diff Collapse all Expand all
18531853 /// tested, and if true, the match fails) [when true] or normal code to emit
18541854 /// [when false].
18551855 std::vector > &GeneratedCode;
1856 /// GeneratedDecl - This is the set of all SDOperand declarations needed for
1857 /// the set of patterns for each top-level opcode.
1858 std::set &GeneratedDecl;
18561859
18571860 std::string ChainName;
18581861 bool DoReplace;
18661869 if (!S.empty())
18671870 GeneratedCode.push_back(std::make_pair(false, S));
18681871 }
1872 void emitDecl(const std::string &S) {
1873 assert(!S.empty() && "Invalid declaration");
1874 GeneratedDecl.insert(S);
1875 }
18691876 public:
18701877 PatternCodeEmitter(DAGISelEmitter &ise, ListInit *preds,
18711878 TreePatternNode *pattern, TreePatternNode *instr,
1872 std::vector > &gc, bool dorep)
1879 std::vector > &gc,
1880 std::set &gd,
1881 bool dorep)
18731882 : ISE(ise), Predicates(preds), Pattern(pattern), Instruction(instr),
1874 GeneratedCode(gc), DoReplace(dorep), TmpNo(0) {}
1883 GeneratedCode(gc), GeneratedDecl(gd), DoReplace(dorep), TmpNo(0) {}
18751884
18761885 /// EmitMatchCode - Emit a matcher for N, going to the label for PatternNo
18771886 /// if the match fails. At this point, we already know that the opcode for N
20012010 else
20022011 FoundChain = true;
20032012 ChainName = "Chain" + ChainSuffix;
2004 emitCode("SDOperand " + ChainName + " = " + RootName +
2013 emitDecl(ChainName);
2014 emitCode(ChainName + " = " + RootName +
20052015 ".getOperand(0);");
20062016 }
20072017 }
20292039 }
20302040
20312041 for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i, ++OpNo) {
2032 emitCode("SDOperand " + RootName + utostr(OpNo) + " = " +
2042 emitDecl(RootName + utostr(OpNo));
2043 emitCode(RootName + utostr(OpNo) + " = " +
20332044 RootName + ".getOperand(" +utostr(OpNo) + ");");
20342045 TreePatternNode *Child = N->getChild(i);
20352046
21362147 }
21372148 emitCode(CastType + " Tmp" + utostr(ResNo) + "C = (" + CastType +
21382149 ")cast(" + Val + ")->getValue();");
2139 emitCode("SDOperand Tmp" + utostr(ResNo) +
2150 emitDecl("Tmp" + utostr(ResNo));
2151 emitCode("Tmp" + utostr(ResNo) +
21402152 " = CurDAG->getTargetConstant(Tmp" + utostr(ResNo) +
21412153 "C, MVT::" + getEnumName(N->getTypeNum(0)) + ");");
21422154 } else if (!N->isLeaf() && N->getOperator()->getName() == "texternalsym"){
21432155 Record *Op = OperatorMap[N->getName()];
21442156 // Transform ExternalSymbol to TargetExternalSymbol
21452157 if (Op && Op->getName() == "externalsym") {
2146 emitCode("SDOperand Tmp" + utostr(ResNo) + " = CurDAG->getTarget"
2158 emitDecl("Tmp" + utostr(ResNo));
2159 emitCode("Tmp" + utostr(ResNo) + " = CurDAG->getTarget"
21472160 "ExternalSymbol(cast(" +
21482161 Val + ")->getSymbol(), MVT::" +
21492162 getEnumName(N->getTypeNum(0)) + ");");
21502163 } else {
2151 emitCode("SDOperand Tmp" + utostr(ResNo) + " = " + Val + ";");
2164 emitDecl("Tmp" + utostr(ResNo));
2165 emitCode("Tmp" + utostr(ResNo) + " = " + Val + ";");
21522166 }
21532167 } else if (!N->isLeaf() && N->getOperator()->getName() == "tglobaladdr") {
21542168 Record *Op = OperatorMap[N->getName()];
21552169 // Transform GlobalAddress to TargetGlobalAddress
21562170 if (Op && Op->getName() == "globaladdr") {
2157 emitCode("SDOperand Tmp" + utostr(ResNo) + " = CurDAG->getTarget"
2171 emitDecl("Tmp" + utostr(ResNo));
2172 emitCode("Tmp" + utostr(ResNo) + " = CurDAG->getTarget"
21582173 "GlobalAddress(cast(" + Val +
21592174 ")->getGlobal(), MVT::" + getEnumName(N->getTypeNum(0)) +
21602175 ");");
21612176 } else {
2162 emitCode("SDOperand Tmp" + utostr(ResNo) + " = " + Val + ";");
2177 emitDecl("Tmp" + utostr(ResNo));
2178 emitCode("Tmp" + utostr(ResNo) + " = " + Val + ";");
21632179 }
21642180 } else if (!N->isLeaf() && N->getOperator()->getName() == "texternalsym"){
2165 emitCode("SDOperand Tmp" + utostr(ResNo) + " = " + Val + ";");
2181 emitDecl("Tmp" + utostr(ResNo));
2182 emitCode("Tmp" + utostr(ResNo) + " = " + Val + ";");
21662183 } else if (!N->isLeaf() && N->getOperator()->getName() == "tconstpool") {
2167 emitCode("SDOperand Tmp" + utostr(ResNo) + " = " + Val + ";");
2184 emitDecl("Tmp" + utostr(ResNo));
2185 emitCode("Tmp" + utostr(ResNo) + " = " + Val + ";");
21682186 } else if (N->isLeaf() && (CP = NodeGetComplexPattern(N, ISE))) {
21692187 std::string Fn = CP->getSelectFunc();
21702188 NumRes = CP->getNumOperands();
2171 std::string Code = "SDOperand ";
2172 for (unsigned i = 0; i < NumRes - 1; ++i)
2173 Code += "Tmp" + utostr(i+ResNo) + ", ";
2174 emitCode(Code + "Tmp" + utostr(NumRes - 1 + ResNo) + ";");
2175
2176 Code = Fn + "(" + Val;
2189 for (unsigned i = 0; i < NumRes; ++i)
2190 emitDecl("Tmp" + utostr(i+ResNo));
2191
2192 std::string Code = Fn + "(" + Val;
21772193 for (unsigned i = 0; i < NumRes; i++)
21782194 Code += ", Tmp" + utostr(i + ResNo);
21792195 emitCheck(Code + ")");
21842200
21852201 TmpNo = ResNo + NumRes;
21862202 } else {
2187 emitCode("SDOperand Tmp" + utostr(ResNo) + " = Select(" + Val + ");");
2203 emitDecl("Tmp" + utostr(ResNo));
2204 emitCode("Tmp" + utostr(ResNo) + " = Select(" + Val + ");");
21882205 }
21892206 // Add Tmp to VariableMap, so that we don't multiply select this
21902207 // value if used multiple times by this pattern result.
21972214 if (DefInit *DI = dynamic_cast(N->getLeafValue())) {
21982215 unsigned ResNo = TmpNo++;
21992216 if (DI->getDef()->isSubClassOf("Register")) {
2200 emitCode("SDOperand Tmp" + utostr(ResNo) + " = CurDAG->getRegister(" +
2217 emitDecl("Tmp" + utostr(ResNo));
2218 emitCode("Tmp" + utostr(ResNo) + " = CurDAG->getRegister(" +
22012219 ISE.getQualifiedName(DI->getDef()) + ", MVT::" +
22022220 getEnumName(N->getTypeNum(0)) + ");");
22032221 return std::make_pair(1, ResNo);
22052223 } else if (IntInit *II = dynamic_cast(N->getLeafValue())) {
22062224 unsigned ResNo = TmpNo++;
22072225 assert(N->getExtTypes().size() == 1 && "Multiple types not handled!");
2208 emitCode("SDOperand Tmp" + utostr(ResNo) +
2226 emitDecl("Tmp" + utostr(ResNo));
2227 emitCode("Tmp" + utostr(ResNo) +
22092228 " = CurDAG->getTargetConstant(" + itostr(II->getValue()) +
22102229 ", MVT::" + getEnumName(N->getTypeNum(0)) + ");");
22112230 return std::make_pair(1, ResNo);
22352254 (isRoot && PatternHasProperty(Pattern, SDNodeInfo::SDNPHasChain, ISE));
22362255
22372256 if (HasInFlag || NodeHasOutFlag || HasOptInFlag || HasImpInputs)
2238 emitCode("SDOperand InFlag = SDOperand(0, 0);");
2257 emitDecl("InFlag");
22392258 if (HasOptInFlag)
22402259 emitCode("bool HasOptInFlag = false;");
22412260
22882307 unsigned NumResults = Inst.getNumResults();
22892308 unsigned ResNo = TmpNo++;
22902309 if (!isRoot) {
2310 emitDecl("Tmp" + utostr(ResNo));
22912311 std::string Code =
2292 "SDOperand Tmp" + utostr(ResNo) + " = CurDAG->getTargetNode(" +
2312 "Tmp" + utostr(ResNo) + " = CurDAG->getTargetNode(" +
22932313 II.Namespace + "::" + II.TheDef->getName();
22942314 if (N->getTypeNum(0) != MVT::isVoid)
22952315 Code += ", MVT::" + getEnumName(N->getTypeNum(0));
23082328 utostr(NumResults) + ");");
23092329 }
23102330 } else if (HasChain || NodeHasOutFlag) {
2331 emitDecl("Result");
23112332 if (HasOptInFlag) {
2312 emitCode("SDOperand Result = SDOperand(0, 0);");
2333 emitCode("Result = SDOperand(0, 0);");
23132334 unsigned FlagNo = (unsigned) NodeHasChain + Pattern->getNumChildren();
23142335 emitCode("if (HasOptInFlag)");
23152336 std::string Code = " Result = CurDAG->getTargetNode(" +
23512372 if (HasChain) Code += ", " + ChainName + ");";
23522373 emitCode(Code);
23532374 } else {
2354 std::string Code = "SDOperand Result = CurDAG->getTargetNode(" +
2375 std::string Code = "Result = CurDAG->getTargetNode(" +
23552376 II.Namespace + "::" + II.TheDef->getName();
23562377
23572378 // Output order: results, chain, flags
24682489 assert(N->getNumChildren() == 1 && "node xform should have one child!");
24692490 unsigned OpVal = EmitResultCode(N->getChild(0)).second;
24702491 unsigned ResNo = TmpNo++;
2471 emitCode("SDOperand Tmp" + utostr(ResNo) + " = Transform_" + Op->getName()
2492 emitDecl("Tmp" + utostr(ResNo));
2493 emitCode("Tmp" + utostr(ResNo) + " = Transform_" + Op->getName()
24722494 + "(Tmp" + utostr(OpVal) + ".Val);");
24732495 if (isRoot) {
24742496 emitCode("CodeGenMap[N] = Tmp" +utostr(ResNo) + ";");
25362558 emitCode("InFlag = Select(" + RootName + utostr(OpNo) + ");");
25372559 } else {
25382560 if (!ChainEmitted) {
2539 emitCode("SDOperand Chain = CurDAG->getEntryNode();");
2561 emitDecl("Chain");
2562 emitCode("Chain = CurDAG->getEntryNode();");
25402563 ChainName = "Chain";
25412564 ChainEmitted = true;
25422565 }
2543 emitCode("SDOperand " + RootName + "CR" + utostr(i) + ";");
2566 emitDecl(RootName + "CR" + utostr(i));
25442567 emitCode(RootName + "CR" + utostr(i) +
25452568 " = CurDAG->getCopyToReg(" + ChainName +
25462569 ", CurDAG->getRegister(" + ISE.getQualifiedName(RR) +
25892612 MVT::ValueType RVT = getRegisterValueType(RR, CGT);
25902613 if (RVT != MVT::Flag) {
25912614 if (!ChainEmitted) {
2592 emitCode("SDOperand Chain = CurDAG->getEntryNode();");
2615 emitDecl("Chain");
2616 emitCode("Chain = CurDAG->getEntryNode();");
25932617 ChainEmitted = true;
25942618 ChainName = "Chain";
25952619 }
26122636 /// succeeds. Returns true if the pattern is not guaranteed to match.
26132637 void DAGISelEmitter::GenerateCodeForPattern(PatternToMatch &Pattern,
26142638 std::vector > &GeneratedCode,
2639 std::set &GeneratedDecl,
26152640 bool DoReplace) {
26162641 PatternCodeEmitter Emitter(*this, Pattern.getPredicates(),
26172642 Pattern.getSrcPattern(), Pattern.getDstPattern(),
2618 GeneratedCode, DoReplace);
2643 GeneratedCode, GeneratedDecl, DoReplace);
26192644
26202645 // Emit the matcher, capturing named arguments in VariableMap.
26212646 bool FoundChain = false;
28692894 // cost one is at the start.
28702895 std::stable_sort(Patterns.begin(), Patterns.end(),
28712896 PatternSortingPredicate(*this));
2872
2897
28732898 typedef std::vector > CodeList;
2899 typedef std::set DeclSet;
28742900
28752901 std::vector > CodeForPatterns;
2902 std::set GeneratedDecl;
28762903 for (unsigned i = 0, e = Patterns.size(); i != e; ++i) {
28772904 CodeList GeneratedCode;
2878 GenerateCodeForPattern(*Patterns[i], GeneratedCode, OptSlctOrder);
2905 GenerateCodeForPattern(*Patterns[i], GeneratedCode, GeneratedDecl,
2906 OptSlctOrder);
28792907 CodeForPatterns.push_back(std::make_pair(Patterns[i], GeneratedCode));
28802908 }
28812909
29022930 exit(1);
29032931 }
29042932 }
2905
2933
2934 // Print all declarations.
2935 for (std::set::iterator I = GeneratedDecl.begin(),
2936 E = GeneratedDecl.end(); I != E; ++I)
2937 OS << " SDOperand " << *I << ";\n";
2938
29062939 // Loop through and reverse all of the CodeList vectors, as we will be
29072940 // accessing them from their logical front, but accessing the end of a
29082941 // vector is more efficient.
1515
1616 #include "TableGenBackend.h"
1717 #include "CodeGenTarget.h"
18 #include
1819
1920 namespace llvm {
2021 class Record;
404405 /// and emission of the instruction selector.
405406 ///
406407 class DAGISelEmitter : public TableGenBackend {
407 public:
408 //typedef std::pair PatternToMatch;
409408 private:
410409 RecordKeeper &Records;
411410 CodeGenTarget Target;
412
411
413412 std::map SDNodes;
414413 std::map > SDNodeXForms;
415414 std::map ComplexPatterns;
471470 std::vector &InstImpResults);
472471 void GenerateCodeForPattern(PatternToMatch &Pattern,
473472 std::vector > &GeneratedCode,
473 std::set &GeneratedDecl,
474474 bool UseGoto);
475475 void EmitPatterns(std::vector
476476 std::vector > > > &Patterns,