blob: ccb3cd34360555a83ea4edbf30c8fd5b423d787d [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 Bataev3392d762016-02-16 11:18:12 +000093 case OMPC_default:
94 case OMPC_proc_bind:
Alexey Bataev3392d762016-02-16 11:18:12 +000095 case OMPC_safelen:
96 case OMPC_simdlen:
Alexey Bataev9cc10fc2019-03-12 18:52:33 +000097 case OMPC_allocator:
Alexey Bataeve04483e2019-03-27 14:14:31 +000098 case OMPC_allocate:
Alexey Bataev3392d762016-02-16 11:18:12 +000099 case OMPC_collapse:
100 case OMPC_private:
Alexey Bataev005248a2016-02-25 05:25:57 +0000101 case OMPC_shared:
Alexey Bataev005248a2016-02-25 05:25:57 +0000102 case OMPC_aligned:
103 case OMPC_copyin:
104 case OMPC_copyprivate:
105 case OMPC_ordered:
106 case OMPC_nowait:
107 case OMPC_untied:
108 case OMPC_mergeable:
109 case OMPC_threadprivate:
110 case OMPC_flush:
111 case OMPC_read:
112 case OMPC_write:
113 case OMPC_update:
114 case OMPC_capture:
115 case OMPC_seq_cst:
116 case OMPC_depend:
Alexey Bataev005248a2016-02-25 05:25:57 +0000117 case OMPC_threads:
118 case OMPC_simd:
119 case OMPC_map:
Alexey Bataev005248a2016-02-25 05:25:57 +0000120 case OMPC_priority:
Alexey Bataev005248a2016-02-25 05:25:57 +0000121 case OMPC_nogroup:
Alexey Bataev005248a2016-02-25 05:25:57 +0000122 case OMPC_hint:
123 case OMPC_defaultmap:
124 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000125 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000126 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000127 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000128 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000129 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000130 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000131 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000132 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000133 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000134 case OMPC_atomic_default_mem_order:
Alexey Bataev729e2422019-08-23 16:11:14 +0000135 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +0000136 case OMPC_match:
Alexey Bataev005248a2016-02-25 05:25:57 +0000137 break;
138 }
139
140 return nullptr;
141}
142
143OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
144 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
145 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
146}
147
148const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
149 switch (C->getClauseKind()) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000150 case OMPC_lastprivate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000151 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000152 case OMPC_reduction:
153 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +0000154 case OMPC_task_reduction:
155 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000156 case OMPC_in_reduction:
157 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000158 case OMPC_linear:
159 return static_cast<const OMPLinearClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000160 case OMPC_schedule:
161 case OMPC_dist_schedule:
162 case OMPC_firstprivate:
163 case OMPC_default:
164 case OMPC_proc_bind:
165 case OMPC_if:
166 case OMPC_final:
167 case OMPC_num_threads:
168 case OMPC_safelen:
169 case OMPC_simdlen:
Alexey Bataev9cc10fc2019-03-12 18:52:33 +0000170 case OMPC_allocator:
Alexey Bataeve04483e2019-03-27 14:14:31 +0000171 case OMPC_allocate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000172 case OMPC_collapse:
173 case OMPC_private:
Alexey Bataev3392d762016-02-16 11:18:12 +0000174 case OMPC_shared:
Alexey Bataev3392d762016-02-16 11:18:12 +0000175 case OMPC_aligned:
176 case OMPC_copyin:
177 case OMPC_copyprivate:
178 case OMPC_ordered:
179 case OMPC_nowait:
180 case OMPC_untied:
181 case OMPC_mergeable:
182 case OMPC_threadprivate:
183 case OMPC_flush:
184 case OMPC_read:
185 case OMPC_write:
186 case OMPC_update:
187 case OMPC_capture:
188 case OMPC_seq_cst:
189 case OMPC_depend:
190 case OMPC_device:
191 case OMPC_threads:
192 case OMPC_simd:
193 case OMPC_map:
194 case OMPC_num_teams:
195 case OMPC_thread_limit:
196 case OMPC_priority:
197 case OMPC_grainsize:
198 case OMPC_nogroup:
199 case OMPC_num_tasks:
200 case OMPC_hint:
201 case OMPC_defaultmap:
202 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000203 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000204 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000205 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000206 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000207 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000208 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000209 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000210 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000211 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000212 case OMPC_atomic_default_mem_order:
Alexey Bataev729e2422019-08-23 16:11:14 +0000213 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +0000214 case OMPC_match:
Alexey Bataev3392d762016-02-16 11:18:12 +0000215 break;
216 }
217
218 return nullptr;
219}
220
Alexey Bataev655cb4a2019-07-16 14:51:46 +0000221/// Gets the address of the original, non-captured, expression used in the
222/// clause as the preinitializer.
223static Stmt **getAddrOfExprAsWritten(Stmt *S) {
224 if (!S)
225 return nullptr;
226 if (auto *DS = dyn_cast<DeclStmt>(S)) {
227 assert(DS->isSingleDecl() && "Only single expression must be captured.");
228 if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
229 return OED->getInitAddress();
230 }
231 return nullptr;
232}
233
234OMPClause::child_range OMPIfClause::used_children() {
235 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
236 return child_range(C, C + 1);
237 return child_range(&Condition, &Condition + 1);
238}
239
Alexey Bataevb9c55e22019-10-14 19:29:52 +0000240OMPClause::child_range OMPGrainsizeClause::used_children() {
241 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
242 return child_range(C, C + 1);
243 return child_range(&Grainsize, &Grainsize + 1);
244}
245
Alexey Bataevd88c7de2019-10-14 20:44:34 +0000246OMPClause::child_range OMPNumTasksClause::used_children() {
247 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
248 return child_range(C, C + 1);
249 return child_range(&NumTasks, &NumTasks + 1);
250}
251
Alexey Bataev3a842ec2019-10-15 19:37:05 +0000252OMPClause::child_range OMPFinalClause::used_children() {
253 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
254 return child_range(C, C + 1);
255 return child_range(&Condition, &Condition + 1);
256}
257
Alexey Bataevf138fda2018-08-13 19:04:24 +0000258OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
259 unsigned NumLoops,
260 SourceLocation StartLoc,
261 SourceLocation LParenLoc,
262 SourceLocation EndLoc) {
263 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
264 auto *Clause =
265 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
266 for (unsigned I = 0; I < NumLoops; ++I) {
267 Clause->setLoopNumIterations(I, nullptr);
268 Clause->setLoopCounter(I, nullptr);
269 }
270 return Clause;
271}
272
273OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
274 unsigned NumLoops) {
275 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
276 auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
277 for (unsigned I = 0; I < NumLoops; ++I) {
278 Clause->setLoopNumIterations(I, nullptr);
279 Clause->setLoopCounter(I, nullptr);
280 }
281 return Clause;
282}
283
284void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
285 Expr *NumIterations) {
286 assert(NumLoop < NumberOfLoops && "out of loops number.");
287 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
288}
289
290ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
291 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
292}
293
294void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
295 assert(NumLoop < NumberOfLoops && "out of loops number.");
296 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
297}
298
Mike Rice0ed46662018-09-20 17:19:41 +0000299Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000300 assert(NumLoop < NumberOfLoops && "out of loops number.");
301 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
302}
303
Mike Rice0ed46662018-09-20 17:19:41 +0000304const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000305 assert(NumLoop < NumberOfLoops && "out of loops number.");
306 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
307}
308
James Y Knightb8bfd962015-10-02 13:41:04 +0000309void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
310 assert(VL.size() == varlist_size() &&
311 "Number of private copies is not the same as the preallocated buffer");
312 std::copy(VL.begin(), VL.end(), varlist_end());
313}
314
315OMPPrivateClause *
316OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
317 SourceLocation LParenLoc, SourceLocation EndLoc,
318 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
319 // Allocate space for private variables and initializer expressions.
James Y Knight374fd202016-01-01 00:38:24 +0000320 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000321 OMPPrivateClause *Clause =
322 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
323 Clause->setVarRefs(VL);
324 Clause->setPrivateCopies(PrivateVL);
325 return Clause;
326}
327
328OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
329 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000330 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000331 return new (Mem) OMPPrivateClause(N);
332}
333
334void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
335 assert(VL.size() == varlist_size() &&
336 "Number of private copies is not the same as the preallocated buffer");
337 std::copy(VL.begin(), VL.end(), varlist_end());
338}
339
340void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
341 assert(VL.size() == varlist_size() &&
342 "Number of inits is not the same as the preallocated buffer");
343 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
344}
345
346OMPFirstprivateClause *
347OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
348 SourceLocation LParenLoc, SourceLocation EndLoc,
349 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
Alexey Bataev417089f2016-02-17 13:19:37 +0000350 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
James Y Knight374fd202016-01-01 00:38:24 +0000351 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000352 OMPFirstprivateClause *Clause =
353 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
354 Clause->setVarRefs(VL);
355 Clause->setPrivateCopies(PrivateVL);
356 Clause->setInits(InitVL);
Alexey Bataev417089f2016-02-17 13:19:37 +0000357 Clause->setPreInitStmt(PreInit);
James Y Knightb8bfd962015-10-02 13:41:04 +0000358 return Clause;
359}
360
361OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
362 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000363 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000364 return new (Mem) OMPFirstprivateClause(N);
365}
366
367void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
368 assert(PrivateCopies.size() == varlist_size() &&
369 "Number of private copies is not the same as the preallocated buffer");
370 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
371}
372
373void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
374 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
375 "not the same as the "
376 "preallocated buffer");
377 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
378}
379
380void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
381 assert(DstExprs.size() == varlist_size() && "Number of destination "
382 "expressions is not the same as "
383 "the preallocated buffer");
384 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
385}
386
387void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
388 assert(AssignmentOps.size() == varlist_size() &&
389 "Number of assignment expressions is not the same as the preallocated "
390 "buffer");
391 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
392 getDestinationExprs().end());
393}
394
395OMPLastprivateClause *OMPLastprivateClause::Create(
396 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
397 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
Alexey Bataev005248a2016-02-25 05:25:57 +0000398 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit,
399 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000400 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000401 OMPLastprivateClause *Clause =
402 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
403 Clause->setVarRefs(VL);
404 Clause->setSourceExprs(SrcExprs);
405 Clause->setDestinationExprs(DstExprs);
406 Clause->setAssignmentOps(AssignmentOps);
Alexey Bataev005248a2016-02-25 05:25:57 +0000407 Clause->setPreInitStmt(PreInit);
408 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000409 return Clause;
410}
411
412OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
413 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000414 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000415 return new (Mem) OMPLastprivateClause(N);
416}
417
418OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
419 SourceLocation StartLoc,
420 SourceLocation LParenLoc,
421 SourceLocation EndLoc,
422 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000423 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000424 OMPSharedClause *Clause =
425 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
426 Clause->setVarRefs(VL);
427 return Clause;
428}
429
430OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000431 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000432 return new (Mem) OMPSharedClause(N);
433}
434
435void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
436 assert(PL.size() == varlist_size() &&
437 "Number of privates is not the same as the preallocated buffer");
438 std::copy(PL.begin(), PL.end(), varlist_end());
439}
440
441void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
442 assert(IL.size() == varlist_size() &&
443 "Number of inits is not the same as the preallocated buffer");
444 std::copy(IL.begin(), IL.end(), getPrivates().end());
445}
446
447void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
448 assert(UL.size() == varlist_size() &&
449 "Number of updates is not the same as the preallocated buffer");
450 std::copy(UL.begin(), UL.end(), getInits().end());
451}
452
453void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
454 assert(FL.size() == varlist_size() &&
455 "Number of final updates is not the same as the preallocated buffer");
456 std::copy(FL.begin(), FL.end(), getUpdates().end());
457}
458
Alexey Bataev195ae902019-08-08 13:42:45 +0000459void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) {
460 assert(
461 UE.size() == varlist_size() + 1 &&
462 "Number of used expressions is not the same as the preallocated buffer");
463 std::copy(UE.begin(), UE.end(), getFinals().end() + 2);
464}
465
James Y Knightb8bfd962015-10-02 13:41:04 +0000466OMPLinearClause *OMPLinearClause::Create(
467 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
468 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
469 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
Alexey Bataev78849fb2016-03-09 09:49:00 +0000470 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
471 Stmt *PreInit, Expr *PostUpdate) {
Alexey Bataev195ae902019-08-08 13:42:45 +0000472 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
473 // (Step and CalcStep), list of used expression + step.
474 void *Mem =
475 C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000476 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
477 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
478 Clause->setVarRefs(VL);
479 Clause->setPrivates(PL);
480 Clause->setInits(IL);
481 // Fill update and final expressions with zeroes, they are provided later,
482 // after the directive construction.
483 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
484 nullptr);
485 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
486 nullptr);
Alexey Bataev195ae902019-08-08 13:42:45 +0000487 std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(),
488 nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000489 Clause->setStep(Step);
490 Clause->setCalcStep(CalcStep);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000491 Clause->setPreInitStmt(PreInit);
492 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000493 return Clause;
494}
495
496OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
497 unsigned NumVars) {
Alexey Bataev195ae902019-08-08 13:42:45 +0000498 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
499 // (Step and CalcStep), list of used expression + step.
500 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars +1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000501 return new (Mem) OMPLinearClause(NumVars);
502}
503
Alexey Bataev195ae902019-08-08 13:42:45 +0000504OMPClause::child_range OMPLinearClause::used_children() {
505 // Range includes only non-nullptr elements.
506 return child_range(
507 reinterpret_cast<Stmt **>(getUsedExprs().begin()),
508 reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr)));
509}
510
James Y Knightb8bfd962015-10-02 13:41:04 +0000511OMPAlignedClause *
512OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
513 SourceLocation LParenLoc, SourceLocation ColonLoc,
514 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
James Y Knight374fd202016-01-01 00:38:24 +0000515 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000516 OMPAlignedClause *Clause = new (Mem)
517 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
518 Clause->setVarRefs(VL);
519 Clause->setAlignment(A);
520 return Clause;
521}
522
523OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
524 unsigned NumVars) {
James Y Knight374fd202016-01-01 00:38:24 +0000525 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000526 return new (Mem) OMPAlignedClause(NumVars);
527}
528
529void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
530 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
531 "not the same as the "
532 "preallocated buffer");
533 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
534}
535
536void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
537 assert(DstExprs.size() == varlist_size() && "Number of destination "
538 "expressions is not the same as "
539 "the preallocated buffer");
540 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
541}
542
543void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
544 assert(AssignmentOps.size() == varlist_size() &&
545 "Number of assignment expressions is not the same as the preallocated "
546 "buffer");
547 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
548 getDestinationExprs().end());
549}
550
551OMPCopyinClause *OMPCopyinClause::Create(
552 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
553 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
554 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000555 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000556 OMPCopyinClause *Clause =
557 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
558 Clause->setVarRefs(VL);
559 Clause->setSourceExprs(SrcExprs);
560 Clause->setDestinationExprs(DstExprs);
561 Clause->setAssignmentOps(AssignmentOps);
562 return Clause;
563}
564
565OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000566 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000567 return new (Mem) OMPCopyinClause(N);
568}
569
570void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
571 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
572 "not the same as the "
573 "preallocated buffer");
574 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
575}
576
577void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
578 assert(DstExprs.size() == varlist_size() && "Number of destination "
579 "expressions is not the same as "
580 "the preallocated buffer");
581 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
582}
583
584void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
585 assert(AssignmentOps.size() == varlist_size() &&
586 "Number of assignment expressions is not the same as the preallocated "
587 "buffer");
588 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
589 getDestinationExprs().end());
590}
591
592OMPCopyprivateClause *OMPCopyprivateClause::Create(
593 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
594 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
595 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000596 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000597 OMPCopyprivateClause *Clause =
598 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
599 Clause->setVarRefs(VL);
600 Clause->setSourceExprs(SrcExprs);
601 Clause->setDestinationExprs(DstExprs);
602 Clause->setAssignmentOps(AssignmentOps);
603 return Clause;
604}
605
606OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
607 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000608 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000609 return new (Mem) OMPCopyprivateClause(N);
610}
611
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000612void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
613 assert(Privates.size() == varlist_size() &&
614 "Number of private copies is not the same as the preallocated buffer");
615 std::copy(Privates.begin(), Privates.end(), varlist_end());
616}
617
James Y Knightb8bfd962015-10-02 13:41:04 +0000618void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
619 assert(
620 LHSExprs.size() == varlist_size() &&
621 "Number of LHS expressions is not the same as the preallocated buffer");
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000622 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
James Y Knightb8bfd962015-10-02 13:41:04 +0000623}
624
625void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
626 assert(
627 RHSExprs.size() == varlist_size() &&
628 "Number of RHS expressions is not the same as the preallocated buffer");
629 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
630}
631
632void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
633 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
634 "expressions is not the same "
635 "as the preallocated buffer");
636 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
637}
638
639OMPReductionClause *OMPReductionClause::Create(
640 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
641 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
642 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000643 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev61205072016-03-02 04:57:40 +0000644 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
645 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000646 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000647 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
648 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
649 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000650 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000651 Clause->setLHSExprs(LHSExprs);
652 Clause->setRHSExprs(RHSExprs);
653 Clause->setReductionOps(ReductionOps);
Alexey Bataev61205072016-03-02 04:57:40 +0000654 Clause->setPreInitStmt(PreInit);
655 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000656 return Clause;
657}
658
659OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
660 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000661 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000662 return new (Mem) OMPReductionClause(N);
663}
664
Alexey Bataev169d96a2017-07-18 20:17:46 +0000665void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
666 assert(Privates.size() == varlist_size() &&
667 "Number of private copies is not the same as the preallocated buffer");
668 std::copy(Privates.begin(), Privates.end(), varlist_end());
669}
670
671void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
672 assert(
673 LHSExprs.size() == varlist_size() &&
674 "Number of LHS expressions is not the same as the preallocated buffer");
675 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
676}
677
678void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
679 assert(
680 RHSExprs.size() == varlist_size() &&
681 "Number of RHS expressions is not the same as the preallocated buffer");
682 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
683}
684
685void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
686 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
687 "expressions is not the same "
688 "as the preallocated buffer");
689 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
690}
691
692OMPTaskReductionClause *OMPTaskReductionClause::Create(
693 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
694 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
695 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
696 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
697 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
698 Expr *PostUpdate) {
699 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
700 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
701 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
702 Clause->setVarRefs(VL);
703 Clause->setPrivates(Privates);
704 Clause->setLHSExprs(LHSExprs);
705 Clause->setRHSExprs(RHSExprs);
706 Clause->setReductionOps(ReductionOps);
707 Clause->setPreInitStmt(PreInit);
708 Clause->setPostUpdateExpr(PostUpdate);
709 return Clause;
710}
711
712OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
713 unsigned N) {
714 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
715 return new (Mem) OMPTaskReductionClause(N);
716}
717
Alexey Bataevfa312f32017-07-21 18:48:21 +0000718void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
719 assert(Privates.size() == varlist_size() &&
720 "Number of private copies is not the same as the preallocated buffer");
721 std::copy(Privates.begin(), Privates.end(), varlist_end());
722}
723
724void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
725 assert(
726 LHSExprs.size() == varlist_size() &&
727 "Number of LHS expressions is not the same as the preallocated buffer");
728 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
729}
730
731void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
732 assert(
733 RHSExprs.size() == varlist_size() &&
734 "Number of RHS expressions is not the same as the preallocated buffer");
735 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
736}
737
738void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
739 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
740 "expressions is not the same "
741 "as the preallocated buffer");
742 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
743}
744
Alexey Bataev88202be2017-07-27 13:20:36 +0000745void OMPInReductionClause::setTaskgroupDescriptors(
746 ArrayRef<Expr *> TaskgroupDescriptors) {
747 assert(TaskgroupDescriptors.size() == varlist_size() &&
748 "Number of in reduction descriptors is not the same as the "
749 "preallocated buffer");
750 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
751 getReductionOps().end());
752}
753
Alexey Bataevfa312f32017-07-21 18:48:21 +0000754OMPInReductionClause *OMPInReductionClause::Create(
755 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
756 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
757 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
758 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev88202be2017-07-27 13:20:36 +0000759 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
760 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
761 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000762 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
763 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
764 Clause->setVarRefs(VL);
765 Clause->setPrivates(Privates);
766 Clause->setLHSExprs(LHSExprs);
767 Clause->setRHSExprs(RHSExprs);
768 Clause->setReductionOps(ReductionOps);
Alexey Bataev88202be2017-07-27 13:20:36 +0000769 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000770 Clause->setPreInitStmt(PreInit);
771 Clause->setPostUpdateExpr(PostUpdate);
772 return Clause;
773}
774
775OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
776 unsigned N) {
Alexey Bataev88202be2017-07-27 13:20:36 +0000777 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000778 return new (Mem) OMPInReductionClause(N);
779}
780
Alexey Bataeve04483e2019-03-27 14:14:31 +0000781OMPAllocateClause *
782OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc,
783 SourceLocation LParenLoc, Expr *Allocator,
784 SourceLocation ColonLoc, SourceLocation EndLoc,
785 ArrayRef<Expr *> VL) {
786 // Allocate space for private variables and initializer expressions.
787 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
788 auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
789 ColonLoc, EndLoc, VL.size());
790 Clause->setVarRefs(VL);
791 return Clause;
792}
793
794OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
795 unsigned N) {
796 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
797 return new (Mem) OMPAllocateClause(N);
798}
799
James Y Knightb8bfd962015-10-02 13:41:04 +0000800OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
801 SourceLocation StartLoc,
802 SourceLocation LParenLoc,
803 SourceLocation EndLoc,
804 ArrayRef<Expr *> VL) {
Alexey Bataev8b427062016-05-25 12:36:08 +0000805 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000806 OMPFlushClause *Clause =
807 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
808 Clause->setVarRefs(VL);
809 return Clause;
810}
811
812OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000813 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000814 return new (Mem) OMPFlushClause(N);
815}
816
Alexey Bataevf138fda2018-08-13 19:04:24 +0000817OMPDependClause *
818OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
819 SourceLocation LParenLoc, SourceLocation EndLoc,
820 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
821 SourceLocation ColonLoc, ArrayRef<Expr *> VL,
822 unsigned NumLoops) {
823 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
824 OMPDependClause *Clause = new (Mem)
825 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000826 Clause->setVarRefs(VL);
827 Clause->setDependencyKind(DepKind);
828 Clause->setDependencyLoc(DepLoc);
829 Clause->setColonLoc(ColonLoc);
Alexey Bataevf138fda2018-08-13 19:04:24 +0000830 for (unsigned I = 0 ; I < NumLoops; ++I)
831 Clause->setLoopData(I, nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000832 return Clause;
833}
834
Alexey Bataevf138fda2018-08-13 19:04:24 +0000835OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
836 unsigned NumLoops) {
837 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
838 return new (Mem) OMPDependClause(N, NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000839}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000840
Alexey Bataevf138fda2018-08-13 19:04:24 +0000841void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
842 assert((getDependencyKind() == OMPC_DEPEND_sink ||
843 getDependencyKind() == OMPC_DEPEND_source) &&
844 NumLoop < NumLoops &&
845 "Expected sink or source depend + loop index must be less number of "
846 "loops.");
847 auto It = std::next(getVarRefs().end(), NumLoop);
848 *It = Cnt;
Alexey Bataev8b427062016-05-25 12:36:08 +0000849}
850
Alexey Bataevf138fda2018-08-13 19:04:24 +0000851Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
852 assert((getDependencyKind() == OMPC_DEPEND_sink ||
853 getDependencyKind() == OMPC_DEPEND_source) &&
854 NumLoop < NumLoops &&
855 "Expected sink or source depend + loop index must be less number of "
856 "loops.");
857 auto It = std::next(getVarRefs().end(), NumLoop);
858 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000859}
860
Alexey Bataevf138fda2018-08-13 19:04:24 +0000861const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
862 assert((getDependencyKind() == OMPC_DEPEND_sink ||
863 getDependencyKind() == OMPC_DEPEND_source) &&
864 NumLoop < NumLoops &&
865 "Expected sink or source depend + loop index must be less number of "
866 "loops.");
867 auto It = std::next(getVarRefs().end(), NumLoop);
868 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000869}
870
Samuel Antao90927002016-04-26 14:54:23 +0000871unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
872 MappableExprComponentListsRef ComponentLists) {
873 unsigned TotalNum = 0u;
874 for (auto &C : ComponentLists)
875 TotalNum += C.size();
876 return TotalNum;
877}
878
879unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
Alexey Bataeve3727102018-04-18 15:57:46 +0000880 ArrayRef<const ValueDecl *> Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000881 unsigned TotalNum = 0u;
882 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
Alexey Bataeve3727102018-04-18 15:57:46 +0000883 for (const ValueDecl *D : Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000884 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
885 if (Cache.count(VD))
886 continue;
887 ++TotalNum;
888 Cache.insert(VD);
889 }
890 return TotalNum;
891}
892
Michael Kruse4304e9d2019-02-19 16:38:20 +0000893OMPMapClause *OMPMapClause::Create(
894 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
895 ArrayRef<ValueDecl *> Declarations,
896 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
897 ArrayRef<OpenMPMapModifierKind> MapModifiers,
898 ArrayRef<SourceLocation> MapModifiersLoc,
899 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
900 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
901 OMPMappableExprListSizeTy Sizes;
902 Sizes.NumVars = Vars.size();
903 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
904 Sizes.NumComponentLists = ComponentLists.size();
905 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao90927002016-04-26 14:54:23 +0000906
907 // We need to allocate:
Michael Kruse4304e9d2019-02-19 16:38:20 +0000908 // 2 x NumVars x Expr* - we have an original list expression and an associated
909 // user-defined mapper for each clause list entry.
Samuel Antao90927002016-04-26 14:54:23 +0000910 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
911 // with each component list.
912 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
913 // number of lists for each unique declaration and the size of each component
914 // list.
915 // NumComponents x MappableComponent - the total of all the components in all
916 // the lists.
917 void *Mem = C.Allocate(
918 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
919 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000920 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
921 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
922 Sizes.NumComponents));
923 OMPMapClause *Clause = new (Mem)
924 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
925 Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
Samuel Antao90927002016-04-26 14:54:23 +0000926
927 Clause->setVarRefs(Vars);
Michael Kruse4304e9d2019-02-19 16:38:20 +0000928 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao90927002016-04-26 14:54:23 +0000929 Clause->setClauseInfo(Declarations, ComponentLists);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000930 Clause->setMapType(Type);
931 Clause->setMapLoc(TypeLoc);
932 return Clause;
933}
934
Michael Kruse4304e9d2019-02-19 16:38:20 +0000935OMPMapClause *
936OMPMapClause::CreateEmpty(const ASTContext &C,
937 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao90927002016-04-26 14:54:23 +0000938 void *Mem = C.Allocate(
939 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
940 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000941 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
942 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
943 Sizes.NumComponents));
944 return new (Mem) OMPMapClause(Sizes);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000945}
Samuel Antao661c0902016-05-26 17:39:58 +0000946
Michael Kruse01f670d2019-02-22 22:29:42 +0000947OMPToClause *OMPToClause::Create(
948 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
949 ArrayRef<ValueDecl *> Declarations,
950 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
951 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000952 OMPMappableExprListSizeTy Sizes;
953 Sizes.NumVars = Vars.size();
954 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
955 Sizes.NumComponentLists = ComponentLists.size();
956 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao661c0902016-05-26 17:39:58 +0000957
958 // We need to allocate:
Michael Kruse01f670d2019-02-22 22:29:42 +0000959 // 2 x NumVars x Expr* - we have an original list expression and an associated
960 // user-defined mapper for each clause list entry.
Samuel Antao661c0902016-05-26 17:39:58 +0000961 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
962 // with each component list.
963 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
964 // number of lists for each unique declaration and the size of each component
965 // list.
966 // NumComponents x MappableComponent - the total of all the components in all
967 // the lists.
968 void *Mem = C.Allocate(
969 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
970 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +0000971 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000972 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
973 Sizes.NumComponents));
Samuel Antao661c0902016-05-26 17:39:58 +0000974
Michael Kruse01f670d2019-02-22 22:29:42 +0000975 auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +0000976
977 Clause->setVarRefs(Vars);
Michael Kruse01f670d2019-02-22 22:29:42 +0000978 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao661c0902016-05-26 17:39:58 +0000979 Clause->setClauseInfo(Declarations, ComponentLists);
980 return Clause;
981}
982
Michael Kruse4304e9d2019-02-19 16:38:20 +0000983OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
984 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao661c0902016-05-26 17:39:58 +0000985 void *Mem = C.Allocate(
986 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
987 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +0000988 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000989 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
990 Sizes.NumComponents));
991 return new (Mem) OMPToClause(Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +0000992}
Samuel Antaoec172c62016-05-26 17:49:04 +0000993
Michael Kruse0336c752019-02-25 20:34:15 +0000994OMPFromClause *OMPFromClause::Create(
995 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
996 ArrayRef<ValueDecl *> Declarations,
997 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
998 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000999 OMPMappableExprListSizeTy Sizes;
1000 Sizes.NumVars = Vars.size();
1001 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1002 Sizes.NumComponentLists = ComponentLists.size();
1003 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaoec172c62016-05-26 17:49:04 +00001004
1005 // We need to allocate:
Michael Kruse0336c752019-02-25 20:34:15 +00001006 // 2 x NumVars x Expr* - we have an original list expression and an associated
1007 // user-defined mapper for each clause list entry.
Samuel Antaoec172c62016-05-26 17:49:04 +00001008 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1009 // with each component list.
1010 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1011 // number of lists for each unique declaration and the size of each component
1012 // list.
1013 // NumComponents x MappableComponent - the total of all the components in all
1014 // the lists.
1015 void *Mem = C.Allocate(
1016 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1017 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001018 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001019 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1020 Sizes.NumComponents));
Samuel Antaoec172c62016-05-26 17:49:04 +00001021
Michael Kruse0336c752019-02-25 20:34:15 +00001022 auto *Clause =
1023 new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001024
1025 Clause->setVarRefs(Vars);
Michael Kruse0336c752019-02-25 20:34:15 +00001026 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antaoec172c62016-05-26 17:49:04 +00001027 Clause->setClauseInfo(Declarations, ComponentLists);
1028 return Clause;
1029}
1030
Michael Kruse4304e9d2019-02-19 16:38:20 +00001031OMPFromClause *
1032OMPFromClause::CreateEmpty(const ASTContext &C,
1033 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaoec172c62016-05-26 17:49:04 +00001034 void *Mem = C.Allocate(
1035 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1036 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001037 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001038 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1039 Sizes.NumComponents));
1040 return new (Mem) OMPFromClause(Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001041}
Carlo Bertolli2404b172016-07-13 15:37:16 +00001042
Samuel Antaocc10b852016-07-28 14:23:26 +00001043void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1044 assert(VL.size() == varlist_size() &&
1045 "Number of private copies is not the same as the preallocated buffer");
1046 std::copy(VL.begin(), VL.end(), varlist_end());
1047}
1048
1049void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
1050 assert(VL.size() == varlist_size() &&
1051 "Number of inits is not the same as the preallocated buffer");
1052 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1053}
1054
1055OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001056 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1057 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
1058 ArrayRef<ValueDecl *> Declarations,
Samuel Antaocc10b852016-07-28 14:23:26 +00001059 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001060 OMPMappableExprListSizeTy Sizes;
1061 Sizes.NumVars = Vars.size();
1062 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1063 Sizes.NumComponentLists = ComponentLists.size();
1064 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaocc10b852016-07-28 14:23:26 +00001065
1066 // We need to allocate:
1067 // 3 x NumVars x Expr* - we have an original list expression for each clause
1068 // list entry and an equal number of private copies and inits.
1069 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1070 // with each component list.
1071 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1072 // number of lists for each unique declaration and the size of each component
1073 // list.
1074 // NumComponents x MappableComponent - the total of all the components in all
1075 // the lists.
1076 void *Mem = C.Allocate(
1077 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1078 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001079 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1080 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1081 Sizes.NumComponents));
Samuel Antaocc10b852016-07-28 14:23:26 +00001082
Michael Kruse4304e9d2019-02-19 16:38:20 +00001083 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
Samuel Antaocc10b852016-07-28 14:23:26 +00001084
1085 Clause->setVarRefs(Vars);
1086 Clause->setPrivateCopies(PrivateVars);
1087 Clause->setInits(Inits);
1088 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001089 return Clause;
1090}
1091
Michael Kruse4304e9d2019-02-19 16:38:20 +00001092OMPUseDevicePtrClause *
1093OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
1094 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaocc10b852016-07-28 14:23:26 +00001095 void *Mem = C.Allocate(
1096 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1097 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001098 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1099 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1100 Sizes.NumComponents));
1101 return new (Mem) OMPUseDevicePtrClause(Sizes);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001102}
Carlo Bertolli70594e92016-07-13 17:16:49 +00001103
Samuel Antao6890b092016-07-28 14:25:09 +00001104OMPIsDevicePtrClause *
Michael Kruse4304e9d2019-02-19 16:38:20 +00001105OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
Samuel Antao6890b092016-07-28 14:25:09 +00001106 ArrayRef<Expr *> Vars,
1107 ArrayRef<ValueDecl *> Declarations,
1108 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001109 OMPMappableExprListSizeTy Sizes;
1110 Sizes.NumVars = Vars.size();
1111 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1112 Sizes.NumComponentLists = ComponentLists.size();
1113 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao6890b092016-07-28 14:25:09 +00001114
1115 // We need to allocate:
1116 // NumVars x Expr* - we have an original list expression for each clause list
1117 // entry.
1118 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1119 // with each component list.
1120 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1121 // number of lists for each unique declaration and the size of each component
1122 // list.
1123 // NumComponents x MappableComponent - the total of all the components in all
1124 // the lists.
1125 void *Mem = C.Allocate(
1126 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1127 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001128 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1129 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1130 Sizes.NumComponents));
Samuel Antao6890b092016-07-28 14:25:09 +00001131
Michael Kruse4304e9d2019-02-19 16:38:20 +00001132 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
Samuel Antao6890b092016-07-28 14:25:09 +00001133
1134 Clause->setVarRefs(Vars);
1135 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001136 return Clause;
1137}
1138
Michael Kruse4304e9d2019-02-19 16:38:20 +00001139OMPIsDevicePtrClause *
1140OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1141 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao6890b092016-07-28 14:25:09 +00001142 void *Mem = C.Allocate(
1143 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1144 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001145 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1146 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1147 Sizes.NumComponents));
1148 return new (Mem) OMPIsDevicePtrClause(Sizes);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001149}
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001150
1151//===----------------------------------------------------------------------===//
1152// OpenMP clauses printing methods
1153//===----------------------------------------------------------------------===//
1154
1155void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1156 OS << "if(";
1157 if (Node->getNameModifier() != OMPD_unknown)
1158 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1159 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1160 OS << ")";
1161}
1162
1163void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1164 OS << "final(";
1165 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1166 OS << ")";
1167}
1168
1169void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1170 OS << "num_threads(";
1171 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1172 OS << ")";
1173}
1174
1175void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1176 OS << "safelen(";
1177 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1178 OS << ")";
1179}
1180
1181void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1182 OS << "simdlen(";
1183 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1184 OS << ")";
1185}
1186
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00001187void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
1188 OS << "allocator(";
1189 Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
1190 OS << ")";
1191}
1192
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001193void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1194 OS << "collapse(";
1195 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1196 OS << ")";
1197}
1198
1199void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1200 OS << "default("
1201 << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
1202 << ")";
1203}
1204
1205void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1206 OS << "proc_bind("
1207 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, Node->getProcBindKind())
1208 << ")";
1209}
1210
1211void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1212 OS << "unified_address";
1213}
1214
1215void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1216 OMPUnifiedSharedMemoryClause *) {
1217 OS << "unified_shared_memory";
1218}
1219
1220void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1221 OS << "reverse_offload";
1222}
1223
1224void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1225 OMPDynamicAllocatorsClause *) {
1226 OS << "dynamic_allocators";
1227}
1228
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00001229void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1230 OMPAtomicDefaultMemOrderClause *Node) {
1231 OS << "atomic_default_mem_order("
1232 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1233 Node->getAtomicDefaultMemOrderKind())
1234 << ")";
1235}
1236
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001237void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1238 OS << "schedule(";
1239 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1240 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1241 Node->getFirstScheduleModifier());
1242 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1243 OS << ", ";
1244 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1245 Node->getSecondScheduleModifier());
1246 }
1247 OS << ": ";
1248 }
1249 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1250 if (auto *E = Node->getChunkSize()) {
1251 OS << ", ";
1252 E->printPretty(OS, nullptr, Policy);
1253 }
1254 OS << ")";
1255}
1256
1257void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1258 OS << "ordered";
1259 if (auto *Num = Node->getNumForLoops()) {
1260 OS << "(";
1261 Num->printPretty(OS, nullptr, Policy, 0);
1262 OS << ")";
1263 }
1264}
1265
1266void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1267 OS << "nowait";
1268}
1269
1270void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1271 OS << "untied";
1272}
1273
1274void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1275 OS << "nogroup";
1276}
1277
1278void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1279 OS << "mergeable";
1280}
1281
1282void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1283
1284void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1285
1286void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
1287 OS << "update";
1288}
1289
1290void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1291 OS << "capture";
1292}
1293
1294void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1295 OS << "seq_cst";
1296}
1297
1298void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1299 OS << "threads";
1300}
1301
1302void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1303
1304void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1305 OS << "device(";
1306 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1307 OS << ")";
1308}
1309
1310void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1311 OS << "num_teams(";
1312 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1313 OS << ")";
1314}
1315
1316void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1317 OS << "thread_limit(";
1318 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1319 OS << ")";
1320}
1321
1322void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1323 OS << "priority(";
1324 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1325 OS << ")";
1326}
1327
1328void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1329 OS << "grainsize(";
1330 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1331 OS << ")";
1332}
1333
1334void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1335 OS << "num_tasks(";
1336 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1337 OS << ")";
1338}
1339
1340void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1341 OS << "hint(";
1342 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1343 OS << ")";
1344}
1345
1346template<typename T>
1347void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1348 for (typename T::varlist_iterator I = Node->varlist_begin(),
1349 E = Node->varlist_end();
1350 I != E; ++I) {
1351 assert(*I && "Expected non-null Stmt");
1352 OS << (I == Node->varlist_begin() ? StartSym : ',');
1353 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1354 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1355 DRE->printPretty(OS, nullptr, Policy, 0);
1356 else
1357 DRE->getDecl()->printQualifiedName(OS);
1358 } else
1359 (*I)->printPretty(OS, nullptr, Policy, 0);
1360 }
1361}
1362
Alexey Bataeve04483e2019-03-27 14:14:31 +00001363void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
1364 if (Node->varlist_empty())
1365 return;
1366 OS << "allocate";
1367 if (Expr *Allocator = Node->getAllocator()) {
1368 OS << "(";
1369 Allocator->printPretty(OS, nullptr, Policy, 0);
1370 OS << ":";
1371 VisitOMPClauseList(Node, ' ');
1372 } else {
1373 VisitOMPClauseList(Node, '(');
1374 }
1375 OS << ")";
1376}
1377
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001378void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1379 if (!Node->varlist_empty()) {
1380 OS << "private";
1381 VisitOMPClauseList(Node, '(');
1382 OS << ")";
1383 }
1384}
1385
1386void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1387 if (!Node->varlist_empty()) {
1388 OS << "firstprivate";
1389 VisitOMPClauseList(Node, '(');
1390 OS << ")";
1391 }
1392}
1393
1394void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1395 if (!Node->varlist_empty()) {
1396 OS << "lastprivate";
1397 VisitOMPClauseList(Node, '(');
1398 OS << ")";
1399 }
1400}
1401
1402void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1403 if (!Node->varlist_empty()) {
1404 OS << "shared";
1405 VisitOMPClauseList(Node, '(');
1406 OS << ")";
1407 }
1408}
1409
1410void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1411 if (!Node->varlist_empty()) {
1412 OS << "reduction(";
1413 NestedNameSpecifier *QualifierLoc =
1414 Node->getQualifierLoc().getNestedNameSpecifier();
1415 OverloadedOperatorKind OOK =
1416 Node->getNameInfo().getName().getCXXOverloadedOperator();
1417 if (QualifierLoc == nullptr && OOK != OO_None) {
1418 // Print reduction identifier in C format
1419 OS << getOperatorSpelling(OOK);
1420 } else {
1421 // Use C++ format
1422 if (QualifierLoc != nullptr)
1423 QualifierLoc->print(OS, Policy);
1424 OS << Node->getNameInfo();
1425 }
1426 OS << ":";
1427 VisitOMPClauseList(Node, ' ');
1428 OS << ")";
1429 }
1430}
1431
1432void OMPClausePrinter::VisitOMPTaskReductionClause(
1433 OMPTaskReductionClause *Node) {
1434 if (!Node->varlist_empty()) {
1435 OS << "task_reduction(";
1436 NestedNameSpecifier *QualifierLoc =
1437 Node->getQualifierLoc().getNestedNameSpecifier();
1438 OverloadedOperatorKind OOK =
1439 Node->getNameInfo().getName().getCXXOverloadedOperator();
1440 if (QualifierLoc == nullptr && OOK != OO_None) {
1441 // Print reduction identifier in C format
1442 OS << getOperatorSpelling(OOK);
1443 } else {
1444 // Use C++ format
1445 if (QualifierLoc != nullptr)
1446 QualifierLoc->print(OS, Policy);
1447 OS << Node->getNameInfo();
1448 }
1449 OS << ":";
1450 VisitOMPClauseList(Node, ' ');
1451 OS << ")";
1452 }
1453}
1454
1455void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1456 if (!Node->varlist_empty()) {
1457 OS << "in_reduction(";
1458 NestedNameSpecifier *QualifierLoc =
1459 Node->getQualifierLoc().getNestedNameSpecifier();
1460 OverloadedOperatorKind OOK =
1461 Node->getNameInfo().getName().getCXXOverloadedOperator();
1462 if (QualifierLoc == nullptr && OOK != OO_None) {
1463 // Print reduction identifier in C format
1464 OS << getOperatorSpelling(OOK);
1465 } else {
1466 // Use C++ format
1467 if (QualifierLoc != nullptr)
1468 QualifierLoc->print(OS, Policy);
1469 OS << Node->getNameInfo();
1470 }
1471 OS << ":";
1472 VisitOMPClauseList(Node, ' ');
1473 OS << ")";
1474 }
1475}
1476
1477void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1478 if (!Node->varlist_empty()) {
1479 OS << "linear";
1480 if (Node->getModifierLoc().isValid()) {
1481 OS << '('
1482 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1483 }
1484 VisitOMPClauseList(Node, '(');
1485 if (Node->getModifierLoc().isValid())
1486 OS << ')';
1487 if (Node->getStep() != nullptr) {
1488 OS << ": ";
1489 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1490 }
1491 OS << ")";
1492 }
1493}
1494
1495void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1496 if (!Node->varlist_empty()) {
1497 OS << "aligned";
1498 VisitOMPClauseList(Node, '(');
1499 if (Node->getAlignment() != nullptr) {
1500 OS << ": ";
1501 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1502 }
1503 OS << ")";
1504 }
1505}
1506
1507void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1508 if (!Node->varlist_empty()) {
1509 OS << "copyin";
1510 VisitOMPClauseList(Node, '(');
1511 OS << ")";
1512 }
1513}
1514
1515void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1516 if (!Node->varlist_empty()) {
1517 OS << "copyprivate";
1518 VisitOMPClauseList(Node, '(');
1519 OS << ")";
1520 }
1521}
1522
1523void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1524 if (!Node->varlist_empty()) {
1525 VisitOMPClauseList(Node, '(');
1526 OS << ")";
1527 }
1528}
1529
1530void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1531 OS << "depend(";
1532 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1533 Node->getDependencyKind());
1534 if (!Node->varlist_empty()) {
1535 OS << " :";
1536 VisitOMPClauseList(Node, ' ');
1537 }
1538 OS << ")";
1539}
1540
1541void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1542 if (!Node->varlist_empty()) {
1543 OS << "map(";
1544 if (Node->getMapType() != OMPC_MAP_unknown) {
Kelvin Lief579432018-12-18 22:18:41 +00001545 for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1546 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1547 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1548 Node->getMapTypeModifier(I));
Michael Kruse4304e9d2019-02-19 16:38:20 +00001549 if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1550 OS << '(';
1551 NestedNameSpecifier *MapperNNS =
1552 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1553 if (MapperNNS)
1554 MapperNNS->print(OS, Policy);
1555 OS << Node->getMapperIdInfo() << ')';
1556 }
Kelvin Lief579432018-12-18 22:18:41 +00001557 OS << ',';
1558 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001559 }
1560 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1561 OS << ':';
1562 }
1563 VisitOMPClauseList(Node, ' ');
1564 OS << ")";
1565 }
1566}
1567
1568void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1569 if (!Node->varlist_empty()) {
1570 OS << "to";
Michael Kruse01f670d2019-02-22 22:29:42 +00001571 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1572 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1573 OS << '(';
1574 OS << "mapper(";
1575 NestedNameSpecifier *MapperNNS =
1576 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1577 if (MapperNNS)
1578 MapperNNS->print(OS, Policy);
1579 OS << MapperId << "):";
1580 VisitOMPClauseList(Node, ' ');
1581 } else {
1582 VisitOMPClauseList(Node, '(');
1583 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001584 OS << ")";
1585 }
1586}
1587
1588void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1589 if (!Node->varlist_empty()) {
1590 OS << "from";
Michael Kruse0336c752019-02-25 20:34:15 +00001591 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1592 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1593 OS << '(';
1594 OS << "mapper(";
1595 NestedNameSpecifier *MapperNNS =
1596 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1597 if (MapperNNS)
1598 MapperNNS->print(OS, Policy);
1599 OS << MapperId << "):";
1600 VisitOMPClauseList(Node, ' ');
1601 } else {
1602 VisitOMPClauseList(Node, '(');
1603 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001604 OS << ")";
1605 }
1606}
1607
1608void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1609 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1610 OMPC_dist_schedule, Node->getDistScheduleKind());
1611 if (auto *E = Node->getChunkSize()) {
1612 OS << ", ";
1613 E->printPretty(OS, nullptr, Policy);
1614 }
1615 OS << ")";
1616}
1617
1618void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1619 OS << "defaultmap(";
1620 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1621 Node->getDefaultmapModifier());
1622 OS << ": ";
1623 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1624 Node->getDefaultmapKind());
1625 OS << ")";
1626}
1627
1628void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1629 if (!Node->varlist_empty()) {
1630 OS << "use_device_ptr";
1631 VisitOMPClauseList(Node, '(');
1632 OS << ")";
1633 }
1634}
1635
1636void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1637 if (!Node->varlist_empty()) {
1638 OS << "is_device_ptr";
1639 VisitOMPClauseList(Node, '(');
1640 OS << ")";
1641 }
1642}
1643