Skip to content

Fix several problems with performance annotations #65820

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

Merged
merged 18 commits into from
May 11, 2023

Conversation

eeckstein
Copy link
Contributor

And rewrite the MandatoryGenericSpecializer in Swift.
The new MandatoryPerformanceOptimizations pass is more powerful because it uses the existing instruction simplification infrastructure. This fixes some false alarms with the performance annotations _noLocks and _noAllocation.

This PR contains several other small fixes and improvements, like extracting the named-return-value optimization from CopyForwarding into its own pass.
For details see the commit messages.

rdar://107576739
rdar://107576844
rdar://107017103, #64511

@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein
Copy link
Contributor Author

@swift-ci benchmark

@eeckstein
Copy link
Contributor Author

@swift-ci test

Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great based on a quick review. I mostly need to trust you on correctness. Too much to review in careful detail.

@@ -758,6 +758,11 @@ static void addLowLevelPassPipeline(SILPassPipelinePlan &P) {

addFunctionPasses(P, OptimizationLevelKind::LowLevel);

// The NamedReturnValueOptimization shouldn't be done before serialization,
// because it might prevent predictable memory optimizations in the caller
// after inlining.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for commenting this pipeline restriction. Pipeline comments are helpful, but I think we should also have a convention that pass dependencies are specified in the file that defines the pass. That's where people will see it when they are investigating the pass, and the information won't be lost as easily. I regularly see the pipeline comments get messed up as people hack on it. In the pass file, you can describe the dependency in more detail with examples. In this case, I'm not sure why NRVO interferes with predictable mem opts, but deferring it until after serialization seems reasonable. It doesn't seem needed for canonicalization and might not be useful if inlining happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍I added a comment

@@ -0,0 +1,132 @@
// RUN: %target-sil-opt -enable-sil-verify-all %s -mandatory-performance-optimizations | %FileCheck %s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: filename typo optimiations

eeckstein added 16 commits May 11, 2023 08:03
…oves the self parameter of a method

When dropping the self metatype parameter of a method, it must become a "thin" function.

Fixes a crash when using performance annotations.

rdar://107202455
The module doesn't necessarily need to be in a valid state when de-serializing a function
This was a leftover from the time we didn't use C++ interop
Performance annotations can now be used without specifying this option
as a shortcut for `Instruction.setOperand`
…ng to a separate function pass

This allows to run the NamedReturnValueOptimization only late in the pipeline.
The optimization shouldn't be done before serialization, because it might prevent predictable memory optimizations in the caller after inlining.
…ries

Instead bail when trying to deleted a dead closure or when performing the apply-of-partial_apply optimization.

TODO: In OSSA this should be solvable without the need of copies to temporaries.
… partial_apply

* move the apply of partial_apply transformation from simplify-apply to simplify-partial_apply
* delete dead partial_apply instructions
* devirtualize apply, try_apply and begin_apply
* `Options.assertConfiguration`
* `Argument.isIndirectResult`
* in `Function`: `selfArgument`, `isTransparent`, `performanceConstraints` and `inlineStrategy`
* `BuiltinInst.substitutionMap`
* `SubstitutionMap.replacementTypes`
* `Type.canBeClass`
As a replacement for the old MandatoryGenericSpecializer

The pass it not enabled yet in the pass pipeline
@eeckstein eeckstein force-pushed the performance-annotations branch from 52ac4d1 to 13108d6 Compare May 11, 2023 06:14
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test and merge

@swift-ci swift-ci merged commit 6877778 into swiftlang:main May 11, 2023
@eeckstein eeckstein deleted the performance-annotations branch May 11, 2023 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@_noLocks is overly restrictive prohibiting common real-time code patterns
4 participants