Skip to content

Commit cf799b3

Browse files
authored
[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.
1 parent 779af9b commit cf799b3

File tree

4 files changed

+11
-29
lines changed

4 files changed

+11
-29
lines changed

llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "llvm/CodeGen/NonRelocatableStringpool.h"
1616
#include "llvm/DWARFLinker/Classic/DWARFLinkerCompileUnit.h"
1717
#include "llvm/DWARFLinker/DWARFLinkerBase.h"
18+
#include "llvm/DWARFLinker/IndexedValuesMap.h"
1819
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
1920
#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
2021
#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
@@ -33,25 +34,7 @@ namespace classic {
3334
class DeclContextTree;
3435

3536
using Offset2UnitMap = DenseMap<uint64_t, CompileUnit *>;
36-
37-
struct DebugDieValuePool {
38-
DenseMap<uint64_t, uint64_t> DieValueMap;
39-
SmallVector<uint64_t> DieValues;
40-
41-
uint64_t getValueIndex(uint64_t Value) {
42-
DenseMap<uint64_t, uint64_t>::iterator It = DieValueMap.find(Value);
43-
if (It == DieValueMap.end()) {
44-
It = DieValueMap.insert(std::make_pair(Value, DieValues.size())).first;
45-
DieValues.push_back(Value);
46-
}
47-
return It->second;
48-
}
49-
50-
void clear() {
51-
DieValueMap.clear();
52-
DieValues.clear();
53-
}
54-
};
37+
using DebugDieValuePool = IndexedValuesMap<uint64_t>;
5538

5639
/// DwarfEmitter presents interface to generate all debug info tables.
5740
class DwarfEmitter {

llvm/lib/DWARFLinker/Parallel/IndexedValuesMap.h renamed to llvm/include/llvm/DWARFLinker/IndexedValuesMap.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_LIB_DWARFLINKER_PARALLEL_INDEXEDVALUESMAP_H
10-
#define LLVM_LIB_DWARFLINKER_PARALLEL_INDEXEDVALUESMAP_H
9+
#ifndef LLVM_DWARFLINKER_INDEXEDVALUESMAP_H
10+
#define LLVM_DWARFLINKER_INDEXEDVALUESMAP_H
1111

1212
#include "llvm/ADT/DenseMap.h"
1313
#include "llvm/ADT/SmallVector.h"
@@ -16,8 +16,8 @@
1616

1717
namespace llvm {
1818
namespace dwarf_linker {
19-
namespace parallel {
2019

20+
/// This class stores values sequentually and assigns index to the each value.
2121
template <typename T> class IndexedValuesMap {
2222
public:
2323
uint64_t getValueIndex(T Value) {
@@ -29,7 +29,7 @@ template <typename T> class IndexedValuesMap {
2929
return It->second;
3030
}
3131

32-
const SmallVector<T> &getValues() { return Values; }
32+
const SmallVector<T> &getValues() const { return Values; }
3333

3434
void clear() {
3535
ValueToIndexMap.clear();
@@ -44,8 +44,7 @@ template <typename T> class IndexedValuesMap {
4444
SmallVector<T> Values;
4545
};
4646

47-
} // end of namespace parallel
4847
} // end of namespace dwarf_linker
4948
} // end of namespace llvm
5049

51-
#endif // LLVM_LIB_DWARFLINKER_PARALLEL_INDEXEDVALUESMAP_H
50+
#endif // LLVM_DWARFLINKER_INDEXEDVALUESMAP_H

llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,13 +2035,13 @@ void DWARFLinker::DIECloner::emitDebugAddrSection(
20352035
if (DwarfVersion < 5)
20362036
return;
20372037

2038-
if (AddrPool.DieValues.empty())
2038+
if (AddrPool.getValues().empty())
20392039
return;
20402040

20412041
MCSymbol *EndLabel = Emitter->emitDwarfDebugAddrsHeader(Unit);
20422042
patchAddrBase(*Unit.getOutputUnitDIE(),
20432043
DIEInteger(Emitter->getDebugAddrSectionSize()));
2044-
Emitter->emitDwarfDebugAddrs(AddrPool.DieValues,
2044+
Emitter->emitDwarfDebugAddrs(AddrPool.getValues(),
20452045
Unit.getOrigUnit().getAddressByteSize());
20462046
Emitter->emitDwarfDebugAddrsFooter(Unit, EndLabel);
20472047
}
@@ -2867,7 +2867,7 @@ Error DWARFLinker::link() {
28672867
if (TheDwarfEmitter != nullptr) {
28682868
TheDwarfEmitter->emitAbbrevs(Abbreviations, Options.TargetDWARFVersion);
28692869
TheDwarfEmitter->emitStrings(DebugStrPool);
2870-
TheDwarfEmitter->emitStringOffsets(StringOffsetPool.DieValues,
2870+
TheDwarfEmitter->emitStringOffsets(StringOffsetPool.getValues(),
28712871
Options.TargetDWARFVersion);
28722872
TheDwarfEmitter->emitLineStrings(DebugLineStrPool);
28732873
for (AccelTableKind TableKind : Options.AccelTables) {

llvm/lib/DWARFLinker/Parallel/DWARFLinkerUnit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#define LLVM_LIB_DWARFLINKER_PARALLEL_DWARFLINKERUNIT_H
1111

1212
#include "DWARFLinkerGlobalData.h"
13-
#include "IndexedValuesMap.h"
1413
#include "OutputSections.h"
1514
#include "llvm/CodeGen/DIE.h"
15+
#include "llvm/DWARFLinker/IndexedValuesMap.h"
1616
#include "llvm/DWARFLinker/Parallel/DWARFLinker.h"
1717
#include "llvm/DWARFLinker/StringPool.h"
1818
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"

0 commit comments

Comments
 (0)