DIBuilder.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. //===- DIBuilder.h - Debug Information Builder ------------------*- 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 file defines a DIBuilder that is useful for creating debugging
  11. // information entries in LLVM IR form.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_IR_DIBUILDER_H
  15. #define LLVM_IR_DIBUILDER_H
  16. #include "llvm/ADT/ArrayRef.h"
  17. #include "llvm/ADT/StringRef.h"
  18. #include "llvm/IR/DebugInfo.h"
  19. #include "llvm/IR/TrackingMDRef.h"
  20. #include "llvm/IR/ValueHandle.h"
  21. #include "llvm/Support/DataTypes.h"
  22. namespace llvm {
  23. class BasicBlock;
  24. class Instruction;
  25. class Function;
  26. class Module;
  27. class Value;
  28. class Constant;
  29. class LLVMContext;
  30. class StringRef;
  31. class DIBuilder {
  32. Module &M;
  33. LLVMContext &VMContext;
  34. DICompileUnit *CUNode; ///< The one compile unit created by this DIBuiler.
  35. Function *DeclareFn; ///< llvm.dbg.declare
  36. Function *ValueFn; ///< llvm.dbg.value
  37. SmallVector<Metadata *, 4> AllEnumTypes;
  38. /// Track the RetainTypes, since they can be updated later on.
  39. SmallVector<TrackingMDNodeRef, 4> AllRetainTypes;
  40. SmallVector<Metadata *, 4> AllSubprograms;
  41. SmallVector<Metadata *, 4> AllGVs;
  42. SmallVector<TrackingMDNodeRef, 4> AllImportedModules;
  43. /// Track nodes that may be unresolved.
  44. SmallVector<TrackingMDNodeRef, 4> UnresolvedNodes;
  45. bool AllowUnresolvedNodes;
  46. /// Each subprogram's preserved local variables.
  47. DenseMap<MDNode *, std::vector<TrackingMDNodeRef>> PreservedVariables;
  48. DIBuilder(const DIBuilder &) = delete;
  49. void operator=(const DIBuilder &) = delete;
  50. /// Create a temporary.
  51. ///
  52. /// Create an \a temporary node and track it in \a UnresolvedNodes.
  53. void trackIfUnresolved(MDNode *N);
  54. public:
  55. /// Construct a builder for a module.
  56. ///
  57. /// If \c AllowUnresolved, collect unresolved nodes attached to the module
  58. /// in order to resolve cycles during \a finalize().
  59. explicit DIBuilder(Module &M, bool AllowUnresolved = true);
  60. enum DebugEmissionKind { FullDebug=1, LineTablesOnly };
  61. /// Construct any deferred debug info descriptors.
  62. void finalize();
  63. /// A CompileUnit provides an anchor for all debugging
  64. /// information generated during this instance of compilation.
  65. /// \param Lang Source programming language, eg. dwarf::DW_LANG_C99
  66. /// \param File File name
  67. /// \param Dir Directory
  68. /// \param Producer Identify the producer of debugging information
  69. /// and code. Usually this is a compiler
  70. /// version string.
  71. /// \param isOptimized A boolean flag which indicates whether optimization
  72. /// is enabled or not.
  73. /// \param Flags This string lists command line options. This
  74. /// string is directly embedded in debug info
  75. /// output which may be used by a tool
  76. /// analyzing generated debugging information.
  77. /// \param RV This indicates runtime version for languages like
  78. /// Objective-C.
  79. /// \param SplitName The name of the file that we'll split debug info
  80. /// out into.
  81. /// \param Kind The kind of debug information to generate.
  82. /// \param DWOId The DWOId if this is a split skeleton compile unit.
  83. /// \param EmitDebugInfo A boolean flag which indicates whether
  84. /// debug information should be written to
  85. /// the final output or not. When this is
  86. /// false, debug information annotations will
  87. /// be present in the IL but they are not
  88. /// written to the final assembly or object
  89. /// file. This supports tracking source
  90. /// location information in the back end
  91. /// without actually changing the output
  92. /// (e.g., when using optimization remarks).
  93. DICompileUnit *
  94. createCompileUnit(unsigned Lang, StringRef File, StringRef Dir,
  95. StringRef Producer, bool isOptimized, StringRef Flags,
  96. unsigned RV, StringRef SplitName = StringRef(),
  97. DebugEmissionKind Kind = FullDebug, uint64_t DWOId = 0,
  98. bool EmitDebugInfo = true);
  99. /// Create a file descriptor to hold debugging information
  100. /// for a file.
  101. DIFile *createFile(StringRef Filename, StringRef Directory);
  102. /// Create a single enumerator value.
  103. DIEnumerator *createEnumerator(StringRef Name, int64_t Val);
  104. /// Create a DWARF unspecified type.
  105. DIBasicType *createUnspecifiedType(StringRef Name);
  106. /// Create C++11 nullptr type.
  107. DIBasicType *createNullPtrType();
  108. /// Create debugging information entry for a basic
  109. /// type.
  110. /// \param Name Type name.
  111. /// \param SizeInBits Size of the type.
  112. /// \param AlignInBits Type alignment.
  113. /// \param Encoding DWARF encoding code, e.g. dwarf::DW_ATE_float.
  114. DIBasicType *createBasicType(StringRef Name, uint64_t SizeInBits,
  115. uint64_t AlignInBits, unsigned Encoding);
  116. /// Create debugging information entry for a qualified
  117. /// type, e.g. 'const int'.
  118. /// \param Tag Tag identifing type, e.g. dwarf::TAG_volatile_type
  119. /// \param FromTy Base Type.
  120. DIDerivedType *createQualifiedType(unsigned Tag, DIType *FromTy);
  121. /// Create debugging information entry for a pointer.
  122. /// \param PointeeTy Type pointed by this pointer.
  123. /// \param SizeInBits Size.
  124. /// \param AlignInBits Alignment. (optional)
  125. /// \param Name Pointer type name. (optional)
  126. DIDerivedType *createPointerType(DIType *PointeeTy, uint64_t SizeInBits,
  127. uint64_t AlignInBits = 0,
  128. StringRef Name = "");
  129. /// Create debugging information entry for a pointer to member.
  130. /// \param PointeeTy Type pointed to by this pointer.
  131. /// \param SizeInBits Size.
  132. /// \param AlignInBits Alignment. (optional)
  133. /// \param Class Type for which this pointer points to members of.
  134. DIDerivedType *createMemberPointerType(DIType *PointeeTy, DIType *Class,
  135. uint64_t SizeInBits,
  136. uint64_t AlignInBits = 0);
  137. /// Create debugging information entry for a c++
  138. /// style reference or rvalue reference type.
  139. DIDerivedType *createReferenceType(unsigned Tag, DIType *RTy);
  140. /// Create debugging information entry for a typedef.
  141. /// \param Ty Original type.
  142. /// \param Name Typedef name.
  143. /// \param File File where this type is defined.
  144. /// \param LineNo Line number.
  145. /// \param Context The surrounding context for the typedef.
  146. DIDerivedType *createTypedef(DIType *Ty, StringRef Name, DIFile *File,
  147. unsigned LineNo, DIScope *Context);
  148. /// Create debugging information entry for a 'friend'.
  149. DIDerivedType *createFriend(DIType *Ty, DIType *FriendTy);
  150. /// Create debugging information entry to establish
  151. /// inheritance relationship between two types.
  152. /// \param Ty Original type.
  153. /// \param BaseTy Base type. Ty is inherits from base.
  154. /// \param BaseOffset Base offset.
  155. /// \param Flags Flags to describe inheritance attribute,
  156. /// e.g. private
  157. DIDerivedType *createInheritance(DIType *Ty, DIType *BaseTy,
  158. uint64_t BaseOffset, unsigned Flags);
  159. /// Create debugging information entry for a member.
  160. /// \param Scope Member scope.
  161. /// \param Name Member name.
  162. /// \param File File where this member is defined.
  163. /// \param LineNo Line number.
  164. /// \param SizeInBits Member size.
  165. /// \param AlignInBits Member alignment.
  166. /// \param OffsetInBits Member offset.
  167. /// \param Flags Flags to encode member attribute, e.g. private
  168. /// \param Ty Parent type.
  169. DIDerivedType *createMemberType(DIScope *Scope, StringRef Name,
  170. DIFile *File, unsigned LineNo,
  171. uint64_t SizeInBits, uint64_t AlignInBits,
  172. uint64_t OffsetInBits, unsigned Flags,
  173. DIType *Ty);
  174. /// Create debugging information entry for a
  175. /// C++ static data member.
  176. /// \param Scope Member scope.
  177. /// \param Name Member name.
  178. /// \param File File where this member is declared.
  179. /// \param LineNo Line number.
  180. /// \param Ty Type of the static member.
  181. /// \param Flags Flags to encode member attribute, e.g. private.
  182. /// \param Val Const initializer of the member.
  183. DIDerivedType *createStaticMemberType(DIScope *Scope, StringRef Name,
  184. DIFile *File, unsigned LineNo,
  185. DIType *Ty, unsigned Flags,
  186. llvm::Constant *Val);
  187. /// Create debugging information entry for Objective-C
  188. /// instance variable.
  189. /// \param Name Member name.
  190. /// \param File File where this member is defined.
  191. /// \param LineNo Line number.
  192. /// \param SizeInBits Member size.
  193. /// \param AlignInBits Member alignment.
  194. /// \param OffsetInBits Member offset.
  195. /// \param Flags Flags to encode member attribute, e.g. private
  196. /// \param Ty Parent type.
  197. /// \param PropertyNode Property associated with this ivar.
  198. DIDerivedType *createObjCIVar(StringRef Name, DIFile *File, unsigned LineNo,
  199. uint64_t SizeInBits, uint64_t AlignInBits,
  200. uint64_t OffsetInBits, unsigned Flags,
  201. DIType *Ty, MDNode *PropertyNode);
  202. /// Create debugging information entry for Objective-C
  203. /// property.
  204. /// \param Name Property name.
  205. /// \param File File where this property is defined.
  206. /// \param LineNumber Line number.
  207. /// \param GetterName Name of the Objective C property getter selector.
  208. /// \param SetterName Name of the Objective C property setter selector.
  209. /// \param PropertyAttributes Objective C property attributes.
  210. /// \param Ty Type.
  211. DIObjCProperty *createObjCProperty(StringRef Name, DIFile *File,
  212. unsigned LineNumber,
  213. StringRef GetterName,
  214. StringRef SetterName,
  215. unsigned PropertyAttributes, DIType *Ty);
  216. /// Create debugging information entry for a class.
  217. /// \param Scope Scope in which this class is defined.
  218. /// \param Name class name.
  219. /// \param File File where this member is defined.
  220. /// \param LineNumber Line number.
  221. /// \param SizeInBits Member size.
  222. /// \param AlignInBits Member alignment.
  223. /// \param OffsetInBits Member offset.
  224. /// \param Flags Flags to encode member attribute, e.g. private
  225. /// \param Elements class members.
  226. /// \param VTableHolder Debug info of the base class that contains vtable
  227. /// for this type. This is used in
  228. /// DW_AT_containing_type. See DWARF documentation
  229. /// for more info.
  230. /// \param TemplateParms Template type parameters.
  231. /// \param UniqueIdentifier A unique identifier for the class.
  232. DICompositeType *createClassType(DIScope *Scope, StringRef Name,
  233. DIFile *File, unsigned LineNumber,
  234. uint64_t SizeInBits, uint64_t AlignInBits,
  235. uint64_t OffsetInBits, unsigned Flags,
  236. DIType *DerivedFrom, DINodeArray Elements,
  237. DIType *VTableHolder = nullptr,
  238. MDNode *TemplateParms = nullptr,
  239. StringRef UniqueIdentifier = "");
  240. /// Create debugging information entry for a struct.
  241. /// \param Scope Scope in which this struct is defined.
  242. /// \param Name Struct name.
  243. /// \param File File where this member is defined.
  244. /// \param LineNumber Line number.
  245. /// \param SizeInBits Member size.
  246. /// \param AlignInBits Member alignment.
  247. /// \param Flags Flags to encode member attribute, e.g. private
  248. /// \param Elements Struct elements.
  249. /// \param RunTimeLang Optional parameter, Objective-C runtime version.
  250. /// \param UniqueIdentifier A unique identifier for the struct.
  251. DICompositeType *createStructType(
  252. DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
  253. uint64_t SizeInBits, uint64_t AlignInBits, unsigned Flags,
  254. DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang = 0,
  255. DIType *VTableHolder = nullptr, StringRef UniqueIdentifier = "");
  256. /// Create debugging information entry for an union.
  257. /// \param Scope Scope in which this union is defined.
  258. /// \param Name Union name.
  259. /// \param File File where this member is defined.
  260. /// \param LineNumber Line number.
  261. /// \param SizeInBits Member size.
  262. /// \param AlignInBits Member alignment.
  263. /// \param Flags Flags to encode member attribute, e.g. private
  264. /// \param Elements Union elements.
  265. /// \param RunTimeLang Optional parameter, Objective-C runtime version.
  266. /// \param UniqueIdentifier A unique identifier for the union.
  267. DICompositeType *createUnionType(DIScope *Scope, StringRef Name,
  268. DIFile *File, unsigned LineNumber,
  269. uint64_t SizeInBits, uint64_t AlignInBits,
  270. unsigned Flags, DINodeArray Elements,
  271. unsigned RunTimeLang = 0,
  272. StringRef UniqueIdentifier = "");
  273. /// Create debugging information for template
  274. /// type parameter.
  275. /// \param Scope Scope in which this type is defined.
  276. /// \param Name Type parameter name.
  277. /// \param Ty Parameter type.
  278. DITemplateTypeParameter *
  279. createTemplateTypeParameter(DIScope *Scope, StringRef Name, DIType *Ty);
  280. /// Create debugging information for template
  281. /// value parameter.
  282. /// \param Scope Scope in which this type is defined.
  283. /// \param Name Value parameter name.
  284. /// \param Ty Parameter type.
  285. /// \param Val Constant parameter value.
  286. DITemplateValueParameter *createTemplateValueParameter(DIScope *Scope,
  287. StringRef Name,
  288. DIType *Ty,
  289. Constant *Val);
  290. /// Create debugging information for a template template parameter.
  291. /// \param Scope Scope in which this type is defined.
  292. /// \param Name Value parameter name.
  293. /// \param Ty Parameter type.
  294. /// \param Val The fully qualified name of the template.
  295. DITemplateValueParameter *createTemplateTemplateParameter(DIScope *Scope,
  296. StringRef Name,
  297. DIType *Ty,
  298. StringRef Val);
  299. /// Create debugging information for a template parameter pack.
  300. /// \param Scope Scope in which this type is defined.
  301. /// \param Name Value parameter name.
  302. /// \param Ty Parameter type.
  303. /// \param Val An array of types in the pack.
  304. DITemplateValueParameter *createTemplateParameterPack(DIScope *Scope,
  305. StringRef Name,
  306. DIType *Ty,
  307. DINodeArray Val);
  308. /// Create debugging information entry for an array.
  309. /// \param Size Array size.
  310. /// \param AlignInBits Alignment.
  311. /// \param Ty Element type.
  312. /// \param Subscripts Subscripts.
  313. DICompositeType *createArrayType(uint64_t Size, uint64_t AlignInBits,
  314. DIType *Ty, DINodeArray Subscripts);
  315. /// Create debugging information entry for a vector type.
  316. /// \param Size Array size.
  317. /// \param AlignInBits Alignment.
  318. /// \param Ty Element type.
  319. /// \param Subscripts Subscripts.
  320. DICompositeType *createVectorType(uint64_t Size, uint64_t AlignInBits,
  321. DIType *Ty, DINodeArray Subscripts);
  322. /// Create debugging information entry for an
  323. /// enumeration.
  324. /// \param Scope Scope in which this enumeration is defined.
  325. /// \param Name Union name.
  326. /// \param File File where this member is defined.
  327. /// \param LineNumber Line number.
  328. /// \param SizeInBits Member size.
  329. /// \param AlignInBits Member alignment.
  330. /// \param Elements Enumeration elements.
  331. /// \param UnderlyingType Underlying type of a C++11/ObjC fixed enum.
  332. /// \param UniqueIdentifier A unique identifier for the enum.
  333. DICompositeType *createEnumerationType(
  334. DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
  335. uint64_t SizeInBits, uint64_t AlignInBits, DINodeArray Elements,
  336. DIType *UnderlyingType, StringRef UniqueIdentifier = "");
  337. /// Create subroutine type.
  338. /// \param File File in which this subroutine is defined.
  339. /// \param ParameterTypes An array of subroutine parameter types. This
  340. /// includes return type at 0th index.
  341. /// \param Flags E.g.: LValueReference.
  342. /// These flags are used to emit dwarf attributes.
  343. DISubroutineType *createSubroutineType(DIFile *File,
  344. DITypeRefArray ParameterTypes,
  345. unsigned Flags = 0);
  346. /// Create a new DIType* with "artificial" flag set.
  347. DIType *createArtificialType(DIType *Ty);
  348. /// Create a new DIType* with the "object pointer"
  349. /// flag set.
  350. DIType *createObjectPointerType(DIType *Ty);
  351. /// Create a permanent forward-declared type.
  352. DICompositeType *createForwardDecl(unsigned Tag, StringRef Name,
  353. DIScope *Scope, DIFile *F, unsigned Line,
  354. unsigned RuntimeLang = 0,
  355. uint64_t SizeInBits = 0,
  356. uint64_t AlignInBits = 0,
  357. StringRef UniqueIdentifier = "");
  358. /// Create a temporary forward-declared type.
  359. DICompositeType *createReplaceableCompositeType(
  360. unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
  361. unsigned RuntimeLang = 0, uint64_t SizeInBits = 0,
  362. uint64_t AlignInBits = 0, unsigned Flags = DINode::FlagFwdDecl,
  363. StringRef UniqueIdentifier = "");
  364. /// Retain DIType* in a module even if it is not referenced
  365. /// through debug info anchors.
  366. void retainType(DIType *T);
  367. /// Create unspecified parameter type
  368. /// for a subroutine type.
  369. DIBasicType *createUnspecifiedParameter();
  370. /// Get a DINodeArray, create one if required.
  371. DINodeArray getOrCreateArray(ArrayRef<Metadata *> Elements);
  372. /// Get a DITypeRefArray, create one if required.
  373. DITypeRefArray getOrCreateTypeArray(ArrayRef<Metadata *> Elements);
  374. /// Create a descriptor for a value range. This
  375. /// implicitly uniques the values returned.
  376. DISubrange *getOrCreateSubrange(int64_t Lo, int64_t Count);
  377. /// Create a new descriptor for the specified
  378. /// variable.
  379. /// \param Context Variable scope.
  380. /// \param Name Name of the variable.
  381. /// \param LinkageName Mangled name of the variable.
  382. /// \param File File where this variable is defined.
  383. /// \param LineNo Line number.
  384. /// \param Ty Variable Type.
  385. /// \param isLocalToUnit Boolean flag indicate whether this variable is
  386. /// externally visible or not.
  387. /// \param Val llvm::Value of the variable.
  388. /// \param Decl Reference to the corresponding declaration.
  389. DIGlobalVariable *createGlobalVariable(DIScope *Context, StringRef Name,
  390. StringRef LinkageName, DIFile *File,
  391. unsigned LineNo, DIType *Ty,
  392. bool isLocalToUnit,
  393. llvm::Constant *Val,
  394. MDNode *Decl = nullptr);
  395. /// Identical to createGlobalVariable
  396. /// except that the resulting DbgNode is temporary and meant to be RAUWed.
  397. DIGlobalVariable *createTempGlobalVariableFwdDecl(
  398. DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
  399. unsigned LineNo, DIType *Ty, bool isLocalToUnit, llvm::Constant *Val,
  400. MDNode *Decl = nullptr);
  401. /// Create a new descriptor for the specified
  402. /// local variable.
  403. /// \param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
  404. /// DW_TAG_arg_variable.
  405. /// \param Scope Variable scope.
  406. /// \param Name Variable name.
  407. /// \param File File where this variable is defined.
  408. /// \param LineNo Line number.
  409. /// \param Ty Variable Type
  410. /// \param AlwaysPreserve Boolean. Set to true if debug info for this
  411. /// variable should be preserved in optimized build.
  412. /// \param Flags Flags, e.g. artificial variable.
  413. /// \param ArgNo If this variable is an argument then this argument's
  414. /// number. 1 indicates 1st argument.
  415. DILocalVariable *createLocalVariable(unsigned Tag, DIScope *Scope,
  416. StringRef Name, DIFile *File,
  417. unsigned LineNo, DIType *Ty,
  418. bool AlwaysPreserve = false,
  419. unsigned Flags = 0,
  420. unsigned ArgNo = 0);
  421. /// Create a new descriptor for the specified
  422. /// variable which has a complex address expression for its address.
  423. /// \param Addr An array of complex address operations.
  424. DIExpression *createExpression(ArrayRef<uint64_t> Addr = None);
  425. DIExpression *createExpression(ArrayRef<int64_t> Addr);
  426. /// Create a descriptor to describe one part
  427. /// of aggregate variable that is fragmented across multiple Values.
  428. ///
  429. /// \param OffsetInBits Offset of the piece in bits.
  430. /// \param SizeInBits Size of the piece in bits.
  431. DIExpression *createBitPieceExpression(unsigned OffsetInBits,
  432. unsigned SizeInBits);
  433. /// Create a new descriptor for the specified subprogram.
  434. /// See comments in DISubprogram* for descriptions of these fields.
  435. /// \param Scope Function scope.
  436. /// \param Name Function name.
  437. /// \param LinkageName Mangled function name.
  438. /// \param File File where this variable is defined.
  439. /// \param LineNo Line number.
  440. /// \param Ty Function type.
  441. /// \param isLocalToUnit True if this function is not externally visible.
  442. /// \param isDefinition True if this is a function definition.
  443. /// \param ScopeLine Set to the beginning of the scope this starts
  444. /// \param Flags e.g. is this function prototyped or not.
  445. /// These flags are used to emit dwarf attributes.
  446. /// \param isOptimized True if optimization is ON.
  447. /// \param Fn llvm::Function pointer.
  448. /// \param TParam Function template parameters.
  449. DISubprogram *
  450. createFunction(DIScope *Scope, StringRef Name, StringRef LinkageName,
  451. DIFile *File, unsigned LineNo, DISubroutineType *Ty,
  452. bool isLocalToUnit, bool isDefinition, unsigned ScopeLine,
  453. unsigned Flags = 0, bool isOptimized = false,
  454. Function *Fn = nullptr, MDNode *TParam = nullptr,
  455. MDNode *Decl = nullptr);
  456. /// Identical to createFunction,
  457. /// except that the resulting DbgNode is meant to be RAUWed.
  458. DISubprogram *createTempFunctionFwdDecl(
  459. DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File,
  460. unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
  461. bool isDefinition, unsigned ScopeLine, unsigned Flags = 0,
  462. bool isOptimized = false, Function *Fn = nullptr,
  463. MDNode *TParam = nullptr, MDNode *Decl = nullptr);
  464. /// FIXME: this is added for dragonegg. Once we update dragonegg
  465. /// to call resolve function, this will be removed.
  466. DISubprogram *
  467. createFunction(DIScopeRef Scope, StringRef Name, StringRef LinkageName,
  468. DIFile *File, unsigned LineNo, DISubroutineType *Ty,
  469. bool isLocalToUnit, bool isDefinition, unsigned ScopeLine,
  470. unsigned Flags = 0, bool isOptimized = false,
  471. Function *Fn = nullptr, MDNode *TParam = nullptr,
  472. MDNode *Decl = nullptr);
  473. /// Create a new descriptor for the specified C++ method.
  474. /// See comments in \a DISubprogram* for descriptions of these fields.
  475. /// \param Scope Function scope.
  476. /// \param Name Function name.
  477. /// \param LinkageName Mangled function name.
  478. /// \param File File where this variable is defined.
  479. /// \param LineNo Line number.
  480. /// \param Ty Function type.
  481. /// \param isLocalToUnit True if this function is not externally visible..
  482. /// \param isDefinition True if this is a function definition.
  483. /// \param Virtuality Attributes describing virtualness. e.g. pure
  484. /// virtual function.
  485. /// \param VTableIndex Index no of this method in virtual table.
  486. /// \param VTableHolder Type that holds vtable.
  487. /// \param Flags e.g. is this function prototyped or not.
  488. /// This flags are used to emit dwarf attributes.
  489. /// \param isOptimized True if optimization is ON.
  490. /// \param Fn llvm::Function pointer.
  491. /// \param TParam Function template parameters.
  492. DISubprogram *
  493. createMethod(DIScope *Scope, StringRef Name, StringRef LinkageName,
  494. DIFile *File, unsigned LineNo, DISubroutineType *Ty,
  495. bool isLocalToUnit, bool isDefinition, unsigned Virtuality = 0,
  496. unsigned VTableIndex = 0, DIType *VTableHolder = nullptr,
  497. unsigned Flags = 0, bool isOptimized = false,
  498. Function *Fn = nullptr, MDNode *TParam = nullptr);
  499. /// This creates new descriptor for a namespace with the specified
  500. /// parent scope.
  501. /// \param Scope Namespace scope
  502. /// \param Name Name of this namespace
  503. /// \param File Source file
  504. /// \param LineNo Line number
  505. DINamespace *createNameSpace(DIScope *Scope, StringRef Name, DIFile *File,
  506. unsigned LineNo);
  507. /// This creates new descriptor for a module with the specified
  508. /// parent scope.
  509. /// \param Scope Parent scope
  510. /// \param Name Name of this module
  511. /// \param ConfigurationMacros
  512. /// A space-separated shell-quoted list of -D macro
  513. /// definitions as they would appear on a command line.
  514. /// \param IncludePath The path to the module map file.
  515. /// \param ISysRoot The clang system root (value of -isysroot).
  516. DIModule *createModule(DIScope *Scope, StringRef Name,
  517. StringRef ConfigurationMacros,
  518. StringRef IncludePath,
  519. StringRef ISysRoot);
  520. /// This creates a descriptor for a lexical block with a new file
  521. /// attached. This merely extends the existing
  522. /// lexical block as it crosses a file.
  523. /// \param Scope Lexical block.
  524. /// \param File Source file.
  525. /// \param Discriminator DWARF path discriminator value.
  526. DILexicalBlockFile *createLexicalBlockFile(DIScope *Scope, DIFile *File,
  527. unsigned Discriminator = 0);
  528. /// This creates a descriptor for a lexical block with the
  529. /// specified parent context.
  530. /// \param Scope Parent lexical scope.
  531. /// \param File Source file.
  532. /// \param Line Line number.
  533. /// \param Col Column number.
  534. DILexicalBlock *createLexicalBlock(DIScope *Scope, DIFile *File,
  535. unsigned Line, unsigned Col);
  536. /// Create a descriptor for an imported module.
  537. /// \param Context The scope this module is imported into
  538. /// \param NS The namespace being imported here
  539. /// \param Line Line number
  540. DIImportedEntity *createImportedModule(DIScope *Context, DINamespace *NS,
  541. unsigned Line);
  542. /// Create a descriptor for an imported module.
  543. /// \param Context The scope this module is imported into
  544. /// \param NS An aliased namespace
  545. /// \param Line Line number
  546. DIImportedEntity *createImportedModule(DIScope *Context,
  547. DIImportedEntity *NS, unsigned Line);
  548. /// Create a descriptor for an imported module.
  549. /// \param Context The scope this module is imported into
  550. /// \param M The module being imported here
  551. /// \param Line Line number
  552. DIImportedEntity *createImportedModule(DIScope *Context, DIModule *M,
  553. unsigned Line);
  554. /// Create a descriptor for an imported function.
  555. /// \param Context The scope this module is imported into
  556. /// \param Decl The declaration (or definition) of a function, type, or
  557. /// variable
  558. /// \param Line Line number
  559. DIImportedEntity *createImportedDeclaration(DIScope *Context, DINode *Decl,
  560. unsigned Line,
  561. StringRef Name = "");
  562. /// Insert a new llvm.dbg.declare intrinsic call.
  563. /// \param Storage llvm::Value of the variable
  564. /// \param VarInfo Variable's debug info descriptor.
  565. /// \param Expr A complex location expression.
  566. /// \param DL Debug info location.
  567. /// \param InsertAtEnd Location for the new intrinsic.
  568. Instruction *insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
  569. DIExpression *Expr, const DILocation *DL,
  570. BasicBlock *InsertAtEnd);
  571. /// Insert a new llvm.dbg.declare intrinsic call.
  572. /// \param Storage llvm::Value of the variable
  573. /// \param VarInfo Variable's debug info descriptor.
  574. /// \param Expr A complex location expression.
  575. /// \param DL Debug info location.
  576. /// \param InsertBefore Location for the new intrinsic.
  577. Instruction *insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
  578. DIExpression *Expr, const DILocation *DL,
  579. Instruction *InsertBefore);
  580. /// Insert a new llvm.dbg.value intrinsic call.
  581. /// \param Val llvm::Value of the variable
  582. /// \param Offset Offset
  583. /// \param VarInfo Variable's debug info descriptor.
  584. /// \param Expr A complex location expression.
  585. /// \param DL Debug info location.
  586. /// \param InsertAtEnd Location for the new intrinsic.
  587. Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
  588. DILocalVariable *VarInfo,
  589. DIExpression *Expr,
  590. const DILocation *DL,
  591. BasicBlock *InsertAtEnd);
  592. /// Insert a new llvm.dbg.value intrinsic call.
  593. /// \param Val llvm::Value of the variable
  594. /// \param Offset Offset
  595. /// \param VarInfo Variable's debug info descriptor.
  596. /// \param Expr A complex location expression.
  597. /// \param DL Debug info location.
  598. /// \param InsertBefore Location for the new intrinsic.
  599. Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
  600. DILocalVariable *VarInfo,
  601. DIExpression *Expr,
  602. const DILocation *DL,
  603. Instruction *InsertBefore);
  604. /// Replace the vtable holder in the given composite type.
  605. ///
  606. /// If this creates a self reference, it may orphan some unresolved cycles
  607. /// in the operands of \c T, so \a DIBuilder needs to track that.
  608. void replaceVTableHolder(DICompositeType *&T,
  609. DICompositeType *VTableHolder);
  610. /// Replace arrays on a composite type.
  611. ///
  612. /// If \c T is resolved, but the arrays aren't -- which can happen if \c T
  613. /// has a self-reference -- \a DIBuilder needs to track the array to
  614. /// resolve cycles.
  615. void replaceArrays(DICompositeType *&T, DINodeArray Elements,
  616. DINodeArray TParems = DINodeArray());
  617. /// Replace a temporary node.
  618. ///
  619. /// Call \a MDNode::replaceAllUsesWith() on \c N, replacing it with \c
  620. /// Replacement.
  621. ///
  622. /// If \c Replacement is the same as \c N.get(), instead call \a
  623. /// MDNode::replaceWithUniqued(). In this case, the uniqued node could
  624. /// have a different address, so we return the final address.
  625. template <class NodeTy>
  626. NodeTy *replaceTemporary(TempMDNode &&N, NodeTy *Replacement) {
  627. if (N.get() == Replacement)
  628. return cast<NodeTy>(MDNode::replaceWithUniqued(std::move(N)));
  629. N->replaceAllUsesWith(Replacement);
  630. return Replacement;
  631. }
  632. };
  633. } // end namespace llvm
  634. #endif