20#ifndef LLVM_ADT_SPARSESET_H
21#define LLVM_ADT_SPARSESET_H
58 return Val.getSparseSetIndex();
66template <
typename KeyT,
typename ValueT,
typename KeyFunctorT>
75template <
typename KeyT,
typename KeyFunctorT>
118template <
typename ValueT,
typename KeyFunctorT =
identity<
unsigned>,
119 typename SparseT = u
int8_t>
121 static_assert(std::is_unsigned_v<SparseT>,
122 "SparseT must be an unsigned integer type");
124 using KeyT =
typename KeyFunctorT::argument_type;
130 void operator()(SparseT *S) { free(S); }
132 std::unique_ptr<SparseT[], Deleter> Sparse;
134 unsigned Universe = 0;
135 KeyFunctorT KeyIndexOf;
159 assert(
empty() &&
"Can only resize universe on an empty map");
161 if (U >= Universe / 4 && U <= Universe)
166 Sparse.reset(
static_cast<SparseT *
>(
safe_calloc(U,
sizeof(SparseT))));
183 bool empty()
const {
return Dense.empty(); }
190 size_type
size()
const {
return Dense.size(); }
205 assert(Idx < Universe &&
"Key out of range");
206 assert(Sparse !=
nullptr &&
"Invalid sparse type");
207 const unsigned Stride = std::numeric_limits<SparseT>::max() + 1u;
208 for (
unsigned i = Sparse[Idx], e =
size(); i < e; i += Stride) {
209 const unsigned FoundIdx = ValIndexOf(Dense[i]);
210 assert(FoundIdx < Universe &&
"Invalid key in set. Did object mutate?");
252 unsigned Idx = ValIndexOf(Val);
256 Sparse[Idx] =
size();
257 Dense.push_back(Val);
258 return {
end() - 1,
true};
268 return Dense.pop_back_val();
287 if (
I !=
end() - 1) {
289 unsigned BackIdx = ValIndexOf(Dense.back());
290 assert(BackIdx < Universe &&
"Invalid key in set. Did object mutate?");
291 Sparse[BackIdx] =
I -
begin();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines MallocAllocator.
This file defines the SmallVector class.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
size_type size() const
size - Returns the number of elements in the set.
iterator findIndex(unsigned Idx)
findIndex - Find an element by its index.
SparseSet & operator=(const SparseSet &)=delete
const ValueT * const_pointer
iterator erase(iterator I)
erase - Erases an existing element identified by a valid iterator.
const ValueT & const_reference
const_iterator find(const KeyT &Key) const
SparseSet(SparseSet &&)=default
typename DenseT::iterator iterator
bool empty() const
empty - Returns true if the set is empty.
size_type count(const KeyT &Key) const
count - Returns 1 if this set contains an element identified by Key, 0 otherwise.
void clear()
clear - Clears the set.
std::pair< iterator, bool > insert(const ValueT &Val)
insert - Attempts to insert a new element.
SparseSet(const SparseSet &)=delete
const_iterator begin() const
const_iterator end() const
ValueT & operator[](const KeyT &Key)
array subscript - If an element already exists with this key, return it.
void setUniverse(unsigned U)
setUniverse - Set the universe size which determines the largest key the set can hold.
bool erase(const KeyT &Key)
erase - Erases an element identified by Key, if it exists.
typename DenseT::const_iterator const_iterator
bool contains(const KeyT &Key) const
Check if the set contains the given Key.
iterator find(const KeyT &Key)
find - Find an element by its key.
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
unsigned operator()(const KeyT &Key) const
SparseSetValFunctor - Helper class for selecting SparseSetValTraits.
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)