]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/IR/DebugInfo.h
Merge content currently under test from ^/vendor/NetBSD/tests/dist/@r312123
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / IR / DebugInfo.h
1 //===- DebugInfo.h - Debug Information Helpers ------------------*- C++ -*-===//
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 // This file defines a bunch of datatypes that are useful for creating and
11 // walking debug info in LLVM IR form. They essentially provide wrappers around
12 // the information in the global variables that's needed when constructing the
13 // DWARF information.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef LLVM_IR_DEBUGINFO_H
18 #define LLVM_IR_DEBUGINFO_H
19
20 #include "llvm/ADT/SmallPtrSet.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/iterator_range.h"
23 #include "llvm/IR/DebugInfoMetadata.h"
24 #include "llvm/Support/Casting.h"
25 #include "llvm/Support/Dwarf.h"
26 #include "llvm/Support/ErrorHandling.h"
27 #include <iterator>
28
29 namespace llvm {
30 class Module;
31 class DbgDeclareInst;
32 class DbgValueInst;
33 template <typename K, typename V, typename KeyInfoT, typename BucketT>
34 class DenseMap;
35
36 /// \brief Find subprogram that is enclosing this scope.
37 DISubprogram *getDISubprogram(const MDNode *Scope);
38
39 /// \brief Strip debug info in the module if it exists.
40 ///
41 /// To do this, we remove all calls to the debugger intrinsics and any named
42 /// metadata for debugging. We also remove debug locations for instructions.
43 /// Return true if module is modified.
44 bool StripDebugInfo(Module &M);
45 bool stripDebugInfo(Function &F);
46
47 /// \brief Return Debug Info Metadata Version by checking module flags.
48 unsigned getDebugMetadataVersionFromModule(const Module &M);
49
50 /// \brief Utility to find all debug info in a module.
51 ///
52 /// DebugInfoFinder tries to list all debug info MDNodes used in a module. To
53 /// list debug info MDNodes used by an instruction, DebugInfoFinder uses
54 /// processDeclare, processValue and processLocation to handle DbgDeclareInst,
55 /// DbgValueInst and DbgLoc attached to instructions. processModule will go
56 /// through all DICompileUnits in llvm.dbg.cu and list debug info MDNodes
57 /// used by the CUs.
58 class DebugInfoFinder {
59 public:
60   /// \brief Process entire module and collect debug info anchors.
61   void processModule(const Module &M);
62
63   /// \brief Process DbgDeclareInst.
64   void processDeclare(const Module &M, const DbgDeclareInst *DDI);
65   /// \brief Process DbgValueInst.
66   void processValue(const Module &M, const DbgValueInst *DVI);
67   /// \brief Process debug info location.
68   void processLocation(const Module &M, const DILocation *Loc);
69
70   /// \brief Clear all lists.
71   void reset();
72
73 private:
74   void InitializeTypeMap(const Module &M);
75
76   void processType(DIType *DT);
77   void processSubprogram(DISubprogram *SP);
78   void processScope(DIScope *Scope);
79   bool addCompileUnit(DICompileUnit *CU);
80   bool addGlobalVariable(DIGlobalVariable *DIG);
81   bool addSubprogram(DISubprogram *SP);
82   bool addType(DIType *DT);
83   bool addScope(DIScope *Scope);
84
85 public:
86   typedef SmallVectorImpl<DICompileUnit *>::const_iterator
87       compile_unit_iterator;
88   typedef SmallVectorImpl<DISubprogram *>::const_iterator subprogram_iterator;
89   typedef SmallVectorImpl<DIGlobalVariable *>::const_iterator
90       global_variable_iterator;
91   typedef SmallVectorImpl<DIType *>::const_iterator type_iterator;
92   typedef SmallVectorImpl<DIScope *>::const_iterator scope_iterator;
93
94   iterator_range<compile_unit_iterator> compile_units() const {
95     return make_range(CUs.begin(), CUs.end());
96   }
97
98   iterator_range<subprogram_iterator> subprograms() const {
99     return make_range(SPs.begin(), SPs.end());
100   }
101
102   iterator_range<global_variable_iterator> global_variables() const {
103     return make_range(GVs.begin(), GVs.end());
104   }
105
106   iterator_range<type_iterator> types() const {
107     return make_range(TYs.begin(), TYs.end());
108   }
109
110   iterator_range<scope_iterator> scopes() const {
111     return make_range(Scopes.begin(), Scopes.end());
112   }
113
114   unsigned compile_unit_count() const { return CUs.size(); }
115   unsigned global_variable_count() const { return GVs.size(); }
116   unsigned subprogram_count() const { return SPs.size(); }
117   unsigned type_count() const { return TYs.size(); }
118   unsigned scope_count() const { return Scopes.size(); }
119
120 private:
121   SmallVector<DICompileUnit *, 8> CUs;
122   SmallVector<DISubprogram *, 8> SPs;
123   SmallVector<DIGlobalVariable *, 8> GVs;
124   SmallVector<DIType *, 8> TYs;
125   SmallVector<DIScope *, 8> Scopes;
126   SmallPtrSet<const MDNode *, 32> NodesSeen;
127 };
128
129 } // end namespace llvm
130
131 #endif