1 //===--- DIBuilder.cpp - Debug Information Builder ------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the DIBuilder.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/DIBuilder.h"
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/DebugInfo.h"
17 #include "llvm/IR/Constants.h"
18 #include "llvm/IR/IntrinsicInst.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/Support/Debug.h"
21 #include "llvm/Support/Dwarf.h"
24 using namespace llvm::dwarf;
26 static Constant *GetTagConstant(LLVMContext &VMContext, unsigned Tag) {
27 assert((Tag & LLVMDebugVersionMask) == 0 &&
28 "Tag too large for debug encoding!");
29 return ConstantInt::get(Type::getInt32Ty(VMContext), Tag | LLVMDebugVersion);
32 DIBuilder::DIBuilder(Module &m)
33 : M(m), VMContext(M.getContext()), TempEnumTypes(0), TempRetainTypes(0),
34 TempSubprograms(0), TempGVs(0), DeclareFn(0), ValueFn(0) {}
36 /// finalize - Construct any deferred debug info descriptors.
37 void DIBuilder::finalize() {
38 DIArray Enums = getOrCreateArray(AllEnumTypes);
39 DIType(TempEnumTypes).replaceAllUsesWith(Enums);
41 SmallVector<Value *, 16> RetainValues;
42 // Declarations and definitions of the same type may be retained. Some
43 // clients RAUW these pairs, leaving duplicates in the retained types
44 // list. Use a set to remove the duplicates while we transform the
45 // TrackingVHs back into Values.
46 SmallPtrSet<Value *, 16> RetainSet;
47 for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++)
48 if (RetainSet.insert(AllRetainTypes[I]))
49 RetainValues.push_back(AllRetainTypes[I]);
50 DIArray RetainTypes = getOrCreateArray(RetainValues);
51 DIType(TempRetainTypes).replaceAllUsesWith(RetainTypes);
53 DIArray SPs = getOrCreateArray(AllSubprograms);
54 DIType(TempSubprograms).replaceAllUsesWith(SPs);
55 for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
56 DISubprogram SP(SPs.getElement(i));
57 SmallVector<Value *, 4> Variables;
58 if (NamedMDNode *NMD = getFnSpecificMDNode(M, SP)) {
59 for (unsigned ii = 0, ee = NMD->getNumOperands(); ii != ee; ++ii)
60 Variables.push_back(NMD->getOperand(ii));
61 NMD->eraseFromParent();
63 if (MDNode *Temp = SP.getVariablesNodes()) {
64 DIArray AV = getOrCreateArray(Variables);
65 DIType(Temp).replaceAllUsesWith(AV);
69 DIArray GVs = getOrCreateArray(AllGVs);
70 DIType(TempGVs).replaceAllUsesWith(GVs);
72 DIArray IMs = getOrCreateArray(AllImportedModules);
73 DIType(TempImportedModules).replaceAllUsesWith(IMs);
76 /// getNonCompileUnitScope - If N is compile unit return NULL otherwise return
78 static MDNode *getNonCompileUnitScope(MDNode *N) {
79 if (DIDescriptor(N).isCompileUnit())
84 static MDNode *createFilePathPair(LLVMContext &VMContext, StringRef Filename,
85 StringRef Directory) {
86 assert(!Filename.empty() && "Unable to create file without name");
88 MDString::get(VMContext, Filename),
89 MDString::get(VMContext, Directory)
91 return MDNode::get(VMContext, Pair);
94 /// createCompileUnit - A CompileUnit provides an anchor for all debugging
95 /// information generated during this instance of compilation.
96 DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename,
98 StringRef Producer, bool isOptimized,
99 StringRef Flags, unsigned RunTimeVer,
101 DebugEmissionKind Kind) {
103 assert(((Lang <= dwarf::DW_LANG_Python && Lang >= dwarf::DW_LANG_C89) ||
104 (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
105 "Invalid Language tag");
106 assert(!Filename.empty() &&
107 "Unable to create compile unit without filename");
108 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
109 TempEnumTypes = MDNode::getTemporary(VMContext, TElts);
111 TempRetainTypes = MDNode::getTemporary(VMContext, TElts);
113 TempSubprograms = MDNode::getTemporary(VMContext, TElts);
115 TempGVs = MDNode::getTemporary(VMContext, TElts);
117 TempImportedModules = MDNode::getTemporary(VMContext, TElts);
120 GetTagConstant(VMContext, dwarf::DW_TAG_compile_unit),
121 createFilePathPair(VMContext, Filename, Directory),
122 ConstantInt::get(Type::getInt32Ty(VMContext), Lang),
123 MDString::get(VMContext, Producer),
124 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
125 MDString::get(VMContext, Flags),
126 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer),
132 MDString::get(VMContext, SplitName),
133 ConstantInt::get(Type::getInt32Ty(VMContext), Kind)
136 MDNode *CUNode = MDNode::get(VMContext, Elts);
138 // Create a named metadata so that it is easier to find cu in a module.
139 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
140 NMD->addOperand(CUNode);
142 return DICompileUnit(CUNode);
145 static DIImportedEntity
146 createImportedModule(LLVMContext &C, DIScope Context, DIDescriptor NS,
147 unsigned Line, StringRef Name,
148 SmallVectorImpl<Value *> &AllImportedModules) {
152 GetTagConstant(C, dwarf::DW_TAG_imported_module),
155 ConstantInt::get(Type::getInt32Ty(C), Line),
157 R = MDNode::get(C, Elts);
160 GetTagConstant(C, dwarf::DW_TAG_imported_module),
163 ConstantInt::get(Type::getInt32Ty(C), Line),
164 MDString::get(C, Name)
166 R = MDNode::get(C, Elts);
168 DIImportedEntity M(R);
169 assert(M.Verify() && "Imported module should be valid");
170 AllImportedModules.push_back(M);
174 DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
175 DINameSpace NS, unsigned Line,
177 return ::createImportedModule(VMContext, Context, NS, Line, Name,
181 DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
185 return ::createImportedModule(VMContext, Context, NS, Line, Name,
189 DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
193 GetTagConstant(VMContext, dwarf::DW_TAG_imported_declaration),
196 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
198 DIImportedEntity M(MDNode::get(VMContext, Elts));
199 assert(M.Verify() && "Imported module should be valid");
200 AllImportedModules.push_back(M);
204 /// createFile - Create a file descriptor to hold debugging information
206 DIFile DIBuilder::createFile(StringRef Filename, StringRef Directory) {
208 GetTagConstant(VMContext, dwarf::DW_TAG_file_type),
209 createFilePathPair(VMContext, Filename, Directory)
211 return DIFile(MDNode::get(VMContext, Elts));
214 /// createEnumerator - Create a single enumerator value.
215 DIEnumerator DIBuilder::createEnumerator(StringRef Name, int64_t Val) {
216 assert(!Name.empty() && "Unable to create enumerator without name");
218 GetTagConstant(VMContext, dwarf::DW_TAG_enumerator),
219 MDString::get(VMContext, Name),
220 ConstantInt::get(Type::getInt64Ty(VMContext), Val)
222 return DIEnumerator(MDNode::get(VMContext, Elts));
225 /// \brief Create a DWARF unspecified type.
226 DIBasicType DIBuilder::createUnspecifiedType(StringRef Name) {
227 assert(!Name.empty() && "Unable to create type without name");
228 // Unspecified types are encoded in DIBasicType format. Line number, filename,
229 // size, alignment, offset and flags are always empty here.
231 GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_type),
234 MDString::get(VMContext, Name),
235 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
236 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
237 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
238 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
239 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
240 ConstantInt::get(Type::getInt32Ty(VMContext), 0) // Encoding
242 return DIBasicType(MDNode::get(VMContext, Elts));
245 /// \brief Create C++11 nullptr type.
246 DIBasicType DIBuilder::createNullPtrType() {
247 return createUnspecifiedType("decltype(nullptr)");
250 /// createBasicType - Create debugging information entry for a basic
251 /// type, e.g 'char'.
253 DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
254 uint64_t AlignInBits, unsigned Encoding) {
255 assert(!Name.empty() && "Unable to create type without name");
256 // Basic types are encoded in DIBasicType format. Line number, filename,
257 // offset and flags are always empty here.
259 GetTagConstant(VMContext, dwarf::DW_TAG_base_type),
260 NULL, // File/directory name
262 MDString::get(VMContext, Name),
263 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
264 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
265 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
266 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
267 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
268 ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
270 return DIBasicType(MDNode::get(VMContext, Elts));
273 /// createQualifiedType - Create debugging information entry for a qualified
274 /// type, e.g. 'const int'.
275 DIDerivedType DIBuilder::createQualifiedType(unsigned Tag, DIType FromTy) {
276 // Qualified types are encoded in DIDerivedType format.
278 GetTagConstant(VMContext, Tag),
281 MDString::get(VMContext, StringRef()), // Empty name.
282 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
283 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
284 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
285 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
286 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
289 return DIDerivedType(MDNode::get(VMContext, Elts));
292 /// createPointerType - Create debugging information entry for a pointer.
294 DIBuilder::createPointerType(DIType PointeeTy, uint64_t SizeInBits,
295 uint64_t AlignInBits, StringRef Name) {
296 // Pointer types are encoded in DIDerivedType format.
298 GetTagConstant(VMContext, dwarf::DW_TAG_pointer_type),
301 MDString::get(VMContext, Name),
302 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
303 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
304 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
305 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
306 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
309 return DIDerivedType(MDNode::get(VMContext, Elts));
312 DIDerivedType DIBuilder::createMemberPointerType(DIType PointeeTy,
314 // Pointer types are encoded in DIDerivedType format.
316 GetTagConstant(VMContext, dwarf::DW_TAG_ptr_to_member_type),
320 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
321 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
322 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
323 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
324 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
328 return DIDerivedType(MDNode::get(VMContext, Elts));
331 /// createReferenceType - Create debugging information entry for a reference
333 DIDerivedType DIBuilder::createReferenceType(unsigned Tag, DIType RTy) {
334 assert(RTy.isType() && "Unable to create reference type");
335 // References are encoded in DIDerivedType format.
337 GetTagConstant(VMContext, Tag),
341 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
342 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
343 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
344 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
345 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
348 return DIDerivedType(MDNode::get(VMContext, Elts));
351 /// createTypedef - Create debugging information entry for a typedef.
352 DIDerivedType DIBuilder::createTypedef(DIType Ty, StringRef Name, DIFile File,
353 unsigned LineNo, DIDescriptor Context) {
354 // typedefs are encoded in DIDerivedType format.
355 assert(Ty.isType() && "Invalid typedef type!");
357 GetTagConstant(VMContext, dwarf::DW_TAG_typedef),
359 DIScope(getNonCompileUnitScope(Context)).getRef(),
360 MDString::get(VMContext, Name),
361 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
362 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
363 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
364 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
365 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
368 return DIDerivedType(MDNode::get(VMContext, Elts));
371 /// createFriend - Create debugging information entry for a 'friend'.
372 DIDerivedType DIBuilder::createFriend(DIType Ty, DIType FriendTy) {
373 // typedefs are encoded in DIDerivedType format.
374 assert(Ty.isType() && "Invalid type!");
375 assert(FriendTy.isType() && "Invalid friend type!");
377 GetTagConstant(VMContext, dwarf::DW_TAG_friend),
381 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
382 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
383 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
384 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
385 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
388 return DIDerivedType(MDNode::get(VMContext, Elts));
391 /// createInheritance - Create debugging information entry to establish
392 /// inheritance relationship between two types.
393 DIDerivedType DIBuilder::createInheritance(DIType Ty, DIType BaseTy,
396 assert(Ty.isType() && "Unable to create inheritance");
397 // TAG_inheritance is encoded in DIDerivedType format.
399 GetTagConstant(VMContext, dwarf::DW_TAG_inheritance),
403 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
404 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
405 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
406 ConstantInt::get(Type::getInt64Ty(VMContext), BaseOffset),
407 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
410 return DIDerivedType(MDNode::get(VMContext, Elts));
413 /// createMemberType - Create debugging information entry for a member.
414 DIDerivedType DIBuilder::createMemberType(DIDescriptor Scope, StringRef Name,
415 DIFile File, unsigned LineNumber,
417 uint64_t AlignInBits,
418 uint64_t OffsetInBits, unsigned Flags,
420 // TAG_member is encoded in DIDerivedType format.
422 GetTagConstant(VMContext, dwarf::DW_TAG_member),
424 DIScope(getNonCompileUnitScope(Scope)).getRef(),
425 MDString::get(VMContext, Name),
426 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
427 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
428 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
429 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
430 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
433 return DIDerivedType(MDNode::get(VMContext, Elts));
436 /// createStaticMemberType - Create debugging information entry for a
437 /// C++ static data member.
439 DIBuilder::createStaticMemberType(DIDescriptor Scope, StringRef Name,
440 DIFile File, unsigned LineNumber,
441 DIType Ty, unsigned Flags,
443 // TAG_member is encoded in DIDerivedType format.
444 Flags |= DIDescriptor::FlagStaticMember;
446 GetTagConstant(VMContext, dwarf::DW_TAG_member),
448 DIScope(getNonCompileUnitScope(Scope)).getRef(),
449 MDString::get(VMContext, Name),
450 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
451 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
452 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
453 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
454 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
458 return DIDerivedType(MDNode::get(VMContext, Elts));
461 /// createObjCIVar - Create debugging information entry for Objective-C
462 /// instance variable.
464 DIBuilder::createObjCIVar(StringRef Name, DIFile File, unsigned LineNumber,
465 uint64_t SizeInBits, uint64_t AlignInBits,
466 uint64_t OffsetInBits, unsigned Flags, DIType Ty,
467 StringRef PropertyName, StringRef GetterName,
468 StringRef SetterName, unsigned PropertyAttributes) {
469 // TAG_member is encoded in DIDerivedType format.
471 GetTagConstant(VMContext, dwarf::DW_TAG_member),
473 getNonCompileUnitScope(File),
474 MDString::get(VMContext, Name),
475 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
476 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
477 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
478 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
479 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
481 MDString::get(VMContext, PropertyName),
482 MDString::get(VMContext, GetterName),
483 MDString::get(VMContext, SetterName),
484 ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes)
486 return DIDerivedType(MDNode::get(VMContext, Elts));
489 /// createObjCIVar - Create debugging information entry for Objective-C
490 /// instance variable.
491 DIDerivedType DIBuilder::createObjCIVar(StringRef Name, DIFile File,
494 uint64_t AlignInBits,
495 uint64_t OffsetInBits, unsigned Flags,
496 DIType Ty, MDNode *PropertyNode) {
497 // TAG_member is encoded in DIDerivedType format.
499 GetTagConstant(VMContext, dwarf::DW_TAG_member),
501 getNonCompileUnitScope(File),
502 MDString::get(VMContext, Name),
503 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
504 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
505 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
506 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
507 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
511 return DIDerivedType(MDNode::get(VMContext, Elts));
514 /// createObjCProperty - Create debugging information entry for Objective-C
517 DIBuilder::createObjCProperty(StringRef Name, DIFile File, unsigned LineNumber,
518 StringRef GetterName, StringRef SetterName,
519 unsigned PropertyAttributes, DIType Ty) {
521 GetTagConstant(VMContext, dwarf::DW_TAG_APPLE_property),
522 MDString::get(VMContext, Name),
524 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
525 MDString::get(VMContext, GetterName),
526 MDString::get(VMContext, SetterName),
527 ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes),
530 return DIObjCProperty(MDNode::get(VMContext, Elts));
533 /// createTemplateTypeParameter - Create debugging information for template
535 DITemplateTypeParameter
536 DIBuilder::createTemplateTypeParameter(DIDescriptor Context, StringRef Name,
537 DIType Ty, MDNode *File, unsigned LineNo,
540 GetTagConstant(VMContext, dwarf::DW_TAG_template_type_parameter),
541 DIScope(getNonCompileUnitScope(Context)).getRef(),
542 MDString::get(VMContext, Name),
545 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
546 ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo)
548 return DITemplateTypeParameter(MDNode::get(VMContext, Elts));
551 DITemplateValueParameter
552 DIBuilder::createTemplateValueParameter(unsigned Tag, DIDescriptor Context,
553 StringRef Name, DIType Ty,
554 Value *Val, MDNode *File,
558 GetTagConstant(VMContext, Tag),
559 DIScope(getNonCompileUnitScope(Context)).getRef(),
560 MDString::get(VMContext, Name),
564 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
565 ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo)
567 return DITemplateValueParameter(MDNode::get(VMContext, Elts));
570 /// createTemplateValueParameter - Create debugging information for template
572 DITemplateValueParameter
573 DIBuilder::createTemplateValueParameter(DIDescriptor Context, StringRef Name,
574 DIType Ty, Value *Val,
575 MDNode *File, unsigned LineNo,
577 return createTemplateValueParameter(dwarf::DW_TAG_template_value_parameter,
578 Context, Name, Ty, Val, File, LineNo,
582 DITemplateValueParameter
583 DIBuilder::createTemplateTemplateParameter(DIDescriptor Context, StringRef Name,
584 DIType Ty, StringRef Val,
585 MDNode *File, unsigned LineNo,
587 return createTemplateValueParameter(
588 dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
589 MDString::get(VMContext, Val), File, LineNo, ColumnNo);
592 DITemplateValueParameter
593 DIBuilder::createTemplateParameterPack(DIDescriptor Context, StringRef Name,
594 DIType Ty, DIArray Val,
595 MDNode *File, unsigned LineNo,
597 return createTemplateValueParameter(dwarf::DW_TAG_GNU_template_parameter_pack,
598 Context, Name, Ty, Val, File, LineNo,
602 /// createClassType - Create debugging information entry for a class.
603 DICompositeType DIBuilder::createClassType(DIDescriptor Context, StringRef Name,
604 DIFile File, unsigned LineNumber,
606 uint64_t AlignInBits,
607 uint64_t OffsetInBits,
608 unsigned Flags, DIType DerivedFrom,
611 MDNode *TemplateParams,
612 StringRef UniqueIdentifier) {
613 assert((!Context || Context.isScope() || Context.isType()) &&
614 "createClassType should be called with a valid Context");
615 // TAG_class_type is encoded in DICompositeType format.
617 GetTagConstant(VMContext, dwarf::DW_TAG_class_type),
619 DIScope(getNonCompileUnitScope(Context)).getRef(),
620 MDString::get(VMContext, Name),
621 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
622 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
623 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
624 ConstantInt::get(Type::getInt32Ty(VMContext), OffsetInBits),
625 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
626 DerivedFrom.getRef(),
628 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
629 VTableHolder.getRef(),
631 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
633 DICompositeType R(MDNode::get(VMContext, Elts));
634 assert(R.isCompositeType() &&
635 "createClassType should return a DICompositeType");
636 if (!UniqueIdentifier.empty())
641 /// createStructType - Create debugging information entry for a struct.
642 DICompositeType DIBuilder::createStructType(DIDescriptor Context,
643 StringRef Name, DIFile File,
646 uint64_t AlignInBits,
647 unsigned Flags, DIType DerivedFrom,
649 unsigned RunTimeLang,
651 StringRef UniqueIdentifier) {
652 // TAG_structure_type is encoded in DICompositeType format.
654 GetTagConstant(VMContext, dwarf::DW_TAG_structure_type),
656 DIScope(getNonCompileUnitScope(Context)).getRef(),
657 MDString::get(VMContext, Name),
658 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
659 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
660 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
661 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
662 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
663 DerivedFrom.getRef(),
665 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
666 VTableHolder.getRef(),
668 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
670 DICompositeType R(MDNode::get(VMContext, Elts));
671 assert(R.isCompositeType() &&
672 "createStructType should return a DICompositeType");
673 if (!UniqueIdentifier.empty())
678 /// createUnionType - Create debugging information entry for an union.
679 DICompositeType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name,
680 DIFile File, unsigned LineNumber,
682 uint64_t AlignInBits, unsigned Flags,
684 unsigned RunTimeLang,
685 StringRef UniqueIdentifier) {
686 // TAG_union_type is encoded in DICompositeType format.
688 GetTagConstant(VMContext, dwarf::DW_TAG_union_type),
690 DIScope(getNonCompileUnitScope(Scope)).getRef(),
691 MDString::get(VMContext, Name),
692 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
693 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
694 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
695 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
696 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
699 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
702 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
704 DICompositeType R(MDNode::get(VMContext, Elts));
705 if (!UniqueIdentifier.empty())
710 /// createSubroutineType - Create subroutine type.
711 DICompositeType DIBuilder::createSubroutineType(DIFile File,
712 DIArray ParameterTypes,
714 // TAG_subroutine_type is encoded in DICompositeType format.
716 GetTagConstant(VMContext, dwarf::DW_TAG_subroutine_type),
717 Constant::getNullValue(Type::getInt32Ty(VMContext)),
719 MDString::get(VMContext, ""),
720 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
721 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
722 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
723 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
724 ConstantInt::get(Type::getInt32Ty(VMContext), Flags), // Flags
727 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
730 NULL // Type Identifer
732 return DICompositeType(MDNode::get(VMContext, Elts));
735 /// createEnumerationType - Create debugging information entry for an
737 DICompositeType DIBuilder::createEnumerationType(
738 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
739 uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
740 DIType UnderlyingType, StringRef UniqueIdentifier) {
741 // TAG_enumeration_type is encoded in DICompositeType format.
743 GetTagConstant(VMContext, dwarf::DW_TAG_enumeration_type),
745 DIScope(getNonCompileUnitScope(Scope)).getRef(),
746 MDString::get(VMContext, Name),
747 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
748 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
749 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
750 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
751 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
752 UnderlyingType.getRef(),
754 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
757 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
759 DICompositeType CTy(MDNode::get(VMContext, Elts));
760 AllEnumTypes.push_back(CTy);
761 if (!UniqueIdentifier.empty())
766 /// createArrayType - Create debugging information entry for an array.
767 DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
768 DIType Ty, DIArray Subscripts) {
769 // TAG_array_type is encoded in DICompositeType format.
771 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
772 NULL, // Filename/Directory,
774 MDString::get(VMContext, ""),
775 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
776 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
777 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
778 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
779 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
782 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
785 NULL // Type Identifer
787 return DICompositeType(MDNode::get(VMContext, Elts));
790 /// createVectorType - Create debugging information entry for a vector.
791 DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits,
792 DIType Ty, DIArray Subscripts) {
793 // A vector is an array type with the FlagVector flag applied.
795 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
796 NULL, // Filename/Directory,
798 MDString::get(VMContext, ""),
799 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
800 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
801 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
802 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
803 ConstantInt::get(Type::getInt32Ty(VMContext), DIType::FlagVector),
806 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
809 NULL // Type Identifer
811 return DICompositeType(MDNode::get(VMContext, Elts));
814 /// createArtificialType - Create a new DIType with "artificial" flag set.
815 DIType DIBuilder::createArtificialType(DIType Ty) {
816 if (Ty.isArtificial())
819 SmallVector<Value *, 9> Elts;
821 assert (N && "Unexpected input DIType!");
822 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
823 Elts.push_back(N->getOperand(i));
825 unsigned CurFlags = Ty.getFlags();
826 CurFlags = CurFlags | DIType::FlagArtificial;
828 // Flags are stored at this slot.
829 // FIXME: Add an enum for this magic value.
830 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
832 return DIType(MDNode::get(VMContext, Elts));
835 /// createObjectPointerType - Create a new type with both the object pointer
836 /// and artificial flags set.
837 DIType DIBuilder::createObjectPointerType(DIType Ty) {
838 if (Ty.isObjectPointer())
841 SmallVector<Value *, 9> Elts;
843 assert (N && "Unexpected input DIType!");
844 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
845 Elts.push_back(N->getOperand(i));
847 unsigned CurFlags = Ty.getFlags();
848 CurFlags = CurFlags | (DIType::FlagObjectPointer | DIType::FlagArtificial);
850 // Flags are stored at this slot.
851 // FIXME: Add an enum for this magic value.
852 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
854 return DIType(MDNode::get(VMContext, Elts));
857 /// retainType - Retain DIType in a module even if it is not referenced
858 /// through debug info anchors.
859 void DIBuilder::retainType(DIType T) {
860 AllRetainTypes.push_back(TrackingVH<MDNode>(T));
863 /// createUnspecifiedParameter - Create unspeicified type descriptor
864 /// for the subroutine type.
865 DIDescriptor DIBuilder::createUnspecifiedParameter() {
867 GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_parameters)
869 return DIDescriptor(MDNode::get(VMContext, Elts));
872 /// createForwardDecl - Create a temporary forward-declared type that
873 /// can be RAUW'd if the full type is seen.
875 DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope,
876 DIFile F, unsigned Line, unsigned RuntimeLang,
877 uint64_t SizeInBits, uint64_t AlignInBits,
878 StringRef UniqueIdentifier) {
879 // Create a temporary MDNode.
881 GetTagConstant(VMContext, Tag),
883 DIScope(getNonCompileUnitScope(Scope)).getRef(),
884 MDString::get(VMContext, Name),
885 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
886 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
887 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
888 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
889 ConstantInt::get(Type::getInt32Ty(VMContext), DIDescriptor::FlagFwdDecl),
892 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang),
894 NULL, //TemplateParams
895 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
897 MDNode *Node = MDNode::getTemporary(VMContext, Elts);
898 DICompositeType RetTy(Node);
899 assert(RetTy.isCompositeType() &&
900 "createForwardDecl result should be a DIType");
901 if (!UniqueIdentifier.empty())
906 /// getOrCreateArray - Get a DIArray, create one if required.
907 DIArray DIBuilder::getOrCreateArray(ArrayRef<Value *> Elements) {
908 return DIArray(MDNode::get(VMContext, Elements));
911 /// getOrCreateSubrange - Create a descriptor for a value range. This
912 /// implicitly uniques the values returned.
913 DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
915 GetTagConstant(VMContext, dwarf::DW_TAG_subrange_type),
916 ConstantInt::get(Type::getInt64Ty(VMContext), Lo),
917 ConstantInt::get(Type::getInt64Ty(VMContext), Count)
920 return DISubrange(MDNode::get(VMContext, Elts));
923 /// \brief Create a new descriptor for the specified global.
924 DIGlobalVariable DIBuilder::createGlobalVariable(StringRef Name,
925 StringRef LinkageName,
926 DIFile F, unsigned LineNumber,
927 DIType Ty, bool isLocalToUnit,
930 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
931 Constant::getNullValue(Type::getInt32Ty(VMContext)),
933 MDString::get(VMContext, Name),
934 MDString::get(VMContext, Name),
935 MDString::get(VMContext, LinkageName),
937 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
939 ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
940 ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
944 MDNode *Node = MDNode::get(VMContext, Elts);
945 AllGVs.push_back(Node);
946 return DIGlobalVariable(Node);
949 /// \brief Create a new descriptor for the specified global.
950 DIGlobalVariable DIBuilder::createGlobalVariable(StringRef Name, DIFile F,
951 unsigned LineNumber, DIType Ty,
954 return createGlobalVariable(Name, Name, F, LineNumber, Ty, isLocalToUnit,
958 /// createStaticVariable - Create a new descriptor for the specified static
960 DIGlobalVariable DIBuilder::createStaticVariable(DIDescriptor Context,
962 StringRef LinkageName,
963 DIFile F, unsigned LineNumber,
964 DIType Ty, bool isLocalToUnit,
965 Value *Val, MDNode *Decl) {
967 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
968 Constant::getNullValue(Type::getInt32Ty(VMContext)),
969 getNonCompileUnitScope(Context),
970 MDString::get(VMContext, Name),
971 MDString::get(VMContext, Name),
972 MDString::get(VMContext, LinkageName),
974 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
976 ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
977 ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
981 MDNode *Node = MDNode::get(VMContext, Elts);
982 AllGVs.push_back(Node);
983 return DIGlobalVariable(Node);
986 /// createVariable - Create a new descriptor for the specified variable.
987 DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
988 StringRef Name, DIFile File,
989 unsigned LineNo, DIType Ty,
990 bool AlwaysPreserve, unsigned Flags,
992 DIDescriptor Context(getNonCompileUnitScope(Scope));
993 assert((!Context || Context.isScope()) &&
994 "createLocalVariable should be called with a valid Context");
995 assert(Ty.isType() &&
996 "createLocalVariable should be called with a valid type");
998 GetTagConstant(VMContext, Tag),
999 getNonCompileUnitScope(Scope),
1000 MDString::get(VMContext, Name),
1002 ConstantInt::get(Type::getInt32Ty(VMContext), (LineNo | (ArgNo << 24))),
1004 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1005 Constant::getNullValue(Type::getInt32Ty(VMContext))
1007 MDNode *Node = MDNode::get(VMContext, Elts);
1008 if (AlwaysPreserve) {
1009 // The optimizer may remove local variable. If there is an interest
1010 // to preserve variable info in such situation then stash it in a
1012 DISubprogram Fn(getDISubprogram(Scope));
1013 NamedMDNode *FnLocals = getOrInsertFnSpecificMDNode(M, Fn);
1014 FnLocals->addOperand(Node);
1016 DIVariable RetVar(Node);
1017 assert(RetVar.isVariable() &&
1018 "createLocalVariable should return a valid DIVariable");
1022 /// createComplexVariable - Create a new descriptor for the specified variable
1023 /// which has a complex address expression for its address.
1024 DIVariable DIBuilder::createComplexVariable(unsigned Tag, DIDescriptor Scope,
1025 StringRef Name, DIFile F,
1027 DIType Ty, ArrayRef<Value *> Addr,
1029 SmallVector<Value *, 15> Elts;
1030 Elts.push_back(GetTagConstant(VMContext, Tag));
1031 Elts.push_back(getNonCompileUnitScope(Scope)),
1032 Elts.push_back(MDString::get(VMContext, Name));
1034 Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext),
1035 (LineNo | (ArgNo << 24))));
1037 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
1038 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
1039 Elts.append(Addr.begin(), Addr.end());
1041 return DIVariable(MDNode::get(VMContext, Elts));
1044 /// createFunction - Create a new descriptor for the specified function.
1045 /// FIXME: this is added for dragonegg. Once we update dragonegg
1046 /// to call resolve function, this will be removed.
1047 DISubprogram DIBuilder::createFunction(DIScopeRef Context, StringRef Name,
1048 StringRef LinkageName, DIFile File,
1049 unsigned LineNo, DICompositeType Ty,
1050 bool isLocalToUnit, bool isDefinition,
1051 unsigned ScopeLine, unsigned Flags,
1052 bool isOptimized, Function *Fn,
1053 MDNode *TParams, MDNode *Decl) {
1054 // dragonegg does not generate identifier for types, so using an empty map
1055 // to resolve the context should be fine.
1056 DITypeIdentifierMap EmptyMap;
1057 return createFunction(Context.resolve(EmptyMap), Name, LinkageName, File,
1058 LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine,
1059 Flags, isOptimized, Fn, TParams, Decl);
1062 /// createFunction - Create a new descriptor for the specified function.
1063 DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name,
1064 StringRef LinkageName, DIFile File,
1065 unsigned LineNo, DICompositeType Ty,
1066 bool isLocalToUnit, bool isDefinition,
1067 unsigned ScopeLine, unsigned Flags,
1068 bool isOptimized, Function *Fn,
1069 MDNode *TParams, MDNode *Decl) {
1070 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1071 "function types should be subroutines");
1072 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
1074 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
1076 DIScope(getNonCompileUnitScope(Context)).getRef(),
1077 MDString::get(VMContext, Name),
1078 MDString::get(VMContext, Name),
1079 MDString::get(VMContext, LinkageName),
1080 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1082 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1083 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1084 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
1085 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
1087 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1088 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
1092 MDNode::getTemporary(VMContext, TElts),
1093 ConstantInt::get(Type::getInt32Ty(VMContext), ScopeLine)
1095 MDNode *Node = MDNode::get(VMContext, Elts);
1097 // Create a named metadata so that we do not lose this mdnode.
1099 AllSubprograms.push_back(Node);
1100 DISubprogram S(Node);
1101 assert(S.isSubprogram() && "createFunction should return a valid DISubprogram");
1105 /// createMethod - Create a new descriptor for the specified C++ method.
1106 DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
1107 StringRef LinkageName, DIFile F,
1108 unsigned LineNo, DICompositeType Ty,
1109 bool isLocalToUnit, bool isDefinition,
1110 unsigned VK, unsigned VIndex,
1111 DIType VTableHolder, unsigned Flags,
1112 bool isOptimized, Function *Fn,
1114 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1115 "function types should be subroutines");
1116 assert(getNonCompileUnitScope(Context) &&
1117 "Methods should have both a Context and a context that isn't "
1118 "the compile unit.");
1119 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
1121 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
1123 DIScope(Context).getRef(),
1124 MDString::get(VMContext, Name),
1125 MDString::get(VMContext, Name),
1126 MDString::get(VMContext, LinkageName),
1127 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1129 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1130 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1131 ConstantInt::get(Type::getInt32Ty(VMContext), VK),
1132 ConstantInt::get(Type::getInt32Ty(VMContext), VIndex),
1133 VTableHolder.getRef(),
1134 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1135 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
1138 Constant::getNullValue(Type::getInt32Ty(VMContext)),
1139 MDNode::getTemporary(VMContext, TElts),
1140 // FIXME: Do we want to use different scope/lines?
1141 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
1143 MDNode *Node = MDNode::get(VMContext, Elts);
1145 AllSubprograms.push_back(Node);
1146 DISubprogram S(Node);
1147 assert(S.isSubprogram() && "createMethod should return a valid DISubprogram");
1151 /// createNameSpace - This creates new descriptor for a namespace
1152 /// with the specified parent scope.
1153 DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
1154 DIFile File, unsigned LineNo) {
1156 GetTagConstant(VMContext, dwarf::DW_TAG_namespace),
1158 getNonCompileUnitScope(Scope),
1159 MDString::get(VMContext, Name),
1160 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
1162 DINameSpace R(MDNode::get(VMContext, Elts));
1163 assert(R.Verify() &&
1164 "createNameSpace should return a verifiable DINameSpace");
1168 /// createLexicalBlockFile - This creates a new MDNode that encapsulates
1169 /// an existing scope with a new filename.
1170 DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
1173 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
1177 DILexicalBlockFile R(MDNode::get(VMContext, Elts));
1180 "createLexicalBlockFile should return a verifiable DILexicalBlockFile");
1184 DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
1185 unsigned Line, unsigned Col) {
1186 // Defeat MDNode uniquing for lexical blocks by using unique id.
1187 static unsigned int unique_id = 0;
1189 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
1191 getNonCompileUnitScope(Scope),
1192 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
1193 ConstantInt::get(Type::getInt32Ty(VMContext), Col),
1194 ConstantInt::get(Type::getInt32Ty(VMContext), unique_id++)
1196 DILexicalBlock R(MDNode::get(VMContext, Elts));
1197 assert(R.Verify() &&
1198 "createLexicalBlock should return a verifiable DILexicalBlock");
1202 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1203 Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
1204 Instruction *InsertBefore) {
1205 assert(Storage && "no storage passed to dbg.declare");
1206 assert(VarInfo.isVariable() &&
1207 "empty or invalid DIVariable passed to dbg.declare");
1209 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1211 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
1212 return CallInst::Create(DeclareFn, Args, "", InsertBefore);
1215 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1216 Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
1217 BasicBlock *InsertAtEnd) {
1218 assert(Storage && "no storage passed to dbg.declare");
1219 assert(VarInfo.isVariable() &&
1220 "empty or invalid DIVariable passed to dbg.declare");
1222 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1224 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
1226 // If this block already has a terminator then insert this intrinsic
1227 // before the terminator.
1228 if (TerminatorInst *T = InsertAtEnd->getTerminator())
1229 return CallInst::Create(DeclareFn, Args, "", T);
1231 return CallInst::Create(DeclareFn, Args, "", InsertAtEnd);
1234 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1235 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
1237 Instruction *InsertBefore) {
1238 assert(V && "no value passed to dbg.value");
1239 assert(VarInfo.isVariable() &&
1240 "empty or invalid DIVariable passed to dbg.value");
1242 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1244 Value *Args[] = { MDNode::get(V->getContext(), V),
1245 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1247 return CallInst::Create(ValueFn, Args, "", InsertBefore);
1250 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1251 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
1253 BasicBlock *InsertAtEnd) {
1254 assert(V && "no value passed to dbg.value");
1255 assert(VarInfo.isVariable() &&
1256 "empty or invalid DIVariable passed to dbg.value");
1258 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1260 Value *Args[] = { MDNode::get(V->getContext(), V),
1261 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1263 return CallInst::Create(ValueFn, Args, "", InsertAtEnd);