blob: c7e7f339d4992b7159da179378508ce4f04d5d39 [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 Bataevcb8e6912020-01-31 16:09:26 -0500140 case OMPC_order:
Alexey Bataev005248a2016-02-25 05:25:57 +0000141 break;
142 }
143
144 return nullptr;
145}
146
147OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
148 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
149 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
150}
151
152const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
153 switch (C->getClauseKind()) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000154 case OMPC_lastprivate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000155 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000156 case OMPC_reduction:
157 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +0000158 case OMPC_task_reduction:
159 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000160 case OMPC_in_reduction:
161 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000162 case OMPC_linear:
163 return static_cast<const OMPLinearClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000164 case OMPC_schedule:
165 case OMPC_dist_schedule:
166 case OMPC_firstprivate:
167 case OMPC_default:
168 case OMPC_proc_bind:
169 case OMPC_if:
170 case OMPC_final:
171 case OMPC_num_threads:
172 case OMPC_safelen:
173 case OMPC_simdlen:
Alexey Bataev9cc10fc2019-03-12 18:52:33 +0000174 case OMPC_allocator:
Alexey Bataeve04483e2019-03-27 14:14:31 +0000175 case OMPC_allocate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000176 case OMPC_collapse:
177 case OMPC_private:
Alexey Bataev3392d762016-02-16 11:18:12 +0000178 case OMPC_shared:
Alexey Bataev3392d762016-02-16 11:18:12 +0000179 case OMPC_aligned:
180 case OMPC_copyin:
181 case OMPC_copyprivate:
182 case OMPC_ordered:
183 case OMPC_nowait:
184 case OMPC_untied:
185 case OMPC_mergeable:
186 case OMPC_threadprivate:
187 case OMPC_flush:
188 case OMPC_read:
189 case OMPC_write:
190 case OMPC_update:
191 case OMPC_capture:
192 case OMPC_seq_cst:
193 case OMPC_depend:
194 case OMPC_device:
195 case OMPC_threads:
196 case OMPC_simd:
197 case OMPC_map:
198 case OMPC_num_teams:
199 case OMPC_thread_limit:
200 case OMPC_priority:
201 case OMPC_grainsize:
202 case OMPC_nogroup:
203 case OMPC_num_tasks:
204 case OMPC_hint:
205 case OMPC_defaultmap:
206 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000207 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000208 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000209 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000210 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000211 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000212 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000213 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000214 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000215 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000216 case OMPC_atomic_default_mem_order:
Alexey Bataev729e2422019-08-23 16:11:14 +0000217 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +0000218 case OMPC_match:
Alexey Bataevb6e70842019-12-16 15:54:17 -0500219 case OMPC_nontemporal:
Alexey Bataevcb8e6912020-01-31 16:09:26 -0500220 case OMPC_order:
Alexey Bataev3392d762016-02-16 11:18:12 +0000221 break;
222 }
223
224 return nullptr;
225}
226
Alexey Bataev655cb4a2019-07-16 14:51:46 +0000227/// Gets the address of the original, non-captured, expression used in the
228/// clause as the preinitializer.
229static Stmt **getAddrOfExprAsWritten(Stmt *S) {
230 if (!S)
231 return nullptr;
232 if (auto *DS = dyn_cast<DeclStmt>(S)) {
233 assert(DS->isSingleDecl() && "Only single expression must be captured.");
234 if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
235 return OED->getInitAddress();
236 }
237 return nullptr;
238}
239
240OMPClause::child_range OMPIfClause::used_children() {
241 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
242 return child_range(C, C + 1);
243 return child_range(&Condition, &Condition + 1);
244}
245
Alexey Bataevb9c55e22019-10-14 19:29:52 +0000246OMPClause::child_range OMPGrainsizeClause::used_children() {
247 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
248 return child_range(C, C + 1);
249 return child_range(&Grainsize, &Grainsize + 1);
250}
251
Alexey Bataevd88c7de2019-10-14 20:44:34 +0000252OMPClause::child_range OMPNumTasksClause::used_children() {
253 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
254 return child_range(C, C + 1);
255 return child_range(&NumTasks, &NumTasks + 1);
256}
257
Alexey Bataev3a842ec2019-10-15 19:37:05 +0000258OMPClause::child_range OMPFinalClause::used_children() {
259 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
260 return child_range(C, C + 1);
261 return child_range(&Condition, &Condition + 1);
262}
263
Alexey Bataev31ba4762019-10-16 18:09:37 +0000264OMPClause::child_range OMPPriorityClause::used_children() {
265 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
266 return child_range(C, C + 1);
267 return child_range(&Priority, &Priority + 1);
268}
269
Alexey Bataevf138fda2018-08-13 19:04:24 +0000270OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
271 unsigned NumLoops,
272 SourceLocation StartLoc,
273 SourceLocation LParenLoc,
274 SourceLocation EndLoc) {
275 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
276 auto *Clause =
277 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
278 for (unsigned I = 0; I < NumLoops; ++I) {
279 Clause->setLoopNumIterations(I, nullptr);
280 Clause->setLoopCounter(I, nullptr);
281 }
282 return Clause;
283}
284
285OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
286 unsigned NumLoops) {
287 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
288 auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
289 for (unsigned I = 0; I < NumLoops; ++I) {
290 Clause->setLoopNumIterations(I, nullptr);
291 Clause->setLoopCounter(I, nullptr);
292 }
293 return Clause;
294}
295
296void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
297 Expr *NumIterations) {
298 assert(NumLoop < NumberOfLoops && "out of loops number.");
299 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
300}
301
302ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
303 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
304}
305
306void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
307 assert(NumLoop < NumberOfLoops && "out of loops number.");
308 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
309}
310
Mike Rice0ed46662018-09-20 17:19:41 +0000311Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000312 assert(NumLoop < NumberOfLoops && "out of loops number.");
313 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
314}
315
Mike Rice0ed46662018-09-20 17:19:41 +0000316const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000317 assert(NumLoop < NumberOfLoops && "out of loops number.");
318 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
319}
320
James Y Knightb8bfd962015-10-02 13:41:04 +0000321void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
322 assert(VL.size() == varlist_size() &&
323 "Number of private copies is not the same as the preallocated buffer");
324 std::copy(VL.begin(), VL.end(), varlist_end());
325}
326
327OMPPrivateClause *
328OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
329 SourceLocation LParenLoc, SourceLocation EndLoc,
330 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
331 // Allocate space for private variables and initializer expressions.
James Y Knight374fd202016-01-01 00:38:24 +0000332 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000333 OMPPrivateClause *Clause =
334 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
335 Clause->setVarRefs(VL);
336 Clause->setPrivateCopies(PrivateVL);
337 return Clause;
338}
339
340OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
341 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000342 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000343 return new (Mem) OMPPrivateClause(N);
344}
345
346void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
347 assert(VL.size() == varlist_size() &&
348 "Number of private copies is not the same as the preallocated buffer");
349 std::copy(VL.begin(), VL.end(), varlist_end());
350}
351
352void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
353 assert(VL.size() == varlist_size() &&
354 "Number of inits is not the same as the preallocated buffer");
355 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
356}
357
358OMPFirstprivateClause *
359OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
360 SourceLocation LParenLoc, SourceLocation EndLoc,
361 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
Alexey Bataev417089f2016-02-17 13:19:37 +0000362 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
James Y Knight374fd202016-01-01 00:38:24 +0000363 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000364 OMPFirstprivateClause *Clause =
365 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
366 Clause->setVarRefs(VL);
367 Clause->setPrivateCopies(PrivateVL);
368 Clause->setInits(InitVL);
Alexey Bataev417089f2016-02-17 13:19:37 +0000369 Clause->setPreInitStmt(PreInit);
James Y Knightb8bfd962015-10-02 13:41:04 +0000370 return Clause;
371}
372
373OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
374 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000375 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000376 return new (Mem) OMPFirstprivateClause(N);
377}
378
379void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
380 assert(PrivateCopies.size() == varlist_size() &&
381 "Number of private copies is not the same as the preallocated buffer");
382 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
383}
384
385void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
386 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
387 "not the same as the "
388 "preallocated buffer");
389 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
390}
391
392void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
393 assert(DstExprs.size() == varlist_size() && "Number of destination "
394 "expressions is not the same as "
395 "the preallocated buffer");
396 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
397}
398
399void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
400 assert(AssignmentOps.size() == varlist_size() &&
401 "Number of assignment expressions is not the same as the preallocated "
402 "buffer");
403 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
404 getDestinationExprs().end());
405}
406
407OMPLastprivateClause *OMPLastprivateClause::Create(
408 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
409 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
Alexey Bataev93dc40d2019-12-20 11:04:57 -0500410 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
411 OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
412 SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000413 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
Alexey Bataev93dc40d2019-12-20 11:04:57 -0500414 OMPLastprivateClause *Clause = new (Mem) OMPLastprivateClause(
415 StartLoc, LParenLoc, EndLoc, LPKind, LPKindLoc, ColonLoc, VL.size());
James Y Knightb8bfd962015-10-02 13:41:04 +0000416 Clause->setVarRefs(VL);
417 Clause->setSourceExprs(SrcExprs);
418 Clause->setDestinationExprs(DstExprs);
419 Clause->setAssignmentOps(AssignmentOps);
Alexey Bataev005248a2016-02-25 05:25:57 +0000420 Clause->setPreInitStmt(PreInit);
421 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000422 return Clause;
423}
424
425OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
426 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000427 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000428 return new (Mem) OMPLastprivateClause(N);
429}
430
431OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
432 SourceLocation StartLoc,
433 SourceLocation LParenLoc,
434 SourceLocation EndLoc,
435 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000436 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000437 OMPSharedClause *Clause =
438 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
439 Clause->setVarRefs(VL);
440 return Clause;
441}
442
443OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000444 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000445 return new (Mem) OMPSharedClause(N);
446}
447
448void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
449 assert(PL.size() == varlist_size() &&
450 "Number of privates is not the same as the preallocated buffer");
451 std::copy(PL.begin(), PL.end(), varlist_end());
452}
453
454void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
455 assert(IL.size() == varlist_size() &&
456 "Number of inits is not the same as the preallocated buffer");
457 std::copy(IL.begin(), IL.end(), getPrivates().end());
458}
459
460void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
461 assert(UL.size() == varlist_size() &&
462 "Number of updates is not the same as the preallocated buffer");
463 std::copy(UL.begin(), UL.end(), getInits().end());
464}
465
466void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
467 assert(FL.size() == varlist_size() &&
468 "Number of final updates is not the same as the preallocated buffer");
469 std::copy(FL.begin(), FL.end(), getUpdates().end());
470}
471
Alexey Bataev195ae902019-08-08 13:42:45 +0000472void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) {
473 assert(
474 UE.size() == varlist_size() + 1 &&
475 "Number of used expressions is not the same as the preallocated buffer");
476 std::copy(UE.begin(), UE.end(), getFinals().end() + 2);
477}
478
James Y Knightb8bfd962015-10-02 13:41:04 +0000479OMPLinearClause *OMPLinearClause::Create(
480 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
481 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
482 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
Alexey Bataev78849fb2016-03-09 09:49:00 +0000483 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
484 Stmt *PreInit, Expr *PostUpdate) {
Alexey Bataev195ae902019-08-08 13:42:45 +0000485 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
486 // (Step and CalcStep), list of used expression + step.
487 void *Mem =
488 C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000489 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
490 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
491 Clause->setVarRefs(VL);
492 Clause->setPrivates(PL);
493 Clause->setInits(IL);
494 // Fill update and final expressions with zeroes, they are provided later,
495 // after the directive construction.
496 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
497 nullptr);
498 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
499 nullptr);
Alexey Bataev195ae902019-08-08 13:42:45 +0000500 std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(),
501 nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000502 Clause->setStep(Step);
503 Clause->setCalcStep(CalcStep);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000504 Clause->setPreInitStmt(PreInit);
505 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000506 return Clause;
507}
508
509OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
510 unsigned NumVars) {
Alexey Bataev195ae902019-08-08 13:42:45 +0000511 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
512 // (Step and CalcStep), list of used expression + step.
513 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars +1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000514 return new (Mem) OMPLinearClause(NumVars);
515}
516
Alexey Bataev195ae902019-08-08 13:42:45 +0000517OMPClause::child_range OMPLinearClause::used_children() {
518 // Range includes only non-nullptr elements.
519 return child_range(
520 reinterpret_cast<Stmt **>(getUsedExprs().begin()),
521 reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr)));
522}
523
James Y Knightb8bfd962015-10-02 13:41:04 +0000524OMPAlignedClause *
525OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
526 SourceLocation LParenLoc, SourceLocation ColonLoc,
527 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
James Y Knight374fd202016-01-01 00:38:24 +0000528 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000529 OMPAlignedClause *Clause = new (Mem)
530 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
531 Clause->setVarRefs(VL);
532 Clause->setAlignment(A);
533 return Clause;
534}
535
536OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
537 unsigned NumVars) {
James Y Knight374fd202016-01-01 00:38:24 +0000538 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000539 return new (Mem) OMPAlignedClause(NumVars);
540}
541
542void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
543 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
544 "not the same as the "
545 "preallocated buffer");
546 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
547}
548
549void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
550 assert(DstExprs.size() == varlist_size() && "Number of destination "
551 "expressions is not the same as "
552 "the preallocated buffer");
553 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
554}
555
556void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
557 assert(AssignmentOps.size() == varlist_size() &&
558 "Number of assignment expressions is not the same as the preallocated "
559 "buffer");
560 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
561 getDestinationExprs().end());
562}
563
564OMPCopyinClause *OMPCopyinClause::Create(
565 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
566 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
567 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000568 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000569 OMPCopyinClause *Clause =
570 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
571 Clause->setVarRefs(VL);
572 Clause->setSourceExprs(SrcExprs);
573 Clause->setDestinationExprs(DstExprs);
574 Clause->setAssignmentOps(AssignmentOps);
575 return Clause;
576}
577
578OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000579 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000580 return new (Mem) OMPCopyinClause(N);
581}
582
583void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
584 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
585 "not the same as the "
586 "preallocated buffer");
587 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
588}
589
590void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
591 assert(DstExprs.size() == varlist_size() && "Number of destination "
592 "expressions is not the same as "
593 "the preallocated buffer");
594 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
595}
596
597void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
598 assert(AssignmentOps.size() == varlist_size() &&
599 "Number of assignment expressions is not the same as the preallocated "
600 "buffer");
601 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
602 getDestinationExprs().end());
603}
604
605OMPCopyprivateClause *OMPCopyprivateClause::Create(
606 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
607 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
608 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000609 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000610 OMPCopyprivateClause *Clause =
611 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
612 Clause->setVarRefs(VL);
613 Clause->setSourceExprs(SrcExprs);
614 Clause->setDestinationExprs(DstExprs);
615 Clause->setAssignmentOps(AssignmentOps);
616 return Clause;
617}
618
619OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
620 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000621 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000622 return new (Mem) OMPCopyprivateClause(N);
623}
624
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000625void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
626 assert(Privates.size() == varlist_size() &&
627 "Number of private copies is not the same as the preallocated buffer");
628 std::copy(Privates.begin(), Privates.end(), varlist_end());
629}
630
James Y Knightb8bfd962015-10-02 13:41:04 +0000631void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
632 assert(
633 LHSExprs.size() == varlist_size() &&
634 "Number of LHS expressions is not the same as the preallocated buffer");
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000635 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
James Y Knightb8bfd962015-10-02 13:41:04 +0000636}
637
638void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
639 assert(
640 RHSExprs.size() == varlist_size() &&
641 "Number of RHS expressions is not the same as the preallocated buffer");
642 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
643}
644
645void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
646 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
647 "expressions is not the same "
648 "as the preallocated buffer");
649 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
650}
651
652OMPReductionClause *OMPReductionClause::Create(
653 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
654 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
655 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000656 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev61205072016-03-02 04:57:40 +0000657 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
658 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000659 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000660 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
661 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
662 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000663 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000664 Clause->setLHSExprs(LHSExprs);
665 Clause->setRHSExprs(RHSExprs);
666 Clause->setReductionOps(ReductionOps);
Alexey Bataev61205072016-03-02 04:57:40 +0000667 Clause->setPreInitStmt(PreInit);
668 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000669 return Clause;
670}
671
672OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
673 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000674 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000675 return new (Mem) OMPReductionClause(N);
676}
677
Alexey Bataev169d96a2017-07-18 20:17:46 +0000678void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
679 assert(Privates.size() == varlist_size() &&
680 "Number of private copies is not the same as the preallocated buffer");
681 std::copy(Privates.begin(), Privates.end(), varlist_end());
682}
683
684void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
685 assert(
686 LHSExprs.size() == varlist_size() &&
687 "Number of LHS expressions is not the same as the preallocated buffer");
688 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
689}
690
691void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
692 assert(
693 RHSExprs.size() == varlist_size() &&
694 "Number of RHS expressions is not the same as the preallocated buffer");
695 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
696}
697
698void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
699 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
700 "expressions is not the same "
701 "as the preallocated buffer");
702 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
703}
704
705OMPTaskReductionClause *OMPTaskReductionClause::Create(
706 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
707 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
708 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
709 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
710 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
711 Expr *PostUpdate) {
712 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
713 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
714 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
715 Clause->setVarRefs(VL);
716 Clause->setPrivates(Privates);
717 Clause->setLHSExprs(LHSExprs);
718 Clause->setRHSExprs(RHSExprs);
719 Clause->setReductionOps(ReductionOps);
720 Clause->setPreInitStmt(PreInit);
721 Clause->setPostUpdateExpr(PostUpdate);
722 return Clause;
723}
724
725OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
726 unsigned N) {
727 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
728 return new (Mem) OMPTaskReductionClause(N);
729}
730
Alexey Bataevfa312f32017-07-21 18:48:21 +0000731void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
732 assert(Privates.size() == varlist_size() &&
733 "Number of private copies is not the same as the preallocated buffer");
734 std::copy(Privates.begin(), Privates.end(), varlist_end());
735}
736
737void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
738 assert(
739 LHSExprs.size() == varlist_size() &&
740 "Number of LHS expressions is not the same as the preallocated buffer");
741 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
742}
743
744void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
745 assert(
746 RHSExprs.size() == varlist_size() &&
747 "Number of RHS expressions is not the same as the preallocated buffer");
748 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
749}
750
751void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
752 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
753 "expressions is not the same "
754 "as the preallocated buffer");
755 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
756}
757
Alexey Bataev88202be2017-07-27 13:20:36 +0000758void OMPInReductionClause::setTaskgroupDescriptors(
759 ArrayRef<Expr *> TaskgroupDescriptors) {
760 assert(TaskgroupDescriptors.size() == varlist_size() &&
761 "Number of in reduction descriptors is not the same as the "
762 "preallocated buffer");
763 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
764 getReductionOps().end());
765}
766
Alexey Bataevfa312f32017-07-21 18:48:21 +0000767OMPInReductionClause *OMPInReductionClause::Create(
768 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
769 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
770 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
771 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev88202be2017-07-27 13:20:36 +0000772 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
773 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
774 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000775 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
776 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
777 Clause->setVarRefs(VL);
778 Clause->setPrivates(Privates);
779 Clause->setLHSExprs(LHSExprs);
780 Clause->setRHSExprs(RHSExprs);
781 Clause->setReductionOps(ReductionOps);
Alexey Bataev88202be2017-07-27 13:20:36 +0000782 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000783 Clause->setPreInitStmt(PreInit);
784 Clause->setPostUpdateExpr(PostUpdate);
785 return Clause;
786}
787
788OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
789 unsigned N) {
Alexey Bataev88202be2017-07-27 13:20:36 +0000790 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000791 return new (Mem) OMPInReductionClause(N);
792}
793
Alexey Bataeve04483e2019-03-27 14:14:31 +0000794OMPAllocateClause *
795OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc,
796 SourceLocation LParenLoc, Expr *Allocator,
797 SourceLocation ColonLoc, SourceLocation EndLoc,
798 ArrayRef<Expr *> VL) {
799 // Allocate space for private variables and initializer expressions.
800 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
801 auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
802 ColonLoc, EndLoc, VL.size());
803 Clause->setVarRefs(VL);
804 return Clause;
805}
806
807OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
808 unsigned N) {
809 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
810 return new (Mem) OMPAllocateClause(N);
811}
812
James Y Knightb8bfd962015-10-02 13:41:04 +0000813OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
814 SourceLocation StartLoc,
815 SourceLocation LParenLoc,
816 SourceLocation EndLoc,
817 ArrayRef<Expr *> VL) {
Alexey Bataev8b427062016-05-25 12:36:08 +0000818 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000819 OMPFlushClause *Clause =
820 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
821 Clause->setVarRefs(VL);
822 return Clause;
823}
824
825OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000826 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000827 return new (Mem) OMPFlushClause(N);
828}
829
Alexey Bataevf138fda2018-08-13 19:04:24 +0000830OMPDependClause *
831OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
832 SourceLocation LParenLoc, SourceLocation EndLoc,
833 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
834 SourceLocation ColonLoc, ArrayRef<Expr *> VL,
835 unsigned NumLoops) {
836 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
837 OMPDependClause *Clause = new (Mem)
838 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000839 Clause->setVarRefs(VL);
840 Clause->setDependencyKind(DepKind);
841 Clause->setDependencyLoc(DepLoc);
842 Clause->setColonLoc(ColonLoc);
Alexey Bataevf138fda2018-08-13 19:04:24 +0000843 for (unsigned I = 0 ; I < NumLoops; ++I)
844 Clause->setLoopData(I, nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000845 return Clause;
846}
847
Alexey Bataevf138fda2018-08-13 19:04:24 +0000848OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
849 unsigned NumLoops) {
850 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
851 return new (Mem) OMPDependClause(N, NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000852}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000853
Alexey Bataevf138fda2018-08-13 19:04:24 +0000854void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
855 assert((getDependencyKind() == OMPC_DEPEND_sink ||
856 getDependencyKind() == OMPC_DEPEND_source) &&
857 NumLoop < NumLoops &&
858 "Expected sink or source depend + loop index must be less number of "
859 "loops.");
860 auto It = std::next(getVarRefs().end(), NumLoop);
861 *It = Cnt;
Alexey Bataev8b427062016-05-25 12:36:08 +0000862}
863
Alexey Bataevf138fda2018-08-13 19:04:24 +0000864Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
865 assert((getDependencyKind() == OMPC_DEPEND_sink ||
866 getDependencyKind() == OMPC_DEPEND_source) &&
867 NumLoop < NumLoops &&
868 "Expected sink or source depend + loop index must be less number of "
869 "loops.");
870 auto It = std::next(getVarRefs().end(), NumLoop);
871 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000872}
873
Alexey Bataevf138fda2018-08-13 19:04:24 +0000874const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
875 assert((getDependencyKind() == OMPC_DEPEND_sink ||
876 getDependencyKind() == OMPC_DEPEND_source) &&
877 NumLoop < NumLoops &&
878 "Expected sink or source depend + loop index must be less number of "
879 "loops.");
880 auto It = std::next(getVarRefs().end(), NumLoop);
881 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000882}
883
Samuel Antao90927002016-04-26 14:54:23 +0000884unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
885 MappableExprComponentListsRef ComponentLists) {
886 unsigned TotalNum = 0u;
887 for (auto &C : ComponentLists)
888 TotalNum += C.size();
889 return TotalNum;
890}
891
892unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
Alexey Bataeve3727102018-04-18 15:57:46 +0000893 ArrayRef<const ValueDecl *> Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000894 unsigned TotalNum = 0u;
895 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
Alexey Bataeve3727102018-04-18 15:57:46 +0000896 for (const ValueDecl *D : Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000897 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
898 if (Cache.count(VD))
899 continue;
900 ++TotalNum;
901 Cache.insert(VD);
902 }
903 return TotalNum;
904}
905
Michael Kruse4304e9d2019-02-19 16:38:20 +0000906OMPMapClause *OMPMapClause::Create(
907 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
908 ArrayRef<ValueDecl *> Declarations,
909 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
910 ArrayRef<OpenMPMapModifierKind> MapModifiers,
911 ArrayRef<SourceLocation> MapModifiersLoc,
912 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
913 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
914 OMPMappableExprListSizeTy Sizes;
915 Sizes.NumVars = Vars.size();
916 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
917 Sizes.NumComponentLists = ComponentLists.size();
918 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao90927002016-04-26 14:54:23 +0000919
920 // We need to allocate:
Michael Kruse4304e9d2019-02-19 16:38:20 +0000921 // 2 x NumVars x Expr* - we have an original list expression and an associated
922 // user-defined mapper for each clause list entry.
Samuel Antao90927002016-04-26 14:54:23 +0000923 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
924 // with each component list.
925 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
926 // number of lists for each unique declaration and the size of each component
927 // list.
928 // NumComponents x MappableComponent - the total of all the components in all
929 // the lists.
930 void *Mem = C.Allocate(
931 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
932 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000933 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
934 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
935 Sizes.NumComponents));
936 OMPMapClause *Clause = new (Mem)
937 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
938 Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
Samuel Antao90927002016-04-26 14:54:23 +0000939
940 Clause->setVarRefs(Vars);
Michael Kruse4304e9d2019-02-19 16:38:20 +0000941 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao90927002016-04-26 14:54:23 +0000942 Clause->setClauseInfo(Declarations, ComponentLists);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000943 Clause->setMapType(Type);
944 Clause->setMapLoc(TypeLoc);
945 return Clause;
946}
947
Michael Kruse4304e9d2019-02-19 16:38:20 +0000948OMPMapClause *
949OMPMapClause::CreateEmpty(const ASTContext &C,
950 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao90927002016-04-26 14:54:23 +0000951 void *Mem = C.Allocate(
952 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
953 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000954 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
955 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
956 Sizes.NumComponents));
957 return new (Mem) OMPMapClause(Sizes);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000958}
Samuel Antao661c0902016-05-26 17:39:58 +0000959
Michael Kruse01f670d2019-02-22 22:29:42 +0000960OMPToClause *OMPToClause::Create(
961 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
962 ArrayRef<ValueDecl *> Declarations,
963 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
964 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000965 OMPMappableExprListSizeTy Sizes;
966 Sizes.NumVars = Vars.size();
967 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
968 Sizes.NumComponentLists = ComponentLists.size();
969 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao661c0902016-05-26 17:39:58 +0000970
971 // We need to allocate:
Michael Kruse01f670d2019-02-22 22:29:42 +0000972 // 2 x NumVars x Expr* - we have an original list expression and an associated
973 // user-defined mapper for each clause list entry.
Samuel Antao661c0902016-05-26 17:39:58 +0000974 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
975 // with each component list.
976 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
977 // number of lists for each unique declaration and the size of each component
978 // list.
979 // NumComponents x MappableComponent - the total of all the components in all
980 // the lists.
981 void *Mem = C.Allocate(
982 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
983 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +0000984 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000985 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
986 Sizes.NumComponents));
Samuel Antao661c0902016-05-26 17:39:58 +0000987
Michael Kruse01f670d2019-02-22 22:29:42 +0000988 auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +0000989
990 Clause->setVarRefs(Vars);
Michael Kruse01f670d2019-02-22 22:29:42 +0000991 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao661c0902016-05-26 17:39:58 +0000992 Clause->setClauseInfo(Declarations, ComponentLists);
993 return Clause;
994}
995
Michael Kruse4304e9d2019-02-19 16:38:20 +0000996OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
997 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao661c0902016-05-26 17:39:58 +0000998 void *Mem = C.Allocate(
999 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1000 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +00001001 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001002 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1003 Sizes.NumComponents));
1004 return new (Mem) OMPToClause(Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +00001005}
Samuel Antaoec172c62016-05-26 17:49:04 +00001006
Michael Kruse0336c752019-02-25 20:34:15 +00001007OMPFromClause *OMPFromClause::Create(
1008 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1009 ArrayRef<ValueDecl *> Declarations,
1010 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1011 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001012 OMPMappableExprListSizeTy Sizes;
1013 Sizes.NumVars = Vars.size();
1014 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1015 Sizes.NumComponentLists = ComponentLists.size();
1016 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaoec172c62016-05-26 17:49:04 +00001017
1018 // We need to allocate:
Michael Kruse0336c752019-02-25 20:34:15 +00001019 // 2 x NumVars x Expr* - we have an original list expression and an associated
1020 // user-defined mapper for each clause list entry.
Samuel Antaoec172c62016-05-26 17:49:04 +00001021 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1022 // with each component list.
1023 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1024 // number of lists for each unique declaration and the size of each component
1025 // list.
1026 // NumComponents x MappableComponent - the total of all the components in all
1027 // the lists.
1028 void *Mem = C.Allocate(
1029 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1030 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001031 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001032 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1033 Sizes.NumComponents));
Samuel Antaoec172c62016-05-26 17:49:04 +00001034
Michael Kruse0336c752019-02-25 20:34:15 +00001035 auto *Clause =
1036 new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001037
1038 Clause->setVarRefs(Vars);
Michael Kruse0336c752019-02-25 20:34:15 +00001039 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antaoec172c62016-05-26 17:49:04 +00001040 Clause->setClauseInfo(Declarations, ComponentLists);
1041 return Clause;
1042}
1043
Michael Kruse4304e9d2019-02-19 16:38:20 +00001044OMPFromClause *
1045OMPFromClause::CreateEmpty(const ASTContext &C,
1046 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaoec172c62016-05-26 17:49:04 +00001047 void *Mem = C.Allocate(
1048 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1049 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001050 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001051 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1052 Sizes.NumComponents));
1053 return new (Mem) OMPFromClause(Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001054}
Carlo Bertolli2404b172016-07-13 15:37:16 +00001055
Samuel Antaocc10b852016-07-28 14:23:26 +00001056void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1057 assert(VL.size() == varlist_size() &&
1058 "Number of private copies is not the same as the preallocated buffer");
1059 std::copy(VL.begin(), VL.end(), varlist_end());
1060}
1061
1062void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
1063 assert(VL.size() == varlist_size() &&
1064 "Number of inits is not the same as the preallocated buffer");
1065 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1066}
1067
1068OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001069 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1070 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
1071 ArrayRef<ValueDecl *> Declarations,
Samuel Antaocc10b852016-07-28 14:23:26 +00001072 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001073 OMPMappableExprListSizeTy Sizes;
1074 Sizes.NumVars = Vars.size();
1075 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1076 Sizes.NumComponentLists = ComponentLists.size();
1077 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaocc10b852016-07-28 14:23:26 +00001078
1079 // We need to allocate:
1080 // 3 x NumVars x Expr* - we have an original list expression for each clause
1081 // list entry and an equal number of private copies and inits.
1082 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1083 // with each component list.
1084 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1085 // number of lists for each unique declaration and the size of each component
1086 // list.
1087 // NumComponents x MappableComponent - the total of all the components in all
1088 // the lists.
1089 void *Mem = C.Allocate(
1090 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1091 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001092 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1093 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1094 Sizes.NumComponents));
Samuel Antaocc10b852016-07-28 14:23:26 +00001095
Michael Kruse4304e9d2019-02-19 16:38:20 +00001096 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
Samuel Antaocc10b852016-07-28 14:23:26 +00001097
1098 Clause->setVarRefs(Vars);
1099 Clause->setPrivateCopies(PrivateVars);
1100 Clause->setInits(Inits);
1101 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001102 return Clause;
1103}
1104
Michael Kruse4304e9d2019-02-19 16:38:20 +00001105OMPUseDevicePtrClause *
1106OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
1107 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaocc10b852016-07-28 14:23:26 +00001108 void *Mem = C.Allocate(
1109 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1110 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001111 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1112 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1113 Sizes.NumComponents));
1114 return new (Mem) OMPUseDevicePtrClause(Sizes);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001115}
Carlo Bertolli70594e92016-07-13 17:16:49 +00001116
Samuel Antao6890b092016-07-28 14:25:09 +00001117OMPIsDevicePtrClause *
Michael Kruse4304e9d2019-02-19 16:38:20 +00001118OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
Samuel Antao6890b092016-07-28 14:25:09 +00001119 ArrayRef<Expr *> Vars,
1120 ArrayRef<ValueDecl *> Declarations,
1121 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001122 OMPMappableExprListSizeTy Sizes;
1123 Sizes.NumVars = Vars.size();
1124 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1125 Sizes.NumComponentLists = ComponentLists.size();
1126 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao6890b092016-07-28 14:25:09 +00001127
1128 // We need to allocate:
1129 // NumVars x Expr* - we have an original list expression for each clause list
1130 // entry.
1131 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1132 // with each component list.
1133 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1134 // number of lists for each unique declaration and the size of each component
1135 // list.
1136 // NumComponents x MappableComponent - the total of all the components in all
1137 // the lists.
1138 void *Mem = C.Allocate(
1139 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1140 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001141 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1142 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1143 Sizes.NumComponents));
Samuel Antao6890b092016-07-28 14:25:09 +00001144
Michael Kruse4304e9d2019-02-19 16:38:20 +00001145 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
Samuel Antao6890b092016-07-28 14:25:09 +00001146
1147 Clause->setVarRefs(Vars);
1148 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001149 return Clause;
1150}
1151
Michael Kruse4304e9d2019-02-19 16:38:20 +00001152OMPIsDevicePtrClause *
1153OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1154 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao6890b092016-07-28 14:25:09 +00001155 void *Mem = C.Allocate(
1156 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1157 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001158 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1159 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1160 Sizes.NumComponents));
1161 return new (Mem) OMPIsDevicePtrClause(Sizes);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001162}
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001163
Alexey Bataevb6e70842019-12-16 15:54:17 -05001164OMPNontemporalClause *OMPNontemporalClause::Create(const ASTContext &C,
1165 SourceLocation StartLoc,
1166 SourceLocation LParenLoc,
1167 SourceLocation EndLoc,
1168 ArrayRef<Expr *> VL) {
Alexey Bataev0860db92019-12-19 10:01:10 -05001169 // Allocate space for nontemporal variables + private references.
1170 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
Alexey Bataevb6e70842019-12-16 15:54:17 -05001171 auto *Clause =
1172 new (Mem) OMPNontemporalClause(StartLoc, LParenLoc, EndLoc, VL.size());
1173 Clause->setVarRefs(VL);
1174 return Clause;
1175}
1176
1177OMPNontemporalClause *OMPNontemporalClause::CreateEmpty(const ASTContext &C,
1178 unsigned N) {
Alexey Bataev0860db92019-12-19 10:01:10 -05001179 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
Alexey Bataevb6e70842019-12-16 15:54:17 -05001180 return new (Mem) OMPNontemporalClause(N);
1181}
1182
Alexey Bataev0860db92019-12-19 10:01:10 -05001183void OMPNontemporalClause::setPrivateRefs(ArrayRef<Expr *> VL) {
1184 assert(VL.size() == varlist_size() && "Number of private references is not "
1185 "the same as the preallocated buffer");
1186 std::copy(VL.begin(), VL.end(), varlist_end());
1187}
1188
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001189//===----------------------------------------------------------------------===//
1190// OpenMP clauses printing methods
1191//===----------------------------------------------------------------------===//
1192
1193void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1194 OS << "if(";
Johannes Doerferteb3e81f2019-11-04 22:00:49 -06001195 if (Node->getNameModifier() != llvm::omp::OMPD_unknown)
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001196 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1197 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1198 OS << ")";
1199}
1200
1201void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1202 OS << "final(";
1203 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1204 OS << ")";
1205}
1206
1207void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1208 OS << "num_threads(";
1209 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1210 OS << ")";
1211}
1212
1213void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1214 OS << "safelen(";
1215 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1216 OS << ")";
1217}
1218
1219void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1220 OS << "simdlen(";
1221 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1222 OS << ")";
1223}
1224
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00001225void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
1226 OS << "allocator(";
1227 Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
1228 OS << ")";
1229}
1230
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001231void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1232 OS << "collapse(";
1233 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1234 OS << ")";
1235}
1236
1237void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1238 OS << "default("
1239 << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
1240 << ")";
1241}
1242
1243void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1244 OS << "proc_bind("
Johannes Doerfert6c5d1f402019-12-25 18:15:36 -06001245 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind,
1246 unsigned(Node->getProcBindKind()))
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001247 << ")";
1248}
1249
1250void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1251 OS << "unified_address";
1252}
1253
1254void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1255 OMPUnifiedSharedMemoryClause *) {
1256 OS << "unified_shared_memory";
1257}
1258
1259void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1260 OS << "reverse_offload";
1261}
1262
1263void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1264 OMPDynamicAllocatorsClause *) {
1265 OS << "dynamic_allocators";
1266}
1267
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00001268void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1269 OMPAtomicDefaultMemOrderClause *Node) {
1270 OS << "atomic_default_mem_order("
1271 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1272 Node->getAtomicDefaultMemOrderKind())
1273 << ")";
1274}
1275
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001276void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1277 OS << "schedule(";
1278 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1279 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1280 Node->getFirstScheduleModifier());
1281 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1282 OS << ", ";
1283 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1284 Node->getSecondScheduleModifier());
1285 }
1286 OS << ": ";
1287 }
1288 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1289 if (auto *E = Node->getChunkSize()) {
1290 OS << ", ";
1291 E->printPretty(OS, nullptr, Policy);
1292 }
1293 OS << ")";
1294}
1295
1296void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1297 OS << "ordered";
1298 if (auto *Num = Node->getNumForLoops()) {
1299 OS << "(";
1300 Num->printPretty(OS, nullptr, Policy, 0);
1301 OS << ")";
1302 }
1303}
1304
1305void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1306 OS << "nowait";
1307}
1308
1309void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1310 OS << "untied";
1311}
1312
1313void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1314 OS << "nogroup";
1315}
1316
1317void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1318 OS << "mergeable";
1319}
1320
1321void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1322
1323void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1324
1325void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
1326 OS << "update";
1327}
1328
1329void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1330 OS << "capture";
1331}
1332
1333void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1334 OS << "seq_cst";
1335}
1336
1337void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1338 OS << "threads";
1339}
1340
1341void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1342
1343void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1344 OS << "device(";
1345 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1346 OS << ")";
1347}
1348
1349void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1350 OS << "num_teams(";
1351 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1352 OS << ")";
1353}
1354
1355void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1356 OS << "thread_limit(";
1357 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1358 OS << ")";
1359}
1360
1361void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1362 OS << "priority(";
1363 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1364 OS << ")";
1365}
1366
1367void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1368 OS << "grainsize(";
1369 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1370 OS << ")";
1371}
1372
1373void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1374 OS << "num_tasks(";
1375 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1376 OS << ")";
1377}
1378
1379void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1380 OS << "hint(";
1381 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1382 OS << ")";
1383}
1384
1385template<typename T>
1386void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1387 for (typename T::varlist_iterator I = Node->varlist_begin(),
1388 E = Node->varlist_end();
1389 I != E; ++I) {
1390 assert(*I && "Expected non-null Stmt");
1391 OS << (I == Node->varlist_begin() ? StartSym : ',');
1392 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1393 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1394 DRE->printPretty(OS, nullptr, Policy, 0);
1395 else
1396 DRE->getDecl()->printQualifiedName(OS);
1397 } else
1398 (*I)->printPretty(OS, nullptr, Policy, 0);
1399 }
1400}
1401
Alexey Bataeve04483e2019-03-27 14:14:31 +00001402void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
1403 if (Node->varlist_empty())
1404 return;
1405 OS << "allocate";
1406 if (Expr *Allocator = Node->getAllocator()) {
1407 OS << "(";
1408 Allocator->printPretty(OS, nullptr, Policy, 0);
1409 OS << ":";
1410 VisitOMPClauseList(Node, ' ');
1411 } else {
1412 VisitOMPClauseList(Node, '(');
1413 }
1414 OS << ")";
1415}
1416
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001417void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1418 if (!Node->varlist_empty()) {
1419 OS << "private";
1420 VisitOMPClauseList(Node, '(');
1421 OS << ")";
1422 }
1423}
1424
1425void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1426 if (!Node->varlist_empty()) {
1427 OS << "firstprivate";
1428 VisitOMPClauseList(Node, '(');
1429 OS << ")";
1430 }
1431}
1432
1433void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1434 if (!Node->varlist_empty()) {
1435 OS << "lastprivate";
Alexey Bataev93dc40d2019-12-20 11:04:57 -05001436 OpenMPLastprivateModifier LPKind = Node->getKind();
1437 if (LPKind != OMPC_LASTPRIVATE_unknown) {
1438 OS << "("
1439 << getOpenMPSimpleClauseTypeName(OMPC_lastprivate, Node->getKind())
1440 << ":";
1441 }
1442 VisitOMPClauseList(Node, LPKind == OMPC_LASTPRIVATE_unknown ? '(' : ' ');
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001443 OS << ")";
1444 }
1445}
1446
1447void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1448 if (!Node->varlist_empty()) {
1449 OS << "shared";
1450 VisitOMPClauseList(Node, '(');
1451 OS << ")";
1452 }
1453}
1454
1455void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1456 if (!Node->varlist_empty()) {
1457 OS << "reduction(";
1458 NestedNameSpecifier *QualifierLoc =
1459 Node->getQualifierLoc().getNestedNameSpecifier();
1460 OverloadedOperatorKind OOK =
1461 Node->getNameInfo().getName().getCXXOverloadedOperator();
1462 if (QualifierLoc == nullptr && OOK != OO_None) {
1463 // Print reduction identifier in C format
1464 OS << getOperatorSpelling(OOK);
1465 } else {
1466 // Use C++ format
1467 if (QualifierLoc != nullptr)
1468 QualifierLoc->print(OS, Policy);
1469 OS << Node->getNameInfo();
1470 }
1471 OS << ":";
1472 VisitOMPClauseList(Node, ' ');
1473 OS << ")";
1474 }
1475}
1476
1477void OMPClausePrinter::VisitOMPTaskReductionClause(
1478 OMPTaskReductionClause *Node) {
1479 if (!Node->varlist_empty()) {
1480 OS << "task_reduction(";
1481 NestedNameSpecifier *QualifierLoc =
1482 Node->getQualifierLoc().getNestedNameSpecifier();
1483 OverloadedOperatorKind OOK =
1484 Node->getNameInfo().getName().getCXXOverloadedOperator();
1485 if (QualifierLoc == nullptr && OOK != OO_None) {
1486 // Print reduction identifier in C format
1487 OS << getOperatorSpelling(OOK);
1488 } else {
1489 // Use C++ format
1490 if (QualifierLoc != nullptr)
1491 QualifierLoc->print(OS, Policy);
1492 OS << Node->getNameInfo();
1493 }
1494 OS << ":";
1495 VisitOMPClauseList(Node, ' ');
1496 OS << ")";
1497 }
1498}
1499
1500void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1501 if (!Node->varlist_empty()) {
1502 OS << "in_reduction(";
1503 NestedNameSpecifier *QualifierLoc =
1504 Node->getQualifierLoc().getNestedNameSpecifier();
1505 OverloadedOperatorKind OOK =
1506 Node->getNameInfo().getName().getCXXOverloadedOperator();
1507 if (QualifierLoc == nullptr && OOK != OO_None) {
1508 // Print reduction identifier in C format
1509 OS << getOperatorSpelling(OOK);
1510 } else {
1511 // Use C++ format
1512 if (QualifierLoc != nullptr)
1513 QualifierLoc->print(OS, Policy);
1514 OS << Node->getNameInfo();
1515 }
1516 OS << ":";
1517 VisitOMPClauseList(Node, ' ');
1518 OS << ")";
1519 }
1520}
1521
1522void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1523 if (!Node->varlist_empty()) {
1524 OS << "linear";
1525 if (Node->getModifierLoc().isValid()) {
1526 OS << '('
1527 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1528 }
1529 VisitOMPClauseList(Node, '(');
1530 if (Node->getModifierLoc().isValid())
1531 OS << ')';
1532 if (Node->getStep() != nullptr) {
1533 OS << ": ";
1534 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1535 }
1536 OS << ")";
1537 }
1538}
1539
1540void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1541 if (!Node->varlist_empty()) {
1542 OS << "aligned";
1543 VisitOMPClauseList(Node, '(');
1544 if (Node->getAlignment() != nullptr) {
1545 OS << ": ";
1546 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1547 }
1548 OS << ")";
1549 }
1550}
1551
1552void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1553 if (!Node->varlist_empty()) {
1554 OS << "copyin";
1555 VisitOMPClauseList(Node, '(');
1556 OS << ")";
1557 }
1558}
1559
1560void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1561 if (!Node->varlist_empty()) {
1562 OS << "copyprivate";
1563 VisitOMPClauseList(Node, '(');
1564 OS << ")";
1565 }
1566}
1567
1568void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1569 if (!Node->varlist_empty()) {
1570 VisitOMPClauseList(Node, '(');
1571 OS << ")";
1572 }
1573}
1574
1575void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1576 OS << "depend(";
1577 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1578 Node->getDependencyKind());
1579 if (!Node->varlist_empty()) {
1580 OS << " :";
1581 VisitOMPClauseList(Node, ' ');
1582 }
1583 OS << ")";
1584}
1585
1586void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1587 if (!Node->varlist_empty()) {
1588 OS << "map(";
1589 if (Node->getMapType() != OMPC_MAP_unknown) {
Kelvin Lief579432018-12-18 22:18:41 +00001590 for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1591 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1592 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1593 Node->getMapTypeModifier(I));
Michael Kruse4304e9d2019-02-19 16:38:20 +00001594 if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1595 OS << '(';
1596 NestedNameSpecifier *MapperNNS =
1597 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1598 if (MapperNNS)
1599 MapperNNS->print(OS, Policy);
1600 OS << Node->getMapperIdInfo() << ')';
1601 }
Kelvin Lief579432018-12-18 22:18:41 +00001602 OS << ',';
1603 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001604 }
1605 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1606 OS << ':';
1607 }
1608 VisitOMPClauseList(Node, ' ');
1609 OS << ")";
1610 }
1611}
1612
1613void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1614 if (!Node->varlist_empty()) {
1615 OS << "to";
Michael Kruse01f670d2019-02-22 22:29:42 +00001616 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1617 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1618 OS << '(';
1619 OS << "mapper(";
1620 NestedNameSpecifier *MapperNNS =
1621 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1622 if (MapperNNS)
1623 MapperNNS->print(OS, Policy);
1624 OS << MapperId << "):";
1625 VisitOMPClauseList(Node, ' ');
1626 } else {
1627 VisitOMPClauseList(Node, '(');
1628 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001629 OS << ")";
1630 }
1631}
1632
1633void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1634 if (!Node->varlist_empty()) {
1635 OS << "from";
Michael Kruse0336c752019-02-25 20:34:15 +00001636 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1637 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1638 OS << '(';
1639 OS << "mapper(";
1640 NestedNameSpecifier *MapperNNS =
1641 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1642 if (MapperNNS)
1643 MapperNNS->print(OS, Policy);
1644 OS << MapperId << "):";
1645 VisitOMPClauseList(Node, ' ');
1646 } else {
1647 VisitOMPClauseList(Node, '(');
1648 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001649 OS << ")";
1650 }
1651}
1652
1653void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1654 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1655 OMPC_dist_schedule, Node->getDistScheduleKind());
1656 if (auto *E = Node->getChunkSize()) {
1657 OS << ", ";
1658 E->printPretty(OS, nullptr, Policy);
1659 }
1660 OS << ")";
1661}
1662
1663void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1664 OS << "defaultmap(";
1665 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1666 Node->getDefaultmapModifier());
1667 OS << ": ";
1668 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1669 Node->getDefaultmapKind());
1670 OS << ")";
1671}
1672
1673void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1674 if (!Node->varlist_empty()) {
1675 OS << "use_device_ptr";
1676 VisitOMPClauseList(Node, '(');
1677 OS << ")";
1678 }
1679}
1680
1681void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1682 if (!Node->varlist_empty()) {
1683 OS << "is_device_ptr";
1684 VisitOMPClauseList(Node, '(');
1685 OS << ")";
1686 }
1687}
1688
Alexey Bataevb6e70842019-12-16 15:54:17 -05001689void OMPClausePrinter::VisitOMPNontemporalClause(OMPNontemporalClause *Node) {
1690 if (!Node->varlist_empty()) {
1691 OS << "nontemporal";
1692 VisitOMPClauseList(Node, '(');
1693 OS << ")";
1694 }
1695}
Alexey Bataevcb8e6912020-01-31 16:09:26 -05001696
1697void OMPClausePrinter::VisitOMPOrderClause(OMPOrderClause *Node) {
1698 OS << "order(" << getOpenMPSimpleClauseTypeName(OMPC_order, Node->getKind())
1699 << ")";
1700}