-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
[BOLT] Hash-based function matching #95821
[BOLT] Hash-based function matching #95821
Conversation
Created using spr 1.3.4
Created using spr 1.3.4 [skip ci]
@llvm/pr-subscribers-bolt Author: shaw young (shawbyoung) ChangesUsing the hashes of binary and profiled functions Test Plan: tbd Full diff: https://github.com/llvm/llvm-project/pull/95821.diff 1 Files Affected:
diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp
index f25f59201f1cd..f0fcb1c130002 100644
--- a/bolt/lib/Profile/YAMLProfileReader.cpp
+++ b/bolt/lib/Profile/YAMLProfileReader.cpp
@@ -415,6 +415,23 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
if (!YamlBF.Used && BF && !ProfiledFunctions.count(BF))
matchProfileToFunction(YamlBF, *BF);
+ // Uses the strict hash of profiled and binary functions to match functions
+ // that are not matched by name or common name.
+ std::unordered_map<size_t, BinaryFunction*> StrictBinaryFunctionHashes;
+ StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size());
+
+ for (auto& [_, BF] : BC.getBinaryFunctions()) {
+ StrictBinaryFunctionHashes[BF.getHash()] = &BF;
+ }
+
+ for (auto YamlBF : YamlBP.Functions) {
+ auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash);
+ if (It != StrictBinaryFunctionHashes.end() && !ProfiledFunctions.count(It->second)) {
+ auto *BF = It->second;
+ matchProfileToFunction(YamlBF, *BF);
+ }
+ }
+
for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions)
if (!YamlBF.Used && opts::Verbosity >= 1)
errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name
|
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 very good, but please address some minor issues.
} | ||
|
||
// Uses the strict hash of profiled and binary functions to match functions | ||
// that are not matched by name or common name. | ||
if (opts::MatchingFunctionsWithHash) { |
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.
What is captured in strict hash?
For reference, function hash for compiler PGO isn't very strict, and it's not strong enough for small functions. So we use comprehensive graph matching in addition to hash matching to recover renamed function/profile pair. Change in #95135 cc @wlei-llvm
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.
In BOLT, a strict hash captures a binary function's block order as well as each blocks' instructions & opcodes. So, the goal of this PR is to recover block-identical functions that have been simply been renamed.
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.
LG overall, with a couple of nits.
Created using spr 1.3.4
Created using spr 1.3.4 [skip ci]
Created using spr 1.3.4
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/151/builds/367 Here is the relevant piece of the build log for the reference:
|
This reverts commit 5e097c7.
Using the hashes of binary and profiled functions to recover functions with changed names. Test Plan: added hashing-based-function-matching.test.
Using the hashes of binary and profiled functions
to recover functions with changed names.
Test Plan: added
hashing-based-function-matching.test.