forked from OSchip/llvm-project
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. llvm-svn: 225685
This commit is contained in:
parent
822f041619
commit
ac3128d901
|
@ -604,25 +604,15 @@ protected:
|
||||||
|
|
||||||
void dropAllReferences();
|
void dropAllReferences();
|
||||||
|
|
||||||
static MDNode *getMDNode(LLVMContext &C, ArrayRef<Metadata *> MDs,
|
|
||||||
bool Insert = true);
|
|
||||||
|
|
||||||
MDOperand *mutable_begin() { return mutable_end() - NumOperands; }
|
MDOperand *mutable_begin() { return mutable_end() - NumOperands; }
|
||||||
MDOperand *mutable_end() { return reinterpret_cast<MDOperand *>(this); }
|
MDOperand *mutable_end() { return reinterpret_cast<MDOperand *>(this); }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static MDNode *get(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
|
static inline MDNode *get(LLVMContext &Context, ArrayRef<Metadata *> MDs);
|
||||||
return getMDNode(Context, MDs, true);
|
static inline MDNode *getIfExists(LLVMContext &Context,
|
||||||
}
|
ArrayRef<Metadata *> MDs);
|
||||||
|
static inline MDNode *getDistinct(LLVMContext &Context,
|
||||||
static MDNode *getIfExists(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
|
ArrayRef<Metadata *> MDs);
|
||||||
return getMDNode(Context, MDs, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Return a distinct node.
|
|
||||||
///
|
|
||||||
/// Return a distinct node -- i.e., a node that is not uniqued.
|
|
||||||
static MDNode *getDistinct(LLVMContext &Context, ArrayRef<Metadata *> MDs);
|
|
||||||
|
|
||||||
/// \brief Return a temporary MDNode
|
/// \brief Return a temporary MDNode
|
||||||
///
|
///
|
||||||
|
@ -774,7 +764,6 @@ private:
|
||||||
class MDTuple : public UniquableMDNode {
|
class MDTuple : public UniquableMDNode {
|
||||||
friend class LLVMContextImpl;
|
friend class LLVMContextImpl;
|
||||||
friend class UniquableMDNode;
|
friend class UniquableMDNode;
|
||||||
friend class MDNode;
|
|
||||||
|
|
||||||
MDTuple(LLVMContext &C, ArrayRef<Metadata *> Vals, bool AllowRAUW)
|
MDTuple(LLVMContext &C, ArrayRef<Metadata *> Vals, bool AllowRAUW)
|
||||||
: UniquableMDNode(C, MDTupleKind, Vals, AllowRAUW) {}
|
: UniquableMDNode(C, MDTupleKind, Vals, AllowRAUW) {}
|
||||||
|
@ -783,15 +772,40 @@ class MDTuple : public UniquableMDNode {
|
||||||
void setHash(unsigned Hash) { MDNodeSubclassData = Hash; }
|
void setHash(unsigned Hash) { MDNodeSubclassData = Hash; }
|
||||||
void recalculateHash();
|
void recalculateHash();
|
||||||
|
|
||||||
|
static MDTuple *getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs,
|
||||||
|
bool ShouldCreate);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// \brief Get the hash, if any.
|
/// \brief Get the hash, if any.
|
||||||
unsigned getHash() const { return MDNodeSubclassData; }
|
unsigned getHash() const { return MDNodeSubclassData; }
|
||||||
|
|
||||||
|
static MDTuple *get(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
|
||||||
|
return getImpl(Context, MDs, /* ShouldCreate */ true);
|
||||||
|
}
|
||||||
|
static MDTuple *getIfExists(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
|
||||||
|
return getImpl(Context, MDs, /* ShouldCreate */ false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief Return a distinct node.
|
||||||
|
///
|
||||||
|
/// Return a distinct node -- i.e., a node that is not uniqued.
|
||||||
|
static MDTuple *getDistinct(LLVMContext &Context, ArrayRef<Metadata *> MDs);
|
||||||
|
|
||||||
static bool classof(const Metadata *MD) {
|
static bool classof(const Metadata *MD) {
|
||||||
return MD->getMetadataID() == MDTupleKind;
|
return MD->getMetadataID() == MDTupleKind;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
MDNode *MDNode::get(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
|
||||||
|
return MDTuple::get(Context, MDs);
|
||||||
|
}
|
||||||
|
MDNode *MDNode::getIfExists(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
|
||||||
|
return MDTuple::getIfExists(Context, MDs);
|
||||||
|
}
|
||||||
|
MDNode *MDNode::getDistinct(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
|
||||||
|
return MDTuple::getDistinct(Context, MDs);
|
||||||
|
}
|
||||||
|
|
||||||
/// \brief Forward declaration of metadata.
|
/// \brief Forward declaration of metadata.
|
||||||
///
|
///
|
||||||
/// Forward declaration of metadata, in the form of a basic tuple. Unlike \a
|
/// Forward declaration of metadata, in the form of a basic tuple. Unlike \a
|
||||||
|
|
|
@ -581,15 +581,15 @@ void UniquableMDNode::handleChangedOperand(void *Ref, Metadata *New) {
|
||||||
storeDistinctInContext();
|
storeDistinctInContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
MDNode *MDNode::getMDNode(LLVMContext &Context, ArrayRef<Metadata *> MDs,
|
MDTuple *MDTuple::getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs,
|
||||||
bool Insert) {
|
bool ShouldCreate) {
|
||||||
auto &Store = Context.pImpl->MDTuples;
|
|
||||||
|
|
||||||
MDTupleInfo::KeyTy Key(MDs);
|
MDTupleInfo::KeyTy Key(MDs);
|
||||||
|
|
||||||
|
auto &Store = Context.pImpl->MDTuples;
|
||||||
auto I = Store.find_as(Key);
|
auto I = Store.find_as(Key);
|
||||||
if (I != Store.end())
|
if (I != Store.end())
|
||||||
return *I;
|
return *I;
|
||||||
if (!Insert)
|
if (!ShouldCreate)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
// Coallocate space for the node and Operands together, then placement new.
|
// Coallocate space for the node and Operands together, then placement new.
|
||||||
|
@ -599,7 +599,7 @@ MDNode *MDNode::getMDNode(LLVMContext &Context, ArrayRef<Metadata *> MDs,
|
||||||
return N;
|
return N;
|
||||||
}
|
}
|
||||||
|
|
||||||
MDNode *MDNode::getDistinct(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
|
MDTuple *MDTuple::getDistinct(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
|
||||||
auto *N = new (MDs.size()) MDTuple(Context, MDs, /* AllowRAUW */ false);
|
auto *N = new (MDs.size()) MDTuple(Context, MDs, /* AllowRAUW */ false);
|
||||||
N->storeDistinctInContext();
|
N->storeDistinctInContext();
|
||||||
return N;
|
return N;
|
||||||
|
|
Loading…
Reference in New Issue