llvm.org GIT mirror llvm / dc6a335
IR: Move creation logic down to MDTuple, NFC Move creation logic for `MDTuple`s down where it belongs. Once there are a few more subclasses, these functions really won't make much sense here (the `friend` relationship was already awkward). For now, leave the `MDNode` versions around, but have it forward down. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225685 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 5 years ago
2 changed file(s) with 36 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
603603
604604 void dropAllReferences();
605605
606 static MDNode *getMDNode(LLVMContext &C, ArrayRef MDs,
607 bool Insert = true);
608
609606 MDOperand *mutable_begin() { return mutable_end() - NumOperands; }
610607 MDOperand *mutable_end() { return reinterpret_cast(this); }
611608
612609 public:
613 static MDNode *get(LLVMContext &Context, ArrayRef MDs) {
614 return getMDNode(Context, MDs, true);
615 }
616
617 static MDNode *getIfExists(LLVMContext &Context, ArrayRef MDs) {
618 return getMDNode(Context, MDs, false);
619 }
620
621 /// \brief Return a distinct node.
622 ///
623 /// Return a distinct node -- i.e., a node that is not uniqued.
624 static MDNode *getDistinct(LLVMContext &Context, ArrayRef MDs);
610 static inline MDNode *get(LLVMContext &Context, ArrayRef MDs);
611 static inline MDNode *getIfExists(LLVMContext &Context,
612 ArrayRef MDs);
613 static inline MDNode *getDistinct(LLVMContext &Context,
614 ArrayRef MDs);
625615
626616 /// \brief Return a temporary MDNode
627617 ///
773763 class MDTuple : public UniquableMDNode {
774764 friend class LLVMContextImpl;
775765 friend class UniquableMDNode;
776 friend class MDNode;
777766
778767 MDTuple(LLVMContext &C, ArrayRef Vals, bool AllowRAUW)
779768 : UniquableMDNode(C, MDTupleKind, Vals, AllowRAUW) {}
782771 void setHash(unsigned Hash) { MDNodeSubclassData = Hash; }
783772 void recalculateHash();
784773
774 static MDTuple *getImpl(LLVMContext &Context, ArrayRef MDs,
775 bool ShouldCreate);
776
785777 public:
786778 /// \brief Get the hash, if any.
787779 unsigned getHash() const { return MDNodeSubclassData; }
788780
781 static MDTuple *get(LLVMContext &Context, ArrayRef MDs) {
782 return getImpl(Context, MDs, /* ShouldCreate */ true);
783 }
784 static MDTuple *getIfExists(LLVMContext &Context, ArrayRef MDs) {
785 return getImpl(Context, MDs, /* ShouldCreate */ false);
786 }
787
788 /// \brief Return a distinct node.
789 ///
790 /// Return a distinct node -- i.e., a node that is not uniqued.
791 static MDTuple *getDistinct(LLVMContext &Context, ArrayRef MDs);
792
789793 static bool classof(const Metadata *MD) {
790794 return MD->getMetadataID() == MDTupleKind;
791795 }
792796 };
797
798 MDNode *MDNode::get(LLVMContext &Context, ArrayRef MDs) {
799 return MDTuple::get(Context, MDs);
800 }
801 MDNode *MDNode::getIfExists(LLVMContext &Context, ArrayRef MDs) {
802 return MDTuple::getIfExists(Context, MDs);
803 }
804 MDNode *MDNode::getDistinct(LLVMContext &Context, ArrayRef MDs) {
805 return MDTuple::getDistinct(Context, MDs);
806 }
793807
794808 /// \brief Forward declaration of metadata.
795809 ///
580580 storeDistinctInContext();
581581 }
582582
583 MDNode *MDNode::getMDNode(LLVMContext &Context, ArrayRef MDs,
584 bool Insert) {
583 MDTuple *MDTuple::getImpl(LLVMContext &Context, ArrayRef MDs,
584 bool ShouldCreate) {
585 MDTupleInfo::KeyTy Key(MDs);
586
585587 auto &Store = Context.pImpl->MDTuples;
586
587 MDTupleInfo::KeyTy Key(MDs);
588588 auto I = Store.find_as(Key);
589589 if (I != Store.end())
590590 return *I;
591 if (!Insert)
591 if (!ShouldCreate)
592592 return nullptr;
593593
594594 // Coallocate space for the node and Operands together, then placement new.
598598 return N;
599599 }
600600
601 MDNode *MDNode::getDistinct(LLVMContext &Context, ArrayRef MDs) {
601 MDTuple *MDTuple::getDistinct(LLVMContext &Context, ArrayRef MDs) {
602602 auto *N = new (MDs.size()) MDTuple(Context, MDs, /* AllowRAUW */ false);
603603 N->storeDistinctInContext();
604604 return N;