blob: 65ecd16faee0292b8b85cc31bfb80d081c47cfa2 [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"
Reid Kleckner26d254f2020-03-11 20:22:14 -070015#include "clang/AST/Attr.h"
Eugene Zelenkod1b2d222017-11-29 23:27:36 +000016#include "clang/AST/Decl.h"
Patrick Lyster074c3ae22018-10-18 14:28:23 +000017#include "clang/AST/DeclOpenMP.h"
Eugene Zelenkod1b2d222017-11-29 23:27:36 +000018#include "clang/Basic/LLVM.h"
Alexey Bataev93dc40d2019-12-20 11:04:57 -050019#include "clang/Basic/OpenMPKinds.h"
Eugene Zelenkod1b2d222017-11-29 23:27:36 +000020#include "llvm/ADT/SmallPtrSet.h"
21#include "llvm/Support/Casting.h"
22#include "llvm/Support/ErrorHandling.h"
23#include <algorithm>
24#include <cassert>
James Y Knightb8bfd962015-10-02 13:41:04 +000025
26using namespace clang;
Johannes Doerfertb2932242020-03-25 19:33:48 -050027using namespace llvm;
28using namespace omp;
James Y Knightb8bfd962015-10-02 13:41:04 +000029
30OMPClause::child_range OMPClause::children() {
31 switch (getClauseKind()) {
32 default:
33 break;
34#define OPENMP_CLAUSE(Name, Class) \
35 case OMPC_##Name: \
36 return static_cast<Class *>(this)->children();
37#include "clang/Basic/OpenMPKinds.def"
38 }
39 llvm_unreachable("unknown OMPClause");
40}
41
Alexey Bataevc2c21ef2019-07-11 14:54:17 +000042OMPClause::child_range OMPClause::used_children() {
43 switch (getClauseKind()) {
44#define OPENMP_CLAUSE(Name, Class) \
45 case OMPC_##Name: \
46 return static_cast<Class *>(this)->used_children();
47#include "clang/Basic/OpenMPKinds.def"
48 case OMPC_threadprivate:
49 case OMPC_uniform:
Alexey Bataev729e2422019-08-23 16:11:14 +000050 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +000051 case OMPC_match:
Alexey Bataevc2c21ef2019-07-11 14:54:17 +000052 case OMPC_unknown:
53 break;
54 }
55 llvm_unreachable("unknown OMPClause");
56}
57
Alexey Bataev3392d762016-02-16 11:18:12 +000058OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
59 auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
60 return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr;
61}
62
63const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
64 switch (C->getClauseKind()) {
65 case OMPC_schedule:
66 return static_cast<const OMPScheduleClause *>(C);
67 case OMPC_dist_schedule:
68 return static_cast<const OMPDistScheduleClause *>(C);
Alexey Bataev417089f2016-02-17 13:19:37 +000069 case OMPC_firstprivate:
70 return static_cast<const OMPFirstprivateClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +000071 case OMPC_lastprivate:
72 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +000073 case OMPC_reduction:
74 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +000075 case OMPC_task_reduction:
76 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +000077 case OMPC_in_reduction:
78 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +000079 case OMPC_linear:
80 return static_cast<const OMPLinearClause *>(C);
Arpith Chacko Jacobfe4890a2017-01-18 20:40:48 +000081 case OMPC_if:
82 return static_cast<const OMPIfClause *>(C);
Arpith Chacko Jacob33c849a2017-01-25 00:57:16 +000083 case OMPC_num_threads:
84 return static_cast<const OMPNumThreadsClause *>(C);
Arpith Chacko Jacobbc126342017-01-25 11:28:18 +000085 case OMPC_num_teams:
86 return static_cast<const OMPNumTeamsClause *>(C);
Arpith Chacko Jacob7ecc0b72017-01-25 11:44:35 +000087 case OMPC_thread_limit:
88 return static_cast<const OMPThreadLimitClause *>(C);
Alexey Bataev931e19b2017-10-02 16:32:39 +000089 case OMPC_device:
90 return static_cast<const OMPDeviceClause *>(C);
Alexey Bataevb9c55e22019-10-14 19:29:52 +000091 case OMPC_grainsize:
92 return static_cast<const OMPGrainsizeClause *>(C);
Alexey Bataevd88c7de2019-10-14 20:44:34 +000093 case OMPC_num_tasks:
94 return static_cast<const OMPNumTasksClause *>(C);
Alexey Bataev3a842ec2019-10-15 19:37:05 +000095 case OMPC_final:
96 return static_cast<const OMPFinalClause *>(C);
Alexey Bataev31ba4762019-10-16 18:09:37 +000097 case OMPC_priority:
98 return static_cast<const OMPPriorityClause *>(C);
Alexey Bataev3392d762016-02-16 11:18:12 +000099 case OMPC_default:
100 case OMPC_proc_bind:
Alexey Bataev3392d762016-02-16 11:18:12 +0000101 case OMPC_safelen:
102 case OMPC_simdlen:
Alexey Bataev9cc10fc2019-03-12 18:52:33 +0000103 case OMPC_allocator:
Alexey Bataeve04483e2019-03-27 14:14:31 +0000104 case OMPC_allocate:
Alexey Bataev3392d762016-02-16 11:18:12 +0000105 case OMPC_collapse:
106 case OMPC_private:
Alexey Bataev005248a2016-02-25 05:25:57 +0000107 case OMPC_shared:
Alexey Bataev005248a2016-02-25 05:25:57 +0000108 case OMPC_aligned:
109 case OMPC_copyin:
110 case OMPC_copyprivate:
111 case OMPC_ordered:
112 case OMPC_nowait:
113 case OMPC_untied:
114 case OMPC_mergeable:
115 case OMPC_threadprivate:
116 case OMPC_flush:
Alexey Bataevc112e942020-02-28 09:52:15 -0500117 case OMPC_depobj:
Alexey Bataev005248a2016-02-25 05:25:57 +0000118 case OMPC_read:
119 case OMPC_write:
120 case OMPC_update:
121 case OMPC_capture:
122 case OMPC_seq_cst:
Alexey Bataevea9166b2020-02-06 16:30:23 -0500123 case OMPC_acq_rel:
Alexey Bataev04a830f2020-02-10 14:30:39 -0500124 case OMPC_acquire:
Alexey Bataev95598342020-02-10 15:49:05 -0500125 case OMPC_release:
Alexey Bataev9a8defc2020-02-11 11:10:43 -0500126 case OMPC_relaxed:
Alexey Bataev005248a2016-02-25 05:25:57 +0000127 case OMPC_depend:
Alexey Bataev005248a2016-02-25 05:25:57 +0000128 case OMPC_threads:
129 case OMPC_simd:
130 case OMPC_map:
Alexey Bataev005248a2016-02-25 05:25:57 +0000131 case OMPC_nogroup:
Alexey Bataev005248a2016-02-25 05:25:57 +0000132 case OMPC_hint:
133 case OMPC_defaultmap:
134 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000135 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000136 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000137 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000138 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000139 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000140 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000141 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000142 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000143 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000144 case OMPC_atomic_default_mem_order:
Alexey Bataev729e2422019-08-23 16:11:14 +0000145 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +0000146 case OMPC_match:
Alexey Bataevb6e70842019-12-16 15:54:17 -0500147 case OMPC_nontemporal:
Alexey Bataevcb8e6912020-01-31 16:09:26 -0500148 case OMPC_order:
Alexey Bataev375437a2020-03-02 14:21:20 -0500149 case OMPC_destroy:
Alexey Bataev0f0564b2020-03-17 09:17:42 -0400150 case OMPC_detach:
Alexey Bataev06dea732020-03-20 09:41:22 -0400151 case OMPC_inclusive:
Alexey Bataev63828a32020-03-23 10:41:08 -0400152 case OMPC_exclusive:
Alexey Bataev005248a2016-02-25 05:25:57 +0000153 break;
154 }
155
156 return nullptr;
157}
158
159OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
160 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
161 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
162}
163
164const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
165 switch (C->getClauseKind()) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000166 case OMPC_lastprivate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000167 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000168 case OMPC_reduction:
169 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +0000170 case OMPC_task_reduction:
171 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000172 case OMPC_in_reduction:
173 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000174 case OMPC_linear:
175 return static_cast<const OMPLinearClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000176 case OMPC_schedule:
177 case OMPC_dist_schedule:
178 case OMPC_firstprivate:
179 case OMPC_default:
180 case OMPC_proc_bind:
181 case OMPC_if:
182 case OMPC_final:
183 case OMPC_num_threads:
184 case OMPC_safelen:
185 case OMPC_simdlen:
Alexey Bataev9cc10fc2019-03-12 18:52:33 +0000186 case OMPC_allocator:
Alexey Bataeve04483e2019-03-27 14:14:31 +0000187 case OMPC_allocate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000188 case OMPC_collapse:
189 case OMPC_private:
Alexey Bataev3392d762016-02-16 11:18:12 +0000190 case OMPC_shared:
Alexey Bataev3392d762016-02-16 11:18:12 +0000191 case OMPC_aligned:
192 case OMPC_copyin:
193 case OMPC_copyprivate:
194 case OMPC_ordered:
195 case OMPC_nowait:
196 case OMPC_untied:
197 case OMPC_mergeable:
198 case OMPC_threadprivate:
199 case OMPC_flush:
Alexey Bataevc112e942020-02-28 09:52:15 -0500200 case OMPC_depobj:
Alexey Bataev3392d762016-02-16 11:18:12 +0000201 case OMPC_read:
202 case OMPC_write:
203 case OMPC_update:
204 case OMPC_capture:
205 case OMPC_seq_cst:
Alexey Bataevea9166b2020-02-06 16:30:23 -0500206 case OMPC_acq_rel:
Alexey Bataev04a830f2020-02-10 14:30:39 -0500207 case OMPC_acquire:
Alexey Bataev95598342020-02-10 15:49:05 -0500208 case OMPC_release:
Alexey Bataev9a8defc2020-02-11 11:10:43 -0500209 case OMPC_relaxed:
Alexey Bataev3392d762016-02-16 11:18:12 +0000210 case OMPC_depend:
211 case OMPC_device:
212 case OMPC_threads:
213 case OMPC_simd:
214 case OMPC_map:
215 case OMPC_num_teams:
216 case OMPC_thread_limit:
217 case OMPC_priority:
218 case OMPC_grainsize:
219 case OMPC_nogroup:
220 case OMPC_num_tasks:
221 case OMPC_hint:
222 case OMPC_defaultmap:
223 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000224 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000225 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000226 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000227 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000228 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000229 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000230 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000231 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000232 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000233 case OMPC_atomic_default_mem_order:
Alexey Bataev729e2422019-08-23 16:11:14 +0000234 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +0000235 case OMPC_match:
Alexey Bataevb6e70842019-12-16 15:54:17 -0500236 case OMPC_nontemporal:
Alexey Bataevcb8e6912020-01-31 16:09:26 -0500237 case OMPC_order:
Alexey Bataev375437a2020-03-02 14:21:20 -0500238 case OMPC_destroy:
Alexey Bataev0f0564b2020-03-17 09:17:42 -0400239 case OMPC_detach:
Alexey Bataev06dea732020-03-20 09:41:22 -0400240 case OMPC_inclusive:
Alexey Bataev63828a32020-03-23 10:41:08 -0400241 case OMPC_exclusive:
Alexey Bataev3392d762016-02-16 11:18:12 +0000242 break;
243 }
244
245 return nullptr;
246}
247
Alexey Bataev655cb4a2019-07-16 14:51:46 +0000248/// Gets the address of the original, non-captured, expression used in the
249/// clause as the preinitializer.
250static Stmt **getAddrOfExprAsWritten(Stmt *S) {
251 if (!S)
252 return nullptr;
253 if (auto *DS = dyn_cast<DeclStmt>(S)) {
254 assert(DS->isSingleDecl() && "Only single expression must be captured.");
255 if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
256 return OED->getInitAddress();
257 }
258 return nullptr;
259}
260
261OMPClause::child_range OMPIfClause::used_children() {
262 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
263 return child_range(C, C + 1);
264 return child_range(&Condition, &Condition + 1);
265}
266
Alexey Bataevb9c55e22019-10-14 19:29:52 +0000267OMPClause::child_range OMPGrainsizeClause::used_children() {
268 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
269 return child_range(C, C + 1);
270 return child_range(&Grainsize, &Grainsize + 1);
271}
272
Alexey Bataevd88c7de2019-10-14 20:44:34 +0000273OMPClause::child_range OMPNumTasksClause::used_children() {
274 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
275 return child_range(C, C + 1);
276 return child_range(&NumTasks, &NumTasks + 1);
277}
278
Alexey Bataev3a842ec2019-10-15 19:37:05 +0000279OMPClause::child_range OMPFinalClause::used_children() {
280 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
281 return child_range(C, C + 1);
282 return child_range(&Condition, &Condition + 1);
283}
284
Alexey Bataev31ba4762019-10-16 18:09:37 +0000285OMPClause::child_range OMPPriorityClause::used_children() {
286 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
287 return child_range(C, C + 1);
288 return child_range(&Priority, &Priority + 1);
289}
290
Alexey Bataevf138fda2018-08-13 19:04:24 +0000291OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
292 unsigned NumLoops,
293 SourceLocation StartLoc,
294 SourceLocation LParenLoc,
295 SourceLocation EndLoc) {
296 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
297 auto *Clause =
298 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
299 for (unsigned I = 0; I < NumLoops; ++I) {
300 Clause->setLoopNumIterations(I, nullptr);
301 Clause->setLoopCounter(I, nullptr);
302 }
303 return Clause;
304}
305
306OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
307 unsigned NumLoops) {
308 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
309 auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
310 for (unsigned I = 0; I < NumLoops; ++I) {
311 Clause->setLoopNumIterations(I, nullptr);
312 Clause->setLoopCounter(I, nullptr);
313 }
314 return Clause;
315}
316
317void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
318 Expr *NumIterations) {
319 assert(NumLoop < NumberOfLoops && "out of loops number.");
320 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
321}
322
323ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
324 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
325}
326
327void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
328 assert(NumLoop < NumberOfLoops && "out of loops number.");
329 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
330}
331
Mike Rice0ed46662018-09-20 17:19:41 +0000332Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000333 assert(NumLoop < NumberOfLoops && "out of loops number.");
334 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
335}
336
Mike Rice0ed46662018-09-20 17:19:41 +0000337const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000338 assert(NumLoop < NumberOfLoops && "out of loops number.");
339 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
340}
341
Alexey Bataev82f7c202020-03-03 13:22:35 -0500342OMPUpdateClause *OMPUpdateClause::Create(const ASTContext &C,
343 SourceLocation StartLoc,
344 SourceLocation EndLoc) {
345 return new (C) OMPUpdateClause(StartLoc, EndLoc, /*IsExtended=*/false);
346}
347
348OMPUpdateClause *
349OMPUpdateClause::Create(const ASTContext &C, SourceLocation StartLoc,
350 SourceLocation LParenLoc, SourceLocation ArgumentLoc,
351 OpenMPDependClauseKind DK, SourceLocation EndLoc) {
352 void *Mem =
353 C.Allocate(totalSizeToAlloc<SourceLocation, OpenMPDependClauseKind>(2, 1),
354 alignof(OMPUpdateClause));
355 auto *Clause =
356 new (Mem) OMPUpdateClause(StartLoc, EndLoc, /*IsExtended=*/true);
357 Clause->setLParenLoc(LParenLoc);
358 Clause->setArgumentLoc(ArgumentLoc);
359 Clause->setDependencyKind(DK);
360 return Clause;
361}
362
363OMPUpdateClause *OMPUpdateClause::CreateEmpty(const ASTContext &C,
364 bool IsExtended) {
365 if (!IsExtended)
366 return new (C) OMPUpdateClause(/*IsExtended=*/false);
367 void *Mem =
368 C.Allocate(totalSizeToAlloc<SourceLocation, OpenMPDependClauseKind>(2, 1),
369 alignof(OMPUpdateClause));
370 auto *Clause = new (Mem) OMPUpdateClause(/*IsExtended=*/true);
371 Clause->IsExtended = true;
372 return Clause;
373}
374
James Y Knightb8bfd962015-10-02 13:41:04 +0000375void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
376 assert(VL.size() == varlist_size() &&
377 "Number of private copies is not the same as the preallocated buffer");
378 std::copy(VL.begin(), VL.end(), varlist_end());
379}
380
381OMPPrivateClause *
382OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
383 SourceLocation LParenLoc, SourceLocation EndLoc,
384 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
385 // Allocate space for private variables and initializer expressions.
James Y Knight374fd202016-01-01 00:38:24 +0000386 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000387 OMPPrivateClause *Clause =
388 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
389 Clause->setVarRefs(VL);
390 Clause->setPrivateCopies(PrivateVL);
391 return Clause;
392}
393
394OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
395 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000396 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000397 return new (Mem) OMPPrivateClause(N);
398}
399
400void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
401 assert(VL.size() == varlist_size() &&
402 "Number of private copies is not the same as the preallocated buffer");
403 std::copy(VL.begin(), VL.end(), varlist_end());
404}
405
406void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
407 assert(VL.size() == varlist_size() &&
408 "Number of inits is not the same as the preallocated buffer");
409 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
410}
411
412OMPFirstprivateClause *
413OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
414 SourceLocation LParenLoc, SourceLocation EndLoc,
415 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
Alexey Bataev417089f2016-02-17 13:19:37 +0000416 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
James Y Knight374fd202016-01-01 00:38:24 +0000417 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000418 OMPFirstprivateClause *Clause =
419 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
420 Clause->setVarRefs(VL);
421 Clause->setPrivateCopies(PrivateVL);
422 Clause->setInits(InitVL);
Alexey Bataev417089f2016-02-17 13:19:37 +0000423 Clause->setPreInitStmt(PreInit);
James Y Knightb8bfd962015-10-02 13:41:04 +0000424 return Clause;
425}
426
427OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
428 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000429 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000430 return new (Mem) OMPFirstprivateClause(N);
431}
432
433void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
434 assert(PrivateCopies.size() == varlist_size() &&
435 "Number of private copies is not the same as the preallocated buffer");
436 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
437}
438
439void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
440 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
441 "not the same as the "
442 "preallocated buffer");
443 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
444}
445
446void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
447 assert(DstExprs.size() == varlist_size() && "Number of destination "
448 "expressions is not the same as "
449 "the preallocated buffer");
450 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
451}
452
453void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
454 assert(AssignmentOps.size() == varlist_size() &&
455 "Number of assignment expressions is not the same as the preallocated "
456 "buffer");
457 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
458 getDestinationExprs().end());
459}
460
461OMPLastprivateClause *OMPLastprivateClause::Create(
462 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
463 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
Alexey Bataev93dc40d2019-12-20 11:04:57 -0500464 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
465 OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
466 SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000467 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
Alexey Bataev93dc40d2019-12-20 11:04:57 -0500468 OMPLastprivateClause *Clause = new (Mem) OMPLastprivateClause(
469 StartLoc, LParenLoc, EndLoc, LPKind, LPKindLoc, ColonLoc, VL.size());
James Y Knightb8bfd962015-10-02 13:41:04 +0000470 Clause->setVarRefs(VL);
471 Clause->setSourceExprs(SrcExprs);
472 Clause->setDestinationExprs(DstExprs);
473 Clause->setAssignmentOps(AssignmentOps);
Alexey Bataev005248a2016-02-25 05:25:57 +0000474 Clause->setPreInitStmt(PreInit);
475 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000476 return Clause;
477}
478
479OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
480 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000481 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000482 return new (Mem) OMPLastprivateClause(N);
483}
484
485OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
486 SourceLocation StartLoc,
487 SourceLocation LParenLoc,
488 SourceLocation EndLoc,
489 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000490 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000491 OMPSharedClause *Clause =
492 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
493 Clause->setVarRefs(VL);
494 return Clause;
495}
496
497OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000498 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000499 return new (Mem) OMPSharedClause(N);
500}
501
502void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
503 assert(PL.size() == varlist_size() &&
504 "Number of privates is not the same as the preallocated buffer");
505 std::copy(PL.begin(), PL.end(), varlist_end());
506}
507
508void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
509 assert(IL.size() == varlist_size() &&
510 "Number of inits is not the same as the preallocated buffer");
511 std::copy(IL.begin(), IL.end(), getPrivates().end());
512}
513
514void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
515 assert(UL.size() == varlist_size() &&
516 "Number of updates is not the same as the preallocated buffer");
517 std::copy(UL.begin(), UL.end(), getInits().end());
518}
519
520void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
521 assert(FL.size() == varlist_size() &&
522 "Number of final updates is not the same as the preallocated buffer");
523 std::copy(FL.begin(), FL.end(), getUpdates().end());
524}
525
Alexey Bataev195ae902019-08-08 13:42:45 +0000526void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) {
527 assert(
528 UE.size() == varlist_size() + 1 &&
529 "Number of used expressions is not the same as the preallocated buffer");
530 std::copy(UE.begin(), UE.end(), getFinals().end() + 2);
531}
532
James Y Knightb8bfd962015-10-02 13:41:04 +0000533OMPLinearClause *OMPLinearClause::Create(
534 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
535 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
536 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
Alexey Bataev78849fb2016-03-09 09:49:00 +0000537 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
538 Stmt *PreInit, Expr *PostUpdate) {
Alexey Bataev195ae902019-08-08 13:42:45 +0000539 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
540 // (Step and CalcStep), list of used expression + step.
541 void *Mem =
542 C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000543 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
544 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
545 Clause->setVarRefs(VL);
546 Clause->setPrivates(PL);
547 Clause->setInits(IL);
548 // Fill update and final expressions with zeroes, they are provided later,
549 // after the directive construction.
550 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
551 nullptr);
552 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
553 nullptr);
Alexey Bataev195ae902019-08-08 13:42:45 +0000554 std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(),
555 nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000556 Clause->setStep(Step);
557 Clause->setCalcStep(CalcStep);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000558 Clause->setPreInitStmt(PreInit);
559 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000560 return Clause;
561}
562
563OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
564 unsigned NumVars) {
Alexey Bataev195ae902019-08-08 13:42:45 +0000565 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
566 // (Step and CalcStep), list of used expression + step.
567 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars +1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000568 return new (Mem) OMPLinearClause(NumVars);
569}
570
Alexey Bataev195ae902019-08-08 13:42:45 +0000571OMPClause::child_range OMPLinearClause::used_children() {
572 // Range includes only non-nullptr elements.
573 return child_range(
574 reinterpret_cast<Stmt **>(getUsedExprs().begin()),
575 reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr)));
576}
577
James Y Knightb8bfd962015-10-02 13:41:04 +0000578OMPAlignedClause *
579OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
580 SourceLocation LParenLoc, SourceLocation ColonLoc,
581 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
James Y Knight374fd202016-01-01 00:38:24 +0000582 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000583 OMPAlignedClause *Clause = new (Mem)
584 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
585 Clause->setVarRefs(VL);
586 Clause->setAlignment(A);
587 return Clause;
588}
589
590OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
591 unsigned NumVars) {
James Y Knight374fd202016-01-01 00:38:24 +0000592 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000593 return new (Mem) OMPAlignedClause(NumVars);
594}
595
596void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
597 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
598 "not the same as the "
599 "preallocated buffer");
600 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
601}
602
603void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
604 assert(DstExprs.size() == varlist_size() && "Number of destination "
605 "expressions is not the same as "
606 "the preallocated buffer");
607 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
608}
609
610void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
611 assert(AssignmentOps.size() == varlist_size() &&
612 "Number of assignment expressions is not the same as the preallocated "
613 "buffer");
614 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
615 getDestinationExprs().end());
616}
617
618OMPCopyinClause *OMPCopyinClause::Create(
619 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
620 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
621 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000622 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000623 OMPCopyinClause *Clause =
624 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
625 Clause->setVarRefs(VL);
626 Clause->setSourceExprs(SrcExprs);
627 Clause->setDestinationExprs(DstExprs);
628 Clause->setAssignmentOps(AssignmentOps);
629 return Clause;
630}
631
632OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000633 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000634 return new (Mem) OMPCopyinClause(N);
635}
636
637void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
638 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
639 "not the same as the "
640 "preallocated buffer");
641 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
642}
643
644void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
645 assert(DstExprs.size() == varlist_size() && "Number of destination "
646 "expressions is not the same as "
647 "the preallocated buffer");
648 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
649}
650
651void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
652 assert(AssignmentOps.size() == varlist_size() &&
653 "Number of assignment expressions is not the same as the preallocated "
654 "buffer");
655 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
656 getDestinationExprs().end());
657}
658
659OMPCopyprivateClause *OMPCopyprivateClause::Create(
660 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
661 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
662 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000663 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000664 OMPCopyprivateClause *Clause =
665 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
666 Clause->setVarRefs(VL);
667 Clause->setSourceExprs(SrcExprs);
668 Clause->setDestinationExprs(DstExprs);
669 Clause->setAssignmentOps(AssignmentOps);
670 return Clause;
671}
672
673OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
674 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000675 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000676 return new (Mem) OMPCopyprivateClause(N);
677}
678
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000679void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
680 assert(Privates.size() == varlist_size() &&
681 "Number of private copies is not the same as the preallocated buffer");
682 std::copy(Privates.begin(), Privates.end(), varlist_end());
683}
684
James Y Knightb8bfd962015-10-02 13:41:04 +0000685void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
686 assert(
687 LHSExprs.size() == varlist_size() &&
688 "Number of LHS expressions is not the same as the preallocated buffer");
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000689 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
James Y Knightb8bfd962015-10-02 13:41:04 +0000690}
691
692void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
693 assert(
694 RHSExprs.size() == varlist_size() &&
695 "Number of RHS expressions is not the same as the preallocated buffer");
696 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
697}
698
699void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
700 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
701 "expressions is not the same "
702 "as the preallocated buffer");
703 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
704}
705
706OMPReductionClause *OMPReductionClause::Create(
707 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
Alexey Bataev1236eb62020-03-23 17:30:38 -0400708 SourceLocation ModifierLoc, SourceLocation EndLoc, SourceLocation ColonLoc,
709 OpenMPReductionClauseModifier Modifier, ArrayRef<Expr *> VL,
James Y Knightb8bfd962015-10-02 13:41:04 +0000710 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000711 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev61205072016-03-02 04:57:40 +0000712 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
713 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000714 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
Alexey Bataev1236eb62020-03-23 17:30:38 -0400715 auto *Clause = new (Mem)
716 OMPReductionClause(StartLoc, LParenLoc, ModifierLoc, EndLoc, ColonLoc,
717 Modifier, VL.size(), QualifierLoc, NameInfo);
James Y Knightb8bfd962015-10-02 13:41:04 +0000718 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000719 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000720 Clause->setLHSExprs(LHSExprs);
721 Clause->setRHSExprs(RHSExprs);
722 Clause->setReductionOps(ReductionOps);
Alexey Bataev61205072016-03-02 04:57:40 +0000723 Clause->setPreInitStmt(PreInit);
724 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000725 return Clause;
726}
727
728OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
729 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000730 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000731 return new (Mem) OMPReductionClause(N);
732}
733
Alexey Bataev169d96a2017-07-18 20:17:46 +0000734void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
735 assert(Privates.size() == varlist_size() &&
736 "Number of private copies is not the same as the preallocated buffer");
737 std::copy(Privates.begin(), Privates.end(), varlist_end());
738}
739
740void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
741 assert(
742 LHSExprs.size() == varlist_size() &&
743 "Number of LHS expressions is not the same as the preallocated buffer");
744 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
745}
746
747void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
748 assert(
749 RHSExprs.size() == varlist_size() &&
750 "Number of RHS expressions is not the same as the preallocated buffer");
751 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
752}
753
754void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
755 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
756 "expressions is not the same "
757 "as the preallocated buffer");
758 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
759}
760
761OMPTaskReductionClause *OMPTaskReductionClause::Create(
762 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
763 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
764 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
765 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
766 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
767 Expr *PostUpdate) {
768 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
769 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
770 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
771 Clause->setVarRefs(VL);
772 Clause->setPrivates(Privates);
773 Clause->setLHSExprs(LHSExprs);
774 Clause->setRHSExprs(RHSExprs);
775 Clause->setReductionOps(ReductionOps);
776 Clause->setPreInitStmt(PreInit);
777 Clause->setPostUpdateExpr(PostUpdate);
778 return Clause;
779}
780
781OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
782 unsigned N) {
783 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
784 return new (Mem) OMPTaskReductionClause(N);
785}
786
Alexey Bataevfa312f32017-07-21 18:48:21 +0000787void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
788 assert(Privates.size() == varlist_size() &&
789 "Number of private copies is not the same as the preallocated buffer");
790 std::copy(Privates.begin(), Privates.end(), varlist_end());
791}
792
793void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
794 assert(
795 LHSExprs.size() == varlist_size() &&
796 "Number of LHS expressions is not the same as the preallocated buffer");
797 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
798}
799
800void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
801 assert(
802 RHSExprs.size() == varlist_size() &&
803 "Number of RHS expressions is not the same as the preallocated buffer");
804 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
805}
806
807void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
808 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
809 "expressions is not the same "
810 "as the preallocated buffer");
811 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
812}
813
Alexey Bataev88202be2017-07-27 13:20:36 +0000814void OMPInReductionClause::setTaskgroupDescriptors(
815 ArrayRef<Expr *> TaskgroupDescriptors) {
816 assert(TaskgroupDescriptors.size() == varlist_size() &&
817 "Number of in reduction descriptors is not the same as the "
818 "preallocated buffer");
819 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
820 getReductionOps().end());
821}
822
Alexey Bataevfa312f32017-07-21 18:48:21 +0000823OMPInReductionClause *OMPInReductionClause::Create(
824 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
825 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
826 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
827 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev88202be2017-07-27 13:20:36 +0000828 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
829 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
830 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000831 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
832 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
833 Clause->setVarRefs(VL);
834 Clause->setPrivates(Privates);
835 Clause->setLHSExprs(LHSExprs);
836 Clause->setRHSExprs(RHSExprs);
837 Clause->setReductionOps(ReductionOps);
Alexey Bataev88202be2017-07-27 13:20:36 +0000838 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000839 Clause->setPreInitStmt(PreInit);
840 Clause->setPostUpdateExpr(PostUpdate);
841 return Clause;
842}
843
844OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
845 unsigned N) {
Alexey Bataev88202be2017-07-27 13:20:36 +0000846 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000847 return new (Mem) OMPInReductionClause(N);
848}
849
Alexey Bataeve04483e2019-03-27 14:14:31 +0000850OMPAllocateClause *
851OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc,
852 SourceLocation LParenLoc, Expr *Allocator,
853 SourceLocation ColonLoc, SourceLocation EndLoc,
854 ArrayRef<Expr *> VL) {
855 // Allocate space for private variables and initializer expressions.
856 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
857 auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
858 ColonLoc, EndLoc, VL.size());
859 Clause->setVarRefs(VL);
860 return Clause;
861}
862
863OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
864 unsigned N) {
865 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
866 return new (Mem) OMPAllocateClause(N);
867}
868
James Y Knightb8bfd962015-10-02 13:41:04 +0000869OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
870 SourceLocation StartLoc,
871 SourceLocation LParenLoc,
872 SourceLocation EndLoc,
873 ArrayRef<Expr *> VL) {
Alexey Bataev8b427062016-05-25 12:36:08 +0000874 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000875 OMPFlushClause *Clause =
876 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
877 Clause->setVarRefs(VL);
878 return Clause;
879}
880
881OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000882 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000883 return new (Mem) OMPFlushClause(N);
884}
885
Alexey Bataevc112e942020-02-28 09:52:15 -0500886OMPDepobjClause *OMPDepobjClause::Create(const ASTContext &C,
887 SourceLocation StartLoc,
888 SourceLocation LParenLoc,
889 SourceLocation RParenLoc,
890 Expr *Depobj) {
891 auto *Clause = new (C) OMPDepobjClause(StartLoc, LParenLoc, RParenLoc);
892 Clause->setDepobj(Depobj);
893 return Clause;
894}
895
896OMPDepobjClause *OMPDepobjClause::CreateEmpty(const ASTContext &C) {
897 return new (C) OMPDepobjClause();
898}
899
Alexey Bataevf138fda2018-08-13 19:04:24 +0000900OMPDependClause *
901OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
902 SourceLocation LParenLoc, SourceLocation EndLoc,
903 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
904 SourceLocation ColonLoc, ArrayRef<Expr *> VL,
905 unsigned NumLoops) {
906 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
907 OMPDependClause *Clause = new (Mem)
908 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000909 Clause->setVarRefs(VL);
910 Clause->setDependencyKind(DepKind);
911 Clause->setDependencyLoc(DepLoc);
912 Clause->setColonLoc(ColonLoc);
Alexey Bataevf138fda2018-08-13 19:04:24 +0000913 for (unsigned I = 0 ; I < NumLoops; ++I)
914 Clause->setLoopData(I, nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000915 return Clause;
916}
917
Alexey Bataevf138fda2018-08-13 19:04:24 +0000918OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
919 unsigned NumLoops) {
920 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
921 return new (Mem) OMPDependClause(N, NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000922}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000923
Alexey Bataevf138fda2018-08-13 19:04:24 +0000924void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
925 assert((getDependencyKind() == OMPC_DEPEND_sink ||
926 getDependencyKind() == OMPC_DEPEND_source) &&
927 NumLoop < NumLoops &&
928 "Expected sink or source depend + loop index must be less number of "
929 "loops.");
930 auto It = std::next(getVarRefs().end(), NumLoop);
931 *It = Cnt;
Alexey Bataev8b427062016-05-25 12:36:08 +0000932}
933
Alexey Bataevf138fda2018-08-13 19:04:24 +0000934Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
935 assert((getDependencyKind() == OMPC_DEPEND_sink ||
936 getDependencyKind() == OMPC_DEPEND_source) &&
937 NumLoop < NumLoops &&
938 "Expected sink or source depend + loop index must be less number of "
939 "loops.");
940 auto It = std::next(getVarRefs().end(), NumLoop);
941 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000942}
943
Alexey Bataevf138fda2018-08-13 19:04:24 +0000944const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
945 assert((getDependencyKind() == OMPC_DEPEND_sink ||
946 getDependencyKind() == OMPC_DEPEND_source) &&
947 NumLoop < NumLoops &&
948 "Expected sink or source depend + loop index must be less number of "
949 "loops.");
950 auto It = std::next(getVarRefs().end(), NumLoop);
951 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000952}
953
Samuel Antao90927002016-04-26 14:54:23 +0000954unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
955 MappableExprComponentListsRef ComponentLists) {
956 unsigned TotalNum = 0u;
957 for (auto &C : ComponentLists)
958 TotalNum += C.size();
959 return TotalNum;
960}
961
962unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
Alexey Bataeve3727102018-04-18 15:57:46 +0000963 ArrayRef<const ValueDecl *> Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000964 unsigned TotalNum = 0u;
965 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
Alexey Bataeve3727102018-04-18 15:57:46 +0000966 for (const ValueDecl *D : Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000967 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
968 if (Cache.count(VD))
969 continue;
970 ++TotalNum;
971 Cache.insert(VD);
972 }
973 return TotalNum;
974}
975
Michael Kruse4304e9d2019-02-19 16:38:20 +0000976OMPMapClause *OMPMapClause::Create(
977 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
978 ArrayRef<ValueDecl *> Declarations,
979 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
980 ArrayRef<OpenMPMapModifierKind> MapModifiers,
981 ArrayRef<SourceLocation> MapModifiersLoc,
982 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
983 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
984 OMPMappableExprListSizeTy Sizes;
985 Sizes.NumVars = Vars.size();
986 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
987 Sizes.NumComponentLists = ComponentLists.size();
988 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao90927002016-04-26 14:54:23 +0000989
990 // We need to allocate:
Michael Kruse4304e9d2019-02-19 16:38:20 +0000991 // 2 x NumVars x Expr* - we have an original list expression and an associated
992 // user-defined mapper for each clause list entry.
Samuel Antao90927002016-04-26 14:54:23 +0000993 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
994 // with each component list.
995 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
996 // number of lists for each unique declaration and the size of each component
997 // list.
998 // NumComponents x MappableComponent - the total of all the components in all
999 // the lists.
1000 void *Mem = C.Allocate(
1001 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1002 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001003 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1004 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1005 Sizes.NumComponents));
1006 OMPMapClause *Clause = new (Mem)
1007 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
1008 Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
Samuel Antao90927002016-04-26 14:54:23 +00001009
1010 Clause->setVarRefs(Vars);
Michael Kruse4304e9d2019-02-19 16:38:20 +00001011 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao90927002016-04-26 14:54:23 +00001012 Clause->setClauseInfo(Declarations, ComponentLists);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001013 Clause->setMapType(Type);
1014 Clause->setMapLoc(TypeLoc);
1015 return Clause;
1016}
1017
Michael Kruse4304e9d2019-02-19 16:38:20 +00001018OMPMapClause *
1019OMPMapClause::CreateEmpty(const ASTContext &C,
1020 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao90927002016-04-26 14:54:23 +00001021 void *Mem = C.Allocate(
1022 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1023 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001024 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1025 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1026 Sizes.NumComponents));
1027 return new (Mem) OMPMapClause(Sizes);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001028}
Samuel Antao661c0902016-05-26 17:39:58 +00001029
Michael Kruse01f670d2019-02-22 22:29:42 +00001030OMPToClause *OMPToClause::Create(
1031 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1032 ArrayRef<ValueDecl *> Declarations,
1033 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1034 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001035 OMPMappableExprListSizeTy Sizes;
1036 Sizes.NumVars = Vars.size();
1037 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1038 Sizes.NumComponentLists = ComponentLists.size();
1039 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao661c0902016-05-26 17:39:58 +00001040
1041 // We need to allocate:
Michael Kruse01f670d2019-02-22 22:29:42 +00001042 // 2 x NumVars x Expr* - we have an original list expression and an associated
1043 // user-defined mapper for each clause list entry.
Samuel Antao661c0902016-05-26 17:39:58 +00001044 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1045 // with each component list.
1046 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1047 // number of lists for each unique declaration and the size of each component
1048 // list.
1049 // NumComponents x MappableComponent - the total of all the components in all
1050 // the lists.
1051 void *Mem = C.Allocate(
1052 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1053 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +00001054 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001055 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1056 Sizes.NumComponents));
Samuel Antao661c0902016-05-26 17:39:58 +00001057
Michael Kruse01f670d2019-02-22 22:29:42 +00001058 auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +00001059
1060 Clause->setVarRefs(Vars);
Michael Kruse01f670d2019-02-22 22:29:42 +00001061 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao661c0902016-05-26 17:39:58 +00001062 Clause->setClauseInfo(Declarations, ComponentLists);
1063 return Clause;
1064}
1065
Michael Kruse4304e9d2019-02-19 16:38:20 +00001066OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
1067 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao661c0902016-05-26 17:39:58 +00001068 void *Mem = C.Allocate(
1069 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1070 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +00001071 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001072 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1073 Sizes.NumComponents));
1074 return new (Mem) OMPToClause(Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +00001075}
Samuel Antaoec172c62016-05-26 17:49:04 +00001076
Michael Kruse0336c752019-02-25 20:34:15 +00001077OMPFromClause *OMPFromClause::Create(
1078 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1079 ArrayRef<ValueDecl *> Declarations,
1080 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1081 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001082 OMPMappableExprListSizeTy Sizes;
1083 Sizes.NumVars = Vars.size();
1084 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1085 Sizes.NumComponentLists = ComponentLists.size();
1086 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaoec172c62016-05-26 17:49:04 +00001087
1088 // We need to allocate:
Michael Kruse0336c752019-02-25 20:34:15 +00001089 // 2 x NumVars x Expr* - we have an original list expression and an associated
1090 // user-defined mapper for each clause list entry.
Samuel Antaoec172c62016-05-26 17:49:04 +00001091 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1092 // with each component list.
1093 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1094 // number of lists for each unique declaration and the size of each component
1095 // list.
1096 // NumComponents x MappableComponent - the total of all the components in all
1097 // the lists.
1098 void *Mem = C.Allocate(
1099 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1100 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001101 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001102 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1103 Sizes.NumComponents));
Samuel Antaoec172c62016-05-26 17:49:04 +00001104
Michael Kruse0336c752019-02-25 20:34:15 +00001105 auto *Clause =
1106 new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001107
1108 Clause->setVarRefs(Vars);
Michael Kruse0336c752019-02-25 20:34:15 +00001109 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antaoec172c62016-05-26 17:49:04 +00001110 Clause->setClauseInfo(Declarations, ComponentLists);
1111 return Clause;
1112}
1113
Michael Kruse4304e9d2019-02-19 16:38:20 +00001114OMPFromClause *
1115OMPFromClause::CreateEmpty(const ASTContext &C,
1116 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaoec172c62016-05-26 17:49:04 +00001117 void *Mem = C.Allocate(
1118 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1119 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001120 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001121 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1122 Sizes.NumComponents));
1123 return new (Mem) OMPFromClause(Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001124}
Carlo Bertolli2404b172016-07-13 15:37:16 +00001125
Samuel Antaocc10b852016-07-28 14:23:26 +00001126void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1127 assert(VL.size() == varlist_size() &&
1128 "Number of private copies is not the same as the preallocated buffer");
1129 std::copy(VL.begin(), VL.end(), varlist_end());
1130}
1131
1132void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
1133 assert(VL.size() == varlist_size() &&
1134 "Number of inits is not the same as the preallocated buffer");
1135 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1136}
1137
1138OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001139 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1140 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
1141 ArrayRef<ValueDecl *> Declarations,
Samuel Antaocc10b852016-07-28 14:23:26 +00001142 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001143 OMPMappableExprListSizeTy Sizes;
1144 Sizes.NumVars = Vars.size();
1145 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1146 Sizes.NumComponentLists = ComponentLists.size();
1147 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaocc10b852016-07-28 14:23:26 +00001148
1149 // We need to allocate:
1150 // 3 x NumVars x Expr* - we have an original list expression for each clause
1151 // list entry and an equal number of private copies and inits.
1152 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1153 // with each component list.
1154 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1155 // number of lists for each unique declaration and the size of each component
1156 // list.
1157 // NumComponents x MappableComponent - the total of all the components in all
1158 // the lists.
1159 void *Mem = C.Allocate(
1160 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1161 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001162 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1163 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1164 Sizes.NumComponents));
Samuel Antaocc10b852016-07-28 14:23:26 +00001165
Michael Kruse4304e9d2019-02-19 16:38:20 +00001166 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
Samuel Antaocc10b852016-07-28 14:23:26 +00001167
1168 Clause->setVarRefs(Vars);
1169 Clause->setPrivateCopies(PrivateVars);
1170 Clause->setInits(Inits);
1171 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001172 return Clause;
1173}
1174
Michael Kruse4304e9d2019-02-19 16:38:20 +00001175OMPUseDevicePtrClause *
1176OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
1177 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaocc10b852016-07-28 14:23:26 +00001178 void *Mem = C.Allocate(
1179 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1180 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001181 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1182 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1183 Sizes.NumComponents));
1184 return new (Mem) OMPUseDevicePtrClause(Sizes);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001185}
Carlo Bertolli70594e92016-07-13 17:16:49 +00001186
Samuel Antao6890b092016-07-28 14:25:09 +00001187OMPIsDevicePtrClause *
Michael Kruse4304e9d2019-02-19 16:38:20 +00001188OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
Samuel Antao6890b092016-07-28 14:25:09 +00001189 ArrayRef<Expr *> Vars,
1190 ArrayRef<ValueDecl *> Declarations,
1191 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001192 OMPMappableExprListSizeTy Sizes;
1193 Sizes.NumVars = Vars.size();
1194 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1195 Sizes.NumComponentLists = ComponentLists.size();
1196 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao6890b092016-07-28 14:25:09 +00001197
1198 // We need to allocate:
1199 // NumVars x Expr* - we have an original list expression for each clause list
1200 // entry.
1201 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1202 // with each component list.
1203 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1204 // number of lists for each unique declaration and the size of each component
1205 // list.
1206 // NumComponents x MappableComponent - the total of all the components in all
1207 // the lists.
1208 void *Mem = C.Allocate(
1209 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1210 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001211 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1212 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1213 Sizes.NumComponents));
Samuel Antao6890b092016-07-28 14:25:09 +00001214
Michael Kruse4304e9d2019-02-19 16:38:20 +00001215 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
Samuel Antao6890b092016-07-28 14:25:09 +00001216
1217 Clause->setVarRefs(Vars);
1218 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001219 return Clause;
1220}
1221
Michael Kruse4304e9d2019-02-19 16:38:20 +00001222OMPIsDevicePtrClause *
1223OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1224 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao6890b092016-07-28 14:25:09 +00001225 void *Mem = C.Allocate(
1226 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1227 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001228 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1229 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1230 Sizes.NumComponents));
1231 return new (Mem) OMPIsDevicePtrClause(Sizes);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001232}
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001233
Alexey Bataevb6e70842019-12-16 15:54:17 -05001234OMPNontemporalClause *OMPNontemporalClause::Create(const ASTContext &C,
1235 SourceLocation StartLoc,
1236 SourceLocation LParenLoc,
1237 SourceLocation EndLoc,
1238 ArrayRef<Expr *> VL) {
Alexey Bataev0860db92019-12-19 10:01:10 -05001239 // Allocate space for nontemporal variables + private references.
1240 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
Alexey Bataevb6e70842019-12-16 15:54:17 -05001241 auto *Clause =
1242 new (Mem) OMPNontemporalClause(StartLoc, LParenLoc, EndLoc, VL.size());
1243 Clause->setVarRefs(VL);
1244 return Clause;
1245}
1246
1247OMPNontemporalClause *OMPNontemporalClause::CreateEmpty(const ASTContext &C,
1248 unsigned N) {
Alexey Bataev0860db92019-12-19 10:01:10 -05001249 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
Alexey Bataevb6e70842019-12-16 15:54:17 -05001250 return new (Mem) OMPNontemporalClause(N);
1251}
1252
Alexey Bataev0860db92019-12-19 10:01:10 -05001253void OMPNontemporalClause::setPrivateRefs(ArrayRef<Expr *> VL) {
1254 assert(VL.size() == varlist_size() && "Number of private references is not "
1255 "the same as the preallocated buffer");
1256 std::copy(VL.begin(), VL.end(), varlist_end());
1257}
1258
Alexey Bataev06dea732020-03-20 09:41:22 -04001259OMPInclusiveClause *OMPInclusiveClause::Create(const ASTContext &C,
1260 SourceLocation StartLoc,
1261 SourceLocation LParenLoc,
1262 SourceLocation EndLoc,
1263 ArrayRef<Expr *> VL) {
1264 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
1265 auto *Clause =
1266 new (Mem) OMPInclusiveClause(StartLoc, LParenLoc, EndLoc, VL.size());
1267 Clause->setVarRefs(VL);
1268 return Clause;
1269}
1270
1271OMPInclusiveClause *OMPInclusiveClause::CreateEmpty(const ASTContext &C,
1272 unsigned N) {
1273 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
1274 return new (Mem) OMPInclusiveClause(N);
1275}
1276
Alexey Bataev63828a32020-03-23 10:41:08 -04001277OMPExclusiveClause *OMPExclusiveClause::Create(const ASTContext &C,
1278 SourceLocation StartLoc,
1279 SourceLocation LParenLoc,
1280 SourceLocation EndLoc,
1281 ArrayRef<Expr *> VL) {
1282 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
1283 auto *Clause =
1284 new (Mem) OMPExclusiveClause(StartLoc, LParenLoc, EndLoc, VL.size());
1285 Clause->setVarRefs(VL);
1286 return Clause;
1287}
1288
1289OMPExclusiveClause *OMPExclusiveClause::CreateEmpty(const ASTContext &C,
1290 unsigned N) {
1291 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
1292 return new (Mem) OMPExclusiveClause(N);
1293}
1294
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001295//===----------------------------------------------------------------------===//
1296// OpenMP clauses printing methods
1297//===----------------------------------------------------------------------===//
1298
1299void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1300 OS << "if(";
Johannes Doerfertb2932242020-03-25 19:33:48 -05001301 if (Node->getNameModifier() != OMPD_unknown)
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001302 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1303 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1304 OS << ")";
1305}
1306
1307void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1308 OS << "final(";
1309 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1310 OS << ")";
1311}
1312
1313void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1314 OS << "num_threads(";
1315 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1316 OS << ")";
1317}
1318
1319void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1320 OS << "safelen(";
1321 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1322 OS << ")";
1323}
1324
1325void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1326 OS << "simdlen(";
1327 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1328 OS << ")";
1329}
1330
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00001331void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
1332 OS << "allocator(";
1333 Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
1334 OS << ")";
1335}
1336
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001337void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1338 OS << "collapse(";
1339 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1340 OS << ")";
1341}
1342
Alexey Bataev0f0564b2020-03-17 09:17:42 -04001343void OMPClausePrinter::VisitOMPDetachClause(OMPDetachClause *Node) {
1344 OS << "detach(";
1345 Node->getEventHandler()->printPretty(OS, nullptr, Policy, 0);
1346 OS << ")";
1347}
1348
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001349void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1350 OS << "default("
Atmn Patel577c9b02020-02-14 21:45:49 -06001351 << getOpenMPSimpleClauseTypeName(OMPC_default,
1352 unsigned(Node->getDefaultKind()))
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001353 << ")";
1354}
1355
1356void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1357 OS << "proc_bind("
Johannes Doerfert6c5d1f402019-12-25 18:15:36 -06001358 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind,
1359 unsigned(Node->getProcBindKind()))
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001360 << ")";
1361}
1362
1363void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1364 OS << "unified_address";
1365}
1366
1367void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1368 OMPUnifiedSharedMemoryClause *) {
1369 OS << "unified_shared_memory";
1370}
1371
1372void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1373 OS << "reverse_offload";
1374}
1375
1376void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1377 OMPDynamicAllocatorsClause *) {
1378 OS << "dynamic_allocators";
1379}
1380
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00001381void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1382 OMPAtomicDefaultMemOrderClause *Node) {
1383 OS << "atomic_default_mem_order("
1384 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1385 Node->getAtomicDefaultMemOrderKind())
1386 << ")";
1387}
1388
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001389void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1390 OS << "schedule(";
1391 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1392 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1393 Node->getFirstScheduleModifier());
1394 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1395 OS << ", ";
1396 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1397 Node->getSecondScheduleModifier());
1398 }
1399 OS << ": ";
1400 }
1401 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1402 if (auto *E = Node->getChunkSize()) {
1403 OS << ", ";
1404 E->printPretty(OS, nullptr, Policy);
1405 }
1406 OS << ")";
1407}
1408
1409void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1410 OS << "ordered";
1411 if (auto *Num = Node->getNumForLoops()) {
1412 OS << "(";
1413 Num->printPretty(OS, nullptr, Policy, 0);
1414 OS << ")";
1415 }
1416}
1417
1418void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1419 OS << "nowait";
1420}
1421
1422void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1423 OS << "untied";
1424}
1425
1426void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1427 OS << "nogroup";
1428}
1429
1430void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1431 OS << "mergeable";
1432}
1433
1434void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1435
1436void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1437
Alexey Bataev82f7c202020-03-03 13:22:35 -05001438void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *Node) {
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001439 OS << "update";
Alexey Bataev82f7c202020-03-03 13:22:35 -05001440 if (Node->isExtended()) {
1441 OS << "(";
1442 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1443 Node->getDependencyKind());
1444 OS << ")";
1445 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001446}
1447
1448void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1449 OS << "capture";
1450}
1451
1452void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1453 OS << "seq_cst";
1454}
1455
Alexey Bataevea9166b2020-02-06 16:30:23 -05001456void OMPClausePrinter::VisitOMPAcqRelClause(OMPAcqRelClause *) {
1457 OS << "acq_rel";
1458}
1459
Alexey Bataev04a830f2020-02-10 14:30:39 -05001460void OMPClausePrinter::VisitOMPAcquireClause(OMPAcquireClause *) {
1461 OS << "acquire";
1462}
1463
Alexey Bataev95598342020-02-10 15:49:05 -05001464void OMPClausePrinter::VisitOMPReleaseClause(OMPReleaseClause *) {
1465 OS << "release";
1466}
1467
Alexey Bataev9a8defc2020-02-11 11:10:43 -05001468void OMPClausePrinter::VisitOMPRelaxedClause(OMPRelaxedClause *) {
1469 OS << "relaxed";
1470}
1471
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001472void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1473 OS << "threads";
1474}
1475
1476void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1477
1478void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1479 OS << "device(";
Alexey Bataev2f8894a2020-03-18 15:01:15 -04001480 OpenMPDeviceClauseModifier Modifier = Node->getModifier();
1481 if (Modifier != OMPC_DEVICE_unknown) {
1482 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), Modifier)
1483 << ": ";
1484 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001485 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1486 OS << ")";
1487}
1488
1489void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1490 OS << "num_teams(";
1491 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1492 OS << ")";
1493}
1494
1495void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1496 OS << "thread_limit(";
1497 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1498 OS << ")";
1499}
1500
1501void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1502 OS << "priority(";
1503 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1504 OS << ")";
1505}
1506
1507void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1508 OS << "grainsize(";
1509 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1510 OS << ")";
1511}
1512
1513void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1514 OS << "num_tasks(";
1515 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1516 OS << ")";
1517}
1518
1519void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1520 OS << "hint(";
1521 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1522 OS << ")";
1523}
1524
Alexey Bataev375437a2020-03-02 14:21:20 -05001525void OMPClausePrinter::VisitOMPDestroyClause(OMPDestroyClause *) {
1526 OS << "destroy";
1527}
1528
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001529template<typename T>
1530void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1531 for (typename T::varlist_iterator I = Node->varlist_begin(),
1532 E = Node->varlist_end();
1533 I != E; ++I) {
1534 assert(*I && "Expected non-null Stmt");
1535 OS << (I == Node->varlist_begin() ? StartSym : ',');
1536 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1537 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1538 DRE->printPretty(OS, nullptr, Policy, 0);
1539 else
1540 DRE->getDecl()->printQualifiedName(OS);
1541 } else
1542 (*I)->printPretty(OS, nullptr, Policy, 0);
1543 }
1544}
1545
Alexey Bataeve04483e2019-03-27 14:14:31 +00001546void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
1547 if (Node->varlist_empty())
1548 return;
1549 OS << "allocate";
1550 if (Expr *Allocator = Node->getAllocator()) {
1551 OS << "(";
1552 Allocator->printPretty(OS, nullptr, Policy, 0);
1553 OS << ":";
1554 VisitOMPClauseList(Node, ' ');
1555 } else {
1556 VisitOMPClauseList(Node, '(');
1557 }
1558 OS << ")";
1559}
1560
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001561void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1562 if (!Node->varlist_empty()) {
1563 OS << "private";
1564 VisitOMPClauseList(Node, '(');
1565 OS << ")";
1566 }
1567}
1568
1569void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1570 if (!Node->varlist_empty()) {
1571 OS << "firstprivate";
1572 VisitOMPClauseList(Node, '(');
1573 OS << ")";
1574 }
1575}
1576
1577void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1578 if (!Node->varlist_empty()) {
1579 OS << "lastprivate";
Alexey Bataev93dc40d2019-12-20 11:04:57 -05001580 OpenMPLastprivateModifier LPKind = Node->getKind();
1581 if (LPKind != OMPC_LASTPRIVATE_unknown) {
1582 OS << "("
1583 << getOpenMPSimpleClauseTypeName(OMPC_lastprivate, Node->getKind())
1584 << ":";
1585 }
1586 VisitOMPClauseList(Node, LPKind == OMPC_LASTPRIVATE_unknown ? '(' : ' ');
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001587 OS << ")";
1588 }
1589}
1590
1591void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1592 if (!Node->varlist_empty()) {
1593 OS << "shared";
1594 VisitOMPClauseList(Node, '(');
1595 OS << ")";
1596 }
1597}
1598
1599void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1600 if (!Node->varlist_empty()) {
1601 OS << "reduction(";
Alexey Bataev1236eb62020-03-23 17:30:38 -04001602 if (Node->getModifierLoc().isValid())
1603 OS << getOpenMPSimpleClauseTypeName(OMPC_reduction, Node->getModifier())
1604 << ", ";
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001605 NestedNameSpecifier *QualifierLoc =
1606 Node->getQualifierLoc().getNestedNameSpecifier();
1607 OverloadedOperatorKind OOK =
1608 Node->getNameInfo().getName().getCXXOverloadedOperator();
1609 if (QualifierLoc == nullptr && OOK != OO_None) {
1610 // Print reduction identifier in C format
1611 OS << getOperatorSpelling(OOK);
1612 } else {
1613 // Use C++ format
1614 if (QualifierLoc != nullptr)
1615 QualifierLoc->print(OS, Policy);
1616 OS << Node->getNameInfo();
1617 }
1618 OS << ":";
1619 VisitOMPClauseList(Node, ' ');
1620 OS << ")";
1621 }
1622}
1623
1624void OMPClausePrinter::VisitOMPTaskReductionClause(
1625 OMPTaskReductionClause *Node) {
1626 if (!Node->varlist_empty()) {
1627 OS << "task_reduction(";
1628 NestedNameSpecifier *QualifierLoc =
1629 Node->getQualifierLoc().getNestedNameSpecifier();
1630 OverloadedOperatorKind OOK =
1631 Node->getNameInfo().getName().getCXXOverloadedOperator();
1632 if (QualifierLoc == nullptr && OOK != OO_None) {
1633 // Print reduction identifier in C format
1634 OS << getOperatorSpelling(OOK);
1635 } else {
1636 // Use C++ format
1637 if (QualifierLoc != nullptr)
1638 QualifierLoc->print(OS, Policy);
1639 OS << Node->getNameInfo();
1640 }
1641 OS << ":";
1642 VisitOMPClauseList(Node, ' ');
1643 OS << ")";
1644 }
1645}
1646
1647void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1648 if (!Node->varlist_empty()) {
1649 OS << "in_reduction(";
1650 NestedNameSpecifier *QualifierLoc =
1651 Node->getQualifierLoc().getNestedNameSpecifier();
1652 OverloadedOperatorKind OOK =
1653 Node->getNameInfo().getName().getCXXOverloadedOperator();
1654 if (QualifierLoc == nullptr && OOK != OO_None) {
1655 // Print reduction identifier in C format
1656 OS << getOperatorSpelling(OOK);
1657 } else {
1658 // Use C++ format
1659 if (QualifierLoc != nullptr)
1660 QualifierLoc->print(OS, Policy);
1661 OS << Node->getNameInfo();
1662 }
1663 OS << ":";
1664 VisitOMPClauseList(Node, ' ');
1665 OS << ")";
1666 }
1667}
1668
1669void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1670 if (!Node->varlist_empty()) {
1671 OS << "linear";
1672 if (Node->getModifierLoc().isValid()) {
1673 OS << '('
1674 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1675 }
1676 VisitOMPClauseList(Node, '(');
1677 if (Node->getModifierLoc().isValid())
1678 OS << ')';
1679 if (Node->getStep() != nullptr) {
1680 OS << ": ";
1681 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1682 }
1683 OS << ")";
1684 }
1685}
1686
1687void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1688 if (!Node->varlist_empty()) {
1689 OS << "aligned";
1690 VisitOMPClauseList(Node, '(');
1691 if (Node->getAlignment() != nullptr) {
1692 OS << ": ";
1693 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1694 }
1695 OS << ")";
1696 }
1697}
1698
1699void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1700 if (!Node->varlist_empty()) {
1701 OS << "copyin";
1702 VisitOMPClauseList(Node, '(');
1703 OS << ")";
1704 }
1705}
1706
1707void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1708 if (!Node->varlist_empty()) {
1709 OS << "copyprivate";
1710 VisitOMPClauseList(Node, '(');
1711 OS << ")";
1712 }
1713}
1714
1715void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1716 if (!Node->varlist_empty()) {
1717 VisitOMPClauseList(Node, '(');
1718 OS << ")";
1719 }
1720}
1721
Alexey Bataevc112e942020-02-28 09:52:15 -05001722void OMPClausePrinter::VisitOMPDepobjClause(OMPDepobjClause *Node) {
1723 OS << "(";
1724 Node->getDepobj()->printPretty(OS, nullptr, Policy, 0);
1725 OS << ")";
1726}
1727
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001728void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1729 OS << "depend(";
1730 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1731 Node->getDependencyKind());
1732 if (!Node->varlist_empty()) {
1733 OS << " :";
1734 VisitOMPClauseList(Node, ' ');
1735 }
1736 OS << ")";
1737}
1738
1739void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1740 if (!Node->varlist_empty()) {
1741 OS << "map(";
1742 if (Node->getMapType() != OMPC_MAP_unknown) {
Kelvin Lief579432018-12-18 22:18:41 +00001743 for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1744 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1745 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1746 Node->getMapTypeModifier(I));
Michael Kruse4304e9d2019-02-19 16:38:20 +00001747 if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1748 OS << '(';
1749 NestedNameSpecifier *MapperNNS =
1750 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1751 if (MapperNNS)
1752 MapperNNS->print(OS, Policy);
1753 OS << Node->getMapperIdInfo() << ')';
1754 }
Kelvin Lief579432018-12-18 22:18:41 +00001755 OS << ',';
1756 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001757 }
1758 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1759 OS << ':';
1760 }
1761 VisitOMPClauseList(Node, ' ');
1762 OS << ")";
1763 }
1764}
1765
1766void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1767 if (!Node->varlist_empty()) {
1768 OS << "to";
Michael Kruse01f670d2019-02-22 22:29:42 +00001769 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1770 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1771 OS << '(';
1772 OS << "mapper(";
1773 NestedNameSpecifier *MapperNNS =
1774 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1775 if (MapperNNS)
1776 MapperNNS->print(OS, Policy);
1777 OS << MapperId << "):";
1778 VisitOMPClauseList(Node, ' ');
1779 } else {
1780 VisitOMPClauseList(Node, '(');
1781 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001782 OS << ")";
1783 }
1784}
1785
1786void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1787 if (!Node->varlist_empty()) {
1788 OS << "from";
Michael Kruse0336c752019-02-25 20:34:15 +00001789 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1790 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1791 OS << '(';
1792 OS << "mapper(";
1793 NestedNameSpecifier *MapperNNS =
1794 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1795 if (MapperNNS)
1796 MapperNNS->print(OS, Policy);
1797 OS << MapperId << "):";
1798 VisitOMPClauseList(Node, ' ');
1799 } else {
1800 VisitOMPClauseList(Node, '(');
1801 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001802 OS << ")";
1803 }
1804}
1805
1806void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1807 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1808 OMPC_dist_schedule, Node->getDistScheduleKind());
1809 if (auto *E = Node->getChunkSize()) {
1810 OS << ", ";
1811 E->printPretty(OS, nullptr, Policy);
1812 }
1813 OS << ")";
1814}
1815
1816void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1817 OS << "defaultmap(";
1818 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1819 Node->getDefaultmapModifier());
1820 OS << ": ";
1821 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1822 Node->getDefaultmapKind());
1823 OS << ")";
1824}
1825
1826void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1827 if (!Node->varlist_empty()) {
1828 OS << "use_device_ptr";
1829 VisitOMPClauseList(Node, '(');
1830 OS << ")";
1831 }
1832}
1833
1834void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1835 if (!Node->varlist_empty()) {
1836 OS << "is_device_ptr";
1837 VisitOMPClauseList(Node, '(');
1838 OS << ")";
1839 }
1840}
1841
Alexey Bataevb6e70842019-12-16 15:54:17 -05001842void OMPClausePrinter::VisitOMPNontemporalClause(OMPNontemporalClause *Node) {
1843 if (!Node->varlist_empty()) {
1844 OS << "nontemporal";
1845 VisitOMPClauseList(Node, '(');
1846 OS << ")";
1847 }
1848}
Alexey Bataevcb8e6912020-01-31 16:09:26 -05001849
1850void OMPClausePrinter::VisitOMPOrderClause(OMPOrderClause *Node) {
1851 OS << "order(" << getOpenMPSimpleClauseTypeName(OMPC_order, Node->getKind())
1852 << ")";
1853}
Johannes Doerfert1228d422019-12-19 20:42:12 -06001854
Alexey Bataev06dea732020-03-20 09:41:22 -04001855void OMPClausePrinter::VisitOMPInclusiveClause(OMPInclusiveClause *Node) {
1856 if (!Node->varlist_empty()) {
1857 OS << "inclusive";
1858 VisitOMPClauseList(Node, '(');
1859 OS << ")";
1860 }
1861}
1862
Alexey Bataev63828a32020-03-23 10:41:08 -04001863void OMPClausePrinter::VisitOMPExclusiveClause(OMPExclusiveClause *Node) {
1864 if (!Node->varlist_empty()) {
1865 OS << "exclusive";
1866 VisitOMPClauseList(Node, '(');
1867 OS << ")";
1868 }
1869}
1870
Johannes Doerfert095cecb2020-02-20 19:50:47 -06001871void OMPTraitInfo::getAsVariantMatchInfo(ASTContext &ASTCtx,
1872 VariantMatchInfo &VMI,
1873 bool DeviceSetOnly) const {
Johannes Doerfert1228d422019-12-19 20:42:12 -06001874 for (const OMPTraitSet &Set : Sets) {
Johannes Doerfert095cecb2020-02-20 19:50:47 -06001875 if (DeviceSetOnly && Set.Kind != TraitSet::device)
1876 continue;
Johannes Doerfert1228d422019-12-19 20:42:12 -06001877 for (const OMPTraitSelector &Selector : Set.Selectors) {
1878
1879 // User conditions are special as we evaluate the condition here.
Johannes Doerfertb2932242020-03-25 19:33:48 -05001880 if (Selector.Kind == TraitSelector::user_condition) {
Johannes Doerfert1228d422019-12-19 20:42:12 -06001881 assert(Selector.ScoreOrCondition &&
1882 "Ill-formed user condition, expected condition expression!");
1883 assert(Selector.Properties.size() == 1 &&
1884 Selector.Properties.front().Kind ==
Johannes Doerfertb2932242020-03-25 19:33:48 -05001885 TraitProperty::user_condition_unknown &&
Johannes Doerfert1228d422019-12-19 20:42:12 -06001886 "Ill-formed user condition, expected unknown trait property!");
1887
1888 llvm::APInt CondVal =
1889 Selector.ScoreOrCondition->EvaluateKnownConstInt(ASTCtx);
1890 VMI.addTrait(CondVal.isNullValue()
Johannes Doerfertb2932242020-03-25 19:33:48 -05001891 ? TraitProperty::user_condition_false
1892 : TraitProperty::user_condition_true);
Johannes Doerfert1228d422019-12-19 20:42:12 -06001893 continue;
1894 }
1895
1896 llvm::APInt Score;
1897 llvm::APInt *ScorePtr = nullptr;
1898 if (Selector.ScoreOrCondition) {
1899 Score = Selector.ScoreOrCondition->EvaluateKnownConstInt(ASTCtx);
1900 ScorePtr = &Score;
1901 }
1902 for (const OMPTraitProperty &Property : Selector.Properties)
1903 VMI.addTrait(Set.Kind, Property.Kind, ScorePtr);
1904
Johannes Doerfertb2932242020-03-25 19:33:48 -05001905 if (Set.Kind != TraitSet::construct)
Johannes Doerfert1228d422019-12-19 20:42:12 -06001906 continue;
1907
1908 // TODO: This might not hold once we implement SIMD properly.
1909 assert(Selector.Properties.size() == 1 &&
1910 Selector.Properties.front().Kind ==
Johannes Doerfertb2932242020-03-25 19:33:48 -05001911 getOpenMPContextTraitPropertyForSelector(
Johannes Doerfert1228d422019-12-19 20:42:12 -06001912 Selector.Kind) &&
1913 "Ill-formed construct selector!");
1914
1915 VMI.ConstructTraits.push_back(Selector.Properties.front().Kind);
1916 }
1917 }
1918}
1919
1920void OMPTraitInfo::print(llvm::raw_ostream &OS,
1921 const PrintingPolicy &Policy) const {
1922 bool FirstSet = true;
1923 for (const OMPTraitInfo::OMPTraitSet &Set : Sets) {
1924 if (!FirstSet)
1925 OS << ", ";
1926 FirstSet = false;
Johannes Doerfertb2932242020-03-25 19:33:48 -05001927 OS << getOpenMPContextTraitSetName(Set.Kind) << "={";
Johannes Doerfert1228d422019-12-19 20:42:12 -06001928
1929 bool FirstSelector = true;
1930 for (const OMPTraitInfo::OMPTraitSelector &Selector : Set.Selectors) {
1931 if (!FirstSelector)
1932 OS << ", ";
1933 FirstSelector = false;
Johannes Doerfertb2932242020-03-25 19:33:48 -05001934 OS << getOpenMPContextTraitSelectorName(Selector.Kind);
Johannes Doerfert1228d422019-12-19 20:42:12 -06001935
1936 bool AllowsTraitScore = false;
1937 bool RequiresProperty = false;
Johannes Doerfertb2932242020-03-25 19:33:48 -05001938 isValidTraitSelectorForTraitSet(
Johannes Doerfert1228d422019-12-19 20:42:12 -06001939 Selector.Kind, Set.Kind, AllowsTraitScore, RequiresProperty);
1940
1941 if (!RequiresProperty)
1942 continue;
1943
1944 OS << "(";
Johannes Doerfertb2932242020-03-25 19:33:48 -05001945 if (Selector.Kind == TraitSelector::user_condition) {
Johannes Doerfert1228d422019-12-19 20:42:12 -06001946 Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy);
1947 } else {
1948
1949 if (Selector.ScoreOrCondition) {
1950 OS << "score(";
1951 Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy);
1952 OS << "): ";
1953 }
1954
1955 bool FirstProperty = true;
1956 for (const OMPTraitInfo::OMPTraitProperty &Property :
1957 Selector.Properties) {
1958 if (!FirstProperty)
1959 OS << ", ";
1960 FirstProperty = false;
Johannes Doerfertb2932242020-03-25 19:33:48 -05001961 OS << getOpenMPContextTraitPropertyName(Property.Kind);
Johannes Doerfert1228d422019-12-19 20:42:12 -06001962 }
1963 }
1964 OS << ")";
1965 }
1966 OS << "}";
1967 }
1968}
1969
1970llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS,
1971 const OMPTraitInfo &TI) {
1972 LangOptions LO;
1973 PrintingPolicy Policy(LO);
1974 TI.print(OS, Policy);
1975 return OS;
1976}
Johannes Doerfert55eca282020-03-13 23:42:05 -05001977llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS,
1978 const OMPTraitInfo *TI) {
1979 return TI ? OS << *TI : OS;
1980}