diff options
| author | Chris Lattner <sabre@nondot.org> | 2009-12-28 09:24:53 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2009-12-28 09:24:53 +0000 |
| commit | c6d17e29dfd6e603ba64fda201814124346775bd (patch) | |
| tree | 88fc8e2f3ec985afee5dc01b86316c9aa5ae8101 | |
| parent | f543eff71c557c13ccda914e7d70d4c214ba433c (diff) | |
| download | bcm5719-llvm-c6d17e29dfd6e603ba64fda201814124346775bd.tar.gz bcm5719-llvm-c6d17e29dfd6e603ba64fda201814124346775bd.zip | |
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.
llvm-svn: 92220
| -rw-r--r-- | llvm/lib/VMCore/Metadata.cpp | 39 |
1 files changed, 13 insertions, 26 deletions
diff --git a/llvm/lib/VMCore/Metadata.cpp b/llvm/lib/VMCore/Metadata.cpp index dd6a0f61348..eddd8b070a6 100644 --- a/llvm/lib/VMCore/Metadata.cpp +++ b/llvm/lib/VMCore/Metadata.cpp @@ -145,31 +145,21 @@ Value *MDNode::getElement(unsigned i) const { 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 @@ void MDNode::replaceElement(Value *From, Value *To) { 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); } //===----------------------------------------------------------------------===// |

