CGDebugInfo.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  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. #ifndef LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
  14. #define LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
  15. #include "CGBuilder.h"
  16. #include "clang/AST/Expr.h"
  17. #include "clang/AST/Type.h"
  18. #include "clang/Basic/SourceLocation.h"
  19. #include "clang/Frontend/CodeGenOptions.h"
  20. #include "llvm/ADT/DenseMap.h"
  21. #include "llvm/IR/DIBuilder.h"
  22. #include "llvm/IR/DebugInfo.h"
  23. #include "llvm/IR/ValueHandle.h"
  24. #include "llvm/Support/Allocator.h"
  25. namespace llvm {
  26. class MDNode;
  27. }
  28. namespace clang {
  29. class CXXMethodDecl;
  30. class VarDecl;
  31. class ObjCInterfaceDecl;
  32. class ObjCIvarDecl;
  33. class ClassTemplateSpecializationDecl;
  34. class GlobalDecl;
  35. class UsingDecl;
  36. namespace CodeGen {
  37. class CodeGenModule;
  38. class CodeGenFunction;
  39. class CGBlockInfo;
  40. /// This class gathers all debug information during compilation and is
  41. /// responsible for emitting to llvm globals or pass directly to the
  42. /// backend.
  43. class CGDebugInfo {
  44. friend class ApplyDebugLocation;
  45. friend class SaveAndRestoreLocation;
  46. CodeGenModule &CGM;
  47. const CodeGenOptions::DebugInfoKind DebugKind;
  48. llvm::DIBuilder DBuilder;
  49. llvm::DICompileUnit *TheCU = nullptr;
  50. SourceLocation CurLoc;
  51. llvm::DIType *VTablePtrType = nullptr;
  52. llvm::DIType *ClassTy = nullptr;
  53. llvm::DICompositeType *ObjTy = nullptr;
  54. llvm::DIType *SelTy = nullptr;
  55. llvm::DIType *OCLImage1dDITy = nullptr;
  56. llvm::DIType *OCLImage1dArrayDITy = nullptr;
  57. llvm::DIType *OCLImage1dBufferDITy = nullptr;
  58. llvm::DIType *OCLImage2dDITy = nullptr;
  59. llvm::DIType *OCLImage2dArrayDITy = nullptr;
  60. llvm::DIType *OCLImage3dDITy = nullptr;
  61. llvm::DIType *OCLEventDITy = nullptr;
  62. /// Cache of previously constructed Types.
  63. llvm::DenseMap<const void *, llvm::TrackingMDRef> TypeCache;
  64. struct ObjCInterfaceCacheEntry {
  65. const ObjCInterfaceType *Type;
  66. llvm::DIType *Decl;
  67. llvm::DIFile *Unit;
  68. ObjCInterfaceCacheEntry(const ObjCInterfaceType *Type, llvm::DIType *Decl,
  69. llvm::DIFile *Unit)
  70. : Type(Type), Decl(Decl), Unit(Unit) {}
  71. };
  72. /// Cache of previously constructed interfaces which may change.
  73. llvm::SmallVector<ObjCInterfaceCacheEntry, 32> ObjCInterfaceCache;
  74. /// Cache of references to AST files such as PCHs or modules.
  75. llvm::DenseMap<uint64_t, llvm::DIModule *> ModuleRefCache;
  76. /// List of interfaces we want to keep even if orphaned.
  77. std::vector<void *> RetainedTypes;
  78. /// Cache of forward declared types to RAUW at the end of
  79. /// compilation.
  80. std::vector<std::pair<const TagType *, llvm::TrackingMDRef>> ReplaceMap;
  81. /// Cache of replaceable forward declarartions (functions and
  82. /// variables) to RAUW at the end of compilation.
  83. std::vector<std::pair<const DeclaratorDecl *, llvm::TrackingMDRef>>
  84. FwdDeclReplaceMap;
  85. /// Keep track of our current nested lexical block.
  86. std::vector<llvm::TypedTrackingMDRef<llvm::DIScope>> LexicalBlockStack;
  87. llvm::DenseMap<const Decl *, llvm::TrackingMDRef> RegionMap;
  88. /// Keep track of LexicalBlockStack counter at the beginning of a
  89. /// function. This is used to pop unbalanced regions at the end of a
  90. /// function.
  91. std::vector<unsigned> FnBeginRegionCount;
  92. /// This is a storage for names that are constructed on demand. For
  93. /// example, C++ destructors, C++ operators etc..
  94. llvm::BumpPtrAllocator DebugInfoNames;
  95. StringRef CWDName;
  96. llvm::DenseMap<const char *, llvm::TrackingMDRef> DIFileCache;
  97. llvm::DenseMap<const FunctionDecl *, llvm::TrackingMDRef> SPCache;
  98. /// Cache declarations relevant to DW_TAG_imported_declarations (C++
  99. /// using declarations) that aren't covered by other more specific caches.
  100. llvm::DenseMap<const Decl *, llvm::TrackingMDRef> DeclCache;
  101. llvm::DenseMap<const NamespaceDecl *, llvm::TrackingMDRef> NameSpaceCache;
  102. llvm::DenseMap<const NamespaceAliasDecl *, llvm::TrackingMDRef>
  103. NamespaceAliasCache;
  104. llvm::DenseMap<const Decl *, llvm::TrackingMDRef> StaticDataMemberCache;
  105. /// Helper functions for getOrCreateType.
  106. /// @{
  107. /// Currently the checksum of an interface includes the number of
  108. /// ivars and property accessors.
  109. unsigned Checksum(const ObjCInterfaceDecl *InterfaceDecl);
  110. llvm::DIType *CreateType(const BuiltinType *Ty);
  111. llvm::DIType *CreateType(const ComplexType *Ty);
  112. llvm::DIType *CreateQualifiedType(QualType Ty, llvm::DIFile *Fg);
  113. llvm::DIType *CreateType(const TypedefType *Ty, llvm::DIFile *Fg);
  114. llvm::DIType *CreateType(const TemplateSpecializationType *Ty,
  115. llvm::DIFile *Fg);
  116. llvm::DIType *CreateType(const ObjCObjectPointerType *Ty, llvm::DIFile *F);
  117. llvm::DIType *CreateType(const PointerType *Ty, llvm::DIFile *F);
  118. llvm::DIType *CreateType(const BlockPointerType *Ty, llvm::DIFile *F);
  119. llvm::DIType *CreateType(const FunctionType *Ty, llvm::DIFile *F);
  120. /// Get structure or union type.
  121. llvm::DIType *CreateType(const RecordType *Tyg);
  122. llvm::DIType *CreateTypeDefinition(const RecordType *Ty);
  123. llvm::DICompositeType *CreateLimitedType(const RecordType *Ty);
  124. void CollectContainingType(const CXXRecordDecl *RD,
  125. llvm::DICompositeType *CT);
  126. /// Get Objective-C interface type.
  127. llvm::DIType *CreateType(const ObjCInterfaceType *Ty, llvm::DIFile *F);
  128. llvm::DIType *CreateTypeDefinition(const ObjCInterfaceType *Ty,
  129. llvm::DIFile *F);
  130. /// Get Objective-C object type.
  131. llvm::DIType *CreateType(const ObjCObjectType *Ty, llvm::DIFile *F);
  132. llvm::DIType *CreateType(const VectorType *Ty, llvm::DIFile *F);
  133. llvm::DIType *CreateType(const ArrayType *Ty, llvm::DIFile *F);
  134. llvm::DIType *CreateType(const LValueReferenceType *Ty, llvm::DIFile *F);
  135. llvm::DIType *CreateType(const RValueReferenceType *Ty, llvm::DIFile *Unit);
  136. llvm::DIType *CreateType(const MemberPointerType *Ty, llvm::DIFile *F);
  137. llvm::DIType *CreateType(const AtomicType *Ty, llvm::DIFile *F);
  138. /// Get enumeration type.
  139. llvm::DIType *CreateEnumType(const EnumType *Ty);
  140. llvm::DIType *CreateTypeDefinition(const EnumType *Ty);
  141. /// Look up the completed type for a self pointer in the TypeCache and
  142. /// create a copy of it with the ObjectPointer and Artificial flags
  143. /// set. If the type is not cached, a new one is created. This should
  144. /// never happen though, since creating a type for the implicit self
  145. /// argument implies that we already parsed the interface definition
  146. /// and the ivar declarations in the implementation.
  147. llvm::DIType *CreateSelfType(const QualType &QualTy, llvm::DIType *Ty);
  148. /// @}
  149. /// Get the type from the cache or return null type if it doesn't
  150. /// exist.
  151. llvm::DIType *getTypeOrNull(const QualType);
  152. /// Return the debug type for a C++ method.
  153. /// \arg CXXMethodDecl is of FunctionType. This function type is
  154. /// not updated to include implicit \c this pointer. Use this routine
  155. /// to get a method type which includes \c this pointer.
  156. llvm::DISubroutineType *getOrCreateMethodType(const CXXMethodDecl *Method,
  157. llvm::DIFile *F);
  158. llvm::DISubroutineType *
  159. getOrCreateInstanceMethodType(QualType ThisPtr, const FunctionProtoType *Func,
  160. llvm::DIFile *Unit);
  161. llvm::DISubroutineType *
  162. getOrCreateFunctionType(const Decl *D, QualType FnType, llvm::DIFile *F);
  163. /// \return debug info descriptor for vtable.
  164. llvm::DIType *getOrCreateVTablePtrType(llvm::DIFile *F);
  165. /// \return namespace descriptor for the given namespace decl.
  166. llvm::DINamespace *getOrCreateNameSpace(const NamespaceDecl *N);
  167. llvm::DIType *getOrCreateTypeDeclaration(QualType PointeeTy, llvm::DIFile *F);
  168. llvm::DIType *CreatePointerLikeType(llvm::dwarf::Tag Tag, const Type *Ty,
  169. QualType PointeeTy, llvm::DIFile *F);
  170. llvm::Value *getCachedInterfaceTypeOrNull(const QualType Ty);
  171. llvm::DIType *getOrCreateStructPtrType(StringRef Name, llvm::DIType *&Cache);
  172. /// A helper function to create a subprogram for a single member
  173. /// function GlobalDecl.
  174. llvm::DISubprogram *CreateCXXMemberFunction(const CXXMethodDecl *Method,
  175. llvm::DIFile *F,
  176. llvm::DIType *RecordTy);
  177. /// A helper function to collect debug info for C++ member
  178. /// functions. This is used while creating debug info entry for a
  179. /// Record.
  180. void CollectCXXMemberFunctions(const CXXRecordDecl *Decl, llvm::DIFile *F,
  181. SmallVectorImpl<llvm::Metadata *> &E,
  182. llvm::DIType *T);
  183. /// A helper function to collect debug info for C++ base
  184. /// classes. This is used while creating debug info entry for a
  185. /// Record.
  186. void CollectCXXBases(const CXXRecordDecl *Decl, llvm::DIFile *F,
  187. SmallVectorImpl<llvm::Metadata *> &EltTys,
  188. llvm::DIType *RecordTy);
  189. /// A helper function to collect template parameters.
  190. llvm::DINodeArray CollectTemplateParams(const TemplateParameterList *TPList,
  191. ArrayRef<TemplateArgument> TAList,
  192. llvm::DIFile *Unit);
  193. /// A helper function to collect debug info for function template
  194. /// parameters.
  195. llvm::DINodeArray CollectFunctionTemplateParams(const FunctionDecl *FD,
  196. llvm::DIFile *Unit);
  197. /// A helper function to collect debug info for template
  198. /// parameters.
  199. llvm::DINodeArray
  200. CollectCXXTemplateParams(const ClassTemplateSpecializationDecl *TS,
  201. llvm::DIFile *F);
  202. llvm::DIType *createFieldType(StringRef name, QualType type,
  203. uint64_t sizeInBitsOverride, SourceLocation loc,
  204. AccessSpecifier AS, uint64_t offsetInBits,
  205. llvm::DIFile *tunit, llvm::DIScope *scope,
  206. const RecordDecl *RD = nullptr);
  207. /// Helpers for collecting fields of a record.
  208. /// @{
  209. void CollectRecordLambdaFields(const CXXRecordDecl *CXXDecl,
  210. SmallVectorImpl<llvm::Metadata *> &E,
  211. llvm::DIType *RecordTy);
  212. llvm::DIDerivedType *CreateRecordStaticField(const VarDecl *Var,
  213. llvm::DIType *RecordTy,
  214. const RecordDecl *RD);
  215. void CollectRecordNormalField(const FieldDecl *Field, uint64_t OffsetInBits,
  216. llvm::DIFile *F,
  217. SmallVectorImpl<llvm::Metadata *> &E,
  218. llvm::DIType *RecordTy, const RecordDecl *RD);
  219. void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile *F,
  220. SmallVectorImpl<llvm::Metadata *> &E,
  221. llvm::DICompositeType *RecordTy);
  222. /// If the C++ class has vtable info then insert appropriate debug
  223. /// info entry in EltTys vector.
  224. void CollectVTableInfo(const CXXRecordDecl *Decl, llvm::DIFile *F,
  225. SmallVectorImpl<llvm::Metadata *> &EltTys);
  226. /// @}
  227. /// Create a new lexical block node and push it on the stack.
  228. void CreateLexicalBlock(SourceLocation Loc);
  229. // HLSL Change Begins
  230. private:
  231. bool TryCollectHLSLRecordElements(const RecordType *Ty,
  232. llvm::DICompositeType *DITy,
  233. SmallVectorImpl<llvm::Metadata *> &Elements);
  234. // HLSL Change Ends
  235. public:
  236. CGDebugInfo(CodeGenModule &CGM);
  237. ~CGDebugInfo();
  238. void finalize();
  239. /// Update the current source location. If \arg loc is invalid it is
  240. /// ignored.
  241. void setLocation(SourceLocation Loc);
  242. /// Emit metadata to indicate a change in line/column information in
  243. /// the source file. If the location is invalid, the previous
  244. /// location will be reused.
  245. void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc);
  246. /// Emit a call to llvm.dbg.function.start to indicate
  247. /// start of a new function.
  248. /// \param Loc The location of the function header.
  249. /// \param ScopeLoc The location of the function body.
  250. void EmitFunctionStart(GlobalDecl GD, SourceLocation Loc,
  251. SourceLocation ScopeLoc, QualType FnType,
  252. llvm::Function *Fn, CGBuilderTy &Builder);
  253. /// Constructs the debug code for exiting a function.
  254. void EmitFunctionEnd(CGBuilderTy &Builder);
  255. /// Emit metadata to indicate the beginning of a new lexical block
  256. /// and push the block onto the stack.
  257. void EmitLexicalBlockStart(CGBuilderTy &Builder, SourceLocation Loc);
  258. /// Emit metadata to indicate the end of a new lexical block and pop
  259. /// the current block.
  260. void EmitLexicalBlockEnd(CGBuilderTy &Builder, SourceLocation Loc);
  261. /// Emit call to \c llvm.dbg.declare for an automatic variable
  262. /// declaration.
  263. void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI,
  264. CGBuilderTy &Builder);
  265. /// Emit call to \c llvm.dbg.declare for an imported variable
  266. /// declaration in a block.
  267. void EmitDeclareOfBlockDeclRefVariable(const VarDecl *variable,
  268. llvm::Value *storage,
  269. CGBuilderTy &Builder,
  270. const CGBlockInfo &blockInfo,
  271. llvm::Instruction *InsertPoint = 0);
  272. /// Emit call to \c llvm.dbg.declare for an argument variable
  273. /// declaration.
  274. void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI,
  275. unsigned ArgNo, CGBuilderTy &Builder);
  276. /// Emit call to \c llvm.dbg.declare for the block-literal argument
  277. /// to a block invocation function.
  278. void EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
  279. llvm::Value *Arg, unsigned ArgNo,
  280. llvm::Value *LocalAddr,
  281. CGBuilderTy &Builder);
  282. /// Emit information about a global variable.
  283. void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
  284. /// Emit global variable's debug info.
  285. void EmitGlobalVariable(const ValueDecl *VD, llvm::Constant *Init);
  286. /// Emit C++ using directive.
  287. void EmitUsingDirective(const UsingDirectiveDecl &UD);
  288. /// Emit the type explicitly casted to.
  289. void EmitExplicitCastType(QualType Ty);
  290. /// Emit C++ using declaration.
  291. void EmitUsingDecl(const UsingDecl &UD);
  292. /// Emit an @import declaration.
  293. void EmitImportDecl(const ImportDecl &ID);
  294. /// Emit C++ namespace alias.
  295. llvm::DIImportedEntity *EmitNamespaceAlias(const NamespaceAliasDecl &NA);
  296. /// Emit record type's standalone debug info.
  297. llvm::DIType *getOrCreateRecordType(QualType Ty, SourceLocation L);
  298. /// Emit an Objective-C interface type standalone debug info.
  299. llvm::DIType *getOrCreateInterfaceType(QualType Ty, SourceLocation Loc);
  300. void completeType(const EnumDecl *ED);
  301. void completeType(const RecordDecl *RD);
  302. void completeRequiredType(const RecordDecl *RD);
  303. void completeClassData(const RecordDecl *RD);
  304. void completeTemplateDefinition(const ClassTemplateSpecializationDecl &SD);
  305. private:
  306. /// Emit call to llvm.dbg.declare for a variable declaration.
  307. /// Tag accepts custom types DW_TAG_arg_variable and DW_TAG_auto_variable,
  308. /// otherwise would be of type llvm::dwarf::Tag.
  309. void EmitDeclare(const VarDecl *decl, llvm::dwarf::Tag Tag, llvm::Value *AI,
  310. unsigned ArgNo, CGBuilderTy &Builder);
  311. /// Build up structure info for the byref. See \a BuildByRefType.
  312. llvm::DIType *EmitTypeForVarWithBlocksAttr(const VarDecl *VD,
  313. uint64_t *OffSet);
  314. /// Get context info for the decl.
  315. llvm::DIScope *getContextDescriptor(const Decl *Decl);
  316. llvm::DIScope *getCurrentContextDescriptor(const Decl *Decl);
  317. /// Create a forward decl for a RecordType in a given context.
  318. llvm::DICompositeType *getOrCreateRecordFwdDecl(const RecordType *,
  319. llvm::DIScope *);
  320. /// Return current directory name.
  321. StringRef getCurrentDirname();
  322. /// Create new compile unit.
  323. void CreateCompileUnit();
  324. /// Get the file debug info descriptor for the input location.
  325. llvm::DIFile *getOrCreateFile(SourceLocation Loc);
  326. /// Get the file info for main compile unit.
  327. llvm::DIFile *getOrCreateMainFile();
  328. /// Get the type from the cache or create a new type if necessary.
  329. llvm::DIType *getOrCreateType(QualType Ty, llvm::DIFile *Fg);
  330. /// Get a reference to a clang module.
  331. llvm::DIModule *
  332. getOrCreateModuleRef(ExternalASTSource::ASTSourceDescriptor Mod);
  333. /// Get the type from the cache or create a new partial type if
  334. /// necessary.
  335. llvm::DIType *getOrCreateLimitedType(const RecordType *Ty, llvm::DIFile *F);
  336. /// Create type metadata for a source language type.
  337. llvm::DIType *CreateTypeNode(QualType Ty, llvm::DIFile *Fg);
  338. /// Return the underlying ObjCInterfaceDecl if \arg Ty is an
  339. /// ObjCInterface or a pointer to one.
  340. ObjCInterfaceDecl *getObjCInterfaceDecl(QualType Ty);
  341. /// Create new member and increase Offset by FType's size.
  342. llvm::DIType *CreateMemberType(llvm::DIFile *Unit, QualType FType,
  343. StringRef Name, uint64_t *Offset);
  344. /// Retrieve the DIDescriptor, if any, for the canonical form of this
  345. /// declaration.
  346. llvm::DINode *getDeclarationOrDefinition(const Decl *D);
  347. /// \return debug info descriptor to describe method
  348. /// declaration for the given method definition.
  349. llvm::DISubprogram *getFunctionDeclaration(const Decl *D);
  350. /// \return debug info descriptor to describe in-class static data
  351. /// member declaration for the given out-of-class definition. If D
  352. /// is an out-of-class definition of a static data member of a
  353. /// class, find its corresponding in-class declaration.
  354. llvm::DIDerivedType *
  355. getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D);
  356. /// Create a subprogram describing the forward declaration
  357. /// represented in the given FunctionDecl.
  358. llvm::DISubprogram *getFunctionForwardDeclaration(const FunctionDecl *FD);
  359. /// Create a global variable describing the forward decalration
  360. /// represented in the given VarDecl.
  361. llvm::DIGlobalVariable *
  362. getGlobalVariableForwardDeclaration(const VarDecl *VD);
  363. /// \brief Return a global variable that represents one of the
  364. /// collection of global variables created for an anonmyous union.
  365. ///
  366. /// Recursively collect all of the member fields of a global
  367. /// anonymous decl and create static variables for them. The first
  368. /// time this is called it needs to be on a union and then from
  369. /// there we can have additional unnamed fields.
  370. llvm::DIGlobalVariable *
  371. CollectAnonRecordDecls(const RecordDecl *RD, llvm::DIFile *Unit,
  372. unsigned LineNo, StringRef LinkageName,
  373. llvm::GlobalVariable *Var, llvm::DIScope *DContext);
  374. /// Get function name for the given FunctionDecl. If the name is
  375. /// constructed on demand (e.g., C++ destructor) then the name is
  376. /// stored on the side.
  377. StringRef getFunctionName(const FunctionDecl *FD);
  378. /// Returns the unmangled name of an Objective-C method.
  379. /// This is the display name for the debugging info.
  380. StringRef getObjCMethodName(const ObjCMethodDecl *FD);
  381. /// Return selector name. This is used for debugging
  382. /// info.
  383. StringRef getSelectorName(Selector S);
  384. /// Get class name including template argument list.
  385. StringRef getClassName(const RecordDecl *RD);
  386. /// Get the vtable name for the given class.
  387. StringRef getVTableName(const CXXRecordDecl *Decl);
  388. /// Get line number for the location. If location is invalid
  389. /// then use current location.
  390. unsigned getLineNumber(SourceLocation Loc);
  391. /// Get column number for the location. If location is
  392. /// invalid then use current location.
  393. /// \param Force Assume DebugColumnInfo option is true.
  394. unsigned getColumnNumber(SourceLocation Loc, bool Force = false);
  395. /// Collect various properties of a FunctionDecl.
  396. /// \param GD A GlobalDecl whose getDecl() must return a FunctionDecl.
  397. void collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit,
  398. StringRef &Name, StringRef &LinkageName,
  399. llvm::DIScope *&FDContext,
  400. llvm::DINodeArray &TParamsArray,
  401. unsigned &Flags);
  402. /// Collect various properties of a VarDecl.
  403. void collectVarDeclProps(const VarDecl *VD, llvm::DIFile *&Unit,
  404. unsigned &LineNo, QualType &T, StringRef &Name,
  405. StringRef &LinkageName, llvm::DIScope *&VDContext);
  406. /// Allocate a copy of \p A using the DebugInfoNames allocator
  407. /// and return a reference to it. If multiple arguments are given the strings
  408. /// are concatenated.
  409. StringRef internString(StringRef A, StringRef B = StringRef()) {
  410. char *Data = DebugInfoNames.Allocate<char>(A.size() + B.size());
  411. if (!A.empty())
  412. std::memcpy(Data, A.data(), A.size());
  413. if (!B.empty())
  414. std::memcpy(Data + A.size(), B.data(), B.size());
  415. return StringRef(Data, A.size() + B.size());
  416. }
  417. };
  418. /// A scoped helper to set the current debug location to the specified
  419. /// location or preferred location of the specified Expr.
  420. class ApplyDebugLocation {
  421. private:
  422. void init(SourceLocation TemporaryLocation, bool DefaultToEmpty = false);
  423. ApplyDebugLocation(CodeGenFunction &CGF, bool DefaultToEmpty,
  424. SourceLocation TemporaryLocation);
  425. llvm::DebugLoc OriginalLocation;
  426. CodeGenFunction &CGF;
  427. public:
  428. /// Set the location to the (valid) TemporaryLocation.
  429. ApplyDebugLocation(CodeGenFunction &CGF, SourceLocation TemporaryLocation);
  430. ApplyDebugLocation(CodeGenFunction &CGF, const Expr *E);
  431. ApplyDebugLocation(CodeGenFunction &CGF, llvm::DebugLoc Loc);
  432. ~ApplyDebugLocation();
  433. /// \brief Apply TemporaryLocation if it is valid. Otherwise switch
  434. /// to an artificial debug location that has a valid scope, but no
  435. /// line information.
  436. ///
  437. /// Artificial locations are useful when emitting compiler-generated
  438. /// helper functions that have no source location associated with
  439. /// them. The DWARF specification allows the compiler to use the
  440. /// special line number 0 to indicate code that can not be
  441. /// attributed to any source location. Note that passing an empty
  442. /// SourceLocation to CGDebugInfo::setLocation() will result in the
  443. /// last valid location being reused.
  444. static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF) {
  445. return ApplyDebugLocation(CGF, false, SourceLocation());
  446. }
  447. /// \brief Apply TemporaryLocation if it is valid. Otherwise switch
  448. /// to an artificial debug location that has a valid scope, but no
  449. /// line information.
  450. static ApplyDebugLocation
  451. CreateDefaultArtificial(CodeGenFunction &CGF,
  452. SourceLocation TemporaryLocation) {
  453. return ApplyDebugLocation(CGF, false, TemporaryLocation);
  454. }
  455. /// Set the IRBuilder to not attach debug locations. Note that
  456. /// passing an empty SourceLocation to \a CGDebugInfo::setLocation()
  457. /// will result in the last valid location being reused. Note that
  458. /// all instructions that do not have a location at the beginning of
  459. /// a function are counted towards to funciton prologue.
  460. static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF) {
  461. return ApplyDebugLocation(CGF, true, SourceLocation());
  462. }
  463. /// \brief Apply TemporaryLocation if it is valid. Otherwise set the IRBuilder
  464. /// to not attach debug locations.
  465. static ApplyDebugLocation
  466. CreateDefaultEmpty(CodeGenFunction &CGF, SourceLocation TemporaryLocation) {
  467. return ApplyDebugLocation(CGF, true, TemporaryLocation);
  468. }
  469. };
  470. } // namespace CodeGen
  471. } // namespace clang
  472. #endif