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,
100 StringRef SplitName) {
101 assert(((Lang <= dwarf::DW_LANG_Python && Lang >= dwarf::DW_LANG_C89) ||
102 (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
103 "Invalid Language tag");
104 assert(!Filename.empty() &&
105 "Unable to create compile unit without filename");
106 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
107 TempEnumTypes = MDNode::getTemporary(VMContext, TElts);
109 TempRetainTypes = MDNode::getTemporary(VMContext, TElts);
111 TempSubprograms = MDNode::getTemporary(VMContext, TElts);
113 TempGVs = MDNode::getTemporary(VMContext, TElts);
115 TempImportedModules = MDNode::getTemporary(VMContext, TElts);
118 GetTagConstant(VMContext, dwarf::DW_TAG_compile_unit),
119 createFilePathPair(VMContext, Filename, Directory),
120 ConstantInt::get(Type::getInt32Ty(VMContext), Lang),
121 MDString::get(VMContext, Producer),
122 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
123 MDString::get(VMContext, Flags),
124 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer),
130 MDString::get(VMContext, SplitName)
133 MDNode *CUNode = MDNode::get(VMContext, Elts);
135 // Create a named metadata so that it is easier to find cu in a module.
136 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
137 NMD->addOperand(CUNode);
139 return DICompileUnit(CUNode);
142 static DIImportedEntity
143 createImportedModule(LLVMContext &C, DIScope Context, DIDescriptor NS,
144 unsigned Line, StringRef Name,
145 SmallVectorImpl<Value *> &AllImportedModules) {
149 GetTagConstant(C, dwarf::DW_TAG_imported_module),
152 ConstantInt::get(Type::getInt32Ty(C), Line),
154 R = MDNode::get(C, Elts);
157 GetTagConstant(C, dwarf::DW_TAG_imported_module),
160 ConstantInt::get(Type::getInt32Ty(C), Line),
161 MDString::get(C, Name)
163 R = MDNode::get(C, Elts);
165 DIImportedEntity M(R);
166 assert(M.Verify() && "Imported module should be valid");
167 AllImportedModules.push_back(M);
171 DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
172 DINameSpace NS, unsigned Line,
174 return ::createImportedModule(VMContext, Context, NS, Line, Name,
178 DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
182 return ::createImportedModule(VMContext, Context, NS, Line, Name,
186 DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
190 GetTagConstant(VMContext, dwarf::DW_TAG_imported_declaration),
193 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
195 DIImportedEntity M(MDNode::get(VMContext, Elts));
196 assert(M.Verify() && "Imported module should be valid");
197 AllImportedModules.push_back(M);
201 /// createFile - Create a file descriptor to hold debugging information
203 DIFile DIBuilder::createFile(StringRef Filename, StringRef Directory) {
205 GetTagConstant(VMContext, dwarf::DW_TAG_file_type),
206 createFilePathPair(VMContext, Filename, Directory)
208 return DIFile(MDNode::get(VMContext, Elts));
211 /// createEnumerator - Create a single enumerator value.
212 DIEnumerator DIBuilder::createEnumerator(StringRef Name, int64_t Val) {
213 assert(!Name.empty() && "Unable to create enumerator without name");
215 GetTagConstant(VMContext, dwarf::DW_TAG_enumerator),
216 MDString::get(VMContext, Name),
217 ConstantInt::get(Type::getInt64Ty(VMContext), Val)
219 return DIEnumerator(MDNode::get(VMContext, Elts));
222 /// \brief Create a DWARF unspecified type.
223 DIBasicType DIBuilder::createUnspecifiedType(StringRef Name) {
224 assert(!Name.empty() && "Unable to create type without name");
225 // Unspecified types are encoded in DIBasicType format. Line number, filename,
226 // size, alignment, offset and flags are always empty here.
228 GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_type),
231 MDString::get(VMContext, Name),
232 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
233 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
234 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
235 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
236 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
237 ConstantInt::get(Type::getInt32Ty(VMContext), 0) // Encoding
239 return DIBasicType(MDNode::get(VMContext, Elts));
242 /// \brief Create C++11 nullptr type.
243 DIBasicType DIBuilder::createNullPtrType() {
244 return createUnspecifiedType("decltype(nullptr)");
247 /// createBasicType - Create debugging information entry for a basic
248 /// type, e.g 'char'.
250 DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
251 uint64_t AlignInBits, unsigned Encoding) {
252 assert(!Name.empty() && "Unable to create type without name");
253 // Basic types are encoded in DIBasicType format. Line number, filename,
254 // offset and flags are always empty here.
256 GetTagConstant(VMContext, dwarf::DW_TAG_base_type),
257 NULL, // File/directory name
259 MDString::get(VMContext, Name),
260 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
261 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
262 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
263 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
264 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
265 ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
267 return DIBasicType(MDNode::get(VMContext, Elts));
270 /// createQualifiedType - Create debugging information entry for a qualified
271 /// type, e.g. 'const int'.
272 DIDerivedType DIBuilder::createQualifiedType(unsigned Tag, DIType FromTy) {
273 // Qualified types are encoded in DIDerivedType format.
275 GetTagConstant(VMContext, Tag),
278 MDString::get(VMContext, StringRef()), // Empty name.
279 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
280 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
281 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
282 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
283 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
286 return DIDerivedType(MDNode::get(VMContext, Elts));
289 /// createPointerType - Create debugging information entry for a pointer.
291 DIBuilder::createPointerType(DIType PointeeTy, uint64_t SizeInBits,
292 uint64_t AlignInBits, StringRef Name) {
293 // Pointer types are encoded in DIDerivedType format.
295 GetTagConstant(VMContext, dwarf::DW_TAG_pointer_type),
298 MDString::get(VMContext, Name),
299 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
300 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
301 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
302 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
303 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
306 return DIDerivedType(MDNode::get(VMContext, Elts));
309 DIDerivedType DIBuilder::createMemberPointerType(DIType PointeeTy,
311 // Pointer types are encoded in DIDerivedType format.
313 GetTagConstant(VMContext, dwarf::DW_TAG_ptr_to_member_type),
317 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
318 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
319 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
320 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
321 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
325 return DIDerivedType(MDNode::get(VMContext, Elts));
328 /// createReferenceType - Create debugging information entry for a reference
330 DIDerivedType DIBuilder::createReferenceType(unsigned Tag, DIType RTy) {
331 assert(RTy.isType() && "Unable to create reference type");
332 // References are encoded in DIDerivedType format.
334 GetTagConstant(VMContext, Tag),
338 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
339 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
340 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
341 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
342 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
345 return DIDerivedType(MDNode::get(VMContext, Elts));
348 /// createTypedef - Create debugging information entry for a typedef.
349 DIDerivedType DIBuilder::createTypedef(DIType Ty, StringRef Name, DIFile File,
350 unsigned LineNo, DIDescriptor Context) {
351 // typedefs are encoded in DIDerivedType format.
352 assert(Ty.isType() && "Invalid typedef type!");
354 GetTagConstant(VMContext, dwarf::DW_TAG_typedef),
356 DIScope(getNonCompileUnitScope(Context)).getRef(),
357 MDString::get(VMContext, Name),
358 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
359 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
360 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
361 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
362 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
365 return DIDerivedType(MDNode::get(VMContext, Elts));
368 /// createFriend - Create debugging information entry for a 'friend'.
369 DIDerivedType DIBuilder::createFriend(DIType Ty, DIType FriendTy) {
370 // typedefs are encoded in DIDerivedType format.
371 assert(Ty.isType() && "Invalid type!");
372 assert(FriendTy.isType() && "Invalid friend type!");
374 GetTagConstant(VMContext, dwarf::DW_TAG_friend),
378 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
379 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
380 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
381 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
382 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
385 return DIDerivedType(MDNode::get(VMContext, Elts));
388 /// createInheritance - Create debugging information entry to establish
389 /// inheritance relationship between two types.
390 DIDerivedType DIBuilder::createInheritance(DIType Ty, DIType BaseTy,
393 assert(Ty.isType() && "Unable to create inheritance");
394 // TAG_inheritance is encoded in DIDerivedType format.
396 GetTagConstant(VMContext, dwarf::DW_TAG_inheritance),
400 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
401 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
402 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
403 ConstantInt::get(Type::getInt64Ty(VMContext), BaseOffset),
404 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
407 return DIDerivedType(MDNode::get(VMContext, Elts));
410 /// createMemberType - Create debugging information entry for a member.
411 DIDerivedType DIBuilder::createMemberType(DIDescriptor Scope, StringRef Name,
412 DIFile File, unsigned LineNumber,
414 uint64_t AlignInBits,
415 uint64_t OffsetInBits, unsigned Flags,
417 // TAG_member is encoded in DIDerivedType format.
419 GetTagConstant(VMContext, dwarf::DW_TAG_member),
421 DIScope(getNonCompileUnitScope(Scope)).getRef(),
422 MDString::get(VMContext, Name),
423 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
424 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
425 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
426 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
427 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
430 return DIDerivedType(MDNode::get(VMContext, Elts));
433 /// createStaticMemberType - Create debugging information entry for a
434 /// C++ static data member.
436 DIBuilder::createStaticMemberType(DIDescriptor Scope, StringRef Name,
437 DIFile File, unsigned LineNumber,
438 DIType Ty, unsigned Flags,
440 // TAG_member is encoded in DIDerivedType format.
441 Flags |= DIDescriptor::FlagStaticMember;
443 GetTagConstant(VMContext, dwarf::DW_TAG_member),
445 DIScope(getNonCompileUnitScope(Scope)).getRef(),
446 MDString::get(VMContext, Name),
447 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
448 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
449 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
450 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
451 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
455 return DIDerivedType(MDNode::get(VMContext, Elts));
458 /// createObjCIVar - Create debugging information entry for Objective-C
459 /// instance variable.
461 DIBuilder::createObjCIVar(StringRef Name, DIFile File, unsigned LineNumber,
462 uint64_t SizeInBits, uint64_t AlignInBits,
463 uint64_t OffsetInBits, unsigned Flags, DIType Ty,
464 StringRef PropertyName, StringRef GetterName,
465 StringRef SetterName, unsigned PropertyAttributes) {
466 // TAG_member is encoded in DIDerivedType format.
468 GetTagConstant(VMContext, dwarf::DW_TAG_member),
470 getNonCompileUnitScope(File),
471 MDString::get(VMContext, Name),
472 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
473 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
474 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
475 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
476 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
478 MDString::get(VMContext, PropertyName),
479 MDString::get(VMContext, GetterName),
480 MDString::get(VMContext, SetterName),
481 ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes)
483 return DIDerivedType(MDNode::get(VMContext, Elts));
486 /// createObjCIVar - Create debugging information entry for Objective-C
487 /// instance variable.
488 DIDerivedType DIBuilder::createObjCIVar(StringRef Name, DIFile File,
491 uint64_t AlignInBits,
492 uint64_t OffsetInBits, unsigned Flags,
493 DIType Ty, MDNode *PropertyNode) {
494 // TAG_member is encoded in DIDerivedType format.
496 GetTagConstant(VMContext, dwarf::DW_TAG_member),
498 getNonCompileUnitScope(File),
499 MDString::get(VMContext, Name),
500 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
501 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
502 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
503 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
504 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
508 return DIDerivedType(MDNode::get(VMContext, Elts));
511 /// createObjCProperty - Create debugging information entry for Objective-C
514 DIBuilder::createObjCProperty(StringRef Name, DIFile File, unsigned LineNumber,
515 StringRef GetterName, StringRef SetterName,
516 unsigned PropertyAttributes, DIType Ty) {
518 GetTagConstant(VMContext, dwarf::DW_TAG_APPLE_property),
519 MDString::get(VMContext, Name),
521 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
522 MDString::get(VMContext, GetterName),
523 MDString::get(VMContext, SetterName),
524 ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes),
527 return DIObjCProperty(MDNode::get(VMContext, Elts));
530 /// createTemplateTypeParameter - Create debugging information for template
532 DITemplateTypeParameter
533 DIBuilder::createTemplateTypeParameter(DIDescriptor Context, StringRef Name,
534 DIType Ty, MDNode *File, unsigned LineNo,
537 GetTagConstant(VMContext, dwarf::DW_TAG_template_type_parameter),
538 DIScope(getNonCompileUnitScope(Context)).getRef(),
539 MDString::get(VMContext, Name),
542 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
543 ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo)
545 return DITemplateTypeParameter(MDNode::get(VMContext, Elts));
548 DITemplateValueParameter
549 DIBuilder::createTemplateValueParameter(unsigned Tag, DIDescriptor Context,
550 StringRef Name, DIType Ty,
551 Value *Val, MDNode *File,
555 GetTagConstant(VMContext, Tag),
556 DIScope(getNonCompileUnitScope(Context)).getRef(),
557 MDString::get(VMContext, Name),
561 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
562 ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo)
564 return DITemplateValueParameter(MDNode::get(VMContext, Elts));
567 /// createTemplateValueParameter - Create debugging information for template
569 DITemplateValueParameter
570 DIBuilder::createTemplateValueParameter(DIDescriptor Context, StringRef Name,
571 DIType Ty, Value *Val,
572 MDNode *File, unsigned LineNo,
574 return createTemplateValueParameter(dwarf::DW_TAG_template_value_parameter,
575 Context, Name, Ty, Val, File, LineNo,
579 DITemplateValueParameter
580 DIBuilder::createTemplateTemplateParameter(DIDescriptor Context, StringRef Name,
581 DIType Ty, StringRef Val,
582 MDNode *File, unsigned LineNo,
584 return createTemplateValueParameter(
585 dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
586 MDString::get(VMContext, Val), File, LineNo, ColumnNo);
589 DITemplateValueParameter
590 DIBuilder::createTemplateParameterPack(DIDescriptor Context, StringRef Name,
591 DIType Ty, DIArray Val,
592 MDNode *File, unsigned LineNo,
594 return createTemplateValueParameter(dwarf::DW_TAG_GNU_template_parameter_pack,
595 Context, Name, Ty, Val, File, LineNo,
599 /// createClassType - Create debugging information entry for a class.
600 DICompositeType DIBuilder::createClassType(DIDescriptor Context, StringRef Name,
601 DIFile File, unsigned LineNumber,
603 uint64_t AlignInBits,
604 uint64_t OffsetInBits,
605 unsigned Flags, DIType DerivedFrom,
608 MDNode *TemplateParams,
609 StringRef UniqueIdentifier) {
610 assert((!Context || Context.isScope() || Context.isType()) &&
611 "createClassType should be called with a valid Context");
612 // TAG_class_type is encoded in DICompositeType format.
614 GetTagConstant(VMContext, dwarf::DW_TAG_class_type),
616 DIScope(getNonCompileUnitScope(Context)).getRef(),
617 MDString::get(VMContext, Name),
618 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
619 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
620 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
621 ConstantInt::get(Type::getInt32Ty(VMContext), OffsetInBits),
622 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
623 DerivedFrom.getRef(),
625 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
626 VTableHolder.getRef(),
628 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
630 DICompositeType R(MDNode::get(VMContext, Elts));
631 assert(R.isCompositeType() &&
632 "createClassType should return a DICompositeType");
633 if (!UniqueIdentifier.empty())
638 /// createStructType - Create debugging information entry for a struct.
639 DICompositeType DIBuilder::createStructType(DIDescriptor Context,
640 StringRef Name, DIFile File,
643 uint64_t AlignInBits,
644 unsigned Flags, DIType DerivedFrom,
646 unsigned RunTimeLang,
648 StringRef UniqueIdentifier) {
649 // TAG_structure_type is encoded in DICompositeType format.
651 GetTagConstant(VMContext, dwarf::DW_TAG_structure_type),
653 DIScope(getNonCompileUnitScope(Context)).getRef(),
654 MDString::get(VMContext, Name),
655 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
656 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
657 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
658 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
659 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
660 DerivedFrom.getRef(),
662 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
663 VTableHolder.getRef(),
665 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
667 DICompositeType R(MDNode::get(VMContext, Elts));
668 assert(R.isCompositeType() &&
669 "createStructType should return a DICompositeType");
670 if (!UniqueIdentifier.empty())
675 /// createUnionType - Create debugging information entry for an union.
676 DICompositeType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name,
677 DIFile File, unsigned LineNumber,
679 uint64_t AlignInBits, unsigned Flags,
681 unsigned RunTimeLang,
682 StringRef UniqueIdentifier) {
683 // TAG_union_type is encoded in DICompositeType format.
685 GetTagConstant(VMContext, dwarf::DW_TAG_union_type),
687 DIScope(getNonCompileUnitScope(Scope)).getRef(),
688 MDString::get(VMContext, Name),
689 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
690 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
691 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
692 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
693 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
696 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
699 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
701 DICompositeType R(MDNode::get(VMContext, Elts));
702 if (!UniqueIdentifier.empty())
707 /// createSubroutineType - Create subroutine type.
708 DICompositeType DIBuilder::createSubroutineType(DIFile File,
709 DIArray ParameterTypes,
711 // TAG_subroutine_type is encoded in DICompositeType format.
713 GetTagConstant(VMContext, dwarf::DW_TAG_subroutine_type),
714 Constant::getNullValue(Type::getInt32Ty(VMContext)),
716 MDString::get(VMContext, ""),
717 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
718 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
719 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
720 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
721 ConstantInt::get(Type::getInt32Ty(VMContext), Flags), // Flags
724 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
727 NULL // Type Identifer
729 return DICompositeType(MDNode::get(VMContext, Elts));
732 /// createEnumerationType - Create debugging information entry for an
734 DICompositeType DIBuilder::createEnumerationType(
735 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
736 uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
737 DIType UnderlyingType, StringRef UniqueIdentifier) {
738 // TAG_enumeration_type is encoded in DICompositeType format.
740 GetTagConstant(VMContext, dwarf::DW_TAG_enumeration_type),
742 DIScope(getNonCompileUnitScope(Scope)).getRef(),
743 MDString::get(VMContext, Name),
744 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
745 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
746 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
747 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
748 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
749 UnderlyingType.getRef(),
751 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
754 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
756 DICompositeType CTy(MDNode::get(VMContext, Elts));
757 AllEnumTypes.push_back(CTy);
758 if (!UniqueIdentifier.empty())
763 /// createArrayType - Create debugging information entry for an array.
764 DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
765 DIType Ty, DIArray Subscripts) {
766 // TAG_array_type is encoded in DICompositeType format.
768 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
769 NULL, // Filename/Directory,
771 MDString::get(VMContext, ""),
772 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
773 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
774 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
775 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
776 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
779 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
782 NULL // Type Identifer
784 return DICompositeType(MDNode::get(VMContext, Elts));
787 /// createVectorType - Create debugging information entry for a vector.
788 DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits,
789 DIType Ty, DIArray Subscripts) {
790 // A vector is an array type with the FlagVector flag applied.
792 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
793 NULL, // Filename/Directory,
795 MDString::get(VMContext, ""),
796 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
797 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
798 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
799 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
800 ConstantInt::get(Type::getInt32Ty(VMContext), DIType::FlagVector),
803 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
806 NULL // Type Identifer
808 return DICompositeType(MDNode::get(VMContext, Elts));
811 /// createArtificialType - Create a new DIType with "artificial" flag set.
812 DIType DIBuilder::createArtificialType(DIType Ty) {
813 if (Ty.isArtificial())
816 SmallVector<Value *, 9> Elts;
818 assert (N && "Unexpected input DIType!");
819 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
820 Elts.push_back(N->getOperand(i));
822 unsigned CurFlags = Ty.getFlags();
823 CurFlags = CurFlags | DIType::FlagArtificial;
825 // Flags are stored at this slot.
826 // FIXME: Add an enum for this magic value.
827 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
829 return DIType(MDNode::get(VMContext, Elts));
832 /// createObjectPointerType - Create a new type with both the object pointer
833 /// and artificial flags set.
834 DIType DIBuilder::createObjectPointerType(DIType Ty) {
835 if (Ty.isObjectPointer())
838 SmallVector<Value *, 9> Elts;
840 assert (N && "Unexpected input DIType!");
841 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
842 Elts.push_back(N->getOperand(i));
844 unsigned CurFlags = Ty.getFlags();
845 CurFlags = CurFlags | (DIType::FlagObjectPointer | DIType::FlagArtificial);
847 // Flags are stored at this slot.
848 // FIXME: Add an enum for this magic value.
849 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
851 return DIType(MDNode::get(VMContext, Elts));
854 /// retainType - Retain DIType in a module even if it is not referenced
855 /// through debug info anchors.
856 void DIBuilder::retainType(DIType T) {
857 AllRetainTypes.push_back(TrackingVH<MDNode>(T));
860 /// createUnspecifiedParameter - Create unspeicified type descriptor
861 /// for the subroutine type.
862 DIDescriptor DIBuilder::createUnspecifiedParameter() {
864 GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_parameters)
866 return DIDescriptor(MDNode::get(VMContext, Elts));
869 /// createForwardDecl - Create a temporary forward-declared type that
870 /// can be RAUW'd if the full type is seen.
872 DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope,
873 DIFile F, unsigned Line, unsigned RuntimeLang,
874 uint64_t SizeInBits, uint64_t AlignInBits,
875 StringRef UniqueIdentifier) {
876 // Create a temporary MDNode.
878 GetTagConstant(VMContext, Tag),
880 DIScope(getNonCompileUnitScope(Scope)).getRef(),
881 MDString::get(VMContext, Name),
882 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
883 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
884 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
885 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
886 ConstantInt::get(Type::getInt32Ty(VMContext), DIDescriptor::FlagFwdDecl),
889 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang),
891 NULL, //TemplateParams
892 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
894 MDNode *Node = MDNode::getTemporary(VMContext, Elts);
895 DICompositeType RetTy(Node);
896 assert(RetTy.isCompositeType() &&
897 "createForwardDecl result should be a DIType");
898 if (!UniqueIdentifier.empty())
903 /// getOrCreateArray - Get a DIArray, create one if required.
904 DIArray DIBuilder::getOrCreateArray(ArrayRef<Value *> Elements) {
905 if (Elements.empty()) {
906 Value *Null = Constant::getNullValue(Type::getInt32Ty(VMContext));
907 return DIArray(MDNode::get(VMContext, Null));
909 return DIArray(MDNode::get(VMContext, Elements));
912 /// getOrCreateSubrange - Create a descriptor for a value range. This
913 /// implicitly uniques the values returned.
914 DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
916 GetTagConstant(VMContext, dwarf::DW_TAG_subrange_type),
917 ConstantInt::get(Type::getInt64Ty(VMContext), Lo),
918 ConstantInt::get(Type::getInt64Ty(VMContext), Count)
921 return DISubrange(MDNode::get(VMContext, Elts));
924 /// \brief Create a new descriptor for the specified global.
925 DIGlobalVariable DIBuilder::createGlobalVariable(StringRef Name,
926 StringRef LinkageName,
927 DIFile F, unsigned LineNumber,
928 DIType Ty, bool isLocalToUnit,
931 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
932 Constant::getNullValue(Type::getInt32Ty(VMContext)),
934 MDString::get(VMContext, Name),
935 MDString::get(VMContext, Name),
936 MDString::get(VMContext, LinkageName),
938 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
940 ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
941 ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
945 MDNode *Node = MDNode::get(VMContext, Elts);
946 AllGVs.push_back(Node);
947 return DIGlobalVariable(Node);
950 /// \brief Create a new descriptor for the specified global.
951 DIGlobalVariable DIBuilder::createGlobalVariable(StringRef Name, DIFile F,
952 unsigned LineNumber, DIType Ty,
955 return createGlobalVariable(Name, Name, F, LineNumber, Ty, isLocalToUnit,
959 /// createStaticVariable - Create a new descriptor for the specified static
961 DIGlobalVariable DIBuilder::createStaticVariable(DIDescriptor Context,
963 StringRef LinkageName,
964 DIFile F, unsigned LineNumber,
965 DIType Ty, bool isLocalToUnit,
966 Value *Val, MDNode *Decl) {
968 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
969 Constant::getNullValue(Type::getInt32Ty(VMContext)),
970 getNonCompileUnitScope(Context),
971 MDString::get(VMContext, Name),
972 MDString::get(VMContext, Name),
973 MDString::get(VMContext, LinkageName),
975 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
977 ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
978 ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
982 MDNode *Node = MDNode::get(VMContext, Elts);
983 AllGVs.push_back(Node);
984 return DIGlobalVariable(Node);
987 /// createVariable - Create a new descriptor for the specified variable.
988 DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
989 StringRef Name, DIFile File,
990 unsigned LineNo, DIType Ty,
991 bool AlwaysPreserve, unsigned Flags,
993 DIDescriptor Context(getNonCompileUnitScope(Scope));
994 assert((!Context || Context.isScope()) &&
995 "createLocalVariable should be called with a valid Context");
996 assert(Ty.isType() &&
997 "createLocalVariable should be called with a valid type");
999 GetTagConstant(VMContext, Tag),
1000 getNonCompileUnitScope(Scope),
1001 MDString::get(VMContext, Name),
1003 ConstantInt::get(Type::getInt32Ty(VMContext), (LineNo | (ArgNo << 24))),
1005 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1006 Constant::getNullValue(Type::getInt32Ty(VMContext))
1008 MDNode *Node = MDNode::get(VMContext, Elts);
1009 if (AlwaysPreserve) {
1010 // The optimizer may remove local variable. If there is an interest
1011 // to preserve variable info in such situation then stash it in a
1013 DISubprogram Fn(getDISubprogram(Scope));
1014 NamedMDNode *FnLocals = getOrInsertFnSpecificMDNode(M, Fn);
1015 FnLocals->addOperand(Node);
1017 DIVariable RetVar(Node);
1018 assert(RetVar.isVariable() &&
1019 "createLocalVariable should return a valid DIVariable");
1023 /// createComplexVariable - Create a new descriptor for the specified variable
1024 /// which has a complex address expression for its address.
1025 DIVariable DIBuilder::createComplexVariable(unsigned Tag, DIDescriptor Scope,
1026 StringRef Name, DIFile F,
1028 DIType Ty, ArrayRef<Value *> Addr,
1030 SmallVector<Value *, 15> Elts;
1031 Elts.push_back(GetTagConstant(VMContext, Tag));
1032 Elts.push_back(getNonCompileUnitScope(Scope)),
1033 Elts.push_back(MDString::get(VMContext, Name));
1035 Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext),
1036 (LineNo | (ArgNo << 24))));
1038 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
1039 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
1040 Elts.append(Addr.begin(), Addr.end());
1042 return DIVariable(MDNode::get(VMContext, Elts));
1045 /// createFunction - Create a new descriptor for the specified function.
1046 /// FIXME: this is added for dragonegg. Once we update dragonegg
1047 /// to call resolve function, this will be removed.
1048 DISubprogram DIBuilder::createFunction(DIScopeRef Context, StringRef Name,
1049 StringRef LinkageName, DIFile File,
1050 unsigned LineNo, DICompositeType Ty,
1051 bool isLocalToUnit, bool isDefinition,
1052 unsigned ScopeLine, unsigned Flags,
1053 bool isOptimized, Function *Fn,
1054 MDNode *TParams, MDNode *Decl) {
1055 // dragonegg does not generate identifier for types, so using an empty map
1056 // to resolve the context should be fine.
1057 DITypeIdentifierMap EmptyMap;
1058 return createFunction(Context.resolve(EmptyMap), Name, LinkageName, File,
1059 LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine,
1060 Flags, isOptimized, Fn, TParams, Decl);
1063 /// createFunction - Create a new descriptor for the specified function.
1064 DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name,
1065 StringRef LinkageName, DIFile File,
1066 unsigned LineNo, DICompositeType Ty,
1067 bool isLocalToUnit, bool isDefinition,
1068 unsigned ScopeLine, unsigned Flags,
1069 bool isOptimized, Function *Fn,
1070 MDNode *TParams, MDNode *Decl) {
1071 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1072 "function types should be subroutines");
1073 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
1075 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
1077 DIScope(getNonCompileUnitScope(Context)).getRef(),
1078 MDString::get(VMContext, Name),
1079 MDString::get(VMContext, Name),
1080 MDString::get(VMContext, LinkageName),
1081 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1083 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1084 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1085 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
1086 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
1088 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1089 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
1093 MDNode::getTemporary(VMContext, TElts),
1094 ConstantInt::get(Type::getInt32Ty(VMContext), ScopeLine)
1096 MDNode *Node = MDNode::get(VMContext, Elts);
1098 // Create a named metadata so that we do not lose this mdnode.
1100 AllSubprograms.push_back(Node);
1101 DISubprogram S(Node);
1102 assert(S.isSubprogram() && "createFunction should return a valid DISubprogram");
1106 /// createMethod - Create a new descriptor for the specified C++ method.
1107 DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
1108 StringRef LinkageName, DIFile F,
1109 unsigned LineNo, DICompositeType Ty,
1110 bool isLocalToUnit, bool isDefinition,
1111 unsigned VK, unsigned VIndex,
1112 DIType VTableHolder, unsigned Flags,
1113 bool isOptimized, Function *Fn,
1115 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1116 "function types should be subroutines");
1117 assert(getNonCompileUnitScope(Context) &&
1118 "Methods should have both a Context and a context that isn't "
1119 "the compile unit.");
1120 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
1122 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
1124 DIScope(Context).getRef(),
1125 MDString::get(VMContext, Name),
1126 MDString::get(VMContext, Name),
1127 MDString::get(VMContext, LinkageName),
1128 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1130 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1131 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1132 ConstantInt::get(Type::getInt32Ty(VMContext), VK),
1133 ConstantInt::get(Type::getInt32Ty(VMContext), VIndex),
1134 VTableHolder.getRef(),
1135 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1136 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
1139 Constant::getNullValue(Type::getInt32Ty(VMContext)),
1140 MDNode::getTemporary(VMContext, TElts),
1141 // FIXME: Do we want to use different scope/lines?
1142 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
1144 MDNode *Node = MDNode::get(VMContext, Elts);
1146 AllSubprograms.push_back(Node);
1147 DISubprogram S(Node);
1148 assert(S.isSubprogram() && "createMethod should return a valid DISubprogram");
1152 /// createNameSpace - This creates new descriptor for a namespace
1153 /// with the specified parent scope.
1154 DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
1155 DIFile File, unsigned LineNo) {
1157 GetTagConstant(VMContext, dwarf::DW_TAG_namespace),
1159 getNonCompileUnitScope(Scope),
1160 MDString::get(VMContext, Name),
1161 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
1163 DINameSpace R(MDNode::get(VMContext, Elts));
1164 assert(R.Verify() &&
1165 "createNameSpace should return a verifiable DINameSpace");
1169 /// createLexicalBlockFile - This creates a new MDNode that encapsulates
1170 /// an existing scope with a new filename.
1171 DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
1174 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
1178 DILexicalBlockFile R(MDNode::get(VMContext, Elts));
1181 "createLexicalBlockFile should return a verifiable DILexicalBlockFile");
1185 DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
1186 unsigned Line, unsigned Col) {
1187 // Defeat MDNode uniquing for lexical blocks by using unique id.
1188 static unsigned int unique_id = 0;
1190 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
1192 getNonCompileUnitScope(Scope),
1193 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
1194 ConstantInt::get(Type::getInt32Ty(VMContext), Col),
1195 ConstantInt::get(Type::getInt32Ty(VMContext), unique_id++)
1197 DILexicalBlock R(MDNode::get(VMContext, Elts));
1198 assert(R.Verify() &&
1199 "createLexicalBlock should return a verifiable DILexicalBlock");
1203 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1204 Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
1205 Instruction *InsertBefore) {
1206 assert(Storage && "no storage passed to dbg.declare");
1207 assert(VarInfo.isVariable() &&
1208 "empty or invalid DIVariable passed to dbg.declare");
1210 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1212 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
1213 return CallInst::Create(DeclareFn, Args, "", InsertBefore);
1216 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1217 Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
1218 BasicBlock *InsertAtEnd) {
1219 assert(Storage && "no storage passed to dbg.declare");
1220 assert(VarInfo.isVariable() &&
1221 "empty or invalid DIVariable passed to dbg.declare");
1223 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1225 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
1227 // If this block already has a terminator then insert this intrinsic
1228 // before the terminator.
1229 if (TerminatorInst *T = InsertAtEnd->getTerminator())
1230 return CallInst::Create(DeclareFn, Args, "", T);
1232 return CallInst::Create(DeclareFn, Args, "", InsertAtEnd);
1235 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1236 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
1238 Instruction *InsertBefore) {
1239 assert(V && "no value passed to dbg.value");
1240 assert(VarInfo.isVariable() &&
1241 "empty or invalid DIVariable passed to dbg.value");
1243 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1245 Value *Args[] = { MDNode::get(V->getContext(), V),
1246 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1248 return CallInst::Create(ValueFn, Args, "", InsertBefore);
1251 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1252 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
1254 BasicBlock *InsertAtEnd) {
1255 assert(V && "no value passed to dbg.value");
1256 assert(VarInfo.isVariable() &&
1257 "empty or invalid DIVariable passed to dbg.value");
1259 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1261 Value *Args[] = { MDNode::get(V->getContext(), V),
1262 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1264 return CallInst::Create(ValueFn, Args, "", InsertAtEnd);