[llvm] [LLVM][DWARF] Refactor code for generating DWARF V5 .debug_names (PR #82394)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 20 15:06:21 PST 2024
https://github.com/cmtice updated https://github.com/llvm/llvm-project/pull/82394
>From 13082cb4705deeb0ed857fa0b724f2bf6c8844bd Mon Sep 17 00:00:00 2001
From: Caroline Tice <cmtice at google.com>
Date: Tue, 20 Feb 2024 09:59:55 -0800
Subject: [PATCH 1/3] [LLVM][DWARF] Refactor code for generating DWARF V4
.debug_names accelerator table.
Update computeDebugNamesUniqueHashes function to start with lowercase letter,
to use a MutableArrayRef for the hashes parameter instead of SmallVector,
and made uniqueHashCount a reference parameter, to allow the accelerator
table class member to be properly updated. Also removed redundant
namespace qualifier.
---
llvm/include/llvm/BinaryFormat/Dwarf.h | 19 +++++++++++++++++++
llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp | 15 +++------------
2 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/Dwarf.h b/llvm/include/llvm/BinaryFormat/Dwarf.h
index 869352b35e3235..c926b34f9d9048 100644
--- a/llvm/include/llvm/BinaryFormat/Dwarf.h
+++ b/llvm/include/llvm/BinaryFormat/Dwarf.h
@@ -613,6 +613,25 @@ enum AcceleratorTable {
DW_hash_function_djb = 0u
};
+// Uniquify the string hashes and calculate the bucket count for the
+// DWARF v5 Accelerator Table.
+inline uint32_t
+computeDebugNamesUniqueHashes(MutableArrayRef<uint32_t> hashes,
+ uint32_t &uniqueHashCount) {
+ 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;
+ else
+ BucketCount = std::max<uint32_t>(uniqueHashCount, 1);
+
+ return BucketCount;
+}
+
// Constants for the GNU pubnames/pubtypes extensions supporting gdb index.
enum GDBIndexEntryKind {
GIEK_NONE,
diff --git a/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp b/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
index 22d995a9cc3c56..f8528b489c3c0b 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
@@ -33,22 +33,13 @@ using namespace llvm;
void AccelTableBase::computeBucketCount() {
// First get the number of unique hashes.
- std::vector<uint32_t> Uniques;
+ SmallVector<uint32_t, 0> Uniques;
Uniques.reserve(Entries.size());
for (const auto &E : Entries)
Uniques.push_back(E.second.HashValue);
- array_pod_sort(Uniques.begin(), Uniques.end());
- std::vector<uint32_t>::iterator P =
- std::unique(Uniques.begin(), Uniques.end());
- UniqueHashCount = std::distance(Uniques.begin(), P);
-
- if (UniqueHashCount > 1024)
- BucketCount = UniqueHashCount / 4;
- else if (UniqueHashCount > 16)
- BucketCount = UniqueHashCount / 2;
- else
- BucketCount = std::max<uint32_t>(UniqueHashCount, 1);
+ BucketCount = llvm::dwarf::computeDebugNamesUniqueHashes(Uniques,
+ UniqueHashCount);
}
void AccelTableBase::finalize(AsmPrinter *Asm, StringRef Prefix) {
>From 3ca217261c7b7317e33cbeccf73f694f5c5eb961 Mon Sep 17 00:00:00 2001
From: Caroline Tice <cmtice at google.com>
Date: Tue, 20 Feb 2024 10:11:02 -0800
Subject: [PATCH 2/3] [LLVM][DWARF] Refactor code for generating DWARF
V5.debug_names
Fix clang format issues.
---
llvm/include/llvm/BinaryFormat/Dwarf.h | 5 ++---
llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp | 4 ++--
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/Dwarf.h b/llvm/include/llvm/BinaryFormat/Dwarf.h
index c926b34f9d9048..ffff372fe79836 100644
--- a/llvm/include/llvm/BinaryFormat/Dwarf.h
+++ b/llvm/include/llvm/BinaryFormat/Dwarf.h
@@ -615,9 +615,8 @@ enum AcceleratorTable {
// Uniquify the string hashes and calculate the bucket count for the
// DWARF v5 Accelerator Table.
-inline uint32_t
-computeDebugNamesUniqueHashes(MutableArrayRef<uint32_t> hashes,
- uint32_t &uniqueHashCount) {
+inline uint32_t computeDebugNamesUniqueHashes(MutableArrayRef<uint32_t> hashes,
+ uint32_t &uniqueHashCount) {
uint32_t BucketCount = 0;
sort(hashes);
diff --git a/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp b/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
index f8528b489c3c0b..08160a9d38eab9 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
@@ -38,8 +38,8 @@ void AccelTableBase::computeBucketCount() {
for (const auto &E : Entries)
Uniques.push_back(E.second.HashValue);
- BucketCount = llvm::dwarf::computeDebugNamesUniqueHashes(Uniques,
- UniqueHashCount);
+ BucketCount =
+ llvm::dwarf::computeDebugNamesUniqueHashes(Uniques, UniqueHashCount);
}
void AccelTableBase::finalize(AsmPrinter *Asm, StringRef Prefix) {
>From 1877363348287626a967f7cf9c4fb3479191fe31 Mon Sep 17 00:00:00 2001
From: Caroline Tice <cmtice at google.com>
Date: Tue, 20 Feb 2024 15:03:45 -0800
Subject: [PATCH 3/3] [LLVM][DWARF] Refactor code for generating DWARF v5
.debug_names
Change function name from 'computeDebugNamesUniqueHashes' to
'getDebugNamesBucketCount', and add coment that this function
consumes its input parameter.
---
llvm/include/llvm/BinaryFormat/Dwarf.h | 7 ++++---
llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp | 2 +-
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/Dwarf.h b/llvm/include/llvm/BinaryFormat/Dwarf.h
index ffff372fe79836..44c0030251b37e 100644
--- a/llvm/include/llvm/BinaryFormat/Dwarf.h
+++ b/llvm/include/llvm/BinaryFormat/Dwarf.h
@@ -614,9 +614,10 @@ enum AcceleratorTable {
};
// Uniquify the string hashes and calculate the bucket count for the
-// DWARF v5 Accelerator Table.
-inline uint32_t computeDebugNamesUniqueHashes(MutableArrayRef<uint32_t> hashes,
- uint32_t &uniqueHashCount) {
+// 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;
sort(hashes);
diff --git a/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp b/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
index 08160a9d38eab9..7f5ce110caf00f 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
@@ -39,7 +39,7 @@ void AccelTableBase::computeBucketCount() {
Uniques.push_back(E.second.HashValue);
BucketCount =
- llvm::dwarf::computeDebugNamesUniqueHashes(Uniques, UniqueHashCount);
+ llvm::dwarf::getDebugNamesBucketCount(Uniques, UniqueHashCount);
}
void AccelTableBase::finalize(AsmPrinter *Asm, StringRef Prefix) {
More information about the llvm-commits
mailing list