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/DerivedTypes.h"
23 #include "llvm/IR/Instructions.h"
24 #include "llvm/IR/IntrinsicInst.h"
25 #include "llvm/IR/Intrinsics.h"
26 #include "llvm/IR/Module.h"
27 #include "llvm/IR/ValueHandle.h"
28 #include "llvm/Support/Debug.h"
29 #include "llvm/Support/Dwarf.h"
30 #include "llvm/Support/raw_ostream.h"
32 using namespace llvm::dwarf;
34 //===----------------------------------------------------------------------===//
36 //===----------------------------------------------------------------------===//
38 bool DIDescriptor::Verify() const {
40 (DIDerivedType(DbgNode).Verify() ||
41 DICompositeType(DbgNode).Verify() || DIBasicType(DbgNode).Verify() ||
42 DIVariable(DbgNode).Verify() || DISubprogram(DbgNode).Verify() ||
43 DIGlobalVariable(DbgNode).Verify() || DIFile(DbgNode).Verify() ||
44 DICompileUnit(DbgNode).Verify() || DINameSpace(DbgNode).Verify() ||
45 DILexicalBlock(DbgNode).Verify() ||
46 DILexicalBlockFile(DbgNode).Verify() ||
47 DISubrange(DbgNode).Verify() || DIEnumerator(DbgNode).Verify() ||
48 DIObjCProperty(DbgNode).Verify() ||
49 DIUnspecifiedParameter(DbgNode).Verify() ||
50 DITemplateTypeParameter(DbgNode).Verify() ||
51 DITemplateValueParameter(DbgNode).Verify() ||
52 DIImportedEntity(DbgNode).Verify());
55 static Value *getField(const MDNode *DbgNode, unsigned Elt) {
56 if (DbgNode == 0 || 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 {
79 if (Elt < DbgNode->getNumOperands())
81 dyn_cast_or_null<ConstantInt>(DbgNode->getOperand(Elt)))
82 return CI->getZExtValue();
87 int64_t DIDescriptor::getInt64Field(unsigned Elt) const {
91 if (Elt < DbgNode->getNumOperands())
93 dyn_cast_or_null<ConstantInt>(DbgNode->getOperand(Elt)))
94 return CI->getSExtValue();
99 DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const {
100 MDNode *Field = getNodeField(DbgNode, Elt);
101 return DIDescriptor(Field);
104 GlobalVariable *DIDescriptor::getGlobalVariableField(unsigned Elt) const {
108 if (Elt < DbgNode->getNumOperands())
109 return dyn_cast_or_null<GlobalVariable>(DbgNode->getOperand(Elt));
113 Constant *DIDescriptor::getConstantField(unsigned Elt) const {
117 if (Elt < DbgNode->getNumOperands())
118 return dyn_cast_or_null<Constant>(DbgNode->getOperand(Elt));
122 Function *DIDescriptor::getFunctionField(unsigned Elt) const {
126 if (Elt < DbgNode->getNumOperands())
127 return dyn_cast_or_null<Function>(DbgNode->getOperand(Elt));
131 void DIDescriptor::replaceFunctionField(unsigned Elt, Function *F) {
135 if (Elt < DbgNode->getNumOperands()) {
136 MDNode *Node = const_cast<MDNode *>(DbgNode);
137 Node->replaceOperandWith(Elt, F);
141 unsigned DIVariable::getNumAddrElements() const {
142 return DbgNode->getNumOperands() - 8;
145 /// getInlinedAt - If this variable is inlined then return inline location.
146 MDNode *DIVariable::getInlinedAt() const { return getNodeField(DbgNode, 7); }
148 //===----------------------------------------------------------------------===//
150 //===----------------------------------------------------------------------===//
152 /// isBasicType - Return true if the specified tag is legal for
154 bool DIDescriptor::isBasicType() const {
158 case dwarf::DW_TAG_base_type:
159 case dwarf::DW_TAG_unspecified_type:
166 /// isDerivedType - Return true if the specified tag is legal for DIDerivedType.
167 bool DIDescriptor::isDerivedType() const {
171 case dwarf::DW_TAG_typedef:
172 case dwarf::DW_TAG_pointer_type:
173 case dwarf::DW_TAG_ptr_to_member_type:
174 case dwarf::DW_TAG_reference_type:
175 case dwarf::DW_TAG_rvalue_reference_type:
176 case dwarf::DW_TAG_const_type:
177 case dwarf::DW_TAG_volatile_type:
178 case dwarf::DW_TAG_restrict_type:
179 case dwarf::DW_TAG_member:
180 case dwarf::DW_TAG_inheritance:
181 case dwarf::DW_TAG_friend:
184 // CompositeTypes are currently modelled as DerivedTypes.
185 return isCompositeType();
189 /// isCompositeType - Return true if the specified tag is legal for
191 bool DIDescriptor::isCompositeType() const {
195 case dwarf::DW_TAG_array_type:
196 case dwarf::DW_TAG_structure_type:
197 case dwarf::DW_TAG_union_type:
198 case dwarf::DW_TAG_enumeration_type:
199 case dwarf::DW_TAG_subroutine_type:
200 case dwarf::DW_TAG_class_type:
207 /// isVariable - Return true if the specified tag is legal for DIVariable.
208 bool DIDescriptor::isVariable() const {
212 case dwarf::DW_TAG_auto_variable:
213 case dwarf::DW_TAG_arg_variable:
220 /// isType - Return true if the specified tag is legal for DIType.
221 bool DIDescriptor::isType() const {
222 return isBasicType() || isCompositeType() || isDerivedType();
225 /// isSubprogram - Return true if the specified tag is legal for
227 bool DIDescriptor::isSubprogram() const {
228 return DbgNode && getTag() == dwarf::DW_TAG_subprogram;
231 /// isGlobalVariable - Return true if the specified tag is legal for
232 /// DIGlobalVariable.
233 bool DIDescriptor::isGlobalVariable() const {
234 return DbgNode && (getTag() == dwarf::DW_TAG_variable ||
235 getTag() == dwarf::DW_TAG_constant);
238 /// isUnspecifiedParmeter - Return true if the specified tag is
239 /// DW_TAG_unspecified_parameters.
240 bool DIDescriptor::isUnspecifiedParameter() const {
241 return DbgNode && getTag() == dwarf::DW_TAG_unspecified_parameters;
244 /// isScope - Return true if the specified tag is one of the scope
246 bool DIDescriptor::isScope() const {
250 case dwarf::DW_TAG_compile_unit:
251 case dwarf::DW_TAG_lexical_block:
252 case dwarf::DW_TAG_subprogram:
253 case dwarf::DW_TAG_namespace:
254 case dwarf::DW_TAG_file_type:
262 /// isTemplateTypeParameter - Return true if the specified tag is
263 /// DW_TAG_template_type_parameter.
264 bool DIDescriptor::isTemplateTypeParameter() const {
265 return DbgNode && getTag() == dwarf::DW_TAG_template_type_parameter;
268 /// isTemplateValueParameter - Return true if the specified tag is
269 /// DW_TAG_template_value_parameter.
270 bool DIDescriptor::isTemplateValueParameter() const {
271 return DbgNode && (getTag() == dwarf::DW_TAG_template_value_parameter ||
272 getTag() == dwarf::DW_TAG_GNU_template_template_param ||
273 getTag() == dwarf::DW_TAG_GNU_template_parameter_pack);
276 /// isCompileUnit - Return true if the specified tag is DW_TAG_compile_unit.
277 bool DIDescriptor::isCompileUnit() const {
278 return DbgNode && getTag() == dwarf::DW_TAG_compile_unit;
281 /// isFile - Return true if the specified tag is DW_TAG_file_type.
282 bool DIDescriptor::isFile() const {
283 return DbgNode && getTag() == dwarf::DW_TAG_file_type;
286 /// isNameSpace - Return true if the specified tag is DW_TAG_namespace.
287 bool DIDescriptor::isNameSpace() const {
288 return DbgNode && getTag() == dwarf::DW_TAG_namespace;
291 /// isLexicalBlockFile - Return true if the specified descriptor is a
292 /// lexical block with an extra file.
293 bool DIDescriptor::isLexicalBlockFile() const {
294 return DbgNode && getTag() == dwarf::DW_TAG_lexical_block &&
295 (DbgNode->getNumOperands() == 3);
298 /// isLexicalBlock - Return true if the specified tag is DW_TAG_lexical_block.
299 bool DIDescriptor::isLexicalBlock() const {
300 return DbgNode && getTag() == dwarf::DW_TAG_lexical_block &&
301 (DbgNode->getNumOperands() > 3);
304 /// isSubrange - Return true if the specified tag is DW_TAG_subrange_type.
305 bool DIDescriptor::isSubrange() const {
306 return DbgNode && getTag() == dwarf::DW_TAG_subrange_type;
309 /// isEnumerator - Return true if the specified tag is DW_TAG_enumerator.
310 bool DIDescriptor::isEnumerator() const {
311 return DbgNode && getTag() == dwarf::DW_TAG_enumerator;
314 /// isObjCProperty - Return true if the specified tag is DW_TAG_APPLE_property.
315 bool DIDescriptor::isObjCProperty() const {
316 return DbgNode && getTag() == dwarf::DW_TAG_APPLE_property;
319 /// \brief Return true if the specified tag is DW_TAG_imported_module or
320 /// DW_TAG_imported_declaration.
321 bool DIDescriptor::isImportedEntity() const {
322 return DbgNode && (getTag() == dwarf::DW_TAG_imported_module ||
323 getTag() == dwarf::DW_TAG_imported_declaration);
326 //===----------------------------------------------------------------------===//
327 // Simple Descriptor Constructors and other Methods
328 //===----------------------------------------------------------------------===//
330 unsigned DIArray::getNumElements() const {
333 return DbgNode->getNumOperands();
336 /// replaceAllUsesWith - Replace all uses of the MDNode used by this
337 /// type with the one in the passed descriptor.
338 void DIType::replaceAllUsesWith(DIDescriptor &D) {
340 assert(DbgNode && "Trying to replace an unverified type!");
342 // Since we use a TrackingVH for the node, its easy for clients to manufacture
343 // legitimate situations where they want to replaceAllUsesWith() on something
344 // which, due to uniquing, has merged with the source. We shield clients from
345 // this detail by allowing a value to be replaced with replaceAllUsesWith()
348 MDNode *Node = const_cast<MDNode *>(DbgNode);
349 const MDNode *DN = D;
350 const Value *V = cast_or_null<Value>(DN);
351 Node->replaceAllUsesWith(const_cast<Value *>(V));
352 MDNode::deleteTemporary(Node);
356 /// replaceAllUsesWith - Replace all uses of the MDNode used by this
357 /// type with the one in D.
358 void DIType::replaceAllUsesWith(MDNode *D) {
360 assert(DbgNode && "Trying to replace an unverified type!");
362 // Since we use a TrackingVH for the node, its easy for clients to manufacture
363 // legitimate situations where they want to replaceAllUsesWith() on something
364 // which, due to uniquing, has merged with the source. We shield clients from
365 // this detail by allowing a value to be replaced with replaceAllUsesWith()
368 MDNode *Node = const_cast<MDNode *>(DbgNode);
369 const MDNode *DN = D;
370 const Value *V = cast_or_null<Value>(DN);
371 Node->replaceAllUsesWith(const_cast<Value *>(V));
372 MDNode::deleteTemporary(Node);
376 /// Verify - Verify that a compile unit is well formed.
377 bool DICompileUnit::Verify() const {
378 if (!isCompileUnit())
381 // Don't bother verifying the compilation directory or producer string
382 // as those could be empty.
383 if (getFilename().empty())
386 return DbgNode->getNumOperands() == 14;
389 /// Verify - Verify that an ObjC property is well formed.
390 bool DIObjCProperty::Verify() const {
391 if (!isObjCProperty())
394 // Don't worry about the rest of the strings for now.
395 return DbgNode->getNumOperands() == 8;
398 /// Check if a field at position Elt of a MDNode is a MDNode.
399 /// We currently allow an empty string and an integer.
400 /// But we don't allow a non-empty string in a MDNode field.
401 static bool fieldIsMDNode(const MDNode *DbgNode, unsigned Elt) {
402 // FIXME: This function should return true, if the field is null or the field
403 // is indeed a MDNode: return !Fld || isa<MDNode>(Fld).
404 Value *Fld = getField(DbgNode, Elt);
405 if (Fld && isa<MDString>(Fld) && !cast<MDString>(Fld)->getString().empty())
410 /// Check if a field at position Elt of a MDNode is a MDString.
411 static bool fieldIsMDString(const MDNode *DbgNode, unsigned Elt) {
412 Value *Fld = getField(DbgNode, Elt);
413 return !Fld || isa<MDString>(Fld);
416 /// Check if a value can be a reference to a type.
417 static bool isTypeRef(const Value *Val) {
419 (isa<MDString>(Val) && !cast<MDString>(Val)->getString().empty()) ||
420 (isa<MDNode>(Val) && DIType(cast<MDNode>(Val)).isType());
423 /// Check if a field at position Elt of a MDNode can be a reference to a type.
424 static bool fieldIsTypeRef(const MDNode *DbgNode, unsigned Elt) {
425 Value *Fld = getField(DbgNode, Elt);
426 return isTypeRef(Fld);
429 /// Check if a value can be a ScopeRef.
430 static bool isScopeRef(const Value *Val) {
432 (isa<MDString>(Val) && !cast<MDString>(Val)->getString().empty()) ||
433 (isa<MDNode>(Val) && DIScope(cast<MDNode>(Val)).isScope());
436 /// Check if a field at position Elt of a MDNode can be a ScopeRef.
437 static bool fieldIsScopeRef(const MDNode *DbgNode, unsigned Elt) {
438 Value *Fld = getField(DbgNode, Elt);
439 return isScopeRef(Fld);
442 /// Verify - Verify that a type descriptor is well formed.
443 bool DIType::Verify() const {
446 // Make sure Context @ field 2 is MDNode.
447 if (!fieldIsScopeRef(DbgNode, 2))
450 // FIXME: Sink this into the various subclass verifies.
451 uint16_t Tag = getTag();
452 if (!isBasicType() && Tag != dwarf::DW_TAG_const_type &&
453 Tag != dwarf::DW_TAG_volatile_type && Tag != dwarf::DW_TAG_pointer_type &&
454 Tag != dwarf::DW_TAG_ptr_to_member_type &&
455 Tag != dwarf::DW_TAG_reference_type &&
456 Tag != dwarf::DW_TAG_rvalue_reference_type &&
457 Tag != dwarf::DW_TAG_restrict_type && Tag != dwarf::DW_TAG_array_type &&
458 Tag != dwarf::DW_TAG_enumeration_type &&
459 Tag != dwarf::DW_TAG_subroutine_type &&
460 Tag != dwarf::DW_TAG_inheritance && Tag != dwarf::DW_TAG_friend &&
461 getFilename().empty())
463 // DIType is abstract, it should be a BasicType, a DerivedType or
466 return DIBasicType(DbgNode).Verify();
467 else if (isCompositeType())
468 return DICompositeType(DbgNode).Verify();
469 else if (isDerivedType())
470 return DIDerivedType(DbgNode).Verify();
475 /// Verify - Verify that a basic type descriptor is well formed.
476 bool DIBasicType::Verify() const {
477 return isBasicType() && DbgNode->getNumOperands() == 10;
480 /// Verify - Verify that a derived type descriptor is well formed.
481 bool DIDerivedType::Verify() const {
482 // Make sure DerivedFrom @ field 9 is TypeRef.
483 if (!fieldIsTypeRef(DbgNode, 9))
485 if (getTag() == dwarf::DW_TAG_ptr_to_member_type)
486 // Make sure ClassType @ field 10 is a TypeRef.
487 if (!fieldIsTypeRef(DbgNode, 10))
490 return isDerivedType() && DbgNode->getNumOperands() >= 10 &&
491 DbgNode->getNumOperands() <= 14;
494 /// Verify - Verify that a composite type descriptor is well formed.
495 bool DICompositeType::Verify() const {
496 if (!isCompositeType())
499 // Make sure DerivedFrom @ field 9 and ContainingType @ field 12 are TypeRef.
500 if (!fieldIsTypeRef(DbgNode, 9))
502 if (!fieldIsTypeRef(DbgNode, 12))
505 // Make sure the type identifier at field 14 is MDString, it can be null.
506 if (!fieldIsMDString(DbgNode, 14))
509 // A subroutine type can't be both & and &&.
510 if (isLValueReference() && isRValueReference())
513 return DbgNode->getNumOperands() == 15;
516 /// Verify - Verify that a subprogram descriptor is well formed.
517 bool DISubprogram::Verify() const {
521 // Make sure context @ field 2 is a ScopeRef and type @ field 7 is a MDNode.
522 if (!fieldIsScopeRef(DbgNode, 2))
524 if (!fieldIsMDNode(DbgNode, 7))
526 // Containing type @ field 12.
527 if (!fieldIsTypeRef(DbgNode, 12))
530 // A subprogram can't be both & and &&.
531 if (isLValueReference() && isRValueReference())
534 return DbgNode->getNumOperands() == 20;
537 /// Verify - Verify that a global variable descriptor is well formed.
538 bool DIGlobalVariable::Verify() const {
539 if (!isGlobalVariable())
542 if (getDisplayName().empty())
544 // Make sure context @ field 2 is an MDNode.
545 if (!fieldIsMDNode(DbgNode, 2))
547 // Make sure that type @ field 8 is a DITypeRef.
548 if (!fieldIsTypeRef(DbgNode, 8))
550 // Make sure StaticDataMemberDeclaration @ field 12 is MDNode.
551 if (!fieldIsMDNode(DbgNode, 12))
554 return DbgNode->getNumOperands() == 13;
557 /// Verify - Verify that a variable descriptor is well formed.
558 bool DIVariable::Verify() const {
562 // Make sure context @ field 1 is an MDNode.
563 if (!fieldIsMDNode(DbgNode, 1))
565 // Make sure that type @ field 5 is a DITypeRef.
566 if (!fieldIsTypeRef(DbgNode, 5))
568 return DbgNode->getNumOperands() >= 8;
571 /// Verify - Verify that a location descriptor is well formed.
572 bool DILocation::Verify() const {
576 return DbgNode->getNumOperands() == 4;
579 /// Verify - Verify that a namespace descriptor is well formed.
580 bool DINameSpace::Verify() const {
583 return DbgNode->getNumOperands() == 5;
586 /// \brief Retrieve the MDNode for the directory/file pair.
587 MDNode *DIFile::getFileNode() const { return getNodeField(DbgNode, 1); }
589 /// \brief Verify that the file descriptor is well formed.
590 bool DIFile::Verify() const {
591 return isFile() && DbgNode->getNumOperands() == 2;
594 /// \brief Verify that the enumerator descriptor is well formed.
595 bool DIEnumerator::Verify() const {
596 return isEnumerator() && DbgNode->getNumOperands() == 3;
599 /// \brief Verify that the subrange descriptor is well formed.
600 bool DISubrange::Verify() const {
601 return isSubrange() && DbgNode->getNumOperands() == 3;
604 /// \brief Verify that the lexical block descriptor is well formed.
605 bool DILexicalBlock::Verify() const {
606 return isLexicalBlock() && DbgNode->getNumOperands() == 7;
609 /// \brief Verify that the file-scoped lexical block descriptor is well formed.
610 bool DILexicalBlockFile::Verify() const {
611 return isLexicalBlockFile() && DbgNode->getNumOperands() == 3;
614 /// \brief Verify that an unspecified parameter descriptor is well formed.
615 bool DIUnspecifiedParameter::Verify() const {
616 return isUnspecifiedParameter() && DbgNode->getNumOperands() == 1;
619 /// \brief Verify that the template type parameter descriptor is well formed.
620 bool DITemplateTypeParameter::Verify() const {
621 return isTemplateTypeParameter() && DbgNode->getNumOperands() == 7;
624 /// \brief Verify that the template value parameter descriptor is well formed.
625 bool DITemplateValueParameter::Verify() const {
626 return isTemplateValueParameter() && DbgNode->getNumOperands() == 8;
629 /// \brief Verify that the imported module descriptor is well formed.
630 bool DIImportedEntity::Verify() const {
631 return isImportedEntity() &&
632 (DbgNode->getNumOperands() == 4 || DbgNode->getNumOperands() == 5);
635 /// getObjCProperty - Return property node, if this ivar is associated with one.
636 MDNode *DIDerivedType::getObjCProperty() const {
637 return getNodeField(DbgNode, 10);
640 MDString *DICompositeType::getIdentifier() const {
641 return cast_or_null<MDString>(getField(DbgNode, 14));
645 static void VerifySubsetOf(const MDNode *LHS, const MDNode *RHS) {
646 for (unsigned i = 0; i != LHS->getNumOperands(); ++i) {
647 // Skip the 'empty' list (that's a single i32 0, rather than truly empty).
648 if (i == 0 && isa<ConstantInt>(LHS->getOperand(i)))
650 const MDNode *E = cast<MDNode>(LHS->getOperand(i));
652 for (unsigned j = 0; !found && j != RHS->getNumOperands(); ++j)
653 found = E == RHS->getOperand(j);
654 assert(found && "Losing a member during member list replacement");
659 /// \brief Set the array of member DITypes.
660 void DICompositeType::setTypeArray(DIArray Elements, DIArray TParams) {
661 assert((!TParams || DbgNode->getNumOperands() == 15) &&
662 "If you're setting the template parameters this should include a slot "
664 TrackingVH<MDNode> N(*this);
667 // Check that the new list of members contains all the old members as well.
668 if (const MDNode *El = cast_or_null<MDNode>(N->getOperand(10)))
669 VerifySubsetOf(El, Elements);
671 N->replaceOperandWith(10, Elements);
674 N->replaceOperandWith(13, TParams);
678 /// Generate a reference to this DIType. Uses the type identifier instead
679 /// of the actual MDNode if possible, to help type uniquing.
680 DIScopeRef DIScope::getRef() const {
681 if (!isCompositeType())
682 return DIScopeRef(*this);
683 DICompositeType DTy(DbgNode);
684 if (!DTy.getIdentifier())
685 return DIScopeRef(*this);
686 return DIScopeRef(DTy.getIdentifier());
689 /// \brief Set the containing type.
690 void DICompositeType::setContainingType(DICompositeType ContainingType) {
691 TrackingVH<MDNode> N(*this);
692 N->replaceOperandWith(12, ContainingType.getRef());
696 /// isInlinedFnArgument - Return true if this variable provides debugging
697 /// information for an inlined function arguments.
698 bool DIVariable::isInlinedFnArgument(const Function *CurFn) {
699 assert(CurFn && "Invalid function");
700 if (!getContext().isSubprogram())
702 // This variable is not inlined function argument if its scope
703 // does not describe current function.
704 return !DISubprogram(getContext()).describes(CurFn);
707 /// describes - Return true if this subprogram provides debugging
708 /// information for the function F.
709 bool DISubprogram::describes(const Function *F) {
710 assert(F && "Invalid function");
711 if (F == getFunction())
713 StringRef Name = getLinkageName();
716 if (F->getName() == Name)
721 unsigned DISubprogram::isOptimized() const {
722 assert(DbgNode && "Invalid subprogram descriptor!");
723 if (DbgNode->getNumOperands() == 15)
724 return getUnsignedField(14);
728 MDNode *DISubprogram::getVariablesNodes() const {
729 return getNodeField(DbgNode, 18);
732 DIArray DISubprogram::getVariables() const {
733 return DIArray(getNodeField(DbgNode, 18));
736 Value *DITemplateValueParameter::getValue() const {
737 return getField(DbgNode, 4);
740 // If the current node has a parent scope then return that,
741 // else return an empty scope.
742 DIScopeRef DIScope::getContext() const {
745 return DIType(DbgNode).getContext();
748 return DIScopeRef(DISubprogram(DbgNode).getContext());
750 if (isLexicalBlock())
751 return DIScopeRef(DILexicalBlock(DbgNode).getContext());
753 if (isLexicalBlockFile())
754 return DIScopeRef(DILexicalBlockFile(DbgNode).getContext());
757 return DIScopeRef(DINameSpace(DbgNode).getContext());
759 assert((isFile() || isCompileUnit()) && "Unhandled type of scope.");
760 return DIScopeRef(NULL);
763 // If the scope node has a name, return that, else return an empty string.
764 StringRef DIScope::getName() const {
766 return DIType(DbgNode).getName();
768 return DISubprogram(DbgNode).getName();
770 return DINameSpace(DbgNode).getName();
771 assert((isLexicalBlock() || isLexicalBlockFile() || isFile() ||
773 "Unhandled type of scope.");
777 StringRef DIScope::getFilename() const {
780 return ::getStringField(getNodeField(DbgNode, 1), 0);
783 StringRef DIScope::getDirectory() const {
786 return ::getStringField(getNodeField(DbgNode, 1), 1);
789 DIArray DICompileUnit::getEnumTypes() const {
790 if (!DbgNode || DbgNode->getNumOperands() < 13)
793 return DIArray(getNodeField(DbgNode, 7));
796 DIArray DICompileUnit::getRetainedTypes() const {
797 if (!DbgNode || DbgNode->getNumOperands() < 13)
800 return DIArray(getNodeField(DbgNode, 8));
803 DIArray DICompileUnit::getSubprograms() const {
804 if (!DbgNode || DbgNode->getNumOperands() < 13)
807 return DIArray(getNodeField(DbgNode, 9));
810 DIArray DICompileUnit::getGlobalVariables() const {
811 if (!DbgNode || DbgNode->getNumOperands() < 13)
814 return DIArray(getNodeField(DbgNode, 10));
817 DIArray DICompileUnit::getImportedEntities() const {
818 if (!DbgNode || DbgNode->getNumOperands() < 13)
821 return DIArray(getNodeField(DbgNode, 11));
824 /// copyWithNewScope - Return a copy of this location, replacing the
825 /// current scope with the given one.
826 DILocation DILocation::copyWithNewScope(LLVMContext &Ctx,
827 DILexicalBlock NewScope) {
828 SmallVector<Value *, 10> Elts;
830 for (unsigned I = 0; I < DbgNode->getNumOperands(); ++I) {
832 Elts.push_back(DbgNode->getOperand(I));
834 Elts.push_back(NewScope);
836 MDNode *NewDIL = MDNode::get(Ctx, Elts);
837 return DILocation(NewDIL);
840 /// computeNewDiscriminator - Generate a new discriminator value for this
841 /// file and line location.
842 unsigned DILocation::computeNewDiscriminator(LLVMContext &Ctx) {
843 std::pair<const char *, unsigned> Key(getFilename().data(), getLineNumber());
844 return ++Ctx.pImpl->DiscriminatorTable[Key];
847 /// fixupSubprogramName - Replace contains special characters used
848 /// in a typical Objective-C names with '.' in a given string.
849 static void fixupSubprogramName(DISubprogram Fn, SmallVectorImpl<char> &Out) {
851 Fn.getFunction() ? Fn.getFunction()->getName() : Fn.getName();
852 FName = Function::getRealLinkageName(FName);
854 StringRef Prefix("llvm.dbg.lv.");
855 Out.reserve(FName.size() + Prefix.size());
856 Out.append(Prefix.begin(), Prefix.end());
858 bool isObjCLike = false;
859 for (size_t i = 0, e = FName.size(); i < e; ++i) {
864 if (isObjCLike && (C == '[' || C == ']' || C == ' ' || C == ':' ||
865 C == '+' || C == '(' || C == ')'))
872 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
873 /// suitable to hold function specific information.
874 NamedMDNode *llvm::getFnSpecificMDNode(const Module &M, DISubprogram Fn) {
875 SmallString<32> Name;
876 fixupSubprogramName(Fn, Name);
877 return M.getNamedMetadata(Name.str());
880 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
881 /// to hold function specific information.
882 NamedMDNode *llvm::getOrInsertFnSpecificMDNode(Module &M, DISubprogram Fn) {
883 SmallString<32> Name;
884 fixupSubprogramName(Fn, Name);
885 return M.getOrInsertNamedMetadata(Name.str());
888 /// createInlinedVariable - Create a new inlined variable based on current
890 /// @param DV Current Variable.
891 /// @param InlinedScope Location at current variable is inlined.
892 DIVariable llvm::createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
893 LLVMContext &VMContext) {
894 SmallVector<Value *, 16> Elts;
895 // Insert inlined scope as 7th element.
896 for (unsigned i = 0, e = DV->getNumOperands(); i != e; ++i)
897 i == 7 ? Elts.push_back(InlinedScope) : Elts.push_back(DV->getOperand(i));
898 return DIVariable(MDNode::get(VMContext, Elts));
901 /// cleanseInlinedVariable - Remove inlined scope from the variable.
902 DIVariable llvm::cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext) {
903 SmallVector<Value *, 16> Elts;
904 // Insert inlined scope as 7th element.
905 for (unsigned i = 0, e = DV->getNumOperands(); i != e; ++i)
906 i == 7 ? Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)))
907 : Elts.push_back(DV->getOperand(i));
908 return DIVariable(MDNode::get(VMContext, Elts));
911 /// getDISubprogram - Find subprogram that is enclosing this scope.
912 DISubprogram llvm::getDISubprogram(const MDNode *Scope) {
913 DIDescriptor D(Scope);
914 if (D.isSubprogram())
915 return DISubprogram(Scope);
917 if (D.isLexicalBlockFile())
918 return getDISubprogram(DILexicalBlockFile(Scope).getContext());
920 if (D.isLexicalBlock())
921 return getDISubprogram(DILexicalBlock(Scope).getContext());
923 return DISubprogram();
926 /// getDICompositeType - Find underlying composite type.
927 DICompositeType llvm::getDICompositeType(DIType T) {
928 if (T.isCompositeType())
929 return DICompositeType(T);
931 if (T.isDerivedType()) {
932 // This function is currently used by dragonegg and dragonegg does
933 // not generate identifier for types, so using an empty map to resolve
934 // DerivedFrom should be fine.
935 DITypeIdentifierMap EmptyMap;
936 return getDICompositeType(
937 DIDerivedType(T).getTypeDerivedFrom().resolve(EmptyMap));
940 return DICompositeType();
943 /// Update DITypeIdentifierMap by going through retained types of each CU.
945 llvm::generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes) {
946 DITypeIdentifierMap Map;
947 for (unsigned CUi = 0, CUe = CU_Nodes->getNumOperands(); CUi != CUe; ++CUi) {
948 DICompileUnit CU(CU_Nodes->getOperand(CUi));
949 DIArray Retain = CU.getRetainedTypes();
950 for (unsigned Ti = 0, Te = Retain.getNumElements(); Ti != Te; ++Ti) {
951 if (!Retain.getElement(Ti).isCompositeType())
953 DICompositeType Ty(Retain.getElement(Ti));
954 if (MDString *TypeId = Ty.getIdentifier()) {
955 // Definition has priority over declaration.
956 // Try to insert (TypeId, Ty) to Map.
957 std::pair<DITypeIdentifierMap::iterator, bool> P =
958 Map.insert(std::make_pair(TypeId, Ty));
959 // If TypeId already exists in Map and this is a definition, replace
960 // whatever we had (declaration or definition) with the definition.
961 if (!P.second && !Ty.isForwardDecl())
962 P.first->second = Ty;
969 //===----------------------------------------------------------------------===//
970 // DebugInfoFinder implementations.
971 //===----------------------------------------------------------------------===//
973 void DebugInfoFinder::reset() {
980 TypeIdentifierMap.clear();
981 TypeMapInitialized = false;
984 void DebugInfoFinder::InitializeTypeMap(const Module &M) {
985 if (!TypeMapInitialized)
986 if (NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu")) {
987 TypeIdentifierMap = generateDITypeIdentifierMap(CU_Nodes);
988 TypeMapInitialized = true;
992 /// processModule - Process entire module and collect debug info.
993 void DebugInfoFinder::processModule(const Module &M) {
994 InitializeTypeMap(M);
995 if (NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu")) {
996 for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
997 DICompileUnit CU(CU_Nodes->getOperand(i));
999 DIArray GVs = CU.getGlobalVariables();
1000 for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i) {
1001 DIGlobalVariable DIG(GVs.getElement(i));
1002 if (addGlobalVariable(DIG)) {
1003 processScope(DIG.getContext());
1004 processType(DIG.getType().resolve(TypeIdentifierMap));
1007 DIArray SPs = CU.getSubprograms();
1008 for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i)
1009 processSubprogram(DISubprogram(SPs.getElement(i)));
1010 DIArray EnumTypes = CU.getEnumTypes();
1011 for (unsigned i = 0, e = EnumTypes.getNumElements(); i != e; ++i)
1012 processType(DIType(EnumTypes.getElement(i)));
1013 DIArray RetainedTypes = CU.getRetainedTypes();
1014 for (unsigned i = 0, e = RetainedTypes.getNumElements(); i != e; ++i)
1015 processType(DIType(RetainedTypes.getElement(i)));
1016 DIArray Imports = CU.getImportedEntities();
1017 for (unsigned i = 0, e = Imports.getNumElements(); i != e; ++i) {
1018 DIImportedEntity Import = DIImportedEntity(Imports.getElement(i));
1019 DIDescriptor Entity = Import.getEntity();
1020 if (Entity.isType())
1021 processType(DIType(Entity));
1022 else if (Entity.isSubprogram())
1023 processSubprogram(DISubprogram(Entity));
1024 else if (Entity.isNameSpace())
1025 processScope(DINameSpace(Entity).getContext());
1031 /// processLocation - Process DILocation.
1032 void DebugInfoFinder::processLocation(const Module &M, DILocation Loc) {
1035 InitializeTypeMap(M);
1036 processScope(Loc.getScope());
1037 processLocation(M, Loc.getOrigLocation());
1040 /// processType - Process DIType.
1041 void DebugInfoFinder::processType(DIType DT) {
1044 processScope(DT.getContext().resolve(TypeIdentifierMap));
1045 if (DT.isCompositeType()) {
1046 DICompositeType DCT(DT);
1047 processType(DCT.getTypeDerivedFrom().resolve(TypeIdentifierMap));
1048 DIArray DA = DCT.getTypeArray();
1049 for (unsigned i = 0, e = DA.getNumElements(); i != e; ++i) {
1050 DIDescriptor D = DA.getElement(i);
1052 processType(DIType(D));
1053 else if (D.isSubprogram())
1054 processSubprogram(DISubprogram(D));
1056 } else if (DT.isDerivedType()) {
1057 DIDerivedType DDT(DT);
1058 processType(DDT.getTypeDerivedFrom().resolve(TypeIdentifierMap));
1062 void DebugInfoFinder::processScope(DIScope Scope) {
1063 if (Scope.isType()) {
1068 if (Scope.isCompileUnit()) {
1069 addCompileUnit(DICompileUnit(Scope));
1072 if (Scope.isSubprogram()) {
1073 processSubprogram(DISubprogram(Scope));
1076 if (!addScope(Scope))
1078 if (Scope.isLexicalBlock()) {
1079 DILexicalBlock LB(Scope);
1080 processScope(LB.getContext());
1081 } else if (Scope.isLexicalBlockFile()) {
1082 DILexicalBlockFile LBF = DILexicalBlockFile(Scope);
1083 processScope(LBF.getScope());
1084 } else if (Scope.isNameSpace()) {
1085 DINameSpace NS(Scope);
1086 processScope(NS.getContext());
1090 /// processSubprogram - Process DISubprogram.
1091 void DebugInfoFinder::processSubprogram(DISubprogram SP) {
1092 if (!addSubprogram(SP))
1094 processScope(SP.getContext().resolve(TypeIdentifierMap));
1095 processType(SP.getType());
1096 DIArray TParams = SP.getTemplateParams();
1097 for (unsigned I = 0, E = TParams.getNumElements(); I != E; ++I) {
1098 DIDescriptor Element = TParams.getElement(I);
1099 if (Element.isTemplateTypeParameter()) {
1100 DITemplateTypeParameter TType(Element);
1101 processScope(TType.getContext().resolve(TypeIdentifierMap));
1102 processType(TType.getType().resolve(TypeIdentifierMap));
1103 } else if (Element.isTemplateValueParameter()) {
1104 DITemplateValueParameter TVal(Element);
1105 processScope(TVal.getContext().resolve(TypeIdentifierMap));
1106 processType(TVal.getType().resolve(TypeIdentifierMap));
1111 /// processDeclare - Process DbgDeclareInst.
1112 void DebugInfoFinder::processDeclare(const Module &M,
1113 const DbgDeclareInst *DDI) {
1114 MDNode *N = dyn_cast<MDNode>(DDI->getVariable());
1117 InitializeTypeMap(M);
1120 if (!DV.isVariable())
1123 if (!NodesSeen.insert(DV))
1125 processScope(DIVariable(N).getContext());
1126 processType(DIVariable(N).getType().resolve(TypeIdentifierMap));
1129 void DebugInfoFinder::processValue(const Module &M, const DbgValueInst *DVI) {
1130 MDNode *N = dyn_cast<MDNode>(DVI->getVariable());
1133 InitializeTypeMap(M);
1136 if (!DV.isVariable())
1139 if (!NodesSeen.insert(DV))
1141 processScope(DIVariable(N).getContext());
1142 processType(DIVariable(N).getType().resolve(TypeIdentifierMap));
1145 /// addType - Add type into Tys.
1146 bool DebugInfoFinder::addType(DIType DT) {
1150 if (!NodesSeen.insert(DT))
1157 /// addCompileUnit - Add compile unit into CUs.
1158 bool DebugInfoFinder::addCompileUnit(DICompileUnit CU) {
1161 if (!NodesSeen.insert(CU))
1168 /// addGlobalVariable - Add global variable into GVs.
1169 bool DebugInfoFinder::addGlobalVariable(DIGlobalVariable DIG) {
1173 if (!NodesSeen.insert(DIG))
1180 // addSubprogram - Add subprgoram into SPs.
1181 bool DebugInfoFinder::addSubprogram(DISubprogram SP) {
1185 if (!NodesSeen.insert(SP))
1192 bool DebugInfoFinder::addScope(DIScope Scope) {
1195 // FIXME: Ocaml binding generates a scope with no content, we treat it
1197 if (Scope->getNumOperands() == 0)
1199 if (!NodesSeen.insert(Scope))
1201 Scopes.push_back(Scope);
1205 //===----------------------------------------------------------------------===//
1206 // DIDescriptor: dump routines for all descriptors.
1207 //===----------------------------------------------------------------------===//
1209 /// dump - Print descriptor to dbgs() with a newline.
1210 void DIDescriptor::dump() const {
1215 /// print - Print descriptor.
1216 void DIDescriptor::print(raw_ostream &OS) const {
1220 if (const char *Tag = dwarf::TagString(getTag()))
1221 OS << "[ " << Tag << " ]";
1223 if (this->isSubrange()) {
1224 DISubrange(DbgNode).printInternal(OS);
1225 } else if (this->isCompileUnit()) {
1226 DICompileUnit(DbgNode).printInternal(OS);
1227 } else if (this->isFile()) {
1228 DIFile(DbgNode).printInternal(OS);
1229 } else if (this->isEnumerator()) {
1230 DIEnumerator(DbgNode).printInternal(OS);
1231 } else if (this->isBasicType()) {
1232 DIType(DbgNode).printInternal(OS);
1233 } else if (this->isDerivedType()) {
1234 DIDerivedType(DbgNode).printInternal(OS);
1235 } else if (this->isCompositeType()) {
1236 DICompositeType(DbgNode).printInternal(OS);
1237 } else if (this->isSubprogram()) {
1238 DISubprogram(DbgNode).printInternal(OS);
1239 } else if (this->isGlobalVariable()) {
1240 DIGlobalVariable(DbgNode).printInternal(OS);
1241 } else if (this->isVariable()) {
1242 DIVariable(DbgNode).printInternal(OS);
1243 } else if (this->isObjCProperty()) {
1244 DIObjCProperty(DbgNode).printInternal(OS);
1245 } else if (this->isNameSpace()) {
1246 DINameSpace(DbgNode).printInternal(OS);
1247 } else if (this->isScope()) {
1248 DIScope(DbgNode).printInternal(OS);
1252 void DISubrange::printInternal(raw_ostream &OS) const {
1253 int64_t Count = getCount();
1255 OS << " [" << getLo() << ", " << Count - 1 << ']';
1257 OS << " [unbounded]";
1260 void DIScope::printInternal(raw_ostream &OS) const {
1261 OS << " [" << getDirectory() << "/" << getFilename() << ']';
1264 void DICompileUnit::printInternal(raw_ostream &OS) const {
1265 DIScope::printInternal(OS);
1267 unsigned Lang = getLanguage();
1268 if (const char *LangStr = dwarf::LanguageString(Lang))
1271 (OS << "lang 0x").write_hex(Lang);
1275 void DIEnumerator::printInternal(raw_ostream &OS) const {
1276 OS << " [" << getName() << " :: " << getEnumValue() << ']';
1279 void DIType::printInternal(raw_ostream &OS) const {
1283 StringRef Res = getName();
1285 OS << " [" << Res << "]";
1287 // TODO: Print context?
1289 OS << " [line " << getLineNumber() << ", size " << getSizeInBits()
1290 << ", align " << getAlignInBits() << ", offset " << getOffsetInBits();
1292 if (const char *Enc =
1293 dwarf::AttributeEncodingString(DIBasicType(DbgNode).getEncoding()))
1294 OS << ", enc " << Enc;
1299 else if (isProtected())
1300 OS << " [protected]";
1303 OS << " [artificial]";
1305 if (isForwardDecl())
1307 else if (getTag() == dwarf::DW_TAG_structure_type ||
1308 getTag() == dwarf::DW_TAG_union_type ||
1309 getTag() == dwarf::DW_TAG_enumeration_type ||
1310 getTag() == dwarf::DW_TAG_class_type)
1314 if (isStaticMember())
1317 if (isLValueReference())
1318 OS << " [reference]";
1320 if (isRValueReference())
1321 OS << " [rvalue reference]";
1324 void DIDerivedType::printInternal(raw_ostream &OS) const {
1325 DIType::printInternal(OS);
1326 OS << " [from " << getTypeDerivedFrom().getName() << ']';
1329 void DICompositeType::printInternal(raw_ostream &OS) const {
1330 DIType::printInternal(OS);
1331 DIArray A = getTypeArray();
1332 OS << " [" << A.getNumElements() << " elements]";
1335 void DINameSpace::printInternal(raw_ostream &OS) const {
1336 StringRef Name = getName();
1338 OS << " [" << Name << ']';
1340 OS << " [line " << getLineNumber() << ']';
1343 void DISubprogram::printInternal(raw_ostream &OS) const {
1344 // TODO : Print context
1345 OS << " [line " << getLineNumber() << ']';
1347 if (isLocalToUnit())
1353 if (getScopeLineNumber() != getLineNumber())
1354 OS << " [scope " << getScopeLineNumber() << "]";
1358 else if (isProtected())
1359 OS << " [protected]";
1361 if (isLValueReference())
1362 OS << " [reference]";
1364 if (isRValueReference())
1365 OS << " [rvalue reference]";
1367 StringRef Res = getName();
1369 OS << " [" << Res << ']';
1372 void DIGlobalVariable::printInternal(raw_ostream &OS) const {
1373 StringRef Res = getName();
1375 OS << " [" << Res << ']';
1377 OS << " [line " << getLineNumber() << ']';
1379 // TODO : Print context
1381 if (isLocalToUnit())
1388 void DIVariable::printInternal(raw_ostream &OS) const {
1389 StringRef Res = getName();
1391 OS << " [" << Res << ']';
1393 OS << " [line " << getLineNumber() << ']';
1396 void DIObjCProperty::printInternal(raw_ostream &OS) const {
1397 StringRef Name = getObjCPropertyName();
1399 OS << " [" << Name << ']';
1401 OS << " [line " << getLineNumber() << ", properties " << getUnsignedField(6)
1405 static void printDebugLoc(DebugLoc DL, raw_ostream &CommentOS,
1406 const LLVMContext &Ctx) {
1407 if (!DL.isUnknown()) { // Print source line info.
1408 DIScope Scope(DL.getScope(Ctx));
1409 assert(Scope.isScope() && "Scope of a DebugLoc should be a DIScope.");
1410 // Omit the directory, because it's likely to be long and uninteresting.
1411 CommentOS << Scope.getFilename();
1412 CommentOS << ':' << DL.getLine();
1413 if (DL.getCol() != 0)
1414 CommentOS << ':' << DL.getCol();
1415 DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(DL.getInlinedAt(Ctx));
1416 if (!InlinedAtDL.isUnknown()) {
1417 CommentOS << " @[ ";
1418 printDebugLoc(InlinedAtDL, CommentOS, Ctx);
1424 void DIVariable::printExtendedName(raw_ostream &OS) const {
1425 const LLVMContext &Ctx = DbgNode->getContext();
1426 StringRef Res = getName();
1428 OS << Res << "," << getLineNumber();
1429 if (MDNode *InlinedAt = getInlinedAt()) {
1430 DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(InlinedAt);
1431 if (!InlinedAtDL.isUnknown()) {
1433 printDebugLoc(InlinedAtDL, OS, Ctx);
1439 /// Specialize constructor to make sure it has the correct type.
1440 template <> DIRef<DIScope>::DIRef(const Value *V) : Val(V) {
1441 assert(isScopeRef(V) && "DIScopeRef should be a MDString or MDNode");
1443 template <> DIRef<DIType>::DIRef(const Value *V) : Val(V) {
1444 assert(isTypeRef(V) && "DITypeRef should be a MDString or MDNode");
1447 /// Specialize getFieldAs to handle fields that are references to DIScopes.
1449 DIScopeRef DIDescriptor::getFieldAs<DIScopeRef>(unsigned Elt) const {
1450 return DIScopeRef(getField(DbgNode, Elt));
1452 /// Specialize getFieldAs to handle fields that are references to DITypes.
1453 template <> DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const {
1454 return DITypeRef(getField(DbgNode, Elt));
1457 /// Strip debug info in the module if it exists.
1458 /// To do this, we remove all calls to the debugger intrinsics and any named
1459 /// metadata for debugging. We also remove debug locations for instructions.
1460 /// Return true if module is modified.
1461 bool llvm::StripDebugInfo(Module &M) {
1463 bool Changed = false;
1465 // Remove all of the calls to the debugger intrinsics, and remove them from
1467 if (Function *Declare = M.getFunction("llvm.dbg.declare")) {
1468 while (!Declare->use_empty()) {
1469 CallInst *CI = cast<CallInst>(Declare->user_back());
1470 CI->eraseFromParent();
1472 Declare->eraseFromParent();
1476 if (Function *DbgVal = M.getFunction("llvm.dbg.value")) {
1477 while (!DbgVal->use_empty()) {
1478 CallInst *CI = cast<CallInst>(DbgVal->user_back());
1479 CI->eraseFromParent();
1481 DbgVal->eraseFromParent();
1485 for (Module::named_metadata_iterator NMI = M.named_metadata_begin(),
1486 NME = M.named_metadata_end(); NMI != NME;) {
1487 NamedMDNode *NMD = NMI;
1489 if (NMD->getName().startswith("llvm.dbg.")) {
1490 NMD->eraseFromParent();
1495 for (Module::iterator MI = M.begin(), ME = M.end(); MI != ME; ++MI)
1496 for (Function::iterator FI = MI->begin(), FE = MI->end(); FI != FE;
1498 for (BasicBlock::iterator BI = FI->begin(), BE = FI->end(); BI != BE;
1500 if (!BI->getDebugLoc().isUnknown()) {
1502 BI->setDebugLoc(DebugLoc());
1509 /// Return Debug Info Metadata Version by checking module flags.
1510 unsigned llvm::getDebugMetadataVersionFromModule(const Module &M) {
1511 Value *Val = M.getModuleFlag("Debug Info Version");
1514 return cast<ConstantInt>(Val)->getZExtValue();