20#ifndef LLVM_ADT_SPARSESET_H
21#define LLVM_ADT_SPARSESET_H
58 return Val.getSparseSetIndex();
66template <
typename KeyT,
typename ValueT,
typename KeyFunctorT>
69 if constexpr (std::is_same_v<KeyT, ValueT>)
70 return KeyFunctorT()(Val);
116 typename KeyFunctorT = identity,
typename SparseT =
uint8_t>
118 static_assert(std::is_unsigned_v<SparseT>,
119 "SparseT must be an unsigned integer type");
126 void operator()(SparseT *S) { free(S); }
128 std::unique_ptr<SparseT[], Deleter> Sparse;
130 unsigned Universe = 0;
131 KeyFunctorT KeyIndexOf;
155 assert(
empty() &&
"Can only resize universe on an empty map");
157 if (U >= Universe / 4 && U <= Universe)
162 Sparse.reset(
static_cast<SparseT *
>(
safe_calloc(U,
sizeof(SparseT))));
179 [[nodiscard]]
bool empty()
const {
return Dense.empty(); }
186 [[nodiscard]] size_type
size()
const {
return Dense.size(); }
201 assert(Idx < Universe &&
"Key out of range");
202 assert(Sparse !=
nullptr &&
"Invalid sparse type");
203 const unsigned Stride = std::numeric_limits<SparseT>::max() + 1u;
204 for (
unsigned i = Sparse[Idx], e =
size(); i < e; i += Stride) {
205 const unsigned FoundIdx = ValIndexOf(Dense[i]);
206 assert(FoundIdx < Universe &&
"Invalid key in set. Did object mutate?");
253 std::pair<iterator, bool>
insert(
const ValueT &Val) {
254 unsigned Idx = ValIndexOf(Val);
258 Sparse[Idx] =
size();
259 Dense.push_back(Val);
260 return {
end() - 1,
true};
270 return Dense.pop_back_val();
289 if (
I !=
end() - 1) {
291 unsigned BackIdx = ValIndexOf(Dense.back());
292 assert(BackIdx < Universe &&
"Invalid key in set. Did object mutate?");
293 Sparse[BackIdx] =
I -
begin();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines MallocAllocator.
This file contains library features backported from future STL versions.
This file defines the SmallVector class.
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.
bool empty() const
empty - Returns true if the set is empty.
void setUniverse(unsigned U)
setUniverse - Set the universe size which determines the largest key the set can hold.
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)