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(0), TempRetainTypes(0),
34 TempSubprograms(0), TempGVs(0), DeclareFn(0), ValueFn(0) {}
36 /// finalize - Construct any deferred debug info descriptors.
37 void DIBuilder::finalize() {
38 DIArray Enums = getOrCreateArray(AllEnumTypes);
39 DIType(TempEnumTypes).replaceAllUsesWith(Enums);
41 SmallVector<Value *, 16> RetainValues;
42 // Declarations and definitions of the same type may be retained. Some
43 // clients RAUW these pairs, leaving duplicates in the retained types
44 // list. Use a set to remove the duplicates while we transform the
45 // TrackingVHs back into Values.
46 SmallPtrSet<Value *, 16> RetainSet;
47 for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++)
48 if (RetainSet.insert(AllRetainTypes[I]))
49 RetainValues.push_back(AllRetainTypes[I]);
50 DIArray RetainTypes = getOrCreateArray(RetainValues);
51 DIType(TempRetainTypes).replaceAllUsesWith(RetainTypes);
53 DIArray SPs = getOrCreateArray(AllSubprograms);
54 DIType(TempSubprograms).replaceAllUsesWith(SPs);
55 for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
56 DISubprogram SP(SPs.getElement(i));
57 SmallVector<Value *, 4> Variables;
58 if (NamedMDNode *NMD = getFnSpecificMDNode(M, SP)) {
59 for (unsigned ii = 0, ee = NMD->getNumOperands(); ii != ee; ++ii)
60 Variables.push_back(NMD->getOperand(ii));
61 NMD->eraseFromParent();
63 if (MDNode *Temp = SP.getVariablesNodes()) {
64 DIArray AV = getOrCreateArray(Variables);
65 DIType(Temp).replaceAllUsesWith(AV);
69 DIArray GVs = getOrCreateArray(AllGVs);
70 DIType(TempGVs).replaceAllUsesWith(GVs);
72 SmallVector<Value *, 16> RetainValuesI;
73 for (unsigned I = 0, E = AllImportedModules.size(); I < E; I++)
74 RetainValuesI.push_back(AllImportedModules[I]);
75 DIArray IMs = getOrCreateArray(RetainValuesI);
76 DIType(TempImportedModules).replaceAllUsesWith(IMs);
79 /// getNonCompileUnitScope - If N is compile unit return NULL otherwise return
81 static MDNode *getNonCompileUnitScope(MDNode *N) {
82 if (DIDescriptor(N).isCompileUnit())
87 static MDNode *createFilePathPair(LLVMContext &VMContext, StringRef Filename,
88 StringRef Directory) {
89 assert(!Filename.empty() && "Unable to create file without name");
91 MDString::get(VMContext, Filename),
92 MDString::get(VMContext, Directory)
94 return MDNode::get(VMContext, Pair);
97 /// createCompileUnit - A CompileUnit provides an anchor for all debugging
98 /// information generated during this instance of compilation.
99 DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename,
101 StringRef Producer, bool isOptimized,
102 StringRef Flags, unsigned RunTimeVer,
104 DebugEmissionKind Kind) {
106 assert(((Lang <= dwarf::DW_LANG_Python && Lang >= dwarf::DW_LANG_C89) ||
107 (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
108 "Invalid Language tag");
109 assert(!Filename.empty() &&
110 "Unable to create compile unit without filename");
111 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
112 TempEnumTypes = MDNode::getTemporary(VMContext, TElts);
114 TempRetainTypes = MDNode::getTemporary(VMContext, TElts);
116 TempSubprograms = MDNode::getTemporary(VMContext, TElts);
118 TempGVs = MDNode::getTemporary(VMContext, TElts);
120 TempImportedModules = MDNode::getTemporary(VMContext, TElts);
123 GetTagConstant(VMContext, dwarf::DW_TAG_compile_unit),
124 createFilePathPair(VMContext, Filename, Directory),
125 ConstantInt::get(Type::getInt32Ty(VMContext), Lang),
126 MDString::get(VMContext, Producer),
127 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
128 MDString::get(VMContext, Flags),
129 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer),
135 MDString::get(VMContext, SplitName),
136 ConstantInt::get(Type::getInt32Ty(VMContext), Kind)
139 MDNode *CUNode = MDNode::get(VMContext, Elts);
141 // Create a named metadata so that it is easier to find cu in a module.
142 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
143 NMD->addOperand(CUNode);
145 return DICompileUnit(CUNode);
148 static DIImportedEntity
149 createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope Context,
150 Value *NS, unsigned Line, StringRef Name,
151 SmallVectorImpl<TrackingVH<MDNode>> &AllImportedModules) {
155 GetTagConstant(C, Tag),
158 ConstantInt::get(Type::getInt32Ty(C), Line),
160 R = MDNode::get(C, Elts);
163 GetTagConstant(C, Tag),
166 ConstantInt::get(Type::getInt32Ty(C), Line),
167 MDString::get(C, Name)
169 R = MDNode::get(C, Elts);
171 DIImportedEntity M(R);
172 assert(M.Verify() && "Imported module should be valid");
173 AllImportedModules.push_back(TrackingVH<MDNode>(M));
177 DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
180 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
181 Context, NS, Line, StringRef(), AllImportedModules);
184 DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
187 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
188 Context, NS, Line, StringRef(), AllImportedModules);
191 DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
193 unsigned Line, StringRef Name) {
194 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
195 Context, Decl.getRef(), Line, Name,
199 DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
200 DIImportedEntity Imp,
201 unsigned Line, StringRef Name) {
202 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
203 Context, Imp, Line, Name, AllImportedModules);
206 /// createFile - Create a file descriptor to hold debugging information
208 DIFile DIBuilder::createFile(StringRef Filename, StringRef Directory) {
210 GetTagConstant(VMContext, dwarf::DW_TAG_file_type),
211 createFilePathPair(VMContext, Filename, Directory)
213 return DIFile(MDNode::get(VMContext, Elts));
216 /// createEnumerator - Create a single enumerator value.
217 DIEnumerator DIBuilder::createEnumerator(StringRef Name, int64_t Val) {
218 assert(!Name.empty() && "Unable to create enumerator without name");
220 GetTagConstant(VMContext, dwarf::DW_TAG_enumerator),
221 MDString::get(VMContext, Name),
222 ConstantInt::get(Type::getInt64Ty(VMContext), Val)
224 return DIEnumerator(MDNode::get(VMContext, Elts));
227 /// \brief Create a DWARF unspecified type.
228 DIBasicType DIBuilder::createUnspecifiedType(StringRef Name) {
229 assert(!Name.empty() && "Unable to create type without name");
230 // Unspecified types are encoded in DIBasicType format. Line number, filename,
231 // size, alignment, offset and flags are always empty here.
233 GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_type),
236 MDString::get(VMContext, Name),
237 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
238 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
239 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
240 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
241 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
242 ConstantInt::get(Type::getInt32Ty(VMContext), 0) // Encoding
244 return DIBasicType(MDNode::get(VMContext, Elts));
247 /// \brief Create C++11 nullptr type.
248 DIBasicType DIBuilder::createNullPtrType() {
249 return createUnspecifiedType("decltype(nullptr)");
252 /// createBasicType - Create debugging information entry for a basic
253 /// type, e.g 'char'.
255 DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
256 uint64_t AlignInBits, unsigned Encoding) {
257 assert(!Name.empty() && "Unable to create type without name");
258 // Basic types are encoded in DIBasicType format. Line number, filename,
259 // offset and flags are always empty here.
261 GetTagConstant(VMContext, dwarf::DW_TAG_base_type),
262 NULL, // File/directory name
264 MDString::get(VMContext, Name),
265 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
266 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
267 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
268 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
269 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
270 ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
272 return DIBasicType(MDNode::get(VMContext, Elts));
275 /// createQualifiedType - Create debugging information entry for a qualified
276 /// type, e.g. 'const int'.
277 DIDerivedType DIBuilder::createQualifiedType(unsigned Tag, DIType FromTy) {
278 // Qualified types are encoded in DIDerivedType format.
280 GetTagConstant(VMContext, Tag),
283 MDString::get(VMContext, StringRef()), // Empty name.
284 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
285 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
286 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
287 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
288 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
291 return DIDerivedType(MDNode::get(VMContext, Elts));
294 /// createPointerType - Create debugging information entry for a pointer.
296 DIBuilder::createPointerType(DIType PointeeTy, uint64_t SizeInBits,
297 uint64_t AlignInBits, StringRef Name) {
298 // Pointer types are encoded in DIDerivedType format.
300 GetTagConstant(VMContext, dwarf::DW_TAG_pointer_type),
303 MDString::get(VMContext, Name),
304 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
305 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
306 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
307 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
308 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
311 return DIDerivedType(MDNode::get(VMContext, Elts));
314 DIDerivedType DIBuilder::createMemberPointerType(DIType PointeeTy,
316 // Pointer types are encoded in DIDerivedType format.
318 GetTagConstant(VMContext, dwarf::DW_TAG_ptr_to_member_type),
322 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
323 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
324 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
325 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
326 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
330 return DIDerivedType(MDNode::get(VMContext, Elts));
333 /// createReferenceType - Create debugging information entry for a reference
335 DIDerivedType DIBuilder::createReferenceType(unsigned Tag, DIType RTy) {
336 assert(RTy.isType() && "Unable to create reference type");
337 // References are encoded in DIDerivedType format.
339 GetTagConstant(VMContext, Tag),
343 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
344 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
345 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
346 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
347 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
350 return DIDerivedType(MDNode::get(VMContext, Elts));
353 /// createTypedef - Create debugging information entry for a typedef.
354 DIDerivedType DIBuilder::createTypedef(DIType Ty, StringRef Name, DIFile File,
355 unsigned LineNo, DIDescriptor Context) {
356 // typedefs are encoded in DIDerivedType format.
357 assert(Ty.isType() && "Invalid typedef type!");
359 GetTagConstant(VMContext, dwarf::DW_TAG_typedef),
361 DIScope(getNonCompileUnitScope(Context)).getRef(),
362 MDString::get(VMContext, Name),
363 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
364 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
365 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
366 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
367 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
370 return DIDerivedType(MDNode::get(VMContext, Elts));
373 /// createFriend - Create debugging information entry for a 'friend'.
374 DIDerivedType DIBuilder::createFriend(DIType Ty, DIType FriendTy) {
375 // typedefs are encoded in DIDerivedType format.
376 assert(Ty.isType() && "Invalid type!");
377 assert(FriendTy.isType() && "Invalid friend type!");
379 GetTagConstant(VMContext, dwarf::DW_TAG_friend),
383 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
384 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
385 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
386 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
387 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
390 return DIDerivedType(MDNode::get(VMContext, Elts));
393 /// createInheritance - Create debugging information entry to establish
394 /// inheritance relationship between two types.
395 DIDerivedType DIBuilder::createInheritance(DIType Ty, DIType BaseTy,
398 assert(Ty.isType() && "Unable to create inheritance");
399 // TAG_inheritance is encoded in DIDerivedType format.
401 GetTagConstant(VMContext, dwarf::DW_TAG_inheritance),
405 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
406 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
407 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
408 ConstantInt::get(Type::getInt64Ty(VMContext), BaseOffset),
409 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
412 return DIDerivedType(MDNode::get(VMContext, Elts));
415 /// createMemberType - Create debugging information entry for a member.
416 DIDerivedType DIBuilder::createMemberType(DIDescriptor Scope, StringRef Name,
417 DIFile File, unsigned LineNumber,
419 uint64_t AlignInBits,
420 uint64_t OffsetInBits, unsigned Flags,
422 // TAG_member is encoded in DIDerivedType format.
424 GetTagConstant(VMContext, dwarf::DW_TAG_member),
426 DIScope(getNonCompileUnitScope(Scope)).getRef(),
427 MDString::get(VMContext, Name),
428 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
429 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
430 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
431 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
432 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
435 return DIDerivedType(MDNode::get(VMContext, Elts));
438 /// createStaticMemberType - Create debugging information entry for a
439 /// C++ static data member.
441 DIBuilder::createStaticMemberType(DIDescriptor Scope, StringRef Name,
442 DIFile File, unsigned LineNumber,
443 DIType Ty, unsigned Flags,
445 // TAG_member is encoded in DIDerivedType format.
446 Flags |= DIDescriptor::FlagStaticMember;
448 GetTagConstant(VMContext, dwarf::DW_TAG_member),
450 DIScope(getNonCompileUnitScope(Scope)).getRef(),
451 MDString::get(VMContext, Name),
452 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
453 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
454 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
455 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
456 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
460 return DIDerivedType(MDNode::get(VMContext, Elts));
463 /// createObjCIVar - Create debugging information entry for Objective-C
464 /// instance variable.
466 DIBuilder::createObjCIVar(StringRef Name, DIFile File, unsigned LineNumber,
467 uint64_t SizeInBits, uint64_t AlignInBits,
468 uint64_t OffsetInBits, unsigned Flags, DIType Ty,
469 StringRef PropertyName, StringRef GetterName,
470 StringRef SetterName, unsigned PropertyAttributes) {
471 // TAG_member is encoded in DIDerivedType format.
473 GetTagConstant(VMContext, dwarf::DW_TAG_member),
475 getNonCompileUnitScope(File),
476 MDString::get(VMContext, Name),
477 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
478 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
479 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
480 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
481 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
483 MDString::get(VMContext, PropertyName),
484 MDString::get(VMContext, GetterName),
485 MDString::get(VMContext, SetterName),
486 ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes)
488 return DIDerivedType(MDNode::get(VMContext, Elts));
491 /// createObjCIVar - Create debugging information entry for Objective-C
492 /// instance variable.
493 DIDerivedType DIBuilder::createObjCIVar(StringRef Name, DIFile File,
496 uint64_t AlignInBits,
497 uint64_t OffsetInBits, unsigned Flags,
498 DIType Ty, MDNode *PropertyNode) {
499 // TAG_member is encoded in DIDerivedType format.
501 GetTagConstant(VMContext, dwarf::DW_TAG_member),
503 getNonCompileUnitScope(File),
504 MDString::get(VMContext, Name),
505 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
506 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
507 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
508 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
509 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
513 return DIDerivedType(MDNode::get(VMContext, Elts));
516 /// createObjCProperty - Create debugging information entry for Objective-C
519 DIBuilder::createObjCProperty(StringRef Name, DIFile File, unsigned LineNumber,
520 StringRef GetterName, StringRef SetterName,
521 unsigned PropertyAttributes, DIType Ty) {
523 GetTagConstant(VMContext, dwarf::DW_TAG_APPLE_property),
524 MDString::get(VMContext, Name),
526 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
527 MDString::get(VMContext, GetterName),
528 MDString::get(VMContext, SetterName),
529 ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes),
532 return DIObjCProperty(MDNode::get(VMContext, Elts));
535 /// createTemplateTypeParameter - Create debugging information for template
537 DITemplateTypeParameter
538 DIBuilder::createTemplateTypeParameter(DIDescriptor Context, StringRef Name,
539 DIType Ty, MDNode *File, unsigned LineNo,
542 GetTagConstant(VMContext, dwarf::DW_TAG_template_type_parameter),
543 DIScope(getNonCompileUnitScope(Context)).getRef(),
544 MDString::get(VMContext, Name),
547 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
548 ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo)
550 return DITemplateTypeParameter(MDNode::get(VMContext, Elts));
553 DITemplateValueParameter
554 DIBuilder::createTemplateValueParameter(unsigned Tag, DIDescriptor Context,
555 StringRef Name, DIType Ty,
556 Value *Val, MDNode *File,
560 GetTagConstant(VMContext, Tag),
561 DIScope(getNonCompileUnitScope(Context)).getRef(),
562 MDString::get(VMContext, Name),
566 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
567 ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo)
569 return DITemplateValueParameter(MDNode::get(VMContext, Elts));
572 /// createTemplateValueParameter - Create debugging information for template
574 DITemplateValueParameter
575 DIBuilder::createTemplateValueParameter(DIDescriptor Context, StringRef Name,
576 DIType Ty, Value *Val,
577 MDNode *File, unsigned LineNo,
579 return createTemplateValueParameter(dwarf::DW_TAG_template_value_parameter,
580 Context, Name, Ty, Val, File, LineNo,
584 DITemplateValueParameter
585 DIBuilder::createTemplateTemplateParameter(DIDescriptor Context, StringRef Name,
586 DIType Ty, StringRef Val,
587 MDNode *File, unsigned LineNo,
589 return createTemplateValueParameter(
590 dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
591 MDString::get(VMContext, Val), File, LineNo, ColumnNo);
594 DITemplateValueParameter
595 DIBuilder::createTemplateParameterPack(DIDescriptor Context, StringRef Name,
596 DIType Ty, DIArray Val,
597 MDNode *File, unsigned LineNo,
599 return createTemplateValueParameter(dwarf::DW_TAG_GNU_template_parameter_pack,
600 Context, Name, Ty, Val, File, LineNo,
604 /// createClassType - Create debugging information entry for a class.
605 DICompositeType DIBuilder::createClassType(DIDescriptor Context, StringRef Name,
606 DIFile File, unsigned LineNumber,
608 uint64_t AlignInBits,
609 uint64_t OffsetInBits,
610 unsigned Flags, DIType DerivedFrom,
613 MDNode *TemplateParams,
614 StringRef UniqueIdentifier) {
615 assert((!Context || Context.isScope() || Context.isType()) &&
616 "createClassType should be called with a valid Context");
617 // TAG_class_type is encoded in DICompositeType format.
619 GetTagConstant(VMContext, dwarf::DW_TAG_class_type),
621 DIScope(getNonCompileUnitScope(Context)).getRef(),
622 MDString::get(VMContext, Name),
623 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
624 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
625 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
626 ConstantInt::get(Type::getInt32Ty(VMContext), OffsetInBits),
627 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
628 DerivedFrom.getRef(),
630 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
631 VTableHolder.getRef(),
633 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
635 DICompositeType R(MDNode::get(VMContext, Elts));
636 assert(R.isCompositeType() &&
637 "createClassType should return a DICompositeType");
638 if (!UniqueIdentifier.empty())
643 /// createStructType - Create debugging information entry for a struct.
644 DICompositeType DIBuilder::createStructType(DIDescriptor Context,
645 StringRef Name, DIFile File,
648 uint64_t AlignInBits,
649 unsigned Flags, DIType DerivedFrom,
651 unsigned RunTimeLang,
653 StringRef UniqueIdentifier) {
654 // TAG_structure_type is encoded in DICompositeType format.
656 GetTagConstant(VMContext, dwarf::DW_TAG_structure_type),
658 DIScope(getNonCompileUnitScope(Context)).getRef(),
659 MDString::get(VMContext, Name),
660 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
661 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
662 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
663 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
664 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
665 DerivedFrom.getRef(),
667 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
668 VTableHolder.getRef(),
670 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
672 DICompositeType R(MDNode::get(VMContext, Elts));
673 assert(R.isCompositeType() &&
674 "createStructType should return a DICompositeType");
675 if (!UniqueIdentifier.empty())
680 /// createUnionType - Create debugging information entry for an union.
681 DICompositeType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name,
682 DIFile File, unsigned LineNumber,
684 uint64_t AlignInBits, unsigned Flags,
686 unsigned RunTimeLang,
687 StringRef UniqueIdentifier) {
688 // TAG_union_type is encoded in DICompositeType format.
690 GetTagConstant(VMContext, dwarf::DW_TAG_union_type),
692 DIScope(getNonCompileUnitScope(Scope)).getRef(),
693 MDString::get(VMContext, Name),
694 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
695 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
696 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
697 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
698 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
701 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
704 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
706 DICompositeType R(MDNode::get(VMContext, Elts));
707 if (!UniqueIdentifier.empty())
712 /// createSubroutineType - Create subroutine type.
713 DICompositeType DIBuilder::createSubroutineType(DIFile File,
714 DIArray ParameterTypes,
716 // TAG_subroutine_type is encoded in DICompositeType format.
718 GetTagConstant(VMContext, dwarf::DW_TAG_subroutine_type),
719 Constant::getNullValue(Type::getInt32Ty(VMContext)),
721 MDString::get(VMContext, ""),
722 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
723 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
724 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
725 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
726 ConstantInt::get(Type::getInt32Ty(VMContext), Flags), // Flags
729 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
732 NULL // Type Identifer
734 return DICompositeType(MDNode::get(VMContext, Elts));
737 /// createEnumerationType - Create debugging information entry for an
739 DICompositeType DIBuilder::createEnumerationType(
740 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
741 uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
742 DIType UnderlyingType, StringRef UniqueIdentifier) {
743 // TAG_enumeration_type is encoded in DICompositeType format.
745 GetTagConstant(VMContext, dwarf::DW_TAG_enumeration_type),
747 DIScope(getNonCompileUnitScope(Scope)).getRef(),
748 MDString::get(VMContext, Name),
749 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
750 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
751 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
752 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
753 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
754 UnderlyingType.getRef(),
756 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
759 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
761 DICompositeType CTy(MDNode::get(VMContext, Elts));
762 AllEnumTypes.push_back(CTy);
763 if (!UniqueIdentifier.empty())
768 /// createArrayType - Create debugging information entry for an array.
769 DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
770 DIType Ty, DIArray Subscripts) {
771 // TAG_array_type is encoded in DICompositeType format.
773 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
774 NULL, // Filename/Directory,
776 MDString::get(VMContext, ""),
777 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
778 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
779 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
780 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
781 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
784 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
787 NULL // Type Identifer
789 return DICompositeType(MDNode::get(VMContext, Elts));
792 /// createVectorType - Create debugging information entry for a vector.
793 DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits,
794 DIType Ty, DIArray Subscripts) {
795 // A vector is an array type with the FlagVector flag applied.
797 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
798 NULL, // Filename/Directory,
800 MDString::get(VMContext, ""),
801 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
802 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
803 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
804 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
805 ConstantInt::get(Type::getInt32Ty(VMContext), DIType::FlagVector),
808 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
811 NULL // Type Identifer
813 return DICompositeType(MDNode::get(VMContext, Elts));
816 /// createArtificialType - Create a new DIType with "artificial" flag set.
817 DIType DIBuilder::createArtificialType(DIType Ty) {
818 if (Ty.isArtificial())
821 SmallVector<Value *, 9> Elts;
823 assert (N && "Unexpected input DIType!");
824 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
825 Elts.push_back(N->getOperand(i));
827 unsigned CurFlags = Ty.getFlags();
828 CurFlags = CurFlags | DIType::FlagArtificial;
830 // Flags are stored at this slot.
831 // FIXME: Add an enum for this magic value.
832 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
834 return DIType(MDNode::get(VMContext, Elts));
837 /// createObjectPointerType - Create a new type with both the object pointer
838 /// and artificial flags set.
839 DIType DIBuilder::createObjectPointerType(DIType Ty) {
840 if (Ty.isObjectPointer())
843 SmallVector<Value *, 9> Elts;
845 assert (N && "Unexpected input DIType!");
846 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
847 Elts.push_back(N->getOperand(i));
849 unsigned CurFlags = Ty.getFlags();
850 CurFlags = CurFlags | (DIType::FlagObjectPointer | DIType::FlagArtificial);
852 // Flags are stored at this slot.
853 // FIXME: Add an enum for this magic value.
854 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
856 return DIType(MDNode::get(VMContext, Elts));
859 /// retainType - Retain DIType in a module even if it is not referenced
860 /// through debug info anchors.
861 void DIBuilder::retainType(DIType T) {
862 AllRetainTypes.push_back(TrackingVH<MDNode>(T));
865 /// createUnspecifiedParameter - Create unspeicified type descriptor
866 /// for the subroutine type.
867 DIDescriptor DIBuilder::createUnspecifiedParameter() {
869 GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_parameters)
871 return DIDescriptor(MDNode::get(VMContext, Elts));
874 /// createForwardDecl - Create a temporary forward-declared type that
875 /// can be RAUW'd if the full type is seen.
877 DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope,
878 DIFile F, unsigned Line, unsigned RuntimeLang,
879 uint64_t SizeInBits, uint64_t AlignInBits,
880 StringRef UniqueIdentifier) {
881 // Create a temporary MDNode.
883 GetTagConstant(VMContext, Tag),
885 DIScope(getNonCompileUnitScope(Scope)).getRef(),
886 MDString::get(VMContext, Name),
887 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
888 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
889 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
890 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
891 ConstantInt::get(Type::getInt32Ty(VMContext), DIDescriptor::FlagFwdDecl),
894 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang),
896 NULL, //TemplateParams
897 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
899 MDNode *Node = MDNode::getTemporary(VMContext, Elts);
900 DICompositeType RetTy(Node);
901 assert(RetTy.isCompositeType() &&
902 "createForwardDecl result should be a DIType");
903 if (!UniqueIdentifier.empty())
908 /// getOrCreateArray - Get a DIArray, create one if required.
909 DIArray DIBuilder::getOrCreateArray(ArrayRef<Value *> Elements) {
910 return DIArray(MDNode::get(VMContext, Elements));
913 /// getOrCreateSubrange - Create a descriptor for a value range. This
914 /// implicitly uniques the values returned.
915 DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
917 GetTagConstant(VMContext, dwarf::DW_TAG_subrange_type),
918 ConstantInt::get(Type::getInt64Ty(VMContext), Lo),
919 ConstantInt::get(Type::getInt64Ty(VMContext), Count)
922 return DISubrange(MDNode::get(VMContext, Elts));
925 /// \brief Create a new descriptor for the specified global.
926 DIGlobalVariable DIBuilder::createGlobalVariable(StringRef Name,
927 StringRef LinkageName,
928 DIFile F, unsigned LineNumber,
929 DITypeRef 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::createGlobalVariable(StringRef Name, DIFile F,
957 return createGlobalVariable(Name, Name, F, LineNumber, Ty, isLocalToUnit,
961 /// createStaticVariable - Create a new descriptor for the specified static
963 DIGlobalVariable DIBuilder::createStaticVariable(DIDescriptor Context,
965 StringRef LinkageName,
966 DIFile F, unsigned LineNumber,
969 Value *Val, MDNode *Decl) {
971 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
972 Constant::getNullValue(Type::getInt32Ty(VMContext)),
973 getNonCompileUnitScope(Context),
974 MDString::get(VMContext, Name),
975 MDString::get(VMContext, Name),
976 MDString::get(VMContext, LinkageName),
978 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
980 ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
981 ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
985 MDNode *Node = MDNode::get(VMContext, Elts);
986 AllGVs.push_back(Node);
987 return DIGlobalVariable(Node);
990 /// createVariable - Create a new descriptor for the specified variable.
991 DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
992 StringRef Name, DIFile File,
993 unsigned LineNo, DITypeRef Ty,
994 bool AlwaysPreserve, unsigned Flags,
996 DIDescriptor Context(getNonCompileUnitScope(Scope));
997 assert((!Context || Context.isScope()) &&
998 "createLocalVariable should be called with a valid Context");
1000 GetTagConstant(VMContext, Tag),
1001 getNonCompileUnitScope(Scope),
1002 MDString::get(VMContext, Name),
1004 ConstantInt::get(Type::getInt32Ty(VMContext), (LineNo | (ArgNo << 24))),
1006 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1007 Constant::getNullValue(Type::getInt32Ty(VMContext))
1009 MDNode *Node = MDNode::get(VMContext, Elts);
1010 if (AlwaysPreserve) {
1011 // The optimizer may remove local variable. If there is an interest
1012 // to preserve variable info in such situation then stash it in a
1014 DISubprogram Fn(getDISubprogram(Scope));
1015 NamedMDNode *FnLocals = getOrInsertFnSpecificMDNode(M, Fn);
1016 FnLocals->addOperand(Node);
1018 DIVariable RetVar(Node);
1019 assert(RetVar.isVariable() &&
1020 "createLocalVariable should return a valid DIVariable");
1024 /// createComplexVariable - Create a new descriptor for the specified variable
1025 /// which has a complex address expression for its address.
1026 DIVariable DIBuilder::createComplexVariable(unsigned Tag, DIDescriptor Scope,
1027 StringRef Name, DIFile F,
1030 ArrayRef<Value *> Addr,
1032 SmallVector<Value *, 15> Elts;
1033 Elts.push_back(GetTagConstant(VMContext, Tag));
1034 Elts.push_back(getNonCompileUnitScope(Scope)),
1035 Elts.push_back(MDString::get(VMContext, Name));
1037 Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext),
1038 (LineNo | (ArgNo << 24))));
1040 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
1041 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
1042 Elts.append(Addr.begin(), Addr.end());
1044 return DIVariable(MDNode::get(VMContext, Elts));
1047 /// createFunction - Create a new descriptor for the specified function.
1048 /// FIXME: this is added for dragonegg. Once we update dragonegg
1049 /// to call resolve function, this will be removed.
1050 DISubprogram DIBuilder::createFunction(DIScopeRef Context, StringRef Name,
1051 StringRef LinkageName, DIFile File,
1052 unsigned LineNo, DICompositeType Ty,
1053 bool isLocalToUnit, bool isDefinition,
1054 unsigned ScopeLine, unsigned Flags,
1055 bool isOptimized, Function *Fn,
1056 MDNode *TParams, MDNode *Decl) {
1057 // dragonegg does not generate identifier for types, so using an empty map
1058 // to resolve the context should be fine.
1059 DITypeIdentifierMap EmptyMap;
1060 return createFunction(Context.resolve(EmptyMap), Name, LinkageName, File,
1061 LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine,
1062 Flags, isOptimized, Fn, TParams, Decl);
1065 /// createFunction - Create a new descriptor for the specified function.
1066 DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name,
1067 StringRef LinkageName, DIFile File,
1068 unsigned LineNo, DICompositeType Ty,
1069 bool isLocalToUnit, bool isDefinition,
1070 unsigned ScopeLine, unsigned Flags,
1071 bool isOptimized, Function *Fn,
1072 MDNode *TParams, MDNode *Decl) {
1073 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1074 "function types should be subroutines");
1075 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
1077 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
1079 DIScope(getNonCompileUnitScope(Context)).getRef(),
1080 MDString::get(VMContext, Name),
1081 MDString::get(VMContext, Name),
1082 MDString::get(VMContext, LinkageName),
1083 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1085 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1086 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1087 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
1088 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
1090 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1091 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
1095 MDNode::getTemporary(VMContext, TElts),
1096 ConstantInt::get(Type::getInt32Ty(VMContext), ScopeLine)
1098 MDNode *Node = MDNode::get(VMContext, Elts);
1100 // Create a named metadata so that we do not lose this mdnode.
1102 AllSubprograms.push_back(Node);
1103 DISubprogram S(Node);
1104 assert(S.isSubprogram() &&
1105 "createFunction should return a valid DISubprogram");
1109 /// createMethod - Create a new descriptor for the specified C++ method.
1110 DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
1111 StringRef LinkageName, DIFile F,
1112 unsigned LineNo, DICompositeType Ty,
1113 bool isLocalToUnit, bool isDefinition,
1114 unsigned VK, unsigned VIndex,
1115 DIType VTableHolder, unsigned Flags,
1116 bool isOptimized, Function *Fn,
1118 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1119 "function types should be subroutines");
1120 assert(getNonCompileUnitScope(Context) &&
1121 "Methods should have both a Context and a context that isn't "
1122 "the compile unit.");
1123 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
1125 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
1127 DIScope(Context).getRef(),
1128 MDString::get(VMContext, Name),
1129 MDString::get(VMContext, Name),
1130 MDString::get(VMContext, LinkageName),
1131 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1133 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1134 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1135 ConstantInt::get(Type::getInt32Ty(VMContext), VK),
1136 ConstantInt::get(Type::getInt32Ty(VMContext), VIndex),
1137 VTableHolder.getRef(),
1138 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1139 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
1142 Constant::getNullValue(Type::getInt32Ty(VMContext)),
1143 MDNode::getTemporary(VMContext, TElts),
1144 // FIXME: Do we want to use different scope/lines?
1145 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
1147 MDNode *Node = MDNode::get(VMContext, Elts);
1149 AllSubprograms.push_back(Node);
1150 DISubprogram S(Node);
1151 assert(S.isSubprogram() && "createMethod should return a valid DISubprogram");
1155 /// createNameSpace - This creates new descriptor for a namespace
1156 /// with the specified parent scope.
1157 DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
1158 DIFile File, unsigned LineNo) {
1160 GetTagConstant(VMContext, dwarf::DW_TAG_namespace),
1162 getNonCompileUnitScope(Scope),
1163 MDString::get(VMContext, Name),
1164 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
1166 DINameSpace R(MDNode::get(VMContext, Elts));
1167 assert(R.Verify() &&
1168 "createNameSpace should return a verifiable DINameSpace");
1172 /// createLexicalBlockFile - This creates a new MDNode that encapsulates
1173 /// an existing scope with a new filename.
1174 DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
1177 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
1181 DILexicalBlockFile R(MDNode::get(VMContext, Elts));
1184 "createLexicalBlockFile should return a verifiable DILexicalBlockFile");
1188 DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
1189 unsigned Line, unsigned Col,
1190 unsigned Discriminator) {
1191 // Defeat MDNode uniquing for lexical blocks by using unique id.
1192 static unsigned int unique_id = 0;
1194 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
1196 getNonCompileUnitScope(Scope),
1197 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
1198 ConstantInt::get(Type::getInt32Ty(VMContext), Col),
1199 ConstantInt::get(Type::getInt32Ty(VMContext), Discriminator),
1200 ConstantInt::get(Type::getInt32Ty(VMContext), unique_id++)
1202 DILexicalBlock R(MDNode::get(VMContext, Elts));
1203 assert(R.Verify() &&
1204 "createLexicalBlock should return a verifiable DILexicalBlock");
1208 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1209 Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
1210 Instruction *InsertBefore) {
1211 assert(Storage && "no storage passed to dbg.declare");
1212 assert(VarInfo.isVariable() &&
1213 "empty or invalid DIVariable passed to dbg.declare");
1215 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1217 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
1218 return CallInst::Create(DeclareFn, Args, "", InsertBefore);
1221 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1222 Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
1223 BasicBlock *InsertAtEnd) {
1224 assert(Storage && "no storage passed to dbg.declare");
1225 assert(VarInfo.isVariable() &&
1226 "empty or invalid DIVariable passed to dbg.declare");
1228 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1230 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
1232 // If this block already has a terminator then insert this intrinsic
1233 // before the terminator.
1234 if (TerminatorInst *T = InsertAtEnd->getTerminator())
1235 return CallInst::Create(DeclareFn, Args, "", T);
1237 return CallInst::Create(DeclareFn, Args, "", InsertAtEnd);
1240 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1241 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
1243 Instruction *InsertBefore) {
1244 assert(V && "no value passed to dbg.value");
1245 assert(VarInfo.isVariable() &&
1246 "empty or invalid DIVariable passed to dbg.value");
1248 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1250 Value *Args[] = { MDNode::get(V->getContext(), V),
1251 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1253 return CallInst::Create(ValueFn, Args, "", InsertBefore);
1256 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1257 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
1259 BasicBlock *InsertAtEnd) {
1260 assert(V && "no value passed to dbg.value");
1261 assert(VarInfo.isVariable() &&
1262 "empty or invalid DIVariable passed to dbg.value");
1264 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1266 Value *Args[] = { MDNode::get(V->getContext(), V),
1267 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1269 return CallInst::Create(ValueFn, Args, "", InsertAtEnd);