summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2010-12-18 00:07:15 +0000
committerOwen Anderson <resistor@mac.com>2010-12-18 00:07:15 +0000
commita479b2325635544fb2c955c4d7e8b6ea9582120f (patch)
tree04d5a0f32335c46cb014aeda4e86d7eb0425f741
parent89cab93fe999f6d81b4b99a71ac797b7ecfec277 (diff)
downloadllvm-a479b2325635544fb2c955c4d7e8b6ea9582120f.tar.gz
llvm-a479b2325635544fb2c955c4d7e8b6ea9582120f.tar.bz2
llvm-a479b2325635544fb2c955c4d7e8b6ea9582120f.tar.xz
Add support to CallbackVH to receive notification when a Value's use-list changes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122114 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Support/ValueHandle.h6
-rw-r--r--include/llvm/Value.h2
-rw-r--r--lib/VMCore/Value.cpp38
3 files changed, 45 insertions, 1 deletions
diff --git a/include/llvm/Support/ValueHandle.h b/include/llvm/Support/ValueHandle.h
index c0cdc35e99..3fdef6b545 100644
--- a/include/llvm/Support/ValueHandle.h
+++ b/include/llvm/Support/ValueHandle.h
@@ -105,6 +105,7 @@ private:
// Callbacks made from Value.
static void ValueIsDeleted(Value *V);
static void ValueIsRAUWd(Value *Old, Value *New);
+ static void ValueAddedUse(Use &U);
// Internal implementation details.
ValueHandleBase **getPrevPtr() const { return PrevPair.getPointer(); }
@@ -389,6 +390,11 @@ public:
/// implemented as a CallbackVH, it would use this method to call
/// setValPtr(new_value). AssertingVH would do nothing in this method.
virtual void allUsesReplacedWith(Value *) {}
+
+ /// Called when a new Use is added to the use-list of this->getValPtr(),
+ /// after the Use has been appended to the list. Other VH kinds would ignore
+ /// this callback, but clients can use it to trigger re-analysis of Values.
+ virtual void addedUse(Use &U) {}
};
// Specialize simplify_type to allow CallbackVH to participate in
diff --git a/include/llvm/Value.h b/include/llvm/Value.h
index b530287829..df610aa7bd 100644
--- a/include/llvm/Value.h
+++ b/include/llvm/Value.h
@@ -195,7 +195,7 @@ public:
/// addUse - This method should only be used by the Use class.
///
- void addUse(Use &U) { U.addToList(&UseList); }
+ void addUse(Use &U);
/// An enumeration for keeping track of the concrete subclass of Value that
/// is actually instantiated. Values of this enumeration are kept in the
diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp
index 76cfb9082a..3c32c566e1 100644
--- a/lib/VMCore/Value.cpp
+++ b/lib/VMCore/Value.cpp
@@ -281,6 +281,16 @@ void Value::takeName(Value *V) {
}
+/// addUse - This method should only be used by the Use class.
+///
+void Value::addUse(Use &U) {
+ U.addToList(&UseList);
+
+ // Notify all ValueHandles (if present) that this value added a Use.
+ if (HasValueHandle)
+ ValueHandleBase::ValueAddedUse(U);
+}
+
// uncheckedReplaceAllUsesWith - This is exactly the same as replaceAllUsesWith,
// except that it doesn't have all of the asserts. The asserts fail because we
// are half-way done resolving types, which causes some types to exist as two
@@ -569,6 +579,34 @@ void ValueHandleBase::ValueIsDeleted(Value *V) {
}
}
+void ValueHandleBase::ValueAddedUse(Use &U) {
+ assert(U->HasValueHandle && "Should only be called if ValueHandles present");
+
+ // Get the linked list base, which is guaranteed to exist since the
+ // HasValueHandle flag is set.
+ LLVMContextImpl *pImpl = U->getContext().pImpl;
+ ValueHandleBase *Entry = pImpl->ValueHandles[U.get()];
+
+ assert(Entry && "Value bit set but no entries exist");
+
+ // We use a local ValueHandleBase as an iterator so that
+ // ValueHandles can add and remove themselves from the list without
+ // breaking our iteration. This is not really an AssertingVH; we
+ // just have to give ValueHandleBase some kind.
+ for (ValueHandleBase Iterator(Assert, *Entry); Entry; Entry = Iterator.Next) {
+ Iterator.RemoveFromUseList();
+ Iterator.AddToExistingUseListAfter(Entry);
+ assert(Entry->Next == &Iterator && "Loop invariant broken.");
+
+ switch (Entry->getKind()) {
+ default:
+ break;
+ case Callback:
+ static_cast<CallbackVH*>(Entry)->addedUse(U);
+ break;
+ }
+ }
+}
void ValueHandleBase::ValueIsRAUWd(Value *Old, Value *New) {
assert(Old->HasValueHandle &&"Should only be called if ValueHandles present");