diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1248,6 +1248,14 @@ as cold. Otherwise, treat callsites without profile samples as if we have no profile}]>, MarshallingInfoFlag>; +def fsample_profile_use_profi : Flag<["-"], "fsample-profile-use-profi">, + Flags<[NoXarchOption, CC1Option]>, Group, + HelpText<"Use profi to infer block and edge counts.">, + DocBrief<[{Profi - a flow-based profile inference algorithm is an extended + and significantly re-engineered classic MCMF (min-cost max-flow) + approach. It models profile inference as an optimization problem + on a control-flow graph with the objectives and constraints + capturing the desired properties on profile data.}]>; def fno_profile_sample_accurate : Flag<["-"], "fno-profile-sample-accurate">, Group, Flags<[NoXarchOption]>; def fauto_profile : Flag<["-"], "fauto-profile">, Group, diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5760,6 +5760,11 @@ Args.AddLastArg(CmdArgs, options::OPT_fclang_abi_compat_EQ); + if (Args.hasArg(options::OPT_fsample_profile_use_profi)) { + CmdArgs.push_back("-mllvm"); + CmdArgs.push_back("-sample-profile-use-profi"); + } + // Add runtime flag for PS4/PS5 when PGO, coverage, or sanitizers are enabled. if (RawTriple.isPS() && !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { diff --git a/clang/test/CodeGen/Inputs/pgo-sample-use-profi.prof b/clang/test/CodeGen/Inputs/pgo-sample-use-profi.prof new file mode 100644 --- /dev/null +++ b/clang/test/CodeGen/Inputs/pgo-sample-use-profi.prof @@ -0,0 +1,8 @@ +_Z11bubble_sortPii:965211:0 + 0: 0 + 2: 4 + 4: 19852 + 5: 20401 + 7: 4556 + 8: 4556 + 13: 0 diff --git a/clang/test/CodeGen/pgo-sample-use-profi.c b/clang/test/CodeGen/pgo-sample-use-profi.c new file mode 100644 --- /dev/null +++ b/clang/test/CodeGen/pgo-sample-use-profi.c @@ -0,0 +1,5 @@ +//Test if profi flat is enabled in frontend as user-facing feature. +// +//RUN: %clang -c -fsample-profile-use-profi -### %s 2>&1 | FileCheck %s + +//CHECK: "-mllvm" "-sample-profile-use-profi" \ No newline at end of file