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