14 #ifndef LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
15 #define LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
24 #include "llvm/ADT/DenseMap.h"
25 #include "llvm/ADT/DenseSet.h"
26 #include "llvm/ADT/Optional.h"
27 #include "llvm/IR/DIBuilder.h"
28 #include "llvm/IR/DebugInfo.h"
29 #include "llvm/IR/ValueHandle.h"
30 #include "llvm/Support/Allocator.h"
37 class ClassTemplateSpecializationDecl;
40 class ObjCInterfaceDecl;
47 class CodeGenFunction;
58 bool DebugTypeExtRefs;
59 llvm::DIBuilder DBuilder;
60 llvm::DICompileUnit *TheCU =
nullptr;
64 llvm::MDNode *CurInlinedAt =
nullptr;
65 llvm::DIType *VTablePtrType =
nullptr;
66 llvm::DIType *ClassTy =
nullptr;
67 llvm::DICompositeType *ObjTy =
nullptr;
68 llvm::DIType *SelTy =
nullptr;
69 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
70 llvm::DIType *SingletonId = nullptr;
71 #include "clang/Basic/OpenCLImageTypes.def"
72 llvm::DIType *OCLSamplerDITy =
nullptr;
73 llvm::DIType *OCLEventDITy =
nullptr;
74 llvm::DIType *OCLClkEventDITy =
nullptr;
75 llvm::DIType *OCLQueueDITy =
nullptr;
76 llvm::DIType *OCLNDRangeDITy =
nullptr;
77 llvm::DIType *OCLReserveIDDITy =
nullptr;
80 llvm::DenseMap<const void *, llvm::TrackingMDRef> TypeCache;
82 llvm::SmallDenseMap<llvm::StringRef, llvm::StringRef> DebugPrefixMap;
84 struct ObjCInterfaceCacheEntry {
85 const ObjCInterfaceType *
Type;
88 ObjCInterfaceCacheEntry(
const ObjCInterfaceType *
Type, llvm::DIType *
Decl,
90 :
Type(Type),
Decl(Decl), Unit(Unit) {}
97 llvm::DenseMap<const Module *, llvm::TrackingMDRef> ModuleCache;
100 std::vector<void *> RetainedTypes;
103 std::vector<std::pair<const TagType *, llvm::TrackingMDRef>> ReplaceMap;
107 std::vector<std::pair<const DeclaratorDecl *, llvm::TrackingMDRef>>
111 std::vector<llvm::TypedTrackingMDRef<llvm::DIScope>> LexicalBlockStack;
112 llvm::DenseMap<const Decl *, llvm::TrackingMDRef> RegionMap;
116 std::vector<unsigned> FnBeginRegionCount;
120 llvm::BumpPtrAllocator DebugInfoNames;
123 llvm::DenseMap<const char *, llvm::TrackingMDRef> DIFileCache;
124 llvm::DenseMap<const FunctionDecl *, llvm::TrackingMDRef> SPCache;
127 llvm::DenseMap<const Decl *, llvm::TrackingMDRef> DeclCache;
128 llvm::DenseMap<const NamespaceDecl *, llvm::TrackingMDRef> NamespaceCache;
129 llvm::DenseMap<const NamespaceAliasDecl *, llvm::TrackingMDRef>
131 llvm::DenseMap<const Decl *, llvm::TypedTrackingMDRef<llvm::DIDerivedType>>
132 StaticDataMemberCache;
138 llvm::DIType *CreateType(
const BuiltinType *Ty);
139 llvm::DIType *CreateType(
const ComplexType *Ty);
140 llvm::DIType *CreateQualifiedType(QualType Ty, llvm::DIFile *Fg);
141 llvm::DIType *CreateType(
const TypedefType *Ty, llvm::DIFile *Fg);
142 llvm::DIType *CreateType(
const TemplateSpecializationType *Ty,
144 llvm::DIType *CreateType(
const ObjCObjectPointerType *Ty, llvm::DIFile *F);
145 llvm::DIType *CreateType(
const PointerType *Ty, llvm::DIFile *F);
146 llvm::DIType *CreateType(
const BlockPointerType *Ty, llvm::DIFile *F);
147 llvm::DIType *CreateType(
const FunctionType *Ty, llvm::DIFile *F);
149 llvm::DIType *CreateType(
const RecordType *Tyg);
150 llvm::DIType *CreateTypeDefinition(
const RecordType *Ty);
151 llvm::DICompositeType *CreateLimitedType(
const RecordType *Ty);
152 void CollectContainingType(
const CXXRecordDecl *RD,
153 llvm::DICompositeType *CT);
155 llvm::DIType *CreateType(
const ObjCInterfaceType *Ty, llvm::DIFile *F);
156 llvm::DIType *CreateTypeDefinition(
const ObjCInterfaceType *Ty,
159 llvm::DIType *CreateType(
const ObjCObjectType *Ty, llvm::DIFile *F);
160 llvm::DIType *CreateType(
const ObjCTypeParamType *Ty, llvm::DIFile *Unit);
162 llvm::DIType *CreateType(
const VectorType *Ty, llvm::DIFile *F);
163 llvm::DIType *CreateType(
const ArrayType *Ty, llvm::DIFile *F);
164 llvm::DIType *CreateType(
const LValueReferenceType *Ty, llvm::DIFile *F);
165 llvm::DIType *CreateType(
const RValueReferenceType *Ty, llvm::DIFile *Unit);
166 llvm::DIType *CreateType(
const MemberPointerType *Ty, llvm::DIFile *F);
167 llvm::DIType *CreateType(
const AtomicType *Ty, llvm::DIFile *F);
168 llvm::DIType *CreateType(
const PipeType *Ty, llvm::DIFile *F);
170 llvm::DIType *CreateEnumType(
const EnumType *Ty);
171 llvm::DIType *CreateTypeDefinition(
const EnumType *Ty);
178 llvm::DIType *CreateSelfType(
const QualType &QualTy, llvm::DIType *Ty);
183 llvm::DIType *getTypeOrNull(
const QualType);
188 llvm::DISubroutineType *getOrCreateMethodType(
const CXXMethodDecl *Method,
190 llvm::DISubroutineType *
191 getOrCreateInstanceMethodType(QualType ThisPtr,
const FunctionProtoType *Func,
193 llvm::DISubroutineType *
194 getOrCreateFunctionType(
const Decl *D, QualType FnType, llvm::DIFile *F);
196 llvm::DIType *getOrCreateVTablePtrType(llvm::DIFile *F);
199 llvm::DINamespace *getOrCreateNamespace(
const NamespaceDecl *N);
200 llvm::DIType *CreatePointerLikeType(llvm::dwarf::Tag Tag,
const Type *Ty,
201 QualType PointeeTy, llvm::DIFile *F);
202 llvm::DIType *getOrCreateStructPtrType(StringRef
Name, llvm::DIType *&
Cache);
206 llvm::DISubprogram *CreateCXXMemberFunction(
const CXXMethodDecl *Method,
208 llvm::DIType *RecordTy);
213 void CollectCXXMemberFunctions(
const CXXRecordDecl *
Decl, llvm::DIFile *F,
214 SmallVectorImpl<llvm::Metadata *> &
E,
220 void CollectCXXBases(
const CXXRecordDecl *
Decl, llvm::DIFile *F,
221 SmallVectorImpl<llvm::Metadata *> &EltTys,
222 llvm::DIType *RecordTy);
226 void CollectCXXBasesAux(
const CXXRecordDecl *RD, llvm::DIFile *Unit,
227 SmallVectorImpl<llvm::Metadata *> &EltTys,
228 llvm::DIType *RecordTy,
231 llvm::DINode::DIFlags StartingFlags);
234 llvm::DINodeArray CollectTemplateParams(
const TemplateParameterList *TPList,
235 ArrayRef<TemplateArgument> TAList,
239 llvm::DINodeArray CollectFunctionTemplateParams(
const FunctionDecl *FD,
245 CollectCXXTemplateParams(
const ClassTemplateSpecializationDecl *TS,
248 llvm::DIType *createFieldType(StringRef name, QualType
type,
250 uint64_t offsetInBits,
251 uint32_t AlignInBits,
252 llvm::DIFile *tunit, llvm::DIScope *scope,
253 const RecordDecl *RD =
nullptr);
255 llvm::DIType *createFieldType(StringRef name, QualType
type,
257 uint64_t offsetInBits, llvm::DIFile *tunit,
258 llvm::DIScope *scope,
259 const RecordDecl *RD =
nullptr) {
260 return createFieldType(name, type, loc, AS, offsetInBits, 0, tunit, scope,
265 llvm::DIType *createBitFieldType(
const FieldDecl *BitFieldDecl,
266 llvm::DIScope *RecordTy,
267 const RecordDecl *RD);
271 void CollectRecordLambdaFields(
const CXXRecordDecl *CXXDecl,
272 SmallVectorImpl<llvm::Metadata *> &
E,
273 llvm::DIType *RecordTy);
274 llvm::DIDerivedType *CreateRecordStaticField(
const VarDecl *Var,
275 llvm::DIType *RecordTy,
276 const RecordDecl *RD);
277 void CollectRecordNormalField(
const FieldDecl *Field, uint64_t OffsetInBits,
279 SmallVectorImpl<llvm::Metadata *> &
E,
280 llvm::DIType *RecordTy,
const RecordDecl *RD);
281 void CollectRecordNestedRecord(
const RecordDecl *RD,
282 SmallVectorImpl<llvm::Metadata *> &
E);
283 void CollectRecordFields(
const RecordDecl *
Decl, llvm::DIFile *F,
284 SmallVectorImpl<llvm::Metadata *> &
E,
285 llvm::DICompositeType *RecordTy);
289 void CollectVTableInfo(
const CXXRecordDecl *
Decl, llvm::DIFile *F,
290 SmallVectorImpl<llvm::Metadata *> &EltTys,
291 llvm::DICompositeType *RecordTy);
295 void CreateLexicalBlock(SourceLocation Loc);
303 void AppendAddressSpaceXDeref(
unsigned AddressSpace,
304 SmallVectorImpl<int64_t> &Expr)
const;
340 void setInlinedAt(llvm::MDNode *InlinedAt) { CurInlinedAt = InlinedAt; }
391 llvm::Instruction *InsertPoint =
nullptr);
446 llvm::DIMacro *
CreateMacro(llvm::DIMacroFile *Parent,
unsigned MType,
460 llvm::DIType *EmitTypeForVarWithBlocksAttr(
const VarDecl *VD,
464 llvm::DIScope *getDeclContextDescriptor(
const Decl *D);
466 llvm::DIScope *getContextDescriptor(
const Decl *
Context,
469 llvm::DIScope *getCurrentContextDescriptor(
const Decl *
Decl);
472 llvm::DICompositeType *getOrCreateRecordFwdDecl(
const RecordType *,
476 StringRef getCurrentDirname();
479 void CreateCompileUnit();
482 std::string remapDIPath(StringRef)
const;
485 llvm::DIFile::ChecksumKind computeChecksum(
FileID FID,
492 llvm::DIFile *getOrCreateMainFile();
495 llvm::DIType *getOrCreateType(
QualType Ty, llvm::DIFile *Fg);
501 bool CreateSkeletonCU);
504 llvm::DIModule *getParentModuleOrNull(
const Decl *D);
508 llvm::DICompositeType *getOrCreateLimitedType(
const RecordType *Ty,
512 llvm::DIType *CreateTypeNode(
QualType Ty, llvm::DIFile *Fg);
515 llvm::DIType *CreateMemberType(llvm::DIFile *Unit,
QualType FType,
520 llvm::DINode *getDeclarationOrDefinition(
const Decl *D);
524 llvm::DISubprogram *getFunctionDeclaration(
const Decl *D);
530 llvm::DIDerivedType *
531 getOrCreateStaticDataMemberDeclarationOrNull(
const VarDecl *D);
534 llvm::DISubprogram *getFunctionFwdDeclOrStub(
GlobalDecl GD,
bool Stub);
538 llvm::DISubprogram *getFunctionForwardDeclaration(
GlobalDecl GD);
542 llvm::DISubprogram *getFunctionStub(
GlobalDecl GD);
546 llvm::DIGlobalVariable *
547 getGlobalVariableForwardDeclaration(
const VarDecl *VD);
556 llvm::DIGlobalVariableExpression *
557 CollectAnonRecordDecls(
const RecordDecl *RD, llvm::DIFile *Unit,
558 unsigned LineNo, StringRef LinkageName,
559 llvm::GlobalVariable *Var, llvm::DIScope *DContext);
591 void collectFunctionDeclProps(
GlobalDecl GD, llvm::DIFile *Unit,
592 StringRef &
Name, StringRef &LinkageName,
593 llvm::DIScope *&FDContext,
594 llvm::DINodeArray &TParamsArray,
595 llvm::DINode::DIFlags &Flags);
598 void collectVarDeclProps(
const VarDecl *VD, llvm::DIFile *&Unit,
600 StringRef &LinkageName, llvm::DIScope *&VDContext);
605 StringRef internString(StringRef A, StringRef B = StringRef()) {
606 char *Data = DebugInfoNames.Allocate<
char>(A.size() + B.size());
608 std::memcpy(Data, A.data(), A.size());
610 std::memcpy(Data + A.size(), B.data(), B.size());
611 return StringRef(Data, A.size() + B.size());
619 void init(
SourceLocation TemporaryLocation,
bool DefaultToEmpty =
false);
623 llvm::DebugLoc OriginalLocation;
688 #endif // LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
void EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block, llvm::Value *Arg, unsigned ArgNo, llvm::Value *LocalAddr, CGBuilderTy &Builder)
Emit call to llvm.dbg.declare for the block-literal argument to a block invocation function...
Smart pointer class that efficiently represents Objective-C method names.
A (possibly-)qualified type.
void EmitExplicitCastType(QualType Ty)
Emit the type explicitly casted to.
llvm::DIType * getOrCreateRecordType(QualType Ty, SourceLocation L)
Emit record type's standalone debug info.
void EmitLexicalBlockEnd(CGBuilderTy &Builder, SourceLocation Loc)
Emit metadata to indicate the end of a new lexical block and pop the current block.
llvm::iterator_range< base_class_const_iterator > base_class_const_range
C Language Family Type Representation.
Decl - This represents one declaration (or definition), e.g.
TypePropertyCache< Private > Cache
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
SourceLocation getLocation() const
Return the current source location.
void setPCHDescriptor(ExternalASTSource::ASTSourceDescriptor PCH)
When generating debug information for a clang module or precompiled header, this module map will be u...
VarDecl - An instance of this class is created to represent a variable declaration or definition...
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI, CGBuilderTy &Builder)
Emit call to llvm.dbg.declare for an automatic variable declaration.
ObjCMethodDecl - Represents an instance or class method declaration.
void completeTemplateDefinition(const ClassTemplateSpecializationDecl &SD)
void setInlinedAt(llvm::MDNode *InlinedAt)
Update the current inline scope.
void EmitInlineFunctionEnd(CGBuilderTy &Builder)
End an inlined function scope.
RecordDecl - Represents a struct/union/class.
Represents a class template specialization, which refers to a class template with a given set of temp...
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
void EmitImportDecl(const ImportDecl &ID)
Emit an declaration.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
void completeClassData(const RecordDecl *RD)
llvm::DIMacro * CreateMacro(llvm::DIMacroFile *Parent, unsigned MType, SourceLocation LineLoc, StringRef Name, StringRef Value)
Create debug info for a macro defined by a #define directive or a macro undefined by a #undef directi...
static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF)
Apply TemporaryLocation if it is valid.
Represents a C++ using-declaration.
friend class SaveAndRestoreLocation
~ApplyInlineDebugLocation()
Restore everything back to the orginial state.
void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl)
Emit information about a global variable.
llvm::DIType * getOrCreateInterfaceType(QualType Ty, SourceLocation Loc)
Emit an Objective-C interface type standalone debug info.
void EmitFunctionEnd(CGBuilderTy &Builder, llvm::Function *Fn)
Constructs the debug code for exiting a function.
llvm::DIImportedEntity * EmitNamespaceAlias(const NamespaceAliasDecl &NA)
Emit C++ namespace alias.
CGBlockInfo - Information to generate a block literal.
void setDwoId(uint64_t Signature)
Module debugging: Support for building PCMs.
void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc)
Emit metadata to indicate a change in line/column information in the source file. ...
ApplyInlineDebugLocation(CodeGenFunction &CGF, GlobalDecl InlinedFn)
Set up the CodeGenFunction's DebugInfo to produce inline locations for the function InlinedFn...
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Expr - This represents one expression.
void EmitInlineFunctionStart(CGBuilderTy &Builder, GlobalDecl GD)
Start a new scope for an inlined function.
llvm::DIMacroFile * CreateTempMacroFile(llvm::DIMacroFile *Parent, SourceLocation LineLoc, SourceLocation FileLoc)
Create debug info for a file referenced by an #include directive.
void completeUnusedClass(const CXXRecordDecl &D)
A scoped helper to set the current debug location to an inlined location.
GlobalDecl - represents a global declaration.
The l-value was considered opaque, so the alignment was determined from a type.
void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI, unsigned ArgNo, CGBuilderTy &Builder)
Emit call to llvm.dbg.declare for an argument variable declaration.
void EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc, QualType FnType)
Emit debug info for a function declaration.
Encodes a location in the source.
void completeRequiredType(const RecordDecl *RD)
A scoped helper to set the current debug location to the specified location or preferred location of ...
llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Loc)
Describes a module import declaration, which makes the contents of the named module visible in the cu...
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
void completeClass(const RecordDecl *RD)
This class organizes the cross-function state that is used while generating LLVM code.
static ApplyDebugLocation CreateDefaultArtificial(CodeGenFunction &CGF, SourceLocation TemporaryLocation)
Apply TemporaryLocation if it is valid.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
CGDebugInfo(CodeGenModule &CGM)
EnumDecl - Represents an enum.
detail::InMemoryDirectory::const_iterator E
void setModuleMap(ModuleMap &MMap)
When generating debug information for a clang module or precompiled header, this module map will be u...
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
llvm::DIType * getOrCreateStandaloneType(QualType Ty, SourceLocation Loc)
Emit standalone debug info for a type.
void completeType(const EnumDecl *ED)
ApplyDebugLocation(ApplyDebugLocation &&Other)
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
void EmitUsingDecl(const UsingDecl &UD)
Emit C++ using declaration.
void EmitUsingDirective(const UsingDirectiveDecl &UD)
Emit C++ using directive.
void EmitLexicalBlockStart(CGBuilderTy &Builder, SourceLocation Loc)
Emit metadata to indicate the beginning of a new lexical block and push the block onto the stack...
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
Defines the clang::SourceLocation class and associated facilities.
Represents a C++ struct/union/class.
BoundNodesTreeBuilder *const Builder
void EmitDeclareOfBlockDeclRefVariable(const VarDecl *variable, llvm::Value *storage, CGBuilderTy &Builder, const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint=nullptr)
Emit call to llvm.dbg.declare for an imported variable declaration in a block.
void EmitFunctionStart(GlobalDecl GD, SourceLocation Loc, SourceLocation ScopeLoc, QualType FnType, llvm::Function *Fn, CGBuilderTy &Builder)
Emit a call to llvm.dbg.function.start to indicate start of a new function.
void setLocation(SourceLocation Loc)
Update the current source location.
Abstracts clang modules and precompiled header files and holds everything needed to generate debug in...
llvm::MDNode * getInlinedAt() const
static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF)
Set the IRBuilder to not attach debug locations.
Represents a C++ namespace alias.
Represents C++ using-directive.