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