[llvm] 3381054 - [llvm-profdata] Use std::unordered_map in SampleProfileMap

William Huang via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 28 15:32:40 PDT 2023


Author: William Huang
Date: 2023-08-28T22:31:19Z
New Revision: 33810543ab3c853da6596323035eeeaa8953d553

URL: https://github.com/llvm/llvm-project/commit/33810543ab3c853da6596323035eeeaa8953d553
DIFF: https://github.com/llvm/llvm-project/commit/33810543ab3c853da6596323035eeeaa8953d553.diff

LOG: [llvm-profdata] Use std::unordered_map in SampleProfileMap

Patch D147740 Change back to std::unordered_map for SampleProfileMap because it has reference validity, the change to use llvm::DenseMap is moved to a different patch.

Reviewed By: wenlei, ayermolo

Differential Revision: https://reviews.llvm.org/D159014

Added: 
    

Modified: 
    llvm/include/llvm/ADT/Hashing.h
    llvm/include/llvm/ProfileData/SampleProf.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/Hashing.h b/llvm/include/llvm/ADT/Hashing.h
index ef983105c7bae6..4e82ba9a6fba2a 100644
--- a/llvm/include/llvm/ADT/Hashing.h
+++ b/llvm/include/llvm/ADT/Hashing.h
@@ -683,4 +683,16 @@ template <> struct DenseMapInfo<hash_code, void> {
 
 } // namespace llvm
 
+/// Implement std::hash so that hash_code can be used in STL containers.
+namespace std {
+
+template<>
+struct hash<llvm::hash_code> {
+  size_t operator()(llvm::hash_code const& Val) const {
+    return Val;
+  }
+};
+
+} // namespace std;
+
 #endif

diff  --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h
index aacea59f282111..3cbfa94896e3a2 100644
--- a/llvm/include/llvm/ProfileData/SampleProf.h
+++ b/llvm/include/llvm/ProfileData/SampleProf.h
@@ -1412,7 +1412,7 @@ class HashKeyMap : public MapT<hash_code, ValueT, MapTArgs...> {
 /// Note: when populating container, make sure to assign the SampleContext to
 /// the mapped value immediately because the key no longer holds it.
 class SampleProfileMap
-    : public HashKeyMap<DenseMap, SampleContext, FunctionSamples> {
+    : public HashKeyMap<std::unordered_map, SampleContext, FunctionSamples> {
 public:
   // Convenience method because this is being used in many places. Set the
   // FunctionSamples' context if its newly inserted.
@@ -1424,12 +1424,12 @@ class SampleProfileMap
   }
 
   iterator find(const SampleContext &Ctx) {
-    return HashKeyMap<llvm::DenseMap, SampleContext, FunctionSamples>::find(
+    return HashKeyMap<std::unordered_map, SampleContext, FunctionSamples>::find(
         Ctx);
   }
 
   const_iterator find(const SampleContext &Ctx) const {
-    return HashKeyMap<llvm::DenseMap, SampleContext, FunctionSamples>::find(
+    return HashKeyMap<std::unordered_map, SampleContext, FunctionSamples>::find(
         Ctx);
   }
 
@@ -1449,8 +1449,8 @@ class SampleProfileMap
   }
 
   size_t erase(const SampleContext &Ctx) {
-    return HashKeyMap<llvm::DenseMap, SampleContext, FunctionSamples>::erase(
-        Ctx);
+    return HashKeyMap<std::unordered_map, SampleContext, FunctionSamples>::
+        erase(Ctx);
   }
 
   size_t erase(const key_type &Key) { return base_type::erase(Key); }


        


More information about the llvm-commits mailing list