@@ -330,40 +330,45 @@ void SILPassManager::runOneIteration() {
330
330
NumOptimizationIterations++;
331
331
SmallVector<SILFunctionTransform*, 16 > PendingFuncTransforms;
332
332
333
- auto KeepTransforming = [&]() {
334
- return Mod->getStage () == SILStage::Raw ||
335
- NumPassesRun < SILNumOptPassesToRun;
336
- };
337
-
338
- // Run the transforms by alternating between function transforms and
339
- // module transforms. We'll queue up all the function transforms
340
- // that we see in a row and then run the entire group of transforms
341
- // on each function in turn. Then we move on to running the next set
342
- // of consequtive module transforms.
343
- auto It = Transformations.begin ();
344
- auto End = Transformations.end ();
345
-
346
- while (It != End && KeepTransforming ()) {
347
- assert ((isa<SILFunctionTransform>(*It) || isa<SILModuleTransform>(*It)) &&
348
- " Unexpected pass kind!" );
333
+ // For each transformation:
334
+ for (SILTransform *ST : Transformations) {
335
+ // Bail out if we've hit the optimization pass limit.
336
+ if (Mod->getStage () == SILStage::Canonical
337
+ && NumPassesRun >= SILNumOptPassesToRun)
338
+ return ;
339
+
340
+ // Run module transformations on the module.
341
+ if (SILModuleTransform *SMT = llvm::dyn_cast<SILModuleTransform>(ST)) {
342
+ // Run all function passes that we've seen since the last module pass.
343
+ // Stop stop this optimization phase if one of the passes requested to
344
+ // stop.
345
+ bool NeedToStop = runFunctionPasses (PendingFuncTransforms);
346
+ if (NeedToStop)
347
+ return ;
348
+
349
+ PendingFuncTransforms.clear ();
350
+
351
+ runModulePass (SMT);
349
352
350
- while (It != End && isa<SILFunctionTransform>(*It) && KeepTransforming ()) {
351
- PendingFuncTransforms.push_back (cast<SILFunctionTransform>(*It));
352
-
353
- ++It;
354
353
++NumPassesRun;
354
+ if (Mod->getStage () == SILStage::Canonical
355
+ && NumPassesRun >= SILNumOptPassesToRun) {
356
+ return ;
357
+ }
358
+
359
+ continue ;
355
360
}
356
361
357
- runFunctionPasses (PendingFuncTransforms);
358
- PendingFuncTransforms.clear ();
359
-
360
- while (It != End && isa<SILModuleTransform>(*It) && KeepTransforming ()) {
361
- runModulePass (cast<SILModuleTransform>(*It));
362
-
363
- ++It;
364
- ++NumPassesRun;
362
+ // Run function transformation on all functions.
363
+ if (SILFunctionTransform *SFT = llvm::dyn_cast<SILFunctionTransform>(ST)) {
364
+ PendingFuncTransforms.push_back (SFT);
365
+ continue ;
365
366
}
367
+
368
+ llvm_unreachable (" Unknown pass kind." );
366
369
}
370
+
371
+ runFunctionPasses (PendingFuncTransforms);
367
372
}
368
373
369
374
void SILPassManager::run () {
0 commit comments