1//===- llvm/ADT/BitVector.h - Bit vectors -----------------------*- C++ -*-===//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//===----------------------------------------------------------------------===//
10/// This file implements the BitVector class.
12//===----------------------------------------------------------------------===//
14#ifndef LLVM_ADT_BITVECTOR_H
15#define LLVM_ADT_BITVECTOR_H
32/// ForwardIterator for the bits that are set.
33/// Iterators get invalidated when resize / reserve is called.
35 const BitVectorT &Parent;
39 assert(Current != -1 &&
"Trying to advance past end.");
40 Current = Parent.find_next(Current);
45 Current = Parent.find_last();
47 Current = Parent.find_prev(Current);
59 : Parent(Parent), Current(Current) {}
90 "Comparing iterators from different BitVectors");
91 return Current ==
Other.Current;
96 "Comparing iterators from different BitVectors");
97 return Current !=
Other.Current;
102 using BitWord = uintptr_t;
104 enum { BITWORD_SIZE = (
unsigned)
sizeof(BitWord) * CHAR_BIT };
106 static_assert(BITWORD_SIZE == 64 || BITWORD_SIZE == 32,
107 "Unsupported word size");
111 Storage Bits;
// Actual bits.
112 unsigned Size = 0;
// Size of bitvector in bits.
117 // Encapsulation of a single bit.
125 WordRef = &b.Bits[Idx / BITWORD_SIZE];
126 BitPos = Idx % BITWORD_SIZE;
139 *WordRef |= BitWord(1) << BitPos;
141 *WordRef &= ~(BitWord(1) << BitPos);
146 return ((*WordRef) & (BitWord(1) << BitPos)) != 0;
163 /// BitVector default ctor - Creates an empty bitvector.
166 /// BitVector ctor - Creates a bitvector of specified number of bits. All
167 /// bits are initialized to the specified value.
169 : Bits(NumBitWords(s), 0 - (BitWord)t), Size(s) {
174 /// empty - Tests whether there are no bits in this bitvector.
175 bool empty()
const {
return Size == 0; }
177 /// size - Returns the number of bits in this bitvector.
180 /// count - Returns the number of bits which are set.
182 unsigned NumBits = 0;
183 for (
auto Bit : Bits)
188 /// any - Returns true if any bit is set.
190 return any_of(Bits, [](BitWord Bit) {
return Bit != 0; });
193 /// all - Returns true if all bits are set.
195 for (
unsigned i = 0; i < Size / BITWORD_SIZE; ++i)
196 if (Bits[i] != ~BitWord(0))
199 // If bits remain check that they are ones. The unused bits are always zero.
200 if (
unsigned Remainder = Size % BITWORD_SIZE)
201 return Bits[Size / BITWORD_SIZE] == (BitWord(1) << Remainder) - 1;
206 /// none - Returns true if none of the bits are set.
211 /// find_first_in - Returns the index of the first set / unset bit,
212 /// depending on \p Set, in the range [Begin, End).
213 /// Returns -1 if all bits in the range are unset / set.
215 assert(Begin <= End && End <= Size);
219 unsigned FirstWord = Begin / BITWORD_SIZE;
220 unsigned LastWord = (End - 1) / BITWORD_SIZE;
222 // Check subsequent words.
223 // The code below is based on search for the first _set_ bit. If
224 // we're searching for the first _unset_, we just take the
225 // complement of each word before we use it and apply
227 for (
unsigned i = FirstWord; i <= LastWord; ++i) {
228 BitWord Copy = Bits[i];
232 if (i == FirstWord) {
233 unsigned FirstBit = Begin % BITWORD_SIZE;
238 unsigned LastBit = (End - 1) % BITWORD_SIZE;
247 /// find_last_in - Returns the index of the last set bit in the range
248 /// [Begin, End). Returns -1 if all bits in the range are unset.
250 assert(Begin <= End && End <= Size);
254 unsigned LastWord = (End - 1) / BITWORD_SIZE;
255 unsigned FirstWord = Begin / BITWORD_SIZE;
257 for (
unsigned i = LastWord + 1; i >= FirstWord + 1; --i) {
258 unsigned CurrentWord = i - 1;
260 BitWord Copy = Bits[CurrentWord];
261 if (CurrentWord == LastWord) {
262 unsigned LastBit = (End - 1) % BITWORD_SIZE;
266 if (CurrentWord == FirstWord) {
267 unsigned FirstBit = Begin % BITWORD_SIZE;
278 /// find_first_unset_in - Returns the index of the first unset bit in the
279 /// range [Begin, End). Returns -1 if all bits in the range are set.
284 /// find_last_unset_in - Returns the index of the last unset bit in the
285 /// range [Begin, End). Returns -1 if all bits in the range are set.
287 assert(Begin <= End && End <= Size);
291 unsigned LastWord = (End - 1) / BITWORD_SIZE;
292 unsigned FirstWord = Begin / BITWORD_SIZE;
294 for (
unsigned i = LastWord + 1; i >= FirstWord + 1; --i) {
295 unsigned CurrentWord = i - 1;
297 BitWord Copy = Bits[CurrentWord];
298 if (CurrentWord == LastWord) {
299 unsigned LastBit = (End - 1) % BITWORD_SIZE;
303 if (CurrentWord == FirstWord) {
304 unsigned FirstBit = Begin % BITWORD_SIZE;
308 if (Copy != ~BitWord(0)) {
311 return Result < Size ? Result : -1;
317 /// find_first - Returns the index of the first set bit, -1 if none
318 /// of the bits are set.
321 /// find_last - Returns the index of the last set bit, -1 if none of the bits
325 /// find_next - Returns the index of the next set bit following the
326 /// "Prev" bit. Returns -1 if the next set bit is not found.
329 /// find_prev - Returns the index of the first set bit that precedes the
330 /// the bit at \p PriorTo. Returns -1 if all previous bits are unset.
333 /// find_first_unset - Returns the index of the first unset bit, -1 if all
334 /// of the bits are set.
337 /// find_next_unset - Returns the index of the next unset bit following the
338 /// "Prev" bit. Returns -1 if all remaining bits are set.
343 /// find_last_unset - Returns the index of the last unset bit, -1 if all of
344 /// the bits are set.
347 /// find_prev_unset - Returns the index of the first unset bit that precedes
348 /// the bit at \p PriorTo. Returns -1 if all previous bits are set.
353 /// clear - Removes all bits from the bitvector.
359 /// resize - Grow or shrink the bitvector.
363 Bits.resize(NumBitWords(
N), 0 - BitWord(t));
367 void reserve(
unsigned N) { Bits.reserve(NumBitWords(
N)); }
377 assert(Idx < Size &&
"access in bound");
378 Bits[Idx / BITWORD_SIZE] |= BitWord(1) << (Idx % BITWORD_SIZE);
382 /// set - Efficiently set a range of bits in [I, E)
384 assert(
I <=
E &&
"Attempted to set backwards range!");
385 assert(
E <=
size() &&
"Attempted to set out-of-bounds range!");
387 if (
I ==
E)
return *
this;
389 if (
I / BITWORD_SIZE ==
E / BITWORD_SIZE) {
390 BitWord EMask = BitWord(1) << (
E % BITWORD_SIZE);
391 BitWord IMask = BitWord(1) << (
I % BITWORD_SIZE);
392 BitWord Mask = EMask - IMask;
393 Bits[
I / BITWORD_SIZE] |= Mask;
397 BitWord PrefixMask = ~BitWord(0) << (
I % BITWORD_SIZE);
398 Bits[
I / BITWORD_SIZE] |= PrefixMask;
401 for (;
I + BITWORD_SIZE <=
E;
I += BITWORD_SIZE)
402 Bits[
I / BITWORD_SIZE] = ~BitWord(0);
404 BitWord PostfixMask = (BitWord(1) << (
E % BITWORD_SIZE)) - 1;
406 Bits[
I / BITWORD_SIZE] |= PostfixMask;
417 Bits[Idx / BITWORD_SIZE] &= ~(BitWord(1) << (Idx % BITWORD_SIZE));
421 /// reset - Efficiently reset a range of bits in [I, E)
423 assert(
I <=
E &&
"Attempted to reset backwards range!");
424 assert(
E <=
size() &&
"Attempted to reset out-of-bounds range!");
426 if (
I ==
E)
return *
this;
428 if (
I / BITWORD_SIZE ==
E / BITWORD_SIZE) {
429 BitWord EMask = BitWord(1) << (
E % BITWORD_SIZE);
430 BitWord IMask = BitWord(1) << (
I % BITWORD_SIZE);
431 BitWord Mask = EMask - IMask;
432 Bits[
I / BITWORD_SIZE] &= ~Mask;
436 BitWord PrefixMask = ~BitWord(0) << (
I % BITWORD_SIZE);
437 Bits[
I / BITWORD_SIZE] &= ~PrefixMask;
440 for (;
I + BITWORD_SIZE <=
E;
I += BITWORD_SIZE)
441 Bits[
I / BITWORD_SIZE] = BitWord(0);
443 BitWord PostfixMask = (BitWord(1) << (
E % BITWORD_SIZE)) - 1;
445 Bits[
I / BITWORD_SIZE] &= ~PostfixMask;
451 for (
auto &Bit : Bits)
458 Bits[Idx / BITWORD_SIZE] ^= BitWord(1) << (Idx % BITWORD_SIZE);
464 assert (Idx < Size &&
"Out-of-bounds Bit access.");
469 assert (Idx < Size &&
"Out-of-bounds Bit access.");
470 BitWord Mask = BitWord(1) << (Idx % BITWORD_SIZE);
471 return (Bits[Idx / BITWORD_SIZE] & Mask) != 0;
474 /// Return the last element in the vector.
476 assert(!
empty() &&
"Getting last element of empty vector.");
477 return (*
this)[
size() - 1];
480 bool test(
unsigned Idx)
const {
484 // Push single bit to end of vector.
486 unsigned OldSize = Size;
487 unsigned NewSize = Size + 1;
489 // Resize, which will insert zeros.
490 // If we already fit then the unused bits will be already zero.
496 // If true, set single bit.
501 /// Pop one bit from the end of the vector.
503 assert(!
empty() &&
"Empty vector has no element to pop.");
507 /// Test if any common bits are set.
509 unsigned ThisWords = Bits.size();
510 unsigned RHSWords =
RHS.Bits.size();
511 for (
unsigned i = 0, e = std::min(ThisWords, RHSWords); i != e; ++i)
512 if (Bits[i] &
RHS.Bits[i])
517 // Comparison operators.
521 unsigned NumWords = Bits.size();
522 return std::equal(Bits.begin(), Bits.begin() + NumWords,
RHS.Bits.begin());
527 /// Intersection, union, disjoint union.
529 unsigned ThisWords = Bits.
size();
530 unsigned RHSWords =
RHS.Bits.size();
532 for (i = 0; i != std::min(ThisWords, RHSWords); ++i)
533 Bits[i] &=
RHS.Bits[i];
535 // Any bits that are just in this bitvector become zero, because they aren't
536 // in the RHS bit vector. Any words only in RHS are ignored because they
537 // are already zero in the LHS.
538 for (; i != ThisWords; ++i)
544 /// reset - Reset bits that are set in RHS. Same as *this &= ~RHS.
546 unsigned ThisWords = Bits.
size();
547 unsigned RHSWords =
RHS.Bits.size();
548 for (
unsigned i = 0; i != std::min(ThisWords, RHSWords); ++i)
549 Bits[i] &= ~
RHS.Bits[i];
553 /// test - Check if (This - RHS) is zero.
554 /// This is the same as reset(RHS) and any().
556 unsigned ThisWords = Bits.size();
557 unsigned RHSWords =
RHS.Bits.size();
559 for (i = 0; i != std::min(ThisWords, RHSWords); ++i)
560 if ((Bits[i] & ~
RHS.Bits[i]) != 0)
563 for (; i != ThisWords ; ++i)
570 template <
class F,
class... ArgTys>
572 ArgTys
const &...Args) {
573 assert(((Arg.
size() == Args.size()) && ...) &&
"consistent sizes");
576 Out.Bits[
I] = f(Arg.Bits[
I], Args.Bits[
I]...);
577 Out.clear_unused_bits();
585 Bits[
I] |=
RHS.Bits[
I];
593 Bits[
I] ^=
RHS.Bits[
I];
602 unsigned NumWords = Bits.size();
605 wordShr(
N / BITWORD_SIZE);
607 unsigned BitDistance =
N % BITWORD_SIZE;
608 if (BitDistance == 0)
611 // When the shift size is not a multiple of the word size, then we have
612 // a tricky situation where each word in succession needs to extract some
613 // of the bits from the next word and or them into this word while
614 // shifting this word to make room for the new bits. This has to be done
615 // for every word in the array.
617 // Since we're shifting each word right, some bits will fall off the end
618 // of each word to the right, and empty space will be created on the left.
619 // The final word in the array will lose bits permanently, so starting at
620 // the beginning, work forwards shifting each word to the right, and
621 // OR'ing in the bits from the end of the next word to the beginning of
625 // Starting with {0xAABBCCDD, 0xEEFF0011, 0x22334455} and shifting right
627 // Step 1: Word[0] >>= 4 ; 0x0ABBCCDD
628 // Step 2: Word[0] |= 0x10000000 ; 0x1ABBCCDD
629 // Step 3: Word[1] >>= 4 ; 0x0EEFF001
630 // Step 4: Word[1] |= 0x50000000 ; 0x5EEFF001
631 // Step 5: Word[2] >>= 4 ; 0x02334455
632 // Result: { 0x1ABBCCDD, 0x5EEFF001, 0x02334455 }
634 const unsigned LSH = BITWORD_SIZE - BitDistance;
636 for (
unsigned I = 0;
I < NumWords - 1; ++
I) {
637 Bits[
I] >>= BitDistance;
638 Bits[
I] |= (Bits[
I + 1] & Mask) << LSH;
641 Bits[NumWords - 1] >>= BitDistance;
651 unsigned NumWords = Bits.size();
654 wordShl(
N / BITWORD_SIZE);
656 unsigned BitDistance =
N % BITWORD_SIZE;
657 if (BitDistance == 0)
660 // When the shift size is not a multiple of the word size, then we have
661 // a tricky situation where each word in succession needs to extract some
662 // of the bits from the previous word and or them into this word while
663 // shifting this word to make room for the new bits. This has to be done
664 // for every word in the array. This is similar to the algorithm outlined
665 // in operator>>=, but backwards.
667 // Since we're shifting each word left, some bits will fall off the end
668 // of each word to the left, and empty space will be created on the right.
669 // The first word in the array will lose bits permanently, so starting at
670 // the end, work backwards shifting each word to the left, and OR'ing
671 // in the bits from the end of the next word to the beginning of the
675 // Starting with {0xAABBCCDD, 0xEEFF0011, 0x22334455} and shifting left
677 // Step 1: Word[2] <<= 4 ; 0x23344550
678 // Step 2: Word[2] |= 0x0000000E ; 0x2334455E
679 // Step 3: Word[1] <<= 4 ; 0xEFF00110
680 // Step 4: Word[1] |= 0x0000000A ; 0xEFF0011A
681 // Step 5: Word[0] <<= 4 ; 0xABBCCDD0
682 // Result: { 0xABBCCDD0, 0xEFF0011A, 0x2334455E }
684 const unsigned RSH = BITWORD_SIZE - BitDistance;
686 for (
int I = NumWords - 1;
I > 0; --
I) {
687 Bits[
I] <<= BitDistance;
688 Bits[
I] |= (Bits[
I - 1] & Mask) >> RSH;
690 Bits[0] <<= BitDistance;
702 assert(!Size && Bits.empty());
709 //===--------------------------------------------------------------------===//
710 // Portable bit mask operations.
711 //===--------------------------------------------------------------------===//
713 // These methods all operate on arrays of uint32_t, each holding 32 bits. The
714 // fixed word size makes it easier to work with literal bit vector constants
717 // The LSB in each word is the lowest numbered bit. The size of a portable
718 // bit mask is always a whole multiple of 32 bits. If no bit mask size is
719 // given, the bit mask is assumed to cover the entire BitVector.
721 /// setBitsInMask - Add '1' bits from Mask to this vector. Don't resize.
722 /// This computes "*this |= Mask".
724 applyMask<true, false>(Mask, MaskWords);
727 /// clearBitsInMask - Clear any bits in this vector that are set in Mask.
728 /// Don't resize. This computes "*this &= ~Mask".
730 applyMask<false, false>(Mask, MaskWords);
733 /// setBitsNotInMask - Add a bit to this vector for every '0' bit in Mask.
734 /// Don't resize. This computes "*this |= ~Mask".
736 applyMask<true, true>(Mask, MaskWords);
739 /// clearBitsNotInMask - Clear a bit in this vector for every '0' bit in Mask.
740 /// Don't resize. This computes "*this &= Mask".
742 applyMask<false, true>(Mask, MaskWords);
746 /// Perform a logical left shift of \p Count words by moving everything
747 /// \p Count words to the right in memory.
749 /// While confusing, words are stored from least significant at Bits[0] to
750 /// most significant at Bits[NumWords-1]. A logical shift left, however,
751 /// moves the current least significant bit to a higher logical index, and
752 /// fills the previous least significant bits with 0. Thus, we actually
753 /// need to move the bytes of the memory to the right, not to the left.
755 /// Words = [0xBBBBAAAA, 0xDDDDFFFF, 0x00000000, 0xDDDD0000]
756 /// represents a BitVector where 0xBBBBAAAA contain the least significant
757 /// bits. So if we want to shift the BitVector left by 2 words, we need
758 /// to turn this into 0x00000000 0x00000000 0xBBBBAAAA 0xDDDDFFFF by using a
759 /// memmove which moves right, not left.
766 // Since we always move Word-sized chunks of data with src and dest both
767 // aligned to a word-boundary, we don't need to worry about endianness
769 std::copy(Bits.begin(), Bits.begin() + NumWords -
Count,
770 Bits.begin() +
Count);
771 std::fill(Bits.begin(), Bits.begin() +
Count, 0);
775 /// Perform a logical right shift of \p Count words by moving those
776 /// words to the left in memory. See wordShl for more information.
784 std::copy(Bits.begin() +
Count, Bits.begin() + NumWords, Bits.begin());
785 std::fill(Bits.begin() + NumWords -
Count, Bits.begin() + NumWords, 0);
788 unsigned NumBitWords(
unsigned S)
const {
789 return (S + BITWORD_SIZE-1) / BITWORD_SIZE;
792 // Set the unused bits in the high words.
793 void set_unused_bits(
bool t =
true) {
794 // Then set any stray high bits of the last used word.
795 if (
unsigned ExtraBits = Size % BITWORD_SIZE) {
796 BitWord ExtraBitMask = ~BitWord(0) << ExtraBits;
798 Bits.back() |= ExtraBitMask;
800 Bits.back() &= ~ExtraBitMask;
804 // Clear the unused bits in the high words.
805 void clear_unused_bits() {
806 set_unused_bits(
false);
809 void init_words(
bool t) {
llvm::fill(Bits, 0 - (BitWord)t); }
811 template<
bool AddBits,
bool InvertMask>
812 void applyMask(
const uint32_t *Mask,
unsigned MaskWords) {
813 static_assert(BITWORD_SIZE % 32 == 0,
"Unsupported BitWord size.");
814 MaskWords = std::min(MaskWords, (
size() + 31) / 32);
815 const unsigned Scale = BITWORD_SIZE / 32;
817 for (i = 0; MaskWords >= Scale; ++i, MaskWords -= Scale) {
818 BitWord BW = Bits[i];
819 // This inner loop should unroll completely when BITWORD_SIZE > 32.
820 for (
unsigned b = 0;
b != BITWORD_SIZE;
b += 32) {
821 uint32_t
M = *
Mask++;
822 if (InvertMask)
M = ~M;
823 if (AddBits) BW |= BitWord(M) <<
b;
824 else BW &= ~(BitWord(M) <<
b);
828 for (
unsigned b = 0; MaskWords;
b += 32, --MaskWords) {
829 uint32_t
M = *
Mask++;
830 if (InvertMask)
M = ~M;
831 if (AddBits) Bits[i] |= BitWord(M) <<
b;
832 else Bits[i] &= ~(BitWord(M) <<
b);
839 /// Return the size (in bytes) of the bit vector.
845 return X.getMemorySize();
857 getHashValue(std::make_pair(V.size(), V.getData()));
860 if (
LHS.isInvalid() ||
RHS.isInvalid())
861 return LHS.isInvalid() ==
RHS.isInvalid();
865}
// end namespace llvm
868 /// Implement std::swap in terms of BitVector swap.
870}
// end namespace std
872#endif // LLVM_ADT_BITVECTOR_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_UNLIKELY(EXPR)
This file defines DenseMapInfo traits for DenseMap.
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
reference & operator=(bool t)
reference(BitVector &b, unsigned Idx)
reference & operator=(reference t)
reference(const reference &)=default
BitVector & operator>>=(unsigned N)
bool test(unsigned Idx) const
void swap(BitVector &RHS)
int find_first() const
find_first - Returns the index of the first set bit, -1 if none of the bits are set.
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
bool anyCommon(const BitVector &RHS) const
Test if any common bits are set.
void clear()
clear - Removes all bits from the bitvector.
bool test(const BitVector &RHS) const
test - Check if (This - RHS) is zero.
BitVector()=default
BitVector default ctor - Creates an empty bitvector.
bool back() const
Return the last element in the vector.
bool operator!=(const BitVector &RHS) const
void clearBitsNotInMask(const uint32_t *Mask, unsigned MaskWords=~0u)
clearBitsNotInMask - Clear a bit in this vector for every '0' bit in Mask.
int find_last() const
find_last - Returns the index of the last set bit, -1 if none of the bits are set.
int find_first_unset_in(unsigned Begin, unsigned End) const
find_first_unset_in - Returns the index of the first unset bit in the range [Begin,...
size_type count() const
count - Returns the number of bits which are set.
BitVector & operator<<=(unsigned N)
ArrayRef< BitWord > getData() const
const_set_bits_iterator set_bits_end() const
BitVector & reset(unsigned Idx)
int find_last_unset() const
find_last_unset - Returns the index of the last unset bit, -1 if all of the bits are set.
void setBitsInMask(const uint32_t *Mask, unsigned MaskWords=~0u)
setBitsInMask - Add '1' bits from Mask to this vector.
const_set_bits_iterator set_iterator
bool any() const
any - Returns true if any bit is set.
bool all() const
all - Returns true if all bits are set.
BitVector(unsigned s, bool t=false)
BitVector ctor - Creates a bitvector of specified number of bits.
BitVector & reset(const BitVector &RHS)
reset - Reset bits that are set in RHS. Same as *this &= ~RHS.
BitVector & operator|=(const BitVector &RHS)
void pop_back()
Pop one bit from the end of the vector.
void clearBitsInMask(const uint32_t *Mask, unsigned MaskWords=~0u)
clearBitsInMask - Clear any bits in this vector that are set in Mask.
int find_prev(unsigned PriorTo) const
find_prev - Returns the index of the first set bit that precedes the the bit at PriorTo.
const_set_bits_iterator_impl< BitVector > const_set_bits_iterator
int find_last_in(unsigned Begin, unsigned End) const
find_last_in - Returns the index of the last set bit in the range [Begin, End).
void setBitsNotInMask(const uint32_t *Mask, unsigned MaskWords=~0u)
setBitsNotInMask - Add a bit to this vector for every '0' bit in Mask.
BitVector & reset(unsigned I, unsigned E)
reset - Efficiently reset a range of bits in [I, E)
bool operator==(const BitVector &RHS) const
int find_next(unsigned Prev) const
find_next - Returns the index of the next set bit following the "Prev" bit.
bool none() const
none - Returns true if none of the bits are set.
const_set_bits_iterator set_bits_begin() const
iterator_range< const_set_bits_iterator > set_bits() const
BitVector & set(unsigned I, unsigned E)
set - Efficiently set a range of bits in [I, E)
size_type getBitCapacity() const
int find_first_in(unsigned Begin, unsigned End, bool Set=true) const
find_first_in - Returns the index of the first set / unset bit, depending on Set, in the range [Begin...
size_type size() const
size - Returns the number of bits in this bitvector.
BitVector & operator^=(const BitVector &RHS)
BitVector & flip(unsigned Idx)
size_type getMemorySize() const
Return the size (in bytes) of the bit vector.
static BitVector & apply(F &&f, BitVector &Out, BitVector const &Arg, ArgTys const &...Args)
bool empty() const
empty - Tests whether there are no bits in this bitvector.
int find_next_unset(unsigned Prev) const
find_next_unset - Returns the index of the next unset bit following the "Prev" bit.
BitVector & set(unsigned Idx)
int find_prev_unset(unsigned PriorTo) const
find_prev_unset - Returns the index of the first unset bit that precedes the bit at PriorTo.
BitVector & operator&=(const BitVector &RHS)
Intersection, union, disjoint union.
int find_first_unset() const
find_first_unset - Returns the index of the first unset bit, -1 if all of the bits are set.
int find_last_unset_in(unsigned Begin, unsigned End) const
find_last_unset_in - Returns the index of the last unset bit in the range [Begin, End).
bool operator[](unsigned Idx) const
reference operator[](unsigned Idx)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
ForwardIterator for the bits that are set.
const_set_bits_iterator_impl operator--(int)
const_set_bits_iterator_impl(const BitVectorT &Parent)
std::bidirectional_iterator_tag iterator_category
bool operator==(const const_set_bits_iterator_impl &Other) const
const_set_bits_iterator_impl(const const_set_bits_iterator_impl &)=default
const_set_bits_iterator_impl & operator++()
const_set_bits_iterator_impl & operator--()
const_set_bits_iterator_impl operator++(int)
std::ptrdiff_t difference_type
const_set_bits_iterator_impl(const BitVectorT &Parent, int Current)
bool operator!=(const const_set_bits_iterator_impl &Other) const
const value_type * pointer
unsigned operator*() const
A range adaptor for a pair of iterators.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
This is an optimization pass for GlobalISel generic memory operations.
void fill(R &&Range, T &&Value)
Provide wrappers to std::fill which take ranges instead of having to pass begin/end explicitly.
BitVector::size_type capacity_in_bytes(const BitVector &X)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
constexpr T maskLeadingOnes(unsigned N)
Create a bitmask with the N left-most bits set to 1, and all other bits set to 0.
constexpr int popcount(T Value) noexcept
Count the number of set bits in a value.
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
int countl_zero(T Val)
Count number of 0's from the most significant bit to the least stopping at the first 1.
FunctionAddr VTableAddr Count
int countl_one(T Value)
Count the number of ones from the most significant bit to the first zero bit.
constexpr T maskTrailingZeros(unsigned N)
Create a bitmask with the N right-most bits set to 0, and all other bits set to 1.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
constexpr T maskTrailingOnes(unsigned N)
Create a bitmask with the N right-most bits set to 1, and all other bits set to 0.
Implement std::hash so that hash_code can be used in STL containers.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
static BitVector getEmptyKey()
static bool isEqual(const BitVector &LHS, const BitVector &RHS)
static unsigned getHashValue(const BitVector &V)
static BitVector getTombstoneKey()
An information struct used to provide DenseMap with the various necessary components for a given valu...