@@ -443,38 +443,26 @@ class CopyPropagation : public SILFunctionTransform {
443443 // / The entry point to this function transformation.
444444 void run () override ;
445445
446+ void propagateCopies (CanonicalDefWorklist &defWorklist, bool &changed,
447+ NonLocalAccessBlockAnalysis *accessBlockAnalysis,
448+ InstructionDeleter &deleter);
449+
446450 void verifyOwnership ();
447451};
448452
449453} // end anonymous namespace
450454
451- // / Top-level pass driver.
452- void CopyPropagation::run () {
455+ void CopyPropagation::propagateCopies (
456+ CanonicalDefWorklist &defWorklist, bool &changed,
457+ NonLocalAccessBlockAnalysis *accessBlockAnalysis,
458+ InstructionDeleter &deleter) {
453459 auto *f = getFunction ();
454460 auto *postOrderAnalysis = getAnalysis<PostOrderAnalysis>();
455- auto *accessBlockAnalysis = getAnalysis<NonLocalAccessBlockAnalysis>();
456461 auto *deadEndBlocksAnalysis = getAnalysis<DeadEndBlocksAnalysis>();
457462 auto *dominanceAnalysis = getAnalysis<DominanceAnalysis>();
458463 auto *calleeAnalysis = getAnalysis<BasicCalleeAnalysis>();
459464 DominanceInfo *domTree = dominanceAnalysis->get (f);
460465
461- // Label for unit testing with debug output.
462- LLVM_DEBUG (llvm::dbgs () << " *** CopyPropagation: " << f->getName () << " \n " );
463-
464- // This algorithm fundamentally assumes ownership.
465- if (!f->hasOwnership ())
466- return ;
467-
468- CanonicalDefWorklist defWorklist (canonicalizeBorrows);
469- auto callbacks =
470- InstModCallbacks ().onDelete ([&](SILInstruction *instToDelete) {
471- defWorklist.erase (instToDelete);
472- instToDelete->eraseFromParent ();
473- });
474-
475- InstructionDeleter deleter (std::move (callbacks));
476- bool changed = false ;
477-
478466 StackList<BeginBorrowInst *> beginBorrowsToShrink (f);
479467 StackList<MoveValueInst *> moveValues (f);
480468
@@ -630,6 +618,32 @@ void CopyPropagation::run() {
630618 if (auto *inst = def->getDefiningInstruction ())
631619 deleter.trackIfDead (inst);
632620 }
621+ }
622+
623+ // / Top-level pass driver.
624+ void CopyPropagation::run () {
625+ auto *f = getFunction ();
626+ // This algorithm fundamentally assumes ownership.
627+ if (!f->hasOwnership ())
628+ return ;
629+
630+ // Label for unit testing with debug output.
631+ LLVM_DEBUG (llvm::dbgs () << " *** CopyPropagation: " << f->getName () << " \n " );
632+
633+ auto *accessBlockAnalysis = getAnalysis<NonLocalAccessBlockAnalysis>();
634+
635+ CanonicalDefWorklist defWorklist (canonicalizeBorrows);
636+
637+ auto callbacks =
638+ InstModCallbacks ().onDelete ([&](SILInstruction *instToDelete) {
639+ defWorklist.erase (instToDelete);
640+ instToDelete->eraseFromParent ();
641+ });
642+ InstructionDeleter deleter (std::move (callbacks));
643+
644+ bool changed = false ;
645+ propagateCopies (defWorklist, changed, accessBlockAnalysis, deleter);
646+
633647 // Recursively cleanup dead defs after removing uses.
634648 deleter.cleanupDeadInstructions ();
635649
0 commit comments