1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00

DebugInfo: Allow isa<> on DIDescriptor and subclasses

Allow LLVM-style casting on `DIDescriptor` and its subclasses so they
can behave more like raw pointers.  I haven't bothered with tests since
I have a follow-up commit coming shortly that uses them extensively in
tree, and I'm hoping to kill `DIDescriptor` entirely before too long (so
they won't have time to bitrot).

Usage examples:

    DIDescriptor D = foo();
    if (DICompileUnit CU = dyn_cast<MDCompileUnit>(D))
      return bar(CU);
    else if (auto *SP = dyn_cast<MDSubprogram>(D))
      return baz(SP);
    return other(D);

llvm-svn: 234250
This commit is contained in:
Duncan P. N. Exon Smith 2015-04-06 22:32:20 +00:00
parent 4214740c57
commit 657d25b1ca

View File

@ -168,6 +168,35 @@ public:
void replaceAllUsesWith(MDNode *D); void replaceAllUsesWith(MDNode *D);
}; };
#define DECLARE_SIMPLIFY_DESCRIPTOR(DESC) \
class DESC; \
template <> struct simplify_type<const DESC>; \
template <> struct simplify_type<DESC>;
DECLARE_SIMPLIFY_DESCRIPTOR(DIDescriptor)
DECLARE_SIMPLIFY_DESCRIPTOR(DISubrange)
DECLARE_SIMPLIFY_DESCRIPTOR(DIEnumerator)
DECLARE_SIMPLIFY_DESCRIPTOR(DIScope)
DECLARE_SIMPLIFY_DESCRIPTOR(DIType)
DECLARE_SIMPLIFY_DESCRIPTOR(DIBasicType)
DECLARE_SIMPLIFY_DESCRIPTOR(DIDerivedType)
DECLARE_SIMPLIFY_DESCRIPTOR(DICompositeType)
DECLARE_SIMPLIFY_DESCRIPTOR(DISubroutineType)
DECLARE_SIMPLIFY_DESCRIPTOR(DIFile)
DECLARE_SIMPLIFY_DESCRIPTOR(DICompileUnit)
DECLARE_SIMPLIFY_DESCRIPTOR(DISubprogram)
DECLARE_SIMPLIFY_DESCRIPTOR(DILexicalBlock)
DECLARE_SIMPLIFY_DESCRIPTOR(DILexicalBlockFile)
DECLARE_SIMPLIFY_DESCRIPTOR(DINameSpace)
DECLARE_SIMPLIFY_DESCRIPTOR(DITemplateTypeParameter)
DECLARE_SIMPLIFY_DESCRIPTOR(DITemplateValueParameter)
DECLARE_SIMPLIFY_DESCRIPTOR(DIGlobalVariable)
DECLARE_SIMPLIFY_DESCRIPTOR(DIVariable)
DECLARE_SIMPLIFY_DESCRIPTOR(DIExpression)
DECLARE_SIMPLIFY_DESCRIPTOR(DILocation)
DECLARE_SIMPLIFY_DESCRIPTOR(DIObjCProperty)
DECLARE_SIMPLIFY_DESCRIPTOR(DIImportedEntity)
#undef DECLARE_SIMPLIFY_DESCRIPTOR
/// \brief This is used to represent ranges, for array bounds. /// \brief This is used to represent ranges, for array bounds.
class DISubrange : public DIDescriptor { class DISubrange : public DIDescriptor {
public: public:
@ -1121,6 +1150,37 @@ public:
StringRef getName() const { return get()->getName(); } StringRef getName() const { return get()->getName(); }
}; };
#define SIMPLIFY_DESCRIPTOR(DESC) \
template <> struct simplify_type<const DESC> { \
typedef Metadata *SimpleType; \
static SimpleType getSimplifiedValue(const DESC &DI) { return DI; } \
}; \
template <> struct simplify_type<DESC> : simplify_type<const DESC> {};
SIMPLIFY_DESCRIPTOR(DIDescriptor)
SIMPLIFY_DESCRIPTOR(DISubrange)
SIMPLIFY_DESCRIPTOR(DIEnumerator)
SIMPLIFY_DESCRIPTOR(DIScope)
SIMPLIFY_DESCRIPTOR(DIType)
SIMPLIFY_DESCRIPTOR(DIBasicType)
SIMPLIFY_DESCRIPTOR(DIDerivedType)
SIMPLIFY_DESCRIPTOR(DICompositeType)
SIMPLIFY_DESCRIPTOR(DISubroutineType)
SIMPLIFY_DESCRIPTOR(DIFile)
SIMPLIFY_DESCRIPTOR(DICompileUnit)
SIMPLIFY_DESCRIPTOR(DISubprogram)
SIMPLIFY_DESCRIPTOR(DILexicalBlock)
SIMPLIFY_DESCRIPTOR(DILexicalBlockFile)
SIMPLIFY_DESCRIPTOR(DINameSpace)
SIMPLIFY_DESCRIPTOR(DITemplateTypeParameter)
SIMPLIFY_DESCRIPTOR(DITemplateValueParameter)
SIMPLIFY_DESCRIPTOR(DIGlobalVariable)
SIMPLIFY_DESCRIPTOR(DIVariable)
SIMPLIFY_DESCRIPTOR(DIExpression)
SIMPLIFY_DESCRIPTOR(DILocation)
SIMPLIFY_DESCRIPTOR(DIObjCProperty)
SIMPLIFY_DESCRIPTOR(DIImportedEntity)
#undef SIMPLIFY_DESCRIPTOR
/// \brief Find subprogram that is enclosing this scope. /// \brief Find subprogram that is enclosing this scope.
DISubprogram getDISubprogram(const MDNode *Scope); DISubprogram getDISubprogram(const MDNode *Scope);