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

Amir Ayupov via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 20 21:46:31 PST 2025


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

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

Test Plan: added skip-inline.s


>From 7aecb355be51547a261df12a9ae0f80d6129f432 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Thu, 20 Feb 2025 21:46:22 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 bolt/lib/Passes/Inliner.cpp | 14 +++++++++++++-
 bolt/test/X86/skip-inline.s | 26 ++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletion(-)
 create mode 100644 bolt/test/X86/skip-inline.s

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



More information about the llvm-commits mailing list