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