OpenMPClause.cpp 55 KB

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