Skip to content

Commit d3016aa

Browse files
authored
[DWARF] Refactor .debug_names bucket count computation (#88087)
`getDebugNamesBucketAndHashCount` lures users to provide an array to compute the bucket count using an O(n log n) sort. This is inefficient as hash table based uniquifying is faster. The performance issue matters less for Clang as the number of names is relatively small. For `ld.lld --debug-names`, I plan to compute the unique hash count as a side product of parallel entry pool computation, and I just need a function to suggest a bucket count.
1 parent a454d92 commit d3016aa

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

llvm/include/llvm/BinaryFormat/Dwarf.h

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -613,23 +613,13 @@ 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 std::pair<uint32_t, uint32_t>
620-
getDebugNamesBucketAndHashCount(MutableArrayRef<uint32_t> Hashes) {
621-
uint32_t BucketCount = 0;
622-
623-
sort(Hashes);
624-
uint32_t UniqueHashCount = llvm::unique(Hashes) - Hashes.begin();
616+
// Return a suggested bucket count for the DWARF v5 Accelerator Table.
617+
inline uint32_t getDebugNamesBucketCount(uint32_t UniqueHashCount) {
625618
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, UniqueHashCount};
619+
return UniqueHashCount / 4;
620+
if (UniqueHashCount > 16)
621+
return UniqueHashCount / 2;
622+
return std::max<uint32_t>(UniqueHashCount, 1);
633623
}
634624

635625
// Constants for the GNU pubnames/pubtypes extensions supporting gdb index.

llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@
3232
using namespace llvm;
3333

3434
void AccelTableBase::computeBucketCount() {
35-
// First get the number of unique hashes.
3635
SmallVector<uint32_t, 0> Uniques;
3736
Uniques.reserve(Entries.size());
3837
for (const auto &E : Entries)
3938
Uniques.push_back(E.second.HashValue);
40-
41-
std::tie(BucketCount, UniqueHashCount) =
42-
llvm::dwarf::getDebugNamesBucketAndHashCount(Uniques);
39+
llvm::sort(Uniques);
40+
UniqueHashCount = llvm::unique(Uniques) - Uniques.begin();
41+
BucketCount = dwarf::getDebugNamesBucketCount(UniqueHashCount);
4342
}
4443

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

0 commit comments

Comments
 (0)