[llvm] [BOLT] Synchronize BBHashMap and YamlBBs in BAT mode (PR #145124)

Jinjie Huang via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 12 02:25:57 PST 2025


================
@@ -2279,12 +2279,11 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC,
       const BoltAddressTranslation::BBHashMapTy &BlockMap =
           BAT->getBBHashMap(FuncAddress);
       YamlBF.Blocks.resize(YamlBF.NumBasicBlocks);
+      for (size_t Idx = 0; Idx != YamlBF.NumBasicBlocks; ++Idx)
+        YamlBF.Blocks[Idx].Index = Idx;
 
-      for (auto &&[Entry, YamlBB] : llvm::zip(BlockMap, YamlBF.Blocks)) {
-        const auto &Block = Entry.second;
-        YamlBB.Hash = Block.Hash;
-        YamlBB.Index = Block.Index;
-      }
+      for (const auto &Block : llvm::make_second_range(BlockMap))
+        YamlBF.Blocks[Block.Index].Hash = Block.Hash;
----------------
Jinjie-Huang wrote:

Seems a potential issue here: `Block.Index` might be >= `YamlBF.Blocks.size()`. Since NumBasicBlocksMap only stores the hot part (fragment) of the function([code](https://github.com/llvm/llvm-project/blob/release/21.x/bolt/lib/Profile/BoltAddressTranslation.cpp#L347)), whereas BBHashMap appears to store both the hot and cold parts([code](https://github.com/llvm/llvm-project/blob/release/21.x/bolt/lib/Profile/BoltAddressTranslation.cpp#L406)). If confirmed, I'd also be happy to submit a change to fix this.


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


More information about the llvm-commits mailing list