blob: 266f577951aedd3291b875cb5511c28cfe45cc8c [file] [log] [blame]
Vedant Kumarca407c42018-07-24 00:41:28 +00001//===- Debugify.h - Attach synthetic debug info to everything -------------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Kumarca407c42018-07-24 00:41:28 +00006//
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 Kumard6ff43c2018-07-24 00:41:29 +000016#include "llvm/ADT/StringRef.h"
17#include "llvm/ADT/MapVector.h"
Vedant Kumarca407c42018-07-24 00:41:28 +000018#include "llvm/IR/PassManager.h"
Vedant Kumard6ff43c2018-07-24 00:41:29 +000019#include "llvm/Support/raw_ostream.h"
Vedant Kumarca407c42018-07-24 00:41:28 +000020
21llvm::ModulePass *createDebugifyModulePass();
22llvm::FunctionPass *createDebugifyFunctionPass();
23
24struct NewPMDebugifyPass : public llvm::PassInfoMixin<NewPMDebugifyPass> {
25 llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM);
26};
27
Vedant Kumard6ff43c2018-07-24 00:41:29 +000028/// Track how much `debugify` information has been lost.
29struct 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.
54using DebugifyStatsMap = llvm::MapVector<llvm::StringRef, DebugifyStatistics>;
55
56/// Export per-pass debugify statistics to the file specified by \p Path.
57void exportDebugifyStats(llvm::StringRef Path, const DebugifyStatsMap &Map);
58
Vedant Kumarca407c42018-07-24 00:41:28 +000059llvm::ModulePass *
60createCheckDebugifyModulePass(bool Strip = false,
Vedant Kumard6ff43c2018-07-24 00:41:29 +000061 llvm::StringRef NameOfWrappedPass = "",
62 DebugifyStatsMap *StatsMap = nullptr);
Vedant Kumarca407c42018-07-24 00:41:28 +000063
64llvm::FunctionPass *
65createCheckDebugifyFunctionPass(bool Strip = false,
Vedant Kumard6ff43c2018-07-24 00:41:29 +000066 llvm::StringRef NameOfWrappedPass = "",
67 DebugifyStatsMap *StatsMap = nullptr);
Vedant Kumarca407c42018-07-24 00:41:28 +000068
69struct 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