From 13082cb4705deeb0ed857fa0b724f2bf6c8844bd Mon Sep 17 00:00:00 2001 From: Caroline Tice Date: Tue, 20 Feb 2024 09:59:55 -0800 Subject: [PATCH 1/4] [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 869352b35e323..c926b34f9d904 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 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(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 22d995a9cc3c5..f8528b489c3c0 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 Uniques; + SmallVector 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::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(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 Date: Tue, 20 Feb 2024 10:11:02 -0800 Subject: [PATCH 2/4] [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 c926b34f9d904..ffff372fe7983 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 hashes, - uint32_t &uniqueHashCount) { +inline uint32_t computeDebugNamesUniqueHashes(MutableArrayRef 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 f8528b489c3c0..08160a9d38eab 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 Date: Tue, 20 Feb 2024 15:03:45 -0800 Subject: [PATCH 3/4] [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 ffff372fe7983..44c0030251b37 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 hashes, - uint32_t &uniqueHashCount) { +// DWARF v5 Accelerator Table. NOTE: This function effectively consumes the +// 'hashes' input parameter. +inline uint32_t getDebugNamesBucketCount(MutableArrayRef 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 08160a9d38eab..7f5ce110caf00 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) { From fc2fbf8a0e1cc87e9b23456c28145577ae47cba0 Mon Sep 17 00:00:00 2001 From: Caroline Tice Date: Tue, 20 Feb 2024 15:57:40 -0800 Subject: [PATCH 4/4] [LLVM][DWARF] Refactor code for generating DWARF v5 .debug_names Clang format fixes. --- llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp b/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp index 7f5ce110caf00..23fc9b2e0410e 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp @@ -38,8 +38,7 @@ void AccelTableBase::computeBucketCount() { for (const auto &E : Entries) Uniques.push_back(E.second.HashValue); - BucketCount = - llvm::dwarf::getDebugNamesBucketCount(Uniques, UniqueHashCount); + BucketCount = llvm::dwarf::getDebugNamesBucketCount(Uniques, UniqueHashCount); } void AccelTableBase::finalize(AsmPrinter *Asm, StringRef Prefix) {