|
20 | 20 | /// 1. Compute "pruned" liveness of def and its copies, ignoring original
|
21 | 21 | /// destroys. Initializes `liveness`.
|
22 | 22 | ///
|
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 |
24 | 27 | /// computed by PrunedLiveness out to destroys which aren't separated from
|
25 | 28 | /// the original destory by "interesting" instructions.
|
26 | 29 | ///
|
27 |
| -/// 3. Initializes `consumes` and inserts new destroy_value instructions. |
| 30 | +/// 4. Initializes `consumes` and inserts new destroy_value instructions. |
28 | 31 | ///
|
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 |
30 | 33 | /// needed. Deletes original copies and destroys and inserts new copies.
|
31 | 34 | ///
|
32 | 35 | /// See CanonicalizeOSSALifetime.h for examples.
|
@@ -410,8 +413,20 @@ void CanonicalizeOSSALifetime::extendLivenessThroughOverlappingAccess() {
|
410 | 413 | }
|
411 | 414 |
|
412 | 415 | //===----------------------------------------------------------------------===//
|
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. |
415 | 430 | //===----------------------------------------------------------------------===//
|
416 | 431 |
|
417 | 432 | namespace {
|
@@ -614,17 +629,17 @@ class ExtendBoundaryToDestroys final {
|
614 | 629 | } // anonymous namespace
|
615 | 630 |
|
616 | 631 | void CanonicalizeOSSALifetime::findExtendedBoundary(
|
| 632 | + PrunedLivenessBoundary const &originalBoundary, |
617 | 633 | 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); |
621 | 636 | ExtendBoundaryToDestroys extender(liveness, originalBoundary,
|
622 | 637 | getCurrentDef());
|
623 | 638 | extender.extend(boundary);
|
624 | 639 | }
|
625 | 640 |
|
626 | 641 | //===----------------------------------------------------------------------===//
|
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. |
628 | 643 | //===----------------------------------------------------------------------===//
|
629 | 644 |
|
630 | 645 | /// Create a new destroy_value instruction before the specified instruction and
|
@@ -714,7 +729,7 @@ void CanonicalizeOSSALifetime::insertDestroysOnBoundary(
|
714 | 729 | }
|
715 | 730 |
|
716 | 731 | //===----------------------------------------------------------------------===//
|
717 |
| -// MARK: Step 4. Rewrite copies and destroys |
| 732 | +// MARK: Step 5. Rewrite copies and destroys |
718 | 733 | //===----------------------------------------------------------------------===//
|
719 | 734 |
|
720 | 735 | /// The lifetime extends beyond given consuming use. Copy the value.
|
@@ -880,12 +895,15 @@ bool CanonicalizeOSSALifetime::canonicalizeValueLifetime(SILValue def) {
|
880 | 895 | return false;
|
881 | 896 | }
|
882 | 897 | 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 |
884 | 902 | 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 |
887 | 905 | insertDestroysOnBoundary(boundary);
|
888 |
| - // Step 4: rewrite copies and delete extra destroys |
| 906 | + // Step 5: rewrite copies and delete extra destroys |
889 | 907 | rewriteCopies();
|
890 | 908 |
|
891 | 909 | clearLiveness();
|
|
0 commit comments