Index: test/DebugInfo/debugify.ll =================================================================== --- test/DebugInfo/debugify.ll +++ test/DebugInfo/debugify.ll @@ -9,6 +9,12 @@ ; RUN: opt -debugify -strip -check-debugify -S -o - < %s | \ ; RUN: FileCheck %s -check-prefix=CHECK-FAIL +; RUN: opt -enable-debugify -strip -S -o - < %s | \ +; RUN: FileCheck %s -check-prefix=CHECK-FAIL + +; RUN: env LLVM_ENABLE_DEBUGIFY=1 opt -strip -S -o - < %s | \ +; RUN: FileCheck %s -check-prefix=CHECK-FAIL + ; CHECK-LABEL: define void @foo define void @foo() { ; CHECK: ret void, !dbg ![[RET1:.*]] Index: tools/opt/Debugify.cpp =================================================================== --- tools/opt/Debugify.cpp +++ tools/opt/Debugify.cpp @@ -204,6 +204,10 @@ } // end anonymous namespace +ModulePass *createDebugifyPass() { return new DebugifyPass(); } + +ModulePass *createCheckDebugifyPass() { return new CheckDebugifyPass(); } + char DebugifyPass::ID = 0; static RegisterPass X("debugify", "Attach debug info to everything"); Index: tools/opt/opt.cpp =================================================================== --- tools/opt/opt.cpp +++ tools/opt/opt.cpp @@ -203,6 +203,11 @@ static cl::opt AnalyzeOnly("analyze", cl::desc("Only perform analysis, no optimization")); +static cl::opt EnableDebugify( + "enable-debugify", + cl::desc( + "Start the pipeline with debugify and end it with check-debugify")); + static cl::opt PrintBreakpoints("print-breakpoints-for-testing", cl::desc("Print select breakpoints location for testing")); @@ -252,6 +257,9 @@ cl::desc("YAML output filename for pass remarks"), cl::value_desc("filename")); +extern ModulePass *createDebugifyPass(); +extern ModulePass *createCheckDebugifyPass(); + static inline void addPass(legacy::PassManagerBase &PM, Pass *P) { // Add the pass to the pass manager... PM.add(P); @@ -468,6 +476,9 @@ return 1; } + if (getenv("LLVM_ENABLE_DEBUGIFY")) + EnableDebugify = true; + // If we are supposed to override the target triple or data layout, do so now. if (!TargetTriple.empty()) M->setTargetTriple(Triple::normalize(TargetTriple)); @@ -569,6 +580,9 @@ Passes.add(createTargetTransformInfoWrapperPass(TM ? TM->getTargetIRAnalysis() : TargetIRAnalysis())); + if (EnableDebugify) + Passes.add(createDebugifyPass()); + std::unique_ptr FPasses; if (OptLevelO0 || OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) { @@ -714,6 +728,9 @@ if (!NoVerify && !VerifyEach) Passes.add(createVerifierPass()); + if (EnableDebugify) + Passes.add(createCheckDebugifyPass()); + // In run twice mode, we want to make sure the output is bit-by-bit // equivalent if we run the pass manager again, so setup two buffers and // a stream to write to them. Note that llc does something similar and it Index: utils/lit/lit/llvm/config.py =================================================================== --- utils/lit/lit/llvm/config.py +++ utils/lit/lit/llvm/config.py @@ -105,6 +105,8 @@ if lit.util.pythonize_bool(breaking_checks): features.add('abi-breaking-checks') + self.with_system_environment('LLVM_ENABLE_DEBUGIFY') + def with_environment(self, variable, value, append_path=False): if append_path: # For paths, we should be able to take a list of them and process all