blob: 3c0952be55645e15883bb8ce9dce43a54216a527 [file] [log] [blame]
James Y Knightb8bfd962015-10-02 13:41:04 +00001//===--- OpenMPClause.cpp - Classes for OpenMP clauses --------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the subclesses of Stmt class declared in OpenMPClause.h
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/OpenMPClause.h"
15
16#include "clang/AST/ASTContext.h"
17
18using namespace clang;
19
20OMPClause::child_range OMPClause::children() {
21 switch (getClauseKind()) {
22 default:
23 break;
24#define OPENMP_CLAUSE(Name, Class) \
25 case OMPC_##Name: \
26 return static_cast<Class *>(this)->children();
27#include "clang/Basic/OpenMPKinds.def"
28 }
29 llvm_unreachable("unknown OMPClause");
30}
31
Alexey Bataev3392d762016-02-16 11:18:12 +000032OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
33 auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
34 return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr;
35}
36
37const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
38 switch (C->getClauseKind()) {
39 case OMPC_schedule:
40 return static_cast<const OMPScheduleClause *>(C);
41 case OMPC_dist_schedule:
42 return static_cast<const OMPDistScheduleClause *>(C);
Alexey Bataev417089f2016-02-17 13:19:37 +000043 case OMPC_firstprivate:
44 return static_cast<const OMPFirstprivateClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +000045 case OMPC_lastprivate:
46 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +000047 case OMPC_reduction:
48 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev3392d762016-02-16 11:18:12 +000049 case OMPC_default:
50 case OMPC_proc_bind:
51 case OMPC_if:
52 case OMPC_final:
53 case OMPC_num_threads:
54 case OMPC_safelen:
55 case OMPC_simdlen:
56 case OMPC_collapse:
57 case OMPC_private:
Alexey Bataev005248a2016-02-25 05:25:57 +000058 case OMPC_shared:
Alexey Bataev005248a2016-02-25 05:25:57 +000059 case OMPC_linear:
60 case OMPC_aligned:
61 case OMPC_copyin:
62 case OMPC_copyprivate:
63 case OMPC_ordered:
64 case OMPC_nowait:
65 case OMPC_untied:
66 case OMPC_mergeable:
67 case OMPC_threadprivate:
68 case OMPC_flush:
69 case OMPC_read:
70 case OMPC_write:
71 case OMPC_update:
72 case OMPC_capture:
73 case OMPC_seq_cst:
74 case OMPC_depend:
75 case OMPC_device:
76 case OMPC_threads:
77 case OMPC_simd:
78 case OMPC_map:
79 case OMPC_num_teams:
80 case OMPC_thread_limit:
81 case OMPC_priority:
82 case OMPC_grainsize:
83 case OMPC_nogroup:
84 case OMPC_num_tasks:
85 case OMPC_hint:
86 case OMPC_defaultmap:
87 case OMPC_unknown:
88 break;
89 }
90
91 return nullptr;
92}
93
94OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
95 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
96 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
97}
98
99const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
100 switch (C->getClauseKind()) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000101 case OMPC_lastprivate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000102 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000103 case OMPC_reduction:
104 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000105 case OMPC_schedule:
106 case OMPC_dist_schedule:
107 case OMPC_firstprivate:
108 case OMPC_default:
109 case OMPC_proc_bind:
110 case OMPC_if:
111 case OMPC_final:
112 case OMPC_num_threads:
113 case OMPC_safelen:
114 case OMPC_simdlen:
115 case OMPC_collapse:
116 case OMPC_private:
Alexey Bataev3392d762016-02-16 11:18:12 +0000117 case OMPC_shared:
Alexey Bataev3392d762016-02-16 11:18:12 +0000118 case OMPC_linear:
119 case OMPC_aligned:
120 case OMPC_copyin:
121 case OMPC_copyprivate:
122 case OMPC_ordered:
123 case OMPC_nowait:
124 case OMPC_untied:
125 case OMPC_mergeable:
126 case OMPC_threadprivate:
127 case OMPC_flush:
128 case OMPC_read:
129 case OMPC_write:
130 case OMPC_update:
131 case OMPC_capture:
132 case OMPC_seq_cst:
133 case OMPC_depend:
134 case OMPC_device:
135 case OMPC_threads:
136 case OMPC_simd:
137 case OMPC_map:
138 case OMPC_num_teams:
139 case OMPC_thread_limit:
140 case OMPC_priority:
141 case OMPC_grainsize:
142 case OMPC_nogroup:
143 case OMPC_num_tasks:
144 case OMPC_hint:
145 case OMPC_defaultmap:
146 case OMPC_unknown:
147 break;
148 }
149
150 return nullptr;
151}
152
James Y Knightb8bfd962015-10-02 13:41:04 +0000153void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
154 assert(VL.size() == varlist_size() &&
155 "Number of private copies is not the same as the preallocated buffer");
156 std::copy(VL.begin(), VL.end(), varlist_end());
157}
158
159OMPPrivateClause *
160OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
161 SourceLocation LParenLoc, SourceLocation EndLoc,
162 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
163 // Allocate space for private variables and initializer expressions.
James Y Knight374fd202016-01-01 00:38:24 +0000164 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000165 OMPPrivateClause *Clause =
166 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
167 Clause->setVarRefs(VL);
168 Clause->setPrivateCopies(PrivateVL);
169 return Clause;
170}
171
172OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
173 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000174 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000175 return new (Mem) OMPPrivateClause(N);
176}
177
178void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
179 assert(VL.size() == varlist_size() &&
180 "Number of private copies is not the same as the preallocated buffer");
181 std::copy(VL.begin(), VL.end(), varlist_end());
182}
183
184void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
185 assert(VL.size() == varlist_size() &&
186 "Number of inits is not the same as the preallocated buffer");
187 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
188}
189
190OMPFirstprivateClause *
191OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
192 SourceLocation LParenLoc, SourceLocation EndLoc,
193 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
Alexey Bataev417089f2016-02-17 13:19:37 +0000194 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
James Y Knight374fd202016-01-01 00:38:24 +0000195 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000196 OMPFirstprivateClause *Clause =
197 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
198 Clause->setVarRefs(VL);
199 Clause->setPrivateCopies(PrivateVL);
200 Clause->setInits(InitVL);
Alexey Bataev417089f2016-02-17 13:19:37 +0000201 Clause->setPreInitStmt(PreInit);
James Y Knightb8bfd962015-10-02 13:41:04 +0000202 return Clause;
203}
204
205OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
206 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000207 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000208 return new (Mem) OMPFirstprivateClause(N);
209}
210
211void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
212 assert(PrivateCopies.size() == varlist_size() &&
213 "Number of private copies is not the same as the preallocated buffer");
214 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
215}
216
217void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
218 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
219 "not the same as the "
220 "preallocated buffer");
221 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
222}
223
224void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
225 assert(DstExprs.size() == varlist_size() && "Number of destination "
226 "expressions is not the same as "
227 "the preallocated buffer");
228 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
229}
230
231void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
232 assert(AssignmentOps.size() == varlist_size() &&
233 "Number of assignment expressions is not the same as the preallocated "
234 "buffer");
235 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
236 getDestinationExprs().end());
237}
238
239OMPLastprivateClause *OMPLastprivateClause::Create(
240 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
241 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
Alexey Bataev005248a2016-02-25 05:25:57 +0000242 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit,
243 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000244 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000245 OMPLastprivateClause *Clause =
246 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
247 Clause->setVarRefs(VL);
248 Clause->setSourceExprs(SrcExprs);
249 Clause->setDestinationExprs(DstExprs);
250 Clause->setAssignmentOps(AssignmentOps);
Alexey Bataev005248a2016-02-25 05:25:57 +0000251 Clause->setPreInitStmt(PreInit);
252 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000253 return Clause;
254}
255
256OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
257 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000258 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000259 return new (Mem) OMPLastprivateClause(N);
260}
261
262OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
263 SourceLocation StartLoc,
264 SourceLocation LParenLoc,
265 SourceLocation EndLoc,
266 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000267 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000268 OMPSharedClause *Clause =
269 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
270 Clause->setVarRefs(VL);
271 return Clause;
272}
273
274OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000275 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000276 return new (Mem) OMPSharedClause(N);
277}
278
279void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
280 assert(PL.size() == varlist_size() &&
281 "Number of privates is not the same as the preallocated buffer");
282 std::copy(PL.begin(), PL.end(), varlist_end());
283}
284
285void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
286 assert(IL.size() == varlist_size() &&
287 "Number of inits is not the same as the preallocated buffer");
288 std::copy(IL.begin(), IL.end(), getPrivates().end());
289}
290
291void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
292 assert(UL.size() == varlist_size() &&
293 "Number of updates is not the same as the preallocated buffer");
294 std::copy(UL.begin(), UL.end(), getInits().end());
295}
296
297void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
298 assert(FL.size() == varlist_size() &&
299 "Number of final updates is not the same as the preallocated buffer");
300 std::copy(FL.begin(), FL.end(), getUpdates().end());
301}
302
303OMPLinearClause *OMPLinearClause::Create(
304 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
305 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
306 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
307 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep) {
308 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
309 // (Step and CalcStep).
James Y Knight374fd202016-01-01 00:38:24 +0000310 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2));
James Y Knightb8bfd962015-10-02 13:41:04 +0000311 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
312 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
313 Clause->setVarRefs(VL);
314 Clause->setPrivates(PL);
315 Clause->setInits(IL);
316 // Fill update and final expressions with zeroes, they are provided later,
317 // after the directive construction.
318 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
319 nullptr);
320 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
321 nullptr);
322 Clause->setStep(Step);
323 Clause->setCalcStep(CalcStep);
324 return Clause;
325}
326
327OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
328 unsigned NumVars) {
329 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
330 // (Step and CalcStep).
James Y Knight374fd202016-01-01 00:38:24 +0000331 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2));
James Y Knightb8bfd962015-10-02 13:41:04 +0000332 return new (Mem) OMPLinearClause(NumVars);
333}
334
335OMPAlignedClause *
336OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
337 SourceLocation LParenLoc, SourceLocation ColonLoc,
338 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
James Y Knight374fd202016-01-01 00:38:24 +0000339 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000340 OMPAlignedClause *Clause = new (Mem)
341 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
342 Clause->setVarRefs(VL);
343 Clause->setAlignment(A);
344 return Clause;
345}
346
347OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
348 unsigned NumVars) {
James Y Knight374fd202016-01-01 00:38:24 +0000349 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000350 return new (Mem) OMPAlignedClause(NumVars);
351}
352
353void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
354 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
355 "not the same as the "
356 "preallocated buffer");
357 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
358}
359
360void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
361 assert(DstExprs.size() == varlist_size() && "Number of destination "
362 "expressions is not the same as "
363 "the preallocated buffer");
364 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
365}
366
367void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
368 assert(AssignmentOps.size() == varlist_size() &&
369 "Number of assignment expressions is not the same as the preallocated "
370 "buffer");
371 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
372 getDestinationExprs().end());
373}
374
375OMPCopyinClause *OMPCopyinClause::Create(
376 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
377 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
378 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000379 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000380 OMPCopyinClause *Clause =
381 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
382 Clause->setVarRefs(VL);
383 Clause->setSourceExprs(SrcExprs);
384 Clause->setDestinationExprs(DstExprs);
385 Clause->setAssignmentOps(AssignmentOps);
386 return Clause;
387}
388
389OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000390 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000391 return new (Mem) OMPCopyinClause(N);
392}
393
394void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
395 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
396 "not the same as the "
397 "preallocated buffer");
398 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
399}
400
401void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
402 assert(DstExprs.size() == varlist_size() && "Number of destination "
403 "expressions is not the same as "
404 "the preallocated buffer");
405 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
406}
407
408void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
409 assert(AssignmentOps.size() == varlist_size() &&
410 "Number of assignment expressions is not the same as the preallocated "
411 "buffer");
412 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
413 getDestinationExprs().end());
414}
415
416OMPCopyprivateClause *OMPCopyprivateClause::Create(
417 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
418 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
419 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000420 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000421 OMPCopyprivateClause *Clause =
422 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
423 Clause->setVarRefs(VL);
424 Clause->setSourceExprs(SrcExprs);
425 Clause->setDestinationExprs(DstExprs);
426 Clause->setAssignmentOps(AssignmentOps);
427 return Clause;
428}
429
430OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
431 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000432 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000433 return new (Mem) OMPCopyprivateClause(N);
434}
435
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000436void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
437 assert(Privates.size() == varlist_size() &&
438 "Number of private copies is not the same as the preallocated buffer");
439 std::copy(Privates.begin(), Privates.end(), varlist_end());
440}
441
James Y Knightb8bfd962015-10-02 13:41:04 +0000442void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
443 assert(
444 LHSExprs.size() == varlist_size() &&
445 "Number of LHS expressions is not the same as the preallocated buffer");
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000446 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
James Y Knightb8bfd962015-10-02 13:41:04 +0000447}
448
449void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
450 assert(
451 RHSExprs.size() == varlist_size() &&
452 "Number of RHS expressions is not the same as the preallocated buffer");
453 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
454}
455
456void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
457 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
458 "expressions is not the same "
459 "as the preallocated buffer");
460 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
461}
462
463OMPReductionClause *OMPReductionClause::Create(
464 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
465 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
466 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000467 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev61205072016-03-02 04:57:40 +0000468 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
469 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000470 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000471 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
472 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
473 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000474 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000475 Clause->setLHSExprs(LHSExprs);
476 Clause->setRHSExprs(RHSExprs);
477 Clause->setReductionOps(ReductionOps);
Alexey Bataev61205072016-03-02 04:57:40 +0000478 Clause->setPreInitStmt(PreInit);
479 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000480 return Clause;
481}
482
483OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
484 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000485 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000486 return new (Mem) OMPReductionClause(N);
487}
488
489OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
490 SourceLocation StartLoc,
491 SourceLocation LParenLoc,
492 SourceLocation EndLoc,
493 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000494 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000495 OMPFlushClause *Clause =
496 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
497 Clause->setVarRefs(VL);
498 return Clause;
499}
500
501OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000502 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000503 return new (Mem) OMPFlushClause(N);
504}
505
506OMPDependClause *
507OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
508 SourceLocation LParenLoc, SourceLocation EndLoc,
509 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
510 SourceLocation ColonLoc, ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000511 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000512 OMPDependClause *Clause =
513 new (Mem) OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size());
514 Clause->setVarRefs(VL);
515 Clause->setDependencyKind(DepKind);
516 Clause->setDependencyLoc(DepLoc);
517 Clause->setColonLoc(ColonLoc);
518 return Clause;
519}
520
521OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000522 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000523 return new (Mem) OMPDependClause(N);
524}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000525
526OMPMapClause *OMPMapClause::Create(const ASTContext &C, SourceLocation StartLoc,
527 SourceLocation LParenLoc,
528 SourceLocation EndLoc, ArrayRef<Expr *> VL,
529 OpenMPMapClauseKind TypeModifier,
530 OpenMPMapClauseKind Type,
Samuel Antao23abd722016-01-19 20:40:49 +0000531 bool TypeIsImplicit,
Kelvin Li0bff7af2015-11-23 05:32:03 +0000532 SourceLocation TypeLoc) {
James Y Knight374fd202016-01-01 00:38:24 +0000533 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
Samuel Antao23abd722016-01-19 20:40:49 +0000534 OMPMapClause *Clause =
535 new (Mem) OMPMapClause(TypeModifier, Type, TypeIsImplicit, TypeLoc,
536 StartLoc, LParenLoc, EndLoc, VL.size());
Kelvin Li0bff7af2015-11-23 05:32:03 +0000537 Clause->setVarRefs(VL);
538 Clause->setMapTypeModifier(TypeModifier);
539 Clause->setMapType(Type);
540 Clause->setMapLoc(TypeLoc);
541 return Clause;
542}
543
544OMPMapClause *OMPMapClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000545 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
Kelvin Li0bff7af2015-11-23 05:32:03 +0000546 return new (Mem) OMPMapClause(N);
547}