16#ifndef LLVM_ADT_BITSET_H
17#define LLVM_ADT_BITSET_H
29template <
unsigned NumBits>
class Bitset {
30 using BitWord = uintptr_t;
32 static constexpr unsigned BitwordBits =
sizeof(BitWord) * CHAR_BIT;
33 static constexpr unsigned RemainderNumBits = NumBits % BitwordBits;
34 static constexpr BitWord RemainderMask =
35 RemainderNumBits == 0 ? ~BitWord(0)
36 : ((BitWord(1) << RemainderNumBits) - 1);
38 static_assert(BitwordBits == 64 || BitwordBits == 32,
39 "Unsupported word size");
41 static constexpr unsigned NumWords =
42 (NumBits + BitwordBits - 1) / BitwordBits;
47 static constexpr unsigned getLastWordIndex() {
return NumWords - 1; }
49 using StorageType = std::array<BitWord, NumWords>;
52 constexpr void maskLastWord() { Bits[getLastWordIndex()] &= RemainderMask; }
56 if constexpr (
sizeof(BitWord) ==
sizeof(
uint64_t)) {
57 for (
size_t I = 0;
I !=
B.size(); ++
I)
60 unsigned BitsToAssign = NumBits;
61 for (
size_t I = 0;
I !=
B.size() && BitsToAssign; ++
I) {
67 BitsToAssign = BitsToAssign >= 32 ? BitsToAssign - 32 : 0;
82 constexpr const BitWord
AllOnes = ~BitWord(0);
83 for (BitWord &
B : Bits)
90 Bits[
I / BitwordBits] |= BitWord(1) << (
I % BitwordBits);
95 Bits[
I / BitwordBits] &= ~(BitWord(1) << (
I % BitwordBits));
100 Bits[
I / BitwordBits] ^= BitWord(1) << (
I % BitwordBits);
105 BitWord Mask = BitWord(1) << (
I % BitwordBits);
106 return (Bits[
I / BitwordBits] & Mask) != 0;
109 constexpr bool test(
unsigned I)
const {
return (*
this)[
I]; }
111 constexpr size_t size()
const {
return NumBits; }
113 constexpr bool any()
const {
114 for (BitWord
B : Bits)
120 constexpr bool none()
const {
return !
any(); }
122 constexpr bool all()
const {
123 constexpr const BitWord
AllOnes = ~BitWord(0);
124 for (
unsigned I = 0;
I < getLastWordIndex(); ++
I)
127 return Bits[getLastWordIndex()] == RemainderMask;
132 for (BitWord Word : Bits)
138 for (
unsigned I = 0,
E = Bits.size();
I !=
E; ++
I) {
139 Bits[
I] ^=
RHS.Bits[
I];
150 for (
unsigned I = 0,
E = Bits.size();
I !=
E; ++
I)
151 Bits[
I] &=
RHS.Bits[
I];
161 for (
unsigned I = 0,
E = Bits.size();
I !=
E; ++
I) {
162 Bits[
I] |=
RHS.Bits[
I];
174 for (BitWord &
B : Result.Bits)
176 Result.maskLastWord();
181 for (
unsigned I = 0;
I < NumWords; ++
I)
182 if (Bits[
I] !=
RHS.Bits[
I])
190 for (
unsigned I = 0,
E =
size();
I !=
E; ++
I) {
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file implements the C++20 <bit> header.
constexpr Bitset operator^(const Bitset &RHS) const
constexpr size_t count() const
constexpr Bitset & set(unsigned I)
constexpr Bitset & flip(unsigned I)
constexpr bool all() const
constexpr bool any() const
constexpr Bitset(const std::array< uint64_t,(NumBits+63)/64 > &B)
constexpr Bitset()=default
constexpr bool operator==(const Bitset &RHS) const
constexpr bool operator<(const Bitset &Other) const
constexpr Bitset & operator^=(const Bitset &RHS)
constexpr Bitset operator&(const Bitset &RHS) const
constexpr bool none() const
constexpr bool operator!=(const Bitset &RHS) const
constexpr bool operator[](unsigned I) const
constexpr size_t size() const
constexpr Bitset & operator|=(const Bitset &RHS)
constexpr Bitset(std::initializer_list< unsigned > Init)
constexpr Bitset & operator&=(const Bitset &RHS)
constexpr bool test(unsigned I) const
constexpr Bitset operator|(const Bitset &RHS) const
constexpr Bitset & reset(unsigned I)
constexpr Bitset operator~() const
This is an optimization pass for GlobalISel generic memory operations.
constexpr int popcount(T Value) noexcept
Count the number of set bits in a value.
FunctionAddr VTableAddr Count