llvm.org GIT mirror llvm / dd6f70d
[DebugInfo] Delete TypedDINodeRef TypedDINodeRef<T> is a redundant wrapper of Metadata * that is actually a T *. Accordingly, change DI{Node,Scope,Type}Ref uses to DI{Node,Scope,Type} * or their const variants. This allows us to delete many resolve() calls that clutter the code. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D61369 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360108 91177308-0d34-0410-b5e6-96231b3b80d8 Fangrui Song 3 months ago
16 changed file(s) with 169 addition(s) and 247 deletion(s). Raw diff Collapse all Expand all
128128 const MCExpr *getFunctionLocalOffsetAfterInsn(const MachineInstr *MI);
129129
130130 /// If this type is derived from a base type then return base type size.
131 static uint64_t getBaseTypeSize(const DITypeRef TyRef);
131 static uint64_t getBaseTypeSize(const DIType *Ty);
132132 };
133133
134134 }
5959
6060 namespace llvm {
6161
62 /// Holds a subclass of DINode.
63 ///
64 /// FIXME: This class doesn't currently make much sense. Previously it was a
65 /// union beteen MDString (for ODR-uniqued types) and things like DIType. To
66 /// support CodeView work, it wasn't deleted outright when MDString-based type
67 /// references were deleted; we'll soon need a similar concept for CodeView
68 /// DITypeIndex.
69 template class TypedDINodeRef {
70 const Metadata *MD = nullptr;
71
72 public:
73 TypedDINodeRef() = default;
74 TypedDINodeRef(std::nullptr_t) {}
75 TypedDINodeRef(const T *MD) : MD(MD) {}
76
77 explicit TypedDINodeRef(const Metadata *MD) : MD(MD) {
78 assert((!MD || isa(MD)) && "Expected valid type ref");
79 }
80
81 template
82 TypedDINodeRef(
83 const TypedDINodeRef &X,
84 typename std::enable_if::value>::type * =
85 nullptr)
86 : MD(X) {}
87
88 operator Metadata *() const { return const_cast(MD); }
89
90 T *resolve() const { return const_cast(cast_or_null(MD)); }
91
92 bool operator==(const TypedDINodeRef &X) const { return MD == X.MD; }
93 bool operator!=(const TypedDINodeRef &X) const { return MD != X.MD; }
94 };
95
96 using DINodeRef = TypedDINodeRef;
97 using DIScopeRef = TypedDINodeRef;
98 using DITypeRef = TypedDINodeRef;
99
10062 class DITypeRefArray {
10163 const MDTuple *N = nullptr;
10264
11375
11476 // FIXME: Fix callers and remove condition on N.
11577 unsigned size() const { return N ? N->getNumOperands() : 0u; }
116 DITypeRef operator[](unsigned I) const { return DITypeRef(N->getOperand(I)); }
117
118 class iterator : std::iterator
119 std::ptrdiff_t, void, DITypeRef> {
78 DIType *operator[](unsigned I) const {
79 return cast_or_null(N->getOperand(I));
80 }
81
82 class iterator : std::iterator
83 std::ptrdiff_t, void, DIType *> {
12084 MDNode::op_iterator I = nullptr;
12185
12286 public:
12387 iterator() = default;
12488 explicit iterator(MDNode::op_iterator I) : I(I) {}
12589
126 DITypeRef operator*() const { return DITypeRef(*I); }
90 DIType *operator*() const { return cast_or_null(*I); }
12791
12892 iterator &operator++() {
12993 ++I;
240204 }
241205 };
242206
243 template struct simplify_type> {
244 using SimpleType = Metadata *;
245
246 static SimpleType getSimplifiedValue(const TypedDINodeRef &MD) {
247 return MD;
248 }
249 };
250
251 template
252 struct simplify_type>
253 : simplify_type> {};
254
255207 /// Generic tagged DWARF-like metadata node.
256208 ///
257209 /// An un-specialized DWARF-like metadata node. The first operand is a
458410 inline Optional getSource() const;
459411
460412 StringRef getName() const;
461 DIScopeRef getScope() const;
413 DIScope *getScope() const;
462414
463415 /// Return the raw underlying file.
464416 ///
672624 uint64_t getOffsetInBits() const { return OffsetInBits; }
673625 DIFlags getFlags() const { return Flags; }
674626
675 DIScopeRef getScope() const { return DIScopeRef(getRawScope()); }
627 DIScope *getScope() const { return cast_or_null(getRawScope()); }
676628 StringRef getName() const { return getStringOperand(2); }
677629
678630
817769 DWARFAddressSpace(DWARFAddressSpace) {}
818770 ~DIDerivedType() = default;
819771
820 static DIDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
821 StringRef Name, DIFile *File, unsigned Line,
822 DIScopeRef Scope, DITypeRef BaseType,
823 uint64_t SizeInBits, uint32_t AlignInBits,
824 uint64_t OffsetInBits,
825 Optional DWARFAddressSpace,
826 DIFlags Flags, Metadata *ExtraData,
827 StorageType Storage, bool ShouldCreate = true) {
772 static DIDerivedType *
773 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
774 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
775 uint32_t AlignInBits, uint64_t OffsetInBits,
776 Optional DWARFAddressSpace, DIFlags Flags,
777 Metadata *ExtraData, StorageType Storage, bool ShouldCreate = true) {
828778 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
829779 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
830780 DWARFAddressSpace, Flags, ExtraData, Storage, ShouldCreate);
858808 ExtraData))
859809 DEFINE_MDNODE_GET(DIDerivedType,
860810 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
861 DIScopeRef Scope, DITypeRef BaseType, uint64_t SizeInBits,
811 DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
862812 uint32_t AlignInBits, uint64_t OffsetInBits,
863813 Optional DWARFAddressSpace, DIFlags Flags,
864814 Metadata *ExtraData = nullptr),
869819 TempDIDerivedType clone() const { return cloneImpl(); }
870820
871821 /// Get the base type this is derived from.
872 DITypeRef getBaseType() const { return DITypeRef(getRawBaseType()); }
822 DIType *getBaseType() const { return cast_or_null(getRawBaseType()); }
873823 Metadata *getRawBaseType() const { return getOperand(3); }
874824
875825 /// \returns The DWARF address space of the memory pointed to or referenced by
889839
890840 /// Get casted version of extra data.
891841 /// @{
892 DITypeRef getClassType() const {
842 DIType *getClassType() const {
893843 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
894 return DITypeRef(getExtraData());
844 return cast_or_null(getExtraData());
895845 }
896846
897847 DIObjCProperty *getObjCProperty() const {
963913
964914 static DICompositeType *
965915 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
966 unsigned Line, DIScopeRef Scope, DITypeRef BaseType,
967 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
968 DIFlags Flags, DINodeArray Elements, unsigned RuntimeLang,
969 DITypeRef VTableHolder, DITemplateParameterArray TemplateParams,
970 StringRef Identifier, DIDerivedType *Discriminator,
971 StorageType Storage, bool ShouldCreate = true) {
916 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
917 uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
918 DINodeArray Elements, unsigned RuntimeLang, DIType *VTableHolder,
919 DITemplateParameterArray TemplateParams, StringRef Identifier,
920 DIDerivedType *Discriminator, StorageType Storage,
921 bool ShouldCreate = true) {
972922 return getImpl(
973923 Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope,
974924 BaseType, SizeInBits, AlignInBits, OffsetInBits, Flags, Elements.get(),
995945 public:
996946 DEFINE_MDNODE_GET(DICompositeType,
997947 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
998 DIScopeRef Scope, DITypeRef BaseType, uint64_t SizeInBits,
999 uint32_t AlignInBits, uint64_t OffsetInBits,
1000 DIFlags Flags, DINodeArray Elements, unsigned RuntimeLang,
1001 DITypeRef VTableHolder,
948 DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
949 uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
950 DINodeArray Elements, unsigned RuntimeLang,
951 DIType *VTableHolder,
1002952 DITemplateParameterArray TemplateParams = nullptr,
1003 StringRef Identifier = "", DIDerivedType *Discriminator = nullptr),
953 StringRef Identifier = "",
954 DIDerivedType *Discriminator = nullptr),
1004955 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
1005956 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
1006957 VTableHolder, TemplateParams, Identifier, Discriminator))
10531004 unsigned RuntimeLang, Metadata *VTableHolder,
10541005 Metadata *TemplateParams, Metadata *Discriminator);
10551006
1056 DITypeRef getBaseType() const { return DITypeRef(getRawBaseType()); }
1007 DIType *getBaseType() const { return cast_or_null(getRawBaseType()); }
10571008 DINodeArray getElements() const {
10581009 return cast_or_null(getRawElements());
10591010 }
1060 DITypeRef getVTableHolder() const { return DITypeRef(getRawVTableHolder()); }
1011 DIType *getVTableHolder() const {
1012 return cast_or_null(getRawVTableHolder());
1013 }
10611014 DITemplateParameterArray getTemplateParams() const {
10621015 return cast_or_null(getRawTemplateParams());
10631016 }
10871040 replaceOperandWith(4, Elements.get());
10881041 }
10891042
1090 void replaceVTableHolder(DITypeRef VTableHolder) {
1043 void replaceVTableHolder(DIType *VTableHolder) {
10911044 replaceOperandWith(5, VTableHolder);
10921045 }
10931046
17041657 ~DISubprogram() = default;
17051658
17061659 static DISubprogram *
1707 getImpl(LLVMContext &Context, DIScopeRef Scope, StringRef Name,
1660 getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
17081661 StringRef LinkageName, DIFile *File, unsigned Line,
1709 DISubroutineType *Type, unsigned ScopeLine, DITypeRef ContainingType,
1662 DISubroutineType *Type, unsigned ScopeLine, DIType *ContainingType,
17101663 unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags,
17111664 DISPFlags SPFlags, DICompileUnit *Unit,
17121665 DITemplateParameterArray TemplateParams, DISubprogram *Declaration,
17411694 public:
17421695 DEFINE_MDNODE_GET(
17431696 DISubprogram,
1744 (DIScopeRef Scope, StringRef Name, StringRef LinkageName, DIFile *File,
1697 (DIScope * Scope, StringRef Name, StringRef LinkageName, DIFile *File,
17451698 unsigned Line, DISubroutineType *Type, unsigned ScopeLine,
1746 DITypeRef ContainingType, unsigned VirtualIndex, int ThisAdjustment,
1699 DIType *ContainingType, unsigned VirtualIndex, int ThisAdjustment,
17471700 DIFlags Flags, DISPFlags SPFlags, DICompileUnit *Unit,
17481701 DITemplateParameterArray TemplateParams = nullptr,
17491702 DISubprogram *Declaration = nullptr, DINodeArray RetainedNodes = nullptr,
18271780 // Returns true if this subprogram is a thunk generated by the compiler.
18281781 bool isThunk() const { return getFlags() & FlagThunk; }
18291782
1830 DIScopeRef getScope() const { return DIScopeRef(getRawScope()); }
1783 DIScope *getScope() const { return cast_or_null(getRawScope()); }
18311784
18321785 StringRef getName() const { return getStringOperand(2); }
18331786 StringRef getLinkageName() const { return getStringOperand(3); }
18351788 DISubroutineType *getType() const {
18361789 return cast_or_null(getRawType());
18371790 }
1838 DITypeRef getContainingType() const {
1839 return DITypeRef(getRawContainingType());
1791 DIType *getContainingType() const {
1792 return cast_or_null(getRawContainingType());
18401793 }
18411794
18421795 DICompileUnit *getUnit() const {
21812134
21822135 public:
21832136 StringRef getName() const { return getStringOperand(0); }
2184 DITypeRef getType() const { return DITypeRef(getRawType()); }
2137 DIType *getType() const { return cast_or_null(getRawType()); }
21852138
21862139 MDString *getRawName() const { return getOperandAs(0); }
21872140 Metadata *getRawType() const { return getOperand(1); }
22032156 ~DITemplateTypeParameter() = default;
22042157
22052158 static DITemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
2206 DITypeRef Type, StorageType Storage,
2159 DIType *Type, StorageType Storage,
22072160 bool ShouldCreate = true) {
22082161 return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
22092162 ShouldCreate);
22172170 }
22182171
22192172 public:
2220 DEFINE_MDNODE_GET(DITemplateTypeParameter, (StringRef Name, DITypeRef Type),
2173 DEFINE_MDNODE_GET(DITemplateTypeParameter, (StringRef Name, DIType *Type),
22212174 (Name, Type))
22222175 DEFINE_MDNODE_GET(DITemplateTypeParameter, (MDString * Name, Metadata *Type),
22232176 (Name, Type))
22402193 ~DITemplateValueParameter() = default;
22412194
22422195 static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
2243 StringRef Name, DITypeRef Type,
2196 StringRef Name, DIType *Type,
22442197 Metadata *Value, StorageType Storage,
22452198 bool ShouldCreate = true) {
22462199 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
22572210 }
22582211
22592212 public:
2260 DEFINE_MDNODE_GET(DITemplateValueParameter, (unsigned Tag, StringRef Name,
2261 DITypeRef Type, Metadata *Value),
2213 DEFINE_MDNODE_GET(DITemplateValueParameter,
2214 (unsigned Tag, StringRef Name, DIType *Type,
2215 Metadata *Value),
22622216 (Tag, Name, Type, Value))
22632217 DEFINE_MDNODE_GET(DITemplateValueParameter, (unsigned Tag, MDString *Name,
22642218 Metadata *Type, Metadata *Value),
22902244 DIScope *getScope() const { return cast_or_null(getRawScope()); }
22912245 StringRef getName() const { return getStringOperand(1); }
22922246 DIFile *getFile() const { return cast_or_null(getRawFile()); }
2293 DITypeRef getType() const { return DITypeRef(getRawType()); }
2247 DIType *getType() const { return cast_or_null(getRawType()); }
22942248 uint32_t getAlignInBits() const { return AlignInBits; }
22952249 uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
22962250 /// Determines the size of the variable's type.
22992253 /// Return the signedness of this variable's type, or None if this type is
23002254 /// neither signed nor unsigned.
23012255 Optional getSignedness() const {
2302 if (auto *BT = dyn_cast(getType().resolve()))
2256 if (auto *BT = dyn_cast(getType()))
23032257 return BT->getSignedness();
23042258 return None;
23052259 }
26102564
26112565 static DIGlobalVariable *
26122566 getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
2613 StringRef LinkageName, DIFile *File, unsigned Line, DITypeRef Type,
2567 StringRef LinkageName, DIFile *File, unsigned Line, DIType *Type,
26142568 bool IsLocalToUnit, bool IsDefinition,
26152569 DIDerivedType *StaticDataMemberDeclaration, MDTuple *TemplateParams,
26162570 uint32_t AlignInBits, StorageType Storage, bool ShouldCreate = true) {
26372591 public:
26382592 DEFINE_MDNODE_GET(DIGlobalVariable,
26392593 (DIScope * Scope, StringRef Name, StringRef LinkageName,
2640 DIFile *File, unsigned Line, DITypeRef Type,
2594 DIFile *File, unsigned Line, DIType *Type,
26412595 bool IsLocalToUnit, bool IsDefinition,
26422596 DIDerivedType *StaticDataMemberDeclaration,
26432597 MDTuple *TemplateParams, uint32_t AlignInBits),
27542708
27552709 static DILocalVariable *getImpl(LLVMContext &Context, DIScope *Scope,
27562710 StringRef Name, DIFile *File, unsigned Line,
2757 DITypeRef Type, unsigned Arg, DIFlags Flags,
2711 DIType *Type, unsigned Arg, DIFlags Flags,
27582712 uint32_t AlignInBits, StorageType Storage,
27592713 bool ShouldCreate = true) {
27602714 return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
27752729 public:
27762730 DEFINE_MDNODE_GET(DILocalVariable,
27772731 (DILocalScope * Scope, StringRef Name, DIFile *File,
2778 unsigned Line, DITypeRef Type, unsigned Arg,
2779 DIFlags Flags, uint32_t AlignInBits),
2732 unsigned Line, DIType *Type, unsigned Arg, DIFlags Flags,
2733 uint32_t AlignInBits),
27802734 (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits))
27812735 DEFINE_MDNODE_GET(DILocalVariable,
27822736 (Metadata * Scope, MDString *Name, Metadata *File,
29012855 static DIObjCProperty *
29022856 getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
29032857 StringRef GetterName, StringRef SetterName, unsigned Attributes,
2904 DITypeRef Type, StorageType Storage, bool ShouldCreate = true) {
2858 DIType *Type, StorageType Storage, bool ShouldCreate = true) {
29052859 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
29062860 getCanonicalMDString(Context, GetterName),
29072861 getCanonicalMDString(Context, SetterName), Attributes, Type,
29232877 DEFINE_MDNODE_GET(DIObjCProperty,
29242878 (StringRef Name, DIFile *File, unsigned Line,
29252879 StringRef GetterName, StringRef SetterName,
2926 unsigned Attributes, DITypeRef Type),
2880 unsigned Attributes, DIType *Type),
29272881 (Name, File, Line, GetterName, SetterName, Attributes,
29282882 Type))
29292883 DEFINE_MDNODE_GET(DIObjCProperty,
29412895 DIFile *getFile() const { return cast_or_null(getRawFile()); }
29422896 StringRef getGetterName() const { return getStringOperand(2); }
29432897 StringRef getSetterName() const { return getStringOperand(3); }
2944 DITypeRef getType() const { return DITypeRef(getRawType()); }
2898 DIType *getType() const { return cast_or_null(getRawType()); }
29452899
29462900 StringRef getFilename() const {
29472901 if (auto *F = getFile())
29852939 ~DIImportedEntity() = default;
29862940
29872941 static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
2988 DIScope *Scope, DINodeRef Entity,
2989 DIFile *File, unsigned Line, StringRef Name,
2942 DIScope *Scope, DINode *Entity, DIFile *File,
2943 unsigned Line, StringRef Name,
29902944 StorageType Storage,
29912945 bool ShouldCreate = true) {
29922946 return getImpl(Context, Tag, Scope, Entity, File, Line,
30052959
30062960 public:
30072961 DEFINE_MDNODE_GET(DIImportedEntity,
3008 (unsigned Tag, DIScope *Scope, DINodeRef Entity,
3009 DIFile *File, unsigned Line, StringRef Name = ""),
2962 (unsigned Tag, DIScope *Scope, DINode *Entity, DIFile *File,
2963 unsigned Line, StringRef Name = ""),
30102964 (Tag, Scope, Entity, File, Line, Name))
30112965 DEFINE_MDNODE_GET(DIImportedEntity,
30122966 (unsigned Tag, Metadata *Scope, Metadata *Entity,
30172971
30182972 unsigned getLine() const { return Line; }
30192973 DIScope *getScope() const { return cast_or_null(getRawScope()); }
3020 DINodeRef getEntity() const { return DINodeRef(getRawEntity()); }
2974 DINode *getEntity() const { return cast_or_null(getRawEntity()); }
30212975 StringRef getName() const { return getStringOperand(2); }
30222976 DIFile *getFile() const { return cast_or_null(getRawFile()); }
30232977
336336 if (!Tuple || Tuple->isDistinct())
337337 return MaybeTuple;
338338
339 // Look through the DITypeRefArray, upgrading each DITypeRef.
339 // Look through the DITypeRefArray, upgrading each DIType *.
340340 SmallVector Ops;
341341 Ops.reserve(Tuple->getNumOperands());
342342 for (Metadata *MD : Tuple->operands())
271271 StringRef ScopeName = getPrettyScopeName(Scope);
272272 if (!ScopeName.empty())
273273 QualifiedNameComponents.push_back(ScopeName);
274 Scope = Scope->getScope().resolve();
274 Scope = Scope->getScope();
275275 }
276276 return ClosestSubprogram;
277277 }
307307 };
308308
309309 static std::string getFullyQualifiedName(const DIScope *Ty) {
310 const DIScope *Scope = Ty->getScope().resolve();
310 const DIScope *Scope = Ty->getScope();
311311 return getFullyQualifiedName(Scope, getPrettyScopeName(Ty));
312312 }
313313
342342 // MSVC.
343343 StringRef DisplayName = SP->getName().split('<').first;
344344
345 const DIScope *Scope = SP->getScope().resolve();
345 const DIScope *Scope = SP->getScope();
346346 TypeIndex TI;
347347 if (const auto *Class = dyn_cast_or_null(Scope)) {
348348 // If the scope is a DICompositeType, then this must be a method. Member
374374 const DIType *ReturnTy = nullptr;
375375 if (auto TypeArray = Ty->getTypeArray()) {
376376 if (TypeArray.size())
377 ReturnTy = TypeArray[0].resolve();
377 ReturnTy = TypeArray[0];
378378 }
379379
380380 if (auto *ReturnDCTy = dyn_cast_or_null(ReturnTy)) {
973973 // If we have a display name, build the fully qualified name by walking the
974974 // chain of scopes.
975975 if (!SP->getName().empty())
976 FuncName =
977 getFullyQualifiedName(SP->getScope().resolve(), SP->getName());
976 FuncName = getFullyQualifiedName(SP->getScope(), SP->getName());
978977
979978 // If our DISubprogram name is empty, use the mangled name.
980979 if (FuncName.empty())
13971396
13981397 // MSVC does not emit UDTs for typedefs that are scoped to classes.
13991398 if (T->getTag() == dwarf::DW_TAG_typedef) {
1400 if (DIScope *Scope = T->getScope().resolve()) {
1399 if (DIScope *Scope = T->getScope()) {
14011400 switch (Scope->getTag()) {
14021401 case dwarf::DW_TAG_structure_type:
14031402 case dwarf::DW_TAG_class_type:
14141413 const DIDerivedType *DT = dyn_cast(T);
14151414 if (!DT)
14161415 return true;
1417 T = DT->getBaseType().resolve();
1416 T = DT->getBaseType();
14181417 }
14191418 return true;
14201419 }
14271426 return;
14281427
14291428 SmallVector QualifiedNameComponents;
1430 const DISubprogram *ClosestSubprogram = getQualifiedNameComponents(
1431 Ty->getScope().resolve(), QualifiedNameComponents);
1429 const DISubprogram *ClosestSubprogram =
1430 getQualifiedNameComponents(Ty->getScope(), QualifiedNameComponents);
14321431
14331432 std::string FullyQualifiedName =
14341433 getQualifiedName(QualifiedNameComponents, getPrettyScopeName(Ty));
14971496 }
14981497
14991498 TypeIndex CodeViewDebug::lowerTypeAlias(const DIDerivedType *Ty) {
1500 DITypeRef UnderlyingTypeRef = Ty->getBaseType();
1501 TypeIndex UnderlyingTypeIndex = getTypeIndex(UnderlyingTypeRef);
1499 TypeIndex UnderlyingTypeIndex = getTypeIndex(Ty->getBaseType());
15021500 StringRef TypeName = Ty->getName();
15031501
15041502 addToUDTs(Ty);
15141512 }
15151513
15161514 TypeIndex CodeViewDebug::lowerTypeArray(const DICompositeType *Ty) {
1517 DITypeRef ElementTypeRef = Ty->getBaseType();
1518 TypeIndex ElementTypeIndex = getTypeIndex(ElementTypeRef);
1515 const DIType *ElementType = Ty->getBaseType();
1516 TypeIndex ElementTypeIndex = getTypeIndex(ElementType);
15191517 // IndexType is size_t, which depends on the bitness of the target.
15201518 TypeIndex IndexType = getPointerSizeInBytes() == 8
15211519 ? TypeIndex(SimpleTypeKind::UInt64Quad)
15221520 : TypeIndex(SimpleTypeKind::UInt32Long);
15231521
1524 uint64_t ElementSize = getBaseTypeSize(ElementTypeRef) / 8;
1522 uint64_t ElementSize = getBaseTypeSize(ElementType) / 8;
15251523
15261524 // Add subranges to array type.
15271525 DINodeArray Elements = Ty->getElements();
17821780 break;
17831781 }
17841782 if (IsModifier)
1785 BaseTy = cast(BaseTy)->getBaseType().resolve();
1783 BaseTy = cast(BaseTy)->getBaseType();
17861784 }
17871785
17881786 // Check if the inner type will use an LF_POINTER record. If so, the
18151813
18161814 TypeIndex CodeViewDebug::lowerTypeFunction(const DISubroutineType *Ty) {
18171815 SmallVector ReturnAndArgTypeIndices;
1818 for (DITypeRef ArgTypeRef : Ty->getTypeArray())
1819 ReturnAndArgTypeIndices.push_back(getTypeIndex(ArgTypeRef));
1816 for (const DIType *ArgType : Ty->getTypeArray())
1817 ReturnAndArgTypeIndices.push_back(getTypeIndex(ArgType));
18201818
18211819 // MSVC uses type none for variadic argument.
18221820 if (ReturnAndArgTypeIndices.size() > 1 &&
18651863 TypeIndex ThisTypeIndex;
18661864 if (!IsStaticMethod && ReturnAndArgs.size() > Index) {
18671865 if (const DIDerivedType *PtrTy =
1868 dyn_cast_or_null(ReturnAndArgs[Index].resolve())) {
1866 dyn_cast_or_null(ReturnAndArgs[Index])) {
18691867 if (PtrTy->getTag() == dwarf::DW_TAG_pointer_type) {
18701868 ThisTypeIndex = getTypeIndexForThisPtr(PtrTy, Ty);
18711869 Index++;
19631961 // Put the Nested flag on a type if it appears immediately inside a tag type.
19641962 // Do not walk the scope chain. Do not attempt to compute ContainsNestedClass
19651963 // here. That flag is only set on definitions, and not forward declarations.
1966 const DIScope *ImmediateScope = Ty->getScope().resolve();
1964 const DIScope *ImmediateScope = Ty->getScope();
19671965 if (ImmediateScope && isa(ImmediateScope))
19681966 CO |= ClassOptions::Nested;
19691967
19761974 CO |= ClassOptions::Scoped;
19771975 } else {
19781976 for (const DIScope *Scope = ImmediateScope; Scope != nullptr;
1979 Scope = Scope->getScope().resolve()) {
1977 Scope = Scope->getScope()) {
19801978 if (isa(Scope)) {
19811979 CO |= ClassOptions::Scoped;
19821980 break;
20962094 // succeeds, and drop the member if that fails.
20972095 assert((DDTy->getOffsetInBits() % 8) == 0 && "Unnamed bitfield member!");
20982096 uint64_t Offset = DDTy->getOffsetInBits();
2099 const DIType *Ty = DDTy->getBaseType().resolve();
2097 const DIType *Ty = DDTy->getBaseType();
21002098 bool FullyResolved = false;
21012099 while (!FullyResolved) {
21022100 switch (Ty->getTag()) {
21042102 case dwarf::DW_TAG_volatile_type:
21052103 // FIXME: we should apply the qualifier types to the indirect fields
21062104 // rather than dropping them.
2107 Ty = cast(Ty)->getBaseType().resolve();
2105 Ty = cast(Ty)->getBaseType();
21082106 break;
21092107 default:
21102108 FullyResolved = true;
23872385
23882386 // Create nested classes.
23892387 for (const DIType *Nested : Info.NestedTypes) {
2390 NestedTypeRecord R(getTypeIndex(DITypeRef(Nested)), Nested->getName());
2388 NestedTypeRecord R(getTypeIndex(Nested), Nested->getName());
23912389 ContinuationBuilder.writeMemberType(R);
23922390 MemberCount++;
23932391 }
24142412 return VBPType;
24152413 }
24162414
2417 TypeIndex CodeViewDebug::getTypeIndex(DITypeRef TypeRef, DITypeRef ClassTyRef) {
2418 const DIType *Ty = TypeRef.resolve();
2419 const DIType *ClassTy = ClassTyRef.resolve();
2420
2415 TypeIndex CodeViewDebug::getTypeIndex(const DIType *Ty, const DIType *ClassTy) {
24212416 // The null DIType is the void type. Don't try to hash it.
24222417 if (!Ty)
24232418 return TypeIndex::Void();
24602455 return recordTypeIndexForDINode(PtrTy, TI, SubroutineTy);
24612456 }
24622457
2463 TypeIndex CodeViewDebug::getTypeIndexForReferenceTo(DITypeRef TypeRef) {
2464 DIType *Ty = TypeRef.resolve();
2458 TypeIndex CodeViewDebug::getTypeIndexForReferenceTo(const DIType *Ty) {
24652459 PointerRecord PR(getTypeIndex(Ty),
24662460 getPointerSizeInBytes() == 8 ? PointerKind::Near64
24672461 : PointerKind::Near32,
24702464 return TypeTable.writeLeafType(PR);
24712465 }
24722466
2473 TypeIndex CodeViewDebug::getCompleteTypeIndex(DITypeRef TypeRef) {
2474 const DIType *Ty = TypeRef.resolve();
2475
2467 TypeIndex CodeViewDebug::getCompleteTypeIndex(const DIType *Ty) {
24762468 // The null DIType is the void type. Don't try to hash it.
24772469 if (!Ty)
24782470 return TypeIndex::Void();
24832475 if (Ty->getTag() == dwarf::DW_TAG_typedef)
24842476 (void)getTypeIndex(Ty);
24852477 while (Ty->getTag() == dwarf::DW_TAG_typedef)
2486 Ty = cast(Ty)->getBaseType().resolve();
2478 Ty = cast(Ty)->getBaseType();
24872479
24882480 // If this is a non-record type, the complete type index is the same as the
24892481 // normal type index. Just call getTypeIndex.
372372
373373 /// Translates the DIType to codeview if necessary and returns a type index
374374 /// for it.
375 codeview::TypeIndex getTypeIndex(DITypeRef TypeRef,
376 DITypeRef ClassTyRef = DITypeRef());
375 codeview::TypeIndex getTypeIndex(const DIType *Ty,
376 const DIType *ClassTy = nullptr);
377377
378378 codeview::TypeIndex
379379 getTypeIndexForThisPtr(const DIDerivedType *PtrTy,
380380 const DISubroutineType *SubroutineTy);
381381
382 codeview::TypeIndex getTypeIndexForReferenceTo(DITypeRef TypeRef);
382 codeview::TypeIndex getTypeIndexForReferenceTo(const DIType *Ty);
383383
384384 codeview::TypeIndex getMemberFunctionType(const DISubprogram *SP,
385385 const DICompositeType *Class);
418418 /// use this entry point when generating symbol records. The complete and
419419 /// incomplete type indices only differ for record types. All other types use
420420 /// the same index.
421 codeview::TypeIndex getCompleteTypeIndex(DITypeRef TypeRef);
421 codeview::TypeIndex getCompleteTypeIndex(const DIType *Ty);
422422
423423 codeview::TypeIndex lowerCompleteTypeClass(const DICompositeType *Ty);
424424 codeview::TypeIndex lowerCompleteTypeUnion(const DICompositeType *Ty);
139139 }
140140
141141 /// If this type is derived from a base type then return base type size.
142 uint64_t DebugHandlerBase::getBaseTypeSize(const DITypeRef TyRef) {
143 DIType *Ty = TyRef.resolve();
142 uint64_t DebugHandlerBase::getBaseTypeSize(const DIType *Ty) {
144143 assert(Ty);
145 DIDerivedType *DDTy = dyn_cast(Ty);
144 const DIDerivedType *DDTy = dyn_cast(Ty);
146145 if (!DDTy)
147146 return Ty->getSizeInBits();
148147
153152 Tag != dwarf::DW_TAG_restrict_type && Tag != dwarf::DW_TAG_atomic_type)
154153 return DDTy->getSizeInBits();
155154
156 DIType *BaseType = DDTy->getBaseType().resolve();
155 DIType *BaseType = DDTy->getBaseType();
157156
158157 if (!BaseType)
159158 return 0;
118118 assert(GV);
119119
120120 auto *GVContext = GV->getScope();
121 auto *GTy = DD->resolve(GV->getType());
121 const DIType *GTy = GV->getType();
122122
123123 // Construct the context before querying for the existence of the DIE in
124124 // case such construction creates the DIE.
130130 DIE *VariableDIE = &createAndAddDIE(GV->getTag(), *ContextDIE, GV);
131131 DIScope *DeclContext;
132132 if (auto *SDMDecl = GV->getStaticDataMemberDeclaration()) {
133 DeclContext = resolve(SDMDecl->getScope());
133 DeclContext = SDMDecl->getScope();
134134 assert(SDMDecl->isStaticMember() && "Expected static member decl");
135135 assert(GV->isDefinition());
136136 // We need the declaration DIE that is in the static member's class.
138138 addDIEEntry(*VariableDIE, dwarf::DW_AT_specification, *VariableSpecDIE);
139139 // If the global variable's type is different from the one in the class
140140 // member type, assume that it's more specific and also emit it.
141 if (GTy != DD->resolve(SDMDecl->getBaseType()))
141 if (GTy != SDMDecl->getBaseType())
142142 addType(*VariableDIE, GTy);
143143 } else {
144144 DeclContext = GV->getScope();
877877 ContextDIE = &getUnitDie();
878878 getOrCreateSubprogramDIE(SPDecl);
879879 } else {
880 ContextDIE = getOrCreateContextDIE(resolve(SP->getScope()));
880 ContextDIE = getOrCreateContextDIE(SP->getScope());
881881 // The scope may be shared with a subprogram that has already been
882882 // constructed in another CU, in which case we need to construct this
883883 // subprogram in the same CU.
926926 DIE *IMDie = DIE::get(DIEValueAllocator, (dwarf::Tag)Module->getTag());
927927 insertDIE(Module, IMDie);
928928 DIE *EntityDie;
929 auto *Entity = resolve(Module->getEntity());
929 auto *Entity = Module->getEntity();
930930 if (auto *NS = dyn_cast(Entity))
931931 EntityDie = getOrCreateNameSpace(NS);
932932 else if (auto *M = dyn_cast(Entity))
11911191 void DwarfCompileUnit::applySubprogramAttributesToDefinition(
11921192 const DISubprogram *SP, DIE &SPDie) {
11931193 auto *SPDecl = SP->getDeclaration();
1194 auto *Context = resolve(SPDecl ? SPDecl->getScope() : SP->getScope());
1194 auto *Context = SPDecl ? SPDecl->getScope() : SP->getScope();
11951195 applySubprogramAttributes(SP, SPDie, includeMinimalInlineScopes());
11961196 addGlobalName(SP->getName(), SPDie, Context);
11971197 }
195195
196196 bool DbgVariable::isBlockByrefVariable() const {
197197 assert(getVariable() && "Invalid complex DbgVariable!");
198 return getVariable()->getType().resolve()->isBlockByrefStruct();
198 return getVariable()->getType()->isBlockByrefStruct();
199199 }
200200
201201 const DIType *DbgVariable::getType() const {
202 DIType *Ty = getVariable()->getType().resolve();
202 DIType *Ty = getVariable()->getType();
203203 // FIXME: isBlockByrefVariable should be reformulated in terms of complex
204204 // addresses instead.
205205 if (Ty->isBlockByrefStruct()) {
231231 uint16_t tag = Ty->getTag();
232232
233233 if (tag == dwarf::DW_TAG_pointer_type)
234 subType = resolve(cast(Ty)->getBaseType());
234 subType = cast(Ty)->getBaseType();
235235
236236 auto Elements = cast(subType)->getElements();
237237 for (unsigned i = 0, N = Elements.size(); i < N; ++i) {
238238 auto *DT = cast(Elements[i]);
239239 if (getName() == DT->getName())
240 return resolve(DT->getBaseType());
240 return DT->getBaseType();
241241 }
242242 }
243243 return Ty;
217217 static bool classof(const DbgEntity *N) {
218218 return N->getDbgEntityID() == DbgVariableKind;
219219 }
220
221 private:
222 template T *resolve(TypedDINodeRef Ref) const {
223 return Ref.resolve();
224 }
225220 };
226221
227222 //===----------------------------------------------------------------------===//
251246
252247 static bool classof(const DbgEntity *N) {
253248 return N->getDbgEntityID() == DbgLabelKind;
254 }
255
256 private:
257 template T *resolve(TypedDINodeRef Ref) const {
258 return Ref.resolve();
259249 }
260250 };
261251
701691 void emitDebugLocEntryLocation(const DebugLocStream::Entry &Entry,
702692 const DwarfCompileUnit *CU);
703693
704 /// Find the MDNode for the given reference.
705 template T *resolve(TypedDINodeRef Ref) const {
706 return Ref.resolve();
707 }
708
709694 void addSubprogramNames(const DICompileUnit &CU, const DISubprogram *SP,
710695 DIE &Die);
711696
470470 assert(T == dwarf::DW_TAG_typedef || T == dwarf::DW_TAG_const_type ||
471471 T == dwarf::DW_TAG_volatile_type ||
472472 T == dwarf::DW_TAG_restrict_type || T == dwarf::DW_TAG_atomic_type);
473 DITypeRef Deriv = DTy->getBaseType();
474 assert(Deriv && "Expected valid base type");
475 return isUnsignedDIType(DD, DD->resolve(Deriv));
473 assert(DTy->getBaseType() && "Expected valid base type");
474 return isUnsignedDIType(DD, DTy->getBaseType());
476475 }
477476
478477 auto *BTy = cast(Ty);
612611 }
613612
614613 DIE *DwarfUnit::createTypeDIE(const DICompositeType *Ty) {
615 auto *Context = resolve(Ty->getScope());
614 auto *Context = Ty->getScope();
616615 DIE *ContextDIE = getOrCreateContextDIE(Context);
617616
618617 if (DIE *TyDIE = getDIE(Ty))
665664
666665 // DW_TAG_restrict_type is not supported in DWARF2
667666 if (Ty->getTag() == dwarf::DW_TAG_restrict_type && DD->getDwarfVersion() <= 2)
668 return getOrCreateTypeDIE(resolve(cast(Ty)->getBaseType()));
667 return getOrCreateTypeDIE(cast(Ty)->getBaseType());
669668
670669 // DW_TAG_atomic_type is not supported in DWARF < 5
671670 if (Ty->getTag() == dwarf::DW_TAG_atomic_type && DD->getDwarfVersion() < 5)
672 return getOrCreateTypeDIE(resolve(cast(Ty)->getBaseType()));
671 return getOrCreateTypeDIE(cast(Ty)->getBaseType());
673672
674673 // Construct the context before querying for the existence of the DIE in case
675674 // such construction creates the DIE.
676 auto *Context = resolve(Ty->getScope());
675 auto *Context = Ty->getScope();
677676 DIE *ContextDIE = getOrCreateContextDIE(Context);
678677 assert(ContextDIE);
679678
720719 SmallVector Parents;
721720 while (!isa(Context)) {
722721 Parents.push_back(Context);
723 if (Context->getScope())
724 Context = resolve(Context->getScope());
722 if (const DIScope *S = Context->getScope())
723 Context = S;
725724 else
726725 // Structure, etc types will have a NULL context if they're at the top
727726 // level.
772771 uint16_t Tag = Buffer.getTag();
773772
774773 // Map to main type, void will not have a type.
775 const DIType *FromTy = resolve(DTy->getBaseType());
774 const DIType *FromTy = DTy->getBaseType();
776775 if (FromTy)
777776 addType(Buffer, FromTy);
778777
788787 addUInt(Buffer, dwarf::DW_AT_byte_size, None, Size);
789788
790789 if (Tag == dwarf::DW_TAG_ptr_to_member_type)
791 addDIEEntry(
792 Buffer, dwarf::DW_AT_containing_type,
793 *getOrCreateTypeDIE(resolve(cast(DTy)->getClassType())));
790 addDIEEntry(Buffer, dwarf::DW_AT_containing_type,
791 *getOrCreateTypeDIE(cast(DTy)->getClassType()));
794792 // Add source line info if available and TyDesc is not a forward declaration.
795793 if (!DTy->isForwardDecl())
796794 addSourceLine(Buffer, DTy);
805803
806804 void DwarfUnit::constructSubprogramArguments(DIE &Buffer, DITypeRefArray Args) {
807805 for (unsigned i = 1, N = Args.size(); i < N; ++i) {
808 const DIType *Ty = resolve(Args[i]);
806 const DIType *Ty = Args[i];
809807 if (!Ty) {
810808 assert(i == N-1 && "Unspecified parameter must be the last argument");
811809 createAndAddDIE(dwarf::DW_TAG_unspecified_parameters, Buffer);
822820 // Add return type. A void return won't have a type.
823821 auto Elements = cast(CTy)->getTypeArray();
824822 if (Elements.size())
825 if (auto RTy = resolve(Elements[0]))
823 if (auto RTy = Elements[0])
826824 addType(Buffer, RTy);
827825
828826 bool isPrototyped = true;
893891 else if (auto *DDTy = dyn_cast(Element)) {
894892 if (DDTy->getTag() == dwarf::DW_TAG_friend) {
895893 DIE &ElemDie = createAndAddDIE(dwarf::DW_TAG_friend, Buffer);
896 addType(ElemDie, resolve(DDTy->getBaseType()), dwarf::DW_AT_friend);
894 addType(ElemDie, DDTy->getBaseType(), dwarf::DW_AT_friend);
897895 } else if (DDTy->isStaticMember()) {
898896 getOrCreateStaticMemberDIE(DDTy);
899897 } else if (Tag == dwarf::DW_TAG_variant_part) {
902900 DIE &Variant = createAndAddDIE(dwarf::DW_TAG_variant, Buffer);
903901 if (const ConstantInt *CI =
904902 dyn_cast_or_null(DDTy->getDiscriminantValue())) {
905 if (isUnsignedDIType(DD, resolve(Discriminator->getBaseType())))
903 if (isUnsignedDIType(DD, Discriminator->getBaseType()))
906904 addUInt(Variant, dwarf::DW_AT_discr_value, None, CI->getZExtValue());
907905 else
908906 addSInt(Variant, dwarf::DW_AT_discr_value, None, CI->getSExtValue());
916914 StringRef PropertyName = Property->getName();
917915 addString(ElemDie, dwarf::DW_AT_APPLE_property_name, PropertyName);
918916 if (Property->getType())
919 addType(ElemDie, resolve(Property->getType()));
917 addType(ElemDie, Property->getType());
920918 addSourceLine(ElemDie, Property);
921919 StringRef GetterName = Property->getGetterName();
922920 if (!GetterName.empty())
942940 // inside C++ composite types to point to the base class with the vtable.
943941 // Rust uses DW_AT_containing_type to link a vtable to the type
944942 // for which it was created.
945 if (auto *ContainingType = resolve(CTy->getVTableHolder()))
943 if (auto *ContainingType = CTy->getVTableHolder())
946944 addDIEEntry(Buffer, dwarf::DW_AT_containing_type,
947945 *getOrCreateTypeDIE(ContainingType));
948946
10121010 createAndAddDIE(dwarf::DW_TAG_template_type_parameter, Buffer);
10131011 // Add the type if it exists, it could be void and therefore no type.
10141012 if (TP->getType())
1015 addType(ParamDIE, resolve(TP->getType()));
1013 addType(ParamDIE, TP->getType());
10161014 if (!TP->getName().empty())
10171015 addString(ParamDIE, dwarf::DW_AT_name, TP->getName());
10181016 }
10241022 // Add the type if there is one, template template and template parameter
10251023 // packs will not have a type.
10261024 if (VP->getTag() == dwarf::DW_TAG_template_value_parameter)
1027 addType(ParamDIE, resolve(VP->getType()));
1025 addType(ParamDIE, VP->getType());
10281026 if (!VP->getName().empty())
10291027 addString(ParamDIE, dwarf::DW_AT_name, VP->getName());
10301028 if (Metadata *Val = VP->getValue()) {
10311029 if (ConstantInt *CI = mdconst::dyn_extract(Val))
1032 addConstantValue(ParamDIE, CI, resolve(VP->getType()));
1030 addConstantValue(ParamDIE, CI, VP->getType());
10331031 else if (GlobalValue *GV = mdconst::dyn_extract(Val)) {
10341032 // We cannot describe the location of dllimport'd entities: the
10351033 // computation of their address requires loads from the IAT.
11031101 // such construction creates the DIE (as is the case for member function
11041102 // declarations).
11051103 DIE *ContextDIE =
1106 Minimal ? &getUnitDie() : getOrCreateContextDIE(resolve(SP->getScope()));
1104 Minimal ? &getUnitDie() : getOrCreateContextDIE(SP->getScope());
11071105
11081106 if (DIE *SPDie = getDIE(SP))
11091107 return SPDie;
12161214 // Add a return type. If this is a type like a C/C++ void type we don't add a
12171215 // return type.
12181216 if (Args.size())
1219 if (auto Ty = resolve(Args[0]))
1217 if (auto Ty = Args[0])
12201218 addType(SPDie, Ty);
12211219
12221220 unsigned VK = SP->getVirtuality();
12281226 addUInt(*Block, dwarf::DW_FORM_udata, SP->getVirtualIndex());
12291227 addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, Block);
12301228 }
1231 ContainingTypeMap.insert(
1232 std::make_pair(&SPDie, resolve(SP->getContainingType())));
1229 ContainingTypeMap.insert(std::make_pair(&SPDie, SP->getContainingType()));
12331230 }
12341231
12351232 if (!SP->isDefinition()) {
13351332 const uint64_t ActualSize = CTy->getSizeInBits();
13361333
13371334 // Obtain the size of each element in the vector.
1338 DIType *BaseTy = CTy->getBaseType().resolve();
1335 DIType *BaseTy = CTy->getBaseType();
13391336 assert(BaseTy && "Unknown vector element type.");
13401337 const uint64_t ElementSize = BaseTy->getSizeInBits();
13411338
13631360 }
13641361
13651362 // Emit the element type.
1366 addType(Buffer, resolve(CTy->getBaseType()));
1363 addType(Buffer, CTy->getBaseType());
13671364
13681365 // Get an anonymous type for index type.
13691366 // FIXME: This type should be passed down from the front end
13811378 }
13821379
13831380 void DwarfUnit::constructEnumTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
1384 const DIType *DTy = resolve(CTy->getBaseType());
1381 const DIType *DTy = CTy->getBaseType();
13851382 bool IsUnsigned = DTy && isUnsignedDIType(DD, DTy);
13861383 if (DTy) {
13871384 if (DD->getDwarfVersion() >= 3)
14251422 if (!Name.empty())
14261423 addString(MemberDie, dwarf::DW_AT_name, Name);
14271424
1428 if (DIType *Resolved = resolve(DT->getBaseType()))
1425 if (DIType *Resolved = DT->getBaseType())
14291426 addType(MemberDie, Resolved);
14301427
14311428 addSourceLine(MemberDie, DT);
15341531
15351532 // Construct the context before querying for the existence of the DIE in case
15361533 // such construction creates the DIE.
1537 DIE *ContextDIE = getOrCreateContextDIE(resolve(DT->getScope()));
1534 DIE *ContextDIE = getOrCreateContextDIE(DT->getScope());
15381535 assert(dwarf::isType(ContextDIE->getTag()) &&
15391536 "Static member should belong to a type.");
15401537
15431540
15441541 DIE &StaticMemberDIE = createAndAddDIE(DT->getTag(), *ContextDIE, DT);
15451542
1546 const DIType *Ty = resolve(DT->getBaseType());
1543 const DIType *Ty = DT->getBaseType();
15471544
15481545 addString(StaticMemberDIE, dwarf::DW_AT_name, DT->getName());
15491546 addType(StaticMemberDIE, Ty);
309309 /// Look up the source ID for the given file. If none currently exists,
310310 /// create a new ID and insert it in the line table.
311311 virtual unsigned getOrCreateSourceID(const DIFile *File) = 0;
312
313 /// Look in the DwarfDebug map for the MDNode that corresponds to the
314 /// reference.
315 template T *resolve(TypedDINodeRef Ref) const {
316 return Ref.resolve();
317 }
318312
319313 /// Emit the common part of the header for this unit.
320314 void emitCommonHeader(bool UseOffsets, dwarf::UnitType UT);
165165 if (Line)
166166 assert(File && "Source location has line number but no file");
167167 unsigned EntitiesCount = C.pImpl->DIImportedEntitys.size();
168 auto *M =
169 DIImportedEntity::get(C, Tag, Context, DINodeRef(NS), File, Line, Name);
168 auto *M = DIImportedEntity::get(C, Tag, Context, cast_or_null(NS),
169 File, Line, Name);
170170 if (EntitiesCount < C.pImpl->DIImportedEntitys.size())
171171 // A new Imported Entity was just added to the context.
172172 // Add it to the Imported Modules list.
8080 continue;
8181 auto *GV = DIG->getVariable();
8282 processScope(GV->getScope());
83 processType(GV->getType().resolve());
83 processType(GV->getType());
8484 }
8585 for (auto *ET : CU->getEnumTypes())
8686 processType(ET);
9090 else
9191 processSubprogram(cast(RT));
9292 for (auto *Import : CU->getImportedEntities()) {
93 auto *Entity = Import->getEntity().resolve();
93 auto *Entity = Import->getEntity();
9494 if (auto *T = dyn_cast(Entity))
9595 processType(T);
9696 else if (auto *SP = dyn_cast(Entity))
123123 void DebugInfoFinder::processType(DIType *DT) {
124124 if (!addType(DT))
125125 return;
126 processScope(DT->getScope().resolve());
126 processScope(DT->getScope());
127127 if (auto *ST = dyn_cast(DT)) {
128 for (DITypeRef Ref : ST->getTypeArray())
129 processType(Ref.resolve());
128 for (DIType *Ref : ST->getTypeArray())
129 processType(Ref);
130130 return;
131131 }
132132 if (auto *DCT = dyn_cast(DT)) {
133 processType(DCT->getBaseType().resolve());
133 processType(DCT->getBaseType());
134134 for (Metadata *D : DCT->getElements()) {
135135 if (auto *T = dyn_cast(D))
136136 processType(T);
140140 return;
141141 }
142142 if (auto *DDT = dyn_cast(DT)) {
143 processType(DDT->getBaseType().resolve());
143 processType(DDT->getBaseType());
144144 }
145145 }
146146
173173 void DebugInfoFinder::processSubprogram(DISubprogram *SP) {
174174 if (!addSubprogram(SP))
175175 return;
176 processScope(SP->getScope().resolve());
176 processScope(SP->getScope());
177177 // Some of the users, e.g. CloneFunctionInto / CloneModule, need to set up a
178178 // ValueMap containing identity mappings for all of the DICompileUnit's, not
179179 // just DISubprogram's, referenced from anywhere within the Function being
186186 processType(SP->getType());
187187 for (auto *Element : SP->getTemplateParams()) {
188188 if (auto *TType = dyn_cast(Element)) {
189 processType(TType->getType().resolve());
189 processType(TType->getType());
190190 } else if (auto *TVal = dyn_cast(Element)) {
191 processType(TVal->getType().resolve());
191 processType(TVal->getType());
192192 }
193193 }
194194 }
206206 if (!NodesSeen.insert(DV).second)
207207 return;
208208 processScope(DV->getScope());
209 processType(DV->getType().resolve());
209 processType(DV->getType());
210210 }
211211
212212 void DebugInfoFinder::processValue(const Module &M, const DbgValueInst *DVI) {
221221 if (!NodesSeen.insert(DV).second)
222222 return;
223223 processScope(DV->getScope());
224 processType(DV->getType().resolve());
224 processType(DV->getType());
225225 }
226226
227227 bool DebugInfoFinder::addType(DIType *DT) {
427427 StringRef LinkageName = MDS->getName().empty() ? MDS->getLinkageName() : "";
428428 DISubprogram *Declaration = nullptr;
429429 auto *Type = cast_or_null(map(MDS->getType()));
430 DITypeRef ContainingType(map(MDS->getContainingType()));
430 DIType *ContainingType =
431 cast_or_null(map(MDS->getContainingType()));
431432 auto *Unit = cast_or_null(map(MDS->getUnit()));
432433 auto Variables = nullptr;
433434 auto TemplateParams = nullptr;
8787 DILocation *L = LocA->getInlinedAt();
8888 while (S) {
8989 Locations.insert(std::make_pair(S, L));
90 S = S->getScope().resolve();
90 S = S->getScope();
9191 if (!S && L) {
9292 S = L->getScope();
9393 L = L->getInlinedAt();
9999 while (S) {
100100 if (Locations.count(std::make_pair(S, L)))
101101 break;
102 S = S->getScope().resolve();
102 S = S->getScope();
103103 if (!S && L) {
104104 S = L->getScope();
105105 L = L->getInlinedAt();
208208 return Flags;
209209 }
210210
211 DIScopeRef DIScope::getScope() const {
211 DIScope *DIScope::getScope() const {
212212 if (auto *T = dyn_cast(this))
213213 return T->getScope();
214214
6464 BTFType.NameOff = BDebug.addString(DTy->getName());
6565
6666 // The base type for PTR/CONST/VOLATILE could be void.
67 const DIType *ResolvedType = DTy->getBaseType().resolve();
67 const DIType *ResolvedType = DTy->getBaseType();
6868 if (!ResolvedType) {
6969 assert((Kind == BTF::BTF_KIND_PTR || Kind == BTF::BTF_KIND_CONST ||
7070 Kind == BTF::BTF_KIND_VOLATILE) &&
208208 } else {
209209 BTFMember.Offset = DDTy->getOffsetInBits();
210210 }
211 BTFMember.Type = BDebug.getTypeId(DDTy->getBaseType().resolve());
211 BTFMember.Type = BDebug.getTypeId(DDTy->getBaseType());
212212 Members.push_back(BTFMember);
213213 }
214214 }
238238
239239 void BTFTypeFuncProto::completeType(BTFDebug &BDebug) {
240240 DITypeRefArray Elements = STy->getTypeArray();
241 auto RetType = Elements[0].resolve();
241 auto RetType = Elements[0];
242242 BTFType.Type = RetType ? BDebug.getTypeId(RetType) : 0;
243243 BTFType.NameOff = 0;
244244
246246 // to represent the vararg, encode the NameOff/Type to be 0.
247247 for (unsigned I = 1, N = Elements.size(); I < N; ++I) {
248248 struct BTF::BTFParam Param;
249 auto Element = Elements[I].resolve();
249 auto Element = Elements[I];
250250 if (Element) {
251251 Param.NameOff = BDebug.addString(FuncArgNames[I]);
252252 Param.Type = BDebug.getTypeId(Element);
392392
393393 // Visit return type and func arg types.
394394 for (const auto Element : Elements) {
395 visitTypeEntry(Element.resolve());
395 visitTypeEntry(Element);
396396 }
397397 }
398398
426426 void BTFDebug::visitArrayType(const DICompositeType *CTy, uint32_t &TypeId) {
427427 // Visit array element type.
428428 uint32_t ElemTypeId;
429 visitTypeEntry(CTy->getBaseType().resolve(), ElemTypeId);
429 visitTypeEntry(CTy->getBaseType(), ElemTypeId);
430430
431431 if (!CTy->getSizeInBits()) {
432432 auto TypeEntry = llvm::make_unique(ElemTypeId, 0);
512512 // Visit base type of pointer, typedef, const, volatile, restrict or
513513 // struct/union member.
514514 uint32_t TempTypeId = 0;
515 visitTypeEntry(DTy->getBaseType().resolve(), TempTypeId);
515 visitTypeEntry(DTy->getBaseType(), TempTypeId);
516516 }
517517
518518 void BTFDebug::visitTypeEntry(const DIType *Ty, uint32_t &TypeId) {
712712 // Collect function arguments for subprogram func type.
713713 uint32_t Arg = DV->getArg();
714714 if (Arg) {
715 visitTypeEntry(DV->getType().resolve());
715 visitTypeEntry(DV->getType());
716716 FuncArgNames[Arg] = DV->getName();
717717 }
718718 }
809809 Global.getDebugInfo(GVs);
810810 uint32_t GVTypeId = 0;
811811 for (auto *GVE : GVs) {
812 visitTypeEntry(GVE->getVariable()->getType().resolve(), GVTypeId);
812 visitTypeEntry(GVE->getVariable()->getType(), GVTypeId);
813813 break;
814814 }
815815
3434 }
3535 } else if (auto *TY = dyn_cast(Context)) {
3636 if (!TY->getName().empty()) {
37 getContextName(TY->getScope().resolve(), N);
37 getContextName(TY->getScope(), N);
3838 N = N + TY->getName().str() + "::";
3939 }
4040 }
4848 auto *SP = cast_or_null(NMD->getOperand(i));
4949 if (!SP)
5050 continue;
51 getContextName(SP->getScope().resolve(), Name);
51 getContextName(SP->getScope(), Name);
5252 Name = Name + SP->getName().str();
5353 if (!Name.empty() && Processed.insert(Name).second) {
5454 Out << Name << "\n";