From 942623540b24fbd3df5df314ee2e02a98a0909de Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Mon, 12 Jan 2015 20:21:37 +0000 Subject: [PATCH] IR: Move creation logic to MDNodeFwdDecl, NFC Same as with `MDTuple`, factor out a `friend MDNode` by moving creation logic to the concrete subclass. llvm-svn: 225690 --- llvm/include/llvm/IR/Metadata.h | 5 ++++- llvm/lib/IR/Metadata.cpp | 8 ++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/llvm/include/llvm/IR/Metadata.h b/llvm/include/llvm/IR/Metadata.h index d06621df3aac..1f327f6bdb3f 100644 --- a/llvm/include/llvm/IR/Metadata.h +++ b/llvm/include/llvm/IR/Metadata.h @@ -813,7 +813,6 @@ MDNode *MDNode::getDistinct(LLVMContext &Context, ArrayRef MDs) { /// uniqued, and is suitable for forward references. class MDNodeFwdDecl : public MDNode, ReplaceableMetadataImpl { friend class Metadata; - friend class MDNode; friend class ReplaceableMetadataImpl; MDNodeFwdDecl(LLVMContext &C, ArrayRef Vals) @@ -823,6 +822,10 @@ public: ~MDNodeFwdDecl() { dropAllReferences(); } using MDNode::operator delete; + static MDNodeFwdDecl *get(LLVMContext &Context, ArrayRef MDs) { + return new (MDs.size()) MDNodeFwdDecl(Context, MDs); + } + static bool classof(const Metadata *MD) { return MD->getMetadataID() == MDNodeFwdDeclKind; } diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp index 3d444660c67c..9088a75156ed 100644 --- a/llvm/lib/IR/Metadata.cpp +++ b/llvm/lib/IR/Metadata.cpp @@ -607,14 +607,10 @@ MDTuple *MDTuple::getDistinct(LLVMContext &Context, ArrayRef MDs) { MDNodeFwdDecl *MDNode::getTemporary(LLVMContext &Context, ArrayRef MDs) { - MDNodeFwdDecl *N = new (MDs.size()) MDNodeFwdDecl(Context, MDs); - return N; + return MDNodeFwdDecl::get(Context, MDs); } -void MDNode::deleteTemporary(MDNode *N) { - assert(isa(N) && "Expected forward declaration"); - delete cast(N); -} +void MDNode::deleteTemporary(MDNode *N) { delete cast(N); } void UniquableMDNode::storeDistinctInContext() { assert(!IsDistinctInContext && "Expected newly distinct metadata");