[llvm-commits] CVS: llvm/utils/TableGen/DAGISelEmitter.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Sep 26 14:59:46 PDT 2005



Changes in directory llvm/utils/TableGen:

DAGISelEmitter.cpp updated: 1.42 -> 1.43
---
Log message:

Emit the switch stmt cases in alphabetical order instead of pointer order,
which is not stable.


---
Diffs of the changes:  (+19 -4)

 DAGISelEmitter.cpp |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)


Index: llvm/utils/TableGen/DAGISelEmitter.cpp
diff -u llvm/utils/TableGen/DAGISelEmitter.cpp:1.42 llvm/utils/TableGen/DAGISelEmitter.cpp:1.43
--- llvm/utils/TableGen/DAGISelEmitter.cpp:1.42	Mon Sep 26 16:53:26 2005
+++ llvm/utils/TableGen/DAGISelEmitter.cpp	Mon Sep 26 16:59:35 2005
@@ -1200,6 +1200,20 @@
   }
 };
 
+
+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 @@
      << "    return Select(N.getOperand(0));\n";
     
   // Group the patterns by their top-level opcodes.
-  std::map<Record*, std::vector<PatternToMatch*> > PatternsByOpcode;
+  std::map<Record*, std::vector<PatternToMatch*>,
+           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<Record*, std::vector<PatternToMatch*> >::iterator
-       PBOI = PatternsByOpcode.begin(), E = PatternsByOpcode.end(); PBOI != E;
-       ++PBOI) {
+  for (std::map<Record*, std::vector<PatternToMatch*>,
+                CompareByRecordName>::iterator PBOI = PatternsByOpcode.begin(),
+       E = PatternsByOpcode.end(); PBOI != E; ++PBOI) {
     const SDNodeInfo &OpcodeInfo = getSDNodeInfo(PBOI->first);
     std::vector<PatternToMatch*> &Patterns = PBOI->second;
     






More information about the llvm-commits mailing list