Skip to content

Commit bfb10c8

Browse files
authored
Merge pull request #28363 from gottesmm/pr-d097386463f35a7609fbf264df06cb5904d9746f
[silopt] Wire up the SerializeSIL pass pipeline so we always serialize at -O even if we don't run all or a subset of the passes.
2 parents 4907a98 + bbbad03 commit bfb10c8

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

include/swift/SILOptimizer/PassManager/PassManager.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class SILPassManager {
9797

9898
/// If true, passes are also run for functions which have
9999
/// OptimizationMode::NoOptimization.
100-
bool isMandatoryPipeline = false;
100+
bool isMandatory = false;
101101

102102
/// The IRGen SIL passes. These have to be dynamically added by IRGen.
103103
llvm::DenseMap<unsigned, SILTransform *> IRGenPasses;
@@ -114,16 +114,15 @@ class SILPassManager {
114114
/// C'tor. It creates and registers all analysis passes, which are defined
115115
/// in Analysis.def.
116116
///
117-
/// If \p isMandatoryPipeline is true, passes are also run for functions
117+
/// If \p isMandatory is true, passes are also run for functions
118118
/// which have OptimizationMode::NoOptimization.
119119
SILPassManager(SILModule *M, llvm::StringRef Stage = "",
120-
bool isMandatoryPipeline = false);
120+
bool isMandatory = false);
121121

122122
/// C'tor. It creates an IRGen pass manager. Passes can query for the
123123
/// IRGenModule.
124124
SILPassManager(SILModule *M, irgen::IRGenModule *IRMod,
125-
llvm::StringRef Stage = "",
126-
bool isMandatoryPipeline = false);
125+
llvm::StringRef Stage = "", bool isMandatory = false);
127126

128127
const SILOptions &getOptions() const;
129128

lib/SILOptimizer/PassManager/PassManager.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ class PassManagerDeserializationNotificationHandler final
273273
} // end anonymous namespace
274274

275275
SILPassManager::SILPassManager(SILModule *M, llvm::StringRef Stage,
276-
bool isMandatoryPipeline)
277-
: Mod(M), StageName(Stage), isMandatoryPipeline(isMandatoryPipeline),
276+
bool isMandatory)
277+
: Mod(M), StageName(Stage), isMandatory(isMandatory),
278278
deserializationNotificationHandler(nullptr) {
279279
#define ANALYSIS(NAME) \
280280
Analyses.push_back(create##NAME##Analysis(Mod));
@@ -292,13 +292,13 @@ SILPassManager::SILPassManager(SILModule *M, llvm::StringRef Stage,
292292
}
293293

294294
SILPassManager::SILPassManager(SILModule *M, irgen::IRGenModule *IRMod,
295-
llvm::StringRef Stage, bool isMandatoryPipeline)
296-
: SILPassManager(M, Stage, isMandatoryPipeline) {
295+
llvm::StringRef Stage, bool isMandatory)
296+
: SILPassManager(M, Stage, isMandatory) {
297297
this->IRMod = IRMod;
298298
}
299299

300300
bool SILPassManager::continueTransforming() {
301-
if (isMandatoryPipeline)
301+
if (isMandatory)
302302
return true;
303303
return NumPassesRun < SILNumOptPassesToRun;
304304
}
@@ -467,7 +467,7 @@ runFunctionPasses(unsigned FromTransIdx, unsigned ToTransIdx) {
467467

468468
// Only include functions that are definitions, and which have not
469469
// been intentionally excluded from optimization.
470-
if (F.isDefinition() && (isMandatoryPipeline || F.shouldOptimize()))
470+
if (F.isDefinition() && (isMandatory || F.shouldOptimize()))
471471
FunctionWorklist.push_back(*I);
472472
}
473473

@@ -675,8 +675,8 @@ void SILPassManager::notifyOfNewFunction(SILFunction *F, SILTransform *T) {
675675

676676
void SILPassManager::addFunctionToWorklist(SILFunction *F,
677677
SILFunction *DerivedFrom) {
678-
assert(F && F->isDefinition() && (isMandatoryPipeline || F->shouldOptimize())
679-
&& "Expected optimizable function definition!");
678+
assert(F && F->isDefinition() && (isMandatory || F->shouldOptimize()) &&
679+
"Expected optimizable function definition!");
680680

681681
constexpr int MaxDeriveLevels = 10;
682682

lib/SILOptimizer/PassManager/Passes.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,27 @@ void swift::runSILOptimizationPasses(SILModule &Module) {
9696
if (Module.getOptions().VerifyAll)
9797
Module.verify();
9898

99-
if (Module.getOptions().DisableSILPerfOptimizations)
99+
if (Module.getOptions().DisableSILPerfOptimizations) {
100+
// If we are not supposed to run SIL perf optzns, we may still need to
101+
// serialize. So serialize now.
102+
SILPassManager PM(&Module, "" /*stage*/, true /*isMandatory*/);
103+
PM.executePassPipelinePlan(
104+
SILPassPipelinePlan::getSerializeSILPassPipeline(Module.getOptions()));
100105
return;
106+
}
101107

102-
SILPassManager PM(&Module);
103-
PM.executePassPipelinePlan(
104-
SILPassPipelinePlan::getPerformancePassPipeline(Module.getOptions()));
108+
{
109+
SILPassManager PM(&Module);
110+
PM.executePassPipelinePlan(
111+
SILPassPipelinePlan::getPerformancePassPipeline(Module.getOptions()));
112+
}
113+
114+
// Check if we actually serialized our module. If we did not, serialize now.
115+
if (!Module.isSerialized()) {
116+
SILPassManager PM(&Module, "" /*stage*/, true /*isMandatory*/);
117+
PM.executePassPipelinePlan(
118+
SILPassPipelinePlan::getSerializeSILPassPipeline(Module.getOptions()));
119+
}
105120

106121
// If we were asked to debug serialization, exit now.
107122
if (Module.getOptions().DebugSerialization)

0 commit comments

Comments
 (0)