blob: 79c49f206dd478df2b42acf0b8f1253481ca62ec [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:
Alexey Bataev005248a2016-02-25 05:25:57 +0000111 break;
112 }
113
114 return nullptr;
115}
116
117OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
118 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
119 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
120}
121
122const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
123 switch (C->getClauseKind()) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000124 case OMPC_lastprivate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000125 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000126 case OMPC_reduction:
127 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +0000128 case OMPC_task_reduction:
129 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000130 case OMPC_in_reduction:
131 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000132 case OMPC_linear:
133 return static_cast<const OMPLinearClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000134 case OMPC_schedule:
135 case OMPC_dist_schedule:
136 case OMPC_firstprivate:
137 case OMPC_default:
138 case OMPC_proc_bind:
139 case OMPC_if:
140 case OMPC_final:
141 case OMPC_num_threads:
142 case OMPC_safelen:
143 case OMPC_simdlen:
144 case OMPC_collapse:
145 case OMPC_private:
Alexey Bataev3392d762016-02-16 11:18:12 +0000146 case OMPC_shared:
Alexey Bataev3392d762016-02-16 11:18:12 +0000147 case OMPC_aligned:
148 case OMPC_copyin:
149 case OMPC_copyprivate:
150 case OMPC_ordered:
151 case OMPC_nowait:
152 case OMPC_untied:
153 case OMPC_mergeable:
154 case OMPC_threadprivate:
155 case OMPC_flush:
156 case OMPC_read:
157 case OMPC_write:
158 case OMPC_update:
159 case OMPC_capture:
160 case OMPC_seq_cst:
161 case OMPC_depend:
162 case OMPC_device:
163 case OMPC_threads:
164 case OMPC_simd:
165 case OMPC_map:
166 case OMPC_num_teams:
167 case OMPC_thread_limit:
168 case OMPC_priority:
169 case OMPC_grainsize:
170 case OMPC_nogroup:
171 case OMPC_num_tasks:
172 case OMPC_hint:
173 case OMPC_defaultmap:
174 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000175 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000176 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000177 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000178 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000179 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000180 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000181 case OMPC_unified_shared_memory:
Alexey Bataev3392d762016-02-16 11:18:12 +0000182 break;
183 }
184
185 return nullptr;
186}
187
Alexey Bataevf138fda2018-08-13 19:04:24 +0000188OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
189 unsigned NumLoops,
190 SourceLocation StartLoc,
191 SourceLocation LParenLoc,
192 SourceLocation EndLoc) {
193 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
194 auto *Clause =
195 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
196 for (unsigned I = 0; I < NumLoops; ++I) {
197 Clause->setLoopNumIterations(I, nullptr);
198 Clause->setLoopCounter(I, nullptr);
199 }
200 return Clause;
201}
202
203OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
204 unsigned NumLoops) {
205 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
206 auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
207 for (unsigned I = 0; I < NumLoops; ++I) {
208 Clause->setLoopNumIterations(I, nullptr);
209 Clause->setLoopCounter(I, nullptr);
210 }
211 return Clause;
212}
213
214void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
215 Expr *NumIterations) {
216 assert(NumLoop < NumberOfLoops && "out of loops number.");
217 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
218}
219
220ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
221 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
222}
223
224void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
225 assert(NumLoop < NumberOfLoops && "out of loops number.");
226 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
227}
228
Mike Rice0ed46662018-09-20 17:19:41 +0000229Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000230 assert(NumLoop < NumberOfLoops && "out of loops number.");
231 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
232}
233
Mike Rice0ed46662018-09-20 17:19:41 +0000234const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000235 assert(NumLoop < NumberOfLoops && "out of loops number.");
236 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
237}
238
James Y Knightb8bfd962015-10-02 13:41:04 +0000239void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
240 assert(VL.size() == varlist_size() &&
241 "Number of private copies is not the same as the preallocated buffer");
242 std::copy(VL.begin(), VL.end(), varlist_end());
243}
244
245OMPPrivateClause *
246OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
247 SourceLocation LParenLoc, SourceLocation EndLoc,
248 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
249 // Allocate space for private variables and initializer expressions.
James Y Knight374fd202016-01-01 00:38:24 +0000250 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000251 OMPPrivateClause *Clause =
252 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
253 Clause->setVarRefs(VL);
254 Clause->setPrivateCopies(PrivateVL);
255 return Clause;
256}
257
258OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
259 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000260 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000261 return new (Mem) OMPPrivateClause(N);
262}
263
264void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
265 assert(VL.size() == varlist_size() &&
266 "Number of private copies is not the same as the preallocated buffer");
267 std::copy(VL.begin(), VL.end(), varlist_end());
268}
269
270void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
271 assert(VL.size() == varlist_size() &&
272 "Number of inits is not the same as the preallocated buffer");
273 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
274}
275
276OMPFirstprivateClause *
277OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
278 SourceLocation LParenLoc, SourceLocation EndLoc,
279 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
Alexey Bataev417089f2016-02-17 13:19:37 +0000280 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
James Y Knight374fd202016-01-01 00:38:24 +0000281 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000282 OMPFirstprivateClause *Clause =
283 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
284 Clause->setVarRefs(VL);
285 Clause->setPrivateCopies(PrivateVL);
286 Clause->setInits(InitVL);
Alexey Bataev417089f2016-02-17 13:19:37 +0000287 Clause->setPreInitStmt(PreInit);
James Y Knightb8bfd962015-10-02 13:41:04 +0000288 return Clause;
289}
290
291OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
292 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000293 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000294 return new (Mem) OMPFirstprivateClause(N);
295}
296
297void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
298 assert(PrivateCopies.size() == varlist_size() &&
299 "Number of private copies is not the same as the preallocated buffer");
300 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
301}
302
303void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
304 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
305 "not the same as the "
306 "preallocated buffer");
307 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
308}
309
310void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
311 assert(DstExprs.size() == varlist_size() && "Number of destination "
312 "expressions is not the same as "
313 "the preallocated buffer");
314 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
315}
316
317void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
318 assert(AssignmentOps.size() == varlist_size() &&
319 "Number of assignment expressions is not the same as the preallocated "
320 "buffer");
321 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
322 getDestinationExprs().end());
323}
324
325OMPLastprivateClause *OMPLastprivateClause::Create(
326 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
327 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
Alexey Bataev005248a2016-02-25 05:25:57 +0000328 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit,
329 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000330 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000331 OMPLastprivateClause *Clause =
332 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
333 Clause->setVarRefs(VL);
334 Clause->setSourceExprs(SrcExprs);
335 Clause->setDestinationExprs(DstExprs);
336 Clause->setAssignmentOps(AssignmentOps);
Alexey Bataev005248a2016-02-25 05:25:57 +0000337 Clause->setPreInitStmt(PreInit);
338 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000339 return Clause;
340}
341
342OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
343 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000344 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000345 return new (Mem) OMPLastprivateClause(N);
346}
347
348OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
349 SourceLocation StartLoc,
350 SourceLocation LParenLoc,
351 SourceLocation EndLoc,
352 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000353 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000354 OMPSharedClause *Clause =
355 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
356 Clause->setVarRefs(VL);
357 return Clause;
358}
359
360OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000361 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000362 return new (Mem) OMPSharedClause(N);
363}
364
365void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
366 assert(PL.size() == varlist_size() &&
367 "Number of privates is not the same as the preallocated buffer");
368 std::copy(PL.begin(), PL.end(), varlist_end());
369}
370
371void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
372 assert(IL.size() == varlist_size() &&
373 "Number of inits is not the same as the preallocated buffer");
374 std::copy(IL.begin(), IL.end(), getPrivates().end());
375}
376
377void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
378 assert(UL.size() == varlist_size() &&
379 "Number of updates is not the same as the preallocated buffer");
380 std::copy(UL.begin(), UL.end(), getInits().end());
381}
382
383void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
384 assert(FL.size() == varlist_size() &&
385 "Number of final updates is not the same as the preallocated buffer");
386 std::copy(FL.begin(), FL.end(), getUpdates().end());
387}
388
389OMPLinearClause *OMPLinearClause::Create(
390 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
391 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
392 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
Alexey Bataev78849fb2016-03-09 09:49:00 +0000393 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
394 Stmt *PreInit, Expr *PostUpdate) {
James Y Knightb8bfd962015-10-02 13:41:04 +0000395 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
396 // (Step and CalcStep).
James Y Knight374fd202016-01-01 00:38:24 +0000397 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2));
James Y Knightb8bfd962015-10-02 13:41:04 +0000398 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
399 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
400 Clause->setVarRefs(VL);
401 Clause->setPrivates(PL);
402 Clause->setInits(IL);
403 // Fill update and final expressions with zeroes, they are provided later,
404 // after the directive construction.
405 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
406 nullptr);
407 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
408 nullptr);
409 Clause->setStep(Step);
410 Clause->setCalcStep(CalcStep);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000411 Clause->setPreInitStmt(PreInit);
412 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000413 return Clause;
414}
415
416OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
417 unsigned NumVars) {
418 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
419 // (Step and CalcStep).
James Y Knight374fd202016-01-01 00:38:24 +0000420 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2));
James Y Knightb8bfd962015-10-02 13:41:04 +0000421 return new (Mem) OMPLinearClause(NumVars);
422}
423
424OMPAlignedClause *
425OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
426 SourceLocation LParenLoc, SourceLocation ColonLoc,
427 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
James Y Knight374fd202016-01-01 00:38:24 +0000428 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000429 OMPAlignedClause *Clause = new (Mem)
430 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
431 Clause->setVarRefs(VL);
432 Clause->setAlignment(A);
433 return Clause;
434}
435
436OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
437 unsigned NumVars) {
James Y Knight374fd202016-01-01 00:38:24 +0000438 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000439 return new (Mem) OMPAlignedClause(NumVars);
440}
441
442void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
443 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
444 "not the same as the "
445 "preallocated buffer");
446 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
447}
448
449void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
450 assert(DstExprs.size() == varlist_size() && "Number of destination "
451 "expressions is not the same as "
452 "the preallocated buffer");
453 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
454}
455
456void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
457 assert(AssignmentOps.size() == varlist_size() &&
458 "Number of assignment expressions is not the same as the preallocated "
459 "buffer");
460 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
461 getDestinationExprs().end());
462}
463
464OMPCopyinClause *OMPCopyinClause::Create(
465 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
466 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
467 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000468 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000469 OMPCopyinClause *Clause =
470 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
471 Clause->setVarRefs(VL);
472 Clause->setSourceExprs(SrcExprs);
473 Clause->setDestinationExprs(DstExprs);
474 Clause->setAssignmentOps(AssignmentOps);
475 return Clause;
476}
477
478OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000479 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000480 return new (Mem) OMPCopyinClause(N);
481}
482
483void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
484 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
485 "not the same as the "
486 "preallocated buffer");
487 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
488}
489
490void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
491 assert(DstExprs.size() == varlist_size() && "Number of destination "
492 "expressions is not the same as "
493 "the preallocated buffer");
494 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
495}
496
497void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
498 assert(AssignmentOps.size() == varlist_size() &&
499 "Number of assignment expressions is not the same as the preallocated "
500 "buffer");
501 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
502 getDestinationExprs().end());
503}
504
505OMPCopyprivateClause *OMPCopyprivateClause::Create(
506 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
507 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
508 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000509 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000510 OMPCopyprivateClause *Clause =
511 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
512 Clause->setVarRefs(VL);
513 Clause->setSourceExprs(SrcExprs);
514 Clause->setDestinationExprs(DstExprs);
515 Clause->setAssignmentOps(AssignmentOps);
516 return Clause;
517}
518
519OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
520 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000521 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000522 return new (Mem) OMPCopyprivateClause(N);
523}
524
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000525void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
526 assert(Privates.size() == varlist_size() &&
527 "Number of private copies is not the same as the preallocated buffer");
528 std::copy(Privates.begin(), Privates.end(), varlist_end());
529}
530
James Y Knightb8bfd962015-10-02 13:41:04 +0000531void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
532 assert(
533 LHSExprs.size() == varlist_size() &&
534 "Number of LHS expressions is not the same as the preallocated buffer");
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000535 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
James Y Knightb8bfd962015-10-02 13:41:04 +0000536}
537
538void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
539 assert(
540 RHSExprs.size() == varlist_size() &&
541 "Number of RHS expressions is not the same as the preallocated buffer");
542 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
543}
544
545void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
546 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
547 "expressions is not the same "
548 "as the preallocated buffer");
549 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
550}
551
552OMPReductionClause *OMPReductionClause::Create(
553 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
554 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
555 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000556 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev61205072016-03-02 04:57:40 +0000557 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
558 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000559 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000560 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
561 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
562 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000563 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000564 Clause->setLHSExprs(LHSExprs);
565 Clause->setRHSExprs(RHSExprs);
566 Clause->setReductionOps(ReductionOps);
Alexey Bataev61205072016-03-02 04:57:40 +0000567 Clause->setPreInitStmt(PreInit);
568 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000569 return Clause;
570}
571
572OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
573 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000574 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000575 return new (Mem) OMPReductionClause(N);
576}
577
Alexey Bataev169d96a2017-07-18 20:17:46 +0000578void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
579 assert(Privates.size() == varlist_size() &&
580 "Number of private copies is not the same as the preallocated buffer");
581 std::copy(Privates.begin(), Privates.end(), varlist_end());
582}
583
584void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
585 assert(
586 LHSExprs.size() == varlist_size() &&
587 "Number of LHS expressions is not the same as the preallocated buffer");
588 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
589}
590
591void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
592 assert(
593 RHSExprs.size() == varlist_size() &&
594 "Number of RHS expressions is not the same as the preallocated buffer");
595 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
596}
597
598void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
599 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
600 "expressions is not the same "
601 "as the preallocated buffer");
602 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
603}
604
605OMPTaskReductionClause *OMPTaskReductionClause::Create(
606 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
607 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
608 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
609 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
610 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
611 Expr *PostUpdate) {
612 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
613 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
614 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
615 Clause->setVarRefs(VL);
616 Clause->setPrivates(Privates);
617 Clause->setLHSExprs(LHSExprs);
618 Clause->setRHSExprs(RHSExprs);
619 Clause->setReductionOps(ReductionOps);
620 Clause->setPreInitStmt(PreInit);
621 Clause->setPostUpdateExpr(PostUpdate);
622 return Clause;
623}
624
625OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
626 unsigned N) {
627 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
628 return new (Mem) OMPTaskReductionClause(N);
629}
630
Alexey Bataevfa312f32017-07-21 18:48:21 +0000631void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
632 assert(Privates.size() == varlist_size() &&
633 "Number of private copies is not the same as the preallocated buffer");
634 std::copy(Privates.begin(), Privates.end(), varlist_end());
635}
636
637void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
638 assert(
639 LHSExprs.size() == varlist_size() &&
640 "Number of LHS expressions is not the same as the preallocated buffer");
641 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
642}
643
644void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
645 assert(
646 RHSExprs.size() == varlist_size() &&
647 "Number of RHS expressions is not the same as the preallocated buffer");
648 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
649}
650
651void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
652 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
653 "expressions is not the same "
654 "as the preallocated buffer");
655 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
656}
657
Alexey Bataev88202be2017-07-27 13:20:36 +0000658void OMPInReductionClause::setTaskgroupDescriptors(
659 ArrayRef<Expr *> TaskgroupDescriptors) {
660 assert(TaskgroupDescriptors.size() == varlist_size() &&
661 "Number of in reduction descriptors is not the same as the "
662 "preallocated buffer");
663 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
664 getReductionOps().end());
665}
666
Alexey Bataevfa312f32017-07-21 18:48:21 +0000667OMPInReductionClause *OMPInReductionClause::Create(
668 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
669 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
670 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
671 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev88202be2017-07-27 13:20:36 +0000672 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
673 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
674 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000675 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
676 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
677 Clause->setVarRefs(VL);
678 Clause->setPrivates(Privates);
679 Clause->setLHSExprs(LHSExprs);
680 Clause->setRHSExprs(RHSExprs);
681 Clause->setReductionOps(ReductionOps);
Alexey Bataev88202be2017-07-27 13:20:36 +0000682 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000683 Clause->setPreInitStmt(PreInit);
684 Clause->setPostUpdateExpr(PostUpdate);
685 return Clause;
686}
687
688OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
689 unsigned N) {
Alexey Bataev88202be2017-07-27 13:20:36 +0000690 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000691 return new (Mem) OMPInReductionClause(N);
692}
693
James Y Knightb8bfd962015-10-02 13:41:04 +0000694OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
695 SourceLocation StartLoc,
696 SourceLocation LParenLoc,
697 SourceLocation EndLoc,
698 ArrayRef<Expr *> VL) {
Alexey Bataev8b427062016-05-25 12:36:08 +0000699 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000700 OMPFlushClause *Clause =
701 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
702 Clause->setVarRefs(VL);
703 return Clause;
704}
705
706OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000707 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000708 return new (Mem) OMPFlushClause(N);
709}
710
Alexey Bataevf138fda2018-08-13 19:04:24 +0000711OMPDependClause *
712OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
713 SourceLocation LParenLoc, SourceLocation EndLoc,
714 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
715 SourceLocation ColonLoc, ArrayRef<Expr *> VL,
716 unsigned NumLoops) {
717 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
718 OMPDependClause *Clause = new (Mem)
719 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000720 Clause->setVarRefs(VL);
721 Clause->setDependencyKind(DepKind);
722 Clause->setDependencyLoc(DepLoc);
723 Clause->setColonLoc(ColonLoc);
Alexey Bataevf138fda2018-08-13 19:04:24 +0000724 for (unsigned I = 0 ; I < NumLoops; ++I)
725 Clause->setLoopData(I, nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000726 return Clause;
727}
728
Alexey Bataevf138fda2018-08-13 19:04:24 +0000729OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
730 unsigned NumLoops) {
731 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
732 return new (Mem) OMPDependClause(N, NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000733}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000734
Alexey Bataevf138fda2018-08-13 19:04:24 +0000735void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
736 assert((getDependencyKind() == OMPC_DEPEND_sink ||
737 getDependencyKind() == OMPC_DEPEND_source) &&
738 NumLoop < NumLoops &&
739 "Expected sink or source depend + loop index must be less number of "
740 "loops.");
741 auto It = std::next(getVarRefs().end(), NumLoop);
742 *It = Cnt;
Alexey Bataev8b427062016-05-25 12:36:08 +0000743}
744
Alexey Bataevf138fda2018-08-13 19:04:24 +0000745Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
746 assert((getDependencyKind() == OMPC_DEPEND_sink ||
747 getDependencyKind() == OMPC_DEPEND_source) &&
748 NumLoop < NumLoops &&
749 "Expected sink or source depend + loop index must be less number of "
750 "loops.");
751 auto It = std::next(getVarRefs().end(), NumLoop);
752 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000753}
754
Alexey Bataevf138fda2018-08-13 19:04:24 +0000755const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
756 assert((getDependencyKind() == OMPC_DEPEND_sink ||
757 getDependencyKind() == OMPC_DEPEND_source) &&
758 NumLoop < NumLoops &&
759 "Expected sink or source depend + loop index must be less number of "
760 "loops.");
761 auto It = std::next(getVarRefs().end(), NumLoop);
762 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000763}
764
Samuel Antao90927002016-04-26 14:54:23 +0000765unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
766 MappableExprComponentListsRef ComponentLists) {
767 unsigned TotalNum = 0u;
768 for (auto &C : ComponentLists)
769 TotalNum += C.size();
770 return TotalNum;
771}
772
773unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
Alexey Bataeve3727102018-04-18 15:57:46 +0000774 ArrayRef<const ValueDecl *> Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000775 unsigned TotalNum = 0u;
776 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
Alexey Bataeve3727102018-04-18 15:57:46 +0000777 for (const ValueDecl *D : Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000778 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
779 if (Cache.count(VD))
780 continue;
781 ++TotalNum;
782 Cache.insert(VD);
783 }
784 return TotalNum;
785}
786
787OMPMapClause *
788OMPMapClause::Create(const ASTContext &C, SourceLocation StartLoc,
789 SourceLocation LParenLoc, SourceLocation EndLoc,
790 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
791 MappableExprComponentListsRef ComponentLists,
792 OpenMPMapClauseKind TypeModifier, OpenMPMapClauseKind Type,
793 bool TypeIsImplicit, SourceLocation TypeLoc) {
Samuel Antao90927002016-04-26 14:54:23 +0000794 unsigned NumVars = Vars.size();
795 unsigned NumUniqueDeclarations =
796 getUniqueDeclarationsTotalNumber(Declarations);
797 unsigned NumComponentLists = ComponentLists.size();
798 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
799
800 // We need to allocate:
801 // NumVars x Expr* - we have an original list expression for each clause list
802 // entry.
803 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
804 // with each component list.
805 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
806 // number of lists for each unique declaration and the size of each component
807 // list.
808 // NumComponents x MappableComponent - the total of all the components in all
809 // the lists.
810 void *Mem = C.Allocate(
811 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
812 OMPClauseMappableExprCommon::MappableComponent>(
813 NumVars, NumUniqueDeclarations,
814 NumUniqueDeclarations + NumComponentLists, NumComponents));
815 OMPMapClause *Clause = new (Mem) OMPMapClause(
816 TypeModifier, Type, TypeIsImplicit, TypeLoc, StartLoc, LParenLoc, EndLoc,
817 NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents);
818
819 Clause->setVarRefs(Vars);
820 Clause->setClauseInfo(Declarations, ComponentLists);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000821 Clause->setMapTypeModifier(TypeModifier);
822 Clause->setMapType(Type);
823 Clause->setMapLoc(TypeLoc);
824 return Clause;
825}
826
Samuel Antao90927002016-04-26 14:54:23 +0000827OMPMapClause *OMPMapClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
828 unsigned NumUniqueDeclarations,
829 unsigned NumComponentLists,
830 unsigned NumComponents) {
831 void *Mem = C.Allocate(
832 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
833 OMPClauseMappableExprCommon::MappableComponent>(
834 NumVars, NumUniqueDeclarations,
835 NumUniqueDeclarations + NumComponentLists, NumComponents));
836 return new (Mem) OMPMapClause(NumVars, NumUniqueDeclarations,
837 NumComponentLists, NumComponents);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000838}
Samuel Antao661c0902016-05-26 17:39:58 +0000839
840OMPToClause *OMPToClause::Create(const ASTContext &C, SourceLocation StartLoc,
841 SourceLocation LParenLoc,
842 SourceLocation EndLoc, ArrayRef<Expr *> Vars,
843 ArrayRef<ValueDecl *> Declarations,
844 MappableExprComponentListsRef ComponentLists) {
845 unsigned NumVars = Vars.size();
846 unsigned NumUniqueDeclarations =
847 getUniqueDeclarationsTotalNumber(Declarations);
848 unsigned NumComponentLists = ComponentLists.size();
849 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
850
851 // We need to allocate:
852 // NumVars x Expr* - we have an original list expression for each clause list
853 // entry.
854 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
855 // with each component list.
856 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
857 // number of lists for each unique declaration and the size of each component
858 // list.
859 // NumComponents x MappableComponent - the total of all the components in all
860 // the lists.
861 void *Mem = C.Allocate(
862 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
863 OMPClauseMappableExprCommon::MappableComponent>(
864 NumVars, NumUniqueDeclarations,
865 NumUniqueDeclarations + NumComponentLists, NumComponents));
866
867 OMPToClause *Clause = new (Mem)
868 OMPToClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
869 NumComponentLists, NumComponents);
870
871 Clause->setVarRefs(Vars);
872 Clause->setClauseInfo(Declarations, ComponentLists);
873 return Clause;
874}
875
876OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
877 unsigned NumUniqueDeclarations,
878 unsigned NumComponentLists,
879 unsigned NumComponents) {
880 void *Mem = C.Allocate(
881 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
882 OMPClauseMappableExprCommon::MappableComponent>(
883 NumVars, NumUniqueDeclarations,
884 NumUniqueDeclarations + NumComponentLists, NumComponents));
885 return new (Mem) OMPToClause(NumVars, NumUniqueDeclarations,
886 NumComponentLists, NumComponents);
887}
Samuel Antaoec172c62016-05-26 17:49:04 +0000888
889OMPFromClause *
890OMPFromClause::Create(const ASTContext &C, SourceLocation StartLoc,
891 SourceLocation LParenLoc, SourceLocation EndLoc,
892 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
893 MappableExprComponentListsRef ComponentLists) {
894 unsigned NumVars = Vars.size();
895 unsigned NumUniqueDeclarations =
896 getUniqueDeclarationsTotalNumber(Declarations);
897 unsigned NumComponentLists = ComponentLists.size();
898 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
899
900 // We need to allocate:
901 // NumVars x Expr* - we have an original list expression for each clause list
902 // entry.
903 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
904 // with each component list.
905 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
906 // number of lists for each unique declaration and the size of each component
907 // list.
908 // NumComponents x MappableComponent - the total of all the components in all
909 // the lists.
910 void *Mem = C.Allocate(
911 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
912 OMPClauseMappableExprCommon::MappableComponent>(
913 NumVars, NumUniqueDeclarations,
914 NumUniqueDeclarations + NumComponentLists, NumComponents));
915
916 OMPFromClause *Clause = new (Mem)
917 OMPFromClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
918 NumComponentLists, NumComponents);
919
920 Clause->setVarRefs(Vars);
921 Clause->setClauseInfo(Declarations, ComponentLists);
922 return Clause;
923}
924
925OMPFromClause *OMPFromClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
926 unsigned NumUniqueDeclarations,
927 unsigned NumComponentLists,
928 unsigned NumComponents) {
929 void *Mem = C.Allocate(
930 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
931 OMPClauseMappableExprCommon::MappableComponent>(
932 NumVars, NumUniqueDeclarations,
933 NumUniqueDeclarations + NumComponentLists, NumComponents));
934 return new (Mem) OMPFromClause(NumVars, NumUniqueDeclarations,
935 NumComponentLists, NumComponents);
936}
Carlo Bertolli2404b172016-07-13 15:37:16 +0000937
Samuel Antaocc10b852016-07-28 14:23:26 +0000938void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
939 assert(VL.size() == varlist_size() &&
940 "Number of private copies is not the same as the preallocated buffer");
941 std::copy(VL.begin(), VL.end(), varlist_end());
942}
943
944void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
945 assert(VL.size() == varlist_size() &&
946 "Number of inits is not the same as the preallocated buffer");
947 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
948}
949
950OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
951 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
952 SourceLocation EndLoc, ArrayRef<Expr *> Vars, ArrayRef<Expr *> PrivateVars,
953 ArrayRef<Expr *> Inits, ArrayRef<ValueDecl *> Declarations,
954 MappableExprComponentListsRef ComponentLists) {
955 unsigned NumVars = Vars.size();
956 unsigned NumUniqueDeclarations =
957 getUniqueDeclarationsTotalNumber(Declarations);
958 unsigned NumComponentLists = ComponentLists.size();
959 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
960
961 // We need to allocate:
962 // 3 x NumVars x Expr* - we have an original list expression for each clause
963 // list entry and an equal number of private copies and inits.
964 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
965 // with each component list.
966 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
967 // number of lists for each unique declaration and the size of each component
968 // list.
969 // NumComponents x MappableComponent - the total of all the components in all
970 // the lists.
971 void *Mem = C.Allocate(
972 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
973 OMPClauseMappableExprCommon::MappableComponent>(
974 3 * NumVars, NumUniqueDeclarations,
975 NumUniqueDeclarations + NumComponentLists, NumComponents));
976
977 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(
978 StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
979 NumComponentLists, NumComponents);
980
981 Clause->setVarRefs(Vars);
982 Clause->setPrivateCopies(PrivateVars);
983 Clause->setInits(Inits);
984 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli2404b172016-07-13 15:37:16 +0000985 return Clause;
986}
987
Samuel Antaocc10b852016-07-28 14:23:26 +0000988OMPUseDevicePtrClause *OMPUseDevicePtrClause::CreateEmpty(
989 const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations,
990 unsigned NumComponentLists, unsigned NumComponents) {
991 void *Mem = C.Allocate(
992 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
993 OMPClauseMappableExprCommon::MappableComponent>(
994 3 * NumVars, NumUniqueDeclarations,
995 NumUniqueDeclarations + NumComponentLists, NumComponents));
996 return new (Mem) OMPUseDevicePtrClause(NumVars, NumUniqueDeclarations,
997 NumComponentLists, NumComponents);
Carlo Bertolli2404b172016-07-13 15:37:16 +0000998}
Carlo Bertolli70594e92016-07-13 17:16:49 +0000999
Samuel Antao6890b092016-07-28 14:25:09 +00001000OMPIsDevicePtrClause *
1001OMPIsDevicePtrClause::Create(const ASTContext &C, SourceLocation StartLoc,
1002 SourceLocation LParenLoc, SourceLocation EndLoc,
1003 ArrayRef<Expr *> Vars,
1004 ArrayRef<ValueDecl *> Declarations,
1005 MappableExprComponentListsRef ComponentLists) {
1006 unsigned NumVars = Vars.size();
1007 unsigned NumUniqueDeclarations =
1008 getUniqueDeclarationsTotalNumber(Declarations);
1009 unsigned NumComponentLists = ComponentLists.size();
1010 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
1011
1012 // We need to allocate:
1013 // NumVars x Expr* - we have an original list expression for each clause list
1014 // entry.
1015 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1016 // with each component list.
1017 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1018 // number of lists for each unique declaration and the size of each component
1019 // list.
1020 // NumComponents x MappableComponent - the total of all the components in all
1021 // the lists.
1022 void *Mem = C.Allocate(
1023 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1024 OMPClauseMappableExprCommon::MappableComponent>(
1025 NumVars, NumUniqueDeclarations,
1026 NumUniqueDeclarations + NumComponentLists, NumComponents));
1027
1028 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(
1029 StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
1030 NumComponentLists, NumComponents);
1031
1032 Clause->setVarRefs(Vars);
1033 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001034 return Clause;
1035}
1036
Samuel Antao6890b092016-07-28 14:25:09 +00001037OMPIsDevicePtrClause *OMPIsDevicePtrClause::CreateEmpty(
1038 const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations,
1039 unsigned NumComponentLists, unsigned NumComponents) {
1040 void *Mem = C.Allocate(
1041 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1042 OMPClauseMappableExprCommon::MappableComponent>(
1043 NumVars, NumUniqueDeclarations,
1044 NumUniqueDeclarations + NumComponentLists, NumComponents));
1045 return new (Mem) OMPIsDevicePtrClause(NumVars, NumUniqueDeclarations,
1046 NumComponentLists, NumComponents);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001047}