blob: 1ef43f7694cf09bb8e36a83e6ca458e1e541c6e6 [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
32void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
33 assert(VL.size() == varlist_size() &&
34 "Number of private copies is not the same as the preallocated buffer");
35 std::copy(VL.begin(), VL.end(), varlist_end());
36}
37
38OMPPrivateClause *
39OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
40 SourceLocation LParenLoc, SourceLocation EndLoc,
41 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
42 // Allocate space for private variables and initializer expressions.
James Y Knight374fd202016-01-01 00:38:24 +000043 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +000044 OMPPrivateClause *Clause =
45 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
46 Clause->setVarRefs(VL);
47 Clause->setPrivateCopies(PrivateVL);
48 return Clause;
49}
50
51OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
52 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +000053 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +000054 return new (Mem) OMPPrivateClause(N);
55}
56
57void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
58 assert(VL.size() == varlist_size() &&
59 "Number of private copies is not the same as the preallocated buffer");
60 std::copy(VL.begin(), VL.end(), varlist_end());
61}
62
63void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
64 assert(VL.size() == varlist_size() &&
65 "Number of inits is not the same as the preallocated buffer");
66 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
67}
68
69OMPFirstprivateClause *
70OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
71 SourceLocation LParenLoc, SourceLocation EndLoc,
72 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
73 ArrayRef<Expr *> InitVL) {
James Y Knight374fd202016-01-01 00:38:24 +000074 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +000075 OMPFirstprivateClause *Clause =
76 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
77 Clause->setVarRefs(VL);
78 Clause->setPrivateCopies(PrivateVL);
79 Clause->setInits(InitVL);
80 return Clause;
81}
82
83OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
84 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +000085 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +000086 return new (Mem) OMPFirstprivateClause(N);
87}
88
89void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
90 assert(PrivateCopies.size() == varlist_size() &&
91 "Number of private copies is not the same as the preallocated buffer");
92 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
93}
94
95void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
96 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
97 "not the same as the "
98 "preallocated buffer");
99 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
100}
101
102void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
103 assert(DstExprs.size() == varlist_size() && "Number of destination "
104 "expressions is not the same as "
105 "the preallocated buffer");
106 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
107}
108
109void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
110 assert(AssignmentOps.size() == varlist_size() &&
111 "Number of assignment expressions is not the same as the preallocated "
112 "buffer");
113 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
114 getDestinationExprs().end());
115}
116
117OMPLastprivateClause *OMPLastprivateClause::Create(
118 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
119 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
120 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000121 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000122 OMPLastprivateClause *Clause =
123 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
124 Clause->setVarRefs(VL);
125 Clause->setSourceExprs(SrcExprs);
126 Clause->setDestinationExprs(DstExprs);
127 Clause->setAssignmentOps(AssignmentOps);
128 return Clause;
129}
130
131OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
132 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000133 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000134 return new (Mem) OMPLastprivateClause(N);
135}
136
137OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
138 SourceLocation StartLoc,
139 SourceLocation LParenLoc,
140 SourceLocation EndLoc,
141 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000142 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000143 OMPSharedClause *Clause =
144 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
145 Clause->setVarRefs(VL);
146 return Clause;
147}
148
149OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000150 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000151 return new (Mem) OMPSharedClause(N);
152}
153
154void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
155 assert(PL.size() == varlist_size() &&
156 "Number of privates is not the same as the preallocated buffer");
157 std::copy(PL.begin(), PL.end(), varlist_end());
158}
159
160void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
161 assert(IL.size() == varlist_size() &&
162 "Number of inits is not the same as the preallocated buffer");
163 std::copy(IL.begin(), IL.end(), getPrivates().end());
164}
165
166void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
167 assert(UL.size() == varlist_size() &&
168 "Number of updates is not the same as the preallocated buffer");
169 std::copy(UL.begin(), UL.end(), getInits().end());
170}
171
172void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
173 assert(FL.size() == varlist_size() &&
174 "Number of final updates is not the same as the preallocated buffer");
175 std::copy(FL.begin(), FL.end(), getUpdates().end());
176}
177
178OMPLinearClause *OMPLinearClause::Create(
179 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
180 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
181 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
182 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep) {
183 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
184 // (Step and CalcStep).
James Y Knight374fd202016-01-01 00:38:24 +0000185 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2));
James Y Knightb8bfd962015-10-02 13:41:04 +0000186 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
187 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
188 Clause->setVarRefs(VL);
189 Clause->setPrivates(PL);
190 Clause->setInits(IL);
191 // Fill update and final expressions with zeroes, they are provided later,
192 // after the directive construction.
193 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
194 nullptr);
195 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
196 nullptr);
197 Clause->setStep(Step);
198 Clause->setCalcStep(CalcStep);
199 return Clause;
200}
201
202OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
203 unsigned NumVars) {
204 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
205 // (Step and CalcStep).
James Y Knight374fd202016-01-01 00:38:24 +0000206 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2));
James Y Knightb8bfd962015-10-02 13:41:04 +0000207 return new (Mem) OMPLinearClause(NumVars);
208}
209
210OMPAlignedClause *
211OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
212 SourceLocation LParenLoc, SourceLocation ColonLoc,
213 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
James Y Knight374fd202016-01-01 00:38:24 +0000214 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000215 OMPAlignedClause *Clause = new (Mem)
216 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
217 Clause->setVarRefs(VL);
218 Clause->setAlignment(A);
219 return Clause;
220}
221
222OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
223 unsigned NumVars) {
James Y Knight374fd202016-01-01 00:38:24 +0000224 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000225 return new (Mem) OMPAlignedClause(NumVars);
226}
227
228void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
229 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
230 "not the same as the "
231 "preallocated buffer");
232 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
233}
234
235void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
236 assert(DstExprs.size() == varlist_size() && "Number of destination "
237 "expressions is not the same as "
238 "the preallocated buffer");
239 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
240}
241
242void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
243 assert(AssignmentOps.size() == varlist_size() &&
244 "Number of assignment expressions is not the same as the preallocated "
245 "buffer");
246 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
247 getDestinationExprs().end());
248}
249
250OMPCopyinClause *OMPCopyinClause::Create(
251 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
252 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
253 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000254 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000255 OMPCopyinClause *Clause =
256 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
257 Clause->setVarRefs(VL);
258 Clause->setSourceExprs(SrcExprs);
259 Clause->setDestinationExprs(DstExprs);
260 Clause->setAssignmentOps(AssignmentOps);
261 return Clause;
262}
263
264OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000265 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000266 return new (Mem) OMPCopyinClause(N);
267}
268
269void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
270 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
271 "not the same as the "
272 "preallocated buffer");
273 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
274}
275
276void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
277 assert(DstExprs.size() == varlist_size() && "Number of destination "
278 "expressions is not the same as "
279 "the preallocated buffer");
280 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
281}
282
283void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
284 assert(AssignmentOps.size() == varlist_size() &&
285 "Number of assignment expressions is not the same as the preallocated "
286 "buffer");
287 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
288 getDestinationExprs().end());
289}
290
291OMPCopyprivateClause *OMPCopyprivateClause::Create(
292 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
293 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
294 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000295 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000296 OMPCopyprivateClause *Clause =
297 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
298 Clause->setVarRefs(VL);
299 Clause->setSourceExprs(SrcExprs);
300 Clause->setDestinationExprs(DstExprs);
301 Clause->setAssignmentOps(AssignmentOps);
302 return Clause;
303}
304
305OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
306 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000307 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000308 return new (Mem) OMPCopyprivateClause(N);
309}
310
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000311void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
312 assert(Privates.size() == varlist_size() &&
313 "Number of private copies is not the same as the preallocated buffer");
314 std::copy(Privates.begin(), Privates.end(), varlist_end());
315}
316
James Y Knightb8bfd962015-10-02 13:41:04 +0000317void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
318 assert(
319 LHSExprs.size() == varlist_size() &&
320 "Number of LHS expressions is not the same as the preallocated buffer");
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000321 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
James Y Knightb8bfd962015-10-02 13:41:04 +0000322}
323
324void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
325 assert(
326 RHSExprs.size() == varlist_size() &&
327 "Number of RHS expressions is not the same as the preallocated buffer");
328 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
329}
330
331void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
332 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
333 "expressions is not the same "
334 "as the preallocated buffer");
335 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
336}
337
338OMPReductionClause *OMPReductionClause::Create(
339 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
340 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
341 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000342 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
343 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000344 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000345 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
346 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
347 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000348 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000349 Clause->setLHSExprs(LHSExprs);
350 Clause->setRHSExprs(RHSExprs);
351 Clause->setReductionOps(ReductionOps);
352 return Clause;
353}
354
355OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
356 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000357 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000358 return new (Mem) OMPReductionClause(N);
359}
360
361OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
362 SourceLocation StartLoc,
363 SourceLocation LParenLoc,
364 SourceLocation EndLoc,
365 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000366 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000367 OMPFlushClause *Clause =
368 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
369 Clause->setVarRefs(VL);
370 return Clause;
371}
372
373OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000374 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000375 return new (Mem) OMPFlushClause(N);
376}
377
378OMPDependClause *
379OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
380 SourceLocation LParenLoc, SourceLocation EndLoc,
381 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
382 SourceLocation ColonLoc, ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000383 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000384 OMPDependClause *Clause =
385 new (Mem) OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size());
386 Clause->setVarRefs(VL);
387 Clause->setDependencyKind(DepKind);
388 Clause->setDependencyLoc(DepLoc);
389 Clause->setColonLoc(ColonLoc);
390 return Clause;
391}
392
393OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000394 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000395 return new (Mem) OMPDependClause(N);
396}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000397
398OMPMapClause *OMPMapClause::Create(const ASTContext &C, SourceLocation StartLoc,
399 SourceLocation LParenLoc,
400 SourceLocation EndLoc, ArrayRef<Expr *> VL,
401 OpenMPMapClauseKind TypeModifier,
402 OpenMPMapClauseKind Type,
403 SourceLocation TypeLoc) {
James Y Knight374fd202016-01-01 00:38:24 +0000404 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
Kelvin Li0bff7af2015-11-23 05:32:03 +0000405 OMPMapClause *Clause = new (Mem) OMPMapClause(
406 TypeModifier, Type, TypeLoc, StartLoc, LParenLoc, EndLoc, VL.size());
407 Clause->setVarRefs(VL);
408 Clause->setMapTypeModifier(TypeModifier);
409 Clause->setMapType(Type);
410 Clause->setMapLoc(TypeLoc);
411 return Clause;
412}
413
414OMPMapClause *OMPMapClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000415 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
Kelvin Li0bff7af2015-11-23 05:32:03 +0000416 return new (Mem) OMPMapClause(N);
417}