diff options
Diffstat (limited to 'contrib/llvm/utils/TableGen/DAGISelEmitter.cpp')
| -rw-r--r-- | contrib/llvm/utils/TableGen/DAGISelEmitter.cpp | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/contrib/llvm/utils/TableGen/DAGISelEmitter.cpp b/contrib/llvm/utils/TableGen/DAGISelEmitter.cpp index 9592ab7052f4..62a0ff700725 100644 --- a/contrib/llvm/utils/TableGen/DAGISelEmitter.cpp +++ b/contrib/llvm/utils/TableGen/DAGISelEmitter.cpp @@ -110,9 +110,11 @@ struct PatternSortingPredicate { if (LHSPatSize < RHSPatSize) return true; if (LHSPatSize > RHSPatSize) return false; - // Sort based on the UID of the pattern, giving us a deterministic ordering - // if all other sorting conditions fail. - assert(LHS == RHS || LHS->ID != RHS->ID); + // Sort based on the UID of the pattern, to reflect source order. + // Note that this is not guaranteed to be unique, since a single source + // pattern may have been resolved into multiple match patterns due to + // alternative fragments. To ensure deterministic output, always use + // std::stable_sort with this predicate. return LHS->ID < RHS->ID; } }; @@ -137,13 +139,16 @@ void DAGISelEmitter::run(raw_ostream &OS) { "// When neither of the GET_DAGISEL* macros is defined, the functions\n" "// are emitted inline.\n\n"; - DEBUG(errs() << "\n\nALL PATTERNS TO MATCH:\n\n"; - for (CodeGenDAGPatterns::ptm_iterator I = CGP.ptm_begin(), - E = CGP.ptm_end(); I != E; ++I) { - errs() << "PATTERN: "; I->getSrcPattern()->dump(); - errs() << "\nRESULT: "; I->getDstPattern()->dump(); - errs() << "\n"; - }); + LLVM_DEBUG(errs() << "\n\nALL PATTERNS TO MATCH:\n\n"; + for (CodeGenDAGPatterns::ptm_iterator I = CGP.ptm_begin(), + E = CGP.ptm_end(); + I != E; ++I) { + errs() << "PATTERN: "; + I->getSrcPattern()->dump(); + errs() << "\nRESULT: "; + I->getDstPattern()->dump(); + errs() << "\n"; + }); // Add all the patterns to a temporary list so we can sort them. std::vector<const PatternToMatch*> Patterns; @@ -153,7 +158,8 @@ void DAGISelEmitter::run(raw_ostream &OS) { // We want to process the matches in order of minimal cost. Sort the patterns // so the least cost one is at the start. - std::sort(Patterns.begin(), Patterns.end(), PatternSortingPredicate(CGP)); + std::stable_sort(Patterns.begin(), Patterns.end(), + PatternSortingPredicate(CGP)); // Convert each variant of each pattern into a Matcher. |
