blob: b97607f8c60f8fe19a3e729dd9e72882fd0806f5 [file] [log] [blame]
Eugene Zelenkod1b2d222017-11-29 23:27:36 +00001//===- OpenMPClause.cpp - Classes for OpenMP clauses ----------------------===//
James Y Knightb8bfd962015-10-02 13:41:04 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
James Y Knightb8bfd962015-10-02 13:41:04 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the subclesses of Stmt class declared in OpenMPClause.h
10//
11//===----------------------------------------------------------------------===//
12
13#include "clang/AST/OpenMPClause.h"
James Y Knightb8bfd962015-10-02 13:41:04 +000014#include "clang/AST/ASTContext.h"
Eugene Zelenkod1b2d222017-11-29 23:27:36 +000015#include "clang/AST/Decl.h"
Patrick Lyster074c3ae22018-10-18 14:28:23 +000016#include "clang/AST/DeclOpenMP.h"
Eugene Zelenkod1b2d222017-11-29 23:27:36 +000017#include "clang/Basic/LLVM.h"
18#include "llvm/ADT/SmallPtrSet.h"
19#include "llvm/Support/Casting.h"
20#include "llvm/Support/ErrorHandling.h"
21#include <algorithm>
22#include <cassert>
James Y Knightb8bfd962015-10-02 13:41:04 +000023
24using namespace clang;
25
26OMPClause::child_range OMPClause::children() {
27 switch (getClauseKind()) {
28 default:
29 break;
30#define OPENMP_CLAUSE(Name, Class) \
31 case OMPC_##Name: \
32 return static_cast<Class *>(this)->children();
33#include "clang/Basic/OpenMPKinds.def"
34 }
35 llvm_unreachable("unknown OMPClause");
36}
37
Alexey Bataevc2c21ef2019-07-11 14:54:17 +000038OMPClause::child_range OMPClause::used_children() {
39 switch (getClauseKind()) {
40#define OPENMP_CLAUSE(Name, Class) \
41 case OMPC_##Name: \
42 return static_cast<Class *>(this)->used_children();
43#include "clang/Basic/OpenMPKinds.def"
44 case OMPC_threadprivate:
45 case OMPC_uniform:
Alexey Bataev729e2422019-08-23 16:11:14 +000046 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +000047 case OMPC_match:
Alexey Bataevc2c21ef2019-07-11 14:54:17 +000048 case OMPC_unknown:
49 break;
50 }
51 llvm_unreachable("unknown OMPClause");
52}
53
Alexey Bataev3392d762016-02-16 11:18:12 +000054OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
55 auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
56 return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr;
57}
58
59const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
60 switch (C->getClauseKind()) {
61 case OMPC_schedule:
62 return static_cast<const OMPScheduleClause *>(C);
63 case OMPC_dist_schedule:
64 return static_cast<const OMPDistScheduleClause *>(C);
Alexey Bataev417089f2016-02-17 13:19:37 +000065 case OMPC_firstprivate:
66 return static_cast<const OMPFirstprivateClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +000067 case OMPC_lastprivate:
68 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +000069 case OMPC_reduction:
70 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +000071 case OMPC_task_reduction:
72 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +000073 case OMPC_in_reduction:
74 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +000075 case OMPC_linear:
76 return static_cast<const OMPLinearClause *>(C);
Arpith Chacko Jacobfe4890a2017-01-18 20:40:48 +000077 case OMPC_if:
78 return static_cast<const OMPIfClause *>(C);
Arpith Chacko Jacob33c849a2017-01-25 00:57:16 +000079 case OMPC_num_threads:
80 return static_cast<const OMPNumThreadsClause *>(C);
Arpith Chacko Jacobbc126342017-01-25 11:28:18 +000081 case OMPC_num_teams:
82 return static_cast<const OMPNumTeamsClause *>(C);
Arpith Chacko Jacob7ecc0b72017-01-25 11:44:35 +000083 case OMPC_thread_limit:
84 return static_cast<const OMPThreadLimitClause *>(C);
Alexey Bataev931e19b2017-10-02 16:32:39 +000085 case OMPC_device:
86 return static_cast<const OMPDeviceClause *>(C);
Alexey Bataevb9c55e22019-10-14 19:29:52 +000087 case OMPC_grainsize:
88 return static_cast<const OMPGrainsizeClause *>(C);
Alexey Bataev3392d762016-02-16 11:18:12 +000089 case OMPC_default:
90 case OMPC_proc_bind:
Alexey Bataev3392d762016-02-16 11:18:12 +000091 case OMPC_final:
Alexey Bataev3392d762016-02-16 11:18:12 +000092 case OMPC_safelen:
93 case OMPC_simdlen:
Alexey Bataev9cc10fc2019-03-12 18:52:33 +000094 case OMPC_allocator:
Alexey Bataeve04483e2019-03-27 14:14:31 +000095 case OMPC_allocate:
Alexey Bataev3392d762016-02-16 11:18:12 +000096 case OMPC_collapse:
97 case OMPC_private:
Alexey Bataev005248a2016-02-25 05:25:57 +000098 case OMPC_shared:
Alexey Bataev005248a2016-02-25 05:25:57 +000099 case OMPC_aligned:
100 case OMPC_copyin:
101 case OMPC_copyprivate:
102 case OMPC_ordered:
103 case OMPC_nowait:
104 case OMPC_untied:
105 case OMPC_mergeable:
106 case OMPC_threadprivate:
107 case OMPC_flush:
108 case OMPC_read:
109 case OMPC_write:
110 case OMPC_update:
111 case OMPC_capture:
112 case OMPC_seq_cst:
113 case OMPC_depend:
Alexey Bataev005248a2016-02-25 05:25:57 +0000114 case OMPC_threads:
115 case OMPC_simd:
116 case OMPC_map:
Alexey Bataev005248a2016-02-25 05:25:57 +0000117 case OMPC_priority:
Alexey Bataev005248a2016-02-25 05:25:57 +0000118 case OMPC_nogroup:
119 case OMPC_num_tasks:
120 case OMPC_hint:
121 case OMPC_defaultmap:
122 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000123 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000124 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000125 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000126 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000127 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000128 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000129 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000130 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000131 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000132 case OMPC_atomic_default_mem_order:
Alexey Bataev729e2422019-08-23 16:11:14 +0000133 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +0000134 case OMPC_match:
Alexey Bataev005248a2016-02-25 05:25:57 +0000135 break;
136 }
137
138 return nullptr;
139}
140
141OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
142 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
143 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
144}
145
146const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
147 switch (C->getClauseKind()) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000148 case OMPC_lastprivate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000149 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000150 case OMPC_reduction:
151 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +0000152 case OMPC_task_reduction:
153 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000154 case OMPC_in_reduction:
155 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000156 case OMPC_linear:
157 return static_cast<const OMPLinearClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000158 case OMPC_schedule:
159 case OMPC_dist_schedule:
160 case OMPC_firstprivate:
161 case OMPC_default:
162 case OMPC_proc_bind:
163 case OMPC_if:
164 case OMPC_final:
165 case OMPC_num_threads:
166 case OMPC_safelen:
167 case OMPC_simdlen:
Alexey Bataev9cc10fc2019-03-12 18:52:33 +0000168 case OMPC_allocator:
Alexey Bataeve04483e2019-03-27 14:14:31 +0000169 case OMPC_allocate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000170 case OMPC_collapse:
171 case OMPC_private:
Alexey Bataev3392d762016-02-16 11:18:12 +0000172 case OMPC_shared:
Alexey Bataev3392d762016-02-16 11:18:12 +0000173 case OMPC_aligned:
174 case OMPC_copyin:
175 case OMPC_copyprivate:
176 case OMPC_ordered:
177 case OMPC_nowait:
178 case OMPC_untied:
179 case OMPC_mergeable:
180 case OMPC_threadprivate:
181 case OMPC_flush:
182 case OMPC_read:
183 case OMPC_write:
184 case OMPC_update:
185 case OMPC_capture:
186 case OMPC_seq_cst:
187 case OMPC_depend:
188 case OMPC_device:
189 case OMPC_threads:
190 case OMPC_simd:
191 case OMPC_map:
192 case OMPC_num_teams:
193 case OMPC_thread_limit:
194 case OMPC_priority:
195 case OMPC_grainsize:
196 case OMPC_nogroup:
197 case OMPC_num_tasks:
198 case OMPC_hint:
199 case OMPC_defaultmap:
200 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000201 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000202 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000203 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000204 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000205 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000206 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000207 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000208 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000209 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000210 case OMPC_atomic_default_mem_order:
Alexey Bataev729e2422019-08-23 16:11:14 +0000211 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +0000212 case OMPC_match:
Alexey Bataev3392d762016-02-16 11:18:12 +0000213 break;
214 }
215
216 return nullptr;
217}
218
Alexey Bataev655cb4a2019-07-16 14:51:46 +0000219/// Gets the address of the original, non-captured, expression used in the
220/// clause as the preinitializer.
221static Stmt **getAddrOfExprAsWritten(Stmt *S) {
222 if (!S)
223 return nullptr;
224 if (auto *DS = dyn_cast<DeclStmt>(S)) {
225 assert(DS->isSingleDecl() && "Only single expression must be captured.");
226 if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
227 return OED->getInitAddress();
228 }
229 return nullptr;
230}
231
232OMPClause::child_range OMPIfClause::used_children() {
233 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
234 return child_range(C, C + 1);
235 return child_range(&Condition, &Condition + 1);
236}
237
Alexey Bataevb9c55e22019-10-14 19:29:52 +0000238OMPClause::child_range OMPGrainsizeClause::used_children() {
239 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
240 return child_range(C, C + 1);
241 return child_range(&Grainsize, &Grainsize + 1);
242}
243
Alexey Bataevf138fda2018-08-13 19:04:24 +0000244OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
245 unsigned NumLoops,
246 SourceLocation StartLoc,
247 SourceLocation LParenLoc,
248 SourceLocation EndLoc) {
249 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
250 auto *Clause =
251 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
252 for (unsigned I = 0; I < NumLoops; ++I) {
253 Clause->setLoopNumIterations(I, nullptr);
254 Clause->setLoopCounter(I, nullptr);
255 }
256 return Clause;
257}
258
259OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
260 unsigned NumLoops) {
261 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
262 auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
263 for (unsigned I = 0; I < NumLoops; ++I) {
264 Clause->setLoopNumIterations(I, nullptr);
265 Clause->setLoopCounter(I, nullptr);
266 }
267 return Clause;
268}
269
270void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
271 Expr *NumIterations) {
272 assert(NumLoop < NumberOfLoops && "out of loops number.");
273 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
274}
275
276ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
277 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
278}
279
280void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
281 assert(NumLoop < NumberOfLoops && "out of loops number.");
282 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
283}
284
Mike Rice0ed46662018-09-20 17:19:41 +0000285Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000286 assert(NumLoop < NumberOfLoops && "out of loops number.");
287 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
288}
289
Mike Rice0ed46662018-09-20 17:19:41 +0000290const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000291 assert(NumLoop < NumberOfLoops && "out of loops number.");
292 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
293}
294
James Y Knightb8bfd962015-10-02 13:41:04 +0000295void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
296 assert(VL.size() == varlist_size() &&
297 "Number of private copies is not the same as the preallocated buffer");
298 std::copy(VL.begin(), VL.end(), varlist_end());
299}
300
301OMPPrivateClause *
302OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
303 SourceLocation LParenLoc, SourceLocation EndLoc,
304 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
305 // Allocate space for private variables and initializer expressions.
James Y Knight374fd202016-01-01 00:38:24 +0000306 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000307 OMPPrivateClause *Clause =
308 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
309 Clause->setVarRefs(VL);
310 Clause->setPrivateCopies(PrivateVL);
311 return Clause;
312}
313
314OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
315 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000316 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000317 return new (Mem) OMPPrivateClause(N);
318}
319
320void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
321 assert(VL.size() == varlist_size() &&
322 "Number of private copies is not the same as the preallocated buffer");
323 std::copy(VL.begin(), VL.end(), varlist_end());
324}
325
326void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
327 assert(VL.size() == varlist_size() &&
328 "Number of inits is not the same as the preallocated buffer");
329 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
330}
331
332OMPFirstprivateClause *
333OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
334 SourceLocation LParenLoc, SourceLocation EndLoc,
335 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
Alexey Bataev417089f2016-02-17 13:19:37 +0000336 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
James Y Knight374fd202016-01-01 00:38:24 +0000337 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000338 OMPFirstprivateClause *Clause =
339 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
340 Clause->setVarRefs(VL);
341 Clause->setPrivateCopies(PrivateVL);
342 Clause->setInits(InitVL);
Alexey Bataev417089f2016-02-17 13:19:37 +0000343 Clause->setPreInitStmt(PreInit);
James Y Knightb8bfd962015-10-02 13:41:04 +0000344 return Clause;
345}
346
347OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
348 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000349 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000350 return new (Mem) OMPFirstprivateClause(N);
351}
352
353void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
354 assert(PrivateCopies.size() == varlist_size() &&
355 "Number of private copies is not the same as the preallocated buffer");
356 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
357}
358
359void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
360 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
361 "not the same as the "
362 "preallocated buffer");
363 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
364}
365
366void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
367 assert(DstExprs.size() == varlist_size() && "Number of destination "
368 "expressions is not the same as "
369 "the preallocated buffer");
370 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
371}
372
373void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
374 assert(AssignmentOps.size() == varlist_size() &&
375 "Number of assignment expressions is not the same as the preallocated "
376 "buffer");
377 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
378 getDestinationExprs().end());
379}
380
381OMPLastprivateClause *OMPLastprivateClause::Create(
382 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
383 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
Alexey Bataev005248a2016-02-25 05:25:57 +0000384 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit,
385 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000386 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000387 OMPLastprivateClause *Clause =
388 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
389 Clause->setVarRefs(VL);
390 Clause->setSourceExprs(SrcExprs);
391 Clause->setDestinationExprs(DstExprs);
392 Clause->setAssignmentOps(AssignmentOps);
Alexey Bataev005248a2016-02-25 05:25:57 +0000393 Clause->setPreInitStmt(PreInit);
394 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000395 return Clause;
396}
397
398OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
399 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000400 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000401 return new (Mem) OMPLastprivateClause(N);
402}
403
404OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
405 SourceLocation StartLoc,
406 SourceLocation LParenLoc,
407 SourceLocation EndLoc,
408 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000409 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000410 OMPSharedClause *Clause =
411 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
412 Clause->setVarRefs(VL);
413 return Clause;
414}
415
416OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000417 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000418 return new (Mem) OMPSharedClause(N);
419}
420
421void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
422 assert(PL.size() == varlist_size() &&
423 "Number of privates is not the same as the preallocated buffer");
424 std::copy(PL.begin(), PL.end(), varlist_end());
425}
426
427void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
428 assert(IL.size() == varlist_size() &&
429 "Number of inits is not the same as the preallocated buffer");
430 std::copy(IL.begin(), IL.end(), getPrivates().end());
431}
432
433void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
434 assert(UL.size() == varlist_size() &&
435 "Number of updates is not the same as the preallocated buffer");
436 std::copy(UL.begin(), UL.end(), getInits().end());
437}
438
439void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
440 assert(FL.size() == varlist_size() &&
441 "Number of final updates is not the same as the preallocated buffer");
442 std::copy(FL.begin(), FL.end(), getUpdates().end());
443}
444
Alexey Bataev195ae902019-08-08 13:42:45 +0000445void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) {
446 assert(
447 UE.size() == varlist_size() + 1 &&
448 "Number of used expressions is not the same as the preallocated buffer");
449 std::copy(UE.begin(), UE.end(), getFinals().end() + 2);
450}
451
James Y Knightb8bfd962015-10-02 13:41:04 +0000452OMPLinearClause *OMPLinearClause::Create(
453 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
454 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
455 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
Alexey Bataev78849fb2016-03-09 09:49:00 +0000456 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
457 Stmt *PreInit, Expr *PostUpdate) {
Alexey Bataev195ae902019-08-08 13:42:45 +0000458 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
459 // (Step and CalcStep), list of used expression + step.
460 void *Mem =
461 C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000462 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
463 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
464 Clause->setVarRefs(VL);
465 Clause->setPrivates(PL);
466 Clause->setInits(IL);
467 // Fill update and final expressions with zeroes, they are provided later,
468 // after the directive construction.
469 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
470 nullptr);
471 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
472 nullptr);
Alexey Bataev195ae902019-08-08 13:42:45 +0000473 std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(),
474 nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000475 Clause->setStep(Step);
476 Clause->setCalcStep(CalcStep);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000477 Clause->setPreInitStmt(PreInit);
478 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000479 return Clause;
480}
481
482OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
483 unsigned NumVars) {
Alexey Bataev195ae902019-08-08 13:42:45 +0000484 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
485 // (Step and CalcStep), list of used expression + step.
486 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars +1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000487 return new (Mem) OMPLinearClause(NumVars);
488}
489
Alexey Bataev195ae902019-08-08 13:42:45 +0000490OMPClause::child_range OMPLinearClause::used_children() {
491 // Range includes only non-nullptr elements.
492 return child_range(
493 reinterpret_cast<Stmt **>(getUsedExprs().begin()),
494 reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr)));
495}
496
James Y Knightb8bfd962015-10-02 13:41:04 +0000497OMPAlignedClause *
498OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
499 SourceLocation LParenLoc, SourceLocation ColonLoc,
500 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
James Y Knight374fd202016-01-01 00:38:24 +0000501 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000502 OMPAlignedClause *Clause = new (Mem)
503 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
504 Clause->setVarRefs(VL);
505 Clause->setAlignment(A);
506 return Clause;
507}
508
509OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
510 unsigned NumVars) {
James Y Knight374fd202016-01-01 00:38:24 +0000511 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000512 return new (Mem) OMPAlignedClause(NumVars);
513}
514
515void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
516 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
517 "not the same as the "
518 "preallocated buffer");
519 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
520}
521
522void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
523 assert(DstExprs.size() == varlist_size() && "Number of destination "
524 "expressions is not the same as "
525 "the preallocated buffer");
526 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
527}
528
529void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
530 assert(AssignmentOps.size() == varlist_size() &&
531 "Number of assignment expressions is not the same as the preallocated "
532 "buffer");
533 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
534 getDestinationExprs().end());
535}
536
537OMPCopyinClause *OMPCopyinClause::Create(
538 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
539 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
540 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000541 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000542 OMPCopyinClause *Clause =
543 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
544 Clause->setVarRefs(VL);
545 Clause->setSourceExprs(SrcExprs);
546 Clause->setDestinationExprs(DstExprs);
547 Clause->setAssignmentOps(AssignmentOps);
548 return Clause;
549}
550
551OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000552 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000553 return new (Mem) OMPCopyinClause(N);
554}
555
556void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
557 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
558 "not the same as the "
559 "preallocated buffer");
560 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
561}
562
563void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
564 assert(DstExprs.size() == varlist_size() && "Number of destination "
565 "expressions is not the same as "
566 "the preallocated buffer");
567 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
568}
569
570void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
571 assert(AssignmentOps.size() == varlist_size() &&
572 "Number of assignment expressions is not the same as the preallocated "
573 "buffer");
574 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
575 getDestinationExprs().end());
576}
577
578OMPCopyprivateClause *OMPCopyprivateClause::Create(
579 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
580 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
581 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000582 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000583 OMPCopyprivateClause *Clause =
584 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
585 Clause->setVarRefs(VL);
586 Clause->setSourceExprs(SrcExprs);
587 Clause->setDestinationExprs(DstExprs);
588 Clause->setAssignmentOps(AssignmentOps);
589 return Clause;
590}
591
592OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
593 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000594 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000595 return new (Mem) OMPCopyprivateClause(N);
596}
597
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000598void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
599 assert(Privates.size() == varlist_size() &&
600 "Number of private copies is not the same as the preallocated buffer");
601 std::copy(Privates.begin(), Privates.end(), varlist_end());
602}
603
James Y Knightb8bfd962015-10-02 13:41:04 +0000604void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
605 assert(
606 LHSExprs.size() == varlist_size() &&
607 "Number of LHS expressions is not the same as the preallocated buffer");
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000608 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
James Y Knightb8bfd962015-10-02 13:41:04 +0000609}
610
611void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
612 assert(
613 RHSExprs.size() == varlist_size() &&
614 "Number of RHS expressions is not the same as the preallocated buffer");
615 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
616}
617
618void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
619 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
620 "expressions is not the same "
621 "as the preallocated buffer");
622 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
623}
624
625OMPReductionClause *OMPReductionClause::Create(
626 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
627 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
628 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000629 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev61205072016-03-02 04:57:40 +0000630 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
631 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000632 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000633 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
634 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
635 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000636 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000637 Clause->setLHSExprs(LHSExprs);
638 Clause->setRHSExprs(RHSExprs);
639 Clause->setReductionOps(ReductionOps);
Alexey Bataev61205072016-03-02 04:57:40 +0000640 Clause->setPreInitStmt(PreInit);
641 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000642 return Clause;
643}
644
645OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
646 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000647 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000648 return new (Mem) OMPReductionClause(N);
649}
650
Alexey Bataev169d96a2017-07-18 20:17:46 +0000651void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
652 assert(Privates.size() == varlist_size() &&
653 "Number of private copies is not the same as the preallocated buffer");
654 std::copy(Privates.begin(), Privates.end(), varlist_end());
655}
656
657void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
658 assert(
659 LHSExprs.size() == varlist_size() &&
660 "Number of LHS expressions is not the same as the preallocated buffer");
661 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
662}
663
664void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
665 assert(
666 RHSExprs.size() == varlist_size() &&
667 "Number of RHS expressions is not the same as the preallocated buffer");
668 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
669}
670
671void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
672 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
673 "expressions is not the same "
674 "as the preallocated buffer");
675 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
676}
677
678OMPTaskReductionClause *OMPTaskReductionClause::Create(
679 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
680 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
681 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
682 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
683 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
684 Expr *PostUpdate) {
685 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
686 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
687 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
688 Clause->setVarRefs(VL);
689 Clause->setPrivates(Privates);
690 Clause->setLHSExprs(LHSExprs);
691 Clause->setRHSExprs(RHSExprs);
692 Clause->setReductionOps(ReductionOps);
693 Clause->setPreInitStmt(PreInit);
694 Clause->setPostUpdateExpr(PostUpdate);
695 return Clause;
696}
697
698OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
699 unsigned N) {
700 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
701 return new (Mem) OMPTaskReductionClause(N);
702}
703
Alexey Bataevfa312f32017-07-21 18:48:21 +0000704void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
705 assert(Privates.size() == varlist_size() &&
706 "Number of private copies is not the same as the preallocated buffer");
707 std::copy(Privates.begin(), Privates.end(), varlist_end());
708}
709
710void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
711 assert(
712 LHSExprs.size() == varlist_size() &&
713 "Number of LHS expressions is not the same as the preallocated buffer");
714 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
715}
716
717void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
718 assert(
719 RHSExprs.size() == varlist_size() &&
720 "Number of RHS expressions is not the same as the preallocated buffer");
721 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
722}
723
724void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
725 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
726 "expressions is not the same "
727 "as the preallocated buffer");
728 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
729}
730
Alexey Bataev88202be2017-07-27 13:20:36 +0000731void OMPInReductionClause::setTaskgroupDescriptors(
732 ArrayRef<Expr *> TaskgroupDescriptors) {
733 assert(TaskgroupDescriptors.size() == varlist_size() &&
734 "Number of in reduction descriptors is not the same as the "
735 "preallocated buffer");
736 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
737 getReductionOps().end());
738}
739
Alexey Bataevfa312f32017-07-21 18:48:21 +0000740OMPInReductionClause *OMPInReductionClause::Create(
741 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
742 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
743 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
744 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev88202be2017-07-27 13:20:36 +0000745 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
746 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
747 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000748 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
749 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
750 Clause->setVarRefs(VL);
751 Clause->setPrivates(Privates);
752 Clause->setLHSExprs(LHSExprs);
753 Clause->setRHSExprs(RHSExprs);
754 Clause->setReductionOps(ReductionOps);
Alexey Bataev88202be2017-07-27 13:20:36 +0000755 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000756 Clause->setPreInitStmt(PreInit);
757 Clause->setPostUpdateExpr(PostUpdate);
758 return Clause;
759}
760
761OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
762 unsigned N) {
Alexey Bataev88202be2017-07-27 13:20:36 +0000763 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000764 return new (Mem) OMPInReductionClause(N);
765}
766
Alexey Bataeve04483e2019-03-27 14:14:31 +0000767OMPAllocateClause *
768OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc,
769 SourceLocation LParenLoc, Expr *Allocator,
770 SourceLocation ColonLoc, SourceLocation EndLoc,
771 ArrayRef<Expr *> VL) {
772 // Allocate space for private variables and initializer expressions.
773 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
774 auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
775 ColonLoc, EndLoc, VL.size());
776 Clause->setVarRefs(VL);
777 return Clause;
778}
779
780OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
781 unsigned N) {
782 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
783 return new (Mem) OMPAllocateClause(N);
784}
785
James Y Knightb8bfd962015-10-02 13:41:04 +0000786OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
787 SourceLocation StartLoc,
788 SourceLocation LParenLoc,
789 SourceLocation EndLoc,
790 ArrayRef<Expr *> VL) {
Alexey Bataev8b427062016-05-25 12:36:08 +0000791 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000792 OMPFlushClause *Clause =
793 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
794 Clause->setVarRefs(VL);
795 return Clause;
796}
797
798OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000799 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000800 return new (Mem) OMPFlushClause(N);
801}
802
Alexey Bataevf138fda2018-08-13 19:04:24 +0000803OMPDependClause *
804OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
805 SourceLocation LParenLoc, SourceLocation EndLoc,
806 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
807 SourceLocation ColonLoc, ArrayRef<Expr *> VL,
808 unsigned NumLoops) {
809 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
810 OMPDependClause *Clause = new (Mem)
811 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000812 Clause->setVarRefs(VL);
813 Clause->setDependencyKind(DepKind);
814 Clause->setDependencyLoc(DepLoc);
815 Clause->setColonLoc(ColonLoc);
Alexey Bataevf138fda2018-08-13 19:04:24 +0000816 for (unsigned I = 0 ; I < NumLoops; ++I)
817 Clause->setLoopData(I, nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000818 return Clause;
819}
820
Alexey Bataevf138fda2018-08-13 19:04:24 +0000821OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
822 unsigned NumLoops) {
823 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
824 return new (Mem) OMPDependClause(N, NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000825}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000826
Alexey Bataevf138fda2018-08-13 19:04:24 +0000827void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
828 assert((getDependencyKind() == OMPC_DEPEND_sink ||
829 getDependencyKind() == OMPC_DEPEND_source) &&
830 NumLoop < NumLoops &&
831 "Expected sink or source depend + loop index must be less number of "
832 "loops.");
833 auto It = std::next(getVarRefs().end(), NumLoop);
834 *It = Cnt;
Alexey Bataev8b427062016-05-25 12:36:08 +0000835}
836
Alexey Bataevf138fda2018-08-13 19:04:24 +0000837Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
838 assert((getDependencyKind() == OMPC_DEPEND_sink ||
839 getDependencyKind() == OMPC_DEPEND_source) &&
840 NumLoop < NumLoops &&
841 "Expected sink or source depend + loop index must be less number of "
842 "loops.");
843 auto It = std::next(getVarRefs().end(), NumLoop);
844 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000845}
846
Alexey Bataevf138fda2018-08-13 19:04:24 +0000847const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
848 assert((getDependencyKind() == OMPC_DEPEND_sink ||
849 getDependencyKind() == OMPC_DEPEND_source) &&
850 NumLoop < NumLoops &&
851 "Expected sink or source depend + loop index must be less number of "
852 "loops.");
853 auto It = std::next(getVarRefs().end(), NumLoop);
854 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000855}
856
Samuel Antao90927002016-04-26 14:54:23 +0000857unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
858 MappableExprComponentListsRef ComponentLists) {
859 unsigned TotalNum = 0u;
860 for (auto &C : ComponentLists)
861 TotalNum += C.size();
862 return TotalNum;
863}
864
865unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
Alexey Bataeve3727102018-04-18 15:57:46 +0000866 ArrayRef<const ValueDecl *> Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000867 unsigned TotalNum = 0u;
868 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
Alexey Bataeve3727102018-04-18 15:57:46 +0000869 for (const ValueDecl *D : Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000870 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
871 if (Cache.count(VD))
872 continue;
873 ++TotalNum;
874 Cache.insert(VD);
875 }
876 return TotalNum;
877}
878
Michael Kruse4304e9d2019-02-19 16:38:20 +0000879OMPMapClause *OMPMapClause::Create(
880 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
881 ArrayRef<ValueDecl *> Declarations,
882 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
883 ArrayRef<OpenMPMapModifierKind> MapModifiers,
884 ArrayRef<SourceLocation> MapModifiersLoc,
885 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
886 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
887 OMPMappableExprListSizeTy Sizes;
888 Sizes.NumVars = Vars.size();
889 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
890 Sizes.NumComponentLists = ComponentLists.size();
891 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao90927002016-04-26 14:54:23 +0000892
893 // We need to allocate:
Michael Kruse4304e9d2019-02-19 16:38:20 +0000894 // 2 x NumVars x Expr* - we have an original list expression and an associated
895 // user-defined mapper for each clause list entry.
Samuel Antao90927002016-04-26 14:54:23 +0000896 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
897 // with each component list.
898 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
899 // number of lists for each unique declaration and the size of each component
900 // list.
901 // NumComponents x MappableComponent - the total of all the components in all
902 // the lists.
903 void *Mem = C.Allocate(
904 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
905 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000906 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
907 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
908 Sizes.NumComponents));
909 OMPMapClause *Clause = new (Mem)
910 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
911 Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
Samuel Antao90927002016-04-26 14:54:23 +0000912
913 Clause->setVarRefs(Vars);
Michael Kruse4304e9d2019-02-19 16:38:20 +0000914 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao90927002016-04-26 14:54:23 +0000915 Clause->setClauseInfo(Declarations, ComponentLists);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000916 Clause->setMapType(Type);
917 Clause->setMapLoc(TypeLoc);
918 return Clause;
919}
920
Michael Kruse4304e9d2019-02-19 16:38:20 +0000921OMPMapClause *
922OMPMapClause::CreateEmpty(const ASTContext &C,
923 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao90927002016-04-26 14:54:23 +0000924 void *Mem = C.Allocate(
925 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
926 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000927 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
928 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
929 Sizes.NumComponents));
930 return new (Mem) OMPMapClause(Sizes);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000931}
Samuel Antao661c0902016-05-26 17:39:58 +0000932
Michael Kruse01f670d2019-02-22 22:29:42 +0000933OMPToClause *OMPToClause::Create(
934 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
935 ArrayRef<ValueDecl *> Declarations,
936 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
937 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000938 OMPMappableExprListSizeTy Sizes;
939 Sizes.NumVars = Vars.size();
940 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
941 Sizes.NumComponentLists = ComponentLists.size();
942 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao661c0902016-05-26 17:39:58 +0000943
944 // We need to allocate:
Michael Kruse01f670d2019-02-22 22:29:42 +0000945 // 2 x NumVars x Expr* - we have an original list expression and an associated
946 // user-defined mapper for each clause list entry.
Samuel Antao661c0902016-05-26 17:39:58 +0000947 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
948 // with each component list.
949 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
950 // number of lists for each unique declaration and the size of each component
951 // list.
952 // NumComponents x MappableComponent - the total of all the components in all
953 // the lists.
954 void *Mem = C.Allocate(
955 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
956 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +0000957 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000958 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
959 Sizes.NumComponents));
Samuel Antao661c0902016-05-26 17:39:58 +0000960
Michael Kruse01f670d2019-02-22 22:29:42 +0000961 auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +0000962
963 Clause->setVarRefs(Vars);
Michael Kruse01f670d2019-02-22 22:29:42 +0000964 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao661c0902016-05-26 17:39:58 +0000965 Clause->setClauseInfo(Declarations, ComponentLists);
966 return Clause;
967}
968
Michael Kruse4304e9d2019-02-19 16:38:20 +0000969OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
970 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao661c0902016-05-26 17:39:58 +0000971 void *Mem = C.Allocate(
972 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
973 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +0000974 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000975 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
976 Sizes.NumComponents));
977 return new (Mem) OMPToClause(Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +0000978}
Samuel Antaoec172c62016-05-26 17:49:04 +0000979
Michael Kruse0336c752019-02-25 20:34:15 +0000980OMPFromClause *OMPFromClause::Create(
981 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
982 ArrayRef<ValueDecl *> Declarations,
983 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
984 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000985 OMPMappableExprListSizeTy Sizes;
986 Sizes.NumVars = Vars.size();
987 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
988 Sizes.NumComponentLists = ComponentLists.size();
989 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaoec172c62016-05-26 17:49:04 +0000990
991 // We need to allocate:
Michael Kruse0336c752019-02-25 20:34:15 +0000992 // 2 x NumVars x Expr* - we have an original list expression and an associated
993 // user-defined mapper for each clause list entry.
Samuel Antaoec172c62016-05-26 17:49:04 +0000994 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
995 // with each component list.
996 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
997 // number of lists for each unique declaration and the size of each component
998 // list.
999 // NumComponents x MappableComponent - the total of all the components in all
1000 // the lists.
1001 void *Mem = C.Allocate(
1002 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1003 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001004 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001005 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1006 Sizes.NumComponents));
Samuel Antaoec172c62016-05-26 17:49:04 +00001007
Michael Kruse0336c752019-02-25 20:34:15 +00001008 auto *Clause =
1009 new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001010
1011 Clause->setVarRefs(Vars);
Michael Kruse0336c752019-02-25 20:34:15 +00001012 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antaoec172c62016-05-26 17:49:04 +00001013 Clause->setClauseInfo(Declarations, ComponentLists);
1014 return Clause;
1015}
1016
Michael Kruse4304e9d2019-02-19 16:38:20 +00001017OMPFromClause *
1018OMPFromClause::CreateEmpty(const ASTContext &C,
1019 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaoec172c62016-05-26 17:49:04 +00001020 void *Mem = C.Allocate(
1021 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1022 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001023 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001024 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1025 Sizes.NumComponents));
1026 return new (Mem) OMPFromClause(Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001027}
Carlo Bertolli2404b172016-07-13 15:37:16 +00001028
Samuel Antaocc10b852016-07-28 14:23:26 +00001029void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1030 assert(VL.size() == varlist_size() &&
1031 "Number of private copies is not the same as the preallocated buffer");
1032 std::copy(VL.begin(), VL.end(), varlist_end());
1033}
1034
1035void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
1036 assert(VL.size() == varlist_size() &&
1037 "Number of inits is not the same as the preallocated buffer");
1038 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1039}
1040
1041OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001042 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1043 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
1044 ArrayRef<ValueDecl *> Declarations,
Samuel Antaocc10b852016-07-28 14:23:26 +00001045 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001046 OMPMappableExprListSizeTy Sizes;
1047 Sizes.NumVars = Vars.size();
1048 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1049 Sizes.NumComponentLists = ComponentLists.size();
1050 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaocc10b852016-07-28 14:23:26 +00001051
1052 // We need to allocate:
1053 // 3 x NumVars x Expr* - we have an original list expression for each clause
1054 // list entry and an equal number of private copies and inits.
1055 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1056 // with each component list.
1057 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1058 // number of lists for each unique declaration and the size of each component
1059 // list.
1060 // NumComponents x MappableComponent - the total of all the components in all
1061 // the lists.
1062 void *Mem = C.Allocate(
1063 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1064 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001065 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1066 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1067 Sizes.NumComponents));
Samuel Antaocc10b852016-07-28 14:23:26 +00001068
Michael Kruse4304e9d2019-02-19 16:38:20 +00001069 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
Samuel Antaocc10b852016-07-28 14:23:26 +00001070
1071 Clause->setVarRefs(Vars);
1072 Clause->setPrivateCopies(PrivateVars);
1073 Clause->setInits(Inits);
1074 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001075 return Clause;
1076}
1077
Michael Kruse4304e9d2019-02-19 16:38:20 +00001078OMPUseDevicePtrClause *
1079OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
1080 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaocc10b852016-07-28 14:23:26 +00001081 void *Mem = C.Allocate(
1082 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1083 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001084 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1085 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1086 Sizes.NumComponents));
1087 return new (Mem) OMPUseDevicePtrClause(Sizes);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001088}
Carlo Bertolli70594e92016-07-13 17:16:49 +00001089
Samuel Antao6890b092016-07-28 14:25:09 +00001090OMPIsDevicePtrClause *
Michael Kruse4304e9d2019-02-19 16:38:20 +00001091OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
Samuel Antao6890b092016-07-28 14:25:09 +00001092 ArrayRef<Expr *> Vars,
1093 ArrayRef<ValueDecl *> Declarations,
1094 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001095 OMPMappableExprListSizeTy Sizes;
1096 Sizes.NumVars = Vars.size();
1097 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1098 Sizes.NumComponentLists = ComponentLists.size();
1099 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao6890b092016-07-28 14:25:09 +00001100
1101 // We need to allocate:
1102 // NumVars x Expr* - we have an original list expression for each clause list
1103 // entry.
1104 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1105 // with each component list.
1106 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1107 // number of lists for each unique declaration and the size of each component
1108 // list.
1109 // NumComponents x MappableComponent - the total of all the components in all
1110 // the lists.
1111 void *Mem = C.Allocate(
1112 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1113 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001114 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1115 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1116 Sizes.NumComponents));
Samuel Antao6890b092016-07-28 14:25:09 +00001117
Michael Kruse4304e9d2019-02-19 16:38:20 +00001118 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
Samuel Antao6890b092016-07-28 14:25:09 +00001119
1120 Clause->setVarRefs(Vars);
1121 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001122 return Clause;
1123}
1124
Michael Kruse4304e9d2019-02-19 16:38:20 +00001125OMPIsDevicePtrClause *
1126OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1127 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao6890b092016-07-28 14:25:09 +00001128 void *Mem = C.Allocate(
1129 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1130 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001131 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1132 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1133 Sizes.NumComponents));
1134 return new (Mem) OMPIsDevicePtrClause(Sizes);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001135}
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001136
1137//===----------------------------------------------------------------------===//
1138// OpenMP clauses printing methods
1139//===----------------------------------------------------------------------===//
1140
1141void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1142 OS << "if(";
1143 if (Node->getNameModifier() != OMPD_unknown)
1144 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1145 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1146 OS << ")";
1147}
1148
1149void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1150 OS << "final(";
1151 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1152 OS << ")";
1153}
1154
1155void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1156 OS << "num_threads(";
1157 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1158 OS << ")";
1159}
1160
1161void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1162 OS << "safelen(";
1163 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1164 OS << ")";
1165}
1166
1167void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1168 OS << "simdlen(";
1169 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1170 OS << ")";
1171}
1172
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00001173void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
1174 OS << "allocator(";
1175 Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
1176 OS << ")";
1177}
1178
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001179void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1180 OS << "collapse(";
1181 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1182 OS << ")";
1183}
1184
1185void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1186 OS << "default("
1187 << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
1188 << ")";
1189}
1190
1191void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1192 OS << "proc_bind("
1193 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, Node->getProcBindKind())
1194 << ")";
1195}
1196
1197void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1198 OS << "unified_address";
1199}
1200
1201void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1202 OMPUnifiedSharedMemoryClause *) {
1203 OS << "unified_shared_memory";
1204}
1205
1206void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1207 OS << "reverse_offload";
1208}
1209
1210void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1211 OMPDynamicAllocatorsClause *) {
1212 OS << "dynamic_allocators";
1213}
1214
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00001215void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1216 OMPAtomicDefaultMemOrderClause *Node) {
1217 OS << "atomic_default_mem_order("
1218 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1219 Node->getAtomicDefaultMemOrderKind())
1220 << ")";
1221}
1222
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001223void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1224 OS << "schedule(";
1225 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1226 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1227 Node->getFirstScheduleModifier());
1228 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1229 OS << ", ";
1230 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1231 Node->getSecondScheduleModifier());
1232 }
1233 OS << ": ";
1234 }
1235 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1236 if (auto *E = Node->getChunkSize()) {
1237 OS << ", ";
1238 E->printPretty(OS, nullptr, Policy);
1239 }
1240 OS << ")";
1241}
1242
1243void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1244 OS << "ordered";
1245 if (auto *Num = Node->getNumForLoops()) {
1246 OS << "(";
1247 Num->printPretty(OS, nullptr, Policy, 0);
1248 OS << ")";
1249 }
1250}
1251
1252void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1253 OS << "nowait";
1254}
1255
1256void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1257 OS << "untied";
1258}
1259
1260void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1261 OS << "nogroup";
1262}
1263
1264void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1265 OS << "mergeable";
1266}
1267
1268void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1269
1270void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1271
1272void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
1273 OS << "update";
1274}
1275
1276void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1277 OS << "capture";
1278}
1279
1280void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1281 OS << "seq_cst";
1282}
1283
1284void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1285 OS << "threads";
1286}
1287
1288void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1289
1290void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1291 OS << "device(";
1292 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1293 OS << ")";
1294}
1295
1296void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1297 OS << "num_teams(";
1298 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1299 OS << ")";
1300}
1301
1302void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1303 OS << "thread_limit(";
1304 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1305 OS << ")";
1306}
1307
1308void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1309 OS << "priority(";
1310 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1311 OS << ")";
1312}
1313
1314void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1315 OS << "grainsize(";
1316 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1317 OS << ")";
1318}
1319
1320void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1321 OS << "num_tasks(";
1322 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1323 OS << ")";
1324}
1325
1326void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1327 OS << "hint(";
1328 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1329 OS << ")";
1330}
1331
1332template<typename T>
1333void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1334 for (typename T::varlist_iterator I = Node->varlist_begin(),
1335 E = Node->varlist_end();
1336 I != E; ++I) {
1337 assert(*I && "Expected non-null Stmt");
1338 OS << (I == Node->varlist_begin() ? StartSym : ',');
1339 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1340 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1341 DRE->printPretty(OS, nullptr, Policy, 0);
1342 else
1343 DRE->getDecl()->printQualifiedName(OS);
1344 } else
1345 (*I)->printPretty(OS, nullptr, Policy, 0);
1346 }
1347}
1348
Alexey Bataeve04483e2019-03-27 14:14:31 +00001349void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
1350 if (Node->varlist_empty())
1351 return;
1352 OS << "allocate";
1353 if (Expr *Allocator = Node->getAllocator()) {
1354 OS << "(";
1355 Allocator->printPretty(OS, nullptr, Policy, 0);
1356 OS << ":";
1357 VisitOMPClauseList(Node, ' ');
1358 } else {
1359 VisitOMPClauseList(Node, '(');
1360 }
1361 OS << ")";
1362}
1363
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001364void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1365 if (!Node->varlist_empty()) {
1366 OS << "private";
1367 VisitOMPClauseList(Node, '(');
1368 OS << ")";
1369 }
1370}
1371
1372void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1373 if (!Node->varlist_empty()) {
1374 OS << "firstprivate";
1375 VisitOMPClauseList(Node, '(');
1376 OS << ")";
1377 }
1378}
1379
1380void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1381 if (!Node->varlist_empty()) {
1382 OS << "lastprivate";
1383 VisitOMPClauseList(Node, '(');
1384 OS << ")";
1385 }
1386}
1387
1388void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1389 if (!Node->varlist_empty()) {
1390 OS << "shared";
1391 VisitOMPClauseList(Node, '(');
1392 OS << ")";
1393 }
1394}
1395
1396void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1397 if (!Node->varlist_empty()) {
1398 OS << "reduction(";
1399 NestedNameSpecifier *QualifierLoc =
1400 Node->getQualifierLoc().getNestedNameSpecifier();
1401 OverloadedOperatorKind OOK =
1402 Node->getNameInfo().getName().getCXXOverloadedOperator();
1403 if (QualifierLoc == nullptr && OOK != OO_None) {
1404 // Print reduction identifier in C format
1405 OS << getOperatorSpelling(OOK);
1406 } else {
1407 // Use C++ format
1408 if (QualifierLoc != nullptr)
1409 QualifierLoc->print(OS, Policy);
1410 OS << Node->getNameInfo();
1411 }
1412 OS << ":";
1413 VisitOMPClauseList(Node, ' ');
1414 OS << ")";
1415 }
1416}
1417
1418void OMPClausePrinter::VisitOMPTaskReductionClause(
1419 OMPTaskReductionClause *Node) {
1420 if (!Node->varlist_empty()) {
1421 OS << "task_reduction(";
1422 NestedNameSpecifier *QualifierLoc =
1423 Node->getQualifierLoc().getNestedNameSpecifier();
1424 OverloadedOperatorKind OOK =
1425 Node->getNameInfo().getName().getCXXOverloadedOperator();
1426 if (QualifierLoc == nullptr && OOK != OO_None) {
1427 // Print reduction identifier in C format
1428 OS << getOperatorSpelling(OOK);
1429 } else {
1430 // Use C++ format
1431 if (QualifierLoc != nullptr)
1432 QualifierLoc->print(OS, Policy);
1433 OS << Node->getNameInfo();
1434 }
1435 OS << ":";
1436 VisitOMPClauseList(Node, ' ');
1437 OS << ")";
1438 }
1439}
1440
1441void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1442 if (!Node->varlist_empty()) {
1443 OS << "in_reduction(";
1444 NestedNameSpecifier *QualifierLoc =
1445 Node->getQualifierLoc().getNestedNameSpecifier();
1446 OverloadedOperatorKind OOK =
1447 Node->getNameInfo().getName().getCXXOverloadedOperator();
1448 if (QualifierLoc == nullptr && OOK != OO_None) {
1449 // Print reduction identifier in C format
1450 OS << getOperatorSpelling(OOK);
1451 } else {
1452 // Use C++ format
1453 if (QualifierLoc != nullptr)
1454 QualifierLoc->print(OS, Policy);
1455 OS << Node->getNameInfo();
1456 }
1457 OS << ":";
1458 VisitOMPClauseList(Node, ' ');
1459 OS << ")";
1460 }
1461}
1462
1463void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1464 if (!Node->varlist_empty()) {
1465 OS << "linear";
1466 if (Node->getModifierLoc().isValid()) {
1467 OS << '('
1468 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1469 }
1470 VisitOMPClauseList(Node, '(');
1471 if (Node->getModifierLoc().isValid())
1472 OS << ')';
1473 if (Node->getStep() != nullptr) {
1474 OS << ": ";
1475 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1476 }
1477 OS << ")";
1478 }
1479}
1480
1481void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1482 if (!Node->varlist_empty()) {
1483 OS << "aligned";
1484 VisitOMPClauseList(Node, '(');
1485 if (Node->getAlignment() != nullptr) {
1486 OS << ": ";
1487 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1488 }
1489 OS << ")";
1490 }
1491}
1492
1493void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1494 if (!Node->varlist_empty()) {
1495 OS << "copyin";
1496 VisitOMPClauseList(Node, '(');
1497 OS << ")";
1498 }
1499}
1500
1501void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1502 if (!Node->varlist_empty()) {
1503 OS << "copyprivate";
1504 VisitOMPClauseList(Node, '(');
1505 OS << ")";
1506 }
1507}
1508
1509void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1510 if (!Node->varlist_empty()) {
1511 VisitOMPClauseList(Node, '(');
1512 OS << ")";
1513 }
1514}
1515
1516void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1517 OS << "depend(";
1518 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1519 Node->getDependencyKind());
1520 if (!Node->varlist_empty()) {
1521 OS << " :";
1522 VisitOMPClauseList(Node, ' ');
1523 }
1524 OS << ")";
1525}
1526
1527void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1528 if (!Node->varlist_empty()) {
1529 OS << "map(";
1530 if (Node->getMapType() != OMPC_MAP_unknown) {
Kelvin Lief579432018-12-18 22:18:41 +00001531 for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1532 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1533 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1534 Node->getMapTypeModifier(I));
Michael Kruse4304e9d2019-02-19 16:38:20 +00001535 if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1536 OS << '(';
1537 NestedNameSpecifier *MapperNNS =
1538 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1539 if (MapperNNS)
1540 MapperNNS->print(OS, Policy);
1541 OS << Node->getMapperIdInfo() << ')';
1542 }
Kelvin Lief579432018-12-18 22:18:41 +00001543 OS << ',';
1544 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001545 }
1546 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1547 OS << ':';
1548 }
1549 VisitOMPClauseList(Node, ' ');
1550 OS << ")";
1551 }
1552}
1553
1554void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1555 if (!Node->varlist_empty()) {
1556 OS << "to";
Michael Kruse01f670d2019-02-22 22:29:42 +00001557 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1558 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1559 OS << '(';
1560 OS << "mapper(";
1561 NestedNameSpecifier *MapperNNS =
1562 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1563 if (MapperNNS)
1564 MapperNNS->print(OS, Policy);
1565 OS << MapperId << "):";
1566 VisitOMPClauseList(Node, ' ');
1567 } else {
1568 VisitOMPClauseList(Node, '(');
1569 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001570 OS << ")";
1571 }
1572}
1573
1574void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1575 if (!Node->varlist_empty()) {
1576 OS << "from";
Michael Kruse0336c752019-02-25 20:34:15 +00001577 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1578 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1579 OS << '(';
1580 OS << "mapper(";
1581 NestedNameSpecifier *MapperNNS =
1582 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1583 if (MapperNNS)
1584 MapperNNS->print(OS, Policy);
1585 OS << MapperId << "):";
1586 VisitOMPClauseList(Node, ' ');
1587 } else {
1588 VisitOMPClauseList(Node, '(');
1589 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001590 OS << ")";
1591 }
1592}
1593
1594void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1595 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1596 OMPC_dist_schedule, Node->getDistScheduleKind());
1597 if (auto *E = Node->getChunkSize()) {
1598 OS << ", ";
1599 E->printPretty(OS, nullptr, Policy);
1600 }
1601 OS << ")";
1602}
1603
1604void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1605 OS << "defaultmap(";
1606 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1607 Node->getDefaultmapModifier());
1608 OS << ": ";
1609 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1610 Node->getDefaultmapKind());
1611 OS << ")";
1612}
1613
1614void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1615 if (!Node->varlist_empty()) {
1616 OS << "use_device_ptr";
1617 VisitOMPClauseList(Node, '(');
1618 OS << ")";
1619 }
1620}
1621
1622void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1623 if (!Node->varlist_empty()) {
1624 OS << "is_device_ptr";
1625 VisitOMPClauseList(Node, '(');
1626 OS << ")";
1627 }
1628}
1629