From a10307bf9543b8ff09a1469ca36bf500a465a73b Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Mon, 6 Apr 2015 22:27:37 +0000 Subject: [PATCH] DebugInfo: Reimplement DIRef<>::resolve() using TypedDebugNodeRef<> Gut `DIRef<>::resolve()`, reimplementing it using `TypedDebugNodeRef<>::resolve()`. Use three separate functions rather than some sort of type traits, since the latter (i.e., mapping `DIScope` => `MDScope`) seems heavy-handed. I don't expect `DIRef<>` to last much longer in tree anyway. As a drive-by fix, make `TypedDebugNodeRef<>::resolve()` do the right thing with `nullptr`. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234248 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/DebugInfo.h | 21 +++++---------------- include/llvm/IR/DebugInfoMetadata.h | 3 +++ lib/IR/DebugInfo.cpp | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/include/llvm/IR/DebugInfo.h b/include/llvm/IR/DebugInfo.h index f851be737df..f022edddb0e 100644 --- a/include/llvm/IR/DebugInfo.h +++ b/include/llvm/IR/DebugInfo.h @@ -301,22 +301,11 @@ public: static DIRef get(const Metadata *MD) { return DIRef(MD); } }; -template -T DIRef::resolve(const DITypeIdentifierMap &Map) const { - if (!Val) - return T(); - - if (const MDNode *MD = dyn_cast(Val)) - return T(MD); - - const MDString *MS = cast(Val); - // Find the corresponding MDNode. - DITypeIdentifierMap::const_iterator Iter = Map.find(MS); - assert(Iter != Map.end() && "Identifier not in the type map?"); - assert(DIDescriptor(Iter->second).isType() && - "MDNode in DITypeIdentifierMap should be a DIType."); - return T(Iter->second); -} +template <> +DIDescriptor DIRef::resolve(const DITypeIdentifierMap &Map) const; +template <> +DIScope DIRef::resolve(const DITypeIdentifierMap &Map) const; +template <> DIType DIRef::resolve(const DITypeIdentifierMap &Map) const; /// \brief Handle fields that are references to DIDescriptors. template <> diff --git a/include/llvm/IR/DebugInfoMetadata.h b/include/llvm/IR/DebugInfoMetadata.h index d162f957701..394c70ee950 100644 --- a/include/llvm/IR/DebugInfoMetadata.h +++ b/include/llvm/IR/DebugInfoMetadata.h @@ -75,6 +75,9 @@ public: static TypedDebugNodeRef get(const T *N); template T *resolve(const MapTy &Map) const { + if (!MD) + return nullptr; + if (auto *Typed = dyn_cast(MD)) return const_cast(Typed); diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp index 8ae2bcb8485..721fbc8c3a0 100644 --- a/lib/IR/DebugInfo.cpp +++ b/lib/IR/DebugInfo.cpp @@ -685,6 +685,20 @@ template <> DITypeRef DIDescriptor::getFieldAs(unsigned Elt) const { return DITypeRef(cast_or_null(getField(DbgNode, Elt))); } +template <> +DIDescriptor +DIRef::resolve(const DITypeIdentifierMap &Map) const { + return DIDescriptor(DebugNodeRef(Val).resolve(Map)); +} +template <> +DIScope DIRef::resolve(const DITypeIdentifierMap &Map) const { + return MDScopeRef(Val).resolve(Map); +} +template <> +DIType DIRef::resolve(const DITypeIdentifierMap &Map) const { + return MDTypeRef(Val).resolve(Map); +} + bool llvm::stripDebugInfo(Function &F) { bool Changed = false; for (BasicBlock &BB : F) { -- 2.11.0