[llvm] b7921f8 - [ADT] Modernize Bitset (NFC) (#162430)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 8 08:13:01 PDT 2025


Author: Kazu Hirata
Date: 2025-10-08T08:12:57-07:00
New Revision: b7921f8292a9d7d18c472043ac3f0c2b5e20fd5f

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

LOG: [ADT] Modernize Bitset (NFC) (#162430)

This patch modernizes BitWord and BITWORD_SIZE with "using" and
"static constexpr", respectively.

Added: 
    

Modified: 
    llvm/include/llvm/ADT/Bitset.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/Bitset.h b/llvm/include/llvm/ADT/Bitset.h
index ecb6b149f0494..b1e539e39aff7 100644
--- a/llvm/include/llvm/ADT/Bitset.h
+++ b/llvm/include/llvm/ADT/Bitset.h
@@ -28,15 +28,15 @@ namespace llvm {
 /// initialization.
 template <unsigned NumBits>
 class Bitset {
-  typedef uintptr_t BitWord;
+  using BitWord = uintptr_t;
 
-  enum { BITWORD_SIZE = (unsigned)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<BitWord, NumWords>;
@@ -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]; }


        


More information about the llvm-commits mailing list