Skip to content

[AArch64][BOLT] Ensure tentative code layout for cold BBs runs. #96609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions bolt/lib/Passes/LongJmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,8 @@ uint64_t LongJmpPass::tentativeLayoutRelocColdPart(
uint64_t LongJmpPass::tentativeLayoutRelocMode(
const BinaryContext &BC, std::vector<BinaryFunction *> &SortedFunctions,
uint64_t DotAddress) {

// Compute hot cold frontier
uint32_t LastHotIndex = -1u;
int64_t LastHotIndex = -1u;
uint32_t CurrentIndex = 0;
if (opts::HotFunctionsAtEnd) {
for (BinaryFunction *BF : SortedFunctions) {
Expand All @@ -351,19 +350,20 @@ uint64_t LongJmpPass::tentativeLayoutRelocMode(
// Hot
CurrentIndex = 0;
bool ColdLayoutDone = false;
auto runColdLayout = [&]() {
DotAddress = tentativeLayoutRelocColdPart(BC, SortedFunctions, DotAddress);
ColdLayoutDone = true;
if (opts::HotFunctionsAtEnd)
DotAddress = alignTo(DotAddress, opts::AlignText);
};
for (BinaryFunction *Func : SortedFunctions) {
if (!BC.shouldEmit(*Func)) {
HotAddresses[Func] = Func->getAddress();
continue;
}

if (!ColdLayoutDone && CurrentIndex >= LastHotIndex) {
DotAddress =
tentativeLayoutRelocColdPart(BC, SortedFunctions, DotAddress);
ColdLayoutDone = true;
if (opts::HotFunctionsAtEnd)
DotAddress = alignTo(DotAddress, opts::AlignText);
}
if (!ColdLayoutDone && CurrentIndex >= LastHotIndex)
runColdLayout();

DotAddress = alignTo(DotAddress, Func->getMinAlignment());
uint64_t Pad =
Expand All @@ -382,6 +382,11 @@ uint64_t LongJmpPass::tentativeLayoutRelocMode(
DotAddress += Func->estimateConstantIslandSize();
++CurrentIndex;
}

// Ensure that tentative code layout always runs for cold blocks.
if (!ColdLayoutDone)
runColdLayout();

// BBs
for (BinaryFunction *Func : SortedFunctions)
tentativeBBLayout(*Func);
Expand Down
27 changes: 27 additions & 0 deletions bolt/test/AArch64/split-funcs-lite.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This test checks that tentative code layout for cold blocks always runs.
# It commonly happens when using lite mode with split functions.

# REQUIRES: system-linux, asserts

# RUN: %clang %cflags -o %t %s
# RUN: %clang %s %cflags -Wl,-q -o %t
# RUN: link_fdata --no-lbr %s %t %t.fdata
# RUN: llvm-bolt %t -o %t.bolt --data %t.fdata -split-functions \
# RUN: -debug 2>&1 | FileCheck %s

.text
.globl foo
.type foo, %function
foo:
.entry_bb:
# FDATA: 1 foo #.entry_bb# 10
cmp x0, #0
b.eq .Lcold_bb1
ret
.Lcold_bb1:
ret

## Force relocation mode.
.reloc 0, R_AARCH64_NONE

# CHECK: foo{{.*}} cold tentative: {{.*}}
Loading