@@ -502,6 +502,8 @@ void CopyPropagation::propagateCopies(
502502 // at least once and then until each stops making changes.
503503 while (true ) {
504504 SmallVector<CopyValueInst *, 4 > modifiedCopyValueInsts;
505+ if (!continueWithNextSubpassRun (bbi))
506+ return ;
505507 auto shrunk = shrinkBorrowScope (*bbi, deleter, calleeAnalysis,
506508 modifiedCopyValueInsts);
507509 for (auto *cvi : modifiedCopyValueInsts)
@@ -516,25 +518,35 @@ void CopyPropagation::propagateCopies(
516518 if (borrowee->getOwnershipKind () != OwnershipKind::Owned)
517519 break ;
518520
521+ if (!continueWithNextSubpassRun (borrowee))
522+ return ;
519523 auto canonicalized = canonicalizer.canonicalizeValueLifetime (borrowee);
520524 if (!canonicalized && !firstRun)
521525 break ;
522526
527+ if (!continueWithNextSubpassRun (bbi))
528+ return ;
523529 auto folded = foldDestroysOfCopiedLexicalBorrow (bbi, *domTree, deleter);
524530 if (!folded)
525531 break ;
526532 auto hoisted = canonicalizer.canonicalizeValueLifetime (folded);
527533 // Keep running even if the new move's destroys can't be hoisted.
528534 (void )hoisted;
535+ if (!continueWithNextSubpassRun (folded))
536+ return ;
529537 eliminateRedundantMove (folded, deleter, defWorklist);
530538 firstRun = false ;
531539 }
532540 }
533541 for (auto *mvi : moveValues) {
542+ if (!continueWithNextSubpassRun (mvi))
543+ return ;
534544 eliminateRedundantMove (mvi, deleter, defWorklist);
535545 }
536546 for (auto *argument : f->getArguments ()) {
537547 if (argument->getOwnershipKind () == OwnershipKind::Owned) {
548+ if (!continueWithNextSubpassRun (argument))
549+ return ;
538550 canonicalizer.canonicalizeValueLifetime (argument);
539551 }
540552 }
@@ -572,8 +584,12 @@ void CopyPropagation::propagateCopies(
572584 // they may be chained, and CanonicalizeBorrowScopes pushes them
573585 // top-down.
574586 for (auto result : ownedForward->getResults ()) {
587+ if (!continueWithNextSubpassRun (result))
588+ return ;
575589 canonicalizer.canonicalizeValueLifetime (result);
576590 }
591+ if (!continueWithNextSubpassRun (ownedForward))
592+ return ;
577593 if (sinkOwnedForward (ownedForward, postOrderAnalysis, domTree)) {
578594 changed = true ;
579595 // Sinking 'ownedForward' may create an opportunity to sink its
@@ -595,6 +611,8 @@ void CopyPropagation::propagateCopies(
595611 BorrowedValue borrow (defWorklist.borrowedValues .pop_back_val ());
596612 assert (canonicalizeBorrows || !borrow.isLocalScope ());
597613
614+ if (!continueWithNextSubpassRun (borrow.value ))
615+ return ;
598616 borrowCanonicalizer.canonicalizeBorrowScope (borrow);
599617 for (CopyValueInst *copy : borrowCanonicalizer.getUpdatedCopies ()) {
600618 defWorklist.updateForCopy (copy);
@@ -611,6 +629,8 @@ void CopyPropagation::propagateCopies(
611629 // Canonicalize all owned defs.
612630 while (!defWorklist.ownedValues .empty ()) {
613631 SILValue def = defWorklist.ownedValues .pop_back_val ();
632+ if (!continueWithNextSubpassRun (def))
633+ return ;
614634 auto canonicalized = canonicalizer.canonicalizeValueLifetime (def);
615635 if (!canonicalized)
616636 continue ;
0 commit comments