Skip to content

[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

Merged
merged 7 commits into from
Sep 28, 2021

Conversation

nate-chandler
Copy link
Contributor

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 introduced to encode the same lifetime as the alloc_stacks did. Here, that is done.

@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler force-pushed the lexical_lifetimes/mem2reg branch from 8ca0f5e to d711283 Compare September 27, 2021 03:21
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - d7112833c1fd77a7d781d46d4c8ba735fa168c02

@nate-chandler nate-chandler force-pushed the lexical_lifetimes/mem2reg branch from d711283 to 48be432 Compare September 27, 2021 15:02
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler force-pushed the lexical_lifetimes/mem2reg branch 2 times, most recently from 4290541 to 06e73f8 Compare September 27, 2021 17:44
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler force-pushed the lexical_lifetimes/mem2reg branch from 06e73f8 to f6b5215 Compare September 27, 2021 17:55
@nate-chandler
Copy link
Contributor Author

@swift-ci please 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.

Minor comments

@nate-chandler nate-chandler force-pushed the lexical_lifetimes/mem2reg branch 3 times, most recently from c9ada12 to 771ace1 Compare September 27, 2021 21:27
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.

changes look good

@nate-chandler nate-chandler force-pushed the lexical_lifetimes/mem2reg branch 4 times, most recently from bfee7ea to 354b73c Compare September 28, 2021 01:10
@nate-chandler
Copy link
Contributor Author

@swift-ci please test and merge

@nate-chandler
Copy link
Contributor Author

@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.
@nate-chandler nate-chandler force-pushed the lexical_lifetimes/mem2reg branch from 354b73c to 79bc4cb Compare September 28, 2021 03:29
@nate-chandler
Copy link
Contributor Author

@swift-ci please test and merge

@swift-ci swift-ci merged commit f872d00 into swiftlang:main Sep 28, 2021
@nate-chandler nate-chandler deleted the lexical_lifetimes/mem2reg branch July 5, 2023 23:32
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.

3 participants