From 5fc3fbd3ca71c91607047cf456b63fcca02274fb Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Sat, 11 Apr 2015 00:39:43 +0000 Subject: [PATCH] DebugInfo: Add forwarding getFilename() accessor to new hierarchy Add forwarding `getFilename()` and `getDirectory()` accessors to nodes in the new hierarchy that define a `getFile()`. Use that to re-implement existing functionality in the `DIDescriptor` hierarchy. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234671 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/DebugInfo.h | 12 ++++----- include/llvm/IR/DebugInfoMetadata.h | 41 +++++++++++++++++++++++++++++ lib/IR/DebugInfo.cpp | 14 ---------- 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/include/llvm/IR/DebugInfo.h b/include/llvm/IR/DebugInfo.h index 7703ad1cfe9..65c10347911 100644 --- a/include/llvm/IR/DebugInfo.h +++ b/include/llvm/IR/DebugInfo.h @@ -222,8 +222,8 @@ public: /// /// If the scope node has a name, return that, else return an empty string. StringRef getName() const; - StringRef getFilename() const; - StringRef getDirectory() const; + StringRef getFilename() const { return get()->getFilename(); } + StringRef getDirectory() const { return get()->getDirectory(); } /// \brief Generate a reference to this DIScope. /// @@ -697,8 +697,8 @@ public: unsigned isDefinition() const { return get()->isDefinition(); } DIScope getContext() const { return DIScope(get()->getScope()); } - StringRef getFilename() const { return getFile().getFilename(); } - StringRef getDirectory() const { return getFile().getDirectory(); } + StringRef getFilename() const { return get()->getFilename(); } + StringRef getDirectory() const { return get()->getDirectory(); } DITypeRef getType() const { return get()->getType(); } GlobalVariable *getGlobal() const; @@ -812,8 +812,8 @@ public: DILocation getOrigLocation() const { return DILocation(get()->getInlinedAt()); } - StringRef getFilename() const { return getScope().getFilename(); } - StringRef getDirectory() const { return getScope().getDirectory(); } + StringRef getFilename() const { return get()->getFilename(); } + StringRef getDirectory() const { return get()->getDirectory(); } bool atSameLineAs(const DILocation &Other) const { return (getLineNumber() == Other.getLineNumber() && getFilename() == Other.getFilename()); diff --git a/include/llvm/IR/DebugInfoMetadata.h b/include/llvm/IR/DebugInfoMetadata.h index 4bed55ef1bd..374f7277636 100644 --- a/include/llvm/IR/DebugInfoMetadata.h +++ b/include/llvm/IR/DebugInfoMetadata.h @@ -416,6 +416,9 @@ protected: public: MDFile *getFile() const { return cast_or_null(getRawFile()); } + inline StringRef getFilename() const; + inline StringRef getDirectory() const; + /// \brief Return the raw underlying file. /// /// An \a MDFile is an \a MDScope, but it doesn't point at a separate file @@ -494,6 +497,18 @@ public: } }; +StringRef MDScope::getFilename() const { + if (auto *F = getFile()) + return F->getFilename(); + return ""; +} + +StringRef MDScope::getDirectory() const { + if (auto *F = getFile()) + return F->getDirectory(); + return ""; +} + /// \brief Base class for types. /// /// TODO: Remove the hardcoded name and context, since many types don't use @@ -1137,6 +1152,10 @@ public: return cast_or_null(getRawInlinedAt()); } + MDFile *getFile() const { return getScope()->getFile(); } + StringRef getFilename() const { return getScope()->getFilename(); } + StringRef getDirectory() const { return getScope()->getDirectory(); } + /// \brief Get the scope where this is inlined. /// /// Walk through \a getInlinedAt() and return \a getScope() from the deepest @@ -1628,6 +1647,17 @@ public: MDFile *getFile() const { return cast_or_null(getRawFile()); } MDTypeRef getType() const { return MDTypeRef(getRawType()); } + StringRef getFilename() const { + if (auto *F = getFile()) + return F->getFilename(); + return ""; + } + StringRef getDirectory() const { + if (auto *F = getFile()) + return F->getDirectory(); + return ""; + } + Metadata *getRawScope() const { return getOperand(0); } MDString *getRawName() const { return getOperandAs(1); } Metadata *getRawFile() const { return getOperand(2); } @@ -2021,6 +2051,17 @@ public: StringRef getSetterName() const { return getStringOperand(3); } MDType *getType() const { return cast_or_null(getRawType()); } + StringRef getFilename() const { + if (auto *F = getFile()) + return F->getFilename(); + return ""; + } + StringRef getDirectory() const { + if (auto *F = getFile()) + return F->getDirectory(); + return ""; + } + MDString *getRawName() const { return getOperandAs(0); } Metadata *getRawFile() const { return getOperand(1); } MDString *getRawGetterName() const { return getOperandAs(2); } diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp index 70a67225685..4b1c1f7bbd1 100644 --- a/lib/IR/DebugInfo.cpp +++ b/lib/IR/DebugInfo.cpp @@ -143,20 +143,6 @@ StringRef DIScope::getName() const { return StringRef(); } -StringRef DIScope::getFilename() const { - if (auto *N = get()) - if (auto *F = N->getFile()) - return F->getFilename(); - return ""; -} - -StringRef DIScope::getDirectory() const { - if (auto *N = get()) - if (auto *F = N->getFile()) - return F->getDirectory(); - return ""; -} - void DICompileUnit::replaceSubprograms(DIArray Subprograms) { get()->replaceSubprograms(MDSubprogramArray(Subprograms)); } -- 2.34.1