[compiler-rt] fb1c515 - Revert "[NFC][sanitizer] constexpr a few functions"
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 24 19:27:06 PDT 2021
Author: Vitaly Buka
Date: 2021-10-24T19:26:55-07:00
New Revision: fb1c515d3b124741485f53d5f3ec6850bc4037b4
URL: https://github.com/llvm/llvm-project/commit/fb1c515d3b124741485f53d5f3ec6850bc4037b4
DIFF: https://github.com/llvm/llvm-project/commit/fb1c515d3b124741485f53d5f3ec6850bc4037b4.diff
LOG: Revert "[NFC][sanitizer] constexpr a few functions"
This reverts a part of commit 8cd51a69e5b4cf9513eb4f416f113058ebd8f257
and 5bf24f0581ee7ab9971b4050497375464b894c59 to fix Windows.
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_common.h
compiler-rt/lib/sanitizer_common/sanitizer_flat_map.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
index b720d99d0d9d..f680aadc3c98 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
@@ -385,9 +385,9 @@ unsigned char _BitScanReverse64(unsigned long *index, unsigned __int64 mask);
}
#endif
-inline constexpr uptr MostSignificantSetBitIndex(uptr x) {
+inline uptr MostSignificantSetBitIndex(uptr x) {
CHECK_NE(x, 0U);
- unsigned long up = 0;
+ unsigned long up;
#if !SANITIZER_WINDOWS || defined(__clang__) || defined(__GNUC__)
# ifdef _WIN64
up = SANITIZER_WORDSIZE - 1 - __builtin_clzll(x);
@@ -402,9 +402,9 @@ inline constexpr uptr MostSignificantSetBitIndex(uptr x) {
return up;
}
-inline constexpr uptr LeastSignificantSetBitIndex(uptr x) {
+inline uptr LeastSignificantSetBitIndex(uptr x) {
CHECK_NE(x, 0U);
- unsigned long up = 0;
+ unsigned long up;
#if !SANITIZER_WINDOWS || defined(__clang__) || defined(__GNUC__)
# ifdef _WIN64
up = __builtin_ctzll(x);
@@ -421,7 +421,7 @@ inline constexpr uptr LeastSignificantSetBitIndex(uptr x) {
inline constexpr bool IsPowerOfTwo(uptr x) { return (x & (x - 1)) == 0; }
-inline constexpr uptr RoundUpToPowerOfTwo(uptr size) {
+inline uptr RoundUpToPowerOfTwo(uptr size) {
CHECK(size);
if (IsPowerOfTwo(size)) return size;
@@ -444,7 +444,7 @@ inline constexpr bool IsAligned(uptr a, uptr alignment) {
return (a & (alignment - 1)) == 0;
}
-inline constexpr uptr Log2(uptr x) {
+inline uptr Log2(uptr x) {
CHECK(IsPowerOfTwo(x));
return LeastSignificantSetBitIndex(x);
}
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_flat_map.h b/compiler-rt/lib/sanitizer_common/sanitizer_flat_map.h
index 0f7467c47e73..e8c34c1e13fd 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_flat_map.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_flat_map.h
@@ -65,9 +65,7 @@ template <typename T, u64 kSize1, u64 kSize2,
typename AddressSpaceViewTy = LocalAddressSpaceView,
class MapUnmapCallback = NoOpMapUnmapCallback>
class TwoLevelMap {
- static_assert(IsPowerOfTwo(kSize2), "");
- static constexpr uptr kSize2Shift = Log2(kSize2);
- static constexpr uptr kSize2Mask = kSize2 - 1;
+ static_assert(IsPowerOfTwo(kSize2), "Use a power of two for performance.");
public:
using AddressSpaceView = AddressSpaceViewTy;
@@ -104,19 +102,19 @@ class TwoLevelMap {
bool contains(uptr idx) const {
CHECK_LT(idx, kSize1 * kSize2);
- return Get(idx >> kSize2Shift);
+ return Get(idx / kSize2);
}
const T &operator[](uptr idx) const {
DCHECK_LT(idx, kSize1 * kSize2);
- T *map2 = GetOrCreate(idx >> kSize2Shift);
- return *AddressSpaceView::Load(&map2[idx & kSize2Mask]);
+ T *map2 = GetOrCreate(idx / kSize2);
+ return *AddressSpaceView::Load(&map2[idx % kSize2]);
}
T &operator[](uptr idx) {
DCHECK_LT(idx, kSize1 * kSize2);
- T *map2 = GetOrCreate(idx >> kSize2Shift);
- return *AddressSpaceView::LoadWritable(&map2[idx & kSize2Mask]);
+ T *map2 = GetOrCreate(idx / kSize2);
+ return *AddressSpaceView::LoadWritable(&map2[idx % kSize2]);
}
private:
More information about the llvm-commits
mailing list