-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Mem2Reg] Lexical allocs create lexical borrows. #39460
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
[Mem2Reg] Lexical allocs create lexical borrows. #39460
Conversation
@swift-ci please test |
8ca0f5e
to
d711283
Compare
@swift-ci please test |
Build failed |
d711283
to
48be432
Compare
@swift-ci please test |
4290541
to
06e73f8
Compare
@swift-ci please test |
06e73f8
to
f6b5215
Compare
@swift-ci please test |
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 comments
c9ada12
to
771ace1
Compare
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.
changes look good
bfee7ea
to
354b73c
Compare
@swift-ci please test and merge |
@swift-ci please test windows platform |
Previously, there was only a frontend flag to influence the LangOpts struct. Now, the flag can be set when running sil-opt which is important for testing.
Previously, the addArgumentToBranch only allowed one to add a single additional argument to a branch. It then verified the argument count. That is a problem if multiple arguments have to be added to arrive at the correct argument count. Specifically, that was a problem when running Mem2Reg on a lexical alloc_stack, where three new phi arguments are added. Here, the function name is changed to addArgumentsToBranch (plural arguments) and the function accepts a SmallVector<SILValue> rather than a single SILValue, allowing one to add all the arguments that are necessary in order to verify that the resulting number of arguments is correct.
When the -enable-experimental-lexical-lifetimes flag is enabled, the alloc_stack instructions which the pass replaces alloc_box instructions with have the lexical attribute.
SILGen turns vars into alloc_boxes. When possible, AllocBoxToStack turns those into alloc_stacks. In order to preserve the lexical lifetime of those vars, the alloc_stacks are annotated with the [lexical] attribute. When Mem2Reg runs, it promotes the loads from and stores into those alloc_stacks to uses of registers. In order to preserve the lexical lifetime during that transformation, lexical borrow scopes must be introduces that encode the same lifetime as the alloc_stacks did. Here, that is done.
354b73c
to
79bc4cb
Compare
@swift-ci please test and merge |
SILGen turns vars into
alloc_box
es. When possible,AllocBoxToStack
turns those intoalloc_stack
s. In order to preserve the lexical lifetime of those vars, thealloc_stack
s are annotated with the[lexical]
attribute. WhenMem2Reg
runs, it promotes theload
s from andstore
s into thosealloc_stack
s to uses of registers. In order to preserve the lexical lifetime during that transformation, lexical borrow scopes must be introduced to encode the same lifetime as thealloc_stack
s did. Here, that is done.