@@ -114,6 +114,8 @@ namespace {
114
114
class MandatoryCombiner final
115
115
: public SILInstructionVisitor<MandatoryCombiner, SILInstruction *> {
116
116
117
+ bool compilingWithOptimization;
118
+
117
119
using Worklist = SmallSILInstructionWorklist<256 >;
118
120
119
121
// / The list of instructions remaining to visit, perhaps to combine.
@@ -135,9 +137,11 @@ class MandatoryCombiner final
135
137
DeadEndBlocks &deadEndBlocks;
136
138
137
139
public:
138
- MandatoryCombiner (SmallVectorImpl<SILInstruction *> &createdInstructions,
140
+ MandatoryCombiner (bool optimized,
141
+ SmallVectorImpl<SILInstruction *> &createdInstructions,
139
142
DeadEndBlocks &deadEndBlocks)
140
- : worklist(" MC" ), madeChange(false ), iteration(0 ),
143
+ : compilingWithOptimization(optimized), worklist(" MC" ), madeChange(false ),
144
+ iteration (0 ),
141
145
instModCallbacks(
142
146
[&](SILInstruction *instruction) {
143
147
worklist.erase (instruction);
@@ -210,8 +214,6 @@ void MandatoryCombiner::addReachableCodeToWorklist(SILFunction &function) {
210
214
blockAlreadyAddedToWorklist.insert (firstBlock);
211
215
}
212
216
213
- bool compilingWithOptimization = function.getEffectiveOptimizationMode () !=
214
- OptimizationMode::NoOptimization;
215
217
while (!blockWorklist.empty ()) {
216
218
auto *block = blockWorklist.pop_back_val ();
217
219
@@ -249,9 +251,6 @@ bool MandatoryCombiner::doOneIteration(SILFunction &function,
249
251
addReachableCodeToWorklist (function);
250
252
MandatoryCombineCanonicalize mcCanonicialize (worklist, deadEndBlocks);
251
253
252
- bool compilingWithOptimization = function.getEffectiveOptimizationMode () !=
253
- OptimizationMode::NoOptimization;
254
-
255
254
while (!worklist.isEmpty ()) {
256
255
auto *instruction = worklist.pop_back_val ();
257
256
if (instruction == nullptr ) {
@@ -383,9 +382,12 @@ SILInstruction *MandatoryCombiner::visitApplyInst(ApplyInst *instruction) {
383
382
namespace {
384
383
385
384
class MandatoryCombine final : public SILFunctionTransform {
386
-
385
+ bool optimized;
387
386
SmallVector<SILInstruction *, 64 > createdInstructions;
388
387
388
+ public:
389
+ MandatoryCombine (bool optimized) : optimized(optimized) {}
390
+
389
391
void run () override {
390
392
auto *function = getFunction ();
391
393
@@ -396,14 +398,15 @@ class MandatoryCombine final : public SILFunctionTransform {
396
398
}
397
399
398
400
DeadEndBlocks deadEndBlocks (function);
399
- MandatoryCombiner combiner (createdInstructions, deadEndBlocks);
401
+ MandatoryCombiner combiner (optimized, createdInstructions, deadEndBlocks);
400
402
bool madeChange = combiner.runOnFunction (*function);
401
403
402
404
if (madeChange) {
403
405
invalidateAnalysis (SILAnalysis::InvalidationKind::Instructions);
404
406
}
405
407
}
406
408
409
+ protected:
407
410
void handleDeleteNotification (SILNode *node) override {
408
411
// Remove instructions that were both created and deleted from the list of
409
412
// created instructions which will eventually be added to the worklist.
@@ -426,4 +429,10 @@ class MandatoryCombine final : public SILFunctionTransform {
426
429
427
430
} // end anonymous namespace
428
431
429
- SILTransform *swift::createMandatoryCombine () { return new MandatoryCombine (); }
432
+ SILTransform *swift::createMandatoryCombine () {
433
+ return new MandatoryCombine (/* optimized*/ false );
434
+ }
435
+
436
+ SILTransform *swift::createOptimizedMandatoryCombine () {
437
+ return new MandatoryCombine (/* optimized*/ true );
438
+ }
0 commit comments