5.10: [CanonicalizeOSSALifetime] Extend lexical lifetimes to unreachables. #68691
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description: Work around incomplete lifetimes to extend lifetimes to unreachables.
When a non-lexical value's lifetime is canonicalized, copies are propagated to consuming uses and destroys to last non-consuming uses. Shortening a lexical value's lifetime in that way isn't allowed: it doesn't respect deinit barriers.
The original lifetime of a value ends at its original lifetime-ending uses: destroys, last consumes, and--without complete OSSA lifetimes enabled--
unreachable
instructions. For a lexical value, the lifetime ends after canonicalization can be hoisted but not over any instructions that are deinit barriers. For destroys, this is handled via a backwards walk.Here, because complete OSSA lifetimes aren't enabled, handling is added for unreachables. The approach is to add the instructions before the
unreachable
instructions to liveness and then skip creating adestroy_value
if the next instruction is anunreachable
.To find the relevant
unreachable
instructions, a copy ofPrunedLiveness
that canonicalization uses is created and the destroys are added to it. (Destroys are not in the original instance of liveness and should not be added to it because having them there would result in extra copies.) That copy is then passed to some utility code shared with OSSALifetimeCompletion to find theunreachable
instructions that terminate the dead-end blocks found by walking forward from the boundary of liveness. Once thoseunreachable
s are found, the instructions prior to them are added to the original copy of liveness.Risk: Low. Uses two preexisting utilities (PrunedLiveness, OSSALifetimeCompletion)
Scope: Narrow. Only affects lifetimes in dead end blocks.
Original PR: #68608
Reviewed By: Andrew Trick ( @atrick )
Testing: Added tests.
Resolves: rdar://115468707