Skip to content

Commit 69657eb

Browse files
authored
[llc] Provide opt like verifier options (#106665)
- Support `verify-each` option. - Default behavior is verifying output only.
1 parent 0b2550f commit 69657eb

27 files changed

+48
-30
lines changed

llvm/include/llvm/Passes/CodeGenPassBuilder.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,9 @@ Error CodeGenPassBuilder<Derived, TargetMachineT>::buildPipeline(
548548
if (auto Err = derived().addMachinePasses(addPass))
549549
return std::move(Err);
550550

551+
if (!Opt.DisableVerify)
552+
addPass(MachineVerifierPass());
553+
551554
if (PrintAsm) {
552555
derived().addAsmPrinter(
553556
addPass, [this, &Out, DwoOut, FileType](MCContext &Ctx) {

llvm/test/CodeGen/AArch64/PHIElimination-crash.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# RUN: llc -mtriple=aarch64-linux-gnu -verify-machineinstrs -o /dev/null %s \
22
# RUN: -run-pass=livevars,phi-node-elimination,twoaddressinstruction \
33
# RUN: -no-phi-elim-live-out-early-exit=1 -phi-elim-split-all-critical-edges=1
4-
# RUN: llc -mtriple=aarch64-linux-gnu -verify-machineinstrs -o /dev/null %s \
4+
# RUN: llc -mtriple=aarch64-linux-gnu -verify-each -o /dev/null %s \
55
# RUN: --passes='require<live-vars>,phi-node-elimination,two-address-instruction' \
66
# RUN: -no-phi-elim-live-out-early-exit=1 -phi-elim-split-all-critical-edges=1
77

llvm/test/CodeGen/AArch64/PHIElimination-debugloc.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# RUN: -run-pass=livevars,phi-node-elimination,twoaddressinstruction \
33
# RUN: -no-phi-elim-live-out-early-exit=1 -phi-elim-split-all-critical-edges=1 \
44
# RUN: | FileCheck %s
5-
# RUN: llc -mtriple=aarch64-linux-gnu -verify-machineinstrs -o - %s \
5+
# RUN: llc -mtriple=aarch64-linux-gnu -verify-each -o - %s \
66
# RUN: --passes='require<live-vars>,phi-node-elimination,two-address-instruction' \
77
# RUN: -no-phi-elim-live-out-early-exit=1 -phi-elim-split-all-critical-edges=1 \
88
# RUN: | FileCheck %s

llvm/test/CodeGen/AArch64/statepoint-twoaddr.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
22
# RUN: llc -mtriple=aarch64-unknown-linux -run-pass=twoaddressinstruction -verify-machineinstrs %s -o - | FileCheck %s
3-
# RUN: llc -mtriple=aarch64-unknown-linux --passes=two-address-instruction %s -o - | FileCheck %s
3+
# RUN: llc -mtriple=aarch64-unknown-linux --passes=two-address-instruction -verify-each %s -o - | FileCheck %s
44
# REQUIRES: aarch64-registered-target
55

66
# Verify that the register class is correctly constrained after the twoaddress replacement

llvm/test/CodeGen/AMDGPU/GlobalISel/twoaddr-extract-dyn-v7f64.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 4
22
# RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=gfx900 -early-live-intervals -run-pass=liveintervals -run-pass=twoaddressinstruction -verify-machineinstrs -o - %s | FileCheck %s
3-
# RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=gfx900 -passes='require<live-intervals>,two-address-instruction' -o - %s | FileCheck %s
3+
# RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=gfx900 -passes='require<live-intervals>,two-address-instruction' -verify-each -o - %s | FileCheck %s
44

55
---
66
name: dyn_extract_v7f64_v_v

llvm/test/CodeGen/AMDGPU/early-lis-two-address-partial-def.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 4
22
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -run-pass=liveintervals -run-pass=twoaddressinstruction -verify-machineinstrs -o - %s | FileCheck --check-prefix=GFX90A %s
3-
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a --passes='require<live-intervals>,two-address-instruction' -o - %s | FileCheck --check-prefix=GFX90A %s
3+
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a --passes='require<live-intervals>,two-address-instruction' -verify-each -o - %s | FileCheck --check-prefix=GFX90A %s
44

55
---
66
name: aligned_partial_vgpr_64

llvm/test/CodeGen/AMDGPU/gfx10-twoaddr-fma.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: llc -mtriple=amdgcn -mcpu=gfx1010 %s -run-pass twoaddressinstruction -verify-machineinstrs -o - | FileCheck --check-prefixes=GFX10 %s
2-
# RUN: llc -mtriple=amdgcn -mcpu=gfx1010 %s --passes=two-address-instruction -o - | FileCheck --check-prefixes=GFX10 %s
2+
# RUN: llc -mtriple=amdgcn -mcpu=gfx1010 %s --passes=two-address-instruction -verify-each -o - | FileCheck --check-prefixes=GFX10 %s
33

44
# GFX10-LABEL: name: test_fmamk_reg_imm_f16
55
# GFX10: %2:vgpr_32 = IMPLICIT_DEF

llvm/test/CodeGen/AMDGPU/gfx11-twoaddr-fma.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
22
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 %s -run-pass twoaddressinstruction -verify-machineinstrs -o - | FileCheck --check-prefixes=GFX11 %s
3-
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 %s --passes=two-address-instruction -verify-machineinstrs -o - | FileCheck --check-prefixes=GFX11 %s
3+
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 %s --passes=two-address-instruction -verify-each -o - | FileCheck --check-prefixes=GFX11 %s
44

55
---
66
name: test_fmamk_reg_imm_f16

llvm/test/CodeGen/AMDGPU/phi-elimination-end-cf.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: llc -mtriple amdgcn -run-pass livevars -run-pass phi-node-elimination -verify-machineinstrs -o - %s | FileCheck %s
2-
# RUN: llc -mtriple amdgcn --passes='require<live-vars>,phi-node-elimination' -o - %s | FileCheck %s
2+
# RUN: llc -mtriple amdgcn --passes='require<live-vars>,phi-node-elimination' -verify-each -o - %s | FileCheck %s
33

44
# CHECK-LABEL: phi-cf-test
55
# CHECK: bb.0:

llvm/test/CodeGen/AMDGPU/split-mbb-lis-subrange.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 2
22
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -verify-machineinstrs -run-pass liveintervals,phi-node-elimination -o - %s | FileCheck -check-prefixes=GCN %s
3-
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 --passes='require<live-intervals>,phi-node-elimination' -o - %s | FileCheck -check-prefixes=GCN %s
3+
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 --passes='require<live-intervals>,phi-node-elimination' -verify-each -o - %s | FileCheck -check-prefixes=GCN %s
44

55
# This checks liveintervals pass verification and phi-node-elimination correctly preserves them.
66

llvm/test/CodeGen/AMDGPU/stale-livevar-in-twoaddr-pass.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: llc -mtriple=amdgcn -mcpu=gfx900 -run-pass=livevars,phi-node-elimination,twoaddressinstruction -verify-machineinstrs -o - %s | FileCheck %s
2-
# RUN: llc -mtriple=amdgcn -mcpu=gfx900 --passes='require<live-vars>,phi-node-elimination,two-address-instruction' -verify-machineinstrs -o - %s | FileCheck %s
2+
# RUN: llc -mtriple=amdgcn -mcpu=gfx900 --passes='require<live-vars>,phi-node-elimination,two-address-instruction' -verify-each -o - %s | FileCheck %s
33
# This used to fail under ASAN enabled build because we didn't update LiveVariables in SIInstrInfo::convertToThreeAddress()
44
# CHECK: _amdgpu_ps_main
55

llvm/test/CodeGen/AMDGPU/twoaddr-fma-f64.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: llc -mtriple=amdgcn -mcpu=gfx90a %s -run-pass twoaddressinstruction -verify-machineinstrs -o - | FileCheck -check-prefix=GCN %s
2-
# RUN: llc -mtriple=amdgcn -mcpu=gfx90a %s --passes=two-address-instruction -o - | FileCheck -check-prefix=GCN %s
2+
# RUN: llc -mtriple=amdgcn -mcpu=gfx90a %s --passes=two-address-instruction -verify-each -o - | FileCheck -check-prefix=GCN %s
33

44
# GCN-LABEL: name: test_fmamk_reg_imm_f64
55
# GCN: V_FMA_F64_e64 0, killed %0, 0, %2, 0, killed %1, 0, 0, implicit $mode, implicit $exec

llvm/test/CodeGen/AMDGPU/twoaddr-fma.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# RUN: llc -mtriple=amdgcn -mcpu=gfx1010 %s -run-pass twoaddressinstruction -verify-machineinstrs -o - | FileCheck --check-prefixes=GCN %s
22
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 %s -run-pass twoaddressinstruction -verify-machineinstrs -o - | FileCheck --check-prefixes=GCN %s
3-
# RUN: llc -mtriple=amdgcn -mcpu=gfx1010 %s --passes=two-address-instruction -o - | FileCheck --check-prefixes=GCN %s
4-
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 %s --passes=two-address-instruction -o - | FileCheck --check-prefixes=GCN %s
3+
# RUN: llc -mtriple=amdgcn -mcpu=gfx1010 %s --passes=two-address-instruction -verify-each -o - | FileCheck --check-prefixes=GCN %s
4+
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 %s --passes=two-address-instruction -verify-each -o - | FileCheck --check-prefixes=GCN %s
55

66
# GCN-LABEL: name: test_fmamk_reg_imm_f32
77
# GCN: %2:vgpr_32 = IMPLICIT_DEF

llvm/test/CodeGen/AMDGPU/twoaddr-mad.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: llc -mtriple=amdgcn -mcpu=gfx900 %s -run-pass twoaddressinstruction -verify-machineinstrs -o - | FileCheck -check-prefix=GCN %s
2-
# RUN: llc -mtriple=amdgcn -mcpu=gfx900 %s --passes=two-address-instruction -o - | FileCheck -check-prefix=GCN %s
2+
# RUN: llc -mtriple=amdgcn -mcpu=gfx900 %s --passes=two-address-instruction -verify-each -o - | FileCheck -check-prefix=GCN %s
33

44
# GCN-LABEL: name: test_madmk_reg_imm_f32
55
# GCN: V_MADMK_F32 killed %0.sub0, 1078523331, killed %1, implicit $mode, implicit $exec

llvm/test/CodeGen/AMDGPU/twoaddr-wmma.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 %s -run-pass twoaddressinstruction -verify-machineinstrs -o - | FileCheck -check-prefix=GCN %s
2-
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 %s --passes=two-address-instruction -o - | FileCheck -check-prefix=GCN %s
2+
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 %s --passes=two-address-instruction -verify-each -o - | FileCheck -check-prefix=GCN %s
33

44
# GCN-LABEL: name: test_v_wmma_f32_16x16x16_f16_twoaddr_w32
55
# GCN: early-clobber %2:vreg_256 = V_WMMA_F32_16X16X16_F16_threeaddr_w32 8, killed %1, 8, killed %1, 8, %0, 0, 0, implicit $exec

llvm/test/CodeGen/Hexagon/two-addr-tied-subregs.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: llc -march hexagon -run-pass livevars -run-pass twoaddressinstruction -verify-machineinstrs -o - %s | FileCheck %s
2-
# RUN: llc -march hexagon --passes='require<live-vars>,two-address-instruction' -o - %s | FileCheck %s
2+
# RUN: llc -march hexagon --passes='require<live-vars>,two-address-instruction' -verify-each -o - %s | FileCheck %s
33

44

55
###############################################################################

llvm/test/CodeGen/PowerPC/2013-07-01-PHIElimBug.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: llc -mtriple powerpc64-unknown-linux-gnu -run-pass livevars -run-pass phi-node-elimination -verify-machineinstrs -o - %s | FileCheck %s
2-
# RUN: llc -mtriple powerpc64-unknown-linux-gnu --passes='require<live-vars>,phi-node-elimination' -o - %s | FileCheck %s
2+
# RUN: llc -mtriple powerpc64-unknown-linux-gnu --passes='require<live-vars>,phi-node-elimination' -verify-each -o - %s | FileCheck %s
33

44
# This test case was originally known as
55
# test/CodeGen/PowerPC/2013-07-01-PHIElimBug.ll

llvm/test/CodeGen/PowerPC/livevars-crash1.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# RUN: -run-pass=livevars,phi-node-elimination -verify-machineinstrs | \
33
# RUN: FileCheck %s
44
# RUN: llc -mtriple powerpc64le-unknown-linux-gnu %s -o - 2>&1 \
5-
# RUN: --passes='require<live-vars>,phi-node-elimination' | \
5+
# RUN: --passes='require<live-vars>,phi-node-elimination' -verify-each | \
66
# RUN: FileCheck %s
77

88
--- |

llvm/test/CodeGen/PowerPC/livevars-crash2.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# RUN: -run-pass=livevars,phi-node-elimination -verify-machineinstrs | \
33
# RUN: FileCheck %s
44
# RUN: llc -mtriple powerpc64le-unknown-linux-gnu %s -o - 2>&1 \
5-
# RUN: --passes='require<live-vars>,phi-node-elimination' | \
5+
# RUN: --passes='require<live-vars>,phi-node-elimination' -verify-each | \
66
# RUN: FileCheck %s
77

88
--- |

llvm/test/CodeGen/X86/distancemap.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
22
# RUN: llc %s -o - -mtriple=x86_64-unknown-linux -run-pass=twoaddressinstruction -verify-machineinstrs | FileCheck %s
3-
# RUN: llc %s -o - -mtriple=x86_64-unknown-linux --passes=two-address-instruction | FileCheck %s
3+
# RUN: llc %s -o - -mtriple=x86_64-unknown-linux --passes=two-address-instruction -verify-each | FileCheck %s
44

55
# In TwoAddressInstructionPass, new instructions should be added to DistanceMap.
66
# In this case, function convertInstTo3Addr is called on the first ADD

llvm/test/CodeGen/X86/phielim-undef.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
22
# RUN: llc -mtriple=x86_64-- -verify-machineinstrs -o - %s -run-pass=livevars,phi-node-elimination,twoaddressinstruction | FileCheck %s
3-
# RUN: llc -mtriple=x86_64-- -verify-machineinstrs -o - %s --passes='require<live-vars>,phi-node-elimination,two-address-instruction' | FileCheck %s
3+
# RUN: llc -mtriple=x86_64-- -verify-machineinstrs -o - %s --passes='require<live-vars>,phi-node-elimination,two-address-instruction' -verify-each | FileCheck %s
44

55
--- |
66
@b114 = external global i16, align 1

llvm/test/CodeGen/X86/twoaddr-mul2.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
22
# RUN: llc -mtriple=x86_64-unknown -mcpu=haswell -run-pass=twoaddressinstruction -verify-machineinstrs %s -o - | FileCheck %s
3-
# RUN: llc -mtriple=x86_64-unknown -mcpu=haswell --passes=two-address-instruction -verify-machineinstrs %s -o - | FileCheck %s
3+
# RUN: llc -mtriple=x86_64-unknown -mcpu=haswell --passes=two-address-instruction -verify-each %s -o - | FileCheck %s
44

55
# Check that we don't have any uses of [[COPY]] after it is killed.
66
---

llvm/test/tools/llc/new-pm/pipeline.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# RUN: llc -mtriple=x86_64-pc-linux-gnu -x mir -passes=no-op-machine-function --print-pipeline-passes -filetype=null < %s | FileCheck %s --match-full-lines
22
# RUN: llc -mtriple=x86_64-pc-linux-gnu -x mir -passes='require<machine-dom-tree>,print<machine-dom-tree>' -print-pipeline-passes < %s | FileCheck --check-prefix=ANALYSIS %s
33

4-
# CHECK: function(machine-function(no-op-machine-function)),PrintMIRPreparePass,function(machine-function(print))
4+
# CHECK: function(machine-function(no-op-machine-function)),PrintMIRPreparePass,function(machine-function(verify,print))
55

66
# ANALYSIS: require<machine-dom-tree>,print<machine-dom-tree>
77

llvm/test/tools/llc/new-pm/verify.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# RUN: not --crash llc -mtriple=x86_64-pc-linux-gnu -debug-pass-manager -passes='module(function(machine-function(trigger-verifier-error)))' -filetype=null %s 2>&1 | FileCheck %s
1+
# RUN: not --crash llc -mtriple=x86_64-pc-linux-gnu -debug-pass-manager -passes='module(function(machine-function(trigger-verifier-error)))' -verify-each -filetype=null %s 2>&1 | FileCheck %s
22

33
# CHECK: Verifying machine function f
44
# CHECK: Broken machine function found after pass "TriggerVerifierErrorPass"

llvm/tools/llc/NewPMDriver.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
#include "llvm/CodeGen/CommandFlags.h"
1919
#include "llvm/CodeGen/MIRParser/MIRParser.h"
2020
#include "llvm/CodeGen/MIRPrinter.h"
21+
#include "llvm/CodeGen/MachineFunctionAnalysis.h"
2122
#include "llvm/CodeGen/MachineModuleInfo.h"
2223
#include "llvm/CodeGen/MachinePassManager.h"
24+
#include "llvm/CodeGen/MachineVerifier.h"
2325
#include "llvm/CodeGen/TargetPassConfig.h"
2426
#include "llvm/IR/DiagnosticInfo.h"
2527
#include "llvm/IR/DiagnosticPrinter.h"
@@ -29,7 +31,6 @@
2931
#include "llvm/IR/PassManager.h"
3032
#include "llvm/IR/Verifier.h"
3133
#include "llvm/IRReader/IRReader.h"
32-
#include "llvm/Passes/CodeGenPassBuilder.h" // TODO: Include pass headers properly.
3334
#include "llvm/Passes/PassBuilder.h"
3435
#include "llvm/Passes/StandardInstrumentations.h"
3536
#include "llvm/Support/CommandLine.h"
@@ -88,7 +89,7 @@ int llvm::compileModuleWithNewPM(
8889
StringRef Arg0, std::unique_ptr<Module> M, std::unique_ptr<MIRParser> MIR,
8990
std::unique_ptr<TargetMachine> Target, std::unique_ptr<ToolOutputFile> Out,
9091
std::unique_ptr<ToolOutputFile> DwoOut, LLVMContext &Context,
91-
const TargetLibraryInfoImpl &TLII, bool NoVerify, StringRef PassPipeline,
92+
const TargetLibraryInfoImpl &TLII, VerifierKind VK, StringRef PassPipeline,
9293
CodeGenFileType FileType) {
9394

9495
if (!PassPipeline.empty() && TargetPassConfig::hasLimitedCodeGenPipeline()) {
@@ -104,14 +105,15 @@ int llvm::compileModuleWithNewPM(
104105

105106
// Fetch options from TargetPassConfig
106107
CGPassBuilderOption Opt = getCGPassBuilderOption();
107-
Opt.DisableVerify = NoVerify;
108+
Opt.DisableVerify = VK != VerifierKind::InputOutput;
108109
Opt.DebugPM = DebugPM;
109110
Opt.RegAlloc = RegAlloc;
110111

111112
MachineModuleInfo MMI(&LLVMTM);
112113

113114
PassInstrumentationCallbacks PIC;
114-
StandardInstrumentations SI(Context, Opt.DebugPM, !NoVerify);
115+
StandardInstrumentations SI(Context, Opt.DebugPM,
116+
VK == VerifierKind::EachPass);
115117
registerCodeGenCallback(PIC, LLVMTM);
116118

117119
MachineFunctionAnalysisManager MFAM;
@@ -147,6 +149,8 @@ int llvm::compileModuleWithNewPM(
147149
ExitOnErr(PB.parsePassPipeline(MPM, PassPipeline));
148150
MPM.addPass(PrintMIRPreparePass(*OS));
149151
MachineFunctionPassManager MFPM;
152+
if (VK == VerifierKind::InputOutput)
153+
MFPM.addPass(MachineVerifierPass());
150154
MFPM.addPass(PrintMIRPass(*OS));
151155
FPM.addPass(createFunctionToMachineFunctionPassAdaptor(std::move(MFPM)));
152156
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));

llvm/tools/llc/NewPMDriver.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class ToolOutputFile;
3232
class LLVMContext;
3333
class MIRParser;
3434

35+
enum class VerifierKind { None, InputOutput, EachPass };
36+
3537
struct LLCDiagnosticHandler : public DiagnosticHandler {
3638
bool handleDiagnostics(const DiagnosticInfo &DI) override;
3739
};
@@ -42,7 +44,7 @@ int compileModuleWithNewPM(StringRef Arg0, std::unique_ptr<Module> M,
4244
std::unique_ptr<ToolOutputFile> Out,
4345
std::unique_ptr<ToolOutputFile> DwoOut,
4446
LLVMContext &Context,
45-
const TargetLibraryInfoImpl &TLII, bool NoVerify,
47+
const TargetLibraryInfoImpl &TLII, VerifierKind VK,
4648
StringRef PassPipeline, CodeGenFileType FileType);
4749
} // namespace llvm
4850

llvm/tools/llc/llc.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ static cl::opt<std::string> SplitDwarfFile(
130130
static cl::opt<bool> NoVerify("disable-verify", cl::Hidden,
131131
cl::desc("Do not verify input module"));
132132

133+
static cl::opt<bool> VerifyEach("verify-each",
134+
cl::desc("Verify after each transform"));
135+
133136
static cl::opt<bool>
134137
DisableSimplifyLibCalls("disable-simplify-libcalls",
135138
cl::desc("Disable simplify-libcalls"));
@@ -647,10 +650,16 @@ static int compileModule(char **argv, LLVMContext &Context) {
647650
WithColor::warning(errs(), argv[0])
648651
<< ": warning: ignoring -mc-relax-all because filetype != obj";
649652

653+
VerifierKind VK = VerifierKind::InputOutput;
654+
if (NoVerify)
655+
VK = VerifierKind::None;
656+
else if (VerifyEach)
657+
VK = VerifierKind::EachPass;
658+
650659
if (EnableNewPassManager || !PassPipeline.empty()) {
651660
return compileModuleWithNewPM(argv[0], std::move(M), std::move(MIR),
652661
std::move(Target), std::move(Out),
653-
std::move(DwoOut), Context, TLII, NoVerify,
662+
std::move(DwoOut), Context, TLII, VK,
654663
PassPipeline, codegen::getFileType());
655664
}
656665

0 commit comments

Comments
 (0)