[llvm-commits] [llvm] r92221 - in /llvm/trunk: include/llvm/Metadata.h lib/VMCore/Metadata.cpp
Chris Lattner
sabre at nondot.org
Mon Dec 28 01:32:11 PST 2009
Author: lattner
Date: Mon Dec 28 03:32:10 2009
New Revision: 92221
URL: http://llvm.org/viewvc/llvm-project?rev=92221&view=rev
Log:
avoid a completely unneeded linear walk.
Modified:
llvm/trunk/include/llvm/Metadata.h
llvm/trunk/lib/VMCore/Metadata.cpp
Modified: llvm/trunk/include/llvm/Metadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Metadata.h?rev=92221&r1=92220&r2=92221&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Metadata.h (original)
+++ llvm/trunk/include/llvm/Metadata.h Mon Dec 28 03:32:10 2009
@@ -102,7 +102,7 @@
};
// Replace each instance of F from the element list of this node with T.
- void replaceElement(Value *F, Value *T);
+ void replaceElement(MDNodeElement *Op, Value *NewVal);
protected:
explicit MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals,
Modified: llvm/trunk/lib/VMCore/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Metadata.cpp?rev=92221&r1=92220&r2=92221&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Metadata.cpp (original)
+++ llvm/trunk/lib/VMCore/Metadata.cpp Mon Dec 28 03:32:10 2009
@@ -76,11 +76,11 @@
void MDNodeElement::deleted() {
- Parent->replaceElement(this->operator Value*(), 0);
+ Parent->replaceElement(this, 0);
}
void MDNodeElement::allUsesReplacedWith(Value *NV) {
- Parent->replaceElement(this->operator Value*(), NV);
+ Parent->replaceElement(this, NV);
}
@@ -142,8 +142,10 @@
// Replace value from this node's element list.
-void MDNode::replaceElement(Value *From, Value *To) {
- if (From == To || !getType())
+void MDNode::replaceElement(MDNodeElement *Op, Value *To) {
+ Value *From = *Op;
+
+ if (From == To)
return;
LLVMContextImpl *pImpl = getType()->getContext().pImpl;
@@ -151,14 +153,9 @@
// 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.
- for (unsigned i = 0, e = getNumElements(); i != e; ++i) {
- if (Operands[i] == From)
- Operands[i].set(To, 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
More information about the llvm-commits
mailing list