@@ -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
738744SILPassPipelinePlan::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