blob: 5ee10fb2a11e6bc849155438a61d841d6f24cce2 [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:
Alexey Bataev9cc10fc2019-03-12 18:52:33 +000076 case OMPC_allocator:
Alexey Bataev3392d762016-02-16 11:18:12 +000077 case OMPC_collapse:
78 case OMPC_private:
Alexey Bataev005248a2016-02-25 05:25:57 +000079 case OMPC_shared:
Alexey Bataev005248a2016-02-25 05:25:57 +000080 case OMPC_aligned:
81 case OMPC_copyin:
82 case OMPC_copyprivate:
83 case OMPC_ordered:
84 case OMPC_nowait:
85 case OMPC_untied:
86 case OMPC_mergeable:
87 case OMPC_threadprivate:
Alexey Bataev25ed0c02019-03-07 17:54:44 +000088 case OMPC_allocate:
Alexey Bataev005248a2016-02-25 05:25:57 +000089 case OMPC_flush:
90 case OMPC_read:
91 case OMPC_write:
92 case OMPC_update:
93 case OMPC_capture:
94 case OMPC_seq_cst:
95 case OMPC_depend:
Alexey Bataev005248a2016-02-25 05:25:57 +000096 case OMPC_threads:
97 case OMPC_simd:
98 case OMPC_map:
Alexey Bataev005248a2016-02-25 05:25:57 +000099 case OMPC_priority:
100 case OMPC_grainsize:
101 case OMPC_nogroup:
102 case OMPC_num_tasks:
103 case OMPC_hint:
104 case OMPC_defaultmap:
105 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000106 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000107 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000108 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000109 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000110 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000111 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000112 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000113 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000114 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000115 case OMPC_atomic_default_mem_order:
Alexey Bataev005248a2016-02-25 05:25:57 +0000116 break;
117 }
118
119 return nullptr;
120}
121
122OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
123 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
124 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
125}
126
127const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
128 switch (C->getClauseKind()) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000129 case OMPC_lastprivate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000130 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000131 case OMPC_reduction:
132 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +0000133 case OMPC_task_reduction:
134 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000135 case OMPC_in_reduction:
136 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000137 case OMPC_linear:
138 return static_cast<const OMPLinearClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000139 case OMPC_schedule:
140 case OMPC_dist_schedule:
141 case OMPC_firstprivate:
142 case OMPC_default:
143 case OMPC_proc_bind:
144 case OMPC_if:
145 case OMPC_final:
146 case OMPC_num_threads:
147 case OMPC_safelen:
148 case OMPC_simdlen:
Alexey Bataev9cc10fc2019-03-12 18:52:33 +0000149 case OMPC_allocator:
Alexey Bataev005248a2016-02-25 05:25:57 +0000150 case OMPC_collapse:
151 case OMPC_private:
Alexey Bataev3392d762016-02-16 11:18:12 +0000152 case OMPC_shared:
Alexey Bataev3392d762016-02-16 11:18:12 +0000153 case OMPC_aligned:
154 case OMPC_copyin:
155 case OMPC_copyprivate:
156 case OMPC_ordered:
157 case OMPC_nowait:
158 case OMPC_untied:
159 case OMPC_mergeable:
160 case OMPC_threadprivate:
Alexey Bataev25ed0c02019-03-07 17:54:44 +0000161 case OMPC_allocate:
Alexey Bataev3392d762016-02-16 11:18:12 +0000162 case OMPC_flush:
163 case OMPC_read:
164 case OMPC_write:
165 case OMPC_update:
166 case OMPC_capture:
167 case OMPC_seq_cst:
168 case OMPC_depend:
169 case OMPC_device:
170 case OMPC_threads:
171 case OMPC_simd:
172 case OMPC_map:
173 case OMPC_num_teams:
174 case OMPC_thread_limit:
175 case OMPC_priority:
176 case OMPC_grainsize:
177 case OMPC_nogroup:
178 case OMPC_num_tasks:
179 case OMPC_hint:
180 case OMPC_defaultmap:
181 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000182 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000183 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000184 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000185 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000186 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000187 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000188 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000189 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000190 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000191 case OMPC_atomic_default_mem_order:
Alexey Bataev3392d762016-02-16 11:18:12 +0000192 break;
193 }
194
195 return nullptr;
196}
197
Alexey Bataevf138fda2018-08-13 19:04:24 +0000198OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
199 unsigned NumLoops,
200 SourceLocation StartLoc,
201 SourceLocation LParenLoc,
202 SourceLocation EndLoc) {
203 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
204 auto *Clause =
205 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
206 for (unsigned I = 0; I < NumLoops; ++I) {
207 Clause->setLoopNumIterations(I, nullptr);
208 Clause->setLoopCounter(I, nullptr);
209 }
210 return Clause;
211}
212
213OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
214 unsigned NumLoops) {
215 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
216 auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
217 for (unsigned I = 0; I < NumLoops; ++I) {
218 Clause->setLoopNumIterations(I, nullptr);
219 Clause->setLoopCounter(I, nullptr);
220 }
221 return Clause;
222}
223
224void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
225 Expr *NumIterations) {
226 assert(NumLoop < NumberOfLoops && "out of loops number.");
227 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
228}
229
230ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
231 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
232}
233
234void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
235 assert(NumLoop < NumberOfLoops && "out of loops number.");
236 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
237}
238
Mike Rice0ed46662018-09-20 17:19:41 +0000239Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000240 assert(NumLoop < NumberOfLoops && "out of loops number.");
241 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
242}
243
Mike Rice0ed46662018-09-20 17:19:41 +0000244const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000245 assert(NumLoop < NumberOfLoops && "out of loops number.");
246 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
247}
248
James Y Knightb8bfd962015-10-02 13:41:04 +0000249void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
250 assert(VL.size() == varlist_size() &&
251 "Number of private copies is not the same as the preallocated buffer");
252 std::copy(VL.begin(), VL.end(), varlist_end());
253}
254
255OMPPrivateClause *
256OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
257 SourceLocation LParenLoc, SourceLocation EndLoc,
258 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
259 // Allocate space for private variables and initializer expressions.
James Y Knight374fd202016-01-01 00:38:24 +0000260 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000261 OMPPrivateClause *Clause =
262 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
263 Clause->setVarRefs(VL);
264 Clause->setPrivateCopies(PrivateVL);
265 return Clause;
266}
267
268OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
269 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000270 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000271 return new (Mem) OMPPrivateClause(N);
272}
273
274void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
275 assert(VL.size() == varlist_size() &&
276 "Number of private copies is not the same as the preallocated buffer");
277 std::copy(VL.begin(), VL.end(), varlist_end());
278}
279
280void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
281 assert(VL.size() == varlist_size() &&
282 "Number of inits is not the same as the preallocated buffer");
283 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
284}
285
286OMPFirstprivateClause *
287OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
288 SourceLocation LParenLoc, SourceLocation EndLoc,
289 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
Alexey Bataev417089f2016-02-17 13:19:37 +0000290 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
James Y Knight374fd202016-01-01 00:38:24 +0000291 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000292 OMPFirstprivateClause *Clause =
293 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
294 Clause->setVarRefs(VL);
295 Clause->setPrivateCopies(PrivateVL);
296 Clause->setInits(InitVL);
Alexey Bataev417089f2016-02-17 13:19:37 +0000297 Clause->setPreInitStmt(PreInit);
James Y Knightb8bfd962015-10-02 13:41:04 +0000298 return Clause;
299}
300
301OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
302 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000303 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000304 return new (Mem) OMPFirstprivateClause(N);
305}
306
307void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
308 assert(PrivateCopies.size() == varlist_size() &&
309 "Number of private copies is not the same as the preallocated buffer");
310 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
311}
312
313void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
314 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
315 "not the same as the "
316 "preallocated buffer");
317 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
318}
319
320void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
321 assert(DstExprs.size() == varlist_size() && "Number of destination "
322 "expressions is not the same as "
323 "the preallocated buffer");
324 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
325}
326
327void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
328 assert(AssignmentOps.size() == varlist_size() &&
329 "Number of assignment expressions is not the same as the preallocated "
330 "buffer");
331 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
332 getDestinationExprs().end());
333}
334
335OMPLastprivateClause *OMPLastprivateClause::Create(
336 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
337 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
Alexey Bataev005248a2016-02-25 05:25:57 +0000338 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit,
339 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000340 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000341 OMPLastprivateClause *Clause =
342 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
343 Clause->setVarRefs(VL);
344 Clause->setSourceExprs(SrcExprs);
345 Clause->setDestinationExprs(DstExprs);
346 Clause->setAssignmentOps(AssignmentOps);
Alexey Bataev005248a2016-02-25 05:25:57 +0000347 Clause->setPreInitStmt(PreInit);
348 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000349 return Clause;
350}
351
352OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
353 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000354 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000355 return new (Mem) OMPLastprivateClause(N);
356}
357
358OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
359 SourceLocation StartLoc,
360 SourceLocation LParenLoc,
361 SourceLocation EndLoc,
362 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000363 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000364 OMPSharedClause *Clause =
365 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
366 Clause->setVarRefs(VL);
367 return Clause;
368}
369
370OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000371 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000372 return new (Mem) OMPSharedClause(N);
373}
374
375void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
376 assert(PL.size() == varlist_size() &&
377 "Number of privates is not the same as the preallocated buffer");
378 std::copy(PL.begin(), PL.end(), varlist_end());
379}
380
381void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
382 assert(IL.size() == varlist_size() &&
383 "Number of inits is not the same as the preallocated buffer");
384 std::copy(IL.begin(), IL.end(), getPrivates().end());
385}
386
387void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
388 assert(UL.size() == varlist_size() &&
389 "Number of updates is not the same as the preallocated buffer");
390 std::copy(UL.begin(), UL.end(), getInits().end());
391}
392
393void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
394 assert(FL.size() == varlist_size() &&
395 "Number of final updates is not the same as the preallocated buffer");
396 std::copy(FL.begin(), FL.end(), getUpdates().end());
397}
398
399OMPLinearClause *OMPLinearClause::Create(
400 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
401 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
402 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
Alexey Bataev78849fb2016-03-09 09:49:00 +0000403 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
404 Stmt *PreInit, Expr *PostUpdate) {
James Y Knightb8bfd962015-10-02 13:41:04 +0000405 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
406 // (Step and CalcStep).
James Y Knight374fd202016-01-01 00:38:24 +0000407 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2));
James Y Knightb8bfd962015-10-02 13:41:04 +0000408 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
409 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
410 Clause->setVarRefs(VL);
411 Clause->setPrivates(PL);
412 Clause->setInits(IL);
413 // Fill update and final expressions with zeroes, they are provided later,
414 // after the directive construction.
415 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
416 nullptr);
417 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
418 nullptr);
419 Clause->setStep(Step);
420 Clause->setCalcStep(CalcStep);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000421 Clause->setPreInitStmt(PreInit);
422 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000423 return Clause;
424}
425
426OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
427 unsigned NumVars) {
428 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
429 // (Step and CalcStep).
James Y Knight374fd202016-01-01 00:38:24 +0000430 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2));
James Y Knightb8bfd962015-10-02 13:41:04 +0000431 return new (Mem) OMPLinearClause(NumVars);
432}
433
434OMPAlignedClause *
435OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
436 SourceLocation LParenLoc, SourceLocation ColonLoc,
437 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
James Y Knight374fd202016-01-01 00:38:24 +0000438 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000439 OMPAlignedClause *Clause = new (Mem)
440 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
441 Clause->setVarRefs(VL);
442 Clause->setAlignment(A);
443 return Clause;
444}
445
446OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
447 unsigned NumVars) {
James Y Knight374fd202016-01-01 00:38:24 +0000448 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000449 return new (Mem) OMPAlignedClause(NumVars);
450}
451
452void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
453 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
454 "not the same as the "
455 "preallocated buffer");
456 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
457}
458
459void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
460 assert(DstExprs.size() == varlist_size() && "Number of destination "
461 "expressions is not the same as "
462 "the preallocated buffer");
463 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
464}
465
466void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
467 assert(AssignmentOps.size() == varlist_size() &&
468 "Number of assignment expressions is not the same as the preallocated "
469 "buffer");
470 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
471 getDestinationExprs().end());
472}
473
474OMPCopyinClause *OMPCopyinClause::Create(
475 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
476 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
477 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000478 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000479 OMPCopyinClause *Clause =
480 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
481 Clause->setVarRefs(VL);
482 Clause->setSourceExprs(SrcExprs);
483 Clause->setDestinationExprs(DstExprs);
484 Clause->setAssignmentOps(AssignmentOps);
485 return Clause;
486}
487
488OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000489 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000490 return new (Mem) OMPCopyinClause(N);
491}
492
493void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
494 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
495 "not the same as the "
496 "preallocated buffer");
497 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
498}
499
500void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
501 assert(DstExprs.size() == varlist_size() && "Number of destination "
502 "expressions is not the same as "
503 "the preallocated buffer");
504 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
505}
506
507void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
508 assert(AssignmentOps.size() == varlist_size() &&
509 "Number of assignment expressions is not the same as the preallocated "
510 "buffer");
511 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
512 getDestinationExprs().end());
513}
514
515OMPCopyprivateClause *OMPCopyprivateClause::Create(
516 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
517 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
518 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000519 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000520 OMPCopyprivateClause *Clause =
521 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
522 Clause->setVarRefs(VL);
523 Clause->setSourceExprs(SrcExprs);
524 Clause->setDestinationExprs(DstExprs);
525 Clause->setAssignmentOps(AssignmentOps);
526 return Clause;
527}
528
529OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
530 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000531 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000532 return new (Mem) OMPCopyprivateClause(N);
533}
534
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000535void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
536 assert(Privates.size() == varlist_size() &&
537 "Number of private copies is not the same as the preallocated buffer");
538 std::copy(Privates.begin(), Privates.end(), varlist_end());
539}
540
James Y Knightb8bfd962015-10-02 13:41:04 +0000541void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
542 assert(
543 LHSExprs.size() == varlist_size() &&
544 "Number of LHS expressions is not the same as the preallocated buffer");
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000545 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
James Y Knightb8bfd962015-10-02 13:41:04 +0000546}
547
548void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
549 assert(
550 RHSExprs.size() == varlist_size() &&
551 "Number of RHS expressions is not the same as the preallocated buffer");
552 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
553}
554
555void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
556 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
557 "expressions is not the same "
558 "as the preallocated buffer");
559 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
560}
561
562OMPReductionClause *OMPReductionClause::Create(
563 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
564 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
565 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000566 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev61205072016-03-02 04:57:40 +0000567 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
568 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000569 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000570 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
571 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
572 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000573 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000574 Clause->setLHSExprs(LHSExprs);
575 Clause->setRHSExprs(RHSExprs);
576 Clause->setReductionOps(ReductionOps);
Alexey Bataev61205072016-03-02 04:57:40 +0000577 Clause->setPreInitStmt(PreInit);
578 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000579 return Clause;
580}
581
582OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
583 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000584 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000585 return new (Mem) OMPReductionClause(N);
586}
587
Alexey Bataev169d96a2017-07-18 20:17:46 +0000588void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
589 assert(Privates.size() == varlist_size() &&
590 "Number of private copies is not the same as the preallocated buffer");
591 std::copy(Privates.begin(), Privates.end(), varlist_end());
592}
593
594void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
595 assert(
596 LHSExprs.size() == varlist_size() &&
597 "Number of LHS expressions is not the same as the preallocated buffer");
598 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
599}
600
601void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
602 assert(
603 RHSExprs.size() == varlist_size() &&
604 "Number of RHS expressions is not the same as the preallocated buffer");
605 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
606}
607
608void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
609 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
610 "expressions is not the same "
611 "as the preallocated buffer");
612 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
613}
614
615OMPTaskReductionClause *OMPTaskReductionClause::Create(
616 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
617 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
618 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
619 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
620 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
621 Expr *PostUpdate) {
622 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
623 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
624 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
625 Clause->setVarRefs(VL);
626 Clause->setPrivates(Privates);
627 Clause->setLHSExprs(LHSExprs);
628 Clause->setRHSExprs(RHSExprs);
629 Clause->setReductionOps(ReductionOps);
630 Clause->setPreInitStmt(PreInit);
631 Clause->setPostUpdateExpr(PostUpdate);
632 return Clause;
633}
634
635OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
636 unsigned N) {
637 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
638 return new (Mem) OMPTaskReductionClause(N);
639}
640
Alexey Bataevfa312f32017-07-21 18:48:21 +0000641void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
642 assert(Privates.size() == varlist_size() &&
643 "Number of private copies is not the same as the preallocated buffer");
644 std::copy(Privates.begin(), Privates.end(), varlist_end());
645}
646
647void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
648 assert(
649 LHSExprs.size() == varlist_size() &&
650 "Number of LHS expressions is not the same as the preallocated buffer");
651 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
652}
653
654void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
655 assert(
656 RHSExprs.size() == varlist_size() &&
657 "Number of RHS expressions is not the same as the preallocated buffer");
658 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
659}
660
661void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
662 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
663 "expressions is not the same "
664 "as the preallocated buffer");
665 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
666}
667
Alexey Bataev88202be2017-07-27 13:20:36 +0000668void OMPInReductionClause::setTaskgroupDescriptors(
669 ArrayRef<Expr *> TaskgroupDescriptors) {
670 assert(TaskgroupDescriptors.size() == varlist_size() &&
671 "Number of in reduction descriptors is not the same as the "
672 "preallocated buffer");
673 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
674 getReductionOps().end());
675}
676
Alexey Bataevfa312f32017-07-21 18:48:21 +0000677OMPInReductionClause *OMPInReductionClause::Create(
678 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
679 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
680 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
681 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev88202be2017-07-27 13:20:36 +0000682 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
683 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
684 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000685 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
686 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
687 Clause->setVarRefs(VL);
688 Clause->setPrivates(Privates);
689 Clause->setLHSExprs(LHSExprs);
690 Clause->setRHSExprs(RHSExprs);
691 Clause->setReductionOps(ReductionOps);
Alexey Bataev88202be2017-07-27 13:20:36 +0000692 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000693 Clause->setPreInitStmt(PreInit);
694 Clause->setPostUpdateExpr(PostUpdate);
695 return Clause;
696}
697
698OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
699 unsigned N) {
Alexey Bataev88202be2017-07-27 13:20:36 +0000700 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000701 return new (Mem) OMPInReductionClause(N);
702}
703
James Y Knightb8bfd962015-10-02 13:41:04 +0000704OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
705 SourceLocation StartLoc,
706 SourceLocation LParenLoc,
707 SourceLocation EndLoc,
708 ArrayRef<Expr *> VL) {
Alexey Bataev8b427062016-05-25 12:36:08 +0000709 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000710 OMPFlushClause *Clause =
711 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
712 Clause->setVarRefs(VL);
713 return Clause;
714}
715
716OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000717 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000718 return new (Mem) OMPFlushClause(N);
719}
720
Alexey Bataevf138fda2018-08-13 19:04:24 +0000721OMPDependClause *
722OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
723 SourceLocation LParenLoc, SourceLocation EndLoc,
724 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
725 SourceLocation ColonLoc, ArrayRef<Expr *> VL,
726 unsigned NumLoops) {
727 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
728 OMPDependClause *Clause = new (Mem)
729 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000730 Clause->setVarRefs(VL);
731 Clause->setDependencyKind(DepKind);
732 Clause->setDependencyLoc(DepLoc);
733 Clause->setColonLoc(ColonLoc);
Alexey Bataevf138fda2018-08-13 19:04:24 +0000734 for (unsigned I = 0 ; I < NumLoops; ++I)
735 Clause->setLoopData(I, nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000736 return Clause;
737}
738
Alexey Bataevf138fda2018-08-13 19:04:24 +0000739OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
740 unsigned NumLoops) {
741 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
742 return new (Mem) OMPDependClause(N, NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000743}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000744
Alexey Bataevf138fda2018-08-13 19:04:24 +0000745void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
746 assert((getDependencyKind() == OMPC_DEPEND_sink ||
747 getDependencyKind() == OMPC_DEPEND_source) &&
748 NumLoop < NumLoops &&
749 "Expected sink or source depend + loop index must be less number of "
750 "loops.");
751 auto It = std::next(getVarRefs().end(), NumLoop);
752 *It = Cnt;
Alexey Bataev8b427062016-05-25 12:36:08 +0000753}
754
Alexey Bataevf138fda2018-08-13 19:04:24 +0000755Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
756 assert((getDependencyKind() == OMPC_DEPEND_sink ||
757 getDependencyKind() == OMPC_DEPEND_source) &&
758 NumLoop < NumLoops &&
759 "Expected sink or source depend + loop index must be less number of "
760 "loops.");
761 auto It = std::next(getVarRefs().end(), NumLoop);
762 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000763}
764
Alexey Bataevf138fda2018-08-13 19:04:24 +0000765const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
766 assert((getDependencyKind() == OMPC_DEPEND_sink ||
767 getDependencyKind() == OMPC_DEPEND_source) &&
768 NumLoop < NumLoops &&
769 "Expected sink or source depend + loop index must be less number of "
770 "loops.");
771 auto It = std::next(getVarRefs().end(), NumLoop);
772 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000773}
774
Samuel Antao90927002016-04-26 14:54:23 +0000775unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
776 MappableExprComponentListsRef ComponentLists) {
777 unsigned TotalNum = 0u;
778 for (auto &C : ComponentLists)
779 TotalNum += C.size();
780 return TotalNum;
781}
782
783unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
Alexey Bataeve3727102018-04-18 15:57:46 +0000784 ArrayRef<const ValueDecl *> Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000785 unsigned TotalNum = 0u;
786 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
Alexey Bataeve3727102018-04-18 15:57:46 +0000787 for (const ValueDecl *D : Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000788 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
789 if (Cache.count(VD))
790 continue;
791 ++TotalNum;
792 Cache.insert(VD);
793 }
794 return TotalNum;
795}
796
Michael Kruse4304e9d2019-02-19 16:38:20 +0000797OMPMapClause *OMPMapClause::Create(
798 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
799 ArrayRef<ValueDecl *> Declarations,
800 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
801 ArrayRef<OpenMPMapModifierKind> MapModifiers,
802 ArrayRef<SourceLocation> MapModifiersLoc,
803 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
804 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
805 OMPMappableExprListSizeTy Sizes;
806 Sizes.NumVars = Vars.size();
807 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
808 Sizes.NumComponentLists = ComponentLists.size();
809 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao90927002016-04-26 14:54:23 +0000810
811 // We need to allocate:
Michael Kruse4304e9d2019-02-19 16:38:20 +0000812 // 2 x NumVars x Expr* - we have an original list expression and an associated
813 // user-defined mapper for each clause list entry.
Samuel Antao90927002016-04-26 14:54:23 +0000814 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
815 // with each component list.
816 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
817 // number of lists for each unique declaration and the size of each component
818 // list.
819 // NumComponents x MappableComponent - the total of all the components in all
820 // the lists.
821 void *Mem = C.Allocate(
822 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
823 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000824 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
825 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
826 Sizes.NumComponents));
827 OMPMapClause *Clause = new (Mem)
828 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
829 Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
Samuel Antao90927002016-04-26 14:54:23 +0000830
831 Clause->setVarRefs(Vars);
Michael Kruse4304e9d2019-02-19 16:38:20 +0000832 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao90927002016-04-26 14:54:23 +0000833 Clause->setClauseInfo(Declarations, ComponentLists);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000834 Clause->setMapType(Type);
835 Clause->setMapLoc(TypeLoc);
836 return Clause;
837}
838
Michael Kruse4304e9d2019-02-19 16:38:20 +0000839OMPMapClause *
840OMPMapClause::CreateEmpty(const ASTContext &C,
841 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao90927002016-04-26 14:54:23 +0000842 void *Mem = C.Allocate(
843 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
844 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000845 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
846 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
847 Sizes.NumComponents));
848 return new (Mem) OMPMapClause(Sizes);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000849}
Samuel Antao661c0902016-05-26 17:39:58 +0000850
Michael Kruse01f670d2019-02-22 22:29:42 +0000851OMPToClause *OMPToClause::Create(
852 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
853 ArrayRef<ValueDecl *> Declarations,
854 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
855 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000856 OMPMappableExprListSizeTy Sizes;
857 Sizes.NumVars = Vars.size();
858 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
859 Sizes.NumComponentLists = ComponentLists.size();
860 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao661c0902016-05-26 17:39:58 +0000861
862 // We need to allocate:
Michael Kruse01f670d2019-02-22 22:29:42 +0000863 // 2 x NumVars x Expr* - we have an original list expression and an associated
864 // user-defined mapper for each clause list entry.
Samuel Antao661c0902016-05-26 17:39:58 +0000865 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
866 // with each component list.
867 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
868 // number of lists for each unique declaration and the size of each component
869 // list.
870 // NumComponents x MappableComponent - the total of all the components in all
871 // the lists.
872 void *Mem = C.Allocate(
873 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
874 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +0000875 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000876 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
877 Sizes.NumComponents));
Samuel Antao661c0902016-05-26 17:39:58 +0000878
Michael Kruse01f670d2019-02-22 22:29:42 +0000879 auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +0000880
881 Clause->setVarRefs(Vars);
Michael Kruse01f670d2019-02-22 22:29:42 +0000882 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao661c0902016-05-26 17:39:58 +0000883 Clause->setClauseInfo(Declarations, ComponentLists);
884 return Clause;
885}
886
Michael Kruse4304e9d2019-02-19 16:38:20 +0000887OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
888 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao661c0902016-05-26 17:39:58 +0000889 void *Mem = C.Allocate(
890 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
891 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +0000892 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000893 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
894 Sizes.NumComponents));
895 return new (Mem) OMPToClause(Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +0000896}
Samuel Antaoec172c62016-05-26 17:49:04 +0000897
Michael Kruse0336c752019-02-25 20:34:15 +0000898OMPFromClause *OMPFromClause::Create(
899 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
900 ArrayRef<ValueDecl *> Declarations,
901 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
902 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000903 OMPMappableExprListSizeTy Sizes;
904 Sizes.NumVars = Vars.size();
905 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
906 Sizes.NumComponentLists = ComponentLists.size();
907 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaoec172c62016-05-26 17:49:04 +0000908
909 // We need to allocate:
Michael Kruse0336c752019-02-25 20:34:15 +0000910 // 2 x NumVars x Expr* - we have an original list expression and an associated
911 // user-defined mapper for each clause list entry.
Samuel Antaoec172c62016-05-26 17:49:04 +0000912 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
913 // with each component list.
914 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
915 // number of lists for each unique declaration and the size of each component
916 // list.
917 // NumComponents x MappableComponent - the total of all the components in all
918 // the lists.
919 void *Mem = C.Allocate(
920 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
921 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +0000922 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000923 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
924 Sizes.NumComponents));
Samuel Antaoec172c62016-05-26 17:49:04 +0000925
Michael Kruse0336c752019-02-25 20:34:15 +0000926 auto *Clause =
927 new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +0000928
929 Clause->setVarRefs(Vars);
Michael Kruse0336c752019-02-25 20:34:15 +0000930 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antaoec172c62016-05-26 17:49:04 +0000931 Clause->setClauseInfo(Declarations, ComponentLists);
932 return Clause;
933}
934
Michael Kruse4304e9d2019-02-19 16:38:20 +0000935OMPFromClause *
936OMPFromClause::CreateEmpty(const ASTContext &C,
937 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaoec172c62016-05-26 17:49:04 +0000938 void *Mem = C.Allocate(
939 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
940 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +0000941 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000942 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
943 Sizes.NumComponents));
944 return new (Mem) OMPFromClause(Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +0000945}
Carlo Bertolli2404b172016-07-13 15:37:16 +0000946
Samuel Antaocc10b852016-07-28 14:23:26 +0000947void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
948 assert(VL.size() == varlist_size() &&
949 "Number of private copies is not the same as the preallocated buffer");
950 std::copy(VL.begin(), VL.end(), varlist_end());
951}
952
953void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
954 assert(VL.size() == varlist_size() &&
955 "Number of inits is not the same as the preallocated buffer");
956 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
957}
958
959OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000960 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
961 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
962 ArrayRef<ValueDecl *> Declarations,
Samuel Antaocc10b852016-07-28 14:23:26 +0000963 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000964 OMPMappableExprListSizeTy Sizes;
965 Sizes.NumVars = Vars.size();
966 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
967 Sizes.NumComponentLists = ComponentLists.size();
968 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaocc10b852016-07-28 14:23:26 +0000969
970 // We need to allocate:
971 // 3 x NumVars x Expr* - we have an original list expression for each clause
972 // list entry and an equal number of private copies and inits.
973 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
974 // with each component list.
975 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
976 // number of lists for each unique declaration and the size of each component
977 // list.
978 // NumComponents x MappableComponent - the total of all the components in all
979 // the lists.
980 void *Mem = C.Allocate(
981 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
982 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000983 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
984 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
985 Sizes.NumComponents));
Samuel Antaocc10b852016-07-28 14:23:26 +0000986
Michael Kruse4304e9d2019-02-19 16:38:20 +0000987 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
Samuel Antaocc10b852016-07-28 14:23:26 +0000988
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
Michael Kruse4304e9d2019-02-19 16:38:20 +0000996OMPUseDevicePtrClause *
997OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
998 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaocc10b852016-07-28 14:23:26 +0000999 void *Mem = C.Allocate(
1000 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1001 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001002 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1003 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1004 Sizes.NumComponents));
1005 return new (Mem) OMPUseDevicePtrClause(Sizes);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001006}
Carlo Bertolli70594e92016-07-13 17:16:49 +00001007
Samuel Antao6890b092016-07-28 14:25:09 +00001008OMPIsDevicePtrClause *
Michael Kruse4304e9d2019-02-19 16:38:20 +00001009OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
Samuel Antao6890b092016-07-28 14:25:09 +00001010 ArrayRef<Expr *> Vars,
1011 ArrayRef<ValueDecl *> Declarations,
1012 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001013 OMPMappableExprListSizeTy Sizes;
1014 Sizes.NumVars = Vars.size();
1015 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1016 Sizes.NumComponentLists = ComponentLists.size();
1017 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao6890b092016-07-28 14:25:09 +00001018
1019 // We need to allocate:
1020 // NumVars x Expr* - we have an original list expression for each clause list
1021 // entry.
1022 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1023 // with each component list.
1024 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1025 // number of lists for each unique declaration and the size of each component
1026 // list.
1027 // NumComponents x MappableComponent - the total of all the components in all
1028 // the lists.
1029 void *Mem = C.Allocate(
1030 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1031 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001032 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1033 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1034 Sizes.NumComponents));
Samuel Antao6890b092016-07-28 14:25:09 +00001035
Michael Kruse4304e9d2019-02-19 16:38:20 +00001036 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
Samuel Antao6890b092016-07-28 14:25:09 +00001037
1038 Clause->setVarRefs(Vars);
1039 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001040 return Clause;
1041}
1042
Michael Kruse4304e9d2019-02-19 16:38:20 +00001043OMPIsDevicePtrClause *
1044OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1045 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao6890b092016-07-28 14:25:09 +00001046 void *Mem = C.Allocate(
1047 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1048 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001049 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1050 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1051 Sizes.NumComponents));
1052 return new (Mem) OMPIsDevicePtrClause(Sizes);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001053}
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001054
1055//===----------------------------------------------------------------------===//
1056// OpenMP clauses printing methods
1057//===----------------------------------------------------------------------===//
1058
1059void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1060 OS << "if(";
1061 if (Node->getNameModifier() != OMPD_unknown)
1062 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1063 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1064 OS << ")";
1065}
1066
1067void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1068 OS << "final(";
1069 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1070 OS << ")";
1071}
1072
1073void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1074 OS << "num_threads(";
1075 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1076 OS << ")";
1077}
1078
1079void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1080 OS << "safelen(";
1081 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1082 OS << ")";
1083}
1084
1085void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1086 OS << "simdlen(";
1087 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1088 OS << ")";
1089}
1090
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00001091void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
1092 OS << "allocator(";
1093 Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
1094 OS << ")";
1095}
1096
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001097void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1098 OS << "collapse(";
1099 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1100 OS << ")";
1101}
1102
1103void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1104 OS << "default("
1105 << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
1106 << ")";
1107}
1108
1109void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1110 OS << "proc_bind("
1111 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, Node->getProcBindKind())
1112 << ")";
1113}
1114
1115void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1116 OS << "unified_address";
1117}
1118
1119void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1120 OMPUnifiedSharedMemoryClause *) {
1121 OS << "unified_shared_memory";
1122}
1123
1124void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1125 OS << "reverse_offload";
1126}
1127
1128void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1129 OMPDynamicAllocatorsClause *) {
1130 OS << "dynamic_allocators";
1131}
1132
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00001133void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1134 OMPAtomicDefaultMemOrderClause *Node) {
1135 OS << "atomic_default_mem_order("
1136 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1137 Node->getAtomicDefaultMemOrderKind())
1138 << ")";
1139}
1140
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001141void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1142 OS << "schedule(";
1143 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1144 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1145 Node->getFirstScheduleModifier());
1146 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1147 OS << ", ";
1148 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1149 Node->getSecondScheduleModifier());
1150 }
1151 OS << ": ";
1152 }
1153 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1154 if (auto *E = Node->getChunkSize()) {
1155 OS << ", ";
1156 E->printPretty(OS, nullptr, Policy);
1157 }
1158 OS << ")";
1159}
1160
1161void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1162 OS << "ordered";
1163 if (auto *Num = Node->getNumForLoops()) {
1164 OS << "(";
1165 Num->printPretty(OS, nullptr, Policy, 0);
1166 OS << ")";
1167 }
1168}
1169
1170void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1171 OS << "nowait";
1172}
1173
1174void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1175 OS << "untied";
1176}
1177
1178void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1179 OS << "nogroup";
1180}
1181
1182void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1183 OS << "mergeable";
1184}
1185
1186void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1187
1188void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1189
1190void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
1191 OS << "update";
1192}
1193
1194void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1195 OS << "capture";
1196}
1197
1198void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1199 OS << "seq_cst";
1200}
1201
1202void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1203 OS << "threads";
1204}
1205
1206void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1207
1208void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1209 OS << "device(";
1210 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1211 OS << ")";
1212}
1213
1214void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1215 OS << "num_teams(";
1216 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1217 OS << ")";
1218}
1219
1220void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1221 OS << "thread_limit(";
1222 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1223 OS << ")";
1224}
1225
1226void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1227 OS << "priority(";
1228 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1229 OS << ")";
1230}
1231
1232void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1233 OS << "grainsize(";
1234 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1235 OS << ")";
1236}
1237
1238void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1239 OS << "num_tasks(";
1240 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1241 OS << ")";
1242}
1243
1244void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1245 OS << "hint(";
1246 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1247 OS << ")";
1248}
1249
1250template<typename T>
1251void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1252 for (typename T::varlist_iterator I = Node->varlist_begin(),
1253 E = Node->varlist_end();
1254 I != E; ++I) {
1255 assert(*I && "Expected non-null Stmt");
1256 OS << (I == Node->varlist_begin() ? StartSym : ',');
1257 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1258 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1259 DRE->printPretty(OS, nullptr, Policy, 0);
1260 else
1261 DRE->getDecl()->printQualifiedName(OS);
1262 } else
1263 (*I)->printPretty(OS, nullptr, Policy, 0);
1264 }
1265}
1266
1267void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1268 if (!Node->varlist_empty()) {
1269 OS << "private";
1270 VisitOMPClauseList(Node, '(');
1271 OS << ")";
1272 }
1273}
1274
1275void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1276 if (!Node->varlist_empty()) {
1277 OS << "firstprivate";
1278 VisitOMPClauseList(Node, '(');
1279 OS << ")";
1280 }
1281}
1282
1283void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1284 if (!Node->varlist_empty()) {
1285 OS << "lastprivate";
1286 VisitOMPClauseList(Node, '(');
1287 OS << ")";
1288 }
1289}
1290
1291void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1292 if (!Node->varlist_empty()) {
1293 OS << "shared";
1294 VisitOMPClauseList(Node, '(');
1295 OS << ")";
1296 }
1297}
1298
1299void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1300 if (!Node->varlist_empty()) {
1301 OS << "reduction(";
1302 NestedNameSpecifier *QualifierLoc =
1303 Node->getQualifierLoc().getNestedNameSpecifier();
1304 OverloadedOperatorKind OOK =
1305 Node->getNameInfo().getName().getCXXOverloadedOperator();
1306 if (QualifierLoc == nullptr && OOK != OO_None) {
1307 // Print reduction identifier in C format
1308 OS << getOperatorSpelling(OOK);
1309 } else {
1310 // Use C++ format
1311 if (QualifierLoc != nullptr)
1312 QualifierLoc->print(OS, Policy);
1313 OS << Node->getNameInfo();
1314 }
1315 OS << ":";
1316 VisitOMPClauseList(Node, ' ');
1317 OS << ")";
1318 }
1319}
1320
1321void OMPClausePrinter::VisitOMPTaskReductionClause(
1322 OMPTaskReductionClause *Node) {
1323 if (!Node->varlist_empty()) {
1324 OS << "task_reduction(";
1325 NestedNameSpecifier *QualifierLoc =
1326 Node->getQualifierLoc().getNestedNameSpecifier();
1327 OverloadedOperatorKind OOK =
1328 Node->getNameInfo().getName().getCXXOverloadedOperator();
1329 if (QualifierLoc == nullptr && OOK != OO_None) {
1330 // Print reduction identifier in C format
1331 OS << getOperatorSpelling(OOK);
1332 } else {
1333 // Use C++ format
1334 if (QualifierLoc != nullptr)
1335 QualifierLoc->print(OS, Policy);
1336 OS << Node->getNameInfo();
1337 }
1338 OS << ":";
1339 VisitOMPClauseList(Node, ' ');
1340 OS << ")";
1341 }
1342}
1343
1344void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1345 if (!Node->varlist_empty()) {
1346 OS << "in_reduction(";
1347 NestedNameSpecifier *QualifierLoc =
1348 Node->getQualifierLoc().getNestedNameSpecifier();
1349 OverloadedOperatorKind OOK =
1350 Node->getNameInfo().getName().getCXXOverloadedOperator();
1351 if (QualifierLoc == nullptr && OOK != OO_None) {
1352 // Print reduction identifier in C format
1353 OS << getOperatorSpelling(OOK);
1354 } else {
1355 // Use C++ format
1356 if (QualifierLoc != nullptr)
1357 QualifierLoc->print(OS, Policy);
1358 OS << Node->getNameInfo();
1359 }
1360 OS << ":";
1361 VisitOMPClauseList(Node, ' ');
1362 OS << ")";
1363 }
1364}
1365
1366void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1367 if (!Node->varlist_empty()) {
1368 OS << "linear";
1369 if (Node->getModifierLoc().isValid()) {
1370 OS << '('
1371 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1372 }
1373 VisitOMPClauseList(Node, '(');
1374 if (Node->getModifierLoc().isValid())
1375 OS << ')';
1376 if (Node->getStep() != nullptr) {
1377 OS << ": ";
1378 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1379 }
1380 OS << ")";
1381 }
1382}
1383
1384void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1385 if (!Node->varlist_empty()) {
1386 OS << "aligned";
1387 VisitOMPClauseList(Node, '(');
1388 if (Node->getAlignment() != nullptr) {
1389 OS << ": ";
1390 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1391 }
1392 OS << ")";
1393 }
1394}
1395
1396void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1397 if (!Node->varlist_empty()) {
1398 OS << "copyin";
1399 VisitOMPClauseList(Node, '(');
1400 OS << ")";
1401 }
1402}
1403
1404void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1405 if (!Node->varlist_empty()) {
1406 OS << "copyprivate";
1407 VisitOMPClauseList(Node, '(');
1408 OS << ")";
1409 }
1410}
1411
1412void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1413 if (!Node->varlist_empty()) {
1414 VisitOMPClauseList(Node, '(');
1415 OS << ")";
1416 }
1417}
1418
1419void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1420 OS << "depend(";
1421 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1422 Node->getDependencyKind());
1423 if (!Node->varlist_empty()) {
1424 OS << " :";
1425 VisitOMPClauseList(Node, ' ');
1426 }
1427 OS << ")";
1428}
1429
1430void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1431 if (!Node->varlist_empty()) {
1432 OS << "map(";
1433 if (Node->getMapType() != OMPC_MAP_unknown) {
Kelvin Lief579432018-12-18 22:18:41 +00001434 for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1435 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1436 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1437 Node->getMapTypeModifier(I));
Michael Kruse4304e9d2019-02-19 16:38:20 +00001438 if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1439 OS << '(';
1440 NestedNameSpecifier *MapperNNS =
1441 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1442 if (MapperNNS)
1443 MapperNNS->print(OS, Policy);
1444 OS << Node->getMapperIdInfo() << ')';
1445 }
Kelvin Lief579432018-12-18 22:18:41 +00001446 OS << ',';
1447 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001448 }
1449 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1450 OS << ':';
1451 }
1452 VisitOMPClauseList(Node, ' ');
1453 OS << ")";
1454 }
1455}
1456
1457void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1458 if (!Node->varlist_empty()) {
1459 OS << "to";
Michael Kruse01f670d2019-02-22 22:29:42 +00001460 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1461 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1462 OS << '(';
1463 OS << "mapper(";
1464 NestedNameSpecifier *MapperNNS =
1465 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1466 if (MapperNNS)
1467 MapperNNS->print(OS, Policy);
1468 OS << MapperId << "):";
1469 VisitOMPClauseList(Node, ' ');
1470 } else {
1471 VisitOMPClauseList(Node, '(');
1472 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001473 OS << ")";
1474 }
1475}
1476
1477void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1478 if (!Node->varlist_empty()) {
1479 OS << "from";
Michael Kruse0336c752019-02-25 20:34:15 +00001480 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1481 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1482 OS << '(';
1483 OS << "mapper(";
1484 NestedNameSpecifier *MapperNNS =
1485 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1486 if (MapperNNS)
1487 MapperNNS->print(OS, Policy);
1488 OS << MapperId << "):";
1489 VisitOMPClauseList(Node, ' ');
1490 } else {
1491 VisitOMPClauseList(Node, '(');
1492 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001493 OS << ")";
1494 }
1495}
1496
1497void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1498 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1499 OMPC_dist_schedule, Node->getDistScheduleKind());
1500 if (auto *E = Node->getChunkSize()) {
1501 OS << ", ";
1502 E->printPretty(OS, nullptr, Policy);
1503 }
1504 OS << ")";
1505}
1506
1507void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1508 OS << "defaultmap(";
1509 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1510 Node->getDefaultmapModifier());
1511 OS << ": ";
1512 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1513 Node->getDefaultmapKind());
1514 OS << ")";
1515}
1516
1517void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1518 if (!Node->varlist_empty()) {
1519 OS << "use_device_ptr";
1520 VisitOMPClauseList(Node, '(');
1521 OS << ")";
1522 }
1523}
1524
1525void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1526 if (!Node->varlist_empty()) {
1527 OS << "is_device_ptr";
1528 VisitOMPClauseList(Node, '(');
1529 OS << ")";
1530 }
1531}
1532