Skip to content

Commit 453b1a2

Browse files
authored
[LLVM][DWARF] Refactor code for generating DWARF V5 .debug_names (#82394)
[LLVM][DWARF] Refactor code for generating DWARF v5 .debug_names Refactor the code that uniques the entries and computes the bucket count for the DWARF V5 .debug_names accelerator table.
1 parent 9978f6a commit 453b1a2

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

llvm/include/llvm/BinaryFormat/Dwarf.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,25 @@ enum AcceleratorTable {
613613
DW_hash_function_djb = 0u
614614
};
615615

616+
// Uniquify the string hashes and calculate the bucket count for the
617+
// DWARF v5 Accelerator Table. NOTE: This function effectively consumes the
618+
// 'hashes' input parameter.
619+
inline uint32_t getDebugNamesBucketCount(MutableArrayRef<uint32_t> hashes,
620+
uint32_t &uniqueHashCount) {
621+
uint32_t BucketCount = 0;
622+
623+
sort(hashes);
624+
uniqueHashCount = llvm::unique(hashes) - hashes.begin();
625+
if (uniqueHashCount > 1024)
626+
BucketCount = uniqueHashCount / 4;
627+
else if (uniqueHashCount > 16)
628+
BucketCount = uniqueHashCount / 2;
629+
else
630+
BucketCount = std::max<uint32_t>(uniqueHashCount, 1);
631+
632+
return BucketCount;
633+
}
634+
616635
// Constants for the GNU pubnames/pubtypes extensions supporting gdb index.
617636
enum GDBIndexEntryKind {
618637
GIEK_NONE,

llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,12 @@ using namespace llvm;
3333

3434
void AccelTableBase::computeBucketCount() {
3535
// First get the number of unique hashes.
36-
std::vector<uint32_t> Uniques;
36+
SmallVector<uint32_t, 0> Uniques;
3737
Uniques.reserve(Entries.size());
3838
for (const auto &E : Entries)
3939
Uniques.push_back(E.second.HashValue);
40-
array_pod_sort(Uniques.begin(), Uniques.end());
41-
std::vector<uint32_t>::iterator P =
42-
std::unique(Uniques.begin(), Uniques.end());
4340

44-
UniqueHashCount = std::distance(Uniques.begin(), P);
45-
46-
if (UniqueHashCount > 1024)
47-
BucketCount = UniqueHashCount / 4;
48-
else if (UniqueHashCount > 16)
49-
BucketCount = UniqueHashCount / 2;
50-
else
51-
BucketCount = std::max<uint32_t>(UniqueHashCount, 1);
41+
BucketCount = llvm::dwarf::getDebugNamesBucketCount(Uniques, UniqueHashCount);
5242
}
5343

5444
void AccelTableBase::finalize(AsmPrinter *Asm, StringRef Prefix) {

0 commit comments

Comments
 (0)