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