Skip to content

Commit f7f5070

Browse files
authored
Merge pull request #70734 from zoecarver/cross-module-everything
2 parents b3890e4 + 64fa0a3 commit f7f5070

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

include/swift/Option/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,11 @@ def EnbaleDefaultCMO : Flag<["-"], "enable-default-cmo">,
976976
Flags<[HelpHidden, FrontendOption]>,
977977
HelpText<"Perform conservative cross-module optimization">;
978978

979+
def EnbaleCMOEverything : Flag<["-"], "enable-cmo-everything">,
980+
Flags<[HelpHidden, FrontendOption]>,
981+
HelpText<"Perform cross-module optimization on everything (all APIs). "
982+
"This is the same level of serialization as Embedded Swift.">;
983+
979984
def CrossModuleOptimization : Flag<["-"], "cross-module-optimization">,
980985
Flags<[HelpHidden, FrontendOption]>,
981986
HelpText<"Perform cross-module optimization">;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,6 +2300,8 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
23002300
Opts.CMOMode = CrossModuleOptimizationMode::Aggressive;
23012301
} else if (Args.hasArg(OPT_EnbaleDefaultCMO)) {
23022302
Opts.CMOMode = CrossModuleOptimizationMode::Default;
2303+
} else if (Args.hasArg(OPT_EnbaleCMOEverything)) {
2304+
Opts.CMOMode = CrossModuleOptimizationMode::Everything;
23032305
}
23042306
Opts.EnableStackProtection =
23052307
Args.hasFlag(OPT_enable_stack_protector, OPT_disable_stack_protector,

lib/FrontendTool/FrontendTool.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,8 @@ static bool validateTBDIfNeeded(const CompilerInvocation &Invocation,
16071607
}
16081608

16091609
// Cross-module optimization does not support TBD.
1610-
if (Invocation.getSILOptions().CMOMode == CrossModuleOptimizationMode::Aggressive) {
1610+
if (Invocation.getSILOptions().CMOMode == CrossModuleOptimizationMode::Aggressive ||
1611+
Invocation.getSILOptions().CMOMode == CrossModuleOptimizationMode::Everything) {
16111612
return false;
16121613
}
16131614

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %{python} %utils/split_file.py -o %t %s
3+
4+
// RUN: %target-swift-frontend -emit-module -o %t/Module.swiftmodule %t/Module.swift -experimental-performance-annotations -enable-cmo-everything -wmo
5+
// RUN: %target-swift-frontend -emit-ir %t/Main.swift -I%t -experimental-performance-annotations -enable-cmo-everything -wmo
6+
7+
8+
// REQUIRES: swift_in_compiler
9+
// REQUIRES: OS=macosx || OS=linux-gnu
10+
11+
// BEGIN Module.swift
12+
13+
@_semantics("optimize.no.crossmodule")
14+
private func bar<R>(count: Int, _ body: (UnsafeMutableBufferPointer<Int>) -> R) -> R {
15+
let pointer = UnsafeMutablePointer<Int>(bitPattern: 42)!
16+
let inoutBufferPointer = UnsafeMutableBufferPointer(start: pointer, count: count)
17+
return body(inoutBufferPointer)
18+
}
19+
20+
public func foo<R>(_ body: () -> R) -> R {
21+
bar(count: 10) { p in
22+
body()
23+
}
24+
}
25+
26+
public func module_func() {
27+
foo {
28+
return 0
29+
}
30+
}
31+
32+
// BEGIN Main.swift
33+
34+
import Module
35+
36+
@_noLocks
37+
public func test() {
38+
module_func()
39+
}
40+
41+
@_noLocks
42+
public func client_func() {
43+
foo {
44+
return 0
45+
}
46+
}

0 commit comments

Comments
 (0)