#include "llvm/Transforms/Utils/Debugify.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassInstrumentation.h"
#include "llvm/Pass.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/JSON.h"
#include <optional>
#define DEBUG_TYPE …
usingnamespacellvm;
namespace {
cl::opt<bool> Quiet("debugify-quiet",
cl::desc("Suppress verbose debugify output"));
cl::opt<uint64_t> DebugifyFunctionsLimit(
"debugify-func-limit",
cl::desc("Set max number of processed functions per pass."),
cl::init(UINT_MAX));
enum class Level { … };
cl::opt<Level> DebugifyLevel(
"debugify-level", cl::desc("Kind of debug info to add"),
cl::values(clEnumValN(Level::Locations, "locations", "Locations only"),
clEnumValN(Level::LocationsAndVariables, "location+variables",
"Locations and Variables")),
cl::init(Level::LocationsAndVariables));
raw_ostream &dbg() { … }
uint64_t getAllocSizeInBits(Module &M, Type *Ty) { … }
bool isFunctionSkipped(Function &F) { … }
Instruction *findTerminatingInstruction(BasicBlock &BB) { … }
}
bool llvm::applyDebugifyMetadata(
Module &M, iterator_range<Module::iterator> Functions, StringRef Banner,
std::function<bool(DIBuilder &DIB, Function &F)> ApplyToMF) { … }
static bool
applyDebugify(Function &F,
enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
DebugInfoPerPass *DebugInfoBeforePass = nullptr,
StringRef NameOfWrappedPass = "") { … }
static bool
applyDebugify(Module &M,
enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
DebugInfoPerPass *DebugInfoBeforePass = nullptr,
StringRef NameOfWrappedPass = "") { … }
bool llvm::stripDebugifyMetadata(Module &M) { … }
bool llvm::collectDebugInfoMetadata(Module &M,
iterator_range<Module::iterator> Functions,
DebugInfoPerPass &DebugInfoBeforePass,
StringRef Banner,
StringRef NameOfWrappedPass) { … }
static bool checkFunctions(const DebugFnMap &DIFunctionsBefore,
const DebugFnMap &DIFunctionsAfter,
StringRef NameOfWrappedPass,
StringRef FileNameFromCU, bool ShouldWriteIntoJSON,
llvm::json::Array &Bugs) { … }
static bool checkInstructions(const DebugInstMap &DILocsBefore,
const DebugInstMap &DILocsAfter,
const WeakInstValueMap &InstToDelete,
StringRef NameOfWrappedPass,
StringRef FileNameFromCU,
bool ShouldWriteIntoJSON,
llvm::json::Array &Bugs) { … }
static bool checkVars(const DebugVarMap &DIVarsBefore,
const DebugVarMap &DIVarsAfter,
StringRef NameOfWrappedPass, StringRef FileNameFromCU,
bool ShouldWriteIntoJSON, llvm::json::Array &Bugs) { … }
static void writeJSON(StringRef OrigDIVerifyBugsReportFilePath,
StringRef FileNameFromCU, StringRef NameOfWrappedPass,
llvm::json::Array &Bugs) { … }
bool llvm::checkDebugInfoMetadata(Module &M,
iterator_range<Module::iterator> Functions,
DebugInfoPerPass &DebugInfoBeforePass,
StringRef Banner, StringRef NameOfWrappedPass,
StringRef OrigDIVerifyBugsReportFilePath) { … }
namespace {
template <typename DbgValTy>
bool diagnoseMisSizedDbgValue(Module &M, DbgValTy *DbgVal) { … }
bool checkDebugifyMetadata(Module &M,
iterator_range<Module::iterator> Functions,
StringRef NameOfWrappedPass, StringRef Banner,
bool Strip, DebugifyStatsMap *StatsMap) { … }
struct DebugifyModulePass : public ModulePass { … };
struct DebugifyFunctionPass : public FunctionPass { … };
struct CheckDebugifyModulePass : public ModulePass { … };
struct CheckDebugifyFunctionPass : public FunctionPass { … };
}
void llvm::exportDebugifyStats(StringRef Path, const DebugifyStatsMap &Map) { … }
ModulePass *createDebugifyModulePass(enum DebugifyMode Mode,
llvm::StringRef NameOfWrappedPass,
DebugInfoPerPass *DebugInfoBeforePass) { … }
FunctionPass *
createDebugifyFunctionPass(enum DebugifyMode Mode,
llvm::StringRef NameOfWrappedPass,
DebugInfoPerPass *DebugInfoBeforePass) { … }
PreservedAnalyses NewPMDebugifyPass::run(Module &M, ModuleAnalysisManager &) { … }
ModulePass *createCheckDebugifyModulePass(
bool Strip, StringRef NameOfWrappedPass, DebugifyStatsMap *StatsMap,
enum DebugifyMode Mode, DebugInfoPerPass *DebugInfoBeforePass,
StringRef OrigDIVerifyBugsReportFilePath) { … }
FunctionPass *createCheckDebugifyFunctionPass(
bool Strip, StringRef NameOfWrappedPass, DebugifyStatsMap *StatsMap,
enum DebugifyMode Mode, DebugInfoPerPass *DebugInfoBeforePass,
StringRef OrigDIVerifyBugsReportFilePath) { … }
PreservedAnalyses NewPMCheckDebugifyPass::run(Module &M,
ModuleAnalysisManager &) { … }
static bool isIgnoredPass(StringRef PassID) { … }
void DebugifyEachInstrumentation::registerCallbacks(
PassInstrumentationCallbacks &PIC, ModuleAnalysisManager &MAM) { … }
char DebugifyModulePass::ID = …;
static RegisterPass<DebugifyModulePass> DM("debugify",
"Attach debug info to everything");
char CheckDebugifyModulePass::ID = …;
static RegisterPass<CheckDebugifyModulePass>
CDM("check-debugify", "Check debug info from -debugify");
char DebugifyFunctionPass::ID = …;
static RegisterPass<DebugifyFunctionPass> DF("debugify-function",
"Attach debug info to a function");
char CheckDebugifyFunctionPass::ID = …;
static RegisterPass<CheckDebugifyFunctionPass>
CDF("check-debugify-function", "Check debug info from -debugify-function");