blob: 4feac0cfd0416e8b7a27eab981e9391c01bd1647 [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:
Alexey Bataev005248a2016-02-25 05:25:57 +0000109 break;
110 }
111
112 return nullptr;
113}
114
115OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
116 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
117 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
118}
119
120const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
121 switch (C->getClauseKind()) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000122 case OMPC_lastprivate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000123 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000124 case OMPC_reduction:
125 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +0000126 case OMPC_task_reduction:
127 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000128 case OMPC_in_reduction:
129 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000130 case OMPC_linear:
131 return static_cast<const OMPLinearClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000132 case OMPC_schedule:
133 case OMPC_dist_schedule:
134 case OMPC_firstprivate:
135 case OMPC_default:
136 case OMPC_proc_bind:
137 case OMPC_if:
138 case OMPC_final:
139 case OMPC_num_threads:
140 case OMPC_safelen:
141 case OMPC_simdlen:
142 case OMPC_collapse:
143 case OMPC_private:
Alexey Bataev3392d762016-02-16 11:18:12 +0000144 case OMPC_shared:
Alexey Bataev3392d762016-02-16 11:18:12 +0000145 case OMPC_aligned:
146 case OMPC_copyin:
147 case OMPC_copyprivate:
148 case OMPC_ordered:
149 case OMPC_nowait:
150 case OMPC_untied:
151 case OMPC_mergeable:
152 case OMPC_threadprivate:
153 case OMPC_flush:
154 case OMPC_read:
155 case OMPC_write:
156 case OMPC_update:
157 case OMPC_capture:
158 case OMPC_seq_cst:
159 case OMPC_depend:
160 case OMPC_device:
161 case OMPC_threads:
162 case OMPC_simd:
163 case OMPC_map:
164 case OMPC_num_teams:
165 case OMPC_thread_limit:
166 case OMPC_priority:
167 case OMPC_grainsize:
168 case OMPC_nogroup:
169 case OMPC_num_tasks:
170 case OMPC_hint:
171 case OMPC_defaultmap:
172 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000173 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000174 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000175 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000176 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000177 case OMPC_is_device_ptr:
Alexey Bataev3392d762016-02-16 11:18:12 +0000178 break;
179 }
180
181 return nullptr;
182}
183
James Y Knightb8bfd962015-10-02 13:41:04 +0000184void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
185 assert(VL.size() == varlist_size() &&
186 "Number of private copies is not the same as the preallocated buffer");
187 std::copy(VL.begin(), VL.end(), varlist_end());
188}
189
190OMPPrivateClause *
191OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
192 SourceLocation LParenLoc, SourceLocation EndLoc,
193 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
194 // Allocate space for private variables and initializer expressions.
James Y Knight374fd202016-01-01 00:38:24 +0000195 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000196 OMPPrivateClause *Clause =
197 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
198 Clause->setVarRefs(VL);
199 Clause->setPrivateCopies(PrivateVL);
200 return Clause;
201}
202
203OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
204 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000205 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000206 return new (Mem) OMPPrivateClause(N);
207}
208
209void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
210 assert(VL.size() == varlist_size() &&
211 "Number of private copies is not the same as the preallocated buffer");
212 std::copy(VL.begin(), VL.end(), varlist_end());
213}
214
215void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
216 assert(VL.size() == varlist_size() &&
217 "Number of inits is not the same as the preallocated buffer");
218 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
219}
220
221OMPFirstprivateClause *
222OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
223 SourceLocation LParenLoc, SourceLocation EndLoc,
224 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
Alexey Bataev417089f2016-02-17 13:19:37 +0000225 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
James Y Knight374fd202016-01-01 00:38:24 +0000226 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000227 OMPFirstprivateClause *Clause =
228 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
229 Clause->setVarRefs(VL);
230 Clause->setPrivateCopies(PrivateVL);
231 Clause->setInits(InitVL);
Alexey Bataev417089f2016-02-17 13:19:37 +0000232 Clause->setPreInitStmt(PreInit);
James Y Knightb8bfd962015-10-02 13:41:04 +0000233 return Clause;
234}
235
236OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
237 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000238 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000239 return new (Mem) OMPFirstprivateClause(N);
240}
241
242void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
243 assert(PrivateCopies.size() == varlist_size() &&
244 "Number of private copies is not the same as the preallocated buffer");
245 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
246}
247
248void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
249 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
250 "not the same as the "
251 "preallocated buffer");
252 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
253}
254
255void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
256 assert(DstExprs.size() == varlist_size() && "Number of destination "
257 "expressions is not the same as "
258 "the preallocated buffer");
259 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
260}
261
262void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
263 assert(AssignmentOps.size() == varlist_size() &&
264 "Number of assignment expressions is not the same as the preallocated "
265 "buffer");
266 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
267 getDestinationExprs().end());
268}
269
270OMPLastprivateClause *OMPLastprivateClause::Create(
271 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
272 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
Alexey Bataev005248a2016-02-25 05:25:57 +0000273 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit,
274 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000275 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000276 OMPLastprivateClause *Clause =
277 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
278 Clause->setVarRefs(VL);
279 Clause->setSourceExprs(SrcExprs);
280 Clause->setDestinationExprs(DstExprs);
281 Clause->setAssignmentOps(AssignmentOps);
Alexey Bataev005248a2016-02-25 05:25:57 +0000282 Clause->setPreInitStmt(PreInit);
283 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000284 return Clause;
285}
286
287OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
288 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000289 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000290 return new (Mem) OMPLastprivateClause(N);
291}
292
293OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
294 SourceLocation StartLoc,
295 SourceLocation LParenLoc,
296 SourceLocation EndLoc,
297 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000298 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000299 OMPSharedClause *Clause =
300 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
301 Clause->setVarRefs(VL);
302 return Clause;
303}
304
305OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000306 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000307 return new (Mem) OMPSharedClause(N);
308}
309
310void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
311 assert(PL.size() == varlist_size() &&
312 "Number of privates is not the same as the preallocated buffer");
313 std::copy(PL.begin(), PL.end(), varlist_end());
314}
315
316void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
317 assert(IL.size() == varlist_size() &&
318 "Number of inits is not the same as the preallocated buffer");
319 std::copy(IL.begin(), IL.end(), getPrivates().end());
320}
321
322void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
323 assert(UL.size() == varlist_size() &&
324 "Number of updates is not the same as the preallocated buffer");
325 std::copy(UL.begin(), UL.end(), getInits().end());
326}
327
328void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
329 assert(FL.size() == varlist_size() &&
330 "Number of final updates is not the same as the preallocated buffer");
331 std::copy(FL.begin(), FL.end(), getUpdates().end());
332}
333
334OMPLinearClause *OMPLinearClause::Create(
335 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
336 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
337 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
Alexey Bataev78849fb2016-03-09 09:49:00 +0000338 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
339 Stmt *PreInit, Expr *PostUpdate) {
James Y Knightb8bfd962015-10-02 13:41:04 +0000340 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
341 // (Step and CalcStep).
James Y Knight374fd202016-01-01 00:38:24 +0000342 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2));
James Y Knightb8bfd962015-10-02 13:41:04 +0000343 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
344 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
345 Clause->setVarRefs(VL);
346 Clause->setPrivates(PL);
347 Clause->setInits(IL);
348 // Fill update and final expressions with zeroes, they are provided later,
349 // after the directive construction.
350 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
351 nullptr);
352 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
353 nullptr);
354 Clause->setStep(Step);
355 Clause->setCalcStep(CalcStep);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000356 Clause->setPreInitStmt(PreInit);
357 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000358 return Clause;
359}
360
361OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
362 unsigned NumVars) {
363 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
364 // (Step and CalcStep).
James Y Knight374fd202016-01-01 00:38:24 +0000365 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2));
James Y Knightb8bfd962015-10-02 13:41:04 +0000366 return new (Mem) OMPLinearClause(NumVars);
367}
368
369OMPAlignedClause *
370OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
371 SourceLocation LParenLoc, SourceLocation ColonLoc,
372 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
James Y Knight374fd202016-01-01 00:38:24 +0000373 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000374 OMPAlignedClause *Clause = new (Mem)
375 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
376 Clause->setVarRefs(VL);
377 Clause->setAlignment(A);
378 return Clause;
379}
380
381OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
382 unsigned NumVars) {
James Y Knight374fd202016-01-01 00:38:24 +0000383 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000384 return new (Mem) OMPAlignedClause(NumVars);
385}
386
387void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
388 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
389 "not the same as the "
390 "preallocated buffer");
391 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
392}
393
394void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
395 assert(DstExprs.size() == varlist_size() && "Number of destination "
396 "expressions is not the same as "
397 "the preallocated buffer");
398 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
399}
400
401void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
402 assert(AssignmentOps.size() == varlist_size() &&
403 "Number of assignment expressions is not the same as the preallocated "
404 "buffer");
405 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
406 getDestinationExprs().end());
407}
408
409OMPCopyinClause *OMPCopyinClause::Create(
410 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
411 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
412 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000413 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000414 OMPCopyinClause *Clause =
415 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
416 Clause->setVarRefs(VL);
417 Clause->setSourceExprs(SrcExprs);
418 Clause->setDestinationExprs(DstExprs);
419 Clause->setAssignmentOps(AssignmentOps);
420 return Clause;
421}
422
423OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000424 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000425 return new (Mem) OMPCopyinClause(N);
426}
427
428void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
429 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
430 "not the same as the "
431 "preallocated buffer");
432 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
433}
434
435void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
436 assert(DstExprs.size() == varlist_size() && "Number of destination "
437 "expressions is not the same as "
438 "the preallocated buffer");
439 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
440}
441
442void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
443 assert(AssignmentOps.size() == varlist_size() &&
444 "Number of assignment expressions is not the same as the preallocated "
445 "buffer");
446 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
447 getDestinationExprs().end());
448}
449
450OMPCopyprivateClause *OMPCopyprivateClause::Create(
451 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
452 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
453 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000454 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000455 OMPCopyprivateClause *Clause =
456 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
457 Clause->setVarRefs(VL);
458 Clause->setSourceExprs(SrcExprs);
459 Clause->setDestinationExprs(DstExprs);
460 Clause->setAssignmentOps(AssignmentOps);
461 return Clause;
462}
463
464OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
465 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000466 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000467 return new (Mem) OMPCopyprivateClause(N);
468}
469
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000470void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
471 assert(Privates.size() == varlist_size() &&
472 "Number of private copies is not the same as the preallocated buffer");
473 std::copy(Privates.begin(), Privates.end(), varlist_end());
474}
475
James Y Knightb8bfd962015-10-02 13:41:04 +0000476void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
477 assert(
478 LHSExprs.size() == varlist_size() &&
479 "Number of LHS expressions is not the same as the preallocated buffer");
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000480 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
James Y Knightb8bfd962015-10-02 13:41:04 +0000481}
482
483void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
484 assert(
485 RHSExprs.size() == varlist_size() &&
486 "Number of RHS expressions is not the same as the preallocated buffer");
487 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
488}
489
490void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
491 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
492 "expressions is not the same "
493 "as the preallocated buffer");
494 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
495}
496
497OMPReductionClause *OMPReductionClause::Create(
498 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
499 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
500 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000501 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev61205072016-03-02 04:57:40 +0000502 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
503 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000504 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000505 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
506 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
507 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000508 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000509 Clause->setLHSExprs(LHSExprs);
510 Clause->setRHSExprs(RHSExprs);
511 Clause->setReductionOps(ReductionOps);
Alexey Bataev61205072016-03-02 04:57:40 +0000512 Clause->setPreInitStmt(PreInit);
513 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000514 return Clause;
515}
516
517OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
518 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000519 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000520 return new (Mem) OMPReductionClause(N);
521}
522
Alexey Bataev169d96a2017-07-18 20:17:46 +0000523void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
524 assert(Privates.size() == varlist_size() &&
525 "Number of private copies is not the same as the preallocated buffer");
526 std::copy(Privates.begin(), Privates.end(), varlist_end());
527}
528
529void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
530 assert(
531 LHSExprs.size() == varlist_size() &&
532 "Number of LHS expressions is not the same as the preallocated buffer");
533 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
534}
535
536void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
537 assert(
538 RHSExprs.size() == varlist_size() &&
539 "Number of RHS expressions is not the same as the preallocated buffer");
540 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
541}
542
543void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
544 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
545 "expressions is not the same "
546 "as the preallocated buffer");
547 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
548}
549
550OMPTaskReductionClause *OMPTaskReductionClause::Create(
551 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
552 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
553 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
554 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
555 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
556 Expr *PostUpdate) {
557 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
558 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
559 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
560 Clause->setVarRefs(VL);
561 Clause->setPrivates(Privates);
562 Clause->setLHSExprs(LHSExprs);
563 Clause->setRHSExprs(RHSExprs);
564 Clause->setReductionOps(ReductionOps);
565 Clause->setPreInitStmt(PreInit);
566 Clause->setPostUpdateExpr(PostUpdate);
567 return Clause;
568}
569
570OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
571 unsigned N) {
572 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
573 return new (Mem) OMPTaskReductionClause(N);
574}
575
Alexey Bataevfa312f32017-07-21 18:48:21 +0000576void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
577 assert(Privates.size() == varlist_size() &&
578 "Number of private copies is not the same as the preallocated buffer");
579 std::copy(Privates.begin(), Privates.end(), varlist_end());
580}
581
582void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
583 assert(
584 LHSExprs.size() == varlist_size() &&
585 "Number of LHS expressions is not the same as the preallocated buffer");
586 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
587}
588
589void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
590 assert(
591 RHSExprs.size() == varlist_size() &&
592 "Number of RHS expressions is not the same as the preallocated buffer");
593 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
594}
595
596void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
597 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
598 "expressions is not the same "
599 "as the preallocated buffer");
600 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
601}
602
Alexey Bataev88202be2017-07-27 13:20:36 +0000603void OMPInReductionClause::setTaskgroupDescriptors(
604 ArrayRef<Expr *> TaskgroupDescriptors) {
605 assert(TaskgroupDescriptors.size() == varlist_size() &&
606 "Number of in reduction descriptors is not the same as the "
607 "preallocated buffer");
608 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
609 getReductionOps().end());
610}
611
Alexey Bataevfa312f32017-07-21 18:48:21 +0000612OMPInReductionClause *OMPInReductionClause::Create(
613 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
614 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
615 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
616 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev88202be2017-07-27 13:20:36 +0000617 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
618 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
619 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000620 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
621 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
622 Clause->setVarRefs(VL);
623 Clause->setPrivates(Privates);
624 Clause->setLHSExprs(LHSExprs);
625 Clause->setRHSExprs(RHSExprs);
626 Clause->setReductionOps(ReductionOps);
Alexey Bataev88202be2017-07-27 13:20:36 +0000627 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000628 Clause->setPreInitStmt(PreInit);
629 Clause->setPostUpdateExpr(PostUpdate);
630 return Clause;
631}
632
633OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
634 unsigned N) {
Alexey Bataev88202be2017-07-27 13:20:36 +0000635 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000636 return new (Mem) OMPInReductionClause(N);
637}
638
James Y Knightb8bfd962015-10-02 13:41:04 +0000639OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
640 SourceLocation StartLoc,
641 SourceLocation LParenLoc,
642 SourceLocation EndLoc,
643 ArrayRef<Expr *> VL) {
Alexey Bataev8b427062016-05-25 12:36:08 +0000644 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000645 OMPFlushClause *Clause =
646 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
647 Clause->setVarRefs(VL);
648 return Clause;
649}
650
651OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000652 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000653 return new (Mem) OMPFlushClause(N);
654}
655
Alexey Bataev8b427062016-05-25 12:36:08 +0000656OMPDependClause *OMPDependClause::Create(
657 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
658 SourceLocation EndLoc, OpenMPDependClauseKind DepKind,
659 SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL) {
660 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000661 OMPDependClause *Clause =
662 new (Mem) OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size());
663 Clause->setVarRefs(VL);
664 Clause->setDependencyKind(DepKind);
665 Clause->setDependencyLoc(DepLoc);
666 Clause->setColonLoc(ColonLoc);
Alexey Bataev8b427062016-05-25 12:36:08 +0000667 Clause->setCounterValue(nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000668 return Clause;
669}
670
671OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N) {
Alexey Bataev2af820542016-05-25 12:51:24 +0000672 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000673 return new (Mem) OMPDependClause(N);
674}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000675
Alexey Bataev8b427062016-05-25 12:36:08 +0000676void OMPDependClause::setCounterValue(Expr *V) {
677 assert(getDependencyKind() == OMPC_DEPEND_sink ||
678 getDependencyKind() == OMPC_DEPEND_source || V == nullptr);
679 *getVarRefs().end() = V;
680}
681
682const Expr *OMPDependClause::getCounterValue() const {
683 auto *V = *getVarRefs().end();
684 assert(getDependencyKind() == OMPC_DEPEND_sink ||
685 getDependencyKind() == OMPC_DEPEND_source || V == nullptr);
686 return V;
687}
688
689Expr *OMPDependClause::getCounterValue() {
690 auto *V = *getVarRefs().end();
691 assert(getDependencyKind() == OMPC_DEPEND_sink ||
692 getDependencyKind() == OMPC_DEPEND_source || V == nullptr);
693 return V;
694}
695
Samuel Antao90927002016-04-26 14:54:23 +0000696unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
697 MappableExprComponentListsRef ComponentLists) {
698 unsigned TotalNum = 0u;
699 for (auto &C : ComponentLists)
700 TotalNum += C.size();
701 return TotalNum;
702}
703
704unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
705 ArrayRef<ValueDecl *> Declarations) {
706 unsigned TotalNum = 0u;
707 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
708 for (auto *D : Declarations) {
709 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
710 if (Cache.count(VD))
711 continue;
712 ++TotalNum;
713 Cache.insert(VD);
714 }
715 return TotalNum;
716}
717
718OMPMapClause *
719OMPMapClause::Create(const ASTContext &C, SourceLocation StartLoc,
720 SourceLocation LParenLoc, SourceLocation EndLoc,
721 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
722 MappableExprComponentListsRef ComponentLists,
723 OpenMPMapClauseKind TypeModifier, OpenMPMapClauseKind Type,
724 bool TypeIsImplicit, SourceLocation TypeLoc) {
Samuel Antao90927002016-04-26 14:54:23 +0000725 unsigned NumVars = Vars.size();
726 unsigned NumUniqueDeclarations =
727 getUniqueDeclarationsTotalNumber(Declarations);
728 unsigned NumComponentLists = ComponentLists.size();
729 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
730
731 // We need to allocate:
732 // NumVars x Expr* - we have an original list expression for each clause list
733 // entry.
734 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
735 // with each component list.
736 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
737 // number of lists for each unique declaration and the size of each component
738 // list.
739 // NumComponents x MappableComponent - the total of all the components in all
740 // the lists.
741 void *Mem = C.Allocate(
742 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
743 OMPClauseMappableExprCommon::MappableComponent>(
744 NumVars, NumUniqueDeclarations,
745 NumUniqueDeclarations + NumComponentLists, NumComponents));
746 OMPMapClause *Clause = new (Mem) OMPMapClause(
747 TypeModifier, Type, TypeIsImplicit, TypeLoc, StartLoc, LParenLoc, EndLoc,
748 NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents);
749
750 Clause->setVarRefs(Vars);
751 Clause->setClauseInfo(Declarations, ComponentLists);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000752 Clause->setMapTypeModifier(TypeModifier);
753 Clause->setMapType(Type);
754 Clause->setMapLoc(TypeLoc);
755 return Clause;
756}
757
Samuel Antao90927002016-04-26 14:54:23 +0000758OMPMapClause *OMPMapClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
759 unsigned NumUniqueDeclarations,
760 unsigned NumComponentLists,
761 unsigned NumComponents) {
762 void *Mem = C.Allocate(
763 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
764 OMPClauseMappableExprCommon::MappableComponent>(
765 NumVars, NumUniqueDeclarations,
766 NumUniqueDeclarations + NumComponentLists, NumComponents));
767 return new (Mem) OMPMapClause(NumVars, NumUniqueDeclarations,
768 NumComponentLists, NumComponents);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000769}
Samuel Antao661c0902016-05-26 17:39:58 +0000770
771OMPToClause *OMPToClause::Create(const ASTContext &C, SourceLocation StartLoc,
772 SourceLocation LParenLoc,
773 SourceLocation EndLoc, ArrayRef<Expr *> Vars,
774 ArrayRef<ValueDecl *> Declarations,
775 MappableExprComponentListsRef ComponentLists) {
776 unsigned NumVars = Vars.size();
777 unsigned NumUniqueDeclarations =
778 getUniqueDeclarationsTotalNumber(Declarations);
779 unsigned NumComponentLists = ComponentLists.size();
780 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
781
782 // We need to allocate:
783 // NumVars x Expr* - we have an original list expression for each clause list
784 // entry.
785 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
786 // with each component list.
787 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
788 // number of lists for each unique declaration and the size of each component
789 // list.
790 // NumComponents x MappableComponent - the total of all the components in all
791 // the lists.
792 void *Mem = C.Allocate(
793 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
794 OMPClauseMappableExprCommon::MappableComponent>(
795 NumVars, NumUniqueDeclarations,
796 NumUniqueDeclarations + NumComponentLists, NumComponents));
797
798 OMPToClause *Clause = new (Mem)
799 OMPToClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
800 NumComponentLists, NumComponents);
801
802 Clause->setVarRefs(Vars);
803 Clause->setClauseInfo(Declarations, ComponentLists);
804 return Clause;
805}
806
807OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
808 unsigned NumUniqueDeclarations,
809 unsigned NumComponentLists,
810 unsigned NumComponents) {
811 void *Mem = C.Allocate(
812 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
813 OMPClauseMappableExprCommon::MappableComponent>(
814 NumVars, NumUniqueDeclarations,
815 NumUniqueDeclarations + NumComponentLists, NumComponents));
816 return new (Mem) OMPToClause(NumVars, NumUniqueDeclarations,
817 NumComponentLists, NumComponents);
818}
Samuel Antaoec172c62016-05-26 17:49:04 +0000819
820OMPFromClause *
821OMPFromClause::Create(const ASTContext &C, SourceLocation StartLoc,
822 SourceLocation LParenLoc, SourceLocation EndLoc,
823 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
824 MappableExprComponentListsRef ComponentLists) {
825 unsigned NumVars = Vars.size();
826 unsigned NumUniqueDeclarations =
827 getUniqueDeclarationsTotalNumber(Declarations);
828 unsigned NumComponentLists = ComponentLists.size();
829 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
830
831 // We need to allocate:
832 // NumVars x Expr* - we have an original list expression for each clause list
833 // entry.
834 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
835 // with each component list.
836 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
837 // number of lists for each unique declaration and the size of each component
838 // list.
839 // NumComponents x MappableComponent - the total of all the components in all
840 // the lists.
841 void *Mem = C.Allocate(
842 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
843 OMPClauseMappableExprCommon::MappableComponent>(
844 NumVars, NumUniqueDeclarations,
845 NumUniqueDeclarations + NumComponentLists, NumComponents));
846
847 OMPFromClause *Clause = new (Mem)
848 OMPFromClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
849 NumComponentLists, NumComponents);
850
851 Clause->setVarRefs(Vars);
852 Clause->setClauseInfo(Declarations, ComponentLists);
853 return Clause;
854}
855
856OMPFromClause *OMPFromClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
857 unsigned NumUniqueDeclarations,
858 unsigned NumComponentLists,
859 unsigned NumComponents) {
860 void *Mem = C.Allocate(
861 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
862 OMPClauseMappableExprCommon::MappableComponent>(
863 NumVars, NumUniqueDeclarations,
864 NumUniqueDeclarations + NumComponentLists, NumComponents));
865 return new (Mem) OMPFromClause(NumVars, NumUniqueDeclarations,
866 NumComponentLists, NumComponents);
867}
Carlo Bertolli2404b172016-07-13 15:37:16 +0000868
Samuel Antaocc10b852016-07-28 14:23:26 +0000869void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
870 assert(VL.size() == varlist_size() &&
871 "Number of private copies is not the same as the preallocated buffer");
872 std::copy(VL.begin(), VL.end(), varlist_end());
873}
874
875void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
876 assert(VL.size() == varlist_size() &&
877 "Number of inits is not the same as the preallocated buffer");
878 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
879}
880
881OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
882 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
883 SourceLocation EndLoc, ArrayRef<Expr *> Vars, ArrayRef<Expr *> PrivateVars,
884 ArrayRef<Expr *> Inits, ArrayRef<ValueDecl *> Declarations,
885 MappableExprComponentListsRef ComponentLists) {
886 unsigned NumVars = Vars.size();
887 unsigned NumUniqueDeclarations =
888 getUniqueDeclarationsTotalNumber(Declarations);
889 unsigned NumComponentLists = ComponentLists.size();
890 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
891
892 // We need to allocate:
893 // 3 x NumVars x Expr* - we have an original list expression for each clause
894 // list entry and an equal number of private copies and inits.
895 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
896 // with each component list.
897 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
898 // number of lists for each unique declaration and the size of each component
899 // list.
900 // NumComponents x MappableComponent - the total of all the components in all
901 // the lists.
902 void *Mem = C.Allocate(
903 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
904 OMPClauseMappableExprCommon::MappableComponent>(
905 3 * NumVars, NumUniqueDeclarations,
906 NumUniqueDeclarations + NumComponentLists, NumComponents));
907
908 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(
909 StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
910 NumComponentLists, NumComponents);
911
912 Clause->setVarRefs(Vars);
913 Clause->setPrivateCopies(PrivateVars);
914 Clause->setInits(Inits);
915 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli2404b172016-07-13 15:37:16 +0000916 return Clause;
917}
918
Samuel Antaocc10b852016-07-28 14:23:26 +0000919OMPUseDevicePtrClause *OMPUseDevicePtrClause::CreateEmpty(
920 const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations,
921 unsigned NumComponentLists, unsigned NumComponents) {
922 void *Mem = C.Allocate(
923 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
924 OMPClauseMappableExprCommon::MappableComponent>(
925 3 * NumVars, NumUniqueDeclarations,
926 NumUniqueDeclarations + NumComponentLists, NumComponents));
927 return new (Mem) OMPUseDevicePtrClause(NumVars, NumUniqueDeclarations,
928 NumComponentLists, NumComponents);
Carlo Bertolli2404b172016-07-13 15:37:16 +0000929}
Carlo Bertolli70594e92016-07-13 17:16:49 +0000930
Samuel Antao6890b092016-07-28 14:25:09 +0000931OMPIsDevicePtrClause *
932OMPIsDevicePtrClause::Create(const ASTContext &C, SourceLocation StartLoc,
933 SourceLocation LParenLoc, SourceLocation EndLoc,
934 ArrayRef<Expr *> Vars,
935 ArrayRef<ValueDecl *> Declarations,
936 MappableExprComponentListsRef ComponentLists) {
937 unsigned NumVars = Vars.size();
938 unsigned NumUniqueDeclarations =
939 getUniqueDeclarationsTotalNumber(Declarations);
940 unsigned NumComponentLists = ComponentLists.size();
941 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
942
943 // We need to allocate:
944 // NumVars x Expr* - we have an original list expression for each clause list
945 // entry.
946 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
947 // with each component list.
948 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
949 // number of lists for each unique declaration and the size of each component
950 // list.
951 // NumComponents x MappableComponent - the total of all the components in all
952 // the lists.
953 void *Mem = C.Allocate(
954 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
955 OMPClauseMappableExprCommon::MappableComponent>(
956 NumVars, NumUniqueDeclarations,
957 NumUniqueDeclarations + NumComponentLists, NumComponents));
958
959 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(
960 StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
961 NumComponentLists, NumComponents);
962
963 Clause->setVarRefs(Vars);
964 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli70594e92016-07-13 17:16:49 +0000965 return Clause;
966}
967
Samuel Antao6890b092016-07-28 14:25:09 +0000968OMPIsDevicePtrClause *OMPIsDevicePtrClause::CreateEmpty(
969 const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations,
970 unsigned NumComponentLists, unsigned NumComponents) {
971 void *Mem = C.Allocate(
972 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
973 OMPClauseMappableExprCommon::MappableComponent>(
974 NumVars, NumUniqueDeclarations,
975 NumUniqueDeclarations + NumComponentLists, NumComponents));
976 return new (Mem) OMPIsDevicePtrClause(NumVars, NumUniqueDeclarations,
977 NumComponentLists, NumComponents);
Carlo Bertolli70594e92016-07-13 17:16:49 +0000978}