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 SmallVector<Value *, 16> RetainValuesI;
73 for (unsigned I = 0, E = AllImportedModules.size(); I < E; I++)
74 RetainValuesI.push_back(AllImportedModules[I]);
75 DIArray IMs = getOrCreateArray(RetainValuesI);
76 DIType(TempImportedModules).replaceAllUsesWith(IMs);
79 /// getNonCompileUnitScope - If N is compile unit return NULL otherwise return
81 static MDNode *getNonCompileUnitScope(MDNode *N) {
82 if (DIDescriptor(N).isCompileUnit())
87 static MDNode *createFilePathPair(LLVMContext &VMContext, StringRef Filename,
88 StringRef Directory) {
89 assert(!Filename.empty() && "Unable to create file without name");
91 MDString::get(VMContext, Filename),
92 MDString::get(VMContext, Directory)
94 return MDNode::get(VMContext, Pair);
97 /// createCompileUnit - A CompileUnit provides an anchor for all debugging
98 /// information generated during this instance of compilation.
99 DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename,
101 StringRef Producer, bool isOptimized,
102 StringRef Flags, unsigned RunTimeVer,
104 DebugEmissionKind Kind) {
106 assert(((Lang <= dwarf::DW_LANG_Python && Lang >= dwarf::DW_LANG_C89) ||
107 (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
108 "Invalid Language tag");
109 assert(!Filename.empty() &&
110 "Unable to create compile unit without filename");
111 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
112 TempEnumTypes = MDNode::getTemporary(VMContext, TElts);
114 TempRetainTypes = MDNode::getTemporary(VMContext, TElts);
116 TempSubprograms = MDNode::getTemporary(VMContext, TElts);
118 TempGVs = MDNode::getTemporary(VMContext, TElts);
120 TempImportedModules = MDNode::getTemporary(VMContext, TElts);
123 GetTagConstant(VMContext, dwarf::DW_TAG_compile_unit),
124 createFilePathPair(VMContext, Filename, Directory),
125 ConstantInt::get(Type::getInt32Ty(VMContext), Lang),
126 MDString::get(VMContext, Producer),
127 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
128 MDString::get(VMContext, Flags),
129 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer),
135 MDString::get(VMContext, SplitName),
136 ConstantInt::get(Type::getInt32Ty(VMContext), Kind)
139 MDNode *CUNode = MDNode::get(VMContext, Elts);
141 // Create a named metadata so that it is easier to find cu in a module.
142 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
143 NMD->addOperand(CUNode);
145 return DICompileUnit(CUNode);
148 static DIImportedEntity
149 createImportedModule(LLVMContext &C, DIScope Context, DIDescriptor NS,
150 unsigned Line, StringRef Name,
151 SmallVectorImpl<TrackingVH<MDNode>> &AllImportedModules) {
155 GetTagConstant(C, dwarf::DW_TAG_imported_module),
158 ConstantInt::get(Type::getInt32Ty(C), Line),
160 R = MDNode::get(C, Elts);
163 GetTagConstant(C, dwarf::DW_TAG_imported_module),
166 ConstantInt::get(Type::getInt32Ty(C), Line),
167 MDString::get(C, Name)
169 R = MDNode::get(C, Elts);
171 DIImportedEntity M(R);
172 assert(M.Verify() && "Imported module should be valid");
173 AllImportedModules.push_back(TrackingVH<MDNode>(M));
177 DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
178 DINameSpace NS, unsigned Line,
180 return ::createImportedModule(VMContext, Context, NS, Line, Name,
184 DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
188 return ::createImportedModule(VMContext, Context, NS, Line, Name,
192 DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
196 GetTagConstant(VMContext, dwarf::DW_TAG_imported_declaration),
199 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
201 DIImportedEntity M(MDNode::get(VMContext, Elts));
202 assert(M.Verify() && "Imported module should be valid");
203 AllImportedModules.push_back(TrackingVH<MDNode>(M));
207 /// createFile - Create a file descriptor to hold debugging information
209 DIFile DIBuilder::createFile(StringRef Filename, StringRef Directory) {
211 GetTagConstant(VMContext, dwarf::DW_TAG_file_type),
212 createFilePathPair(VMContext, Filename, Directory)
214 return DIFile(MDNode::get(VMContext, Elts));
217 /// createEnumerator - Create a single enumerator value.
218 DIEnumerator DIBuilder::createEnumerator(StringRef Name, int64_t Val) {
219 assert(!Name.empty() && "Unable to create enumerator without name");
221 GetTagConstant(VMContext, dwarf::DW_TAG_enumerator),
222 MDString::get(VMContext, Name),
223 ConstantInt::get(Type::getInt64Ty(VMContext), Val)
225 return DIEnumerator(MDNode::get(VMContext, Elts));
228 /// \brief Create a DWARF unspecified type.
229 DIBasicType DIBuilder::createUnspecifiedType(StringRef Name) {
230 assert(!Name.empty() && "Unable to create type without name");
231 // Unspecified types are encoded in DIBasicType format. Line number, filename,
232 // size, alignment, offset and flags are always empty here.
234 GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_type),
237 MDString::get(VMContext, Name),
238 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
239 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
240 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
241 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
242 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
243 ConstantInt::get(Type::getInt32Ty(VMContext), 0) // Encoding
245 return DIBasicType(MDNode::get(VMContext, Elts));
248 /// \brief Create C++11 nullptr type.
249 DIBasicType DIBuilder::createNullPtrType() {
250 return createUnspecifiedType("decltype(nullptr)");
253 /// createBasicType - Create debugging information entry for a basic
254 /// type, e.g 'char'.
256 DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
257 uint64_t AlignInBits, unsigned Encoding) {
258 assert(!Name.empty() && "Unable to create type without name");
259 // Basic types are encoded in DIBasicType format. Line number, filename,
260 // offset and flags are always empty here.
262 GetTagConstant(VMContext, dwarf::DW_TAG_base_type),
263 NULL, // File/directory name
265 MDString::get(VMContext, Name),
266 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
267 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
268 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
269 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
270 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
271 ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
273 return DIBasicType(MDNode::get(VMContext, Elts));
276 /// createQualifiedType - Create debugging information entry for a qualified
277 /// type, e.g. 'const int'.
278 DIDerivedType DIBuilder::createQualifiedType(unsigned Tag, DIType FromTy) {
279 // Qualified types are encoded in DIDerivedType format.
281 GetTagConstant(VMContext, Tag),
284 MDString::get(VMContext, StringRef()), // Empty name.
285 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
286 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
287 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
288 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
289 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
292 return DIDerivedType(MDNode::get(VMContext, Elts));
295 /// createPointerType - Create debugging information entry for a pointer.
297 DIBuilder::createPointerType(DIType PointeeTy, uint64_t SizeInBits,
298 uint64_t AlignInBits, StringRef Name) {
299 // Pointer types are encoded in DIDerivedType format.
301 GetTagConstant(VMContext, dwarf::DW_TAG_pointer_type),
304 MDString::get(VMContext, Name),
305 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
306 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
307 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
308 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
309 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
312 return DIDerivedType(MDNode::get(VMContext, Elts));
315 DIDerivedType DIBuilder::createMemberPointerType(DIType PointeeTy,
317 // Pointer types are encoded in DIDerivedType format.
319 GetTagConstant(VMContext, dwarf::DW_TAG_ptr_to_member_type),
323 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
324 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
325 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
326 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
327 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
331 return DIDerivedType(MDNode::get(VMContext, Elts));
334 /// createReferenceType - Create debugging information entry for a reference
336 DIDerivedType DIBuilder::createReferenceType(unsigned Tag, DIType RTy) {
337 assert(RTy.isType() && "Unable to create reference type");
338 // References are encoded in DIDerivedType format.
340 GetTagConstant(VMContext, Tag),
344 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
345 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
346 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
347 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
348 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
351 return DIDerivedType(MDNode::get(VMContext, Elts));
354 /// createTypedef - Create debugging information entry for a typedef.
355 DIDerivedType DIBuilder::createTypedef(DIType Ty, StringRef Name, DIFile File,
356 unsigned LineNo, DIDescriptor Context) {
357 // typedefs are encoded in DIDerivedType format.
358 assert(Ty.isType() && "Invalid typedef type!");
360 GetTagConstant(VMContext, dwarf::DW_TAG_typedef),
362 DIScope(getNonCompileUnitScope(Context)).getRef(),
363 MDString::get(VMContext, Name),
364 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
365 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
366 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
367 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
368 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
371 return DIDerivedType(MDNode::get(VMContext, Elts));
374 /// createFriend - Create debugging information entry for a 'friend'.
375 DIDerivedType DIBuilder::createFriend(DIType Ty, DIType FriendTy) {
376 // typedefs are encoded in DIDerivedType format.
377 assert(Ty.isType() && "Invalid type!");
378 assert(FriendTy.isType() && "Invalid friend type!");
380 GetTagConstant(VMContext, dwarf::DW_TAG_friend),
384 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
385 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
386 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
387 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
388 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
391 return DIDerivedType(MDNode::get(VMContext, Elts));
394 /// createInheritance - Create debugging information entry to establish
395 /// inheritance relationship between two types.
396 DIDerivedType DIBuilder::createInheritance(DIType Ty, DIType BaseTy,
399 assert(Ty.isType() && "Unable to create inheritance");
400 // TAG_inheritance is encoded in DIDerivedType format.
402 GetTagConstant(VMContext, dwarf::DW_TAG_inheritance),
406 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
407 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
408 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
409 ConstantInt::get(Type::getInt64Ty(VMContext), BaseOffset),
410 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
413 return DIDerivedType(MDNode::get(VMContext, Elts));
416 /// createMemberType - Create debugging information entry for a member.
417 DIDerivedType DIBuilder::createMemberType(DIDescriptor Scope, StringRef Name,
418 DIFile File, unsigned LineNumber,
420 uint64_t AlignInBits,
421 uint64_t OffsetInBits, unsigned Flags,
423 // TAG_member is encoded in DIDerivedType format.
425 GetTagConstant(VMContext, dwarf::DW_TAG_member),
427 DIScope(getNonCompileUnitScope(Scope)).getRef(),
428 MDString::get(VMContext, Name),
429 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
430 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
431 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
432 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
433 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
436 return DIDerivedType(MDNode::get(VMContext, Elts));
439 /// createStaticMemberType - Create debugging information entry for a
440 /// C++ static data member.
442 DIBuilder::createStaticMemberType(DIDescriptor Scope, StringRef Name,
443 DIFile File, unsigned LineNumber,
444 DIType Ty, unsigned Flags,
446 // TAG_member is encoded in DIDerivedType format.
447 Flags |= DIDescriptor::FlagStaticMember;
449 GetTagConstant(VMContext, dwarf::DW_TAG_member),
451 DIScope(getNonCompileUnitScope(Scope)).getRef(),
452 MDString::get(VMContext, Name),
453 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
454 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
455 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
456 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
457 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
461 return DIDerivedType(MDNode::get(VMContext, Elts));
464 /// createObjCIVar - Create debugging information entry for Objective-C
465 /// instance variable.
467 DIBuilder::createObjCIVar(StringRef Name, DIFile File, unsigned LineNumber,
468 uint64_t SizeInBits, uint64_t AlignInBits,
469 uint64_t OffsetInBits, unsigned Flags, DIType Ty,
470 StringRef PropertyName, StringRef GetterName,
471 StringRef SetterName, unsigned PropertyAttributes) {
472 // TAG_member is encoded in DIDerivedType format.
474 GetTagConstant(VMContext, dwarf::DW_TAG_member),
476 getNonCompileUnitScope(File),
477 MDString::get(VMContext, Name),
478 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
479 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
480 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
481 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
482 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
484 MDString::get(VMContext, PropertyName),
485 MDString::get(VMContext, GetterName),
486 MDString::get(VMContext, SetterName),
487 ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes)
489 return DIDerivedType(MDNode::get(VMContext, Elts));
492 /// createObjCIVar - Create debugging information entry for Objective-C
493 /// instance variable.
494 DIDerivedType DIBuilder::createObjCIVar(StringRef Name, DIFile File,
497 uint64_t AlignInBits,
498 uint64_t OffsetInBits, unsigned Flags,
499 DIType Ty, MDNode *PropertyNode) {
500 // TAG_member is encoded in DIDerivedType format.
502 GetTagConstant(VMContext, dwarf::DW_TAG_member),
504 getNonCompileUnitScope(File),
505 MDString::get(VMContext, Name),
506 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
507 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
508 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
509 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
510 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
514 return DIDerivedType(MDNode::get(VMContext, Elts));
517 /// createObjCProperty - Create debugging information entry for Objective-C
520 DIBuilder::createObjCProperty(StringRef Name, DIFile File, unsigned LineNumber,
521 StringRef GetterName, StringRef SetterName,
522 unsigned PropertyAttributes, DIType Ty) {
524 GetTagConstant(VMContext, dwarf::DW_TAG_APPLE_property),
525 MDString::get(VMContext, Name),
527 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
528 MDString::get(VMContext, GetterName),
529 MDString::get(VMContext, SetterName),
530 ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes),
533 return DIObjCProperty(MDNode::get(VMContext, Elts));
536 /// createTemplateTypeParameter - Create debugging information for template
538 DITemplateTypeParameter
539 DIBuilder::createTemplateTypeParameter(DIDescriptor Context, StringRef Name,
540 DIType Ty, MDNode *File, unsigned LineNo,
543 GetTagConstant(VMContext, dwarf::DW_TAG_template_type_parameter),
544 DIScope(getNonCompileUnitScope(Context)).getRef(),
545 MDString::get(VMContext, Name),
548 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
549 ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo)
551 return DITemplateTypeParameter(MDNode::get(VMContext, Elts));
554 DITemplateValueParameter
555 DIBuilder::createTemplateValueParameter(unsigned Tag, DIDescriptor Context,
556 StringRef Name, DIType Ty,
557 Value *Val, MDNode *File,
561 GetTagConstant(VMContext, Tag),
562 DIScope(getNonCompileUnitScope(Context)).getRef(),
563 MDString::get(VMContext, Name),
567 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
568 ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo)
570 return DITemplateValueParameter(MDNode::get(VMContext, Elts));
573 /// createTemplateValueParameter - Create debugging information for template
575 DITemplateValueParameter
576 DIBuilder::createTemplateValueParameter(DIDescriptor Context, StringRef Name,
577 DIType Ty, Value *Val,
578 MDNode *File, unsigned LineNo,
580 return createTemplateValueParameter(dwarf::DW_TAG_template_value_parameter,
581 Context, Name, Ty, Val, File, LineNo,
585 DITemplateValueParameter
586 DIBuilder::createTemplateTemplateParameter(DIDescriptor Context, StringRef Name,
587 DIType Ty, StringRef Val,
588 MDNode *File, unsigned LineNo,
590 return createTemplateValueParameter(
591 dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
592 MDString::get(VMContext, Val), File, LineNo, ColumnNo);
595 DITemplateValueParameter
596 DIBuilder::createTemplateParameterPack(DIDescriptor Context, StringRef Name,
597 DIType Ty, DIArray Val,
598 MDNode *File, unsigned LineNo,
600 return createTemplateValueParameter(dwarf::DW_TAG_GNU_template_parameter_pack,
601 Context, Name, Ty, Val, File, LineNo,
605 /// createClassType - Create debugging information entry for a class.
606 DICompositeType DIBuilder::createClassType(DIDescriptor Context, StringRef Name,
607 DIFile File, unsigned LineNumber,
609 uint64_t AlignInBits,
610 uint64_t OffsetInBits,
611 unsigned Flags, DIType DerivedFrom,
614 MDNode *TemplateParams,
615 StringRef UniqueIdentifier) {
616 assert((!Context || Context.isScope() || Context.isType()) &&
617 "createClassType should be called with a valid Context");
618 // TAG_class_type is encoded in DICompositeType format.
620 GetTagConstant(VMContext, dwarf::DW_TAG_class_type),
622 DIScope(getNonCompileUnitScope(Context)).getRef(),
623 MDString::get(VMContext, Name),
624 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
625 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
626 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
627 ConstantInt::get(Type::getInt32Ty(VMContext), OffsetInBits),
628 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
629 DerivedFrom.getRef(),
631 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
632 VTableHolder.getRef(),
634 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
636 DICompositeType R(MDNode::get(VMContext, Elts));
637 assert(R.isCompositeType() &&
638 "createClassType should return a DICompositeType");
639 if (!UniqueIdentifier.empty())
644 /// createStructType - Create debugging information entry for a struct.
645 DICompositeType DIBuilder::createStructType(DIDescriptor Context,
646 StringRef Name, DIFile File,
649 uint64_t AlignInBits,
650 unsigned Flags, DIType DerivedFrom,
652 unsigned RunTimeLang,
654 StringRef UniqueIdentifier) {
655 // TAG_structure_type is encoded in DICompositeType format.
657 GetTagConstant(VMContext, dwarf::DW_TAG_structure_type),
659 DIScope(getNonCompileUnitScope(Context)).getRef(),
660 MDString::get(VMContext, Name),
661 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
662 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
663 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
664 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
665 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
666 DerivedFrom.getRef(),
668 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
669 VTableHolder.getRef(),
671 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
673 DICompositeType R(MDNode::get(VMContext, Elts));
674 assert(R.isCompositeType() &&
675 "createStructType should return a DICompositeType");
676 if (!UniqueIdentifier.empty())
681 /// createUnionType - Create debugging information entry for an union.
682 DICompositeType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name,
683 DIFile File, unsigned LineNumber,
685 uint64_t AlignInBits, unsigned Flags,
687 unsigned RunTimeLang,
688 StringRef UniqueIdentifier) {
689 // TAG_union_type is encoded in DICompositeType format.
691 GetTagConstant(VMContext, dwarf::DW_TAG_union_type),
693 DIScope(getNonCompileUnitScope(Scope)).getRef(),
694 MDString::get(VMContext, Name),
695 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
696 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
697 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
698 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
699 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
702 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
705 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
707 DICompositeType R(MDNode::get(VMContext, Elts));
708 if (!UniqueIdentifier.empty())
713 /// createSubroutineType - Create subroutine type.
714 DICompositeType DIBuilder::createSubroutineType(DIFile File,
715 DIArray ParameterTypes,
717 // TAG_subroutine_type is encoded in DICompositeType format.
719 GetTagConstant(VMContext, dwarf::DW_TAG_subroutine_type),
720 Constant::getNullValue(Type::getInt32Ty(VMContext)),
722 MDString::get(VMContext, ""),
723 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
724 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
725 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
726 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
727 ConstantInt::get(Type::getInt32Ty(VMContext), Flags), // Flags
730 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
733 NULL // Type Identifer
735 return DICompositeType(MDNode::get(VMContext, Elts));
738 /// createEnumerationType - Create debugging information entry for an
740 DICompositeType DIBuilder::createEnumerationType(
741 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
742 uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
743 DIType UnderlyingType, StringRef UniqueIdentifier) {
744 // TAG_enumeration_type is encoded in DICompositeType format.
746 GetTagConstant(VMContext, dwarf::DW_TAG_enumeration_type),
748 DIScope(getNonCompileUnitScope(Scope)).getRef(),
749 MDString::get(VMContext, Name),
750 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
751 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
752 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
753 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
754 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
755 UnderlyingType.getRef(),
757 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
760 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
762 DICompositeType CTy(MDNode::get(VMContext, Elts));
763 AllEnumTypes.push_back(CTy);
764 if (!UniqueIdentifier.empty())
769 /// createArrayType - Create debugging information entry for an array.
770 DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
771 DIType Ty, DIArray Subscripts) {
772 // TAG_array_type is encoded in DICompositeType format.
774 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
775 NULL, // Filename/Directory,
777 MDString::get(VMContext, ""),
778 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
779 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
780 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
781 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
782 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
785 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
788 NULL // Type Identifer
790 return DICompositeType(MDNode::get(VMContext, Elts));
793 /// createVectorType - Create debugging information entry for a vector.
794 DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits,
795 DIType Ty, DIArray Subscripts) {
796 // A vector is an array type with the FlagVector flag applied.
798 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
799 NULL, // Filename/Directory,
801 MDString::get(VMContext, ""),
802 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
803 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
804 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
805 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
806 ConstantInt::get(Type::getInt32Ty(VMContext), DIType::FlagVector),
809 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
812 NULL // Type Identifer
814 return DICompositeType(MDNode::get(VMContext, Elts));
817 /// createArtificialType - Create a new DIType with "artificial" flag set.
818 DIType DIBuilder::createArtificialType(DIType Ty) {
819 if (Ty.isArtificial())
822 SmallVector<Value *, 9> Elts;
824 assert (N && "Unexpected input DIType!");
825 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
826 Elts.push_back(N->getOperand(i));
828 unsigned CurFlags = Ty.getFlags();
829 CurFlags = CurFlags | DIType::FlagArtificial;
831 // Flags are stored at this slot.
832 // FIXME: Add an enum for this magic value.
833 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
835 return DIType(MDNode::get(VMContext, Elts));
838 /// createObjectPointerType - Create a new type with both the object pointer
839 /// and artificial flags set.
840 DIType DIBuilder::createObjectPointerType(DIType Ty) {
841 if (Ty.isObjectPointer())
844 SmallVector<Value *, 9> Elts;
846 assert (N && "Unexpected input DIType!");
847 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
848 Elts.push_back(N->getOperand(i));
850 unsigned CurFlags = Ty.getFlags();
851 CurFlags = CurFlags | (DIType::FlagObjectPointer | DIType::FlagArtificial);
853 // Flags are stored at this slot.
854 // FIXME: Add an enum for this magic value.
855 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
857 return DIType(MDNode::get(VMContext, Elts));
860 /// retainType - Retain DIType in a module even if it is not referenced
861 /// through debug info anchors.
862 void DIBuilder::retainType(DIType T) {
863 AllRetainTypes.push_back(TrackingVH<MDNode>(T));
866 /// createUnspecifiedParameter - Create unspeicified type descriptor
867 /// for the subroutine type.
868 DIDescriptor DIBuilder::createUnspecifiedParameter() {
870 GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_parameters)
872 return DIDescriptor(MDNode::get(VMContext, Elts));
875 /// createForwardDecl - Create a temporary forward-declared type that
876 /// can be RAUW'd if the full type is seen.
878 DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope,
879 DIFile F, unsigned Line, unsigned RuntimeLang,
880 uint64_t SizeInBits, uint64_t AlignInBits,
881 StringRef UniqueIdentifier) {
882 // Create a temporary MDNode.
884 GetTagConstant(VMContext, Tag),
886 DIScope(getNonCompileUnitScope(Scope)).getRef(),
887 MDString::get(VMContext, Name),
888 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
889 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
890 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
891 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
892 ConstantInt::get(Type::getInt32Ty(VMContext), DIDescriptor::FlagFwdDecl),
895 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang),
897 NULL, //TemplateParams
898 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
900 MDNode *Node = MDNode::getTemporary(VMContext, Elts);
901 DICompositeType RetTy(Node);
902 assert(RetTy.isCompositeType() &&
903 "createForwardDecl result should be a DIType");
904 if (!UniqueIdentifier.empty())
909 /// getOrCreateArray - Get a DIArray, create one if required.
910 DIArray DIBuilder::getOrCreateArray(ArrayRef<Value *> Elements) {
911 return DIArray(MDNode::get(VMContext, Elements));
914 /// getOrCreateSubrange - Create a descriptor for a value range. This
915 /// implicitly uniques the values returned.
916 DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
918 GetTagConstant(VMContext, dwarf::DW_TAG_subrange_type),
919 ConstantInt::get(Type::getInt64Ty(VMContext), Lo),
920 ConstantInt::get(Type::getInt64Ty(VMContext), Count)
923 return DISubrange(MDNode::get(VMContext, Elts));
926 /// \brief Create a new descriptor for the specified global.
927 DIGlobalVariable DIBuilder::createGlobalVariable(StringRef Name,
928 StringRef LinkageName,
929 DIFile F, unsigned LineNumber,
930 DIType Ty, bool isLocalToUnit,
933 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
934 Constant::getNullValue(Type::getInt32Ty(VMContext)),
936 MDString::get(VMContext, Name),
937 MDString::get(VMContext, Name),
938 MDString::get(VMContext, LinkageName),
940 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
942 ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
943 ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
947 MDNode *Node = MDNode::get(VMContext, Elts);
948 AllGVs.push_back(Node);
949 return DIGlobalVariable(Node);
952 /// \brief Create a new descriptor for the specified global.
953 DIGlobalVariable DIBuilder::createGlobalVariable(StringRef Name, DIFile F,
954 unsigned LineNumber, DIType Ty,
957 return createGlobalVariable(Name, Name, F, LineNumber, Ty, isLocalToUnit,
961 /// createStaticVariable - Create a new descriptor for the specified static
963 DIGlobalVariable DIBuilder::createStaticVariable(DIDescriptor Context,
965 StringRef LinkageName,
966 DIFile F, unsigned LineNumber,
967 DIType Ty, bool isLocalToUnit,
968 Value *Val, MDNode *Decl) {
970 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
971 Constant::getNullValue(Type::getInt32Ty(VMContext)),
972 getNonCompileUnitScope(Context),
973 MDString::get(VMContext, Name),
974 MDString::get(VMContext, Name),
975 MDString::get(VMContext, LinkageName),
977 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
979 ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
980 ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
984 MDNode *Node = MDNode::get(VMContext, Elts);
985 AllGVs.push_back(Node);
986 return DIGlobalVariable(Node);
989 /// createVariable - Create a new descriptor for the specified variable.
990 DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
991 StringRef Name, DIFile File,
992 unsigned LineNo, DIType Ty,
993 bool AlwaysPreserve, unsigned Flags,
995 DIDescriptor Context(getNonCompileUnitScope(Scope));
996 assert((!Context || Context.isScope()) &&
997 "createLocalVariable should be called with a valid Context");
998 assert(Ty.isType() &&
999 "createLocalVariable should be called with a valid type");
1001 GetTagConstant(VMContext, Tag),
1002 getNonCompileUnitScope(Scope),
1003 MDString::get(VMContext, Name),
1005 ConstantInt::get(Type::getInt32Ty(VMContext), (LineNo | (ArgNo << 24))),
1007 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1008 Constant::getNullValue(Type::getInt32Ty(VMContext))
1010 MDNode *Node = MDNode::get(VMContext, Elts);
1011 if (AlwaysPreserve) {
1012 // The optimizer may remove local variable. If there is an interest
1013 // to preserve variable info in such situation then stash it in a
1015 DISubprogram Fn(getDISubprogram(Scope));
1016 NamedMDNode *FnLocals = getOrInsertFnSpecificMDNode(M, Fn);
1017 FnLocals->addOperand(Node);
1019 DIVariable RetVar(Node);
1020 assert(RetVar.isVariable() &&
1021 "createLocalVariable should return a valid DIVariable");
1025 /// createComplexVariable - Create a new descriptor for the specified variable
1026 /// which has a complex address expression for its address.
1027 DIVariable DIBuilder::createComplexVariable(unsigned Tag, DIDescriptor Scope,
1028 StringRef Name, DIFile F,
1030 DIType Ty, ArrayRef<Value *> Addr,
1032 SmallVector<Value *, 15> Elts;
1033 Elts.push_back(GetTagConstant(VMContext, Tag));
1034 Elts.push_back(getNonCompileUnitScope(Scope)),
1035 Elts.push_back(MDString::get(VMContext, Name));
1037 Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext),
1038 (LineNo | (ArgNo << 24))));
1040 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
1041 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
1042 Elts.append(Addr.begin(), Addr.end());
1044 return DIVariable(MDNode::get(VMContext, Elts));
1047 /// createFunction - Create a new descriptor for the specified function.
1048 /// FIXME: this is added for dragonegg. Once we update dragonegg
1049 /// to call resolve function, this will be removed.
1050 DISubprogram DIBuilder::createFunction(DIScopeRef Context, StringRef Name,
1051 StringRef LinkageName, DIFile File,
1052 unsigned LineNo, DICompositeType Ty,
1053 bool isLocalToUnit, bool isDefinition,
1054 unsigned ScopeLine, unsigned Flags,
1055 bool isOptimized, Function *Fn,
1056 MDNode *TParams, MDNode *Decl) {
1057 // dragonegg does not generate identifier for types, so using an empty map
1058 // to resolve the context should be fine.
1059 DITypeIdentifierMap EmptyMap;
1060 return createFunction(Context.resolve(EmptyMap), Name, LinkageName, File,
1061 LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine,
1062 Flags, isOptimized, Fn, TParams, Decl);
1065 /// createFunction - Create a new descriptor for the specified function.
1066 DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name,
1067 StringRef LinkageName, DIFile File,
1068 unsigned LineNo, DICompositeType Ty,
1069 bool isLocalToUnit, bool isDefinition,
1070 unsigned ScopeLine, unsigned Flags,
1071 bool isOptimized, Function *Fn,
1072 MDNode *TParams, MDNode *Decl) {
1073 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1074 "function types should be subroutines");
1075 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
1077 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
1079 DIScope(getNonCompileUnitScope(Context)).getRef(),
1080 MDString::get(VMContext, Name),
1081 MDString::get(VMContext, Name),
1082 MDString::get(VMContext, LinkageName),
1083 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1085 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1086 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1087 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
1088 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
1090 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1091 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
1095 MDNode::getTemporary(VMContext, TElts),
1096 ConstantInt::get(Type::getInt32Ty(VMContext), ScopeLine)
1098 MDNode *Node = MDNode::get(VMContext, Elts);
1100 // Create a named metadata so that we do not lose this mdnode.
1102 AllSubprograms.push_back(Node);
1103 DISubprogram S(Node);
1104 assert(S.isSubprogram() && "createFunction should return a valid DISubprogram");
1108 /// createMethod - Create a new descriptor for the specified C++ method.
1109 DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
1110 StringRef LinkageName, DIFile F,
1111 unsigned LineNo, DICompositeType Ty,
1112 bool isLocalToUnit, bool isDefinition,
1113 unsigned VK, unsigned VIndex,
1114 DIType VTableHolder, unsigned Flags,
1115 bool isOptimized, Function *Fn,
1117 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1118 "function types should be subroutines");
1119 assert(getNonCompileUnitScope(Context) &&
1120 "Methods should have both a Context and a context that isn't "
1121 "the compile unit.");
1122 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
1124 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
1126 DIScope(Context).getRef(),
1127 MDString::get(VMContext, Name),
1128 MDString::get(VMContext, Name),
1129 MDString::get(VMContext, LinkageName),
1130 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1132 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1133 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1134 ConstantInt::get(Type::getInt32Ty(VMContext), VK),
1135 ConstantInt::get(Type::getInt32Ty(VMContext), VIndex),
1136 VTableHolder.getRef(),
1137 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1138 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
1141 Constant::getNullValue(Type::getInt32Ty(VMContext)),
1142 MDNode::getTemporary(VMContext, TElts),
1143 // FIXME: Do we want to use different scope/lines?
1144 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
1146 MDNode *Node = MDNode::get(VMContext, Elts);
1148 AllSubprograms.push_back(Node);
1149 DISubprogram S(Node);
1150 assert(S.isSubprogram() && "createMethod should return a valid DISubprogram");
1154 /// createNameSpace - This creates new descriptor for a namespace
1155 /// with the specified parent scope.
1156 DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
1157 DIFile File, unsigned LineNo) {
1159 GetTagConstant(VMContext, dwarf::DW_TAG_namespace),
1161 getNonCompileUnitScope(Scope),
1162 MDString::get(VMContext, Name),
1163 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
1165 DINameSpace R(MDNode::get(VMContext, Elts));
1166 assert(R.Verify() &&
1167 "createNameSpace should return a verifiable DINameSpace");
1171 /// createLexicalBlockFile - This creates a new MDNode that encapsulates
1172 /// an existing scope with a new filename.
1173 DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
1176 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
1180 DILexicalBlockFile R(MDNode::get(VMContext, Elts));
1183 "createLexicalBlockFile should return a verifiable DILexicalBlockFile");
1187 DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
1188 unsigned Line, unsigned Col) {
1189 // Defeat MDNode uniquing for lexical blocks by using unique id.
1190 static unsigned int unique_id = 0;
1192 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
1194 getNonCompileUnitScope(Scope),
1195 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
1196 ConstantInt::get(Type::getInt32Ty(VMContext), Col),
1197 ConstantInt::get(Type::getInt32Ty(VMContext), unique_id++)
1199 DILexicalBlock R(MDNode::get(VMContext, Elts));
1200 assert(R.Verify() &&
1201 "createLexicalBlock should return a verifiable DILexicalBlock");
1205 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1206 Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
1207 Instruction *InsertBefore) {
1208 assert(Storage && "no storage passed to dbg.declare");
1209 assert(VarInfo.isVariable() &&
1210 "empty or invalid DIVariable passed to dbg.declare");
1212 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1214 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
1215 return CallInst::Create(DeclareFn, Args, "", InsertBefore);
1218 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1219 Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
1220 BasicBlock *InsertAtEnd) {
1221 assert(Storage && "no storage passed to dbg.declare");
1222 assert(VarInfo.isVariable() &&
1223 "empty or invalid DIVariable passed to dbg.declare");
1225 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1227 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
1229 // If this block already has a terminator then insert this intrinsic
1230 // before the terminator.
1231 if (TerminatorInst *T = InsertAtEnd->getTerminator())
1232 return CallInst::Create(DeclareFn, Args, "", T);
1234 return CallInst::Create(DeclareFn, Args, "", InsertAtEnd);
1237 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1238 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
1240 Instruction *InsertBefore) {
1241 assert(V && "no value passed to dbg.value");
1242 assert(VarInfo.isVariable() &&
1243 "empty or invalid DIVariable passed to dbg.value");
1245 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1247 Value *Args[] = { MDNode::get(V->getContext(), V),
1248 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1250 return CallInst::Create(ValueFn, Args, "", InsertBefore);
1253 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1254 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
1256 BasicBlock *InsertAtEnd) {
1257 assert(V && "no value passed to dbg.value");
1258 assert(VarInfo.isVariable() &&
1259 "empty or invalid DIVariable passed to dbg.value");
1261 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1263 Value *Args[] = { MDNode::get(V->getContext(), V),
1264 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1266 return CallInst::Create(ValueFn, Args, "", InsertAtEnd);