return StringRef();
}
+ static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) {
+ if (S.empty())
+ return nullptr;
+ return MDString::get(Context, S);
+ }
+
public:
unsigned getTag() const { return SubclassData16; }
StringRef Header,
ArrayRef<Metadata *> DwarfOps,
StorageType Storage,
+ bool ShouldCreate = true) {
+ return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
+ DwarfOps, Storage, ShouldCreate);
+ }
+
+ static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
+ MDString *Header,
+ ArrayRef<Metadata *> DwarfOps,
+ StorageType Storage,
bool ShouldCreate = true);
TempGenericDebugNode cloneImpl() const {
DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, StringRef Header,
ArrayRef<Metadata *> DwarfOps),
(Tag, Header, DwarfOps))
+ DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, MDString *Header,
+ ArrayRef<Metadata *> DwarfOps),
+ (Tag, Header, DwarfOps))
/// \brief Return a (temporary) clone of this.
TempGenericDebugNode clone() const { return cloneImpl(); }
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)
}
// 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);