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;
55 friend class SaveAndRestoreLocation;
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,
229 const CXXRecordDecl::base_class_const_range &Bases,
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 CollectRecordNestedType(
const TypeDecl *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;
307 CGDebugInfo(CodeGenModule &CGM);
315 void setDwoId(uint64_t Signature);
340 void setInlinedAt(llvm::MDNode *InlinedAt) { CurInlinedAt = InlinedAt; }
370 void EmitFunctionEnd(
CGBuilderTy &Builder, llvm::Function *Fn);
387 void EmitDeclareOfBlockDeclRefVariable(
const VarDecl *variable,
391 llvm::Instruction *InsertPoint =
nullptr);
400 void EmitDeclareOfBlockLiteralArgVariable(
const CGBlockInfo &block,
401 StringRef Name,
unsigned ArgNo,
402 llvm::AllocaInst *LocalAddr,
406 void EmitGlobalVariable(llvm::GlobalVariable *GV,
const VarDecl *Decl);
415 void EmitExplicitCastType(
QualType Ty);
435 void completeType(
const EnumDecl *ED);
437 void completeRequiredType(
const RecordDecl *RD);
446 llvm::DIMacro *CreateMacro(llvm::DIMacroFile *
Parent,
unsigned MType,
451 llvm::DIMacroFile *CreateTempMacroFile(llvm::DIMacroFile *Parent,
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,
516 StringRef Name, uint64_t *
Offset);
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);
575 StringRef getSelectorName(
Selector S);
594 void collectFunctionDeclProps(
GlobalDecl GD, llvm::DIFile *Unit,
595 StringRef &Name, StringRef &LinkageName,
596 llvm::DIScope *&FDContext,
597 llvm::DINodeArray &TParamsArray,
598 llvm::DINode::DIFlags &Flags);
601 void collectVarDeclProps(
const VarDecl *VD, llvm::DIFile *&Unit,
602 unsigned &LineNo,
QualType &T, StringRef &Name,
603 StringRef &LinkageName, llvm::DIScope *&VDContext);
608 StringRef internString(StringRef A, StringRef B = StringRef()) {
609 char *Data = DebugInfoNames.Allocate<
char>(A.size() + B.size());
611 std::memcpy(Data, A.data(), A.size());
613 std::memcpy(Data + A.size(), B.data(), B.size());
614 return StringRef(Data, A.size() + B.size());
622 void init(
SourceLocation TemporaryLocation,
bool DefaultToEmpty =
false);
626 llvm::DebugLoc OriginalLocation;
691 #endif // LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
An instance of this class is created to represent a function declaration or definition.
llvm::MDNode * getInlinedAt() const
Smart pointer class that efficiently represents Objective-C method names.
void EmitLocation(raw_ostream &o, const SourceManager &SM, SourceLocation L, const FIDMap &FM, unsigned indent)
A (possibly-)qualified type.
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
C Language Family Type Representation.
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
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...
ObjCMethodDecl - Represents an instance or class method declaration.
Describes how types, statements, expressions, and declarations should be printed. ...
void setInlinedAt(llvm::MDNode *InlinedAt)
Update the current inline 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...
static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF)
Apply TemporaryLocation if it is valid.
Represents a C++ using-declaration.
CGBlockInfo - Information to generate a block literal.
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Expr - This represents one expression.
const FunctionProtoType * T
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
A scoped helper to set the current debug location to an inlined location.
GlobalDecl - represents a global declaration.
Encodes a location in the source.
A scoped helper to set the current debug location to the specified location or preferred location of ...
Describes a module import declaration, which makes the contents of the named module visible in the cu...
SourceLocation getLocation() const
Return the current source location.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
This class organizes the cross-function state that is used while generating LLVM code.
Dataflow Directional Tag Classes.
static ApplyDebugLocation CreateDefaultArtificial(CodeGenFunction &CGF, SourceLocation TemporaryLocation)
Apply TemporaryLocation if it is valid.
EnumDecl - Represents an enum.
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...
ApplyDebugLocation(ApplyDebugLocation &&Other)
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
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.
Abstracts clang modules and precompiled header files and holds everything needed to generate debug in...
static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF)
Set the IRBuilder to not attach debug locations.
Represents a C++ namespace alias.
Represents C++ using-directive.