[llvm] [BOLT] Introduce skip-inline flag (PR #128135)

via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 20 21:47:05 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-bolt

Author: Amir Ayupov (aaupov)

<details>
<summary>Changes</summary>

Introduce exclusion list for inlining, allowing more fine-grained
control than using skip-funcs.

Test Plan: added skip-inline.s


---
Full diff: https://github.com/llvm/llvm-project/pull/128135.diff


2 Files Affected:

- (modified) bolt/lib/Passes/Inliner.cpp (+13-1) 
- (added) bolt/test/X86/skip-inline.s (+26) 


``````````diff
diff --git a/bolt/lib/Passes/Inliner.cpp b/bolt/lib/Passes/Inliner.cpp
index 1793f4ff1f148..9b28c7efde5bf 100644
--- a/bolt/lib/Passes/Inliner.cpp
+++ b/bolt/lib/Passes/Inliner.cpp
@@ -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));
 
@@ -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;
@@ -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)
diff --git a/bolt/test/X86/skip-inline.s b/bolt/test/X86/skip-inline.s
new file mode 100644
index 0000000000000..748990a0cd587
--- /dev/null
+++ b/bolt/test/X86/skip-inline.s
@@ -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

``````````

</details>


https://github.com/llvm/llvm-project/pull/128135


More information about the llvm-commits mailing list