blob: 9d8a7ebc3023ed708a801ecb5d424920204b0243 [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//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
James Y Knightb8bfd962015-10-02 13:41:04 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the subclesses of Stmt class declared in OpenMPClause.h
10//
11//===----------------------------------------------------------------------===//
12
13#include "clang/AST/OpenMPClause.h"
James Y Knightb8bfd962015-10-02 13:41:04 +000014#include "clang/AST/ASTContext.h"
Eugene Zelenkod1b2d222017-11-29 23:27:36 +000015#include "clang/AST/Decl.h"
Patrick Lyster074c3ae22018-10-18 14:28:23 +000016#include "clang/AST/DeclOpenMP.h"
Eugene Zelenkod1b2d222017-11-29 23:27:36 +000017#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 Bataevc2c21ef2019-07-11 14:54:17 +000038OMPClause::child_range OMPClause::used_children() {
39 switch (getClauseKind()) {
40#define OPENMP_CLAUSE(Name, Class) \
41 case OMPC_##Name: \
42 return static_cast<Class *>(this)->used_children();
43#include "clang/Basic/OpenMPKinds.def"
44 case OMPC_threadprivate:
45 case OMPC_uniform:
46 case OMPC_unknown:
47 break;
48 }
49 llvm_unreachable("unknown OMPClause");
50}
51
Alexey Bataev3392d762016-02-16 11:18:12 +000052OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
53 auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
54 return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr;
55}
56
57const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
58 switch (C->getClauseKind()) {
59 case OMPC_schedule:
60 return static_cast<const OMPScheduleClause *>(C);
61 case OMPC_dist_schedule:
62 return static_cast<const OMPDistScheduleClause *>(C);
Alexey Bataev417089f2016-02-17 13:19:37 +000063 case OMPC_firstprivate:
64 return static_cast<const OMPFirstprivateClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +000065 case OMPC_lastprivate:
66 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +000067 case OMPC_reduction:
68 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +000069 case OMPC_task_reduction:
70 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +000071 case OMPC_in_reduction:
72 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +000073 case OMPC_linear:
74 return static_cast<const OMPLinearClause *>(C);
Arpith Chacko Jacobfe4890a2017-01-18 20:40:48 +000075 case OMPC_if:
76 return static_cast<const OMPIfClause *>(C);
Arpith Chacko Jacob33c849a2017-01-25 00:57:16 +000077 case OMPC_num_threads:
78 return static_cast<const OMPNumThreadsClause *>(C);
Arpith Chacko Jacobbc126342017-01-25 11:28:18 +000079 case OMPC_num_teams:
80 return static_cast<const OMPNumTeamsClause *>(C);
Arpith Chacko Jacob7ecc0b72017-01-25 11:44:35 +000081 case OMPC_thread_limit:
82 return static_cast<const OMPThreadLimitClause *>(C);
Alexey Bataev931e19b2017-10-02 16:32:39 +000083 case OMPC_device:
84 return static_cast<const OMPDeviceClause *>(C);
Alexey Bataev3392d762016-02-16 11:18:12 +000085 case OMPC_default:
86 case OMPC_proc_bind:
Alexey Bataev3392d762016-02-16 11:18:12 +000087 case OMPC_final:
Alexey Bataev3392d762016-02-16 11:18:12 +000088 case OMPC_safelen:
89 case OMPC_simdlen:
Alexey Bataev9cc10fc2019-03-12 18:52:33 +000090 case OMPC_allocator:
Alexey Bataeve04483e2019-03-27 14:14:31 +000091 case OMPC_allocate:
Alexey Bataev3392d762016-02-16 11:18:12 +000092 case OMPC_collapse:
93 case OMPC_private:
Alexey Bataev005248a2016-02-25 05:25:57 +000094 case OMPC_shared:
Alexey Bataev005248a2016-02-25 05:25:57 +000095 case OMPC_aligned:
96 case OMPC_copyin:
97 case OMPC_copyprivate:
98 case OMPC_ordered:
99 case OMPC_nowait:
100 case OMPC_untied:
101 case OMPC_mergeable:
102 case OMPC_threadprivate:
103 case OMPC_flush:
104 case OMPC_read:
105 case OMPC_write:
106 case OMPC_update:
107 case OMPC_capture:
108 case OMPC_seq_cst:
109 case OMPC_depend:
Alexey Bataev005248a2016-02-25 05:25:57 +0000110 case OMPC_threads:
111 case OMPC_simd:
112 case OMPC_map:
Alexey Bataev005248a2016-02-25 05:25:57 +0000113 case OMPC_priority:
114 case OMPC_grainsize:
115 case OMPC_nogroup:
116 case OMPC_num_tasks:
117 case OMPC_hint:
118 case OMPC_defaultmap:
119 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000120 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000121 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000122 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000123 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000124 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000125 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000126 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000127 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000128 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000129 case OMPC_atomic_default_mem_order:
Alexey Bataev005248a2016-02-25 05:25:57 +0000130 break;
131 }
132
133 return nullptr;
134}
135
136OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
137 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
138 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
139}
140
141const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
142 switch (C->getClauseKind()) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000143 case OMPC_lastprivate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000144 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000145 case OMPC_reduction:
146 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +0000147 case OMPC_task_reduction:
148 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000149 case OMPC_in_reduction:
150 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000151 case OMPC_linear:
152 return static_cast<const OMPLinearClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000153 case OMPC_schedule:
154 case OMPC_dist_schedule:
155 case OMPC_firstprivate:
156 case OMPC_default:
157 case OMPC_proc_bind:
158 case OMPC_if:
159 case OMPC_final:
160 case OMPC_num_threads:
161 case OMPC_safelen:
162 case OMPC_simdlen:
Alexey Bataev9cc10fc2019-03-12 18:52:33 +0000163 case OMPC_allocator:
Alexey Bataeve04483e2019-03-27 14:14:31 +0000164 case OMPC_allocate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000165 case OMPC_collapse:
166 case OMPC_private:
Alexey Bataev3392d762016-02-16 11:18:12 +0000167 case OMPC_shared:
Alexey Bataev3392d762016-02-16 11:18:12 +0000168 case OMPC_aligned:
169 case OMPC_copyin:
170 case OMPC_copyprivate:
171 case OMPC_ordered:
172 case OMPC_nowait:
173 case OMPC_untied:
174 case OMPC_mergeable:
175 case OMPC_threadprivate:
176 case OMPC_flush:
177 case OMPC_read:
178 case OMPC_write:
179 case OMPC_update:
180 case OMPC_capture:
181 case OMPC_seq_cst:
182 case OMPC_depend:
183 case OMPC_device:
184 case OMPC_threads:
185 case OMPC_simd:
186 case OMPC_map:
187 case OMPC_num_teams:
188 case OMPC_thread_limit:
189 case OMPC_priority:
190 case OMPC_grainsize:
191 case OMPC_nogroup:
192 case OMPC_num_tasks:
193 case OMPC_hint:
194 case OMPC_defaultmap:
195 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000196 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000197 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000198 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000199 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000200 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000201 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000202 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000203 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000204 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000205 case OMPC_atomic_default_mem_order:
Alexey Bataev3392d762016-02-16 11:18:12 +0000206 break;
207 }
208
209 return nullptr;
210}
211
Alexey Bataev655cb4a2019-07-16 14:51:46 +0000212/// Gets the address of the original, non-captured, expression used in the
213/// clause as the preinitializer.
214static Stmt **getAddrOfExprAsWritten(Stmt *S) {
215 if (!S)
216 return nullptr;
217 if (auto *DS = dyn_cast<DeclStmt>(S)) {
218 assert(DS->isSingleDecl() && "Only single expression must be captured.");
219 if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
220 return OED->getInitAddress();
221 }
222 return nullptr;
223}
224
225OMPClause::child_range OMPIfClause::used_children() {
226 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
227 return child_range(C, C + 1);
228 return child_range(&Condition, &Condition + 1);
229}
230
Alexey Bataevf138fda2018-08-13 19:04:24 +0000231OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
232 unsigned NumLoops,
233 SourceLocation StartLoc,
234 SourceLocation LParenLoc,
235 SourceLocation EndLoc) {
236 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
237 auto *Clause =
238 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
239 for (unsigned I = 0; I < NumLoops; ++I) {
240 Clause->setLoopNumIterations(I, nullptr);
241 Clause->setLoopCounter(I, nullptr);
242 }
243 return Clause;
244}
245
246OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
247 unsigned NumLoops) {
248 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
249 auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
250 for (unsigned I = 0; I < NumLoops; ++I) {
251 Clause->setLoopNumIterations(I, nullptr);
252 Clause->setLoopCounter(I, nullptr);
253 }
254 return Clause;
255}
256
257void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
258 Expr *NumIterations) {
259 assert(NumLoop < NumberOfLoops && "out of loops number.");
260 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
261}
262
263ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
264 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
265}
266
267void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
268 assert(NumLoop < NumberOfLoops && "out of loops number.");
269 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
270}
271
Mike Rice0ed46662018-09-20 17:19:41 +0000272Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000273 assert(NumLoop < NumberOfLoops && "out of loops number.");
274 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
275}
276
Mike Rice0ed46662018-09-20 17:19:41 +0000277const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000278 assert(NumLoop < NumberOfLoops && "out of loops number.");
279 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
280}
281
James Y Knightb8bfd962015-10-02 13:41:04 +0000282void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
283 assert(VL.size() == varlist_size() &&
284 "Number of private copies is not the same as the preallocated buffer");
285 std::copy(VL.begin(), VL.end(), varlist_end());
286}
287
288OMPPrivateClause *
289OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
290 SourceLocation LParenLoc, SourceLocation EndLoc,
291 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
292 // Allocate space for private variables and initializer expressions.
James Y Knight374fd202016-01-01 00:38:24 +0000293 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000294 OMPPrivateClause *Clause =
295 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
296 Clause->setVarRefs(VL);
297 Clause->setPrivateCopies(PrivateVL);
298 return Clause;
299}
300
301OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
302 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000303 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000304 return new (Mem) OMPPrivateClause(N);
305}
306
307void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
308 assert(VL.size() == varlist_size() &&
309 "Number of private copies is not the same as the preallocated buffer");
310 std::copy(VL.begin(), VL.end(), varlist_end());
311}
312
313void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
314 assert(VL.size() == varlist_size() &&
315 "Number of inits is not the same as the preallocated buffer");
316 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
317}
318
319OMPFirstprivateClause *
320OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
321 SourceLocation LParenLoc, SourceLocation EndLoc,
322 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
Alexey Bataev417089f2016-02-17 13:19:37 +0000323 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
James Y Knight374fd202016-01-01 00:38:24 +0000324 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000325 OMPFirstprivateClause *Clause =
326 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
327 Clause->setVarRefs(VL);
328 Clause->setPrivateCopies(PrivateVL);
329 Clause->setInits(InitVL);
Alexey Bataev417089f2016-02-17 13:19:37 +0000330 Clause->setPreInitStmt(PreInit);
James Y Knightb8bfd962015-10-02 13:41:04 +0000331 return Clause;
332}
333
334OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
335 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000336 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000337 return new (Mem) OMPFirstprivateClause(N);
338}
339
340void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
341 assert(PrivateCopies.size() == varlist_size() &&
342 "Number of private copies is not the same as the preallocated buffer");
343 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
344}
345
346void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
347 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
348 "not the same as the "
349 "preallocated buffer");
350 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
351}
352
353void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
354 assert(DstExprs.size() == varlist_size() && "Number of destination "
355 "expressions is not the same as "
356 "the preallocated buffer");
357 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
358}
359
360void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
361 assert(AssignmentOps.size() == varlist_size() &&
362 "Number of assignment expressions is not the same as the preallocated "
363 "buffer");
364 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
365 getDestinationExprs().end());
366}
367
368OMPLastprivateClause *OMPLastprivateClause::Create(
369 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
370 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
Alexey Bataev005248a2016-02-25 05:25:57 +0000371 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit,
372 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000373 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000374 OMPLastprivateClause *Clause =
375 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
376 Clause->setVarRefs(VL);
377 Clause->setSourceExprs(SrcExprs);
378 Clause->setDestinationExprs(DstExprs);
379 Clause->setAssignmentOps(AssignmentOps);
Alexey Bataev005248a2016-02-25 05:25:57 +0000380 Clause->setPreInitStmt(PreInit);
381 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000382 return Clause;
383}
384
385OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
386 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000387 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000388 return new (Mem) OMPLastprivateClause(N);
389}
390
391OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
392 SourceLocation StartLoc,
393 SourceLocation LParenLoc,
394 SourceLocation EndLoc,
395 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000396 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000397 OMPSharedClause *Clause =
398 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
399 Clause->setVarRefs(VL);
400 return Clause;
401}
402
403OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000404 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000405 return new (Mem) OMPSharedClause(N);
406}
407
408void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
409 assert(PL.size() == varlist_size() &&
410 "Number of privates is not the same as the preallocated buffer");
411 std::copy(PL.begin(), PL.end(), varlist_end());
412}
413
414void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
415 assert(IL.size() == varlist_size() &&
416 "Number of inits is not the same as the preallocated buffer");
417 std::copy(IL.begin(), IL.end(), getPrivates().end());
418}
419
420void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
421 assert(UL.size() == varlist_size() &&
422 "Number of updates is not the same as the preallocated buffer");
423 std::copy(UL.begin(), UL.end(), getInits().end());
424}
425
426void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
427 assert(FL.size() == varlist_size() &&
428 "Number of final updates is not the same as the preallocated buffer");
429 std::copy(FL.begin(), FL.end(), getUpdates().end());
430}
431
432OMPLinearClause *OMPLinearClause::Create(
433 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
434 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
435 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
Alexey Bataev78849fb2016-03-09 09:49:00 +0000436 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
437 Stmt *PreInit, Expr *PostUpdate) {
James Y Knightb8bfd962015-10-02 13:41:04 +0000438 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
439 // (Step and CalcStep).
James Y Knight374fd202016-01-01 00:38:24 +0000440 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2));
James Y Knightb8bfd962015-10-02 13:41:04 +0000441 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
442 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
443 Clause->setVarRefs(VL);
444 Clause->setPrivates(PL);
445 Clause->setInits(IL);
446 // Fill update and final expressions with zeroes, they are provided later,
447 // after the directive construction.
448 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
449 nullptr);
450 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
451 nullptr);
452 Clause->setStep(Step);
453 Clause->setCalcStep(CalcStep);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000454 Clause->setPreInitStmt(PreInit);
455 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000456 return Clause;
457}
458
459OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
460 unsigned NumVars) {
461 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
462 // (Step and CalcStep).
James Y Knight374fd202016-01-01 00:38:24 +0000463 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2));
James Y Knightb8bfd962015-10-02 13:41:04 +0000464 return new (Mem) OMPLinearClause(NumVars);
465}
466
467OMPAlignedClause *
468OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
469 SourceLocation LParenLoc, SourceLocation ColonLoc,
470 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
James Y Knight374fd202016-01-01 00:38:24 +0000471 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000472 OMPAlignedClause *Clause = new (Mem)
473 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
474 Clause->setVarRefs(VL);
475 Clause->setAlignment(A);
476 return Clause;
477}
478
479OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
480 unsigned NumVars) {
James Y Knight374fd202016-01-01 00:38:24 +0000481 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000482 return new (Mem) OMPAlignedClause(NumVars);
483}
484
485void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
486 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
487 "not the same as the "
488 "preallocated buffer");
489 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
490}
491
492void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
493 assert(DstExprs.size() == varlist_size() && "Number of destination "
494 "expressions is not the same as "
495 "the preallocated buffer");
496 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
497}
498
499void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
500 assert(AssignmentOps.size() == varlist_size() &&
501 "Number of assignment expressions is not the same as the preallocated "
502 "buffer");
503 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
504 getDestinationExprs().end());
505}
506
507OMPCopyinClause *OMPCopyinClause::Create(
508 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
509 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
510 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000511 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000512 OMPCopyinClause *Clause =
513 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
514 Clause->setVarRefs(VL);
515 Clause->setSourceExprs(SrcExprs);
516 Clause->setDestinationExprs(DstExprs);
517 Clause->setAssignmentOps(AssignmentOps);
518 return Clause;
519}
520
521OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000522 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000523 return new (Mem) OMPCopyinClause(N);
524}
525
526void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
527 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
528 "not the same as the "
529 "preallocated buffer");
530 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
531}
532
533void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
534 assert(DstExprs.size() == varlist_size() && "Number of destination "
535 "expressions is not the same as "
536 "the preallocated buffer");
537 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
538}
539
540void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
541 assert(AssignmentOps.size() == varlist_size() &&
542 "Number of assignment expressions is not the same as the preallocated "
543 "buffer");
544 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
545 getDestinationExprs().end());
546}
547
548OMPCopyprivateClause *OMPCopyprivateClause::Create(
549 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
550 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
551 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000552 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000553 OMPCopyprivateClause *Clause =
554 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
555 Clause->setVarRefs(VL);
556 Clause->setSourceExprs(SrcExprs);
557 Clause->setDestinationExprs(DstExprs);
558 Clause->setAssignmentOps(AssignmentOps);
559 return Clause;
560}
561
562OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
563 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000564 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000565 return new (Mem) OMPCopyprivateClause(N);
566}
567
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000568void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
569 assert(Privates.size() == varlist_size() &&
570 "Number of private copies is not the same as the preallocated buffer");
571 std::copy(Privates.begin(), Privates.end(), varlist_end());
572}
573
James Y Knightb8bfd962015-10-02 13:41:04 +0000574void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
575 assert(
576 LHSExprs.size() == varlist_size() &&
577 "Number of LHS expressions is not the same as the preallocated buffer");
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000578 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
James Y Knightb8bfd962015-10-02 13:41:04 +0000579}
580
581void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
582 assert(
583 RHSExprs.size() == varlist_size() &&
584 "Number of RHS expressions is not the same as the preallocated buffer");
585 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
586}
587
588void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
589 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
590 "expressions is not the same "
591 "as the preallocated buffer");
592 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
593}
594
595OMPReductionClause *OMPReductionClause::Create(
596 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
597 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
598 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000599 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev61205072016-03-02 04:57:40 +0000600 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
601 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000602 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000603 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
604 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
605 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000606 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000607 Clause->setLHSExprs(LHSExprs);
608 Clause->setRHSExprs(RHSExprs);
609 Clause->setReductionOps(ReductionOps);
Alexey Bataev61205072016-03-02 04:57:40 +0000610 Clause->setPreInitStmt(PreInit);
611 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000612 return Clause;
613}
614
615OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
616 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000617 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000618 return new (Mem) OMPReductionClause(N);
619}
620
Alexey Bataev169d96a2017-07-18 20:17:46 +0000621void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
622 assert(Privates.size() == varlist_size() &&
623 "Number of private copies is not the same as the preallocated buffer");
624 std::copy(Privates.begin(), Privates.end(), varlist_end());
625}
626
627void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
628 assert(
629 LHSExprs.size() == varlist_size() &&
630 "Number of LHS expressions is not the same as the preallocated buffer");
631 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
632}
633
634void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
635 assert(
636 RHSExprs.size() == varlist_size() &&
637 "Number of RHS expressions is not the same as the preallocated buffer");
638 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
639}
640
641void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
642 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
643 "expressions is not the same "
644 "as the preallocated buffer");
645 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
646}
647
648OMPTaskReductionClause *OMPTaskReductionClause::Create(
649 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
650 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
651 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
652 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
653 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
654 Expr *PostUpdate) {
655 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
656 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
657 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
658 Clause->setVarRefs(VL);
659 Clause->setPrivates(Privates);
660 Clause->setLHSExprs(LHSExprs);
661 Clause->setRHSExprs(RHSExprs);
662 Clause->setReductionOps(ReductionOps);
663 Clause->setPreInitStmt(PreInit);
664 Clause->setPostUpdateExpr(PostUpdate);
665 return Clause;
666}
667
668OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
669 unsigned N) {
670 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
671 return new (Mem) OMPTaskReductionClause(N);
672}
673
Alexey Bataevfa312f32017-07-21 18:48:21 +0000674void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
675 assert(Privates.size() == varlist_size() &&
676 "Number of private copies is not the same as the preallocated buffer");
677 std::copy(Privates.begin(), Privates.end(), varlist_end());
678}
679
680void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
681 assert(
682 LHSExprs.size() == varlist_size() &&
683 "Number of LHS expressions is not the same as the preallocated buffer");
684 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
685}
686
687void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
688 assert(
689 RHSExprs.size() == varlist_size() &&
690 "Number of RHS expressions is not the same as the preallocated buffer");
691 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
692}
693
694void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
695 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
696 "expressions is not the same "
697 "as the preallocated buffer");
698 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
699}
700
Alexey Bataev88202be2017-07-27 13:20:36 +0000701void OMPInReductionClause::setTaskgroupDescriptors(
702 ArrayRef<Expr *> TaskgroupDescriptors) {
703 assert(TaskgroupDescriptors.size() == varlist_size() &&
704 "Number of in reduction descriptors is not the same as the "
705 "preallocated buffer");
706 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
707 getReductionOps().end());
708}
709
Alexey Bataevfa312f32017-07-21 18:48:21 +0000710OMPInReductionClause *OMPInReductionClause::Create(
711 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
712 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
713 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
714 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev88202be2017-07-27 13:20:36 +0000715 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
716 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
717 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000718 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
719 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
720 Clause->setVarRefs(VL);
721 Clause->setPrivates(Privates);
722 Clause->setLHSExprs(LHSExprs);
723 Clause->setRHSExprs(RHSExprs);
724 Clause->setReductionOps(ReductionOps);
Alexey Bataev88202be2017-07-27 13:20:36 +0000725 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000726 Clause->setPreInitStmt(PreInit);
727 Clause->setPostUpdateExpr(PostUpdate);
728 return Clause;
729}
730
731OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
732 unsigned N) {
Alexey Bataev88202be2017-07-27 13:20:36 +0000733 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000734 return new (Mem) OMPInReductionClause(N);
735}
736
Alexey Bataeve04483e2019-03-27 14:14:31 +0000737OMPAllocateClause *
738OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc,
739 SourceLocation LParenLoc, Expr *Allocator,
740 SourceLocation ColonLoc, SourceLocation EndLoc,
741 ArrayRef<Expr *> VL) {
742 // Allocate space for private variables and initializer expressions.
743 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
744 auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
745 ColonLoc, EndLoc, VL.size());
746 Clause->setVarRefs(VL);
747 return Clause;
748}
749
750OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
751 unsigned N) {
752 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
753 return new (Mem) OMPAllocateClause(N);
754}
755
James Y Knightb8bfd962015-10-02 13:41:04 +0000756OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
757 SourceLocation StartLoc,
758 SourceLocation LParenLoc,
759 SourceLocation EndLoc,
760 ArrayRef<Expr *> VL) {
Alexey Bataev8b427062016-05-25 12:36:08 +0000761 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000762 OMPFlushClause *Clause =
763 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
764 Clause->setVarRefs(VL);
765 return Clause;
766}
767
768OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000769 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000770 return new (Mem) OMPFlushClause(N);
771}
772
Alexey Bataevf138fda2018-08-13 19:04:24 +0000773OMPDependClause *
774OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
775 SourceLocation LParenLoc, SourceLocation EndLoc,
776 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
777 SourceLocation ColonLoc, ArrayRef<Expr *> VL,
778 unsigned NumLoops) {
779 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
780 OMPDependClause *Clause = new (Mem)
781 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000782 Clause->setVarRefs(VL);
783 Clause->setDependencyKind(DepKind);
784 Clause->setDependencyLoc(DepLoc);
785 Clause->setColonLoc(ColonLoc);
Alexey Bataevf138fda2018-08-13 19:04:24 +0000786 for (unsigned I = 0 ; I < NumLoops; ++I)
787 Clause->setLoopData(I, nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000788 return Clause;
789}
790
Alexey Bataevf138fda2018-08-13 19:04:24 +0000791OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
792 unsigned NumLoops) {
793 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
794 return new (Mem) OMPDependClause(N, NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000795}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000796
Alexey Bataevf138fda2018-08-13 19:04:24 +0000797void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
798 assert((getDependencyKind() == OMPC_DEPEND_sink ||
799 getDependencyKind() == OMPC_DEPEND_source) &&
800 NumLoop < NumLoops &&
801 "Expected sink or source depend + loop index must be less number of "
802 "loops.");
803 auto It = std::next(getVarRefs().end(), NumLoop);
804 *It = Cnt;
Alexey Bataev8b427062016-05-25 12:36:08 +0000805}
806
Alexey Bataevf138fda2018-08-13 19:04:24 +0000807Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
808 assert((getDependencyKind() == OMPC_DEPEND_sink ||
809 getDependencyKind() == OMPC_DEPEND_source) &&
810 NumLoop < NumLoops &&
811 "Expected sink or source depend + loop index must be less number of "
812 "loops.");
813 auto It = std::next(getVarRefs().end(), NumLoop);
814 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000815}
816
Alexey Bataevf138fda2018-08-13 19:04:24 +0000817const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
818 assert((getDependencyKind() == OMPC_DEPEND_sink ||
819 getDependencyKind() == OMPC_DEPEND_source) &&
820 NumLoop < NumLoops &&
821 "Expected sink or source depend + loop index must be less number of "
822 "loops.");
823 auto It = std::next(getVarRefs().end(), NumLoop);
824 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000825}
826
Samuel Antao90927002016-04-26 14:54:23 +0000827unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
828 MappableExprComponentListsRef ComponentLists) {
829 unsigned TotalNum = 0u;
830 for (auto &C : ComponentLists)
831 TotalNum += C.size();
832 return TotalNum;
833}
834
835unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
Alexey Bataeve3727102018-04-18 15:57:46 +0000836 ArrayRef<const ValueDecl *> Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000837 unsigned TotalNum = 0u;
838 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
Alexey Bataeve3727102018-04-18 15:57:46 +0000839 for (const ValueDecl *D : Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000840 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
841 if (Cache.count(VD))
842 continue;
843 ++TotalNum;
844 Cache.insert(VD);
845 }
846 return TotalNum;
847}
848
Michael Kruse4304e9d2019-02-19 16:38:20 +0000849OMPMapClause *OMPMapClause::Create(
850 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
851 ArrayRef<ValueDecl *> Declarations,
852 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
853 ArrayRef<OpenMPMapModifierKind> MapModifiers,
854 ArrayRef<SourceLocation> MapModifiersLoc,
855 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
856 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
857 OMPMappableExprListSizeTy Sizes;
858 Sizes.NumVars = Vars.size();
859 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
860 Sizes.NumComponentLists = ComponentLists.size();
861 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao90927002016-04-26 14:54:23 +0000862
863 // We need to allocate:
Michael Kruse4304e9d2019-02-19 16:38:20 +0000864 // 2 x NumVars x Expr* - we have an original list expression and an associated
865 // user-defined mapper for each clause list entry.
Samuel Antao90927002016-04-26 14:54:23 +0000866 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
867 // with each component list.
868 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
869 // number of lists for each unique declaration and the size of each component
870 // list.
871 // NumComponents x MappableComponent - the total of all the components in all
872 // the lists.
873 void *Mem = C.Allocate(
874 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
875 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000876 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
877 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
878 Sizes.NumComponents));
879 OMPMapClause *Clause = new (Mem)
880 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
881 Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
Samuel Antao90927002016-04-26 14:54:23 +0000882
883 Clause->setVarRefs(Vars);
Michael Kruse4304e9d2019-02-19 16:38:20 +0000884 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao90927002016-04-26 14:54:23 +0000885 Clause->setClauseInfo(Declarations, ComponentLists);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000886 Clause->setMapType(Type);
887 Clause->setMapLoc(TypeLoc);
888 return Clause;
889}
890
Michael Kruse4304e9d2019-02-19 16:38:20 +0000891OMPMapClause *
892OMPMapClause::CreateEmpty(const ASTContext &C,
893 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao90927002016-04-26 14:54:23 +0000894 void *Mem = C.Allocate(
895 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
896 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000897 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
898 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
899 Sizes.NumComponents));
900 return new (Mem) OMPMapClause(Sizes);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000901}
Samuel Antao661c0902016-05-26 17:39:58 +0000902
Michael Kruse01f670d2019-02-22 22:29:42 +0000903OMPToClause *OMPToClause::Create(
904 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
905 ArrayRef<ValueDecl *> Declarations,
906 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
907 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000908 OMPMappableExprListSizeTy Sizes;
909 Sizes.NumVars = Vars.size();
910 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
911 Sizes.NumComponentLists = ComponentLists.size();
912 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao661c0902016-05-26 17:39:58 +0000913
914 // We need to allocate:
Michael Kruse01f670d2019-02-22 22:29:42 +0000915 // 2 x NumVars x Expr* - we have an original list expression and an associated
916 // user-defined mapper for each clause list entry.
Samuel Antao661c0902016-05-26 17:39:58 +0000917 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
918 // with each component list.
919 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
920 // number of lists for each unique declaration and the size of each component
921 // list.
922 // NumComponents x MappableComponent - the total of all the components in all
923 // the lists.
924 void *Mem = C.Allocate(
925 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
926 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +0000927 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000928 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
929 Sizes.NumComponents));
Samuel Antao661c0902016-05-26 17:39:58 +0000930
Michael Kruse01f670d2019-02-22 22:29:42 +0000931 auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +0000932
933 Clause->setVarRefs(Vars);
Michael Kruse01f670d2019-02-22 22:29:42 +0000934 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao661c0902016-05-26 17:39:58 +0000935 Clause->setClauseInfo(Declarations, ComponentLists);
936 return Clause;
937}
938
Michael Kruse4304e9d2019-02-19 16:38:20 +0000939OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
940 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao661c0902016-05-26 17:39:58 +0000941 void *Mem = C.Allocate(
942 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
943 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +0000944 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000945 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
946 Sizes.NumComponents));
947 return new (Mem) OMPToClause(Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +0000948}
Samuel Antaoec172c62016-05-26 17:49:04 +0000949
Michael Kruse0336c752019-02-25 20:34:15 +0000950OMPFromClause *OMPFromClause::Create(
951 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
952 ArrayRef<ValueDecl *> Declarations,
953 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
954 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000955 OMPMappableExprListSizeTy Sizes;
956 Sizes.NumVars = Vars.size();
957 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
958 Sizes.NumComponentLists = ComponentLists.size();
959 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaoec172c62016-05-26 17:49:04 +0000960
961 // We need to allocate:
Michael Kruse0336c752019-02-25 20:34:15 +0000962 // 2 x NumVars x Expr* - we have an original list expression and an associated
963 // user-defined mapper for each clause list entry.
Samuel Antaoec172c62016-05-26 17:49:04 +0000964 // 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>(
Michael Kruse0336c752019-02-25 20:34:15 +0000974 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000975 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
976 Sizes.NumComponents));
Samuel Antaoec172c62016-05-26 17:49:04 +0000977
Michael Kruse0336c752019-02-25 20:34:15 +0000978 auto *Clause =
979 new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +0000980
981 Clause->setVarRefs(Vars);
Michael Kruse0336c752019-02-25 20:34:15 +0000982 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antaoec172c62016-05-26 17:49:04 +0000983 Clause->setClauseInfo(Declarations, ComponentLists);
984 return Clause;
985}
986
Michael Kruse4304e9d2019-02-19 16:38:20 +0000987OMPFromClause *
988OMPFromClause::CreateEmpty(const ASTContext &C,
989 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaoec172c62016-05-26 17:49:04 +0000990 void *Mem = C.Allocate(
991 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
992 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +0000993 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000994 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
995 Sizes.NumComponents));
996 return new (Mem) OMPFromClause(Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +0000997}
Carlo Bertolli2404b172016-07-13 15:37:16 +0000998
Samuel Antaocc10b852016-07-28 14:23:26 +0000999void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1000 assert(VL.size() == varlist_size() &&
1001 "Number of private copies is not the same as the preallocated buffer");
1002 std::copy(VL.begin(), VL.end(), varlist_end());
1003}
1004
1005void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
1006 assert(VL.size() == varlist_size() &&
1007 "Number of inits is not the same as the preallocated buffer");
1008 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1009}
1010
1011OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001012 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1013 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
1014 ArrayRef<ValueDecl *> Declarations,
Samuel Antaocc10b852016-07-28 14:23:26 +00001015 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001016 OMPMappableExprListSizeTy Sizes;
1017 Sizes.NumVars = Vars.size();
1018 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1019 Sizes.NumComponentLists = ComponentLists.size();
1020 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaocc10b852016-07-28 14:23:26 +00001021
1022 // We need to allocate:
1023 // 3 x NumVars x Expr* - we have an original list expression for each clause
1024 // list entry and an equal number of private copies and inits.
1025 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1026 // with each component list.
1027 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1028 // number of lists for each unique declaration and the size of each component
1029 // list.
1030 // NumComponents x MappableComponent - the total of all the components in all
1031 // the lists.
1032 void *Mem = C.Allocate(
1033 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1034 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001035 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1036 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1037 Sizes.NumComponents));
Samuel Antaocc10b852016-07-28 14:23:26 +00001038
Michael Kruse4304e9d2019-02-19 16:38:20 +00001039 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
Samuel Antaocc10b852016-07-28 14:23:26 +00001040
1041 Clause->setVarRefs(Vars);
1042 Clause->setPrivateCopies(PrivateVars);
1043 Clause->setInits(Inits);
1044 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001045 return Clause;
1046}
1047
Michael Kruse4304e9d2019-02-19 16:38:20 +00001048OMPUseDevicePtrClause *
1049OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
1050 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaocc10b852016-07-28 14:23:26 +00001051 void *Mem = C.Allocate(
1052 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1053 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001054 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1055 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1056 Sizes.NumComponents));
1057 return new (Mem) OMPUseDevicePtrClause(Sizes);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001058}
Carlo Bertolli70594e92016-07-13 17:16:49 +00001059
Samuel Antao6890b092016-07-28 14:25:09 +00001060OMPIsDevicePtrClause *
Michael Kruse4304e9d2019-02-19 16:38:20 +00001061OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
Samuel Antao6890b092016-07-28 14:25:09 +00001062 ArrayRef<Expr *> Vars,
1063 ArrayRef<ValueDecl *> Declarations,
1064 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001065 OMPMappableExprListSizeTy Sizes;
1066 Sizes.NumVars = Vars.size();
1067 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1068 Sizes.NumComponentLists = ComponentLists.size();
1069 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao6890b092016-07-28 14:25:09 +00001070
1071 // We need to allocate:
1072 // NumVars x Expr* - we have an original list expression for each clause list
1073 // entry.
1074 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1075 // with each component list.
1076 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1077 // number of lists for each unique declaration and the size of each component
1078 // list.
1079 // NumComponents x MappableComponent - the total of all the components in all
1080 // the lists.
1081 void *Mem = C.Allocate(
1082 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1083 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001084 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1085 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1086 Sizes.NumComponents));
Samuel Antao6890b092016-07-28 14:25:09 +00001087
Michael Kruse4304e9d2019-02-19 16:38:20 +00001088 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
Samuel Antao6890b092016-07-28 14:25:09 +00001089
1090 Clause->setVarRefs(Vars);
1091 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001092 return Clause;
1093}
1094
Michael Kruse4304e9d2019-02-19 16:38:20 +00001095OMPIsDevicePtrClause *
1096OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1097 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao6890b092016-07-28 14:25:09 +00001098 void *Mem = C.Allocate(
1099 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1100 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001101 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1102 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1103 Sizes.NumComponents));
1104 return new (Mem) OMPIsDevicePtrClause(Sizes);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001105}
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001106
1107//===----------------------------------------------------------------------===//
1108// OpenMP clauses printing methods
1109//===----------------------------------------------------------------------===//
1110
1111void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1112 OS << "if(";
1113 if (Node->getNameModifier() != OMPD_unknown)
1114 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1115 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1116 OS << ")";
1117}
1118
1119void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1120 OS << "final(";
1121 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1122 OS << ")";
1123}
1124
1125void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1126 OS << "num_threads(";
1127 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1128 OS << ")";
1129}
1130
1131void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1132 OS << "safelen(";
1133 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1134 OS << ")";
1135}
1136
1137void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1138 OS << "simdlen(";
1139 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1140 OS << ")";
1141}
1142
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00001143void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
1144 OS << "allocator(";
1145 Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
1146 OS << ")";
1147}
1148
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001149void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1150 OS << "collapse(";
1151 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1152 OS << ")";
1153}
1154
1155void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1156 OS << "default("
1157 << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
1158 << ")";
1159}
1160
1161void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1162 OS << "proc_bind("
1163 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, Node->getProcBindKind())
1164 << ")";
1165}
1166
1167void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1168 OS << "unified_address";
1169}
1170
1171void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1172 OMPUnifiedSharedMemoryClause *) {
1173 OS << "unified_shared_memory";
1174}
1175
1176void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1177 OS << "reverse_offload";
1178}
1179
1180void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1181 OMPDynamicAllocatorsClause *) {
1182 OS << "dynamic_allocators";
1183}
1184
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00001185void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1186 OMPAtomicDefaultMemOrderClause *Node) {
1187 OS << "atomic_default_mem_order("
1188 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1189 Node->getAtomicDefaultMemOrderKind())
1190 << ")";
1191}
1192
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001193void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1194 OS << "schedule(";
1195 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1196 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1197 Node->getFirstScheduleModifier());
1198 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1199 OS << ", ";
1200 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1201 Node->getSecondScheduleModifier());
1202 }
1203 OS << ": ";
1204 }
1205 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1206 if (auto *E = Node->getChunkSize()) {
1207 OS << ", ";
1208 E->printPretty(OS, nullptr, Policy);
1209 }
1210 OS << ")";
1211}
1212
1213void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1214 OS << "ordered";
1215 if (auto *Num = Node->getNumForLoops()) {
1216 OS << "(";
1217 Num->printPretty(OS, nullptr, Policy, 0);
1218 OS << ")";
1219 }
1220}
1221
1222void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1223 OS << "nowait";
1224}
1225
1226void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1227 OS << "untied";
1228}
1229
1230void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1231 OS << "nogroup";
1232}
1233
1234void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1235 OS << "mergeable";
1236}
1237
1238void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1239
1240void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1241
1242void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
1243 OS << "update";
1244}
1245
1246void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1247 OS << "capture";
1248}
1249
1250void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1251 OS << "seq_cst";
1252}
1253
1254void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1255 OS << "threads";
1256}
1257
1258void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1259
1260void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1261 OS << "device(";
1262 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1263 OS << ")";
1264}
1265
1266void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1267 OS << "num_teams(";
1268 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1269 OS << ")";
1270}
1271
1272void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1273 OS << "thread_limit(";
1274 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1275 OS << ")";
1276}
1277
1278void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1279 OS << "priority(";
1280 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1281 OS << ")";
1282}
1283
1284void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1285 OS << "grainsize(";
1286 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1287 OS << ")";
1288}
1289
1290void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1291 OS << "num_tasks(";
1292 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1293 OS << ")";
1294}
1295
1296void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1297 OS << "hint(";
1298 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1299 OS << ")";
1300}
1301
1302template<typename T>
1303void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1304 for (typename T::varlist_iterator I = Node->varlist_begin(),
1305 E = Node->varlist_end();
1306 I != E; ++I) {
1307 assert(*I && "Expected non-null Stmt");
1308 OS << (I == Node->varlist_begin() ? StartSym : ',');
1309 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1310 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1311 DRE->printPretty(OS, nullptr, Policy, 0);
1312 else
1313 DRE->getDecl()->printQualifiedName(OS);
1314 } else
1315 (*I)->printPretty(OS, nullptr, Policy, 0);
1316 }
1317}
1318
Alexey Bataeve04483e2019-03-27 14:14:31 +00001319void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
1320 if (Node->varlist_empty())
1321 return;
1322 OS << "allocate";
1323 if (Expr *Allocator = Node->getAllocator()) {
1324 OS << "(";
1325 Allocator->printPretty(OS, nullptr, Policy, 0);
1326 OS << ":";
1327 VisitOMPClauseList(Node, ' ');
1328 } else {
1329 VisitOMPClauseList(Node, '(');
1330 }
1331 OS << ")";
1332}
1333
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001334void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1335 if (!Node->varlist_empty()) {
1336 OS << "private";
1337 VisitOMPClauseList(Node, '(');
1338 OS << ")";
1339 }
1340}
1341
1342void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1343 if (!Node->varlist_empty()) {
1344 OS << "firstprivate";
1345 VisitOMPClauseList(Node, '(');
1346 OS << ")";
1347 }
1348}
1349
1350void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1351 if (!Node->varlist_empty()) {
1352 OS << "lastprivate";
1353 VisitOMPClauseList(Node, '(');
1354 OS << ")";
1355 }
1356}
1357
1358void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1359 if (!Node->varlist_empty()) {
1360 OS << "shared";
1361 VisitOMPClauseList(Node, '(');
1362 OS << ")";
1363 }
1364}
1365
1366void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1367 if (!Node->varlist_empty()) {
1368 OS << "reduction(";
1369 NestedNameSpecifier *QualifierLoc =
1370 Node->getQualifierLoc().getNestedNameSpecifier();
1371 OverloadedOperatorKind OOK =
1372 Node->getNameInfo().getName().getCXXOverloadedOperator();
1373 if (QualifierLoc == nullptr && OOK != OO_None) {
1374 // Print reduction identifier in C format
1375 OS << getOperatorSpelling(OOK);
1376 } else {
1377 // Use C++ format
1378 if (QualifierLoc != nullptr)
1379 QualifierLoc->print(OS, Policy);
1380 OS << Node->getNameInfo();
1381 }
1382 OS << ":";
1383 VisitOMPClauseList(Node, ' ');
1384 OS << ")";
1385 }
1386}
1387
1388void OMPClausePrinter::VisitOMPTaskReductionClause(
1389 OMPTaskReductionClause *Node) {
1390 if (!Node->varlist_empty()) {
1391 OS << "task_reduction(";
1392 NestedNameSpecifier *QualifierLoc =
1393 Node->getQualifierLoc().getNestedNameSpecifier();
1394 OverloadedOperatorKind OOK =
1395 Node->getNameInfo().getName().getCXXOverloadedOperator();
1396 if (QualifierLoc == nullptr && OOK != OO_None) {
1397 // Print reduction identifier in C format
1398 OS << getOperatorSpelling(OOK);
1399 } else {
1400 // Use C++ format
1401 if (QualifierLoc != nullptr)
1402 QualifierLoc->print(OS, Policy);
1403 OS << Node->getNameInfo();
1404 }
1405 OS << ":";
1406 VisitOMPClauseList(Node, ' ');
1407 OS << ")";
1408 }
1409}
1410
1411void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1412 if (!Node->varlist_empty()) {
1413 OS << "in_reduction(";
1414 NestedNameSpecifier *QualifierLoc =
1415 Node->getQualifierLoc().getNestedNameSpecifier();
1416 OverloadedOperatorKind OOK =
1417 Node->getNameInfo().getName().getCXXOverloadedOperator();
1418 if (QualifierLoc == nullptr && OOK != OO_None) {
1419 // Print reduction identifier in C format
1420 OS << getOperatorSpelling(OOK);
1421 } else {
1422 // Use C++ format
1423 if (QualifierLoc != nullptr)
1424 QualifierLoc->print(OS, Policy);
1425 OS << Node->getNameInfo();
1426 }
1427 OS << ":";
1428 VisitOMPClauseList(Node, ' ');
1429 OS << ")";
1430 }
1431}
1432
1433void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1434 if (!Node->varlist_empty()) {
1435 OS << "linear";
1436 if (Node->getModifierLoc().isValid()) {
1437 OS << '('
1438 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1439 }
1440 VisitOMPClauseList(Node, '(');
1441 if (Node->getModifierLoc().isValid())
1442 OS << ')';
1443 if (Node->getStep() != nullptr) {
1444 OS << ": ";
1445 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1446 }
1447 OS << ")";
1448 }
1449}
1450
1451void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1452 if (!Node->varlist_empty()) {
1453 OS << "aligned";
1454 VisitOMPClauseList(Node, '(');
1455 if (Node->getAlignment() != nullptr) {
1456 OS << ": ";
1457 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1458 }
1459 OS << ")";
1460 }
1461}
1462
1463void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1464 if (!Node->varlist_empty()) {
1465 OS << "copyin";
1466 VisitOMPClauseList(Node, '(');
1467 OS << ")";
1468 }
1469}
1470
1471void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1472 if (!Node->varlist_empty()) {
1473 OS << "copyprivate";
1474 VisitOMPClauseList(Node, '(');
1475 OS << ")";
1476 }
1477}
1478
1479void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1480 if (!Node->varlist_empty()) {
1481 VisitOMPClauseList(Node, '(');
1482 OS << ")";
1483 }
1484}
1485
1486void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1487 OS << "depend(";
1488 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1489 Node->getDependencyKind());
1490 if (!Node->varlist_empty()) {
1491 OS << " :";
1492 VisitOMPClauseList(Node, ' ');
1493 }
1494 OS << ")";
1495}
1496
1497void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1498 if (!Node->varlist_empty()) {
1499 OS << "map(";
1500 if (Node->getMapType() != OMPC_MAP_unknown) {
Kelvin Lief579432018-12-18 22:18:41 +00001501 for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1502 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1503 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1504 Node->getMapTypeModifier(I));
Michael Kruse4304e9d2019-02-19 16:38:20 +00001505 if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1506 OS << '(';
1507 NestedNameSpecifier *MapperNNS =
1508 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1509 if (MapperNNS)
1510 MapperNNS->print(OS, Policy);
1511 OS << Node->getMapperIdInfo() << ')';
1512 }
Kelvin Lief579432018-12-18 22:18:41 +00001513 OS << ',';
1514 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001515 }
1516 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1517 OS << ':';
1518 }
1519 VisitOMPClauseList(Node, ' ');
1520 OS << ")";
1521 }
1522}
1523
1524void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1525 if (!Node->varlist_empty()) {
1526 OS << "to";
Michael Kruse01f670d2019-02-22 22:29:42 +00001527 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1528 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1529 OS << '(';
1530 OS << "mapper(";
1531 NestedNameSpecifier *MapperNNS =
1532 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1533 if (MapperNNS)
1534 MapperNNS->print(OS, Policy);
1535 OS << MapperId << "):";
1536 VisitOMPClauseList(Node, ' ');
1537 } else {
1538 VisitOMPClauseList(Node, '(');
1539 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001540 OS << ")";
1541 }
1542}
1543
1544void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1545 if (!Node->varlist_empty()) {
1546 OS << "from";
Michael Kruse0336c752019-02-25 20:34:15 +00001547 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1548 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1549 OS << '(';
1550 OS << "mapper(";
1551 NestedNameSpecifier *MapperNNS =
1552 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1553 if (MapperNNS)
1554 MapperNNS->print(OS, Policy);
1555 OS << MapperId << "):";
1556 VisitOMPClauseList(Node, ' ');
1557 } else {
1558 VisitOMPClauseList(Node, '(');
1559 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001560 OS << ")";
1561 }
1562}
1563
1564void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1565 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1566 OMPC_dist_schedule, Node->getDistScheduleKind());
1567 if (auto *E = Node->getChunkSize()) {
1568 OS << ", ";
1569 E->printPretty(OS, nullptr, Policy);
1570 }
1571 OS << ")";
1572}
1573
1574void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1575 OS << "defaultmap(";
1576 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1577 Node->getDefaultmapModifier());
1578 OS << ": ";
1579 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1580 Node->getDefaultmapKind());
1581 OS << ")";
1582}
1583
1584void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1585 if (!Node->varlist_empty()) {
1586 OS << "use_device_ptr";
1587 VisitOMPClauseList(Node, '(');
1588 OS << ")";
1589 }
1590}
1591
1592void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1593 if (!Node->varlist_empty()) {
1594 OS << "is_device_ptr";
1595 VisitOMPClauseList(Node, '(');
1596 OS << ")";
1597 }
1598}
1599