diff options
Diffstat (limited to 'llvm/tools/opt/opt.cpp')
-rw-r--r-- | llvm/tools/opt/opt.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp index 98ad700409c..6e287b6c0ab 100644 --- a/llvm/tools/opt/opt.cpp +++ b/llvm/tools/opt/opt.cpp @@ -217,6 +217,11 @@ static cl::opt<bool> DebugifyEach( cl::desc( "Start each pass with debugify and end it with check-debugify")); +static cl::opt<std::string> + DebugifyExport("debugify-export", + cl::desc("Export per-pass debugify statistics to this file"), + cl::value_desc("filename"), cl::init("")); + static cl::opt<bool> PrintBreakpoints("print-breakpoints-for-testing", cl::desc("Print select breakpoints location for testing")); @@ -267,34 +272,45 @@ static cl::opt<std::string> cl::value_desc("filename")); class OptCustomPassManager : public legacy::PassManager { + DebugifyStatsMap DIStatsMap; + public: using super = legacy::PassManager; void add(Pass *P) override { + // Wrap each pass with (-check)-debugify passes if requested, making + // exceptions for passes which shouldn't see -debugify instrumentation. bool WrapWithDebugify = DebugifyEach && !P->getAsImmutablePass() && !isIRPrintingPass(P) && !isBitcodeWriterPass(P); if (!WrapWithDebugify) { super::add(P); return; } + + // Apply -debugify/-check-debugify before/after each pass and collect + // debug info loss statistics. PassKind Kind = P->getPassKind(); + StringRef Name = P->getPassName(); + // TODO: Implement Debugify for BasicBlockPass, LoopPass. switch (Kind) { case PT_Function: super::add(createDebugifyFunctionPass()); super::add(P); - super::add(createCheckDebugifyFunctionPass(true, P->getPassName())); + super::add(createCheckDebugifyFunctionPass(true, Name, &DIStatsMap)); break; case PT_Module: super::add(createDebugifyModulePass()); super::add(P); - super::add(createCheckDebugifyModulePass(true, P->getPassName())); + super::add(createCheckDebugifyModulePass(true, Name, &DIStatsMap)); break; default: super::add(P); break; } } + + const DebugifyStatsMap &getDebugifyStatsMap() const { return DIStatsMap; } }; static inline void addPass(legacy::PassManagerBase &PM, Pass *P) { @@ -839,6 +855,9 @@ int main(int argc, char **argv) { Out->os() << BOS->str(); } + if (DebugifyEach && !DebugifyExport.empty()) + exportDebugifyStats(DebugifyExport, Passes.getDebugifyStatsMap()); + // Declare success. if (!NoOutput || PrintBreakpoints) Out->keep(); |