[llvm] [LLVM][DWARF] Make dwarf::getDebugNamesBucketCount return a pair. (PR #83047)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 26 20:22:04 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/5] [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/5] [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)
>From 59d394945b6c953c1ddb9ef2e38418ded2f2434c Mon Sep 17 00:00:00 2001
From: Caroline Tice <cmtice at google.com>
Date: Mon, 26 Feb 2024 14:12:59 -0800
Subject: [PATCH 3/5] [LLVM][DWARF] Make dwarf::getDebugNamesBucketCount return
a pair.
Make local variables start with uppercase letter.
---
llvm/include/llvm/BinaryFormat/Dwarf.h | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/Dwarf.h b/llvm/include/llvm/BinaryFormat/Dwarf.h
index e5e6f2470d39a1..5990ff4e09b7a5 100644
--- a/llvm/include/llvm/BinaryFormat/Dwarf.h
+++ b/llvm/include/llvm/BinaryFormat/Dwarf.h
@@ -617,19 +617,19 @@ enum AcceleratorTable {
// 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 bucketCount = 0;
-
- sort(hashes);
- uint32_t uniqueHashCount = llvm::unique(hashes) - hashes.begin();
- if (uniqueHashCount > 1024)
- bucketCount = uniqueHashCount / 4;
- else if (uniqueHashCount > 16)
- bucketCount = uniqueHashCount / 2;
+getDebugNamesBucketAndHashCount(MutableArrayRef<uint32_t> Hashes) {
+ uint32_t BucketCount = 0;
+
+ 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, uniqueHashCount};
+ return {BucketCount, UniqueHashCount};
}
// Constants for the GNU pubnames/pubtypes extensions supporting gdb index.
>From 821b902590f0ee1f7b65be2fbe74769ec5909667 Mon Sep 17 00:00:00 2001
From: Caroline Tice <cmtice at google.com>
Date: Mon, 26 Feb 2024 14:18:32 -0800
Subject: [PATCH 4/5] [LLVM][DWARF] Make dwarf::getDebugNamesBucketCount return
a pair.
Make local variables start with uppercase letter.
---
llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp b/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
index 94e9d5e9cb77ce..9e1727a0b8d138 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
@@ -38,9 +38,9 @@ void AccelTableBase::computeBucketCount() {
for (const auto &E : Entries)
Uniques.push_back(E.second.HashValue);
- auto counts = llvm::dwarf::getDebugNamesBucketAndHashCount(Uniques);
- BucketCount = counts.first;
- UniqueHashCount = counts.second;
+ auto Counts = llvm::dwarf::getDebugNamesBucketAndHashCount(Uniques);
+ BucketCount = Counts.first;
+ UniqueHashCount = Counts.second;
}
void AccelTableBase::finalize(AsmPrinter *Asm, StringRef Prefix) {
>From 380c69edda0c0bf24499ba1ae8439f106038bac9 Mon Sep 17 00:00:00 2001
From: Caroline Tice <cmtice at google.com>
Date: Mon, 26 Feb 2024 20:20:48 -0800
Subject: [PATCH 5/5] [LLVM][DWARF] Make dwarf::getDebugNamesBucketCount return
a pair.
Fix case of parameter in comment.
---
llvm/include/llvm/BinaryFormat/Dwarf.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/include/llvm/BinaryFormat/Dwarf.h b/llvm/include/llvm/BinaryFormat/Dwarf.h
index 5990ff4e09b7a5..a53e79bf6e39c1 100644
--- a/llvm/include/llvm/BinaryFormat/Dwarf.h
+++ b/llvm/include/llvm/BinaryFormat/Dwarf.h
@@ -615,7 +615,7 @@ 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.
+// 'Hashes' input parameter.
inline std::pair<uint32_t, uint32_t>
getDebugNamesBucketAndHashCount(MutableArrayRef<uint32_t> Hashes) {
uint32_t BucketCount = 0;
More information about the llvm-commits
mailing list