Skip to content

[opt] Add new -enable-cmo-everything flag to enable serializing all sil. #70734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -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">;
Expand Down
2 changes: 2 additions & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
46 changes: 46 additions & 0 deletions test/SILOptimizer/cross-module-opt-everything.swift
Original file line number Diff line number Diff line change
@@ -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
}
}