diff options
author | Manman Ren <manman.ren@gmail.com> | 2013-09-11 18:55:55 +0000 |
---|---|---|
committer | Manman Ren <manman.ren@gmail.com> | 2013-09-11 18:55:55 +0000 |
commit | dc293b3fe9e3cb7eb7ce7035b32218251a06fbfe (patch) | |
tree | 279dfd3d252c3d3067823a2ac4712b5312b31d69 | |
parent | 55c06ae7afa3f862a6bb4a4441fe485c135f5b5e (diff) |
Debug Info: move class definition of DIRef.
Definition of DIRef used to require the full definition of DIType because
of usage of DIType::isType in DIRef::resolve. We now use DIDescriptor::isType
instead to remove the requirement and move definition of DIRef before DIType.
With this, we can move the definition of DIType::getContext to the header
file.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190540 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/DebugInfo.h | 96 | ||||
-rw-r--r-- | lib/IR/DebugInfo.cpp | 4 |
2 files changed, 48 insertions, 52 deletions
diff --git a/include/llvm/DebugInfo.h b/include/llvm/DebugInfo.h index deebcfd4395..515dc65162b 100644 --- a/include/llvm/DebugInfo.h +++ b/include/llvm/DebugInfo.h @@ -193,6 +193,7 @@ namespace llvm { template <typename T> class DIRef; typedef DIRef<DIScope> DIScopeRef; + typedef DIRef<DIType> DITypeRef; /// DIScope - A base class for various scopes. class DIScope : public DIDescriptor { @@ -213,6 +214,52 @@ namespace llvm { DIScopeRef generateRef(); }; + /// Represents reference to a DIDescriptor, abstracts over direct and + /// identifier-based metadata references. + template <typename T> + class DIRef { + template <typename DescTy> + friend DescTy DIDescriptor::getFieldAs(unsigned Elt) const; + friend DIScopeRef DIScope::getContext() const; + friend DIScopeRef DIScope::generateRef(); + + /// Val can be either a MDNode or a MDString, in the latter, + /// MDString specifies the type identifier. + const Value *Val; + explicit DIRef(const Value *V); + public: + 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); + } + operator Value *() const { return const_cast<Value*>(Val); } + }; + + /// Specialize getFieldAs to handle fields that are references to DIScopes. + template <> + DIScopeRef DIDescriptor::getFieldAs<DIScopeRef>(unsigned Elt) const; + /// Specialize DIRef constructor for DIScopeRef. + template <> + DIRef<DIScope>::DIRef(const Value *V); + + /// Specialize getFieldAs to handle fields that are references to DITypes. + template <> + DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const; + /// Specialize DIRef constructor for DITypeRef. + template <> + DIRef<DIType>::DIRef(const Value *V); + /// DIType - This is a wrapper for a type. /// FIXME: Types should be factored much better so that CV qualifiers and /// others do not require a huge and empty descriptor full of zeros. @@ -227,7 +274,7 @@ namespace llvm { /// Verify - Verify that a type descriptor is well formed. bool Verify() const; - DIScopeRef getContext() const; + DIScopeRef getContext() const { return getFieldAs<DIScopeRef>(2); } StringRef getName() const { return getStringField(3); } unsigned getLineNumber() const { return getUnsignedField(4); } uint64_t getSizeInBits() const { return getUInt64Field(5); } @@ -283,53 +330,6 @@ namespace llvm { void replaceAllUsesWith(MDNode *D); }; - /// Represents reference to a DIDescriptor, abstracts over direct and - /// identifier-based metadata references. - template <typename T> - class DIRef { - template <typename DescTy> - friend DescTy DIDescriptor::getFieldAs(unsigned Elt) const; - friend DIScopeRef DIScope::getContext() const; - friend DIScopeRef DIScope::generateRef(); - - /// Val can be either a MDNode or a MDString, in the latter, - /// MDString specifies the type identifier. - const Value *Val; - explicit DIRef(const Value *V); - public: - 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(DIType(Iter->second).isType() && - "MDNode in DITypeIdentifierMap should be a DIType."); - return T(Iter->second); - } - operator Value *() const { return const_cast<Value*>(Val); } - }; - - /// Specialize getFieldAs to handle fields that are references to DIScopes. - template <> - DIScopeRef DIDescriptor::getFieldAs<DIScopeRef>(unsigned Elt) const; - /// Specialize DIRef constructor for DIScopeRef. - template <> - DIRef<DIScope>::DIRef(const Value *V); - - typedef DIRef<DIType> DITypeRef; - /// Specialize getFieldAs to handle fields that are references to DITypes. - template <> - DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const; - /// Specialize DIRef constructor for DITypeRef. - template <> - DIRef<DIType>::DIRef(const Value *V); - /// DIBasicType - A basic type, like 'int' or 'float'. class DIBasicType : public DIType { public: diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp index 87984a09759..e5a92ab15d9 100644 --- a/lib/IR/DebugInfo.cpp +++ b/lib/IR/DebugInfo.cpp @@ -1452,7 +1452,3 @@ template <> DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const { return DITypeRef(getField(DbgNode, Elt)); } - -DIScopeRef DIType::getContext() const { - return getFieldAs<DIScopeRef>(2); -} |