16#ifndef LLVM_ADT_BITSET_H
17#define LLVM_ADT_BITSET_H
29template <
unsigned NumBits>
31 typedef uintptr_t BitWord;
33 enum { BITWORD_SIZE = (
unsigned)
sizeof(BitWord) * CHAR_BIT };
35 static_assert(BITWORD_SIZE == 64 || BITWORD_SIZE == 32,
36 "Unsupported word size");
38 static constexpr unsigned NumWords = (NumBits + BITWORD_SIZE-1) / BITWORD_SIZE;
39 std::array<BitWord, NumWords> Bits{};
42 constexpr Bitset(
const std::array<BitWord, NumWords> &
B)
53 std::fill(std::begin(Bits), std::end(Bits), -BitWord(0));
58 Bits[
I / BITWORD_SIZE] |= BitWord(1) << (
I % BITWORD_SIZE);
63 Bits[
I / BITWORD_SIZE] &= ~(BitWord(1) << (
I % BITWORD_SIZE));
68 Bits[
I / BITWORD_SIZE] ^= BitWord(1) << (
I % BITWORD_SIZE);
73 BitWord Mask = BitWord(1) << (
I % BITWORD_SIZE);
74 return (Bits[
I / BITWORD_SIZE] & Mask) != 0;
77 constexpr bool test(
unsigned I)
const {
return (*
this)[
I]; }
79 constexpr size_t size()
const {
return NumBits; }
93 for (
unsigned I = 0,
E = Bits.size();
I !=
E; ++
I) {
94 Bits[
I] ^=
RHS.Bits[
I];
105 for (
unsigned I = 0,
E = Bits.size();
I !=
E; ++
I)
106 Bits[
I] &=
RHS.Bits[
I];
116 for (
unsigned I = 0,
E = Bits.size();
I !=
E; ++
I) {
117 Bits[
I] |=
RHS.Bits[
I];
129 for (
auto &
B : Result.Bits)
135 return std::equal(std::begin(Bits), std::end(Bits), std::begin(
RHS.Bits));
141 for (
unsigned I = 0,
E =
size();
I !=
E; ++
I) {
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is a constexpr reimplementation of a subset of std::bitset.
constexpr Bitset operator^(const Bitset &RHS) const
constexpr Bitset & set(unsigned I)
constexpr Bitset & flip(unsigned I)
bool operator<(const Bitset &Other) const
bool operator!=(const Bitset &RHS) const
constexpr Bitset()=default
constexpr Bitset & operator^=(const Bitset &RHS)
constexpr Bitset operator&(const Bitset &RHS) const
constexpr bool operator[](unsigned I) const
constexpr size_t size() const
constexpr Bitset & operator|=(const Bitset &RHS)
bool operator==(const Bitset &RHS) const
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(const std::array< BitWord, NumWords > &B)
constexpr Bitset & reset(unsigned I)
constexpr Bitset operator~() const
This is an optimization pass for GlobalISel generic memory operations.
int popcount(T Value) noexcept
Count the number of set bits in a value.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.