[llvm] [DWARFLinker][NFC] Move common code into the base library: IndexedValuesMap. (PR #77437)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 9 03:10:23 PST 2024
https://github.com/avl-llvm updated https://github.com/llvm/llvm-project/pull/77437
>From 497a318e302f24b0536fece7631073547e34a543 Mon Sep 17 00:00:00 2001
From: Alexey Lapshin <a.v.lapshin at mail.ru>
Date: Tue, 9 Jan 2024 13:11:31 +0300
Subject: [PATCH 1/2] [DWARFLinker][NFC] Move common code into the base
library: IndexedValuesMap.
This patch is extracted from #74725.
Both dwarflinkers contain similar classes for indexed values.
Move the code into the DWARFLinkerBase.
---
.../llvm/DWARFLinker/Classic/DWARFLinker.h | 21 ++-----------------
.../llvm/DWARFLinker}/IndexedValuesMap.h | 11 +++++-----
llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp | 6 +++---
.../DWARFLinker/Parallel/DWARFLinkerUnit.h | 2 +-
4 files changed, 11 insertions(+), 29 deletions(-)
rename llvm/{lib/DWARFLinker/Parallel => include/llvm/DWARFLinker}/IndexedValuesMap.h (80%)
diff --git a/llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h b/llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h
index d3aaa3baadc47d..0b26f05361860b 100644
--- a/llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h
+++ b/llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h
@@ -14,6 +14,7 @@
#include "llvm/CodeGen/AccelTable.h"
#include "llvm/CodeGen/NonRelocatableStringpool.h"
#include "llvm/DWARFLinker/Classic/DWARFLinkerCompileUnit.h"
+#include "llvm/DWARFLinker/IndexedValuesMap.h"
#include "llvm/DWARFLinker/DWARFLinkerBase.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugLine.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 8d76c3bcf672e7..c9f52919bf7d64 100644
--- a/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
+++ b/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
@@ -2048,13 +2048,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);
}
@@ -2880,7 +2880,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..f269da4ee1bd81 100644
--- a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerUnit.h
+++ b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerUnit.h
@@ -10,10 +10,10 @@
#define LLVM_LIB_DWARFLINKER_PARALLEL_DWARFLINKERUNIT_H
#include "DWARFLinkerGlobalData.h"
-#include "IndexedValuesMap.h"
#include "OutputSections.h"
#include "llvm/CodeGen/DIE.h"
#include "llvm/DWARFLinker/Parallel/DWARFLinker.h"
+#include "llvm/DWARFLinker/IndexedValuesMap.h"
#include "llvm/DWARFLinker/StringPool.h"
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
#include "llvm/Support/LEB128.h"
>From 32ec4254104339c4871d17e9d14b19430b17f7d3 Mon Sep 17 00:00:00 2001
From: Alexey Lapshin <a.v.lapshin at mail.ru>
Date: Tue, 9 Jan 2024 14:09:46 +0300
Subject: [PATCH 2/2] make formatter happy.
---
llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h | 2 +-
llvm/lib/DWARFLinker/Parallel/DWARFLinkerUnit.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h b/llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h
index 0b26f05361860b..46d3f3148818b1 100644
--- a/llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h
+++ b/llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h
@@ -14,8 +14,8 @@
#include "llvm/CodeGen/AccelTable.h"
#include "llvm/CodeGen/NonRelocatableStringpool.h"
#include "llvm/DWARFLinker/Classic/DWARFLinkerCompileUnit.h"
-#include "llvm/DWARFLinker/IndexedValuesMap.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"
diff --git a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerUnit.h b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerUnit.h
index f269da4ee1bd81..e16b82f696a2d8 100644
--- a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerUnit.h
+++ b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerUnit.h
@@ -12,8 +12,8 @@
#include "DWARFLinkerGlobalData.h"
#include "OutputSections.h"
#include "llvm/CodeGen/DIE.h"
-#include "llvm/DWARFLinker/Parallel/DWARFLinker.h"
#include "llvm/DWARFLinker/IndexedValuesMap.h"
+#include "llvm/DWARFLinker/Parallel/DWARFLinker.h"
#include "llvm/DWARFLinker/StringPool.h"
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
#include "llvm/Support/LEB128.h"
More information about the llvm-commits
mailing list