Skip to content

Commit bf578fd

Browse files
committed
[BOLT][NFC] Avoid computing BF hash twice in YAML reader
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.
1 parent d1d9545 commit bf578fd

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3698,6 +3698,13 @@ BinaryFunction::BasicBlockListType BinaryFunction::dfs() const {
36983698

36993699
size_t BinaryFunction::computeHash(bool UseDFS, HashFunction HashFunction,
37003700
OperandHashFuncTy OperandHashFunc) const {
3701+
LLVM_DEBUG({
3702+
dbgs() << "BOLT-DEBUG: computeHash " << getPrintName() << ' '
3703+
<< (UseDFS ? "dfs" : "bin") << " order "
3704+
<< (HashFunction == HashFunction::StdHash ? "std::hash" : "xxh3")
3705+
<< '\n';
3706+
});
3707+
37013708
if (size() == 0)
37023709
return 0;
37033710

bolt/lib/Profile/YAMLProfileReader.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,14 @@ bool YAMLProfileReader::parseFunctionProfile(
102102
if (BF.empty())
103103
return true;
104104

105-
if (!opts::IgnoreHash &&
106-
YamlBF.Hash != BF.computeHash(IsDFSOrder, HashFunction)) {
107-
if (opts::Verbosity >= 1)
108-
errs() << "BOLT-WARNING: function hash mismatch\n";
109-
ProfileMatched = false;
105+
if (!opts::IgnoreHash) {
106+
if (!BF.getHash())
107+
BF.computeHash(IsDFSOrder, HashFunction);
108+
if (YamlBF.Hash != BF.getHash()) {
109+
if (opts::Verbosity >= 1)
110+
errs() << "BOLT-WARNING: function hash mismatch\n";
111+
ProfileMatched = false;
112+
}
110113
}
111114

112115
if (YamlBF.NumBasicBlocks != BF.size()) {

0 commit comments

Comments
 (0)