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

Amir Ayupov via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 20 17:07:47 PDT 2025


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

If some basic blocks are not present in BAT, blocks in BBHashMap and
YamlBF.Blocks may not come in the same order. Decouple the iteration
during initialization.

Test Plan: TBD


>From 5f357959a5156687314e83c86280e2bff20e0dc5 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Fri, 20 Jun 2025 17:07:36 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 bolt/lib/Profile/DataAggregator.cpp | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp
index 5c8af3710720d..07d706c926a42 100644
--- a/bolt/lib/Profile/DataAggregator.cpp
+++ b/bolt/lib/Profile/DataAggregator.cpp
@@ -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;
 
       // Lookup containing basic block offset and index
       auto getBlock = [&BlockMap](uint32_t Offset) {



More information about the llvm-commits mailing list