Skip to content

Commit 681a6c8

Browse files
authored
Merge pull request #78939 from meg-gupta/ossamoduleson
Enable serialization in OSSA
2 parents 21c4850 + 20db2a4 commit 681a6c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+182
-455
lines changed

include/swift/AST/SILOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class SILOptions {
191191
/// Do we always serialize SIL in OSSA form?
192192
///
193193
/// If this is disabled we do not serialize in OSSA form when optimizing.
194-
bool EnableOSSAModules = false;
194+
bool EnableOSSAModules = true;
195195

196196
/// Allow recompilation of a non-OSSA module to an OSSA module when imported
197197
/// from another OSSA module.

lib/DriverTool/sil_func_extractor_main.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,8 @@ struct SILFuncExtractorOptions {
118118
llvm::cl::init(false),
119119
llvm::cl::desc("Do not dump AST."));
120120

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

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

372373
symbolgraphgen::SymbolGraphOptions symbolGraphOpts;
373374

lib/DriverTool/sil_opt_main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,8 @@ struct SILOptOptions {
310310
EnableMoveInoutStackProtection = llvm::cl::opt<bool>("enable-move-inout-stack-protector",
311311
llvm::cl::desc("Enable the stack protector by moving values to temporaries."));
312312

313-
llvm::cl::opt<bool>
314-
EnableOSSAModules = llvm::cl::opt<bool>(
315-
"enable-ossa-modules",
313+
llvm::cl::opt<bool> EnableOSSAModules = llvm::cl::opt<bool>(
314+
"enable-ossa-modules", llvm::cl::init(true),
316315
llvm::cl::desc("Do we always serialize SIL in OSSA form? If "
317316
"this is disabled we do not serialize in OSSA "
318317
"form when optimizing."));
@@ -884,7 +883,7 @@ int sil_opt_main(ArrayRef<const char *> argv, void *MainAddr) {
884883
SILOpts.EnableSILOpaqueValues = options.EnableSILOpaqueValues;
885884
SILOpts.OSSACompleteLifetimes = options.EnableOSSACompleteLifetimes;
886885
SILOpts.OSSAVerifyComplete = options.EnableOSSAVerifyComplete;
887-
886+
SILOpts.StopOptimizationAfterSerialization |= options.EmitSIB;
888887
if (options.CopyPropagationState) {
889888
SILOpts.CopyPropagation = *options.CopyPropagationState;
890889
}
@@ -1059,6 +1058,7 @@ int sil_opt_main(ArrayRef<const char *> argv, void *MainAddr) {
10591058
serializationOpts.OutputPath = OutputFile;
10601059
serializationOpts.SerializeAllSIL = options.EmitSIB;
10611060
serializationOpts.IsSIB = options.EmitSIB;
1061+
serializationOpts.IsOSSA = SILOpts.EnableOSSAModules;
10621062

10631063
symbolgraphgen::SymbolGraphOptions symbolGraphOptions;
10641064

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2615,7 +2615,9 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
26152615
// If we're only emitting a module, stop optimizations once we've serialized
26162616
// the SIL for the module.
26172617
if (FEOpts.RequestedAction == FrontendOptions::ActionType::EmitModuleOnly ||
2618-
FEOpts.RequestedAction == FrontendOptions::ActionType::CompileModuleFromInterface)
2618+
FEOpts.RequestedAction ==
2619+
FrontendOptions::ActionType::CompileModuleFromInterface ||
2620+
FEOpts.RequestedAction == FrontendOptions::ActionType::EmitSIB)
26192621
Opts.StopOptimizationAfterSerialization = true;
26202622

26212623
if (Args.getLastArg(OPT_emit_empty_object_file)) {

lib/FrontendTool/FrontendTool.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,7 @@ static bool serializeSIB(SILModule *SM, const PrimarySpecificPaths &PSPs,
14091409
serializationOpts.OutputPath = moduleOutputPath;
14101410
serializationOpts.SerializeAllSIL = true;
14111411
serializationOpts.IsSIB = true;
1412+
serializationOpts.IsOSSA = Context.SILOpts.EnableOSSAModules;
14121413

14131414
symbolgraphgen::SymbolGraphOptions symbolGraphOptions;
14141415

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,15 +1011,15 @@ SILPassPipelinePlan::getPerformancePassPipeline(const SILOptions &Options) {
10111011
// importing this module.
10121012
P.addSerializeSILPass();
10131013

1014+
if (Options.StopOptimizationAfterSerialization)
1015+
return P;
1016+
10141017
if (P.getOptions().EnableOSSAModules && SILPrintFinalOSSAModule) {
10151018
addModulePrinterPipeline(P, "SIL Print Final OSSA Module");
10161019
}
10171020
// Strip any transparent functions that still have ownership.
10181021
P.addOwnershipModelEliminator();
10191022

1020-
if (Options.StopOptimizationAfterSerialization)
1021-
return P;
1022-
10231023
P.addAutodiffClosureSpecialization();
10241024

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

1085+
if (Options.StopOptimizationAfterSerialization)
1086+
return P;
1087+
10851088
// Now that we have serialized, propagate debug info.
10861089
P.addMovedAsyncVarDebugInfoPropagator();
10871090

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5858
/// describe what change you made. The content of this comment isn't important;
5959
/// it just ensures a conflict if two people change the module format.
6060
/// Don't worry about adhering to the 80-column limit for this line.
61-
const uint16_t SWIFTMODULE_VERSION_MINOR = 916; // destroy_not_escaped_closure
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 917; // ossa serialization
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,8 @@ void swift::serialization::diagnoseSerializedASTLoadFailure(
12441244
moduleBufferID);
12451245
break;
12461246
case serialization::Status::NotInOSSA:
1247-
if (Ctx.SerializationOpts.ExplicitModuleBuild) {
1247+
if (Ctx.SerializationOpts.ExplicitModuleBuild ||
1248+
Ctx.SILOpts.EnableOSSAModules) {
12481249
Ctx.Diags.diagnose(diagLoc,
12491250
diag::serialization_non_ossa_module_incompatible,
12501251
ModuleName);

stdlib/public/core/VarArgs.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ public func withVaList<R>(_ args: [CVarArg],
159159
for a in args {
160160
builder.append(a)
161161
}
162-
return _withVaList(builder, body)
162+
let result = _withVaList(builder, body)
163+
_fixLifetime(args)
164+
return result
163165
}
164166

165167
/// Invoke `body` with a C `va_list` argument derived from `builder`.

test/AutoDiff/SILOptimizer/vjp_inlining.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func caller_of_with_control_flow(x: Float) -> Float {
3131
gradient(at: x, of: with_control_flow)
3232
}
3333
// CHECK-LABEL: decision {{.*}} $s12vjp_inlining17with_control_flowyS2fFTJrSpSr
34-
// CHECK-NEXT: "reverse-mode derivative of vjp_inlining.with_control_flow(_:)" inlined into "caller_of_with_control_flow"
34+
// CHECK-NEXT: "reverse-mode derivative of vjp_inlining.with_control_flow(_:)" inlined into "reverse-mode derivative of vjp_inlining.wrapperOnWithControlFlow(x:)"
3535

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

4747
// =============================================================== //
4848
// VJPs without control-flow are not inlined into non-VJP callers

test/ModuleInterface/ossa-modules/different-modes-have-different-hashes.swift

Lines changed: 0 additions & 180 deletions
This file was deleted.

0 commit comments

Comments
 (0)