blob: 2c4d159a1bc82546e5fdab95a05558281bd77396 [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 Bataev78849fb2016-03-09 09:49:00 +000051 case OMPC_linear:
52 return static_cast<const OMPLinearClause *>(C);
Arpith Chacko Jacobfe4890a2017-01-18 20:40:48 +000053 case OMPC_if:
54 return static_cast<const OMPIfClause *>(C);
Arpith Chacko Jacob33c849a2017-01-25 00:57:16 +000055 case OMPC_num_threads:
56 return static_cast<const OMPNumThreadsClause *>(C);
Arpith Chacko Jacobbc126342017-01-25 11:28:18 +000057 case OMPC_num_teams:
58 return static_cast<const OMPNumTeamsClause *>(C);
Arpith Chacko Jacob7ecc0b72017-01-25 11:44:35 +000059 case OMPC_thread_limit:
60 return static_cast<const OMPThreadLimitClause *>(C);
Alexey Bataev3392d762016-02-16 11:18:12 +000061 case OMPC_default:
62 case OMPC_proc_bind:
Alexey Bataev3392d762016-02-16 11:18:12 +000063 case OMPC_final:
Alexey Bataev3392d762016-02-16 11:18:12 +000064 case OMPC_safelen:
65 case OMPC_simdlen:
66 case OMPC_collapse:
67 case OMPC_private:
Alexey Bataev005248a2016-02-25 05:25:57 +000068 case OMPC_shared:
Alexey Bataev005248a2016-02-25 05:25:57 +000069 case OMPC_aligned:
70 case OMPC_copyin:
71 case OMPC_copyprivate:
72 case OMPC_ordered:
73 case OMPC_nowait:
74 case OMPC_untied:
75 case OMPC_mergeable:
76 case OMPC_threadprivate:
77 case OMPC_flush:
78 case OMPC_read:
79 case OMPC_write:
80 case OMPC_update:
81 case OMPC_capture:
82 case OMPC_seq_cst:
83 case OMPC_depend:
84 case OMPC_device:
85 case OMPC_threads:
86 case OMPC_simd:
87 case OMPC_map:
Alexey Bataev005248a2016-02-25 05:25:57 +000088 case OMPC_priority:
89 case OMPC_grainsize:
90 case OMPC_nogroup:
91 case OMPC_num_tasks:
92 case OMPC_hint:
93 case OMPC_defaultmap:
94 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +000095 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +000096 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +000097 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +000098 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +000099 case OMPC_is_device_ptr:
Alexey Bataev005248a2016-02-25 05:25:57 +0000100 break;
101 }
102
103 return nullptr;
104}
105
106OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
107 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
108 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
109}
110
111const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
112 switch (C->getClauseKind()) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000113 case OMPC_lastprivate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000114 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000115 case OMPC_reduction:
116 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +0000117 case OMPC_task_reduction:
118 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000119 case OMPC_linear:
120 return static_cast<const OMPLinearClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000121 case OMPC_schedule:
122 case OMPC_dist_schedule:
123 case OMPC_firstprivate:
124 case OMPC_default:
125 case OMPC_proc_bind:
126 case OMPC_if:
127 case OMPC_final:
128 case OMPC_num_threads:
129 case OMPC_safelen:
130 case OMPC_simdlen:
131 case OMPC_collapse:
132 case OMPC_private:
Alexey Bataev3392d762016-02-16 11:18:12 +0000133 case OMPC_shared:
Alexey Bataev3392d762016-02-16 11:18:12 +0000134 case OMPC_aligned:
135 case OMPC_copyin:
136 case OMPC_copyprivate:
137 case OMPC_ordered:
138 case OMPC_nowait:
139 case OMPC_untied:
140 case OMPC_mergeable:
141 case OMPC_threadprivate:
142 case OMPC_flush:
143 case OMPC_read:
144 case OMPC_write:
145 case OMPC_update:
146 case OMPC_capture:
147 case OMPC_seq_cst:
148 case OMPC_depend:
149 case OMPC_device:
150 case OMPC_threads:
151 case OMPC_simd:
152 case OMPC_map:
153 case OMPC_num_teams:
154 case OMPC_thread_limit:
155 case OMPC_priority:
156 case OMPC_grainsize:
157 case OMPC_nogroup:
158 case OMPC_num_tasks:
159 case OMPC_hint:
160 case OMPC_defaultmap:
161 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000162 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000163 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000164 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000165 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000166 case OMPC_is_device_ptr:
Alexey Bataev3392d762016-02-16 11:18:12 +0000167 break;
168 }
169
170 return nullptr;
171}
172
James Y Knightb8bfd962015-10-02 13:41:04 +0000173void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
174 assert(VL.size() == varlist_size() &&
175 "Number of private copies is not the same as the preallocated buffer");
176 std::copy(VL.begin(), VL.end(), varlist_end());
177}
178
179OMPPrivateClause *
180OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
181 SourceLocation LParenLoc, SourceLocation EndLoc,
182 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
183 // Allocate space for private variables and initializer expressions.
James Y Knight374fd202016-01-01 00:38:24 +0000184 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000185 OMPPrivateClause *Clause =
186 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
187 Clause->setVarRefs(VL);
188 Clause->setPrivateCopies(PrivateVL);
189 return Clause;
190}
191
192OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
193 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000194 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000195 return new (Mem) OMPPrivateClause(N);
196}
197
198void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
199 assert(VL.size() == varlist_size() &&
200 "Number of private copies is not the same as the preallocated buffer");
201 std::copy(VL.begin(), VL.end(), varlist_end());
202}
203
204void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
205 assert(VL.size() == varlist_size() &&
206 "Number of inits is not the same as the preallocated buffer");
207 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
208}
209
210OMPFirstprivateClause *
211OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
212 SourceLocation LParenLoc, SourceLocation EndLoc,
213 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
Alexey Bataev417089f2016-02-17 13:19:37 +0000214 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
James Y Knight374fd202016-01-01 00:38:24 +0000215 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000216 OMPFirstprivateClause *Clause =
217 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
218 Clause->setVarRefs(VL);
219 Clause->setPrivateCopies(PrivateVL);
220 Clause->setInits(InitVL);
Alexey Bataev417089f2016-02-17 13:19:37 +0000221 Clause->setPreInitStmt(PreInit);
James Y Knightb8bfd962015-10-02 13:41:04 +0000222 return Clause;
223}
224
225OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
226 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000227 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000228 return new (Mem) OMPFirstprivateClause(N);
229}
230
231void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
232 assert(PrivateCopies.size() == varlist_size() &&
233 "Number of private copies is not the same as the preallocated buffer");
234 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
235}
236
237void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
238 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
239 "not the same as the "
240 "preallocated buffer");
241 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
242}
243
244void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
245 assert(DstExprs.size() == varlist_size() && "Number of destination "
246 "expressions is not the same as "
247 "the preallocated buffer");
248 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
249}
250
251void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
252 assert(AssignmentOps.size() == varlist_size() &&
253 "Number of assignment expressions is not the same as the preallocated "
254 "buffer");
255 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
256 getDestinationExprs().end());
257}
258
259OMPLastprivateClause *OMPLastprivateClause::Create(
260 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
261 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
Alexey Bataev005248a2016-02-25 05:25:57 +0000262 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit,
263 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000264 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000265 OMPLastprivateClause *Clause =
266 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
267 Clause->setVarRefs(VL);
268 Clause->setSourceExprs(SrcExprs);
269 Clause->setDestinationExprs(DstExprs);
270 Clause->setAssignmentOps(AssignmentOps);
Alexey Bataev005248a2016-02-25 05:25:57 +0000271 Clause->setPreInitStmt(PreInit);
272 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000273 return Clause;
274}
275
276OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
277 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000278 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000279 return new (Mem) OMPLastprivateClause(N);
280}
281
282OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
283 SourceLocation StartLoc,
284 SourceLocation LParenLoc,
285 SourceLocation EndLoc,
286 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000287 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000288 OMPSharedClause *Clause =
289 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
290 Clause->setVarRefs(VL);
291 return Clause;
292}
293
294OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000295 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000296 return new (Mem) OMPSharedClause(N);
297}
298
299void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
300 assert(PL.size() == varlist_size() &&
301 "Number of privates is not the same as the preallocated buffer");
302 std::copy(PL.begin(), PL.end(), varlist_end());
303}
304
305void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
306 assert(IL.size() == varlist_size() &&
307 "Number of inits is not the same as the preallocated buffer");
308 std::copy(IL.begin(), IL.end(), getPrivates().end());
309}
310
311void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
312 assert(UL.size() == varlist_size() &&
313 "Number of updates is not the same as the preallocated buffer");
314 std::copy(UL.begin(), UL.end(), getInits().end());
315}
316
317void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
318 assert(FL.size() == varlist_size() &&
319 "Number of final updates is not the same as the preallocated buffer");
320 std::copy(FL.begin(), FL.end(), getUpdates().end());
321}
322
323OMPLinearClause *OMPLinearClause::Create(
324 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
325 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
326 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
Alexey Bataev78849fb2016-03-09 09:49:00 +0000327 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
328 Stmt *PreInit, Expr *PostUpdate) {
James Y Knightb8bfd962015-10-02 13:41:04 +0000329 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
330 // (Step and CalcStep).
James Y Knight374fd202016-01-01 00:38:24 +0000331 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2));
James Y Knightb8bfd962015-10-02 13:41:04 +0000332 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
333 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
334 Clause->setVarRefs(VL);
335 Clause->setPrivates(PL);
336 Clause->setInits(IL);
337 // Fill update and final expressions with zeroes, they are provided later,
338 // after the directive construction.
339 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
340 nullptr);
341 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
342 nullptr);
343 Clause->setStep(Step);
344 Clause->setCalcStep(CalcStep);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000345 Clause->setPreInitStmt(PreInit);
346 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000347 return Clause;
348}
349
350OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
351 unsigned NumVars) {
352 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
353 // (Step and CalcStep).
James Y Knight374fd202016-01-01 00:38:24 +0000354 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2));
James Y Knightb8bfd962015-10-02 13:41:04 +0000355 return new (Mem) OMPLinearClause(NumVars);
356}
357
358OMPAlignedClause *
359OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
360 SourceLocation LParenLoc, SourceLocation ColonLoc,
361 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
James Y Knight374fd202016-01-01 00:38:24 +0000362 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000363 OMPAlignedClause *Clause = new (Mem)
364 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
365 Clause->setVarRefs(VL);
366 Clause->setAlignment(A);
367 return Clause;
368}
369
370OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
371 unsigned NumVars) {
James Y Knight374fd202016-01-01 00:38:24 +0000372 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000373 return new (Mem) OMPAlignedClause(NumVars);
374}
375
376void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
377 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
378 "not the same as the "
379 "preallocated buffer");
380 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
381}
382
383void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
384 assert(DstExprs.size() == varlist_size() && "Number of destination "
385 "expressions is not the same as "
386 "the preallocated buffer");
387 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
388}
389
390void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
391 assert(AssignmentOps.size() == varlist_size() &&
392 "Number of assignment expressions is not the same as the preallocated "
393 "buffer");
394 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
395 getDestinationExprs().end());
396}
397
398OMPCopyinClause *OMPCopyinClause::Create(
399 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
400 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
401 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000402 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000403 OMPCopyinClause *Clause =
404 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
405 Clause->setVarRefs(VL);
406 Clause->setSourceExprs(SrcExprs);
407 Clause->setDestinationExprs(DstExprs);
408 Clause->setAssignmentOps(AssignmentOps);
409 return Clause;
410}
411
412OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000413 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000414 return new (Mem) OMPCopyinClause(N);
415}
416
417void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
418 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
419 "not the same as the "
420 "preallocated buffer");
421 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
422}
423
424void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
425 assert(DstExprs.size() == varlist_size() && "Number of destination "
426 "expressions is not the same as "
427 "the preallocated buffer");
428 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
429}
430
431void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
432 assert(AssignmentOps.size() == varlist_size() &&
433 "Number of assignment expressions is not the same as the preallocated "
434 "buffer");
435 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
436 getDestinationExprs().end());
437}
438
439OMPCopyprivateClause *OMPCopyprivateClause::Create(
440 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
441 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
442 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000443 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000444 OMPCopyprivateClause *Clause =
445 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
446 Clause->setVarRefs(VL);
447 Clause->setSourceExprs(SrcExprs);
448 Clause->setDestinationExprs(DstExprs);
449 Clause->setAssignmentOps(AssignmentOps);
450 return Clause;
451}
452
453OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
454 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000455 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000456 return new (Mem) OMPCopyprivateClause(N);
457}
458
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000459void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
460 assert(Privates.size() == varlist_size() &&
461 "Number of private copies is not the same as the preallocated buffer");
462 std::copy(Privates.begin(), Privates.end(), varlist_end());
463}
464
James Y Knightb8bfd962015-10-02 13:41:04 +0000465void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
466 assert(
467 LHSExprs.size() == varlist_size() &&
468 "Number of LHS expressions is not the same as the preallocated buffer");
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000469 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
James Y Knightb8bfd962015-10-02 13:41:04 +0000470}
471
472void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
473 assert(
474 RHSExprs.size() == varlist_size() &&
475 "Number of RHS expressions is not the same as the preallocated buffer");
476 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
477}
478
479void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
480 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
481 "expressions is not the same "
482 "as the preallocated buffer");
483 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
484}
485
486OMPReductionClause *OMPReductionClause::Create(
487 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
488 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
489 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000490 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev61205072016-03-02 04:57:40 +0000491 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
492 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000493 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000494 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
495 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
496 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000497 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000498 Clause->setLHSExprs(LHSExprs);
499 Clause->setRHSExprs(RHSExprs);
500 Clause->setReductionOps(ReductionOps);
Alexey Bataev61205072016-03-02 04:57:40 +0000501 Clause->setPreInitStmt(PreInit);
502 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000503 return Clause;
504}
505
506OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
507 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000508 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000509 return new (Mem) OMPReductionClause(N);
510}
511
Alexey Bataev169d96a2017-07-18 20:17:46 +0000512void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
513 assert(Privates.size() == varlist_size() &&
514 "Number of private copies is not the same as the preallocated buffer");
515 std::copy(Privates.begin(), Privates.end(), varlist_end());
516}
517
518void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
519 assert(
520 LHSExprs.size() == varlist_size() &&
521 "Number of LHS expressions is not the same as the preallocated buffer");
522 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
523}
524
525void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
526 assert(
527 RHSExprs.size() == varlist_size() &&
528 "Number of RHS expressions is not the same as the preallocated buffer");
529 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
530}
531
532void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
533 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
534 "expressions is not the same "
535 "as the preallocated buffer");
536 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
537}
538
539OMPTaskReductionClause *OMPTaskReductionClause::Create(
540 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
541 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
542 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
543 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
544 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
545 Expr *PostUpdate) {
546 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
547 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
548 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
549 Clause->setVarRefs(VL);
550 Clause->setPrivates(Privates);
551 Clause->setLHSExprs(LHSExprs);
552 Clause->setRHSExprs(RHSExprs);
553 Clause->setReductionOps(ReductionOps);
554 Clause->setPreInitStmt(PreInit);
555 Clause->setPostUpdateExpr(PostUpdate);
556 return Clause;
557}
558
559OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
560 unsigned N) {
561 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
562 return new (Mem) OMPTaskReductionClause(N);
563}
564
James Y Knightb8bfd962015-10-02 13:41:04 +0000565OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
566 SourceLocation StartLoc,
567 SourceLocation LParenLoc,
568 SourceLocation EndLoc,
569 ArrayRef<Expr *> VL) {
Alexey Bataev8b427062016-05-25 12:36:08 +0000570 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000571 OMPFlushClause *Clause =
572 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
573 Clause->setVarRefs(VL);
574 return Clause;
575}
576
577OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000578 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000579 return new (Mem) OMPFlushClause(N);
580}
581
Alexey Bataev8b427062016-05-25 12:36:08 +0000582OMPDependClause *OMPDependClause::Create(
583 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
584 SourceLocation EndLoc, OpenMPDependClauseKind DepKind,
585 SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL) {
586 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000587 OMPDependClause *Clause =
588 new (Mem) OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size());
589 Clause->setVarRefs(VL);
590 Clause->setDependencyKind(DepKind);
591 Clause->setDependencyLoc(DepLoc);
592 Clause->setColonLoc(ColonLoc);
Alexey Bataev8b427062016-05-25 12:36:08 +0000593 Clause->setCounterValue(nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000594 return Clause;
595}
596
597OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N) {
Alexey Bataev2af820542016-05-25 12:51:24 +0000598 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000599 return new (Mem) OMPDependClause(N);
600}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000601
Alexey Bataev8b427062016-05-25 12:36:08 +0000602void OMPDependClause::setCounterValue(Expr *V) {
603 assert(getDependencyKind() == OMPC_DEPEND_sink ||
604 getDependencyKind() == OMPC_DEPEND_source || V == nullptr);
605 *getVarRefs().end() = V;
606}
607
608const Expr *OMPDependClause::getCounterValue() const {
609 auto *V = *getVarRefs().end();
610 assert(getDependencyKind() == OMPC_DEPEND_sink ||
611 getDependencyKind() == OMPC_DEPEND_source || V == nullptr);
612 return V;
613}
614
615Expr *OMPDependClause::getCounterValue() {
616 auto *V = *getVarRefs().end();
617 assert(getDependencyKind() == OMPC_DEPEND_sink ||
618 getDependencyKind() == OMPC_DEPEND_source || V == nullptr);
619 return V;
620}
621
Samuel Antao90927002016-04-26 14:54:23 +0000622unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
623 MappableExprComponentListsRef ComponentLists) {
624 unsigned TotalNum = 0u;
625 for (auto &C : ComponentLists)
626 TotalNum += C.size();
627 return TotalNum;
628}
629
630unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
631 ArrayRef<ValueDecl *> Declarations) {
632 unsigned TotalNum = 0u;
633 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
634 for (auto *D : Declarations) {
635 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
636 if (Cache.count(VD))
637 continue;
638 ++TotalNum;
639 Cache.insert(VD);
640 }
641 return TotalNum;
642}
643
644OMPMapClause *
645OMPMapClause::Create(const ASTContext &C, SourceLocation StartLoc,
646 SourceLocation LParenLoc, SourceLocation EndLoc,
647 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
648 MappableExprComponentListsRef ComponentLists,
649 OpenMPMapClauseKind TypeModifier, OpenMPMapClauseKind Type,
650 bool TypeIsImplicit, SourceLocation TypeLoc) {
651
652 unsigned NumVars = Vars.size();
653 unsigned NumUniqueDeclarations =
654 getUniqueDeclarationsTotalNumber(Declarations);
655 unsigned NumComponentLists = ComponentLists.size();
656 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
657
658 // We need to allocate:
659 // NumVars x Expr* - we have an original list expression for each clause list
660 // entry.
661 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
662 // with each component list.
663 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
664 // number of lists for each unique declaration and the size of each component
665 // list.
666 // NumComponents x MappableComponent - the total of all the components in all
667 // the lists.
668 void *Mem = C.Allocate(
669 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
670 OMPClauseMappableExprCommon::MappableComponent>(
671 NumVars, NumUniqueDeclarations,
672 NumUniqueDeclarations + NumComponentLists, NumComponents));
673 OMPMapClause *Clause = new (Mem) OMPMapClause(
674 TypeModifier, Type, TypeIsImplicit, TypeLoc, StartLoc, LParenLoc, EndLoc,
675 NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents);
676
677 Clause->setVarRefs(Vars);
678 Clause->setClauseInfo(Declarations, ComponentLists);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000679 Clause->setMapTypeModifier(TypeModifier);
680 Clause->setMapType(Type);
681 Clause->setMapLoc(TypeLoc);
682 return Clause;
683}
684
Samuel Antao90927002016-04-26 14:54:23 +0000685OMPMapClause *OMPMapClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
686 unsigned NumUniqueDeclarations,
687 unsigned NumComponentLists,
688 unsigned NumComponents) {
689 void *Mem = C.Allocate(
690 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
691 OMPClauseMappableExprCommon::MappableComponent>(
692 NumVars, NumUniqueDeclarations,
693 NumUniqueDeclarations + NumComponentLists, NumComponents));
694 return new (Mem) OMPMapClause(NumVars, NumUniqueDeclarations,
695 NumComponentLists, NumComponents);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000696}
Samuel Antao661c0902016-05-26 17:39:58 +0000697
698OMPToClause *OMPToClause::Create(const ASTContext &C, SourceLocation StartLoc,
699 SourceLocation LParenLoc,
700 SourceLocation EndLoc, ArrayRef<Expr *> Vars,
701 ArrayRef<ValueDecl *> Declarations,
702 MappableExprComponentListsRef ComponentLists) {
703 unsigned NumVars = Vars.size();
704 unsigned NumUniqueDeclarations =
705 getUniqueDeclarationsTotalNumber(Declarations);
706 unsigned NumComponentLists = ComponentLists.size();
707 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
708
709 // We need to allocate:
710 // NumVars x Expr* - we have an original list expression for each clause list
711 // entry.
712 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
713 // with each component list.
714 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
715 // number of lists for each unique declaration and the size of each component
716 // list.
717 // NumComponents x MappableComponent - the total of all the components in all
718 // the lists.
719 void *Mem = C.Allocate(
720 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
721 OMPClauseMappableExprCommon::MappableComponent>(
722 NumVars, NumUniqueDeclarations,
723 NumUniqueDeclarations + NumComponentLists, NumComponents));
724
725 OMPToClause *Clause = new (Mem)
726 OMPToClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
727 NumComponentLists, NumComponents);
728
729 Clause->setVarRefs(Vars);
730 Clause->setClauseInfo(Declarations, ComponentLists);
731 return Clause;
732}
733
734OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
735 unsigned NumUniqueDeclarations,
736 unsigned NumComponentLists,
737 unsigned NumComponents) {
738 void *Mem = C.Allocate(
739 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
740 OMPClauseMappableExprCommon::MappableComponent>(
741 NumVars, NumUniqueDeclarations,
742 NumUniqueDeclarations + NumComponentLists, NumComponents));
743 return new (Mem) OMPToClause(NumVars, NumUniqueDeclarations,
744 NumComponentLists, NumComponents);
745}
Samuel Antaoec172c62016-05-26 17:49:04 +0000746
747OMPFromClause *
748OMPFromClause::Create(const ASTContext &C, SourceLocation StartLoc,
749 SourceLocation LParenLoc, SourceLocation EndLoc,
750 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
751 MappableExprComponentListsRef ComponentLists) {
752 unsigned NumVars = Vars.size();
753 unsigned NumUniqueDeclarations =
754 getUniqueDeclarationsTotalNumber(Declarations);
755 unsigned NumComponentLists = ComponentLists.size();
756 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
757
758 // We need to allocate:
759 // NumVars x Expr* - we have an original list expression for each clause list
760 // entry.
761 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
762 // with each component list.
763 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
764 // number of lists for each unique declaration and the size of each component
765 // list.
766 // NumComponents x MappableComponent - the total of all the components in all
767 // the lists.
768 void *Mem = C.Allocate(
769 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
770 OMPClauseMappableExprCommon::MappableComponent>(
771 NumVars, NumUniqueDeclarations,
772 NumUniqueDeclarations + NumComponentLists, NumComponents));
773
774 OMPFromClause *Clause = new (Mem)
775 OMPFromClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
776 NumComponentLists, NumComponents);
777
778 Clause->setVarRefs(Vars);
779 Clause->setClauseInfo(Declarations, ComponentLists);
780 return Clause;
781}
782
783OMPFromClause *OMPFromClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
784 unsigned NumUniqueDeclarations,
785 unsigned NumComponentLists,
786 unsigned NumComponents) {
787 void *Mem = C.Allocate(
788 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
789 OMPClauseMappableExprCommon::MappableComponent>(
790 NumVars, NumUniqueDeclarations,
791 NumUniqueDeclarations + NumComponentLists, NumComponents));
792 return new (Mem) OMPFromClause(NumVars, NumUniqueDeclarations,
793 NumComponentLists, NumComponents);
794}
Carlo Bertolli2404b172016-07-13 15:37:16 +0000795
Samuel Antaocc10b852016-07-28 14:23:26 +0000796void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
797 assert(VL.size() == varlist_size() &&
798 "Number of private copies is not the same as the preallocated buffer");
799 std::copy(VL.begin(), VL.end(), varlist_end());
800}
801
802void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
803 assert(VL.size() == varlist_size() &&
804 "Number of inits is not the same as the preallocated buffer");
805 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
806}
807
808OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
809 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
810 SourceLocation EndLoc, ArrayRef<Expr *> Vars, ArrayRef<Expr *> PrivateVars,
811 ArrayRef<Expr *> Inits, ArrayRef<ValueDecl *> Declarations,
812 MappableExprComponentListsRef ComponentLists) {
813 unsigned NumVars = Vars.size();
814 unsigned NumUniqueDeclarations =
815 getUniqueDeclarationsTotalNumber(Declarations);
816 unsigned NumComponentLists = ComponentLists.size();
817 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
818
819 // We need to allocate:
820 // 3 x NumVars x Expr* - we have an original list expression for each clause
821 // list entry and an equal number of private copies and inits.
822 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
823 // with each component list.
824 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
825 // number of lists for each unique declaration and the size of each component
826 // list.
827 // NumComponents x MappableComponent - the total of all the components in all
828 // the lists.
829 void *Mem = C.Allocate(
830 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
831 OMPClauseMappableExprCommon::MappableComponent>(
832 3 * NumVars, NumUniqueDeclarations,
833 NumUniqueDeclarations + NumComponentLists, NumComponents));
834
835 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(
836 StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
837 NumComponentLists, NumComponents);
838
839 Clause->setVarRefs(Vars);
840 Clause->setPrivateCopies(PrivateVars);
841 Clause->setInits(Inits);
842 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli2404b172016-07-13 15:37:16 +0000843 return Clause;
844}
845
Samuel Antaocc10b852016-07-28 14:23:26 +0000846OMPUseDevicePtrClause *OMPUseDevicePtrClause::CreateEmpty(
847 const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations,
848 unsigned NumComponentLists, unsigned NumComponents) {
849 void *Mem = C.Allocate(
850 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
851 OMPClauseMappableExprCommon::MappableComponent>(
852 3 * NumVars, NumUniqueDeclarations,
853 NumUniqueDeclarations + NumComponentLists, NumComponents));
854 return new (Mem) OMPUseDevicePtrClause(NumVars, NumUniqueDeclarations,
855 NumComponentLists, NumComponents);
Carlo Bertolli2404b172016-07-13 15:37:16 +0000856}
Carlo Bertolli70594e92016-07-13 17:16:49 +0000857
Samuel Antao6890b092016-07-28 14:25:09 +0000858OMPIsDevicePtrClause *
859OMPIsDevicePtrClause::Create(const ASTContext &C, SourceLocation StartLoc,
860 SourceLocation LParenLoc, SourceLocation EndLoc,
861 ArrayRef<Expr *> Vars,
862 ArrayRef<ValueDecl *> Declarations,
863 MappableExprComponentListsRef ComponentLists) {
864 unsigned NumVars = Vars.size();
865 unsigned NumUniqueDeclarations =
866 getUniqueDeclarationsTotalNumber(Declarations);
867 unsigned NumComponentLists = ComponentLists.size();
868 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
869
870 // We need to allocate:
871 // NumVars x Expr* - we have an original list expression for each clause list
872 // entry.
873 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
874 // with each component list.
875 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
876 // number of lists for each unique declaration and the size of each component
877 // list.
878 // NumComponents x MappableComponent - the total of all the components in all
879 // the lists.
880 void *Mem = C.Allocate(
881 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
882 OMPClauseMappableExprCommon::MappableComponent>(
883 NumVars, NumUniqueDeclarations,
884 NumUniqueDeclarations + NumComponentLists, NumComponents));
885
886 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(
887 StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
888 NumComponentLists, NumComponents);
889
890 Clause->setVarRefs(Vars);
891 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli70594e92016-07-13 17:16:49 +0000892 return Clause;
893}
894
Samuel Antao6890b092016-07-28 14:25:09 +0000895OMPIsDevicePtrClause *OMPIsDevicePtrClause::CreateEmpty(
896 const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations,
897 unsigned NumComponentLists, unsigned NumComponents) {
898 void *Mem = C.Allocate(
899 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
900 OMPClauseMappableExprCommon::MappableComponent>(
901 NumVars, NumUniqueDeclarations,
902 NumUniqueDeclarations + NumComponentLists, NumComponents));
903 return new (Mem) OMPIsDevicePtrClause(NumVars, NumUniqueDeclarations,
904 NumComponentLists, NumComponents);
Carlo Bertolli70594e92016-07-13 17:16:49 +0000905}