Skip to content

Commit 5954456

Browse files
committed
Revert "Simplify the pass manager execution logic."
This reverts commit 9d4d3c8. I forgot to finish up changes required to make -Xllvm -sil-opt-pass-count continue working the way it did, so I'll back that out until I have those changes as well.
1 parent 6e763b7 commit 5954456

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

lib/SILOptimizer/PassManager/PassManager.cpp

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

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);
349352

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

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;
365366
}
367+
368+
llvm_unreachable("Unknown pass kind.");
366369
}
370+
371+
runFunctionPasses(PendingFuncTransforms);
367372
}
368373

369374
void SILPassManager::run() {

0 commit comments

Comments
 (0)