@@ -79,8 +79,7 @@ static void addDefiniteInitialization(SILPassPipelinePlan &P) {
79
79
P.addRawSILInstLowering ();
80
80
}
81
81
82
- static void addMandatoryOptPipeline (SILPassPipelinePlan &P,
83
- const SILOptions &Options) {
82
+ static void addMandatoryOptPipeline (SILPassPipelinePlan &P) {
84
83
P.startPipeline (" Guaranteed Passes" );
85
84
P.addDiagnoseStaticExclusivity ();
86
85
P.addCapturePromotion ();
@@ -99,11 +98,13 @@ static void addMandatoryOptPipeline(SILPassPipelinePlan &P,
99
98
// pass. This will happen when OSSA is no longer eliminated before the
100
99
// optimizer pipeline is run implying we can put a pass that requires OSSA
101
100
// there.
101
+ const auto &Options = P.getOptions ();
102
102
if (Options.EnableMandatorySemanticARCOpts && Options.shouldOptimize ()) {
103
103
P.addSemanticARCOpts ();
104
104
}
105
105
P.addClosureLifetimeFixup ();
106
- P.addOwnershipModelEliminator ();
106
+ if (Options.StripOwnershipDuringDiagnosticsPipeline )
107
+ P.addOwnershipModelEliminator ();
107
108
P.addMandatoryInlining ();
108
109
P.addMandatorySILLinker ();
109
110
@@ -130,7 +131,7 @@ static void addMandatoryOptPipeline(SILPassPipelinePlan &P,
130
131
131
132
SILPassPipelinePlan
132
133
SILPassPipelinePlan::getDiagnosticPassPipeline (const SILOptions &Options) {
133
- SILPassPipelinePlan P;
134
+ SILPassPipelinePlan P (Options) ;
134
135
135
136
if (SILViewSILGenCFG) {
136
137
addCFGPrinterPipeline (P, " SIL View SILGen CFG" );
@@ -145,7 +146,7 @@ SILPassPipelinePlan::getDiagnosticPassPipeline(const SILOptions &Options) {
145
146
}
146
147
147
148
// Otherwise run the rest of diagnostics.
148
- addMandatoryOptPipeline (P, Options );
149
+ addMandatoryOptPipeline (P);
149
150
150
151
if (SILViewGuaranteedCFG) {
151
152
addCFGPrinterPipeline (P, " SIL View Guaranteed CFG" );
@@ -157,8 +158,9 @@ SILPassPipelinePlan::getDiagnosticPassPipeline(const SILOptions &Options) {
157
158
// Ownership Eliminator Pipeline
158
159
// ===----------------------------------------------------------------------===//
159
160
160
- SILPassPipelinePlan SILPassPipelinePlan::getOwnershipEliminatorPassPipeline () {
161
- SILPassPipelinePlan P;
161
+ SILPassPipelinePlan SILPassPipelinePlan::getOwnershipEliminatorPassPipeline (
162
+ const SILOptions &Options) {
163
+ SILPassPipelinePlan P (Options);
162
164
addOwnershipModelEliminatorPipeline (P);
163
165
return P;
164
166
}
@@ -240,8 +242,7 @@ void addHighLevelLoopOptPasses(SILPassPipelinePlan &P) {
240
242
}
241
243
242
244
// Perform classic SSA optimizations.
243
- void addSSAPasses (SILPassPipelinePlan &P, OptimizationLevelKind OpLevel,
244
- bool stopAfterSerialization = false ) {
245
+ void addSSAPasses (SILPassPipelinePlan &P, OptimizationLevelKind OpLevel) {
245
246
// Promote box allocations to stack allocations.
246
247
P.addAllocBoxToStack ();
247
248
@@ -294,7 +295,12 @@ void addSSAPasses(SILPassPipelinePlan &P, OptimizationLevelKind OpLevel,
294
295
// which reduces the ability of the compiler to optimize clients
295
296
// importing this module.
296
297
P.addSerializeSILPass ();
297
- if (stopAfterSerialization)
298
+
299
+ // Now strip any transparent functions that still have ownership.
300
+ if (!P.getOptions ().StripOwnershipDuringDiagnosticsPipeline )
301
+ P.addOwnershipModelEliminator ();
302
+
303
+ if (P.getOptions ().StopOptimizationAfterSerialization )
298
304
return ;
299
305
300
306
// Does inline semantics-functions (except "availability"), but not
@@ -370,6 +376,11 @@ static void addPerfEarlyModulePassPipeline(SILPassPipelinePlan &P) {
370
376
// Get rid of apparently dead functions as soon as possible so that
371
377
// we do not spend time optimizing them.
372
378
P.addDeadFunctionElimination ();
379
+
380
+ // Strip ownership from non-transparent functions.
381
+ if (!P.getOptions ().StripOwnershipDuringDiagnosticsPipeline )
382
+ P.addNonTransparentFunctionOwnershipModelEliminator ();
383
+
373
384
// Start by cloning functions from stdlib.
374
385
P.addPerformanceSILLinker ();
375
386
@@ -399,11 +410,10 @@ static void addMidModulePassesStackPromotePassPipeline(SILPassPipelinePlan &P) {
399
410
P.addStackPromotion ();
400
411
}
401
412
402
- static bool addMidLevelPassPipeline (SILPassPipelinePlan &P,
403
- bool stopAfterSerialization) {
413
+ static bool addMidLevelPassPipeline (SILPassPipelinePlan &P) {
404
414
P.startPipeline (" MidLevel" );
405
- addSSAPasses (P, OptimizationLevelKind::MidLevel, stopAfterSerialization );
406
- if (stopAfterSerialization )
415
+ addSSAPasses (P, OptimizationLevelKind::MidLevel);
416
+ if (P. getOptions (). StopOptimizationAfterSerialization )
407
417
return true ;
408
418
409
419
// Specialize partially applied functions with dead arguments as a preparation
@@ -538,8 +548,8 @@ static void addSILDebugInfoGeneratorPipeline(SILPassPipelinePlan &P) {
538
548
// / Mandatory IRGen preparation. It is the caller's job to set the set stage to
539
549
// / "lowered" after running this pipeline.
540
550
SILPassPipelinePlan
541
- SILPassPipelinePlan::getLoweringPassPipeline () {
542
- SILPassPipelinePlan P;
551
+ SILPassPipelinePlan::getLoweringPassPipeline (const SILOptions &Options ) {
552
+ SILPassPipelinePlan P (Options) ;
543
553
P.startPipeline (" Address Lowering" );
544
554
P.addIRGenPrepare ();
545
555
P.addAddressLowering ();
@@ -549,7 +559,7 @@ SILPassPipelinePlan::getLoweringPassPipeline() {
549
559
550
560
SILPassPipelinePlan
551
561
SILPassPipelinePlan::getIRGenPreparePassPipeline (const SILOptions &Options) {
552
- SILPassPipelinePlan P;
562
+ SILPassPipelinePlan P (Options) ;
553
563
P.startPipeline (" IRGen Preparation" );
554
564
// Insert SIL passes to run during IRGen.
555
565
// Hoist generic alloc_stack instructions to the entry block to enable better
@@ -563,7 +573,7 @@ SILPassPipelinePlan::getIRGenPreparePassPipeline(const SILOptions &Options) {
563
573
564
574
SILPassPipelinePlan
565
575
SILPassPipelinePlan::getSILOptPreparePassPipeline (const SILOptions &Options) {
566
- SILPassPipelinePlan P;
576
+ SILPassPipelinePlan P (Options) ;
567
577
568
578
if (Options.DebugSerialization ) {
569
579
addPerfDebugSerializationPipeline (P);
@@ -578,7 +588,7 @@ SILPassPipelinePlan::getSILOptPreparePassPipeline(const SILOptions &Options) {
578
588
579
589
SILPassPipelinePlan
580
590
SILPassPipelinePlan::getPerformancePassPipeline (const SILOptions &Options) {
581
- SILPassPipelinePlan P;
591
+ SILPassPipelinePlan P (Options) ;
582
592
583
593
if (Options.DebugSerialization ) {
584
594
addPerfDebugSerializationPipeline (P);
@@ -594,7 +604,7 @@ SILPassPipelinePlan::getPerformancePassPipeline(const SILOptions &Options) {
594
604
addMidModulePassesStackPromotePassPipeline (P);
595
605
596
606
// Run an iteration of the mid-level SSA passes.
597
- if (addMidLevelPassPipeline (P, Options. StopOptimizationAfterSerialization ))
607
+ if (addMidLevelPassPipeline (P))
598
608
return P;
599
609
600
610
// Perform optimizations that specialize.
@@ -624,8 +634,9 @@ SILPassPipelinePlan::getPerformancePassPipeline(const SILOptions &Options) {
624
634
// Onone Pass Pipeline
625
635
// ===----------------------------------------------------------------------===//
626
636
627
- SILPassPipelinePlan SILPassPipelinePlan::getOnonePassPipeline () {
628
- SILPassPipelinePlan P;
637
+ SILPassPipelinePlan
638
+ SILPassPipelinePlan::getOnonePassPipeline (const SILOptions &Options) {
639
+ SILPassPipelinePlan P (Options);
629
640
630
641
// First specialize user-code.
631
642
P.startPipeline (" Prespecialization" );
@@ -642,15 +653,20 @@ SILPassPipelinePlan SILPassPipelinePlan::getOnonePassPipeline() {
642
653
// Finally serialize the SIL if we are asked to.
643
654
P.addSerializeSILPass ();
644
655
656
+ // And then strip ownership before we IRGen.
657
+ if (!Options.StripOwnershipDuringDiagnosticsPipeline )
658
+ P.addOwnershipModelEliminator ();
659
+
645
660
return P;
646
661
}
647
662
648
663
// ===----------------------------------------------------------------------===//
649
664
// Inst Count Pass Pipeline
650
665
// ===----------------------------------------------------------------------===//
651
666
652
- SILPassPipelinePlan SILPassPipelinePlan::getInstCountPassPipeline () {
653
- SILPassPipelinePlan P;
667
+ SILPassPipelinePlan
668
+ SILPassPipelinePlan::getInstCountPassPipeline (const SILOptions &Options) {
669
+ SILPassPipelinePlan P (Options);
654
670
P.startPipeline (" Inst Count" );
655
671
P.addInstCount ();
656
672
return P;
@@ -680,8 +696,9 @@ void SILPassPipelinePlan::addPasses(ArrayRef<PassKind> PassKinds) {
680
696
}
681
697
682
698
SILPassPipelinePlan
683
- SILPassPipelinePlan::getPassPipelineForKinds (ArrayRef<PassKind> PassKinds) {
684
- SILPassPipelinePlan P;
699
+ SILPassPipelinePlan::getPassPipelineForKinds (const SILOptions &Options,
700
+ ArrayRef<PassKind> PassKinds) {
701
+ SILPassPipelinePlan P (Options);
685
702
P.startPipeline (" Pass List Pipeline" );
686
703
P.addPasses (PassKinds);
687
704
return P;
@@ -717,7 +734,8 @@ void SILPassPipelinePlan::print(llvm::raw_ostream &os) {
717
734
}
718
735
719
736
SILPassPipelinePlan
720
- SILPassPipelinePlan::getPassPipelineFromFile (StringRef Filename) {
737
+ SILPassPipelinePlan::getPassPipelineFromFile (const SILOptions &Options,
738
+ StringRef Filename) {
721
739
namespace yaml = llvm::yaml;
722
740
LLVM_DEBUG (llvm::dbgs () << " Parsing Pass Pipeline from " << Filename << " \n " );
723
741
@@ -736,7 +754,7 @@ SILPassPipelinePlan::getPassPipelineFromFile(StringRef Filename) {
736
754
yaml::Node *N = DI->getRoot ();
737
755
assert (N && " Failed to find a root" );
738
756
739
- SILPassPipelinePlan P;
757
+ SILPassPipelinePlan P (Options) ;
740
758
741
759
auto *RootList = cast<yaml::SequenceNode>(N);
742
760
llvm::SmallVector<PassKind, 32 > Passes;
0 commit comments