Skip to content

[ownership] Add a frontend option to stop optimizing right before we lower ownership. #33984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/swift/AST/SILOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class SILOptions {
/// Whether to stop the optimization pipeline after serializing SIL.
bool StopOptimizationAfterSerialization = false;

/// Whether to stop the optimization pipeline right before we lower ownership
/// and go from OSSA to non-ownership SIL.
bool StopOptimizationBeforeLoweringOwnership = false;

/// Whether to skip emitting non-inlinable function bodies.
bool SkipNonInlinableFunctionBodies = false;

Expand Down
5 changes: 5 additions & 0 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,11 @@ def sil_debug_serialization : Flag<["-"], "sil-debug-serialization">,
HelpText<"Do not eliminate functions in Mandatory Inlining/SILCombine dead "
"functions. (for debugging only)">;

def sil_stop_optzns_before_lowering_ownership :
Flag<["-"], "sil-stop-optzns-before-lowering-ownership">,
HelpText<"Stop optimizing at SIL time before we lower ownership from SIL. "
"Intended only for SIL ossa tests">;

def print_inst_counts : Flag<["-"], "print-inst-counts">,
HelpText<"Before IRGen, count all the various SIL instructions. Must be used "
"in conjunction with -print-stats.">;
Expand Down
2 changes: 2 additions & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,8 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
Opts.EmitVerboseSIL |= Args.hasArg(OPT_emit_verbose_sil);
Opts.EmitSortedSIL |= Args.hasArg(OPT_emit_sorted_sil);
Opts.PrintInstCounts |= Args.hasArg(OPT_print_inst_counts);
Opts.StopOptimizationBeforeLoweringOwnership |=
Args.hasArg(OPT_sil_stop_optzns_before_lowering_ownership);
if (const Arg *A = Args.getLastArg(OPT_external_pass_pipeline_filename))
Opts.ExternalPassPipelineFilename = A->getValue();

Expand Down
12 changes: 11 additions & 1 deletion lib/SILOptimizer/PassManager/PassPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ static void addPerfEarlyModulePassPipeline(SILPassPipelinePlan &P) {
//
// This is done so we can push ownership through the pass pipeline first for
// the stdlib and then everything else.
if (P.getOptions().StopOptimizationBeforeLoweringOwnership)
return;

P.addNonStdlibNonTransparentFunctionOwnershipModelEliminator();

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

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

// Then if we were asked to stop optimization before lowering OSSA (causing us
// to exit early from addPerfEarlyModulePassPipeline), exit early.
if (P.getOptions().StopOptimizationBeforeLoweringOwnership)
return P;

// Then run an iteration of the high-level SSA passes.
//
// FIXME: When *not* emitting a .swiftmodule, skip the high-level function
// pipeline to save compile time.
//
// NOTE: Ownership is now stripped within this function!
// NOTE: Ownership is now stripped within this function for the stdlib.
addHighLevelFunctionPipeline(P);

addHighLevelModulePipeline(P);
Expand Down