From 3748147aaf73cba847ffad30a55de7e7df214b13 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 26 Sep 2005 21:59:35 +0000 Subject: [PATCH] Emit the switch stmt cases in alphabetical order instead of pointer order, which is not stable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23456 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/DAGISelEmitter.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/utils/TableGen/DAGISelEmitter.cpp b/utils/TableGen/DAGISelEmitter.cpp index 77067806f2d..bd439093c17 100644 --- a/utils/TableGen/DAGISelEmitter.cpp +++ b/utils/TableGen/DAGISelEmitter.cpp @@ -1200,6 +1200,20 @@ struct PatternSortingPredicate { } }; + +namespace { + /// CompareByRecordName - An ordering predicate that implements less-than by + /// comparing the names records. + struct CompareByRecordName { + bool operator()(const Record *LHS, const Record *RHS) const { + // Sort by name first. + if (LHS->getName() < RHS->getName()) return true; + // If both names are equal, sort by pointer. + return LHS->getName() == RHS->getName() && LHS < RHS; + } + }; +} + void DAGISelEmitter::EmitInstructionSelector(std::ostream &OS) { // Emit boilerplate. OS << "// The main instruction selector code.\n" @@ -1220,15 +1234,16 @@ void DAGISelEmitter::EmitInstructionSelector(std::ostream &OS) { << " return Select(N.getOperand(0));\n"; // Group the patterns by their top-level opcodes. - std::map > PatternsByOpcode; + std::map, + CompareByRecordName> PatternsByOpcode; for (unsigned i = 0, e = PatternsToMatch.size(); i != e; ++i) PatternsByOpcode[PatternsToMatch[i].first->getOperator()] .push_back(&PatternsToMatch[i]); // Loop over all of the case statements. - for (std::map >::iterator - PBOI = PatternsByOpcode.begin(), E = PatternsByOpcode.end(); PBOI != E; - ++PBOI) { + for (std::map, + CompareByRecordName>::iterator PBOI = PatternsByOpcode.begin(), + E = PatternsByOpcode.end(); PBOI != E; ++PBOI) { const SDNodeInfo &OpcodeInfo = getSDNodeInfo(PBOI->first); std::vector &Patterns = PBOI->second; -- 2.34.1