Serialize after high level passes for -emit-sib

This commit is contained in:
Meghana Gupta
2025-01-24 16:06:37 -08:00
parent 1625001d69
commit 6f9167c29e
9 changed files with 41 additions and 32 deletions

View File

@@ -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."));
@@ -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 =
@@ -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;

View File

@@ -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."));
@@ -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;
}
@@ -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;

View File

@@ -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)) {

View File

@@ -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;

View File

@@ -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
@@ -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();

View File

@@ -10,7 +10,7 @@
sil_stage raw
import Types
// CHECK-LABEL: sil @missingParam : $@convention(thin) (SoonToBeMissing) -> () {
// CHECK-LABEL: sil [ossa] @missingParam : $@convention(thin) (SoonToBeMissing) -> () {
// CHECK-RECOVERY-NEGATIVE-NOT: sil [ossa] @missingParam
sil [ossa] @missingParam : $@convention(thin) (SoonToBeMissing) -> () {
entry(%arg : $SoonToBeMissing):

View File

@@ -12,11 +12,11 @@ import def_always_inline
// SIL-LABEL: sil public_external [serialized] [always_inline] [canonical] [ossa] @$s17def_always_inline22AlwaysInlineInitStructV1xACSb_tcfC : $@convention(method) (Bool, @thin AlwaysInlineInitStruct.Type) -> AlwaysInlineInitStruct {
// SIL-LABEL: sil @main
// SIL-LABEL: sil [ossa] @main
// SIL: [[RAW:%.+]] = global_addr @$s13always_inline3rawSbvp : $*Bool
// SIL: [[FUNC:%.+]] = function_ref @$s17def_always_inline16testAlwaysInline1xS2b_tF : $@convention(thin) (Bool) -> Bool
// SIL: [[RESULT:%.+]] = apply [[FUNC]]({{%.+}}) : $@convention(thin) (Bool) -> Bool
// SIL: store [[RESULT]] to [[RAW]] : $*Bool
// SIL: store [[RESULT]] to [trivial] [[RAW]] : $*Bool
var raw = testAlwaysInline(x: false)
// SIL: [[FUNC2:%.+]] = function_ref @$s17def_always_inline22AlwaysInlineInitStructV1xACSb_tcfC : $@convention(method) (Bool, @thin AlwaysInlineInitStruct.Type) -> AlwaysInlineInitStruct

View File

@@ -12,11 +12,11 @@ import def_noinline
// SIL-LABEL: sil public_external [serialized] [noinline] [canonical] [ossa] @$s12def_noinline18NoInlineInitStructV1xACSb_tcfC : $@convention(method) (Bool, @thin NoInlineInitStruct.Type) -> NoInlineInitStruct {
// SIL-LABEL: sil @main
// SIL-LABEL: sil [ossa] @main
// SIL: [[RAW:%.+]] = global_addr @$s8noinline3rawSbvp : $*Bool
// SIL: [[FUNC:%.+]] = function_ref @$s12def_noinline12testNoinline1xS2b_tF : $@convention(thin) (Bool) -> Bool
// SIL: [[RESULT:%.+]] = apply [[FUNC]]({{%.+}}) : $@convention(thin) (Bool) -> Bool
// SIL: store [[RESULT]] to [[RAW]] : $*Bool
// SIL: store [[RESULT]] to [trivial] [[RAW]] : $*Bool
var raw = testNoinline(x: false)
// SIL: [[FUNC2:%.+]] = function_ref @$s12def_noinline18NoInlineInitStructV1xACSb_tcfC : $@convention(method) (Bool, @thin NoInlineInitStruct.Type) -> NoInlineInitStruct

View File

@@ -16,22 +16,22 @@
// REQUIRES: swift_in_compiler
// EXTRACT-FOO-NOT: sil hidden @$s5basic1XV4testyyF : $@convention(method) (X) -> () {
// EXTRACT-FOO-NOT: sil hidden @$s5basic7VehicleC1nACSi_tcfc : $@convention(method) (Int, @guaranteed Vehicle) -> @owned Vehicle {
// EXTRACT-FOO-NOT: sil hidden @$s5basic7VehicleC3nowSiyF : $@convention(method) (@guaranteed Vehicle) -> Int {
// EXTRACT-FOO-NOT: sil [ossa] hidden @$s5basic1XV4testyyF : $@convention(method) (X) -> () {
// EXTRACT-FOO-NOT: sil [ossa] hidden @$s5basic7VehicleC1nACSi_tcfc : $@convention(method) (Int, @guaranteed Vehicle) -> @owned Vehicle {
// EXTRACT-FOO-NOT: sil [ossa] hidden @$s5basic7VehicleC3nowSiyF : $@convention(method) (@guaranteed Vehicle) -> Int {
// EXTRACT-FOO-LABEL: sil @$s5basic3fooSiyF : $@convention(thin) () -> Int {
// EXTRACT-FOO-LABEL: sil [ossa] @$s5basic3fooSiyF : $@convention(thin) () -> Int {
// EXTRACT-FOO: bb0:
// EXTRACT-FOO-NEXT: %0 = integer_literal
// EXTRACT-FOO: %[[POS:.*]] = struct $Int
// EXTRACT-FOO-NEXT: return %[[POS]] : $Int
// EXTRACT-TEST-NOT: sil hidden @$s5basic3fooSiyF : $@convention(thin) () -> Int {
// EXTRACT-TEST-NOT: sil hidden @$s5basic7VehicleC1nACSi_tcfc : $@convention(method) (Int, @guaranteed Vehicle) -> @owned Vehicle {
// EXTRACT-TEST-NOT: sil hidden @$s5basic7VehicleC3nowSiyF : $@convention(method) (@guaranteed Vehicle) -> Int {
// EXTRACT-TEST-NOT: sil [ossa] hidden @$s5basic3fooSiyF : $@convention(thin) () -> Int {
// EXTRACT-TEST-NOT: sil [ossa] hidden @$s5basic7VehicleC1nACSi_tcfc : $@convention(method) (Int, @guaranteed Vehicle) -> @owned Vehicle {
// EXTRACT-TEST-NOT: sil [ossa] hidden @$s5basic7VehicleC3nowSiyF : $@convention(method) (@guaranteed Vehicle) -> Int {
// EXTRACT-TEST-LABEL: sil @$s5basic1XV4testyyF : $@convention(method) (X) -> () {
// EXTRACT-TEST-LABEL: sil [ossa] @$s5basic1XV4testyyF : $@convention(method) (X) -> () {
// EXTRACT-TEST: bb0(%0 : $X):
// EXTRACT-TEST-NEXT: function_ref
// EXTRACT-TEST-NEXT: function_ref @$s5basic3fooSiyF : $@convention(thin) () -> Int
@@ -40,25 +40,27 @@
// EXTRACT-TEST-NEXT: return
// EXTRACT-INIT-NOT: sil @$s5basic3fooSiyF : $@convention(thin) () -> Int {
// EXTRACT-INIT-NOT: sil @$s5basic1XV4testyyF : $@convention(method) (X) -> () {
// EXTRACT-INIT-NOT: sil @$s5basic7VehicleC3nowSiyF : $@convention(method) (@owned Vehicle) -> Int {
// EXTRACT-INIT-NOT: sil [ossa] @$s5basic3fooSiyF : $@convention(thin) () -> Int {
// EXTRACT-INIT-NOT: sil [ossa] @$s5basic1XV4testyyF : $@convention(method) (X) -> () {
// EXTRACT-INIT-NOT: sil [ossa] @$s5basic7VehicleC3nowSiyF : $@convention(method) (@owned Vehicle) -> Int {
// EXTRACT-INIT-LABEL: sil @$s5basic7VehicleC1nACSi_tcfc : $@convention(method) (Int, @owned Vehicle) -> @owned Vehicle {
// EXTRACT-INIT-LABEL: sil [ossa] @$s5basic7VehicleC1nACSi_tcfc : $@convention(method) (Int, @owned Vehicle) -> @owned Vehicle {
// EXTRACT-INIT: bb0
// EXTRACT-INIT-NEXT: end_init_let_ref
// EXTRACT-INIT-NEXT: begin_borrow
// EXTRACT-INIT-NEXT: ref_element_addr
// EXTRACT-INIT-NEXT: begin_access [init] [static]
// EXTRACT-INIT-NEXT: store
// EXTRACT-INIT-NEXT: end_access
// EXTRACT-INIT-NEXT: end_borrow
// EXTRACT-INIT-NEXT: return
// EXTRACT-NOW-NOT: sil @$s5basic3fooSiyF : $@convention(thin) () -> Int {
// EXTRACT-NOW-NOT: sil @$s5basic1XV4testyyF : $@convention(method) (X) -> () {
// EXTRACT-NOW-NOT: sil @$s5basic7VehicleC1nACSi_tcfc : $@convention(method) (Int, @guaranteed Vehicle) -> @owned Vehicle {
// EXTRACT-NOW-NOT: sil [ossa] @$s5basic3fooSiyF : $@convention(thin) () -> Int {
// EXTRACT-NOW-NOT: sil [ossa] @$s5basic1XV4testyyF : $@convention(method) (X) -> () {
// EXTRACT-NOW-NOT: sil [ossa] @$s5basic7VehicleC1nACSi_tcfc : $@convention(method) (Int, @guaranteed Vehicle) -> @owned Vehicle {
// EXTRACT-NOW-LABEL: sil @$s5basic7VehicleC3nowSiyF : $@convention(method) (@guaranteed Vehicle) -> Int {
// EXTRACT-NOW-LABEL: sil [ossa] @$s5basic7VehicleC3nowSiyF : $@convention(method) (@guaranteed Vehicle) -> Int {
// EXTRACT-NOW: bb0
// EXTRACT-NOW: class_method
// EXTRACT-NOW-NEXT: apply