Skip to content

Commit 7a01d0c

Browse files
committed
Adds ir_profile_use
Option dedicated for IR level PGO uses
1 parent fb55618 commit 7a01d0c

File tree

6 files changed

+26
-6
lines changed

6 files changed

+26
-6
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,9 @@ class IRGenOptions {
548548
/// Path to the profdata file to be used for PGO, or the empty string.
549549
std::string UseProfile = "";
550550

551+
/// Path to the profdata file to be used for IR/CS-IR PGO, or the empty string.
552+
std::string UseIRProfile = "";
553+
551554
/// Path to the data file to be used for sampling-based PGO,
552555
/// or the empty string.
553556
std::string UseSampleProfile = "";

include/swift/Option/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,11 @@ def ir_profile_generate: Flag<["-"], "ir-profile-generate">,
16211621
Flags<[FrontendOption, NoInteractiveOption]>,
16221622
HelpText<"Generate instrumented code to collect execution counts into default.profraw (overridden by LLVM_PROFILE_FILE env var)">;
16231623

1624+
def ir_profile_use : CommaJoined<["-"], "ir-profile-use=">,
1625+
Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath]>,
1626+
MetaVarName<"<profdata>">,
1627+
HelpText<"Supply an IR-level PGO profdata file to enable profile-guided optimization">;
1628+
16241629
def embed_bitcode : Flag<["-"], "embed-bitcode">,
16251630
Flags<[FrontendOption, NoInteractiveOption]>,
16261631
HelpText<"Embed LLVM IR bitcode as data">;

lib/Driver/Driver.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,28 @@ static void validateProfilingArgs(DiagnosticEngine &diags,
219219
const Arg *ProfileUse = args.getLastArg(options::OPT_profile_use);
220220
const Arg *IRProfileGenerate =
221221
args.getLastArg(options::OPT_ir_profile_generate);
222+
const Arg *IRProfileUse = args.getLastArg(options::OPT_ir_profile_use);
222223
if (ProfileGenerate && ProfileUse) {
223224
diags.diagnose(SourceLoc(), diag::error_conflicting_options,
224225
"-profile-generate", "-profile-use");
225226
}
227+
if (ProfileGenerate && IRProfileUse) {
228+
diags.diagnose(SourceLoc(), diag::error_conflicting_options,
229+
"-profile-generate", "-ir-profile-use");
230+
}
226231
if (IRProfileGenerate && ProfileUse) {
227232
diags.diagnose(SourceLoc(), diag::error_conflicting_options,
228233
"-ir-profile-generate", "-profile-use");
229234
}
230-
235+
if (IRProfileGenerate && IRProfileUse) {
236+
diags.diagnose(SourceLoc(), diag::error_conflicting_options,
237+
"-ir-profile-generate", "-ir-profile-use");
238+
}
231239
// Check if the profdata is missing
232-
if (ProfileUse && !llvm::sys::fs::exists(ProfileUse->getValue())) {
233-
diags.diagnose(SourceLoc(), diag::error_profile_missing,
234-
ProfileUse->getValue());
240+
for (const Arg *use : {ProfileUse, IRProfileUse}) {
241+
if (use && !llvm::sys::fs::exists(use->getValue())) {
242+
diags.diagnose(SourceLoc(), diag::error_profile_missing, use->getValue());
243+
}
235244
}
236245
}
237246

lib/Driver/ToolChains.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
333333
inputArgs.AddLastArg(arguments, options::OPT_profile_generate);
334334
inputArgs.AddLastArg(arguments, options::OPT_profile_use);
335335
inputArgs.AddLastArg(arguments, options::OPT_ir_profile_generate);
336+
inputArgs.AddLastArg(arguments, options::OPT_ir_profile_use);
336337
inputArgs.AddLastArg(arguments, options::OPT_cs_profile_generate);
337338
inputArgs.AddLastArg(arguments, options::OPT_cs_profile_generate_EQ);
338339
inputArgs.AddLastArg(arguments, options::OPT_profile_coverage_mapping);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3502,6 +3502,8 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
35023502
Args.hasArg(OPT_cs_profile_generate_EQ);
35033503
if (auto V = Args.getLastArgValue(OPT_cs_profile_generate_EQ); !V.empty())
35043504
Opts.InstrProfileOutput = V.str();
3505+
const Arg *IRProfileUse = Args.getLastArg(OPT_ir_profile_use);
3506+
Opts.UseIRProfile = IRProfileUse ? IRProfileUse->getValue() : "";
35053507

35063508
Opts.DebugInfoForProfiling |= Args.hasArg(OPT_debug_info_for_profiling);
35073509

lib/IRGen/IRGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ static void populatePGOOptions(std::optional<PGOOptions> &Out,
232232
}
233233

234234
if (Opts.EnableCSIRProfileGen) {
235-
const bool hasUse = !Opts.UseProfile.empty();
235+
const bool hasUse = !Opts.UseIRProfile.empty();
236236
Out = PGOOptions(
237-
/*ProfileFile=*/ Opts.UseProfile,
237+
/*ProfileFile=*/ Opts.UseIRProfile,
238238
/*CSProfileGenFile=*/ Opts.InstrProfileOutput,
239239
/*ProfileRemappingFile=*/ "",
240240
/*MemoryProfile=*/ "",

0 commit comments

Comments
 (0)