[llvm-branch-commits] [llvm] [BOLT] Match blocks with calls as anchors (PR #96596)

Shaw Young via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Jul 8 07:53:40 PDT 2024


================
@@ -414,31 +449,59 @@ createFlowFunction(const BinaryFunction::BasicBlockOrderType &BlockOrder) {
 /// matched to a jump in the binary, the count is recorded in CFG.
 size_t matchWeightsByHashes(
     BinaryContext &BC, const BinaryFunction::BasicBlockOrderType &BlockOrder,
-    const yaml::bolt::BinaryFunctionProfile &YamlBF, FlowFunction &Func) {
+    const yaml::bolt::BinaryFunctionProfile &YamlBF, FlowFunction &Func,
+    HashFunction HashFunction,
+    const DenseMap<uint32_t, std::string *> &IdToFunctionName) {
+
   assert(Func.Blocks.size() == BlockOrder.size() + 2);
 
+  std::vector<uint64_t> CallHashes;
   std::vector<FlowBlock *> Blocks;
   std::vector<BlendedBlockHash> BlendedHashes;
   for (uint64_t I = 0; I < BlockOrder.size(); I++) {
     const BinaryBasicBlock *BB = BlockOrder[I];
     assert(BB->getHash() != 0 && "empty hash of BinaryBasicBlock");
+
+    std::string CallHashStr = hashBlockCalls(BC, *BB);
+    if (CallHashStr.empty()) {
+      CallHashes.push_back(0);
+    } else if (HashFunction == HashFunction::StdHash) {
+      CallHashes.push_back(std::hash<std::string>{}(CallHashStr));
+    } else if (HashFunction == HashFunction::XXH3) {
+      CallHashes.push_back(llvm::xxh3_64bits(CallHashStr));
+    } else {
+      llvm_unreachable("Unhandled HashFunction");
----------------
shawbyoung wrote:

This is the same llvm_unreachable message used in existing hash computations, so for consistency's sake I'd like to keep this as is. But if you feel strongly about it I can change the calls I've written to llvm_unreachable as well as previous calls 

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


More information about the llvm-branch-commits mailing list