From: Duncan P. N. Exon Smith Date: Sat, 11 Apr 2015 17:37:23 +0000 (+0000) Subject: DebugInfo: Move DIScope::getName() and getContext() to MDScope X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=4e1b79bbd8944bd7875ec720a895664f46b9ed9c;p=oota-llvm.git DebugInfo: Move DIScope::getName() and getContext() to MDScope Continue gutting the `DIDescriptor` hierarchy. In this case, move the guts of `DIScope::getName()` and `DIScope::getContext()` to `MDScope::getName()` and `MDScope::getScope()`. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234691 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/IR/DebugInfo.h b/include/llvm/IR/DebugInfo.h index 9237377e2a3..e575e83484b 100644 --- a/include/llvm/IR/DebugInfo.h +++ b/include/llvm/IR/DebugInfo.h @@ -213,15 +213,8 @@ public: return *get(); } - /// \brief Get the parent scope. - /// - /// Gets the parent scope for this scope node or returns a default - /// constructed scope. - DIScopeRef getContext() const; - /// \brief Get the scope name. - /// - /// If the scope node has a name, return that, else return an empty string. - StringRef getName() const; + inline DIScopeRef getContext() const; + StringRef getName() const { return get()->getName(); } StringRef getFilename() const { return get()->getFilename(); } StringRef getDirectory() const { return get()->getDirectory(); } @@ -258,6 +251,8 @@ template <> DIScope DIRef::resolve(const DITypeIdentifierMap &Map) const; template <> DIType DIRef::resolve(const DITypeIdentifierMap &Map) const; +DIScopeRef DIScope::getContext() const { return get()->getScope(); } + /// \brief This is a wrapper for a type. /// /// FIXME: Types should be factored much better so that CV qualifiers and diff --git a/include/llvm/IR/DebugInfoMetadata.h b/include/llvm/IR/DebugInfoMetadata.h index 2c66e6717b1..8d18a5f8644 100644 --- a/include/llvm/IR/DebugInfoMetadata.h +++ b/include/llvm/IR/DebugInfoMetadata.h @@ -419,6 +419,9 @@ public: inline StringRef getFilename() const; inline StringRef getDirectory() const; + StringRef getName() const; + MDScopeRef getScope() const; + /// \brief Return the raw underlying file. /// /// An \a MDFile is an \a MDScope, but it doesn't point at a separate file diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp index 4b1c1f7bbd1..6845827fc24 100644 --- a/lib/IR/DebugInfo.cpp +++ b/lib/IR/DebugInfo.cpp @@ -112,37 +112,6 @@ GlobalVariable *DIGlobalVariable::getGlobal() const { return dyn_cast_or_null(getConstant()); } -DIScopeRef DIScope::getContext() const { - if (DIType T = dyn_cast(*this)) - return T.getContext(); - - if (DISubprogram SP = dyn_cast(*this)) - return MDScopeRef(SP.getContext()); - - if (DILexicalBlock LB = dyn_cast(*this)) - return MDScopeRef(LB.getContext()); - - if (DINameSpace NS = dyn_cast(*this)) - return MDScopeRef(NS.getContext()); - - assert((isa(*this) || isa(*this)) && - "Unhandled type of scope."); - return MDScopeRef(); -} - -StringRef DIScope::getName() const { - if (DIType T = dyn_cast(*this)) - return T.getName(); - if (DISubprogram SP = dyn_cast(*this)) - return SP.getName(); - if (DINameSpace NS = dyn_cast(*this)) - return NS.getName(); - assert((isa(*this) || isa(*this) || - isa(*this)) && - "Unhandled type of scope."); - return StringRef(); -} - void DICompileUnit::replaceSubprograms(DIArray Subprograms) { get()->replaceSubprograms(MDSubprogramArray(Subprograms)); } diff --git a/lib/IR/DebugInfoMetadata.cpp b/lib/IR/DebugInfoMetadata.cpp index 6ce091f54d1..e98be8ed6e7 100644 --- a/lib/IR/DebugInfoMetadata.cpp +++ b/lib/IR/DebugInfoMetadata.cpp @@ -108,6 +108,36 @@ unsigned DebugNode::splitFlags(unsigned Flags, return Flags; } +MDScopeRef MDScope::getScope() const { + if (auto *T = dyn_cast(this)) + return T->getScope(); + + if (auto *SP = dyn_cast(this)) + return SP->getScope(); + + if (auto *LB = dyn_cast(this)) + return MDScopeRef(LB->getScope()); + + if (auto *NS = dyn_cast(this)) + return MDScopeRef(NS->getScope()); + + assert((isa(this) || isa(this)) && + "Unhandled type of scope."); + return nullptr; +} + +StringRef MDScope::getName() const { + if (auto *T = dyn_cast(this)) + return T->getName(); + if (auto *SP = dyn_cast(this)) + return SP->getName(); + if (auto *NS = dyn_cast(this)) + return NS->getName(); + assert((isa(this) || isa(this) || + isa(this)) && + "Unhandled type of scope."); + return ""; +} static StringRef getString(const MDString *S) { if (S)