Skip to content

Commit dc9baba

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 aa3cbe0 commit dc9baba

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
@@ -573,8 +573,10 @@ void CanonicalizeOSSALifetime::findOriginalBoundary(
573573
/// with consumedAtExitBlocks, liveness should be extended to its original
574574
/// extent.
575575
/// [Extend liveness down to the boundary between green blocks and uncolored.]
576-
void CanonicalizeOSSALifetime::extendUnconsumedLiveness(
577-
PrunedLivenessBoundary const &boundary) {
576+
void CanonicalizeOSSALifetime::visitExtendedUnconsumedBoundary(
577+
ArrayRef<SILInstruction *> ends,
578+
llvm::function_ref<void(SILInstruction *, PrunedLiveness::LifetimeEnding)>
579+
visitor) {
578580
auto currentDef = getCurrentDef();
579581

580582
// First, collect the blocks that were _originally_ live. We can't use
@@ -622,7 +624,7 @@ void CanonicalizeOSSALifetime::extendUnconsumedLiveness(
622624
// consumes. These are just the instructions on the boundary which aren't
623625
// destroys.
624626
BasicBlockWorklist worklist(currentDef->getFunction());
625-
for (auto *instruction : boundary.lastUsers) {
627+
for (auto *instruction : ends) {
626628
if (destroys.contains(instruction))
627629
continue;
628630
if (liveness->isInterestingUser(instruction)
@@ -651,7 +653,7 @@ void CanonicalizeOSSALifetime::extendUnconsumedLiveness(
651653
// Add "the instruction(s) before the terminator" of the predecessor to
652654
// liveness.
653655
predecessor->getTerminator()->visitPriorInstructions([&](auto *inst) {
654-
liveness->extendToNonUse(inst);
656+
visitor(inst, PrunedLiveness::LifetimeEnding::NonUse());
655657
return true;
656658
});
657659
}
@@ -665,10 +667,18 @@ void CanonicalizeOSSALifetime::extendUnconsumedLiveness(
665667
// hoisting it would avoid a copy.
666668
if (consumedAtExitBlocks.contains(block))
667669
continue;
668-
liveness->updateForUse(destroy, /*lifetimeEnding*/ true);
670+
visitor(destroy, PrunedLiveness::LifetimeEnding::Ending());
669671
}
670672
}
671673

674+
void CanonicalizeOSSALifetime::extendUnconsumedLiveness(
675+
PrunedLivenessBoundary const &boundary) {
676+
visitExtendedUnconsumedBoundary(
677+
boundary.lastUsers, [&](auto *instruction, auto lifetimeEnding) {
678+
liveness->updateForUse(instruction, lifetimeEnding);
679+
});
680+
}
681+
672682
//===----------------------------------------------------------------------===//
673683
// MARK: Step 4. Extend the "original" boundary from step 2 up to destroys that
674684
// aren't separated from it by "interesting" instructions.

0 commit comments

Comments
 (0)