@@ -161,6 +161,57 @@ class SILCombineCanonicalize final : CanonicalizeInstruction {
161
161
}
162
162
};
163
163
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
+
164
215
bool SILCombiner::trySinkOwnedForwardingInst (SingleValueInstruction *svi) {
165
216
if (auto *consumingUse = svi->getSingleConsumingUse ()) {
166
217
auto *consumingUser = consumingUse->getUser ();
@@ -455,7 +506,7 @@ bool SILCombiner::runOnFunction(SILFunction &F) {
455
506
StackNesting::fixNesting (&F);
456
507
}
457
508
458
- // Cleanup the builder and return whether or not we made any changes.
509
+ assert (TrackingList. empty () && " TrackingList should be fully processed " );
459
510
return Changed;
460
511
}
461
512
@@ -532,33 +583,18 @@ namespace {
532
583
533
584
class SILCombine : public SILFunctionTransform {
534
585
535
- llvm::SmallVector<SILInstruction *, 64 > TrackingList;
536
-
537
586
// / The entry point to the transformation.
538
587
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
-
545
588
bool enableCopyPropagation =
546
589
getOptions ().CopyPropagation == CopyPropagationOption::On;
547
590
if (getOptions ().EnableOSSAModules ) {
548
591
enableCopyPropagation =
549
592
getOptions ().CopyPropagation != CopyPropagationOption::Off;
550
593
}
551
594
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 ,
558
596
enableCopyPropagation);
559
597
bool Changed = Combiner.runOnFunction (*getFunction ());
560
- assert (TrackingList.empty () &&
561
- " TrackingList should be fully processed by SILCombiner" );
562
598
563
599
if (Changed) {
564
600
// Invalidate everything.
0 commit comments