blob: a50e2de7f5193c60eead1bb2d426a1e648616577 [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 Bataev3392d762016-02-16 11:18:12 +000038OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
39 auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
40 return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr;
41}
42
43const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
44 switch (C->getClauseKind()) {
45 case OMPC_schedule:
46 return static_cast<const OMPScheduleClause *>(C);
47 case OMPC_dist_schedule:
48 return static_cast<const OMPDistScheduleClause *>(C);
Alexey Bataev417089f2016-02-17 13:19:37 +000049 case OMPC_firstprivate:
50 return static_cast<const OMPFirstprivateClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +000051 case OMPC_lastprivate:
52 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +000053 case OMPC_reduction:
54 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +000055 case OMPC_task_reduction:
56 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +000057 case OMPC_in_reduction:
58 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +000059 case OMPC_linear:
60 return static_cast<const OMPLinearClause *>(C);
Arpith Chacko Jacobfe4890a2017-01-18 20:40:48 +000061 case OMPC_if:
62 return static_cast<const OMPIfClause *>(C);
Arpith Chacko Jacob33c849a2017-01-25 00:57:16 +000063 case OMPC_num_threads:
64 return static_cast<const OMPNumThreadsClause *>(C);
Arpith Chacko Jacobbc126342017-01-25 11:28:18 +000065 case OMPC_num_teams:
66 return static_cast<const OMPNumTeamsClause *>(C);
Arpith Chacko Jacob7ecc0b72017-01-25 11:44:35 +000067 case OMPC_thread_limit:
68 return static_cast<const OMPThreadLimitClause *>(C);
Alexey Bataev931e19b2017-10-02 16:32:39 +000069 case OMPC_device:
70 return static_cast<const OMPDeviceClause *>(C);
Alexey Bataev3392d762016-02-16 11:18:12 +000071 case OMPC_default:
72 case OMPC_proc_bind:
Alexey Bataev3392d762016-02-16 11:18:12 +000073 case OMPC_final:
Alexey Bataev3392d762016-02-16 11:18:12 +000074 case OMPC_safelen:
75 case OMPC_simdlen:
76 case OMPC_collapse:
77 case OMPC_private:
Alexey Bataev005248a2016-02-25 05:25:57 +000078 case OMPC_shared:
Alexey Bataev005248a2016-02-25 05:25:57 +000079 case OMPC_aligned:
80 case OMPC_copyin:
81 case OMPC_copyprivate:
82 case OMPC_ordered:
83 case OMPC_nowait:
84 case OMPC_untied:
85 case OMPC_mergeable:
86 case OMPC_threadprivate:
87 case OMPC_flush:
88 case OMPC_read:
89 case OMPC_write:
90 case OMPC_update:
91 case OMPC_capture:
92 case OMPC_seq_cst:
93 case OMPC_depend:
Alexey Bataev005248a2016-02-25 05:25:57 +000094 case OMPC_threads:
95 case OMPC_simd:
96 case OMPC_map:
Alexey Bataev005248a2016-02-25 05:25:57 +000097 case OMPC_priority:
98 case OMPC_grainsize:
99 case OMPC_nogroup:
100 case OMPC_num_tasks:
101 case OMPC_hint:
102 case OMPC_defaultmap:
103 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000104 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000105 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000106 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000107 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000108 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000109 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000110 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000111 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000112 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000113 case OMPC_atomic_default_mem_order:
Alexey Bataev005248a2016-02-25 05:25:57 +0000114 break;
115 }
116
117 return nullptr;
118}
119
120OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
121 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
122 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
123}
124
125const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
126 switch (C->getClauseKind()) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000127 case OMPC_lastprivate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000128 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000129 case OMPC_reduction:
130 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +0000131 case OMPC_task_reduction:
132 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000133 case OMPC_in_reduction:
134 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000135 case OMPC_linear:
136 return static_cast<const OMPLinearClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000137 case OMPC_schedule:
138 case OMPC_dist_schedule:
139 case OMPC_firstprivate:
140 case OMPC_default:
141 case OMPC_proc_bind:
142 case OMPC_if:
143 case OMPC_final:
144 case OMPC_num_threads:
145 case OMPC_safelen:
146 case OMPC_simdlen:
147 case OMPC_collapse:
148 case OMPC_private:
Alexey Bataev3392d762016-02-16 11:18:12 +0000149 case OMPC_shared:
Alexey Bataev3392d762016-02-16 11:18:12 +0000150 case OMPC_aligned:
151 case OMPC_copyin:
152 case OMPC_copyprivate:
153 case OMPC_ordered:
154 case OMPC_nowait:
155 case OMPC_untied:
156 case OMPC_mergeable:
157 case OMPC_threadprivate:
158 case OMPC_flush:
159 case OMPC_read:
160 case OMPC_write:
161 case OMPC_update:
162 case OMPC_capture:
163 case OMPC_seq_cst:
164 case OMPC_depend:
165 case OMPC_device:
166 case OMPC_threads:
167 case OMPC_simd:
168 case OMPC_map:
169 case OMPC_num_teams:
170 case OMPC_thread_limit:
171 case OMPC_priority:
172 case OMPC_grainsize:
173 case OMPC_nogroup:
174 case OMPC_num_tasks:
175 case OMPC_hint:
176 case OMPC_defaultmap:
177 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000178 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000179 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000180 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000181 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000182 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000183 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000184 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000185 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000186 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000187 case OMPC_atomic_default_mem_order:
Alexey Bataev3392d762016-02-16 11:18:12 +0000188 break;
189 }
190
191 return nullptr;
192}
193
Alexey Bataevf138fda2018-08-13 19:04:24 +0000194OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
195 unsigned NumLoops,
196 SourceLocation StartLoc,
197 SourceLocation LParenLoc,
198 SourceLocation EndLoc) {
199 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
200 auto *Clause =
201 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
202 for (unsigned I = 0; I < NumLoops; ++I) {
203 Clause->setLoopNumIterations(I, nullptr);
204 Clause->setLoopCounter(I, nullptr);
205 }
206 return Clause;
207}
208
209OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
210 unsigned NumLoops) {
211 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
212 auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
213 for (unsigned I = 0; I < NumLoops; ++I) {
214 Clause->setLoopNumIterations(I, nullptr);
215 Clause->setLoopCounter(I, nullptr);
216 }
217 return Clause;
218}
219
220void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
221 Expr *NumIterations) {
222 assert(NumLoop < NumberOfLoops && "out of loops number.");
223 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
224}
225
226ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
227 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
228}
229
230void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
231 assert(NumLoop < NumberOfLoops && "out of loops number.");
232 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
233}
234
Mike Rice0ed46662018-09-20 17:19:41 +0000235Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000236 assert(NumLoop < NumberOfLoops && "out of loops number.");
237 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
238}
239
Mike Rice0ed46662018-09-20 17:19:41 +0000240const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000241 assert(NumLoop < NumberOfLoops && "out of loops number.");
242 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
243}
244
James Y Knightb8bfd962015-10-02 13:41:04 +0000245void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
246 assert(VL.size() == varlist_size() &&
247 "Number of private copies is not the same as the preallocated buffer");
248 std::copy(VL.begin(), VL.end(), varlist_end());
249}
250
251OMPPrivateClause *
252OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
253 SourceLocation LParenLoc, SourceLocation EndLoc,
254 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
255 // Allocate space for private variables and initializer expressions.
James Y Knight374fd202016-01-01 00:38:24 +0000256 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000257 OMPPrivateClause *Clause =
258 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
259 Clause->setVarRefs(VL);
260 Clause->setPrivateCopies(PrivateVL);
261 return Clause;
262}
263
264OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
265 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000266 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000267 return new (Mem) OMPPrivateClause(N);
268}
269
270void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
271 assert(VL.size() == varlist_size() &&
272 "Number of private copies is not the same as the preallocated buffer");
273 std::copy(VL.begin(), VL.end(), varlist_end());
274}
275
276void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
277 assert(VL.size() == varlist_size() &&
278 "Number of inits is not the same as the preallocated buffer");
279 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
280}
281
282OMPFirstprivateClause *
283OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
284 SourceLocation LParenLoc, SourceLocation EndLoc,
285 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
Alexey Bataev417089f2016-02-17 13:19:37 +0000286 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
James Y Knight374fd202016-01-01 00:38:24 +0000287 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000288 OMPFirstprivateClause *Clause =
289 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
290 Clause->setVarRefs(VL);
291 Clause->setPrivateCopies(PrivateVL);
292 Clause->setInits(InitVL);
Alexey Bataev417089f2016-02-17 13:19:37 +0000293 Clause->setPreInitStmt(PreInit);
James Y Knightb8bfd962015-10-02 13:41:04 +0000294 return Clause;
295}
296
297OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
298 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000299 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000300 return new (Mem) OMPFirstprivateClause(N);
301}
302
303void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
304 assert(PrivateCopies.size() == varlist_size() &&
305 "Number of private copies is not the same as the preallocated buffer");
306 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
307}
308
309void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
310 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
311 "not the same as the "
312 "preallocated buffer");
313 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
314}
315
316void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
317 assert(DstExprs.size() == varlist_size() && "Number of destination "
318 "expressions is not the same as "
319 "the preallocated buffer");
320 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
321}
322
323void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
324 assert(AssignmentOps.size() == varlist_size() &&
325 "Number of assignment expressions is not the same as the preallocated "
326 "buffer");
327 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
328 getDestinationExprs().end());
329}
330
331OMPLastprivateClause *OMPLastprivateClause::Create(
332 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
333 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
Alexey Bataev005248a2016-02-25 05:25:57 +0000334 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit,
335 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000336 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000337 OMPLastprivateClause *Clause =
338 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
339 Clause->setVarRefs(VL);
340 Clause->setSourceExprs(SrcExprs);
341 Clause->setDestinationExprs(DstExprs);
342 Clause->setAssignmentOps(AssignmentOps);
Alexey Bataev005248a2016-02-25 05:25:57 +0000343 Clause->setPreInitStmt(PreInit);
344 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000345 return Clause;
346}
347
348OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
349 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000350 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000351 return new (Mem) OMPLastprivateClause(N);
352}
353
354OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
355 SourceLocation StartLoc,
356 SourceLocation LParenLoc,
357 SourceLocation EndLoc,
358 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000359 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000360 OMPSharedClause *Clause =
361 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
362 Clause->setVarRefs(VL);
363 return Clause;
364}
365
366OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000367 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000368 return new (Mem) OMPSharedClause(N);
369}
370
371void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
372 assert(PL.size() == varlist_size() &&
373 "Number of privates is not the same as the preallocated buffer");
374 std::copy(PL.begin(), PL.end(), varlist_end());
375}
376
377void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
378 assert(IL.size() == varlist_size() &&
379 "Number of inits is not the same as the preallocated buffer");
380 std::copy(IL.begin(), IL.end(), getPrivates().end());
381}
382
383void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
384 assert(UL.size() == varlist_size() &&
385 "Number of updates is not the same as the preallocated buffer");
386 std::copy(UL.begin(), UL.end(), getInits().end());
387}
388
389void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
390 assert(FL.size() == varlist_size() &&
391 "Number of final updates is not the same as the preallocated buffer");
392 std::copy(FL.begin(), FL.end(), getUpdates().end());
393}
394
395OMPLinearClause *OMPLinearClause::Create(
396 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
397 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
398 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
Alexey Bataev78849fb2016-03-09 09:49:00 +0000399 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
400 Stmt *PreInit, Expr *PostUpdate) {
James Y Knightb8bfd962015-10-02 13:41:04 +0000401 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
402 // (Step and CalcStep).
James Y Knight374fd202016-01-01 00:38:24 +0000403 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2));
James Y Knightb8bfd962015-10-02 13:41:04 +0000404 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
405 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
406 Clause->setVarRefs(VL);
407 Clause->setPrivates(PL);
408 Clause->setInits(IL);
409 // Fill update and final expressions with zeroes, they are provided later,
410 // after the directive construction.
411 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
412 nullptr);
413 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
414 nullptr);
415 Clause->setStep(Step);
416 Clause->setCalcStep(CalcStep);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000417 Clause->setPreInitStmt(PreInit);
418 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000419 return Clause;
420}
421
422OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
423 unsigned NumVars) {
424 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
425 // (Step and CalcStep).
James Y Knight374fd202016-01-01 00:38:24 +0000426 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2));
James Y Knightb8bfd962015-10-02 13:41:04 +0000427 return new (Mem) OMPLinearClause(NumVars);
428}
429
430OMPAlignedClause *
431OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
432 SourceLocation LParenLoc, SourceLocation ColonLoc,
433 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
James Y Knight374fd202016-01-01 00:38:24 +0000434 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000435 OMPAlignedClause *Clause = new (Mem)
436 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
437 Clause->setVarRefs(VL);
438 Clause->setAlignment(A);
439 return Clause;
440}
441
442OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
443 unsigned NumVars) {
James Y Knight374fd202016-01-01 00:38:24 +0000444 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000445 return new (Mem) OMPAlignedClause(NumVars);
446}
447
448void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
449 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
450 "not the same as the "
451 "preallocated buffer");
452 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
453}
454
455void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
456 assert(DstExprs.size() == varlist_size() && "Number of destination "
457 "expressions is not the same as "
458 "the preallocated buffer");
459 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
460}
461
462void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
463 assert(AssignmentOps.size() == varlist_size() &&
464 "Number of assignment expressions is not the same as the preallocated "
465 "buffer");
466 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
467 getDestinationExprs().end());
468}
469
470OMPCopyinClause *OMPCopyinClause::Create(
471 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
472 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
473 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000474 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000475 OMPCopyinClause *Clause =
476 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
477 Clause->setVarRefs(VL);
478 Clause->setSourceExprs(SrcExprs);
479 Clause->setDestinationExprs(DstExprs);
480 Clause->setAssignmentOps(AssignmentOps);
481 return Clause;
482}
483
484OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000485 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000486 return new (Mem) OMPCopyinClause(N);
487}
488
489void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
490 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
491 "not the same as the "
492 "preallocated buffer");
493 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
494}
495
496void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
497 assert(DstExprs.size() == varlist_size() && "Number of destination "
498 "expressions is not the same as "
499 "the preallocated buffer");
500 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
501}
502
503void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
504 assert(AssignmentOps.size() == varlist_size() &&
505 "Number of assignment expressions is not the same as the preallocated "
506 "buffer");
507 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
508 getDestinationExprs().end());
509}
510
511OMPCopyprivateClause *OMPCopyprivateClause::Create(
512 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
513 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
514 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000515 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000516 OMPCopyprivateClause *Clause =
517 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
518 Clause->setVarRefs(VL);
519 Clause->setSourceExprs(SrcExprs);
520 Clause->setDestinationExprs(DstExprs);
521 Clause->setAssignmentOps(AssignmentOps);
522 return Clause;
523}
524
525OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
526 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000527 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000528 return new (Mem) OMPCopyprivateClause(N);
529}
530
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000531void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
532 assert(Privates.size() == varlist_size() &&
533 "Number of private copies is not the same as the preallocated buffer");
534 std::copy(Privates.begin(), Privates.end(), varlist_end());
535}
536
James Y Knightb8bfd962015-10-02 13:41:04 +0000537void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
538 assert(
539 LHSExprs.size() == varlist_size() &&
540 "Number of LHS expressions is not the same as the preallocated buffer");
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000541 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
James Y Knightb8bfd962015-10-02 13:41:04 +0000542}
543
544void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
545 assert(
546 RHSExprs.size() == varlist_size() &&
547 "Number of RHS expressions is not the same as the preallocated buffer");
548 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
549}
550
551void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
552 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
553 "expressions is not the same "
554 "as the preallocated buffer");
555 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
556}
557
558OMPReductionClause *OMPReductionClause::Create(
559 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
560 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
561 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000562 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev61205072016-03-02 04:57:40 +0000563 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
564 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000565 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000566 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
567 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
568 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000569 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000570 Clause->setLHSExprs(LHSExprs);
571 Clause->setRHSExprs(RHSExprs);
572 Clause->setReductionOps(ReductionOps);
Alexey Bataev61205072016-03-02 04:57:40 +0000573 Clause->setPreInitStmt(PreInit);
574 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000575 return Clause;
576}
577
578OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
579 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000580 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000581 return new (Mem) OMPReductionClause(N);
582}
583
Alexey Bataev169d96a2017-07-18 20:17:46 +0000584void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
585 assert(Privates.size() == varlist_size() &&
586 "Number of private copies is not the same as the preallocated buffer");
587 std::copy(Privates.begin(), Privates.end(), varlist_end());
588}
589
590void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
591 assert(
592 LHSExprs.size() == varlist_size() &&
593 "Number of LHS expressions is not the same as the preallocated buffer");
594 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
595}
596
597void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
598 assert(
599 RHSExprs.size() == varlist_size() &&
600 "Number of RHS expressions is not the same as the preallocated buffer");
601 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
602}
603
604void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
605 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
606 "expressions is not the same "
607 "as the preallocated buffer");
608 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
609}
610
611OMPTaskReductionClause *OMPTaskReductionClause::Create(
612 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
613 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
614 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
615 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
616 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
617 Expr *PostUpdate) {
618 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
619 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
620 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
621 Clause->setVarRefs(VL);
622 Clause->setPrivates(Privates);
623 Clause->setLHSExprs(LHSExprs);
624 Clause->setRHSExprs(RHSExprs);
625 Clause->setReductionOps(ReductionOps);
626 Clause->setPreInitStmt(PreInit);
627 Clause->setPostUpdateExpr(PostUpdate);
628 return Clause;
629}
630
631OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
632 unsigned N) {
633 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
634 return new (Mem) OMPTaskReductionClause(N);
635}
636
Alexey Bataevfa312f32017-07-21 18:48:21 +0000637void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
638 assert(Privates.size() == varlist_size() &&
639 "Number of private copies is not the same as the preallocated buffer");
640 std::copy(Privates.begin(), Privates.end(), varlist_end());
641}
642
643void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
644 assert(
645 LHSExprs.size() == varlist_size() &&
646 "Number of LHS expressions is not the same as the preallocated buffer");
647 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
648}
649
650void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
651 assert(
652 RHSExprs.size() == varlist_size() &&
653 "Number of RHS expressions is not the same as the preallocated buffer");
654 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
655}
656
657void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
658 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
659 "expressions is not the same "
660 "as the preallocated buffer");
661 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
662}
663
Alexey Bataev88202be2017-07-27 13:20:36 +0000664void OMPInReductionClause::setTaskgroupDescriptors(
665 ArrayRef<Expr *> TaskgroupDescriptors) {
666 assert(TaskgroupDescriptors.size() == varlist_size() &&
667 "Number of in reduction descriptors is not the same as the "
668 "preallocated buffer");
669 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
670 getReductionOps().end());
671}
672
Alexey Bataevfa312f32017-07-21 18:48:21 +0000673OMPInReductionClause *OMPInReductionClause::Create(
674 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
675 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
676 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
677 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev88202be2017-07-27 13:20:36 +0000678 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
679 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
680 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000681 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
682 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
683 Clause->setVarRefs(VL);
684 Clause->setPrivates(Privates);
685 Clause->setLHSExprs(LHSExprs);
686 Clause->setRHSExprs(RHSExprs);
687 Clause->setReductionOps(ReductionOps);
Alexey Bataev88202be2017-07-27 13:20:36 +0000688 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000689 Clause->setPreInitStmt(PreInit);
690 Clause->setPostUpdateExpr(PostUpdate);
691 return Clause;
692}
693
694OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
695 unsigned N) {
Alexey Bataev88202be2017-07-27 13:20:36 +0000696 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000697 return new (Mem) OMPInReductionClause(N);
698}
699
James Y Knightb8bfd962015-10-02 13:41:04 +0000700OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
701 SourceLocation StartLoc,
702 SourceLocation LParenLoc,
703 SourceLocation EndLoc,
704 ArrayRef<Expr *> VL) {
Alexey Bataev8b427062016-05-25 12:36:08 +0000705 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000706 OMPFlushClause *Clause =
707 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
708 Clause->setVarRefs(VL);
709 return Clause;
710}
711
712OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000713 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000714 return new (Mem) OMPFlushClause(N);
715}
716
Alexey Bataevf138fda2018-08-13 19:04:24 +0000717OMPDependClause *
718OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
719 SourceLocation LParenLoc, SourceLocation EndLoc,
720 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
721 SourceLocation ColonLoc, ArrayRef<Expr *> VL,
722 unsigned NumLoops) {
723 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
724 OMPDependClause *Clause = new (Mem)
725 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000726 Clause->setVarRefs(VL);
727 Clause->setDependencyKind(DepKind);
728 Clause->setDependencyLoc(DepLoc);
729 Clause->setColonLoc(ColonLoc);
Alexey Bataevf138fda2018-08-13 19:04:24 +0000730 for (unsigned I = 0 ; I < NumLoops; ++I)
731 Clause->setLoopData(I, nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000732 return Clause;
733}
734
Alexey Bataevf138fda2018-08-13 19:04:24 +0000735OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
736 unsigned NumLoops) {
737 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
738 return new (Mem) OMPDependClause(N, NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000739}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000740
Alexey Bataevf138fda2018-08-13 19:04:24 +0000741void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
742 assert((getDependencyKind() == OMPC_DEPEND_sink ||
743 getDependencyKind() == OMPC_DEPEND_source) &&
744 NumLoop < NumLoops &&
745 "Expected sink or source depend + loop index must be less number of "
746 "loops.");
747 auto It = std::next(getVarRefs().end(), NumLoop);
748 *It = Cnt;
Alexey Bataev8b427062016-05-25 12:36:08 +0000749}
750
Alexey Bataevf138fda2018-08-13 19:04:24 +0000751Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
752 assert((getDependencyKind() == OMPC_DEPEND_sink ||
753 getDependencyKind() == OMPC_DEPEND_source) &&
754 NumLoop < NumLoops &&
755 "Expected sink or source depend + loop index must be less number of "
756 "loops.");
757 auto It = std::next(getVarRefs().end(), NumLoop);
758 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000759}
760
Alexey Bataevf138fda2018-08-13 19:04:24 +0000761const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
762 assert((getDependencyKind() == OMPC_DEPEND_sink ||
763 getDependencyKind() == OMPC_DEPEND_source) &&
764 NumLoop < NumLoops &&
765 "Expected sink or source depend + loop index must be less number of "
766 "loops.");
767 auto It = std::next(getVarRefs().end(), NumLoop);
768 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000769}
770
Samuel Antao90927002016-04-26 14:54:23 +0000771unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
772 MappableExprComponentListsRef ComponentLists) {
773 unsigned TotalNum = 0u;
774 for (auto &C : ComponentLists)
775 TotalNum += C.size();
776 return TotalNum;
777}
778
779unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
Alexey Bataeve3727102018-04-18 15:57:46 +0000780 ArrayRef<const ValueDecl *> Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000781 unsigned TotalNum = 0u;
782 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
Alexey Bataeve3727102018-04-18 15:57:46 +0000783 for (const ValueDecl *D : Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000784 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
785 if (Cache.count(VD))
786 continue;
787 ++TotalNum;
788 Cache.insert(VD);
789 }
790 return TotalNum;
791}
792
Michael Kruse4304e9d2019-02-19 16:38:20 +0000793OMPMapClause *OMPMapClause::Create(
794 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
795 ArrayRef<ValueDecl *> Declarations,
796 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
797 ArrayRef<OpenMPMapModifierKind> MapModifiers,
798 ArrayRef<SourceLocation> MapModifiersLoc,
799 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
800 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
801 OMPMappableExprListSizeTy Sizes;
802 Sizes.NumVars = Vars.size();
803 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
804 Sizes.NumComponentLists = ComponentLists.size();
805 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao90927002016-04-26 14:54:23 +0000806
807 // We need to allocate:
Michael Kruse4304e9d2019-02-19 16:38:20 +0000808 // 2 x NumVars x Expr* - we have an original list expression and an associated
809 // user-defined mapper for each clause list entry.
Samuel Antao90927002016-04-26 14:54:23 +0000810 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
811 // with each component list.
812 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
813 // number of lists for each unique declaration and the size of each component
814 // list.
815 // NumComponents x MappableComponent - the total of all the components in all
816 // the lists.
817 void *Mem = C.Allocate(
818 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
819 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000820 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
821 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
822 Sizes.NumComponents));
823 OMPMapClause *Clause = new (Mem)
824 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
825 Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
Samuel Antao90927002016-04-26 14:54:23 +0000826
827 Clause->setVarRefs(Vars);
Michael Kruse4304e9d2019-02-19 16:38:20 +0000828 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao90927002016-04-26 14:54:23 +0000829 Clause->setClauseInfo(Declarations, ComponentLists);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000830 Clause->setMapType(Type);
831 Clause->setMapLoc(TypeLoc);
832 return Clause;
833}
834
Michael Kruse4304e9d2019-02-19 16:38:20 +0000835OMPMapClause *
836OMPMapClause::CreateEmpty(const ASTContext &C,
837 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao90927002016-04-26 14:54:23 +0000838 void *Mem = C.Allocate(
839 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
840 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000841 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
842 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
843 Sizes.NumComponents));
844 return new (Mem) OMPMapClause(Sizes);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000845}
Samuel Antao661c0902016-05-26 17:39:58 +0000846
Michael Kruse01f670d2019-02-22 22:29:42 +0000847OMPToClause *OMPToClause::Create(
848 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
849 ArrayRef<ValueDecl *> Declarations,
850 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
851 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000852 OMPMappableExprListSizeTy Sizes;
853 Sizes.NumVars = Vars.size();
854 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
855 Sizes.NumComponentLists = ComponentLists.size();
856 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao661c0902016-05-26 17:39:58 +0000857
858 // We need to allocate:
Michael Kruse01f670d2019-02-22 22:29:42 +0000859 // 2 x NumVars x Expr* - we have an original list expression and an associated
860 // user-defined mapper for each clause list entry.
Samuel Antao661c0902016-05-26 17:39:58 +0000861 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
862 // with each component list.
863 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
864 // number of lists for each unique declaration and the size of each component
865 // list.
866 // NumComponents x MappableComponent - the total of all the components in all
867 // the lists.
868 void *Mem = C.Allocate(
869 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
870 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +0000871 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000872 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
873 Sizes.NumComponents));
Samuel Antao661c0902016-05-26 17:39:58 +0000874
Michael Kruse01f670d2019-02-22 22:29:42 +0000875 auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +0000876
877 Clause->setVarRefs(Vars);
Michael Kruse01f670d2019-02-22 22:29:42 +0000878 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao661c0902016-05-26 17:39:58 +0000879 Clause->setClauseInfo(Declarations, ComponentLists);
880 return Clause;
881}
882
Michael Kruse4304e9d2019-02-19 16:38:20 +0000883OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
884 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao661c0902016-05-26 17:39:58 +0000885 void *Mem = C.Allocate(
886 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
887 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +0000888 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000889 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
890 Sizes.NumComponents));
891 return new (Mem) OMPToClause(Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +0000892}
Samuel Antaoec172c62016-05-26 17:49:04 +0000893
Michael Kruse0336c752019-02-25 20:34:15 +0000894OMPFromClause *OMPFromClause::Create(
895 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
896 ArrayRef<ValueDecl *> Declarations,
897 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
898 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000899 OMPMappableExprListSizeTy Sizes;
900 Sizes.NumVars = Vars.size();
901 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
902 Sizes.NumComponentLists = ComponentLists.size();
903 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaoec172c62016-05-26 17:49:04 +0000904
905 // We need to allocate:
Michael Kruse0336c752019-02-25 20:34:15 +0000906 // 2 x NumVars x Expr* - we have an original list expression and an associated
907 // user-defined mapper for each clause list entry.
Samuel Antaoec172c62016-05-26 17:49:04 +0000908 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
909 // with each component list.
910 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
911 // number of lists for each unique declaration and the size of each component
912 // list.
913 // NumComponents x MappableComponent - the total of all the components in all
914 // the lists.
915 void *Mem = C.Allocate(
916 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
917 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +0000918 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000919 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
920 Sizes.NumComponents));
Samuel Antaoec172c62016-05-26 17:49:04 +0000921
Michael Kruse0336c752019-02-25 20:34:15 +0000922 auto *Clause =
923 new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +0000924
925 Clause->setVarRefs(Vars);
Michael Kruse0336c752019-02-25 20:34:15 +0000926 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antaoec172c62016-05-26 17:49:04 +0000927 Clause->setClauseInfo(Declarations, ComponentLists);
928 return Clause;
929}
930
Michael Kruse4304e9d2019-02-19 16:38:20 +0000931OMPFromClause *
932OMPFromClause::CreateEmpty(const ASTContext &C,
933 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaoec172c62016-05-26 17:49:04 +0000934 void *Mem = C.Allocate(
935 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
936 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +0000937 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000938 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
939 Sizes.NumComponents));
940 return new (Mem) OMPFromClause(Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +0000941}
Carlo Bertolli2404b172016-07-13 15:37:16 +0000942
Samuel Antaocc10b852016-07-28 14:23:26 +0000943void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
944 assert(VL.size() == varlist_size() &&
945 "Number of private copies is not the same as the preallocated buffer");
946 std::copy(VL.begin(), VL.end(), varlist_end());
947}
948
949void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
950 assert(VL.size() == varlist_size() &&
951 "Number of inits is not the same as the preallocated buffer");
952 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
953}
954
955OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000956 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
957 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
958 ArrayRef<ValueDecl *> Declarations,
Samuel Antaocc10b852016-07-28 14:23:26 +0000959 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000960 OMPMappableExprListSizeTy Sizes;
961 Sizes.NumVars = Vars.size();
962 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
963 Sizes.NumComponentLists = ComponentLists.size();
964 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaocc10b852016-07-28 14:23:26 +0000965
966 // We need to allocate:
967 // 3 x NumVars x Expr* - we have an original list expression for each clause
968 // list entry and an equal number of private copies and inits.
969 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
970 // with each component list.
971 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
972 // number of lists for each unique declaration and the size of each component
973 // list.
974 // NumComponents x MappableComponent - the total of all the components in all
975 // the lists.
976 void *Mem = C.Allocate(
977 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
978 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000979 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
980 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
981 Sizes.NumComponents));
Samuel Antaocc10b852016-07-28 14:23:26 +0000982
Michael Kruse4304e9d2019-02-19 16:38:20 +0000983 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
Samuel Antaocc10b852016-07-28 14:23:26 +0000984
985 Clause->setVarRefs(Vars);
986 Clause->setPrivateCopies(PrivateVars);
987 Clause->setInits(Inits);
988 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli2404b172016-07-13 15:37:16 +0000989 return Clause;
990}
991
Michael Kruse4304e9d2019-02-19 16:38:20 +0000992OMPUseDevicePtrClause *
993OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
994 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaocc10b852016-07-28 14:23:26 +0000995 void *Mem = C.Allocate(
996 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
997 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000998 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
999 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1000 Sizes.NumComponents));
1001 return new (Mem) OMPUseDevicePtrClause(Sizes);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001002}
Carlo Bertolli70594e92016-07-13 17:16:49 +00001003
Samuel Antao6890b092016-07-28 14:25:09 +00001004OMPIsDevicePtrClause *
Michael Kruse4304e9d2019-02-19 16:38:20 +00001005OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
Samuel Antao6890b092016-07-28 14:25:09 +00001006 ArrayRef<Expr *> Vars,
1007 ArrayRef<ValueDecl *> Declarations,
1008 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001009 OMPMappableExprListSizeTy Sizes;
1010 Sizes.NumVars = Vars.size();
1011 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1012 Sizes.NumComponentLists = ComponentLists.size();
1013 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao6890b092016-07-28 14:25:09 +00001014
1015 // We need to allocate:
1016 // NumVars x Expr* - we have an original list expression for each clause list
1017 // entry.
1018 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1019 // with each component list.
1020 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1021 // number of lists for each unique declaration and the size of each component
1022 // list.
1023 // NumComponents x MappableComponent - the total of all the components in all
1024 // the lists.
1025 void *Mem = C.Allocate(
1026 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1027 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001028 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1029 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1030 Sizes.NumComponents));
Samuel Antao6890b092016-07-28 14:25:09 +00001031
Michael Kruse4304e9d2019-02-19 16:38:20 +00001032 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
Samuel Antao6890b092016-07-28 14:25:09 +00001033
1034 Clause->setVarRefs(Vars);
1035 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001036 return Clause;
1037}
1038
Michael Kruse4304e9d2019-02-19 16:38:20 +00001039OMPIsDevicePtrClause *
1040OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1041 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao6890b092016-07-28 14:25:09 +00001042 void *Mem = C.Allocate(
1043 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1044 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001045 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1046 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1047 Sizes.NumComponents));
1048 return new (Mem) OMPIsDevicePtrClause(Sizes);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001049}
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001050
1051//===----------------------------------------------------------------------===//
1052// OpenMP clauses printing methods
1053//===----------------------------------------------------------------------===//
1054
1055void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1056 OS << "if(";
1057 if (Node->getNameModifier() != OMPD_unknown)
1058 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1059 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1060 OS << ")";
1061}
1062
1063void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1064 OS << "final(";
1065 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1066 OS << ")";
1067}
1068
1069void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1070 OS << "num_threads(";
1071 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1072 OS << ")";
1073}
1074
1075void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1076 OS << "safelen(";
1077 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1078 OS << ")";
1079}
1080
1081void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1082 OS << "simdlen(";
1083 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1084 OS << ")";
1085}
1086
1087void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1088 OS << "collapse(";
1089 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1090 OS << ")";
1091}
1092
1093void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1094 OS << "default("
1095 << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
1096 << ")";
1097}
1098
1099void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1100 OS << "proc_bind("
1101 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, Node->getProcBindKind())
1102 << ")";
1103}
1104
1105void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1106 OS << "unified_address";
1107}
1108
1109void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1110 OMPUnifiedSharedMemoryClause *) {
1111 OS << "unified_shared_memory";
1112}
1113
1114void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1115 OS << "reverse_offload";
1116}
1117
1118void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1119 OMPDynamicAllocatorsClause *) {
1120 OS << "dynamic_allocators";
1121}
1122
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00001123void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1124 OMPAtomicDefaultMemOrderClause *Node) {
1125 OS << "atomic_default_mem_order("
1126 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1127 Node->getAtomicDefaultMemOrderKind())
1128 << ")";
1129}
1130
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001131void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1132 OS << "schedule(";
1133 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1134 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1135 Node->getFirstScheduleModifier());
1136 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1137 OS << ", ";
1138 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1139 Node->getSecondScheduleModifier());
1140 }
1141 OS << ": ";
1142 }
1143 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1144 if (auto *E = Node->getChunkSize()) {
1145 OS << ", ";
1146 E->printPretty(OS, nullptr, Policy);
1147 }
1148 OS << ")";
1149}
1150
1151void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1152 OS << "ordered";
1153 if (auto *Num = Node->getNumForLoops()) {
1154 OS << "(";
1155 Num->printPretty(OS, nullptr, Policy, 0);
1156 OS << ")";
1157 }
1158}
1159
1160void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1161 OS << "nowait";
1162}
1163
1164void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1165 OS << "untied";
1166}
1167
1168void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1169 OS << "nogroup";
1170}
1171
1172void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1173 OS << "mergeable";
1174}
1175
1176void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1177
1178void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1179
1180void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
1181 OS << "update";
1182}
1183
1184void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1185 OS << "capture";
1186}
1187
1188void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1189 OS << "seq_cst";
1190}
1191
1192void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1193 OS << "threads";
1194}
1195
1196void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1197
1198void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1199 OS << "device(";
1200 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1201 OS << ")";
1202}
1203
1204void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1205 OS << "num_teams(";
1206 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1207 OS << ")";
1208}
1209
1210void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1211 OS << "thread_limit(";
1212 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1213 OS << ")";
1214}
1215
1216void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1217 OS << "priority(";
1218 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1219 OS << ")";
1220}
1221
1222void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1223 OS << "grainsize(";
1224 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1225 OS << ")";
1226}
1227
1228void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1229 OS << "num_tasks(";
1230 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1231 OS << ")";
1232}
1233
1234void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1235 OS << "hint(";
1236 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1237 OS << ")";
1238}
1239
1240template<typename T>
1241void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1242 for (typename T::varlist_iterator I = Node->varlist_begin(),
1243 E = Node->varlist_end();
1244 I != E; ++I) {
1245 assert(*I && "Expected non-null Stmt");
1246 OS << (I == Node->varlist_begin() ? StartSym : ',');
1247 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1248 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1249 DRE->printPretty(OS, nullptr, Policy, 0);
1250 else
1251 DRE->getDecl()->printQualifiedName(OS);
1252 } else
1253 (*I)->printPretty(OS, nullptr, Policy, 0);
1254 }
1255}
1256
1257void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1258 if (!Node->varlist_empty()) {
1259 OS << "private";
1260 VisitOMPClauseList(Node, '(');
1261 OS << ")";
1262 }
1263}
1264
1265void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1266 if (!Node->varlist_empty()) {
1267 OS << "firstprivate";
1268 VisitOMPClauseList(Node, '(');
1269 OS << ")";
1270 }
1271}
1272
1273void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1274 if (!Node->varlist_empty()) {
1275 OS << "lastprivate";
1276 VisitOMPClauseList(Node, '(');
1277 OS << ")";
1278 }
1279}
1280
1281void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1282 if (!Node->varlist_empty()) {
1283 OS << "shared";
1284 VisitOMPClauseList(Node, '(');
1285 OS << ")";
1286 }
1287}
1288
1289void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1290 if (!Node->varlist_empty()) {
1291 OS << "reduction(";
1292 NestedNameSpecifier *QualifierLoc =
1293 Node->getQualifierLoc().getNestedNameSpecifier();
1294 OverloadedOperatorKind OOK =
1295 Node->getNameInfo().getName().getCXXOverloadedOperator();
1296 if (QualifierLoc == nullptr && OOK != OO_None) {
1297 // Print reduction identifier in C format
1298 OS << getOperatorSpelling(OOK);
1299 } else {
1300 // Use C++ format
1301 if (QualifierLoc != nullptr)
1302 QualifierLoc->print(OS, Policy);
1303 OS << Node->getNameInfo();
1304 }
1305 OS << ":";
1306 VisitOMPClauseList(Node, ' ');
1307 OS << ")";
1308 }
1309}
1310
1311void OMPClausePrinter::VisitOMPTaskReductionClause(
1312 OMPTaskReductionClause *Node) {
1313 if (!Node->varlist_empty()) {
1314 OS << "task_reduction(";
1315 NestedNameSpecifier *QualifierLoc =
1316 Node->getQualifierLoc().getNestedNameSpecifier();
1317 OverloadedOperatorKind OOK =
1318 Node->getNameInfo().getName().getCXXOverloadedOperator();
1319 if (QualifierLoc == nullptr && OOK != OO_None) {
1320 // Print reduction identifier in C format
1321 OS << getOperatorSpelling(OOK);
1322 } else {
1323 // Use C++ format
1324 if (QualifierLoc != nullptr)
1325 QualifierLoc->print(OS, Policy);
1326 OS << Node->getNameInfo();
1327 }
1328 OS << ":";
1329 VisitOMPClauseList(Node, ' ');
1330 OS << ")";
1331 }
1332}
1333
1334void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1335 if (!Node->varlist_empty()) {
1336 OS << "in_reduction(";
1337 NestedNameSpecifier *QualifierLoc =
1338 Node->getQualifierLoc().getNestedNameSpecifier();
1339 OverloadedOperatorKind OOK =
1340 Node->getNameInfo().getName().getCXXOverloadedOperator();
1341 if (QualifierLoc == nullptr && OOK != OO_None) {
1342 // Print reduction identifier in C format
1343 OS << getOperatorSpelling(OOK);
1344 } else {
1345 // Use C++ format
1346 if (QualifierLoc != nullptr)
1347 QualifierLoc->print(OS, Policy);
1348 OS << Node->getNameInfo();
1349 }
1350 OS << ":";
1351 VisitOMPClauseList(Node, ' ');
1352 OS << ")";
1353 }
1354}
1355
1356void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1357 if (!Node->varlist_empty()) {
1358 OS << "linear";
1359 if (Node->getModifierLoc().isValid()) {
1360 OS << '('
1361 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1362 }
1363 VisitOMPClauseList(Node, '(');
1364 if (Node->getModifierLoc().isValid())
1365 OS << ')';
1366 if (Node->getStep() != nullptr) {
1367 OS << ": ";
1368 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1369 }
1370 OS << ")";
1371 }
1372}
1373
1374void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1375 if (!Node->varlist_empty()) {
1376 OS << "aligned";
1377 VisitOMPClauseList(Node, '(');
1378 if (Node->getAlignment() != nullptr) {
1379 OS << ": ";
1380 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1381 }
1382 OS << ")";
1383 }
1384}
1385
1386void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1387 if (!Node->varlist_empty()) {
1388 OS << "copyin";
1389 VisitOMPClauseList(Node, '(');
1390 OS << ")";
1391 }
1392}
1393
1394void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1395 if (!Node->varlist_empty()) {
1396 OS << "copyprivate";
1397 VisitOMPClauseList(Node, '(');
1398 OS << ")";
1399 }
1400}
1401
1402void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1403 if (!Node->varlist_empty()) {
1404 VisitOMPClauseList(Node, '(');
1405 OS << ")";
1406 }
1407}
1408
1409void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1410 OS << "depend(";
1411 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1412 Node->getDependencyKind());
1413 if (!Node->varlist_empty()) {
1414 OS << " :";
1415 VisitOMPClauseList(Node, ' ');
1416 }
1417 OS << ")";
1418}
1419
1420void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1421 if (!Node->varlist_empty()) {
1422 OS << "map(";
1423 if (Node->getMapType() != OMPC_MAP_unknown) {
Kelvin Lief579432018-12-18 22:18:41 +00001424 for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1425 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1426 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1427 Node->getMapTypeModifier(I));
Michael Kruse4304e9d2019-02-19 16:38:20 +00001428 if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1429 OS << '(';
1430 NestedNameSpecifier *MapperNNS =
1431 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1432 if (MapperNNS)
1433 MapperNNS->print(OS, Policy);
1434 OS << Node->getMapperIdInfo() << ')';
1435 }
Kelvin Lief579432018-12-18 22:18:41 +00001436 OS << ',';
1437 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001438 }
1439 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1440 OS << ':';
1441 }
1442 VisitOMPClauseList(Node, ' ');
1443 OS << ")";
1444 }
1445}
1446
1447void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1448 if (!Node->varlist_empty()) {
1449 OS << "to";
Michael Kruse01f670d2019-02-22 22:29:42 +00001450 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1451 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1452 OS << '(';
1453 OS << "mapper(";
1454 NestedNameSpecifier *MapperNNS =
1455 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1456 if (MapperNNS)
1457 MapperNNS->print(OS, Policy);
1458 OS << MapperId << "):";
1459 VisitOMPClauseList(Node, ' ');
1460 } else {
1461 VisitOMPClauseList(Node, '(');
1462 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001463 OS << ")";
1464 }
1465}
1466
1467void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1468 if (!Node->varlist_empty()) {
1469 OS << "from";
Michael Kruse0336c752019-02-25 20:34:15 +00001470 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1471 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1472 OS << '(';
1473 OS << "mapper(";
1474 NestedNameSpecifier *MapperNNS =
1475 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1476 if (MapperNNS)
1477 MapperNNS->print(OS, Policy);
1478 OS << MapperId << "):";
1479 VisitOMPClauseList(Node, ' ');
1480 } else {
1481 VisitOMPClauseList(Node, '(');
1482 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001483 OS << ")";
1484 }
1485}
1486
1487void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1488 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1489 OMPC_dist_schedule, Node->getDistScheduleKind());
1490 if (auto *E = Node->getChunkSize()) {
1491 OS << ", ";
1492 E->printPretty(OS, nullptr, Policy);
1493 }
1494 OS << ")";
1495}
1496
1497void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1498 OS << "defaultmap(";
1499 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1500 Node->getDefaultmapModifier());
1501 OS << ": ";
1502 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1503 Node->getDefaultmapKind());
1504 OS << ")";
1505}
1506
1507void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1508 if (!Node->varlist_empty()) {
1509 OS << "use_device_ptr";
1510 VisitOMPClauseList(Node, '(');
1511 OS << ")";
1512 }
1513}
1514
1515void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1516 if (!Node->varlist_empty()) {
1517 OS << "is_device_ptr";
1518 VisitOMPClauseList(Node, '(');
1519 OS << ")";
1520 }
1521}
1522