diff options
| author | Fangrui Song <maskray@google.com> | 2019-05-07 02:06:37 +0000 |
|---|---|---|
| committer | Fangrui Song <maskray@google.com> | 2019-05-07 02:06:37 +0000 |
| commit | da82ce99b7460164ffb841619aadb44f397d2106 (patch) | |
| tree | 6eeb15bafc58fe997fd3b0666fb47331e9287746 /llvm/include | |
| parent | a400ca3f3d42de0b0aa5c441de761d182c6010e8 (diff) | |
| download | bcm5719-llvm-da82ce99b7460164ffb841619aadb44f397d2106.tar.gz bcm5719-llvm-da82ce99b7460164ffb841619aadb44f397d2106.zip | |
[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
llvm-svn: 360108
Diffstat (limited to 'llvm/include')
| -rw-r--r-- | llvm/include/llvm/CodeGen/DebugHandlerBase.h | 2 | ||||
| -rw-r--r-- | llvm/include/llvm/IR/DebugInfoMetadata.h | 174 |
2 files changed, 65 insertions, 111 deletions
diff --git a/llvm/include/llvm/CodeGen/DebugHandlerBase.h b/llvm/include/llvm/CodeGen/DebugHandlerBase.h index 3771d4892cf..4008d597395 100644 --- a/llvm/include/llvm/CodeGen/DebugHandlerBase.h +++ b/llvm/include/llvm/CodeGen/DebugHandlerBase.h @@ -129,7 +129,7 @@ public: const MCExpr *getFunctionLocalOffsetAfterInsn(const MachineInstr *MI); /// If this type is derived from a base type then return base type size. - static uint64_t getBaseTypeSize(const DITypeRef TyRef); + static uint64_t getBaseTypeSize(const DIType *Ty); }; } diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h index d8030902028..0d2617ecdb6 100644 --- a/llvm/include/llvm/IR/DebugInfoMetadata.h +++ b/llvm/include/llvm/IR/DebugInfoMetadata.h @@ -60,44 +60,6 @@ namespace llvm { -/// Holds a subclass of DINode. -/// -/// FIXME: This class doesn't currently make much sense. Previously it was a -/// union beteen MDString (for ODR-uniqued types) and things like DIType. To -/// support CodeView work, it wasn't deleted outright when MDString-based type -/// references were deleted; we'll soon need a similar concept for CodeView -/// DITypeIndex. -template <class T> class TypedDINodeRef { - const Metadata *MD = nullptr; - -public: - TypedDINodeRef() = default; - TypedDINodeRef(std::nullptr_t) {} - TypedDINodeRef(const T *MD) : MD(MD) {} - - explicit TypedDINodeRef(const Metadata *MD) : MD(MD) { - assert((!MD || isa<T>(MD)) && "Expected valid type ref"); - } - - template <class U> - TypedDINodeRef( - const TypedDINodeRef<U> &X, - typename std::enable_if<std::is_convertible<U *, T *>::value>::type * = - nullptr) - : MD(X) {} - - operator Metadata *() const { return const_cast<Metadata *>(MD); } - - T *resolve() const { return const_cast<T *>(cast_or_null<T>(MD)); } - - bool operator==(const TypedDINodeRef<T> &X) const { return MD == X.MD; } - bool operator!=(const TypedDINodeRef<T> &X) const { return MD != X.MD; } -}; - -using DINodeRef = TypedDINodeRef<DINode>; -using DIScopeRef = TypedDINodeRef<DIScope>; -using DITypeRef = TypedDINodeRef<DIType>; - class DITypeRefArray { const MDTuple *N = nullptr; @@ -114,17 +76,19 @@ public: // FIXME: Fix callers and remove condition on N. unsigned size() const { return N ? N->getNumOperands() : 0u; } - DITypeRef operator[](unsigned I) const { return DITypeRef(N->getOperand(I)); } + DIType *operator[](unsigned I) const { + return cast_or_null<DIType>(N->getOperand(I)); + } - class iterator : std::iterator<std::input_iterator_tag, DITypeRef, - std::ptrdiff_t, void, DITypeRef> { + class iterator : std::iterator<std::input_iterator_tag, DIType *, + std::ptrdiff_t, void, DIType *> { MDNode::op_iterator I = nullptr; public: iterator() = default; explicit iterator(MDNode::op_iterator I) : I(I) {} - DITypeRef operator*() const { return DITypeRef(*I); } + DIType *operator*() const { return cast_or_null<DIType>(*I); } iterator &operator++() { ++I; @@ -241,18 +205,6 @@ public: } }; -template <class T> struct simplify_type<const TypedDINodeRef<T>> { - using SimpleType = Metadata *; - - static SimpleType getSimplifiedValue(const TypedDINodeRef<T> &MD) { - return MD; - } -}; - -template <class T> -struct simplify_type<TypedDINodeRef<T>> - : simplify_type<const TypedDINodeRef<T>> {}; - /// Generic tagged DWARF-like metadata node. /// /// An un-specialized DWARF-like metadata node. The first operand is a @@ -459,7 +411,7 @@ public: inline Optional<StringRef> getSource() const; StringRef getName() const; - DIScopeRef getScope() const; + DIScope *getScope() const; /// Return the raw underlying file. /// @@ -673,7 +625,7 @@ public: uint64_t getOffsetInBits() const { return OffsetInBits; } DIFlags getFlags() const { return Flags; } - DIScopeRef getScope() const { return DIScopeRef(getRawScope()); } + DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); } StringRef getName() const { return getStringOperand(2); } @@ -818,14 +770,12 @@ class DIDerivedType : public DIType { DWARFAddressSpace(DWARFAddressSpace) {} ~DIDerivedType() = default; - static DIDerivedType *getImpl(LLVMContext &Context, unsigned Tag, - StringRef Name, DIFile *File, unsigned Line, - DIScopeRef Scope, DITypeRef BaseType, - uint64_t SizeInBits, uint32_t AlignInBits, - uint64_t OffsetInBits, - Optional<unsigned> DWARFAddressSpace, - DIFlags Flags, Metadata *ExtraData, - StorageType Storage, bool ShouldCreate = true) { + static DIDerivedType * + getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File, + unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits, + uint32_t AlignInBits, uint64_t OffsetInBits, + Optional<unsigned> DWARFAddressSpace, DIFlags Flags, + Metadata *ExtraData, StorageType Storage, bool ShouldCreate = true) { return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits, DWARFAddressSpace, Flags, ExtraData, Storage, ShouldCreate); @@ -859,7 +809,7 @@ public: ExtraData)) DEFINE_MDNODE_GET(DIDerivedType, (unsigned Tag, StringRef Name, DIFile *File, unsigned Line, - DIScopeRef Scope, DITypeRef BaseType, uint64_t SizeInBits, + DIScope *Scope, DIType *BaseType, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, Optional<unsigned> DWARFAddressSpace, DIFlags Flags, Metadata *ExtraData = nullptr), @@ -870,7 +820,7 @@ public: TempDIDerivedType clone() const { return cloneImpl(); } /// Get the base type this is derived from. - DITypeRef getBaseType() const { return DITypeRef(getRawBaseType()); } + DIType *getBaseType() const { return cast_or_null<DIType>(getRawBaseType()); } Metadata *getRawBaseType() const { return getOperand(3); } /// \returns The DWARF address space of the memory pointed to or referenced by @@ -890,9 +840,9 @@ public: /// Get casted version of extra data. /// @{ - DITypeRef getClassType() const { + DIType *getClassType() const { assert(getTag() == dwarf::DW_TAG_ptr_to_member_type); - return DITypeRef(getExtraData()); + return cast_or_null<DIType>(getExtraData()); } DIObjCProperty *getObjCProperty() const { @@ -964,12 +914,12 @@ class DICompositeType : public DIType { static DICompositeType * getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File, - unsigned Line, DIScopeRef Scope, DITypeRef BaseType, - uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, - DIFlags Flags, DINodeArray Elements, unsigned RuntimeLang, - DITypeRef VTableHolder, DITemplateParameterArray TemplateParams, - StringRef Identifier, DIDerivedType *Discriminator, - StorageType Storage, bool ShouldCreate = true) { + unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits, + uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags, + DINodeArray Elements, unsigned RuntimeLang, DIType *VTableHolder, + DITemplateParameterArray TemplateParams, StringRef Identifier, + DIDerivedType *Discriminator, StorageType Storage, + bool ShouldCreate = true) { return getImpl( Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits, Flags, Elements.get(), @@ -996,12 +946,13 @@ class DICompositeType : public DIType { public: DEFINE_MDNODE_GET(DICompositeType, (unsigned Tag, StringRef Name, DIFile *File, unsigned Line, - DIScopeRef Scope, DITypeRef BaseType, uint64_t SizeInBits, - uint32_t AlignInBits, uint64_t OffsetInBits, - DIFlags Flags, DINodeArray Elements, unsigned RuntimeLang, - DITypeRef VTableHolder, + DIScope *Scope, DIType *BaseType, uint64_t SizeInBits, + uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags, + DINodeArray Elements, unsigned RuntimeLang, + DIType *VTableHolder, DITemplateParameterArray TemplateParams = nullptr, - StringRef Identifier = "", DIDerivedType *Discriminator = nullptr), + StringRef Identifier = "", + DIDerivedType *Discriminator = nullptr), (Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder, TemplateParams, Identifier, Discriminator)) @@ -1054,11 +1005,13 @@ public: unsigned RuntimeLang, Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator); - DITypeRef getBaseType() const { return DITypeRef(getRawBaseType()); } + DIType *getBaseType() const { return cast_or_null<DIType>(getRawBaseType()); } DINodeArray getElements() const { return cast_or_null<MDTuple>(getRawElements()); } - DITypeRef getVTableHolder() const { return DITypeRef(getRawVTableHolder()); } + DIType *getVTableHolder() const { + return cast_or_null<DIType>(getRawVTableHolder()); + } DITemplateParameterArray getTemplateParams() const { return cast_or_null<MDTuple>(getRawTemplateParams()); } @@ -1088,7 +1041,7 @@ public: replaceOperandWith(4, Elements.get()); } - void replaceVTableHolder(DITypeRef VTableHolder) { + void replaceVTableHolder(DIType *VTableHolder) { replaceOperandWith(5, VTableHolder); } @@ -1705,9 +1658,9 @@ private: ~DISubprogram() = default; static DISubprogram * - getImpl(LLVMContext &Context, DIScopeRef Scope, StringRef Name, + getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File, unsigned Line, - DISubroutineType *Type, unsigned ScopeLine, DITypeRef ContainingType, + DISubroutineType *Type, unsigned ScopeLine, DIType *ContainingType, unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, DICompileUnit *Unit, DITemplateParameterArray TemplateParams, DISubprogram *Declaration, @@ -1742,9 +1695,9 @@ private: public: DEFINE_MDNODE_GET( DISubprogram, - (DIScopeRef Scope, StringRef Name, StringRef LinkageName, DIFile *File, + (DIScope * Scope, StringRef Name, StringRef LinkageName, DIFile *File, unsigned Line, DISubroutineType *Type, unsigned ScopeLine, - DITypeRef ContainingType, unsigned VirtualIndex, int ThisAdjustment, + DIType *ContainingType, unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, DICompileUnit *Unit, DITemplateParameterArray TemplateParams = nullptr, DISubprogram *Declaration = nullptr, DINodeArray RetainedNodes = nullptr, @@ -1828,7 +1781,7 @@ public: // Returns true if this subprogram is a thunk generated by the compiler. bool isThunk() const { return getFlags() & FlagThunk; } - DIScopeRef getScope() const { return DIScopeRef(getRawScope()); } + DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); } StringRef getName() const { return getStringOperand(2); } StringRef getLinkageName() const { return getStringOperand(3); } @@ -1836,8 +1789,8 @@ public: DISubroutineType *getType() const { return cast_or_null<DISubroutineType>(getRawType()); } - DITypeRef getContainingType() const { - return DITypeRef(getRawContainingType()); + DIType *getContainingType() const { + return cast_or_null<DIType>(getRawContainingType()); } DICompileUnit *getUnit() const { @@ -2182,7 +2135,7 @@ protected: public: StringRef getName() const { return getStringOperand(0); } - DITypeRef getType() const { return DITypeRef(getRawType()); } + DIType *getType() const { return cast_or_null<DIType>(getRawType()); } MDString *getRawName() const { return getOperandAs<MDString>(0); } Metadata *getRawType() const { return getOperand(1); } @@ -2204,7 +2157,7 @@ class DITemplateTypeParameter : public DITemplateParameter { ~DITemplateTypeParameter() = default; static DITemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name, - DITypeRef Type, StorageType Storage, + DIType *Type, StorageType Storage, bool ShouldCreate = true) { return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage, ShouldCreate); @@ -2218,7 +2171,7 @@ class DITemplateTypeParameter : public DITemplateParameter { } public: - DEFINE_MDNODE_GET(DITemplateTypeParameter, (StringRef Name, DITypeRef Type), + DEFINE_MDNODE_GET(DITemplateTypeParameter, (StringRef Name, DIType *Type), (Name, Type)) DEFINE_MDNODE_GET(DITemplateTypeParameter, (MDString * Name, Metadata *Type), (Name, Type)) @@ -2241,7 +2194,7 @@ class DITemplateValueParameter : public DITemplateParameter { ~DITemplateValueParameter() = default; static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag, - StringRef Name, DITypeRef Type, + StringRef Name, DIType *Type, Metadata *Value, StorageType Storage, bool ShouldCreate = true) { return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type, @@ -2258,8 +2211,9 @@ class DITemplateValueParameter : public DITemplateParameter { } public: - DEFINE_MDNODE_GET(DITemplateValueParameter, (unsigned Tag, StringRef Name, - DITypeRef Type, Metadata *Value), + DEFINE_MDNODE_GET(DITemplateValueParameter, + (unsigned Tag, StringRef Name, DIType *Type, + Metadata *Value), (Tag, Name, Type, Value)) DEFINE_MDNODE_GET(DITemplateValueParameter, (unsigned Tag, MDString *Name, Metadata *Type, Metadata *Value), @@ -2291,7 +2245,7 @@ public: DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); } StringRef getName() const { return getStringOperand(1); } DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); } - DITypeRef getType() const { return DITypeRef(getRawType()); } + DIType *getType() const { return cast_or_null<DIType>(getRawType()); } uint32_t getAlignInBits() const { return AlignInBits; } uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; } /// Determines the size of the variable's type. @@ -2300,7 +2254,7 @@ public: /// Return the signedness of this variable's type, or None if this type is /// neither signed nor unsigned. Optional<DIBasicType::Signedness> getSignedness() const { - if (auto *BT = dyn_cast<DIBasicType>(getType().resolve())) + if (auto *BT = dyn_cast<DIBasicType>(getType())) return BT->getSignedness(); return None; } @@ -2611,7 +2565,7 @@ class DIGlobalVariable : public DIVariable { static DIGlobalVariable * getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name, - StringRef LinkageName, DIFile *File, unsigned Line, DITypeRef Type, + StringRef LinkageName, DIFile *File, unsigned Line, DIType *Type, bool IsLocalToUnit, bool IsDefinition, DIDerivedType *StaticDataMemberDeclaration, MDTuple *TemplateParams, uint32_t AlignInBits, StorageType Storage, bool ShouldCreate = true) { @@ -2638,7 +2592,7 @@ class DIGlobalVariable : public DIVariable { public: DEFINE_MDNODE_GET(DIGlobalVariable, (DIScope * Scope, StringRef Name, StringRef LinkageName, - DIFile *File, unsigned Line, DITypeRef Type, + DIFile *File, unsigned Line, DIType *Type, bool IsLocalToUnit, bool IsDefinition, DIDerivedType *StaticDataMemberDeclaration, MDTuple *TemplateParams, uint32_t AlignInBits), @@ -2755,7 +2709,7 @@ class DILocalVariable : public DIVariable { static DILocalVariable *getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name, DIFile *File, unsigned Line, - DITypeRef Type, unsigned Arg, DIFlags Flags, + DIType *Type, unsigned Arg, DIFlags Flags, uint32_t AlignInBits, StorageType Storage, bool ShouldCreate = true) { return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File, @@ -2776,8 +2730,8 @@ class DILocalVariable : public DIVariable { public: DEFINE_MDNODE_GET(DILocalVariable, (DILocalScope * Scope, StringRef Name, DIFile *File, - unsigned Line, DITypeRef Type, unsigned Arg, - DIFlags Flags, uint32_t AlignInBits), + unsigned Line, DIType *Type, unsigned Arg, DIFlags Flags, + uint32_t AlignInBits), (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits)) DEFINE_MDNODE_GET(DILocalVariable, (Metadata * Scope, MDString *Name, Metadata *File, @@ -2902,7 +2856,7 @@ class DIObjCProperty : public DINode { static DIObjCProperty * getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line, StringRef GetterName, StringRef SetterName, unsigned Attributes, - DITypeRef Type, StorageType Storage, bool ShouldCreate = true) { + DIType *Type, StorageType Storage, bool ShouldCreate = true) { return getImpl(Context, getCanonicalMDString(Context, Name), File, Line, getCanonicalMDString(Context, GetterName), getCanonicalMDString(Context, SetterName), Attributes, Type, @@ -2924,7 +2878,7 @@ public: DEFINE_MDNODE_GET(DIObjCProperty, (StringRef Name, DIFile *File, unsigned Line, StringRef GetterName, StringRef SetterName, - unsigned Attributes, DITypeRef Type), + unsigned Attributes, DIType *Type), (Name, File, Line, GetterName, SetterName, Attributes, Type)) DEFINE_MDNODE_GET(DIObjCProperty, @@ -2942,7 +2896,7 @@ public: DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); } StringRef getGetterName() const { return getStringOperand(2); } StringRef getSetterName() const { return getStringOperand(3); } - DITypeRef getType() const { return DITypeRef(getRawType()); } + DIType *getType() const { return cast_or_null<DIType>(getRawType()); } StringRef getFilename() const { if (auto *F = getFile()) @@ -2986,8 +2940,8 @@ class DIImportedEntity : public DINode { ~DIImportedEntity() = default; static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag, - DIScope *Scope, DINodeRef Entity, - DIFile *File, unsigned Line, StringRef Name, + DIScope *Scope, DINode *Entity, DIFile *File, + unsigned Line, StringRef Name, StorageType Storage, bool ShouldCreate = true) { return getImpl(Context, Tag, Scope, Entity, File, Line, @@ -3006,8 +2960,8 @@ class DIImportedEntity : public DINode { public: DEFINE_MDNODE_GET(DIImportedEntity, - (unsigned Tag, DIScope *Scope, DINodeRef Entity, - DIFile *File, unsigned Line, StringRef Name = ""), + (unsigned Tag, DIScope *Scope, DINode *Entity, DIFile *File, + unsigned Line, StringRef Name = ""), (Tag, Scope, Entity, File, Line, Name)) DEFINE_MDNODE_GET(DIImportedEntity, (unsigned Tag, Metadata *Scope, Metadata *Entity, @@ -3018,7 +2972,7 @@ public: unsigned getLine() const { return Line; } DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); } - DINodeRef getEntity() const { return DINodeRef(getRawEntity()); } + DINode *getEntity() const { return cast_or_null<DINode>(getRawEntity()); } StringRef getName() const { return getStringOperand(2); } DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); } |

