From: Duncan P. N. Exon Smith Date: Mon, 6 Apr 2015 18:02:43 +0000 (+0000) Subject: DebugInfo: Create MDTypeRef, etc., to replace DITypeRef X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=05652b6afa44be14fe33e9a20f0e508f2bfd292e;p=oota-llvm.git DebugInfo: Create MDTypeRef, etc., to replace DITypeRef Create a string-based wrapper in the debug info hierarchy for type references. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234188 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/IR/DebugInfo.h b/include/llvm/IR/DebugInfo.h index a11cfad802a..acd906b08b8 100644 --- a/include/llvm/IR/DebugInfo.h +++ b/include/llvm/IR/DebugInfo.h @@ -290,6 +290,12 @@ template class DIRef { explicit DIRef(const Metadata *V); public: + template + DIRef(const TypedDebugNodeRef &Ref, + typename std::enable_if::value>::type * = + nullptr) + : Val(Ref) {} + T resolve(const DITypeIdentifierMap &Map) const; operator Metadata *() const { return const_cast(Val); } diff --git a/include/llvm/IR/DebugInfoMetadata.h b/include/llvm/IR/DebugInfoMetadata.h index a03e8764ade..85c28ccca34 100644 --- a/include/llvm/IR/DebugInfoMetadata.h +++ b/include/llvm/IR/DebugInfoMetadata.h @@ -41,6 +41,54 @@ namespace llvm { +/// \brief Pointer union between a subclass of DebugNode and MDString. +/// +/// \a MDCompositeType can be referenced via an \a MDString unique identifier. +/// This class allows some type safety in the face of that, requiring either a +/// node of a particular type or an \a MDString. +template class TypedDebugNodeRef { + const Metadata *MD = nullptr; + +public: + TypedDebugNodeRef(std::nullptr_t) {} + + /// \brief Construct from a raw pointer. + explicit TypedDebugNodeRef(const Metadata *MD) : MD(MD) { + assert((!MD || isa(MD) || isa(MD)) && "Expected valid ref"); + } + + template + TypedDebugNodeRef( + const TypedDebugNodeRef &X, + typename std::enable_if::value>::type * = + nullptr) + : MD(X) {} + + operator Metadata *() const { return const_cast(MD); } + + bool operator==(const TypedDebugNodeRef &X) const { return MD == X.MD; }; + bool operator!=(const TypedDebugNodeRef &X) const { return MD != X.MD; }; + + /// \brief Create a reference. + /// + /// Get a reference to \c N, using an \a MDString reference if available. + static TypedDebugNodeRef get(const T *N); + + template T *resolve(const MapTy &Map) const { + if (auto *Typed = dyn_cast(MD)) + return const_cast(Typed); + + auto *S = cast(MD); + auto I = Map.find(S); + assert(I != Map.end() && "Missing identifier in type map"); + return cast(I->second); + } +}; + +typedef TypedDebugNodeRef DebugNodeRef; +typedef TypedDebugNodeRef MDScopeRef; +typedef TypedDebugNodeRef MDTypeRef; + /// \brief Tagged DWARF-like metadata node. /// /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*, @@ -88,6 +136,8 @@ public: FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic }; + DebugNodeRef getRef() const { return DebugNodeRef::get(this); } + static bool classof(const Metadata *MD) { switch (MD->getMetadataID()) { default: @@ -116,6 +166,18 @@ public: } }; +template +struct simplify_type> { + typedef Metadata *SimpleType; + static SimpleType getSimplifiedValue(const TypedDebugNodeRef &MD) { + return MD; + } +}; + +template +struct simplify_type> + : simplify_type> {}; + /// \brief Generic tagged DWARF-like metadata node. /// /// An un-specialized DWARF-like metadata node. The first operand is a @@ -305,6 +367,8 @@ public: : static_cast(getOperand(0)); } + MDScopeRef getRef() const { return MDScopeRef::get(this); } + static bool classof(const Metadata *MD) { switch (MD->getMetadataID()) { default: @@ -414,6 +478,8 @@ public: Flags = NewFlags; } + MDTypeRef getRef() const { return MDTypeRef::get(this); } + static bool classof(const Metadata *MD) { switch (MD->getMetadataID()) { default: @@ -724,6 +790,14 @@ public: } }; +template TypedDebugNodeRef TypedDebugNodeRef::get(const T *N) { + if (N) + if (auto *Composite = dyn_cast(N)) + if (auto *S = Composite->getRawIdentifier()) + return TypedDebugNodeRef(S); + return TypedDebugNodeRef(N); +} + /// \brief Type array for a subprogram. /// /// TODO: Detach from CompositeType, and fold the array of types in directly diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp index 2f497e9dc11..550418a1573 100644 --- a/lib/IR/DebugInfo.cpp +++ b/lib/IR/DebugInfo.cpp @@ -253,14 +253,7 @@ void DICompositeType::setArraysHelper(MDNode *Elements, MDNode *TParams) { DbgNode = N; } -DIScopeRef DIScope::getRef() const { - if (!isCompositeType()) - return DIScopeRef(*this); - DICompositeType DTy(DbgNode); - if (!DTy.getIdentifier()) - return DIScopeRef(*this); - return DIScopeRef(DTy.getIdentifier()); -} +DIScopeRef DIScope::getRef() const { return MDScopeRef::get(get()); } void DICompositeType::setContainingType(DICompositeType ContainingType) { TypedTrackingMDRef N(get());