[llvm] [BOLT] Extend calculateEmittedSize for Block Size Calculation (PR #73076)
Maksim Panchenko via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 22 11:54:06 PST 2023
================
@@ -2331,14 +2331,37 @@ BinaryContext::calculateEmittedSize(BinaryFunction &BF, bool FixBranches) {
MCAsmLayout Layout(Assembler);
Assembler.layout(Layout);
+ // Obtain fragment sizes.
+ std::vector<uint64_t> FragmentSizes;
+ // Main fragment size.
const uint64_t HotSize =
Layout.getSymbolOffset(*EndLabel) - Layout.getSymbolOffset(*StartLabel);
- const uint64_t ColdSize =
- std::accumulate(SplitLabels.begin(), SplitLabels.end(), 0ULL,
- [&](const uint64_t Accu, const LabelRange &Labels) {
- return Accu + Layout.getSymbolOffset(*Labels.second) -
- Layout.getSymbolOffset(*Labels.first);
- });
+ FragmentSizes.push_back(HotSize);
+ // Split fragment sizes.
+ uint64_t ColdSize = 0;
+ for (const auto &Labels : SplitLabels) {
+ uint64_t Size = Layout.getSymbolOffset(*Labels.second) -
+ Layout.getSymbolOffset(*Labels.first);
+ FragmentSizes.push_back(Size);
+ ColdSize += Size;
+ }
+
+ // Populate new start and end offsets of each basic block.
+ BinaryBasicBlock *PrevBB = nullptr;
+ uint64_t FragmentIndex = 0;
+ for (FunctionFragment &FF : BF.getLayout().fragments()) {
----------------
maksfb wrote:
nit: you can move `PrevBB` inside the loop body.
https://github.com/llvm/llvm-project/pull/73076
More information about the llvm-commits
mailing list