[Modules] Move ValueHandle into the IR library where Value itself lives.
authorChandler Carruth <chandlerc@gmail.com>
Tue, 4 Mar 2014 11:17:44 +0000 (11:17 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Tue, 4 Mar 2014 11:17:44 +0000 (11:17 +0000)
Move the test for this class into the IR unittests as well.

This uncovers that ValueMap too is in the IR library. Ironically, the
unittest for ValueMap is useless in the Support library (honestly, so
was the ValueHandle test) and so it already lives in the IR unittests.
Mmmm, tasty layering.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202821 91177308-0d34-0410-b5e6-96231b3b80d8

52 files changed:
include/llvm/ADT/ValueMap.h
include/llvm/Analysis/AliasSetTracker.h
include/llvm/Analysis/CallGraph.h
include/llvm/Analysis/IVUsers.h
include/llvm/Analysis/MemoryBuiltins.h
include/llvm/Analysis/MemoryDependenceAnalysis.h
include/llvm/Analysis/ScalarEvolution.h
include/llvm/Analysis/ScalarEvolutionExpander.h
include/llvm/CodeGen/LexicalScopes.h
include/llvm/CodeGen/MachineModuleInfo.h
include/llvm/DIBuilder.h
include/llvm/ExecutionEngine/ExecutionEngine.h
include/llvm/IR/IRBuilder.h
include/llvm/IR/Value.h
include/llvm/IR/ValueHandle.h [new file with mode: 0644]
include/llvm/Support/ValueHandle.h [deleted file]
include/llvm/Transforms/Utils/Cloning.h
include/llvm/Transforms/Utils/SSAUpdaterImpl.h
include/llvm/Transforms/Utils/SimplifyIndVar.h
lib/Analysis/InstructionSimplify.cpp
lib/Analysis/LazyValueInfo.cpp
lib/AsmParser/LLParser.h
lib/Bitcode/Reader/BitcodeReader.h
lib/CodeGen/AsmPrinter/DwarfDebug.cpp
lib/CodeGen/CodeGenPrepare.cpp
lib/ExecutionEngine/EventListenerCommon.h
lib/ExecutionEngine/ExecutionEngine.cpp
lib/ExecutionEngine/IntelJITEvents/IntelJITEventListener.cpp
lib/ExecutionEngine/JIT/JIT.h
lib/ExecutionEngine/JIT/JITEmitter.cpp
lib/IR/DebugInfo.cpp
lib/IR/LLVMContextImpl.h
lib/IR/Metadata.cpp
lib/IR/Value.cpp
lib/Target/PowerPC/PPCCTRLoops.cpp
lib/Target/XCore/XCoreLowerThreadLocal.cpp
lib/Transforms/IPO/GlobalOpt.cpp
lib/Transforms/IPO/MergeFunctions.cpp
lib/Transforms/InstCombine/InstructionCombining.cpp
lib/Transforms/Scalar/JumpThreading.cpp
lib/Transforms/Scalar/LoopStrengthReduce.cpp
lib/Transforms/Scalar/Reassociate.cpp
lib/Transforms/Scalar/TailRecursionElimination.cpp
lib/Transforms/Utils/BasicBlockUtils.cpp
lib/Transforms/Utils/Local.cpp
lib/Transforms/Vectorize/BBVectorize.cpp
lib/Transforms/Vectorize/LoopVectorize.cpp
unittests/IR/CMakeLists.txt
unittests/IR/MetadataTest.cpp
unittests/IR/ValueHandleTest.cpp [new file with mode: 0644]
unittests/Support/CMakeLists.txt
unittests/Support/ValueHandleTest.cpp [deleted file]

index b4fed7a..18913d8 100644 (file)
@@ -27,8 +27,8 @@
 #define LLVM_ADT_VALUEMAP_H
 
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/Mutex.h"
-#include "llvm/Support/ValueHandle.h"
 #include "llvm/Support/type_traits.h"
 #include <iterator>
 
index da00707..a800505 100644 (file)
@@ -20,7 +20,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/ilist.h"
 #include "llvm/ADT/ilist_node.h"
-#include "llvm/Support/ValueHandle.h"
+#include "llvm/IR/ValueHandle.h"
 #include <vector>
 
 namespace llvm {
index c813e4b..2866ed6 100644 (file)
@@ -57,9 +57,9 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/IR/CallSite.h"
 #include "llvm/IR/Function.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/IncludeFile.h"
-#include "llvm/Support/ValueHandle.h"
 #include <map>
 
 namespace llvm {
index 58d347e..52df2ff 100644 (file)
@@ -17,7 +17,7 @@
 
 #include "llvm/Analysis/LoopPass.h"
 #include "llvm/Analysis/ScalarEvolutionNormalization.h"
-#include "llvm/Support/ValueHandle.h"
+#include "llvm/IR/ValueHandle.h"
 
 namespace llvm {
 
index ec2fea8..7784db4 100644 (file)
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/Operator.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/InstVisitor.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/TargetFolder.h"
-#include "llvm/Support/ValueHandle.h"
 
 namespace llvm {
 class CallInst;
index b4b401a..329aa25 100644 (file)
@@ -20,8 +20,8 @@
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/Analysis/AliasAnalysis.h"
 #include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Pass.h"
-#include "llvm/Support/ValueHandle.h"
 
 namespace llvm {
   class Function;
index e1d4861..e2d8765 100644 (file)
 #include "llvm/IR/Function.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/Operator.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/ConstantRange.h"
 #include "llvm/Support/DataTypes.h"
-#include "llvm/Support/ValueHandle.h"
 #include <map>
 
 namespace llvm {
index 167861d..3e57ba8 100644 (file)
@@ -17,8 +17,8 @@
 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
 #include "llvm/Analysis/ScalarEvolutionNormalization.h"
 #include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/TargetFolder.h"
-#include "llvm/Support/ValueHandle.h"
 #include <set>
 
 namespace llvm {
index af1f847..bfa787d 100644 (file)
@@ -22,8 +22,8 @@
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/IR/Metadata.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/DebugLoc.h"
-#include "llvm/Support/ValueHandle.h"
 #include <utility>
 namespace llvm {
 
index 460c08c..b510206 100644 (file)
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/IR/Metadata.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MachineLocation.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/DebugLoc.h"
 #include "llvm/Support/Dwarf.h"
-#include "llvm/Support/ValueHandle.h"
 
 namespace llvm {
 
index df900e2..d795859 100644 (file)
@@ -18,8 +18,8 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/DebugInfo.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/DataTypes.h"
-#include "llvm/Support/ValueHandle.h"
 
 namespace llvm {
   class BasicBlock;
index b906b27..605236b 100644 (file)
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/ValueMap.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/MC/MCCodeGenInfo.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Mutex.h"
-#include "llvm/Support/ValueHandle.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetOptions.h"
 #include <map>
index e43bc9f..2926466 100644 (file)
@@ -23,9 +23,9 @@
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Operator.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/CBindingWrapping.h"
 #include "llvm/Support/ConstantFolder.h"
-#include "llvm/Support/ValueHandle.h"
 
 namespace llvm {
   class MDNode;
index 858c6e3..f194502 100644 (file)
@@ -61,7 +61,7 @@ typedef StringMapEntry<Value*> ValueName;
 /// Every value has a "use list" that keeps track of which other Values are
 /// using this Value.  A Value can also have an arbitrary number of ValueHandle
 /// objects that watch it and listen to RAUW and Destroy events.  See
-/// llvm/Support/ValueHandle.h for details.
+/// llvm/IR/ValueHandle.h for details.
 ///
 /// @brief LLVM Value Representation
 class Value {
diff --git a/include/llvm/IR/ValueHandle.h b/include/llvm/IR/ValueHandle.h
new file mode 100644 (file)
index 0000000..9b5e11a
--- /dev/null
@@ -0,0 +1,380 @@
+//===- ValueHandle.h - Value Smart Pointer classes --------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares the ValueHandle class and its sub-classes.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_IR_VALUEHANDLE_H
+#define LLVM_IR_VALUEHANDLE_H
+
+#include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/ADT/PointerIntPair.h"
+#include "llvm/IR/Value.h"
+
+namespace llvm {
+class ValueHandleBase;
+template<typename From> struct simplify_type;
+
+// ValueHandleBase** is only 4-byte aligned.
+template<>
+class PointerLikeTypeTraits<ValueHandleBase**> {
+public:
+  static inline void *getAsVoidPointer(ValueHandleBase** P) { return P; }
+  static inline ValueHandleBase **getFromVoidPointer(void *P) {
+    return static_cast<ValueHandleBase**>(P);
+  }
+  enum { NumLowBitsAvailable = 2 };
+};
+
+/// ValueHandleBase - This is the common base class of value handles.
+/// ValueHandle's are smart pointers to Value's that have special behavior when
+/// the value is deleted or ReplaceAllUsesWith'd.  See the specific handles
+/// below for details.
+///
+class ValueHandleBase {
+  friend class Value;
+protected:
+  /// HandleBaseKind - This indicates what sub class the handle actually is.
+  /// This is to avoid having a vtable for the light-weight handle pointers. The
+  /// fully general Callback version does have a vtable.
+  enum HandleBaseKind {
+    Assert,
+    Callback,
+    Tracking,
+    Weak
+  };
+
+private:
+  PointerIntPair<ValueHandleBase**, 2, HandleBaseKind> PrevPair;
+  ValueHandleBase *Next;
+
+  // A subclass may want to store some information along with the value
+  // pointer. Allow them to do this by making the value pointer a pointer-int
+  // pair. The 'setValPtrInt' and 'getValPtrInt' methods below give them this
+  // access.
+  PointerIntPair<Value*, 2> VP;
+
+  ValueHandleBase(const ValueHandleBase&) LLVM_DELETED_FUNCTION;
+public:
+  explicit ValueHandleBase(HandleBaseKind Kind)
+    : PrevPair(0, Kind), Next(0), VP(0, 0) {}
+  ValueHandleBase(HandleBaseKind Kind, Value *V)
+    : PrevPair(0, Kind), Next(0), VP(V, 0) {
+    if (isValid(VP.getPointer()))
+      AddToUseList();
+  }
+  ValueHandleBase(HandleBaseKind Kind, const ValueHandleBase &RHS)
+    : PrevPair(0, Kind), Next(0), VP(RHS.VP) {
+    if (isValid(VP.getPointer()))
+      AddToExistingUseList(RHS.getPrevPtr());
+  }
+  ~ValueHandleBase() {
+    if (isValid(VP.getPointer()))
+      RemoveFromUseList();
+  }
+
+  Value *operator=(Value *RHS) {
+    if (VP.getPointer() == RHS) return RHS;
+    if (isValid(VP.getPointer())) RemoveFromUseList();
+    VP.setPointer(RHS);
+    if (isValid(VP.getPointer())) AddToUseList();
+    return RHS;
+  }
+
+  Value *operator=(const ValueHandleBase &RHS) {
+    if (VP.getPointer() == RHS.VP.getPointer()) return RHS.VP.getPointer();
+    if (isValid(VP.getPointer())) RemoveFromUseList();
+    VP.setPointer(RHS.VP.getPointer());
+    if (isValid(VP.getPointer())) AddToExistingUseList(RHS.getPrevPtr());
+    return VP.getPointer();
+  }
+
+  Value *operator->() const { return getValPtr(); }
+  Value &operator*() const { return *getValPtr(); }
+
+protected:
+  Value *getValPtr() const { return VP.getPointer(); }
+
+  void setValPtrInt(unsigned K) { VP.setInt(K); }
+  unsigned getValPtrInt() const { return VP.getInt(); }
+
+  static bool isValid(Value *V) {
+    return V &&
+           V != DenseMapInfo<Value *>::getEmptyKey() &&
+           V != DenseMapInfo<Value *>::getTombstoneKey();
+  }
+
+public:
+  // Callbacks made from Value.
+  static void ValueIsDeleted(Value *V);
+  static void ValueIsRAUWd(Value *Old, Value *New);
+
+private:
+  // Internal implementation details.
+  ValueHandleBase **getPrevPtr() const { return PrevPair.getPointer(); }
+  HandleBaseKind getKind() const { return PrevPair.getInt(); }
+  void setPrevPtr(ValueHandleBase **Ptr) { PrevPair.setPointer(Ptr); }
+
+  /// AddToExistingUseList - Add this ValueHandle to the use list for VP, where
+  /// List is the address of either the head of the list or a Next node within
+  /// the existing use list.
+  void AddToExistingUseList(ValueHandleBase **List);
+
+  /// AddToExistingUseListAfter - Add this ValueHandle to the use list after
+  /// Node.
+  void AddToExistingUseListAfter(ValueHandleBase *Node);
+
+  /// AddToUseList - Add this ValueHandle to the use list for VP.
+  void AddToUseList();
+  /// RemoveFromUseList - Remove this ValueHandle from its current use list.
+  void RemoveFromUseList();
+};
+
+/// WeakVH - This is a value handle that tries hard to point to a Value, even
+/// across RAUW operations, but will null itself out if the value is destroyed.
+/// this is useful for advisory sorts of information, but should not be used as
+/// the key of a map (since the map would have to rearrange itself when the
+/// pointer changes).
+class WeakVH : public ValueHandleBase {
+public:
+  WeakVH() : ValueHandleBase(Weak) {}
+  WeakVH(Value *P) : ValueHandleBase(Weak, P) {}
+  WeakVH(const WeakVH &RHS)
+    : ValueHandleBase(Weak, RHS) {}
+
+  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;
+  }
+};
+
+/// AssertingVH - This is a Value Handle that points to a value and asserts out
+/// if the value is destroyed while the handle is still live.  This is very
+/// useful for catching dangling pointer bugs and other things which can be
+/// non-obvious.  One particularly useful place to use this is as the Key of a
+/// map.  Dangling pointer bugs often lead to really subtle bugs that only occur
+/// if another object happens to get allocated to the same address as the old
+/// one.  Using an AssertingVH ensures that an assert is triggered as soon as
+/// the bad delete occurs.
+///
+/// Note that an AssertingVH handle does *not* follow values across RAUW
+/// operations.  This means that RAUW's need to explicitly update the
+/// AssertingVH's as it moves.  This is required because in non-assert mode this
+/// class turns into a trivial wrapper around a pointer.
+template <typename ValueTy>
+class AssertingVH
+#ifndef NDEBUG
+  : public ValueHandleBase
+#endif
+  {
+
+#ifndef NDEBUG
+  ValueTy *getValPtr() const {
+    return static_cast<ValueTy*>(ValueHandleBase::getValPtr());
+  }
+  void setValPtr(ValueTy *P) {
+    ValueHandleBase::operator=(GetAsValue(P));
+  }
+#else
+  ValueTy *ThePtr;
+  ValueTy *getValPtr() const { return ThePtr; }
+  void setValPtr(ValueTy *P) { ThePtr = P; }
+#endif
+
+  // Convert a ValueTy*, which may be const, to the type the base
+  // class expects.
+  static Value *GetAsValue(Value *V) { return V; }
+  static Value *GetAsValue(const Value *V) { return const_cast<Value*>(V); }
+
+public:
+#ifndef NDEBUG
+  AssertingVH() : ValueHandleBase(Assert) {}
+  AssertingVH(ValueTy *P) : ValueHandleBase(Assert, GetAsValue(P)) {}
+  AssertingVH(const AssertingVH &RHS) : ValueHandleBase(Assert, RHS) {}
+#else
+  AssertingVH() : ThePtr(0) {}
+  AssertingVH(ValueTy *P) : ThePtr(P) {}
+#endif
+
+  operator ValueTy*() const {
+    return getValPtr();
+  }
+
+  ValueTy *operator=(ValueTy *RHS) {
+    setValPtr(RHS);
+    return getValPtr();
+  }
+  ValueTy *operator=(const AssertingVH<ValueTy> &RHS) {
+    setValPtr(RHS.getValPtr());
+    return getValPtr();
+  }
+
+  ValueTy *operator->() const { return getValPtr(); }
+  ValueTy &operator*() const { return *getValPtr(); }
+};
+
+// Specialize DenseMapInfo to allow AssertingVH to participate in DenseMap.
+template<typename T>
+struct DenseMapInfo<AssertingVH<T> > {
+  typedef DenseMapInfo<T*> PointerInfo;
+  static inline AssertingVH<T> getEmptyKey() {
+    return AssertingVH<T>(PointerInfo::getEmptyKey());
+  }
+  static inline T* getTombstoneKey() {
+    return AssertingVH<T>(PointerInfo::getTombstoneKey());
+  }
+  static unsigned getHashValue(const AssertingVH<T> &Val) {
+    return PointerInfo::getHashValue(Val);
+  }
+  static bool isEqual(const AssertingVH<T> &LHS, const AssertingVH<T> &RHS) {
+    return LHS == RHS;
+  }
+};
+  
+template <typename T>
+struct isPodLike<AssertingVH<T> > {
+#ifdef NDEBUG
+  static const bool value = true;
+#else
+  static const bool value = false;
+#endif
+};
+
+
+/// TrackingVH - This is a value handle that tracks a Value (or Value subclass),
+/// even across RAUW operations.
+///
+/// TrackingVH is designed for situations where a client needs to hold a handle
+/// to a Value (or subclass) across some operations which may move that value,
+/// but should never destroy it or replace it with some unacceptable type.
+///
+/// It is an error to do anything with a TrackingVH whose value has been
+/// destroyed, except to destruct it.
+///
+/// It is an error to attempt to replace a value with one of a type which is
+/// incompatible with any of its outstanding TrackingVHs.
+template<typename ValueTy>
+class TrackingVH : public ValueHandleBase {
+  void CheckValidity() const {
+    Value *VP = ValueHandleBase::getValPtr();
+
+    // Null is always ok.
+    if (!VP) return;
+
+    // Check that this value is valid (i.e., it hasn't been deleted). We
+    // explicitly delay this check until access to avoid requiring clients to be
+    // unnecessarily careful w.r.t. destruction.
+    assert(ValueHandleBase::isValid(VP) && "Tracked Value was deleted!");
+
+    // Check that the value is a member of the correct subclass. We would like
+    // to check this property on assignment for better debugging, but we don't
+    // want to require a virtual interface on this VH. Instead we allow RAUW to
+    // replace this value with a value of an invalid type, and check it here.
+    assert(isa<ValueTy>(VP) &&
+           "Tracked Value was replaced by one with an invalid type!");
+  }
+
+  ValueTy *getValPtr() const {
+    CheckValidity();
+    return (ValueTy*)ValueHandleBase::getValPtr();
+  }
+  void setValPtr(ValueTy *P) {
+    CheckValidity();
+    ValueHandleBase::operator=(GetAsValue(P));
+  }
+
+  // Convert a ValueTy*, which may be const, to the type the base
+  // class expects.
+  static Value *GetAsValue(Value *V) { return V; }
+  static Value *GetAsValue(const Value *V) { return const_cast<Value*>(V); }
+
+public:
+  TrackingVH() : ValueHandleBase(Tracking) {}
+  TrackingVH(ValueTy *P) : ValueHandleBase(Tracking, GetAsValue(P)) {}
+  TrackingVH(const TrackingVH &RHS) : ValueHandleBase(Tracking, RHS) {}
+
+  operator ValueTy*() const {
+    return getValPtr();
+  }
+
+  ValueTy *operator=(ValueTy *RHS) {
+    setValPtr(RHS);
+    return getValPtr();
+  }
+  ValueTy *operator=(const TrackingVH<ValueTy> &RHS) {
+    setValPtr(RHS.getValPtr());
+    return getValPtr();
+  }
+
+  ValueTy *operator->() const { return getValPtr(); }
+  ValueTy &operator*() const { return *getValPtr(); }
+};
+
+/// CallbackVH - This is a value handle that allows subclasses to define
+/// callbacks that run when the underlying Value has RAUW called on it or is
+/// destroyed.  This class can be used as the key of a map, as long as the user
+/// takes it out of the map before calling setValPtr() (since the map has to
+/// rearrange itself when the pointer changes).  Unlike ValueHandleBase, this
+/// class has a vtable and a virtual destructor.
+class CallbackVH : public ValueHandleBase {
+  virtual void anchor();
+protected:
+  CallbackVH(const CallbackVH &RHS)
+    : ValueHandleBase(Callback, RHS) {}
+
+  virtual ~CallbackVH() {}
+
+  void setValPtr(Value *P) {
+    ValueHandleBase::operator=(P);
+  }
+
+public:
+  CallbackVH() : ValueHandleBase(Callback) {}
+  CallbackVH(Value *P) : ValueHandleBase(Callback, P) {}
+
+  operator Value*() const {
+    return getValPtr();
+  }
+
+  /// Called when this->getValPtr() is destroyed, inside ~Value(), so you may
+  /// call any non-virtual Value method on getValPtr(), but no subclass methods.
+  /// If WeakVH were implemented as a CallbackVH, it would use this method to
+  /// call setValPtr(NULL).  AssertingVH would use this method to cause an
+  /// assertion failure.
+  ///
+  /// All implementations must remove the reference from this object to the
+  /// Value that's being destroyed.
+  virtual void deleted() { setValPtr(NULL); }
+
+  /// Called when this->getValPtr()->replaceAllUsesWith(new_value) is called,
+  /// _before_ any of the uses have actually been replaced.  If WeakVH were
+  /// 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 *) {}
+};
+
+} // End llvm namespace
+
+#endif
diff --git a/include/llvm/Support/ValueHandle.h b/include/llvm/Support/ValueHandle.h
deleted file mode 100644 (file)
index bc02ba3..0000000
+++ /dev/null
@@ -1,380 +0,0 @@
-//===- llvm/Support/ValueHandle.h - Value Smart Pointer classes -*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file declares the ValueHandle class and its sub-classes.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_SUPPORT_VALUEHANDLE_H
-#define LLVM_SUPPORT_VALUEHANDLE_H
-
-#include "llvm/ADT/DenseMapInfo.h"
-#include "llvm/ADT/PointerIntPair.h"
-#include "llvm/IR/Value.h"
-
-namespace llvm {
-class ValueHandleBase;
-template<typename From> struct simplify_type;
-
-// ValueHandleBase** is only 4-byte aligned.
-template<>
-class PointerLikeTypeTraits<ValueHandleBase**> {
-public:
-  static inline void *getAsVoidPointer(ValueHandleBase** P) { return P; }
-  static inline ValueHandleBase **getFromVoidPointer(void *P) {
-    return static_cast<ValueHandleBase**>(P);
-  }
-  enum { NumLowBitsAvailable = 2 };
-};
-
-/// ValueHandleBase - This is the common base class of value handles.
-/// ValueHandle's are smart pointers to Value's that have special behavior when
-/// the value is deleted or ReplaceAllUsesWith'd.  See the specific handles
-/// below for details.
-///
-class ValueHandleBase {
-  friend class Value;
-protected:
-  /// HandleBaseKind - This indicates what sub class the handle actually is.
-  /// This is to avoid having a vtable for the light-weight handle pointers. The
-  /// fully general Callback version does have a vtable.
-  enum HandleBaseKind {
-    Assert,
-    Callback,
-    Tracking,
-    Weak
-  };
-
-private:
-  PointerIntPair<ValueHandleBase**, 2, HandleBaseKind> PrevPair;
-  ValueHandleBase *Next;
-
-  // A subclass may want to store some information along with the value
-  // pointer. Allow them to do this by making the value pointer a pointer-int
-  // pair. The 'setValPtrInt' and 'getValPtrInt' methods below give them this
-  // access.
-  PointerIntPair<Value*, 2> VP;
-
-  ValueHandleBase(const ValueHandleBase&) LLVM_DELETED_FUNCTION;
-public:
-  explicit ValueHandleBase(HandleBaseKind Kind)
-    : PrevPair(0, Kind), Next(0), VP(0, 0) {}
-  ValueHandleBase(HandleBaseKind Kind, Value *V)
-    : PrevPair(0, Kind), Next(0), VP(V, 0) {
-    if (isValid(VP.getPointer()))
-      AddToUseList();
-  }
-  ValueHandleBase(HandleBaseKind Kind, const ValueHandleBase &RHS)
-    : PrevPair(0, Kind), Next(0), VP(RHS.VP) {
-    if (isValid(VP.getPointer()))
-      AddToExistingUseList(RHS.getPrevPtr());
-  }
-  ~ValueHandleBase() {
-    if (isValid(VP.getPointer()))
-      RemoveFromUseList();
-  }
-
-  Value *operator=(Value *RHS) {
-    if (VP.getPointer() == RHS) return RHS;
-    if (isValid(VP.getPointer())) RemoveFromUseList();
-    VP.setPointer(RHS);
-    if (isValid(VP.getPointer())) AddToUseList();
-    return RHS;
-  }
-
-  Value *operator=(const ValueHandleBase &RHS) {
-    if (VP.getPointer() == RHS.VP.getPointer()) return RHS.VP.getPointer();
-    if (isValid(VP.getPointer())) RemoveFromUseList();
-    VP.setPointer(RHS.VP.getPointer());
-    if (isValid(VP.getPointer())) AddToExistingUseList(RHS.getPrevPtr());
-    return VP.getPointer();
-  }
-
-  Value *operator->() const { return getValPtr(); }
-  Value &operator*() const { return *getValPtr(); }
-
-protected:
-  Value *getValPtr() const { return VP.getPointer(); }
-
-  void setValPtrInt(unsigned K) { VP.setInt(K); }
-  unsigned getValPtrInt() const { return VP.getInt(); }
-
-  static bool isValid(Value *V) {
-    return V &&
-           V != DenseMapInfo<Value *>::getEmptyKey() &&
-           V != DenseMapInfo<Value *>::getTombstoneKey();
-  }
-
-public:
-  // Callbacks made from Value.
-  static void ValueIsDeleted(Value *V);
-  static void ValueIsRAUWd(Value *Old, Value *New);
-
-private:
-  // Internal implementation details.
-  ValueHandleBase **getPrevPtr() const { return PrevPair.getPointer(); }
-  HandleBaseKind getKind() const { return PrevPair.getInt(); }
-  void setPrevPtr(ValueHandleBase **Ptr) { PrevPair.setPointer(Ptr); }
-
-  /// AddToExistingUseList - Add this ValueHandle to the use list for VP, where
-  /// List is the address of either the head of the list or a Next node within
-  /// the existing use list.
-  void AddToExistingUseList(ValueHandleBase **List);
-
-  /// AddToExistingUseListAfter - Add this ValueHandle to the use list after
-  /// Node.
-  void AddToExistingUseListAfter(ValueHandleBase *Node);
-
-  /// AddToUseList - Add this ValueHandle to the use list for VP.
-  void AddToUseList();
-  /// RemoveFromUseList - Remove this ValueHandle from its current use list.
-  void RemoveFromUseList();
-};
-
-/// WeakVH - This is a value handle that tries hard to point to a Value, even
-/// across RAUW operations, but will null itself out if the value is destroyed.
-/// this is useful for advisory sorts of information, but should not be used as
-/// the key of a map (since the map would have to rearrange itself when the
-/// pointer changes).
-class WeakVH : public ValueHandleBase {
-public:
-  WeakVH() : ValueHandleBase(Weak) {}
-  WeakVH(Value *P) : ValueHandleBase(Weak, P) {}
-  WeakVH(const WeakVH &RHS)
-    : ValueHandleBase(Weak, RHS) {}
-
-  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;
-  }
-};
-
-/// AssertingVH - This is a Value Handle that points to a value and asserts out
-/// if the value is destroyed while the handle is still live.  This is very
-/// useful for catching dangling pointer bugs and other things which can be
-/// non-obvious.  One particularly useful place to use this is as the Key of a
-/// map.  Dangling pointer bugs often lead to really subtle bugs that only occur
-/// if another object happens to get allocated to the same address as the old
-/// one.  Using an AssertingVH ensures that an assert is triggered as soon as
-/// the bad delete occurs.
-///
-/// Note that an AssertingVH handle does *not* follow values across RAUW
-/// operations.  This means that RAUW's need to explicitly update the
-/// AssertingVH's as it moves.  This is required because in non-assert mode this
-/// class turns into a trivial wrapper around a pointer.
-template <typename ValueTy>
-class AssertingVH
-#ifndef NDEBUG
-  : public ValueHandleBase
-#endif
-  {
-
-#ifndef NDEBUG
-  ValueTy *getValPtr() const {
-    return static_cast<ValueTy*>(ValueHandleBase::getValPtr());
-  }
-  void setValPtr(ValueTy *P) {
-    ValueHandleBase::operator=(GetAsValue(P));
-  }
-#else
-  ValueTy *ThePtr;
-  ValueTy *getValPtr() const { return ThePtr; }
-  void setValPtr(ValueTy *P) { ThePtr = P; }
-#endif
-
-  // Convert a ValueTy*, which may be const, to the type the base
-  // class expects.
-  static Value *GetAsValue(Value *V) { return V; }
-  static Value *GetAsValue(const Value *V) { return const_cast<Value*>(V); }
-
-public:
-#ifndef NDEBUG
-  AssertingVH() : ValueHandleBase(Assert) {}
-  AssertingVH(ValueTy *P) : ValueHandleBase(Assert, GetAsValue(P)) {}
-  AssertingVH(const AssertingVH &RHS) : ValueHandleBase(Assert, RHS) {}
-#else
-  AssertingVH() : ThePtr(0) {}
-  AssertingVH(ValueTy *P) : ThePtr(P) {}
-#endif
-
-  operator ValueTy*() const {
-    return getValPtr();
-  }
-
-  ValueTy *operator=(ValueTy *RHS) {
-    setValPtr(RHS);
-    return getValPtr();
-  }
-  ValueTy *operator=(const AssertingVH<ValueTy> &RHS) {
-    setValPtr(RHS.getValPtr());
-    return getValPtr();
-  }
-
-  ValueTy *operator->() const { return getValPtr(); }
-  ValueTy &operator*() const { return *getValPtr(); }
-};
-
-// Specialize DenseMapInfo to allow AssertingVH to participate in DenseMap.
-template<typename T>
-struct DenseMapInfo<AssertingVH<T> > {
-  typedef DenseMapInfo<T*> PointerInfo;
-  static inline AssertingVH<T> getEmptyKey() {
-    return AssertingVH<T>(PointerInfo::getEmptyKey());
-  }
-  static inline T* getTombstoneKey() {
-    return AssertingVH<T>(PointerInfo::getTombstoneKey());
-  }
-  static unsigned getHashValue(const AssertingVH<T> &Val) {
-    return PointerInfo::getHashValue(Val);
-  }
-  static bool isEqual(const AssertingVH<T> &LHS, const AssertingVH<T> &RHS) {
-    return LHS == RHS;
-  }
-};
-  
-template <typename T>
-struct isPodLike<AssertingVH<T> > {
-#ifdef NDEBUG
-  static const bool value = true;
-#else
-  static const bool value = false;
-#endif
-};
-
-
-/// TrackingVH - This is a value handle that tracks a Value (or Value subclass),
-/// even across RAUW operations.
-///
-/// TrackingVH is designed for situations where a client needs to hold a handle
-/// to a Value (or subclass) across some operations which may move that value,
-/// but should never destroy it or replace it with some unacceptable type.
-///
-/// It is an error to do anything with a TrackingVH whose value has been
-/// destroyed, except to destruct it.
-///
-/// It is an error to attempt to replace a value with one of a type which is
-/// incompatible with any of its outstanding TrackingVHs.
-template<typename ValueTy>
-class TrackingVH : public ValueHandleBase {
-  void CheckValidity() const {
-    Value *VP = ValueHandleBase::getValPtr();
-
-    // Null is always ok.
-    if (!VP) return;
-
-    // Check that this value is valid (i.e., it hasn't been deleted). We
-    // explicitly delay this check until access to avoid requiring clients to be
-    // unnecessarily careful w.r.t. destruction.
-    assert(ValueHandleBase::isValid(VP) && "Tracked Value was deleted!");
-
-    // Check that the value is a member of the correct subclass. We would like
-    // to check this property on assignment for better debugging, but we don't
-    // want to require a virtual interface on this VH. Instead we allow RAUW to
-    // replace this value with a value of an invalid type, and check it here.
-    assert(isa<ValueTy>(VP) &&
-           "Tracked Value was replaced by one with an invalid type!");
-  }
-
-  ValueTy *getValPtr() const {
-    CheckValidity();
-    return (ValueTy*)ValueHandleBase::getValPtr();
-  }
-  void setValPtr(ValueTy *P) {
-    CheckValidity();
-    ValueHandleBase::operator=(GetAsValue(P));
-  }
-
-  // Convert a ValueTy*, which may be const, to the type the base
-  // class expects.
-  static Value *GetAsValue(Value *V) { return V; }
-  static Value *GetAsValue(const Value *V) { return const_cast<Value*>(V); }
-
-public:
-  TrackingVH() : ValueHandleBase(Tracking) {}
-  TrackingVH(ValueTy *P) : ValueHandleBase(Tracking, GetAsValue(P)) {}
-  TrackingVH(const TrackingVH &RHS) : ValueHandleBase(Tracking, RHS) {}
-
-  operator ValueTy*() const {
-    return getValPtr();
-  }
-
-  ValueTy *operator=(ValueTy *RHS) {
-    setValPtr(RHS);
-    return getValPtr();
-  }
-  ValueTy *operator=(const TrackingVH<ValueTy> &RHS) {
-    setValPtr(RHS.getValPtr());
-    return getValPtr();
-  }
-
-  ValueTy *operator->() const { return getValPtr(); }
-  ValueTy &operator*() const { return *getValPtr(); }
-};
-
-/// CallbackVH - This is a value handle that allows subclasses to define
-/// callbacks that run when the underlying Value has RAUW called on it or is
-/// destroyed.  This class can be used as the key of a map, as long as the user
-/// takes it out of the map before calling setValPtr() (since the map has to
-/// rearrange itself when the pointer changes).  Unlike ValueHandleBase, this
-/// class has a vtable and a virtual destructor.
-class CallbackVH : public ValueHandleBase {
-  virtual void anchor();
-protected:
-  CallbackVH(const CallbackVH &RHS)
-    : ValueHandleBase(Callback, RHS) {}
-
-  virtual ~CallbackVH() {}
-
-  void setValPtr(Value *P) {
-    ValueHandleBase::operator=(P);
-  }
-
-public:
-  CallbackVH() : ValueHandleBase(Callback) {}
-  CallbackVH(Value *P) : ValueHandleBase(Callback, P) {}
-
-  operator Value*() const {
-    return getValPtr();
-  }
-
-  /// Called when this->getValPtr() is destroyed, inside ~Value(), so you may
-  /// call any non-virtual Value method on getValPtr(), but no subclass methods.
-  /// If WeakVH were implemented as a CallbackVH, it would use this method to
-  /// call setValPtr(NULL).  AssertingVH would use this method to cause an
-  /// assertion failure.
-  ///
-  /// All implementations must remove the reference from this object to the
-  /// Value that's being destroyed.
-  virtual void deleted() { setValPtr(NULL); }
-
-  /// Called when this->getValPtr()->replaceAllUsesWith(new_value) is called,
-  /// _before_ any of the uses have actually been replaced.  If WeakVH were
-  /// 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 *) {}
-};
-
-} // End llvm namespace
-
-#endif
index 7b6db47..6c4e501 100644 (file)
@@ -21,7 +21,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/ADT/ValueMap.h"
-#include "llvm/Support/ValueHandle.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Transforms/Utils/ValueMapper.h"
 
 namespace llvm {
index a9adbd7..0f3da16 100644 (file)
@@ -17,9 +17,9 @@
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Debug.h"
-#include "llvm/Support/ValueHandle.h"
 
 namespace llvm {
 
index 3c3de46..dedeca3 100644 (file)
@@ -16,8 +16,8 @@
 #ifndef LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H
 #define LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H
 
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/CommandLine.h"
-#include "llvm/Support/ValueHandle.h"
 
 namespace llvm {
 
index b1af8f8..6cefc78 100644 (file)
@@ -30,8 +30,8 @@
 #include "llvm/IR/GlobalAlias.h"
 #include "llvm/IR/Operator.h"
 #include "llvm/IR/PatternMatch.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/ConstantRange.h"
-#include "llvm/Support/ValueHandle.h"
 using namespace llvm;
 using namespace llvm::PatternMatch;
 
index c78763f..b68b386 100644 (file)
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/PatternMatch.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/ConstantRange.h"
 #include "llvm/Support/Debug.h"
-#include "llvm/Support/ValueHandle.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetLibraryInfo.h"
 #include <map>
index d25374f..790ffd2 100644 (file)
@@ -22,7 +22,7 @@
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Operator.h"
 #include "llvm/IR/Type.h"
-#include "llvm/Support/ValueHandle.h"
+#include "llvm/IR/ValueHandle.h"
 #include <map>
 
 namespace llvm {
index f6c9d66..56795e2 100644 (file)
@@ -21,7 +21,7 @@
 #include "llvm/IR/Attributes.h"
 #include "llvm/IR/OperandTraits.h"
 #include "llvm/IR/Type.h"
-#include "llvm/Support/ValueHandle.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/system_error.h"
 #include <vector>
 
index 5d46620..91aa763 100644 (file)
@@ -29,6 +29,7 @@
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/MC/MCAsmInfo.h"
 #include "llvm/MC/MCSection.h"
 #include "llvm/MC/MCStreamer.h"
@@ -42,7 +43,6 @@
 #include "llvm/Support/MD5.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Timer.h"
-#include "llvm/Support/ValueHandle.h"
 #include "llvm/Target/TargetFrameLowering.h"
 #include "llvm/Target/TargetLoweringObjectFile.h"
 #include "llvm/Target/TargetMachine.h"
index 8ad68bd..7e2dce6 100644 (file)
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/PatternMatch.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
-#include "llvm/Support/ValueHandle.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetLibraryInfo.h"
 #include "llvm/Target/TargetLowering.h"
index 314db8b..5d756ed 100644 (file)
@@ -17,8 +17,8 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/DebugInfo.h"
 #include "llvm/IR/Metadata.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/Path.h"
-#include "llvm/Support/ValueHandle.h"
 
 namespace llvm {
 
index 335efaf..062c13f 100644 (file)
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Operator.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/DynamicLibrary.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Host.h"
 #include "llvm/Support/MutexGuard.h"
 #include "llvm/Support/TargetRegistry.h"
-#include "llvm/Support/ValueHandle.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
 #include <cmath>
index 7dc295f..bfcbbc8 100644 (file)
@@ -28,7 +28,7 @@
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/Errno.h"
-#include "llvm/Support/ValueHandle.h"
+#include "llvm/IR/ValueHandle.h"
 #include "EventListenerCommon.h"
 #include "IntelJITEventsWrapper.h"
 
index 4f6416f..6af2b4a 100644 (file)
@@ -15,8 +15,8 @@
 #define JIT_H
 
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/PassManager.h"
-#include "llvm/Support/ValueHandle.h"
 
 namespace llvm {
 
index acbbfa1..ba5d4e4 100644 (file)
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Disassembler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Memory.h"
 #include "llvm/Support/MutexGuard.h"
-#include "llvm/Support/ValueHandle.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetInstrInfo.h"
 #include "llvm/Target/TargetJITInfo.h"
index df059c4..add4b87 100644 (file)
@@ -24,9 +24,9 @@
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Dwarf.h"
-#include "llvm/Support/ValueHandle.h"
 #include "llvm/Support/raw_ostream.h"
 using namespace llvm;
 using namespace llvm::dwarf;
index 8b94ab1..7a3cdb9 100644 (file)
@@ -30,7 +30,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Metadata.h"
-#include "llvm/Support/ValueHandle.h"
+#include "llvm/IR/ValueHandle.h"
 #include <vector>
 
 namespace llvm {
index ad943de..512dec1 100644 (file)
@@ -22,9 +22,9 @@
 #include "llvm/IR/Instruction.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/ConstantRange.h"
 #include "llvm/Support/LeakDetector.h"
-#include "llvm/Support/ValueHandle.h"
 using namespace llvm;
 
 //===----------------------------------------------------------------------===//
index cc850cb..eb12bc5 100644 (file)
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Operator.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/IR/ValueSymbolTable.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/LeakDetector.h"
 #include "llvm/Support/ManagedStatic.h"
-#include "llvm/Support/ValueHandle.h"
 #include <algorithm>
 using namespace llvm;
 
index feba3f1..9c5db50 100644 (file)
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/PassSupport.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
-#include "llvm/Support/ValueHandle.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetLibraryInfo.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
index 3a93d2a..da83098 100644 (file)
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/NoFolder.h"
-#include "llvm/Support/ValueHandle.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
 
 #define DEBUG_TYPE "xcore-lower-thread-local"
index 0a23384..71c5e05 100644 (file)
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Operator.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
-#include "llvm/Support/ValueHandle.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetLibraryInfo.h"
 #include "llvm/Transforms/Utils/GlobalStatus.h"
index c4a39fa..ec8f72c 100644 (file)
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Operator.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ValueHandle.h"
 #include "llvm/Support/raw_ostream.h"
 #include <vector>
 using namespace llvm;
index d6c8a54..b960d47 100644 (file)
 #include "llvm/IR/GetElementPtrTypeIterator.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/PatternMatch.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
-#include "llvm/Support/ValueHandle.h"
 #include "llvm/Target/TargetLibraryInfo.h"
 #include "llvm/Transforms/Utils/Local.h"
 #include <algorithm>
index ed784f6..d241489 100644 (file)
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
-#include "llvm/Support/ValueHandle.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetLibraryInfo.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
index 5ab32d9..f4cf570 100644 (file)
@@ -68,9 +68,9 @@
 #include "llvm/IR/Dominators.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
-#include "llvm/Support/ValueHandle.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
 #include "llvm/Transforms/Utils/Local.h"
index b6535a7..99b5505 100644 (file)
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/Debug.h"
-#include "llvm/Support/ValueHandle.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Transforms/Utils/Local.h"
 #include <algorithm>
index 855ae43..ad92a59 100644 (file)
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/Debug.h"
-#include "llvm/Support/ValueHandle.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
 #include "llvm/Transforms/Utils/Local.h"
index 918bd16..67c8649 100644 (file)
@@ -24,8 +24,8 @@
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Type.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ValueHandle.h"
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/Transforms/Utils/Local.h"
 #include <algorithm>
index b6d9fb7..f437be6 100644 (file)
 #include "llvm/IR/MDBuilder.h"
 #include "llvm/IR/Metadata.h"
 #include "llvm/IR/Operator.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/MathExtras.h"
-#include "llvm/Support/ValueHandle.h"
 #include "llvm/Support/raw_ostream.h"
 using namespace llvm;
 
index 4855d4e..df65e01 100644 (file)
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Metadata.h"
 #include "llvm/IR/Type.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
-#include "llvm/Support/ValueHandle.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Transforms/Utils/Local.h"
 #include <algorithm>
index 70a0baf..1ff347d 100644 (file)
 #include "llvm/IR/PatternMatch.h"
 #include "llvm/IR/Type.h"
 #include "llvm/IR/Value.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/IR/Verifier.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/BranchProbability.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
-#include "llvm/Support/ValueHandle.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetLibraryInfo.h"
 #include "llvm/Transforms/Scalar.h"
index 305079f..fd8d842 100644 (file)
@@ -19,6 +19,7 @@ set(IRSources
   PatternMatch.cpp
   TypeBuilderTest.cpp
   TypesTest.cpp
+  ValueHandleTest.cpp
   ValueMapTest.cpp
   ValueTest.cpp
   VerifierTest.cpp
index 352e83e..00a2783 100644 (file)
@@ -13,7 +13,7 @@
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Type.h"
-#include "llvm/Support/ValueHandle.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/raw_ostream.h"
 #include "gtest/gtest.h"
 using namespace llvm;
diff --git a/unittests/IR/ValueHandleTest.cpp b/unittests/IR/ValueHandleTest.cpp
new file mode 100644 (file)
index 0000000..bbca701
--- /dev/null
@@ -0,0 +1,408 @@
+//===- ValueHandleTest.cpp - ValueHandle tests ----------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/IR/ValueHandle.h"
+#include "llvm/ADT/OwningPtr.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/LLVMContext.h"
+#include "gtest/gtest.h"
+#include <memory>
+
+using namespace llvm;
+
+namespace {
+
+class ValueHandle : public testing::Test {
+protected:
+  Constant *ConstantV;
+  std::auto_ptr<BitCastInst> BitcastV;
+
+  ValueHandle() :
+    ConstantV(ConstantInt::get(Type::getInt32Ty(getGlobalContext()), 0)),
+    BitcastV(new BitCastInst(ConstantV, Type::getInt32Ty(getGlobalContext()))) {
+  }
+};
+
+class ConcreteCallbackVH : public CallbackVH {
+public:
+  ConcreteCallbackVH(Value *V) : CallbackVH(V) {}
+};
+
+TEST_F(ValueHandle, WeakVH_BasicOperation) {
+  WeakVH WVH(BitcastV.get());
+  EXPECT_EQ(BitcastV.get(), WVH);
+  WVH = ConstantV;
+  EXPECT_EQ(ConstantV, WVH);
+
+  // Make sure I can call a method on the underlying Value.  It
+  // doesn't matter which method.
+  EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), WVH->getType());
+  EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (*WVH).getType());
+}
+
+TEST_F(ValueHandle, WeakVH_Comparisons) {
+  WeakVH BitcastWVH(BitcastV.get());
+  WeakVH ConstantWVH(ConstantV);
+
+  EXPECT_TRUE(BitcastWVH == BitcastWVH);
+  EXPECT_TRUE(BitcastV.get() == BitcastWVH);
+  EXPECT_TRUE(BitcastWVH == BitcastV.get());
+  EXPECT_FALSE(BitcastWVH == ConstantWVH);
+
+  EXPECT_TRUE(BitcastWVH != ConstantWVH);
+  EXPECT_TRUE(BitcastV.get() != ConstantWVH);
+  EXPECT_TRUE(BitcastWVH != ConstantV);
+  EXPECT_FALSE(BitcastWVH != BitcastWVH);
+
+  // Cast to Value* so comparisons work.
+  Value *BV = BitcastV.get();
+  Value *CV = ConstantV;
+  EXPECT_EQ(BV < CV, BitcastWVH < ConstantWVH);
+  EXPECT_EQ(BV <= CV, BitcastWVH <= ConstantWVH);
+  EXPECT_EQ(BV > CV, BitcastWVH > ConstantWVH);
+  EXPECT_EQ(BV >= CV, BitcastWVH >= ConstantWVH);
+
+  EXPECT_EQ(BV < CV, BitcastV.get() < ConstantWVH);
+  EXPECT_EQ(BV <= CV, BitcastV.get() <= ConstantWVH);
+  EXPECT_EQ(BV > CV, BitcastV.get() > ConstantWVH);
+  EXPECT_EQ(BV >= CV, BitcastV.get() >= ConstantWVH);
+
+  EXPECT_EQ(BV < CV, BitcastWVH < ConstantV);
+  EXPECT_EQ(BV <= CV, BitcastWVH <= ConstantV);
+  EXPECT_EQ(BV > CV, BitcastWVH > ConstantV);
+  EXPECT_EQ(BV >= CV, BitcastWVH >= ConstantV);
+}
+
+TEST_F(ValueHandle, WeakVH_FollowsRAUW) {
+  WeakVH WVH(BitcastV.get());
+  WeakVH WVH_Copy(WVH);
+  WeakVH WVH_Recreated(BitcastV.get());
+  BitcastV->replaceAllUsesWith(ConstantV);
+  EXPECT_EQ(ConstantV, WVH);
+  EXPECT_EQ(ConstantV, WVH_Copy);
+  EXPECT_EQ(ConstantV, WVH_Recreated);
+}
+
+TEST_F(ValueHandle, WeakVH_NullOnDeletion) {
+  WeakVH WVH(BitcastV.get());
+  WeakVH WVH_Copy(WVH);
+  WeakVH WVH_Recreated(BitcastV.get());
+  BitcastV.reset();
+  Value *null_value = NULL;
+  EXPECT_EQ(null_value, WVH);
+  EXPECT_EQ(null_value, WVH_Copy);
+  EXPECT_EQ(null_value, WVH_Recreated);
+}
+
+
+TEST_F(ValueHandle, AssertingVH_BasicOperation) {
+  AssertingVH<CastInst> AVH(BitcastV.get());
+  CastInst *implicit_to_exact_type = AVH;
+  (void)implicit_to_exact_type;  // Avoid warning.
+
+  AssertingVH<Value> GenericAVH(BitcastV.get());
+  EXPECT_EQ(BitcastV.get(), GenericAVH);
+  GenericAVH = ConstantV;
+  EXPECT_EQ(ConstantV, GenericAVH);
+
+  // Make sure I can call a method on the underlying CastInst.  It
+  // doesn't matter which method.
+  EXPECT_FALSE(AVH->mayWriteToMemory());
+  EXPECT_FALSE((*AVH).mayWriteToMemory());
+}
+
+TEST_F(ValueHandle, AssertingVH_Const) {
+  const CastInst *ConstBitcast = BitcastV.get();
+  AssertingVH<const CastInst> AVH(ConstBitcast);
+  const CastInst *implicit_to_exact_type = AVH;
+  (void)implicit_to_exact_type;  // Avoid warning.
+}
+
+TEST_F(ValueHandle, AssertingVH_Comparisons) {
+  AssertingVH<Value> BitcastAVH(BitcastV.get());
+  AssertingVH<Value> ConstantAVH(ConstantV);
+
+  EXPECT_TRUE(BitcastAVH == BitcastAVH);
+  EXPECT_TRUE(BitcastV.get() == BitcastAVH);
+  EXPECT_TRUE(BitcastAVH == BitcastV.get());
+  EXPECT_FALSE(BitcastAVH == ConstantAVH);
+
+  EXPECT_TRUE(BitcastAVH != ConstantAVH);
+  EXPECT_TRUE(BitcastV.get() != ConstantAVH);
+  EXPECT_TRUE(BitcastAVH != ConstantV);
+  EXPECT_FALSE(BitcastAVH != BitcastAVH);
+
+  // Cast to Value* so comparisons work.
+  Value *BV = BitcastV.get();
+  Value *CV = ConstantV;
+  EXPECT_EQ(BV < CV, BitcastAVH < ConstantAVH);
+  EXPECT_EQ(BV <= CV, BitcastAVH <= ConstantAVH);
+  EXPECT_EQ(BV > CV, BitcastAVH > ConstantAVH);
+  EXPECT_EQ(BV >= CV, BitcastAVH >= ConstantAVH);
+
+  EXPECT_EQ(BV < CV, BitcastV.get() < ConstantAVH);
+  EXPECT_EQ(BV <= CV, BitcastV.get() <= ConstantAVH);
+  EXPECT_EQ(BV > CV, BitcastV.get() > ConstantAVH);
+  EXPECT_EQ(BV >= CV, BitcastV.get() >= ConstantAVH);
+
+  EXPECT_EQ(BV < CV, BitcastAVH < ConstantV);
+  EXPECT_EQ(BV <= CV, BitcastAVH <= ConstantV);
+  EXPECT_EQ(BV > CV, BitcastAVH > ConstantV);
+  EXPECT_EQ(BV >= CV, BitcastAVH >= ConstantV);
+}
+
+TEST_F(ValueHandle, AssertingVH_DoesNotFollowRAUW) {
+  AssertingVH<Value> AVH(BitcastV.get());
+  BitcastV->replaceAllUsesWith(ConstantV);
+  EXPECT_EQ(BitcastV.get(), AVH);
+}
+
+#ifdef NDEBUG
+
+TEST_F(ValueHandle, AssertingVH_ReducesToPointer) {
+  EXPECT_EQ(sizeof(CastInst *), sizeof(AssertingVH<CastInst>));
+}
+
+#else  // !NDEBUG
+
+#ifdef GTEST_HAS_DEATH_TEST
+
+TEST_F(ValueHandle, AssertingVH_Asserts) {
+  AssertingVH<Value> AVH(BitcastV.get());
+  EXPECT_DEATH({BitcastV.reset();},
+               "An asserting value handle still pointed to this value!");
+  AssertingVH<Value> Copy(AVH);
+  AVH = NULL;
+  EXPECT_DEATH({BitcastV.reset();},
+               "An asserting value handle still pointed to this value!");
+  Copy = NULL;
+  BitcastV.reset();
+}
+
+#endif  // GTEST_HAS_DEATH_TEST
+
+#endif  // NDEBUG
+
+TEST_F(ValueHandle, CallbackVH_BasicOperation) {
+  ConcreteCallbackVH CVH(BitcastV.get());
+  EXPECT_EQ(BitcastV.get(), CVH);
+  CVH = ConstantV;
+  EXPECT_EQ(ConstantV, CVH);
+
+  // Make sure I can call a method on the underlying Value.  It
+  // doesn't matter which method.
+  EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), CVH->getType());
+  EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (*CVH).getType());
+}
+
+TEST_F(ValueHandle, CallbackVH_Comparisons) {
+  ConcreteCallbackVH BitcastCVH(BitcastV.get());
+  ConcreteCallbackVH ConstantCVH(ConstantV);
+
+  EXPECT_TRUE(BitcastCVH == BitcastCVH);
+  EXPECT_TRUE(BitcastV.get() == BitcastCVH);
+  EXPECT_TRUE(BitcastCVH == BitcastV.get());
+  EXPECT_FALSE(BitcastCVH == ConstantCVH);
+
+  EXPECT_TRUE(BitcastCVH != ConstantCVH);
+  EXPECT_TRUE(BitcastV.get() != ConstantCVH);
+  EXPECT_TRUE(BitcastCVH != ConstantV);
+  EXPECT_FALSE(BitcastCVH != BitcastCVH);
+
+  // Cast to Value* so comparisons work.
+  Value *BV = BitcastV.get();
+  Value *CV = ConstantV;
+  EXPECT_EQ(BV < CV, BitcastCVH < ConstantCVH);
+  EXPECT_EQ(BV <= CV, BitcastCVH <= ConstantCVH);
+  EXPECT_EQ(BV > CV, BitcastCVH > ConstantCVH);
+  EXPECT_EQ(BV >= CV, BitcastCVH >= ConstantCVH);
+
+  EXPECT_EQ(BV < CV, BitcastV.get() < ConstantCVH);
+  EXPECT_EQ(BV <= CV, BitcastV.get() <= ConstantCVH);
+  EXPECT_EQ(BV > CV, BitcastV.get() > ConstantCVH);
+  EXPECT_EQ(BV >= CV, BitcastV.get() >= ConstantCVH);
+
+  EXPECT_EQ(BV < CV, BitcastCVH < ConstantV);
+  EXPECT_EQ(BV <= CV, BitcastCVH <= ConstantV);
+  EXPECT_EQ(BV > CV, BitcastCVH > ConstantV);
+  EXPECT_EQ(BV >= CV, BitcastCVH >= ConstantV);
+}
+
+TEST_F(ValueHandle, CallbackVH_CallbackOnDeletion) {
+  class RecordingVH : public CallbackVH {
+  public:
+    int DeletedCalls;
+    int AURWCalls;
+
+    RecordingVH() : DeletedCalls(0), AURWCalls(0) {}
+    RecordingVH(Value *V) : CallbackVH(V), DeletedCalls(0), AURWCalls(0) {}
+
+  private:
+    virtual void deleted() { DeletedCalls++; CallbackVH::deleted(); }
+    virtual void allUsesReplacedWith(Value *) { AURWCalls++; }
+  };
+
+  RecordingVH RVH;
+  RVH = BitcastV.get();
+  EXPECT_EQ(0, RVH.DeletedCalls);
+  EXPECT_EQ(0, RVH.AURWCalls);
+  BitcastV.reset();
+  EXPECT_EQ(1, RVH.DeletedCalls);
+  EXPECT_EQ(0, RVH.AURWCalls);
+}
+
+TEST_F(ValueHandle, CallbackVH_CallbackOnRAUW) {
+  class RecordingVH : public CallbackVH {
+  public:
+    int DeletedCalls;
+    Value *AURWArgument;
+
+    RecordingVH() : DeletedCalls(0), AURWArgument(NULL) {}
+    RecordingVH(Value *V)
+      : CallbackVH(V), DeletedCalls(0), AURWArgument(NULL) {}
+
+  private:
+    virtual void deleted() { DeletedCalls++; CallbackVH::deleted(); }
+    virtual void allUsesReplacedWith(Value *new_value) {
+      EXPECT_EQ(NULL, AURWArgument);
+      AURWArgument = new_value;
+    }
+  };
+
+  RecordingVH RVH;
+  RVH = BitcastV.get();
+  EXPECT_EQ(0, RVH.DeletedCalls);
+  EXPECT_EQ(NULL, RVH.AURWArgument);
+  BitcastV->replaceAllUsesWith(ConstantV);
+  EXPECT_EQ(0, RVH.DeletedCalls);
+  EXPECT_EQ(ConstantV, RVH.AURWArgument);
+}
+
+TEST_F(ValueHandle, CallbackVH_DeletionCanRAUW) {
+  class RecoveringVH : public CallbackVH {
+  public:
+    int DeletedCalls;
+    Value *AURWArgument;
+    LLVMContext *Context;
+
+    RecoveringVH() : DeletedCalls(0), AURWArgument(NULL), 
+                     Context(&getGlobalContext()) {}
+    RecoveringVH(Value *V)
+      : CallbackVH(V), DeletedCalls(0), AURWArgument(NULL), 
+        Context(&getGlobalContext()) {}
+
+  private:
+    virtual void deleted() {
+      getValPtr()->replaceAllUsesWith(Constant::getNullValue(Type::getInt32Ty(getGlobalContext())));
+      setValPtr(NULL);
+    }
+    virtual void allUsesReplacedWith(Value *new_value) {
+      ASSERT_TRUE(NULL != getValPtr());
+      EXPECT_EQ(1U, getValPtr()->getNumUses());
+      EXPECT_EQ(NULL, AURWArgument);
+      AURWArgument = new_value;
+    }
+  };
+
+  // Normally, if a value has uses, deleting it will crash.  However, we can use
+  // a CallbackVH to remove the uses before the check for no uses.
+  RecoveringVH RVH;
+  RVH = BitcastV.get();
+  std::auto_ptr<BinaryOperator> BitcastUser(
+    BinaryOperator::CreateAdd(RVH, 
+                              Constant::getNullValue(Type::getInt32Ty(getGlobalContext()))));
+  EXPECT_EQ(BitcastV.get(), BitcastUser->getOperand(0));
+  BitcastV.reset();  // Would crash without the ValueHandler.
+  EXPECT_EQ(Constant::getNullValue(Type::getInt32Ty(getGlobalContext())), RVH.AURWArgument);
+  EXPECT_EQ(Constant::getNullValue(Type::getInt32Ty(getGlobalContext())),
+            BitcastUser->getOperand(0));
+}
+
+TEST_F(ValueHandle, DestroyingOtherVHOnSameValueDoesntBreakIteration) {
+  // When a CallbackVH modifies other ValueHandles in its callbacks,
+  // that shouldn't interfere with non-modified ValueHandles receiving
+  // their appropriate callbacks.
+  //
+  // We create the active CallbackVH in the middle of a palindromic
+  // arrangement of other VHs so that the bad behavior would be
+  // triggered in whichever order callbacks run.
+
+  class DestroyingVH : public CallbackVH {
+  public:
+    OwningPtr<WeakVH> ToClear[2];
+    DestroyingVH(Value *V) {
+      ToClear[0].reset(new WeakVH(V));
+      setValPtr(V);
+      ToClear[1].reset(new WeakVH(V));
+    }
+    virtual void deleted() {
+      ToClear[0].reset();
+      ToClear[1].reset();
+      CallbackVH::deleted();
+    }
+    virtual void allUsesReplacedWith(Value *) {
+      ToClear[0].reset();
+      ToClear[1].reset();
+    }
+  };
+
+  {
+    WeakVH ShouldBeVisited1(BitcastV.get());
+    DestroyingVH C(BitcastV.get());
+    WeakVH ShouldBeVisited2(BitcastV.get());
+
+    BitcastV->replaceAllUsesWith(ConstantV);
+    EXPECT_EQ(ConstantV, static_cast<Value*>(ShouldBeVisited1));
+    EXPECT_EQ(ConstantV, static_cast<Value*>(ShouldBeVisited2));
+  }
+
+  {
+    WeakVH ShouldBeVisited1(BitcastV.get());
+    DestroyingVH C(BitcastV.get());
+    WeakVH ShouldBeVisited2(BitcastV.get());
+
+    BitcastV.reset();
+    EXPECT_EQ(NULL, static_cast<Value*>(ShouldBeVisited1));
+    EXPECT_EQ(NULL, static_cast<Value*>(ShouldBeVisited2));
+  }
+}
+
+TEST_F(ValueHandle, AssertingVHCheckedLast) {
+  // If a CallbackVH exists to clear out a group of AssertingVHs on
+  // Value deletion, the CallbackVH should get a chance to do so
+  // before the AssertingVHs assert.
+
+  class ClearingVH : public CallbackVH {
+  public:
+    AssertingVH<Value> *ToClear[2];
+    ClearingVH(Value *V,
+               AssertingVH<Value> &A0, AssertingVH<Value> &A1)
+      : CallbackVH(V) {
+      ToClear[0] = &A0;
+      ToClear[1] = &A1;
+    }
+
+    virtual void deleted() {
+      *ToClear[0] = 0;
+      *ToClear[1] = 0;
+      CallbackVH::deleted();
+    }
+  };
+
+  AssertingVH<Value> A1, A2;
+  A1 = BitcastV.get();
+  ClearingVH C(BitcastV.get(), A1, A2);
+  A2 = BitcastV.get();
+  // C.deleted() should run first, clearing the two AssertingVHs,
+  // which should prevent them from asserting.
+  BitcastV.reset();
+}
+
+}
index bfbef98..46c5c33 100644 (file)
@@ -35,7 +35,6 @@ add_llvm_unittest(SupportTests
   ThreadLocalTest.cpp
   TimeValueTest.cpp
   UnicodeTest.cpp
-  ValueHandleTest.cpp
   YAMLIOTest.cpp
   YAMLParserTest.cpp
   formatted_raw_ostream_test.cpp
diff --git a/unittests/Support/ValueHandleTest.cpp b/unittests/Support/ValueHandleTest.cpp
deleted file mode 100644 (file)
index 05aafa2..0000000
+++ /dev/null
@@ -1,408 +0,0 @@
-//===- llvm/unittest/Support/ValueHandleTest.cpp - ValueHandle tests --------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Support/ValueHandle.h"
-#include "llvm/ADT/OwningPtr.h"
-#include "llvm/IR/Constants.h"
-#include "llvm/IR/Instructions.h"
-#include "llvm/IR/LLVMContext.h"
-#include "gtest/gtest.h"
-#include <memory>
-
-using namespace llvm;
-
-namespace {
-
-class ValueHandle : public testing::Test {
-protected:
-  Constant *ConstantV;
-  std::auto_ptr<BitCastInst> BitcastV;
-
-  ValueHandle() :
-    ConstantV(ConstantInt::get(Type::getInt32Ty(getGlobalContext()), 0)),
-    BitcastV(new BitCastInst(ConstantV, Type::getInt32Ty(getGlobalContext()))) {
-  }
-};
-
-class ConcreteCallbackVH : public CallbackVH {
-public:
-  ConcreteCallbackVH(Value *V) : CallbackVH(V) {}
-};
-
-TEST_F(ValueHandle, WeakVH_BasicOperation) {
-  WeakVH WVH(BitcastV.get());
-  EXPECT_EQ(BitcastV.get(), WVH);
-  WVH = ConstantV;
-  EXPECT_EQ(ConstantV, WVH);
-
-  // Make sure I can call a method on the underlying Value.  It
-  // doesn't matter which method.
-  EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), WVH->getType());
-  EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (*WVH).getType());
-}
-
-TEST_F(ValueHandle, WeakVH_Comparisons) {
-  WeakVH BitcastWVH(BitcastV.get());
-  WeakVH ConstantWVH(ConstantV);
-
-  EXPECT_TRUE(BitcastWVH == BitcastWVH);
-  EXPECT_TRUE(BitcastV.get() == BitcastWVH);
-  EXPECT_TRUE(BitcastWVH == BitcastV.get());
-  EXPECT_FALSE(BitcastWVH == ConstantWVH);
-
-  EXPECT_TRUE(BitcastWVH != ConstantWVH);
-  EXPECT_TRUE(BitcastV.get() != ConstantWVH);
-  EXPECT_TRUE(BitcastWVH != ConstantV);
-  EXPECT_FALSE(BitcastWVH != BitcastWVH);
-
-  // Cast to Value* so comparisons work.
-  Value *BV = BitcastV.get();
-  Value *CV = ConstantV;
-  EXPECT_EQ(BV < CV, BitcastWVH < ConstantWVH);
-  EXPECT_EQ(BV <= CV, BitcastWVH <= ConstantWVH);
-  EXPECT_EQ(BV > CV, BitcastWVH > ConstantWVH);
-  EXPECT_EQ(BV >= CV, BitcastWVH >= ConstantWVH);
-
-  EXPECT_EQ(BV < CV, BitcastV.get() < ConstantWVH);
-  EXPECT_EQ(BV <= CV, BitcastV.get() <= ConstantWVH);
-  EXPECT_EQ(BV > CV, BitcastV.get() > ConstantWVH);
-  EXPECT_EQ(BV >= CV, BitcastV.get() >= ConstantWVH);
-
-  EXPECT_EQ(BV < CV, BitcastWVH < ConstantV);
-  EXPECT_EQ(BV <= CV, BitcastWVH <= ConstantV);
-  EXPECT_EQ(BV > CV, BitcastWVH > ConstantV);
-  EXPECT_EQ(BV >= CV, BitcastWVH >= ConstantV);
-}
-
-TEST_F(ValueHandle, WeakVH_FollowsRAUW) {
-  WeakVH WVH(BitcastV.get());
-  WeakVH WVH_Copy(WVH);
-  WeakVH WVH_Recreated(BitcastV.get());
-  BitcastV->replaceAllUsesWith(ConstantV);
-  EXPECT_EQ(ConstantV, WVH);
-  EXPECT_EQ(ConstantV, WVH_Copy);
-  EXPECT_EQ(ConstantV, WVH_Recreated);
-}
-
-TEST_F(ValueHandle, WeakVH_NullOnDeletion) {
-  WeakVH WVH(BitcastV.get());
-  WeakVH WVH_Copy(WVH);
-  WeakVH WVH_Recreated(BitcastV.get());
-  BitcastV.reset();
-  Value *null_value = NULL;
-  EXPECT_EQ(null_value, WVH);
-  EXPECT_EQ(null_value, WVH_Copy);
-  EXPECT_EQ(null_value, WVH_Recreated);
-}
-
-
-TEST_F(ValueHandle, AssertingVH_BasicOperation) {
-  AssertingVH<CastInst> AVH(BitcastV.get());
-  CastInst *implicit_to_exact_type = AVH;
-  (void)implicit_to_exact_type;  // Avoid warning.
-
-  AssertingVH<Value> GenericAVH(BitcastV.get());
-  EXPECT_EQ(BitcastV.get(), GenericAVH);
-  GenericAVH = ConstantV;
-  EXPECT_EQ(ConstantV, GenericAVH);
-
-  // Make sure I can call a method on the underlying CastInst.  It
-  // doesn't matter which method.
-  EXPECT_FALSE(AVH->mayWriteToMemory());
-  EXPECT_FALSE((*AVH).mayWriteToMemory());
-}
-
-TEST_F(ValueHandle, AssertingVH_Const) {
-  const CastInst *ConstBitcast = BitcastV.get();
-  AssertingVH<const CastInst> AVH(ConstBitcast);
-  const CastInst *implicit_to_exact_type = AVH;
-  (void)implicit_to_exact_type;  // Avoid warning.
-}
-
-TEST_F(ValueHandle, AssertingVH_Comparisons) {
-  AssertingVH<Value> BitcastAVH(BitcastV.get());
-  AssertingVH<Value> ConstantAVH(ConstantV);
-
-  EXPECT_TRUE(BitcastAVH == BitcastAVH);
-  EXPECT_TRUE(BitcastV.get() == BitcastAVH);
-  EXPECT_TRUE(BitcastAVH == BitcastV.get());
-  EXPECT_FALSE(BitcastAVH == ConstantAVH);
-
-  EXPECT_TRUE(BitcastAVH != ConstantAVH);
-  EXPECT_TRUE(BitcastV.get() != ConstantAVH);
-  EXPECT_TRUE(BitcastAVH != ConstantV);
-  EXPECT_FALSE(BitcastAVH != BitcastAVH);
-
-  // Cast to Value* so comparisons work.
-  Value *BV = BitcastV.get();
-  Value *CV = ConstantV;
-  EXPECT_EQ(BV < CV, BitcastAVH < ConstantAVH);
-  EXPECT_EQ(BV <= CV, BitcastAVH <= ConstantAVH);
-  EXPECT_EQ(BV > CV, BitcastAVH > ConstantAVH);
-  EXPECT_EQ(BV >= CV, BitcastAVH >= ConstantAVH);
-
-  EXPECT_EQ(BV < CV, BitcastV.get() < ConstantAVH);
-  EXPECT_EQ(BV <= CV, BitcastV.get() <= ConstantAVH);
-  EXPECT_EQ(BV > CV, BitcastV.get() > ConstantAVH);
-  EXPECT_EQ(BV >= CV, BitcastV.get() >= ConstantAVH);
-
-  EXPECT_EQ(BV < CV, BitcastAVH < ConstantV);
-  EXPECT_EQ(BV <= CV, BitcastAVH <= ConstantV);
-  EXPECT_EQ(BV > CV, BitcastAVH > ConstantV);
-  EXPECT_EQ(BV >= CV, BitcastAVH >= ConstantV);
-}
-
-TEST_F(ValueHandle, AssertingVH_DoesNotFollowRAUW) {
-  AssertingVH<Value> AVH(BitcastV.get());
-  BitcastV->replaceAllUsesWith(ConstantV);
-  EXPECT_EQ(BitcastV.get(), AVH);
-}
-
-#ifdef NDEBUG
-
-TEST_F(ValueHandle, AssertingVH_ReducesToPointer) {
-  EXPECT_EQ(sizeof(CastInst *), sizeof(AssertingVH<CastInst>));
-}
-
-#else  // !NDEBUG
-
-#ifdef GTEST_HAS_DEATH_TEST
-
-TEST_F(ValueHandle, AssertingVH_Asserts) {
-  AssertingVH<Value> AVH(BitcastV.get());
-  EXPECT_DEATH({BitcastV.reset();},
-               "An asserting value handle still pointed to this value!");
-  AssertingVH<Value> Copy(AVH);
-  AVH = NULL;
-  EXPECT_DEATH({BitcastV.reset();},
-               "An asserting value handle still pointed to this value!");
-  Copy = NULL;
-  BitcastV.reset();
-}
-
-#endif  // GTEST_HAS_DEATH_TEST
-
-#endif  // NDEBUG
-
-TEST_F(ValueHandle, CallbackVH_BasicOperation) {
-  ConcreteCallbackVH CVH(BitcastV.get());
-  EXPECT_EQ(BitcastV.get(), CVH);
-  CVH = ConstantV;
-  EXPECT_EQ(ConstantV, CVH);
-
-  // Make sure I can call a method on the underlying Value.  It
-  // doesn't matter which method.
-  EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), CVH->getType());
-  EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (*CVH).getType());
-}
-
-TEST_F(ValueHandle, CallbackVH_Comparisons) {
-  ConcreteCallbackVH BitcastCVH(BitcastV.get());
-  ConcreteCallbackVH ConstantCVH(ConstantV);
-
-  EXPECT_TRUE(BitcastCVH == BitcastCVH);
-  EXPECT_TRUE(BitcastV.get() == BitcastCVH);
-  EXPECT_TRUE(BitcastCVH == BitcastV.get());
-  EXPECT_FALSE(BitcastCVH == ConstantCVH);
-
-  EXPECT_TRUE(BitcastCVH != ConstantCVH);
-  EXPECT_TRUE(BitcastV.get() != ConstantCVH);
-  EXPECT_TRUE(BitcastCVH != ConstantV);
-  EXPECT_FALSE(BitcastCVH != BitcastCVH);
-
-  // Cast to Value* so comparisons work.
-  Value *BV = BitcastV.get();
-  Value *CV = ConstantV;
-  EXPECT_EQ(BV < CV, BitcastCVH < ConstantCVH);
-  EXPECT_EQ(BV <= CV, BitcastCVH <= ConstantCVH);
-  EXPECT_EQ(BV > CV, BitcastCVH > ConstantCVH);
-  EXPECT_EQ(BV >= CV, BitcastCVH >= ConstantCVH);
-
-  EXPECT_EQ(BV < CV, BitcastV.get() < ConstantCVH);
-  EXPECT_EQ(BV <= CV, BitcastV.get() <= ConstantCVH);
-  EXPECT_EQ(BV > CV, BitcastV.get() > ConstantCVH);
-  EXPECT_EQ(BV >= CV, BitcastV.get() >= ConstantCVH);
-
-  EXPECT_EQ(BV < CV, BitcastCVH < ConstantV);
-  EXPECT_EQ(BV <= CV, BitcastCVH <= ConstantV);
-  EXPECT_EQ(BV > CV, BitcastCVH > ConstantV);
-  EXPECT_EQ(BV >= CV, BitcastCVH >= ConstantV);
-}
-
-TEST_F(ValueHandle, CallbackVH_CallbackOnDeletion) {
-  class RecordingVH : public CallbackVH {
-  public:
-    int DeletedCalls;
-    int AURWCalls;
-
-    RecordingVH() : DeletedCalls(0), AURWCalls(0) {}
-    RecordingVH(Value *V) : CallbackVH(V), DeletedCalls(0), AURWCalls(0) {}
-
-  private:
-    virtual void deleted() { DeletedCalls++; CallbackVH::deleted(); }
-    virtual void allUsesReplacedWith(Value *) { AURWCalls++; }
-  };
-
-  RecordingVH RVH;
-  RVH = BitcastV.get();
-  EXPECT_EQ(0, RVH.DeletedCalls);
-  EXPECT_EQ(0, RVH.AURWCalls);
-  BitcastV.reset();
-  EXPECT_EQ(1, RVH.DeletedCalls);
-  EXPECT_EQ(0, RVH.AURWCalls);
-}
-
-TEST_F(ValueHandle, CallbackVH_CallbackOnRAUW) {
-  class RecordingVH : public CallbackVH {
-  public:
-    int DeletedCalls;
-    Value *AURWArgument;
-
-    RecordingVH() : DeletedCalls(0), AURWArgument(NULL) {}
-    RecordingVH(Value *V)
-      : CallbackVH(V), DeletedCalls(0), AURWArgument(NULL) {}
-
-  private:
-    virtual void deleted() { DeletedCalls++; CallbackVH::deleted(); }
-    virtual void allUsesReplacedWith(Value *new_value) {
-      EXPECT_EQ(NULL, AURWArgument);
-      AURWArgument = new_value;
-    }
-  };
-
-  RecordingVH RVH;
-  RVH = BitcastV.get();
-  EXPECT_EQ(0, RVH.DeletedCalls);
-  EXPECT_EQ(NULL, RVH.AURWArgument);
-  BitcastV->replaceAllUsesWith(ConstantV);
-  EXPECT_EQ(0, RVH.DeletedCalls);
-  EXPECT_EQ(ConstantV, RVH.AURWArgument);
-}
-
-TEST_F(ValueHandle, CallbackVH_DeletionCanRAUW) {
-  class RecoveringVH : public CallbackVH {
-  public:
-    int DeletedCalls;
-    Value *AURWArgument;
-    LLVMContext *Context;
-
-    RecoveringVH() : DeletedCalls(0), AURWArgument(NULL), 
-                     Context(&getGlobalContext()) {}
-    RecoveringVH(Value *V)
-      : CallbackVH(V), DeletedCalls(0), AURWArgument(NULL), 
-        Context(&getGlobalContext()) {}
-
-  private:
-    virtual void deleted() {
-      getValPtr()->replaceAllUsesWith(Constant::getNullValue(Type::getInt32Ty(getGlobalContext())));
-      setValPtr(NULL);
-    }
-    virtual void allUsesReplacedWith(Value *new_value) {
-      ASSERT_TRUE(NULL != getValPtr());
-      EXPECT_EQ(1U, getValPtr()->getNumUses());
-      EXPECT_EQ(NULL, AURWArgument);
-      AURWArgument = new_value;
-    }
-  };
-
-  // Normally, if a value has uses, deleting it will crash.  However, we can use
-  // a CallbackVH to remove the uses before the check for no uses.
-  RecoveringVH RVH;
-  RVH = BitcastV.get();
-  std::auto_ptr<BinaryOperator> BitcastUser(
-    BinaryOperator::CreateAdd(RVH, 
-                              Constant::getNullValue(Type::getInt32Ty(getGlobalContext()))));
-  EXPECT_EQ(BitcastV.get(), BitcastUser->getOperand(0));
-  BitcastV.reset();  // Would crash without the ValueHandler.
-  EXPECT_EQ(Constant::getNullValue(Type::getInt32Ty(getGlobalContext())), RVH.AURWArgument);
-  EXPECT_EQ(Constant::getNullValue(Type::getInt32Ty(getGlobalContext())),
-            BitcastUser->getOperand(0));
-}
-
-TEST_F(ValueHandle, DestroyingOtherVHOnSameValueDoesntBreakIteration) {
-  // When a CallbackVH modifies other ValueHandles in its callbacks,
-  // that shouldn't interfere with non-modified ValueHandles receiving
-  // their appropriate callbacks.
-  //
-  // We create the active CallbackVH in the middle of a palindromic
-  // arrangement of other VHs so that the bad behavior would be
-  // triggered in whichever order callbacks run.
-
-  class DestroyingVH : public CallbackVH {
-  public:
-    OwningPtr<WeakVH> ToClear[2];
-    DestroyingVH(Value *V) {
-      ToClear[0].reset(new WeakVH(V));
-      setValPtr(V);
-      ToClear[1].reset(new WeakVH(V));
-    }
-    virtual void deleted() {
-      ToClear[0].reset();
-      ToClear[1].reset();
-      CallbackVH::deleted();
-    }
-    virtual void allUsesReplacedWith(Value *) {
-      ToClear[0].reset();
-      ToClear[1].reset();
-    }
-  };
-
-  {
-    WeakVH ShouldBeVisited1(BitcastV.get());
-    DestroyingVH C(BitcastV.get());
-    WeakVH ShouldBeVisited2(BitcastV.get());
-
-    BitcastV->replaceAllUsesWith(ConstantV);
-    EXPECT_EQ(ConstantV, static_cast<Value*>(ShouldBeVisited1));
-    EXPECT_EQ(ConstantV, static_cast<Value*>(ShouldBeVisited2));
-  }
-
-  {
-    WeakVH ShouldBeVisited1(BitcastV.get());
-    DestroyingVH C(BitcastV.get());
-    WeakVH ShouldBeVisited2(BitcastV.get());
-
-    BitcastV.reset();
-    EXPECT_EQ(NULL, static_cast<Value*>(ShouldBeVisited1));
-    EXPECT_EQ(NULL, static_cast<Value*>(ShouldBeVisited2));
-  }
-}
-
-TEST_F(ValueHandle, AssertingVHCheckedLast) {
-  // If a CallbackVH exists to clear out a group of AssertingVHs on
-  // Value deletion, the CallbackVH should get a chance to do so
-  // before the AssertingVHs assert.
-
-  class ClearingVH : public CallbackVH {
-  public:
-    AssertingVH<Value> *ToClear[2];
-    ClearingVH(Value *V,
-               AssertingVH<Value> &A0, AssertingVH<Value> &A1)
-      : CallbackVH(V) {
-      ToClear[0] = &A0;
-      ToClear[1] = &A1;
-    }
-
-    virtual void deleted() {
-      *ToClear[0] = 0;
-      *ToClear[1] = 0;
-      CallbackVH::deleted();
-    }
-  };
-
-  AssertingVH<Value> A1, A2;
-  A1 = BitcastV.get();
-  ClearingVH C(BitcastV.get(), A1, A2);
-  A2 = BitcastV.get();
-  // C.deleted() should run first, clearing the two AssertingVHs,
-  // which should prevent them from asserting.
-  BitcastV.reset();
-}
-
-}