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>
printOpenACCDirectiveKind(StreamTy & Out,OpenACCDirectiveKind K)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
isOpenACCComputeDirectiveKind(OpenACCDirectiveKind K)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 /// 'copy' clause alias 'pcopy'. Preserved for diagnostic purposes.
193 PCopy,
194 /// 'copy' clause alias 'present_or_copy'. Preserved for diagnostic purposes.
195 PresentOrCopy,
196 /// 'use_device' clause, allowed on 'host_data' construct.
197 UseDevice,
198 /// 'attach' clause, allowed on Compute and Combined constructs, plus 'data'
199 /// and 'enter data'.
200 Attach,
201 /// 'delete' clause, allowed on the 'exit data' construct.
202 Delete,
203 /// 'detach' clause, allowed on the 'exit data' construct.
204 Detach,
205 /// 'device' clause, allowed on the 'update' construct.
206 Device,
207 /// 'deviceptr' clause, allowed on Compute and Combined Constructs, plus
208 /// 'data' and 'declare'.
209 DevicePtr,
210 /// 'device_resident' clause, allowed on the 'declare' construct.
211 DeviceResident,
212 /// 'firstprivate' clause, allowed on 'parallel', 'serial', 'parallel loop',
213 /// and 'serial loop' constructs.
214 FirstPrivate,
215 /// 'host' clause, allowed on 'update' construct.
216 Host,
217 /// 'link' clause, allowed on 'declare' construct.
218 Link,
219 /// 'no_create' clause, allowed on allowed on Compute and Combined constructs,
220 /// plus 'data'.
221 NoCreate,
222 /// 'present' clause, allowed on Compute and Combined constructs, plus 'data'
223 /// and 'declare'.
224 Present,
225 /// 'private' clause, allowed on 'parallel', 'serial', 'loop', 'parallel
226 /// loop', and 'serial loop' constructs.
227 Private,
228 /// 'copyout' clause, allowed on Compute and Combined constructs, plus 'data',
229 /// 'exit data', and 'declare'.
230 CopyOut,
231 /// 'copyout' clause alias 'pcopyout'. Preserved for diagnostic purposes.
232 PCopyOut,
233 /// 'copyout' clause alias 'present_or_copyout'. Preserved for diagnostic
234 /// purposes.
235 PresentOrCopyOut,
236 /// 'copyin' clause, allowed on Compute and Combined constructs, plus 'data',
237 /// 'enter data', and 'declare'.
238 CopyIn,
239 /// 'copyin' clause alias 'pcopyin'. Preserved for diagnostic purposes.
240 PCopyIn,
241 /// 'copyin' clause alias 'present_or_copyin'. Preserved for diagnostic
242 /// purposes.
243 PresentOrCopyIn,
244 /// 'create' clause, allowed on Compute and Combined constructs, plus 'data',
245 /// 'enter data', and 'declare'.
246 Create,
247 /// 'create' clause alias 'pcreate'. Preserved for diagnostic purposes.
248 PCreate,
249 /// 'create' clause alias 'present_or_create'. Preserved for diagnostic
250 /// purposes.
251 PresentOrCreate,
252 /// 'reduction' clause, allowed on Parallel, Serial, Loop, and the combined
253 /// constructs.
254 Reduction,
255 /// 'collapse' clause, allowed on 'loop' and Combined constructs.
256 Collapse,
257 /// 'bind' clause, allowed on routine constructs.
258 Bind,
259 /// 'vector_length' clause, allowed on 'parallel', 'kernels', 'parallel loop',
260 /// and 'kernels loop' constructs.
261 VectorLength,
262 /// 'num_gangs' clause, allowed on 'parallel', 'kernels', parallel loop', and
263 /// 'kernels loop' constructs.
264 NumGangs,
265 /// 'num_workers' clause, allowed on 'parallel', 'kernels', parallel loop',
266 /// and 'kernels loop' constructs.
267 NumWorkers,
268 /// 'device_num' clause, allowed on 'init', 'shutdown', and 'set' constructs.
269 DeviceNum,
270 /// 'default_async' clause, allowed on 'set' construct.
271 DefaultAsync,
272 /// 'device_type' clause, allowed on Compute, 'data', 'init', 'shutdown',
273 /// 'set', update', 'loop', 'routine', and Combined constructs.
274 DeviceType,
275 /// 'dtype' clause, an alias for 'device_type', stored separately for
276 /// diagnostic purposes.
277 DType,
278 /// 'async' clause, allowed on Compute, Data, 'update', 'wait', and Combined
279 /// constructs.
280 Async,
281 /// 'tile' clause, allowed on 'loop' and Combined constructs.
282 Tile,
283 /// 'gang' clause, allowed on 'loop' and Combined constructs.
284 Gang,
285 /// 'wait' clause, allowed on Compute, Data, 'update', and Combined
286 /// constructs.
287 Wait,
288
289 /// Represents an invalid clause, for the purposes of parsing.
290 Invalid,
291 };
292
293 template <typename StreamTy>
printOpenACCClauseKind(StreamTy & Out,OpenACCClauseKind K)294 inline StreamTy &printOpenACCClauseKind(StreamTy &Out, OpenACCClauseKind K) {
295 switch (K) {
296 case OpenACCClauseKind::Finalize:
297 return Out << "finalize";
298
299 case OpenACCClauseKind::IfPresent:
300 return Out << "if_present";
301
302 case OpenACCClauseKind::Seq:
303 return Out << "seq";
304
305 case OpenACCClauseKind::Independent:
306 return Out << "independent";
307
308 case OpenACCClauseKind::Auto:
309 return Out << "auto";
310
311 case OpenACCClauseKind::Worker:
312 return Out << "worker";
313
314 case OpenACCClauseKind::Vector:
315 return Out << "vector";
316
317 case OpenACCClauseKind::NoHost:
318 return Out << "nohost";
319
320 case OpenACCClauseKind::Default:
321 return Out << "default";
322
323 case OpenACCClauseKind::If:
324 return Out << "if";
325
326 case OpenACCClauseKind::Self:
327 return Out << "self";
328
329 case OpenACCClauseKind::Copy:
330 return Out << "copy";
331
332 case OpenACCClauseKind::PCopy:
333 return Out << "pcopy";
334
335 case OpenACCClauseKind::PresentOrCopy:
336 return Out << "present_or_copy";
337
338 case OpenACCClauseKind::UseDevice:
339 return Out << "use_device";
340
341 case OpenACCClauseKind::Attach:
342 return Out << "attach";
343
344 case OpenACCClauseKind::Delete:
345 return Out << "delete";
346
347 case OpenACCClauseKind::Detach:
348 return Out << "detach";
349
350 case OpenACCClauseKind::Device:
351 return Out << "device";
352
353 case OpenACCClauseKind::DevicePtr:
354 return Out << "deviceptr";
355
356 case OpenACCClauseKind::DeviceResident:
357 return Out << "device_resident";
358
359 case OpenACCClauseKind::FirstPrivate:
360 return Out << "firstprivate";
361
362 case OpenACCClauseKind::Host:
363 return Out << "host";
364
365 case OpenACCClauseKind::Link:
366 return Out << "link";
367
368 case OpenACCClauseKind::NoCreate:
369 return Out << "no_create";
370
371 case OpenACCClauseKind::Present:
372 return Out << "present";
373
374 case OpenACCClauseKind::Private:
375 return Out << "private";
376
377 case OpenACCClauseKind::CopyOut:
378 return Out << "copyout";
379
380 case OpenACCClauseKind::PCopyOut:
381 return Out << "pcopyout";
382
383 case OpenACCClauseKind::PresentOrCopyOut:
384 return Out << "present_or_copyout";
385
386 case OpenACCClauseKind::CopyIn:
387 return Out << "copyin";
388
389 case OpenACCClauseKind::PCopyIn:
390 return Out << "pcopyin";
391
392 case OpenACCClauseKind::PresentOrCopyIn:
393 return Out << "present_or_copyin";
394
395 case OpenACCClauseKind::Create:
396 return Out << "create";
397
398 case OpenACCClauseKind::PCreate:
399 return Out << "pcreate";
400
401 case OpenACCClauseKind::PresentOrCreate:
402 return Out << "present_or_create";
403
404 case OpenACCClauseKind::Reduction:
405 return Out << "reduction";
406
407 case OpenACCClauseKind::Collapse:
408 return Out << "collapse";
409
410 case OpenACCClauseKind::Bind:
411 return Out << "bind";
412
413 case OpenACCClauseKind::VectorLength:
414 return Out << "vector_length";
415
416 case OpenACCClauseKind::NumGangs:
417 return Out << "num_gangs";
418
419 case OpenACCClauseKind::NumWorkers:
420 return Out << "num_workers";
421
422 case OpenACCClauseKind::DeviceNum:
423 return Out << "device_num";
424
425 case OpenACCClauseKind::DefaultAsync:
426 return Out << "default_async";
427
428 case OpenACCClauseKind::DeviceType:
429 return Out << "device_type";
430
431 case OpenACCClauseKind::DType:
432 return Out << "dtype";
433
434 case OpenACCClauseKind::Async:
435 return Out << "async";
436
437 case OpenACCClauseKind::Tile:
438 return Out << "tile";
439
440 case OpenACCClauseKind::Gang:
441 return Out << "gang";
442
443 case OpenACCClauseKind::Wait:
444 return Out << "wait";
445
446 case OpenACCClauseKind::Invalid:
447 return Out << "<invalid>";
448 }
449 llvm_unreachable("Uncovered clause kind");
450 }
451
452 inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &Out,
453 OpenACCClauseKind K) {
454 return printOpenACCClauseKind(Out, K);
455 }
456
457 inline llvm::raw_ostream &operator<<(llvm::raw_ostream &Out,
458 OpenACCClauseKind K) {
459 return printOpenACCClauseKind(Out, K);
460 }
461
462 enum class OpenACCDefaultClauseKind {
463 /// 'none' option.
464 None,
465 /// 'present' option.
466 Present,
467 /// Not a valid option.
468 Invalid,
469 };
470
471 template <typename StreamTy>
printOpenACCDefaultClauseKind(StreamTy & Out,OpenACCDefaultClauseKind K)472 inline StreamTy &printOpenACCDefaultClauseKind(StreamTy &Out,
473 OpenACCDefaultClauseKind K) {
474 switch (K) {
475 case OpenACCDefaultClauseKind::None:
476 return Out << "none";
477 case OpenACCDefaultClauseKind::Present:
478 return Out << "present";
479 case OpenACCDefaultClauseKind::Invalid:
480 return Out << "<invalid>";
481 }
482 llvm_unreachable("Unknown OpenACCDefaultClauseKind enum");
483 }
484
485 inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &Out,
486 OpenACCDefaultClauseKind K) {
487 return printOpenACCDefaultClauseKind(Out, K);
488 }
489
490 inline llvm::raw_ostream &operator<<(llvm::raw_ostream &Out,
491 OpenACCDefaultClauseKind K) {
492 return printOpenACCDefaultClauseKind(Out, K);
493 }
494
495 enum class OpenACCReductionOperator {
496 /// '+'.
497 Addition,
498 /// '*'.
499 Multiplication,
500 /// 'max'.
501 Max,
502 /// 'min'.
503 Min,
504 /// '&'.
505 BitwiseAnd,
506 /// '|'.
507 BitwiseOr,
508 /// '^'.
509 BitwiseXOr,
510 /// '&&'.
511 And,
512 /// '||'.
513 Or,
514 /// Invalid Reduction Clause Kind.
515 Invalid,
516 };
517
518 template <typename StreamTy>
printOpenACCReductionOperator(StreamTy & Out,OpenACCReductionOperator Op)519 inline StreamTy &printOpenACCReductionOperator(StreamTy &Out,
520 OpenACCReductionOperator Op) {
521 switch (Op) {
522 case OpenACCReductionOperator::Addition:
523 return Out << "+";
524 case OpenACCReductionOperator::Multiplication:
525 return Out << "*";
526 case OpenACCReductionOperator::Max:
527 return Out << "max";
528 case OpenACCReductionOperator::Min:
529 return Out << "min";
530 case OpenACCReductionOperator::BitwiseAnd:
531 return Out << "&";
532 case OpenACCReductionOperator::BitwiseOr:
533 return Out << "|";
534 case OpenACCReductionOperator::BitwiseXOr:
535 return Out << "^";
536 case OpenACCReductionOperator::And:
537 return Out << "&&";
538 case OpenACCReductionOperator::Or:
539 return Out << "||";
540 case OpenACCReductionOperator::Invalid:
541 return Out << "<invalid>";
542 }
543 llvm_unreachable("Unknown reduction operator kind");
544 }
545 inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &Out,
546 OpenACCReductionOperator Op) {
547 return printOpenACCReductionOperator(Out, Op);
548 }
549 inline llvm::raw_ostream &operator<<(llvm::raw_ostream &Out,
550 OpenACCReductionOperator Op) {
551 return printOpenACCReductionOperator(Out, Op);
552 }
553 } // namespace clang
554
555 #endif // LLVM_CLANG_BASIC_OPENACCKINDS_H
556