Skip to content

Commit df3add1

Browse files
committed
Update Options.swift
1 parent 5c8c159 commit df3add1

File tree

5 files changed

+266
-22
lines changed

5 files changed

+266
-22
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3314,21 +3314,25 @@ extension Driver {
33143314
let genFlags: [Option] = [
33153315
.profileGenerate,
33163316
.irProfileGenerate,
3317+
.irProfileGenerateEQ,
33173318
.csProfileGenerate,
3318-
.csProfileGenerateEq,
3319+
.csProfileGenerateEQ,
33193320
]
3321+
func resolveDualFormConflict(_ plain: Option, _ equalsForm: Option) {
3322+
if parsedOptions.hasArgument(plain),
3323+
parsedOptions.hasArgument(equalsForm)
3324+
{
3325+
diagnosticEngine.emit(
3326+
.error(Error.conflictingOptions(plain, equalsForm)),
3327+
location: nil
3328+
)
3329+
providedGen.removeAll { $0 == equalsForm }
3330+
}
3331+
}
33203332

33213333
var providedGen = genFlags.filter { parsedOptions.hasArgument($0) }
3322-
if parsedOptions.hasArgument(.csProfileGenerate),
3323-
parsedOptions.hasArgument(.csProfileGenerateEq)
3324-
{
3325-
// If both forms were specified, report a clear conflict.
3326-
diagnosticEngine.emit(
3327-
.error(Error.conflictingOptions(.csProfileGenerate, .csProfileGenerateEq)),
3328-
location: nil
3329-
)
3330-
providedGen.removeAll { $0 == .csProfileGenerateEq }
3331-
}
3334+
resolveDualFormConflict(.irProfileGenerate, .irProfileGenerateEQ)
3335+
resolveDualFormConflict(.csProfileGenerate, .csProfileGenerateEQ)
33323336

33333337
guard providedGen.count >= 2 else { return }
33343338
for i in 1..<providedGen.count {
@@ -3344,10 +3348,12 @@ extension Driver {
33443348
let conflictingGenFlags: [Option] = [
33453349
.profileGenerate,
33463350
.irProfileGenerate,
3351+
.irProfileGenerateEQ,
33473352
]
33483353
let useProfArgs: [Option] = [
33493354
.profileUse,
33503355
.profileSampleUse,
3356+
.irProfileUse
33513357
]
33523358
let providedUse = useProfArgs.filter { parsedOptions.hasArgument($0) }
33533359
guard !providedUse.isEmpty else { return }
@@ -3412,6 +3418,10 @@ extension Driver {
34123418
if let profileSampleUseArg = parsedOptions.getLastArgument(.profileSampleUse)?.asSingle {
34133419
checkForMissingProfilingData([profileSampleUseArg])
34143420
}
3421+
3422+
if let irProfileUseArgs = parsedOptions.getLastArgument(.irProfileUse)?.asMultiple {
3423+
checkForMissingProfilingData(irProfileUseArgs)
3424+
}
34153425
}
34163426

34173427
static func validateParseableOutputArgs(_ parsedOptions: inout ParsedOptions,

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,9 @@ extension Driver {
238238
try commandLine.appendLast(.suppressWarnings, from: &parsedOptions)
239239
try commandLine.appendLast(.profileGenerate, from: &parsedOptions)
240240
try commandLine.appendLast(.irProfileGenerate, from: &parsedOptions)
241+
try commandLine.appendLast(.irProfileGenerateEQ, from: &parsedOptions)
241242
try commandLine.appendLast(.csProfileGenerate, from: &parsedOptions)
242-
try commandLine.appendLast(.csProfileGenerateEq, from: &parsedOptions)
243+
try commandLine.appendLast(.csProfileGenerateEQ, from: &parsedOptions)
243244
try commandLine.appendLast(.profileUse, from: &parsedOptions)
244245
try commandLine.appendLast(.profileCoverageMapping, from: &parsedOptions)
245246
try commandLine.appendLast(.debugInfoForProfiling, from: &parsedOptions)

Sources/SwiftDriver/Toolchains/Toolchain.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,23 +384,34 @@ extension Toolchain {
384384
args.append("-fprofile-generate")
385385
}
386386

387+
if options.contains(.irProfileGenerateEQ),
388+
let path = options.getLastArgument(.irProfileGenerateEQ)?.asSingle {
389+
args.append("-fprofile-generate=\(path)")
390+
}
391+
387392
if options.contains(.csProfileGenerate) {
388393
args.append("-fcs-profile-generate")
389394
}
390395

391-
if options.contains(.csProfileGenerateEq),
392-
let path = options.getLastArgument(.csProfileGenerateEq)?.asSingle {
396+
if options.contains(.csProfileGenerateEQ),
397+
let path = options.getLastArgument(.csProfileGenerateEQ)?.asSingle {
393398
args.append("-fcs-profile-generate=\(path)")
394399
}
395400

401+
if options.contains(.irProfileUse),
402+
let path = options.getLastArgument(.irProfileUse)?.asMultiple.last {
403+
args.append("-fprofile-use=\(path)")
404+
}
405+
396406
return args
397407
}
398408

399409
internal func needsInstrumentedProfile(from parsedOptions: inout ParsedOptions) -> Bool {
400410
parsedOptions.contains(.profileGenerate) ||
401411
parsedOptions.contains(.irProfileGenerate) ||
412+
parsedOptions.contains(.irProfileGenerateEQ) ||
402413
parsedOptions.contains(.csProfileGenerate) ||
403-
parsedOptions.contains(.csProfileGenerateEq)
414+
parsedOptions.contains(.csProfileGenerateEQ)
404415
}
405416
}
406417

Sources/SwiftOptions/Options.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ extension Option {
105105
public static let coveragePrefixMap: Option = Option("-coverage-prefix-map", .separate, attributes: [.frontend], metaVar: "<prefix=replacement>", helpText: "Remap source paths in coverage info")
106106
public static let CrossModuleOptimization: Option = Option("-cross-module-optimization", .flag, attributes: [.helpHidden, .frontend], helpText: "Perform cross-module optimization")
107107
public static let crosscheckUnqualifiedLookup: Option = Option("-crosscheck-unqualified-lookup", .flag, attributes: [.frontend, .noDriver], helpText: "Compare legacy DeclContext- to ASTScope-based unqualified name lookup (for debugging)")
108+
public static let csProfileGenerateEQ: Option = Option("-cs-profile-generate=", .joined, attributes: [.frontend, .noInteractive], metaVar: "<directory>", helpText: "Generate instrumented code to collect context sensitive execution counts into <directory>/default.profraw (overridden by LLVM_PROFILE_FILE env var)")
109+
public static let csProfileGenerate: Option = Option("-cs-profile-generate", .flag, attributes: [.frontend, .noInteractive], helpText: "Generate instrumented code to collect context sensitive execution counts into default.profraw (overridden by LLVM_PROFILE_FILE env var)")
108110
public static let cxxInteropGettersSettersAsProperties: Option = Option("-cxx-interop-getters-setters-as-properties", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Import getters and setters as computed properties in Swift")
109111
public static let cxxInteropUseOpaquePointerForMoveonly: Option = Option("-cxx-interop-use-opaque-pointer-for-moveonly", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Testing flag that will be eliminated soon. Do not use.")
110112
public static let cxxInteroperabilityMode: Option = Option("-cxx-interoperability-mode=", .joined, attributes: [.frontend, .synthesizeInterface], helpText: "Enables C++ interoperability; pass 'default' to enable or 'off' to disable")
@@ -643,6 +645,9 @@ extension Option {
643645
public static let swiftinterfaceCompilerVersion: Option = Option("-interface-compiler-version", .separate, attributes: [.helpHidden, .frontend], metaVar: "<intcvers>", helpText: "The version of the Swift compiler used to generate a .swiftinterface file")
644646
public static let internalizeAtLink: Option = Option("-internalize-at-link", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Allow internalizing public symbols and vtables at link time (assume all client code of public types is part of the same link unit, or that external symbols are explicitly requested via -exported_symbols_list)")
645647
public static let interpret: Option = Option("-interpret", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Immediate mode", group: .modes)
648+
public static let irProfileGenerateEQ: Option = Option("-ir-profile-generate=", .joined, attributes: [.frontend, .noInteractive], metaVar: "<directory>", helpText: "Generate instrumented code to collect execution counts into <directory>/default.profraw (overridden by LLVM_PROFILE_FILE env var)")
649+
public static let irProfileGenerate: Option = Option("-ir-profile-generate", .flag, attributes: [.frontend, .noInteractive], helpText: "Generate instrumented code to collect execution counts into default.profraw (overridden by LLVM_PROFILE_FILE env var)")
650+
public static let irProfileUse: Option = Option("-ir-profile-use=", .commaJoined, attributes: [.frontend, .noInteractive, .argumentIsPath], metaVar: "<profdata>", helpText: "Supply an IR-level PGO profdata file to enable profile-guided optimization")
646651
public static let Isystem: Option = Option("-Isystem", .separate, attributes: [.frontend, .synthesizeInterface, .argumentIsPath], helpText: "Add directory to the system import search path")
647652
public static let I: Option = Option("-I", .joinedOrSeparate, attributes: [.frontend, .synthesizeInterface, .argumentIsPath], helpText: "Add directory to the import search path")
648653
public static let i: Option = Option("-i", .flag, group: .modes)
@@ -776,9 +781,6 @@ extension Option {
776781
public static let printZeroStats: Option = Option("-print-zero-stats", .flag, attributes: [.helpHidden, .frontend], helpText: "Prints all stats even if they are zero")
777782
public static let profileCoverageMapping: Option = Option("-profile-coverage-mapping", .flag, attributes: [.frontend, .noInteractive], helpText: "Generate coverage data for use with profiled execution counts")
778783
public static let profileGenerate: Option = Option("-profile-generate", .flag, attributes: [.frontend, .noInteractive], helpText: "Generate instrumented code to collect execution counts")
779-
public static let irProfileGenerate: Option = Option("-ir-profile-generate", .flag, attributes: [.frontend, .noInteractive], helpText: "Generate instrumented code to collect execution counts into default.profraw (overridden by LLVM_PROFILE_FILE env var)")
780-
public static let csProfileGenerate: Option = Option("-cs-profile-generate", .flag, attributes: [.frontend, .noInteractive], helpText: "Generate instrumented code to collect context sensitive execution counts into default.profraw (overridden by LLVM_PROFILE_FILE env var)")
781-
public static let csProfileGenerateEq: Option = Option("-cs-profile-generate=", .joined, attributes: [.frontend, .noInteractive, .argumentIsPath], metaVar: "<dir>", helpText: "Generate instrumented code to collect context sensitive execution counts into <directory>/default.profraw (overridden by LLVM_PROFILE_FILE env var)")
782784
public static let profileSampleUse: Option = Option("-profile-sample-use=", .joined, attributes: [.frontend, .noInteractive, .argumentIsPath], metaVar: "<profile data>", helpText: "Supply sampling-based profiling data from llvm-profdata to enable profile-guided optimization")
783785
public static let profileStatsEntities: Option = Option("-profile-stats-entities", .flag, attributes: [.helpHidden, .frontend], helpText: "Profile changes to stats in -stats-output-dir, subdivided by source entity")
784786
public static let profileStatsEvents: Option = Option("-profile-stats-events", .flag, attributes: [.helpHidden, .frontend], helpText: "Profile changes to stats in -stats-output-dir")
@@ -1081,6 +1083,8 @@ extension Option {
10811083
Option.coveragePrefixMap,
10821084
Option.CrossModuleOptimization,
10831085
Option.crosscheckUnqualifiedLookup,
1086+
Option.csProfileGenerateEQ,
1087+
Option.csProfileGenerate,
10841088
Option.cxxInteropGettersSettersAsProperties,
10851089
Option.cxxInteropUseOpaquePointerForMoveonly,
10861090
Option.cxxInteroperabilityMode,
@@ -1619,6 +1623,9 @@ extension Option {
16191623
Option.swiftinterfaceCompilerVersion,
16201624
Option.internalizeAtLink,
16211625
Option.interpret,
1626+
Option.irProfileGenerateEQ,
1627+
Option.irProfileGenerate,
1628+
Option.irProfileUse,
16221629
Option.Isystem,
16231630
Option.I,
16241631
Option.i,
@@ -1752,9 +1759,6 @@ extension Option {
17521759
Option.printZeroStats,
17531760
Option.profileCoverageMapping,
17541761
Option.profileGenerate,
1755-
Option.irProfileGenerate,
1756-
Option.csProfileGenerate,
1757-
Option.csProfileGenerateEq,
17581762
Option.profileSampleUse,
17591763
Option.profileStatsEntities,
17601764
Option.profileStatsEvents,

0 commit comments

Comments
 (0)