@@ -161,6 +161,57 @@ class SILCombineCanonicalize final : CanonicalizeInstruction {
161161 }
162162};
163163
164+ SILCombiner::SILCombiner (SILFunctionTransform *trans,
165+ bool removeCondFails, bool enableCopyPropagation) :
166+ parentTransform(trans),
167+ AA(trans->getPassManager ()->getAnalysis<AliasAnalysis>(trans->getFunction ())),
168+ DA(trans->getPassManager ()->getAnalysis<DominanceAnalysis>()),
169+ PCA(trans->getPassManager ()->getAnalysis<ProtocolConformanceAnalysis>()),
170+ CHA(trans->getPassManager ()->getAnalysis<ClassHierarchyAnalysis>()),
171+ NLABA(trans->getPassManager ()->getAnalysis<NonLocalAccessBlockAnalysis>()),
172+ Worklist(" SC" ),
173+ deleter(InstModCallbacks()
174+ .onDelete([&](SILInstruction *instToDelete) {
175+ // We allow for users in SILCombine to perform 2 stage
176+ // deletion, so we need to split the erasing of
177+ // instructions from adding operands to the worklist.
178+ eraseInstFromFunction (*instToDelete,
179+ false /* don't add operands */ );
180+ })
181+ .onNotifyWillBeDeleted(
182+ [&](SILInstruction *instThatWillBeDeleted) {
183+ Worklist.addOperandsToWorklist (
184+ *instThatWillBeDeleted);
185+ })
186+ .onCreateNewInst([&](SILInstruction *newlyCreatedInst) {
187+ Worklist.add (newlyCreatedInst);
188+ })
189+ .onSetUseValue([&](Operand *use, SILValue newValue) {
190+ use->set (newValue);
191+ Worklist.add (use->getUser ());
192+ })),
193+ deadEndBlocks(trans->getFunction ()), MadeChange(false ),
194+ RemoveCondFails(removeCondFails),
195+ enableCopyPropagation(enableCopyPropagation), Iteration(0 ),
196+ Builder(*trans->getFunction (), &TrackingList),
197+ FuncBuilder(*trans),
198+ CastOpt(
199+ FuncBuilder, nullptr /* SILBuilderContext*/ ,
200+ /* ReplaceValueUsesAction */
201+ [&](SILValue Original, SILValue Replacement) {
202+ replaceValueUsesWith (Original, Replacement);
203+ },
204+ /* ReplaceInstUsesAction */
205+ [&](SingleValueInstruction *I, ValueBase *V) {
206+ replaceInstUsesWith (*I, V);
207+ },
208+ /* EraseAction */
209+ [&](SILInstruction *I) { eraseInstFromFunction (*I); }),
210+ deBlocks(trans->getFunction ()),
211+ ownershipFixupContext(getInstModCallbacks(), deBlocks),
212+ swiftPassInvocation(trans->getPassManager (),
213+ trans->getFunction(), this) {}
214+
164215bool SILCombiner::trySinkOwnedForwardingInst (SingleValueInstruction *svi) {
165216 if (auto *consumingUse = svi->getSingleConsumingUse ()) {
166217 auto *consumingUser = consumingUse->getUser ();
@@ -455,7 +506,7 @@ bool SILCombiner::runOnFunction(SILFunction &F) {
455506 StackNesting::fixNesting (&F);
456507 }
457508
458- // Cleanup the builder and return whether or not we made any changes.
509+ assert (TrackingList. empty () && " TrackingList should be fully processed " );
459510 return Changed;
460511}
461512
@@ -532,33 +583,18 @@ namespace {
532583
533584class SILCombine : public SILFunctionTransform {
534585
535- llvm::SmallVector<SILInstruction *, 64 > TrackingList;
536-
537586 // / The entry point to the transformation.
538587 void run () override {
539- auto *AA = PM->getAnalysis <AliasAnalysis>(getFunction ());
540- auto *DA = PM->getAnalysis <DominanceAnalysis>();
541- auto *PCA = PM->getAnalysis <ProtocolConformanceAnalysis>();
542- auto *CHA = PM->getAnalysis <ClassHierarchyAnalysis>();
543- auto *NLABA = PM->getAnalysis <NonLocalAccessBlockAnalysis>();
544-
545588 bool enableCopyPropagation =
546589 getOptions ().CopyPropagation == CopyPropagationOption::On;
547590 if (getOptions ().EnableOSSAModules ) {
548591 enableCopyPropagation =
549592 getOptions ().CopyPropagation != CopyPropagationOption::Off;
550593 }
551594
552- SILOptFunctionBuilder FuncBuilder (*this );
553- // Create a SILBuilder with a tracking list for newly added
554- // instructions, which we will periodically move to our worklist.
555- SILBuilder B (*getFunction (), &TrackingList);
556- SILCombiner Combiner (this , FuncBuilder, B, AA, DA, PCA, CHA, NLABA,
557- getOptions ().RemoveRuntimeAsserts ,
595+ SILCombiner Combiner (this , getOptions ().RemoveRuntimeAsserts ,
558596 enableCopyPropagation);
559597 bool Changed = Combiner.runOnFunction (*getFunction ());
560- assert (TrackingList.empty () &&
561- " TrackingList should be fully processed by SILCombiner" );
562598
563599 if (Changed) {
564600 // Invalidate everything.
0 commit comments