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