diff options
author | Chris Lattner <sabre@nondot.org> | 2009-12-30 21:42:11 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-12-30 21:42:11 +0000 |
commit | 54a1f9f9c1e2cf6f4541e998b20f5c7cfbe642d9 (patch) | |
tree | 0fcab2122eded0f20eddece09ebd8ffc21c1fb57 /lib/VMCore | |
parent | 83738a20ddb64838f94461320c6af8ae2a8329ba (diff) | |
download | external_llvm-54a1f9f9c1e2cf6f4541e998b20f5c7cfbe642d9.zip external_llvm-54a1f9f9c1e2cf6f4541e998b20f5c7cfbe642d9.tar.gz external_llvm-54a1f9f9c1e2cf6f4541e998b20f5c7cfbe642d9.tar.bz2 |
do not bother reuniquing mdnodes whose operands drop to null. Doing
so can be a huge performance issue when tearing down modules and mdnodes
are not guaranteed to be unique anyway. This speeds up:
$ time ~/llvm/Release/bin/clang gcc.c -w -S -g
from 72 to 35s, where gcc.c is from:
http://people.csail.mit.edu/smcc/projects/single-file-programs/
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92315 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/Metadata.cpp | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp index d5c1dba..0bed865 100644 --- a/lib/VMCore/Metadata.cpp +++ b/lib/VMCore/Metadata.cpp @@ -87,8 +87,10 @@ void MDNodeElement::allUsesReplacedWith(Value *NV) { /// ~MDNode - Destroy MDNode. MDNode::~MDNode() { - LLVMContextImpl *pImpl = getType()->getContext().pImpl; - pImpl->MDNodeSet.RemoveNode(this); + if (!isNotUniqued()) { + LLVMContextImpl *pImpl = getType()->getContext().pImpl; + pImpl->MDNodeSet.RemoveNode(this); + } delete [] Operands; Operands = NULL; } @@ -97,6 +99,7 @@ MDNode::MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals, bool isFunctionLocal) : MetadataBase(Type::getMetadataTy(C), Value::MDNodeVal) { NumOperands = NumVals; + // FIXME: Coallocate the operand list. These have fixed arity. Operands = new MDNodeElement[NumOperands]; for (unsigned i = 0; i != NumVals; ++i) @@ -146,25 +149,40 @@ void MDNode::replaceElement(MDNodeElement *Op, Value *To) { if (From == To) return; + // Update the operand. + Op->set(To, this); + + // If this node is already not being uniqued (because one of the operands + // already went to null), then there is nothing else to do here. + if (isNotUniqued()) return; + LLVMContextImpl *pImpl = getType()->getContext().pImpl; // Remove "this" from the context map. FoldingSet doesn't have to reprofile // this node to remove it, so we don't care what state the operands are in. pImpl->MDNodeSet.RemoveNode(this); - // Update the operand. - Op->set(To, this); - - // Insert updated "this" into the context's folding node set. - // If a node with same element list already exist then before inserting - // updated "this" into the folding node set, replace all uses of existing - // node with updated "this" node. + // If we are dropping an argument to null, we choose to not unique the MDNode + // anymore. This commonly occurs during destruction, and uniquing these + // brings little reuse. + if (To == 0) { + setIsNotUniqued(); + return; + } + + // Now that the node is out of the folding set, get ready to reinsert it. + // First, check to see if another node with the same operands already exists + // in the set. If it doesn't exist, this returns the position to insert it. FoldingSetNodeID ID; Profile(ID); void *InsertPoint; MDNode *N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint); if (N) { + // FIXME: + // If it already exists in the set, we don't reinsert it, we just claim it + // isn't uniqued. + N->replaceAllUsesWith(this); delete N; N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint); |