Skip to content

[BOLT] Introduce skip-inline flag #128135

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 1 commit into from
Feb 21, 2025
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
14 changes: 13 additions & 1 deletion bolt/lib/Passes/Inliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ ForceInlineFunctions("force-inline",
cl::Hidden,
cl::cat(BoltOptCategory));

static cl::list<std::string> SkipInlineFunctions(
"skip-inline", cl::CommaSeparated,
cl::desc("list of functions to never consider for inlining"),
cl::value_desc("func1,func2,func3,..."), cl::Hidden,
cl::cat(BoltOptCategory));

static cl::opt<bool> InlineAll("inline-all", cl::desc("inline all functions"),
cl::cat(BoltOptCategory));

Expand Down Expand Up @@ -105,6 +111,12 @@ bool mustConsider(const llvm::bolt::BinaryFunction &Function) {
return false;
}

bool mustSkip(const llvm::bolt::BinaryFunction &Function) {
return llvm::any_of(opts::SkipInlineFunctions, [&](const std::string &Name) {
return Function.hasName(Name);
});
}

void syncOptions() {
if (opts::InlineIgnoreCFI)
opts::InlineIgnoreLeafCFI = true;
Expand Down Expand Up @@ -223,7 +235,7 @@ InliningInfo getInliningInfo(const BinaryFunction &BF) {
void Inliner::findInliningCandidates(BinaryContext &BC) {
for (const auto &BFI : BC.getBinaryFunctions()) {
const BinaryFunction &Function = BFI.second;
if (!shouldOptimize(Function))
if (!shouldOptimize(Function) || opts::mustSkip(Function))
continue;
const InliningInfo InlInfo = getInliningInfo(Function);
if (InlInfo.Type != INL_NONE)
Expand Down
26 changes: 26 additions & 0 deletions bolt/test/X86/skip-inline.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Check skip-inline flag behavior

# RUN: llvm-mc --filetype=obj --triple=x86_64-unknown-unknown %s -o %t.o
# RUN: ld.lld %t.o -o %t.exe -q
# RUN: llvm-bolt %t.exe --inline-small-functions --print-finalized --print-only=main \
# RUN: -o %t.null | FileCheck %s --check-prefix=CHECK-INLINE
# RUN: llvm-bolt %t.exe --inline-small-functions --skip-inline=foo --print-finalized \
# RUN: --print-only=main -o %t.null | FileCheck %s --check-prefix=CHECK-NO-INLINE
# CHECK-INLINE: Binary Function "main"
# CHECK-INLINE: ud2
# CHECK-NO-INLINE: Binary Function "main"
# CHECK-NO-INLINE: callq foo

.globl _start
_start:
call main

.globl main
main:
call foo
ret

.globl foo
foo:
ud2
ret
Loading