[llvm-commits] [llvm] r92220 - /llvm/trunk/lib/VMCore/Metadata.cpp
Chris Lattner
sabre at nondot.org
Mon Dec 28 01:24:53 PST 2009
Author: lattner
Date: Mon Dec 28 03:24:53 2009
New Revision: 92220
URL: http://llvm.org/viewvc/llvm-project?rev=92220&view=rev
Log:
Eliminate two bits of ugliness in MDNode::replaceElement:
eliminate the temporary smallvector, and only do FindNodeOrInsertPos
twice if the first one succeeds and we delete a node.
Modified:
llvm/trunk/lib/VMCore/Metadata.cpp
Modified: llvm/trunk/lib/VMCore/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Metadata.cpp?rev=92220&r1=92219&r2=92220&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Metadata.cpp (original)
+++ llvm/trunk/lib/VMCore/Metadata.cpp Mon Dec 28 03:24:53 2009
@@ -145,31 +145,21 @@
void MDNode::replaceElement(Value *From, Value *To) {
if (From == To || !getType())
return;
- LLVMContext &Context = getType()->getContext();
- LLVMContextImpl *pImpl = Context.pImpl;
+ 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);
+
// Find value. This is a linear search, do something if it consumes
// lot of time. It is possible that to have multiple instances of
// From in this MDNode's element list.
- SmallVector<unsigned, 4> Indexes;
- unsigned Index = 0;
- for (unsigned i = 0, e = getNumElements(); i != e; ++i, ++Index) {
- Value *V = getElement(i);
- if (V && V == From)
- Indexes.push_back(Index);
+ for (unsigned i = 0, e = getNumElements(); i != e; ++i) {
+ if (Operands[i] == From)
+ Operands[i].set(To, this);
}
- if (Indexes.empty())
- return;
-
- // Remove "this" from the context map.
- pImpl->MDNodeSet.RemoveNode(this);
-
- // Replace From element(s) in place.
- for (SmallVector<unsigned, 4>::iterator I = Indexes.begin(), E = Indexes.end();
- I != E; ++I)
- Operands[*I].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
@@ -182,15 +172,12 @@
if (N) {
N->replaceAllUsesWith(this);
delete N;
- N = 0;
+ N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
+ assert(N == 0 && "shouldn't be in the map now!"); (void)N;
}
- N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
- if (!N) {
- // InsertPoint will have been set by the FindNodeOrInsertPos call.
- N = this;
- pImpl->MDNodeSet.InsertNode(N, InsertPoint);
- }
+ // InsertPoint will have been set by the FindNodeOrInsertPos call.
+ pImpl->MDNodeSet.InsertNode(this, InsertPoint);
}
//===----------------------------------------------------------------------===//
More information about the llvm-commits
mailing list