1 | //===- OMPConstants.h - OpenMP related constants and helpers ------ C++ -*-===// |
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 | /// \file |
9 | /// |
10 | /// This file defines constans and helpers used when dealing with OpenMP. |
11 | /// |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #ifndef LLVM_FRONTEND_OPENMP_OMPCONSTANTS_H |
15 | #define LLVM_FRONTEND_OPENMP_OMPCONSTANTS_H |
16 | |
17 | #include "llvm/ADT/BitmaskEnum.h" |
18 | #include "llvm/ADT/StringRef.h" |
19 | #include "llvm/Frontend/OpenMP/OMP.h" |
20 | |
21 | namespace llvm { |
22 | namespace omp { |
23 | LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE(); |
24 | |
25 | /// IDs for all Internal Control Variables (ICVs). |
26 | enum class InternalControlVar { |
27 | #define ICV_DATA_ENV(Enum, ...) Enum, |
28 | #include "llvm/Frontend/OpenMP/OMPKinds.def" |
29 | }; |
30 | |
31 | #define ICV_DATA_ENV(Enum, ...) \ |
32 | constexpr auto Enum = omp::InternalControlVar::Enum; |
33 | #include "llvm/Frontend/OpenMP/OMPKinds.def" |
34 | |
35 | enum class ICVInitValue { |
36 | #define ICV_INIT_VALUE(Enum, Name) Enum, |
37 | #include "llvm/Frontend/OpenMP/OMPKinds.def" |
38 | }; |
39 | |
40 | #define ICV_INIT_VALUE(Enum, Name) \ |
41 | constexpr auto Enum = omp::ICVInitValue::Enum; |
42 | #include "llvm/Frontend/OpenMP/OMPKinds.def" |
43 | |
44 | /// IDs for all omp runtime library (RTL) functions. |
45 | enum class RuntimeFunction { |
46 | #define OMP_RTL(Enum, ...) Enum, |
47 | #include "llvm/Frontend/OpenMP/OMPKinds.def" |
48 | }; |
49 | |
50 | #define OMP_RTL(Enum, ...) constexpr auto Enum = omp::RuntimeFunction::Enum; |
51 | #include "llvm/Frontend/OpenMP/OMPKinds.def" |
52 | |
53 | /// IDs for the different default kinds. |
54 | enum class DefaultKind { |
55 | #define OMP_DEFAULT_KIND(Enum, Str) Enum, |
56 | #include "llvm/Frontend/OpenMP/OMPKinds.def" |
57 | }; |
58 | |
59 | #define OMP_DEFAULT_KIND(Enum, ...) \ |
60 | constexpr auto Enum = omp::DefaultKind::Enum; |
61 | #include "llvm/Frontend/OpenMP/OMPKinds.def" |
62 | |
63 | /// IDs for all omp runtime library ident_t flag encodings (see |
64 | /// their defintion in openmp/runtime/src/kmp.h). |
65 | enum class IdentFlag { |
66 | #define OMP_IDENT_FLAG(Enum, Str, Value) Enum = Value, |
67 | #include "llvm/Frontend/OpenMP/OMPKinds.def" |
68 | LLVM_MARK_AS_BITMASK_ENUM(0x7FFFFFFF) |
69 | }; |
70 | |
71 | #define OMP_IDENT_FLAG(Enum, ...) constexpr auto Enum = omp::IdentFlag::Enum; |
72 | #include "llvm/Frontend/OpenMP/OMPKinds.def" |
73 | |
74 | // Version of the kernel argument format used by the omp runtime. |
75 | #define OMP_KERNEL_ARG_VERSION 3 |
76 | |
77 | // Minimum version of the compiler that generates a kernel dynamic pointer. |
78 | #define OMP_KERNEL_ARG_MIN_VERSION_WITH_DYN_PTR 3 |
79 | |
80 | /// \note This needs to be kept in sync with kmp.h enum sched_type. |
81 | /// Todo: Update kmp.h to include this file, and remove the enums in kmp.h |
82 | enum class OMPScheduleType { |
83 | // For typed comparisons, not a valid schedule |
84 | None = 0, |
85 | |
86 | // Schedule algorithms |
87 | BaseStaticChunked = 1, |
88 | BaseStatic = 2, |
89 | BaseDynamicChunked = 3, |
90 | BaseGuidedChunked = 4, |
91 | BaseRuntime = 5, |
92 | BaseAuto = 6, |
93 | BaseTrapezoidal = 7, |
94 | BaseGreedy = 8, |
95 | BaseBalanced = 9, |
96 | BaseGuidedIterativeChunked = 10, |
97 | BaseGuidedAnalyticalChunked = 11, |
98 | BaseSteal = 12, |
99 | |
100 | // with chunk adjustment (e.g., simd) |
101 | BaseStaticBalancedChunked = 13, |
102 | BaseGuidedSimd = 14, |
103 | BaseRuntimeSimd = 15, |
104 | |
105 | // static schedules algorithims for distribute |
106 | BaseDistributeChunked = 27, |
107 | BaseDistribute = 28, |
108 | |
109 | // Modifier flags to be combined with schedule algorithms |
110 | ModifierUnordered = (1 << 5), |
111 | ModifierOrdered = (1 << 6), |
112 | ModifierNomerge = (1 << 7), |
113 | ModifierMonotonic = (1 << 29), |
114 | ModifierNonmonotonic = (1 << 30), |
115 | |
116 | // Masks combining multiple flags |
117 | OrderingMask = ModifierUnordered | ModifierOrdered | ModifierNomerge, |
118 | MonotonicityMask = ModifierMonotonic | ModifierNonmonotonic, |
119 | ModifierMask = OrderingMask | MonotonicityMask, |
120 | |
121 | // valid schedule type values, without monotonicity flags |
122 | UnorderedStaticChunked = BaseStaticChunked | ModifierUnordered, // 33 |
123 | UnorderedStatic = BaseStatic | ModifierUnordered, // 34 |
124 | UnorderedDynamicChunked = BaseDynamicChunked | ModifierUnordered, // 35 |
125 | UnorderedGuidedChunked = BaseGuidedChunked | ModifierUnordered, // 36 |
126 | UnorderedRuntime = BaseRuntime | ModifierUnordered, // 37 |
127 | UnorderedAuto = BaseAuto | ModifierUnordered, // 38 |
128 | UnorderedTrapezoidal = BaseTrapezoidal | ModifierUnordered, // 39 |
129 | UnorderedGreedy = BaseGreedy | ModifierUnordered, // 40 |
130 | UnorderedBalanced = BaseBalanced | ModifierUnordered, // 41 |
131 | UnorderedGuidedIterativeChunked = |
132 | BaseGuidedIterativeChunked | ModifierUnordered, // 42 |
133 | UnorderedGuidedAnalyticalChunked = |
134 | BaseGuidedAnalyticalChunked | ModifierUnordered, // 43 |
135 | UnorderedSteal = BaseSteal | ModifierUnordered, // 44 |
136 | |
137 | UnorderedStaticBalancedChunked = |
138 | BaseStaticBalancedChunked | ModifierUnordered, // 45 |
139 | UnorderedGuidedSimd = BaseGuidedSimd | ModifierUnordered, // 46 |
140 | UnorderedRuntimeSimd = BaseRuntimeSimd | ModifierUnordered, // 47 |
141 | |
142 | OrderedStaticChunked = BaseStaticChunked | ModifierOrdered, // 65 |
143 | OrderedStatic = BaseStatic | ModifierOrdered, // 66 |
144 | OrderedDynamicChunked = BaseDynamicChunked | ModifierOrdered, // 67 |
145 | OrderedGuidedChunked = BaseGuidedChunked | ModifierOrdered, // 68 |
146 | OrderedRuntime = BaseRuntime | ModifierOrdered, // 69 |
147 | OrderedAuto = BaseAuto | ModifierOrdered, // 70 |
148 | OrderdTrapezoidal = BaseTrapezoidal | ModifierOrdered, // 71 |
149 | |
150 | OrderedDistributeChunked = BaseDistributeChunked | ModifierOrdered, // 91 |
151 | OrderedDistribute = BaseDistribute | ModifierOrdered, // 92 |
152 | |
153 | NomergeUnorderedStaticChunked = |
154 | BaseStaticChunked | ModifierUnordered | ModifierNomerge, // 161 |
155 | NomergeUnorderedStatic = |
156 | BaseStatic | ModifierUnordered | ModifierNomerge, // 162 |
157 | NomergeUnorderedDynamicChunked = |
158 | BaseDynamicChunked | ModifierUnordered | ModifierNomerge, // 163 |
159 | NomergeUnorderedGuidedChunked = |
160 | BaseGuidedChunked | ModifierUnordered | ModifierNomerge, // 164 |
161 | NomergeUnorderedRuntime = |
162 | BaseRuntime | ModifierUnordered | ModifierNomerge, // 165 |
163 | NomergeUnorderedAuto = BaseAuto | ModifierUnordered | ModifierNomerge, // 166 |
164 | NomergeUnorderedTrapezoidal = |
165 | BaseTrapezoidal | ModifierUnordered | ModifierNomerge, // 167 |
166 | NomergeUnorderedGreedy = |
167 | BaseGreedy | ModifierUnordered | ModifierNomerge, // 168 |
168 | NomergeUnorderedBalanced = |
169 | BaseBalanced | ModifierUnordered | ModifierNomerge, // 169 |
170 | NomergeUnorderedGuidedIterativeChunked = |
171 | BaseGuidedIterativeChunked | ModifierUnordered | ModifierNomerge, // 170 |
172 | NomergeUnorderedGuidedAnalyticalChunked = |
173 | BaseGuidedAnalyticalChunked | ModifierUnordered | ModifierNomerge, // 171 |
174 | NomergeUnorderedSteal = |
175 | BaseSteal | ModifierUnordered | ModifierNomerge, // 172 |
176 | |
177 | NomergeOrderedStaticChunked = |
178 | BaseStaticChunked | ModifierOrdered | ModifierNomerge, // 193 |
179 | NomergeOrderedStatic = BaseStatic | ModifierOrdered | ModifierNomerge, // 194 |
180 | NomergeOrderedDynamicChunked = |
181 | BaseDynamicChunked | ModifierOrdered | ModifierNomerge, // 195 |
182 | NomergeOrderedGuidedChunked = |
183 | BaseGuidedChunked | ModifierOrdered | ModifierNomerge, // 196 |
184 | NomergeOrderedRuntime = |
185 | BaseRuntime | ModifierOrdered | ModifierNomerge, // 197 |
186 | NomergeOrderedAuto = BaseAuto | ModifierOrdered | ModifierNomerge, // 198 |
187 | NomergeOrderedTrapezoidal = |
188 | BaseTrapezoidal | ModifierOrdered | ModifierNomerge, // 199 |
189 | |
190 | LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ ModifierMask) |
191 | }; |
192 | |
193 | /// Values for bit flags used to specify the mapping type for |
194 | /// offloading. |
195 | enum class OpenMPOffloadMappingFlags : uint64_t { |
196 | /// No flags |
197 | OMP_MAP_NONE = 0x0, |
198 | /// Allocate memory on the device and move data from host to device. |
199 | OMP_MAP_TO = 0x01, |
200 | /// Allocate memory on the device and move data from device to host. |
201 | OMP_MAP_FROM = 0x02, |
202 | /// Always perform the requested mapping action on the element, even |
203 | /// if it was already mapped before. |
204 | OMP_MAP_ALWAYS = 0x04, |
205 | /// Delete the element from the device environment, ignoring the |
206 | /// current reference count associated with the element. |
207 | OMP_MAP_DELETE = 0x08, |
208 | /// The element being mapped is a pointer-pointee pair; both the |
209 | /// pointer and the pointee should be mapped. |
210 | OMP_MAP_PTR_AND_OBJ = 0x10, |
211 | /// This flags signals that the base address of an entry should be |
212 | /// passed to the target kernel as an argument. |
213 | OMP_MAP_TARGET_PARAM = 0x20, |
214 | /// Signal that the runtime library has to return the device pointer |
215 | /// in the current position for the data being mapped. Used when we have the |
216 | /// use_device_ptr or use_device_addr clause. |
217 | OMP_MAP_RETURN_PARAM = 0x40, |
218 | /// This flag signals that the reference being passed is a pointer to |
219 | /// private data. |
220 | OMP_MAP_PRIVATE = 0x80, |
221 | /// Pass the element to the device by value. |
222 | OMP_MAP_LITERAL = 0x100, |
223 | /// Implicit map |
224 | OMP_MAP_IMPLICIT = 0x200, |
225 | /// Close is a hint to the runtime to allocate memory close to |
226 | /// the target device. |
227 | OMP_MAP_CLOSE = 0x400, |
228 | /// 0x800 is reserved for compatibility with XLC. |
229 | /// Produce a runtime error if the data is not already allocated. |
230 | OMP_MAP_PRESENT = 0x1000, |
231 | // Increment and decrement a separate reference counter so that the data |
232 | // cannot be unmapped within the associated region. Thus, this flag is |
233 | // intended to be used on 'target' and 'target data' directives because they |
234 | // are inherently structured. It is not intended to be used on 'target |
235 | // enter data' and 'target exit data' directives because they are inherently |
236 | // dynamic. |
237 | // This is an OpenMP extension for the sake of OpenACC support. |
238 | OMP_MAP_OMPX_HOLD = 0x2000, |
239 | /// Signal that the runtime library should use args as an array of |
240 | /// descriptor_dim pointers and use args_size as dims. Used when we have |
241 | /// non-contiguous list items in target update directive |
242 | OMP_MAP_NON_CONTIG = 0x100000000000, |
243 | /// The 16 MSBs of the flags indicate whether the entry is member of some |
244 | /// struct/class. |
245 | OMP_MAP_MEMBER_OF = 0xffff000000000000, |
246 | LLVM_MARK_AS_BITMASK_ENUM(/* LargestFlag = */ OMP_MAP_MEMBER_OF) |
247 | }; |
248 | |
249 | enum OpenMPOffloadingReservedDeviceIDs { |
250 | /// Device ID if the device was not defined, runtime should get it |
251 | /// from environment variables in the spec. |
252 | OMP_DEVICEID_UNDEF = -1 |
253 | }; |
254 | |
255 | enum class AddressSpace : unsigned { |
256 | Generic = 0, |
257 | Global = 1, |
258 | Shared = 3, |
259 | Constant = 4, |
260 | Local = 5, |
261 | }; |
262 | |
263 | /// \note This needs to be kept in sync with interop.h enum kmp_interop_type_t.: |
264 | enum class OMPInteropType { Unknown, Target, TargetSync }; |
265 | |
266 | /// Atomic compare operations. Currently OpenMP only supports ==, >, and <. |
267 | enum class OMPAtomicCompareOp : unsigned { EQ, MIN, MAX }; |
268 | |
269 | /// Fields ids in kmp_depend_info record. |
270 | enum class RTLDependInfoFields { BaseAddr, Len, Flags }; |
271 | |
272 | /// Dependence kind for RTL. |
273 | enum class RTLDependenceKindTy { |
274 | DepUnknown = 0x0, |
275 | DepIn = 0x01, |
276 | DepInOut = 0x3, |
277 | DepMutexInOutSet = 0x4, |
278 | DepInOutSet = 0x8, |
279 | DepOmpAllMem = 0x80, |
280 | }; |
281 | |
282 | /// A type of worksharing loop construct |
283 | enum class WorksharingLoopType { |
284 | // Worksharing `for`-loop |
285 | ForStaticLoop, |
286 | // Worksharing `distrbute`-loop |
287 | DistributeStaticLoop, |
288 | // Worksharing `distrbute parallel for`-loop |
289 | DistributeForStaticLoop |
290 | }; |
291 | |
292 | } // end namespace omp |
293 | |
294 | } // end namespace llvm |
295 | |
296 | #include "OMPDeviceConstants.h" |
297 | |
298 | #endif // LLVM_FRONTEND_OPENMP_OMPCONSTANTS_H |
299 | |