[llvm] Add a flag to disable salvage-unused-profile for large modules. (PR #185354)
Snehasish Kumar via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 8 23:30:49 PDT 2026
https://github.com/snehasish updated https://github.com/llvm/llvm-project/pull/185354
>From fb4e9f2bd8df81aa16451865b241a9cafc4f3e20 Mon Sep 17 00:00:00 2001
From: Snehasish Kumar <snehasishk at google.com>
Date: Mon, 9 Mar 2026 06:24:24 +0000
Subject: [PATCH] Add a flag to disable salvage-unused-profile for large
modules.
---
llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp | 11 +++++++++++
.../pseudo-probe-stale-profile-renaming.ll | 4 ++++
2 files changed, 15 insertions(+)
diff --git a/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp b/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp
index b9fb7a3ae4b5b..63f74390771dc 100644
--- a/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp
@@ -54,6 +54,11 @@ extern cl::opt<bool> SalvageUnusedProfile;
extern cl::opt<bool> PersistProfileStaleness;
extern cl::opt<bool> ReportProfileStaleness;
+static cl::opt<unsigned> SalvageUnusedProfileMaxFunctions(
+ "salvage-unused-profile-max-functions", cl::Hidden, cl::init(UINT_MAX),
+ cl::desc("The maximum number of functions in a module, above which stale "
+ "profile matching will be skipped."));
+
static cl::opt<unsigned> SalvageStaleProfileMaxCallsites(
"salvage-stale-profile-max-callsites", cl::Hidden, cl::init(UINT_MAX),
cl::desc("The maximum number of callsites in a function, above which stale "
@@ -886,6 +891,12 @@ void SampleProfileMatcher::UpdateWithSalvagedProfiles() {
void SampleProfileMatcher::runOnModule() {
ProfileConverter::flattenProfile(Reader.getProfiles(), FlattenedProfiles,
FunctionSamples::ProfileIsCS);
+
+ // Disable SalvageUnusedProfile if the module has an extremely large number of
+ // functions to limit compile time.
+ SalvageUnusedProfile =
+ SalvageUnusedProfile && M.size() < SalvageUnusedProfileMaxFunctions;
+
if (SalvageUnusedProfile)
findFunctionsWithoutProfile();
diff --git a/llvm/test/Transforms/SampleProfile/pseudo-probe-stale-profile-renaming.ll b/llvm/test/Transforms/SampleProfile/pseudo-probe-stale-profile-renaming.ll
index f7d51d02327d4..c09fdc467def0 100644
--- a/llvm/test/Transforms/SampleProfile/pseudo-probe-stale-profile-renaming.ll
+++ b/llvm/test/Transforms/SampleProfile/pseudo-probe-stale-profile-renaming.ll
@@ -1,8 +1,12 @@
; REQUIRES: asserts && x86-registered-target
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/pseudo-probe-stale-profile-renaming.prof --salvage-stale-profile --salvage-unused-profile -report-profile-staleness -persist-profile-staleness -S --debug-only=sample-profile,sample-profile-matcher,sample-profile-impl -pass-remarks=inline --min-call-count-for-cg-matching=0 --min-func-count-for-cg-matching=0 --func-profile-similarity-threshold=70 2>&1 | FileCheck %s
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/pseudo-probe-stale-profile-renaming.prof --salvage-stale-profile --salvage-unused-profile -S --debug-only=sample-profile,sample-profile-matcher,sample-profile-impl --min-call-count-for-cg-matching=10 --min-func-count-for-cg-matching=10 2>&1 | FileCheck %s --check-prefix=TINY-FUNC
+; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/pseudo-probe-stale-profile-renaming.prof --salvage-stale-profile --salvage-unused-profile --salvage-unused-profile-max-functions=1 -S --debug-only=sample-profile-matcher 2>&1 | FileCheck %s --check-prefix=SKIP-SALVAGE
; Verify find new IR functions.
+; SKIP-SALVAGE: define dso_local i32 @main()
+; SKIP-SALVAGE-NOT: Function new_block_only is not in profile or profile symbol list.
+; SKIP-SALVAGE-NOT: Function new_foo is not in profile or profile symbol list.
; CHECK: Function new_block_only is not in profile or profile symbol list.
; CHECK: Function new_foo is not in profile or profile symbol list.
More information about the llvm-commits
mailing list