================ @@ -155,5 +155,51 @@ std::string hashBlockLoose(BinaryContext &BC, const BinaryBasicBlock &BB) { return HashString; } +/// An even looser hash of a basic block to use with stale profile matching, +/// composed of the names of a block's called functions in lexicographic order. +std::string hashBlockCalls(BinaryContext &BC, const BinaryBasicBlock &BB) { + // The hash is computed by creating a string of all lexicographically ordered + // called function names. + std::multiset<std::string> FunctionNames; + for (const MCInst &Instr : BB) { + // Skip non-call instructions. + if (!BC.MIB->isCall(Instr)) + continue; + const MCSymbol *CallSymbol = BC.MIB->getTargetSymbol(Instr); + if (!CallSymbol) + continue; + FunctionNames.insert(std::string(CallSymbol->getName())); + } + + std::string HashString; + for (const std::string &FunctionName : FunctionNames) + HashString.append(FunctionName); + + return HashString; +} + +/// The same as the above function, but for profiled functions. ---------------- dcci wrote:
functions can be moved around the file, I wouldn't say "same as above" -- as above can change. https://github.com/llvm/llvm-project/pull/96596 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits