From: Duncan P. N. Exon Smith Date: Mon, 2 Feb 2015 19:54:05 +0000 (+0000) Subject: IR: Separate helpers for string operands, NFC X-Git-Tag: llvmorg-3.7.0-rc1~13366 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=442ec0223ba0c129526530bb11d872977a600b70;p=platform%2Fupstream%2Fllvm.git IR: Separate helpers for string operands, NFC llvm-svn: 227846 --- diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h index 28f29ec..4727e1f 100644 --- a/llvm/include/llvm/IR/DebugInfoMetadata.h +++ b/llvm/include/llvm/IR/DebugInfoMetadata.h @@ -100,6 +100,12 @@ protected: } ~DebugNode() {} + StringRef getStringOperand(unsigned I) const { + if (auto *S = cast_or_null(getOperand(I))) + return S->getString(); + return StringRef(); + } + public: unsigned getTag() const { return SubclassData16; } @@ -171,11 +177,7 @@ public: TempGenericDebugNode clone() const { return cloneImpl(); } unsigned getTag() const { return SubclassData16; } - StringRef getHeader() const { - if (auto *S = cast_or_null(getOperand(0))) - return S->getString(); - return StringRef(); - } + StringRef getHeader() const { return getStringOperand(0); } op_iterator dwarf_op_begin() const { return op_begin() + 1; } op_iterator dwarf_op_end() const { return op_end(); } diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp index 9daf785..66dcc8e 100644 --- a/llvm/lib/IR/DebugInfoMetadata.cpp +++ b/llvm/lib/IR/DebugInfoMetadata.cpp @@ -71,6 +71,13 @@ MDLocation *MDLocation::getImpl(LLVMContext &Context, unsigned Line, Storage, Context.pImpl->MDLocations); } +/// \brief Get the MDString, or nullptr if the string is empty. +static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) { + if (S.empty()) + return nullptr; + return MDString::get(Context, S); +} + GenericDebugNode *GenericDebugNode::getImpl(LLVMContext &Context, unsigned Tag, StringRef Header, ArrayRef DwarfOps, @@ -89,8 +96,7 @@ GenericDebugNode *GenericDebugNode::getImpl(LLVMContext &Context, unsigned Tag, } // Use a nullptr for empty headers. - Metadata *PreOps[] = {Header.empty() ? nullptr - : MDString::get(Context, Header)}; + Metadata *PreOps[] = {getCanonicalMDString(Context, Header)}; return storeImpl(new (DwarfOps.size() + 1) GenericDebugNode( Context, Storage, Hash, Tag, PreOps, DwarfOps), Storage, Context.pImpl->GenericDebugNodes);