-
Notifications
You must be signed in to change notification settings - Fork 10.5k
AliasAnalysis: a complete overhaul of alias- and memory-behavior analysis #75505
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@swift-ci test |
@swift-ci benchmark |
cd74d74
to
4119d5d
Compare
@swift-ci test |
…eOfMetatype` The same for SILType It needs to be made clear that this is not the "original", but the lowered SIL type. NFC
…e` builtin for function types We need to compare the not lowered types, because function types may differ in their original version but are equal in the lowered version, e.g. ``` ((Int, Int) -> ()) (((Int, Int)) -> ()) ``` Fixes a miscompile
Make each instruction to appear in a separate line
…irection` parameter It simplifies the EscapeUtils API NFC
… `BeginBorrowInst`
…lure` function in case of a failure This brings all the nice verifier features to the swift verifier, like printing the surrounding instructions in case of a failure, etc.
Indirect-in arguments are consumed by the caller and that not only counts as read but also as a write.
It was called for non-address operands of fix_lifetime. Just exclude such fix_lifetime instructions from moving. It's not important anyway.
… value Instead of just aborting if a `begin_apply` gets an address argument, follow the yielded values and see if they actually escape
It's dangerous to continue walking over an `unchecked_addr_cast` which casts between two different types. We can only do this if the result is known to be the end of the walk, i.e. the cast result is not used in a relevant way.
…ysis tests *) remove `// users: ...` comments *) replace some `CHECK:` with `CHECK-NEXT:` lines. Otherwise the test could pass although the result is wrong
…struction, ignoring:)`
…istinct` If the operand types (which are classes) of `ref_element_addr` or `ref_tail_addr` differ, then we know those can't be the same objects.
The result of a store_borrow can "escape" to other access bases, like a "pointer" access base. Then a store-borrow access base is _not_ distinct from such another base.
…ysis The main changes are: *) Rewrite everything in swift. So far, parts of memory-behavior analysis were already implemented in swift. Now everything is done in swift and lives in `AliasAnalysis.swift`. This is a big code simplification. *) Support many more instructions in the memory-behavior analysis - especially OSSA instructions, like `begin_borrow`, `end_borrow`, `store_borrow`, `load_borrow`. The computation of end_borrow effects is now much more precise. Also, partial_apply is now handled more precisely. *) Simplify and reduce type-based alias analysis (TBAA). The complexity of the old TBAA comes from old days where the language and SIL didn't have strict aliasing and exclusivity rules (e.g. for inout arguments). Now TBAA is only needed for code using unsafe pointers. The new TBAA handles this - and not more. Note that TBAA for classes is already done in `AccessBase.isDistinct`. *) Handle aliasing in `begin_access [modify]` scopes. We already supported truly immutable scopes like `begin_access [read]` or `ref_element_addr [immutable]`. For `begin_access [modify]` we know that there are no other reads or writes to the access-address within the scope. *) Don't cache memory-behavior results. It turned out that the hit-miss rate was pretty bad (~ 1:7). The overhead of the cache lookup took as long as recomputing the memory behavior.
4119d5d
to
031f235
Compare
@swift-ci test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The main changes are:
Rewrite everything in swift. So far, parts of memory-behavior analysis were already implemented in swift. Now everything is done in swift and lives in
AliasAnalysis.swift
. This is a big code simplification.Support many more instructions in the memory-behavior analysis - especially OSSA instructions, like
begin_borrow
,end_borrow
,store_borrow
,load_borrow
. The computation of end_borrow effects is now much more precise. Also, partial_apply is now handled more precisely.Simplify and reduce type-based alias analysis (TBAA). The complexity of the old TBAA comes from old days where the language and SIL didn't have strict aliasing and exclusivity rules (e.g. for inout arguments). Now TBAA is only needed for code using unsafe pointers and for classes. The new TBAA handles this - and not more.
Handle aliasing in
begin_access [modify]
scopes. We already supported truly immutable scopes likebegin_access [read]
orref_element_addr [immutable]
. Forbegin_access [modify]
we know that there are no other reads or writes to the access-address within the scope.Don't cache memory-behavior results. It turned out that the hit-miss rate was pretty bad (~ 1:7). The overhead of the cache lookup took as long as recomputing the memory behavior.
Also fix a wrong constant folding of the
is_same_metatype
builtin for function type. This was uncovered by a lit test due to the better alias analysis.