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/IR/DIBuilder.h"
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/IR/Constants.h"
17 #include "llvm/IR/DebugInfo.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(nullptr),
34 TempRetainTypes(nullptr), TempSubprograms(nullptr), TempGVs(nullptr),
35 DeclareFn(nullptr), ValueFn(nullptr) {}
37 /// finalize - Construct any deferred debug info descriptors.
38 void DIBuilder::finalize() {
39 DIArray Enums = getOrCreateArray(AllEnumTypes);
40 DIType(TempEnumTypes).replaceAllUsesWith(Enums);
42 SmallVector<Value *, 16> RetainValues;
43 // Declarations and definitions of the same type may be retained. Some
44 // clients RAUW these pairs, leaving duplicates in the retained types
45 // list. Use a set to remove the duplicates while we transform the
46 // TrackingVHs back into Values.
47 SmallPtrSet<Value *, 16> RetainSet;
48 for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++)
49 if (RetainSet.insert(AllRetainTypes[I]))
50 RetainValues.push_back(AllRetainTypes[I]);
51 DIArray RetainTypes = getOrCreateArray(RetainValues);
52 DIType(TempRetainTypes).replaceAllUsesWith(RetainTypes);
54 DIArray SPs = getOrCreateArray(AllSubprograms);
55 DIType(TempSubprograms).replaceAllUsesWith(SPs);
56 for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
57 DISubprogram SP(SPs.getElement(i));
58 SmallVector<Value *, 4> Variables;
59 if (NamedMDNode *NMD = getFnSpecificMDNode(M, SP)) {
60 for (unsigned ii = 0, ee = NMD->getNumOperands(); ii != ee; ++ii)
61 Variables.push_back(NMD->getOperand(ii));
62 NMD->eraseFromParent();
64 if (MDNode *Temp = SP.getVariablesNodes()) {
65 DIArray AV = getOrCreateArray(Variables);
66 DIType(Temp).replaceAllUsesWith(AV);
70 DIArray GVs = getOrCreateArray(AllGVs);
71 DIType(TempGVs).replaceAllUsesWith(GVs);
73 SmallVector<Value *, 16> RetainValuesI;
74 for (unsigned I = 0, E = AllImportedModules.size(); I < E; I++)
75 RetainValuesI.push_back(AllImportedModules[I]);
76 DIArray IMs = getOrCreateArray(RetainValuesI);
77 DIType(TempImportedModules).replaceAllUsesWith(IMs);
80 /// getNonCompileUnitScope - If N is compile unit return NULL otherwise return
82 static MDNode *getNonCompileUnitScope(MDNode *N) {
83 if (DIDescriptor(N).isCompileUnit())
88 static MDNode *createFilePathPair(LLVMContext &VMContext, StringRef Filename,
89 StringRef Directory) {
90 assert(!Filename.empty() && "Unable to create file without name");
92 MDString::get(VMContext, Filename),
93 MDString::get(VMContext, Directory)
95 return MDNode::get(VMContext, Pair);
98 /// createCompileUnit - A CompileUnit provides an anchor for all debugging
99 /// information generated during this instance of compilation.
100 DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename,
102 StringRef Producer, bool isOptimized,
103 StringRef Flags, unsigned RunTimeVer,
105 DebugEmissionKind Kind) {
107 assert(((Lang <= dwarf::DW_LANG_Python && Lang >= dwarf::DW_LANG_C89) ||
108 (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
109 "Invalid Language tag");
110 assert(!Filename.empty() &&
111 "Unable to create compile unit without filename");
112 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
113 TempEnumTypes = MDNode::getTemporary(VMContext, TElts);
115 TempRetainTypes = MDNode::getTemporary(VMContext, TElts);
117 TempSubprograms = MDNode::getTemporary(VMContext, TElts);
119 TempGVs = MDNode::getTemporary(VMContext, TElts);
121 TempImportedModules = MDNode::getTemporary(VMContext, TElts);
124 GetTagConstant(VMContext, dwarf::DW_TAG_compile_unit),
125 createFilePathPair(VMContext, Filename, Directory),
126 ConstantInt::get(Type::getInt32Ty(VMContext), Lang),
127 MDString::get(VMContext, Producer),
128 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
129 MDString::get(VMContext, Flags),
130 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer),
136 MDString::get(VMContext, SplitName),
137 ConstantInt::get(Type::getInt32Ty(VMContext), Kind)
140 MDNode *CUNode = MDNode::get(VMContext, Elts);
142 // Create a named metadata so that it is easier to find cu in a module.
143 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
144 NMD->addOperand(CUNode);
146 return DICompileUnit(CUNode);
149 static DIImportedEntity
150 createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope Context,
151 Value *NS, unsigned Line, StringRef Name,
152 SmallVectorImpl<TrackingVH<MDNode>> &AllImportedModules) {
156 GetTagConstant(C, Tag),
159 ConstantInt::get(Type::getInt32Ty(C), Line),
161 R = MDNode::get(C, Elts);
164 GetTagConstant(C, Tag),
167 ConstantInt::get(Type::getInt32Ty(C), Line),
168 MDString::get(C, Name)
170 R = MDNode::get(C, Elts);
172 DIImportedEntity M(R);
173 assert(M.Verify() && "Imported module should be valid");
174 AllImportedModules.push_back(TrackingVH<MDNode>(M));
178 DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
181 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
182 Context, NS, Line, StringRef(), AllImportedModules);
185 DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
188 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
189 Context, NS, Line, StringRef(), AllImportedModules);
192 DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
194 unsigned Line, StringRef Name) {
195 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
196 Context, Decl.getRef(), Line, Name,
200 DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
201 DIImportedEntity Imp,
202 unsigned Line, StringRef Name) {
203 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
204 Context, Imp, Line, Name, AllImportedModules);
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 nullptr, // 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() ? nullptr
635 : MDString::get(VMContext, UniqueIdentifier)
637 DICompositeType R(MDNode::get(VMContext, Elts));
638 assert(R.isCompositeType() &&
639 "createClassType should return a DICompositeType");
640 if (!UniqueIdentifier.empty())
645 /// createStructType - Create debugging information entry for a struct.
646 DICompositeType DIBuilder::createStructType(DIDescriptor Context,
647 StringRef Name, DIFile File,
650 uint64_t AlignInBits,
651 unsigned Flags, DIType DerivedFrom,
653 unsigned RunTimeLang,
655 StringRef UniqueIdentifier) {
656 // TAG_structure_type is encoded in DICompositeType format.
658 GetTagConstant(VMContext, dwarf::DW_TAG_structure_type),
660 DIScope(getNonCompileUnitScope(Context)).getRef(),
661 MDString::get(VMContext, Name),
662 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
663 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
664 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
665 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
666 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
667 DerivedFrom.getRef(),
669 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
670 VTableHolder.getRef(),
672 UniqueIdentifier.empty() ? nullptr
673 : MDString::get(VMContext, UniqueIdentifier)
675 DICompositeType R(MDNode::get(VMContext, Elts));
676 assert(R.isCompositeType() &&
677 "createStructType should return a DICompositeType");
678 if (!UniqueIdentifier.empty())
683 /// createUnionType - Create debugging information entry for an union.
684 DICompositeType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name,
685 DIFile File, unsigned LineNumber,
687 uint64_t AlignInBits, unsigned Flags,
689 unsigned RunTimeLang,
690 StringRef UniqueIdentifier) {
691 // TAG_union_type is encoded in DICompositeType format.
693 GetTagConstant(VMContext, dwarf::DW_TAG_union_type),
695 DIScope(getNonCompileUnitScope(Scope)).getRef(),
696 MDString::get(VMContext, Name),
697 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
698 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
699 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
700 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
701 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
704 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
707 UniqueIdentifier.empty() ? nullptr
708 : MDString::get(VMContext, UniqueIdentifier)
710 DICompositeType R(MDNode::get(VMContext, Elts));
711 if (!UniqueIdentifier.empty())
716 /// createSubroutineType - Create subroutine type.
717 DICompositeType DIBuilder::createSubroutineType(DIFile File,
718 DIArray ParameterTypes,
720 // TAG_subroutine_type is encoded in DICompositeType format.
722 GetTagConstant(VMContext, dwarf::DW_TAG_subroutine_type),
723 Constant::getNullValue(Type::getInt32Ty(VMContext)),
725 MDString::get(VMContext, ""),
726 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
727 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
728 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
729 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
730 ConstantInt::get(Type::getInt32Ty(VMContext), Flags), // Flags
733 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
736 nullptr // Type Identifer
738 return DICompositeType(MDNode::get(VMContext, Elts));
741 /// createEnumerationType - Create debugging information entry for an
743 DICompositeType DIBuilder::createEnumerationType(
744 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
745 uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
746 DIType UnderlyingType, StringRef UniqueIdentifier) {
747 // TAG_enumeration_type is encoded in DICompositeType format.
749 GetTagConstant(VMContext, dwarf::DW_TAG_enumeration_type),
751 DIScope(getNonCompileUnitScope(Scope)).getRef(),
752 MDString::get(VMContext, Name),
753 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
754 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
755 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
756 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
757 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
758 UnderlyingType.getRef(),
760 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
763 UniqueIdentifier.empty() ? nullptr
764 : MDString::get(VMContext, UniqueIdentifier)
766 DICompositeType CTy(MDNode::get(VMContext, Elts));
767 AllEnumTypes.push_back(CTy);
768 if (!UniqueIdentifier.empty())
773 /// createArrayType - Create debugging information entry for an array.
774 DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
775 DIType Ty, DIArray Subscripts) {
776 // TAG_array_type is encoded in DICompositeType format.
778 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
779 nullptr, // Filename/Directory,
781 MDString::get(VMContext, ""),
782 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
783 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
784 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
785 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
786 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
789 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
792 nullptr // Type Identifer
794 return DICompositeType(MDNode::get(VMContext, Elts));
797 /// createVectorType - Create debugging information entry for a vector.
798 DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits,
799 DIType Ty, DIArray Subscripts) {
800 // A vector is an array type with the FlagVector flag applied.
802 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
803 nullptr, // Filename/Directory,
805 MDString::get(VMContext, ""),
806 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
807 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
808 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
809 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
810 ConstantInt::get(Type::getInt32Ty(VMContext), DIType::FlagVector),
813 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
816 nullptr // Type Identifer
818 return DICompositeType(MDNode::get(VMContext, Elts));
821 /// createArtificialType - Create a new DIType with "artificial" flag set.
822 DIType DIBuilder::createArtificialType(DIType Ty) {
823 if (Ty.isArtificial())
826 SmallVector<Value *, 9> Elts;
828 assert (N && "Unexpected input DIType!");
829 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
830 Elts.push_back(N->getOperand(i));
832 unsigned CurFlags = Ty.getFlags();
833 CurFlags = CurFlags | DIType::FlagArtificial;
835 // Flags are stored at this slot.
836 // FIXME: Add an enum for this magic value.
837 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
839 return DIType(MDNode::get(VMContext, Elts));
842 /// createObjectPointerType - Create a new type with both the object pointer
843 /// and artificial flags set.
844 DIType DIBuilder::createObjectPointerType(DIType Ty) {
845 if (Ty.isObjectPointer())
848 SmallVector<Value *, 9> Elts;
850 assert (N && "Unexpected input DIType!");
851 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
852 Elts.push_back(N->getOperand(i));
854 unsigned CurFlags = Ty.getFlags();
855 CurFlags = CurFlags | (DIType::FlagObjectPointer | DIType::FlagArtificial);
857 // Flags are stored at this slot.
858 // FIXME: Add an enum for this magic value.
859 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
861 return DIType(MDNode::get(VMContext, Elts));
864 /// retainType - Retain DIType in a module even if it is not referenced
865 /// through debug info anchors.
866 void DIBuilder::retainType(DIType T) {
867 AllRetainTypes.push_back(TrackingVH<MDNode>(T));
870 /// createUnspecifiedParameter - Create unspeicified type descriptor
871 /// for the subroutine type.
872 DIDescriptor DIBuilder::createUnspecifiedParameter() {
874 GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_parameters)
876 return DIDescriptor(MDNode::get(VMContext, Elts));
879 /// createForwardDecl - Create a temporary forward-declared type that
880 /// can be RAUW'd if the full type is seen.
882 DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope,
883 DIFile F, unsigned Line, unsigned RuntimeLang,
884 uint64_t SizeInBits, uint64_t AlignInBits,
885 StringRef UniqueIdentifier) {
886 // Create a temporary MDNode.
888 GetTagConstant(VMContext, Tag),
890 DIScope(getNonCompileUnitScope(Scope)).getRef(),
891 MDString::get(VMContext, Name),
892 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
893 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
894 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
895 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
896 ConstantInt::get(Type::getInt32Ty(VMContext), DIDescriptor::FlagFwdDecl),
899 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang),
901 nullptr, //TemplateParams
902 UniqueIdentifier.empty() ? nullptr
903 : MDString::get(VMContext, UniqueIdentifier)
905 MDNode *Node = MDNode::getTemporary(VMContext, Elts);
906 DICompositeType RetTy(Node);
907 assert(RetTy.isCompositeType() &&
908 "createForwardDecl result should be a DIType");
909 if (!UniqueIdentifier.empty())
914 /// getOrCreateArray - Get a DIArray, create one if required.
915 DIArray DIBuilder::getOrCreateArray(ArrayRef<Value *> Elements) {
916 return DIArray(MDNode::get(VMContext, Elements));
919 /// getOrCreateSubrange - Create a descriptor for a value range. This
920 /// implicitly uniques the values returned.
921 DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
923 GetTagConstant(VMContext, dwarf::DW_TAG_subrange_type),
924 ConstantInt::get(Type::getInt64Ty(VMContext), Lo),
925 ConstantInt::get(Type::getInt64Ty(VMContext), Count)
928 return DISubrange(MDNode::get(VMContext, Elts));
931 /// \brief Create a new descriptor for the specified global.
932 DIGlobalVariable DIBuilder::createGlobalVariable(StringRef Name,
933 StringRef LinkageName,
934 DIFile F, unsigned LineNumber,
935 DITypeRef Ty, bool isLocalToUnit,
938 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
939 Constant::getNullValue(Type::getInt32Ty(VMContext)),
941 MDString::get(VMContext, Name),
942 MDString::get(VMContext, Name),
943 MDString::get(VMContext, LinkageName),
945 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
947 ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
948 ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
952 MDNode *Node = MDNode::get(VMContext, Elts);
953 AllGVs.push_back(Node);
954 return DIGlobalVariable(Node);
957 /// \brief Create a new descriptor for the specified global.
958 DIGlobalVariable DIBuilder::createGlobalVariable(StringRef Name, DIFile F,
963 return createGlobalVariable(Name, Name, F, LineNumber, Ty, isLocalToUnit,
967 /// createStaticVariable - Create a new descriptor for the specified static
969 DIGlobalVariable DIBuilder::createStaticVariable(DIDescriptor Context,
971 StringRef LinkageName,
972 DIFile F, unsigned LineNumber,
975 Value *Val, MDNode *Decl) {
977 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
978 Constant::getNullValue(Type::getInt32Ty(VMContext)),
979 getNonCompileUnitScope(Context),
980 MDString::get(VMContext, Name),
981 MDString::get(VMContext, Name),
982 MDString::get(VMContext, LinkageName),
984 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
986 ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
987 ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
991 MDNode *Node = MDNode::get(VMContext, Elts);
992 AllGVs.push_back(Node);
993 return DIGlobalVariable(Node);
996 /// createVariable - Create a new descriptor for the specified variable.
997 DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
998 StringRef Name, DIFile File,
999 unsigned LineNo, DITypeRef Ty,
1000 bool AlwaysPreserve, unsigned Flags,
1002 DIDescriptor Context(getNonCompileUnitScope(Scope));
1003 assert((!Context || Context.isScope()) &&
1004 "createLocalVariable should be called with a valid Context");
1006 GetTagConstant(VMContext, Tag),
1007 getNonCompileUnitScope(Scope),
1008 MDString::get(VMContext, Name),
1010 ConstantInt::get(Type::getInt32Ty(VMContext), (LineNo | (ArgNo << 24))),
1012 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1013 Constant::getNullValue(Type::getInt32Ty(VMContext))
1015 MDNode *Node = MDNode::get(VMContext, Elts);
1016 if (AlwaysPreserve) {
1017 // The optimizer may remove local variable. If there is an interest
1018 // to preserve variable info in such situation then stash it in a
1020 DISubprogram Fn(getDISubprogram(Scope));
1021 NamedMDNode *FnLocals = getOrInsertFnSpecificMDNode(M, Fn);
1022 FnLocals->addOperand(Node);
1024 DIVariable RetVar(Node);
1025 assert(RetVar.isVariable() &&
1026 "createLocalVariable should return a valid DIVariable");
1030 /// createComplexVariable - Create a new descriptor for the specified variable
1031 /// which has a complex address expression for its address.
1032 DIVariable DIBuilder::createComplexVariable(unsigned Tag, DIDescriptor Scope,
1033 StringRef Name, DIFile F,
1036 ArrayRef<Value *> Addr,
1038 SmallVector<Value *, 15> Elts;
1039 Elts.push_back(GetTagConstant(VMContext, Tag));
1040 Elts.push_back(getNonCompileUnitScope(Scope)),
1041 Elts.push_back(MDString::get(VMContext, Name));
1043 Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext),
1044 (LineNo | (ArgNo << 24))));
1046 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
1047 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
1048 Elts.append(Addr.begin(), Addr.end());
1050 return DIVariable(MDNode::get(VMContext, Elts));
1053 /// createFunction - Create a new descriptor for the specified function.
1054 /// FIXME: this is added for dragonegg. Once we update dragonegg
1055 /// to call resolve function, this will be removed.
1056 DISubprogram DIBuilder::createFunction(DIScopeRef Context, StringRef Name,
1057 StringRef LinkageName, DIFile File,
1058 unsigned LineNo, DICompositeType Ty,
1059 bool isLocalToUnit, bool isDefinition,
1060 unsigned ScopeLine, unsigned Flags,
1061 bool isOptimized, Function *Fn,
1062 MDNode *TParams, MDNode *Decl) {
1063 // dragonegg does not generate identifier for types, so using an empty map
1064 // to resolve the context should be fine.
1065 DITypeIdentifierMap EmptyMap;
1066 return createFunction(Context.resolve(EmptyMap), Name, LinkageName, File,
1067 LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine,
1068 Flags, isOptimized, Fn, TParams, Decl);
1071 /// createFunction - Create a new descriptor for the specified function.
1072 DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name,
1073 StringRef LinkageName, DIFile File,
1074 unsigned LineNo, DICompositeType Ty,
1075 bool isLocalToUnit, bool isDefinition,
1076 unsigned ScopeLine, unsigned Flags,
1077 bool isOptimized, Function *Fn,
1078 MDNode *TParams, MDNode *Decl) {
1079 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1080 "function types should be subroutines");
1081 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
1083 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
1085 DIScope(getNonCompileUnitScope(Context)).getRef(),
1086 MDString::get(VMContext, Name),
1087 MDString::get(VMContext, Name),
1088 MDString::get(VMContext, LinkageName),
1089 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1091 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1092 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1093 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
1094 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
1096 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1097 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
1101 MDNode::getTemporary(VMContext, TElts),
1102 ConstantInt::get(Type::getInt32Ty(VMContext), ScopeLine)
1104 MDNode *Node = MDNode::get(VMContext, Elts);
1106 // Create a named metadata so that we do not lose this mdnode.
1108 AllSubprograms.push_back(Node);
1109 DISubprogram S(Node);
1110 assert(S.isSubprogram() &&
1111 "createFunction should return a valid DISubprogram");
1115 /// createMethod - Create a new descriptor for the specified C++ method.
1116 DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
1117 StringRef LinkageName, DIFile F,
1118 unsigned LineNo, DICompositeType Ty,
1119 bool isLocalToUnit, bool isDefinition,
1120 unsigned VK, unsigned VIndex,
1121 DIType VTableHolder, unsigned Flags,
1122 bool isOptimized, Function *Fn,
1124 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1125 "function types should be subroutines");
1126 assert(getNonCompileUnitScope(Context) &&
1127 "Methods should have both a Context and a context that isn't "
1128 "the compile unit.");
1129 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
1131 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
1133 DIScope(Context).getRef(),
1134 MDString::get(VMContext, Name),
1135 MDString::get(VMContext, Name),
1136 MDString::get(VMContext, LinkageName),
1137 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1139 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1140 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1141 ConstantInt::get(Type::getInt32Ty(VMContext), VK),
1142 ConstantInt::get(Type::getInt32Ty(VMContext), VIndex),
1143 VTableHolder.getRef(),
1144 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1145 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
1148 Constant::getNullValue(Type::getInt32Ty(VMContext)),
1149 MDNode::getTemporary(VMContext, TElts),
1150 // FIXME: Do we want to use different scope/lines?
1151 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
1153 MDNode *Node = MDNode::get(VMContext, Elts);
1155 AllSubprograms.push_back(Node);
1156 DISubprogram S(Node);
1157 assert(S.isSubprogram() && "createMethod should return a valid DISubprogram");
1161 /// createNameSpace - This creates new descriptor for a namespace
1162 /// with the specified parent scope.
1163 DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
1164 DIFile File, unsigned LineNo) {
1166 GetTagConstant(VMContext, dwarf::DW_TAG_namespace),
1168 getNonCompileUnitScope(Scope),
1169 MDString::get(VMContext, Name),
1170 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
1172 DINameSpace R(MDNode::get(VMContext, Elts));
1173 assert(R.Verify() &&
1174 "createNameSpace should return a verifiable DINameSpace");
1178 /// createLexicalBlockFile - This creates a new MDNode that encapsulates
1179 /// an existing scope with a new filename.
1180 DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
1183 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
1187 DILexicalBlockFile R(MDNode::get(VMContext, Elts));
1190 "createLexicalBlockFile should return a verifiable DILexicalBlockFile");
1194 DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
1195 unsigned Line, unsigned Col,
1196 unsigned Discriminator) {
1197 // Defeat MDNode uniquing for lexical blocks by using unique id.
1198 static unsigned int unique_id = 0;
1200 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
1202 getNonCompileUnitScope(Scope),
1203 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
1204 ConstantInt::get(Type::getInt32Ty(VMContext), Col),
1205 ConstantInt::get(Type::getInt32Ty(VMContext), Discriminator),
1206 ConstantInt::get(Type::getInt32Ty(VMContext), unique_id++)
1208 DILexicalBlock R(MDNode::get(VMContext, Elts));
1209 assert(R.Verify() &&
1210 "createLexicalBlock should return a verifiable DILexicalBlock");
1214 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1215 Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
1216 Instruction *InsertBefore) {
1217 assert(Storage && "no storage passed to dbg.declare");
1218 assert(VarInfo.isVariable() &&
1219 "empty or invalid DIVariable passed to dbg.declare");
1221 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1223 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
1224 return CallInst::Create(DeclareFn, Args, "", InsertBefore);
1227 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1228 Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
1229 BasicBlock *InsertAtEnd) {
1230 assert(Storage && "no storage passed to dbg.declare");
1231 assert(VarInfo.isVariable() &&
1232 "empty or invalid DIVariable passed to dbg.declare");
1234 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1236 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
1238 // If this block already has a terminator then insert this intrinsic
1239 // before the terminator.
1240 if (TerminatorInst *T = InsertAtEnd->getTerminator())
1241 return CallInst::Create(DeclareFn, Args, "", T);
1243 return CallInst::Create(DeclareFn, Args, "", InsertAtEnd);
1246 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1247 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
1249 Instruction *InsertBefore) {
1250 assert(V && "no value passed to dbg.value");
1251 assert(VarInfo.isVariable() &&
1252 "empty or invalid DIVariable passed to dbg.value");
1254 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1256 Value *Args[] = { MDNode::get(V->getContext(), V),
1257 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1259 return CallInst::Create(ValueFn, Args, "", InsertBefore);
1262 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1263 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
1265 BasicBlock *InsertAtEnd) {
1266 assert(V && "no value passed to dbg.value");
1267 assert(VarInfo.isVariable() &&
1268 "empty or invalid DIVariable passed to dbg.value");
1270 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1272 Value *Args[] = { MDNode::get(V->getContext(), V),
1273 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1275 return CallInst::Create(ValueFn, Args, "", InsertAtEnd);