Changes in directory llvm/utils/TableGen:
DAGISelEmitter.cpp updated: 1.151 -> 1.152 --- Log message: Split out code generation from analysis from emission --- Diffs of the changes: (+36 -14) DAGISelEmitter.cpp | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 36 insertions(+), 14 deletions(-) Index: llvm/utils/TableGen/DAGISelEmitter.cpp diff -u llvm/utils/TableGen/DAGISelEmitter.cpp:1.151 llvm/utils/TableGen/DAGISelEmitter.cpp:1.152 --- llvm/utils/TableGen/DAGISelEmitter.cpp:1.151 Sat Jan 28 20:43:35 2006 +++ llvm/utils/TableGen/DAGISelEmitter.cpp Sat Jan 28 20:57:39 2006 @@ -2647,16 +2647,43 @@ std::stable_sort(Patterns.begin(), Patterns.end(), PatternSortingPredicate(*this)); - bool mightNotMatch = true; + typedef std::vector<std::pair<bool, std::string> > CodeList; + + std::vector<std::pair<PatternToMatch*, CodeList> > CodeForPatterns; for (unsigned i = 0, e = Patterns.size(); i != e; ++i) { - PatternToMatch &Pattern = *Patterns[i]; - std::vector<std::pair<bool, std::string> > GeneratedCode; - EmitCodeForPattern(Pattern, GeneratedCode); + CodeList GeneratedCode; + EmitCodeForPattern(*Patterns[i], GeneratedCode); + CodeForPatterns.push_back(std::make_pair(Patterns[i], GeneratedCode)); + } + + // Scan the code to see if all of the patterns are reachable and if it is + // possible that the last one might not match. + bool mightNotMatch = true; + for (unsigned i = 0, e = CodeForPatterns.size(); i != e; ++i) { + CodeList &GeneratedCode = CodeForPatterns[i].second; + mightNotMatch = false; - static unsigned PatternCount = 0; - unsigned PatternNo = PatternCount++; + for (unsigned j = 0, e = GeneratedCode.size(); j != e; ++j) { + if (GeneratedCode[j].first) { // predicate. + mightNotMatch = true; + break; + } + } + + // If this pattern definitely matches, and if it isn't the last one, the + // patterns after it CANNOT ever match. Error out. + if (mightNotMatch == false && i != CodeForPatterns.size()-1) { + std::cerr << "Pattern '"; + CodeForPatterns[i+1].first->getSrcPattern()->print(OS); + std::cerr << "' is impossible to select!\n"; + exit(1); + } + } - OS << " { // Pattern #" << PatternNo << ": "; + for (unsigned i = 0, e = CodeForPatterns.size(); i != e; ++i) { + CodeList &GeneratedCode = CodeForPatterns[i].second; + PatternToMatch &Pattern = *CodeForPatterns[i].first; + OS << " { // Pattern: "; Pattern.getSrcPattern()->print(OS); OS << "\n // Emits: "; Pattern.getDstPattern()->print(OS); @@ -2683,15 +2710,10 @@ OS << std::string(Indent-2, ' ') << "}\n"; OS << " }\n"; - - if (!mightNotMatch && i != Patterns.size()-1) { - std::cerr << "Pattern " - << Patterns[i+1]->getDstPattern()->getOperator()->getName() - << " is impossible to select!\n"; - exit(1); - } } + // If the last pattern has predicates (which could fail) emit code to catch + // the case where nothing handles a pattern. if (mightNotMatch) OS << " std::cerr << \"Cannot yet select: \";\n" << " N.Val->dump(CurDAG);\n" _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits