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) {}
104 /// isDerivedType - Return true if the specified tag is legal for
106 bool DIDerivedType::isDerivedType(unsigned Tag) {
108 case dwarf::DW_TAG_typedef:
109 case dwarf::DW_TAG_pointer_type:
110 case dwarf::DW_TAG_reference_type:
111 case dwarf::DW_TAG_const_type:
112 case dwarf::DW_TAG_volatile_type:
113 case dwarf::DW_TAG_restrict_type:
114 case dwarf::DW_TAG_member:
115 case dwarf::DW_TAG_inheritance:
118 // FIXME: Even though it doesn't make sense, CompositeTypes are current
119 // modelled as DerivedTypes, this should return true for them as well.
124 DIDerivedType::DIDerivedType(GlobalVariable *GV) : DIType(GV, true, true) {
125 if (GV && !isDerivedType(getTag()))
129 /// isCompositeType - Return true if the specified tag is legal for
131 bool DICompositeType::isCompositeType(unsigned TAG) {
133 case dwarf::DW_TAG_array_type:
134 case dwarf::DW_TAG_structure_type:
135 case dwarf::DW_TAG_union_type:
136 case dwarf::DW_TAG_enumeration_type:
137 case dwarf::DW_TAG_vector_type:
138 case dwarf::DW_TAG_subroutine_type:
145 DICompositeType::DICompositeType(GlobalVariable *GV)
146 : DIDerivedType(GV, true, true) {
147 if (GV && !isCompositeType(getTag()))
151 /// isVariable - Return true if the specified tag is legal for DIVariable.
152 bool DIVariable::isVariable(unsigned Tag) {
154 case dwarf::DW_TAG_auto_variable:
155 case dwarf::DW_TAG_arg_variable:
156 case dwarf::DW_TAG_return_variable:
163 DIVariable::DIVariable(GlobalVariable *GV) : DIDescriptor(GV) {
164 if (GV && !isVariable(getTag()))
170 //===----------------------------------------------------------------------===//
171 // DIFactory: Basic Helpers
172 //===----------------------------------------------------------------------===//
174 DIFactory::DIFactory(Module &m) : M(m) {
175 StopPointFn = FuncStartFn = RegionStartFn = RegionEndFn = DeclareFn = 0;
176 EmptyStructPtr = PointerType::getUnqual(StructType::get(NULL, NULL));
179 /// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'.
180 /// This is only valid when the descriptor is non-null.
181 Constant *DIFactory::getCastToEmpty(DIDescriptor D) {
182 if (D.isNull()) return Constant::getNullValue(EmptyStructPtr);
183 return ConstantExpr::getBitCast(D.getGV(), EmptyStructPtr);
186 Constant *DIFactory::GetTagConstant(unsigned TAG) {
187 assert((TAG & DIDescriptor::VersionMask) == 0 &&
188 "Tag too large for debug encoding!");
189 return ConstantInt::get(Type::Int32Ty, TAG | DIDescriptor::Version6);
192 Constant *DIFactory::GetStringConstant(const std::string &String) {
193 // Check string cache for previous edition.
194 Constant *&Slot = StringCache[String];
196 // Return Constant if previously defined.
197 if (Slot) return Slot;
199 const PointerType *DestTy = PointerType::getUnqual(Type::Int8Ty);
201 // If empty string then use a sbyte* null instead.
203 return Slot = ConstantPointerNull::get(DestTy);
205 // Construct string as an llvm constant.
206 Constant *ConstStr = ConstantArray::get(String);
208 // Otherwise create and return a new string global.
209 GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true,
210 GlobalVariable::InternalLinkage,
211 ConstStr, ".str", &M);
212 StrGV->setSection("llvm.metadata");
213 return Slot = ConstantExpr::getBitCast(StrGV, DestTy);
216 /// GetOrCreateAnchor - Look up an anchor for the specified tag and name. If it
217 /// already exists, return it. If not, create a new one and return it.
218 DIAnchor DIFactory::GetOrCreateAnchor(unsigned TAG, const char *Name) {
219 const Type *EltTy = StructType::get(Type::Int32Ty, Type::Int32Ty, NULL);
221 // Otherwise, create the global or return it if already in the module.
222 Constant *C = M.getOrInsertGlobal(Name, EltTy);
223 assert(isa<GlobalVariable>(C) && "Incorrectly typed anchor?");
224 GlobalVariable *GV = cast<GlobalVariable>(C);
226 // If it has an initializer, it is already in the module.
227 if (GV->hasInitializer())
228 return SubProgramAnchor = DIAnchor(GV);
230 GV->setLinkage(GlobalValue::LinkOnceLinkage);
231 GV->setSection("llvm.metadata");
232 GV->setConstant(true);
233 M.addTypeName("llvm.dbg.anchor.type", EltTy);
235 // Otherwise, set the initializer.
237 GetTagConstant(dwarf::DW_TAG_anchor),
238 ConstantInt::get(Type::Int32Ty, TAG)
241 GV->setInitializer(ConstantStruct::get(Elts, 2));
247 //===----------------------------------------------------------------------===//
248 // DIFactory: Primary Constructors
249 //===----------------------------------------------------------------------===//
251 /// GetOrCreateCompileUnitAnchor - Return the anchor for compile units,
252 /// creating a new one if there isn't already one in the module.
253 DIAnchor DIFactory::GetOrCreateCompileUnitAnchor() {
254 // If we already created one, just return it.
255 if (!CompileUnitAnchor.isNull())
256 return CompileUnitAnchor;
257 return CompileUnitAnchor = GetOrCreateAnchor(dwarf::DW_TAG_compile_unit,
258 "llvm.dbg.compile_units");
261 /// GetOrCreateSubprogramAnchor - Return the anchor for subprograms,
262 /// creating a new one if there isn't already one in the module.
263 DIAnchor DIFactory::GetOrCreateSubprogramAnchor() {
264 // If we already created one, just return it.
265 if (!SubProgramAnchor.isNull())
266 return SubProgramAnchor;
267 return SubProgramAnchor = GetOrCreateAnchor(dwarf::DW_TAG_subprogram,
268 "llvm.dbg.subprograms");
271 /// GetOrCreateGlobalVariableAnchor - Return the anchor for globals,
272 /// creating a new one if there isn't already one in the module.
273 DIAnchor DIFactory::GetOrCreateGlobalVariableAnchor() {
274 // If we already created one, just return it.
275 if (!GlobalVariableAnchor.isNull())
276 return GlobalVariableAnchor;
277 return GlobalVariableAnchor = GetOrCreateAnchor(dwarf::DW_TAG_variable,
278 "llvm.dbg.global_variables");
281 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
282 /// This implicitly uniques the arrays created.
283 DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) {
284 SmallVector<Constant*, 16> Elts;
286 for (unsigned i = 0; i != NumTys; ++i)
287 Elts.push_back(getCastToEmpty(Tys[i]));
289 Constant *Init = ConstantArray::get(ArrayType::get(EmptyStructPtr,
291 &Elts[0], Elts.size());
292 // If we already have this array, just return the uniqued version.
293 DIDescriptor &Entry = SimpleConstantCache[Init];
294 if (!Entry.isNull()) return DIArray(Entry.getGV());
296 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
297 GlobalValue::InternalLinkage,
298 Init, "llvm.dbg.array", &M);
299 GV->setSection("llvm.metadata");
300 Entry = DIDescriptor(GV);
304 /// GetOrCreateSubrange - Create a descriptor for a value range. This
305 /// implicitly uniques the values returned.
306 DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) {
308 GetTagConstant(dwarf::DW_TAG_subrange_type),
309 ConstantInt::get(Type::Int64Ty, Lo),
310 ConstantInt::get(Type::Int64Ty, Hi)
313 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
315 // If we already have this range, just return the uniqued version.
316 DIDescriptor &Entry = SimpleConstantCache[Init];
317 if (!Entry.isNull()) return DISubrange(Entry.getGV());
319 M.addTypeName("llvm.dbg.subrange.type", Init->getType());
321 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
322 GlobalValue::InternalLinkage,
323 Init, "llvm.dbg.subrange", &M);
324 GV->setSection("llvm.metadata");
325 Entry = DIDescriptor(GV);
326 return DISubrange(GV);
331 /// CreateCompileUnit - Create a new descriptor for the specified compile
332 /// unit. Note that this does not unique compile units within the module.
333 DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID,
334 const std::string &Filename,
335 const std::string &Directory,
336 const std::string &Producer) {
338 GetTagConstant(dwarf::DW_TAG_compile_unit),
339 getCastToEmpty(GetOrCreateCompileUnitAnchor()),
340 ConstantInt::get(Type::Int32Ty, LangID),
341 GetStringConstant(Filename),
342 GetStringConstant(Directory),
343 GetStringConstant(Producer)
346 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
348 M.addTypeName("llvm.dbg.compile_unit.type", Init->getType());
349 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
350 GlobalValue::InternalLinkage,
351 Init, "llvm.dbg.compile_unit", &M);
352 GV->setSection("llvm.metadata");
353 return DICompileUnit(GV);
356 /// CreateEnumerator - Create a single enumerator value.
357 DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){
359 GetTagConstant(dwarf::DW_TAG_enumerator),
360 GetStringConstant(Name),
361 ConstantInt::get(Type::Int64Ty, Val)
364 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
366 M.addTypeName("llvm.dbg.enumerator.type", Init->getType());
367 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
368 GlobalValue::InternalLinkage,
369 Init, "llvm.dbg.enumerator", &M);
370 GV->setSection("llvm.metadata");
371 return DIEnumerator(GV);
375 /// CreateBasicType - Create a basic type like int, float, etc.
376 DIBasicType DIFactory::CreateBasicType(DIDescriptor Context,
377 const std::string &Name,
378 DICompileUnit CompileUnit,
381 uint64_t AlignInBits,
382 uint64_t OffsetInBits, unsigned Flags,
385 GetTagConstant(dwarf::DW_TAG_base_type),
386 getCastToEmpty(Context),
387 GetStringConstant(Name),
388 getCastToEmpty(CompileUnit),
389 ConstantInt::get(Type::Int32Ty, LineNumber),
390 ConstantInt::get(Type::Int64Ty, SizeInBits),
391 ConstantInt::get(Type::Int64Ty, AlignInBits),
392 ConstantInt::get(Type::Int64Ty, OffsetInBits),
393 ConstantInt::get(Type::Int32Ty, Flags),
394 ConstantInt::get(Type::Int32Ty, Encoding)
397 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
399 M.addTypeName("llvm.dbg.basictype.type", Init->getType());
400 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
401 GlobalValue::InternalLinkage,
402 Init, "llvm.dbg.basictype", &M);
403 GV->setSection("llvm.metadata");
404 return DIBasicType(GV);
407 /// CreateDerivedType - Create a derived type like const qualified type,
408 /// pointer, typedef, etc.
409 DIDerivedType DIFactory::CreateDerivedType(unsigned Tag,
410 DIDescriptor Context,
411 const std::string &Name,
412 DICompileUnit CompileUnit,
415 uint64_t AlignInBits,
416 uint64_t OffsetInBits,
418 DIType DerivedFrom) {
421 getCastToEmpty(Context),
422 GetStringConstant(Name),
423 getCastToEmpty(CompileUnit),
424 ConstantInt::get(Type::Int32Ty, LineNumber),
425 ConstantInt::get(Type::Int64Ty, SizeInBits),
426 ConstantInt::get(Type::Int64Ty, AlignInBits),
427 ConstantInt::get(Type::Int64Ty, OffsetInBits),
428 ConstantInt::get(Type::Int32Ty, Flags),
429 getCastToEmpty(DerivedFrom)
432 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
434 M.addTypeName("llvm.dbg.derivedtype.type", Init->getType());
435 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
436 GlobalValue::InternalLinkage,
437 Init, "llvm.dbg.derivedtype", &M);
438 GV->setSection("llvm.metadata");
439 return DIDerivedType(GV);
442 /// CreateCompositeType - Create a composite type like array, struct, etc.
443 DICompositeType DIFactory::CreateCompositeType(unsigned Tag,
444 DIDescriptor Context,
445 const std::string &Name,
446 DICompileUnit CompileUnit,
449 uint64_t AlignInBits,
450 uint64_t OffsetInBits,
456 getCastToEmpty(Context),
457 GetStringConstant(Name),
458 getCastToEmpty(CompileUnit),
459 ConstantInt::get(Type::Int32Ty, LineNumber),
460 ConstantInt::get(Type::Int64Ty, SizeInBits),
461 ConstantInt::get(Type::Int64Ty, AlignInBits),
462 ConstantInt::get(Type::Int64Ty, OffsetInBits),
463 ConstantInt::get(Type::Int32Ty, Flags),
464 getCastToEmpty(DerivedFrom),
465 getCastToEmpty(Elements)
468 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
470 M.addTypeName("llvm.dbg.composite.type", Init->getType());
471 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
472 GlobalValue::InternalLinkage,
473 Init, "llvm.dbg.composite", &M);
474 GV->setSection("llvm.metadata");
475 return DICompositeType(GV);
479 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
480 /// See comments in DISubprogram for descriptions of these fields. This
481 /// method does not unique the generated descriptors.
482 DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context,
483 const std::string &Name,
484 const std::string &DisplayName,
485 const std::string &LinkageName,
486 DICompileUnit CompileUnit,
487 unsigned LineNo, DIType Type,
491 GetTagConstant(dwarf::DW_TAG_subprogram),
492 getCastToEmpty(GetOrCreateSubprogramAnchor()),
493 getCastToEmpty(Context),
494 GetStringConstant(Name),
495 GetStringConstant(DisplayName),
496 GetStringConstant(LinkageName),
497 getCastToEmpty(CompileUnit),
498 ConstantInt::get(Type::Int32Ty, LineNo),
499 getCastToEmpty(Type),
500 ConstantInt::get(Type::Int1Ty, isLocalToUnit),
501 ConstantInt::get(Type::Int1Ty, isDefinition)
504 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
506 M.addTypeName("llvm.dbg.subprogram.type", Init->getType());
507 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
508 GlobalValue::InternalLinkage,
509 Init, "llvm.dbg.subprogram", &M);
510 GV->setSection("llvm.metadata");
511 return DISubprogram(GV);
514 /// CreateGlobalVariable - Create a new descriptor for the specified global.
516 DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
517 const std::string &DisplayName,
518 const std::string &LinkageName,
519 DICompileUnit CompileUnit,
520 unsigned LineNo, DIType Type,bool isLocalToUnit,
521 bool isDefinition, llvm::GlobalVariable *Val) {
524 GetTagConstant(dwarf::DW_TAG_variable),
525 getCastToEmpty(GetOrCreateGlobalVariableAnchor()),
526 getCastToEmpty(Context),
527 GetStringConstant(Name),
528 GetStringConstant(DisplayName),
529 GetStringConstant(LinkageName),
530 getCastToEmpty(CompileUnit),
531 ConstantInt::get(Type::Int32Ty, LineNo),
532 getCastToEmpty(Type),
533 ConstantInt::get(Type::Int1Ty, isLocalToUnit),
534 ConstantInt::get(Type::Int1Ty, isDefinition),
535 ConstantExpr::getBitCast(Val, EmptyStructPtr)
538 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
540 M.addTypeName("llvm.dbg.global_variable.type", Init->getType());
541 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
542 GlobalValue::InternalLinkage,
543 Init, "llvm.dbg.global_variable", &M);
544 GV->setSection("llvm.metadata");
545 return DIGlobalVariable(GV);
549 /// CreateVariable - Create a new descriptor for the specified variable.
550 DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context,
551 const std::string &Name,
552 DICompileUnit CompileUnit, unsigned LineNo,
557 getCastToEmpty(Context),
558 GetStringConstant(Name),
559 getCastToEmpty(CompileUnit),
560 ConstantInt::get(Type::Int32Ty, LineNo),
561 getCastToEmpty(Type),
564 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
566 M.addTypeName("llvm.dbg.variable.type", Init->getType());
567 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
568 GlobalValue::InternalLinkage,
569 Init, "llvm.dbg.variable", &M);
570 GV->setSection("llvm.metadata");
571 return DIVariable(GV);
575 /// CreateBlock - This creates a descriptor for a lexical block with the
576 /// specified parent context.
577 DIBlock DIFactory::CreateBlock(DIDescriptor Context) {
579 GetTagConstant(dwarf::DW_TAG_lexical_block),
580 getCastToEmpty(Context)
583 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
585 M.addTypeName("llvm.dbg.block.type", Init->getType());
586 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
587 GlobalValue::InternalLinkage,
588 Init, "llvm.dbg.block", &M);
589 GV->setSection("llvm.metadata");
594 //===----------------------------------------------------------------------===//
595 // DIFactory: Routines for inserting code into a function
596 //===----------------------------------------------------------------------===//
598 /// InsertStopPoint - Create a new llvm.dbg.stoppoint intrinsic invocation,
599 /// inserting it at the end of the specified basic block.
600 void DIFactory::InsertStopPoint(DICompileUnit CU, unsigned LineNo,
601 unsigned ColNo, BasicBlock *BB) {
603 // Lazily construct llvm.dbg.stoppoint function.
605 StopPointFn = llvm::Intrinsic::getDeclaration(&M,
606 llvm::Intrinsic::dbg_stoppoint);
608 // Invoke llvm.dbg.stoppoint
610 llvm::ConstantInt::get(llvm::Type::Int32Ty, LineNo),
611 llvm::ConstantInt::get(llvm::Type::Int32Ty, ColNo),
614 CallInst::Create(StopPointFn, Args, Args+3, "", BB);
617 /// InsertSubprogramStart - Create a new llvm.dbg.func.start intrinsic to
618 /// mark the start of the specified subprogram.
619 void DIFactory::InsertSubprogramStart(DISubprogram SP, BasicBlock *BB) {
620 // Lazily construct llvm.dbg.func.start.
622 FuncStartFn = llvm::Intrinsic::getDeclaration(&M,
623 llvm::Intrinsic::dbg_func_start);
625 // Call llvm.dbg.func.start which also implicitly sets a stoppoint.
626 CallInst::Create(FuncStartFn, getCastToEmpty(SP), "", BB);
629 /// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to
630 /// mark the start of a region for the specified scoping descriptor.
631 void DIFactory::InsertRegionStart(DIDescriptor D, BasicBlock *BB) {
632 // Lazily construct llvm.dbg.region.start function.
634 RegionStartFn = llvm::Intrinsic::getDeclaration(&M,
635 llvm::Intrinsic::dbg_region_start);
636 // Call llvm.dbg.func.start.
637 CallInst::Create(RegionStartFn, getCastToEmpty(D), "", BB);
641 /// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to
642 /// mark the end of a region for the specified scoping descriptor.
643 void DIFactory::InsertRegionEnd(DIDescriptor D, BasicBlock *BB) {
644 // Lazily construct llvm.dbg.region.end function.
646 RegionEndFn = llvm::Intrinsic::getDeclaration(&M,
647 llvm::Intrinsic::dbg_region_end);
649 CallInst::Create(RegionEndFn, getCastToEmpty(D), "", BB);
652 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
653 void DIFactory::InsertDeclare(llvm::Value *Storage, DIVariable D,
655 // Cast the storage to a {}* for the call to llvm.dbg.declare.
656 Storage = new llvm::BitCastInst(Storage, EmptyStructPtr, "", BB);
659 DeclareFn = llvm::Intrinsic::getDeclaration(&M,
660 llvm::Intrinsic::dbg_declare);
661 Value *Args[] = { Storage, getCastToEmpty(D) };
662 CallInst::Create(DeclareFn, Args, Args+2, "", BB);