From e0ba22227da4b942709a1dc3e0e4736c2e145ce5 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Tue, 7 Oct 2025 07:19:57 -0700 Subject: [PATCH 1/2] [ADT] Modernize Bitset (NFC) This patch modernizes BitWord and BITWORD_SIZE with "using" and "static constexpr", respectively. --- llvm/include/llvm/ADT/Bitset.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/ADT/Bitset.h b/llvm/include/llvm/ADT/Bitset.h index ecb6b149f0494..d9f750ff55185 100644 --- a/llvm/include/llvm/ADT/Bitset.h +++ b/llvm/include/llvm/ADT/Bitset.h @@ -28,9 +28,9 @@ namespace llvm { /// initialization. template class Bitset { - typedef uintptr_t BitWord; + using BitWord = uintptr_t; - enum { BITWORD_SIZE = (unsigned)sizeof(BitWord) * CHAR_BIT }; + static constexpr unsigned BITWORD_SIZE = sizeof(BitWord) * CHAR_BIT; static_assert(BITWORD_SIZE == 64 || BITWORD_SIZE == 32, "Unsupported word size"); From ac429a0cda148838ffff9dcb3f6da496919442bc Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Wed, 8 Oct 2025 06:49:08 -0700 Subject: [PATCH 2/2] Address a comment. --- llvm/include/llvm/ADT/Bitset.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/llvm/include/llvm/ADT/Bitset.h b/llvm/include/llvm/ADT/Bitset.h index d9f750ff55185..b1e539e39aff7 100644 --- a/llvm/include/llvm/ADT/Bitset.h +++ b/llvm/include/llvm/ADT/Bitset.h @@ -30,13 +30,13 @@ template class Bitset { using BitWord = uintptr_t; - static constexpr unsigned BITWORD_SIZE = sizeof(BitWord) * CHAR_BIT; + static constexpr unsigned BitwordBits = sizeof(BitWord) * CHAR_BIT; - static_assert(BITWORD_SIZE == 64 || BITWORD_SIZE == 32, + static_assert(BitwordBits == 64 || BitwordBits == 32, "Unsupported word size"); static constexpr unsigned NumWords = - (NumBits + BITWORD_SIZE - 1) / BITWORD_SIZE; + (NumBits + BitwordBits - 1) / BitwordBits; protected: using StorageType = std::array; @@ -60,23 +60,23 @@ class Bitset { } constexpr Bitset &set(unsigned I) { - Bits[I / BITWORD_SIZE] |= BitWord(1) << (I % BITWORD_SIZE); + Bits[I / BitwordBits] |= BitWord(1) << (I % BitwordBits); return *this; } constexpr Bitset &reset(unsigned I) { - Bits[I / BITWORD_SIZE] &= ~(BitWord(1) << (I % BITWORD_SIZE)); + Bits[I / BitwordBits] &= ~(BitWord(1) << (I % BitwordBits)); return *this; } constexpr Bitset &flip(unsigned I) { - Bits[I / BITWORD_SIZE] ^= BitWord(1) << (I % BITWORD_SIZE); + Bits[I / BitwordBits] ^= BitWord(1) << (I % BitwordBits); return *this; } constexpr bool operator[](unsigned I) const { - BitWord Mask = BitWord(1) << (I % BITWORD_SIZE); - return (Bits[I / BITWORD_SIZE] & Mask) != 0; + BitWord Mask = BitWord(1) << (I % BitwordBits); + return (Bits[I / BitwordBits] & Mask) != 0; } constexpr bool test(unsigned I) const { return (*this)[I]; }