1 | //===--- OpenACCKinds.h - OpenACC 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 OpenACC-specific enums and functions. |
11 | /// |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #ifndef LLVM_CLANG_BASIC_OPENACCKINDS_H |
15 | #define LLVM_CLANG_BASIC_OPENACCKINDS_H |
16 | |
17 | #include "clang/Basic/Diagnostic.h" |
18 | #include "llvm/Support/ErrorHandling.h" |
19 | #include "llvm/Support/raw_ostream.h" |
20 | |
21 | namespace clang { |
22 | // Represents the Construct/Directive kind of a pragma directive. Note the |
23 | // OpenACC standard is inconsistent between calling these Construct vs |
24 | // Directive, but we're calling it a Directive to be consistent with OpenMP. |
25 | enum class OpenACCDirectiveKind { |
26 | // Compute Constructs. |
27 | Parallel, |
28 | Serial, |
29 | Kernels, |
30 | |
31 | // Data Environment. "enter data" and "exit data" are also referred to in the |
32 | // Executable Directives section, but just as a back reference to the Data |
33 | // Environment. |
34 | Data, |
35 | EnterData, |
36 | ExitData, |
37 | HostData, |
38 | |
39 | // Misc. |
40 | Loop, |
41 | Cache, |
42 | |
43 | // Combined Constructs. |
44 | ParallelLoop, |
45 | SerialLoop, |
46 | KernelsLoop, |
47 | |
48 | // Atomic Construct. |
49 | Atomic, |
50 | |
51 | // Declare Directive. |
52 | Declare, |
53 | |
54 | // Executable Directives. "wait" is first referred to here, but ends up being |
55 | // in its own section after "routine". |
56 | Init, |
57 | Shutdown, |
58 | Set, |
59 | Update, |
60 | Wait, |
61 | |
62 | // Procedure Calls in Compute Regions. |
63 | Routine, |
64 | |
65 | // Invalid. |
66 | Invalid, |
67 | }; |
68 | |
69 | template <typename StreamTy> |
70 | inline StreamTy &printOpenACCDirectiveKind(StreamTy &Out, |
71 | OpenACCDirectiveKind K) { |
72 | switch (K) { |
73 | case OpenACCDirectiveKind::Parallel: |
74 | return Out << "parallel" ; |
75 | |
76 | case OpenACCDirectiveKind::Serial: |
77 | return Out << "serial" ; |
78 | |
79 | case OpenACCDirectiveKind::Kernels: |
80 | return Out << "kernels" ; |
81 | |
82 | case OpenACCDirectiveKind::Data: |
83 | return Out << "data" ; |
84 | |
85 | case OpenACCDirectiveKind::EnterData: |
86 | return Out << "enter data" ; |
87 | |
88 | case OpenACCDirectiveKind::ExitData: |
89 | return Out << "exit data" ; |
90 | |
91 | case OpenACCDirectiveKind::HostData: |
92 | return Out << "host_data" ; |
93 | |
94 | case OpenACCDirectiveKind::Loop: |
95 | return Out << "loop" ; |
96 | |
97 | case OpenACCDirectiveKind::Cache: |
98 | return Out << "cache" ; |
99 | |
100 | case OpenACCDirectiveKind::ParallelLoop: |
101 | return Out << "parallel loop" ; |
102 | |
103 | case OpenACCDirectiveKind::SerialLoop: |
104 | return Out << "serial loop" ; |
105 | |
106 | case OpenACCDirectiveKind::KernelsLoop: |
107 | return Out << "kernels loop" ; |
108 | |
109 | case OpenACCDirectiveKind::Atomic: |
110 | return Out << "atomic" ; |
111 | |
112 | case OpenACCDirectiveKind::Declare: |
113 | return Out << "declare" ; |
114 | |
115 | case OpenACCDirectiveKind::Init: |
116 | return Out << "init" ; |
117 | |
118 | case OpenACCDirectiveKind::Shutdown: |
119 | return Out << "shutdown" ; |
120 | |
121 | case OpenACCDirectiveKind::Set: |
122 | return Out << "set" ; |
123 | |
124 | case OpenACCDirectiveKind::Update: |
125 | return Out << "update" ; |
126 | |
127 | case OpenACCDirectiveKind::Wait: |
128 | return Out << "wait" ; |
129 | |
130 | case OpenACCDirectiveKind::Routine: |
131 | return Out << "routine" ; |
132 | |
133 | case OpenACCDirectiveKind::Invalid: |
134 | return Out << "<invalid>" ; |
135 | } |
136 | llvm_unreachable("Uncovered directive kind" ); |
137 | } |
138 | |
139 | inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &Out, |
140 | OpenACCDirectiveKind K) { |
141 | return printOpenACCDirectiveKind(Out, K); |
142 | } |
143 | |
144 | inline llvm::raw_ostream &operator<<(llvm::raw_ostream &Out, |
145 | OpenACCDirectiveKind K) { |
146 | return printOpenACCDirectiveKind(Out, K); |
147 | } |
148 | |
149 | inline bool isOpenACCComputeDirectiveKind(OpenACCDirectiveKind K) { |
150 | return K == OpenACCDirectiveKind::Parallel || |
151 | K == OpenACCDirectiveKind::Serial || |
152 | K == OpenACCDirectiveKind::Kernels; |
153 | } |
154 | |
155 | enum class OpenACCAtomicKind { |
156 | Read, |
157 | Write, |
158 | Update, |
159 | Capture, |
160 | Invalid, |
161 | }; |
162 | |
163 | /// Represents the kind of an OpenACC clause. |
164 | enum class OpenACCClauseKind { |
165 | /// 'finalize' clause, allowed on 'exit data' directive. |
166 | Finalize, |
167 | /// 'if_present' clause, allowed on 'host_data' and 'update' directives. |
168 | IfPresent, |
169 | /// 'seq' clause, allowed on 'loop' and 'routine' directives. |
170 | Seq, |
171 | /// 'independent' clause, allowed on 'loop' directives. |
172 | Independent, |
173 | /// 'auto' clause, allowed on 'loop' directives. |
174 | Auto, |
175 | /// 'worker' clause, allowed on 'loop', Combined, and 'routine' directives. |
176 | Worker, |
177 | /// 'vector' clause, allowed on 'loop', Combined, and 'routine' directives. |
178 | Vector, |
179 | /// 'nohost' clause, allowed on 'routine' directives. |
180 | NoHost, |
181 | /// 'default' clause, allowed on parallel, serial, kernel (and compound) |
182 | /// constructs. |
183 | Default, |
184 | /// 'if' clause, allowed on all the Compute Constructs, Data Constructs, |
185 | /// Executable Constructs, and Combined Constructs. |
186 | If, |
187 | /// 'self' clause, allowed on Compute and Combined Constructs, plus 'update'. |
188 | Self, |
189 | /// 'copy' clause, allowed on Compute and Combined Constructs, plus 'data' and |
190 | /// 'declare'. |
191 | Copy, |
192 | /// 'use_device' clause, allowed on 'host_data' construct. |
193 | UseDevice, |
194 | /// 'attach' clause, allowed on Compute and Combined constructs, plus 'data' |
195 | /// and 'enter data'. |
196 | Attach, |
197 | /// 'delete' clause, allowed on the 'exit data' construct. |
198 | Delete, |
199 | /// 'detach' clause, allowed on the 'exit data' construct. |
200 | Detach, |
201 | /// 'device' clause, allowed on the 'update' construct. |
202 | Device, |
203 | /// 'deviceptr' clause, allowed on Compute and Combined Constructs, plus |
204 | /// 'data' and 'declare'. |
205 | DevicePtr, |
206 | /// 'device_resident' clause, allowed on the 'declare' construct. |
207 | DeviceResident, |
208 | /// 'firstprivate' clause, allowed on 'parallel', 'serial', 'parallel loop', |
209 | /// and 'serial loop' constructs. |
210 | FirstPrivate, |
211 | /// 'host' clause, allowed on 'update' construct. |
212 | Host, |
213 | /// 'link' clause, allowed on 'declare' construct. |
214 | Link, |
215 | /// 'no_create' clause, allowed on allowed on Compute and Combined constructs, |
216 | /// plus 'data'. |
217 | NoCreate, |
218 | /// 'present' clause, allowed on Compute and Combined constructs, plus 'data' |
219 | /// and 'declare'. |
220 | Present, |
221 | /// 'private' clause, allowed on 'parallel', 'serial', 'loop', 'parallel |
222 | /// loop', and 'serial loop' constructs. |
223 | Private, |
224 | /// 'copyout' clause, allowed on Compute and Combined constructs, plus 'data', |
225 | /// 'exit data', and 'declare'. |
226 | CopyOut, |
227 | /// 'copyin' clause, allowed on Compute and Combined constructs, plus 'data', |
228 | /// 'enter data', and 'declare'. |
229 | CopyIn, |
230 | /// 'copyin' clause, allowed on Compute and Combined constructs, plus 'data', |
231 | /// 'enter data', and 'declare'. |
232 | Create, |
233 | /// 'reduction' clause, allowed on Parallel, Serial, Loop, and the combined |
234 | /// constructs. |
235 | Reduction, |
236 | /// 'collapse' clause, allowed on 'loop' and Combined constructs. |
237 | Collapse, |
238 | /// 'bind' clause, allowed on routine constructs. |
239 | Bind, |
240 | /// 'vector_length' clause, allowed on 'parallel', 'kernels', 'parallel loop', |
241 | /// and 'kernels loop' constructs. |
242 | VectorLength, |
243 | /// 'num_gangs' clause, allowed on 'parallel', 'kernels', parallel loop', and |
244 | /// 'kernels loop' constructs. |
245 | NumGangs, |
246 | /// 'num_workers' clause, allowed on 'parallel', 'kernels', parallel loop', |
247 | /// and 'kernels loop' constructs. |
248 | NumWorkers, |
249 | /// 'device_num' clause, allowed on 'init', 'shutdown', and 'set' constructs. |
250 | DeviceNum, |
251 | /// 'default_async' clause, allowed on 'set' construct. |
252 | DefaultAsync, |
253 | /// 'device_type' clause, allowed on Compute, 'data', 'init', 'shutdown', |
254 | /// 'set', update', 'loop', 'routine', and Combined constructs. |
255 | DeviceType, |
256 | /// 'dtype' clause, an alias for 'device_type', stored separately for |
257 | /// diagnostic purposes. |
258 | DType, |
259 | /// 'async' clause, allowed on Compute, Data, 'update', 'wait', and Combined |
260 | /// constructs. |
261 | Async, |
262 | /// 'tile' clause, allowed on 'loop' and Combined constructs. |
263 | Tile, |
264 | /// 'gang' clause, allowed on 'loop' and Combined constructs. |
265 | Gang, |
266 | /// 'wait' clause, allowed on Compute, Data, 'update', and Combined |
267 | /// constructs. |
268 | Wait, |
269 | |
270 | /// Represents an invalid clause, for the purposes of parsing. |
271 | Invalid, |
272 | }; |
273 | |
274 | template <typename StreamTy> |
275 | inline StreamTy &printOpenACCClauseKind(StreamTy &Out, OpenACCClauseKind K) { |
276 | switch (K) { |
277 | case OpenACCClauseKind::Finalize: |
278 | return Out << "finalize" ; |
279 | |
280 | case OpenACCClauseKind::IfPresent: |
281 | return Out << "if_present" ; |
282 | |
283 | case OpenACCClauseKind::Seq: |
284 | return Out << "seq" ; |
285 | |
286 | case OpenACCClauseKind::Independent: |
287 | return Out << "independent" ; |
288 | |
289 | case OpenACCClauseKind::Auto: |
290 | return Out << "auto" ; |
291 | |
292 | case OpenACCClauseKind::Worker: |
293 | return Out << "worker" ; |
294 | |
295 | case OpenACCClauseKind::Vector: |
296 | return Out << "vector" ; |
297 | |
298 | case OpenACCClauseKind::NoHost: |
299 | return Out << "nohost" ; |
300 | |
301 | case OpenACCClauseKind::Default: |
302 | return Out << "default" ; |
303 | |
304 | case OpenACCClauseKind::If: |
305 | return Out << "if" ; |
306 | |
307 | case OpenACCClauseKind::Self: |
308 | return Out << "self" ; |
309 | |
310 | case OpenACCClauseKind::Copy: |
311 | return Out << "copy" ; |
312 | |
313 | case OpenACCClauseKind::UseDevice: |
314 | return Out << "use_device" ; |
315 | |
316 | case OpenACCClauseKind::Attach: |
317 | return Out << "attach" ; |
318 | |
319 | case OpenACCClauseKind::Delete: |
320 | return Out << "delete" ; |
321 | |
322 | case OpenACCClauseKind::Detach: |
323 | return Out << "detach" ; |
324 | |
325 | case OpenACCClauseKind::Device: |
326 | return Out << "device" ; |
327 | |
328 | case OpenACCClauseKind::DevicePtr: |
329 | return Out << "deviceptr" ; |
330 | |
331 | case OpenACCClauseKind::DeviceResident: |
332 | return Out << "device_resident" ; |
333 | |
334 | case OpenACCClauseKind::FirstPrivate: |
335 | return Out << "firstprivate" ; |
336 | |
337 | case OpenACCClauseKind::Host: |
338 | return Out << "host" ; |
339 | |
340 | case OpenACCClauseKind::Link: |
341 | return Out << "link" ; |
342 | |
343 | case OpenACCClauseKind::NoCreate: |
344 | return Out << "no_create" ; |
345 | |
346 | case OpenACCClauseKind::Present: |
347 | return Out << "present" ; |
348 | |
349 | case OpenACCClauseKind::Private: |
350 | return Out << "private" ; |
351 | |
352 | case OpenACCClauseKind::CopyOut: |
353 | return Out << "copyout" ; |
354 | |
355 | case OpenACCClauseKind::CopyIn: |
356 | return Out << "copyin" ; |
357 | |
358 | case OpenACCClauseKind::Create: |
359 | return Out << "create" ; |
360 | |
361 | case OpenACCClauseKind::Reduction: |
362 | return Out << "reduction" ; |
363 | |
364 | case OpenACCClauseKind::Collapse: |
365 | return Out << "collapse" ; |
366 | |
367 | case OpenACCClauseKind::Bind: |
368 | return Out << "bind" ; |
369 | |
370 | case OpenACCClauseKind::VectorLength: |
371 | return Out << "vector_length" ; |
372 | |
373 | case OpenACCClauseKind::NumGangs: |
374 | return Out << "num_gangs" ; |
375 | |
376 | case OpenACCClauseKind::NumWorkers: |
377 | return Out << "num_workers" ; |
378 | |
379 | case OpenACCClauseKind::DeviceNum: |
380 | return Out << "device_num" ; |
381 | |
382 | case OpenACCClauseKind::DefaultAsync: |
383 | return Out << "default_async" ; |
384 | |
385 | case OpenACCClauseKind::DeviceType: |
386 | return Out << "device_type" ; |
387 | |
388 | case OpenACCClauseKind::DType: |
389 | return Out << "dtype" ; |
390 | |
391 | case OpenACCClauseKind::Async: |
392 | return Out << "async" ; |
393 | |
394 | case OpenACCClauseKind::Tile: |
395 | return Out << "tile" ; |
396 | |
397 | case OpenACCClauseKind::Gang: |
398 | return Out << "gang" ; |
399 | |
400 | case OpenACCClauseKind::Wait: |
401 | return Out << "wait" ; |
402 | |
403 | case OpenACCClauseKind::Invalid: |
404 | return Out << "<invalid>" ; |
405 | } |
406 | llvm_unreachable("Uncovered clause kind" ); |
407 | } |
408 | |
409 | inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &Out, |
410 | OpenACCClauseKind K) { |
411 | return printOpenACCClauseKind(Out, K); |
412 | } |
413 | |
414 | inline llvm::raw_ostream &operator<<(llvm::raw_ostream &Out, |
415 | OpenACCClauseKind K) { |
416 | return printOpenACCClauseKind(Out, K); |
417 | } |
418 | |
419 | enum class OpenACCDefaultClauseKind { |
420 | /// 'none' option. |
421 | None, |
422 | /// 'present' option. |
423 | Present, |
424 | /// Not a valid option. |
425 | Invalid, |
426 | }; |
427 | |
428 | template <typename StreamTy> |
429 | inline StreamTy &printOpenACCDefaultClauseKind(StreamTy &Out, |
430 | OpenACCDefaultClauseKind K) { |
431 | switch (K) { |
432 | case OpenACCDefaultClauseKind::None: |
433 | return Out << "none" ; |
434 | case OpenACCDefaultClauseKind::Present: |
435 | return Out << "present" ; |
436 | case OpenACCDefaultClauseKind::Invalid: |
437 | return Out << "<invalid>" ; |
438 | } |
439 | llvm_unreachable("Unknown OpenACCDefaultClauseKind enum" ); |
440 | } |
441 | |
442 | inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &Out, |
443 | OpenACCDefaultClauseKind K) { |
444 | return printOpenACCDefaultClauseKind(Out, K); |
445 | } |
446 | |
447 | inline llvm::raw_ostream &operator<<(llvm::raw_ostream &Out, |
448 | OpenACCDefaultClauseKind K) { |
449 | return printOpenACCDefaultClauseKind(Out, K); |
450 | } |
451 | |
452 | enum class OpenACCReductionOperator { |
453 | /// '+'. |
454 | Addition, |
455 | /// '*'. |
456 | Multiplication, |
457 | /// 'max'. |
458 | Max, |
459 | /// 'min'. |
460 | Min, |
461 | /// '&'. |
462 | BitwiseAnd, |
463 | /// '|'. |
464 | BitwiseOr, |
465 | /// '^'. |
466 | BitwiseXOr, |
467 | /// '&&'. |
468 | And, |
469 | /// '||'. |
470 | Or, |
471 | /// Invalid Reduction Clause Kind. |
472 | Invalid, |
473 | }; |
474 | } // namespace clang |
475 | |
476 | #endif // LLVM_CLANG_BASIC_OPENACCKINDS_H |
477 | |