Skip to content

Commit c8cd497

Browse files
authored
[Driver] Support fprofile-sample-use= for CL (#117282)
Sampling PGO has already been supported on Windows. This patch adds /fprofile-sample-use= /fprofile-sample-use: /fno-profile-sample-use and supports -fprofile-sample-use= for CL.
1 parent 63c5a42 commit c8cd497

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

clang/docs/UsersManual.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,7 +2660,7 @@ usual build cycle when using sample profilers for optimization:
26602660
26612661
> clang-cl /O2 -gdwarf -gline-tables-only ^
26622662
/clang:-fdebug-info-for-profiling /clang:-funique-internal-linkage-names ^
2663-
/fprofile-sample-use=code.prof code.cc /Fe:code /fuse-ld=lld /link /debug:dwarf
2663+
/fprofile-sample-use=code.prof code.cc /Fe:code -fuse-ld=lld /link /debug:dwarf
26642664
26652665
[OPTIONAL] Sampling-based profiles can have inaccuracies or missing block/
26662666
edge counters. The profile inference algorithm (profi) can be used to infer
@@ -2679,7 +2679,7 @@ usual build cycle when using sample profilers for optimization:
26792679
26802680
> clang-cl /clang:-fsample-profile-use-profi /O2 -gdwarf -gline-tables-only ^
26812681
/clang:-fdebug-info-for-profiling /clang:-funique-internal-linkage-names ^
2682-
/fprofile-sample-use=code.prof code.cc /Fe:code /fuse-ld=lld /link /debug:dwarf
2682+
/fprofile-sample-use=code.prof code.cc /Fe:code -fuse-ld=lld /link /debug:dwarf
26832683
26842684
Sample Profile Formats
26852685
""""""""""""""""""""""

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,7 @@ def fno_profile_sample_use : Flag<["-"], "fno-profile-sample-use">, Group<f_Grou
17361736
Visibility<[ClangOption, CLOption]>;
17371737
def fprofile_sample_use_EQ : Joined<["-"], "fprofile-sample-use=">,
17381738
Group<f_Group>,
1739-
Visibility<[ClangOption, CC1Option]>,
1739+
Visibility<[ClangOption, CLOption, CC1Option]>,
17401740
HelpText<"Enable sample-based profile guided optimizations">,
17411741
MarshallingInfoString<CodeGenOpts<"SampleProfileFile">>;
17421742
def fprofile_sample_accurate : Flag<["-"], "fprofile-sample-accurate">,
@@ -8506,6 +8506,8 @@ def _SLASH_fp_strict : CLFlag<"fp:strict">, HelpText<"">, Alias<ffp_model_EQ>, A
85068506
def _SLASH_fsanitize_EQ_address : CLFlag<"fsanitize=address">,
85078507
HelpText<"Enable AddressSanitizer">,
85088508
Alias<fsanitize_EQ>, AliasArgs<["address"]>;
8509+
def : CLJoined<"fprofile-sample-use:">, Alias<fprofile_sample_use_EQ>;
8510+
def : CLJoined<"fprofile-sample-use=">, Alias<fprofile_sample_use_EQ>;
85098511
def _SLASH_GA : CLFlag<"GA">, Alias<ftlsmodel_EQ>, AliasArgs<["local-exec"]>,
85108512
HelpText<"Assume thread-local variables are defined in the executable">;
85118513
def _SLASH_GR : CLFlag<"GR">, HelpText<"Emit RTTI data (default)">;

clang/test/Driver/cl-options.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@
101101
// CHECK-PROFILE-USE: "-fprofile-instrument-use-path=default.profdata"
102102
// CHECK-PROFILE-USE-FILE: "-fprofile-instrument-use-path=/tmp/somefile.prof"
103103

104+
// RUN: %clang_cl -### /FA -fprofile-sample-use=%S/Inputs/file.prof -- %s 2>&1 | FileCheck --check-prefix=CHECK-PROFILE-SAMPLE-USE %s
105+
// RUN: %clang_cl -### /FA /fprofile-sample-use=%S/Inputs/file.prof -- %s 2>&1 | FileCheck --check-prefix=CHECK-PROFILE-SAMPLE-USE %s
106+
// RUN: %clang_cl -### /FA /fprofile-sample-use:%S/Inputs/file.prof -- %s 2>&1 | FileCheck --check-prefix=CHECK-PROFILE-SAMPLE-USE %s
107+
// CHECK-PROFILE-SAMPLE-USE: "-fprofile-sample-use={{.*}}/file.prof"
108+
104109
// RUN: %clang_cl /GA -### -- %s 2>&1 | FileCheck -check-prefix=GA %s
105110
// GA: -ftls-model=local-exec
106111

0 commit comments

Comments
 (0)