Skip to content

Commit 7cd9c5e

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:4aeb7a0f5e35 into amd-gfx:c48ae1cfb717
Local branch amd-gfx c48ae1c Merged main:3d40411ee889 into amd-gfx:e3dbac853df2 Remote branch main 4aeb7a0 [gn build] Port d2a46e6
2 parents c48ae1c + 4aeb7a0 commit 7cd9c5e

File tree

10 files changed

+236
-3
lines changed

10 files changed

+236
-3
lines changed

libcxx/docs/Status/PSTLPaper.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Section,Description,Assignee,Complete
3636
| `[alg.min.max] <https://wg21.link/alg.min.max>`_,std::min_element,Nikolas Klauser,|Not Started|
3737
| `[alg.min.max] <https://wg21.link/alg.min.max>`_,std::minmax_element,Nikolas Klauser,|Not Started|
3838
| `[mismatch] <https://wg21.link/mismatch>`_,std::mismatch,Nikolas Klauser,|Not Started|
39-
| `[alg.move] <https://wg21.link/alg.move>`_,std::move,Nikolas Klauser,|In Progress|
39+
| `[alg.move] <https://wg21.link/alg.move>`_,std::move,Nikolas Klauser,|Complete|
4040
| `[alg.none.of] <https://wg21.link/alg.none.of>`_,std::none_of,Nikolas Klauser,|Complete|
4141
| `[alg.nth.element] <https://wg21.link/alg.nth.element>`_,std::nth_element,Nikolas Klauser,|Not Started|
4242
| `[alg.sort] <https://wg21.link/alg.sort>`_,std::partial_sort,Nikolas Klauser,|Not Started|

libcxx/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ set(files
9494
__algorithm/pstl_generate.h
9595
__algorithm/pstl_is_partitioned.h
9696
__algorithm/pstl_merge.h
97+
__algorithm/pstl_move.h
9798
__algorithm/pstl_replace.h
9899
__algorithm/pstl_sort.h
99100
__algorithm/pstl_stable_sort.h

libcxx/include/__algorithm/pstl_backend.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ implemented, all the algorithms will eventually forward to the basis algorithms
131131
_OutIterator __result,
132132
_Comp __comp);
133133
134+
template <class _ExecutionPolicy, class _Iterator, class _OutIterator>
135+
optional<_OutIterator> __pstl_move(_Backend, _Iterator __first, _Iterator __last, _OutIterator __result);
136+
134137
template <class _ExecutionPolicy, class _Iterator, class _Tp, class _BinaryOperation>
135138
optional<_Tp> __pstl_reduce(_Backend, _Iterator __first, _Iterator __last, _Tp __init, _BinaryOperation __op);
136139
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___ALGORITHM_PSTL_MOVE_H
10+
#define _LIBCPP___ALGORITHM_PSTL_MOVE_H
11+
12+
#include <__algorithm/copy_n.h>
13+
#include <__algorithm/pstl_frontend_dispatch.h>
14+
#include <__algorithm/pstl_transform.h>
15+
#include <__config>
16+
#include <__functional/identity.h>
17+
#include <__iterator/iterator_traits.h>
18+
#include <__type_traits/enable_if.h>
19+
#include <__type_traits/is_constant_evaluated.h>
20+
#include <__type_traits/is_execution_policy.h>
21+
#include <__type_traits/is_trivially_copyable.h>
22+
#include <__type_traits/remove_cvref.h>
23+
#include <optional>
24+
25+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26+
# pragma GCC system_header
27+
#endif
28+
29+
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
30+
31+
_LIBCPP_BEGIN_NAMESPACE_STD
32+
33+
// TODO: Use the std::copy/move shenanigans to forward to std::memmove
34+
// Investigate whether we want to still forward to std::transform(policy)
35+
// in that case for the execution::par part, or whether we actually want
36+
// to run everything serially in that case.
37+
38+
template <class>
39+
void __pstl_move();
40+
41+
template <class _ExecutionPolicy,
42+
class _ForwardIterator,
43+
class _ForwardOutIterator,
44+
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
45+
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
46+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<_ForwardOutIterator>
47+
__move(_ExecutionPolicy&& __policy,
48+
_ForwardIterator&& __first,
49+
_ForwardIterator&& __last,
50+
_ForwardOutIterator&& __result) noexcept {
51+
return std::__pstl_frontend_dispatch(
52+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_move, _RawPolicy),
53+
[&__policy](_ForwardIterator __g_first, _ForwardIterator __g_last, _ForwardOutIterator __g_result) {
54+
return std::__transform(__policy, __g_first, __g_last, __g_result, [](auto&& __v) { return std::move(__v); });
55+
},
56+
std::move(__first),
57+
std::move(__last),
58+
std::move(__result));
59+
}
60+
61+
template <class _ExecutionPolicy,
62+
class _ForwardIterator,
63+
class _ForwardOutIterator,
64+
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
65+
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
66+
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator
67+
move(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _ForwardOutIterator __result) {
68+
auto __res = std::__move(__policy, std::move(__first), std::move(__last), std::move(__result));
69+
if (!__res)
70+
std::__throw_bad_alloc();
71+
return *__res;
72+
}
73+
74+
_LIBCPP_END_NAMESPACE_STD
75+
76+
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
77+
78+
#endif // _LIBCPP___ALGORITHM_PSTL_MOVE_H

libcxx/include/algorithm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,7 @@ template <class BidirectionalIterator, class Compare>
18331833
#include <__algorithm/pstl_generate.h>
18341834
#include <__algorithm/pstl_is_partitioned.h>
18351835
#include <__algorithm/pstl_merge.h>
1836+
#include <__algorithm/pstl_move.h>
18361837
#include <__algorithm/pstl_replace.h>
18371838
#include <__algorithm/pstl_sort.h>
18381839
#include <__algorithm/pstl_stable_sort.h>

libcxx/test/libcxx/algorithms/pstl.robust_against_customization_points_not_working.pass.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,15 @@ optional<__empty> __pstl_fill_n(TestBackend, ForwardIterator, Size, Func) {
172172
return __empty{};
173173
}
174174

175+
bool pstl_move_called = false;
176+
177+
template <class, class ForwardIterator, class Size, class Func>
178+
ForwardIterator __pstl_move(TestBackend, ForwardIterator, Size, Func) {
179+
assert(!pstl_move_called);
180+
pstl_move_called = true;
181+
return 0;
182+
}
183+
175184
bool pstl_is_partitioned_called = false;
176185

177186
template <class, class ForwardIterator, class Func>
@@ -352,7 +361,9 @@ int main(int, char**) {
352361
(void)std::generate_n(TestPolicy{}, std::begin(a), std::size(a), pred);
353362
assert(std::pstl_generate_n_called);
354363
(void)std::is_partitioned(TestPolicy{}, std::begin(a), std::end(a), pred);
355-
assert(std::pstl_generate_n_called);
364+
assert(std::pstl_is_partitioned_called);
365+
(void)std::move(TestPolicy{}, std::begin(a), std::end(a), std::begin(a));
366+
assert(std::pstl_move_called);
356367
(void)std::replace(TestPolicy{}, std::begin(a), std::end(a), 0, 0);
357368
assert(std::pstl_replace_called);
358369
(void)std::replace_if(TestPolicy{}, std::begin(a), std::end(a), pred, 0);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03, c++11, c++14
10+
// UNSUPPORTED: no-exceptions
11+
// REQUIRES: has-unix-headers
12+
13+
// UNSUPPORTED: libcpp-has-no-incomplete-pstl
14+
15+
// check that std::move(ExecutionPolicy) terminates on user-thrown exceptions
16+
17+
#include <algorithm>
18+
19+
#include "check_assertion.h"
20+
#include "test_execution_policies.h"
21+
#include "test_iterators.h"
22+
23+
int main(int, char**) {
24+
test_execution_policies([](auto&& policy) {
25+
EXPECT_STD_TERMINATE([&] {
26+
try {
27+
int a[] = {1, 2};
28+
int b[] = {1, 2};
29+
(void)std::move(policy,
30+
util::throw_on_move_iterator(std::begin(a), 1),
31+
util::throw_on_move_iterator(std::end(a), 1),
32+
util::throw_on_move_iterator(std::begin(b), 1));
33+
} catch (const util::iterator_error&) {
34+
assert(false);
35+
}
36+
std::terminate(); // make the test pass in case the algorithm didn't move the iterator
37+
});
38+
});
39+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03, c++11, c++14
10+
11+
// UNSUPPORTED: libcpp-has-no-incomplete-pstl
12+
13+
// <algorithm>
14+
15+
// template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
16+
// ForwardIterator2 move(ExecutionPolicy&& policy,
17+
// ForwardIterator1 first, ForwardIterator1 last,
18+
// ForwardIterator2 result);
19+
20+
#include <algorithm>
21+
#include <vector>
22+
23+
#include "test_macros.h"
24+
#include "test_execution_policies.h"
25+
#include "test_iterators.h"
26+
27+
EXECUTION_POLICY_SFINAE_TEST(move);
28+
29+
static_assert(sfinae_test_move<int, int*, int*, int*>);
30+
static_assert(!sfinae_test_move<std::execution::parallel_policy, int*, int*, int*>);
31+
32+
template <class Iter1, class Iter2>
33+
struct TestInt {
34+
template <class Policy>
35+
void operator()(Policy&& policy) {
36+
// simple test
37+
for (const int size : {0, 1, 2, 100, 350}) {
38+
std::vector<int> a(size);
39+
for (int i = 0; i != size; ++i)
40+
a[i] = i + 1;
41+
42+
std::vector<int> out(std::size(a));
43+
decltype(auto) ret =
44+
std::move(policy, Iter1(std::data(a)), Iter1(std::data(a) + std::size(a)), Iter2(std::data(out)));
45+
static_assert(std::is_same_v<decltype(ret), Iter2>);
46+
assert(base(ret) == std::data(out) + std::size(out));
47+
for (int i = 0; i != size; ++i)
48+
assert(out[i] == i + 1);
49+
}
50+
}
51+
};
52+
53+
struct MovedToTester {
54+
bool moved_to = false;
55+
MovedToTester() = default;
56+
MovedToTester(MovedToTester&&) {}
57+
MovedToTester& operator=(MovedToTester&&) {
58+
assert(!moved_to);
59+
moved_to = true;
60+
return *this;
61+
}
62+
~MovedToTester() = default;
63+
};
64+
65+
template <class Iter1, class Iter2>
66+
struct TestNonTrivial {
67+
template <class Policy>
68+
void operator()(Policy&& policy) {
69+
// simple test
70+
for (const int size : {0, 1, 2, 100, 350}) {
71+
std::vector<MovedToTester> a(size);
72+
73+
std::vector<MovedToTester> out(std::size(a));
74+
auto ret = std::move(policy, Iter1(std::data(a)), Iter1(std::data(a) + std::size(a)), Iter2(std::data(out)));
75+
assert(base(ret) == std::data(out) + std::size(out));
76+
assert(std::all_of(std::begin(out), std::end(out), [](MovedToTester& t) { return t.moved_to; }));
77+
assert(std::none_of(std::begin(a), std::end(a), [](MovedToTester& t) { return t.moved_to; }));
78+
}
79+
}
80+
};
81+
82+
int main(int, char**) {
83+
types::for_each(types::forward_iterator_list<int*>{}, types::apply_type_identity{[](auto v) {
84+
using Iter = typename decltype(v)::type;
85+
types::for_each(
86+
types::forward_iterator_list<int*>{},
87+
TestIteratorWithPolicies< types::partial_instantiation<TestInt, Iter>::template apply>{});
88+
}});
89+
90+
types::for_each(
91+
types::forward_iterator_list<MovedToTester*>{}, types::apply_type_identity{[](auto v) {
92+
using Iter = typename decltype(v)::type;
93+
types::for_each(
94+
types::forward_iterator_list<MovedToTester*>{},
95+
TestIteratorWithPolicies< types::partial_instantiation<TestNonTrivial, Iter>::template apply>{});
96+
}});
97+
98+
return 0;
99+
}

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 478279
19+
#define LLVM_MAIN_REVISION 478281
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/utils/gn/secondary/libcxx/include/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ if (current_toolchain == default_toolchain) {
168168
"__algorithm/pstl_generate.h",
169169
"__algorithm/pstl_is_partitioned.h",
170170
"__algorithm/pstl_merge.h",
171+
"__algorithm/pstl_move.h",
171172
"__algorithm/pstl_replace.h",
172173
"__algorithm/pstl_sort.h",
173174
"__algorithm/pstl_stable_sort.h",

0 commit comments

Comments
 (0)