Changeset View
Changeset View
Standalone View
Standalone View
include/llvm/IR/ValueMap.h
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | struct ValueMapConfig { | ||||
template<typename ExtraDataT> | template<typename ExtraDataT> | ||||
static void onDelete(const ExtraDataT &/*Data*/, KeyT /*Old*/) {} | static void onDelete(const ExtraDataT &/*Data*/, KeyT /*Old*/) {} | ||||
/// Returns a mutex that should be acquired around any changes to the map. | /// 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 | /// 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 | /// and onDelete) and not inside other ValueMap methods. NULL means that no | ||||
/// mutex is necessary. | /// mutex is necessary. | ||||
template<typename ExtraDataT> | template<typename ExtraDataT> | ||||
static sys::Mutex *getMutex(const ExtraDataT &/*Data*/) { return nullptr; } | static sys::MutexBase *getMutex(const ExtraDataT &/*Data*/) { return nullptr; } | ||||
}; | }; | ||||
/// See the file comment. | /// See the file comment. | ||||
template<typename KeyT, typename ValueT, typename Config =ValueMapConfig<KeyT> > | template<typename KeyT, typename ValueT, typename Config =ValueMapConfig<KeyT> > | ||||
class ValueMap { | class ValueMap { | ||||
friend class ValueMapCallbackVH<KeyT, ValueT, Config>; | friend class ValueMapCallbackVH<KeyT, ValueT, Config>; | ||||
typedef ValueMapCallbackVH<KeyT, ValueT, Config> ValueMapCVH; | typedef ValueMapCallbackVH<KeyT, ValueT, Config> ValueMapCVH; | ||||
typedef DenseMap<ValueMapCVH, ValueT, DenseMapInfo<ValueMapCVH> > MapT; | typedef DenseMap<ValueMapCVH, ValueT, DenseMapInfo<ValueMapCVH> > MapT; | ||||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | ValueMapCallbackVH(KeyT Key, ValueMapT *Map) | ||||
Map(Map) {} | Map(Map) {} | ||||
public: | public: | ||||
KeyT Unwrap() const { return cast_or_null<KeySansPointerT>(getValPtr()); } | KeyT Unwrap() const { return cast_or_null<KeySansPointerT>(getValPtr()); } | ||||
void deleted() override { | void deleted() override { | ||||
// Make a copy that won't get changed even when *this is destroyed. | // Make a copy that won't get changed even when *this is destroyed. | ||||
ValueMapCallbackVH Copy(*this); | ValueMapCallbackVH Copy(*this); | ||||
sys::Mutex *M = Config::getMutex(Copy.Map->Data); | sys::MutexBase *M = Config::getMutex(Copy.Map->Data); | ||||
if (M) | if (M) | ||||
M->acquire(); | M->acquire(); | ||||
Config::onDelete(Copy.Map->Data, Copy.Unwrap()); // May destroy *this. | Config::onDelete(Copy.Map->Data, Copy.Unwrap()); // May destroy *this. | ||||
Copy.Map->Map.erase(Copy); // Definitely destroys *this. | Copy.Map->Map.erase(Copy); // Definitely destroys *this. | ||||
if (M) | if (M) | ||||
M->release(); | M->release(); | ||||
} | } | ||||
void allUsesReplacedWith(Value *new_key) override { | void allUsesReplacedWith(Value *new_key) override { | ||||
assert(isa<KeySansPointerT>(new_key) && | assert(isa<KeySansPointerT>(new_key) && | ||||
"Invalid RAUW on key of ValueMap<>"); | "Invalid RAUW on key of ValueMap<>"); | ||||
// Make a copy that won't get changed even when *this is destroyed. | // Make a copy that won't get changed even when *this is destroyed. | ||||
ValueMapCallbackVH Copy(*this); | ValueMapCallbackVH Copy(*this); | ||||
sys::Mutex *M = Config::getMutex(Copy.Map->Data); | sys::MutexBase *M = Config::getMutex(Copy.Map->Data); | ||||
if (M) | if (M) | ||||
M->acquire(); | M->acquire(); | ||||
KeyT typed_new_key = cast<KeySansPointerT>(new_key); | KeyT typed_new_key = cast<KeySansPointerT>(new_key); | ||||
// Can destroy *this: | // Can destroy *this: | ||||
Config::onRAUW(Copy.Map->Data, Copy.Unwrap(), typed_new_key); | Config::onRAUW(Copy.Map->Data, Copy.Unwrap(), typed_new_key); | ||||
if (Config::FollowRAUW) { | if (Config::FollowRAUW) { | ||||
typename ValueMapT::MapT::iterator I = Copy.Map->Map.find(Copy); | typename ValueMapT::MapT::iterator I = Copy.Map->Map.find(Copy); | ||||
▲ Show 20 Lines • Show All 141 Lines • Show Last 20 Lines |