[debugify] Move the Debugify pass from tools/opt to lib/Transform/Utils

Summary:
I need to make use of this pass from a driver program that isn't opt.
Therefore this patch moves this pass into the LLVM library so that it is
available for use elsewhere.

There was one function I kept in tools/opt which is exportDebugifyStats()
this is because it's serializing the statistics into a human readable
format and this seemed more in keeping with opt than a library function

Reviewers: vsk, aprantl

Subscribers: mgorny, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D69926
This commit is contained in:
Daniel Sanders 2019-11-06 16:08:01 -08:00
parent bdeb2724f0
commit 25ee861372
6 changed files with 28 additions and 40 deletions

View File

@ -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 @@ struct DebugifyStatistics {
/// Map pass names to a per-pass DebugifyStatistics instance.
using DebugifyStatsMap = llvm::MapVector<llvm::StringRef, DebugifyStatistics>;
/// 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 @@ struct NewPMCheckDebugifyPass
llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM);
};
#endif // LLVM_TOOLS_OPT_DEBUGIFY_H
#endif // LLVM_TRANSFORM_UTILS_DEBUGIFY_H

View File

@ -11,6 +11,7 @@ add_llvm_library(LLVMTransformUtils
CloneModule.cpp
CodeExtractor.cpp
CtorUtils.cpp
Debugify.cpp
DemoteRegToStack.cpp
EntryExitInstrumenter.cpp
EscapeEnumerator.cpp

View File

@ -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 @@ private:
} // 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() {

View File

@ -27,7 +27,6 @@ set(LLVM_LINK_COMPONENTS
add_llvm_tool(opt
AnalysisWrappers.cpp
BreakpointPrinter.cpp
Debugify.cpp
GraphPrinters.cpp
NewPMDriver.cpp
PassPrinters.cpp

View File

@ -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;

View File

@ -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 <algorithm>
#include <memory>
using namespace llvm;
@ -482,6 +482,27 @@ void initializePollyPasses(llvm::PassRegistry &Registry);
}
#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
//