mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[opt] Add new -enable-cmo-everything flag to enable serializing all sil, match serialization behavior of Embedded Swift.
This commit is contained in:
@@ -976,6 +976,11 @@ def EnbaleDefaultCMO : Flag<["-"], "enable-default-cmo">,
|
||||
Flags<[HelpHidden, FrontendOption]>,
|
||||
HelpText<"Perform conservative cross-module optimization">;
|
||||
|
||||
def EnbaleCMOEverything : Flag<["-"], "enable-cmo-everything">,
|
||||
Flags<[HelpHidden, FrontendOption]>,
|
||||
HelpText<"Perform cross-module optimization on everything (all APIs). "
|
||||
"This is the same level of serialization as Embedded Swift.">;
|
||||
|
||||
def CrossModuleOptimization : Flag<["-"], "cross-module-optimization">,
|
||||
Flags<[HelpHidden, FrontendOption]>,
|
||||
HelpText<"Perform cross-module optimization">;
|
||||
|
||||
@@ -2308,6 +2308,8 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
|
||||
Opts.CMOMode = CrossModuleOptimizationMode::Aggressive;
|
||||
} else if (Args.hasArg(OPT_EnbaleDefaultCMO)) {
|
||||
Opts.CMOMode = CrossModuleOptimizationMode::Default;
|
||||
} else if (Args.hasArg(OPT_EnbaleCMOEverything)) {
|
||||
Opts.CMOMode = CrossModuleOptimizationMode::Everything;
|
||||
}
|
||||
Opts.EnableStackProtection =
|
||||
Args.hasFlag(OPT_enable_stack_protector, OPT_disable_stack_protector,
|
||||
|
||||
@@ -1607,7 +1607,8 @@ static bool validateTBDIfNeeded(const CompilerInvocation &Invocation,
|
||||
}
|
||||
|
||||
// Cross-module optimization does not support TBD.
|
||||
if (Invocation.getSILOptions().CMOMode == CrossModuleOptimizationMode::Aggressive) {
|
||||
if (Invocation.getSILOptions().CMOMode == CrossModuleOptimizationMode::Aggressive ||
|
||||
Invocation.getSILOptions().CMOMode == CrossModuleOptimizationMode::Everything) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
46
test/SILOptimizer/cross-module-opt-everything.swift
Normal file
46
test/SILOptimizer/cross-module-opt-everything.swift
Normal file
@@ -0,0 +1,46 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %{python} %utils/split_file.py -o %t %s
|
||||
|
||||
// RUN: %target-swift-frontend -emit-module -o %t/Module.swiftmodule %t/Module.swift -experimental-performance-annotations -enable-cmo-everything -wmo
|
||||
// RUN: %target-swift-frontend -emit-ir %t/Main.swift -I%t -experimental-performance-annotations -enable-cmo-everything -wmo
|
||||
|
||||
|
||||
// REQUIRES: swift_in_compiler
|
||||
// REQUIRES: OS=macosx || OS=linux-gnu
|
||||
|
||||
// BEGIN Module.swift
|
||||
|
||||
@_semantics("optimize.no.crossmodule")
|
||||
private func bar<R>(count: Int, _ body: (UnsafeMutableBufferPointer<Int>) -> R) -> R {
|
||||
let pointer = UnsafeMutablePointer<Int>(bitPattern: 42)!
|
||||
let inoutBufferPointer = UnsafeMutableBufferPointer(start: pointer, count: count)
|
||||
return body(inoutBufferPointer)
|
||||
}
|
||||
|
||||
public func foo<R>(_ body: () -> R) -> R {
|
||||
bar(count: 10) { p in
|
||||
body()
|
||||
}
|
||||
}
|
||||
|
||||
public func module_func() {
|
||||
foo {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
// BEGIN Main.swift
|
||||
|
||||
import Module
|
||||
|
||||
@_noLocks
|
||||
public func test() {
|
||||
module_func()
|
||||
}
|
||||
|
||||
@_noLocks
|
||||
public func client_func() {
|
||||
foo {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user