Skip to content

Commit

Permalink
[LLVM][DWARF] Make dwarf::getDebugNamesBucketCount return a pair. (ll…
Browse files Browse the repository at this point in the history
…vm#83047)

llvm::dwarf::getDebugNamesBucketCount directly returns the bucket count,
via return statement, but it also returns the hash count via a
parameter. This changes the function to return them both as a std::pair,
in the return statement. It also changes the name of the function to
make it clear it returns both values.
  • Loading branch information
cmtice committed Feb 27, 2024
1 parent e7900e6 commit f066377
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
22 changes: 11 additions & 11 deletions llvm/include/llvm/BinaryFormat/Dwarf.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,21 +615,21 @@ enum AcceleratorTable {

// Uniquify the string hashes and calculate the bucket count for the
// DWARF v5 Accelerator Table. NOTE: This function effectively consumes the
// 'hashes' input parameter.
inline uint32_t getDebugNamesBucketCount(MutableArrayRef<uint32_t> hashes,
uint32_t &uniqueHashCount) {
// 'Hashes' input parameter.
inline std::pair<uint32_t, uint32_t>
getDebugNamesBucketAndHashCount(MutableArrayRef<uint32_t> Hashes) {
uint32_t BucketCount = 0;

sort(hashes);
uniqueHashCount = llvm::unique(hashes) - hashes.begin();
if (uniqueHashCount > 1024)
BucketCount = uniqueHashCount / 4;
else if (uniqueHashCount > 16)
BucketCount = uniqueHashCount / 2;
sort(Hashes);
uint32_t UniqueHashCount = llvm::unique(Hashes) - Hashes.begin();
if (UniqueHashCount > 1024)
BucketCount = UniqueHashCount / 4;
else if (UniqueHashCount > 16)
BucketCount = UniqueHashCount / 2;
else
BucketCount = std::max<uint32_t>(uniqueHashCount, 1);
BucketCount = std::max<uint32_t>(UniqueHashCount, 1);

return BucketCount;
return {BucketCount, UniqueHashCount};
}

// Constants for the GNU pubnames/pubtypes extensions supporting gdb index.
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ void AccelTableBase::computeBucketCount() {
for (const auto &E : Entries)
Uniques.push_back(E.second.HashValue);

BucketCount = llvm::dwarf::getDebugNamesBucketCount(Uniques, UniqueHashCount);
auto Counts = llvm::dwarf::getDebugNamesBucketAndHashCount(Uniques);
BucketCount = Counts.first;
UniqueHashCount = Counts.second;
}

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

0 comments on commit f066377

Please sign in to comment.