xref: /freebsd/contrib/llvm-project/clang/lib/Basic/OpenMPKinds.cpp (revision 95eb4b873b6a8b527c5bd78d7191975dfca38998)
1 //===--- OpenMPKinds.cpp - Token Kinds Support ----------------------------===//
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 /// This file implements the OpenMP enum and support functions.
10 ///
11 //===----------------------------------------------------------------------===//
12 
13 #include "clang/Basic/OpenMPKinds.h"
14 #include "clang/Basic/IdentifierTable.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/ADT/StringSwitch.h"
17 #include "llvm/Support/ErrorHandling.h"
18 #include <cassert>
19 
20 using namespace clang;
21 using namespace llvm::omp;
22 
23 unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, StringRef Str,
24                                           const LangOptions &LangOpts) {
25   switch (Kind) {
26   case OMPC_default:
27     return llvm::StringSwitch<unsigned>(Str)
28 #define OMP_DEFAULT_KIND(Enum, Name) .Case(Name, unsigned(Enum))
29 #include "llvm/Frontend/OpenMP/OMPKinds.def"
30         .Default(unsigned(llvm::omp::OMP_DEFAULT_unknown));
31   case OMPC_proc_bind:
32     return llvm::StringSwitch<unsigned>(Str)
33 #define OMP_PROC_BIND_KIND(Enum, Name, Value) .Case(Name, Value)
34 #include "llvm/Frontend/OpenMP/OMPKinds.def"
35         .Default(unsigned(llvm::omp::OMP_PROC_BIND_unknown));
36   case OMPC_schedule:
37     return llvm::StringSwitch<unsigned>(Str)
38 #define OPENMP_SCHEDULE_KIND(Name)                                             \
39   .Case(#Name, static_cast<unsigned>(OMPC_SCHEDULE_##Name))
40 #define OPENMP_SCHEDULE_MODIFIER(Name)                                         \
41   .Case(#Name, static_cast<unsigned>(OMPC_SCHEDULE_MODIFIER_##Name))
42 #include "clang/Basic/OpenMPKinds.def"
43         .Default(OMPC_SCHEDULE_unknown);
44   case OMPC_depend: {
45     unsigned Type = llvm::StringSwitch<unsigned>(Str)
46 #define OPENMP_DEPEND_KIND(Name) .Case(#Name, OMPC_DEPEND_##Name)
47 #include "clang/Basic/OpenMPKinds.def"
48                         .Default(OMPC_DEPEND_unknown);
49     if (LangOpts.OpenMP < 51 && Type == OMPC_DEPEND_inoutset)
50       return OMPC_DEPEND_unknown;
51     return Type;
52   }
53   case OMPC_doacross:
54     return llvm::StringSwitch<OpenMPDoacrossClauseModifier>(Str)
55 #define OPENMP_DOACROSS_MODIFIER(Name) .Case(#Name, OMPC_DOACROSS_##Name)
56 #include "clang/Basic/OpenMPKinds.def"
57         .Default(OMPC_DOACROSS_unknown);
58   case OMPC_linear:
59     return llvm::StringSwitch<OpenMPLinearClauseKind>(Str)
60 #define OPENMP_LINEAR_KIND(Name) .Case(#Name, OMPC_LINEAR_##Name)
61 #include "clang/Basic/OpenMPKinds.def"
62         .Default(OMPC_LINEAR_unknown);
63   case OMPC_map: {
64     unsigned Type = llvm::StringSwitch<unsigned>(Str)
65 #define OPENMP_MAP_KIND(Name)                                                  \
66   .Case(#Name, static_cast<unsigned>(OMPC_MAP_##Name))
67 #define OPENMP_MAP_MODIFIER_KIND(Name)                                         \
68   .Case(#Name, static_cast<unsigned>(OMPC_MAP_MODIFIER_##Name))
69 #include "clang/Basic/OpenMPKinds.def"
70         .Default(OMPC_MAP_unknown);
71     if (LangOpts.OpenMP < 51 && Type == OMPC_MAP_MODIFIER_present)
72       return OMPC_MAP_MODIFIER_unknown;
73     if (!LangOpts.OpenMPExtensions && Type == OMPC_MAP_MODIFIER_ompx_hold)
74       return OMPC_MAP_MODIFIER_unknown;
75     return Type;
76   }
77   case OMPC_to:
78   case OMPC_from: {
79     unsigned Type = llvm::StringSwitch<unsigned>(Str)
80 #define OPENMP_MOTION_MODIFIER_KIND(Name)                                      \
81   .Case(#Name, static_cast<unsigned>(OMPC_MOTION_MODIFIER_##Name))
82 #include "clang/Basic/OpenMPKinds.def"
83         .Default(OMPC_MOTION_MODIFIER_unknown);
84     if (LangOpts.OpenMP < 51 && Type == OMPC_MOTION_MODIFIER_present)
85       return OMPC_MOTION_MODIFIER_unknown;
86     return Type;
87   }
88   case OMPC_dist_schedule:
89     return llvm::StringSwitch<OpenMPDistScheduleClauseKind>(Str)
90 #define OPENMP_DIST_SCHEDULE_KIND(Name) .Case(#Name, OMPC_DIST_SCHEDULE_##Name)
91 #include "clang/Basic/OpenMPKinds.def"
92         .Default(OMPC_DIST_SCHEDULE_unknown);
93   case OMPC_defaultmap:
94     return llvm::StringSwitch<unsigned>(Str)
95 #define OPENMP_DEFAULTMAP_KIND(Name)                                           \
96   .Case(#Name, static_cast<unsigned>(OMPC_DEFAULTMAP_##Name))
97 #define OPENMP_DEFAULTMAP_MODIFIER(Name)                                       \
98   .Case(#Name, static_cast<unsigned>(OMPC_DEFAULTMAP_MODIFIER_##Name))
99 #include "clang/Basic/OpenMPKinds.def"
100         .Default(OMPC_DEFAULTMAP_unknown);
101   case OMPC_atomic_default_mem_order:
102      return llvm::StringSwitch<OpenMPAtomicDefaultMemOrderClauseKind>(Str)
103 #define OPENMP_ATOMIC_DEFAULT_MEM_ORDER_KIND(Name)       \
104   .Case(#Name, OMPC_ATOMIC_DEFAULT_MEM_ORDER_##Name)
105 #include "clang/Basic/OpenMPKinds.def"
106         .Default(OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown);
107   case OMPC_fail:
108     return static_cast<unsigned int>(llvm::StringSwitch<llvm::omp::Clause>(Str)
109 #define OPENMP_ATOMIC_FAIL_MODIFIER(Name) .Case(#Name, OMPC_##Name)
110 #include "clang/Basic/OpenMPKinds.def"
111                                          .Default(OMPC_unknown));
112   case OMPC_device_type:
113     return llvm::StringSwitch<OpenMPDeviceType>(Str)
114 #define OPENMP_DEVICE_TYPE_KIND(Name) .Case(#Name, OMPC_DEVICE_TYPE_##Name)
115 #include "clang/Basic/OpenMPKinds.def"
116         .Default(OMPC_DEVICE_TYPE_unknown);
117   case OMPC_at:
118     return llvm::StringSwitch<OpenMPAtClauseKind>(Str)
119 #define OPENMP_AT_KIND(Name) .Case(#Name, OMPC_AT_##Name)
120 #include "clang/Basic/OpenMPKinds.def"
121         .Default(OMPC_AT_unknown);
122   case OMPC_severity:
123     return llvm::StringSwitch<OpenMPSeverityClauseKind>(Str)
124 #define OPENMP_SEVERITY_KIND(Name) .Case(#Name, OMPC_SEVERITY_##Name)
125 #include "clang/Basic/OpenMPKinds.def"
126         .Default(OMPC_SEVERITY_unknown);
127   case OMPC_lastprivate:
128     return llvm::StringSwitch<OpenMPLastprivateModifier>(Str)
129 #define OPENMP_LASTPRIVATE_KIND(Name) .Case(#Name, OMPC_LASTPRIVATE_##Name)
130 #include "clang/Basic/OpenMPKinds.def"
131         .Default(OMPC_LASTPRIVATE_unknown);
132   case OMPC_order:
133     return llvm::StringSwitch<unsigned>(Str)
134 #define OPENMP_ORDER_KIND(Name)                                                \
135   .Case(#Name, static_cast<unsigned>(OMPC_ORDER_##Name))
136 #define OPENMP_ORDER_MODIFIER(Name)                                            \
137   .Case(#Name, static_cast<unsigned>(OMPC_ORDER_MODIFIER_##Name))
138 #include "clang/Basic/OpenMPKinds.def"
139         .Default(OMPC_ORDER_unknown);
140   case OMPC_update:
141     return llvm::StringSwitch<OpenMPDependClauseKind>(Str)
142 #define OPENMP_DEPEND_KIND(Name) .Case(#Name, OMPC_DEPEND_##Name)
143 #include "clang/Basic/OpenMPKinds.def"
144         .Default(OMPC_DEPEND_unknown);
145   case OMPC_device:
146     return llvm::StringSwitch<OpenMPDeviceClauseModifier>(Str)
147 #define OPENMP_DEVICE_MODIFIER(Name) .Case(#Name, OMPC_DEVICE_##Name)
148 #include "clang/Basic/OpenMPKinds.def"
149         .Default(OMPC_DEVICE_unknown);
150   case OMPC_reduction:
151     return llvm::StringSwitch<OpenMPReductionClauseModifier>(Str)
152 #define OPENMP_REDUCTION_MODIFIER(Name) .Case(#Name, OMPC_REDUCTION_##Name)
153 #include "clang/Basic/OpenMPKinds.def"
154         .Default(OMPC_REDUCTION_unknown);
155   case OMPC_adjust_args:
156     return llvm::StringSwitch<OpenMPAdjustArgsOpKind>(Str)
157 #define OPENMP_ADJUST_ARGS_KIND(Name) .Case(#Name, OMPC_ADJUST_ARGS_##Name)
158 #include "clang/Basic/OpenMPKinds.def"
159         .Default(OMPC_ADJUST_ARGS_unknown);
160   case OMPC_bind:
161     return llvm::StringSwitch<unsigned>(Str)
162 #define OPENMP_BIND_KIND(Name) .Case(#Name, OMPC_BIND_##Name)
163 #include "clang/Basic/OpenMPKinds.def"
164         .Default(OMPC_BIND_unknown);
165   case OMPC_grainsize: {
166     unsigned Type = llvm::StringSwitch<unsigned>(Str)
167 #define OPENMP_GRAINSIZE_MODIFIER(Name) .Case(#Name, OMPC_GRAINSIZE_##Name)
168 #include "clang/Basic/OpenMPKinds.def"
169                         .Default(OMPC_GRAINSIZE_unknown);
170     if (LangOpts.OpenMP < 51)
171       return OMPC_GRAINSIZE_unknown;
172     return Type;
173   }
174   case OMPC_num_tasks: {
175     unsigned Type = llvm::StringSwitch<unsigned>(Str)
176 #define OPENMP_NUMTASKS_MODIFIER(Name) .Case(#Name, OMPC_NUMTASKS_##Name)
177 #include "clang/Basic/OpenMPKinds.def"
178                         .Default(OMPC_NUMTASKS_unknown);
179     if (LangOpts.OpenMP < 51)
180       return OMPC_NUMTASKS_unknown;
181     return Type;
182   }
183   case OMPC_unknown:
184   case OMPC_threadprivate:
185   case OMPC_if:
186   case OMPC_final:
187   case OMPC_num_threads:
188   case OMPC_safelen:
189   case OMPC_simdlen:
190   case OMPC_sizes:
191   case OMPC_allocator:
192   case OMPC_allocate:
193   case OMPC_collapse:
194   case OMPC_private:
195   case OMPC_firstprivate:
196   case OMPC_shared:
197   case OMPC_task_reduction:
198   case OMPC_in_reduction:
199   case OMPC_aligned:
200   case OMPC_copyin:
201   case OMPC_copyprivate:
202   case OMPC_ordered:
203   case OMPC_nowait:
204   case OMPC_untied:
205   case OMPC_mergeable:
206   case OMPC_flush:
207   case OMPC_depobj:
208   case OMPC_read:
209   case OMPC_write:
210   case OMPC_capture:
211   case OMPC_compare:
212   case OMPC_seq_cst:
213   case OMPC_acq_rel:
214   case OMPC_acquire:
215   case OMPC_release:
216   case OMPC_relaxed:
217   case OMPC_threads:
218   case OMPC_simd:
219   case OMPC_num_teams:
220   case OMPC_thread_limit:
221   case OMPC_priority:
222   case OMPC_nogroup:
223   case OMPC_hint:
224   case OMPC_uniform:
225   case OMPC_use_device_ptr:
226   case OMPC_use_device_addr:
227   case OMPC_is_device_ptr:
228   case OMPC_has_device_addr:
229   case OMPC_unified_address:
230   case OMPC_unified_shared_memory:
231   case OMPC_reverse_offload:
232   case OMPC_dynamic_allocators:
233   case OMPC_match:
234   case OMPC_nontemporal:
235   case OMPC_destroy:
236   case OMPC_novariants:
237   case OMPC_nocontext:
238   case OMPC_detach:
239   case OMPC_inclusive:
240   case OMPC_exclusive:
241   case OMPC_uses_allocators:
242   case OMPC_affinity:
243   case OMPC_when:
244   case OMPC_append_args:
245     break;
246   default:
247     break;
248   }
249   llvm_unreachable("Invalid OpenMP simple clause kind");
250 }
251 
252 const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
253                                                  unsigned Type) {
254   switch (Kind) {
255   case OMPC_default:
256     switch (llvm::omp::DefaultKind(Type)) {
257 #define OMP_DEFAULT_KIND(Enum, Name)                                           \
258   case Enum:                                                                   \
259     return Name;
260 #include "llvm/Frontend/OpenMP/OMPKinds.def"
261     }
262     llvm_unreachable("Invalid OpenMP 'default' clause type");
263   case OMPC_proc_bind:
264     switch (Type) {
265 #define OMP_PROC_BIND_KIND(Enum, Name, Value)                                  \
266   case Value:                                                                  \
267     return Name;
268 #include "llvm/Frontend/OpenMP/OMPKinds.def"
269     }
270     llvm_unreachable("Invalid OpenMP 'proc_bind' clause type");
271   case OMPC_schedule:
272     switch (Type) {
273     case OMPC_SCHEDULE_unknown:
274     case OMPC_SCHEDULE_MODIFIER_last:
275       return "unknown";
276 #define OPENMP_SCHEDULE_KIND(Name)                                             \
277     case OMPC_SCHEDULE_##Name:                                                 \
278       return #Name;
279 #define OPENMP_SCHEDULE_MODIFIER(Name)                                         \
280     case OMPC_SCHEDULE_MODIFIER_##Name:                                        \
281       return #Name;
282 #include "clang/Basic/OpenMPKinds.def"
283     }
284     llvm_unreachable("Invalid OpenMP 'schedule' clause type");
285   case OMPC_depend:
286     switch (Type) {
287     case OMPC_DEPEND_unknown:
288       return "unknown";
289 #define OPENMP_DEPEND_KIND(Name)                                             \
290   case OMPC_DEPEND_##Name:                                                   \
291     return #Name;
292 #include "clang/Basic/OpenMPKinds.def"
293     }
294     llvm_unreachable("Invalid OpenMP 'depend' clause type");
295   case OMPC_doacross:
296     switch (Type) {
297     case OMPC_DOACROSS_unknown:
298       return "unknown";
299 #define OPENMP_DOACROSS_MODIFIER(Name)                                         \
300   case OMPC_DOACROSS_##Name:                                                   \
301     return #Name;
302 #include "clang/Basic/OpenMPKinds.def"
303     }
304     llvm_unreachable("Invalid OpenMP 'doacross' clause type");
305   case OMPC_linear:
306     switch (Type) {
307     case OMPC_LINEAR_unknown:
308       return "unknown";
309 #define OPENMP_LINEAR_KIND(Name)                                             \
310   case OMPC_LINEAR_##Name:                                                   \
311     return #Name;
312 #include "clang/Basic/OpenMPKinds.def"
313     }
314     llvm_unreachable("Invalid OpenMP 'linear' clause type");
315   case OMPC_map:
316     switch (Type) {
317     case OMPC_MAP_unknown:
318     case OMPC_MAP_MODIFIER_last:
319       return "unknown";
320 #define OPENMP_MAP_KIND(Name)                                                \
321   case OMPC_MAP_##Name:                                                      \
322     return #Name;
323 #define OPENMP_MAP_MODIFIER_KIND(Name)                                       \
324   case OMPC_MAP_MODIFIER_##Name:                                             \
325     return #Name;
326 #include "clang/Basic/OpenMPKinds.def"
327     default:
328       break;
329     }
330     llvm_unreachable("Invalid OpenMP 'map' clause type");
331   case OMPC_to:
332   case OMPC_from:
333     switch (Type) {
334     case OMPC_MOTION_MODIFIER_unknown:
335       return "unknown";
336 #define OPENMP_MOTION_MODIFIER_KIND(Name)                                      \
337   case OMPC_MOTION_MODIFIER_##Name:                                            \
338     return #Name;
339 #include "clang/Basic/OpenMPKinds.def"
340     default:
341       break;
342     }
343     llvm_unreachable("Invalid OpenMP 'to' or 'from' clause type");
344   case OMPC_dist_schedule:
345     switch (Type) {
346     case OMPC_DIST_SCHEDULE_unknown:
347       return "unknown";
348 #define OPENMP_DIST_SCHEDULE_KIND(Name)                                      \
349   case OMPC_DIST_SCHEDULE_##Name:                                            \
350     return #Name;
351 #include "clang/Basic/OpenMPKinds.def"
352     }
353     llvm_unreachable("Invalid OpenMP 'dist_schedule' clause type");
354   case OMPC_defaultmap:
355     switch (Type) {
356     case OMPC_DEFAULTMAP_unknown:
357     case OMPC_DEFAULTMAP_MODIFIER_last:
358       return "unknown";
359 #define OPENMP_DEFAULTMAP_KIND(Name)                                         \
360     case OMPC_DEFAULTMAP_##Name:                                             \
361       return #Name;
362 #define OPENMP_DEFAULTMAP_MODIFIER(Name)                                     \
363     case OMPC_DEFAULTMAP_MODIFIER_##Name:                                    \
364       return #Name;
365 #include "clang/Basic/OpenMPKinds.def"
366     }
367     llvm_unreachable("Invalid OpenMP 'schedule' clause type");
368   case OMPC_atomic_default_mem_order:
369     switch (Type) {
370     case OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown:
371       return "unknown";
372 #define OPENMP_ATOMIC_DEFAULT_MEM_ORDER_KIND(Name)                           \
373     case OMPC_ATOMIC_DEFAULT_MEM_ORDER_##Name:                               \
374       return #Name;
375 #include "clang/Basic/OpenMPKinds.def"
376 }
377     llvm_unreachable("Invalid OpenMP 'atomic_default_mem_order' clause type");
378   case OMPC_device_type:
379     switch (Type) {
380     case OMPC_DEVICE_TYPE_unknown:
381       return "unknown";
382 #define OPENMP_DEVICE_TYPE_KIND(Name)                                          \
383     case OMPC_DEVICE_TYPE_##Name:                                              \
384       return #Name;
385 #include "clang/Basic/OpenMPKinds.def"
386     }
387     llvm_unreachable("Invalid OpenMP 'device_type' clause type");
388   case OMPC_at:
389     switch (Type) {
390     case OMPC_AT_unknown:
391       return "unknown";
392 #define OPENMP_AT_KIND(Name)                                                   \
393   case OMPC_AT_##Name:                                                         \
394     return #Name;
395 #include "clang/Basic/OpenMPKinds.def"
396     }
397     llvm_unreachable("Invalid OpenMP 'at' clause type");
398   case OMPC_severity:
399     switch (Type) {
400     case OMPC_SEVERITY_unknown:
401       return "unknown";
402 #define OPENMP_SEVERITY_KIND(Name)                                             \
403   case OMPC_SEVERITY_##Name:                                                   \
404     return #Name;
405 #include "clang/Basic/OpenMPKinds.def"
406     }
407     llvm_unreachable("Invalid OpenMP 'severity' clause type");
408   case OMPC_lastprivate:
409     switch (Type) {
410     case OMPC_LASTPRIVATE_unknown:
411       return "unknown";
412 #define OPENMP_LASTPRIVATE_KIND(Name)                                          \
413     case OMPC_LASTPRIVATE_##Name:                                              \
414       return #Name;
415 #include "clang/Basic/OpenMPKinds.def"
416     }
417     llvm_unreachable("Invalid OpenMP 'lastprivate' clause type");
418   case OMPC_order:
419     switch (Type) {
420     case OMPC_ORDER_unknown:
421     case OMPC_ORDER_MODIFIER_last:
422       return "unknown";
423 #define OPENMP_ORDER_KIND(Name)                                                \
424   case OMPC_ORDER_##Name:                                                      \
425     return #Name;
426 #define OPENMP_ORDER_MODIFIER(Name)                                            \
427   case OMPC_ORDER_MODIFIER_##Name:                                             \
428     return #Name;
429 #include "clang/Basic/OpenMPKinds.def"
430     }
431     llvm_unreachable("Invalid OpenMP 'order' clause type");
432   case OMPC_update:
433     switch (Type) {
434     case OMPC_DEPEND_unknown:
435       return "unknown";
436 #define OPENMP_DEPEND_KIND(Name)                                               \
437   case OMPC_DEPEND_##Name:                                                     \
438     return #Name;
439 #include "clang/Basic/OpenMPKinds.def"
440     }
441     llvm_unreachable("Invalid OpenMP 'depend' clause type");
442   case OMPC_fail: {
443     OpenMPClauseKind CK = static_cast<OpenMPClauseKind>(Type);
444     return getOpenMPClauseName(CK).data();
445     llvm_unreachable("Invalid OpenMP 'fail' clause modifier");
446   }
447   case OMPC_device:
448     switch (Type) {
449     case OMPC_DEVICE_unknown:
450       return "unknown";
451 #define OPENMP_DEVICE_MODIFIER(Name)                                           \
452   case OMPC_DEVICE_##Name:                                                     \
453     return #Name;
454 #include "clang/Basic/OpenMPKinds.def"
455     }
456     llvm_unreachable("Invalid OpenMP 'device' clause modifier");
457   case OMPC_reduction:
458     switch (Type) {
459     case OMPC_REDUCTION_unknown:
460       return "unknown";
461 #define OPENMP_REDUCTION_MODIFIER(Name)                                        \
462   case OMPC_REDUCTION_##Name:                                                  \
463     return #Name;
464 #include "clang/Basic/OpenMPKinds.def"
465     }
466     llvm_unreachable("Invalid OpenMP 'reduction' clause modifier");
467   case OMPC_adjust_args:
468     switch (Type) {
469     case OMPC_ADJUST_ARGS_unknown:
470       return "unknown";
471 #define OPENMP_ADJUST_ARGS_KIND(Name)                                          \
472   case OMPC_ADJUST_ARGS_##Name:                                                \
473     return #Name;
474 #include "clang/Basic/OpenMPKinds.def"
475     }
476     llvm_unreachable("Invalid OpenMP 'adjust_args' clause kind");
477   case OMPC_bind:
478     switch (Type) {
479     case OMPC_BIND_unknown:
480       return "unknown";
481 #define OPENMP_BIND_KIND(Name)                                                 \
482   case OMPC_BIND_##Name:                                                       \
483     return #Name;
484 #include "clang/Basic/OpenMPKinds.def"
485     }
486     llvm_unreachable("Invalid OpenMP 'bind' clause type");
487   case OMPC_grainsize:
488     switch (Type) {
489     case OMPC_GRAINSIZE_unknown:
490       return "unknown";
491 #define OPENMP_GRAINSIZE_MODIFIER(Name)                                        \
492   case OMPC_GRAINSIZE_##Name:                                                  \
493     return #Name;
494 #include "clang/Basic/OpenMPKinds.def"
495     }
496     llvm_unreachable("Invalid OpenMP 'grainsize' clause modifier");
497   case OMPC_num_tasks:
498     switch (Type) {
499     case OMPC_NUMTASKS_unknown:
500       return "unknown";
501 #define OPENMP_NUMTASKS_MODIFIER(Name)                                         \
502   case OMPC_NUMTASKS_##Name:                                                   \
503     return #Name;
504 #include "clang/Basic/OpenMPKinds.def"
505     }
506     llvm_unreachable("Invalid OpenMP 'num_tasks' clause modifier");
507   case OMPC_unknown:
508   case OMPC_threadprivate:
509   case OMPC_if:
510   case OMPC_final:
511   case OMPC_num_threads:
512   case OMPC_safelen:
513   case OMPC_simdlen:
514   case OMPC_sizes:
515   case OMPC_allocator:
516   case OMPC_allocate:
517   case OMPC_collapse:
518   case OMPC_private:
519   case OMPC_firstprivate:
520   case OMPC_shared:
521   case OMPC_task_reduction:
522   case OMPC_in_reduction:
523   case OMPC_aligned:
524   case OMPC_copyin:
525   case OMPC_copyprivate:
526   case OMPC_ordered:
527   case OMPC_nowait:
528   case OMPC_untied:
529   case OMPC_mergeable:
530   case OMPC_flush:
531   case OMPC_depobj:
532   case OMPC_read:
533   case OMPC_write:
534   case OMPC_capture:
535   case OMPC_compare:
536   case OMPC_seq_cst:
537   case OMPC_acq_rel:
538   case OMPC_acquire:
539   case OMPC_release:
540   case OMPC_relaxed:
541   case OMPC_threads:
542   case OMPC_simd:
543   case OMPC_num_teams:
544   case OMPC_thread_limit:
545   case OMPC_priority:
546   case OMPC_nogroup:
547   case OMPC_hint:
548   case OMPC_uniform:
549   case OMPC_use_device_ptr:
550   case OMPC_use_device_addr:
551   case OMPC_is_device_ptr:
552   case OMPC_has_device_addr:
553   case OMPC_unified_address:
554   case OMPC_unified_shared_memory:
555   case OMPC_reverse_offload:
556   case OMPC_dynamic_allocators:
557   case OMPC_match:
558   case OMPC_nontemporal:
559   case OMPC_destroy:
560   case OMPC_detach:
561   case OMPC_novariants:
562   case OMPC_nocontext:
563   case OMPC_inclusive:
564   case OMPC_exclusive:
565   case OMPC_uses_allocators:
566   case OMPC_affinity:
567   case OMPC_when:
568   case OMPC_append_args:
569     break;
570   default:
571     break;
572   }
573   llvm_unreachable("Invalid OpenMP simple clause kind");
574 }
575 
576 bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
577   return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
578          DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
579          DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
580          DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
581          DKind == OMPD_parallel_master_taskloop ||
582          DKind == OMPD_parallel_master_taskloop_simd ||
583          DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
584          DKind == OMPD_parallel_masked_taskloop || DKind == OMPD_distribute ||
585          DKind == OMPD_parallel_masked_taskloop_simd ||
586          DKind == OMPD_target_parallel_for ||
587          DKind == OMPD_distribute_parallel_for ||
588          DKind == OMPD_distribute_parallel_for_simd ||
589          DKind == OMPD_distribute_simd ||
590          DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
591          DKind == OMPD_teams_distribute ||
592          DKind == OMPD_teams_distribute_simd ||
593          DKind == OMPD_teams_distribute_parallel_for_simd ||
594          DKind == OMPD_teams_distribute_parallel_for ||
595          DKind == OMPD_target_teams_distribute ||
596          DKind == OMPD_target_teams_distribute_parallel_for ||
597          DKind == OMPD_target_teams_distribute_parallel_for_simd ||
598          DKind == OMPD_target_teams_distribute_simd || DKind == OMPD_tile ||
599          DKind == OMPD_unroll || DKind == OMPD_loop ||
600          DKind == OMPD_teams_loop || DKind == OMPD_target_teams_loop ||
601          DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop;
602 }
603 
604 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
605   return DKind == OMPD_for || DKind == OMPD_for_simd ||
606          DKind == OMPD_sections || DKind == OMPD_section ||
607          DKind == OMPD_single || DKind == OMPD_parallel_for ||
608          DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
609          DKind == OMPD_target_parallel_for ||
610          DKind == OMPD_distribute_parallel_for ||
611          DKind == OMPD_distribute_parallel_for_simd ||
612          DKind == OMPD_target_parallel_for_simd ||
613          DKind == OMPD_teams_distribute_parallel_for_simd ||
614          DKind == OMPD_teams_distribute_parallel_for ||
615          DKind == OMPD_target_teams_distribute_parallel_for ||
616          DKind == OMPD_target_teams_distribute_parallel_for_simd ||
617          DKind == OMPD_parallel_loop || DKind == OMPD_teams_loop ||
618          DKind == OMPD_target_parallel_loop || DKind == OMPD_target_teams_loop;
619 }
620 
621 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
622   return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
623          DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
624          DKind == OMPD_parallel_master_taskloop ||
625          DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
626          DKind == OMPD_parallel_masked_taskloop ||
627          DKind == OMPD_parallel_masked_taskloop_simd ||
628          DKind == OMPD_parallel_master_taskloop_simd;
629 }
630 
631 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
632   return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
633          DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
634          DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
635          DKind == OMPD_distribute_parallel_for ||
636          DKind == OMPD_distribute_parallel_for_simd ||
637          DKind == OMPD_target_parallel_for_simd ||
638          DKind == OMPD_teams_distribute_parallel_for ||
639          DKind == OMPD_teams_distribute_parallel_for_simd ||
640          DKind == OMPD_target_teams_distribute_parallel_for ||
641          DKind == OMPD_target_teams_distribute_parallel_for_simd ||
642          DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
643          DKind == OMPD_parallel_master_taskloop ||
644          DKind == OMPD_parallel_master_taskloop_simd ||
645          DKind == OMPD_parallel_masked_taskloop ||
646          DKind == OMPD_parallel_masked_taskloop_simd ||
647          DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop ||
648          DKind == OMPD_teams_loop;
649 }
650 
651 bool clang::isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind) {
652   return DKind == OMPD_target || DKind == OMPD_target_parallel ||
653          DKind == OMPD_target_parallel_for ||
654          DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
655          DKind == OMPD_target_teams || DKind == OMPD_target_teams_distribute ||
656          DKind == OMPD_target_teams_distribute_parallel_for ||
657          DKind == OMPD_target_teams_distribute_parallel_for_simd ||
658          DKind == OMPD_target_teams_distribute_simd ||
659          DKind == OMPD_target_teams_loop || DKind == OMPD_target_parallel_loop;
660 }
661 
662 bool clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
663   return DKind == OMPD_target_data || DKind == OMPD_target_enter_data ||
664          DKind == OMPD_target_exit_data || DKind == OMPD_target_update;
665 }
666 
667 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
668   return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
669          DKind == OMPD_teams_distribute_simd ||
670          DKind == OMPD_teams_distribute_parallel_for_simd ||
671          DKind == OMPD_teams_distribute_parallel_for ||
672          DKind == OMPD_teams_loop;
673 }
674 
675 bool clang::isOpenMPTeamsDirective(OpenMPDirectiveKind DKind) {
676   return isOpenMPNestingTeamsDirective(DKind) || DKind == OMPD_target_teams ||
677          DKind == OMPD_target_teams_distribute ||
678          DKind == OMPD_target_teams_distribute_parallel_for ||
679          DKind == OMPD_target_teams_distribute_parallel_for_simd ||
680          DKind == OMPD_target_teams_distribute_simd ||
681          DKind == OMPD_target_teams_loop;
682 }
683 
684 bool clang::isOpenMPSimdDirective(OpenMPDirectiveKind DKind) {
685   return DKind == OMPD_simd || DKind == OMPD_for_simd ||
686          DKind == OMPD_parallel_for_simd || DKind == OMPD_taskloop_simd ||
687          DKind == OMPD_master_taskloop_simd ||
688          DKind == OMPD_masked_taskloop_simd ||
689          DKind == OMPD_parallel_master_taskloop_simd ||
690          DKind == OMPD_parallel_masked_taskloop_simd ||
691          DKind == OMPD_distribute_parallel_for_simd ||
692          DKind == OMPD_distribute_simd || DKind == OMPD_target_simd ||
693          DKind == OMPD_teams_distribute_simd ||
694          DKind == OMPD_teams_distribute_parallel_for_simd ||
695          DKind == OMPD_target_teams_distribute_parallel_for_simd ||
696          DKind == OMPD_target_teams_distribute_simd ||
697          DKind == OMPD_target_parallel_for_simd;
698 }
699 
700 bool clang::isOpenMPNestingDistributeDirective(OpenMPDirectiveKind Kind) {
701   return Kind == OMPD_distribute || Kind == OMPD_distribute_parallel_for ||
702          Kind == OMPD_distribute_parallel_for_simd ||
703          Kind == OMPD_distribute_simd;
704   // TODO add next directives.
705 }
706 
707 bool clang::isOpenMPDistributeDirective(OpenMPDirectiveKind Kind) {
708   return isOpenMPNestingDistributeDirective(Kind) ||
709          Kind == OMPD_teams_distribute || Kind == OMPD_teams_distribute_simd ||
710          Kind == OMPD_teams_distribute_parallel_for_simd ||
711          Kind == OMPD_teams_distribute_parallel_for ||
712          Kind == OMPD_target_teams_distribute ||
713          Kind == OMPD_target_teams_distribute_parallel_for ||
714          Kind == OMPD_target_teams_distribute_parallel_for_simd ||
715          Kind == OMPD_target_teams_distribute_simd;
716 }
717 
718 bool clang::isOpenMPGenericLoopDirective(OpenMPDirectiveKind Kind) {
719   return Kind == OMPD_loop || Kind == OMPD_teams_loop ||
720          Kind == OMPD_target_teams_loop || Kind == OMPD_parallel_loop ||
721          Kind == OMPD_target_parallel_loop;
722 }
723 
724 bool clang::isOpenMPPrivate(OpenMPClauseKind Kind) {
725   return Kind == OMPC_private || Kind == OMPC_firstprivate ||
726          Kind == OMPC_lastprivate || Kind == OMPC_linear ||
727          Kind == OMPC_reduction || Kind == OMPC_task_reduction ||
728          Kind == OMPC_in_reduction; // TODO add next clauses like 'reduction'.
729 }
730 
731 bool clang::isOpenMPThreadPrivate(OpenMPClauseKind Kind) {
732   return Kind == OMPC_threadprivate || Kind == OMPC_copyin;
733 }
734 
735 bool clang::isOpenMPTaskingDirective(OpenMPDirectiveKind Kind) {
736   return Kind == OMPD_task || isOpenMPTaskLoopDirective(Kind);
737 }
738 
739 bool clang::isOpenMPLoopBoundSharingDirective(OpenMPDirectiveKind Kind) {
740   return Kind == OMPD_distribute_parallel_for ||
741          Kind == OMPD_distribute_parallel_for_simd ||
742          Kind == OMPD_teams_distribute_parallel_for_simd ||
743          Kind == OMPD_teams_distribute_parallel_for ||
744          Kind == OMPD_target_teams_distribute_parallel_for ||
745          Kind == OMPD_target_teams_distribute_parallel_for_simd ||
746          Kind == OMPD_teams_loop || Kind == OMPD_target_teams_loop;
747 }
748 
749 bool clang::isOpenMPLoopTransformationDirective(OpenMPDirectiveKind DKind) {
750   return DKind == OMPD_tile || DKind == OMPD_unroll;
751 }
752 
753 bool clang::isOpenMPCombinedParallelADirective(OpenMPDirectiveKind DKind) {
754   return DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
755          DKind == OMPD_parallel_master ||
756          DKind == OMPD_parallel_master_taskloop ||
757          DKind == OMPD_parallel_master_taskloop_simd ||
758          DKind == OMPD_parallel_sections;
759 }
760 
761 bool clang::needsTaskBasedThreadLimit(OpenMPDirectiveKind DKind) {
762   return DKind == OMPD_target || DKind == OMPD_target_parallel ||
763          DKind == OMPD_target_parallel_for ||
764          DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
765          DKind == OMPD_target_parallel_loop;
766 }
767 
768 void clang::getOpenMPCaptureRegions(
769     SmallVectorImpl<OpenMPDirectiveKind> &CaptureRegions,
770     OpenMPDirectiveKind DKind) {
771   assert(unsigned(DKind) < llvm::omp::Directive_enumSize);
772   switch (DKind) {
773   case OMPD_metadirective:
774     CaptureRegions.push_back(OMPD_metadirective);
775     break;
776   case OMPD_parallel:
777   case OMPD_parallel_for:
778   case OMPD_parallel_for_simd:
779   case OMPD_parallel_master:
780   case OMPD_parallel_masked:
781   case OMPD_parallel_sections:
782   case OMPD_distribute_parallel_for:
783   case OMPD_distribute_parallel_for_simd:
784   case OMPD_parallel_loop:
785     CaptureRegions.push_back(OMPD_parallel);
786     break;
787   case OMPD_target_teams:
788   case OMPD_target_teams_distribute:
789   case OMPD_target_teams_distribute_simd:
790     CaptureRegions.push_back(OMPD_task);
791     CaptureRegions.push_back(OMPD_target);
792     CaptureRegions.push_back(OMPD_teams);
793     break;
794   case OMPD_teams:
795   case OMPD_teams_distribute:
796   case OMPD_teams_distribute_simd:
797     CaptureRegions.push_back(OMPD_teams);
798     break;
799   case OMPD_target:
800   case OMPD_target_simd:
801     CaptureRegions.push_back(OMPD_task);
802     CaptureRegions.push_back(OMPD_target);
803     break;
804   case OMPD_teams_loop:
805   case OMPD_teams_distribute_parallel_for:
806   case OMPD_teams_distribute_parallel_for_simd:
807     CaptureRegions.push_back(OMPD_teams);
808     CaptureRegions.push_back(OMPD_parallel);
809     break;
810   case OMPD_target_parallel:
811   case OMPD_target_parallel_for:
812   case OMPD_target_parallel_for_simd:
813   case OMPD_target_parallel_loop:
814     CaptureRegions.push_back(OMPD_task);
815     CaptureRegions.push_back(OMPD_target);
816     CaptureRegions.push_back(OMPD_parallel);
817     break;
818   case OMPD_task:
819   case OMPD_target_enter_data:
820   case OMPD_target_exit_data:
821   case OMPD_target_update:
822     CaptureRegions.push_back(OMPD_task);
823     break;
824   case OMPD_taskloop:
825   case OMPD_taskloop_simd:
826   case OMPD_master_taskloop:
827   case OMPD_master_taskloop_simd:
828   case OMPD_masked_taskloop:
829   case OMPD_masked_taskloop_simd:
830     CaptureRegions.push_back(OMPD_taskloop);
831     break;
832   case OMPD_parallel_masked_taskloop:
833   case OMPD_parallel_masked_taskloop_simd:
834   case OMPD_parallel_master_taskloop:
835   case OMPD_parallel_master_taskloop_simd:
836     CaptureRegions.push_back(OMPD_parallel);
837     CaptureRegions.push_back(OMPD_taskloop);
838     break;
839   case OMPD_target_teams_loop:
840   case OMPD_target_teams_distribute_parallel_for:
841   case OMPD_target_teams_distribute_parallel_for_simd:
842     CaptureRegions.push_back(OMPD_task);
843     CaptureRegions.push_back(OMPD_target);
844     CaptureRegions.push_back(OMPD_teams);
845     CaptureRegions.push_back(OMPD_parallel);
846     break;
847   case OMPD_nothing:
848     CaptureRegions.push_back(OMPD_nothing);
849     break;
850   case OMPD_loop:
851     // TODO: 'loop' may require different capture regions depending on the bind
852     // clause or the parent directive when there is no bind clause. Use
853     // OMPD_unknown for now.
854   case OMPD_simd:
855   case OMPD_for:
856   case OMPD_for_simd:
857   case OMPD_sections:
858   case OMPD_section:
859   case OMPD_single:
860   case OMPD_master:
861   case OMPD_critical:
862   case OMPD_taskgroup:
863   case OMPD_distribute:
864   case OMPD_ordered:
865   case OMPD_atomic:
866   case OMPD_target_data:
867   case OMPD_distribute_simd:
868   case OMPD_scope:
869   case OMPD_dispatch:
870     CaptureRegions.push_back(OMPD_unknown);
871     break;
872   case OMPD_tile:
873   case OMPD_unroll:
874     // loop transformations do not introduce captures.
875     break;
876   case OMPD_threadprivate:
877   case OMPD_allocate:
878   case OMPD_taskyield:
879   case OMPD_barrier:
880   case OMPD_error:
881   case OMPD_taskwait:
882   case OMPD_cancellation_point:
883   case OMPD_cancel:
884   case OMPD_flush:
885   case OMPD_depobj:
886   case OMPD_scan:
887   case OMPD_declare_reduction:
888   case OMPD_declare_mapper:
889   case OMPD_declare_simd:
890   case OMPD_declare_target:
891   case OMPD_end_declare_target:
892   case OMPD_requires:
893   case OMPD_declare_variant:
894   case OMPD_begin_declare_variant:
895   case OMPD_end_declare_variant:
896     llvm_unreachable("OpenMP Directive is not allowed");
897   case OMPD_unknown:
898   default:
899     llvm_unreachable("Unknown OpenMP directive");
900   }
901 }
902 
903 bool clang::checkFailClauseParameter(OpenMPClauseKind FailClauseParameter) {
904   return FailClauseParameter == llvm::omp::OMPC_acquire ||
905          FailClauseParameter == llvm::omp::OMPC_relaxed ||
906          FailClauseParameter == llvm::omp::OMPC_seq_cst;
907 }
908 
909