15#ifndef LLVM_ADT_PRIORITYWORKLIST_H
16#define LLVM_ADT_PRIORITYWORKLIST_H
53template <
typename T,
typename VectorT = std::vector<T>,
54 typename MapT = DenseMap<T, ptrdiff_t>>
84 assert(!
empty() &&
"Cannot call back() on empty PriorityWorklist!");
91 assert(
X !=
T() &&
"Cannot insert a null (default constructed) value!");
92 auto InsertResult = M.insert({
X, V.size()});
93 if (InsertResult.second) {
99 auto &
Index = InsertResult.first->second;
100 assert(V[
Index] ==
X &&
"Value not actually at index in map!");
111 template <
typename SequenceT>
112 std::enable_if_t<!std::is_convertible<SequenceT, T>::value>
114 if (std::begin(Input) == std::end(Input))
121 V.insert(V.end(), std::begin(Input), std::end(Input));
123 for (
ptrdiff_t i = V.size() - 1; i >= StartIndex; --i) {
124 auto InsertResult = M.insert({V[i], i});
125 if (InsertResult.second)
131 if (
Index < StartIndex) {
145 assert(!
empty() &&
"Cannot remove an element when empty!");
146 assert(
back() !=
T() &&
"Cannot have a null element at the back!");
150 }
while (!V.empty() && V.back() ==
T());
167 assert(V[
I->second] ==
X &&
"Value not actually at index in map!");
171 }
while (!V.empty() && V.back() ==
T());
192 template <
typename UnaryPredicate>
194 typename VectorT::iterator
E =
195 remove_if(V, TestAndEraseFromMap<UnaryPredicate>(
P, M));
198 for (
auto I = V.begin();
I !=
E; ++
I)
200 M[*
I] =
I - V.begin();
223 template <
typename UnaryPredicateT>
224 class TestAndEraseFromMap {
229 TestAndEraseFromMap(UnaryPredicateT P,
MapT &M)
232 bool operator()(
const T &Arg) {
254template <
typename T,
unsigned N>
257 SmallDenseMap<T, ptrdiff_t>> {
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the DenseMap class.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
A FILO worklist that prioritizes on re-insertion without duplication.
const T & back() const
Return the last element of the PriorityWorklist.
PriorityWorklist()=default
Construct an empty PriorityWorklist.
size_type count(const key_type &key) const
Count the number of elements of a given key in the PriorityWorklist.
void clear()
Reverse the items in the PriorityWorklist.
typename MapT::size_type size_type
size_type size() const
Returns the number of elements in the worklist.
bool erase_if(UnaryPredicate P)
Erase items from the set vector based on a predicate function.
bool erase(const T &X)
Erase an item from the worklist.
void pop_back()
Remove the last element of the PriorityWorklist.
bool empty() const
Determine if the PriorityWorklist is empty or not.
bool insert(const T &X)
Insert a new element into the PriorityWorklist.
std::enable_if_t<!std::is_convertible< SequenceT, T >::value > insert(SequenceT &&Input)
Insert a sequence of new elements into the PriorityWorklist.
A version of PriorityWorklist that selects small size optimized data structures for the vector and ma...
SmallPriorityWorklist()=default
This is an optimization pass for GlobalISel generic memory operations.
auto remove_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.