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),
34 TempRetainTypes(0), TempSubprograms(0), TempGVs(0), DeclareFn(0),
38 /// finalize - Construct any deferred debug info descriptors.
39 void DIBuilder::finalize() {
40 DIArray Enums = getOrCreateArray(AllEnumTypes);
41 DIType(TempEnumTypes).replaceAllUsesWith(Enums);
43 SmallVector<Value *, 16> RetainValues;
44 // Declarations and definitions of the same type may be retained. Some
45 // clients RAUW these pairs, leaving duplicates in the retained types
46 // list. Use a set to remove the duplicates while we transform the
47 // TrackingVHs back into Values.
48 SmallPtrSet<Value *, 16> RetainSet;
49 for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++)
50 if (RetainSet.insert(AllRetainTypes[I]))
51 RetainValues.push_back(AllRetainTypes[I]);
52 DIArray RetainTypes = getOrCreateArray(RetainValues);
53 DIType(TempRetainTypes).replaceAllUsesWith(RetainTypes);
55 DIArray SPs = getOrCreateArray(AllSubprograms);
56 DIType(TempSubprograms).replaceAllUsesWith(SPs);
57 for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
58 DISubprogram SP(SPs.getElement(i));
59 SmallVector<Value *, 4> Variables;
60 if (NamedMDNode *NMD = getFnSpecificMDNode(M, SP)) {
61 for (unsigned ii = 0, ee = NMD->getNumOperands(); ii != ee; ++ii)
62 Variables.push_back(NMD->getOperand(ii));
63 NMD->eraseFromParent();
65 if (MDNode *Temp = SP.getVariablesNodes()) {
66 DIArray AV = getOrCreateArray(Variables);
67 DIType(Temp).replaceAllUsesWith(AV);
71 DIArray GVs = getOrCreateArray(AllGVs);
72 DIType(TempGVs).replaceAllUsesWith(GVs);
74 DIArray IMs = getOrCreateArray(AllImportedModules);
75 DIType(TempImportedModules).replaceAllUsesWith(IMs);
78 /// getNonCompileUnitScope - If N is compile unit return NULL otherwise return
80 static MDNode *getNonCompileUnitScope(MDNode *N) {
81 if (DIDescriptor(N).isCompileUnit())
86 static MDNode *createFilePathPair(LLVMContext &VMContext, StringRef Filename,
87 StringRef Directory) {
88 assert(!Filename.empty() && "Unable to create file without name");
90 MDString::get(VMContext, Filename),
91 MDString::get(VMContext, Directory),
93 return MDNode::get(VMContext, Pair);
96 /// createCompileUnit - A CompileUnit provides an anchor for all debugging
97 /// information generated during this instance of compilation.
98 DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename,
100 StringRef Producer, bool isOptimized,
101 StringRef Flags, unsigned RunTimeVer,
102 StringRef SplitName) {
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)
135 MDNode *CUNode = MDNode::get(VMContext, Elts);
137 // Create a named metadata so that it is easier to find cu in a module.
138 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
139 NMD->addOperand(CUNode);
141 return DICompileUnit(CUNode);
144 static DIImportedEntity
145 createImportedModule(LLVMContext &C, DIScope Context, DIDescriptor NS,
146 unsigned Line, StringRef Name,
147 SmallVectorImpl<Value *> &AllImportedModules) {
151 GetTagConstant(C, dwarf::DW_TAG_imported_module),
154 ConstantInt::get(Type::getInt32Ty(C), Line),
156 R = MDNode::get(C, Elts);
159 GetTagConstant(C, dwarf::DW_TAG_imported_module),
162 ConstantInt::get(Type::getInt32Ty(C), Line),
163 MDString::get(C, Name)
165 R = MDNode::get(C, Elts);
167 DIImportedEntity M(R);
168 assert(M.Verify() && "Imported module should be valid");
169 AllImportedModules.push_back(M);
173 DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
174 DINameSpace NS, unsigned Line,
176 return ::createImportedModule(VMContext, Context, NS, Line, Name,
180 DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
184 return ::createImportedModule(VMContext, Context, NS, Line, Name,
188 DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
192 GetTagConstant(VMContext, dwarf::DW_TAG_imported_declaration),
195 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
197 DIImportedEntity M(MDNode::get(VMContext, Elts));
198 assert(M.Verify() && "Imported module should be valid");
199 AllImportedModules.push_back(M);
203 /// createFile - Create a file descriptor to hold debugging information
205 DIFile DIBuilder::createFile(StringRef Filename, StringRef Directory) {
207 GetTagConstant(VMContext, dwarf::DW_TAG_file_type),
208 createFilePathPair(VMContext, Filename, Directory)
210 return DIFile(MDNode::get(VMContext, Elts));
213 /// createEnumerator - Create a single enumerator value.
214 DIEnumerator DIBuilder::createEnumerator(StringRef Name, int64_t Val) {
215 assert(!Name.empty() && "Unable to create enumerator without name");
217 GetTagConstant(VMContext, dwarf::DW_TAG_enumerator),
218 MDString::get(VMContext, Name),
219 ConstantInt::get(Type::getInt64Ty(VMContext), Val)
221 return DIEnumerator(MDNode::get(VMContext, Elts));
224 /// \brief Create a DWARF unspecified type.
225 DIBasicType DIBuilder::createUnspecifiedType(StringRef Name) {
226 assert(!Name.empty() && "Unable to create type without name");
227 // Unspecified types are encoded in DIBasicType format. Line number, filename,
228 // size, alignment, offset and flags are always empty here.
230 GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_type),
233 MDString::get(VMContext, Name),
234 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
235 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
236 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
237 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
238 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
239 ConstantInt::get(Type::getInt32Ty(VMContext), 0) // Encoding
241 return DIBasicType(MDNode::get(VMContext, Elts));
244 /// \brief Create C++11 nullptr type.
245 DIBasicType DIBuilder::createNullPtrType() {
246 return createUnspecifiedType("decltype(nullptr)");
249 /// createBasicType - Create debugging information entry for a basic
250 /// type, e.g 'char'.
252 DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
253 uint64_t AlignInBits, unsigned Encoding) {
254 assert(!Name.empty() && "Unable to create type without name");
255 // Basic types are encoded in DIBasicType format. Line number, filename,
256 // offset and flags are always empty here.
258 GetTagConstant(VMContext, dwarf::DW_TAG_base_type),
259 NULL, // File/directory name
261 MDString::get(VMContext, Name),
262 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
263 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
264 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
265 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
266 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
267 ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
269 return DIBasicType(MDNode::get(VMContext, Elts));
272 /// createQualifiedType - Create debugging information entry for a qualified
273 /// type, e.g. 'const int'.
274 DIDerivedType DIBuilder::createQualifiedType(unsigned Tag, DIType FromTy) {
275 // Qualified types are encoded in DIDerivedType format.
277 GetTagConstant(VMContext, Tag),
280 MDString::get(VMContext, StringRef()), // Empty name.
281 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
282 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
283 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
284 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
285 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
288 return DIDerivedType(MDNode::get(VMContext, Elts));
291 /// createPointerType - Create debugging information entry for a pointer.
293 DIBuilder::createPointerType(DIType PointeeTy, uint64_t SizeInBits,
294 uint64_t AlignInBits, StringRef Name) {
295 // Pointer types are encoded in DIDerivedType format.
297 GetTagConstant(VMContext, dwarf::DW_TAG_pointer_type),
300 MDString::get(VMContext, Name),
301 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
302 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
303 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
304 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
305 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
308 return DIDerivedType(MDNode::get(VMContext, Elts));
311 DIDerivedType DIBuilder::createMemberPointerType(DIType PointeeTy,
313 // Pointer types are encoded in DIDerivedType format.
315 GetTagConstant(VMContext, dwarf::DW_TAG_ptr_to_member_type),
319 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
320 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
321 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
322 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
323 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
327 return DIDerivedType(MDNode::get(VMContext, Elts));
330 /// createReferenceType - Create debugging information entry for a reference
332 DIDerivedType DIBuilder::createReferenceType(unsigned Tag, DIType RTy) {
333 assert(RTy.isType() && "Unable to create reference type");
334 // References are encoded in DIDerivedType format.
336 GetTagConstant(VMContext, Tag),
340 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
341 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
342 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
343 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
344 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
347 return DIDerivedType(MDNode::get(VMContext, Elts));
350 /// createTypedef - Create debugging information entry for a typedef.
351 DIDerivedType DIBuilder::createTypedef(DIType Ty, StringRef Name, DIFile File,
352 unsigned LineNo, DIDescriptor Context) {
353 // typedefs are encoded in DIDerivedType format.
354 assert(Ty.isType() && "Invalid typedef type!");
356 GetTagConstant(VMContext, dwarf::DW_TAG_typedef),
358 DIScope(getNonCompileUnitScope(Context)).getRef(),
359 MDString::get(VMContext, Name),
360 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
361 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
362 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
363 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
364 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
367 return DIDerivedType(MDNode::get(VMContext, Elts));
370 /// createFriend - Create debugging information entry for a 'friend'.
371 DIDerivedType DIBuilder::createFriend(DIType Ty, DIType FriendTy) {
372 // typedefs are encoded in DIDerivedType format.
373 assert(Ty.isType() && "Invalid type!");
374 assert(FriendTy.isType() && "Invalid friend type!");
376 GetTagConstant(VMContext, dwarf::DW_TAG_friend),
380 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
381 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
382 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
383 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
384 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
387 return DIDerivedType(MDNode::get(VMContext, Elts));
390 /// createInheritance - Create debugging information entry to establish
391 /// inheritance relationship between two types.
392 DIDerivedType DIBuilder::createInheritance(
393 DIType Ty, DIType BaseTy, uint64_t BaseOffset, unsigned Flags) {
394 assert(Ty.isType() && "Unable to create inheritance");
395 // TAG_inheritance is encoded in DIDerivedType format.
397 GetTagConstant(VMContext, dwarf::DW_TAG_inheritance),
401 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
402 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
403 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
404 ConstantInt::get(Type::getInt64Ty(VMContext), BaseOffset),
405 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
408 return DIDerivedType(MDNode::get(VMContext, Elts));
411 /// createMemberType - Create debugging information entry for a member.
412 DIDerivedType DIBuilder::createMemberType(
413 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
414 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
415 unsigned Flags, DIType Ty) {
416 // TAG_member is encoded in DIDerivedType format.
418 GetTagConstant(VMContext, dwarf::DW_TAG_member),
420 DIScope(getNonCompileUnitScope(Scope)).getRef(),
421 MDString::get(VMContext, Name),
422 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
423 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
424 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
425 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
426 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
429 return DIDerivedType(MDNode::get(VMContext, Elts));
432 /// createStaticMemberType - Create debugging information entry for a
433 /// C++ static data member.
435 DIBuilder::createStaticMemberType(DIDescriptor Scope, StringRef Name,
436 DIFile File, unsigned LineNumber,
437 DIType Ty, unsigned Flags,
439 // TAG_member is encoded in DIDerivedType format.
440 Flags |= DIDescriptor::FlagStaticMember;
442 GetTagConstant(VMContext, dwarf::DW_TAG_member),
444 DIScope(getNonCompileUnitScope(Scope)).getRef(),
445 MDString::get(VMContext, Name),
446 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
447 ConstantInt::get(Type::getInt64Ty(VMContext), 0/*SizeInBits*/),
448 ConstantInt::get(Type::getInt64Ty(VMContext), 0/*AlignInBits*/),
449 ConstantInt::get(Type::getInt64Ty(VMContext), 0/*OffsetInBits*/),
450 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
454 return DIDerivedType(MDNode::get(VMContext, Elts));
457 /// createObjCIVar - Create debugging information entry for Objective-C
458 /// instance variable.
460 DIBuilder::createObjCIVar(StringRef Name,
461 DIFile File, unsigned LineNumber,
462 uint64_t SizeInBits, uint64_t AlignInBits,
463 uint64_t OffsetInBits, unsigned Flags,
464 DIType Ty, StringRef PropertyName,
465 StringRef GetterName, StringRef SetterName,
466 unsigned PropertyAttributes) {
467 // TAG_member is encoded in DIDerivedType format.
469 GetTagConstant(VMContext, dwarf::DW_TAG_member),
471 getNonCompileUnitScope(File),
472 MDString::get(VMContext, Name),
473 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
474 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
475 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
476 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
477 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
479 MDString::get(VMContext, PropertyName),
480 MDString::get(VMContext, GetterName),
481 MDString::get(VMContext, SetterName),
482 ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes)
484 return DIDerivedType(MDNode::get(VMContext, Elts));
487 /// createObjCIVar - Create debugging information entry for Objective-C
488 /// instance variable.
490 DIBuilder::createObjCIVar(StringRef Name,
491 DIFile File, unsigned LineNumber,
492 uint64_t SizeInBits, uint64_t AlignInBits,
493 uint64_t OffsetInBits, unsigned Flags,
494 DIType Ty, MDNode *PropertyNode) {
495 // TAG_member is encoded in DIDerivedType format.
497 GetTagConstant(VMContext, dwarf::DW_TAG_member),
499 getNonCompileUnitScope(File),
500 MDString::get(VMContext, Name),
501 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
502 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
503 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
504 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
505 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
509 return DIDerivedType(MDNode::get(VMContext, Elts));
512 /// createObjCProperty - Create debugging information entry for Objective-C
514 DIObjCProperty DIBuilder::createObjCProperty(StringRef Name,
515 DIFile File, unsigned LineNumber,
516 StringRef GetterName,
517 StringRef SetterName,
518 unsigned PropertyAttributes,
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),
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.
712 DIBuilder::createSubroutineType(DIFile File, DIArray ParameterTypes) {
713 // TAG_subroutine_type is encoded in DICompositeType format.
715 GetTagConstant(VMContext, dwarf::DW_TAG_subroutine_type),
716 Constant::getNullValue(Type::getInt32Ty(VMContext)),
718 MDString::get(VMContext, ""),
719 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
720 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
721 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
722 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
723 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
726 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
729 NULL // Type Identifer
731 return DICompositeType(MDNode::get(VMContext, Elts));
734 /// createEnumerationType - Create debugging information entry for an
736 DICompositeType DIBuilder::createEnumerationType(
737 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
738 uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
739 DIType UnderlyingType, StringRef UniqueIdentifier) {
740 // TAG_enumeration_type is encoded in DICompositeType format.
742 GetTagConstant(VMContext, dwarf::DW_TAG_enumeration_type),
744 DIScope(getNonCompileUnitScope(Scope)).getRef(),
745 MDString::get(VMContext, Name),
746 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
747 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
748 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
749 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
750 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
751 UnderlyingType.getRef(),
753 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
756 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
758 MDNode *Node = MDNode::get(VMContext, Elts);
759 AllEnumTypes.push_back(Node);
760 if (!UniqueIdentifier.empty())
762 return DICompositeType(Node);
765 /// createArrayType - Create debugging information entry for an array.
766 DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
767 DIType Ty, DIArray Subscripts) {
768 // TAG_array_type is encoded in DICompositeType format.
770 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
771 NULL, // Filename/Directory,
773 MDString::get(VMContext, ""),
774 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
775 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
776 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
777 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
778 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
781 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
784 NULL // Type Identifer
786 return DICompositeType(MDNode::get(VMContext, Elts));
789 /// createVectorType - Create debugging information entry for a vector.
790 DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits,
791 DIType Ty, DIArray Subscripts) {
792 // A vector is an array type with the FlagVector flag applied.
794 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
795 NULL, // Filename/Directory,
797 MDString::get(VMContext, ""),
798 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
799 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
800 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
801 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
802 ConstantInt::get(Type::getInt32Ty(VMContext), DIType::FlagVector),
805 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
808 NULL // Type Identifer
810 return DICompositeType(MDNode::get(VMContext, Elts));
813 /// createArtificialType - Create a new DIType with "artificial" flag set.
814 DIType DIBuilder::createArtificialType(DIType Ty) {
815 if (Ty.isArtificial())
818 SmallVector<Value *, 9> Elts;
820 assert (N && "Unexpected input DIType!");
821 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
822 Elts.push_back(N->getOperand(i));
824 unsigned CurFlags = Ty.getFlags();
825 CurFlags = CurFlags | DIType::FlagArtificial;
827 // Flags are stored at this slot.
828 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
830 return DIType(MDNode::get(VMContext, Elts));
833 /// createObjectPointerType - Create a new type with both the object pointer
834 /// and artificial flags set.
835 DIType DIBuilder::createObjectPointerType(DIType Ty) {
836 if (Ty.isObjectPointer())
839 SmallVector<Value *, 9> Elts;
841 assert (N && "Unexpected input DIType!");
842 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
843 Elts.push_back(N->getOperand(i));
845 unsigned CurFlags = Ty.getFlags();
846 CurFlags = CurFlags | (DIType::FlagObjectPointer | DIType::FlagArtificial);
848 // Flags are stored at this slot.
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.
871 DICompositeType DIBuilder::createForwardDecl(unsigned Tag, StringRef Name,
872 DIDescriptor Scope, DIFile F,
873 unsigned Line, unsigned RuntimeLang,
875 uint64_t AlignInBits,
876 StringRef UniqueIdentifier) {
877 // Create a temporary MDNode.
879 GetTagConstant(VMContext, Tag),
881 DIScope(getNonCompileUnitScope(Scope)).getRef(),
882 MDString::get(VMContext, Name),
883 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
884 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
885 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
886 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
887 ConstantInt::get(Type::getInt32Ty(VMContext),
888 DIDescriptor::FlagFwdDecl),
891 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang),
893 NULL, //TemplateParams
894 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
896 MDNode *Node = MDNode::getTemporary(VMContext, Elts);
897 DICompositeType RetTy(Node);
898 assert(RetTy.isCompositeType() &&
899 "createForwardDecl result should be a DIType");
900 if (!UniqueIdentifier.empty())
905 /// getOrCreateArray - Get a DIArray, create one if required.
906 DIArray DIBuilder::getOrCreateArray(ArrayRef<Value *> Elements) {
907 if (Elements.empty()) {
908 Value *Null = Constant::getNullValue(Type::getInt32Ty(VMContext));
909 return DIArray(MDNode::get(VMContext, Null));
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::
928 createGlobalVariable(StringRef Name, StringRef LinkageName, DIFile F,
929 unsigned LineNumber, DIType Ty, bool isLocalToUnit,
932 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
933 Constant::getNullValue(Type::getInt32Ty(VMContext)),
935 MDString::get(VMContext, Name),
936 MDString::get(VMContext, Name),
937 MDString::get(VMContext, LinkageName),
939 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
941 ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
942 ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
946 MDNode *Node = MDNode::get(VMContext, Elts);
947 AllGVs.push_back(Node);
948 return DIGlobalVariable(Node);
951 /// \brief Create a new descriptor for the specified global.
952 DIGlobalVariable DIBuilder::
953 createGlobalVariable(StringRef Name, DIFile F, unsigned LineNumber,
954 DIType Ty, bool isLocalToUnit, Value *Val) {
955 return createGlobalVariable(Name, Name, F, LineNumber, Ty, isLocalToUnit,
959 /// createStaticVariable - Create a new descriptor for the specified static
961 DIGlobalVariable DIBuilder::
962 createStaticVariable(DIDescriptor Context, StringRef Name,
963 StringRef LinkageName, DIFile F, unsigned LineNumber,
964 DIType Ty, bool isLocalToUnit, Value *Val, MDNode *Decl) {
966 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
967 Constant::getNullValue(Type::getInt32Ty(VMContext)),
968 getNonCompileUnitScope(Context),
969 MDString::get(VMContext, Name),
970 MDString::get(VMContext, Name),
971 MDString::get(VMContext, LinkageName),
973 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
975 ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
976 ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
980 MDNode *Node = MDNode::get(VMContext, Elts);
981 AllGVs.push_back(Node);
982 return DIGlobalVariable(Node);
985 /// createVariable - Create a new descriptor for the specified variable.
986 DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
987 StringRef Name, DIFile File,
988 unsigned LineNo, DIType Ty,
989 bool AlwaysPreserve, unsigned Flags,
991 DIDescriptor Context(getNonCompileUnitScope(Scope));
992 assert((!Context || Context.isScope()) &&
993 "createLocalVariable should be called with a valid Context");
994 assert(Ty.isType() &&
995 "createLocalVariable should be called with a valid type");
997 GetTagConstant(VMContext, Tag),
998 getNonCompileUnitScope(Scope),
999 MDString::get(VMContext, Name),
1001 ConstantInt::get(Type::getInt32Ty(VMContext), (LineNo | (ArgNo << 24))),
1003 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1004 Constant::getNullValue(Type::getInt32Ty(VMContext))
1006 MDNode *Node = MDNode::get(VMContext, Elts);
1007 if (AlwaysPreserve) {
1008 // The optimizer may remove local variable. If there is an interest
1009 // to preserve variable info in such situation then stash it in a
1011 DISubprogram Fn(getDISubprogram(Scope));
1012 NamedMDNode *FnLocals = getOrInsertFnSpecificMDNode(M, Fn);
1013 FnLocals->addOperand(Node);
1015 DIVariable RetVar(Node);
1016 assert(RetVar.isVariable() &&
1017 "createLocalVariable should return a valid DIVariable");
1021 /// createComplexVariable - Create a new descriptor for the specified variable
1022 /// which has a complex address expression for its address.
1023 DIVariable DIBuilder::createComplexVariable(unsigned Tag, DIDescriptor Scope,
1024 StringRef Name, DIFile F,
1026 DIType Ty, ArrayRef<Value *> Addr,
1028 SmallVector<Value *, 15> Elts;
1029 Elts.push_back(GetTagConstant(VMContext, Tag));
1030 Elts.push_back(getNonCompileUnitScope(Scope)),
1031 Elts.push_back(MDString::get(VMContext, Name));
1033 Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext),
1034 (LineNo | (ArgNo << 24))));
1036 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
1037 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
1038 Elts.append(Addr.begin(), Addr.end());
1040 return DIVariable(MDNode::get(VMContext, Elts));
1043 /// createFunction - Create a new descriptor for the specified function.
1044 /// FIXME: this is added for dragonegg. Once we update dragonegg
1045 /// to call resolve function, this will be removed.
1046 DISubprogram DIBuilder::createFunction(DIScopeRef Context,
1048 StringRef LinkageName,
1049 DIFile File, unsigned LineNo,
1051 bool isLocalToUnit, bool isDefinition,
1053 unsigned Flags, bool isOptimized,
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,
1068 StringRef LinkageName,
1069 DIFile File, unsigned LineNo,
1071 bool isLocalToUnit, bool isDefinition,
1073 unsigned Flags, bool isOptimized,
1077 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1078 "function types should be subroutines");
1079 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
1081 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
1083 DIScope(getNonCompileUnitScope(Context)).getRef(),
1084 MDString::get(VMContext, Name),
1085 MDString::get(VMContext, Name),
1086 MDString::get(VMContext, LinkageName),
1087 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1089 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1090 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1091 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
1092 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
1094 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1095 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
1099 MDNode::getTemporary(VMContext, TElts),
1100 ConstantInt::get(Type::getInt32Ty(VMContext), ScopeLine)
1102 MDNode *Node = MDNode::get(VMContext, Elts);
1104 // Create a named metadata so that we do not lose this mdnode.
1106 AllSubprograms.push_back(Node);
1107 DISubprogram S(Node);
1108 assert(S.isSubprogram() && "createFunction should return a valid DISubprogram");
1112 /// createMethod - Create a new descriptor for the specified C++ method.
1113 DISubprogram DIBuilder::createMethod(DIDescriptor Context,
1115 StringRef LinkageName,
1117 unsigned LineNo, DICompositeType Ty,
1120 unsigned VK, unsigned VIndex,
1121 DIType VTableHolder,
1126 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1127 "function types should be subroutines");
1128 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
1130 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
1132 DIScope(getNonCompileUnitScope(Context)).getRef(),
1133 MDString::get(VMContext, Name),
1134 MDString::get(VMContext, Name),
1135 MDString::get(VMContext, LinkageName),
1136 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1138 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1139 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1140 ConstantInt::get(Type::getInt32Ty(VMContext), (unsigned)VK),
1141 ConstantInt::get(Type::getInt32Ty(VMContext), VIndex),
1142 VTableHolder.getRef(),
1143 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1144 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
1147 Constant::getNullValue(Type::getInt32Ty(VMContext)),
1148 MDNode::getTemporary(VMContext, TElts),
1149 // FIXME: Do we want to use different scope/lines?
1150 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
1152 MDNode *Node = MDNode::get(VMContext, Elts);
1154 AllSubprograms.push_back(Node);
1155 DISubprogram S(Node);
1156 assert(S.isSubprogram() && "createMethod should return a valid DISubprogram");
1160 /// createNameSpace - This creates new descriptor for a namespace
1161 /// with the specified parent scope.
1162 DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
1163 DIFile File, unsigned LineNo) {
1165 GetTagConstant(VMContext, dwarf::DW_TAG_namespace),
1167 getNonCompileUnitScope(Scope),
1168 MDString::get(VMContext, Name),
1169 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
1171 DINameSpace R(MDNode::get(VMContext, Elts));
1172 assert(R.Verify() &&
1173 "createNameSpace should return a verifiable DINameSpace");
1177 /// createLexicalBlockFile - This creates a new MDNode that encapsulates
1178 /// an existing scope with a new filename.
1179 DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
1182 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
1186 DILexicalBlockFile R(MDNode::get(VMContext, Elts));
1189 "createLexicalBlockFile should return a verifiable DILexicalBlockFile");
1193 DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
1194 unsigned Line, unsigned Col) {
1195 // Defeat MDNode uniquing for lexical blocks by using unique id.
1196 static unsigned int unique_id = 0;
1198 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
1200 getNonCompileUnitScope(Scope),
1201 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
1202 ConstantInt::get(Type::getInt32Ty(VMContext), Col),
1203 ConstantInt::get(Type::getInt32Ty(VMContext), unique_id++)
1205 DILexicalBlock R(MDNode::get(VMContext, Elts));
1206 assert(R.Verify() &&
1207 "createLexicalBlock should return a verifiable DILexicalBlock");
1211 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1212 Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
1213 Instruction *InsertBefore) {
1214 assert(Storage && "no storage passed to dbg.declare");
1215 assert(VarInfo.isVariable() &&
1216 "empty or invalid DIVariable passed to dbg.declare");
1218 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1220 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
1221 return CallInst::Create(DeclareFn, Args, "", InsertBefore);
1224 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1225 Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
1226 BasicBlock *InsertAtEnd) {
1227 assert(Storage && "no storage passed to dbg.declare");
1228 assert(VarInfo.isVariable() &&
1229 "empty or invalid DIVariable passed to dbg.declare");
1231 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1233 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
1235 // If this block already has a terminator then insert this intrinsic
1236 // before the terminator.
1237 if (TerminatorInst *T = InsertAtEnd->getTerminator())
1238 return CallInst::Create(DeclareFn, Args, "", T);
1240 return CallInst::Create(DeclareFn, Args, "", InsertAtEnd);
1243 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1244 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
1246 Instruction *InsertBefore) {
1247 assert(V && "no value passed to dbg.value");
1248 assert(VarInfo.isVariable() &&
1249 "empty or invalid DIVariable passed to dbg.value");
1251 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1253 Value *Args[] = { MDNode::get(V->getContext(), V),
1254 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1256 return CallInst::Create(ValueFn, Args, "", InsertBefore);
1259 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1260 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
1262 BasicBlock *InsertAtEnd) {
1263 assert(V && "no value passed to dbg.value");
1264 assert(VarInfo.isVariable() &&
1265 "empty or invalid DIVariable passed to dbg.value");
1267 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1269 Value *Args[] = { MDNode::get(V->getContext(), V),
1270 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1272 return CallInst::Create(ValueFn, Args, "", InsertAtEnd);