blob: fe1334469d48621db85d77e8bf59570e5820d754 [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 Bataevd88c7de2019-10-14 20:44:34 +000089 case OMPC_num_tasks:
90 return static_cast<const OMPNumTasksClause *>(C);
Alexey Bataev3a842ec2019-10-15 19:37:05 +000091 case OMPC_final:
92 return static_cast<const OMPFinalClause *>(C);
Alexey Bataev31ba4762019-10-16 18:09:37 +000093 case OMPC_priority:
94 return static_cast<const OMPPriorityClause *>(C);
Alexey Bataev3392d762016-02-16 11:18:12 +000095 case OMPC_default:
96 case OMPC_proc_bind:
Alexey Bataev3392d762016-02-16 11:18:12 +000097 case OMPC_safelen:
98 case OMPC_simdlen:
Alexey Bataev9cc10fc2019-03-12 18:52:33 +000099 case OMPC_allocator:
Alexey Bataeve04483e2019-03-27 14:14:31 +0000100 case OMPC_allocate:
Alexey Bataev3392d762016-02-16 11:18:12 +0000101 case OMPC_collapse:
102 case OMPC_private:
Alexey Bataev005248a2016-02-25 05:25:57 +0000103 case OMPC_shared:
Alexey Bataev005248a2016-02-25 05:25:57 +0000104 case OMPC_aligned:
105 case OMPC_copyin:
106 case OMPC_copyprivate:
107 case OMPC_ordered:
108 case OMPC_nowait:
109 case OMPC_untied:
110 case OMPC_mergeable:
111 case OMPC_threadprivate:
112 case OMPC_flush:
113 case OMPC_read:
114 case OMPC_write:
115 case OMPC_update:
116 case OMPC_capture:
117 case OMPC_seq_cst:
118 case OMPC_depend:
Alexey Bataev005248a2016-02-25 05:25:57 +0000119 case OMPC_threads:
120 case OMPC_simd:
121 case OMPC_map:
Alexey Bataev005248a2016-02-25 05:25:57 +0000122 case OMPC_nogroup:
Alexey Bataev005248a2016-02-25 05:25:57 +0000123 case OMPC_hint:
124 case OMPC_defaultmap:
125 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000126 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000127 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000128 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000129 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000130 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000131 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000132 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000133 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000134 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000135 case OMPC_atomic_default_mem_order:
Alexey Bataev729e2422019-08-23 16:11:14 +0000136 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +0000137 case OMPC_match:
Alexey Bataev005248a2016-02-25 05:25:57 +0000138 break;
139 }
140
141 return nullptr;
142}
143
144OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
145 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
146 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
147}
148
149const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
150 switch (C->getClauseKind()) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000151 case OMPC_lastprivate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000152 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000153 case OMPC_reduction:
154 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +0000155 case OMPC_task_reduction:
156 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000157 case OMPC_in_reduction:
158 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000159 case OMPC_linear:
160 return static_cast<const OMPLinearClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000161 case OMPC_schedule:
162 case OMPC_dist_schedule:
163 case OMPC_firstprivate:
164 case OMPC_default:
165 case OMPC_proc_bind:
166 case OMPC_if:
167 case OMPC_final:
168 case OMPC_num_threads:
169 case OMPC_safelen:
170 case OMPC_simdlen:
Alexey Bataev9cc10fc2019-03-12 18:52:33 +0000171 case OMPC_allocator:
Alexey Bataeve04483e2019-03-27 14:14:31 +0000172 case OMPC_allocate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000173 case OMPC_collapse:
174 case OMPC_private:
Alexey Bataev3392d762016-02-16 11:18:12 +0000175 case OMPC_shared:
Alexey Bataev3392d762016-02-16 11:18:12 +0000176 case OMPC_aligned:
177 case OMPC_copyin:
178 case OMPC_copyprivate:
179 case OMPC_ordered:
180 case OMPC_nowait:
181 case OMPC_untied:
182 case OMPC_mergeable:
183 case OMPC_threadprivate:
184 case OMPC_flush:
185 case OMPC_read:
186 case OMPC_write:
187 case OMPC_update:
188 case OMPC_capture:
189 case OMPC_seq_cst:
190 case OMPC_depend:
191 case OMPC_device:
192 case OMPC_threads:
193 case OMPC_simd:
194 case OMPC_map:
195 case OMPC_num_teams:
196 case OMPC_thread_limit:
197 case OMPC_priority:
198 case OMPC_grainsize:
199 case OMPC_nogroup:
200 case OMPC_num_tasks:
201 case OMPC_hint:
202 case OMPC_defaultmap:
203 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000204 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000205 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000206 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000207 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000208 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000209 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000210 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000211 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000212 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000213 case OMPC_atomic_default_mem_order:
Alexey Bataev729e2422019-08-23 16:11:14 +0000214 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +0000215 case OMPC_match:
Alexey Bataev3392d762016-02-16 11:18:12 +0000216 break;
217 }
218
219 return nullptr;
220}
221
Alexey Bataev655cb4a2019-07-16 14:51:46 +0000222/// Gets the address of the original, non-captured, expression used in the
223/// clause as the preinitializer.
224static Stmt **getAddrOfExprAsWritten(Stmt *S) {
225 if (!S)
226 return nullptr;
227 if (auto *DS = dyn_cast<DeclStmt>(S)) {
228 assert(DS->isSingleDecl() && "Only single expression must be captured.");
229 if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
230 return OED->getInitAddress();
231 }
232 return nullptr;
233}
234
235OMPClause::child_range OMPIfClause::used_children() {
236 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
237 return child_range(C, C + 1);
238 return child_range(&Condition, &Condition + 1);
239}
240
Alexey Bataevb9c55e22019-10-14 19:29:52 +0000241OMPClause::child_range OMPGrainsizeClause::used_children() {
242 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
243 return child_range(C, C + 1);
244 return child_range(&Grainsize, &Grainsize + 1);
245}
246
Alexey Bataevd88c7de2019-10-14 20:44:34 +0000247OMPClause::child_range OMPNumTasksClause::used_children() {
248 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
249 return child_range(C, C + 1);
250 return child_range(&NumTasks, &NumTasks + 1);
251}
252
Alexey Bataev3a842ec2019-10-15 19:37:05 +0000253OMPClause::child_range OMPFinalClause::used_children() {
254 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
255 return child_range(C, C + 1);
256 return child_range(&Condition, &Condition + 1);
257}
258
Alexey Bataev31ba4762019-10-16 18:09:37 +0000259OMPClause::child_range OMPPriorityClause::used_children() {
260 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
261 return child_range(C, C + 1);
262 return child_range(&Priority, &Priority + 1);
263}
264
Alexey Bataevf138fda2018-08-13 19:04:24 +0000265OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
266 unsigned NumLoops,
267 SourceLocation StartLoc,
268 SourceLocation LParenLoc,
269 SourceLocation EndLoc) {
270 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
271 auto *Clause =
272 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
273 for (unsigned I = 0; I < NumLoops; ++I) {
274 Clause->setLoopNumIterations(I, nullptr);
275 Clause->setLoopCounter(I, nullptr);
276 }
277 return Clause;
278}
279
280OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
281 unsigned NumLoops) {
282 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
283 auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
284 for (unsigned I = 0; I < NumLoops; ++I) {
285 Clause->setLoopNumIterations(I, nullptr);
286 Clause->setLoopCounter(I, nullptr);
287 }
288 return Clause;
289}
290
291void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
292 Expr *NumIterations) {
293 assert(NumLoop < NumberOfLoops && "out of loops number.");
294 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
295}
296
297ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
298 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
299}
300
301void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
302 assert(NumLoop < NumberOfLoops && "out of loops number.");
303 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
304}
305
Mike Rice0ed46662018-09-20 17:19:41 +0000306Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000307 assert(NumLoop < NumberOfLoops && "out of loops number.");
308 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
309}
310
Mike Rice0ed46662018-09-20 17:19:41 +0000311const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000312 assert(NumLoop < NumberOfLoops && "out of loops number.");
313 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
314}
315
James Y Knightb8bfd962015-10-02 13:41:04 +0000316void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
317 assert(VL.size() == varlist_size() &&
318 "Number of private copies is not the same as the preallocated buffer");
319 std::copy(VL.begin(), VL.end(), varlist_end());
320}
321
322OMPPrivateClause *
323OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
324 SourceLocation LParenLoc, SourceLocation EndLoc,
325 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
326 // Allocate space for private variables and initializer expressions.
James Y Knight374fd202016-01-01 00:38:24 +0000327 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000328 OMPPrivateClause *Clause =
329 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
330 Clause->setVarRefs(VL);
331 Clause->setPrivateCopies(PrivateVL);
332 return Clause;
333}
334
335OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
336 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000337 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000338 return new (Mem) OMPPrivateClause(N);
339}
340
341void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
342 assert(VL.size() == varlist_size() &&
343 "Number of private copies is not the same as the preallocated buffer");
344 std::copy(VL.begin(), VL.end(), varlist_end());
345}
346
347void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
348 assert(VL.size() == varlist_size() &&
349 "Number of inits is not the same as the preallocated buffer");
350 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
351}
352
353OMPFirstprivateClause *
354OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
355 SourceLocation LParenLoc, SourceLocation EndLoc,
356 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
Alexey Bataev417089f2016-02-17 13:19:37 +0000357 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
James Y Knight374fd202016-01-01 00:38:24 +0000358 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000359 OMPFirstprivateClause *Clause =
360 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
361 Clause->setVarRefs(VL);
362 Clause->setPrivateCopies(PrivateVL);
363 Clause->setInits(InitVL);
Alexey Bataev417089f2016-02-17 13:19:37 +0000364 Clause->setPreInitStmt(PreInit);
James Y Knightb8bfd962015-10-02 13:41:04 +0000365 return Clause;
366}
367
368OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
369 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000370 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000371 return new (Mem) OMPFirstprivateClause(N);
372}
373
374void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
375 assert(PrivateCopies.size() == varlist_size() &&
376 "Number of private copies is not the same as the preallocated buffer");
377 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
378}
379
380void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
381 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
382 "not the same as the "
383 "preallocated buffer");
384 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
385}
386
387void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
388 assert(DstExprs.size() == varlist_size() && "Number of destination "
389 "expressions is not the same as "
390 "the preallocated buffer");
391 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
392}
393
394void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
395 assert(AssignmentOps.size() == varlist_size() &&
396 "Number of assignment expressions is not the same as the preallocated "
397 "buffer");
398 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
399 getDestinationExprs().end());
400}
401
402OMPLastprivateClause *OMPLastprivateClause::Create(
403 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
404 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
Alexey Bataev005248a2016-02-25 05:25:57 +0000405 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit,
406 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000407 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000408 OMPLastprivateClause *Clause =
409 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
410 Clause->setVarRefs(VL);
411 Clause->setSourceExprs(SrcExprs);
412 Clause->setDestinationExprs(DstExprs);
413 Clause->setAssignmentOps(AssignmentOps);
Alexey Bataev005248a2016-02-25 05:25:57 +0000414 Clause->setPreInitStmt(PreInit);
415 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000416 return Clause;
417}
418
419OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
420 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000421 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000422 return new (Mem) OMPLastprivateClause(N);
423}
424
425OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
426 SourceLocation StartLoc,
427 SourceLocation LParenLoc,
428 SourceLocation EndLoc,
429 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000430 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000431 OMPSharedClause *Clause =
432 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
433 Clause->setVarRefs(VL);
434 return Clause;
435}
436
437OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000438 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000439 return new (Mem) OMPSharedClause(N);
440}
441
442void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
443 assert(PL.size() == varlist_size() &&
444 "Number of privates is not the same as the preallocated buffer");
445 std::copy(PL.begin(), PL.end(), varlist_end());
446}
447
448void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
449 assert(IL.size() == varlist_size() &&
450 "Number of inits is not the same as the preallocated buffer");
451 std::copy(IL.begin(), IL.end(), getPrivates().end());
452}
453
454void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
455 assert(UL.size() == varlist_size() &&
456 "Number of updates is not the same as the preallocated buffer");
457 std::copy(UL.begin(), UL.end(), getInits().end());
458}
459
460void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
461 assert(FL.size() == varlist_size() &&
462 "Number of final updates is not the same as the preallocated buffer");
463 std::copy(FL.begin(), FL.end(), getUpdates().end());
464}
465
Alexey Bataev195ae902019-08-08 13:42:45 +0000466void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) {
467 assert(
468 UE.size() == varlist_size() + 1 &&
469 "Number of used expressions is not the same as the preallocated buffer");
470 std::copy(UE.begin(), UE.end(), getFinals().end() + 2);
471}
472
James Y Knightb8bfd962015-10-02 13:41:04 +0000473OMPLinearClause *OMPLinearClause::Create(
474 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
475 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
476 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
Alexey Bataev78849fb2016-03-09 09:49:00 +0000477 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
478 Stmt *PreInit, Expr *PostUpdate) {
Alexey Bataev195ae902019-08-08 13:42:45 +0000479 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
480 // (Step and CalcStep), list of used expression + step.
481 void *Mem =
482 C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000483 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
484 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
485 Clause->setVarRefs(VL);
486 Clause->setPrivates(PL);
487 Clause->setInits(IL);
488 // Fill update and final expressions with zeroes, they are provided later,
489 // after the directive construction.
490 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
491 nullptr);
492 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
493 nullptr);
Alexey Bataev195ae902019-08-08 13:42:45 +0000494 std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(),
495 nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000496 Clause->setStep(Step);
497 Clause->setCalcStep(CalcStep);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000498 Clause->setPreInitStmt(PreInit);
499 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000500 return Clause;
501}
502
503OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
504 unsigned NumVars) {
Alexey Bataev195ae902019-08-08 13:42:45 +0000505 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
506 // (Step and CalcStep), list of used expression + step.
507 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars +1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000508 return new (Mem) OMPLinearClause(NumVars);
509}
510
Alexey Bataev195ae902019-08-08 13:42:45 +0000511OMPClause::child_range OMPLinearClause::used_children() {
512 // Range includes only non-nullptr elements.
513 return child_range(
514 reinterpret_cast<Stmt **>(getUsedExprs().begin()),
515 reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr)));
516}
517
James Y Knightb8bfd962015-10-02 13:41:04 +0000518OMPAlignedClause *
519OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
520 SourceLocation LParenLoc, SourceLocation ColonLoc,
521 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
James Y Knight374fd202016-01-01 00:38:24 +0000522 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000523 OMPAlignedClause *Clause = new (Mem)
524 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
525 Clause->setVarRefs(VL);
526 Clause->setAlignment(A);
527 return Clause;
528}
529
530OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
531 unsigned NumVars) {
James Y Knight374fd202016-01-01 00:38:24 +0000532 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000533 return new (Mem) OMPAlignedClause(NumVars);
534}
535
536void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
537 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
538 "not the same as the "
539 "preallocated buffer");
540 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
541}
542
543void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
544 assert(DstExprs.size() == varlist_size() && "Number of destination "
545 "expressions is not the same as "
546 "the preallocated buffer");
547 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
548}
549
550void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
551 assert(AssignmentOps.size() == varlist_size() &&
552 "Number of assignment expressions is not the same as the preallocated "
553 "buffer");
554 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
555 getDestinationExprs().end());
556}
557
558OMPCopyinClause *OMPCopyinClause::Create(
559 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
560 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
561 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000562 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000563 OMPCopyinClause *Clause =
564 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
565 Clause->setVarRefs(VL);
566 Clause->setSourceExprs(SrcExprs);
567 Clause->setDestinationExprs(DstExprs);
568 Clause->setAssignmentOps(AssignmentOps);
569 return Clause;
570}
571
572OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000573 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000574 return new (Mem) OMPCopyinClause(N);
575}
576
577void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
578 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
579 "not the same as the "
580 "preallocated buffer");
581 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
582}
583
584void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
585 assert(DstExprs.size() == varlist_size() && "Number of destination "
586 "expressions is not the same as "
587 "the preallocated buffer");
588 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
589}
590
591void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
592 assert(AssignmentOps.size() == varlist_size() &&
593 "Number of assignment expressions is not the same as the preallocated "
594 "buffer");
595 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
596 getDestinationExprs().end());
597}
598
599OMPCopyprivateClause *OMPCopyprivateClause::Create(
600 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
601 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
602 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000603 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000604 OMPCopyprivateClause *Clause =
605 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
606 Clause->setVarRefs(VL);
607 Clause->setSourceExprs(SrcExprs);
608 Clause->setDestinationExprs(DstExprs);
609 Clause->setAssignmentOps(AssignmentOps);
610 return Clause;
611}
612
613OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
614 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000615 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000616 return new (Mem) OMPCopyprivateClause(N);
617}
618
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000619void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
620 assert(Privates.size() == varlist_size() &&
621 "Number of private copies is not the same as the preallocated buffer");
622 std::copy(Privates.begin(), Privates.end(), varlist_end());
623}
624
James Y Knightb8bfd962015-10-02 13:41:04 +0000625void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
626 assert(
627 LHSExprs.size() == varlist_size() &&
628 "Number of LHS expressions is not the same as the preallocated buffer");
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000629 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
James Y Knightb8bfd962015-10-02 13:41:04 +0000630}
631
632void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
633 assert(
634 RHSExprs.size() == varlist_size() &&
635 "Number of RHS expressions is not the same as the preallocated buffer");
636 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
637}
638
639void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
640 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
641 "expressions is not the same "
642 "as the preallocated buffer");
643 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
644}
645
646OMPReductionClause *OMPReductionClause::Create(
647 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
648 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
649 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000650 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev61205072016-03-02 04:57:40 +0000651 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
652 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000653 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000654 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
655 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
656 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000657 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000658 Clause->setLHSExprs(LHSExprs);
659 Clause->setRHSExprs(RHSExprs);
660 Clause->setReductionOps(ReductionOps);
Alexey Bataev61205072016-03-02 04:57:40 +0000661 Clause->setPreInitStmt(PreInit);
662 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000663 return Clause;
664}
665
666OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
667 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000668 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000669 return new (Mem) OMPReductionClause(N);
670}
671
Alexey Bataev169d96a2017-07-18 20:17:46 +0000672void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
673 assert(Privates.size() == varlist_size() &&
674 "Number of private copies is not the same as the preallocated buffer");
675 std::copy(Privates.begin(), Privates.end(), varlist_end());
676}
677
678void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
679 assert(
680 LHSExprs.size() == varlist_size() &&
681 "Number of LHS expressions is not the same as the preallocated buffer");
682 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
683}
684
685void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
686 assert(
687 RHSExprs.size() == varlist_size() &&
688 "Number of RHS expressions is not the same as the preallocated buffer");
689 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
690}
691
692void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
693 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
694 "expressions is not the same "
695 "as the preallocated buffer");
696 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
697}
698
699OMPTaskReductionClause *OMPTaskReductionClause::Create(
700 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
701 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
702 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
703 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
704 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
705 Expr *PostUpdate) {
706 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
707 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
708 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
709 Clause->setVarRefs(VL);
710 Clause->setPrivates(Privates);
711 Clause->setLHSExprs(LHSExprs);
712 Clause->setRHSExprs(RHSExprs);
713 Clause->setReductionOps(ReductionOps);
714 Clause->setPreInitStmt(PreInit);
715 Clause->setPostUpdateExpr(PostUpdate);
716 return Clause;
717}
718
719OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
720 unsigned N) {
721 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
722 return new (Mem) OMPTaskReductionClause(N);
723}
724
Alexey Bataevfa312f32017-07-21 18:48:21 +0000725void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
726 assert(Privates.size() == varlist_size() &&
727 "Number of private copies is not the same as the preallocated buffer");
728 std::copy(Privates.begin(), Privates.end(), varlist_end());
729}
730
731void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
732 assert(
733 LHSExprs.size() == varlist_size() &&
734 "Number of LHS expressions is not the same as the preallocated buffer");
735 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
736}
737
738void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
739 assert(
740 RHSExprs.size() == varlist_size() &&
741 "Number of RHS expressions is not the same as the preallocated buffer");
742 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
743}
744
745void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
746 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
747 "expressions is not the same "
748 "as the preallocated buffer");
749 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
750}
751
Alexey Bataev88202be2017-07-27 13:20:36 +0000752void OMPInReductionClause::setTaskgroupDescriptors(
753 ArrayRef<Expr *> TaskgroupDescriptors) {
754 assert(TaskgroupDescriptors.size() == varlist_size() &&
755 "Number of in reduction descriptors is not the same as the "
756 "preallocated buffer");
757 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
758 getReductionOps().end());
759}
760
Alexey Bataevfa312f32017-07-21 18:48:21 +0000761OMPInReductionClause *OMPInReductionClause::Create(
762 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
763 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
764 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
765 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev88202be2017-07-27 13:20:36 +0000766 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
767 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
768 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000769 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
770 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
771 Clause->setVarRefs(VL);
772 Clause->setPrivates(Privates);
773 Clause->setLHSExprs(LHSExprs);
774 Clause->setRHSExprs(RHSExprs);
775 Clause->setReductionOps(ReductionOps);
Alexey Bataev88202be2017-07-27 13:20:36 +0000776 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000777 Clause->setPreInitStmt(PreInit);
778 Clause->setPostUpdateExpr(PostUpdate);
779 return Clause;
780}
781
782OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
783 unsigned N) {
Alexey Bataev88202be2017-07-27 13:20:36 +0000784 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000785 return new (Mem) OMPInReductionClause(N);
786}
787
Alexey Bataeve04483e2019-03-27 14:14:31 +0000788OMPAllocateClause *
789OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc,
790 SourceLocation LParenLoc, Expr *Allocator,
791 SourceLocation ColonLoc, SourceLocation EndLoc,
792 ArrayRef<Expr *> VL) {
793 // Allocate space for private variables and initializer expressions.
794 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
795 auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
796 ColonLoc, EndLoc, VL.size());
797 Clause->setVarRefs(VL);
798 return Clause;
799}
800
801OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
802 unsigned N) {
803 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
804 return new (Mem) OMPAllocateClause(N);
805}
806
James Y Knightb8bfd962015-10-02 13:41:04 +0000807OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
808 SourceLocation StartLoc,
809 SourceLocation LParenLoc,
810 SourceLocation EndLoc,
811 ArrayRef<Expr *> VL) {
Alexey Bataev8b427062016-05-25 12:36:08 +0000812 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000813 OMPFlushClause *Clause =
814 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
815 Clause->setVarRefs(VL);
816 return Clause;
817}
818
819OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000820 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000821 return new (Mem) OMPFlushClause(N);
822}
823
Alexey Bataevf138fda2018-08-13 19:04:24 +0000824OMPDependClause *
825OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
826 SourceLocation LParenLoc, SourceLocation EndLoc,
827 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
828 SourceLocation ColonLoc, ArrayRef<Expr *> VL,
829 unsigned NumLoops) {
830 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
831 OMPDependClause *Clause = new (Mem)
832 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000833 Clause->setVarRefs(VL);
834 Clause->setDependencyKind(DepKind);
835 Clause->setDependencyLoc(DepLoc);
836 Clause->setColonLoc(ColonLoc);
Alexey Bataevf138fda2018-08-13 19:04:24 +0000837 for (unsigned I = 0 ; I < NumLoops; ++I)
838 Clause->setLoopData(I, nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000839 return Clause;
840}
841
Alexey Bataevf138fda2018-08-13 19:04:24 +0000842OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
843 unsigned NumLoops) {
844 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
845 return new (Mem) OMPDependClause(N, NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000846}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000847
Alexey Bataevf138fda2018-08-13 19:04:24 +0000848void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
849 assert((getDependencyKind() == OMPC_DEPEND_sink ||
850 getDependencyKind() == OMPC_DEPEND_source) &&
851 NumLoop < NumLoops &&
852 "Expected sink or source depend + loop index must be less number of "
853 "loops.");
854 auto It = std::next(getVarRefs().end(), NumLoop);
855 *It = Cnt;
Alexey Bataev8b427062016-05-25 12:36:08 +0000856}
857
Alexey Bataevf138fda2018-08-13 19:04:24 +0000858Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
859 assert((getDependencyKind() == OMPC_DEPEND_sink ||
860 getDependencyKind() == OMPC_DEPEND_source) &&
861 NumLoop < NumLoops &&
862 "Expected sink or source depend + loop index must be less number of "
863 "loops.");
864 auto It = std::next(getVarRefs().end(), NumLoop);
865 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000866}
867
Alexey Bataevf138fda2018-08-13 19:04:24 +0000868const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
869 assert((getDependencyKind() == OMPC_DEPEND_sink ||
870 getDependencyKind() == OMPC_DEPEND_source) &&
871 NumLoop < NumLoops &&
872 "Expected sink or source depend + loop index must be less number of "
873 "loops.");
874 auto It = std::next(getVarRefs().end(), NumLoop);
875 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000876}
877
Samuel Antao90927002016-04-26 14:54:23 +0000878unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
879 MappableExprComponentListsRef ComponentLists) {
880 unsigned TotalNum = 0u;
881 for (auto &C : ComponentLists)
882 TotalNum += C.size();
883 return TotalNum;
884}
885
886unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
Alexey Bataeve3727102018-04-18 15:57:46 +0000887 ArrayRef<const ValueDecl *> Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000888 unsigned TotalNum = 0u;
889 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
Alexey Bataeve3727102018-04-18 15:57:46 +0000890 for (const ValueDecl *D : Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000891 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
892 if (Cache.count(VD))
893 continue;
894 ++TotalNum;
895 Cache.insert(VD);
896 }
897 return TotalNum;
898}
899
Michael Kruse4304e9d2019-02-19 16:38:20 +0000900OMPMapClause *OMPMapClause::Create(
901 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
902 ArrayRef<ValueDecl *> Declarations,
903 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
904 ArrayRef<OpenMPMapModifierKind> MapModifiers,
905 ArrayRef<SourceLocation> MapModifiersLoc,
906 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
907 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
908 OMPMappableExprListSizeTy Sizes;
909 Sizes.NumVars = Vars.size();
910 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
911 Sizes.NumComponentLists = ComponentLists.size();
912 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao90927002016-04-26 14:54:23 +0000913
914 // We need to allocate:
Michael Kruse4304e9d2019-02-19 16:38:20 +0000915 // 2 x NumVars x Expr* - we have an original list expression and an associated
916 // user-defined mapper for each clause list entry.
Samuel Antao90927002016-04-26 14:54:23 +0000917 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
918 // with each component list.
919 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
920 // number of lists for each unique declaration and the size of each component
921 // list.
922 // NumComponents x MappableComponent - the total of all the components in all
923 // the lists.
924 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 OMPMapClause *Clause = new (Mem)
931 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
932 Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
Samuel Antao90927002016-04-26 14:54:23 +0000933
934 Clause->setVarRefs(Vars);
Michael Kruse4304e9d2019-02-19 16:38:20 +0000935 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao90927002016-04-26 14:54:23 +0000936 Clause->setClauseInfo(Declarations, ComponentLists);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000937 Clause->setMapType(Type);
938 Clause->setMapLoc(TypeLoc);
939 return Clause;
940}
941
Michael Kruse4304e9d2019-02-19 16:38:20 +0000942OMPMapClause *
943OMPMapClause::CreateEmpty(const ASTContext &C,
944 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao90927002016-04-26 14:54:23 +0000945 void *Mem = C.Allocate(
946 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
947 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000948 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
949 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
950 Sizes.NumComponents));
951 return new (Mem) OMPMapClause(Sizes);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000952}
Samuel Antao661c0902016-05-26 17:39:58 +0000953
Michael Kruse01f670d2019-02-22 22:29:42 +0000954OMPToClause *OMPToClause::Create(
955 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
956 ArrayRef<ValueDecl *> Declarations,
957 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
958 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000959 OMPMappableExprListSizeTy Sizes;
960 Sizes.NumVars = Vars.size();
961 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
962 Sizes.NumComponentLists = ComponentLists.size();
963 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao661c0902016-05-26 17:39:58 +0000964
965 // We need to allocate:
Michael Kruse01f670d2019-02-22 22:29:42 +0000966 // 2 x NumVars x Expr* - we have an original list expression and an associated
967 // user-defined mapper for each clause list entry.
Samuel Antao661c0902016-05-26 17:39:58 +0000968 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
969 // with each component list.
970 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
971 // number of lists for each unique declaration and the size of each component
972 // list.
973 // NumComponents x MappableComponent - the total of all the components in all
974 // the lists.
975 void *Mem = C.Allocate(
976 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
977 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +0000978 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000979 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
980 Sizes.NumComponents));
Samuel Antao661c0902016-05-26 17:39:58 +0000981
Michael Kruse01f670d2019-02-22 22:29:42 +0000982 auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +0000983
984 Clause->setVarRefs(Vars);
Michael Kruse01f670d2019-02-22 22:29:42 +0000985 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao661c0902016-05-26 17:39:58 +0000986 Clause->setClauseInfo(Declarations, ComponentLists);
987 return Clause;
988}
989
Michael Kruse4304e9d2019-02-19 16:38:20 +0000990OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
991 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao661c0902016-05-26 17:39:58 +0000992 void *Mem = C.Allocate(
993 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
994 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +0000995 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000996 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
997 Sizes.NumComponents));
998 return new (Mem) OMPToClause(Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +0000999}
Samuel Antaoec172c62016-05-26 17:49:04 +00001000
Michael Kruse0336c752019-02-25 20:34:15 +00001001OMPFromClause *OMPFromClause::Create(
1002 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1003 ArrayRef<ValueDecl *> Declarations,
1004 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1005 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001006 OMPMappableExprListSizeTy Sizes;
1007 Sizes.NumVars = Vars.size();
1008 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1009 Sizes.NumComponentLists = ComponentLists.size();
1010 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaoec172c62016-05-26 17:49:04 +00001011
1012 // We need to allocate:
Michael Kruse0336c752019-02-25 20:34:15 +00001013 // 2 x NumVars x Expr* - we have an original list expression and an associated
1014 // user-defined mapper for each clause list entry.
Samuel Antaoec172c62016-05-26 17:49:04 +00001015 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1016 // with each component list.
1017 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1018 // number of lists for each unique declaration and the size of each component
1019 // list.
1020 // NumComponents x MappableComponent - the total of all the components in all
1021 // the lists.
1022 void *Mem = C.Allocate(
1023 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1024 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001025 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001026 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1027 Sizes.NumComponents));
Samuel Antaoec172c62016-05-26 17:49:04 +00001028
Michael Kruse0336c752019-02-25 20:34:15 +00001029 auto *Clause =
1030 new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001031
1032 Clause->setVarRefs(Vars);
Michael Kruse0336c752019-02-25 20:34:15 +00001033 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antaoec172c62016-05-26 17:49:04 +00001034 Clause->setClauseInfo(Declarations, ComponentLists);
1035 return Clause;
1036}
1037
Michael Kruse4304e9d2019-02-19 16:38:20 +00001038OMPFromClause *
1039OMPFromClause::CreateEmpty(const ASTContext &C,
1040 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaoec172c62016-05-26 17:49:04 +00001041 void *Mem = C.Allocate(
1042 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1043 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001044 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001045 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1046 Sizes.NumComponents));
1047 return new (Mem) OMPFromClause(Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001048}
Carlo Bertolli2404b172016-07-13 15:37:16 +00001049
Samuel Antaocc10b852016-07-28 14:23:26 +00001050void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1051 assert(VL.size() == varlist_size() &&
1052 "Number of private copies is not the same as the preallocated buffer");
1053 std::copy(VL.begin(), VL.end(), varlist_end());
1054}
1055
1056void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
1057 assert(VL.size() == varlist_size() &&
1058 "Number of inits is not the same as the preallocated buffer");
1059 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1060}
1061
1062OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001063 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1064 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
1065 ArrayRef<ValueDecl *> Declarations,
Samuel Antaocc10b852016-07-28 14:23:26 +00001066 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001067 OMPMappableExprListSizeTy Sizes;
1068 Sizes.NumVars = Vars.size();
1069 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1070 Sizes.NumComponentLists = ComponentLists.size();
1071 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaocc10b852016-07-28 14:23:26 +00001072
1073 // We need to allocate:
1074 // 3 x NumVars x Expr* - we have an original list expression for each clause
1075 // list entry and an equal number of private copies and inits.
1076 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1077 // with each component list.
1078 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1079 // number of lists for each unique declaration and the size of each component
1080 // list.
1081 // NumComponents x MappableComponent - the total of all the components in all
1082 // the lists.
1083 void *Mem = C.Allocate(
1084 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1085 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001086 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1087 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1088 Sizes.NumComponents));
Samuel Antaocc10b852016-07-28 14:23:26 +00001089
Michael Kruse4304e9d2019-02-19 16:38:20 +00001090 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
Samuel Antaocc10b852016-07-28 14:23:26 +00001091
1092 Clause->setVarRefs(Vars);
1093 Clause->setPrivateCopies(PrivateVars);
1094 Clause->setInits(Inits);
1095 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001096 return Clause;
1097}
1098
Michael Kruse4304e9d2019-02-19 16:38:20 +00001099OMPUseDevicePtrClause *
1100OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
1101 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaocc10b852016-07-28 14:23:26 +00001102 void *Mem = C.Allocate(
1103 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1104 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001105 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1106 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1107 Sizes.NumComponents));
1108 return new (Mem) OMPUseDevicePtrClause(Sizes);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001109}
Carlo Bertolli70594e92016-07-13 17:16:49 +00001110
Samuel Antao6890b092016-07-28 14:25:09 +00001111OMPIsDevicePtrClause *
Michael Kruse4304e9d2019-02-19 16:38:20 +00001112OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
Samuel Antao6890b092016-07-28 14:25:09 +00001113 ArrayRef<Expr *> Vars,
1114 ArrayRef<ValueDecl *> Declarations,
1115 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001116 OMPMappableExprListSizeTy Sizes;
1117 Sizes.NumVars = Vars.size();
1118 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1119 Sizes.NumComponentLists = ComponentLists.size();
1120 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao6890b092016-07-28 14:25:09 +00001121
1122 // We need to allocate:
1123 // NumVars x Expr* - we have an original list expression for each clause list
1124 // entry.
1125 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1126 // with each component list.
1127 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1128 // number of lists for each unique declaration and the size of each component
1129 // list.
1130 // NumComponents x MappableComponent - the total of all the components in all
1131 // the lists.
1132 void *Mem = C.Allocate(
1133 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1134 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001135 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1136 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1137 Sizes.NumComponents));
Samuel Antao6890b092016-07-28 14:25:09 +00001138
Michael Kruse4304e9d2019-02-19 16:38:20 +00001139 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
Samuel Antao6890b092016-07-28 14:25:09 +00001140
1141 Clause->setVarRefs(Vars);
1142 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001143 return Clause;
1144}
1145
Michael Kruse4304e9d2019-02-19 16:38:20 +00001146OMPIsDevicePtrClause *
1147OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1148 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao6890b092016-07-28 14:25:09 +00001149 void *Mem = C.Allocate(
1150 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1151 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001152 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1153 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1154 Sizes.NumComponents));
1155 return new (Mem) OMPIsDevicePtrClause(Sizes);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001156}
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001157
1158//===----------------------------------------------------------------------===//
1159// OpenMP clauses printing methods
1160//===----------------------------------------------------------------------===//
1161
1162void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1163 OS << "if(";
1164 if (Node->getNameModifier() != OMPD_unknown)
1165 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1166 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1167 OS << ")";
1168}
1169
1170void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1171 OS << "final(";
1172 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1173 OS << ")";
1174}
1175
1176void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1177 OS << "num_threads(";
1178 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1179 OS << ")";
1180}
1181
1182void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1183 OS << "safelen(";
1184 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1185 OS << ")";
1186}
1187
1188void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1189 OS << "simdlen(";
1190 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1191 OS << ")";
1192}
1193
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00001194void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
1195 OS << "allocator(";
1196 Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
1197 OS << ")";
1198}
1199
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001200void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1201 OS << "collapse(";
1202 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1203 OS << ")";
1204}
1205
1206void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1207 OS << "default("
1208 << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
1209 << ")";
1210}
1211
1212void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1213 OS << "proc_bind("
1214 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, Node->getProcBindKind())
1215 << ")";
1216}
1217
1218void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1219 OS << "unified_address";
1220}
1221
1222void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1223 OMPUnifiedSharedMemoryClause *) {
1224 OS << "unified_shared_memory";
1225}
1226
1227void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1228 OS << "reverse_offload";
1229}
1230
1231void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1232 OMPDynamicAllocatorsClause *) {
1233 OS << "dynamic_allocators";
1234}
1235
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00001236void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1237 OMPAtomicDefaultMemOrderClause *Node) {
1238 OS << "atomic_default_mem_order("
1239 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1240 Node->getAtomicDefaultMemOrderKind())
1241 << ")";
1242}
1243
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001244void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1245 OS << "schedule(";
1246 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1247 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1248 Node->getFirstScheduleModifier());
1249 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1250 OS << ", ";
1251 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1252 Node->getSecondScheduleModifier());
1253 }
1254 OS << ": ";
1255 }
1256 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1257 if (auto *E = Node->getChunkSize()) {
1258 OS << ", ";
1259 E->printPretty(OS, nullptr, Policy);
1260 }
1261 OS << ")";
1262}
1263
1264void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1265 OS << "ordered";
1266 if (auto *Num = Node->getNumForLoops()) {
1267 OS << "(";
1268 Num->printPretty(OS, nullptr, Policy, 0);
1269 OS << ")";
1270 }
1271}
1272
1273void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1274 OS << "nowait";
1275}
1276
1277void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1278 OS << "untied";
1279}
1280
1281void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1282 OS << "nogroup";
1283}
1284
1285void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1286 OS << "mergeable";
1287}
1288
1289void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1290
1291void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1292
1293void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
1294 OS << "update";
1295}
1296
1297void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1298 OS << "capture";
1299}
1300
1301void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1302 OS << "seq_cst";
1303}
1304
1305void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1306 OS << "threads";
1307}
1308
1309void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1310
1311void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1312 OS << "device(";
1313 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1314 OS << ")";
1315}
1316
1317void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1318 OS << "num_teams(";
1319 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1320 OS << ")";
1321}
1322
1323void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1324 OS << "thread_limit(";
1325 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1326 OS << ")";
1327}
1328
1329void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1330 OS << "priority(";
1331 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1332 OS << ")";
1333}
1334
1335void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1336 OS << "grainsize(";
1337 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1338 OS << ")";
1339}
1340
1341void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1342 OS << "num_tasks(";
1343 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1344 OS << ")";
1345}
1346
1347void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1348 OS << "hint(";
1349 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1350 OS << ")";
1351}
1352
1353template<typename T>
1354void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1355 for (typename T::varlist_iterator I = Node->varlist_begin(),
1356 E = Node->varlist_end();
1357 I != E; ++I) {
1358 assert(*I && "Expected non-null Stmt");
1359 OS << (I == Node->varlist_begin() ? StartSym : ',');
1360 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1361 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1362 DRE->printPretty(OS, nullptr, Policy, 0);
1363 else
1364 DRE->getDecl()->printQualifiedName(OS);
1365 } else
1366 (*I)->printPretty(OS, nullptr, Policy, 0);
1367 }
1368}
1369
Alexey Bataeve04483e2019-03-27 14:14:31 +00001370void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
1371 if (Node->varlist_empty())
1372 return;
1373 OS << "allocate";
1374 if (Expr *Allocator = Node->getAllocator()) {
1375 OS << "(";
1376 Allocator->printPretty(OS, nullptr, Policy, 0);
1377 OS << ":";
1378 VisitOMPClauseList(Node, ' ');
1379 } else {
1380 VisitOMPClauseList(Node, '(');
1381 }
1382 OS << ")";
1383}
1384
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001385void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1386 if (!Node->varlist_empty()) {
1387 OS << "private";
1388 VisitOMPClauseList(Node, '(');
1389 OS << ")";
1390 }
1391}
1392
1393void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1394 if (!Node->varlist_empty()) {
1395 OS << "firstprivate";
1396 VisitOMPClauseList(Node, '(');
1397 OS << ")";
1398 }
1399}
1400
1401void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1402 if (!Node->varlist_empty()) {
1403 OS << "lastprivate";
1404 VisitOMPClauseList(Node, '(');
1405 OS << ")";
1406 }
1407}
1408
1409void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1410 if (!Node->varlist_empty()) {
1411 OS << "shared";
1412 VisitOMPClauseList(Node, '(');
1413 OS << ")";
1414 }
1415}
1416
1417void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1418 if (!Node->varlist_empty()) {
1419 OS << "reduction(";
1420 NestedNameSpecifier *QualifierLoc =
1421 Node->getQualifierLoc().getNestedNameSpecifier();
1422 OverloadedOperatorKind OOK =
1423 Node->getNameInfo().getName().getCXXOverloadedOperator();
1424 if (QualifierLoc == nullptr && OOK != OO_None) {
1425 // Print reduction identifier in C format
1426 OS << getOperatorSpelling(OOK);
1427 } else {
1428 // Use C++ format
1429 if (QualifierLoc != nullptr)
1430 QualifierLoc->print(OS, Policy);
1431 OS << Node->getNameInfo();
1432 }
1433 OS << ":";
1434 VisitOMPClauseList(Node, ' ');
1435 OS << ")";
1436 }
1437}
1438
1439void OMPClausePrinter::VisitOMPTaskReductionClause(
1440 OMPTaskReductionClause *Node) {
1441 if (!Node->varlist_empty()) {
1442 OS << "task_reduction(";
1443 NestedNameSpecifier *QualifierLoc =
1444 Node->getQualifierLoc().getNestedNameSpecifier();
1445 OverloadedOperatorKind OOK =
1446 Node->getNameInfo().getName().getCXXOverloadedOperator();
1447 if (QualifierLoc == nullptr && OOK != OO_None) {
1448 // Print reduction identifier in C format
1449 OS << getOperatorSpelling(OOK);
1450 } else {
1451 // Use C++ format
1452 if (QualifierLoc != nullptr)
1453 QualifierLoc->print(OS, Policy);
1454 OS << Node->getNameInfo();
1455 }
1456 OS << ":";
1457 VisitOMPClauseList(Node, ' ');
1458 OS << ")";
1459 }
1460}
1461
1462void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1463 if (!Node->varlist_empty()) {
1464 OS << "in_reduction(";
1465 NestedNameSpecifier *QualifierLoc =
1466 Node->getQualifierLoc().getNestedNameSpecifier();
1467 OverloadedOperatorKind OOK =
1468 Node->getNameInfo().getName().getCXXOverloadedOperator();
1469 if (QualifierLoc == nullptr && OOK != OO_None) {
1470 // Print reduction identifier in C format
1471 OS << getOperatorSpelling(OOK);
1472 } else {
1473 // Use C++ format
1474 if (QualifierLoc != nullptr)
1475 QualifierLoc->print(OS, Policy);
1476 OS << Node->getNameInfo();
1477 }
1478 OS << ":";
1479 VisitOMPClauseList(Node, ' ');
1480 OS << ")";
1481 }
1482}
1483
1484void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1485 if (!Node->varlist_empty()) {
1486 OS << "linear";
1487 if (Node->getModifierLoc().isValid()) {
1488 OS << '('
1489 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1490 }
1491 VisitOMPClauseList(Node, '(');
1492 if (Node->getModifierLoc().isValid())
1493 OS << ')';
1494 if (Node->getStep() != nullptr) {
1495 OS << ": ";
1496 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1497 }
1498 OS << ")";
1499 }
1500}
1501
1502void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1503 if (!Node->varlist_empty()) {
1504 OS << "aligned";
1505 VisitOMPClauseList(Node, '(');
1506 if (Node->getAlignment() != nullptr) {
1507 OS << ": ";
1508 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1509 }
1510 OS << ")";
1511 }
1512}
1513
1514void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1515 if (!Node->varlist_empty()) {
1516 OS << "copyin";
1517 VisitOMPClauseList(Node, '(');
1518 OS << ")";
1519 }
1520}
1521
1522void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1523 if (!Node->varlist_empty()) {
1524 OS << "copyprivate";
1525 VisitOMPClauseList(Node, '(');
1526 OS << ")";
1527 }
1528}
1529
1530void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1531 if (!Node->varlist_empty()) {
1532 VisitOMPClauseList(Node, '(');
1533 OS << ")";
1534 }
1535}
1536
1537void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1538 OS << "depend(";
1539 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1540 Node->getDependencyKind());
1541 if (!Node->varlist_empty()) {
1542 OS << " :";
1543 VisitOMPClauseList(Node, ' ');
1544 }
1545 OS << ")";
1546}
1547
1548void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1549 if (!Node->varlist_empty()) {
1550 OS << "map(";
1551 if (Node->getMapType() != OMPC_MAP_unknown) {
Kelvin Lief579432018-12-18 22:18:41 +00001552 for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1553 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1554 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1555 Node->getMapTypeModifier(I));
Michael Kruse4304e9d2019-02-19 16:38:20 +00001556 if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1557 OS << '(';
1558 NestedNameSpecifier *MapperNNS =
1559 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1560 if (MapperNNS)
1561 MapperNNS->print(OS, Policy);
1562 OS << Node->getMapperIdInfo() << ')';
1563 }
Kelvin Lief579432018-12-18 22:18:41 +00001564 OS << ',';
1565 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001566 }
1567 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1568 OS << ':';
1569 }
1570 VisitOMPClauseList(Node, ' ');
1571 OS << ")";
1572 }
1573}
1574
1575void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1576 if (!Node->varlist_empty()) {
1577 OS << "to";
Michael Kruse01f670d2019-02-22 22:29:42 +00001578 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1579 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1580 OS << '(';
1581 OS << "mapper(";
1582 NestedNameSpecifier *MapperNNS =
1583 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1584 if (MapperNNS)
1585 MapperNNS->print(OS, Policy);
1586 OS << MapperId << "):";
1587 VisitOMPClauseList(Node, ' ');
1588 } else {
1589 VisitOMPClauseList(Node, '(');
1590 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001591 OS << ")";
1592 }
1593}
1594
1595void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1596 if (!Node->varlist_empty()) {
1597 OS << "from";
Michael Kruse0336c752019-02-25 20:34:15 +00001598 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1599 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1600 OS << '(';
1601 OS << "mapper(";
1602 NestedNameSpecifier *MapperNNS =
1603 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1604 if (MapperNNS)
1605 MapperNNS->print(OS, Policy);
1606 OS << MapperId << "):";
1607 VisitOMPClauseList(Node, ' ');
1608 } else {
1609 VisitOMPClauseList(Node, '(');
1610 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001611 OS << ")";
1612 }
1613}
1614
1615void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1616 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1617 OMPC_dist_schedule, Node->getDistScheduleKind());
1618 if (auto *E = Node->getChunkSize()) {
1619 OS << ", ";
1620 E->printPretty(OS, nullptr, Policy);
1621 }
1622 OS << ")";
1623}
1624
1625void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1626 OS << "defaultmap(";
1627 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1628 Node->getDefaultmapModifier());
1629 OS << ": ";
1630 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1631 Node->getDefaultmapKind());
1632 OS << ")";
1633}
1634
1635void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1636 if (!Node->varlist_empty()) {
1637 OS << "use_device_ptr";
1638 VisitOMPClauseList(Node, '(');
1639 OS << ")";
1640 }
1641}
1642
1643void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1644 if (!Node->varlist_empty()) {
1645 OS << "is_device_ptr";
1646 VisitOMPClauseList(Node, '(');
1647 OS << ")";
1648 }
1649}
1650