summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorManman Ren <manman.ren@gmail.com>2013-09-10 18:30:07 +0000
committerManman Ren <manman.ren@gmail.com>2013-09-10 18:30:07 +0000
commit34b3dcc3b5e391e04276081bb5aecc42073d3e63 (patch)
tree36792a26736fe486e8913a1a0236cff8808f3512 /llvm/lib
parent19ae779af1c6f89dd0285ebc9b846300d378a0b6 (diff)
downloadbcm5719-llvm-34b3dcc3b5e391e04276081bb5aecc42073d3e63.tar.gz
bcm5719-llvm-34b3dcc3b5e391e04276081bb5aecc42073d3e63.zip
Debug Info: define a DIRef template.
Specialize the constructors for DIRef<DIScope> and DIRef<DIType> to make sure the Value is indeed a scope ref and a type ref. Use DIScopeRef for DIScope::getContext and DIType::getContext and use DITypeRef for getContainingType and getClassType. DIScope::generateRef now returns a DIScopeRef instead of a "Value *" for readability and type safety. llvm-svn: 190418
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp5
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h5
-rw-r--r--llvm/lib/IR/DebugInfo.cpp41
3 files changed, 23 insertions, 28 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 7db6df0e19a..608ce6a5688 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -2644,8 +2644,3 @@ void DwarfDebug::emitDebugStrDWO() {
InfoHolder.emitStrings(Asm->getObjFileLowering().getDwarfStrDWOSection(),
OffSec, StrSym);
}
-
-/// Find the MDNode for the given scope reference.
-DIScope DwarfDebug::resolve(DIScopeRef SRef) const {
- return SRef.resolve(TypeIdentifierMap);
-}
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
index e026c668135..6c13b9ec6f9 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -684,7 +684,10 @@ public:
unsigned getDwarfVersion() const { return DwarfVersion; }
/// Find the MDNode for the given scope reference.
- DIScope resolve(DIScopeRef SRef) const;
+ template <typename T>
+ T resolve(DIRef<T> Ref) const {
+ return Ref.resolve(TypeIdentifierMap);
+ }
/// isSubprogramContext - Return true if Context is either a subprogram
/// or another context nested inside a subprogram.
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 51c9e58b2d7..87984a09759 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -725,13 +725,13 @@ void DICompositeType::addMember(DIDescriptor D) {
/// Generate a reference to this DIType. Uses the type identifier instead
/// of the actual MDNode if possible, to help type uniquing.
-Value *DIScope::generateRef() {
+DIScopeRef DIScope::generateRef() {
if (!isCompositeType())
- return *this;
+ return DIScopeRef(*this);
DICompositeType DTy(DbgNode);
if (!DTy.getIdentifier())
- return *this;
- return DTy.getIdentifier();
+ return DIScopeRef(*this);
+ return DIScopeRef(DTy.getIdentifier());
}
/// \brief Set the containing type.
@@ -1432,26 +1432,14 @@ void DIVariable::printExtendedName(raw_ostream &OS) const {
}
}
-DIScopeRef::DIScopeRef(const Value *V) : Val(V) {
+/// Specialize constructor to make sure it has the correct type.
+template <>
+DIRef<DIScope>::DIRef(const Value *V) : Val(V) {
assert(isScopeRef(V) && "DIScopeRef should be a MDString or MDNode");
}
-
-/// Given a DITypeIdentifierMap, tries to find the corresponding
-/// DIScope for a DIScopeRef.
-DIScope DIScopeRef::resolve(const DITypeIdentifierMap &Map) const {
- if (!Val)
- return DIScope();
-
- if (const MDNode *MD = dyn_cast<MDNode>(Val))
- return DIScope(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(DIType(Iter->second).isType() &&
- "MDNode in DITypeIdentifierMap should be a DIType.");
- return DIScope(Iter->second);
+template <>
+DIRef<DIType>::DIRef(const Value *V) : Val(V) {
+ assert(isTypeRef(V) && "DITypeRef should be a MDString or MDNode");
}
/// Specialize getFieldAs to handle fields that are references to DIScopes.
@@ -1459,3 +1447,12 @@ template <>
DIScopeRef DIDescriptor::getFieldAs<DIScopeRef>(unsigned Elt) const {
return DIScopeRef(getField(DbgNode, Elt));
}
+/// Specialize getFieldAs to handle fields that are references to DITypes.
+template <>
+DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const {
+ return DITypeRef(getField(DbgNode, Elt));
+}
+
+DIScopeRef DIType::getContext() const {
+ return getFieldAs<DIScopeRef>(2);
+}
OpenPOWER on IntegriCloud