Skip to content

Commit c1bbfc1

Browse files
committed
[CanonicalizeOSSALifetime] Separated steps.
Rather than having finding the boundary be a single combined step, separate finding the original boundary from extending that boundary. This enables inserting an optional step between those steps, namely to extend unconsumed liveness to its original extent at Onone.
1 parent 8cf65c6 commit c1bbfc1

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

include/swift/SILOptimizer/Utils/CanonicalizeOSSALifetime.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,10 @@ class CanonicalizeOSSALifetime final {
347347

348348
void extendLivenessThroughOverlappingAccess();
349349

350-
void findExtendedBoundary(PrunedLivenessBoundary &boundary);
350+
void findOriginalBoundary(PrunedLivenessBoundary &boundary);
351+
352+
void findExtendedBoundary(PrunedLivenessBoundary const &originalBoundary,
353+
PrunedLivenessBoundary &boundary);
351354

352355
void insertDestroysOnBoundary(PrunedLivenessBoundary const &boundary);
353356

lib/SILOptimizer/Utils/CanonicalizeOSSALifetime.cpp

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@
2020
/// 1. Compute "pruned" liveness of def and its copies, ignoring original
2121
/// destroys. Initializes `liveness`.
2222
///
23-
/// 2. Find the "extended" boundary of liveness by walking out from the boundary
23+
/// 2. Find the "original" boundary of liveness using
24+
/// PrunedLiveness::computeBoundary.
25+
///
26+
/// 3. Find the "extended" boundary of liveness by walking out from the boundary
2427
/// computed by PrunedLiveness out to destroys which aren't separated from
2528
/// the original destory by "interesting" instructions.
2629
///
27-
/// 3. Initializes `consumes` and inserts new destroy_value instructions.
30+
/// 4. Initializes `consumes` and inserts new destroy_value instructions.
2831
///
29-
/// 4. Rewrite `def`s original copies and destroys, inserting new copies where
32+
/// 5. Rewrite `def`s original copies and destroys, inserting new copies where
3033
/// needed. Deletes original copies and destroys and inserts new copies.
3134
///
3235
/// See CanonicalizeOSSALifetime.h for examples.
@@ -410,8 +413,20 @@ void CanonicalizeOSSALifetime::extendLivenessThroughOverlappingAccess() {
410413
}
411414

412415
//===----------------------------------------------------------------------===//
413-
// MARK: Step 2. Find the destroy points of the current def based on the pruned
414-
// liveness computed in Step 1.
416+
// MARK: Step 2. Find the "original" (unextended) boundary determined by the
417+
// liveness built up in step 1.
418+
//===----------------------------------------------------------------------===//
419+
420+
void CanonicalizeOSSALifetime::findOriginalBoundary(
421+
PrunedLivenessBoundary &boundary) {
422+
assert(boundary.lastUsers.size() == 0 && boundary.boundaryEdges.size() == 0 &&
423+
boundary.deadDefs.size() == 0);
424+
liveness.computeBoundary(boundary, consumingBlocks.getArrayRef());
425+
}
426+
427+
//===----------------------------------------------------------------------===//
428+
// MARK: Step 3. Extend the "original" boundary from step 2 up to destroys that
429+
// aren't separated from it by "interesting" instructions.
415430
//===----------------------------------------------------------------------===//
416431

417432
namespace {
@@ -614,17 +629,17 @@ class ExtendBoundaryToDestroys final {
614629
} // anonymous namespace
615630

616631
void CanonicalizeOSSALifetime::findExtendedBoundary(
632+
PrunedLivenessBoundary const &originalBoundary,
617633
PrunedLivenessBoundary &boundary) {
618-
PrunedLivenessBoundary originalBoundary;
619-
liveness.computeBoundary(originalBoundary, consumingBlocks.getArrayRef());
620-
634+
assert(boundary.lastUsers.size() == 0 && boundary.boundaryEdges.size() == 0 &&
635+
boundary.deadDefs.size() == 0);
621636
ExtendBoundaryToDestroys extender(liveness, originalBoundary,
622637
getCurrentDef());
623638
extender.extend(boundary);
624639
}
625640

626641
//===----------------------------------------------------------------------===//
627-
// MARK: Step 3. Insert destroys onto the boundary found in step 2 where needed.
642+
// MARK: Step 4. Insert destroys onto the boundary found in step 3 where needed.
628643
//===----------------------------------------------------------------------===//
629644

630645
/// Create a new destroy_value instruction before the specified instruction and
@@ -714,7 +729,7 @@ void CanonicalizeOSSALifetime::insertDestroysOnBoundary(
714729
}
715730

716731
//===----------------------------------------------------------------------===//
717-
// MARK: Step 4. Rewrite copies and destroys
732+
// MARK: Step 5. Rewrite copies and destroys
718733
//===----------------------------------------------------------------------===//
719734

720735
/// The lifetime extends beyond given consuming use. Copy the value.
@@ -880,12 +895,15 @@ bool CanonicalizeOSSALifetime::canonicalizeValueLifetime(SILValue def) {
880895
return false;
881896
}
882897
extendLivenessThroughOverlappingAccess();
883-
// Step 2: compute boundary
898+
// Step 2: compute original boundary
899+
PrunedLivenessBoundary originalBoundary;
900+
findOriginalBoundary(originalBoundary);
901+
// Step 3: extend boundary to destroys
884902
PrunedLivenessBoundary boundary;
885-
findExtendedBoundary(boundary);
886-
// Step 3: insert destroys and record consumes
903+
findExtendedBoundary(originalBoundary, boundary);
904+
// Step 4: insert destroys and record consumes
887905
insertDestroysOnBoundary(boundary);
888-
// Step 4: rewrite copies and delete extra destroys
906+
// Step 5: rewrite copies and delete extra destroys
889907
rewriteCopies();
890908

891909
clearLiveness();

0 commit comments

Comments
 (0)