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