Skip to content

Commit eef41a5

Browse files
committed
Run AMDGPUTargetVerifier within AMDGPU pipeline. Move IsValid from
Module to TargetVerify.
1 parent 8443cdd commit eef41a5

File tree

9 files changed

+17
-13
lines changed

9 files changed

+17
-13
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
904904
TheModule->getContext(),
905905
(CodeGenOpts.DebugPassManager || DebugPassStructure),
906906
CodeGenOpts.VerifyEach, PrintPassOpts);
907-
SI.registerCallbacks(PIC, &MAM);
907+
SI.registerCallbacks(PIC, &MAM, &FAM);
908908
PassBuilder PB(TM.get(), PTO, PGOOpt, &PIC);
909909

910910
// Handle the assignment tracking feature options.

llvm/include/llvm/IR/Module.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,6 @@ class LLVM_ABI Module {
211211
/// @name Constructors
212212
/// @{
213213
public:
214-
/// Is this Module valid as determined by one of the verification passes
215-
/// i.e. Lint, Verifier, TargetVerifier.
216-
bool IsValid = true;
217-
218214
/// Is this Module using intrinsics to record the position of debugging
219215
/// information, or non-intrinsic records? See IsNewDbgInfoFormat in
220216
/// \ref BasicBlock.

llvm/include/llvm/Target/TargetVerifier.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class TargetVerify {
7070
std::string Messages;
7171
raw_string_ostream MessagesStr;
7272

73+
bool IsValid = true;
74+
7375
TargetVerify(Module *Mod)
7476
: Mod(Mod), TT(Triple::normalize(Mod->getTargetTriple())),
7577
MessagesStr(Messages) {}

llvm/lib/Analysis/Lint.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ PreservedAnalyses LintPass::run(Function &F, FunctionAnalysisManager &AM) {
748748
L.visit(F);
749749
dbgs() << L.MessagesStr.str();
750750
if (!L.MessagesStr.str().empty()) {
751-
F.getParent()->IsValid = false;
751+
//F.getParent()->IsValid = false;
752752
if (LintAbortOnError)
753753
report_fatal_error(Twine("Linter found errors, aborting. (enabled by --") +
754754
LintAbortOnErrorArgName + ")",

llvm/lib/IR/Verifier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7744,7 +7744,7 @@ VerifierAnalysis::Result VerifierAnalysis::run(Function &F,
77447744
PreservedAnalyses VerifierPass::run(Module &M, ModuleAnalysisManager &AM) {
77457745
auto Res = AM.getResult<VerifierAnalysis>(M);
77467746
if (Res.IRBroken || Res.DebugInfoBroken) {
7747-
M.IsValid = false;
7747+
//M.IsValid = false;
77487748
if (VerifyAbortOnError && FatalErrors)
77497749
report_fatal_error("Broken module found, compilation aborted!");
77507750
}
@@ -7755,7 +7755,7 @@ PreservedAnalyses VerifierPass::run(Module &M, ModuleAnalysisManager &AM) {
77557755
PreservedAnalyses VerifierPass::run(Function &F, FunctionAnalysisManager &AM) {
77567756
auto res = AM.getResult<VerifierAnalysis>(F);
77577757
if (res.IRBroken) {
7758-
F.getParent()->IsValid = false;
7758+
//F.getParent()->IsValid = false;
77597759
if (VerifyAbortOnError && FatalErrors)
77607760
report_fatal_error("Broken function found, compilation aborted!");
77617761
}

llvm/lib/Passes/StandardInstrumentations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,7 @@ void VerifyInstrumentation::registerCallbacks(PassInstrumentationCallbacks &PIC,
14861486
if (FAM) {
14871487
TargetVerify TV(const_cast<Module*>(F->getParent()));
14881488
TV.run(*const_cast<Function*>(F), *FAM);
1489-
if (!F->getParent()->IsValid)
1489+
if (!TV.IsValid)
14901490
report_fatal_error(formatv("Broken function found after pass "
14911491
"\"{0}\", compilation aborted!",
14921492
P));

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#include "llvm/MC/TargetRegistry.h"
7474
#include "llvm/Passes/PassBuilder.h"
7575
#include "llvm/Support/FormatVariadic.h"
76+
#include "llvm/Target/TargetVerify/AMDGPUTargetVerifier.h"
7677
#include "llvm/Transforms/HipStdPar/HipStdPar.h"
7778
#include "llvm/Transforms/IPO.h"
7879
#include "llvm/Transforms/IPO/AlwaysInliner.h"
@@ -1227,6 +1228,8 @@ void AMDGPUPassConfig::addIRPasses() {
12271228
addPass(createLICMPass());
12281229
}
12291230

1231+
//addPass(AMDGPUTargetVerifierPass());
1232+
12301233
TargetPassConfig::addIRPasses();
12311234

12321235
// EarlyCSE is not always strong enough to clean up what LSR produces. For
@@ -1992,6 +1995,8 @@ void AMDGPUCodeGenPassBuilder::addIRPasses(AddIRPass &addPass) const {
19921995
// but EarlyCSE can do neither of them.
19931996
if (isPassEnabled(EnableScalarIRPasses))
19941997
addEarlyCSEOrGVNPass(addPass);
1998+
1999+
addPass(AMDGPUTargetVerifierPass());
19952000
}
19962001

19972002
void AMDGPUCodeGenPassBuilder::addCodeGenPrepare(AddIRPass &addPass) const {

llvm/lib/Target/AMDGPU/AMDGPUTargetVerifier.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ PreservedAnalyses AMDGPUTargetVerifierPass::run(Function &F, FunctionAnalysisMan
205205

206206
dbgs() << TV.MessagesStr.str();
207207
if (!TV.MessagesStr.str().empty()) {
208-
F.getParent()->IsValid = false;
208+
TV.IsValid = false;
209+
return PreservedAnalyses::none();
209210
}
210211

211212
return PreservedAnalyses::all();

llvm/tools/llvm-tgt-verify/llvm-tgt-verify.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ int main(int argc, char **argv) {
163163
FPM.addPass(TargetVerifierPass());
164164
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
165165

166-
MPM.run(*M, MAM);
167-
168-
if (!M->IsValid)
166+
auto PA = MPM.run(*M, MAM);
167+
auto PAC = PA.getChecker<VerifierAnalysis>();
168+
if (!PAC.preserved())
169169
return 1;
170170

171171
return 0;

0 commit comments

Comments
 (0)