Skip to content

Commit 13f8336

Browse files
haoyuintelphoebewang
authored andcommitted
[Driver] Add -fsample-profile-use-profi
This patch enable `-sample-profile-use-profi` in Clang frontend as user-facing feature. By using this patch, we can use the cflag of `-fsample-profile-use-profi` instead of `-mllvm -sample-profile-use-profi`. Reviewed By: hans, MaskRay Differential Revision: https://reviews.llvm.org/D136846
1 parent 70c781f commit 13f8336

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

clang/docs/UsersManual.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,6 +2241,15 @@ usual build cycle when using sample profilers for optimization:
22412241
22422242
$ clang++ -O2 -gline-tables-only -fprofile-sample-use=code.prof code.cc -o code
22432243
2244+
[OPTIONAL] Sampling-based profiles can have inaccuracies or missing block/
2245+
edge counters. The profile inference algorithm (profi) can be used to infer
2246+
missing blocks and edge counts, and improve the quality of profile data.
2247+
Enable it with ``-fsample-profile-use-profi``.
2248+
2249+
.. code-block:: console
2250+
2251+
$ clang++ -O2 -gline-tables-only -fprofile-sample-use=code.prof \
2252+
-fsample-profile-use-profi code.cc -o code
22442253
22452254
Sample Profile Formats
22462255
""""""""""""""""""""""

clang/include/clang/Driver/Options.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,13 @@ def fprofile_sample_accurate : Flag<["-"], "fprofile-sample-accurate">,
12511251
as cold. Otherwise, treat callsites without profile samples as if
12521252
we have no profile}]>,
12531253
MarshallingInfoFlag<CodeGenOpts<"ProfileSampleAccurate">>;
1254+
def fsample_profile_use_profi : Flag<["-"], "fsample-profile-use-profi">,
1255+
Flags<[NoXarchOption, CC1Option]>, Group<f_Group>,
1256+
HelpText<"Use profi to infer block and edge counts">,
1257+
DocBrief<[{Infer block and edge counts. If the profiles have errors or missing
1258+
blocks caused by sampling, profile inference (profi) can convert
1259+
basic block counts to branch probabilites to fix them by extended
1260+
and re-engineered classic MCMF (min-cost max-flow) approach.}]>;
12541261
def fno_profile_sample_accurate : Flag<["-"], "fno-profile-sample-accurate">,
12551262
Group<f_Group>, Flags<[NoXarchOption]>;
12561263
def fauto_profile : Flag<["-"], "fauto-profile">, Group<f_Group>,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5729,6 +5729,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
57295729

57305730
Args.AddLastArg(CmdArgs, options::OPT_fclang_abi_compat_EQ);
57315731

5732+
if (getLastProfileSampleUseArg(Args) &&
5733+
Args.hasArg(options::OPT_fsample_profile_use_profi)) {
5734+
CmdArgs.push_back("-mllvm");
5735+
CmdArgs.push_back("-sample-profile-use-profi");
5736+
}
5737+
57325738
// Add runtime flag for PS4/PS5 when PGO, coverage, or sanitizers are enabled.
57335739
if (RawTriple.isPS() &&
57345740
!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/// Test if profi flat is enabled in frontend as user-facing feature.
2+
// RUN: %clang -c -fsample-profile-use-profi -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s
3+
4+
// CHECK: "-mllvm" "-sample-profile-use-profi"

0 commit comments

Comments
 (0)