@@ -330,45 +330,40 @@ void SILPassManager::runOneIteration() {
330
330
NumOptimizationIterations++;
331
331
SmallVector<SILFunctionTransform*, 16 > PendingFuncTransforms;
332
332
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);
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!" );
352
349
350
+ while (It != End && isa<SILFunctionTransform>(*It) && KeepTransforming ()) {
351
+ PendingFuncTransforms.push_back (cast<SILFunctionTransform>(*It));
352
+
353
+ ++It;
353
354
++NumPassesRun;
354
- if (Mod->getStage () == SILStage::Canonical
355
- && NumPassesRun >= SILNumOptPassesToRun) {
356
- return ;
357
- }
358
-
359
- continue ;
360
355
}
361
356
362
- // Run function transformation on all functions.
363
- if (SILFunctionTransform *SFT = llvm::dyn_cast<SILFunctionTransform>(ST)) {
364
- PendingFuncTransforms.push_back (SFT);
365
- continue ;
366
- }
357
+ runFunctionPasses (PendingFuncTransforms);
358
+ PendingFuncTransforms.clear ();
367
359
368
- llvm_unreachable ( " Unknown pass kind. " );
369
- }
360
+ while (It != End && isa<SILModuleTransform>(*It) && KeepTransforming ()) {
361
+ runModulePass (cast<SILModuleTransform>(*It));
370
362
371
- runFunctionPasses (PendingFuncTransforms);
363
+ ++It;
364
+ ++NumPassesRun;
365
+ }
366
+ }
372
367
}
373
368
374
369
void SILPassManager::run () {
0 commit comments