clang API Documentation

OpenMPKinds.cpp
Go to the documentation of this file.
00001 //===--- OpenMPKinds.cpp - Token Kinds Support ----------------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 /// \file
00010 /// \brief This file implements the OpenMP enum and support functions.
00011 ///
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "clang/Basic/OpenMPKinds.h"
00015 #include "clang/Basic/IdentifierTable.h"
00016 #include "llvm/ADT/StringRef.h"
00017 #include "llvm/ADT/StringSwitch.h"
00018 #include "llvm/Support/ErrorHandling.h"
00019 #include <cassert>
00020 
00021 using namespace clang;
00022 
00023 OpenMPDirectiveKind clang::getOpenMPDirectiveKind(StringRef Str) {
00024   return llvm::StringSwitch<OpenMPDirectiveKind>(Str)
00025 #define OPENMP_DIRECTIVE(Name) .Case(#Name, OMPD_##Name)
00026 #define OPENMP_DIRECTIVE_EXT(Name, Str) .Case(Str, OMPD_##Name)
00027 #include "clang/Basic/OpenMPKinds.def"
00028       .Default(OMPD_unknown);
00029 }
00030 
00031 const char *clang::getOpenMPDirectiveName(OpenMPDirectiveKind Kind) {
00032   assert(Kind <= OMPD_unknown);
00033   switch (Kind) {
00034   case OMPD_unknown:
00035     return "unknown";
00036 #define OPENMP_DIRECTIVE(Name)                                                 \
00037   case OMPD_##Name:                                                            \
00038     return #Name;
00039 #define OPENMP_DIRECTIVE_EXT(Name, Str)                                        \
00040   case OMPD_##Name:                                                            \
00041     return Str;
00042 #include "clang/Basic/OpenMPKinds.def"
00043     break;
00044   }
00045   llvm_unreachable("Invalid OpenMP directive kind");
00046 }
00047 
00048 OpenMPClauseKind clang::getOpenMPClauseKind(StringRef Str) {
00049   // 'flush' clause cannot be specified explicitly, because this is an implicit
00050   // clause for 'flush' directive. If the 'flush' clause is explicitly specified
00051   // the Parser should generate a warning about extra tokens at the end of the
00052   // directive.
00053   if (Str == "flush")
00054     return OMPC_unknown;
00055   return llvm::StringSwitch<OpenMPClauseKind>(Str)
00056 #define OPENMP_CLAUSE(Name, Class) .Case(#Name, OMPC_##Name)
00057 #include "clang/Basic/OpenMPKinds.def"
00058       .Default(OMPC_unknown);
00059 }
00060 
00061 const char *clang::getOpenMPClauseName(OpenMPClauseKind Kind) {
00062   assert(Kind <= OMPC_unknown);
00063   switch (Kind) {
00064   case OMPC_unknown:
00065     return "unknown";
00066 #define OPENMP_CLAUSE(Name, Class)                                             \
00067   case OMPC_##Name:                                                            \
00068     return #Name;
00069 #include "clang/Basic/OpenMPKinds.def"
00070   case OMPC_threadprivate:
00071     return "threadprivate or thread local";
00072   }
00073   llvm_unreachable("Invalid OpenMP clause kind");
00074 }
00075 
00076 unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind,
00077                                           StringRef Str) {
00078   switch (Kind) {
00079   case OMPC_default:
00080     return llvm::StringSwitch<OpenMPDefaultClauseKind>(Str)
00081 #define OPENMP_DEFAULT_KIND(Name) .Case(#Name, OMPC_DEFAULT_##Name)
00082 #include "clang/Basic/OpenMPKinds.def"
00083         .Default(OMPC_DEFAULT_unknown);
00084   case OMPC_proc_bind:
00085     return llvm::StringSwitch<OpenMPProcBindClauseKind>(Str)
00086 #define OPENMP_PROC_BIND_KIND(Name) .Case(#Name, OMPC_PROC_BIND_##Name)
00087 #include "clang/Basic/OpenMPKinds.def"
00088         .Default(OMPC_PROC_BIND_unknown);
00089   case OMPC_schedule:
00090     return llvm::StringSwitch<OpenMPScheduleClauseKind>(Str)
00091 #define OPENMP_SCHEDULE_KIND(Name) .Case(#Name, OMPC_SCHEDULE_##Name)
00092 #include "clang/Basic/OpenMPKinds.def"
00093         .Default(OMPC_SCHEDULE_unknown);
00094   case OMPC_unknown:
00095   case OMPC_threadprivate:
00096   case OMPC_if:
00097   case OMPC_final:
00098   case OMPC_num_threads:
00099   case OMPC_safelen:
00100   case OMPC_collapse:
00101   case OMPC_private:
00102   case OMPC_firstprivate:
00103   case OMPC_lastprivate:
00104   case OMPC_shared:
00105   case OMPC_reduction:
00106   case OMPC_linear:
00107   case OMPC_aligned:
00108   case OMPC_copyin:
00109   case OMPC_copyprivate:
00110   case OMPC_ordered:
00111   case OMPC_nowait:
00112   case OMPC_untied:
00113   case OMPC_mergeable:
00114   case OMPC_flush:
00115   case OMPC_read:
00116   case OMPC_write:
00117   case OMPC_update:
00118   case OMPC_capture:
00119   case OMPC_seq_cst:
00120     break;
00121   }
00122   llvm_unreachable("Invalid OpenMP simple clause kind");
00123 }
00124 
00125 const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
00126                                                  unsigned Type) {
00127   switch (Kind) {
00128   case OMPC_default:
00129     switch (Type) {
00130     case OMPC_DEFAULT_unknown:
00131       return "unknown";
00132 #define OPENMP_DEFAULT_KIND(Name)                                              \
00133   case OMPC_DEFAULT_##Name:                                                    \
00134     return #Name;
00135 #include "clang/Basic/OpenMPKinds.def"
00136     }
00137     llvm_unreachable("Invalid OpenMP 'default' clause type");
00138   case OMPC_proc_bind:
00139     switch (Type) {
00140     case OMPC_PROC_BIND_unknown:
00141       return "unknown";
00142 #define OPENMP_PROC_BIND_KIND(Name)                                            \
00143   case OMPC_PROC_BIND_##Name:                                                  \
00144     return #Name;
00145 #include "clang/Basic/OpenMPKinds.def"
00146     }
00147     llvm_unreachable("Invalid OpenMP 'proc_bind' clause type");
00148   case OMPC_schedule:
00149     switch (Type) {
00150     case OMPC_SCHEDULE_unknown:
00151       return "unknown";
00152 #define OPENMP_SCHEDULE_KIND(Name)                                             \
00153   case OMPC_SCHEDULE_##Name:                                                   \
00154     return #Name;
00155 #include "clang/Basic/OpenMPKinds.def"
00156     }
00157     llvm_unreachable("Invalid OpenMP 'schedule' clause type");
00158   case OMPC_unknown:
00159   case OMPC_threadprivate:
00160   case OMPC_if:
00161   case OMPC_final:
00162   case OMPC_num_threads:
00163   case OMPC_safelen:
00164   case OMPC_collapse:
00165   case OMPC_private:
00166   case OMPC_firstprivate:
00167   case OMPC_lastprivate:
00168   case OMPC_shared:
00169   case OMPC_reduction:
00170   case OMPC_linear:
00171   case OMPC_aligned:
00172   case OMPC_copyin:
00173   case OMPC_copyprivate:
00174   case OMPC_ordered:
00175   case OMPC_nowait:
00176   case OMPC_untied:
00177   case OMPC_mergeable:
00178   case OMPC_flush:
00179   case OMPC_read:
00180   case OMPC_write:
00181   case OMPC_update:
00182   case OMPC_capture:
00183   case OMPC_seq_cst:
00184     break;
00185   }
00186   llvm_unreachable("Invalid OpenMP simple clause kind");
00187 }
00188 
00189 bool clang::isAllowedClauseForDirective(OpenMPDirectiveKind DKind,
00190                                         OpenMPClauseKind CKind) {
00191   assert(DKind <= OMPD_unknown);
00192   assert(CKind <= OMPC_unknown);
00193   switch (DKind) {
00194   case OMPD_parallel:
00195     switch (CKind) {
00196 #define OPENMP_PARALLEL_CLAUSE(Name)                                           \
00197   case OMPC_##Name:                                                            \
00198     return true;
00199 #include "clang/Basic/OpenMPKinds.def"
00200     default:
00201       break;
00202     }
00203     break;
00204   case OMPD_simd:
00205     switch (CKind) {
00206 #define OPENMP_SIMD_CLAUSE(Name)                                               \
00207   case OMPC_##Name:                                                            \
00208     return true;
00209 #include "clang/Basic/OpenMPKinds.def"
00210     default:
00211       break;
00212     }
00213     break;
00214   case OMPD_for:
00215     switch (CKind) {
00216 #define OPENMP_FOR_CLAUSE(Name)                                                \
00217   case OMPC_##Name:                                                            \
00218     return true;
00219 #include "clang/Basic/OpenMPKinds.def"
00220     default:
00221       break;
00222     }
00223     break;
00224   case OMPD_for_simd:
00225     switch (CKind) {
00226 #define OPENMP_FOR_SIMD_CLAUSE(Name)                                           \
00227   case OMPC_##Name:                                                            \
00228     return true;
00229 #include "clang/Basic/OpenMPKinds.def"
00230     default:
00231       break;
00232     }
00233     break;
00234   case OMPD_sections:
00235     switch (CKind) {
00236 #define OPENMP_SECTIONS_CLAUSE(Name)                                           \
00237   case OMPC_##Name:                                                            \
00238     return true;
00239 #include "clang/Basic/OpenMPKinds.def"
00240     default:
00241       break;
00242     }
00243     break;
00244   case OMPD_single:
00245     switch (CKind) {
00246 #define OPENMP_SINGLE_CLAUSE(Name)                                             \
00247   case OMPC_##Name:                                                            \
00248     return true;
00249 #include "clang/Basic/OpenMPKinds.def"
00250     default:
00251       break;
00252     }
00253     break;
00254   case OMPD_parallel_for:
00255     switch (CKind) {
00256 #define OPENMP_PARALLEL_FOR_CLAUSE(Name)                                       \
00257   case OMPC_##Name:                                                            \
00258     return true;
00259 #include "clang/Basic/OpenMPKinds.def"
00260     default:
00261       break;
00262     }
00263     break;
00264   case OMPD_parallel_for_simd:
00265     switch (CKind) {
00266 #define OPENMP_PARALLEL_FOR_SIMD_CLAUSE(Name)                                  \
00267   case OMPC_##Name:                                                            \
00268     return true;
00269 #include "clang/Basic/OpenMPKinds.def"
00270     default:
00271       break;
00272     }
00273     break;
00274   case OMPD_parallel_sections:
00275     switch (CKind) {
00276 #define OPENMP_PARALLEL_SECTIONS_CLAUSE(Name)                                  \
00277   case OMPC_##Name:                                                            \
00278     return true;
00279 #include "clang/Basic/OpenMPKinds.def"
00280     default:
00281       break;
00282     }
00283     break;
00284   case OMPD_task:
00285     switch (CKind) {
00286 #define OPENMP_TASK_CLAUSE(Name)                                               \
00287   case OMPC_##Name:                                                            \
00288     return true;
00289 #include "clang/Basic/OpenMPKinds.def"
00290     default:
00291       break;
00292     }
00293     break;
00294   case OMPD_flush:
00295     return CKind == OMPC_flush;
00296     break;
00297   case OMPD_atomic:
00298     switch (CKind) {
00299 #define OPENMP_ATOMIC_CLAUSE(Name)                                             \
00300   case OMPC_##Name:                                                            \
00301     return true;
00302 #include "clang/Basic/OpenMPKinds.def"
00303     default:
00304       break;
00305     }
00306     break;
00307   case OMPD_target:
00308     switch (CKind) {
00309 #define OPENMP_TARGET_CLAUSE(Name)                                             \
00310   case OMPC_##Name:                                                            \
00311     return true;
00312 #include "clang/Basic/OpenMPKinds.def"
00313     default:
00314       break;
00315     }
00316     break;
00317   case OMPD_teams:
00318     switch (CKind) {
00319 #define OPENMP_TEAMS_CLAUSE(Name)                                              \
00320   case OMPC_##Name:                                                            \
00321     return true;
00322 #include "clang/Basic/OpenMPKinds.def"
00323     default:
00324       break;
00325     }
00326     break;
00327   case OMPD_unknown:
00328   case OMPD_threadprivate:
00329   case OMPD_section:
00330   case OMPD_master:
00331   case OMPD_critical:
00332   case OMPD_taskyield:
00333   case OMPD_barrier:
00334   case OMPD_taskwait:
00335   case OMPD_ordered:
00336     break;
00337   }
00338   return false;
00339 }
00340 
00341 bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
00342   return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
00343          DKind == OMPD_parallel_for ||
00344          DKind == OMPD_parallel_for_simd; // TODO add next directives.
00345 }
00346 
00347 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
00348   return DKind == OMPD_for || DKind == OMPD_for_simd ||
00349          DKind == OMPD_sections || DKind == OMPD_section ||
00350          DKind == OMPD_single || DKind == OMPD_parallel_for ||
00351          DKind == OMPD_parallel_for_simd ||
00352          DKind == OMPD_parallel_sections; // TODO add next directives.
00353 }
00354 
00355 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
00356   return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
00357          DKind == OMPD_parallel_for_simd ||
00358          DKind == OMPD_parallel_sections; // TODO add next directives.
00359 }
00360 
00361 bool clang::isOpenMPTeamsDirective(OpenMPDirectiveKind DKind) {
00362   return DKind == OMPD_teams; // TODO add next directives.
00363 }
00364 
00365 bool clang::isOpenMPSimdDirective(OpenMPDirectiveKind DKind) {
00366   return DKind == OMPD_simd || DKind == OMPD_for_simd ||
00367          DKind == OMPD_parallel_for_simd; // TODO add next directives.
00368 }
00369 
00370 bool clang::isOpenMPPrivate(OpenMPClauseKind Kind) {
00371   return Kind == OMPC_private || Kind == OMPC_firstprivate ||
00372          Kind == OMPC_lastprivate || Kind == OMPC_linear ||
00373          Kind == OMPC_reduction; // TODO add next clauses like 'reduction'.
00374 }
00375 
00376 bool clang::isOpenMPThreadPrivate(OpenMPClauseKind Kind) {
00377   return Kind == OMPC_threadprivate ||
00378          Kind == OMPC_copyin; // TODO add next clauses like 'copyprivate'.
00379 }
00380