-
Notifications
You must be signed in to change notification settings - Fork 215
Adds IR level PGO Instrumentation options #1992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3307,24 +3307,93 @@ extension Driver { | |
| } | ||
| } | ||
|
|
||
| static private func validateProfilingGenerateArgs( | ||
| _ parsedOptions: inout ParsedOptions, | ||
| diagnosticEngine: DiagnosticsEngine | ||
| ) { | ||
| let genFlags: [Option] = [ | ||
| .profileGenerate, | ||
| .irProfileGenerate, | ||
| .irProfileGenerateEQ, | ||
| .csProfileGenerate, | ||
| .csProfileGenerateEQ, | ||
| ] | ||
| func resolveDualFormConflict(_ plain: Option, _ equalsForm: Option) { | ||
| if parsedOptions.hasArgument(plain), | ||
| parsedOptions.hasArgument(equalsForm) | ||
| { | ||
| diagnosticEngine.emit( | ||
| .error(Error.conflictingOptions(plain, equalsForm)), | ||
| location: nil | ||
| ) | ||
| providedGen.removeAll { $0 == equalsForm } | ||
| } | ||
| } | ||
|
|
||
| var providedGen = genFlags.filter { parsedOptions.hasArgument($0) } | ||
| resolveDualFormConflict(.irProfileGenerate, .irProfileGenerateEQ) | ||
| resolveDualFormConflict(.csProfileGenerate, .csProfileGenerateEQ) | ||
|
|
||
| guard providedGen.count >= 2 else { return } | ||
| for i in 1..<providedGen.count { | ||
| let error = Error.conflictingOptions(providedGen[i - 1], providedGen[i]) | ||
| diagnosticEngine.emit(.error(error), location: nil) | ||
| } | ||
| } | ||
|
|
||
| static private func validateProfilingUseArgs( | ||
| _ parsedOptions: inout ParsedOptions, | ||
| diagnosticEngine: DiagnosticsEngine | ||
| ) { | ||
| let conflictingGenFlags: [Option] = [ | ||
| .profileGenerate, | ||
| .irProfileGenerate, | ||
| .irProfileGenerateEQ, | ||
| ] | ||
| let useProfArgs: [Option] = [ | ||
| .profileUse, | ||
| .profileSampleUse, | ||
| .irProfileUse | ||
| ] | ||
| let providedUse = useProfArgs.filter { parsedOptions.hasArgument($0) } | ||
| guard !providedUse.isEmpty else { return } | ||
|
|
||
| // At most one *use* option allowed | ||
| if providedUse.count > 1 { | ||
| for i in 0..<(providedUse.count - 1) { | ||
| for j in (i + 1)..<providedUse.count { | ||
|
Comment on lines
+3363
to
+3364
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking that maybe is easier to understand (and to repeat here and above), if one uses |
||
| diagnosticEngine.emit( | ||
| .error(Error.conflictingOptions(providedUse[i], providedUse[j])), | ||
| location: nil | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // If no generate flags, we're good. | ||
| let providedGen = conflictingGenFlags.filter { parsedOptions.hasArgument($0) } | ||
| guard !providedGen.isEmpty else { return } | ||
|
|
||
| // We already diagnosed if the user passed more than one "use" option | ||
| // (e.g. both `-profile-use` and `-profile-sample-use`). To avoid | ||
| // spamming diagnostics, we now treat the first provided "use" flag | ||
| // as the canonical representative. | ||
| let canonicalUse = providedUse[0] | ||
|
|
||
| // Generate vs Use are mutually exclusive | ||
| for g in providedGen { | ||
| diagnosticEngine.emit(.error(Error.conflictingOptions(g, canonicalUse)), location: nil) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| static func validateProfilingArgs(_ parsedOptions: inout ParsedOptions, | ||
| fileSystem: FileSystem, | ||
| workingDirectory: AbsolutePath?, | ||
| diagnosticEngine: DiagnosticsEngine) { | ||
| let conflictingProfArgs: [Option] = [.profileGenerate, | ||
| .profileUse, | ||
| .profileSampleUse] | ||
|
|
||
| // Find out which of the mutually exclusive profiling arguments were provided. | ||
| let provided = conflictingProfArgs.filter { parsedOptions.hasArgument($0) } | ||
|
|
||
| // If there's at least two of them, there's a conflict. | ||
| if provided.count >= 2 { | ||
| for i in 1..<provided.count { | ||
| let error = Error.conflictingOptions(provided[i-1], provided[i]) | ||
| diagnosticEngine.emit(.error(error), location: nil) | ||
| } | ||
| } | ||
| validateProfilingGenerateArgs(&parsedOptions, diagnosticEngine: diagnosticEngine) | ||
| validateProfilingUseArgs(&parsedOptions, diagnosticEngine: diagnosticEngine) | ||
|
|
||
| // Ensure files exist for the given paths. | ||
| func checkForMissingProfilingData(_ profileDataArgs: [String]) { | ||
|
|
@@ -3349,6 +3418,10 @@ extension Driver { | |
| if let profileSampleUseArg = parsedOptions.getLastArgument(.profileSampleUse)?.asSingle { | ||
| checkForMissingProfilingData([profileSampleUseArg]) | ||
| } | ||
|
|
||
| if let irProfileUseArgs = parsedOptions.getLastArgument(.irProfileUse)?.asMultiple { | ||
| checkForMissingProfilingData(irProfileUseArgs) | ||
| } | ||
| } | ||
|
|
||
| static func validateParseableOutputArgs(_ parsedOptions: inout ParsedOptions, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -258,9 +258,7 @@ extension DarwinToolchain { | |
| fileSystem: fileSystem | ||
| ) | ||
|
|
||
| if parsedOptions.hasArgument(.profileGenerate) { | ||
| commandLine.appendFlag("-fprofile-generate") | ||
| } | ||
|
Comment on lines
-261
to
-263
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels like a bug to me. As I understand, Swift's
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this behavior is existing in swift-driver today, and I’m a bit wary of changing it here because there may be tests and downstream flows that rely on it. This PR is primarily adding the new pieces, that said, if you feel it’s worth addressing this legacy behavior in the same PR, please let me know and I can look into it. |
||
| commandLine.appendFlags(mapInstrumentationTypeToClangArgs(from: &parsedOptions)) | ||
|
|
||
| // These custom arguments should be right before the object file at the | ||
| // end. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -237,6 +237,11 @@ extension Driver { | |
| try commandLine.appendLast(.RpassMissedEQ, from: &parsedOptions) | ||
| try commandLine.appendLast(.suppressWarnings, from: &parsedOptions) | ||
| try commandLine.appendLast(.profileGenerate, from: &parsedOptions) | ||
| try commandLine.appendLast(.irProfileGenerate, from: &parsedOptions) | ||
| try commandLine.appendLast(.irProfileGenerateEQ, from: &parsedOptions) | ||
| try commandLine.appendLast(.irProfileUse, from: &parsedOptions) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a flag that points to the file. It needs path remapping if needed. Use Also means this is not handled correctly in swift-frontend/scanner. See the comment I added to the other review. |
||
| try commandLine.appendLast(.csProfileGenerate, from: &parsedOptions) | ||
| try commandLine.appendLast(.csProfileGenerateEQ, from: &parsedOptions) | ||
| try commandLine.appendLast(.profileUse, from: &parsedOptions) | ||
| try commandLine.appendLast(.profileCoverageMapping, from: &parsedOptions) | ||
| try commandLine.appendLast(.debugInfoForProfiling, from: &parsedOptions) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: any reason for this not being similar to the C++ driver?
Edit: I did not realize that you were might have been moving around existing code. @kavon might be able to answer this better, but maybe what might have worked for them and only 3 flags might not work as well for 5 flags (and when the flags do not mix
genanduselike in their case).