Skip to content

Commit a445079

Browse files
authored
Merge pull request #33984 from gottesmm/pr-5adf3ac760b4c158f5710c5ddb5d7859625d8c4d
[ownership] Add a frontend option to stop optimizing right before we lower ownership.
2 parents 6508a18 + 4cbc07c commit a445079

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

include/swift/AST/SILOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ class SILOptions {
8181
/// Whether to stop the optimization pipeline after serializing SIL.
8282
bool StopOptimizationAfterSerialization = false;
8383

84+
/// Whether to stop the optimization pipeline right before we lower ownership
85+
/// and go from OSSA to non-ownership SIL.
86+
bool StopOptimizationBeforeLoweringOwnership = false;
87+
8488
/// Whether to skip emitting non-inlinable function bodies.
8589
bool SkipNonInlinableFunctionBodies = false;
8690

include/swift/Option/FrontendOptions.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,11 @@ def sil_debug_serialization : Flag<["-"], "sil-debug-serialization">,
580580
HelpText<"Do not eliminate functions in Mandatory Inlining/SILCombine dead "
581581
"functions. (for debugging only)">;
582582

583+
def sil_stop_optzns_before_lowering_ownership :
584+
Flag<["-"], "sil-stop-optzns-before-lowering-ownership">,
585+
HelpText<"Stop optimizing at SIL time before we lower ownership from SIL. "
586+
"Intended only for SIL ossa tests">;
587+
583588
def print_inst_counts : Flag<["-"], "print-inst-counts">,
584589
HelpText<"Before IRGen, count all the various SIL instructions. Must be used "
585590
"in conjunction with -print-stats.">;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,8 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
11481148
Opts.EmitVerboseSIL |= Args.hasArg(OPT_emit_verbose_sil);
11491149
Opts.EmitSortedSIL |= Args.hasArg(OPT_emit_sorted_sil);
11501150
Opts.PrintInstCounts |= Args.hasArg(OPT_print_inst_counts);
1151+
Opts.StopOptimizationBeforeLoweringOwnership |=
1152+
Args.hasArg(OPT_sil_stop_optzns_before_lowering_ownership);
11511153
if (const Arg *A = Args.getLastArg(OPT_external_pass_pipeline_filename))
11521154
Opts.ExternalPassPipelineFilename = A->getValue();
11531155

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,9 @@ static void addPerfEarlyModulePassPipeline(SILPassPipelinePlan &P) {
447447
//
448448
// This is done so we can push ownership through the pass pipeline first for
449449
// the stdlib and then everything else.
450+
if (P.getOptions().StopOptimizationBeforeLoweringOwnership)
451+
return;
452+
450453
P.addNonStdlibNonTransparentFunctionOwnershipModelEliminator();
451454

452455
// Start by linking in referenced functions from other modules.
@@ -721,14 +724,21 @@ SILPassPipelinePlan::getPerformancePassPipeline(const SILOptions &Options) {
721724

722725
// Eliminate immediately dead functions and then clone functions from the
723726
// stdlib.
727+
//
728+
// This also performs early OSSA based optimizations on *all* swift code.
724729
addPerfEarlyModulePassPipeline(P);
725730

731+
// Then if we were asked to stop optimization before lowering OSSA (causing us
732+
// to exit early from addPerfEarlyModulePassPipeline), exit early.
733+
if (P.getOptions().StopOptimizationBeforeLoweringOwnership)
734+
return P;
735+
726736
// Then run an iteration of the high-level SSA passes.
727737
//
728738
// FIXME: When *not* emitting a .swiftmodule, skip the high-level function
729739
// pipeline to save compile time.
730740
//
731-
// NOTE: Ownership is now stripped within this function!
741+
// NOTE: Ownership is now stripped within this function for the stdlib.
732742
addHighLevelFunctionPipeline(P);
733743

734744
addHighLevelModulePipeline(P);

0 commit comments

Comments
 (0)