diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 0822df2640d23..ef6bcfe296a80 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1698,6 +1698,8 @@ def fsample_profile_use_profi : Flag<["-"], "fsample-profile-use-profi">, basic block counts to branch probabilities to fix them by extended and re-engineered classic MCMF (min-cost max-flow) approach.}]>; def fno_profile_sample_accurate : Flag<["-"], "fno-profile-sample-accurate">, Group; +def fno_sample_profile_use_profi : Flag<["-"], "fno-sample-profile-use-profi">, + Group; def fno_auto_profile : Flag<["-"], "fno-auto-profile">, Group, Alias; def fauto_profile_EQ : Joined<["-"], "fauto-profile=">, diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 8a18865b899d2..bfc731a1d113a 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -6283,7 +6283,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Args.AddLastArg(CmdArgs, options::OPT_fclang_abi_compat_EQ); if (getLastProfileSampleUseArg(Args) && - Args.hasArg(options::OPT_fsample_profile_use_profi)) { + Args.hasFlag(options::OPT_fsample_profile_use_profi, + options::OPT_fno_sample_profile_use_profi, false)) { CmdArgs.push_back("-mllvm"); CmdArgs.push_back("-sample-profile-use-profi"); } diff --git a/clang/test/Driver/pgo-sample-use-profi.c b/clang/test/Driver/pgo-sample-use-profi.c index 0370d947ce590..a8c8e81f96dcb 100644 --- a/clang/test/Driver/pgo-sample-use-profi.c +++ b/clang/test/Driver/pgo-sample-use-profi.c @@ -1,4 +1,20 @@ -/// Test if profi flat is enabled in frontend as user-facing feature. -// RUN: %clang --target=x86_64 -c -fsample-profile-use-profi -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s +/// Test if profi flag is enabled/disabled correctly based on user-specified configuration. +/// Ensure that profi flag is disabled by default + +// Target specific checks: +// RUN: %clang --target=x86_64 -c -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-PROFI +// RUN: %clang --target=AArch64 -c -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-PROFI + +// Target agnostic checks: +// RUN: %clang -c -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-PROFI +// RUN: %clang -c -fsample-profile-use-profi -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s +// RUN: %clang -c -fno-sample-profile-use-profi -fsample-profile-use-profi -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s + +// Cases where profi flag is explicitly disabled: +// RUN: %clang -c -### %s 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-PROFI +// RUN: %clang -c -fno-sample-profile-use-profi -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-PROFI +// 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 + // CHECK: "-mllvm" "-sample-profile-use-profi" +// CHECK-NO-PROFI-NOT: "-sample-profile-use-profi"