mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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.
This commit is contained in:
@@ -330,45 +330,40 @@ void SILPassManager::runOneIteration() {
|
|||||||
NumOptimizationIterations++;
|
NumOptimizationIterations++;
|
||||||
SmallVector<SILFunctionTransform*, 16> PendingFuncTransforms;
|
SmallVector<SILFunctionTransform*, 16> PendingFuncTransforms;
|
||||||
|
|
||||||
// For each transformation:
|
auto KeepTransforming = [&]() {
|
||||||
for (SILTransform *ST : Transformations) {
|
return Mod->getStage() == SILStage::Raw ||
|
||||||
// Bail out if we've hit the optimization pass limit.
|
NumPassesRun < SILNumOptPassesToRun;
|
||||||
if (Mod->getStage() == SILStage::Canonical
|
};
|
||||||
&& NumPassesRun >= SILNumOptPassesToRun)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Run module transformations on the module.
|
// Run the transforms by alternating between function transforms and
|
||||||
if (SILModuleTransform *SMT = llvm::dyn_cast<SILModuleTransform>(ST)) {
|
// module transforms. We'll queue up all the function transforms
|
||||||
// Run all function passes that we've seen since the last module pass.
|
// that we see in a row and then run the entire group of transforms
|
||||||
// Stop stop this optimization phase if one of the passes requested to
|
// on each function in turn. Then we move on to running the next set
|
||||||
// stop.
|
// of consequtive module transforms.
|
||||||
bool NeedToStop = runFunctionPasses(PendingFuncTransforms);
|
auto It = Transformations.begin();
|
||||||
if (NeedToStop)
|
auto End = Transformations.end();
|
||||||
return;
|
|
||||||
|
|
||||||
PendingFuncTransforms.clear();
|
while (It != End && KeepTransforming()) {
|
||||||
|
assert((isa<SILFunctionTransform>(*It) || isa<SILModuleTransform>(*It)) &&
|
||||||
|
"Unexpected pass kind!");
|
||||||
|
|
||||||
runModulePass(SMT);
|
while (It != End && isa<SILFunctionTransform>(*It) && KeepTransforming()) {
|
||||||
|
PendingFuncTransforms.push_back(cast<SILFunctionTransform>(*It));
|
||||||
|
|
||||||
|
++It;
|
||||||
++NumPassesRun;
|
++NumPassesRun;
|
||||||
if (Mod->getStage() == SILStage::Canonical
|
|
||||||
&& NumPassesRun >= SILNumOptPassesToRun) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run function transformation on all functions.
|
|
||||||
if (SILFunctionTransform *SFT = llvm::dyn_cast<SILFunctionTransform>(ST)) {
|
|
||||||
PendingFuncTransforms.push_back(SFT);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
llvm_unreachable("Unknown pass kind.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
runFunctionPasses(PendingFuncTransforms);
|
runFunctionPasses(PendingFuncTransforms);
|
||||||
|
PendingFuncTransforms.clear();
|
||||||
|
|
||||||
|
while (It != End && isa<SILModuleTransform>(*It) && KeepTransforming()) {
|
||||||
|
runModulePass(cast<SILModuleTransform>(*It));
|
||||||
|
|
||||||
|
++It;
|
||||||
|
++NumPassesRun;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SILPassManager::run() {
|
void SILPassManager::run() {
|
||||||
|
|||||||
Reference in New Issue
Block a user