annotate clang/lib/CodeGen/CGDebugInfo.h @ 180:680fa57a2f20

fix compile errors.
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 30 May 2020 17:44:06 +0900
parents 0572611fdcc8
children 2e18cbf3894f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 //===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -------------*- C++ -*-===//
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
8 //
anatofuz
parents:
diff changeset
9 // This is the source-level debug info generator for llvm translation.
anatofuz
parents:
diff changeset
10 //
anatofuz
parents:
diff changeset
11 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
13 #ifndef LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
anatofuz
parents:
diff changeset
14 #define LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
anatofuz
parents:
diff changeset
15
anatofuz
parents:
diff changeset
16 #include "CGBuilder.h"
anatofuz
parents:
diff changeset
17 #include "clang/AST/DeclCXX.h"
anatofuz
parents:
diff changeset
18 #include "clang/AST/Expr.h"
anatofuz
parents:
diff changeset
19 #include "clang/AST/ExternalASTSource.h"
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
20 #include "clang/AST/PrettyPrinter.h"
150
anatofuz
parents:
diff changeset
21 #include "clang/AST/Type.h"
anatofuz
parents:
diff changeset
22 #include "clang/AST/TypeOrdering.h"
anatofuz
parents:
diff changeset
23 #include "clang/Basic/CodeGenOptions.h"
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
24 #include "clang/Basic/Module.h"
150
anatofuz
parents:
diff changeset
25 #include "clang/Basic/SourceLocation.h"
anatofuz
parents:
diff changeset
26 #include "llvm/ADT/DenseMap.h"
anatofuz
parents:
diff changeset
27 #include "llvm/ADT/DenseSet.h"
anatofuz
parents:
diff changeset
28 #include "llvm/ADT/Optional.h"
anatofuz
parents:
diff changeset
29 #include "llvm/IR/DIBuilder.h"
anatofuz
parents:
diff changeset
30 #include "llvm/IR/DebugInfo.h"
anatofuz
parents:
diff changeset
31 #include "llvm/IR/ValueHandle.h"
anatofuz
parents:
diff changeset
32 #include "llvm/Support/Allocator.h"
anatofuz
parents:
diff changeset
33
anatofuz
parents:
diff changeset
34 namespace llvm {
anatofuz
parents:
diff changeset
35 class MDNode;
anatofuz
parents:
diff changeset
36 }
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 namespace clang {
anatofuz
parents:
diff changeset
39 class ClassTemplateSpecializationDecl;
anatofuz
parents:
diff changeset
40 class GlobalDecl;
anatofuz
parents:
diff changeset
41 class ModuleMap;
anatofuz
parents:
diff changeset
42 class ObjCInterfaceDecl;
anatofuz
parents:
diff changeset
43 class ObjCIvarDecl;
anatofuz
parents:
diff changeset
44 class UsingDecl;
anatofuz
parents:
diff changeset
45 class VarDecl;
anatofuz
parents:
diff changeset
46 enum class DynamicInitKind : unsigned;
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 namespace CodeGen {
anatofuz
parents:
diff changeset
49 class CodeGenModule;
anatofuz
parents:
diff changeset
50 class CodeGenFunction;
anatofuz
parents:
diff changeset
51 class CGBlockInfo;
anatofuz
parents:
diff changeset
52
anatofuz
parents:
diff changeset
53 /// This class gathers all debug information during compilation and is
anatofuz
parents:
diff changeset
54 /// responsible for emitting to llvm globals or pass directly to the
anatofuz
parents:
diff changeset
55 /// backend.
anatofuz
parents:
diff changeset
56 class CGDebugInfo {
anatofuz
parents:
diff changeset
57 friend class ApplyDebugLocation;
anatofuz
parents:
diff changeset
58 friend class SaveAndRestoreLocation;
anatofuz
parents:
diff changeset
59 CodeGenModule &CGM;
anatofuz
parents:
diff changeset
60 const codegenoptions::DebugInfoKind DebugKind;
anatofuz
parents:
diff changeset
61 bool DebugTypeExtRefs;
anatofuz
parents:
diff changeset
62 llvm::DIBuilder DBuilder;
anatofuz
parents:
diff changeset
63 llvm::DICompileUnit *TheCU = nullptr;
anatofuz
parents:
diff changeset
64 ModuleMap *ClangModuleMap = nullptr;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
65 ASTSourceDescriptor PCHDescriptor;
150
anatofuz
parents:
diff changeset
66 SourceLocation CurLoc;
anatofuz
parents:
diff changeset
67 llvm::MDNode *CurInlinedAt = nullptr;
anatofuz
parents:
diff changeset
68 llvm::DIType *VTablePtrType = nullptr;
anatofuz
parents:
diff changeset
69 llvm::DIType *ClassTy = nullptr;
anatofuz
parents:
diff changeset
70 llvm::DICompositeType *ObjTy = nullptr;
anatofuz
parents:
diff changeset
71 llvm::DIType *SelTy = nullptr;
anatofuz
parents:
diff changeset
72 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
anatofuz
parents:
diff changeset
73 llvm::DIType *SingletonId = nullptr;
anatofuz
parents:
diff changeset
74 #include "clang/Basic/OpenCLImageTypes.def"
anatofuz
parents:
diff changeset
75 llvm::DIType *OCLSamplerDITy = nullptr;
anatofuz
parents:
diff changeset
76 llvm::DIType *OCLEventDITy = nullptr;
anatofuz
parents:
diff changeset
77 llvm::DIType *OCLClkEventDITy = nullptr;
anatofuz
parents:
diff changeset
78 llvm::DIType *OCLQueueDITy = nullptr;
anatofuz
parents:
diff changeset
79 llvm::DIType *OCLNDRangeDITy = nullptr;
anatofuz
parents:
diff changeset
80 llvm::DIType *OCLReserveIDDITy = nullptr;
anatofuz
parents:
diff changeset
81 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
anatofuz
parents:
diff changeset
82 llvm::DIType *Id##Ty = nullptr;
anatofuz
parents:
diff changeset
83 #include "clang/Basic/OpenCLExtensionTypes.def"
anatofuz
parents:
diff changeset
84
anatofuz
parents:
diff changeset
85 /// Cache of previously constructed Types.
anatofuz
parents:
diff changeset
86 llvm::DenseMap<const void *, llvm::TrackingMDRef> TypeCache;
anatofuz
parents:
diff changeset
87
anatofuz
parents:
diff changeset
88 std::map<llvm::StringRef, llvm::StringRef, std::greater<llvm::StringRef>>
anatofuz
parents:
diff changeset
89 DebugPrefixMap;
anatofuz
parents:
diff changeset
90
anatofuz
parents:
diff changeset
91 /// Cache that maps VLA types to size expressions for that type,
anatofuz
parents:
diff changeset
92 /// represented by instantiated Metadata nodes.
anatofuz
parents:
diff changeset
93 llvm::SmallDenseMap<QualType, llvm::Metadata *> SizeExprCache;
anatofuz
parents:
diff changeset
94
anatofuz
parents:
diff changeset
95 /// Callbacks to use when printing names and types.
anatofuz
parents:
diff changeset
96 class PrintingCallbacks final : public clang::PrintingCallbacks {
anatofuz
parents:
diff changeset
97 const CGDebugInfo &Self;
anatofuz
parents:
diff changeset
98
anatofuz
parents:
diff changeset
99 public:
anatofuz
parents:
diff changeset
100 PrintingCallbacks(const CGDebugInfo &Self) : Self(Self) {}
anatofuz
parents:
diff changeset
101 std::string remapPath(StringRef Path) const override {
anatofuz
parents:
diff changeset
102 return Self.remapDIPath(Path);
anatofuz
parents:
diff changeset
103 }
anatofuz
parents:
diff changeset
104 };
anatofuz
parents:
diff changeset
105 PrintingCallbacks PrintCB = {*this};
anatofuz
parents:
diff changeset
106
anatofuz
parents:
diff changeset
107 struct ObjCInterfaceCacheEntry {
anatofuz
parents:
diff changeset
108 const ObjCInterfaceType *Type;
anatofuz
parents:
diff changeset
109 llvm::DIType *Decl;
anatofuz
parents:
diff changeset
110 llvm::DIFile *Unit;
anatofuz
parents:
diff changeset
111 ObjCInterfaceCacheEntry(const ObjCInterfaceType *Type, llvm::DIType *Decl,
anatofuz
parents:
diff changeset
112 llvm::DIFile *Unit)
anatofuz
parents:
diff changeset
113 : Type(Type), Decl(Decl), Unit(Unit) {}
anatofuz
parents:
diff changeset
114 };
anatofuz
parents:
diff changeset
115
anatofuz
parents:
diff changeset
116 /// Cache of previously constructed interfaces which may change.
anatofuz
parents:
diff changeset
117 llvm::SmallVector<ObjCInterfaceCacheEntry, 32> ObjCInterfaceCache;
anatofuz
parents:
diff changeset
118
anatofuz
parents:
diff changeset
119 /// Cache of forward declarations for methods belonging to the interface.
anatofuz
parents:
diff changeset
120 /// The extra bit on the DISubprogram specifies whether a method is
anatofuz
parents:
diff changeset
121 /// "objc_direct".
anatofuz
parents:
diff changeset
122 llvm::DenseMap<const ObjCInterfaceDecl *,
anatofuz
parents:
diff changeset
123 std::vector<llvm::PointerIntPair<llvm::DISubprogram *, 1>>>
anatofuz
parents:
diff changeset
124 ObjCMethodCache;
anatofuz
parents:
diff changeset
125
anatofuz
parents:
diff changeset
126 /// Cache of references to clang modules and precompiled headers.
anatofuz
parents:
diff changeset
127 llvm::DenseMap<const Module *, llvm::TrackingMDRef> ModuleCache;
anatofuz
parents:
diff changeset
128
anatofuz
parents:
diff changeset
129 /// List of interfaces we want to keep even if orphaned.
anatofuz
parents:
diff changeset
130 std::vector<void *> RetainedTypes;
anatofuz
parents:
diff changeset
131
anatofuz
parents:
diff changeset
132 /// Cache of forward declared types to RAUW at the end of compilation.
anatofuz
parents:
diff changeset
133 std::vector<std::pair<const TagType *, llvm::TrackingMDRef>> ReplaceMap;
anatofuz
parents:
diff changeset
134
anatofuz
parents:
diff changeset
135 /// Cache of replaceable forward declarations (functions and
anatofuz
parents:
diff changeset
136 /// variables) to RAUW at the end of compilation.
anatofuz
parents:
diff changeset
137 std::vector<std::pair<const DeclaratorDecl *, llvm::TrackingMDRef>>
anatofuz
parents:
diff changeset
138 FwdDeclReplaceMap;
anatofuz
parents:
diff changeset
139
anatofuz
parents:
diff changeset
140 /// Keep track of our current nested lexical block.
anatofuz
parents:
diff changeset
141 std::vector<llvm::TypedTrackingMDRef<llvm::DIScope>> LexicalBlockStack;
anatofuz
parents:
diff changeset
142 llvm::DenseMap<const Decl *, llvm::TrackingMDRef> RegionMap;
anatofuz
parents:
diff changeset
143 /// Keep track of LexicalBlockStack counter at the beginning of a
anatofuz
parents:
diff changeset
144 /// function. This is used to pop unbalanced regions at the end of a
anatofuz
parents:
diff changeset
145 /// function.
anatofuz
parents:
diff changeset
146 std::vector<unsigned> FnBeginRegionCount;
anatofuz
parents:
diff changeset
147
anatofuz
parents:
diff changeset
148 /// This is a storage for names that are constructed on demand. For
anatofuz
parents:
diff changeset
149 /// example, C++ destructors, C++ operators etc..
anatofuz
parents:
diff changeset
150 llvm::BumpPtrAllocator DebugInfoNames;
anatofuz
parents:
diff changeset
151 StringRef CWDName;
anatofuz
parents:
diff changeset
152
anatofuz
parents:
diff changeset
153 llvm::DenseMap<const char *, llvm::TrackingMDRef> DIFileCache;
anatofuz
parents:
diff changeset
154 llvm::DenseMap<const FunctionDecl *, llvm::TrackingMDRef> SPCache;
anatofuz
parents:
diff changeset
155 /// Cache declarations relevant to DW_TAG_imported_declarations (C++
anatofuz
parents:
diff changeset
156 /// using declarations) that aren't covered by other more specific caches.
anatofuz
parents:
diff changeset
157 llvm::DenseMap<const Decl *, llvm::TrackingMDRef> DeclCache;
anatofuz
parents:
diff changeset
158 llvm::DenseMap<const NamespaceDecl *, llvm::TrackingMDRef> NamespaceCache;
anatofuz
parents:
diff changeset
159 llvm::DenseMap<const NamespaceAliasDecl *, llvm::TrackingMDRef>
anatofuz
parents:
diff changeset
160 NamespaceAliasCache;
anatofuz
parents:
diff changeset
161 llvm::DenseMap<const Decl *, llvm::TypedTrackingMDRef<llvm::DIDerivedType>>
anatofuz
parents:
diff changeset
162 StaticDataMemberCache;
anatofuz
parents:
diff changeset
163
anatofuz
parents:
diff changeset
164 /// Helper functions for getOrCreateType.
anatofuz
parents:
diff changeset
165 /// @{
anatofuz
parents:
diff changeset
166 /// Currently the checksum of an interface includes the number of
anatofuz
parents:
diff changeset
167 /// ivars and property accessors.
anatofuz
parents:
diff changeset
168 llvm::DIType *CreateType(const BuiltinType *Ty);
anatofuz
parents:
diff changeset
169 llvm::DIType *CreateType(const ComplexType *Ty);
anatofuz
parents:
diff changeset
170 llvm::DIType *CreateType(const AutoType *Ty);
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
171 llvm::DIType *CreateType(const ExtIntType *Ty);
150
anatofuz
parents:
diff changeset
172 llvm::DIType *CreateQualifiedType(QualType Ty, llvm::DIFile *Fg);
anatofuz
parents:
diff changeset
173 llvm::DIType *CreateType(const TypedefType *Ty, llvm::DIFile *Fg);
anatofuz
parents:
diff changeset
174 llvm::DIType *CreateType(const TemplateSpecializationType *Ty,
anatofuz
parents:
diff changeset
175 llvm::DIFile *Fg);
anatofuz
parents:
diff changeset
176 llvm::DIType *CreateType(const ObjCObjectPointerType *Ty, llvm::DIFile *F);
anatofuz
parents:
diff changeset
177 llvm::DIType *CreateType(const PointerType *Ty, llvm::DIFile *F);
anatofuz
parents:
diff changeset
178 llvm::DIType *CreateType(const BlockPointerType *Ty, llvm::DIFile *F);
anatofuz
parents:
diff changeset
179 llvm::DIType *CreateType(const FunctionType *Ty, llvm::DIFile *F);
anatofuz
parents:
diff changeset
180 /// Get structure or union type.
anatofuz
parents:
diff changeset
181 llvm::DIType *CreateType(const RecordType *Tyg);
anatofuz
parents:
diff changeset
182 llvm::DIType *CreateTypeDefinition(const RecordType *Ty);
anatofuz
parents:
diff changeset
183 llvm::DICompositeType *CreateLimitedType(const RecordType *Ty);
anatofuz
parents:
diff changeset
184 void CollectContainingType(const CXXRecordDecl *RD,
anatofuz
parents:
diff changeset
185 llvm::DICompositeType *CT);
anatofuz
parents:
diff changeset
186 /// Get Objective-C interface type.
anatofuz
parents:
diff changeset
187 llvm::DIType *CreateType(const ObjCInterfaceType *Ty, llvm::DIFile *F);
anatofuz
parents:
diff changeset
188 llvm::DIType *CreateTypeDefinition(const ObjCInterfaceType *Ty,
anatofuz
parents:
diff changeset
189 llvm::DIFile *F);
anatofuz
parents:
diff changeset
190 /// Get Objective-C object type.
anatofuz
parents:
diff changeset
191 llvm::DIType *CreateType(const ObjCObjectType *Ty, llvm::DIFile *F);
anatofuz
parents:
diff changeset
192 llvm::DIType *CreateType(const ObjCTypeParamType *Ty, llvm::DIFile *Unit);
anatofuz
parents:
diff changeset
193
anatofuz
parents:
diff changeset
194 llvm::DIType *CreateType(const VectorType *Ty, llvm::DIFile *F);
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
195 llvm::DIType *CreateType(const ConstantMatrixType *Ty, llvm::DIFile *F);
150
anatofuz
parents:
diff changeset
196 llvm::DIType *CreateType(const ArrayType *Ty, llvm::DIFile *F);
anatofuz
parents:
diff changeset
197 llvm::DIType *CreateType(const LValueReferenceType *Ty, llvm::DIFile *F);
anatofuz
parents:
diff changeset
198 llvm::DIType *CreateType(const RValueReferenceType *Ty, llvm::DIFile *Unit);
anatofuz
parents:
diff changeset
199 llvm::DIType *CreateType(const MemberPointerType *Ty, llvm::DIFile *F);
anatofuz
parents:
diff changeset
200 llvm::DIType *CreateType(const AtomicType *Ty, llvm::DIFile *F);
anatofuz
parents:
diff changeset
201 llvm::DIType *CreateType(const PipeType *Ty, llvm::DIFile *F);
anatofuz
parents:
diff changeset
202 /// Get enumeration type.
anatofuz
parents:
diff changeset
203 llvm::DIType *CreateEnumType(const EnumType *Ty);
anatofuz
parents:
diff changeset
204 llvm::DIType *CreateTypeDefinition(const EnumType *Ty);
anatofuz
parents:
diff changeset
205 /// Look up the completed type for a self pointer in the TypeCache and
anatofuz
parents:
diff changeset
206 /// create a copy of it with the ObjectPointer and Artificial flags
anatofuz
parents:
diff changeset
207 /// set. If the type is not cached, a new one is created. This should
anatofuz
parents:
diff changeset
208 /// never happen though, since creating a type for the implicit self
anatofuz
parents:
diff changeset
209 /// argument implies that we already parsed the interface definition
anatofuz
parents:
diff changeset
210 /// and the ivar declarations in the implementation.
anatofuz
parents:
diff changeset
211 llvm::DIType *CreateSelfType(const QualType &QualTy, llvm::DIType *Ty);
anatofuz
parents:
diff changeset
212 /// @}
anatofuz
parents:
diff changeset
213
anatofuz
parents:
diff changeset
214 /// Get the type from the cache or return null type if it doesn't
anatofuz
parents:
diff changeset
215 /// exist.
anatofuz
parents:
diff changeset
216 llvm::DIType *getTypeOrNull(const QualType);
anatofuz
parents:
diff changeset
217 /// Return the debug type for a C++ method.
anatofuz
parents:
diff changeset
218 /// \arg CXXMethodDecl is of FunctionType. This function type is
anatofuz
parents:
diff changeset
219 /// not updated to include implicit \c this pointer. Use this routine
anatofuz
parents:
diff changeset
220 /// to get a method type which includes \c this pointer.
anatofuz
parents:
diff changeset
221 llvm::DISubroutineType *getOrCreateMethodType(const CXXMethodDecl *Method,
anatofuz
parents:
diff changeset
222 llvm::DIFile *F, bool decl);
anatofuz
parents:
diff changeset
223 llvm::DISubroutineType *
anatofuz
parents:
diff changeset
224 getOrCreateInstanceMethodType(QualType ThisPtr, const FunctionProtoType *Func,
anatofuz
parents:
diff changeset
225 llvm::DIFile *Unit, bool decl);
anatofuz
parents:
diff changeset
226 llvm::DISubroutineType *
anatofuz
parents:
diff changeset
227 getOrCreateFunctionType(const Decl *D, QualType FnType, llvm::DIFile *F);
anatofuz
parents:
diff changeset
228 /// \return debug info descriptor for vtable.
anatofuz
parents:
diff changeset
229 llvm::DIType *getOrCreateVTablePtrType(llvm::DIFile *F);
anatofuz
parents:
diff changeset
230
anatofuz
parents:
diff changeset
231 /// \return namespace descriptor for the given namespace decl.
anatofuz
parents:
diff changeset
232 llvm::DINamespace *getOrCreateNamespace(const NamespaceDecl *N);
anatofuz
parents:
diff changeset
233 llvm::DIType *CreatePointerLikeType(llvm::dwarf::Tag Tag, const Type *Ty,
anatofuz
parents:
diff changeset
234 QualType PointeeTy, llvm::DIFile *F);
anatofuz
parents:
diff changeset
235 llvm::DIType *getOrCreateStructPtrType(StringRef Name, llvm::DIType *&Cache);
anatofuz
parents:
diff changeset
236
anatofuz
parents:
diff changeset
237 /// A helper function to create a subprogram for a single member
anatofuz
parents:
diff changeset
238 /// function GlobalDecl.
anatofuz
parents:
diff changeset
239 llvm::DISubprogram *CreateCXXMemberFunction(const CXXMethodDecl *Method,
anatofuz
parents:
diff changeset
240 llvm::DIFile *F,
anatofuz
parents:
diff changeset
241 llvm::DIType *RecordTy);
anatofuz
parents:
diff changeset
242
anatofuz
parents:
diff changeset
243 /// A helper function to collect debug info for C++ member
anatofuz
parents:
diff changeset
244 /// functions. This is used while creating debug info entry for a
anatofuz
parents:
diff changeset
245 /// Record.
anatofuz
parents:
diff changeset
246 void CollectCXXMemberFunctions(const CXXRecordDecl *Decl, llvm::DIFile *F,
anatofuz
parents:
diff changeset
247 SmallVectorImpl<llvm::Metadata *> &E,
anatofuz
parents:
diff changeset
248 llvm::DIType *T);
anatofuz
parents:
diff changeset
249
anatofuz
parents:
diff changeset
250 /// A helper function to collect debug info for C++ base
anatofuz
parents:
diff changeset
251 /// classes. This is used while creating debug info entry for a
anatofuz
parents:
diff changeset
252 /// Record.
anatofuz
parents:
diff changeset
253 void CollectCXXBases(const CXXRecordDecl *Decl, llvm::DIFile *F,
anatofuz
parents:
diff changeset
254 SmallVectorImpl<llvm::Metadata *> &EltTys,
anatofuz
parents:
diff changeset
255 llvm::DIType *RecordTy);
anatofuz
parents:
diff changeset
256
anatofuz
parents:
diff changeset
257 /// Helper function for CollectCXXBases.
anatofuz
parents:
diff changeset
258 /// Adds debug info entries for types in Bases that are not in SeenTypes.
anatofuz
parents:
diff changeset
259 void CollectCXXBasesAux(
anatofuz
parents:
diff changeset
260 const CXXRecordDecl *RD, llvm::DIFile *Unit,
anatofuz
parents:
diff changeset
261 SmallVectorImpl<llvm::Metadata *> &EltTys, llvm::DIType *RecordTy,
anatofuz
parents:
diff changeset
262 const CXXRecordDecl::base_class_const_range &Bases,
anatofuz
parents:
diff changeset
263 llvm::DenseSet<CanonicalDeclPtr<const CXXRecordDecl>> &SeenTypes,
anatofuz
parents:
diff changeset
264 llvm::DINode::DIFlags StartingFlags);
anatofuz
parents:
diff changeset
265
anatofuz
parents:
diff changeset
266 /// A helper function to collect template parameters.
anatofuz
parents:
diff changeset
267 llvm::DINodeArray CollectTemplateParams(const TemplateParameterList *TPList,
anatofuz
parents:
diff changeset
268 ArrayRef<TemplateArgument> TAList,
anatofuz
parents:
diff changeset
269 llvm::DIFile *Unit);
anatofuz
parents:
diff changeset
270 /// A helper function to collect debug info for function template
anatofuz
parents:
diff changeset
271 /// parameters.
anatofuz
parents:
diff changeset
272 llvm::DINodeArray CollectFunctionTemplateParams(const FunctionDecl *FD,
anatofuz
parents:
diff changeset
273 llvm::DIFile *Unit);
anatofuz
parents:
diff changeset
274
anatofuz
parents:
diff changeset
275 /// A helper function to collect debug info for function template
anatofuz
parents:
diff changeset
276 /// parameters.
anatofuz
parents:
diff changeset
277 llvm::DINodeArray CollectVarTemplateParams(const VarDecl *VD,
anatofuz
parents:
diff changeset
278 llvm::DIFile *Unit);
anatofuz
parents:
diff changeset
279
anatofuz
parents:
diff changeset
280 /// A helper function to collect debug info for template
anatofuz
parents:
diff changeset
281 /// parameters.
anatofuz
parents:
diff changeset
282 llvm::DINodeArray
anatofuz
parents:
diff changeset
283 CollectCXXTemplateParams(const ClassTemplateSpecializationDecl *TS,
anatofuz
parents:
diff changeset
284 llvm::DIFile *F);
anatofuz
parents:
diff changeset
285
anatofuz
parents:
diff changeset
286 llvm::DIType *createFieldType(StringRef name, QualType type,
anatofuz
parents:
diff changeset
287 SourceLocation loc, AccessSpecifier AS,
anatofuz
parents:
diff changeset
288 uint64_t offsetInBits, uint32_t AlignInBits,
anatofuz
parents:
diff changeset
289 llvm::DIFile *tunit, llvm::DIScope *scope,
anatofuz
parents:
diff changeset
290 const RecordDecl *RD = nullptr);
anatofuz
parents:
diff changeset
291
anatofuz
parents:
diff changeset
292 llvm::DIType *createFieldType(StringRef name, QualType type,
anatofuz
parents:
diff changeset
293 SourceLocation loc, AccessSpecifier AS,
anatofuz
parents:
diff changeset
294 uint64_t offsetInBits, llvm::DIFile *tunit,
anatofuz
parents:
diff changeset
295 llvm::DIScope *scope,
anatofuz
parents:
diff changeset
296 const RecordDecl *RD = nullptr) {
anatofuz
parents:
diff changeset
297 return createFieldType(name, type, loc, AS, offsetInBits, 0, tunit, scope,
anatofuz
parents:
diff changeset
298 RD);
anatofuz
parents:
diff changeset
299 }
anatofuz
parents:
diff changeset
300
anatofuz
parents:
diff changeset
301 /// Create new bit field member.
anatofuz
parents:
diff changeset
302 llvm::DIType *createBitFieldType(const FieldDecl *BitFieldDecl,
anatofuz
parents:
diff changeset
303 llvm::DIScope *RecordTy,
anatofuz
parents:
diff changeset
304 const RecordDecl *RD);
anatofuz
parents:
diff changeset
305
anatofuz
parents:
diff changeset
306 /// Helpers for collecting fields of a record.
anatofuz
parents:
diff changeset
307 /// @{
anatofuz
parents:
diff changeset
308 void CollectRecordLambdaFields(const CXXRecordDecl *CXXDecl,
anatofuz
parents:
diff changeset
309 SmallVectorImpl<llvm::Metadata *> &E,
anatofuz
parents:
diff changeset
310 llvm::DIType *RecordTy);
anatofuz
parents:
diff changeset
311 llvm::DIDerivedType *CreateRecordStaticField(const VarDecl *Var,
anatofuz
parents:
diff changeset
312 llvm::DIType *RecordTy,
anatofuz
parents:
diff changeset
313 const RecordDecl *RD);
anatofuz
parents:
diff changeset
314 void CollectRecordNormalField(const FieldDecl *Field, uint64_t OffsetInBits,
anatofuz
parents:
diff changeset
315 llvm::DIFile *F,
anatofuz
parents:
diff changeset
316 SmallVectorImpl<llvm::Metadata *> &E,
anatofuz
parents:
diff changeset
317 llvm::DIType *RecordTy, const RecordDecl *RD);
anatofuz
parents:
diff changeset
318 void CollectRecordNestedType(const TypeDecl *RD,
anatofuz
parents:
diff changeset
319 SmallVectorImpl<llvm::Metadata *> &E);
anatofuz
parents:
diff changeset
320 void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile *F,
anatofuz
parents:
diff changeset
321 SmallVectorImpl<llvm::Metadata *> &E,
anatofuz
parents:
diff changeset
322 llvm::DICompositeType *RecordTy);
anatofuz
parents:
diff changeset
323
anatofuz
parents:
diff changeset
324 /// If the C++ class has vtable info then insert appropriate debug
anatofuz
parents:
diff changeset
325 /// info entry in EltTys vector.
anatofuz
parents:
diff changeset
326 void CollectVTableInfo(const CXXRecordDecl *Decl, llvm::DIFile *F,
anatofuz
parents:
diff changeset
327 SmallVectorImpl<llvm::Metadata *> &EltTys,
anatofuz
parents:
diff changeset
328 llvm::DICompositeType *RecordTy);
anatofuz
parents:
diff changeset
329 /// @}
anatofuz
parents:
diff changeset
330
anatofuz
parents:
diff changeset
331 /// Create a new lexical block node and push it on the stack.
anatofuz
parents:
diff changeset
332 void CreateLexicalBlock(SourceLocation Loc);
anatofuz
parents:
diff changeset
333
anatofuz
parents:
diff changeset
334 /// If target-specific LLVM \p AddressSpace directly maps to target-specific
anatofuz
parents:
diff changeset
335 /// DWARF address space, appends extended dereferencing mechanism to complex
anatofuz
parents:
diff changeset
336 /// expression \p Expr. Otherwise, does nothing.
anatofuz
parents:
diff changeset
337 ///
anatofuz
parents:
diff changeset
338 /// Extended dereferencing mechanism is has the following format:
anatofuz
parents:
diff changeset
339 /// DW_OP_constu <DWARF Address Space> DW_OP_swap DW_OP_xderef
anatofuz
parents:
diff changeset
340 void AppendAddressSpaceXDeref(unsigned AddressSpace,
anatofuz
parents:
diff changeset
341 SmallVectorImpl<int64_t> &Expr) const;
anatofuz
parents:
diff changeset
342
anatofuz
parents:
diff changeset
343 /// A helper function to collect debug info for the default elements of a
anatofuz
parents:
diff changeset
344 /// block.
anatofuz
parents:
diff changeset
345 ///
anatofuz
parents:
diff changeset
346 /// \returns The next available field offset after the default elements.
anatofuz
parents:
diff changeset
347 uint64_t collectDefaultElementTypesForBlockPointer(
anatofuz
parents:
diff changeset
348 const BlockPointerType *Ty, llvm::DIFile *Unit,
anatofuz
parents:
diff changeset
349 llvm::DIDerivedType *DescTy, unsigned LineNo,
anatofuz
parents:
diff changeset
350 SmallVectorImpl<llvm::Metadata *> &EltTys);
anatofuz
parents:
diff changeset
351
anatofuz
parents:
diff changeset
352 /// A helper function to collect debug info for the default fields of a
anatofuz
parents:
diff changeset
353 /// block.
anatofuz
parents:
diff changeset
354 void collectDefaultFieldsForBlockLiteralDeclare(
anatofuz
parents:
diff changeset
355 const CGBlockInfo &Block, const ASTContext &Context, SourceLocation Loc,
anatofuz
parents:
diff changeset
356 const llvm::StructLayout &BlockLayout, llvm::DIFile *Unit,
anatofuz
parents:
diff changeset
357 SmallVectorImpl<llvm::Metadata *> &Fields);
anatofuz
parents:
diff changeset
358
anatofuz
parents:
diff changeset
359 public:
anatofuz
parents:
diff changeset
360 CGDebugInfo(CodeGenModule &CGM);
anatofuz
parents:
diff changeset
361 ~CGDebugInfo();
anatofuz
parents:
diff changeset
362
anatofuz
parents:
diff changeset
363 void finalize();
anatofuz
parents:
diff changeset
364
anatofuz
parents:
diff changeset
365 /// Remap a given path with the current debug prefix map
anatofuz
parents:
diff changeset
366 std::string remapDIPath(StringRef) const;
anatofuz
parents:
diff changeset
367
anatofuz
parents:
diff changeset
368 /// Register VLA size expression debug node with the qualified type.
anatofuz
parents:
diff changeset
369 void registerVLASizeExpression(QualType Ty, llvm::Metadata *SizeExpr) {
anatofuz
parents:
diff changeset
370 SizeExprCache[Ty] = SizeExpr;
anatofuz
parents:
diff changeset
371 }
anatofuz
parents:
diff changeset
372
anatofuz
parents:
diff changeset
373 /// Module debugging: Support for building PCMs.
anatofuz
parents:
diff changeset
374 /// @{
anatofuz
parents:
diff changeset
375 /// Set the main CU's DwoId field to \p Signature.
anatofuz
parents:
diff changeset
376 void setDwoId(uint64_t Signature);
anatofuz
parents:
diff changeset
377
anatofuz
parents:
diff changeset
378 /// When generating debug information for a clang module or
anatofuz
parents:
diff changeset
379 /// precompiled header, this module map will be used to determine
anatofuz
parents:
diff changeset
380 /// the module of origin of each Decl.
anatofuz
parents:
diff changeset
381 void setModuleMap(ModuleMap &MMap) { ClangModuleMap = &MMap; }
anatofuz
parents:
diff changeset
382
anatofuz
parents:
diff changeset
383 /// When generating debug information for a clang module or
anatofuz
parents:
diff changeset
384 /// precompiled header, this module map will be used to determine
anatofuz
parents:
diff changeset
385 /// the module of origin of each Decl.
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
386 void setPCHDescriptor(ASTSourceDescriptor PCH) { PCHDescriptor = PCH; }
150
anatofuz
parents:
diff changeset
387 /// @}
anatofuz
parents:
diff changeset
388
anatofuz
parents:
diff changeset
389 /// Update the current source location. If \arg loc is invalid it is
anatofuz
parents:
diff changeset
390 /// ignored.
anatofuz
parents:
diff changeset
391 void setLocation(SourceLocation Loc);
anatofuz
parents:
diff changeset
392
anatofuz
parents:
diff changeset
393 /// Return the current source location. This does not necessarily correspond
anatofuz
parents:
diff changeset
394 /// to the IRBuilder's current DebugLoc.
anatofuz
parents:
diff changeset
395 SourceLocation getLocation() const { return CurLoc; }
anatofuz
parents:
diff changeset
396
anatofuz
parents:
diff changeset
397 /// Update the current inline scope. All subsequent calls to \p EmitLocation
anatofuz
parents:
diff changeset
398 /// will create a location with this inlinedAt field.
anatofuz
parents:
diff changeset
399 void setInlinedAt(llvm::MDNode *InlinedAt) { CurInlinedAt = InlinedAt; }
anatofuz
parents:
diff changeset
400
anatofuz
parents:
diff changeset
401 /// \return the current inline scope.
anatofuz
parents:
diff changeset
402 llvm::MDNode *getInlinedAt() const { return CurInlinedAt; }
anatofuz
parents:
diff changeset
403
anatofuz
parents:
diff changeset
404 // Converts a SourceLocation to a DebugLoc
anatofuz
parents:
diff changeset
405 llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Loc);
anatofuz
parents:
diff changeset
406
anatofuz
parents:
diff changeset
407 /// Emit metadata to indicate a change in line/column information in
anatofuz
parents:
diff changeset
408 /// the source file. If the location is invalid, the previous
anatofuz
parents:
diff changeset
409 /// location will be reused.
anatofuz
parents:
diff changeset
410 void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc);
anatofuz
parents:
diff changeset
411
anatofuz
parents:
diff changeset
412 /// Emit a call to llvm.dbg.function.start to indicate
anatofuz
parents:
diff changeset
413 /// start of a new function.
anatofuz
parents:
diff changeset
414 /// \param Loc The location of the function header.
anatofuz
parents:
diff changeset
415 /// \param ScopeLoc The location of the function body.
anatofuz
parents:
diff changeset
416 void EmitFunctionStart(GlobalDecl GD, SourceLocation Loc,
anatofuz
parents:
diff changeset
417 SourceLocation ScopeLoc, QualType FnType,
anatofuz
parents:
diff changeset
418 llvm::Function *Fn, bool CurFnIsThunk,
anatofuz
parents:
diff changeset
419 CGBuilderTy &Builder);
anatofuz
parents:
diff changeset
420
anatofuz
parents:
diff changeset
421 /// Start a new scope for an inlined function.
anatofuz
parents:
diff changeset
422 void EmitInlineFunctionStart(CGBuilderTy &Builder, GlobalDecl GD);
anatofuz
parents:
diff changeset
423 /// End an inlined function scope.
anatofuz
parents:
diff changeset
424 void EmitInlineFunctionEnd(CGBuilderTy &Builder);
anatofuz
parents:
diff changeset
425
anatofuz
parents:
diff changeset
426 /// Emit debug info for a function declaration.
anatofuz
parents:
diff changeset
427 /// \p Fn is set only when a declaration for a debug call site gets created.
anatofuz
parents:
diff changeset
428 void EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc,
anatofuz
parents:
diff changeset
429 QualType FnType, llvm::Function *Fn = nullptr);
anatofuz
parents:
diff changeset
430
anatofuz
parents:
diff changeset
431 /// Emit debug info for an extern function being called.
anatofuz
parents:
diff changeset
432 /// This is needed for call site debug info.
anatofuz
parents:
diff changeset
433 void EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
anatofuz
parents:
diff changeset
434 QualType CalleeType,
anatofuz
parents:
diff changeset
435 const FunctionDecl *CalleeDecl);
anatofuz
parents:
diff changeset
436
anatofuz
parents:
diff changeset
437 /// Constructs the debug code for exiting a function.
anatofuz
parents:
diff changeset
438 void EmitFunctionEnd(CGBuilderTy &Builder, llvm::Function *Fn);
anatofuz
parents:
diff changeset
439
anatofuz
parents:
diff changeset
440 /// Emit metadata to indicate the beginning of a new lexical block
anatofuz
parents:
diff changeset
441 /// and push the block onto the stack.
anatofuz
parents:
diff changeset
442 void EmitLexicalBlockStart(CGBuilderTy &Builder, SourceLocation Loc);
anatofuz
parents:
diff changeset
443
anatofuz
parents:
diff changeset
444 /// Emit metadata to indicate the end of a new lexical block and pop
anatofuz
parents:
diff changeset
445 /// the current block.
anatofuz
parents:
diff changeset
446 void EmitLexicalBlockEnd(CGBuilderTy &Builder, SourceLocation Loc);
anatofuz
parents:
diff changeset
447
anatofuz
parents:
diff changeset
448 /// Emit call to \c llvm.dbg.declare for an automatic variable
anatofuz
parents:
diff changeset
449 /// declaration.
anatofuz
parents:
diff changeset
450 /// Returns a pointer to the DILocalVariable associated with the
anatofuz
parents:
diff changeset
451 /// llvm.dbg.declare, or nullptr otherwise.
anatofuz
parents:
diff changeset
452 llvm::DILocalVariable *
anatofuz
parents:
diff changeset
453 EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI,
anatofuz
parents:
diff changeset
454 CGBuilderTy &Builder,
anatofuz
parents:
diff changeset
455 const bool UsePointerValue = false);
anatofuz
parents:
diff changeset
456
anatofuz
parents:
diff changeset
457 /// Emit call to \c llvm.dbg.label for an label.
anatofuz
parents:
diff changeset
458 void EmitLabel(const LabelDecl *D, CGBuilderTy &Builder);
anatofuz
parents:
diff changeset
459
anatofuz
parents:
diff changeset
460 /// Emit call to \c llvm.dbg.declare for an imported variable
anatofuz
parents:
diff changeset
461 /// declaration in a block.
anatofuz
parents:
diff changeset
462 void EmitDeclareOfBlockDeclRefVariable(
anatofuz
parents:
diff changeset
463 const VarDecl *variable, llvm::Value *storage, CGBuilderTy &Builder,
anatofuz
parents:
diff changeset
464 const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint = nullptr);
anatofuz
parents:
diff changeset
465
anatofuz
parents:
diff changeset
466 /// Emit call to \c llvm.dbg.declare for an argument variable
anatofuz
parents:
diff changeset
467 /// declaration.
anatofuz
parents:
diff changeset
468 void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI,
anatofuz
parents:
diff changeset
469 unsigned ArgNo, CGBuilderTy &Builder);
anatofuz
parents:
diff changeset
470
anatofuz
parents:
diff changeset
471 /// Emit call to \c llvm.dbg.declare for the block-literal argument
anatofuz
parents:
diff changeset
472 /// to a block invocation function.
anatofuz
parents:
diff changeset
473 void EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
anatofuz
parents:
diff changeset
474 StringRef Name, unsigned ArgNo,
anatofuz
parents:
diff changeset
475 llvm::AllocaInst *LocalAddr,
anatofuz
parents:
diff changeset
476 CGBuilderTy &Builder);
anatofuz
parents:
diff changeset
477
anatofuz
parents:
diff changeset
478 /// Emit information about a global variable.
anatofuz
parents:
diff changeset
479 void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
anatofuz
parents:
diff changeset
480
anatofuz
parents:
diff changeset
481 /// Emit a constant global variable's debug info.
anatofuz
parents:
diff changeset
482 void EmitGlobalVariable(const ValueDecl *VD, const APValue &Init);
anatofuz
parents:
diff changeset
483
anatofuz
parents:
diff changeset
484 /// Emit information about an external variable.
anatofuz
parents:
diff changeset
485 void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
anatofuz
parents:
diff changeset
486
anatofuz
parents:
diff changeset
487 /// Emit C++ using directive.
anatofuz
parents:
diff changeset
488 void EmitUsingDirective(const UsingDirectiveDecl &UD);
anatofuz
parents:
diff changeset
489
anatofuz
parents:
diff changeset
490 /// Emit the type explicitly casted to.
anatofuz
parents:
diff changeset
491 void EmitExplicitCastType(QualType Ty);
anatofuz
parents:
diff changeset
492
anatofuz
parents:
diff changeset
493 /// Emit C++ using declaration.
anatofuz
parents:
diff changeset
494 void EmitUsingDecl(const UsingDecl &UD);
anatofuz
parents:
diff changeset
495
anatofuz
parents:
diff changeset
496 /// Emit an @import declaration.
anatofuz
parents:
diff changeset
497 void EmitImportDecl(const ImportDecl &ID);
anatofuz
parents:
diff changeset
498
anatofuz
parents:
diff changeset
499 /// Emit C++ namespace alias.
anatofuz
parents:
diff changeset
500 llvm::DIImportedEntity *EmitNamespaceAlias(const NamespaceAliasDecl &NA);
anatofuz
parents:
diff changeset
501
anatofuz
parents:
diff changeset
502 /// Emit record type's standalone debug info.
anatofuz
parents:
diff changeset
503 llvm::DIType *getOrCreateRecordType(QualType Ty, SourceLocation L);
anatofuz
parents:
diff changeset
504
anatofuz
parents:
diff changeset
505 /// Emit an Objective-C interface type standalone debug info.
anatofuz
parents:
diff changeset
506 llvm::DIType *getOrCreateInterfaceType(QualType Ty, SourceLocation Loc);
anatofuz
parents:
diff changeset
507
anatofuz
parents:
diff changeset
508 /// Emit standalone debug info for a type.
anatofuz
parents:
diff changeset
509 llvm::DIType *getOrCreateStandaloneType(QualType Ty, SourceLocation Loc);
anatofuz
parents:
diff changeset
510
anatofuz
parents:
diff changeset
511 /// Add heapallocsite metadata for MSAllocator calls.
anatofuz
parents:
diff changeset
512 void addHeapAllocSiteMetadata(llvm::Instruction *CallSite, QualType Ty,
anatofuz
parents:
diff changeset
513 SourceLocation Loc);
anatofuz
parents:
diff changeset
514
anatofuz
parents:
diff changeset
515 void completeType(const EnumDecl *ED);
anatofuz
parents:
diff changeset
516 void completeType(const RecordDecl *RD);
anatofuz
parents:
diff changeset
517 void completeRequiredType(const RecordDecl *RD);
anatofuz
parents:
diff changeset
518 void completeClassData(const RecordDecl *RD);
anatofuz
parents:
diff changeset
519 void completeClass(const RecordDecl *RD);
anatofuz
parents:
diff changeset
520
anatofuz
parents:
diff changeset
521 void completeTemplateDefinition(const ClassTemplateSpecializationDecl &SD);
anatofuz
parents:
diff changeset
522 void completeUnusedClass(const CXXRecordDecl &D);
anatofuz
parents:
diff changeset
523
anatofuz
parents:
diff changeset
524 /// Create debug info for a macro defined by a #define directive or a macro
anatofuz
parents:
diff changeset
525 /// undefined by a #undef directive.
anatofuz
parents:
diff changeset
526 llvm::DIMacro *CreateMacro(llvm::DIMacroFile *Parent, unsigned MType,
anatofuz
parents:
diff changeset
527 SourceLocation LineLoc, StringRef Name,
anatofuz
parents:
diff changeset
528 StringRef Value);
anatofuz
parents:
diff changeset
529
anatofuz
parents:
diff changeset
530 /// Create debug info for a file referenced by an #include directive.
anatofuz
parents:
diff changeset
531 llvm::DIMacroFile *CreateTempMacroFile(llvm::DIMacroFile *Parent,
anatofuz
parents:
diff changeset
532 SourceLocation LineLoc,
anatofuz
parents:
diff changeset
533 SourceLocation FileLoc);
anatofuz
parents:
diff changeset
534
anatofuz
parents:
diff changeset
535 private:
anatofuz
parents:
diff changeset
536 /// Emit call to llvm.dbg.declare for a variable declaration.
anatofuz
parents:
diff changeset
537 /// Returns a pointer to the DILocalVariable associated with the
anatofuz
parents:
diff changeset
538 /// llvm.dbg.declare, or nullptr otherwise.
anatofuz
parents:
diff changeset
539 llvm::DILocalVariable *EmitDeclare(const VarDecl *decl, llvm::Value *AI,
anatofuz
parents:
diff changeset
540 llvm::Optional<unsigned> ArgNo,
anatofuz
parents:
diff changeset
541 CGBuilderTy &Builder,
anatofuz
parents:
diff changeset
542 const bool UsePointerValue = false);
anatofuz
parents:
diff changeset
543
anatofuz
parents:
diff changeset
544 struct BlockByRefType {
anatofuz
parents:
diff changeset
545 /// The wrapper struct used inside the __block_literal struct.
anatofuz
parents:
diff changeset
546 llvm::DIType *BlockByRefWrapper;
anatofuz
parents:
diff changeset
547 /// The type as it appears in the source code.
anatofuz
parents:
diff changeset
548 llvm::DIType *WrappedType;
anatofuz
parents:
diff changeset
549 };
anatofuz
parents:
diff changeset
550
anatofuz
parents:
diff changeset
551 /// Build up structure info for the byref. See \a BuildByRefType.
anatofuz
parents:
diff changeset
552 BlockByRefType EmitTypeForVarWithBlocksAttr(const VarDecl *VD,
anatofuz
parents:
diff changeset
553 uint64_t *OffSet);
anatofuz
parents:
diff changeset
554
anatofuz
parents:
diff changeset
555 /// Get context info for the DeclContext of \p Decl.
anatofuz
parents:
diff changeset
556 llvm::DIScope *getDeclContextDescriptor(const Decl *D);
anatofuz
parents:
diff changeset
557 /// Get context info for a given DeclContext \p Decl.
anatofuz
parents:
diff changeset
558 llvm::DIScope *getContextDescriptor(const Decl *Context,
anatofuz
parents:
diff changeset
559 llvm::DIScope *Default);
anatofuz
parents:
diff changeset
560
anatofuz
parents:
diff changeset
561 llvm::DIScope *getCurrentContextDescriptor(const Decl *Decl);
anatofuz
parents:
diff changeset
562
anatofuz
parents:
diff changeset
563 /// Create a forward decl for a RecordType in a given context.
anatofuz
parents:
diff changeset
564 llvm::DICompositeType *getOrCreateRecordFwdDecl(const RecordType *,
anatofuz
parents:
diff changeset
565 llvm::DIScope *);
anatofuz
parents:
diff changeset
566
anatofuz
parents:
diff changeset
567 /// Return current directory name.
anatofuz
parents:
diff changeset
568 StringRef getCurrentDirname();
anatofuz
parents:
diff changeset
569
anatofuz
parents:
diff changeset
570 /// Create new compile unit.
anatofuz
parents:
diff changeset
571 void CreateCompileUnit();
anatofuz
parents:
diff changeset
572
anatofuz
parents:
diff changeset
573 /// Compute the file checksum debug info for input file ID.
anatofuz
parents:
diff changeset
574 Optional<llvm::DIFile::ChecksumKind>
anatofuz
parents:
diff changeset
575 computeChecksum(FileID FID, SmallString<32> &Checksum) const;
anatofuz
parents:
diff changeset
576
anatofuz
parents:
diff changeset
577 /// Get the source of the given file ID.
anatofuz
parents:
diff changeset
578 Optional<StringRef> getSource(const SourceManager &SM, FileID FID);
anatofuz
parents:
diff changeset
579
anatofuz
parents:
diff changeset
580 /// Convenience function to get the file debug info descriptor for the input
anatofuz
parents:
diff changeset
581 /// location.
anatofuz
parents:
diff changeset
582 llvm::DIFile *getOrCreateFile(SourceLocation Loc);
anatofuz
parents:
diff changeset
583
anatofuz
parents:
diff changeset
584 /// Create a file debug info descriptor for a source file.
anatofuz
parents:
diff changeset
585 llvm::DIFile *
anatofuz
parents:
diff changeset
586 createFile(StringRef FileName,
anatofuz
parents:
diff changeset
587 Optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo,
anatofuz
parents:
diff changeset
588 Optional<StringRef> Source);
anatofuz
parents:
diff changeset
589
anatofuz
parents:
diff changeset
590 /// Get the type from the cache or create a new type if necessary.
anatofuz
parents:
diff changeset
591 llvm::DIType *getOrCreateType(QualType Ty, llvm::DIFile *Fg);
anatofuz
parents:
diff changeset
592
anatofuz
parents:
diff changeset
593 /// Get a reference to a clang module. If \p CreateSkeletonCU is true,
anatofuz
parents:
diff changeset
594 /// this also creates a split dwarf skeleton compile unit.
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
595 llvm::DIModule *getOrCreateModuleRef(ASTSourceDescriptor Mod,
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
596 bool CreateSkeletonCU);
150
anatofuz
parents:
diff changeset
597
anatofuz
parents:
diff changeset
598 /// DebugTypeExtRefs: If \p D originated in a clang module, return it.
anatofuz
parents:
diff changeset
599 llvm::DIModule *getParentModuleOrNull(const Decl *D);
anatofuz
parents:
diff changeset
600
anatofuz
parents:
diff changeset
601 /// Get the type from the cache or create a new partial type if
anatofuz
parents:
diff changeset
602 /// necessary.
anatofuz
parents:
diff changeset
603 llvm::DICompositeType *getOrCreateLimitedType(const RecordType *Ty,
anatofuz
parents:
diff changeset
604 llvm::DIFile *F);
anatofuz
parents:
diff changeset
605
anatofuz
parents:
diff changeset
606 /// Create type metadata for a source language type.
anatofuz
parents:
diff changeset
607 llvm::DIType *CreateTypeNode(QualType Ty, llvm::DIFile *Fg);
anatofuz
parents:
diff changeset
608
anatofuz
parents:
diff changeset
609 /// Create new member and increase Offset by FType's size.
anatofuz
parents:
diff changeset
610 llvm::DIType *CreateMemberType(llvm::DIFile *Unit, QualType FType,
anatofuz
parents:
diff changeset
611 StringRef Name, uint64_t *Offset);
anatofuz
parents:
diff changeset
612
anatofuz
parents:
diff changeset
613 /// Retrieve the DIDescriptor, if any, for the canonical form of this
anatofuz
parents:
diff changeset
614 /// declaration.
anatofuz
parents:
diff changeset
615 llvm::DINode *getDeclarationOrDefinition(const Decl *D);
anatofuz
parents:
diff changeset
616
anatofuz
parents:
diff changeset
617 /// \return debug info descriptor to describe method
anatofuz
parents:
diff changeset
618 /// declaration for the given method definition.
anatofuz
parents:
diff changeset
619 llvm::DISubprogram *getFunctionDeclaration(const Decl *D);
anatofuz
parents:
diff changeset
620
anatofuz
parents:
diff changeset
621 /// \return debug info descriptor to the describe method declaration
anatofuz
parents:
diff changeset
622 /// for the given method definition.
anatofuz
parents:
diff changeset
623 /// \param FnType For Objective-C methods, their type.
anatofuz
parents:
diff changeset
624 /// \param LineNo The declaration's line number.
anatofuz
parents:
diff changeset
625 /// \param Flags The DIFlags for the method declaration.
anatofuz
parents:
diff changeset
626 /// \param SPFlags The subprogram-spcific flags for the method declaration.
anatofuz
parents:
diff changeset
627 llvm::DISubprogram *
anatofuz
parents:
diff changeset
628 getObjCMethodDeclaration(const Decl *D, llvm::DISubroutineType *FnType,
anatofuz
parents:
diff changeset
629 unsigned LineNo, llvm::DINode::DIFlags Flags,
anatofuz
parents:
diff changeset
630 llvm::DISubprogram::DISPFlags SPFlags);
anatofuz
parents:
diff changeset
631
anatofuz
parents:
diff changeset
632 /// \return debug info descriptor to describe in-class static data
anatofuz
parents:
diff changeset
633 /// member declaration for the given out-of-class definition. If D
anatofuz
parents:
diff changeset
634 /// is an out-of-class definition of a static data member of a
anatofuz
parents:
diff changeset
635 /// class, find its corresponding in-class declaration.
anatofuz
parents:
diff changeset
636 llvm::DIDerivedType *
anatofuz
parents:
diff changeset
637 getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D);
anatofuz
parents:
diff changeset
638
anatofuz
parents:
diff changeset
639 /// Helper that either creates a forward declaration or a stub.
anatofuz
parents:
diff changeset
640 llvm::DISubprogram *getFunctionFwdDeclOrStub(GlobalDecl GD, bool Stub);
anatofuz
parents:
diff changeset
641
anatofuz
parents:
diff changeset
642 /// Create a subprogram describing the forward declaration
anatofuz
parents:
diff changeset
643 /// represented in the given FunctionDecl wrapped in a GlobalDecl.
anatofuz
parents:
diff changeset
644 llvm::DISubprogram *getFunctionForwardDeclaration(GlobalDecl GD);
anatofuz
parents:
diff changeset
645
anatofuz
parents:
diff changeset
646 /// Create a DISubprogram describing the function
anatofuz
parents:
diff changeset
647 /// represented in the given FunctionDecl wrapped in a GlobalDecl.
anatofuz
parents:
diff changeset
648 llvm::DISubprogram *getFunctionStub(GlobalDecl GD);
anatofuz
parents:
diff changeset
649
anatofuz
parents:
diff changeset
650 /// Create a global variable describing the forward declaration
anatofuz
parents:
diff changeset
651 /// represented in the given VarDecl.
anatofuz
parents:
diff changeset
652 llvm::DIGlobalVariable *
anatofuz
parents:
diff changeset
653 getGlobalVariableForwardDeclaration(const VarDecl *VD);
anatofuz
parents:
diff changeset
654
anatofuz
parents:
diff changeset
655 /// Return a global variable that represents one of the collection of global
anatofuz
parents:
diff changeset
656 /// variables created for an anonmyous union.
anatofuz
parents:
diff changeset
657 ///
anatofuz
parents:
diff changeset
658 /// Recursively collect all of the member fields of a global
anatofuz
parents:
diff changeset
659 /// anonymous decl and create static variables for them. The first
anatofuz
parents:
diff changeset
660 /// time this is called it needs to be on a union and then from
anatofuz
parents:
diff changeset
661 /// there we can have additional unnamed fields.
anatofuz
parents:
diff changeset
662 llvm::DIGlobalVariableExpression *
anatofuz
parents:
diff changeset
663 CollectAnonRecordDecls(const RecordDecl *RD, llvm::DIFile *Unit,
anatofuz
parents:
diff changeset
664 unsigned LineNo, StringRef LinkageName,
anatofuz
parents:
diff changeset
665 llvm::GlobalVariable *Var, llvm::DIScope *DContext);
anatofuz
parents:
diff changeset
666
anatofuz
parents:
diff changeset
667
anatofuz
parents:
diff changeset
668 /// Return flags which enable debug info emission for call sites, provided
anatofuz
parents:
diff changeset
669 /// that it is supported and enabled.
anatofuz
parents:
diff changeset
670 llvm::DINode::DIFlags getCallSiteRelatedAttrs() const;
anatofuz
parents:
diff changeset
671
anatofuz
parents:
diff changeset
672 /// Get the printing policy for producing names for debug info.
anatofuz
parents:
diff changeset
673 PrintingPolicy getPrintingPolicy() const;
anatofuz
parents:
diff changeset
674
anatofuz
parents:
diff changeset
675 /// Get function name for the given FunctionDecl. If the name is
anatofuz
parents:
diff changeset
676 /// constructed on demand (e.g., C++ destructor) then the name is
anatofuz
parents:
diff changeset
677 /// stored on the side.
anatofuz
parents:
diff changeset
678 StringRef getFunctionName(const FunctionDecl *FD);
anatofuz
parents:
diff changeset
679
anatofuz
parents:
diff changeset
680 /// Returns the unmangled name of an Objective-C method.
anatofuz
parents:
diff changeset
681 /// This is the display name for the debugging info.
anatofuz
parents:
diff changeset
682 StringRef getObjCMethodName(const ObjCMethodDecl *FD);
anatofuz
parents:
diff changeset
683
anatofuz
parents:
diff changeset
684 /// Return selector name. This is used for debugging
anatofuz
parents:
diff changeset
685 /// info.
anatofuz
parents:
diff changeset
686 StringRef getSelectorName(Selector S);
anatofuz
parents:
diff changeset
687
anatofuz
parents:
diff changeset
688 /// Get class name including template argument list.
anatofuz
parents:
diff changeset
689 StringRef getClassName(const RecordDecl *RD);
anatofuz
parents:
diff changeset
690
anatofuz
parents:
diff changeset
691 /// Get the vtable name for the given class.
anatofuz
parents:
diff changeset
692 StringRef getVTableName(const CXXRecordDecl *Decl);
anatofuz
parents:
diff changeset
693
anatofuz
parents:
diff changeset
694 /// Get the name to use in the debug info for a dynamic initializer or atexit
anatofuz
parents:
diff changeset
695 /// stub function.
anatofuz
parents:
diff changeset
696 StringRef getDynamicInitializerName(const VarDecl *VD,
anatofuz
parents:
diff changeset
697 DynamicInitKind StubKind,
anatofuz
parents:
diff changeset
698 llvm::Function *InitFn);
anatofuz
parents:
diff changeset
699
anatofuz
parents:
diff changeset
700 /// Get line number for the location. If location is invalid
anatofuz
parents:
diff changeset
701 /// then use current location.
anatofuz
parents:
diff changeset
702 unsigned getLineNumber(SourceLocation Loc);
anatofuz
parents:
diff changeset
703
anatofuz
parents:
diff changeset
704 /// Get column number for the location. If location is
anatofuz
parents:
diff changeset
705 /// invalid then use current location.
anatofuz
parents:
diff changeset
706 /// \param Force Assume DebugColumnInfo option is true.
anatofuz
parents:
diff changeset
707 unsigned getColumnNumber(SourceLocation Loc, bool Force = false);
anatofuz
parents:
diff changeset
708
anatofuz
parents:
diff changeset
709 /// Collect various properties of a FunctionDecl.
anatofuz
parents:
diff changeset
710 /// \param GD A GlobalDecl whose getDecl() must return a FunctionDecl.
anatofuz
parents:
diff changeset
711 void collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit,
anatofuz
parents:
diff changeset
712 StringRef &Name, StringRef &LinkageName,
anatofuz
parents:
diff changeset
713 llvm::DIScope *&FDContext,
anatofuz
parents:
diff changeset
714 llvm::DINodeArray &TParamsArray,
anatofuz
parents:
diff changeset
715 llvm::DINode::DIFlags &Flags);
anatofuz
parents:
diff changeset
716
anatofuz
parents:
diff changeset
717 /// Collect various properties of a VarDecl.
anatofuz
parents:
diff changeset
718 void collectVarDeclProps(const VarDecl *VD, llvm::DIFile *&Unit,
anatofuz
parents:
diff changeset
719 unsigned &LineNo, QualType &T, StringRef &Name,
anatofuz
parents:
diff changeset
720 StringRef &LinkageName,
anatofuz
parents:
diff changeset
721 llvm::MDTuple *&TemplateParameters,
anatofuz
parents:
diff changeset
722 llvm::DIScope *&VDContext);
anatofuz
parents:
diff changeset
723
anatofuz
parents:
diff changeset
724 /// Allocate a copy of \p A using the DebugInfoNames allocator
anatofuz
parents:
diff changeset
725 /// and return a reference to it. If multiple arguments are given the strings
anatofuz
parents:
diff changeset
726 /// are concatenated.
anatofuz
parents:
diff changeset
727 StringRef internString(StringRef A, StringRef B = StringRef()) {
anatofuz
parents:
diff changeset
728 char *Data = DebugInfoNames.Allocate<char>(A.size() + B.size());
anatofuz
parents:
diff changeset
729 if (!A.empty())
anatofuz
parents:
diff changeset
730 std::memcpy(Data, A.data(), A.size());
anatofuz
parents:
diff changeset
731 if (!B.empty())
anatofuz
parents:
diff changeset
732 std::memcpy(Data + A.size(), B.data(), B.size());
anatofuz
parents:
diff changeset
733 return StringRef(Data, A.size() + B.size());
anatofuz
parents:
diff changeset
734 }
anatofuz
parents:
diff changeset
735 };
anatofuz
parents:
diff changeset
736
anatofuz
parents:
diff changeset
737 /// A scoped helper to set the current debug location to the specified
anatofuz
parents:
diff changeset
738 /// location or preferred location of the specified Expr.
anatofuz
parents:
diff changeset
739 class ApplyDebugLocation {
anatofuz
parents:
diff changeset
740 private:
anatofuz
parents:
diff changeset
741 void init(SourceLocation TemporaryLocation, bool DefaultToEmpty = false);
anatofuz
parents:
diff changeset
742 ApplyDebugLocation(CodeGenFunction &CGF, bool DefaultToEmpty,
anatofuz
parents:
diff changeset
743 SourceLocation TemporaryLocation);
anatofuz
parents:
diff changeset
744
anatofuz
parents:
diff changeset
745 llvm::DebugLoc OriginalLocation;
anatofuz
parents:
diff changeset
746 CodeGenFunction *CGF;
anatofuz
parents:
diff changeset
747
anatofuz
parents:
diff changeset
748 public:
anatofuz
parents:
diff changeset
749 /// Set the location to the (valid) TemporaryLocation.
anatofuz
parents:
diff changeset
750 ApplyDebugLocation(CodeGenFunction &CGF, SourceLocation TemporaryLocation);
anatofuz
parents:
diff changeset
751 ApplyDebugLocation(CodeGenFunction &CGF, const Expr *E);
anatofuz
parents:
diff changeset
752 ApplyDebugLocation(CodeGenFunction &CGF, llvm::DebugLoc Loc);
anatofuz
parents:
diff changeset
753 ApplyDebugLocation(ApplyDebugLocation &&Other) : CGF(Other.CGF) {
anatofuz
parents:
diff changeset
754 Other.CGF = nullptr;
anatofuz
parents:
diff changeset
755 }
anatofuz
parents:
diff changeset
756 ApplyDebugLocation &operator=(ApplyDebugLocation &&) = default;
anatofuz
parents:
diff changeset
757
anatofuz
parents:
diff changeset
758 ~ApplyDebugLocation();
anatofuz
parents:
diff changeset
759
anatofuz
parents:
diff changeset
760 /// Apply TemporaryLocation if it is valid. Otherwise switch
anatofuz
parents:
diff changeset
761 /// to an artificial debug location that has a valid scope, but no
anatofuz
parents:
diff changeset
762 /// line information.
anatofuz
parents:
diff changeset
763 ///
anatofuz
parents:
diff changeset
764 /// Artificial locations are useful when emitting compiler-generated
anatofuz
parents:
diff changeset
765 /// helper functions that have no source location associated with
anatofuz
parents:
diff changeset
766 /// them. The DWARF specification allows the compiler to use the
anatofuz
parents:
diff changeset
767 /// special line number 0 to indicate code that can not be
anatofuz
parents:
diff changeset
768 /// attributed to any source location. Note that passing an empty
anatofuz
parents:
diff changeset
769 /// SourceLocation to CGDebugInfo::setLocation() will result in the
anatofuz
parents:
diff changeset
770 /// last valid location being reused.
anatofuz
parents:
diff changeset
771 static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF) {
anatofuz
parents:
diff changeset
772 return ApplyDebugLocation(CGF, false, SourceLocation());
anatofuz
parents:
diff changeset
773 }
anatofuz
parents:
diff changeset
774 /// Apply TemporaryLocation if it is valid. Otherwise switch
anatofuz
parents:
diff changeset
775 /// to an artificial debug location that has a valid scope, but no
anatofuz
parents:
diff changeset
776 /// line information.
anatofuz
parents:
diff changeset
777 static ApplyDebugLocation
anatofuz
parents:
diff changeset
778 CreateDefaultArtificial(CodeGenFunction &CGF,
anatofuz
parents:
diff changeset
779 SourceLocation TemporaryLocation) {
anatofuz
parents:
diff changeset
780 return ApplyDebugLocation(CGF, false, TemporaryLocation);
anatofuz
parents:
diff changeset
781 }
anatofuz
parents:
diff changeset
782
anatofuz
parents:
diff changeset
783 /// Set the IRBuilder to not attach debug locations. Note that
anatofuz
parents:
diff changeset
784 /// passing an empty SourceLocation to \a CGDebugInfo::setLocation()
anatofuz
parents:
diff changeset
785 /// will result in the last valid location being reused. Note that
anatofuz
parents:
diff changeset
786 /// all instructions that do not have a location at the beginning of
anatofuz
parents:
diff changeset
787 /// a function are counted towards to function prologue.
anatofuz
parents:
diff changeset
788 static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF) {
anatofuz
parents:
diff changeset
789 return ApplyDebugLocation(CGF, true, SourceLocation());
anatofuz
parents:
diff changeset
790 }
anatofuz
parents:
diff changeset
791 };
anatofuz
parents:
diff changeset
792
anatofuz
parents:
diff changeset
793 /// A scoped helper to set the current debug location to an inlined location.
anatofuz
parents:
diff changeset
794 class ApplyInlineDebugLocation {
anatofuz
parents:
diff changeset
795 SourceLocation SavedLocation;
anatofuz
parents:
diff changeset
796 CodeGenFunction *CGF;
anatofuz
parents:
diff changeset
797
anatofuz
parents:
diff changeset
798 public:
anatofuz
parents:
diff changeset
799 /// Set up the CodeGenFunction's DebugInfo to produce inline locations for the
anatofuz
parents:
diff changeset
800 /// function \p InlinedFn. The current debug location becomes the inlined call
anatofuz
parents:
diff changeset
801 /// site of the inlined function.
anatofuz
parents:
diff changeset
802 ApplyInlineDebugLocation(CodeGenFunction &CGF, GlobalDecl InlinedFn);
anatofuz
parents:
diff changeset
803 /// Restore everything back to the original state.
anatofuz
parents:
diff changeset
804 ~ApplyInlineDebugLocation();
anatofuz
parents:
diff changeset
805 };
anatofuz
parents:
diff changeset
806
anatofuz
parents:
diff changeset
807 } // namespace CodeGen
anatofuz
parents:
diff changeset
808 } // namespace clang
anatofuz
parents:
diff changeset
809
anatofuz
parents:
diff changeset
810 #endif // LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H