blob: e87ae3e158c7a4512b1d7c7a4ae9688586ed3a59 [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
793OMPMapClause *
794OMPMapClause::Create(const ASTContext &C, SourceLocation StartLoc,
795 SourceLocation LParenLoc, SourceLocation EndLoc,
796 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
797 MappableExprComponentListsRef ComponentLists,
Kelvin Lief579432018-12-18 22:18:41 +0000798 ArrayRef<OpenMPMapModifierKind> MapModifiers,
799 ArrayRef<SourceLocation> MapModifiersLoc,
800 OpenMPMapClauseKind Type, bool TypeIsImplicit,
801 SourceLocation TypeLoc) {
Samuel Antao90927002016-04-26 14:54:23 +0000802 unsigned NumVars = Vars.size();
803 unsigned NumUniqueDeclarations =
804 getUniqueDeclarationsTotalNumber(Declarations);
805 unsigned NumComponentLists = ComponentLists.size();
806 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
807
808 // We need to allocate:
809 // NumVars x Expr* - we have an original list expression for each clause list
810 // entry.
811 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
812 // with each component list.
813 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
814 // number of lists for each unique declaration and the size of each component
815 // list.
816 // NumComponents x MappableComponent - the total of all the components in all
817 // the lists.
818 void *Mem = C.Allocate(
819 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
820 OMPClauseMappableExprCommon::MappableComponent>(
821 NumVars, NumUniqueDeclarations,
822 NumUniqueDeclarations + NumComponentLists, NumComponents));
823 OMPMapClause *Clause = new (Mem) OMPMapClause(
Kelvin Lief579432018-12-18 22:18:41 +0000824 MapModifiers, MapModifiersLoc, Type, TypeIsImplicit, TypeLoc, StartLoc,
825 LParenLoc, EndLoc, NumVars, NumUniqueDeclarations, NumComponentLists,
826 NumComponents);
Samuel Antao90927002016-04-26 14:54:23 +0000827
828 Clause->setVarRefs(Vars);
829 Clause->setClauseInfo(Declarations, ComponentLists);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000830 Clause->setMapType(Type);
831 Clause->setMapLoc(TypeLoc);
832 return Clause;
833}
834
Samuel Antao90927002016-04-26 14:54:23 +0000835OMPMapClause *OMPMapClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
836 unsigned NumUniqueDeclarations,
837 unsigned NumComponentLists,
838 unsigned NumComponents) {
839 void *Mem = C.Allocate(
840 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
841 OMPClauseMappableExprCommon::MappableComponent>(
842 NumVars, NumUniqueDeclarations,
843 NumUniqueDeclarations + NumComponentLists, NumComponents));
844 return new (Mem) OMPMapClause(NumVars, NumUniqueDeclarations,
845 NumComponentLists, NumComponents);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000846}
Samuel Antao661c0902016-05-26 17:39:58 +0000847
848OMPToClause *OMPToClause::Create(const ASTContext &C, SourceLocation StartLoc,
849 SourceLocation LParenLoc,
850 SourceLocation EndLoc, ArrayRef<Expr *> Vars,
851 ArrayRef<ValueDecl *> Declarations,
852 MappableExprComponentListsRef ComponentLists) {
853 unsigned NumVars = Vars.size();
854 unsigned NumUniqueDeclarations =
855 getUniqueDeclarationsTotalNumber(Declarations);
856 unsigned NumComponentLists = ComponentLists.size();
857 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
858
859 // We need to allocate:
860 // NumVars x Expr* - we have an original list expression for each clause list
861 // entry.
862 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
863 // with each component list.
864 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
865 // number of lists for each unique declaration and the size of each component
866 // list.
867 // NumComponents x MappableComponent - the total of all the components in all
868 // the lists.
869 void *Mem = C.Allocate(
870 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
871 OMPClauseMappableExprCommon::MappableComponent>(
872 NumVars, NumUniqueDeclarations,
873 NumUniqueDeclarations + NumComponentLists, NumComponents));
874
875 OMPToClause *Clause = new (Mem)
876 OMPToClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
877 NumComponentLists, NumComponents);
878
879 Clause->setVarRefs(Vars);
880 Clause->setClauseInfo(Declarations, ComponentLists);
881 return Clause;
882}
883
884OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
885 unsigned NumUniqueDeclarations,
886 unsigned NumComponentLists,
887 unsigned NumComponents) {
888 void *Mem = C.Allocate(
889 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
890 OMPClauseMappableExprCommon::MappableComponent>(
891 NumVars, NumUniqueDeclarations,
892 NumUniqueDeclarations + NumComponentLists, NumComponents));
893 return new (Mem) OMPToClause(NumVars, NumUniqueDeclarations,
894 NumComponentLists, NumComponents);
895}
Samuel Antaoec172c62016-05-26 17:49:04 +0000896
897OMPFromClause *
898OMPFromClause::Create(const ASTContext &C, SourceLocation StartLoc,
899 SourceLocation LParenLoc, SourceLocation EndLoc,
900 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
901 MappableExprComponentListsRef ComponentLists) {
902 unsigned NumVars = Vars.size();
903 unsigned NumUniqueDeclarations =
904 getUniqueDeclarationsTotalNumber(Declarations);
905 unsigned NumComponentLists = ComponentLists.size();
906 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
907
908 // We need to allocate:
909 // NumVars x Expr* - we have an original list expression for each clause list
910 // entry.
911 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
912 // with each component list.
913 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
914 // number of lists for each unique declaration and the size of each component
915 // list.
916 // NumComponents x MappableComponent - the total of all the components in all
917 // the lists.
918 void *Mem = C.Allocate(
919 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
920 OMPClauseMappableExprCommon::MappableComponent>(
921 NumVars, NumUniqueDeclarations,
922 NumUniqueDeclarations + NumComponentLists, NumComponents));
923
924 OMPFromClause *Clause = new (Mem)
925 OMPFromClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
926 NumComponentLists, NumComponents);
927
928 Clause->setVarRefs(Vars);
929 Clause->setClauseInfo(Declarations, ComponentLists);
930 return Clause;
931}
932
933OMPFromClause *OMPFromClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
934 unsigned NumUniqueDeclarations,
935 unsigned NumComponentLists,
936 unsigned NumComponents) {
937 void *Mem = C.Allocate(
938 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
939 OMPClauseMappableExprCommon::MappableComponent>(
940 NumVars, NumUniqueDeclarations,
941 NumUniqueDeclarations + NumComponentLists, NumComponents));
942 return new (Mem) OMPFromClause(NumVars, NumUniqueDeclarations,
943 NumComponentLists, NumComponents);
944}
Carlo Bertolli2404b172016-07-13 15:37:16 +0000945
Samuel Antaocc10b852016-07-28 14:23:26 +0000946void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
947 assert(VL.size() == varlist_size() &&
948 "Number of private copies is not the same as the preallocated buffer");
949 std::copy(VL.begin(), VL.end(), varlist_end());
950}
951
952void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
953 assert(VL.size() == varlist_size() &&
954 "Number of inits is not the same as the preallocated buffer");
955 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
956}
957
958OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
959 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
960 SourceLocation EndLoc, ArrayRef<Expr *> Vars, ArrayRef<Expr *> PrivateVars,
961 ArrayRef<Expr *> Inits, ArrayRef<ValueDecl *> Declarations,
962 MappableExprComponentListsRef ComponentLists) {
963 unsigned NumVars = Vars.size();
964 unsigned NumUniqueDeclarations =
965 getUniqueDeclarationsTotalNumber(Declarations);
966 unsigned NumComponentLists = ComponentLists.size();
967 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
968
969 // We need to allocate:
970 // 3 x NumVars x Expr* - we have an original list expression for each clause
971 // list entry and an equal number of private copies and inits.
972 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
973 // with each component list.
974 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
975 // number of lists for each unique declaration and the size of each component
976 // list.
977 // NumComponents x MappableComponent - the total of all the components in all
978 // the lists.
979 void *Mem = C.Allocate(
980 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
981 OMPClauseMappableExprCommon::MappableComponent>(
982 3 * NumVars, NumUniqueDeclarations,
983 NumUniqueDeclarations + NumComponentLists, NumComponents));
984
985 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(
986 StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
987 NumComponentLists, NumComponents);
988
989 Clause->setVarRefs(Vars);
990 Clause->setPrivateCopies(PrivateVars);
991 Clause->setInits(Inits);
992 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli2404b172016-07-13 15:37:16 +0000993 return Clause;
994}
995
Samuel Antaocc10b852016-07-28 14:23:26 +0000996OMPUseDevicePtrClause *OMPUseDevicePtrClause::CreateEmpty(
997 const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations,
998 unsigned NumComponentLists, unsigned NumComponents) {
999 void *Mem = C.Allocate(
1000 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1001 OMPClauseMappableExprCommon::MappableComponent>(
1002 3 * NumVars, NumUniqueDeclarations,
1003 NumUniqueDeclarations + NumComponentLists, NumComponents));
1004 return new (Mem) OMPUseDevicePtrClause(NumVars, NumUniqueDeclarations,
1005 NumComponentLists, NumComponents);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001006}
Carlo Bertolli70594e92016-07-13 17:16:49 +00001007
Samuel Antao6890b092016-07-28 14:25:09 +00001008OMPIsDevicePtrClause *
1009OMPIsDevicePtrClause::Create(const ASTContext &C, SourceLocation StartLoc,
1010 SourceLocation LParenLoc, SourceLocation EndLoc,
1011 ArrayRef<Expr *> Vars,
1012 ArrayRef<ValueDecl *> Declarations,
1013 MappableExprComponentListsRef ComponentLists) {
1014 unsigned NumVars = Vars.size();
1015 unsigned NumUniqueDeclarations =
1016 getUniqueDeclarationsTotalNumber(Declarations);
1017 unsigned NumComponentLists = ComponentLists.size();
1018 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
1019
1020 // We need to allocate:
1021 // NumVars x Expr* - we have an original list expression for each clause list
1022 // entry.
1023 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1024 // with each component list.
1025 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1026 // number of lists for each unique declaration and the size of each component
1027 // list.
1028 // NumComponents x MappableComponent - the total of all the components in all
1029 // the lists.
1030 void *Mem = C.Allocate(
1031 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1032 OMPClauseMappableExprCommon::MappableComponent>(
1033 NumVars, NumUniqueDeclarations,
1034 NumUniqueDeclarations + NumComponentLists, NumComponents));
1035
1036 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(
1037 StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
1038 NumComponentLists, NumComponents);
1039
1040 Clause->setVarRefs(Vars);
1041 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001042 return Clause;
1043}
1044
Samuel Antao6890b092016-07-28 14:25:09 +00001045OMPIsDevicePtrClause *OMPIsDevicePtrClause::CreateEmpty(
1046 const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations,
1047 unsigned NumComponentLists, unsigned NumComponents) {
1048 void *Mem = C.Allocate(
1049 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1050 OMPClauseMappableExprCommon::MappableComponent>(
1051 NumVars, NumUniqueDeclarations,
1052 NumUniqueDeclarations + NumComponentLists, NumComponents));
1053 return new (Mem) OMPIsDevicePtrClause(NumVars, NumUniqueDeclarations,
1054 NumComponentLists, NumComponents);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001055}
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001056
1057//===----------------------------------------------------------------------===//
1058// OpenMP clauses printing methods
1059//===----------------------------------------------------------------------===//
1060
1061void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1062 OS << "if(";
1063 if (Node->getNameModifier() != OMPD_unknown)
1064 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1065 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1066 OS << ")";
1067}
1068
1069void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1070 OS << "final(";
1071 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1072 OS << ")";
1073}
1074
1075void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1076 OS << "num_threads(";
1077 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1078 OS << ")";
1079}
1080
1081void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1082 OS << "safelen(";
1083 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1084 OS << ")";
1085}
1086
1087void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1088 OS << "simdlen(";
1089 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1090 OS << ")";
1091}
1092
1093void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1094 OS << "collapse(";
1095 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1096 OS << ")";
1097}
1098
1099void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1100 OS << "default("
1101 << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
1102 << ")";
1103}
1104
1105void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1106 OS << "proc_bind("
1107 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, Node->getProcBindKind())
1108 << ")";
1109}
1110
1111void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1112 OS << "unified_address";
1113}
1114
1115void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1116 OMPUnifiedSharedMemoryClause *) {
1117 OS << "unified_shared_memory";
1118}
1119
1120void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1121 OS << "reverse_offload";
1122}
1123
1124void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1125 OMPDynamicAllocatorsClause *) {
1126 OS << "dynamic_allocators";
1127}
1128
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00001129void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1130 OMPAtomicDefaultMemOrderClause *Node) {
1131 OS << "atomic_default_mem_order("
1132 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1133 Node->getAtomicDefaultMemOrderKind())
1134 << ")";
1135}
1136
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001137void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1138 OS << "schedule(";
1139 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1140 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1141 Node->getFirstScheduleModifier());
1142 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1143 OS << ", ";
1144 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1145 Node->getSecondScheduleModifier());
1146 }
1147 OS << ": ";
1148 }
1149 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1150 if (auto *E = Node->getChunkSize()) {
1151 OS << ", ";
1152 E->printPretty(OS, nullptr, Policy);
1153 }
1154 OS << ")";
1155}
1156
1157void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1158 OS << "ordered";
1159 if (auto *Num = Node->getNumForLoops()) {
1160 OS << "(";
1161 Num->printPretty(OS, nullptr, Policy, 0);
1162 OS << ")";
1163 }
1164}
1165
1166void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1167 OS << "nowait";
1168}
1169
1170void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1171 OS << "untied";
1172}
1173
1174void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1175 OS << "nogroup";
1176}
1177
1178void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1179 OS << "mergeable";
1180}
1181
1182void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1183
1184void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1185
1186void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
1187 OS << "update";
1188}
1189
1190void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1191 OS << "capture";
1192}
1193
1194void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1195 OS << "seq_cst";
1196}
1197
1198void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1199 OS << "threads";
1200}
1201
1202void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1203
1204void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1205 OS << "device(";
1206 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1207 OS << ")";
1208}
1209
1210void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1211 OS << "num_teams(";
1212 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1213 OS << ")";
1214}
1215
1216void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1217 OS << "thread_limit(";
1218 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1219 OS << ")";
1220}
1221
1222void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1223 OS << "priority(";
1224 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1225 OS << ")";
1226}
1227
1228void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1229 OS << "grainsize(";
1230 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1231 OS << ")";
1232}
1233
1234void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1235 OS << "num_tasks(";
1236 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1237 OS << ")";
1238}
1239
1240void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1241 OS << "hint(";
1242 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1243 OS << ")";
1244}
1245
1246template<typename T>
1247void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1248 for (typename T::varlist_iterator I = Node->varlist_begin(),
1249 E = Node->varlist_end();
1250 I != E; ++I) {
1251 assert(*I && "Expected non-null Stmt");
1252 OS << (I == Node->varlist_begin() ? StartSym : ',');
1253 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1254 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1255 DRE->printPretty(OS, nullptr, Policy, 0);
1256 else
1257 DRE->getDecl()->printQualifiedName(OS);
1258 } else
1259 (*I)->printPretty(OS, nullptr, Policy, 0);
1260 }
1261}
1262
1263void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1264 if (!Node->varlist_empty()) {
1265 OS << "private";
1266 VisitOMPClauseList(Node, '(');
1267 OS << ")";
1268 }
1269}
1270
1271void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1272 if (!Node->varlist_empty()) {
1273 OS << "firstprivate";
1274 VisitOMPClauseList(Node, '(');
1275 OS << ")";
1276 }
1277}
1278
1279void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1280 if (!Node->varlist_empty()) {
1281 OS << "lastprivate";
1282 VisitOMPClauseList(Node, '(');
1283 OS << ")";
1284 }
1285}
1286
1287void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1288 if (!Node->varlist_empty()) {
1289 OS << "shared";
1290 VisitOMPClauseList(Node, '(');
1291 OS << ")";
1292 }
1293}
1294
1295void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1296 if (!Node->varlist_empty()) {
1297 OS << "reduction(";
1298 NestedNameSpecifier *QualifierLoc =
1299 Node->getQualifierLoc().getNestedNameSpecifier();
1300 OverloadedOperatorKind OOK =
1301 Node->getNameInfo().getName().getCXXOverloadedOperator();
1302 if (QualifierLoc == nullptr && OOK != OO_None) {
1303 // Print reduction identifier in C format
1304 OS << getOperatorSpelling(OOK);
1305 } else {
1306 // Use C++ format
1307 if (QualifierLoc != nullptr)
1308 QualifierLoc->print(OS, Policy);
1309 OS << Node->getNameInfo();
1310 }
1311 OS << ":";
1312 VisitOMPClauseList(Node, ' ');
1313 OS << ")";
1314 }
1315}
1316
1317void OMPClausePrinter::VisitOMPTaskReductionClause(
1318 OMPTaskReductionClause *Node) {
1319 if (!Node->varlist_empty()) {
1320 OS << "task_reduction(";
1321 NestedNameSpecifier *QualifierLoc =
1322 Node->getQualifierLoc().getNestedNameSpecifier();
1323 OverloadedOperatorKind OOK =
1324 Node->getNameInfo().getName().getCXXOverloadedOperator();
1325 if (QualifierLoc == nullptr && OOK != OO_None) {
1326 // Print reduction identifier in C format
1327 OS << getOperatorSpelling(OOK);
1328 } else {
1329 // Use C++ format
1330 if (QualifierLoc != nullptr)
1331 QualifierLoc->print(OS, Policy);
1332 OS << Node->getNameInfo();
1333 }
1334 OS << ":";
1335 VisitOMPClauseList(Node, ' ');
1336 OS << ")";
1337 }
1338}
1339
1340void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1341 if (!Node->varlist_empty()) {
1342 OS << "in_reduction(";
1343 NestedNameSpecifier *QualifierLoc =
1344 Node->getQualifierLoc().getNestedNameSpecifier();
1345 OverloadedOperatorKind OOK =
1346 Node->getNameInfo().getName().getCXXOverloadedOperator();
1347 if (QualifierLoc == nullptr && OOK != OO_None) {
1348 // Print reduction identifier in C format
1349 OS << getOperatorSpelling(OOK);
1350 } else {
1351 // Use C++ format
1352 if (QualifierLoc != nullptr)
1353 QualifierLoc->print(OS, Policy);
1354 OS << Node->getNameInfo();
1355 }
1356 OS << ":";
1357 VisitOMPClauseList(Node, ' ');
1358 OS << ")";
1359 }
1360}
1361
1362void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1363 if (!Node->varlist_empty()) {
1364 OS << "linear";
1365 if (Node->getModifierLoc().isValid()) {
1366 OS << '('
1367 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1368 }
1369 VisitOMPClauseList(Node, '(');
1370 if (Node->getModifierLoc().isValid())
1371 OS << ')';
1372 if (Node->getStep() != nullptr) {
1373 OS << ": ";
1374 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1375 }
1376 OS << ")";
1377 }
1378}
1379
1380void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1381 if (!Node->varlist_empty()) {
1382 OS << "aligned";
1383 VisitOMPClauseList(Node, '(');
1384 if (Node->getAlignment() != nullptr) {
1385 OS << ": ";
1386 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1387 }
1388 OS << ")";
1389 }
1390}
1391
1392void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1393 if (!Node->varlist_empty()) {
1394 OS << "copyin";
1395 VisitOMPClauseList(Node, '(');
1396 OS << ")";
1397 }
1398}
1399
1400void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1401 if (!Node->varlist_empty()) {
1402 OS << "copyprivate";
1403 VisitOMPClauseList(Node, '(');
1404 OS << ")";
1405 }
1406}
1407
1408void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1409 if (!Node->varlist_empty()) {
1410 VisitOMPClauseList(Node, '(');
1411 OS << ")";
1412 }
1413}
1414
1415void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1416 OS << "depend(";
1417 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1418 Node->getDependencyKind());
1419 if (!Node->varlist_empty()) {
1420 OS << " :";
1421 VisitOMPClauseList(Node, ' ');
1422 }
1423 OS << ")";
1424}
1425
1426void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1427 if (!Node->varlist_empty()) {
1428 OS << "map(";
1429 if (Node->getMapType() != OMPC_MAP_unknown) {
Kelvin Lief579432018-12-18 22:18:41 +00001430 for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1431 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1432 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1433 Node->getMapTypeModifier(I));
1434 OS << ',';
1435 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001436 }
1437 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1438 OS << ':';
1439 }
1440 VisitOMPClauseList(Node, ' ');
1441 OS << ")";
1442 }
1443}
1444
1445void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1446 if (!Node->varlist_empty()) {
1447 OS << "to";
1448 VisitOMPClauseList(Node, '(');
1449 OS << ")";
1450 }
1451}
1452
1453void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1454 if (!Node->varlist_empty()) {
1455 OS << "from";
1456 VisitOMPClauseList(Node, '(');
1457 OS << ")";
1458 }
1459}
1460
1461void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1462 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1463 OMPC_dist_schedule, Node->getDistScheduleKind());
1464 if (auto *E = Node->getChunkSize()) {
1465 OS << ", ";
1466 E->printPretty(OS, nullptr, Policy);
1467 }
1468 OS << ")";
1469}
1470
1471void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1472 OS << "defaultmap(";
1473 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1474 Node->getDefaultmapModifier());
1475 OS << ": ";
1476 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1477 Node->getDefaultmapKind());
1478 OS << ")";
1479}
1480
1481void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1482 if (!Node->varlist_empty()) {
1483 OS << "use_device_ptr";
1484 VisitOMPClauseList(Node, '(');
1485 OS << ")";
1486 }
1487}
1488
1489void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1490 if (!Node->varlist_empty()) {
1491 OS << "is_device_ptr";
1492 VisitOMPClauseList(Node, '(');
1493 OS << ")";
1494 }
1495}
1496