xref: /llvm-project/pstl/include/pstl/internal/pstl_config.h (revision 603c286334b07f568d39f6706c848f576914f323)
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_CONFIG_H
11 #define _PSTL_CONFIG_H
12 
13 #include <__pstl_config_site>
14 
15 // The version is XYYZ, where X is major, YY is minor, and Z is patch (i.e. X.YY.Z)
16 #define _PSTL_VERSION 17000
17 #define _PSTL_VERSION_MAJOR (_PSTL_VERSION / 1000)
18 #define _PSTL_VERSION_MINOR ((_PSTL_VERSION % 1000) / 10)
19 #define _PSTL_VERSION_PATCH (_PSTL_VERSION % 10)
20 
21 #if !defined(_PSTL_PAR_BACKEND_SERIAL) && !defined(_PSTL_PAR_BACKEND_TBB) && !defined(_PSTL_PAR_BACKEND_OPENMP)
22 #    error "A parallel backend must be specified"
23 #endif
24 
25 // Check the user-defined macro for warnings
26 #if defined(PSTL_USAGE_WARNINGS)
27 #    define _PSTL_USAGE_WARNINGS
28 #endif
29 
30 #if defined(_LIBCPP_VERSION)
31 #    include <__assert>
32 #    define _PSTL_ASSERT(pred) _LIBCPP_ASSERT(pred, "")
33 #elif defined(__GLIBCXX__)
34 #    define _PSTL_ASSERT(pred) __glibcxx_assert(pred)
35 #else
36 #    include <cassert>
37 #    define _PSTL_ASSERT(pred) (assert((pred)))
38 #endif
39 
40 // Portability "#pragma" definition
41 #ifdef _MSC_VER
42 #    define _PSTL_PRAGMA(x) __pragma(x)
43 #else
44 #    define _PSTL_PRAGMA(x) _Pragma(#    x)
45 #endif
46 
47 #define _PSTL_STRING_AUX(x) #x
48 #define _PSTL_STRING(x) _PSTL_STRING_AUX(x)
49 #define _PSTL_STRING_CONCAT(x, y) x #y
50 
51 #ifdef _PSTL_HIDE_FROM_ABI_PER_TU
52 #    define _PSTL_HIDE_FROM_ABI_PUSH                                                                                   \
53         _Pragma("clang attribute push(__attribute__((internal_linkage)), apply_to=any(function,record))")
54 #    define _PSTL_HIDE_FROM_ABI_POP _Pragma("clang attribute pop")
55 #else
56 #    define _PSTL_HIDE_FROM_ABI_PUSH /* nothing */
57 #    define _PSTL_HIDE_FROM_ABI_POP  /* nothing */
58 #endif
59 
60 // note that when ICC or Clang is in use, _PSTL_GCC_VERSION might not fully match
61 // the actual GCC version on the system.
62 #define _PSTL_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
63 
64 #if defined(__clang__)
65 // according to clang documentation, version can be vendor specific
66 #    define _PSTL_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
67 #endif
68 
69 // Enable SIMD for compilers that support OpenMP 4.0
70 #if (defined(_OPENMP) && _OPENMP >= 201307) || \
71     (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1600) || \
72     (!defined(__INTEL_COMPILER) && _PSTL_GCC_VERSION >= 40900) || \
73     defined(__clang__)
74 #    define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd)
75 #    define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd)
76 #    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM))
77 #elif !defined(_MSC_VER) //#pragma simd
78 #    define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(simd)
79 #    define _PSTL_PRAGMA_DECLARE_SIMD
80 #    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(simd reduction(PRM))
81 #else //no simd
82 #    define _PSTL_PRAGMA_SIMD
83 #    define _PSTL_PRAGMA_DECLARE_SIMD
84 #    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM)
85 #endif //Enable SIMD
86 
87 #if defined(__INTEL_COMPILER)
88 #    define _PSTL_PRAGMA_FORCEINLINE _PSTL_PRAGMA(forceinline)
89 #else
90 #    define _PSTL_PRAGMA_FORCEINLINE
91 #endif
92 
93 #if defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1900
94 #    define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM))
95 #    define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM))
96 #    define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM))
97 #else
98 #    define _PSTL_PRAGMA_SIMD_SCAN(PRM)
99 #    define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
100 #    define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
101 #endif
102 
103 // Should be defined to 1 for environments with a vendor implementation of C++17 execution policies
104 #define _PSTL_CPP17_EXECUTION_POLICIES_PRESENT (_MSC_VER >= 1912 && _MSVC_LANG >= 201703L) ||                          \
105     (_GLIBCXX_RELEASE >= 9 && __GLIBCXX__ >= 20190503 && __cplusplus >= 201703L)
106 
107 #if (defined(_MSC_VER) && _MSC_VER >= 1900) || \
108     __cplusplus >= 201300L || \
109     __cpp_lib_robust_nonmodifying_seq_ops == 201304
110 #   define _PSTL_CPP14_2RANGE_MISMATCH_EQUAL_PRESENT
111 #endif
112 #if (defined(_MSC_VER) && _MSC_VER >= 1900) || \
113     __cplusplus >= 201402L || \
114     __cpp_lib_make_reverse_iterator == 201402
115 #   define _PSTL_CPP14_MAKE_REVERSE_ITERATOR_PRESENT
116 #endif
117 #if (defined(_MSC_VER) && _MSC_VER >= 1900) || __cplusplus >= 201402L
118 #   define _PSTL_CPP14_INTEGER_SEQUENCE_PRESENT
119 #endif
120 #if (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1700) || \
121     (defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023918) || \
122     __cplusplus >= 201402L
123 #   define _PSTL_CPP14_VARIABLE_TEMPLATES_PRESENT
124 #endif
125 
126 #if defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1800
127 #   define _PSTL_EARLYEXIT_PRESENT
128 #   define _PSTL_MONOTONIC_PRESENT
129 #endif
130 
131 #if (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1900) || \
132     (!defined(__INTEL_COMPILER) && _PSTL_GCC_VERSION >= 40900) || \
133     (defined(_OPENMP) && _OPENMP >= 201307)
134 #    define _PSTL_UDR_PRESENT
135 #endif
136 
137 #if defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1900 && __INTEL_COMPILER_BUILD_DATE >= 20180626
138 #   define _PSTL_UDS_PRESENT
139 #endif
140 
141 #if defined(_PSTL_EARLYEXIT_PRESENT)
142 #    define _PSTL_PRAGMA_SIMD_EARLYEXIT _PSTL_PRAGMA(omp simd early_exit)
143 #else
144 #    define _PSTL_PRAGMA_SIMD_EARLYEXIT
145 #endif
146 
147 #if defined(_PSTL_MONOTONIC_PRESENT)
148 #    define _PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(PRM) _PSTL_PRAGMA(omp ordered simd monotonic(PRM))
149 #    define _PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(PRM1, PRM2) _PSTL_PRAGMA(omp ordered simd monotonic(PRM1, PRM2))
150 #else
151 #    define _PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(PRM)
152 #    define _PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(PRM1, PRM2)
153 #endif
154 
155 // Declaration of reduction functor, where
156 // NAME - the name of the functor
157 // OP - type of the callable object with the reduction operation
158 // omp_in - refers to the local partial result
159 // omp_out - refers to the final value of the combiner operator
160 // omp_priv - refers to the private copy of the initial value
161 // omp_orig - refers to the original variable to be reduced
162 #define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)                                                                       \
163     _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig))
164 
165 #if defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1600
166 #    define _PSTL_PRAGMA_VECTOR_UNALIGNED _PSTL_PRAGMA(vector unaligned)
167 #else
168 #    define _PSTL_PRAGMA_VECTOR_UNALIGNED
169 #endif
170 
171 // Check the user-defined macro to use non-temporal stores
172 #if defined(PSTL_USE_NONTEMPORAL_STORES) && (__INTEL_COMPILER >= 1600)
173 #    define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED _PSTL_PRAGMA(vector nontemporal)
174 #else
175 #    define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
176 #endif
177 
178 #if defined(_MSC_VER) || defined(__INTEL_COMPILER) // the preprocessors don't type a message location
179 #    define _PSTL_PRAGMA_LOCATION __FILE__ ":" _PSTL_STRING(__LINE__) ": [Parallel STL message]: "
180 #else
181 #    define _PSTL_PRAGMA_LOCATION " [Parallel STL message]: "
182 #endif
183 
184 #define _PSTL_PRAGMA_MESSAGE_IMPL(x) _PSTL_PRAGMA(message(_PSTL_STRING_CONCAT(_PSTL_PRAGMA_LOCATION, x)))
185 
186 #if defined(_PSTL_USAGE_WARNINGS)
187 #    define _PSTL_PRAGMA_MESSAGE(x) _PSTL_PRAGMA_MESSAGE_IMPL(x)
188 #    define _PSTL_PRAGMA_MESSAGE_POLICIES(x) _PSTL_PRAGMA_MESSAGE_IMPL(x)
189 #else
190 #    define _PSTL_PRAGMA_MESSAGE(x)
191 #    define _PSTL_PRAGMA_MESSAGE_POLICIES(x)
192 #endif
193 
194 // broken macros
195 #if (defined(__GLIBCXX__) && __GLIBCXX__ < 20150716) || \
196     (defined(_MSC_VER) && _MSC_VER < 1800)
197 #   define _PSTL_CPP11_STD_ROTATE_BROKEN
198 #endif
199 
200 #if defined(__INTEL_COMPILER) && __INTEL_COMPILER == 1800
201 #   define _PSTL_ICC_18_OMP_SIMD_BROKEN
202 #endif
203 
204 #endif /* _PSTL_CONFIG_H */
205