1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef _PSTL_EXECUTION_IMPL_H 11 #define _PSTL_EXECUTION_IMPL_H 12 13 #include <iterator> 14 #include <type_traits> 15 16 #include "pstl_config.h" 17 #include "execution_defs.h" 18 19 _PSTL_HIDE_FROM_ABI_PUSH 20 21 namespace __pstl 22 { 23 namespace __internal 24 { 25 26 using namespace __pstl::execution; 27 28 template <typename _IteratorType> 29 struct __is_random_access_iterator 30 : std::is_same<typename std::iterator_traits<_IteratorType>::iterator_category, 31 std::random_access_iterator_tag> 32 { 33 }; 34 35 template <typename Policy> 36 struct __policy_traits 37 { 38 }; 39 40 template <> 41 struct __policy_traits<sequenced_policy> 42 { 43 typedef std::false_type __allow_parallel; 44 typedef std::false_type __allow_unsequenced; 45 typedef std::false_type __allow_vector; 46 }; 47 48 template <> 49 struct __policy_traits<unsequenced_policy> 50 { 51 typedef std::false_type __allow_parallel; 52 typedef std::true_type __allow_unsequenced; 53 typedef std::true_type __allow_vector; 54 }; 55 56 template <> 57 struct __policy_traits<parallel_policy> 58 { 59 typedef std::true_type __allow_parallel; 60 typedef std::false_type __allow_unsequenced; 61 typedef std::false_type __allow_vector; 62 }; 63 64 template <> 65 struct __policy_traits<parallel_unsequenced_policy> 66 { 67 typedef std::true_type __allow_parallel; 68 typedef std::true_type __allow_unsequenced; 69 typedef std::true_type __allow_vector; 70 }; 71 72 template <typename _ExecutionPolicy> 73 using __allow_vector = 74 typename __internal::__policy_traits<typename std::decay<_ExecutionPolicy>::type>::__allow_vector; 75 76 template <typename _ExecutionPolicy> 77 using __allow_unsequenced = 78 typename __internal::__policy_traits<typename std::decay<_ExecutionPolicy>::type>::__allow_unsequenced; 79 80 template <typename _ExecutionPolicy> 81 using __allow_parallel = 82 typename __internal::__policy_traits<typename std::decay<_ExecutionPolicy>::type>::__allow_parallel; 83 84 template <typename _ExecutionPolicy, typename... _IteratorTypes> 85 typename std::conjunction<__allow_vector<_ExecutionPolicy>, 86 __is_random_access_iterator<_IteratorTypes>...>::type 87 __is_vectorization_preferred(_ExecutionPolicy&&) 88 { 89 return {}; 90 } 91 92 template <typename _ExecutionPolicy, typename... _IteratorTypes> 93 typename std::conjunction<__allow_parallel<_ExecutionPolicy>, 94 __is_random_access_iterator<_IteratorTypes>...>::type 95 __is_parallelization_preferred(_ExecutionPolicy&&) 96 { 97 return {}; 98 } 99 100 } // namespace __internal 101 } // namespace __pstl 102 103 _PSTL_HIDE_FROM_ABI_POP 104 105 #endif /* _PSTL_EXECUTION_IMPL_H */ 106