[libcxx-commits] [PATCH] D62719: A hot fix for exclusive_scan

Mikhail Dvorskiy via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jun 13 04:56:34 PDT 2019


MikeDvorskiy updated this revision to Diff 204487.
MikeDvorskiy added a comment.

1. The  test was improved.
2. Minor changes in PSTL code. It needs for possibility of coverage that case in "negative test scenario".


Repository:
  rPSTL pstl

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62719/new/

https://reviews.llvm.org/D62719

Files:
  include/pstl/internal/glue_numeric_defs.h
  include/pstl/internal/glue_numeric_impl.h
  test/CMakeLists.txt
  test/std/numerics/numeric.ops/scan.fail.cpp


Index: test/std/numerics/numeric.ops/scan.fail.cpp
===================================================================
--- /dev/null
+++ test/std/numerics/numeric.ops/scan.fail.cpp
@@ -0,0 +1,29 @@
+// -*- C++ -*-
+//===-- scan.pass.cpp -----------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include <execution>
+#include <numeric>
+
+struct CustomPolicy {
+
+constexpr std::false_type __allow_vector() { return std::false_type{}; }
+constexpr std::false_type __allow_parallel() { return std::false_type{}; }
+
+} policy;
+
+int32_t
+main()
+{    
+    int *first = nullptr, *last=nullptr, *result = nullptr;
+
+    std::exclusive_scan(policy, first, last, result, 0);
+    std::exclusive_scan(policy, first, last, result, 0, std::plus<int>());
+
+    return 0;
+}
Index: test/CMakeLists.txt
===================================================================
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -23,7 +23,7 @@
 target_link_libraries(test_stdlib INTERFACE pstl::ParallelSTL)
 target_compile_options(test_stdlib INTERFACE -Wno-gnu-include-next)
 
-file(GLOB_RECURSE UNIT_TESTS "*.pass.cpp")
+file(GLOB_RECURSE UNIT_TESTS "*.pass.cpp" "*.fail.cpp")
 foreach(_file IN LISTS UNIT_TESTS)
     file(RELATIVE_PATH _target "${CMAKE_CURRENT_SOURCE_DIR}" "${_file}")
     string(REPLACE ".cpp" "" _target "${_target}")
Index: include/pstl/internal/glue_numeric_impl.h
===================================================================
--- include/pstl/internal/glue_numeric_impl.h
+++ include/pstl/internal/glue_numeric_impl.h
@@ -96,17 +96,25 @@
 exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                _ForwardIterator2 __result, _Tp __init)
 {
-    return transform_exclusive_scan(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result, __init,
-                                    std::plus<_Tp>(), __pstl::__internal::__no_op());
+    using namespace __pstl;
+    return __internal::__pattern_transform_scan(
+        std::forward<_ExecutionPolicy>(__exec), __first, __last, __result, __pstl::__internal::__no_op(), __init,
+        std::plus<_Tp>(), /*inclusive=*/std::false_type(),
+        __internal::__is_vectorization_preferred<_ExecutionPolicy, _ForwardIterator1, _ForwardIterator2>(__exec),
+        __internal::__is_parallelization_preferred<_ExecutionPolicy, _ForwardIterator1, _ForwardIterator2>(__exec));
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation>
-_ForwardIterator2
+__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                _ForwardIterator2 __result, _Tp __init, _BinaryOperation __binary_op)
 {
-    return transform_exclusive_scan(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result, __init,
-                                    __binary_op, __pstl::__internal::__no_op());
+    using namespace __pstl;
+    return __internal::__pattern_transform_scan(
+        std::forward<_ExecutionPolicy>(__exec), __first, __last, __result, __pstl::__internal::__no_op(), __init,
+        __binary_op, /*inclusive=*/std::false_type(),
+        __internal::__is_vectorization_preferred<_ExecutionPolicy, _ForwardIterator1, _ForwardIterator2>(__exec),
+        __internal::__is_parallelization_preferred<_ExecutionPolicy, _ForwardIterator1, _ForwardIterator2>(__exec));
 }
 
 // [inclusive.scan]
Index: include/pstl/internal/glue_numeric_defs.h
===================================================================
--- include/pstl/internal/glue_numeric_defs.h
+++ include/pstl/internal/glue_numeric_defs.h
@@ -57,7 +57,7 @@
                _ForwardIterator2 __result, _Tp __init);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation>
-_ForwardIterator2
+__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                _ForwardIterator2 __result, _Tp __init, _BinaryOperation __binary_op);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62719.204487.patch
Type: text/x-patch
Size: 4511 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190613/f55ebe62/attachment.bin>


More information about the libcxx-commits mailing list