Skip to content

Commit 58a2501

Browse files
committed
OwnershipLifetimeExtender::createPlusOneCopy comments
1 parent 5ac273d commit 58a2501

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

lib/SILOptimizer/Utils/OwnershipOptUtils.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,14 @@ struct OwnershipLifetimeExtender {
492492

493493
} // end anonymous namespace
494494

495-
// Lifetime extend newValue over owned oldValue assuming that our copy will have
496-
// its lifetime ended by oldValue's lifetime ending uses after RAUWing by our
497-
// caller.
495+
/// Lifetime extend \p value over \p consumingPoint, assuming that \p
496+
/// consumingPoint will consume \p value after the client performs replacement
497+
/// (this implicit destruction on the caller-side makes it a "plus-one"
498+
/// copy). Destroy \p copy on all paths that don't reach \p consumingPoint.
499+
///
500+
/// Precondition: \p value is owned
501+
///
502+
/// Precondition: \p consumingPoint is dominated by \p value
498503
CopyValueInst *
499504
OwnershipLifetimeExtender::createPlusOneCopy(SILValue value,
500505
SILInstruction *consumingPoint) {
@@ -507,28 +512,23 @@ OwnershipLifetimeExtender::createPlusOneCopy(SILValue value,
507512

508513
auto *result = copy;
509514
findJointPostDominatingSet(
510-
copyPoint->getParent(), consumingPoint->getParent(),
515+
copy->getParent(), consumingPoint->getParent(),
511516
// inputBlocksFoundDuringWalk.
512517
[&](SILBasicBlock *loopBlock) {
513-
// This must be consumingPoint->getParent() since we only have one
514-
// consuming use. In this case, we know that this is the consuming
515-
// point where we will need a control equivalent copy_value (and that
516-
// destroy_value will be put for the out of loop value as appropriate.
518+
// Since copy dominates consumingPoint, it must be outside the
519+
// loop. Otherwise backward traversal would have stopped at copyPoint.
520+
//
521+
// Create an extra copy when the consumingPoint is inside a loop and the
522+
// original copy is outside the loop. The new copy will be consumed
523+
// within the loop in the same block as the consume. The original copy
524+
// will be destroyed on all paths exiting the loop.
517525
assert(loopBlock == consumingPoint->getParent());
518526
auto front = loopBlock->begin();
519527
SILBuilderWithScope newBuilder(front);
520-
521-
// Create an extra copy when the consuming point is inside a
522-
// loop and both copyPoint and the destroy points are outside the
523-
// loop. This copy will be consumed in the same block. The original
524-
// value will be destroyed on all paths exiting the loop.
525-
//
526-
// Since copyPoint dominates consumingPoint, it must be outside the
527-
// loop. Otherwise backward traversal would have stopped at copyPoint.
528528
result = newBuilder.createCopyValue(front->getLoc(), copy);
529529
callbacks.createdNewInst(result);
530530
},
531-
// Input blocks in joint post dom set. We don't care about thse.
531+
// Leaky blocks that never reach consumingPoint.
532532
[&](SILBasicBlock *postDomBlock) {
533533
auto front = postDomBlock->begin();
534534
SILBuilderWithScope newBuilder(front);

0 commit comments

Comments
 (0)