Skip to content

Enable serialization in OSSA #78939

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 9 commits into from
Jan 31, 2025
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
2 changes: 1 addition & 1 deletion include/swift/AST/SILOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class SILOptions {
/// Do we always serialize SIL in OSSA form?
///
/// If this is disabled we do not serialize in OSSA form when optimizing.
bool EnableOSSAModules = false;
bool EnableOSSAModules = true;

/// Allow recompilation of a non-OSSA module to an OSSA module when imported
/// from another OSSA module.
Expand Down
7 changes: 4 additions & 3 deletions lib/DriverTool/sil_func_extractor_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ struct SILFuncExtractorOptions {
llvm::cl::init(false),
llvm::cl::desc("Do not dump AST."));

llvm::cl::opt<bool>
EnableOSSAModules = llvm::cl::opt<bool>(
"enable-ossa-modules",
llvm::cl::opt<bool> EnableOSSAModules = llvm::cl::opt<bool>(
"enable-ossa-modules", llvm::cl::init(true),
llvm::cl::desc("Do we always serialize SIL in OSSA form? If "
"this is disabled we do not serialize in OSSA "
"form when optimizing."));
Expand Down Expand Up @@ -277,6 +276,7 @@ int sil_func_extractor_main(ArrayRef<const char *> argv, void *MainAddr) {
Opts.EmitVerboseSIL = options.EmitVerboseSIL;
Opts.EmitSortedSIL = options.EmitSortedSIL;
Opts.EnableOSSAModules = options.EnableOSSAModules;
Opts.StopOptimizationAfterSerialization |= options.EmitSIB;

serialization::ExtendedValidationInfo extendedInfo;
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileBufOrErr =
Expand Down Expand Up @@ -368,6 +368,7 @@ int sil_func_extractor_main(ArrayRef<const char *> argv, void *MainAddr) {
serializationOpts.OutputPath = OutputFile;
serializationOpts.SerializeAllSIL = true;
serializationOpts.IsSIB = true;
serializationOpts.IsOSSA = options.EnableOSSAModules;

symbolgraphgen::SymbolGraphOptions symbolGraphOpts;

Expand Down
8 changes: 4 additions & 4 deletions lib/DriverTool/sil_opt_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,8 @@ struct SILOptOptions {
EnableMoveInoutStackProtection = llvm::cl::opt<bool>("enable-move-inout-stack-protector",
llvm::cl::desc("Enable the stack protector by moving values to temporaries."));

llvm::cl::opt<bool>
EnableOSSAModules = llvm::cl::opt<bool>(
"enable-ossa-modules",
llvm::cl::opt<bool> EnableOSSAModules = llvm::cl::opt<bool>(
"enable-ossa-modules", llvm::cl::init(true),
llvm::cl::desc("Do we always serialize SIL in OSSA form? If "
"this is disabled we do not serialize in OSSA "
"form when optimizing."));
Expand Down Expand Up @@ -884,7 +883,7 @@ int sil_opt_main(ArrayRef<const char *> argv, void *MainAddr) {
SILOpts.EnableSILOpaqueValues = options.EnableSILOpaqueValues;
SILOpts.OSSACompleteLifetimes = options.EnableOSSACompleteLifetimes;
SILOpts.OSSAVerifyComplete = options.EnableOSSAVerifyComplete;

SILOpts.StopOptimizationAfterSerialization |= options.EmitSIB;
if (options.CopyPropagationState) {
SILOpts.CopyPropagation = *options.CopyPropagationState;
}
Expand Down Expand Up @@ -1059,6 +1058,7 @@ int sil_opt_main(ArrayRef<const char *> argv, void *MainAddr) {
serializationOpts.OutputPath = OutputFile;
serializationOpts.SerializeAllSIL = options.EmitSIB;
serializationOpts.IsSIB = options.EmitSIB;
serializationOpts.IsOSSA = SILOpts.EnableOSSAModules;

symbolgraphgen::SymbolGraphOptions symbolGraphOptions;

Expand Down
4 changes: 3 additions & 1 deletion lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2615,7 +2615,9 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
// If we're only emitting a module, stop optimizations once we've serialized
// the SIL for the module.
if (FEOpts.RequestedAction == FrontendOptions::ActionType::EmitModuleOnly ||
FEOpts.RequestedAction == FrontendOptions::ActionType::CompileModuleFromInterface)
FEOpts.RequestedAction ==
FrontendOptions::ActionType::CompileModuleFromInterface ||
FEOpts.RequestedAction == FrontendOptions::ActionType::EmitSIB)
Opts.StopOptimizationAfterSerialization = true;

if (Args.getLastArg(OPT_emit_empty_object_file)) {
Expand Down
1 change: 1 addition & 0 deletions lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,7 @@ static bool serializeSIB(SILModule *SM, const PrimarySpecificPaths &PSPs,
serializationOpts.OutputPath = moduleOutputPath;
serializationOpts.SerializeAllSIL = true;
serializationOpts.IsSIB = true;
serializationOpts.IsOSSA = Context.SILOpts.EnableOSSAModules;

symbolgraphgen::SymbolGraphOptions symbolGraphOptions;

Expand Down
9 changes: 6 additions & 3 deletions lib/SILOptimizer/PassManager/PassPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,15 +1011,15 @@ SILPassPipelinePlan::getPerformancePassPipeline(const SILOptions &Options) {
// importing this module.
P.addSerializeSILPass();

if (Options.StopOptimizationAfterSerialization)
return P;

if (P.getOptions().EnableOSSAModules && SILPrintFinalOSSAModule) {
addModulePrinterPipeline(P, "SIL Print Final OSSA Module");
}
// Strip any transparent functions that still have ownership.
P.addOwnershipModelEliminator();

if (Options.StopOptimizationAfterSerialization)
return P;

P.addAutodiffClosureSpecialization();

// After serialization run the function pass pipeline to iteratively lower
Expand Down Expand Up @@ -1082,6 +1082,9 @@ SILPassPipelinePlan::getOnonePassPipeline(const SILOptions &Options) {
P.startPipeline("Serialization");
P.addSerializeSILPass();

if (Options.StopOptimizationAfterSerialization)
return P;

// Now that we have serialized, propagate debug info.
P.addMovedAsyncVarDebugInfoPropagator();

Expand Down
2 changes: 1 addition & 1 deletion lib/Serialization/ModuleFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
/// describe what change you made. The content of this comment isn't important;
/// it just ensures a conflict if two people change the module format.
/// Don't worry about adhering to the 80-column limit for this line.
const uint16_t SWIFTMODULE_VERSION_MINOR = 916; // destroy_not_escaped_closure
const uint16_t SWIFTMODULE_VERSION_MINOR = 917; // ossa serialization

/// A standard hash seed used for all string hashes in a serialized module.
///
Expand Down
3 changes: 2 additions & 1 deletion lib/Serialization/SerializedModuleLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,8 @@ void swift::serialization::diagnoseSerializedASTLoadFailure(
moduleBufferID);
break;
case serialization::Status::NotInOSSA:
if (Ctx.SerializationOpts.ExplicitModuleBuild) {
if (Ctx.SerializationOpts.ExplicitModuleBuild ||
Ctx.SILOpts.EnableOSSAModules) {
Ctx.Diags.diagnose(diagLoc,
diag::serialization_non_ossa_module_incompatible,
ModuleName);
Expand Down
4 changes: 3 additions & 1 deletion stdlib/public/core/VarArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ public func withVaList<R>(_ args: [CVarArg],
for a in args {
builder.append(a)
}
return _withVaList(builder, body)
let result = _withVaList(builder, body)
_fixLifetime(args)
return result
}

/// Invoke `body` with a C `va_list` argument derived from `builder`.
Expand Down
4 changes: 2 additions & 2 deletions test/AutoDiff/SILOptimizer/vjp_inlining.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func caller_of_with_control_flow(x: Float) -> Float {
gradient(at: x, of: with_control_flow)
}
// CHECK-LABEL: decision {{.*}} $s12vjp_inlining17with_control_flowyS2fFTJrSpSr
// CHECK-NEXT: "reverse-mode derivative of vjp_inlining.with_control_flow(_:)" inlined into "caller_of_with_control_flow"
// CHECK-NEXT: "reverse-mode derivative of vjp_inlining.with_control_flow(_:)" inlined into "reverse-mode derivative of vjp_inlining.wrapperOnWithControlFlow(x:)"

// =============================================================== //
// VJPs with control-flow are inlined into VJP callers
Expand All @@ -42,7 +42,7 @@ func wrapperOnWithControlFlow(x: Float) -> Float {
return with_control_flow(x)
}
// CHECK-LABEL: decision {{.*}} $s12vjp_inlining17with_control_flowyS2fFTJrSpSr
// CHECK-NEXT: "reverse-mode derivative of vjp_inlining.with_control_flow(_:)" inlined into "reverse-mode derivative of vjp_inlining.wrapperOnWithControlFlow(x:)"
// CHECK-NEXT: "reverse-mode derivative of vjp_inlining.with_control_flow(_:)" inlined into "caller_of_with_control_flow"

// =============================================================== //
// VJPs without control-flow are not inlined into non-VJP callers
Expand Down

This file was deleted.

Loading