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