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
13#include "clang/Basic/OpenMPKinds.h"
14#include "clang/Basic/IdentifierTable.h"
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
23unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, StringRef Str,
24 const LangOptions &LangOpts) {
25 switch (Kind) {
26 case OMPC_default:
27 return llvm::StringSwitch<unsigned>(Str)
28#define OMP_DEFAULT_KIND(Enum, Name) .Case(Name, unsigned(Enum))
29#include "llvm/Frontend/OpenMP/OMPKinds.def"
30 .Default(Value: unsigned(llvm::omp::OMP_DEFAULT_unknown));
31 case OMPC_proc_bind:
32 return llvm::StringSwitch<unsigned>(Str)
33#define OMP_PROC_BIND_KIND(Enum, Name, Value) .Case(Name, Value)
34#include "llvm/Frontend/OpenMP/OMPKinds.def"
35 .Default(Value: unsigned(llvm::omp::OMP_PROC_BIND_unknown));
36 case OMPC_schedule:
37 return llvm::StringSwitch<unsigned>(Str)
38#define OPENMP_SCHEDULE_KIND(Name) \
39 .Case(#Name, static_cast<unsigned>(OMPC_SCHEDULE_##Name))
40#define OPENMP_SCHEDULE_MODIFIER(Name) \
41 .Case(#Name, static_cast<unsigned>(OMPC_SCHEDULE_MODIFIER_##Name))
42#include "clang/Basic/OpenMPKinds.def"
43 .Default(Value: OMPC_SCHEDULE_unknown);
44 case OMPC_depend: {
45 unsigned Type = llvm::StringSwitch<unsigned>(Str)
46#define OPENMP_DEPEND_KIND(Name) .Case(#Name, OMPC_DEPEND_##Name)
47#include "clang/Basic/OpenMPKinds.def"
48 .Default(Value: OMPC_DEPEND_unknown);
49 if (LangOpts.OpenMP < 51 && Type == OMPC_DEPEND_inoutset)
50 return OMPC_DEPEND_unknown;
51 return Type;
52 }
53 case OMPC_doacross:
54 return llvm::StringSwitch<OpenMPDoacrossClauseModifier>(Str)
55#define OPENMP_DOACROSS_MODIFIER(Name) .Case(#Name, OMPC_DOACROSS_##Name)
56#include "clang/Basic/OpenMPKinds.def"
57 .Default(Value: OMPC_DOACROSS_unknown);
58 case OMPC_linear:
59 return llvm::StringSwitch<OpenMPLinearClauseKind>(Str)
60#define OPENMP_LINEAR_KIND(Name) .Case(#Name, OMPC_LINEAR_##Name)
61#include "clang/Basic/OpenMPKinds.def"
62 .Default(Value: OMPC_LINEAR_unknown);
63 case OMPC_map: {
64 unsigned Type = llvm::StringSwitch<unsigned>(Str)
65#define OPENMP_MAP_KIND(Name) \
66 .Case(#Name, static_cast<unsigned>(OMPC_MAP_##Name))
67#define OPENMP_MAP_MODIFIER_KIND(Name) \
68 .Case(#Name, static_cast<unsigned>(OMPC_MAP_MODIFIER_##Name))
69#include "clang/Basic/OpenMPKinds.def"
70 .Default(Value: OMPC_MAP_unknown);
71 if (LangOpts.OpenMP < 51 && Type == OMPC_MAP_MODIFIER_present)
72 return OMPC_MAP_MODIFIER_unknown;
73 if (!LangOpts.OpenMPExtensions && Type == OMPC_MAP_MODIFIER_ompx_hold)
74 return OMPC_MAP_MODIFIER_unknown;
75 return Type;
76 }
77 case OMPC_to:
78 case OMPC_from: {
79 unsigned Type = llvm::StringSwitch<unsigned>(Str)
80#define OPENMP_MOTION_MODIFIER_KIND(Name) \
81 .Case(#Name, static_cast<unsigned>(OMPC_MOTION_MODIFIER_##Name))
82#include "clang/Basic/OpenMPKinds.def"
83 .Default(Value: OMPC_MOTION_MODIFIER_unknown);
84 if (LangOpts.OpenMP < 51 && Type == OMPC_MOTION_MODIFIER_present)
85 return OMPC_MOTION_MODIFIER_unknown;
86 return Type;
87 }
88 case OMPC_dist_schedule:
89 return llvm::StringSwitch<OpenMPDistScheduleClauseKind>(Str)
90#define OPENMP_DIST_SCHEDULE_KIND(Name) .Case(#Name, OMPC_DIST_SCHEDULE_##Name)
91#include "clang/Basic/OpenMPKinds.def"
92 .Default(Value: OMPC_DIST_SCHEDULE_unknown);
93 case OMPC_defaultmap:
94 return llvm::StringSwitch<unsigned>(Str)
95#define OPENMP_DEFAULTMAP_KIND(Name) \
96 .Case(#Name, static_cast<unsigned>(OMPC_DEFAULTMAP_##Name))
97#define OPENMP_DEFAULTMAP_MODIFIER(Name) \
98 .Case(#Name, static_cast<unsigned>(OMPC_DEFAULTMAP_MODIFIER_##Name))
99#include "clang/Basic/OpenMPKinds.def"
100 .Default(Value: OMPC_DEFAULTMAP_unknown);
101 case OMPC_atomic_default_mem_order:
102 return llvm::StringSwitch<OpenMPAtomicDefaultMemOrderClauseKind>(Str)
103#define OPENMP_ATOMIC_DEFAULT_MEM_ORDER_KIND(Name) \
104 .Case(#Name, OMPC_ATOMIC_DEFAULT_MEM_ORDER_##Name)
105#include "clang/Basic/OpenMPKinds.def"
106 .Default(Value: OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown);
107 case OMPC_fail:
108 return static_cast<unsigned int>(llvm::StringSwitch<llvm::omp::Clause>(Str)
109#define OPENMP_ATOMIC_FAIL_MODIFIER(Name) .Case(#Name, OMPC_##Name)
110#include "clang/Basic/OpenMPKinds.def"
111 .Default(Value: OMPC_unknown));
112 case OMPC_device_type:
113 return llvm::StringSwitch<OpenMPDeviceType>(Str)
114#define OPENMP_DEVICE_TYPE_KIND(Name) .Case(#Name, OMPC_DEVICE_TYPE_##Name)
115#include "clang/Basic/OpenMPKinds.def"
116 .Default(Value: OMPC_DEVICE_TYPE_unknown);
117 case OMPC_at:
118 return llvm::StringSwitch<OpenMPAtClauseKind>(Str)
119#define OPENMP_AT_KIND(Name) .Case(#Name, OMPC_AT_##Name)
120#include "clang/Basic/OpenMPKinds.def"
121 .Default(Value: OMPC_AT_unknown);
122 case OMPC_severity:
123 return llvm::StringSwitch<OpenMPSeverityClauseKind>(Str)
124#define OPENMP_SEVERITY_KIND(Name) .Case(#Name, OMPC_SEVERITY_##Name)
125#include "clang/Basic/OpenMPKinds.def"
126 .Default(Value: OMPC_SEVERITY_unknown);
127 case OMPC_lastprivate:
128 return llvm::StringSwitch<OpenMPLastprivateModifier>(Str)
129#define OPENMP_LASTPRIVATE_KIND(Name) .Case(#Name, OMPC_LASTPRIVATE_##Name)
130#include "clang/Basic/OpenMPKinds.def"
131 .Default(Value: OMPC_LASTPRIVATE_unknown);
132 case OMPC_order:
133 return llvm::StringSwitch<unsigned>(Str)
134#define OPENMP_ORDER_KIND(Name) \
135 .Case(#Name, static_cast<unsigned>(OMPC_ORDER_##Name))
136#define OPENMP_ORDER_MODIFIER(Name) \
137 .Case(#Name, static_cast<unsigned>(OMPC_ORDER_MODIFIER_##Name))
138#include "clang/Basic/OpenMPKinds.def"
139 .Default(Value: OMPC_ORDER_unknown);
140 case OMPC_update:
141 return llvm::StringSwitch<OpenMPDependClauseKind>(Str)
142#define OPENMP_DEPEND_KIND(Name) .Case(#Name, OMPC_DEPEND_##Name)
143#include "clang/Basic/OpenMPKinds.def"
144 .Default(Value: OMPC_DEPEND_unknown);
145 case OMPC_device:
146 return llvm::StringSwitch<OpenMPDeviceClauseModifier>(Str)
147#define OPENMP_DEVICE_MODIFIER(Name) .Case(#Name, OMPC_DEVICE_##Name)
148#include "clang/Basic/OpenMPKinds.def"
149 .Default(Value: OMPC_DEVICE_unknown);
150 case OMPC_reduction:
151 return llvm::StringSwitch<OpenMPReductionClauseModifier>(Str)
152#define OPENMP_REDUCTION_MODIFIER(Name) .Case(#Name, OMPC_REDUCTION_##Name)
153#include "clang/Basic/OpenMPKinds.def"
154 .Default(Value: OMPC_REDUCTION_unknown);
155 case OMPC_adjust_args:
156 return llvm::StringSwitch<OpenMPAdjustArgsOpKind>(Str)
157#define OPENMP_ADJUST_ARGS_KIND(Name) .Case(#Name, OMPC_ADJUST_ARGS_##Name)
158#include "clang/Basic/OpenMPKinds.def"
159 .Default(Value: OMPC_ADJUST_ARGS_unknown);
160 case OMPC_bind:
161 return llvm::StringSwitch<unsigned>(Str)
162#define OPENMP_BIND_KIND(Name) .Case(#Name, OMPC_BIND_##Name)
163#include "clang/Basic/OpenMPKinds.def"
164 .Default(Value: OMPC_BIND_unknown);
165 case OMPC_grainsize: {
166 unsigned Type = llvm::StringSwitch<unsigned>(Str)
167#define OPENMP_GRAINSIZE_MODIFIER(Name) .Case(#Name, OMPC_GRAINSIZE_##Name)
168#include "clang/Basic/OpenMPKinds.def"
169 .Default(Value: OMPC_GRAINSIZE_unknown);
170 if (LangOpts.OpenMP < 51)
171 return OMPC_GRAINSIZE_unknown;
172 return Type;
173 }
174 case OMPC_num_tasks: {
175 unsigned Type = llvm::StringSwitch<unsigned>(Str)
176#define OPENMP_NUMTASKS_MODIFIER(Name) .Case(#Name, OMPC_NUMTASKS_##Name)
177#include "clang/Basic/OpenMPKinds.def"
178 .Default(Value: OMPC_NUMTASKS_unknown);
179 if (LangOpts.OpenMP < 51)
180 return OMPC_NUMTASKS_unknown;
181 return Type;
182 }
183 case OMPC_unknown:
184 case OMPC_threadprivate:
185 case OMPC_if:
186 case OMPC_final:
187 case OMPC_num_threads:
188 case OMPC_safelen:
189 case OMPC_simdlen:
190 case OMPC_sizes:
191 case OMPC_allocator:
192 case OMPC_allocate:
193 case OMPC_collapse:
194 case OMPC_private:
195 case OMPC_firstprivate:
196 case OMPC_shared:
197 case OMPC_task_reduction:
198 case OMPC_in_reduction:
199 case OMPC_aligned:
200 case OMPC_copyin:
201 case OMPC_copyprivate:
202 case OMPC_ordered:
203 case OMPC_nowait:
204 case OMPC_untied:
205 case OMPC_mergeable:
206 case OMPC_flush:
207 case OMPC_depobj:
208 case OMPC_read:
209 case OMPC_write:
210 case OMPC_capture:
211 case OMPC_compare:
212 case OMPC_seq_cst:
213 case OMPC_acq_rel:
214 case OMPC_acquire:
215 case OMPC_release:
216 case OMPC_relaxed:
217 case OMPC_threads:
218 case OMPC_simd:
219 case OMPC_num_teams:
220 case OMPC_thread_limit:
221 case OMPC_priority:
222 case OMPC_nogroup:
223 case OMPC_hint:
224 case OMPC_uniform:
225 case OMPC_use_device_ptr:
226 case OMPC_use_device_addr:
227 case OMPC_is_device_ptr:
228 case OMPC_has_device_addr:
229 case OMPC_unified_address:
230 case OMPC_unified_shared_memory:
231 case OMPC_reverse_offload:
232 case OMPC_dynamic_allocators:
233 case OMPC_match:
234 case OMPC_nontemporal:
235 case OMPC_destroy:
236 case OMPC_novariants:
237 case OMPC_nocontext:
238 case OMPC_detach:
239 case OMPC_inclusive:
240 case OMPC_exclusive:
241 case OMPC_uses_allocators:
242 case OMPC_affinity:
243 case OMPC_when:
244 case OMPC_append_args:
245 break;
246 default:
247 break;
248 }
249 llvm_unreachable("Invalid OpenMP simple clause kind");
250}
251
252const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
253 unsigned Type) {
254 switch (Kind) {
255 case OMPC_default:
256 switch (llvm::omp::DefaultKind(Type)) {
257#define OMP_DEFAULT_KIND(Enum, Name) \
258 case Enum: \
259 return Name;
260#include "llvm/Frontend/OpenMP/OMPKinds.def"
261 }
262 llvm_unreachable("Invalid OpenMP 'default' clause type");
263 case OMPC_proc_bind:
264 switch (Type) {
265#define OMP_PROC_BIND_KIND(Enum, Name, Value) \
266 case Value: \
267 return Name;
268#include "llvm/Frontend/OpenMP/OMPKinds.def"
269 }
270 llvm_unreachable("Invalid OpenMP 'proc_bind' clause type");
271 case OMPC_schedule:
272 switch (Type) {
273 case OMPC_SCHEDULE_unknown:
274 case OMPC_SCHEDULE_MODIFIER_last:
275 return "unknown";
276#define OPENMP_SCHEDULE_KIND(Name) \
277 case OMPC_SCHEDULE_##Name: \
278 return #Name;
279#define OPENMP_SCHEDULE_MODIFIER(Name) \
280 case OMPC_SCHEDULE_MODIFIER_##Name: \
281 return #Name;
282#include "clang/Basic/OpenMPKinds.def"
283 }
284 llvm_unreachable("Invalid OpenMP 'schedule' clause type");
285 case OMPC_depend:
286 switch (Type) {
287 case OMPC_DEPEND_unknown:
288 return "unknown";
289#define OPENMP_DEPEND_KIND(Name) \
290 case OMPC_DEPEND_##Name: \
291 return #Name;
292#include "clang/Basic/OpenMPKinds.def"
293 }
294 llvm_unreachable("Invalid OpenMP 'depend' clause type");
295 case OMPC_doacross:
296 switch (Type) {
297 case OMPC_DOACROSS_unknown:
298 return "unknown";
299#define OPENMP_DOACROSS_MODIFIER(Name) \
300 case OMPC_DOACROSS_##Name: \
301 return #Name;
302#include "clang/Basic/OpenMPKinds.def"
303 }
304 llvm_unreachable("Invalid OpenMP 'doacross' clause type");
305 case OMPC_linear:
306 switch (Type) {
307 case OMPC_LINEAR_unknown:
308 return "unknown";
309#define OPENMP_LINEAR_KIND(Name) \
310 case OMPC_LINEAR_##Name: \
311 return #Name;
312#include "clang/Basic/OpenMPKinds.def"
313 }
314 llvm_unreachable("Invalid OpenMP 'linear' clause type");
315 case OMPC_map:
316 switch (Type) {
317 case OMPC_MAP_unknown:
318 case OMPC_MAP_MODIFIER_last:
319 return "unknown";
320#define OPENMP_MAP_KIND(Name) \
321 case OMPC_MAP_##Name: \
322 return #Name;
323#define OPENMP_MAP_MODIFIER_KIND(Name) \
324 case OMPC_MAP_MODIFIER_##Name: \
325 return #Name;
326#include "clang/Basic/OpenMPKinds.def"
327 default:
328 break;
329 }
330 llvm_unreachable("Invalid OpenMP 'map' clause type");
331 case OMPC_to:
332 case OMPC_from:
333 switch (Type) {
334 case OMPC_MOTION_MODIFIER_unknown:
335 return "unknown";
336#define OPENMP_MOTION_MODIFIER_KIND(Name) \
337 case OMPC_MOTION_MODIFIER_##Name: \
338 return #Name;
339#include "clang/Basic/OpenMPKinds.def"
340 default:
341 break;
342 }
343 llvm_unreachable("Invalid OpenMP 'to' or 'from' clause type");
344 case OMPC_dist_schedule:
345 switch (Type) {
346 case OMPC_DIST_SCHEDULE_unknown:
347 return "unknown";
348#define OPENMP_DIST_SCHEDULE_KIND(Name) \
349 case OMPC_DIST_SCHEDULE_##Name: \
350 return #Name;
351#include "clang/Basic/OpenMPKinds.def"
352 }
353 llvm_unreachable("Invalid OpenMP 'dist_schedule' clause type");
354 case OMPC_defaultmap:
355 switch (Type) {
356 case OMPC_DEFAULTMAP_unknown:
357 case OMPC_DEFAULTMAP_MODIFIER_last:
358 return "unknown";
359#define OPENMP_DEFAULTMAP_KIND(Name) \
360 case OMPC_DEFAULTMAP_##Name: \
361 return #Name;
362#define OPENMP_DEFAULTMAP_MODIFIER(Name) \
363 case OMPC_DEFAULTMAP_MODIFIER_##Name: \
364 return #Name;
365#include "clang/Basic/OpenMPKinds.def"
366 }
367 llvm_unreachable("Invalid OpenMP 'schedule' clause type");
368 case OMPC_atomic_default_mem_order:
369 switch (Type) {
370 case OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown:
371 return "unknown";
372#define OPENMP_ATOMIC_DEFAULT_MEM_ORDER_KIND(Name) \
373 case OMPC_ATOMIC_DEFAULT_MEM_ORDER_##Name: \
374 return #Name;
375#include "clang/Basic/OpenMPKinds.def"
376}
377 llvm_unreachable("Invalid OpenMP 'atomic_default_mem_order' clause type");
378 case OMPC_device_type:
379 switch (Type) {
380 case OMPC_DEVICE_TYPE_unknown:
381 return "unknown";
382#define OPENMP_DEVICE_TYPE_KIND(Name) \
383 case OMPC_DEVICE_TYPE_##Name: \
384 return #Name;
385#include "clang/Basic/OpenMPKinds.def"
386 }
387 llvm_unreachable("Invalid OpenMP 'device_type' clause type");
388 case OMPC_at:
389 switch (Type) {
390 case OMPC_AT_unknown:
391 return "unknown";
392#define OPENMP_AT_KIND(Name) \
393 case OMPC_AT_##Name: \
394 return #Name;
395#include "clang/Basic/OpenMPKinds.def"
396 }
397 llvm_unreachable("Invalid OpenMP 'at' clause type");
398 case OMPC_severity:
399 switch (Type) {
400 case OMPC_SEVERITY_unknown:
401 return "unknown";
402#define OPENMP_SEVERITY_KIND(Name) \
403 case OMPC_SEVERITY_##Name: \
404 return #Name;
405#include "clang/Basic/OpenMPKinds.def"
406 }
407 llvm_unreachable("Invalid OpenMP 'severity' clause type");
408 case OMPC_lastprivate:
409 switch (Type) {
410 case OMPC_LASTPRIVATE_unknown:
411 return "unknown";
412#define OPENMP_LASTPRIVATE_KIND(Name) \
413 case OMPC_LASTPRIVATE_##Name: \
414 return #Name;
415#include "clang/Basic/OpenMPKinds.def"
416 }
417 llvm_unreachable("Invalid OpenMP 'lastprivate' clause type");
418 case OMPC_order:
419 switch (Type) {
420 case OMPC_ORDER_unknown:
421 case OMPC_ORDER_MODIFIER_last:
422 return "unknown";
423#define OPENMP_ORDER_KIND(Name) \
424 case OMPC_ORDER_##Name: \
425 return #Name;
426#define OPENMP_ORDER_MODIFIER(Name) \
427 case OMPC_ORDER_MODIFIER_##Name: \
428 return #Name;
429#include "clang/Basic/OpenMPKinds.def"
430 }
431 llvm_unreachable("Invalid OpenMP 'order' clause type");
432 case OMPC_update:
433 switch (Type) {
434 case OMPC_DEPEND_unknown:
435 return "unknown";
436#define OPENMP_DEPEND_KIND(Name) \
437 case OMPC_DEPEND_##Name: \
438 return #Name;
439#include "clang/Basic/OpenMPKinds.def"
440 }
441 llvm_unreachable("Invalid OpenMP 'depend' clause type");
442 case OMPC_fail: {
443 OpenMPClauseKind CK = static_cast<OpenMPClauseKind>(Type);
444 return getOpenMPClauseName(C: CK).data();
445 llvm_unreachable("Invalid OpenMP 'fail' clause modifier");
446 }
447 case OMPC_device:
448 switch (Type) {
449 case OMPC_DEVICE_unknown:
450 return "unknown";
451#define OPENMP_DEVICE_MODIFIER(Name) \
452 case OMPC_DEVICE_##Name: \
453 return #Name;
454#include "clang/Basic/OpenMPKinds.def"
455 }
456 llvm_unreachable("Invalid OpenMP 'device' clause modifier");
457 case OMPC_reduction:
458 switch (Type) {
459 case OMPC_REDUCTION_unknown:
460 return "unknown";
461#define OPENMP_REDUCTION_MODIFIER(Name) \
462 case OMPC_REDUCTION_##Name: \
463 return #Name;
464#include "clang/Basic/OpenMPKinds.def"
465 }
466 llvm_unreachable("Invalid OpenMP 'reduction' clause modifier");
467 case OMPC_adjust_args:
468 switch (Type) {
469 case OMPC_ADJUST_ARGS_unknown:
470 return "unknown";
471#define OPENMP_ADJUST_ARGS_KIND(Name) \
472 case OMPC_ADJUST_ARGS_##Name: \
473 return #Name;
474#include "clang/Basic/OpenMPKinds.def"
475 }
476 llvm_unreachable("Invalid OpenMP 'adjust_args' clause kind");
477 case OMPC_bind:
478 switch (Type) {
479 case OMPC_BIND_unknown:
480 return "unknown";
481#define OPENMP_BIND_KIND(Name) \
482 case OMPC_BIND_##Name: \
483 return #Name;
484#include "clang/Basic/OpenMPKinds.def"
485 }
486 llvm_unreachable("Invalid OpenMP 'bind' clause type");
487 case OMPC_grainsize:
488 switch (Type) {
489 case OMPC_GRAINSIZE_unknown:
490 return "unknown";
491#define OPENMP_GRAINSIZE_MODIFIER(Name) \
492 case OMPC_GRAINSIZE_##Name: \
493 return #Name;
494#include "clang/Basic/OpenMPKinds.def"
495 }
496 llvm_unreachable("Invalid OpenMP 'grainsize' clause modifier");
497 case OMPC_num_tasks:
498 switch (Type) {
499 case OMPC_NUMTASKS_unknown:
500 return "unknown";
501#define OPENMP_NUMTASKS_MODIFIER(Name) \
502 case OMPC_NUMTASKS_##Name: \
503 return #Name;
504#include "clang/Basic/OpenMPKinds.def"
505 }
506 llvm_unreachable("Invalid OpenMP 'num_tasks' clause modifier");
507 case OMPC_unknown:
508 case OMPC_threadprivate:
509 case OMPC_if:
510 case OMPC_final:
511 case OMPC_num_threads:
512 case OMPC_safelen:
513 case OMPC_simdlen:
514 case OMPC_sizes:
515 case OMPC_allocator:
516 case OMPC_allocate:
517 case OMPC_collapse:
518 case OMPC_private:
519 case OMPC_firstprivate:
520 case OMPC_shared:
521 case OMPC_task_reduction:
522 case OMPC_in_reduction:
523 case OMPC_aligned:
524 case OMPC_copyin:
525 case OMPC_copyprivate:
526 case OMPC_ordered:
527 case OMPC_nowait:
528 case OMPC_untied:
529 case OMPC_mergeable:
530 case OMPC_flush:
531 case OMPC_depobj:
532 case OMPC_read:
533 case OMPC_write:
534 case OMPC_capture:
535 case OMPC_compare:
536 case OMPC_seq_cst:
537 case OMPC_acq_rel:
538 case OMPC_acquire:
539 case OMPC_release:
540 case OMPC_relaxed:
541 case OMPC_threads:
542 case OMPC_simd:
543 case OMPC_num_teams:
544 case OMPC_thread_limit:
545 case OMPC_priority:
546 case OMPC_nogroup:
547 case OMPC_hint:
548 case OMPC_uniform:
549 case OMPC_use_device_ptr:
550 case OMPC_use_device_addr:
551 case OMPC_is_device_ptr:
552 case OMPC_has_device_addr:
553 case OMPC_unified_address:
554 case OMPC_unified_shared_memory:
555 case OMPC_reverse_offload:
556 case OMPC_dynamic_allocators:
557 case OMPC_match:
558 case OMPC_nontemporal:
559 case OMPC_destroy:
560 case OMPC_detach:
561 case OMPC_novariants:
562 case OMPC_nocontext:
563 case OMPC_inclusive:
564 case OMPC_exclusive:
565 case OMPC_uses_allocators:
566 case OMPC_affinity:
567 case OMPC_when:
568 case OMPC_append_args:
569 break;
570 default:
571 break;
572 }
573 llvm_unreachable("Invalid OpenMP simple clause kind");
574}
575
576bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
577 return getDirectiveAssociation(D: DKind) == Association::Loop;
578}
579
580bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
581 return DKind == OMPD_for || DKind == OMPD_for_simd ||
582 DKind == OMPD_sections || DKind == OMPD_section ||
583 DKind == OMPD_single || DKind == OMPD_parallel_for ||
584 DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
585 DKind == OMPD_target_parallel_for ||
586 DKind == OMPD_distribute_parallel_for ||
587 DKind == OMPD_distribute_parallel_for_simd ||
588 DKind == OMPD_target_parallel_for_simd ||
589 DKind == OMPD_teams_distribute_parallel_for_simd ||
590 DKind == OMPD_teams_distribute_parallel_for ||
591 DKind == OMPD_target_teams_distribute_parallel_for ||
592 DKind == OMPD_target_teams_distribute_parallel_for_simd ||
593 DKind == OMPD_parallel_loop || DKind == OMPD_teams_loop ||
594 DKind == OMPD_target_parallel_loop || DKind == OMPD_target_teams_loop;
595}
596
597bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
598 return DKind == OMPD_taskloop ||
599 llvm::is_contained(Range: getLeafConstructs(D: DKind), Element: OMPD_taskloop);
600}
601
602bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
603 if (DKind == OMPD_teams_loop)
604 return true;
605 return DKind == OMPD_parallel ||
606 llvm::is_contained(Range: getLeafConstructs(D: DKind), Element: OMPD_parallel);
607}
608
609bool clang::isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind) {
610 return DKind == OMPD_target ||
611 llvm::is_contained(Range: getLeafConstructs(D: DKind), Element: OMPD_target);
612}
613
614bool clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
615 return DKind == OMPD_target_data || DKind == OMPD_target_enter_data ||
616 DKind == OMPD_target_exit_data || DKind == OMPD_target_update;
617}
618
619bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
620 if (DKind == OMPD_teams)
621 return true;
622 ArrayRef<Directive> Leaves = getLeafConstructs(D: DKind);
623 return !Leaves.empty() && Leaves.front() == OMPD_teams;
624}
625
626bool clang::isOpenMPTeamsDirective(OpenMPDirectiveKind DKind) {
627 return DKind == OMPD_teams ||
628 llvm::is_contained(Range: getLeafConstructs(D: DKind), Element: OMPD_teams);
629}
630
631bool clang::isOpenMPSimdDirective(OpenMPDirectiveKind DKind) {
632 // Avoid OMPD_declare_simd
633 if (getDirectiveAssociation(D: DKind) != Association::Loop)
634 return false;
635 // Formally, OMPD_end_do_simd also has a loop association, but
636 // it's a Fortran-specific directive.
637
638 return DKind == OMPD_simd ||
639 llvm::is_contained(Range: getLeafConstructs(D: DKind), Element: OMPD_simd);
640}
641
642bool clang::isOpenMPNestingDistributeDirective(OpenMPDirectiveKind Kind) {
643 if (Kind == OMPD_distribute)
644 return true;
645 ArrayRef<Directive> Leaves = getLeafConstructs(D: Kind);
646 return !Leaves.empty() && Leaves.front() == OMPD_distribute;
647}
648
649bool clang::isOpenMPDistributeDirective(OpenMPDirectiveKind Kind) {
650 return Kind == OMPD_distribute ||
651 llvm::is_contained(Range: getLeafConstructs(D: Kind), Element: OMPD_distribute);
652}
653
654bool clang::isOpenMPGenericLoopDirective(OpenMPDirectiveKind Kind) {
655 if (Kind == OMPD_loop)
656 return true;
657 ArrayRef<Directive> Leaves = getLeafConstructs(D: Kind);
658 return !Leaves.empty() && Leaves.back() == OMPD_loop;
659}
660
661bool clang::isOpenMPPrivate(OpenMPClauseKind Kind) {
662 return Kind == OMPC_private || Kind == OMPC_firstprivate ||
663 Kind == OMPC_lastprivate || Kind == OMPC_linear ||
664 Kind == OMPC_reduction || Kind == OMPC_task_reduction ||
665 Kind == OMPC_in_reduction; // TODO add next clauses like 'reduction'.
666}
667
668bool clang::isOpenMPThreadPrivate(OpenMPClauseKind Kind) {
669 return Kind == OMPC_threadprivate || Kind == OMPC_copyin;
670}
671
672bool clang::isOpenMPTaskingDirective(OpenMPDirectiveKind Kind) {
673 return Kind == OMPD_task || isOpenMPTaskLoopDirective(DKind: Kind);
674}
675
676bool clang::isOpenMPLoopBoundSharingDirective(OpenMPDirectiveKind Kind) {
677 return Kind == OMPD_distribute_parallel_for ||
678 Kind == OMPD_distribute_parallel_for_simd ||
679 Kind == OMPD_teams_distribute_parallel_for_simd ||
680 Kind == OMPD_teams_distribute_parallel_for ||
681 Kind == OMPD_target_teams_distribute_parallel_for ||
682 Kind == OMPD_target_teams_distribute_parallel_for_simd ||
683 Kind == OMPD_teams_loop || Kind == OMPD_target_teams_loop;
684}
685
686bool clang::isOpenMPLoopTransformationDirective(OpenMPDirectiveKind DKind) {
687 return DKind == OMPD_tile || DKind == OMPD_unroll || DKind == OMPD_reverse ||
688 DKind == OMPD_interchange;
689}
690
691bool clang::isOpenMPCombinedParallelADirective(OpenMPDirectiveKind DKind) {
692 return DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
693 DKind == OMPD_parallel_master ||
694 DKind == OMPD_parallel_master_taskloop ||
695 DKind == OMPD_parallel_master_taskloop_simd ||
696 DKind == OMPD_parallel_sections;
697}
698
699bool clang::needsTaskBasedThreadLimit(OpenMPDirectiveKind DKind) {
700 return DKind == OMPD_target || DKind == OMPD_target_parallel ||
701 DKind == OMPD_target_parallel_for ||
702 DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
703 DKind == OMPD_target_parallel_loop;
704}
705
706bool clang::isOpenMPExecutableDirective(OpenMPDirectiveKind DKind) {
707 if (DKind == OMPD_error)
708 return true;
709 Category Cat = getDirectiveCategory(D: DKind);
710 return Cat == Category::Executable || Cat == Category::Subsidiary;
711}
712
713bool clang::isOpenMPCapturingDirective(OpenMPDirectiveKind DKind) {
714 if (isOpenMPExecutableDirective(DKind)) {
715 switch (DKind) {
716 case OMPD_atomic:
717 case OMPD_barrier:
718 case OMPD_cancel:
719 case OMPD_cancellation_point:
720 case OMPD_critical:
721 case OMPD_depobj:
722 case OMPD_error:
723 case OMPD_flush:
724 case OMPD_masked:
725 case OMPD_master:
726 case OMPD_section:
727 case OMPD_taskwait:
728 case OMPD_taskyield:
729 return false;
730 default:
731 return !isOpenMPLoopTransformationDirective(DKind);
732 }
733 }
734 // Non-executable directives.
735 switch (DKind) {
736 case OMPD_metadirective:
737 case OMPD_nothing:
738 return true;
739 default:
740 break;
741 }
742 return false;
743}
744
745void clang::getOpenMPCaptureRegions(
746 SmallVectorImpl<OpenMPDirectiveKind> &CaptureRegions,
747 OpenMPDirectiveKind DKind) {
748 assert(unsigned(DKind) < llvm::omp::Directive_enumSize);
749 assert(isOpenMPCapturingDirective(DKind) && "Expecting capturing directive");
750
751 auto GetRegionsForLeaf = [&](OpenMPDirectiveKind LKind) {
752 assert(isLeafConstruct(LKind) && "Epecting leaf directive");
753 // Whether a leaf would require OMPD_unknown if it occured on its own.
754 switch (LKind) {
755 case OMPD_metadirective:
756 CaptureRegions.push_back(Elt: OMPD_metadirective);
757 break;
758 case OMPD_nothing:
759 CaptureRegions.push_back(Elt: OMPD_nothing);
760 break;
761 case OMPD_parallel:
762 CaptureRegions.push_back(Elt: OMPD_parallel);
763 break;
764 case OMPD_target:
765 CaptureRegions.push_back(Elt: OMPD_task);
766 CaptureRegions.push_back(Elt: OMPD_target);
767 break;
768 case OMPD_task:
769 case OMPD_target_enter_data:
770 case OMPD_target_exit_data:
771 case OMPD_target_update:
772 CaptureRegions.push_back(Elt: OMPD_task);
773 break;
774 case OMPD_teams:
775 CaptureRegions.push_back(Elt: OMPD_teams);
776 break;
777 case OMPD_taskloop:
778 CaptureRegions.push_back(Elt: OMPD_taskloop);
779 break;
780 case OMPD_loop:
781 // TODO: 'loop' may require different capture regions depending on the
782 // bind clause or the parent directive when there is no bind clause.
783 // If any of the directives that push regions here are parents of 'loop',
784 // assume 'parallel'. Otherwise do nothing.
785 if (!CaptureRegions.empty() &&
786 !llvm::is_contained(Range&: CaptureRegions, Element: OMPD_parallel))
787 CaptureRegions.push_back(Elt: OMPD_parallel);
788 else
789 return true;
790 break;
791 case OMPD_dispatch:
792 case OMPD_distribute:
793 case OMPD_for:
794 case OMPD_masked:
795 case OMPD_master:
796 case OMPD_ordered:
797 case OMPD_scope:
798 case OMPD_sections:
799 case OMPD_simd:
800 case OMPD_single:
801 case OMPD_target_data:
802 case OMPD_taskgroup:
803 // These directives (when standalone) use OMPD_unknown as the region,
804 // but when they're constituents of a compound directive, and other
805 // leafs from that directive have specific regions, then these directives
806 // add no additional regions.
807 return true;
808 default:
809 llvm::errs() << getOpenMPDirectiveName(D: LKind) << '\n';
810 llvm_unreachable("Unexpected directive");
811 }
812 return false;
813 };
814
815 bool MayNeedUnknownRegion = false;
816 for (OpenMPDirectiveKind L : getLeafConstructsOrSelf(D: DKind))
817 MayNeedUnknownRegion |= GetRegionsForLeaf(L);
818
819 // We need OMPD_unknown when no regions were added, and specific leaf
820 // constructs were present. Push a single OMPD_unknown as the capture
821 /// region.
822 if (CaptureRegions.empty() && MayNeedUnknownRegion)
823 CaptureRegions.push_back(Elt: OMPD_unknown);
824
825 // OMPD_unknown is only expected as the only region. If other regions
826 // are present OMPD_unknown should not be present.
827 assert((CaptureRegions[0] == OMPD_unknown ||
828 !llvm::is_contained(CaptureRegions, OMPD_unknown)) &&
829 "Misplaced OMPD_unknown");
830}
831
832bool clang::checkFailClauseParameter(OpenMPClauseKind FailClauseParameter) {
833 return FailClauseParameter == llvm::omp::OMPC_acquire ||
834 FailClauseParameter == llvm::omp::OMPC_relaxed ||
835 FailClauseParameter == llvm::omp::OMPC_seq_cst;
836}
837
838