[llvm] [LLVM][DWARF] Make dwarf::getDebugNamesBucketCount return a pair. (PR #83047)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 26 12:19:18 PST 2024
https://github.com/cmtice updated https://github.com/llvm/llvm-project/pull/83047
>From 840411da8d03e96207f582631983ee8d7700ba1d Mon Sep 17 00:00:00 2001
From: Caroline Tice <cmtice at google.com>
Date: Mon, 26 Feb 2024 10:50:12 -0800
Subject: [PATCH 1/2] [LLVM][DWARF] Make dwarf::getDebugNamesBucketCount return
a pair.
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.
---
llvm/include/llvm/BinaryFormat/Dwarf.h | 15 ++++++++-------
llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp | 4 +++-
2 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/Dwarf.h b/llvm/include/llvm/BinaryFormat/Dwarf.h
index 44c0030251b37e..e2d79785162e37 100644
--- a/llvm/include/llvm/BinaryFormat/Dwarf.h
+++ b/llvm/include/llvm/BinaryFormat/Dwarf.h
@@ -616,20 +616,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) {
- uint32_t BucketCount = 0;
+inline std::pair<uint32_t, uint32_t> getDebugNamesBucketAndHashCount(
+ MutableArrayRef<uint32_t> hashes) {
+ uint32_t uniqueHashCount = 0;
+ uint32_t bucketCount = 0;
sort(hashes);
uniqueHashCount = llvm::unique(hashes) - hashes.begin();
if (uniqueHashCount > 1024)
- BucketCount = uniqueHashCount / 4;
+ bucketCount = uniqueHashCount / 4;
else if (uniqueHashCount > 16)
- BucketCount = uniqueHashCount / 2;
+ 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.
diff --git a/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp b/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
index 23fc9b2e0410e0..94e9d5e9cb77ce 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
@@ -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) {
>From 8891de25fe74af966a627c6fe8725fcaedc8677d Mon Sep 17 00:00:00 2001
From: Caroline Tice <cmtice at google.com>
Date: Mon, 26 Feb 2024 12:17:40 -0800
Subject: [PATCH 2/2] [LLVM][DWARF] Make dwarf::getDebugNamesBucketCount return
a pair.
Fix clang-format issue. Avoid unnecessary declaration before
initialization.
---
llvm/include/llvm/BinaryFormat/Dwarf.h | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/Dwarf.h b/llvm/include/llvm/BinaryFormat/Dwarf.h
index e2d79785162e37..e5e6f2470d39a1 100644
--- a/llvm/include/llvm/BinaryFormat/Dwarf.h
+++ b/llvm/include/llvm/BinaryFormat/Dwarf.h
@@ -616,13 +616,12 @@ 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 std::pair<uint32_t, uint32_t> getDebugNamesBucketAndHashCount(
- MutableArrayRef<uint32_t> hashes) {
- uint32_t uniqueHashCount = 0;
+inline std::pair<uint32_t, uint32_t>
+getDebugNamesBucketAndHashCount(MutableArrayRef<uint32_t> hashes) {
uint32_t bucketCount = 0;
sort(hashes);
- uniqueHashCount = llvm::unique(hashes) - hashes.begin();
+ uint32_t uniqueHashCount = llvm::unique(hashes) - hashes.begin();
if (uniqueHashCount > 1024)
bucketCount = uniqueHashCount / 4;
else if (uniqueHashCount > 16)
More information about the llvm-commits
mailing list