blob: 9dcf5c19201ab88a07e4a2b076b34518f11eb365 [file] [log] [blame]
James Y Knightb8bfd962015-10-02 13:41:04 +00001//===--- 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
14#include "clang/AST/OpenMPClause.h"
15
16#include "clang/AST/ASTContext.h"
17
18using namespace clang;
19
20OMPClause::child_range OMPClause::children() {
21 switch (getClauseKind()) {
22 default:
23 break;
24#define OPENMP_CLAUSE(Name, Class) \
25 case OMPC_##Name: \
26 return static_cast<Class *>(this)->children();
27#include "clang/Basic/OpenMPKinds.def"
28 }
29 llvm_unreachable("unknown OMPClause");
30}
31
Alexey Bataev3392d762016-02-16 11:18:12 +000032OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
33 auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
34 return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr;
35}
36
37const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
38 switch (C->getClauseKind()) {
39 case OMPC_schedule:
40 return static_cast<const OMPScheduleClause *>(C);
41 case OMPC_dist_schedule:
42 return static_cast<const OMPDistScheduleClause *>(C);
Alexey Bataev417089f2016-02-17 13:19:37 +000043 case OMPC_firstprivate:
44 return static_cast<const OMPFirstprivateClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +000045 case OMPC_lastprivate:
46 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +000047 case OMPC_reduction:
48 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +000049 case OMPC_task_reduction:
50 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +000051 case OMPC_in_reduction:
52 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +000053 case OMPC_linear:
54 return static_cast<const OMPLinearClause *>(C);
Arpith Chacko Jacobfe4890a2017-01-18 20:40:48 +000055 case OMPC_if:
56 return static_cast<const OMPIfClause *>(C);
Arpith Chacko Jacob33c849a2017-01-25 00:57:16 +000057 case OMPC_num_threads:
58 return static_cast<const OMPNumThreadsClause *>(C);
Arpith Chacko Jacobbc126342017-01-25 11:28:18 +000059 case OMPC_num_teams:
60 return static_cast<const OMPNumTeamsClause *>(C);
Arpith Chacko Jacob7ecc0b72017-01-25 11:44:35 +000061 case OMPC_thread_limit:
62 return static_cast<const OMPThreadLimitClause *>(C);
Alexey Bataev3392d762016-02-16 11:18:12 +000063 case OMPC_default:
64 case OMPC_proc_bind:
Alexey Bataev3392d762016-02-16 11:18:12 +000065 case OMPC_final:
Alexey Bataev3392d762016-02-16 11:18:12 +000066 case OMPC_safelen:
67 case OMPC_simdlen:
68 case OMPC_collapse:
69 case OMPC_private:
Alexey Bataev005248a2016-02-25 05:25:57 +000070 case OMPC_shared:
Alexey Bataev005248a2016-02-25 05:25:57 +000071 case OMPC_aligned:
72 case OMPC_copyin:
73 case OMPC_copyprivate:
74 case OMPC_ordered:
75 case OMPC_nowait:
76 case OMPC_untied:
77 case OMPC_mergeable:
78 case OMPC_threadprivate:
79 case OMPC_flush:
80 case OMPC_read:
81 case OMPC_write:
82 case OMPC_update:
83 case OMPC_capture:
84 case OMPC_seq_cst:
85 case OMPC_depend:
86 case OMPC_device:
87 case OMPC_threads:
88 case OMPC_simd:
89 case OMPC_map:
Alexey Bataev005248a2016-02-25 05:25:57 +000090 case OMPC_priority:
91 case OMPC_grainsize:
92 case OMPC_nogroup:
93 case OMPC_num_tasks:
94 case OMPC_hint:
95 case OMPC_defaultmap:
96 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +000097 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +000098 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +000099 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000100 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000101 case OMPC_is_device_ptr:
Alexey Bataev005248a2016-02-25 05:25:57 +0000102 break;
103 }
104
105 return nullptr;
106}
107
108OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
109 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
110 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
111}
112
113const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
114 switch (C->getClauseKind()) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000115 case OMPC_lastprivate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000116 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000117 case OMPC_reduction:
118 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +0000119 case OMPC_task_reduction:
120 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000121 case OMPC_in_reduction:
122 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000123 case OMPC_linear:
124 return static_cast<const OMPLinearClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000125 case OMPC_schedule:
126 case OMPC_dist_schedule:
127 case OMPC_firstprivate:
128 case OMPC_default:
129 case OMPC_proc_bind:
130 case OMPC_if:
131 case OMPC_final:
132 case OMPC_num_threads:
133 case OMPC_safelen:
134 case OMPC_simdlen:
135 case OMPC_collapse:
136 case OMPC_private:
Alexey Bataev3392d762016-02-16 11:18:12 +0000137 case OMPC_shared:
Alexey Bataev3392d762016-02-16 11:18:12 +0000138 case OMPC_aligned:
139 case OMPC_copyin:
140 case OMPC_copyprivate:
141 case OMPC_ordered:
142 case OMPC_nowait:
143 case OMPC_untied:
144 case OMPC_mergeable:
145 case OMPC_threadprivate:
146 case OMPC_flush:
147 case OMPC_read:
148 case OMPC_write:
149 case OMPC_update:
150 case OMPC_capture:
151 case OMPC_seq_cst:
152 case OMPC_depend:
153 case OMPC_device:
154 case OMPC_threads:
155 case OMPC_simd:
156 case OMPC_map:
157 case OMPC_num_teams:
158 case OMPC_thread_limit:
159 case OMPC_priority:
160 case OMPC_grainsize:
161 case OMPC_nogroup:
162 case OMPC_num_tasks:
163 case OMPC_hint:
164 case OMPC_defaultmap:
165 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000166 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000167 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000168 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000169 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000170 case OMPC_is_device_ptr:
Alexey Bataev3392d762016-02-16 11:18:12 +0000171 break;
172 }
173
174 return nullptr;
175}
176
James Y Knightb8bfd962015-10-02 13:41:04 +0000177void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
178 assert(VL.size() == varlist_size() &&
179 "Number of private copies is not the same as the preallocated buffer");
180 std::copy(VL.begin(), VL.end(), varlist_end());
181}
182
183OMPPrivateClause *
184OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
185 SourceLocation LParenLoc, SourceLocation EndLoc,
186 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
187 // Allocate space for private variables and initializer expressions.
James Y Knight374fd202016-01-01 00:38:24 +0000188 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000189 OMPPrivateClause *Clause =
190 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
191 Clause->setVarRefs(VL);
192 Clause->setPrivateCopies(PrivateVL);
193 return Clause;
194}
195
196OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
197 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000198 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000199 return new (Mem) OMPPrivateClause(N);
200}
201
202void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
203 assert(VL.size() == varlist_size() &&
204 "Number of private copies is not the same as the preallocated buffer");
205 std::copy(VL.begin(), VL.end(), varlist_end());
206}
207
208void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
209 assert(VL.size() == varlist_size() &&
210 "Number of inits is not the same as the preallocated buffer");
211 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
212}
213
214OMPFirstprivateClause *
215OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
216 SourceLocation LParenLoc, SourceLocation EndLoc,
217 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
Alexey Bataev417089f2016-02-17 13:19:37 +0000218 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
James Y Knight374fd202016-01-01 00:38:24 +0000219 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000220 OMPFirstprivateClause *Clause =
221 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
222 Clause->setVarRefs(VL);
223 Clause->setPrivateCopies(PrivateVL);
224 Clause->setInits(InitVL);
Alexey Bataev417089f2016-02-17 13:19:37 +0000225 Clause->setPreInitStmt(PreInit);
James Y Knightb8bfd962015-10-02 13:41:04 +0000226 return Clause;
227}
228
229OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
230 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000231 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000232 return new (Mem) OMPFirstprivateClause(N);
233}
234
235void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
236 assert(PrivateCopies.size() == varlist_size() &&
237 "Number of private copies is not the same as the preallocated buffer");
238 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
239}
240
241void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
242 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
243 "not the same as the "
244 "preallocated buffer");
245 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
246}
247
248void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
249 assert(DstExprs.size() == varlist_size() && "Number of destination "
250 "expressions is not the same as "
251 "the preallocated buffer");
252 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
253}
254
255void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
256 assert(AssignmentOps.size() == varlist_size() &&
257 "Number of assignment expressions is not the same as the preallocated "
258 "buffer");
259 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
260 getDestinationExprs().end());
261}
262
263OMPLastprivateClause *OMPLastprivateClause::Create(
264 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
265 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
Alexey Bataev005248a2016-02-25 05:25:57 +0000266 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit,
267 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000268 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000269 OMPLastprivateClause *Clause =
270 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
271 Clause->setVarRefs(VL);
272 Clause->setSourceExprs(SrcExprs);
273 Clause->setDestinationExprs(DstExprs);
274 Clause->setAssignmentOps(AssignmentOps);
Alexey Bataev005248a2016-02-25 05:25:57 +0000275 Clause->setPreInitStmt(PreInit);
276 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000277 return Clause;
278}
279
280OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
281 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000282 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000283 return new (Mem) OMPLastprivateClause(N);
284}
285
286OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
287 SourceLocation StartLoc,
288 SourceLocation LParenLoc,
289 SourceLocation EndLoc,
290 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000291 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000292 OMPSharedClause *Clause =
293 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
294 Clause->setVarRefs(VL);
295 return Clause;
296}
297
298OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000299 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000300 return new (Mem) OMPSharedClause(N);
301}
302
303void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
304 assert(PL.size() == varlist_size() &&
305 "Number of privates is not the same as the preallocated buffer");
306 std::copy(PL.begin(), PL.end(), varlist_end());
307}
308
309void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
310 assert(IL.size() == varlist_size() &&
311 "Number of inits is not the same as the preallocated buffer");
312 std::copy(IL.begin(), IL.end(), getPrivates().end());
313}
314
315void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
316 assert(UL.size() == varlist_size() &&
317 "Number of updates is not the same as the preallocated buffer");
318 std::copy(UL.begin(), UL.end(), getInits().end());
319}
320
321void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
322 assert(FL.size() == varlist_size() &&
323 "Number of final updates is not the same as the preallocated buffer");
324 std::copy(FL.begin(), FL.end(), getUpdates().end());
325}
326
327OMPLinearClause *OMPLinearClause::Create(
328 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
329 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
330 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
Alexey Bataev78849fb2016-03-09 09:49:00 +0000331 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
332 Stmt *PreInit, Expr *PostUpdate) {
James Y Knightb8bfd962015-10-02 13:41:04 +0000333 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
334 // (Step and CalcStep).
James Y Knight374fd202016-01-01 00:38:24 +0000335 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2));
James Y Knightb8bfd962015-10-02 13:41:04 +0000336 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
337 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
338 Clause->setVarRefs(VL);
339 Clause->setPrivates(PL);
340 Clause->setInits(IL);
341 // Fill update and final expressions with zeroes, they are provided later,
342 // after the directive construction.
343 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
344 nullptr);
345 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
346 nullptr);
347 Clause->setStep(Step);
348 Clause->setCalcStep(CalcStep);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000349 Clause->setPreInitStmt(PreInit);
350 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000351 return Clause;
352}
353
354OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
355 unsigned NumVars) {
356 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
357 // (Step and CalcStep).
James Y Knight374fd202016-01-01 00:38:24 +0000358 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2));
James Y Knightb8bfd962015-10-02 13:41:04 +0000359 return new (Mem) OMPLinearClause(NumVars);
360}
361
362OMPAlignedClause *
363OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
364 SourceLocation LParenLoc, SourceLocation ColonLoc,
365 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
James Y Knight374fd202016-01-01 00:38:24 +0000366 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000367 OMPAlignedClause *Clause = new (Mem)
368 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
369 Clause->setVarRefs(VL);
370 Clause->setAlignment(A);
371 return Clause;
372}
373
374OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
375 unsigned NumVars) {
James Y Knight374fd202016-01-01 00:38:24 +0000376 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000377 return new (Mem) OMPAlignedClause(NumVars);
378}
379
380void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
381 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
382 "not the same as the "
383 "preallocated buffer");
384 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
385}
386
387void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
388 assert(DstExprs.size() == varlist_size() && "Number of destination "
389 "expressions is not the same as "
390 "the preallocated buffer");
391 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
392}
393
394void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
395 assert(AssignmentOps.size() == varlist_size() &&
396 "Number of assignment expressions is not the same as the preallocated "
397 "buffer");
398 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
399 getDestinationExprs().end());
400}
401
402OMPCopyinClause *OMPCopyinClause::Create(
403 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
404 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
405 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000406 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000407 OMPCopyinClause *Clause =
408 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
409 Clause->setVarRefs(VL);
410 Clause->setSourceExprs(SrcExprs);
411 Clause->setDestinationExprs(DstExprs);
412 Clause->setAssignmentOps(AssignmentOps);
413 return Clause;
414}
415
416OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000417 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000418 return new (Mem) OMPCopyinClause(N);
419}
420
421void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
422 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
423 "not the same as the "
424 "preallocated buffer");
425 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
426}
427
428void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
429 assert(DstExprs.size() == varlist_size() && "Number of destination "
430 "expressions is not the same as "
431 "the preallocated buffer");
432 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
433}
434
435void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
436 assert(AssignmentOps.size() == varlist_size() &&
437 "Number of assignment expressions is not the same as the preallocated "
438 "buffer");
439 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
440 getDestinationExprs().end());
441}
442
443OMPCopyprivateClause *OMPCopyprivateClause::Create(
444 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
445 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
446 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000447 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000448 OMPCopyprivateClause *Clause =
449 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
450 Clause->setVarRefs(VL);
451 Clause->setSourceExprs(SrcExprs);
452 Clause->setDestinationExprs(DstExprs);
453 Clause->setAssignmentOps(AssignmentOps);
454 return Clause;
455}
456
457OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
458 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000459 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000460 return new (Mem) OMPCopyprivateClause(N);
461}
462
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000463void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
464 assert(Privates.size() == varlist_size() &&
465 "Number of private copies is not the same as the preallocated buffer");
466 std::copy(Privates.begin(), Privates.end(), varlist_end());
467}
468
James Y Knightb8bfd962015-10-02 13:41:04 +0000469void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
470 assert(
471 LHSExprs.size() == varlist_size() &&
472 "Number of LHS expressions is not the same as the preallocated buffer");
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000473 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
James Y Knightb8bfd962015-10-02 13:41:04 +0000474}
475
476void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
477 assert(
478 RHSExprs.size() == varlist_size() &&
479 "Number of RHS expressions is not the same as the preallocated buffer");
480 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
481}
482
483void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
484 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
485 "expressions is not the same "
486 "as the preallocated buffer");
487 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
488}
489
490OMPReductionClause *OMPReductionClause::Create(
491 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
492 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
493 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000494 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev61205072016-03-02 04:57:40 +0000495 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
496 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000497 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000498 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
499 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
500 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000501 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000502 Clause->setLHSExprs(LHSExprs);
503 Clause->setRHSExprs(RHSExprs);
504 Clause->setReductionOps(ReductionOps);
Alexey Bataev61205072016-03-02 04:57:40 +0000505 Clause->setPreInitStmt(PreInit);
506 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000507 return Clause;
508}
509
510OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
511 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000512 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000513 return new (Mem) OMPReductionClause(N);
514}
515
Alexey Bataev169d96a2017-07-18 20:17:46 +0000516void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
517 assert(Privates.size() == varlist_size() &&
518 "Number of private copies is not the same as the preallocated buffer");
519 std::copy(Privates.begin(), Privates.end(), varlist_end());
520}
521
522void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
523 assert(
524 LHSExprs.size() == varlist_size() &&
525 "Number of LHS expressions is not the same as the preallocated buffer");
526 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
527}
528
529void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
530 assert(
531 RHSExprs.size() == varlist_size() &&
532 "Number of RHS expressions is not the same as the preallocated buffer");
533 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
534}
535
536void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
537 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
538 "expressions is not the same "
539 "as the preallocated buffer");
540 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
541}
542
543OMPTaskReductionClause *OMPTaskReductionClause::Create(
544 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
545 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
546 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
547 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
548 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
549 Expr *PostUpdate) {
550 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
551 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
552 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
553 Clause->setVarRefs(VL);
554 Clause->setPrivates(Privates);
555 Clause->setLHSExprs(LHSExprs);
556 Clause->setRHSExprs(RHSExprs);
557 Clause->setReductionOps(ReductionOps);
558 Clause->setPreInitStmt(PreInit);
559 Clause->setPostUpdateExpr(PostUpdate);
560 return Clause;
561}
562
563OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
564 unsigned N) {
565 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
566 return new (Mem) OMPTaskReductionClause(N);
567}
568
Alexey Bataevfa312f32017-07-21 18:48:21 +0000569void 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
575void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
576 assert(
577 LHSExprs.size() == varlist_size() &&
578 "Number of LHS expressions is not the same as the preallocated buffer");
579 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
580}
581
582void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
583 assert(
584 RHSExprs.size() == varlist_size() &&
585 "Number of RHS expressions is not the same as the preallocated buffer");
586 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
587}
588
589void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
590 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
591 "expressions is not the same "
592 "as the preallocated buffer");
593 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
594}
595
596OMPInReductionClause *OMPInReductionClause::Create(
597 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
598 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
599 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
600 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
601 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
602 Expr *PostUpdate) {
603 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
604 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
605 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
606 Clause->setVarRefs(VL);
607 Clause->setPrivates(Privates);
608 Clause->setLHSExprs(LHSExprs);
609 Clause->setRHSExprs(RHSExprs);
610 Clause->setReductionOps(ReductionOps);
611 Clause->setPreInitStmt(PreInit);
612 Clause->setPostUpdateExpr(PostUpdate);
613 return Clause;
614}
615
616OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
617 unsigned N) {
618 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
619 return new (Mem) OMPInReductionClause(N);
620}
621
James Y Knightb8bfd962015-10-02 13:41:04 +0000622OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
623 SourceLocation StartLoc,
624 SourceLocation LParenLoc,
625 SourceLocation EndLoc,
626 ArrayRef<Expr *> VL) {
Alexey Bataev8b427062016-05-25 12:36:08 +0000627 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000628 OMPFlushClause *Clause =
629 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
630 Clause->setVarRefs(VL);
631 return Clause;
632}
633
634OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000635 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000636 return new (Mem) OMPFlushClause(N);
637}
638
Alexey Bataev8b427062016-05-25 12:36:08 +0000639OMPDependClause *OMPDependClause::Create(
640 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
641 SourceLocation EndLoc, OpenMPDependClauseKind DepKind,
642 SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL) {
643 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000644 OMPDependClause *Clause =
645 new (Mem) OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size());
646 Clause->setVarRefs(VL);
647 Clause->setDependencyKind(DepKind);
648 Clause->setDependencyLoc(DepLoc);
649 Clause->setColonLoc(ColonLoc);
Alexey Bataev8b427062016-05-25 12:36:08 +0000650 Clause->setCounterValue(nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000651 return Clause;
652}
653
654OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N) {
Alexey Bataev2af820542016-05-25 12:51:24 +0000655 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000656 return new (Mem) OMPDependClause(N);
657}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000658
Alexey Bataev8b427062016-05-25 12:36:08 +0000659void OMPDependClause::setCounterValue(Expr *V) {
660 assert(getDependencyKind() == OMPC_DEPEND_sink ||
661 getDependencyKind() == OMPC_DEPEND_source || V == nullptr);
662 *getVarRefs().end() = V;
663}
664
665const Expr *OMPDependClause::getCounterValue() const {
666 auto *V = *getVarRefs().end();
667 assert(getDependencyKind() == OMPC_DEPEND_sink ||
668 getDependencyKind() == OMPC_DEPEND_source || V == nullptr);
669 return V;
670}
671
672Expr *OMPDependClause::getCounterValue() {
673 auto *V = *getVarRefs().end();
674 assert(getDependencyKind() == OMPC_DEPEND_sink ||
675 getDependencyKind() == OMPC_DEPEND_source || V == nullptr);
676 return V;
677}
678
Samuel Antao90927002016-04-26 14:54:23 +0000679unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
680 MappableExprComponentListsRef ComponentLists) {
681 unsigned TotalNum = 0u;
682 for (auto &C : ComponentLists)
683 TotalNum += C.size();
684 return TotalNum;
685}
686
687unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
688 ArrayRef<ValueDecl *> Declarations) {
689 unsigned TotalNum = 0u;
690 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
691 for (auto *D : Declarations) {
692 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
693 if (Cache.count(VD))
694 continue;
695 ++TotalNum;
696 Cache.insert(VD);
697 }
698 return TotalNum;
699}
700
701OMPMapClause *
702OMPMapClause::Create(const ASTContext &C, SourceLocation StartLoc,
703 SourceLocation LParenLoc, SourceLocation EndLoc,
704 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
705 MappableExprComponentListsRef ComponentLists,
706 OpenMPMapClauseKind TypeModifier, OpenMPMapClauseKind Type,
707 bool TypeIsImplicit, SourceLocation TypeLoc) {
708
709 unsigned NumVars = Vars.size();
710 unsigned NumUniqueDeclarations =
711 getUniqueDeclarationsTotalNumber(Declarations);
712 unsigned NumComponentLists = ComponentLists.size();
713 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
714
715 // We need to allocate:
716 // NumVars x Expr* - we have an original list expression for each clause list
717 // entry.
718 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
719 // with each component list.
720 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
721 // number of lists for each unique declaration and the size of each component
722 // list.
723 // NumComponents x MappableComponent - the total of all the components in all
724 // the lists.
725 void *Mem = C.Allocate(
726 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
727 OMPClauseMappableExprCommon::MappableComponent>(
728 NumVars, NumUniqueDeclarations,
729 NumUniqueDeclarations + NumComponentLists, NumComponents));
730 OMPMapClause *Clause = new (Mem) OMPMapClause(
731 TypeModifier, Type, TypeIsImplicit, TypeLoc, StartLoc, LParenLoc, EndLoc,
732 NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents);
733
734 Clause->setVarRefs(Vars);
735 Clause->setClauseInfo(Declarations, ComponentLists);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000736 Clause->setMapTypeModifier(TypeModifier);
737 Clause->setMapType(Type);
738 Clause->setMapLoc(TypeLoc);
739 return Clause;
740}
741
Samuel Antao90927002016-04-26 14:54:23 +0000742OMPMapClause *OMPMapClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
743 unsigned NumUniqueDeclarations,
744 unsigned NumComponentLists,
745 unsigned NumComponents) {
746 void *Mem = C.Allocate(
747 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
748 OMPClauseMappableExprCommon::MappableComponent>(
749 NumVars, NumUniqueDeclarations,
750 NumUniqueDeclarations + NumComponentLists, NumComponents));
751 return new (Mem) OMPMapClause(NumVars, NumUniqueDeclarations,
752 NumComponentLists, NumComponents);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000753}
Samuel Antao661c0902016-05-26 17:39:58 +0000754
755OMPToClause *OMPToClause::Create(const ASTContext &C, SourceLocation StartLoc,
756 SourceLocation LParenLoc,
757 SourceLocation EndLoc, ArrayRef<Expr *> Vars,
758 ArrayRef<ValueDecl *> Declarations,
759 MappableExprComponentListsRef ComponentLists) {
760 unsigned NumVars = Vars.size();
761 unsigned NumUniqueDeclarations =
762 getUniqueDeclarationsTotalNumber(Declarations);
763 unsigned NumComponentLists = ComponentLists.size();
764 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
765
766 // We need to allocate:
767 // NumVars x Expr* - we have an original list expression for each clause list
768 // entry.
769 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
770 // with each component list.
771 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
772 // number of lists for each unique declaration and the size of each component
773 // list.
774 // NumComponents x MappableComponent - the total of all the components in all
775 // the lists.
776 void *Mem = C.Allocate(
777 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
778 OMPClauseMappableExprCommon::MappableComponent>(
779 NumVars, NumUniqueDeclarations,
780 NumUniqueDeclarations + NumComponentLists, NumComponents));
781
782 OMPToClause *Clause = new (Mem)
783 OMPToClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
784 NumComponentLists, NumComponents);
785
786 Clause->setVarRefs(Vars);
787 Clause->setClauseInfo(Declarations, ComponentLists);
788 return Clause;
789}
790
791OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
792 unsigned NumUniqueDeclarations,
793 unsigned NumComponentLists,
794 unsigned NumComponents) {
795 void *Mem = C.Allocate(
796 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
797 OMPClauseMappableExprCommon::MappableComponent>(
798 NumVars, NumUniqueDeclarations,
799 NumUniqueDeclarations + NumComponentLists, NumComponents));
800 return new (Mem) OMPToClause(NumVars, NumUniqueDeclarations,
801 NumComponentLists, NumComponents);
802}
Samuel Antaoec172c62016-05-26 17:49:04 +0000803
804OMPFromClause *
805OMPFromClause::Create(const ASTContext &C, SourceLocation StartLoc,
806 SourceLocation LParenLoc, SourceLocation EndLoc,
807 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
808 MappableExprComponentListsRef ComponentLists) {
809 unsigned NumVars = Vars.size();
810 unsigned NumUniqueDeclarations =
811 getUniqueDeclarationsTotalNumber(Declarations);
812 unsigned NumComponentLists = ComponentLists.size();
813 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
814
815 // We need to allocate:
816 // NumVars x Expr* - we have an original list expression for each clause list
817 // entry.
818 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
819 // with each component list.
820 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
821 // number of lists for each unique declaration and the size of each component
822 // list.
823 // NumComponents x MappableComponent - the total of all the components in all
824 // the lists.
825 void *Mem = C.Allocate(
826 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
827 OMPClauseMappableExprCommon::MappableComponent>(
828 NumVars, NumUniqueDeclarations,
829 NumUniqueDeclarations + NumComponentLists, NumComponents));
830
831 OMPFromClause *Clause = new (Mem)
832 OMPFromClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
833 NumComponentLists, NumComponents);
834
835 Clause->setVarRefs(Vars);
836 Clause->setClauseInfo(Declarations, ComponentLists);
837 return Clause;
838}
839
840OMPFromClause *OMPFromClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
841 unsigned NumUniqueDeclarations,
842 unsigned NumComponentLists,
843 unsigned NumComponents) {
844 void *Mem = C.Allocate(
845 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
846 OMPClauseMappableExprCommon::MappableComponent>(
847 NumVars, NumUniqueDeclarations,
848 NumUniqueDeclarations + NumComponentLists, NumComponents));
849 return new (Mem) OMPFromClause(NumVars, NumUniqueDeclarations,
850 NumComponentLists, NumComponents);
851}
Carlo Bertolli2404b172016-07-13 15:37:16 +0000852
Samuel Antaocc10b852016-07-28 14:23:26 +0000853void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
854 assert(VL.size() == varlist_size() &&
855 "Number of private copies is not the same as the preallocated buffer");
856 std::copy(VL.begin(), VL.end(), varlist_end());
857}
858
859void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
860 assert(VL.size() == varlist_size() &&
861 "Number of inits is not the same as the preallocated buffer");
862 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
863}
864
865OMPUseDevicePtrClause *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
876 // We need to allocate:
877 // 3 x NumVars x Expr* - we have an original list expression for each clause
878 // list entry and an equal number of private copies and inits.
879 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
880 // with each component list.
881 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
882 // number of lists for each unique declaration and the size of each component
883 // list.
884 // NumComponents x MappableComponent - the total of all the components in all
885 // the lists.
886 void *Mem = C.Allocate(
887 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
888 OMPClauseMappableExprCommon::MappableComponent>(
889 3 * NumVars, NumUniqueDeclarations,
890 NumUniqueDeclarations + NumComponentLists, NumComponents));
891
892 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(
893 StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
894 NumComponentLists, NumComponents);
895
896 Clause->setVarRefs(Vars);
897 Clause->setPrivateCopies(PrivateVars);
898 Clause->setInits(Inits);
899 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli2404b172016-07-13 15:37:16 +0000900 return Clause;
901}
902
Samuel Antaocc10b852016-07-28 14:23:26 +0000903OMPUseDevicePtrClause *OMPUseDevicePtrClause::CreateEmpty(
904 const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations,
905 unsigned NumComponentLists, unsigned NumComponents) {
906 void *Mem = C.Allocate(
907 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
908 OMPClauseMappableExprCommon::MappableComponent>(
909 3 * NumVars, NumUniqueDeclarations,
910 NumUniqueDeclarations + NumComponentLists, NumComponents));
911 return new (Mem) OMPUseDevicePtrClause(NumVars, NumUniqueDeclarations,
912 NumComponentLists, NumComponents);
Carlo Bertolli2404b172016-07-13 15:37:16 +0000913}
Carlo Bertolli70594e92016-07-13 17:16:49 +0000914
Samuel Antao6890b092016-07-28 14:25:09 +0000915OMPIsDevicePtrClause *
916OMPIsDevicePtrClause::Create(const ASTContext &C, SourceLocation StartLoc,
917 SourceLocation LParenLoc, SourceLocation EndLoc,
918 ArrayRef<Expr *> Vars,
919 ArrayRef<ValueDecl *> Declarations,
920 MappableExprComponentListsRef ComponentLists) {
921 unsigned NumVars = Vars.size();
922 unsigned NumUniqueDeclarations =
923 getUniqueDeclarationsTotalNumber(Declarations);
924 unsigned NumComponentLists = ComponentLists.size();
925 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
926
927 // We need to allocate:
928 // NumVars x Expr* - we have an original list expression for each clause list
929 // entry.
930 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
931 // with each component list.
932 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
933 // number of lists for each unique declaration and the size of each component
934 // list.
935 // NumComponents x MappableComponent - the total of all the components in all
936 // the lists.
937 void *Mem = C.Allocate(
938 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
939 OMPClauseMappableExprCommon::MappableComponent>(
940 NumVars, NumUniqueDeclarations,
941 NumUniqueDeclarations + NumComponentLists, NumComponents));
942
943 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(
944 StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
945 NumComponentLists, NumComponents);
946
947 Clause->setVarRefs(Vars);
948 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli70594e92016-07-13 17:16:49 +0000949 return Clause;
950}
951
Samuel Antao6890b092016-07-28 14:25:09 +0000952OMPIsDevicePtrClause *OMPIsDevicePtrClause::CreateEmpty(
953 const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations,
954 unsigned NumComponentLists, unsigned NumComponents) {
955 void *Mem = C.Allocate(
956 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
957 OMPClauseMappableExprCommon::MappableComponent>(
958 NumVars, NumUniqueDeclarations,
959 NumUniqueDeclarations + NumComponentLists, NumComponents));
960 return new (Mem) OMPIsDevicePtrClause(NumVars, NumUniqueDeclarations,
961 NumComponentLists, NumComponents);
Carlo Bertolli70594e92016-07-13 17:16:49 +0000962}