Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:50

0001 //===--- OpenACCKinds.h - OpenACC Enums -------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 ///
0009 /// \file
0010 /// Defines some OpenACC-specific enums and functions.
0011 ///
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_CLANG_BASIC_OPENACCKINDS_H
0015 #define LLVM_CLANG_BASIC_OPENACCKINDS_H
0016 
0017 #include "clang/Basic/Diagnostic.h"
0018 #include "llvm/Support/ErrorHandling.h"
0019 #include "llvm/Support/raw_ostream.h"
0020 
0021 namespace clang {
0022 // Represents the Construct/Directive kind of a pragma directive. Note the
0023 // OpenACC standard is inconsistent between calling these Construct vs
0024 // Directive, but we're calling it a Directive to be consistent with OpenMP.
0025 enum class OpenACCDirectiveKind : uint8_t {
0026   // Compute Constructs.
0027   Parallel,
0028   Serial,
0029   Kernels,
0030 
0031   // Data Environment. "enter data" and "exit data" are also referred to in the
0032   // Executable Directives section, but just as a back reference to the Data
0033   // Environment.
0034   Data,
0035   EnterData,
0036   ExitData,
0037   HostData,
0038 
0039   // Misc.
0040   Loop,
0041   Cache,
0042 
0043   // Combined Constructs.
0044   ParallelLoop,
0045   SerialLoop,
0046   KernelsLoop,
0047 
0048   // Atomic Construct.
0049   Atomic,
0050 
0051   // Declare Directive.
0052   Declare,
0053 
0054   // Executable Directives. "wait" is first referred to here, but ends up being
0055   // in its own section after "routine".
0056   Init,
0057   Shutdown,
0058   Set,
0059   Update,
0060   Wait,
0061 
0062   // Procedure Calls in Compute Regions.
0063   Routine,
0064 
0065   // Invalid.
0066   Invalid,
0067 };
0068 
0069 template <typename StreamTy>
0070 inline StreamTy &printOpenACCDirectiveKind(StreamTy &Out,
0071                                            OpenACCDirectiveKind K) {
0072   switch (K) {
0073   case OpenACCDirectiveKind::Parallel:
0074     return Out << "parallel";
0075 
0076   case OpenACCDirectiveKind::Serial:
0077     return Out << "serial";
0078 
0079   case OpenACCDirectiveKind::Kernels:
0080     return Out << "kernels";
0081 
0082   case OpenACCDirectiveKind::Data:
0083     return Out << "data";
0084 
0085   case OpenACCDirectiveKind::EnterData:
0086     return Out << "enter data";
0087 
0088   case OpenACCDirectiveKind::ExitData:
0089     return Out << "exit data";
0090 
0091   case OpenACCDirectiveKind::HostData:
0092     return Out << "host_data";
0093 
0094   case OpenACCDirectiveKind::Loop:
0095     return Out << "loop";
0096 
0097   case OpenACCDirectiveKind::Cache:
0098     return Out << "cache";
0099 
0100   case OpenACCDirectiveKind::ParallelLoop:
0101     return Out << "parallel loop";
0102 
0103   case OpenACCDirectiveKind::SerialLoop:
0104     return Out << "serial loop";
0105 
0106   case OpenACCDirectiveKind::KernelsLoop:
0107     return Out << "kernels loop";
0108 
0109   case OpenACCDirectiveKind::Atomic:
0110     return Out << "atomic";
0111 
0112   case OpenACCDirectiveKind::Declare:
0113     return Out << "declare";
0114 
0115   case OpenACCDirectiveKind::Init:
0116     return Out << "init";
0117 
0118   case OpenACCDirectiveKind::Shutdown:
0119     return Out << "shutdown";
0120 
0121   case OpenACCDirectiveKind::Set:
0122     return Out << "set";
0123 
0124   case OpenACCDirectiveKind::Update:
0125     return Out << "update";
0126 
0127   case OpenACCDirectiveKind::Wait:
0128     return Out << "wait";
0129 
0130   case OpenACCDirectiveKind::Routine:
0131     return Out << "routine";
0132 
0133   case OpenACCDirectiveKind::Invalid:
0134     return Out << "<invalid>";
0135   }
0136   llvm_unreachable("Uncovered directive kind");
0137 }
0138 
0139 inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &Out,
0140                                              OpenACCDirectiveKind K) {
0141   return printOpenACCDirectiveKind(Out, K);
0142 }
0143 
0144 inline llvm::raw_ostream &operator<<(llvm::raw_ostream &Out,
0145                                      OpenACCDirectiveKind K) {
0146   return printOpenACCDirectiveKind(Out, K);
0147 }
0148 
0149 inline bool isOpenACCComputeDirectiveKind(OpenACCDirectiveKind K) {
0150   return K == OpenACCDirectiveKind::Parallel ||
0151          K == OpenACCDirectiveKind::Serial ||
0152          K == OpenACCDirectiveKind::Kernels;
0153 }
0154 
0155 inline bool isOpenACCCombinedDirectiveKind(OpenACCDirectiveKind K) {
0156   return K == OpenACCDirectiveKind::ParallelLoop ||
0157          K == OpenACCDirectiveKind::SerialLoop ||
0158          K == OpenACCDirectiveKind::KernelsLoop;
0159 }
0160 
0161 // Tests 'K' to see if it is 'data', 'host_data', 'enter data', or 'exit data'.
0162 inline bool isOpenACCDataDirectiveKind(OpenACCDirectiveKind K) {
0163   return K == OpenACCDirectiveKind::Data ||
0164          K == OpenACCDirectiveKind::EnterData ||
0165          K == OpenACCDirectiveKind::ExitData ||
0166          K == OpenACCDirectiveKind::HostData;
0167 }
0168 
0169 enum class OpenACCAtomicKind : uint8_t {
0170   Read,
0171   Write,
0172   Update,
0173   Capture,
0174   Invalid,
0175 };
0176 
0177 /// Represents the kind of an OpenACC clause.
0178 enum class OpenACCClauseKind : uint8_t {
0179   /// 'finalize' clause, allowed on 'exit data' directive.
0180   Finalize,
0181   /// 'if_present' clause, allowed on 'host_data' and 'update' directives.
0182   IfPresent,
0183   /// 'seq' clause, allowed on 'loop' and 'routine' directives.
0184   Seq,
0185   /// 'independent' clause, allowed on 'loop' directives.
0186   Independent,
0187   /// 'auto' clause, allowed on 'loop' directives.
0188   Auto,
0189   /// 'worker' clause, allowed on 'loop', Combined, and 'routine' directives.
0190   Worker,
0191   /// 'vector' clause, allowed on 'loop', Combined, and 'routine' directives.
0192   Vector,
0193   /// 'nohost' clause, allowed on 'routine' directives.
0194   NoHost,
0195   /// 'default' clause, allowed on parallel, serial, kernel (and compound)
0196   /// constructs.
0197   Default,
0198   /// 'if' clause, allowed on all the Compute Constructs, Data Constructs,
0199   /// Executable Constructs, and Combined Constructs.
0200   If,
0201   /// 'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
0202   Self,
0203   /// 'copy' clause, allowed on Compute and Combined Constructs, plus 'data' and
0204   /// 'declare'.
0205   Copy,
0206   /// 'copy' clause alias 'pcopy'.  Preserved for diagnostic purposes.
0207   PCopy,
0208   /// 'copy' clause alias 'present_or_copy'.  Preserved for diagnostic purposes.
0209   PresentOrCopy,
0210   /// 'use_device' clause, allowed on 'host_data' construct.
0211   UseDevice,
0212   /// 'attach' clause, allowed on Compute and Combined constructs, plus 'data'
0213   /// and 'enter data'.
0214   Attach,
0215   /// 'delete' clause, allowed on the 'exit data' construct.
0216   Delete,
0217   /// 'detach' clause, allowed on the 'exit data' construct.
0218   Detach,
0219   /// 'device' clause, allowed on the 'update' construct.
0220   Device,
0221   /// 'deviceptr' clause, allowed on Compute and Combined Constructs, plus
0222   /// 'data' and 'declare'.
0223   DevicePtr,
0224   /// 'device_resident' clause, allowed on the 'declare' construct.
0225   DeviceResident,
0226   /// 'firstprivate' clause, allowed on 'parallel', 'serial', 'parallel loop',
0227   /// and 'serial loop' constructs.
0228   FirstPrivate,
0229   /// 'host' clause, allowed on 'update' construct.
0230   Host,
0231   /// 'link' clause, allowed on 'declare' construct.
0232   Link,
0233   /// 'no_create' clause, allowed on allowed on Compute and Combined constructs,
0234   /// plus 'data'.
0235   NoCreate,
0236   /// 'present' clause, allowed on Compute and Combined constructs, plus 'data'
0237   /// and 'declare'.
0238   Present,
0239   /// 'private' clause, allowed on 'parallel', 'serial', 'loop', 'parallel
0240   /// loop', and 'serial loop' constructs.
0241   Private,
0242   /// 'copyout' clause, allowed on Compute and Combined constructs, plus 'data',
0243   /// 'exit data', and 'declare'.
0244   CopyOut,
0245   /// 'copyout' clause alias 'pcopyout'.  Preserved for diagnostic purposes.
0246   PCopyOut,
0247   /// 'copyout' clause alias 'present_or_copyout'.  Preserved for diagnostic
0248   /// purposes.
0249   PresentOrCopyOut,
0250   /// 'copyin' clause, allowed on Compute and Combined constructs, plus 'data',
0251   /// 'enter data', and 'declare'.
0252   CopyIn,
0253   /// 'copyin' clause alias 'pcopyin'.  Preserved for diagnostic purposes.
0254   PCopyIn,
0255   /// 'copyin' clause alias 'present_or_copyin'.  Preserved for diagnostic
0256   /// purposes.
0257   PresentOrCopyIn,
0258   /// 'create' clause, allowed on Compute and Combined constructs, plus 'data',
0259   /// 'enter data', and 'declare'.
0260   Create,
0261   /// 'create' clause alias 'pcreate'.  Preserved for diagnostic purposes.
0262   PCreate,
0263   /// 'create' clause alias 'present_or_create'.  Preserved for diagnostic
0264   /// purposes.
0265   PresentOrCreate,
0266   /// 'reduction' clause, allowed on Parallel, Serial, Loop, and the combined
0267   /// constructs.
0268   Reduction,
0269   /// 'collapse' clause, allowed on 'loop' and Combined constructs.
0270   Collapse,
0271   /// 'bind' clause, allowed on routine constructs.
0272   Bind,
0273   /// 'vector_length' clause, allowed on 'parallel', 'kernels', 'parallel loop',
0274   /// and 'kernels loop' constructs.
0275   VectorLength,
0276   /// 'num_gangs' clause, allowed on 'parallel', 'kernels', parallel loop', and
0277   /// 'kernels loop' constructs.
0278   NumGangs,
0279   /// 'num_workers' clause, allowed on 'parallel', 'kernels', parallel loop',
0280   /// and 'kernels loop' constructs.
0281   NumWorkers,
0282   /// 'device_num' clause, allowed on 'init', 'shutdown', and 'set' constructs.
0283   DeviceNum,
0284   /// 'default_async' clause, allowed on 'set' construct.
0285   DefaultAsync,
0286   /// 'device_type' clause, allowed on Compute, 'data', 'init', 'shutdown',
0287   /// 'set', update', 'loop', 'routine', and Combined constructs.
0288   DeviceType,
0289   /// 'dtype' clause, an alias for 'device_type', stored separately for
0290   /// diagnostic purposes.
0291   DType,
0292   /// 'async' clause, allowed on Compute, Data, 'update', 'wait', and Combined
0293   /// constructs.
0294   Async,
0295   /// 'tile' clause, allowed on 'loop' and Combined constructs.
0296   Tile,
0297   /// 'gang' clause, allowed on 'loop' and Combined constructs.
0298   Gang,
0299   /// 'wait' clause, allowed on Compute, Data, 'update', and Combined
0300   /// constructs.
0301   Wait,
0302 
0303   /// Represents an invalid clause, for the purposes of parsing.
0304   Invalid,
0305 };
0306 
0307 template <typename StreamTy>
0308 inline StreamTy &printOpenACCClauseKind(StreamTy &Out, OpenACCClauseKind K) {
0309   switch (K) {
0310   case OpenACCClauseKind::Finalize:
0311     return Out << "finalize";
0312 
0313   case OpenACCClauseKind::IfPresent:
0314     return Out << "if_present";
0315 
0316   case OpenACCClauseKind::Seq:
0317     return Out << "seq";
0318 
0319   case OpenACCClauseKind::Independent:
0320     return Out << "independent";
0321 
0322   case OpenACCClauseKind::Auto:
0323     return Out << "auto";
0324 
0325   case OpenACCClauseKind::Worker:
0326     return Out << "worker";
0327 
0328   case OpenACCClauseKind::Vector:
0329     return Out << "vector";
0330 
0331   case OpenACCClauseKind::NoHost:
0332     return Out << "nohost";
0333 
0334   case OpenACCClauseKind::Default:
0335     return Out << "default";
0336 
0337   case OpenACCClauseKind::If:
0338     return Out << "if";
0339 
0340   case OpenACCClauseKind::Self:
0341     return Out << "self";
0342 
0343   case OpenACCClauseKind::Copy:
0344     return Out << "copy";
0345 
0346   case OpenACCClauseKind::PCopy:
0347     return Out << "pcopy";
0348 
0349   case OpenACCClauseKind::PresentOrCopy:
0350     return Out << "present_or_copy";
0351 
0352   case OpenACCClauseKind::UseDevice:
0353     return Out << "use_device";
0354 
0355   case OpenACCClauseKind::Attach:
0356     return Out << "attach";
0357 
0358   case OpenACCClauseKind::Delete:
0359     return Out << "delete";
0360 
0361   case OpenACCClauseKind::Detach:
0362     return Out << "detach";
0363 
0364   case OpenACCClauseKind::Device:
0365     return Out << "device";
0366 
0367   case OpenACCClauseKind::DevicePtr:
0368     return Out << "deviceptr";
0369 
0370   case OpenACCClauseKind::DeviceResident:
0371     return Out << "device_resident";
0372 
0373   case OpenACCClauseKind::FirstPrivate:
0374     return Out << "firstprivate";
0375 
0376   case OpenACCClauseKind::Host:
0377     return Out << "host";
0378 
0379   case OpenACCClauseKind::Link:
0380     return Out << "link";
0381 
0382   case OpenACCClauseKind::NoCreate:
0383     return Out << "no_create";
0384 
0385   case OpenACCClauseKind::Present:
0386     return Out << "present";
0387 
0388   case OpenACCClauseKind::Private:
0389     return Out << "private";
0390 
0391   case OpenACCClauseKind::CopyOut:
0392     return Out << "copyout";
0393 
0394   case OpenACCClauseKind::PCopyOut:
0395     return Out << "pcopyout";
0396 
0397   case OpenACCClauseKind::PresentOrCopyOut:
0398     return Out << "present_or_copyout";
0399 
0400   case OpenACCClauseKind::CopyIn:
0401     return Out << "copyin";
0402 
0403   case OpenACCClauseKind::PCopyIn:
0404     return Out << "pcopyin";
0405 
0406   case OpenACCClauseKind::PresentOrCopyIn:
0407     return Out << "present_or_copyin";
0408 
0409   case OpenACCClauseKind::Create:
0410     return Out << "create";
0411 
0412   case OpenACCClauseKind::PCreate:
0413     return Out << "pcreate";
0414 
0415   case OpenACCClauseKind::PresentOrCreate:
0416     return Out << "present_or_create";
0417 
0418   case OpenACCClauseKind::Reduction:
0419     return Out << "reduction";
0420 
0421   case OpenACCClauseKind::Collapse:
0422     return Out << "collapse";
0423 
0424   case OpenACCClauseKind::Bind:
0425     return Out << "bind";
0426 
0427   case OpenACCClauseKind::VectorLength:
0428     return Out << "vector_length";
0429 
0430   case OpenACCClauseKind::NumGangs:
0431     return Out << "num_gangs";
0432 
0433   case OpenACCClauseKind::NumWorkers:
0434     return Out << "num_workers";
0435 
0436   case OpenACCClauseKind::DeviceNum:
0437     return Out << "device_num";
0438 
0439   case OpenACCClauseKind::DefaultAsync:
0440     return Out << "default_async";
0441 
0442   case OpenACCClauseKind::DeviceType:
0443     return Out << "device_type";
0444 
0445   case OpenACCClauseKind::DType:
0446     return Out << "dtype";
0447 
0448   case OpenACCClauseKind::Async:
0449     return Out << "async";
0450 
0451   case OpenACCClauseKind::Tile:
0452     return Out << "tile";
0453 
0454   case OpenACCClauseKind::Gang:
0455     return Out << "gang";
0456 
0457   case OpenACCClauseKind::Wait:
0458     return Out << "wait";
0459 
0460   case OpenACCClauseKind::Invalid:
0461     return Out << "<invalid>";
0462   }
0463   llvm_unreachable("Uncovered clause kind");
0464 }
0465 
0466 inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &Out,
0467                                              OpenACCClauseKind K) {
0468   return printOpenACCClauseKind(Out, K);
0469 }
0470 
0471 inline llvm::raw_ostream &operator<<(llvm::raw_ostream &Out,
0472                                      OpenACCClauseKind K) {
0473   return printOpenACCClauseKind(Out, K);
0474 }
0475 
0476 enum class OpenACCDefaultClauseKind : uint8_t {
0477   /// 'none' option.
0478   None,
0479   /// 'present' option.
0480   Present,
0481   /// Not a valid option.
0482   Invalid,
0483 };
0484 
0485 template <typename StreamTy>
0486 inline StreamTy &printOpenACCDefaultClauseKind(StreamTy &Out,
0487                                                OpenACCDefaultClauseKind K) {
0488   switch (K) {
0489   case OpenACCDefaultClauseKind::None:
0490     return Out << "none";
0491   case OpenACCDefaultClauseKind::Present:
0492     return Out << "present";
0493   case OpenACCDefaultClauseKind::Invalid:
0494     return Out << "<invalid>";
0495   }
0496   llvm_unreachable("Unknown OpenACCDefaultClauseKind enum");
0497 }
0498 
0499 inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &Out,
0500                                              OpenACCDefaultClauseKind K) {
0501   return printOpenACCDefaultClauseKind(Out, K);
0502 }
0503 
0504 inline llvm::raw_ostream &operator<<(llvm::raw_ostream &Out,
0505                                      OpenACCDefaultClauseKind K) {
0506   return printOpenACCDefaultClauseKind(Out, K);
0507 }
0508 
0509 enum class OpenACCReductionOperator : uint8_t {
0510   /// '+'.
0511   Addition,
0512   /// '*'.
0513   Multiplication,
0514   /// 'max'.
0515   Max,
0516   /// 'min'.
0517   Min,
0518   /// '&'.
0519   BitwiseAnd,
0520   /// '|'.
0521   BitwiseOr,
0522   /// '^'.
0523   BitwiseXOr,
0524   /// '&&'.
0525   And,
0526   /// '||'.
0527   Or,
0528   /// Invalid Reduction Clause Kind.
0529   Invalid,
0530 };
0531 
0532 template <typename StreamTy>
0533 inline StreamTy &printOpenACCReductionOperator(StreamTy &Out,
0534                                                OpenACCReductionOperator Op) {
0535   switch (Op) {
0536   case OpenACCReductionOperator::Addition:
0537     return Out << "+";
0538   case OpenACCReductionOperator::Multiplication:
0539     return Out << "*";
0540   case OpenACCReductionOperator::Max:
0541     return Out << "max";
0542   case OpenACCReductionOperator::Min:
0543     return Out << "min";
0544   case OpenACCReductionOperator::BitwiseAnd:
0545     return Out << "&";
0546   case OpenACCReductionOperator::BitwiseOr:
0547     return Out << "|";
0548   case OpenACCReductionOperator::BitwiseXOr:
0549     return Out << "^";
0550   case OpenACCReductionOperator::And:
0551     return Out << "&&";
0552   case OpenACCReductionOperator::Or:
0553     return Out << "||";
0554   case OpenACCReductionOperator::Invalid:
0555     return Out << "<invalid>";
0556   }
0557   llvm_unreachable("Unknown reduction operator kind");
0558 }
0559 inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &Out,
0560                                              OpenACCReductionOperator Op) {
0561   return printOpenACCReductionOperator(Out, Op);
0562 }
0563 inline llvm::raw_ostream &operator<<(llvm::raw_ostream &Out,
0564                                      OpenACCReductionOperator Op) {
0565   return printOpenACCReductionOperator(Out, Op);
0566 }
0567 
0568 enum class OpenACCGangKind : uint8_t {
0569   /// num:
0570   Num,
0571   /// dim:
0572   Dim,
0573   /// static:
0574   Static
0575 };
0576 
0577 template <typename StreamTy>
0578 inline StreamTy &printOpenACCGangKind(StreamTy &Out, OpenACCGangKind GK) {
0579   switch (GK) {
0580   case OpenACCGangKind::Num:
0581     return Out << "num";
0582   case OpenACCGangKind::Dim:
0583     return Out << "dim";
0584   case OpenACCGangKind::Static:
0585     return Out << "static";
0586   }
0587   llvm_unreachable("unknown gang kind");
0588 }
0589 inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &Out,
0590                                              OpenACCGangKind Op) {
0591   return printOpenACCGangKind(Out, Op);
0592 }
0593 inline llvm::raw_ostream &operator<<(llvm::raw_ostream &Out,
0594                                      OpenACCGangKind Op) {
0595   return printOpenACCGangKind(Out, Op);
0596 }
0597 } // namespace clang
0598 
0599 #endif // LLVM_CLANG_BASIC_OPENACCKINDS_H