Skip to content

Commit 361350f

Browse files
authored
[BOLT][DWARF] Deduplicate Foreign TU list (llvm#97629)
There could be multiple TUs with the same hash in various DWO files. In bigger binaries this could be in the thousands. Although they could be structurally different and we need to output Entries for all of them, for the purposes of figuring out a TU hash we only need one entry in Foreign TU list.
1 parent 94a067a commit 361350f

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

bolt/include/bolt/Core/DebugNames.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ class DWARF5AcceleratorTable {
9191
uint64_t CurrentUnitOffset = 0;
9292
const DWARFUnit *CurrentUnit = nullptr;
9393
std::unordered_map<uint32_t, uint32_t> AbbrevTagToIndexMap;
94+
/// Contains a map of TU hashes to a Foreign TU indecies.
95+
/// This is used to reduce the size of Foreign TU list since there could be
96+
/// multiple TUs with the same hash.
97+
DenseMap<uint64_t, uint32_t> TUHashToIndexMap;
9498

9599
/// Represents a group of entries with identical name (and hence, hash value).
96100
struct HashData {

bolt/lib/Core/DebugNames.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ void DWARF5AcceleratorTable::addUnit(DWARFUnit &Unit,
9090
auto Iter = CUOffsetsToPatch.insert({*DWOID, CUList.size()});
9191
if (Iter.second)
9292
CUList.push_back(BADCUOFFSET);
93-
ForeignTUList.push_back(cast<DWARFTypeUnit>(&Unit)->getTypeHash());
93+
const uint64_t TUHash = cast<DWARFTypeUnit>(&Unit)->getTypeHash();
94+
if (!TUHashToIndexMap.count(TUHash)) {
95+
TUHashToIndexMap.insert({TUHash, ForeignTUList.size()});
96+
ForeignTUList.push_back(TUHash);
97+
}
9498
} else {
9599
LocalTUList.push_back(CurrentUnitOffset);
96100
}
@@ -231,8 +235,13 @@ DWARF5AcceleratorTable::addAccelTableEntry(
231235
IsTU = Unit.isTypeUnit();
232236
DieTag = Die.getTag();
233237
if (IsTU) {
234-
if (DWOID)
235-
return ForeignTUList.size() - 1;
238+
if (DWOID) {
239+
const uint64_t TUHash = cast<DWARFTypeUnit>(&Unit)->getTypeHash();
240+
auto Iter = TUHashToIndexMap.find(TUHash);
241+
assert(Iter != TUHashToIndexMap.end() &&
242+
"Could not find TU hash in map");
243+
return Iter->second;
244+
}
236245
return LocalTUList.size() - 1;
237246
}
238247
return CUList.size() - 1;

bolt/test/X86/dwarf5-df-types-debug-names.test

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@
1818
; BOLT: type_signature = [[TYPE1:0x[0-9a-f]*]]
1919
; BOLT: Compile Unit
2020
; BOLT: type_signature = [[TYPE2:0x[0-9a-f]*]]
21-
; BOLT: type_signature = [[TYPE3:0x[0-9a-f]*]]
21+
; BOLT: type_signature = [[TYPE1]]
2222
; BOLT: Compile Unit
2323
; BOLT: [[OFFSET:0x[0-9a-f]*]]: Compile Unit
2424
; BOLT: [[OFFSET1:0x[0-9a-f]*]]: Compile Unit
2525

2626
; BOLT: Name Index @ 0x0 {
2727
; BOLT-NEXT: Header {
28-
; BOLT-NEXT: Length: 0x17E
28+
; BOLT-NEXT: Length: 0x176
2929
; BOLT-NEXT: Format: DWARF32
3030
; BOLT-NEXT: Version: 5
3131
; BOLT-NEXT: CU count: 2
3232
; BOLT-NEXT: Local TU count: 0
33-
; BOLT-NEXT: Foreign TU count: 4
33+
; BOLT-NEXT: Foreign TU count: 3
3434
; BOLT-NEXT: Bucket count: 9
3535
; BOLT-NEXT: Name count: 9
3636
; BOLT-NEXT: Abbreviations table size: 0x37
@@ -44,7 +44,6 @@
4444
; BOLT-NEXT: ForeignTU[0]: [[TYPE]]
4545
; BOLT-NEXT: ForeignTU[1]: [[TYPE1]]
4646
; BOLT-NEXT: ForeignTU[2]: [[TYPE2]]
47-
; BOLT-NEXT: ForeignTU[3]: [[TYPE3]]
4847
; BOLT-NEXT: ]
4948
; BOLT-NEXT: Abbreviations [
5049
; BOLT-NEXT: Abbreviation [[ABBREV:0x[0-9a-f]*]] {
@@ -173,7 +172,7 @@
173172
; BOLT-NEXT: Entry @ {{.+}} {
174173
; BOLT-NEXT: Abbrev: [[ABBREV]]
175174
; BOLT-NEXT: Tag: DW_TAG_structure_type
176-
; BOLT-NEXT: DW_IDX_type_unit: 0x03
175+
; BOLT-NEXT: DW_IDX_type_unit: 0x01
177176
; BOLT-NEXT: DW_IDX_compile_unit: 0x01
178177
; BOLT-NEXT: DW_IDX_die_offset: 0x00000021
179178
; BOLT-NEXT: DW_IDX_parent: <parent not indexed>
@@ -237,7 +236,7 @@
237236
; BOLT-NEXT: Entry @ {{.+}} {
238237
; BOLT-NEXT: Abbrev: 0x5
239238
; BOLT-NEXT: Tag: DW_TAG_base_type
240-
; BOLT-NEXT: DW_IDX_type_unit: 0x03
239+
; BOLT-NEXT: DW_IDX_type_unit: 0x01
241240
; BOLT-NEXT: DW_IDX_compile_unit: 0x01
242241
; BOLT-NEXT: DW_IDX_die_offset: 0x00000048
243242
; BOLT-NEXT: DW_IDX_parent: <parent not indexed>

0 commit comments

Comments
 (0)