blob: 6eac98250c8ff737af3148f3410b2f06b6136b0c [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"
Alexey Bataev93dc40d2019-12-20 11:04:57 -050018#include "clang/Basic/OpenMPKinds.h"
Eugene Zelenkod1b2d222017-11-29 23:27:36 +000019#include "llvm/ADT/SmallPtrSet.h"
20#include "llvm/Support/Casting.h"
21#include "llvm/Support/ErrorHandling.h"
22#include <algorithm>
23#include <cassert>
James Y Knightb8bfd962015-10-02 13:41:04 +000024
25using namespace clang;
26
27OMPClause::child_range OMPClause::children() {
28 switch (getClauseKind()) {
29 default:
30 break;
31#define OPENMP_CLAUSE(Name, Class) \
32 case OMPC_##Name: \
33 return static_cast<Class *>(this)->children();
34#include "clang/Basic/OpenMPKinds.def"
35 }
36 llvm_unreachable("unknown OMPClause");
37}
38
Alexey Bataevc2c21ef2019-07-11 14:54:17 +000039OMPClause::child_range OMPClause::used_children() {
40 switch (getClauseKind()) {
41#define OPENMP_CLAUSE(Name, Class) \
42 case OMPC_##Name: \
43 return static_cast<Class *>(this)->used_children();
44#include "clang/Basic/OpenMPKinds.def"
45 case OMPC_threadprivate:
46 case OMPC_uniform:
Alexey Bataev729e2422019-08-23 16:11:14 +000047 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +000048 case OMPC_match:
Alexey Bataevc2c21ef2019-07-11 14:54:17 +000049 case OMPC_unknown:
50 break;
51 }
52 llvm_unreachable("unknown OMPClause");
53}
54
Alexey Bataev3392d762016-02-16 11:18:12 +000055OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
56 auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
57 return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr;
58}
59
60const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
61 switch (C->getClauseKind()) {
62 case OMPC_schedule:
63 return static_cast<const OMPScheduleClause *>(C);
64 case OMPC_dist_schedule:
65 return static_cast<const OMPDistScheduleClause *>(C);
Alexey Bataev417089f2016-02-17 13:19:37 +000066 case OMPC_firstprivate:
67 return static_cast<const OMPFirstprivateClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +000068 case OMPC_lastprivate:
69 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +000070 case OMPC_reduction:
71 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +000072 case OMPC_task_reduction:
73 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +000074 case OMPC_in_reduction:
75 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +000076 case OMPC_linear:
77 return static_cast<const OMPLinearClause *>(C);
Arpith Chacko Jacobfe4890a2017-01-18 20:40:48 +000078 case OMPC_if:
79 return static_cast<const OMPIfClause *>(C);
Arpith Chacko Jacob33c849a2017-01-25 00:57:16 +000080 case OMPC_num_threads:
81 return static_cast<const OMPNumThreadsClause *>(C);
Arpith Chacko Jacobbc126342017-01-25 11:28:18 +000082 case OMPC_num_teams:
83 return static_cast<const OMPNumTeamsClause *>(C);
Arpith Chacko Jacob7ecc0b72017-01-25 11:44:35 +000084 case OMPC_thread_limit:
85 return static_cast<const OMPThreadLimitClause *>(C);
Alexey Bataev931e19b2017-10-02 16:32:39 +000086 case OMPC_device:
87 return static_cast<const OMPDeviceClause *>(C);
Alexey Bataevb9c55e22019-10-14 19:29:52 +000088 case OMPC_grainsize:
89 return static_cast<const OMPGrainsizeClause *>(C);
Alexey Bataevd88c7de2019-10-14 20:44:34 +000090 case OMPC_num_tasks:
91 return static_cast<const OMPNumTasksClause *>(C);
Alexey Bataev3a842ec2019-10-15 19:37:05 +000092 case OMPC_final:
93 return static_cast<const OMPFinalClause *>(C);
Alexey Bataev31ba4762019-10-16 18:09:37 +000094 case OMPC_priority:
95 return static_cast<const OMPPriorityClause *>(C);
Alexey Bataev3392d762016-02-16 11:18:12 +000096 case OMPC_default:
97 case OMPC_proc_bind:
Alexey Bataev3392d762016-02-16 11:18:12 +000098 case OMPC_safelen:
99 case OMPC_simdlen:
Alexey Bataev9cc10fc2019-03-12 18:52:33 +0000100 case OMPC_allocator:
Alexey Bataeve04483e2019-03-27 14:14:31 +0000101 case OMPC_allocate:
Alexey Bataev3392d762016-02-16 11:18:12 +0000102 case OMPC_collapse:
103 case OMPC_private:
Alexey Bataev005248a2016-02-25 05:25:57 +0000104 case OMPC_shared:
Alexey Bataev005248a2016-02-25 05:25:57 +0000105 case OMPC_aligned:
106 case OMPC_copyin:
107 case OMPC_copyprivate:
108 case OMPC_ordered:
109 case OMPC_nowait:
110 case OMPC_untied:
111 case OMPC_mergeable:
112 case OMPC_threadprivate:
113 case OMPC_flush:
114 case OMPC_read:
115 case OMPC_write:
116 case OMPC_update:
117 case OMPC_capture:
118 case OMPC_seq_cst:
Alexey Bataevea9166b2020-02-06 16:30:23 -0500119 case OMPC_acq_rel:
Alexey Bataev04a830f2020-02-10 14:30:39 -0500120 case OMPC_acquire:
Alexey Bataev95598342020-02-10 15:49:05 -0500121 case OMPC_release:
Alexey Bataev9a8defc2020-02-11 11:10:43 -0500122 case OMPC_relaxed:
Alexey Bataev005248a2016-02-25 05:25:57 +0000123 case OMPC_depend:
Alexey Bataev005248a2016-02-25 05:25:57 +0000124 case OMPC_threads:
125 case OMPC_simd:
126 case OMPC_map:
Alexey Bataev005248a2016-02-25 05:25:57 +0000127 case OMPC_nogroup:
Alexey Bataev005248a2016-02-25 05:25:57 +0000128 case OMPC_hint:
129 case OMPC_defaultmap:
130 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000131 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000132 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000133 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000134 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000135 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000136 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000137 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000138 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000139 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000140 case OMPC_atomic_default_mem_order:
Alexey Bataev729e2422019-08-23 16:11:14 +0000141 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +0000142 case OMPC_match:
Alexey Bataevb6e70842019-12-16 15:54:17 -0500143 case OMPC_nontemporal:
Alexey Bataevcb8e6912020-01-31 16:09:26 -0500144 case OMPC_order:
Alexey Bataev005248a2016-02-25 05:25:57 +0000145 break;
146 }
147
148 return nullptr;
149}
150
151OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
152 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
153 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
154}
155
156const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
157 switch (C->getClauseKind()) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000158 case OMPC_lastprivate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000159 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000160 case OMPC_reduction:
161 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +0000162 case OMPC_task_reduction:
163 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000164 case OMPC_in_reduction:
165 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000166 case OMPC_linear:
167 return static_cast<const OMPLinearClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000168 case OMPC_schedule:
169 case OMPC_dist_schedule:
170 case OMPC_firstprivate:
171 case OMPC_default:
172 case OMPC_proc_bind:
173 case OMPC_if:
174 case OMPC_final:
175 case OMPC_num_threads:
176 case OMPC_safelen:
177 case OMPC_simdlen:
Alexey Bataev9cc10fc2019-03-12 18:52:33 +0000178 case OMPC_allocator:
Alexey Bataeve04483e2019-03-27 14:14:31 +0000179 case OMPC_allocate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000180 case OMPC_collapse:
181 case OMPC_private:
Alexey Bataev3392d762016-02-16 11:18:12 +0000182 case OMPC_shared:
Alexey Bataev3392d762016-02-16 11:18:12 +0000183 case OMPC_aligned:
184 case OMPC_copyin:
185 case OMPC_copyprivate:
186 case OMPC_ordered:
187 case OMPC_nowait:
188 case OMPC_untied:
189 case OMPC_mergeable:
190 case OMPC_threadprivate:
191 case OMPC_flush:
192 case OMPC_read:
193 case OMPC_write:
194 case OMPC_update:
195 case OMPC_capture:
196 case OMPC_seq_cst:
Alexey Bataevea9166b2020-02-06 16:30:23 -0500197 case OMPC_acq_rel:
Alexey Bataev04a830f2020-02-10 14:30:39 -0500198 case OMPC_acquire:
Alexey Bataev95598342020-02-10 15:49:05 -0500199 case OMPC_release:
Alexey Bataev9a8defc2020-02-11 11:10:43 -0500200 case OMPC_relaxed:
Alexey Bataev3392d762016-02-16 11:18:12 +0000201 case OMPC_depend:
202 case OMPC_device:
203 case OMPC_threads:
204 case OMPC_simd:
205 case OMPC_map:
206 case OMPC_num_teams:
207 case OMPC_thread_limit:
208 case OMPC_priority:
209 case OMPC_grainsize:
210 case OMPC_nogroup:
211 case OMPC_num_tasks:
212 case OMPC_hint:
213 case OMPC_defaultmap:
214 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000215 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000216 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000217 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000218 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000219 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000220 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000221 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000222 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000223 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000224 case OMPC_atomic_default_mem_order:
Alexey Bataev729e2422019-08-23 16:11:14 +0000225 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +0000226 case OMPC_match:
Alexey Bataevb6e70842019-12-16 15:54:17 -0500227 case OMPC_nontemporal:
Alexey Bataevcb8e6912020-01-31 16:09:26 -0500228 case OMPC_order:
Alexey Bataev3392d762016-02-16 11:18:12 +0000229 break;
230 }
231
232 return nullptr;
233}
234
Alexey Bataev655cb4a2019-07-16 14:51:46 +0000235/// Gets the address of the original, non-captured, expression used in the
236/// clause as the preinitializer.
237static Stmt **getAddrOfExprAsWritten(Stmt *S) {
238 if (!S)
239 return nullptr;
240 if (auto *DS = dyn_cast<DeclStmt>(S)) {
241 assert(DS->isSingleDecl() && "Only single expression must be captured.");
242 if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
243 return OED->getInitAddress();
244 }
245 return nullptr;
246}
247
248OMPClause::child_range OMPIfClause::used_children() {
249 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
250 return child_range(C, C + 1);
251 return child_range(&Condition, &Condition + 1);
252}
253
Alexey Bataevb9c55e22019-10-14 19:29:52 +0000254OMPClause::child_range OMPGrainsizeClause::used_children() {
255 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
256 return child_range(C, C + 1);
257 return child_range(&Grainsize, &Grainsize + 1);
258}
259
Alexey Bataevd88c7de2019-10-14 20:44:34 +0000260OMPClause::child_range OMPNumTasksClause::used_children() {
261 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
262 return child_range(C, C + 1);
263 return child_range(&NumTasks, &NumTasks + 1);
264}
265
Alexey Bataev3a842ec2019-10-15 19:37:05 +0000266OMPClause::child_range OMPFinalClause::used_children() {
267 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
268 return child_range(C, C + 1);
269 return child_range(&Condition, &Condition + 1);
270}
271
Alexey Bataev31ba4762019-10-16 18:09:37 +0000272OMPClause::child_range OMPPriorityClause::used_children() {
273 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
274 return child_range(C, C + 1);
275 return child_range(&Priority, &Priority + 1);
276}
277
Alexey Bataevf138fda2018-08-13 19:04:24 +0000278OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
279 unsigned NumLoops,
280 SourceLocation StartLoc,
281 SourceLocation LParenLoc,
282 SourceLocation EndLoc) {
283 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
284 auto *Clause =
285 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
286 for (unsigned I = 0; I < NumLoops; ++I) {
287 Clause->setLoopNumIterations(I, nullptr);
288 Clause->setLoopCounter(I, nullptr);
289 }
290 return Clause;
291}
292
293OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
294 unsigned NumLoops) {
295 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
296 auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
297 for (unsigned I = 0; I < NumLoops; ++I) {
298 Clause->setLoopNumIterations(I, nullptr);
299 Clause->setLoopCounter(I, nullptr);
300 }
301 return Clause;
302}
303
304void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
305 Expr *NumIterations) {
306 assert(NumLoop < NumberOfLoops && "out of loops number.");
307 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
308}
309
310ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
311 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
312}
313
314void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
315 assert(NumLoop < NumberOfLoops && "out of loops number.");
316 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
317}
318
Mike Rice0ed46662018-09-20 17:19:41 +0000319Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000320 assert(NumLoop < NumberOfLoops && "out of loops number.");
321 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
322}
323
Mike Rice0ed46662018-09-20 17:19:41 +0000324const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000325 assert(NumLoop < NumberOfLoops && "out of loops number.");
326 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
327}
328
James Y Knightb8bfd962015-10-02 13:41:04 +0000329void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
330 assert(VL.size() == varlist_size() &&
331 "Number of private copies is not the same as the preallocated buffer");
332 std::copy(VL.begin(), VL.end(), varlist_end());
333}
334
335OMPPrivateClause *
336OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
337 SourceLocation LParenLoc, SourceLocation EndLoc,
338 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
339 // Allocate space for private variables and initializer expressions.
James Y Knight374fd202016-01-01 00:38:24 +0000340 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000341 OMPPrivateClause *Clause =
342 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
343 Clause->setVarRefs(VL);
344 Clause->setPrivateCopies(PrivateVL);
345 return Clause;
346}
347
348OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
349 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000350 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000351 return new (Mem) OMPPrivateClause(N);
352}
353
354void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
355 assert(VL.size() == varlist_size() &&
356 "Number of private copies is not the same as the preallocated buffer");
357 std::copy(VL.begin(), VL.end(), varlist_end());
358}
359
360void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
361 assert(VL.size() == varlist_size() &&
362 "Number of inits is not the same as the preallocated buffer");
363 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
364}
365
366OMPFirstprivateClause *
367OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
368 SourceLocation LParenLoc, SourceLocation EndLoc,
369 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
Alexey Bataev417089f2016-02-17 13:19:37 +0000370 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
James Y Knight374fd202016-01-01 00:38:24 +0000371 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000372 OMPFirstprivateClause *Clause =
373 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
374 Clause->setVarRefs(VL);
375 Clause->setPrivateCopies(PrivateVL);
376 Clause->setInits(InitVL);
Alexey Bataev417089f2016-02-17 13:19:37 +0000377 Clause->setPreInitStmt(PreInit);
James Y Knightb8bfd962015-10-02 13:41:04 +0000378 return Clause;
379}
380
381OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
382 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000383 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000384 return new (Mem) OMPFirstprivateClause(N);
385}
386
387void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
388 assert(PrivateCopies.size() == varlist_size() &&
389 "Number of private copies is not the same as the preallocated buffer");
390 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
391}
392
393void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
394 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
395 "not the same as the "
396 "preallocated buffer");
397 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
398}
399
400void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
401 assert(DstExprs.size() == varlist_size() && "Number of destination "
402 "expressions is not the same as "
403 "the preallocated buffer");
404 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
405}
406
407void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
408 assert(AssignmentOps.size() == varlist_size() &&
409 "Number of assignment expressions is not the same as the preallocated "
410 "buffer");
411 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
412 getDestinationExprs().end());
413}
414
415OMPLastprivateClause *OMPLastprivateClause::Create(
416 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
417 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
Alexey Bataev93dc40d2019-12-20 11:04:57 -0500418 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
419 OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
420 SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000421 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
Alexey Bataev93dc40d2019-12-20 11:04:57 -0500422 OMPLastprivateClause *Clause = new (Mem) OMPLastprivateClause(
423 StartLoc, LParenLoc, EndLoc, LPKind, LPKindLoc, ColonLoc, VL.size());
James Y Knightb8bfd962015-10-02 13:41:04 +0000424 Clause->setVarRefs(VL);
425 Clause->setSourceExprs(SrcExprs);
426 Clause->setDestinationExprs(DstExprs);
427 Clause->setAssignmentOps(AssignmentOps);
Alexey Bataev005248a2016-02-25 05:25:57 +0000428 Clause->setPreInitStmt(PreInit);
429 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000430 return Clause;
431}
432
433OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
434 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000435 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000436 return new (Mem) OMPLastprivateClause(N);
437}
438
439OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
440 SourceLocation StartLoc,
441 SourceLocation LParenLoc,
442 SourceLocation EndLoc,
443 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000444 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000445 OMPSharedClause *Clause =
446 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
447 Clause->setVarRefs(VL);
448 return Clause;
449}
450
451OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000452 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000453 return new (Mem) OMPSharedClause(N);
454}
455
456void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
457 assert(PL.size() == varlist_size() &&
458 "Number of privates is not the same as the preallocated buffer");
459 std::copy(PL.begin(), PL.end(), varlist_end());
460}
461
462void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
463 assert(IL.size() == varlist_size() &&
464 "Number of inits is not the same as the preallocated buffer");
465 std::copy(IL.begin(), IL.end(), getPrivates().end());
466}
467
468void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
469 assert(UL.size() == varlist_size() &&
470 "Number of updates is not the same as the preallocated buffer");
471 std::copy(UL.begin(), UL.end(), getInits().end());
472}
473
474void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
475 assert(FL.size() == varlist_size() &&
476 "Number of final updates is not the same as the preallocated buffer");
477 std::copy(FL.begin(), FL.end(), getUpdates().end());
478}
479
Alexey Bataev195ae902019-08-08 13:42:45 +0000480void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) {
481 assert(
482 UE.size() == varlist_size() + 1 &&
483 "Number of used expressions is not the same as the preallocated buffer");
484 std::copy(UE.begin(), UE.end(), getFinals().end() + 2);
485}
486
James Y Knightb8bfd962015-10-02 13:41:04 +0000487OMPLinearClause *OMPLinearClause::Create(
488 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
489 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
490 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
Alexey Bataev78849fb2016-03-09 09:49:00 +0000491 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
492 Stmt *PreInit, Expr *PostUpdate) {
Alexey Bataev195ae902019-08-08 13:42:45 +0000493 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
494 // (Step and CalcStep), list of used expression + step.
495 void *Mem =
496 C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000497 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
498 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
499 Clause->setVarRefs(VL);
500 Clause->setPrivates(PL);
501 Clause->setInits(IL);
502 // Fill update and final expressions with zeroes, they are provided later,
503 // after the directive construction.
504 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
505 nullptr);
506 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
507 nullptr);
Alexey Bataev195ae902019-08-08 13:42:45 +0000508 std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(),
509 nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000510 Clause->setStep(Step);
511 Clause->setCalcStep(CalcStep);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000512 Clause->setPreInitStmt(PreInit);
513 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000514 return Clause;
515}
516
517OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
518 unsigned NumVars) {
Alexey Bataev195ae902019-08-08 13:42:45 +0000519 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
520 // (Step and CalcStep), list of used expression + step.
521 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars +1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000522 return new (Mem) OMPLinearClause(NumVars);
523}
524
Alexey Bataev195ae902019-08-08 13:42:45 +0000525OMPClause::child_range OMPLinearClause::used_children() {
526 // Range includes only non-nullptr elements.
527 return child_range(
528 reinterpret_cast<Stmt **>(getUsedExprs().begin()),
529 reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr)));
530}
531
James Y Knightb8bfd962015-10-02 13:41:04 +0000532OMPAlignedClause *
533OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
534 SourceLocation LParenLoc, SourceLocation ColonLoc,
535 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
James Y Knight374fd202016-01-01 00:38:24 +0000536 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000537 OMPAlignedClause *Clause = new (Mem)
538 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
539 Clause->setVarRefs(VL);
540 Clause->setAlignment(A);
541 return Clause;
542}
543
544OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
545 unsigned NumVars) {
James Y Knight374fd202016-01-01 00:38:24 +0000546 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000547 return new (Mem) OMPAlignedClause(NumVars);
548}
549
550void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
551 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
552 "not the same as the "
553 "preallocated buffer");
554 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
555}
556
557void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
558 assert(DstExprs.size() == varlist_size() && "Number of destination "
559 "expressions is not the same as "
560 "the preallocated buffer");
561 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
562}
563
564void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
565 assert(AssignmentOps.size() == varlist_size() &&
566 "Number of assignment expressions is not the same as the preallocated "
567 "buffer");
568 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
569 getDestinationExprs().end());
570}
571
572OMPCopyinClause *OMPCopyinClause::Create(
573 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
574 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
575 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000576 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000577 OMPCopyinClause *Clause =
578 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
579 Clause->setVarRefs(VL);
580 Clause->setSourceExprs(SrcExprs);
581 Clause->setDestinationExprs(DstExprs);
582 Clause->setAssignmentOps(AssignmentOps);
583 return Clause;
584}
585
586OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000587 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000588 return new (Mem) OMPCopyinClause(N);
589}
590
591void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
592 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
593 "not the same as the "
594 "preallocated buffer");
595 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
596}
597
598void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
599 assert(DstExprs.size() == varlist_size() && "Number of destination "
600 "expressions is not the same as "
601 "the preallocated buffer");
602 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
603}
604
605void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
606 assert(AssignmentOps.size() == varlist_size() &&
607 "Number of assignment expressions is not the same as the preallocated "
608 "buffer");
609 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
610 getDestinationExprs().end());
611}
612
613OMPCopyprivateClause *OMPCopyprivateClause::Create(
614 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
615 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
616 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000617 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000618 OMPCopyprivateClause *Clause =
619 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
620 Clause->setVarRefs(VL);
621 Clause->setSourceExprs(SrcExprs);
622 Clause->setDestinationExprs(DstExprs);
623 Clause->setAssignmentOps(AssignmentOps);
624 return Clause;
625}
626
627OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
628 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000629 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000630 return new (Mem) OMPCopyprivateClause(N);
631}
632
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000633void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
634 assert(Privates.size() == varlist_size() &&
635 "Number of private copies is not the same as the preallocated buffer");
636 std::copy(Privates.begin(), Privates.end(), varlist_end());
637}
638
James Y Knightb8bfd962015-10-02 13:41:04 +0000639void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
640 assert(
641 LHSExprs.size() == varlist_size() &&
642 "Number of LHS expressions is not the same as the preallocated buffer");
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000643 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
James Y Knightb8bfd962015-10-02 13:41:04 +0000644}
645
646void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
647 assert(
648 RHSExprs.size() == varlist_size() &&
649 "Number of RHS expressions is not the same as the preallocated buffer");
650 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
651}
652
653void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
654 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
655 "expressions is not the same "
656 "as the preallocated buffer");
657 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
658}
659
660OMPReductionClause *OMPReductionClause::Create(
661 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
662 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
663 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000664 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev61205072016-03-02 04:57:40 +0000665 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
666 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000667 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000668 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
669 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
670 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000671 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000672 Clause->setLHSExprs(LHSExprs);
673 Clause->setRHSExprs(RHSExprs);
674 Clause->setReductionOps(ReductionOps);
Alexey Bataev61205072016-03-02 04:57:40 +0000675 Clause->setPreInitStmt(PreInit);
676 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000677 return Clause;
678}
679
680OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
681 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000682 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000683 return new (Mem) OMPReductionClause(N);
684}
685
Alexey Bataev169d96a2017-07-18 20:17:46 +0000686void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
687 assert(Privates.size() == varlist_size() &&
688 "Number of private copies is not the same as the preallocated buffer");
689 std::copy(Privates.begin(), Privates.end(), varlist_end());
690}
691
692void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
693 assert(
694 LHSExprs.size() == varlist_size() &&
695 "Number of LHS expressions is not the same as the preallocated buffer");
696 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
697}
698
699void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
700 assert(
701 RHSExprs.size() == varlist_size() &&
702 "Number of RHS expressions is not the same as the preallocated buffer");
703 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
704}
705
706void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
707 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
708 "expressions is not the same "
709 "as the preallocated buffer");
710 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
711}
712
713OMPTaskReductionClause *OMPTaskReductionClause::Create(
714 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
715 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
716 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
717 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
718 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
719 Expr *PostUpdate) {
720 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
721 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
722 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
723 Clause->setVarRefs(VL);
724 Clause->setPrivates(Privates);
725 Clause->setLHSExprs(LHSExprs);
726 Clause->setRHSExprs(RHSExprs);
727 Clause->setReductionOps(ReductionOps);
728 Clause->setPreInitStmt(PreInit);
729 Clause->setPostUpdateExpr(PostUpdate);
730 return Clause;
731}
732
733OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
734 unsigned N) {
735 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
736 return new (Mem) OMPTaskReductionClause(N);
737}
738
Alexey Bataevfa312f32017-07-21 18:48:21 +0000739void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
740 assert(Privates.size() == varlist_size() &&
741 "Number of private copies is not the same as the preallocated buffer");
742 std::copy(Privates.begin(), Privates.end(), varlist_end());
743}
744
745void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
746 assert(
747 LHSExprs.size() == varlist_size() &&
748 "Number of LHS expressions is not the same as the preallocated buffer");
749 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
750}
751
752void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
753 assert(
754 RHSExprs.size() == varlist_size() &&
755 "Number of RHS expressions is not the same as the preallocated buffer");
756 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
757}
758
759void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
760 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
761 "expressions is not the same "
762 "as the preallocated buffer");
763 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
764}
765
Alexey Bataev88202be2017-07-27 13:20:36 +0000766void OMPInReductionClause::setTaskgroupDescriptors(
767 ArrayRef<Expr *> TaskgroupDescriptors) {
768 assert(TaskgroupDescriptors.size() == varlist_size() &&
769 "Number of in reduction descriptors is not the same as the "
770 "preallocated buffer");
771 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
772 getReductionOps().end());
773}
774
Alexey Bataevfa312f32017-07-21 18:48:21 +0000775OMPInReductionClause *OMPInReductionClause::Create(
776 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
777 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
778 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
779 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev88202be2017-07-27 13:20:36 +0000780 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
781 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
782 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000783 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
784 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
785 Clause->setVarRefs(VL);
786 Clause->setPrivates(Privates);
787 Clause->setLHSExprs(LHSExprs);
788 Clause->setRHSExprs(RHSExprs);
789 Clause->setReductionOps(ReductionOps);
Alexey Bataev88202be2017-07-27 13:20:36 +0000790 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000791 Clause->setPreInitStmt(PreInit);
792 Clause->setPostUpdateExpr(PostUpdate);
793 return Clause;
794}
795
796OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
797 unsigned N) {
Alexey Bataev88202be2017-07-27 13:20:36 +0000798 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000799 return new (Mem) OMPInReductionClause(N);
800}
801
Alexey Bataeve04483e2019-03-27 14:14:31 +0000802OMPAllocateClause *
803OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc,
804 SourceLocation LParenLoc, Expr *Allocator,
805 SourceLocation ColonLoc, SourceLocation EndLoc,
806 ArrayRef<Expr *> VL) {
807 // Allocate space for private variables and initializer expressions.
808 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
809 auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
810 ColonLoc, EndLoc, VL.size());
811 Clause->setVarRefs(VL);
812 return Clause;
813}
814
815OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
816 unsigned N) {
817 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
818 return new (Mem) OMPAllocateClause(N);
819}
820
James Y Knightb8bfd962015-10-02 13:41:04 +0000821OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
822 SourceLocation StartLoc,
823 SourceLocation LParenLoc,
824 SourceLocation EndLoc,
825 ArrayRef<Expr *> VL) {
Alexey Bataev8b427062016-05-25 12:36:08 +0000826 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000827 OMPFlushClause *Clause =
828 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
829 Clause->setVarRefs(VL);
830 return Clause;
831}
832
833OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000834 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000835 return new (Mem) OMPFlushClause(N);
836}
837
Alexey Bataevf138fda2018-08-13 19:04:24 +0000838OMPDependClause *
839OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
840 SourceLocation LParenLoc, SourceLocation EndLoc,
841 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
842 SourceLocation ColonLoc, ArrayRef<Expr *> VL,
843 unsigned NumLoops) {
844 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
845 OMPDependClause *Clause = new (Mem)
846 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000847 Clause->setVarRefs(VL);
848 Clause->setDependencyKind(DepKind);
849 Clause->setDependencyLoc(DepLoc);
850 Clause->setColonLoc(ColonLoc);
Alexey Bataevf138fda2018-08-13 19:04:24 +0000851 for (unsigned I = 0 ; I < NumLoops; ++I)
852 Clause->setLoopData(I, nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000853 return Clause;
854}
855
Alexey Bataevf138fda2018-08-13 19:04:24 +0000856OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
857 unsigned NumLoops) {
858 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
859 return new (Mem) OMPDependClause(N, NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000860}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000861
Alexey Bataevf138fda2018-08-13 19:04:24 +0000862void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
863 assert((getDependencyKind() == OMPC_DEPEND_sink ||
864 getDependencyKind() == OMPC_DEPEND_source) &&
865 NumLoop < NumLoops &&
866 "Expected sink or source depend + loop index must be less number of "
867 "loops.");
868 auto It = std::next(getVarRefs().end(), NumLoop);
869 *It = Cnt;
Alexey Bataev8b427062016-05-25 12:36:08 +0000870}
871
Alexey Bataevf138fda2018-08-13 19:04:24 +0000872Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
873 assert((getDependencyKind() == OMPC_DEPEND_sink ||
874 getDependencyKind() == OMPC_DEPEND_source) &&
875 NumLoop < NumLoops &&
876 "Expected sink or source depend + loop index must be less number of "
877 "loops.");
878 auto It = std::next(getVarRefs().end(), NumLoop);
879 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000880}
881
Alexey Bataevf138fda2018-08-13 19:04:24 +0000882const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
883 assert((getDependencyKind() == OMPC_DEPEND_sink ||
884 getDependencyKind() == OMPC_DEPEND_source) &&
885 NumLoop < NumLoops &&
886 "Expected sink or source depend + loop index must be less number of "
887 "loops.");
888 auto It = std::next(getVarRefs().end(), NumLoop);
889 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000890}
891
Samuel Antao90927002016-04-26 14:54:23 +0000892unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
893 MappableExprComponentListsRef ComponentLists) {
894 unsigned TotalNum = 0u;
895 for (auto &C : ComponentLists)
896 TotalNum += C.size();
897 return TotalNum;
898}
899
900unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
Alexey Bataeve3727102018-04-18 15:57:46 +0000901 ArrayRef<const ValueDecl *> Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000902 unsigned TotalNum = 0u;
903 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
Alexey Bataeve3727102018-04-18 15:57:46 +0000904 for (const ValueDecl *D : Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000905 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
906 if (Cache.count(VD))
907 continue;
908 ++TotalNum;
909 Cache.insert(VD);
910 }
911 return TotalNum;
912}
913
Michael Kruse4304e9d2019-02-19 16:38:20 +0000914OMPMapClause *OMPMapClause::Create(
915 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
916 ArrayRef<ValueDecl *> Declarations,
917 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
918 ArrayRef<OpenMPMapModifierKind> MapModifiers,
919 ArrayRef<SourceLocation> MapModifiersLoc,
920 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
921 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
922 OMPMappableExprListSizeTy Sizes;
923 Sizes.NumVars = Vars.size();
924 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
925 Sizes.NumComponentLists = ComponentLists.size();
926 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao90927002016-04-26 14:54:23 +0000927
928 // We need to allocate:
Michael Kruse4304e9d2019-02-19 16:38:20 +0000929 // 2 x NumVars x Expr* - we have an original list expression and an associated
930 // user-defined mapper for each clause list entry.
Samuel Antao90927002016-04-26 14:54:23 +0000931 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
932 // with each component list.
933 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
934 // number of lists for each unique declaration and the size of each component
935 // list.
936 // NumComponents x MappableComponent - the total of all the components in all
937 // the lists.
938 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 OMPMapClause *Clause = new (Mem)
945 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
946 Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
Samuel Antao90927002016-04-26 14:54:23 +0000947
948 Clause->setVarRefs(Vars);
Michael Kruse4304e9d2019-02-19 16:38:20 +0000949 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao90927002016-04-26 14:54:23 +0000950 Clause->setClauseInfo(Declarations, ComponentLists);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000951 Clause->setMapType(Type);
952 Clause->setMapLoc(TypeLoc);
953 return Clause;
954}
955
Michael Kruse4304e9d2019-02-19 16:38:20 +0000956OMPMapClause *
957OMPMapClause::CreateEmpty(const ASTContext &C,
958 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao90927002016-04-26 14:54:23 +0000959 void *Mem = C.Allocate(
960 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
961 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000962 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
963 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
964 Sizes.NumComponents));
965 return new (Mem) OMPMapClause(Sizes);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000966}
Samuel Antao661c0902016-05-26 17:39:58 +0000967
Michael Kruse01f670d2019-02-22 22:29:42 +0000968OMPToClause *OMPToClause::Create(
969 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
970 ArrayRef<ValueDecl *> Declarations,
971 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
972 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000973 OMPMappableExprListSizeTy Sizes;
974 Sizes.NumVars = Vars.size();
975 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
976 Sizes.NumComponentLists = ComponentLists.size();
977 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao661c0902016-05-26 17:39:58 +0000978
979 // We need to allocate:
Michael Kruse01f670d2019-02-22 22:29:42 +0000980 // 2 x NumVars x Expr* - we have an original list expression and an associated
981 // user-defined mapper for each clause list entry.
Samuel Antao661c0902016-05-26 17:39:58 +0000982 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
983 // with each component list.
984 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
985 // number of lists for each unique declaration and the size of each component
986 // list.
987 // NumComponents x MappableComponent - the total of all the components in all
988 // the lists.
989 void *Mem = C.Allocate(
990 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
991 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +0000992 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000993 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
994 Sizes.NumComponents));
Samuel Antao661c0902016-05-26 17:39:58 +0000995
Michael Kruse01f670d2019-02-22 22:29:42 +0000996 auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +0000997
998 Clause->setVarRefs(Vars);
Michael Kruse01f670d2019-02-22 22:29:42 +0000999 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao661c0902016-05-26 17:39:58 +00001000 Clause->setClauseInfo(Declarations, ComponentLists);
1001 return Clause;
1002}
1003
Michael Kruse4304e9d2019-02-19 16:38:20 +00001004OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
1005 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao661c0902016-05-26 17:39:58 +00001006 void *Mem = C.Allocate(
1007 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1008 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +00001009 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001010 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1011 Sizes.NumComponents));
1012 return new (Mem) OMPToClause(Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +00001013}
Samuel Antaoec172c62016-05-26 17:49:04 +00001014
Michael Kruse0336c752019-02-25 20:34:15 +00001015OMPFromClause *OMPFromClause::Create(
1016 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1017 ArrayRef<ValueDecl *> Declarations,
1018 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1019 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001020 OMPMappableExprListSizeTy Sizes;
1021 Sizes.NumVars = Vars.size();
1022 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1023 Sizes.NumComponentLists = ComponentLists.size();
1024 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaoec172c62016-05-26 17:49:04 +00001025
1026 // We need to allocate:
Michael Kruse0336c752019-02-25 20:34:15 +00001027 // 2 x NumVars x Expr* - we have an original list expression and an associated
1028 // user-defined mapper for each clause list entry.
Samuel Antaoec172c62016-05-26 17:49:04 +00001029 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1030 // with each component list.
1031 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1032 // number of lists for each unique declaration and the size of each component
1033 // list.
1034 // NumComponents x MappableComponent - the total of all the components in all
1035 // the lists.
1036 void *Mem = C.Allocate(
1037 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1038 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001039 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001040 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1041 Sizes.NumComponents));
Samuel Antaoec172c62016-05-26 17:49:04 +00001042
Michael Kruse0336c752019-02-25 20:34:15 +00001043 auto *Clause =
1044 new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001045
1046 Clause->setVarRefs(Vars);
Michael Kruse0336c752019-02-25 20:34:15 +00001047 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antaoec172c62016-05-26 17:49:04 +00001048 Clause->setClauseInfo(Declarations, ComponentLists);
1049 return Clause;
1050}
1051
Michael Kruse4304e9d2019-02-19 16:38:20 +00001052OMPFromClause *
1053OMPFromClause::CreateEmpty(const ASTContext &C,
1054 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaoec172c62016-05-26 17:49:04 +00001055 void *Mem = C.Allocate(
1056 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1057 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001058 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001059 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1060 Sizes.NumComponents));
1061 return new (Mem) OMPFromClause(Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001062}
Carlo Bertolli2404b172016-07-13 15:37:16 +00001063
Samuel Antaocc10b852016-07-28 14:23:26 +00001064void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1065 assert(VL.size() == varlist_size() &&
1066 "Number of private copies is not the same as the preallocated buffer");
1067 std::copy(VL.begin(), VL.end(), varlist_end());
1068}
1069
1070void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
1071 assert(VL.size() == varlist_size() &&
1072 "Number of inits is not the same as the preallocated buffer");
1073 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1074}
1075
1076OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001077 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1078 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
1079 ArrayRef<ValueDecl *> Declarations,
Samuel Antaocc10b852016-07-28 14:23:26 +00001080 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001081 OMPMappableExprListSizeTy Sizes;
1082 Sizes.NumVars = Vars.size();
1083 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1084 Sizes.NumComponentLists = ComponentLists.size();
1085 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaocc10b852016-07-28 14:23:26 +00001086
1087 // We need to allocate:
1088 // 3 x NumVars x Expr* - we have an original list expression for each clause
1089 // list entry and an equal number of private copies and inits.
1090 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1091 // with each component list.
1092 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1093 // number of lists for each unique declaration and the size of each component
1094 // list.
1095 // NumComponents x MappableComponent - the total of all the components in all
1096 // the lists.
1097 void *Mem = C.Allocate(
1098 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1099 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001100 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1101 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1102 Sizes.NumComponents));
Samuel Antaocc10b852016-07-28 14:23:26 +00001103
Michael Kruse4304e9d2019-02-19 16:38:20 +00001104 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
Samuel Antaocc10b852016-07-28 14:23:26 +00001105
1106 Clause->setVarRefs(Vars);
1107 Clause->setPrivateCopies(PrivateVars);
1108 Clause->setInits(Inits);
1109 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001110 return Clause;
1111}
1112
Michael Kruse4304e9d2019-02-19 16:38:20 +00001113OMPUseDevicePtrClause *
1114OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
1115 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaocc10b852016-07-28 14:23:26 +00001116 void *Mem = C.Allocate(
1117 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1118 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001119 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1120 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1121 Sizes.NumComponents));
1122 return new (Mem) OMPUseDevicePtrClause(Sizes);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001123}
Carlo Bertolli70594e92016-07-13 17:16:49 +00001124
Samuel Antao6890b092016-07-28 14:25:09 +00001125OMPIsDevicePtrClause *
Michael Kruse4304e9d2019-02-19 16:38:20 +00001126OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
Samuel Antao6890b092016-07-28 14:25:09 +00001127 ArrayRef<Expr *> Vars,
1128 ArrayRef<ValueDecl *> Declarations,
1129 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001130 OMPMappableExprListSizeTy Sizes;
1131 Sizes.NumVars = Vars.size();
1132 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1133 Sizes.NumComponentLists = ComponentLists.size();
1134 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao6890b092016-07-28 14:25:09 +00001135
1136 // We need to allocate:
1137 // NumVars x Expr* - we have an original list expression for each clause list
1138 // entry.
1139 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1140 // with each component list.
1141 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1142 // number of lists for each unique declaration and the size of each component
1143 // list.
1144 // NumComponents x MappableComponent - the total of all the components in all
1145 // the lists.
1146 void *Mem = C.Allocate(
1147 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1148 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001149 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1150 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1151 Sizes.NumComponents));
Samuel Antao6890b092016-07-28 14:25:09 +00001152
Michael Kruse4304e9d2019-02-19 16:38:20 +00001153 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
Samuel Antao6890b092016-07-28 14:25:09 +00001154
1155 Clause->setVarRefs(Vars);
1156 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001157 return Clause;
1158}
1159
Michael Kruse4304e9d2019-02-19 16:38:20 +00001160OMPIsDevicePtrClause *
1161OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1162 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao6890b092016-07-28 14:25:09 +00001163 void *Mem = C.Allocate(
1164 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1165 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001166 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1167 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1168 Sizes.NumComponents));
1169 return new (Mem) OMPIsDevicePtrClause(Sizes);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001170}
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001171
Alexey Bataevb6e70842019-12-16 15:54:17 -05001172OMPNontemporalClause *OMPNontemporalClause::Create(const ASTContext &C,
1173 SourceLocation StartLoc,
1174 SourceLocation LParenLoc,
1175 SourceLocation EndLoc,
1176 ArrayRef<Expr *> VL) {
Alexey Bataev0860db92019-12-19 10:01:10 -05001177 // Allocate space for nontemporal variables + private references.
1178 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
Alexey Bataevb6e70842019-12-16 15:54:17 -05001179 auto *Clause =
1180 new (Mem) OMPNontemporalClause(StartLoc, LParenLoc, EndLoc, VL.size());
1181 Clause->setVarRefs(VL);
1182 return Clause;
1183}
1184
1185OMPNontemporalClause *OMPNontemporalClause::CreateEmpty(const ASTContext &C,
1186 unsigned N) {
Alexey Bataev0860db92019-12-19 10:01:10 -05001187 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
Alexey Bataevb6e70842019-12-16 15:54:17 -05001188 return new (Mem) OMPNontemporalClause(N);
1189}
1190
Alexey Bataev0860db92019-12-19 10:01:10 -05001191void OMPNontemporalClause::setPrivateRefs(ArrayRef<Expr *> VL) {
1192 assert(VL.size() == varlist_size() && "Number of private references is not "
1193 "the same as the preallocated buffer");
1194 std::copy(VL.begin(), VL.end(), varlist_end());
1195}
1196
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001197//===----------------------------------------------------------------------===//
1198// OpenMP clauses printing methods
1199//===----------------------------------------------------------------------===//
1200
1201void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1202 OS << "if(";
Johannes Doerferteb3e81f2019-11-04 22:00:49 -06001203 if (Node->getNameModifier() != llvm::omp::OMPD_unknown)
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001204 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1205 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1206 OS << ")";
1207}
1208
1209void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1210 OS << "final(";
1211 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1212 OS << ")";
1213}
1214
1215void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1216 OS << "num_threads(";
1217 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1218 OS << ")";
1219}
1220
1221void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1222 OS << "safelen(";
1223 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1224 OS << ")";
1225}
1226
1227void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1228 OS << "simdlen(";
1229 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1230 OS << ")";
1231}
1232
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00001233void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
1234 OS << "allocator(";
1235 Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
1236 OS << ")";
1237}
1238
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001239void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1240 OS << "collapse(";
1241 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1242 OS << ")";
1243}
1244
1245void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1246 OS << "default("
1247 << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
1248 << ")";
1249}
1250
1251void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1252 OS << "proc_bind("
Johannes Doerfert6c5d1f402019-12-25 18:15:36 -06001253 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind,
1254 unsigned(Node->getProcBindKind()))
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001255 << ")";
1256}
1257
1258void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1259 OS << "unified_address";
1260}
1261
1262void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1263 OMPUnifiedSharedMemoryClause *) {
1264 OS << "unified_shared_memory";
1265}
1266
1267void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1268 OS << "reverse_offload";
1269}
1270
1271void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1272 OMPDynamicAllocatorsClause *) {
1273 OS << "dynamic_allocators";
1274}
1275
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00001276void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1277 OMPAtomicDefaultMemOrderClause *Node) {
1278 OS << "atomic_default_mem_order("
1279 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1280 Node->getAtomicDefaultMemOrderKind())
1281 << ")";
1282}
1283
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001284void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1285 OS << "schedule(";
1286 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1287 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1288 Node->getFirstScheduleModifier());
1289 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1290 OS << ", ";
1291 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1292 Node->getSecondScheduleModifier());
1293 }
1294 OS << ": ";
1295 }
1296 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1297 if (auto *E = Node->getChunkSize()) {
1298 OS << ", ";
1299 E->printPretty(OS, nullptr, Policy);
1300 }
1301 OS << ")";
1302}
1303
1304void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1305 OS << "ordered";
1306 if (auto *Num = Node->getNumForLoops()) {
1307 OS << "(";
1308 Num->printPretty(OS, nullptr, Policy, 0);
1309 OS << ")";
1310 }
1311}
1312
1313void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1314 OS << "nowait";
1315}
1316
1317void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1318 OS << "untied";
1319}
1320
1321void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1322 OS << "nogroup";
1323}
1324
1325void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1326 OS << "mergeable";
1327}
1328
1329void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1330
1331void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1332
1333void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
1334 OS << "update";
1335}
1336
1337void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1338 OS << "capture";
1339}
1340
1341void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1342 OS << "seq_cst";
1343}
1344
Alexey Bataevea9166b2020-02-06 16:30:23 -05001345void OMPClausePrinter::VisitOMPAcqRelClause(OMPAcqRelClause *) {
1346 OS << "acq_rel";
1347}
1348
Alexey Bataev04a830f2020-02-10 14:30:39 -05001349void OMPClausePrinter::VisitOMPAcquireClause(OMPAcquireClause *) {
1350 OS << "acquire";
1351}
1352
Alexey Bataev95598342020-02-10 15:49:05 -05001353void OMPClausePrinter::VisitOMPReleaseClause(OMPReleaseClause *) {
1354 OS << "release";
1355}
1356
Alexey Bataev9a8defc2020-02-11 11:10:43 -05001357void OMPClausePrinter::VisitOMPRelaxedClause(OMPRelaxedClause *) {
1358 OS << "relaxed";
1359}
1360
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001361void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1362 OS << "threads";
1363}
1364
1365void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1366
1367void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1368 OS << "device(";
1369 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1370 OS << ")";
1371}
1372
1373void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1374 OS << "num_teams(";
1375 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1376 OS << ")";
1377}
1378
1379void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1380 OS << "thread_limit(";
1381 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1382 OS << ")";
1383}
1384
1385void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1386 OS << "priority(";
1387 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1388 OS << ")";
1389}
1390
1391void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1392 OS << "grainsize(";
1393 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1394 OS << ")";
1395}
1396
1397void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1398 OS << "num_tasks(";
1399 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1400 OS << ")";
1401}
1402
1403void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1404 OS << "hint(";
1405 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1406 OS << ")";
1407}
1408
1409template<typename T>
1410void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1411 for (typename T::varlist_iterator I = Node->varlist_begin(),
1412 E = Node->varlist_end();
1413 I != E; ++I) {
1414 assert(*I && "Expected non-null Stmt");
1415 OS << (I == Node->varlist_begin() ? StartSym : ',');
1416 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1417 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1418 DRE->printPretty(OS, nullptr, Policy, 0);
1419 else
1420 DRE->getDecl()->printQualifiedName(OS);
1421 } else
1422 (*I)->printPretty(OS, nullptr, Policy, 0);
1423 }
1424}
1425
Alexey Bataeve04483e2019-03-27 14:14:31 +00001426void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
1427 if (Node->varlist_empty())
1428 return;
1429 OS << "allocate";
1430 if (Expr *Allocator = Node->getAllocator()) {
1431 OS << "(";
1432 Allocator->printPretty(OS, nullptr, Policy, 0);
1433 OS << ":";
1434 VisitOMPClauseList(Node, ' ');
1435 } else {
1436 VisitOMPClauseList(Node, '(');
1437 }
1438 OS << ")";
1439}
1440
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001441void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1442 if (!Node->varlist_empty()) {
1443 OS << "private";
1444 VisitOMPClauseList(Node, '(');
1445 OS << ")";
1446 }
1447}
1448
1449void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1450 if (!Node->varlist_empty()) {
1451 OS << "firstprivate";
1452 VisitOMPClauseList(Node, '(');
1453 OS << ")";
1454 }
1455}
1456
1457void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1458 if (!Node->varlist_empty()) {
1459 OS << "lastprivate";
Alexey Bataev93dc40d2019-12-20 11:04:57 -05001460 OpenMPLastprivateModifier LPKind = Node->getKind();
1461 if (LPKind != OMPC_LASTPRIVATE_unknown) {
1462 OS << "("
1463 << getOpenMPSimpleClauseTypeName(OMPC_lastprivate, Node->getKind())
1464 << ":";
1465 }
1466 VisitOMPClauseList(Node, LPKind == OMPC_LASTPRIVATE_unknown ? '(' : ' ');
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001467 OS << ")";
1468 }
1469}
1470
1471void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1472 if (!Node->varlist_empty()) {
1473 OS << "shared";
1474 VisitOMPClauseList(Node, '(');
1475 OS << ")";
1476 }
1477}
1478
1479void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1480 if (!Node->varlist_empty()) {
1481 OS << "reduction(";
1482 NestedNameSpecifier *QualifierLoc =
1483 Node->getQualifierLoc().getNestedNameSpecifier();
1484 OverloadedOperatorKind OOK =
1485 Node->getNameInfo().getName().getCXXOverloadedOperator();
1486 if (QualifierLoc == nullptr && OOK != OO_None) {
1487 // Print reduction identifier in C format
1488 OS << getOperatorSpelling(OOK);
1489 } else {
1490 // Use C++ format
1491 if (QualifierLoc != nullptr)
1492 QualifierLoc->print(OS, Policy);
1493 OS << Node->getNameInfo();
1494 }
1495 OS << ":";
1496 VisitOMPClauseList(Node, ' ');
1497 OS << ")";
1498 }
1499}
1500
1501void OMPClausePrinter::VisitOMPTaskReductionClause(
1502 OMPTaskReductionClause *Node) {
1503 if (!Node->varlist_empty()) {
1504 OS << "task_reduction(";
1505 NestedNameSpecifier *QualifierLoc =
1506 Node->getQualifierLoc().getNestedNameSpecifier();
1507 OverloadedOperatorKind OOK =
1508 Node->getNameInfo().getName().getCXXOverloadedOperator();
1509 if (QualifierLoc == nullptr && OOK != OO_None) {
1510 // Print reduction identifier in C format
1511 OS << getOperatorSpelling(OOK);
1512 } else {
1513 // Use C++ format
1514 if (QualifierLoc != nullptr)
1515 QualifierLoc->print(OS, Policy);
1516 OS << Node->getNameInfo();
1517 }
1518 OS << ":";
1519 VisitOMPClauseList(Node, ' ');
1520 OS << ")";
1521 }
1522}
1523
1524void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1525 if (!Node->varlist_empty()) {
1526 OS << "in_reduction(";
1527 NestedNameSpecifier *QualifierLoc =
1528 Node->getQualifierLoc().getNestedNameSpecifier();
1529 OverloadedOperatorKind OOK =
1530 Node->getNameInfo().getName().getCXXOverloadedOperator();
1531 if (QualifierLoc == nullptr && OOK != OO_None) {
1532 // Print reduction identifier in C format
1533 OS << getOperatorSpelling(OOK);
1534 } else {
1535 // Use C++ format
1536 if (QualifierLoc != nullptr)
1537 QualifierLoc->print(OS, Policy);
1538 OS << Node->getNameInfo();
1539 }
1540 OS << ":";
1541 VisitOMPClauseList(Node, ' ');
1542 OS << ")";
1543 }
1544}
1545
1546void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1547 if (!Node->varlist_empty()) {
1548 OS << "linear";
1549 if (Node->getModifierLoc().isValid()) {
1550 OS << '('
1551 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1552 }
1553 VisitOMPClauseList(Node, '(');
1554 if (Node->getModifierLoc().isValid())
1555 OS << ')';
1556 if (Node->getStep() != nullptr) {
1557 OS << ": ";
1558 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1559 }
1560 OS << ")";
1561 }
1562}
1563
1564void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1565 if (!Node->varlist_empty()) {
1566 OS << "aligned";
1567 VisitOMPClauseList(Node, '(');
1568 if (Node->getAlignment() != nullptr) {
1569 OS << ": ";
1570 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1571 }
1572 OS << ")";
1573 }
1574}
1575
1576void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1577 if (!Node->varlist_empty()) {
1578 OS << "copyin";
1579 VisitOMPClauseList(Node, '(');
1580 OS << ")";
1581 }
1582}
1583
1584void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1585 if (!Node->varlist_empty()) {
1586 OS << "copyprivate";
1587 VisitOMPClauseList(Node, '(');
1588 OS << ")";
1589 }
1590}
1591
1592void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1593 if (!Node->varlist_empty()) {
1594 VisitOMPClauseList(Node, '(');
1595 OS << ")";
1596 }
1597}
1598
1599void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1600 OS << "depend(";
1601 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1602 Node->getDependencyKind());
1603 if (!Node->varlist_empty()) {
1604 OS << " :";
1605 VisitOMPClauseList(Node, ' ');
1606 }
1607 OS << ")";
1608}
1609
1610void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1611 if (!Node->varlist_empty()) {
1612 OS << "map(";
1613 if (Node->getMapType() != OMPC_MAP_unknown) {
Kelvin Lief579432018-12-18 22:18:41 +00001614 for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1615 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1616 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1617 Node->getMapTypeModifier(I));
Michael Kruse4304e9d2019-02-19 16:38:20 +00001618 if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1619 OS << '(';
1620 NestedNameSpecifier *MapperNNS =
1621 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1622 if (MapperNNS)
1623 MapperNNS->print(OS, Policy);
1624 OS << Node->getMapperIdInfo() << ')';
1625 }
Kelvin Lief579432018-12-18 22:18:41 +00001626 OS << ',';
1627 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001628 }
1629 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1630 OS << ':';
1631 }
1632 VisitOMPClauseList(Node, ' ');
1633 OS << ")";
1634 }
1635}
1636
1637void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1638 if (!Node->varlist_empty()) {
1639 OS << "to";
Michael Kruse01f670d2019-02-22 22:29:42 +00001640 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1641 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1642 OS << '(';
1643 OS << "mapper(";
1644 NestedNameSpecifier *MapperNNS =
1645 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1646 if (MapperNNS)
1647 MapperNNS->print(OS, Policy);
1648 OS << MapperId << "):";
1649 VisitOMPClauseList(Node, ' ');
1650 } else {
1651 VisitOMPClauseList(Node, '(');
1652 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001653 OS << ")";
1654 }
1655}
1656
1657void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1658 if (!Node->varlist_empty()) {
1659 OS << "from";
Michael Kruse0336c752019-02-25 20:34:15 +00001660 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1661 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1662 OS << '(';
1663 OS << "mapper(";
1664 NestedNameSpecifier *MapperNNS =
1665 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1666 if (MapperNNS)
1667 MapperNNS->print(OS, Policy);
1668 OS << MapperId << "):";
1669 VisitOMPClauseList(Node, ' ');
1670 } else {
1671 VisitOMPClauseList(Node, '(');
1672 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001673 OS << ")";
1674 }
1675}
1676
1677void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1678 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1679 OMPC_dist_schedule, Node->getDistScheduleKind());
1680 if (auto *E = Node->getChunkSize()) {
1681 OS << ", ";
1682 E->printPretty(OS, nullptr, Policy);
1683 }
1684 OS << ")";
1685}
1686
1687void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1688 OS << "defaultmap(";
1689 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1690 Node->getDefaultmapModifier());
1691 OS << ": ";
1692 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1693 Node->getDefaultmapKind());
1694 OS << ")";
1695}
1696
1697void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1698 if (!Node->varlist_empty()) {
1699 OS << "use_device_ptr";
1700 VisitOMPClauseList(Node, '(');
1701 OS << ")";
1702 }
1703}
1704
1705void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1706 if (!Node->varlist_empty()) {
1707 OS << "is_device_ptr";
1708 VisitOMPClauseList(Node, '(');
1709 OS << ")";
1710 }
1711}
1712
Alexey Bataevb6e70842019-12-16 15:54:17 -05001713void OMPClausePrinter::VisitOMPNontemporalClause(OMPNontemporalClause *Node) {
1714 if (!Node->varlist_empty()) {
1715 OS << "nontemporal";
1716 VisitOMPClauseList(Node, '(');
1717 OS << ")";
1718 }
1719}
Alexey Bataevcb8e6912020-01-31 16:09:26 -05001720
1721void OMPClausePrinter::VisitOMPOrderClause(OMPOrderClause *Node) {
1722 OS << "order(" << getOpenMPSimpleClauseTypeName(OMPC_order, Node->getKind())
1723 << ")";
1724}