Skip to content

Commit 4734920

Browse files
committed
Don't rerun diagnostic passes on deserialized SIL.
1 parent 0dfce6c commit 4734920

11 files changed

+53
-1
lines changed

lib/SILOptimizer/IPO/CapturePromotion.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,9 @@ class CapturePromotionPass : public SILModuleTransform {
13061306
void run() override {
13071307
SmallVector<SILFunction*, 128> Worklist;
13081308
for (auto &F : *getModule()) {
1309+
if (F.wasDeserializedCanonical())
1310+
continue;
1311+
13091312
processFunction(&F, Worklist);
13101313
}
13111314

lib/SILOptimizer/Mandatory/ConstantPropagation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class ConstantPropagation : public SILFunctionTransform {
4646
} // end anonymous namespace
4747

4848
SILTransform *swift::createDiagnosticConstantPropagation() {
49+
// Diagostic propagation is rerun on deserialized SIL because it is sensitive
50+
// to assert configuration.
4951
return new ConstantPropagation(true /*enable diagnostics*/);
5052
}
5153

lib/SILOptimizer/Mandatory/DataflowDiagnostics.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ class EmitDFDiagnostics : public SILFunctionTransform {
120120

121121
/// The entry point to the transformation.
122122
void run() override {
123+
// Don't rerun diagnostics on deserialized functions.
124+
if (getFunction()->wasDeserializedCanonical())
125+
return;
126+
123127
SILModule &M = getFunction()->getModule();
124128
for (auto &BB : *getFunction())
125129
for (auto &I : BB) {

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2963,6 +2963,10 @@ class DefiniteInitialization : public SILFunctionTransform {
29632963

29642964
/// The entry point to the transformation.
29652965
void run() override {
2966+
// Don't rerun diagnostics on deserialized functions.
2967+
if (getFunction()->wasDeserializedCanonical())
2968+
return;
2969+
29662970
// Walk through and promote all of the alloc_box's that we can.
29672971
if (checkDefiniteInitialization(*getFunction())) {
29682972
invalidateAnalysis(SILAnalysis::InvalidationKind::FunctionBody);

lib/SILOptimizer/Mandatory/DiagnoseUnreachable.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,10 @@ void swift::performSILDiagnoseUnreachable(SILModule *M) {
793793
namespace {
794794
class NoReturnFolding : public SILFunctionTransform {
795795
void run() override {
796+
// Don't rerun diagnostics on deserialized functions.
797+
if (getFunction()->wasDeserializedCanonical())
798+
return;
799+
796800
performNoReturnFunctionProcessing(*getFunction(), this);
797801
}
798802
};
@@ -804,6 +808,8 @@ SILTransform *swift::createNoReturnFolding() {
804808

805809

806810
namespace {
811+
// This pass reruns on deserialized SIL because diagnostic constant propagation
812+
// can expose unreachable blocks which are then removed by this pass.
807813
class DiagnoseUnreachable : public SILFunctionTransform {
808814
void run() override {
809815
diagnoseUnreachable(*getFunction());

lib/SILOptimizer/Mandatory/GuaranteedARCOpts.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ bool GuaranteedARCOptsVisitor::visitReleaseValueInst(ReleaseValueInst *RVI) {
205205

206206
namespace {
207207

208+
// Even though this is a mandatory pass, it is rerun after deserialization in
209+
// cast DiagnosticConstantPropagation exposed anything new in this assert
210+
// configutation.
208211
struct GuaranteedARCOpts : SILFunctionTransform {
209212
void run() override {
210213
GuaranteedARCOptsVisitor Visitor;

lib/SILOptimizer/Mandatory/MandatoryInlining.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,19 @@ runOnFunctionRecursively(SILFunction *F, FullApplySite AI,
603603
//===----------------------------------------------------------------------===//
604604

605605
namespace {
606+
/// MandatoryInlining reruns on deserialized functions for two reasons, both
607+
/// unrelated to mandatory inlining:
608+
///
609+
/// 1. It recursively visits the entire call tree rooted at transparent
610+
/// functions. This has the effect of linking all reachable functions. If they
611+
/// aren't linked until the explicit SILLinker pass, then they don't benefit
612+
/// from rerunning optimizations like PredictableMemOps. Ideally we wouldn't
613+
/// need to rerun PredictableMemOps and wouldn't need to eagerly link anything
614+
/// in the mandatory pipeline.
615+
///
616+
/// 2. It may devirtualize non-transparent methods. It's not clear whether we
617+
/// really need to devirtualize this early without actually inlining, but it can
618+
/// unblock other optimizations in the mandatory pipeline.
606619
class MandatoryInlining : public SILModuleTransform {
607620
/// The entry point to the transformation.
608621
void run() override {
@@ -614,7 +627,6 @@ class MandatoryInlining : public SILModuleTransform {
614627
ImmutableFunctionSet::Factory SetFactory;
615628

616629
for (auto &F : *M) {
617-
618630
// Don't inline into thunks, even transparent callees.
619631
if (F.isThunk())
620632
continue;

lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,12 @@ namespace {
13941394

13951395
class PredictableMemoryOptimizations : public SILFunctionTransform {
13961396
/// The entry point to the transformation.
1397+
///
1398+
/// FIXME: This pass should not need to rerun on deserialized
1399+
/// functions. Nothing should have changed in the upstream pipeline after
1400+
/// deserialization. However, rerunning does improve some benchmarks. This
1401+
/// either indicates that this pass missing some opportunities the first time,
1402+
/// or has a pass order dependency on other early passes.
13971403
void run() override {
13981404
if (optimizeMemoryAllocations(*getFunction()))
13991405
invalidateAnalysis(SILAnalysis::InvalidationKind::FunctionBody);

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ static void addMandatoryOptPipeline(SILPassPipelinePlan &P,
9191
P.addOwnershipModelEliminator();
9292
P.addMandatoryInlining();
9393
P.addPredictableMemoryOptimizations();
94+
95+
// Diagnostic ConstantPropagation must be rerun on deserialized functions
96+
// because it is sensitive to the assert configuration.
97+
// Consequently, certain optimization passes beyond this point will also rerun.
9498
P.addDiagnosticConstantPropagation();
9599
P.addGuaranteedARCOpts();
96100
P.addDiagnoseUnreachable();

lib/SILOptimizer/Transforms/AllocBoxToStack.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,10 @@ namespace {
944944
class AllocBoxToStack : public SILFunctionTransform {
945945
/// The entry point to the transformation.
946946
void run() override {
947+
// Don't rerun on deserialized functions. Nothing should have changed.
948+
if (getFunction()->wasDeserializedCanonical())
949+
return;
950+
947951
AllocBoxToStackState pass(this);
948952
for (auto &BB : *getFunction()) {
949953
for (auto &I : BB)

lib/SILOptimizer/Transforms/MarkUninitializedFixup.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ namespace {
7474

7575
struct MarkUninitializedFixup : SILFunctionTransform {
7676
void run() override {
77+
// Don't rerun on deserialized functions. Nothing should have changed.
78+
if (getFunction()->wasDeserializedCanonical())
79+
return;
80+
7781
bool MadeChange = false;
7882
for (auto &BB : *getFunction()) {
7983
for (auto II = BB.begin(), IE = BB.end(); II != IE;) {

0 commit comments

Comments
 (0)