14 #ifndef LLVM_ADT_SMALLPTRSET_H 15 #define LLVM_ADT_SMALLPTRSET_H 25 #include <initializer_list> 75 : SmallArray(SmallStorage), CurArray(SmallStorage),
76 CurArraySize(SmallSize), NumNonEmpty(0), NumTombstones(0) {
77 assert(SmallSize && (SmallSize & (SmallSize-1)) == 0 &&
78 "Initial size must be a power of two!");
99 if (
size() * 4 < CurArraySize && CurArraySize > 32)
100 return shrink_and_clear();
102 memset(CurArray, -1, CurArraySize *
sizeof(
void *));
115 return reinterpret_cast<void*
>(-1);
125 std::pair<const void *const *, bool>
insert_imp(
const void *Ptr) {
128 const void **LastTombstone =
nullptr;
129 for (
const void **APtr = SmallArray, **
E = SmallArray + NumNonEmpty;
131 const void *
Value = *APtr;
133 return std::make_pair(APtr,
false);
135 LastTombstone = APtr;
139 if (LastTombstone !=
nullptr) {
140 *LastTombstone = Ptr;
143 return std::make_pair(LastTombstone,
true);
147 if (NumNonEmpty < CurArraySize) {
148 SmallArray[NumNonEmpty++] = Ptr;
150 return std::make_pair(SmallArray + (NumNonEmpty - 1),
true);
154 return insert_imp_big(Ptr);
166 const void **Loc =
const_cast<const void **
>(
P);
167 assert(*Loc == Ptr &&
"broken find!");
176 const void *
const *
find_imp(
const void * Ptr)
const {
179 for (
const void *
const *APtr = SmallArray,
180 *
const *
E = SmallArray + NumNonEmpty; APtr !=
E; ++APtr)
187 auto *Bucket = FindBucketFor(Ptr);
194 bool isSmall()
const {
return CurArray ==
SmallArray; }
196 std::pair<const void *const *, bool> insert_imp_big(
const void *Ptr);
198 const void *
const *FindBucketFor(
const void *Ptr)
const;
199 void shrink_and_clear();
202 void Grow(
unsigned NewSize);
228 : Bucket(BP), End(E) {
237 return Bucket == RHS.
Bucket;
240 return Bucket != RHS.
Bucket;
249 while (Bucket != End &&
256 while (Bucket != End &&
265 template <
typename PtrTy>
284 assert(isHandleInSync() &&
"invalid iterator access!");
287 return PtrTraits::getFromVoidPointer(const_cast<void *>(Bucket[-1]));
290 return PtrTraits::getFromVoidPointer(const_cast<void*>(*Bucket));
294 assert(isHandleInSync() &&
"invalid iterator access!");
319 template<
unsigned N,
bool isPowerTwo>
342 template <
typename PtrType>
370 std::pair<iterator, bool>
insert(PtrType Ptr) {
371 auto p =
insert_imp(PtrTraits::getAsVoidPointer(Ptr));
372 return std::make_pair(makeIterator(p.first), p.second);
378 return erase_imp(PtrTraits::getAsVoidPointer(Ptr));
383 return makeIterator(
find_imp(ConstPtrTraits::getAsVoidPointer(Ptr)));
386 template <
typename IterT>
392 void insert(std::initializer_list<PtrType> IL) {
393 insert(IL.begin(), IL.end());
405 iterator makeIterator(
const void *
const *
P)
const {
416 template <
typename PtrType>
422 for (
const auto *KV : LHS)
432 template <
typename PtrType>
435 return !(LHS == RHS);
442 template<
class PtrType,
unsigned SmallSize>
447 static_assert(SmallSize <= 32,
"SmallSize should be small");
454 const void *SmallStorage[SmallSizePowTwo];
460 : BaseT(SmallStorage, SmallSizePowTwo,
std::move(that)) {}
462 template<
typename It>
468 : BaseT(SmallStorage, SmallSizePowTwo) {
469 this->insert(IL.begin(), IL.end());
482 this->
MoveFrom(SmallSizePowTwo, std::move(RHS));
489 this->insert(IL.begin(), IL.end());
504 template<
class T,
unsigned N>
511 #endif // LLVM_ADT_SMALLPTRSET_H static void * getTombstoneMarker()
SmallPtrSetImpl(const void **SmallStorage, unsigned SmallSize, SmallPtrSetImpl &&that)
const_iterator end(StringRef path)
Get end iterator over path.
SmallPtrSet(const SmallPtrSet &that)
This class represents lattice values for constants.
bool operator==(const SmallPtrSetIteratorImpl &RHS) const
SmallPtrSetImpl(const void **SmallStorage, const SmallPtrSetImpl &that)
bool operator!=(const SmallPtrSetIteratorImpl &RHS) const
void MoveFrom(unsigned SmallSize, SmallPtrSetImplBase &&RHS)
unsigned NumNonEmpty
Number of elements in CurArray that contain a value or are a tombstone.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
SmallPtrSetIterator & operator++()
SmallPtrSetIteratorImpl - This is the common base class shared between all instances of SmallPtrSetIt...
void swap(SmallPtrSetImplBase &RHS)
swap - Swaps the elements of two sets.
const PtrTy operator*() const
SmallPtrSet(std::initializer_list< PtrType > IL)
A base class for data structure classes wishing to make iterators ("handles") pointing into themselve...
iterator find(ConstPtrType Ptr) const
const void *const * find_imp(const void *Ptr) const
Returns the raw pointer needed to construct an iterator.
SmallPtrSet(SmallPtrSet &&that)
void incrementEpoch()
Calling incrementEpoch invalidates all handles pointing into the calling instance.
unsigned CurArraySize
CurArraySize - The allocated size of CurArray, always a power of two.
bool shouldReverseIterate()
const void ** CurArray
CurArray - This is the current set of buckets.
RoundUpToPowerOfTwo - This is a helper template that rounds N up to the next power of two (which mean...
bool erase_imp(const void *Ptr)
erase_imp - If the set contains the specified pointer, remove it and return true, otherwise return fa...
A base class for iterator classes ("handles") that wish to poll for iterator invalidating modificatio...
A traits type that is used to handle pointer types and things that are just wrappers for pointers as ...
SmallPtrSet< PtrType, SmallSize > & operator=(const SmallPtrSet< PtrType, SmallSize > &RHS)
static void * getEmptyMarker()
void AdvanceIfNotValid()
AdvanceIfNotValid - If the current bucket isn't valid, advance to a bucket that is.
const void ** EndPointer() const
void CopyFrom(const SmallPtrSetImplBase &RHS)
void insert(IterT I, IterT E)
SmallPtrSet< PtrType, SmallSize > & operator=(SmallPtrSet< PtrType, SmallSize > &&RHS)
std::ptrdiff_t difference_type
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LLVM_NODISCARD bool empty() const
SmallPtrSetIterator operator++(int)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSetImpl(const void **SmallStorage, unsigned SmallSize)
const void *const * Bucket
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::forward_iterator_tag iterator_category
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
bool erase(PtrType Ptr)
erase - If the set contains the specified pointer, remove it and return true, otherwise return false...
const void ** SmallArray
SmallArray - Points to a fixed size set of buckets, used in 'small mode'.
SmallPtrSetImplBase(const void **SmallStorage, unsigned SmallSize)
SmallPtrSetImplBase(const void **SmallStorage, const SmallPtrSetImplBase &that)
RoundUpToPowerOfTwoH - If N is not a power of two, increase it.
SmallPtrSetImplBase - This is the common code shared among all the SmallPtrSet<>'s, which is almost everything.
bool operator!=(uint64_t V1, const APInt &V2)
unsigned NumTombstones
Number of tombstones in CurArray.
This class represents an analyzed expression in the program.
SmallPtrSet< PtrType, SmallSize > & operator=(std::initializer_list< PtrType > IL)
SmallPtrSetIterator(const void *const *BP, const void *const *E, const DebugEpochBase &Epoch)
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
SmallPtrSetIteratorImpl(const void *const *BP, const void *const *E)
bool operator==(uint64_t V1, const APInt &V2)
SmallPtrSetImplBase & operator=(const SmallPtrSetImplBase &)=delete
void insert(std::initializer_list< PtrType > IL)
void swap(SmallPtrSet< PtrType, SmallSize > &RHS)
swap - Swaps the elements of two sets.
std::pair< const void *const *, bool > insert_imp(const void *Ptr)
insert_imp - This returns true if the pointer was new to the set, false if it was already in the set...