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