[llvm] [BOLT][DWARF][NFC] Refactor RangeListsWritersByCU (PR #95008)

Sayhaan Siddiqui via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 10 09:55:51 PDT 2024


https://github.com/sayhaan updated https://github.com/llvm/llvm-project/pull/95008

>From 997fff1bec96935882b03fa4de3565e07449e806 Mon Sep 17 00:00:00 2001
From: Sayhaan Siddiqui <sayhaan at meta.com>
Date: Mon, 10 Jun 2024 09:47:07 -0700
Subject: [PATCH 1/2] Refactor RangeListsWritersByCU

---
 bolt/include/bolt/Rewrite/DWARFRewriter.h | 11 +++++------
 bolt/lib/Rewrite/DWARFRewriter.cpp        | 14 ++++++--------
 2 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/bolt/include/bolt/Rewrite/DWARFRewriter.h b/bolt/include/bolt/Rewrite/DWARFRewriter.h
index 8dec32de9008e..91891cb28a4f1 100644
--- a/bolt/include/bolt/Rewrite/DWARFRewriter.h
+++ b/bolt/include/bolt/Rewrite/DWARFRewriter.h
@@ -82,12 +82,11 @@ class DWARFRewriter {
   using LocWriters = std::map<uint64_t, std::unique_ptr<DebugLocWriter>>;
   /// Use a separate location list writer for each compilation unit
   LocWriters LocListWritersByCU;
-
-  using RangeListsDWOWriers =
-      std::unordered_map<uint64_t,
-                         std::unique_ptr<DebugRangeListsSectionWriter>>;
-  /// Store Rangelists writer for each DWO CU.
-  RangeListsDWOWriers RangeListsWritersByCU;
+  
+  /// Stores and serializes information that will be put in to the
+  /// .debug_rnglists DWARF section.
+  /// Instance is created per DWO.
+  std::unique_ptr<DebugRangeListsSectionWriter> RangeListsWriter;
 
   std::mutex LocListDebugInfoPatchesMutex;
 
diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 8814ebbd10aa5..370ad19e1e2da 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -636,12 +636,10 @@ void DWARFRewriter::updateDebugInfo() {
           std::make_unique<DebugLoclistWriter>(CU, DwarfVersion, false);
 
       if (std::optional<uint64_t> DWOId = CU.getDWOId()) {
-        assert(RangeListsWritersByCU.count(*DWOId) == 0 &&
-               "RangeLists writer for DWO unit already exists.");
         auto RangeListsSectionWriter =
             std::make_unique<DebugRangeListsSectionWriter>();
         RangeListsSectionWriter->initSection(CU);
-        RangeListsWritersByCU[*DWOId] = std::move(RangeListsSectionWriter);
+        RangeListsWriter = std::move(RangeListsSectionWriter);
       }
 
     } else {
@@ -690,7 +688,7 @@ void DWARFRewriter::updateDebugInfo() {
       DebugLoclistWriter DebugLocDWoWriter(*Unit, Unit->getVersion(), true);
       DebugRangesSectionWriter *TempRangesSectionWriter = RangesSectionWriter;
       if (Unit->getVersion() >= 5) {
-        TempRangesSectionWriter = RangeListsWritersByCU[*DWOId].get();
+        TempRangesSectionWriter = RangeListsWriter.get();
       } else {
         RangesBase = RangesSectionWriter->getSectionOffset();
         setDwoRangesBase(*DWOId, *RangesBase);
@@ -1872,9 +1870,9 @@ void DWARFRewriter::updateDWP(DWARFUnit &CU,
 
   DebugRangeListsSectionWriter *RangeListssWriter = nullptr;
   if (CU.getVersion() == 5) {
-    assert(RangeListsWritersByCU.count(DWOId) != 0 &&
+    assert(RangeListsWriter &&
            "No RangeListsWriter for DWO ID.");
-    RangeListssWriter = RangeListsWritersByCU[DWOId].get();
+    RangeListssWriter = RangeListsWriter.get();
   }
   auto AddType = [&](unsigned int Index, uint32_t IndexVersion, uint64_t Offset,
                      uint64_t Length, uint64_t Hash) -> void {
@@ -2021,9 +2019,9 @@ void DWARFRewriter::writeDWOFiles(
 
   DebugRangeListsSectionWriter *RangeListssWriter = nullptr;
   if (CU.getVersion() == 5) {
-    assert(RangeListsWritersByCU.count(DWOId) != 0 &&
+    assert(RangeListsWriter &&
            "No RangeListsWriter for DWO ID.");
-    RangeListssWriter = RangeListsWritersByCU[DWOId].get();
+    RangeListssWriter = RangeListsWriter.get();
 
     // Handling .debug_rnglists.dwo separately. The original .o/.dwo might not
     // have .debug_rnglists so won't be part of the loop below.

>From 29b9112965ecf302de85a3f6b1ef1500f7749381 Mon Sep 17 00:00:00 2001
From: Sayhaan Siddiqui <sayhaan at meta.com>
Date: Mon, 10 Jun 2024 09:55:18 -0700
Subject: [PATCH 2/2] Formatting changes

---
 bolt/include/bolt/Rewrite/DWARFRewriter.h |  2 +-
 bolt/lib/Rewrite/DWARFRewriter.cpp        | 17 +++++++----------
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/bolt/include/bolt/Rewrite/DWARFRewriter.h b/bolt/include/bolt/Rewrite/DWARFRewriter.h
index 91891cb28a4f1..c9cc913d28717 100644
--- a/bolt/include/bolt/Rewrite/DWARFRewriter.h
+++ b/bolt/include/bolt/Rewrite/DWARFRewriter.h
@@ -82,7 +82,7 @@ class DWARFRewriter {
   using LocWriters = std::map<uint64_t, std::unique_ptr<DebugLocWriter>>;
   /// Use a separate location list writer for each compilation unit
   LocWriters LocListWritersByCU;
-  
+
   /// Stores and serializes information that will be put in to the
   /// .debug_rnglists DWARF section.
   /// Instance is created per DWO.
diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 370ad19e1e2da..abaa88bc48329 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -326,12 +326,11 @@ static cl::opt<bool> KeepARanges(
         "keep or generate .debug_aranges section if .gdb_index is written"),
     cl::Hidden, cl::cat(BoltCategory));
 
-static cl::opt<bool>
-DeterministicDebugInfo("deterministic-debuginfo",
-  cl::desc("disables parallel execution of tasks that may produce "
-           "nondeterministic debug info"),
-  cl::init(true),
-  cl::cat(BoltCategory));
+static cl::opt<bool> DeterministicDebugInfo(
+    "deterministic-debuginfo",
+    cl::desc("disables parallel execution of tasks that may produce "
+             "nondeterministic debug info"),
+    cl::init(true), cl::cat(BoltCategory));
 
 static cl::opt<std::string> DwarfOutputPath(
     "dwarf-output-path",
@@ -1870,8 +1869,7 @@ void DWARFRewriter::updateDWP(DWARFUnit &CU,
 
   DebugRangeListsSectionWriter *RangeListssWriter = nullptr;
   if (CU.getVersion() == 5) {
-    assert(RangeListsWriter &&
-           "No RangeListsWriter for DWO ID.");
+    assert(RangeListsWriter && "No RangeListsWriter for DWO ID.");
     RangeListssWriter = RangeListsWriter.get();
   }
   auto AddType = [&](unsigned int Index, uint32_t IndexVersion, uint64_t Offset,
@@ -2019,8 +2017,7 @@ void DWARFRewriter::writeDWOFiles(
 
   DebugRangeListsSectionWriter *RangeListssWriter = nullptr;
   if (CU.getVersion() == 5) {
-    assert(RangeListsWriter &&
-           "No RangeListsWriter for DWO ID.");
+    assert(RangeListsWriter && "No RangeListsWriter for DWO ID.");
     RangeListssWriter = RangeListsWriter.get();
 
     // Handling .debug_rnglists.dwo separately. The original .o/.dwo might not



More information about the llvm-commits mailing list