blob: 89d592e7d2ea1fbfc8f813799dcb8d88805d150f [file] [log] [blame]
Guy Benyei7f92f2d2012-12-18 14:30:41 +00001//===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -------------*- 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//
Stephen Hinesc568f1e2014-07-21 00:47:37 -070010// This is the source-level debug info generator for llvm translation.
Guy Benyei7f92f2d2012-12-18 14:30:41 +000011//
12//===----------------------------------------------------------------------===//
13
Stephen Hines176edba2014-12-01 14:53:08 -080014#ifndef LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
15#define LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
Guy Benyei7f92f2d2012-12-18 14:30:41 +000016
17#include "CGBuilder.h"
18#include "clang/AST/Expr.h"
19#include "clang/AST/Type.h"
20#include "clang/Basic/SourceLocation.h"
Eric Christopher13c97672013-05-16 00:45:23 +000021#include "clang/Frontend/CodeGenOptions.h"
Guy Benyei7f92f2d2012-12-18 14:30:41 +000022#include "llvm/ADT/DenseMap.h"
Stephen Hines651f13c2014-04-23 16:59:28 -070023#include "llvm/IR/DIBuilder.h"
24#include "llvm/IR/DebugInfo.h"
25#include "llvm/IR/ValueHandle.h"
Guy Benyei7f92f2d2012-12-18 14:30:41 +000026#include "llvm/Support/Allocator.h"
Guy Benyei7f92f2d2012-12-18 14:30:41 +000027
28namespace llvm {
29 class MDNode;
30}
31
32namespace clang {
33 class CXXMethodDecl;
34 class VarDecl;
35 class ObjCInterfaceDecl;
Adrian Prantl4919de62013-03-06 22:03:30 +000036 class ObjCIvarDecl;
Guy Benyei7f92f2d2012-12-18 14:30:41 +000037 class ClassTemplateSpecializationDecl;
38 class GlobalDecl;
David Blaikie9faebd22013-05-20 04:58:53 +000039 class UsingDecl;
Guy Benyei7f92f2d2012-12-18 14:30:41 +000040
41namespace CodeGen {
42 class CodeGenModule;
43 class CodeGenFunction;
44 class CGBlockInfo;
45
46/// CGDebugInfo - This class gathers all debug information during compilation
47/// and is responsible for emitting to llvm globals or pass directly to
48/// the backend.
49class CGDebugInfo {
Adrian Prantlb061ce22013-07-18 01:36:04 +000050 friend class ArtificialLocation;
Stephen Hines651f13c2014-04-23 16:59:28 -070051 friend class SaveAndRestoreLocation;
Guy Benyei7f92f2d2012-12-18 14:30:41 +000052 CodeGenModule &CGM;
Eric Christopher3a7d82c2013-05-20 19:59:06 +000053 const CodeGenOptions::DebugInfoKind DebugKind;
Guy Benyei7f92f2d2012-12-18 14:30:41 +000054 llvm::DIBuilder DBuilder;
55 llvm::DICompileUnit TheCU;
56 SourceLocation CurLoc, PrevLoc;
57 llvm::DIType VTablePtrType;
58 llvm::DIType ClassTy;
Eric Christopherf068c922013-04-02 22:59:11 +000059 llvm::DICompositeType ObjTy;
Guy Benyei7f92f2d2012-12-18 14:30:41 +000060 llvm::DIType SelTy;
Guy Benyeib13621d2012-12-18 14:38:23 +000061 llvm::DIType OCLImage1dDITy, OCLImage1dArrayDITy, OCLImage1dBufferDITy;
62 llvm::DIType OCLImage2dDITy, OCLImage2dArrayDITy;
63 llvm::DIType OCLImage3dDITy;
Guy Benyeie6b9d802013-01-20 12:31:11 +000064 llvm::DIType OCLEventDITy;
Eric Christopher688cf5b2013-07-14 21:12:44 +000065 llvm::DIType BlockLiteralGeneric;
Eric Christopher7c811dc2013-05-16 00:52:23 +000066
Guy Benyei7f92f2d2012-12-18 14:30:41 +000067 /// TypeCache - Cache of previously constructed Types.
Stephen Hines6bcf27b2014-05-29 04:14:42 -070068 llvm::DenseMap<const void *, llvm::WeakVH> TypeCache;
69
70 struct ObjCInterfaceCacheEntry {
71 const ObjCInterfaceType *Type;
72 llvm::DIType Decl;
73 llvm::DIFile Unit;
74 ObjCInterfaceCacheEntry(const ObjCInterfaceType *Type, llvm::DIType Decl,
75 llvm::DIFile Unit)
76 : Type(Type), Decl(Decl), Unit(Unit) {}
77 };
Guy Benyei7f92f2d2012-12-18 14:30:41 +000078
Adrian Prantl4919de62013-03-06 22:03:30 +000079 /// ObjCInterfaceCache - Cache of previously constructed interfaces
Stephen Hines6bcf27b2014-05-29 04:14:42 -070080 /// which may change.
81 llvm::SmallVector<ObjCInterfaceCacheEntry, 32> ObjCInterfaceCache;
Adrian Prantl4919de62013-03-06 22:03:30 +000082
Adrian Prantlebbd7e02013-03-11 18:33:46 +000083 /// RetainedTypes - list of interfaces we want to keep even if orphaned.
84 std::vector<void *> RetainedTypes;
85
Guy Benyei7f92f2d2012-12-18 14:30:41 +000086 /// ReplaceMap - Cache of forward declared types to RAUW at the end of
87 /// compilation.
Stephen Hines6bcf27b2014-05-29 04:14:42 -070088 std::vector<std::pair<const TagType *, llvm::WeakVH>> ReplaceMap;
Guy Benyei7f92f2d2012-12-18 14:30:41 +000089
Stephen Hines176edba2014-12-01 14:53:08 -080090 /// \brief Cache of replaceable forward declarartions (functions and
91 /// variables) to RAUW at the end of compilation.
92 std::vector<std::pair<const DeclaratorDecl *, llvm::WeakVH>> FwdDeclReplaceMap;
93
Guy Benyei7f92f2d2012-12-18 14:30:41 +000094 // LexicalBlockStack - Keep track of our current nested lexical block.
95 std::vector<llvm::TrackingVH<llvm::MDNode> > LexicalBlockStack;
96 llvm::DenseMap<const Decl *, llvm::WeakVH> RegionMap;
97 // FnBeginRegionCount - Keep track of LexicalBlockStack counter at the
98 // beginning of a function. This is used to pop unbalanced regions at
99 // the end of a function.
100 std::vector<unsigned> FnBeginRegionCount;
101
102 /// DebugInfoNames - This is a storage for names that are
103 /// constructed on demand. For example, C++ destructors, C++ operators etc..
104 llvm::BumpPtrAllocator DebugInfoNames;
105 StringRef CWDName;
106
107 llvm::DenseMap<const char *, llvm::WeakVH> DIFileCache;
108 llvm::DenseMap<const FunctionDecl *, llvm::WeakVH> SPCache;
David Blaikie9faebd22013-05-20 04:58:53 +0000109 /// \brief Cache declarations relevant to DW_TAG_imported_declarations (C++
110 /// using declarations) that aren't covered by other more specific caches.
111 llvm::DenseMap<const Decl *, llvm::WeakVH> DeclCache;
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000112 llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH> NameSpaceCache;
David Blaikiefc46ebc2013-05-20 22:50:41 +0000113 llvm::DenseMap<const NamespaceAliasDecl *, llvm::WeakVH> NamespaceAliasCache;
Eric Christopher0395de32013-01-16 01:22:32 +0000114 llvm::DenseMap<const Decl *, llvm::WeakVH> StaticDataMemberCache;
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000115
116 /// Helper functions for getOrCreateType.
Adrian Prantl4919de62013-03-06 22:03:30 +0000117 unsigned Checksum(const ObjCInterfaceDecl *InterfaceDecl);
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000118 llvm::DIType CreateType(const BuiltinType *Ty);
119 llvm::DIType CreateType(const ComplexType *Ty);
David Blaikie29b8b682013-09-04 22:03:57 +0000120 llvm::DIType CreateQualifiedType(QualType Ty, llvm::DIFile Fg);
121 llvm::DIType CreateType(const TypedefType *Ty, llvm::DIFile Fg);
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700122 llvm::DIType CreateType(const TemplateSpecializationType *Ty, llvm::DIFile Fg);
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000123 llvm::DIType CreateType(const ObjCObjectPointerType *Ty,
124 llvm::DIFile F);
125 llvm::DIType CreateType(const PointerType *Ty, llvm::DIFile F);
126 llvm::DIType CreateType(const BlockPointerType *Ty, llvm::DIFile F);
127 llvm::DIType CreateType(const FunctionType *Ty, llvm::DIFile F);
David Blaikie29b8b682013-09-04 22:03:57 +0000128 llvm::DIType CreateType(const RecordType *Tyg);
David Blaikie27804892013-08-15 20:49:17 +0000129 llvm::DIType CreateTypeDefinition(const RecordType *Ty);
David Blaikieeaacc882013-08-20 21:03:29 +0000130 llvm::DICompositeType CreateLimitedType(const RecordType *Ty);
David Blaikie498298d2013-08-18 16:55:33 +0000131 void CollectContainingType(const CXXRecordDecl *RD, llvm::DICompositeType CT);
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000132 llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DIFile F);
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700133 llvm::DIType CreateTypeDefinition(const ObjCInterfaceType *Ty, llvm::DIFile F);
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000134 llvm::DIType CreateType(const ObjCObjectType *Ty, llvm::DIFile F);
135 llvm::DIType CreateType(const VectorType *Ty, llvm::DIFile F);
136 llvm::DIType CreateType(const ArrayType *Ty, llvm::DIFile F);
137 llvm::DIType CreateType(const LValueReferenceType *Ty, llvm::DIFile F);
138 llvm::DIType CreateType(const RValueReferenceType *Ty, llvm::DIFile Unit);
139 llvm::DIType CreateType(const MemberPointerType *Ty, llvm::DIFile F);
140 llvm::DIType CreateType(const AtomicType *Ty, llvm::DIFile F);
Manman Renf3327332013-08-28 21:20:28 +0000141 llvm::DIType CreateEnumType(const EnumType *Ty);
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700142 llvm::DIType CreateTypeDefinition(const EnumType *Ty);
Adrian Prantle86fcc42013-03-29 19:20:29 +0000143 llvm::DIType CreateSelfType(const QualType &QualTy, llvm::DIType Ty);
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000144 llvm::DIType getTypeOrNull(const QualType);
David Blaikie9a845292013-05-22 23:22:42 +0000145 llvm::DICompositeType getOrCreateMethodType(const CXXMethodDecl *Method,
146 llvm::DIFile F);
147 llvm::DICompositeType getOrCreateInstanceMethodType(
David Blaikie9c78f9b2013-01-07 23:06:35 +0000148 QualType ThisPtr, const FunctionProtoType *Func, llvm::DIFile Unit);
David Blaikie9a845292013-05-22 23:22:42 +0000149 llvm::DICompositeType getOrCreateFunctionType(const Decl *D, QualType FnType,
150 llvm::DIFile F);
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000151 llvm::DIType getOrCreateVTablePtrType(llvm::DIFile F);
152 llvm::DINameSpace getOrCreateNameSpace(const NamespaceDecl *N);
David Blaikieb0f77b02013-05-24 21:33:22 +0000153 llvm::DIType getOrCreateTypeDeclaration(QualType PointeeTy, llvm::DIFile F);
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700154 llvm::DIType CreatePointerLikeType(llvm::dwarf::Tag Tag,
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000155 const Type *Ty, QualType PointeeTy,
156 llvm::DIFile F);
Guy Benyeib13621d2012-12-18 14:38:23 +0000157
Adrian Prantlebbd7e02013-03-11 18:33:46 +0000158 llvm::Value *getCachedInterfaceTypeOrNull(const QualType Ty);
Guy Benyeib13621d2012-12-18 14:38:23 +0000159 llvm::DIType getOrCreateStructPtrType(StringRef Name, llvm::DIType &Cache);
160
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000161 llvm::DISubprogram CreateCXXMemberFunction(const CXXMethodDecl *Method,
162 llvm::DIFile F,
163 llvm::DIType RecordTy);
Eric Christopher7c811dc2013-05-16 00:52:23 +0000164
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000165 void CollectCXXMemberFunctions(const CXXRecordDecl *Decl,
166 llvm::DIFile F,
167 SmallVectorImpl<llvm::Value *> &E,
168 llvm::DIType T);
169
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000170 void CollectCXXBases(const CXXRecordDecl *Decl,
171 llvm::DIFile F,
172 SmallVectorImpl<llvm::Value *> &EltTys,
173 llvm::DIType RecordTy);
Eric Christopher7c811dc2013-05-16 00:52:23 +0000174
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000175 llvm::DIArray
176 CollectTemplateParams(const TemplateParameterList *TPList,
David Blaikie35178dc2013-06-22 18:59:18 +0000177 ArrayRef<TemplateArgument> TAList,
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000178 llvm::DIFile Unit);
179 llvm::DIArray
180 CollectFunctionTemplateParams(const FunctionDecl *FD, llvm::DIFile Unit);
Eric Christopher7c811dc2013-05-16 00:52:23 +0000181 llvm::DIArray
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000182 CollectCXXTemplateParams(const ClassTemplateSpecializationDecl *TS,
183 llvm::DIFile F);
184
185 llvm::DIType createFieldType(StringRef name, QualType type,
186 uint64_t sizeInBitsOverride, SourceLocation loc,
Stephen Hines176edba2014-12-01 14:53:08 -0800187 AccessSpecifier AS,
188 uint64_t offsetInBits,
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000189 llvm::DIFile tunit,
Stephen Hines176edba2014-12-01 14:53:08 -0800190 llvm::DIScope scope,
191 const RecordDecl* RD = nullptr);
Eric Christopher0395de32013-01-16 01:22:32 +0000192
193 // Helpers for collecting fields of a record.
194 void CollectRecordLambdaFields(const CXXRecordDecl *CXXDecl,
195 SmallVectorImpl<llvm::Value *> &E,
196 llvm::DIType RecordTy);
David Blaikiecbcb0302013-08-15 22:50:29 +0000197 llvm::DIDerivedType CreateRecordStaticField(const VarDecl *Var,
Stephen Hines176edba2014-12-01 14:53:08 -0800198 llvm::DIType RecordTy,
199 const RecordDecl* RD);
Eric Christopher0395de32013-01-16 01:22:32 +0000200 void CollectRecordNormalField(const FieldDecl *Field, uint64_t OffsetInBits,
201 llvm::DIFile F,
202 SmallVectorImpl<llvm::Value *> &E,
Stephen Hines176edba2014-12-01 14:53:08 -0800203 llvm::DIType RecordTy,
204 const RecordDecl* RD);
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000205 void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile F,
206 SmallVectorImpl<llvm::Value *> &E,
David Blaikie841fd112013-08-16 20:40:25 +0000207 llvm::DICompositeType RecordTy);
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000208
209 void CollectVTableInfo(const CXXRecordDecl *Decl,
210 llvm::DIFile F,
211 SmallVectorImpl<llvm::Value *> &EltTys);
212
213 // CreateLexicalBlock - Create a new lexical block node and push it on
214 // the stack.
215 void CreateLexicalBlock(SourceLocation Loc);
Eric Christopher7c811dc2013-05-16 00:52:23 +0000216
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000217public:
218 CGDebugInfo(CodeGenModule &CGM);
219 ~CGDebugInfo();
220
221 void finalize();
222
223 /// setLocation - Update the current source location. If \arg loc is
224 /// invalid it is ignored.
225 void setLocation(SourceLocation Loc);
226
Adrian Prantl59f0a5a2013-05-16 00:41:29 +0000227 /// getLocation - Return the current source location.
228 SourceLocation getLocation() const { return CurLoc; }
229
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000230 /// EmitLocation - Emit metadata to indicate a change in line/column
231 /// information in the source file.
Adrian Prantl00df5ea2013-03-12 20:43:25 +0000232 /// \param ForceColumnInfo Assume DebugColumnInfo option is true.
233 void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc,
234 bool ForceColumnInfo = false);
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000235
236 /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
237 /// start of a new function.
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700238 /// \param Loc The location of the function header.
239 /// \param ScopeLoc The location of the function body.
240 void EmitFunctionStart(GlobalDecl GD,
241 SourceLocation Loc, SourceLocation ScopeLoc,
242 QualType FnType, llvm::Function *Fn,
243 CGBuilderTy &Builder);
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000244
245 /// EmitFunctionEnd - Constructs the debug code for exiting a function.
246 void EmitFunctionEnd(CGBuilderTy &Builder);
247
248 /// EmitLexicalBlockStart - Emit metadata to indicate the beginning of a
249 /// new lexical block and push the block onto the stack.
250 void EmitLexicalBlockStart(CGBuilderTy &Builder, SourceLocation Loc);
251
252 /// EmitLexicalBlockEnd - Emit metadata to indicate the end of a new lexical
253 /// block and pop the current block.
254 void EmitLexicalBlockEnd(CGBuilderTy &Builder, SourceLocation Loc);
255
256 /// EmitDeclareOfAutoVariable - Emit call to llvm.dbg.declare for an automatic
257 /// variable declaration.
258 void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI,
259 CGBuilderTy &Builder);
260
261 /// EmitDeclareOfBlockDeclRefVariable - Emit call to llvm.dbg.declare for an
262 /// imported variable declaration in a block.
263 void EmitDeclareOfBlockDeclRefVariable(const VarDecl *variable,
264 llvm::Value *storage,
265 CGBuilderTy &Builder,
Stephen Hines176edba2014-12-01 14:53:08 -0800266 const CGBlockInfo &blockInfo,
267 llvm::Instruction *InsertPoint = 0);
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000268
269 /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument
270 /// variable declaration.
271 void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI,
272 unsigned ArgNo, CGBuilderTy &Builder);
273
274 /// EmitDeclareOfBlockLiteralArgVariable - Emit call to
275 /// llvm.dbg.declare for the block-literal argument to a block
276 /// invocation function.
277 void EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
Stephen Hines176edba2014-12-01 14:53:08 -0800278 llvm::Value *Arg, unsigned ArgNo,
Adrian Prantl836e7c92013-03-14 17:53:33 +0000279 llvm::Value *LocalAddr,
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000280 CGBuilderTy &Builder);
281
282 /// EmitGlobalVariable - Emit information about a global variable.
Yunzhong Gao3b8e0b72013-08-30 08:53:09 +0000283 void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000284
Yunzhong Gao3b8e0b72013-08-30 08:53:09 +0000285 /// EmitGlobalVariable - Emit global variable's debug info.
286 void EmitGlobalVariable(const ValueDecl *VD, llvm::Constant *Init);
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000287
David Blaikie957dac52013-04-22 06:13:21 +0000288 /// \brief - Emit C++ using directive.
289 void EmitUsingDirective(const UsingDirectiveDecl &UD);
290
Stephen Hines176edba2014-12-01 14:53:08 -0800291 /// EmitExplicitCastType - Emit the type explicitly casted to.
292 void EmitExplicitCastType(QualType Ty);
293
David Blaikie9faebd22013-05-20 04:58:53 +0000294 /// \brief - Emit C++ using declaration.
295 void EmitUsingDecl(const UsingDecl &UD);
296
David Blaikiefc46ebc2013-05-20 22:50:41 +0000297 /// \brief - Emit C++ namespace alias.
298 llvm::DIImportedEntity EmitNamespaceAlias(const NamespaceAliasDecl &NA);
299
Eric Christopher7c811dc2013-05-16 00:52:23 +0000300 /// getOrCreateRecordType - Emit record type's standalone debug info.
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000301 llvm::DIType getOrCreateRecordType(QualType Ty, SourceLocation L);
302
303 /// getOrCreateInterfaceType - Emit an objective c interface type standalone
304 /// debug info.
305 llvm::DIType getOrCreateInterfaceType(QualType Ty,
Eric Christopher13c97672013-05-16 00:45:23 +0000306 SourceLocation Loc);
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000307
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700308 void completeType(const EnumDecl *ED);
David Blaikie27804892013-08-15 20:49:17 +0000309 void completeType(const RecordDecl *RD);
310 void completeRequiredType(const RecordDecl *RD);
David Blaikie5434fc22013-08-20 01:28:15 +0000311 void completeClassData(const RecordDecl *RD);
David Blaikieeab6a362013-06-21 00:40:50 +0000312
Stephen Hines651f13c2014-04-23 16:59:28 -0700313 void completeTemplateDefinition(const ClassTemplateSpecializationDecl &SD);
314
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000315private:
316 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700317 /// Tag accepts custom types DW_TAG_arg_variable and DW_TAG_auto_variable,
318 /// otherwise would be of type llvm::dwarf::Tag.
319 void EmitDeclare(const VarDecl *decl, llvm::dwarf::LLVMConstants Tag,
320 llvm::Value *AI, unsigned ArgNo, CGBuilderTy &Builder);
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000321
Eric Christopher7c811dc2013-05-16 00:52:23 +0000322 // EmitTypeForVarWithBlocksAttr - Build up structure info for the byref.
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000323 // See BuildByRefType.
324 llvm::DIType EmitTypeForVarWithBlocksAttr(const VarDecl *VD,
325 uint64_t *OffSet);
326
327 /// getContextDescriptor - Get context info for the decl.
David Blaikiebb000792013-04-19 06:56:38 +0000328 llvm::DIScope getContextDescriptor(const Decl *Decl);
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000329
David Blaikie9faebd22013-05-20 04:58:53 +0000330 llvm::DIScope getCurrentContextDescriptor(const Decl *Decl);
331
David Blaikie951094b2013-08-15 18:59:40 +0000332 /// \brief Create a forward decl for a RecordType in a given context.
Manman Renf3327332013-08-28 21:20:28 +0000333 llvm::DICompositeType getOrCreateRecordFwdDecl(const RecordType *,
David Blaikieeaacc882013-08-20 21:03:29 +0000334 llvm::DIDescriptor);
Eric Christopher7c811dc2013-05-16 00:52:23 +0000335
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000336 /// createContextChain - Create a set of decls for the context chain.
337 llvm::DIDescriptor createContextChain(const Decl *Decl);
338
339 /// getCurrentDirname - Return current directory name.
340 StringRef getCurrentDirname();
341
342 /// CreateCompileUnit - Create new compile unit.
343 void CreateCompileUnit();
344
Eric Christopher7c811dc2013-05-16 00:52:23 +0000345 /// getOrCreateFile - Get the file debug info descriptor for the input
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000346 /// location.
347 llvm::DIFile getOrCreateFile(SourceLocation Loc);
348
349 /// getOrCreateMainFile - Get the file info for main compile unit.
350 llvm::DIFile getOrCreateMainFile();
351
352 /// getOrCreateType - Get the type from the cache or create a new type if
353 /// necessary.
David Blaikie29b8b682013-09-04 22:03:57 +0000354 llvm::DIType getOrCreateType(QualType Ty, llvm::DIFile Fg);
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000355
356 /// getOrCreateLimitedType - Get the type from the cache or create a new
357 /// partial type if necessary.
David Blaikie4a077162013-08-12 22:24:20 +0000358 llvm::DIType getOrCreateLimitedType(const RecordType *Ty, llvm::DIFile F);
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000359
360 /// CreateTypeNode - Create type metadata for a source language type.
David Blaikie29b8b682013-09-04 22:03:57 +0000361 llvm::DIType CreateTypeNode(QualType Ty, llvm::DIFile Fg);
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000362
Adrian Prantl4919de62013-03-06 22:03:30 +0000363 /// getObjCInterfaceDecl - return the underlying ObjCInterfaceDecl
364 /// if Ty is an ObjCInterface or a pointer to one.
365 ObjCInterfaceDecl* getObjCInterfaceDecl(QualType Ty);
366
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000367 /// CreateMemberType - Create new member and increase Offset by FType's size.
368 llvm::DIType CreateMemberType(llvm::DIFile Unit, QualType FType,
369 StringRef Name, uint64_t *Offset);
370
Stephen Hines176edba2014-12-01 14:53:08 -0800371 /// \brief Retrieve the DIDescriptor, if any, for the canonical form of this
David Blaikie9faebd22013-05-20 04:58:53 +0000372 /// declaration.
Stephen Hines176edba2014-12-01 14:53:08 -0800373 llvm::DIDescriptor getDeclarationOrDefinition(const Decl *D);
David Blaikie9faebd22013-05-20 04:58:53 +0000374
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000375 /// getFunctionDeclaration - Return debug info descriptor to describe method
376 /// declaration for the given method definition.
377 llvm::DISubprogram getFunctionDeclaration(const Decl *D);
378
David Blaikie5434fc22013-08-20 01:28:15 +0000379 /// Return debug info descriptor to describe in-class static data member
380 /// declaration for the given out-of-class definition.
381 llvm::DIDerivedType
382 getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D);
Eric Christopher0395de32013-01-16 01:22:32 +0000383
Stephen Hines176edba2014-12-01 14:53:08 -0800384 /// \brief Create a DISubprogram describing the forward
385 /// decalration represented in the given FunctionDecl.
386 llvm::DISubprogram getFunctionForwardDeclaration(const FunctionDecl *FD);
387
388 /// \brief Create a DIGlobalVariable describing the forward
389 /// decalration represented in the given VarDecl.
390 llvm::DIGlobalVariable getGlobalVariableForwardDeclaration(const VarDecl *VD);
391
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700392 /// Return a global variable that represents one of the collection of
393 /// global variables created for an anonmyous union.
394 llvm::DIGlobalVariable
395 CollectAnonRecordDecls(const RecordDecl *RD, llvm::DIFile Unit, unsigned LineNo,
396 StringRef LinkageName, llvm::GlobalVariable *Var,
397 llvm::DIDescriptor DContext);
398
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000399 /// getFunctionName - Get function name for the given FunctionDecl. If the
Benjamin Kramere5753592013-09-09 14:48:42 +0000400 /// name is constructed on demand (e.g. C++ destructor) then the name
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000401 /// is stored on the side.
402 StringRef getFunctionName(const FunctionDecl *FD);
403
404 /// getObjCMethodName - Returns the unmangled name of an Objective-C method.
Eric Christopher7c811dc2013-05-16 00:52:23 +0000405 /// This is the display name for the debugging info.
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000406 StringRef getObjCMethodName(const ObjCMethodDecl *FD);
407
408 /// getSelectorName - Return selector name. This is used for debugging
409 /// info.
410 StringRef getSelectorName(Selector S);
411
412 /// getClassName - Get class name including template argument list.
413 StringRef getClassName(const RecordDecl *RD);
414
415 /// getVTableName - Get vtable name for the given Class.
416 StringRef getVTableName(const CXXRecordDecl *Decl);
417
418 /// getLineNumber - Get line number for the location. If location is invalid
419 /// then use current location.
420 unsigned getLineNumber(SourceLocation Loc);
421
Eric Christopher7c811dc2013-05-16 00:52:23 +0000422 /// getColumnNumber - Get column number for the location. If location is
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000423 /// invalid then use current location.
Adrian Prantl00df5ea2013-03-12 20:43:25 +0000424 /// \param Force Assume DebugColumnInfo option is true.
425 unsigned getColumnNumber(SourceLocation Loc, bool Force=false);
Benjamin Kramer84953792013-09-09 16:39:06 +0000426
Stephen Hines176edba2014-12-01 14:53:08 -0800427 /// \brief Collect various properties of a FunctionDecl.
428 /// \param GD A GlobalDecl whose getDecl() must return a FunctionDecl.
429 void collectFunctionDeclProps(GlobalDecl GD,
430 llvm::DIFile Unit,
431 StringRef &Name, StringRef &LinkageName,
432 llvm::DIDescriptor &FDContext,
433 llvm::DIArray &TParamsArray,
434 unsigned &Flags);
435
436 /// \brief Collect various properties of a VarDecl.
437 void collectVarDeclProps(const VarDecl *VD, llvm::DIFile &Unit,
438 unsigned &LineNo, QualType &T,
439 StringRef &Name, StringRef &LinkageName,
440 llvm::DIDescriptor &VDContext);
441
Benjamin Kramer84953792013-09-09 16:39:06 +0000442 /// internString - Allocate a copy of \p A using the DebugInfoNames allocator
443 /// and return a reference to it. If multiple arguments are given the strings
444 /// are concatenated.
445 StringRef internString(StringRef A, StringRef B = StringRef()) {
446 char *Data = DebugInfoNames.Allocate<char>(A.size() + B.size());
447 std::memcpy(Data, A.data(), A.size());
448 std::memcpy(Data + A.size(), B.data(), B.size());
449 return StringRef(Data, A.size() + B.size());
450 }
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000451};
Adrian Prantled6bbe42013-07-18 00:28:02 +0000452
Stephen Hines651f13c2014-04-23 16:59:28 -0700453/// SaveAndRestoreLocation - An RAII object saves the current location
454/// and automatically restores it to the original value.
455class SaveAndRestoreLocation {
456protected:
Adrian Prantled6bbe42013-07-18 00:28:02 +0000457 SourceLocation SavedLoc;
458 CGDebugInfo *DI;
459 CGBuilderTy &Builder;
460public:
Stephen Hines651f13c2014-04-23 16:59:28 -0700461 SaveAndRestoreLocation(CodeGenFunction &CGF, CGBuilderTy &B);
462 /// Autorestore everything back to normal.
463 ~SaveAndRestoreLocation();
464};
465
466/// NoLocation - An RAII object that temporarily disables debug
467/// locations. This is useful for emitting instructions that should be
468/// counted towards the function prologue.
469class NoLocation : public SaveAndRestoreLocation {
470public:
Adrian Prantled6bbe42013-07-18 00:28:02 +0000471 NoLocation(CodeGenFunction &CGF, CGBuilderTy &B);
Stephen Hines651f13c2014-04-23 16:59:28 -0700472 /// Autorestore everything back to normal.
Adrian Prantled6bbe42013-07-18 00:28:02 +0000473 ~NoLocation();
474};
475
Adrian Prantlb061ce22013-07-18 01:36:04 +0000476/// ArtificialLocation - An RAII object that temporarily switches to
477/// an artificial debug location that has a valid scope, but no line
Adrian Prantled6bbe42013-07-18 00:28:02 +0000478/// information. This is useful when emitting compiler-generated
479/// helper functions that have no source location associated with
Adrian Prantlb6cdc962013-07-24 20:34:39 +0000480/// them. The DWARF specification allows the compiler to use the
481/// special line number 0 to indicate code that can not be attributed
482/// to any source location.
Adrian Prantled6bbe42013-07-18 00:28:02 +0000483///
Adrian Prantlb6cdc962013-07-24 20:34:39 +0000484/// This is necessary because passing an empty SourceLocation to
Adrian Prantled6bbe42013-07-18 00:28:02 +0000485/// CGDebugInfo::setLocation() will result in the last valid location
486/// being reused.
Stephen Hines651f13c2014-04-23 16:59:28 -0700487class ArtificialLocation : public SaveAndRestoreLocation {
Adrian Prantled6bbe42013-07-18 00:28:02 +0000488public:
Adrian Prantlb061ce22013-07-18 01:36:04 +0000489 ArtificialLocation(CodeGenFunction &CGF, CGBuilderTy &B);
Adrian Prantlb6cdc962013-07-24 20:34:39 +0000490
491 /// Set the current location to line 0, but within the current scope
Adrian Prantl09ade332013-07-25 00:23:37 +0000492 /// (= the top of the LexicalBlockStack).
Adrian Prantlb6cdc962013-07-24 20:34:39 +0000493 void Emit();
494
Stephen Hines651f13c2014-04-23 16:59:28 -0700495 /// Autorestore everything back to normal.
Adrian Prantlb061ce22013-07-18 01:36:04 +0000496 ~ArtificialLocation();
Adrian Prantled6bbe42013-07-18 00:28:02 +0000497};
498
499
Guy Benyei7f92f2d2012-12-18 14:30:41 +0000500} // namespace CodeGen
501} // namespace clang
502
503
504#endif