Skip to content

Commit 260e68b

Browse files
committed
Passmanager: fix a problem with skipping the inliner pass
A pass is skipped if no other pass changed the function since the previous run of the same pass. Don't do this is if a pass depends on the function bodies of called functions, e.g. the inliner. Other passes might change the callees, e.g. function signature opts, which makes it worth to run the inliner again, even if the function itself didn't change.
1 parent 3e04b86 commit 260e68b

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

include/swift/SILOptimizer/PassManager/PassManager.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ class SILPassManager {
203203
/// Set to true when a pass invalidates an analysis.
204204
bool CurrentPassHasInvalidated = false;
205205

206+
bool currentPassDependsOnCalleeBodies = false;
207+
206208
/// True if we need to stop running passes and restart again on the
207209
/// same function.
208210
bool RestartPipeline = false;
@@ -337,6 +339,10 @@ class SILPassManager {
337339
CompletedPassesMap[F].reset();
338340
}
339341

342+
void setDependingOnCalleeBodies() {
343+
currentPassDependsOnCalleeBodies = true;
344+
}
345+
340346
/// Reset the state of the pass manager and remove all transformation
341347
/// owned by the pass manager. Analysis passes will be kept.
342348
void resetAndRemoveTransformations();

lib/SILOptimizer/PassManager/PassManager.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ void SILPassManager::runPassOnFunction(unsigned TransIdx, SILFunction *F) {
551551
updateSILModuleStatsBeforeTransform(F->getModule(), SFT, *this, NumPassesRun);
552552

553553
CurrentPassHasInvalidated = false;
554+
currentPassDependsOnCalleeBodies = false;
554555
numSubpassesRun = 0;
555556

556557
auto MatchFun = [&](const std::string &Str) -> bool {
@@ -652,7 +653,7 @@ void SILPassManager::runPassOnFunction(unsigned TransIdx, SILFunction *F) {
652653
duration.count());
653654

654655
// Remember if this pass didn't change anything.
655-
if (!CurrentPassHasInvalidated)
656+
if (!CurrentPassHasInvalidated && !currentPassDependsOnCalleeBodies)
656657
completedPasses.set((size_t)SFT->getPassKind());
657658

658659
if (getOptions().VerifyAll &&

lib/SILOptimizer/Transforms/PerformanceInliner.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class SILPerformanceInliner {
100100
/// global_init attributes.
101101
InlineSelection WhatToInline;
102102

103+
SILPassManager *pm;
103104
DominanceAnalysis *DA;
104105
SILLoopAnalysis *LA;
105106
BasicCalleeAnalysis *BCA;
@@ -227,11 +228,12 @@ class SILPerformanceInliner {
227228

228229
public:
229230
SILPerformanceInliner(StringRef PassName, SILOptFunctionBuilder &FuncBuilder,
230-
InlineSelection WhatToInline, DominanceAnalysis *DA,
231+
InlineSelection WhatToInline,
232+
SILPassManager *pm, DominanceAnalysis *DA,
231233
SILLoopAnalysis *LA, BasicCalleeAnalysis *BCA,
232234
OptimizationMode OptMode, OptRemark::Emitter &ORE)
233235
: PassName(PassName), FuncBuilder(FuncBuilder),
234-
WhatToInline(WhatToInline), DA(DA), LA(LA), BCA(BCA), CBI(DA), ORE(ORE),
236+
WhatToInline(WhatToInline), pm(pm), DA(DA), LA(LA), BCA(BCA), CBI(DA), ORE(ORE),
235237
OptMode(OptMode) {}
236238

237239
bool inlineCallsIntoFunction(SILFunction *F);
@@ -934,6 +936,8 @@ void SILPerformanceInliner::collectAppliesToInline(
934936
if (!FullApplySite::isa(&*I))
935937
continue;
936938

939+
pm->setDependingOnCalleeBodies();
940+
937941
FullApplySite AI = FullApplySite(&*I);
938942

939943
auto *Callee = getEligibleFunction(AI, WhatToInline);
@@ -1155,8 +1159,8 @@ class SILPerformanceInlinerPass : public SILFunctionTransform {
11551159

11561160
SILOptFunctionBuilder FuncBuilder(*this);
11571161

1158-
SILPerformanceInliner Inliner(getID(), FuncBuilder, WhatToInline, DA, LA,
1159-
BCA, OptMode, ORE);
1162+
SILPerformanceInliner Inliner(getID(), FuncBuilder, WhatToInline,
1163+
getPassManager(), DA, LA, BCA, OptMode, ORE);
11601164

11611165
assert(getFunction()->isDefinition() &&
11621166
"Expected only functions with bodies!");

0 commit comments

Comments
 (0)