OpenMPClause.cpp 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650
  1. //===- OpenMPClause.cpp - Classes for OpenMP clauses ----------------------===//
  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. // This file implements the subclesses of Stmt class declared in OpenMPClause.h
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "clang/AST/OpenMPClause.h"
  13. #include "clang/AST/ASTContext.h"
  14. #include "clang/AST/Decl.h"
  15. #include "clang/AST/DeclOpenMP.h"
  16. #include "clang/Basic/LLVM.h"
  17. #include "llvm/ADT/SmallPtrSet.h"
  18. #include "llvm/Support/Casting.h"
  19. #include "llvm/Support/ErrorHandling.h"
  20. #include <algorithm>
  21. #include <cassert>
  22. using namespace clang;
  23. OMPClause::child_range OMPClause::children() {
  24. switch (getClauseKind()) {
  25. default:
  26. break;
  27. #define OPENMP_CLAUSE(Name, Class) \
  28. case OMPC_##Name: \
  29. return static_cast<Class *>(this)->children();
  30. #include "clang/Basic/OpenMPKinds.def"
  31. }
  32. llvm_unreachable("unknown OMPClause");
  33. }
  34. OMPClause::child_range OMPClause::used_children() {
  35. switch (getClauseKind()) {
  36. #define OPENMP_CLAUSE(Name, Class) \
  37. case OMPC_##Name: \
  38. return static_cast<Class *>(this)->used_children();
  39. #include "clang/Basic/OpenMPKinds.def"
  40. case OMPC_threadprivate:
  41. case OMPC_uniform:
  42. case OMPC_device_type:
  43. case OMPC_match:
  44. case OMPC_unknown:
  45. break;
  46. }
  47. llvm_unreachable("unknown OMPClause");
  48. }
  49. OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
  50. auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
  51. return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr;
  52. }
  53. const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
  54. switch (C->getClauseKind()) {
  55. case OMPC_schedule:
  56. return static_cast<const OMPScheduleClause *>(C);
  57. case OMPC_dist_schedule:
  58. return static_cast<const OMPDistScheduleClause *>(C);
  59. case OMPC_firstprivate:
  60. return static_cast<const OMPFirstprivateClause *>(C);
  61. case OMPC_lastprivate:
  62. return static_cast<const OMPLastprivateClause *>(C);
  63. case OMPC_reduction:
  64. return static_cast<const OMPReductionClause *>(C);
  65. case OMPC_task_reduction:
  66. return static_cast<const OMPTaskReductionClause *>(C);
  67. case OMPC_in_reduction:
  68. return static_cast<const OMPInReductionClause *>(C);
  69. case OMPC_linear:
  70. return static_cast<const OMPLinearClause *>(C);
  71. case OMPC_if:
  72. return static_cast<const OMPIfClause *>(C);
  73. case OMPC_num_threads:
  74. return static_cast<const OMPNumThreadsClause *>(C);
  75. case OMPC_num_teams:
  76. return static_cast<const OMPNumTeamsClause *>(C);
  77. case OMPC_thread_limit:
  78. return static_cast<const OMPThreadLimitClause *>(C);
  79. case OMPC_device:
  80. return static_cast<const OMPDeviceClause *>(C);
  81. case OMPC_grainsize:
  82. return static_cast<const OMPGrainsizeClause *>(C);
  83. case OMPC_num_tasks:
  84. return static_cast<const OMPNumTasksClause *>(C);
  85. case OMPC_final:
  86. return static_cast<const OMPFinalClause *>(C);
  87. case OMPC_priority:
  88. return static_cast<const OMPPriorityClause *>(C);
  89. case OMPC_default:
  90. case OMPC_proc_bind:
  91. case OMPC_safelen:
  92. case OMPC_simdlen:
  93. case OMPC_allocator:
  94. case OMPC_allocate:
  95. case OMPC_collapse:
  96. case OMPC_private:
  97. case OMPC_shared:
  98. case OMPC_aligned:
  99. case OMPC_copyin:
  100. case OMPC_copyprivate:
  101. case OMPC_ordered:
  102. case OMPC_nowait:
  103. case OMPC_untied:
  104. case OMPC_mergeable:
  105. case OMPC_threadprivate:
  106. case OMPC_flush:
  107. case OMPC_read:
  108. case OMPC_write:
  109. case OMPC_update:
  110. case OMPC_capture:
  111. case OMPC_seq_cst:
  112. case OMPC_depend:
  113. case OMPC_threads:
  114. case OMPC_simd:
  115. case OMPC_map:
  116. case OMPC_nogroup:
  117. case OMPC_hint:
  118. case OMPC_defaultmap:
  119. case OMPC_unknown:
  120. case OMPC_uniform:
  121. case OMPC_to:
  122. case OMPC_from:
  123. case OMPC_use_device_ptr:
  124. case OMPC_is_device_ptr:
  125. case OMPC_unified_address:
  126. case OMPC_unified_shared_memory:
  127. case OMPC_reverse_offload:
  128. case OMPC_dynamic_allocators:
  129. case OMPC_atomic_default_mem_order:
  130. case OMPC_device_type:
  131. case OMPC_match:
  132. break;
  133. }
  134. return nullptr;
  135. }
  136. OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
  137. auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
  138. return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
  139. }
  140. const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
  141. switch (C->getClauseKind()) {
  142. case OMPC_lastprivate:
  143. return static_cast<const OMPLastprivateClause *>(C);
  144. case OMPC_reduction:
  145. return static_cast<const OMPReductionClause *>(C);
  146. case OMPC_task_reduction:
  147. return static_cast<const OMPTaskReductionClause *>(C);
  148. case OMPC_in_reduction:
  149. return static_cast<const OMPInReductionClause *>(C);
  150. case OMPC_linear:
  151. return static_cast<const OMPLinearClause *>(C);
  152. case OMPC_schedule:
  153. case OMPC_dist_schedule:
  154. case OMPC_firstprivate:
  155. case OMPC_default:
  156. case OMPC_proc_bind:
  157. case OMPC_if:
  158. case OMPC_final:
  159. case OMPC_num_threads:
  160. case OMPC_safelen:
  161. case OMPC_simdlen:
  162. case OMPC_allocator:
  163. case OMPC_allocate:
  164. case OMPC_collapse:
  165. case OMPC_private:
  166. case OMPC_shared:
  167. case OMPC_aligned:
  168. case OMPC_copyin:
  169. case OMPC_copyprivate:
  170. case OMPC_ordered:
  171. case OMPC_nowait:
  172. case OMPC_untied:
  173. case OMPC_mergeable:
  174. case OMPC_threadprivate:
  175. case OMPC_flush:
  176. case OMPC_read:
  177. case OMPC_write:
  178. case OMPC_update:
  179. case OMPC_capture:
  180. case OMPC_seq_cst:
  181. case OMPC_depend:
  182. case OMPC_device:
  183. case OMPC_threads:
  184. case OMPC_simd:
  185. case OMPC_map:
  186. case OMPC_num_teams:
  187. case OMPC_thread_limit:
  188. case OMPC_priority:
  189. case OMPC_grainsize:
  190. case OMPC_nogroup:
  191. case OMPC_num_tasks:
  192. case OMPC_hint:
  193. case OMPC_defaultmap:
  194. case OMPC_unknown:
  195. case OMPC_uniform:
  196. case OMPC_to:
  197. case OMPC_from:
  198. case OMPC_use_device_ptr:
  199. case OMPC_is_device_ptr:
  200. case OMPC_unified_address:
  201. case OMPC_unified_shared_memory:
  202. case OMPC_reverse_offload:
  203. case OMPC_dynamic_allocators:
  204. case OMPC_atomic_default_mem_order:
  205. case OMPC_device_type:
  206. case OMPC_match:
  207. break;
  208. }
  209. return nullptr;
  210. }
  211. /// Gets the address of the original, non-captured, expression used in the
  212. /// clause as the preinitializer.
  213. static Stmt **getAddrOfExprAsWritten(Stmt *S) {
  214. if (!S)
  215. return nullptr;
  216. if (auto *DS = dyn_cast<DeclStmt>(S)) {
  217. assert(DS->isSingleDecl() && "Only single expression must be captured.");
  218. if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
  219. return OED->getInitAddress();
  220. }
  221. return nullptr;
  222. }
  223. OMPClause::child_range OMPIfClause::used_children() {
  224. if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
  225. return child_range(C, C + 1);
  226. return child_range(&Condition, &Condition + 1);
  227. }
  228. OMPClause::child_range OMPGrainsizeClause::used_children() {
  229. if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
  230. return child_range(C, C + 1);
  231. return child_range(&Grainsize, &Grainsize + 1);
  232. }
  233. OMPClause::child_range OMPNumTasksClause::used_children() {
  234. if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
  235. return child_range(C, C + 1);
  236. return child_range(&NumTasks, &NumTasks + 1);
  237. }
  238. OMPClause::child_range OMPFinalClause::used_children() {
  239. if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
  240. return child_range(C, C + 1);
  241. return child_range(&Condition, &Condition + 1);
  242. }
  243. OMPClause::child_range OMPPriorityClause::used_children() {
  244. if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
  245. return child_range(C, C + 1);
  246. return child_range(&Priority, &Priority + 1);
  247. }
  248. OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
  249. unsigned NumLoops,
  250. SourceLocation StartLoc,
  251. SourceLocation LParenLoc,
  252. SourceLocation EndLoc) {
  253. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
  254. auto *Clause =
  255. new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
  256. for (unsigned I = 0; I < NumLoops; ++I) {
  257. Clause->setLoopNumIterations(I, nullptr);
  258. Clause->setLoopCounter(I, nullptr);
  259. }
  260. return Clause;
  261. }
  262. OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
  263. unsigned NumLoops) {
  264. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
  265. auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
  266. for (unsigned I = 0; I < NumLoops; ++I) {
  267. Clause->setLoopNumIterations(I, nullptr);
  268. Clause->setLoopCounter(I, nullptr);
  269. }
  270. return Clause;
  271. }
  272. void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
  273. Expr *NumIterations) {
  274. assert(NumLoop < NumberOfLoops && "out of loops number.");
  275. getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
  276. }
  277. ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
  278. return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
  279. }
  280. void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
  281. assert(NumLoop < NumberOfLoops && "out of loops number.");
  282. getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
  283. }
  284. Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
  285. assert(NumLoop < NumberOfLoops && "out of loops number.");
  286. return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
  287. }
  288. const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
  289. assert(NumLoop < NumberOfLoops && "out of loops number.");
  290. return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
  291. }
  292. void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
  293. assert(VL.size() == varlist_size() &&
  294. "Number of private copies is not the same as the preallocated buffer");
  295. std::copy(VL.begin(), VL.end(), varlist_end());
  296. }
  297. OMPPrivateClause *
  298. OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
  299. SourceLocation LParenLoc, SourceLocation EndLoc,
  300. ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
  301. // Allocate space for private variables and initializer expressions.
  302. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
  303. OMPPrivateClause *Clause =
  304. new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
  305. Clause->setVarRefs(VL);
  306. Clause->setPrivateCopies(PrivateVL);
  307. return Clause;
  308. }
  309. OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
  310. unsigned N) {
  311. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
  312. return new (Mem) OMPPrivateClause(N);
  313. }
  314. void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
  315. assert(VL.size() == varlist_size() &&
  316. "Number of private copies is not the same as the preallocated buffer");
  317. std::copy(VL.begin(), VL.end(), varlist_end());
  318. }
  319. void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
  320. assert(VL.size() == varlist_size() &&
  321. "Number of inits is not the same as the preallocated buffer");
  322. std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
  323. }
  324. OMPFirstprivateClause *
  325. OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
  326. SourceLocation LParenLoc, SourceLocation EndLoc,
  327. ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
  328. ArrayRef<Expr *> InitVL, Stmt *PreInit) {
  329. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
  330. OMPFirstprivateClause *Clause =
  331. new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
  332. Clause->setVarRefs(VL);
  333. Clause->setPrivateCopies(PrivateVL);
  334. Clause->setInits(InitVL);
  335. Clause->setPreInitStmt(PreInit);
  336. return Clause;
  337. }
  338. OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
  339. unsigned N) {
  340. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
  341. return new (Mem) OMPFirstprivateClause(N);
  342. }
  343. void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
  344. assert(PrivateCopies.size() == varlist_size() &&
  345. "Number of private copies is not the same as the preallocated buffer");
  346. std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
  347. }
  348. void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
  349. assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
  350. "not the same as the "
  351. "preallocated buffer");
  352. std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
  353. }
  354. void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
  355. assert(DstExprs.size() == varlist_size() && "Number of destination "
  356. "expressions is not the same as "
  357. "the preallocated buffer");
  358. std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
  359. }
  360. void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
  361. assert(AssignmentOps.size() == varlist_size() &&
  362. "Number of assignment expressions is not the same as the preallocated "
  363. "buffer");
  364. std::copy(AssignmentOps.begin(), AssignmentOps.end(),
  365. getDestinationExprs().end());
  366. }
  367. OMPLastprivateClause *OMPLastprivateClause::Create(
  368. const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  369. SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
  370. ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit,
  371. Expr *PostUpdate) {
  372. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
  373. OMPLastprivateClause *Clause =
  374. new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
  375. Clause->setVarRefs(VL);
  376. Clause->setSourceExprs(SrcExprs);
  377. Clause->setDestinationExprs(DstExprs);
  378. Clause->setAssignmentOps(AssignmentOps);
  379. Clause->setPreInitStmt(PreInit);
  380. Clause->setPostUpdateExpr(PostUpdate);
  381. return Clause;
  382. }
  383. OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
  384. unsigned N) {
  385. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
  386. return new (Mem) OMPLastprivateClause(N);
  387. }
  388. OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
  389. SourceLocation StartLoc,
  390. SourceLocation LParenLoc,
  391. SourceLocation EndLoc,
  392. ArrayRef<Expr *> VL) {
  393. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
  394. OMPSharedClause *Clause =
  395. new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
  396. Clause->setVarRefs(VL);
  397. return Clause;
  398. }
  399. OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
  400. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
  401. return new (Mem) OMPSharedClause(N);
  402. }
  403. void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
  404. assert(PL.size() == varlist_size() &&
  405. "Number of privates is not the same as the preallocated buffer");
  406. std::copy(PL.begin(), PL.end(), varlist_end());
  407. }
  408. void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
  409. assert(IL.size() == varlist_size() &&
  410. "Number of inits is not the same as the preallocated buffer");
  411. std::copy(IL.begin(), IL.end(), getPrivates().end());
  412. }
  413. void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
  414. assert(UL.size() == varlist_size() &&
  415. "Number of updates is not the same as the preallocated buffer");
  416. std::copy(UL.begin(), UL.end(), getInits().end());
  417. }
  418. void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
  419. assert(FL.size() == varlist_size() &&
  420. "Number of final updates is not the same as the preallocated buffer");
  421. std::copy(FL.begin(), FL.end(), getUpdates().end());
  422. }
  423. void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) {
  424. assert(
  425. UE.size() == varlist_size() + 1 &&
  426. "Number of used expressions is not the same as the preallocated buffer");
  427. std::copy(UE.begin(), UE.end(), getFinals().end() + 2);
  428. }
  429. OMPLinearClause *OMPLinearClause::Create(
  430. const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  431. OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
  432. SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
  433. ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
  434. Stmt *PreInit, Expr *PostUpdate) {
  435. // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
  436. // (Step and CalcStep), list of used expression + step.
  437. void *Mem =
  438. C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1));
  439. OMPLinearClause *Clause = new (Mem) OMPLinearClause(
  440. StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
  441. Clause->setVarRefs(VL);
  442. Clause->setPrivates(PL);
  443. Clause->setInits(IL);
  444. // Fill update and final expressions with zeroes, they are provided later,
  445. // after the directive construction.
  446. std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
  447. nullptr);
  448. std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
  449. nullptr);
  450. std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(),
  451. nullptr);
  452. Clause->setStep(Step);
  453. Clause->setCalcStep(CalcStep);
  454. Clause->setPreInitStmt(PreInit);
  455. Clause->setPostUpdateExpr(PostUpdate);
  456. return Clause;
  457. }
  458. OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
  459. unsigned NumVars) {
  460. // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
  461. // (Step and CalcStep), list of used expression + step.
  462. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars +1));
  463. return new (Mem) OMPLinearClause(NumVars);
  464. }
  465. OMPClause::child_range OMPLinearClause::used_children() {
  466. // Range includes only non-nullptr elements.
  467. return child_range(
  468. reinterpret_cast<Stmt **>(getUsedExprs().begin()),
  469. reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr)));
  470. }
  471. OMPAlignedClause *
  472. OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
  473. SourceLocation LParenLoc, SourceLocation ColonLoc,
  474. SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
  475. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
  476. OMPAlignedClause *Clause = new (Mem)
  477. OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
  478. Clause->setVarRefs(VL);
  479. Clause->setAlignment(A);
  480. return Clause;
  481. }
  482. OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
  483. unsigned NumVars) {
  484. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
  485. return new (Mem) OMPAlignedClause(NumVars);
  486. }
  487. void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
  488. assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
  489. "not the same as the "
  490. "preallocated buffer");
  491. std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
  492. }
  493. void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
  494. assert(DstExprs.size() == varlist_size() && "Number of destination "
  495. "expressions is not the same as "
  496. "the preallocated buffer");
  497. std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
  498. }
  499. void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
  500. assert(AssignmentOps.size() == varlist_size() &&
  501. "Number of assignment expressions is not the same as the preallocated "
  502. "buffer");
  503. std::copy(AssignmentOps.begin(), AssignmentOps.end(),
  504. getDestinationExprs().end());
  505. }
  506. OMPCopyinClause *OMPCopyinClause::Create(
  507. const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  508. SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
  509. ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
  510. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
  511. OMPCopyinClause *Clause =
  512. new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
  513. Clause->setVarRefs(VL);
  514. Clause->setSourceExprs(SrcExprs);
  515. Clause->setDestinationExprs(DstExprs);
  516. Clause->setAssignmentOps(AssignmentOps);
  517. return Clause;
  518. }
  519. OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
  520. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
  521. return new (Mem) OMPCopyinClause(N);
  522. }
  523. void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
  524. assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
  525. "not the same as the "
  526. "preallocated buffer");
  527. std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
  528. }
  529. void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
  530. assert(DstExprs.size() == varlist_size() && "Number of destination "
  531. "expressions is not the same as "
  532. "the preallocated buffer");
  533. std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
  534. }
  535. void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
  536. assert(AssignmentOps.size() == varlist_size() &&
  537. "Number of assignment expressions is not the same as the preallocated "
  538. "buffer");
  539. std::copy(AssignmentOps.begin(), AssignmentOps.end(),
  540. getDestinationExprs().end());
  541. }
  542. OMPCopyprivateClause *OMPCopyprivateClause::Create(
  543. const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  544. SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
  545. ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
  546. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
  547. OMPCopyprivateClause *Clause =
  548. new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
  549. Clause->setVarRefs(VL);
  550. Clause->setSourceExprs(SrcExprs);
  551. Clause->setDestinationExprs(DstExprs);
  552. Clause->setAssignmentOps(AssignmentOps);
  553. return Clause;
  554. }
  555. OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
  556. unsigned N) {
  557. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
  558. return new (Mem) OMPCopyprivateClause(N);
  559. }
  560. void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
  561. assert(Privates.size() == varlist_size() &&
  562. "Number of private copies is not the same as the preallocated buffer");
  563. std::copy(Privates.begin(), Privates.end(), varlist_end());
  564. }
  565. void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
  566. assert(
  567. LHSExprs.size() == varlist_size() &&
  568. "Number of LHS expressions is not the same as the preallocated buffer");
  569. std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
  570. }
  571. void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
  572. assert(
  573. RHSExprs.size() == varlist_size() &&
  574. "Number of RHS expressions is not the same as the preallocated buffer");
  575. std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
  576. }
  577. void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
  578. assert(ReductionOps.size() == varlist_size() && "Number of reduction "
  579. "expressions is not the same "
  580. "as the preallocated buffer");
  581. std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
  582. }
  583. OMPReductionClause *OMPReductionClause::Create(
  584. const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  585. SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
  586. NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
  587. ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
  588. ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
  589. Expr *PostUpdate) {
  590. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
  591. OMPReductionClause *Clause = new (Mem) OMPReductionClause(
  592. StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
  593. Clause->setVarRefs(VL);
  594. Clause->setPrivates(Privates);
  595. Clause->setLHSExprs(LHSExprs);
  596. Clause->setRHSExprs(RHSExprs);
  597. Clause->setReductionOps(ReductionOps);
  598. Clause->setPreInitStmt(PreInit);
  599. Clause->setPostUpdateExpr(PostUpdate);
  600. return Clause;
  601. }
  602. OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
  603. unsigned N) {
  604. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
  605. return new (Mem) OMPReductionClause(N);
  606. }
  607. void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
  608. assert(Privates.size() == varlist_size() &&
  609. "Number of private copies is not the same as the preallocated buffer");
  610. std::copy(Privates.begin(), Privates.end(), varlist_end());
  611. }
  612. void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
  613. assert(
  614. LHSExprs.size() == varlist_size() &&
  615. "Number of LHS expressions is not the same as the preallocated buffer");
  616. std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
  617. }
  618. void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
  619. assert(
  620. RHSExprs.size() == varlist_size() &&
  621. "Number of RHS expressions is not the same as the preallocated buffer");
  622. std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
  623. }
  624. void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
  625. assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
  626. "expressions is not the same "
  627. "as the preallocated buffer");
  628. std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
  629. }
  630. OMPTaskReductionClause *OMPTaskReductionClause::Create(
  631. const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  632. SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
  633. NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
  634. ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
  635. ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
  636. Expr *PostUpdate) {
  637. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
  638. OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
  639. StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
  640. Clause->setVarRefs(VL);
  641. Clause->setPrivates(Privates);
  642. Clause->setLHSExprs(LHSExprs);
  643. Clause->setRHSExprs(RHSExprs);
  644. Clause->setReductionOps(ReductionOps);
  645. Clause->setPreInitStmt(PreInit);
  646. Clause->setPostUpdateExpr(PostUpdate);
  647. return Clause;
  648. }
  649. OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
  650. unsigned N) {
  651. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
  652. return new (Mem) OMPTaskReductionClause(N);
  653. }
  654. void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
  655. assert(Privates.size() == varlist_size() &&
  656. "Number of private copies is not the same as the preallocated buffer");
  657. std::copy(Privates.begin(), Privates.end(), varlist_end());
  658. }
  659. void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
  660. assert(
  661. LHSExprs.size() == varlist_size() &&
  662. "Number of LHS expressions is not the same as the preallocated buffer");
  663. std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
  664. }
  665. void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
  666. assert(
  667. RHSExprs.size() == varlist_size() &&
  668. "Number of RHS expressions is not the same as the preallocated buffer");
  669. std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
  670. }
  671. void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
  672. assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
  673. "expressions is not the same "
  674. "as the preallocated buffer");
  675. std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
  676. }
  677. void OMPInReductionClause::setTaskgroupDescriptors(
  678. ArrayRef<Expr *> TaskgroupDescriptors) {
  679. assert(TaskgroupDescriptors.size() == varlist_size() &&
  680. "Number of in reduction descriptors is not the same as the "
  681. "preallocated buffer");
  682. std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
  683. getReductionOps().end());
  684. }
  685. OMPInReductionClause *OMPInReductionClause::Create(
  686. const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  687. SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
  688. NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
  689. ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
  690. ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
  691. ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
  692. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
  693. OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
  694. StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
  695. Clause->setVarRefs(VL);
  696. Clause->setPrivates(Privates);
  697. Clause->setLHSExprs(LHSExprs);
  698. Clause->setRHSExprs(RHSExprs);
  699. Clause->setReductionOps(ReductionOps);
  700. Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
  701. Clause->setPreInitStmt(PreInit);
  702. Clause->setPostUpdateExpr(PostUpdate);
  703. return Clause;
  704. }
  705. OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
  706. unsigned N) {
  707. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
  708. return new (Mem) OMPInReductionClause(N);
  709. }
  710. OMPAllocateClause *
  711. OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc,
  712. SourceLocation LParenLoc, Expr *Allocator,
  713. SourceLocation ColonLoc, SourceLocation EndLoc,
  714. ArrayRef<Expr *> VL) {
  715. // Allocate space for private variables and initializer expressions.
  716. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
  717. auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
  718. ColonLoc, EndLoc, VL.size());
  719. Clause->setVarRefs(VL);
  720. return Clause;
  721. }
  722. OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
  723. unsigned N) {
  724. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
  725. return new (Mem) OMPAllocateClause(N);
  726. }
  727. OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
  728. SourceLocation StartLoc,
  729. SourceLocation LParenLoc,
  730. SourceLocation EndLoc,
  731. ArrayRef<Expr *> VL) {
  732. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
  733. OMPFlushClause *Clause =
  734. new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
  735. Clause->setVarRefs(VL);
  736. return Clause;
  737. }
  738. OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
  739. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
  740. return new (Mem) OMPFlushClause(N);
  741. }
  742. OMPDependClause *
  743. OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
  744. SourceLocation LParenLoc, SourceLocation EndLoc,
  745. OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
  746. SourceLocation ColonLoc, ArrayRef<Expr *> VL,
  747. unsigned NumLoops) {
  748. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
  749. OMPDependClause *Clause = new (Mem)
  750. OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
  751. Clause->setVarRefs(VL);
  752. Clause->setDependencyKind(DepKind);
  753. Clause->setDependencyLoc(DepLoc);
  754. Clause->setColonLoc(ColonLoc);
  755. for (unsigned I = 0 ; I < NumLoops; ++I)
  756. Clause->setLoopData(I, nullptr);
  757. return Clause;
  758. }
  759. OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
  760. unsigned NumLoops) {
  761. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
  762. return new (Mem) OMPDependClause(N, NumLoops);
  763. }
  764. void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
  765. assert((getDependencyKind() == OMPC_DEPEND_sink ||
  766. getDependencyKind() == OMPC_DEPEND_source) &&
  767. NumLoop < NumLoops &&
  768. "Expected sink or source depend + loop index must be less number of "
  769. "loops.");
  770. auto It = std::next(getVarRefs().end(), NumLoop);
  771. *It = Cnt;
  772. }
  773. Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
  774. assert((getDependencyKind() == OMPC_DEPEND_sink ||
  775. getDependencyKind() == OMPC_DEPEND_source) &&
  776. NumLoop < NumLoops &&
  777. "Expected sink or source depend + loop index must be less number of "
  778. "loops.");
  779. auto It = std::next(getVarRefs().end(), NumLoop);
  780. return *It;
  781. }
  782. const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
  783. assert((getDependencyKind() == OMPC_DEPEND_sink ||
  784. getDependencyKind() == OMPC_DEPEND_source) &&
  785. NumLoop < NumLoops &&
  786. "Expected sink or source depend + loop index must be less number of "
  787. "loops.");
  788. auto It = std::next(getVarRefs().end(), NumLoop);
  789. return *It;
  790. }
  791. unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
  792. MappableExprComponentListsRef ComponentLists) {
  793. unsigned TotalNum = 0u;
  794. for (auto &C : ComponentLists)
  795. TotalNum += C.size();
  796. return TotalNum;
  797. }
  798. unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
  799. ArrayRef<const ValueDecl *> Declarations) {
  800. unsigned TotalNum = 0u;
  801. llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
  802. for (const ValueDecl *D : Declarations) {
  803. const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
  804. if (Cache.count(VD))
  805. continue;
  806. ++TotalNum;
  807. Cache.insert(VD);
  808. }
  809. return TotalNum;
  810. }
  811. OMPMapClause *OMPMapClause::Create(
  812. const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
  813. ArrayRef<ValueDecl *> Declarations,
  814. MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
  815. ArrayRef<OpenMPMapModifierKind> MapModifiers,
  816. ArrayRef<SourceLocation> MapModifiersLoc,
  817. NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
  818. OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
  819. OMPMappableExprListSizeTy Sizes;
  820. Sizes.NumVars = Vars.size();
  821. Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
  822. Sizes.NumComponentLists = ComponentLists.size();
  823. Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
  824. // We need to allocate:
  825. // 2 x NumVars x Expr* - we have an original list expression and an associated
  826. // user-defined mapper for each clause list entry.
  827. // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
  828. // with each component list.
  829. // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
  830. // number of lists for each unique declaration and the size of each component
  831. // list.
  832. // NumComponents x MappableComponent - the total of all the components in all
  833. // the lists.
  834. void *Mem = C.Allocate(
  835. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  836. OMPClauseMappableExprCommon::MappableComponent>(
  837. 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
  838. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  839. Sizes.NumComponents));
  840. OMPMapClause *Clause = new (Mem)
  841. OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
  842. Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
  843. Clause->setVarRefs(Vars);
  844. Clause->setUDMapperRefs(UDMapperRefs);
  845. Clause->setClauseInfo(Declarations, ComponentLists);
  846. Clause->setMapType(Type);
  847. Clause->setMapLoc(TypeLoc);
  848. return Clause;
  849. }
  850. OMPMapClause *
  851. OMPMapClause::CreateEmpty(const ASTContext &C,
  852. const OMPMappableExprListSizeTy &Sizes) {
  853. void *Mem = C.Allocate(
  854. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  855. OMPClauseMappableExprCommon::MappableComponent>(
  856. 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
  857. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  858. Sizes.NumComponents));
  859. return new (Mem) OMPMapClause(Sizes);
  860. }
  861. OMPToClause *OMPToClause::Create(
  862. const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
  863. ArrayRef<ValueDecl *> Declarations,
  864. MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
  865. NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
  866. OMPMappableExprListSizeTy Sizes;
  867. Sizes.NumVars = Vars.size();
  868. Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
  869. Sizes.NumComponentLists = ComponentLists.size();
  870. Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
  871. // We need to allocate:
  872. // 2 x NumVars x Expr* - we have an original list expression and an associated
  873. // user-defined mapper for each clause list entry.
  874. // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
  875. // with each component list.
  876. // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
  877. // number of lists for each unique declaration and the size of each component
  878. // list.
  879. // NumComponents x MappableComponent - the total of all the components in all
  880. // the lists.
  881. void *Mem = C.Allocate(
  882. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  883. OMPClauseMappableExprCommon::MappableComponent>(
  884. 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
  885. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  886. Sizes.NumComponents));
  887. auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
  888. Clause->setVarRefs(Vars);
  889. Clause->setUDMapperRefs(UDMapperRefs);
  890. Clause->setClauseInfo(Declarations, ComponentLists);
  891. return Clause;
  892. }
  893. OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
  894. const OMPMappableExprListSizeTy &Sizes) {
  895. void *Mem = C.Allocate(
  896. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  897. OMPClauseMappableExprCommon::MappableComponent>(
  898. 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
  899. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  900. Sizes.NumComponents));
  901. return new (Mem) OMPToClause(Sizes);
  902. }
  903. OMPFromClause *OMPFromClause::Create(
  904. const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
  905. ArrayRef<ValueDecl *> Declarations,
  906. MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
  907. NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
  908. OMPMappableExprListSizeTy Sizes;
  909. Sizes.NumVars = Vars.size();
  910. Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
  911. Sizes.NumComponentLists = ComponentLists.size();
  912. Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
  913. // We need to allocate:
  914. // 2 x NumVars x Expr* - we have an original list expression and an associated
  915. // user-defined mapper for each clause list entry.
  916. // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
  917. // with each component list.
  918. // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
  919. // number of lists for each unique declaration and the size of each component
  920. // list.
  921. // NumComponents x MappableComponent - the total of all the components in all
  922. // the lists.
  923. void *Mem = C.Allocate(
  924. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  925. OMPClauseMappableExprCommon::MappableComponent>(
  926. 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
  927. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  928. Sizes.NumComponents));
  929. auto *Clause =
  930. new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
  931. Clause->setVarRefs(Vars);
  932. Clause->setUDMapperRefs(UDMapperRefs);
  933. Clause->setClauseInfo(Declarations, ComponentLists);
  934. return Clause;
  935. }
  936. OMPFromClause *
  937. OMPFromClause::CreateEmpty(const ASTContext &C,
  938. const OMPMappableExprListSizeTy &Sizes) {
  939. void *Mem = C.Allocate(
  940. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  941. OMPClauseMappableExprCommon::MappableComponent>(
  942. 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
  943. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  944. Sizes.NumComponents));
  945. return new (Mem) OMPFromClause(Sizes);
  946. }
  947. void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
  948. assert(VL.size() == varlist_size() &&
  949. "Number of private copies is not the same as the preallocated buffer");
  950. std::copy(VL.begin(), VL.end(), varlist_end());
  951. }
  952. void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
  953. assert(VL.size() == varlist_size() &&
  954. "Number of inits is not the same as the preallocated buffer");
  955. std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
  956. }
  957. OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
  958. const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
  959. ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
  960. ArrayRef<ValueDecl *> Declarations,
  961. MappableExprComponentListsRef ComponentLists) {
  962. OMPMappableExprListSizeTy Sizes;
  963. Sizes.NumVars = Vars.size();
  964. Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
  965. Sizes.NumComponentLists = ComponentLists.size();
  966. Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
  967. // We need to allocate:
  968. // 3 x NumVars x Expr* - we have an original list expression for each clause
  969. // list entry and an equal number of private copies and inits.
  970. // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
  971. // with each component list.
  972. // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
  973. // number of lists for each unique declaration and the size of each component
  974. // list.
  975. // NumComponents x MappableComponent - the total of all the components in all
  976. // the lists.
  977. void *Mem = C.Allocate(
  978. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  979. OMPClauseMappableExprCommon::MappableComponent>(
  980. 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
  981. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  982. Sizes.NumComponents));
  983. OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
  984. Clause->setVarRefs(Vars);
  985. Clause->setPrivateCopies(PrivateVars);
  986. Clause->setInits(Inits);
  987. Clause->setClauseInfo(Declarations, ComponentLists);
  988. return Clause;
  989. }
  990. OMPUseDevicePtrClause *
  991. OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
  992. const OMPMappableExprListSizeTy &Sizes) {
  993. void *Mem = C.Allocate(
  994. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  995. OMPClauseMappableExprCommon::MappableComponent>(
  996. 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
  997. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  998. Sizes.NumComponents));
  999. return new (Mem) OMPUseDevicePtrClause(Sizes);
  1000. }
  1001. OMPIsDevicePtrClause *
  1002. OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
  1003. ArrayRef<Expr *> Vars,
  1004. ArrayRef<ValueDecl *> Declarations,
  1005. MappableExprComponentListsRef ComponentLists) {
  1006. OMPMappableExprListSizeTy Sizes;
  1007. Sizes.NumVars = Vars.size();
  1008. Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
  1009. Sizes.NumComponentLists = ComponentLists.size();
  1010. Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
  1011. // We need to allocate:
  1012. // NumVars x Expr* - we have an original list expression for each clause list
  1013. // entry.
  1014. // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
  1015. // with each component list.
  1016. // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
  1017. // number of lists for each unique declaration and the size of each component
  1018. // list.
  1019. // NumComponents x MappableComponent - the total of all the components in all
  1020. // the lists.
  1021. void *Mem = C.Allocate(
  1022. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  1023. OMPClauseMappableExprCommon::MappableComponent>(
  1024. Sizes.NumVars, Sizes.NumUniqueDeclarations,
  1025. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  1026. Sizes.NumComponents));
  1027. OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
  1028. Clause->setVarRefs(Vars);
  1029. Clause->setClauseInfo(Declarations, ComponentLists);
  1030. return Clause;
  1031. }
  1032. OMPIsDevicePtrClause *
  1033. OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
  1034. const OMPMappableExprListSizeTy &Sizes) {
  1035. void *Mem = C.Allocate(
  1036. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  1037. OMPClauseMappableExprCommon::MappableComponent>(
  1038. Sizes.NumVars, Sizes.NumUniqueDeclarations,
  1039. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  1040. Sizes.NumComponents));
  1041. return new (Mem) OMPIsDevicePtrClause(Sizes);
  1042. }
  1043. //===----------------------------------------------------------------------===//
  1044. // OpenMP clauses printing methods
  1045. //===----------------------------------------------------------------------===//
  1046. void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
  1047. OS << "if(";
  1048. if (Node->getNameModifier() != OMPD_unknown)
  1049. OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
  1050. Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
  1051. OS << ")";
  1052. }
  1053. void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
  1054. OS << "final(";
  1055. Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
  1056. OS << ")";
  1057. }
  1058. void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
  1059. OS << "num_threads(";
  1060. Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
  1061. OS << ")";
  1062. }
  1063. void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
  1064. OS << "safelen(";
  1065. Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
  1066. OS << ")";
  1067. }
  1068. void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
  1069. OS << "simdlen(";
  1070. Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
  1071. OS << ")";
  1072. }
  1073. void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
  1074. OS << "allocator(";
  1075. Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
  1076. OS << ")";
  1077. }
  1078. void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
  1079. OS << "collapse(";
  1080. Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
  1081. OS << ")";
  1082. }
  1083. void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
  1084. OS << "default("
  1085. << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
  1086. << ")";
  1087. }
  1088. void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
  1089. OS << "proc_bind("
  1090. << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, Node->getProcBindKind())
  1091. << ")";
  1092. }
  1093. void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
  1094. OS << "unified_address";
  1095. }
  1096. void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
  1097. OMPUnifiedSharedMemoryClause *) {
  1098. OS << "unified_shared_memory";
  1099. }
  1100. void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
  1101. OS << "reverse_offload";
  1102. }
  1103. void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
  1104. OMPDynamicAllocatorsClause *) {
  1105. OS << "dynamic_allocators";
  1106. }
  1107. void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
  1108. OMPAtomicDefaultMemOrderClause *Node) {
  1109. OS << "atomic_default_mem_order("
  1110. << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
  1111. Node->getAtomicDefaultMemOrderKind())
  1112. << ")";
  1113. }
  1114. void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
  1115. OS << "schedule(";
  1116. if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
  1117. OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
  1118. Node->getFirstScheduleModifier());
  1119. if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
  1120. OS << ", ";
  1121. OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
  1122. Node->getSecondScheduleModifier());
  1123. }
  1124. OS << ": ";
  1125. }
  1126. OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
  1127. if (auto *E = Node->getChunkSize()) {
  1128. OS << ", ";
  1129. E->printPretty(OS, nullptr, Policy);
  1130. }
  1131. OS << ")";
  1132. }
  1133. void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
  1134. OS << "ordered";
  1135. if (auto *Num = Node->getNumForLoops()) {
  1136. OS << "(";
  1137. Num->printPretty(OS, nullptr, Policy, 0);
  1138. OS << ")";
  1139. }
  1140. }
  1141. void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
  1142. OS << "nowait";
  1143. }
  1144. void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
  1145. OS << "untied";
  1146. }
  1147. void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
  1148. OS << "nogroup";
  1149. }
  1150. void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
  1151. OS << "mergeable";
  1152. }
  1153. void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
  1154. void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
  1155. void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
  1156. OS << "update";
  1157. }
  1158. void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
  1159. OS << "capture";
  1160. }
  1161. void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
  1162. OS << "seq_cst";
  1163. }
  1164. void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
  1165. OS << "threads";
  1166. }
  1167. void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
  1168. void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
  1169. OS << "device(";
  1170. Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
  1171. OS << ")";
  1172. }
  1173. void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
  1174. OS << "num_teams(";
  1175. Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
  1176. OS << ")";
  1177. }
  1178. void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
  1179. OS << "thread_limit(";
  1180. Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
  1181. OS << ")";
  1182. }
  1183. void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
  1184. OS << "priority(";
  1185. Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
  1186. OS << ")";
  1187. }
  1188. void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
  1189. OS << "grainsize(";
  1190. Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
  1191. OS << ")";
  1192. }
  1193. void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
  1194. OS << "num_tasks(";
  1195. Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
  1196. OS << ")";
  1197. }
  1198. void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
  1199. OS << "hint(";
  1200. Node->getHint()->printPretty(OS, nullptr, Policy, 0);
  1201. OS << ")";
  1202. }
  1203. template<typename T>
  1204. void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
  1205. for (typename T::varlist_iterator I = Node->varlist_begin(),
  1206. E = Node->varlist_end();
  1207. I != E; ++I) {
  1208. assert(*I && "Expected non-null Stmt");
  1209. OS << (I == Node->varlist_begin() ? StartSym : ',');
  1210. if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
  1211. if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
  1212. DRE->printPretty(OS, nullptr, Policy, 0);
  1213. else
  1214. DRE->getDecl()->printQualifiedName(OS);
  1215. } else
  1216. (*I)->printPretty(OS, nullptr, Policy, 0);
  1217. }
  1218. }
  1219. void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
  1220. if (Node->varlist_empty())
  1221. return;
  1222. OS << "allocate";
  1223. if (Expr *Allocator = Node->getAllocator()) {
  1224. OS << "(";
  1225. Allocator->printPretty(OS, nullptr, Policy, 0);
  1226. OS << ":";
  1227. VisitOMPClauseList(Node, ' ');
  1228. } else {
  1229. VisitOMPClauseList(Node, '(');
  1230. }
  1231. OS << ")";
  1232. }
  1233. void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
  1234. if (!Node->varlist_empty()) {
  1235. OS << "private";
  1236. VisitOMPClauseList(Node, '(');
  1237. OS << ")";
  1238. }
  1239. }
  1240. void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
  1241. if (!Node->varlist_empty()) {
  1242. OS << "firstprivate";
  1243. VisitOMPClauseList(Node, '(');
  1244. OS << ")";
  1245. }
  1246. }
  1247. void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
  1248. if (!Node->varlist_empty()) {
  1249. OS << "lastprivate";
  1250. VisitOMPClauseList(Node, '(');
  1251. OS << ")";
  1252. }
  1253. }
  1254. void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
  1255. if (!Node->varlist_empty()) {
  1256. OS << "shared";
  1257. VisitOMPClauseList(Node, '(');
  1258. OS << ")";
  1259. }
  1260. }
  1261. void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
  1262. if (!Node->varlist_empty()) {
  1263. OS << "reduction(";
  1264. NestedNameSpecifier *QualifierLoc =
  1265. Node->getQualifierLoc().getNestedNameSpecifier();
  1266. OverloadedOperatorKind OOK =
  1267. Node->getNameInfo().getName().getCXXOverloadedOperator();
  1268. if (QualifierLoc == nullptr && OOK != OO_None) {
  1269. // Print reduction identifier in C format
  1270. OS << getOperatorSpelling(OOK);
  1271. } else {
  1272. // Use C++ format
  1273. if (QualifierLoc != nullptr)
  1274. QualifierLoc->print(OS, Policy);
  1275. OS << Node->getNameInfo();
  1276. }
  1277. OS << ":";
  1278. VisitOMPClauseList(Node, ' ');
  1279. OS << ")";
  1280. }
  1281. }
  1282. void OMPClausePrinter::VisitOMPTaskReductionClause(
  1283. OMPTaskReductionClause *Node) {
  1284. if (!Node->varlist_empty()) {
  1285. OS << "task_reduction(";
  1286. NestedNameSpecifier *QualifierLoc =
  1287. Node->getQualifierLoc().getNestedNameSpecifier();
  1288. OverloadedOperatorKind OOK =
  1289. Node->getNameInfo().getName().getCXXOverloadedOperator();
  1290. if (QualifierLoc == nullptr && OOK != OO_None) {
  1291. // Print reduction identifier in C format
  1292. OS << getOperatorSpelling(OOK);
  1293. } else {
  1294. // Use C++ format
  1295. if (QualifierLoc != nullptr)
  1296. QualifierLoc->print(OS, Policy);
  1297. OS << Node->getNameInfo();
  1298. }
  1299. OS << ":";
  1300. VisitOMPClauseList(Node, ' ');
  1301. OS << ")";
  1302. }
  1303. }
  1304. void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
  1305. if (!Node->varlist_empty()) {
  1306. OS << "in_reduction(";
  1307. NestedNameSpecifier *QualifierLoc =
  1308. Node->getQualifierLoc().getNestedNameSpecifier();
  1309. OverloadedOperatorKind OOK =
  1310. Node->getNameInfo().getName().getCXXOverloadedOperator();
  1311. if (QualifierLoc == nullptr && OOK != OO_None) {
  1312. // Print reduction identifier in C format
  1313. OS << getOperatorSpelling(OOK);
  1314. } else {
  1315. // Use C++ format
  1316. if (QualifierLoc != nullptr)
  1317. QualifierLoc->print(OS, Policy);
  1318. OS << Node->getNameInfo();
  1319. }
  1320. OS << ":";
  1321. VisitOMPClauseList(Node, ' ');
  1322. OS << ")";
  1323. }
  1324. }
  1325. void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
  1326. if (!Node->varlist_empty()) {
  1327. OS << "linear";
  1328. if (Node->getModifierLoc().isValid()) {
  1329. OS << '('
  1330. << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
  1331. }
  1332. VisitOMPClauseList(Node, '(');
  1333. if (Node->getModifierLoc().isValid())
  1334. OS << ')';
  1335. if (Node->getStep() != nullptr) {
  1336. OS << ": ";
  1337. Node->getStep()->printPretty(OS, nullptr, Policy, 0);
  1338. }
  1339. OS << ")";
  1340. }
  1341. }
  1342. void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
  1343. if (!Node->varlist_empty()) {
  1344. OS << "aligned";
  1345. VisitOMPClauseList(Node, '(');
  1346. if (Node->getAlignment() != nullptr) {
  1347. OS << ": ";
  1348. Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
  1349. }
  1350. OS << ")";
  1351. }
  1352. }
  1353. void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
  1354. if (!Node->varlist_empty()) {
  1355. OS << "copyin";
  1356. VisitOMPClauseList(Node, '(');
  1357. OS << ")";
  1358. }
  1359. }
  1360. void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
  1361. if (!Node->varlist_empty()) {
  1362. OS << "copyprivate";
  1363. VisitOMPClauseList(Node, '(');
  1364. OS << ")";
  1365. }
  1366. }
  1367. void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
  1368. if (!Node->varlist_empty()) {
  1369. VisitOMPClauseList(Node, '(');
  1370. OS << ")";
  1371. }
  1372. }
  1373. void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
  1374. OS << "depend(";
  1375. OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
  1376. Node->getDependencyKind());
  1377. if (!Node->varlist_empty()) {
  1378. OS << " :";
  1379. VisitOMPClauseList(Node, ' ');
  1380. }
  1381. OS << ")";
  1382. }
  1383. void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
  1384. if (!Node->varlist_empty()) {
  1385. OS << "map(";
  1386. if (Node->getMapType() != OMPC_MAP_unknown) {
  1387. for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
  1388. if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
  1389. OS << getOpenMPSimpleClauseTypeName(OMPC_map,
  1390. Node->getMapTypeModifier(I));
  1391. if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
  1392. OS << '(';
  1393. NestedNameSpecifier *MapperNNS =
  1394. Node->getMapperQualifierLoc().getNestedNameSpecifier();
  1395. if (MapperNNS)
  1396. MapperNNS->print(OS, Policy);
  1397. OS << Node->getMapperIdInfo() << ')';
  1398. }
  1399. OS << ',';
  1400. }
  1401. }
  1402. OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
  1403. OS << ':';
  1404. }
  1405. VisitOMPClauseList(Node, ' ');
  1406. OS << ")";
  1407. }
  1408. }
  1409. void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
  1410. if (!Node->varlist_empty()) {
  1411. OS << "to";
  1412. DeclarationNameInfo MapperId = Node->getMapperIdInfo();
  1413. if (MapperId.getName() && !MapperId.getName().isEmpty()) {
  1414. OS << '(';
  1415. OS << "mapper(";
  1416. NestedNameSpecifier *MapperNNS =
  1417. Node->getMapperQualifierLoc().getNestedNameSpecifier();
  1418. if (MapperNNS)
  1419. MapperNNS->print(OS, Policy);
  1420. OS << MapperId << "):";
  1421. VisitOMPClauseList(Node, ' ');
  1422. } else {
  1423. VisitOMPClauseList(Node, '(');
  1424. }
  1425. OS << ")";
  1426. }
  1427. }
  1428. void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
  1429. if (!Node->varlist_empty()) {
  1430. OS << "from";
  1431. DeclarationNameInfo MapperId = Node->getMapperIdInfo();
  1432. if (MapperId.getName() && !MapperId.getName().isEmpty()) {
  1433. OS << '(';
  1434. OS << "mapper(";
  1435. NestedNameSpecifier *MapperNNS =
  1436. Node->getMapperQualifierLoc().getNestedNameSpecifier();
  1437. if (MapperNNS)
  1438. MapperNNS->print(OS, Policy);
  1439. OS << MapperId << "):";
  1440. VisitOMPClauseList(Node, ' ');
  1441. } else {
  1442. VisitOMPClauseList(Node, '(');
  1443. }
  1444. OS << ")";
  1445. }
  1446. }
  1447. void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
  1448. OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
  1449. OMPC_dist_schedule, Node->getDistScheduleKind());
  1450. if (auto *E = Node->getChunkSize()) {
  1451. OS << ", ";
  1452. E->printPretty(OS, nullptr, Policy);
  1453. }
  1454. OS << ")";
  1455. }
  1456. void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
  1457. OS << "defaultmap(";
  1458. OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
  1459. Node->getDefaultmapModifier());
  1460. OS << ": ";
  1461. OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
  1462. Node->getDefaultmapKind());
  1463. OS << ")";
  1464. }
  1465. void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
  1466. if (!Node->varlist_empty()) {
  1467. OS << "use_device_ptr";
  1468. VisitOMPClauseList(Node, '(');
  1469. OS << ")";
  1470. }
  1471. }
  1472. void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
  1473. if (!Node->varlist_empty()) {
  1474. OS << "is_device_ptr";
  1475. VisitOMPClauseList(Node, '(');
  1476. OS << ")";
  1477. }
  1478. }