-
Notifications
You must be signed in to change notification settings - Fork 10.5k
CopyPropagation for SILValues with ownership. #18902
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
Conversation
@swift-ci test. |
@eeckstein @gottesmm @aschwaighofer high-level reviews are welcome, keeping in mind that this isn't enabled yet. The next step is moving all the ownership utilities into a centralized API. |
@swift-ci test. |
@aschwaighofer @eeckstein anyone interested in reviewing this? |
Build failed |
Build failed |
@aschwaighofer @eeckstein I'm rewriting all the comments now. So don't spend time on the current PR until I finish that. |
@eeckstein @aschwaighofer @gottesmm |
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.
much better now, thanks!
/// | ||
/// bb0(%arg : @owned $T, %addr : @trivial $*T): | ||
/// (The original copy is deleted.) | ||
/// debug_value %copy : $T |
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.
The operand be %arg
/// %copy = copy_value %0 : $T | ||
/// store %3 to [init] %1 : $*T | ||
/// (The non-consuming use now uses the original value.) | ||
/// debug_value %0 : $T |
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.
s/%0/%arg
the same on the next 2 lines
/// debug_value %copy : $T | ||
/// (A new copy_value is inserted before the consuming store.) | ||
/// %copy = copy_value %0 : $T | ||
/// store %3 to [init] %1 : $*T |
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.
s/%3/%copy/
|
||
void markBlockLive(SILBasicBlock *bb, IsLive_t isLive) { | ||
assert(isLive != Dead && "erasing live blocks isn't implemented."); | ||
liveBlocks[bb] = isLive; |
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.
implicitly converting an enum to a bool.
Better: liveBlocks[bb] = (isLive == LiveOut);
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.
Of course. Done.
This is a simple "utility" pass that canonicalizes SSA SILValues with respect to copies and destroys. It is a self-contained, provably complete pass that eliminates spurious copy_value instructions from scalar SSA SILValues. It fundamentally depends on ownership SIL, but otherwise can be run efficiently after any other pass. It separates the pure problem of handling scalar SSA values from the more important and complex problems: - Promoting variables to SSA form (PredictableMemOps and Mem2Reg partially do this). - Optimizing copies within "SIL borrow" scopes (another mandatory pass will be introduced to do this). - Composing and decomposing aggregates (SROA handles some of this). - Coalescing phis (A BlockArgumentOptimizer will be introduced as part of AddressLowering). - Removing unnecessary retain/release when nothing within its scope may release the same object (ARC Code Motion does some of this). Note that removing SSA copies was more obviously necessary before the migration to +0 argument convention.
@swift-ci smoke test. |
This pass is part of a prototype that I implemented a year ago to experiment with opaque SIL values. The pass isn't particularly useful until after opaque values are enabled. However, we want to begin incrementally merging support for opaque values because there are interdepedencies with other work. Also, we want to be transparent about opaque values work, now that we're ramping it back up.
This is a simple "utility" pass that canonicalizes SSA SILValues with
respect to copies and destroys. It is a self-contained, provably
complete pass that eliminates spurious copy_value instructions from
scalar SSA SILValues. It fundamentally depends on ownership SIL, but
otherwise can be run efficiently after any other pass. It separates
the pure problem of handling scalar SSA values from the more important
and complex problems:
Promoting variables to SSA form (PredictableMemOps and Mem2Reg
partially do this).
Optimizing copies within "SIL borrow" scopes (another mandatory pass
will be introduced to do this).
Composing and decomposing aggregates (SROA handles some of this).
Coalescing phis (A BlockArgumentOptimizer will be introduced as part
of AddressLowering).
Removing unnecessary retain/release when nothing within its scope
may release the same object (ARC Code Motion does some of this).
Note that removing SSA copies was more obviously necessary before the
migration to +0 argument convention.