LLVM  12.0.0git
Debugify.h
Go to the documentation of this file.
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_TRANSFORM_UTILS_DEBUGIFY_H
14 #define LLVM_TRANSFORM_UTILS_DEBUGIFY_H
15 
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/ADT/MapVector.h"
18 #include "llvm/IR/PassManager.h"
19 
20 namespace llvm {
21 class DIBuilder;
22 
23 /// Add synthesized debug information to a module.
24 ///
25 /// \param M The module to add debug information to.
26 /// \param Functions A range of functions to add debug information to.
27 /// \param Banner A prefix string to add to debug/error messages.
28 /// \param ApplyToMF A call back that will add debug information to the
29 /// MachineFunction for a Function. If nullptr, then the
30 /// MachineFunction (if any) will not be modified.
32  Module &M, iterator_range<Module::iterator> Functions, StringRef Banner,
33  std::function<bool(DIBuilder &, Function &)> ApplyToMF);
34 
35 /// Strip out all of the metadata and debug info inserted by debugify. If no
36 /// llvm.debugify module-level named metadata is present, this is a no-op.
37 /// Returns true if any change was made.
39 
40 } // namespace llvm
41 
44 
45 struct NewPMDebugifyPass : public llvm::PassInfoMixin<NewPMDebugifyPass> {
47 };
48 
49 /// Track how much `debugify` information has been lost.
51  /// Number of missing dbg.values.
52  unsigned NumDbgValuesMissing = 0;
53 
54  /// Number of dbg.values expected.
55  unsigned NumDbgValuesExpected = 0;
56 
57  /// Number of instructions with empty debug locations.
58  unsigned NumDbgLocsMissing = 0;
59 
60  /// Number of instructions expected to have debug locations.
61  unsigned NumDbgLocsExpected = 0;
62 
63  /// Get the ratio of missing/expected dbg.values.
64  float getMissingValueRatio() const {
65  return float(NumDbgValuesMissing) / float(NumDbgLocsExpected);
66  }
67 
68  /// Get the ratio of missing/expected instructions with locations.
69  float getEmptyLocationRatio() const {
70  return float(NumDbgLocsMissing) / float(NumDbgLocsExpected);
71  }
72 };
73 
74 /// Map pass names to a per-pass DebugifyStatistics instance.
76 
78 createCheckDebugifyModulePass(bool Strip = false,
79  llvm::StringRef NameOfWrappedPass = "",
80  DebugifyStatsMap *StatsMap = nullptr);
81 
83 createCheckDebugifyFunctionPass(bool Strip = false,
84  llvm::StringRef NameOfWrappedPass = "",
85  DebugifyStatsMap *StatsMap = nullptr);
86 
88  : public llvm::PassInfoMixin<NewPMCheckDebugifyPass> {
90 };
91 
92 #endif // LLVM_TRANSFORM_UTILS_DEBUGIFY_H
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Track how much debugify information has been lost.
Definition: Debugify.h:50
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:67
Machine Debugify Module
This class implements a map that also provides access to all stored values in a deterministic order...
Definition: MapVector.h:37
llvm::FunctionPass * createCheckDebugifyFunctionPass(bool Strip=false, llvm::StringRef NameOfWrappedPass="", DebugifyStatsMap *StatsMap=nullptr)
Definition: Debugify.cpp:493
bool stripDebugifyMetadata(Module &M)
Strip out all of the metadata and debug info inserted by debugify.
Definition: Debugify.cpp:201
llvm::ModulePass * createDebugifyModulePass()
Definition: Debugify.cpp:475
llvm::ModulePass * createCheckDebugifyModulePass(bool Strip=false, llvm::StringRef NameOfWrappedPass="", DebugifyStatsMap *StatsMap=nullptr)
Definition: Debugify.cpp:487
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:373
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:154
bool applyDebugifyMetadata(Module &M, iterator_range< Module::iterator > Functions, StringRef Banner, std::function< bool(DIBuilder &, Function &)> ApplyToMF)
Add synthesized debug information to a module.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:284
llvm::FunctionPass * createDebugifyFunctionPass()
Definition: Debugify.cpp:477
float getEmptyLocationRatio() const
Get the ratio of missing/expected instructions with locations.
Definition: Debugify.h:69
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:224
float getMissingValueRatio() const
Get the ratio of missing/expected dbg.values.
Definition: Debugify.h:64
print Print MemDeps of function
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
A container for analyses that lazily runs them and caches their results.
This header defines various interfaces for pass management in LLVM.