[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 13:33:46 PDT 2023
huangjd created this revision.
huangjd added reviewers: davidxl, snehasish, wenlei, ayermolo.
Herald added a project: All.
huangjd requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Patch D147740 <https://reviews.llvm.org/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.
Repository:
rG LLVM Github Monorepo
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,12 @@
} // namespace llvm
+/// Implement std::hash so that hash_code can be used in STL containers.
+template<>
+struct std::hash<llvm::hash_code> {
+ size_t operator()(llvm::hash_code const& Obj) const {
+ return Obj;
+ }
+};
+
#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159014.554033.patch
Type: text/x-patch
Size: 1975 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230828/015cb64a/attachment-0001.bin>
More information about the llvm-commits
mailing list