clang 22.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_num_tasks: {
200 unsigned Type = llvm::StringSwitch<unsigned>(Str)
201#define OPENMP_NUMTASKS_MODIFIER(Name) .Case(#Name, OMPC_NUMTASKS_##Name)
202#include "clang/Basic/OpenMPKinds.def"
203 .Default(OMPC_NUMTASKS_unknown);
204 if (LangOpts.OpenMP < 51)
206 return Type;
207 }
208 case OMPC_allocate:
209 return llvm::StringSwitch<OpenMPAllocateClauseModifier>(Str)
210#define OPENMP_ALLOCATE_MODIFIER(Name) .Case(#Name, OMPC_ALLOCATE_##Name)
211#include "clang/Basic/OpenMPKinds.def"
212 .Default(OMPC_ALLOCATE_unknown);
213 case OMPC_threadset: {
214 unsigned Type = llvm::StringSwitch<unsigned>(Str)
215#define OPENMP_THREADSET_KIND(Name) .Case(#Name, OMPC_THREADSET_##Name)
216#include "clang/Basic/OpenMPKinds.def"
217 .Default(OMPC_THREADSET_unknown);
218 if (LangOpts.OpenMP < 60)
220 return Type;
221 }
222 case OMPC_num_threads: {
223 unsigned Type = llvm::StringSwitch<unsigned>(Str)
224#define OPENMP_NUMTHREADS_MODIFIER(Name) .Case(#Name, OMPC_NUMTHREADS_##Name)
225#include "clang/Basic/OpenMPKinds.def"
226 .Default(OMPC_NUMTHREADS_unknown);
227 if (LangOpts.OpenMP < 60)
229 return Type;
230 }
231 case OMPC_unknown:
232 case OMPC_threadprivate:
233 case OMPC_groupprivate:
234 case OMPC_if:
235 case OMPC_final:
236 case OMPC_safelen:
237 case OMPC_simdlen:
238 case OMPC_sizes:
239 case OMPC_permutation:
240 case OMPC_allocator:
241 case OMPC_collapse:
242 case OMPC_private:
243 case OMPC_firstprivate:
244 case OMPC_shared:
245 case OMPC_task_reduction:
246 case OMPC_in_reduction:
247 case OMPC_aligned:
248 case OMPC_copyin:
249 case OMPC_copyprivate:
250 case OMPC_ordered:
251 case OMPC_nowait:
252 case OMPC_untied:
253 case OMPC_mergeable:
254 case OMPC_flush:
255 case OMPC_depobj:
256 case OMPC_read:
257 case OMPC_write:
258 case OMPC_capture:
259 case OMPC_compare:
260 case OMPC_seq_cst:
261 case OMPC_acq_rel:
262 case OMPC_acquire:
263 case OMPC_release:
264 case OMPC_relaxed:
265 case OMPC_threads:
266 case OMPC_simd:
267 case OMPC_num_teams:
268 case OMPC_thread_limit:
269 case OMPC_priority:
270 case OMPC_nogroup:
271 case OMPC_hint:
272 case OMPC_uniform:
273 case OMPC_use_device_ptr:
274 case OMPC_use_device_addr:
275 case OMPC_is_device_ptr:
276 case OMPC_has_device_addr:
277 case OMPC_unified_address:
278 case OMPC_unified_shared_memory:
279 case OMPC_reverse_offload:
280 case OMPC_dynamic_allocators:
281 case OMPC_self_maps:
282 case OMPC_match:
283 case OMPC_nontemporal:
284 case OMPC_destroy:
285 case OMPC_novariants:
286 case OMPC_nocontext:
287 case OMPC_detach:
288 case OMPC_inclusive:
289 case OMPC_exclusive:
290 case OMPC_uses_allocators:
291 case OMPC_affinity:
292 case OMPC_when:
293 case OMPC_append_args:
294 case OMPC_looprange:
295 break;
296 default:
297 break;
298 }
299 llvm_unreachable("Invalid OpenMP simple clause kind");
300}
301
303 unsigned Type) {
304 switch (Kind) {
305 case OMPC_default:
306 switch (llvm::omp::DefaultKind(Type)) {
307#define OMP_DEFAULT_KIND(Enum, Name) \
308 case Enum: \
309 return Name;
310#include "llvm/Frontend/OpenMP/OMPKinds.def"
311 }
312 llvm_unreachable("Invalid OpenMP 'default' clause type");
313 case OMPC_proc_bind:
314 switch (Type) {
315#define OMP_PROC_BIND_KIND(Enum, Name, Value) \
316 case Value: \
317 return Name;
318#include "llvm/Frontend/OpenMP/OMPKinds.def"
319 }
320 llvm_unreachable("Invalid OpenMP 'proc_bind' clause type");
321 case OMPC_schedule:
322 switch (Type) {
325 return "unknown";
326#define OPENMP_SCHEDULE_KIND(Name) \
327 case OMPC_SCHEDULE_##Name: \
328 return #Name;
329#define OPENMP_SCHEDULE_MODIFIER(Name) \
330 case OMPC_SCHEDULE_MODIFIER_##Name: \
331 return #Name;
332#include "clang/Basic/OpenMPKinds.def"
333 }
334 llvm_unreachable("Invalid OpenMP 'schedule' clause type");
335 case OMPC_depend:
336 switch (Type) {
338 return "unknown";
339#define OPENMP_DEPEND_KIND(Name) \
340 case OMPC_DEPEND_##Name: \
341 return #Name;
342#include "clang/Basic/OpenMPKinds.def"
343 }
344 llvm_unreachable("Invalid OpenMP 'depend' clause type");
345 case OMPC_doacross:
346 switch (Type) {
348 return "unknown";
349#define OPENMP_DOACROSS_MODIFIER(Name) \
350 case OMPC_DOACROSS_##Name: \
351 return #Name;
352#include "clang/Basic/OpenMPKinds.def"
353 }
354 llvm_unreachable("Invalid OpenMP 'doacross' clause type");
355 case OMPC_linear:
356 switch (Type) {
358 return "unknown";
359#define OPENMP_LINEAR_KIND(Name) \
360 case OMPC_LINEAR_##Name: \
361 return #Name;
362#include "clang/Basic/OpenMPKinds.def"
363 }
364 llvm_unreachable("Invalid OpenMP 'linear' clause type");
365 case OMPC_map:
366 switch (Type) {
367 case OMPC_MAP_unknown:
369 return "unknown";
370#define OPENMP_MAP_KIND(Name) \
371 case OMPC_MAP_##Name: \
372 return #Name;
373#define OPENMP_MAP_MODIFIER_KIND(Name) \
374 case OMPC_MAP_MODIFIER_##Name: \
375 return #Name;
376#include "clang/Basic/OpenMPKinds.def"
377 default:
378 break;
379 }
380 llvm_unreachable("Invalid OpenMP 'map' clause type");
381 case OMPC_to:
382 case OMPC_from:
383 switch (Type) {
385 return "unknown";
386#define OPENMP_MOTION_MODIFIER_KIND(Name) \
387 case OMPC_MOTION_MODIFIER_##Name: \
388 return #Name;
389#include "clang/Basic/OpenMPKinds.def"
390 default:
391 break;
392 }
393 llvm_unreachable("Invalid OpenMP 'to' or 'from' clause type");
394 case OMPC_dist_schedule:
395 switch (Type) {
397 return "unknown";
398#define OPENMP_DIST_SCHEDULE_KIND(Name) \
399 case OMPC_DIST_SCHEDULE_##Name: \
400 return #Name;
401#include "clang/Basic/OpenMPKinds.def"
402 }
403 llvm_unreachable("Invalid OpenMP 'dist_schedule' clause type");
404 case OMPC_defaultmap:
405 switch (Type) {
408 return "unknown";
409#define OPENMP_DEFAULTMAP_KIND(Name) \
410 case OMPC_DEFAULTMAP_##Name: \
411 return #Name;
412#define OPENMP_DEFAULTMAP_MODIFIER(Name) \
413 case OMPC_DEFAULTMAP_MODIFIER_##Name: \
414 return #Name;
415#include "clang/Basic/OpenMPKinds.def"
416 }
417 llvm_unreachable("Invalid OpenMP 'defaultmap' clause type");
418 case OMPC_atomic_default_mem_order:
419 switch (Type) {
421 return "unknown";
422#define OPENMP_ATOMIC_DEFAULT_MEM_ORDER_KIND(Name) \
423 case OMPC_ATOMIC_DEFAULT_MEM_ORDER_##Name: \
424 return #Name;
425#include "clang/Basic/OpenMPKinds.def"
426}
427 llvm_unreachable("Invalid OpenMP 'atomic_default_mem_order' clause type");
428 case OMPC_device_type:
429 switch (Type) {
431 return "unknown";
432#define OPENMP_DEVICE_TYPE_KIND(Name) \
433 case OMPC_DEVICE_TYPE_##Name: \
434 return #Name;
435#include "clang/Basic/OpenMPKinds.def"
436 }
437 llvm_unreachable("Invalid OpenMP 'device_type' clause type");
438 case OMPC_at:
439 switch (Type) {
440 case OMPC_AT_unknown:
441 return "unknown";
442#define OPENMP_AT_KIND(Name) \
443 case OMPC_AT_##Name: \
444 return #Name;
445#include "clang/Basic/OpenMPKinds.def"
446 }
447 llvm_unreachable("Invalid OpenMP 'at' clause type");
448 case OMPC_severity:
449 switch (Type) {
451 return "unknown";
452#define OPENMP_SEVERITY_KIND(Name) \
453 case OMPC_SEVERITY_##Name: \
454 return #Name;
455#include "clang/Basic/OpenMPKinds.def"
456 }
457 llvm_unreachable("Invalid OpenMP 'severity' clause type");
458 case OMPC_lastprivate:
459 switch (Type) {
461 return "unknown";
462#define OPENMP_LASTPRIVATE_KIND(Name) \
463 case OMPC_LASTPRIVATE_##Name: \
464 return #Name;
465#include "clang/Basic/OpenMPKinds.def"
466 }
467 llvm_unreachable("Invalid OpenMP 'lastprivate' clause type");
468 case OMPC_order:
469 switch (Type) {
472 return "unknown";
473#define OPENMP_ORDER_KIND(Name) \
474 case OMPC_ORDER_##Name: \
475 return #Name;
476#define OPENMP_ORDER_MODIFIER(Name) \
477 case OMPC_ORDER_MODIFIER_##Name: \
478 return #Name;
479#include "clang/Basic/OpenMPKinds.def"
480 }
481 llvm_unreachable("Invalid OpenMP 'order' clause type");
482 case OMPC_update:
483 switch (Type) {
485 return "unknown";
486#define OPENMP_DEPEND_KIND(Name) \
487 case OMPC_DEPEND_##Name: \
488 return #Name;
489#include "clang/Basic/OpenMPKinds.def"
490 }
491 llvm_unreachable("Invalid OpenMP 'depend' clause type");
492 case OMPC_fail: {
493 OpenMPClauseKind CK = static_cast<OpenMPClauseKind>(Type);
494 return getOpenMPClauseName(CK).data();
495 llvm_unreachable("Invalid OpenMP 'fail' clause modifier");
496 }
497 case OMPC_device:
498 switch (Type) {
500 return "unknown";
501#define OPENMP_DEVICE_MODIFIER(Name) \
502 case OMPC_DEVICE_##Name: \
503 return #Name;
504#include "clang/Basic/OpenMPKinds.def"
505 }
506 llvm_unreachable("Invalid OpenMP 'device' clause modifier");
507 case OMPC_reduction:
508 switch (Type) {
510 return "unknown";
511#define OPENMP_REDUCTION_MODIFIER(Name) \
512 case OMPC_REDUCTION_##Name: \
513 return #Name;
514#include "clang/Basic/OpenMPKinds.def"
515 }
516 llvm_unreachable("Invalid OpenMP 'reduction' clause modifier");
517 case OMPC_adjust_args:
518 switch (Type) {
520 return "unknown";
521#define OPENMP_ADJUST_ARGS_KIND(Name) \
522 case OMPC_ADJUST_ARGS_##Name: \
523 return #Name;
524#include "clang/Basic/OpenMPKinds.def"
525 }
526 llvm_unreachable("Invalid OpenMP 'adjust_args' clause kind");
527 case OMPC_bind:
528 switch (Type) {
530 return "unknown";
531#define OPENMP_BIND_KIND(Name) \
532 case OMPC_BIND_##Name: \
533 return #Name;
534#include "clang/Basic/OpenMPKinds.def"
535 }
536 llvm_unreachable("Invalid OpenMP 'bind' clause type");
537 case OMPC_grainsize:
538 switch (Type) {
540 return "unknown";
541#define OPENMP_GRAINSIZE_MODIFIER(Name) \
542 case OMPC_GRAINSIZE_##Name: \
543 return #Name;
544#include "clang/Basic/OpenMPKinds.def"
545 }
546 llvm_unreachable("Invalid OpenMP 'grainsize' clause modifier");
547 case OMPC_num_tasks:
548 switch (Type) {
550 return "unknown";
551#define OPENMP_NUMTASKS_MODIFIER(Name) \
552 case OMPC_NUMTASKS_##Name: \
553 return #Name;
554#include "clang/Basic/OpenMPKinds.def"
555 }
556 llvm_unreachable("Invalid OpenMP 'num_tasks' clause modifier");
557 case OMPC_allocate:
558 switch (Type) {
560 return "unknown";
561#define OPENMP_ALLOCATE_MODIFIER(Name) \
562 case OMPC_ALLOCATE_##Name: \
563 return #Name;
564#include "clang/Basic/OpenMPKinds.def"
565 }
566 llvm_unreachable("Invalid OpenMP 'allocate' clause modifier");
567 case OMPC_num_threads:
568 switch (Type) {
570 return "unknown";
571#define OPENMP_NUMTHREADS_MODIFIER(Name) \
572 case OMPC_NUMTHREADS_##Name: \
573 return #Name;
574#include "clang/Basic/OpenMPKinds.def"
575 }
576 llvm_unreachable("Invalid OpenMP 'num_threads' clause modifier");
577 case OMPC_threadset:
578 switch (Type) {
580 return "unknown";
581#define OPENMP_THREADSET_KIND(Name) \
582 case OMPC_THREADSET_##Name: \
583 return #Name;
584#include "clang/Basic/OpenMPKinds.def"
585 }
586 llvm_unreachable("Invalid OpenMP 'threadset' clause modifier");
587 case OMPC_unknown:
588 case OMPC_threadprivate:
589 case OMPC_groupprivate:
590 case OMPC_if:
591 case OMPC_final:
592 case OMPC_safelen:
593 case OMPC_simdlen:
594 case OMPC_sizes:
595 case OMPC_permutation:
596 case OMPC_allocator:
597 case OMPC_collapse:
598 case OMPC_private:
599 case OMPC_firstprivate:
600 case OMPC_shared:
601 case OMPC_task_reduction:
602 case OMPC_in_reduction:
603 case OMPC_aligned:
604 case OMPC_copyin:
605 case OMPC_copyprivate:
606 case OMPC_ordered:
607 case OMPC_nowait:
608 case OMPC_untied:
609 case OMPC_mergeable:
610 case OMPC_flush:
611 case OMPC_depobj:
612 case OMPC_read:
613 case OMPC_write:
614 case OMPC_capture:
615 case OMPC_compare:
616 case OMPC_seq_cst:
617 case OMPC_acq_rel:
618 case OMPC_acquire:
619 case OMPC_release:
620 case OMPC_relaxed:
621 case OMPC_threads:
622 case OMPC_simd:
623 case OMPC_num_teams:
624 case OMPC_thread_limit:
625 case OMPC_priority:
626 case OMPC_nogroup:
627 case OMPC_hint:
628 case OMPC_uniform:
629 case OMPC_use_device_ptr:
630 case OMPC_use_device_addr:
631 case OMPC_is_device_ptr:
632 case OMPC_has_device_addr:
633 case OMPC_unified_address:
634 case OMPC_unified_shared_memory:
635 case OMPC_reverse_offload:
636 case OMPC_dynamic_allocators:
637 case OMPC_self_maps:
638 case OMPC_match:
639 case OMPC_nontemporal:
640 case OMPC_destroy:
641 case OMPC_detach:
642 case OMPC_novariants:
643 case OMPC_nocontext:
644 case OMPC_inclusive:
645 case OMPC_exclusive:
646 case OMPC_uses_allocators:
647 case OMPC_affinity:
648 case OMPC_when:
649 case OMPC_append_args:
650 case OMPC_looprange:
651 break;
652 default:
653 break;
654 }
655 llvm_unreachable("Invalid OpenMP simple clause kind");
656}
657
659 return getDirectiveAssociation(DKind) == Association::Loop;
660}
661
663 return DKind == OMPD_for || DKind == OMPD_for_simd ||
664 DKind == OMPD_sections || DKind == OMPD_section ||
665 DKind == OMPD_single || DKind == OMPD_parallel_for ||
666 DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
667 DKind == OMPD_target_parallel_for ||
668 DKind == OMPD_distribute_parallel_for ||
669 DKind == OMPD_distribute_parallel_for_simd ||
670 DKind == OMPD_target_parallel_for_simd ||
671 DKind == OMPD_teams_distribute_parallel_for_simd ||
672 DKind == OMPD_teams_distribute_parallel_for ||
673 DKind == OMPD_target_teams_distribute_parallel_for ||
674 DKind == OMPD_target_teams_distribute_parallel_for_simd ||
675 DKind == OMPD_parallel_loop || DKind == OMPD_teams_loop ||
676 DKind == OMPD_target_parallel_loop || DKind == OMPD_target_teams_loop;
677}
678
680 return DKind == OMPD_taskloop ||
681 llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
682}
683
685 if (DKind == OMPD_teams_loop)
686 return true;
687 return DKind == OMPD_parallel ||
688 llvm::is_contained(getLeafConstructs(DKind), OMPD_parallel);
689}
690
692 return DKind == OMPD_target ||
693 llvm::is_contained(getLeafConstructs(DKind), OMPD_target);
694}
695
697 return DKind == OMPD_target_data || DKind == OMPD_target_enter_data ||
698 DKind == OMPD_target_exit_data || DKind == OMPD_target_update;
699}
700
702 return DKind == OMPD_target_data || DKind == OMPD_target_enter_data ||
704}
705
707 if (DKind == OMPD_teams)
708 return true;
709 ArrayRef<Directive> Leaves = getLeafConstructs(DKind);
710 return !Leaves.empty() && Leaves.front() == OMPD_teams;
711}
712
714 return DKind == OMPD_teams ||
715 llvm::is_contained(getLeafConstructs(DKind), OMPD_teams);
716}
717
719 // Avoid OMPD_declare_simd
720 if (getDirectiveAssociation(DKind) != Association::Loop)
721 return false;
722 // Formally, OMPD_end_do_simd also has a loop association, but
723 // it's a Fortran-specific directive.
724
725 return DKind == OMPD_simd ||
726 llvm::is_contained(getLeafConstructs(DKind), OMPD_simd);
727}
728
730 if (Kind == OMPD_distribute)
731 return true;
732 ArrayRef<Directive> Leaves = getLeafConstructs(Kind);
733 return !Leaves.empty() && Leaves.front() == OMPD_distribute;
734}
735
737 return Kind == OMPD_distribute ||
738 llvm::is_contained(getLeafConstructs(Kind), OMPD_distribute);
739}
740
742 if (Kind == OMPD_loop)
743 return true;
744 ArrayRef<Directive> Leaves = getLeafConstructs(Kind);
745 return !Leaves.empty() && Leaves.back() == OMPD_loop;
746}
747
749 return Kind == OMPC_private || Kind == OMPC_firstprivate ||
750 Kind == OMPC_lastprivate || Kind == OMPC_linear ||
751 Kind == OMPC_reduction || Kind == OMPC_task_reduction ||
752 Kind == OMPC_in_reduction; // TODO add next clauses like 'reduction'.
753}
754
756 return Kind == OMPC_threadprivate || Kind == OMPC_copyin;
757}
758
760 return Kind == OMPD_task || isOpenMPTaskLoopDirective(Kind);
761}
762
764 return Kind == OMPD_distribute_parallel_for ||
765 Kind == OMPD_distribute_parallel_for_simd ||
766 Kind == OMPD_teams_distribute_parallel_for_simd ||
767 Kind == OMPD_teams_distribute_parallel_for ||
768 Kind == OMPD_target_teams_distribute_parallel_for ||
769 Kind == OMPD_target_teams_distribute_parallel_for_simd ||
770 Kind == OMPD_teams_loop || Kind == OMPD_target_teams_loop;
771}
772
774 OpenMPDirectiveKind DKind) {
775 return DKind == OMPD_tile || DKind == OMPD_unroll || DKind == OMPD_reverse ||
776 DKind == OMPD_interchange || DKind == OMPD_stripe;
777}
778
780 OpenMPDirectiveKind DKind) {
781 return DKind == OMPD_fuse;
782}
783
788
790 return DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
791 DKind == OMPD_parallel_master ||
792 DKind == OMPD_parallel_master_taskloop ||
793 DKind == OMPD_parallel_master_taskloop_simd ||
794 DKind == OMPD_parallel_sections;
795}
796
798 return DKind == OMPD_target || DKind == OMPD_target_parallel ||
799 DKind == OMPD_target_parallel_for ||
800 DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
801 DKind == OMPD_target_parallel_loop;
802}
803
805 if (DKind == OMPD_error)
806 return true;
807 Category Cat = getDirectiveCategory(DKind);
808 return Cat == Category::Executable || Cat == Category::Subsidiary;
809}
810
812 if (DKind == OMPD_error)
813 return true;
814 Category Cat = getDirectiveCategory(DKind);
815 return Cat == Category::Informational;
816}
817
819 if (isOpenMPExecutableDirective(DKind)) {
820 switch (DKind) {
821 case OMPD_atomic:
822 case OMPD_barrier:
823 case OMPD_cancel:
824 case OMPD_cancellation_point:
825 case OMPD_critical:
826 case OMPD_depobj:
827 case OMPD_error:
828 case OMPD_flush:
829 case OMPD_masked:
830 case OMPD_master:
831 case OMPD_section:
832 case OMPD_taskwait:
833 case OMPD_taskyield:
834 case OMPD_assume:
835 return false;
836 default:
838 }
839 }
840 // Non-executable directives.
841 switch (DKind) {
842 case OMPD_metadirective:
843 case OMPD_nothing:
844 return true;
845 default:
846 break;
847 }
848 return false;
849}
850
852 OpenMPDirectiveKind DKind, const LangOptions &LangOpts) {
853 // Directives strictly nestable in a construct with order(concurrent) are:
854 // OpenMP 5.x: loop, parallel, simd, combined directive starting with parallel
855 // OpenMP 6.0: above plus atomic and all loop-transformation directives
856
857 if (DKind == OMPD_loop || DKind == OMPD_parallel || DKind == OMPD_simd ||
859 return true;
860
861 if (LangOpts.OpenMP >= 60)
862 return DKind == OMPD_atomic ||
864
865 return false;
866}
867
870 OpenMPDirectiveKind DKind) {
871 assert(unsigned(DKind) < llvm::omp::Directive_enumSize);
872 assert(isOpenMPCapturingDirective(DKind) && "Expecting capturing directive");
873
874 auto GetRegionsForLeaf = [&](OpenMPDirectiveKind LKind) {
875 assert(isLeafConstruct(LKind) && "Epecting leaf directive");
876 // Whether a leaf would require OMPD_unknown if it occured on its own.
877 switch (LKind) {
878 case OMPD_metadirective:
879 CaptureRegions.push_back(OMPD_metadirective);
880 break;
881 case OMPD_nothing:
882 CaptureRegions.push_back(OMPD_nothing);
883 break;
884 case OMPD_parallel:
885 CaptureRegions.push_back(OMPD_parallel);
886 break;
887 case OMPD_target:
888 CaptureRegions.push_back(OMPD_task);
889 CaptureRegions.push_back(OMPD_target);
890 break;
891 case OMPD_task:
892 case OMPD_target_enter_data:
893 case OMPD_target_exit_data:
894 case OMPD_target_update:
895 CaptureRegions.push_back(OMPD_task);
896 break;
897 case OMPD_teams:
898 CaptureRegions.push_back(OMPD_teams);
899 break;
900 case OMPD_taskloop:
901 CaptureRegions.push_back(OMPD_taskloop);
902 break;
903 case OMPD_loop:
904 // TODO: 'loop' may require different capture regions depending on the
905 // bind clause or the parent directive when there is no bind clause.
906 // If any of the directives that push regions here are parents of 'loop',
907 // assume 'parallel'. Otherwise do nothing.
908 if (!CaptureRegions.empty() &&
909 !llvm::is_contained(CaptureRegions, OMPD_parallel))
910 CaptureRegions.push_back(OMPD_parallel);
911 else
912 return true;
913 break;
914 case OMPD_dispatch:
915 case OMPD_distribute:
916 case OMPD_for:
917 case OMPD_ordered:
918 case OMPD_scope:
919 case OMPD_sections:
920 case OMPD_simd:
921 case OMPD_single:
922 case OMPD_target_data:
923 case OMPD_taskgroup:
924 case OMPD_stripe:
925 // These directives (when standalone) use OMPD_unknown as the region,
926 // but when they're constituents of a compound directive, and other
927 // leafs from that directive have specific regions, then these directives
928 // add no additional regions.
929 return true;
930 case OMPD_masked:
931 case OMPD_master:
932 return false;
933 default:
934 llvm::errs() << getOpenMPDirectiveName(LKind, llvm::omp::FallbackVersion)
935 << '\n';
936 llvm_unreachable("Unexpected directive");
937 }
938 return false;
939 };
940
941 bool MayNeedUnknownRegion = false;
942 for (OpenMPDirectiveKind L : getLeafConstructsOrSelf(DKind))
943 MayNeedUnknownRegion |= GetRegionsForLeaf(L);
944
945 // We need OMPD_unknown when no regions were added, and specific leaf
946 // constructs were present. Push a single OMPD_unknown as the capture
947 /// region.
948 if (CaptureRegions.empty() && MayNeedUnknownRegion)
949 CaptureRegions.push_back(OMPD_unknown);
950
951 // OMPD_unknown is only expected as the only region. If other regions
952 // are present OMPD_unknown should not be present.
953 assert((CaptureRegions[0] == OMPD_unknown ||
954 !llvm::is_contained(CaptureRegions, OMPD_unknown)) &&
955 "Misplaced OMPD_unknown");
956}
957
959 return FailClauseParameter == llvm::omp::OMPC_acquire ||
960 FailClauseParameter == llvm::omp::OMPC_relaxed ||
961 FailClauseParameter == llvm::omp::OMPC_seq_cst;
962}
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.
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.
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
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