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