[llvm] r234248 - DebugInfo: Reimplement DIRef<>::resolve() using TypedDebugNodeRef<>
Duncan P. N. Exon Smith
dexonsmith at apple.com
Mon Apr 6 15:27:38 PDT 2015
Author: dexonsmith
Date: Mon Apr 6 17:27:37 2015
New Revision: 234248
URL: http://llvm.org/viewvc/llvm-project?rev=234248&view=rev
Log:
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`.
Modified:
llvm/trunk/include/llvm/IR/DebugInfo.h
llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
llvm/trunk/lib/IR/DebugInfo.cpp
Modified: llvm/trunk/include/llvm/IR/DebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfo.h?rev=234248&r1=234247&r2=234248&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfo.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfo.h Mon Apr 6 17:27:37 2015
@@ -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 <>
Modified: llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfoMetadata.h?rev=234248&r1=234247&r2=234248&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Mon Apr 6 17:27:37 2015
@@ -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);
Modified: llvm/trunk/lib/IR/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=234248&r1=234247&r2=234248&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfo.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfo.cpp Mon Apr 6 17:27:37 2015
@@ -685,6 +685,20 @@ template <> DITypeRef DIDescriptor::getF
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) {
More information about the llvm-commits
mailing list