clang 23.0.0git
OpenMPKinds.cpp
Go to the documentation of this file.
1//===--- OpenMPKinds.cpp - Token Kinds Support ----------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9/// This file implements the OpenMP enum and support functions.
10///
11//===----------------------------------------------------------------------===//
12
15#include "llvm/ADT/StringRef.h"
16#include "llvm/ADT/StringSwitch.h"
17#include "llvm/Support/ErrorHandling.h"
18#include <cassert>
19
20using namespace clang;
21using namespace llvm::omp;
22
25 const LangOptions &LangOpts) {
26 return llvm::StringSwitch<OpenMPDefaultClauseVariableCategory>(Str)
27#define OPENMP_DEFAULT_VARIABLE_CATEGORY(Name) \
28 .Case(#Name, OMPC_DEFAULT_VC_##Name)
29#include "clang/Basic/OpenMPKinds.def"
31}
32
34 switch (VC) {
35#define OPENMP_DEFAULT_VARIABLE_CATEGORY(Name) \
36 case OMPC_DEFAULT_VC_##Name: \
37 return #Name;
38#include "clang/Basic/OpenMPKinds.def"
39 }
40 llvm_unreachable("Invalid Variable Category in the default clause");
41}
42
43unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, StringRef Str,
44 const LangOptions &LangOpts) {
45 switch (Kind) {
46 case OMPC_default:
47 return llvm::StringSwitch<unsigned>(Str)
48#define OMP_DEFAULT_KIND(Enum, Name) .Case(Name, unsigned(Enum))
49#include "llvm/Frontend/OpenMP/OMPKinds.def"
50 .Default(unsigned(llvm::omp::OMP_DEFAULT_unknown));
51 case OMPC_proc_bind:
52 return llvm::StringSwitch<unsigned>(Str)
53#define OMP_PROC_BIND_KIND(Enum, Name, Value) .Case(Name, Value)
54#include "llvm/Frontend/OpenMP/OMPKinds.def"
55 .Default(unsigned(llvm::omp::OMP_PROC_BIND_unknown));
56 case OMPC_schedule:
57 return llvm::StringSwitch<unsigned>(Str)
58#define OPENMP_SCHEDULE_KIND(Name) \
59 .Case(#Name, static_cast<unsigned>(OMPC_SCHEDULE_##Name))
60#define OPENMP_SCHEDULE_MODIFIER(Name) \
61 .Case(#Name, static_cast<unsigned>(OMPC_SCHEDULE_MODIFIER_##Name))
62#include "clang/Basic/OpenMPKinds.def"
63 .Default(OMPC_SCHEDULE_unknown);
64 case OMPC_depend: {
65 unsigned Type = llvm::StringSwitch<unsigned>(Str)
66#define OPENMP_DEPEND_KIND(Name) .Case(#Name, OMPC_DEPEND_##Name)
67#include "clang/Basic/OpenMPKinds.def"
68 .Default(OMPC_DEPEND_unknown);
69 if (LangOpts.OpenMP < 51 && Type == OMPC_DEPEND_inoutset)
71 return Type;
72 }
73 case OMPC_doacross:
74 return llvm::StringSwitch<OpenMPDoacrossClauseModifier>(Str)
75#define OPENMP_DOACROSS_MODIFIER(Name) .Case(#Name, OMPC_DOACROSS_##Name)
76#include "clang/Basic/OpenMPKinds.def"
77 .Default(OMPC_DOACROSS_unknown);
78 case OMPC_linear:
79 return llvm::StringSwitch<OpenMPLinearClauseKind>(Str)
80#define OPENMP_LINEAR_KIND(Name) .Case(#Name, OMPC_LINEAR_##Name)
81#include "clang/Basic/OpenMPKinds.def"
82 .Default(OMPC_LINEAR_unknown);
83 case OMPC_map: {
84 unsigned Type = llvm::StringSwitch<unsigned>(Str)
85#define OPENMP_MAP_KIND(Name) \
86 .Case(#Name, static_cast<unsigned>(OMPC_MAP_##Name))
87#define OPENMP_MAP_MODIFIER_KIND(Name) \
88 .Case(#Name, static_cast<unsigned>(OMPC_MAP_MODIFIER_##Name))
89#include "clang/Basic/OpenMPKinds.def"
90 .Default(OMPC_MAP_unknown);
91 if (LangOpts.OpenMP < 51 && Type == OMPC_MAP_MODIFIER_present)
93 if (!LangOpts.OpenMPExtensions && Type == OMPC_MAP_MODIFIER_ompx_hold)
95 return Type;
96 }
97 case OMPC_to:
98 case OMPC_from: {
99 unsigned Type = llvm::StringSwitch<unsigned>(Str)
100#define OPENMP_MOTION_MODIFIER_KIND(Name) \
101 .Case(#Name, static_cast<unsigned>(OMPC_MOTION_MODIFIER_##Name))
102#include "clang/Basic/OpenMPKinds.def"
104 if (LangOpts.OpenMP < 51 && Type == OMPC_MOTION_MODIFIER_present)
106 return Type;
107 }
108 case OMPC_dist_schedule:
109 return llvm::StringSwitch<OpenMPDistScheduleClauseKind>(Str)
110#define OPENMP_DIST_SCHEDULE_KIND(Name) .Case(#Name, OMPC_DIST_SCHEDULE_##Name)
111#include "clang/Basic/OpenMPKinds.def"
113 case OMPC_defaultmap: {
114 unsigned Type = llvm::StringSwitch<unsigned>(Str)
115#define OPENMP_DEFAULTMAP_KIND(Name) \
116 .Case(#Name, static_cast<unsigned>(OMPC_DEFAULTMAP_##Name))
117#define OPENMP_DEFAULTMAP_MODIFIER(Name) \
118 .Case(#Name, static_cast<unsigned>(OMPC_DEFAULTMAP_MODIFIER_##Name))
119#include "clang/Basic/OpenMPKinds.def"
120 .Default(OMPC_DEFAULTMAP_unknown);
121 if (LangOpts.OpenMP < 60 && (Type == OMPC_DEFAULTMAP_MODIFIER_storage ||
122 Type == OMPC_DEFAULTMAP_MODIFIER_private))
124 return Type;
125 }
126 case OMPC_atomic_default_mem_order:
127 return llvm::StringSwitch<OpenMPAtomicDefaultMemOrderClauseKind>(Str)
128#define OPENMP_ATOMIC_DEFAULT_MEM_ORDER_KIND(Name) \
129 .Case(#Name, OMPC_ATOMIC_DEFAULT_MEM_ORDER_##Name)
130#include "clang/Basic/OpenMPKinds.def"
132 case OMPC_fail:
133 return static_cast<unsigned int>(llvm::StringSwitch<llvm::omp::Clause>(Str)
134#define OPENMP_ATOMIC_FAIL_MODIFIER(Name) .Case(#Name, OMPC_##Name)
135#include "clang/Basic/OpenMPKinds.def"
136 .Default(OMPC_unknown));
137 case OMPC_device_type:
138 return llvm::StringSwitch<OpenMPDeviceType>(Str)
139#define OPENMP_DEVICE_TYPE_KIND(Name) .Case(#Name, OMPC_DEVICE_TYPE_##Name)
140#include "clang/Basic/OpenMPKinds.def"
141 .Default(OMPC_DEVICE_TYPE_unknown);
142 case OMPC_at:
143 return llvm::StringSwitch<OpenMPAtClauseKind>(Str)
144#define OPENMP_AT_KIND(Name) .Case(#Name, OMPC_AT_##Name)
145#include "clang/Basic/OpenMPKinds.def"
146 .Default(OMPC_AT_unknown);
147 case OMPC_severity:
148 return llvm::StringSwitch<OpenMPSeverityClauseKind>(Str)
149#define OPENMP_SEVERITY_KIND(Name) .Case(#Name, OMPC_SEVERITY_##Name)
150#include "clang/Basic/OpenMPKinds.def"
151 .Default(OMPC_SEVERITY_unknown);
152 case OMPC_lastprivate:
153 return llvm::StringSwitch<OpenMPLastprivateModifier>(Str)
154#define OPENMP_LASTPRIVATE_KIND(Name) .Case(#Name, OMPC_LASTPRIVATE_##Name)
155#include "clang/Basic/OpenMPKinds.def"
156 .Default(OMPC_LASTPRIVATE_unknown);
157 case OMPC_order:
158 return llvm::StringSwitch<unsigned>(Str)
159#define OPENMP_ORDER_KIND(Name) \
160 .Case(#Name, static_cast<unsigned>(OMPC_ORDER_##Name))
161#define OPENMP_ORDER_MODIFIER(Name) \
162 .Case(#Name, static_cast<unsigned>(OMPC_ORDER_MODIFIER_##Name))
163#include "clang/Basic/OpenMPKinds.def"
164 .Default(OMPC_ORDER_unknown);
165 case OMPC_update:
166 return llvm::StringSwitch<OpenMPDependClauseKind>(Str)
167#define OPENMP_DEPEND_KIND(Name) .Case(#Name, OMPC_DEPEND_##Name)
168#include "clang/Basic/OpenMPKinds.def"
169 .Default(OMPC_DEPEND_unknown);
170 case OMPC_device:
171 return llvm::StringSwitch<OpenMPDeviceClauseModifier>(Str)
172#define OPENMP_DEVICE_MODIFIER(Name) .Case(#Name, OMPC_DEVICE_##Name)
173#include "clang/Basic/OpenMPKinds.def"
174 .Default(OMPC_DEVICE_unknown);
175 case OMPC_reduction:
176 return llvm::StringSwitch<OpenMPReductionClauseModifier>(Str)
177#define OPENMP_REDUCTION_MODIFIER(Name) .Case(#Name, OMPC_REDUCTION_##Name)
178#include "clang/Basic/OpenMPKinds.def"
179 .Default(OMPC_REDUCTION_unknown);
180 case OMPC_adjust_args:
181 return llvm::StringSwitch<OpenMPAdjustArgsOpKind>(Str)
182#define OPENMP_ADJUST_ARGS_KIND(Name) .Case(#Name, OMPC_ADJUST_ARGS_##Name)
183#include "clang/Basic/OpenMPKinds.def"
184 .Default(OMPC_ADJUST_ARGS_unknown);
185 case OMPC_bind:
186 return llvm::StringSwitch<unsigned>(Str)
187#define OPENMP_BIND_KIND(Name) .Case(#Name, OMPC_BIND_##Name)
188#include "clang/Basic/OpenMPKinds.def"
189 .Default(OMPC_BIND_unknown);
190 case OMPC_grainsize: {
191 unsigned Type = llvm::StringSwitch<unsigned>(Str)
192#define OPENMP_GRAINSIZE_MODIFIER(Name) .Case(#Name, OMPC_GRAINSIZE_##Name)
193#include "clang/Basic/OpenMPKinds.def"
194 .Default(OMPC_GRAINSIZE_unknown);
195 if (LangOpts.OpenMP < 51)
197 return Type;
198 }
199 case OMPC_dyn_groupprivate: {
200 return llvm::StringSwitch<unsigned>(Str)
201#define OPENMP_DYN_GROUPPRIVATE_MODIFIER(Name) \
202 .Case(#Name, OMPC_DYN_GROUPPRIVATE_##Name)
203#define OPENMP_DYN_GROUPPRIVATE_FALLBACK_MODIFIER(Name) \
204 .Case(#Name, OMPC_DYN_GROUPPRIVATE_FALLBACK_##Name) \
205 .Case("fallback(" #Name ")", OMPC_DYN_GROUPPRIVATE_FALLBACK_##Name)
206#include "clang/Basic/OpenMPKinds.def"
208 }
209 case OMPC_num_tasks: {
210 unsigned Type = llvm::StringSwitch<unsigned>(Str)
211#define OPENMP_NUMTASKS_MODIFIER(Name) .Case(#Name, OMPC_NUMTASKS_##Name)
212#include "clang/Basic/OpenMPKinds.def"
213 .Default(OMPC_NUMTASKS_unknown);
214 if (LangOpts.OpenMP < 51)
216 return Type;
217 }
218 case OMPC_allocate:
219 return llvm::StringSwitch<OpenMPAllocateClauseModifier>(Str)
220#define OPENMP_ALLOCATE_MODIFIER(Name) .Case(#Name, OMPC_ALLOCATE_##Name)
221#include "clang/Basic/OpenMPKinds.def"
222 .Default(OMPC_ALLOCATE_unknown);
223 case OMPC_threadset: {
224 unsigned Type = llvm::StringSwitch<unsigned>(Str)
225#define OPENMP_THREADSET_KIND(Name) .Case(#Name, OMPC_THREADSET_##Name)
226#include "clang/Basic/OpenMPKinds.def"
227 .Default(OMPC_THREADSET_unknown);
228 if (LangOpts.OpenMP < 60)
230 return Type;
231 }
232 case OMPC_num_threads: {
233 unsigned Type = llvm::StringSwitch<unsigned>(Str)
234#define OPENMP_NUMTHREADS_MODIFIER(Name) .Case(#Name, OMPC_NUMTHREADS_##Name)
235#include "clang/Basic/OpenMPKinds.def"
236 .Default(OMPC_NUMTHREADS_unknown);
237 if (LangOpts.OpenMP < 60)
239 return Type;
240 }
241 case OMPC_use_device_ptr: {
242 unsigned Type = llvm::StringSwitch<unsigned>(Str)
243#define OPENMP_USE_DEVICE_PTR_FALLBACK_MODIFIER(Name) \
244 .Case(#Name, OMPC_USE_DEVICE_PTR_FALLBACK_##Name)
245#include "clang/Basic/OpenMPKinds.def"
247 if (LangOpts.OpenMP < 61)
249 return Type;
250 }
251 case OMPC_unknown:
252 case OMPC_threadprivate:
253 case OMPC_groupprivate:
254 case OMPC_if:
255 case OMPC_final:
256 case OMPC_safelen:
257 case OMPC_simdlen:
258 case OMPC_sizes:
259 case OMPC_permutation:
260 case OMPC_allocator:
261 case OMPC_collapse:
262 case OMPC_private:
263 case OMPC_firstprivate:
264 case OMPC_shared:
265 case OMPC_task_reduction:
266 case OMPC_in_reduction:
267 case OMPC_aligned:
268 case OMPC_copyin:
269 case OMPC_copyprivate:
270 case OMPC_ordered:
271 case OMPC_nowait:
272 case OMPC_untied:
273 case OMPC_mergeable:
274 case OMPC_flush:
275 case OMPC_depobj:
276 case OMPC_read:
277 case OMPC_write:
278 case OMPC_capture:
279 case OMPC_compare:
280 case OMPC_seq_cst:
281 case OMPC_acq_rel:
282 case OMPC_acquire:
283 case OMPC_release:
284 case OMPC_relaxed:
285 case OMPC_threads:
286 case OMPC_simd:
287 case OMPC_num_teams:
288 case OMPC_thread_limit:
289 case OMPC_priority:
290 case OMPC_nogroup:
291 case OMPC_hint:
292 case OMPC_uniform:
293 case OMPC_use_device_addr:
294 case OMPC_is_device_ptr:
295 case OMPC_has_device_addr:
296 case OMPC_unified_address:
297 case OMPC_unified_shared_memory:
298 case OMPC_reverse_offload:
299 case OMPC_dynamic_allocators:
300 case OMPC_self_maps:
301 case OMPC_match:
302 case OMPC_nontemporal:
303 case OMPC_destroy:
304 case OMPC_novariants:
305 case OMPC_nocontext:
306 case OMPC_detach:
307 case OMPC_inclusive:
308 case OMPC_exclusive:
309 case OMPC_uses_allocators:
310 case OMPC_affinity:
311 case OMPC_when:
312 case OMPC_append_args:
313 case OMPC_looprange:
314 break;
315 default:
316 break;
317 }
318 llvm_unreachable("Invalid OpenMP simple clause kind");
319}
320
322 unsigned Type) {
323 switch (Kind) {
324 case OMPC_default:
325 switch (llvm::omp::DefaultKind(Type)) {
326#define OMP_DEFAULT_KIND(Enum, Name) \
327 case Enum: \
328 return Name;
329#include "llvm/Frontend/OpenMP/OMPKinds.def"
330 }
331 llvm_unreachable("Invalid OpenMP 'default' clause type");
332 case OMPC_proc_bind:
333 switch (Type) {
334#define OMP_PROC_BIND_KIND(Enum, Name, Value) \
335 case Value: \
336 return Name;
337#include "llvm/Frontend/OpenMP/OMPKinds.def"
338 }
339 llvm_unreachable("Invalid OpenMP 'proc_bind' clause type");
340 case OMPC_schedule:
341 switch (Type) {
344 return "unknown";
345#define OPENMP_SCHEDULE_KIND(Name) \
346 case OMPC_SCHEDULE_##Name: \
347 return #Name;
348#define OPENMP_SCHEDULE_MODIFIER(Name) \
349 case OMPC_SCHEDULE_MODIFIER_##Name: \
350 return #Name;
351#include "clang/Basic/OpenMPKinds.def"
352 }
353 llvm_unreachable("Invalid OpenMP 'schedule' clause type");
354 case OMPC_depend:
355 switch (Type) {
357 return "unknown";
358#define OPENMP_DEPEND_KIND(Name) \
359 case OMPC_DEPEND_##Name: \
360 return #Name;
361#include "clang/Basic/OpenMPKinds.def"
362 }
363 llvm_unreachable("Invalid OpenMP 'depend' clause type");
364 case OMPC_doacross:
365 switch (Type) {
367 return "unknown";
368#define OPENMP_DOACROSS_MODIFIER(Name) \
369 case OMPC_DOACROSS_##Name: \
370 return #Name;
371#include "clang/Basic/OpenMPKinds.def"
372 }
373 llvm_unreachable("Invalid OpenMP 'doacross' clause type");
374 case OMPC_linear:
375 switch (Type) {
377 return "unknown";
378#define OPENMP_LINEAR_KIND(Name) \
379 case OMPC_LINEAR_##Name: \
380 return #Name;
381#include "clang/Basic/OpenMPKinds.def"
382 }
383 llvm_unreachable("Invalid OpenMP 'linear' clause type");
384 case OMPC_map:
385 switch (Type) {
386 case OMPC_MAP_unknown:
388 return "unknown";
389#define OPENMP_MAP_KIND(Name) \
390 case OMPC_MAP_##Name: \
391 return #Name;
392#define OPENMP_MAP_MODIFIER_KIND(Name) \
393 case OMPC_MAP_MODIFIER_##Name: \
394 return #Name;
395#include "clang/Basic/OpenMPKinds.def"
396 default:
397 break;
398 }
399 llvm_unreachable("Invalid OpenMP 'map' clause type");
400 case OMPC_to:
401 case OMPC_from:
402 switch (Type) {
404 return "unknown";
405#define OPENMP_MOTION_MODIFIER_KIND(Name) \
406 case OMPC_MOTION_MODIFIER_##Name: \
407 return #Name;
408#include "clang/Basic/OpenMPKinds.def"
409 default:
410 break;
411 }
412 llvm_unreachable("Invalid OpenMP 'to' or 'from' clause type");
413 case OMPC_dist_schedule:
414 switch (Type) {
416 return "unknown";
417#define OPENMP_DIST_SCHEDULE_KIND(Name) \
418 case OMPC_DIST_SCHEDULE_##Name: \
419 return #Name;
420#include "clang/Basic/OpenMPKinds.def"
421 }
422 llvm_unreachable("Invalid OpenMP 'dist_schedule' clause type");
423 case OMPC_defaultmap:
424 switch (Type) {
427 return "unknown";
428#define OPENMP_DEFAULTMAP_KIND(Name) \
429 case OMPC_DEFAULTMAP_##Name: \
430 return #Name;
431#define OPENMP_DEFAULTMAP_MODIFIER(Name) \
432 case OMPC_DEFAULTMAP_MODIFIER_##Name: \
433 return #Name;
434#include "clang/Basic/OpenMPKinds.def"
435 }
436 llvm_unreachable("Invalid OpenMP 'defaultmap' clause type");
437 case OMPC_atomic_default_mem_order:
438 switch (Type) {
440 return "unknown";
441#define OPENMP_ATOMIC_DEFAULT_MEM_ORDER_KIND(Name) \
442 case OMPC_ATOMIC_DEFAULT_MEM_ORDER_##Name: \
443 return #Name;
444#include "clang/Basic/OpenMPKinds.def"
445}
446 llvm_unreachable("Invalid OpenMP 'atomic_default_mem_order' clause type");
447 case OMPC_device_type:
448 switch (Type) {
450 return "unknown";
451#define OPENMP_DEVICE_TYPE_KIND(Name) \
452 case OMPC_DEVICE_TYPE_##Name: \
453 return #Name;
454#include "clang/Basic/OpenMPKinds.def"
455 }
456 llvm_unreachable("Invalid OpenMP 'device_type' clause type");
457 case OMPC_at:
458 switch (Type) {
459 case OMPC_AT_unknown:
460 return "unknown";
461#define OPENMP_AT_KIND(Name) \
462 case OMPC_AT_##Name: \
463 return #Name;
464#include "clang/Basic/OpenMPKinds.def"
465 }
466 llvm_unreachable("Invalid OpenMP 'at' clause type");
467 case OMPC_severity:
468 switch (Type) {
470 return "unknown";
471#define OPENMP_SEVERITY_KIND(Name) \
472 case OMPC_SEVERITY_##Name: \
473 return #Name;
474#include "clang/Basic/OpenMPKinds.def"
475 }
476 llvm_unreachable("Invalid OpenMP 'severity' clause type");
477 case OMPC_lastprivate:
478 switch (Type) {
480 return "unknown";
481#define OPENMP_LASTPRIVATE_KIND(Name) \
482 case OMPC_LASTPRIVATE_##Name: \
483 return #Name;
484#include "clang/Basic/OpenMPKinds.def"
485 }
486 llvm_unreachable("Invalid OpenMP 'lastprivate' clause type");
487 case OMPC_order:
488 switch (Type) {
491 return "unknown";
492#define OPENMP_ORDER_KIND(Name) \
493 case OMPC_ORDER_##Name: \
494 return #Name;
495#define OPENMP_ORDER_MODIFIER(Name) \
496 case OMPC_ORDER_MODIFIER_##Name: \
497 return #Name;
498#include "clang/Basic/OpenMPKinds.def"
499 }
500 llvm_unreachable("Invalid OpenMP 'order' clause type");
501 case OMPC_update:
502 switch (Type) {
504 return "unknown";
505#define OPENMP_DEPEND_KIND(Name) \
506 case OMPC_DEPEND_##Name: \
507 return #Name;
508#include "clang/Basic/OpenMPKinds.def"
509 }
510 llvm_unreachable("Invalid OpenMP 'depend' clause type");
511 case OMPC_fail: {
512 OpenMPClauseKind CK = static_cast<OpenMPClauseKind>(Type);
513 return getOpenMPClauseName(CK).data();
514 llvm_unreachable("Invalid OpenMP 'fail' clause modifier");
515 }
516 case OMPC_device:
517 switch (Type) {
519 return "unknown";
520#define OPENMP_DEVICE_MODIFIER(Name) \
521 case OMPC_DEVICE_##Name: \
522 return #Name;
523#include "clang/Basic/OpenMPKinds.def"
524 }
525 llvm_unreachable("Invalid OpenMP 'device' clause modifier");
526 case OMPC_reduction:
527 switch (Type) {
529 return "unknown";
530#define OPENMP_REDUCTION_MODIFIER(Name) \
531 case OMPC_REDUCTION_##Name: \
532 return #Name;
533#include "clang/Basic/OpenMPKinds.def"
534 }
535 llvm_unreachable("Invalid OpenMP 'reduction' clause modifier");
536 case OMPC_adjust_args:
537 switch (Type) {
539 return "unknown";
540#define OPENMP_ADJUST_ARGS_KIND(Name) \
541 case OMPC_ADJUST_ARGS_##Name: \
542 return #Name;
543#include "clang/Basic/OpenMPKinds.def"
544 }
545 llvm_unreachable("Invalid OpenMP 'adjust_args' clause kind");
546 case OMPC_bind:
547 switch (Type) {
549 return "unknown";
550#define OPENMP_BIND_KIND(Name) \
551 case OMPC_BIND_##Name: \
552 return #Name;
553#include "clang/Basic/OpenMPKinds.def"
554 }
555 llvm_unreachable("Invalid OpenMP 'bind' clause type");
556 case OMPC_grainsize:
557 switch (Type) {
559 return "unknown";
560#define OPENMP_GRAINSIZE_MODIFIER(Name) \
561 case OMPC_GRAINSIZE_##Name: \
562 return #Name;
563#include "clang/Basic/OpenMPKinds.def"
564 }
565 llvm_unreachable("Invalid OpenMP 'grainsize' clause modifier");
566 case OMPC_dyn_groupprivate:
567 switch (Type) {
570 return "unknown";
571#define OPENMP_DYN_GROUPPRIVATE_MODIFIER(Name) \
572 case OMPC_DYN_GROUPPRIVATE_##Name: \
573 return #Name;
574#define OPENMP_DYN_GROUPPRIVATE_FALLBACK_MODIFIER(Name) \
575 case OMPC_DYN_GROUPPRIVATE_FALLBACK_##Name: \
576 return "fallback(" #Name ")";
577#include "clang/Basic/OpenMPKinds.def"
578 }
579 llvm_unreachable("Invalid OpenMP 'dyn_groupprivate' clause modifier");
580 case OMPC_num_tasks:
581 switch (Type) {
583 return "unknown";
584#define OPENMP_NUMTASKS_MODIFIER(Name) \
585 case OMPC_NUMTASKS_##Name: \
586 return #Name;
587#include "clang/Basic/OpenMPKinds.def"
588 }
589 llvm_unreachable("Invalid OpenMP 'num_tasks' clause modifier");
590 case OMPC_allocate:
591 switch (Type) {
593 return "unknown";
594#define OPENMP_ALLOCATE_MODIFIER(Name) \
595 case OMPC_ALLOCATE_##Name: \
596 return #Name;
597#include "clang/Basic/OpenMPKinds.def"
598 }
599 llvm_unreachable("Invalid OpenMP 'allocate' clause modifier");
600 case OMPC_num_threads:
601 switch (Type) {
603 return "unknown";
604#define OPENMP_NUMTHREADS_MODIFIER(Name) \
605 case OMPC_NUMTHREADS_##Name: \
606 return #Name;
607#include "clang/Basic/OpenMPKinds.def"
608 }
609 llvm_unreachable("Invalid OpenMP 'num_threads' clause modifier");
610 case OMPC_threadset:
611 switch (Type) {
613 return "unknown";
614#define OPENMP_THREADSET_KIND(Name) \
615 case OMPC_THREADSET_##Name: \
616 return #Name;
617#include "clang/Basic/OpenMPKinds.def"
618 }
619 llvm_unreachable("Invalid OpenMP 'threadset' clause modifier");
620 case OMPC_use_device_ptr:
621 switch (Type) {
623 return "unknown";
624#define OPENMP_USE_DEVICE_PTR_FALLBACK_MODIFIER(Name) \
625 case OMPC_USE_DEVICE_PTR_FALLBACK_##Name: \
626 return #Name;
627#include "clang/Basic/OpenMPKinds.def"
628 }
629 llvm_unreachable("Invalid OpenMP 'use_device_ptr' clause modifier");
630 case OMPC_unknown:
631 case OMPC_threadprivate:
632 case OMPC_groupprivate:
633 case OMPC_if:
634 case OMPC_final:
635 case OMPC_safelen:
636 case OMPC_simdlen:
637 case OMPC_sizes:
638 case OMPC_permutation:
639 case OMPC_allocator:
640 case OMPC_collapse:
641 case OMPC_private:
642 case OMPC_firstprivate:
643 case OMPC_shared:
644 case OMPC_task_reduction:
645 case OMPC_in_reduction:
646 case OMPC_aligned:
647 case OMPC_copyin:
648 case OMPC_copyprivate:
649 case OMPC_ordered:
650 case OMPC_nowait:
651 case OMPC_untied:
652 case OMPC_mergeable:
653 case OMPC_flush:
654 case OMPC_depobj:
655 case OMPC_read:
656 case OMPC_write:
657 case OMPC_capture:
658 case OMPC_compare:
659 case OMPC_seq_cst:
660 case OMPC_acq_rel:
661 case OMPC_acquire:
662 case OMPC_release:
663 case OMPC_relaxed:
664 case OMPC_threads:
665 case OMPC_simd:
666 case OMPC_num_teams:
667 case OMPC_thread_limit:
668 case OMPC_priority:
669 case OMPC_nogroup:
670 case OMPC_hint:
671 case OMPC_uniform:
672 case OMPC_use_device_addr:
673 case OMPC_is_device_ptr:
674 case OMPC_has_device_addr:
675 case OMPC_unified_address:
676 case OMPC_unified_shared_memory:
677 case OMPC_reverse_offload:
678 case OMPC_dynamic_allocators:
679 case OMPC_self_maps:
680 case OMPC_match:
681 case OMPC_nontemporal:
682 case OMPC_destroy:
683 case OMPC_detach:
684 case OMPC_novariants:
685 case OMPC_nocontext:
686 case OMPC_inclusive:
687 case OMPC_exclusive:
688 case OMPC_uses_allocators:
689 case OMPC_affinity:
690 case OMPC_when:
691 case OMPC_append_args:
692 case OMPC_looprange:
693 break;
694 default:
695 break;
696 }
697 llvm_unreachable("Invalid OpenMP simple clause kind");
698}
699
701 return getDirectiveAssociation(DKind) == Association::LoopNest;
702}
703
705 return DKind == OMPD_for || DKind == OMPD_for_simd ||
706 DKind == OMPD_sections || DKind == OMPD_section ||
707 DKind == OMPD_single || DKind == OMPD_parallel_for ||
708 DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
709 DKind == OMPD_target_parallel_for ||
710 DKind == OMPD_distribute_parallel_for ||
711 DKind == OMPD_distribute_parallel_for_simd ||
712 DKind == OMPD_target_parallel_for_simd ||
713 DKind == OMPD_teams_distribute_parallel_for_simd ||
714 DKind == OMPD_teams_distribute_parallel_for ||
715 DKind == OMPD_target_teams_distribute_parallel_for ||
716 DKind == OMPD_target_teams_distribute_parallel_for_simd ||
717 DKind == OMPD_parallel_loop || DKind == OMPD_teams_loop ||
718 DKind == OMPD_target_parallel_loop || DKind == OMPD_target_teams_loop;
719}
720
722 return DKind == OMPD_taskloop ||
723 llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
724}
725
727 if (DKind == OMPD_teams_loop)
728 return true;
729 return DKind == OMPD_parallel ||
730 llvm::is_contained(getLeafConstructs(DKind), OMPD_parallel);
731}
732
734 return DKind == OMPD_target ||
735 llvm::is_contained(getLeafConstructs(DKind), OMPD_target);
736}
737
739 return DKind == OMPD_target_data || DKind == OMPD_target_enter_data ||
740 DKind == OMPD_target_exit_data || DKind == OMPD_target_update;
741}
742
744 return DKind == OMPD_target_data || DKind == OMPD_target_enter_data ||
746}
747
749 if (DKind == OMPD_teams)
750 return true;
751 ArrayRef<Directive> Leaves = getLeafConstructs(DKind);
752 return !Leaves.empty() && Leaves.front() == OMPD_teams;
753}
754
756 return DKind == OMPD_teams ||
757 llvm::is_contained(getLeafConstructs(DKind), OMPD_teams);
758}
759
761 // Avoid OMPD_declare_simd
762 if (getDirectiveAssociation(DKind) != Association::LoopNest)
763 return false;
764 // Formally, OMPD_end_do_simd also has a loop association, but
765 // it's a Fortran-specific directive.
766
767 return DKind == OMPD_simd ||
768 llvm::is_contained(getLeafConstructs(DKind), OMPD_simd);
769}
770
772 if (Kind == OMPD_distribute)
773 return true;
774 ArrayRef<Directive> Leaves = getLeafConstructs(Kind);
775 return !Leaves.empty() && Leaves.front() == OMPD_distribute;
776}
777
779 return Kind == OMPD_distribute ||
780 llvm::is_contained(getLeafConstructs(Kind), OMPD_distribute);
781}
782
784 if (Kind == OMPD_loop)
785 return true;
786 ArrayRef<Directive> Leaves = getLeafConstructs(Kind);
787 return !Leaves.empty() && Leaves.back() == OMPD_loop;
788}
789
791 return Kind == OMPC_private || Kind == OMPC_firstprivate ||
792 Kind == OMPC_lastprivate || Kind == OMPC_linear ||
793 Kind == OMPC_reduction || Kind == OMPC_task_reduction ||
794 Kind == OMPC_in_reduction; // TODO add next clauses like 'reduction'.
795}
796
798 return Kind == OMPC_threadprivate || Kind == OMPC_copyin;
799}
800
802 return Kind == OMPD_task || isOpenMPTaskLoopDirective(Kind);
803}
804
806 return Kind == OMPD_distribute_parallel_for ||
807 Kind == OMPD_distribute_parallel_for_simd ||
808 Kind == OMPD_teams_distribute_parallel_for_simd ||
809 Kind == OMPD_teams_distribute_parallel_for ||
810 Kind == OMPD_target_teams_distribute_parallel_for ||
811 Kind == OMPD_target_teams_distribute_parallel_for_simd ||
812 Kind == OMPD_teams_loop || Kind == OMPD_target_teams_loop;
813}
814
816 OpenMPDirectiveKind DKind) {
817 return DKind == OMPD_tile || DKind == OMPD_unroll || DKind == OMPD_reverse ||
818 DKind == OMPD_interchange || DKind == OMPD_stripe;
819}
820
822 OpenMPDirectiveKind DKind) {
823 return DKind == OMPD_fuse;
824}
825
830
832 return DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
833 DKind == OMPD_parallel_master ||
834 DKind == OMPD_parallel_master_taskloop ||
835 DKind == OMPD_parallel_master_taskloop_simd ||
836 DKind == OMPD_parallel_sections;
837}
838
840 return DKind == OMPD_target || DKind == OMPD_target_parallel ||
841 DKind == OMPD_target_parallel_for ||
842 DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
843 DKind == OMPD_target_parallel_loop;
844}
845
847 if (DKind == OMPD_error)
848 return true;
849 Category Cat = getDirectiveCategory(DKind);
850 return Cat == Category::Executable || Cat == Category::Subsidiary;
851}
852
854 if (DKind == OMPD_error)
855 return true;
856 Category Cat = getDirectiveCategory(DKind);
857 return Cat == Category::Informational;
858}
859
861 if (isOpenMPExecutableDirective(DKind)) {
862 switch (DKind) {
863 case OMPD_atomic:
864 case OMPD_barrier:
865 case OMPD_cancel:
866 case OMPD_cancellation_point:
867 case OMPD_critical:
868 case OMPD_depobj:
869 case OMPD_error:
870 case OMPD_flush:
871 case OMPD_masked:
872 case OMPD_master:
873 case OMPD_section:
874 case OMPD_taskwait:
875 case OMPD_taskyield:
876 case OMPD_assume:
877 return false;
878 default:
880 }
881 }
882 // Non-executable directives.
883 switch (DKind) {
884 case OMPD_metadirective:
885 case OMPD_nothing:
886 return true;
887 default:
888 break;
889 }
890 return false;
891}
892
894 OpenMPDirectiveKind DKind, const LangOptions &LangOpts) {
895 // Directives strictly nestable in a construct with order(concurrent) are:
896 // OpenMP 5.x: loop, parallel, simd, combined directive starting with parallel
897 // OpenMP 6.0: above plus atomic and all loop-transformation directives
898
899 if (DKind == OMPD_loop || DKind == OMPD_parallel || DKind == OMPD_simd ||
901 return true;
902
903 if (LangOpts.OpenMP >= 60)
904 return DKind == OMPD_atomic ||
906
907 return false;
908}
909
912 OpenMPDirectiveKind DKind) {
913 assert(unsigned(DKind) < llvm::omp::Directive_enumSize);
914 assert(isOpenMPCapturingDirective(DKind) && "Expecting capturing directive");
915
916 auto GetRegionsForLeaf = [&](OpenMPDirectiveKind LKind) {
917 assert(isLeafConstruct(LKind) && "Epecting leaf directive");
918 // Whether a leaf would require OMPD_unknown if it occurred on its own.
919 switch (LKind) {
920 case OMPD_metadirective:
921 CaptureRegions.push_back(OMPD_metadirective);
922 break;
923 case OMPD_nothing:
924 CaptureRegions.push_back(OMPD_nothing);
925 break;
926 case OMPD_parallel:
927 CaptureRegions.push_back(OMPD_parallel);
928 break;
929 case OMPD_target:
930 CaptureRegions.push_back(OMPD_task);
931 CaptureRegions.push_back(OMPD_target);
932 break;
933 case OMPD_task:
934 case OMPD_target_enter_data:
935 case OMPD_target_exit_data:
936 case OMPD_target_update:
937 CaptureRegions.push_back(OMPD_task);
938 break;
939 case OMPD_teams:
940 CaptureRegions.push_back(OMPD_teams);
941 break;
942 case OMPD_taskloop:
943 CaptureRegions.push_back(OMPD_taskloop);
944 break;
945 case OMPD_loop:
946 // TODO: 'loop' may require different capture regions depending on the
947 // bind clause or the parent directive when there is no bind clause.
948 // If any of the directives that push regions here are parents of 'loop',
949 // assume 'parallel'. Otherwise do nothing.
950 if (!CaptureRegions.empty() &&
951 !llvm::is_contained(CaptureRegions, OMPD_parallel))
952 CaptureRegions.push_back(OMPD_parallel);
953 else
954 return true;
955 break;
956 case OMPD_dispatch:
957 case OMPD_distribute:
958 case OMPD_for:
959 case OMPD_ordered:
960 case OMPD_scope:
961 case OMPD_sections:
962 case OMPD_simd:
963 case OMPD_single:
964 case OMPD_target_data:
965 case OMPD_taskgroup:
966 case OMPD_stripe:
967 // These directives (when standalone) use OMPD_unknown as the region,
968 // but when they're constituents of a compound directive, and other
969 // leafs from that directive have specific regions, then these directives
970 // add no additional regions.
971 return true;
972 case OMPD_masked:
973 case OMPD_master:
974 return false;
975 default:
976 llvm::errs() << getOpenMPDirectiveName(LKind, llvm::omp::FallbackVersion)
977 << '\n';
978 llvm_unreachable("Unexpected directive");
979 }
980 return false;
981 };
982
983 bool MayNeedUnknownRegion = false;
984 for (OpenMPDirectiveKind L : getLeafConstructsOrSelf(DKind))
985 MayNeedUnknownRegion |= GetRegionsForLeaf(L);
986
987 // We need OMPD_unknown when no regions were added, and specific leaf
988 // constructs were present. Push a single OMPD_unknown as the capture
989 /// region.
990 if (CaptureRegions.empty() && MayNeedUnknownRegion)
991 CaptureRegions.push_back(OMPD_unknown);
992
993 // OMPD_unknown is only expected as the only region. If other regions
994 // are present OMPD_unknown should not be present.
995 assert((CaptureRegions[0] == OMPD_unknown ||
996 !llvm::is_contained(CaptureRegions, OMPD_unknown)) &&
997 "Misplaced OMPD_unknown");
998}
999
1001 return FailClauseParameter == llvm::omp::OMPC_acquire ||
1002 FailClauseParameter == llvm::omp::OMPC_relaxed ||
1003 FailClauseParameter == llvm::omp::OMPC_seq_cst;
1004}
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Defines some OpenMP-specific enums and functions.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
The base class of the type hierarchy.
Definition TypeBase.h:1833
The JSON file list parser is used to communicate input to InstallAPI.
bool isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a worksharing directive.
bool needsTaskBasedThreadLimit(OpenMPDirectiveKind DKind)
Checks if the specified target directive, combined or not, needs task based thread_limit.
bool isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind)
Checks if the specified composite/combined directive constitutes a teams directive in the outermost n...
bool checkFailClauseParameter(OpenMPClauseKind FailClauseParameter)
Checks if the parameter to the fail clause in "#pragma atomic compare fail" is restricted only to mem...
bool isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a target data offload directive.
OpenMPDefaultClauseVariableCategory
OpenMP variable-category for 'default' clause.
@ OMPC_DEFAULT_VC_unknown
bool isOpenMPLoopTransformationDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a loop transformation directive.
@ OMPC_DEFAULTMAP_MODIFIER_last
@ OMPC_DEFAULTMAP_MODIFIER_unknown
@ OMPC_ORDER_MODIFIER_last
@ OMPC_ADJUST_ARGS_unknown
@ OMPC_AT_unknown
bool isOpenMPDistributeDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a distribute directive.
@ OMPC_REDUCTION_unknown
@ OMPC_DEVICE_TYPE_unknown
@ OMPC_SCHEDULE_MODIFIER_last
Definition OpenMPKinds.h:44
const char * getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, unsigned Type)
bool isOpenMPParallelDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a parallel-kind directive.
bool isOpenMPPrivate(OpenMPClauseKind Kind)
Checks if the specified clause is one of private clauses like 'private', 'firstprivate',...
@ OMPC_DIST_SCHEDULE_unknown
@ OMPC_DOACROSS_unknown
bool isOpenMPTaskingDirective(OpenMPDirectiveKind Kind)
Checks if the specified directive kind is one of tasking directives - task, taskloop,...
bool isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a target code offload directive.
@ OMPC_DYN_GROUPPRIVATE_FALLBACK_last
bool isOpenMPTeamsDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a teams-kind directive.
bool isOpenMPGenericLoopDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive constitutes a 'loop' directive in the outermost nest.
@ OMPC_BIND_unknown
@ OMPC_LASTPRIVATE_unknown
@ OMPC_DEPEND_unknown
Definition OpenMPKinds.h:59
bool isOpenMPCanonicalLoopSequenceTransformationDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a loop transformation directive that applies to a canonical loop...
@ OMPC_GRAINSIZE_unknown
unsigned getOpenMPSimpleClauseType(OpenMPClauseKind Kind, llvm::StringRef Str, const LangOptions &LangOpts)
bool isOpenMPCanonicalLoopNestTransformationDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a loop transformation directive that applies to a canonical loop...
@ OMPC_NUMTASKS_unknown
bool isOpenMPTargetMapEnteringDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a map-entering target directive.
@ OMPC_USE_DEVICE_PTR_FALLBACK_unknown
bool isOpenMPOrderConcurrentNestableDirective(OpenMPDirectiveKind DKind, const LangOptions &LangOpts)
Checks if the specified directive is an order concurrent nestable directive that can be nested within...
bool isOpenMPLoopDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a directive with an associated loop construct.
bool isOpenMPCapturingDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive can capture variables.
@ OMPC_SEVERITY_unknown
bool isOpenMPLoopBoundSharingDirective(OpenMPDirectiveKind Kind)
Checks if the specified directive kind is one of the composite or combined directives that need loop ...
@ OMPC_MOTION_MODIFIER_unknown
Definition OpenMPKinds.h:96
@ OMPC_DEFAULTMAP_unknown
@ OMPC_ALLOCATE_unknown
bool isOpenMPThreadPrivate(OpenMPClauseKind Kind)
Checks if the specified clause is one of threadprivate clauses like 'threadprivate',...
@ OMPC_LINEAR_unknown
Definition OpenMPKinds.h:67
bool isOpenMPExecutableDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is considered as "executable".
llvm::omp::Directive OpenMPDirectiveKind
OpenMP directives.
Definition OpenMPKinds.h:25
@ OMPC_DYN_GROUPPRIVATE_unknown
bool isOpenMPInformationalDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is considered as "informational".
bool isOpenMPSimdDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a simd directive.
void getOpenMPCaptureRegions(llvm::SmallVectorImpl< OpenMPDirectiveKind > &CaptureRegions, OpenMPDirectiveKind DKind)
Return the captured regions of an OpenMP directive.
@ OMPC_NUMTHREADS_unknown
@ OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown
const char * getOpenMPDefaultVariableCategoryName(unsigned VC)
@ OMPC_DEVICE_unknown
Definition OpenMPKinds.h:51
@ OMPC_MAP_MODIFIER_last
Definition OpenMPKinds.h:84
@ OMPC_MAP_MODIFIER_unknown
Definition OpenMPKinds.h:80
bool isOpenMPCombinedParallelADirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a combined construct for which the first construct is a parallel...
llvm::omp::Clause OpenMPClauseKind
OpenMP clauses.
Definition OpenMPKinds.h:28
bool isOpenMPNestingDistributeDirective(OpenMPDirectiveKind DKind)
Checks if the specified composite/combined directive constitutes a distribute directive in the outerm...
@ OMPC_ORDER_unknown
@ OMPC_SCHEDULE_unknown
Definition OpenMPKinds.h:35
bool isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a taskloop directive.
@ OMPC_THREADSET_unknown
OpenMPDefaultClauseVariableCategory getOpenMPDefaultVariableCategory(StringRef Str, const LangOptions &LangOpts)
@ OMPC_MAP_unknown
Definition OpenMPKinds.h:75