xref: /freebsd/contrib/llvm-project/clang/lib/Basic/OpenMPKinds.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===--- OpenMPKinds.cpp - Token Kinds Support ----------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric /// \file
90b57cec5SDimitry Andric /// This file implements the OpenMP enum and support functions.
100b57cec5SDimitry Andric ///
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #include "clang/Basic/OpenMPKinds.h"
140b57cec5SDimitry Andric #include "clang/Basic/IdentifierTable.h"
150b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h"
160b57cec5SDimitry Andric #include "llvm/ADT/StringSwitch.h"
170b57cec5SDimitry Andric #include "llvm/Support/ErrorHandling.h"
180b57cec5SDimitry Andric #include <cassert>
190b57cec5SDimitry Andric 
200b57cec5SDimitry Andric using namespace clang;
21480093f4SDimitry Andric using namespace llvm::omp;
220b57cec5SDimitry Andric 
getOpenMPSimpleClauseType(OpenMPClauseKind Kind,StringRef Str,const LangOptions & LangOpts)23e8d8bef9SDimitry Andric unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, StringRef Str,
24349cc55cSDimitry Andric                                           const LangOptions &LangOpts) {
250b57cec5SDimitry Andric   switch (Kind) {
260b57cec5SDimitry Andric   case OMPC_default:
275ffd83dbSDimitry Andric     return llvm::StringSwitch<unsigned>(Str)
285ffd83dbSDimitry Andric #define OMP_DEFAULT_KIND(Enum, Name) .Case(Name, unsigned(Enum))
295ffd83dbSDimitry Andric #include "llvm/Frontend/OpenMP/OMPKinds.def"
305ffd83dbSDimitry Andric         .Default(unsigned(llvm::omp::OMP_DEFAULT_unknown));
310b57cec5SDimitry Andric   case OMPC_proc_bind:
32480093f4SDimitry Andric     return llvm::StringSwitch<unsigned>(Str)
33480093f4SDimitry Andric #define OMP_PROC_BIND_KIND(Enum, Name, Value) .Case(Name, Value)
34480093f4SDimitry Andric #include "llvm/Frontend/OpenMP/OMPKinds.def"
35480093f4SDimitry Andric         .Default(unsigned(llvm::omp::OMP_PROC_BIND_unknown));
360b57cec5SDimitry Andric   case OMPC_schedule:
370b57cec5SDimitry Andric     return llvm::StringSwitch<unsigned>(Str)
380b57cec5SDimitry Andric #define OPENMP_SCHEDULE_KIND(Name)                                             \
390b57cec5SDimitry Andric   .Case(#Name, static_cast<unsigned>(OMPC_SCHEDULE_##Name))
400b57cec5SDimitry Andric #define OPENMP_SCHEDULE_MODIFIER(Name)                                         \
410b57cec5SDimitry Andric   .Case(#Name, static_cast<unsigned>(OMPC_SCHEDULE_MODIFIER_##Name))
420b57cec5SDimitry Andric #include "clang/Basic/OpenMPKinds.def"
430b57cec5SDimitry Andric         .Default(OMPC_SCHEDULE_unknown);
4481ad6265SDimitry Andric   case OMPC_depend: {
4581ad6265SDimitry Andric     unsigned Type = llvm::StringSwitch<unsigned>(Str)
460b57cec5SDimitry Andric #define OPENMP_DEPEND_KIND(Name) .Case(#Name, OMPC_DEPEND_##Name)
470b57cec5SDimitry Andric #include "clang/Basic/OpenMPKinds.def"
480b57cec5SDimitry Andric                         .Default(OMPC_DEPEND_unknown);
4981ad6265SDimitry Andric     if (LangOpts.OpenMP < 51 && Type == OMPC_DEPEND_inoutset)
5081ad6265SDimitry Andric       return OMPC_DEPEND_unknown;
5181ad6265SDimitry Andric     return Type;
5281ad6265SDimitry Andric   }
5306c3fb27SDimitry Andric   case OMPC_doacross:
5406c3fb27SDimitry Andric     return llvm::StringSwitch<OpenMPDoacrossClauseModifier>(Str)
5506c3fb27SDimitry Andric #define OPENMP_DOACROSS_MODIFIER(Name) .Case(#Name, OMPC_DOACROSS_##Name)
5606c3fb27SDimitry Andric #include "clang/Basic/OpenMPKinds.def"
5706c3fb27SDimitry Andric         .Default(OMPC_DOACROSS_unknown);
580b57cec5SDimitry Andric   case OMPC_linear:
590b57cec5SDimitry Andric     return llvm::StringSwitch<OpenMPLinearClauseKind>(Str)
600b57cec5SDimitry Andric #define OPENMP_LINEAR_KIND(Name) .Case(#Name, OMPC_LINEAR_##Name)
610b57cec5SDimitry Andric #include "clang/Basic/OpenMPKinds.def"
620b57cec5SDimitry Andric         .Default(OMPC_LINEAR_unknown);
63e8d8bef9SDimitry Andric   case OMPC_map: {
64e8d8bef9SDimitry Andric     unsigned Type = llvm::StringSwitch<unsigned>(Str)
650b57cec5SDimitry Andric #define OPENMP_MAP_KIND(Name)                                                  \
660b57cec5SDimitry Andric   .Case(#Name, static_cast<unsigned>(OMPC_MAP_##Name))
670b57cec5SDimitry Andric #define OPENMP_MAP_MODIFIER_KIND(Name)                                         \
680b57cec5SDimitry Andric   .Case(#Name, static_cast<unsigned>(OMPC_MAP_MODIFIER_##Name))
690b57cec5SDimitry Andric #include "clang/Basic/OpenMPKinds.def"
700b57cec5SDimitry Andric         .Default(OMPC_MAP_unknown);
71349cc55cSDimitry Andric     if (LangOpts.OpenMP < 51 && Type == OMPC_MAP_MODIFIER_present)
72349cc55cSDimitry Andric       return OMPC_MAP_MODIFIER_unknown;
73349cc55cSDimitry Andric     if (!LangOpts.OpenMPExtensions && Type == OMPC_MAP_MODIFIER_ompx_hold)
74e8d8bef9SDimitry Andric       return OMPC_MAP_MODIFIER_unknown;
75e8d8bef9SDimitry Andric     return Type;
76e8d8bef9SDimitry Andric   }
770b57cec5SDimitry Andric   case OMPC_to:
78e8d8bef9SDimitry Andric   case OMPC_from: {
79e8d8bef9SDimitry Andric     unsigned Type = llvm::StringSwitch<unsigned>(Str)
80e8d8bef9SDimitry Andric #define OPENMP_MOTION_MODIFIER_KIND(Name)                                      \
81e8d8bef9SDimitry Andric   .Case(#Name, static_cast<unsigned>(OMPC_MOTION_MODIFIER_##Name))
820b57cec5SDimitry Andric #include "clang/Basic/OpenMPKinds.def"
83e8d8bef9SDimitry Andric         .Default(OMPC_MOTION_MODIFIER_unknown);
84349cc55cSDimitry Andric     if (LangOpts.OpenMP < 51 && Type == OMPC_MOTION_MODIFIER_present)
85e8d8bef9SDimitry Andric       return OMPC_MOTION_MODIFIER_unknown;
86e8d8bef9SDimitry Andric     return Type;
87e8d8bef9SDimitry Andric   }
880b57cec5SDimitry Andric   case OMPC_dist_schedule:
890b57cec5SDimitry Andric     return llvm::StringSwitch<OpenMPDistScheduleClauseKind>(Str)
900b57cec5SDimitry Andric #define OPENMP_DIST_SCHEDULE_KIND(Name) .Case(#Name, OMPC_DIST_SCHEDULE_##Name)
910b57cec5SDimitry Andric #include "clang/Basic/OpenMPKinds.def"
920b57cec5SDimitry Andric         .Default(OMPC_DIST_SCHEDULE_unknown);
930b57cec5SDimitry Andric   case OMPC_defaultmap:
940b57cec5SDimitry Andric     return llvm::StringSwitch<unsigned>(Str)
950b57cec5SDimitry Andric #define OPENMP_DEFAULTMAP_KIND(Name)                                           \
960b57cec5SDimitry Andric   .Case(#Name, static_cast<unsigned>(OMPC_DEFAULTMAP_##Name))
970b57cec5SDimitry Andric #define OPENMP_DEFAULTMAP_MODIFIER(Name)                                       \
980b57cec5SDimitry Andric   .Case(#Name, static_cast<unsigned>(OMPC_DEFAULTMAP_MODIFIER_##Name))
990b57cec5SDimitry Andric #include "clang/Basic/OpenMPKinds.def"
1000b57cec5SDimitry Andric         .Default(OMPC_DEFAULTMAP_unknown);
1010b57cec5SDimitry Andric   case OMPC_atomic_default_mem_order:
1020b57cec5SDimitry Andric      return llvm::StringSwitch<OpenMPAtomicDefaultMemOrderClauseKind>(Str)
1030b57cec5SDimitry Andric #define OPENMP_ATOMIC_DEFAULT_MEM_ORDER_KIND(Name)       \
1040b57cec5SDimitry Andric   .Case(#Name, OMPC_ATOMIC_DEFAULT_MEM_ORDER_##Name)
1050b57cec5SDimitry Andric #include "clang/Basic/OpenMPKinds.def"
1060b57cec5SDimitry Andric         .Default(OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown);
1075f757f3fSDimitry Andric   case OMPC_fail:
1085f757f3fSDimitry Andric     return static_cast<unsigned int>(llvm::StringSwitch<llvm::omp::Clause>(Str)
1095f757f3fSDimitry Andric #define OPENMP_ATOMIC_FAIL_MODIFIER(Name) .Case(#Name, OMPC_##Name)
1105f757f3fSDimitry Andric #include "clang/Basic/OpenMPKinds.def"
1115f757f3fSDimitry Andric                                          .Default(OMPC_unknown));
112a7dea167SDimitry Andric   case OMPC_device_type:
113a7dea167SDimitry Andric     return llvm::StringSwitch<OpenMPDeviceType>(Str)
114a7dea167SDimitry Andric #define OPENMP_DEVICE_TYPE_KIND(Name) .Case(#Name, OMPC_DEVICE_TYPE_##Name)
115a7dea167SDimitry Andric #include "clang/Basic/OpenMPKinds.def"
116a7dea167SDimitry Andric         .Default(OMPC_DEVICE_TYPE_unknown);
117bdd1243dSDimitry Andric   case OMPC_at:
118bdd1243dSDimitry Andric     return llvm::StringSwitch<OpenMPAtClauseKind>(Str)
119bdd1243dSDimitry Andric #define OPENMP_AT_KIND(Name) .Case(#Name, OMPC_AT_##Name)
120bdd1243dSDimitry Andric #include "clang/Basic/OpenMPKinds.def"
121bdd1243dSDimitry Andric         .Default(OMPC_AT_unknown);
122bdd1243dSDimitry Andric   case OMPC_severity:
123bdd1243dSDimitry Andric     return llvm::StringSwitch<OpenMPSeverityClauseKind>(Str)
124bdd1243dSDimitry Andric #define OPENMP_SEVERITY_KIND(Name) .Case(#Name, OMPC_SEVERITY_##Name)
125bdd1243dSDimitry Andric #include "clang/Basic/OpenMPKinds.def"
126bdd1243dSDimitry Andric         .Default(OMPC_SEVERITY_unknown);
127480093f4SDimitry Andric   case OMPC_lastprivate:
128480093f4SDimitry Andric     return llvm::StringSwitch<OpenMPLastprivateModifier>(Str)
129480093f4SDimitry Andric #define OPENMP_LASTPRIVATE_KIND(Name) .Case(#Name, OMPC_LASTPRIVATE_##Name)
130480093f4SDimitry Andric #include "clang/Basic/OpenMPKinds.def"
131480093f4SDimitry Andric         .Default(OMPC_LASTPRIVATE_unknown);
1325ffd83dbSDimitry Andric   case OMPC_order:
133bdd1243dSDimitry Andric     return llvm::StringSwitch<unsigned>(Str)
134bdd1243dSDimitry Andric #define OPENMP_ORDER_KIND(Name)                                                \
135bdd1243dSDimitry Andric   .Case(#Name, static_cast<unsigned>(OMPC_ORDER_##Name))
136bdd1243dSDimitry Andric #define OPENMP_ORDER_MODIFIER(Name)                                            \
137bdd1243dSDimitry Andric   .Case(#Name, static_cast<unsigned>(OMPC_ORDER_MODIFIER_##Name))
1385ffd83dbSDimitry Andric #include "clang/Basic/OpenMPKinds.def"
1395ffd83dbSDimitry Andric         .Default(OMPC_ORDER_unknown);
1405ffd83dbSDimitry Andric   case OMPC_update:
1415ffd83dbSDimitry Andric     return llvm::StringSwitch<OpenMPDependClauseKind>(Str)
1425ffd83dbSDimitry Andric #define OPENMP_DEPEND_KIND(Name) .Case(#Name, OMPC_DEPEND_##Name)
1435ffd83dbSDimitry Andric #include "clang/Basic/OpenMPKinds.def"
1445ffd83dbSDimitry Andric         .Default(OMPC_DEPEND_unknown);
1455ffd83dbSDimitry Andric   case OMPC_device:
1465ffd83dbSDimitry Andric     return llvm::StringSwitch<OpenMPDeviceClauseModifier>(Str)
1475ffd83dbSDimitry Andric #define OPENMP_DEVICE_MODIFIER(Name) .Case(#Name, OMPC_DEVICE_##Name)
1485ffd83dbSDimitry Andric #include "clang/Basic/OpenMPKinds.def"
1495ffd83dbSDimitry Andric         .Default(OMPC_DEVICE_unknown);
1505ffd83dbSDimitry Andric   case OMPC_reduction:
1515ffd83dbSDimitry Andric     return llvm::StringSwitch<OpenMPReductionClauseModifier>(Str)
1525ffd83dbSDimitry Andric #define OPENMP_REDUCTION_MODIFIER(Name) .Case(#Name, OMPC_REDUCTION_##Name)
1535ffd83dbSDimitry Andric #include "clang/Basic/OpenMPKinds.def"
1545ffd83dbSDimitry Andric         .Default(OMPC_REDUCTION_unknown);
155349cc55cSDimitry Andric   case OMPC_adjust_args:
156349cc55cSDimitry Andric     return llvm::StringSwitch<OpenMPAdjustArgsOpKind>(Str)
157349cc55cSDimitry Andric #define OPENMP_ADJUST_ARGS_KIND(Name) .Case(#Name, OMPC_ADJUST_ARGS_##Name)
158349cc55cSDimitry Andric #include "clang/Basic/OpenMPKinds.def"
159349cc55cSDimitry Andric         .Default(OMPC_ADJUST_ARGS_unknown);
160349cc55cSDimitry Andric   case OMPC_bind:
161349cc55cSDimitry Andric     return llvm::StringSwitch<unsigned>(Str)
162349cc55cSDimitry Andric #define OPENMP_BIND_KIND(Name) .Case(#Name, OMPC_BIND_##Name)
163349cc55cSDimitry Andric #include "clang/Basic/OpenMPKinds.def"
164349cc55cSDimitry Andric         .Default(OMPC_BIND_unknown);
165bdd1243dSDimitry Andric   case OMPC_grainsize: {
166bdd1243dSDimitry Andric     unsigned Type = llvm::StringSwitch<unsigned>(Str)
167bdd1243dSDimitry Andric #define OPENMP_GRAINSIZE_MODIFIER(Name) .Case(#Name, OMPC_GRAINSIZE_##Name)
168bdd1243dSDimitry Andric #include "clang/Basic/OpenMPKinds.def"
169bdd1243dSDimitry Andric                         .Default(OMPC_GRAINSIZE_unknown);
170bdd1243dSDimitry Andric     if (LangOpts.OpenMP < 51)
171bdd1243dSDimitry Andric       return OMPC_GRAINSIZE_unknown;
172bdd1243dSDimitry Andric     return Type;
173bdd1243dSDimitry Andric   }
174bdd1243dSDimitry Andric   case OMPC_num_tasks: {
175bdd1243dSDimitry Andric     unsigned Type = llvm::StringSwitch<unsigned>(Str)
176bdd1243dSDimitry Andric #define OPENMP_NUMTASKS_MODIFIER(Name) .Case(#Name, OMPC_NUMTASKS_##Name)
177bdd1243dSDimitry Andric #include "clang/Basic/OpenMPKinds.def"
178bdd1243dSDimitry Andric                         .Default(OMPC_NUMTASKS_unknown);
179bdd1243dSDimitry Andric     if (LangOpts.OpenMP < 51)
180bdd1243dSDimitry Andric       return OMPC_NUMTASKS_unknown;
181bdd1243dSDimitry Andric     return Type;
182bdd1243dSDimitry Andric   }
1830b57cec5SDimitry Andric   case OMPC_unknown:
1840b57cec5SDimitry Andric   case OMPC_threadprivate:
1850b57cec5SDimitry Andric   case OMPC_if:
1860b57cec5SDimitry Andric   case OMPC_final:
1870b57cec5SDimitry Andric   case OMPC_num_threads:
1880b57cec5SDimitry Andric   case OMPC_safelen:
1890b57cec5SDimitry Andric   case OMPC_simdlen:
190fe6060f1SDimitry Andric   case OMPC_sizes:
1910b57cec5SDimitry Andric   case OMPC_allocator:
1920b57cec5SDimitry Andric   case OMPC_allocate:
1930b57cec5SDimitry Andric   case OMPC_collapse:
1940b57cec5SDimitry Andric   case OMPC_private:
1950b57cec5SDimitry Andric   case OMPC_firstprivate:
1960b57cec5SDimitry Andric   case OMPC_shared:
1970b57cec5SDimitry Andric   case OMPC_task_reduction:
1980b57cec5SDimitry Andric   case OMPC_in_reduction:
1990b57cec5SDimitry Andric   case OMPC_aligned:
2000b57cec5SDimitry Andric   case OMPC_copyin:
2010b57cec5SDimitry Andric   case OMPC_copyprivate:
2020b57cec5SDimitry Andric   case OMPC_ordered:
2030b57cec5SDimitry Andric   case OMPC_nowait:
2040b57cec5SDimitry Andric   case OMPC_untied:
2050b57cec5SDimitry Andric   case OMPC_mergeable:
2060b57cec5SDimitry Andric   case OMPC_flush:
2075ffd83dbSDimitry Andric   case OMPC_depobj:
2080b57cec5SDimitry Andric   case OMPC_read:
2090b57cec5SDimitry Andric   case OMPC_write:
2100b57cec5SDimitry Andric   case OMPC_capture:
2110eae32dcSDimitry Andric   case OMPC_compare:
2120b57cec5SDimitry Andric   case OMPC_seq_cst:
2135ffd83dbSDimitry Andric   case OMPC_acq_rel:
2145ffd83dbSDimitry Andric   case OMPC_acquire:
2155ffd83dbSDimitry Andric   case OMPC_release:
2165ffd83dbSDimitry Andric   case OMPC_relaxed:
2170b57cec5SDimitry Andric   case OMPC_threads:
2180b57cec5SDimitry Andric   case OMPC_simd:
2190b57cec5SDimitry Andric   case OMPC_num_teams:
2200b57cec5SDimitry Andric   case OMPC_thread_limit:
2210b57cec5SDimitry Andric   case OMPC_priority:
2220b57cec5SDimitry Andric   case OMPC_nogroup:
2230b57cec5SDimitry Andric   case OMPC_hint:
2240b57cec5SDimitry Andric   case OMPC_uniform:
2250b57cec5SDimitry Andric   case OMPC_use_device_ptr:
2265ffd83dbSDimitry Andric   case OMPC_use_device_addr:
2270b57cec5SDimitry Andric   case OMPC_is_device_ptr:
22881ad6265SDimitry Andric   case OMPC_has_device_addr:
2290b57cec5SDimitry Andric   case OMPC_unified_address:
2300b57cec5SDimitry Andric   case OMPC_unified_shared_memory:
2310b57cec5SDimitry Andric   case OMPC_reverse_offload:
2320b57cec5SDimitry Andric   case OMPC_dynamic_allocators:
233a7dea167SDimitry Andric   case OMPC_match:
234480093f4SDimitry Andric   case OMPC_nontemporal:
2355ffd83dbSDimitry Andric   case OMPC_destroy:
236fe6060f1SDimitry Andric   case OMPC_novariants:
237fe6060f1SDimitry Andric   case OMPC_nocontext:
2385ffd83dbSDimitry Andric   case OMPC_detach:
2395ffd83dbSDimitry Andric   case OMPC_inclusive:
2405ffd83dbSDimitry Andric   case OMPC_exclusive:
2415ffd83dbSDimitry Andric   case OMPC_uses_allocators:
2425ffd83dbSDimitry Andric   case OMPC_affinity:
243349cc55cSDimitry Andric   case OMPC_when:
244349cc55cSDimitry Andric   case OMPC_append_args:
2455ffd83dbSDimitry Andric     break;
2465ffd83dbSDimitry Andric   default:
2470b57cec5SDimitry Andric     break;
2480b57cec5SDimitry Andric   }
2490b57cec5SDimitry Andric   llvm_unreachable("Invalid OpenMP simple clause kind");
2500b57cec5SDimitry Andric }
2510b57cec5SDimitry Andric 
getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,unsigned Type)2520b57cec5SDimitry Andric const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
2530b57cec5SDimitry Andric                                                  unsigned Type) {
2540b57cec5SDimitry Andric   switch (Kind) {
2550b57cec5SDimitry Andric   case OMPC_default:
2565ffd83dbSDimitry Andric     switch (llvm::omp::DefaultKind(Type)) {
2575ffd83dbSDimitry Andric #define OMP_DEFAULT_KIND(Enum, Name)                                           \
2585ffd83dbSDimitry Andric   case Enum:                                                                   \
2595ffd83dbSDimitry Andric     return Name;
2605ffd83dbSDimitry Andric #include "llvm/Frontend/OpenMP/OMPKinds.def"
2610b57cec5SDimitry Andric     }
2620b57cec5SDimitry Andric     llvm_unreachable("Invalid OpenMP 'default' clause type");
2630b57cec5SDimitry Andric   case OMPC_proc_bind:
2640b57cec5SDimitry Andric     switch (Type) {
265480093f4SDimitry Andric #define OMP_PROC_BIND_KIND(Enum, Name, Value)                                  \
266480093f4SDimitry Andric   case Value:                                                                  \
267480093f4SDimitry Andric     return Name;
268480093f4SDimitry Andric #include "llvm/Frontend/OpenMP/OMPKinds.def"
2690b57cec5SDimitry Andric     }
2700b57cec5SDimitry Andric     llvm_unreachable("Invalid OpenMP 'proc_bind' clause type");
2710b57cec5SDimitry Andric   case OMPC_schedule:
2720b57cec5SDimitry Andric     switch (Type) {
2730b57cec5SDimitry Andric     case OMPC_SCHEDULE_unknown:
2740b57cec5SDimitry Andric     case OMPC_SCHEDULE_MODIFIER_last:
2750b57cec5SDimitry Andric       return "unknown";
2760b57cec5SDimitry Andric #define OPENMP_SCHEDULE_KIND(Name)                                             \
2770b57cec5SDimitry Andric     case OMPC_SCHEDULE_##Name:                                                 \
2780b57cec5SDimitry Andric       return #Name;
2790b57cec5SDimitry Andric #define OPENMP_SCHEDULE_MODIFIER(Name)                                         \
2800b57cec5SDimitry Andric     case OMPC_SCHEDULE_MODIFIER_##Name:                                        \
2810b57cec5SDimitry Andric       return #Name;
2820b57cec5SDimitry Andric #include "clang/Basic/OpenMPKinds.def"
2830b57cec5SDimitry Andric     }
2840b57cec5SDimitry Andric     llvm_unreachable("Invalid OpenMP 'schedule' clause type");
2850b57cec5SDimitry Andric   case OMPC_depend:
2860b57cec5SDimitry Andric     switch (Type) {
2870b57cec5SDimitry Andric     case OMPC_DEPEND_unknown:
2880b57cec5SDimitry Andric       return "unknown";
2890b57cec5SDimitry Andric #define OPENMP_DEPEND_KIND(Name)                                             \
2900b57cec5SDimitry Andric   case OMPC_DEPEND_##Name:                                                   \
2910b57cec5SDimitry Andric     return #Name;
2920b57cec5SDimitry Andric #include "clang/Basic/OpenMPKinds.def"
2930b57cec5SDimitry Andric     }
2940b57cec5SDimitry Andric     llvm_unreachable("Invalid OpenMP 'depend' clause type");
29506c3fb27SDimitry Andric   case OMPC_doacross:
29606c3fb27SDimitry Andric     switch (Type) {
29706c3fb27SDimitry Andric     case OMPC_DOACROSS_unknown:
29806c3fb27SDimitry Andric       return "unknown";
29906c3fb27SDimitry Andric #define OPENMP_DOACROSS_MODIFIER(Name)                                         \
30006c3fb27SDimitry Andric   case OMPC_DOACROSS_##Name:                                                   \
30106c3fb27SDimitry Andric     return #Name;
30206c3fb27SDimitry Andric #include "clang/Basic/OpenMPKinds.def"
30306c3fb27SDimitry Andric     }
30406c3fb27SDimitry Andric     llvm_unreachable("Invalid OpenMP 'doacross' clause type");
3050b57cec5SDimitry Andric   case OMPC_linear:
3060b57cec5SDimitry Andric     switch (Type) {
3070b57cec5SDimitry Andric     case OMPC_LINEAR_unknown:
3080b57cec5SDimitry Andric       return "unknown";
3090b57cec5SDimitry Andric #define OPENMP_LINEAR_KIND(Name)                                             \
3100b57cec5SDimitry Andric   case OMPC_LINEAR_##Name:                                                   \
3110b57cec5SDimitry Andric     return #Name;
3120b57cec5SDimitry Andric #include "clang/Basic/OpenMPKinds.def"
3130b57cec5SDimitry Andric     }
3140b57cec5SDimitry Andric     llvm_unreachable("Invalid OpenMP 'linear' clause type");
3150b57cec5SDimitry Andric   case OMPC_map:
3160b57cec5SDimitry Andric     switch (Type) {
3170b57cec5SDimitry Andric     case OMPC_MAP_unknown:
3180b57cec5SDimitry Andric     case OMPC_MAP_MODIFIER_last:
3190b57cec5SDimitry Andric       return "unknown";
3200b57cec5SDimitry Andric #define OPENMP_MAP_KIND(Name)                                                \
3210b57cec5SDimitry Andric   case OMPC_MAP_##Name:                                                      \
3220b57cec5SDimitry Andric     return #Name;
3230b57cec5SDimitry Andric #define OPENMP_MAP_MODIFIER_KIND(Name)                                       \
3240b57cec5SDimitry Andric   case OMPC_MAP_MODIFIER_##Name:                                             \
3250b57cec5SDimitry Andric     return #Name;
3260b57cec5SDimitry Andric #include "clang/Basic/OpenMPKinds.def"
3270b57cec5SDimitry Andric     default:
3280b57cec5SDimitry Andric       break;
3290b57cec5SDimitry Andric     }
3300b57cec5SDimitry Andric     llvm_unreachable("Invalid OpenMP 'map' clause type");
3310b57cec5SDimitry Andric   case OMPC_to:
3320b57cec5SDimitry Andric   case OMPC_from:
3330b57cec5SDimitry Andric     switch (Type) {
334e8d8bef9SDimitry Andric     case OMPC_MOTION_MODIFIER_unknown:
3350b57cec5SDimitry Andric       return "unknown";
336e8d8bef9SDimitry Andric #define OPENMP_MOTION_MODIFIER_KIND(Name)                                      \
337e8d8bef9SDimitry Andric   case OMPC_MOTION_MODIFIER_##Name:                                            \
3380b57cec5SDimitry Andric     return #Name;
3390b57cec5SDimitry Andric #include "clang/Basic/OpenMPKinds.def"
3400b57cec5SDimitry Andric     default:
3410b57cec5SDimitry Andric       break;
3420b57cec5SDimitry Andric     }
343e8d8bef9SDimitry Andric     llvm_unreachable("Invalid OpenMP 'to' or 'from' clause type");
3440b57cec5SDimitry Andric   case OMPC_dist_schedule:
3450b57cec5SDimitry Andric     switch (Type) {
3460b57cec5SDimitry Andric     case OMPC_DIST_SCHEDULE_unknown:
3470b57cec5SDimitry Andric       return "unknown";
3480b57cec5SDimitry Andric #define OPENMP_DIST_SCHEDULE_KIND(Name)                                      \
3490b57cec5SDimitry Andric   case OMPC_DIST_SCHEDULE_##Name:                                            \
3500b57cec5SDimitry Andric     return #Name;
3510b57cec5SDimitry Andric #include "clang/Basic/OpenMPKinds.def"
3520b57cec5SDimitry Andric     }
3530b57cec5SDimitry Andric     llvm_unreachable("Invalid OpenMP 'dist_schedule' clause type");
3540b57cec5SDimitry Andric   case OMPC_defaultmap:
3550b57cec5SDimitry Andric     switch (Type) {
3560b57cec5SDimitry Andric     case OMPC_DEFAULTMAP_unknown:
3570b57cec5SDimitry Andric     case OMPC_DEFAULTMAP_MODIFIER_last:
3580b57cec5SDimitry Andric       return "unknown";
3590b57cec5SDimitry Andric #define OPENMP_DEFAULTMAP_KIND(Name)                                         \
3600b57cec5SDimitry Andric     case OMPC_DEFAULTMAP_##Name:                                             \
3610b57cec5SDimitry Andric       return #Name;
3620b57cec5SDimitry Andric #define OPENMP_DEFAULTMAP_MODIFIER(Name)                                     \
3630b57cec5SDimitry Andric     case OMPC_DEFAULTMAP_MODIFIER_##Name:                                    \
3640b57cec5SDimitry Andric       return #Name;
3650b57cec5SDimitry Andric #include "clang/Basic/OpenMPKinds.def"
3660b57cec5SDimitry Andric     }
3670b57cec5SDimitry Andric     llvm_unreachable("Invalid OpenMP 'schedule' clause type");
3680b57cec5SDimitry Andric   case OMPC_atomic_default_mem_order:
3690b57cec5SDimitry Andric     switch (Type) {
3700b57cec5SDimitry Andric     case OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown:
3710b57cec5SDimitry Andric       return "unknown";
3720b57cec5SDimitry Andric #define OPENMP_ATOMIC_DEFAULT_MEM_ORDER_KIND(Name)                           \
3730b57cec5SDimitry Andric     case OMPC_ATOMIC_DEFAULT_MEM_ORDER_##Name:                               \
3740b57cec5SDimitry Andric       return #Name;
3750b57cec5SDimitry Andric #include "clang/Basic/OpenMPKinds.def"
3760b57cec5SDimitry Andric }
3770b57cec5SDimitry Andric     llvm_unreachable("Invalid OpenMP 'atomic_default_mem_order' clause type");
378a7dea167SDimitry Andric   case OMPC_device_type:
379a7dea167SDimitry Andric     switch (Type) {
380a7dea167SDimitry Andric     case OMPC_DEVICE_TYPE_unknown:
381a7dea167SDimitry Andric       return "unknown";
382a7dea167SDimitry Andric #define OPENMP_DEVICE_TYPE_KIND(Name)                                          \
383a7dea167SDimitry Andric     case OMPC_DEVICE_TYPE_##Name:                                              \
384a7dea167SDimitry Andric       return #Name;
385a7dea167SDimitry Andric #include "clang/Basic/OpenMPKinds.def"
386a7dea167SDimitry Andric     }
387a7dea167SDimitry Andric     llvm_unreachable("Invalid OpenMP 'device_type' clause type");
388bdd1243dSDimitry Andric   case OMPC_at:
389bdd1243dSDimitry Andric     switch (Type) {
390bdd1243dSDimitry Andric     case OMPC_AT_unknown:
391bdd1243dSDimitry Andric       return "unknown";
392bdd1243dSDimitry Andric #define OPENMP_AT_KIND(Name)                                                   \
393bdd1243dSDimitry Andric   case OMPC_AT_##Name:                                                         \
394bdd1243dSDimitry Andric     return #Name;
395bdd1243dSDimitry Andric #include "clang/Basic/OpenMPKinds.def"
396bdd1243dSDimitry Andric     }
397bdd1243dSDimitry Andric     llvm_unreachable("Invalid OpenMP 'at' clause type");
398bdd1243dSDimitry Andric   case OMPC_severity:
399bdd1243dSDimitry Andric     switch (Type) {
400bdd1243dSDimitry Andric     case OMPC_SEVERITY_unknown:
401bdd1243dSDimitry Andric       return "unknown";
402bdd1243dSDimitry Andric #define OPENMP_SEVERITY_KIND(Name)                                             \
403bdd1243dSDimitry Andric   case OMPC_SEVERITY_##Name:                                                   \
404bdd1243dSDimitry Andric     return #Name;
405bdd1243dSDimitry Andric #include "clang/Basic/OpenMPKinds.def"
406bdd1243dSDimitry Andric     }
407bdd1243dSDimitry Andric     llvm_unreachable("Invalid OpenMP 'severity' clause type");
408480093f4SDimitry Andric   case OMPC_lastprivate:
409480093f4SDimitry Andric     switch (Type) {
410480093f4SDimitry Andric     case OMPC_LASTPRIVATE_unknown:
411480093f4SDimitry Andric       return "unknown";
412480093f4SDimitry Andric #define OPENMP_LASTPRIVATE_KIND(Name)                                          \
413480093f4SDimitry Andric     case OMPC_LASTPRIVATE_##Name:                                              \
414480093f4SDimitry Andric       return #Name;
415480093f4SDimitry Andric #include "clang/Basic/OpenMPKinds.def"
416480093f4SDimitry Andric     }
417480093f4SDimitry Andric     llvm_unreachable("Invalid OpenMP 'lastprivate' clause type");
4185ffd83dbSDimitry Andric   case OMPC_order:
4195ffd83dbSDimitry Andric     switch (Type) {
4205ffd83dbSDimitry Andric     case OMPC_ORDER_unknown:
421bdd1243dSDimitry Andric     case OMPC_ORDER_MODIFIER_last:
4225ffd83dbSDimitry Andric       return "unknown";
4235ffd83dbSDimitry Andric #define OPENMP_ORDER_KIND(Name)                                                \
4245ffd83dbSDimitry Andric   case OMPC_ORDER_##Name:                                                      \
4255ffd83dbSDimitry Andric     return #Name;
426bdd1243dSDimitry Andric #define OPENMP_ORDER_MODIFIER(Name)                                            \
427bdd1243dSDimitry Andric   case OMPC_ORDER_MODIFIER_##Name:                                             \
428bdd1243dSDimitry Andric     return #Name;
4295ffd83dbSDimitry Andric #include "clang/Basic/OpenMPKinds.def"
4305ffd83dbSDimitry Andric     }
4315ffd83dbSDimitry Andric     llvm_unreachable("Invalid OpenMP 'order' clause type");
4325ffd83dbSDimitry Andric   case OMPC_update:
4335ffd83dbSDimitry Andric     switch (Type) {
4345ffd83dbSDimitry Andric     case OMPC_DEPEND_unknown:
4355ffd83dbSDimitry Andric       return "unknown";
4365ffd83dbSDimitry Andric #define OPENMP_DEPEND_KIND(Name)                                               \
4375ffd83dbSDimitry Andric   case OMPC_DEPEND_##Name:                                                     \
4385ffd83dbSDimitry Andric     return #Name;
4395ffd83dbSDimitry Andric #include "clang/Basic/OpenMPKinds.def"
4405ffd83dbSDimitry Andric     }
4415ffd83dbSDimitry Andric     llvm_unreachable("Invalid OpenMP 'depend' clause type");
4425f757f3fSDimitry Andric   case OMPC_fail: {
4435f757f3fSDimitry Andric     OpenMPClauseKind CK = static_cast<OpenMPClauseKind>(Type);
4445f757f3fSDimitry Andric     return getOpenMPClauseName(CK).data();
4455f757f3fSDimitry Andric     llvm_unreachable("Invalid OpenMP 'fail' clause modifier");
4465f757f3fSDimitry Andric   }
4475ffd83dbSDimitry Andric   case OMPC_device:
4485ffd83dbSDimitry Andric     switch (Type) {
4495ffd83dbSDimitry Andric     case OMPC_DEVICE_unknown:
4505ffd83dbSDimitry Andric       return "unknown";
4515ffd83dbSDimitry Andric #define OPENMP_DEVICE_MODIFIER(Name)                                           \
4525ffd83dbSDimitry Andric   case OMPC_DEVICE_##Name:                                                     \
4535ffd83dbSDimitry Andric     return #Name;
4545ffd83dbSDimitry Andric #include "clang/Basic/OpenMPKinds.def"
4555ffd83dbSDimitry Andric     }
4565ffd83dbSDimitry Andric     llvm_unreachable("Invalid OpenMP 'device' clause modifier");
4575ffd83dbSDimitry Andric   case OMPC_reduction:
4585ffd83dbSDimitry Andric     switch (Type) {
4595ffd83dbSDimitry Andric     case OMPC_REDUCTION_unknown:
4605ffd83dbSDimitry Andric       return "unknown";
4615ffd83dbSDimitry Andric #define OPENMP_REDUCTION_MODIFIER(Name)                                        \
4625ffd83dbSDimitry Andric   case OMPC_REDUCTION_##Name:                                                  \
4635ffd83dbSDimitry Andric     return #Name;
4645ffd83dbSDimitry Andric #include "clang/Basic/OpenMPKinds.def"
4655ffd83dbSDimitry Andric     }
4665ffd83dbSDimitry Andric     llvm_unreachable("Invalid OpenMP 'reduction' clause modifier");
467349cc55cSDimitry Andric   case OMPC_adjust_args:
468349cc55cSDimitry Andric     switch (Type) {
469349cc55cSDimitry Andric     case OMPC_ADJUST_ARGS_unknown:
470349cc55cSDimitry Andric       return "unknown";
471349cc55cSDimitry Andric #define OPENMP_ADJUST_ARGS_KIND(Name)                                          \
472349cc55cSDimitry Andric   case OMPC_ADJUST_ARGS_##Name:                                                \
473349cc55cSDimitry Andric     return #Name;
474349cc55cSDimitry Andric #include "clang/Basic/OpenMPKinds.def"
475349cc55cSDimitry Andric     }
476349cc55cSDimitry Andric     llvm_unreachable("Invalid OpenMP 'adjust_args' clause kind");
477349cc55cSDimitry Andric   case OMPC_bind:
478349cc55cSDimitry Andric     switch (Type) {
479349cc55cSDimitry Andric     case OMPC_BIND_unknown:
480349cc55cSDimitry Andric       return "unknown";
481349cc55cSDimitry Andric #define OPENMP_BIND_KIND(Name)                                                 \
482349cc55cSDimitry Andric   case OMPC_BIND_##Name:                                                       \
483349cc55cSDimitry Andric     return #Name;
484349cc55cSDimitry Andric #include "clang/Basic/OpenMPKinds.def"
485349cc55cSDimitry Andric     }
486349cc55cSDimitry Andric     llvm_unreachable("Invalid OpenMP 'bind' clause type");
487bdd1243dSDimitry Andric   case OMPC_grainsize:
488bdd1243dSDimitry Andric     switch (Type) {
489bdd1243dSDimitry Andric     case OMPC_GRAINSIZE_unknown:
490bdd1243dSDimitry Andric       return "unknown";
491bdd1243dSDimitry Andric #define OPENMP_GRAINSIZE_MODIFIER(Name)                                        \
492bdd1243dSDimitry Andric   case OMPC_GRAINSIZE_##Name:                                                  \
493bdd1243dSDimitry Andric     return #Name;
494bdd1243dSDimitry Andric #include "clang/Basic/OpenMPKinds.def"
495bdd1243dSDimitry Andric     }
496bdd1243dSDimitry Andric     llvm_unreachable("Invalid OpenMP 'grainsize' clause modifier");
497bdd1243dSDimitry Andric   case OMPC_num_tasks:
498bdd1243dSDimitry Andric     switch (Type) {
499bdd1243dSDimitry Andric     case OMPC_NUMTASKS_unknown:
500bdd1243dSDimitry Andric       return "unknown";
501bdd1243dSDimitry Andric #define OPENMP_NUMTASKS_MODIFIER(Name)                                         \
502bdd1243dSDimitry Andric   case OMPC_NUMTASKS_##Name:                                                   \
503bdd1243dSDimitry Andric     return #Name;
504bdd1243dSDimitry Andric #include "clang/Basic/OpenMPKinds.def"
505bdd1243dSDimitry Andric     }
506bdd1243dSDimitry Andric     llvm_unreachable("Invalid OpenMP 'num_tasks' clause modifier");
5070b57cec5SDimitry Andric   case OMPC_unknown:
5080b57cec5SDimitry Andric   case OMPC_threadprivate:
5090b57cec5SDimitry Andric   case OMPC_if:
5100b57cec5SDimitry Andric   case OMPC_final:
5110b57cec5SDimitry Andric   case OMPC_num_threads:
5120b57cec5SDimitry Andric   case OMPC_safelen:
5130b57cec5SDimitry Andric   case OMPC_simdlen:
514fe6060f1SDimitry Andric   case OMPC_sizes:
5150b57cec5SDimitry Andric   case OMPC_allocator:
5160b57cec5SDimitry Andric   case OMPC_allocate:
5170b57cec5SDimitry Andric   case OMPC_collapse:
5180b57cec5SDimitry Andric   case OMPC_private:
5190b57cec5SDimitry Andric   case OMPC_firstprivate:
5200b57cec5SDimitry Andric   case OMPC_shared:
5210b57cec5SDimitry Andric   case OMPC_task_reduction:
5220b57cec5SDimitry Andric   case OMPC_in_reduction:
5230b57cec5SDimitry Andric   case OMPC_aligned:
5240b57cec5SDimitry Andric   case OMPC_copyin:
5250b57cec5SDimitry Andric   case OMPC_copyprivate:
5260b57cec5SDimitry Andric   case OMPC_ordered:
5270b57cec5SDimitry Andric   case OMPC_nowait:
5280b57cec5SDimitry Andric   case OMPC_untied:
5290b57cec5SDimitry Andric   case OMPC_mergeable:
5300b57cec5SDimitry Andric   case OMPC_flush:
5315ffd83dbSDimitry Andric   case OMPC_depobj:
5320b57cec5SDimitry Andric   case OMPC_read:
5330b57cec5SDimitry Andric   case OMPC_write:
5340b57cec5SDimitry Andric   case OMPC_capture:
5350eae32dcSDimitry Andric   case OMPC_compare:
5360b57cec5SDimitry Andric   case OMPC_seq_cst:
5375ffd83dbSDimitry Andric   case OMPC_acq_rel:
5385ffd83dbSDimitry Andric   case OMPC_acquire:
5395ffd83dbSDimitry Andric   case OMPC_release:
5405ffd83dbSDimitry Andric   case OMPC_relaxed:
5410b57cec5SDimitry Andric   case OMPC_threads:
5420b57cec5SDimitry Andric   case OMPC_simd:
5430b57cec5SDimitry Andric   case OMPC_num_teams:
5440b57cec5SDimitry Andric   case OMPC_thread_limit:
5450b57cec5SDimitry Andric   case OMPC_priority:
5460b57cec5SDimitry Andric   case OMPC_nogroup:
5470b57cec5SDimitry Andric   case OMPC_hint:
5480b57cec5SDimitry Andric   case OMPC_uniform:
5490b57cec5SDimitry Andric   case OMPC_use_device_ptr:
5505ffd83dbSDimitry Andric   case OMPC_use_device_addr:
5510b57cec5SDimitry Andric   case OMPC_is_device_ptr:
55281ad6265SDimitry Andric   case OMPC_has_device_addr:
5530b57cec5SDimitry Andric   case OMPC_unified_address:
5540b57cec5SDimitry Andric   case OMPC_unified_shared_memory:
5550b57cec5SDimitry Andric   case OMPC_reverse_offload:
5560b57cec5SDimitry Andric   case OMPC_dynamic_allocators:
557a7dea167SDimitry Andric   case OMPC_match:
558480093f4SDimitry Andric   case OMPC_nontemporal:
5595ffd83dbSDimitry Andric   case OMPC_destroy:
5605ffd83dbSDimitry Andric   case OMPC_detach:
561fe6060f1SDimitry Andric   case OMPC_novariants:
562fe6060f1SDimitry Andric   case OMPC_nocontext:
5635ffd83dbSDimitry Andric   case OMPC_inclusive:
5645ffd83dbSDimitry Andric   case OMPC_exclusive:
5655ffd83dbSDimitry Andric   case OMPC_uses_allocators:
5665ffd83dbSDimitry Andric   case OMPC_affinity:
567349cc55cSDimitry Andric   case OMPC_when:
568349cc55cSDimitry Andric   case OMPC_append_args:
5695ffd83dbSDimitry Andric     break;
5705ffd83dbSDimitry Andric   default:
5710b57cec5SDimitry Andric     break;
5720b57cec5SDimitry Andric   }
5730b57cec5SDimitry Andric   llvm_unreachable("Invalid OpenMP simple clause kind");
5740b57cec5SDimitry Andric }
5750b57cec5SDimitry Andric 
isOpenMPLoopDirective(OpenMPDirectiveKind DKind)5760b57cec5SDimitry Andric bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
577*0fca6ea1SDimitry Andric   return getDirectiveAssociation(DKind) == Association::Loop;
5780b57cec5SDimitry Andric }
5790b57cec5SDimitry Andric 
isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind)5800b57cec5SDimitry Andric bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
5810b57cec5SDimitry Andric   return DKind == OMPD_for || DKind == OMPD_for_simd ||
5820b57cec5SDimitry Andric          DKind == OMPD_sections || DKind == OMPD_section ||
5830b57cec5SDimitry Andric          DKind == OMPD_single || DKind == OMPD_parallel_for ||
5840b57cec5SDimitry Andric          DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
5850b57cec5SDimitry Andric          DKind == OMPD_target_parallel_for ||
5860b57cec5SDimitry Andric          DKind == OMPD_distribute_parallel_for ||
5870b57cec5SDimitry Andric          DKind == OMPD_distribute_parallel_for_simd ||
5880b57cec5SDimitry Andric          DKind == OMPD_target_parallel_for_simd ||
5890b57cec5SDimitry Andric          DKind == OMPD_teams_distribute_parallel_for_simd ||
5900b57cec5SDimitry Andric          DKind == OMPD_teams_distribute_parallel_for ||
5910b57cec5SDimitry Andric          DKind == OMPD_target_teams_distribute_parallel_for ||
59206c3fb27SDimitry Andric          DKind == OMPD_target_teams_distribute_parallel_for_simd ||
59306c3fb27SDimitry Andric          DKind == OMPD_parallel_loop || DKind == OMPD_teams_loop ||
59406c3fb27SDimitry Andric          DKind == OMPD_target_parallel_loop || DKind == OMPD_target_teams_loop;
5950b57cec5SDimitry Andric }
5960b57cec5SDimitry Andric 
isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind)5970b57cec5SDimitry Andric bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
598*0fca6ea1SDimitry Andric   return DKind == OMPD_taskloop ||
599*0fca6ea1SDimitry Andric          llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
6000b57cec5SDimitry Andric }
6010b57cec5SDimitry Andric 
isOpenMPParallelDirective(OpenMPDirectiveKind DKind)6020b57cec5SDimitry Andric bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
603*0fca6ea1SDimitry Andric   if (DKind == OMPD_teams_loop)
604*0fca6ea1SDimitry Andric     return true;
605*0fca6ea1SDimitry Andric   return DKind == OMPD_parallel ||
606*0fca6ea1SDimitry Andric          llvm::is_contained(getLeafConstructs(DKind), OMPD_parallel);
6070b57cec5SDimitry Andric }
6080b57cec5SDimitry Andric 
isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind)6090b57cec5SDimitry Andric bool clang::isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind) {
610*0fca6ea1SDimitry Andric   return DKind == OMPD_target ||
611*0fca6ea1SDimitry Andric          llvm::is_contained(getLeafConstructs(DKind), OMPD_target);
6120b57cec5SDimitry Andric }
6130b57cec5SDimitry Andric 
isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind)6140b57cec5SDimitry Andric bool clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
6150b57cec5SDimitry Andric   return DKind == OMPD_target_data || DKind == OMPD_target_enter_data ||
6160b57cec5SDimitry Andric          DKind == OMPD_target_exit_data || DKind == OMPD_target_update;
6170b57cec5SDimitry Andric }
6180b57cec5SDimitry Andric 
isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind)6190b57cec5SDimitry Andric bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
620*0fca6ea1SDimitry Andric   if (DKind == OMPD_teams)
621*0fca6ea1SDimitry Andric     return true;
622*0fca6ea1SDimitry Andric   ArrayRef<Directive> Leaves = getLeafConstructs(DKind);
623*0fca6ea1SDimitry Andric   return !Leaves.empty() && Leaves.front() == OMPD_teams;
6240b57cec5SDimitry Andric }
6250b57cec5SDimitry Andric 
isOpenMPTeamsDirective(OpenMPDirectiveKind DKind)6260b57cec5SDimitry Andric bool clang::isOpenMPTeamsDirective(OpenMPDirectiveKind DKind) {
627*0fca6ea1SDimitry Andric   return DKind == OMPD_teams ||
628*0fca6ea1SDimitry Andric          llvm::is_contained(getLeafConstructs(DKind), OMPD_teams);
6290b57cec5SDimitry Andric }
6300b57cec5SDimitry Andric 
isOpenMPSimdDirective(OpenMPDirectiveKind DKind)6310b57cec5SDimitry Andric bool clang::isOpenMPSimdDirective(OpenMPDirectiveKind DKind) {
632*0fca6ea1SDimitry Andric   // Avoid OMPD_declare_simd
633*0fca6ea1SDimitry Andric   if (getDirectiveAssociation(DKind) != Association::Loop)
634*0fca6ea1SDimitry Andric     return false;
635*0fca6ea1SDimitry Andric   // Formally, OMPD_end_do_simd also has a loop association, but
636*0fca6ea1SDimitry Andric   // it's a Fortran-specific directive.
637*0fca6ea1SDimitry Andric 
638*0fca6ea1SDimitry Andric   return DKind == OMPD_simd ||
639*0fca6ea1SDimitry Andric          llvm::is_contained(getLeafConstructs(DKind), OMPD_simd);
6400b57cec5SDimitry Andric }
6410b57cec5SDimitry Andric 
isOpenMPNestingDistributeDirective(OpenMPDirectiveKind Kind)6420b57cec5SDimitry Andric bool clang::isOpenMPNestingDistributeDirective(OpenMPDirectiveKind Kind) {
643*0fca6ea1SDimitry Andric   if (Kind == OMPD_distribute)
644*0fca6ea1SDimitry Andric     return true;
645*0fca6ea1SDimitry Andric   ArrayRef<Directive> Leaves = getLeafConstructs(Kind);
646*0fca6ea1SDimitry Andric   return !Leaves.empty() && Leaves.front() == OMPD_distribute;
6470b57cec5SDimitry Andric }
6480b57cec5SDimitry Andric 
isOpenMPDistributeDirective(OpenMPDirectiveKind Kind)6490b57cec5SDimitry Andric bool clang::isOpenMPDistributeDirective(OpenMPDirectiveKind Kind) {
650*0fca6ea1SDimitry Andric   return Kind == OMPD_distribute ||
651*0fca6ea1SDimitry Andric          llvm::is_contained(getLeafConstructs(Kind), OMPD_distribute);
6520b57cec5SDimitry Andric }
6530b57cec5SDimitry Andric 
isOpenMPGenericLoopDirective(OpenMPDirectiveKind Kind)654349cc55cSDimitry Andric bool clang::isOpenMPGenericLoopDirective(OpenMPDirectiveKind Kind) {
655*0fca6ea1SDimitry Andric   if (Kind == OMPD_loop)
656*0fca6ea1SDimitry Andric     return true;
657*0fca6ea1SDimitry Andric   ArrayRef<Directive> Leaves = getLeafConstructs(Kind);
658*0fca6ea1SDimitry Andric   return !Leaves.empty() && Leaves.back() == OMPD_loop;
659349cc55cSDimitry Andric }
660349cc55cSDimitry Andric 
isOpenMPPrivate(OpenMPClauseKind Kind)6610b57cec5SDimitry Andric bool clang::isOpenMPPrivate(OpenMPClauseKind Kind) {
6620b57cec5SDimitry Andric   return Kind == OMPC_private || Kind == OMPC_firstprivate ||
6630b57cec5SDimitry Andric          Kind == OMPC_lastprivate || Kind == OMPC_linear ||
6640b57cec5SDimitry Andric          Kind == OMPC_reduction || Kind == OMPC_task_reduction ||
6650b57cec5SDimitry Andric          Kind == OMPC_in_reduction; // TODO add next clauses like 'reduction'.
6660b57cec5SDimitry Andric }
6670b57cec5SDimitry Andric 
isOpenMPThreadPrivate(OpenMPClauseKind Kind)6680b57cec5SDimitry Andric bool clang::isOpenMPThreadPrivate(OpenMPClauseKind Kind) {
6690b57cec5SDimitry Andric   return Kind == OMPC_threadprivate || Kind == OMPC_copyin;
6700b57cec5SDimitry Andric }
6710b57cec5SDimitry Andric 
isOpenMPTaskingDirective(OpenMPDirectiveKind Kind)6720b57cec5SDimitry Andric bool clang::isOpenMPTaskingDirective(OpenMPDirectiveKind Kind) {
6730b57cec5SDimitry Andric   return Kind == OMPD_task || isOpenMPTaskLoopDirective(Kind);
6740b57cec5SDimitry Andric }
6750b57cec5SDimitry Andric 
isOpenMPLoopBoundSharingDirective(OpenMPDirectiveKind Kind)6760b57cec5SDimitry Andric bool clang::isOpenMPLoopBoundSharingDirective(OpenMPDirectiveKind Kind) {
6770b57cec5SDimitry Andric   return Kind == OMPD_distribute_parallel_for ||
6780b57cec5SDimitry Andric          Kind == OMPD_distribute_parallel_for_simd ||
6790b57cec5SDimitry Andric          Kind == OMPD_teams_distribute_parallel_for_simd ||
6800b57cec5SDimitry Andric          Kind == OMPD_teams_distribute_parallel_for ||
6810b57cec5SDimitry Andric          Kind == OMPD_target_teams_distribute_parallel_for ||
68206c3fb27SDimitry Andric          Kind == OMPD_target_teams_distribute_parallel_for_simd ||
68306c3fb27SDimitry Andric          Kind == OMPD_teams_loop || Kind == OMPD_target_teams_loop;
6840b57cec5SDimitry Andric }
6850b57cec5SDimitry Andric 
isOpenMPLoopTransformationDirective(OpenMPDirectiveKind DKind)686fe6060f1SDimitry Andric bool clang::isOpenMPLoopTransformationDirective(OpenMPDirectiveKind DKind) {
687*0fca6ea1SDimitry Andric   return DKind == OMPD_tile || DKind == OMPD_unroll || DKind == OMPD_reverse ||
688*0fca6ea1SDimitry Andric          DKind == OMPD_interchange;
689fe6060f1SDimitry Andric }
690fe6060f1SDimitry Andric 
isOpenMPCombinedParallelADirective(OpenMPDirectiveKind DKind)691bdd1243dSDimitry Andric bool clang::isOpenMPCombinedParallelADirective(OpenMPDirectiveKind DKind) {
692bdd1243dSDimitry Andric   return DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
693bdd1243dSDimitry Andric          DKind == OMPD_parallel_master ||
694bdd1243dSDimitry Andric          DKind == OMPD_parallel_master_taskloop ||
695bdd1243dSDimitry Andric          DKind == OMPD_parallel_master_taskloop_simd ||
696bdd1243dSDimitry Andric          DKind == OMPD_parallel_sections;
697bdd1243dSDimitry Andric }
698bdd1243dSDimitry Andric 
needsTaskBasedThreadLimit(OpenMPDirectiveKind DKind)6995f757f3fSDimitry Andric bool clang::needsTaskBasedThreadLimit(OpenMPDirectiveKind DKind) {
7005f757f3fSDimitry Andric   return DKind == OMPD_target || DKind == OMPD_target_parallel ||
7015f757f3fSDimitry Andric          DKind == OMPD_target_parallel_for ||
7025f757f3fSDimitry Andric          DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
7035f757f3fSDimitry Andric          DKind == OMPD_target_parallel_loop;
7045f757f3fSDimitry Andric }
7055f757f3fSDimitry Andric 
isOpenMPExecutableDirective(OpenMPDirectiveKind DKind)706*0fca6ea1SDimitry Andric bool clang::isOpenMPExecutableDirective(OpenMPDirectiveKind DKind) {
707*0fca6ea1SDimitry Andric   if (DKind == OMPD_error)
708*0fca6ea1SDimitry Andric     return true;
709*0fca6ea1SDimitry Andric   Category Cat = getDirectiveCategory(DKind);
710*0fca6ea1SDimitry Andric   return Cat == Category::Executable || Cat == Category::Subsidiary;
711*0fca6ea1SDimitry Andric }
712*0fca6ea1SDimitry Andric 
isOpenMPCapturingDirective(OpenMPDirectiveKind DKind)713*0fca6ea1SDimitry Andric bool clang::isOpenMPCapturingDirective(OpenMPDirectiveKind DKind) {
714*0fca6ea1SDimitry Andric   if (isOpenMPExecutableDirective(DKind)) {
715*0fca6ea1SDimitry Andric     switch (DKind) {
716*0fca6ea1SDimitry Andric     case OMPD_atomic:
717*0fca6ea1SDimitry Andric     case OMPD_barrier:
718*0fca6ea1SDimitry Andric     case OMPD_cancel:
719*0fca6ea1SDimitry Andric     case OMPD_cancellation_point:
720*0fca6ea1SDimitry Andric     case OMPD_critical:
721*0fca6ea1SDimitry Andric     case OMPD_depobj:
722*0fca6ea1SDimitry Andric     case OMPD_error:
723*0fca6ea1SDimitry Andric     case OMPD_flush:
724*0fca6ea1SDimitry Andric     case OMPD_masked:
725*0fca6ea1SDimitry Andric     case OMPD_master:
726*0fca6ea1SDimitry Andric     case OMPD_section:
727*0fca6ea1SDimitry Andric     case OMPD_taskwait:
728*0fca6ea1SDimitry Andric     case OMPD_taskyield:
729*0fca6ea1SDimitry Andric       return false;
730*0fca6ea1SDimitry Andric     default:
731*0fca6ea1SDimitry Andric       return !isOpenMPLoopTransformationDirective(DKind);
732*0fca6ea1SDimitry Andric     }
733*0fca6ea1SDimitry Andric   }
734*0fca6ea1SDimitry Andric   // Non-executable directives.
735*0fca6ea1SDimitry Andric   switch (DKind) {
736*0fca6ea1SDimitry Andric   case OMPD_metadirective:
737*0fca6ea1SDimitry Andric   case OMPD_nothing:
738*0fca6ea1SDimitry Andric     return true;
739*0fca6ea1SDimitry Andric   default:
740*0fca6ea1SDimitry Andric     break;
741*0fca6ea1SDimitry Andric   }
742*0fca6ea1SDimitry Andric   return false;
743*0fca6ea1SDimitry Andric }
744*0fca6ea1SDimitry Andric 
getOpenMPCaptureRegions(SmallVectorImpl<OpenMPDirectiveKind> & CaptureRegions,OpenMPDirectiveKind DKind)7450b57cec5SDimitry Andric void clang::getOpenMPCaptureRegions(
7460b57cec5SDimitry Andric     SmallVectorImpl<OpenMPDirectiveKind> &CaptureRegions,
7470b57cec5SDimitry Andric     OpenMPDirectiveKind DKind) {
7485ffd83dbSDimitry Andric   assert(unsigned(DKind) < llvm::omp::Directive_enumSize);
749*0fca6ea1SDimitry Andric   assert(isOpenMPCapturingDirective(DKind) && "Expecting capturing directive");
750*0fca6ea1SDimitry Andric 
751*0fca6ea1SDimitry Andric   auto GetRegionsForLeaf = [&](OpenMPDirectiveKind LKind) {
752*0fca6ea1SDimitry Andric     assert(isLeafConstruct(LKind) && "Epecting leaf directive");
753*0fca6ea1SDimitry Andric     // Whether a leaf would require OMPD_unknown if it occured on its own.
754*0fca6ea1SDimitry Andric     switch (LKind) {
755349cc55cSDimitry Andric     case OMPD_metadirective:
756349cc55cSDimitry Andric       CaptureRegions.push_back(OMPD_metadirective);
757349cc55cSDimitry Andric       break;
758*0fca6ea1SDimitry Andric     case OMPD_nothing:
759*0fca6ea1SDimitry Andric       CaptureRegions.push_back(OMPD_nothing);
760*0fca6ea1SDimitry Andric       break;
7610b57cec5SDimitry Andric     case OMPD_parallel:
7620b57cec5SDimitry Andric       CaptureRegions.push_back(OMPD_parallel);
7630b57cec5SDimitry Andric       break;
7640b57cec5SDimitry Andric     case OMPD_target:
7650b57cec5SDimitry Andric       CaptureRegions.push_back(OMPD_task);
7660b57cec5SDimitry Andric       CaptureRegions.push_back(OMPD_target);
7670b57cec5SDimitry Andric       break;
7680b57cec5SDimitry Andric     case OMPD_task:
7690b57cec5SDimitry Andric     case OMPD_target_enter_data:
7700b57cec5SDimitry Andric     case OMPD_target_exit_data:
7710b57cec5SDimitry Andric     case OMPD_target_update:
7720b57cec5SDimitry Andric       CaptureRegions.push_back(OMPD_task);
7730b57cec5SDimitry Andric       break;
774*0fca6ea1SDimitry Andric     case OMPD_teams:
7750b57cec5SDimitry Andric       CaptureRegions.push_back(OMPD_teams);
7760b57cec5SDimitry Andric       break;
777*0fca6ea1SDimitry Andric     case OMPD_taskloop:
778*0fca6ea1SDimitry Andric       CaptureRegions.push_back(OMPD_taskloop);
77981ad6265SDimitry Andric       break;
780349cc55cSDimitry Andric     case OMPD_loop:
781*0fca6ea1SDimitry Andric       // TODO: 'loop' may require different capture regions depending on the
782*0fca6ea1SDimitry Andric       // bind clause or the parent directive when there is no bind clause.
783*0fca6ea1SDimitry Andric       // If any of the directives that push regions here are parents of 'loop',
784*0fca6ea1SDimitry Andric       // assume 'parallel'. Otherwise do nothing.
785*0fca6ea1SDimitry Andric       if (!CaptureRegions.empty() &&
786*0fca6ea1SDimitry Andric           !llvm::is_contained(CaptureRegions, OMPD_parallel))
787*0fca6ea1SDimitry Andric         CaptureRegions.push_back(OMPD_parallel);
788*0fca6ea1SDimitry Andric       else
789*0fca6ea1SDimitry Andric         return true;
790*0fca6ea1SDimitry Andric       break;
791fe6060f1SDimitry Andric     case OMPD_dispatch:
792*0fca6ea1SDimitry Andric     case OMPD_distribute:
793*0fca6ea1SDimitry Andric     case OMPD_for:
794*0fca6ea1SDimitry Andric     case OMPD_masked:
795*0fca6ea1SDimitry Andric     case OMPD_master:
796*0fca6ea1SDimitry Andric     case OMPD_ordered:
797*0fca6ea1SDimitry Andric     case OMPD_scope:
798*0fca6ea1SDimitry Andric     case OMPD_sections:
799*0fca6ea1SDimitry Andric     case OMPD_simd:
800*0fca6ea1SDimitry Andric     case OMPD_single:
801*0fca6ea1SDimitry Andric     case OMPD_target_data:
802*0fca6ea1SDimitry Andric     case OMPD_taskgroup:
803*0fca6ea1SDimitry Andric       // These directives (when standalone) use OMPD_unknown as the region,
804*0fca6ea1SDimitry Andric       // but when they're constituents of a compound directive, and other
805*0fca6ea1SDimitry Andric       // leafs from that directive have specific regions, then these directives
806*0fca6ea1SDimitry Andric       // add no additional regions.
807*0fca6ea1SDimitry Andric       return true;
8085ffd83dbSDimitry Andric     default:
809*0fca6ea1SDimitry Andric       llvm::errs() << getOpenMPDirectiveName(LKind) << '\n';
810*0fca6ea1SDimitry Andric       llvm_unreachable("Unexpected directive");
8110b57cec5SDimitry Andric     }
812*0fca6ea1SDimitry Andric     return false;
813*0fca6ea1SDimitry Andric   };
814*0fca6ea1SDimitry Andric 
815*0fca6ea1SDimitry Andric   bool MayNeedUnknownRegion = false;
816*0fca6ea1SDimitry Andric   for (OpenMPDirectiveKind L : getLeafConstructsOrSelf(DKind))
817*0fca6ea1SDimitry Andric     MayNeedUnknownRegion |= GetRegionsForLeaf(L);
818*0fca6ea1SDimitry Andric 
819*0fca6ea1SDimitry Andric   // We need OMPD_unknown when no regions were added, and specific leaf
820*0fca6ea1SDimitry Andric   // constructs were present. Push a single OMPD_unknown as the capture
821*0fca6ea1SDimitry Andric   /// region.
822*0fca6ea1SDimitry Andric   if (CaptureRegions.empty() && MayNeedUnknownRegion)
823*0fca6ea1SDimitry Andric     CaptureRegions.push_back(OMPD_unknown);
824*0fca6ea1SDimitry Andric 
825*0fca6ea1SDimitry Andric   // OMPD_unknown is only expected as the only region. If other regions
826*0fca6ea1SDimitry Andric   // are present OMPD_unknown should not be present.
827*0fca6ea1SDimitry Andric   assert((CaptureRegions[0] == OMPD_unknown ||
828*0fca6ea1SDimitry Andric           !llvm::is_contained(CaptureRegions, OMPD_unknown)) &&
829*0fca6ea1SDimitry Andric          "Misplaced OMPD_unknown");
8300b57cec5SDimitry Andric }
8315f757f3fSDimitry Andric 
checkFailClauseParameter(OpenMPClauseKind FailClauseParameter)8325f757f3fSDimitry Andric bool clang::checkFailClauseParameter(OpenMPClauseKind FailClauseParameter) {
8335f757f3fSDimitry Andric   return FailClauseParameter == llvm::omp::OMPC_acquire ||
8345f757f3fSDimitry Andric          FailClauseParameter == llvm::omp::OMPC_relaxed ||
8355f757f3fSDimitry Andric          FailClauseParameter == llvm::omp::OMPC_seq_cst;
8365f757f3fSDimitry Andric }
8375f757f3fSDimitry Andric 
838