[llvm] r227846 - IR: Separate helpers for string operands, NFC

Duncan P. N. Exon Smith dexonsmith at apple.com
Mon Feb 2 11:54:05 PST 2015


Author: dexonsmith
Date: Mon Feb  2 13:54:05 2015
New Revision: 227846

URL: http://llvm.org/viewvc/llvm-project?rev=227846&view=rev
Log:
IR: Separate helpers for string operands, NFC

Modified:
    llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
    llvm/trunk/lib/IR/DebugInfoMetadata.cpp

Modified: llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfoMetadata.h?rev=227846&r1=227845&r2=227846&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Mon Feb  2 13:54:05 2015
@@ -100,6 +100,12 @@ protected:
   }
   ~DebugNode() {}
 
+  StringRef getStringOperand(unsigned I) const {
+    if (auto *S = cast_or_null<MDString>(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<MDString>(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(); }

Modified: llvm/trunk/lib/IR/DebugInfoMetadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfoMetadata.cpp?rev=227846&r1=227845&r2=227846&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfoMetadata.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfoMetadata.cpp Mon Feb  2 13:54:05 2015
@@ -71,6 +71,13 @@ MDLocation *MDLocation::getImpl(LLVMCont
                    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<Metadata *> DwarfOps,
@@ -89,8 +96,7 @@ GenericDebugNode *GenericDebugNode::getI
   }
 
   // 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);





More information about the llvm-commits mailing list