[compiler-rt] ea0ce32 - [ORC-RT] Make ExecutorAddr hashable.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 7 21:11:15 PST 2022


Author: Lang Hames
Date: 2022-02-08T16:11:07+11:00
New Revision: ea0ce326fd12178b1797b7f3e3b2a204d22d0ab7

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

LOG: [ORC-RT] Make ExecutorAddr hashable.

This will be used in an upcoming macho_platform patch.

Added: 
    

Modified: 
    compiler-rt/lib/orc/executor_address.h
    compiler-rt/lib/orc/unittests/executor_address_test.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/orc/executor_address.h b/compiler-rt/lib/orc/executor_address.h
index 79ad9b7f1409..f8f417cb636d 100644
--- a/compiler-rt/lib/orc/executor_address.h
+++ b/compiler-rt/lib/orc/executor_address.h
@@ -212,4 +212,15 @@ using SPSExecutorAddrRangeSequence = SPSSequence<SPSExecutorAddrRange>;
 
 } // End namespace __orc_rt
 
+namespace std {
+
+// Make ExecutorAddr hashable.
+template <> struct hash<__orc_rt::ExecutorAddr> {
+  size_t operator()(const __orc_rt::ExecutorAddr &A) const {
+    return hash<uint64_t>()(A.getValue());
+  }
+};
+
+} // namespace std
+
 #endif // ORC_RT_EXECUTOR_ADDRESS_H

diff  --git a/compiler-rt/lib/orc/unittests/executor_address_test.cpp b/compiler-rt/lib/orc/unittests/executor_address_test.cpp
index 19a794ab6e18..7712ef9a773f 100644
--- a/compiler-rt/lib/orc/unittests/executor_address_test.cpp
+++ b/compiler-rt/lib/orc/unittests/executor_address_test.cpp
@@ -75,3 +75,10 @@ TEST(ExecutorAddrTest, AddrRanges) {
   EXPECT_TRUE(R1.overlaps(R3));
   EXPECT_TRUE(R1.overlaps(R4));
 }
+
+TEST(ExecutorAddrTest, Hashable) {
+  uint64_t RawAddr = 0x1234567890ABCDEF;
+  ExecutorAddr Addr(RawAddr);
+
+  EXPECT_EQ(std::hash<uint64_t>()(RawAddr), std::hash<ExecutorAddr>()(Addr));
+}


        


More information about the llvm-commits mailing list