15 #ifndef LLVM_ADT_SMALLPTRSET_H 16 #define LLVM_ADT_SMALLPTRSET_H 26 #include <initializer_list> 76 : SmallArray(SmallStorage), CurArray(SmallStorage),
77 CurArraySize(SmallSize), NumNonEmpty(0), NumTombstones(0) {
78 assert(SmallSize && (SmallSize & (SmallSize-1)) == 0 &&
79 "Initial size must be a power of two!");
100 if (
size() * 4 < CurArraySize && CurArraySize > 32)
101 return shrink_and_clear();
103 memset(CurArray, -1, CurArraySize *
sizeof(
void *));
116 return reinterpret_cast<void*
>(-1);
126 std::pair<const void *const *, bool>
insert_imp(
const void *Ptr) {
129 const void **LastTombstone =
nullptr;
130 for (
const void **APtr = SmallArray, **
E = SmallArray + NumNonEmpty;
132 const void *
Value = *APtr;
134 return std::make_pair(APtr,
false);
136 LastTombstone = APtr;
140 if (LastTombstone !=
nullptr) {
141 *LastTombstone = Ptr;
144 return std::make_pair(LastTombstone,
true);
148 if (NumNonEmpty < CurArraySize) {
149 SmallArray[NumNonEmpty++] = Ptr;
151 return std::make_pair(SmallArray + (NumNonEmpty - 1),
true);
155 return insert_imp_big(Ptr);
167 const void **Loc =
const_cast<const void **
>(
P);
168 assert(*Loc == Ptr &&
"broken find!");
177 const void *
const *
find_imp(
const void * Ptr)
const {
180 for (
const void *
const *APtr = SmallArray,
181 *
const *
E = SmallArray + NumNonEmpty; APtr !=
E; ++APtr)
188 auto *Bucket = FindBucketFor(Ptr);
195 bool isSmall()
const {
return CurArray ==
SmallArray; }
197 std::pair<const void *const *, bool> insert_imp_big(
const void *Ptr);
199 const void *
const *FindBucketFor(
const void *Ptr)
const;
200 void shrink_and_clear();
203 void Grow(
unsigned NewSize);
229 : Bucket(BP), End(E) {
238 return Bucket == RHS.
Bucket;
241 return Bucket != RHS.
Bucket;
250 while (Bucket != End &&
257 while (Bucket != End &&
266 template <
typename PtrTy>
285 assert(isHandleInSync() &&
"invalid iterator access!");
288 return PtrTraits::getFromVoidPointer(const_cast<void *>(Bucket[-1]));
291 return PtrTraits::getFromVoidPointer(const_cast<void*>(*Bucket));
295 assert(isHandleInSync() &&
"invalid iterator access!");
320 template<
unsigned N,
bool isPowerTwo>
343 template <
typename PtrType>
371 std::pair<iterator, bool>
insert(PtrType Ptr) {
372 auto p =
insert_imp(PtrTraits::getAsVoidPointer(Ptr));
373 return std::make_pair(makeIterator(p.first), p.second);
379 return erase_imp(PtrTraits::getAsVoidPointer(Ptr));
384 return makeIterator(
find_imp(ConstPtrTraits::getAsVoidPointer(Ptr)));
387 template <
typename IterT>
393 void insert(std::initializer_list<PtrType> IL) {
394 insert(IL.begin(), IL.end());
406 iterator makeIterator(
const void *
const *
P)
const {
417 template<
class PtrType,
unsigned SmallSize>
422 static_assert(SmallSize <= 32,
"SmallSize should be small");
429 const void *SmallStorage[SmallSizePowTwo];
435 : BaseT(SmallStorage, SmallSizePowTwo,
std::move(that)) {}
437 template<
typename It>
443 : BaseT(SmallStorage, SmallSizePowTwo) {
444 this->insert(IL.begin(), IL.end());
457 this->
MoveFrom(SmallSizePowTwo, std::move(RHS));
464 this->insert(IL.begin(), IL.end());
479 template<
class T,
unsigned N>
486 #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++()
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
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.
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)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
SmallPtrSetIteratorImpl(const void *const *BP, const void *const *E)
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...