OSDN Git Service

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