16 #ifndef LLVM_ADT_PRIORITYWORKLIST_H
17 #define LLVM_ADT_PRIORITYWORKLIST_H
54 template <
typename T,
typename VectorT = std::vector<T>,
55 typename MapT = DenseMap<T, ptrdiff_t>>
85 assert(!
empty() &&
"Cannot call back() on empty PriorityWorklist!");
92 assert(X !=
T() &&
"Cannot insert a null (default constructed) value!");
93 auto InsertResult = M.insert({
X, V.size()});
94 if (InsertResult.second) {
100 auto &Index = InsertResult.first->second;
101 assert(V[Index] == X &&
"Value not actually at index in map!");
102 if (Index != (ptrdiff_t)(V.size() - 1)) {
105 Index = (ptrdiff_t)V.size();
112 template <
typename SequenceT>
113 typename std::enable_if<!std::is_convertible<SequenceT, T>::value>::type
121 ptrdiff_t StartIndex = V.size();
124 for (ptrdiff_t
i = V.size() - 1;
i >= StartIndex; --
i) {
125 auto InsertResult = M.insert({V[
i],
i});
126 if (InsertResult.second)
131 ptrdiff_t &Index = InsertResult.first->second;
132 if (Index < StartIndex) {
146 assert(!
empty() &&
"Cannot remove an element when empty!");
147 assert(
back() !=
T() &&
"Cannot have a null element at the back!");
151 }
while (!V.empty() && V.back() ==
T());
168 assert(V[
I->second] == X &&
"Value not actually at index in map!");
169 if (
I->second == (ptrdiff_t)(V.size() - 1)) {
172 }
while (!V.empty() && V.back() ==
T());
193 template <
typename UnaryPredicate>
195 typename VectorT::iterator
E =
196 remove_if(V, TestAndEraseFromMap<UnaryPredicate>(P, M));
199 for (
auto I = V.begin();
I !=
E; ++
I)
201 M[*
I] =
I - V.begin();
224 template <
typename UnaryPredicateT>
225 class TestAndEraseFromMap {
230 TestAndEraseFromMap(UnaryPredicateT
P, MapT &M)
231 : P(std::move(P)), M(M) {}
233 bool operator()(
const T &Arg) {
255 template <
typename T,
unsigned N>
258 SmallDenseMap<T, ptrdiff_t>> {
265 #endif // LLVM_ADT_PRIORITYWORKLIST_H
This routine provides some synthesis utilities to produce sequences of values.
const_iterator end(StringRef path)
Get end iterator over path.
bool erase(const T &X)
Erase an item from the worklist.
bool insert(const T &X)
Insert a new element into the PriorityWorklist.
LLVM_NODISCARD T pop_back_val()
auto remove_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly...
bool erase_if(UnaryPredicate P)
Erase items from the set vector based on a predicate function.
const_iterator begin(StringRef path)
Get begin iterator over path.
PriorityWorklist()=default
Construct an empty PriorityWorklist.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
void clear()
Reverse the items in the PriorityWorklist.
size_type size() const
Returns the number of elements in the worklist.
std::enable_if<!std::is_convertible< SequenceT, T >::value >::type insert(SequenceT &&Input)
Insert a sequence of new elements into the PriorityWorklist.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
A version of PriorityWorklist that selects small size optimized data structures for the vector and ma...
A FILO worklist that prioritizes on re-insertion without duplication.
const T & const_reference
size_type count(const key_type &key) const
Count the number of elements of a given key in the PriorityWorklist.
const T & back() const
Return the last element of the PriorityWorklist.
void pop_back()
Remove the last element of the PriorityWorklist.
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
An SCC of the call graph.
SmallPriorityWorklist()=default
MapT::size_type size_type
bool empty() const
Determine if the PriorityWorklist is empty or not.