Skip to content

Add -no-whole-module-optimization #29362

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 2 commits into from
Jan 23, 2020
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
4 changes: 4 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,10 @@ def whole_module_optimization : Flag<["-"], "whole-module-optimization">,
HelpText<"Optimize input files together instead of individually">,
Flags<[FrontendOption, NoInteractiveOption]>;

def no_whole_module_optimization : Flag<["-"], "no-whole-module-optimization">,
HelpText<"Disable optimizing input files together instead of individually">,
Flags<[FrontendOption, NoInteractiveOption]>;

def enable_batch_mode : Flag<["-"], "enable-batch-mode">,
Flags<[FrontendOption, NoInteractiveOption, HelpHidden]>,
HelpText<"Enable combining frontend jobs into batches">;
Expand Down
14 changes: 10 additions & 4 deletions lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,9 @@ static bool computeIncremental(const llvm::opt::InputArgList *ArgList,
return false;

const char *ReasonToDisable =
ArgList->hasArg(options::OPT_whole_module_optimization)
ArgList->hasFlag(options::OPT_whole_module_optimization,
options::OPT_no_whole_module_optimization,
false)
? "is not compatible with whole module optimization."
: ArgList->hasArg(options::OPT_embed_bitcode)
? "is not currently compatible with embedding LLVM IR bitcode."
Expand Down Expand Up @@ -1755,8 +1757,13 @@ Driver::computeCompilerMode(const DerivedArgList &Args,
return Inputs.empty() ? OutputInfo::Mode::REPL
: OutputInfo::Mode::Immediate;

bool UseWMO = Args.hasFlag(options::OPT_whole_module_optimization,
options::OPT_no_whole_module_optimization,
false);

const Arg *ArgRequiringSingleCompile = Args.getLastArg(
options::OPT_whole_module_optimization, options::OPT_index_file);
options::OPT_index_file,
UseWMO ? options::OPT_whole_module_optimization : llvm::opt::OptSpecifier());

BatchModeOut = Args.hasFlag(options::OPT_enable_batch_mode,
options::OPT_disable_batch_mode,
Expand All @@ -1771,8 +1778,7 @@ Driver::computeCompilerMode(const DerivedArgList &Args,
// user about this decision.
// FIXME: AST dump also doesn't work with `-index-file`, but that fix is a bit
// more complicated than this.
if (Args.hasArg(options::OPT_whole_module_optimization) &&
Args.hasArg(options::OPT_dump_ast)) {
if (UseWMO && Args.hasArg(options::OPT_dump_ast)) {
Diags.diagnose(SourceLoc(), diag::warn_ignoring_wmo);
return OutputInfo::Mode::StandardCompile;
}
Expand Down
10 changes: 10 additions & 0 deletions test/Driver/negating_WMO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %empty-directory(%t)

// RUN: %swiftc_driver -whole-module-optimization %S/../Inputs/empty.swift -### 2>&1 | %FileCheck -check-prefix WMO %s
// WMO-NOT: -primary-file
// RUN: %swiftc_driver -whole-module-optimization -no-whole-module-optimization %S/../Inputs/empty.swift -### 2>&1 | %FileCheck -check-prefix NO-WMO %s
// NO-WMO: -primary-file

// RUN: %swiftc_driver -enable-batch-mode -whole-module-optimization -no-whole-module-optimization %S/../Inputs/empty.swift -### 2>&1 | %FileCheck -check-prefix BATCH %s
// BATCH: -primary-file
// BATCH-NOT: warning: ignoring '-enable-batch-mode' because '-whole-module-optimization' was also specified