@@ -443,38 +443,26 @@ class CopyPropagation : public SILFunctionTransform {
443
443
// / The entry point to this function transformation.
444
444
void run () override ;
445
445
446
+ void propagateCopies (CanonicalDefWorklist &defWorklist, bool &changed,
447
+ NonLocalAccessBlockAnalysis *accessBlockAnalysis,
448
+ InstructionDeleter &deleter);
449
+
446
450
void verifyOwnership ();
447
451
};
448
452
449
453
} // end anonymous namespace
450
454
451
- // / Top-level pass driver.
452
- void CopyPropagation::run () {
455
+ void CopyPropagation::propagateCopies (
456
+ CanonicalDefWorklist &defWorklist, bool &changed,
457
+ NonLocalAccessBlockAnalysis *accessBlockAnalysis,
458
+ InstructionDeleter &deleter) {
453
459
auto *f = getFunction ();
454
460
auto *postOrderAnalysis = getAnalysis<PostOrderAnalysis>();
455
- auto *accessBlockAnalysis = getAnalysis<NonLocalAccessBlockAnalysis>();
456
461
auto *deadEndBlocksAnalysis = getAnalysis<DeadEndBlocksAnalysis>();
457
462
auto *dominanceAnalysis = getAnalysis<DominanceAnalysis>();
458
463
auto *calleeAnalysis = getAnalysis<BasicCalleeAnalysis>();
459
464
DominanceInfo *domTree = dominanceAnalysis->get (f);
460
465
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
-
478
466
StackList<BeginBorrowInst *> beginBorrowsToShrink (f);
479
467
StackList<MoveValueInst *> moveValues (f);
480
468
@@ -630,6 +618,32 @@ void CopyPropagation::run() {
630
618
if (auto *inst = def->getDefiningInstruction ())
631
619
deleter.trackIfDead (inst);
632
620
}
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
+
633
647
// Recursively cleanup dead defs after removing uses.
634
648
deleter.cleanupDeadInstructions ();
635
649
0 commit comments