clang  3.8.0
OpenMPKinds.cpp
Go to the documentation of this file.
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 
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/ADT/StringSwitch.h"
18 #include "llvm/Support/ErrorHandling.h"
19 #include <cassert>
20 
21 using namespace clang;
22 
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);
29 }
30 
32  assert(Kind <= OMPD_unknown);
33  switch (Kind) {
34  case OMPD_unknown:
35  return "unknown";
36 #define OPENMP_DIRECTIVE(Name) \
37  case OMPD_##Name: \
38  return #Name;
39 #define OPENMP_DIRECTIVE_EXT(Name, Str) \
40  case OMPD_##Name: \
41  return Str;
42 #include "clang/Basic/OpenMPKinds.def"
43  break;
44  }
45  llvm_unreachable("Invalid OpenMP directive kind");
46 }
47 
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
52  // directive.
53  if (Str == "flush")
54  return OMPC_unknown;
55  return llvm::StringSwitch<OpenMPClauseKind>(Str)
56 #define OPENMP_CLAUSE(Name, Class) .Case(#Name, OMPC_##Name)
57 #include "clang/Basic/OpenMPKinds.def"
58  .Default(OMPC_unknown);
59 }
60 
62  assert(Kind <= OMPC_unknown);
63  switch (Kind) {
64  case OMPC_unknown:
65  return "unknown";
66 #define OPENMP_CLAUSE(Name, Class) \
67  case OMPC_##Name: \
68  return #Name;
69 #include "clang/Basic/OpenMPKinds.def"
70  case OMPC_threadprivate:
71  return "threadprivate or thread local";
72  }
73  llvm_unreachable("Invalid OpenMP clause kind");
74 }
75 
77  StringRef Str) {
78  switch (Kind) {
79  case OMPC_default:
80  return llvm::StringSwitch<OpenMPDefaultClauseKind>(Str)
81 #define OPENMP_DEFAULT_KIND(Name) .Case(#Name, OMPC_DEFAULT_##Name)
82 #include "clang/Basic/OpenMPKinds.def"
83  .Default(OMPC_DEFAULT_unknown);
84  case OMPC_proc_bind:
85  return llvm::StringSwitch<OpenMPProcBindClauseKind>(Str)
86 #define OPENMP_PROC_BIND_KIND(Name) .Case(#Name, OMPC_PROC_BIND_##Name)
87 #include "clang/Basic/OpenMPKinds.def"
88  .Default(OMPC_PROC_BIND_unknown);
89  case OMPC_schedule:
90  return llvm::StringSwitch<unsigned>(Str)
91 #define OPENMP_SCHEDULE_KIND(Name) \
92  .Case(#Name, static_cast<unsigned>(OMPC_SCHEDULE_##Name))
93 #define OPENMP_SCHEDULE_MODIFIER(Name) \
94  .Case(#Name, static_cast<unsigned>(OMPC_SCHEDULE_MODIFIER_##Name))
95 #include "clang/Basic/OpenMPKinds.def"
96  .Default(OMPC_SCHEDULE_unknown);
97  case OMPC_depend:
98  return llvm::StringSwitch<OpenMPDependClauseKind>(Str)
99 #define OPENMP_DEPEND_KIND(Name) .Case(#Name, OMPC_DEPEND_##Name)
100 #include "clang/Basic/OpenMPKinds.def"
101  .Default(OMPC_DEPEND_unknown);
102  case OMPC_linear:
103  return llvm::StringSwitch<OpenMPLinearClauseKind>(Str)
104 #define OPENMP_LINEAR_KIND(Name) .Case(#Name, OMPC_LINEAR_##Name)
105 #include "clang/Basic/OpenMPKinds.def"
106  .Default(OMPC_LINEAR_unknown);
107  case OMPC_map:
108  return llvm::StringSwitch<OpenMPMapClauseKind>(Str)
109 #define OPENMP_MAP_KIND(Name) .Case(#Name, OMPC_MAP_##Name)
110 #include "clang/Basic/OpenMPKinds.def"
111  .Default(OMPC_MAP_unknown);
112  case OMPC_unknown:
113  case OMPC_threadprivate:
114  case OMPC_if:
115  case OMPC_final:
116  case OMPC_num_threads:
117  case OMPC_safelen:
118  case OMPC_simdlen:
119  case OMPC_collapse:
120  case OMPC_private:
121  case OMPC_firstprivate:
122  case OMPC_lastprivate:
123  case OMPC_shared:
124  case OMPC_reduction:
125  case OMPC_aligned:
126  case OMPC_copyin:
127  case OMPC_copyprivate:
128  case OMPC_ordered:
129  case OMPC_nowait:
130  case OMPC_untied:
131  case OMPC_mergeable:
132  case OMPC_flush:
133  case OMPC_read:
134  case OMPC_write:
135  case OMPC_update:
136  case OMPC_capture:
137  case OMPC_seq_cst:
138  case OMPC_device:
139  case OMPC_threads:
140  case OMPC_simd:
141  case OMPC_num_teams:
142  case OMPC_thread_limit:
143  case OMPC_priority:
144  case OMPC_grainsize:
145  case OMPC_nogroup:
146  case OMPC_num_tasks:
147  case OMPC_hint:
148  break;
149  }
150  llvm_unreachable("Invalid OpenMP simple clause kind");
151 }
152 
154  unsigned Type) {
155  switch (Kind) {
156  case OMPC_default:
157  switch (Type) {
159  return "unknown";
160 #define OPENMP_DEFAULT_KIND(Name) \
161  case OMPC_DEFAULT_##Name: \
162  return #Name;
163 #include "clang/Basic/OpenMPKinds.def"
164  }
165  llvm_unreachable("Invalid OpenMP 'default' clause type");
166  case OMPC_proc_bind:
167  switch (Type) {
169  return "unknown";
170 #define OPENMP_PROC_BIND_KIND(Name) \
171  case OMPC_PROC_BIND_##Name: \
172  return #Name;
173 #include "clang/Basic/OpenMPKinds.def"
174  }
175  llvm_unreachable("Invalid OpenMP 'proc_bind' clause type");
176  case OMPC_schedule:
177  switch (Type) {
180  return "unknown";
181 #define OPENMP_SCHEDULE_KIND(Name) \
182  case OMPC_SCHEDULE_##Name: \
183  return #Name;
184 #define OPENMP_SCHEDULE_MODIFIER(Name) \
185  case OMPC_SCHEDULE_MODIFIER_##Name: \
186  return #Name;
187 #include "clang/Basic/OpenMPKinds.def"
188  }
189  llvm_unreachable("Invalid OpenMP 'schedule' clause type");
190  case OMPC_depend:
191  switch (Type) {
192  case OMPC_DEPEND_unknown:
193  return "unknown";
194 #define OPENMP_DEPEND_KIND(Name) \
195  case OMPC_DEPEND_##Name: \
196  return #Name;
197 #include "clang/Basic/OpenMPKinds.def"
198  }
199  llvm_unreachable("Invalid OpenMP 'depend' clause type");
200  case OMPC_linear:
201  switch (Type) {
202  case OMPC_LINEAR_unknown:
203  return "unknown";
204 #define OPENMP_LINEAR_KIND(Name) \
205  case OMPC_LINEAR_##Name: \
206  return #Name;
207 #include "clang/Basic/OpenMPKinds.def"
208  }
209  llvm_unreachable("Invalid OpenMP 'linear' clause type");
210  case OMPC_map:
211  switch (Type) {
212  case OMPC_MAP_unknown:
213  return "unknown";
214 #define OPENMP_MAP_KIND(Name) \
215  case OMPC_MAP_##Name: \
216  return #Name;
217 #include "clang/Basic/OpenMPKinds.def"
218  default:
219  break;
220  }
221  llvm_unreachable("Invalid OpenMP 'map' clause type");
222  case OMPC_unknown:
223  case OMPC_threadprivate:
224  case OMPC_if:
225  case OMPC_final:
226  case OMPC_num_threads:
227  case OMPC_safelen:
228  case OMPC_simdlen:
229  case OMPC_collapse:
230  case OMPC_private:
231  case OMPC_firstprivate:
232  case OMPC_lastprivate:
233  case OMPC_shared:
234  case OMPC_reduction:
235  case OMPC_aligned:
236  case OMPC_copyin:
237  case OMPC_copyprivate:
238  case OMPC_ordered:
239  case OMPC_nowait:
240  case OMPC_untied:
241  case OMPC_mergeable:
242  case OMPC_flush:
243  case OMPC_read:
244  case OMPC_write:
245  case OMPC_update:
246  case OMPC_capture:
247  case OMPC_seq_cst:
248  case OMPC_device:
249  case OMPC_threads:
250  case OMPC_simd:
251  case OMPC_num_teams:
252  case OMPC_thread_limit:
253  case OMPC_priority:
254  case OMPC_grainsize:
255  case OMPC_nogroup:
256  case OMPC_num_tasks:
257  case OMPC_hint:
258  break;
259  }
260  llvm_unreachable("Invalid OpenMP simple clause kind");
261 }
262 
264  OpenMPClauseKind CKind) {
265  assert(DKind <= OMPD_unknown);
266  assert(CKind <= OMPC_unknown);
267  switch (DKind) {
268  case OMPD_parallel:
269  switch (CKind) {
270 #define OPENMP_PARALLEL_CLAUSE(Name) \
271  case OMPC_##Name: \
272  return true;
273 #include "clang/Basic/OpenMPKinds.def"
274  default:
275  break;
276  }
277  break;
278  case OMPD_simd:
279  switch (CKind) {
280 #define OPENMP_SIMD_CLAUSE(Name) \
281  case OMPC_##Name: \
282  return true;
283 #include "clang/Basic/OpenMPKinds.def"
284  default:
285  break;
286  }
287  break;
288  case OMPD_for:
289  switch (CKind) {
290 #define OPENMP_FOR_CLAUSE(Name) \
291  case OMPC_##Name: \
292  return true;
293 #include "clang/Basic/OpenMPKinds.def"
294  default:
295  break;
296  }
297  break;
298  case OMPD_for_simd:
299  switch (CKind) {
300 #define OPENMP_FOR_SIMD_CLAUSE(Name) \
301  case OMPC_##Name: \
302  return true;
303 #include "clang/Basic/OpenMPKinds.def"
304  default:
305  break;
306  }
307  break;
308  case OMPD_sections:
309  switch (CKind) {
310 #define OPENMP_SECTIONS_CLAUSE(Name) \
311  case OMPC_##Name: \
312  return true;
313 #include "clang/Basic/OpenMPKinds.def"
314  default:
315  break;
316  }
317  break;
318  case OMPD_single:
319  switch (CKind) {
320 #define OPENMP_SINGLE_CLAUSE(Name) \
321  case OMPC_##Name: \
322  return true;
323 #include "clang/Basic/OpenMPKinds.def"
324  default:
325  break;
326  }
327  break;
328  case OMPD_parallel_for:
329  switch (CKind) {
330 #define OPENMP_PARALLEL_FOR_CLAUSE(Name) \
331  case OMPC_##Name: \
332  return true;
333 #include "clang/Basic/OpenMPKinds.def"
334  default:
335  break;
336  }
337  break;
338  case OMPD_parallel_for_simd:
339  switch (CKind) {
340 #define OPENMP_PARALLEL_FOR_SIMD_CLAUSE(Name) \
341  case OMPC_##Name: \
342  return true;
343 #include "clang/Basic/OpenMPKinds.def"
344  default:
345  break;
346  }
347  break;
348  case OMPD_parallel_sections:
349  switch (CKind) {
350 #define OPENMP_PARALLEL_SECTIONS_CLAUSE(Name) \
351  case OMPC_##Name: \
352  return true;
353 #include "clang/Basic/OpenMPKinds.def"
354  default:
355  break;
356  }
357  break;
358  case OMPD_task:
359  switch (CKind) {
360 #define OPENMP_TASK_CLAUSE(Name) \
361  case OMPC_##Name: \
362  return true;
363 #include "clang/Basic/OpenMPKinds.def"
364  default:
365  break;
366  }
367  break;
368  case OMPD_flush:
369  return CKind == OMPC_flush;
370  break;
371  case OMPD_atomic:
372  switch (CKind) {
373 #define OPENMP_ATOMIC_CLAUSE(Name) \
374  case OMPC_##Name: \
375  return true;
376 #include "clang/Basic/OpenMPKinds.def"
377  default:
378  break;
379  }
380  break;
381  case OMPD_target:
382  switch (CKind) {
383 #define OPENMP_TARGET_CLAUSE(Name) \
384  case OMPC_##Name: \
385  return true;
386 #include "clang/Basic/OpenMPKinds.def"
387  default:
388  break;
389  }
390  break;
391  case OMPD_target_data:
392  switch (CKind) {
393 #define OPENMP_TARGET_DATA_CLAUSE(Name) \
394  case OMPC_##Name: \
395  return true;
396 #include "clang/Basic/OpenMPKinds.def"
397  default:
398  break;
399  }
400  break;
401  case OMPD_teams:
402  switch (CKind) {
403 #define OPENMP_TEAMS_CLAUSE(Name) \
404  case OMPC_##Name: \
405  return true;
406 #include "clang/Basic/OpenMPKinds.def"
407  default:
408  break;
409  }
410  break;
411  case OMPD_cancel:
412  switch (CKind) {
413 #define OPENMP_CANCEL_CLAUSE(Name) \
414  case OMPC_##Name: \
415  return true;
416 #include "clang/Basic/OpenMPKinds.def"
417  default:
418  break;
419  }
420  break;
421  case OMPD_ordered:
422  switch (CKind) {
423 #define OPENMP_ORDERED_CLAUSE(Name) \
424  case OMPC_##Name: \
425  return true;
426 #include "clang/Basic/OpenMPKinds.def"
427  default:
428  break;
429  }
430  break;
431  case OMPD_taskloop:
432  switch (CKind) {
433 #define OPENMP_TASKLOOP_CLAUSE(Name) \
434  case OMPC_##Name: \
435  return true;
436 #include "clang/Basic/OpenMPKinds.def"
437  default:
438  break;
439  }
440  break;
441  case OMPD_taskloop_simd:
442  switch (CKind) {
443 #define OPENMP_TASKLOOP_SIMD_CLAUSE(Name) \
444  case OMPC_##Name: \
445  return true;
446 #include "clang/Basic/OpenMPKinds.def"
447  default:
448  break;
449  }
450  break;
451  case OMPD_critical:
452  switch (CKind) {
453 #define OPENMP_CRITICAL_CLAUSE(Name) \
454  case OMPC_##Name: \
455  return true;
456 #include "clang/Basic/OpenMPKinds.def"
457  default:
458  break;
459  }
460  break;
461  case OMPD_distribute:
462  switch (CKind) {
463 #define OPENMP_DISTRIBUTE_CLAUSE(Name) \
464  case OMPC_##Name: \
465  return true;
466 #include "clang/Basic/OpenMPKinds.def"
467  default:
468  break;
469  }
470  break;
471  case OMPD_unknown:
472  case OMPD_threadprivate:
473  case OMPD_section:
474  case OMPD_master:
475  case OMPD_taskyield:
476  case OMPD_barrier:
477  case OMPD_taskwait:
478  case OMPD_taskgroup:
479  case OMPD_cancellation_point:
480  break;
481  }
482  return false;
483 }
484 
486  return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
487  DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
488  DKind == OMPD_taskloop ||
489  DKind == OMPD_taskloop_simd ||
490  DKind == OMPD_distribute; // TODO add next directives.
491 }
492 
494  return DKind == OMPD_for || DKind == OMPD_for_simd ||
495  DKind == OMPD_sections || DKind == OMPD_section ||
496  DKind == OMPD_single || DKind == OMPD_parallel_for ||
497  DKind == OMPD_parallel_for_simd ||
498  DKind == OMPD_parallel_sections; // TODO add next directives.
499 }
500 
502  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd;
503 }
504 
506  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
507  DKind == OMPD_parallel_for_simd ||
508  DKind == OMPD_parallel_sections; // TODO add next directives.
509 }
510 
512  return DKind == OMPD_target; // TODO add next directives.
513 }
514 
516  return DKind == OMPD_teams; // TODO add next directives.
517 }
518 
520  return DKind == OMPD_simd || DKind == OMPD_for_simd ||
521  DKind == OMPD_parallel_for_simd ||
522  DKind == OMPD_taskloop_simd; // TODO add next directives.
523 }
524 
526  return Kind == OMPD_distribute; // TODO add next directives.
527 }
528 
530  return Kind == OMPC_private || Kind == OMPC_firstprivate ||
531  Kind == OMPC_lastprivate || Kind == OMPC_linear ||
532  Kind == OMPC_reduction; // TODO add next clauses like 'reduction'.
533 }
534 
536  return Kind == OMPC_threadprivate || Kind == OMPC_copyin;
537 }
538 
#define OPENMP_MAP_KIND(Name)
The base class of the type hierarchy.
Definition: Type.h:1249
const char * getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, unsigned Type)
bool isAllowedClauseForDirective(OpenMPDirectiveKind DKind, OpenMPClauseKind CKind)
#define OPENMP_LINEAR_KIND(Name)
const char * getOpenMPClauseName(OpenMPClauseKind Kind)
Definition: OpenMPKinds.cpp:61
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4381
Defines some OpenMP-specific enums and functions.
bool isOpenMPTeamsDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a teams-kind directive.
OpenMPClauseKind getOpenMPClauseKind(llvm::StringRef Str)
bool isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a worksharing directive.
#define OPENMP_CLAUSE(Name, Class)
#define OPENMP_PROC_BIND_KIND(Name)
bool isOpenMPPrivate(OpenMPClauseKind Kind)
Checks if the specified clause is one of private clauses like 'private', 'firstprivate', 'reduction' etc.
bool isOpenMPParallelDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a parallel-kind directive.
#define OPENMP_DEPEND_KIND(Name)
OpenMPClauseKind
OpenMP clauses.
Definition: OpenMPKinds.h:33
#define OPENMP_DIRECTIVE(Name)
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
bool isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a taskloop directive.
Kind
OpenMPDirectiveKind
OpenMP directives.
Definition: OpenMPKinds.h:23
bool isOpenMPSimdDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a simd directive.
#define OPENMP_DEFAULT_KIND(Name)
bool isOpenMPThreadPrivate(OpenMPClauseKind Kind)
Checks if the specified clause is one of threadprivate clauses like 'threadprivate', 'copyin' or 'copyprivate'.
unsigned getOpenMPSimpleClauseType(OpenMPClauseKind Kind, llvm::StringRef Str)
bool isOpenMPDistributeDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a distribute directive.
bool isOpenMPTargetDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a target-kind directive.
OpenMPDirectiveKind getOpenMPDirectiveKind(llvm::StringRef Str)
const char * getOpenMPDirectiveName(OpenMPDirectiveKind Kind)
Definition: OpenMPKinds.cpp:31
#define OPENMP_SCHEDULE_KIND(Name)
bool isOpenMPLoopDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a directive with an associated loop construct.