-
Notifications
You must be signed in to change notification settings - Fork 10.5k
SIL: add the borrowed-from instruction #71176
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
SIL: add the borrowed-from instruction #71176
Conversation
898c0c0
to
fad94c6
Compare
fad94c6
to
daa7bc7
Compare
a2f9dc7
to
237bd40
Compare
@swift-ci test |
@swift-ci test |
2955436
to
973467f
Compare
@swift-ci benchmark |
973467f
to
a1d9657
Compare
a1d9657
to
9ddaf33
Compare
@swift-ci test |
(``%1``). | ||
In case of an adjacent phi, all incoming values of the adjacent phi must be | ||
borrow introducers for the corresponding incoming value of the borrowed | ||
operand in all predecessor blocks. |
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.
While working on guaranteed phis, I think I encountered some cases where enclosing value could be adjacent or dominating. Does the borrowed from insertion pass handle when this can happen ?
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.
I'm not sure what you mean exactly. Yes, the enclosing values (= the operands after from
) can be an adjacent phis or dominating borrow introducers.
This is computed iteratively (until convergence) from incoming values in predcessors
…a reverse dependency
It declares from which enclosing values a guaranteed phi argument is borrowed from.
Compute, update and handle borrowed-from instruction in various utilities and passes. Also, used borrowed-from to simplify `gatherBorrowIntroducers` and `gatherEnclosingValues`. Replace those utilities by `Value.getBorrowIntroducers` and `Value.getEnclosingValues`, which return a lazily computed Sequence of borrowed/enclosing values.
9ddaf33
to
e14c1d1
Compare
@swift-ci smoke test |
The borrowed-from instruction declares from which enclosing values a guaranteed phi argument is borrowed from. For example:
An enclosing value is either a dominating borrow introducer of the borrowed operand (
%3
) or an adjacent phi-argument in the same block (%4
).So far, this information was computed dynamically by ownership utilities (e.g.
gatherEnclosingValues
). With the borrowed-from instructions those utilities get dramatically simpler.The borrowed-from instruction is similar in spirit to phi-nodes in plain SSA: it "caches" information from predecessor blocks so that optimization passes can easily access this information. If an optimization pass introduces a new guaranteed phi argument it can use the
BorrowedFromUpdater
to generate the required borrowed-from instructions. This is similar toSSAUpdater
which inserts required phi-nodes.Beside simplifying the ownership utilities, it's also useful that the adjacent phi relations are now explicitly visible in SIL.
Another nice thing is that this change is (almost) a pure addition to SIL. This means that the existing C++ ownership utilities still work - with and without inserted borrowed-from instructions. The only exception is that they have to look through borrowed-from instructions in some places.