-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[LLVM][DWARF] Refactor code for generating DWARF V5 .debug_names #82394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
13082cb
3ca2172
1877363
fc2fbf8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without returning the iterator from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I understand your comment? Yes, I want the changes to hashes to make it back to the caller. I thought making it a MutableArray meant that the changes would get back to the user? Originally I had it as a SmallVector &, but felipepivezan asked me to change it to a MutableArray instead. LLVM would not allow me to declare the MutableArray as a reference? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
MutableArrays are meant to be passed by copy, they are just a "non const ptr" + "size" abstraction.
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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I went back and double checked the callers; they do NOT expect a usable vector after this call, so that is fine. However I'm getting a compile time error using the MutableArrayRef, which I could use to help figuring out how to fix: third_party/llvm/llvm-project/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp:43:50: error: non-const lvalue reference to type 'MutableArrayRef<uint32_t>' (aka 'MutableArrayRef') cannot bind to a value of unrelated type 'SmallVector<uint32_t, 0>' (aka 'SmallVector<unsigned int, 0>') ('Uniques', at the call site, line 43, is a SmallVector...) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Did you make it a reference? It should not be a reference There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this function calculates and returns two different values: the bucket count (for which the function is named) and the unique hash count. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In hindsight, we should have just returned a pair There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be adjusted post-merge? 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
FWIW I 100% agree with you, but every now and then this runs into the LLVM's community general hesitancy to use
Can't think of any example this early, but you could probably do something like:
And then on the call site you'd normally do something like:
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
|
||
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, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this maybe should be
getDebugNamesBucketCount
? (because it doesn't return the unique number of hashes, it returns the number of buckets)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well it does return the unique number of hashes, in the second parameter, but I'm Ok with renaming the function...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. Yeah, naming it after what it returns seems the most legible.
If the intent is to use the uniqued hashes array after the call (not relevant to the current caller, but possibly relevant to the new usage you want to add) maybe the simplest thing is to have the function take a
SmallVectorImpl<uint32_t>&
, and after callinguique
, use that result to shorten the vector down to the size of the uniqued range (by calling the vector'sresize
function) - then the caller can inspect the vector's size after calling, and doesn't need the secondary out parameter?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've renamed the function as suggested, and added a note in the function comment that it consumes the array parameter.