Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1 | //===--- 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 Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 10 | // This is the source-level debug info generator for llvm translation. |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 14 | #ifndef LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H |
| 15 | #define LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 16 | |
| 17 | #include "CGBuilder.h" |
| 18 | #include "clang/AST/Expr.h" |
| 19 | #include "clang/AST/Type.h" |
| 20 | #include "clang/Basic/SourceLocation.h" |
Eric Christopher | 13c9767 | 2013-05-16 00:45:23 +0000 | [diff] [blame] | 21 | #include "clang/Frontend/CodeGenOptions.h" |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/DenseMap.h" |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 23 | #include "llvm/IR/DIBuilder.h" |
| 24 | #include "llvm/IR/DebugInfo.h" |
| 25 | #include "llvm/IR/ValueHandle.h" |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 26 | #include "llvm/Support/Allocator.h" |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 27 | |
| 28 | namespace llvm { |
| 29 | class MDNode; |
| 30 | } |
| 31 | |
| 32 | namespace clang { |
| 33 | class CXXMethodDecl; |
| 34 | class VarDecl; |
| 35 | class ObjCInterfaceDecl; |
Adrian Prantl | 4919de6 | 2013-03-06 22:03:30 +0000 | [diff] [blame] | 36 | class ObjCIvarDecl; |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 37 | class ClassTemplateSpecializationDecl; |
| 38 | class GlobalDecl; |
David Blaikie | 9faebd2 | 2013-05-20 04:58:53 +0000 | [diff] [blame] | 39 | class UsingDecl; |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 40 | |
| 41 | namespace 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. |
| 49 | class CGDebugInfo { |
Adrian Prantl | b061ce2 | 2013-07-18 01:36:04 +0000 | [diff] [blame] | 50 | friend class ArtificialLocation; |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 51 | friend class SaveAndRestoreLocation; |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 52 | CodeGenModule &CGM; |
Eric Christopher | 3a7d82c | 2013-05-20 19:59:06 +0000 | [diff] [blame] | 53 | const CodeGenOptions::DebugInfoKind DebugKind; |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 54 | llvm::DIBuilder DBuilder; |
| 55 | llvm::DICompileUnit TheCU; |
| 56 | SourceLocation CurLoc, PrevLoc; |
| 57 | llvm::DIType VTablePtrType; |
| 58 | llvm::DIType ClassTy; |
Eric Christopher | f068c92 | 2013-04-02 22:59:11 +0000 | [diff] [blame] | 59 | llvm::DICompositeType ObjTy; |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 60 | llvm::DIType SelTy; |
Guy Benyei | b13621d | 2012-12-18 14:38:23 +0000 | [diff] [blame] | 61 | llvm::DIType OCLImage1dDITy, OCLImage1dArrayDITy, OCLImage1dBufferDITy; |
| 62 | llvm::DIType OCLImage2dDITy, OCLImage2dArrayDITy; |
| 63 | llvm::DIType OCLImage3dDITy; |
Guy Benyei | e6b9d80 | 2013-01-20 12:31:11 +0000 | [diff] [blame] | 64 | llvm::DIType OCLEventDITy; |
Eric Christopher | 688cf5b | 2013-07-14 21:12:44 +0000 | [diff] [blame] | 65 | llvm::DIType BlockLiteralGeneric; |
Eric Christopher | 7c811dc | 2013-05-16 00:52:23 +0000 | [diff] [blame] | 66 | |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 67 | /// TypeCache - Cache of previously constructed Types. |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 68 | 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 Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 78 | |
Adrian Prantl | 4919de6 | 2013-03-06 22:03:30 +0000 | [diff] [blame] | 79 | /// ObjCInterfaceCache - Cache of previously constructed interfaces |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 80 | /// which may change. |
| 81 | llvm::SmallVector<ObjCInterfaceCacheEntry, 32> ObjCInterfaceCache; |
Adrian Prantl | 4919de6 | 2013-03-06 22:03:30 +0000 | [diff] [blame] | 82 | |
Adrian Prantl | ebbd7e0 | 2013-03-11 18:33:46 +0000 | [diff] [blame] | 83 | /// RetainedTypes - list of interfaces we want to keep even if orphaned. |
| 84 | std::vector<void *> RetainedTypes; |
| 85 | |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 86 | /// ReplaceMap - Cache of forward declared types to RAUW at the end of |
| 87 | /// compilation. |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 88 | std::vector<std::pair<const TagType *, llvm::WeakVH>> ReplaceMap; |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 89 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 90 | /// \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 Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 94 | // 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 Blaikie | 9faebd2 | 2013-05-20 04:58:53 +0000 | [diff] [blame] | 109 | /// \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 Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 112 | llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH> NameSpaceCache; |
David Blaikie | fc46ebc | 2013-05-20 22:50:41 +0000 | [diff] [blame] | 113 | llvm::DenseMap<const NamespaceAliasDecl *, llvm::WeakVH> NamespaceAliasCache; |
Eric Christopher | 0395de3 | 2013-01-16 01:22:32 +0000 | [diff] [blame] | 114 | llvm::DenseMap<const Decl *, llvm::WeakVH> StaticDataMemberCache; |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 115 | |
| 116 | /// Helper functions for getOrCreateType. |
Adrian Prantl | 4919de6 | 2013-03-06 22:03:30 +0000 | [diff] [blame] | 117 | unsigned Checksum(const ObjCInterfaceDecl *InterfaceDecl); |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 118 | llvm::DIType CreateType(const BuiltinType *Ty); |
| 119 | llvm::DIType CreateType(const ComplexType *Ty); |
David Blaikie | 29b8b68 | 2013-09-04 22:03:57 +0000 | [diff] [blame] | 120 | llvm::DIType CreateQualifiedType(QualType Ty, llvm::DIFile Fg); |
| 121 | llvm::DIType CreateType(const TypedefType *Ty, llvm::DIFile Fg); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 122 | llvm::DIType CreateType(const TemplateSpecializationType *Ty, llvm::DIFile Fg); |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 123 | 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 Blaikie | 29b8b68 | 2013-09-04 22:03:57 +0000 | [diff] [blame] | 128 | llvm::DIType CreateType(const RecordType *Tyg); |
David Blaikie | 2780489 | 2013-08-15 20:49:17 +0000 | [diff] [blame] | 129 | llvm::DIType CreateTypeDefinition(const RecordType *Ty); |
David Blaikie | eaacc88 | 2013-08-20 21:03:29 +0000 | [diff] [blame] | 130 | llvm::DICompositeType CreateLimitedType(const RecordType *Ty); |
David Blaikie | 498298d | 2013-08-18 16:55:33 +0000 | [diff] [blame] | 131 | void CollectContainingType(const CXXRecordDecl *RD, llvm::DICompositeType CT); |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 132 | llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DIFile F); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 133 | llvm::DIType CreateTypeDefinition(const ObjCInterfaceType *Ty, llvm::DIFile F); |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 134 | 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 Ren | f332733 | 2013-08-28 21:20:28 +0000 | [diff] [blame] | 141 | llvm::DIType CreateEnumType(const EnumType *Ty); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 142 | llvm::DIType CreateTypeDefinition(const EnumType *Ty); |
Adrian Prantl | e86fcc4 | 2013-03-29 19:20:29 +0000 | [diff] [blame] | 143 | llvm::DIType CreateSelfType(const QualType &QualTy, llvm::DIType Ty); |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 144 | llvm::DIType getTypeOrNull(const QualType); |
David Blaikie | 9a84529 | 2013-05-22 23:22:42 +0000 | [diff] [blame] | 145 | llvm::DICompositeType getOrCreateMethodType(const CXXMethodDecl *Method, |
| 146 | llvm::DIFile F); |
| 147 | llvm::DICompositeType getOrCreateInstanceMethodType( |
David Blaikie | 9c78f9b | 2013-01-07 23:06:35 +0000 | [diff] [blame] | 148 | QualType ThisPtr, const FunctionProtoType *Func, llvm::DIFile Unit); |
David Blaikie | 9a84529 | 2013-05-22 23:22:42 +0000 | [diff] [blame] | 149 | llvm::DICompositeType getOrCreateFunctionType(const Decl *D, QualType FnType, |
| 150 | llvm::DIFile F); |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 151 | llvm::DIType getOrCreateVTablePtrType(llvm::DIFile F); |
| 152 | llvm::DINameSpace getOrCreateNameSpace(const NamespaceDecl *N); |
David Blaikie | b0f77b0 | 2013-05-24 21:33:22 +0000 | [diff] [blame] | 153 | llvm::DIType getOrCreateTypeDeclaration(QualType PointeeTy, llvm::DIFile F); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 154 | llvm::DIType CreatePointerLikeType(llvm::dwarf::Tag Tag, |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 155 | const Type *Ty, QualType PointeeTy, |
| 156 | llvm::DIFile F); |
Guy Benyei | b13621d | 2012-12-18 14:38:23 +0000 | [diff] [blame] | 157 | |
Adrian Prantl | ebbd7e0 | 2013-03-11 18:33:46 +0000 | [diff] [blame] | 158 | llvm::Value *getCachedInterfaceTypeOrNull(const QualType Ty); |
Guy Benyei | b13621d | 2012-12-18 14:38:23 +0000 | [diff] [blame] | 159 | llvm::DIType getOrCreateStructPtrType(StringRef Name, llvm::DIType &Cache); |
| 160 | |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 161 | llvm::DISubprogram CreateCXXMemberFunction(const CXXMethodDecl *Method, |
| 162 | llvm::DIFile F, |
| 163 | llvm::DIType RecordTy); |
Eric Christopher | 7c811dc | 2013-05-16 00:52:23 +0000 | [diff] [blame] | 164 | |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 165 | void CollectCXXMemberFunctions(const CXXRecordDecl *Decl, |
| 166 | llvm::DIFile F, |
| 167 | SmallVectorImpl<llvm::Value *> &E, |
| 168 | llvm::DIType T); |
| 169 | |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 170 | void CollectCXXBases(const CXXRecordDecl *Decl, |
| 171 | llvm::DIFile F, |
| 172 | SmallVectorImpl<llvm::Value *> &EltTys, |
| 173 | llvm::DIType RecordTy); |
Eric Christopher | 7c811dc | 2013-05-16 00:52:23 +0000 | [diff] [blame] | 174 | |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 175 | llvm::DIArray |
| 176 | CollectTemplateParams(const TemplateParameterList *TPList, |
David Blaikie | 35178dc | 2013-06-22 18:59:18 +0000 | [diff] [blame] | 177 | ArrayRef<TemplateArgument> TAList, |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 178 | llvm::DIFile Unit); |
| 179 | llvm::DIArray |
| 180 | CollectFunctionTemplateParams(const FunctionDecl *FD, llvm::DIFile Unit); |
Eric Christopher | 7c811dc | 2013-05-16 00:52:23 +0000 | [diff] [blame] | 181 | llvm::DIArray |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 182 | CollectCXXTemplateParams(const ClassTemplateSpecializationDecl *TS, |
| 183 | llvm::DIFile F); |
| 184 | |
| 185 | llvm::DIType createFieldType(StringRef name, QualType type, |
| 186 | uint64_t sizeInBitsOverride, SourceLocation loc, |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 187 | AccessSpecifier AS, |
| 188 | uint64_t offsetInBits, |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 189 | llvm::DIFile tunit, |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 190 | llvm::DIScope scope, |
| 191 | const RecordDecl* RD = nullptr); |
Eric Christopher | 0395de3 | 2013-01-16 01:22:32 +0000 | [diff] [blame] | 192 | |
| 193 | // Helpers for collecting fields of a record. |
| 194 | void CollectRecordLambdaFields(const CXXRecordDecl *CXXDecl, |
| 195 | SmallVectorImpl<llvm::Value *> &E, |
| 196 | llvm::DIType RecordTy); |
David Blaikie | cbcb030 | 2013-08-15 22:50:29 +0000 | [diff] [blame] | 197 | llvm::DIDerivedType CreateRecordStaticField(const VarDecl *Var, |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 198 | llvm::DIType RecordTy, |
| 199 | const RecordDecl* RD); |
Eric Christopher | 0395de3 | 2013-01-16 01:22:32 +0000 | [diff] [blame] | 200 | void CollectRecordNormalField(const FieldDecl *Field, uint64_t OffsetInBits, |
| 201 | llvm::DIFile F, |
| 202 | SmallVectorImpl<llvm::Value *> &E, |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 203 | llvm::DIType RecordTy, |
| 204 | const RecordDecl* RD); |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 205 | void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile F, |
| 206 | SmallVectorImpl<llvm::Value *> &E, |
David Blaikie | 841fd11 | 2013-08-16 20:40:25 +0000 | [diff] [blame] | 207 | llvm::DICompositeType RecordTy); |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 208 | |
| 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 Christopher | 7c811dc | 2013-05-16 00:52:23 +0000 | [diff] [blame] | 216 | |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 217 | public: |
| 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 Prantl | 59f0a5a | 2013-05-16 00:41:29 +0000 | [diff] [blame] | 227 | /// getLocation - Return the current source location. |
| 228 | SourceLocation getLocation() const { return CurLoc; } |
| 229 | |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 230 | /// EmitLocation - Emit metadata to indicate a change in line/column |
| 231 | /// information in the source file. |
Adrian Prantl | 00df5ea | 2013-03-12 20:43:25 +0000 | [diff] [blame] | 232 | /// \param ForceColumnInfo Assume DebugColumnInfo option is true. |
| 233 | void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc, |
| 234 | bool ForceColumnInfo = false); |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 235 | |
| 236 | /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate |
| 237 | /// start of a new function. |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 238 | /// \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 Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 244 | |
| 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 Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 266 | const CGBlockInfo &blockInfo, |
| 267 | llvm::Instruction *InsertPoint = 0); |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 268 | |
| 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 Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 278 | llvm::Value *Arg, unsigned ArgNo, |
Adrian Prantl | 836e7c9 | 2013-03-14 17:53:33 +0000 | [diff] [blame] | 279 | llvm::Value *LocalAddr, |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 280 | CGBuilderTy &Builder); |
| 281 | |
| 282 | /// EmitGlobalVariable - Emit information about a global variable. |
Yunzhong Gao | 3b8e0b7 | 2013-08-30 08:53:09 +0000 | [diff] [blame] | 283 | void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl); |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 284 | |
Yunzhong Gao | 3b8e0b7 | 2013-08-30 08:53:09 +0000 | [diff] [blame] | 285 | /// EmitGlobalVariable - Emit global variable's debug info. |
| 286 | void EmitGlobalVariable(const ValueDecl *VD, llvm::Constant *Init); |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 287 | |
David Blaikie | 957dac5 | 2013-04-22 06:13:21 +0000 | [diff] [blame] | 288 | /// \brief - Emit C++ using directive. |
| 289 | void EmitUsingDirective(const UsingDirectiveDecl &UD); |
| 290 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 291 | /// EmitExplicitCastType - Emit the type explicitly casted to. |
| 292 | void EmitExplicitCastType(QualType Ty); |
| 293 | |
David Blaikie | 9faebd2 | 2013-05-20 04:58:53 +0000 | [diff] [blame] | 294 | /// \brief - Emit C++ using declaration. |
| 295 | void EmitUsingDecl(const UsingDecl &UD); |
| 296 | |
David Blaikie | fc46ebc | 2013-05-20 22:50:41 +0000 | [diff] [blame] | 297 | /// \brief - Emit C++ namespace alias. |
| 298 | llvm::DIImportedEntity EmitNamespaceAlias(const NamespaceAliasDecl &NA); |
| 299 | |
Eric Christopher | 7c811dc | 2013-05-16 00:52:23 +0000 | [diff] [blame] | 300 | /// getOrCreateRecordType - Emit record type's standalone debug info. |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 301 | 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 Christopher | 13c9767 | 2013-05-16 00:45:23 +0000 | [diff] [blame] | 306 | SourceLocation Loc); |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 307 | |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 308 | void completeType(const EnumDecl *ED); |
David Blaikie | 2780489 | 2013-08-15 20:49:17 +0000 | [diff] [blame] | 309 | void completeType(const RecordDecl *RD); |
| 310 | void completeRequiredType(const RecordDecl *RD); |
David Blaikie | 5434fc2 | 2013-08-20 01:28:15 +0000 | [diff] [blame] | 311 | void completeClassData(const RecordDecl *RD); |
David Blaikie | eab6a36 | 2013-06-21 00:40:50 +0000 | [diff] [blame] | 312 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 313 | void completeTemplateDefinition(const ClassTemplateSpecializationDecl &SD); |
| 314 | |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 315 | private: |
| 316 | /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration. |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 317 | /// 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 Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 321 | |
Eric Christopher | 7c811dc | 2013-05-16 00:52:23 +0000 | [diff] [blame] | 322 | // EmitTypeForVarWithBlocksAttr - Build up structure info for the byref. |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 323 | // See BuildByRefType. |
| 324 | llvm::DIType EmitTypeForVarWithBlocksAttr(const VarDecl *VD, |
| 325 | uint64_t *OffSet); |
| 326 | |
| 327 | /// getContextDescriptor - Get context info for the decl. |
David Blaikie | bb00079 | 2013-04-19 06:56:38 +0000 | [diff] [blame] | 328 | llvm::DIScope getContextDescriptor(const Decl *Decl); |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 329 | |
David Blaikie | 9faebd2 | 2013-05-20 04:58:53 +0000 | [diff] [blame] | 330 | llvm::DIScope getCurrentContextDescriptor(const Decl *Decl); |
| 331 | |
David Blaikie | 951094b | 2013-08-15 18:59:40 +0000 | [diff] [blame] | 332 | /// \brief Create a forward decl for a RecordType in a given context. |
Manman Ren | f332733 | 2013-08-28 21:20:28 +0000 | [diff] [blame] | 333 | llvm::DICompositeType getOrCreateRecordFwdDecl(const RecordType *, |
David Blaikie | eaacc88 | 2013-08-20 21:03:29 +0000 | [diff] [blame] | 334 | llvm::DIDescriptor); |
Eric Christopher | 7c811dc | 2013-05-16 00:52:23 +0000 | [diff] [blame] | 335 | |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 336 | /// 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 Christopher | 7c811dc | 2013-05-16 00:52:23 +0000 | [diff] [blame] | 345 | /// getOrCreateFile - Get the file debug info descriptor for the input |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 346 | /// 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 Blaikie | 29b8b68 | 2013-09-04 22:03:57 +0000 | [diff] [blame] | 354 | llvm::DIType getOrCreateType(QualType Ty, llvm::DIFile Fg); |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 355 | |
| 356 | /// getOrCreateLimitedType - Get the type from the cache or create a new |
| 357 | /// partial type if necessary. |
David Blaikie | 4a07716 | 2013-08-12 22:24:20 +0000 | [diff] [blame] | 358 | llvm::DIType getOrCreateLimitedType(const RecordType *Ty, llvm::DIFile F); |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 359 | |
| 360 | /// CreateTypeNode - Create type metadata for a source language type. |
David Blaikie | 29b8b68 | 2013-09-04 22:03:57 +0000 | [diff] [blame] | 361 | llvm::DIType CreateTypeNode(QualType Ty, llvm::DIFile Fg); |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 362 | |
Adrian Prantl | 4919de6 | 2013-03-06 22:03:30 +0000 | [diff] [blame] | 363 | /// getObjCInterfaceDecl - return the underlying ObjCInterfaceDecl |
| 364 | /// if Ty is an ObjCInterface or a pointer to one. |
| 365 | ObjCInterfaceDecl* getObjCInterfaceDecl(QualType Ty); |
| 366 | |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 367 | /// 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 Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 371 | /// \brief Retrieve the DIDescriptor, if any, for the canonical form of this |
David Blaikie | 9faebd2 | 2013-05-20 04:58:53 +0000 | [diff] [blame] | 372 | /// declaration. |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 373 | llvm::DIDescriptor getDeclarationOrDefinition(const Decl *D); |
David Blaikie | 9faebd2 | 2013-05-20 04:58:53 +0000 | [diff] [blame] | 374 | |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 375 | /// getFunctionDeclaration - Return debug info descriptor to describe method |
| 376 | /// declaration for the given method definition. |
| 377 | llvm::DISubprogram getFunctionDeclaration(const Decl *D); |
| 378 | |
David Blaikie | 5434fc2 | 2013-08-20 01:28:15 +0000 | [diff] [blame] | 379 | /// 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 Christopher | 0395de3 | 2013-01-16 01:22:32 +0000 | [diff] [blame] | 383 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 384 | /// \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 Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 392 | /// 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 Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 399 | /// getFunctionName - Get function name for the given FunctionDecl. If the |
Benjamin Kramer | e575359 | 2013-09-09 14:48:42 +0000 | [diff] [blame] | 400 | /// name is constructed on demand (e.g. C++ destructor) then the name |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 401 | /// is stored on the side. |
| 402 | StringRef getFunctionName(const FunctionDecl *FD); |
| 403 | |
| 404 | /// getObjCMethodName - Returns the unmangled name of an Objective-C method. |
Eric Christopher | 7c811dc | 2013-05-16 00:52:23 +0000 | [diff] [blame] | 405 | /// This is the display name for the debugging info. |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 406 | 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 Christopher | 7c811dc | 2013-05-16 00:52:23 +0000 | [diff] [blame] | 422 | /// getColumnNumber - Get column number for the location. If location is |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 423 | /// invalid then use current location. |
Adrian Prantl | 00df5ea | 2013-03-12 20:43:25 +0000 | [diff] [blame] | 424 | /// \param Force Assume DebugColumnInfo option is true. |
| 425 | unsigned getColumnNumber(SourceLocation Loc, bool Force=false); |
Benjamin Kramer | 8495379 | 2013-09-09 16:39:06 +0000 | [diff] [blame] | 426 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 427 | /// \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 Kramer | 8495379 | 2013-09-09 16:39:06 +0000 | [diff] [blame] | 442 | /// 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 Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 451 | }; |
Adrian Prantl | ed6bbe4 | 2013-07-18 00:28:02 +0000 | [diff] [blame] | 452 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 453 | /// SaveAndRestoreLocation - An RAII object saves the current location |
| 454 | /// and automatically restores it to the original value. |
| 455 | class SaveAndRestoreLocation { |
| 456 | protected: |
Adrian Prantl | ed6bbe4 | 2013-07-18 00:28:02 +0000 | [diff] [blame] | 457 | SourceLocation SavedLoc; |
| 458 | CGDebugInfo *DI; |
| 459 | CGBuilderTy &Builder; |
| 460 | public: |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 461 | 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. |
| 469 | class NoLocation : public SaveAndRestoreLocation { |
| 470 | public: |
Adrian Prantl | ed6bbe4 | 2013-07-18 00:28:02 +0000 | [diff] [blame] | 471 | NoLocation(CodeGenFunction &CGF, CGBuilderTy &B); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 472 | /// Autorestore everything back to normal. |
Adrian Prantl | ed6bbe4 | 2013-07-18 00:28:02 +0000 | [diff] [blame] | 473 | ~NoLocation(); |
| 474 | }; |
| 475 | |
Adrian Prantl | b061ce2 | 2013-07-18 01:36:04 +0000 | [diff] [blame] | 476 | /// ArtificialLocation - An RAII object that temporarily switches to |
| 477 | /// an artificial debug location that has a valid scope, but no line |
Adrian Prantl | ed6bbe4 | 2013-07-18 00:28:02 +0000 | [diff] [blame] | 478 | /// information. This is useful when emitting compiler-generated |
| 479 | /// helper functions that have no source location associated with |
Adrian Prantl | b6cdc96 | 2013-07-24 20:34:39 +0000 | [diff] [blame] | 480 | /// 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 Prantl | ed6bbe4 | 2013-07-18 00:28:02 +0000 | [diff] [blame] | 483 | /// |
Adrian Prantl | b6cdc96 | 2013-07-24 20:34:39 +0000 | [diff] [blame] | 484 | /// This is necessary because passing an empty SourceLocation to |
Adrian Prantl | ed6bbe4 | 2013-07-18 00:28:02 +0000 | [diff] [blame] | 485 | /// CGDebugInfo::setLocation() will result in the last valid location |
| 486 | /// being reused. |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 487 | class ArtificialLocation : public SaveAndRestoreLocation { |
Adrian Prantl | ed6bbe4 | 2013-07-18 00:28:02 +0000 | [diff] [blame] | 488 | public: |
Adrian Prantl | b061ce2 | 2013-07-18 01:36:04 +0000 | [diff] [blame] | 489 | ArtificialLocation(CodeGenFunction &CGF, CGBuilderTy &B); |
Adrian Prantl | b6cdc96 | 2013-07-24 20:34:39 +0000 | [diff] [blame] | 490 | |
| 491 | /// Set the current location to line 0, but within the current scope |
Adrian Prantl | 09ade33 | 2013-07-25 00:23:37 +0000 | [diff] [blame] | 492 | /// (= the top of the LexicalBlockStack). |
Adrian Prantl | b6cdc96 | 2013-07-24 20:34:39 +0000 | [diff] [blame] | 493 | void Emit(); |
| 494 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 495 | /// Autorestore everything back to normal. |
Adrian Prantl | b061ce2 | 2013-07-18 01:36:04 +0000 | [diff] [blame] | 496 | ~ArtificialLocation(); |
Adrian Prantl | ed6bbe4 | 2013-07-18 00:28:02 +0000 | [diff] [blame] | 497 | }; |
| 498 | |
| 499 | |
Guy Benyei | 7f92f2d | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 500 | } // namespace CodeGen |
| 501 | } // namespace clang |
| 502 | |
| 503 | |
| 504 | #endif |