13 #ifndef LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
14 #define LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
26 #include "llvm/ADT/DenseMap.h"
27 #include "llvm/ADT/DenseSet.h"
28 #include "llvm/ADT/Optional.h"
29 #include "llvm/IR/DIBuilder.h"
30 #include "llvm/IR/DebugInfo.h"
31 #include "llvm/IR/ValueHandle.h"
32 #include "llvm/Support/Allocator.h"
39 class ClassTemplateSpecializationDecl;
42 class ObjCInterfaceDecl;
49 class CodeGenFunction;
57 friend class SaveAndRestoreLocation;
60 bool DebugTypeExtRefs;
61 llvm::DIBuilder DBuilder;
62 llvm::DICompileUnit *TheCU =
nullptr;
66 llvm::MDNode *CurInlinedAt =
nullptr;
67 llvm::DIType *VTablePtrType =
nullptr;
68 llvm::DIType *ClassTy =
nullptr;
69 llvm::DICompositeType *ObjTy =
nullptr;
70 llvm::DIType *SelTy =
nullptr;
71 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
72 llvm::DIType *SingletonId = nullptr;
73 #include "clang/Basic/OpenCLImageTypes.def"
74 llvm::DIType *OCLSamplerDITy =
nullptr;
75 llvm::DIType *OCLEventDITy =
nullptr;
76 llvm::DIType *OCLClkEventDITy =
nullptr;
77 llvm::DIType *OCLQueueDITy =
nullptr;
78 llvm::DIType *OCLNDRangeDITy =
nullptr;
79 llvm::DIType *OCLReserveIDDITy =
nullptr;
80 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
81 llvm::DIType *Id##Ty = nullptr;
82 #include "clang/Basic/OpenCLExtensionTypes.def"
85 llvm::DenseMap<const void *, llvm::TrackingMDRef> TypeCache;
87 std::map<llvm::StringRef, llvm::StringRef, std::greater<llvm::StringRef>>
92 llvm::SmallDenseMap<QualType, llvm::Metadata *> SizeExprCache;
96 const CGDebugInfo &Self;
99 PrintingCallbacks(
const CGDebugInfo &Self) : Self(Self) {}
100 std::string remapPath(StringRef Path)
const override {
101 return Self.remapDIPath(Path);
104 PrintingCallbacks PrintCB = {*
this};
106 struct ObjCInterfaceCacheEntry {
107 const ObjCInterfaceType *
Type;
110 ObjCInterfaceCacheEntry(
const ObjCInterfaceType *Type, llvm::DIType *Decl,
121 llvm::DenseMap<
const ObjCInterfaceDecl *,
122 std::vector<llvm::PointerIntPair<llvm::DISubprogram *, 1>>>
126 llvm::DenseMap<const Module *, llvm::TrackingMDRef> ModuleCache;
129 std::vector<void *> RetainedTypes;
132 std::vector<std::pair<const TagType *, llvm::TrackingMDRef>> ReplaceMap;
136 std::vector<std::pair<const DeclaratorDecl *, llvm::TrackingMDRef>>
140 std::vector<llvm::TypedTrackingMDRef<llvm::DIScope>> LexicalBlockStack;
141 llvm::DenseMap<const Decl *, llvm::TrackingMDRef> RegionMap;
145 std::vector<unsigned> FnBeginRegionCount;
149 llvm::BumpPtrAllocator DebugInfoNames;
152 llvm::DenseMap<const char *, llvm::TrackingMDRef> DIFileCache;
153 llvm::DenseMap<const FunctionDecl *, llvm::TrackingMDRef> SPCache;
157 llvm::DenseMap<const Decl *, llvm::TrackingMDRef> DeclCache;
158 llvm::DenseMap<const Decl *, llvm::TrackingMDRef> ImportedDeclCache;
159 llvm::DenseMap<const NamespaceDecl *, llvm::TrackingMDRef> NamespaceCache;
160 llvm::DenseMap<const NamespaceAliasDecl *, llvm::TrackingMDRef>
162 llvm::DenseMap<const Decl *, llvm::TypedTrackingMDRef<llvm::DIDerivedType>>
163 StaticDataMemberCache;
165 using ParamDecl2StmtTy = llvm::DenseMap<const ParmVarDecl *, const Stmt *>;
166 using Param2DILocTy =
167 llvm::DenseMap<const ParmVarDecl *, llvm::DILocalVariable *>;
170 ParamDecl2StmtTy CoroutineParameterMappings;
172 Param2DILocTy ParamDbgMappings;
178 llvm::DIType *CreateType(
const BuiltinType *Ty);
179 llvm::DIType *CreateType(
const ComplexType *Ty);
180 llvm::DIType *CreateType(
const AutoType *Ty);
181 llvm::DIType *CreateType(
const BitIntType *Ty);
182 llvm::DIType *CreateQualifiedType(QualType Ty, llvm::DIFile *Fg);
183 llvm::DIType *CreateQualifiedType(
const FunctionProtoType *Ty,
185 llvm::DIType *CreateType(
const TypedefType *Ty, llvm::DIFile *Fg);
186 llvm::DIType *CreateType(
const TemplateSpecializationType *Ty,
188 llvm::DIType *CreateType(
const ObjCObjectPointerType *Ty, llvm::DIFile *F);
189 llvm::DIType *CreateType(
const PointerType *Ty, llvm::DIFile *F);
190 llvm::DIType *CreateType(
const BlockPointerType *Ty, llvm::DIFile *F);
191 llvm::DIType *CreateType(
const FunctionType *Ty, llvm::DIFile *F);
193 llvm::DIType *CreateType(
const RecordType *Tyg);
194 llvm::DIType *CreateTypeDefinition(
const RecordType *Ty);
195 llvm::DICompositeType *CreateLimitedType(
const RecordType *Ty);
196 void CollectContainingType(
const CXXRecordDecl *RD,
197 llvm::DICompositeType *CT);
199 llvm::DIType *CreateType(
const ObjCInterfaceType *Ty, llvm::DIFile *F);
200 llvm::DIType *CreateTypeDefinition(
const ObjCInterfaceType *Ty,
203 llvm::DIType *CreateType(
const ObjCObjectType *Ty, llvm::DIFile *F);
204 llvm::DIType *CreateType(
const ObjCTypeParamType *Ty, llvm::DIFile *Unit);
206 llvm::DIType *CreateType(
const VectorType *Ty, llvm::DIFile *F);
207 llvm::DIType *CreateType(
const ConstantMatrixType *Ty, llvm::DIFile *F);
208 llvm::DIType *CreateType(
const ArrayType *Ty, llvm::DIFile *F);
209 llvm::DIType *CreateType(
const LValueReferenceType *Ty, llvm::DIFile *F);
210 llvm::DIType *CreateType(
const RValueReferenceType *Ty, llvm::DIFile *Unit);
211 llvm::DIType *CreateType(
const MemberPointerType *Ty, llvm::DIFile *F);
212 llvm::DIType *CreateType(
const AtomicType *Ty, llvm::DIFile *F);
213 llvm::DIType *CreateType(
const PipeType *Ty, llvm::DIFile *F);
215 llvm::DIType *CreateEnumType(
const EnumType *Ty);
216 llvm::DIType *CreateTypeDefinition(
const EnumType *Ty);
223 llvm::DIType *CreateSelfType(
const QualType &QualTy, llvm::DIType *Ty);
228 llvm::DIType *getTypeOrNull(
const QualType);
233 llvm::DISubroutineType *getOrCreateMethodType(
const CXXMethodDecl *Method,
234 llvm::DIFile *F,
bool decl);
235 llvm::DISubroutineType *
236 getOrCreateInstanceMethodType(QualType ThisPtr,
const FunctionProtoType *Func,
237 llvm::DIFile *Unit,
bool decl);
238 llvm::DISubroutineType *
239 getOrCreateFunctionType(
const Decl *D, QualType FnType, llvm::DIFile *F);
241 llvm::DIType *getOrCreateVTablePtrType(llvm::DIFile *F);
244 llvm::DINamespace *getOrCreateNamespace(
const NamespaceDecl *N);
245 llvm::DIType *CreatePointerLikeType(llvm::dwarf::Tag Tag,
const Type *Ty,
246 QualType PointeeTy, llvm::DIFile *F);
247 llvm::DIType *getOrCreateStructPtrType(StringRef Name, llvm::DIType *&
Cache);
251 llvm::DISubprogram *CreateCXXMemberFunction(
const CXXMethodDecl *Method,
253 llvm::DIType *RecordTy);
258 void CollectCXXMemberFunctions(
const CXXRecordDecl *Decl, llvm::DIFile *F,
259 SmallVectorImpl<llvm::Metadata *> &E,
265 void CollectCXXBases(
const CXXRecordDecl *Decl, llvm::DIFile *F,
266 SmallVectorImpl<llvm::Metadata *> &EltTys,
267 llvm::DIType *RecordTy);
271 void CollectCXXBasesAux(
272 const CXXRecordDecl *RD, llvm::DIFile *Unit,
273 SmallVectorImpl<llvm::Metadata *> &EltTys, llvm::DIType *RecordTy,
276 llvm::DINode::DIFlags StartingFlags);
278 struct TemplateArgs {
279 const TemplateParameterList *TList;
287 llvm::DINodeArray CollectFunctionTemplateParams(
const FunctionDecl *FD,
292 llvm::DINodeArray CollectVarTemplateParams(
const VarDecl *VD,
301 llvm::DINodeArray CollectCXXTemplateParams(
const RecordDecl *TS,
305 llvm::DINodeArray CollectBTFDeclTagAnnotations(
const Decl *D);
307 llvm::DIType *createFieldType(StringRef
name, QualType
type,
309 uint64_t offsetInBits, uint32_t AlignInBits,
310 llvm::DIFile *tunit, llvm::DIScope *scope,
311 const RecordDecl *RD =
nullptr,
312 llvm::DINodeArray Annotations =
nullptr);
314 llvm::DIType *createFieldType(StringRef
name, QualType
type,
316 uint64_t offsetInBits, llvm::DIFile *tunit,
317 llvm::DIScope *scope,
318 const RecordDecl *RD =
nullptr) {
319 return createFieldType(
name,
type, loc, AS, offsetInBits, 0, tunit, scope,
324 llvm::DIType *createBitFieldType(
const FieldDecl *BitFieldDecl,
325 llvm::DIScope *RecordTy,
326 const RecordDecl *RD);
330 void CollectRecordLambdaFields(
const CXXRecordDecl *CXXDecl,
331 SmallVectorImpl<llvm::Metadata *> &E,
332 llvm::DIType *RecordTy);
333 llvm::DIDerivedType *CreateRecordStaticField(
const VarDecl *Var,
334 llvm::DIType *RecordTy,
335 const RecordDecl *RD);
336 void CollectRecordNormalField(
const FieldDecl *Field, uint64_t OffsetInBits,
338 SmallVectorImpl<llvm::Metadata *> &E,
339 llvm::DIType *RecordTy,
const RecordDecl *RD);
340 void CollectRecordNestedType(
const TypeDecl *RD,
341 SmallVectorImpl<llvm::Metadata *> &E);
342 void CollectRecordFields(
const RecordDecl *Decl, llvm::DIFile *F,
343 SmallVectorImpl<llvm::Metadata *> &E,
344 llvm::DICompositeType *RecordTy);
348 void CollectVTableInfo(
const CXXRecordDecl *Decl, llvm::DIFile *F,
349 SmallVectorImpl<llvm::Metadata *> &EltTys);
353 void CreateLexicalBlock(SourceLocation Loc);
361 void AppendAddressSpaceXDeref(
unsigned AddressSpace,
362 SmallVectorImpl<uint64_t> &Expr)
const;
368 uint64_t collectDefaultElementTypesForBlockPointer(
369 const BlockPointerType *Ty, llvm::DIFile *Unit,
370 llvm::DIDerivedType *DescTy,
unsigned LineNo,
371 SmallVectorImpl<llvm::Metadata *> &EltTys);
375 void collectDefaultFieldsForBlockLiteralDeclare(
376 const CGBlockInfo &Block,
const ASTContext &Context, SourceLocation Loc,
377 const llvm::StructLayout &BlockLayout, llvm::DIFile *Unit,
378 SmallVectorImpl<llvm::Metadata *> &Fields);
381 CGDebugInfo(CodeGenModule &CGM);
391 SizeExprCache[Ty] = SizeExpr;
397 void setDwoId(uint64_t Signature);
420 void setInlinedAt(llvm::MDNode *InlinedAt) { CurInlinedAt = InlinedAt; }
442 llvm::Function *Fn,
bool CurFnIsThunk);
452 QualType FnType, llvm::Function *Fn =
nullptr);
456 void EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
461 void EmitFunctionEnd(
CGBuilderTy &Builder, llvm::Function *Fn);
475 llvm::DILocalVariable *
476 EmitDeclareOfAutoVariable(
const VarDecl *
Decl, llvm::Value *AI,
478 const bool UsePointerValue =
false);
485 void EmitDeclareOfBlockDeclRefVariable(
487 const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint =
nullptr);
491 llvm::DILocalVariable *EmitDeclareOfArgVariable(
const VarDecl *
Decl,
498 void EmitDeclareOfBlockLiteralArgVariable(
const CGBlockInfo &block,
499 StringRef Name,
unsigned ArgNo,
500 llvm::AllocaInst *LocalAddr,
504 void EmitGlobalVariable(llvm::GlobalVariable *GV,
const VarDecl *
Decl);
510 void EmitExternalVariable(llvm::GlobalVariable *GV,
const VarDecl *
Decl);
513 void EmitGlobalAlias(
const llvm::GlobalValue *GV,
const GlobalDecl Decl);
519 void EmitExplicitCastType(
QualType Ty);
522 void EmitAndRetainType(
QualType Ty);
541 void AddStringLiteralDebugInfo(llvm::GlobalVariable *GV,
557 void addHeapAllocSiteMetadata(llvm::CallBase *CallSite,
QualType AllocatedTy,
560 void completeType(
const EnumDecl *ED);
562 void completeRequiredType(
const RecordDecl *RD);
571 llvm::DIMacro *CreateMacro(llvm::DIMacroFile *
Parent,
unsigned MType,
576 llvm::DIMacroFile *CreateTempMacroFile(llvm::DIMacroFile *
Parent,
582 return CoroutineParameterMappings;
589 llvm::DILocalVariable *EmitDeclare(
const VarDecl *
decl, llvm::Value *AI,
592 const bool UsePointerValue =
false);
597 llvm::DILocalVariable *EmitDeclare(
const BindingDecl *
decl, llvm::Value *AI,
600 const bool UsePointerValue =
false);
602 struct BlockByRefType {
604 llvm::DIType *BlockByRefWrapper;
606 llvm::DIType *WrappedType;
612 BlockByRefType EmitTypeForVarWithBlocksAttr(
const VarDecl *VD,
616 llvm::DIScope *getDeclContextDescriptor(
const Decl *D);
618 llvm::DIScope *getContextDescriptor(
const Decl *Context,
619 llvm::DIScope *Default);
621 llvm::DIScope *getCurrentContextDescriptor(
const Decl *
Decl);
624 llvm::DICompositeType *getOrCreateRecordFwdDecl(
const RecordType *,
628 StringRef getCurrentDirname();
631 void CreateCompileUnit();
646 createFile(StringRef FileName,
647 Optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo,
651 llvm::DIType *getOrCreateType(
QualType Ty, llvm::DIFile *Fg);
656 bool CreateSkeletonCU);
659 llvm::DIModule *getParentModuleOrNull(
const Decl *D);
663 llvm::DICompositeType *getOrCreateLimitedType(
const RecordType *Ty);
666 llvm::DIType *CreateTypeNode(
QualType Ty, llvm::DIFile *Fg);
669 llvm::DIType *CreateMemberType(llvm::DIFile *Unit,
QualType FType,
670 StringRef Name, uint64_t *
Offset);
674 llvm::DINode *getDeclarationOrDefinition(
const Decl *D);
678 llvm::DISubprogram *getFunctionDeclaration(
const Decl *D);
687 getObjCMethodDeclaration(
const Decl *D, llvm::DISubroutineType *FnType,
688 unsigned LineNo, llvm::DINode::DIFlags Flags,
689 llvm::DISubprogram::DISPFlags SPFlags);
695 llvm::DIDerivedType *
696 getOrCreateStaticDataMemberDeclarationOrNull(
const VarDecl *D);
699 llvm::DISubprogram *getFunctionFwdDeclOrStub(
GlobalDecl GD,
bool Stub);
703 llvm::DISubprogram *getFunctionForwardDeclaration(
GlobalDecl GD);
707 llvm::DISubprogram *getFunctionStub(
GlobalDecl GD);
711 llvm::DIGlobalVariable *
712 getGlobalVariableForwardDeclaration(
const VarDecl *VD);
721 llvm::DIGlobalVariableExpression *
722 CollectAnonRecordDecls(
const RecordDecl *RD, llvm::DIFile *Unit,
723 unsigned LineNo, StringRef LinkageName,
724 llvm::GlobalVariable *Var, llvm::DIScope *DContext);
729 llvm::DINode::DIFlags getCallSiteRelatedAttrs()
const;
745 StringRef getSelectorName(
Selector S);
755 StringRef getDynamicInitializerName(
const VarDecl *VD,
757 llvm::Function *InitFn);
770 void collectFunctionDeclProps(
GlobalDecl GD, llvm::DIFile *Unit,
771 StringRef &Name, StringRef &LinkageName,
772 llvm::DIScope *&FDContext,
773 llvm::DINodeArray &TParamsArray,
774 llvm::DINode::DIFlags &Flags);
777 void collectVarDeclProps(
const VarDecl *VD, llvm::DIFile *&Unit,
778 unsigned &LineNo,
QualType &T, StringRef &Name,
779 StringRef &LinkageName,
780 llvm::MDTuple *&TemplateParameters,
781 llvm::DIScope *&VDContext);
786 StringRef internString(StringRef A, StringRef B = StringRef()) {
787 char *Data = DebugInfoNames.Allocate<
char>(A.size() + B.size());
792 return StringRef(Data, A.size() + B.size());
800 void init(
SourceLocation TemporaryLocation,
bool DefaultToEmpty =
false);
804 llvm::DebugLoc OriginalLocation;
869 #endif // LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H