1 //===--- OpenMPKinds.h - OpenMP enums ---------------------------*- C++ -*-===//
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 ///
9 /// \file
10 /// Defines some OpenMP-specific enums and functions.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_BASIC_OPENMPKINDS_H
15 #define LLVM_CLANG_BASIC_OPENMPKINDS_H
16 
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Frontend/OpenMP/OMPConstants.h"
19 
20 namespace clang {
21 
22 /// OpenMP directives.
23 using OpenMPDirectiveKind = llvm::omp::Directive;
24 
25 /// OpenMP clauses.
26 using OpenMPClauseKind = llvm::omp::Clause;
27 
28 /// OpenMP attributes for 'schedule' clause.
29 enum OpenMPScheduleClauseKind {
30 #define OPENMP_SCHEDULE_KIND(Name) \
31   OMPC_SCHEDULE_##Name,
32 #include "clang/Basic/OpenMPKinds.def"
33   OMPC_SCHEDULE_unknown
34 };
35 
36 /// OpenMP modifiers for 'schedule' clause.
37 enum OpenMPScheduleClauseModifier {
38   OMPC_SCHEDULE_MODIFIER_unknown = OMPC_SCHEDULE_unknown,
39 #define OPENMP_SCHEDULE_MODIFIER(Name) \
40   OMPC_SCHEDULE_MODIFIER_##Name,
41 #include "clang/Basic/OpenMPKinds.def"
42   OMPC_SCHEDULE_MODIFIER_last
43 };
44 
45 /// OpenMP modifiers for 'device' clause.
46 enum OpenMPDeviceClauseModifier {
47 #define OPENMP_DEVICE_MODIFIER(Name) OMPC_DEVICE_##Name,
48 #include "clang/Basic/OpenMPKinds.def"
49   OMPC_DEVICE_unknown,
50 };
51 
52 /// OpenMP attributes for 'depend' clause.
53 enum OpenMPDependClauseKind {
54 #define OPENMP_DEPEND_KIND(Name) \
55   OMPC_DEPEND_##Name,
56 #include "clang/Basic/OpenMPKinds.def"
57   OMPC_DEPEND_unknown
58 };
59 
60 /// OpenMP attributes for 'linear' clause.
61 enum OpenMPLinearClauseKind {
62 #define OPENMP_LINEAR_KIND(Name) \
63   OMPC_LINEAR_##Name,
64 #include "clang/Basic/OpenMPKinds.def"
65   OMPC_LINEAR_unknown
66 };
67 
68 /// OpenMP mapping kind for 'map' clause.
69 enum OpenMPMapClauseKind {
70 #define OPENMP_MAP_KIND(Name) \
71   OMPC_MAP_##Name,
72 #include "clang/Basic/OpenMPKinds.def"
73   OMPC_MAP_unknown
74 };
75 
76 /// OpenMP modifier kind for 'map' clause.
77 enum OpenMPMapModifierKind {
78   OMPC_MAP_MODIFIER_unknown = OMPC_MAP_unknown,
79 #define OPENMP_MAP_MODIFIER_KIND(Name) \
80   OMPC_MAP_MODIFIER_##Name,
81 #include "clang/Basic/OpenMPKinds.def"
82   OMPC_MAP_MODIFIER_last
83 };
84 
85   /// Number of allowed map-type-modifiers.
86 static constexpr unsigned NumberOfOMPMapClauseModifiers =
87     OMPC_MAP_MODIFIER_last - OMPC_MAP_MODIFIER_unknown - 1;
88 
89 /// OpenMP modifier kind for 'to' or 'from' clause.
90 enum OpenMPMotionModifierKind {
91 #define OPENMP_MOTION_MODIFIER_KIND(Name) \
92   OMPC_MOTION_MODIFIER_##Name,
93 #include "clang/Basic/OpenMPKinds.def"
94   OMPC_MOTION_MODIFIER_unknown
95 };
96 
97 /// Number of allowed motion-modifiers.
98 static constexpr unsigned NumberOfOMPMotionModifiers =
99     OMPC_MOTION_MODIFIER_unknown;
100 
101 /// OpenMP attributes for 'dist_schedule' clause.
102 enum OpenMPDistScheduleClauseKind {
103 #define OPENMP_DIST_SCHEDULE_KIND(Name) OMPC_DIST_SCHEDULE_##Name,
104 #include "clang/Basic/OpenMPKinds.def"
105   OMPC_DIST_SCHEDULE_unknown
106 };
107 
108 /// OpenMP attributes for 'defaultmap' clause.
109 enum OpenMPDefaultmapClauseKind {
110 #define OPENMP_DEFAULTMAP_KIND(Name) \
111   OMPC_DEFAULTMAP_##Name,
112 #include "clang/Basic/OpenMPKinds.def"
113   OMPC_DEFAULTMAP_unknown
114 };
115 
116 /// OpenMP modifiers for 'defaultmap' clause.
117 enum OpenMPDefaultmapClauseModifier {
118   OMPC_DEFAULTMAP_MODIFIER_unknown = OMPC_DEFAULTMAP_unknown,
119 #define OPENMP_DEFAULTMAP_MODIFIER(Name) \
120   OMPC_DEFAULTMAP_MODIFIER_##Name,
121 #include "clang/Basic/OpenMPKinds.def"
122   OMPC_DEFAULTMAP_MODIFIER_last
123 };
124 
125 /// OpenMP attributes for 'atomic_default_mem_order' clause.
126 enum OpenMPAtomicDefaultMemOrderClauseKind {
127 #define OPENMP_ATOMIC_DEFAULT_MEM_ORDER_KIND(Name)  \
128   OMPC_ATOMIC_DEFAULT_MEM_ORDER_##Name,
129 #include "clang/Basic/OpenMPKinds.def"
130   OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown
131 };
132 
133 /// OpenMP device type for 'device_type' clause.
134 enum OpenMPDeviceType {
135 #define OPENMP_DEVICE_TYPE_KIND(Name) \
136   OMPC_DEVICE_TYPE_##Name,
137 #include "clang/Basic/OpenMPKinds.def"
138   OMPC_DEVICE_TYPE_unknown
139 };
140 
141 /// OpenMP 'lastprivate' clause modifier.
142 enum OpenMPLastprivateModifier {
143 #define OPENMP_LASTPRIVATE_KIND(Name) OMPC_LASTPRIVATE_##Name,
144 #include "clang/Basic/OpenMPKinds.def"
145   OMPC_LASTPRIVATE_unknown,
146 };
147 
148 /// OpenMP attributes for 'order' clause.
149 enum OpenMPOrderClauseKind {
150 #define OPENMP_ORDER_KIND(Name) OMPC_ORDER_##Name,
151 #include "clang/Basic/OpenMPKinds.def"
152   OMPC_ORDER_unknown,
153 };
154 
155 /// Scheduling data for loop-based OpenMP directives.
156 struct OpenMPScheduleTy final {
157   OpenMPScheduleClauseKind Schedule = OMPC_SCHEDULE_unknown;
158   OpenMPScheduleClauseModifier M1 = OMPC_SCHEDULE_MODIFIER_unknown;
159   OpenMPScheduleClauseModifier M2 = OMPC_SCHEDULE_MODIFIER_unknown;
160 };
161 
162 /// OpenMP modifiers for 'reduction' clause.
163 enum OpenMPReductionClauseModifier {
164 #define OPENMP_REDUCTION_MODIFIER(Name) OMPC_REDUCTION_##Name,
165 #include "clang/Basic/OpenMPKinds.def"
166   OMPC_REDUCTION_unknown,
167 };
168 
169 unsigned getOpenMPSimpleClauseType(OpenMPClauseKind Kind, llvm::StringRef Str,
170                                    unsigned OpenMPVersion);
171 const char *getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, unsigned Type);
172 
173 /// Checks if the specified directive is a directive with an associated
174 /// loop construct.
175 /// \param DKind Specified directive.
176 /// \return true - the directive is a loop-associated directive like 'omp simd'
177 /// or 'omp for' directive, otherwise - false.
178 bool isOpenMPLoopDirective(OpenMPDirectiveKind DKind);
179 
180 /// Checks if the specified directive is a worksharing directive.
181 /// \param DKind Specified directive.
182 /// \return true - the directive is a worksharing directive like 'omp for',
183 /// otherwise - false.
184 bool isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind);
185 
186 /// Checks if the specified directive is a taskloop directive.
187 /// \param DKind Specified directive.
188 /// \return true - the directive is a worksharing directive like 'omp taskloop',
189 /// otherwise - false.
190 bool isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind);
191 
192 /// Checks if the specified directive is a parallel-kind directive.
193 /// \param DKind Specified directive.
194 /// \return true - the directive is a parallel-like directive like 'omp
195 /// parallel', otherwise - false.
196 bool isOpenMPParallelDirective(OpenMPDirectiveKind DKind);
197 
198 /// Checks if the specified directive is a target code offload directive.
199 /// \param DKind Specified directive.
200 /// \return true - the directive is a target code offload directive like
201 /// 'omp target', 'omp target parallel', 'omp target xxx'
202 /// otherwise - false.
203 bool isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind);
204 
205 /// Checks if the specified directive is a target data offload directive.
206 /// \param DKind Specified directive.
207 /// \return true - the directive is a target data offload directive like
208 /// 'omp target data', 'omp target update', 'omp target enter data',
209 /// 'omp target exit data'
210 /// otherwise - false.
211 bool isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind);
212 
213 /// Checks if the specified composite/combined directive constitutes a teams
214 /// directive in the outermost nest.  For example
215 /// 'omp teams distribute' or 'omp teams distribute parallel for'.
216 /// \param DKind Specified directive.
217 /// \return true - the directive has teams on the outermost nest, otherwise -
218 /// false.
219 bool isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind);
220 
221 /// Checks if the specified directive is a teams-kind directive.  For example,
222 /// 'omp teams distribute' or 'omp target teams'.
223 /// \param DKind Specified directive.
224 /// \return true - the directive is a teams-like directive, otherwise - false.
225 bool isOpenMPTeamsDirective(OpenMPDirectiveKind DKind);
226 
227 /// Checks if the specified directive is a simd directive.
228 /// \param DKind Specified directive.
229 /// \return true - the directive is a simd directive like 'omp simd',
230 /// otherwise - false.
231 bool isOpenMPSimdDirective(OpenMPDirectiveKind DKind);
232 
233 /// Checks if the specified directive is a distribute directive.
234 /// \param DKind Specified directive.
235 /// \return true - the directive is a distribute-directive like 'omp
236 /// distribute',
237 /// otherwise - false.
238 bool isOpenMPDistributeDirective(OpenMPDirectiveKind DKind);
239 
240 /// Checks if the specified composite/combined directive constitutes a
241 /// distribute directive in the outermost nest.  For example,
242 /// 'omp distribute parallel for' or 'omp distribute'.
243 /// \param DKind Specified directive.
244 /// \return true - the directive has distribute on the outermost nest.
245 /// otherwise - false.
246 bool isOpenMPNestingDistributeDirective(OpenMPDirectiveKind DKind);
247 
248 /// Checks if the specified clause is one of private clauses like
249 /// 'private', 'firstprivate', 'reduction' etc..
250 /// \param Kind Clause kind.
251 /// \return true - the clause is a private clause, otherwise - false.
252 bool isOpenMPPrivate(OpenMPClauseKind Kind);
253 
254 /// Checks if the specified clause is one of threadprivate clauses like
255 /// 'threadprivate', 'copyin' or 'copyprivate'.
256 /// \param Kind Clause kind.
257 /// \return true - the clause is a threadprivate clause, otherwise - false.
258 bool isOpenMPThreadPrivate(OpenMPClauseKind Kind);
259 
260 /// Checks if the specified directive kind is one of tasking directives - task,
261 /// taskloop, taksloop simd, master taskloop, parallel master taskloop, master
262 /// taskloop simd, or parallel master taskloop simd.
263 bool isOpenMPTaskingDirective(OpenMPDirectiveKind Kind);
264 
265 /// Checks if the specified directive kind is one of the composite or combined
266 /// directives that need loop bound sharing across loops outlined in nested
267 /// functions
268 bool isOpenMPLoopBoundSharingDirective(OpenMPDirectiveKind Kind);
269 
270 /// Return the captured regions of an OpenMP directive.
271 void getOpenMPCaptureRegions(
272     llvm::SmallVectorImpl<OpenMPDirectiveKind> &CaptureRegions,
273     OpenMPDirectiveKind DKind);
274 }
275 
276 #endif
277 
278