/// \brief Maps from type identifier to the actual MDNode.
typedef DenseMap<const MDString *, MDNode *> DITypeIdentifierMap;
-/// \brief A thin wraper around MDNode to access encoded debug info.
-///
-/// This should not be stored in a container, because the underlying MDNode may
-/// change in certain situations.
class DIDescriptor {
-public:
- /// \brief Duplicated debug info flags.
- ///
- /// \see DebugNode::DIFlags.
- enum {
-#define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = DebugNode::Flag##NAME,
-#include "llvm/IR/DebugInfoFlags.def"
- FlagAccessibility = DebugNode::FlagAccessibility
- };
-
-protected:
- const MDNode *DbgNode;
+ MDNode *N;
public:
- explicit DIDescriptor(const MDNode *N = nullptr) : DbgNode(N) {}
- DIDescriptor(const DebugNode *N) : DbgNode(N) {}
-
- MDNode *get() const { return const_cast<MDNode *>(DbgNode); }
- operator MDNode *() const { return get(); }
- MDNode *operator->() const { return get(); }
- MDNode &operator*() const { return *get(); }
-
- // An explicit operator bool so that we can do testing of DI values
- // easily.
- // FIXME: This operator bool isn't actually protecting anything at the
- // moment due to the conversion operator above making DIDescriptor nodes
- // implicitly convertable to bool.
- explicit operator bool() const { return DbgNode != nullptr; }
-
- bool operator==(DIDescriptor Other) const { return DbgNode == Other.DbgNode; }
- bool operator!=(DIDescriptor Other) const { return !operator==(Other); }
-
- uint16_t getTag() const {
- if (auto *N = dyn_cast_or_null<DebugNode>(get()))
- return N->getTag();
- return 0;
- }
+ DIDescriptor(const MDNode *N = nullptr) : N(const_cast<MDNode *>(N)) {}
- void print(raw_ostream &OS) const;
- void dump() const;
+ operator MDNode *() const { return N; }
+ MDNode *operator->() const { return N; }
+ MDNode &operator*() const { return *N; }
};
#define DECLARE_SIMPLIFY_DESCRIPTOR(DESC) \
typedef DebugNodeArray DIArray;
typedef MDTypeRefArray DITypeArray;
+typedef DebugNodeRef DIDescriptorRef;
+typedef MDScopeRef DIScopeRef;
+typedef MDTypeRef DITypeRef;
class DISubrange {
MDSubrange *N;
MDEnumerator &operator*() const { return *N; }
};
-template <typename T> class DIRef;
-typedef DIRef<DIDescriptor> DIDescriptorRef;
-typedef DIRef<DIScope> DIScopeRef;
-typedef DIRef<DIType> DITypeRef;
-
class DIScope {
MDScope *N;
MDScope &operator*() const { return *N; }
};
-/// \brief Represents reference to a DIDescriptor.
-///
-/// Abstracts over direct and identifier-based metadata references.
-template <typename T> class DIRef {
- /// \brief Val can be either a MDNode or a MDString.
- ///
- /// In the latter, MDString specifies the type identifier.
- const Metadata *Val;
-
-public:
- template <class U>
- DIRef(const TypedDebugNodeRef<U> &Ref,
- typename std::enable_if<std::is_convertible<U *, T>::value>::type * =
- nullptr)
- : Val(Ref) {}
-
- T resolve(const DITypeIdentifierMap &Map) const;
- operator Metadata *() const { return const_cast<Metadata *>(Val); }
-};
-
-template <>
-DIDescriptor DIRef<DIDescriptor>::resolve(const DITypeIdentifierMap &Map) const;
-template <>
-DIScope DIRef<DIScope>::resolve(const DITypeIdentifierMap &Map) const;
-template <> DIType DIRef<DIType>::resolve(const DITypeIdentifierMap &Map) const;
-
class DIType {
MDType *N;