From dc293b3fe9e3cb7eb7ce7035b32218251a06fbfe Mon Sep 17 00:00:00 2001 From: Manman Ren Date: Wed, 11 Sep 2013 18:55:55 +0000 Subject: [PATCH] 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 --- include/llvm/DebugInfo.h | 96 ++++++++++++++++++++++++------------------------ 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 class DIRef; typedef DIRef DIScopeRef; + typedef DIRef 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 + class DIRef { + template + 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(Val)) + return T(MD); + + const MDString *MS = cast(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(Val); } + }; + + /// Specialize getFieldAs to handle fields that are references to DIScopes. + template <> + DIScopeRef DIDescriptor::getFieldAs(unsigned Elt) const; + /// Specialize DIRef constructor for DIScopeRef. + template <> + DIRef::DIRef(const Value *V); + + /// Specialize getFieldAs to handle fields that are references to DITypes. + template <> + DITypeRef DIDescriptor::getFieldAs(unsigned Elt) const; + /// Specialize DIRef constructor for DITypeRef. + template <> + DIRef::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(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 - class DIRef { - template - 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(Val)) - return T(MD); - - const MDString *MS = cast(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(Val); } - }; - - /// Specialize getFieldAs to handle fields that are references to DIScopes. - template <> - DIScopeRef DIDescriptor::getFieldAs(unsigned Elt) const; - /// Specialize DIRef constructor for DIScopeRef. - template <> - DIRef::DIRef(const Value *V); - - typedef DIRef DITypeRef; - /// Specialize getFieldAs to handle fields that are references to DITypes. - template <> - DITypeRef DIDescriptor::getFieldAs(unsigned Elt) const; - /// Specialize DIRef constructor for DITypeRef. - template <> - DIRef::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(unsigned Elt) const { return DITypeRef(getField(DbgNode, Elt)); } - -DIScopeRef DIType::getContext() const { - return getFieldAs(2); -} -- 2.11.0