From a60d430e31513a15a381d5af17869223958e3187 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Thu, 19 Mar 2015 22:24:17 +0000 Subject: [PATCH] Verifier: Remove the separate -verify-di pass Remove `DebugInfoVerifierLegacyPass` and the `-verify-di` pass. Instead, call into the `DebugInfoVerifier` from inside `VerifierLegacyPass::finalizeModule()`. This better matches the logic in `verifyModule()` (used by the new PassManager), avoids requiring two separate passes to verify the IR, and makes the API for "add a pass to verify the IR" simple. Note: the `-verify-debug-info` flag still works (for now, at least; eventually it might make sense to just remove it). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232772 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/Verifier.h | 13 +-------- include/llvm/InitializePasses.h | 1 - lib/CodeGen/Passes.cpp | 10 +------ lib/IR/Verifier.cpp | 34 ++--------------------- lib/LTO/LTOCodeGenerator.cpp | 1 - lib/Transforms/IPO/PassManagerBuilder.cpp | 8 ++---- lib/Transforms/Scalar/Scalar.cpp | 1 - tools/bugpoint/CrashDebugger.cpp | 1 - tools/llvm-stress/llvm-stress.cpp | 1 - tools/opt/opt.cpp | 11 ++------ 10 files changed, 9 insertions(+), 72 deletions(-) diff --git a/include/llvm/IR/Verifier.h b/include/llvm/IR/Verifier.h index 43bd123e7f4..89039d24195 100644 --- a/include/llvm/IR/Verifier.h +++ b/include/llvm/IR/Verifier.h @@ -56,20 +56,9 @@ bool verifyModule(const Module &M, raw_ostream *OS = nullptr); /// printed to stderr, and by default they are fatal. You can override that by /// passing \c false to \p FatalErrors. /// -/// Note that this creates a pass suitable for the legacy pass manager. It has nothing to do with \c VerifierPass. -FunctionPass *createVerifierPass(bool FatalErrors = true); - -/// \brief Create a debug-info verifier pass. -/// -/// Check a module for validity of debug info. This is essentially a pass -/// wrapped around the debug-info parts of \a verifyModule(). When the pass -/// detects a verification error it is always printed to stderr, and by default -/// they are fatal. You can override that by passing \c false to \p -/// FatalErrors. -/// /// Note that this creates a pass suitable for the legacy pass manager. It has /// nothing to do with \c VerifierPass. -ModulePass *createDebugInfoVerifierPass(bool FatalErrors = true); +FunctionPass *createVerifierPass(bool FatalErrors = true); class VerifierPass { bool FatalErrors; diff --git a/include/llvm/InitializePasses.h b/include/llvm/InitializePasses.h index b5ec65938b1..1d428b0a73a 100644 --- a/include/llvm/InitializePasses.h +++ b/include/llvm/InitializePasses.h @@ -106,7 +106,6 @@ void initializeDAEPass(PassRegistry&); void initializeDAHPass(PassRegistry&); void initializeDCEPass(PassRegistry&); void initializeDSEPass(PassRegistry&); -void initializeDebugInfoVerifierLegacyPassPass(PassRegistry &); void initializeDeadInstEliminationPass(PassRegistry&); void initializeDeadMachineInstructionElimPass(PassRegistry&); void initializeDelinearizationPass(PassRegistry &); diff --git a/lib/CodeGen/Passes.cpp b/lib/CodeGen/Passes.cpp index 1184525a288..b904b109952 100644 --- a/lib/CodeGen/Passes.cpp +++ b/lib/CodeGen/Passes.cpp @@ -374,10 +374,8 @@ void TargetPassConfig::addIRPasses() { // Before running any passes, run the verifier to determine if the input // coming from the front-end and/or optimizer is valid. - if (!DisableVerify) { + if (!DisableVerify) addPass(createVerifierPass()); - addPass(createDebugInfoVerifierPass()); - } // Run loop strength reduction before anything else. if (getOptLevel() != CodeGenOpt::None && !DisableLSR) { @@ -448,12 +446,6 @@ void TargetPassConfig::addCodeGenPrepare() { void TargetPassConfig::addISelPrepare() { addPreISel(); - // Need to verify DebugInfo *before* creating the stack protector analysis. - // It's a function pass, and verifying between it and its users causes a - // crash. - if (!DisableVerify) - addPass(createDebugInfoVerifierPass()); - addPass(createStackProtectorPass(TM)); if (PrintISelInput) diff --git a/lib/IR/Verifier.cpp b/lib/IR/Verifier.cpp index 219a7aa16a4..34e61dbff3e 100644 --- a/lib/IR/Verifier.cpp +++ b/lib/IR/Verifier.cpp @@ -3147,30 +3147,8 @@ struct VerifierLegacyPass : public FunctionPass { if (!V.verify(M) && FatalErrors) report_fatal_error("Broken module found, compilation aborted!"); - return false; - } - - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.setPreservesAll(); - } -}; -struct DebugInfoVerifierLegacyPass : public ModulePass { - static char ID; - - DebugInfoVerifier V; - bool FatalErrors; - - DebugInfoVerifierLegacyPass() : ModulePass(ID), FatalErrors(true) { - initializeDebugInfoVerifierLegacyPassPass(*PassRegistry::getPassRegistry()); - } - explicit DebugInfoVerifierLegacyPass(bool FatalErrors) - : ModulePass(ID), V(dbgs()), FatalErrors(FatalErrors) { - initializeDebugInfoVerifierLegacyPassPass(*PassRegistry::getPassRegistry()); - } - - bool runOnModule(Module &M) override { - if (!V.verify(M) && FatalErrors) - report_fatal_error("Broken debug info found, compilation aborted!"); + if (!DebugInfoVerifier(dbgs()).verify(M) && FatalErrors) + report_fatal_error("Broken module found, compilation aborted!"); return false; } @@ -3184,18 +3162,10 @@ struct DebugInfoVerifierLegacyPass : public ModulePass { char VerifierLegacyPass::ID = 0; INITIALIZE_PASS(VerifierLegacyPass, "verify", "Module Verifier", false, false) -char DebugInfoVerifierLegacyPass::ID = 0; -INITIALIZE_PASS(DebugInfoVerifierLegacyPass, "verify-di", "Debug Info Verifier", - false, false) - FunctionPass *llvm::createVerifierPass(bool FatalErrors) { return new VerifierLegacyPass(FatalErrors); } -ModulePass *llvm::createDebugInfoVerifierPass(bool FatalErrors) { - return new DebugInfoVerifierLegacyPass(FatalErrors); -} - PreservedAnalyses VerifierPass::run(Module &M) { if (verifyModule(M, &dbgs()) && FatalErrors) report_fatal_error("Broken module found, compilation aborted!"); diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp index 797c64941ef..a6f980b77ba 100644 --- a/lib/LTO/LTOCodeGenerator.cpp +++ b/lib/LTO/LTOCodeGenerator.cpp @@ -471,7 +471,6 @@ void LTOCodeGenerator::applyScopeRestrictions() { // Start off with a verification pass. legacy::PassManager passes; passes.add(createVerifierPass()); - passes.add(createDebugInfoVerifierPass()); // mark which symbols can not be internalized Mangler Mangler(TargetMach->getDataLayout()); diff --git a/lib/Transforms/IPO/PassManagerBuilder.cpp b/lib/Transforms/IPO/PassManagerBuilder.cpp index 46e221037ca..d28d5630fbd 100644 --- a/lib/Transforms/IPO/PassManagerBuilder.cpp +++ b/lib/Transforms/IPO/PassManagerBuilder.cpp @@ -511,10 +511,8 @@ void PassManagerBuilder::populateLTOPassManager(legacy::PassManagerBase &PM) { if (LibraryInfo) PM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo)); - if (VerifyInput) { + if (VerifyInput) PM.add(createVerifierPass()); - PM.add(createDebugInfoVerifierPass()); - } if (OptLevel > 1) addLTOOptimizationPasses(PM); @@ -527,10 +525,8 @@ void PassManagerBuilder::populateLTOPassManager(legacy::PassManagerBase &PM) { if (OptLevel != 0) addLateLTOOptimizationPasses(PM); - if (VerifyOutput) { + if (VerifyOutput) PM.add(createVerifierPass()); - PM.add(createDebugInfoVerifierPass()); - } } inline PassManagerBuilder *unwrap(LLVMPassManagerBuilderRef P) { diff --git a/lib/Transforms/Scalar/Scalar.cpp b/lib/Transforms/Scalar/Scalar.cpp index 02baab4446c..6cc8411bb5b 100644 --- a/lib/Transforms/Scalar/Scalar.cpp +++ b/lib/Transforms/Scalar/Scalar.cpp @@ -210,7 +210,6 @@ void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM) { void LLVMAddVerifierPass(LLVMPassManagerRef PM) { unwrap(PM)->add(createVerifierPass()); - // FIXME: should this also add createDebugInfoVerifierPass()? } void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM) { diff --git a/tools/bugpoint/CrashDebugger.cpp b/tools/bugpoint/CrashDebugger.cpp index ee18169923e..f9f3f1001d2 100644 --- a/tools/bugpoint/CrashDebugger.cpp +++ b/tools/bugpoint/CrashDebugger.cpp @@ -409,7 +409,6 @@ bool ReduceCrashingInstructions::TestInsts(std::vector // Verify that this is still valid. legacy::PassManager Passes; Passes.add(createVerifierPass()); - Passes.add(createDebugInfoVerifierPass()); Passes.run(*M); // Try running on the hacked up program... diff --git a/tools/llvm-stress/llvm-stress.cpp b/tools/llvm-stress/llvm-stress.cpp index 05ceeb592a5..f5e718ba65b 100644 --- a/tools/llvm-stress/llvm-stress.cpp +++ b/tools/llvm-stress/llvm-stress.cpp @@ -713,7 +713,6 @@ int main(int argc, char **argv) { legacy::PassManager Passes; Passes.add(createVerifierPass()); - Passes.add(createDebugInfoVerifierPass()); Passes.add(createPrintModulePass(Out->os())); Passes.run(*M.get()); Out->keep(); diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 6c27c1ecbbf..c1e120af540 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -185,10 +185,8 @@ static inline void addPass(legacy::PassManagerBase &PM, Pass *P) { PM.add(P); // If we are verifying all of the intermediate steps, add the verifier... - if (VerifyEach) { + if (VerifyEach) PM.add(createVerifierPass()); - PM.add(createDebugInfoVerifierPass()); - } } /// This routine adds optimization passes based on selected optimization level, @@ -198,8 +196,7 @@ static inline void addPass(legacy::PassManagerBase &PM, Pass *P) { static void AddOptimizationPasses(legacy::PassManagerBase &MPM, legacy::FunctionPassManager &FPM, unsigned OptLevel, unsigned SizeLevel) { - FPM.add(createVerifierPass()); // Verify that input is correct - MPM.add(createDebugInfoVerifierPass()); // Verify that debug info is correct + FPM.add(createVerifierPass()); // Verify that input is correct PassManagerBuilder Builder; Builder.OptLevel = OptLevel; @@ -558,10 +555,8 @@ int main(int argc, char **argv) { } // Check that the module is well formed on completion of optimization - if (!NoVerify && !VerifyEach) { + if (!NoVerify && !VerifyEach) Passes.add(createVerifierPass()); - Passes.add(createDebugInfoVerifierPass()); - } // Write bitcode or assembly to the output as the last step... if (!NoOutput && !AnalyzeOnly) {