9 #ifndef LLVM_SUPPORT_PARALLEL_H 10 #define LLVM_SUPPORT_PARALLEL_H 13 #include "llvm/Config/llvm-config.h" 17 #include <condition_variable> 29 :
public std::integral_constant<
30 bool, llvm::is_one_of<T, sequential_execution_policy,
31 parallel_execution_policy>::value> {};
38 #if LLVM_ENABLE_THREADS 42 mutable std::mutex
Mutex;
43 mutable std::condition_variable Cond;
50 std::lock_guard<std::mutex> lock(Mutex);
55 std::lock_guard<std::mutex> lock(Mutex);
61 std::unique_lock<std::mutex> lock(Mutex);
62 Cond.wait(lock, [&] {
return Count == 0; });
82 template <
class RandomAccessIterator,
class Comparator>
83 RandomAccessIterator
medianOf3(RandomAccessIterator Start,
84 RandomAccessIterator End,
85 const Comparator &Comp) {
86 RandomAccessIterator Mid = Start + (std::distance(Start, End) / 2);
87 return Comp(*Start, *(End - 1))
88 ? (Comp(*Mid, *(End - 1)) ? (Comp(*Start, *Mid) ? Mid : Start)
90 : (Comp(*Mid, *Start) ? (Comp(*(End - 1), *Mid) ? Mid : End - 1)
94 template <
class RandomAccessIterator,
class Comparator>
104 auto Pivot =
medianOf3(Start, End, Comp);
107 Pivot =
std::partition(Start, End - 1, [&Comp, End](decltype(*Start) V) {
108 return Comp(V, *(End - 1));
114 TG.
spawn([=, &Comp, &TG] {
120 template <
class RandomAccessIterator,
class Comparator>
122 const Comparator &Comp) {
128 template <
class IterTy,
class FuncTy>
134 ptrdiff_t TaskSize = std::distance(Begin, End) / 1024;
139 while (TaskSize < std::distance(Begin, End)) {
146 template <
class IndexTy,
class FuncTy>
148 ptrdiff_t TaskSize = (End - Begin) / 1024;
154 for (; I + TaskSize < End; I += TaskSize) {
156 for (IndexTy J = I,
E = I + TaskSize; J !=
E; ++J)
160 for (IndexTy J = I; J < End; ++J)
166 template <
typename Iter>
168 std::less<typename std::iterator_traits<Iter>::value_type>;
173 template <
class Policy,
class RandomAccessIterator,
175 void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End,
176 const Comparator &Comp = Comparator()) {
178 "Invalid execution policy!");
182 template <
class Policy,
class IterTy,
class FuncTy>
183 void for_each(Policy policy, IterTy Begin, IterTy End, FuncTy Fn) {
185 "Invalid execution policy!");
189 template <
class Policy,
class IndexTy,
class FuncTy>
190 void for_each_n(Policy policy, IndexTy Begin, IndexTy End, FuncTy Fn) {
192 "Invalid execution policy!");
193 for (IndexTy
I = Begin;
I != End; ++
I)
199 #if LLVM_ENABLE_THREADS 200 template <
class RandomAccessIterator,
203 RandomAccessIterator End,
const Comparator &Comp = Comparator()) {
207 template <
class IterTy,
class FuncTy>
213 template <
class IndexTy,
class FuncTy>
223 #endif // LLVM_SUPPORT_PARALLEL_H const ptrdiff_t MinParallelSize
void for_each_n(Policy policy, IndexTy Begin, IndexTy End, FuncTy Fn)
This class represents lattice values for constants.
void parallel_for_each_n(IndexTy Begin, IndexTy End, FuncTy Fn)
constexpr sequential_execution_policy seq
SmartMutex< false > Mutex
Mutex - A standard, always enforced mutex.
auto partition(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::partition which take ranges instead of having to pass begin/end explicitly...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void sort(IteratorTy Start, IteratorTy End)
constexpr parallel_execution_policy par
void for_each(Policy policy, IterTy Begin, IterTy End, FuncTy Fn)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
std::less< typename std::iterator_traits< Iter >::value_type > DefComparator
void parallel_for_each(IterTy Begin, IterTy End, FuncTy Fn)
void parallel_sort(RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp)
RandomAccessIterator medianOf3(RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp)
Inclusive median.
void for_each(parallel_execution_policy policy, IterTy Begin, IterTy End, FuncTy Fn)
void parallel_quick_sort(RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp, TaskGroup &TG, size_t Depth)
void spawn(std::function< void()> f)
print Print MemDeps of function
void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.