From 627e6efa5b274db10564ace161d2ef583ddfcb66 Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Mon, 15 May 2023 06:56:40 -0700 Subject: Revert "[libc++][PSTL] Implement std::transform" This reverts commit cbd9e5454741ebe6b39521fe1a8ed4eed5c2c801. The wrong patch was landed. --- libcxx/include/CMakeLists.txt | 1 - libcxx/include/__algorithm/pstl_transform.h | 129 --------------------- .../include/__pstl/internal/glue_algorithm_defs.h | 23 ++++ .../include/__pstl/internal/glue_algorithm_impl.h | 21 ++++ libcxx/include/algorithm | 1 - .../alg.transform/pstl.transform.binary.pass.cpp | 85 -------------- .../alg.transform/pstl.transform.unary.pass.cpp | 67 ----------- libcxx/test/support/type_algorithms.h | 7 -- 8 files changed, 44 insertions(+), 290 deletions(-) delete mode 100644 libcxx/include/__algorithm/pstl_transform.h delete mode 100644 libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/pstl.transform.binary.pass.cpp delete mode 100644 libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/pstl.transform.unary.pass.cpp (limited to 'libcxx') diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt index f304b5dafef8..4dd363de4d17 100644 --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -82,7 +82,6 @@ set(files __algorithm/pstl_find.h __algorithm/pstl_for_each.h __algorithm/pstl_frontend_dispatch.h - __algorithm/pstl_transform.h __algorithm/push_heap.h __algorithm/ranges_adjacent_find.h __algorithm/ranges_all_of.h diff --git a/libcxx/include/__algorithm/pstl_transform.h b/libcxx/include/__algorithm/pstl_transform.h deleted file mode 100644 index 74a869583f51..000000000000 --- a/libcxx/include/__algorithm/pstl_transform.h +++ /dev/null @@ -1,129 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_PSTL_TRANSFORM_H -#define _LIBCPP___ALGORITHM_PSTL_TRANSFORM_H - -#include <__algorithm/transform.h> -#include <__config> -#include <__iterator/iterator_traits.h> -#include <__pstl/internal/parallel_backend.h> -#include <__pstl/internal/unseq_backend_simd.h> -#include <__type_traits/is_execution_policy.h> -#include <__utility/terminate_on_exception.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 - -_LIBCPP_BEGIN_NAMESPACE_STD - -template >, int> = 0> -_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator transform( - _ExecutionPolicy&& __policy, - _ForwardIterator __first, - _ForwardIterator __last, - _ForwardOutIterator __result, - _UnaryOperation __op) { - if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> && - __is_cpp17_random_access_iterator<_ForwardIterator>::value && - __is_cpp17_random_access_iterator<_ForwardOutIterator>::value) { - std::__terminate_on_exception([&] { - __pstl::__par_backend::__parallel_for( - __pstl::__internal::__par_backend_tag{}, - __policy, - __first, - __last, - [&__policy, __op, __first, __result](_ForwardIterator __brick_first, _ForwardIterator __brick_last) { - return std::transform( - std::__remove_parallel_policy(__policy), - __brick_first, - __brick_last, - __result + (__brick_first - __first), - __op); - }); - }); - return __result + (__last - __first); - } else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> && - __is_cpp17_random_access_iterator<_ForwardIterator>::value && - __is_cpp17_random_access_iterator<_ForwardOutIterator>::value) { - return __pstl::__unseq_backend::__simd_walk_2( - __first, - __last - __first, - __result, - [&](__iter_reference<_ForwardIterator> __in_value, __iter_reference<_ForwardOutIterator> __out_value) { - __out_value = __op(__in_value); - }); - } else { - return std::transform(__first, __last, __result, __op); - } -} - -template >, int> = 0> -_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator transform( - _ExecutionPolicy&& __policy, - _ForwardIterator1 __first1, - _ForwardIterator1 __last1, - _ForwardIterator2 __first2, - _ForwardOutIterator __result, - _BinaryOperation __op) { - if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> && - __is_cpp17_random_access_iterator<_ForwardIterator1>::value && - __is_cpp17_random_access_iterator<_ForwardIterator2>::value && - __is_cpp17_random_access_iterator<_ForwardOutIterator>::value) { - std::__terminate_on_exception([&] { - __pstl::__par_backend::__parallel_for( - __pstl::__internal::__par_backend_tag{}, - __policy, - __first1, - __last1, - [&__policy, __op, __first1, __first2, __result]( - _ForwardIterator1 __brick_first, _ForwardIterator1 __brick_last) { - return std::transform( - std::__remove_parallel_policy(__policy), - __brick_first, - __brick_last, - __first2 + (__brick_first - __first1), - __result + (__brick_first - __first1), - __op); - }); - }); - return __result + (__last1 - __first1); - } else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> && - __is_cpp17_random_access_iterator<_ForwardIterator1>::value && - __is_cpp17_random_access_iterator<_ForwardIterator2>::value && - __is_cpp17_random_access_iterator<_ForwardOutIterator>::value) { - return __pstl::__unseq_backend::__simd_walk_3( - __first1, - __last1 - __first1, - __first2, - __result, - [&](__iter_reference<_ForwardIterator1> __in1, - __iter_reference<_ForwardIterator2> __in2, - __iter_reference<_ForwardOutIterator> __out) { __out = __op(__in1, __in2); }); - } else { - return std::transform(__first1, __last1, __first2, __result, __op); - } -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 - -#endif // _LIBCPP___ALGORITHM_PSTL_TRANSFORM_H diff --git a/libcxx/include/__pstl/internal/glue_algorithm_defs.h b/libcxx/include/__pstl/internal/glue_algorithm_defs.h index de4501e56b2c..82bb3f508d5a 100644 --- a/libcxx/include/__pstl/internal/glue_algorithm_defs.h +++ b/libcxx/include/__pstl/internal/glue_algorithm_defs.h @@ -134,6 +134,29 @@ template swap_ranges( _ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2); +// [alg.transform] + +template +__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> +transform(_ExecutionPolicy&& __exec, + _ForwardIterator1 __first, + _ForwardIterator1 __last, + _ForwardIterator2 __result, + _UnaryOperation __op); + +template +__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> +transform(_ExecutionPolicy&& __exec, + _ForwardIterator1 __first1, + _ForwardIterator1 __last1, + _ForwardIterator2 __first2, + _ForwardIterator __result, + _BinaryOperation __op); + // [alg.replace] template diff --git a/libcxx/include/__pstl/internal/glue_algorithm_impl.h b/libcxx/include/__pstl/internal/glue_algorithm_impl.h index bae5efa7d057..db62705233b9 100644 --- a/libcxx/include/__pstl/internal/glue_algorithm_impl.h +++ b/libcxx/include/__pstl/internal/glue_algorithm_impl.h @@ -251,6 +251,27 @@ __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardItera // [alg.transform] +template +__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> +transform(_ExecutionPolicy&& __exec, + _ForwardIterator1 __first, + _ForwardIterator1 __last, + _ForwardIterator2 __result, + _UnaryOperation __op) { + typedef typename iterator_traits<_ForwardIterator1>::reference _InputType; + typedef typename iterator_traits<_ForwardIterator2>::reference _OutputType; + + auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result); + + return __pstl::__internal::__pattern_walk2( + __dispatch_tag, + std::forward<_ExecutionPolicy>(__exec), + __first, + __last, + __result, + [__op](_InputType __x, _OutputType __y) mutable { __y = __op(__x); }); +} + template #include <__algorithm/pstl_fill.h> #include <__algorithm/pstl_find.h> #include <__algorithm/pstl_for_each.h> -#include <__algorithm/pstl_transform.h> #include <__algorithm/push_heap.h> #include <__algorithm/ranges_adjacent_find.h> #include <__algorithm/ranges_all_of.h> diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/pstl.transform.binary.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/pstl.transform.binary.pass.cpp deleted file mode 100644 index 1076a1548ee3..000000000000 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/pstl.transform.binary.pass.cpp +++ /dev/null @@ -1,85 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: c++03, c++11, c++14 - -// UNSUPPORTED: libcpp-has-no-incomplete-pstl - -// - -// template -// ForwardIterator -// transform(ExecutionPolicy&& exec, -// ForwardIterator1 first1, ForwardIterator1 last1, -// ForwardIterator2 first2, ForwardIterator result, -// BinaryOperation binary_op); - -#include -#include - -#include "test_macros.h" -#include "test_execution_policies.h" -#include "test_iterators.h" - -EXECUTION_POLICY_SFINAE_TEST(transform); - -static_assert(sfinae_test_transform); -static_assert(!sfinae_test_transform); - -template -struct Test { - template - void operator()(Policy&& policy) { - // simple test - for (const int size : {0, 1, 2, 100, 350}) { - std::vector a(size); - std::vector b(size); - for (int i = 0; i != size; ++i) { - a[i] = i + 1; - b[i] = i - 3; - } - - std::vector out(std::size(a)); - decltype(auto) ret = std::transform( - policy, - Iter1(std::data(a)), - Iter1(std::data(a) + std::size(a)), - Iter2(std::data(b)), - Iter3(std::data(out)), - [](int i, int j) { return i + j + 3; }); - static_assert(std::is_same_v); - assert(base(ret) == std::data(out) + std::size(out)); - for (int i = 0; i != size; ++i) { - assert(out[i] == i * 2 + 1); - } - } - } -}; - -template -struct TestIterators2 { - template - void operator()() { - types::for_each(types::forward_iterator_list{}, - TestIteratorWithPolicies::template apply>{}); - } -}; - -struct TestIterators1 { - template - void operator()() { - types::for_each(types::forward_iterator_list{}, TestIterators2{}); - } -}; - -int main(int, char**) { - types::for_each(types::forward_iterator_list{}, TestIterators1{}); - - return 0; -} diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/pstl.transform.unary.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/pstl.transform.unary.pass.cpp deleted file mode 100644 index 31069de4e523..000000000000 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/pstl.transform.unary.pass.cpp +++ /dev/null @@ -1,67 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: c++03, c++11, c++14 - -// UNSUPPORTED: libcpp-has-no-incomplete-pstl - -// - -// template -// ForwardIterator2 -// transform(ExecutionPolicy&& exec, -// ForwardIterator1 first1, ForwardIterator1 last1, -// ForwardIterator2 result, UnaryOperation op); - -#include -#include - -#include "test_macros.h" -#include "test_execution_policies.h" -#include "test_iterators.h" - -// We can't test the constraint on the execution policy, because that would conflict with the binary -// transform algorithm that doesn't take an execution policy, which is not constrained at all. - -template -struct Test { - template - void operator()(Policy&& policy) { - // simple test - for (const int size : {0, 1, 2, 100, 350}) { - std::vector a(size); - for (int i = 0; i != size; ++i) - a[i] = i + 1; - - std::vector out(std::size(a)); - decltype(auto) ret = std::transform( - policy, Iter1(std::data(a)), Iter1(std::data(a) + std::size(a)), Iter2(std::data(out)), [](int i) { - return i + 3; - }); - static_assert(std::is_same_v); - assert(base(ret) == std::data(out) + std::size(out)); - for (int i = 0; i != size; ++i) - assert(out[i] == i + 4); - } - } -}; - -struct TestIterators { - template - void operator()() { - types::for_each(types::forward_iterator_list{}, - TestIteratorWithPolicies::template apply>{}); - } -}; - -int main(int, char**) { - types::for_each(types::forward_iterator_list{}, TestIterators{}); - - return 0; -} diff --git a/libcxx/test/support/type_algorithms.h b/libcxx/test/support/type_algorithms.h index ac3ee60b2ccf..95a282b7b0bc 100644 --- a/libcxx/test/support/type_algorithms.h +++ b/libcxx/test/support/type_algorithms.h @@ -52,13 +52,6 @@ TEST_CONSTEXPR_CXX14 void for_each(type_list, Functor f) { swallow((f.template operator()(), 0)...); } - -template