Skip to content

[SILOptimizer] Add deinit-barrier side-effect. #61495

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 6 commits into from
Oct 20, 2022

Conversation

nate-chandler
Copy link
Contributor

@nate-chandler nate-chandler commented Oct 7, 2022

Computed whether a function counts as a deinit barrier during ComputeSideEffects. Hoisted destroy_addrs of lexical addresses, destroy_values of owned lexical values, and end_borrows of lexical begin_borrows over applies of functions which are not deinit barriers.

@nate-chandler nate-chandler force-pushed the rdar90412220 branch 5 times, most recently from 95a441b to 33f71f7 Compare October 13, 2022 22:19
@nate-chandler nate-chandler marked this pull request as ready for review October 13, 2022 22:20
@nate-chandler nate-chandler assigned atrick and meg-gupta and unassigned atrick and meg-gupta Oct 14, 2022
@nate-chandler nate-chandler force-pushed the rdar90412220 branch 2 times, most recently from 4dc3dcf to 6cb48bc Compare October 14, 2022 17:45
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler force-pushed the rdar90412220 branch 3 times, most recently from e1ec516 to 9fbd4cb Compare October 18, 2022 17:15
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

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

nice!
lgtm

@nate-chandler nate-chandler force-pushed the rdar90412220 branch 2 times, most recently from ccf9a6b to 21bca72 Compare October 19, 2022 00:49
Added new C++-to-Swift callback for isDeinitBarrier.

And pass it CalleeAnalysis so it can depend on function effects.  For
now, the argument is ignored.  And, all callers just pass nullptr.

Promoted to API the mayAccessPointer component predicate of
isDeinitBarrier which needs to remain in C++.  That predicate will also
depends on function effects.  For that reason, it too is now passed a
BasicCalleeAnalysis and is moved into SILOptimizer.

Also, added more conservative versions of isDeinitBarrier and
maySynchronize which will never consider side-effects.
Functions "are deinit barriers" (more pedantically, applies of functions
are deinit barriers) if any of their instructions are deinit barriers.
During side-effect analysis, when walking a function's instructions for
other global effects, also check for the deinit-barrier effect.  If an
instruction is found to be a deinit barrier, mark the function's global
effects accordingly.

Add SILFunction::isDeinitBarrier to conveniently access the effects
computed during ComputeSideEffects.

Update the isBarrierApply predicate to iterate over the list of callees,
if complete, to check whether any is a deinit barrier.  If none is, then
the apply is not a deinit barrier.
Checked that applies of empty functions, or their callees, or their
callees' callees, are not deinit barriers.  Checked that applies of
unknown functions, or their callees, or their callees' calles, are
deinit barriers.
Pass a BasicCalleeAnalysis instance to isDeinitBarrier.  This will
enable SSADestroyHoisting to hoist destroy_addrs over applies of
functions that are not themselves deinit barriers.
Pass a BasicCalleeAnalysis instance to isDeinitBarrier.  This will allow
ShrinkBorrowScope to hoist end_borrows over applies of functions which
are not deinit barriers.
Pass a BasicCalleeAnalysis instance to isDeinitBarrier.  This enables
LexicalDestroyHoisting to hoist destroys over applies of functions which
are not deinit barriers.
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler
Copy link
Contributor Author

@swift-ci please test source compatibility

@nate-chandler
Copy link
Contributor Author

@swift-ci please benchmark

@nate-chandler
Copy link
Contributor Author

@swift-ci please clean test macOS platform

1 similar comment
@nate-chandler
Copy link
Contributor Author

@swift-ci please clean test macOS platform

@nate-chandler nate-chandler merged commit 513b9cb into swiftlang:main Oct 20, 2022
@nate-chandler nate-chandler deleted the rdar90412220 branch October 20, 2022 01:21
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.

4 participants