Skip to content

Commit 497a318

Browse files
committed
[DWARFLinker][NFC] Move common code into the base library: IndexedValuesMap.
This patch is extracted from llvm#74725. Both dwarflinkers contain similar classes for indexed values. Move the code into the DWARFLinkerBase.
1 parent 414ea3a commit 497a318

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
@@ -14,6 +14,7 @@
1414
#include "llvm/CodeGen/AccelTable.h"
1515
#include "llvm/CodeGen/NonRelocatableStringpool.h"
1616
#include "llvm/DWARFLinker/Classic/DWARFLinkerCompileUnit.h"
17+
#include "llvm/DWARFLinker/IndexedValuesMap.h"
1718
#include "llvm/DWARFLinker/DWARFLinkerBase.h"
1819
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
1920
#include "llvm/DebugInfo/DWARF/DWARFDebugLine.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
@@ -2048,13 +2048,13 @@ void DWARFLinker::DIECloner::emitDebugAddrSection(
20482048
if (DwarfVersion < 5)
20492049
return;
20502050

2051-
if (AddrPool.DieValues.empty())
2051+
if (AddrPool.getValues().empty())
20522052
return;
20532053

20542054
MCSymbol *EndLabel = Emitter->emitDwarfDebugAddrsHeader(Unit);
20552055
patchAddrBase(*Unit.getOutputUnitDIE(),
20562056
DIEInteger(Emitter->getDebugAddrSectionSize()));
2057-
Emitter->emitDwarfDebugAddrs(AddrPool.DieValues,
2057+
Emitter->emitDwarfDebugAddrs(AddrPool.getValues(),
20582058
Unit.getOrigUnit().getAddressByteSize());
20592059
Emitter->emitDwarfDebugAddrsFooter(Unit, EndLabel);
20602060
}
@@ -2880,7 +2880,7 @@ Error DWARFLinker::link() {
28802880
if (TheDwarfEmitter != nullptr) {
28812881
TheDwarfEmitter->emitAbbrevs(Abbreviations, Options.TargetDWARFVersion);
28822882
TheDwarfEmitter->emitStrings(DebugStrPool);
2883-
TheDwarfEmitter->emitStringOffsets(StringOffsetPool.DieValues,
2883+
TheDwarfEmitter->emitStringOffsets(StringOffsetPool.getValues(),
28842884
Options.TargetDWARFVersion);
28852885
TheDwarfEmitter->emitLineStrings(DebugLineStrPool);
28862886
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,10 +10,10 @@
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"
1615
#include "llvm/DWARFLinker/Parallel/DWARFLinker.h"
16+
#include "llvm/DWARFLinker/IndexedValuesMap.h"
1717
#include "llvm/DWARFLinker/StringPool.h"
1818
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
1919
#include "llvm/Support/LEB128.h"

0 commit comments

Comments
 (0)