[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 10:14:10 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/2] [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/2] [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) {



More information about the llvm-commits mailing list