OpenMPClause.cpp 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  1. //===- OpenMPClause.cpp - Classes for OpenMP clauses ----------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements the subclesses of Stmt class declared in OpenMPClause.h
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "clang/AST/OpenMPClause.h"
  14. #include "clang/AST/ASTContext.h"
  15. #include "clang/AST/Decl.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_flush:
  83. case OMPC_read:
  84. case OMPC_write:
  85. case OMPC_update:
  86. case OMPC_capture:
  87. case OMPC_seq_cst:
  88. case OMPC_depend:
  89. case OMPC_threads:
  90. case OMPC_simd:
  91. case OMPC_map:
  92. case OMPC_priority:
  93. case OMPC_grainsize:
  94. case OMPC_nogroup:
  95. case OMPC_num_tasks:
  96. case OMPC_hint:
  97. case OMPC_defaultmap:
  98. case OMPC_unknown:
  99. case OMPC_uniform:
  100. case OMPC_to:
  101. case OMPC_from:
  102. case OMPC_use_device_ptr:
  103. case OMPC_is_device_ptr:
  104. case OMPC_unified_address:
  105. case OMPC_unified_shared_memory:
  106. break;
  107. }
  108. return nullptr;
  109. }
  110. OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
  111. auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
  112. return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
  113. }
  114. const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
  115. switch (C->getClauseKind()) {
  116. case OMPC_lastprivate:
  117. return static_cast<const OMPLastprivateClause *>(C);
  118. case OMPC_reduction:
  119. return static_cast<const OMPReductionClause *>(C);
  120. case OMPC_task_reduction:
  121. return static_cast<const OMPTaskReductionClause *>(C);
  122. case OMPC_in_reduction:
  123. return static_cast<const OMPInReductionClause *>(C);
  124. case OMPC_linear:
  125. return static_cast<const OMPLinearClause *>(C);
  126. case OMPC_schedule:
  127. case OMPC_dist_schedule:
  128. case OMPC_firstprivate:
  129. case OMPC_default:
  130. case OMPC_proc_bind:
  131. case OMPC_if:
  132. case OMPC_final:
  133. case OMPC_num_threads:
  134. case OMPC_safelen:
  135. case OMPC_simdlen:
  136. case OMPC_collapse:
  137. case OMPC_private:
  138. case OMPC_shared:
  139. case OMPC_aligned:
  140. case OMPC_copyin:
  141. case OMPC_copyprivate:
  142. case OMPC_ordered:
  143. case OMPC_nowait:
  144. case OMPC_untied:
  145. case OMPC_mergeable:
  146. case OMPC_threadprivate:
  147. case OMPC_flush:
  148. case OMPC_read:
  149. case OMPC_write:
  150. case OMPC_update:
  151. case OMPC_capture:
  152. case OMPC_seq_cst:
  153. case OMPC_depend:
  154. case OMPC_device:
  155. case OMPC_threads:
  156. case OMPC_simd:
  157. case OMPC_map:
  158. case OMPC_num_teams:
  159. case OMPC_thread_limit:
  160. case OMPC_priority:
  161. case OMPC_grainsize:
  162. case OMPC_nogroup:
  163. case OMPC_num_tasks:
  164. case OMPC_hint:
  165. case OMPC_defaultmap:
  166. case OMPC_unknown:
  167. case OMPC_uniform:
  168. case OMPC_to:
  169. case OMPC_from:
  170. case OMPC_use_device_ptr:
  171. case OMPC_is_device_ptr:
  172. case OMPC_unified_address:
  173. case OMPC_unified_shared_memory:
  174. break;
  175. }
  176. return nullptr;
  177. }
  178. OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
  179. unsigned NumLoops,
  180. SourceLocation StartLoc,
  181. SourceLocation LParenLoc,
  182. SourceLocation EndLoc) {
  183. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
  184. auto *Clause =
  185. new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
  186. for (unsigned I = 0; I < NumLoops; ++I) {
  187. Clause->setLoopNumIterations(I, nullptr);
  188. Clause->setLoopCounter(I, nullptr);
  189. }
  190. return Clause;
  191. }
  192. OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
  193. unsigned NumLoops) {
  194. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
  195. auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
  196. for (unsigned I = 0; I < NumLoops; ++I) {
  197. Clause->setLoopNumIterations(I, nullptr);
  198. Clause->setLoopCounter(I, nullptr);
  199. }
  200. return Clause;
  201. }
  202. void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
  203. Expr *NumIterations) {
  204. assert(NumLoop < NumberOfLoops && "out of loops number.");
  205. getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
  206. }
  207. ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
  208. return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
  209. }
  210. void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
  211. assert(NumLoop < NumberOfLoops && "out of loops number.");
  212. getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
  213. }
  214. Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
  215. assert(NumLoop < NumberOfLoops && "out of loops number.");
  216. return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
  217. }
  218. const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
  219. assert(NumLoop < NumberOfLoops && "out of loops number.");
  220. return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
  221. }
  222. void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
  223. assert(VL.size() == varlist_size() &&
  224. "Number of private copies is not the same as the preallocated buffer");
  225. std::copy(VL.begin(), VL.end(), varlist_end());
  226. }
  227. OMPPrivateClause *
  228. OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
  229. SourceLocation LParenLoc, SourceLocation EndLoc,
  230. ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
  231. // Allocate space for private variables and initializer expressions.
  232. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
  233. OMPPrivateClause *Clause =
  234. new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
  235. Clause->setVarRefs(VL);
  236. Clause->setPrivateCopies(PrivateVL);
  237. return Clause;
  238. }
  239. OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
  240. unsigned N) {
  241. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
  242. return new (Mem) OMPPrivateClause(N);
  243. }
  244. void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
  245. assert(VL.size() == varlist_size() &&
  246. "Number of private copies is not the same as the preallocated buffer");
  247. std::copy(VL.begin(), VL.end(), varlist_end());
  248. }
  249. void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
  250. assert(VL.size() == varlist_size() &&
  251. "Number of inits is not the same as the preallocated buffer");
  252. std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
  253. }
  254. OMPFirstprivateClause *
  255. OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
  256. SourceLocation LParenLoc, SourceLocation EndLoc,
  257. ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
  258. ArrayRef<Expr *> InitVL, Stmt *PreInit) {
  259. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
  260. OMPFirstprivateClause *Clause =
  261. new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
  262. Clause->setVarRefs(VL);
  263. Clause->setPrivateCopies(PrivateVL);
  264. Clause->setInits(InitVL);
  265. Clause->setPreInitStmt(PreInit);
  266. return Clause;
  267. }
  268. OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
  269. unsigned N) {
  270. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
  271. return new (Mem) OMPFirstprivateClause(N);
  272. }
  273. void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
  274. assert(PrivateCopies.size() == varlist_size() &&
  275. "Number of private copies is not the same as the preallocated buffer");
  276. std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
  277. }
  278. void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
  279. assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
  280. "not the same as the "
  281. "preallocated buffer");
  282. std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
  283. }
  284. void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
  285. assert(DstExprs.size() == varlist_size() && "Number of destination "
  286. "expressions is not the same as "
  287. "the preallocated buffer");
  288. std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
  289. }
  290. void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
  291. assert(AssignmentOps.size() == varlist_size() &&
  292. "Number of assignment expressions is not the same as the preallocated "
  293. "buffer");
  294. std::copy(AssignmentOps.begin(), AssignmentOps.end(),
  295. getDestinationExprs().end());
  296. }
  297. OMPLastprivateClause *OMPLastprivateClause::Create(
  298. const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  299. SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
  300. ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit,
  301. Expr *PostUpdate) {
  302. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
  303. OMPLastprivateClause *Clause =
  304. new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
  305. Clause->setVarRefs(VL);
  306. Clause->setSourceExprs(SrcExprs);
  307. Clause->setDestinationExprs(DstExprs);
  308. Clause->setAssignmentOps(AssignmentOps);
  309. Clause->setPreInitStmt(PreInit);
  310. Clause->setPostUpdateExpr(PostUpdate);
  311. return Clause;
  312. }
  313. OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
  314. unsigned N) {
  315. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
  316. return new (Mem) OMPLastprivateClause(N);
  317. }
  318. OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
  319. SourceLocation StartLoc,
  320. SourceLocation LParenLoc,
  321. SourceLocation EndLoc,
  322. ArrayRef<Expr *> VL) {
  323. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
  324. OMPSharedClause *Clause =
  325. new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
  326. Clause->setVarRefs(VL);
  327. return Clause;
  328. }
  329. OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
  330. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
  331. return new (Mem) OMPSharedClause(N);
  332. }
  333. void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
  334. assert(PL.size() == varlist_size() &&
  335. "Number of privates is not the same as the preallocated buffer");
  336. std::copy(PL.begin(), PL.end(), varlist_end());
  337. }
  338. void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
  339. assert(IL.size() == varlist_size() &&
  340. "Number of inits is not the same as the preallocated buffer");
  341. std::copy(IL.begin(), IL.end(), getPrivates().end());
  342. }
  343. void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
  344. assert(UL.size() == varlist_size() &&
  345. "Number of updates is not the same as the preallocated buffer");
  346. std::copy(UL.begin(), UL.end(), getInits().end());
  347. }
  348. void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
  349. assert(FL.size() == varlist_size() &&
  350. "Number of final updates is not the same as the preallocated buffer");
  351. std::copy(FL.begin(), FL.end(), getUpdates().end());
  352. }
  353. OMPLinearClause *OMPLinearClause::Create(
  354. const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  355. OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
  356. SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
  357. ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
  358. Stmt *PreInit, Expr *PostUpdate) {
  359. // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
  360. // (Step and CalcStep).
  361. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2));
  362. OMPLinearClause *Clause = new (Mem) OMPLinearClause(
  363. StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
  364. Clause->setVarRefs(VL);
  365. Clause->setPrivates(PL);
  366. Clause->setInits(IL);
  367. // Fill update and final expressions with zeroes, they are provided later,
  368. // after the directive construction.
  369. std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
  370. nullptr);
  371. std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
  372. nullptr);
  373. Clause->setStep(Step);
  374. Clause->setCalcStep(CalcStep);
  375. Clause->setPreInitStmt(PreInit);
  376. Clause->setPostUpdateExpr(PostUpdate);
  377. return Clause;
  378. }
  379. OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
  380. unsigned NumVars) {
  381. // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
  382. // (Step and CalcStep).
  383. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2));
  384. return new (Mem) OMPLinearClause(NumVars);
  385. }
  386. OMPAlignedClause *
  387. OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
  388. SourceLocation LParenLoc, SourceLocation ColonLoc,
  389. SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
  390. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
  391. OMPAlignedClause *Clause = new (Mem)
  392. OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
  393. Clause->setVarRefs(VL);
  394. Clause->setAlignment(A);
  395. return Clause;
  396. }
  397. OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
  398. unsigned NumVars) {
  399. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
  400. return new (Mem) OMPAlignedClause(NumVars);
  401. }
  402. void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
  403. assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
  404. "not the same as the "
  405. "preallocated buffer");
  406. std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
  407. }
  408. void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
  409. assert(DstExprs.size() == varlist_size() && "Number of destination "
  410. "expressions is not the same as "
  411. "the preallocated buffer");
  412. std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
  413. }
  414. void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
  415. assert(AssignmentOps.size() == varlist_size() &&
  416. "Number of assignment expressions is not the same as the preallocated "
  417. "buffer");
  418. std::copy(AssignmentOps.begin(), AssignmentOps.end(),
  419. getDestinationExprs().end());
  420. }
  421. OMPCopyinClause *OMPCopyinClause::Create(
  422. const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  423. SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
  424. ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
  425. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
  426. OMPCopyinClause *Clause =
  427. new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
  428. Clause->setVarRefs(VL);
  429. Clause->setSourceExprs(SrcExprs);
  430. Clause->setDestinationExprs(DstExprs);
  431. Clause->setAssignmentOps(AssignmentOps);
  432. return Clause;
  433. }
  434. OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
  435. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
  436. return new (Mem) OMPCopyinClause(N);
  437. }
  438. void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
  439. assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
  440. "not the same as the "
  441. "preallocated buffer");
  442. std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
  443. }
  444. void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
  445. assert(DstExprs.size() == varlist_size() && "Number of destination "
  446. "expressions is not the same as "
  447. "the preallocated buffer");
  448. std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
  449. }
  450. void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
  451. assert(AssignmentOps.size() == varlist_size() &&
  452. "Number of assignment expressions is not the same as the preallocated "
  453. "buffer");
  454. std::copy(AssignmentOps.begin(), AssignmentOps.end(),
  455. getDestinationExprs().end());
  456. }
  457. OMPCopyprivateClause *OMPCopyprivateClause::Create(
  458. const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  459. SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
  460. ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
  461. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
  462. OMPCopyprivateClause *Clause =
  463. new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
  464. Clause->setVarRefs(VL);
  465. Clause->setSourceExprs(SrcExprs);
  466. Clause->setDestinationExprs(DstExprs);
  467. Clause->setAssignmentOps(AssignmentOps);
  468. return Clause;
  469. }
  470. OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
  471. unsigned N) {
  472. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
  473. return new (Mem) OMPCopyprivateClause(N);
  474. }
  475. void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
  476. assert(Privates.size() == varlist_size() &&
  477. "Number of private copies is not the same as the preallocated buffer");
  478. std::copy(Privates.begin(), Privates.end(), varlist_end());
  479. }
  480. void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
  481. assert(
  482. LHSExprs.size() == varlist_size() &&
  483. "Number of LHS expressions is not the same as the preallocated buffer");
  484. std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
  485. }
  486. void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
  487. assert(
  488. RHSExprs.size() == varlist_size() &&
  489. "Number of RHS expressions is not the same as the preallocated buffer");
  490. std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
  491. }
  492. void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
  493. assert(ReductionOps.size() == varlist_size() && "Number of reduction "
  494. "expressions is not the same "
  495. "as the preallocated buffer");
  496. std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
  497. }
  498. OMPReductionClause *OMPReductionClause::Create(
  499. const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  500. SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
  501. NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
  502. ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
  503. ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
  504. Expr *PostUpdate) {
  505. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
  506. OMPReductionClause *Clause = new (Mem) OMPReductionClause(
  507. StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
  508. Clause->setVarRefs(VL);
  509. Clause->setPrivates(Privates);
  510. Clause->setLHSExprs(LHSExprs);
  511. Clause->setRHSExprs(RHSExprs);
  512. Clause->setReductionOps(ReductionOps);
  513. Clause->setPreInitStmt(PreInit);
  514. Clause->setPostUpdateExpr(PostUpdate);
  515. return Clause;
  516. }
  517. OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
  518. unsigned N) {
  519. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
  520. return new (Mem) OMPReductionClause(N);
  521. }
  522. void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
  523. assert(Privates.size() == varlist_size() &&
  524. "Number of private copies is not the same as the preallocated buffer");
  525. std::copy(Privates.begin(), Privates.end(), varlist_end());
  526. }
  527. void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
  528. assert(
  529. LHSExprs.size() == varlist_size() &&
  530. "Number of LHS expressions is not the same as the preallocated buffer");
  531. std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
  532. }
  533. void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
  534. assert(
  535. RHSExprs.size() == varlist_size() &&
  536. "Number of RHS expressions is not the same as the preallocated buffer");
  537. std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
  538. }
  539. void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
  540. assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
  541. "expressions is not the same "
  542. "as the preallocated buffer");
  543. std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
  544. }
  545. OMPTaskReductionClause *OMPTaskReductionClause::Create(
  546. const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  547. SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
  548. NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
  549. ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
  550. ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
  551. Expr *PostUpdate) {
  552. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
  553. OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
  554. StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
  555. Clause->setVarRefs(VL);
  556. Clause->setPrivates(Privates);
  557. Clause->setLHSExprs(LHSExprs);
  558. Clause->setRHSExprs(RHSExprs);
  559. Clause->setReductionOps(ReductionOps);
  560. Clause->setPreInitStmt(PreInit);
  561. Clause->setPostUpdateExpr(PostUpdate);
  562. return Clause;
  563. }
  564. OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
  565. unsigned N) {
  566. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
  567. return new (Mem) OMPTaskReductionClause(N);
  568. }
  569. void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
  570. assert(Privates.size() == varlist_size() &&
  571. "Number of private copies is not the same as the preallocated buffer");
  572. std::copy(Privates.begin(), Privates.end(), varlist_end());
  573. }
  574. void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
  575. assert(
  576. LHSExprs.size() == varlist_size() &&
  577. "Number of LHS expressions is not the same as the preallocated buffer");
  578. std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
  579. }
  580. void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
  581. assert(
  582. RHSExprs.size() == varlist_size() &&
  583. "Number of RHS expressions is not the same as the preallocated buffer");
  584. std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
  585. }
  586. void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
  587. assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
  588. "expressions is not the same "
  589. "as the preallocated buffer");
  590. std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
  591. }
  592. void OMPInReductionClause::setTaskgroupDescriptors(
  593. ArrayRef<Expr *> TaskgroupDescriptors) {
  594. assert(TaskgroupDescriptors.size() == varlist_size() &&
  595. "Number of in reduction descriptors is not the same as the "
  596. "preallocated buffer");
  597. std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
  598. getReductionOps().end());
  599. }
  600. OMPInReductionClause *OMPInReductionClause::Create(
  601. const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  602. SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
  603. NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
  604. ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
  605. ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
  606. ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
  607. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
  608. OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
  609. StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
  610. Clause->setVarRefs(VL);
  611. Clause->setPrivates(Privates);
  612. Clause->setLHSExprs(LHSExprs);
  613. Clause->setRHSExprs(RHSExprs);
  614. Clause->setReductionOps(ReductionOps);
  615. Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
  616. Clause->setPreInitStmt(PreInit);
  617. Clause->setPostUpdateExpr(PostUpdate);
  618. return Clause;
  619. }
  620. OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
  621. unsigned N) {
  622. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
  623. return new (Mem) OMPInReductionClause(N);
  624. }
  625. OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
  626. SourceLocation StartLoc,
  627. SourceLocation LParenLoc,
  628. SourceLocation EndLoc,
  629. ArrayRef<Expr *> VL) {
  630. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
  631. OMPFlushClause *Clause =
  632. new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
  633. Clause->setVarRefs(VL);
  634. return Clause;
  635. }
  636. OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
  637. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
  638. return new (Mem) OMPFlushClause(N);
  639. }
  640. OMPDependClause *
  641. OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
  642. SourceLocation LParenLoc, SourceLocation EndLoc,
  643. OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
  644. SourceLocation ColonLoc, ArrayRef<Expr *> VL,
  645. unsigned NumLoops) {
  646. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
  647. OMPDependClause *Clause = new (Mem)
  648. OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
  649. Clause->setVarRefs(VL);
  650. Clause->setDependencyKind(DepKind);
  651. Clause->setDependencyLoc(DepLoc);
  652. Clause->setColonLoc(ColonLoc);
  653. for (unsigned I = 0 ; I < NumLoops; ++I)
  654. Clause->setLoopData(I, nullptr);
  655. return Clause;
  656. }
  657. OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
  658. unsigned NumLoops) {
  659. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
  660. return new (Mem) OMPDependClause(N, NumLoops);
  661. }
  662. void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
  663. assert((getDependencyKind() == OMPC_DEPEND_sink ||
  664. getDependencyKind() == OMPC_DEPEND_source) &&
  665. NumLoop < NumLoops &&
  666. "Expected sink or source depend + loop index must be less number of "
  667. "loops.");
  668. auto It = std::next(getVarRefs().end(), NumLoop);
  669. *It = Cnt;
  670. }
  671. Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
  672. assert((getDependencyKind() == OMPC_DEPEND_sink ||
  673. getDependencyKind() == OMPC_DEPEND_source) &&
  674. NumLoop < NumLoops &&
  675. "Expected sink or source depend + loop index must be less number of "
  676. "loops.");
  677. auto It = std::next(getVarRefs().end(), NumLoop);
  678. return *It;
  679. }
  680. const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
  681. assert((getDependencyKind() == OMPC_DEPEND_sink ||
  682. getDependencyKind() == OMPC_DEPEND_source) &&
  683. NumLoop < NumLoops &&
  684. "Expected sink or source depend + loop index must be less number of "
  685. "loops.");
  686. auto It = std::next(getVarRefs().end(), NumLoop);
  687. return *It;
  688. }
  689. unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
  690. MappableExprComponentListsRef ComponentLists) {
  691. unsigned TotalNum = 0u;
  692. for (auto &C : ComponentLists)
  693. TotalNum += C.size();
  694. return TotalNum;
  695. }
  696. unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
  697. ArrayRef<const ValueDecl *> Declarations) {
  698. unsigned TotalNum = 0u;
  699. llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
  700. for (const ValueDecl *D : Declarations) {
  701. const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
  702. if (Cache.count(VD))
  703. continue;
  704. ++TotalNum;
  705. Cache.insert(VD);
  706. }
  707. return TotalNum;
  708. }
  709. OMPMapClause *
  710. OMPMapClause::Create(const ASTContext &C, SourceLocation StartLoc,
  711. SourceLocation LParenLoc, SourceLocation EndLoc,
  712. ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
  713. MappableExprComponentListsRef ComponentLists,
  714. OpenMPMapClauseKind TypeModifier, OpenMPMapClauseKind Type,
  715. bool TypeIsImplicit, SourceLocation TypeLoc) {
  716. unsigned NumVars = Vars.size();
  717. unsigned NumUniqueDeclarations =
  718. getUniqueDeclarationsTotalNumber(Declarations);
  719. unsigned NumComponentLists = ComponentLists.size();
  720. unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
  721. // We need to allocate:
  722. // NumVars x Expr* - we have an original list expression for each clause list
  723. // entry.
  724. // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
  725. // with each component list.
  726. // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
  727. // number of lists for each unique declaration and the size of each component
  728. // list.
  729. // NumComponents x MappableComponent - the total of all the components in all
  730. // the lists.
  731. void *Mem = C.Allocate(
  732. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  733. OMPClauseMappableExprCommon::MappableComponent>(
  734. NumVars, NumUniqueDeclarations,
  735. NumUniqueDeclarations + NumComponentLists, NumComponents));
  736. OMPMapClause *Clause = new (Mem) OMPMapClause(
  737. TypeModifier, Type, TypeIsImplicit, TypeLoc, StartLoc, LParenLoc, EndLoc,
  738. NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents);
  739. Clause->setVarRefs(Vars);
  740. Clause->setClauseInfo(Declarations, ComponentLists);
  741. Clause->setMapTypeModifier(TypeModifier);
  742. Clause->setMapType(Type);
  743. Clause->setMapLoc(TypeLoc);
  744. return Clause;
  745. }
  746. OMPMapClause *OMPMapClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
  747. unsigned NumUniqueDeclarations,
  748. unsigned NumComponentLists,
  749. unsigned NumComponents) {
  750. void *Mem = C.Allocate(
  751. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  752. OMPClauseMappableExprCommon::MappableComponent>(
  753. NumVars, NumUniqueDeclarations,
  754. NumUniqueDeclarations + NumComponentLists, NumComponents));
  755. return new (Mem) OMPMapClause(NumVars, NumUniqueDeclarations,
  756. NumComponentLists, NumComponents);
  757. }
  758. OMPToClause *OMPToClause::Create(const ASTContext &C, SourceLocation StartLoc,
  759. SourceLocation LParenLoc,
  760. SourceLocation EndLoc, ArrayRef<Expr *> Vars,
  761. ArrayRef<ValueDecl *> Declarations,
  762. MappableExprComponentListsRef ComponentLists) {
  763. unsigned NumVars = Vars.size();
  764. unsigned NumUniqueDeclarations =
  765. getUniqueDeclarationsTotalNumber(Declarations);
  766. unsigned NumComponentLists = ComponentLists.size();
  767. unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
  768. // We need to allocate:
  769. // NumVars x Expr* - we have an original list expression for each clause list
  770. // entry.
  771. // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
  772. // with each component list.
  773. // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
  774. // number of lists for each unique declaration and the size of each component
  775. // list.
  776. // NumComponents x MappableComponent - the total of all the components in all
  777. // the lists.
  778. void *Mem = C.Allocate(
  779. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  780. OMPClauseMappableExprCommon::MappableComponent>(
  781. NumVars, NumUniqueDeclarations,
  782. NumUniqueDeclarations + NumComponentLists, NumComponents));
  783. OMPToClause *Clause = new (Mem)
  784. OMPToClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
  785. NumComponentLists, NumComponents);
  786. Clause->setVarRefs(Vars);
  787. Clause->setClauseInfo(Declarations, ComponentLists);
  788. return Clause;
  789. }
  790. OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
  791. unsigned NumUniqueDeclarations,
  792. unsigned NumComponentLists,
  793. unsigned NumComponents) {
  794. void *Mem = C.Allocate(
  795. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  796. OMPClauseMappableExprCommon::MappableComponent>(
  797. NumVars, NumUniqueDeclarations,
  798. NumUniqueDeclarations + NumComponentLists, NumComponents));
  799. return new (Mem) OMPToClause(NumVars, NumUniqueDeclarations,
  800. NumComponentLists, NumComponents);
  801. }
  802. OMPFromClause *
  803. OMPFromClause::Create(const ASTContext &C, SourceLocation StartLoc,
  804. SourceLocation LParenLoc, SourceLocation EndLoc,
  805. ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
  806. MappableExprComponentListsRef ComponentLists) {
  807. unsigned NumVars = Vars.size();
  808. unsigned NumUniqueDeclarations =
  809. getUniqueDeclarationsTotalNumber(Declarations);
  810. unsigned NumComponentLists = ComponentLists.size();
  811. unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
  812. // We need to allocate:
  813. // NumVars x Expr* - we have an original list expression for each clause list
  814. // entry.
  815. // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
  816. // with each component list.
  817. // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
  818. // number of lists for each unique declaration and the size of each component
  819. // list.
  820. // NumComponents x MappableComponent - the total of all the components in all
  821. // the lists.
  822. void *Mem = C.Allocate(
  823. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  824. OMPClauseMappableExprCommon::MappableComponent>(
  825. NumVars, NumUniqueDeclarations,
  826. NumUniqueDeclarations + NumComponentLists, NumComponents));
  827. OMPFromClause *Clause = new (Mem)
  828. OMPFromClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
  829. NumComponentLists, NumComponents);
  830. Clause->setVarRefs(Vars);
  831. Clause->setClauseInfo(Declarations, ComponentLists);
  832. return Clause;
  833. }
  834. OMPFromClause *OMPFromClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
  835. unsigned NumUniqueDeclarations,
  836. unsigned NumComponentLists,
  837. unsigned NumComponents) {
  838. void *Mem = C.Allocate(
  839. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  840. OMPClauseMappableExprCommon::MappableComponent>(
  841. NumVars, NumUniqueDeclarations,
  842. NumUniqueDeclarations + NumComponentLists, NumComponents));
  843. return new (Mem) OMPFromClause(NumVars, NumUniqueDeclarations,
  844. NumComponentLists, NumComponents);
  845. }
  846. void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
  847. assert(VL.size() == varlist_size() &&
  848. "Number of private copies is not the same as the preallocated buffer");
  849. std::copy(VL.begin(), VL.end(), varlist_end());
  850. }
  851. void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
  852. assert(VL.size() == varlist_size() &&
  853. "Number of inits is not the same as the preallocated buffer");
  854. std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
  855. }
  856. OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
  857. const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  858. SourceLocation EndLoc, ArrayRef<Expr *> Vars, ArrayRef<Expr *> PrivateVars,
  859. ArrayRef<Expr *> Inits, ArrayRef<ValueDecl *> Declarations,
  860. MappableExprComponentListsRef ComponentLists) {
  861. unsigned NumVars = Vars.size();
  862. unsigned NumUniqueDeclarations =
  863. getUniqueDeclarationsTotalNumber(Declarations);
  864. unsigned NumComponentLists = ComponentLists.size();
  865. unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
  866. // We need to allocate:
  867. // 3 x NumVars x Expr* - we have an original list expression for each clause
  868. // list entry and an equal number of private copies and inits.
  869. // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
  870. // with each component list.
  871. // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
  872. // number of lists for each unique declaration and the size of each component
  873. // list.
  874. // NumComponents x MappableComponent - the total of all the components in all
  875. // the lists.
  876. void *Mem = C.Allocate(
  877. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  878. OMPClauseMappableExprCommon::MappableComponent>(
  879. 3 * NumVars, NumUniqueDeclarations,
  880. NumUniqueDeclarations + NumComponentLists, NumComponents));
  881. OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(
  882. StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
  883. NumComponentLists, NumComponents);
  884. Clause->setVarRefs(Vars);
  885. Clause->setPrivateCopies(PrivateVars);
  886. Clause->setInits(Inits);
  887. Clause->setClauseInfo(Declarations, ComponentLists);
  888. return Clause;
  889. }
  890. OMPUseDevicePtrClause *OMPUseDevicePtrClause::CreateEmpty(
  891. const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations,
  892. unsigned NumComponentLists, unsigned NumComponents) {
  893. void *Mem = C.Allocate(
  894. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  895. OMPClauseMappableExprCommon::MappableComponent>(
  896. 3 * NumVars, NumUniqueDeclarations,
  897. NumUniqueDeclarations + NumComponentLists, NumComponents));
  898. return new (Mem) OMPUseDevicePtrClause(NumVars, NumUniqueDeclarations,
  899. NumComponentLists, NumComponents);
  900. }
  901. OMPIsDevicePtrClause *
  902. OMPIsDevicePtrClause::Create(const ASTContext &C, SourceLocation StartLoc,
  903. SourceLocation LParenLoc, SourceLocation EndLoc,
  904. ArrayRef<Expr *> Vars,
  905. ArrayRef<ValueDecl *> Declarations,
  906. MappableExprComponentListsRef ComponentLists) {
  907. unsigned NumVars = Vars.size();
  908. unsigned NumUniqueDeclarations =
  909. getUniqueDeclarationsTotalNumber(Declarations);
  910. unsigned NumComponentLists = ComponentLists.size();
  911. unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
  912. // We need to allocate:
  913. // NumVars x Expr* - we have an original list expression for each clause list
  914. // entry.
  915. // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
  916. // with each component list.
  917. // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
  918. // number of lists for each unique declaration and the size of each component
  919. // list.
  920. // NumComponents x MappableComponent - the total of all the components in all
  921. // the lists.
  922. void *Mem = C.Allocate(
  923. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  924. OMPClauseMappableExprCommon::MappableComponent>(
  925. NumVars, NumUniqueDeclarations,
  926. NumUniqueDeclarations + NumComponentLists, NumComponents));
  927. OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(
  928. StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
  929. NumComponentLists, NumComponents);
  930. Clause->setVarRefs(Vars);
  931. Clause->setClauseInfo(Declarations, ComponentLists);
  932. return Clause;
  933. }
  934. OMPIsDevicePtrClause *OMPIsDevicePtrClause::CreateEmpty(
  935. const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations,
  936. unsigned NumComponentLists, unsigned NumComponents) {
  937. void *Mem = C.Allocate(
  938. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  939. OMPClauseMappableExprCommon::MappableComponent>(
  940. NumVars, NumUniqueDeclarations,
  941. NumUniqueDeclarations + NumComponentLists, NumComponents));
  942. return new (Mem) OMPIsDevicePtrClause(NumVars, NumUniqueDeclarations,
  943. NumComponentLists, NumComponents);
  944. }