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