blob: d1a60c73e7236081102696735cc7e62512320566 [file] [log] [blame]
Vedant Kumara4afd1f2018-07-24 00:41:28 +00001//===- 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 Kumar499e3df2018-07-24 00:41:29 +000017#include "llvm/ADT/StringRef.h"
18#include "llvm/ADT/MapVector.h"
Vedant Kumara4afd1f2018-07-24 00:41:28 +000019#include "llvm/IR/PassManager.h"
Vedant Kumar499e3df2018-07-24 00:41:29 +000020#include "llvm/Support/raw_ostream.h"
Vedant Kumara4afd1f2018-07-24 00:41:28 +000021
22llvm::ModulePass *createDebugifyModulePass();
23llvm::FunctionPass *createDebugifyFunctionPass();
24
25struct NewPMDebugifyPass : public llvm::PassInfoMixin<NewPMDebugifyPass> {
26 llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM);
27};
28
Vedant Kumar499e3df2018-07-24 00:41:29 +000029/// Track how much `debugify` information has been lost.
30struct 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.
55using DebugifyStatsMap = llvm::MapVector<llvm::StringRef, DebugifyStatistics>;
56
57/// Export per-pass debugify statistics to the file specified by \p Path.
58void exportDebugifyStats(llvm::StringRef Path, const DebugifyStatsMap &Map);
59
Vedant Kumara4afd1f2018-07-24 00:41:28 +000060llvm::ModulePass *
61createCheckDebugifyModulePass(bool Strip = false,
Vedant Kumar499e3df2018-07-24 00:41:29 +000062 llvm::StringRef NameOfWrappedPass = "",
63 DebugifyStatsMap *StatsMap = nullptr);
Vedant Kumara4afd1f2018-07-24 00:41:28 +000064
65llvm::FunctionPass *
66createCheckDebugifyFunctionPass(bool Strip = false,
Vedant Kumar499e3df2018-07-24 00:41:29 +000067 llvm::StringRef NameOfWrappedPass = "",
68 DebugifyStatsMap *StatsMap = nullptr);
Vedant Kumara4afd1f2018-07-24 00:41:28 +000069
70struct 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