[llvm] cf799b3 - [DWARFLinker][NFC] Move common code into the base library: IndexedValuesMap. (#77437)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 18 03:29:49 PST 2024


Author: Alexey Lapshin
Date: 2024-01-18T14:29:46+03:00
New Revision: cf799b3d3badbcb0c028266daa73043c0d0462c1

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

LOG: [DWARFLinker][NFC] Move common code into the base library: IndexedValuesMap. (#77437)

This patch is extracted from #74725.
Both dwarflinkers contain similar classes for indexed values. Move the
code into the DWARFLinkerBase.

Added: 
    llvm/include/llvm/DWARFLinker/IndexedValuesMap.h

Modified: 
    llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h
    llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
    llvm/lib/DWARFLinker/Parallel/DWARFLinkerUnit.h

Removed: 
    llvm/lib/DWARFLinker/Parallel/IndexedValuesMap.h


################################################################################
diff  --git a/llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h b/llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h
index d3aaa3baadc47d..46d3f3148818b1 100644
--- a/llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h
+++ b/llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h
@@ -15,6 +15,7 @@
 #include "llvm/CodeGen/NonRelocatableStringpool.h"
 #include "llvm/DWARFLinker/Classic/DWARFLinkerCompileUnit.h"
 #include "llvm/DWARFLinker/DWARFLinkerBase.h"
+#include "llvm/DWARFLinker/IndexedValuesMap.h"
 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
@@ -33,25 +34,7 @@ namespace classic {
 class DeclContextTree;
 
 using Offset2UnitMap = DenseMap<uint64_t, CompileUnit *>;
-
-struct DebugDieValuePool {
-  DenseMap<uint64_t, uint64_t> DieValueMap;
-  SmallVector<uint64_t> DieValues;
-
-  uint64_t getValueIndex(uint64_t Value) {
-    DenseMap<uint64_t, uint64_t>::iterator It = DieValueMap.find(Value);
-    if (It == DieValueMap.end()) {
-      It = DieValueMap.insert(std::make_pair(Value, DieValues.size())).first;
-      DieValues.push_back(Value);
-    }
-    return It->second;
-  }
-
-  void clear() {
-    DieValueMap.clear();
-    DieValues.clear();
-  }
-};
+using DebugDieValuePool = IndexedValuesMap<uint64_t>;
 
 /// DwarfEmitter presents interface to generate all debug info tables.
 class DwarfEmitter {

diff  --git a/llvm/lib/DWARFLinker/Parallel/IndexedValuesMap.h b/llvm/include/llvm/DWARFLinker/IndexedValuesMap.h
similarity index 80%
rename from llvm/lib/DWARFLinker/Parallel/IndexedValuesMap.h
rename to llvm/include/llvm/DWARFLinker/IndexedValuesMap.h
index b592ce37937bc4..fadbeb168b5334 100644
--- a/llvm/lib/DWARFLinker/Parallel/IndexedValuesMap.h
+++ b/llvm/include/llvm/DWARFLinker/IndexedValuesMap.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIB_DWARFLINKER_PARALLEL_INDEXEDVALUESMAP_H
-#define LLVM_LIB_DWARFLINKER_PARALLEL_INDEXEDVALUESMAP_H
+#ifndef LLVM_DWARFLINKER_INDEXEDVALUESMAP_H
+#define LLVM_DWARFLINKER_INDEXEDVALUESMAP_H
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallVector.h"
@@ -16,8 +16,8 @@
 
 namespace llvm {
 namespace dwarf_linker {
-namespace parallel {
 
+/// This class stores values sequentually and assigns index to the each value.
 template <typename T> class IndexedValuesMap {
 public:
   uint64_t getValueIndex(T Value) {
@@ -29,7 +29,7 @@ template <typename T> class IndexedValuesMap {
     return It->second;
   }
 
-  const SmallVector<T> &getValues() { return Values; }
+  const SmallVector<T> &getValues() const { return Values; }
 
   void clear() {
     ValueToIndexMap.clear();
@@ -44,8 +44,7 @@ template <typename T> class IndexedValuesMap {
   SmallVector<T> Values;
 };
 
-} // end of namespace parallel
 } // end of namespace dwarf_linker
 } // end of namespace llvm
 
-#endif // LLVM_LIB_DWARFLINKER_PARALLEL_INDEXEDVALUESMAP_H
+#endif // LLVM_DWARFLINKER_INDEXEDVALUESMAP_H

diff  --git a/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp b/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
index ac2c26e5224078..db294169ceb9b8 100644
--- a/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
+++ b/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
@@ -2035,13 +2035,13 @@ void DWARFLinker::DIECloner::emitDebugAddrSection(
   if (DwarfVersion < 5)
     return;
 
-  if (AddrPool.DieValues.empty())
+  if (AddrPool.getValues().empty())
     return;
 
   MCSymbol *EndLabel = Emitter->emitDwarfDebugAddrsHeader(Unit);
   patchAddrBase(*Unit.getOutputUnitDIE(),
                 DIEInteger(Emitter->getDebugAddrSectionSize()));
-  Emitter->emitDwarfDebugAddrs(AddrPool.DieValues,
+  Emitter->emitDwarfDebugAddrs(AddrPool.getValues(),
                                Unit.getOrigUnit().getAddressByteSize());
   Emitter->emitDwarfDebugAddrsFooter(Unit, EndLabel);
 }
@@ -2867,7 +2867,7 @@ Error DWARFLinker::link() {
     if (TheDwarfEmitter != nullptr) {
       TheDwarfEmitter->emitAbbrevs(Abbreviations, Options.TargetDWARFVersion);
       TheDwarfEmitter->emitStrings(DebugStrPool);
-      TheDwarfEmitter->emitStringOffsets(StringOffsetPool.DieValues,
+      TheDwarfEmitter->emitStringOffsets(StringOffsetPool.getValues(),
                                          Options.TargetDWARFVersion);
       TheDwarfEmitter->emitLineStrings(DebugLineStrPool);
       for (AccelTableKind TableKind : Options.AccelTables) {

diff  --git a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerUnit.h b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerUnit.h
index 36c24372e49420..e16b82f696a2d8 100644
--- a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerUnit.h
+++ b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerUnit.h
@@ -10,9 +10,9 @@
 #define LLVM_LIB_DWARFLINKER_PARALLEL_DWARFLINKERUNIT_H
 
 #include "DWARFLinkerGlobalData.h"
-#include "IndexedValuesMap.h"
 #include "OutputSections.h"
 #include "llvm/CodeGen/DIE.h"
+#include "llvm/DWARFLinker/IndexedValuesMap.h"
 #include "llvm/DWARFLinker/Parallel/DWARFLinker.h"
 #include "llvm/DWARFLinker/StringPool.h"
 #include "llvm/DebugInfo/DWARF/DWARFUnit.h"


        


More information about the llvm-commits mailing list