From: Duncan P. N. Exon Smith Date: Mon, 6 Apr 2015 17:21:05 +0000 (+0000) Subject: DebugInfo: Remove dead code for accessing fields X-Git-Tag: llvmorg-3.7.0-rc1~7486 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=398069064dc90cddafc1f51c513d73ee7806beac;p=platform%2Fupstream%2Fllvm.git DebugInfo: Remove dead code for accessing fields Most fields are now accessed via the new debug info hierarchy. I'll make the rest of this code dead soon. llvm-svn: 234182 --- diff --git a/llvm/include/llvm/IR/DebugInfo.h b/llvm/include/llvm/IR/DebugInfo.h index d2f752c..4bc51e1 100644 --- a/llvm/include/llvm/IR/DebugInfo.h +++ b/llvm/include/llvm/IR/DebugInfo.h @@ -58,65 +58,6 @@ class DIObjCProperty; /// \brief Maps from type identifier to the actual MDNode. typedef DenseMap DITypeIdentifierMap; -class DIHeaderFieldIterator - : public std::iterator { - StringRef Header; - StringRef Current; - -public: - DIHeaderFieldIterator() {} - explicit DIHeaderFieldIterator(StringRef Header) - : Header(Header), Current(Header.slice(0, Header.find('\0'))) {} - StringRef operator*() const { return Current; } - const StringRef *operator->() const { return &Current; } - DIHeaderFieldIterator &operator++() { - increment(); - return *this; - } - DIHeaderFieldIterator operator++(int) { - DIHeaderFieldIterator X(*this); - increment(); - return X; - } - bool operator==(const DIHeaderFieldIterator &X) const { - return Current.data() == X.Current.data(); - } - bool operator!=(const DIHeaderFieldIterator &X) const { - return !(*this == X); - } - - StringRef getHeader() const { return Header; } - StringRef getCurrent() const { return Current; } - StringRef getPrefix() const { - if (Current.begin() == Header.begin()) - return StringRef(); - return Header.slice(0, Current.begin() - Header.begin() - 1); - } - StringRef getSuffix() const { - if (Current.end() == Header.end()) - return StringRef(); - return Header.slice(Current.end() - Header.begin() + 1, StringRef::npos); - } - - /// \brief Get the current field as a number. - /// - /// Convert the current field into a number. Return \c 0 on error. - template T getNumber() const { - T Int; - if (getCurrent().getAsInteger(0, Int)) - return 0; - return Int; - } - -private: - void increment() { - assert(Current.data() != nullptr && "Cannot increment past the end"); - StringRef Suffix = getSuffix(); - Current = Suffix.slice(0, Suffix.find('\0')); - } -}; - /// \brief A thin wraper around MDNode to access encoded debug info. /// /// This should not be stored in a container, because the underlying MDNode may @@ -149,22 +90,11 @@ public: protected: const MDNode *DbgNode; - StringRef getStringField(unsigned Elt) const; - unsigned getUnsignedField(unsigned Elt) const { - return (unsigned)getUInt64Field(Elt); - } - uint64_t getUInt64Field(unsigned Elt) const; - int64_t getInt64Field(unsigned Elt) const; DIDescriptor getDescriptorField(unsigned Elt) const; - template DescTy getFieldAs(unsigned Elt) const { return DescTy(getDescriptorField(Elt)); } - GlobalVariable *getGlobalVariableField(unsigned Elt) const; - Constant *getConstantField(unsigned Elt) const; - Function *getFunctionField(unsigned Elt) const; - public: explicit DIDescriptor(const MDNode *N = nullptr) : DbgNode(N) {} @@ -188,35 +118,6 @@ public: bool operator==(DIDescriptor Other) const { return DbgNode == Other.DbgNode; } bool operator!=(DIDescriptor Other) const { return !operator==(Other); } - StringRef getHeader() const { return getStringField(0); } - - size_t getNumHeaderFields() const { - return std::distance(DIHeaderFieldIterator(getHeader()), - DIHeaderFieldIterator()); - } - - DIHeaderFieldIterator header_begin() const { - return DIHeaderFieldIterator(getHeader()); - } - DIHeaderFieldIterator header_end() const { return DIHeaderFieldIterator(); } - - DIHeaderFieldIterator getHeaderIterator(unsigned Index) const { - // Since callers expect an empty string for out-of-range accesses, we can't - // use std::advance() here. - for (auto I = header_begin(), E = header_end(); I != E; ++I, --Index) - if (!Index) - return I; - return header_end(); - } - - StringRef getHeaderField(unsigned Index) const { - return *getHeaderIterator(Index); - } - - template T getHeaderFieldAs(unsigned Index) const { - return getHeaderIterator(Index).getNumber(); - } - uint16_t getTag() const { if (auto *N = dyn_cast_or_null(get())) return N->getTag(); diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index 70025c7..2f497e9 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -106,56 +106,11 @@ static MDNode *getNodeField(const MDNode *DbgNode, unsigned Elt) { return dyn_cast_or_null(getField(DbgNode, Elt)); } -static StringRef getStringField(const MDNode *DbgNode, unsigned Elt) { - if (MDString *MDS = dyn_cast_or_null(getField(DbgNode, Elt))) - return MDS->getString(); - return StringRef(); -} - -StringRef DIDescriptor::getStringField(unsigned Elt) const { - return ::getStringField(DbgNode, Elt); -} - -uint64_t DIDescriptor::getUInt64Field(unsigned Elt) const { - if (auto *C = getConstantField(Elt)) - if (ConstantInt *CI = dyn_cast(C)) - return CI->getZExtValue(); - - return 0; -} - -int64_t DIDescriptor::getInt64Field(unsigned Elt) const { - if (auto *C = getConstantField(Elt)) - if (ConstantInt *CI = dyn_cast(C)) - return CI->getZExtValue(); - - return 0; -} - DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const { MDNode *Field = getNodeField(DbgNode, Elt); return DIDescriptor(Field); } -GlobalVariable *DIDescriptor::getGlobalVariableField(unsigned Elt) const { - return dyn_cast_or_null(getConstantField(Elt)); -} - -Constant *DIDescriptor::getConstantField(unsigned Elt) const { - if (!DbgNode) - return nullptr; - - if (Elt < DbgNode->getNumOperands()) - if (auto *C = - dyn_cast_or_null(DbgNode->getOperand(Elt))) - return C->getValue(); - return nullptr; -} - -Function *DIDescriptor::getFunctionField(unsigned Elt) const { - return dyn_cast_or_null(getConstantField(Elt)); -} - /// \brief Return the size reported by the variable's type. unsigned DIVariable::getSizeInBits(const DITypeIdentifierMap &Map) { DIType Ty = getType().resolve(Map); diff --git a/llvm/unittests/IR/DebugInfoTest.cpp b/llvm/unittests/IR/DebugInfoTest.cpp index a957b99..53279f5 100644 --- a/llvm/unittests/IR/DebugInfoTest.cpp +++ b/llvm/unittests/IR/DebugInfoTest.cpp @@ -12,59 +12,8 @@ using namespace llvm; -namespace llvm { - -static void PrintTo(const StringRef &S, ::std::ostream *os) { - *os << "(" << (const void *)S.data() << "," << S.size() << ") = '"; - for (auto C : S) - if (C) - *os << C; - else - *os << "\\00"; - *os << "'"; -} -static void PrintTo(const DIHeaderFieldIterator &I, ::std::ostream *os) { - PrintTo(I.getCurrent(), os); - *os << " in "; - PrintTo(I.getHeader(), os); -} - -} // end namespace llvm - namespace { -#define MAKE_FIELD_ITERATOR(S) \ - DIHeaderFieldIterator(StringRef(S, sizeof(S) - 1)) -TEST(DebugInfoTest, DIHeaderFieldIterator) { - ASSERT_EQ(DIHeaderFieldIterator(), DIHeaderFieldIterator()); - - ASSERT_NE(DIHeaderFieldIterator(), MAKE_FIELD_ITERATOR("")); - ASSERT_EQ(DIHeaderFieldIterator(), ++MAKE_FIELD_ITERATOR("")); - ASSERT_EQ("", *DIHeaderFieldIterator("")); - - ASSERT_NE(DIHeaderFieldIterator(), MAKE_FIELD_ITERATOR("stuff")); - ASSERT_EQ(DIHeaderFieldIterator(), ++MAKE_FIELD_ITERATOR("stuff")); - ASSERT_EQ("stuff", *DIHeaderFieldIterator("stuff")); - - ASSERT_NE(DIHeaderFieldIterator(), MAKE_FIELD_ITERATOR("st\0uff")); - ASSERT_NE(DIHeaderFieldIterator(), ++MAKE_FIELD_ITERATOR("st\0uff")); - ASSERT_EQ(DIHeaderFieldIterator(), ++++MAKE_FIELD_ITERATOR("st\0uff")); - ASSERT_EQ("st", *MAKE_FIELD_ITERATOR("st\0uff")); - ASSERT_EQ("uff", *++MAKE_FIELD_ITERATOR("st\0uff")); - - ASSERT_NE(DIHeaderFieldIterator(), MAKE_FIELD_ITERATOR("stuff\0")); - ASSERT_NE(DIHeaderFieldIterator(), ++MAKE_FIELD_ITERATOR("stuff\0")); - ASSERT_EQ(DIHeaderFieldIterator(), ++++MAKE_FIELD_ITERATOR("stuff\0")); - ASSERT_EQ("stuff", *MAKE_FIELD_ITERATOR("stuff\0")); - ASSERT_EQ("", *++MAKE_FIELD_ITERATOR("stuff\0")); - - ASSERT_NE(DIHeaderFieldIterator(), MAKE_FIELD_ITERATOR("\0stuff")); - ASSERT_NE(DIHeaderFieldIterator(), ++MAKE_FIELD_ITERATOR("\0stuff")); - ASSERT_EQ(DIHeaderFieldIterator(), ++++MAKE_FIELD_ITERATOR("\0stuff")); - ASSERT_EQ("", *MAKE_FIELD_ITERATOR("\0stuff")); - ASSERT_EQ("stuff", *++MAKE_FIELD_ITERATOR("\0stuff")); -} - TEST(DIDescriptorTest, getFlag) { // Some valid flags. EXPECT_EQ(DIDescriptor::FlagPublic, DIDescriptor::getFlag("DIFlagPublic"));