OpenMPClause.cpp 55 KB

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