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/IR/DebugInfo.h"
16 #include "LLVMContextImpl.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/SmallPtrSet.h"
19 #include "llvm/ADT/SmallString.h"
20 #include "llvm/Analysis/ValueTracking.h"
21 #include "llvm/IR/Constants.h"
22 #include "llvm/IR/DIBuilder.h"
23 #include "llvm/IR/DerivedTypes.h"
24 #include "llvm/IR/Instructions.h"
25 #include "llvm/IR/IntrinsicInst.h"
26 #include "llvm/IR/Intrinsics.h"
27 #include "llvm/IR/Module.h"
28 #include "llvm/IR/ValueHandle.h"
29 #include "llvm/Support/Debug.h"
30 #include "llvm/Support/Dwarf.h"
31 #include "llvm/Support/raw_ostream.h"
33 using namespace llvm::dwarf;
35 //===----------------------------------------------------------------------===//
37 //===----------------------------------------------------------------------===//
39 bool DIDescriptor::Verify() const {
41 (DIDerivedType(DbgNode).Verify() ||
42 DICompositeType(DbgNode).Verify() || DIBasicType(DbgNode).Verify() ||
43 DIVariable(DbgNode).Verify() || DISubprogram(DbgNode).Verify() ||
44 DIGlobalVariable(DbgNode).Verify() || DIFile(DbgNode).Verify() ||
45 DICompileUnit(DbgNode).Verify() || DINameSpace(DbgNode).Verify() ||
46 DILexicalBlock(DbgNode).Verify() ||
47 DILexicalBlockFile(DbgNode).Verify() ||
48 DISubrange(DbgNode).Verify() || DIEnumerator(DbgNode).Verify() ||
49 DIObjCProperty(DbgNode).Verify() ||
50 DITemplateTypeParameter(DbgNode).Verify() ||
51 DITemplateValueParameter(DbgNode).Verify() ||
52 DIImportedEntity(DbgNode).Verify() || DIExpression(DbgNode).Verify());
55 static Metadata *getField(const MDNode *DbgNode, unsigned Elt) {
56 if (!DbgNode || Elt >= DbgNode->getNumOperands())
58 return DbgNode->getOperand(Elt);
61 static MDNode *getNodeField(const MDNode *DbgNode, unsigned Elt) {
62 return dyn_cast_or_null<MDNode>(getField(DbgNode, Elt));
65 static StringRef getStringField(const MDNode *DbgNode, unsigned Elt) {
66 if (MDString *MDS = dyn_cast_or_null<MDString>(getField(DbgNode, Elt)))
67 return MDS->getString();
71 StringRef DIDescriptor::getStringField(unsigned Elt) const {
72 return ::getStringField(DbgNode, Elt);
75 uint64_t DIDescriptor::getUInt64Field(unsigned Elt) const {
76 if (auto *C = getConstantField(Elt))
77 if (ConstantInt *CI = dyn_cast<ConstantInt>(C))
78 return CI->getZExtValue();
83 int64_t DIDescriptor::getInt64Field(unsigned Elt) const {
84 if (auto *C = getConstantField(Elt))
85 if (ConstantInt *CI = dyn_cast<ConstantInt>(C))
86 return CI->getZExtValue();
91 DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const {
92 MDNode *Field = getNodeField(DbgNode, Elt);
93 return DIDescriptor(Field);
96 GlobalVariable *DIDescriptor::getGlobalVariableField(unsigned Elt) const {
97 return dyn_cast_or_null<GlobalVariable>(getConstantField(Elt));
100 Constant *DIDescriptor::getConstantField(unsigned Elt) const {
104 if (Elt < DbgNode->getNumOperands())
106 dyn_cast_or_null<ConstantAsMetadata>(DbgNode->getOperand(Elt)))
107 return C->getValue();
111 Function *DIDescriptor::getFunctionField(unsigned Elt) const {
112 return dyn_cast_or_null<Function>(getConstantField(Elt));
115 void DIDescriptor::replaceFunctionField(unsigned Elt, Function *F) {
119 if (Elt < DbgNode->getNumOperands()) {
120 MDNode *Node = const_cast<MDNode *>(DbgNode);
121 Node->replaceOperandWith(Elt, F ? ConstantAsMetadata::get(F) : nullptr);
125 static unsigned DIVariableInlinedAtIndex = 4;
126 MDNode *DIVariable::getInlinedAt() const {
127 return getNodeField(DbgNode, DIVariableInlinedAtIndex);
130 /// \brief Return the size reported by the variable's type.
131 unsigned DIVariable::getSizeInBits(const DITypeIdentifierMap &Map) {
132 DIType Ty = getType().resolve(Map);
133 // Follow derived types until we reach a type that
134 // reports back a size.
135 while (Ty.isDerivedType() && !Ty.getSizeInBits()) {
136 DIDerivedType DT(&*Ty);
137 Ty = DT.getTypeDerivedFrom().resolve(Map);
139 assert(Ty.getSizeInBits() && "type with size 0");
140 return Ty.getSizeInBits();
143 uint64_t DIExpression::getElement(unsigned Idx) const {
144 unsigned I = Idx + 1;
145 assert(I < getNumHeaderFields() &&
146 "non-existing complex address element requested");
147 return getHeaderFieldAs<int64_t>(I);
150 bool DIExpression::isVariablePiece() const {
151 unsigned N = getNumElements();
152 return N >=3 && getElement(N-3) == dwarf::DW_OP_piece;
155 uint64_t DIExpression::getPieceOffset() const {
156 assert(isVariablePiece() && "not a piece");
157 return getElement(getNumElements()-2);
160 uint64_t DIExpression::getPieceSize() const {
161 assert(isVariablePiece() && "not a piece");
162 return getElement(getNumElements()-1);
165 DIExpression::iterator DIExpression::begin() const {
166 return DIExpression::iterator(*this);
169 DIExpression::iterator DIExpression::end() const {
170 return DIExpression::iterator();
173 const DIExpression::Operand &DIExpression::Operand::getNext() const {
178 //===----------------------------------------------------------------------===//
180 //===----------------------------------------------------------------------===//
182 bool DIDescriptor::isSubroutineType() const {
183 return DbgNode && getTag() == dwarf::DW_TAG_subroutine_type;
186 bool DIDescriptor::isBasicType() const {
190 case dwarf::DW_TAG_base_type:
191 case dwarf::DW_TAG_unspecified_type:
198 bool DIDescriptor::isDerivedType() const {
202 case dwarf::DW_TAG_typedef:
203 case dwarf::DW_TAG_pointer_type:
204 case dwarf::DW_TAG_ptr_to_member_type:
205 case dwarf::DW_TAG_reference_type:
206 case dwarf::DW_TAG_rvalue_reference_type:
207 case dwarf::DW_TAG_const_type:
208 case dwarf::DW_TAG_volatile_type:
209 case dwarf::DW_TAG_restrict_type:
210 case dwarf::DW_TAG_member:
211 case dwarf::DW_TAG_inheritance:
212 case dwarf::DW_TAG_friend:
215 // CompositeTypes are currently modelled as DerivedTypes.
216 return isCompositeType();
220 bool DIDescriptor::isCompositeType() const {
224 case dwarf::DW_TAG_array_type:
225 case dwarf::DW_TAG_structure_type:
226 case dwarf::DW_TAG_union_type:
227 case dwarf::DW_TAG_enumeration_type:
228 case dwarf::DW_TAG_subroutine_type:
229 case dwarf::DW_TAG_class_type:
236 bool DIDescriptor::isVariable() const {
240 case dwarf::DW_TAG_auto_variable:
241 case dwarf::DW_TAG_arg_variable:
248 bool DIDescriptor::isType() const {
249 return isBasicType() || isCompositeType() || isDerivedType();
252 bool DIDescriptor::isSubprogram() const {
253 return DbgNode && getTag() == dwarf::DW_TAG_subprogram;
256 bool DIDescriptor::isGlobalVariable() const {
257 return DbgNode && (getTag() == dwarf::DW_TAG_variable ||
258 getTag() == dwarf::DW_TAG_constant);
261 bool DIDescriptor::isScope() const {
265 case dwarf::DW_TAG_compile_unit:
266 case dwarf::DW_TAG_lexical_block:
267 case dwarf::DW_TAG_subprogram:
268 case dwarf::DW_TAG_namespace:
269 case dwarf::DW_TAG_file_type:
277 bool DIDescriptor::isTemplateTypeParameter() const {
278 return DbgNode && getTag() == dwarf::DW_TAG_template_type_parameter;
281 bool DIDescriptor::isTemplateValueParameter() const {
282 return DbgNode && (getTag() == dwarf::DW_TAG_template_value_parameter ||
283 getTag() == dwarf::DW_TAG_GNU_template_template_param ||
284 getTag() == dwarf::DW_TAG_GNU_template_parameter_pack);
287 bool DIDescriptor::isCompileUnit() const {
288 return DbgNode && getTag() == dwarf::DW_TAG_compile_unit;
291 bool DIDescriptor::isFile() const {
292 return DbgNode && getTag() == dwarf::DW_TAG_file_type;
295 bool DIDescriptor::isNameSpace() const {
296 return DbgNode && getTag() == dwarf::DW_TAG_namespace;
299 bool DIDescriptor::isLexicalBlockFile() const {
300 return DbgNode && getTag() == dwarf::DW_TAG_lexical_block &&
301 DbgNode->getNumOperands() == 3 && getNumHeaderFields() == 2;
304 bool DIDescriptor::isLexicalBlock() const {
305 // FIXME: There are always exactly 4 header fields in DILexicalBlock, but
306 // something relies on this returning true for DILexicalBlockFile.
307 return DbgNode && getTag() == dwarf::DW_TAG_lexical_block &&
308 DbgNode->getNumOperands() == 3 &&
309 (getNumHeaderFields() == 2 || getNumHeaderFields() == 4);
312 bool DIDescriptor::isSubrange() const {
313 return DbgNode && getTag() == dwarf::DW_TAG_subrange_type;
316 bool DIDescriptor::isEnumerator() const {
317 return DbgNode && getTag() == dwarf::DW_TAG_enumerator;
320 bool DIDescriptor::isObjCProperty() const {
321 return DbgNode && getTag() == dwarf::DW_TAG_APPLE_property;
324 bool DIDescriptor::isImportedEntity() const {
325 return DbgNode && (getTag() == dwarf::DW_TAG_imported_module ||
326 getTag() == dwarf::DW_TAG_imported_declaration);
329 bool DIDescriptor::isExpression() const {
330 return DbgNode && (getTag() == dwarf::DW_TAG_expression);
333 //===----------------------------------------------------------------------===//
334 // Simple Descriptor Constructors and other Methods
335 //===----------------------------------------------------------------------===//
337 void DIDescriptor::replaceAllUsesWith(LLVMContext &VMContext, DIDescriptor D) {
339 assert(DbgNode && "Trying to replace an unverified type!");
341 // Since we use a TrackingVH for the node, its easy for clients to manufacture
342 // legitimate situations where they want to replaceAllUsesWith() on something
343 // which, due to uniquing, has merged with the source. We shield clients from
344 // this detail by allowing a value to be replaced with replaceAllUsesWith()
346 const MDNode *DN = D;
348 SmallVector<Metadata *, 10> Ops(DbgNode->getNumOperands());
349 for (size_t i = 0; i != Ops.size(); ++i)
350 Ops[i] = DbgNode->getOperand(i);
351 DN = MDNode::get(VMContext, Ops);
354 assert(DbgNode->isTemporary() && "Expected temporary node");
355 auto *Node = const_cast<MDNode *>(DbgNode);
356 Node->replaceAllUsesWith(const_cast<MDNode *>(DN));
357 MDNode::deleteTemporary(Node);
361 void DIDescriptor::replaceAllUsesWith(MDNode *D) {
362 assert(DbgNode && "Trying to replace an unverified type!");
363 assert(DbgNode != D && "This replacement should always happen");
364 assert(DbgNode->isTemporary() && "Expected temporary node");
365 auto *Node = const_cast<MDNode *>(DbgNode);
366 Node->replaceAllUsesWith(D);
367 MDNode::deleteTemporary(Node);
370 bool DICompileUnit::Verify() const {
371 if (!isCompileUnit())
374 // Don't bother verifying the compilation directory or producer string
375 // as those could be empty.
376 if (getFilename().empty())
379 return DbgNode->getNumOperands() == 7 && getNumHeaderFields() == 8;
382 bool DIObjCProperty::Verify() const {
383 if (!isObjCProperty())
386 // Don't worry about the rest of the strings for now.
387 return DbgNode->getNumOperands() == 3 && getNumHeaderFields() == 6;
390 /// \brief Check if a field at position Elt of a MDNode is a MDNode.
392 /// We currently allow an empty string and an integer.
393 /// But we don't allow a non-empty string in a MDNode field.
394 static bool fieldIsMDNode(const MDNode *DbgNode, unsigned Elt) {
395 // FIXME: This function should return true, if the field is null or the field
396 // is indeed a MDNode: return !Fld || isa<MDNode>(Fld).
397 Metadata *Fld = getField(DbgNode, Elt);
398 if (Fld && isa<MDString>(Fld) && !cast<MDString>(Fld)->getString().empty())
403 /// \brief Check if a field at position Elt of a MDNode is a MDString.
404 static bool fieldIsMDString(const MDNode *DbgNode, unsigned Elt) {
405 Metadata *Fld = getField(DbgNode, Elt);
406 return !Fld || isa<MDString>(Fld);
409 /// \brief Check if a value can be a reference to a type.
410 static bool isTypeRef(const Metadata *MD) {
413 if (auto *S = dyn_cast<MDString>(MD))
414 return !S->getString().empty();
415 if (auto *N = dyn_cast<MDNode>(MD))
416 return DIType(N).isType();
420 /// \brief Check if referenced field might be a type.
421 static bool fieldIsTypeRef(const MDNode *DbgNode, unsigned Elt) {
422 return isTypeRef(dyn_cast_or_null<Metadata>(getField(DbgNode, Elt)));
425 /// \brief Check if a value can be a ScopeRef.
426 static bool isScopeRef(const Metadata *MD) {
429 if (auto *S = dyn_cast<MDString>(MD))
430 return !S->getString().empty();
431 return isa<MDNode>(MD);
434 /// \brief Check if a field at position Elt of a MDNode can be a ScopeRef.
435 static bool fieldIsScopeRef(const MDNode *DbgNode, unsigned Elt) {
436 return isScopeRef(dyn_cast_or_null<Metadata>(getField(DbgNode, Elt)));
439 bool DIType::Verify() const {
442 // Make sure Context @ field 2 is MDNode.
443 if (!fieldIsScopeRef(DbgNode, 2))
446 // FIXME: Sink this into the various subclass verifies.
447 uint16_t Tag = getTag();
448 if (!isBasicType() && Tag != dwarf::DW_TAG_const_type &&
449 Tag != dwarf::DW_TAG_volatile_type && Tag != dwarf::DW_TAG_pointer_type &&
450 Tag != dwarf::DW_TAG_ptr_to_member_type &&
451 Tag != dwarf::DW_TAG_reference_type &&
452 Tag != dwarf::DW_TAG_rvalue_reference_type &&
453 Tag != dwarf::DW_TAG_restrict_type && Tag != dwarf::DW_TAG_array_type &&
454 Tag != dwarf::DW_TAG_enumeration_type &&
455 Tag != dwarf::DW_TAG_subroutine_type &&
456 Tag != dwarf::DW_TAG_inheritance && Tag != dwarf::DW_TAG_friend &&
457 getFilename().empty())
460 // DIType is abstract, it should be a BasicType, a DerivedType or
463 return DIBasicType(DbgNode).Verify();
464 else if (isCompositeType())
465 return DICompositeType(DbgNode).Verify();
466 else if (isDerivedType())
467 return DIDerivedType(DbgNode).Verify();
472 bool DIBasicType::Verify() const {
473 return isBasicType() && DbgNode->getNumOperands() == 3 &&
474 getNumHeaderFields() == 8;
477 bool DIDerivedType::Verify() const {
478 // Make sure DerivedFrom @ field 3 is TypeRef.
479 if (!fieldIsTypeRef(DbgNode, 3))
481 if (getTag() == dwarf::DW_TAG_ptr_to_member_type)
482 // Make sure ClassType @ field 4 is a TypeRef.
483 if (!fieldIsTypeRef(DbgNode, 4))
486 return isDerivedType() && DbgNode->getNumOperands() >= 4 &&
487 DbgNode->getNumOperands() <= 8 && getNumHeaderFields() >= 7 &&
488 getNumHeaderFields() <= 8;
491 bool DICompositeType::Verify() const {
492 if (!isCompositeType())
495 // Make sure DerivedFrom @ field 3 and ContainingType @ field 5 are TypeRef.
496 if (!fieldIsTypeRef(DbgNode, 3))
498 if (!fieldIsTypeRef(DbgNode, 5))
501 // Make sure the type identifier at field 7 is MDString, it can be null.
502 if (!fieldIsMDString(DbgNode, 7))
505 // A subroutine type can't be both & and &&.
506 if (isLValueReference() && isRValueReference())
509 return DbgNode->getNumOperands() == 8 && getNumHeaderFields() == 8;
512 bool DISubprogram::Verify() const {
516 // Make sure context @ field 2 is a ScopeRef and type @ field 3 is a MDNode.
517 if (!fieldIsScopeRef(DbgNode, 2))
519 if (!fieldIsMDNode(DbgNode, 3))
521 // Containing type @ field 4.
522 if (!fieldIsTypeRef(DbgNode, 4))
525 // A subprogram can't be both & and &&.
526 if (isLValueReference() && isRValueReference())
529 // If a DISubprogram has an llvm::Function*, then scope chains from all
530 // instructions within the function should lead to this DISubprogram.
531 if (auto *F = getFunction()) {
532 for (auto &BB : *F) {
534 DebugLoc DL = I.getDebugLoc();
538 MDNode *Scope = nullptr;
539 MDNode *IA = nullptr;
540 // walk the inlined-at scopes
541 while ((IA = DL.getInlinedAt()))
542 DL = DebugLoc::getFromDILocation(IA);
543 DL.getScopeAndInlinedAt(Scope, IA);
547 while (!DIDescriptor(Scope).isSubprogram()) {
548 DILexicalBlockFile D(Scope);
549 Scope = D.isLexicalBlockFile()
551 : DebugLoc::getFromDILexicalBlock(Scope).getScope();
555 if (!DISubprogram(Scope).describes(F))
560 return DbgNode->getNumOperands() == 9 && getNumHeaderFields() == 12;
563 bool DIGlobalVariable::Verify() const {
564 if (!isGlobalVariable())
567 if (getDisplayName().empty())
569 // Make sure context @ field 1 is an MDNode.
570 if (!fieldIsMDNode(DbgNode, 1))
572 // Make sure that type @ field 3 is a DITypeRef.
573 if (!fieldIsTypeRef(DbgNode, 3))
575 // Make sure StaticDataMemberDeclaration @ field 5 is MDNode.
576 if (!fieldIsMDNode(DbgNode, 5))
579 return DbgNode->getNumOperands() == 6 && getNumHeaderFields() == 7;
582 bool DIVariable::Verify() const {
586 // Make sure context @ field 1 is an MDNode.
587 if (!fieldIsMDNode(DbgNode, 1))
589 // Make sure that type @ field 3 is a DITypeRef.
590 if (!fieldIsTypeRef(DbgNode, 3))
593 // Check the number of header fields, which is common between complex and
595 if (getNumHeaderFields() != 4)
598 // Variable without an inline location.
599 if (DbgNode->getNumOperands() == 4)
602 // Variable with an inline location.
603 return getInlinedAt() != nullptr && DbgNode->getNumOperands() == 5;
606 bool DIExpression::Verify() const {
607 // Empty DIExpressions may be represented as a nullptr.
611 if (!(isExpression() && DbgNode->getNumOperands() == 1))
614 for (auto Op : *this)
617 // Must be the last element of the expression.
618 return std::distance(Op.getBase(), DIHeaderFieldIterator()) == 3;
620 if (std::distance(Op.getBase(), DIHeaderFieldIterator()) < 2)
626 // Other operators are not yet supported by the backend.
632 bool DILocation::Verify() const {
633 return DbgNode && isa<MDLocation>(DbgNode);
636 bool DINameSpace::Verify() const {
639 return DbgNode->getNumOperands() == 3 && getNumHeaderFields() == 3;
642 MDNode *DIFile::getFileNode() const { return getNodeField(DbgNode, 1); }
644 bool DIFile::Verify() const {
645 return isFile() && DbgNode->getNumOperands() == 2;
648 bool DIEnumerator::Verify() const {
649 return isEnumerator() && DbgNode->getNumOperands() == 1 &&
650 getNumHeaderFields() == 3;
653 bool DISubrange::Verify() const {
654 return isSubrange() && DbgNode->getNumOperands() == 1 &&
655 getNumHeaderFields() == 3;
658 bool DILexicalBlock::Verify() const {
659 return isLexicalBlock() && DbgNode->getNumOperands() == 3 &&
660 getNumHeaderFields() == 4;
663 bool DILexicalBlockFile::Verify() const {
664 return isLexicalBlockFile() && DbgNode->getNumOperands() == 3 &&
665 getNumHeaderFields() == 2;
668 bool DITemplateTypeParameter::Verify() const {
669 return isTemplateTypeParameter() && DbgNode->getNumOperands() == 4 &&
670 getNumHeaderFields() == 4;
673 bool DITemplateValueParameter::Verify() const {
674 return isTemplateValueParameter() && DbgNode->getNumOperands() == 5 &&
675 getNumHeaderFields() == 4;
678 bool DIImportedEntity::Verify() const {
679 return isImportedEntity() && DbgNode->getNumOperands() == 3 &&
680 getNumHeaderFields() == 3;
683 MDNode *DIDerivedType::getObjCProperty() const {
684 return getNodeField(DbgNode, 4);
687 MDString *DICompositeType::getIdentifier() const {
688 return cast_or_null<MDString>(getField(DbgNode, 7));
692 static void VerifySubsetOf(const MDNode *LHS, const MDNode *RHS) {
693 for (unsigned i = 0; i != LHS->getNumOperands(); ++i) {
694 // Skip the 'empty' list (that's a single i32 0, rather than truly empty).
695 if (i == 0 && mdconst::hasa<ConstantInt>(LHS->getOperand(i)))
697 const MDNode *E = cast<MDNode>(LHS->getOperand(i));
699 for (unsigned j = 0; !found && j != RHS->getNumOperands(); ++j)
700 found = (E == cast<MDNode>(RHS->getOperand(j)));
701 assert(found && "Losing a member during member list replacement");
706 void DICompositeType::setArraysHelper(MDNode *Elements, MDNode *TParams) {
707 TrackingMDNodeRef N(*this);
710 // Check that the new list of members contains all the old members as well.
711 if (const MDNode *El = cast_or_null<MDNode>(N->getOperand(4)))
712 VerifySubsetOf(El, Elements);
714 N->replaceOperandWith(4, Elements);
717 N->replaceOperandWith(6, TParams);
721 DIScopeRef DIScope::getRef() const {
722 if (!isCompositeType())
723 return DIScopeRef(*this);
724 DICompositeType DTy(DbgNode);
725 if (!DTy.getIdentifier())
726 return DIScopeRef(*this);
727 return DIScopeRef(DTy.getIdentifier());
730 void DICompositeType::setContainingType(DICompositeType ContainingType) {
731 TrackingMDNodeRef N(*this);
732 N->replaceOperandWith(5, ContainingType.getRef());
736 bool DIVariable::isInlinedFnArgument(const Function *CurFn) {
737 assert(CurFn && "Invalid function");
738 if (!getContext().isSubprogram())
740 // This variable is not inlined function argument if its scope
741 // does not describe current function.
742 return !DISubprogram(getContext()).describes(CurFn);
745 bool DISubprogram::describes(const Function *F) {
746 assert(F && "Invalid function");
747 if (F == getFunction())
749 StringRef Name = getLinkageName();
752 if (F->getName() == Name)
757 MDNode *DISubprogram::getVariablesNodes() const {
758 return getNodeField(DbgNode, 8);
761 DIArray DISubprogram::getVariables() const {
762 return DIArray(getNodeField(DbgNode, 8));
765 Metadata *DITemplateValueParameter::getValue() const {
766 return DbgNode->getOperand(3);
769 DIScopeRef DIScope::getContext() const {
772 return DIType(DbgNode).getContext();
775 return DIScopeRef(DISubprogram(DbgNode).getContext());
777 if (isLexicalBlock())
778 return DIScopeRef(DILexicalBlock(DbgNode).getContext());
780 if (isLexicalBlockFile())
781 return DIScopeRef(DILexicalBlockFile(DbgNode).getContext());
784 return DIScopeRef(DINameSpace(DbgNode).getContext());
786 assert((isFile() || isCompileUnit()) && "Unhandled type of scope.");
787 return DIScopeRef(nullptr);
790 StringRef DIScope::getName() const {
792 return DIType(DbgNode).getName();
794 return DISubprogram(DbgNode).getName();
796 return DINameSpace(DbgNode).getName();
797 assert((isLexicalBlock() || isLexicalBlockFile() || isFile() ||
799 "Unhandled type of scope.");
803 StringRef DIScope::getFilename() const {
806 return ::getStringField(getNodeField(DbgNode, 1), 0);
809 StringRef DIScope::getDirectory() const {
812 return ::getStringField(getNodeField(DbgNode, 1), 1);
815 DIArray DICompileUnit::getEnumTypes() const {
816 if (!DbgNode || DbgNode->getNumOperands() < 7)
819 return DIArray(getNodeField(DbgNode, 2));
822 DIArray DICompileUnit::getRetainedTypes() const {
823 if (!DbgNode || DbgNode->getNumOperands() < 7)
826 return DIArray(getNodeField(DbgNode, 3));
829 DIArray DICompileUnit::getSubprograms() const {
830 if (!DbgNode || DbgNode->getNumOperands() < 7)
833 return DIArray(getNodeField(DbgNode, 4));
836 DIArray DICompileUnit::getGlobalVariables() const {
837 if (!DbgNode || DbgNode->getNumOperands() < 7)
840 return DIArray(getNodeField(DbgNode, 5));
843 DIArray DICompileUnit::getImportedEntities() const {
844 if (!DbgNode || DbgNode->getNumOperands() < 7)
847 return DIArray(getNodeField(DbgNode, 6));
850 void DICompileUnit::replaceSubprograms(DIArray Subprograms) {
851 assert(Verify() && "Expected compile unit");
852 if (Subprograms == getSubprograms())
855 const_cast<MDNode *>(DbgNode)->replaceOperandWith(4, Subprograms);
858 void DICompileUnit::replaceGlobalVariables(DIArray GlobalVariables) {
859 assert(Verify() && "Expected compile unit");
860 if (GlobalVariables == getGlobalVariables())
863 const_cast<MDNode *>(DbgNode)->replaceOperandWith(5, GlobalVariables);
866 DILocation DILocation::copyWithNewScope(LLVMContext &Ctx,
867 DILexicalBlockFile NewScope) {
869 assert(NewScope && "Expected valid scope");
871 const auto *Old = cast<MDLocation>(DbgNode);
872 return DILocation(MDLocation::get(Ctx, Old->getLine(), Old->getColumn(),
873 NewScope, Old->getInlinedAt()));
876 unsigned DILocation::computeNewDiscriminator(LLVMContext &Ctx) {
877 std::pair<const char *, unsigned> Key(getFilename().data(), getLineNumber());
878 return ++Ctx.pImpl->DiscriminatorTable[Key];
881 DIVariable llvm::createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
882 LLVMContext &VMContext) {
883 assert(DIVariable(DV).Verify() && "Expected a DIVariable");
885 return cleanseInlinedVariable(DV, VMContext);
887 // Insert inlined scope.
888 SmallVector<Metadata *, 8> Elts;
889 for (unsigned I = 0, E = DIVariableInlinedAtIndex; I != E; ++I)
890 Elts.push_back(DV->getOperand(I));
891 Elts.push_back(InlinedScope);
893 DIVariable Inlined(MDNode::get(VMContext, Elts));
894 assert(Inlined.Verify() && "Expected to create a DIVariable");
898 DIVariable llvm::cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext) {
899 assert(DIVariable(DV).Verify() && "Expected a DIVariable");
900 if (!DIVariable(DV).getInlinedAt())
901 return DIVariable(DV);
903 // Remove inlined scope.
904 SmallVector<Metadata *, 8> Elts;
905 for (unsigned I = 0, E = DIVariableInlinedAtIndex; I != E; ++I)
906 Elts.push_back(DV->getOperand(I));
908 DIVariable Cleansed(MDNode::get(VMContext, Elts));
909 assert(Cleansed.Verify() && "Expected to create a DIVariable");
913 DISubprogram llvm::getDISubprogram(const MDNode *Scope) {
914 DIDescriptor D(Scope);
915 if (D.isSubprogram())
916 return DISubprogram(Scope);
918 if (D.isLexicalBlockFile())
919 return getDISubprogram(DILexicalBlockFile(Scope).getContext());
921 if (D.isLexicalBlock())
922 return getDISubprogram(DILexicalBlock(Scope).getContext());
924 return DISubprogram();
927 DISubprogram llvm::getDISubprogram(const Function *F) {
928 // We look for the first instr that has a debug annotation leading back to F.
929 for (auto &BB : *F) {
930 auto Inst = std::find_if(BB.begin(), BB.end(), [](const Instruction &Inst) {
931 return !Inst.getDebugLoc().isUnknown();
933 if (Inst == BB.end())
935 DebugLoc DLoc = Inst->getDebugLoc();
936 const MDNode *Scope = DLoc.getScopeNode();
937 DISubprogram Subprogram = getDISubprogram(Scope);
938 return Subprogram.describes(F) ? Subprogram : DISubprogram();
941 return DISubprogram();
944 DICompositeType llvm::getDICompositeType(DIType T) {
945 if (T.isCompositeType())
946 return DICompositeType(T);
948 if (T.isDerivedType()) {
949 // This function is currently used by dragonegg and dragonegg does
950 // not generate identifier for types, so using an empty map to resolve
951 // DerivedFrom should be fine.
952 DITypeIdentifierMap EmptyMap;
953 return getDICompositeType(
954 DIDerivedType(T).getTypeDerivedFrom().resolve(EmptyMap));
957 return DICompositeType();
961 llvm::generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes) {
962 DITypeIdentifierMap Map;
963 for (unsigned CUi = 0, CUe = CU_Nodes->getNumOperands(); CUi != CUe; ++CUi) {
964 DICompileUnit CU(CU_Nodes->getOperand(CUi));
965 DIArray Retain = CU.getRetainedTypes();
966 for (unsigned Ti = 0, Te = Retain.getNumElements(); Ti != Te; ++Ti) {
967 if (!Retain.getElement(Ti).isCompositeType())
969 DICompositeType Ty(Retain.getElement(Ti));
970 if (MDString *TypeId = Ty.getIdentifier()) {
971 // Definition has priority over declaration.
972 // Try to insert (TypeId, Ty) to Map.
973 std::pair<DITypeIdentifierMap::iterator, bool> P =
974 Map.insert(std::make_pair(TypeId, Ty));
975 // If TypeId already exists in Map and this is a definition, replace
976 // whatever we had (declaration or definition) with the definition.
977 if (!P.second && !Ty.isForwardDecl())
978 P.first->second = Ty;
985 //===----------------------------------------------------------------------===//
986 // DebugInfoFinder implementations.
987 //===----------------------------------------------------------------------===//
989 void DebugInfoFinder::reset() {
996 TypeIdentifierMap.clear();
997 TypeMapInitialized = false;
1000 void DebugInfoFinder::InitializeTypeMap(const Module &M) {
1001 if (!TypeMapInitialized)
1002 if (NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu")) {
1003 TypeIdentifierMap = generateDITypeIdentifierMap(CU_Nodes);
1004 TypeMapInitialized = true;
1008 void DebugInfoFinder::processModule(const Module &M) {
1009 InitializeTypeMap(M);
1010 if (NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu")) {
1011 for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
1012 DICompileUnit CU(CU_Nodes->getOperand(i));
1014 DIArray GVs = CU.getGlobalVariables();
1015 for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i) {
1016 DIGlobalVariable DIG(GVs.getElement(i));
1017 if (addGlobalVariable(DIG)) {
1018 processScope(DIG.getContext());
1019 processType(DIG.getType().resolve(TypeIdentifierMap));
1022 DIArray SPs = CU.getSubprograms();
1023 for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i)
1024 processSubprogram(DISubprogram(SPs.getElement(i)));
1025 DIArray EnumTypes = CU.getEnumTypes();
1026 for (unsigned i = 0, e = EnumTypes.getNumElements(); i != e; ++i)
1027 processType(DIType(EnumTypes.getElement(i)));
1028 DIArray RetainedTypes = CU.getRetainedTypes();
1029 for (unsigned i = 0, e = RetainedTypes.getNumElements(); i != e; ++i)
1030 processType(DIType(RetainedTypes.getElement(i)));
1031 DIArray Imports = CU.getImportedEntities();
1032 for (unsigned i = 0, e = Imports.getNumElements(); i != e; ++i) {
1033 DIImportedEntity Import = DIImportedEntity(Imports.getElement(i));
1034 DIDescriptor Entity = Import.getEntity().resolve(TypeIdentifierMap);
1035 if (Entity.isType())
1036 processType(DIType(Entity));
1037 else if (Entity.isSubprogram())
1038 processSubprogram(DISubprogram(Entity));
1039 else if (Entity.isNameSpace())
1040 processScope(DINameSpace(Entity).getContext());
1046 void DebugInfoFinder::processLocation(const Module &M, DILocation Loc) {
1049 InitializeTypeMap(M);
1050 processScope(Loc.getScope());
1051 processLocation(M, Loc.getOrigLocation());
1054 void DebugInfoFinder::processType(DIType DT) {
1057 processScope(DT.getContext().resolve(TypeIdentifierMap));
1058 if (DT.isCompositeType()) {
1059 DICompositeType DCT(DT);
1060 processType(DCT.getTypeDerivedFrom().resolve(TypeIdentifierMap));
1061 if (DT.isSubroutineType()) {
1062 DITypeArray DTA = DISubroutineType(DT).getTypeArray();
1063 for (unsigned i = 0, e = DTA.getNumElements(); i != e; ++i)
1064 processType(DTA.getElement(i).resolve(TypeIdentifierMap));
1067 DIArray DA = DCT.getElements();
1068 for (unsigned i = 0, e = DA.getNumElements(); i != e; ++i) {
1069 DIDescriptor D = DA.getElement(i);
1071 processType(DIType(D));
1072 else if (D.isSubprogram())
1073 processSubprogram(DISubprogram(D));
1075 } else if (DT.isDerivedType()) {
1076 DIDerivedType DDT(DT);
1077 processType(DDT.getTypeDerivedFrom().resolve(TypeIdentifierMap));
1081 void DebugInfoFinder::processScope(DIScope Scope) {
1082 if (Scope.isType()) {
1087 if (Scope.isCompileUnit()) {
1088 addCompileUnit(DICompileUnit(Scope));
1091 if (Scope.isSubprogram()) {
1092 processSubprogram(DISubprogram(Scope));
1095 if (!addScope(Scope))
1097 if (Scope.isLexicalBlock()) {
1098 DILexicalBlock LB(Scope);
1099 processScope(LB.getContext());
1100 } else if (Scope.isLexicalBlockFile()) {
1101 DILexicalBlockFile LBF = DILexicalBlockFile(Scope);
1102 processScope(LBF.getScope());
1103 } else if (Scope.isNameSpace()) {
1104 DINameSpace NS(Scope);
1105 processScope(NS.getContext());
1109 void DebugInfoFinder::processSubprogram(DISubprogram SP) {
1110 if (!addSubprogram(SP))
1112 processScope(SP.getContext().resolve(TypeIdentifierMap));
1113 processType(SP.getType());
1114 DIArray TParams = SP.getTemplateParams();
1115 for (unsigned I = 0, E = TParams.getNumElements(); I != E; ++I) {
1116 DIDescriptor Element = TParams.getElement(I);
1117 if (Element.isTemplateTypeParameter()) {
1118 DITemplateTypeParameter TType(Element);
1119 processScope(TType.getContext().resolve(TypeIdentifierMap));
1120 processType(TType.getType().resolve(TypeIdentifierMap));
1121 } else if (Element.isTemplateValueParameter()) {
1122 DITemplateValueParameter TVal(Element);
1123 processScope(TVal.getContext().resolve(TypeIdentifierMap));
1124 processType(TVal.getType().resolve(TypeIdentifierMap));
1129 void DebugInfoFinder::processDeclare(const Module &M,
1130 const DbgDeclareInst *DDI) {
1131 MDNode *N = dyn_cast<MDNode>(DDI->getVariable());
1134 InitializeTypeMap(M);
1137 if (!DV.isVariable())
1140 if (!NodesSeen.insert(DV).second)
1142 processScope(DIVariable(N).getContext());
1143 processType(DIVariable(N).getType().resolve(TypeIdentifierMap));
1146 void DebugInfoFinder::processValue(const Module &M, const DbgValueInst *DVI) {
1147 MDNode *N = dyn_cast<MDNode>(DVI->getVariable());
1150 InitializeTypeMap(M);
1153 if (!DV.isVariable())
1156 if (!NodesSeen.insert(DV).second)
1158 processScope(DIVariable(N).getContext());
1159 processType(DIVariable(N).getType().resolve(TypeIdentifierMap));
1162 bool DebugInfoFinder::addType(DIType DT) {
1166 if (!NodesSeen.insert(DT).second)
1173 bool DebugInfoFinder::addCompileUnit(DICompileUnit CU) {
1176 if (!NodesSeen.insert(CU).second)
1183 bool DebugInfoFinder::addGlobalVariable(DIGlobalVariable DIG) {
1187 if (!NodesSeen.insert(DIG).second)
1194 bool DebugInfoFinder::addSubprogram(DISubprogram SP) {
1198 if (!NodesSeen.insert(SP).second)
1205 bool DebugInfoFinder::addScope(DIScope Scope) {
1208 // FIXME: Ocaml binding generates a scope with no content, we treat it
1210 if (Scope->getNumOperands() == 0)
1212 if (!NodesSeen.insert(Scope).second)
1214 Scopes.push_back(Scope);
1218 //===----------------------------------------------------------------------===//
1219 // DIDescriptor: dump routines for all descriptors.
1220 //===----------------------------------------------------------------------===//
1222 void DIDescriptor::dump() const {
1227 void DIDescriptor::print(raw_ostream &OS) const {
1231 if (const char *Tag = dwarf::TagString(getTag()))
1232 OS << "[ " << Tag << " ]";
1234 if (this->isSubrange()) {
1235 DISubrange(DbgNode).printInternal(OS);
1236 } else if (this->isCompileUnit()) {
1237 DICompileUnit(DbgNode).printInternal(OS);
1238 } else if (this->isFile()) {
1239 DIFile(DbgNode).printInternal(OS);
1240 } else if (this->isEnumerator()) {
1241 DIEnumerator(DbgNode).printInternal(OS);
1242 } else if (this->isBasicType()) {
1243 DIType(DbgNode).printInternal(OS);
1244 } else if (this->isDerivedType()) {
1245 DIDerivedType(DbgNode).printInternal(OS);
1246 } else if (this->isCompositeType()) {
1247 DICompositeType(DbgNode).printInternal(OS);
1248 } else if (this->isSubprogram()) {
1249 DISubprogram(DbgNode).printInternal(OS);
1250 } else if (this->isGlobalVariable()) {
1251 DIGlobalVariable(DbgNode).printInternal(OS);
1252 } else if (this->isVariable()) {
1253 DIVariable(DbgNode).printInternal(OS);
1254 } else if (this->isObjCProperty()) {
1255 DIObjCProperty(DbgNode).printInternal(OS);
1256 } else if (this->isNameSpace()) {
1257 DINameSpace(DbgNode).printInternal(OS);
1258 } else if (this->isScope()) {
1259 DIScope(DbgNode).printInternal(OS);
1260 } else if (this->isExpression()) {
1261 DIExpression(DbgNode).printInternal(OS);
1265 void DISubrange::printInternal(raw_ostream &OS) const {
1266 int64_t Count = getCount();
1268 OS << " [" << getLo() << ", " << Count - 1 << ']';
1270 OS << " [unbounded]";
1273 void DIScope::printInternal(raw_ostream &OS) const {
1274 OS << " [" << getDirectory() << "/" << getFilename() << ']';
1277 void DICompileUnit::printInternal(raw_ostream &OS) const {
1278 DIScope::printInternal(OS);
1280 unsigned Lang = getLanguage();
1281 if (const char *LangStr = dwarf::LanguageString(Lang))
1284 (OS << "lang 0x").write_hex(Lang);
1288 void DIEnumerator::printInternal(raw_ostream &OS) const {
1289 OS << " [" << getName() << " :: " << getEnumValue() << ']';
1292 void DIType::printInternal(raw_ostream &OS) const {
1296 StringRef Res = getName();
1298 OS << " [" << Res << "]";
1300 // TODO: Print context?
1302 OS << " [line " << getLineNumber() << ", size " << getSizeInBits()
1303 << ", align " << getAlignInBits() << ", offset " << getOffsetInBits();
1305 if (const char *Enc =
1306 dwarf::AttributeEncodingString(DIBasicType(DbgNode).getEncoding()))
1307 OS << ", enc " << Enc;
1312 else if (isProtected())
1313 OS << " [protected]";
1314 else if (isPublic())
1318 OS << " [artificial]";
1320 if (isForwardDecl())
1322 else if (getTag() == dwarf::DW_TAG_structure_type ||
1323 getTag() == dwarf::DW_TAG_union_type ||
1324 getTag() == dwarf::DW_TAG_enumeration_type ||
1325 getTag() == dwarf::DW_TAG_class_type)
1329 if (isStaticMember())
1332 if (isLValueReference())
1333 OS << " [reference]";
1335 if (isRValueReference())
1336 OS << " [rvalue reference]";
1339 void DIDerivedType::printInternal(raw_ostream &OS) const {
1340 DIType::printInternal(OS);
1341 OS << " [from " << getTypeDerivedFrom().getName() << ']';
1344 void DICompositeType::printInternal(raw_ostream &OS) const {
1345 DIType::printInternal(OS);
1346 DIArray A = getElements();
1347 OS << " [" << A.getNumElements() << " elements]";
1350 void DINameSpace::printInternal(raw_ostream &OS) const {
1351 StringRef Name = getName();
1353 OS << " [" << Name << ']';
1355 OS << " [line " << getLineNumber() << ']';
1358 void DISubprogram::printInternal(raw_ostream &OS) const {
1359 // TODO : Print context
1360 OS << " [line " << getLineNumber() << ']';
1362 if (isLocalToUnit())
1368 if (getScopeLineNumber() != getLineNumber())
1369 OS << " [scope " << getScopeLineNumber() << "]";
1373 else if (isProtected())
1374 OS << " [protected]";
1375 else if (isPublic())
1378 if (isLValueReference())
1379 OS << " [reference]";
1381 if (isRValueReference())
1382 OS << " [rvalue reference]";
1384 StringRef Res = getName();
1386 OS << " [" << Res << ']';
1389 void DIGlobalVariable::printInternal(raw_ostream &OS) const {
1390 StringRef Res = getName();
1392 OS << " [" << Res << ']';
1394 OS << " [line " << getLineNumber() << ']';
1396 // TODO : Print context
1398 if (isLocalToUnit())
1405 void DIVariable::printInternal(raw_ostream &OS) const {
1406 StringRef Res = getName();
1408 OS << " [" << Res << ']';
1410 OS << " [line " << getLineNumber() << ']';
1413 void DIExpression::printInternal(raw_ostream &OS) const {
1414 for (auto Op : *this) {
1415 OS << " [" << OperationEncodingString(Op);
1418 OS << " " << Op.getArg(1);
1422 OS << " offset=" << Op.getArg(1) << ", size=" << Op.getArg(2);
1429 llvm_unreachable("unhandled operation");
1435 void DIObjCProperty::printInternal(raw_ostream &OS) const {
1436 StringRef Name = getObjCPropertyName();
1438 OS << " [" << Name << ']';
1440 OS << " [line " << getLineNumber() << ", properties " << getUnsignedField(6)
1444 static void printDebugLoc(DebugLoc DL, raw_ostream &CommentOS,
1445 const LLVMContext &Ctx) {
1446 if (!DL.isUnknown()) { // Print source line info.
1447 DIScope Scope(DL.getScope(Ctx));
1448 assert(Scope.isScope() && "Scope of a DebugLoc should be a DIScope.");
1449 // Omit the directory, because it's likely to be long and uninteresting.
1450 CommentOS << Scope.getFilename();
1451 CommentOS << ':' << DL.getLine();
1452 if (DL.getCol() != 0)
1453 CommentOS << ':' << DL.getCol();
1454 DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(DL.getInlinedAt(Ctx));
1455 if (!InlinedAtDL.isUnknown()) {
1456 CommentOS << " @[ ";
1457 printDebugLoc(InlinedAtDL, CommentOS, Ctx);
1463 void DIVariable::printExtendedName(raw_ostream &OS) const {
1464 const LLVMContext &Ctx = DbgNode->getContext();
1465 StringRef Res = getName();
1467 OS << Res << "," << getLineNumber();
1468 if (MDNode *InlinedAt = getInlinedAt()) {
1469 DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(InlinedAt);
1470 if (!InlinedAtDL.isUnknown()) {
1472 printDebugLoc(InlinedAtDL, OS, Ctx);
1478 template <> DIRef<DIScope>::DIRef(const Metadata *V) : Val(V) {
1479 assert(isScopeRef(V) && "DIScopeRef should be a MDString or MDNode");
1481 template <> DIRef<DIType>::DIRef(const Metadata *V) : Val(V) {
1482 assert(isTypeRef(V) && "DITypeRef should be a MDString or MDNode");
1486 DIScopeRef DIDescriptor::getFieldAs<DIScopeRef>(unsigned Elt) const {
1487 return DIScopeRef(cast_or_null<Metadata>(getField(DbgNode, Elt)));
1489 template <> DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const {
1490 return DITypeRef(cast_or_null<Metadata>(getField(DbgNode, Elt)));
1493 bool llvm::StripDebugInfo(Module &M) {
1494 bool Changed = false;
1496 // Remove all of the calls to the debugger intrinsics, and remove them from
1498 if (Function *Declare = M.getFunction("llvm.dbg.declare")) {
1499 while (!Declare->use_empty()) {
1500 CallInst *CI = cast<CallInst>(Declare->user_back());
1501 CI->eraseFromParent();
1503 Declare->eraseFromParent();
1507 if (Function *DbgVal = M.getFunction("llvm.dbg.value")) {
1508 while (!DbgVal->use_empty()) {
1509 CallInst *CI = cast<CallInst>(DbgVal->user_back());
1510 CI->eraseFromParent();
1512 DbgVal->eraseFromParent();
1516 for (Module::named_metadata_iterator NMI = M.named_metadata_begin(),
1517 NME = M.named_metadata_end(); NMI != NME;) {
1518 NamedMDNode *NMD = NMI;
1520 if (NMD->getName().startswith("llvm.dbg.")) {
1521 NMD->eraseFromParent();
1526 for (Module::iterator MI = M.begin(), ME = M.end(); MI != ME; ++MI)
1527 for (Function::iterator FI = MI->begin(), FE = MI->end(); FI != FE;
1529 for (BasicBlock::iterator BI = FI->begin(), BE = FI->end(); BI != BE;
1531 if (!BI->getDebugLoc().isUnknown()) {
1533 BI->setDebugLoc(DebugLoc());
1540 unsigned llvm::getDebugMetadataVersionFromModule(const Module &M) {
1541 if (auto *Val = mdconst::extract_or_null<ConstantInt>(
1542 M.getModuleFlag("Debug Info Version")))
1543 return Val->getZExtValue();
1547 llvm::DenseMap<const llvm::Function *, llvm::DISubprogram>
1548 llvm::makeSubprogramMap(const Module &M) {
1549 DenseMap<const Function *, DISubprogram> R;
1551 NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu");
1555 for (MDNode *N : CU_Nodes->operands()) {
1556 DICompileUnit CUNode(N);
1557 DIArray SPs = CUNode.getSubprograms();
1558 for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
1559 DISubprogram SP(SPs.getElement(i));
1560 if (Function *F = SP.getFunction())
1561 R.insert(std::make_pair(F, SP));