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