diff options
author | Bill Wendling <isanbard@gmail.com> | 2012-04-08 10:20:49 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2012-04-08 10:20:49 +0000 |
commit | 69b2c71abb3fa17612ebfb1fb804b656ea47ab8f (patch) | |
tree | 30b93fc4db3a0c187684552a1a665231a8d3fdd9 /lib/VMCore/Metadata.cpp | |
parent | 5252c432dd93147fa70a536be58a15ef329de0b7 (diff) | |
download | external_llvm-69b2c71abb3fa17612ebfb1fb804b656ea47ab8f.zip external_llvm-69b2c71abb3fa17612ebfb1fb804b656ea47ab8f.tar.gz external_llvm-69b2c71abb3fa17612ebfb1fb804b656ea47ab8f.tar.bz2 |
Remove the 'Parent' pointer from the MDNodeOperand class.
An MDNode has a list of MDNodeOperands allocated directly after it as part of
its allocation. Therefore, the Parent of the MDNodeOperands can be found by
walking back through the operands to the beginning of that list. Mark the first
operand's value pointer as being the 'first' operand so that we know where the
beginning of said list is.
This saves a *lot* of space during LTO with -O0 -g flags.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154280 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Metadata.cpp')
-rw-r--r-- | lib/VMCore/Metadata.cpp | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp index d5f6aa9..e6fd64c 100644 --- a/lib/VMCore/Metadata.cpp +++ b/lib/VMCore/Metadata.cpp @@ -50,14 +50,26 @@ MDString *MDString::get(LLVMContext &Context, StringRef Str) { // Use CallbackVH to hold MDNode operands. namespace llvm { class MDNodeOperand : public CallbackVH { - MDNode *Parent; + MDNode *getParent() { + MDNodeOperand *Cur = this; + + while (Cur->getValPtrInt() != 1) + --Cur; + + assert(Cur->getValPtrInt() == 1 && + "Couldn't find the beginning of the operand list!"); + return reinterpret_cast<MDNode*>(Cur) - 1; + } + public: - MDNodeOperand(Value *V, MDNode *P) : CallbackVH(V), Parent(P) {} + MDNodeOperand(Value *V) : CallbackVH(V) {} ~MDNodeOperand() {} - void set(Value *V) { - setValPtr(V); - } + void set(Value *V) { this->setValPtr(V); } + + /// setAsFirstOperand - Accessor method to mark the operand as the first in + /// the list. + void setAsFirstOperand(unsigned V) { this->setValPtrInt(V); } virtual void deleted(); virtual void allUsesReplacedWith(Value *NV); @@ -66,15 +78,13 @@ public: void MDNodeOperand::deleted() { - Parent->replaceOperand(this, 0); + getParent()->replaceOperand(this, 0); } void MDNodeOperand::allUsesReplacedWith(Value *NV) { - Parent->replaceOperand(this, NV); + getParent()->replaceOperand(this, NV); } - - //===----------------------------------------------------------------------===// // MDNode implementation. // @@ -102,8 +112,13 @@ MDNode::MDNode(LLVMContext &C, ArrayRef<Value*> Vals, bool isFunctionLocal) // Initialize the operand list, which is co-allocated on the end of the node. unsigned i = 0; for (MDNodeOperand *Op = getOperandPtr(this, 0), *E = Op+NumOperands; - Op != E; ++Op, ++i) - new (Op) MDNodeOperand(Vals[i], this); + Op != E; ++Op, ++i) { + new (Op) MDNodeOperand(Vals[i]); + + // Mark the first MDNodeOperand as being the first in the list of operands. + if (i == 0) + Op->setAsFirstOperand(1); + } } |