[llvm] 599711d - [llvm-dwarfdump] StringMap -> MapVector to make iteration order stable

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 25 20:05:12 PST 2021


Author: Fangrui Song
Date: 2021-02-25T20:05:05-08:00
New Revision: 599711dce58719f137b82449fc9f9dee8f9252c4

URL: https://github.com/llvm/llvm-project/commit/599711dce58719f137b82449fc9f9dee8f9252c4
DIFF: https://github.com/llvm/llvm-project/commit/599711dce58719f137b82449fc9f9dee8f9252c4.diff

LOG: [llvm-dwarfdump] StringMap -> MapVector to make iteration order stable

Exposed by D97396

Added: 
    

Modified: 
    llvm/test/tools/llvm-dwarfdump/X86/section_sizes_coff.test
    llvm/test/tools/llvm-dwarfdump/X86/section_sizes_elf.test
    llvm/test/tools/llvm-dwarfdump/X86/section_sizes_macho.test
    llvm/test/tools/llvm-dwarfdump/X86/statistics.ll
    llvm/tools/llvm-dwarfdump/SectionSizes.cpp
    llvm/tools/llvm-dwarfdump/Statistics.cpp
    llvm/tools/llvm-dwarfdump/llvm-dwarfdump.h

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-dwarfdump/X86/section_sizes_coff.test b/llvm/test/tools/llvm-dwarfdump/X86/section_sizes_coff.test
index 7d72e02b946d..3f584dec439f 100644
--- a/llvm/test/tools/llvm-dwarfdump/X86/section_sizes_coff.test
+++ b/llvm/test/tools/llvm-dwarfdump/X86/section_sizes_coff.test
@@ -9,9 +9,9 @@
 # CHECK-NEXT:----------------------------------------------------
 # CHECK-NEXT:SECTION        SIZE (b)
 # CHECK-NEXT:-------------  --------
-# CHECK-NEXT:.debug_info           2 (0.70%)
-# CHECK-NEXT:.debug_abbrev         1 (0.35%)
 # CHECK-NEXT:.debug_str            1 (0.35%)
+# CHECK-NEXT:.debug_abbrev         1 (0.35%)
+# CHECK-NEXT:.debug_info           2 (0.70%)
 # CHECK-EMPTY:
 # CHECK-NEXT: Total Size: 4  (1.40%)
 # CHECK-NEXT: Total File Size: 286

diff  --git a/llvm/test/tools/llvm-dwarfdump/X86/section_sizes_elf.test b/llvm/test/tools/llvm-dwarfdump/X86/section_sizes_elf.test
index 5b2bb5344b2a..7d234e6f8ed9 100644
--- a/llvm/test/tools/llvm-dwarfdump/X86/section_sizes_elf.test
+++ b/llvm/test/tools/llvm-dwarfdump/X86/section_sizes_elf.test
@@ -10,11 +10,11 @@
 # CHECK-NEXT:SECTION          SIZE (b)
 # CHECK-NEXT:---------------  --------
 # CHECK-NEXT:.debug_info            17 (1.62%)
+# CHECK-NEXT:.debug_line            19 (1.81%)
 # CHECK-NEXT:.debug_loc              1 (0.10%)
 # CHECK-NEXT:.debug_type            26 (2.48%)
 # CHECK-NEXT:.debug_foo            100 (9.54%)
 # CHECK-NEXT:.debug_info.dwo         9 (0.86%)
-# CHECK-NEXT:.debug_line            19 (1.81%)
 # CHECK-EMPTY:
 # CHECK-NEXT: Total Size: 172  (16.41%)
 # CHECK-NEXT: Total File Size: 1048

diff  --git a/llvm/test/tools/llvm-dwarfdump/X86/section_sizes_macho.test b/llvm/test/tools/llvm-dwarfdump/X86/section_sizes_macho.test
index 2500c1730bf2..efa4cdd5829a 100644
--- a/llvm/test/tools/llvm-dwarfdump/X86/section_sizes_macho.test
+++ b/llvm/test/tools/llvm-dwarfdump/X86/section_sizes_macho.test
@@ -9,14 +9,14 @@
 # CHECK-NEXT:----------------------------------------------------
 # CHECK-NEXT:SECTION           SIZE (b)
 # CHECK-NEXT:----------------  --------
+# CHECK-NEXT:__debug_str            183 (9.78%)
+# CHECK-NEXT:__debug_abbrev          58 (3.10%)
 # CHECK-NEXT:__debug_info            83 (4.43%)
 # CHECK-NEXT:__apple_names           60 (3.21%)
-# CHECK-NEXT:__apple_types           71 (3.79%)
-# CHECK-NEXT:__debug_abbrev          58 (3.10%)
+# CHECK-NEXT:__apple_objc            36 (1.92%)
 # CHECK-NEXT:__apple_namespac        36 (1.92%)
+# CHECK-NEXT:__apple_types           71 (3.79%)
 # CHECK-NEXT:__debug_line            61 (3.26%)
-# CHECK-NEXT:__debug_str            183 (9.78%)
-# CHECK-NEXT:__apple_objc            36 (1.92%)
 # CHECK-EMPTY:
 # CHECK-NEXT: Total Size: 588  (31.41%)
 # CHECK-NEXT: Total File Size: 1872

diff  --git a/llvm/test/tools/llvm-dwarfdump/X86/statistics.ll b/llvm/test/tools/llvm-dwarfdump/X86/statistics.ll
index 8bf029a8944a..4ecff4faf423 100644
--- a/llvm/test/tools/llvm-dwarfdump/X86/statistics.ll
+++ b/llvm/test/tools/llvm-dwarfdump/X86/statistics.ll
@@ -54,15 +54,15 @@
 ; CHECK:      "sum_all_local_vars(#bytes in parent scope covered by DW_AT_location)":
 ; CHECK:      "#bytes within functions": [[FUNCSIZE:[0-9]+]]
 ; CHECK:      "#bytes within inlined functions": [[INLINESIZE:[0-9]+]]
-; CHECK:      "#bytes in __debug_info": 459,
-; CHECK-NEXT: "#bytes in __debug_loc": 35,
-; CHECK-NEXT: "#bytes in __apple_names": 348,
-; CHECK-NEXT: "#bytes in __apple_types": 133,
+; CHECK:      "#bytes in __debug_loc": 35,
 ; CHECK-NEXT: "#bytes in __debug_abbrev": 384,
-; CHECK-NEXT: "#bytes in __apple_namespac": 60,
-; CHECK-NEXT: "#bytes in __debug_line": 126,
+; CHECK-NEXT: "#bytes in __debug_info": 459,
 ; CHECK-NEXT: "#bytes in __debug_str": 231,
+; CHECK-NEXT: "#bytes in __apple_names": 348,
 ; CHECK-NEXT: "#bytes in __apple_objc": 36,
+; CHECK-NEXT: "#bytes in __apple_namespac": 60,
+; CHECK-NEXT: "#bytes in __apple_types": 133,
+; CHECK-NEXT: "#bytes in __debug_line": 126,
 
 ; ModuleID = '/tmp/quality.cpp'
 source_filename = "/tmp/quality.cpp"

diff  --git a/llvm/tools/llvm-dwarfdump/SectionSizes.cpp b/llvm/tools/llvm-dwarfdump/SectionSizes.cpp
index 8c456d50baa7..f13087ac39c1 100644
--- a/llvm/tools/llvm-dwarfdump/SectionSizes.cpp
+++ b/llvm/tools/llvm-dwarfdump/SectionSizes.cpp
@@ -18,10 +18,8 @@ static size_t getNameColumnWidth(const SectionSizes &Sizes,
                                  const StringRef SectionNameTitle) {
   // The minimum column width should be the size of "SECTION".
   size_t Width = SectionNameTitle.size();
-  for (const auto &DebugSec : Sizes.DebugSectionSizes) {
-    StringRef SectionName = DebugSec.getKey();
-    Width = std::max(Width, SectionName.size());
-  }
+  for (const auto &It : Sizes.DebugSectionSizes)
+    Width = std::max(Width, It.first.size());
   return Width;
 }
 
@@ -29,8 +27,8 @@ static size_t getSizeColumnWidth(const SectionSizes &Sizes,
                                  const StringRef SectionSizeTitle) {
   // The minimum column width should be the size of the column title.
   size_t Width = SectionSizeTitle.size();
-  for (const auto &DebugSec : Sizes.DebugSectionSizes) {
-    size_t NumWidth = std::to_string(DebugSec.getValue()).size();
+  for (const auto &It : Sizes.DebugSectionSizes) {
+    size_t NumWidth = std::to_string(It.second).size();
     Width = std::max(Width, NumWidth);
   }
   return Width;
@@ -59,13 +57,13 @@ static void prettyPrintSectionSizes(const ObjectFile &Obj,
     OS << "-";
   OS << '\n';
 
-  for (const auto &DebugSec : Sizes.DebugSectionSizes) {
-    OS << left_justify(DebugSec.getKey(), NameColWidth) << "  ";
+  for (const auto &It : Sizes.DebugSectionSizes) {
+    OS << left_justify(It.first, NameColWidth) << "  ";
 
-    auto NumBytes = std::to_string(DebugSec.getValue());
+    std::string NumBytes = std::to_string(It.second);
     OS << right_justify(NumBytes, SizeColWidth) << " ("
-       << format("%0.2f", DebugSec.getValue() /
-                              static_cast<double>(Sizes.TotalObjectSize) * 100)
+       << format("%0.2f",
+                 It.second / static_cast<double>(Sizes.TotalObjectSize) * 100)
        << "%)\n";
   }
 
@@ -99,7 +97,7 @@ void dwarfdump::calculateSectionSizes(const ObjectFile &Obj,
       continue;
 
     Sizes.TotalDebugSectionsSize += Section.getSize();
-    Sizes.DebugSectionSizes[SectionName] += Section.getSize();
+    Sizes.DebugSectionSizes[std::string(SectionName)] += Section.getSize();
   }
 }
 

diff  --git a/llvm/tools/llvm-dwarfdump/Statistics.cpp b/llvm/tools/llvm-dwarfdump/Statistics.cpp
index 7974980e2be0..3758a56da7a2 100644
--- a/llvm/tools/llvm-dwarfdump/Statistics.cpp
+++ b/llvm/tools/llvm-dwarfdump/Statistics.cpp
@@ -642,9 +642,8 @@ static void printLocationStats(json::OStream &J, const char *Key,
 }
 
 static void printSectionSizes(json::OStream &J, const SectionSizes &Sizes) {
-  for (const auto &DebugSec : Sizes.DebugSectionSizes)
-    J.attribute((Twine("#bytes in ") + DebugSec.getKey()).str(),
-                int64_t(DebugSec.getValue()));
+  for (const auto &It : Sizes.DebugSectionSizes)
+    J.attribute((Twine("#bytes in ") + It.first).str(), int64_t(It.second));
 }
 
 /// Stop tracking inlined variables with a location.

diff  --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.h b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.h
index dc41298265d2..cf7da56c91f8 100644
--- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.h
+++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.h
@@ -9,6 +9,8 @@
 #ifndef LLVM_TOOLS_LLVM_DWARFDUMP_LLVM_DWARFDUMP_H
 #define LLVM_TOOLS_LLVM_DWARFDUMP_LLVM_DWARFDUMP_H
 
+#include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
 #include "llvm/Object/ObjectFile.h"
@@ -21,7 +23,7 @@ namespace dwarfdump {
 struct SectionSizes {
   /// Map of .debug section names and their sizes across all such-named
   /// sections.
-  StringMap<uint64_t> DebugSectionSizes;
+  MapVector<std::string, uint64_t, StringMap<uint64_t>> DebugSectionSizes;
   /// Total number of bytes of all sections.
   uint64_t TotalObjectSize = 0;
   /// Total number of bytes of all debug sections.


        


More information about the llvm-commits mailing list