diff --git a/llvm/tools/opt/Debugify.h b/llvm/include/llvm/Transforms/Utils/Debugify.h rename from llvm/tools/opt/Debugify.h rename to llvm/include/llvm/Transforms/Utils/Debugify.h --- a/llvm/tools/opt/Debugify.h +++ b/llvm/include/llvm/Transforms/Utils/Debugify.h @@ -10,13 +10,12 @@ /// //===----------------------------------------------------------------------===// -#ifndef LLVM_TOOLS_OPT_DEBUGIFY_H -#define LLVM_TOOLS_OPT_DEBUGIFY_H +#ifndef LLVM_TRANSFORM_UTILS_DEBUGIFY_H +#define LLVM_TRANSFORM_UTILS_DEBUGIFY_H #include "llvm/ADT/StringRef.h" #include "llvm/ADT/MapVector.h" #include "llvm/IR/PassManager.h" -#include "llvm/Support/raw_ostream.h" llvm::ModulePass *createDebugifyModulePass(); llvm::FunctionPass *createDebugifyFunctionPass(); @@ -53,9 +52,6 @@ /// Map pass names to a per-pass DebugifyStatistics instance. using DebugifyStatsMap = llvm::MapVector; -/// Export per-pass debugify statistics to the file specified by \p Path. -void exportDebugifyStats(llvm::StringRef Path, const DebugifyStatsMap &Map); - llvm::ModulePass * createCheckDebugifyModulePass(bool Strip = false, llvm::StringRef NameOfWrappedPass = "", @@ -71,4 +67,4 @@ llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM); }; -#endif // LLVM_TOOLS_OPT_DEBUGIFY_H +#endif // LLVM_TRANSFORM_UTILS_DEBUGIFY_H diff --git a/llvm/lib/Transforms/Utils/CMakeLists.txt b/llvm/lib/Transforms/Utils/CMakeLists.txt --- a/llvm/lib/Transforms/Utils/CMakeLists.txt +++ b/llvm/lib/Transforms/Utils/CMakeLists.txt @@ -11,6 +11,7 @@ CloneModule.cpp CodeExtractor.cpp CtorUtils.cpp + Debugify.cpp DemoteRegToStack.cpp EntryExitInstrumenter.cpp EscapeEnumerator.cpp diff --git a/llvm/tools/opt/Debugify.cpp b/llvm/lib/Transforms/Utils/Debugify.cpp rename from llvm/tools/opt/Debugify.cpp rename to llvm/lib/Transforms/Utils/Debugify.cpp --- a/llvm/tools/opt/Debugify.cpp +++ b/llvm/lib/Transforms/Utils/Debugify.cpp @@ -11,24 +11,16 @@ /// //===----------------------------------------------------------------------===// -#include "Debugify.h" #include "llvm/ADT/BitVector.h" #include "llvm/ADT/StringExtras.h" -#include "llvm/IR/BasicBlock.h" -#include "llvm/IR/Constants.h" #include "llvm/IR/DIBuilder.h" #include "llvm/IR/DebugInfo.h" -#include "llvm/IR/Function.h" -#include "llvm/IR/GlobalVariable.h" #include "llvm/IR/InstIterator.h" -#include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Module.h" -#include "llvm/IR/Type.h" #include "llvm/Pass.h" -#include "llvm/Support/raw_ostream.h" -#include "llvm/Transforms/IPO.h" +#include "llvm/Transforms/Utils/Debugify.h" using namespace llvm; @@ -395,27 +387,6 @@ } // end anonymous namespace -void exportDebugifyStats(llvm::StringRef Path, const DebugifyStatsMap &Map) { - std::error_code EC; - raw_fd_ostream OS{Path, EC}; - if (EC) { - errs() << "Could not open file: " << EC.message() << ", " << Path << '\n'; - return; - } - - OS << "Pass Name" << ',' << "# of missing debug values" << ',' - << "# of missing locations" << ',' << "Missing/Expected value ratio" << ',' - << "Missing/Expected location ratio" << '\n'; - for (const auto &Entry : Map) { - StringRef Pass = Entry.first; - DebugifyStatistics Stats = Entry.second; - - OS << Pass << ',' << Stats.NumDbgValuesMissing << ',' - << Stats.NumDbgLocsMissing << ',' << Stats.getMissingValueRatio() << ',' - << Stats.getEmptyLocationRatio() << '\n'; - } -} - ModulePass *createDebugifyModulePass() { return new DebugifyModulePass(); } FunctionPass *createDebugifyFunctionPass() { diff --git a/llvm/tools/opt/CMakeLists.txt b/llvm/tools/opt/CMakeLists.txt --- a/llvm/tools/opt/CMakeLists.txt +++ b/llvm/tools/opt/CMakeLists.txt @@ -27,7 +27,6 @@ add_llvm_tool(opt AnalysisWrappers.cpp BreakpointPrinter.cpp - Debugify.cpp GraphPrinters.cpp NewPMDriver.cpp PassPrinters.cpp diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp --- a/llvm/tools/opt/NewPMDriver.cpp +++ b/llvm/tools/opt/NewPMDriver.cpp @@ -13,7 +13,6 @@ //===----------------------------------------------------------------------===// #include "NewPMDriver.h" -#include "Debugify.h" #include "PassPrinters.h" #include "llvm/ADT/StringRef.h" #include "llvm/Analysis/AliasAnalysis.h" @@ -35,6 +34,7 @@ #include "llvm/Target/TargetMachine.h" #include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h" #include "llvm/Transforms/Scalar/LoopPassManager.h" +#include "llvm/Transforms/Utils/Debugify.h" using namespace llvm; using namespace opt_tool; diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp --- a/llvm/tools/opt/opt.cpp +++ b/llvm/tools/opt/opt.cpp @@ -12,7 +12,6 @@ //===----------------------------------------------------------------------===// #include "BreakpointPrinter.h" -#include "Debugify.h" #include "NewPMDriver.h" #include "PassPrinters.h" #include "llvm/ADT/Triple.h" @@ -56,6 +55,7 @@ #include "llvm/Transforms/IPO/AlwaysInliner.h" #include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/Transforms/Utils/Cloning.h" +#include "llvm/Transforms/Utils/Debugify.h" #include #include using namespace llvm; @@ -482,6 +482,27 @@ } #endif +void exportDebugifyStats(llvm::StringRef Path, const DebugifyStatsMap &Map) { + std::error_code EC; + raw_fd_ostream OS{Path, EC}; + if (EC) { + errs() << "Could not open file: " << EC.message() << ", " << Path << '\n'; + return; + } + + OS << "Pass Name" << ',' << "# of missing debug values" << ',' + << "# of missing locations" << ',' << "Missing/Expected value ratio" << ',' + << "Missing/Expected location ratio" << '\n'; + for (const auto &Entry : Map) { + StringRef Pass = Entry.first; + DebugifyStatistics Stats = Entry.second; + + OS << Pass << ',' << Stats.NumDbgValuesMissing << ',' + << Stats.NumDbgLocsMissing << ',' << Stats.getMissingValueRatio() << ',' + << Stats.getEmptyLocationRatio() << '\n'; + } +} + //===----------------------------------------------------------------------===// // main for opt //