14 #ifndef LLVM_ADT_SMALLBITVECTOR_H
15 #define LLVM_ADT_SMALLBITVECTOR_H
36 NumBaseBits =
sizeof(uintptr_t) * CHAR_BIT,
40 SmallNumRawBits = NumBaseBits - 1,
45 SmallNumSizeBits = (NumBaseBits == 32 ? 5 :
46 NumBaseBits == 64 ? 6 :
50 SmallNumDataBits = SmallNumRawBits - SmallNumSizeBits
53 static_assert(NumBaseBits == 64 || NumBaseBits == 32,
54 "Unsupported word size");
75 TheVector.
set(BitPos);
77 TheVector.
reset(BitPos);
82 return const_cast<const SmallBitVector &
>(TheVector).
operator[](BitPos);
87 bool isSmall()
const {
88 return X & uintptr_t(1);
91 BitVector *getPointer()
const {
93 return reinterpret_cast<BitVector *
>(X);
96 void switchToSmall(uintptr_t NewSmallBits,
size_t NewSize) {
98 setSmallSize(NewSize);
99 setSmallBits(NewSmallBits);
102 void switchToLarge(BitVector *BV) {
103 X =
reinterpret_cast<uintptr_t
>(BV);
104 assert(!isSmall() &&
"Tried to use an unaligned pointer");
109 uintptr_t getSmallRawBits()
const {
114 void setSmallRawBits(uintptr_t NewRawBits) {
116 X = (NewRawBits << 1) | uintptr_t(1);
120 size_t getSmallSize()
const {
121 return getSmallRawBits() >> SmallNumDataBits;
124 void setSmallSize(
size_t Size) {
125 setSmallRawBits(getSmallBits() | (Size << SmallNumDataBits));
129 uintptr_t getSmallBits()
const {
130 return getSmallRawBits() & ~(~uintptr_t(0) << getSmallSize());
133 void setSmallBits(uintptr_t NewBits) {
134 setSmallRawBits((NewBits & ~(~uintptr_t(0) << getSmallSize())) |
135 (getSmallSize() << SmallNumDataBits));
145 if (s <= SmallNumDataBits)
146 switchToSmall(
t ? ~uintptr_t(0) : 0, s);
156 switchToLarge(
new BitVector(*RHS.getPointer()));
170 return isSmall() ? getSmallSize() == 0 : getPointer()->
empty();
175 return isSmall() ? getSmallSize() : getPointer()->
size();
181 uintptr_t
Bits = getSmallBits();
184 return getPointer()->
count();
190 return getSmallBits() != 0;
191 return getPointer()->
any();
197 return getSmallBits() == (uintptr_t(1) << getSmallSize()) - 1;
198 return getPointer()->
all();
204 return getSmallBits() == 0;
205 return getPointer()->
none();
211 uintptr_t
Bits = getSmallBits();
223 uintptr_t
Bits = getSmallBits();
225 Bits &= ~uintptr_t(0) << (Prev + 1);
226 if (Bits == 0 || Prev + 1 >= getSmallSize())
244 }
else if (SmallNumDataBits >= N) {
245 uintptr_t NewBits =
t ? ~uintptr_t(0) << getSmallSize() : 0;
247 setSmallBits(NewBits | getSmallBits());
250 uintptr_t OldBits = getSmallBits();
251 for (
size_t i = 0, e = getSmallSize();
i != e; ++
i)
252 (*BV)[
i] = (OldBits >>
i) & 1;
259 if (N > SmallNumDataBits) {
260 uintptr_t OldBits = getSmallRawBits();
261 size_t SmallSize = getSmallSize();
263 for (
size_t i = 0;
i < SmallSize; ++
i)
264 if ((OldBits >>
i) & 1)
277 setSmallBits(~uintptr_t(0));
285 assert(Idx <= static_cast<unsigned>(
286 std::numeric_limits<uintptr_t>::digits) &&
287 "undefined behavior");
288 setSmallBits(getSmallBits() | (uintptr_t(1) << Idx));
291 getPointer()->
set(Idx);
297 assert(I <= E &&
"Attempted to set backwards range!");
298 assert(E <=
size() &&
"Attempted to set out-of-bounds range!");
299 if (I == E)
return *
this;
301 uintptr_t EMask = ((uintptr_t)1) <<
E;
302 uintptr_t IMask = ((uintptr_t)1) <<
I;
303 uintptr_t
Mask = EMask - IMask;
304 setSmallBits(getSmallBits() | Mask);
306 getPointer()->
set(I, E);
314 getPointer()->
reset();
320 setSmallBits(getSmallBits() & ~(uintptr_t(1) << Idx));
322 getPointer()->
reset(Idx);
328 assert(I <= E &&
"Attempted to reset backwards range!");
329 assert(E <=
size() &&
"Attempted to reset out-of-bounds range!");
330 if (I == E)
return *
this;
332 uintptr_t EMask = ((uintptr_t)1) <<
E;
333 uintptr_t IMask = ((uintptr_t)1) <<
I;
334 uintptr_t
Mask = EMask - IMask;
335 setSmallBits(getSmallBits() & ~Mask);
337 getPointer()->
reset(I, E);
343 setSmallBits(~getSmallBits());
345 getPointer()->
flip();
351 setSmallBits(getSmallBits() ^ (uintptr_t(1) << Idx));
353 getPointer()->
flip(Idx);
364 assert(Idx <
size() &&
"Out-of-bounds Bit access.");
369 assert(Idx <
size() &&
"Out-of-bounds Bit access.");
371 return ((getSmallBits() >> Idx) & 1) != 0;
372 return getPointer()->operator[](Idx);
375 bool test(
unsigned Idx)
const {
381 if (isSmall() && RHS.isSmall())
382 return (getSmallBits() & RHS.getSmallBits()) != 0;
383 if (!isSmall() && !RHS.isSmall())
384 return getPointer()->
anyCommon(*RHS.getPointer());
397 return getSmallBits() == RHS.getSmallBits();
399 return *getPointer() == *RHS.getPointer();
403 return !(*
this == RHS);
410 setSmallBits(getSmallBits() & RHS.getSmallBits());
411 else if (!RHS.isSmall())
412 getPointer()->operator&=(*RHS.getPointer());
416 getPointer()->operator&=(*Copy.getPointer());
423 if (isSmall() && RHS.isSmall())
424 setSmallBits(getSmallBits() & ~RHS.getSmallBits());
425 else if (!isSmall() && !RHS.isSmall())
426 getPointer()->
reset(*RHS.getPointer());
437 if (isSmall() && RHS.isSmall())
438 return (getSmallBits() & ~RHS.getSmallBits()) != 0;
439 if (!isSmall() && !RHS.isSmall())
440 return getPointer()->
test(*RHS.getPointer());
447 for (e =
size(); i != e; ++
i)
457 setSmallBits(getSmallBits() | RHS.getSmallBits());
458 else if (!RHS.isSmall())
459 getPointer()->operator|=(*RHS.getPointer());
463 getPointer()->operator|=(*Copy.getPointer());
471 setSmallBits(getSmallBits() ^ RHS.getSmallBits());
472 else if (!RHS.isSmall())
473 getPointer()->operator^=(*RHS.getPointer());
477 getPointer()->operator^=(*Copy.getPointer());
488 switchToLarge(
new BitVector(*RHS.getPointer()));
491 *getPointer() = *RHS.getPointer();
516 applyMask<true, false>(
Mask, MaskWords);
525 applyMask<false, false>(
Mask, MaskWords);
534 applyMask<true, true>(
Mask, MaskWords);
543 applyMask<false, true>(
Mask, MaskWords);
549 template <
bool AddBits,
bool InvertMask>
550 void applyMask(
const uint32_t *
Mask,
unsigned MaskWords) {
551 assert(MaskWords <=
sizeof(uintptr_t) &&
"Mask is larger than base!");
552 uintptr_t M = Mask[0];
553 if (NumBaseBits == 64)
554 M |= uint64_t(Mask[1]) << 32;
558 setSmallBits(getSmallBits() | M);
560 setSmallBits(getSmallBits() & ~M);
564 inline SmallBitVector
571 inline SmallBitVector
578 inline SmallBitVector
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.
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)
SmallBitVector & reset(unsigned I, unsigned E)
Efficiently reset a range of bits in [I, E)
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.
bool all() const
Returns true if all bits are set.
SmallBitVector operator&(const SmallBitVector &LHS, const SmallBitVector &RHS)
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.
void resize(unsigned N, bool t=false)
Grow or shrink the bitvector.
bool any() const
any - Returns true if any bit is set.
SmallBitVector & flip(unsigned Idx)
SmallBitVector & operator&=(const SmallBitVector &RHS)
SmallBitVector(unsigned s, bool t=false)
Creates a bitvector of specified number of bits.
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.
SmallBitVector operator|(const SmallBitVector &LHS, const SmallBitVector &RHS)
reference & operator=(reference t)
SmallBitVector & reset(unsigned Idx)
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.
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 etc Experimental Use value profile to guide fuzzing Number of simultaneous worker processes to run the jobs If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
reference & operator=(bool t)
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
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.
bool empty() const
empty - Tests whether there are no bits in this bitvector.
int find_next(unsigned Prev) const
Returns the index of the next set bit following the "Prev" bit.
SmallBitVector()
Creates an empty bitvector.
void clear()
Clear all bits.
SmallBitVector & operator^=(const SmallBitVector &RHS)
unsigned countPopulation(T Value)
Count the number of set bits in a value.
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
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.
bool test(unsigned Idx) const
void setBitsInMask(const uint32_t *Mask, unsigned MaskWords=~0u)
Add '1' bits from Mask to this vector.
void swap(SmallBitVector &RHS)
SmallBitVector operator~() const
SmallBitVector & set(unsigned Idx)
bool operator==(const SmallBitVector &RHS) const
SmallBitVector operator^(const SmallBitVector &LHS, const SmallBitVector &RHS)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
bool operator[](unsigned Idx) const
bool empty() const
Tests whether there are no bits in this bitvector.
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)