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