Skip to content

Commit dd8c715

Browse files
committed
[IRGen] Add flags to control LLVM verify-each.
Analogous to -sil-verify-all, the new flags cause LLVM verification to be run after each LLVM optimization pass.
1 parent 974767e commit dd8c715

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ class IRGenOptions {
272272
/// well-formed?
273273
unsigned Verify : 1;
274274

275+
/// Whether to verify after every optimizer change.
276+
unsigned VerifyEach : 1;
277+
275278
OptimizationMode OptMode;
276279

277280
/// Which sanitizer is turned on.
@@ -580,7 +583,7 @@ class IRGenOptions {
580583

581584
IRGenOptions()
582585
: OutputKind(IRGenOutputKind::LLVMAssemblyAfterOptimization),
583-
Verify(true), OptMode(OptimizationMode::NotSet),
586+
Verify(true), VerifyEach(false), OptMode(OptimizationMode::NotSet),
584587
Sanitizers(OptionSet<SanitizerKind>()),
585588
SanitizersWithRecoveryInstrumentation(OptionSet<SanitizerKind>()),
586589
SanitizeAddressUseODRIndicator(false), SanitizerUseStableABI(false),

include/swift/Option/FrontendOptions.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,12 @@ def disable_swift_specific_llvm_optzns : Flag<["-"], "disable-swift-specific-llv
592592
def disable_llvm_verify : Flag<["-"], "disable-llvm-verify">,
593593
HelpText<"Don't run the LLVM IR verifier.">;
594594

595+
def enable_llvm_verify_each : Flag<["-"], "enable-llvm-verify-each">,
596+
HelpText<"Run the LLVM IR verifier after every pass.">;
597+
598+
def disable_llvm_verify_each : Flag<["-"], "disable-llvm-verify-each">,
599+
HelpText<"Don't run the LLVM IR verifier after every pass.">;
600+
595601
def disable_llvm_value_names : Flag<["-"], "disable-llvm-value-names">,
596602
HelpText<"Don't add names to local values in LLVM IR">;
597603

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3235,6 +3235,9 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
32353235
if (Args.hasArg(OPT_disable_llvm_verify))
32363236
Opts.Verify = false;
32373237

3238+
Opts.VerifyEach = Args.hasFlag(OPT_enable_llvm_verify_each,
3239+
OPT_disable_llvm_verify_each, Opts.VerifyEach);
3240+
32383241
Opts.EmitStackPromotionChecks |= Args.hasArg(OPT_stack_promotion_checks);
32393242
if (const Arg *A = Args.getLastArg(OPT_stack_promotion_limit)) {
32403243
unsigned limit;

lib/IRGen/IRGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ void swift::performLLVMOptimizations(const IRGenOptions &Opts,
294294
PrintPassOpts.Indent = DebugPassStructure;
295295
PrintPassOpts.SkipAnalyses = DebugPassStructure;
296296
StandardInstrumentations SI(Module->getContext(), DebugPassStructure,
297-
/*VerifyEach*/ false, PrintPassOpts);
297+
Opts.VerifyEach, PrintPassOpts);
298298
SI.registerCallbacks(PIC, &MAM);
299299

300300
PassBuilder PB(TargetMachine, PTO, PGOOpt, &PIC);

0 commit comments

Comments
 (0)