Skip to content

Commit f83f437

Browse files
committed
[NFC] OwnedValueCan: Extracted extension visitor.
Parameterized `extendUnconsumedLiveness` on the ends of interest and the action to take when visiting the extended boundary and named the resulting function `visitExtendedUnconsumedBoundary`.
1 parent 371c242 commit f83f437

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

include/swift/SILOptimizer/Utils/CanonicalizeOSSALifetime.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,10 @@ class CanonicalizeOSSALifetime final {
459459
void extendLivenessToDeinitBarriers();
460460

461461
void extendUnconsumedLiveness(PrunedLivenessBoundary const &boundary);
462+
void visitExtendedUnconsumedBoundary(
463+
ArrayRef<SILInstruction *> ends,
464+
llvm::function_ref<void(SILInstruction *, PrunedLiveness::LifetimeEnding)>
465+
visitor);
462466

463467
void insertDestroysOnBoundary(PrunedLivenessBoundary const &boundary);
464468

lib/SILOptimizer/Utils/CanonicalizeOSSALifetime.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,10 @@ void CanonicalizeOSSALifetime::findOriginalBoundary(
568568
/// with consumedAtExitBlocks, liveness should be extended to its original
569569
/// extent.
570570
/// [Extend liveness down to the boundary between green blocks and uncolored.]
571-
void CanonicalizeOSSALifetime::extendUnconsumedLiveness(
572-
PrunedLivenessBoundary const &boundary) {
571+
void CanonicalizeOSSALifetime::visitExtendedUnconsumedBoundary(
572+
ArrayRef<SILInstruction *> ends,
573+
llvm::function_ref<void(SILInstruction *, PrunedLiveness::LifetimeEnding)>
574+
visitor) {
573575
auto currentDef = getCurrentDef();
574576

575577
// First, collect the blocks that were _originally_ live. We can't use
@@ -617,7 +619,7 @@ void CanonicalizeOSSALifetime::extendUnconsumedLiveness(
617619
// consumes. These are just the instructions on the boundary which aren't
618620
// destroys.
619621
BasicBlockWorklist worklist(currentDef->getFunction());
620-
for (auto *instruction : boundary.lastUsers) {
622+
for (auto *instruction : ends) {
621623
if (destroys.contains(instruction))
622624
continue;
623625
if (liveness->isInterestingUser(instruction)
@@ -646,7 +648,7 @@ void CanonicalizeOSSALifetime::extendUnconsumedLiveness(
646648
// Add "the instruction(s) before the terminator" of the predecessor to
647649
// liveness.
648650
predecessor->getTerminator()->visitPriorInstructions([&](auto *inst) {
649-
liveness->extendToNonUse(inst);
651+
visitor(inst, PrunedLiveness::LifetimeEnding::NonUse());
650652
return true;
651653
});
652654
}
@@ -660,10 +662,18 @@ void CanonicalizeOSSALifetime::extendUnconsumedLiveness(
660662
// hoisting it would avoid a copy.
661663
if (consumedAtExitBlocks.contains(block))
662664
continue;
663-
liveness->updateForUse(destroy, /*lifetimeEnding*/ true);
665+
visitor(destroy, PrunedLiveness::LifetimeEnding::Ending());
664666
}
665667
}
666668

669+
void CanonicalizeOSSALifetime::extendUnconsumedLiveness(
670+
PrunedLivenessBoundary const &boundary) {
671+
visitExtendedUnconsumedBoundary(
672+
boundary.lastUsers, [&](auto *instruction, auto lifetimeEnding) {
673+
liveness->updateForUse(instruction, lifetimeEnding);
674+
});
675+
}
676+
667677
//===----------------------------------------------------------------------===//
668678
// MARK: Step 4. Extend the "original" boundary from step 2 up to destroys that
669679
// aren't separated from it by "interesting" instructions.

0 commit comments

Comments
 (0)