OpenMPKinds.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. //===--- OpenMPKinds.cpp - Token Kinds Support ----------------------------===//
  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. /// \file
  9. /// This file implements the OpenMP enum and support functions.
  10. ///
  11. //===----------------------------------------------------------------------===//
  12. #include "clang/Basic/OpenMPKinds.h"
  13. #include "clang/Basic/IdentifierTable.h"
  14. #include "llvm/ADT/StringRef.h"
  15. #include "llvm/ADT/StringSwitch.h"
  16. #include "llvm/Support/ErrorHandling.h"
  17. #include <cassert>
  18. using namespace clang;
  19. using namespace llvm::omp;
  20. unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, StringRef Str,
  21. const LangOptions &LangOpts) {
  22. switch (Kind) {
  23. case OMPC_default:
  24. return llvm::StringSwitch<unsigned>(Str)
  25. #define OMP_DEFAULT_KIND(Enum, Name) .Case(Name, unsigned(Enum))
  26. #include "llvm/Frontend/OpenMP/OMPKinds.def"
  27. .Default(unsigned(llvm::omp::OMP_DEFAULT_unknown));
  28. case OMPC_proc_bind:
  29. return llvm::StringSwitch<unsigned>(Str)
  30. #define OMP_PROC_BIND_KIND(Enum, Name, Value) .Case(Name, Value)
  31. #include "llvm/Frontend/OpenMP/OMPKinds.def"
  32. .Default(unsigned(llvm::omp::OMP_PROC_BIND_unknown));
  33. case OMPC_schedule:
  34. return llvm::StringSwitch<unsigned>(Str)
  35. #define OPENMP_SCHEDULE_KIND(Name) \
  36. .Case(#Name, static_cast<unsigned>(OMPC_SCHEDULE_##Name))
  37. #define OPENMP_SCHEDULE_MODIFIER(Name) \
  38. .Case(#Name, static_cast<unsigned>(OMPC_SCHEDULE_MODIFIER_##Name))
  39. #include "clang/Basic/OpenMPKinds.def"
  40. .Default(OMPC_SCHEDULE_unknown);
  41. case OMPC_depend:
  42. return llvm::StringSwitch<OpenMPDependClauseKind>(Str)
  43. #define OPENMP_DEPEND_KIND(Name) .Case(#Name, OMPC_DEPEND_##Name)
  44. #include "clang/Basic/OpenMPKinds.def"
  45. .Default(OMPC_DEPEND_unknown);
  46. case OMPC_linear:
  47. return llvm::StringSwitch<OpenMPLinearClauseKind>(Str)
  48. #define OPENMP_LINEAR_KIND(Name) .Case(#Name, OMPC_LINEAR_##Name)
  49. #include "clang/Basic/OpenMPKinds.def"
  50. .Default(OMPC_LINEAR_unknown);
  51. case OMPC_map: {
  52. unsigned Type = llvm::StringSwitch<unsigned>(Str)
  53. #define OPENMP_MAP_KIND(Name) \
  54. .Case(#Name, static_cast<unsigned>(OMPC_MAP_##Name))
  55. #define OPENMP_MAP_MODIFIER_KIND(Name) \
  56. .Case(#Name, static_cast<unsigned>(OMPC_MAP_MODIFIER_##Name))
  57. #include "clang/Basic/OpenMPKinds.def"
  58. .Default(OMPC_MAP_unknown);
  59. if (LangOpts.OpenMP < 51 && Type == OMPC_MAP_MODIFIER_present)
  60. return OMPC_MAP_MODIFIER_unknown;
  61. if (!LangOpts.OpenMPExtensions && Type == OMPC_MAP_MODIFIER_ompx_hold)
  62. return OMPC_MAP_MODIFIER_unknown;
  63. return Type;
  64. }
  65. case OMPC_to:
  66. case OMPC_from: {
  67. unsigned Type = llvm::StringSwitch<unsigned>(Str)
  68. #define OPENMP_MOTION_MODIFIER_KIND(Name) \
  69. .Case(#Name, static_cast<unsigned>(OMPC_MOTION_MODIFIER_##Name))
  70. #include "clang/Basic/OpenMPKinds.def"
  71. .Default(OMPC_MOTION_MODIFIER_unknown);
  72. if (LangOpts.OpenMP < 51 && Type == OMPC_MOTION_MODIFIER_present)
  73. return OMPC_MOTION_MODIFIER_unknown;
  74. return Type;
  75. }
  76. case OMPC_dist_schedule:
  77. return llvm::StringSwitch<OpenMPDistScheduleClauseKind>(Str)
  78. #define OPENMP_DIST_SCHEDULE_KIND(Name) .Case(#Name, OMPC_DIST_SCHEDULE_##Name)
  79. #include "clang/Basic/OpenMPKinds.def"
  80. .Default(OMPC_DIST_SCHEDULE_unknown);
  81. case OMPC_defaultmap:
  82. return llvm::StringSwitch<unsigned>(Str)
  83. #define OPENMP_DEFAULTMAP_KIND(Name) \
  84. .Case(#Name, static_cast<unsigned>(OMPC_DEFAULTMAP_##Name))
  85. #define OPENMP_DEFAULTMAP_MODIFIER(Name) \
  86. .Case(#Name, static_cast<unsigned>(OMPC_DEFAULTMAP_MODIFIER_##Name))
  87. #include "clang/Basic/OpenMPKinds.def"
  88. .Default(OMPC_DEFAULTMAP_unknown);
  89. case OMPC_atomic_default_mem_order:
  90. return llvm::StringSwitch<OpenMPAtomicDefaultMemOrderClauseKind>(Str)
  91. #define OPENMP_ATOMIC_DEFAULT_MEM_ORDER_KIND(Name) \
  92. .Case(#Name, OMPC_ATOMIC_DEFAULT_MEM_ORDER_##Name)
  93. #include "clang/Basic/OpenMPKinds.def"
  94. .Default(OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown);
  95. case OMPC_device_type:
  96. return llvm::StringSwitch<OpenMPDeviceType>(Str)
  97. #define OPENMP_DEVICE_TYPE_KIND(Name) .Case(#Name, OMPC_DEVICE_TYPE_##Name)
  98. #include "clang/Basic/OpenMPKinds.def"
  99. .Default(OMPC_DEVICE_TYPE_unknown);
  100. case OMPC_lastprivate:
  101. return llvm::StringSwitch<OpenMPLastprivateModifier>(Str)
  102. #define OPENMP_LASTPRIVATE_KIND(Name) .Case(#Name, OMPC_LASTPRIVATE_##Name)
  103. #include "clang/Basic/OpenMPKinds.def"
  104. .Default(OMPC_LASTPRIVATE_unknown);
  105. case OMPC_order:
  106. return llvm::StringSwitch<OpenMPOrderClauseKind>(Str)
  107. #define OPENMP_ORDER_KIND(Name) .Case(#Name, OMPC_ORDER_##Name)
  108. #include "clang/Basic/OpenMPKinds.def"
  109. .Default(OMPC_ORDER_unknown);
  110. case OMPC_update:
  111. return llvm::StringSwitch<OpenMPDependClauseKind>(Str)
  112. #define OPENMP_DEPEND_KIND(Name) .Case(#Name, OMPC_DEPEND_##Name)
  113. #include "clang/Basic/OpenMPKinds.def"
  114. .Default(OMPC_DEPEND_unknown);
  115. case OMPC_device:
  116. return llvm::StringSwitch<OpenMPDeviceClauseModifier>(Str)
  117. #define OPENMP_DEVICE_MODIFIER(Name) .Case(#Name, OMPC_DEVICE_##Name)
  118. #include "clang/Basic/OpenMPKinds.def"
  119. .Default(OMPC_DEVICE_unknown);
  120. case OMPC_reduction:
  121. return llvm::StringSwitch<OpenMPReductionClauseModifier>(Str)
  122. #define OPENMP_REDUCTION_MODIFIER(Name) .Case(#Name, OMPC_REDUCTION_##Name)
  123. #include "clang/Basic/OpenMPKinds.def"
  124. .Default(OMPC_REDUCTION_unknown);
  125. case OMPC_adjust_args:
  126. return llvm::StringSwitch<OpenMPAdjustArgsOpKind>(Str)
  127. #define OPENMP_ADJUST_ARGS_KIND(Name) .Case(#Name, OMPC_ADJUST_ARGS_##Name)
  128. #include "clang/Basic/OpenMPKinds.def"
  129. .Default(OMPC_ADJUST_ARGS_unknown);
  130. case OMPC_bind:
  131. return llvm::StringSwitch<unsigned>(Str)
  132. #define OPENMP_BIND_KIND(Name) .Case(#Name, OMPC_BIND_##Name)
  133. #include "clang/Basic/OpenMPKinds.def"
  134. .Default(OMPC_BIND_unknown);
  135. case OMPC_unknown:
  136. case OMPC_threadprivate:
  137. case OMPC_if:
  138. case OMPC_final:
  139. case OMPC_num_threads:
  140. case OMPC_safelen:
  141. case OMPC_simdlen:
  142. case OMPC_sizes:
  143. case OMPC_allocator:
  144. case OMPC_allocate:
  145. case OMPC_collapse:
  146. case OMPC_private:
  147. case OMPC_firstprivate:
  148. case OMPC_shared:
  149. case OMPC_task_reduction:
  150. case OMPC_in_reduction:
  151. case OMPC_aligned:
  152. case OMPC_copyin:
  153. case OMPC_copyprivate:
  154. case OMPC_ordered:
  155. case OMPC_nowait:
  156. case OMPC_untied:
  157. case OMPC_mergeable:
  158. case OMPC_flush:
  159. case OMPC_depobj:
  160. case OMPC_read:
  161. case OMPC_write:
  162. case OMPC_capture:
  163. case OMPC_compare:
  164. case OMPC_seq_cst:
  165. case OMPC_acq_rel:
  166. case OMPC_acquire:
  167. case OMPC_release:
  168. case OMPC_relaxed:
  169. case OMPC_threads:
  170. case OMPC_simd:
  171. case OMPC_num_teams:
  172. case OMPC_thread_limit:
  173. case OMPC_priority:
  174. case OMPC_grainsize:
  175. case OMPC_nogroup:
  176. case OMPC_num_tasks:
  177. case OMPC_hint:
  178. case OMPC_uniform:
  179. case OMPC_use_device_ptr:
  180. case OMPC_use_device_addr:
  181. case OMPC_is_device_ptr:
  182. case OMPC_unified_address:
  183. case OMPC_unified_shared_memory:
  184. case OMPC_reverse_offload:
  185. case OMPC_dynamic_allocators:
  186. case OMPC_match:
  187. case OMPC_nontemporal:
  188. case OMPC_destroy:
  189. case OMPC_novariants:
  190. case OMPC_nocontext:
  191. case OMPC_detach:
  192. case OMPC_inclusive:
  193. case OMPC_exclusive:
  194. case OMPC_uses_allocators:
  195. case OMPC_affinity:
  196. case OMPC_when:
  197. case OMPC_append_args:
  198. break;
  199. default:
  200. break;
  201. }
  202. llvm_unreachable("Invalid OpenMP simple clause kind");
  203. }
  204. const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
  205. unsigned Type) {
  206. switch (Kind) {
  207. case OMPC_default:
  208. switch (llvm::omp::DefaultKind(Type)) {
  209. #define OMP_DEFAULT_KIND(Enum, Name) \
  210. case Enum: \
  211. return Name;
  212. #include "llvm/Frontend/OpenMP/OMPKinds.def"
  213. }
  214. llvm_unreachable("Invalid OpenMP 'default' clause type");
  215. case OMPC_proc_bind:
  216. switch (Type) {
  217. #define OMP_PROC_BIND_KIND(Enum, Name, Value) \
  218. case Value: \
  219. return Name;
  220. #include "llvm/Frontend/OpenMP/OMPKinds.def"
  221. }
  222. llvm_unreachable("Invalid OpenMP 'proc_bind' clause type");
  223. case OMPC_schedule:
  224. switch (Type) {
  225. case OMPC_SCHEDULE_unknown:
  226. case OMPC_SCHEDULE_MODIFIER_last:
  227. return "unknown";
  228. #define OPENMP_SCHEDULE_KIND(Name) \
  229. case OMPC_SCHEDULE_##Name: \
  230. return #Name;
  231. #define OPENMP_SCHEDULE_MODIFIER(Name) \
  232. case OMPC_SCHEDULE_MODIFIER_##Name: \
  233. return #Name;
  234. #include "clang/Basic/OpenMPKinds.def"
  235. }
  236. llvm_unreachable("Invalid OpenMP 'schedule' clause type");
  237. case OMPC_depend:
  238. switch (Type) {
  239. case OMPC_DEPEND_unknown:
  240. return "unknown";
  241. #define OPENMP_DEPEND_KIND(Name) \
  242. case OMPC_DEPEND_##Name: \
  243. return #Name;
  244. #include "clang/Basic/OpenMPKinds.def"
  245. }
  246. llvm_unreachable("Invalid OpenMP 'depend' clause type");
  247. case OMPC_linear:
  248. switch (Type) {
  249. case OMPC_LINEAR_unknown:
  250. return "unknown";
  251. #define OPENMP_LINEAR_KIND(Name) \
  252. case OMPC_LINEAR_##Name: \
  253. return #Name;
  254. #include "clang/Basic/OpenMPKinds.def"
  255. }
  256. llvm_unreachable("Invalid OpenMP 'linear' clause type");
  257. case OMPC_map:
  258. switch (Type) {
  259. case OMPC_MAP_unknown:
  260. case OMPC_MAP_MODIFIER_last:
  261. return "unknown";
  262. #define OPENMP_MAP_KIND(Name) \
  263. case OMPC_MAP_##Name: \
  264. return #Name;
  265. #define OPENMP_MAP_MODIFIER_KIND(Name) \
  266. case OMPC_MAP_MODIFIER_##Name: \
  267. return #Name;
  268. #include "clang/Basic/OpenMPKinds.def"
  269. default:
  270. break;
  271. }
  272. llvm_unreachable("Invalid OpenMP 'map' clause type");
  273. case OMPC_to:
  274. case OMPC_from:
  275. switch (Type) {
  276. case OMPC_MOTION_MODIFIER_unknown:
  277. return "unknown";
  278. #define OPENMP_MOTION_MODIFIER_KIND(Name) \
  279. case OMPC_MOTION_MODIFIER_##Name: \
  280. return #Name;
  281. #include "clang/Basic/OpenMPKinds.def"
  282. default:
  283. break;
  284. }
  285. llvm_unreachable("Invalid OpenMP 'to' or 'from' clause type");
  286. case OMPC_dist_schedule:
  287. switch (Type) {
  288. case OMPC_DIST_SCHEDULE_unknown:
  289. return "unknown";
  290. #define OPENMP_DIST_SCHEDULE_KIND(Name) \
  291. case OMPC_DIST_SCHEDULE_##Name: \
  292. return #Name;
  293. #include "clang/Basic/OpenMPKinds.def"
  294. }
  295. llvm_unreachable("Invalid OpenMP 'dist_schedule' clause type");
  296. case OMPC_defaultmap:
  297. switch (Type) {
  298. case OMPC_DEFAULTMAP_unknown:
  299. case OMPC_DEFAULTMAP_MODIFIER_last:
  300. return "unknown";
  301. #define OPENMP_DEFAULTMAP_KIND(Name) \
  302. case OMPC_DEFAULTMAP_##Name: \
  303. return #Name;
  304. #define OPENMP_DEFAULTMAP_MODIFIER(Name) \
  305. case OMPC_DEFAULTMAP_MODIFIER_##Name: \
  306. return #Name;
  307. #include "clang/Basic/OpenMPKinds.def"
  308. }
  309. llvm_unreachable("Invalid OpenMP 'schedule' clause type");
  310. case OMPC_atomic_default_mem_order:
  311. switch (Type) {
  312. case OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown:
  313. return "unknown";
  314. #define OPENMP_ATOMIC_DEFAULT_MEM_ORDER_KIND(Name) \
  315. case OMPC_ATOMIC_DEFAULT_MEM_ORDER_##Name: \
  316. return #Name;
  317. #include "clang/Basic/OpenMPKinds.def"
  318. }
  319. llvm_unreachable("Invalid OpenMP 'atomic_default_mem_order' clause type");
  320. case OMPC_device_type:
  321. switch (Type) {
  322. case OMPC_DEVICE_TYPE_unknown:
  323. return "unknown";
  324. #define OPENMP_DEVICE_TYPE_KIND(Name) \
  325. case OMPC_DEVICE_TYPE_##Name: \
  326. return #Name;
  327. #include "clang/Basic/OpenMPKinds.def"
  328. }
  329. llvm_unreachable("Invalid OpenMP 'device_type' clause type");
  330. case OMPC_lastprivate:
  331. switch (Type) {
  332. case OMPC_LASTPRIVATE_unknown:
  333. return "unknown";
  334. #define OPENMP_LASTPRIVATE_KIND(Name) \
  335. case OMPC_LASTPRIVATE_##Name: \
  336. return #Name;
  337. #include "clang/Basic/OpenMPKinds.def"
  338. }
  339. llvm_unreachable("Invalid OpenMP 'lastprivate' clause type");
  340. case OMPC_order:
  341. switch (Type) {
  342. case OMPC_ORDER_unknown:
  343. return "unknown";
  344. #define OPENMP_ORDER_KIND(Name) \
  345. case OMPC_ORDER_##Name: \
  346. return #Name;
  347. #include "clang/Basic/OpenMPKinds.def"
  348. }
  349. llvm_unreachable("Invalid OpenMP 'order' clause type");
  350. case OMPC_update:
  351. switch (Type) {
  352. case OMPC_DEPEND_unknown:
  353. return "unknown";
  354. #define OPENMP_DEPEND_KIND(Name) \
  355. case OMPC_DEPEND_##Name: \
  356. return #Name;
  357. #include "clang/Basic/OpenMPKinds.def"
  358. }
  359. llvm_unreachable("Invalid OpenMP 'depend' clause type");
  360. case OMPC_device:
  361. switch (Type) {
  362. case OMPC_DEVICE_unknown:
  363. return "unknown";
  364. #define OPENMP_DEVICE_MODIFIER(Name) \
  365. case OMPC_DEVICE_##Name: \
  366. return #Name;
  367. #include "clang/Basic/OpenMPKinds.def"
  368. }
  369. llvm_unreachable("Invalid OpenMP 'device' clause modifier");
  370. case OMPC_reduction:
  371. switch (Type) {
  372. case OMPC_REDUCTION_unknown:
  373. return "unknown";
  374. #define OPENMP_REDUCTION_MODIFIER(Name) \
  375. case OMPC_REDUCTION_##Name: \
  376. return #Name;
  377. #include "clang/Basic/OpenMPKinds.def"
  378. }
  379. llvm_unreachable("Invalid OpenMP 'reduction' clause modifier");
  380. case OMPC_adjust_args:
  381. switch (Type) {
  382. case OMPC_ADJUST_ARGS_unknown:
  383. return "unknown";
  384. #define OPENMP_ADJUST_ARGS_KIND(Name) \
  385. case OMPC_ADJUST_ARGS_##Name: \
  386. return #Name;
  387. #include "clang/Basic/OpenMPKinds.def"
  388. }
  389. llvm_unreachable("Invalid OpenMP 'adjust_args' clause kind");
  390. case OMPC_bind:
  391. switch (Type) {
  392. case OMPC_BIND_unknown:
  393. return "unknown";
  394. #define OPENMP_BIND_KIND(Name) \
  395. case OMPC_BIND_##Name: \
  396. return #Name;
  397. #include "clang/Basic/OpenMPKinds.def"
  398. }
  399. llvm_unreachable("Invalid OpenMP 'bind' clause type");
  400. case OMPC_unknown:
  401. case OMPC_threadprivate:
  402. case OMPC_if:
  403. case OMPC_final:
  404. case OMPC_num_threads:
  405. case OMPC_safelen:
  406. case OMPC_simdlen:
  407. case OMPC_sizes:
  408. case OMPC_allocator:
  409. case OMPC_allocate:
  410. case OMPC_collapse:
  411. case OMPC_private:
  412. case OMPC_firstprivate:
  413. case OMPC_shared:
  414. case OMPC_task_reduction:
  415. case OMPC_in_reduction:
  416. case OMPC_aligned:
  417. case OMPC_copyin:
  418. case OMPC_copyprivate:
  419. case OMPC_ordered:
  420. case OMPC_nowait:
  421. case OMPC_untied:
  422. case OMPC_mergeable:
  423. case OMPC_flush:
  424. case OMPC_depobj:
  425. case OMPC_read:
  426. case OMPC_write:
  427. case OMPC_capture:
  428. case OMPC_compare:
  429. case OMPC_seq_cst:
  430. case OMPC_acq_rel:
  431. case OMPC_acquire:
  432. case OMPC_release:
  433. case OMPC_relaxed:
  434. case OMPC_threads:
  435. case OMPC_simd:
  436. case OMPC_num_teams:
  437. case OMPC_thread_limit:
  438. case OMPC_priority:
  439. case OMPC_grainsize:
  440. case OMPC_nogroup:
  441. case OMPC_num_tasks:
  442. case OMPC_hint:
  443. case OMPC_uniform:
  444. case OMPC_use_device_ptr:
  445. case OMPC_use_device_addr:
  446. case OMPC_is_device_ptr:
  447. case OMPC_unified_address:
  448. case OMPC_unified_shared_memory:
  449. case OMPC_reverse_offload:
  450. case OMPC_dynamic_allocators:
  451. case OMPC_match:
  452. case OMPC_nontemporal:
  453. case OMPC_destroy:
  454. case OMPC_detach:
  455. case OMPC_novariants:
  456. case OMPC_nocontext:
  457. case OMPC_inclusive:
  458. case OMPC_exclusive:
  459. case OMPC_uses_allocators:
  460. case OMPC_affinity:
  461. case OMPC_when:
  462. case OMPC_append_args:
  463. break;
  464. default:
  465. break;
  466. }
  467. llvm_unreachable("Invalid OpenMP simple clause kind");
  468. }
  469. bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
  470. return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
  471. DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
  472. DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
  473. DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
  474. DKind == OMPD_parallel_master_taskloop ||
  475. DKind == OMPD_parallel_master_taskloop_simd ||
  476. DKind == OMPD_distribute || DKind == OMPD_target_parallel_for ||
  477. DKind == OMPD_distribute_parallel_for ||
  478. DKind == OMPD_distribute_parallel_for_simd ||
  479. DKind == OMPD_distribute_simd ||
  480. DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
  481. DKind == OMPD_teams_distribute ||
  482. DKind == OMPD_teams_distribute_simd ||
  483. DKind == OMPD_teams_distribute_parallel_for_simd ||
  484. DKind == OMPD_teams_distribute_parallel_for ||
  485. DKind == OMPD_target_teams_distribute ||
  486. DKind == OMPD_target_teams_distribute_parallel_for ||
  487. DKind == OMPD_target_teams_distribute_parallel_for_simd ||
  488. DKind == OMPD_target_teams_distribute_simd || DKind == OMPD_tile ||
  489. DKind == OMPD_unroll || DKind == OMPD_loop;
  490. }
  491. bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
  492. return DKind == OMPD_for || DKind == OMPD_for_simd ||
  493. DKind == OMPD_sections || DKind == OMPD_section ||
  494. DKind == OMPD_single || DKind == OMPD_parallel_for ||
  495. DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
  496. DKind == OMPD_target_parallel_for ||
  497. DKind == OMPD_distribute_parallel_for ||
  498. DKind == OMPD_distribute_parallel_for_simd ||
  499. DKind == OMPD_target_parallel_for_simd ||
  500. DKind == OMPD_teams_distribute_parallel_for_simd ||
  501. DKind == OMPD_teams_distribute_parallel_for ||
  502. DKind == OMPD_target_teams_distribute_parallel_for ||
  503. DKind == OMPD_target_teams_distribute_parallel_for_simd;
  504. }
  505. bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
  506. return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
  507. DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
  508. DKind == OMPD_parallel_master_taskloop ||
  509. DKind == OMPD_parallel_master_taskloop_simd;
  510. }
  511. bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
  512. return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
  513. DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
  514. DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
  515. DKind == OMPD_distribute_parallel_for ||
  516. DKind == OMPD_distribute_parallel_for_simd ||
  517. DKind == OMPD_target_parallel_for_simd ||
  518. DKind == OMPD_teams_distribute_parallel_for ||
  519. DKind == OMPD_teams_distribute_parallel_for_simd ||
  520. DKind == OMPD_target_teams_distribute_parallel_for ||
  521. DKind == OMPD_target_teams_distribute_parallel_for_simd ||
  522. DKind == OMPD_parallel_master ||
  523. DKind == OMPD_parallel_master_taskloop ||
  524. DKind == OMPD_parallel_master_taskloop_simd;
  525. }
  526. bool clang::isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind) {
  527. return DKind == OMPD_target || DKind == OMPD_target_parallel ||
  528. DKind == OMPD_target_parallel_for ||
  529. DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
  530. DKind == OMPD_target_teams || DKind == OMPD_target_teams_distribute ||
  531. DKind == OMPD_target_teams_distribute_parallel_for ||
  532. DKind == OMPD_target_teams_distribute_parallel_for_simd ||
  533. DKind == OMPD_target_teams_distribute_simd;
  534. }
  535. bool clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
  536. return DKind == OMPD_target_data || DKind == OMPD_target_enter_data ||
  537. DKind == OMPD_target_exit_data || DKind == OMPD_target_update;
  538. }
  539. bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
  540. return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
  541. DKind == OMPD_teams_distribute_simd ||
  542. DKind == OMPD_teams_distribute_parallel_for_simd ||
  543. DKind == OMPD_teams_distribute_parallel_for;
  544. }
  545. bool clang::isOpenMPTeamsDirective(OpenMPDirectiveKind DKind) {
  546. return isOpenMPNestingTeamsDirective(DKind) ||
  547. DKind == OMPD_target_teams || DKind == OMPD_target_teams_distribute ||
  548. DKind == OMPD_target_teams_distribute_parallel_for ||
  549. DKind == OMPD_target_teams_distribute_parallel_for_simd ||
  550. DKind == OMPD_target_teams_distribute_simd;
  551. }
  552. bool clang::isOpenMPSimdDirective(OpenMPDirectiveKind DKind) {
  553. return DKind == OMPD_simd || DKind == OMPD_for_simd ||
  554. DKind == OMPD_parallel_for_simd || DKind == OMPD_taskloop_simd ||
  555. DKind == OMPD_master_taskloop_simd ||
  556. DKind == OMPD_parallel_master_taskloop_simd ||
  557. DKind == OMPD_distribute_parallel_for_simd ||
  558. DKind == OMPD_distribute_simd || DKind == OMPD_target_simd ||
  559. DKind == OMPD_teams_distribute_simd ||
  560. DKind == OMPD_teams_distribute_parallel_for_simd ||
  561. DKind == OMPD_target_teams_distribute_parallel_for_simd ||
  562. DKind == OMPD_target_teams_distribute_simd ||
  563. DKind == OMPD_target_parallel_for_simd;
  564. }
  565. bool clang::isOpenMPNestingDistributeDirective(OpenMPDirectiveKind Kind) {
  566. return Kind == OMPD_distribute || Kind == OMPD_distribute_parallel_for ||
  567. Kind == OMPD_distribute_parallel_for_simd ||
  568. Kind == OMPD_distribute_simd;
  569. // TODO add next directives.
  570. }
  571. bool clang::isOpenMPDistributeDirective(OpenMPDirectiveKind Kind) {
  572. return isOpenMPNestingDistributeDirective(Kind) ||
  573. Kind == OMPD_teams_distribute || Kind == OMPD_teams_distribute_simd ||
  574. Kind == OMPD_teams_distribute_parallel_for_simd ||
  575. Kind == OMPD_teams_distribute_parallel_for ||
  576. Kind == OMPD_target_teams_distribute ||
  577. Kind == OMPD_target_teams_distribute_parallel_for ||
  578. Kind == OMPD_target_teams_distribute_parallel_for_simd ||
  579. Kind == OMPD_target_teams_distribute_simd;
  580. }
  581. bool clang::isOpenMPGenericLoopDirective(OpenMPDirectiveKind Kind) {
  582. return Kind == OMPD_loop;
  583. }
  584. bool clang::isOpenMPPrivate(OpenMPClauseKind Kind) {
  585. return Kind == OMPC_private || Kind == OMPC_firstprivate ||
  586. Kind == OMPC_lastprivate || Kind == OMPC_linear ||
  587. Kind == OMPC_reduction || Kind == OMPC_task_reduction ||
  588. Kind == OMPC_in_reduction; // TODO add next clauses like 'reduction'.
  589. }
  590. bool clang::isOpenMPThreadPrivate(OpenMPClauseKind Kind) {
  591. return Kind == OMPC_threadprivate || Kind == OMPC_copyin;
  592. }
  593. bool clang::isOpenMPTaskingDirective(OpenMPDirectiveKind Kind) {
  594. return Kind == OMPD_task || isOpenMPTaskLoopDirective(Kind);
  595. }
  596. bool clang::isOpenMPLoopBoundSharingDirective(OpenMPDirectiveKind Kind) {
  597. return Kind == OMPD_distribute_parallel_for ||
  598. Kind == OMPD_distribute_parallel_for_simd ||
  599. Kind == OMPD_teams_distribute_parallel_for_simd ||
  600. Kind == OMPD_teams_distribute_parallel_for ||
  601. Kind == OMPD_target_teams_distribute_parallel_for ||
  602. Kind == OMPD_target_teams_distribute_parallel_for_simd;
  603. }
  604. bool clang::isOpenMPLoopTransformationDirective(OpenMPDirectiveKind DKind) {
  605. return DKind == OMPD_tile || DKind == OMPD_unroll;
  606. }
  607. void clang::getOpenMPCaptureRegions(
  608. SmallVectorImpl<OpenMPDirectiveKind> &CaptureRegions,
  609. OpenMPDirectiveKind DKind) {
  610. assert(unsigned(DKind) < llvm::omp::Directive_enumSize);
  611. switch (DKind) {
  612. case OMPD_metadirective:
  613. CaptureRegions.push_back(OMPD_metadirective);
  614. break;
  615. case OMPD_parallel:
  616. case OMPD_parallel_for:
  617. case OMPD_parallel_for_simd:
  618. case OMPD_parallel_master:
  619. case OMPD_parallel_sections:
  620. case OMPD_distribute_parallel_for:
  621. case OMPD_distribute_parallel_for_simd:
  622. CaptureRegions.push_back(OMPD_parallel);
  623. break;
  624. case OMPD_target_teams:
  625. case OMPD_target_teams_distribute:
  626. case OMPD_target_teams_distribute_simd:
  627. CaptureRegions.push_back(OMPD_task);
  628. CaptureRegions.push_back(OMPD_target);
  629. CaptureRegions.push_back(OMPD_teams);
  630. break;
  631. case OMPD_teams:
  632. case OMPD_teams_distribute:
  633. case OMPD_teams_distribute_simd:
  634. CaptureRegions.push_back(OMPD_teams);
  635. break;
  636. case OMPD_target:
  637. case OMPD_target_simd:
  638. CaptureRegions.push_back(OMPD_task);
  639. CaptureRegions.push_back(OMPD_target);
  640. break;
  641. case OMPD_teams_distribute_parallel_for:
  642. case OMPD_teams_distribute_parallel_for_simd:
  643. CaptureRegions.push_back(OMPD_teams);
  644. CaptureRegions.push_back(OMPD_parallel);
  645. break;
  646. case OMPD_target_parallel:
  647. case OMPD_target_parallel_for:
  648. case OMPD_target_parallel_for_simd:
  649. CaptureRegions.push_back(OMPD_task);
  650. CaptureRegions.push_back(OMPD_target);
  651. CaptureRegions.push_back(OMPD_parallel);
  652. break;
  653. case OMPD_task:
  654. case OMPD_target_enter_data:
  655. case OMPD_target_exit_data:
  656. case OMPD_target_update:
  657. CaptureRegions.push_back(OMPD_task);
  658. break;
  659. case OMPD_taskloop:
  660. case OMPD_taskloop_simd:
  661. case OMPD_master_taskloop:
  662. case OMPD_master_taskloop_simd:
  663. CaptureRegions.push_back(OMPD_taskloop);
  664. break;
  665. case OMPD_parallel_master_taskloop:
  666. case OMPD_parallel_master_taskloop_simd:
  667. CaptureRegions.push_back(OMPD_parallel);
  668. CaptureRegions.push_back(OMPD_taskloop);
  669. break;
  670. case OMPD_target_teams_distribute_parallel_for:
  671. case OMPD_target_teams_distribute_parallel_for_simd:
  672. CaptureRegions.push_back(OMPD_task);
  673. CaptureRegions.push_back(OMPD_target);
  674. CaptureRegions.push_back(OMPD_teams);
  675. CaptureRegions.push_back(OMPD_parallel);
  676. break;
  677. case OMPD_loop:
  678. // TODO: 'loop' may require different capture regions depending on the bind
  679. // clause or the parent directive when there is no bind clause. Use
  680. // OMPD_unknown for now.
  681. case OMPD_simd:
  682. case OMPD_for:
  683. case OMPD_for_simd:
  684. case OMPD_sections:
  685. case OMPD_section:
  686. case OMPD_single:
  687. case OMPD_master:
  688. case OMPD_critical:
  689. case OMPD_taskgroup:
  690. case OMPD_distribute:
  691. case OMPD_ordered:
  692. case OMPD_atomic:
  693. case OMPD_target_data:
  694. case OMPD_distribute_simd:
  695. case OMPD_dispatch:
  696. CaptureRegions.push_back(OMPD_unknown);
  697. break;
  698. case OMPD_tile:
  699. case OMPD_unroll:
  700. // loop transformations do not introduce captures.
  701. break;
  702. case OMPD_threadprivate:
  703. case OMPD_allocate:
  704. case OMPD_taskyield:
  705. case OMPD_barrier:
  706. case OMPD_taskwait:
  707. case OMPD_cancellation_point:
  708. case OMPD_cancel:
  709. case OMPD_flush:
  710. case OMPD_depobj:
  711. case OMPD_scan:
  712. case OMPD_declare_reduction:
  713. case OMPD_declare_mapper:
  714. case OMPD_declare_simd:
  715. case OMPD_declare_target:
  716. case OMPD_end_declare_target:
  717. case OMPD_requires:
  718. case OMPD_declare_variant:
  719. case OMPD_begin_declare_variant:
  720. case OMPD_end_declare_variant:
  721. llvm_unreachable("OpenMP Directive is not allowed");
  722. case OMPD_unknown:
  723. default:
  724. llvm_unreachable("Unknown OpenMP directive");
  725. }
  726. }