• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     DICompileUnit *CUNode;   ///< The one compile unit created by this DIBuiler.
40     Function *DeclareFn;     ///< llvm.dbg.declare
41     Function *ValueFn;       ///< llvm.dbg.value
42 
43     SmallVector<Metadata *, 4> AllEnumTypes;
44     /// Track the RetainTypes, since they can be updated later on.
45     SmallVector<TrackingMDNodeRef, 4> AllRetainTypes;
46     SmallVector<Metadata *, 4> AllSubprograms;
47     SmallVector<Metadata *, 4> AllGVs;
48     SmallVector<TrackingMDNodeRef, 4> AllImportedModules;
49 
50     /// Track nodes that may be unresolved.
51     SmallVector<TrackingMDNodeRef, 4> UnresolvedNodes;
52     bool AllowUnresolvedNodes;
53 
54     /// Each subprogram's preserved local variables.
55     DenseMap<MDNode *, std::vector<TrackingMDNodeRef>> PreservedVariables;
56 
57     DIBuilder(const DIBuilder &) = delete;
58     void operator=(const DIBuilder &) = delete;
59 
60     /// Create a temporary.
61     ///
62     /// Create an \a temporary node and track it in \a UnresolvedNodes.
63     void trackIfUnresolved(MDNode *N);
64 
65   public:
66     /// Construct a builder for a module.
67     ///
68     /// If \c AllowUnresolved, collect unresolved nodes attached to the module
69     /// in order to resolve cycles during \a finalize().
70     explicit DIBuilder(Module &M, bool AllowUnresolved = true);
71     enum DebugEmissionKind { FullDebug=1, LineTablesOnly };
72 
73     /// Construct any deferred debug info descriptors.
74     void finalize();
75 
76     /// A CompileUnit provides an anchor for all debugging
77     /// information generated during this instance of compilation.
78     /// \param Lang          Source programming language, eg. dwarf::DW_LANG_C99
79     /// \param File          File name
80     /// \param Dir           Directory
81     /// \param Producer      Identify the producer of debugging information
82     ///                      and code.  Usually this is a compiler
83     ///                      version string.
84     /// \param isOptimized   A boolean flag which indicates whether optimization
85     ///                      is enabled or not.
86     /// \param Flags         This string lists command line options. This
87     ///                      string is directly embedded in debug info
88     ///                      output which may be used by a tool
89     ///                      analyzing generated debugging information.
90     /// \param RV            This indicates runtime version for languages like
91     ///                      Objective-C.
92     /// \param SplitName     The name of the file that we'll split debug info
93     ///                      out into.
94     /// \param Kind          The kind of debug information to generate.
95     /// \param DWOId         The DWOId if this is a split skeleton compile unit.
96     /// \param EmitDebugInfo A boolean flag which indicates whether
97     ///                      debug information should be written to
98     ///                      the final output or not. When this is
99     ///                      false, debug information annotations will
100     ///                      be present in the IL but they are not
101     ///                      written to the final assembly or object
102     ///                      file. This supports tracking source
103     ///                      location information in the back end
104     ///                      without actually changing the output
105     ///                      (e.g., when using optimization remarks).
106     DICompileUnit *
107     createCompileUnit(unsigned Lang, StringRef File, StringRef Dir,
108                       StringRef Producer, bool isOptimized, StringRef Flags,
109                       unsigned RV, StringRef SplitName = StringRef(),
110                       DebugEmissionKind Kind = FullDebug, uint64_t DWOId = 0,
111                       bool EmitDebugInfo = true);
112 
113     /// Create a file descriptor to hold debugging information
114     /// for a file.
115     DIFile *createFile(StringRef Filename, StringRef Directory);
116 
117     /// Create a single enumerator value.
118     DIEnumerator *createEnumerator(StringRef Name, int64_t Val);
119 
120     /// Create a DWARF unspecified type.
121     DIBasicType *createUnspecifiedType(StringRef Name);
122 
123     /// Create C++11 nullptr type.
124     DIBasicType *createNullPtrType();
125 
126     /// Create debugging information entry for a basic
127     /// type.
128     /// \param Name        Type name.
129     /// \param SizeInBits  Size of the type.
130     /// \param AlignInBits Type alignment.
131     /// \param Encoding    DWARF encoding code, e.g. dwarf::DW_ATE_float.
132     DIBasicType *createBasicType(StringRef Name, uint64_t SizeInBits,
133                                  uint64_t AlignInBits, unsigned Encoding);
134 
135     /// Create debugging information entry for a qualified
136     /// type, e.g. 'const int'.
137     /// \param Tag         Tag identifing type, e.g. dwarf::TAG_volatile_type
138     /// \param FromTy      Base Type.
139     DIDerivedType *createQualifiedType(unsigned Tag, DIType *FromTy);
140 
141     /// Create debugging information entry for a pointer.
142     /// \param PointeeTy   Type pointed by this pointer.
143     /// \param SizeInBits  Size.
144     /// \param AlignInBits Alignment. (optional)
145     /// \param Name        Pointer type name. (optional)
146     DIDerivedType *createPointerType(DIType *PointeeTy, uint64_t SizeInBits,
147                                      uint64_t AlignInBits = 0,
148                                      StringRef Name = "");
149 
150     /// Create debugging information entry for a pointer to member.
151     /// \param PointeeTy Type pointed to by this pointer.
152     /// \param SizeInBits  Size.
153     /// \param AlignInBits Alignment. (optional)
154     /// \param Class Type for which this pointer points to members of.
155     DIDerivedType *createMemberPointerType(DIType *PointeeTy, DIType *Class,
156                                            uint64_t SizeInBits,
157                                            uint64_t AlignInBits = 0);
158 
159     /// Create debugging information entry for a c++
160     /// style reference or rvalue reference type.
161     DIDerivedType *createReferenceType(unsigned Tag, DIType *RTy,
162                                        uint64_t SizeInBits = 0,
163                                        uint64_t AlignInBits = 0);
164 
165     /// 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     /// Create debugging information entry for a 'friend'.
175     DIDerivedType *createFriend(DIType *Ty, DIType *FriendTy);
176 
177     /// 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     /// 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     /// 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     /// 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     /// 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     /// 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     /// 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     /// 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     /// 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     /// 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     /// 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     /// 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     /// 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     /// 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     /// 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     /// Create subroutine type.
380     /// \param ParameterTypes  An array of subroutine parameter types. This
381     ///                        includes return type at 0th index.
382     /// \param Flags           E.g.: LValueReference.
383     ///                        These flags are used to emit dwarf attributes.
384     DISubroutineType *createSubroutineType(DITypeRefArray ParameterTypes,
385                                            unsigned Flags = 0);
386 
387     /// Create an external type reference.
388     /// \param Tag              Dwarf TAG.
389     /// \param File             File in which the type is defined.
390     /// \param UniqueIdentifier A unique identifier for the type.
391     DICompositeType *createExternalTypeRef(unsigned Tag, DIFile *File,
392                                            StringRef UniqueIdentifier);
393 
394     /// Create a new DIType* with "artificial" flag set.
395     DIType *createArtificialType(DIType *Ty);
396 
397     /// Create a new DIType* with the "object pointer"
398     /// flag set.
399     DIType *createObjectPointerType(DIType *Ty);
400 
401     /// Create a permanent forward-declared type.
402     DICompositeType *createForwardDecl(unsigned Tag, StringRef Name,
403                                        DIScope *Scope, DIFile *F, unsigned Line,
404                                        unsigned RuntimeLang = 0,
405                                        uint64_t SizeInBits = 0,
406                                        uint64_t AlignInBits = 0,
407                                        StringRef UniqueIdentifier = "");
408 
409     /// Create a temporary forward-declared type.
410     DICompositeType *createReplaceableCompositeType(
411         unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
412         unsigned RuntimeLang = 0, uint64_t SizeInBits = 0,
413         uint64_t AlignInBits = 0, unsigned Flags = DINode::FlagFwdDecl,
414         StringRef UniqueIdentifier = "");
415 
416     /// Retain DIType* in a module even if it is not referenced
417     /// through debug info anchors.
418     void retainType(DIType *T);
419 
420     /// Create unspecified parameter type
421     /// for a subroutine type.
422     DIBasicType *createUnspecifiedParameter();
423 
424     /// Get a DINodeArray, create one if required.
425     DINodeArray getOrCreateArray(ArrayRef<Metadata *> Elements);
426 
427     /// Get a DITypeRefArray, create one if required.
428     DITypeRefArray getOrCreateTypeArray(ArrayRef<Metadata *> Elements);
429 
430     /// Create a descriptor for a value range.  This
431     /// implicitly uniques the values returned.
432     DISubrange *getOrCreateSubrange(int64_t Lo, int64_t Count);
433 
434     /// Create a new descriptor for the specified
435     /// variable.
436     /// \param Context     Variable scope.
437     /// \param Name        Name of the variable.
438     /// \param LinkageName Mangled  name of the variable.
439     /// \param File        File where this variable is defined.
440     /// \param LineNo      Line number.
441     /// \param Ty          Variable Type.
442     /// \param isLocalToUnit Boolean flag indicate whether this variable is
443     ///                      externally visible or not.
444     /// \param Val         llvm::Value of the variable.
445     /// \param Decl        Reference to the corresponding declaration.
446     DIGlobalVariable *createGlobalVariable(DIScope *Context, StringRef Name,
447                                            StringRef LinkageName, DIFile *File,
448                                            unsigned LineNo, DIType *Ty,
449                                            bool isLocalToUnit,
450                                            llvm::Constant *Val,
451                                            MDNode *Decl = nullptr);
452 
453     /// Identical to createGlobalVariable
454     /// except that the resulting DbgNode is temporary and meant to be RAUWed.
455     DIGlobalVariable *createTempGlobalVariableFwdDecl(
456         DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
457         unsigned LineNo, DIType *Ty, bool isLocalToUnit, llvm::Constant *Val,
458         MDNode *Decl = nullptr);
459 
460     /// Create a new descriptor for an auto variable.  This is a local variable
461     /// that is not a subprogram parameter.
462     ///
463     /// \c Scope must be a \a DILocalScope, and thus its scope chain eventually
464     /// leads to a \a DISubprogram.
465     ///
466     /// If \c AlwaysPreserve, this variable will be referenced from its
467     /// containing subprogram, and will survive some optimizations.
468     DILocalVariable *createAutoVariable(DIScope *Scope, StringRef Name,
469                                          DIFile *File, unsigned LineNo,
470                                          DIType *Ty,
471                                          bool AlwaysPreserve = false,
472                                          unsigned Flags = 0);
473 
474     /// Create a new descriptor for a parameter variable.
475     ///
476     /// \c Scope must be a \a DILocalScope, and thus its scope chain eventually
477     /// leads to a \a DISubprogram.
478     ///
479     /// \c ArgNo is the index (starting from \c 1) of this variable in the
480     /// subprogram parameters.  \c ArgNo should not conflict with other
481     /// parameters of the same subprogram.
482     ///
483     /// If \c AlwaysPreserve, this variable will be referenced from its
484     /// containing subprogram, and will survive some optimizations.
485     DILocalVariable *createParameterVariable(DIScope *Scope, StringRef Name,
486                                              unsigned ArgNo, DIFile *File,
487                                              unsigned LineNo, DIType *Ty,
488                                              bool AlwaysPreserve = false,
489                                              unsigned Flags = 0);
490 
491     /// Create a new descriptor for the specified
492     /// variable which has a complex address expression for its address.
493     /// \param Addr        An array of complex address operations.
494     DIExpression *createExpression(ArrayRef<uint64_t> Addr = None);
495     DIExpression *createExpression(ArrayRef<int64_t> Addr);
496 
497     /// Create a descriptor to describe one part
498     /// of aggregate variable that is fragmented across multiple Values.
499     ///
500     /// \param OffsetInBits Offset of the piece in bits.
501     /// \param SizeInBits   Size of the piece in bits.
502     DIExpression *createBitPieceExpression(unsigned OffsetInBits,
503                                            unsigned SizeInBits);
504 
505     /// Create a new descriptor for the specified subprogram.
506     /// See comments in DISubprogram* for descriptions of these fields.
507     /// \param Scope         Function scope.
508     /// \param Name          Function name.
509     /// \param LinkageName   Mangled function name.
510     /// \param File          File where this variable is defined.
511     /// \param LineNo        Line number.
512     /// \param Ty            Function type.
513     /// \param isLocalToUnit True if this function is not externally visible.
514     /// \param isDefinition  True if this is a function definition.
515     /// \param ScopeLine     Set to the beginning of the scope this starts
516     /// \param Flags         e.g. is this function prototyped or not.
517     ///                      These flags are used to emit dwarf attributes.
518     /// \param isOptimized   True if optimization is ON.
519     /// \param TParams       Function template parameters.
520     DISubprogram *createFunction(DIScope *Scope, StringRef Name,
521                                  StringRef LinkageName, DIFile *File,
522                                  unsigned LineNo, DISubroutineType *Ty,
523                                  bool isLocalToUnit, bool isDefinition,
524                                  unsigned ScopeLine, unsigned Flags = 0,
525                                  bool isOptimized = false,
526                                  DITemplateParameterArray TParams = nullptr,
527                                  DISubprogram *Decl = nullptr);
528 
529     /// Identical to createFunction,
530     /// except that the resulting DbgNode is meant to be RAUWed.
531     DISubprogram *createTempFunctionFwdDecl(
532         DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File,
533         unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
534         bool isDefinition, unsigned ScopeLine, unsigned Flags = 0,
535         bool isOptimized = false, DITemplateParameterArray TParams = nullptr,
536         DISubprogram *Decl = nullptr);
537 
538     /// FIXME: this is added for dragonegg. Once we update dragonegg
539     /// to call resolve function, this will be removed.
540     DISubprogram *createFunction(DIScopeRef Scope, StringRef Name,
541                                  StringRef LinkageName, DIFile *File,
542                                  unsigned LineNo, DISubroutineType *Ty,
543                                  bool isLocalToUnit, bool isDefinition,
544                                  unsigned ScopeLine, unsigned Flags = 0,
545                                  bool isOptimized = false,
546                                  DITemplateParameterArray TParams = nullptr,
547                                  DISubprogram *Decl = nullptr);
548 
549     /// Create a new descriptor for the specified C++ method.
550     /// See comments in \a DISubprogram* for descriptions of these fields.
551     /// \param Scope         Function scope.
552     /// \param Name          Function name.
553     /// \param LinkageName   Mangled function name.
554     /// \param File          File where this variable is defined.
555     /// \param LineNo        Line number.
556     /// \param Ty            Function type.
557     /// \param isLocalToUnit True if this function is not externally visible..
558     /// \param isDefinition  True if this is a function definition.
559     /// \param Virtuality    Attributes describing virtualness. e.g. pure
560     ///                      virtual function.
561     /// \param VTableIndex   Index no of this method in virtual table.
562     /// \param VTableHolder  Type that holds vtable.
563     /// \param Flags         e.g. is this function prototyped or not.
564     ///                      This flags are used to emit dwarf attributes.
565     /// \param isOptimized   True if optimization is ON.
566     /// \param TParams       Function template parameters.
567     DISubprogram *
568     createMethod(DIScope *Scope, StringRef Name, StringRef LinkageName,
569                  DIFile *File, unsigned LineNo, DISubroutineType *Ty,
570                  bool isLocalToUnit, bool isDefinition, unsigned Virtuality = 0,
571                  unsigned VTableIndex = 0, DIType *VTableHolder = nullptr,
572                  unsigned Flags = 0, bool isOptimized = false,
573                  DITemplateParameterArray TParams = nullptr);
574 
575     /// This creates new descriptor for a namespace with the specified
576     /// parent scope.
577     /// \param Scope       Namespace scope
578     /// \param Name        Name of this namespace
579     /// \param File        Source file
580     /// \param LineNo      Line number
581     DINamespace *createNameSpace(DIScope *Scope, StringRef Name, DIFile *File,
582                                  unsigned LineNo);
583 
584     /// This creates new descriptor for a module with the specified
585     /// parent scope.
586     /// \param Scope       Parent scope
587     /// \param Name        Name of this module
588     /// \param ConfigurationMacros
589     ///                    A space-separated shell-quoted list of -D macro
590     ///                    definitions as they would appear on a command line.
591     /// \param IncludePath The path to the module map file.
592     /// \param ISysRoot    The clang system root (value of -isysroot).
593     DIModule *createModule(DIScope *Scope, StringRef Name,
594                            StringRef ConfigurationMacros,
595                            StringRef IncludePath,
596                            StringRef ISysRoot);
597 
598     /// This creates a descriptor for a lexical block with a new file
599     /// attached. This merely extends the existing
600     /// lexical block as it crosses a file.
601     /// \param Scope       Lexical block.
602     /// \param File        Source file.
603     /// \param Discriminator DWARF path discriminator value.
604     DILexicalBlockFile *createLexicalBlockFile(DIScope *Scope, DIFile *File,
605                                                unsigned Discriminator = 0);
606 
607     /// This creates a descriptor for a lexical block with the
608     /// specified parent context.
609     /// \param Scope         Parent lexical scope.
610     /// \param File          Source file.
611     /// \param Line          Line number.
612     /// \param Col           Column number.
613     DILexicalBlock *createLexicalBlock(DIScope *Scope, DIFile *File,
614                                        unsigned Line, unsigned Col);
615 
616     /// Create a descriptor for an imported module.
617     /// \param Context The scope this module is imported into
618     /// \param NS The namespace being imported here
619     /// \param Line Line number
620     DIImportedEntity *createImportedModule(DIScope *Context, DINamespace *NS,
621                                            unsigned Line);
622 
623     /// Create a descriptor for an imported module.
624     /// \param Context The scope this module is imported into
625     /// \param NS An aliased namespace
626     /// \param Line Line number
627     DIImportedEntity *createImportedModule(DIScope *Context,
628                                            DIImportedEntity *NS, unsigned Line);
629 
630     /// Create a descriptor for an imported module.
631     /// \param Context The scope this module is imported into
632     /// \param M The module being imported here
633     /// \param Line Line number
634     DIImportedEntity *createImportedModule(DIScope *Context, DIModule *M,
635                                            unsigned Line);
636 
637     /// Create a descriptor for an imported function.
638     /// \param Context The scope this module is imported into
639     /// \param Decl The declaration (or definition) of a function, type, or
640     ///             variable
641     /// \param Line Line number
642     DIImportedEntity *createImportedDeclaration(DIScope *Context, DINode *Decl,
643                                                 unsigned Line,
644                                                 StringRef Name = "");
645 
646     /// Insert a new llvm.dbg.declare intrinsic call.
647     /// \param Storage     llvm::Value of the variable
648     /// \param VarInfo     Variable's debug info descriptor.
649     /// \param Expr        A complex location expression.
650     /// \param DL          Debug info location.
651     /// \param InsertAtEnd Location for the new intrinsic.
652     Instruction *insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
653                                DIExpression *Expr, const DILocation *DL,
654                                BasicBlock *InsertAtEnd);
655 
656     /// Insert a new llvm.dbg.declare intrinsic call.
657     /// \param Storage      llvm::Value of the variable
658     /// \param VarInfo      Variable's debug info descriptor.
659     /// \param Expr         A complex location expression.
660     /// \param DL           Debug info location.
661     /// \param InsertBefore Location for the new intrinsic.
662     Instruction *insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
663                                DIExpression *Expr, const DILocation *DL,
664                                Instruction *InsertBefore);
665 
666     /// Insert a new llvm.dbg.value intrinsic call.
667     /// \param Val          llvm::Value of the variable
668     /// \param Offset       Offset
669     /// \param VarInfo      Variable's debug info descriptor.
670     /// \param Expr         A complex location expression.
671     /// \param DL           Debug info location.
672     /// \param InsertAtEnd Location for the new intrinsic.
673     Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
674                                          DILocalVariable *VarInfo,
675                                          DIExpression *Expr,
676                                          const DILocation *DL,
677                                          BasicBlock *InsertAtEnd);
678 
679     /// Insert a new llvm.dbg.value intrinsic call.
680     /// \param Val          llvm::Value of the variable
681     /// \param Offset       Offset
682     /// \param VarInfo      Variable's debug info descriptor.
683     /// \param Expr         A complex location expression.
684     /// \param DL           Debug info location.
685     /// \param InsertBefore Location for the new intrinsic.
686     Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
687                                          DILocalVariable *VarInfo,
688                                          DIExpression *Expr,
689                                          const DILocation *DL,
690                                          Instruction *InsertBefore);
691 
692     /// Replace the vtable holder in the given composite type.
693     ///
694     /// If this creates a self reference, it may orphan some unresolved cycles
695     /// in the operands of \c T, so \a DIBuilder needs to track that.
696     void replaceVTableHolder(DICompositeType *&T,
697                              DICompositeType *VTableHolder);
698 
699     /// Replace arrays on a composite type.
700     ///
701     /// If \c T is resolved, but the arrays aren't -- which can happen if \c T
702     /// has a self-reference -- \a DIBuilder needs to track the array to
703     /// resolve cycles.
704     void replaceArrays(DICompositeType *&T, DINodeArray Elements,
705                        DINodeArray TParams = DINodeArray());
706 
707     /// Replace a temporary node.
708     ///
709     /// Call \a MDNode::replaceAllUsesWith() on \c N, replacing it with \c
710     /// Replacement.
711     ///
712     /// If \c Replacement is the same as \c N.get(), instead call \a
713     /// MDNode::replaceWithUniqued().  In this case, the uniqued node could
714     /// have a different address, so we return the final address.
715     template <class NodeTy>
replaceTemporary(TempMDNode && N,NodeTy * Replacement)716     NodeTy *replaceTemporary(TempMDNode &&N, NodeTy *Replacement) {
717       if (N.get() == Replacement)
718         return cast<NodeTy>(MDNode::replaceWithUniqued(std::move(N)));
719 
720       N->replaceAllUsesWith(Replacement);
721       return Replacement;
722     }
723   };
724 } // end namespace llvm
725 
726 #endif
727