|
@@ -34,7 +34,7 @@ protected:
|
|
///
|
|
///
|
|
/// This is to avoid having a vtable for the light-weight handle pointers. The
|
|
/// This is to avoid having a vtable for the light-weight handle pointers. The
|
|
/// fully general Callback version does have a vtable.
|
|
/// fully general Callback version does have a vtable.
|
|
- enum HandleBaseKind { Assert, Callback, WeakTracking };
|
|
|
|
|
|
+ enum HandleBaseKind { Assert, Callback, Weak, WeakTracking };
|
|
|
|
|
|
ValueHandleBase(const ValueHandleBase &RHS)
|
|
ValueHandleBase(const ValueHandleBase &RHS)
|
|
: ValueHandleBase(RHS.PrevPair.getInt(), RHS) {}
|
|
: ValueHandleBase(RHS.PrevPair.getInt(), RHS) {}
|
|
@@ -46,7 +46,7 @@ protected:
|
|
}
|
|
}
|
|
|
|
|
|
private:
|
|
private:
|
|
- PointerIntPair<ValueHandleBase**, 2, HandleBaseKind> PrevPair;
|
|
|
|
|
|
+ PointerIntPair<ValueHandleBase**, 3, HandleBaseKind> PrevPair;
|
|
ValueHandleBase *Next;
|
|
ValueHandleBase *Next;
|
|
|
|
|
|
Value *Val;
|
|
Value *Val;
|
|
@@ -134,6 +134,42 @@ private:
|
|
void AddToUseList();
|
|
void AddToUseList();
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+/// \brief A nullable Value handle that is nullable.
|
|
|
|
+///
|
|
|
|
+/// This is a value handle that points to a value, and nulls itself
|
|
|
|
+/// out if that value is deleted.
|
|
|
|
+class WeakVH : public ValueHandleBase {
|
|
|
|
+public:
|
|
|
|
+ WeakVH() : ValueHandleBase(Weak) {}
|
|
|
|
+ WeakVH(Value *P) : ValueHandleBase(Weak, P) {}
|
|
|
|
+ WeakVH(const WeakVH &RHS)
|
|
|
|
+ : ValueHandleBase(Weak, RHS) {}
|
|
|
|
+
|
|
|
|
+ WeakVH &operator=(const WeakVH &RHS) = default;
|
|
|
|
+
|
|
|
|
+ Value *operator=(Value *RHS) {
|
|
|
|
+ return ValueHandleBase::operator=(RHS);
|
|
|
|
+ }
|
|
|
|
+ Value *operator=(const ValueHandleBase &RHS) {
|
|
|
|
+ return ValueHandleBase::operator=(RHS);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ operator Value*() const {
|
|
|
|
+ return getValPtr();
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+// Specialize simplify_type to allow WeakVH to participate in
|
|
|
|
+// dyn_cast, isa, etc.
|
|
|
|
+template <> struct simplify_type<WeakVH> {
|
|
|
|
+ typedef Value *SimpleType;
|
|
|
|
+ static SimpleType getSimplifiedValue(WeakVH &WVH) { return WVH; }
|
|
|
|
+};
|
|
|
|
+template <> struct simplify_type<const WeakVH> {
|
|
|
|
+ typedef Value *SimpleType;
|
|
|
|
+ static SimpleType getSimplifiedValue(const WeakVH &WVH) { return WVH; }
|
|
|
|
+};
|
|
|
|
+
|
|
/// \brief Value handle that is nullable, but tries to track the Value.
|
|
/// \brief Value handle that is nullable, but tries to track the Value.
|
|
///
|
|
///
|
|
/// This is a value handle that tries hard to point to a Value, even across
|
|
/// This is a value handle that tries hard to point to a Value, even across
|