[llvm] [BOLT][DWARF][NFC] Refactor address writers (PR #98094)

Alexander Yermolovich via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 10 18:42:39 PDT 2024


================
@@ -613,48 +613,60 @@ void DWARFRewriter::updateDebugInfo() {
   }
 
   if (BC.isDWARF5Used()) {
-    AddrWriter = std::make_unique<DebugAddrWriterDwarf5>(&BC);
+    FinalAddrWriter = std::make_unique<DebugAddrWriterDwarf5>(&BC);
     RangeListsSectionWriter = std::make_unique<DebugRangeListsSectionWriter>();
-    DebugRangeListsSectionWriter::setAddressWriter(AddrWriter.get());
   } else {
-    AddrWriter = std::make_unique<DebugAddrWriter>(&BC);
+    FinalAddrWriter = std::make_unique<DebugAddrWriter>(&BC);
   }
 
   if (BC.isDWARFLegacyUsed()) {
     LegacyRangesSectionWriter = std::make_unique<DebugRangesSectionWriter>();
     LegacyRangesSectionWriter->initSection();
   }
 
-  DebugLoclistWriter::setAddressWriter(AddrWriter.get());
-
   uint32_t CUIndex = 0;
   std::mutex AccessMutex;
   // Needs to be invoked in the same order as CUs are processed.
-  auto createRangeLocList = [&](DWARFUnit &CU) -> DebugLocWriter * {
+  auto createRangeLocListAddressWriters =
+      [&](DWARFUnit &CU) -> DebugLocWriter * {
     std::lock_guard<std::mutex> Lock(AccessMutex);
     const uint16_t DwarfVersion = CU.getVersion();
     if (DwarfVersion >= 5) {
-      LocListWritersByCU[CUIndex] =
-          std::make_unique<DebugLoclistWriter>(CU, DwarfVersion, false);
+      auto AddrW = std::make_unique<DebugAddrWriterDwarf5>(
+          &BC, CU.getAddressByteSize(), CU.getAddrOffsetSectionBase());
+      DebugAddrWriter *AddressWriter =
+          AddressWritersByCU.insert({CU.getOffset(), std::move(AddrW)})
+              .first->second.get();
+      RangeListsSectionWriter->setAddressWriter(AddressWriter);
+      LocListWritersByCU[CUIndex] = std::make_unique<DebugLoclistWriter>(
+          CU, DwarfVersion, false, *AddressWriter);
 
       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);
+        DebugRangeListsSectionWriter *RangeListSectionWriter =
+            RangeListsWritersByCU
+                .insert({*DWOId, std::move(RangeListsSectionWriter)})
+                .first->second.get();
+        RangeListSectionWriter->setAddressWriter(AddressWriter);
----------------
ayermolo wrote:

Minor nit. Move above the insert. That way you don't need to do the whole .first->second to store in temp.

https://github.com/llvm/llvm-project/pull/98094


More information about the llvm-commits mailing list