[llvm] [LLVM][DWARF] Refactor code for generating DWARF V5 .debug_names (PR #82394)

Felipe de Azevedo Piovezan via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 20 13:01:19 PST 2024


================
@@ -613,6 +613,24 @@ 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();
----------------
felipepiovezan wrote:

> LLVM would not allow me to declare the MutableArray as a reference

MutableArrays are meant to be passed by copy, they are just a "non const ptr" + "size" abstraction.

> I thought making it a MutableArray meant that the changes would get back to the user? 

The changes make it back to the user, but this is not the important distinction between MutableArrayRef and SmallVector. The SmallVector API exposes resizing capabilities, which we are not using inside this function. So you communicate this intent by using the more restricted API.

That said, David's point is that the `erase` functions only moves elements around, it doesn't actually erase them (contrary to what the name suggests). Because of that, the caller of this function can't possibly have a useful vector after this function returns.

https://github.com/llvm/llvm-project/pull/82394


More information about the llvm-commits mailing list