1 //===--- DebugInfo.cpp - Debug Information Helper Classes -----------------===//
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 helper classes used to build and interpret debug
11 // information in LLVM IR form.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Analysis/DebugInfo.h"
16 #include "llvm/Constants.h"
17 #include "llvm/DerivedTypes.h"
18 #include "llvm/Intrinsics.h"
19 #include "llvm/Instructions.h"
20 #include "llvm/Module.h"
21 #include "llvm/Analysis/ValueTracking.h"
22 #include "llvm/Support/Dwarf.h"
25 //===----------------------------------------------------------------------===//
27 //===----------------------------------------------------------------------===//
29 DIDescriptor::DIDescriptor(GlobalVariable *gv, unsigned RequiredTag) {
32 // If this is non-null, check to see if the Tag matches. If not, set to null.
33 if (GV && getTag() != RequiredTag)
38 std::string DIDescriptor::getStringField(unsigned Elt) const {
39 if (GV == 0) return "";
40 Constant *C = GV->getInitializer();
41 if (C == 0 || Elt >= C->getNumOperands())
45 // Fills in the string if it succeeds
46 if (!GetConstantStringInfo(C->getOperand(Elt), Result))
51 uint64_t DIDescriptor::getUInt64Field(unsigned Elt) const {
52 if (GV == 0) return 0;
53 Constant *C = GV->getInitializer();
54 if (C == 0 || Elt >= C->getNumOperands())
56 if (ConstantInt *CI = dyn_cast<ConstantInt>(C->getOperand(Elt)))
57 return CI->getZExtValue();
62 DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const {
63 if (GV == 0) return DIDescriptor();
64 Constant *C = GV->getInitializer();
65 if (C == 0 || Elt >= C->getNumOperands())
66 return DIDescriptor();
67 C = C->getOperand(Elt);
68 return DIDescriptor(dyn_cast<GlobalVariable>(C->stripPointerCasts()));
71 GlobalVariable *DIDescriptor::getGlobalVariableField(unsigned Elt) const {
72 if (GV == 0) return 0;
73 Constant *C = GV->getInitializer();
74 if (C == 0 || Elt >= C->getNumOperands())
76 C = C->getOperand(Elt);
78 return dyn_cast<GlobalVariable>(C->stripPointerCasts());
83 //===----------------------------------------------------------------------===//
84 // Simple Descriptor Constructors and other Methods
85 //===----------------------------------------------------------------------===//
87 DIAnchor::DIAnchor(GlobalVariable *GV)
88 : DIDescriptor(GV, dwarf::DW_TAG_anchor) {}
89 DIEnumerator::DIEnumerator(GlobalVariable *GV)
90 : DIDescriptor(GV, dwarf::DW_TAG_enumerator) {}
91 DISubrange::DISubrange(GlobalVariable *GV)
92 : DIDescriptor(GV, dwarf::DW_TAG_subrange_type) {}
93 DICompileUnit::DICompileUnit(GlobalVariable *GV)
94 : DIDescriptor(GV, dwarf::DW_TAG_compile_unit) {}
95 DIBasicType::DIBasicType(GlobalVariable *GV)
96 : DIType(GV, dwarf::DW_TAG_base_type) {}
97 DISubprogram::DISubprogram(GlobalVariable *GV)
98 : DIGlobal(GV, dwarf::DW_TAG_subprogram) {}
99 DIGlobalVariable::DIGlobalVariable(GlobalVariable *GV)
100 : DIGlobal(GV, dwarf::DW_TAG_variable) {}
101 DIBlock::DIBlock(GlobalVariable *GV)
102 : DIDescriptor(GV, dwarf::DW_TAG_lexical_block) {}
103 // needed by DIVariable::getType()
104 DIType::DIType(GlobalVariable *gv) : DIDescriptor(gv) {
106 unsigned tag = getTag();
107 if (tag != dwarf::DW_TAG_base_type && !DIDerivedType::isDerivedType(tag) &&
108 !DICompositeType::isCompositeType(tag))
112 /// isDerivedType - Return true if the specified tag is legal for
114 bool DIDerivedType::isDerivedType(unsigned Tag) {
116 case dwarf::DW_TAG_typedef:
117 case dwarf::DW_TAG_pointer_type:
118 case dwarf::DW_TAG_reference_type:
119 case dwarf::DW_TAG_const_type:
120 case dwarf::DW_TAG_volatile_type:
121 case dwarf::DW_TAG_restrict_type:
122 case dwarf::DW_TAG_member:
123 case dwarf::DW_TAG_inheritance:
126 // FIXME: Even though it doesn't make sense, CompositeTypes are current
127 // modelled as DerivedTypes, this should return true for them as well.
132 DIDerivedType::DIDerivedType(GlobalVariable *GV) : DIType(GV, true, true) {
133 if (GV && !isDerivedType(getTag()))
137 /// isCompositeType - Return true if the specified tag is legal for
139 bool DICompositeType::isCompositeType(unsigned TAG) {
141 case dwarf::DW_TAG_array_type:
142 case dwarf::DW_TAG_structure_type:
143 case dwarf::DW_TAG_union_type:
144 case dwarf::DW_TAG_enumeration_type:
145 case dwarf::DW_TAG_vector_type:
146 case dwarf::DW_TAG_subroutine_type:
153 DICompositeType::DICompositeType(GlobalVariable *GV)
154 : DIDerivedType(GV, true, true) {
155 if (GV && !isCompositeType(getTag()))
159 /// isVariable - Return true if the specified tag is legal for DIVariable.
160 bool DIVariable::isVariable(unsigned Tag) {
162 case dwarf::DW_TAG_auto_variable:
163 case dwarf::DW_TAG_arg_variable:
164 case dwarf::DW_TAG_return_variable:
171 DIVariable::DIVariable(GlobalVariable *GV) : DIDescriptor(GV) {
172 if (GV && !isVariable(getTag()))
178 //===----------------------------------------------------------------------===//
179 // DIFactory: Basic Helpers
180 //===----------------------------------------------------------------------===//
182 DIFactory::DIFactory(Module &m) : M(m) {
183 StopPointFn = FuncStartFn = RegionStartFn = RegionEndFn = DeclareFn = 0;
184 EmptyStructPtr = PointerType::getUnqual(StructType::get(NULL, NULL));
187 /// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'.
188 /// This is only valid when the descriptor is non-null.
189 Constant *DIFactory::getCastToEmpty(DIDescriptor D) {
190 if (D.isNull()) return Constant::getNullValue(EmptyStructPtr);
191 return ConstantExpr::getBitCast(D.getGV(), EmptyStructPtr);
194 Constant *DIFactory::GetTagConstant(unsigned TAG) {
195 assert((TAG & DIDescriptor::VersionMask) == 0 &&
196 "Tag too large for debug encoding!");
197 return ConstantInt::get(Type::Int32Ty, TAG | DIDescriptor::Version6);
200 Constant *DIFactory::GetStringConstant(const std::string &String) {
201 // Check string cache for previous edition.
202 Constant *&Slot = StringCache[String];
204 // Return Constant if previously defined.
205 if (Slot) return Slot;
207 const PointerType *DestTy = PointerType::getUnqual(Type::Int8Ty);
209 // If empty string then use a sbyte* null instead.
211 return Slot = ConstantPointerNull::get(DestTy);
213 // Construct string as an llvm constant.
214 Constant *ConstStr = ConstantArray::get(String);
216 // Otherwise create and return a new string global.
217 GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true,
218 GlobalVariable::InternalLinkage,
219 ConstStr, ".str", &M);
220 StrGV->setSection("llvm.metadata");
221 return Slot = ConstantExpr::getBitCast(StrGV, DestTy);
224 /// GetOrCreateAnchor - Look up an anchor for the specified tag and name. If it
225 /// already exists, return it. If not, create a new one and return it.
226 DIAnchor DIFactory::GetOrCreateAnchor(unsigned TAG, const char *Name) {
227 const Type *EltTy = StructType::get(Type::Int32Ty, Type::Int32Ty, NULL);
229 // Otherwise, create the global or return it if already in the module.
230 Constant *C = M.getOrInsertGlobal(Name, EltTy);
231 assert(isa<GlobalVariable>(C) && "Incorrectly typed anchor?");
232 GlobalVariable *GV = cast<GlobalVariable>(C);
234 // If it has an initializer, it is already in the module.
235 if (GV->hasInitializer())
236 return SubProgramAnchor = DIAnchor(GV);
238 GV->setLinkage(GlobalValue::LinkOnceLinkage);
239 GV->setSection("llvm.metadata");
240 GV->setConstant(true);
241 M.addTypeName("llvm.dbg.anchor.type", EltTy);
243 // Otherwise, set the initializer.
245 GetTagConstant(dwarf::DW_TAG_anchor),
246 ConstantInt::get(Type::Int32Ty, TAG)
249 GV->setInitializer(ConstantStruct::get(Elts, 2));
255 //===----------------------------------------------------------------------===//
256 // DIFactory: Primary Constructors
257 //===----------------------------------------------------------------------===//
259 /// GetOrCreateCompileUnitAnchor - Return the anchor for compile units,
260 /// creating a new one if there isn't already one in the module.
261 DIAnchor DIFactory::GetOrCreateCompileUnitAnchor() {
262 // If we already created one, just return it.
263 if (!CompileUnitAnchor.isNull())
264 return CompileUnitAnchor;
265 return CompileUnitAnchor = GetOrCreateAnchor(dwarf::DW_TAG_compile_unit,
266 "llvm.dbg.compile_units");
269 /// GetOrCreateSubprogramAnchor - Return the anchor for subprograms,
270 /// creating a new one if there isn't already one in the module.
271 DIAnchor DIFactory::GetOrCreateSubprogramAnchor() {
272 // If we already created one, just return it.
273 if (!SubProgramAnchor.isNull())
274 return SubProgramAnchor;
275 return SubProgramAnchor = GetOrCreateAnchor(dwarf::DW_TAG_subprogram,
276 "llvm.dbg.subprograms");
279 /// GetOrCreateGlobalVariableAnchor - Return the anchor for globals,
280 /// creating a new one if there isn't already one in the module.
281 DIAnchor DIFactory::GetOrCreateGlobalVariableAnchor() {
282 // If we already created one, just return it.
283 if (!GlobalVariableAnchor.isNull())
284 return GlobalVariableAnchor;
285 return GlobalVariableAnchor = GetOrCreateAnchor(dwarf::DW_TAG_variable,
286 "llvm.dbg.global_variables");
289 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
290 /// This implicitly uniques the arrays created.
291 DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) {
292 SmallVector<Constant*, 16> Elts;
294 for (unsigned i = 0; i != NumTys; ++i)
295 Elts.push_back(getCastToEmpty(Tys[i]));
297 Constant *Init = ConstantArray::get(ArrayType::get(EmptyStructPtr,
299 &Elts[0], Elts.size());
300 // If we already have this array, just return the uniqued version.
301 DIDescriptor &Entry = SimpleConstantCache[Init];
302 if (!Entry.isNull()) return DIArray(Entry.getGV());
304 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
305 GlobalValue::InternalLinkage,
306 Init, "llvm.dbg.array", &M);
307 GV->setSection("llvm.metadata");
308 Entry = DIDescriptor(GV);
312 /// GetOrCreateSubrange - Create a descriptor for a value range. This
313 /// implicitly uniques the values returned.
314 DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) {
316 GetTagConstant(dwarf::DW_TAG_subrange_type),
317 ConstantInt::get(Type::Int64Ty, Lo),
318 ConstantInt::get(Type::Int64Ty, Hi)
321 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
323 // If we already have this range, just return the uniqued version.
324 DIDescriptor &Entry = SimpleConstantCache[Init];
325 if (!Entry.isNull()) return DISubrange(Entry.getGV());
327 M.addTypeName("llvm.dbg.subrange.type", Init->getType());
329 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
330 GlobalValue::InternalLinkage,
331 Init, "llvm.dbg.subrange", &M);
332 GV->setSection("llvm.metadata");
333 Entry = DIDescriptor(GV);
334 return DISubrange(GV);
339 /// CreateCompileUnit - Create a new descriptor for the specified compile
340 /// unit. Note that this does not unique compile units within the module.
341 DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID,
342 const std::string &Filename,
343 const std::string &Directory,
344 const std::string &Producer) {
346 GetTagConstant(dwarf::DW_TAG_compile_unit),
347 getCastToEmpty(GetOrCreateCompileUnitAnchor()),
348 ConstantInt::get(Type::Int32Ty, LangID),
349 GetStringConstant(Filename),
350 GetStringConstant(Directory),
351 GetStringConstant(Producer)
354 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
356 M.addTypeName("llvm.dbg.compile_unit.type", Init->getType());
357 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
358 GlobalValue::InternalLinkage,
359 Init, "llvm.dbg.compile_unit", &M);
360 GV->setSection("llvm.metadata");
361 return DICompileUnit(GV);
364 /// CreateEnumerator - Create a single enumerator value.
365 DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){
367 GetTagConstant(dwarf::DW_TAG_enumerator),
368 GetStringConstant(Name),
369 ConstantInt::get(Type::Int64Ty, Val)
372 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
374 M.addTypeName("llvm.dbg.enumerator.type", Init->getType());
375 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
376 GlobalValue::InternalLinkage,
377 Init, "llvm.dbg.enumerator", &M);
378 GV->setSection("llvm.metadata");
379 return DIEnumerator(GV);
383 /// CreateBasicType - Create a basic type like int, float, etc.
384 DIBasicType DIFactory::CreateBasicType(DIDescriptor Context,
385 const std::string &Name,
386 DICompileUnit CompileUnit,
389 uint64_t AlignInBits,
390 uint64_t OffsetInBits, unsigned Flags,
393 GetTagConstant(dwarf::DW_TAG_base_type),
394 getCastToEmpty(Context),
395 GetStringConstant(Name),
396 getCastToEmpty(CompileUnit),
397 ConstantInt::get(Type::Int32Ty, LineNumber),
398 ConstantInt::get(Type::Int64Ty, SizeInBits),
399 ConstantInt::get(Type::Int64Ty, AlignInBits),
400 ConstantInt::get(Type::Int64Ty, OffsetInBits),
401 ConstantInt::get(Type::Int32Ty, Flags),
402 ConstantInt::get(Type::Int32Ty, Encoding)
405 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
407 M.addTypeName("llvm.dbg.basictype.type", Init->getType());
408 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
409 GlobalValue::InternalLinkage,
410 Init, "llvm.dbg.basictype", &M);
411 GV->setSection("llvm.metadata");
412 return DIBasicType(GV);
415 /// CreateDerivedType - Create a derived type like const qualified type,
416 /// pointer, typedef, etc.
417 DIDerivedType DIFactory::CreateDerivedType(unsigned Tag,
418 DIDescriptor Context,
419 const std::string &Name,
420 DICompileUnit CompileUnit,
423 uint64_t AlignInBits,
424 uint64_t OffsetInBits,
426 DIType DerivedFrom) {
429 getCastToEmpty(Context),
430 GetStringConstant(Name),
431 getCastToEmpty(CompileUnit),
432 ConstantInt::get(Type::Int32Ty, LineNumber),
433 ConstantInt::get(Type::Int64Ty, SizeInBits),
434 ConstantInt::get(Type::Int64Ty, AlignInBits),
435 ConstantInt::get(Type::Int64Ty, OffsetInBits),
436 ConstantInt::get(Type::Int32Ty, Flags),
437 getCastToEmpty(DerivedFrom)
440 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
442 M.addTypeName("llvm.dbg.derivedtype.type", Init->getType());
443 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
444 GlobalValue::InternalLinkage,
445 Init, "llvm.dbg.derivedtype", &M);
446 GV->setSection("llvm.metadata");
447 return DIDerivedType(GV);
450 /// CreateCompositeType - Create a composite type like array, struct, etc.
451 DICompositeType DIFactory::CreateCompositeType(unsigned Tag,
452 DIDescriptor Context,
453 const std::string &Name,
454 DICompileUnit CompileUnit,
457 uint64_t AlignInBits,
458 uint64_t OffsetInBits,
464 getCastToEmpty(Context),
465 GetStringConstant(Name),
466 getCastToEmpty(CompileUnit),
467 ConstantInt::get(Type::Int32Ty, LineNumber),
468 ConstantInt::get(Type::Int64Ty, SizeInBits),
469 ConstantInt::get(Type::Int64Ty, AlignInBits),
470 ConstantInt::get(Type::Int64Ty, OffsetInBits),
471 ConstantInt::get(Type::Int32Ty, Flags),
472 getCastToEmpty(DerivedFrom),
473 getCastToEmpty(Elements)
476 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
478 M.addTypeName("llvm.dbg.composite.type", Init->getType());
479 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
480 GlobalValue::InternalLinkage,
481 Init, "llvm.dbg.composite", &M);
482 GV->setSection("llvm.metadata");
483 return DICompositeType(GV);
487 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
488 /// See comments in DISubprogram for descriptions of these fields. This
489 /// method does not unique the generated descriptors.
490 DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context,
491 const std::string &Name,
492 const std::string &DisplayName,
493 const std::string &LinkageName,
494 DICompileUnit CompileUnit,
495 unsigned LineNo, DIType Type,
499 GetTagConstant(dwarf::DW_TAG_subprogram),
500 getCastToEmpty(GetOrCreateSubprogramAnchor()),
501 getCastToEmpty(Context),
502 GetStringConstant(Name),
503 GetStringConstant(DisplayName),
504 GetStringConstant(LinkageName),
505 getCastToEmpty(CompileUnit),
506 ConstantInt::get(Type::Int32Ty, LineNo),
507 getCastToEmpty(Type),
508 ConstantInt::get(Type::Int1Ty, isLocalToUnit),
509 ConstantInt::get(Type::Int1Ty, isDefinition)
512 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
514 M.addTypeName("llvm.dbg.subprogram.type", Init->getType());
515 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
516 GlobalValue::InternalLinkage,
517 Init, "llvm.dbg.subprogram", &M);
518 GV->setSection("llvm.metadata");
519 return DISubprogram(GV);
522 /// CreateGlobalVariable - Create a new descriptor for the specified global.
524 DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
525 const std::string &DisplayName,
526 const std::string &LinkageName,
527 DICompileUnit CompileUnit,
528 unsigned LineNo, DIType Type,bool isLocalToUnit,
529 bool isDefinition, llvm::GlobalVariable *Val) {
532 GetTagConstant(dwarf::DW_TAG_variable),
533 getCastToEmpty(GetOrCreateGlobalVariableAnchor()),
534 getCastToEmpty(Context),
535 GetStringConstant(Name),
536 GetStringConstant(DisplayName),
537 GetStringConstant(LinkageName),
538 getCastToEmpty(CompileUnit),
539 ConstantInt::get(Type::Int32Ty, LineNo),
540 getCastToEmpty(Type),
541 ConstantInt::get(Type::Int1Ty, isLocalToUnit),
542 ConstantInt::get(Type::Int1Ty, isDefinition),
543 ConstantExpr::getBitCast(Val, EmptyStructPtr)
546 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
548 M.addTypeName("llvm.dbg.global_variable.type", Init->getType());
549 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
550 GlobalValue::InternalLinkage,
551 Init, "llvm.dbg.global_variable", &M);
552 GV->setSection("llvm.metadata");
553 return DIGlobalVariable(GV);
557 /// CreateVariable - Create a new descriptor for the specified variable.
558 DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context,
559 const std::string &Name,
560 DICompileUnit CompileUnit, unsigned LineNo,
565 getCastToEmpty(Context),
566 GetStringConstant(Name),
567 getCastToEmpty(CompileUnit),
568 ConstantInt::get(Type::Int32Ty, LineNo),
569 getCastToEmpty(Type),
572 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
574 M.addTypeName("llvm.dbg.variable.type", Init->getType());
575 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
576 GlobalValue::InternalLinkage,
577 Init, "llvm.dbg.variable", &M);
578 GV->setSection("llvm.metadata");
579 return DIVariable(GV);
583 /// CreateBlock - This creates a descriptor for a lexical block with the
584 /// specified parent context.
585 DIBlock DIFactory::CreateBlock(DIDescriptor Context) {
587 GetTagConstant(dwarf::DW_TAG_lexical_block),
588 getCastToEmpty(Context)
591 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
593 M.addTypeName("llvm.dbg.block.type", Init->getType());
594 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
595 GlobalValue::InternalLinkage,
596 Init, "llvm.dbg.block", &M);
597 GV->setSection("llvm.metadata");
602 //===----------------------------------------------------------------------===//
603 // DIFactory: Routines for inserting code into a function
604 //===----------------------------------------------------------------------===//
606 /// InsertStopPoint - Create a new llvm.dbg.stoppoint intrinsic invocation,
607 /// inserting it at the end of the specified basic block.
608 void DIFactory::InsertStopPoint(DICompileUnit CU, unsigned LineNo,
609 unsigned ColNo, BasicBlock *BB) {
611 // Lazily construct llvm.dbg.stoppoint function.
613 StopPointFn = llvm::Intrinsic::getDeclaration(&M,
614 llvm::Intrinsic::dbg_stoppoint);
616 // Invoke llvm.dbg.stoppoint
618 llvm::ConstantInt::get(llvm::Type::Int32Ty, LineNo),
619 llvm::ConstantInt::get(llvm::Type::Int32Ty, ColNo),
622 CallInst::Create(StopPointFn, Args, Args+3, "", BB);
625 /// InsertSubprogramStart - Create a new llvm.dbg.func.start intrinsic to
626 /// mark the start of the specified subprogram.
627 void DIFactory::InsertSubprogramStart(DISubprogram SP, BasicBlock *BB) {
628 // Lazily construct llvm.dbg.func.start.
630 FuncStartFn = llvm::Intrinsic::getDeclaration(&M,
631 llvm::Intrinsic::dbg_func_start);
633 // Call llvm.dbg.func.start which also implicitly sets a stoppoint.
634 CallInst::Create(FuncStartFn, getCastToEmpty(SP), "", BB);
637 /// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to
638 /// mark the start of a region for the specified scoping descriptor.
639 void DIFactory::InsertRegionStart(DIDescriptor D, BasicBlock *BB) {
640 // Lazily construct llvm.dbg.region.start function.
642 RegionStartFn = llvm::Intrinsic::getDeclaration(&M,
643 llvm::Intrinsic::dbg_region_start);
644 // Call llvm.dbg.func.start.
645 CallInst::Create(RegionStartFn, getCastToEmpty(D), "", BB);
649 /// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to
650 /// mark the end of a region for the specified scoping descriptor.
651 void DIFactory::InsertRegionEnd(DIDescriptor D, BasicBlock *BB) {
652 // Lazily construct llvm.dbg.region.end function.
654 RegionEndFn = llvm::Intrinsic::getDeclaration(&M,
655 llvm::Intrinsic::dbg_region_end);
657 CallInst::Create(RegionEndFn, getCastToEmpty(D), "", BB);
660 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
661 void DIFactory::InsertDeclare(llvm::Value *Storage, DIVariable D,
663 // Cast the storage to a {}* for the call to llvm.dbg.declare.
664 Storage = new llvm::BitCastInst(Storage, EmptyStructPtr, "", BB);
667 DeclareFn = llvm::Intrinsic::getDeclaration(&M,
668 llvm::Intrinsic::dbg_declare);
669 Value *Args[] = { Storage, getCastToEmpty(D) };
670 CallInst::Create(DeclareFn, Args, Args+2, "", BB);