diff options
author | Amir Ayupov <aaupov@fb.com> | 2024-05-24 14:00:03 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-24 14:00:03 -0700 |
commit | 720cade2b68b5c360a5035a98d7ff643191fa3e0 (patch) | |
tree | ccb350efd0defe8a96b06b4e7a2ecd4298fa97c0 /bolt | |
parent | 57be0d2c86e6da73bbd34850a348a87e0a03afbb (diff) | |
download | llvm-720cade2b68b5c360a5035a98d7ff643191fa3e0.zip llvm-720cade2b68b5c360a5035a98d7ff643191fa3e0.tar.gz llvm-720cade2b68b5c360a5035a98d7ff643191fa3e0.tar.bz2 |
[BOLT][NFC] Avoid computing BF hash twice in YAML reader (#75096)
We compute BF hashes in `YAMLProfileReader::readProfile` when first
matching profile functions with binary functions, and second time in
`YAMLProfileReader::parseFunctionProfile` during the profile assignment
(we need to do that to account for LTO private functions with
mismatching suffix).
Avoid recomputing the hash if it's been set.
Diffstat (limited to 'bolt')
-rw-r--r-- | bolt/lib/Core/BinaryFunction.cpp | 7 | ||||
-rw-r--r-- | bolt/lib/Profile/YAMLProfileReader.cpp | 13 |
2 files changed, 15 insertions, 5 deletions
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp index 1bb05f0..89fd8b0 100644 --- a/bolt/lib/Core/BinaryFunction.cpp +++ b/bolt/lib/Core/BinaryFunction.cpp @@ -3698,6 +3698,13 @@ BinaryFunction::BasicBlockListType BinaryFunction::dfs() const { size_t BinaryFunction::computeHash(bool UseDFS, HashFunction HashFunction, OperandHashFuncTy OperandHashFunc) const { + LLVM_DEBUG({ + dbgs() << "BOLT-DEBUG: computeHash " << getPrintName() << ' ' + << (UseDFS ? "dfs" : "bin") << " order " + << (HashFunction == HashFunction::StdHash ? "std::hash" : "xxh3") + << '\n'; + }); + if (size() == 0) return 0; diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index aa38dda..f25f5920 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -102,11 +102,14 @@ bool YAMLProfileReader::parseFunctionProfile( if (BF.empty()) return true; - if (!opts::IgnoreHash && - YamlBF.Hash != BF.computeHash(IsDFSOrder, HashFunction)) { - if (opts::Verbosity >= 1) - errs() << "BOLT-WARNING: function hash mismatch\n"; - ProfileMatched = false; + if (!opts::IgnoreHash) { + if (!BF.getHash()) + BF.computeHash(IsDFSOrder, HashFunction); + if (YamlBF.Hash != BF.getHash()) { + if (opts::Verbosity >= 1) + errs() << "BOLT-WARNING: function hash mismatch\n"; + ProfileMatched = false; + } } if (YamlBF.NumBasicBlocks != BF.size()) { |