[llvm] [BOLT][DWARF] Deduplicate Foreign TU list (PR #97629)
Alexander Yermolovich via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 3 12:57:42 PDT 2024
https://github.com/ayermolo created https://github.com/llvm/llvm-project/pull/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.
>From 6d14c76e448d3fe72a147e80c9dd5d575479e030 Mon Sep 17 00:00:00 2001
From: Alexander Yermolovich <ayermolo at meta.com>
Date: Wed, 3 Jul 2024 12:23:16 -0700
Subject: [PATCH] [BOLT][DWARF] Deduplicate Foreign TU list
Summary:
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.
Test Plan: ninja check-bolt
Reviewers: #llvm-bolt
Differential Revision: https://phabricator.intern.facebook.com/D59343146
Tasks: T188628025
---
bolt/include/bolt/Core/DebugNames.h | 4 ++++
bolt/lib/Core/DebugNames.cpp | 15 ++++++++++++---
bolt/test/X86/dwarf5-df-types-debug-names.test | 11 +++++------
3 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/bolt/include/bolt/Core/DebugNames.h b/bolt/include/bolt/Core/DebugNames.h
index a14a30529fad5..e0a8103802de9 100644
--- a/bolt/include/bolt/Core/DebugNames.h
+++ b/bolt/include/bolt/Core/DebugNames.h
@@ -91,6 +91,10 @@ class DWARF5AcceleratorTable {
uint64_t CurrentUnitOffset = 0;
const DWARFUnit *CurrentUnit = nullptr;
std::unordered_map<uint32_t, uint32_t> AbbrevTagToIndexMap;
+ /// Contains a map of TU hashes to a Foreign TU indecies.
+ /// This is used to reduce the size of Foreign TU list since there could be
+ /// multiple TUs with the same hash.
+ std::unordered_map<uint64_t, uint32_t> TUHashToIndexMap;
/// Represents a group of entries with identical name (and hence, hash value).
struct HashData {
diff --git a/bolt/lib/Core/DebugNames.cpp b/bolt/lib/Core/DebugNames.cpp
index ebe895e019ccb..640b29ec36d5c 100644
--- a/bolt/lib/Core/DebugNames.cpp
+++ b/bolt/lib/Core/DebugNames.cpp
@@ -90,7 +90,11 @@ void DWARF5AcceleratorTable::addUnit(DWARFUnit &Unit,
auto Iter = CUOffsetsToPatch.insert({*DWOID, CUList.size()});
if (Iter.second)
CUList.push_back(BADCUOFFSET);
- ForeignTUList.push_back(cast<DWARFTypeUnit>(&Unit)->getTypeHash());
+ const uint64_t TUHash = cast<DWARFTypeUnit>(&Unit)->getTypeHash();
+ if (!TUHashToIndexMap.count(TUHash)) {
+ TUHashToIndexMap.insert({TUHash, ForeignTUList.size()});
+ ForeignTUList.push_back(TUHash);
+ }
} else {
LocalTUList.push_back(CurrentUnitOffset);
}
@@ -231,8 +235,13 @@ DWARF5AcceleratorTable::addAccelTableEntry(
IsTU = Unit.isTypeUnit();
DieTag = Die.getTag();
if (IsTU) {
- if (DWOID)
- return ForeignTUList.size() - 1;
+ if (DWOID) {
+ const uint64_t TUHash = cast<DWARFTypeUnit>(&Unit)->getTypeHash();
+ auto Iter = TUHashToIndexMap.find(TUHash);
+ assert(Iter != TUHashToIndexMap.end() &&
+ "Could not find TU hash in map");
+ return Iter->second;
+ }
return LocalTUList.size() - 1;
}
return CUList.size() - 1;
diff --git a/bolt/test/X86/dwarf5-df-types-debug-names.test b/bolt/test/X86/dwarf5-df-types-debug-names.test
index f5a2c9c10353e..7c1c8e4fd5b38 100644
--- a/bolt/test/X86/dwarf5-df-types-debug-names.test
+++ b/bolt/test/X86/dwarf5-df-types-debug-names.test
@@ -18,19 +18,19 @@
; BOLT: type_signature = [[TYPE1:0x[0-9a-f]*]]
; BOLT: Compile Unit
; BOLT: type_signature = [[TYPE2:0x[0-9a-f]*]]
-; BOLT: type_signature = [[TYPE3:0x[0-9a-f]*]]
+; BOLT: type_signature = [[TYPE1]]
; BOLT: Compile Unit
; BOLT: [[OFFSET:0x[0-9a-f]*]]: Compile Unit
; BOLT: [[OFFSET1:0x[0-9a-f]*]]: Compile Unit
; BOLT: Name Index @ 0x0 {
; BOLT-NEXT: Header {
-; BOLT-NEXT: Length: 0x17E
+; BOLT-NEXT: Length: 0x176
; BOLT-NEXT: Format: DWARF32
; BOLT-NEXT: Version: 5
; BOLT-NEXT: CU count: 2
; BOLT-NEXT: Local TU count: 0
-; BOLT-NEXT: Foreign TU count: 4
+; BOLT-NEXT: Foreign TU count: 3
; BOLT-NEXT: Bucket count: 9
; BOLT-NEXT: Name count: 9
; BOLT-NEXT: Abbreviations table size: 0x37
@@ -44,7 +44,6 @@
; BOLT-NEXT: ForeignTU[0]: [[TYPE]]
; BOLT-NEXT: ForeignTU[1]: [[TYPE1]]
; BOLT-NEXT: ForeignTU[2]: [[TYPE2]]
-; BOLT-NEXT: ForeignTU[3]: [[TYPE3]]
; BOLT-NEXT: ]
; BOLT-NEXT: Abbreviations [
; BOLT-NEXT: Abbreviation [[ABBREV:0x[0-9a-f]*]] {
@@ -173,7 +172,7 @@
; BOLT-NEXT: Entry @ {{.+}} {
; BOLT-NEXT: Abbrev: [[ABBREV]]
; BOLT-NEXT: Tag: DW_TAG_structure_type
-; BOLT-NEXT: DW_IDX_type_unit: 0x03
+; BOLT-NEXT: DW_IDX_type_unit: 0x01
; BOLT-NEXT: DW_IDX_compile_unit: 0x01
; BOLT-NEXT: DW_IDX_die_offset: 0x00000021
; BOLT-NEXT: DW_IDX_parent: <parent not indexed>
@@ -237,7 +236,7 @@
; BOLT-NEXT: Entry @ {{.+}} {
; BOLT-NEXT: Abbrev: 0x5
; BOLT-NEXT: Tag: DW_TAG_base_type
-; BOLT-NEXT: DW_IDX_type_unit: 0x03
+; BOLT-NEXT: DW_IDX_type_unit: 0x01
; BOLT-NEXT: DW_IDX_compile_unit: 0x01
; BOLT-NEXT: DW_IDX_die_offset: 0x00000048
; BOLT-NEXT: DW_IDX_parent: <parent not indexed>
More information about the llvm-commits
mailing list