clang  7.0.0
CGDebugInfo.h
Go to the documentation of this file.
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 //
10 // This is the source-level debug info generator for llvm translation.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
15 #define LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
16 
17 #include "CGBuilder.h"
18 #include "clang/AST/DeclCXX.h"
19 #include "clang/AST/Expr.h"
21 #include "clang/AST/Type.h"
22 #include "clang/AST/TypeOrdering.h"
25 #include "llvm/ADT/DenseMap.h"
26 #include "llvm/ADT/DenseSet.h"
27 #include "llvm/ADT/Optional.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"
32 
33 namespace llvm {
34 class MDNode;
35 }
36 
37 namespace clang {
38 class ClassTemplateSpecializationDecl;
39 class GlobalDecl;
40 class ModuleMap;
41 class ObjCInterfaceDecl;
42 class ObjCIvarDecl;
43 class UsingDecl;
44 class VarDecl;
45 
46 namespace CodeGen {
47 class CodeGenModule;
48 class CodeGenFunction;
49 class CGBlockInfo;
50 
51 /// This class gathers all debug information during compilation and is
52 /// responsible for emitting to llvm globals or pass directly to the
53 /// backend.
54 class CGDebugInfo {
55  friend class ApplyDebugLocation;
56  friend class SaveAndRestoreLocation;
57  CodeGenModule &CGM;
58  const codegenoptions::DebugInfoKind DebugKind;
59  bool DebugTypeExtRefs;
60  llvm::DIBuilder DBuilder;
61  llvm::DICompileUnit *TheCU = nullptr;
62  ModuleMap *ClangModuleMap = nullptr;
64  SourceLocation CurLoc;
65  llvm::MDNode *CurInlinedAt = nullptr;
66  llvm::DIType *VTablePtrType = nullptr;
67  llvm::DIType *ClassTy = nullptr;
68  llvm::DICompositeType *ObjTy = nullptr;
69  llvm::DIType *SelTy = nullptr;
70 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
71  llvm::DIType *SingletonId = nullptr;
72 #include "clang/Basic/OpenCLImageTypes.def"
73  llvm::DIType *OCLSamplerDITy = nullptr;
74  llvm::DIType *OCLEventDITy = nullptr;
75  llvm::DIType *OCLClkEventDITy = nullptr;
76  llvm::DIType *OCLQueueDITy = nullptr;
77  llvm::DIType *OCLNDRangeDITy = nullptr;
78  llvm::DIType *OCLReserveIDDITy = nullptr;
79 
80  /// Cache of previously constructed Types.
81  llvm::DenseMap<const void *, llvm::TrackingMDRef> TypeCache;
82 
83  llvm::SmallDenseMap<llvm::StringRef, llvm::StringRef> DebugPrefixMap;
84 
85  /// Cache that maps VLA types to size expressions for that type,
86  /// represented by instantiated Metadata nodes.
87  llvm::SmallDenseMap<QualType, llvm::Metadata *> SizeExprCache;
88 
89  struct ObjCInterfaceCacheEntry {
90  const ObjCInterfaceType *Type;
91  llvm::DIType *Decl;
92  llvm::DIFile *Unit;
93  ObjCInterfaceCacheEntry(const ObjCInterfaceType *Type, llvm::DIType *Decl,
94  llvm::DIFile *Unit)
95  : Type(Type), Decl(Decl), Unit(Unit) {}
96  };
97 
98  /// Cache of previously constructed interfaces which may change.
100 
101  /// Cache of forward declarations for methods belonging to the interface.
102  llvm::DenseMap<const ObjCInterfaceDecl *, std::vector<llvm::DISubprogram *>>
103  ObjCMethodCache;
104 
105  /// Cache of references to clang modules and precompiled headers.
106  llvm::DenseMap<const Module *, llvm::TrackingMDRef> ModuleCache;
107 
108  /// List of interfaces we want to keep even if orphaned.
109  std::vector<void *> RetainedTypes;
110 
111  /// Cache of forward declared types to RAUW at the end of compilation.
112  std::vector<std::pair<const TagType *, llvm::TrackingMDRef>> ReplaceMap;
113 
114  /// Cache of replaceable forward declarations (functions and
115  /// variables) to RAUW at the end of compilation.
116  std::vector<std::pair<const DeclaratorDecl *, llvm::TrackingMDRef>>
117  FwdDeclReplaceMap;
118 
119  /// Keep track of our current nested lexical block.
120  std::vector<llvm::TypedTrackingMDRef<llvm::DIScope>> LexicalBlockStack;
121  llvm::DenseMap<const Decl *, llvm::TrackingMDRef> RegionMap;
122  /// Keep track of LexicalBlockStack counter at the beginning of a
123  /// function. This is used to pop unbalanced regions at the end of a
124  /// function.
125  std::vector<unsigned> FnBeginRegionCount;
126 
127  /// This is a storage for names that are constructed on demand. For
128  /// example, C++ destructors, C++ operators etc..
129  llvm::BumpPtrAllocator DebugInfoNames;
130  StringRef CWDName;
131 
132  llvm::DenseMap<const char *, llvm::TrackingMDRef> DIFileCache;
133  llvm::DenseMap<const FunctionDecl *, llvm::TrackingMDRef> SPCache;
134  /// Cache declarations relevant to DW_TAG_imported_declarations (C++
135  /// using declarations) that aren't covered by other more specific caches.
136  llvm::DenseMap<const Decl *, llvm::TrackingMDRef> DeclCache;
137  llvm::DenseMap<const NamespaceDecl *, llvm::TrackingMDRef> NamespaceCache;
138  llvm::DenseMap<const NamespaceAliasDecl *, llvm::TrackingMDRef>
139  NamespaceAliasCache;
140  llvm::DenseMap<const Decl *, llvm::TypedTrackingMDRef<llvm::DIDerivedType>>
141  StaticDataMemberCache;
142 
143  /// Helper functions for getOrCreateType.
144  /// @{
145  /// Currently the checksum of an interface includes the number of
146  /// ivars and property accessors.
147  llvm::DIType *CreateType(const BuiltinType *Ty);
148  llvm::DIType *CreateType(const ComplexType *Ty);
149  llvm::DIType *CreateQualifiedType(QualType Ty, llvm::DIFile *Fg);
150  llvm::DIType *CreateType(const TypedefType *Ty, llvm::DIFile *Fg);
151  llvm::DIType *CreateType(const TemplateSpecializationType *Ty,
152  llvm::DIFile *Fg);
153  llvm::DIType *CreateType(const ObjCObjectPointerType *Ty, llvm::DIFile *F);
154  llvm::DIType *CreateType(const PointerType *Ty, llvm::DIFile *F);
155  llvm::DIType *CreateType(const BlockPointerType *Ty, llvm::DIFile *F);
156  llvm::DIType *CreateType(const FunctionType *Ty, llvm::DIFile *F);
157  /// Get structure or union type.
158  llvm::DIType *CreateType(const RecordType *Tyg);
159  llvm::DIType *CreateTypeDefinition(const RecordType *Ty);
160  llvm::DICompositeType *CreateLimitedType(const RecordType *Ty);
161  void CollectContainingType(const CXXRecordDecl *RD,
162  llvm::DICompositeType *CT);
163  /// Get Objective-C interface type.
164  llvm::DIType *CreateType(const ObjCInterfaceType *Ty, llvm::DIFile *F);
165  llvm::DIType *CreateTypeDefinition(const ObjCInterfaceType *Ty,
166  llvm::DIFile *F);
167  /// Get Objective-C object type.
168  llvm::DIType *CreateType(const ObjCObjectType *Ty, llvm::DIFile *F);
169  llvm::DIType *CreateType(const ObjCTypeParamType *Ty, llvm::DIFile *Unit);
170 
171  llvm::DIType *CreateType(const VectorType *Ty, llvm::DIFile *F);
172  llvm::DIType *CreateType(const ArrayType *Ty, llvm::DIFile *F);
173  llvm::DIType *CreateType(const LValueReferenceType *Ty, llvm::DIFile *F);
174  llvm::DIType *CreateType(const RValueReferenceType *Ty, llvm::DIFile *Unit);
175  llvm::DIType *CreateType(const MemberPointerType *Ty, llvm::DIFile *F);
176  llvm::DIType *CreateType(const AtomicType *Ty, llvm::DIFile *F);
177  llvm::DIType *CreateType(const PipeType *Ty, llvm::DIFile *F);
178  /// Get enumeration type.
179  llvm::DIType *CreateEnumType(const EnumType *Ty);
180  llvm::DIType *CreateTypeDefinition(const EnumType *Ty);
181  /// Look up the completed type for a self pointer in the TypeCache and
182  /// create a copy of it with the ObjectPointer and Artificial flags
183  /// set. If the type is not cached, a new one is created. This should
184  /// never happen though, since creating a type for the implicit self
185  /// argument implies that we already parsed the interface definition
186  /// and the ivar declarations in the implementation.
187  llvm::DIType *CreateSelfType(const QualType &QualTy, llvm::DIType *Ty);
188  /// @}
189 
190  /// Get the type from the cache or return null type if it doesn't
191  /// exist.
192  llvm::DIType *getTypeOrNull(const QualType);
193  /// Return the debug type for a C++ method.
194  /// \arg CXXMethodDecl is of FunctionType. This function type is
195  /// not updated to include implicit \c this pointer. Use this routine
196  /// to get a method type which includes \c this pointer.
197  llvm::DISubroutineType *getOrCreateMethodType(const CXXMethodDecl *Method,
198  llvm::DIFile *F);
199  llvm::DISubroutineType *
200  getOrCreateInstanceMethodType(QualType ThisPtr, const FunctionProtoType *Func,
201  llvm::DIFile *Unit);
202  llvm::DISubroutineType *
203  getOrCreateFunctionType(const Decl *D, QualType FnType, llvm::DIFile *F);
204  /// \return debug info descriptor for vtable.
205  llvm::DIType *getOrCreateVTablePtrType(llvm::DIFile *F);
206 
207  /// \return namespace descriptor for the given namespace decl.
208  llvm::DINamespace *getOrCreateNamespace(const NamespaceDecl *N);
209  llvm::DIType *CreatePointerLikeType(llvm::dwarf::Tag Tag, const Type *Ty,
210  QualType PointeeTy, llvm::DIFile *F);
211  llvm::DIType *getOrCreateStructPtrType(StringRef Name, llvm::DIType *&Cache);
212 
213  /// A helper function to create a subprogram for a single member
214  /// function GlobalDecl.
215  llvm::DISubprogram *CreateCXXMemberFunction(const CXXMethodDecl *Method,
216  llvm::DIFile *F,
217  llvm::DIType *RecordTy);
218 
219  /// A helper function to collect debug info for C++ member
220  /// functions. This is used while creating debug info entry for a
221  /// Record.
222  void CollectCXXMemberFunctions(const CXXRecordDecl *Decl, llvm::DIFile *F,
223  SmallVectorImpl<llvm::Metadata *> &E,
224  llvm::DIType *T);
225 
226  /// A helper function to collect debug info for C++ base
227  /// classes. This is used while creating debug info entry for a
228  /// Record.
229  void CollectCXXBases(const CXXRecordDecl *Decl, llvm::DIFile *F,
230  SmallVectorImpl<llvm::Metadata *> &EltTys,
231  llvm::DIType *RecordTy);
232 
233  /// Helper function for CollectCXXBases.
234  /// Adds debug info entries for types in Bases that are not in SeenTypes.
235  void CollectCXXBasesAux(
236  const CXXRecordDecl *RD, llvm::DIFile *Unit,
237  SmallVectorImpl<llvm::Metadata *> &EltTys, llvm::DIType *RecordTy,
238  const CXXRecordDecl::base_class_const_range &Bases,
239  llvm::DenseSet<CanonicalDeclPtr<const CXXRecordDecl>> &SeenTypes,
240  llvm::DINode::DIFlags StartingFlags);
241 
242  /// A helper function to collect template parameters.
243  llvm::DINodeArray CollectTemplateParams(const TemplateParameterList *TPList,
244  ArrayRef<TemplateArgument> TAList,
245  llvm::DIFile *Unit);
246  /// A helper function to collect debug info for function template
247  /// parameters.
248  llvm::DINodeArray CollectFunctionTemplateParams(const FunctionDecl *FD,
249  llvm::DIFile *Unit);
250 
251  /// A helper function to collect debug info for template
252  /// parameters.
253  llvm::DINodeArray
254  CollectCXXTemplateParams(const ClassTemplateSpecializationDecl *TS,
255  llvm::DIFile *F);
256 
257  llvm::DIType *createFieldType(StringRef name, QualType type,
258  SourceLocation loc, AccessSpecifier AS,
259  uint64_t offsetInBits, uint32_t AlignInBits,
260  llvm::DIFile *tunit, llvm::DIScope *scope,
261  const RecordDecl *RD = nullptr);
262 
263  llvm::DIType *createFieldType(StringRef name, QualType type,
264  SourceLocation loc, AccessSpecifier AS,
265  uint64_t offsetInBits, llvm::DIFile *tunit,
266  llvm::DIScope *scope,
267  const RecordDecl *RD = nullptr) {
268  return createFieldType(name, type, loc, AS, offsetInBits, 0, tunit, scope,
269  RD);
270  }
271 
272  /// Create new bit field member.
273  llvm::DIType *createBitFieldType(const FieldDecl *BitFieldDecl,
274  llvm::DIScope *RecordTy,
275  const RecordDecl *RD);
276 
277  /// Helpers for collecting fields of a record.
278  /// @{
279  void CollectRecordLambdaFields(const CXXRecordDecl *CXXDecl,
280  SmallVectorImpl<llvm::Metadata *> &E,
281  llvm::DIType *RecordTy);
282  llvm::DIDerivedType *CreateRecordStaticField(const VarDecl *Var,
283  llvm::DIType *RecordTy,
284  const RecordDecl *RD);
285  void CollectRecordNormalField(const FieldDecl *Field, uint64_t OffsetInBits,
286  llvm::DIFile *F,
287  SmallVectorImpl<llvm::Metadata *> &E,
288  llvm::DIType *RecordTy, const RecordDecl *RD);
289  void CollectRecordNestedType(const TypeDecl *RD,
290  SmallVectorImpl<llvm::Metadata *> &E);
291  void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile *F,
292  SmallVectorImpl<llvm::Metadata *> &E,
293  llvm::DICompositeType *RecordTy);
294 
295  /// If the C++ class has vtable info then insert appropriate debug
296  /// info entry in EltTys vector.
297  void CollectVTableInfo(const CXXRecordDecl *Decl, llvm::DIFile *F,
298  SmallVectorImpl<llvm::Metadata *> &EltTys,
299  llvm::DICompositeType *RecordTy);
300  /// @}
301 
302  /// Create a new lexical block node and push it on the stack.
303  void CreateLexicalBlock(SourceLocation Loc);
304 
305  /// If target-specific LLVM \p AddressSpace directly maps to target-specific
306  /// DWARF address space, appends extended dereferencing mechanism to complex
307  /// expression \p Expr. Otherwise, does nothing.
308  ///
309  /// Extended dereferencing mechanism is has the following format:
310  /// DW_OP_constu <DWARF Address Space> DW_OP_swap DW_OP_xderef
311  void AppendAddressSpaceXDeref(unsigned AddressSpace,
312  SmallVectorImpl<int64_t> &Expr) const;
313 
314 public:
315  CGDebugInfo(CodeGenModule &CGM);
316  ~CGDebugInfo();
317 
318  void finalize();
319 
320  /// Register VLA size expression debug node with the qualified type.
321  void registerVLASizeExpression(QualType Ty, llvm::Metadata *SizeExpr) {
322  SizeExprCache[Ty] = SizeExpr;
323  }
324 
325  /// Module debugging: Support for building PCMs.
326  /// @{
327  /// Set the main CU's DwoId field to \p Signature.
328  void setDwoId(uint64_t Signature);
329 
330  /// When generating debug information for a clang module or
331  /// precompiled header, this module map will be used to determine
332  /// the module of origin of each Decl.
333  void setModuleMap(ModuleMap &MMap) { ClangModuleMap = &MMap; }
334 
335  /// When generating debug information for a clang module or
336  /// precompiled header, this module map will be used to determine
337  /// the module of origin of each Decl.
339  PCHDescriptor = PCH;
340  }
341  /// @}
342 
343  /// Update the current source location. If \arg loc is invalid it is
344  /// ignored.
345  void setLocation(SourceLocation Loc);
346 
347  /// Return the current source location. This does not necessarily correspond
348  /// to the IRBuilder's current DebugLoc.
349  SourceLocation getLocation() const { return CurLoc; }
350 
351  /// Update the current inline scope. All subsequent calls to \p EmitLocation
352  /// will create a location with this inlinedAt field.
353  void setInlinedAt(llvm::MDNode *InlinedAt) { CurInlinedAt = InlinedAt; }
354 
355  /// \return the current inline scope.
356  llvm::MDNode *getInlinedAt() const { return CurInlinedAt; }
357 
358  // Converts a SourceLocation to a DebugLoc
359  llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Loc);
360 
361  /// Emit metadata to indicate a change in line/column information in
362  /// the source file. If the location is invalid, the previous
363  /// location will be reused.
364  void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc);
365 
366  /// Emit a call to llvm.dbg.function.start to indicate
367  /// start of a new function.
368  /// \param Loc The location of the function header.
369  /// \param ScopeLoc The location of the function body.
370  void EmitFunctionStart(GlobalDecl GD, SourceLocation Loc,
371  SourceLocation ScopeLoc, QualType FnType,
372  llvm::Function *Fn, bool CurFnIsThunk,
373  CGBuilderTy &Builder);
374 
375  /// Start a new scope for an inlined function.
376  void EmitInlineFunctionStart(CGBuilderTy &Builder, GlobalDecl GD);
377  /// End an inlined function scope.
378  void EmitInlineFunctionEnd(CGBuilderTy &Builder);
379 
380  /// Emit debug info for a function declaration.
381  void EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc, QualType FnType);
382 
383  /// Constructs the debug code for exiting a function.
384  void EmitFunctionEnd(CGBuilderTy &Builder, llvm::Function *Fn);
385 
386  /// Emit metadata to indicate the beginning of a new lexical block
387  /// and push the block onto the stack.
388  void EmitLexicalBlockStart(CGBuilderTy &Builder, SourceLocation Loc);
389 
390  /// Emit metadata to indicate the end of a new lexical block and pop
391  /// the current block.
392  void EmitLexicalBlockEnd(CGBuilderTy &Builder, SourceLocation Loc);
393 
394  /// Emit call to \c llvm.dbg.declare for an automatic variable
395  /// declaration.
396  /// Returns a pointer to the DILocalVariable associated with the
397  /// llvm.dbg.declare, or nullptr otherwise.
398  llvm::DILocalVariable *EmitDeclareOfAutoVariable(const VarDecl *Decl,
399  llvm::Value *AI,
400  CGBuilderTy &Builder);
401 
402  /// Emit call to \c llvm.dbg.declare for an imported variable
403  /// declaration in a block.
404  void EmitDeclareOfBlockDeclRefVariable(
405  const VarDecl *variable, llvm::Value *storage, CGBuilderTy &Builder,
406  const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint = nullptr);
407 
408  /// Emit call to \c llvm.dbg.declare for an argument variable
409  /// declaration.
410  void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI,
411  unsigned ArgNo, CGBuilderTy &Builder);
412 
413  /// Emit call to \c llvm.dbg.declare for the block-literal argument
414  /// to a block invocation function.
415  void EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
416  StringRef Name, unsigned ArgNo,
417  llvm::AllocaInst *LocalAddr,
418  CGBuilderTy &Builder);
419 
420  /// Emit information about a global variable.
421  void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
422 
423  /// Emit a constant global variable's debug info.
424  void EmitGlobalVariable(const ValueDecl *VD, const APValue &Init);
425 
426  /// Emit C++ using directive.
427  void EmitUsingDirective(const UsingDirectiveDecl &UD);
428 
429  /// Emit the type explicitly casted to.
430  void EmitExplicitCastType(QualType Ty);
431 
432  /// Emit C++ using declaration.
433  void EmitUsingDecl(const UsingDecl &UD);
434 
435  /// Emit an @import declaration.
436  void EmitImportDecl(const ImportDecl &ID);
437 
438  /// Emit C++ namespace alias.
439  llvm::DIImportedEntity *EmitNamespaceAlias(const NamespaceAliasDecl &NA);
440 
441  /// Emit record type's standalone debug info.
442  llvm::DIType *getOrCreateRecordType(QualType Ty, SourceLocation L);
443 
444  /// Emit an Objective-C interface type standalone debug info.
445  llvm::DIType *getOrCreateInterfaceType(QualType Ty, SourceLocation Loc);
446 
447  /// Emit standalone debug info for a type.
448  llvm::DIType *getOrCreateStandaloneType(QualType Ty, SourceLocation Loc);
449 
450  void completeType(const EnumDecl *ED);
451  void completeType(const RecordDecl *RD);
452  void completeRequiredType(const RecordDecl *RD);
453  void completeClassData(const RecordDecl *RD);
454  void completeClass(const RecordDecl *RD);
455 
456  void completeTemplateDefinition(const ClassTemplateSpecializationDecl &SD);
457  void completeUnusedClass(const CXXRecordDecl &D);
458 
459  /// Create debug info for a macro defined by a #define directive or a macro
460  /// undefined by a #undef directive.
461  llvm::DIMacro *CreateMacro(llvm::DIMacroFile *Parent, unsigned MType,
462  SourceLocation LineLoc, StringRef Name,
463  StringRef Value);
464 
465  /// Create debug info for a file referenced by an #include directive.
466  llvm::DIMacroFile *CreateTempMacroFile(llvm::DIMacroFile *Parent,
467  SourceLocation LineLoc,
468  SourceLocation FileLoc);
469 
470 private:
471  /// Emit call to llvm.dbg.declare for a variable declaration.
472  /// Returns a pointer to the DILocalVariable associated with the
473  /// llvm.dbg.declare, or nullptr otherwise.
474  llvm::DILocalVariable *EmitDeclare(const VarDecl *decl, llvm::Value *AI,
476  CGBuilderTy &Builder);
477 
478  /// Build up structure info for the byref. See \a BuildByRefType.
479  llvm::DIType *EmitTypeForVarWithBlocksAttr(const VarDecl *VD,
480  uint64_t *OffSet);
481 
482  /// Get context info for the DeclContext of \p Decl.
483  llvm::DIScope *getDeclContextDescriptor(const Decl *D);
484  /// Get context info for a given DeclContext \p Decl.
485  llvm::DIScope *getContextDescriptor(const Decl *Context,
486  llvm::DIScope *Default);
487 
488  llvm::DIScope *getCurrentContextDescriptor(const Decl *Decl);
489 
490  /// Create a forward decl for a RecordType in a given context.
491  llvm::DICompositeType *getOrCreateRecordFwdDecl(const RecordType *,
492  llvm::DIScope *);
493 
494  /// Return current directory name.
495  StringRef getCurrentDirname();
496 
497  /// Create new compile unit.
498  void CreateCompileUnit();
499 
500  /// Remap a given path with the current debug prefix map
501  std::string remapDIPath(StringRef) const;
502 
503  /// Compute the file checksum debug info for input file ID.
505  computeChecksum(FileID FID, SmallString<32> &Checksum) const;
506 
507  /// Get the source of the given file ID.
508  Optional<StringRef> getSource(const SourceManager &SM, FileID FID);
509 
510  /// Get the file debug info descriptor for the input location.
511  llvm::DIFile *getOrCreateFile(SourceLocation Loc);
512 
513  /// Get the file info for main compile unit.
514  llvm::DIFile *getOrCreateMainFile();
515 
516  /// Get the type from the cache or create a new type if necessary.
517  llvm::DIType *getOrCreateType(QualType Ty, llvm::DIFile *Fg);
518 
519  /// Get a reference to a clang module. If \p CreateSkeletonCU is true,
520  /// this also creates a split dwarf skeleton compile unit.
521  llvm::DIModule *
522  getOrCreateModuleRef(ExternalASTSource::ASTSourceDescriptor Mod,
523  bool CreateSkeletonCU);
524 
525  /// DebugTypeExtRefs: If \p D originated in a clang module, return it.
526  llvm::DIModule *getParentModuleOrNull(const Decl *D);
527 
528  /// Get the type from the cache or create a new partial type if
529  /// necessary.
530  llvm::DICompositeType *getOrCreateLimitedType(const RecordType *Ty,
531  llvm::DIFile *F);
532 
533  /// Create type metadata for a source language type.
534  llvm::DIType *CreateTypeNode(QualType Ty, llvm::DIFile *Fg);
535 
536  /// Create new member and increase Offset by FType's size.
537  llvm::DIType *CreateMemberType(llvm::DIFile *Unit, QualType FType,
538  StringRef Name, uint64_t *Offset);
539 
540  /// Retrieve the DIDescriptor, if any, for the canonical form of this
541  /// declaration.
542  llvm::DINode *getDeclarationOrDefinition(const Decl *D);
543 
544  /// \return debug info descriptor to describe method
545  /// declaration for the given method definition.
546  llvm::DISubprogram *getFunctionDeclaration(const Decl *D);
547 
548  /// \return debug info descriptor to describe in-class static data
549  /// member declaration for the given out-of-class definition. If D
550  /// is an out-of-class definition of a static data member of a
551  /// class, find its corresponding in-class declaration.
552  llvm::DIDerivedType *
553  getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D);
554 
555  /// Helper that either creates a forward declaration or a stub.
556  llvm::DISubprogram *getFunctionFwdDeclOrStub(GlobalDecl GD, bool Stub);
557 
558  /// Create a subprogram describing the forward declaration
559  /// represented in the given FunctionDecl wrapped in a GlobalDecl.
560  llvm::DISubprogram *getFunctionForwardDeclaration(GlobalDecl GD);
561 
562  /// Create a DISubprogram describing the function
563  /// represented in the given FunctionDecl wrapped in a GlobalDecl.
564  llvm::DISubprogram *getFunctionStub(GlobalDecl GD);
565 
566  /// Create a global variable describing the forward declaration
567  /// represented in the given VarDecl.
568  llvm::DIGlobalVariable *
569  getGlobalVariableForwardDeclaration(const VarDecl *VD);
570 
571  /// Return a global variable that represents one of the collection of global
572  /// variables created for an anonmyous union.
573  ///
574  /// Recursively collect all of the member fields of a global
575  /// anonymous decl and create static variables for them. The first
576  /// time this is called it needs to be on a union and then from
577  /// there we can have additional unnamed fields.
578  llvm::DIGlobalVariableExpression *
579  CollectAnonRecordDecls(const RecordDecl *RD, llvm::DIFile *Unit,
580  unsigned LineNo, StringRef LinkageName,
581  llvm::GlobalVariable *Var, llvm::DIScope *DContext);
582 
583  /// Get the printing policy for producing names for debug info.
584  PrintingPolicy getPrintingPolicy() const;
585 
586  /// Get function name for the given FunctionDecl. If the name is
587  /// constructed on demand (e.g., C++ destructor) then the name is
588  /// stored on the side.
589  StringRef getFunctionName(const FunctionDecl *FD);
590 
591  /// Returns the unmangled name of an Objective-C method.
592  /// This is the display name for the debugging info.
593  StringRef getObjCMethodName(const ObjCMethodDecl *FD);
594 
595  /// Return selector name. This is used for debugging
596  /// info.
597  StringRef getSelectorName(Selector S);
598 
599  /// Get class name including template argument list.
600  StringRef getClassName(const RecordDecl *RD);
601 
602  /// Get the vtable name for the given class.
603  StringRef getVTableName(const CXXRecordDecl *Decl);
604 
605  /// Get line number for the location. If location is invalid
606  /// then use current location.
607  unsigned getLineNumber(SourceLocation Loc);
608 
609  /// Get column number for the location. If location is
610  /// invalid then use current location.
611  /// \param Force Assume DebugColumnInfo option is true.
612  unsigned getColumnNumber(SourceLocation Loc, bool Force = false);
613 
614  /// Collect various properties of a FunctionDecl.
615  /// \param GD A GlobalDecl whose getDecl() must return a FunctionDecl.
616  void collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit,
617  StringRef &Name, StringRef &LinkageName,
618  llvm::DIScope *&FDContext,
619  llvm::DINodeArray &TParamsArray,
620  llvm::DINode::DIFlags &Flags);
621 
622  /// Collect various properties of a VarDecl.
623  void collectVarDeclProps(const VarDecl *VD, llvm::DIFile *&Unit,
624  unsigned &LineNo, QualType &T, StringRef &Name,
625  StringRef &LinkageName, llvm::DIScope *&VDContext);
626 
627  /// Allocate a copy of \p A using the DebugInfoNames allocator
628  /// and return a reference to it. If multiple arguments are given the strings
629  /// are concatenated.
630  StringRef internString(StringRef A, StringRef B = StringRef()) {
631  char *Data = DebugInfoNames.Allocate<char>(A.size() + B.size());
632  if (!A.empty())
633  std::memcpy(Data, A.data(), A.size());
634  if (!B.empty())
635  std::memcpy(Data + A.size(), B.data(), B.size());
636  return StringRef(Data, A.size() + B.size());
637  }
638 };
639 
640 /// A scoped helper to set the current debug location to the specified
641 /// location or preferred location of the specified Expr.
643 private:
644  void init(SourceLocation TemporaryLocation, bool DefaultToEmpty = false);
645  ApplyDebugLocation(CodeGenFunction &CGF, bool DefaultToEmpty,
646  SourceLocation TemporaryLocation);
647 
648  llvm::DebugLoc OriginalLocation;
649  CodeGenFunction *CGF;
650 
651 public:
652  /// Set the location to the (valid) TemporaryLocation.
653  ApplyDebugLocation(CodeGenFunction &CGF, SourceLocation TemporaryLocation);
654  ApplyDebugLocation(CodeGenFunction &CGF, const Expr *E);
655  ApplyDebugLocation(CodeGenFunction &CGF, llvm::DebugLoc Loc);
656  ApplyDebugLocation(ApplyDebugLocation &&Other) : CGF(Other.CGF) {
657  Other.CGF = nullptr;
658  }
659 
661 
662  /// Apply TemporaryLocation if it is valid. Otherwise switch
663  /// to an artificial debug location that has a valid scope, but no
664  /// line information.
665  ///
666  /// Artificial locations are useful when emitting compiler-generated
667  /// helper functions that have no source location associated with
668  /// them. The DWARF specification allows the compiler to use the
669  /// special line number 0 to indicate code that can not be
670  /// attributed to any source location. Note that passing an empty
671  /// SourceLocation to CGDebugInfo::setLocation() will result in the
672  /// last valid location being reused.
674  return ApplyDebugLocation(CGF, false, SourceLocation());
675  }
676  /// Apply TemporaryLocation if it is valid. Otherwise switch
677  /// to an artificial debug location that has a valid scope, but no
678  /// line information.
679  static ApplyDebugLocation
681  SourceLocation TemporaryLocation) {
682  return ApplyDebugLocation(CGF, false, TemporaryLocation);
683  }
684 
685  /// Set the IRBuilder to not attach debug locations. Note that
686  /// passing an empty SourceLocation to \a CGDebugInfo::setLocation()
687  /// will result in the last valid location being reused. Note that
688  /// all instructions that do not have a location at the beginning of
689  /// a function are counted towards to function prologue.
691  return ApplyDebugLocation(CGF, true, SourceLocation());
692  }
693 };
694 
695 /// A scoped helper to set the current debug location to an inlined location.
697  SourceLocation SavedLocation;
698  CodeGenFunction *CGF;
699 
700 public:
701  /// Set up the CodeGenFunction's DebugInfo to produce inline locations for the
702  /// function \p InlinedFn. The current debug location becomes the inlined call
703  /// site of the inlined function.
705  /// Restore everything back to the orginial state.
707 };
708 
709 } // namespace CodeGen
710 } // namespace clang
711 
712 #endif // LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
Represents a function declaration or definition.
Definition: Decl.h:1716
llvm::MDNode * getInlinedAt() const
Definition: CGDebugInfo.h:356
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)
Definition: PlistSupport.h:97
A (possibly-)qualified type.
Definition: Type.h:655
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:30
C Language Family Type Representation.
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:98
void finalize(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema)
void setPCHDescriptor(ExternalASTSource::ASTSourceDescriptor PCH)
When generating debug information for a clang module or precompiled header, this module map will be u...
Definition: CGDebugInfo.h:338
Represents a variable declaration or definition.
Definition: Decl.h:814
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
Definition: CGDebugInfo.h:54
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:139
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:38
void setInlinedAt(llvm::MDNode *InlinedAt)
Update the current inline scope.
Definition: CGDebugInfo.h:353
Represents a struct/union/class.
Definition: Decl.h:3570
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.
Definition: CGDebugInfo.h:673
Represents a C++ using-declaration.
Definition: DeclCXX.h:3360
uint32_t Offset
Definition: CacheTokens.cpp:43
void registerVLASizeExpression(QualType Ty, llvm::Metadata *SizeExpr)
Register VLA size expression debug node with the qualified type.
Definition: CGDebugInfo.h:321
NodeId Parent
Definition: ASTDiff.cpp:192
CGBlockInfo - Information to generate a block literal.
Definition: CGBlocks.h:150
Allows QualTypes to be sorted and hence used in maps and sets.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:637
Expr - This represents one expression.
Definition: Expr.h:106
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
A scoped helper to set the current debug location to an inlined location.
Definition: CGDebugInfo.h:696
const SourceManager & SM
Definition: Format.cpp:1475
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:35
Encodes a location in the source.
A scoped helper to set the current debug location to the specified location or preferred location of ...
Definition: CGDebugInfo.h:642
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:4142
SourceLocation getLocation() const
Return the current source location.
Definition: CGDebugInfo.h:349
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.
Definition: CGDebugInfo.h:680
Represents an enum.
Definition: Decl.h:3313
void setModuleMap(ModuleMap &MMap)
When generating debug information for a clang module or precompiled header, this module map will be u...
Definition: CGDebugInfo.h:333
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4135
ApplyDebugLocation(ApplyDebugLocation &&Other)
Definition: CGDebugInfo.h:656
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
Definition: APValue.h:38
The type-property cache.
Definition: Type.cpp:3464
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.
Definition: DeclCXX.h:302
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.
Definition: CGDebugInfo.h:690
Represents a C++ namespace alias.
Definition: DeclCXX.h:3028
Represents C++ using-directive.
Definition: DeclCXX.h:2924
This class handles loading and caching of source files into memory.