Use a MapVector instead of an extra sort.
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 9 Mar 2015 22:08:37 +0000 (22:08 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 9 Mar 2015 22:08:37 +0000 (22:08 +0000)
This also has the advantage of not depending on the brittle getLabelBeginName.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231714 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/AsmPrinter/DwarfDebug.cpp
test/DebugInfo/X86/dwarf-aranges.ll

index 04dedbd3f6531871c6083f099b3b1b712440a37f..a4e5b8d3aab171f0bc48c9d2e7dff7f488f9a609 100644 (file)
@@ -287,13 +287,6 @@ static StringRef getObjCMethodName(StringRef In) {
   return In.slice(In.find(' ') + 1, In.find(']'));
 }
 
-// Helper for sorting sections into a stable output order.
-static bool SectionSort(const MCSection *A, const MCSection *B) {
-  std::string LA = (A ? A->getLabelBeginName() : "");
-  std::string LB = (B ? B->getLabelBeginName() : "");
-  return LA < LB;
-}
-
 // Add the various names to the Dwarf accelerator table names.
 // TODO: Determine whether or not we should add names for programs
 // that do not have a DW_AT_name or DW_AT_linkage_name field - this
@@ -1739,7 +1732,7 @@ struct ArangeSpan {
 // address we can tie back to a CU.
 void DwarfDebug::emitDebugARanges() {
   // Provides a unique id per text section.
-  DenseMap<const MCSection *, SmallVector<SymbolCU, 8>> SectionMap;
+  MapVector<const MCSection *, SmallVector<SymbolCU, 8>> SectionMap;
 
   // Filter labels by section.
   for (const SymbolCU &SCU : ArangeLabels) {
@@ -1756,20 +1749,10 @@ void DwarfDebug::emitDebugARanges() {
     }
   }
 
-  // Build a list of sections used.
-  std::vector<const MCSection *> Sections;
-  for (const auto &it : SectionMap) {
-    const MCSection *Section = it.first;
-    Sections.push_back(Section);
-  }
-
-  // Sort the sections into order.
-  // This is only done to ensure consistent output order across different runs.
-  std::sort(Sections.begin(), Sections.end(), SectionSort);
-
   // Add terminating symbols for each section.
-  for (unsigned ID = 0, E = Sections.size(); ID != E; ID++) {
-    const MCSection *Section = Sections[ID];
+  unsigned ID = 0;
+  for (const auto &I : SectionMap) {
+    const MCSection *Section = I.first;
     MCSymbol *Sym = nullptr;
 
     if (Section) {
@@ -1784,12 +1767,14 @@ void DwarfDebug::emitDebugARanges() {
 
     // Insert a final terminator.
     SectionMap[Section].push_back(SymbolCU(nullptr, Sym));
+    ++ID;
   }
 
   DenseMap<DwarfCompileUnit *, std::vector<ArangeSpan>> Spans;
 
-  for (const MCSection *Section : Sections) {
-    SmallVector<SymbolCU, 8> &List = SectionMap[Section];
+  for (auto &I : SectionMap) {
+    const MCSection *Section = I.first;
+    SmallVector<SymbolCU, 8> &List = I.second;
     if (List.size() < 2)
       continue;
 
index b7e99302cd436a7a7fa3ad6adc18762629892e21..57207c4717e8c65367cecf0fea68a5e194fc6519 100644 (file)
@@ -9,21 +9,21 @@
 ; -- alignment --
 ; CHECK-NEXT: .zero 4,255
 
+; <data section> - it should have made one span covering all vars in this CU.
+; CHECK-NEXT: .quad some_data
+; CHECK-NEXT: .quad .Ldebug_end0-some_data
+
+; <other sections> - it should have made one span covering all vars in this CU.
+; CHECK-NEXT: .quad some_other
+; CHECK-NEXT: .quad .Ldebug_end1-some_other
+
 ; <common symbols> - it should have made one span for each symbol.
 ; CHECK-NEXT: .quad some_bss
 ; CHECK-NEXT: .quad 4
 
-; <data section> - it should have made one span covering all vars in this CU.
-; CHECK-NEXT: .quad some_data
-; CHECK-NEXT: .quad .Ldebug_end1-some_data
-
 ; <text section> - it should have made one span covering all functions in this CU.
 ; CHECK-NEXT: .quad .Lfunc_begin0
-; CHECK-NEXT: .quad .Ldebug_end2-.Lfunc_begin0
-
-; <other sections> - it should have made one span covering all vars in this CU.
-; CHECK-NEXT: .quad some_other
-; CHECK-NEXT: .quad .Ldebug_end3-some_other
+; CHECK-NEXT: .quad .Ldebug_end3-.Lfunc_begin0
 
 ; -- finish --
 ; CHECK-NEXT: # ARange terminator