Skip to content

Commit 702c1bc

Browse files
committed
[arc] Change guaranteed arc opts to be based on SemanticARCOpts and move from Diagnostic pipeline -> Onone pipeline.
The pass is already not being run during normal compilation scenarios today since it bails on OSSA except in certain bit-rot situations where a test wasn't updated and so was inadvertently invoking the pass. I discovered these while originally just trying to eliminate the pass from the diagnostic pipeline. The reason why I am doing this in one larger change is that I found there were a bunch of sil tests inadvertently relying on guaranteed arc opts to eliminate copy traffic. So, if I just removed this and did this in two steps, I would basically be unoptimizing then re-optimizing the tests. Some notes: 1. The new guaranteed arc opts is based off of SemanticARCOpts and runs only on ossa. Specifically, in this new pass, we just perform simple canonicalizations that do not involve any significant analysis. Some examples: a copy_value all of whose uses are destroys. This will do what the original pass did and more without more compile time. I did a conservative first approximation, but we can probably tune this a bit. 2. the reason why I am doing this now is that I was trying to eliminate the enable-ownership-stripping-after-serialization flag and discovered that the test opaque_value_mandatory implicitly depends on this since sil-opt by default was the only place left in the compiler with that option set to false by default. So I am eliminating that dependency before I land the larger change.
1 parent 73d8419 commit 702c1bc

18 files changed

+121
-505
lines changed

lib/SILOptimizer/Mandatory/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ target_sources(swiftSILOptimizer PRIVATE
1212
DiagnoseStaticExclusivity.cpp
1313
DiagnoseUnreachable.cpp
1414
Differentiation.cpp
15-
GuaranteedARCOpts.cpp
1615
IRGenPrepare.cpp
1716
MandatoryInlining.cpp
1817
PredictableMemOpt.cpp

lib/SILOptimizer/Mandatory/GuaranteedARCOpts.cpp

Lines changed: 0 additions & 260 deletions
This file was deleted.

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,15 @@ static void addDefiniteInitialization(SILPassPipelinePlan &P) {
7878
P.addRawSILInstLowering();
7979
}
8080

81-
static void addMandatoryOptPipeline(SILPassPipelinePlan &P) {
82-
P.startPipeline("Guaranteed Passes");
81+
// This pipeline defines a set of mandatory diagnostic passes and a set of
82+
// supporting optimization passes that enable those diagnostics. These are run
83+
// before any performance optimizations and in contrast to those optimizations
84+
// _IS_ run when SourceKit emits diagnostics.
85+
//
86+
// Any passes not needed for diagnostic emission that need to run at -Onone
87+
// should be in the -Onone pass pipeline and the prepare optimizations pipeline.
88+
static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
89+
P.startPipeline("Mandatory Diagnostic Passes + Enabling Optimization Passes");
8390
P.addSILGenCleanup();
8491
P.addDiagnoseInvalidEscapingCaptures();
8592
P.addDiagnoseStaticExclusivity();
@@ -142,7 +149,6 @@ static void addMandatoryOptPipeline(SILPassPipelinePlan &P) {
142149
// dead allocations.
143150
P.addPredictableDeadAllocationElimination();
144151

145-
P.addGuaranteedARCOpts();
146152
P.addDiagnoseUnreachable();
147153
P.addDiagnoseInfiniteRecursion();
148154
P.addYieldOnceCheck();
@@ -169,7 +175,7 @@ SILPassPipelinePlan::getDiagnosticPassPipeline(const SILOptions &Options) {
169175
}
170176

171177
// Otherwise run the rest of diagnostics.
172-
addMandatoryOptPipeline(P);
178+
addMandatoryDiagnosticOptPipeline(P);
173179

174180
if (SILViewGuaranteedCFG) {
175181
addCFGPrinterPipeline(P, "SIL View Guaranteed CFG");
@@ -738,9 +744,14 @@ SILPassPipelinePlan
738744
SILPassPipelinePlan::getOnonePassPipeline(const SILOptions &Options) {
739745
SILPassPipelinePlan P(Options);
740746

741-
P.startPipeline("Mandatory Combines");
747+
// These are optimizations that we do not need to enable diagnostics (or
748+
// depend on other passes needed for diagnostics). Thus we can run them later
749+
// and avoid having SourceKit run these passes when just emitting diagnostics
750+
// in the editor.
751+
P.startPipeline("non-Diagnostic Enabling Mandatory Optimizations");
742752
P.addForEachLoopUnroll();
743753
P.addMandatoryCombine();
754+
P.addGuaranteedARCOpts();
744755

745756
// First serialize the SIL if we are asked to.
746757
P.startPipeline("Serialization");

0 commit comments

Comments
 (0)