[llvm] [BOLT][DWARF][NFC] Split processUnitDIE into two lambdas (PR #99225)

Sayhaan Siddiqui via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 19 14:56:59 PDT 2024


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

>From f070a33364c8246e847267afe5826815c24975ed Mon Sep 17 00:00:00 2001
From: Sayhaan Siddiqui <sayhaan at meta.com>
Date: Tue, 16 Jul 2024 11:25:48 -0700
Subject: [PATCH 1/9] Split processUnitDIE into two lambdas

Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: https://phabricator.intern.facebook.com/D59822423
---
 bolt/lib/Rewrite/DWARFRewriter.cpp | 77 ++++++++++++++++--------------
 1 file changed, 40 insertions(+), 37 deletions(-)

diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 1ec216b39e95c..520fc1d2807f2 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -621,44 +621,47 @@ void DWARFRewriter::updateDebugInfo() {
   std::mutex AccessMutex;
   // Needs to be invoked in the same order as CUs are processed.
   auto createRangeLocListAddressWriters =
-      [&](DWARFUnit &CU) -> DebugLocWriter * {
-    std::lock_guard<std::mutex> Lock(AccessMutex);
-    const uint16_t DwarfVersion = CU.getVersion();
-    if (DwarfVersion >= 5) {
-      auto AddrW = std::make_unique<DebugAddrWriterDwarf5>(
-          &BC, CU.getAddressByteSize(), CU.getAddrOffsetSectionBase());
-      RangeListsSectionWriter->setAddressWriter(AddrW.get());
-      LocListWritersByCU[CUIndex] =
-          std::make_unique<DebugLoclistWriter>(CU, DwarfVersion, false, *AddrW);
-
-      if (std::optional<uint64_t> DWOId = CU.getDWOId()) {
-        assert(RangeListsWritersByCU.count(*DWOId) == 0 &&
-               "RangeLists writer for DWO unit already exists.");
-        auto DWORangeListsSectionWriter =
-            std::make_unique<DebugRangeListsSectionWriter>();
-        DWORangeListsSectionWriter->initSection(CU);
-        DWORangeListsSectionWriter->setAddressWriter(AddrW.get());
-        RangeListsWritersByCU[*DWOId] = std::move(DWORangeListsSectionWriter);
-      }
-      AddressWritersByCU[CU.getOffset()] = std::move(AddrW);
+      [&](DWARFUnit &CU,
+          llvm::DenseMap<uint64_t, uint64_t> &LocListWritersIndexByCU) {
+        std::lock_guard<std::mutex> Lock(AccessMutex);
 
-    } else {
-      auto AddrW =
-          std::make_unique<DebugAddrWriter>(&BC, CU.getAddressByteSize());
-      AddressWritersByCU[CU.getOffset()] = std::move(AddrW);
-      LocListWritersByCU[CUIndex] = std::make_unique<DebugLocWriter>();
-      if (std::optional<uint64_t> DWOId = CU.getDWOId()) {
-        assert(LegacyRangesWritersByCU.count(*DWOId) == 0 &&
-               "LegacyRangeLists writer for DWO unit already exists.");
-        auto LegacyRangesSectionWriterByCU =
-            std::make_unique<DebugRangesSectionWriter>();
-        LegacyRangesSectionWriterByCU->initSection(CU);
-        LegacyRangesWritersByCU[*DWOId] =
-            std::move(LegacyRangesSectionWriterByCU);
-      }
-    }
-    return LocListWritersByCU[CUIndex++].get();
-  };
+        const uint16_t DwarfVersion = CU.getVersion();
+        if (DwarfVersion >= 5) {
+          auto AddrW = std::make_unique<DebugAddrWriterDwarf5>(
+              &BC, CU.getAddressByteSize(), CU.getAddrOffsetSectionBase());
+          RangeListsSectionWriter->setAddressWriter(AddrW.get());
+          LocListWritersByCU[CUIndex] = std::make_unique<DebugLoclistWriter>(
+              CU, DwarfVersion, false, *AddrW);
+
+          if (std::optional<uint64_t> DWOId = CU.getDWOId()) {
+            assert(RangeListsWritersByCU.count(*DWOId) == 0 &&
+                   "RangeLists writer for DWO unit already exists.");
+            auto DWORangeListsSectionWriter =
+                std::make_unique<DebugRangeListsSectionWriter>();
+            DWORangeListsSectionWriter->initSection(CU);
+            DWORangeListsSectionWriter->setAddressWriter(AddrW.get());
+            RangeListsWritersByCU[*DWOId] =
+                std::move(DWORangeListsSectionWriter);
+          }
+          AddressWritersByCU[CU.getOffset()] = std::move(AddrW);
+
+        } else {
+          auto AddrW =
+              std::make_unique<DebugAddrWriter>(&BC, CU.getAddressByteSize());
+          AddressWritersByCU[CU.getOffset()] = std::move(AddrW);
+          LocListWritersByCU[CUIndex] = std::make_unique<DebugLocWriter>();
+          if (std::optional<uint64_t> DWOId = CU.getDWOId()) {
+            assert(LegacyRangesWritersByCU.count(*DWOId) == 0 &&
+                   "LegacyRangeLists writer for DWO unit already exists.");
+            auto LegacyRangesSectionWriterByCU =
+                std::make_unique<DebugRangesSectionWriter>();
+            LegacyRangesSectionWriterByCU->initSection(CU);
+            LegacyRangesWritersByCU[*DWOId] =
+                std::move(LegacyRangesSectionWriterByCU);
+          }
+        }
+        LocListWritersIndexByCU[CU.getOffset()] = CUIndex++;
+      };
 
   DWARF5AcceleratorTable DebugNamesTable(opts::CreateDebugNames, BC,
                                          *StrWriter);

>From 4452abc259515a76825ff50c5762343169e32d23 Mon Sep 17 00:00:00 2001
From: Sayhaan Siddiqui <sayhaan at meta.com>
Date: Thu, 18 Jul 2024 09:48:42 -0700
Subject: [PATCH 2/9] Updates to change RangesBase initialization

---
 bolt/lib/Rewrite/DWARFRewriter.cpp | 108 +++++++++++++++--------------
 1 file changed, 56 insertions(+), 52 deletions(-)

diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 520fc1d2807f2..72aae004f850a 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -669,71 +669,75 @@ void DWARFRewriter::updateDebugInfo() {
   DWPState State;
   if (opts::WriteDWP)
     initDWPState(State);
-  auto processUnitDIE = [&](DWARFUnit *Unit, DIEBuilder *DIEBlder) {
-    // Check if the unit is a skeleton and we need special updates for it and
-    // its matching split/DWO CU.
+  auto processSplitCU = [&](DWARFUnit *Unit, DIEBuilder *DIEBlder) {
     std::optional<DWARFUnit *> SplitCU;
     std::optional<uint64_t> RangesBase;
     std::optional<uint64_t> DWOId = Unit->getDWOId();
     if (DWOId)
       SplitCU = BC.getDWOCU(*DWOId);
-    DebugLocWriter *DebugLocWriter = createRangeLocListAddressWriters(*Unit);
-    DebugRangesSectionWriter *RangesSectionWriter =
-        Unit->getVersion() >= 5 ? RangeListsSectionWriter.get()
-                                : LegacyRangesSectionWriter.get();
-    DebugAddrWriter *AddressWriter =
-        AddressWritersByCU[Unit->getOffset()].get();
-    // Skipping CUs that failed to load.
-    if (SplitCU) {
-      DIEBuilder DWODIEBuilder(BC, &(*SplitCU)->getContext(), DebugNamesTable,
-                               Unit);
-      DWODIEBuilder.buildDWOUnit(**SplitCU);
-      std::string DWOName = "";
-      std::optional<std::string> DwarfOutputPath =
-          opts::DwarfOutputPath.empty()
-              ? std::nullopt
-              : std::optional<std::string>(opts::DwarfOutputPath.c_str());
-      {
-        std::lock_guard<std::mutex> Lock(AccessMutex);
-        DWOName = DIEBlder->updateDWONameCompDir(
-            *StrOffstsWriter, *StrWriter, *Unit, DwarfOutputPath, std::nullopt);
-      }
-      DebugStrOffsetsWriter DWOStrOffstsWriter(BC);
-      DebugStrWriter DWOStrWriter((*SplitCU)->getContext(), true);
-      DWODIEBuilder.updateDWONameCompDirForTypes(DWOStrOffstsWriter,
-                                                 DWOStrWriter, **SplitCU,
-                                                 DwarfOutputPath, DWOName);
-      DebugLoclistWriter DebugLocDWoWriter(*Unit, Unit->getVersion(), true,
-                                           *AddressWriter);
-      DebugRangesSectionWriter *TempRangesSectionWriter = RangesSectionWriter;
-      if (Unit->getVersion() >= 5) {
-        TempRangesSectionWriter = RangeListsWritersByCU[*DWOId].get();
-      } else {
-        TempRangesSectionWriter = LegacyRangesWritersByCU[*DWOId].get();
-        RangesBase = RangesSectionWriter->getSectionOffset();
-      }
-
-      updateUnitDebugInfo(*(*SplitCU), DWODIEBuilder, DebugLocDWoWriter,
-                          *TempRangesSectionWriter, *AddressWriter);
-      DebugLocDWoWriter.finalize(DWODIEBuilder,
-                                 *DWODIEBuilder.getUnitDIEbyUnit(**SplitCU));
-      if (Unit->getVersion() >= 5)
-        TempRangesSectionWriter->finalizeSection();
-
-      emitDWOBuilder(DWOName, DWODIEBuilder, *this, **SplitCU, *Unit, State,
-                     DebugLocDWoWriter, DWOStrOffstsWriter, DWOStrWriter,
-                     GDBIndexSection);
+    if (!SplitCU)
+      return;
+    DebugAddrWriter &AddressWriter =
+        *AddressWritersByCU[Unit->getOffset()].get();
+    DIEBuilder DWODIEBuilder(BC, &(*SplitCU)->getContext(), DebugNamesTable,
+                             Unit);
+    DWODIEBuilder.buildDWOUnit(**SplitCU);
+    std::string DWOName = "";
+    std::optional<std::string> DwarfOutputPath =
+        opts::DwarfOutputPath.empty()
+            ? std::nullopt
+            : std::optional<std::string>(opts::DwarfOutputPath.c_str());
+    {
+      std::lock_guard<std::mutex> Lock(AccessMutex);
+      DWOName = DIEBlder->updateDWONameCompDir(
+          *StrOffstsWriter, *StrWriter, *Unit, DwarfOutputPath, std::nullopt);
     }
+    DebugStrOffsetsWriter DWOStrOffstsWriter(BC);
+    DebugStrWriter DWOStrWriter((*SplitCU)->getContext(), true);
+    DWODIEBuilder.updateDWONameCompDirForTypes(
+        DWOStrOffstsWriter, DWOStrWriter, **SplitCU, DwarfOutputPath, DWOName);
+    DebugLoclistWriter DebugLocDWoWriter(*Unit, Unit->getVersion(), true,
+                                         AddressWriter);
+    DebugRangesSectionWriter *TempRangesSectionWriter;
+    if (Unit->getVersion() >= 5)
+      TempRangesSectionWriter = RangeListsWritersByCU[*DWOId].get();
+    else
+      TempRangesSectionWriter = LegacyRangesWritersByCU[*DWOId].get();
+  
+    updateUnitDebugInfo(*(*SplitCU), DWODIEBuilder, DebugLocDWoWriter,
+                        *TempRangesSectionWriter, AddressWriter);
+    DebugLocDWoWriter.finalize(DWODIEBuilder,
+                               *DWODIEBuilder.getUnitDIEbyUnit(**SplitCU));
+    if (Unit->getVersion() >= 5)
+      TempRangesSectionWriter->finalizeSection();
 
+    emitDWOBuilder(DWOName, DWODIEBuilder, *this, **SplitCU, *Unit, State,
+                   DebugLocDWoWriter, DWOStrOffstsWriter, DWOStrWriter,
+                   GDBIndexSection);
+  };
+  auto processMainBinaryCU = [&](DWARFUnit *Unit, DIEBuilder *DIEBlder,
+                                 DebugLocWriter *DebugLocWriter) {
+    DebugAddrWriter &AddressWriter =
+        *AddressWritersByCU[Unit->getOffset()].get();
+    DebugRangesSectionWriter &RangesSectionWriter =
+        Unit->getVersion() >= 5 ? *RangeListsSectionWriter.get()
+                                : *LegacyRangesSectionWriter.get();
+    std::optional<uint64_t> RangesBase;
+    std::optional<DWARFUnit *> SplitCU;
+    std::optional<uint64_t> DWOId = Unit->getDWOId();
+    if (DWOId)
+      SplitCU = BC.getDWOCU(*DWOId);
     if (Unit->getVersion() >= 5) {
       RangesBase = RangesSectionWriter->getSectionOffset() +
                    getDWARF5RngListLocListHeaderSize();
       RangesSectionWriter->initSection(*Unit);
       StrOffstsWriter->finalizeSection(*Unit, *DIEBlder);
+    } else if(SplitCU) {
+      RangesBase = LegacyRangesSectionWriter.get()->getSectionOffset();
     }
-
-    updateUnitDebugInfo(*Unit, *DIEBlder, *DebugLocWriter, *RangesSectionWriter,
-                        *AddressWriter, RangesBase);
+  
+    updateUnitDebugInfo(*Unit, *DIEBlder, *DebugLocWriter, RangesSectionWriter,
+                        AddressWriter, RangesBase);
     DebugLocWriter->finalize(*DIEBlder, *DIEBlder->getUnitDIEbyUnit(*Unit));
     if (Unit->getVersion() >= 5)
       RangesSectionWriter->finalizeSection();

>From ef2b571078ac0215e201ba83cc7f2cbcc0c4d0a4 Mon Sep 17 00:00:00 2001
From: Sayhaan Siddiqui <sayhaan at meta.com>
Date: Thu, 18 Jul 2024 09:50:46 -0700
Subject: [PATCH 3/9] Formatting changes

---
 bolt/lib/Rewrite/DWARFRewriter.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 72aae004f850a..151abdd9aca17 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -703,7 +703,7 @@ void DWARFRewriter::updateDebugInfo() {
       TempRangesSectionWriter = RangeListsWritersByCU[*DWOId].get();
     else
       TempRangesSectionWriter = LegacyRangesWritersByCU[*DWOId].get();
-  
+
     updateUnitDebugInfo(*(*SplitCU), DWODIEBuilder, DebugLocDWoWriter,
                         *TempRangesSectionWriter, AddressWriter);
     DebugLocDWoWriter.finalize(DWODIEBuilder,
@@ -732,10 +732,10 @@ void DWARFRewriter::updateDebugInfo() {
                    getDWARF5RngListLocListHeaderSize();
       RangesSectionWriter->initSection(*Unit);
       StrOffstsWriter->finalizeSection(*Unit, *DIEBlder);
-    } else if(SplitCU) {
+    } else if (SplitCU) {
       RangesBase = LegacyRangesSectionWriter.get()->getSectionOffset();
     }
-  
+
     updateUnitDebugInfo(*Unit, *DIEBlder, *DebugLocWriter, RangesSectionWriter,
                         AddressWriter, RangesBase);
     DebugLocWriter->finalize(*DIEBlder, *DIEBlder->getUnitDIEbyUnit(*Unit));

>From 2e87f2789b5033e9be68a0c5d389c7f8be27aba9 Mon Sep 17 00:00:00 2001
From: Sayhaan Siddiqui <sayhaan at meta.com>
Date: Thu, 18 Jul 2024 10:57:12 -0700
Subject: [PATCH 4/9] Formatting changes

---
 bolt/lib/Rewrite/DWARFRewriter.cpp | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 151abdd9aca17..5a6fd55c00fb1 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -698,11 +698,7 @@ void DWARFRewriter::updateDebugInfo() {
         DWOStrOffstsWriter, DWOStrWriter, **SplitCU, DwarfOutputPath, DWOName);
     DebugLoclistWriter DebugLocDWoWriter(*Unit, Unit->getVersion(), true,
                                          AddressWriter);
-    DebugRangesSectionWriter *TempRangesSectionWriter;
-    if (Unit->getVersion() >= 5)
-      TempRangesSectionWriter = RangeListsWritersByCU[*DWOId].get();
-    else
-      TempRangesSectionWriter = LegacyRangesWritersByCU[*DWOId].get();
+    DebugRangesSectionWriter *TempRangesSectionWriter = Unit->getVersion() >= 5 ? RangeListsWritersByCU[*DWOId].get() : LegacyRangesWritersByCU[*DWOId].get();
 
     updateUnitDebugInfo(*(*SplitCU), DWODIEBuilder, DebugLocDWoWriter,
                         *TempRangesSectionWriter, AddressWriter);

>From ede100a9c501c116ca5c5edce3a0bc3f908af35f Mon Sep 17 00:00:00 2001
From: Sayhaan Siddiqui <sayhaan at meta.com>
Date: Thu, 18 Jul 2024 11:02:33 -0700
Subject: [PATCH 5/9] Formatting changes

---
 bolt/lib/Rewrite/DWARFRewriter.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 5a6fd55c00fb1..25e5c1087dc77 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -698,7 +698,9 @@ void DWARFRewriter::updateDebugInfo() {
         DWOStrOffstsWriter, DWOStrWriter, **SplitCU, DwarfOutputPath, DWOName);
     DebugLoclistWriter DebugLocDWoWriter(*Unit, Unit->getVersion(), true,
                                          AddressWriter);
-    DebugRangesSectionWriter *TempRangesSectionWriter = Unit->getVersion() >= 5 ? RangeListsWritersByCU[*DWOId].get() : LegacyRangesWritersByCU[*DWOId].get();
+    DebugRangesSectionWriter *TempRangesSectionWriter =
+        Unit->getVersion() >= 5 ? RangeListsWritersByCU[*DWOId].get()
+                                : LegacyRangesWritersByCU[*DWOId].get();
 
     updateUnitDebugInfo(*(*SplitCU), DWODIEBuilder, DebugLocDWoWriter,
                         *TempRangesSectionWriter, AddressWriter);

>From 6fc3eb75b8947139f073fdc9f8bb04e4ba93387a Mon Sep 17 00:00:00 2001
From: Sayhaan Siddiqui <sayhaan at meta.com>
Date: Thu, 18 Jul 2024 13:24:03 -0700
Subject: [PATCH 6/9] Updates and formatting changes

---
 bolt/lib/Rewrite/DWARFRewriter.cpp | 48 ++++++++++++++----------------
 1 file changed, 23 insertions(+), 25 deletions(-)

diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 25e5c1087dc77..5aa7a0f7ad16d 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -644,7 +644,6 @@ void DWARFRewriter::updateDebugInfo() {
                 std::move(DWORangeListsSectionWriter);
           }
           AddressWritersByCU[CU.getOffset()] = std::move(AddrW);
-
         } else {
           auto AddrW =
               std::make_unique<DebugAddrWriter>(&BC, CU.getAddressByteSize());
@@ -669,18 +668,17 @@ void DWARFRewriter::updateDebugInfo() {
   DWPState State;
   if (opts::WriteDWP)
     initDWPState(State);
-  auto processSplitCU = [&](DWARFUnit *Unit, DIEBuilder *DIEBlder) {
+  auto processSplitCU = [&](DWARFUnit &Unit, DIEBuilder &DIEBlder) {
     std::optional<DWARFUnit *> SplitCU;
-    std::optional<uint64_t> RangesBase;
-    std::optional<uint64_t> DWOId = Unit->getDWOId();
+    std::optional<uint64_t> DWOId = Unit.getDWOId();
     if (DWOId)
       SplitCU = BC.getDWOCU(*DWOId);
     if (!SplitCU)
       return;
     DebugAddrWriter &AddressWriter =
-        *AddressWritersByCU[Unit->getOffset()].get();
+        *AddressWritersByCU[Unit.getOffset()].get();
     DIEBuilder DWODIEBuilder(BC, &(*SplitCU)->getContext(), DebugNamesTable,
-                             Unit);
+                             &Unit);
     DWODIEBuilder.buildDWOUnit(**SplitCU);
     std::string DWOName = "";
     std::optional<std::string> DwarfOutputPath =
@@ -689,56 +687,56 @@ void DWARFRewriter::updateDebugInfo() {
             : std::optional<std::string>(opts::DwarfOutputPath.c_str());
     {
       std::lock_guard<std::mutex> Lock(AccessMutex);
-      DWOName = DIEBlder->updateDWONameCompDir(
-          *StrOffstsWriter, *StrWriter, *Unit, DwarfOutputPath, std::nullopt);
+      DWOName = DIEBlder.updateDWONameCompDir(
+          *StrOffstsWriter, *StrWriter, Unit, DwarfOutputPath, std::nullopt);
     }
     DebugStrOffsetsWriter DWOStrOffstsWriter(BC);
     DebugStrWriter DWOStrWriter((*SplitCU)->getContext(), true);
     DWODIEBuilder.updateDWONameCompDirForTypes(
         DWOStrOffstsWriter, DWOStrWriter, **SplitCU, DwarfOutputPath, DWOName);
-    DebugLoclistWriter DebugLocDWoWriter(*Unit, Unit->getVersion(), true,
+    DebugLoclistWriter DebugLocDWoWriter(Unit, Unit.getVersion(), true,
                                          AddressWriter);
     DebugRangesSectionWriter *TempRangesSectionWriter =
-        Unit->getVersion() >= 5 ? RangeListsWritersByCU[*DWOId].get()
+        Unit.getVersion() >= 5 ? RangeListsWritersByCU[*DWOId].get()
                                 : LegacyRangesWritersByCU[*DWOId].get();
 
     updateUnitDebugInfo(*(*SplitCU), DWODIEBuilder, DebugLocDWoWriter,
                         *TempRangesSectionWriter, AddressWriter);
     DebugLocDWoWriter.finalize(DWODIEBuilder,
                                *DWODIEBuilder.getUnitDIEbyUnit(**SplitCU));
-    if (Unit->getVersion() >= 5)
+    if (Unit.getVersion() >= 5)
       TempRangesSectionWriter->finalizeSection();
 
-    emitDWOBuilder(DWOName, DWODIEBuilder, *this, **SplitCU, *Unit, State,
+    emitDWOBuilder(DWOName, DWODIEBuilder, *this, **SplitCU, Unit, State,
                    DebugLocDWoWriter, DWOStrOffstsWriter, DWOStrWriter,
                    GDBIndexSection);
   };
-  auto processMainBinaryCU = [&](DWARFUnit *Unit, DIEBuilder *DIEBlder,
-                                 DebugLocWriter *DebugLocWriter) {
+  auto processMainBinaryCU = [&](DWARFUnit &Unit, DIEBuilder &DIEBlder,
+                                 DebugLocWriter &DebugLocWriter) {
     DebugAddrWriter &AddressWriter =
-        *AddressWritersByCU[Unit->getOffset()].get();
+        *AddressWritersByCU[Unit.getOffset()].get();
     DebugRangesSectionWriter &RangesSectionWriter =
-        Unit->getVersion() >= 5 ? *RangeListsSectionWriter.get()
+        Unit.getVersion() >= 5 ? *RangeListsSectionWriter.get()
                                 : *LegacyRangesSectionWriter.get();
     std::optional<uint64_t> RangesBase;
     std::optional<DWARFUnit *> SplitCU;
-    std::optional<uint64_t> DWOId = Unit->getDWOId();
+    std::optional<uint64_t> DWOId = Unit.getDWOId();
     if (DWOId)
       SplitCU = BC.getDWOCU(*DWOId);
-    if (Unit->getVersion() >= 5) {
-      RangesBase = RangesSectionWriter->getSectionOffset() +
+    if (Unit.getVersion() >= 5) {
+      RangesBase = RangesSectionWriter.getSectionOffset() +
                    getDWARF5RngListLocListHeaderSize();
-      RangesSectionWriter->initSection(*Unit);
-      StrOffstsWriter->finalizeSection(*Unit, *DIEBlder);
+      RangesSectionWriter.initSection(Unit);
+      StrOffstsWriter->finalizeSection(Unit, DIEBlder);
     } else if (SplitCU) {
       RangesBase = LegacyRangesSectionWriter.get()->getSectionOffset();
     }
 
-    updateUnitDebugInfo(*Unit, *DIEBlder, *DebugLocWriter, RangesSectionWriter,
+    updateUnitDebugInfo(Unit, DIEBlder, DebugLocWriter, RangesSectionWriter,
                         AddressWriter, RangesBase);
-    DebugLocWriter->finalize(*DIEBlder, *DIEBlder->getUnitDIEbyUnit(*Unit));
-    if (Unit->getVersion() >= 5)
-      RangesSectionWriter->finalizeSection();
+    DebugLocWriter.finalize(DIEBlder, *DIEBlder.getUnitDIEbyUnit(Unit));
+    if (Unit.getVersion() >= 5)
+      RangesSectionWriter.finalizeSection();
   };
 
   DIEBuilder DIEBlder(BC, BC.DwCtx.get(), DebugNamesTable);

>From bed437dec946e574f79b1ad726526e7cf1ede225 Mon Sep 17 00:00:00 2001
From: Sayhaan Siddiqui <sayhaan at meta.com>
Date: Thu, 18 Jul 2024 13:29:15 -0700
Subject: [PATCH 7/9] Formatting change

---
 bolt/lib/Rewrite/DWARFRewriter.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 5aa7a0f7ad16d..477a9080f0c87 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -698,7 +698,7 @@ void DWARFRewriter::updateDebugInfo() {
                                          AddressWriter);
     DebugRangesSectionWriter *TempRangesSectionWriter =
         Unit.getVersion() >= 5 ? RangeListsWritersByCU[*DWOId].get()
-                                : LegacyRangesWritersByCU[*DWOId].get();
+                               : LegacyRangesWritersByCU[*DWOId].get();
 
     updateUnitDebugInfo(*(*SplitCU), DWODIEBuilder, DebugLocDWoWriter,
                         *TempRangesSectionWriter, AddressWriter);
@@ -717,7 +717,7 @@ void DWARFRewriter::updateDebugInfo() {
         *AddressWritersByCU[Unit.getOffset()].get();
     DebugRangesSectionWriter &RangesSectionWriter =
         Unit.getVersion() >= 5 ? *RangeListsSectionWriter.get()
-                                : *LegacyRangesSectionWriter.get();
+                               : *LegacyRangesSectionWriter.get();
     std::optional<uint64_t> RangesBase;
     std::optional<DWARFUnit *> SplitCU;
     std::optional<uint64_t> DWOId = Unit.getDWOId();

>From ee47e847d110cdf816d55ee2afba0ba2d8b04be1 Mon Sep 17 00:00:00 2001
From: Sayhaan Siddiqui <sayhaan at meta.com>
Date: Thu, 18 Jul 2024 14:40:23 -0700
Subject: [PATCH 8/9] Update code to be in new PR

---
 bolt/lib/Rewrite/DWARFRewriter.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 477a9080f0c87..20e6abfab4523 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -326,6 +326,12 @@ 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<std::string> DwarfOutputPath(
     "dwarf-output-path",
     cl::desc("Path to where .dwo files or dwp file will be written out to."),
@@ -601,6 +607,11 @@ void DWARFRewriter::updateDebugInfo() {
   StrWriter = std::make_unique<DebugStrWriter>(*BC.DwCtx, false);
   StrOffstsWriter = std::make_unique<DebugStrOffsetsWriter>(BC);
 
+  if (!opts::DeterministicDebugInfo) {
+    opts::DeterministicDebugInfo = true;
+    errs() << "BOLT-WARNING: --deterministic-debuginfo is being deprecated\n";
+  }
+
   /// Stores and serializes information that will be put into the
   /// .debug_addr DWARF section.
   std::unique_ptr<DebugAddrWriter> FinalAddrWriter;

>From 45867229f9ad2c0638df190868d26a984b23fbc6 Mon Sep 17 00:00:00 2001
From: Sayhaan Siddiqui <sayhaan at meta.com>
Date: Fri, 19 Jul 2024 14:55:29 -0700
Subject: [PATCH 9/9] Updates

---
 bolt/lib/Rewrite/DWARFRewriter.cpp | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 20e6abfab4523..2429c113d2d39 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -326,12 +326,6 @@ 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<std::string> DwarfOutputPath(
     "dwarf-output-path",
     cl::desc("Path to where .dwo files or dwp file will be written out to."),
@@ -607,11 +601,6 @@ void DWARFRewriter::updateDebugInfo() {
   StrWriter = std::make_unique<DebugStrWriter>(*BC.DwCtx, false);
   StrOffstsWriter = std::make_unique<DebugStrOffsetsWriter>(BC);
 
-  if (!opts::DeterministicDebugInfo) {
-    opts::DeterministicDebugInfo = true;
-    errs() << "BOLT-WARNING: --deterministic-debuginfo is being deprecated\n";
-  }
-
   /// Stores and serializes information that will be put into the
   /// .debug_addr DWARF section.
   std::unique_ptr<DebugAddrWriter> FinalAddrWriter;
@@ -765,8 +754,16 @@ void DWARFRewriter::updateDebugInfo() {
   CUPartitionVector PartVec = partitionCUs(*BC.DwCtx);
   for (std::vector<DWARFUnit *> &Vec : PartVec) {
     DIEBlder.buildCompileUnits(Vec);
-    for (DWARFUnit *CU : DIEBlder.getProcessedCUs())
-      processUnitDIE(CU, &DIEBlder);
+    llvm::DenseMap<uint64_t, uint64_t> LocListWritersIndexByCU;
+    for (DWARFUnit *CU : DIEBlder.getProcessedCUs()) {
+      createRangeLocListAddressWriters(*CU, LocListWritersIndexByCU);
+      processSplitCU(*CU, DIEBlder);
+    }
+    for (DWARFUnit *CU : DIEBlder.getProcessedCUs()) {
+      DebugLocWriter *DebugLocWriter =
+          LocListWritersByCU[LocListWritersIndexByCU[CU->getOffset()]].get();
+      processMainBinaryCU(*CU, DIEBlder, *DebugLocWriter);
+    }
     finalizeCompileUnits(DIEBlder, *Streamer, OffsetMap,
                          DIEBlder.getProcessedCUs(), *FinalAddrWriter);
   }



More information about the llvm-commits mailing list