Skip to content

Commit 6f9167c

Browse files
committed
Serialize after high level passes for -emit-sib
1 parent 1625001 commit 6f9167c

File tree

9 files changed

+41
-32
lines changed

9 files changed

+41
-32
lines changed

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

test/SIL/Serialization/Recovery/function.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
sil_stage raw
1111
import Types
1212

13-
// CHECK-LABEL: sil @missingParam : $@convention(thin) (SoonToBeMissing) -> () {
13+
// CHECK-LABEL: sil [ossa] @missingParam : $@convention(thin) (SoonToBeMissing) -> () {
1414
// CHECK-RECOVERY-NEGATIVE-NOT: sil [ossa] @missingParam
1515
sil [ossa] @missingParam : $@convention(thin) (SoonToBeMissing) -> () {
1616
entry(%arg : $SoonToBeMissing):

test/Serialization/always_inline.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import def_always_inline
1212

1313
// SIL-LABEL: sil public_external [serialized] [always_inline] [canonical] [ossa] @$s17def_always_inline22AlwaysInlineInitStructV1xACSb_tcfC : $@convention(method) (Bool, @thin AlwaysInlineInitStruct.Type) -> AlwaysInlineInitStruct {
1414

15-
// SIL-LABEL: sil @main
15+
// SIL-LABEL: sil [ossa] @main
1616
// SIL: [[RAW:%.+]] = global_addr @$s13always_inline3rawSbvp : $*Bool
1717
// SIL: [[FUNC:%.+]] = function_ref @$s17def_always_inline16testAlwaysInline1xS2b_tF : $@convention(thin) (Bool) -> Bool
1818
// SIL: [[RESULT:%.+]] = apply [[FUNC]]({{%.+}}) : $@convention(thin) (Bool) -> Bool
19-
// SIL: store [[RESULT]] to [[RAW]] : $*Bool
19+
// SIL: store [[RESULT]] to [trivial] [[RAW]] : $*Bool
2020
var raw = testAlwaysInline(x: false)
2121

2222
// SIL: [[FUNC2:%.+]] = function_ref @$s17def_always_inline22AlwaysInlineInitStructV1xACSb_tcfC : $@convention(method) (Bool, @thin AlwaysInlineInitStruct.Type) -> AlwaysInlineInitStruct

test/Serialization/noinline.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import def_noinline
1212

1313
// SIL-LABEL: sil public_external [serialized] [noinline] [canonical] [ossa] @$s12def_noinline18NoInlineInitStructV1xACSb_tcfC : $@convention(method) (Bool, @thin NoInlineInitStruct.Type) -> NoInlineInitStruct {
1414

15-
// SIL-LABEL: sil @main
15+
// SIL-LABEL: sil [ossa] @main
1616
// SIL: [[RAW:%.+]] = global_addr @$s8noinline3rawSbvp : $*Bool
1717
// SIL: [[FUNC:%.+]] = function_ref @$s12def_noinline12testNoinline1xS2b_tF : $@convention(thin) (Bool) -> Bool
1818
// SIL: [[RESULT:%.+]] = apply [[FUNC]]({{%.+}}) : $@convention(thin) (Bool) -> Bool
19-
// SIL: store [[RESULT]] to [[RAW]] : $*Bool
19+
// SIL: store [[RESULT]] to [trivial] [[RAW]] : $*Bool
2020
var raw = testNoinline(x: false)
2121

2222
// SIL: [[FUNC2:%.+]] = function_ref @$s12def_noinline18NoInlineInitStructV1xACSb_tcfC : $@convention(method) (Bool, @thin NoInlineInitStruct.Type) -> NoInlineInitStruct

test/sil-func-extractor/basic.swift

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@
1616

1717
// REQUIRES: swift_in_compiler
1818

19-
// EXTRACT-FOO-NOT: sil hidden @$s5basic1XV4testyyF : $@convention(method) (X) -> () {
20-
// EXTRACT-FOO-NOT: sil hidden @$s5basic7VehicleC1nACSi_tcfc : $@convention(method) (Int, @guaranteed Vehicle) -> @owned Vehicle {
21-
// EXTRACT-FOO-NOT: sil hidden @$s5basic7VehicleC3nowSiyF : $@convention(method) (@guaranteed Vehicle) -> Int {
19+
// EXTRACT-FOO-NOT: sil [ossa] hidden @$s5basic1XV4testyyF : $@convention(method) (X) -> () {
20+
// EXTRACT-FOO-NOT: sil [ossa] hidden @$s5basic7VehicleC1nACSi_tcfc : $@convention(method) (Int, @guaranteed Vehicle) -> @owned Vehicle {
21+
// EXTRACT-FOO-NOT: sil [ossa] hidden @$s5basic7VehicleC3nowSiyF : $@convention(method) (@guaranteed Vehicle) -> Int {
2222

23-
// EXTRACT-FOO-LABEL: sil @$s5basic3fooSiyF : $@convention(thin) () -> Int {
23+
// EXTRACT-FOO-LABEL: sil [ossa] @$s5basic3fooSiyF : $@convention(thin) () -> Int {
2424
// EXTRACT-FOO: bb0:
2525
// EXTRACT-FOO-NEXT: %0 = integer_literal
2626
// EXTRACT-FOO: %[[POS:.*]] = struct $Int
2727
// EXTRACT-FOO-NEXT: return %[[POS]] : $Int
2828

2929

30-
// EXTRACT-TEST-NOT: sil hidden @$s5basic3fooSiyF : $@convention(thin) () -> Int {
31-
// EXTRACT-TEST-NOT: sil hidden @$s5basic7VehicleC1nACSi_tcfc : $@convention(method) (Int, @guaranteed Vehicle) -> @owned Vehicle {
32-
// EXTRACT-TEST-NOT: sil hidden @$s5basic7VehicleC3nowSiyF : $@convention(method) (@guaranteed Vehicle) -> Int {
30+
// EXTRACT-TEST-NOT: sil [ossa] hidden @$s5basic3fooSiyF : $@convention(thin) () -> Int {
31+
// EXTRACT-TEST-NOT: sil [ossa] hidden @$s5basic7VehicleC1nACSi_tcfc : $@convention(method) (Int, @guaranteed Vehicle) -> @owned Vehicle {
32+
// EXTRACT-TEST-NOT: sil [ossa] hidden @$s5basic7VehicleC3nowSiyF : $@convention(method) (@guaranteed Vehicle) -> Int {
3333

34-
// EXTRACT-TEST-LABEL: sil @$s5basic1XV4testyyF : $@convention(method) (X) -> () {
34+
// EXTRACT-TEST-LABEL: sil [ossa] @$s5basic1XV4testyyF : $@convention(method) (X) -> () {
3535
// EXTRACT-TEST: bb0(%0 : $X):
3636
// EXTRACT-TEST-NEXT: function_ref
3737
// EXTRACT-TEST-NEXT: function_ref @$s5basic3fooSiyF : $@convention(thin) () -> Int
@@ -40,25 +40,27 @@
4040
// EXTRACT-TEST-NEXT: return
4141

4242

43-
// EXTRACT-INIT-NOT: sil @$s5basic3fooSiyF : $@convention(thin) () -> Int {
44-
// EXTRACT-INIT-NOT: sil @$s5basic1XV4testyyF : $@convention(method) (X) -> () {
45-
// EXTRACT-INIT-NOT: sil @$s5basic7VehicleC3nowSiyF : $@convention(method) (@owned Vehicle) -> Int {
43+
// EXTRACT-INIT-NOT: sil [ossa] @$s5basic3fooSiyF : $@convention(thin) () -> Int {
44+
// EXTRACT-INIT-NOT: sil [ossa] @$s5basic1XV4testyyF : $@convention(method) (X) -> () {
45+
// EXTRACT-INIT-NOT: sil [ossa] @$s5basic7VehicleC3nowSiyF : $@convention(method) (@owned Vehicle) -> Int {
4646

47-
// EXTRACT-INIT-LABEL: sil @$s5basic7VehicleC1nACSi_tcfc : $@convention(method) (Int, @owned Vehicle) -> @owned Vehicle {
47+
// EXTRACT-INIT-LABEL: sil [ossa] @$s5basic7VehicleC1nACSi_tcfc : $@convention(method) (Int, @owned Vehicle) -> @owned Vehicle {
4848
// EXTRACT-INIT: bb0
4949
// EXTRACT-INIT-NEXT: end_init_let_ref
50+
// EXTRACT-INIT-NEXT: begin_borrow
5051
// EXTRACT-INIT-NEXT: ref_element_addr
5152
// EXTRACT-INIT-NEXT: begin_access [init] [static]
5253
// EXTRACT-INIT-NEXT: store
5354
// EXTRACT-INIT-NEXT: end_access
55+
// EXTRACT-INIT-NEXT: end_borrow
5456
// EXTRACT-INIT-NEXT: return
5557

5658

57-
// EXTRACT-NOW-NOT: sil @$s5basic3fooSiyF : $@convention(thin) () -> Int {
58-
// EXTRACT-NOW-NOT: sil @$s5basic1XV4testyyF : $@convention(method) (X) -> () {
59-
// EXTRACT-NOW-NOT: sil @$s5basic7VehicleC1nACSi_tcfc : $@convention(method) (Int, @guaranteed Vehicle) -> @owned Vehicle {
59+
// EXTRACT-NOW-NOT: sil [ossa] @$s5basic3fooSiyF : $@convention(thin) () -> Int {
60+
// EXTRACT-NOW-NOT: sil [ossa] @$s5basic1XV4testyyF : $@convention(method) (X) -> () {
61+
// EXTRACT-NOW-NOT: sil [ossa] @$s5basic7VehicleC1nACSi_tcfc : $@convention(method) (Int, @guaranteed Vehicle) -> @owned Vehicle {
6062

61-
// EXTRACT-NOW-LABEL: sil @$s5basic7VehicleC3nowSiyF : $@convention(method) (@guaranteed Vehicle) -> Int {
63+
// EXTRACT-NOW-LABEL: sil [ossa] @$s5basic7VehicleC3nowSiyF : $@convention(method) (@guaranteed Vehicle) -> Int {
6264
// EXTRACT-NOW: bb0
6365
// EXTRACT-NOW: class_method
6466
// EXTRACT-NOW-NEXT: apply

0 commit comments

Comments
 (0)