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/IR/DIBuilder.h"
29 #include "llvm/IR/DebugInfo.h"
30 #include "llvm/IR/ValueHandle.h"
31 #include "llvm/Support/Allocator.h"
39 class ClassTemplateSpecializationDecl;
42 class ObjCInterfaceDecl;
49 class CodeGenFunction;
57 friend class SaveAndRestoreLocation;
59 const llvm::codegenoptions::DebugInfoKind DebugKind;
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 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
75 llvm::DIType *Sampled##SingletonId = nullptr;
76 #define IMAGE_WRITE_TYPE(Type, Id, Ext)
77 #define IMAGE_READ_WRITE_TYPE(Type, Id, Ext)
78 #include "clang/Basic/OpenCLImageTypes.def"
79 llvm::DIType *OCLSamplerDITy =
nullptr;
80 llvm::DIType *OCLEventDITy =
nullptr;
81 llvm::DIType *OCLClkEventDITy =
nullptr;
82 llvm::DIType *OCLQueueDITy =
nullptr;
83 llvm::DIType *OCLNDRangeDITy =
nullptr;
84 llvm::DIType *OCLReserveIDDITy =
nullptr;
85 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
86 llvm::DIType *Id##Ty = nullptr;
87 #include "clang/Basic/OpenCLExtensionTypes.def"
88 #define WASM_TYPE(Name, Id, SingletonId) llvm::DIType *SingletonId = nullptr;
89 #include "clang/Basic/WebAssemblyReferenceTypes.def"
92 llvm::DenseMap<const void *, llvm::TrackingMDRef> TypeCache;
96 llvm::SmallDenseMap<QualType, llvm::Metadata *> SizeExprCache;
100 const CGDebugInfo &Self;
103 PrintingCallbacks(
const CGDebugInfo &Self) : Self(Self) {}
104 std::string remapPath(StringRef Path)
const override {
105 return Self.remapDIPath(Path);
108 PrintingCallbacks PrintCB = {*
this};
110 struct ObjCInterfaceCacheEntry {
111 const ObjCInterfaceType *
Type;
114 ObjCInterfaceCacheEntry(
const ObjCInterfaceType *Type, llvm::DIType *Decl,
125 llvm::DenseMap<
const ObjCInterfaceDecl *,
126 std::vector<llvm::PointerIntPair<llvm::DISubprogram *, 1>>>
130 llvm::DenseMap<const Module *, llvm::TrackingMDRef> ModuleCache;
133 std::vector<void *> RetainedTypes;
136 std::vector<std::pair<const TagType *, llvm::TrackingMDRef>> ReplaceMap;
140 std::vector<std::pair<const DeclaratorDecl *, llvm::TrackingMDRef>>
144 std::vector<llvm::TypedTrackingMDRef<llvm::DIScope>> LexicalBlockStack;
145 llvm::DenseMap<const Decl *, llvm::TrackingMDRef> RegionMap;
149 std::vector<unsigned> FnBeginRegionCount;
153 llvm::BumpPtrAllocator DebugInfoNames;
156 llvm::DenseMap<const char *, llvm::TrackingMDRef> DIFileCache;
157 llvm::DenseMap<const FunctionDecl *, llvm::TrackingMDRef> SPCache;
161 llvm::DenseMap<const Decl *, llvm::TrackingMDRef> DeclCache;
162 llvm::DenseMap<const Decl *, llvm::TrackingMDRef> ImportedDeclCache;
163 llvm::DenseMap<const NamespaceDecl *, llvm::TrackingMDRef> NamespaceCache;
164 llvm::DenseMap<const NamespaceAliasDecl *, llvm::TrackingMDRef>
166 llvm::DenseMap<const Decl *, llvm::TypedTrackingMDRef<llvm::DIDerivedType>>
167 StaticDataMemberCache;
169 using ParamDecl2StmtTy = llvm::DenseMap<const ParmVarDecl *, const Stmt *>;
170 using Param2DILocTy =
171 llvm::DenseMap<const ParmVarDecl *, llvm::DILocalVariable *>;
174 ParamDecl2StmtTy CoroutineParameterMappings;
176 Param2DILocTy ParamDbgMappings;
182 llvm::DIType *CreateType(
const BuiltinType *Ty);
183 llvm::DIType *CreateType(
const ComplexType *Ty);
184 llvm::DIType *CreateType(
const BitIntType *Ty);
185 llvm::DIType *CreateQualifiedType(QualType Ty, llvm::DIFile *Fg);
186 llvm::DIType *CreateQualifiedType(
const FunctionProtoType *Ty,
188 llvm::DIType *CreateType(
const TypedefType *Ty, llvm::DIFile *Fg);
189 llvm::DIType *CreateType(
const TemplateSpecializationType *Ty,
191 llvm::DIType *CreateType(
const ObjCObjectPointerType *Ty, llvm::DIFile *F);
192 llvm::DIType *CreateType(
const PointerType *Ty, llvm::DIFile *F);
193 llvm::DIType *CreateType(
const BlockPointerType *Ty, llvm::DIFile *F);
194 llvm::DIType *CreateType(
const FunctionType *Ty, llvm::DIFile *F);
196 llvm::DIType *CreateType(
const RecordType *Tyg);
204 std::pair<llvm::DIType *, llvm::DIType *>
205 CreateTypeDefinition(
const RecordType *Ty);
206 llvm::DICompositeType *CreateLimitedType(
const RecordType *Ty);
207 void CollectContainingType(
const CXXRecordDecl *RD,
208 llvm::DICompositeType *CT);
210 llvm::DIType *CreateType(
const ObjCInterfaceType *Ty, llvm::DIFile *F);
211 llvm::DIType *CreateTypeDefinition(
const ObjCInterfaceType *Ty,
214 llvm::DIType *CreateType(
const ObjCObjectType *Ty, llvm::DIFile *F);
215 llvm::DIType *CreateType(
const ObjCTypeParamType *Ty, llvm::DIFile *Unit);
217 llvm::DIType *CreateType(
const VectorType *Ty, llvm::DIFile *F);
218 llvm::DIType *CreateType(
const ConstantMatrixType *Ty, llvm::DIFile *F);
219 llvm::DIType *CreateType(
const ArrayType *Ty, llvm::DIFile *F);
220 llvm::DIType *CreateType(
const LValueReferenceType *Ty, llvm::DIFile *F);
221 llvm::DIType *CreateType(
const RValueReferenceType *Ty, llvm::DIFile *Unit);
222 llvm::DIType *CreateType(
const MemberPointerType *Ty, llvm::DIFile *F);
223 llvm::DIType *CreateType(
const AtomicType *Ty, llvm::DIFile *F);
224 llvm::DIType *CreateType(
const PipeType *Ty, llvm::DIFile *F);
226 llvm::DIType *CreateEnumType(
const EnumType *Ty);
227 llvm::DIType *CreateTypeDefinition(
const EnumType *Ty);
234 llvm::DIType *CreateSelfType(
const QualType &QualTy, llvm::DIType *Ty);
239 llvm::DIType *getTypeOrNull(
const QualType);
244 llvm::DISubroutineType *getOrCreateMethodType(
const CXXMethodDecl *Method,
246 llvm::DISubroutineType *
247 getOrCreateInstanceMethodType(QualType ThisPtr,
const FunctionProtoType *Func,
249 llvm::DISubroutineType *
250 getOrCreateFunctionType(
const Decl *D, QualType FnType, llvm::DIFile *F);
252 llvm::DIType *getOrCreateVTablePtrType(llvm::DIFile *F);
255 llvm::DINamespace *getOrCreateNamespace(
const NamespaceDecl *N);
256 llvm::DIType *CreatePointerLikeType(llvm::dwarf::Tag Tag,
const Type *Ty,
257 QualType PointeeTy, llvm::DIFile *F);
258 llvm::DIType *getOrCreateStructPtrType(StringRef Name, llvm::DIType *&
Cache);
262 llvm::DISubprogram *CreateCXXMemberFunction(
const CXXMethodDecl *Method,
264 llvm::DIType *RecordTy);
269 void CollectCXXMemberFunctions(
const CXXRecordDecl *Decl, llvm::DIFile *F,
270 SmallVectorImpl<llvm::Metadata *> &E,
276 void CollectCXXBases(
const CXXRecordDecl *Decl, llvm::DIFile *F,
277 SmallVectorImpl<llvm::Metadata *> &EltTys,
278 llvm::DIType *RecordTy);
282 void CollectCXXBasesAux(
283 const CXXRecordDecl *RD, llvm::DIFile *Unit,
284 SmallVectorImpl<llvm::Metadata *> &EltTys, llvm::DIType *RecordTy,
287 llvm::DINode::DIFlags StartingFlags);
292 llvm::DIType *GetPreferredNameType(
const CXXRecordDecl *RD,
295 struct TemplateArgs {
296 const TemplateParameterList *TList;
300 llvm::DINodeArray CollectTemplateParams(std::optional<TemplateArgs> Args,
304 llvm::DINodeArray CollectFunctionTemplateParams(
const FunctionDecl *FD,
309 llvm::DINodeArray CollectVarTemplateParams(
const VarDecl *VD,
314 std::optional<TemplateArgs>
GetTemplateArgs(
const FunctionDecl *)
const;
318 llvm::DINodeArray CollectCXXTemplateParams(
const RecordDecl *TS,
322 llvm::DINodeArray CollectBTFDeclTagAnnotations(
const Decl *D);
324 llvm::DIType *createFieldType(StringRef
name, QualType
type,
326 uint64_t offsetInBits, uint32_t AlignInBits,
327 llvm::DIFile *tunit, llvm::DIScope *scope,
328 const RecordDecl *RD =
nullptr,
329 llvm::DINodeArray Annotations =
nullptr);
331 llvm::DIType *createFieldType(StringRef
name, QualType
type,
333 uint64_t offsetInBits, llvm::DIFile *tunit,
334 llvm::DIScope *scope,
335 const RecordDecl *RD =
nullptr) {
336 return createFieldType(
name,
type, loc, AS, offsetInBits, 0, tunit, scope,
341 llvm::DIDerivedType *createBitFieldType(
const FieldDecl *BitFieldDecl,
342 llvm::DIScope *RecordTy,
343 const RecordDecl *RD);
346 llvm::DIType *CreateBindingDeclType(
const BindingDecl *BD);
350 llvm::DIDerivedType *createBitFieldSeparatorIfNeeded(
351 const FieldDecl *BitFieldDecl,
const llvm::DIDerivedType *BitFieldDI,
356 void CollectRecordLambdaFields(
const CXXRecordDecl *CXXDecl,
357 SmallVectorImpl<llvm::Metadata *> &E,
358 llvm::DIType *RecordTy);
359 llvm::DIDerivedType *CreateRecordStaticField(
const VarDecl *Var,
360 llvm::DIType *RecordTy,
361 const RecordDecl *RD);
362 void CollectRecordNormalField(
const FieldDecl *Field,
uint64_t OffsetInBits,
364 SmallVectorImpl<llvm::Metadata *> &E,
365 llvm::DIType *RecordTy,
const RecordDecl *RD);
366 void CollectRecordNestedType(
const TypeDecl *RD,
367 SmallVectorImpl<llvm::Metadata *> &E);
368 void CollectRecordFields(
const RecordDecl *Decl, llvm::DIFile *F,
369 SmallVectorImpl<llvm::Metadata *> &E,
370 llvm::DICompositeType *RecordTy);
374 void CollectVTableInfo(
const CXXRecordDecl *Decl, llvm::DIFile *F,
375 SmallVectorImpl<llvm::Metadata *> &EltTys);
379 void CreateLexicalBlock(SourceLocation
Loc);
387 void AppendAddressSpaceXDeref(
unsigned AddressSpace,
388 SmallVectorImpl<uint64_t> &Expr)
const;
394 uint64_t collectDefaultElementTypesForBlockPointer(
395 const BlockPointerType *Ty, llvm::DIFile *Unit,
396 llvm::DIDerivedType *DescTy,
unsigned LineNo,
397 SmallVectorImpl<llvm::Metadata *> &EltTys);
401 void collectDefaultFieldsForBlockLiteralDeclare(
402 const CGBlockInfo &Block,
const ASTContext &Context, SourceLocation
Loc,
403 const llvm::StructLayout &BlockLayout, llvm::DIFile *Unit,
404 SmallVectorImpl<llvm::Metadata *> &Fields);
407 CGDebugInfo(CodeGenModule &CGM);
413 std::string remapDIPath(StringRef)
const;
417 SizeExprCache[Ty] = SizeExpr;
446 void setInlinedAt(llvm::MDNode *InlinedAt) { CurInlinedAt = InlinedAt; }
468 llvm::Function *Fn,
bool CurFnIsThunk);
478 QualType FnType, llvm::Function *Fn =
nullptr);
482 void EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
487 void EmitFunctionEnd(
CGBuilderTy &Builder, llvm::Function *Fn);
501 llvm::DILocalVariable *
502 EmitDeclareOfAutoVariable(
const VarDecl *
Decl, llvm::Value *AI,
504 const bool UsePointerValue =
false);
511 void EmitDeclareOfBlockDeclRefVariable(
513 const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint =
nullptr);
517 llvm::DILocalVariable *
518 EmitDeclareOfArgVariable(
const VarDecl *
Decl, llvm::Value *AI,
unsigned ArgNo,
519 CGBuilderTy &Builder,
bool UsePointerValue =
false);
523 void EmitDeclareOfBlockLiteralArgVariable(
const CGBlockInfo &block,
524 StringRef Name,
unsigned ArgNo,
525 llvm::AllocaInst *LocalAddr,
529 void EmitGlobalVariable(llvm::GlobalVariable *GV,
const VarDecl *
Decl);
535 void EmitExternalVariable(llvm::GlobalVariable *GV,
const VarDecl *
Decl);
538 void EmitGlobalAlias(
const llvm::GlobalValue *GV,
const GlobalDecl Decl);
544 void EmitExplicitCastType(
QualType Ty);
547 void EmitAndRetainType(
QualType Ty);
566 void AddStringLiteralDebugInfo(llvm::GlobalVariable *GV,
582 void addHeapAllocSiteMetadata(llvm::CallBase *CallSite,
QualType AllocatedTy,
585 void completeType(
const EnumDecl *ED);
587 void completeRequiredType(
const RecordDecl *RD);
596 llvm::DIMacro *CreateMacro(llvm::DIMacroFile *
Parent,
unsigned MType,
601 llvm::DIMacroFile *CreateTempMacroFile(llvm::DIMacroFile *
Parent,
607 return CoroutineParameterMappings;
614 llvm::DILocalVariable *EmitDeclare(
const VarDecl *
decl, llvm::Value *AI,
615 std::optional<unsigned> ArgNo,
617 const bool UsePointerValue =
false);
622 llvm::DILocalVariable *EmitDeclare(
const BindingDecl *
decl, llvm::Value *AI,
623 std::optional<unsigned> ArgNo,
625 const bool UsePointerValue =
false);
627 struct BlockByRefType {
629 llvm::DIType *BlockByRefWrapper;
631 llvm::DIType *WrappedType;
635 std::string GetName(
const Decl *,
bool Qualified =
false)
const;
638 BlockByRefType EmitTypeForVarWithBlocksAttr(
const VarDecl *VD,
642 llvm::DIScope *getDeclContextDescriptor(
const Decl *D);
644 llvm::DIScope *getContextDescriptor(
const Decl *Context,
645 llvm::DIScope *Default);
647 llvm::DIScope *getCurrentContextDescriptor(
const Decl *
Decl);
650 llvm::DICompositeType *getOrCreateRecordFwdDecl(
const RecordType *,
654 StringRef getCurrentDirname();
657 void CreateCompileUnit();
660 std::optional<llvm::DIFile::ChecksumKind>
672 createFile(StringRef FileName,
673 std::optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo,
674 std::optional<StringRef> Source);
677 llvm::DIType *getOrCreateType(
QualType Ty, llvm::DIFile *Fg);
682 bool CreateSkeletonCU);
685 llvm::DIModule *getParentModuleOrNull(
const Decl *D);
689 llvm::DICompositeType *getOrCreateLimitedType(
const RecordType *Ty);
692 llvm::DIType *CreateTypeNode(
QualType Ty, llvm::DIFile *Fg);
695 llvm::DIType *CreateMemberType(llvm::DIFile *Unit,
QualType FType,
700 llvm::DINode *getDeclarationOrDefinition(
const Decl *D);
704 llvm::DISubprogram *getFunctionDeclaration(
const Decl *D);
713 getObjCMethodDeclaration(
const Decl *D, llvm::DISubroutineType *FnType,
714 unsigned LineNo, llvm::DINode::DIFlags Flags,
715 llvm::DISubprogram::DISPFlags SPFlags);
721 llvm::DIDerivedType *
722 getOrCreateStaticDataMemberDeclarationOrNull(
const VarDecl *D);
725 llvm::DISubprogram *getFunctionFwdDeclOrStub(
GlobalDecl GD,
bool Stub);
729 llvm::DISubprogram *getFunctionForwardDeclaration(
GlobalDecl GD);
733 llvm::DISubprogram *getFunctionStub(
GlobalDecl GD);
737 llvm::DIGlobalVariable *
738 getGlobalVariableForwardDeclaration(
const VarDecl *VD);
747 llvm::DIGlobalVariableExpression *
748 CollectAnonRecordDecls(
const RecordDecl *RD, llvm::DIFile *Unit,
749 unsigned LineNo, StringRef LinkageName,
750 llvm::GlobalVariable *Var, llvm::DIScope *DContext);
755 llvm::DINode::DIFlags getCallSiteRelatedAttrs()
const;
771 StringRef getSelectorName(
Selector S);
781 StringRef getDynamicInitializerName(
const VarDecl *VD,
783 llvm::Function *InitFn);
796 void collectFunctionDeclProps(
GlobalDecl GD, llvm::DIFile *Unit,
797 StringRef &Name, StringRef &LinkageName,
798 llvm::DIScope *&FDContext,
799 llvm::DINodeArray &TParamsArray,
800 llvm::DINode::DIFlags &Flags);
803 void collectVarDeclProps(
const VarDecl *VD, llvm::DIFile *&Unit,
804 unsigned &LineNo,
QualType &
T, StringRef &Name,
805 StringRef &LinkageName,
806 llvm::MDTuple *&TemplateParameters,
807 llvm::DIScope *&VDContext);
811 llvm::DIExpression *createConstantValueExpression(
const clang::ValueDecl *VD,
817 StringRef internString(StringRef A, StringRef B = StringRef()) {
818 char *
Data = DebugInfoNames.Allocate<
char>(A.size() + B.size());
823 return StringRef(Data, A.size() + B.size());
831 void init(
SourceLocation TemporaryLocation,
bool DefaultToEmpty =
false);
835 llvm::DebugLoc OriginalLocation;
849 if (
this != &
Other) {
static llvm::SmallVector< TemplateArgument > GetTemplateArgs(const TemplateDecl *TD, const TemplateSpecializationType *Ty)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::Module class, which describes a module in the source code.
Defines the clang::SourceLocation class and associated facilities.
Allows QualTypes to be sorted and hence used in maps and sets.
TypePropertyCache< Private > Cache
C Language Family Type Representation.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Abstracts clang modules and precompiled header files and holds everything needed to generate debug in...
A binding in a decomposition declaration.
Represents a C++ struct/union/class.
llvm::iterator_range< base_class_const_iterator > base_class_const_range
Represents a class template specialization, which refers to a class template with a given set of temp...
A scoped helper to set the current debug location to the specified location or preferred location of ...
static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF)
Apply TemporaryLocation if it is valid.
static ApplyDebugLocation CreateDefaultArtificial(CodeGenFunction &CGF, SourceLocation TemporaryLocation)
Apply TemporaryLocation if it is valid.
ApplyDebugLocation(ApplyDebugLocation &&Other)
ApplyDebugLocation & operator=(ApplyDebugLocation &&Other)
static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF)
Set the IRBuilder to not attach debug locations.
A scoped helper to set the current debug location to an inlined location.
CGBlockInfo - Information to generate a block literal.
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
Param2DILocTy & getParamDbgMappings()
llvm::MDNode * getInlinedAt() const
void setInlinedAt(llvm::MDNode *InlinedAt)
Update the current inline scope.
SourceLocation getLocation() const
Return the current source location.
ParamDecl2StmtTy & getCoroutineParameterMappings()
void setModuleMap(ModuleMap &MMap)
When generating debug information for a clang module or precompiled header, this module map will be u...
void setPCHDescriptor(ASTSourceDescriptor PCH)
When generating debug information for a clang module or precompiled header, this module map will be u...
void registerVLASizeExpression(QualType Ty, llvm::Metadata *SizeExpr)
Register VLA size expression debug node with the qualified type.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
This class organizes the cross-function state that is used while generating LLVM code.
Decl - This represents one declaration (or definition), e.g.
This represents one expression.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Represents a function declaration or definition.
GlobalDecl - represents a global declaration.
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Represents the declaration of a label.
Represents a C++ namespace alias.
ObjCMethodDecl - Represents an instance or class method declaration.
Callbacks to use to customize the behavior of the pretty-printer.
A (possibly-)qualified type.
Represents a struct/union/class.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Smart pointer class that efficiently represents Objective-C method names.
Encodes a location in the source.
This class handles loading and caching of source files into memory.
StringLiteral - This represents a string literal expression, e.g.
Represents a C++ using-declaration.
Represents C++ using-directive.
Represents a C++ using-enum-declaration.
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
bool noSystemDebugInfo(const Decl *D, const CodeGenModule &CGM)
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
void EmitLocation(raw_ostream &o, const SourceManager &SM, SourceLocation L, const FIDMap &FM, unsigned indent)
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
@ PCH
Disable validation for a precompiled header and the modules it depends on.
void finalize(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema)
@ Other
Other implicit parameter.
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Diagnostic wrappers for TextAPI types for error reporting.
Describes how types, statements, expressions, and declarations should be printed.