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>,
123 typename SparseT = uint8_t>
125 static_assert(std::is_unsigned_v<SparseT>,
126 "SparseT must be an unsigned integer type");
128 using KeyT =
typename KeyFunctorT::argument_type;
132 SparseT *Sparse =
nullptr;
133 unsigned Universe = 0;
134 KeyFunctorT KeyIndexOf;
158 assert(
empty() &&
"Can only resize universe on an empty map");
160 if (U >= Universe/4 && U <= Universe)
166 Sparse =
static_cast<SparseT*
>(
safe_calloc(U,
sizeof(SparseT)));
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?");
254 unsigned Idx = ValIndexOf(Val);
257 return std::make_pair(
I,
false);
259 Dense.push_back(Val);
260 return std::make_pair(
end() - 1,
true);
272 return Dense.pop_back_val();
291 if (
I !=
end() - 1) {
293 unsigned BackIdx = ValIndexOf(
Dense.back());
294 assert(BackIdx < Universe &&
"Invalid key in set. Did object mutate?");
295 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
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)