diff options
author | Chris Lattner <sabre@nondot.org> | 2009-12-28 07:41:54 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-12-28 07:41:54 +0000 |
commit | c5e08a963973f43c10869cd249c0718d307dd031 (patch) | |
tree | 64a0237283ed4ed33f39bfae9cc7cea6094338b1 /lib | |
parent | 0b86a6f049e4d839bd770241571628d10c980887 (diff) |
move ElementVH out of the MDNode class into the MDNode.cpp file. Among
other things, this avoids vtable and rtti data for it being splatted in
every translation unit that uses it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92207 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VMCore/Metadata.cpp | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp index d632f8d4fc..84cab624c6 100644 --- a/lib/VMCore/Metadata.cpp +++ b/lib/VMCore/Metadata.cpp @@ -47,16 +47,46 @@ MDString *MDString::get(LLVMContext &Context, const char *Str) { } //===----------------------------------------------------------------------===// +// MDNodeElement implementation. +// + +// Use CallbackVH to hold MDNode elements. +namespace llvm { +class MDNodeElement : public CallbackVH { + MDNode *Parent; +public: + MDNodeElement() {} + MDNodeElement(Value *V, MDNode *P) : CallbackVH(V), Parent(P) {} + ~MDNodeElement() {} + + virtual void deleted(); + virtual void allUsesReplacedWith(Value *NV); +}; +} // end namespace llvm. + + +void MDNodeElement::deleted() { + Parent->replaceElement(this->operator Value*(), 0); +} + +void MDNodeElement::allUsesReplacedWith(Value *NV) { + Parent->replaceElement(this->operator Value*(), NV); +} + + + +//===----------------------------------------------------------------------===// // MDNode implementation. // + MDNode::MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals, bool isFunctionLocal) : MetadataBase(Type::getMetadataTy(C), Value::MDNodeVal) { NodeSize = NumVals; - Node = new ElementVH[NodeSize]; - ElementVH *Ptr = Node; + Node = new MDNodeElement[NodeSize]; + MDNodeElement *Ptr = Node; for (unsigned i = 0; i != NumVals; ++i) - *Ptr++ = ElementVH(Vals[i], this); + *Ptr++ = MDNodeElement(Vals[i], this); if (isFunctionLocal) SubclassData |= FunctionLocalBit; } @@ -91,6 +121,14 @@ MDNode::~MDNode() { Node = NULL; } +/// getElement - Return specified element. +Value *MDNode::getElement(unsigned i) const { + assert(i < getNumElements() && "Invalid element number!"); + return Node[i]; +} + + + // Replace value from this node's element list. void MDNode::replaceElement(Value *From, Value *To) { if (From == To || !getType()) @@ -119,7 +157,7 @@ void MDNode::replaceElement(Value *From, Value *To) { for (SmallVector<unsigned, 4>::iterator I = Indexes.begin(), E = Indexes.end(); I != E; ++I) { unsigned Index = *I; - Node[Index] = ElementVH(To, this); + Node[Index] = MDNodeElement(To, this); } // Insert updated "this" into the context's folding node set. |