]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/tools/opt/Debugify.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / tools / opt / Debugify.h
1 //===- Debugify.h - Attach synthetic debug info to everything -------------===//
2 //
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
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
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/ADT/MapVector.h"
18 #include "llvm/IR/PassManager.h"
19 #include "llvm/Support/raw_ostream.h"
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
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
59 llvm::ModulePass *
60 createCheckDebugifyModulePass(bool Strip = false,
61                               llvm::StringRef NameOfWrappedPass = "",
62                               DebugifyStatsMap *StatsMap = nullptr);
63
64 llvm::FunctionPass *
65 createCheckDebugifyFunctionPass(bool Strip = false,
66                                 llvm::StringRef NameOfWrappedPass = "",
67                                 DebugifyStatsMap *StatsMap = nullptr);
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