Vedant Kumar | a4afd1f | 2018-07-24 00:41:28 +0000 | [diff] [blame] | 1 | //===- Debugify.h - Attach synthetic debug info to everything -------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// |
| 10 | /// \file Interface to the `debugify` synthetic debug info testing utility. |
| 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_TOOLS_OPT_DEBUGIFY_H |
| 15 | #define LLVM_TOOLS_OPT_DEBUGIFY_H |
| 16 | |
Vedant Kumar | 499e3df | 2018-07-24 00:41:29 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/StringRef.h" |
| 18 | #include "llvm/ADT/MapVector.h" |
Vedant Kumar | a4afd1f | 2018-07-24 00:41:28 +0000 | [diff] [blame] | 19 | #include "llvm/IR/PassManager.h" |
Vedant Kumar | 499e3df | 2018-07-24 00:41:29 +0000 | [diff] [blame] | 20 | #include "llvm/Support/raw_ostream.h" |
Vedant Kumar | a4afd1f | 2018-07-24 00:41:28 +0000 | [diff] [blame] | 21 | |
| 22 | llvm::ModulePass *createDebugifyModulePass(); |
| 23 | llvm::FunctionPass *createDebugifyFunctionPass(); |
| 24 | |
| 25 | struct NewPMDebugifyPass : public llvm::PassInfoMixin<NewPMDebugifyPass> { |
| 26 | llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM); |
| 27 | }; |
| 28 | |
Vedant Kumar | 499e3df | 2018-07-24 00:41:29 +0000 | [diff] [blame] | 29 | /// Track how much `debugify` information has been lost. |
| 30 | struct DebugifyStatistics { |
| 31 | /// Number of missing dbg.values. |
| 32 | unsigned NumDbgValuesMissing = 0; |
| 33 | |
| 34 | /// Number of dbg.values expected. |
| 35 | unsigned NumDbgValuesExpected = 0; |
| 36 | |
| 37 | /// Number of instructions with empty debug locations. |
| 38 | unsigned NumDbgLocsMissing = 0; |
| 39 | |
| 40 | /// Number of instructions expected to have debug locations. |
| 41 | unsigned NumDbgLocsExpected = 0; |
| 42 | |
| 43 | /// Get the ratio of missing/expected dbg.values. |
| 44 | float getMissingValueRatio() const { |
| 45 | return float(NumDbgValuesMissing) / float(NumDbgLocsExpected); |
| 46 | } |
| 47 | |
| 48 | /// Get the ratio of missing/expected instructions with locations. |
| 49 | float getEmptyLocationRatio() const { |
| 50 | return float(NumDbgLocsMissing) / float(NumDbgLocsExpected); |
| 51 | } |
| 52 | }; |
| 53 | |
| 54 | /// Map pass names to a per-pass DebugifyStatistics instance. |
| 55 | using DebugifyStatsMap = llvm::MapVector<llvm::StringRef, DebugifyStatistics>; |
| 56 | |
| 57 | /// Export per-pass debugify statistics to the file specified by \p Path. |
| 58 | void exportDebugifyStats(llvm::StringRef Path, const DebugifyStatsMap &Map); |
| 59 | |
Vedant Kumar | a4afd1f | 2018-07-24 00:41:28 +0000 | [diff] [blame] | 60 | llvm::ModulePass * |
| 61 | createCheckDebugifyModulePass(bool Strip = false, |
Vedant Kumar | 499e3df | 2018-07-24 00:41:29 +0000 | [diff] [blame] | 62 | llvm::StringRef NameOfWrappedPass = "", |
| 63 | DebugifyStatsMap *StatsMap = nullptr); |
Vedant Kumar | a4afd1f | 2018-07-24 00:41:28 +0000 | [diff] [blame] | 64 | |
| 65 | llvm::FunctionPass * |
| 66 | createCheckDebugifyFunctionPass(bool Strip = false, |
Vedant Kumar | 499e3df | 2018-07-24 00:41:29 +0000 | [diff] [blame] | 67 | llvm::StringRef NameOfWrappedPass = "", |
| 68 | DebugifyStatsMap *StatsMap = nullptr); |
Vedant Kumar | a4afd1f | 2018-07-24 00:41:28 +0000 | [diff] [blame] | 69 | |
| 70 | struct NewPMCheckDebugifyPass |
| 71 | : public llvm::PassInfoMixin<NewPMCheckDebugifyPass> { |
| 72 | llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM); |
| 73 | }; |
| 74 | |
| 75 | #endif // LLVM_TOOLS_OPT_DEBUGIFY_H |