llvm.org GIT mirror llvm / afc6740
DebugInfo: Remove DIDescriptor from the DIBuilder API As a step toward killing `DIDescriptor` and its subclasses, remove it from the `DIBuilder` API. Replace the subclasses with appropriate pointers from the new debug info hierarchy. There are a couple of possible surprises in type choices for out-of-tree frontends: - Subroutine types: `MDSubroutineType`, not `MDCompositeTypeBase`. - Composite types: `MDCompositeType`, not `MDCompositeTypeBase`. - Scopes: `MDScope`, not `MDNode`. - Generic debug info nodes: `DebugNode`, not `MDNode`. This is part of PR23080. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235111 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 4 years ago
5 changed file(s) with 421 addition(s) and 499 deletion(s). Raw diff Collapse all Expand all
5757 unsigned Line,
5858 unsigned Column) {
5959 DIBuilder *D = unwrap(Dref);
60 DILexicalBlock LB =
61 D->createLexicalBlock(DIDescriptor(unwrap(Scope)),
62 unwrap(File), Line, Column);
60 auto *LB = D->createLexicalBlock(unwrap(Scope),
61 unwrap(File), Line, Column);
6362 return wrap(LB);
6463 }
6564
6867 LLVMMetadataRef File,
6968 unsigned Discriminator) {
7069 DIBuilder *D = unwrap(Dref);
71 DILexicalBlockFile LBF =
72 D->createLexicalBlockFile(DIDescriptor(unwrap(Scope)),
73 unwrap(File), Discriminator);
70 DILexicalBlockFile LBF = D->createLexicalBlockFile(
71 unwrap(Scope), unwrap(File), Discriminator);
7472 return wrap(LBF);
7573 }
7674
8179 unsigned ScopeLine, unsigned Flags, int IsOptimized, LLVMValueRef Func) {
8280 DIBuilder *D = unwrap(Dref);
8381 DISubprogram SP = D->createFunction(
84 DIDescriptor(unwrap(Scope)), Name, LinkageName,
82 unwrap(Scope), Name, LinkageName,
8583 File ? unwrap(File) : nullptr, Line,
86 unwrapCompositeTypeBase>(CompositeType), IsLocalToUnit, IsDefinition,
84 unwrapSubroutineType>(CompositeType), IsLocalToUnit, IsDefinition,
8785 ScopeLine, Flags, IsOptimized, unwrap(Func));
8886 return wrap(SP);
8987 }
9492 int AlwaysPreserve, unsigned Flags, unsigned ArgNo) {
9593 DIBuilder *D = unwrap(Dref);
9694 DIVariable V = D->createLocalVariable(
97 Tag, DIDescriptor(unwrap(Scope)), Name, unwrap(File),
98 Line, unwrap(Ty), AlwaysPreserve, Flags, ArgNo);
95 Tag, unwrap(Scope), Name, unwrap(File), Line,
96 unwrap(Ty), AlwaysPreserve, Flags, ArgNo);
9997 return wrap(V);
10098 }
10199
137135 LLVMMetadataRef ElementTypes) {
138136 DIBuilder *D = unwrap(Dref);
139137 DICompositeType CT = D->createStructType(
140 DIDescriptor(unwrap(Scope)), Name,
141 File ? unwrap(File) : nullptr, Line, SizeInBits, AlignInBits,
142 Flags, DerivedFrom ? unwrap(DerivedFrom) : nullptr,
138 unwrap(Scope), Name, File ? unwrap(File) : nullptr, Line,
139 SizeInBits, AlignInBits, Flags,
140 DerivedFrom ? unwrap(DerivedFrom) : nullptr,
143141 ElementTypes ? DIArray(unwrap(ElementTypes)) : nullptr);
144142 return wrap(CT);
145143 }
151149 unsigned Flags) {
152150 DIBuilder *D = unwrap(Dref);
153151 DICompositeType CT = D->createReplaceableCompositeType(
154 Tag, Name, DIDescriptor(unwrap(Scope)),
155 File ? unwrap(File) : nullptr, Line, RuntimeLang, SizeInBits,
156 AlignInBits, Flags);
152 Tag, Name, unwrap(Scope), File ? unwrap(File) : nullptr,
153 Line, RuntimeLang, SizeInBits, AlignInBits, Flags);
157154 return wrap(CT);
158155 }
159156
165162 unsigned Flags, LLVMMetadataRef Ty) {
166163 DIBuilder *D = unwrap(Dref);
167164 DIDerivedType DT = D->createMemberType(
168 DIDescriptor(unwrap(Scope)), Name,
169 File ? unwrap(File) : nullptr, Line, SizeInBits, AlignInBits,
170 OffsetInBits, Flags, unwrap(Ty));
165 unwrap(Scope), Name, File ? unwrap(File) : nullptr, Line,
166 SizeInBits, AlignInBits, OffsetInBits, Flags, unwrap(Ty));
171167 return wrap(DT);
172168 }
173169
190186 DIBuilder *D = unwrap(Dref);
191187 DIDerivedType DT = D->createTypedef(
192188 unwrap(Ty), Name, File ? unwrap(File) : nullptr, Line,
193 Context ? DIDescriptor(unwrap(Context)) : DIDescriptor());
189 Context ? unwrap(Context) : nullptr);
194190 return wrap(DT);
195191 }
196192
835835 DebugLoc::get(AST->getLine(), AST->getCol(), Scope));
836836 }
837837
838 static DICompositeType CreateFunctionType(unsigned NumArgs, DIFile Unit) {
838 static MDSubroutineType *CreateFunctionType(unsigned NumArgs, DIFile Unit) {
839839 SmallVector EltTys;
840840 DIType DblTy = KSDbgInfo.getDoubleTy();
841841
12251225 // Create a subprogram DIE for this function.
12261226 DIFile Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(),
12271227 KSDbgInfo.TheCU->getDirectory());
1228 DIDescriptor FContext = Unit;
1228 MDScope *FContext = Unit;
12291229 unsigned LineNo = Line;
12301230 unsigned ScopeLine = Line;
12311231 DISubprogram SP = DBuilder->createFunction(
2929 class Value;
3030 class Constant;
3131 class LLVMContext;
32 class MDNode;
3332 class StringRef;
34 class DIBasicType;
35 class DICompileUnit;
36 class DICompositeType;
37 class DIDerivedType;
38 class DIDescriptor;
39 class DIFile;
40 class DIEnumerator;
41 class DIType;
42 class DIGlobalVariable;
43 class DIImportedEntity;
44 class DINameSpace;
45 class DIVariable;
46 class DISubrange;
47 class DILexicalBlockFile;
48 class DILexicalBlock;
49 class DIScope;
50 class DISubprogram;
51 class DITemplateTypeParameter;
52 class DITemplateValueParameter;
53 class DIObjCProperty;
5433
5534 class DIBuilder {
5635 Module &M;
124103 /// source location information in the back end
125104 /// without actually changing the output (e.g.,
126105 /// when using optimization remarks).
127 DICompileUnit createCompileUnit(unsigned Lang, StringRef File,
128 StringRef Dir, StringRef Producer,
129 bool isOptimized, StringRef Flags,
130 unsigned RV,
131 StringRef SplitName = StringRef(),
132 DebugEmissionKind Kind = FullDebug,
133 bool EmitDebugInfo = true);
106 MDCompileUnit *createCompileUnit(unsigned Lang, StringRef File,
107 StringRef Dir, StringRef Producer,
108 bool isOptimized, StringRef Flags,
109 unsigned RV, StringRef SplitName = "",
110 DebugEmissionKind Kind = FullDebug,
111 bool EmitDebugInfo = true);
134112
135113 /// createFile - Create a file descriptor to hold debugging information
136114 /// for a file.
137 DIFile createFile(StringRef Filename, StringRef Directory);
115 MDFile *createFile(StringRef Filename, StringRef Directory);
138116
139117 /// createEnumerator - Create a single enumerator value.
140 DIEnumerator createEnumerator(StringRef Name, int64_t Val);
118 MDEnumerator *createEnumerator(StringRef Name, int64_t Val);
141119
142120 /// \brief Create a DWARF unspecified type.
143 DIBasicType createUnspecifiedType(StringRef Name);
121 MDBasicType *createUnspecifiedType(StringRef Name);
144122
145123 /// \brief Create C++11 nullptr type.
146 DIBasicType createNullPtrType();
124 MDBasicType *createNullPtrType();
147125
148126 /// createBasicType - Create debugging information entry for a basic
149127 /// type.
151129 /// @param SizeInBits Size of the type.
152130 /// @param AlignInBits Type alignment.
153131 /// @param Encoding DWARF encoding code, e.g. dwarf::DW_ATE_float.
154 DIBasicType createBasicType(StringRef Name, uint64_t SizeInBits,
155 uint64_t AlignInBits, unsigned Encoding);
132 MDBasicType *createBasicType(StringRef Name, uint64_t SizeInBits,
133 uint64_t AlignInBits, unsigned Encoding);
156134
157135 /// createQualifiedType - Create debugging information entry for a qualified
158136 /// type, e.g. 'const int'.
159137 /// @param Tag Tag identifing type, e.g. dwarf::TAG_volatile_type
160138 /// @param FromTy Base Type.
161 DIDerivedType createQualifiedType(unsigned Tag, DIType FromTy);
139 MDDerivedType *createQualifiedType(unsigned Tag, MDType *FromTy);
162140
163141 /// createPointerType - Create debugging information entry for a pointer.
164142 /// @param PointeeTy Type pointed by this pointer.
165143 /// @param SizeInBits Size.
166144 /// @param AlignInBits Alignment. (optional)
167145 /// @param Name Pointer type name. (optional)
168 DIDerivedType
169 createPointerType(DIType PointeeTy, uint64_t SizeInBits,
170 uint64_t AlignInBits = 0, StringRef Name = StringRef());
146 MDDerivedType *createPointerType(MDType *PointeeTy, uint64_t SizeInBits,
147 uint64_t AlignInBits = 0,
148 StringRef Name = "");
171149
172150 /// \brief Create debugging information entry for a pointer to member.
173151 /// @param PointeeTy Type pointed to by this pointer.
174152 /// @param SizeInBits Size.
175153 /// @param AlignInBits Alignment. (optional)
176154 /// @param Class Type for which this pointer points to members of.
177 DIDerivedType createMemberPointerType(DIType PointeeTy, DIType Class,
178 uint64_t SizeInBits,
179 uint64_t AlignInBits = 0);
155 MDDerivedType *createMemberPointerType(MDType *PointeeTy, MDType *Class,
156 uint64_t SizeInBits,
157 uint64_t AlignInBits = 0);
180158
181159 /// createReferenceType - Create debugging information entry for a c++
182160 /// style reference or rvalue reference type.
183 DIDerivedType createReferenceType(unsigned Tag, DIType RTy);
161 MDDerivedType *createReferenceType(unsigned Tag, MDType *RTy);
184162
185163 /// createTypedef - Create debugging information entry for a typedef.
186164 /// @param Ty Original type.
188166 /// @param File File where this type is defined.
189167 /// @param LineNo Line number.
190168 /// @param Context The surrounding context for the typedef.
191 DIDerivedType createTypedef(DIType Ty, StringRef Name, DIFile File,
192 unsigned LineNo, DIDescriptor Context);
169 MDDerivedType *createTypedef(MDType *Ty, StringRef Name, MDFile *File,
170 unsigned LineNo, MDScope *Context);
193171
194172 /// createFriend - Create debugging information entry for a 'friend'.
195 DIDerivedType createFriend(DIType Ty, DIType FriendTy);
173 MDDerivedType *createFriend(MDType *Ty, MDType *FriendTy);
196174
197175 /// createInheritance - Create debugging information entry to establish
198176 /// inheritance relationship between two types.
201179 /// @param BaseOffset Base offset.
202180 /// @param Flags Flags to describe inheritance attribute,
203181 /// e.g. private
204 DIDerivedType createInheritance(DIType Ty, DIType BaseTy,
205 uint64_t BaseOffset, unsigned Flags);
182 MDDerivedType *createInheritance(MDType *Ty, MDType *BaseTy,
183 uint64_t BaseOffset, unsigned Flags);
206184
207185 /// createMemberType - Create debugging information entry for a member.
208186 /// @param Scope Member scope.
214192 /// @param OffsetInBits Member offset.
215193 /// @param Flags Flags to encode member attribute, e.g. private
216194 /// @param Ty Parent type.
217 DIDerivedType
218 createMemberType(DIDescriptor Scope, StringRef Name, DIFile File,
219 unsigned LineNo, uint64_t SizeInBits, uint64_t AlignInBits,
220 uint64_t OffsetInBits, unsigned Flags, DIType Ty);
195 MDDerivedType *createMemberType(MDScope *Scope, StringRef Name,
196 MDFile *File, unsigned LineNo,
197 uint64_t SizeInBits, uint64_t AlignInBits,
198 uint64_t OffsetInBits, unsigned Flags,
199 MDType *Ty);
221200
222201 /// createStaticMemberType - Create debugging information entry for a
223202 /// C++ static data member.
228207 /// @param Ty Type of the static member.
229208 /// @param Flags Flags to encode member attribute, e.g. private.
230209 /// @param Val Const initializer of the member.
231 DIDerivedType createStaticMemberType(DIDescriptor Scope, StringRef Name,
232 DIFile File, unsigned LineNo,
233 DIType Ty, unsigned Flags,
234 llvm::Constant *Val);
210 MDDerivedType *createStaticMemberType(MDScope *Scope, StringRef Name,
211 MDFile *File, unsigned LineNo,
212 MDType *Ty, unsigned Flags,
213 llvm::Constant *Val);
235214
236215 /// createObjCIVar - Create debugging information entry for Objective-C
237216 /// instance variable.
244223 /// @param Flags Flags to encode member attribute, e.g. private
245224 /// @param Ty Parent type.
246225 /// @param PropertyNode Property associated with this ivar.
247 DIDerivedType createObjCIVar(StringRef Name, DIFile File,
248 unsigned LineNo, uint64_t SizeInBits,
249 uint64_t AlignInBits, uint64_t OffsetInBits,
250 unsigned Flags, DIType Ty,
251 MDNode *PropertyNode);
226 MDDerivedType *createObjCIVar(StringRef Name, MDFile *File, unsigned LineNo,
227 uint64_t SizeInBits, uint64_t AlignInBits,
228 uint64_t OffsetInBits, unsigned Flags,
229 MDType *Ty, MDNode *PropertyNode);
252230
253231 /// createObjCProperty - Create debugging information entry for Objective-C
254232 /// property.
259237 /// @param SetterName Name of the Objective C property setter selector.
260238 /// @param PropertyAttributes Objective C property attributes.
261239 /// @param Ty Type.
262 DIObjCProperty createObjCProperty(StringRef Name,
263 DIFile File, unsigned LineNumber,
264 StringRef GetterName,
265 StringRef SetterName,
266 unsigned PropertyAttributes,
267 DIType Ty);
240 MDObjCProperty *createObjCProperty(StringRef Name, MDFile *File,
241 unsigned LineNumber,
242 StringRef GetterName,
243 StringRef SetterName,
244 unsigned PropertyAttributes, MDType *Ty);
268245
269246 /// createClassType - Create debugging information entry for a class.
270247 /// @param Scope Scope in which this class is defined.
282259 /// for more info.
283260 /// @param TemplateParms Template type parameters.
284261 /// @param UniqueIdentifier A unique identifier for the class.
285 DICompositeType createClassType(DIDescriptor Scope, StringRef Name,
286 DIFile File, unsigned LineNumber,
287 uint64_t SizeInBits, uint64_t AlignInBits,
288 uint64_t OffsetInBits, unsigned Flags,
289 DIType DerivedFrom, DIArray Elements,
290 DIType VTableHolder = DIType(),
291 MDNode *TemplateParms = nullptr,
292 StringRef UniqueIdentifier = StringRef());
262 MDCompositeType *createClassType(MDScope *Scope, StringRef Name,
263 MDFile *File, unsigned LineNumber,
264 uint64_t SizeInBits, uint64_t AlignInBits,
265 uint64_t OffsetInBits, unsigned Flags,
266 MDType *DerivedFrom, DIArray Elements,
267 MDType *VTableHolder = nullptr,
268 MDNode *TemplateParms = nullptr,
269 StringRef UniqueIdentifier = "");
293270
294271 /// createStructType - Create debugging information entry for a struct.
295272 /// @param Scope Scope in which this struct is defined.
302279 /// @param Elements Struct elements.
303280 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
304281 /// @param UniqueIdentifier A unique identifier for the struct.
305 DICompositeType createStructType(DIDescriptor Scope, StringRef Name,
306 DIFile File, unsigned LineNumber,
307 uint64_t SizeInBits, uint64_t AlignInBits,
308 unsigned Flags, DIType DerivedFrom,
309 DIArray Elements, unsigned RunTimeLang = 0,
310 DIType VTableHolder = DIType(),
311 StringRef UniqueIdentifier = StringRef());
282 MDCompositeType *createStructType(
283 MDScope *Scope, StringRef Name, MDFile *File, unsigned LineNumber,
284 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Flags,
285 MDType *DerivedFrom, DIArray Elements, unsigned RunTimeLang = 0,
286 MDType *VTableHolder = nullptr, StringRef UniqueIdentifier = "");
312287
313288 /// createUnionType - Create debugging information entry for an union.
314289 /// @param Scope Scope in which this union is defined.
321296 /// @param Elements Union elements.
322297 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
323298 /// @param UniqueIdentifier A unique identifier for the union.
324 DICompositeType createUnionType(
325 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
326 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Flags,
327 DIArray Elements, unsigned RunTimeLang = 0,
328 StringRef UniqueIdentifier = StringRef());
299 MDCompositeType *createUnionType(MDScope *Scope, StringRef Name,
300 MDFile *File, unsigned LineNumber,
301 uint64_t SizeInBits, uint64_t AlignInBits,
302 unsigned Flags, DIArray Elements,
303 unsigned RunTimeLang = 0,
304 StringRef UniqueIdentifier = "");
329305
330306 /// createTemplateTypeParameter - Create debugging information for template
331307 /// type parameter.
332308 /// @param Scope Scope in which this type is defined.
333309 /// @param Name Type parameter name.
334310 /// @param Ty Parameter type.
335 DITemplateTypeParameter
336 createTemplateTypeParameter(DIDescriptor Scope, StringRef Name, DIType Ty);
311 MDTemplateTypeParameter *
312 createTemplateTypeParameter(MDScope *Scope, StringRef Name, MDType *Ty);
337313
338314 /// createTemplateValueParameter - Create debugging information for template
339315 /// value parameter.
341317 /// @param Name Value parameter name.
342318 /// @param Ty Parameter type.
343319 /// @param Val Constant parameter value.
344 DITemplateValueParameter createTemplateValueParameter(DIDescriptor Scope,
345 StringRef Name,
346 DIType Ty,
347 Constant *Val);
320 MDTemplateValueParameter *createTemplateValueParameter(MDScope *Scope,
321 StringRef Name,
322 MDType *Ty,
323 Constant *Val);
348324
349325 /// \brief Create debugging information for a template template parameter.
350326 /// @param Scope Scope in which this type is defined.
351327 /// @param Name Value parameter name.
352328 /// @param Ty Parameter type.
353329 /// @param Val The fully qualified name of the template.
354 DITemplateValueParameter createTemplateTemplateParameter(DIDescriptor Scope,
355 StringRef Name,
356 DIType Ty,
357 StringRef Val);
330 MDTemplateValueParameter *createTemplateTemplateParameter(MDScope *Scope,
331 StringRef Name,
332 MDType *Ty,
333 StringRef Val);
358334
359335 /// \brief Create debugging information for a template parameter pack.
360336 /// @param Scope Scope in which this type is defined.
361337 /// @param Name Value parameter name.
362338 /// @param Ty Parameter type.
363339 /// @param Val An array of types in the pack.
364 DITemplateValueParameter createTemplateParameterPack(DIDescriptor Scope,
365 StringRef Name,
366 DIType Ty,
367 DIArray Val);
340 MDTemplateValueParameter *createTemplateParameterPack(MDScope *Scope,
341 StringRef Name,
342 MDType *Ty,
343 DIArray Val);
368344
369345 /// createArrayType - Create debugging information entry for an array.
370346 /// @param Size Array size.
371347 /// @param AlignInBits Alignment.
372348 /// @param Ty Element type.
373349 /// @param Subscripts Subscripts.
374 DICompositeType createArrayType(uint64_t Size, uint64_t AlignInBits,
375 DIType Ty, DIArray Subscripts);
350 MDCompositeType *createArrayType(uint64_t Size, uint64_t AlignInBits,
351 MDType *Ty, DIArray Subscripts);
376352
377353 /// createVectorType - Create debugging information entry for a vector type.
378354 /// @param Size Array size.
379355 /// @param AlignInBits Alignment.
380356 /// @param Ty Element type.
381357 /// @param Subscripts Subscripts.
382 DICompositeType createVectorType(uint64_t Size, uint64_t AlignInBits,
383 DIType Ty, DIArray Subscripts);
358 MDCompositeType *createVectorType(uint64_t Size, uint64_t AlignInBits,
359 MDType *Ty, DIArray Subscripts);
384360
385361 /// createEnumerationType - Create debugging information entry for an
386362 /// enumeration.
393369 /// @param Elements Enumeration elements.
394370 /// @param UnderlyingType Underlying type of a C++11/ObjC fixed enum.
395371 /// @param UniqueIdentifier A unique identifier for the enum.
396 DICompositeType createEnumerationType(DIDescriptor Scope, StringRef Name,
397 DIFile File, unsigned LineNumber, uint64_t SizeInBits,
398 uint64_t AlignInBits, DIArray Elements, DIType UnderlyingType,
399 StringRef UniqueIdentifier = StringRef());
372 MDCompositeType *createEnumerationType(
373 MDScope *Scope, StringRef Name, MDFile *File, unsigned LineNumber,
374 uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
375 MDType *UnderlyingType, StringRef UniqueIdentifier = "");
400376
401377 /// createSubroutineType - Create subroutine type.
402378 /// @param File File in which this subroutine is defined.
404380 /// includes return type at 0th index.
405381 /// @param Flags E.g.: LValueReference.
406382 /// These flags are used to emit dwarf attributes.
407 DISubroutineType createSubroutineType(DIFile File,
408 DITypeArray ParameterTypes,
409 unsigned Flags = 0);
410
411 /// createArtificialType - Create a new DIType with "artificial" flag set.
412 DIType createArtificialType(DIType Ty);
413
414 /// createObjectPointerType - Create a new DIType with the "object pointer"
383 MDSubroutineType *createSubroutineType(MDFile *File,
384 DITypeArray ParameterTypes,
385 unsigned Flags = 0);
386
387 /// createArtificialType - Create a new MDType* with "artificial" flag set.
388 MDType *createArtificialType(MDType *Ty);
389
390 /// createObjectPointerType - Create a new MDType* with the "object pointer"
415391 /// flag set.
416 DIType createObjectPointerType(DIType Ty);
392 MDType *createObjectPointerType(MDType *Ty);
417393
418394 /// \brief Create a permanent forward-declared type.
419 DICompositeType createForwardDecl(unsigned Tag, StringRef Name,
420 DIDescriptor Scope, DIFile F,
421 unsigned Line, unsigned RuntimeLang = 0,
422 uint64_t SizeInBits = 0,
423 uint64_t AlignInBits = 0,
424 StringRef UniqueIdentifier = StringRef());
395 MDCompositeType *createForwardDecl(unsigned Tag, StringRef Name,
396 MDScope *Scope, MDFile *F, unsigned Line,
397 unsigned RuntimeLang = 0,
398 uint64_t SizeInBits = 0,
399 uint64_t AlignInBits = 0,
400 StringRef UniqueIdentifier = "");
425401
426402 /// \brief Create a temporary forward-declared type.
427 DICompositeType createReplaceableCompositeType(
428 unsigned Tag, StringRef Name, DIDescriptor Scope, DIFile F,
429 unsigned Line, unsigned RuntimeLang = 0, uint64_t SizeInBits = 0,
403 MDCompositeType *createReplaceableCompositeType(
404 unsigned Tag, StringRef Name, MDScope *Scope, MDFile *F, unsigned Line,
405 unsigned RuntimeLang = 0, uint64_t SizeInBits = 0,
430406 uint64_t AlignInBits = 0, unsigned Flags = DebugNode::FlagFwdDecl,
431 StringRef UniqueIdentifier = StringRef());
432
433 /// retainType - Retain DIType in a module even if it is not referenced
407 StringRef UniqueIdentifier = "");
408
409 /// retainType - Retain MDType* in a module even if it is not referenced
434410 /// through debug info anchors.
435 void retainType(DIType T);
411 void retainType(MDType *T);
436412
437413 /// createUnspecifiedParameter - Create unspecified parameter type
438414 /// for a subroutine type.
439 DIBasicType createUnspecifiedParameter();
415 MDBasicType *createUnspecifiedParameter();
440416
441417 /// getOrCreateArray - Get a DIArray, create one if required.
442418 DIArray getOrCreateArray(ArrayRef Elements);
446422
447423 /// getOrCreateSubrange - Create a descriptor for a value range. This
448424 /// implicitly uniques the values returned.
449 DISubrange getOrCreateSubrange(int64_t Lo, int64_t Count);
450
425 MDSubrange *getOrCreateSubrange(int64_t Lo, int64_t Count);
451426
452427 /// createGlobalVariable - Create a new descriptor for the specified
453428 /// variable.
461436 /// externally visible or not.
462437 /// @param Val llvm::Value of the variable.
463438 /// @param Decl Reference to the corresponding declaration.
464 DIGlobalVariable createGlobalVariable(DIDescriptor Context, StringRef Name,
465 StringRef LinkageName, DIFile File,
466 unsigned LineNo, DIType Ty,
467 bool isLocalToUnit,
468 llvm::Constant *Val,
469 MDNode *Decl = nullptr);
439 MDGlobalVariable *createGlobalVariable(MDScope *Context, StringRef Name,
440 StringRef LinkageName, MDFile *File,
441 unsigned LineNo, MDType *Ty,
442 bool isLocalToUnit,
443 llvm::Constant *Val,
444 MDNode *Decl = nullptr);
470445
471446 /// createTempGlobalVariableFwdDecl - Identical to createGlobalVariable
472447 /// except that the resulting DbgNode is temporary and meant to be RAUWed.
473 DIGlobalVariable createTempGlobalVariableFwdDecl(
474 DIDescriptor Context, StringRef Name, StringRef LinkageName,
475 DIFile File, unsigned LineNo, DIType Ty, bool isLocalToUnit,
476 llvm::Constant *Val, MDNode *Decl = nullptr);
448 MDGlobalVariable *createTempGlobalVariableFwdDecl(
449 MDScope *Context, StringRef Name, StringRef LinkageName, MDFile *File,
450 unsigned LineNo, MDType *Ty, bool isLocalToUnit, llvm::Constant *Val,
451 MDNode *Decl = nullptr);
477452
478453 /// createLocalVariable - Create a new descriptor for the specified
479454 /// local variable.
489464 /// @param Flags Flags, e.g. artificial variable.
490465 /// @param ArgNo If this variable is an argument then this argument's
491466 /// number. 1 indicates 1st argument.
492 DIVariable createLocalVariable(unsigned Tag, DIDescriptor Scope,
493 StringRef Name, DIFile File, unsigned LineNo,
494 DIType Ty, bool AlwaysPreserve = false,
495 unsigned Flags = 0, unsigned ArgNo = 0);
467 MDLocalVariable *createLocalVariable(unsigned Tag, MDScope *Scope,
468 StringRef Name, MDFile *File,
469 unsigned LineNo, MDType *Ty,
470 bool AlwaysPreserve = false,
471 unsigned Flags = 0,
472 unsigned ArgNo = 0);
496473
497474 /// createExpression - Create a new descriptor for the specified
498475 /// variable which has a complex address expression for its address.
499476 /// @param Addr An array of complex address operations.
500 DIExpression createExpression(ArrayRef Addr = None);
501 DIExpression createExpression(ArrayRef Addr);
477 MDExpression *createExpression(ArrayRef Addr = None);
478 MDExpression *createExpression(ArrayRef Addr);
502479
503480 /// createBitPieceExpression - Create a descriptor to describe one part
504481 /// of aggregate variable that is fragmented across multiple Values.
505482 ///
506483 /// @param OffsetInBits Offset of the piece in bits.
507484 /// @param SizeInBits Size of the piece in bits.
508 DIExpression createBitPieceExpression(unsigned OffsetInBits,
509 unsigned SizeInBits);
485 MDExpression *createBitPieceExpression(unsigned OffsetInBits,
486 unsigned SizeInBits);
510487
511488 /// createFunction - Create a new descriptor for the specified subprogram.
512 /// See comments in DISubprogram for descriptions of these fields.
489 /// See comments in MDSubprogram* for descriptions of these fields.
513490 /// @param Scope Function scope.
514491 /// @param Name Function name.
515492 /// @param LinkageName Mangled function name.
524501 /// @param isOptimized True if optimization is ON.
525502 /// @param Fn llvm::Function pointer.
526503 /// @param TParam Function template parameters.
527 DISubprogram createFunction(DIDescriptor Scope, StringRef Name,
528 StringRef LinkageName,
529 DIFile File, unsigned LineNo,
530 DICompositeType Ty, bool isLocalToUnit,
531 bool isDefinition,
532 unsigned ScopeLine,
533 unsigned Flags = 0,
534 bool isOptimized = false,
535 Function *Fn = nullptr,
536 MDNode *TParam = nullptr,
537 MDNode *Decl = nullptr);
504 MDSubprogram *
505 createFunction(MDScope *Scope, StringRef Name, StringRef LinkageName,
506 MDFile *File, unsigned LineNo, MDSubroutineType *Ty,
507 bool isLocalToUnit, bool isDefinition, unsigned ScopeLine,
508 unsigned Flags = 0, bool isOptimized = false,
509 Function *Fn = nullptr, MDNode *TParam = nullptr,
510 MDNode *Decl = nullptr);
538511
539512 /// createTempFunctionFwdDecl - Identical to createFunction,
540513 /// except that the resulting DbgNode is meant to be RAUWed.
541 DISubprogram createTempFunctionFwdDecl(DIDescriptor Scope, StringRef Name,
542 StringRef LinkageName,
543 DIFile File, unsigned LineNo,
544 DICompositeType Ty, bool isLocalToUnit,
545 bool isDefinition,
546 unsigned ScopeLine,
547 unsigned Flags = 0,
548 bool isOptimized = false,
549 Function *Fn = nullptr,
550 MDNode *TParam = nullptr,
551 MDNode *Decl = nullptr);
552
514 MDSubprogram *createTempFunctionFwdDecl(
515 MDScope *Scope, StringRef Name, StringRef LinkageName, MDFile *File,
516 unsigned LineNo, MDSubroutineType *Ty, bool isLocalToUnit,
517 bool isDefinition, unsigned ScopeLine, unsigned Flags = 0,
518 bool isOptimized = false, Function *Fn = nullptr,
519 MDNode *TParam = nullptr, MDNode *Decl = nullptr);
553520
554521 /// FIXME: this is added for dragonegg. Once we update dragonegg
555522 /// to call resolve function, this will be removed.
556 DISubprogram createFunction(DIScopeRef Scope, StringRef Name,
557 StringRef LinkageName,
558 DIFile File, unsigned LineNo,
559 DICompositeType Ty, bool isLocalToUnit,
560 bool isDefinition,
561 unsigned ScopeLine,
562 unsigned Flags = 0,
563 bool isOptimized = false,
564 Function *Fn = nullptr,
565 MDNode *TParam = nullptr,
566 MDNode *Decl = nullptr);
523 MDSubprogram *
524 createFunction(DIScopeRef Scope, StringRef Name, StringRef LinkageName,
525 MDFile *File, unsigned LineNo, MDSubroutineType *Ty,
526 bool isLocalToUnit, bool isDefinition, unsigned ScopeLine,
527 unsigned Flags = 0, bool isOptimized = false,
528 Function *Fn = nullptr, MDNode *TParam = nullptr,
529 MDNode *Decl = nullptr);
567530
568531 /// createMethod - Create a new descriptor for the specified C++ method.
569 /// See comments in DISubprogram for descriptions of these fields.
532 /// See comments in MDSubprogram* for descriptions of these fields.
570533 /// @param Scope Function scope.
571534 /// @param Name Function name.
572535 /// @param LinkageName Mangled function name.
584547 /// @param isOptimized True if optimization is ON.
585548 /// @param Fn llvm::Function pointer.
586549 /// @param TParam Function template parameters.
587 DISubprogram createMethod(DIDescriptor Scope, StringRef Name,
588 StringRef LinkageName,
589 DIFile File, unsigned LineNo,
590 DICompositeType Ty, bool isLocalToUnit,
591 bool isDefinition,
592 unsigned Virtuality = 0, unsigned VTableIndex = 0,
593 DIType VTableHolder = DIType(),
594 unsigned Flags = 0,
595 bool isOptimized = false,
596 Function *Fn = nullptr,
597 MDNode *TParam = nullptr);
550 MDSubprogram *
551 createMethod(MDScope *Scope, StringRef Name, StringRef LinkageName,
552 MDFile *File, unsigned LineNo, MDSubroutineType *Ty,
553 bool isLocalToUnit, bool isDefinition, unsigned Virtuality = 0,
554 unsigned VTableIndex = 0, MDType *VTableHolder = nullptr,
555 unsigned Flags = 0, bool isOptimized = false,
556 Function *Fn = nullptr, MDNode *TParam = nullptr);
598557
599558 /// createNameSpace - This creates new descriptor for a namespace
600559 /// with the specified parent scope.
602561 /// @param Name Name of this namespace
603562 /// @param File Source file
604563 /// @param LineNo Line number
605 DINameSpace createNameSpace(DIDescriptor Scope, StringRef Name,
606 DIFile File, unsigned LineNo);
607
564 MDNamespace *createNameSpace(MDScope *Scope, StringRef Name, MDFile *File,
565 unsigned LineNo);
608566
609567 /// createLexicalBlockFile - This creates a descriptor for a lexical
610568 /// block with a new file attached. This merely extends the existing
612570 /// @param Scope Lexical block.
613571 /// @param File Source file.
614572 /// @param Discriminator DWARF path discriminator value.
615 DILexicalBlockFile createLexicalBlockFile(DIDescriptor Scope, DIFile File,
616 unsigned Discriminator = 0);
573 MDLexicalBlockFile *createLexicalBlockFile(MDScope *Scope, MDFile *File,
574 unsigned Discriminator = 0);
617575
618576 /// createLexicalBlock - This creates a descriptor for a lexical block
619577 /// with the specified parent context.
621579 /// @param File Source file.
622580 /// @param Line Line number.
623581 /// @param Col Column number.
624 DILexicalBlock createLexicalBlock(DIDescriptor Scope, DIFile File,
625 unsigned Line, unsigned Col);
582 MDLexicalBlock *createLexicalBlock(MDScope *Scope, MDFile *File,
583 unsigned Line, unsigned Col);
626584
627585 /// \brief Create a descriptor for an imported module.
628586 /// @param Context The scope this module is imported into
629587 /// @param NS The namespace being imported here
630588 /// @param Line Line number
631 DIImportedEntity createImportedModule(DIScope Context, DINameSpace NS,
632 unsigned Line);
589 MDImportedEntity *createImportedModule(MDScope *Context, MDNamespace *NS,
590 unsigned Line);
633591
634592 /// \brief Create a descriptor for an imported module.
635593 /// @param Context The scope this module is imported into
636594 /// @param NS An aliased namespace
637595 /// @param Line Line number
638 DIImportedEntity createImportedModule(DIScope Context, DIImportedEntity NS,
639 unsigned Line);
596 MDImportedEntity *createImportedModule(MDScope *Context,
597 MDImportedEntity *NS, unsigned Line);
640598
641599 /// \brief Create a descriptor for an imported function.
642600 /// @param Context The scope this module is imported into
643601 /// @param Decl The declaration (or definition) of a function, type, or
644602 /// variable
645603 /// @param Line Line number
646 DIImportedEntity createImportedDeclaration(DIScope Context, DIDescriptor Decl,
647 unsigned Line,
648 StringRef Name = StringRef());
649 DIImportedEntity createImportedDeclaration(DIScope Context,
650 DIImportedEntity NS,
651 unsigned Line,
652 StringRef Name = StringRef());
604 MDImportedEntity *createImportedDeclaration(MDScope *Context,
605 DebugNode *Decl, unsigned Line,
606 StringRef Name = "");
653607
654608 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
655609 /// @param Storage llvm::Value of the variable
657611 /// @param Expr A complex location expression.
658612 /// @param DL Debug info location.
659613 /// @param InsertAtEnd Location for the new intrinsic.
660 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
661 DIExpression Expr, const MDLocation *DL,
614 Instruction *insertDeclare(llvm::Value *Storage, MDLocalVariable *VarInfo,
615 MDExpression *Expr, const MDLocation *DL,
662616 BasicBlock *InsertAtEnd);
663617
664618 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
667621 /// @param Expr A complex location expression.
668622 /// @param DL Debug info location.
669623 /// @param InsertBefore Location for the new intrinsic.
670 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
671 DIExpression Expr, const MDLocation *DL,
624 Instruction *insertDeclare(llvm::Value *Storage, MDLocalVariable *VarInfo,
625 MDExpression *Expr, const MDLocation *DL,
672626 Instruction *InsertBefore);
673627
674628 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
679633 /// @param DL Debug info location.
680634 /// @param InsertAtEnd Location for the new intrinsic.
681635 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
682 DIVariable VarInfo, DIExpression Expr,
636 MDLocalVariable *VarInfo,
637 MDExpression *Expr,
683638 const MDLocation *DL,
684639 BasicBlock *InsertAtEnd);
685640
691646 /// @param DL Debug info location.
692647 /// @param InsertBefore Location for the new intrinsic.
693648 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
694 DIVariable VarInfo, DIExpression Expr,
649 MDLocalVariable *VarInfo,
650 MDExpression *Expr,
695651 const MDLocation *DL,
696652 Instruction *InsertBefore);
697653
699655 ///
700656 /// If this creates a self reference, it may orphan some unresolved cycles
701657 /// in the operands of \c T, so \a DIBuilder needs to track that.
702 void replaceVTableHolder(DICompositeType &T, DICompositeType VTableHolder);
658 void replaceVTableHolder(MDCompositeType *&T,
659 MDCompositeType *VTableHolder);
703660
704661 /// \brief Replace arrays on a composite type.
705662 ///
706663 /// If \c T is resolved, but the arrays aren't -- which can happen if \c T
707664 /// has a self-reference -- \a DIBuilder needs to track the array to
708665 /// resolve cycles.
709 void replaceArrays(DICompositeType &T, DIArray Elements,
666 void replaceArrays(MDCompositeType *&T, DIArray Elements,
710667 DIArray TParems = DIArray());
711668
712669 /// \brief Replace a temporary node.
7373 }
7474
7575 void DIBuilder::finalize() {
76 DIArray Enums = getOrCreateArray(AllEnumTypes);
77 TempEnumTypes->replaceAllUsesWith(Enums.get());
76 TempEnumTypes->replaceAllUsesWith(MDTuple::get(VMContext, AllEnumTypes));
7877
7978 SmallVector RetainValues;
8079 // Declarations and definitions of the same type may be retained. Some
8584 for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++)
8685 if (RetainSet.insert(AllRetainTypes[I]).second)
8786 RetainValues.push_back(AllRetainTypes[I]);
88 DIArray RetainTypes = getOrCreateArray(RetainValues);
89 TempRetainTypes->replaceAllUsesWith(RetainTypes.get());
90
91 DIArray SPs = getOrCreateArray(AllSubprograms);
87 TempRetainTypes->replaceAllUsesWith(MDTuple::get(VMContext, RetainValues));
88
89 MDSubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms);
9290 TempSubprograms->replaceAllUsesWith(SPs.get());
93 for (unsigned i = 0, e = SPs.size(); i != e; ++i) {
94 DISubprogram SP = cast(SPs[i]);
91 for (auto *SP : SPs) {
9592 if (MDTuple *Temp = SP->getVariables().get()) {
9693 const auto &PV = PreservedVariables.lookup(SP);
9794 SmallVector Variables(PV.begin(), PV.end());
10097 }
10198 }
10299
103 DIArray GVs = getOrCreateArray(AllGVs);
104 TempGVs->replaceAllUsesWith(GVs.get());
105
106 SmallVector RetainValuesI(AllImportedModules.begin(),
107 AllImportedModules.end());
108 DIArray IMs = getOrCreateArray(RetainValuesI);
109 TempImportedModules->replaceAllUsesWith(IMs.get());
100 TempGVs->replaceAllUsesWith(MDTuple::get(VMContext, AllGVs));
101
102 TempImportedModules->replaceAllUsesWith(MDTuple::get(
103 VMContext, SmallVector(AllImportedModules.begin(),
104 AllImportedModules.end())));
110105
111106 // Now that all temp nodes have been replaced or deleted, resolve remaining
112107 // cycles.
120115 }
121116
122117 /// If N is compile unit return NULL otherwise return N.
123 static MDScope *getNonCompileUnitScope(MDNode *N) {
118 static MDScope *getNonCompileUnitScope(MDScope *N) {
124119 if (!N || isa(N))
125120 return nullptr;
126121 return cast(N);
127122 }
128123
129 DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename,
130 StringRef Directory,
131 StringRef Producer, bool isOptimized,
132 StringRef Flags, unsigned RunTimeVer,
133 StringRef SplitName,
134 DebugEmissionKind Kind,
135 bool EmitDebugInfo) {
124 MDCompileUnit *DIBuilder::createCompileUnit(
125 unsigned Lang, StringRef Filename, StringRef Directory, StringRef Producer,
126 bool isOptimized, StringRef Flags, unsigned RunTimeVer, StringRef SplitName,
127 DebugEmissionKind Kind, bool EmitDebugInfo) {
136128
137129 assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) ||
138130 (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
170162 return CUNode;
171163 }
172164
173 static DIImportedEntity
174 createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope Context,
165 static MDImportedEntity*
166 createImportedModule(LLVMContext &C, dwarf::Tag Tag, MDScope* Context,
175167 Metadata *NS, unsigned Line, StringRef Name,
176168 SmallVectorImpl &AllImportedModules) {
177 DIImportedEntity M =
169 auto *M =
178170 MDImportedEntity::get(C, Tag, Context, DebugNodeRef(NS), Line, Name);
179171 AllImportedModules.emplace_back(M);
180172 return M;
181173 }
182174
183 DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
184 DINameSpace NS,
175 MDImportedEntity* DIBuilder::createImportedModule(MDScope* Context,
176 MDNamespace* NS,
185177 unsigned Line) {
186178 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
187179 Context, NS, Line, StringRef(), AllImportedModules);
188180 }
189181
190 DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
191 DIImportedEntity NS,
182 MDImportedEntity* DIBuilder::createImportedModule(MDScope* Context,
183 MDImportedEntity* NS,
192184 unsigned Line) {
193185 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
194186 Context, NS, Line, StringRef(), AllImportedModules);
195187 }
196188
197 DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
198 DIDescriptor Decl,
199 unsigned Line,
200 StringRef Name) {
189 MDImportedEntity *DIBuilder::createImportedDeclaration(MDScope *Context,
190 DebugNode *Decl,
191 unsigned Line,
192 StringRef Name) {
201193 // Make sure to use the unique identifier based metadata reference for
202194 // types that have one.
203 return ::createImportedModule(
204 VMContext, dwarf::DW_TAG_imported_declaration, Context,
205 DebugNodeRef::get(cast_or_null(Decl)), Line, Name,
206 AllImportedModules);
207 }
208
209 DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
210 DIImportedEntity Imp,
211 unsigned Line, StringRef Name) {
212195 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
213 Context, Imp, Line, Name, AllImportedModules);
214 }
215
216 DIFile DIBuilder::createFile(StringRef Filename, StringRef Directory) {
196 Context, DebugNodeRef::get(Decl), Line, Name,
197 AllImportedModules);
198 }
199
200 MDFile* DIBuilder::createFile(StringRef Filename, StringRef Directory) {
217201 return MDFile::get(VMContext, Filename, Directory);
218202 }
219203
220 DIEnumerator DIBuilder::createEnumerator(StringRef Name, int64_t Val) {
204 MDEnumerator *DIBuilder::createEnumerator(StringRef Name, int64_t Val) {
221205 assert(!Name.empty() && "Unable to create enumerator without name");
222206 return MDEnumerator::get(VMContext, Val, Name);
223207 }
224208
225 DIBasicType DIBuilder::createUnspecifiedType(StringRef Name) {
209 MDBasicType *DIBuilder::createUnspecifiedType(StringRef Name) {
226210 assert(!Name.empty() && "Unable to create type without name");
227211 return MDBasicType::get(VMContext, dwarf::DW_TAG_unspecified_type, Name);
228212 }
229213
230 DIBasicType DIBuilder::createNullPtrType() {
214 MDBasicType *DIBuilder::createNullPtrType() {
231215 return createUnspecifiedType("decltype(nullptr)");
232216 }
233217
234 DIBasicType
235 DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
236 uint64_t AlignInBits, unsigned Encoding) {
218 MDBasicType *DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
219 uint64_t AlignInBits,
220 unsigned Encoding) {
237221 assert(!Name.empty() && "Unable to create type without name");
238222 return MDBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits,
239223 AlignInBits, Encoding);
240224 }
241225
242 DIDerivedType DIBuilder::createQualifiedType(unsigned Tag, DIType FromTy) {
226 MDDerivedType *DIBuilder::createQualifiedType(unsigned Tag, MDType *FromTy) {
243227 return MDDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr,
244228 MDTypeRef::get(FromTy), 0, 0, 0, 0);
245229 }
246230
247 DIDerivedType
248 DIBuilder::createPointerType(DIType PointeeTy, uint64_t SizeInBits,
249 uint64_t AlignInBits, StringRef Name) {
231 MDDerivedType *DIBuilder::createPointerType(MDType *PointeeTy,
232 uint64_t SizeInBits,
233 uint64_t AlignInBits,
234 StringRef Name) {
250235 // FIXME: Why is there a name here?
251236 return MDDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name,
252237 nullptr, 0, nullptr, MDTypeRef::get(PointeeTy),
253238 SizeInBits, AlignInBits, 0, 0);
254239 }
255240
256 DIDerivedType
257 DIBuilder::createMemberPointerType(DIType PointeeTy, DIType Base,
258 uint64_t SizeInBits, uint64_t AlignInBits) {
241 MDDerivedType *DIBuilder::createMemberPointerType(MDType *PointeeTy,
242 MDType *Base,
243 uint64_t SizeInBits,
244 uint64_t AlignInBits) {
259245 return MDDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "",
260246 nullptr, 0, nullptr, MDTypeRef::get(PointeeTy),
261247 SizeInBits, AlignInBits, 0, 0, MDTypeRef::get(Base));
262248 }
263249
264 DIDerivedType DIBuilder::createReferenceType(unsigned Tag, DIType RTy) {
250 MDDerivedType *DIBuilder::createReferenceType(unsigned Tag, MDType *RTy) {
265251 assert(RTy && "Unable to create reference type");
266252 return MDDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr,
267253 MDTypeRef::get(RTy), 0, 0, 0, 0);
268254 }
269255
270 DIDerivedType DIBuilder::createTypedef(DIType Ty, StringRef Name, DIFile File,
271 unsigned LineNo, DIDescriptor Context) {
272 return MDDerivedType::get(
273 VMContext, dwarf::DW_TAG_typedef, Name, File, LineNo,
274 MDScopeRef::get(DIScope(getNonCompileUnitScope(Context))),
275 MDTypeRef::get(Ty), 0, 0, 0, 0);
276 }
277
278 DIDerivedType DIBuilder::createFriend(DIType Ty, DIType FriendTy) {
279 // typedefs are encoded in DIDerivedType format.
256 MDDerivedType *DIBuilder::createTypedef(MDType *Ty, StringRef Name,
257 MDFile *File, unsigned LineNo,
258 MDScope *Context) {
259 return MDDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name, File,
260 LineNo,
261 MDScopeRef::get(getNonCompileUnitScope(Context)),
262 MDTypeRef::get(Ty), 0, 0, 0, 0);
263 }
264
265 MDDerivedType *DIBuilder::createFriend(MDType *Ty, MDType *FriendTy) {
280266 assert(Ty && "Invalid type!");
281267 assert(FriendTy && "Invalid friend type!");
282268 return MDDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0,
284270 0, 0);
285271 }
286272
287 DIDerivedType DIBuilder::createInheritance(DIType Ty, DIType BaseTy,
288 uint64_t BaseOffset,
289 unsigned Flags) {
273 MDDerivedType *DIBuilder::createInheritance(MDType *Ty, MDType *BaseTy,
274 uint64_t BaseOffset,
275 unsigned Flags) {
290276 assert(Ty && "Unable to create inheritance");
291277 return MDDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr,
292278 0, MDTypeRef::get(Ty), MDTypeRef::get(BaseTy), 0, 0,
293279 BaseOffset, Flags);
294280 }
295281
296 DIDerivedType DIBuilder::createMemberType(DIDescriptor Scope, StringRef Name,
297 DIFile File, unsigned LineNumber,
298 uint64_t SizeInBits,
299 uint64_t AlignInBits,
300 uint64_t OffsetInBits, unsigned Flags,
301 DIType Ty) {
282 MDDerivedType *DIBuilder::createMemberType(MDScope *Scope, StringRef Name,
283 MDFile *File, unsigned LineNumber,
284 uint64_t SizeInBits,
285 uint64_t AlignInBits,
286 uint64_t OffsetInBits,
287 unsigned Flags, MDType *Ty) {
302288 return MDDerivedType::get(
303289 VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
304 MDScopeRef::get(DIScope(getNonCompileUnitScope(Scope))),
305 MDTypeRef::get(Ty), SizeInBits, AlignInBits, OffsetInBits, Flags);
290 MDScopeRef::get(getNonCompileUnitScope(Scope)), MDTypeRef::get(Ty),
291 SizeInBits, AlignInBits, OffsetInBits, Flags);
306292 }
307293
308294 static ConstantAsMetadata *getConstantOrNull(Constant *C) {
311297 return nullptr;
312298 }
313299
314 DIDerivedType DIBuilder::createStaticMemberType(DIDescriptor Scope,
315 StringRef Name, DIFile File,
316 unsigned LineNumber, DIType Ty,
317 unsigned Flags,
318 llvm::Constant *Val) {
319 // TAG_member is encoded in DIDerivedType format.
300 MDDerivedType *DIBuilder::createStaticMemberType(MDScope *Scope, StringRef Name,
301 MDFile *File,
302 unsigned LineNumber,
303 MDType *Ty, unsigned Flags,
304 llvm::Constant *Val) {
320305 Flags |= DebugNode::FlagStaticMember;
321306 return MDDerivedType::get(
322307 VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
323 MDScopeRef::get(DIScope(getNonCompileUnitScope(Scope))),
324 MDTypeRef::get(Ty), 0, 0, 0, Flags, getConstantOrNull(Val));
325 }
326
327 DIDerivedType DIBuilder::createObjCIVar(StringRef Name, DIFile File,
328 unsigned LineNumber,
329 uint64_t SizeInBits,
330 uint64_t AlignInBits,
331 uint64_t OffsetInBits, unsigned Flags,
332 DIType Ty, MDNode *PropertyNode) {
308 MDScopeRef::get(getNonCompileUnitScope(Scope)), MDTypeRef::get(Ty), 0, 0,
309 0, Flags, getConstantOrNull(Val));
310 }
311
312 MDDerivedType *DIBuilder::createObjCIVar(StringRef Name, MDFile *File,
313 unsigned LineNumber,
314 uint64_t SizeInBits,
315 uint64_t AlignInBits,
316 uint64_t OffsetInBits, unsigned Flags,
317 MDType *Ty, MDNode *PropertyNode) {
333318 return MDDerivedType::get(
334319 VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
335320 MDScopeRef::get(getNonCompileUnitScope(File)), MDTypeRef::get(Ty),
336321 SizeInBits, AlignInBits, OffsetInBits, Flags, PropertyNode);
337322 }
338323
339 DIObjCProperty
340 DIBuilder::createObjCProperty(StringRef Name, DIFile File, unsigned LineNumber,
324 MDObjCProperty *
325 DIBuilder::createObjCProperty(StringRef Name, MDFile *File, unsigned LineNumber,
341326 StringRef GetterName, StringRef SetterName,
342 unsigned PropertyAttributes, DIType Ty) {
327 unsigned PropertyAttributes, MDType *Ty) {
343328 return MDObjCProperty::get(VMContext, Name, File, LineNumber, GetterName,
344329 SetterName, PropertyAttributes, Ty);
345330 }
346331
347 DITemplateTypeParameter
348 DIBuilder::createTemplateTypeParameter(DIDescriptor Context, StringRef Name,
349 DIType Ty) {
332 MDTemplateTypeParameter *
333 DIBuilder::createTemplateTypeParameter(MDScope *Context, StringRef Name,
334 MDType *Ty) {
350335 assert((!Context || isa(Context)) && "Expected compile unit");
351336 return MDTemplateTypeParameter::get(VMContext, Name, MDTypeRef::get(Ty));
352337 }
353338
354 static DITemplateValueParameter
339 static MDTemplateValueParameter *
355340 createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag,
356 DIDescriptor Context, StringRef Name,
357 DIType Ty, Metadata *MD) {
341 MDScope *Context, StringRef Name, MDType *Ty,
342 Metadata *MD) {
358343 assert((!Context || isa(Context)) && "Expected compile unit");
359344 return MDTemplateValueParameter::get(VMContext, Tag, Name, MDTypeRef::get(Ty),
360345 MD);
361346 }
362347
363 DITemplateValueParameter
364 DIBuilder::createTemplateValueParameter(DIDescriptor Context, StringRef Name,
365 DIType Ty, Constant *Val) {
348 MDTemplateValueParameter *
349 DIBuilder::createTemplateValueParameter(MDScope *Context, StringRef Name,
350 MDType *Ty, Constant *Val) {
366351 return createTemplateValueParameterHelper(
367352 VMContext, dwarf::DW_TAG_template_value_parameter, Context, Name, Ty,
368353 getConstantOrNull(Val));
369354 }
370355
371 DITemplateValueParameter
372 DIBuilder::createTemplateTemplateParameter(DIDescriptor Context, StringRef Name,
373 DIType Ty, StringRef Val) {
356 MDTemplateValueParameter *
357 DIBuilder::createTemplateTemplateParameter(MDScope *Context, StringRef Name,
358 MDType *Ty, StringRef Val) {
374359 return createTemplateValueParameterHelper(
375360 VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
376361 MDString::get(VMContext, Val));
377362 }
378363
379 DITemplateValueParameter
380 DIBuilder::createTemplateParameterPack(DIDescriptor Context, StringRef Name,
381 DIType Ty, DIArray Val) {
364 MDTemplateValueParameter *
365 DIBuilder::createTemplateParameterPack(MDScope *Context, StringRef Name,
366 MDType *Ty, DIArray Val) {
382367 return createTemplateValueParameterHelper(
383368 VMContext, dwarf::DW_TAG_GNU_template_parameter_pack, Context, Name, Ty,
384369 Val.get());
385370 }
386371
387 DICompositeType DIBuilder::createClassType(DIDescriptor Context, StringRef Name,
388 DIFile File, unsigned LineNumber,
389 uint64_t SizeInBits,
390 uint64_t AlignInBits,
391 uint64_t OffsetInBits,
392 unsigned Flags, DIType DerivedFrom,
393 DIArray Elements,
394 DIType VTableHolder,
395 MDNode *TemplateParams,
396 StringRef UniqueIdentifier) {
372 MDCompositeType *DIBuilder::createClassType(
373 MDScope *Context, StringRef Name, MDFile *File, unsigned LineNumber,
374 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
375 unsigned Flags, MDType *DerivedFrom, DIArray Elements, MDType *VTableHolder,
376 MDNode *TemplateParams, StringRef UniqueIdentifier) {
397377 assert((!Context || isa(Context)) &&
398378 "createClassType should be called with a valid Context");
399 // TAG_class_type is encoded in DICompositeType format.
400 DICompositeType R = MDCompositeType::get(
379
380 auto *R = MDCompositeType::get(
401381 VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
402 MDScopeRef::get(DIScope(getNonCompileUnitScope(Context))),
382 MDScopeRef::get(getNonCompileUnitScope(Context)),
403383 MDTypeRef::get(DerivedFrom), SizeInBits, AlignInBits, OffsetInBits, Flags,
404384 Elements, 0, MDTypeRef::get(VTableHolder),
405385 cast_or_null(TemplateParams), UniqueIdentifier);
409389 return R;
410390 }
411391
412 DICompositeType DIBuilder::createStructType(DIDescriptor Context,
413 StringRef Name, DIFile File,
414 unsigned LineNumber,
415 uint64_t SizeInBits,
416 uint64_t AlignInBits,
417 unsigned Flags, DIType DerivedFrom,
418 DIArray Elements,
419 unsigned RunTimeLang,
420 DIType VTableHolder,
421 StringRef UniqueIdentifier) {
422 DICompositeType R = MDCompositeType::get(
392 MDCompositeType *DIBuilder::createStructType(
393 MDScope *Context, StringRef Name, MDFile *File, unsigned LineNumber,
394 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Flags,
395 MDType *DerivedFrom, DIArray Elements, unsigned RunTimeLang,
396 MDType *VTableHolder, StringRef UniqueIdentifier) {
397 auto *R = MDCompositeType::get(
423398 VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
424 MDScopeRef::get(DIScope(getNonCompileUnitScope(Context))),
399 MDScopeRef::get(getNonCompileUnitScope(Context)),
425400 MDTypeRef::get(DerivedFrom), SizeInBits, AlignInBits, 0, Flags, Elements,
426401 RunTimeLang, MDTypeRef::get(VTableHolder), nullptr, UniqueIdentifier);
427402 if (!UniqueIdentifier.empty())
430405 return R;
431406 }
432407
433 DICompositeType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name,
434 DIFile File, unsigned LineNumber,
408 MDCompositeType* DIBuilder::createUnionType(MDScope * Scope, StringRef Name,
409 MDFile* File, unsigned LineNumber,
435410 uint64_t SizeInBits,
436411 uint64_t AlignInBits, unsigned Flags,
437412 DIArray Elements,
438413 unsigned RunTimeLang,
439414 StringRef UniqueIdentifier) {
440 DICompositeType R = MDCompositeType::get(
415 auto *R = MDCompositeType::get(
441416 VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber,
442 MDScopeRef::get(DIScope(getNonCompileUnitScope(Scope))), nullptr,
443 SizeInBits, AlignInBits, 0, Flags, Elements, RunTimeLang, nullptr,
444 nullptr, UniqueIdentifier);
417 MDScopeRef::get(getNonCompileUnitScope(Scope)), nullptr, SizeInBits,
418 AlignInBits, 0, Flags, Elements, RunTimeLang, nullptr, nullptr,
419 UniqueIdentifier);
445420 if (!UniqueIdentifier.empty())
446421 retainType(R);
447422 trackIfUnresolved(R);
448423 return R;
449424 }
450425
451 DISubroutineType DIBuilder::createSubroutineType(DIFile File,
452 DITypeArray ParameterTypes,
453 unsigned Flags) {
426 MDSubroutineType *DIBuilder::createSubroutineType(MDFile *File,
427 DITypeArray ParameterTypes,
428 unsigned Flags) {
454429 return MDSubroutineType::get(VMContext, Flags, ParameterTypes);
455430 }
456431
457 DICompositeType DIBuilder::createEnumerationType(
458 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
432 MDCompositeType *DIBuilder::createEnumerationType(
433 MDScope *Scope, StringRef Name, MDFile *File, unsigned LineNumber,
459434 uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
460 DIType UnderlyingType, StringRef UniqueIdentifier) {
461 DICompositeType CTy = MDCompositeType::get(
435 MDType *UnderlyingType, StringRef UniqueIdentifier) {
436 auto *CTy = MDCompositeType::get(
462437 VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber,
463 MDScopeRef::get(DIScope(getNonCompileUnitScope(Scope))),
438 MDScopeRef::get(getNonCompileUnitScope(Scope)),
464439 MDTypeRef::get(UnderlyingType), SizeInBits, AlignInBits, 0, 0, Elements,
465440 0, nullptr, nullptr, UniqueIdentifier);
466441 AllEnumTypes.push_back(CTy);
470445 return CTy;
471446 }
472447
473 DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
474 DIType Ty, DIArray Subscripts) {
448 MDCompositeType *DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
449 MDType *Ty, DIArray Subscripts) {
475450 auto *R = MDCompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
476451 nullptr, 0, nullptr, MDTypeRef::get(Ty), Size,
477452 AlignInBits, 0, 0, Subscripts, 0, nullptr);
479454 return R;
480455 }
481456
482 DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits,
483 DIType Ty, DIArray Subscripts) {
457 MDCompositeType *DIBuilder::createVectorType(uint64_t Size,
458 uint64_t AlignInBits, MDType *Ty,
459 DIArray Subscripts) {
484460 auto *R =
485461 MDCompositeType::get(VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0,
486462 nullptr, MDTypeRef::get(Ty), Size, AlignInBits, 0,
489465 return R;
490466 }
491467
492 static DIType createTypeWithFlags(LLVMContext &Context, DIType Ty,
493 unsigned FlagsToSet) {
494 TempMDType NewTy = cast(static_cast(Ty))->clone();
468 static MDType *createTypeWithFlags(LLVMContext &Context, MDType *Ty,
469 unsigned FlagsToSet) {
470 auto NewTy = Ty->clone();
495471 NewTy->setFlags(NewTy->getFlags() | FlagsToSet);
496472 return MDNode::replaceWithUniqued(std::move(NewTy));
497473 }
498474
499 DIType DIBuilder::createArtificialType(DIType Ty) {
475 MDType *DIBuilder::createArtificialType(MDType *Ty) {
500476 // FIXME: Restrict this to the nodes where it's valid.
501477 if (Ty->isArtificial())
502478 return Ty;
503479 return createTypeWithFlags(VMContext, Ty, DebugNode::FlagArtificial);
504480 }
505481
506 DIType DIBuilder::createObjectPointerType(DIType Ty) {
482 MDType *DIBuilder::createObjectPointerType(MDType *Ty) {
507483 // FIXME: Restrict this to the nodes where it's valid.
508484 if (Ty->isObjectPointer())
509485 return Ty;
511487 return createTypeWithFlags(VMContext, Ty, Flags);
512488 }
513489
514 void DIBuilder::retainType(DIType T) {
490 void DIBuilder::retainType(MDType *T) {
515491 assert(T && "Expected non-null type");
516492 AllRetainTypes.emplace_back(T);
517493 }
518494
519 DIBasicType DIBuilder::createUnspecifiedParameter() { return nullptr; }
520
521 DICompositeType
522 DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope,
523 DIFile F, unsigned Line, unsigned RuntimeLang,
495 MDBasicType *DIBuilder::createUnspecifiedParameter() { return nullptr; }
496
497 MDCompositeType*
498 DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, MDScope * Scope,
499 MDFile* F, unsigned Line, unsigned RuntimeLang,
524500 uint64_t SizeInBits, uint64_t AlignInBits,
525501 StringRef UniqueIdentifier) {
526502 // FIXME: Define in terms of createReplaceableForwardDecl() by calling
527503 // replaceWithUniqued().
528 DICompositeType RetTy = MDCompositeType::get(
504 auto *RetTy = MDCompositeType::get(
529505 VMContext, Tag, Name, F, Line,
530 MDScopeRef::get(DIScope(getNonCompileUnitScope(Scope))), nullptr,
531 SizeInBits, AlignInBits, 0, DebugNode::FlagFwdDecl, nullptr, RuntimeLang,
532 nullptr, nullptr, UniqueIdentifier);
506 MDScopeRef::get(getNonCompileUnitScope(Scope)), nullptr, SizeInBits,
507 AlignInBits, 0, DebugNode::FlagFwdDecl, nullptr, RuntimeLang, nullptr,
508 nullptr, UniqueIdentifier);
533509 if (!UniqueIdentifier.empty())
534510 retainType(RetTy);
535511 trackIfUnresolved(RetTy);
536512 return RetTy;
537513 }
538514
539 DICompositeType DIBuilder::createReplaceableCompositeType(
540 unsigned Tag, StringRef Name, DIDescriptor Scope, DIFile F, unsigned Line,
515 MDCompositeType* DIBuilder::createReplaceableCompositeType(
516 unsigned Tag, StringRef Name, MDScope * Scope, MDFile* F, unsigned Line,
541517 unsigned RuntimeLang, uint64_t SizeInBits, uint64_t AlignInBits,
542518 unsigned Flags, StringRef UniqueIdentifier) {
543 DICompositeType RetTy =
544 MDCompositeType::getTemporary(
545 VMContext, Tag, Name, F, Line,
546 MDScopeRef::get(DIScope(getNonCompileUnitScope(Scope))), nullptr,
547 SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, nullptr,
548 nullptr, UniqueIdentifier)
549 .release();
519 auto *RetTy = MDCompositeType::getTemporary(
520 VMContext, Tag, Name, F, Line,
521 MDScopeRef::get(getNonCompileUnitScope(Scope)), nullptr,
522 SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang,
523 nullptr, nullptr, UniqueIdentifier).release();
550524 if (!UniqueIdentifier.empty())
551525 retainType(RetTy);
552526 trackIfUnresolved(RetTy);
554528 }
555529
556530 DIArray DIBuilder::getOrCreateArray(ArrayRef Elements) {
557 return DIArray(MDNode::get(VMContext, Elements));
531 return MDTuple::get(VMContext, Elements);
558532 }
559533
560534 DITypeArray DIBuilder::getOrCreateTypeArray(ArrayRef Elements) {
568542 return DITypeArray(MDNode::get(VMContext, Elts));
569543 }
570544
571 DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
545 MDSubrange *DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
572546 return MDSubrange::get(VMContext, Count, Lo);
573547 }
574548
575 static void checkGlobalVariableScope(DIDescriptor Context) {
549 static void checkGlobalVariableScope(MDScope * Context) {
576550 #ifndef NDEBUG
577551 if (auto *CT =
578552 dyn_cast_or_null(getNonCompileUnitScope(Context)))
581555 #endif
582556 }
583557
584 DIGlobalVariable DIBuilder::createGlobalVariable(
585 DIDescriptor Context, StringRef Name, StringRef LinkageName, DIFile F,
586 unsigned LineNumber, DIType Ty, bool isLocalToUnit, Constant *Val,
558 MDGlobalVariable *DIBuilder::createGlobalVariable(
559 MDScope *Context, StringRef Name, StringRef LinkageName, MDFile *F,
560 unsigned LineNumber, MDType *Ty, bool isLocalToUnit, Constant *Val,
587561 MDNode *Decl) {
588562 checkGlobalVariableScope(Context);
589563
595569 return N;
596570 }
597571
598 DIGlobalVariable DIBuilder::createTempGlobalVariableFwdDecl(
599 DIDescriptor Context, StringRef Name, StringRef LinkageName, DIFile F,
600 unsigned LineNumber, DIType Ty, bool isLocalToUnit, Constant *Val,
572 MDGlobalVariable *DIBuilder::createTempGlobalVariableFwdDecl(
573 MDScope *Context, StringRef Name, StringRef LinkageName, MDFile *F,
574 unsigned LineNumber, MDType *Ty, bool isLocalToUnit, Constant *Val,
601575 MDNode *Decl) {
602576 checkGlobalVariableScope(Context);
603577
608582 .release();
609583 }
610584
611 DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
612 StringRef Name, DIFile File,
613 unsigned LineNo, DIType Ty,
614 bool AlwaysPreserve, unsigned Flags,
615 unsigned ArgNo) {
585 MDLocalVariable *DIBuilder::createLocalVariable(
586 unsigned Tag, MDScope *Scope, StringRef Name, MDFile *File, unsigned LineNo,
587 MDType *Ty, bool AlwaysPreserve, unsigned Flags, unsigned ArgNo) {
616588 // FIXME: Why getNonCompileUnitScope()?
617589 // FIXME: Why is "!Context" okay here?
618590 // FIXME: WHy doesn't this check for a subprogram or lexical block (AFAICT
619591 // the only valid scopes)?
620 DIScope Context = getNonCompileUnitScope(Scope);
592 MDScope* Context = getNonCompileUnitScope(Scope);
621593
622594 auto *Node = MDLocalVariable::get(
623595 VMContext, Tag, cast_or_null(Context), Name, File, LineNo,
626598 // The optimizer may remove local variable. If there is an interest
627599 // to preserve variable info in such situation then stash it in a
628600 // named mdnode.
629 DISubprogram Fn(getDISubprogram(Scope));
601 MDSubprogram *Fn = getDISubprogram(Scope);
630602 assert(Fn && "Missing subprogram for local variable");
631603 PreservedVariables[Fn].emplace_back(Node);
632604 }
633605 return Node;
634606 }
635607
636 DIExpression DIBuilder::createExpression(ArrayRef Addr) {
608 MDExpression* DIBuilder::createExpression(ArrayRef Addr) {
637609 return MDExpression::get(VMContext, Addr);
638610 }
639611
640 DIExpression DIBuilder::createExpression(ArrayRef Signed) {
612 MDExpression* DIBuilder::createExpression(ArrayRef Signed) {
641613 // TODO: Remove the callers of this signed version and delete.
642614 SmallVector Addr(Signed.begin(), Signed.end());
643615 return createExpression(Addr);
644616 }
645617
646 DIExpression DIBuilder::createBitPieceExpression(unsigned OffsetInBytes,
618 MDExpression* DIBuilder::createBitPieceExpression(unsigned OffsetInBytes,
647619 unsigned SizeInBytes) {
648620 uint64_t Addr[] = {dwarf::DW_OP_bit_piece, OffsetInBytes, SizeInBytes};
649621 return MDExpression::get(VMContext, Addr);
650622 }
651623
652 DISubprogram DIBuilder::createFunction(DIScopeRef Context, StringRef Name,
653 StringRef LinkageName, DIFile File,
654 unsigned LineNo, DICompositeType Ty,
624 MDSubprogram* DIBuilder::createFunction(DIScopeRef Context, StringRef Name,
625 StringRef LinkageName, MDFile* File,
626 unsigned LineNo, MDSubroutineType* Ty,
655627 bool isLocalToUnit, bool isDefinition,
656628 unsigned ScopeLine, unsigned Flags,
657629 bool isOptimized, Function *Fn,
664636 Flags, isOptimized, Fn, TParams, Decl);
665637 }
666638
667 DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name,
668 StringRef LinkageName, DIFile File,
669 unsigned LineNo, DICompositeType Ty,
639 MDSubprogram* DIBuilder::createFunction(MDScope * Context, StringRef Name,
640 StringRef LinkageName, MDFile* File,
641 unsigned LineNo, MDSubroutineType* Ty,
670642 bool isLocalToUnit, bool isDefinition,
671643 unsigned ScopeLine, unsigned Flags,
672644 bool isOptimized, Function *Fn,
674646 assert(Ty->getTag() == dwarf::DW_TAG_subroutine_type &&
675647 "function types should be subroutines");
676648 auto *Node = MDSubprogram::get(
677 VMContext, MDScopeRef::get(DIScope(getNonCompileUnitScope(Context))),
678 Name, LinkageName, File, LineNo, cast_or_null(Ty),
649 VMContext, MDScopeRef::get(getNonCompileUnitScope(Context)), Name,
650 LinkageName, File, LineNo, Ty,
679651 isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized,
680652 Fn, cast_or_null(TParams), cast_or_null(Decl),
681653 MDTuple::getTemporary(VMContext, None).release());
686658 return Node;
687659 }
688660
689 DISubprogram
690 DIBuilder::createTempFunctionFwdDecl(DIDescriptor Context, StringRef Name,
691 StringRef LinkageName, DIFile File,
692 unsigned LineNo, DICompositeType Ty,
661 MDSubprogram*
662 DIBuilder::createTempFunctionFwdDecl(MDScope * Context, StringRef Name,
663 StringRef LinkageName, MDFile* File,
664 unsigned LineNo, MDSubroutineType* Ty,
693665 bool isLocalToUnit, bool isDefinition,
694666 unsigned ScopeLine, unsigned Flags,
695667 bool isOptimized, Function *Fn,
696668 MDNode *TParams, MDNode *Decl) {
697669 return MDSubprogram::getTemporary(
698 VMContext,
699 MDScopeRef::get(DIScope(getNonCompileUnitScope(Context))), Name,
700 LinkageName, File, LineNo, cast_or_null(Ty),
670 VMContext, MDScopeRef::get(getNonCompileUnitScope(Context)), Name,
671 LinkageName, File, LineNo, Ty,
701672 isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, Flags,
702673 isOptimized, Fn, cast_or_null(TParams),
703 cast_or_null(Decl), nullptr)
704 .release();
705 }
706
707 DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
708 StringRef LinkageName, DIFile F,
709 unsigned LineNo, DICompositeType Ty,
710 bool isLocalToUnit, bool isDefinition,
711 unsigned VK, unsigned VIndex,
712 DIType VTableHolder, unsigned Flags,
713 bool isOptimized, Function *Fn,
714 MDNode *TParam) {
674 cast_or_null(Decl), nullptr).release();
675 }
676
677 MDSubprogram *
678 DIBuilder::createMethod(MDScope *Context, StringRef Name, StringRef LinkageName,
679 MDFile *F, unsigned LineNo, MDSubroutineType *Ty,
680 bool isLocalToUnit, bool isDefinition, unsigned VK,
681 unsigned VIndex, MDType *VTableHolder, unsigned Flags,
682 bool isOptimized, Function *Fn, MDNode *TParam) {
715683 assert(Ty->getTag() == dwarf::DW_TAG_subroutine_type &&
716684 "function types should be subroutines");
717685 assert(getNonCompileUnitScope(Context) &&
720688 // FIXME: Do we want to use different scope/lines?
721689 auto *SP = MDSubprogram::get(
722690 VMContext, MDScopeRef::get(cast(Context)), Name, LinkageName, F,
723 LineNo, cast_or_null(Ty), isLocalToUnit, isDefinition,
724 LineNo, MDTypeRef::get(VTableHolder), VK, VIndex, Flags, isOptimized, Fn,
691 LineNo, Ty, isLocalToUnit, isDefinition, LineNo,
692 MDTypeRef::get(VTableHolder), VK, VIndex, Flags, isOptimized, Fn,
725693 cast_or_null(TParam), nullptr, nullptr);
726694
727695 if (isDefinition)
730698 return SP;
731699 }
732700
733 DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
734 DIFile File, unsigned LineNo) {
701 MDNamespace* DIBuilder::createNameSpace(MDScope * Scope, StringRef Name,
702 MDFile* File, unsigned LineNo) {
735703 return MDNamespace::get(VMContext, getNonCompileUnitScope(Scope), File, Name,
736704 LineNo);
737705 }
738706
739 DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
740 DIFile File,
707 MDLexicalBlockFile* DIBuilder::createLexicalBlockFile(MDScope * Scope,
708 MDFile* File,
741709 unsigned Discriminator) {
742710 return MDLexicalBlockFile::get(VMContext, Scope, File, Discriminator);
743711 }
744712
745 DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
713 MDLexicalBlock* DIBuilder::createLexicalBlock(MDScope * Scope, MDFile* File,
746714 unsigned Line, unsigned Col) {
747715 // Make these distinct, to avoid merging two lexical blocks on the same
748716 // file/line/column.
760728 return I;
761729 }
762730
763 Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
764 DIExpression Expr, const MDLocation *DL,
731 Instruction *DIBuilder::insertDeclare(Value *Storage, MDLocalVariable* VarInfo,
732 MDExpression* Expr, const MDLocation *DL,
765733 Instruction *InsertBefore) {
766 assert(VarInfo && "empty or invalid DIVariable passed to dbg.declare");
734 assert(VarInfo && "empty or invalid MDLocalVariable* passed to dbg.declare");
767735 assert(DL && "Expected debug loc");
768736 assert(DL->getScope()->getSubprogram() ==
769737 VarInfo->getScope()->getSubprogram() &&
779747 return withDebugLoc(CallInst::Create(DeclareFn, Args, "", InsertBefore), DL);
780748 }
781749
782 Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
783 DIExpression Expr, const MDLocation *DL,
750 Instruction *DIBuilder::insertDeclare(Value *Storage, MDLocalVariable* VarInfo,
751 MDExpression* Expr, const MDLocation *DL,
784752 BasicBlock *InsertAtEnd) {
785 assert(VarInfo && "empty or invalid DIVariable passed to dbg.declare");
753 assert(VarInfo && "empty or invalid MDLocalVariable* passed to dbg.declare");
786754 assert(DL && "Expected debug loc");
787755 assert(DL->getScope()->getSubprogram() ==
788756 VarInfo->getScope()->getSubprogram() &&
804772 }
805773
806774 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
807 DIVariable VarInfo,
808 DIExpression Expr,
775 MDLocalVariable* VarInfo,
776 MDExpression* Expr,
809777 const MDLocation *DL,
810778 Instruction *InsertBefore) {
811779 assert(V && "no value passed to dbg.value");
812 assert(VarInfo && "empty or invalid DIVariable passed to dbg.value");
780 assert(VarInfo && "empty or invalid MDLocalVariable* passed to dbg.value");
813781 assert(DL && "Expected debug loc");
814782 assert(DL->getScope()->getSubprogram() ==
815783 VarInfo->getScope()->getSubprogram() &&
827795 }
828796
829797 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
830 DIVariable VarInfo,
831 DIExpression Expr,
798 MDLocalVariable* VarInfo,
799 MDExpression* Expr,
832800 const MDLocation *DL,
833801 BasicBlock *InsertAtEnd) {
834802 assert(V && "no value passed to dbg.value");
835 assert(VarInfo && "empty or invalid DIVariable passed to dbg.value");
803 assert(VarInfo && "empty or invalid MDLocalVariable* passed to dbg.value");
836804 assert(DL && "Expected debug loc");
837805 assert(DL->getScope()->getSubprogram() ==
838806 VarInfo->getScope()->getSubprogram() &&
850818 return withDebugLoc(CallInst::Create(ValueFn, Args, "", InsertAtEnd), DL);
851819 }
852820
853 void DIBuilder::replaceVTableHolder(DICompositeType &T, DICompositeType VTableHolder) {
821 void DIBuilder::replaceVTableHolder(MDCompositeType* &T, MDCompositeType* VTableHolder) {
854822 {
855 TypedTrackingMDRefBase> N(T);
823 TypedTrackingMDRef> N(T);
856824 N->replaceVTableHolder(MDTypeRef::get(VTableHolder));
857825 T = N.get();
858826 }
869837 trackIfUnresolved(N);
870838 }
871839
872 void DIBuilder::replaceArrays(DICompositeType &T, DIArray Elements,
840 void DIBuilder::replaceArrays(MDCompositeType* &T, DIArray Elements,
873841 DIArray TParams) {
874842 {
875 TypedTrackingMDRefBase> N(T);
843 TypedTrackingMDRef> N(T);
876844 if (Elements)
877845 N->replaceElements(Elements);
878846 if (TParams)
229229 // Function DI
230230 DIFile File = DBuilder.createFile("filename.c", "/file/dir/");
231231 DITypeArray ParamTypes = DBuilder.getOrCreateTypeArray(None);
232 DICompositeType FuncType = DBuilder.createSubroutineType(File, ParamTypes);
232 MDSubroutineType *FuncType =
233 DBuilder.createSubroutineType(File, ParamTypes);
233234 DICompileUnit CU = DBuilder.createCompileUnit(dwarf::DW_LANG_C99,
234235 "filename.c", "/file/dir", "CloneFunc", false, "", 0);
235236