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 Value *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 {
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 static unsigned DIVariableInlinedAtIndex = 4;
142 MDNode *DIVariable::getInlinedAt() const {
143 return getNodeField(DbgNode, DIVariableInlinedAtIndex);
146 /// \brief Return the size reported by the variable's type.
147 unsigned DIVariable::getSizeInBits(const DITypeIdentifierMap &Map) {
148 DIType Ty = getType().resolve(Map);
149 // Follow derived types until we reach a type that
150 // reports back a size.
151 while (Ty.isDerivedType() && !Ty.getSizeInBits()) {
152 DIDerivedType DT(&*Ty);
153 Ty = DT.getTypeDerivedFrom().resolve(Map);
155 assert(Ty.getSizeInBits() && "type with size 0");
156 return Ty.getSizeInBits();
159 uint64_t DIExpression::getElement(unsigned Idx) const {
160 unsigned I = Idx + 1;
161 assert(I < getNumHeaderFields() &&
162 "non-existing complex address element requested");
163 return getHeaderFieldAs<int64_t>(I);
166 bool DIExpression::isVariablePiece() const {
167 return getNumElements() && getElement(0) == dwarf::DW_OP_piece;
170 uint64_t DIExpression::getPieceOffset() const {
171 assert(isVariablePiece());
172 return getElement(1);
175 uint64_t DIExpression::getPieceSize() const {
176 assert(isVariablePiece());
177 return getElement(2);
180 //===----------------------------------------------------------------------===//
182 //===----------------------------------------------------------------------===//
184 bool DIDescriptor::isSubroutineType() const {
185 return isCompositeType() && getTag() == dwarf::DW_TAG_subroutine_type;
188 bool DIDescriptor::isBasicType() const {
192 case dwarf::DW_TAG_base_type:
193 case dwarf::DW_TAG_unspecified_type:
200 bool DIDescriptor::isDerivedType() const {
204 case dwarf::DW_TAG_typedef:
205 case dwarf::DW_TAG_pointer_type:
206 case dwarf::DW_TAG_ptr_to_member_type:
207 case dwarf::DW_TAG_reference_type:
208 case dwarf::DW_TAG_rvalue_reference_type:
209 case dwarf::DW_TAG_const_type:
210 case dwarf::DW_TAG_volatile_type:
211 case dwarf::DW_TAG_restrict_type:
212 case dwarf::DW_TAG_member:
213 case dwarf::DW_TAG_inheritance:
214 case dwarf::DW_TAG_friend:
217 // CompositeTypes are currently modelled as DerivedTypes.
218 return isCompositeType();
222 bool DIDescriptor::isCompositeType() const {
226 case dwarf::DW_TAG_array_type:
227 case dwarf::DW_TAG_structure_type:
228 case dwarf::DW_TAG_union_type:
229 case dwarf::DW_TAG_enumeration_type:
230 case dwarf::DW_TAG_subroutine_type:
231 case dwarf::DW_TAG_class_type:
238 bool DIDescriptor::isVariable() const {
242 case dwarf::DW_TAG_auto_variable:
243 case dwarf::DW_TAG_arg_variable:
250 bool DIDescriptor::isType() const {
251 return isBasicType() || isCompositeType() || isDerivedType();
254 bool DIDescriptor::isSubprogram() const {
255 return DbgNode && getTag() == dwarf::DW_TAG_subprogram;
258 bool DIDescriptor::isGlobalVariable() const {
259 return DbgNode && (getTag() == dwarf::DW_TAG_variable ||
260 getTag() == dwarf::DW_TAG_constant);
263 bool DIDescriptor::isScope() const {
267 case dwarf::DW_TAG_compile_unit:
268 case dwarf::DW_TAG_lexical_block:
269 case dwarf::DW_TAG_subprogram:
270 case dwarf::DW_TAG_namespace:
271 case dwarf::DW_TAG_file_type:
279 bool DIDescriptor::isTemplateTypeParameter() const {
280 return DbgNode && getTag() == dwarf::DW_TAG_template_type_parameter;
283 bool DIDescriptor::isTemplateValueParameter() const {
284 return DbgNode && (getTag() == dwarf::DW_TAG_template_value_parameter ||
285 getTag() == dwarf::DW_TAG_GNU_template_template_param ||
286 getTag() == dwarf::DW_TAG_GNU_template_parameter_pack);
289 bool DIDescriptor::isCompileUnit() const {
290 return DbgNode && getTag() == dwarf::DW_TAG_compile_unit;
293 bool DIDescriptor::isFile() const {
294 return DbgNode && getTag() == dwarf::DW_TAG_file_type;
297 bool DIDescriptor::isNameSpace() const {
298 return DbgNode && getTag() == dwarf::DW_TAG_namespace;
301 bool DIDescriptor::isLexicalBlockFile() const {
302 return DbgNode && getTag() == dwarf::DW_TAG_lexical_block &&
303 DbgNode->getNumOperands() == 3 && getNumHeaderFields() == 2;
306 bool DIDescriptor::isLexicalBlock() const {
307 // FIXME: There are always exactly 4 header fields in DILexicalBlock, but
308 // something relies on this returning true for DILexicalBlockFile.
309 return DbgNode && getTag() == dwarf::DW_TAG_lexical_block &&
310 DbgNode->getNumOperands() == 3 &&
311 (getNumHeaderFields() == 2 || getNumHeaderFields() == 4);
314 bool DIDescriptor::isSubrange() const {
315 return DbgNode && getTag() == dwarf::DW_TAG_subrange_type;
318 bool DIDescriptor::isEnumerator() const {
319 return DbgNode && getTag() == dwarf::DW_TAG_enumerator;
322 bool DIDescriptor::isObjCProperty() const {
323 return DbgNode && getTag() == dwarf::DW_TAG_APPLE_property;
326 bool DIDescriptor::isImportedEntity() const {
327 return DbgNode && (getTag() == dwarf::DW_TAG_imported_module ||
328 getTag() == dwarf::DW_TAG_imported_declaration);
331 bool DIDescriptor::isExpression() const {
332 return DbgNode && (getTag() == dwarf::DW_TAG_expression);
335 //===----------------------------------------------------------------------===//
336 // Simple Descriptor Constructors and other Methods
337 //===----------------------------------------------------------------------===//
339 void DIDescriptor::replaceAllUsesWith(LLVMContext &VMContext, DIDescriptor D) {
341 assert(DbgNode && "Trying to replace an unverified type!");
343 // Since we use a TrackingVH for the node, its easy for clients to manufacture
344 // legitimate situations where they want to replaceAllUsesWith() on something
345 // which, due to uniquing, has merged with the source. We shield clients from
346 // this detail by allowing a value to be replaced with replaceAllUsesWith()
348 const MDNode *DN = D;
350 SmallVector<Value*, 10> Ops(DbgNode->getNumOperands());
351 for (size_t i = 0; i != Ops.size(); ++i)
352 Ops[i] = DbgNode->getOperand(i);
353 DN = MDNode::get(VMContext, Ops);
356 MDNode *Node = const_cast<MDNode *>(DbgNode);
357 const Value *V = cast_or_null<Value>(DN);
358 Node->replaceAllUsesWith(const_cast<Value *>(V));
359 MDNode::deleteTemporary(Node);
363 void DIDescriptor::replaceAllUsesWith(MDNode *D) {
365 assert(DbgNode && "Trying to replace an unverified type!");
366 assert(DbgNode != D && "This replacement should always happen");
367 MDNode *Node = const_cast<MDNode *>(DbgNode);
368 const MDNode *DN = D;
369 const Value *V = cast_or_null<Value>(DN);
370 Node->replaceAllUsesWith(const_cast<Value *>(V));
371 MDNode::deleteTemporary(Node);
374 bool DICompileUnit::Verify() const {
375 if (!isCompileUnit())
378 // Don't bother verifying the compilation directory or producer string
379 // as those could be empty.
380 if (getFilename().empty())
383 return DbgNode->getNumOperands() == 7 && getNumHeaderFields() == 8;
386 bool DIObjCProperty::Verify() const {
387 if (!isObjCProperty())
390 // Don't worry about the rest of the strings for now.
391 return DbgNode->getNumOperands() == 3 && getNumHeaderFields() == 6;
394 /// \brief Check if a field at position Elt of a MDNode is a MDNode.
396 /// We currently allow an empty string and an integer.
397 /// But we don't allow a non-empty string in a MDNode field.
398 static bool fieldIsMDNode(const MDNode *DbgNode, unsigned Elt) {
399 // FIXME: This function should return true, if the field is null or the field
400 // is indeed a MDNode: return !Fld || isa<MDNode>(Fld).
401 Value *Fld = getField(DbgNode, Elt);
402 if (Fld && isa<MDString>(Fld) && !cast<MDString>(Fld)->getString().empty())
407 /// \brief Check if a field at position Elt of a MDNode is a MDString.
408 static bool fieldIsMDString(const MDNode *DbgNode, unsigned Elt) {
409 Value *Fld = getField(DbgNode, Elt);
410 return !Fld || isa<MDString>(Fld);
413 /// \brief Check if a value can be a reference to a type.
414 static bool isTypeRef(const Metadata *MD) {
417 if (auto *S = dyn_cast<MDString>(MD))
418 return !S->getString().empty();
419 if (auto *N = dyn_cast<MDNode>(MD))
420 return DIType(N).isType();
424 /// \brief Check if referenced field might be a type.
425 static bool fieldIsTypeRef(const MDNode *DbgNode, unsigned Elt) {
426 return isTypeRef(dyn_cast_or_null<Metadata>(getField(DbgNode, Elt)));
429 /// \brief Check if a value can be a ScopeRef.
430 static bool isScopeRef(const Metadata *MD) {
433 if (auto *S = dyn_cast<MDString>(MD))
434 return !S->getString().empty();
435 return isa<MDNode>(MD);
438 /// \brief Check if a field at position Elt of a MDNode can be a ScopeRef.
439 static bool fieldIsScopeRef(const MDNode *DbgNode, unsigned Elt) {
440 return isScopeRef(dyn_cast_or_null<Metadata>(getField(DbgNode, Elt)));
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())
464 // DIType is abstract, it should be a BasicType, a DerivedType or
467 return DIBasicType(DbgNode).Verify();
468 else if (isCompositeType())
469 return DICompositeType(DbgNode).Verify();
470 else if (isDerivedType())
471 return DIDerivedType(DbgNode).Verify();
476 bool DIBasicType::Verify() const {
477 return isBasicType() && DbgNode->getNumOperands() == 3 &&
478 getNumHeaderFields() == 8;
481 bool DIDerivedType::Verify() const {
482 // Make sure DerivedFrom @ field 3 is TypeRef.
483 if (!fieldIsTypeRef(DbgNode, 3))
485 if (getTag() == dwarf::DW_TAG_ptr_to_member_type)
486 // Make sure ClassType @ field 4 is a TypeRef.
487 if (!fieldIsTypeRef(DbgNode, 4))
490 return isDerivedType() && DbgNode->getNumOperands() >= 4 &&
491 DbgNode->getNumOperands() <= 8 && getNumHeaderFields() >= 7 &&
492 getNumHeaderFields() <= 8;
495 bool DICompositeType::Verify() const {
496 if (!isCompositeType())
499 // Make sure DerivedFrom @ field 3 and ContainingType @ field 5 are TypeRef.
500 if (!fieldIsTypeRef(DbgNode, 3))
502 if (!fieldIsTypeRef(DbgNode, 5))
505 // Make sure the type identifier at field 7 is MDString, it can be null.
506 if (!fieldIsMDString(DbgNode, 7))
509 // A subroutine type can't be both & and &&.
510 if (isLValueReference() && isRValueReference())
513 return DbgNode->getNumOperands() == 8 && getNumHeaderFields() == 8;
516 bool DISubprogram::Verify() const {
520 // Make sure context @ field 2 is a ScopeRef and type @ field 3 is a MDNode.
521 if (!fieldIsScopeRef(DbgNode, 2))
523 if (!fieldIsMDNode(DbgNode, 3))
525 // Containing type @ field 4.
526 if (!fieldIsTypeRef(DbgNode, 4))
529 // A subprogram can't be both & and &&.
530 if (isLValueReference() && isRValueReference())
533 // If a DISubprogram has an llvm::Function*, then scope chains from all
534 // instructions within the function should lead to this DISubprogram.
535 if (auto *F = getFunction()) {
536 LLVMContext &Ctxt = F->getContext();
537 for (auto &BB : *F) {
539 DebugLoc DL = I.getDebugLoc();
543 MDNode *Scope = nullptr;
544 MDNode *IA = nullptr;
545 // walk the inlined-at scopes
546 while (DL.getScopeAndInlinedAt(Scope, IA, F->getContext()), IA)
547 DL = DebugLoc::getFromDILocation(IA);
548 DL.getScopeAndInlinedAt(Scope, IA, Ctxt);
550 while (!DIDescriptor(Scope).isSubprogram()) {
551 DILexicalBlockFile D(Scope);
552 Scope = D.isLexicalBlockFile()
554 : DebugLoc::getFromDILexicalBlock(Scope).getScope(Ctxt);
556 if (!DISubprogram(Scope).describes(F))
561 return DbgNode->getNumOperands() == 9 && getNumHeaderFields() == 12;
564 bool DIGlobalVariable::Verify() const {
565 if (!isGlobalVariable())
568 if (getDisplayName().empty())
570 // Make sure context @ field 1 is a ScopeRef.
571 if (!fieldIsScopeRef(DbgNode, 1))
573 // Make sure that type @ field 3 is a DITypeRef.
574 if (!fieldIsTypeRef(DbgNode, 3))
576 // Make sure StaticDataMemberDeclaration @ field 5 is MDNode.
577 if (!fieldIsMDNode(DbgNode, 5))
580 return DbgNode->getNumOperands() == 6 && getNumHeaderFields() == 7;
583 bool DIVariable::Verify() const {
587 // Make sure context @ field 1 is an MDNode.
588 if (!fieldIsMDNode(DbgNode, 1))
590 // Make sure that type @ field 3 is a DITypeRef.
591 if (!fieldIsTypeRef(DbgNode, 3))
594 // Check the number of header fields, which is common between complex and
596 if (getNumHeaderFields() != 4)
599 // Variable without an inline location.
600 if (DbgNode->getNumOperands() == 4)
603 // Variable with an inline location.
604 return getInlinedAt() != nullptr && DbgNode->getNumOperands() == 5;
607 bool DIExpression::Verify() const {
608 // Empty DIExpressions may be represented as a nullptr.
612 return isExpression() && DbgNode->getNumOperands() == 1;
615 bool DILocation::Verify() const {
619 return DbgNode->getNumOperands() == 4;
622 bool DINameSpace::Verify() const {
625 return DbgNode->getNumOperands() == 3 && getNumHeaderFields() == 3;
628 MDNode *DIFile::getFileNode() const { return getNodeField(DbgNode, 1); }
630 bool DIFile::Verify() const {
631 return isFile() && DbgNode->getNumOperands() == 2;
634 bool DIEnumerator::Verify() const {
635 return isEnumerator() && DbgNode->getNumOperands() == 1 &&
636 getNumHeaderFields() == 3;
639 bool DISubrange::Verify() const {
640 return isSubrange() && DbgNode->getNumOperands() == 1 &&
641 getNumHeaderFields() == 3;
644 bool DILexicalBlock::Verify() const {
645 return isLexicalBlock() && DbgNode->getNumOperands() == 3 &&
646 getNumHeaderFields() == 4;
649 bool DILexicalBlockFile::Verify() const {
650 return isLexicalBlockFile() && DbgNode->getNumOperands() == 3 &&
651 getNumHeaderFields() == 2;
654 bool DITemplateTypeParameter::Verify() const {
655 return isTemplateTypeParameter() && DbgNode->getNumOperands() == 4 &&
656 getNumHeaderFields() == 4;
659 bool DITemplateValueParameter::Verify() const {
660 return isTemplateValueParameter() && DbgNode->getNumOperands() == 5 &&
661 getNumHeaderFields() == 4;
664 bool DIImportedEntity::Verify() const {
665 return isImportedEntity() && DbgNode->getNumOperands() == 3 &&
666 getNumHeaderFields() == 3;
669 MDNode *DIDerivedType::getObjCProperty() const {
670 return getNodeField(DbgNode, 4);
673 MDString *DICompositeType::getIdentifier() const {
674 return cast_or_null<MDString>(getField(DbgNode, 7));
678 static void VerifySubsetOf(const MDNode *LHS, const MDNode *RHS) {
679 for (unsigned i = 0; i != LHS->getNumOperands(); ++i) {
680 // Skip the 'empty' list (that's a single i32 0, rather than truly empty).
681 if (i == 0 && isa<ConstantInt>(LHS->getOperand(i)))
683 const MDNode *E = cast<MDNode>(LHS->getOperand(i));
685 for (unsigned j = 0; !found && j != RHS->getNumOperands(); ++j)
686 found = E == RHS->getOperand(j);
687 assert(found && "Losing a member during member list replacement");
692 void DICompositeType::setArraysHelper(MDNode *Elements, MDNode *TParams) {
693 TrackingVH<MDNode> N(*this);
696 // Check that the new list of members contains all the old members as well.
697 if (const MDNode *El = cast_or_null<MDNode>(N->getOperand(4)))
698 VerifySubsetOf(El, Elements);
700 N->replaceOperandWith(4, Elements);
703 N->replaceOperandWith(6, TParams);
707 DIScopeRef DIScope::getRef() const {
708 if (!isCompositeType())
709 return DIScopeRef(*this);
710 DICompositeType DTy(DbgNode);
711 if (!DTy.getIdentifier())
712 return DIScopeRef(*this);
713 return DIScopeRef(DTy.getIdentifier());
716 void DICompositeType::setContainingType(DICompositeType ContainingType) {
717 TrackingVH<MDNode> N(*this);
718 N->replaceOperandWith(5, ContainingType.getRef());
722 bool DIVariable::isInlinedFnArgument(const Function *CurFn) {
723 assert(CurFn && "Invalid function");
724 if (!getContext().isSubprogram())
726 // This variable is not inlined function argument if its scope
727 // does not describe current function.
728 return !DISubprogram(getContext()).describes(CurFn);
731 bool DISubprogram::describes(const Function *F) {
732 assert(F && "Invalid function");
733 if (F == getFunction())
735 StringRef Name = getLinkageName();
738 if (F->getName() == Name)
743 MDNode *DISubprogram::getVariablesNodes() const {
744 return getNodeField(DbgNode, 8);
747 DIArray DISubprogram::getVariables() const {
748 return DIArray(getNodeField(DbgNode, 8));
751 Value *DITemplateValueParameter::getValue() const {
752 return getField(DbgNode, 3);
755 DIScopeRef DIScope::getContext() const {
758 return DIType(DbgNode).getContext();
761 return DIScopeRef(DISubprogram(DbgNode).getContext());
763 if (isLexicalBlock())
764 return DIScopeRef(DILexicalBlock(DbgNode).getContext());
766 if (isLexicalBlockFile())
767 return DIScopeRef(DILexicalBlockFile(DbgNode).getContext());
770 return DIScopeRef(DINameSpace(DbgNode).getContext());
772 assert((isFile() || isCompileUnit()) && "Unhandled type of scope.");
773 return DIScopeRef(nullptr);
776 StringRef DIScope::getName() const {
778 return DIType(DbgNode).getName();
780 return DISubprogram(DbgNode).getName();
782 return DINameSpace(DbgNode).getName();
783 assert((isLexicalBlock() || isLexicalBlockFile() || isFile() ||
785 "Unhandled type of scope.");
789 StringRef DIScope::getFilename() const {
792 return ::getStringField(getNodeField(DbgNode, 1), 0);
795 StringRef DIScope::getDirectory() const {
798 return ::getStringField(getNodeField(DbgNode, 1), 1);
801 DIArray DICompileUnit::getEnumTypes() const {
802 if (!DbgNode || DbgNode->getNumOperands() < 7)
805 return DIArray(getNodeField(DbgNode, 2));
808 DIArray DICompileUnit::getRetainedTypes() const {
809 if (!DbgNode || DbgNode->getNumOperands() < 7)
812 return DIArray(getNodeField(DbgNode, 3));
815 DIArray DICompileUnit::getSubprograms() const {
816 if (!DbgNode || DbgNode->getNumOperands() < 7)
819 return DIArray(getNodeField(DbgNode, 4));
822 DIArray DICompileUnit::getGlobalVariables() const {
823 if (!DbgNode || DbgNode->getNumOperands() < 7)
826 return DIArray(getNodeField(DbgNode, 5));
829 DIArray DICompileUnit::getImportedEntities() const {
830 if (!DbgNode || DbgNode->getNumOperands() < 7)
833 return DIArray(getNodeField(DbgNode, 6));
836 void DICompileUnit::replaceSubprograms(DIArray Subprograms) {
837 assert(Verify() && "Expected compile unit");
838 if (Subprograms == getSubprograms())
841 const_cast<MDNode *>(DbgNode)->replaceOperandWith(4, Subprograms);
844 void DICompileUnit::replaceGlobalVariables(DIArray GlobalVariables) {
845 assert(Verify() && "Expected compile unit");
846 if (GlobalVariables == getGlobalVariables())
849 const_cast<MDNode *>(DbgNode)->replaceOperandWith(5, GlobalVariables);
852 DILocation DILocation::copyWithNewScope(LLVMContext &Ctx,
853 DILexicalBlockFile NewScope) {
854 SmallVector<Value *, 10> Elts;
856 for (unsigned I = 0; I < DbgNode->getNumOperands(); ++I) {
858 Elts.push_back(DbgNode->getOperand(I));
860 Elts.push_back(NewScope);
862 MDNode *NewDIL = MDNode::get(Ctx, Elts);
863 return DILocation(NewDIL);
866 unsigned DILocation::computeNewDiscriminator(LLVMContext &Ctx) {
867 std::pair<const char *, unsigned> Key(getFilename().data(), getLineNumber());
868 return ++Ctx.pImpl->DiscriminatorTable[Key];
871 DIVariable llvm::createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
872 LLVMContext &VMContext) {
873 assert(DIVariable(DV).Verify() && "Expected a DIVariable");
875 return cleanseInlinedVariable(DV, VMContext);
877 // Insert inlined scope.
878 SmallVector<Value *, 8> Elts;
879 for (unsigned I = 0, E = DIVariableInlinedAtIndex; I != E; ++I)
880 Elts.push_back(DV->getOperand(I));
881 Elts.push_back(InlinedScope);
883 DIVariable Inlined(MDNode::get(VMContext, Elts));
884 assert(Inlined.Verify() && "Expected to create a DIVariable");
888 DIVariable llvm::cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext) {
889 assert(DIVariable(DV).Verify() && "Expected a DIVariable");
890 if (!DIVariable(DV).getInlinedAt())
891 return DIVariable(DV);
893 // Remove inlined scope.
894 SmallVector<Value *, 8> Elts;
895 for (unsigned I = 0, E = DIVariableInlinedAtIndex; I != E; ++I)
896 Elts.push_back(DV->getOperand(I));
898 DIVariable Cleansed(MDNode::get(VMContext, Elts));
899 assert(Cleansed.Verify() && "Expected to create a DIVariable");
903 DISubprogram llvm::getDISubprogram(const MDNode *Scope) {
904 DIDescriptor D(Scope);
905 if (D.isSubprogram())
906 return DISubprogram(Scope);
908 if (D.isLexicalBlockFile())
909 return getDISubprogram(DILexicalBlockFile(Scope).getContext());
911 if (D.isLexicalBlock())
912 return getDISubprogram(DILexicalBlock(Scope).getContext());
914 return DISubprogram();
917 DISubprogram llvm::getDISubprogram(const Function *F) {
918 // We look for the first instr that has a debug annotation leading back to F.
919 for (auto &BB : *F) {
920 auto Inst = std::find_if(BB.begin(), BB.end(), [](const Instruction &Inst) {
921 return !Inst.getDebugLoc().isUnknown();
923 if (Inst == BB.end())
925 DebugLoc DLoc = Inst->getDebugLoc();
926 const MDNode *Scope = DLoc.getScopeNode(F->getParent()->getContext());
927 DISubprogram Subprogram = getDISubprogram(Scope);
928 return Subprogram.describes(F) ? Subprogram : DISubprogram();
931 return DISubprogram();
934 DICompositeType llvm::getDICompositeType(DIType T) {
935 if (T.isCompositeType())
936 return DICompositeType(T);
938 if (T.isDerivedType()) {
939 // This function is currently used by dragonegg and dragonegg does
940 // not generate identifier for types, so using an empty map to resolve
941 // DerivedFrom should be fine.
942 DITypeIdentifierMap EmptyMap;
943 return getDICompositeType(
944 DIDerivedType(T).getTypeDerivedFrom().resolve(EmptyMap));
947 return DICompositeType();
951 llvm::generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes) {
952 DITypeIdentifierMap Map;
953 for (unsigned CUi = 0, CUe = CU_Nodes->getNumOperands(); CUi != CUe; ++CUi) {
954 DICompileUnit CU(CU_Nodes->getOperand(CUi));
955 DIArray Retain = CU.getRetainedTypes();
956 for (unsigned Ti = 0, Te = Retain.getNumElements(); Ti != Te; ++Ti) {
957 if (!Retain.getElement(Ti).isCompositeType())
959 DICompositeType Ty(Retain.getElement(Ti));
960 if (MDString *TypeId = Ty.getIdentifier()) {
961 // Definition has priority over declaration.
962 // Try to insert (TypeId, Ty) to Map.
963 std::pair<DITypeIdentifierMap::iterator, bool> P =
964 Map.insert(std::make_pair(TypeId, Ty));
965 // If TypeId already exists in Map and this is a definition, replace
966 // whatever we had (declaration or definition) with the definition.
967 if (!P.second && !Ty.isForwardDecl())
968 P.first->second = Ty;
975 //===----------------------------------------------------------------------===//
976 // DebugInfoFinder implementations.
977 //===----------------------------------------------------------------------===//
979 void DebugInfoFinder::reset() {
986 TypeIdentifierMap.clear();
987 TypeMapInitialized = false;
990 void DebugInfoFinder::InitializeTypeMap(const Module &M) {
991 if (!TypeMapInitialized)
992 if (NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu")) {
993 TypeIdentifierMap = generateDITypeIdentifierMap(CU_Nodes);
994 TypeMapInitialized = true;
998 void DebugInfoFinder::processModule(const Module &M) {
999 InitializeTypeMap(M);
1000 if (NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu")) {
1001 for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
1002 DICompileUnit CU(CU_Nodes->getOperand(i));
1004 DIArray GVs = CU.getGlobalVariables();
1005 for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i) {
1006 DIGlobalVariable DIG(GVs.getElement(i));
1007 if (addGlobalVariable(DIG)) {
1008 processScope(DIG.getContext().resolve(TypeIdentifierMap));
1009 processType(DIG.getType().resolve(TypeIdentifierMap));
1012 DIArray SPs = CU.getSubprograms();
1013 for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i)
1014 processSubprogram(DISubprogram(SPs.getElement(i)));
1015 DIArray EnumTypes = CU.getEnumTypes();
1016 for (unsigned i = 0, e = EnumTypes.getNumElements(); i != e; ++i)
1017 processType(DIType(EnumTypes.getElement(i)));
1018 DIArray RetainedTypes = CU.getRetainedTypes();
1019 for (unsigned i = 0, e = RetainedTypes.getNumElements(); i != e; ++i)
1020 processType(DIType(RetainedTypes.getElement(i)));
1021 DIArray Imports = CU.getImportedEntities();
1022 for (unsigned i = 0, e = Imports.getNumElements(); i != e; ++i) {
1023 DIImportedEntity Import = DIImportedEntity(Imports.getElement(i));
1024 DIDescriptor Entity = Import.getEntity().resolve(TypeIdentifierMap);
1025 if (Entity.isType())
1026 processType(DIType(Entity));
1027 else if (Entity.isSubprogram())
1028 processSubprogram(DISubprogram(Entity));
1029 else if (Entity.isNameSpace())
1030 processScope(DINameSpace(Entity).getContext());
1036 void DebugInfoFinder::processLocation(const Module &M, DILocation Loc) {
1039 InitializeTypeMap(M);
1040 processScope(Loc.getScope());
1041 processLocation(M, Loc.getOrigLocation());
1044 void DebugInfoFinder::processType(DIType DT) {
1047 processScope(DT.getContext().resolve(TypeIdentifierMap));
1048 if (DT.isCompositeType()) {
1049 DICompositeType DCT(DT);
1050 processType(DCT.getTypeDerivedFrom().resolve(TypeIdentifierMap));
1051 if (DT.isSubroutineType()) {
1052 DITypeArray DTA = DISubroutineType(DT).getTypeArray();
1053 for (unsigned i = 0, e = DTA.getNumElements(); i != e; ++i)
1054 processType(DTA.getElement(i).resolve(TypeIdentifierMap));
1057 DIArray DA = DCT.getElements();
1058 for (unsigned i = 0, e = DA.getNumElements(); i != e; ++i) {
1059 DIDescriptor D = DA.getElement(i);
1061 processType(DIType(D));
1062 else if (D.isSubprogram())
1063 processSubprogram(DISubprogram(D));
1065 } else if (DT.isDerivedType()) {
1066 DIDerivedType DDT(DT);
1067 processType(DDT.getTypeDerivedFrom().resolve(TypeIdentifierMap));
1071 void DebugInfoFinder::processScope(DIScope Scope) {
1072 if (Scope.isType()) {
1077 if (Scope.isCompileUnit()) {
1078 addCompileUnit(DICompileUnit(Scope));
1081 if (Scope.isSubprogram()) {
1082 processSubprogram(DISubprogram(Scope));
1085 if (!addScope(Scope))
1087 if (Scope.isLexicalBlock()) {
1088 DILexicalBlock LB(Scope);
1089 processScope(LB.getContext());
1090 } else if (Scope.isLexicalBlockFile()) {
1091 DILexicalBlockFile LBF = DILexicalBlockFile(Scope);
1092 processScope(LBF.getScope());
1093 } else if (Scope.isNameSpace()) {
1094 DINameSpace NS(Scope);
1095 processScope(NS.getContext());
1099 void DebugInfoFinder::processSubprogram(DISubprogram SP) {
1100 if (!addSubprogram(SP))
1102 processScope(SP.getContext().resolve(TypeIdentifierMap));
1103 processType(SP.getType());
1104 DIArray TParams = SP.getTemplateParams();
1105 for (unsigned I = 0, E = TParams.getNumElements(); I != E; ++I) {
1106 DIDescriptor Element = TParams.getElement(I);
1107 if (Element.isTemplateTypeParameter()) {
1108 DITemplateTypeParameter TType(Element);
1109 processScope(TType.getContext().resolve(TypeIdentifierMap));
1110 processType(TType.getType().resolve(TypeIdentifierMap));
1111 } else if (Element.isTemplateValueParameter()) {
1112 DITemplateValueParameter TVal(Element);
1113 processScope(TVal.getContext().resolve(TypeIdentifierMap));
1114 processType(TVal.getType().resolve(TypeIdentifierMap));
1119 void DebugInfoFinder::processDeclare(const Module &M,
1120 const DbgDeclareInst *DDI) {
1121 MDNode *N = dyn_cast<MDNode>(DDI->getVariable());
1124 InitializeTypeMap(M);
1127 if (!DV.isVariable())
1130 if (!NodesSeen.insert(DV).second)
1132 processScope(DIVariable(N).getContext());
1133 processType(DIVariable(N).getType().resolve(TypeIdentifierMap));
1136 void DebugInfoFinder::processValue(const Module &M, const DbgValueInst *DVI) {
1137 MDNode *N = dyn_cast<MDNode>(DVI->getVariable());
1140 InitializeTypeMap(M);
1143 if (!DV.isVariable())
1146 if (!NodesSeen.insert(DV).second)
1148 processScope(DIVariable(N).getContext());
1149 processType(DIVariable(N).getType().resolve(TypeIdentifierMap));
1152 bool DebugInfoFinder::addType(DIType DT) {
1156 if (!NodesSeen.insert(DT).second)
1163 bool DebugInfoFinder::addCompileUnit(DICompileUnit CU) {
1166 if (!NodesSeen.insert(CU).second)
1173 bool DebugInfoFinder::addGlobalVariable(DIGlobalVariable DIG) {
1177 if (!NodesSeen.insert(DIG).second)
1184 bool DebugInfoFinder::addSubprogram(DISubprogram SP) {
1188 if (!NodesSeen.insert(SP).second)
1195 bool DebugInfoFinder::addScope(DIScope Scope) {
1198 // FIXME: Ocaml binding generates a scope with no content, we treat it
1200 if (Scope->getNumOperands() == 0)
1202 if (!NodesSeen.insert(Scope).second)
1204 Scopes.push_back(Scope);
1208 //===----------------------------------------------------------------------===//
1209 // DIDescriptor: dump routines for all descriptors.
1210 //===----------------------------------------------------------------------===//
1212 void DIDescriptor::dump() const {
1217 void DIDescriptor::print(raw_ostream &OS) const {
1221 if (const char *Tag = dwarf::TagString(getTag()))
1222 OS << "[ " << Tag << " ]";
1224 if (this->isSubrange()) {
1225 DISubrange(DbgNode).printInternal(OS);
1226 } else if (this->isCompileUnit()) {
1227 DICompileUnit(DbgNode).printInternal(OS);
1228 } else if (this->isFile()) {
1229 DIFile(DbgNode).printInternal(OS);
1230 } else if (this->isEnumerator()) {
1231 DIEnumerator(DbgNode).printInternal(OS);
1232 } else if (this->isBasicType()) {
1233 DIType(DbgNode).printInternal(OS);
1234 } else if (this->isDerivedType()) {
1235 DIDerivedType(DbgNode).printInternal(OS);
1236 } else if (this->isCompositeType()) {
1237 DICompositeType(DbgNode).printInternal(OS);
1238 } else if (this->isSubprogram()) {
1239 DISubprogram(DbgNode).printInternal(OS);
1240 } else if (this->isGlobalVariable()) {
1241 DIGlobalVariable(DbgNode).printInternal(OS);
1242 } else if (this->isVariable()) {
1243 DIVariable(DbgNode).printInternal(OS);
1244 } else if (this->isObjCProperty()) {
1245 DIObjCProperty(DbgNode).printInternal(OS);
1246 } else if (this->isNameSpace()) {
1247 DINameSpace(DbgNode).printInternal(OS);
1248 } else if (this->isScope()) {
1249 DIScope(DbgNode).printInternal(OS);
1250 } else if (this->isExpression()) {
1251 DIExpression(DbgNode).printInternal(OS);
1255 void DISubrange::printInternal(raw_ostream &OS) const {
1256 int64_t Count = getCount();
1258 OS << " [" << getLo() << ", " << Count - 1 << ']';
1260 OS << " [unbounded]";
1263 void DIScope::printInternal(raw_ostream &OS) const {
1264 OS << " [" << getDirectory() << "/" << getFilename() << ']';
1267 void DICompileUnit::printInternal(raw_ostream &OS) const {
1268 DIScope::printInternal(OS);
1270 unsigned Lang = getLanguage();
1271 if (const char *LangStr = dwarf::LanguageString(Lang))
1274 (OS << "lang 0x").write_hex(Lang);
1278 void DIEnumerator::printInternal(raw_ostream &OS) const {
1279 OS << " [" << getName() << " :: " << getEnumValue() << ']';
1282 void DIType::printInternal(raw_ostream &OS) const {
1286 StringRef Res = getName();
1288 OS << " [" << Res << "]";
1290 // TODO: Print context?
1292 OS << " [line " << getLineNumber() << ", size " << getSizeInBits()
1293 << ", align " << getAlignInBits() << ", offset " << getOffsetInBits();
1295 if (const char *Enc =
1296 dwarf::AttributeEncodingString(DIBasicType(DbgNode).getEncoding()))
1297 OS << ", enc " << Enc;
1302 else if (isProtected())
1303 OS << " [protected]";
1304 else if (isPublic())
1308 OS << " [artificial]";
1310 if (isForwardDecl())
1312 else if (getTag() == dwarf::DW_TAG_structure_type ||
1313 getTag() == dwarf::DW_TAG_union_type ||
1314 getTag() == dwarf::DW_TAG_enumeration_type ||
1315 getTag() == dwarf::DW_TAG_class_type)
1319 if (isStaticMember())
1322 if (isLValueReference())
1323 OS << " [reference]";
1325 if (isRValueReference())
1326 OS << " [rvalue reference]";
1329 void DIDerivedType::printInternal(raw_ostream &OS) const {
1330 DIType::printInternal(OS);
1331 OS << " [from " << getTypeDerivedFrom().getName() << ']';
1334 void DICompositeType::printInternal(raw_ostream &OS) const {
1335 DIType::printInternal(OS);
1336 DIArray A = getElements();
1337 OS << " [" << A.getNumElements() << " elements]";
1340 void DINameSpace::printInternal(raw_ostream &OS) const {
1341 StringRef Name = getName();
1343 OS << " [" << Name << ']';
1345 OS << " [line " << getLineNumber() << ']';
1348 void DISubprogram::printInternal(raw_ostream &OS) const {
1349 // TODO : Print context
1350 OS << " [line " << getLineNumber() << ']';
1352 if (isLocalToUnit())
1358 if (getScopeLineNumber() != getLineNumber())
1359 OS << " [scope " << getScopeLineNumber() << "]";
1363 else if (isProtected())
1364 OS << " [protected]";
1365 else if (isPublic())
1368 if (isLValueReference())
1369 OS << " [reference]";
1371 if (isRValueReference())
1372 OS << " [rvalue reference]";
1374 StringRef Res = getName();
1376 OS << " [" << Res << ']';
1379 void DIGlobalVariable::printInternal(raw_ostream &OS) const {
1380 StringRef Res = getName();
1382 OS << " [" << Res << ']';
1384 OS << " [line " << getLineNumber() << ']';
1386 // TODO : Print context
1388 if (isLocalToUnit())
1395 void DIVariable::printInternal(raw_ostream &OS) const {
1396 StringRef Res = getName();
1398 OS << " [" << Res << ']';
1400 OS << " [line " << getLineNumber() << ']';
1403 void DIExpression::printInternal(raw_ostream &OS) const {
1404 for (unsigned I = 0; I < getNumElements(); ++I) {
1405 uint64_t OpCode = getElement(I);
1406 OS << " [" << OperationEncodingString(OpCode);
1409 OS << " " << getElement(++I);
1413 unsigned Offset = getElement(++I);
1414 unsigned Size = getElement(++I);
1415 OS << " offset=" << Offset << ", size=" << Size;
1419 // Else bail out early. This may be a line table entry.
1427 void DIObjCProperty::printInternal(raw_ostream &OS) const {
1428 StringRef Name = getObjCPropertyName();
1430 OS << " [" << Name << ']';
1432 OS << " [line " << getLineNumber() << ", properties " << getUnsignedField(6)
1436 static void printDebugLoc(DebugLoc DL, raw_ostream &CommentOS,
1437 const LLVMContext &Ctx) {
1438 if (!DL.isUnknown()) { // Print source line info.
1439 DIScope Scope(DL.getScope(Ctx));
1440 assert(Scope.isScope() && "Scope of a DebugLoc should be a DIScope.");
1441 // Omit the directory, because it's likely to be long and uninteresting.
1442 CommentOS << Scope.getFilename();
1443 CommentOS << ':' << DL.getLine();
1444 if (DL.getCol() != 0)
1445 CommentOS << ':' << DL.getCol();
1446 DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(DL.getInlinedAt(Ctx));
1447 if (!InlinedAtDL.isUnknown()) {
1448 CommentOS << " @[ ";
1449 printDebugLoc(InlinedAtDL, CommentOS, Ctx);
1455 void DIVariable::printExtendedName(raw_ostream &OS) const {
1456 const LLVMContext &Ctx = DbgNode->getContext();
1457 StringRef Res = getName();
1459 OS << Res << "," << getLineNumber();
1460 if (MDNode *InlinedAt = getInlinedAt()) {
1461 DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(InlinedAt);
1462 if (!InlinedAtDL.isUnknown()) {
1464 printDebugLoc(InlinedAtDL, OS, Ctx);
1470 template <> DIRef<DIScope>::DIRef(const Metadata *V) : Val(V) {
1471 assert(isScopeRef(V) && "DIScopeRef should be a MDString or MDNode");
1473 template <> DIRef<DIType>::DIRef(const Metadata *V) : Val(V) {
1474 assert(isTypeRef(V) && "DITypeRef should be a MDString or MDNode");
1478 DIScopeRef DIDescriptor::getFieldAs<DIScopeRef>(unsigned Elt) const {
1479 return DIScopeRef(cast_or_null<Metadata>(getField(DbgNode, Elt)));
1481 template <> DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const {
1482 return DITypeRef(cast_or_null<Metadata>(getField(DbgNode, Elt)));
1485 bool llvm::StripDebugInfo(Module &M) {
1486 bool Changed = false;
1488 // Remove all of the calls to the debugger intrinsics, and remove them from
1490 if (Function *Declare = M.getFunction("llvm.dbg.declare")) {
1491 while (!Declare->use_empty()) {
1492 CallInst *CI = cast<CallInst>(Declare->user_back());
1493 CI->eraseFromParent();
1495 Declare->eraseFromParent();
1499 if (Function *DbgVal = M.getFunction("llvm.dbg.value")) {
1500 while (!DbgVal->use_empty()) {
1501 CallInst *CI = cast<CallInst>(DbgVal->user_back());
1502 CI->eraseFromParent();
1504 DbgVal->eraseFromParent();
1508 for (Module::named_metadata_iterator NMI = M.named_metadata_begin(),
1509 NME = M.named_metadata_end(); NMI != NME;) {
1510 NamedMDNode *NMD = NMI;
1512 if (NMD->getName().startswith("llvm.dbg.")) {
1513 NMD->eraseFromParent();
1518 for (Module::iterator MI = M.begin(), ME = M.end(); MI != ME; ++MI)
1519 for (Function::iterator FI = MI->begin(), FE = MI->end(); FI != FE;
1521 for (BasicBlock::iterator BI = FI->begin(), BE = FI->end(); BI != BE;
1523 if (!BI->getDebugLoc().isUnknown()) {
1525 BI->setDebugLoc(DebugLoc());
1532 unsigned llvm::getDebugMetadataVersionFromModule(const Module &M) {
1533 Value *Val = M.getModuleFlag("Debug Info Version");
1536 return cast<ConstantInt>(Val)->getZExtValue();
1539 llvm::DenseMap<const llvm::Function *, llvm::DISubprogram>
1540 llvm::makeSubprogramMap(const Module &M) {
1541 DenseMap<const Function *, DISubprogram> R;
1543 NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu");
1547 for (MDNode *N : CU_Nodes->operands()) {
1548 DICompileUnit CUNode(N);
1549 DIArray SPs = CUNode.getSubprograms();
1550 for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
1551 DISubprogram SP(SPs.getElement(i));
1552 if (Function *F = SP.getFunction())
1553 R.insert(std::make_pair(F, SP));