Skip to content

Commit d373f6f

Browse files
committed
NFC: throws prediction frontend flag
1 parent 346bd23 commit d373f6f

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

include/swift/AST/SILOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ class SILOptions {
118118
/// Controls whether to run async demotion pass.
119119
bool EnableAsyncDemotion = false;
120120

121+
/// Controls whether to always assume that functions rarely throw an Error
122+
/// within the optimizer. This influences static branch prediction.
123+
bool EnableThrowsPrediction = false;
124+
121125
/// Should we run any SIL performance optimizations
122126
///
123127
/// Useful when you want to enable -O LLVM opts but not -O SIL opts.

include/swift/Option/FrontendOptions.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,11 @@ def enable_spec_devirt : Flag<["-"], "enable-spec-devirt">,
540540
def enable_async_demotion : Flag<["-"], "enable-experimental-async-demotion">,
541541
HelpText<"Enables an optimization pass to demote async functions.">;
542542

543+
def enable_throws_prediction : Flag<["-"], "enable-throws-prediction">,
544+
HelpText<"Enables optimization assumption that functions rarely throw errors.">;
545+
def disable_throws_prediction : Flag<["-"], "disable-throws-prediction">,
546+
HelpText<"Disables optimization assumption that functions rarely throw errors.">;
547+
543548
def disable_access_control : Flag<["-"], "disable-access-control">,
544549
HelpText<"Don't respect access control restrictions">;
545550
def enable_access_control : Flag<["-"], "enable-access-control">,

lib/DriverTool/sil_opt_main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ struct SILOptOptions {
289289
EnableAsyncDemotion = llvm::cl::opt<bool>("enable-async-demotion",
290290
llvm::cl::desc("Enables an optimization pass to demote async functions."));
291291

292+
llvm::cl::opt<bool>
293+
EnableThrowsPrediction = llvm::cl::opt<bool>("enable-throws-prediction",
294+
llvm::cl::desc("Enables optimization assumption that functions rarely throw errors."));
295+
292296
llvm::cl::opt<bool>
293297
EnableMoveInoutStackProtection = llvm::cl::opt<bool>("enable-move-inout-stack-protector",
294298
llvm::cl::desc("Enable the stack protector by moving values to temporaries."));
@@ -847,6 +851,7 @@ int sil_opt_main(ArrayRef<const char *> argv, void *MainAddr) {
847851

848852
SILOpts.EnableSpeculativeDevirtualization = options.EnableSpeculativeDevirtualization;
849853
SILOpts.EnableAsyncDemotion = options.EnableAsyncDemotion;
854+
SILOpts.EnableThrowsPrediction = options.EnableThrowsPrediction;
850855
SILOpts.IgnoreAlwaysInline = options.IgnoreAlwaysInline;
851856
SILOpts.EnableOSSAModules = options.EnableOSSAModules;
852857
SILOpts.EnableSILOpaqueValues = options.EnableSILOpaqueValues;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2597,6 +2597,9 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
25972597
OPT_enable_sil_opaque_values, OPT_disable_sil_opaque_values, false);
25982598
Opts.EnableSpeculativeDevirtualization |= Args.hasArg(OPT_enable_spec_devirt);
25992599
Opts.EnableAsyncDemotion |= Args.hasArg(OPT_enable_async_demotion);
2600+
Opts.EnableThrowsPrediction = Args.hasFlag(
2601+
OPT_enable_throws_prediction, OPT_disable_throws_prediction,
2602+
Opts.EnableThrowsPrediction);
26002603
Opts.EnableActorDataRaceChecks |= Args.hasFlag(
26012604
OPT_enable_actor_data_race_checks,
26022605
OPT_disable_actor_data_race_checks, /*default=*/false);

0 commit comments

Comments
 (0)