14 #ifndef LLVM_ADT_SMALLBITVECTOR_H
15 #define LLVM_ADT_SMALLBITVECTOR_H
43 NumBaseBits =
sizeof(uintptr_t) * CHAR_BIT,
47 SmallNumRawBits = NumBaseBits - 1,
52 SmallNumSizeBits = (NumBaseBits == 32 ? 5 :
53 NumBaseBits == 64 ? 6 :
57 SmallNumDataBits = SmallNumRawBits - SmallNumSizeBits
60 static_assert(NumBaseBits == 64 || NumBaseBits == 32,
61 "Unsupported word size");
83 TheVector.
set(BitPos);
85 TheVector.
reset(BitPos);
90 return const_cast<const SmallBitVector &
>(TheVector).
operator[](BitPos);
95 bool isSmall()
const {
96 return X & uintptr_t(1);
99 BitVector *getPointer()
const {
101 return reinterpret_cast<BitVector *
>(X);
104 void switchToSmall(uintptr_t NewSmallBits,
size_t NewSize) {
106 setSmallSize(NewSize);
107 setSmallBits(NewSmallBits);
110 void switchToLarge(BitVector *BV) {
111 X =
reinterpret_cast<uintptr_t
>(BV);
112 assert(!isSmall() &&
"Tried to use an unaligned pointer");
117 uintptr_t getSmallRawBits()
const {
122 void setSmallRawBits(uintptr_t NewRawBits) {
124 X = (NewRawBits << 1) | uintptr_t(1);
128 size_t getSmallSize()
const {
return getSmallRawBits() >> SmallNumDataBits; }
130 void setSmallSize(
size_t Size) {
131 setSmallRawBits(getSmallBits() | (Size << SmallNumDataBits));
135 uintptr_t getSmallBits()
const {
136 return getSmallRawBits() & ~(~uintptr_t(0) << getSmallSize());
139 void setSmallBits(uintptr_t NewBits) {
140 setSmallRawBits((NewBits & ~(~uintptr_t(0) << getSmallSize())) |
141 (getSmallSize() << SmallNumDataBits));
151 if (s <= SmallNumDataBits)
152 switchToSmall(
t ? ~uintptr_t(0) : 0, s);
162 switchToLarge(
new BitVector(*RHS.getPointer()));
191 return isSmall() ? getSmallSize() == 0 : getPointer()->
empty();
196 return isSmall() ? getSmallSize() : getPointer()->
size();
202 uintptr_t
Bits = getSmallBits();
205 return getPointer()->
count();
211 return getSmallBits() != 0;
212 return getPointer()->
any();
218 return getSmallBits() == (uintptr_t(1) << getSmallSize()) - 1;
219 return getPointer()->
all();
225 return getSmallBits() == 0;
226 return getPointer()->
none();
232 uintptr_t
Bits = getSmallBits();
242 uintptr_t
Bits = getSmallBits();
253 if (
count() == getSmallSize())
256 uintptr_t
Bits = getSmallBits();
264 if (
count() == getSmallSize())
267 uintptr_t
Bits = getSmallBits();
277 uintptr_t
Bits = getSmallBits();
279 Bits &= ~uintptr_t(0) << (Prev + 1);
280 if (Bits == 0 || Prev + 1 >= getSmallSize())
292 uintptr_t
Bits = getSmallBits();
294 uintptr_t
Mask = (1 << Prev) - 1;
297 if (Bits == ~uintptr_t(0) || Prev + 1 >= getSmallSize())
312 uintptr_t
Bits = getSmallBits();
313 Bits &= maskTrailingOnes<uintptr_t>(PriorTo + 1);
333 }
else if (SmallNumDataBits >= N) {
334 uintptr_t NewBits =
t ? ~uintptr_t(0) << getSmallSize() : 0;
336 setSmallBits(NewBits | getSmallBits());
339 uintptr_t OldBits = getSmallBits();
340 for (
size_t i = 0, e = getSmallSize(); i != e; ++i)
341 (*BV)[i] = (OldBits >> i) & 1;
348 if (N > SmallNumDataBits) {
349 uintptr_t OldBits = getSmallRawBits();
350 size_t SmallSize = getSmallSize();
352 for (
size_t i = 0; i < SmallSize; ++i)
353 if ((OldBits >> i) & 1)
366 setSmallBits(~uintptr_t(0));
374 assert(Idx <= static_cast<unsigned>(
375 std::numeric_limits<uintptr_t>::digits) &&
376 "undefined behavior");
377 setSmallBits(getSmallBits() | (uintptr_t(1) << Idx));
380 getPointer()->
set(Idx);
386 assert(I <= E &&
"Attempted to set backwards range!");
387 assert(E <=
size() &&
"Attempted to set out-of-bounds range!");
388 if (I == E)
return *
this;
390 uintptr_t EMask = ((uintptr_t)1) <<
E;
391 uintptr_t IMask = ((uintptr_t)1) <<
I;
392 uintptr_t
Mask = EMask - IMask;
393 setSmallBits(getSmallBits() | Mask);
395 getPointer()->
set(I, E);
403 getPointer()->
reset();
409 setSmallBits(getSmallBits() & ~(uintptr_t(1) << Idx));
411 getPointer()->
reset(Idx);
417 assert(I <= E &&
"Attempted to reset backwards range!");
418 assert(E <=
size() &&
"Attempted to reset out-of-bounds range!");
419 if (I == E)
return *
this;
421 uintptr_t EMask = ((uintptr_t)1) <<
E;
422 uintptr_t IMask = ((uintptr_t)1) <<
I;
423 uintptr_t
Mask = EMask - IMask;
424 setSmallBits(getSmallBits() & ~Mask);
426 getPointer()->
reset(I, E);
432 setSmallBits(~getSmallBits());
434 getPointer()->
flip();
440 setSmallBits(getSmallBits() ^ (uintptr_t(1) << Idx));
442 getPointer()->
flip(Idx);
453 assert(Idx <
size() &&
"Out-of-bounds Bit access.");
458 assert(Idx <
size() &&
"Out-of-bounds Bit access.");
460 return ((getSmallBits() >> Idx) & 1) != 0;
461 return getPointer()->operator[](Idx);
464 bool test(
unsigned Idx)
const {
470 if (isSmall() && RHS.isSmall())
471 return (getSmallBits() & RHS.getSmallBits()) != 0;
472 if (!isSmall() && !RHS.isSmall())
473 return getPointer()->
anyCommon(*RHS.getPointer());
486 return getSmallBits() == RHS.getSmallBits();
488 return *getPointer() == *RHS.getPointer();
492 return !(*
this == RHS);
499 setSmallBits(getSmallBits() & RHS.getSmallBits());
500 else if (!RHS.isSmall())
501 getPointer()->operator&=(*RHS.getPointer());
505 getPointer()->operator&=(*Copy.getPointer());
512 if (isSmall() && RHS.isSmall())
513 setSmallBits(getSmallBits() & ~RHS.getSmallBits());
514 else if (!isSmall() && !RHS.isSmall())
515 getPointer()->
reset(*RHS.getPointer());
526 if (isSmall() && RHS.isSmall())
527 return (getSmallBits() & ~RHS.getSmallBits()) != 0;
528 if (!isSmall() && !RHS.isSmall())
529 return getPointer()->
test(*RHS.getPointer());
536 for (e =
size(); i != e; ++i)
546 setSmallBits(getSmallBits() | RHS.getSmallBits());
547 else if (!RHS.isSmall())
548 getPointer()->operator|=(*RHS.getPointer());
552 getPointer()->operator|=(*Copy.getPointer());
560 setSmallBits(getSmallBits() ^ RHS.getSmallBits());
561 else if (!RHS.isSmall())
562 getPointer()->operator^=(*RHS.getPointer());
566 getPointer()->operator^=(*Copy.getPointer());
573 setSmallBits(getSmallBits() << N);
575 getPointer()->operator<<=(
N);
581 setSmallBits(getSmallBits() >> N);
583 getPointer()->operator>>=(
N);
593 switchToLarge(
new BitVector(*RHS.getPointer()));
596 *getPointer() = *RHS.getPointer();
621 applyMask<true, false>(
Mask, MaskWords);
630 applyMask<false, false>(
Mask, MaskWords);
639 applyMask<true, true>(
Mask, MaskWords);
648 applyMask<false, true>(
Mask, MaskWords);
654 template <
bool AddBits,
bool InvertMask>
655 void applyMask(
const uint32_t *
Mask,
unsigned MaskWords) {
656 assert(MaskWords <=
sizeof(uintptr_t) &&
"Mask is larger than base!");
657 uintptr_t M = Mask[0];
658 if (NumBaseBits == 64)
659 M |= uint64_t(Mask[1]) << 32;
663 setSmallBits(getSmallBits() | M);
665 setSmallBits(getSmallBits() & ~M);
669 inline SmallBitVector
676 inline SmallBitVector
683 inline SmallBitVector
702 #endif // LLVM_ADT_SMALLBITVECTOR_H
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
void clearBitsInMask(const uint32_t *Mask, unsigned MaskWords=~0u)
clearBitsInMask - Clear any bits in this vector that are set in Mask.
int find_first() const
find_first - Returns the index of the first set bit, -1 if none of the bits are set.
size_type size() const
size - Returns the number of bits in this bitvector.
size_type count() const
Returns the number of bits which are set.
void clearBitsInMask(const uint32_t *Mask, unsigned MaskWords=~0u)
Clear any bits in this vector that are set in Mask.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
bool operator!=(const SmallBitVector &RHS) const
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
const SmallBitVector & operator=(SmallBitVector &&RHS)
bool none() const
none - Returns true if none of the bits are set.
reference operator[](unsigned Idx)
int find_first_unset() const
Returns the index of the first unset bit, -1 if all of the bits are set.
SmallBitVector & reset(unsigned I, unsigned E)
Efficiently reset a range of bits in [I, E)
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
bool anyCommon(const BitVector &RHS) const
Test if any common bits are set.
int find_next(unsigned Prev) const
find_next - Returns the index of the next set bit following the "Prev" bit.
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
bool all() const
Returns true if all bits are set.
const SmallBitVector & operator=(const SmallBitVector &RHS)
void setBitsNotInMask(const uint32_t *Mask, unsigned MaskWords=~0u)
setBitsNotInMask - Add a bit to this vector for every '0' bit in Mask.
APInt operator^(APInt a, const APInt &b)
void resize(unsigned N, bool t=false)
Grow or shrink the bitvector.
bool any() const
any - Returns true if any bit is set.
int find_last() const
find_last - Returns the index of the last set bit, -1 if none of the bits are set.
std::size_t countLeadingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the most significant bit to the least stopping at the first 1...
SmallBitVector & flip(unsigned Idx)
SmallBitVector & operator&=(const SmallBitVector &RHS)
SmallBitVector(unsigned s, bool t=false)
Creates a bitvector of specified number of bits.
std::size_t countTrailingOnes(T Value, ZeroBehavior ZB=ZB_Width)
Count the number of ones from the least significant bit to the first zero bit.
bool anyCommon(const SmallBitVector &RHS) const
Test if any common bits are set.
int find_first() const
Returns the index of the first set bit, -1 if none of the bits are set.
reference & operator=(reference t)
SmallBitVector & reset(unsigned Idx)
int find_prev(unsigned PriorTo) const
find_prev - Returns the index of the first set bit that precedes the the bit at PriorTo.
SmallBitVector & reset(const SmallBitVector &RHS)
Reset bits that are set in RHS. Same as *this &= ~RHS.
bool test(const SmallBitVector &RHS) const
Check if (This - RHS) is zero. This is the same as reset(RHS) and any().
bool all() const
all - Returns true if all bits are set.
reference & operator=(bool t)
SmallBitVector()=default
Creates an empty bitvector.
const_set_bits_iterator set_bits_begin() const
void clearBitsNotInMask(const uint32_t *Mask, unsigned MaskWords=~0u)
clearBitsNotInMask - Clear a bit in this vector for every '0' bit in Mask.
size_type count() const
count - Returns the number of bits which are set.
reference(SmallBitVector &b, unsigned Idx)
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
void clearBitsNotInMask(const uint32_t *Mask, unsigned MaskWords=~0u)
Clear a bit in this vector for every '0' bit in Mask.
void setBitsNotInMask(const uint32_t *Mask, unsigned MaskWords=~0u)
Add a bit to this vector for every '0' bit in Mask.
APInt operator&(APInt a, const APInt &b)
bool empty() const
empty - Tests whether there are no bits in this bitvector.
const_set_bits_iterator_impl< SmallBitVector > const_set_bits_iterator
int find_next(unsigned Prev) const
Returns the index of the next set bit following the "Prev" bit.
ForwardIterator for the bits that are set.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
int find_last_unset() const
void clear()
Clear all bits.
SmallBitVector & operator^=(const SmallBitVector &RHS)
unsigned countPopulation(T Value)
Count the number of set bits in a value.
iterator_range< const_set_bits_iterator > set_bits() const
SmallBitVector & set(unsigned I, unsigned E)
Efficiently set a range of bits in [I, E)
SmallBitVector(const SmallBitVector &RHS)
SmallBitVector copy ctor.
bool test(unsigned Idx) const
int find_first_unset() const
find_first_unset - Returns the index of the first unset bit, -1 if all of the bits are set...
bool none() const
Returns true if none of the bits are set.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
size_t size() const
Returns the number of bits in this bitvector.
A range adaptor for a pair of iterators.
int find_prev(unsigned PriorTo) const
find_prev - Returns the index of the first set bit that precedes the the bit at PriorTo.
int find_next_unset(unsigned Prev) const
Returns the index of the next unset bit following the "Prev" bit.
bool test(unsigned Idx) const
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
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)
Add '1' bits from Mask to this vector.
SmallBitVector & operator<<=(unsigned N)
void swap(SmallBitVector &RHS)
SmallBitVector operator~() const
SmallBitVector & set(unsigned Idx)
bool operator==(const SmallBitVector &RHS) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SmallBitVector & operator>>=(unsigned N)
int find_next_unset(unsigned Prev) const
find_next_unset - Returns the index of the next unset bit following the "Prev" bit.
bool any() const
Returns true if any bit is set.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
const_set_bits_iterator set_bits_end() const
APInt operator|(APInt a, const APInt &b)
bool operator[](unsigned Idx) const
bool empty() const
Tests whether there are no bits in this bitvector.
std::size_t countLeadingOnes(T Value, ZeroBehavior ZB=ZB_Width)
Count the number of ones from the most significant bit to the first zero bit.
void setBitsInMask(const uint32_t *Mask, unsigned MaskWords=~0u)
setBitsInMask - Add '1' bits from Mask to this vector.
SmallBitVector & operator|=(const SmallBitVector &RHS)
SmallBitVector(SmallBitVector &&RHS)