Skip to content

Commit a8fbc47

Browse files
committed
Minor pass manager refactoring.
Extract the code related to running a module pass into a separate function.
1 parent abea2ab commit a8fbc47

File tree

2 files changed

+57
-46
lines changed

2 files changed

+57
-46
lines changed

include/swift/SILOptimizer/PassManager/PassManager.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace swift {
2626
class SILFunction;
2727
class SILFunctionTransform;
2828
class SILModule;
29+
class SILModuleTransform;
2930
class SILOptions;
3031
class SILTransform;
3132

@@ -156,6 +157,10 @@ class SILPassManager {
156157

157158
typedef llvm::ArrayRef<SILFunctionTransform *> PassList;
158159
private:
160+
/// Run the SIL module transform \p SMT over all the functions in
161+
/// the module.
162+
void runModulePass(SILModuleTransform *SMT);
163+
159164
/// Run the passes in \p FuncTransforms. Return true
160165
/// if the pass manager requested to stop the execution
161166
/// of the optimization cycle (this is a debug feature).

lib/SILOptimizer/PassManager/PassManager.cpp

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,57 @@ bool SILPassManager::runFunctionPasses(PassList FuncTransforms) {
257257
return false;
258258
}
259259

260+
void SILPassManager::runModulePass(SILModuleTransform *SMT) {
261+
if (isDisabled(SMT))
262+
return;
263+
264+
const SILOptions &Options = getOptions();
265+
266+
PrettyStackTraceSILModuleTransform X(SMT);
267+
268+
SMT->injectPassManager(this);
269+
SMT->injectModule(Mod);
270+
271+
currentPassHasInvalidated = false;
272+
273+
if (SILPrintPassName)
274+
llvm::dbgs() << "#" << NumPassesRun << " Stage: " << StageName
275+
<< " Pass: " << SMT->getName() << " (module pass)\n";
276+
277+
if (doPrintBefore(SMT, nullptr)) {
278+
llvm::dbgs() << "*** SIL module before " << StageName << " "
279+
<< SMT->getName() << " (" << NumOptimizationIterations
280+
<< ") ***\n";
281+
printModule(Mod, Options.EmitVerboseSIL);
282+
}
283+
284+
llvm::sys::TimeValue StartTime = llvm::sys::TimeValue::now();
285+
Mod->registerDeleteNotificationHandler(SMT);
286+
SMT->run();
287+
Mod->removeDeleteNotificationHandler(SMT);
288+
289+
if (SILPrintPassTime) {
290+
auto Delta = llvm::sys::TimeValue::now().nanoseconds() -
291+
StartTime.nanoseconds();
292+
llvm::dbgs() << Delta << " (" << SMT->getName() << ",Module)\n";
293+
}
294+
295+
// If this pass invalidated anything, print and verify.
296+
if (doPrintAfter(SMT, nullptr,
297+
currentPassHasInvalidated && SILPrintAll)) {
298+
llvm::dbgs() << "*** SIL module after " << StageName << " "
299+
<< SMT->getName() << " (" << NumOptimizationIterations
300+
<< ") ***\n";
301+
printModule(Mod, Options.EmitVerboseSIL);
302+
}
303+
304+
if (Options.VerifyAll &&
305+
(currentPassHasInvalidated || !SILVerifyWithoutInvalidation)) {
306+
Mod->verify();
307+
verifyAnalyses();
308+
}
309+
}
310+
260311
void SILPassManager::runOneIteration() {
261312
// Verify that all analysis were properly unlocked.
262313
for (auto A : Analysis) {
@@ -297,52 +348,7 @@ void SILPassManager::runOneIteration() {
297348

298349
PendingFuncTransforms.clear();
299350

300-
if (isDisabled(SMT))
301-
continue;
302-
303-
PrettyStackTraceSILModuleTransform X(SMT);
304-
305-
SMT->injectPassManager(this);
306-
SMT->injectModule(Mod);
307-
308-
currentPassHasInvalidated = false;
309-
310-
if (SILPrintPassName)
311-
llvm::dbgs() << "#" << NumPassesRun << " Stage: " << StageName
312-
<< " Pass: " << SMT->getName() << " (module pass)\n";
313-
314-
if (doPrintBefore(SMT, nullptr)) {
315-
llvm::dbgs() << "*** SIL module before " << StageName << " "
316-
<< SMT->getName() << " (" << NumOptimizationIterations
317-
<< ") ***\n";
318-
printModule(Mod, Options.EmitVerboseSIL);
319-
}
320-
321-
llvm::sys::TimeValue StartTime = llvm::sys::TimeValue::now();
322-
Mod->registerDeleteNotificationHandler(SMT);
323-
SMT->run();
324-
Mod->removeDeleteNotificationHandler(SMT);
325-
326-
if (SILPrintPassTime) {
327-
auto Delta = llvm::sys::TimeValue::now().nanoseconds() -
328-
StartTime.nanoseconds();
329-
llvm::dbgs() << Delta << " (" << SMT->getName() << ",Module)\n";
330-
}
331-
332-
// If this pass invalidated anything, print and verify.
333-
if (doPrintAfter(SMT, nullptr,
334-
currentPassHasInvalidated && SILPrintAll)) {
335-
llvm::dbgs() << "*** SIL module after " << StageName << " "
336-
<< SMT->getName() << " (" << NumOptimizationIterations
337-
<< ") ***\n";
338-
printModule(Mod, Options.EmitVerboseSIL);
339-
}
340-
341-
if (Options.VerifyAll &&
342-
(currentPassHasInvalidated || !SILVerifyWithoutInvalidation)) {
343-
Mod->verify();
344-
verifyAnalyses();
345-
}
351+
runModulePass(SMT);
346352

347353
++NumPassesRun;
348354
if (Mod->getStage() == SILStage::Canonical

0 commit comments

Comments
 (0)