[llvm] [ADT] Use a constexpr version of llvm::bit_ceil (NFC) (PR #79709)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 27 13:51:06 PST 2024
================
@@ -311,30 +312,17 @@ class LLVM_DEBUGEPOCHBASE_HANDLEBASE_EMPTYBASE SmallPtrSetIterator
}
};
-/// RoundUpToPowerOfTwo - This is a helper template that rounds N up to the next
-/// power of two (which means N itself if N is already a power of two).
-template<unsigned N>
-struct RoundUpToPowerOfTwo;
-
-/// RoundUpToPowerOfTwoH - If N is not a power of two, increase it. This is a
-/// helper template used to implement RoundUpToPowerOfTwo.
-template<unsigned N, bool isPowerTwo>
-struct RoundUpToPowerOfTwoH {
- enum { Val = N };
-};
-template<unsigned N>
-struct RoundUpToPowerOfTwoH<N, false> {
- enum {
- // We could just use NextVal = N+1, but this converges faster. N|(N-1) sets
- // the right-most zero bits to one all at once, e.g. 0b0011000 -> 0b0011111.
- Val = RoundUpToPowerOfTwo<(N|(N-1)) + 1>::Val
- };
-};
-
-template<unsigned N>
-struct RoundUpToPowerOfTwo {
- enum { Val = RoundUpToPowerOfTwoH<N, (N&(N-1)) == 0>::Val };
-};
+namespace detail {
+// A constexpr version of llvm::bit_ceil.
+// TODO: Replace this with std::bit_ceil once C++20 is available.
----------------
MaskRay wrote:
Can llvm/ADT/bit.h bit_ceil be changed to constexpr and used here?
https://github.com/llvm/llvm-project/pull/79709
More information about the llvm-commits
mailing list