20#ifndef LLVM_ADT_SPARSESET_H
21#define LLVM_ADT_SPARSESET_H
56template<
typename ValueT>
59 return Val.getSparseSetIndex();
67template<
typename KeyT,
typename ValueT,
typename KeyFunctorT>
76template<
typename KeyT,
typename KeyFunctorT>
79 return KeyFunctorT()(Key);
122 typename KeyFunctorT = identity<unsigned>,
125 static_assert(std::is_unsigned_v<SparseT>,
126 "SparseT must be an unsigned integer type");
128 using KeyT =
typename KeyFunctorT::argument_type;
134 void operator()(SparseT *S) { free(S); }
136 std::unique_ptr<SparseT[], Deleter> Sparse;
138 unsigned Universe = 0;
139 KeyFunctorT KeyIndexOf;
163 assert(
empty() &&
"Can only resize universe on an empty map");
165 if (U >= Universe/4 && U <= Universe)
170 Sparse.reset(
static_cast<SparseT *
>(
safe_calloc(U,
sizeof(SparseT))));
209 assert(
Idx < Universe &&
"Key out of range");
210 assert(Sparse !=
nullptr &&
"Invalid sparse type");
211 const unsigned Stride = std::numeric_limits<SparseT>::max() + 1u;
212 for (
unsigned i = Sparse[
Idx], e =
size(); i < e; i += Stride) {
213 const unsigned FoundIdx = ValIndexOf(
Dense[i]);
214 assert(FoundIdx < Universe &&
"Invalid key in set. Did object mutate?");
258 unsigned Idx = ValIndexOf(Val);
261 return std::make_pair(
I,
false);
263 Dense.push_back(Val);
264 return std::make_pair(
end() - 1,
true);
276 return Dense.pop_back_val();
295 if (
I !=
end() - 1) {
297 unsigned BackIdx = ValIndexOf(
Dense.back());
298 assert(BackIdx < Universe &&
"Invalid key in set. Did object mutate?");
299 Sparse[BackIdx] =
I -
begin();
This file defines MallocAllocator.
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
SparseSet - Fast set implementation for objects that can be identified by small unsigned keys.
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
iterator erase(iterator I)
erase - Erases an existing element identified by a valid iterator.
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)
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)