20#ifndef LLVM_ADT_SPARSESET_H
21#define LLVM_ADT_SPARSESET_H
59 return Val.getSparseSetIndex();
67template <
typename KeyT,
typename ValueT,
typename KeyFunctorT>
70 if constexpr (std::is_same_v<KeyT, ValueT>)
71 return KeyFunctorT()(Val);
117 typename KeyFunctorT = identity,
typename SparseT =
uint8_t>
119 static_assert(std::is_unsigned_v<SparseT>,
120 "SparseT must be an unsigned integer type");
127 void operator()(SparseT *S) { free(S); }
129 std::unique_ptr<SparseT[], Deleter> Sparse;
131 unsigned Universe = 0;
132 KeyFunctorT KeyIndexOf;
156 assert(
empty() &&
"Can only resize universe on an empty map");
158 if (U >= Universe / 4 && U <= Universe)
163 Sparse.reset(
static_cast<SparseT *
>(
safe_calloc(U,
sizeof(SparseT))));
180 [[nodiscard]]
bool empty()
const {
return Dense.empty(); }
187 [[nodiscard]] size_type
size()
const {
return Dense.size(); }
202 assert(Idx < Universe &&
"Key out of range");
203 assert(Sparse !=
nullptr &&
"Invalid sparse type");
204 const unsigned Stride = std::numeric_limits<SparseT>::max() + 1u;
205 for (
unsigned i = Sparse[Idx], e =
size(); i < e; i += Stride) {
206 const unsigned FoundIdx = ValIndexOf(Dense[i]);
207 assert(FoundIdx < Universe &&
"Invalid key in set. Did object mutate?");
254 std::pair<iterator, bool>
insert(
const ValueT &Val) {
255 unsigned Idx = ValIndexOf(Val);
259 Sparse[Idx] =
size();
260 Dense.push_back(Val);
261 return {
end() - 1,
true};
271 return Dense.pop_back_val();
290 if (
I !=
end() - 1) {
292 unsigned BackIdx = ValIndexOf(Dense.back());
293 assert(BackIdx < Universe &&
"Invalid key in set. Did object mutate?");
294 Sparse[BackIdx] =
I -
begin();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines MallocAllocator.
#define LLVM_ATTRIBUTE_WARN_UNUSED
This file contains library features backported from future STL versions.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
This file defines the SmallVector class.
static const BasicSubtargetSubTypeKV * find(StringRef S, ArrayRef< BasicSubtargetSubTypeKV > A)
Find KV in array using binary search.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
iterator erase(iterator I)
erase - Erases an existing element identified by a valid iterator.
ValueT & operator[](const KeyT &Key)
array subscript - If an element already exists with this key, return it.
SparseSet & operator=(const SparseSet &)=delete
void clear()
clear - Clears the set.
const_iterator begin() const
iterator findIndex(unsigned Idx)
findIndex - Find an element by its index.
SparseSet(const SparseSet &)=delete
typename DenseT::const_iterator const_iterator
const_iterator end() const
bool erase(const KeyT &Key)
erase - Erases an element identified by Key, if it exists.
typename DenseT::iterator iterator
size_type size() const
size - Returns the number of elements in the set.
const_iterator find(const KeyT &Key) const
std::pair< iterator, bool > insert(const ValueT &Val)
insert - Attempts to insert a new element.
SparseSet(SparseSet &&)=default
size_type count(const KeyT &Key) const
count - Returns 1 if this set contains an element identified by Key, 0 otherwise.
const ValueT * const_pointer
const ValueT & const_reference
iterator find(const KeyT &Key)
find - Find an element by its key.
bool contains(const KeyT &Key) const
Check if the set contains the given Key.
void setUniverse(unsigned U)
setUniverse - Set the universe size which determines the largest key the set can hold.
FollowingPoolPopCache erase(Autorelease)
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ATTRIBUTE_RETURNS_NONNULL void * safe_calloc(size_t Count, size_t Sz)
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
SparseSetValFunctor - Helper class for getting a value's index.
unsigned operator()(const ValueT &Val) const
SparseSetValTraits - Objects in a SparseSet are identified by keys that can be uniquely converted to ...
static unsigned getValIndex(const ValueT &Val)