diff options
author | Manman Ren <manman.ren@gmail.com> | 2013-09-09 19:03:51 +0000 |
---|---|---|
committer | Manman Ren <manman.ren@gmail.com> | 2013-09-09 19:03:51 +0000 |
commit | c573305bce147df68051a6dffef034c6210ab89c (patch) | |
tree | fb0ee7096fc8f96036ba913911eb5678746093aa /lib/IR/DebugInfo.cpp | |
parent | 626a4b785b8ef14bbd4f763a01396df3c6a758f7 (diff) | |
download | llvm-c573305bce147df68051a6dffef034c6210ab89c.tar.gz llvm-c573305bce147df68051a6dffef034c6210ab89c.tar.bz2 llvm-c573305bce147df68051a6dffef034c6210ab89c.tar.xz |
Debug Info: Rename DITypeRef to DIScopeRef.
A reference to a scope is more general than a reference to a type since
DIType is a subclass of DIScope.
A reference to a type can be either an identifier for the type or
the DIType itself, while a reference to a scope can be either an
identifier for the type (when the scope is indeed a type) or the
DIScope itself. A reference to a type and a reference to a scope
will be resolved in the same way. The only difference is in the
verifier when a field is a reference to a type (i.e. the containing
type field of a DICompositeType) or a field is a reference to a scope
(i.e. the context field of a DIType).
This is to get ready for switching DIType::getContext to return
DIScopeRef instead of DIScope.
Tighten up isTypeRef and isScopeRef to make sure the identifier is not
empty and the MDNode is DIType for TypeRef and DIScope for ScopeRef.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190322 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR/DebugInfo.cpp')
-rw-r--r-- | lib/IR/DebugInfo.cpp | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp index d0667cd6db..7f56f2fb1f 100644 --- a/lib/IR/DebugInfo.cpp +++ b/lib/IR/DebugInfo.cpp @@ -426,17 +426,26 @@ static bool fieldIsMDString(const MDNode *DbgNode, unsigned Elt) { return !Fld || isa<MDString>(Fld); } -/// Check if a value can be a TypeRef. +/// Check if a value can be a reference to a type. static bool isTypeRef(const Value *Val) { - return !Val || isa<MDString>(Val) || isa<MDNode>(Val); + return !Val || + (isa<MDString>(Val) && !cast<MDString>(Val)->getString().empty()) || + (isa<MDNode>(Val) && DIType(cast<MDNode>(Val)).isType()); } -/// Check if a field at position Elt of a MDNode can be a TypeRef. +/// Check if a field at position Elt of a MDNode can be a reference to a type. static bool fieldIsTypeRef(const MDNode *DbgNode, unsigned Elt) { Value *Fld = getField(DbgNode, Elt); return isTypeRef(Fld); } +/// Check if a value can be a ScopeRef. +static bool isScopeRef(const Value *Val) { + return !Val || + (isa<MDString>(Val) && !cast<MDString>(Val)->getString().empty()) || + (isa<MDNode>(Val) && DIScope(cast<MDNode>(Val)).isScope()); +} + /// Verify - Verify that a type descriptor is well formed. bool DIType::Verify() const { if (!isType()) @@ -710,13 +719,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. -DITypeRef DIType::generateRef() { +Value *DIScope::generateRef() { if (!isCompositeType()) - return DITypeRef(*this); + return *this; DICompositeType DTy(DbgNode); if (!DTy.getIdentifier()) - return DITypeRef(*this); - return DITypeRef(DTy.getIdentifier()); + return *this; + return DTy.getIdentifier(); } /// \brief Set the containing type. @@ -1428,33 +1437,30 @@ void DIVariable::printExtendedName(raw_ostream &OS) const { } } -DITypeRef::DITypeRef(const Value *V) : TypeVal(V) { - assert(isTypeRef(V) && "DITypeRef should be a MDString or MDNode"); +DIScopeRef::DIScopeRef(const Value *V) : Val(V) { + assert(isScopeRef(V) && "DIScopeRef should be a MDString or MDNode"); } /// Given a DITypeIdentifierMap, tries to find the corresponding -/// DIType for a DITypeRef. -DIType DITypeRef::resolve(const DITypeIdentifierMap &Map) const { - if (!TypeVal) - return NULL; - - if (const MDNode *MD = dyn_cast<MDNode>(TypeVal)) { - assert(DIType(MD).isType() && - "MDNode in DITypeRef should be a DIType."); - return MD; - } +/// 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>(TypeVal); + 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 Iter->second; + return DIScope(Iter->second); } -/// Specialize getFieldAs to handle fields that are references to DITypes. +/// Specialize getFieldAs to handle fields that are references to DIScopes. template <> -DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const { - return DITypeRef(getField(DbgNode, Elt)); +DIScopeRef DIDescriptor::getFieldAs<DIScopeRef>(unsigned Elt) const { + return DIScopeRef(getField(DbgNode, Elt)); } |