[Modules] Move ValueMap to the IR library. While this class does not
authorChandler Carruth <chandlerc@gmail.com>
Tue, 4 Mar 2014 11:26:31 +0000 (11:26 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Tue, 4 Mar 2014 11:26:31 +0000 (11:26 +0000)
directly care about the Value class (it is templated so that the key can
be any arbitrary Value subclass), it is in fact concretely tied to the
Value class through the ValueHandle's CallbackVH interface which relies
on the key type being some Value subclass to establish the value handle
chain.

Ironically, the unittest is already in the right library.

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

16 files changed:
docs/ProgrammersManual.rst
include/llvm/ADT/ValueMap.h [deleted file]
include/llvm/CodeGen/StackProtector.h
include/llvm/ExecutionEngine/ExecutionEngine.h
include/llvm/IR/ValueMap.h [new file with mode: 0644]
include/llvm/Transforms/Utils/Cloning.h
include/llvm/Transforms/Utils/ValueMapper.h
lib/CodeGen/CodeGenPrepare.cpp
lib/ExecutionEngine/JIT/JITEmitter.cpp
lib/Target/Mips/MipsMachineFunction.h
lib/Target/NVPTX/NVPTXGenericToNVVM.cpp
lib/Target/R600/AMDGPUISelDAGToDAG.cpp
lib/Transforms/Instrumentation/DebugIR.cpp
lib/Transforms/Instrumentation/MemorySanitizer.cpp
tools/bugpoint/BugDriver.h
unittests/IR/ValueMapTest.cpp

index 99aa5c7877b4e2230e68629fb3156560c48907cb..4862611c09c685ecb6e92e512f285fe45e18dcc7 100644 (file)
@@ -1318,7 +1318,7 @@ type used.
 
 .. _dss_valuemap:
 
-llvm/ADT/ValueMap.h
+llvm/IR/ValueMap.h
 ^^^^^^^^^^^^^^^^^^^
 
 ValueMap is a wrapper around a :ref:`DenseMap <dss_densemap>` mapping
diff --git a/include/llvm/ADT/ValueMap.h b/include/llvm/ADT/ValueMap.h
deleted file mode 100644 (file)
index 18913d8..0000000
+++ /dev/null
@@ -1,377 +0,0 @@
-//===- llvm/ADT/ValueMap.h - Safe map from Values to data -------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines the ValueMap class.  ValueMap maps Value* or any subclass
-// to an arbitrary other type.  It provides the DenseMap interface but updates
-// itself to remain safe when keys are RAUWed or deleted.  By default, when a
-// key is RAUWed from V1 to V2, the old mapping V1->target is removed, and a new
-// mapping V2->target is added.  If V2 already existed, its old target is
-// overwritten.  When a key is deleted, its mapping is removed.
-//
-// You can override a ValueMap's Config parameter to control exactly what
-// happens on RAUW and destruction and to get called back on each event.  It's
-// legal to call back into the ValueMap from a Config's callbacks.  Config
-// parameters should inherit from ValueMapConfig<KeyT> to get default
-// implementations of all the methods ValueMap uses.  See ValueMapConfig for
-// documentation of the functions you can override.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_ADT_VALUEMAP_H
-#define LLVM_ADT_VALUEMAP_H
-
-#include "llvm/ADT/DenseMap.h"
-#include "llvm/IR/ValueHandle.h"
-#include "llvm/Support/Mutex.h"
-#include "llvm/Support/type_traits.h"
-#include <iterator>
-
-namespace llvm {
-
-template<typename KeyT, typename ValueT, typename Config>
-class ValueMapCallbackVH;
-
-template<typename DenseMapT, typename KeyT>
-class ValueMapIterator;
-template<typename DenseMapT, typename KeyT>
-class ValueMapConstIterator;
-
-/// This class defines the default behavior for configurable aspects of
-/// ValueMap<>.  User Configs should inherit from this class to be as compatible
-/// as possible with future versions of ValueMap.
-template<typename KeyT>
-struct ValueMapConfig {
-  /// If FollowRAUW is true, the ValueMap will update mappings on RAUW. If it's
-  /// false, the ValueMap will leave the original mapping in place.
-  enum { FollowRAUW = true };
-
-  // All methods will be called with a first argument of type ExtraData.  The
-  // default implementations in this class take a templated first argument so
-  // that users' subclasses can use any type they want without having to
-  // override all the defaults.
-  struct ExtraData {};
-
-  template<typename ExtraDataT>
-  static void onRAUW(const ExtraDataT & /*Data*/, KeyT /*Old*/, KeyT /*New*/) {}
-  template<typename ExtraDataT>
-  static void onDelete(const ExtraDataT &/*Data*/, KeyT /*Old*/) {}
-
-  /// Returns a mutex that should be acquired around any changes to the map.
-  /// This is only acquired from the CallbackVH (and held around calls to onRAUW
-  /// and onDelete) and not inside other ValueMap methods.  NULL means that no
-  /// mutex is necessary.
-  template<typename ExtraDataT>
-  static sys::Mutex *getMutex(const ExtraDataT &/*Data*/) { return NULL; }
-};
-
-/// See the file comment.
-template<typename KeyT, typename ValueT, typename Config =ValueMapConfig<KeyT> >
-class ValueMap {
-  friend class ValueMapCallbackVH<KeyT, ValueT, Config>;
-  typedef ValueMapCallbackVH<KeyT, ValueT, Config> ValueMapCVH;
-  typedef DenseMap<ValueMapCVH, ValueT, DenseMapInfo<ValueMapCVH> > MapT;
-  typedef typename Config::ExtraData ExtraData;
-  MapT Map;
-  ExtraData Data;
-  ValueMap(const ValueMap&) LLVM_DELETED_FUNCTION;
-  ValueMap& operator=(const ValueMap&) LLVM_DELETED_FUNCTION;
-public:
-  typedef KeyT key_type;
-  typedef ValueT mapped_type;
-  typedef std::pair<KeyT, ValueT> value_type;
-
-  explicit ValueMap(unsigned NumInitBuckets = 64)
-    : Map(NumInitBuckets), Data() {}
-  explicit ValueMap(const ExtraData &Data, unsigned NumInitBuckets = 64)
-    : Map(NumInitBuckets), Data(Data) {}
-
-  ~ValueMap() {}
-
-  typedef ValueMapIterator<MapT, KeyT> iterator;
-  typedef ValueMapConstIterator<MapT, KeyT> const_iterator;
-  inline iterator begin() { return iterator(Map.begin()); }
-  inline iterator end() { return iterator(Map.end()); }
-  inline const_iterator begin() const { return const_iterator(Map.begin()); }
-  inline const_iterator end() const { return const_iterator(Map.end()); }
-
-  bool empty() const { return Map.empty(); }
-  unsigned size() const { return Map.size(); }
-
-  /// Grow the map so that it has at least Size buckets. Does not shrink
-  void resize(size_t Size) { Map.resize(Size); }
-
-  void clear() { Map.clear(); }
-
-  /// count - Return true if the specified key is in the map.
-  bool count(const KeyT &Val) const {
-    return Map.find_as(Val) != Map.end();
-  }
-
-  iterator find(const KeyT &Val) {
-    return iterator(Map.find_as(Val));
-  }
-  const_iterator find(const KeyT &Val) const {
-    return const_iterator(Map.find_as(Val));
-  }
-
-  /// lookup - Return the entry for the specified key, or a default
-  /// constructed value if no such entry exists.
-  ValueT lookup(const KeyT &Val) const {
-    typename MapT::const_iterator I = Map.find_as(Val);
-    return I != Map.end() ? I->second : ValueT();
-  }
-
-  // Inserts key,value pair into the map if the key isn't already in the map.
-  // If the key is already in the map, it returns false and doesn't update the
-  // value.
-  std::pair<iterator, bool> insert(const std::pair<KeyT, ValueT> &KV) {
-    std::pair<typename MapT::iterator, bool> map_result=
-      Map.insert(std::make_pair(Wrap(KV.first), KV.second));
-    return std::make_pair(iterator(map_result.first), map_result.second);
-  }
-
-  /// insert - Range insertion of pairs.
-  template<typename InputIt>
-  void insert(InputIt I, InputIt E) {
-    for (; I != E; ++I)
-      insert(*I);
-  }
-
-
-  bool erase(const KeyT &Val) {
-    typename MapT::iterator I = Map.find_as(Val);
-    if (I == Map.end())
-      return false;
-
-    Map.erase(I);
-    return true;
-  }
-  void erase(iterator I) {
-    return Map.erase(I.base());
-  }
-
-  value_type& FindAndConstruct(const KeyT &Key) {
-    return Map.FindAndConstruct(Wrap(Key));
-  }
-
-  ValueT &operator[](const KeyT &Key) {
-    return Map[Wrap(Key)];
-  }
-
-  /// isPointerIntoBucketsArray - Return true if the specified pointer points
-  /// somewhere into the ValueMap's array of buckets (i.e. either to a key or
-  /// value in the ValueMap).
-  bool isPointerIntoBucketsArray(const void *Ptr) const {
-    return Map.isPointerIntoBucketsArray(Ptr);
-  }
-
-  /// getPointerIntoBucketsArray() - Return an opaque pointer into the buckets
-  /// array.  In conjunction with the previous method, this can be used to
-  /// determine whether an insertion caused the ValueMap to reallocate.
-  const void *getPointerIntoBucketsArray() const {
-    return Map.getPointerIntoBucketsArray();
-  }
-
-private:
-  // Takes a key being looked up in the map and wraps it into a
-  // ValueMapCallbackVH, the actual key type of the map.  We use a helper
-  // function because ValueMapCVH is constructed with a second parameter.
-  ValueMapCVH Wrap(KeyT key) const {
-    // The only way the resulting CallbackVH could try to modify *this (making
-    // the const_cast incorrect) is if it gets inserted into the map.  But then
-    // this function must have been called from a non-const method, making the
-    // const_cast ok.
-    return ValueMapCVH(key, const_cast<ValueMap*>(this));
-  }
-};
-
-// This CallbackVH updates its ValueMap when the contained Value changes,
-// according to the user's preferences expressed through the Config object.
-template<typename KeyT, typename ValueT, typename Config>
-class ValueMapCallbackVH : public CallbackVH {
-  friend class ValueMap<KeyT, ValueT, Config>;
-  friend struct DenseMapInfo<ValueMapCallbackVH>;
-  typedef ValueMap<KeyT, ValueT, Config> ValueMapT;
-  typedef typename llvm::remove_pointer<KeyT>::type KeySansPointerT;
-
-  ValueMapT *Map;
-
-  ValueMapCallbackVH(KeyT Key, ValueMapT *Map)
-      : CallbackVH(const_cast<Value*>(static_cast<const Value*>(Key))),
-        Map(Map) {}
-
-public:
-  KeyT Unwrap() const { return cast_or_null<KeySansPointerT>(getValPtr()); }
-
-  virtual void deleted() {
-    // Make a copy that won't get changed even when *this is destroyed.
-    ValueMapCallbackVH Copy(*this);
-    sys::Mutex *M = Config::getMutex(Copy.Map->Data);
-    if (M)
-      M->acquire();
-    Config::onDelete(Copy.Map->Data, Copy.Unwrap());  // May destroy *this.
-    Copy.Map->Map.erase(Copy);  // Definitely destroys *this.
-    if (M)
-      M->release();
-  }
-  virtual void allUsesReplacedWith(Value *new_key) {
-    assert(isa<KeySansPointerT>(new_key) &&
-           "Invalid RAUW on key of ValueMap<>");
-    // Make a copy that won't get changed even when *this is destroyed.
-    ValueMapCallbackVH Copy(*this);
-    sys::Mutex *M = Config::getMutex(Copy.Map->Data);
-    if (M)
-      M->acquire();
-
-    KeyT typed_new_key = cast<KeySansPointerT>(new_key);
-    // Can destroy *this:
-    Config::onRAUW(Copy.Map->Data, Copy.Unwrap(), typed_new_key);
-    if (Config::FollowRAUW) {
-      typename ValueMapT::MapT::iterator I = Copy.Map->Map.find(Copy);
-      // I could == Copy.Map->Map.end() if the onRAUW callback already
-      // removed the old mapping.
-      if (I != Copy.Map->Map.end()) {
-        ValueT Target(I->second);
-        Copy.Map->Map.erase(I);  // Definitely destroys *this.
-        Copy.Map->insert(std::make_pair(typed_new_key, Target));
-      }
-    }
-    if (M)
-      M->release();
-  }
-};
-
-template<typename KeyT, typename ValueT, typename Config>
-struct DenseMapInfo<ValueMapCallbackVH<KeyT, ValueT, Config> > {
-  typedef ValueMapCallbackVH<KeyT, ValueT, Config> VH;
-  typedef DenseMapInfo<KeyT> PointerInfo;
-
-  static inline VH getEmptyKey() {
-    return VH(PointerInfo::getEmptyKey(), NULL);
-  }
-  static inline VH getTombstoneKey() {
-    return VH(PointerInfo::getTombstoneKey(), NULL);
-  }
-  static unsigned getHashValue(const VH &Val) {
-    return PointerInfo::getHashValue(Val.Unwrap());
-  }
-  static unsigned getHashValue(const KeyT &Val) {
-    return PointerInfo::getHashValue(Val);
-  }
-  static bool isEqual(const VH &LHS, const VH &RHS) {
-    return LHS == RHS;
-  }
-  static bool isEqual(const KeyT &LHS, const VH &RHS) {
-    return LHS == RHS.getValPtr();
-  }
-};
-
-
-template<typename DenseMapT, typename KeyT>
-class ValueMapIterator :
-    public std::iterator<std::forward_iterator_tag,
-                         std::pair<KeyT, typename DenseMapT::mapped_type>,
-                         ptrdiff_t> {
-  typedef typename DenseMapT::iterator BaseT;
-  typedef typename DenseMapT::mapped_type ValueT;
-  BaseT I;
-public:
-  ValueMapIterator() : I() {}
-
-  ValueMapIterator(BaseT I) : I(I) {}
-
-  BaseT base() const { return I; }
-
-  struct ValueTypeProxy {
-    const KeyT first;
-    ValueT& second;
-    ValueTypeProxy *operator->() { return this; }
-    operator std::pair<KeyT, ValueT>() const {
-      return std::make_pair(first, second);
-    }
-  };
-
-  ValueTypeProxy operator*() const {
-    ValueTypeProxy Result = {I->first.Unwrap(), I->second};
-    return Result;
-  }
-
-  ValueTypeProxy operator->() const {
-    return operator*();
-  }
-
-  bool operator==(const ValueMapIterator &RHS) const {
-    return I == RHS.I;
-  }
-  bool operator!=(const ValueMapIterator &RHS) const {
-    return I != RHS.I;
-  }
-
-  inline ValueMapIterator& operator++() {  // Preincrement
-    ++I;
-    return *this;
-  }
-  ValueMapIterator operator++(int) {  // Postincrement
-    ValueMapIterator tmp = *this; ++*this; return tmp;
-  }
-};
-
-template<typename DenseMapT, typename KeyT>
-class ValueMapConstIterator :
-    public std::iterator<std::forward_iterator_tag,
-                         std::pair<KeyT, typename DenseMapT::mapped_type>,
-                         ptrdiff_t> {
-  typedef typename DenseMapT::const_iterator BaseT;
-  typedef typename DenseMapT::mapped_type ValueT;
-  BaseT I;
-public:
-  ValueMapConstIterator() : I() {}
-  ValueMapConstIterator(BaseT I) : I(I) {}
-  ValueMapConstIterator(ValueMapIterator<DenseMapT, KeyT> Other)
-    : I(Other.base()) {}
-
-  BaseT base() const { return I; }
-
-  struct ValueTypeProxy {
-    const KeyT first;
-    const ValueT& second;
-    ValueTypeProxy *operator->() { return this; }
-    operator std::pair<KeyT, ValueT>() const {
-      return std::make_pair(first, second);
-    }
-  };
-
-  ValueTypeProxy operator*() const {
-    ValueTypeProxy Result = {I->first.Unwrap(), I->second};
-    return Result;
-  }
-
-  ValueTypeProxy operator->() const {
-    return operator*();
-  }
-
-  bool operator==(const ValueMapConstIterator &RHS) const {
-    return I == RHS.I;
-  }
-  bool operator!=(const ValueMapConstIterator &RHS) const {
-    return I != RHS.I;
-  }
-
-  inline ValueMapConstIterator& operator++() {  // Preincrement
-    ++I;
-    return *this;
-  }
-  ValueMapConstIterator operator++(int) {  // Postincrement
-    ValueMapConstIterator tmp = *this; ++*this; return tmp;
-  }
-};
-
-} // end namespace llvm
-
-#endif
index 89992d5d3892802b27f7b29c196cd2cde5e6a67c..3edacdff42c9c6641ccff08f74d6d85d0799b23c 100644 (file)
@@ -19,8 +19,8 @@
 
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/Triple.h"
-#include "llvm/ADT/ValueMap.h"
 #include "llvm/IR/Dominators.h"
+#include "llvm/IR/ValueMap.h"
 #include "llvm/Pass.h"
 #include "llvm/Target/TargetLowering.h"
 
index 605236ba87aad09466ee34b02ad39d957fa05b23..e4f276d0fad5c25ecb8de8f7a74f58cda79f0dfc 100644 (file)
@@ -18,8 +18,8 @@
 #include "llvm-c/ExecutionEngine.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/ValueMap.h"
 #include "llvm/IR/ValueHandle.h"
+#include "llvm/IR/ValueMap.h"
 #include "llvm/MC/MCCodeGenInfo.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Mutex.h"
diff --git a/include/llvm/IR/ValueMap.h b/include/llvm/IR/ValueMap.h
new file mode 100644 (file)
index 0000000..0a5ce76
--- /dev/null
@@ -0,0 +1,377 @@
+//===- ValueMap.h - Safe map from Values to data ----------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the ValueMap class.  ValueMap maps Value* or any subclass
+// to an arbitrary other type.  It provides the DenseMap interface but updates
+// itself to remain safe when keys are RAUWed or deleted.  By default, when a
+// key is RAUWed from V1 to V2, the old mapping V1->target is removed, and a new
+// mapping V2->target is added.  If V2 already existed, its old target is
+// overwritten.  When a key is deleted, its mapping is removed.
+//
+// You can override a ValueMap's Config parameter to control exactly what
+// happens on RAUW and destruction and to get called back on each event.  It's
+// legal to call back into the ValueMap from a Config's callbacks.  Config
+// parameters should inherit from ValueMapConfig<KeyT> to get default
+// implementations of all the methods ValueMap uses.  See ValueMapConfig for
+// documentation of the functions you can override.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_IR_VALUEMAP_H
+#define LLVM_IR_VALUEMAP_H
+
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/IR/ValueHandle.h"
+#include "llvm/Support/Mutex.h"
+#include "llvm/Support/type_traits.h"
+#include <iterator>
+
+namespace llvm {
+
+template<typename KeyT, typename ValueT, typename Config>
+class ValueMapCallbackVH;
+
+template<typename DenseMapT, typename KeyT>
+class ValueMapIterator;
+template<typename DenseMapT, typename KeyT>
+class ValueMapConstIterator;
+
+/// This class defines the default behavior for configurable aspects of
+/// ValueMap<>.  User Configs should inherit from this class to be as compatible
+/// as possible with future versions of ValueMap.
+template<typename KeyT>
+struct ValueMapConfig {
+  /// If FollowRAUW is true, the ValueMap will update mappings on RAUW. If it's
+  /// false, the ValueMap will leave the original mapping in place.
+  enum { FollowRAUW = true };
+
+  // All methods will be called with a first argument of type ExtraData.  The
+  // default implementations in this class take a templated first argument so
+  // that users' subclasses can use any type they want without having to
+  // override all the defaults.
+  struct ExtraData {};
+
+  template<typename ExtraDataT>
+  static void onRAUW(const ExtraDataT & /*Data*/, KeyT /*Old*/, KeyT /*New*/) {}
+  template<typename ExtraDataT>
+  static void onDelete(const ExtraDataT &/*Data*/, KeyT /*Old*/) {}
+
+  /// Returns a mutex that should be acquired around any changes to the map.
+  /// This is only acquired from the CallbackVH (and held around calls to onRAUW
+  /// and onDelete) and not inside other ValueMap methods.  NULL means that no
+  /// mutex is necessary.
+  template<typename ExtraDataT>
+  static sys::Mutex *getMutex(const ExtraDataT &/*Data*/) { return NULL; }
+};
+
+/// See the file comment.
+template<typename KeyT, typename ValueT, typename Config =ValueMapConfig<KeyT> >
+class ValueMap {
+  friend class ValueMapCallbackVH<KeyT, ValueT, Config>;
+  typedef ValueMapCallbackVH<KeyT, ValueT, Config> ValueMapCVH;
+  typedef DenseMap<ValueMapCVH, ValueT, DenseMapInfo<ValueMapCVH> > MapT;
+  typedef typename Config::ExtraData ExtraData;
+  MapT Map;
+  ExtraData Data;
+  ValueMap(const ValueMap&) LLVM_DELETED_FUNCTION;
+  ValueMap& operator=(const ValueMap&) LLVM_DELETED_FUNCTION;
+public:
+  typedef KeyT key_type;
+  typedef ValueT mapped_type;
+  typedef std::pair<KeyT, ValueT> value_type;
+
+  explicit ValueMap(unsigned NumInitBuckets = 64)
+    : Map(NumInitBuckets), Data() {}
+  explicit ValueMap(const ExtraData &Data, unsigned NumInitBuckets = 64)
+    : Map(NumInitBuckets), Data(Data) {}
+
+  ~ValueMap() {}
+
+  typedef ValueMapIterator<MapT, KeyT> iterator;
+  typedef ValueMapConstIterator<MapT, KeyT> const_iterator;
+  inline iterator begin() { return iterator(Map.begin()); }
+  inline iterator end() { return iterator(Map.end()); }
+  inline const_iterator begin() const { return const_iterator(Map.begin()); }
+  inline const_iterator end() const { return const_iterator(Map.end()); }
+
+  bool empty() const { return Map.empty(); }
+  unsigned size() const { return Map.size(); }
+
+  /// Grow the map so that it has at least Size buckets. Does not shrink
+  void resize(size_t Size) { Map.resize(Size); }
+
+  void clear() { Map.clear(); }
+
+  /// count - Return true if the specified key is in the map.
+  bool count(const KeyT &Val) const {
+    return Map.find_as(Val) != Map.end();
+  }
+
+  iterator find(const KeyT &Val) {
+    return iterator(Map.find_as(Val));
+  }
+  const_iterator find(const KeyT &Val) const {
+    return const_iterator(Map.find_as(Val));
+  }
+
+  /// lookup - Return the entry for the specified key, or a default
+  /// constructed value if no such entry exists.
+  ValueT lookup(const KeyT &Val) const {
+    typename MapT::const_iterator I = Map.find_as(Val);
+    return I != Map.end() ? I->second : ValueT();
+  }
+
+  // Inserts key,value pair into the map if the key isn't already in the map.
+  // If the key is already in the map, it returns false and doesn't update the
+  // value.
+  std::pair<iterator, bool> insert(const std::pair<KeyT, ValueT> &KV) {
+    std::pair<typename MapT::iterator, bool> map_result=
+      Map.insert(std::make_pair(Wrap(KV.first), KV.second));
+    return std::make_pair(iterator(map_result.first), map_result.second);
+  }
+
+  /// insert - Range insertion of pairs.
+  template<typename InputIt>
+  void insert(InputIt I, InputIt E) {
+    for (; I != E; ++I)
+      insert(*I);
+  }
+
+
+  bool erase(const KeyT &Val) {
+    typename MapT::iterator I = Map.find_as(Val);
+    if (I == Map.end())
+      return false;
+
+    Map.erase(I);
+    return true;
+  }
+  void erase(iterator I) {
+    return Map.erase(I.base());
+  }
+
+  value_type& FindAndConstruct(const KeyT &Key) {
+    return Map.FindAndConstruct(Wrap(Key));
+  }
+
+  ValueT &operator[](const KeyT &Key) {
+    return Map[Wrap(Key)];
+  }
+
+  /// isPointerIntoBucketsArray - Return true if the specified pointer points
+  /// somewhere into the ValueMap's array of buckets (i.e. either to a key or
+  /// value in the ValueMap).
+  bool isPointerIntoBucketsArray(const void *Ptr) const {
+    return Map.isPointerIntoBucketsArray(Ptr);
+  }
+
+  /// getPointerIntoBucketsArray() - Return an opaque pointer into the buckets
+  /// array.  In conjunction with the previous method, this can be used to
+  /// determine whether an insertion caused the ValueMap to reallocate.
+  const void *getPointerIntoBucketsArray() const {
+    return Map.getPointerIntoBucketsArray();
+  }
+
+private:
+  // Takes a key being looked up in the map and wraps it into a
+  // ValueMapCallbackVH, the actual key type of the map.  We use a helper
+  // function because ValueMapCVH is constructed with a second parameter.
+  ValueMapCVH Wrap(KeyT key) const {
+    // The only way the resulting CallbackVH could try to modify *this (making
+    // the const_cast incorrect) is if it gets inserted into the map.  But then
+    // this function must have been called from a non-const method, making the
+    // const_cast ok.
+    return ValueMapCVH(key, const_cast<ValueMap*>(this));
+  }
+};
+
+// This CallbackVH updates its ValueMap when the contained Value changes,
+// according to the user's preferences expressed through the Config object.
+template<typename KeyT, typename ValueT, typename Config>
+class ValueMapCallbackVH : public CallbackVH {
+  friend class ValueMap<KeyT, ValueT, Config>;
+  friend struct DenseMapInfo<ValueMapCallbackVH>;
+  typedef ValueMap<KeyT, ValueT, Config> ValueMapT;
+  typedef typename llvm::remove_pointer<KeyT>::type KeySansPointerT;
+
+  ValueMapT *Map;
+
+  ValueMapCallbackVH(KeyT Key, ValueMapT *Map)
+      : CallbackVH(const_cast<Value*>(static_cast<const Value*>(Key))),
+        Map(Map) {}
+
+public:
+  KeyT Unwrap() const { return cast_or_null<KeySansPointerT>(getValPtr()); }
+
+  virtual void deleted() {
+    // Make a copy that won't get changed even when *this is destroyed.
+    ValueMapCallbackVH Copy(*this);
+    sys::Mutex *M = Config::getMutex(Copy.Map->Data);
+    if (M)
+      M->acquire();
+    Config::onDelete(Copy.Map->Data, Copy.Unwrap());  // May destroy *this.
+    Copy.Map->Map.erase(Copy);  // Definitely destroys *this.
+    if (M)
+      M->release();
+  }
+  virtual void allUsesReplacedWith(Value *new_key) {
+    assert(isa<KeySansPointerT>(new_key) &&
+           "Invalid RAUW on key of ValueMap<>");
+    // Make a copy that won't get changed even when *this is destroyed.
+    ValueMapCallbackVH Copy(*this);
+    sys::Mutex *M = Config::getMutex(Copy.Map->Data);
+    if (M)
+      M->acquire();
+
+    KeyT typed_new_key = cast<KeySansPointerT>(new_key);
+    // Can destroy *this:
+    Config::onRAUW(Copy.Map->Data, Copy.Unwrap(), typed_new_key);
+    if (Config::FollowRAUW) {
+      typename ValueMapT::MapT::iterator I = Copy.Map->Map.find(Copy);
+      // I could == Copy.Map->Map.end() if the onRAUW callback already
+      // removed the old mapping.
+      if (I != Copy.Map->Map.end()) {
+        ValueT Target(I->second);
+        Copy.Map->Map.erase(I);  // Definitely destroys *this.
+        Copy.Map->insert(std::make_pair(typed_new_key, Target));
+      }
+    }
+    if (M)
+      M->release();
+  }
+};
+
+template<typename KeyT, typename ValueT, typename Config>
+struct DenseMapInfo<ValueMapCallbackVH<KeyT, ValueT, Config> > {
+  typedef ValueMapCallbackVH<KeyT, ValueT, Config> VH;
+  typedef DenseMapInfo<KeyT> PointerInfo;
+
+  static inline VH getEmptyKey() {
+    return VH(PointerInfo::getEmptyKey(), NULL);
+  }
+  static inline VH getTombstoneKey() {
+    return VH(PointerInfo::getTombstoneKey(), NULL);
+  }
+  static unsigned getHashValue(const VH &Val) {
+    return PointerInfo::getHashValue(Val.Unwrap());
+  }
+  static unsigned getHashValue(const KeyT &Val) {
+    return PointerInfo::getHashValue(Val);
+  }
+  static bool isEqual(const VH &LHS, const VH &RHS) {
+    return LHS == RHS;
+  }
+  static bool isEqual(const KeyT &LHS, const VH &RHS) {
+    return LHS == RHS.getValPtr();
+  }
+};
+
+
+template<typename DenseMapT, typename KeyT>
+class ValueMapIterator :
+    public std::iterator<std::forward_iterator_tag,
+                         std::pair<KeyT, typename DenseMapT::mapped_type>,
+                         ptrdiff_t> {
+  typedef typename DenseMapT::iterator BaseT;
+  typedef typename DenseMapT::mapped_type ValueT;
+  BaseT I;
+public:
+  ValueMapIterator() : I() {}
+
+  ValueMapIterator(BaseT I) : I(I) {}
+
+  BaseT base() const { return I; }
+
+  struct ValueTypeProxy {
+    const KeyT first;
+    ValueT& second;
+    ValueTypeProxy *operator->() { return this; }
+    operator std::pair<KeyT, ValueT>() const {
+      return std::make_pair(first, second);
+    }
+  };
+
+  ValueTypeProxy operator*() const {
+    ValueTypeProxy Result = {I->first.Unwrap(), I->second};
+    return Result;
+  }
+
+  ValueTypeProxy operator->() const {
+    return operator*();
+  }
+
+  bool operator==(const ValueMapIterator &RHS) const {
+    return I == RHS.I;
+  }
+  bool operator!=(const ValueMapIterator &RHS) const {
+    return I != RHS.I;
+  }
+
+  inline ValueMapIterator& operator++() {  // Preincrement
+    ++I;
+    return *this;
+  }
+  ValueMapIterator operator++(int) {  // Postincrement
+    ValueMapIterator tmp = *this; ++*this; return tmp;
+  }
+};
+
+template<typename DenseMapT, typename KeyT>
+class ValueMapConstIterator :
+    public std::iterator<std::forward_iterator_tag,
+                         std::pair<KeyT, typename DenseMapT::mapped_type>,
+                         ptrdiff_t> {
+  typedef typename DenseMapT::const_iterator BaseT;
+  typedef typename DenseMapT::mapped_type ValueT;
+  BaseT I;
+public:
+  ValueMapConstIterator() : I() {}
+  ValueMapConstIterator(BaseT I) : I(I) {}
+  ValueMapConstIterator(ValueMapIterator<DenseMapT, KeyT> Other)
+    : I(Other.base()) {}
+
+  BaseT base() const { return I; }
+
+  struct ValueTypeProxy {
+    const KeyT first;
+    const ValueT& second;
+    ValueTypeProxy *operator->() { return this; }
+    operator std::pair<KeyT, ValueT>() const {
+      return std::make_pair(first, second);
+    }
+  };
+
+  ValueTypeProxy operator*() const {
+    ValueTypeProxy Result = {I->first.Unwrap(), I->second};
+    return Result;
+  }
+
+  ValueTypeProxy operator->() const {
+    return operator*();
+  }
+
+  bool operator==(const ValueMapConstIterator &RHS) const {
+    return I == RHS.I;
+  }
+  bool operator!=(const ValueMapConstIterator &RHS) const {
+    return I != RHS.I;
+  }
+
+  inline ValueMapConstIterator& operator++() {  // Preincrement
+    ++I;
+    return *this;
+  }
+  ValueMapConstIterator operator++(int) {  // Postincrement
+    ValueMapConstIterator tmp = *this; ++*this; return tmp;
+  }
+};
+
+} // end namespace llvm
+
+#endif
index 6c4e50125ef3a5609780922ed4dd14bff0222d34..13532e80093102592a81062236513e206a1982bb 100644 (file)
@@ -20,8 +20,8 @@
 
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/Twine.h"
-#include "llvm/ADT/ValueMap.h"
 #include "llvm/IR/ValueHandle.h"
+#include "llvm/IR/ValueMap.h"
 #include "llvm/Transforms/Utils/ValueMapper.h"
 
 namespace llvm {
index d56ac07690fd540f50224aede38c114e2c63a6e3..e96610e76af8836978e15f2df81c328368936d76 100644 (file)
@@ -15,7 +15,7 @@
 #ifndef LLVM_TRANSFORMS_UTILS_VALUEMAPPER_H
 #define LLVM_TRANSFORMS_UTILS_VALUEMAPPER_H
 
-#include "llvm/ADT/ValueMap.h"
+#include "llvm/IR/ValueMap.h"
 
 namespace llvm {
   class Value;
index 7e2dce6a717b52145c8a85f76b2747a43072fd29..d9ee0e8c799cb41c934ab0f904a892faaacd0a07 100644 (file)
@@ -18,7 +18,6 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/Statistic.h"
-#include "llvm/ADT/ValueMap.h"
 #include "llvm/Analysis/InstructionSimplify.h"
 #include "llvm/IR/CallSite.h"
 #include "llvm/IR/Constants.h"
@@ -33,6 +32,7 @@
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/PatternMatch.h"
 #include "llvm/IR/ValueHandle.h"
+#include "llvm/IR/ValueMap.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
index ba5d4e42addc7314fbe832c4ce9962a3a9690278..b660f0149aa2e0876b922f5d26651c5da0102f1d 100644 (file)
@@ -19,7 +19,6 @@
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/Statistic.h"
-#include "llvm/ADT/ValueMap.h"
 #include "llvm/CodeGen/JITCodeEmitter.h"
 #include "llvm/CodeGen/MachineCodeInfo.h"
 #include "llvm/CodeGen/MachineConstantPool.h"
@@ -36,6 +35,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/ValueHandle.h"
+#include "llvm/IR/ValueMap.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Disassembler.h"
 #include "llvm/Support/ErrorHandling.h"
index d54c3606431d4fea40853c015d4eaacbc95b322c..3e14c8cbf801bb942963d7ec78bda54b33194bec 100644 (file)
 #include "Mips16HardFloatInfo.h"
 #include "MipsSubtarget.h"
 #include "llvm/ADT/StringMap.h"
-#include "llvm/ADT/ValueMap.h"
 #include "llvm/CodeGen/MachineFrameInfo.h"
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/MachineMemOperand.h"
 #include "llvm/CodeGen/PseudoSourceValue.h"
 #include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/ValueMap.h"
 #include "llvm/Target/TargetFrameLowering.h"
 #include "llvm/Target/TargetMachine.h"
 #include <map>
index a211dba0c0f910629e932c075f147540c16a21da..860d93935742accbe79fc017f91c9bcd3633f2ac 100644 (file)
@@ -15,7 +15,6 @@
 #include "NVPTX.h"
 #include "MCTargetDesc/NVPTXBaseInfo.h"
 #include "NVPTXUtilities.h"
-#include "llvm/ADT/ValueMap.h"
 #include "llvm/CodeGen/MachineFunctionAnalysis.h"
 #include "llvm/CodeGen/ValueTypes.h"
 #include "llvm/IR/Constants.h"
@@ -25,6 +24,7 @@
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Operator.h"
+#include "llvm/IR/ValueMap.h"
 #include "llvm/PassManager.h"
 
 using namespace llvm;
index fea875c3e75565727c82e5aee928bda2a709e9c5..e8c5f5b2dce84e20edc4b1e42e8bf91c2de7fdc1 100644 (file)
 #include "AMDGPURegisterInfo.h"
 #include "R600InstrInfo.h"
 #include "SIISelLowering.h"
-#include "llvm/ADT/ValueMap.h"
 #include "llvm/Analysis/ValueTracking.h"
 #include "llvm/CodeGen/MachineRegisterInfo.h"
 #include "llvm/CodeGen/PseudoSourceValue.h"
 #include "llvm/CodeGen/SelectionDAG.h"
 #include "llvm/CodeGen/SelectionDAGISel.h"
+#include "llvm/IR/ValueMap.h"
 #include "llvm/Support/Compiler.h"
 #include <list>
 #include <queue>
index f552bbffc0fa4c3caa7e067cb86acf6a7b017e49..519894c283a17c3bc57d28c17a4eba6940a496cd 100644 (file)
@@ -18,7 +18,7 @@
 
 #define DEBUG_TYPE "debug-ir"
 
-#include "llvm/ADT/ValueMap.h"
+#include "llvm/IR/ValueMap.h"
 #include "DebugIR.h"
 #include "llvm/DIBuilder.h"
 #include "llvm/DebugInfo.h"
index 95129d2df1710152f946acf8f8b8a6063850f6fd..6e517174bf8c6e4707c31a04cad608d24975208b 100644 (file)
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/Triple.h"
-#include "llvm/ADT/ValueMap.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/MDBuilder.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Type.h"
+#include "llvm/IR/ValueMap.h"
 #include "llvm/InstVisitor.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Compiler.h"
index 27b37f4dc69b5a431c2f812a11aedd141462be8e..c01bbe557dc120897b009766119201620194b0fe 100644 (file)
@@ -16,7 +16,7 @@
 #ifndef BUGDRIVER_H
 #define BUGDRIVER_H
 
-#include "llvm/ADT/ValueMap.h"
+#include "llvm/IR/ValueMap.h"
 #include "llvm/Transforms/Utils/ValueMapper.h"
 #include <string>
 #include <vector>
index 4c8a4a9372dfccdbe16173ba1d8ef7e8bf8c07c4..2e7e5dc493594537a803edce256842e0aa0468b9 100644 (file)
@@ -7,7 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/ADT/ValueMap.h"
+#include "llvm/IR/ValueMap.h"
 #include "llvm/ADT/OwningPtr.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/IR/Constants.h"