@@ -346,11 +346,13 @@ void addFunctionPasses(SILPassPipelinePlan &P,
346
346
P.addDevirtualizer ();
347
347
P.addARCSequenceOpts ();
348
348
349
- // We earlier eliminated ownership if we are not compiling the stdlib. Now
350
- // handle the stdlib functions, re-simplifying, eliminating ARC as we do.
351
- P.addCopyPropagation ();
352
- P.addSemanticARCOpts ();
353
- P.addNonTransparentFunctionOwnershipModelEliminator ();
349
+ if (!P.getOptions ().SerializeStdlibWithOwnershipWithOpts ) {
350
+ // We earlier eliminated ownership if we are not compiling the stdlib. Now
351
+ // handle the stdlib functions, re-simplifying, eliminating ARC as we do.
352
+ P.addCopyPropagation ();
353
+ P.addSemanticARCOpts ();
354
+ P.addNonTransparentFunctionOwnershipModelEliminator ();
355
+ }
354
356
355
357
switch (OpLevel) {
356
358
case OptimizationLevelKind::HighLevel:
@@ -368,6 +370,12 @@ void addFunctionPasses(SILPassPipelinePlan &P,
368
370
break ;
369
371
}
370
372
373
+ // Clean up Semantic ARC before we perform additional post-inliner opts.
374
+ if (P.getOptions ().SerializeStdlibWithOwnershipWithOpts ) {
375
+ P.addCopyPropagation ();
376
+ P.addSemanticARCOpts ();
377
+ }
378
+
371
379
// Promote stack allocations to values and eliminate redundant
372
380
// loads.
373
381
P.addMem2Reg ();
@@ -426,6 +434,12 @@ void addFunctionPasses(SILPassPipelinePlan &P,
426
434
P.addRetainSinking ();
427
435
P.addReleaseHoisting ();
428
436
P.addARCSequenceOpts ();
437
+
438
+ // Run a final round of ARC opts when ownership is enabled.
439
+ if (P.getOptions ().SerializeStdlibWithOwnershipWithOpts ) {
440
+ P.addCopyPropagation ();
441
+ P.addSemanticARCOpts ();
442
+ }
429
443
}
430
444
431
445
static void addPerfDebugSerializationPipeline (SILPassPipelinePlan &P) {
@@ -514,7 +528,6 @@ static void addHighLevelFunctionPipeline(SILPassPipelinePlan &P) {
514
528
// FIXME: update EagerSpecializer to be a function pass!
515
529
P.addEagerSpecializer ();
516
530
517
- // stdlib ownership model elimination is done within addFunctionPasses
518
531
addFunctionPasses (P, OptimizationLevelKind::HighLevel);
519
532
520
533
addHighLevelLoopOptPasses (P);
@@ -770,6 +783,13 @@ SILPassPipelinePlan::getPerformancePassPipeline(const SILOptions &Options) {
770
783
771
784
addHighLevelModulePipeline (P);
772
785
786
+ // Run one last copy propagation/semantic arc opts run before serialization/us
787
+ // lowering ownership.
788
+ if (P.getOptions ().SerializeStdlibWithOwnershipWithOpts ) {
789
+ P.addCopyPropagation ();
790
+ P.addSemanticARCOpts ();
791
+ }
792
+
773
793
addSerializePipeline (P);
774
794
if (Options.StopOptimizationAfterSerialization )
775
795
return P;
0 commit comments