blob: f062c3e463a8759c13ea220c293ee31c21bd108f [file] [log] [blame]
Eugene Zelenkod1b2d222017-11-29 23:27:36 +00001//===- OpenMPClause.cpp - Classes for OpenMP clauses ----------------------===//
James Y Knightb8bfd962015-10-02 13:41:04 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
James Y Knightb8bfd962015-10-02 13:41:04 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the subclesses of Stmt class declared in OpenMPClause.h
10//
11//===----------------------------------------------------------------------===//
12
13#include "clang/AST/OpenMPClause.h"
James Y Knightb8bfd962015-10-02 13:41:04 +000014#include "clang/AST/ASTContext.h"
Eugene Zelenkod1b2d222017-11-29 23:27:36 +000015#include "clang/AST/Decl.h"
Patrick Lyster074c3ae22018-10-18 14:28:23 +000016#include "clang/AST/DeclOpenMP.h"
Eugene Zelenkod1b2d222017-11-29 23:27:36 +000017#include "clang/Basic/LLVM.h"
18#include "llvm/ADT/SmallPtrSet.h"
19#include "llvm/Support/Casting.h"
20#include "llvm/Support/ErrorHandling.h"
21#include <algorithm>
22#include <cassert>
James Y Knightb8bfd962015-10-02 13:41:04 +000023
24using namespace clang;
25
26OMPClause::child_range OMPClause::children() {
27 switch (getClauseKind()) {
28 default:
29 break;
30#define OPENMP_CLAUSE(Name, Class) \
31 case OMPC_##Name: \
32 return static_cast<Class *>(this)->children();
33#include "clang/Basic/OpenMPKinds.def"
34 }
35 llvm_unreachable("unknown OMPClause");
36}
37
Alexey Bataevc2c21ef2019-07-11 14:54:17 +000038OMPClause::child_range OMPClause::used_children() {
39 switch (getClauseKind()) {
40#define OPENMP_CLAUSE(Name, Class) \
41 case OMPC_##Name: \
42 return static_cast<Class *>(this)->used_children();
43#include "clang/Basic/OpenMPKinds.def"
44 case OMPC_threadprivate:
45 case OMPC_uniform:
Alexey Bataev729e2422019-08-23 16:11:14 +000046 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +000047 case OMPC_match:
Alexey Bataevc2c21ef2019-07-11 14:54:17 +000048 case OMPC_unknown:
49 break;
50 }
51 llvm_unreachable("unknown OMPClause");
52}
53
Alexey Bataev3392d762016-02-16 11:18:12 +000054OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
55 auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
56 return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr;
57}
58
59const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
60 switch (C->getClauseKind()) {
61 case OMPC_schedule:
62 return static_cast<const OMPScheduleClause *>(C);
63 case OMPC_dist_schedule:
64 return static_cast<const OMPDistScheduleClause *>(C);
Alexey Bataev417089f2016-02-17 13:19:37 +000065 case OMPC_firstprivate:
66 return static_cast<const OMPFirstprivateClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +000067 case OMPC_lastprivate:
68 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +000069 case OMPC_reduction:
70 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +000071 case OMPC_task_reduction:
72 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +000073 case OMPC_in_reduction:
74 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +000075 case OMPC_linear:
76 return static_cast<const OMPLinearClause *>(C);
Arpith Chacko Jacobfe4890a2017-01-18 20:40:48 +000077 case OMPC_if:
78 return static_cast<const OMPIfClause *>(C);
Arpith Chacko Jacob33c849a2017-01-25 00:57:16 +000079 case OMPC_num_threads:
80 return static_cast<const OMPNumThreadsClause *>(C);
Arpith Chacko Jacobbc126342017-01-25 11:28:18 +000081 case OMPC_num_teams:
82 return static_cast<const OMPNumTeamsClause *>(C);
Arpith Chacko Jacob7ecc0b72017-01-25 11:44:35 +000083 case OMPC_thread_limit:
84 return static_cast<const OMPThreadLimitClause *>(C);
Alexey Bataev931e19b2017-10-02 16:32:39 +000085 case OMPC_device:
86 return static_cast<const OMPDeviceClause *>(C);
Alexey Bataevb9c55e22019-10-14 19:29:52 +000087 case OMPC_grainsize:
88 return static_cast<const OMPGrainsizeClause *>(C);
Alexey Bataevd88c7de2019-10-14 20:44:34 +000089 case OMPC_num_tasks:
90 return static_cast<const OMPNumTasksClause *>(C);
Alexey Bataev3a842ec2019-10-15 19:37:05 +000091 case OMPC_final:
92 return static_cast<const OMPFinalClause *>(C);
Alexey Bataev31ba4762019-10-16 18:09:37 +000093 case OMPC_priority:
94 return static_cast<const OMPPriorityClause *>(C);
Alexey Bataev3392d762016-02-16 11:18:12 +000095 case OMPC_default:
96 case OMPC_proc_bind:
Alexey Bataev3392d762016-02-16 11:18:12 +000097 case OMPC_safelen:
98 case OMPC_simdlen:
Alexey Bataev9cc10fc2019-03-12 18:52:33 +000099 case OMPC_allocator:
Alexey Bataeve04483e2019-03-27 14:14:31 +0000100 case OMPC_allocate:
Alexey Bataev3392d762016-02-16 11:18:12 +0000101 case OMPC_collapse:
102 case OMPC_private:
Alexey Bataev005248a2016-02-25 05:25:57 +0000103 case OMPC_shared:
Alexey Bataev005248a2016-02-25 05:25:57 +0000104 case OMPC_aligned:
105 case OMPC_copyin:
106 case OMPC_copyprivate:
107 case OMPC_ordered:
108 case OMPC_nowait:
109 case OMPC_untied:
110 case OMPC_mergeable:
111 case OMPC_threadprivate:
112 case OMPC_flush:
113 case OMPC_read:
114 case OMPC_write:
115 case OMPC_update:
116 case OMPC_capture:
117 case OMPC_seq_cst:
118 case OMPC_depend:
Alexey Bataev005248a2016-02-25 05:25:57 +0000119 case OMPC_threads:
120 case OMPC_simd:
121 case OMPC_map:
Alexey Bataev005248a2016-02-25 05:25:57 +0000122 case OMPC_nogroup:
Alexey Bataev005248a2016-02-25 05:25:57 +0000123 case OMPC_hint:
124 case OMPC_defaultmap:
125 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000126 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000127 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000128 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000129 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000130 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000131 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000132 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000133 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000134 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000135 case OMPC_atomic_default_mem_order:
Alexey Bataev729e2422019-08-23 16:11:14 +0000136 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +0000137 case OMPC_match:
Alexey Bataevb6e70842019-12-16 15:54:17 -0500138 case OMPC_nontemporal:
Alexey Bataev005248a2016-02-25 05:25:57 +0000139 break;
140 }
141
142 return nullptr;
143}
144
145OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
146 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
147 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
148}
149
150const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
151 switch (C->getClauseKind()) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000152 case OMPC_lastprivate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000153 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000154 case OMPC_reduction:
155 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +0000156 case OMPC_task_reduction:
157 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000158 case OMPC_in_reduction:
159 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000160 case OMPC_linear:
161 return static_cast<const OMPLinearClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000162 case OMPC_schedule:
163 case OMPC_dist_schedule:
164 case OMPC_firstprivate:
165 case OMPC_default:
166 case OMPC_proc_bind:
167 case OMPC_if:
168 case OMPC_final:
169 case OMPC_num_threads:
170 case OMPC_safelen:
171 case OMPC_simdlen:
Alexey Bataev9cc10fc2019-03-12 18:52:33 +0000172 case OMPC_allocator:
Alexey Bataeve04483e2019-03-27 14:14:31 +0000173 case OMPC_allocate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000174 case OMPC_collapse:
175 case OMPC_private:
Alexey Bataev3392d762016-02-16 11:18:12 +0000176 case OMPC_shared:
Alexey Bataev3392d762016-02-16 11:18:12 +0000177 case OMPC_aligned:
178 case OMPC_copyin:
179 case OMPC_copyprivate:
180 case OMPC_ordered:
181 case OMPC_nowait:
182 case OMPC_untied:
183 case OMPC_mergeable:
184 case OMPC_threadprivate:
185 case OMPC_flush:
186 case OMPC_read:
187 case OMPC_write:
188 case OMPC_update:
189 case OMPC_capture:
190 case OMPC_seq_cst:
191 case OMPC_depend:
192 case OMPC_device:
193 case OMPC_threads:
194 case OMPC_simd:
195 case OMPC_map:
196 case OMPC_num_teams:
197 case OMPC_thread_limit:
198 case OMPC_priority:
199 case OMPC_grainsize:
200 case OMPC_nogroup:
201 case OMPC_num_tasks:
202 case OMPC_hint:
203 case OMPC_defaultmap:
204 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000205 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000206 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000207 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000208 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000209 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000210 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000211 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000212 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000213 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000214 case OMPC_atomic_default_mem_order:
Alexey Bataev729e2422019-08-23 16:11:14 +0000215 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +0000216 case OMPC_match:
Alexey Bataevb6e70842019-12-16 15:54:17 -0500217 case OMPC_nontemporal:
Alexey Bataev3392d762016-02-16 11:18:12 +0000218 break;
219 }
220
221 return nullptr;
222}
223
Alexey Bataev655cb4a2019-07-16 14:51:46 +0000224/// Gets the address of the original, non-captured, expression used in the
225/// clause as the preinitializer.
226static Stmt **getAddrOfExprAsWritten(Stmt *S) {
227 if (!S)
228 return nullptr;
229 if (auto *DS = dyn_cast<DeclStmt>(S)) {
230 assert(DS->isSingleDecl() && "Only single expression must be captured.");
231 if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
232 return OED->getInitAddress();
233 }
234 return nullptr;
235}
236
237OMPClause::child_range OMPIfClause::used_children() {
238 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
239 return child_range(C, C + 1);
240 return child_range(&Condition, &Condition + 1);
241}
242
Alexey Bataevb9c55e22019-10-14 19:29:52 +0000243OMPClause::child_range OMPGrainsizeClause::used_children() {
244 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
245 return child_range(C, C + 1);
246 return child_range(&Grainsize, &Grainsize + 1);
247}
248
Alexey Bataevd88c7de2019-10-14 20:44:34 +0000249OMPClause::child_range OMPNumTasksClause::used_children() {
250 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
251 return child_range(C, C + 1);
252 return child_range(&NumTasks, &NumTasks + 1);
253}
254
Alexey Bataev3a842ec2019-10-15 19:37:05 +0000255OMPClause::child_range OMPFinalClause::used_children() {
256 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
257 return child_range(C, C + 1);
258 return child_range(&Condition, &Condition + 1);
259}
260
Alexey Bataev31ba4762019-10-16 18:09:37 +0000261OMPClause::child_range OMPPriorityClause::used_children() {
262 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
263 return child_range(C, C + 1);
264 return child_range(&Priority, &Priority + 1);
265}
266
Alexey Bataevf138fda2018-08-13 19:04:24 +0000267OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
268 unsigned NumLoops,
269 SourceLocation StartLoc,
270 SourceLocation LParenLoc,
271 SourceLocation EndLoc) {
272 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
273 auto *Clause =
274 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
275 for (unsigned I = 0; I < NumLoops; ++I) {
276 Clause->setLoopNumIterations(I, nullptr);
277 Clause->setLoopCounter(I, nullptr);
278 }
279 return Clause;
280}
281
282OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
283 unsigned NumLoops) {
284 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
285 auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
286 for (unsigned I = 0; I < NumLoops; ++I) {
287 Clause->setLoopNumIterations(I, nullptr);
288 Clause->setLoopCounter(I, nullptr);
289 }
290 return Clause;
291}
292
293void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
294 Expr *NumIterations) {
295 assert(NumLoop < NumberOfLoops && "out of loops number.");
296 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
297}
298
299ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
300 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
301}
302
303void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
304 assert(NumLoop < NumberOfLoops && "out of loops number.");
305 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
306}
307
Mike Rice0ed46662018-09-20 17:19:41 +0000308Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000309 assert(NumLoop < NumberOfLoops && "out of loops number.");
310 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
311}
312
Mike Rice0ed46662018-09-20 17:19:41 +0000313const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000314 assert(NumLoop < NumberOfLoops && "out of loops number.");
315 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
316}
317
James Y Knightb8bfd962015-10-02 13:41:04 +0000318void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
319 assert(VL.size() == varlist_size() &&
320 "Number of private copies is not the same as the preallocated buffer");
321 std::copy(VL.begin(), VL.end(), varlist_end());
322}
323
324OMPPrivateClause *
325OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
326 SourceLocation LParenLoc, SourceLocation EndLoc,
327 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
328 // Allocate space for private variables and initializer expressions.
James Y Knight374fd202016-01-01 00:38:24 +0000329 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000330 OMPPrivateClause *Clause =
331 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
332 Clause->setVarRefs(VL);
333 Clause->setPrivateCopies(PrivateVL);
334 return Clause;
335}
336
337OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
338 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000339 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000340 return new (Mem) OMPPrivateClause(N);
341}
342
343void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
344 assert(VL.size() == varlist_size() &&
345 "Number of private copies is not the same as the preallocated buffer");
346 std::copy(VL.begin(), VL.end(), varlist_end());
347}
348
349void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
350 assert(VL.size() == varlist_size() &&
351 "Number of inits is not the same as the preallocated buffer");
352 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
353}
354
355OMPFirstprivateClause *
356OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
357 SourceLocation LParenLoc, SourceLocation EndLoc,
358 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
Alexey Bataev417089f2016-02-17 13:19:37 +0000359 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
James Y Knight374fd202016-01-01 00:38:24 +0000360 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000361 OMPFirstprivateClause *Clause =
362 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
363 Clause->setVarRefs(VL);
364 Clause->setPrivateCopies(PrivateVL);
365 Clause->setInits(InitVL);
Alexey Bataev417089f2016-02-17 13:19:37 +0000366 Clause->setPreInitStmt(PreInit);
James Y Knightb8bfd962015-10-02 13:41:04 +0000367 return Clause;
368}
369
370OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
371 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000372 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000373 return new (Mem) OMPFirstprivateClause(N);
374}
375
376void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
377 assert(PrivateCopies.size() == varlist_size() &&
378 "Number of private copies is not the same as the preallocated buffer");
379 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
380}
381
382void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
383 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
384 "not the same as the "
385 "preallocated buffer");
386 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
387}
388
389void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
390 assert(DstExprs.size() == varlist_size() && "Number of destination "
391 "expressions is not the same as "
392 "the preallocated buffer");
393 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
394}
395
396void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
397 assert(AssignmentOps.size() == varlist_size() &&
398 "Number of assignment expressions is not the same as the preallocated "
399 "buffer");
400 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
401 getDestinationExprs().end());
402}
403
404OMPLastprivateClause *OMPLastprivateClause::Create(
405 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
406 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
Alexey Bataev005248a2016-02-25 05:25:57 +0000407 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit,
408 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000409 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000410 OMPLastprivateClause *Clause =
411 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
412 Clause->setVarRefs(VL);
413 Clause->setSourceExprs(SrcExprs);
414 Clause->setDestinationExprs(DstExprs);
415 Clause->setAssignmentOps(AssignmentOps);
Alexey Bataev005248a2016-02-25 05:25:57 +0000416 Clause->setPreInitStmt(PreInit);
417 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000418 return Clause;
419}
420
421OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
422 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000423 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000424 return new (Mem) OMPLastprivateClause(N);
425}
426
427OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
428 SourceLocation StartLoc,
429 SourceLocation LParenLoc,
430 SourceLocation EndLoc,
431 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000432 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000433 OMPSharedClause *Clause =
434 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
435 Clause->setVarRefs(VL);
436 return Clause;
437}
438
439OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000440 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000441 return new (Mem) OMPSharedClause(N);
442}
443
444void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
445 assert(PL.size() == varlist_size() &&
446 "Number of privates is not the same as the preallocated buffer");
447 std::copy(PL.begin(), PL.end(), varlist_end());
448}
449
450void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
451 assert(IL.size() == varlist_size() &&
452 "Number of inits is not the same as the preallocated buffer");
453 std::copy(IL.begin(), IL.end(), getPrivates().end());
454}
455
456void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
457 assert(UL.size() == varlist_size() &&
458 "Number of updates is not the same as the preallocated buffer");
459 std::copy(UL.begin(), UL.end(), getInits().end());
460}
461
462void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
463 assert(FL.size() == varlist_size() &&
464 "Number of final updates is not the same as the preallocated buffer");
465 std::copy(FL.begin(), FL.end(), getUpdates().end());
466}
467
Alexey Bataev195ae902019-08-08 13:42:45 +0000468void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) {
469 assert(
470 UE.size() == varlist_size() + 1 &&
471 "Number of used expressions is not the same as the preallocated buffer");
472 std::copy(UE.begin(), UE.end(), getFinals().end() + 2);
473}
474
James Y Knightb8bfd962015-10-02 13:41:04 +0000475OMPLinearClause *OMPLinearClause::Create(
476 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
477 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
478 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
Alexey Bataev78849fb2016-03-09 09:49:00 +0000479 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
480 Stmt *PreInit, Expr *PostUpdate) {
Alexey Bataev195ae902019-08-08 13:42:45 +0000481 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
482 // (Step and CalcStep), list of used expression + step.
483 void *Mem =
484 C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000485 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
486 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
487 Clause->setVarRefs(VL);
488 Clause->setPrivates(PL);
489 Clause->setInits(IL);
490 // Fill update and final expressions with zeroes, they are provided later,
491 // after the directive construction.
492 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
493 nullptr);
494 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
495 nullptr);
Alexey Bataev195ae902019-08-08 13:42:45 +0000496 std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(),
497 nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000498 Clause->setStep(Step);
499 Clause->setCalcStep(CalcStep);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000500 Clause->setPreInitStmt(PreInit);
501 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000502 return Clause;
503}
504
505OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
506 unsigned NumVars) {
Alexey Bataev195ae902019-08-08 13:42:45 +0000507 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
508 // (Step and CalcStep), list of used expression + step.
509 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars +1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000510 return new (Mem) OMPLinearClause(NumVars);
511}
512
Alexey Bataev195ae902019-08-08 13:42:45 +0000513OMPClause::child_range OMPLinearClause::used_children() {
514 // Range includes only non-nullptr elements.
515 return child_range(
516 reinterpret_cast<Stmt **>(getUsedExprs().begin()),
517 reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr)));
518}
519
James Y Knightb8bfd962015-10-02 13:41:04 +0000520OMPAlignedClause *
521OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
522 SourceLocation LParenLoc, SourceLocation ColonLoc,
523 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
James Y Knight374fd202016-01-01 00:38:24 +0000524 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000525 OMPAlignedClause *Clause = new (Mem)
526 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
527 Clause->setVarRefs(VL);
528 Clause->setAlignment(A);
529 return Clause;
530}
531
532OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
533 unsigned NumVars) {
James Y Knight374fd202016-01-01 00:38:24 +0000534 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000535 return new (Mem) OMPAlignedClause(NumVars);
536}
537
538void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
539 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
540 "not the same as the "
541 "preallocated buffer");
542 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
543}
544
545void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
546 assert(DstExprs.size() == varlist_size() && "Number of destination "
547 "expressions is not the same as "
548 "the preallocated buffer");
549 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
550}
551
552void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
553 assert(AssignmentOps.size() == varlist_size() &&
554 "Number of assignment expressions is not the same as the preallocated "
555 "buffer");
556 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
557 getDestinationExprs().end());
558}
559
560OMPCopyinClause *OMPCopyinClause::Create(
561 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
562 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
563 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000564 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000565 OMPCopyinClause *Clause =
566 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
567 Clause->setVarRefs(VL);
568 Clause->setSourceExprs(SrcExprs);
569 Clause->setDestinationExprs(DstExprs);
570 Clause->setAssignmentOps(AssignmentOps);
571 return Clause;
572}
573
574OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000575 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000576 return new (Mem) OMPCopyinClause(N);
577}
578
579void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
580 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
581 "not the same as the "
582 "preallocated buffer");
583 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
584}
585
586void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
587 assert(DstExprs.size() == varlist_size() && "Number of destination "
588 "expressions is not the same as "
589 "the preallocated buffer");
590 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
591}
592
593void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
594 assert(AssignmentOps.size() == varlist_size() &&
595 "Number of assignment expressions is not the same as the preallocated "
596 "buffer");
597 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
598 getDestinationExprs().end());
599}
600
601OMPCopyprivateClause *OMPCopyprivateClause::Create(
602 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
603 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
604 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000605 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000606 OMPCopyprivateClause *Clause =
607 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
608 Clause->setVarRefs(VL);
609 Clause->setSourceExprs(SrcExprs);
610 Clause->setDestinationExprs(DstExprs);
611 Clause->setAssignmentOps(AssignmentOps);
612 return Clause;
613}
614
615OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
616 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000617 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000618 return new (Mem) OMPCopyprivateClause(N);
619}
620
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000621void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
622 assert(Privates.size() == varlist_size() &&
623 "Number of private copies is not the same as the preallocated buffer");
624 std::copy(Privates.begin(), Privates.end(), varlist_end());
625}
626
James Y Knightb8bfd962015-10-02 13:41:04 +0000627void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
628 assert(
629 LHSExprs.size() == varlist_size() &&
630 "Number of LHS expressions is not the same as the preallocated buffer");
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000631 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
James Y Knightb8bfd962015-10-02 13:41:04 +0000632}
633
634void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
635 assert(
636 RHSExprs.size() == varlist_size() &&
637 "Number of RHS expressions is not the same as the preallocated buffer");
638 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
639}
640
641void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
642 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
643 "expressions is not the same "
644 "as the preallocated buffer");
645 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
646}
647
648OMPReductionClause *OMPReductionClause::Create(
649 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
650 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
651 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000652 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev61205072016-03-02 04:57:40 +0000653 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
654 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000655 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000656 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
657 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
658 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000659 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000660 Clause->setLHSExprs(LHSExprs);
661 Clause->setRHSExprs(RHSExprs);
662 Clause->setReductionOps(ReductionOps);
Alexey Bataev61205072016-03-02 04:57:40 +0000663 Clause->setPreInitStmt(PreInit);
664 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000665 return Clause;
666}
667
668OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
669 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000670 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000671 return new (Mem) OMPReductionClause(N);
672}
673
Alexey Bataev169d96a2017-07-18 20:17:46 +0000674void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
675 assert(Privates.size() == varlist_size() &&
676 "Number of private copies is not the same as the preallocated buffer");
677 std::copy(Privates.begin(), Privates.end(), varlist_end());
678}
679
680void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
681 assert(
682 LHSExprs.size() == varlist_size() &&
683 "Number of LHS expressions is not the same as the preallocated buffer");
684 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
685}
686
687void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
688 assert(
689 RHSExprs.size() == varlist_size() &&
690 "Number of RHS expressions is not the same as the preallocated buffer");
691 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
692}
693
694void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
695 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
696 "expressions is not the same "
697 "as the preallocated buffer");
698 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
699}
700
701OMPTaskReductionClause *OMPTaskReductionClause::Create(
702 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
703 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
704 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
705 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
706 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
707 Expr *PostUpdate) {
708 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
709 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
710 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
711 Clause->setVarRefs(VL);
712 Clause->setPrivates(Privates);
713 Clause->setLHSExprs(LHSExprs);
714 Clause->setRHSExprs(RHSExprs);
715 Clause->setReductionOps(ReductionOps);
716 Clause->setPreInitStmt(PreInit);
717 Clause->setPostUpdateExpr(PostUpdate);
718 return Clause;
719}
720
721OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
722 unsigned N) {
723 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
724 return new (Mem) OMPTaskReductionClause(N);
725}
726
Alexey Bataevfa312f32017-07-21 18:48:21 +0000727void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
728 assert(Privates.size() == varlist_size() &&
729 "Number of private copies is not the same as the preallocated buffer");
730 std::copy(Privates.begin(), Privates.end(), varlist_end());
731}
732
733void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
734 assert(
735 LHSExprs.size() == varlist_size() &&
736 "Number of LHS expressions is not the same as the preallocated buffer");
737 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
738}
739
740void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
741 assert(
742 RHSExprs.size() == varlist_size() &&
743 "Number of RHS expressions is not the same as the preallocated buffer");
744 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
745}
746
747void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
748 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
749 "expressions is not the same "
750 "as the preallocated buffer");
751 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
752}
753
Alexey Bataev88202be2017-07-27 13:20:36 +0000754void OMPInReductionClause::setTaskgroupDescriptors(
755 ArrayRef<Expr *> TaskgroupDescriptors) {
756 assert(TaskgroupDescriptors.size() == varlist_size() &&
757 "Number of in reduction descriptors is not the same as the "
758 "preallocated buffer");
759 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
760 getReductionOps().end());
761}
762
Alexey Bataevfa312f32017-07-21 18:48:21 +0000763OMPInReductionClause *OMPInReductionClause::Create(
764 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
765 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
766 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
767 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev88202be2017-07-27 13:20:36 +0000768 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
769 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
770 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000771 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
772 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
773 Clause->setVarRefs(VL);
774 Clause->setPrivates(Privates);
775 Clause->setLHSExprs(LHSExprs);
776 Clause->setRHSExprs(RHSExprs);
777 Clause->setReductionOps(ReductionOps);
Alexey Bataev88202be2017-07-27 13:20:36 +0000778 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000779 Clause->setPreInitStmt(PreInit);
780 Clause->setPostUpdateExpr(PostUpdate);
781 return Clause;
782}
783
784OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
785 unsigned N) {
Alexey Bataev88202be2017-07-27 13:20:36 +0000786 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000787 return new (Mem) OMPInReductionClause(N);
788}
789
Alexey Bataeve04483e2019-03-27 14:14:31 +0000790OMPAllocateClause *
791OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc,
792 SourceLocation LParenLoc, Expr *Allocator,
793 SourceLocation ColonLoc, SourceLocation EndLoc,
794 ArrayRef<Expr *> VL) {
795 // Allocate space for private variables and initializer expressions.
796 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
797 auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
798 ColonLoc, EndLoc, VL.size());
799 Clause->setVarRefs(VL);
800 return Clause;
801}
802
803OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
804 unsigned N) {
805 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
806 return new (Mem) OMPAllocateClause(N);
807}
808
James Y Knightb8bfd962015-10-02 13:41:04 +0000809OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
810 SourceLocation StartLoc,
811 SourceLocation LParenLoc,
812 SourceLocation EndLoc,
813 ArrayRef<Expr *> VL) {
Alexey Bataev8b427062016-05-25 12:36:08 +0000814 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000815 OMPFlushClause *Clause =
816 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
817 Clause->setVarRefs(VL);
818 return Clause;
819}
820
821OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000822 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000823 return new (Mem) OMPFlushClause(N);
824}
825
Alexey Bataevf138fda2018-08-13 19:04:24 +0000826OMPDependClause *
827OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
828 SourceLocation LParenLoc, SourceLocation EndLoc,
829 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
830 SourceLocation ColonLoc, ArrayRef<Expr *> VL,
831 unsigned NumLoops) {
832 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
833 OMPDependClause *Clause = new (Mem)
834 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000835 Clause->setVarRefs(VL);
836 Clause->setDependencyKind(DepKind);
837 Clause->setDependencyLoc(DepLoc);
838 Clause->setColonLoc(ColonLoc);
Alexey Bataevf138fda2018-08-13 19:04:24 +0000839 for (unsigned I = 0 ; I < NumLoops; ++I)
840 Clause->setLoopData(I, nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000841 return Clause;
842}
843
Alexey Bataevf138fda2018-08-13 19:04:24 +0000844OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
845 unsigned NumLoops) {
846 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
847 return new (Mem) OMPDependClause(N, NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000848}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000849
Alexey Bataevf138fda2018-08-13 19:04:24 +0000850void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
851 assert((getDependencyKind() == OMPC_DEPEND_sink ||
852 getDependencyKind() == OMPC_DEPEND_source) &&
853 NumLoop < NumLoops &&
854 "Expected sink or source depend + loop index must be less number of "
855 "loops.");
856 auto It = std::next(getVarRefs().end(), NumLoop);
857 *It = Cnt;
Alexey Bataev8b427062016-05-25 12:36:08 +0000858}
859
Alexey Bataevf138fda2018-08-13 19:04:24 +0000860Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
861 assert((getDependencyKind() == OMPC_DEPEND_sink ||
862 getDependencyKind() == OMPC_DEPEND_source) &&
863 NumLoop < NumLoops &&
864 "Expected sink or source depend + loop index must be less number of "
865 "loops.");
866 auto It = std::next(getVarRefs().end(), NumLoop);
867 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000868}
869
Alexey Bataevf138fda2018-08-13 19:04:24 +0000870const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
871 assert((getDependencyKind() == OMPC_DEPEND_sink ||
872 getDependencyKind() == OMPC_DEPEND_source) &&
873 NumLoop < NumLoops &&
874 "Expected sink or source depend + loop index must be less number of "
875 "loops.");
876 auto It = std::next(getVarRefs().end(), NumLoop);
877 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000878}
879
Samuel Antao90927002016-04-26 14:54:23 +0000880unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
881 MappableExprComponentListsRef ComponentLists) {
882 unsigned TotalNum = 0u;
883 for (auto &C : ComponentLists)
884 TotalNum += C.size();
885 return TotalNum;
886}
887
888unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
Alexey Bataeve3727102018-04-18 15:57:46 +0000889 ArrayRef<const ValueDecl *> Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000890 unsigned TotalNum = 0u;
891 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
Alexey Bataeve3727102018-04-18 15:57:46 +0000892 for (const ValueDecl *D : Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000893 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
894 if (Cache.count(VD))
895 continue;
896 ++TotalNum;
897 Cache.insert(VD);
898 }
899 return TotalNum;
900}
901
Michael Kruse4304e9d2019-02-19 16:38:20 +0000902OMPMapClause *OMPMapClause::Create(
903 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
904 ArrayRef<ValueDecl *> Declarations,
905 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
906 ArrayRef<OpenMPMapModifierKind> MapModifiers,
907 ArrayRef<SourceLocation> MapModifiersLoc,
908 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
909 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
910 OMPMappableExprListSizeTy Sizes;
911 Sizes.NumVars = Vars.size();
912 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
913 Sizes.NumComponentLists = ComponentLists.size();
914 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao90927002016-04-26 14:54:23 +0000915
916 // We need to allocate:
Michael Kruse4304e9d2019-02-19 16:38:20 +0000917 // 2 x NumVars x Expr* - we have an original list expression and an associated
918 // user-defined mapper for each clause list entry.
Samuel Antao90927002016-04-26 14:54:23 +0000919 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
920 // with each component list.
921 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
922 // number of lists for each unique declaration and the size of each component
923 // list.
924 // NumComponents x MappableComponent - the total of all the components in all
925 // the lists.
926 void *Mem = C.Allocate(
927 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
928 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000929 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
930 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
931 Sizes.NumComponents));
932 OMPMapClause *Clause = new (Mem)
933 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
934 Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
Samuel Antao90927002016-04-26 14:54:23 +0000935
936 Clause->setVarRefs(Vars);
Michael Kruse4304e9d2019-02-19 16:38:20 +0000937 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao90927002016-04-26 14:54:23 +0000938 Clause->setClauseInfo(Declarations, ComponentLists);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000939 Clause->setMapType(Type);
940 Clause->setMapLoc(TypeLoc);
941 return Clause;
942}
943
Michael Kruse4304e9d2019-02-19 16:38:20 +0000944OMPMapClause *
945OMPMapClause::CreateEmpty(const ASTContext &C,
946 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao90927002016-04-26 14:54:23 +0000947 void *Mem = C.Allocate(
948 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
949 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000950 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
951 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
952 Sizes.NumComponents));
953 return new (Mem) OMPMapClause(Sizes);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000954}
Samuel Antao661c0902016-05-26 17:39:58 +0000955
Michael Kruse01f670d2019-02-22 22:29:42 +0000956OMPToClause *OMPToClause::Create(
957 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
958 ArrayRef<ValueDecl *> Declarations,
959 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
960 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000961 OMPMappableExprListSizeTy Sizes;
962 Sizes.NumVars = Vars.size();
963 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
964 Sizes.NumComponentLists = ComponentLists.size();
965 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao661c0902016-05-26 17:39:58 +0000966
967 // We need to allocate:
Michael Kruse01f670d2019-02-22 22:29:42 +0000968 // 2 x NumVars x Expr* - we have an original list expression and an associated
969 // user-defined mapper for each clause list entry.
Samuel Antao661c0902016-05-26 17:39:58 +0000970 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
971 // with each component list.
972 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
973 // number of lists for each unique declaration and the size of each component
974 // list.
975 // NumComponents x MappableComponent - the total of all the components in all
976 // the lists.
977 void *Mem = C.Allocate(
978 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
979 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +0000980 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000981 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
982 Sizes.NumComponents));
Samuel Antao661c0902016-05-26 17:39:58 +0000983
Michael Kruse01f670d2019-02-22 22:29:42 +0000984 auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +0000985
986 Clause->setVarRefs(Vars);
Michael Kruse01f670d2019-02-22 22:29:42 +0000987 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao661c0902016-05-26 17:39:58 +0000988 Clause->setClauseInfo(Declarations, ComponentLists);
989 return Clause;
990}
991
Michael Kruse4304e9d2019-02-19 16:38:20 +0000992OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
993 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao661c0902016-05-26 17:39:58 +0000994 void *Mem = C.Allocate(
995 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
996 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +0000997 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000998 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
999 Sizes.NumComponents));
1000 return new (Mem) OMPToClause(Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +00001001}
Samuel Antaoec172c62016-05-26 17:49:04 +00001002
Michael Kruse0336c752019-02-25 20:34:15 +00001003OMPFromClause *OMPFromClause::Create(
1004 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1005 ArrayRef<ValueDecl *> Declarations,
1006 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1007 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001008 OMPMappableExprListSizeTy Sizes;
1009 Sizes.NumVars = Vars.size();
1010 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1011 Sizes.NumComponentLists = ComponentLists.size();
1012 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaoec172c62016-05-26 17:49:04 +00001013
1014 // We need to allocate:
Michael Kruse0336c752019-02-25 20:34:15 +00001015 // 2 x NumVars x Expr* - we have an original list expression and an associated
1016 // user-defined mapper for each clause list entry.
Samuel Antaoec172c62016-05-26 17:49:04 +00001017 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1018 // with each component list.
1019 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1020 // number of lists for each unique declaration and the size of each component
1021 // list.
1022 // NumComponents x MappableComponent - the total of all the components in all
1023 // the lists.
1024 void *Mem = C.Allocate(
1025 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1026 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001027 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001028 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1029 Sizes.NumComponents));
Samuel Antaoec172c62016-05-26 17:49:04 +00001030
Michael Kruse0336c752019-02-25 20:34:15 +00001031 auto *Clause =
1032 new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001033
1034 Clause->setVarRefs(Vars);
Michael Kruse0336c752019-02-25 20:34:15 +00001035 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antaoec172c62016-05-26 17:49:04 +00001036 Clause->setClauseInfo(Declarations, ComponentLists);
1037 return Clause;
1038}
1039
Michael Kruse4304e9d2019-02-19 16:38:20 +00001040OMPFromClause *
1041OMPFromClause::CreateEmpty(const ASTContext &C,
1042 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaoec172c62016-05-26 17:49:04 +00001043 void *Mem = C.Allocate(
1044 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1045 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001046 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001047 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1048 Sizes.NumComponents));
1049 return new (Mem) OMPFromClause(Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001050}
Carlo Bertolli2404b172016-07-13 15:37:16 +00001051
Samuel Antaocc10b852016-07-28 14:23:26 +00001052void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1053 assert(VL.size() == varlist_size() &&
1054 "Number of private copies is not the same as the preallocated buffer");
1055 std::copy(VL.begin(), VL.end(), varlist_end());
1056}
1057
1058void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
1059 assert(VL.size() == varlist_size() &&
1060 "Number of inits is not the same as the preallocated buffer");
1061 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1062}
1063
1064OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001065 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1066 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
1067 ArrayRef<ValueDecl *> Declarations,
Samuel Antaocc10b852016-07-28 14:23:26 +00001068 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001069 OMPMappableExprListSizeTy Sizes;
1070 Sizes.NumVars = Vars.size();
1071 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1072 Sizes.NumComponentLists = ComponentLists.size();
1073 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaocc10b852016-07-28 14:23:26 +00001074
1075 // We need to allocate:
1076 // 3 x NumVars x Expr* - we have an original list expression for each clause
1077 // list entry and an equal number of private copies and inits.
1078 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1079 // with each component list.
1080 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1081 // number of lists for each unique declaration and the size of each component
1082 // list.
1083 // NumComponents x MappableComponent - the total of all the components in all
1084 // the lists.
1085 void *Mem = C.Allocate(
1086 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1087 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001088 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1089 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1090 Sizes.NumComponents));
Samuel Antaocc10b852016-07-28 14:23:26 +00001091
Michael Kruse4304e9d2019-02-19 16:38:20 +00001092 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
Samuel Antaocc10b852016-07-28 14:23:26 +00001093
1094 Clause->setVarRefs(Vars);
1095 Clause->setPrivateCopies(PrivateVars);
1096 Clause->setInits(Inits);
1097 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001098 return Clause;
1099}
1100
Michael Kruse4304e9d2019-02-19 16:38:20 +00001101OMPUseDevicePtrClause *
1102OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
1103 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaocc10b852016-07-28 14:23:26 +00001104 void *Mem = C.Allocate(
1105 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1106 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001107 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1108 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1109 Sizes.NumComponents));
1110 return new (Mem) OMPUseDevicePtrClause(Sizes);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001111}
Carlo Bertolli70594e92016-07-13 17:16:49 +00001112
Samuel Antao6890b092016-07-28 14:25:09 +00001113OMPIsDevicePtrClause *
Michael Kruse4304e9d2019-02-19 16:38:20 +00001114OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
Samuel Antao6890b092016-07-28 14:25:09 +00001115 ArrayRef<Expr *> Vars,
1116 ArrayRef<ValueDecl *> Declarations,
1117 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001118 OMPMappableExprListSizeTy Sizes;
1119 Sizes.NumVars = Vars.size();
1120 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1121 Sizes.NumComponentLists = ComponentLists.size();
1122 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao6890b092016-07-28 14:25:09 +00001123
1124 // We need to allocate:
1125 // NumVars x Expr* - we have an original list expression for each clause list
1126 // entry.
1127 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1128 // with each component list.
1129 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1130 // number of lists for each unique declaration and the size of each component
1131 // list.
1132 // NumComponents x MappableComponent - the total of all the components in all
1133 // the lists.
1134 void *Mem = C.Allocate(
1135 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1136 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001137 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1138 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1139 Sizes.NumComponents));
Samuel Antao6890b092016-07-28 14:25:09 +00001140
Michael Kruse4304e9d2019-02-19 16:38:20 +00001141 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
Samuel Antao6890b092016-07-28 14:25:09 +00001142
1143 Clause->setVarRefs(Vars);
1144 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001145 return Clause;
1146}
1147
Michael Kruse4304e9d2019-02-19 16:38:20 +00001148OMPIsDevicePtrClause *
1149OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1150 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao6890b092016-07-28 14:25:09 +00001151 void *Mem = C.Allocate(
1152 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1153 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001154 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1155 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1156 Sizes.NumComponents));
1157 return new (Mem) OMPIsDevicePtrClause(Sizes);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001158}
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001159
Alexey Bataevb6e70842019-12-16 15:54:17 -05001160OMPNontemporalClause *OMPNontemporalClause::Create(const ASTContext &C,
1161 SourceLocation StartLoc,
1162 SourceLocation LParenLoc,
1163 SourceLocation EndLoc,
1164 ArrayRef<Expr *> VL) {
1165 // Allocate space for nontemporal variables.
1166 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
1167 auto *Clause =
1168 new (Mem) OMPNontemporalClause(StartLoc, LParenLoc, EndLoc, VL.size());
1169 Clause->setVarRefs(VL);
1170 return Clause;
1171}
1172
1173OMPNontemporalClause *OMPNontemporalClause::CreateEmpty(const ASTContext &C,
1174 unsigned N) {
1175 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
1176 return new (Mem) OMPNontemporalClause(N);
1177}
1178
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001179//===----------------------------------------------------------------------===//
1180// OpenMP clauses printing methods
1181//===----------------------------------------------------------------------===//
1182
1183void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1184 OS << "if(";
Johannes Doerferteb3e81f2019-11-04 22:00:49 -06001185 if (Node->getNameModifier() != llvm::omp::OMPD_unknown)
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001186 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1187 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1188 OS << ")";
1189}
1190
1191void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1192 OS << "final(";
1193 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1194 OS << ")";
1195}
1196
1197void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1198 OS << "num_threads(";
1199 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1200 OS << ")";
1201}
1202
1203void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1204 OS << "safelen(";
1205 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1206 OS << ")";
1207}
1208
1209void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1210 OS << "simdlen(";
1211 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1212 OS << ")";
1213}
1214
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00001215void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
1216 OS << "allocator(";
1217 Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
1218 OS << ")";
1219}
1220
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001221void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1222 OS << "collapse(";
1223 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1224 OS << ")";
1225}
1226
1227void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1228 OS << "default("
1229 << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
1230 << ")";
1231}
1232
1233void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1234 OS << "proc_bind("
1235 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, Node->getProcBindKind())
1236 << ")";
1237}
1238
1239void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1240 OS << "unified_address";
1241}
1242
1243void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1244 OMPUnifiedSharedMemoryClause *) {
1245 OS << "unified_shared_memory";
1246}
1247
1248void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1249 OS << "reverse_offload";
1250}
1251
1252void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1253 OMPDynamicAllocatorsClause *) {
1254 OS << "dynamic_allocators";
1255}
1256
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00001257void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1258 OMPAtomicDefaultMemOrderClause *Node) {
1259 OS << "atomic_default_mem_order("
1260 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1261 Node->getAtomicDefaultMemOrderKind())
1262 << ")";
1263}
1264
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001265void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1266 OS << "schedule(";
1267 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1268 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1269 Node->getFirstScheduleModifier());
1270 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1271 OS << ", ";
1272 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1273 Node->getSecondScheduleModifier());
1274 }
1275 OS << ": ";
1276 }
1277 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1278 if (auto *E = Node->getChunkSize()) {
1279 OS << ", ";
1280 E->printPretty(OS, nullptr, Policy);
1281 }
1282 OS << ")";
1283}
1284
1285void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1286 OS << "ordered";
1287 if (auto *Num = Node->getNumForLoops()) {
1288 OS << "(";
1289 Num->printPretty(OS, nullptr, Policy, 0);
1290 OS << ")";
1291 }
1292}
1293
1294void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1295 OS << "nowait";
1296}
1297
1298void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1299 OS << "untied";
1300}
1301
1302void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1303 OS << "nogroup";
1304}
1305
1306void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1307 OS << "mergeable";
1308}
1309
1310void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1311
1312void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1313
1314void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
1315 OS << "update";
1316}
1317
1318void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1319 OS << "capture";
1320}
1321
1322void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1323 OS << "seq_cst";
1324}
1325
1326void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1327 OS << "threads";
1328}
1329
1330void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1331
1332void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1333 OS << "device(";
1334 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1335 OS << ")";
1336}
1337
1338void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1339 OS << "num_teams(";
1340 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1341 OS << ")";
1342}
1343
1344void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1345 OS << "thread_limit(";
1346 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1347 OS << ")";
1348}
1349
1350void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1351 OS << "priority(";
1352 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1353 OS << ")";
1354}
1355
1356void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1357 OS << "grainsize(";
1358 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1359 OS << ")";
1360}
1361
1362void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1363 OS << "num_tasks(";
1364 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1365 OS << ")";
1366}
1367
1368void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1369 OS << "hint(";
1370 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1371 OS << ")";
1372}
1373
1374template<typename T>
1375void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1376 for (typename T::varlist_iterator I = Node->varlist_begin(),
1377 E = Node->varlist_end();
1378 I != E; ++I) {
1379 assert(*I && "Expected non-null Stmt");
1380 OS << (I == Node->varlist_begin() ? StartSym : ',');
1381 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1382 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1383 DRE->printPretty(OS, nullptr, Policy, 0);
1384 else
1385 DRE->getDecl()->printQualifiedName(OS);
1386 } else
1387 (*I)->printPretty(OS, nullptr, Policy, 0);
1388 }
1389}
1390
Alexey Bataeve04483e2019-03-27 14:14:31 +00001391void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
1392 if (Node->varlist_empty())
1393 return;
1394 OS << "allocate";
1395 if (Expr *Allocator = Node->getAllocator()) {
1396 OS << "(";
1397 Allocator->printPretty(OS, nullptr, Policy, 0);
1398 OS << ":";
1399 VisitOMPClauseList(Node, ' ');
1400 } else {
1401 VisitOMPClauseList(Node, '(');
1402 }
1403 OS << ")";
1404}
1405
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001406void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1407 if (!Node->varlist_empty()) {
1408 OS << "private";
1409 VisitOMPClauseList(Node, '(');
1410 OS << ")";
1411 }
1412}
1413
1414void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1415 if (!Node->varlist_empty()) {
1416 OS << "firstprivate";
1417 VisitOMPClauseList(Node, '(');
1418 OS << ")";
1419 }
1420}
1421
1422void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1423 if (!Node->varlist_empty()) {
1424 OS << "lastprivate";
1425 VisitOMPClauseList(Node, '(');
1426 OS << ")";
1427 }
1428}
1429
1430void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1431 if (!Node->varlist_empty()) {
1432 OS << "shared";
1433 VisitOMPClauseList(Node, '(');
1434 OS << ")";
1435 }
1436}
1437
1438void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1439 if (!Node->varlist_empty()) {
1440 OS << "reduction(";
1441 NestedNameSpecifier *QualifierLoc =
1442 Node->getQualifierLoc().getNestedNameSpecifier();
1443 OverloadedOperatorKind OOK =
1444 Node->getNameInfo().getName().getCXXOverloadedOperator();
1445 if (QualifierLoc == nullptr && OOK != OO_None) {
1446 // Print reduction identifier in C format
1447 OS << getOperatorSpelling(OOK);
1448 } else {
1449 // Use C++ format
1450 if (QualifierLoc != nullptr)
1451 QualifierLoc->print(OS, Policy);
1452 OS << Node->getNameInfo();
1453 }
1454 OS << ":";
1455 VisitOMPClauseList(Node, ' ');
1456 OS << ")";
1457 }
1458}
1459
1460void OMPClausePrinter::VisitOMPTaskReductionClause(
1461 OMPTaskReductionClause *Node) {
1462 if (!Node->varlist_empty()) {
1463 OS << "task_reduction(";
1464 NestedNameSpecifier *QualifierLoc =
1465 Node->getQualifierLoc().getNestedNameSpecifier();
1466 OverloadedOperatorKind OOK =
1467 Node->getNameInfo().getName().getCXXOverloadedOperator();
1468 if (QualifierLoc == nullptr && OOK != OO_None) {
1469 // Print reduction identifier in C format
1470 OS << getOperatorSpelling(OOK);
1471 } else {
1472 // Use C++ format
1473 if (QualifierLoc != nullptr)
1474 QualifierLoc->print(OS, Policy);
1475 OS << Node->getNameInfo();
1476 }
1477 OS << ":";
1478 VisitOMPClauseList(Node, ' ');
1479 OS << ")";
1480 }
1481}
1482
1483void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1484 if (!Node->varlist_empty()) {
1485 OS << "in_reduction(";
1486 NestedNameSpecifier *QualifierLoc =
1487 Node->getQualifierLoc().getNestedNameSpecifier();
1488 OverloadedOperatorKind OOK =
1489 Node->getNameInfo().getName().getCXXOverloadedOperator();
1490 if (QualifierLoc == nullptr && OOK != OO_None) {
1491 // Print reduction identifier in C format
1492 OS << getOperatorSpelling(OOK);
1493 } else {
1494 // Use C++ format
1495 if (QualifierLoc != nullptr)
1496 QualifierLoc->print(OS, Policy);
1497 OS << Node->getNameInfo();
1498 }
1499 OS << ":";
1500 VisitOMPClauseList(Node, ' ');
1501 OS << ")";
1502 }
1503}
1504
1505void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1506 if (!Node->varlist_empty()) {
1507 OS << "linear";
1508 if (Node->getModifierLoc().isValid()) {
1509 OS << '('
1510 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1511 }
1512 VisitOMPClauseList(Node, '(');
1513 if (Node->getModifierLoc().isValid())
1514 OS << ')';
1515 if (Node->getStep() != nullptr) {
1516 OS << ": ";
1517 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1518 }
1519 OS << ")";
1520 }
1521}
1522
1523void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1524 if (!Node->varlist_empty()) {
1525 OS << "aligned";
1526 VisitOMPClauseList(Node, '(');
1527 if (Node->getAlignment() != nullptr) {
1528 OS << ": ";
1529 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1530 }
1531 OS << ")";
1532 }
1533}
1534
1535void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1536 if (!Node->varlist_empty()) {
1537 OS << "copyin";
1538 VisitOMPClauseList(Node, '(');
1539 OS << ")";
1540 }
1541}
1542
1543void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1544 if (!Node->varlist_empty()) {
1545 OS << "copyprivate";
1546 VisitOMPClauseList(Node, '(');
1547 OS << ")";
1548 }
1549}
1550
1551void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1552 if (!Node->varlist_empty()) {
1553 VisitOMPClauseList(Node, '(');
1554 OS << ")";
1555 }
1556}
1557
1558void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1559 OS << "depend(";
1560 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1561 Node->getDependencyKind());
1562 if (!Node->varlist_empty()) {
1563 OS << " :";
1564 VisitOMPClauseList(Node, ' ');
1565 }
1566 OS << ")";
1567}
1568
1569void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1570 if (!Node->varlist_empty()) {
1571 OS << "map(";
1572 if (Node->getMapType() != OMPC_MAP_unknown) {
Kelvin Lief579432018-12-18 22:18:41 +00001573 for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1574 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1575 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1576 Node->getMapTypeModifier(I));
Michael Kruse4304e9d2019-02-19 16:38:20 +00001577 if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1578 OS << '(';
1579 NestedNameSpecifier *MapperNNS =
1580 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1581 if (MapperNNS)
1582 MapperNNS->print(OS, Policy);
1583 OS << Node->getMapperIdInfo() << ')';
1584 }
Kelvin Lief579432018-12-18 22:18:41 +00001585 OS << ',';
1586 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001587 }
1588 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1589 OS << ':';
1590 }
1591 VisitOMPClauseList(Node, ' ');
1592 OS << ")";
1593 }
1594}
1595
1596void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1597 if (!Node->varlist_empty()) {
1598 OS << "to";
Michael Kruse01f670d2019-02-22 22:29:42 +00001599 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1600 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1601 OS << '(';
1602 OS << "mapper(";
1603 NestedNameSpecifier *MapperNNS =
1604 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1605 if (MapperNNS)
1606 MapperNNS->print(OS, Policy);
1607 OS << MapperId << "):";
1608 VisitOMPClauseList(Node, ' ');
1609 } else {
1610 VisitOMPClauseList(Node, '(');
1611 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001612 OS << ")";
1613 }
1614}
1615
1616void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1617 if (!Node->varlist_empty()) {
1618 OS << "from";
Michael Kruse0336c752019-02-25 20:34:15 +00001619 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1620 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1621 OS << '(';
1622 OS << "mapper(";
1623 NestedNameSpecifier *MapperNNS =
1624 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1625 if (MapperNNS)
1626 MapperNNS->print(OS, Policy);
1627 OS << MapperId << "):";
1628 VisitOMPClauseList(Node, ' ');
1629 } else {
1630 VisitOMPClauseList(Node, '(');
1631 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001632 OS << ")";
1633 }
1634}
1635
1636void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1637 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1638 OMPC_dist_schedule, Node->getDistScheduleKind());
1639 if (auto *E = Node->getChunkSize()) {
1640 OS << ", ";
1641 E->printPretty(OS, nullptr, Policy);
1642 }
1643 OS << ")";
1644}
1645
1646void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1647 OS << "defaultmap(";
1648 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1649 Node->getDefaultmapModifier());
1650 OS << ": ";
1651 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1652 Node->getDefaultmapKind());
1653 OS << ")";
1654}
1655
1656void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1657 if (!Node->varlist_empty()) {
1658 OS << "use_device_ptr";
1659 VisitOMPClauseList(Node, '(');
1660 OS << ")";
1661 }
1662}
1663
1664void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1665 if (!Node->varlist_empty()) {
1666 OS << "is_device_ptr";
1667 VisitOMPClauseList(Node, '(');
1668 OS << ")";
1669 }
1670}
1671
Alexey Bataevb6e70842019-12-16 15:54:17 -05001672void OMPClausePrinter::VisitOMPNontemporalClause(OMPNontemporalClause *Node) {
1673 if (!Node->varlist_empty()) {
1674 OS << "nontemporal";
1675 VisitOMPClauseList(Node, '(');
1676 OS << ")";
1677 }
1678}