IR: Allow GenericDebugNode construction from MDString
Allow `GenericDebugNode` construction directly from `MDString`, rather
than requiring `StringRef`s. I've refactored the `StringRef`
constructors to use these. There's no real functionality change here,
except for exposing the lower-level API.
The purpose of this is to simplify construction of string operands when
reading bitcode. It's unnecessarily indirect to parse an `MDString` ID,
lookup the `MDString` in the bitcode reader list, get the `StringRef`
out of that, and then have `GenericDebugNode::getImpl()` use
`MDString::get()` to acquire the original `MDString`. Instead, this
allows the bitcode reader to directly pass in the `MDString`.
llvm-svn: 227848
diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp
index 66dcc8e..21a95f9 100644
--- a/llvm/lib/IR/DebugInfoMetadata.cpp
+++ b/llvm/lib/IR/DebugInfoMetadata.cpp
@@ -71,21 +71,24 @@
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);
+static StringRef getString(const MDString *S) {
+ if (S)
+ return S->getString();
+ return StringRef();
+}
+
+static bool isCanonical(const MDString *S) {
+ return !S || !S->getString().empty();
}
GenericDebugNode *GenericDebugNode::getImpl(LLVMContext &Context, unsigned Tag,
- StringRef Header,
+ MDString *Header,
ArrayRef<Metadata *> DwarfOps,
StorageType Storage,
bool ShouldCreate) {
unsigned Hash = 0;
if (Storage == Uniqued) {
- GenericDebugNodeInfo::KeyTy Key(Tag, Header, DwarfOps);
+ GenericDebugNodeInfo::KeyTy Key(Tag, getString(Header), DwarfOps);
if (auto *N = getUniqued(Context.pImpl->GenericDebugNodes, Key))
return N;
if (!ShouldCreate)
@@ -96,7 +99,8 @@
}
// Use a nullptr for empty headers.
- Metadata *PreOps[] = {getCanonicalMDString(Context, Header)};
+ assert(isCanonical(Header) && "Expected canonical MDString");
+ Metadata *PreOps[] = {Header};
return storeImpl(new (DwarfOps.size() + 1) GenericDebugNode(
Context, Storage, Hash, Tag, PreOps, DwarfOps),
Storage, Context.pImpl->GenericDebugNodes);