DebugInfo: Reimplement DIRef<>::resolve() using TypedDebugNodeRef<>
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 6 Apr 2015 22:27:37 +0000 (22:27 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 6 Apr 2015 22:27:37 +0000 (22:27 +0000)
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
include/llvm/IR/DebugInfoMetadata.h
lib/IR/DebugInfo.cpp

index f851be737dfa2eb8d1651a0a1b89b34c2e687f08..f022edddb0e41bc7aa7ad4af3df303dd46b141cc 100644 (file)
@@ -301,22 +301,11 @@ public:
   static DIRef get(const Metadata *MD) { return DIRef(MD); }
 };
 
-template <typename T>
-T DIRef<T>::resolve(const DITypeIdentifierMap &Map) const {
-  if (!Val)
-    return T();
-
-  if (const MDNode *MD = dyn_cast<MDNode>(Val))
-    return T(MD);
-
-  const MDString *MS = cast<MDString>(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<DIDescriptor>::resolve(const DITypeIdentifierMap &Map) const;
+template <>
+DIScope DIRef<DIScope>::resolve(const DITypeIdentifierMap &Map) const;
+template <> DIType DIRef<DIType>::resolve(const DITypeIdentifierMap &Map) const;
 
 /// \brief Handle fields that are references to DIDescriptors.
 template <>
index d162f9577017b0500ccc81122d9213f8118eee96..394c70ee9500f849dc507ca7cef510eb7dc77794 100644 (file)
@@ -75,6 +75,9 @@ public:
   static TypedDebugNodeRef get(const T *N);
 
   template <class MapTy> T *resolve(const MapTy &Map) const {
+    if (!MD)
+      return nullptr;
+
     if (auto *Typed = dyn_cast<T>(MD))
       return const_cast<T *>(Typed);
 
index 8ae2bcb84856f283a2279d712f16dc30117b44d0..721fbc8c3a08e6fe6255189f6bf5ee9a00dc92ac 100644 (file)
@@ -685,6 +685,20 @@ template <> DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const {
   return DITypeRef(cast_or_null<Metadata>(getField(DbgNode, Elt)));
 }
 
+template <>
+DIDescriptor
+DIRef<DIDescriptor>::resolve(const DITypeIdentifierMap &Map) const {
+  return DIDescriptor(DebugNodeRef(Val).resolve(Map));
+}
+template <>
+DIScope DIRef<DIScope>::resolve(const DITypeIdentifierMap &Map) const {
+  return MDScopeRef(Val).resolve(Map);
+}
+template <>
+DIType DIRef<DIType>::resolve(const DITypeIdentifierMap &Map) const {
+  return MDTypeRef(Val).resolve(Map);
+}
+
 bool llvm::stripDebugInfo(Function &F) {
   bool Changed = false;
   for (BasicBlock &BB : F) {