[PATCH] D159014: [llvm-profdata] Use std::unordered_map in SampleProfileMap

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


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG33810543ab3c: [llvm-profdata] Use std::unordered_map in SampleProfileMap (authored by huangjd).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159014/new/

https://reviews.llvm.org/D159014

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


Index: llvm/include/llvm/ProfileData/SampleProf.h
===================================================================
--- llvm/include/llvm/ProfileData/SampleProf.h
+++ llvm/include/llvm/ProfileData/SampleProf.h
@@ -1412,7 +1412,7 @@
 /// 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 @@
   }
 
   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 @@
   }
 
   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); }
Index: llvm/include/llvm/ADT/Hashing.h
===================================================================
--- llvm/include/llvm/ADT/Hashing.h
+++ llvm/include/llvm/ADT/Hashing.h
@@ -683,4 +683,16 @@
 
 } // 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159014.554078.patch
Type: text/x-patch
Size: 2012 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230828/0f20e89a/attachment.bin>


More information about the llvm-commits mailing list