19 #ifndef LLVM_ADT_SPARSESET_H 20 #define LLVM_ADT_SPARSESET_H 55 template<
typename ValueT>
58 return Val.getSparseSetIndex();
66 template<
typename KeyT,
typename ValueT,
typename KeyFunctorT>
75 template<
typename KeyT,
typename KeyFunctorT>
78 return KeyFunctorT()(
Key);
122 typename SparseT = uint8_t>
124 static_assert(std::numeric_limits<SparseT>::is_integer &&
125 !std::numeric_limits<SparseT>::is_signed,
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");
207 for (
unsigned i = Sparse[Idx],
e =
size(); i <
e; i += Stride) {
208 const unsigned FoundIdx = ValIndexOf(Dense[i]);
209 assert(FoundIdx < Universe &&
"Invalid key in set. Did object mutate?");
225 return findIndex(KeyIndexOf(Key));
229 return const_cast<SparseSet*
>(
this)->findIndex(KeyIndexOf(Key));
236 return find(Key) ==
end() ? 0 : 1;
250 unsigned Idx = ValIndexOf(Val);
253 return std::make_pair(I,
false);
254 Sparse[Idx] =
size();
256 return std::make_pair(
end() - 1,
true);
263 return *insert(
ValueT(Key)).first;
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();
315 #endif // LLVM_ADT_SPARSESET_H
ValueT & operator[](const KeyT &Key)
array subscript - If an element already exists with this key, return it.
const_iterator end(StringRef path)
Get end iterator over path.
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
typename SuperClass::const_iterator const_iterator
This class represents lattice values for constants.
std::pair< iterator, bool > insert(const ValueT &Val)
insert - Attempts to insert a new element.
bool erase(const KeyT &Key)
erase - Erases an element identified by Key, if it exists.
void push_back(const T &Elt)
SparseSetValTraits - Objects in a SparseSet are identified by keys that can be uniquely converted to ...
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
size_type count(const KeyT &Key) const
count - Returns 1 if this set contains an element identified by Key, 0 otherwise. ...
size_type size() const
size - Returns the number of elements in the set.
iterator findIndex(unsigned Idx)
findIndex - Find an element by its index.
iterator erase(iterator I)
erase - Erases an existing element identified by a valid iterator.
bool empty() const
empty - Returns true if the set is empty.
typename DenseT::iterator iterator
typename DenseT::const_iterator const_iterator
unsigned operator()(const ValueT &Val) const
void setUniverse(unsigned U)
setUniverse - Set the universe size which determines the largest key the set can hold.
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
const_iterator end() const
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
Align max(MaybeAlign Lhs, Align Rhs)
const_iterator begin() const
LLVM_NODISCARD T pop_back_val()
typename SuperClass::iterator iterator
SparseSetValFunctor - Helper class for selecting SparseSetValTraits.
SparseSet - Fast set implmentation for objects that can be identified by small unsigned keys...
LLVM_NODISCARD bool empty() const
iterator find(const KeyT &Key)
find - Find an element by its key.
const_iterator find(const KeyT &Key) const
void clear()
clear - Clears the set.
unsigned operator()(const KeyT &Key) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM_ATTRIBUTE_RETURNS_NONNULL void * safe_calloc(size_t Count, size_t Sz)
static unsigned getValIndex(const ValueT &Val)