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

Davide Italiano via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Jul 8 09:30:56 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) {
----------------
dcci wrote:

then it should be
```
if (hash.empty()) {
  ...
} else {
  if (hash == xxh3) {}
  if (hash == stdhash) {}
}
```

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


More information about the llvm-branch-commits mailing list