8#ifndef SPARSEBITVECTOR_H
9#define SPARSEBITVECTOR_H
23# define HAS_CLZ __has_builtin(__builtin_clz)
24# define HAS_CLZLL __has_builtin(__builtin_clzll)
25# define HAS_CTZ __has_builtin(__builtin_ctz)
26# define HAS_CTZLL __has_builtin(__builtin_ctzll)
53 return std::numeric_limits<T>::digits;
59 T Shift = std::numeric_limits<T>::digits >> 1;
60 T Mask = std::numeric_limits<T>::max() >>
Shift;
75#if defined(__GNUC__) || defined(_MSC_VER)
76template <
typename T>
struct TrailingZerosCounter<
T, 4>
83#if HAS_CTZ || defined(__GNUC__)
85#elif defined(_MSC_VER)
93#if !defined(_MSC_VER) || defined(_M_X64)
94template <
typename T>
struct TrailingZerosCounter<
T, 8>
101#if HAS_CTZLL || defined(__GNUC__)
103#elif defined(_MSC_VER)
123 static_assert(std::numeric_limits<T>::is_integer &&
124 !std::numeric_limits<T>::is_signed,
125 "Only unsigned integral types are allowed.");
134 static_assert(
SizeOfT <= 4,
"Not implemented!");
139 v =
v - ((
v >> 1) & 0x55555555);
140 v = (
v & 0x33333333) + ((
v >> 2) & 0x33333333);
141 return ((
v + (
v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
151 return std::numeric_limits<T>::digits;
167#if defined(__GNUC__) || defined(_MSC_VER)
168template <
typename T>
struct LeadingZerosCounter<
T, 4>
175#if defined(__GNUC__) || HAS_CLZ
177#elif defined(_MSC_VER)
185#if !defined(_MSC_VER) || defined(_M_X64)
186template <
typename T>
struct LeadingZerosCounter<
T, 8>
193#if defined(__GNUC__) || HAS_CLZLL
195#elif defined(_MSC_VER)
215 static_assert(std::numeric_limits<T>::is_integer &&
216 !std::numeric_limits<T>::is_signed,
217 "Only unsigned integral types are allowed.");
229 v =
v - ((
v >> 1) & 0x5555555555555555ULL);
230 v = (
v & 0x3333333333333333ULL) + ((
v >> 2) & 0x3333333333333333ULL);
231 v = (
v + (
v >> 4)) & 0x0F0F0F0F0F0F0F0FULL;
243 static_assert(std::numeric_limits<T>::is_integer &&
244 !std::numeric_limits<T>::is_signed,
245 "Only unsigned integral types are allowed.");
299 return !(*
this ==
RHS);
362 assert(
false &&
"SBV: find_first: SBV cannot be empty");
376 assert(
false &&
"SBV: find_last: SBV cannot be empty");
391 &&
"Word Position outside of element");
500template <
unsigned ElementSize = 128>
504 using ElementList = std::list<SparseBitVectorElement<ElementSize>>;
712 return !(*
this ==
RHS);
833 return !(*
this ==
RHS);
861 if (
RHS.Elements.empty())
1022 else if (
this == &
RHS2)
1036 if (
RHS1.Elements.empty())
1091 while (
Iter2 !=
RHS.Elements.end())
1173template <
unsigned ElementSize>
1180template <
unsigned ElementSize>
1184 return LHS->operator|=(
RHS);
1187template <
unsigned ElementSize>
1191 return LHS->operator&=(
RHS);
1194template <
unsigned ElementSize>
1203template <
unsigned ElementSize>
1204inline SparseBitVector<ElementSize>
1213template <
unsigned ElementSize>
1214inline SparseBitVector<ElementSize>
1223template <
unsigned ElementSize>
1224inline SparseBitVector<ElementSize>
1234template <
unsigned ElementSize>
1255template <
unsigned N>
struct std::hash<
SVF::SparseBitVector<N>>
1260 return h(std::make_pair(std::make_pair(sbv.
count(), sbv.
find_first()),
const_iterator begin(void) const
const_iterator end(void) const
bool empty(void) const
Returns true if no bits are set.
SparseBitVectorIterator()=delete
void AdvanceToNextNonZero()
ElementListConstIter Iter
bool operator!=(const SparseBitVectorIterator &RHS) const
void AdvanceToFirstNonZero()
SparseBitVectorIterator(const SparseBitVector< ElementSize > *RHS, bool end=false)
bool operator==(const SparseBitVectorIterator &RHS) const
SparseBitVectorIterator operator++(int)
unsigned operator*() const
SparseBitVectorElement< ElementSize >::BitWord Bits
SparseBitVectorIterator & operator++()
SparseBitVectorIterator iterator
SparseBitVector & operator=(SparseBitVector &&RHS)
bool test(unsigned Idx) const
bool operator&=(const SparseBitVector &RHS)
bool intersects(const SparseBitVector< ElementSize > *RHS) const
void intersectWithComplement(const SparseBitVector< ElementSize > *RHS1, const SparseBitVector< ElementSize > *RHS2)
bool test_and_set(unsigned Idx)
typename ElementList::iterator ElementListIter
bool operator|=(const SparseBitVector &RHS)
bool intersects(const SparseBitVector< ElementSize > &RHS) const
std::list< SparseBitVectorElement< ElementSize > > ElementList
bool operator==(const SparseBitVector &RHS) const
bool intersectWithComplement(const SparseBitVector &RHS)
SparseBitVector(SparseBitVector &&RHS) noexcept
SparseBitVector(const SparseBitVector &RHS)
bool intersectWithComplement(const SparseBitVector< ElementSize > *RHS) const
ElementListIter FindLowerBound(unsigned ElementIndex)
ElementListConstIter FindLowerBoundConst(unsigned ElementIndex) const
bool contains(const SparseBitVector< ElementSize > &RHS) const
bool operator!=(const SparseBitVector &RHS) const
typename ElementList::const_iterator ElementListConstIter
ElementListIter FindLowerBoundImpl(unsigned ElementIndex) const
SparseBitVector & operator=(const SparseBitVector &RHS)
ElementListIter CurrElementIter
void intersectWithComplement(const SparseBitVector< ElementSize > &RHS1, const SparseBitVector< ElementSize > &RHS2)
IntervalValue operator-(const IntervalValue &lhs, const IntervalValue &rhs)
Subtract IntervalValues.
unsigned countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
bool operator&=(SparseBitVector< ElementSize > *LHS, const SparseBitVector< ElementSize > &RHS)
IntervalValue operator&(const IntervalValue &lhs, const IntervalValue &rhs)
Bitwise AND of IntervalValues.
llvm::Value Value
LLVM Basic classes.
llvm::IRBuilder IRBuilder
bool operator|=(SparseBitVector< ElementSize > &LHS, const SparseBitVector< ElementSize > *RHS)
void dump(const SparseBitVector< ElementSize > &LHS, std::ostream &out)
IntervalValue operator|(const IntervalValue &lhs, const IntervalValue &rhs)
Bitwise OR of IntervalValues.
unsigned countPopulation(T Value)
ZeroBehavior
The behavior an operation has on an input of 0.
@ ZB_Undefined
The returned value is undefined.
@ ZB_Max
The returned value is numeric_limits<T>::max()
@ ZB_Width
The returned value is numeric_limits<T>::digits.
unsigned countLeadingZeros(T Val, ZeroBehavior ZB=ZB_Width)
static unsigned count(T Val, ZeroBehavior)
static unsigned count(T Value)
static unsigned count(T Value)
int find_last() const
find_last - Returns the index of the last set bit.
int find_first() const
find_first - Returns the index of the first set bit.
bool intersects(const SparseBitVectorElement &RHS) const
bool intersectWith(const SparseBitVectorElement &RHS, bool &BecameZero)
bool unionWith(const SparseBitVectorElement &RHS)
bool test(unsigned Idx) const
BitWord Bits[BITWORDS_PER_ELEMENT]
BitWord word(unsigned Idx) const
int find_next(unsigned Curr) const
void intersectWithComplement(const SparseBitVectorElement &RHS1, const SparseBitVectorElement &RHS2, bool &BecameZero)
SparseBitVectorElement(unsigned Idx)
bool test_and_set(unsigned Idx)
SparseBitVectorElement()=default
bool operator==(const SparseBitVectorElement &RHS) const
bool operator!=(const SparseBitVectorElement &RHS) const
bool intersectWithComplement(const SparseBitVectorElement &RHS, bool &BecameZero)
static unsigned count(T Val, ZeroBehavior)
size_t operator()(const SVF::SparseBitVector< N > &sbv) const