1 //===--- OpenMPKinds.cpp - Token Kinds Support ----------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// \brief This file implements the OpenMP enum and support functions.
12 //===----------------------------------------------------------------------===//
14 #include "clang/Basic/OpenMPKinds.h"
15 #include "clang/Basic/IdentifierTable.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/ADT/StringSwitch.h"
18 #include "llvm/Support/ErrorHandling.h"
21 using namespace clang;
23 OpenMPDirectiveKind clang::getOpenMPDirectiveKind(StringRef Str) {
24 return llvm::StringSwitch<OpenMPDirectiveKind>(Str)
25 #define OPENMP_DIRECTIVE(Name) .Case(#Name, OMPD_##Name)
26 #define OPENMP_DIRECTIVE_EXT(Name, Str) .Case(Str, OMPD_##Name)
27 #include "clang/Basic/OpenMPKinds.def"
28 .Default(OMPD_unknown);
31 const char *clang::getOpenMPDirectiveName(OpenMPDirectiveKind Kind) {
32 assert(Kind <= OMPD_unknown);
36 #define OPENMP_DIRECTIVE(Name) \
39 #define OPENMP_DIRECTIVE_EXT(Name, Str) \
42 #include "clang/Basic/OpenMPKinds.def"
45 llvm_unreachable("Invalid OpenMP directive kind");
48 OpenMPClauseKind clang::getOpenMPClauseKind(StringRef Str) {
49 // 'flush' clause cannot be specified explicitly, because this is an implicit
50 // clause for 'flush' directive. If the 'flush' clause is explicitly specified
51 // the Parser should generate a warning about extra tokens at the end of the
55 return llvm::StringSwitch<OpenMPClauseKind>(Str)
56 #define OPENMP_CLAUSE(Name, Class) .Case(#Name, OMPC_##Name)
57 #include "clang/Basic/OpenMPKinds.def"
58 .Case("uniform", OMPC_uniform)
59 .Default(OMPC_unknown);
62 const char *clang::getOpenMPClauseName(OpenMPClauseKind Kind) {
63 assert(Kind <= OMPC_unknown);
67 #define OPENMP_CLAUSE(Name, Class) \
70 #include "clang/Basic/OpenMPKinds.def"
73 case OMPC_threadprivate:
74 return "threadprivate or thread local";
76 llvm_unreachable("Invalid OpenMP clause kind");
79 unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind,
83 return llvm::StringSwitch<OpenMPDefaultClauseKind>(Str)
84 #define OPENMP_DEFAULT_KIND(Name) .Case(#Name, OMPC_DEFAULT_##Name)
85 #include "clang/Basic/OpenMPKinds.def"
86 .Default(OMPC_DEFAULT_unknown);
88 return llvm::StringSwitch<OpenMPProcBindClauseKind>(Str)
89 #define OPENMP_PROC_BIND_KIND(Name) .Case(#Name, OMPC_PROC_BIND_##Name)
90 #include "clang/Basic/OpenMPKinds.def"
91 .Default(OMPC_PROC_BIND_unknown);
93 return llvm::StringSwitch<unsigned>(Str)
94 #define OPENMP_SCHEDULE_KIND(Name) \
95 .Case(#Name, static_cast<unsigned>(OMPC_SCHEDULE_##Name))
96 #define OPENMP_SCHEDULE_MODIFIER(Name) \
97 .Case(#Name, static_cast<unsigned>(OMPC_SCHEDULE_MODIFIER_##Name))
98 #include "clang/Basic/OpenMPKinds.def"
99 .Default(OMPC_SCHEDULE_unknown);
101 return llvm::StringSwitch<OpenMPDependClauseKind>(Str)
102 #define OPENMP_DEPEND_KIND(Name) .Case(#Name, OMPC_DEPEND_##Name)
103 #include "clang/Basic/OpenMPKinds.def"
104 .Default(OMPC_DEPEND_unknown);
106 return llvm::StringSwitch<OpenMPLinearClauseKind>(Str)
107 #define OPENMP_LINEAR_KIND(Name) .Case(#Name, OMPC_LINEAR_##Name)
108 #include "clang/Basic/OpenMPKinds.def"
109 .Default(OMPC_LINEAR_unknown);
111 return llvm::StringSwitch<OpenMPMapClauseKind>(Str)
112 #define OPENMP_MAP_KIND(Name) .Case(#Name, OMPC_MAP_##Name)
113 #include "clang/Basic/OpenMPKinds.def"
114 .Default(OMPC_MAP_unknown);
115 case OMPC_dist_schedule:
116 return llvm::StringSwitch<OpenMPDistScheduleClauseKind>(Str)
117 #define OPENMP_DIST_SCHEDULE_KIND(Name) .Case(#Name, OMPC_DIST_SCHEDULE_##Name)
118 #include "clang/Basic/OpenMPKinds.def"
119 .Default(OMPC_DIST_SCHEDULE_unknown);
120 case OMPC_defaultmap:
121 return llvm::StringSwitch<unsigned>(Str)
122 #define OPENMP_DEFAULTMAP_KIND(Name) \
123 .Case(#Name, static_cast<unsigned>(OMPC_DEFAULTMAP_##Name))
124 #define OPENMP_DEFAULTMAP_MODIFIER(Name) \
125 .Case(#Name, static_cast<unsigned>(OMPC_DEFAULTMAP_MODIFIER_##Name))
126 #include "clang/Basic/OpenMPKinds.def"
127 .Default(OMPC_DEFAULTMAP_unknown);
129 case OMPC_threadprivate:
132 case OMPC_num_threads:
137 case OMPC_firstprivate:
138 case OMPC_lastprivate:
143 case OMPC_copyprivate:
158 case OMPC_thread_limit:
167 case OMPC_use_device_ptr:
168 case OMPC_is_device_ptr:
171 llvm_unreachable("Invalid OpenMP simple clause kind");
174 const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
179 case OMPC_DEFAULT_unknown:
181 #define OPENMP_DEFAULT_KIND(Name) \
182 case OMPC_DEFAULT_##Name: \
184 #include "clang/Basic/OpenMPKinds.def"
186 llvm_unreachable("Invalid OpenMP 'default' clause type");
189 case OMPC_PROC_BIND_unknown:
191 #define OPENMP_PROC_BIND_KIND(Name) \
192 case OMPC_PROC_BIND_##Name: \
194 #include "clang/Basic/OpenMPKinds.def"
196 llvm_unreachable("Invalid OpenMP 'proc_bind' clause type");
199 case OMPC_SCHEDULE_unknown:
200 case OMPC_SCHEDULE_MODIFIER_last:
202 #define OPENMP_SCHEDULE_KIND(Name) \
203 case OMPC_SCHEDULE_##Name: \
205 #define OPENMP_SCHEDULE_MODIFIER(Name) \
206 case OMPC_SCHEDULE_MODIFIER_##Name: \
208 #include "clang/Basic/OpenMPKinds.def"
210 llvm_unreachable("Invalid OpenMP 'schedule' clause type");
213 case OMPC_DEPEND_unknown:
215 #define OPENMP_DEPEND_KIND(Name) \
216 case OMPC_DEPEND_##Name: \
218 #include "clang/Basic/OpenMPKinds.def"
220 llvm_unreachable("Invalid OpenMP 'depend' clause type");
223 case OMPC_LINEAR_unknown:
225 #define OPENMP_LINEAR_KIND(Name) \
226 case OMPC_LINEAR_##Name: \
228 #include "clang/Basic/OpenMPKinds.def"
230 llvm_unreachable("Invalid OpenMP 'linear' clause type");
233 case OMPC_MAP_unknown:
235 #define OPENMP_MAP_KIND(Name) \
236 case OMPC_MAP_##Name: \
238 #include "clang/Basic/OpenMPKinds.def"
242 llvm_unreachable("Invalid OpenMP 'map' clause type");
243 case OMPC_dist_schedule:
245 case OMPC_DIST_SCHEDULE_unknown:
247 #define OPENMP_DIST_SCHEDULE_KIND(Name) \
248 case OMPC_DIST_SCHEDULE_##Name: \
250 #include "clang/Basic/OpenMPKinds.def"
252 llvm_unreachable("Invalid OpenMP 'dist_schedule' clause type");
253 case OMPC_defaultmap:
255 case OMPC_DEFAULTMAP_unknown:
256 case OMPC_DEFAULTMAP_MODIFIER_last:
258 #define OPENMP_DEFAULTMAP_KIND(Name) \
259 case OMPC_DEFAULTMAP_##Name: \
261 #define OPENMP_DEFAULTMAP_MODIFIER(Name) \
262 case OMPC_DEFAULTMAP_MODIFIER_##Name: \
264 #include "clang/Basic/OpenMPKinds.def"
266 llvm_unreachable("Invalid OpenMP 'schedule' clause type");
268 case OMPC_threadprivate:
271 case OMPC_num_threads:
276 case OMPC_firstprivate:
277 case OMPC_lastprivate:
282 case OMPC_copyprivate:
297 case OMPC_thread_limit:
306 case OMPC_use_device_ptr:
307 case OMPC_is_device_ptr:
310 llvm_unreachable("Invalid OpenMP simple clause kind");
313 bool clang::isAllowedClauseForDirective(OpenMPDirectiveKind DKind,
314 OpenMPClauseKind CKind) {
315 assert(DKind <= OMPD_unknown);
316 assert(CKind <= OMPC_unknown);
320 #define OPENMP_PARALLEL_CLAUSE(Name) \
323 #include "clang/Basic/OpenMPKinds.def"
330 #define OPENMP_SIMD_CLAUSE(Name) \
333 #include "clang/Basic/OpenMPKinds.def"
340 #define OPENMP_FOR_CLAUSE(Name) \
343 #include "clang/Basic/OpenMPKinds.def"
350 #define OPENMP_FOR_SIMD_CLAUSE(Name) \
353 #include "clang/Basic/OpenMPKinds.def"
360 #define OPENMP_SECTIONS_CLAUSE(Name) \
363 #include "clang/Basic/OpenMPKinds.def"
370 #define OPENMP_SINGLE_CLAUSE(Name) \
373 #include "clang/Basic/OpenMPKinds.def"
378 case OMPD_parallel_for:
380 #define OPENMP_PARALLEL_FOR_CLAUSE(Name) \
383 #include "clang/Basic/OpenMPKinds.def"
388 case OMPD_parallel_for_simd:
390 #define OPENMP_PARALLEL_FOR_SIMD_CLAUSE(Name) \
393 #include "clang/Basic/OpenMPKinds.def"
398 case OMPD_parallel_sections:
400 #define OPENMP_PARALLEL_SECTIONS_CLAUSE(Name) \
403 #include "clang/Basic/OpenMPKinds.def"
410 #define OPENMP_TASK_CLAUSE(Name) \
413 #include "clang/Basic/OpenMPKinds.def"
419 return CKind == OMPC_flush;
423 #define OPENMP_ATOMIC_CLAUSE(Name) \
426 #include "clang/Basic/OpenMPKinds.def"
433 #define OPENMP_TARGET_CLAUSE(Name) \
436 #include "clang/Basic/OpenMPKinds.def"
441 case OMPD_target_data:
443 #define OPENMP_TARGET_DATA_CLAUSE(Name) \
446 #include "clang/Basic/OpenMPKinds.def"
451 case OMPD_target_enter_data:
453 #define OPENMP_TARGET_ENTER_DATA_CLAUSE(Name) \
456 #include "clang/Basic/OpenMPKinds.def"
461 case OMPD_target_exit_data:
463 #define OPENMP_TARGET_EXIT_DATA_CLAUSE(Name) \
466 #include "clang/Basic/OpenMPKinds.def"
471 case OMPD_target_parallel:
473 #define OPENMP_TARGET_PARALLEL_CLAUSE(Name) \
476 #include "clang/Basic/OpenMPKinds.def"
481 case OMPD_target_parallel_for:
483 #define OPENMP_TARGET_PARALLEL_FOR_CLAUSE(Name) \
486 #include "clang/Basic/OpenMPKinds.def"
491 case OMPD_target_update:
493 #define OPENMP_TARGET_UPDATE_CLAUSE(Name) \
496 #include "clang/Basic/OpenMPKinds.def"
503 #define OPENMP_TEAMS_CLAUSE(Name) \
506 #include "clang/Basic/OpenMPKinds.def"
511 case OMPD_declare_simd:
515 #define OPENMP_CANCEL_CLAUSE(Name) \
518 #include "clang/Basic/OpenMPKinds.def"
525 #define OPENMP_ORDERED_CLAUSE(Name) \
528 #include "clang/Basic/OpenMPKinds.def"
535 #define OPENMP_TASKLOOP_CLAUSE(Name) \
538 #include "clang/Basic/OpenMPKinds.def"
543 case OMPD_taskloop_simd:
545 #define OPENMP_TASKLOOP_SIMD_CLAUSE(Name) \
548 #include "clang/Basic/OpenMPKinds.def"
555 #define OPENMP_CRITICAL_CLAUSE(Name) \
558 #include "clang/Basic/OpenMPKinds.def"
563 case OMPD_distribute:
565 #define OPENMP_DISTRIBUTE_CLAUSE(Name) \
568 #include "clang/Basic/OpenMPKinds.def"
573 case OMPD_distribute_parallel_for:
575 #define OPENMP_DISTRIBUTE_PARALLEL_FOR_CLAUSE(Name) \
578 #include "clang/Basic/OpenMPKinds.def"
583 case OMPD_distribute_parallel_for_simd:
585 #define OPENMP_DISTRIBUTE_PARALLEL_FOR_SIMD_CLAUSE(Name) \
588 #include "clang/Basic/OpenMPKinds.def"
593 case OMPD_distribute_simd:
595 #define OPENMP_DISTRIBUTE_SIMD_CLAUSE(Name) \
598 #include "clang/Basic/OpenMPKinds.def"
603 case OMPD_target_parallel_for_simd:
605 #define OPENMP_TARGET_PARALLEL_FOR_SIMD_CLAUSE(Name) \
608 #include "clang/Basic/OpenMPKinds.def"
613 case OMPD_declare_target:
614 case OMPD_end_declare_target:
616 case OMPD_threadprivate:
623 case OMPD_cancellation_point:
624 case OMPD_declare_reduction:
630 bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
631 return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
632 DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
633 DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
634 DKind == OMPD_distribute || DKind == OMPD_target_parallel_for ||
635 DKind == OMPD_distribute_parallel_for ||
636 DKind == OMPD_distribute_parallel_for_simd ||
637 DKind == OMPD_distribute_simd ||
638 DKind == OMPD_target_parallel_for_simd;
639 // TODO add next directives.
642 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
643 return DKind == OMPD_for || DKind == OMPD_for_simd ||
644 DKind == OMPD_sections || DKind == OMPD_section ||
645 DKind == OMPD_single || DKind == OMPD_parallel_for ||
646 DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
647 DKind == OMPD_target_parallel_for ||
648 DKind == OMPD_distribute_parallel_for ||
649 DKind == OMPD_distribute_parallel_for_simd ||
650 DKind == OMPD_target_parallel_for_simd;
651 // TODO add next directives.
654 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
655 return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd;
658 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
659 return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
660 DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
661 DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
662 DKind == OMPD_distribute_parallel_for ||
663 DKind == OMPD_distribute_parallel_for_simd ||
664 DKind == OMPD_target_parallel_for_simd;
665 // TODO add next directives.
668 bool clang::isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind) {
669 // TODO add next directives.
670 return DKind == OMPD_target || DKind == OMPD_target_parallel ||
671 DKind == OMPD_target_parallel_for ||
672 DKind == OMPD_target_parallel_for_simd;
675 bool clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
676 return DKind == OMPD_target_data || DKind == OMPD_target_enter_data ||
677 DKind == OMPD_target_exit_data || DKind == OMPD_target_update;
680 bool clang::isOpenMPTeamsDirective(OpenMPDirectiveKind DKind) {
681 return DKind == OMPD_teams; // TODO add next directives.
684 bool clang::isOpenMPSimdDirective(OpenMPDirectiveKind DKind) {
685 return DKind == OMPD_simd || DKind == OMPD_for_simd ||
686 DKind == OMPD_parallel_for_simd || DKind == OMPD_taskloop_simd ||
687 DKind == OMPD_distribute_parallel_for_simd ||
688 DKind == OMPD_distribute_simd;
689 // TODO add next directives.
692 bool clang::isOpenMPDistributeDirective(OpenMPDirectiveKind Kind) {
693 return Kind == OMPD_distribute || Kind == OMPD_distribute_parallel_for ||
694 Kind == OMPD_distribute_parallel_for_simd ||
695 Kind == OMPD_distribute_simd;
696 // TODO add next directives.
699 bool clang::isOpenMPPrivate(OpenMPClauseKind Kind) {
700 return Kind == OMPC_private || Kind == OMPC_firstprivate ||
701 Kind == OMPC_lastprivate || Kind == OMPC_linear ||
702 Kind == OMPC_reduction; // TODO add next clauses like 'reduction'.
705 bool clang::isOpenMPThreadPrivate(OpenMPClauseKind Kind) {
706 return Kind == OMPC_threadprivate || Kind == OMPC_copyin;
709 bool clang::isOpenMPTaskingDirective(OpenMPDirectiveKind Kind) {
710 return Kind == OMPD_task || isOpenMPTaskLoopDirective(Kind);
713 bool clang::isOpenMPLoopBoundSharingDirective(OpenMPDirectiveKind Kind) {
714 return Kind == OMPD_distribute_parallel_for ||
715 Kind == OMPD_distribute_parallel_for_simd ||
716 Kind == OMPD_distribute_simd;