aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/IR/ValueMap.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/IR/ValueMap.h')
-rw-r--r--include/llvm/IR/ValueMap.h19
1 files changed, 11 insertions, 8 deletions
diff --git a/include/llvm/IR/ValueMap.h b/include/llvm/IR/ValueMap.h
index 1503aed..43a79c7 100644
--- a/include/llvm/IR/ValueMap.h
+++ b/include/llvm/IR/ValueMap.h
@@ -45,8 +45,10 @@ 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>
+template<typename KeyT, typename MutexT = sys::Mutex>
struct ValueMapConfig {
+ typedef MutexT mutex_type;
+
/// 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 };
@@ -67,7 +69,7 @@ struct ValueMapConfig {
/// 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 nullptr; }
+ static mutex_type *getMutex(const ExtraDataT &/*Data*/) { return nullptr; }
};
/// See the file comment.
@@ -85,6 +87,7 @@ public:
typedef KeyT key_type;
typedef ValueT mapped_type;
typedef std::pair<KeyT, ValueT> value_type;
+ typedef unsigned size_type;
explicit ValueMap(unsigned NumInitBuckets = 64)
: Map(NumInitBuckets), Data() {}
@@ -101,16 +104,16 @@ public:
inline const_iterator end() const { return const_iterator(Map.end()); }
bool empty() const { return Map.empty(); }
- unsigned size() const { return Map.size(); }
+ size_type 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();
+ /// Return 1 if the specified key is in the map, 0 otherwise.
+ size_type count(const KeyT &Val) const {
+ return Map.find_as(Val) == Map.end() ? 0 : 1;
}
iterator find(const KeyT &Val) {
@@ -212,7 +215,7 @@ public:
void deleted() override {
// Make a copy that won't get changed even when *this is destroyed.
ValueMapCallbackVH Copy(*this);
- sys::Mutex *M = Config::getMutex(Copy.Map->Data);
+ typename Config::mutex_type *M = Config::getMutex(Copy.Map->Data);
if (M)
M->acquire();
Config::onDelete(Copy.Map->Data, Copy.Unwrap()); // May destroy *this.
@@ -225,7 +228,7 @@ public:
"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);
+ typename Config::mutex_type *M = Config::getMutex(Copy.Map->Data);
if (M)
M->acquire();