20 #ifndef LLVM_ADT_SPARSESET_H 21 #define LLVM_ADT_SPARSESET_H 56 template<
typename ValueT>
59 return Val.getSparseSetIndex();
67 template<
typename KeyT,
typename ValueT,
typename KeyFunctorT>
76 template<
typename KeyT,
typename KeyFunctorT>
79 return KeyFunctorT()(
Key);
123 typename SparseT = uint8_t>
125 static_assert(std::numeric_limits<SparseT>::is_integer &&
126 !std::numeric_limits<SparseT>::is_signed,
127 "SparseT must be an unsigned integer type");
129 using KeyT =
typename KeyFunctorT::argument_type;
133 SparseT *Sparse =
nullptr;
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)
167 Sparse =
static_cast<SparseT*
>(
safe_calloc(U,
sizeof(SparseT)));
206 assert(Idx < Universe &&
"Key out of range");
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?");
226 return findIndex(KeyIndexOf(Key));
230 return const_cast<SparseSet*
>(
this)->findIndex(KeyIndexOf(Key));
237 return find(Key) ==
end() ? 0 : 1;
251 unsigned Idx = ValIndexOf(Val);
254 return std::make_pair(I,
false);
255 Sparse[Idx] =
size();
257 return std::make_pair(
end() - 1,
true);
264 return *insert(
ValueT(Key)).first;
288 if (I !=
end() - 1) {
290 unsigned BackIdx = ValIndexOf(Dense.
back());
291 assert(BackIdx < Universe &&
"Invalid key in set. Did object mutate?");
292 Sparse[BackIdx] = I -
begin();
316 #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.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
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
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
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.
const_iterator begin() const
LLVM_NODISCARD T pop_back_val()
typename SuperClass::iterator iterator
SparseSetValFunctor - Helper class for selecting SparseSetValTraits.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
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)