[compiler-rt] 948b91a - [NFC][sanitizer] Atomix relaxed in TwoLevelMap
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 31 12:18:08 PDT 2021
Author: Vitaly Buka
Date: 2021-10-31T12:18:03-07:00
New Revision: 948b91a08e1712a6e2226eca5baf14a13a0c9ba5
URL: https://github.com/llvm/llvm-project/commit/948b91a08e1712a6e2226eca5baf14a13a0c9ba5
DIFF: https://github.com/llvm/llvm-project/commit/948b91a08e1712a6e2226eca5baf14a13a0c9ba5.diff
LOG: [NFC][sanitizer] Atomix relaxed in TwoLevelMap
This is NOOP in x86_64.
On arch64 it avoids Data Memory Barrier with visible improvements on micro benchmarks.
Reviewed By: dvyukov
Differential Revision: https://reviews.llvm.org/D112391
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_flat_map.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_flat_map.h b/compiler-rt/lib/sanitizer_common/sanitizer_flat_map.h
index e8c34c1e13fd..05fb554d20c1 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_flat_map.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_flat_map.h
@@ -129,7 +129,16 @@ class TwoLevelMap {
}
T *GetOrCreate(uptr idx) const {
- T *res = Get(idx);
+ DCHECK_LT(idx, kSize1);
+ // This code needs to use memory_order_acquire/consume, but we use
+ // memory_order_relaxed for performance reasons (matters for arm64). We
+ // expect memory_order_relaxed to be effectively equivalent to
+ // memory_order_consume in this case for all relevant architectures: all
+ // dependent data is reachable only by dereferencing the resulting pointer.
+ // If relaxed load fails to see stored ptr, the code will fall back to
+ // Create() and reload the value again with locked mutex as a memory
+ // barrier.
+ T *res = reinterpret_cast<T *>(atomic_load_relaxed(&map1_[idx]));
if (LIKELY(res))
return res;
return Create(idx);
More information about the llvm-commits
mailing list