Skip to content

[ownership] Make whether or not we serialize in OSSA form based off of a flag instead of off of whether or not we are processing the stdlib. #36031

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
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
5 changes: 5 additions & 0 deletions include/swift/AST/SILOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ class SILOptions {
/// and go from OSSA to non-ownership SIL.
bool StopOptimizationBeforeLoweringOwnership = false;

/// Do we always serialize SIL in OSSA form?
///
/// If this is disabled we do not serialize in OSSA form when optimizing.
bool EnableOSSAModules = false;

// The kind of function bodies to skip emitting.
FunctionBodySkipping SkipFunctionBodies = FunctionBodySkipping::None;

Expand Down
4 changes: 4 additions & 0 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,10 @@ def disable_ast_verifier : Flag<["-"], "disable-ast-verifier">,
"disabled. NOTE: Can not be used if enable-ast-verifier is used "
"as well">;

def enable_ossa_modules : Flag<["-"], "enable-ossa-modules">,
HelpText<"Always serialize SIL in ossa form. If this flag is not passed in, "
"when optimizing ownership will be lowered before serializing SIL">;

def new_driver_path
: Separate<["-"], "new-driver-path">, MetaVarName<"<path>">,
HelpText<"Path of the new driver to be used">;
Expand Down
1 change: 1 addition & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,7 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
Opts.RemoveRuntimeAsserts |= Args.hasArg(OPT_RemoveRuntimeAsserts);

Opts.EnableARCOptimizations &= !Args.hasArg(OPT_disable_arc_opts);
Opts.EnableOSSAModules |= Args.hasArg(OPT_enable_ossa_modules);
Opts.EnableOSSAOptimizations &= !Args.hasArg(OPT_disable_ossa_opts);
Opts.EnableSpeculativeDevirtualization |= Args.hasArg(OPT_enable_spec_devirt);
Opts.DisableSILPerfOptimizations |= Args.hasArg(OPT_disable_sil_perf_optzns);
Expand Down
14 changes: 6 additions & 8 deletions lib/SILOptimizer/PassManager/PassPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,11 @@ void addFunctionPasses(SILPassPipelinePlan &P,
P.addDevirtualizer();
P.addARCSequenceOpts();

if (!P.getOptions().SerializeStdlibWithOwnershipWithOpts) {
if (P.getOptions().EnableOSSAModules) {
// We earlier eliminated ownership if we are not compiling the stdlib. Now
// handle the stdlib functions, re-simplifying, eliminating ARC as we do.
P.addCopyPropagation();
P.addSemanticARCOpts();
P.addNonTransparentFunctionOwnershipModelEliminator();
}

switch (OpLevel) {
Expand All @@ -372,7 +371,7 @@ void addFunctionPasses(SILPassPipelinePlan &P,
}

// Clean up Semantic ARC before we perform additional post-inliner opts.
if (P.getOptions().SerializeStdlibWithOwnershipWithOpts) {
if (P.getOptions().EnableOSSAModules) {
P.addCopyPropagation();
P.addSemanticARCOpts();
}
Expand Down Expand Up @@ -437,7 +436,7 @@ void addFunctionPasses(SILPassPipelinePlan &P,
P.addARCSequenceOpts();

// Run a final round of ARC opts when ownership is enabled.
if (P.getOptions().SerializeStdlibWithOwnershipWithOpts) {
if (P.getOptions().EnableOSSAModules) {
P.addCopyPropagation();
P.addSemanticARCOpts();
}
Expand Down Expand Up @@ -490,7 +489,8 @@ static void addPerfEarlyModulePassPipeline(SILPassPipelinePlan &P) {
if (P.getOptions().StopOptimizationBeforeLoweringOwnership)
return;

P.addNonStdlibNonTransparentFunctionOwnershipModelEliminator();
if (!P.getOptions().EnableOSSAModules)
P.addNonTransparentFunctionOwnershipModelEliminator();

// Start by linking in referenced functions from other modules.
P.addPerformanceSILLinker();
Expand Down Expand Up @@ -778,15 +778,13 @@ SILPassPipelinePlan::getPerformancePassPipeline(const SILOptions &Options) {
//
// FIXME: When *not* emitting a .swiftmodule, skip the high-level function
// pipeline to save compile time.
//
// NOTE: Ownership is now stripped within this function for the stdlib.
addHighLevelFunctionPipeline(P);

addHighLevelModulePipeline(P);

// Run one last copy propagation/semantic arc opts run before serialization/us
// lowering ownership.
if (P.getOptions().SerializeStdlibWithOwnershipWithOpts) {
if (P.getOptions().EnableOSSAModules) {
P.addCopyPropagation();
P.addSemanticARCOpts();
}
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ endif()

# STAGING: Temporarily avoids having to write #fileID in Swift.swiftinterface.
list(APPEND swift_stdlib_compile_flags "-Xfrontend" "-enable-experimental-concise-pound-file")
list(APPEND swift_stdlib_compile_flags "-Xfrontend" "-enable-ossa-modules")

if(SWIFT_CHECK_ESSENTIAL_STDLIB)
add_swift_target_library(swift_stdlib_essential ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB IS_STDLIB_CORE
Expand Down
4 changes: 2 additions & 2 deletions test/SIL/Serialization/shared_function_serialization.sil
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %S/Inputs/shared_function_serialization_input.swift -o %t/Swift.swiftmodule -emit-module -parse-as-library -parse-stdlib -module-link-name swiftCore -module-name Swift -O
// RUN: %target-sil-opt -enable-sil-verify-all -I %t -performance-linker -inline %s -o - | %FileCheck %s
// RUN: %target-swift-frontend %S/Inputs/shared_function_serialization_input.swift -o %t/Swift.swiftmodule -emit-module -parse-as-library -parse-stdlib -module-link-name swiftCore -module-name Swift -O -enable-ossa-modules
// RUN: %target-sil-opt -enable-sil-verify-all -I %t -performance-linker -enable-ossa-modules -inline %s -o - | %FileCheck %s

// CHECK: sil private @top_level_code
// CHECK: sil public_external [serialized] [ossa] @$ss1XVABycfC{{.*}}
Expand Down
2 changes: 1 addition & 1 deletion test/Serialization/early-serialization.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -O -module-name Swift -module-link-name swiftCore -parse-as-library -parse-stdlib -emit-module %s -o %t/Swift.swiftmodule
// RUN: %target-swift-frontend -emit-module -O -module-name Swift -module-link-name swiftCore -parse-as-library -parse-stdlib -emit-module %s -o %t/Swift.swiftmodule -enable-ossa-modules
// RUN: %target-sil-opt -enable-sil-verify-all %t/Swift.swiftmodule -emit-sorted-sil -o - | %FileCheck %s

// Test that early serialization works as expected:
Expand Down
4 changes: 2 additions & 2 deletions test/sil-func-extractor/load-serialized-sil.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %target-swift-frontend -primary-file %s -module-name Swift -g -module-link-name swiftCore -O -parse-as-library -parse-stdlib -emit-module -emit-module-path - -o /dev/null | %target-sil-func-extractor -module-name="Swift" -func='$ss1XV4testyyF' | %FileCheck %s
// RUN: %target-swift-frontend -primary-file %s -module-name Swift -g -O -parse-as-library -parse-stdlib -emit-sib -o - | %target-sil-func-extractor -module-name="Swift" -func='$ss1XV4testyyF' | %FileCheck %s -check-prefix=SIB-CHECK
// RUN: %target-swift-frontend -primary-file %s -module-name Swift -g -module-link-name swiftCore -O -parse-as-library -parse-stdlib -emit-module -emit-module-path - -enable-ossa-modules -o /dev/null | %target-sil-func-extractor -module-name="Swift" -enable-ossa-modules -func='$ss1XV4testyyF' | %FileCheck %s
// RUN: %target-swift-frontend -primary-file %s -module-name Swift -g -O -parse-as-library -parse-stdlib -emit-sib -enable-ossa-modules -o - | %target-sil-func-extractor -module-name="Swift" -enable-ossa-modules -func='$ss1XV4testyyF' | %FileCheck %s -check-prefix=SIB-CHECK

// CHECK: import Builtin
// CHECK: import Swift
Expand Down
4 changes: 2 additions & 2 deletions test/sil-opt/sil-opt.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %target-swift-frontend -primary-file %s -module-name Swift -g -module-link-name swiftCore -O -parse-as-library -parse-stdlib -emit-module -emit-module-path - -o /dev/null | %target-sil-opt -enable-sil-verify-all -module-name="Swift" -emit-sorted-sil | %FileCheck %s
// RUN: %target-swift-frontend -primary-file %s -module-name Swift -g -O -parse-as-library -parse-stdlib -emit-sib -o - | %target-sil-opt -enable-sil-verify-all -module-name="Swift" -emit-sorted-sil | %FileCheck %s -check-prefix=SIB-CHECK
// RUN: %target-swift-frontend -primary-file %s -enable-ossa-modules -module-name Swift -g -module-link-name swiftCore -O -parse-as-library -parse-stdlib -emit-module -emit-module-path - -o /dev/null | %target-sil-opt -enable-sil-verify-all -module-name="Swift" -emit-sorted-sil | %FileCheck %s
// RUN: %target-swift-frontend -primary-file %s -enable-ossa-modules -module-name Swift -g -O -parse-as-library -parse-stdlib -emit-sib -o - | %target-sil-opt -enable-sil-verify-all -module-name="Swift" -emit-sorted-sil | %FileCheck %s -check-prefix=SIB-CHECK

// CHECK: import Builtin
// CHECK: import Swift
Expand Down
7 changes: 7 additions & 0 deletions tools/sil-func-extractor/SILFunctionExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ DisableASTDump("sil-disable-ast-dump", llvm::cl::Hidden,
llvm::cl::init(false),
llvm::cl::desc("Do not dump AST."));

static llvm::cl::opt<bool> EnableOSSAModules(
"enable-ossa-modules",
llvm::cl::desc("Do we always serialize SIL in OSSA form? If "
"this is disabled we do not serialize in OSSA "
"form when optimizing."));

// This function isn't referenced outside its translation unit, but it
// can't use the "static" keyword because its address is used for
// getMainExecutable (since some platforms don't support taking the
Expand Down Expand Up @@ -247,6 +253,7 @@ int main(int argc, char **argv) {
SILOptions &Opts = Invocation.getSILOptions();
Opts.EmitVerboseSIL = EmitVerboseSIL;
Opts.EmitSortedSIL = EmitSortedSIL;
Opts.EnableOSSAModules = EnableOSSAModules;

serialization::ExtendedValidationInfo extendedInfo;
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileBufOrErr =
Expand Down
7 changes: 7 additions & 0 deletions tools/sil-opt/SILOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ static llvm::cl::opt<bool>
EnableSpeculativeDevirtualization("enable-spec-devirt",
llvm::cl::desc("Enable Speculative Devirtualization pass."));

static llvm::cl::opt<bool> EnableOSSAModules(
"enable-ossa-modules",
llvm::cl::desc("Do we always serialize SIL in OSSA form? If "
"this is disabled we do not serialize in OSSA "
"form when optimizing."));

namespace {
enum class EnforceExclusivityMode {
Unchecked, // static only
Expand Down Expand Up @@ -456,6 +462,7 @@ int main(int argc, char **argv) {

SILOpts.EnableSpeculativeDevirtualization = EnableSpeculativeDevirtualization;
SILOpts.IgnoreAlwaysInline = IgnoreAlwaysInline;
SILOpts.EnableOSSAModules = EnableOSSAModules;

serialization::ExtendedValidationInfo extendedInfo;
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileBufOrErr =
Expand Down