From 159445bcb9ecf71558ac003b5d8c6685d112af85 Mon Sep 17 00:00:00 2001 From: Nilanjana Basu Date: Tue, 24 Jun 2025 17:01:10 -0700 Subject: [PATCH] [Clang][Driver][SamplePGO] Enable -fsample-profile-use-profi for sample-pgo in clang --- clang/include/clang/Driver/Options.td | 1 + clang/lib/Driver/ToolChains/Clang.cpp | 3 ++- clang/test/Driver/pgo-sample-use-profi.c | 13 ++++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index ebdcce1085d2d..92e5eff54697a 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1725,6 +1725,7 @@ 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 3c7b21807a36a..9c335da132730 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -6451,7 +6451,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &Job, 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, true)) { 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..0037b0ba8ace0 100644 --- a/clang/test/Driver/pgo-sample-use-profi.c +++ b/clang/test/Driver/pgo-sample-use-profi.c @@ -1,4 +1,15 @@ -/// Test if profi flat is enabled in frontend as user-facing feature. +/// Test if profi flag is enabled in frontend as user-facing feature. +// RUN: %clang --target=x86_64 -c -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s // RUN: %clang --target=x86_64 -c -fsample-profile-use-profi -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s +// RUN: %clang --target=x86_64 -c -fno-sample-profile-use-profi -fsample-profile-use-profi -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s +// RUN: %clang --target=x86_64 -c -fno-sample-profile-use-profi -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-PROFI +// RUN: %clang --target=x86_64 -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 + +// RUN: %clang --target=AArch64 -c -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s +// RUN: %clang --target=AArch64 -c -fsample-profile-use-profi -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s +// RUN: %clang --target=AArch64 -c -fno-sample-profile-use-profi -fsample-profile-use-profi -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s +// RUN: %clang --target=AArch64 -c -fno-sample-profile-use-profi -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-PROFI +// RUN: %clang --target=AArch64 -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"