Skip to content

Commit e3bbabf

Browse files
committed
use -fprofile-generate to specify the profile path
1 parent d660d3b commit e3bbabf

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,10 +1787,7 @@ defm debug_info_for_profiling : BoolFOption<"debug-info-for-profiling",
17871787
NegFlag<SetFalse>>;
17881788
def fprofile_sample_cold_function : Flag<["-"], "fprofile-sample-cold-function">,
17891789
Group<f_Group>, Visibility<[ClangOption, CLOption]>,
1790-
HelpText<"Generate instrumented code to cold functions guided by sampling-based profile into default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env var)">;
1791-
def fprofile_sample_cold_function_EQ : Joined<["-"], "fprofile-sample-cold-function=">,
1792-
Group<f_Group>, Visibility<[ClangOption, CLOption]>, MetaVarName<"<file>">,
1793-
HelpText<"Generate instrumented code to cold functions guided by sampling-based profile into <file> (overridden by LLVM_PROFILE_FILE env var)">;
1790+
HelpText<"Generate instrumented code to cold functions guided by sampling-based profile">;
17941791
def fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">,
17951792
Group<f_Group>, Visibility<[ClangOption, CLOption]>,
17961793
HelpText<"Generate instrumented code to collect execution counts into default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env var)">;

clang/lib/Driver/ToolChain.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -889,9 +889,7 @@ bool ToolChain::needsProfileRT(const ArgList &Args) {
889889
Args.hasArg(options::OPT_fprofile_instr_generate) ||
890890
Args.hasArg(options::OPT_fprofile_instr_generate_EQ) ||
891891
Args.hasArg(options::OPT_fcreate_profile) ||
892-
Args.hasArg(options::OPT_forder_file_instrumentation) ||
893-
Args.hasArg(options::OPT_fprofile_sample_cold_function) ||
894-
Args.hasArg(options::OPT_fprofile_sample_cold_function_EQ);
892+
Args.hasArg(options::OPT_forder_file_instrumentation);
895893
}
896894

897895
bool ToolChain::needsGCovInstrumentation(const llvm::opt::ArgList &Args) {

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -649,26 +649,24 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
649649
}
650650
}
651651

652-
if (auto *SampleColdArg =
653-
Args.getLastArg(options::OPT_fprofile_sample_cold_function,
654-
options::OPT_fprofile_sample_cold_function_EQ)) {
655-
SmallString<128> Path(SampleColdArg->getOption().matches(
656-
options::OPT_fprofile_sample_cold_function_EQ)
657-
? SampleColdArg->getValue()
658-
: "");
659-
llvm::sys::path::append(Path, "default_%m.profraw");
652+
auto *SampleColdArg =
653+
Args.getLastArg(options::OPT_fprofile_sample_cold_function);
654+
655+
Arg *PGOGenArg = nullptr;
656+
if (SampleColdArg) {
657+
SmallString<128> Path(
658+
PGOGenerateArg->getOption().matches(options::OPT_fprofile_generate_EQ)
659+
? PGOGenerateArg->getValue()
660+
: "");
661+
Path.append("default_%m.profraw");
660662
CmdArgs.push_back("-mllvm");
661663
CmdArgs.push_back(Args.MakeArgString(
662664
Twine("--instrument-sample-cold-function-path=") + Path));
663-
}
664-
665-
Arg *PGOGenArg = nullptr;
666-
if (PGOGenerateArg) {
665+
} else if (PGOGenerateArg) {
667666
assert(!CSPGOGenerateArg);
668667
PGOGenArg = PGOGenerateArg;
669668
CmdArgs.push_back("-fprofile-instrument=llvm");
670-
}
671-
if (CSPGOGenerateArg) {
669+
} else if (CSPGOGenerateArg) {
672670
assert(!PGOGenerateArg);
673671
PGOGenArg = CSPGOGenerateArg;
674672
CmdArgs.push_back("-fprofile-instrument=csllvm");
@@ -7037,7 +7035,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
70377035
options::OPT_fcs_profile_generate,
70387036
options::OPT_fcs_profile_generate_EQ, options::OPT_fprofile_use,
70397037
options::OPT_fprofile_use_EQ);
7040-
if (PGOArg)
7038+
auto *SampleColdArg =
7039+
Args.getLastArg(options::OPT_fprofile_sample_cold_function);
7040+
if (PGOArg && !SampleColdArg)
70417041
D.Diag(diag::err_drv_argument_not_allowed_with)
70427042
<< "SampleUse with PGO options";
70437043

0 commit comments

Comments
 (0)