diff options
author | Djordje Todorovic <djordje.todorovic@syrmia.com> | 2021-02-18 02:03:18 -0800 |
---|---|---|
committer | Djordje Todorovic <djtodoro@cisco.com> | 2021-02-18 02:04:27 -0800 |
commit | c1e23894fcf592fa5f74d9c2447f947c011f6216 (patch) | |
tree | f91577c60491205fdf2fa8557ee38022c3db0073 /llvm/lib/Transforms/Utils/Debugify.cpp | |
parent | 55d8f0d03b31e1a85b40eb95705ec4c220d80fd4 (diff) | |
download | llvm-c1e23894fcf592fa5f74d9c2447f947c011f6216.zip llvm-c1e23894fcf592fa5f74d9c2447f947c011f6216.tar.gz llvm-c1e23894fcf592fa5f74d9c2447f947c011f6216.tar.bz2 |
Revert "[Debugify] Make the debugify aware of the original (-g) Debug Info"
This reverts rG8ee7c7e02953.
One test is failing, I'll reland this as soon as possible.
Diffstat (limited to 'llvm/lib/Transforms/Utils/Debugify.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/Debugify.cpp | 371 |
1 files changed, 41 insertions, 330 deletions
diff --git a/llvm/lib/Transforms/Utils/Debugify.cpp b/llvm/lib/Transforms/Utils/Debugify.cpp index 5c7780f0..3e4d53c 100644 --- a/llvm/lib/Transforms/Utils/Debugify.cpp +++ b/llvm/lib/Transforms/Utils/Debugify.cpp @@ -1,4 +1,4 @@ -//===- Debugify.cpp - Check debug info preservation in optimizations ------===// +//===- Debugify.cpp - Attach synthetic debug info to everything -----------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,10 +6,8 @@ // //===----------------------------------------------------------------------===// /// -/// \file In the `synthetic` mode, the `-debugify` attaches synthetic debug info -/// to everything. It can be used to create targeted tests for debug info -/// preservation. In addition, when using the `original` mode, it can check -/// original debug info preservation. The `synthetic` mode is default one. +/// \file This pass attaches synthetic debug info to everything. It can be used +/// to create targeted tests for debug info preservation. /// //===----------------------------------------------------------------------===// @@ -26,8 +24,6 @@ #include "llvm/Pass.h" #include "llvm/Support/CommandLine.h" -#define DEBUG_TYPE "debugify" - using namespace llvm; namespace { @@ -39,8 +35,6 @@ enum class Level { Locations, LocationsAndVariables }; - -// Used for the synthetic mode only. cl::opt<Level> DebugifyLevel( "debugify-level", cl::desc("Kind of debug info to add"), cl::values(clEnumValN(Level::Locations, "locations", "Locations only"), @@ -205,33 +199,16 @@ bool llvm::applyDebugifyMetadata( return true; } -static bool -applyDebugify(Function &F, - enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo, - DebugInfoPerPassMap *DIPreservationMap = nullptr, - StringRef NameOfWrappedPass = "") { +static bool applyDebugify(Function &F) { Module &M = *F.getParent(); auto FuncIt = F.getIterator(); - if (Mode == DebugifyMode::SyntheticDebugInfo) - return applyDebugifyMetadata(M, make_range(FuncIt, std::next(FuncIt)), - "FunctionDebugify: ", /*ApplyToMF*/ nullptr); - assert(DIPreservationMap); - return collectDebugInfoMetadata(M, M.functions(), *DIPreservationMap, - "FunctionDebugify (original debuginfo)", - NameOfWrappedPass); + return applyDebugifyMetadata(M, make_range(FuncIt, std::next(FuncIt)), + "FunctionDebugify: ", /*ApplyToMF=*/nullptr); } -static bool -applyDebugify(Module &M, - enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo, - DebugInfoPerPassMap *DIPreservationMap = nullptr, - StringRef NameOfWrappedPass = "") { - if (Mode == DebugifyMode::SyntheticDebugInfo) - return applyDebugifyMetadata(M, M.functions(), - "ModuleDebugify: ", /*ApplyToMF*/ nullptr); - return collectDebugInfoMetadata(M, M.functions(), *DIPreservationMap, - "ModuleDebugify (original debuginfo)", - NameOfWrappedPass); +static bool applyDebugify(Module &M) { + return applyDebugifyMetadata(M, M.functions(), + "ModuleDebugify: ", /*ApplyToMF=*/nullptr); } bool llvm::stripDebugifyMetadata(Module &M) { @@ -279,211 +256,6 @@ bool llvm::stripDebugifyMetadata(Module &M) { return Changed; } -bool llvm::collectDebugInfoMetadata(Module &M, - iterator_range<Module::iterator> Functions, - DebugInfoPerPassMap &DIPreservationMap, - StringRef Banner, - StringRef NameOfWrappedPass) { - LLVM_DEBUG(dbgs() << Banner << ": (before) " << NameOfWrappedPass << '\n'); - - // Clear the map with the debug info before every single pass. - DIPreservationMap.clear(); - - if (!M.getNamedMetadata("llvm.dbg.cu")) { - dbg() << Banner << ": Skipping module without debug info\n"; - return false; - } - - // Visit each instruction. - for (Function &F : Functions) { - if (isFunctionSkipped(F)) - continue; - - // Collect the DISubprogram. - auto *SP = F.getSubprogram(); - DIPreservationMap[NameOfWrappedPass].DIFunctions.insert({F.getName(), SP}); - if (SP) - LLVM_DEBUG(dbgs() << " Collecting subprogram: " << *SP << '\n'); - - for (BasicBlock &BB : F) { - // Collect debug locations (!dbg). - // TODO: Collect dbg.values. - for (Instruction &I : BB) { - // Skip PHIs. - if (isa<PHINode>(I)) - continue; - - // Skip debug instructions. - if (isa<DbgInfoIntrinsic>(&I)) - continue; - - LLVM_DEBUG(dbgs() << " Collecting info for inst: " << I << '\n'); - DIPreservationMap[NameOfWrappedPass].InstToDelete.insert({&I, &I}); - - const DILocation *Loc = I.getDebugLoc().get(); - bool HasLoc = Loc != nullptr; - DIPreservationMap[NameOfWrappedPass].DILocations.insert({&I, HasLoc}); - } - } - } - - return true; -} - -// This checks the preservation of original debug info attached to functions. -static bool checkFunctions(const DebugFnMap &DIFunctionsBefore, - const DebugFnMap &DIFunctionsAfter, - StringRef NameOfWrappedPass, - StringRef FileNameFromCU) { - bool Preserved = true; - for (const auto &F : DIFunctionsAfter) { - if (F.second) - continue; - auto SPIt = DIFunctionsBefore.find(F.first); - if (SPIt == DIFunctionsBefore.end()) { - dbg() << "ERROR: " << NameOfWrappedPass - << " did not generate DISubprogram for " << F.first << " from " - << FileNameFromCU << '\n'; - Preserved = false; - } else { - auto SP = SPIt->second; - if (!SP) - continue; - // If the function had the SP attached before the pass, consider it as - // a debug info bug. - dbg() << "ERROR: " << NameOfWrappedPass << " dropped DISubprogram of " - << F.first << " from " << FileNameFromCU << '\n'; - Preserved = false; - } - } - - return Preserved; -} - -// This checks the preservation of the original debug info attached to -// instructions. -static bool checkInstructions(const DebugInstMap &DILocsBefore, - const DebugInstMap &DILocsAfter, - const WeakInstValueMap &InstToDelete, - StringRef NameOfWrappedPass, - StringRef FileNameFromCU) { - bool Preserved = true; - for (const auto &L : DILocsAfter) { - if (L.second) - continue; - auto Instr = L.first; - - // In order to avoid pointer reuse/recycling, skip the values that might - // have been deleted during a pass. - auto WeakInstrPtr = InstToDelete.find(Instr); - if (WeakInstrPtr != InstToDelete.end() && !WeakInstrPtr->second) - continue; - - auto FnName = Instr->getFunction()->getName(); - auto BB = Instr->getParent(); - auto BBName = BB->hasName() ? BB->getName() : "no-name"; - - auto InstrIt = DILocsBefore.find(Instr); - if (InstrIt == DILocsBefore.end()) { - dbg() << "WARNING: " << NameOfWrappedPass - << " did not generate DILocation for " << *Instr - << " (BB: " << BBName << ", Fn: " << FnName - << ", File: " << FileNameFromCU << ")\n"; - Preserved = false; - } else { - if (!InstrIt->second) - continue; - // If the instr had the !dbg attached before the pass, consider it as - // a debug info issue. - dbg() << "WARNING: " << NameOfWrappedPass << " dropped DILocation of " - << *Instr << " (BB: " << BBName << ", Fn: " << FnName - << ", File: " << FileNameFromCU << ")\n"; - Preserved = false; - } - } - - return Preserved; -} - -bool llvm::checkDebugInfoMetadata(Module &M, - iterator_range<Module::iterator> Functions, - DebugInfoPerPassMap &DIPreservationMap, - StringRef Banner, - StringRef NameOfWrappedPass) { - LLVM_DEBUG(dbgs() << Banner << ": (after) " << NameOfWrappedPass << '\n'); - - if (!M.getNamedMetadata("llvm.dbg.cu")) { - dbg() << Banner << ": Skipping module without debug info\n"; - return false; - } - - // Map the debug info holding DIs after a pass. - DebugInfoPerPassMap DIPreservationAfter; - - // Visit each instruction. - for (Function &F : Functions) { - if (isFunctionSkipped(F)) - continue; - - // TODO: Collect metadata other than DISubprograms. - // Collect the DISubprogram. - auto *SP = F.getSubprogram(); - DIPreservationAfter[NameOfWrappedPass].DIFunctions.insert({F.getName(), SP}); - if (SP) - LLVM_DEBUG(dbgs() << " Collecting subprogram: " << *SP << '\n'); - - for (BasicBlock &BB : F) { - // Collect debug locations (!dbg attachments). - // TODO: Collect dbg.values. - for (Instruction &I : BB) { - // Skip PHIs. - if (isa<PHINode>(I)) - continue; - - // Skip debug instructions. - if (isa<DbgInfoIntrinsic>(&I)) - continue; - - LLVM_DEBUG(dbgs() << " Collecting info for inst: " << I << '\n'); - - const DILocation *Loc = I.getDebugLoc().get(); - bool HasLoc = Loc != nullptr; - - DIPreservationAfter[NameOfWrappedPass].DILocations.insert({&I, HasLoc}); - } - } - } - - // TODO: The name of the module could be read better? - StringRef FileNameFromCU = - (cast<DICompileUnit>(M.getNamedMetadata("llvm.dbg.cu")->getOperand(0))) - ->getFilename(); - - auto DIFunctionsBefore = DIPreservationMap[NameOfWrappedPass].DIFunctions; - auto DIFunctionsAfter = DIPreservationAfter[NameOfWrappedPass].DIFunctions; - - auto DILocsBefore = DIPreservationMap[NameOfWrappedPass].DILocations; - auto DILocsAfter = DIPreservationAfter[NameOfWrappedPass].DILocations; - - auto InstToDelete = DIPreservationAfter[NameOfWrappedPass].InstToDelete; - - bool ResultForFunc = checkFunctions(DIFunctionsBefore, DIFunctionsAfter, - NameOfWrappedPass, FileNameFromCU); - bool ResultForInsts = - checkInstructions(DILocsBefore, DILocsAfter, InstToDelete, - NameOfWrappedPass, FileNameFromCU); - bool Result = ResultForFunc && ResultForInsts; - - StringRef ResultBanner = NameOfWrappedPass != "" ? NameOfWrappedPass : Banner; - if (Result) - dbg() << ResultBanner << ": PASS\n"; - else - dbg() << ResultBanner << ": FAIL\n"; - - LLVM_DEBUG(dbgs() << "\n\n"); - return Result; -} - namespace { /// Return true if a mis-sized diagnostic is issued for \p DVI. bool diagnoseMisSizedDbgValue(Module &M, DbgValueInst *DVI) { @@ -622,74 +394,43 @@ bool checkDebugifyMetadata(Module &M, /// ModulePass for attaching synthetic debug info to everything, used with the /// legacy module pass manager. struct DebugifyModulePass : public ModulePass { - bool runOnModule(Module &M) override { - return applyDebugify(M, Mode, DIPreservationMap, NameOfWrappedPass); - } + bool runOnModule(Module &M) override { return applyDebugify(M); } - DebugifyModulePass(enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo, - StringRef NameOfWrappedPass = "", - DebugInfoPerPassMap *DIPreservationMap = nullptr) - : ModulePass(ID), NameOfWrappedPass(NameOfWrappedPass), - DIPreservationMap(DIPreservationMap), Mode(Mode) {} + DebugifyModulePass() : ModulePass(ID) {} void getAnalysisUsage(AnalysisUsage &AU) const override { AU.setPreservesAll(); } static char ID; // Pass identification. - -private: - StringRef NameOfWrappedPass; - DebugInfoPerPassMap *DIPreservationMap; - enum DebugifyMode Mode; }; /// FunctionPass for attaching synthetic debug info to instructions within a /// single function, used with the legacy module pass manager. struct DebugifyFunctionPass : public FunctionPass { - bool runOnFunction(Function &F) override { - return applyDebugify(F, Mode, DIPreservationMap, NameOfWrappedPass); - } + bool runOnFunction(Function &F) override { return applyDebugify(F); } - DebugifyFunctionPass( - enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo, - StringRef NameOfWrappedPass = "", - DebugInfoPerPassMap *DIPreservationMap = nullptr) - : FunctionPass(ID), NameOfWrappedPass(NameOfWrappedPass), - DIPreservationMap(DIPreservationMap), Mode(Mode) {} + DebugifyFunctionPass() : FunctionPass(ID) {} void getAnalysisUsage(AnalysisUsage &AU) const override { AU.setPreservesAll(); } static char ID; // Pass identification. - -private: - StringRef NameOfWrappedPass; - DebugInfoPerPassMap *DIPreservationMap; - enum DebugifyMode Mode; }; /// ModulePass for checking debug info inserted by -debugify, used with the /// legacy module pass manager. struct CheckDebugifyModulePass : public ModulePass { bool runOnModule(Module &M) override { - if (Mode == DebugifyMode::SyntheticDebugInfo) - return checkDebugifyMetadata(M, M.functions(), NameOfWrappedPass, - "CheckModuleDebugify", Strip, StatsMap); - return checkDebugInfoMetadata( - M, M.functions(), *DIPreservationMap, - "CheckModuleDebugify (original debuginfo)", NameOfWrappedPass); + return checkDebugifyMetadata(M, M.functions(), NameOfWrappedPass, + "CheckModuleDebugify", Strip, StatsMap); } - CheckDebugifyModulePass( - bool Strip = false, StringRef NameOfWrappedPass = "", - DebugifyStatsMap *StatsMap = nullptr, - enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo, - DebugInfoPerPassMap *DIPreservationMap = nullptr) - : ModulePass(ID), NameOfWrappedPass(NameOfWrappedPass), - StatsMap(StatsMap), DIPreservationMap(DIPreservationMap), Mode(Mode), - Strip(Strip) {} + CheckDebugifyModulePass(bool Strip = false, StringRef NameOfWrappedPass = "", + DebugifyStatsMap *StatsMap = nullptr) + : ModulePass(ID), Strip(Strip), NameOfWrappedPass(NameOfWrappedPass), + StatsMap(StatsMap) {} void getAnalysisUsage(AnalysisUsage &AU) const override { AU.setPreservesAll(); @@ -698,11 +439,9 @@ struct CheckDebugifyModulePass : public ModulePass { static char ID; // Pass identification. private: + bool Strip; StringRef NameOfWrappedPass; DebugifyStatsMap *StatsMap; - DebugInfoPerPassMap *DIPreservationMap; - enum DebugifyMode Mode; - bool Strip; }; /// FunctionPass for checking debug info inserted by -debugify-function, used @@ -711,23 +450,16 @@ struct CheckDebugifyFunctionPass : public FunctionPass { bool runOnFunction(Function &F) override { Module &M = *F.getParent(); auto FuncIt = F.getIterator(); - if (Mode == DebugifyMode::SyntheticDebugInfo) - return checkDebugifyMetadata(M, make_range(FuncIt, std::next(FuncIt)), - NameOfWrappedPass, "CheckFunctionDebugify", - Strip, StatsMap); - return checkDebugInfoMetadata( - M, make_range(FuncIt, std::next(FuncIt)), *DIPreservationMap, - "CheckFunctionDebugify (original debuginfo)", NameOfWrappedPass); + return checkDebugifyMetadata(M, make_range(FuncIt, std::next(FuncIt)), + NameOfWrappedPass, "CheckFunctionDebugify", + Strip, StatsMap); } - CheckDebugifyFunctionPass( - bool Strip = false, StringRef NameOfWrappedPass = "", - DebugifyStatsMap *StatsMap = nullptr, - enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo, - DebugInfoPerPassMap *DIPreservationMap = nullptr) - : FunctionPass(ID), NameOfWrappedPass(NameOfWrappedPass), - StatsMap(StatsMap), DIPreservationMap(DIPreservationMap), Mode(Mode), - Strip(Strip) {} + CheckDebugifyFunctionPass(bool Strip = false, + StringRef NameOfWrappedPass = "", + DebugifyStatsMap *StatsMap = nullptr) + : FunctionPass(ID), Strip(Strip), NameOfWrappedPass(NameOfWrappedPass), + StatsMap(StatsMap) {} void getAnalysisUsage(AnalysisUsage &AU) const override { AU.setPreservesAll(); @@ -736,11 +468,9 @@ struct CheckDebugifyFunctionPass : public FunctionPass { static char ID; // Pass identification. private: + bool Strip; StringRef NameOfWrappedPass; DebugifyStatsMap *StatsMap; - DebugInfoPerPassMap *DIPreservationMap; - enum DebugifyMode Mode; - bool Strip; }; } // end anonymous namespace @@ -766,23 +496,12 @@ void llvm::exportDebugifyStats(StringRef Path, const DebugifyStatsMap &Map) { } } -ModulePass *createDebugifyModulePass(enum DebugifyMode Mode, - llvm::StringRef NameOfWrappedPass, - DebugInfoPerPassMap *DIPreservationMap) { - if (Mode == DebugifyMode::SyntheticDebugInfo) - return new DebugifyModulePass(); - assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode"); - return new DebugifyModulePass(Mode, NameOfWrappedPass, DIPreservationMap); +ModulePass *llvm::createDebugifyModulePass() { + return new DebugifyModulePass(); } -FunctionPass * -createDebugifyFunctionPass(enum DebugifyMode Mode, - llvm::StringRef NameOfWrappedPass, - DebugInfoPerPassMap *DIPreservationMap) { - if (Mode == DebugifyMode::SyntheticDebugInfo) - return new DebugifyFunctionPass(); - assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode"); - return new DebugifyFunctionPass(Mode, NameOfWrappedPass, DIPreservationMap); +FunctionPass *llvm::createDebugifyFunctionPass() { + return new DebugifyFunctionPass(); } PreservedAnalyses NewPMDebugifyPass::run(Module &M, ModuleAnalysisManager &) { @@ -791,24 +510,16 @@ PreservedAnalyses NewPMDebugifyPass::run(Module &M, ModuleAnalysisManager &) { return PreservedAnalyses::all(); } -ModulePass *createCheckDebugifyModulePass( - bool Strip, StringRef NameOfWrappedPass, DebugifyStatsMap *StatsMap, - enum DebugifyMode Mode, DebugInfoPerPassMap *DIPreservationMap) { - if (Mode == DebugifyMode::SyntheticDebugInfo) - return new CheckDebugifyModulePass(Strip, NameOfWrappedPass, StatsMap); - assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode"); - return new CheckDebugifyModulePass(false, NameOfWrappedPass, nullptr, Mode, - DIPreservationMap); +ModulePass *llvm::createCheckDebugifyModulePass(bool Strip, + StringRef NameOfWrappedPass, + DebugifyStatsMap *StatsMap) { + return new CheckDebugifyModulePass(Strip, NameOfWrappedPass, StatsMap); } -FunctionPass *createCheckDebugifyFunctionPass( - bool Strip, StringRef NameOfWrappedPass, DebugifyStatsMap *StatsMap, - enum DebugifyMode Mode, DebugInfoPerPassMap *DIPreservationMap) { - if (Mode == DebugifyMode::SyntheticDebugInfo) - return new CheckDebugifyFunctionPass(Strip, NameOfWrappedPass, StatsMap); - assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode"); - return new CheckDebugifyFunctionPass(false, NameOfWrappedPass, nullptr, Mode, - DIPreservationMap); +FunctionPass * +llvm::createCheckDebugifyFunctionPass(bool Strip, StringRef NameOfWrappedPass, + DebugifyStatsMap *StatsMap) { + return new CheckDebugifyFunctionPass(Strip, NameOfWrappedPass, StatsMap); } PreservedAnalyses NewPMCheckDebugifyPass::run(Module &M, |