[llvm-branch-commits] [llvm] [BOLT] Map branch source address to the containing basic block in BAT YAML (PR #91273)
Amir Ayupov via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri May 10 17:59:02 PDT 2024
================
@@ -2378,21 +2378,24 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC,
return CSI;
};
+ // Lookup containing basic block offset and index
+ auto getBlock = [&BlockMap](uint32_t Offset) {
+ auto BlockIt = BlockMap.upper_bound(Offset);
+ assert(BlockIt != BlockMap.begin());
+ --BlockIt;
+ return std::pair(BlockIt->first, BlockIt->second.getBBIndex());
+ };
+
for (const auto &[FromOffset, SuccKV] : Branches.IntraIndex) {
- if (!BlockMap.isInputBlock(FromOffset))
- continue;
- const unsigned Index = BlockMap.getBBIndex(FromOffset);
+ const auto &[_, Index] = getBlock(FromOffset);
----------------
aaupov wrote:
> Do we expect getBlock() to always return a good value?
Yes. It performs an `upper_bound` lookup with an unsigned value against a BlockMap which should contain a zero key (entry basic block). As long as the function has it, we're good. If not, it's worth looking why do we have such a function in BAT.
> There's no chance for malformed input to trigger the assertion above?
No, any offset in the profile is >=0.
https://github.com/llvm/llvm-project/pull/91273
More information about the llvm-branch-commits
mailing list