diff options
Diffstat (limited to 'llvm/tools/opt/opt.cpp')
| -rw-r--r-- | llvm/tools/opt/opt.cpp | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp index 3e5499f90b9..f55509db218 100644 --- a/llvm/tools/opt/opt.cpp +++ b/llvm/tools/opt/opt.cpp @@ -207,6 +207,11 @@ static cl::opt<bool> EnableDebugify( cl::desc( "Start the pipeline with debugify and end it with check-debugify")); +static cl::opt<bool> DebugifyEach( + "debugify-each", + cl::desc( + "Start each pass with debugify and end it with check-debugify")); + static cl::opt<bool> PrintBreakpoints("print-breakpoints-for-testing", cl::desc("Print select breakpoints location for testing")); @@ -256,6 +261,37 @@ static cl::opt<std::string> cl::desc("YAML output filename for pass remarks"), cl::value_desc("filename")); +class OptCustomPassManager : public legacy::PassManager { +public: + using super = legacy::PassManager; + + void add(Pass *P) override { + bool WrapWithDebugify = + DebugifyEach && !P->getAsImmutablePass() && !isIRPrintingPass(P); + if (!WrapWithDebugify) { + super::add(P); + return; + } + PassKind Kind = P->getPassKind(); + // TODO: Implement Debugify for BasicBlockPass, LoopPass. + switch (Kind) { + case PT_Function: + super::add(createDebugifyFunctionPass()); + super::add(P); + super::add(createCheckDebugifyFunctionPass(true)); + break; + case PT_Module: + super::add(createDebugifyModulePass()); + super::add(P); + super::add(createCheckDebugifyModulePass(true)); + break; + default: + super::add(P); + break; + } + } +}; + static inline void addPass(legacy::PassManagerBase &PM, Pass *P) { // Add the pass to the pass manager... PM.add(P); @@ -556,8 +592,8 @@ int main(int argc, char **argv) { // Create a PassManager to hold and optimize the collection of passes we are // about to build. - // - legacy::PassManager Passes; + OptCustomPassManager Passes; + bool AddOneTimeDebugifyPasses = EnableDebugify && !DebugifyEach; // Add an appropriate TargetLibraryInfo pass for the module's triple. TargetLibraryInfoImpl TLII(ModuleTriple); @@ -571,8 +607,8 @@ int main(int argc, char **argv) { Passes.add(createTargetTransformInfoWrapperPass(TM ? TM->getTargetIRAnalysis() : TargetIRAnalysis())); - if (EnableDebugify) - Passes.add(createDebugifyPass()); + if (AddOneTimeDebugifyPasses) + Passes.add(createDebugifyModulePass()); std::unique_ptr<legacy::FunctionPassManager> FPasses; if (OptLevelO0 || OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || @@ -719,8 +755,8 @@ int main(int argc, char **argv) { if (!NoVerify && !VerifyEach) Passes.add(createVerifierPass()); - if (EnableDebugify) - Passes.add(createCheckDebugifyPass()); + if (AddOneTimeDebugifyPasses) + Passes.add(createCheckDebugifyModulePass(false)); // 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 |

