[llvm] ADT: Expose typedef for Bitset's storage type (PR #151986)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 4 08:22:41 PDT 2025


https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/151986

Allows subclasses to directly initialize the underlying storage.
This will enable tablegen to emit a smaller initializer list to
initialize constant bitsets. For runtime libcalls we need to
initialize many hundreds of bits in many different sets so this
shrinks the generated output to a more manageable size.

Extracted from #151948

>From 56e54930fd16b546c580d9992056a52c8c59e335 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Tue, 5 Aug 2025 00:10:58 +0900
Subject: [PATCH] ADT: Expose typedef for Bitset's storage type

Allows subclasses to directly initialize the underlying storage.
This will enable tablegen to emit a smaller initializer list to
initialize constant bitsets. For runtime libcalls we need to
initialize many hundreds of bits in many different sets so this
shrinks the generated output to a more manageable size.

Extracted from #151948
---
 llvm/include/llvm/ADT/Bitset.h | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/llvm/include/llvm/ADT/Bitset.h b/llvm/include/llvm/ADT/Bitset.h
index 55b96e47f2ed6..ecb6b149f0494 100644
--- a/llvm/include/llvm/ADT/Bitset.h
+++ b/llvm/include/llvm/ADT/Bitset.h
@@ -35,12 +35,17 @@ class Bitset {
   static_assert(BITWORD_SIZE == 64 || BITWORD_SIZE == 32,
                 "Unsupported word size");
 
-  static constexpr unsigned NumWords = (NumBits + BITWORD_SIZE-1) / BITWORD_SIZE;
-  std::array<BitWord, NumWords> Bits{};
+  static constexpr unsigned NumWords =
+      (NumBits + BITWORD_SIZE - 1) / BITWORD_SIZE;
 
 protected:
-  constexpr Bitset(const std::array<BitWord, NumWords> &B)
-      : Bits{B} {}
+  using StorageType = std::array<BitWord, NumWords>;
+
+private:
+  StorageType Bits{};
+
+protected:
+  constexpr Bitset(const StorageType &B) : Bits{B} {}
 
 public:
   constexpr Bitset() = default;



More information about the llvm-commits mailing list