Add IRPGO and CSIRPGO options to Swift (#84335)

This PR introduces three new instrumentation flags and plumbs them
through to IRGen:

1. `-ir-profile-generate` - enable IR-level instrumentation.
2. `-cs-profile-generate` - enable context-sensitive IR-level
instrumentation.
3. `-ir-profile-use` - IR-level PGO input profdata file to enable
profile-guided optimization (both IRPGO and CSIRPGO)

**Context:**
https://forums.swift.org/t/ir-level-pgo-instrumentation-in-swift/82123

**Swift-driver PR:** https://github.com/swiftlang/swift-driver/pull/1992

**Tests and validation:**
This PR includes ir level verification tests, also checks few edge-cases
when `-ir-profile-use` supplied profile is either missing or is an
invalid IR profile.

However, for argument validation, linking, and generating IR profiles
that can later be consumed by -cs-profile-generate, I’ll need
corresponding swift-driver changes. Those changes are being tracked in
https://github.com/swiftlang/swift-driver/pull/1992
This commit is contained in:
Chirag Ramani
2025-10-09 17:41:47 -07:00
committed by GitHub
parent 8458226347
commit 5179bc9609
15 changed files with 409 additions and 11 deletions

View File

@@ -3572,6 +3572,17 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
const Arg *ProfileSampleUse = Args.getLastArg(OPT_profile_sample_use);
Opts.UseSampleProfile = ProfileSampleUse ? ProfileSampleUse->getValue() : "";
Opts.EnableIRProfileGen = Args.hasArg(OPT_ir_profile_generate) ||
Args.hasArg(OPT_ir_profile_generate_EQ);
if (auto V = Args.getLastArgValue(OPT_ir_profile_generate_EQ); !V.empty())
Opts.InstrProfileOutput = V.str();
Opts.EnableCSIRProfileGen = Args.hasArg(OPT_cs_profile_generate) ||
Args.hasArg(OPT_cs_profile_generate_EQ);
if (auto V = Args.getLastArgValue(OPT_cs_profile_generate_EQ); !V.empty())
Opts.InstrProfileOutput = V.str();
const Arg *IRProfileUse = Args.getLastArg(OPT_ir_profile_use);
Opts.UseIRProfile = IRProfileUse ? IRProfileUse->getValue() : "";
Opts.DebugInfoForProfiling |= Args.hasArg(OPT_debug_info_for_profiling);