Skip to content

Commit 8c8c978

Browse files
keithvarungandhi-apple
authored andcommitted
Add -no-whole-module-optimization (#29362)
This adds an argument to allow negating `-whole-module-optimization`. This is useful for cases where it's easier to add an extra flag to your swiftc invocation rather than removing the original one.
1 parent 9febf0b commit 8c8c978

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,10 @@ def whole_module_optimization : Flag<["-"], "whole-module-optimization">,
867867
HelpText<"Optimize input files together instead of individually">,
868868
Flags<[FrontendOption, NoInteractiveOption]>;
869869

870+
def no_whole_module_optimization : Flag<["-"], "no-whole-module-optimization">,
871+
HelpText<"Disable optimizing input files together instead of individually">,
872+
Flags<[FrontendOption, NoInteractiveOption]>;
873+
870874
def enable_batch_mode : Flag<["-"], "enable-batch-mode">,
871875
Flags<[FrontendOption, NoInteractiveOption, HelpHidden]>,
872876
HelpText<"Enable combining frontend jobs into batches">;

lib/Driver/Driver.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,9 @@ static bool computeIncremental(const llvm::opt::InputArgList *ArgList,
720720
return false;
721721

722722
const char *ReasonToDisable =
723-
ArgList->hasArg(options::OPT_whole_module_optimization)
723+
ArgList->hasFlag(options::OPT_whole_module_optimization,
724+
options::OPT_no_whole_module_optimization,
725+
false)
724726
? "is not compatible with whole module optimization."
725727
: ArgList->hasArg(options::OPT_embed_bitcode)
726728
? "is not currently compatible with embedding LLVM IR bitcode."
@@ -1761,8 +1763,13 @@ Driver::computeCompilerMode(const DerivedArgList &Args,
17611763
return Inputs.empty() ? OutputInfo::Mode::REPL
17621764
: OutputInfo::Mode::Immediate;
17631765

1766+
bool UseWMO = Args.hasFlag(options::OPT_whole_module_optimization,
1767+
options::OPT_no_whole_module_optimization,
1768+
false);
1769+
17641770
const Arg *ArgRequiringSingleCompile = Args.getLastArg(
1765-
options::OPT_whole_module_optimization, options::OPT_index_file);
1771+
options::OPT_index_file,
1772+
UseWMO ? options::OPT_whole_module_optimization : llvm::opt::OptSpecifier());
17661773

17671774
BatchModeOut = Args.hasFlag(options::OPT_enable_batch_mode,
17681775
options::OPT_disable_batch_mode,
@@ -1777,8 +1784,7 @@ Driver::computeCompilerMode(const DerivedArgList &Args,
17771784
// user about this decision.
17781785
// FIXME: AST dump also doesn't work with `-index-file`, but that fix is a bit
17791786
// more complicated than this.
1780-
if (Args.hasArg(options::OPT_whole_module_optimization) &&
1781-
Args.hasArg(options::OPT_dump_ast)) {
1787+
if (UseWMO && Args.hasArg(options::OPT_dump_ast)) {
17821788
Diags.diagnose(SourceLoc(), diag::warn_ignoring_wmo);
17831789
return OutputInfo::Mode::StandardCompile;
17841790
}

test/Driver/negating_WMO.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %swiftc_driver -whole-module-optimization %S/../Inputs/empty.swift -### 2>&1 | %FileCheck -check-prefix WMO %s
4+
// WMO-NOT: -primary-file
5+
// RUN: %swiftc_driver -whole-module-optimization -no-whole-module-optimization %S/../Inputs/empty.swift -### 2>&1 | %FileCheck -check-prefix NO-WMO %s
6+
// NO-WMO: -primary-file
7+
8+
// RUN: %swiftc_driver -enable-batch-mode -whole-module-optimization -no-whole-module-optimization %S/../Inputs/empty.swift -### 2>&1 | %FileCheck -check-prefix BATCH %s
9+
// BATCH: -primary-file
10+
// BATCH-NOT: warning: ignoring '-enable-batch-mode' because '-whole-module-optimization' was also specified

0 commit comments

Comments
 (0)