xref: /llvm-project/clang/include/clang/Basic/OpenMPKinds.h (revision ad38e24eb74e97148faec97c4f843b87768b6e9b)
1 //===--- OpenMPKinds.h - OpenMP enums ---------------------------*- 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 ///
9 /// \file
10 /// Defines some OpenMP-specific enums and functions.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_BASIC_OPENMPKINDS_H
15 #define LLVM_CLANG_BASIC_OPENMPKINDS_H
16 
17 #include "clang/Basic/LangOptions.h"
18 #include "llvm/ADT/Sequence.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Frontend/OpenMP/OMPConstants.h"
21 
22 namespace clang {
23 
24 /// OpenMP directives.
25 using OpenMPDirectiveKind = llvm::omp::Directive;
26 
27 /// OpenMP clauses.
28 using OpenMPClauseKind = llvm::omp::Clause;
29 
30 /// OpenMP attributes for 'schedule' clause.
31 enum OpenMPScheduleClauseKind {
32 #define OPENMP_SCHEDULE_KIND(Name) \
33   OMPC_SCHEDULE_##Name,
34 #include "clang/Basic/OpenMPKinds.def"
35   OMPC_SCHEDULE_unknown
36 };
37 
38 /// OpenMP modifiers for 'schedule' clause.
39 enum OpenMPScheduleClauseModifier {
40   OMPC_SCHEDULE_MODIFIER_unknown = OMPC_SCHEDULE_unknown,
41 #define OPENMP_SCHEDULE_MODIFIER(Name) \
42   OMPC_SCHEDULE_MODIFIER_##Name,
43 #include "clang/Basic/OpenMPKinds.def"
44   OMPC_SCHEDULE_MODIFIER_last
45 };
46 
47 /// OpenMP modifiers for 'device' clause.
48 enum OpenMPDeviceClauseModifier {
49 #define OPENMP_DEVICE_MODIFIER(Name) OMPC_DEVICE_##Name,
50 #include "clang/Basic/OpenMPKinds.def"
51   OMPC_DEVICE_unknown,
52 };
53 
54 /// OpenMP attributes for 'depend' clause.
55 enum OpenMPDependClauseKind {
56 #define OPENMP_DEPEND_KIND(Name) \
57   OMPC_DEPEND_##Name,
58 #include "clang/Basic/OpenMPKinds.def"
59   OMPC_DEPEND_unknown
60 };
61 
62 /// OpenMP attributes for 'linear' clause.
63 enum OpenMPLinearClauseKind {
64 #define OPENMP_LINEAR_KIND(Name) \
65   OMPC_LINEAR_##Name,
66 #include "clang/Basic/OpenMPKinds.def"
67   OMPC_LINEAR_unknown
68 };
69 
70 /// OpenMP mapping kind for 'map' clause.
71 enum OpenMPMapClauseKind {
72 #define OPENMP_MAP_KIND(Name) \
73   OMPC_MAP_##Name,
74 #include "clang/Basic/OpenMPKinds.def"
75   OMPC_MAP_unknown
76 };
77 
78 /// OpenMP modifier kind for 'map' clause.
79 enum OpenMPMapModifierKind {
80   OMPC_MAP_MODIFIER_unknown = OMPC_MAP_unknown,
81 #define OPENMP_MAP_MODIFIER_KIND(Name) \
82   OMPC_MAP_MODIFIER_##Name,
83 #include "clang/Basic/OpenMPKinds.def"
84   OMPC_MAP_MODIFIER_last
85 };
86 
87 /// Number of allowed map-type-modifiers.
88 static constexpr unsigned NumberOfOMPMapClauseModifiers =
89     OMPC_MAP_MODIFIER_last - OMPC_MAP_MODIFIER_unknown - 1;
90 
91 /// OpenMP modifier kind for 'to' or 'from' clause.
92 enum OpenMPMotionModifierKind {
93 #define OPENMP_MOTION_MODIFIER_KIND(Name) \
94   OMPC_MOTION_MODIFIER_##Name,
95 #include "clang/Basic/OpenMPKinds.def"
96   OMPC_MOTION_MODIFIER_unknown
97 };
98 
99 /// Number of allowed motion-modifiers.
100 static constexpr unsigned NumberOfOMPMotionModifiers =
101     OMPC_MOTION_MODIFIER_unknown;
102 
103 /// OpenMP attributes for 'dist_schedule' clause.
104 enum OpenMPDistScheduleClauseKind {
105 #define OPENMP_DIST_SCHEDULE_KIND(Name) OMPC_DIST_SCHEDULE_##Name,
106 #include "clang/Basic/OpenMPKinds.def"
107   OMPC_DIST_SCHEDULE_unknown
108 };
109 
110 /// OpenMP attributes for 'defaultmap' clause.
111 enum OpenMPDefaultmapClauseKind {
112 #define OPENMP_DEFAULTMAP_KIND(Name) \
113   OMPC_DEFAULTMAP_##Name,
114 #include "clang/Basic/OpenMPKinds.def"
115   OMPC_DEFAULTMAP_unknown
116 };
117 
118 /// OpenMP modifiers for 'defaultmap' clause.
119 enum OpenMPDefaultmapClauseModifier {
120   OMPC_DEFAULTMAP_MODIFIER_unknown = OMPC_DEFAULTMAP_unknown,
121 #define OPENMP_DEFAULTMAP_MODIFIER(Name) \
122   OMPC_DEFAULTMAP_MODIFIER_##Name,
123 #include "clang/Basic/OpenMPKinds.def"
124   OMPC_DEFAULTMAP_MODIFIER_last
125 };
126 
127 /// OpenMP attributes for 'atomic_default_mem_order' clause.
128 enum OpenMPAtomicDefaultMemOrderClauseKind {
129 #define OPENMP_ATOMIC_DEFAULT_MEM_ORDER_KIND(Name)  \
130   OMPC_ATOMIC_DEFAULT_MEM_ORDER_##Name,
131 #include "clang/Basic/OpenMPKinds.def"
132   OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown
133 };
134 
135 /// OpenMP attributes for 'at' clause.
136 enum OpenMPAtClauseKind {
137 #define OPENMP_AT_KIND(Name) OMPC_AT_##Name,
138 #include "clang/Basic/OpenMPKinds.def"
139   OMPC_AT_unknown
140 };
141 
142 /// OpenMP attributes for 'severity' clause.
143 enum OpenMPSeverityClauseKind {
144 #define OPENMP_SEVERITY_KIND(Name) OMPC_SEVERITY_##Name,
145 #include "clang/Basic/OpenMPKinds.def"
146   OMPC_SEVERITY_unknown
147 };
148 
149 /// OpenMP device type for 'device_type' clause.
150 enum OpenMPDeviceType {
151 #define OPENMP_DEVICE_TYPE_KIND(Name) \
152   OMPC_DEVICE_TYPE_##Name,
153 #include "clang/Basic/OpenMPKinds.def"
154   OMPC_DEVICE_TYPE_unknown
155 };
156 
157 /// OpenMP 'lastprivate' clause modifier.
158 enum OpenMPLastprivateModifier {
159 #define OPENMP_LASTPRIVATE_KIND(Name) OMPC_LASTPRIVATE_##Name,
160 #include "clang/Basic/OpenMPKinds.def"
161   OMPC_LASTPRIVATE_unknown,
162 };
163 
164 /// OpenMP attributes for 'order' clause.
165 enum OpenMPOrderClauseKind {
166 #define OPENMP_ORDER_KIND(Name) OMPC_ORDER_##Name,
167 #include "clang/Basic/OpenMPKinds.def"
168   OMPC_ORDER_unknown,
169 };
170 
171 /// OpenMP modifiers for 'order' clause.
172 enum OpenMPOrderClauseModifier {
173   OMPC_ORDER_MODIFIER_unknown = OMPC_ORDER_unknown,
174 #define OPENMP_ORDER_MODIFIER(Name) OMPC_ORDER_MODIFIER_##Name,
175 #include "clang/Basic/OpenMPKinds.def"
176   OMPC_ORDER_MODIFIER_last
177 };
178 
179 /// Scheduling data for loop-based OpenMP directives.
180 struct OpenMPScheduleTy final {
181   OpenMPScheduleClauseKind Schedule = OMPC_SCHEDULE_unknown;
182   OpenMPScheduleClauseModifier M1 = OMPC_SCHEDULE_MODIFIER_unknown;
183   OpenMPScheduleClauseModifier M2 = OMPC_SCHEDULE_MODIFIER_unknown;
184 };
185 
186 /// OpenMP modifiers for 'reduction' clause.
187 enum OpenMPReductionClauseModifier {
188 #define OPENMP_REDUCTION_MODIFIER(Name) OMPC_REDUCTION_##Name,
189 #include "clang/Basic/OpenMPKinds.def"
190   OMPC_REDUCTION_unknown,
191 };
192 
193 /// OpenMP adjust-op kinds for 'adjust_args' clause.
194 enum OpenMPAdjustArgsOpKind {
195 #define OPENMP_ADJUST_ARGS_KIND(Name) OMPC_ADJUST_ARGS_##Name,
196 #include "clang/Basic/OpenMPKinds.def"
197   OMPC_ADJUST_ARGS_unknown,
198 };
199 
200 /// OpenMP bindings for the 'bind' clause.
201 enum OpenMPBindClauseKind {
202 #define OPENMP_BIND_KIND(Name) OMPC_BIND_##Name,
203 #include "clang/Basic/OpenMPKinds.def"
204   OMPC_BIND_unknown
205 };
206 
207 enum OpenMPGrainsizeClauseModifier {
208 #define OPENMP_GRAINSIZE_MODIFIER(Name) OMPC_GRAINSIZE_##Name,
209 #include "clang/Basic/OpenMPKinds.def"
210   OMPC_GRAINSIZE_unknown
211 };
212 
213 enum OpenMPNumTasksClauseModifier {
214 #define OPENMP_NUMTASKS_MODIFIER(Name) OMPC_NUMTASKS_##Name,
215 #include "clang/Basic/OpenMPKinds.def"
216   OMPC_NUMTASKS_unknown
217 };
218 
219 /// OpenMP dependence types for 'doacross' clause.
220 enum OpenMPDoacrossClauseModifier {
221 #define OPENMP_DOACROSS_MODIFIER(Name) OMPC_DOACROSS_##Name,
222 #include "clang/Basic/OpenMPKinds.def"
223   OMPC_DOACROSS_unknown
224 };
225 
226 /// OpenMP modifiers for 'allocate' clause.
227 enum OpenMPAllocateClauseModifier {
228 #define OPENMP_ALLOCATE_MODIFIER(Name) OMPC_ALLOCATE_##Name,
229 #include "clang/Basic/OpenMPKinds.def"
230   OMPC_ALLOCATE_unknown
231 };
232 
233 /// Number of allowed allocate-modifiers.
234 static constexpr unsigned NumberOfOMPAllocateClauseModifiers =
235     OMPC_ALLOCATE_unknown;
236 
237 /// Contains 'interop' data for 'append_args' and 'init' clauses.
238 class Expr;
239 struct OMPInteropInfo final {
240   OMPInteropInfo(bool IsTarget = false, bool IsTargetSync = false)
241       : IsTarget(IsTarget), IsTargetSync(IsTargetSync) {}
242   bool IsTarget;
243   bool IsTargetSync;
244   llvm::SmallVector<Expr *, 4> PreferTypes;
245 };
246 
247 unsigned getOpenMPSimpleClauseType(OpenMPClauseKind Kind, llvm::StringRef Str,
248                                    const LangOptions &LangOpts);
249 const char *getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, unsigned Type);
250 
251 /// Checks if the specified directive is a directive with an associated
252 /// loop construct.
253 /// \param DKind Specified directive.
254 /// \return true - the directive is a loop-associated directive like 'omp simd'
255 /// or 'omp for' directive, otherwise - false.
256 bool isOpenMPLoopDirective(OpenMPDirectiveKind DKind);
257 
258 /// Checks if the specified directive is a worksharing directive.
259 /// \param DKind Specified directive.
260 /// \return true - the directive is a worksharing directive like 'omp for',
261 /// otherwise - false.
262 bool isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind);
263 
264 /// Checks if the specified directive is a taskloop directive.
265 /// \param DKind Specified directive.
266 /// \return true - the directive is a worksharing directive like 'omp taskloop',
267 /// otherwise - false.
268 bool isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind);
269 
270 /// Checks if the specified directive is a parallel-kind directive.
271 /// \param DKind Specified directive.
272 /// \return true - the directive is a parallel-like directive like 'omp
273 /// parallel', otherwise - false.
274 bool isOpenMPParallelDirective(OpenMPDirectiveKind DKind);
275 
276 /// Checks if the specified directive is a target code offload directive.
277 /// \param DKind Specified directive.
278 /// \return true - the directive is a target code offload directive like
279 /// 'omp target', 'omp target parallel', 'omp target xxx'
280 /// otherwise - false.
281 bool isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind);
282 
283 /// Checks if the specified directive is a target data offload directive.
284 /// \param DKind Specified directive.
285 /// \return true - the directive is a target data offload directive like
286 /// 'omp target data', 'omp target update', 'omp target enter data',
287 /// 'omp target exit data'
288 /// otherwise - false.
289 bool isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind);
290 
291 /// Checks if the specified composite/combined directive constitutes a teams
292 /// directive in the outermost nest.  For example
293 /// 'omp teams distribute' or 'omp teams distribute parallel for'.
294 /// \param DKind Specified directive.
295 /// \return true - the directive has teams on the outermost nest, otherwise -
296 /// false.
297 bool isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind);
298 
299 /// Checks if the specified directive is a teams-kind directive.  For example,
300 /// 'omp teams distribute' or 'omp target teams'.
301 /// \param DKind Specified directive.
302 /// \return true - the directive is a teams-like directive, otherwise - false.
303 bool isOpenMPTeamsDirective(OpenMPDirectiveKind DKind);
304 
305 /// Checks if the specified directive is a simd directive.
306 /// \param DKind Specified directive.
307 /// \return true - the directive is a simd directive like 'omp simd',
308 /// otherwise - false.
309 bool isOpenMPSimdDirective(OpenMPDirectiveKind DKind);
310 
311 /// Checks if the specified directive is a distribute directive.
312 /// \param DKind Specified directive.
313 /// \return true - the directive is a distribute-directive like 'omp
314 /// distribute',
315 /// otherwise - false.
316 bool isOpenMPDistributeDirective(OpenMPDirectiveKind DKind);
317 
318 /// Checks if the specified composite/combined directive constitutes a
319 /// distribute directive in the outermost nest.  For example,
320 /// 'omp distribute parallel for' or 'omp distribute'.
321 /// \param DKind Specified directive.
322 /// \return true - the directive has distribute on the outermost nest.
323 /// otherwise - false.
324 bool isOpenMPNestingDistributeDirective(OpenMPDirectiveKind DKind);
325 
326 /// Checks if the specified directive constitutes a 'loop' directive in the
327 /// outermost nest.  For example, 'omp teams loop' or 'omp loop'.
328 /// \param DKind Specified directive.
329 /// \return true - the directive has loop on the outermost nest.
330 /// otherwise - false.
331 bool isOpenMPGenericLoopDirective(OpenMPDirectiveKind DKind);
332 
333 /// Checks if the specified clause is one of private clauses like
334 /// 'private', 'firstprivate', 'reduction' etc..
335 /// \param Kind Clause kind.
336 /// \return true - the clause is a private clause, otherwise - false.
337 bool isOpenMPPrivate(OpenMPClauseKind Kind);
338 
339 /// Checks if the specified clause is one of threadprivate clauses like
340 /// 'threadprivate', 'copyin' or 'copyprivate'.
341 /// \param Kind Clause kind.
342 /// \return true - the clause is a threadprivate clause, otherwise - false.
343 bool isOpenMPThreadPrivate(OpenMPClauseKind Kind);
344 
345 /// Checks if the specified directive kind is one of tasking directives - task,
346 /// taskloop, taksloop simd, master taskloop, parallel master taskloop, master
347 /// taskloop simd, or parallel master taskloop simd.
348 bool isOpenMPTaskingDirective(OpenMPDirectiveKind Kind);
349 
350 /// Checks if the specified directive kind is one of the composite or combined
351 /// directives that need loop bound sharing across loops outlined in nested
352 /// functions
353 bool isOpenMPLoopBoundSharingDirective(OpenMPDirectiveKind Kind);
354 
355 /// Checks if the specified directive is a loop transformation directive.
356 /// \param DKind Specified directive.
357 /// \return True iff the directive is a loop transformation.
358 bool isOpenMPLoopTransformationDirective(OpenMPDirectiveKind DKind);
359 
360 /// Return the captured regions of an OpenMP directive.
361 void getOpenMPCaptureRegions(
362     llvm::SmallVectorImpl<OpenMPDirectiveKind> &CaptureRegions,
363     OpenMPDirectiveKind DKind);
364 
365 /// Checks if the specified directive is a combined construct for which
366 /// the first construct is a parallel construct.
367 /// \param DKind Specified directive.
368 /// \return true - if the above condition is met for this directive
369 /// otherwise - false.
370 bool isOpenMPCombinedParallelADirective(OpenMPDirectiveKind DKind);
371 
372 /// Checks if the specified target directive, combined or not, needs task based
373 /// thread_limit
374 /// \param DKind Specified directive.
375 /// \return true - if the above condition is met for this directive
376 /// otherwise - false.
377 bool needsTaskBasedThreadLimit(OpenMPDirectiveKind DKind);
378 
379 /// Checks if the parameter to the fail clause in "#pragma atomic compare fail"
380 /// is restricted only to memory order clauses of "OMPC_acquire",
381 /// "OMPC_relaxed" and "OMPC_seq_cst".
382 bool checkFailClauseParameter(OpenMPClauseKind FailClauseParameter);
383 
384 /// Checks if the specified directive is considered as "executable". This
385 /// combines the OpenMP categories of "executable" and "subsidiary", plus
386 /// any other directives that should be treated as executable.
387 /// \param DKind Specified directive.
388 /// \return true - if the above condition is met for this directive
389 /// otherwise - false.
390 bool isOpenMPExecutableDirective(OpenMPDirectiveKind DKind);
391 
392 /// Checks if the specified directive is considered as "informational".
393 /// \param DKind Specified directive.
394 /// \return true if it is an informational directive, false otherwise.
395 bool isOpenMPInformationalDirective(OpenMPDirectiveKind DKind);
396 
397 /// Checks if the specified directive can capture variables.
398 /// \param DKind Specified directive.
399 /// \return true - if the above condition is met for this directive
400 /// otherwise - false.
401 bool isOpenMPCapturingDirective(OpenMPDirectiveKind DKind);
402 }
403 
404 template <>
405 struct llvm::enum_iteration_traits<clang::OpenMPDefaultmapClauseKind> {
406   static constexpr bool is_iterable = true;
407 };
408 #endif
409 
410