[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
Thu Feb 22 08:23:27 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:

> With C++17 structured bindings, returning multiple values via pairs/tuples should really be the norm, rather than using reference parameters as outputs, in my opinion.

FWIW I 100% agree with you, but every now and then this runs into the LLVM's community general hesitancy to use `auto` more aggressively.

> I'll try to create another PR (probably in a day or two) to fix this. Do you know of any examples I could look at to see how this is done well?

Can't think of any example this early, but you could probably do something like:

```
inline std::pair<uint32_t, uint32_t> getDebugNamesBucketAndHashCount((MutableArrayRef<uint32_t> hashes) {
   ...
   return {BucketCount, HashCount};
}
```

And then on the call site you'd normally do something like:

```
auto [BuckerCount, HashCount] = getDebugNamesBucketAndHashCount(...)
```

However, since those are actually member variables, you can't really use a declaration like that. You'll need to store the pair in a temporary variable and assign to the member variables using `.first` and `.second`



```


```

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


More information about the llvm-commits mailing list