blob: 5ef82648c89d1292e8133d9de52e6f2ef66a8708 [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:
119 case OMPC_depend:
Alexey Bataev005248a2016-02-25 05:25:57 +0000120 case OMPC_threads:
121 case OMPC_simd:
122 case OMPC_map:
Alexey Bataev005248a2016-02-25 05:25:57 +0000123 case OMPC_nogroup:
Alexey Bataev005248a2016-02-25 05:25:57 +0000124 case OMPC_hint:
125 case OMPC_defaultmap:
126 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000127 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000128 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000129 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000130 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000131 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000132 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000133 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000134 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000135 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000136 case OMPC_atomic_default_mem_order:
Alexey Bataev729e2422019-08-23 16:11:14 +0000137 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +0000138 case OMPC_match:
Alexey Bataevb6e70842019-12-16 15:54:17 -0500139 case OMPC_nontemporal:
Alexey Bataev005248a2016-02-25 05:25:57 +0000140 break;
141 }
142
143 return nullptr;
144}
145
146OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
147 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
148 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
149}
150
151const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
152 switch (C->getClauseKind()) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000153 case OMPC_lastprivate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000154 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000155 case OMPC_reduction:
156 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +0000157 case OMPC_task_reduction:
158 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000159 case OMPC_in_reduction:
160 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000161 case OMPC_linear:
162 return static_cast<const OMPLinearClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000163 case OMPC_schedule:
164 case OMPC_dist_schedule:
165 case OMPC_firstprivate:
166 case OMPC_default:
167 case OMPC_proc_bind:
168 case OMPC_if:
169 case OMPC_final:
170 case OMPC_num_threads:
171 case OMPC_safelen:
172 case OMPC_simdlen:
Alexey Bataev9cc10fc2019-03-12 18:52:33 +0000173 case OMPC_allocator:
Alexey Bataeve04483e2019-03-27 14:14:31 +0000174 case OMPC_allocate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000175 case OMPC_collapse:
176 case OMPC_private:
Alexey Bataev3392d762016-02-16 11:18:12 +0000177 case OMPC_shared:
Alexey Bataev3392d762016-02-16 11:18:12 +0000178 case OMPC_aligned:
179 case OMPC_copyin:
180 case OMPC_copyprivate:
181 case OMPC_ordered:
182 case OMPC_nowait:
183 case OMPC_untied:
184 case OMPC_mergeable:
185 case OMPC_threadprivate:
186 case OMPC_flush:
187 case OMPC_read:
188 case OMPC_write:
189 case OMPC_update:
190 case OMPC_capture:
191 case OMPC_seq_cst:
192 case OMPC_depend:
193 case OMPC_device:
194 case OMPC_threads:
195 case OMPC_simd:
196 case OMPC_map:
197 case OMPC_num_teams:
198 case OMPC_thread_limit:
199 case OMPC_priority:
200 case OMPC_grainsize:
201 case OMPC_nogroup:
202 case OMPC_num_tasks:
203 case OMPC_hint:
204 case OMPC_defaultmap:
205 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000206 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000207 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000208 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000209 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000210 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000211 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000212 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000213 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000214 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000215 case OMPC_atomic_default_mem_order:
Alexey Bataev729e2422019-08-23 16:11:14 +0000216 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +0000217 case OMPC_match:
Alexey Bataevb6e70842019-12-16 15:54:17 -0500218 case OMPC_nontemporal:
Alexey Bataev3392d762016-02-16 11:18:12 +0000219 break;
220 }
221
222 return nullptr;
223}
224
Alexey Bataev655cb4a2019-07-16 14:51:46 +0000225/// Gets the address of the original, non-captured, expression used in the
226/// clause as the preinitializer.
227static Stmt **getAddrOfExprAsWritten(Stmt *S) {
228 if (!S)
229 return nullptr;
230 if (auto *DS = dyn_cast<DeclStmt>(S)) {
231 assert(DS->isSingleDecl() && "Only single expression must be captured.");
232 if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
233 return OED->getInitAddress();
234 }
235 return nullptr;
236}
237
238OMPClause::child_range OMPIfClause::used_children() {
239 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
240 return child_range(C, C + 1);
241 return child_range(&Condition, &Condition + 1);
242}
243
Alexey Bataevb9c55e22019-10-14 19:29:52 +0000244OMPClause::child_range OMPGrainsizeClause::used_children() {
245 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
246 return child_range(C, C + 1);
247 return child_range(&Grainsize, &Grainsize + 1);
248}
249
Alexey Bataevd88c7de2019-10-14 20:44:34 +0000250OMPClause::child_range OMPNumTasksClause::used_children() {
251 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
252 return child_range(C, C + 1);
253 return child_range(&NumTasks, &NumTasks + 1);
254}
255
Alexey Bataev3a842ec2019-10-15 19:37:05 +0000256OMPClause::child_range OMPFinalClause::used_children() {
257 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
258 return child_range(C, C + 1);
259 return child_range(&Condition, &Condition + 1);
260}
261
Alexey Bataev31ba4762019-10-16 18:09:37 +0000262OMPClause::child_range OMPPriorityClause::used_children() {
263 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
264 return child_range(C, C + 1);
265 return child_range(&Priority, &Priority + 1);
266}
267
Alexey Bataevf138fda2018-08-13 19:04:24 +0000268OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
269 unsigned NumLoops,
270 SourceLocation StartLoc,
271 SourceLocation LParenLoc,
272 SourceLocation EndLoc) {
273 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
274 auto *Clause =
275 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
276 for (unsigned I = 0; I < NumLoops; ++I) {
277 Clause->setLoopNumIterations(I, nullptr);
278 Clause->setLoopCounter(I, nullptr);
279 }
280 return Clause;
281}
282
283OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
284 unsigned NumLoops) {
285 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
286 auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
287 for (unsigned I = 0; I < NumLoops; ++I) {
288 Clause->setLoopNumIterations(I, nullptr);
289 Clause->setLoopCounter(I, nullptr);
290 }
291 return Clause;
292}
293
294void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
295 Expr *NumIterations) {
296 assert(NumLoop < NumberOfLoops && "out of loops number.");
297 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
298}
299
300ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
301 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
302}
303
304void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
305 assert(NumLoop < NumberOfLoops && "out of loops number.");
306 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
307}
308
Mike Rice0ed46662018-09-20 17:19:41 +0000309Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000310 assert(NumLoop < NumberOfLoops && "out of loops number.");
311 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
312}
313
Mike Rice0ed46662018-09-20 17:19:41 +0000314const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000315 assert(NumLoop < NumberOfLoops && "out of loops number.");
316 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
317}
318
James Y Knightb8bfd962015-10-02 13:41:04 +0000319void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
320 assert(VL.size() == varlist_size() &&
321 "Number of private copies is not the same as the preallocated buffer");
322 std::copy(VL.begin(), VL.end(), varlist_end());
323}
324
325OMPPrivateClause *
326OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
327 SourceLocation LParenLoc, SourceLocation EndLoc,
328 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
329 // Allocate space for private variables and initializer expressions.
James Y Knight374fd202016-01-01 00:38:24 +0000330 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000331 OMPPrivateClause *Clause =
332 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
333 Clause->setVarRefs(VL);
334 Clause->setPrivateCopies(PrivateVL);
335 return Clause;
336}
337
338OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
339 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000340 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000341 return new (Mem) OMPPrivateClause(N);
342}
343
344void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
345 assert(VL.size() == varlist_size() &&
346 "Number of private copies is not the same as the preallocated buffer");
347 std::copy(VL.begin(), VL.end(), varlist_end());
348}
349
350void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
351 assert(VL.size() == varlist_size() &&
352 "Number of inits is not the same as the preallocated buffer");
353 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
354}
355
356OMPFirstprivateClause *
357OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
358 SourceLocation LParenLoc, SourceLocation EndLoc,
359 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
Alexey Bataev417089f2016-02-17 13:19:37 +0000360 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
James Y Knight374fd202016-01-01 00:38:24 +0000361 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000362 OMPFirstprivateClause *Clause =
363 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
364 Clause->setVarRefs(VL);
365 Clause->setPrivateCopies(PrivateVL);
366 Clause->setInits(InitVL);
Alexey Bataev417089f2016-02-17 13:19:37 +0000367 Clause->setPreInitStmt(PreInit);
James Y Knightb8bfd962015-10-02 13:41:04 +0000368 return Clause;
369}
370
371OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
372 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000373 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000374 return new (Mem) OMPFirstprivateClause(N);
375}
376
377void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
378 assert(PrivateCopies.size() == varlist_size() &&
379 "Number of private copies is not the same as the preallocated buffer");
380 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
381}
382
383void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
384 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
385 "not the same as the "
386 "preallocated buffer");
387 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
388}
389
390void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
391 assert(DstExprs.size() == varlist_size() && "Number of destination "
392 "expressions is not the same as "
393 "the preallocated buffer");
394 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
395}
396
397void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
398 assert(AssignmentOps.size() == varlist_size() &&
399 "Number of assignment expressions is not the same as the preallocated "
400 "buffer");
401 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
402 getDestinationExprs().end());
403}
404
405OMPLastprivateClause *OMPLastprivateClause::Create(
406 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
407 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
Alexey Bataev93dc40d2019-12-20 11:04:57 -0500408 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
409 OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
410 SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000411 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
Alexey Bataev93dc40d2019-12-20 11:04:57 -0500412 OMPLastprivateClause *Clause = new (Mem) OMPLastprivateClause(
413 StartLoc, LParenLoc, EndLoc, LPKind, LPKindLoc, ColonLoc, VL.size());
James Y Knightb8bfd962015-10-02 13:41:04 +0000414 Clause->setVarRefs(VL);
415 Clause->setSourceExprs(SrcExprs);
416 Clause->setDestinationExprs(DstExprs);
417 Clause->setAssignmentOps(AssignmentOps);
Alexey Bataev005248a2016-02-25 05:25:57 +0000418 Clause->setPreInitStmt(PreInit);
419 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000420 return Clause;
421}
422
423OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
424 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000425 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000426 return new (Mem) OMPLastprivateClause(N);
427}
428
429OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
430 SourceLocation StartLoc,
431 SourceLocation LParenLoc,
432 SourceLocation EndLoc,
433 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000434 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000435 OMPSharedClause *Clause =
436 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
437 Clause->setVarRefs(VL);
438 return Clause;
439}
440
441OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000442 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000443 return new (Mem) OMPSharedClause(N);
444}
445
446void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
447 assert(PL.size() == varlist_size() &&
448 "Number of privates is not the same as the preallocated buffer");
449 std::copy(PL.begin(), PL.end(), varlist_end());
450}
451
452void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
453 assert(IL.size() == varlist_size() &&
454 "Number of inits is not the same as the preallocated buffer");
455 std::copy(IL.begin(), IL.end(), getPrivates().end());
456}
457
458void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
459 assert(UL.size() == varlist_size() &&
460 "Number of updates is not the same as the preallocated buffer");
461 std::copy(UL.begin(), UL.end(), getInits().end());
462}
463
464void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
465 assert(FL.size() == varlist_size() &&
466 "Number of final updates is not the same as the preallocated buffer");
467 std::copy(FL.begin(), FL.end(), getUpdates().end());
468}
469
Alexey Bataev195ae902019-08-08 13:42:45 +0000470void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) {
471 assert(
472 UE.size() == varlist_size() + 1 &&
473 "Number of used expressions is not the same as the preallocated buffer");
474 std::copy(UE.begin(), UE.end(), getFinals().end() + 2);
475}
476
James Y Knightb8bfd962015-10-02 13:41:04 +0000477OMPLinearClause *OMPLinearClause::Create(
478 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
479 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
480 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
Alexey Bataev78849fb2016-03-09 09:49:00 +0000481 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
482 Stmt *PreInit, Expr *PostUpdate) {
Alexey Bataev195ae902019-08-08 13:42:45 +0000483 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
484 // (Step and CalcStep), list of used expression + step.
485 void *Mem =
486 C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000487 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
488 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
489 Clause->setVarRefs(VL);
490 Clause->setPrivates(PL);
491 Clause->setInits(IL);
492 // Fill update and final expressions with zeroes, they are provided later,
493 // after the directive construction.
494 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
495 nullptr);
496 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
497 nullptr);
Alexey Bataev195ae902019-08-08 13:42:45 +0000498 std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(),
499 nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000500 Clause->setStep(Step);
501 Clause->setCalcStep(CalcStep);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000502 Clause->setPreInitStmt(PreInit);
503 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000504 return Clause;
505}
506
507OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
508 unsigned NumVars) {
Alexey Bataev195ae902019-08-08 13:42:45 +0000509 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
510 // (Step and CalcStep), list of used expression + step.
511 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars +1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000512 return new (Mem) OMPLinearClause(NumVars);
513}
514
Alexey Bataev195ae902019-08-08 13:42:45 +0000515OMPClause::child_range OMPLinearClause::used_children() {
516 // Range includes only non-nullptr elements.
517 return child_range(
518 reinterpret_cast<Stmt **>(getUsedExprs().begin()),
519 reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr)));
520}
521
James Y Knightb8bfd962015-10-02 13:41:04 +0000522OMPAlignedClause *
523OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
524 SourceLocation LParenLoc, SourceLocation ColonLoc,
525 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
James Y Knight374fd202016-01-01 00:38:24 +0000526 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000527 OMPAlignedClause *Clause = new (Mem)
528 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
529 Clause->setVarRefs(VL);
530 Clause->setAlignment(A);
531 return Clause;
532}
533
534OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
535 unsigned NumVars) {
James Y Knight374fd202016-01-01 00:38:24 +0000536 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000537 return new (Mem) OMPAlignedClause(NumVars);
538}
539
540void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
541 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
542 "not the same as the "
543 "preallocated buffer");
544 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
545}
546
547void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
548 assert(DstExprs.size() == varlist_size() && "Number of destination "
549 "expressions is not the same as "
550 "the preallocated buffer");
551 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
552}
553
554void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
555 assert(AssignmentOps.size() == varlist_size() &&
556 "Number of assignment expressions is not the same as the preallocated "
557 "buffer");
558 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
559 getDestinationExprs().end());
560}
561
562OMPCopyinClause *OMPCopyinClause::Create(
563 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
564 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
565 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000566 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000567 OMPCopyinClause *Clause =
568 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
569 Clause->setVarRefs(VL);
570 Clause->setSourceExprs(SrcExprs);
571 Clause->setDestinationExprs(DstExprs);
572 Clause->setAssignmentOps(AssignmentOps);
573 return Clause;
574}
575
576OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000577 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000578 return new (Mem) OMPCopyinClause(N);
579}
580
581void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
582 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
583 "not the same as the "
584 "preallocated buffer");
585 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
586}
587
588void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
589 assert(DstExprs.size() == varlist_size() && "Number of destination "
590 "expressions is not the same as "
591 "the preallocated buffer");
592 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
593}
594
595void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
596 assert(AssignmentOps.size() == varlist_size() &&
597 "Number of assignment expressions is not the same as the preallocated "
598 "buffer");
599 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
600 getDestinationExprs().end());
601}
602
603OMPCopyprivateClause *OMPCopyprivateClause::Create(
604 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
605 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
606 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000607 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000608 OMPCopyprivateClause *Clause =
609 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
610 Clause->setVarRefs(VL);
611 Clause->setSourceExprs(SrcExprs);
612 Clause->setDestinationExprs(DstExprs);
613 Clause->setAssignmentOps(AssignmentOps);
614 return Clause;
615}
616
617OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
618 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000619 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000620 return new (Mem) OMPCopyprivateClause(N);
621}
622
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000623void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
624 assert(Privates.size() == varlist_size() &&
625 "Number of private copies is not the same as the preallocated buffer");
626 std::copy(Privates.begin(), Privates.end(), varlist_end());
627}
628
James Y Knightb8bfd962015-10-02 13:41:04 +0000629void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
630 assert(
631 LHSExprs.size() == varlist_size() &&
632 "Number of LHS expressions is not the same as the preallocated buffer");
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000633 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
James Y Knightb8bfd962015-10-02 13:41:04 +0000634}
635
636void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
637 assert(
638 RHSExprs.size() == varlist_size() &&
639 "Number of RHS expressions is not the same as the preallocated buffer");
640 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
641}
642
643void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
644 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
645 "expressions is not the same "
646 "as the preallocated buffer");
647 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
648}
649
650OMPReductionClause *OMPReductionClause::Create(
651 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
652 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
653 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000654 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev61205072016-03-02 04:57:40 +0000655 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
656 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000657 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000658 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
659 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
660 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000661 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000662 Clause->setLHSExprs(LHSExprs);
663 Clause->setRHSExprs(RHSExprs);
664 Clause->setReductionOps(ReductionOps);
Alexey Bataev61205072016-03-02 04:57:40 +0000665 Clause->setPreInitStmt(PreInit);
666 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000667 return Clause;
668}
669
670OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
671 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000672 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000673 return new (Mem) OMPReductionClause(N);
674}
675
Alexey Bataev169d96a2017-07-18 20:17:46 +0000676void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
677 assert(Privates.size() == varlist_size() &&
678 "Number of private copies is not the same as the preallocated buffer");
679 std::copy(Privates.begin(), Privates.end(), varlist_end());
680}
681
682void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
683 assert(
684 LHSExprs.size() == varlist_size() &&
685 "Number of LHS expressions is not the same as the preallocated buffer");
686 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
687}
688
689void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
690 assert(
691 RHSExprs.size() == varlist_size() &&
692 "Number of RHS expressions is not the same as the preallocated buffer");
693 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
694}
695
696void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
697 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
698 "expressions is not the same "
699 "as the preallocated buffer");
700 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
701}
702
703OMPTaskReductionClause *OMPTaskReductionClause::Create(
704 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
705 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
706 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
707 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
708 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
709 Expr *PostUpdate) {
710 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
711 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
712 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
713 Clause->setVarRefs(VL);
714 Clause->setPrivates(Privates);
715 Clause->setLHSExprs(LHSExprs);
716 Clause->setRHSExprs(RHSExprs);
717 Clause->setReductionOps(ReductionOps);
718 Clause->setPreInitStmt(PreInit);
719 Clause->setPostUpdateExpr(PostUpdate);
720 return Clause;
721}
722
723OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
724 unsigned N) {
725 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
726 return new (Mem) OMPTaskReductionClause(N);
727}
728
Alexey Bataevfa312f32017-07-21 18:48:21 +0000729void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
730 assert(Privates.size() == varlist_size() &&
731 "Number of private copies is not the same as the preallocated buffer");
732 std::copy(Privates.begin(), Privates.end(), varlist_end());
733}
734
735void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
736 assert(
737 LHSExprs.size() == varlist_size() &&
738 "Number of LHS expressions is not the same as the preallocated buffer");
739 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
740}
741
742void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
743 assert(
744 RHSExprs.size() == varlist_size() &&
745 "Number of RHS expressions is not the same as the preallocated buffer");
746 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
747}
748
749void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
750 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
751 "expressions is not the same "
752 "as the preallocated buffer");
753 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
754}
755
Alexey Bataev88202be2017-07-27 13:20:36 +0000756void OMPInReductionClause::setTaskgroupDescriptors(
757 ArrayRef<Expr *> TaskgroupDescriptors) {
758 assert(TaskgroupDescriptors.size() == varlist_size() &&
759 "Number of in reduction descriptors is not the same as the "
760 "preallocated buffer");
761 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
762 getReductionOps().end());
763}
764
Alexey Bataevfa312f32017-07-21 18:48:21 +0000765OMPInReductionClause *OMPInReductionClause::Create(
766 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
767 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
768 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
769 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev88202be2017-07-27 13:20:36 +0000770 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
771 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
772 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000773 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
774 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
775 Clause->setVarRefs(VL);
776 Clause->setPrivates(Privates);
777 Clause->setLHSExprs(LHSExprs);
778 Clause->setRHSExprs(RHSExprs);
779 Clause->setReductionOps(ReductionOps);
Alexey Bataev88202be2017-07-27 13:20:36 +0000780 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000781 Clause->setPreInitStmt(PreInit);
782 Clause->setPostUpdateExpr(PostUpdate);
783 return Clause;
784}
785
786OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
787 unsigned N) {
Alexey Bataev88202be2017-07-27 13:20:36 +0000788 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000789 return new (Mem) OMPInReductionClause(N);
790}
791
Alexey Bataeve04483e2019-03-27 14:14:31 +0000792OMPAllocateClause *
793OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc,
794 SourceLocation LParenLoc, Expr *Allocator,
795 SourceLocation ColonLoc, SourceLocation EndLoc,
796 ArrayRef<Expr *> VL) {
797 // Allocate space for private variables and initializer expressions.
798 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
799 auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
800 ColonLoc, EndLoc, VL.size());
801 Clause->setVarRefs(VL);
802 return Clause;
803}
804
805OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
806 unsigned N) {
807 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
808 return new (Mem) OMPAllocateClause(N);
809}
810
James Y Knightb8bfd962015-10-02 13:41:04 +0000811OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
812 SourceLocation StartLoc,
813 SourceLocation LParenLoc,
814 SourceLocation EndLoc,
815 ArrayRef<Expr *> VL) {
Alexey Bataev8b427062016-05-25 12:36:08 +0000816 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000817 OMPFlushClause *Clause =
818 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
819 Clause->setVarRefs(VL);
820 return Clause;
821}
822
823OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000824 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000825 return new (Mem) OMPFlushClause(N);
826}
827
Alexey Bataevf138fda2018-08-13 19:04:24 +0000828OMPDependClause *
829OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
830 SourceLocation LParenLoc, SourceLocation EndLoc,
831 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
832 SourceLocation ColonLoc, ArrayRef<Expr *> VL,
833 unsigned NumLoops) {
834 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
835 OMPDependClause *Clause = new (Mem)
836 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000837 Clause->setVarRefs(VL);
838 Clause->setDependencyKind(DepKind);
839 Clause->setDependencyLoc(DepLoc);
840 Clause->setColonLoc(ColonLoc);
Alexey Bataevf138fda2018-08-13 19:04:24 +0000841 for (unsigned I = 0 ; I < NumLoops; ++I)
842 Clause->setLoopData(I, nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000843 return Clause;
844}
845
Alexey Bataevf138fda2018-08-13 19:04:24 +0000846OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
847 unsigned NumLoops) {
848 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
849 return new (Mem) OMPDependClause(N, NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000850}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000851
Alexey Bataevf138fda2018-08-13 19:04:24 +0000852void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
853 assert((getDependencyKind() == OMPC_DEPEND_sink ||
854 getDependencyKind() == OMPC_DEPEND_source) &&
855 NumLoop < NumLoops &&
856 "Expected sink or source depend + loop index must be less number of "
857 "loops.");
858 auto It = std::next(getVarRefs().end(), NumLoop);
859 *It = Cnt;
Alexey Bataev8b427062016-05-25 12:36:08 +0000860}
861
Alexey Bataevf138fda2018-08-13 19:04:24 +0000862Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
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 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000870}
871
Alexey Bataevf138fda2018-08-13 19:04:24 +0000872const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
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
Samuel Antao90927002016-04-26 14:54:23 +0000882unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
883 MappableExprComponentListsRef ComponentLists) {
884 unsigned TotalNum = 0u;
885 for (auto &C : ComponentLists)
886 TotalNum += C.size();
887 return TotalNum;
888}
889
890unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
Alexey Bataeve3727102018-04-18 15:57:46 +0000891 ArrayRef<const ValueDecl *> Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000892 unsigned TotalNum = 0u;
893 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
Alexey Bataeve3727102018-04-18 15:57:46 +0000894 for (const ValueDecl *D : Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000895 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
896 if (Cache.count(VD))
897 continue;
898 ++TotalNum;
899 Cache.insert(VD);
900 }
901 return TotalNum;
902}
903
Michael Kruse4304e9d2019-02-19 16:38:20 +0000904OMPMapClause *OMPMapClause::Create(
905 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
906 ArrayRef<ValueDecl *> Declarations,
907 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
908 ArrayRef<OpenMPMapModifierKind> MapModifiers,
909 ArrayRef<SourceLocation> MapModifiersLoc,
910 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
911 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
912 OMPMappableExprListSizeTy Sizes;
913 Sizes.NumVars = Vars.size();
914 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
915 Sizes.NumComponentLists = ComponentLists.size();
916 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao90927002016-04-26 14:54:23 +0000917
918 // We need to allocate:
Michael Kruse4304e9d2019-02-19 16:38:20 +0000919 // 2 x NumVars x Expr* - we have an original list expression and an associated
920 // user-defined mapper for each clause list entry.
Samuel Antao90927002016-04-26 14:54:23 +0000921 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
922 // with each component list.
923 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
924 // number of lists for each unique declaration and the size of each component
925 // list.
926 // NumComponents x MappableComponent - the total of all the components in all
927 // the lists.
928 void *Mem = C.Allocate(
929 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
930 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000931 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
932 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
933 Sizes.NumComponents));
934 OMPMapClause *Clause = new (Mem)
935 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
936 Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
Samuel Antao90927002016-04-26 14:54:23 +0000937
938 Clause->setVarRefs(Vars);
Michael Kruse4304e9d2019-02-19 16:38:20 +0000939 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao90927002016-04-26 14:54:23 +0000940 Clause->setClauseInfo(Declarations, ComponentLists);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000941 Clause->setMapType(Type);
942 Clause->setMapLoc(TypeLoc);
943 return Clause;
944}
945
Michael Kruse4304e9d2019-02-19 16:38:20 +0000946OMPMapClause *
947OMPMapClause::CreateEmpty(const ASTContext &C,
948 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao90927002016-04-26 14:54:23 +0000949 void *Mem = C.Allocate(
950 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
951 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000952 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
953 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
954 Sizes.NumComponents));
955 return new (Mem) OMPMapClause(Sizes);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000956}
Samuel Antao661c0902016-05-26 17:39:58 +0000957
Michael Kruse01f670d2019-02-22 22:29:42 +0000958OMPToClause *OMPToClause::Create(
959 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
960 ArrayRef<ValueDecl *> Declarations,
961 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
962 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000963 OMPMappableExprListSizeTy Sizes;
964 Sizes.NumVars = Vars.size();
965 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
966 Sizes.NumComponentLists = ComponentLists.size();
967 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao661c0902016-05-26 17:39:58 +0000968
969 // We need to allocate:
Michael Kruse01f670d2019-02-22 22:29:42 +0000970 // 2 x NumVars x Expr* - we have an original list expression and an associated
971 // user-defined mapper for each clause list entry.
Samuel Antao661c0902016-05-26 17:39:58 +0000972 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
973 // with each component list.
974 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
975 // number of lists for each unique declaration and the size of each component
976 // list.
977 // NumComponents x MappableComponent - the total of all the components in all
978 // the lists.
979 void *Mem = C.Allocate(
980 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
981 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +0000982 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000983 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
984 Sizes.NumComponents));
Samuel Antao661c0902016-05-26 17:39:58 +0000985
Michael Kruse01f670d2019-02-22 22:29:42 +0000986 auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +0000987
988 Clause->setVarRefs(Vars);
Michael Kruse01f670d2019-02-22 22:29:42 +0000989 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao661c0902016-05-26 17:39:58 +0000990 Clause->setClauseInfo(Declarations, ComponentLists);
991 return Clause;
992}
993
Michael Kruse4304e9d2019-02-19 16:38:20 +0000994OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
995 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao661c0902016-05-26 17:39:58 +0000996 void *Mem = C.Allocate(
997 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
998 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +0000999 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001000 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1001 Sizes.NumComponents));
1002 return new (Mem) OMPToClause(Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +00001003}
Samuel Antaoec172c62016-05-26 17:49:04 +00001004
Michael Kruse0336c752019-02-25 20:34:15 +00001005OMPFromClause *OMPFromClause::Create(
1006 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1007 ArrayRef<ValueDecl *> Declarations,
1008 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1009 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001010 OMPMappableExprListSizeTy Sizes;
1011 Sizes.NumVars = Vars.size();
1012 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1013 Sizes.NumComponentLists = ComponentLists.size();
1014 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaoec172c62016-05-26 17:49:04 +00001015
1016 // We need to allocate:
Michael Kruse0336c752019-02-25 20:34:15 +00001017 // 2 x NumVars x Expr* - we have an original list expression and an associated
1018 // user-defined mapper for each clause list entry.
Samuel Antaoec172c62016-05-26 17:49:04 +00001019 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1020 // with each component list.
1021 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1022 // number of lists for each unique declaration and the size of each component
1023 // list.
1024 // NumComponents x MappableComponent - the total of all the components in all
1025 // the lists.
1026 void *Mem = C.Allocate(
1027 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1028 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001029 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001030 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1031 Sizes.NumComponents));
Samuel Antaoec172c62016-05-26 17:49:04 +00001032
Michael Kruse0336c752019-02-25 20:34:15 +00001033 auto *Clause =
1034 new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001035
1036 Clause->setVarRefs(Vars);
Michael Kruse0336c752019-02-25 20:34:15 +00001037 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antaoec172c62016-05-26 17:49:04 +00001038 Clause->setClauseInfo(Declarations, ComponentLists);
1039 return Clause;
1040}
1041
Michael Kruse4304e9d2019-02-19 16:38:20 +00001042OMPFromClause *
1043OMPFromClause::CreateEmpty(const ASTContext &C,
1044 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaoec172c62016-05-26 17:49:04 +00001045 void *Mem = C.Allocate(
1046 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1047 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001048 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001049 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1050 Sizes.NumComponents));
1051 return new (Mem) OMPFromClause(Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001052}
Carlo Bertolli2404b172016-07-13 15:37:16 +00001053
Samuel Antaocc10b852016-07-28 14:23:26 +00001054void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1055 assert(VL.size() == varlist_size() &&
1056 "Number of private copies is not the same as the preallocated buffer");
1057 std::copy(VL.begin(), VL.end(), varlist_end());
1058}
1059
1060void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
1061 assert(VL.size() == varlist_size() &&
1062 "Number of inits is not the same as the preallocated buffer");
1063 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1064}
1065
1066OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001067 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1068 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
1069 ArrayRef<ValueDecl *> Declarations,
Samuel Antaocc10b852016-07-28 14:23:26 +00001070 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001071 OMPMappableExprListSizeTy Sizes;
1072 Sizes.NumVars = Vars.size();
1073 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1074 Sizes.NumComponentLists = ComponentLists.size();
1075 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaocc10b852016-07-28 14:23:26 +00001076
1077 // We need to allocate:
1078 // 3 x NumVars x Expr* - we have an original list expression for each clause
1079 // list entry and an equal number of private copies and inits.
1080 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1081 // with each component list.
1082 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1083 // number of lists for each unique declaration and the size of each component
1084 // list.
1085 // NumComponents x MappableComponent - the total of all the components in all
1086 // the lists.
1087 void *Mem = C.Allocate(
1088 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1089 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001090 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1091 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1092 Sizes.NumComponents));
Samuel Antaocc10b852016-07-28 14:23:26 +00001093
Michael Kruse4304e9d2019-02-19 16:38:20 +00001094 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
Samuel Antaocc10b852016-07-28 14:23:26 +00001095
1096 Clause->setVarRefs(Vars);
1097 Clause->setPrivateCopies(PrivateVars);
1098 Clause->setInits(Inits);
1099 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001100 return Clause;
1101}
1102
Michael Kruse4304e9d2019-02-19 16:38:20 +00001103OMPUseDevicePtrClause *
1104OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
1105 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaocc10b852016-07-28 14:23:26 +00001106 void *Mem = C.Allocate(
1107 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1108 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001109 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1110 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1111 Sizes.NumComponents));
1112 return new (Mem) OMPUseDevicePtrClause(Sizes);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001113}
Carlo Bertolli70594e92016-07-13 17:16:49 +00001114
Samuel Antao6890b092016-07-28 14:25:09 +00001115OMPIsDevicePtrClause *
Michael Kruse4304e9d2019-02-19 16:38:20 +00001116OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
Samuel Antao6890b092016-07-28 14:25:09 +00001117 ArrayRef<Expr *> Vars,
1118 ArrayRef<ValueDecl *> Declarations,
1119 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001120 OMPMappableExprListSizeTy Sizes;
1121 Sizes.NumVars = Vars.size();
1122 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1123 Sizes.NumComponentLists = ComponentLists.size();
1124 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao6890b092016-07-28 14:25:09 +00001125
1126 // We need to allocate:
1127 // NumVars x Expr* - we have an original list expression for each clause list
1128 // entry.
1129 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1130 // with each component list.
1131 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1132 // number of lists for each unique declaration and the size of each component
1133 // list.
1134 // NumComponents x MappableComponent - the total of all the components in all
1135 // the lists.
1136 void *Mem = C.Allocate(
1137 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1138 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001139 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1140 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1141 Sizes.NumComponents));
Samuel Antao6890b092016-07-28 14:25:09 +00001142
Michael Kruse4304e9d2019-02-19 16:38:20 +00001143 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
Samuel Antao6890b092016-07-28 14:25:09 +00001144
1145 Clause->setVarRefs(Vars);
1146 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001147 return Clause;
1148}
1149
Michael Kruse4304e9d2019-02-19 16:38:20 +00001150OMPIsDevicePtrClause *
1151OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1152 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao6890b092016-07-28 14:25:09 +00001153 void *Mem = C.Allocate(
1154 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1155 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001156 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1157 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1158 Sizes.NumComponents));
1159 return new (Mem) OMPIsDevicePtrClause(Sizes);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001160}
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001161
Alexey Bataevb6e70842019-12-16 15:54:17 -05001162OMPNontemporalClause *OMPNontemporalClause::Create(const ASTContext &C,
1163 SourceLocation StartLoc,
1164 SourceLocation LParenLoc,
1165 SourceLocation EndLoc,
1166 ArrayRef<Expr *> VL) {
Alexey Bataev0860db92019-12-19 10:01:10 -05001167 // Allocate space for nontemporal variables + private references.
1168 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
Alexey Bataevb6e70842019-12-16 15:54:17 -05001169 auto *Clause =
1170 new (Mem) OMPNontemporalClause(StartLoc, LParenLoc, EndLoc, VL.size());
1171 Clause->setVarRefs(VL);
1172 return Clause;
1173}
1174
1175OMPNontemporalClause *OMPNontemporalClause::CreateEmpty(const ASTContext &C,
1176 unsigned N) {
Alexey Bataev0860db92019-12-19 10:01:10 -05001177 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
Alexey Bataevb6e70842019-12-16 15:54:17 -05001178 return new (Mem) OMPNontemporalClause(N);
1179}
1180
Alexey Bataev0860db92019-12-19 10:01:10 -05001181void OMPNontemporalClause::setPrivateRefs(ArrayRef<Expr *> VL) {
1182 assert(VL.size() == varlist_size() && "Number of private references is not "
1183 "the same as the preallocated buffer");
1184 std::copy(VL.begin(), VL.end(), varlist_end());
1185}
1186
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001187//===----------------------------------------------------------------------===//
1188// OpenMP clauses printing methods
1189//===----------------------------------------------------------------------===//
1190
1191void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1192 OS << "if(";
Johannes Doerferteb3e81f2019-11-04 22:00:49 -06001193 if (Node->getNameModifier() != llvm::omp::OMPD_unknown)
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001194 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1195 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1196 OS << ")";
1197}
1198
1199void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1200 OS << "final(";
1201 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1202 OS << ")";
1203}
1204
1205void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1206 OS << "num_threads(";
1207 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1208 OS << ")";
1209}
1210
1211void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1212 OS << "safelen(";
1213 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1214 OS << ")";
1215}
1216
1217void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1218 OS << "simdlen(";
1219 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1220 OS << ")";
1221}
1222
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00001223void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
1224 OS << "allocator(";
1225 Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
1226 OS << ")";
1227}
1228
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001229void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1230 OS << "collapse(";
1231 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1232 OS << ")";
1233}
1234
1235void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1236 OS << "default("
1237 << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
1238 << ")";
1239}
1240
1241void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1242 OS << "proc_bind("
Johannes Doerfert6c5d1f402019-12-25 18:15:36 -06001243 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind,
1244 unsigned(Node->getProcBindKind()))
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001245 << ")";
1246}
1247
1248void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1249 OS << "unified_address";
1250}
1251
1252void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1253 OMPUnifiedSharedMemoryClause *) {
1254 OS << "unified_shared_memory";
1255}
1256
1257void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1258 OS << "reverse_offload";
1259}
1260
1261void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1262 OMPDynamicAllocatorsClause *) {
1263 OS << "dynamic_allocators";
1264}
1265
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00001266void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1267 OMPAtomicDefaultMemOrderClause *Node) {
1268 OS << "atomic_default_mem_order("
1269 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1270 Node->getAtomicDefaultMemOrderKind())
1271 << ")";
1272}
1273
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001274void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1275 OS << "schedule(";
1276 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1277 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1278 Node->getFirstScheduleModifier());
1279 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1280 OS << ", ";
1281 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1282 Node->getSecondScheduleModifier());
1283 }
1284 OS << ": ";
1285 }
1286 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1287 if (auto *E = Node->getChunkSize()) {
1288 OS << ", ";
1289 E->printPretty(OS, nullptr, Policy);
1290 }
1291 OS << ")";
1292}
1293
1294void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1295 OS << "ordered";
1296 if (auto *Num = Node->getNumForLoops()) {
1297 OS << "(";
1298 Num->printPretty(OS, nullptr, Policy, 0);
1299 OS << ")";
1300 }
1301}
1302
1303void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1304 OS << "nowait";
1305}
1306
1307void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1308 OS << "untied";
1309}
1310
1311void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1312 OS << "nogroup";
1313}
1314
1315void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1316 OS << "mergeable";
1317}
1318
1319void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1320
1321void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1322
1323void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
1324 OS << "update";
1325}
1326
1327void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1328 OS << "capture";
1329}
1330
1331void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1332 OS << "seq_cst";
1333}
1334
1335void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1336 OS << "threads";
1337}
1338
1339void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1340
1341void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1342 OS << "device(";
1343 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1344 OS << ")";
1345}
1346
1347void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1348 OS << "num_teams(";
1349 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1350 OS << ")";
1351}
1352
1353void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1354 OS << "thread_limit(";
1355 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1356 OS << ")";
1357}
1358
1359void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1360 OS << "priority(";
1361 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1362 OS << ")";
1363}
1364
1365void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1366 OS << "grainsize(";
1367 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1368 OS << ")";
1369}
1370
1371void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1372 OS << "num_tasks(";
1373 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1374 OS << ")";
1375}
1376
1377void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1378 OS << "hint(";
1379 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1380 OS << ")";
1381}
1382
1383template<typename T>
1384void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1385 for (typename T::varlist_iterator I = Node->varlist_begin(),
1386 E = Node->varlist_end();
1387 I != E; ++I) {
1388 assert(*I && "Expected non-null Stmt");
1389 OS << (I == Node->varlist_begin() ? StartSym : ',');
1390 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1391 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1392 DRE->printPretty(OS, nullptr, Policy, 0);
1393 else
1394 DRE->getDecl()->printQualifiedName(OS);
1395 } else
1396 (*I)->printPretty(OS, nullptr, Policy, 0);
1397 }
1398}
1399
Alexey Bataeve04483e2019-03-27 14:14:31 +00001400void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
1401 if (Node->varlist_empty())
1402 return;
1403 OS << "allocate";
1404 if (Expr *Allocator = Node->getAllocator()) {
1405 OS << "(";
1406 Allocator->printPretty(OS, nullptr, Policy, 0);
1407 OS << ":";
1408 VisitOMPClauseList(Node, ' ');
1409 } else {
1410 VisitOMPClauseList(Node, '(');
1411 }
1412 OS << ")";
1413}
1414
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001415void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1416 if (!Node->varlist_empty()) {
1417 OS << "private";
1418 VisitOMPClauseList(Node, '(');
1419 OS << ")";
1420 }
1421}
1422
1423void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1424 if (!Node->varlist_empty()) {
1425 OS << "firstprivate";
1426 VisitOMPClauseList(Node, '(');
1427 OS << ")";
1428 }
1429}
1430
1431void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1432 if (!Node->varlist_empty()) {
1433 OS << "lastprivate";
Alexey Bataev93dc40d2019-12-20 11:04:57 -05001434 OpenMPLastprivateModifier LPKind = Node->getKind();
1435 if (LPKind != OMPC_LASTPRIVATE_unknown) {
1436 OS << "("
1437 << getOpenMPSimpleClauseTypeName(OMPC_lastprivate, Node->getKind())
1438 << ":";
1439 }
1440 VisitOMPClauseList(Node, LPKind == OMPC_LASTPRIVATE_unknown ? '(' : ' ');
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001441 OS << ")";
1442 }
1443}
1444
1445void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1446 if (!Node->varlist_empty()) {
1447 OS << "shared";
1448 VisitOMPClauseList(Node, '(');
1449 OS << ")";
1450 }
1451}
1452
1453void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1454 if (!Node->varlist_empty()) {
1455 OS << "reduction(";
1456 NestedNameSpecifier *QualifierLoc =
1457 Node->getQualifierLoc().getNestedNameSpecifier();
1458 OverloadedOperatorKind OOK =
1459 Node->getNameInfo().getName().getCXXOverloadedOperator();
1460 if (QualifierLoc == nullptr && OOK != OO_None) {
1461 // Print reduction identifier in C format
1462 OS << getOperatorSpelling(OOK);
1463 } else {
1464 // Use C++ format
1465 if (QualifierLoc != nullptr)
1466 QualifierLoc->print(OS, Policy);
1467 OS << Node->getNameInfo();
1468 }
1469 OS << ":";
1470 VisitOMPClauseList(Node, ' ');
1471 OS << ")";
1472 }
1473}
1474
1475void OMPClausePrinter::VisitOMPTaskReductionClause(
1476 OMPTaskReductionClause *Node) {
1477 if (!Node->varlist_empty()) {
1478 OS << "task_reduction(";
1479 NestedNameSpecifier *QualifierLoc =
1480 Node->getQualifierLoc().getNestedNameSpecifier();
1481 OverloadedOperatorKind OOK =
1482 Node->getNameInfo().getName().getCXXOverloadedOperator();
1483 if (QualifierLoc == nullptr && OOK != OO_None) {
1484 // Print reduction identifier in C format
1485 OS << getOperatorSpelling(OOK);
1486 } else {
1487 // Use C++ format
1488 if (QualifierLoc != nullptr)
1489 QualifierLoc->print(OS, Policy);
1490 OS << Node->getNameInfo();
1491 }
1492 OS << ":";
1493 VisitOMPClauseList(Node, ' ');
1494 OS << ")";
1495 }
1496}
1497
1498void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1499 if (!Node->varlist_empty()) {
1500 OS << "in_reduction(";
1501 NestedNameSpecifier *QualifierLoc =
1502 Node->getQualifierLoc().getNestedNameSpecifier();
1503 OverloadedOperatorKind OOK =
1504 Node->getNameInfo().getName().getCXXOverloadedOperator();
1505 if (QualifierLoc == nullptr && OOK != OO_None) {
1506 // Print reduction identifier in C format
1507 OS << getOperatorSpelling(OOK);
1508 } else {
1509 // Use C++ format
1510 if (QualifierLoc != nullptr)
1511 QualifierLoc->print(OS, Policy);
1512 OS << Node->getNameInfo();
1513 }
1514 OS << ":";
1515 VisitOMPClauseList(Node, ' ');
1516 OS << ")";
1517 }
1518}
1519
1520void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1521 if (!Node->varlist_empty()) {
1522 OS << "linear";
1523 if (Node->getModifierLoc().isValid()) {
1524 OS << '('
1525 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1526 }
1527 VisitOMPClauseList(Node, '(');
1528 if (Node->getModifierLoc().isValid())
1529 OS << ')';
1530 if (Node->getStep() != nullptr) {
1531 OS << ": ";
1532 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1533 }
1534 OS << ")";
1535 }
1536}
1537
1538void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1539 if (!Node->varlist_empty()) {
1540 OS << "aligned";
1541 VisitOMPClauseList(Node, '(');
1542 if (Node->getAlignment() != nullptr) {
1543 OS << ": ";
1544 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1545 }
1546 OS << ")";
1547 }
1548}
1549
1550void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1551 if (!Node->varlist_empty()) {
1552 OS << "copyin";
1553 VisitOMPClauseList(Node, '(');
1554 OS << ")";
1555 }
1556}
1557
1558void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1559 if (!Node->varlist_empty()) {
1560 OS << "copyprivate";
1561 VisitOMPClauseList(Node, '(');
1562 OS << ")";
1563 }
1564}
1565
1566void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1567 if (!Node->varlist_empty()) {
1568 VisitOMPClauseList(Node, '(');
1569 OS << ")";
1570 }
1571}
1572
1573void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1574 OS << "depend(";
1575 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1576 Node->getDependencyKind());
1577 if (!Node->varlist_empty()) {
1578 OS << " :";
1579 VisitOMPClauseList(Node, ' ');
1580 }
1581 OS << ")";
1582}
1583
1584void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1585 if (!Node->varlist_empty()) {
1586 OS << "map(";
1587 if (Node->getMapType() != OMPC_MAP_unknown) {
Kelvin Lief579432018-12-18 22:18:41 +00001588 for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1589 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1590 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1591 Node->getMapTypeModifier(I));
Michael Kruse4304e9d2019-02-19 16:38:20 +00001592 if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1593 OS << '(';
1594 NestedNameSpecifier *MapperNNS =
1595 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1596 if (MapperNNS)
1597 MapperNNS->print(OS, Policy);
1598 OS << Node->getMapperIdInfo() << ')';
1599 }
Kelvin Lief579432018-12-18 22:18:41 +00001600 OS << ',';
1601 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001602 }
1603 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1604 OS << ':';
1605 }
1606 VisitOMPClauseList(Node, ' ');
1607 OS << ")";
1608 }
1609}
1610
1611void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1612 if (!Node->varlist_empty()) {
1613 OS << "to";
Michael Kruse01f670d2019-02-22 22:29:42 +00001614 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1615 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1616 OS << '(';
1617 OS << "mapper(";
1618 NestedNameSpecifier *MapperNNS =
1619 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1620 if (MapperNNS)
1621 MapperNNS->print(OS, Policy);
1622 OS << MapperId << "):";
1623 VisitOMPClauseList(Node, ' ');
1624 } else {
1625 VisitOMPClauseList(Node, '(');
1626 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001627 OS << ")";
1628 }
1629}
1630
1631void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1632 if (!Node->varlist_empty()) {
1633 OS << "from";
Michael Kruse0336c752019-02-25 20:34:15 +00001634 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1635 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1636 OS << '(';
1637 OS << "mapper(";
1638 NestedNameSpecifier *MapperNNS =
1639 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1640 if (MapperNNS)
1641 MapperNNS->print(OS, Policy);
1642 OS << MapperId << "):";
1643 VisitOMPClauseList(Node, ' ');
1644 } else {
1645 VisitOMPClauseList(Node, '(');
1646 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001647 OS << ")";
1648 }
1649}
1650
1651void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1652 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1653 OMPC_dist_schedule, Node->getDistScheduleKind());
1654 if (auto *E = Node->getChunkSize()) {
1655 OS << ", ";
1656 E->printPretty(OS, nullptr, Policy);
1657 }
1658 OS << ")";
1659}
1660
1661void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1662 OS << "defaultmap(";
1663 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1664 Node->getDefaultmapModifier());
1665 OS << ": ";
1666 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1667 Node->getDefaultmapKind());
1668 OS << ")";
1669}
1670
1671void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1672 if (!Node->varlist_empty()) {
1673 OS << "use_device_ptr";
1674 VisitOMPClauseList(Node, '(');
1675 OS << ")";
1676 }
1677}
1678
1679void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1680 if (!Node->varlist_empty()) {
1681 OS << "is_device_ptr";
1682 VisitOMPClauseList(Node, '(');
1683 OS << ")";
1684 }
1685}
1686
Alexey Bataevb6e70842019-12-16 15:54:17 -05001687void OMPClausePrinter::VisitOMPNontemporalClause(OMPNontemporalClause *Node) {
1688 if (!Node->varlist_empty()) {
1689 OS << "nontemporal";
1690 VisitOMPClauseList(Node, '(');
1691 OS << ")";
1692 }
1693}