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/IntrinsicInst.h"
20 #include "llvm/Instructions.h"
21 #include "llvm/Module.h"
22 #include "llvm/Analysis/ValueTracking.h"
23 #include "llvm/ADT/SmallPtrSet.h"
24 #include "llvm/ADT/SmallString.h"
25 #include "llvm/ADT/STLExtras.h"
26 #include "llvm/Support/Debug.h"
27 #include "llvm/Support/Dwarf.h"
28 #include "llvm/Support/raw_ostream.h"
30 using namespace llvm::dwarf;
32 //===----------------------------------------------------------------------===//
34 //===----------------------------------------------------------------------===//
36 DIDescriptor::DIDescriptor(const DIFile F) : DbgNode(F.DbgNode) {
39 DIDescriptor::DIDescriptor(const DISubprogram F) : DbgNode(F.DbgNode) {
42 DIDescriptor::DIDescriptor(const DILexicalBlock F) : DbgNode(F.DbgNode) {
45 DIDescriptor::DIDescriptor(const DIVariable F) : DbgNode(F.DbgNode) {
48 DIDescriptor::DIDescriptor(const DIType F) : DbgNode(F.DbgNode) {
52 DIDescriptor::getStringField(unsigned Elt) const {
56 if (Elt < DbgNode->getNumOperands())
57 if (MDString *MDS = dyn_cast_or_null<MDString>(DbgNode->getOperand(Elt)))
58 return MDS->getString();
63 uint64_t DIDescriptor::getUInt64Field(unsigned Elt) const {
67 if (Elt < DbgNode->getNumOperands())
68 if (ConstantInt *CI = dyn_cast<ConstantInt>(DbgNode->getOperand(Elt)))
69 return CI->getZExtValue();
74 DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const {
76 return DIDescriptor();
78 if (Elt < DbgNode->getNumOperands())
80 DIDescriptor(dyn_cast_or_null<const MDNode>(DbgNode->getOperand(Elt)));
81 return DIDescriptor();
84 GlobalVariable *DIDescriptor::getGlobalVariableField(unsigned Elt) const {
88 if (Elt < DbgNode->getNumOperands())
89 return dyn_cast_or_null<GlobalVariable>(DbgNode->getOperand(Elt));
93 Constant *DIDescriptor::getConstantField(unsigned Elt) const {
97 if (Elt < DbgNode->getNumOperands())
98 return dyn_cast_or_null<Constant>(DbgNode->getOperand(Elt));
102 Function *DIDescriptor::getFunctionField(unsigned Elt) const {
106 if (Elt < DbgNode->getNumOperands())
107 return dyn_cast_or_null<Function>(DbgNode->getOperand(Elt));
111 unsigned DIVariable::getNumAddrElements() const {
112 if (getVersion() <= llvm::LLVMDebugVersion8)
113 return DbgNode->getNumOperands()-6;
114 return DbgNode->getNumOperands()-7;
118 //===----------------------------------------------------------------------===//
120 //===----------------------------------------------------------------------===//
122 /// isBasicType - Return true if the specified tag is legal for
124 bool DIDescriptor::isBasicType() const {
125 return DbgNode && getTag() == dwarf::DW_TAG_base_type;
128 /// isDerivedType - Return true if the specified tag is legal for DIDerivedType.
129 bool DIDescriptor::isDerivedType() const {
130 if (!DbgNode) return false;
132 case dwarf::DW_TAG_typedef:
133 case dwarf::DW_TAG_pointer_type:
134 case dwarf::DW_TAG_reference_type:
135 case dwarf::DW_TAG_const_type:
136 case dwarf::DW_TAG_volatile_type:
137 case dwarf::DW_TAG_restrict_type:
138 case dwarf::DW_TAG_member:
139 case dwarf::DW_TAG_inheritance:
140 case dwarf::DW_TAG_friend:
143 // CompositeTypes are currently modelled as DerivedTypes.
144 return isCompositeType();
148 /// isCompositeType - Return true if the specified tag is legal for
150 bool DIDescriptor::isCompositeType() const {
151 if (!DbgNode) return false;
153 case dwarf::DW_TAG_array_type:
154 case dwarf::DW_TAG_structure_type:
155 case dwarf::DW_TAG_union_type:
156 case dwarf::DW_TAG_enumeration_type:
157 case dwarf::DW_TAG_vector_type:
158 case dwarf::DW_TAG_subroutine_type:
159 case dwarf::DW_TAG_class_type:
166 /// isVariable - Return true if the specified tag is legal for DIVariable.
167 bool DIDescriptor::isVariable() const {
168 if (!DbgNode) return false;
170 case dwarf::DW_TAG_auto_variable:
171 case dwarf::DW_TAG_arg_variable:
172 case dwarf::DW_TAG_return_variable:
179 /// isType - Return true if the specified tag is legal for DIType.
180 bool DIDescriptor::isType() const {
181 return isBasicType() || isCompositeType() || isDerivedType();
184 /// isSubprogram - Return true if the specified tag is legal for
186 bool DIDescriptor::isSubprogram() const {
187 return DbgNode && getTag() == dwarf::DW_TAG_subprogram;
190 /// isGlobalVariable - Return true if the specified tag is legal for
191 /// DIGlobalVariable.
192 bool DIDescriptor::isGlobalVariable() const {
193 return DbgNode && (getTag() == dwarf::DW_TAG_variable ||
194 getTag() == dwarf::DW_TAG_constant);
197 /// isGlobal - Return true if the specified tag is legal for DIGlobal.
198 bool DIDescriptor::isGlobal() const {
199 return isGlobalVariable();
202 /// isUnspecifiedParmeter - Return true if the specified tab is
203 /// DW_TAG_unspecified_parameters.
204 bool DIDescriptor::isUnspecifiedParameter() const {
205 return DbgNode && getTag() == dwarf::DW_TAG_unspecified_parameters;
208 /// isScope - Return true if the specified tag is one of the scope
210 bool DIDescriptor::isScope() const {
211 if (!DbgNode) return false;
213 case dwarf::DW_TAG_compile_unit:
214 case dwarf::DW_TAG_lexical_block:
215 case dwarf::DW_TAG_subprogram:
216 case dwarf::DW_TAG_namespace:
224 /// isCompileUnit - Return true if the specified tag is DW_TAG_compile_unit.
225 bool DIDescriptor::isCompileUnit() const {
226 return DbgNode && getTag() == dwarf::DW_TAG_compile_unit;
229 /// isFile - Return true if the specified tag is DW_TAG_file_type.
230 bool DIDescriptor::isFile() const {
231 return DbgNode && getTag() == dwarf::DW_TAG_file_type;
234 /// isNameSpace - Return true if the specified tag is DW_TAG_namespace.
235 bool DIDescriptor::isNameSpace() const {
236 return DbgNode && getTag() == dwarf::DW_TAG_namespace;
239 /// isLexicalBlock - Return true if the specified tag is DW_TAG_lexical_block.
240 bool DIDescriptor::isLexicalBlock() const {
241 return DbgNode && getTag() == dwarf::DW_TAG_lexical_block;
244 /// isSubrange - Return true if the specified tag is DW_TAG_subrange_type.
245 bool DIDescriptor::isSubrange() const {
246 return DbgNode && getTag() == dwarf::DW_TAG_subrange_type;
249 /// isEnumerator - Return true if the specified tag is DW_TAG_enumerator.
250 bool DIDescriptor::isEnumerator() const {
251 return DbgNode && getTag() == dwarf::DW_TAG_enumerator;
254 //===----------------------------------------------------------------------===//
255 // Simple Descriptor Constructors and other Methods
256 //===----------------------------------------------------------------------===//
258 DIType::DIType(const MDNode *N) : DIScope(N) {
260 if (!isBasicType() && !isDerivedType() && !isCompositeType()) {
265 unsigned DIArray::getNumElements() const {
268 return DbgNode->getNumOperands();
271 /// replaceAllUsesWith - Replace all uses of debug info referenced by
273 void DIType::replaceAllUsesWith(DIDescriptor &D) {
277 // Since we use a TrackingVH for the node, its easy for clients to manufacture
278 // legitimate situations where they want to replaceAllUsesWith() on something
279 // which, due to uniquing, has merged with the source. We shield clients from
280 // this detail by allowing a value to be replaced with replaceAllUsesWith()
283 MDNode *Node = const_cast<MDNode*>(DbgNode);
284 const MDNode *DN = D;
285 const Value *V = cast_or_null<Value>(DN);
286 Node->replaceAllUsesWith(const_cast<Value*>(V));
287 MDNode::deleteTemporary(Node);
291 /// Verify - Verify that a compile unit is well formed.
292 bool DICompileUnit::Verify() const {
295 StringRef N = getFilename();
298 // It is possible that directory and produce string is empty.
302 /// Verify - Verify that a type descriptor is well formed.
303 bool DIType::Verify() const {
306 if (!getContext().Verify())
309 DICompileUnit CU = getCompileUnit();
315 /// Verify - Verify that a basic type descriptor is well formed.
316 bool DIBasicType::Verify() const {
317 return isBasicType();
320 /// Verify - Verify that a derived type descriptor is well formed.
321 bool DIDerivedType::Verify() const {
322 return isDerivedType();
325 /// Verify - Verify that a composite type descriptor is well formed.
326 bool DICompositeType::Verify() const {
329 if (!getContext().Verify())
332 DICompileUnit CU = getCompileUnit();
338 /// Verify - Verify that a subprogram descriptor is well formed.
339 bool DISubprogram::Verify() const {
343 if (!getContext().Verify())
346 DICompileUnit CU = getCompileUnit();
350 DICompositeType Ty = getType();
356 /// Verify - Verify that a global variable descriptor is well formed.
357 bool DIGlobalVariable::Verify() const {
361 if (getDisplayName().empty())
364 if (!getContext().Verify())
367 DICompileUnit CU = getCompileUnit();
371 DIType Ty = getType();
375 if (!getGlobal() && !getConstant())
381 /// Verify - Verify that a variable descriptor is well formed.
382 bool DIVariable::Verify() const {
386 if (!getContext().Verify())
389 if (!getCompileUnit().Verify())
392 DIType Ty = getType();
399 /// Verify - Verify that a location descriptor is well formed.
400 bool DILocation::Verify() const {
404 return DbgNode->getNumOperands() == 4;
407 /// Verify - Verify that a namespace descriptor is well formed.
408 bool DINameSpace::Verify() const {
411 if (getName().empty())
413 if (!getCompileUnit().Verify())
418 /// getOriginalTypeSize - If this type is derived from a base type then
419 /// return base type size.
420 uint64_t DIDerivedType::getOriginalTypeSize() const {
421 unsigned Tag = getTag();
422 if (Tag == dwarf::DW_TAG_member || Tag == dwarf::DW_TAG_typedef ||
423 Tag == dwarf::DW_TAG_const_type || Tag == dwarf::DW_TAG_volatile_type ||
424 Tag == dwarf::DW_TAG_restrict_type) {
425 DIType BaseType = getTypeDerivedFrom();
426 // If this type is not derived from any type then take conservative
428 if (!BaseType.isValid())
429 return getSizeInBits();
430 if (BaseType.isDerivedType())
431 return DIDerivedType(BaseType).getOriginalTypeSize();
433 return BaseType.getSizeInBits();
436 return getSizeInBits();
439 /// isInlinedFnArgument - Return true if this variable provides debugging
440 /// information for an inlined function arguments.
441 bool DIVariable::isInlinedFnArgument(const Function *CurFn) {
442 assert(CurFn && "Invalid function");
443 if (!getContext().isSubprogram())
445 // This variable is not inlined function argument if its scope
446 // does not describe current function.
447 return !(DISubprogram(getContext()).describes(CurFn));
450 /// describes - Return true if this subprogram provides debugging
451 /// information for the function F.
452 bool DISubprogram::describes(const Function *F) {
453 assert(F && "Invalid function");
454 if (F == getFunction())
456 StringRef Name = getLinkageName();
459 if (F->getName() == Name)
464 unsigned DISubprogram::isOptimized() const {
465 assert (DbgNode && "Invalid subprogram descriptor!");
466 if (DbgNode->getNumOperands() == 16)
467 return getUnsignedField(15);
471 StringRef DIScope::getFilename() const {
474 if (isLexicalBlock())
475 return DILexicalBlock(DbgNode).getFilename();
477 return DISubprogram(DbgNode).getFilename();
479 return DICompileUnit(DbgNode).getFilename();
481 return DINameSpace(DbgNode).getFilename();
483 return DIType(DbgNode).getFilename();
485 return DIFile(DbgNode).getFilename();
486 assert(0 && "Invalid DIScope!");
490 StringRef DIScope::getDirectory() const {
493 if (isLexicalBlock())
494 return DILexicalBlock(DbgNode).getDirectory();
496 return DISubprogram(DbgNode).getDirectory();
498 return DICompileUnit(DbgNode).getDirectory();
500 return DINameSpace(DbgNode).getDirectory();
502 return DIType(DbgNode).getDirectory();
504 return DIFile(DbgNode).getDirectory();
505 assert(0 && "Invalid DIScope!");
509 //===----------------------------------------------------------------------===//
510 // DIDescriptor: dump routines for all descriptors.
511 //===----------------------------------------------------------------------===//
514 /// print - Print descriptor.
515 void DIDescriptor::print(raw_ostream &OS) const {
516 OS << "[" << dwarf::TagString(getTag()) << "] ";
517 OS.write_hex((intptr_t) &*DbgNode) << ']';
520 /// print - Print compile unit.
521 void DICompileUnit::print(raw_ostream &OS) const {
523 OS << " [" << dwarf::LanguageString(getLanguage()) << "] ";
525 OS << " [" << getDirectory() << "/" << getFilename() << "]";
528 /// print - Print type.
529 void DIType::print(raw_ostream &OS) const {
530 if (!DbgNode) return;
532 StringRef Res = getName();
534 OS << " [" << Res << "] ";
536 unsigned Tag = getTag();
537 OS << " [" << dwarf::TagString(Tag) << "] ";
539 // TODO : Print context
540 getCompileUnit().print(OS);
542 << "line " << getLineNumber() << ", "
543 << getSizeInBits() << " bits, "
544 << getAlignInBits() << " bit alignment, "
545 << getOffsetInBits() << " bit offset"
550 else if (isProtected())
551 OS << " [protected] ";
557 DIBasicType(DbgNode).print(OS);
558 else if (isDerivedType())
559 DIDerivedType(DbgNode).print(OS);
560 else if (isCompositeType())
561 DICompositeType(DbgNode).print(OS);
563 OS << "Invalid DIType\n";
570 /// print - Print basic type.
571 void DIBasicType::print(raw_ostream &OS) const {
572 OS << " [" << dwarf::AttributeEncodingString(getEncoding()) << "] ";
575 /// print - Print derived type.
576 void DIDerivedType::print(raw_ostream &OS) const {
577 OS << "\n\t Derived From: "; getTypeDerivedFrom().print(OS);
580 /// print - Print composite type.
581 void DICompositeType::print(raw_ostream &OS) const {
582 DIArray A = getTypeArray();
583 OS << " [" << A.getNumElements() << " elements]";
586 /// print - Print subprogram.
587 void DISubprogram::print(raw_ostream &OS) const {
588 StringRef Res = getName();
590 OS << " [" << Res << "] ";
592 unsigned Tag = getTag();
593 OS << " [" << dwarf::TagString(Tag) << "] ";
595 // TODO : Print context
596 getCompileUnit().print(OS);
597 OS << " [" << getLineNumber() << "] ";
608 /// print - Print global variable.
609 void DIGlobalVariable::print(raw_ostream &OS) const {
611 StringRef Res = getName();
613 OS << " [" << Res << "] ";
615 unsigned Tag = getTag();
616 OS << " [" << dwarf::TagString(Tag) << "] ";
618 // TODO : Print context
619 getCompileUnit().print(OS);
620 OS << " [" << getLineNumber() << "] ";
628 if (isGlobalVariable())
629 DIGlobalVariable(DbgNode).print(OS);
633 /// print - Print variable.
634 void DIVariable::print(raw_ostream &OS) const {
635 StringRef Res = getName();
637 OS << " [" << Res << "] ";
639 getCompileUnit().print(OS);
640 OS << " [" << getLineNumber() << "] ";
644 // FIXME: Dump complex addresses
647 /// dump - Print descriptor to dbgs() with a newline.
648 void DIDescriptor::dump() const {
649 print(dbgs()); dbgs() << '\n';
652 /// dump - Print compile unit to dbgs() with a newline.
653 void DICompileUnit::dump() const {
654 print(dbgs()); dbgs() << '\n';
657 /// dump - Print type to dbgs() with a newline.
658 void DIType::dump() const {
659 print(dbgs()); dbgs() << '\n';
662 /// dump - Print basic type to dbgs() with a newline.
663 void DIBasicType::dump() const {
664 print(dbgs()); dbgs() << '\n';
667 /// dump - Print derived type to dbgs() with a newline.
668 void DIDerivedType::dump() const {
669 print(dbgs()); dbgs() << '\n';
672 /// dump - Print composite type to dbgs() with a newline.
673 void DICompositeType::dump() const {
674 print(dbgs()); dbgs() << '\n';
677 /// dump - Print subprogram to dbgs() with a newline.
678 void DISubprogram::dump() const {
679 print(dbgs()); dbgs() << '\n';
682 /// dump - Print global variable.
683 void DIGlobalVariable::dump() const {
684 print(dbgs()); dbgs() << '\n';
687 /// dump - Print variable.
688 void DIVariable::dump() const {
689 print(dbgs()); dbgs() << '\n';
692 //===----------------------------------------------------------------------===//
693 // DIFactory: Basic Helpers
694 //===----------------------------------------------------------------------===//
696 DIFactory::DIFactory(Module &m)
697 : M(m), VMContext(M.getContext()), DeclareFn(0), ValueFn(0) {}
699 Constant *DIFactory::GetTagConstant(unsigned TAG) {
700 assert((TAG & LLVMDebugVersionMask) == 0 &&
701 "Tag too large for debug encoding!");
702 return ConstantInt::get(Type::getInt32Ty(VMContext), TAG | LLVMDebugVersion);
705 //===----------------------------------------------------------------------===//
706 // DIFactory: Primary Constructors
707 //===----------------------------------------------------------------------===//
709 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
710 /// This implicitly uniques the arrays created.
711 DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) {
713 Value *Null = llvm::Constant::getNullValue(Type::getInt32Ty(VMContext));
714 return DIArray(MDNode::get(VMContext, &Null, 1));
717 SmallVector<Value *, 16> Elts(Tys, Tys+NumTys);
718 return DIArray(MDNode::get(VMContext, Elts.data(), Elts.size()));
721 /// GetOrCreateSubrange - Create a descriptor for a value range. This
722 /// implicitly uniques the values returned.
723 DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) {
725 GetTagConstant(dwarf::DW_TAG_subrange_type),
726 ConstantInt::get(Type::getInt64Ty(VMContext), Lo),
727 ConstantInt::get(Type::getInt64Ty(VMContext), Hi)
730 return DISubrange(MDNode::get(VMContext, &Elts[0], 3));
733 /// CreateUnspecifiedParameter - Create unspeicified type descriptor
734 /// for the subroutine type.
735 DIDescriptor DIFactory::CreateUnspecifiedParameter() {
737 GetTagConstant(dwarf::DW_TAG_unspecified_parameters)
739 return DIDescriptor(MDNode::get(VMContext, &Elts[0], 1));
742 /// CreateCompileUnit - Create a new descriptor for the specified compile
743 /// unit. Note that this does not unique compile units within the module.
744 DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID,
751 unsigned RunTimeVer) {
753 GetTagConstant(dwarf::DW_TAG_compile_unit),
754 llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
755 ConstantInt::get(Type::getInt32Ty(VMContext), LangID),
756 MDString::get(VMContext, Filename),
757 MDString::get(VMContext, Directory),
758 MDString::get(VMContext, Producer),
759 ConstantInt::get(Type::getInt1Ty(VMContext), isMain),
760 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
761 MDString::get(VMContext, Flags),
762 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer)
765 return DICompileUnit(MDNode::get(VMContext, &Elts[0], 10));
768 /// CreateFile - Create a new descriptor for the specified file.
769 DIFile DIFactory::CreateFile(StringRef Filename,
773 GetTagConstant(dwarf::DW_TAG_file_type),
774 MDString::get(VMContext, Filename),
775 MDString::get(VMContext, Directory),
779 return DIFile(MDNode::get(VMContext, &Elts[0], 4));
782 /// CreateEnumerator - Create a single enumerator value.
783 DIEnumerator DIFactory::CreateEnumerator(StringRef Name, uint64_t Val){
785 GetTagConstant(dwarf::DW_TAG_enumerator),
786 MDString::get(VMContext, Name),
787 ConstantInt::get(Type::getInt64Ty(VMContext), Val)
789 return DIEnumerator(MDNode::get(VMContext, &Elts[0], 3));
793 /// CreateBasicType - Create a basic type like int, float, etc.
794 DIBasicType DIFactory::CreateBasicType(DIDescriptor Context,
799 uint64_t AlignInBits,
800 uint64_t OffsetInBits, unsigned Flags,
803 GetTagConstant(dwarf::DW_TAG_base_type),
805 MDString::get(VMContext, Name),
807 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
808 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
809 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
810 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
811 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
812 ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
814 return DIBasicType(MDNode::get(VMContext, &Elts[0], 10));
818 /// CreateBasicType - Create a basic type like int, float, etc.
819 DIBasicType DIFactory::CreateBasicTypeEx(DIDescriptor Context,
823 Constant *SizeInBits,
824 Constant *AlignInBits,
825 Constant *OffsetInBits, unsigned Flags,
828 GetTagConstant(dwarf::DW_TAG_base_type),
830 MDString::get(VMContext, Name),
832 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
836 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
837 ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
839 return DIBasicType(MDNode::get(VMContext, &Elts[0], 10));
842 /// CreateArtificialType - Create a new DIType with "artificial" flag set.
843 DIType DIFactory::CreateArtificialType(DIType Ty) {
844 if (Ty.isArtificial())
847 SmallVector<Value *, 9> Elts;
849 assert (N && "Unexpected input DIType!");
850 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
851 if (Value *V = N->getOperand(i))
854 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
857 unsigned CurFlags = Ty.getFlags();
858 CurFlags = CurFlags | DIType::FlagArtificial;
860 // Flags are stored at this slot.
861 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
863 return DIType(MDNode::get(VMContext, Elts.data(), Elts.size()));
866 /// CreateDerivedType - Create a derived type like const qualified type,
867 /// pointer, typedef, etc.
868 DIDerivedType DIFactory::CreateDerivedType(unsigned Tag,
869 DIDescriptor Context,
874 uint64_t AlignInBits,
875 uint64_t OffsetInBits,
877 DIType DerivedFrom) {
881 MDString::get(VMContext, Name),
883 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
884 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
885 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
886 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
887 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
890 return DIDerivedType(MDNode::get(VMContext, &Elts[0], 10));
894 /// CreateDerivedType - Create a derived type like const qualified type,
895 /// pointer, typedef, etc.
896 DIDerivedType DIFactory::CreateDerivedTypeEx(unsigned Tag,
897 DIDescriptor Context,
901 Constant *SizeInBits,
902 Constant *AlignInBits,
903 Constant *OffsetInBits,
905 DIType DerivedFrom) {
909 MDString::get(VMContext, Name),
911 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
915 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
918 return DIDerivedType(MDNode::get(VMContext, &Elts[0], 10));
922 /// CreateCompositeType - Create a composite type like array, struct, etc.
923 DICompositeType DIFactory::CreateCompositeType(unsigned Tag,
924 DIDescriptor Context,
929 uint64_t AlignInBits,
930 uint64_t OffsetInBits,
934 unsigned RuntimeLang,
935 MDNode *ContainingType) {
940 MDString::get(VMContext, Name),
942 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
943 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
944 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
945 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
946 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
949 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang),
953 MDNode *Node = MDNode::get(VMContext, &Elts[0], 13);
954 // Create a named metadata so that we do not lose this enum info.
955 if (Tag == dwarf::DW_TAG_enumeration_type) {
956 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.enum");
957 NMD->addOperand(Node);
959 return DICompositeType(Node);
963 /// CreateTemporaryType - Create a temporary forward-declared type.
964 DIType DIFactory::CreateTemporaryType() {
965 // Give the temporary MDNode a tag. It doesn't matter what tag we
966 // use here as long as DIType accepts it.
968 GetTagConstant(DW_TAG_base_type)
970 MDNode *Node = MDNode::getTemporary(VMContext, Elts, array_lengthof(Elts));
975 /// CreateCompositeType - Create a composite type like array, struct, etc.
976 DICompositeType DIFactory::CreateCompositeTypeEx(unsigned Tag,
977 DIDescriptor Context,
981 Constant *SizeInBits,
982 Constant *AlignInBits,
983 Constant *OffsetInBits,
987 unsigned RuntimeLang,
988 MDNode *ContainingType) {
992 MDString::get(VMContext, Name),
994 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
998 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1001 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang),
1004 MDNode *Node = MDNode::get(VMContext, &Elts[0], 13);
1005 // Create a named metadata so that we do not lose this enum info.
1006 if (Tag == dwarf::DW_TAG_enumeration_type) {
1007 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.enum");
1008 NMD->addOperand(Node);
1010 return DICompositeType(Node);
1014 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
1015 /// See comments in DISubprogram for descriptions of these fields. This
1016 /// method does not unique the generated descriptors.
1017 DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context,
1019 StringRef DisplayName,
1020 StringRef LinkageName,
1022 unsigned LineNo, DIType Ty,
1025 unsigned VK, unsigned VIndex,
1026 DIType ContainingType,
1032 GetTagConstant(dwarf::DW_TAG_subprogram),
1033 llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
1035 MDString::get(VMContext, Name),
1036 MDString::get(VMContext, DisplayName),
1037 MDString::get(VMContext, LinkageName),
1039 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1041 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1042 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1043 ConstantInt::get(Type::getInt32Ty(VMContext), (unsigned)VK),
1044 ConstantInt::get(Type::getInt32Ty(VMContext), VIndex),
1046 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1047 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
1050 MDNode *Node = MDNode::get(VMContext, &Elts[0], 17);
1052 // Create a named metadata so that we do not lose this mdnode.
1053 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.sp");
1054 NMD->addOperand(Node);
1055 return DISubprogram(Node);
1058 /// CreateSubprogramDefinition - Create new subprogram descriptor for the
1059 /// given declaration.
1060 DISubprogram DIFactory::CreateSubprogramDefinition(DISubprogram &SPDeclaration){
1061 if (SPDeclaration.isDefinition())
1062 return DISubprogram(SPDeclaration);
1064 MDNode *DeclNode = SPDeclaration;
1066 GetTagConstant(dwarf::DW_TAG_subprogram),
1067 llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
1068 DeclNode->getOperand(2), // Context
1069 DeclNode->getOperand(3), // Name
1070 DeclNode->getOperand(4), // DisplayName
1071 DeclNode->getOperand(5), // LinkageName
1072 DeclNode->getOperand(6), // CompileUnit
1073 DeclNode->getOperand(7), // LineNo
1074 DeclNode->getOperand(8), // Type
1075 DeclNode->getOperand(9), // isLocalToUnit
1076 ConstantInt::get(Type::getInt1Ty(VMContext), true),
1077 DeclNode->getOperand(11), // Virtuality
1078 DeclNode->getOperand(12), // VIndex
1079 DeclNode->getOperand(13), // Containting Type
1080 DeclNode->getOperand(14), // Flags
1081 DeclNode->getOperand(15), // isOptimized
1082 SPDeclaration.getFunction()
1084 MDNode *Node =MDNode::get(VMContext, &Elts[0], 16);
1086 // Create a named metadata so that we do not lose this mdnode.
1087 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.sp");
1088 NMD->addOperand(Node);
1089 return DISubprogram(Node);
1092 /// CreateGlobalVariable - Create a new descriptor for the specified global.
1094 DIFactory::CreateGlobalVariable(DIDescriptor Context, StringRef Name,
1095 StringRef DisplayName,
1096 StringRef LinkageName,
1098 unsigned LineNo, DIType Ty,bool isLocalToUnit,
1099 bool isDefinition, llvm::GlobalVariable *Val) {
1101 GetTagConstant(dwarf::DW_TAG_variable),
1102 llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
1104 MDString::get(VMContext, Name),
1105 MDString::get(VMContext, DisplayName),
1106 MDString::get(VMContext, LinkageName),
1108 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1110 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1111 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1115 Value *const *Vs = &Elts[0];
1116 MDNode *Node = MDNode::get(VMContext,Vs, 12);
1118 // Create a named metadata so that we do not lose this mdnode.
1119 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.gv");
1120 NMD->addOperand(Node);
1122 return DIGlobalVariable(Node);
1125 /// CreateGlobalVariable - Create a new descriptor for the specified constant.
1127 DIFactory::CreateGlobalVariable(DIDescriptor Context, StringRef Name,
1128 StringRef DisplayName,
1129 StringRef LinkageName,
1131 unsigned LineNo, DIType Ty,bool isLocalToUnit,
1132 bool isDefinition, llvm::Constant *Val) {
1134 GetTagConstant(dwarf::DW_TAG_variable),
1135 llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
1137 MDString::get(VMContext, Name),
1138 MDString::get(VMContext, DisplayName),
1139 MDString::get(VMContext, LinkageName),
1141 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1143 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1144 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1148 Value *const *Vs = &Elts[0];
1149 MDNode *Node = MDNode::get(VMContext,Vs, 12);
1151 // Create a named metadata so that we do not lose this mdnode.
1152 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.gv");
1153 NMD->addOperand(Node);
1155 return DIGlobalVariable(Node);
1158 /// CreateVariable - Create a new descriptor for the specified variable.
1159 DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context,
1163 DIType Ty, bool AlwaysPreserve,
1166 GetTagConstant(Tag),
1168 MDString::get(VMContext, Name),
1170 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1172 ConstantInt::get(Type::getInt32Ty(VMContext), Flags)
1174 MDNode *Node = MDNode::get(VMContext, &Elts[0], 7);
1175 if (AlwaysPreserve) {
1176 // The optimizer may remove local variable. If there is an interest
1177 // to preserve variable info in such situation then stash it in a
1179 DISubprogram Fn(getDISubprogram(Context));
1180 StringRef FName = "fn";
1181 if (Fn.getFunction())
1182 FName = Fn.getFunction()->getName();
1184 if (FName.startswith(StringRef(&One, 1)))
1185 FName = FName.substr(1);
1187 SmallString<32> Out;
1188 NamedMDNode *FnLocals =
1189 M.getOrInsertNamedMetadata(Twine("llvm.dbg.lv.", FName).toStringRef(Out));
1190 FnLocals->addOperand(Node);
1192 return DIVariable(Node);
1196 /// CreateComplexVariable - Create a new descriptor for the specified variable
1197 /// which has a complex address expression for its address.
1198 DIVariable DIFactory::CreateComplexVariable(unsigned Tag, DIDescriptor Context,
1199 StringRef Name, DIFile F,
1201 DIType Ty, Value *const *Addr,
1203 SmallVector<Value *, 15> Elts;
1204 Elts.push_back(GetTagConstant(Tag));
1205 Elts.push_back(Context);
1206 Elts.push_back(MDString::get(VMContext, Name));
1208 Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), LineNo));
1210 Elts.append(Addr, Addr+NumAddr);
1212 return DIVariable(MDNode::get(VMContext, Elts.data(), Elts.size()));
1216 /// CreateBlock - This creates a descriptor for a lexical block with the
1217 /// specified parent VMContext.
1218 DILexicalBlock DIFactory::CreateLexicalBlock(DIDescriptor Context,
1219 DIFile F, unsigned LineNo,
1221 // Defeat MDNode uniqing for lexical blocks.
1222 static unsigned int unique_id = 0;
1224 GetTagConstant(dwarf::DW_TAG_lexical_block),
1226 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1227 ConstantInt::get(Type::getInt32Ty(VMContext), Col),
1229 ConstantInt::get(Type::getInt32Ty(VMContext), unique_id++)
1231 return DILexicalBlock(MDNode::get(VMContext, &Elts[0], 6));
1234 /// CreateNameSpace - This creates new descriptor for a namespace
1235 /// with the specified parent context.
1236 DINameSpace DIFactory::CreateNameSpace(DIDescriptor Context, StringRef Name,
1240 GetTagConstant(dwarf::DW_TAG_namespace),
1242 MDString::get(VMContext, Name),
1244 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
1246 return DINameSpace(MDNode::get(VMContext, &Elts[0], 5));
1249 /// CreateLocation - Creates a debug info location.
1250 DILocation DIFactory::CreateLocation(unsigned LineNo, unsigned ColumnNo,
1251 DIScope S, DILocation OrigLoc) {
1253 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1254 ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo),
1258 return DILocation(MDNode::get(VMContext, &Elts[0], 4));
1261 //===----------------------------------------------------------------------===//
1262 // DIFactory: Routines for inserting code into a function
1263 //===----------------------------------------------------------------------===//
1265 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1266 Instruction *DIFactory::InsertDeclare(Value *Storage, DIVariable D,
1267 Instruction *InsertBefore) {
1268 assert(Storage && "no storage passed to dbg.declare");
1269 assert(D.Verify() && "empty DIVariable passed to dbg.declare");
1271 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1273 Value *Args[] = { MDNode::get(Storage->getContext(), &Storage, 1),
1275 return CallInst::Create(DeclareFn, Args, Args+2, "", InsertBefore);
1278 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1279 Instruction *DIFactory::InsertDeclare(Value *Storage, DIVariable D,
1280 BasicBlock *InsertAtEnd) {
1281 assert(Storage && "no storage passed to dbg.declare");
1282 assert(D.Verify() && "invalid DIVariable passed to dbg.declare");
1284 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1286 Value *Args[] = { MDNode::get(Storage->getContext(), &Storage, 1),
1289 // If this block already has a terminator then insert this intrinsic
1290 // before the terminator.
1291 if (TerminatorInst *T = InsertAtEnd->getTerminator())
1292 return CallInst::Create(DeclareFn, Args, Args+2, "", T);
1294 return CallInst::Create(DeclareFn, Args, Args+2, "", InsertAtEnd);}
1296 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1297 Instruction *DIFactory::InsertDbgValueIntrinsic(Value *V, uint64_t Offset,
1299 Instruction *InsertBefore) {
1300 assert(V && "no value passed to dbg.value");
1301 assert(D.Verify() && "invalid DIVariable passed to dbg.value");
1303 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1305 Value *Args[] = { MDNode::get(V->getContext(), &V, 1),
1306 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1308 return CallInst::Create(ValueFn, Args, Args+3, "", InsertBefore);
1311 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1312 Instruction *DIFactory::InsertDbgValueIntrinsic(Value *V, uint64_t Offset,
1314 BasicBlock *InsertAtEnd) {
1315 assert(V && "no value passed to dbg.value");
1316 assert(D.Verify() && "invalid DIVariable passed to dbg.value");
1318 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1320 Value *Args[] = { MDNode::get(V->getContext(), &V, 1),
1321 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1323 return CallInst::Create(ValueFn, Args, Args+3, "", InsertAtEnd);
1326 // RecordType - Record DIType in a module such that it is not lost even if
1327 // it is not referenced through debug info anchors.
1328 void DIFactory::RecordType(DIType T) {
1329 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.ty");
1334 //===----------------------------------------------------------------------===//
1335 // DebugInfoFinder implementations.
1336 //===----------------------------------------------------------------------===//
1338 /// processModule - Process entire module and collect debug info.
1339 void DebugInfoFinder::processModule(Module &M) {
1340 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
1341 for (Function::iterator FI = (*I).begin(), FE = (*I).end(); FI != FE; ++FI)
1342 for (BasicBlock::iterator BI = (*FI).begin(), BE = (*FI).end(); BI != BE;
1344 if (DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(BI))
1345 processDeclare(DDI);
1347 DebugLoc Loc = BI->getDebugLoc();
1348 if (Loc.isUnknown())
1351 LLVMContext &Ctx = BI->getContext();
1352 DIDescriptor Scope(Loc.getScope(Ctx));
1354 if (Scope.isCompileUnit())
1355 addCompileUnit(DICompileUnit(Scope));
1356 else if (Scope.isSubprogram())
1357 processSubprogram(DISubprogram(Scope));
1358 else if (Scope.isLexicalBlock())
1359 processLexicalBlock(DILexicalBlock(Scope));
1361 if (MDNode *IA = Loc.getInlinedAt(Ctx))
1362 processLocation(DILocation(IA));
1365 if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.gv")) {
1366 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
1367 DIGlobalVariable DIG(cast<MDNode>(NMD->getOperand(i)));
1368 if (addGlobalVariable(DIG)) {
1369 addCompileUnit(DIG.getCompileUnit());
1370 processType(DIG.getType());
1375 if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.sp"))
1376 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
1377 processSubprogram(DISubprogram(NMD->getOperand(i)));
1380 /// processLocation - Process DILocation.
1381 void DebugInfoFinder::processLocation(DILocation Loc) {
1382 if (!Loc.Verify()) return;
1383 DIDescriptor S(Loc.getScope());
1384 if (S.isCompileUnit())
1385 addCompileUnit(DICompileUnit(S));
1386 else if (S.isSubprogram())
1387 processSubprogram(DISubprogram(S));
1388 else if (S.isLexicalBlock())
1389 processLexicalBlock(DILexicalBlock(S));
1390 processLocation(Loc.getOrigLocation());
1393 /// processType - Process DIType.
1394 void DebugInfoFinder::processType(DIType DT) {
1398 addCompileUnit(DT.getCompileUnit());
1399 if (DT.isCompositeType()) {
1400 DICompositeType DCT(DT);
1401 processType(DCT.getTypeDerivedFrom());
1402 DIArray DA = DCT.getTypeArray();
1403 for (unsigned i = 0, e = DA.getNumElements(); i != e; ++i) {
1404 DIDescriptor D = DA.getElement(i);
1406 processType(DIType(D));
1407 else if (D.isSubprogram())
1408 processSubprogram(DISubprogram(D));
1410 } else if (DT.isDerivedType()) {
1411 DIDerivedType DDT(DT);
1412 processType(DDT.getTypeDerivedFrom());
1416 /// processLexicalBlock
1417 void DebugInfoFinder::processLexicalBlock(DILexicalBlock LB) {
1418 DIScope Context = LB.getContext();
1419 if (Context.isLexicalBlock())
1420 return processLexicalBlock(DILexicalBlock(Context));
1422 return processSubprogram(DISubprogram(Context));
1425 /// processSubprogram - Process DISubprogram.
1426 void DebugInfoFinder::processSubprogram(DISubprogram SP) {
1427 if (!addSubprogram(SP))
1429 addCompileUnit(SP.getCompileUnit());
1430 processType(SP.getType());
1433 /// processDeclare - Process DbgDeclareInst.
1434 void DebugInfoFinder::processDeclare(DbgDeclareInst *DDI) {
1435 MDNode *N = dyn_cast<MDNode>(DDI->getVariable());
1439 if (!DV.isVariable())
1442 if (!NodesSeen.insert(DV))
1445 addCompileUnit(DIVariable(N).getCompileUnit());
1446 processType(DIVariable(N).getType());
1449 /// addType - Add type into Tys.
1450 bool DebugInfoFinder::addType(DIType DT) {
1454 if (!NodesSeen.insert(DT))
1461 /// addCompileUnit - Add compile unit into CUs.
1462 bool DebugInfoFinder::addCompileUnit(DICompileUnit CU) {
1466 if (!NodesSeen.insert(CU))
1473 /// addGlobalVariable - Add global variable into GVs.
1474 bool DebugInfoFinder::addGlobalVariable(DIGlobalVariable DIG) {
1475 if (!DIDescriptor(DIG).isGlobalVariable())
1478 if (!NodesSeen.insert(DIG))
1485 // addSubprogram - Add subprgoram into SPs.
1486 bool DebugInfoFinder::addSubprogram(DISubprogram SP) {
1487 if (!DIDescriptor(SP).isSubprogram())
1490 if (!NodesSeen.insert(SP))
1497 /// Find the debug info descriptor corresponding to this global variable.
1498 static Value *findDbgGlobalDeclare(GlobalVariable *V) {
1499 const Module *M = V->getParent();
1500 NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.gv");
1504 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
1505 DIDescriptor DIG(cast<MDNode>(NMD->getOperand(i)));
1506 if (!DIG.isGlobalVariable())
1508 if (DIGlobalVariable(DIG).getGlobal() == V)
1514 /// Finds the llvm.dbg.declare intrinsic corresponding to this value if any.
1515 /// It looks through pointer casts too.
1516 static const DbgDeclareInst *findDbgDeclare(const Value *V) {
1517 V = V->stripPointerCasts();
1519 if (!isa<Instruction>(V) && !isa<Argument>(V))
1522 const Function *F = NULL;
1523 if (const Instruction *I = dyn_cast<Instruction>(V))
1524 F = I->getParent()->getParent();
1525 else if (const Argument *A = dyn_cast<Argument>(V))
1528 for (Function::const_iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI)
1529 for (BasicBlock::const_iterator BI = (*FI).begin(), BE = (*FI).end();
1531 if (const DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(BI))
1532 if (DDI->getAddress() == V)
1538 bool llvm::getLocationInfo(const Value *V, std::string &DisplayName,
1539 std::string &Type, unsigned &LineNo,
1540 std::string &File, std::string &Dir) {
1544 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(const_cast<Value*>(V))) {
1545 Value *DIGV = findDbgGlobalDeclare(GV);
1546 if (!DIGV) return false;
1547 DIGlobalVariable Var(cast<MDNode>(DIGV));
1549 StringRef D = Var.getDisplayName();
1552 LineNo = Var.getLineNumber();
1553 Unit = Var.getCompileUnit();
1554 TypeD = Var.getType();
1556 const DbgDeclareInst *DDI = findDbgDeclare(V);
1557 if (!DDI) return false;
1558 DIVariable Var(cast<MDNode>(DDI->getVariable()));
1560 StringRef D = Var.getName();
1563 LineNo = Var.getLineNumber();
1564 Unit = Var.getCompileUnit();
1565 TypeD = Var.getType();
1568 StringRef T = TypeD.getName();
1571 StringRef F = Unit.getFilename();
1574 StringRef D = Unit.getDirectory();
1580 /// getDISubprogram - Find subprogram that is enclosing this scope.
1581 DISubprogram llvm::getDISubprogram(const MDNode *Scope) {
1582 DIDescriptor D(Scope);
1583 if (D.isSubprogram())
1584 return DISubprogram(Scope);
1586 if (D.isLexicalBlock())
1587 return getDISubprogram(DILexicalBlock(Scope).getContext());
1589 return DISubprogram();
1592 /// getDICompositeType - Find underlying composite type.
1593 DICompositeType llvm::getDICompositeType(DIType T) {
1594 if (T.isCompositeType())
1595 return DICompositeType(T);
1597 if (T.isDerivedType())
1598 return getDICompositeType(DIDerivedType(T).getTypeDerivedFrom());
1600 return DICompositeType();