IR: Separate helpers for string operands, NFC
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 2 Feb 2015 19:54:05 +0000 (19:54 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 2 Feb 2015 19:54:05 +0000 (19:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227846 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/DebugInfoMetadata.h
lib/IR/DebugInfoMetadata.cpp

index 28f29ec8353e1320f4b4d13ccd30b50f0a6a12b6..4727e1f9990c352c1696d47b4f5f6676f667ea47 100644 (file)
@@ -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(); }
index 9daf7857ba6670718d71a8777c6f606d691aa77b..66dcc8e80558b4312efba5be3008a767a9f75a55 100644 (file)
@@ -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<Metadata *> 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);