[llvm-commits] [llvm] r122114 - in /llvm/trunk: include/llvm/Support/ValueHandle.h include/llvm/Value.h lib/VMCore/Value.cpp

Chris Lattner clattner at apple.com
Sun Dec 19 12:22:56 PST 2010


On Dec 17, 2010, at 4:07 PM, Owen Anderson wrote:

> Author: resistor
> Date: Fri Dec 17 18:07:15 2010
> New Revision: 122114
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=122114&view=rev
> Log:
> Add support to CallbackVH to receive notification when a Value's use-list changes.

Hi Owen,

What do you plan to use this for?  I don't like that this penalizes all clients of the IR (by making addUse more expensive)... what does your client need this for?

-Chris

> 
> Modified:
>    llvm/trunk/include/llvm/Support/ValueHandle.h
>    llvm/trunk/include/llvm/Value.h
>    llvm/trunk/lib/VMCore/Value.cpp
> 
> Modified: llvm/trunk/include/llvm/Support/ValueHandle.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ValueHandle.h?rev=122114&r1=122113&r2=122114&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Support/ValueHandle.h (original)
> +++ llvm/trunk/include/llvm/Support/ValueHandle.h Fri Dec 17 18:07:15 2010
> @@ -105,6 +105,7 @@
>   // 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 @@
>   /// 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
> 
> Modified: llvm/trunk/include/llvm/Value.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Value.h?rev=122114&r1=122113&r2=122114&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Value.h (original)
> +++ llvm/trunk/include/llvm/Value.h Fri Dec 17 18:07:15 2010
> @@ -195,7 +195,7 @@
> 
>   /// 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 
> 
> Modified: llvm/trunk/lib/VMCore/Value.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Value.cpp?rev=122114&r1=122113&r2=122114&view=diff
> ==============================================================================
> --- llvm/trunk/lib/VMCore/Value.cpp (original)
> +++ llvm/trunk/lib/VMCore/Value.cpp Fri Dec 17 18:07:15 2010
> @@ -281,6 +281,16 @@
> }
> 
> 
> +/// 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::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");
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list