Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1 | //===--- OpenMPKinds.cpp - Token Kinds Support ----------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// \brief This file implements the OpenMP enum and support functions. |
| 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/Basic/OpenMPKinds.h" |
| 15 | #include "clang/Basic/IdentifierTable.h" |
Matt Beaumont-Gay | 07544fa | 2013-03-25 21:32:02 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/StringRef.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/StringSwitch.h" |
| 18 | #include "llvm/Support/ErrorHandling.h" |
| 19 | #include <cassert> |
| 20 | |
| 21 | using namespace clang; |
| 22 | |
| 23 | OpenMPDirectiveKind clang::getOpenMPDirectiveKind(StringRef Str) { |
| 24 | return llvm::StringSwitch<OpenMPDirectiveKind>(Str) |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 25 | #define OPENMP_DIRECTIVE(Name) .Case(#Name, OMPD_##Name) |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 26 | #include "clang/Basic/OpenMPKinds.def" |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 27 | .Default(OMPD_unknown); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | const char *clang::getOpenMPDirectiveName(OpenMPDirectiveKind Kind) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 31 | assert(Kind <= OMPD_unknown); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 32 | switch (Kind) { |
| 33 | case OMPD_unknown: |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 34 | return "unknown"; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 35 | #define OPENMP_DIRECTIVE(Name) \ |
| 36 | case OMPD_##Name: \ |
| 37 | return #Name; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 38 | #include "clang/Basic/OpenMPKinds.def" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 39 | break; |
| 40 | } |
| 41 | llvm_unreachable("Invalid OpenMP directive kind"); |
| 42 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 43 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 44 | OpenMPClauseKind clang::getOpenMPClauseKind(StringRef Str) { |
| 45 | return llvm::StringSwitch<OpenMPClauseKind>(Str) |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 46 | #define OPENMP_CLAUSE(Name, Class) .Case(#Name, OMPC_##Name) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 47 | #include "clang/Basic/OpenMPKinds.def" |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 48 | .Default(OMPC_unknown); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | const char *clang::getOpenMPClauseName(OpenMPClauseKind Kind) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 52 | assert(Kind <= OMPC_unknown); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 53 | switch (Kind) { |
| 54 | case OMPC_unknown: |
| 55 | return "unknown"; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 56 | #define OPENMP_CLAUSE(Name, Class) \ |
| 57 | case OMPC_##Name: \ |
| 58 | return #Name; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 59 | #include "clang/Basic/OpenMPKinds.def" |
| 60 | case OMPC_threadprivate: |
| 61 | return "threadprivate or thread local"; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 62 | } |
| 63 | llvm_unreachable("Invalid OpenMP clause kind"); |
| 64 | } |
| 65 | |
| 66 | unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, |
| 67 | StringRef Str) { |
| 68 | switch (Kind) { |
| 69 | case OMPC_default: |
| 70 | return llvm::StringSwitch<OpenMPDefaultClauseKind>(Str) |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 71 | #define OPENMP_DEFAULT_KIND(Name) .Case(#Name, OMPC_DEFAULT_##Name) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 72 | #include "clang/Basic/OpenMPKinds.def" |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 73 | .Default(OMPC_DEFAULT_unknown); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 74 | case OMPC_proc_bind: |
| 75 | return llvm::StringSwitch<OpenMPProcBindClauseKind>(Str) |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 76 | #define OPENMP_PROC_BIND_KIND(Name) .Case(#Name, OMPC_PROC_BIND_##Name) |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 77 | #include "clang/Basic/OpenMPKinds.def" |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 78 | .Default(OMPC_PROC_BIND_unknown); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 79 | case OMPC_schedule: |
| 80 | return llvm::StringSwitch<OpenMPScheduleClauseKind>(Str) |
| 81 | #define OPENMP_SCHEDULE_KIND(Name) .Case(#Name, OMPC_SCHEDULE_##Name) |
| 82 | #include "clang/Basic/OpenMPKinds.def" |
| 83 | .Default(OMPC_SCHEDULE_unknown); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 84 | case OMPC_unknown: |
| 85 | case OMPC_threadprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 86 | case OMPC_if: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 87 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 88 | case OMPC_safelen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 89 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 90 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 91 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 92 | case OMPC_lastprivate: |
David Blaikie | 3e8aa9a | 2013-09-06 20:58:25 +0000 | [diff] [blame] | 93 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 94 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 95 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 96 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 97 | case OMPC_copyin: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 98 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 99 | case OMPC_nowait: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 100 | break; |
| 101 | } |
| 102 | llvm_unreachable("Invalid OpenMP simple clause kind"); |
| 103 | } |
| 104 | |
| 105 | const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, |
| 106 | unsigned Type) { |
| 107 | switch (Kind) { |
| 108 | case OMPC_default: |
| 109 | switch (Type) { |
| 110 | case OMPC_DEFAULT_unknown: |
| 111 | return "unknown"; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 112 | #define OPENMP_DEFAULT_KIND(Name) \ |
| 113 | case OMPC_DEFAULT_##Name: \ |
| 114 | return #Name; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 115 | #include "clang/Basic/OpenMPKinds.def" |
| 116 | } |
| 117 | llvm_unreachable("Invalid OpenMP 'default' clause type"); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 118 | case OMPC_proc_bind: |
| 119 | switch (Type) { |
| 120 | case OMPC_PROC_BIND_unknown: |
| 121 | return "unknown"; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 122 | #define OPENMP_PROC_BIND_KIND(Name) \ |
| 123 | case OMPC_PROC_BIND_##Name: \ |
| 124 | return #Name; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 125 | #include "clang/Basic/OpenMPKinds.def" |
| 126 | } |
| 127 | llvm_unreachable("Invalid OpenMP 'proc_bind' clause type"); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 128 | case OMPC_schedule: |
| 129 | switch (Type) { |
| 130 | case OMPC_SCHEDULE_unknown: |
| 131 | return "unknown"; |
| 132 | #define OPENMP_SCHEDULE_KIND(Name) \ |
| 133 | case OMPC_SCHEDULE_##Name: \ |
| 134 | return #Name; |
| 135 | #include "clang/Basic/OpenMPKinds.def" |
| 136 | } |
| 137 | llvm_unreachable("Invalid OpenMP 'schedule' clause type"); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 138 | case OMPC_unknown: |
| 139 | case OMPC_threadprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 140 | case OMPC_if: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 141 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 142 | case OMPC_safelen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 143 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 144 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 145 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 146 | case OMPC_lastprivate: |
David Blaikie | 3e8aa9a | 2013-09-06 20:58:25 +0000 | [diff] [blame] | 147 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 148 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 149 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 150 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 151 | case OMPC_copyin: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 152 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 153 | case OMPC_nowait: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 154 | break; |
| 155 | } |
| 156 | llvm_unreachable("Invalid OpenMP simple clause kind"); |
| 157 | } |
| 158 | |
| 159 | bool clang::isAllowedClauseForDirective(OpenMPDirectiveKind DKind, |
| 160 | OpenMPClauseKind CKind) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 161 | assert(DKind <= OMPD_unknown); |
| 162 | assert(CKind <= OMPC_unknown); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 163 | switch (DKind) { |
| 164 | case OMPD_parallel: |
| 165 | switch (CKind) { |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 166 | #define OPENMP_PARALLEL_CLAUSE(Name) \ |
| 167 | case OMPC_##Name: \ |
| 168 | return true; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 169 | #include "clang/Basic/OpenMPKinds.def" |
| 170 | default: |
| 171 | break; |
| 172 | } |
| 173 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 174 | case OMPD_simd: |
| 175 | switch (CKind) { |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 176 | #define OPENMP_SIMD_CLAUSE(Name) \ |
| 177 | case OMPC_##Name: \ |
| 178 | return true; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 179 | #include "clang/Basic/OpenMPKinds.def" |
| 180 | default: |
| 181 | break; |
| 182 | } |
| 183 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 184 | case OMPD_for: |
| 185 | switch (CKind) { |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 186 | #define OPENMP_FOR_CLAUSE(Name) \ |
| 187 | case OMPC_##Name: \ |
| 188 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 189 | #include "clang/Basic/OpenMPKinds.def" |
| 190 | default: |
| 191 | break; |
| 192 | } |
| 193 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 194 | case OMPD_sections: |
| 195 | switch (CKind) { |
| 196 | #define OPENMP_SECTIONS_CLAUSE(Name) \ |
| 197 | case OMPC_##Name: \ |
| 198 | return true; |
| 199 | #include "clang/Basic/OpenMPKinds.def" |
| 200 | default: |
| 201 | break; |
| 202 | } |
| 203 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 204 | case OMPD_single: |
| 205 | switch (CKind) { |
| 206 | #define OPENMP_SINGLE_CLAUSE(Name) \ |
| 207 | case OMPC_##Name: \ |
| 208 | return true; |
| 209 | #include "clang/Basic/OpenMPKinds.def" |
| 210 | default: |
| 211 | break; |
| 212 | } |
| 213 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 214 | case OMPD_unknown: |
| 215 | case OMPD_threadprivate: |
| 216 | case OMPD_task: |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 217 | case OMPD_section: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 218 | break; |
| 219 | } |
| 220 | return false; |
| 221 | } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 222 | |
| 223 | bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) { |
| 224 | return DKind == OMPD_simd || DKind == OMPD_for; // TODO add next directives. |
| 225 | } |
| 226 | |
| 227 | bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) { |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 228 | return DKind == OMPD_for || DKind == OMPD_sections || DKind == OMPD_section || |
| 229 | DKind == OMPD_single; // TODO add next directives. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) { |
| 233 | return DKind == OMPD_parallel; // TODO add next directives. |
| 234 | } |
| 235 | |
| 236 | bool clang::isOpenMPSimdDirective(OpenMPDirectiveKind DKind) { |
| 237 | return DKind == OMPD_simd; // TODO || DKind == OMPD_for_simd || ... |
| 238 | } |
| 239 | |
| 240 | bool clang::isOpenMPPrivate(OpenMPClauseKind Kind) { |
| 241 | return Kind == OMPC_private || Kind == OMPC_firstprivate || |
| 242 | Kind == OMPC_lastprivate || Kind == OMPC_linear || |
| 243 | Kind == OMPC_reduction; // TODO add next clauses like 'reduction'. |
| 244 | } |
| 245 | |
| 246 | bool clang::isOpenMPThreadPrivate(OpenMPClauseKind Kind) { |
| 247 | return Kind == OMPC_threadprivate || |
| 248 | Kind == OMPC_copyin; // TODO add next clauses like 'copyprivate'. |
| 249 | } |
| 250 | |