change NamedMDNode to use a pimpl for its operand list instead

of making it a declared part of the value.

llvm-svn: 92209
This commit is contained in:
Chris Lattner 2009-12-28 08:07:14 +00:00
parent 0a47dbff64
commit 4967dbad20
2 changed files with 38 additions and 18 deletions

View File

@ -158,7 +158,7 @@ class NamedMDNode : public MetadataBase, public ilist_node<NamedMDNode> {
NamedMDNode(const NamedMDNode &); // DO NOT IMPLEMENT
Module *Parent;
SmallVector<TrackingVH<MetadataBase>, 4> Node;
void *Operands; // SmallVector<TrackingVH<MetadataBase>, 4>
void setParent(Module *M) { Parent = M; }
protected:
@ -188,21 +188,14 @@ public:
inline const Module *getParent() const { return Parent; }
/// getElement - Return specified element.
MetadataBase *getElement(unsigned i) const {
assert(i < getNumElements() && "Invalid element number!");
return Node[i];
}
MetadataBase *getElement(unsigned i) const;
/// getNumElements - Return number of NamedMDNode elements.
unsigned getNumElements() const {
return (unsigned)Node.size();
}
unsigned getNumElements() const;
/// addElement - Add metadata element.
void addElement(MetadataBase *M) {
Node.push_back(TrackingVH<MetadataBase>(M));
}
void addElement(MetadataBase *M);
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const NamedMDNode *) { return true; }
static bool classof(const Value *V) {

View File

@ -226,12 +226,19 @@ bool MDNode::getLocalFunction(Function *LocalFunction,
//===----------------------------------------------------------------------===//
// NamedMDNode implementation.
//
static SmallVector<TrackingVH<MetadataBase>, 4> &getNMDOps(void *Operands) {
return *(SmallVector<TrackingVH<MetadataBase>, 4>*)Operands;
}
NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N,
MetadataBase *const *MDs,
unsigned NumMDs, Module *ParentModule)
: MetadataBase(Type::getMetadataTy(C), Value::NamedMDNodeVal), Parent(0) {
setName(N);
Operands = new SmallVector<TrackingVH<MetadataBase>, 4>();
SmallVector<TrackingVH<MetadataBase>, 4> &Node = getNMDOps(Operands);
for (unsigned i = 0; i != NumMDs; ++i)
Node.push_back(TrackingVH<MetadataBase>(MDs[i]));
@ -242,12 +249,35 @@ NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N,
NamedMDNode *NamedMDNode::Create(const NamedMDNode *NMD, Module *M) {
assert(NMD && "Invalid source NamedMDNode!");
SmallVector<MetadataBase *, 4> Elems;
Elems.reserve(NMD->getNumElements());
for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++i)
Elems.push_back(NMD->getElement(i));
return new NamedMDNode(NMD->getContext(), NMD->getName().data(),
Elems.data(), Elems.size(), M);
}
NamedMDNode::~NamedMDNode() {
dropAllReferences();
delete &getNMDOps(Operands);
}
/// getNumElements - Return number of NamedMDNode elements.
unsigned NamedMDNode::getNumElements() const {
return (unsigned)getNMDOps(Operands).size();
}
/// getElement - Return specified element.
MetadataBase *NamedMDNode::getElement(unsigned i) const {
assert(i < getNumElements() && "Invalid element number!");
return getNMDOps(Operands)[i];
}
/// addElement - Add metadata element.
void NamedMDNode::addElement(MetadataBase *M) {
getNMDOps(Operands).push_back(TrackingVH<MetadataBase>(M));
}
/// eraseFromParent - Drop all references and remove the node from parent
/// module.
void NamedMDNode::eraseFromParent() {
@ -256,12 +286,9 @@ void NamedMDNode::eraseFromParent() {
/// dropAllReferences - Remove all uses and clear node vector.
void NamedMDNode::dropAllReferences() {
Node.clear();
getNMDOps(Operands).clear();
}
NamedMDNode::~NamedMDNode() {
dropAllReferences();
}
//===----------------------------------------------------------------------===//
// MetadataContextImpl implementation.