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