[llvm-branch-commits] [llvm-branch] r85309 - in /llvm/branches/Apple/Leela: docs/ProgrammersManual.html include/llvm/ADT/DenseMap.h include/llvm/ADT/ValueMap.h include/llvm/Support/type_traits.h unittests/ADT/ValueMapTest.cpp
Bill Wendling
isanbard at gmail.com
Tue Oct 27 14:15:54 PDT 2009
Author: void
Date: Tue Oct 27 16:15:53 2009
New Revision: 85309
URL: http://llvm.org/viewvc/llvm-project?rev=85309&view=rev
Log:
$ svn merge -c 84902 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r84902 into '.':
U include/llvm/ADT/ValueMap.h
G docs/ProgrammersManual.html
U unittests/ADT/ValueMapTest.cpp
$ svn merge -c 84967 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r84967 into '.':
U include/llvm/ADT/DenseMap.h
U include/llvm/ADT/ValueMap.h
U unittests/ADT/ValueMapTest.cpp
$ svn merge -c 85198 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85198 into '.':
G include/llvm/ADT/ValueMap.h
Added:
llvm/branches/Apple/Leela/include/llvm/ADT/ValueMap.h
- copied, changed from r84890, llvm/trunk/include/llvm/ADT/ValueMap.h
llvm/branches/Apple/Leela/unittests/ADT/ValueMapTest.cpp
- copied, changed from r84890, llvm/trunk/unittests/ADT/ValueMapTest.cpp
Modified:
llvm/branches/Apple/Leela/docs/ProgrammersManual.html
llvm/branches/Apple/Leela/include/llvm/ADT/DenseMap.h
llvm/branches/Apple/Leela/include/llvm/Support/type_traits.h
Modified: llvm/branches/Apple/Leela/docs/ProgrammersManual.html
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/docs/ProgrammersManual.html?rev=85309&r1=85308&r2=85309&view=diff
==============================================================================
--- llvm/branches/Apple/Leela/docs/ProgrammersManual.html (original)
+++ llvm/branches/Apple/Leela/docs/ProgrammersManual.html Tue Oct 27 16:15:53 2009
@@ -83,6 +83,7 @@
<li><a href="#dss_stringmap">"llvm/ADT/StringMap.h"</a></li>
<li><a href="#dss_indexedmap">"llvm/ADT/IndexedMap.h"</a></li>
<li><a href="#dss_densemap">"llvm/ADT/DenseMap.h"</a></li>
+ <li><a href="#dss_valuemap">"llvm/ADT/ValueMap.h"</a></li>
<li><a href="#dss_map"><map></a></li>
<li><a href="#dss_othermap">Other Map-Like Container Options</a></li>
</ul></li>
@@ -1492,6 +1493,23 @@
<!-- _______________________________________________________________________ -->
<div class="doc_subsubsection">
+ <a name="dss_valuemap">"llvm/ADT/ValueMap.h"</a>
+</div>
+
+<div class="doc_text">
+
+<p>
+ValueMap is a wrapper around a <a href="#dss_densemap">DenseMap</a> mapping
+Value*s (or subclasses) to another type. When a Value is deleted or RAUW'ed,
+ValueMap will update itself so the new version of the key is mapped to the same
+value, just as if the key were a WeakVH. You can configure exactly how this
+happens, and what else happens on these two events, by passing
+a <code>Config</code> parameter to the ValueMap template.</p>
+
+</div>
+
+<!-- _______________________________________________________________________ -->
+<div class="doc_subsubsection">
<a name="dss_map"><map></a>
</div>
Modified: llvm/branches/Apple/Leela/include/llvm/ADT/DenseMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/ADT/DenseMap.h?rev=85309&r1=85308&r2=85309&view=diff
==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/ADT/DenseMap.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/ADT/DenseMap.h Tue Oct 27 16:15:53 2009
@@ -454,12 +454,12 @@
return Ptr != RHS.Ptr;
}
- inline DenseMapIterator& operator++() { // Preincrement
+ inline DenseMapIterator& operator++() { // Preincrement
++Ptr;
AdvancePastEmptyBuckets();
return *this;
}
- DenseMapIterator operator++(int) { // Postincrement
+ DenseMapIterator operator++(int) { // Postincrement
DenseMapIterator tmp = *this; ++*this; return tmp;
}
Copied: llvm/branches/Apple/Leela/include/llvm/ADT/ValueMap.h (from r84890, llvm/trunk/include/llvm/ADT/ValueMap.h)
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/ADT/ValueMap.h?p2=llvm/branches/Apple/Leela/include/llvm/ADT/ValueMap.h&p1=llvm/trunk/include/llvm/ADT/ValueMap.h&r1=84890&r2=85309&rev=85309&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/ValueMap.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/ADT/ValueMap.h Tue Oct 27 16:15:53 2009
@@ -7,7 +7,19 @@
//
//===----------------------------------------------------------------------===//
//
-// This file defines the ValueMap class.
+// 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.
//
//===----------------------------------------------------------------------===//
@@ -31,6 +43,9 @@
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
@@ -46,27 +61,17 @@
template<typename ExtraDataT>
static void onRAUW(const ExtraDataT &Data, KeyT Old, KeyT New) {}
template<typename ExtraDataT>
- static void onDeleted(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.
/// This is only acquired from the CallbackVH (and held around calls to onRAUW
- /// and onDeleted) 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.
template<typename ExtraDataT>
static sys::Mutex *getMutex(const ExtraDataT &Data) { return NULL; }
};
-/// ValueMap maps Value* or any subclass to an arbitrary other
-/// type. It provides the DenseMap interface. When the key values are
-/// deleted or RAUWed, ValueMap relies on the Config to decide what to
-/// do. Config parameters should inherit from ValueMapConfig<KeyT> to
-/// get default implementations of all the methods ValueMap uses.
-///
-/// 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 Config to get
-/// called back on each event.
+/// See the file comment.
template<typename KeyT, typename ValueT, typename Config = ValueMapConfig<KeyT>,
typename ValueInfoT = DenseMapInfo<ValueT> >
class ValueMap {
@@ -177,6 +182,9 @@
}
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
@@ -186,16 +194,18 @@
}
};
+// 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, typename ValueInfoT>
class ValueMapCallbackVH : public CallbackVH {
friend class ValueMap<KeyT, ValueT, Config, ValueInfoT>;
- friend class DenseMapInfo<ValueMapCallbackVH>;
- typedef ValueMap<KeyT, ValueT, Config, ValueInfoT> ValueMap;
+ friend struct DenseMapInfo<ValueMapCallbackVH>;
+ typedef ValueMap<KeyT, ValueT, Config, ValueInfoT> ValueMapT;
typedef typename llvm::remove_pointer<KeyT>::type KeySansPointerT;
- ValueMap *Map;
+ ValueMapT *Map;
- ValueMapCallbackVH(KeyT Key, ValueMap *Map)
+ ValueMapCallbackVH(KeyT Key, ValueMapT *Map)
: CallbackVH(const_cast<Value*>(static_cast<const Value*>(Key))),
Map(Map) {}
@@ -208,7 +218,7 @@
sys::Mutex *M = Config::getMutex(Copy.Map->Data);
if (M)
M->acquire();
- Config::onDeleted(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.
if (M)
M->release();
@@ -226,7 +236,7 @@
// Can destroy *this:
Config::onRAUW(Copy.Map->Data, Copy.Unwrap(), typed_new_key);
if (Config::FollowRAUW) {
- typename ValueMap::MapT::iterator I = Copy.Map->Map.find(Copy);
+ 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()) {
@@ -279,7 +289,7 @@
struct ValueTypeProxy {
const KeyT first;
ValueT& second;
- ValueTypeProxy *operator->() { return this; }
+ ValueTypeProxy *operator->() { return this; }
operator std::pair<KeyT, ValueT>() const {
return std::make_pair(first, second);
}
@@ -301,11 +311,11 @@
return I != RHS.I;
}
- inline ValueMapIterator& operator++() { // Preincrement
+ inline ValueMapIterator& operator++() { // Preincrement
++I;
return *this;
}
- ValueMapIterator operator++(int) { // Postincrement
+ ValueMapIterator operator++(int) { // Postincrement
ValueMapIterator tmp = *this; ++*this; return tmp;
}
};
@@ -329,7 +339,7 @@
struct ValueTypeProxy {
const KeyT first;
const ValueT& second;
- ValueTypeProxy *operator->() { return this; }
+ ValueTypeProxy *operator->() { return this; }
operator std::pair<KeyT, ValueT>() const {
return std::make_pair(first, second);
}
@@ -351,11 +361,11 @@
return I != RHS.I;
}
- inline ValueMapConstIterator& operator++() { // Preincrement
+ inline ValueMapConstIterator& operator++() { // Preincrement
++I;
return *this;
}
- ValueMapConstIterator operator++(int) { // Postincrement
+ ValueMapConstIterator operator++(int) { // Postincrement
ValueMapConstIterator tmp = *this; ++*this; return tmp;
}
};
Modified: llvm/branches/Apple/Leela/include/llvm/Support/type_traits.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Support/type_traits.h?rev=85309&r1=85308&r2=85309&view=diff
==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Support/type_traits.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Support/type_traits.h Tue Oct 27 16:15:53 2009
@@ -76,6 +76,15 @@
sizeof(char) == sizeof(dont_use::base_of_helper<Base>((Derived*)0));
};
+// remove_pointer - Metafunction to turn Foo* into Foo. Defined in
+// C++0x [meta.trans.ptr].
+template <typename T> struct remove_pointer { typedef T type; };
+template <typename T> struct remove_pointer<T*> { typedef T type; };
+template <typename T> struct remove_pointer<T*const> { typedef T type; };
+template <typename T> struct remove_pointer<T*volatile> { typedef T type; };
+template <typename T> struct remove_pointer<T*const volatile> {
+ typedef T type; };
+
}
#endif
Copied: llvm/branches/Apple/Leela/unittests/ADT/ValueMapTest.cpp (from r84890, llvm/trunk/unittests/ADT/ValueMapTest.cpp)
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/unittests/ADT/ValueMapTest.cpp?p2=llvm/branches/Apple/Leela/unittests/ADT/ValueMapTest.cpp&p1=llvm/trunk/unittests/ADT/ValueMapTest.cpp&r1=84890&r2=85309&rev=85309&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/ValueMapTest.cpp (original)
+++ llvm/branches/Apple/Leela/unittests/ADT/ValueMapTest.cpp Tue Oct 27 16:15:53 2009
@@ -8,8 +8,8 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/ValueMap.h"
-
#include "llvm/Instructions.h"
+#include "llvm/LLVMContext.h"
#include "llvm/ADT/OwningPtr.h"
#include "gtest/gtest.h"
@@ -187,7 +187,7 @@
*Data.CalledRAUW = true;
EXPECT_FALSE(Data.M->tryacquire()) << "Mutex should already be locked.";
}
- static void onDeleted(const ExtraData &Data, KeyT Old) {
+ static void onDelete(const ExtraData &Data, KeyT Old) {
*Data.CalledDeleted = true;
EXPECT_FALSE(Data.M->tryacquire()) << "Mutex should already be locked.";
}
@@ -238,7 +238,7 @@
static void onRAUW(const ExtraData &Data, KeyT Old, KeyT New) {
++*Data.RAUWs;
}
- static void onDeleted(const ExtraData &Data, KeyT Old) {
+ static void onDelete(const ExtraData &Data, KeyT Old) {
++*Data.Deletions;
}
};
@@ -270,7 +270,7 @@
static void onRAUW(ExtraData Map, KeyT Old, KeyT New) {
(*Map)->erase(Old);
}
- static void onDeleted(ExtraData Map, KeyT Old) {
+ static void onDelete(ExtraData Map, KeyT Old) {
(*Map)->erase(Old);
}
};
More information about the llvm-branch-commits
mailing list