[llvm] [IPO] NFC: avoid recalculating FunctionId hashes during ProfiledCallGraph construction (PR #109014)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 27 09:06:07 PDT 2024


itrofimow wrote:

Please note that I'm not adding another hash field, nor is it stored anywhere: for all intensive purposes `PrehashedFunctionId` is private to `ProfiledCallGraph` and doesn't leave its private scope.

W.r.t. to hashing `FunctionId`, `addProfiledCalls` currently does this (in pseudocode):
```
void addProfiledCalls(const FunctionSamples &Samples) {
    HashMap.lookup(Samples.GetFunction()); // from addProfiledFunction
    ....
    HashMap.lookup(Samples.GetFunction()); // from getBodySamples loop
    ....
    HashMap.lookup(Samples.GetFunction()); // from getCallsiteSamples loop
}
```
which calculates the hash in question 3 times. All this PR is doing is instead to calculate the hash once.

Although the `FunctionId` is capable to represent its hash value, it represents _either_ a string_view name or hash, and the name is used by callers in ways that are out of scope of my understanding of the code. I think the refactoring suggested could be implemented, but my knowledge wouldn't be sufficient to implement functional changes here, when this PR alone already brings very noticeable performance improvements.

I'll see if I can make the `PrehashesFunctionId` wrapper actually private to `ProfiledCallGraph` to avoid confusion.

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


More information about the llvm-commits mailing list