Skip to content

Commit d433134

Browse files
authored
[Clang][Driver][SamplePGO] Introduce -fno_sample_profile_use_profi flag for SamplePGO (#145957)
This flag allows opting out of using profile inference pass for SamplePGO.
1 parent c863e0e commit d433134

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,8 @@ def fsample_profile_use_profi : Flag<["-"], "fsample-profile-use-profi">,
16981698
basic block counts to branch probabilities to fix them by extended
16991699
and re-engineered classic MCMF (min-cost max-flow) approach.}]>;
17001700
def fno_profile_sample_accurate : Flag<["-"], "fno-profile-sample-accurate">, Group<f_Group>;
1701+
def fno_sample_profile_use_profi : Flag<["-"], "fno-sample-profile-use-profi">,
1702+
Group<f_Group>;
17011703
def fno_auto_profile : Flag<["-"], "fno-auto-profile">, Group<f_Group>,
17021704
Alias<fno_profile_sample_use>;
17031705
def fauto_profile_EQ : Joined<["-"], "fauto-profile=">,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6281,7 +6281,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
62816281
Args.AddLastArg(CmdArgs, options::OPT_fclang_abi_compat_EQ);
62826282

62836283
if (getLastProfileSampleUseArg(Args) &&
6284-
Args.hasArg(options::OPT_fsample_profile_use_profi)) {
6284+
Args.hasFlag(options::OPT_fsample_profile_use_profi,
6285+
options::OPT_fno_sample_profile_use_profi, false)) {
62856286
CmdArgs.push_back("-mllvm");
62866287
CmdArgs.push_back("-sample-profile-use-profi");
62876288
}
Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
/// Test if profi flat is enabled in frontend as user-facing feature.
2-
// RUN: %clang --target=x86_64 -c -fsample-profile-use-profi -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s
1+
/// Test if profi flag is enabled/disabled correctly based on user-specified configuration.
2+
/// Ensure that profi flag is disabled by default
3+
4+
// Target specific checks:
5+
// RUN: %clang --target=x86_64 -c -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-PROFI
6+
// RUN: %clang --target=AArch64 -c -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-PROFI
7+
8+
// Target agnostic checks:
9+
// RUN: %clang -c -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-PROFI
10+
// RUN: %clang -c -fsample-profile-use-profi -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s
11+
// RUN: %clang -c -fno-sample-profile-use-profi -fsample-profile-use-profi -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s
12+
13+
// Cases where profi flag is explicitly disabled:
14+
// RUN: %clang -c -### %s 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-PROFI
15+
// RUN: %clang -c -fno-sample-profile-use-profi -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-PROFI
16+
// RUN: %clang -c -fsample-profile-use-profi -fno-sample-profile-use-profi -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-PROFI
17+
318

419
// CHECK: "-mllvm" "-sample-profile-use-profi"
20+
// CHECK-NO-PROFI-NOT: "-sample-profile-use-profi"

0 commit comments

Comments
 (0)