Skip to content

Commit 209252f

Browse files
authored
[BOLT] Introduce skip-inline flag (#128135)
Introduce exclusion list for inlining, allowing more fine-grained control than using skip-funcs. Test Plan: added skip-inline.s
1 parent a66376b commit 209252f

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

bolt/lib/Passes/Inliner.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ ForceInlineFunctions("force-inline",
4949
cl::Hidden,
5050
cl::cat(BoltOptCategory));
5151

52+
static cl::list<std::string> SkipInlineFunctions(
53+
"skip-inline", cl::CommaSeparated,
54+
cl::desc("list of functions to never consider for inlining"),
55+
cl::value_desc("func1,func2,func3,..."), cl::Hidden,
56+
cl::cat(BoltOptCategory));
57+
5258
static cl::opt<bool> InlineAll("inline-all", cl::desc("inline all functions"),
5359
cl::cat(BoltOptCategory));
5460

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

114+
bool mustSkip(const llvm::bolt::BinaryFunction &Function) {
115+
return llvm::any_of(opts::SkipInlineFunctions, [&](const std::string &Name) {
116+
return Function.hasName(Name);
117+
});
118+
}
119+
108120
void syncOptions() {
109121
if (opts::InlineIgnoreCFI)
110122
opts::InlineIgnoreLeafCFI = true;
@@ -223,7 +235,7 @@ InliningInfo getInliningInfo(const BinaryFunction &BF) {
223235
void Inliner::findInliningCandidates(BinaryContext &BC) {
224236
for (const auto &BFI : BC.getBinaryFunctions()) {
225237
const BinaryFunction &Function = BFI.second;
226-
if (!shouldOptimize(Function))
238+
if (!shouldOptimize(Function) || opts::mustSkip(Function))
227239
continue;
228240
const InliningInfo InlInfo = getInliningInfo(Function);
229241
if (InlInfo.Type != INL_NONE)

bolt/test/X86/skip-inline.s

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## Check skip-inline flag behavior
2+
3+
# RUN: llvm-mc --filetype=obj --triple=x86_64-unknown-unknown %s -o %t.o
4+
# RUN: ld.lld %t.o -o %t.exe -q
5+
# RUN: llvm-bolt %t.exe --inline-small-functions --print-finalized --print-only=main \
6+
# RUN: -o %t.null | FileCheck %s --check-prefix=CHECK-INLINE
7+
# RUN: llvm-bolt %t.exe --inline-small-functions --skip-inline=foo --print-finalized \
8+
# RUN: --print-only=main -o %t.null | FileCheck %s --check-prefix=CHECK-NO-INLINE
9+
# CHECK-INLINE: Binary Function "main"
10+
# CHECK-INLINE: ud2
11+
# CHECK-NO-INLINE: Binary Function "main"
12+
# CHECK-NO-INLINE: callq foo
13+
14+
.globl _start
15+
_start:
16+
call main
17+
18+
.globl main
19+
main:
20+
call foo
21+
ret
22+
23+
.globl foo
24+
foo:
25+
ud2
26+
ret

0 commit comments

Comments
 (0)