blob: 5642294f09decb8f07ac4ddba5c9133d5fc054f3 [file] [log] [blame]
Eugene Zelenkod1b2d222017-11-29 23:27:36 +00001//===- OpenMPClause.cpp - Classes for OpenMP clauses ----------------------===//
James Y Knightb8bfd962015-10-02 13:41:04 +00002//
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"
James Y Knightb8bfd962015-10-02 13:41:04 +000015#include "clang/AST/ASTContext.h"
Eugene Zelenkod1b2d222017-11-29 23:27:36 +000016#include "clang/AST/Decl.h"
17#include "clang/Basic/LLVM.h"
18#include "llvm/ADT/SmallPtrSet.h"
19#include "llvm/Support/Casting.h"
20#include "llvm/Support/ErrorHandling.h"
21#include <algorithm>
22#include <cassert>
James Y Knightb8bfd962015-10-02 13:41:04 +000023
24using namespace clang;
25
26OMPClause::child_range OMPClause::children() {
27 switch (getClauseKind()) {
28 default:
29 break;
30#define OPENMP_CLAUSE(Name, Class) \
31 case OMPC_##Name: \
32 return static_cast<Class *>(this)->children();
33#include "clang/Basic/OpenMPKinds.def"
34 }
35 llvm_unreachable("unknown OMPClause");
36}
37
Alexey Bataev3392d762016-02-16 11:18:12 +000038OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
39 auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
40 return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr;
41}
42
43const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
44 switch (C->getClauseKind()) {
45 case OMPC_schedule:
46 return static_cast<const OMPScheduleClause *>(C);
47 case OMPC_dist_schedule:
48 return static_cast<const OMPDistScheduleClause *>(C);
Alexey Bataev417089f2016-02-17 13:19:37 +000049 case OMPC_firstprivate:
50 return static_cast<const OMPFirstprivateClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +000051 case OMPC_lastprivate:
52 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +000053 case OMPC_reduction:
54 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +000055 case OMPC_task_reduction:
56 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +000057 case OMPC_in_reduction:
58 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +000059 case OMPC_linear:
60 return static_cast<const OMPLinearClause *>(C);
Arpith Chacko Jacobfe4890a2017-01-18 20:40:48 +000061 case OMPC_if:
62 return static_cast<const OMPIfClause *>(C);
Arpith Chacko Jacob33c849a2017-01-25 00:57:16 +000063 case OMPC_num_threads:
64 return static_cast<const OMPNumThreadsClause *>(C);
Arpith Chacko Jacobbc126342017-01-25 11:28:18 +000065 case OMPC_num_teams:
66 return static_cast<const OMPNumTeamsClause *>(C);
Arpith Chacko Jacob7ecc0b72017-01-25 11:44:35 +000067 case OMPC_thread_limit:
68 return static_cast<const OMPThreadLimitClause *>(C);
Alexey Bataev931e19b2017-10-02 16:32:39 +000069 case OMPC_device:
70 return static_cast<const OMPDeviceClause *>(C);
Alexey Bataev3392d762016-02-16 11:18:12 +000071 case OMPC_default:
72 case OMPC_proc_bind:
Alexey Bataev3392d762016-02-16 11:18:12 +000073 case OMPC_final:
Alexey Bataev3392d762016-02-16 11:18:12 +000074 case OMPC_safelen:
75 case OMPC_simdlen:
76 case OMPC_collapse:
77 case OMPC_private:
Alexey Bataev005248a2016-02-25 05:25:57 +000078 case OMPC_shared:
Alexey Bataev005248a2016-02-25 05:25:57 +000079 case OMPC_aligned:
80 case OMPC_copyin:
81 case OMPC_copyprivate:
82 case OMPC_ordered:
83 case OMPC_nowait:
84 case OMPC_untied:
85 case OMPC_mergeable:
86 case OMPC_threadprivate:
87 case OMPC_flush:
88 case OMPC_read:
89 case OMPC_write:
90 case OMPC_update:
91 case OMPC_capture:
92 case OMPC_seq_cst:
93 case OMPC_depend:
Alexey Bataev005248a2016-02-25 05:25:57 +000094 case OMPC_threads:
95 case OMPC_simd:
96 case OMPC_map:
Alexey Bataev005248a2016-02-25 05:25:57 +000097 case OMPC_priority:
98 case OMPC_grainsize:
99 case OMPC_nogroup:
100 case OMPC_num_tasks:
101 case OMPC_hint:
102 case OMPC_defaultmap:
103 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000104 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000105 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000106 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000107 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000108 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000109 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000110 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000111 case OMPC_reverse_offload:
Alexey Bataev005248a2016-02-25 05:25:57 +0000112 break;
113 }
114
115 return nullptr;
116}
117
118OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
119 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
120 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
121}
122
123const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
124 switch (C->getClauseKind()) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000125 case OMPC_lastprivate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000126 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000127 case OMPC_reduction:
128 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +0000129 case OMPC_task_reduction:
130 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000131 case OMPC_in_reduction:
132 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000133 case OMPC_linear:
134 return static_cast<const OMPLinearClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000135 case OMPC_schedule:
136 case OMPC_dist_schedule:
137 case OMPC_firstprivate:
138 case OMPC_default:
139 case OMPC_proc_bind:
140 case OMPC_if:
141 case OMPC_final:
142 case OMPC_num_threads:
143 case OMPC_safelen:
144 case OMPC_simdlen:
145 case OMPC_collapse:
146 case OMPC_private:
Alexey Bataev3392d762016-02-16 11:18:12 +0000147 case OMPC_shared:
Alexey Bataev3392d762016-02-16 11:18:12 +0000148 case OMPC_aligned:
149 case OMPC_copyin:
150 case OMPC_copyprivate:
151 case OMPC_ordered:
152 case OMPC_nowait:
153 case OMPC_untied:
154 case OMPC_mergeable:
155 case OMPC_threadprivate:
156 case OMPC_flush:
157 case OMPC_read:
158 case OMPC_write:
159 case OMPC_update:
160 case OMPC_capture:
161 case OMPC_seq_cst:
162 case OMPC_depend:
163 case OMPC_device:
164 case OMPC_threads:
165 case OMPC_simd:
166 case OMPC_map:
167 case OMPC_num_teams:
168 case OMPC_thread_limit:
169 case OMPC_priority:
170 case OMPC_grainsize:
171 case OMPC_nogroup:
172 case OMPC_num_tasks:
173 case OMPC_hint:
174 case OMPC_defaultmap:
175 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000176 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000177 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000178 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000179 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000180 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000181 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000182 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000183 case OMPC_reverse_offload:
Alexey Bataev3392d762016-02-16 11:18:12 +0000184 break;
185 }
186
187 return nullptr;
188}
189
Alexey Bataevf138fda2018-08-13 19:04:24 +0000190OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
191 unsigned NumLoops,
192 SourceLocation StartLoc,
193 SourceLocation LParenLoc,
194 SourceLocation EndLoc) {
195 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
196 auto *Clause =
197 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
198 for (unsigned I = 0; I < NumLoops; ++I) {
199 Clause->setLoopNumIterations(I, nullptr);
200 Clause->setLoopCounter(I, nullptr);
201 }
202 return Clause;
203}
204
205OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
206 unsigned NumLoops) {
207 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
208 auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
209 for (unsigned I = 0; I < NumLoops; ++I) {
210 Clause->setLoopNumIterations(I, nullptr);
211 Clause->setLoopCounter(I, nullptr);
212 }
213 return Clause;
214}
215
216void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
217 Expr *NumIterations) {
218 assert(NumLoop < NumberOfLoops && "out of loops number.");
219 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
220}
221
222ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
223 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
224}
225
226void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
227 assert(NumLoop < NumberOfLoops && "out of loops number.");
228 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
229}
230
Mike Rice0ed46662018-09-20 17:19:41 +0000231Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000232 assert(NumLoop < NumberOfLoops && "out of loops number.");
233 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
234}
235
Mike Rice0ed46662018-09-20 17:19:41 +0000236const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000237 assert(NumLoop < NumberOfLoops && "out of loops number.");
238 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
239}
240
James Y Knightb8bfd962015-10-02 13:41:04 +0000241void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
242 assert(VL.size() == varlist_size() &&
243 "Number of private copies is not the same as the preallocated buffer");
244 std::copy(VL.begin(), VL.end(), varlist_end());
245}
246
247OMPPrivateClause *
248OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
249 SourceLocation LParenLoc, SourceLocation EndLoc,
250 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
251 // Allocate space for private variables and initializer expressions.
James Y Knight374fd202016-01-01 00:38:24 +0000252 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000253 OMPPrivateClause *Clause =
254 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
255 Clause->setVarRefs(VL);
256 Clause->setPrivateCopies(PrivateVL);
257 return Clause;
258}
259
260OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
261 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000262 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000263 return new (Mem) OMPPrivateClause(N);
264}
265
266void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
267 assert(VL.size() == varlist_size() &&
268 "Number of private copies is not the same as the preallocated buffer");
269 std::copy(VL.begin(), VL.end(), varlist_end());
270}
271
272void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
273 assert(VL.size() == varlist_size() &&
274 "Number of inits is not the same as the preallocated buffer");
275 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
276}
277
278OMPFirstprivateClause *
279OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
280 SourceLocation LParenLoc, SourceLocation EndLoc,
281 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
Alexey Bataev417089f2016-02-17 13:19:37 +0000282 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
James Y Knight374fd202016-01-01 00:38:24 +0000283 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000284 OMPFirstprivateClause *Clause =
285 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
286 Clause->setVarRefs(VL);
287 Clause->setPrivateCopies(PrivateVL);
288 Clause->setInits(InitVL);
Alexey Bataev417089f2016-02-17 13:19:37 +0000289 Clause->setPreInitStmt(PreInit);
James Y Knightb8bfd962015-10-02 13:41:04 +0000290 return Clause;
291}
292
293OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
294 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000295 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000296 return new (Mem) OMPFirstprivateClause(N);
297}
298
299void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
300 assert(PrivateCopies.size() == varlist_size() &&
301 "Number of private copies is not the same as the preallocated buffer");
302 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
303}
304
305void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
306 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
307 "not the same as the "
308 "preallocated buffer");
309 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
310}
311
312void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
313 assert(DstExprs.size() == varlist_size() && "Number of destination "
314 "expressions is not the same as "
315 "the preallocated buffer");
316 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
317}
318
319void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
320 assert(AssignmentOps.size() == varlist_size() &&
321 "Number of assignment expressions is not the same as the preallocated "
322 "buffer");
323 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
324 getDestinationExprs().end());
325}
326
327OMPLastprivateClause *OMPLastprivateClause::Create(
328 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
329 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
Alexey Bataev005248a2016-02-25 05:25:57 +0000330 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit,
331 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000332 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000333 OMPLastprivateClause *Clause =
334 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
335 Clause->setVarRefs(VL);
336 Clause->setSourceExprs(SrcExprs);
337 Clause->setDestinationExprs(DstExprs);
338 Clause->setAssignmentOps(AssignmentOps);
Alexey Bataev005248a2016-02-25 05:25:57 +0000339 Clause->setPreInitStmt(PreInit);
340 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000341 return Clause;
342}
343
344OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
345 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000346 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000347 return new (Mem) OMPLastprivateClause(N);
348}
349
350OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
351 SourceLocation StartLoc,
352 SourceLocation LParenLoc,
353 SourceLocation EndLoc,
354 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000355 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000356 OMPSharedClause *Clause =
357 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
358 Clause->setVarRefs(VL);
359 return Clause;
360}
361
362OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000363 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000364 return new (Mem) OMPSharedClause(N);
365}
366
367void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
368 assert(PL.size() == varlist_size() &&
369 "Number of privates is not the same as the preallocated buffer");
370 std::copy(PL.begin(), PL.end(), varlist_end());
371}
372
373void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
374 assert(IL.size() == varlist_size() &&
375 "Number of inits is not the same as the preallocated buffer");
376 std::copy(IL.begin(), IL.end(), getPrivates().end());
377}
378
379void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
380 assert(UL.size() == varlist_size() &&
381 "Number of updates is not the same as the preallocated buffer");
382 std::copy(UL.begin(), UL.end(), getInits().end());
383}
384
385void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
386 assert(FL.size() == varlist_size() &&
387 "Number of final updates is not the same as the preallocated buffer");
388 std::copy(FL.begin(), FL.end(), getUpdates().end());
389}
390
391OMPLinearClause *OMPLinearClause::Create(
392 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
393 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
394 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
Alexey Bataev78849fb2016-03-09 09:49:00 +0000395 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
396 Stmt *PreInit, Expr *PostUpdate) {
James Y Knightb8bfd962015-10-02 13:41:04 +0000397 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
398 // (Step and CalcStep).
James Y Knight374fd202016-01-01 00:38:24 +0000399 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2));
James Y Knightb8bfd962015-10-02 13:41:04 +0000400 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
401 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
402 Clause->setVarRefs(VL);
403 Clause->setPrivates(PL);
404 Clause->setInits(IL);
405 // Fill update and final expressions with zeroes, they are provided later,
406 // after the directive construction.
407 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
408 nullptr);
409 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
410 nullptr);
411 Clause->setStep(Step);
412 Clause->setCalcStep(CalcStep);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000413 Clause->setPreInitStmt(PreInit);
414 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000415 return Clause;
416}
417
418OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
419 unsigned NumVars) {
420 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
421 // (Step and CalcStep).
James Y Knight374fd202016-01-01 00:38:24 +0000422 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2));
James Y Knightb8bfd962015-10-02 13:41:04 +0000423 return new (Mem) OMPLinearClause(NumVars);
424}
425
426OMPAlignedClause *
427OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
428 SourceLocation LParenLoc, SourceLocation ColonLoc,
429 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
James Y Knight374fd202016-01-01 00:38:24 +0000430 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000431 OMPAlignedClause *Clause = new (Mem)
432 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
433 Clause->setVarRefs(VL);
434 Clause->setAlignment(A);
435 return Clause;
436}
437
438OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
439 unsigned NumVars) {
James Y Knight374fd202016-01-01 00:38:24 +0000440 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000441 return new (Mem) OMPAlignedClause(NumVars);
442}
443
444void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
445 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
446 "not the same as the "
447 "preallocated buffer");
448 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
449}
450
451void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
452 assert(DstExprs.size() == varlist_size() && "Number of destination "
453 "expressions is not the same as "
454 "the preallocated buffer");
455 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
456}
457
458void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
459 assert(AssignmentOps.size() == varlist_size() &&
460 "Number of assignment expressions is not the same as the preallocated "
461 "buffer");
462 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
463 getDestinationExprs().end());
464}
465
466OMPCopyinClause *OMPCopyinClause::Create(
467 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
468 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
469 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000470 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000471 OMPCopyinClause *Clause =
472 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
473 Clause->setVarRefs(VL);
474 Clause->setSourceExprs(SrcExprs);
475 Clause->setDestinationExprs(DstExprs);
476 Clause->setAssignmentOps(AssignmentOps);
477 return Clause;
478}
479
480OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000481 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000482 return new (Mem) OMPCopyinClause(N);
483}
484
485void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
486 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
487 "not the same as the "
488 "preallocated buffer");
489 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
490}
491
492void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
493 assert(DstExprs.size() == varlist_size() && "Number of destination "
494 "expressions is not the same as "
495 "the preallocated buffer");
496 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
497}
498
499void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
500 assert(AssignmentOps.size() == varlist_size() &&
501 "Number of assignment expressions is not the same as the preallocated "
502 "buffer");
503 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
504 getDestinationExprs().end());
505}
506
507OMPCopyprivateClause *OMPCopyprivateClause::Create(
508 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
509 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
510 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000511 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000512 OMPCopyprivateClause *Clause =
513 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
514 Clause->setVarRefs(VL);
515 Clause->setSourceExprs(SrcExprs);
516 Clause->setDestinationExprs(DstExprs);
517 Clause->setAssignmentOps(AssignmentOps);
518 return Clause;
519}
520
521OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
522 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000523 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000524 return new (Mem) OMPCopyprivateClause(N);
525}
526
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000527void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
528 assert(Privates.size() == varlist_size() &&
529 "Number of private copies is not the same as the preallocated buffer");
530 std::copy(Privates.begin(), Privates.end(), varlist_end());
531}
532
James Y Knightb8bfd962015-10-02 13:41:04 +0000533void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
534 assert(
535 LHSExprs.size() == varlist_size() &&
536 "Number of LHS expressions is not the same as the preallocated buffer");
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000537 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
James Y Knightb8bfd962015-10-02 13:41:04 +0000538}
539
540void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
541 assert(
542 RHSExprs.size() == varlist_size() &&
543 "Number of RHS expressions is not the same as the preallocated buffer");
544 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
545}
546
547void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
548 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
549 "expressions is not the same "
550 "as the preallocated buffer");
551 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
552}
553
554OMPReductionClause *OMPReductionClause::Create(
555 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
556 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
557 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000558 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev61205072016-03-02 04:57:40 +0000559 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
560 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000561 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000562 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
563 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
564 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000565 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000566 Clause->setLHSExprs(LHSExprs);
567 Clause->setRHSExprs(RHSExprs);
568 Clause->setReductionOps(ReductionOps);
Alexey Bataev61205072016-03-02 04:57:40 +0000569 Clause->setPreInitStmt(PreInit);
570 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000571 return Clause;
572}
573
574OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
575 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000576 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000577 return new (Mem) OMPReductionClause(N);
578}
579
Alexey Bataev169d96a2017-07-18 20:17:46 +0000580void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
581 assert(Privates.size() == varlist_size() &&
582 "Number of private copies is not the same as the preallocated buffer");
583 std::copy(Privates.begin(), Privates.end(), varlist_end());
584}
585
586void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
587 assert(
588 LHSExprs.size() == varlist_size() &&
589 "Number of LHS expressions is not the same as the preallocated buffer");
590 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
591}
592
593void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
594 assert(
595 RHSExprs.size() == varlist_size() &&
596 "Number of RHS expressions is not the same as the preallocated buffer");
597 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
598}
599
600void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
601 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
602 "expressions is not the same "
603 "as the preallocated buffer");
604 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
605}
606
607OMPTaskReductionClause *OMPTaskReductionClause::Create(
608 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
609 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
610 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
611 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
612 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
613 Expr *PostUpdate) {
614 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
615 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
616 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
617 Clause->setVarRefs(VL);
618 Clause->setPrivates(Privates);
619 Clause->setLHSExprs(LHSExprs);
620 Clause->setRHSExprs(RHSExprs);
621 Clause->setReductionOps(ReductionOps);
622 Clause->setPreInitStmt(PreInit);
623 Clause->setPostUpdateExpr(PostUpdate);
624 return Clause;
625}
626
627OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
628 unsigned N) {
629 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
630 return new (Mem) OMPTaskReductionClause(N);
631}
632
Alexey Bataevfa312f32017-07-21 18:48:21 +0000633void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
634 assert(Privates.size() == varlist_size() &&
635 "Number of private copies is not the same as the preallocated buffer");
636 std::copy(Privates.begin(), Privates.end(), varlist_end());
637}
638
639void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
640 assert(
641 LHSExprs.size() == varlist_size() &&
642 "Number of LHS expressions is not the same as the preallocated buffer");
643 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
644}
645
646void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
647 assert(
648 RHSExprs.size() == varlist_size() &&
649 "Number of RHS expressions is not the same as the preallocated buffer");
650 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
651}
652
653void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
654 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
655 "expressions is not the same "
656 "as the preallocated buffer");
657 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
658}
659
Alexey Bataev88202be2017-07-27 13:20:36 +0000660void OMPInReductionClause::setTaskgroupDescriptors(
661 ArrayRef<Expr *> TaskgroupDescriptors) {
662 assert(TaskgroupDescriptors.size() == varlist_size() &&
663 "Number of in reduction descriptors is not the same as the "
664 "preallocated buffer");
665 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
666 getReductionOps().end());
667}
668
Alexey Bataevfa312f32017-07-21 18:48:21 +0000669OMPInReductionClause *OMPInReductionClause::Create(
670 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
671 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
672 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
673 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev88202be2017-07-27 13:20:36 +0000674 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
675 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
676 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000677 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
678 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
679 Clause->setVarRefs(VL);
680 Clause->setPrivates(Privates);
681 Clause->setLHSExprs(LHSExprs);
682 Clause->setRHSExprs(RHSExprs);
683 Clause->setReductionOps(ReductionOps);
Alexey Bataev88202be2017-07-27 13:20:36 +0000684 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000685 Clause->setPreInitStmt(PreInit);
686 Clause->setPostUpdateExpr(PostUpdate);
687 return Clause;
688}
689
690OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
691 unsigned N) {
Alexey Bataev88202be2017-07-27 13:20:36 +0000692 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000693 return new (Mem) OMPInReductionClause(N);
694}
695
James Y Knightb8bfd962015-10-02 13:41:04 +0000696OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
697 SourceLocation StartLoc,
698 SourceLocation LParenLoc,
699 SourceLocation EndLoc,
700 ArrayRef<Expr *> VL) {
Alexey Bataev8b427062016-05-25 12:36:08 +0000701 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000702 OMPFlushClause *Clause =
703 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
704 Clause->setVarRefs(VL);
705 return Clause;
706}
707
708OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000709 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000710 return new (Mem) OMPFlushClause(N);
711}
712
Alexey Bataevf138fda2018-08-13 19:04:24 +0000713OMPDependClause *
714OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
715 SourceLocation LParenLoc, SourceLocation EndLoc,
716 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
717 SourceLocation ColonLoc, ArrayRef<Expr *> VL,
718 unsigned NumLoops) {
719 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
720 OMPDependClause *Clause = new (Mem)
721 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000722 Clause->setVarRefs(VL);
723 Clause->setDependencyKind(DepKind);
724 Clause->setDependencyLoc(DepLoc);
725 Clause->setColonLoc(ColonLoc);
Alexey Bataevf138fda2018-08-13 19:04:24 +0000726 for (unsigned I = 0 ; I < NumLoops; ++I)
727 Clause->setLoopData(I, nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000728 return Clause;
729}
730
Alexey Bataevf138fda2018-08-13 19:04:24 +0000731OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
732 unsigned NumLoops) {
733 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
734 return new (Mem) OMPDependClause(N, NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000735}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000736
Alexey Bataevf138fda2018-08-13 19:04:24 +0000737void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
738 assert((getDependencyKind() == OMPC_DEPEND_sink ||
739 getDependencyKind() == OMPC_DEPEND_source) &&
740 NumLoop < NumLoops &&
741 "Expected sink or source depend + loop index must be less number of "
742 "loops.");
743 auto It = std::next(getVarRefs().end(), NumLoop);
744 *It = Cnt;
Alexey Bataev8b427062016-05-25 12:36:08 +0000745}
746
Alexey Bataevf138fda2018-08-13 19:04:24 +0000747Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
748 assert((getDependencyKind() == OMPC_DEPEND_sink ||
749 getDependencyKind() == OMPC_DEPEND_source) &&
750 NumLoop < NumLoops &&
751 "Expected sink or source depend + loop index must be less number of "
752 "loops.");
753 auto It = std::next(getVarRefs().end(), NumLoop);
754 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000755}
756
Alexey Bataevf138fda2018-08-13 19:04:24 +0000757const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
758 assert((getDependencyKind() == OMPC_DEPEND_sink ||
759 getDependencyKind() == OMPC_DEPEND_source) &&
760 NumLoop < NumLoops &&
761 "Expected sink or source depend + loop index must be less number of "
762 "loops.");
763 auto It = std::next(getVarRefs().end(), NumLoop);
764 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000765}
766
Samuel Antao90927002016-04-26 14:54:23 +0000767unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
768 MappableExprComponentListsRef ComponentLists) {
769 unsigned TotalNum = 0u;
770 for (auto &C : ComponentLists)
771 TotalNum += C.size();
772 return TotalNum;
773}
774
775unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
Alexey Bataeve3727102018-04-18 15:57:46 +0000776 ArrayRef<const ValueDecl *> Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000777 unsigned TotalNum = 0u;
778 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
Alexey Bataeve3727102018-04-18 15:57:46 +0000779 for (const ValueDecl *D : Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000780 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
781 if (Cache.count(VD))
782 continue;
783 ++TotalNum;
784 Cache.insert(VD);
785 }
786 return TotalNum;
787}
788
789OMPMapClause *
790OMPMapClause::Create(const ASTContext &C, SourceLocation StartLoc,
791 SourceLocation LParenLoc, SourceLocation EndLoc,
792 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
793 MappableExprComponentListsRef ComponentLists,
794 OpenMPMapClauseKind TypeModifier, OpenMPMapClauseKind Type,
795 bool TypeIsImplicit, SourceLocation TypeLoc) {
Samuel Antao90927002016-04-26 14:54:23 +0000796 unsigned NumVars = Vars.size();
797 unsigned NumUniqueDeclarations =
798 getUniqueDeclarationsTotalNumber(Declarations);
799 unsigned NumComponentLists = ComponentLists.size();
800 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
801
802 // We need to allocate:
803 // NumVars x Expr* - we have an original list expression for each clause list
804 // entry.
805 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
806 // with each component list.
807 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
808 // number of lists for each unique declaration and the size of each component
809 // list.
810 // NumComponents x MappableComponent - the total of all the components in all
811 // the lists.
812 void *Mem = C.Allocate(
813 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
814 OMPClauseMappableExprCommon::MappableComponent>(
815 NumVars, NumUniqueDeclarations,
816 NumUniqueDeclarations + NumComponentLists, NumComponents));
817 OMPMapClause *Clause = new (Mem) OMPMapClause(
818 TypeModifier, Type, TypeIsImplicit, TypeLoc, StartLoc, LParenLoc, EndLoc,
819 NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents);
820
821 Clause->setVarRefs(Vars);
822 Clause->setClauseInfo(Declarations, ComponentLists);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000823 Clause->setMapTypeModifier(TypeModifier);
824 Clause->setMapType(Type);
825 Clause->setMapLoc(TypeLoc);
826 return Clause;
827}
828
Samuel Antao90927002016-04-26 14:54:23 +0000829OMPMapClause *OMPMapClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
830 unsigned NumUniqueDeclarations,
831 unsigned NumComponentLists,
832 unsigned NumComponents) {
833 void *Mem = C.Allocate(
834 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
835 OMPClauseMappableExprCommon::MappableComponent>(
836 NumVars, NumUniqueDeclarations,
837 NumUniqueDeclarations + NumComponentLists, NumComponents));
838 return new (Mem) OMPMapClause(NumVars, NumUniqueDeclarations,
839 NumComponentLists, NumComponents);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000840}
Samuel Antao661c0902016-05-26 17:39:58 +0000841
842OMPToClause *OMPToClause::Create(const ASTContext &C, SourceLocation StartLoc,
843 SourceLocation LParenLoc,
844 SourceLocation EndLoc, ArrayRef<Expr *> Vars,
845 ArrayRef<ValueDecl *> Declarations,
846 MappableExprComponentListsRef ComponentLists) {
847 unsigned NumVars = Vars.size();
848 unsigned NumUniqueDeclarations =
849 getUniqueDeclarationsTotalNumber(Declarations);
850 unsigned NumComponentLists = ComponentLists.size();
851 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
852
853 // We need to allocate:
854 // NumVars x Expr* - we have an original list expression for each clause list
855 // entry.
856 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
857 // with each component list.
858 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
859 // number of lists for each unique declaration and the size of each component
860 // list.
861 // NumComponents x MappableComponent - the total of all the components in all
862 // the lists.
863 void *Mem = C.Allocate(
864 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
865 OMPClauseMappableExprCommon::MappableComponent>(
866 NumVars, NumUniqueDeclarations,
867 NumUniqueDeclarations + NumComponentLists, NumComponents));
868
869 OMPToClause *Clause = new (Mem)
870 OMPToClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
871 NumComponentLists, NumComponents);
872
873 Clause->setVarRefs(Vars);
874 Clause->setClauseInfo(Declarations, ComponentLists);
875 return Clause;
876}
877
878OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
879 unsigned NumUniqueDeclarations,
880 unsigned NumComponentLists,
881 unsigned NumComponents) {
882 void *Mem = C.Allocate(
883 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
884 OMPClauseMappableExprCommon::MappableComponent>(
885 NumVars, NumUniqueDeclarations,
886 NumUniqueDeclarations + NumComponentLists, NumComponents));
887 return new (Mem) OMPToClause(NumVars, NumUniqueDeclarations,
888 NumComponentLists, NumComponents);
889}
Samuel Antaoec172c62016-05-26 17:49:04 +0000890
891OMPFromClause *
892OMPFromClause::Create(const ASTContext &C, SourceLocation StartLoc,
893 SourceLocation LParenLoc, SourceLocation EndLoc,
894 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
895 MappableExprComponentListsRef ComponentLists) {
896 unsigned NumVars = Vars.size();
897 unsigned NumUniqueDeclarations =
898 getUniqueDeclarationsTotalNumber(Declarations);
899 unsigned NumComponentLists = ComponentLists.size();
900 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
901
902 // We need to allocate:
903 // NumVars x Expr* - we have an original list expression for each clause list
904 // entry.
905 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
906 // with each component list.
907 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
908 // number of lists for each unique declaration and the size of each component
909 // list.
910 // NumComponents x MappableComponent - the total of all the components in all
911 // the lists.
912 void *Mem = C.Allocate(
913 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
914 OMPClauseMappableExprCommon::MappableComponent>(
915 NumVars, NumUniqueDeclarations,
916 NumUniqueDeclarations + NumComponentLists, NumComponents));
917
918 OMPFromClause *Clause = new (Mem)
919 OMPFromClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
920 NumComponentLists, NumComponents);
921
922 Clause->setVarRefs(Vars);
923 Clause->setClauseInfo(Declarations, ComponentLists);
924 return Clause;
925}
926
927OMPFromClause *OMPFromClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
928 unsigned NumUniqueDeclarations,
929 unsigned NumComponentLists,
930 unsigned NumComponents) {
931 void *Mem = C.Allocate(
932 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
933 OMPClauseMappableExprCommon::MappableComponent>(
934 NumVars, NumUniqueDeclarations,
935 NumUniqueDeclarations + NumComponentLists, NumComponents));
936 return new (Mem) OMPFromClause(NumVars, NumUniqueDeclarations,
937 NumComponentLists, NumComponents);
938}
Carlo Bertolli2404b172016-07-13 15:37:16 +0000939
Samuel Antaocc10b852016-07-28 14:23:26 +0000940void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
941 assert(VL.size() == varlist_size() &&
942 "Number of private copies is not the same as the preallocated buffer");
943 std::copy(VL.begin(), VL.end(), varlist_end());
944}
945
946void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
947 assert(VL.size() == varlist_size() &&
948 "Number of inits is not the same as the preallocated buffer");
949 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
950}
951
952OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
953 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
954 SourceLocation EndLoc, ArrayRef<Expr *> Vars, ArrayRef<Expr *> PrivateVars,
955 ArrayRef<Expr *> Inits, ArrayRef<ValueDecl *> Declarations,
956 MappableExprComponentListsRef ComponentLists) {
957 unsigned NumVars = Vars.size();
958 unsigned NumUniqueDeclarations =
959 getUniqueDeclarationsTotalNumber(Declarations);
960 unsigned NumComponentLists = ComponentLists.size();
961 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
962
963 // We need to allocate:
964 // 3 x NumVars x Expr* - we have an original list expression for each clause
965 // list entry and an equal number of private copies and inits.
966 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
967 // with each component list.
968 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
969 // number of lists for each unique declaration and the size of each component
970 // list.
971 // NumComponents x MappableComponent - the total of all the components in all
972 // the lists.
973 void *Mem = C.Allocate(
974 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
975 OMPClauseMappableExprCommon::MappableComponent>(
976 3 * NumVars, NumUniqueDeclarations,
977 NumUniqueDeclarations + NumComponentLists, NumComponents));
978
979 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(
980 StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
981 NumComponentLists, NumComponents);
982
983 Clause->setVarRefs(Vars);
984 Clause->setPrivateCopies(PrivateVars);
985 Clause->setInits(Inits);
986 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli2404b172016-07-13 15:37:16 +0000987 return Clause;
988}
989
Samuel Antaocc10b852016-07-28 14:23:26 +0000990OMPUseDevicePtrClause *OMPUseDevicePtrClause::CreateEmpty(
991 const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations,
992 unsigned NumComponentLists, unsigned NumComponents) {
993 void *Mem = C.Allocate(
994 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
995 OMPClauseMappableExprCommon::MappableComponent>(
996 3 * NumVars, NumUniqueDeclarations,
997 NumUniqueDeclarations + NumComponentLists, NumComponents));
998 return new (Mem) OMPUseDevicePtrClause(NumVars, NumUniqueDeclarations,
999 NumComponentLists, NumComponents);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001000}
Carlo Bertolli70594e92016-07-13 17:16:49 +00001001
Samuel Antao6890b092016-07-28 14:25:09 +00001002OMPIsDevicePtrClause *
1003OMPIsDevicePtrClause::Create(const ASTContext &C, SourceLocation StartLoc,
1004 SourceLocation LParenLoc, SourceLocation EndLoc,
1005 ArrayRef<Expr *> Vars,
1006 ArrayRef<ValueDecl *> Declarations,
1007 MappableExprComponentListsRef ComponentLists) {
1008 unsigned NumVars = Vars.size();
1009 unsigned NumUniqueDeclarations =
1010 getUniqueDeclarationsTotalNumber(Declarations);
1011 unsigned NumComponentLists = ComponentLists.size();
1012 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
1013
1014 // We need to allocate:
1015 // NumVars x Expr* - we have an original list expression for each clause list
1016 // entry.
1017 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1018 // with each component list.
1019 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1020 // number of lists for each unique declaration and the size of each component
1021 // list.
1022 // NumComponents x MappableComponent - the total of all the components in all
1023 // the lists.
1024 void *Mem = C.Allocate(
1025 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1026 OMPClauseMappableExprCommon::MappableComponent>(
1027 NumVars, NumUniqueDeclarations,
1028 NumUniqueDeclarations + NumComponentLists, NumComponents));
1029
1030 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(
1031 StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
1032 NumComponentLists, NumComponents);
1033
1034 Clause->setVarRefs(Vars);
1035 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001036 return Clause;
1037}
1038
Samuel Antao6890b092016-07-28 14:25:09 +00001039OMPIsDevicePtrClause *OMPIsDevicePtrClause::CreateEmpty(
1040 const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations,
1041 unsigned NumComponentLists, unsigned NumComponents) {
1042 void *Mem = C.Allocate(
1043 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1044 OMPClauseMappableExprCommon::MappableComponent>(
1045 NumVars, NumUniqueDeclarations,
1046 NumUniqueDeclarations + NumComponentLists, NumComponents));
1047 return new (Mem) OMPIsDevicePtrClause(NumVars, NumUniqueDeclarations,
1048 NumComponentLists, NumComponents);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001049}