blob: 7cba4d7039a7031dd5d219dc0fb819e81fbc192f [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
Alexey Bataev195ae902019-08-08 13:42:45 +0000432void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) {
433 assert(
434 UE.size() == varlist_size() + 1 &&
435 "Number of used expressions is not the same as the preallocated buffer");
436 std::copy(UE.begin(), UE.end(), getFinals().end() + 2);
437}
438
James Y Knightb8bfd962015-10-02 13:41:04 +0000439OMPLinearClause *OMPLinearClause::Create(
440 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
441 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
442 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
Alexey Bataev78849fb2016-03-09 09:49:00 +0000443 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
444 Stmt *PreInit, Expr *PostUpdate) {
Alexey Bataev195ae902019-08-08 13:42:45 +0000445 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
446 // (Step and CalcStep), list of used expression + step.
447 void *Mem =
448 C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000449 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
450 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
451 Clause->setVarRefs(VL);
452 Clause->setPrivates(PL);
453 Clause->setInits(IL);
454 // Fill update and final expressions with zeroes, they are provided later,
455 // after the directive construction.
456 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
457 nullptr);
458 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
459 nullptr);
Alexey Bataev195ae902019-08-08 13:42:45 +0000460 std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(),
461 nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000462 Clause->setStep(Step);
463 Clause->setCalcStep(CalcStep);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000464 Clause->setPreInitStmt(PreInit);
465 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000466 return Clause;
467}
468
469OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
470 unsigned NumVars) {
Alexey Bataev195ae902019-08-08 13:42:45 +0000471 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
472 // (Step and CalcStep), list of used expression + step.
473 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars +1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000474 return new (Mem) OMPLinearClause(NumVars);
475}
476
Alexey Bataev195ae902019-08-08 13:42:45 +0000477OMPClause::child_range OMPLinearClause::used_children() {
478 // Range includes only non-nullptr elements.
479 return child_range(
480 reinterpret_cast<Stmt **>(getUsedExprs().begin()),
481 reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr)));
482}
483
James Y Knightb8bfd962015-10-02 13:41:04 +0000484OMPAlignedClause *
485OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
486 SourceLocation LParenLoc, SourceLocation ColonLoc,
487 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
James Y Knight374fd202016-01-01 00:38:24 +0000488 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000489 OMPAlignedClause *Clause = new (Mem)
490 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
491 Clause->setVarRefs(VL);
492 Clause->setAlignment(A);
493 return Clause;
494}
495
496OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
497 unsigned NumVars) {
James Y Knight374fd202016-01-01 00:38:24 +0000498 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000499 return new (Mem) OMPAlignedClause(NumVars);
500}
501
502void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
503 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
504 "not the same as the "
505 "preallocated buffer");
506 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
507}
508
509void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
510 assert(DstExprs.size() == varlist_size() && "Number of destination "
511 "expressions is not the same as "
512 "the preallocated buffer");
513 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
514}
515
516void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
517 assert(AssignmentOps.size() == varlist_size() &&
518 "Number of assignment expressions is not the same as the preallocated "
519 "buffer");
520 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
521 getDestinationExprs().end());
522}
523
524OMPCopyinClause *OMPCopyinClause::Create(
525 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
526 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
527 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000528 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000529 OMPCopyinClause *Clause =
530 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
531 Clause->setVarRefs(VL);
532 Clause->setSourceExprs(SrcExprs);
533 Clause->setDestinationExprs(DstExprs);
534 Clause->setAssignmentOps(AssignmentOps);
535 return Clause;
536}
537
538OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000539 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000540 return new (Mem) OMPCopyinClause(N);
541}
542
543void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
544 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
545 "not the same as the "
546 "preallocated buffer");
547 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
548}
549
550void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
551 assert(DstExprs.size() == varlist_size() && "Number of destination "
552 "expressions is not the same as "
553 "the preallocated buffer");
554 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
555}
556
557void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
558 assert(AssignmentOps.size() == varlist_size() &&
559 "Number of assignment expressions is not the same as the preallocated "
560 "buffer");
561 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
562 getDestinationExprs().end());
563}
564
565OMPCopyprivateClause *OMPCopyprivateClause::Create(
566 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
567 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
568 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000569 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000570 OMPCopyprivateClause *Clause =
571 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
572 Clause->setVarRefs(VL);
573 Clause->setSourceExprs(SrcExprs);
574 Clause->setDestinationExprs(DstExprs);
575 Clause->setAssignmentOps(AssignmentOps);
576 return Clause;
577}
578
579OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
580 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000581 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000582 return new (Mem) OMPCopyprivateClause(N);
583}
584
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000585void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
586 assert(Privates.size() == varlist_size() &&
587 "Number of private copies is not the same as the preallocated buffer");
588 std::copy(Privates.begin(), Privates.end(), varlist_end());
589}
590
James Y Knightb8bfd962015-10-02 13:41:04 +0000591void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
592 assert(
593 LHSExprs.size() == varlist_size() &&
594 "Number of LHS expressions is not the same as the preallocated buffer");
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000595 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
James Y Knightb8bfd962015-10-02 13:41:04 +0000596}
597
598void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
599 assert(
600 RHSExprs.size() == varlist_size() &&
601 "Number of RHS expressions is not the same as the preallocated buffer");
602 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
603}
604
605void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
606 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
607 "expressions is not the same "
608 "as the preallocated buffer");
609 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
610}
611
612OMPReductionClause *OMPReductionClause::Create(
613 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
614 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
615 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000616 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev61205072016-03-02 04:57:40 +0000617 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
618 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000619 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000620 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
621 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
622 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000623 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000624 Clause->setLHSExprs(LHSExprs);
625 Clause->setRHSExprs(RHSExprs);
626 Clause->setReductionOps(ReductionOps);
Alexey Bataev61205072016-03-02 04:57:40 +0000627 Clause->setPreInitStmt(PreInit);
628 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000629 return Clause;
630}
631
632OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
633 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000634 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000635 return new (Mem) OMPReductionClause(N);
636}
637
Alexey Bataev169d96a2017-07-18 20:17:46 +0000638void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
639 assert(Privates.size() == varlist_size() &&
640 "Number of private copies is not the same as the preallocated buffer");
641 std::copy(Privates.begin(), Privates.end(), varlist_end());
642}
643
644void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
645 assert(
646 LHSExprs.size() == varlist_size() &&
647 "Number of LHS expressions is not the same as the preallocated buffer");
648 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
649}
650
651void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
652 assert(
653 RHSExprs.size() == varlist_size() &&
654 "Number of RHS expressions is not the same as the preallocated buffer");
655 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
656}
657
658void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
659 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
660 "expressions is not the same "
661 "as the preallocated buffer");
662 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
663}
664
665OMPTaskReductionClause *OMPTaskReductionClause::Create(
666 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
667 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
668 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
669 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
670 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
671 Expr *PostUpdate) {
672 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
673 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
674 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
675 Clause->setVarRefs(VL);
676 Clause->setPrivates(Privates);
677 Clause->setLHSExprs(LHSExprs);
678 Clause->setRHSExprs(RHSExprs);
679 Clause->setReductionOps(ReductionOps);
680 Clause->setPreInitStmt(PreInit);
681 Clause->setPostUpdateExpr(PostUpdate);
682 return Clause;
683}
684
685OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
686 unsigned N) {
687 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
688 return new (Mem) OMPTaskReductionClause(N);
689}
690
Alexey Bataevfa312f32017-07-21 18:48:21 +0000691void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
692 assert(Privates.size() == varlist_size() &&
693 "Number of private copies is not the same as the preallocated buffer");
694 std::copy(Privates.begin(), Privates.end(), varlist_end());
695}
696
697void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
698 assert(
699 LHSExprs.size() == varlist_size() &&
700 "Number of LHS expressions is not the same as the preallocated buffer");
701 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
702}
703
704void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
705 assert(
706 RHSExprs.size() == varlist_size() &&
707 "Number of RHS expressions is not the same as the preallocated buffer");
708 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
709}
710
711void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
712 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
713 "expressions is not the same "
714 "as the preallocated buffer");
715 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
716}
717
Alexey Bataev88202be2017-07-27 13:20:36 +0000718void OMPInReductionClause::setTaskgroupDescriptors(
719 ArrayRef<Expr *> TaskgroupDescriptors) {
720 assert(TaskgroupDescriptors.size() == varlist_size() &&
721 "Number of in reduction descriptors is not the same as the "
722 "preallocated buffer");
723 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
724 getReductionOps().end());
725}
726
Alexey Bataevfa312f32017-07-21 18:48:21 +0000727OMPInReductionClause *OMPInReductionClause::Create(
728 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
729 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
730 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
731 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev88202be2017-07-27 13:20:36 +0000732 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
733 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
734 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000735 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
736 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
737 Clause->setVarRefs(VL);
738 Clause->setPrivates(Privates);
739 Clause->setLHSExprs(LHSExprs);
740 Clause->setRHSExprs(RHSExprs);
741 Clause->setReductionOps(ReductionOps);
Alexey Bataev88202be2017-07-27 13:20:36 +0000742 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000743 Clause->setPreInitStmt(PreInit);
744 Clause->setPostUpdateExpr(PostUpdate);
745 return Clause;
746}
747
748OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
749 unsigned N) {
Alexey Bataev88202be2017-07-27 13:20:36 +0000750 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000751 return new (Mem) OMPInReductionClause(N);
752}
753
Alexey Bataeve04483e2019-03-27 14:14:31 +0000754OMPAllocateClause *
755OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc,
756 SourceLocation LParenLoc, Expr *Allocator,
757 SourceLocation ColonLoc, SourceLocation EndLoc,
758 ArrayRef<Expr *> VL) {
759 // Allocate space for private variables and initializer expressions.
760 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
761 auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
762 ColonLoc, EndLoc, VL.size());
763 Clause->setVarRefs(VL);
764 return Clause;
765}
766
767OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
768 unsigned N) {
769 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
770 return new (Mem) OMPAllocateClause(N);
771}
772
James Y Knightb8bfd962015-10-02 13:41:04 +0000773OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
774 SourceLocation StartLoc,
775 SourceLocation LParenLoc,
776 SourceLocation EndLoc,
777 ArrayRef<Expr *> VL) {
Alexey Bataev8b427062016-05-25 12:36:08 +0000778 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000779 OMPFlushClause *Clause =
780 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
781 Clause->setVarRefs(VL);
782 return Clause;
783}
784
785OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000786 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000787 return new (Mem) OMPFlushClause(N);
788}
789
Alexey Bataevf138fda2018-08-13 19:04:24 +0000790OMPDependClause *
791OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
792 SourceLocation LParenLoc, SourceLocation EndLoc,
793 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
794 SourceLocation ColonLoc, ArrayRef<Expr *> VL,
795 unsigned NumLoops) {
796 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
797 OMPDependClause *Clause = new (Mem)
798 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000799 Clause->setVarRefs(VL);
800 Clause->setDependencyKind(DepKind);
801 Clause->setDependencyLoc(DepLoc);
802 Clause->setColonLoc(ColonLoc);
Alexey Bataevf138fda2018-08-13 19:04:24 +0000803 for (unsigned I = 0 ; I < NumLoops; ++I)
804 Clause->setLoopData(I, nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000805 return Clause;
806}
807
Alexey Bataevf138fda2018-08-13 19:04:24 +0000808OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
809 unsigned NumLoops) {
810 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
811 return new (Mem) OMPDependClause(N, NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000812}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000813
Alexey Bataevf138fda2018-08-13 19:04:24 +0000814void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
815 assert((getDependencyKind() == OMPC_DEPEND_sink ||
816 getDependencyKind() == OMPC_DEPEND_source) &&
817 NumLoop < NumLoops &&
818 "Expected sink or source depend + loop index must be less number of "
819 "loops.");
820 auto It = std::next(getVarRefs().end(), NumLoop);
821 *It = Cnt;
Alexey Bataev8b427062016-05-25 12:36:08 +0000822}
823
Alexey Bataevf138fda2018-08-13 19:04:24 +0000824Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
825 assert((getDependencyKind() == OMPC_DEPEND_sink ||
826 getDependencyKind() == OMPC_DEPEND_source) &&
827 NumLoop < NumLoops &&
828 "Expected sink or source depend + loop index must be less number of "
829 "loops.");
830 auto It = std::next(getVarRefs().end(), NumLoop);
831 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000832}
833
Alexey Bataevf138fda2018-08-13 19:04:24 +0000834const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
835 assert((getDependencyKind() == OMPC_DEPEND_sink ||
836 getDependencyKind() == OMPC_DEPEND_source) &&
837 NumLoop < NumLoops &&
838 "Expected sink or source depend + loop index must be less number of "
839 "loops.");
840 auto It = std::next(getVarRefs().end(), NumLoop);
841 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000842}
843
Samuel Antao90927002016-04-26 14:54:23 +0000844unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
845 MappableExprComponentListsRef ComponentLists) {
846 unsigned TotalNum = 0u;
847 for (auto &C : ComponentLists)
848 TotalNum += C.size();
849 return TotalNum;
850}
851
852unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
Alexey Bataeve3727102018-04-18 15:57:46 +0000853 ArrayRef<const ValueDecl *> Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000854 unsigned TotalNum = 0u;
855 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
Alexey Bataeve3727102018-04-18 15:57:46 +0000856 for (const ValueDecl *D : Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000857 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
858 if (Cache.count(VD))
859 continue;
860 ++TotalNum;
861 Cache.insert(VD);
862 }
863 return TotalNum;
864}
865
Michael Kruse4304e9d2019-02-19 16:38:20 +0000866OMPMapClause *OMPMapClause::Create(
867 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
868 ArrayRef<ValueDecl *> Declarations,
869 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
870 ArrayRef<OpenMPMapModifierKind> MapModifiers,
871 ArrayRef<SourceLocation> MapModifiersLoc,
872 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
873 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
874 OMPMappableExprListSizeTy Sizes;
875 Sizes.NumVars = Vars.size();
876 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
877 Sizes.NumComponentLists = ComponentLists.size();
878 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao90927002016-04-26 14:54:23 +0000879
880 // We need to allocate:
Michael Kruse4304e9d2019-02-19 16:38:20 +0000881 // 2 x NumVars x Expr* - we have an original list expression and an associated
882 // user-defined mapper for each clause list entry.
Samuel Antao90927002016-04-26 14:54:23 +0000883 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
884 // with each component list.
885 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
886 // number of lists for each unique declaration and the size of each component
887 // list.
888 // NumComponents x MappableComponent - the total of all the components in all
889 // the lists.
890 void *Mem = C.Allocate(
891 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
892 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000893 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
894 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
895 Sizes.NumComponents));
896 OMPMapClause *Clause = new (Mem)
897 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
898 Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
Samuel Antao90927002016-04-26 14:54:23 +0000899
900 Clause->setVarRefs(Vars);
Michael Kruse4304e9d2019-02-19 16:38:20 +0000901 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao90927002016-04-26 14:54:23 +0000902 Clause->setClauseInfo(Declarations, ComponentLists);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000903 Clause->setMapType(Type);
904 Clause->setMapLoc(TypeLoc);
905 return Clause;
906}
907
Michael Kruse4304e9d2019-02-19 16:38:20 +0000908OMPMapClause *
909OMPMapClause::CreateEmpty(const ASTContext &C,
910 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao90927002016-04-26 14:54:23 +0000911 void *Mem = C.Allocate(
912 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
913 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000914 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
915 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
916 Sizes.NumComponents));
917 return new (Mem) OMPMapClause(Sizes);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000918}
Samuel Antao661c0902016-05-26 17:39:58 +0000919
Michael Kruse01f670d2019-02-22 22:29:42 +0000920OMPToClause *OMPToClause::Create(
921 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
922 ArrayRef<ValueDecl *> Declarations,
923 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
924 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000925 OMPMappableExprListSizeTy Sizes;
926 Sizes.NumVars = Vars.size();
927 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
928 Sizes.NumComponentLists = ComponentLists.size();
929 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao661c0902016-05-26 17:39:58 +0000930
931 // We need to allocate:
Michael Kruse01f670d2019-02-22 22:29:42 +0000932 // 2 x NumVars x Expr* - we have an original list expression and an associated
933 // user-defined mapper for each clause list entry.
Samuel Antao661c0902016-05-26 17:39:58 +0000934 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
935 // with each component list.
936 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
937 // number of lists for each unique declaration and the size of each component
938 // list.
939 // NumComponents x MappableComponent - the total of all the components in all
940 // the lists.
941 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));
Samuel Antao661c0902016-05-26 17:39:58 +0000947
Michael Kruse01f670d2019-02-22 22:29:42 +0000948 auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +0000949
950 Clause->setVarRefs(Vars);
Michael Kruse01f670d2019-02-22 22:29:42 +0000951 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao661c0902016-05-26 17:39:58 +0000952 Clause->setClauseInfo(Declarations, ComponentLists);
953 return Clause;
954}
955
Michael Kruse4304e9d2019-02-19 16:38:20 +0000956OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
957 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao661c0902016-05-26 17:39:58 +0000958 void *Mem = C.Allocate(
959 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
960 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +0000961 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000962 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
963 Sizes.NumComponents));
964 return new (Mem) OMPToClause(Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +0000965}
Samuel Antaoec172c62016-05-26 17:49:04 +0000966
Michael Kruse0336c752019-02-25 20:34:15 +0000967OMPFromClause *OMPFromClause::Create(
968 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
969 ArrayRef<ValueDecl *> Declarations,
970 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
971 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000972 OMPMappableExprListSizeTy Sizes;
973 Sizes.NumVars = Vars.size();
974 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
975 Sizes.NumComponentLists = ComponentLists.size();
976 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaoec172c62016-05-26 17:49:04 +0000977
978 // We need to allocate:
Michael Kruse0336c752019-02-25 20:34:15 +0000979 // 2 x NumVars x Expr* - we have an original list expression and an associated
980 // user-defined mapper for each clause list entry.
Samuel Antaoec172c62016-05-26 17:49:04 +0000981 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
982 // with each component list.
983 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
984 // number of lists for each unique declaration and the size of each component
985 // list.
986 // NumComponents x MappableComponent - the total of all the components in all
987 // the lists.
988 void *Mem = C.Allocate(
989 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
990 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +0000991 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000992 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
993 Sizes.NumComponents));
Samuel Antaoec172c62016-05-26 17:49:04 +0000994
Michael Kruse0336c752019-02-25 20:34:15 +0000995 auto *Clause =
996 new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +0000997
998 Clause->setVarRefs(Vars);
Michael Kruse0336c752019-02-25 20:34:15 +0000999 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antaoec172c62016-05-26 17:49:04 +00001000 Clause->setClauseInfo(Declarations, ComponentLists);
1001 return Clause;
1002}
1003
Michael Kruse4304e9d2019-02-19 16:38:20 +00001004OMPFromClause *
1005OMPFromClause::CreateEmpty(const ASTContext &C,
1006 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaoec172c62016-05-26 17:49:04 +00001007 void *Mem = C.Allocate(
1008 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1009 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001010 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001011 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1012 Sizes.NumComponents));
1013 return new (Mem) OMPFromClause(Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001014}
Carlo Bertolli2404b172016-07-13 15:37:16 +00001015
Samuel Antaocc10b852016-07-28 14:23:26 +00001016void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1017 assert(VL.size() == varlist_size() &&
1018 "Number of private copies is not the same as the preallocated buffer");
1019 std::copy(VL.begin(), VL.end(), varlist_end());
1020}
1021
1022void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
1023 assert(VL.size() == varlist_size() &&
1024 "Number of inits is not the same as the preallocated buffer");
1025 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1026}
1027
1028OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001029 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1030 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
1031 ArrayRef<ValueDecl *> Declarations,
Samuel Antaocc10b852016-07-28 14:23:26 +00001032 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001033 OMPMappableExprListSizeTy Sizes;
1034 Sizes.NumVars = Vars.size();
1035 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1036 Sizes.NumComponentLists = ComponentLists.size();
1037 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaocc10b852016-07-28 14:23:26 +00001038
1039 // We need to allocate:
1040 // 3 x NumVars x Expr* - we have an original list expression for each clause
1041 // list entry and an equal number of private copies and inits.
1042 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1043 // with each component list.
1044 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1045 // number of lists for each unique declaration and the size of each component
1046 // list.
1047 // NumComponents x MappableComponent - the total of all the components in all
1048 // the lists.
1049 void *Mem = C.Allocate(
1050 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1051 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001052 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1053 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1054 Sizes.NumComponents));
Samuel Antaocc10b852016-07-28 14:23:26 +00001055
Michael Kruse4304e9d2019-02-19 16:38:20 +00001056 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
Samuel Antaocc10b852016-07-28 14:23:26 +00001057
1058 Clause->setVarRefs(Vars);
1059 Clause->setPrivateCopies(PrivateVars);
1060 Clause->setInits(Inits);
1061 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001062 return Clause;
1063}
1064
Michael Kruse4304e9d2019-02-19 16:38:20 +00001065OMPUseDevicePtrClause *
1066OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
1067 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaocc10b852016-07-28 14:23:26 +00001068 void *Mem = C.Allocate(
1069 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1070 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001071 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1072 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1073 Sizes.NumComponents));
1074 return new (Mem) OMPUseDevicePtrClause(Sizes);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001075}
Carlo Bertolli70594e92016-07-13 17:16:49 +00001076
Samuel Antao6890b092016-07-28 14:25:09 +00001077OMPIsDevicePtrClause *
Michael Kruse4304e9d2019-02-19 16:38:20 +00001078OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
Samuel Antao6890b092016-07-28 14:25:09 +00001079 ArrayRef<Expr *> Vars,
1080 ArrayRef<ValueDecl *> Declarations,
1081 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001082 OMPMappableExprListSizeTy Sizes;
1083 Sizes.NumVars = Vars.size();
1084 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1085 Sizes.NumComponentLists = ComponentLists.size();
1086 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao6890b092016-07-28 14:25:09 +00001087
1088 // We need to allocate:
1089 // NumVars x Expr* - we have an original list expression for each clause list
1090 // entry.
1091 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1092 // with each component list.
1093 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1094 // number of lists for each unique declaration and the size of each component
1095 // list.
1096 // NumComponents x MappableComponent - the total of all the components in all
1097 // the lists.
1098 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));
Samuel Antao6890b092016-07-28 14:25:09 +00001104
Michael Kruse4304e9d2019-02-19 16:38:20 +00001105 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
Samuel Antao6890b092016-07-28 14:25:09 +00001106
1107 Clause->setVarRefs(Vars);
1108 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001109 return Clause;
1110}
1111
Michael Kruse4304e9d2019-02-19 16:38:20 +00001112OMPIsDevicePtrClause *
1113OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1114 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao6890b092016-07-28 14:25:09 +00001115 void *Mem = C.Allocate(
1116 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1117 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001118 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1119 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1120 Sizes.NumComponents));
1121 return new (Mem) OMPIsDevicePtrClause(Sizes);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001122}
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001123
1124//===----------------------------------------------------------------------===//
1125// OpenMP clauses printing methods
1126//===----------------------------------------------------------------------===//
1127
1128void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1129 OS << "if(";
1130 if (Node->getNameModifier() != OMPD_unknown)
1131 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1132 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1133 OS << ")";
1134}
1135
1136void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1137 OS << "final(";
1138 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1139 OS << ")";
1140}
1141
1142void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1143 OS << "num_threads(";
1144 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1145 OS << ")";
1146}
1147
1148void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1149 OS << "safelen(";
1150 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1151 OS << ")";
1152}
1153
1154void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1155 OS << "simdlen(";
1156 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1157 OS << ")";
1158}
1159
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00001160void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
1161 OS << "allocator(";
1162 Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
1163 OS << ")";
1164}
1165
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001166void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1167 OS << "collapse(";
1168 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1169 OS << ")";
1170}
1171
1172void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1173 OS << "default("
1174 << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
1175 << ")";
1176}
1177
1178void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1179 OS << "proc_bind("
1180 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, Node->getProcBindKind())
1181 << ")";
1182}
1183
1184void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1185 OS << "unified_address";
1186}
1187
1188void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1189 OMPUnifiedSharedMemoryClause *) {
1190 OS << "unified_shared_memory";
1191}
1192
1193void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1194 OS << "reverse_offload";
1195}
1196
1197void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1198 OMPDynamicAllocatorsClause *) {
1199 OS << "dynamic_allocators";
1200}
1201
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00001202void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1203 OMPAtomicDefaultMemOrderClause *Node) {
1204 OS << "atomic_default_mem_order("
1205 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1206 Node->getAtomicDefaultMemOrderKind())
1207 << ")";
1208}
1209
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001210void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1211 OS << "schedule(";
1212 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1213 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1214 Node->getFirstScheduleModifier());
1215 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1216 OS << ", ";
1217 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1218 Node->getSecondScheduleModifier());
1219 }
1220 OS << ": ";
1221 }
1222 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1223 if (auto *E = Node->getChunkSize()) {
1224 OS << ", ";
1225 E->printPretty(OS, nullptr, Policy);
1226 }
1227 OS << ")";
1228}
1229
1230void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1231 OS << "ordered";
1232 if (auto *Num = Node->getNumForLoops()) {
1233 OS << "(";
1234 Num->printPretty(OS, nullptr, Policy, 0);
1235 OS << ")";
1236 }
1237}
1238
1239void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1240 OS << "nowait";
1241}
1242
1243void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1244 OS << "untied";
1245}
1246
1247void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1248 OS << "nogroup";
1249}
1250
1251void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1252 OS << "mergeable";
1253}
1254
1255void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1256
1257void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1258
1259void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
1260 OS << "update";
1261}
1262
1263void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1264 OS << "capture";
1265}
1266
1267void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1268 OS << "seq_cst";
1269}
1270
1271void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1272 OS << "threads";
1273}
1274
1275void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1276
1277void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1278 OS << "device(";
1279 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1280 OS << ")";
1281}
1282
1283void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1284 OS << "num_teams(";
1285 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1286 OS << ")";
1287}
1288
1289void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1290 OS << "thread_limit(";
1291 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1292 OS << ")";
1293}
1294
1295void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1296 OS << "priority(";
1297 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1298 OS << ")";
1299}
1300
1301void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1302 OS << "grainsize(";
1303 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1304 OS << ")";
1305}
1306
1307void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1308 OS << "num_tasks(";
1309 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1310 OS << ")";
1311}
1312
1313void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1314 OS << "hint(";
1315 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1316 OS << ")";
1317}
1318
1319template<typename T>
1320void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1321 for (typename T::varlist_iterator I = Node->varlist_begin(),
1322 E = Node->varlist_end();
1323 I != E; ++I) {
1324 assert(*I && "Expected non-null Stmt");
1325 OS << (I == Node->varlist_begin() ? StartSym : ',');
1326 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1327 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1328 DRE->printPretty(OS, nullptr, Policy, 0);
1329 else
1330 DRE->getDecl()->printQualifiedName(OS);
1331 } else
1332 (*I)->printPretty(OS, nullptr, Policy, 0);
1333 }
1334}
1335
Alexey Bataeve04483e2019-03-27 14:14:31 +00001336void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
1337 if (Node->varlist_empty())
1338 return;
1339 OS << "allocate";
1340 if (Expr *Allocator = Node->getAllocator()) {
1341 OS << "(";
1342 Allocator->printPretty(OS, nullptr, Policy, 0);
1343 OS << ":";
1344 VisitOMPClauseList(Node, ' ');
1345 } else {
1346 VisitOMPClauseList(Node, '(');
1347 }
1348 OS << ")";
1349}
1350
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001351void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1352 if (!Node->varlist_empty()) {
1353 OS << "private";
1354 VisitOMPClauseList(Node, '(');
1355 OS << ")";
1356 }
1357}
1358
1359void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1360 if (!Node->varlist_empty()) {
1361 OS << "firstprivate";
1362 VisitOMPClauseList(Node, '(');
1363 OS << ")";
1364 }
1365}
1366
1367void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1368 if (!Node->varlist_empty()) {
1369 OS << "lastprivate";
1370 VisitOMPClauseList(Node, '(');
1371 OS << ")";
1372 }
1373}
1374
1375void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1376 if (!Node->varlist_empty()) {
1377 OS << "shared";
1378 VisitOMPClauseList(Node, '(');
1379 OS << ")";
1380 }
1381}
1382
1383void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1384 if (!Node->varlist_empty()) {
1385 OS << "reduction(";
1386 NestedNameSpecifier *QualifierLoc =
1387 Node->getQualifierLoc().getNestedNameSpecifier();
1388 OverloadedOperatorKind OOK =
1389 Node->getNameInfo().getName().getCXXOverloadedOperator();
1390 if (QualifierLoc == nullptr && OOK != OO_None) {
1391 // Print reduction identifier in C format
1392 OS << getOperatorSpelling(OOK);
1393 } else {
1394 // Use C++ format
1395 if (QualifierLoc != nullptr)
1396 QualifierLoc->print(OS, Policy);
1397 OS << Node->getNameInfo();
1398 }
1399 OS << ":";
1400 VisitOMPClauseList(Node, ' ');
1401 OS << ")";
1402 }
1403}
1404
1405void OMPClausePrinter::VisitOMPTaskReductionClause(
1406 OMPTaskReductionClause *Node) {
1407 if (!Node->varlist_empty()) {
1408 OS << "task_reduction(";
1409 NestedNameSpecifier *QualifierLoc =
1410 Node->getQualifierLoc().getNestedNameSpecifier();
1411 OverloadedOperatorKind OOK =
1412 Node->getNameInfo().getName().getCXXOverloadedOperator();
1413 if (QualifierLoc == nullptr && OOK != OO_None) {
1414 // Print reduction identifier in C format
1415 OS << getOperatorSpelling(OOK);
1416 } else {
1417 // Use C++ format
1418 if (QualifierLoc != nullptr)
1419 QualifierLoc->print(OS, Policy);
1420 OS << Node->getNameInfo();
1421 }
1422 OS << ":";
1423 VisitOMPClauseList(Node, ' ');
1424 OS << ")";
1425 }
1426}
1427
1428void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1429 if (!Node->varlist_empty()) {
1430 OS << "in_reduction(";
1431 NestedNameSpecifier *QualifierLoc =
1432 Node->getQualifierLoc().getNestedNameSpecifier();
1433 OverloadedOperatorKind OOK =
1434 Node->getNameInfo().getName().getCXXOverloadedOperator();
1435 if (QualifierLoc == nullptr && OOK != OO_None) {
1436 // Print reduction identifier in C format
1437 OS << getOperatorSpelling(OOK);
1438 } else {
1439 // Use C++ format
1440 if (QualifierLoc != nullptr)
1441 QualifierLoc->print(OS, Policy);
1442 OS << Node->getNameInfo();
1443 }
1444 OS << ":";
1445 VisitOMPClauseList(Node, ' ');
1446 OS << ")";
1447 }
1448}
1449
1450void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1451 if (!Node->varlist_empty()) {
1452 OS << "linear";
1453 if (Node->getModifierLoc().isValid()) {
1454 OS << '('
1455 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1456 }
1457 VisitOMPClauseList(Node, '(');
1458 if (Node->getModifierLoc().isValid())
1459 OS << ')';
1460 if (Node->getStep() != nullptr) {
1461 OS << ": ";
1462 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1463 }
1464 OS << ")";
1465 }
1466}
1467
1468void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1469 if (!Node->varlist_empty()) {
1470 OS << "aligned";
1471 VisitOMPClauseList(Node, '(');
1472 if (Node->getAlignment() != nullptr) {
1473 OS << ": ";
1474 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1475 }
1476 OS << ")";
1477 }
1478}
1479
1480void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1481 if (!Node->varlist_empty()) {
1482 OS << "copyin";
1483 VisitOMPClauseList(Node, '(');
1484 OS << ")";
1485 }
1486}
1487
1488void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1489 if (!Node->varlist_empty()) {
1490 OS << "copyprivate";
1491 VisitOMPClauseList(Node, '(');
1492 OS << ")";
1493 }
1494}
1495
1496void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1497 if (!Node->varlist_empty()) {
1498 VisitOMPClauseList(Node, '(');
1499 OS << ")";
1500 }
1501}
1502
1503void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1504 OS << "depend(";
1505 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1506 Node->getDependencyKind());
1507 if (!Node->varlist_empty()) {
1508 OS << " :";
1509 VisitOMPClauseList(Node, ' ');
1510 }
1511 OS << ")";
1512}
1513
1514void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1515 if (!Node->varlist_empty()) {
1516 OS << "map(";
1517 if (Node->getMapType() != OMPC_MAP_unknown) {
Kelvin Lief579432018-12-18 22:18:41 +00001518 for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1519 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1520 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1521 Node->getMapTypeModifier(I));
Michael Kruse4304e9d2019-02-19 16:38:20 +00001522 if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1523 OS << '(';
1524 NestedNameSpecifier *MapperNNS =
1525 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1526 if (MapperNNS)
1527 MapperNNS->print(OS, Policy);
1528 OS << Node->getMapperIdInfo() << ')';
1529 }
Kelvin Lief579432018-12-18 22:18:41 +00001530 OS << ',';
1531 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001532 }
1533 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1534 OS << ':';
1535 }
1536 VisitOMPClauseList(Node, ' ');
1537 OS << ")";
1538 }
1539}
1540
1541void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1542 if (!Node->varlist_empty()) {
1543 OS << "to";
Michael Kruse01f670d2019-02-22 22:29:42 +00001544 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1545 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1546 OS << '(';
1547 OS << "mapper(";
1548 NestedNameSpecifier *MapperNNS =
1549 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1550 if (MapperNNS)
1551 MapperNNS->print(OS, Policy);
1552 OS << MapperId << "):";
1553 VisitOMPClauseList(Node, ' ');
1554 } else {
1555 VisitOMPClauseList(Node, '(');
1556 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001557 OS << ")";
1558 }
1559}
1560
1561void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1562 if (!Node->varlist_empty()) {
1563 OS << "from";
Michael Kruse0336c752019-02-25 20:34:15 +00001564 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1565 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1566 OS << '(';
1567 OS << "mapper(";
1568 NestedNameSpecifier *MapperNNS =
1569 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1570 if (MapperNNS)
1571 MapperNNS->print(OS, Policy);
1572 OS << MapperId << "):";
1573 VisitOMPClauseList(Node, ' ');
1574 } else {
1575 VisitOMPClauseList(Node, '(');
1576 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001577 OS << ")";
1578 }
1579}
1580
1581void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1582 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1583 OMPC_dist_schedule, Node->getDistScheduleKind());
1584 if (auto *E = Node->getChunkSize()) {
1585 OS << ", ";
1586 E->printPretty(OS, nullptr, Policy);
1587 }
1588 OS << ")";
1589}
1590
1591void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1592 OS << "defaultmap(";
1593 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1594 Node->getDefaultmapModifier());
1595 OS << ": ";
1596 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1597 Node->getDefaultmapKind());
1598 OS << ")";
1599}
1600
1601void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1602 if (!Node->varlist_empty()) {
1603 OS << "use_device_ptr";
1604 VisitOMPClauseList(Node, '(');
1605 OS << ")";
1606 }
1607}
1608
1609void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1610 if (!Node->varlist_empty()) {
1611 OS << "is_device_ptr";
1612 VisitOMPClauseList(Node, '(');
1613 OS << ")";
1614 }
1615}
1616