Skip to content

AliasAnalysis: check for immutable scopes. #37473

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 3 commits into from
May 21, 2021

Conversation

eeckstein
Copy link
Contributor

If the "regular" alias analysis thinks that an instruction may write to an address, check if the instruction is in an immutable scope of V.
That means that even if we don't know anything about the instruction (e.g. a call to an unknown function), we can be sure that it cannot write to the address.

An immutable scope is for example a read-only begin_access/end_access scope.
Another example is a borrow scope of an immutable copy-on-write buffer, for example:

   %b = begin_borrow %array_buffer
   %addr = ref_element_addr [immutable] %b : $BufferType, #BufferType.someField

eeckstein added 2 commits May 18, 2021 08:56
This reduces the size of the index from 8 to 4 bytes, which is important in AliasAnalysis where we use pairs of such indices.
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein eeckstein requested review from gottesmm and atrick May 18, 2021 07:03
 If the "regular" alias analysis thinks that an instruction may write to an address, check if the instruction is in an immutable scope of V.
That means that even if we don't know anything about the instruction (e.g. a call to an unknown function), we can be sure that it cannot write to the address.

An immutable scope is for example a read-only begin_access/end_access scope.
Another example is a borrow scope of an immutable copy-on-write buffer, for example:
   %b = begin_borrow %array_buffer
   %addr = ref_element_addr [immutable] %b : $BufferType, #BufferType.someField
@eeckstein eeckstein force-pushed the aliasanalysis-immutable-scopes branch from 05f9272 to 3701de4 Compare May 18, 2021 08:15
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein eeckstein merged commit d001b1d into swiftlang:main May 21, 2021
@eeckstein eeckstein deleted the aliasanalysis-immutable-scopes branch May 21, 2021 06:28
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.

@eeckstein This code looks great. At some point it becomes worthwhile to compute instruction indices instead, but I don't know how close we are to that point yet.

We should be preserving access markers in OSSA. That will simplify a lot of logic and open up optimization.

We'll want to remove borrow scopes for temporaries, but the preserved access scope should serve the same purpose for those short scopes. Borrows will still be useful for the larger defined scopes.

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.

2 participants