[llvm-commits] [llvm] r157124 - /llvm/trunk/include/llvm/ADT/ValueMap.h

Benjamin Kramer benny.kra at googlemail.com
Sat May 19 12:15:32 PDT 2012


Author: d0k
Date: Sat May 19 14:15:32 2012
New Revision: 157124

URL: http://llvm.org/viewvc/llvm-project?rev=157124&view=rev
Log:
ValueMap: Use DenseMap's find_as mechanism to reduce use list churn.

Otherwise just looking up a value in the map requires creating a VH, adding it to the use lists and destroying it again.

Modified:
    llvm/trunk/include/llvm/ADT/ValueMap.h

Modified: llvm/trunk/include/llvm/ADT/ValueMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/ValueMap.h?rev=157124&r1=157123&r2=157124&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/ValueMap.h (original)
+++ llvm/trunk/include/llvm/ADT/ValueMap.h Sat May 19 14:15:32 2012
@@ -111,20 +111,21 @@
 
   /// count - Return true if the specified key is in the map.
   bool count(const KeyT &Val) const {
-    return Map.count(Wrap(Val));
+    return Map.find_as(Val) != Map.end();
   }
 
   iterator find(const KeyT &Val) {
-    return iterator(Map.find(Wrap(Val)));
+    return iterator(Map.find_as(Val));
   }
   const_iterator find(const KeyT &Val) const {
-    return const_iterator(Map.find(Wrap(Val)));
+    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 {
-    return Map.lookup(Wrap(Val));
+    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.
@@ -145,7 +146,12 @@
 
 
   bool erase(const KeyT &Val) {
-    return Map.erase(Wrap(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());
@@ -256,9 +262,15 @@
   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;
+  }
 };
 
 





More information about the llvm-commits mailing list