Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / src / pstl / libdispatch.cpp
blob52d4afbcce6e00c8d4fb5ab10d5d500526b12d75
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include <__algorithm/min.h>
10 #include <__algorithm/pstl_backends/cpu_backends/libdispatch.h>
11 #include <__config>
12 #include <dispatch/dispatch.h>
14 _LIBCPP_BEGIN_NAMESPACE_STD
16 namespace __par_backend::inline __libdispatch {
18 void __dispatch_apply(size_t chunk_count, void* context, void (*func)(void* context, size_t chunk)) noexcept {
19 ::dispatch_apply_f(chunk_count, DISPATCH_APPLY_AUTO, context, func);
22 __chunk_partitions __partition_chunks(ptrdiff_t element_count) noexcept {
23 __chunk_partitions partitions;
24 partitions.__chunk_count_ = std::max<ptrdiff_t>(1, element_count / 256);
25 partitions.__chunk_size_ = element_count / partitions.__chunk_count_;
26 partitions.__first_chunk_size_ = element_count - (partitions.__chunk_count_ - 1) * partitions.__chunk_size_;
27 if (partitions.__chunk_count_ == 0 && element_count > 0)
28 partitions.__chunk_count_ = 1;
29 return partitions;
32 // NOLINTNEXTLINE(llvm-namespace-comment) // This is https://llvm.org/PR56804
33 } // namespace __par_backend::inline __libdispatch
35 _LIBCPP_END_NAMESPACE_STD