Skip to content

Commit 9d4d3c8

Browse files
committed
Simplify the pass manager execution logic.
Make it a bit more clear that we're alternating between collecting (and then running) function passes, and running module passes. Removes some duplication that was present.
1 parent bc10b7b commit 9d4d3c8

File tree

1 file changed

+28
-33
lines changed

1 file changed

+28
-33
lines changed

lib/SILOptimizer/PassManager/PassManager.cpp

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -330,45 +330,40 @@ void SILPassManager::runOneIteration() {
330330
NumOptimizationIterations++;
331331
SmallVector<SILFunctionTransform*, 16> PendingFuncTransforms;
332332

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!");
352349

350+
while (It != End && isa<SILFunctionTransform>(*It) && KeepTransforming()) {
351+
PendingFuncTransforms.push_back(cast<SILFunctionTransform>(*It));
352+
353+
++It;
353354
++NumPassesRun;
354-
if (Mod->getStage() == SILStage::Canonical
355-
&& NumPassesRun >= SILNumOptPassesToRun) {
356-
return;
357-
}
358-
359-
continue;
360355
}
361356

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();
367359

368-
llvm_unreachable("Unknown pass kind.");
369-
}
360+
while (It != End && isa<SILModuleTransform>(*It) && KeepTransforming()) {
361+
runModulePass(cast<SILModuleTransform>(*It));
370362

371-
runFunctionPasses(PendingFuncTransforms);
363+
++It;
364+
++NumPassesRun;
365+
}
366+
}
372367
}
373368

374369
void SILPassManager::run() {

0 commit comments

Comments
 (0)