• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/ADT/MapVector.h"
19 #include "llvm/IR/PassManager.h"
20 #include "llvm/Support/raw_ostream.h"
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 
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.
getMissingValueRatioDebugifyStatistics44   float getMissingValueRatio() const {
45     return float(NumDbgValuesMissing) / float(NumDbgLocsExpected);
46   }
47 
48   /// Get the ratio of missing/expected instructions with locations.
getEmptyLocationRatioDebugifyStatistics49   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 
60 llvm::ModulePass *
61 createCheckDebugifyModulePass(bool Strip = false,
62                               llvm::StringRef NameOfWrappedPass = "",
63                               DebugifyStatsMap *StatsMap = nullptr);
64 
65 llvm::FunctionPass *
66 createCheckDebugifyFunctionPass(bool Strip = false,
67                                 llvm::StringRef NameOfWrappedPass = "",
68                                 DebugifyStatsMap *StatsMap = nullptr);
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
76