blob: 2bd02a0cda4f7c716bc77efcb447832484c1822b [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:
Alexey Bataevc112e942020-02-28 09:52:15 -0500114 case OMPC_depobj:
Alexey Bataev005248a2016-02-25 05:25:57 +0000115 case OMPC_read:
116 case OMPC_write:
117 case OMPC_update:
118 case OMPC_capture:
119 case OMPC_seq_cst:
Alexey Bataevea9166b2020-02-06 16:30:23 -0500120 case OMPC_acq_rel:
Alexey Bataev04a830f2020-02-10 14:30:39 -0500121 case OMPC_acquire:
Alexey Bataev95598342020-02-10 15:49:05 -0500122 case OMPC_release:
Alexey Bataev9a8defc2020-02-11 11:10:43 -0500123 case OMPC_relaxed:
Alexey Bataev005248a2016-02-25 05:25:57 +0000124 case OMPC_depend:
Alexey Bataev005248a2016-02-25 05:25:57 +0000125 case OMPC_threads:
126 case OMPC_simd:
127 case OMPC_map:
Alexey Bataev005248a2016-02-25 05:25:57 +0000128 case OMPC_nogroup:
Alexey Bataev005248a2016-02-25 05:25:57 +0000129 case OMPC_hint:
130 case OMPC_defaultmap:
131 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000132 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000133 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000134 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000135 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000136 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000137 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000138 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000139 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000140 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000141 case OMPC_atomic_default_mem_order:
Alexey Bataev729e2422019-08-23 16:11:14 +0000142 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +0000143 case OMPC_match:
Alexey Bataevb6e70842019-12-16 15:54:17 -0500144 case OMPC_nontemporal:
Alexey Bataevcb8e6912020-01-31 16:09:26 -0500145 case OMPC_order:
Alexey Bataev375437a2020-03-02 14:21:20 -0500146 case OMPC_destroy:
Alexey Bataev005248a2016-02-25 05:25:57 +0000147 break;
148 }
149
150 return nullptr;
151}
152
153OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
154 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
155 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
156}
157
158const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
159 switch (C->getClauseKind()) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000160 case OMPC_lastprivate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000161 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000162 case OMPC_reduction:
163 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +0000164 case OMPC_task_reduction:
165 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000166 case OMPC_in_reduction:
167 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000168 case OMPC_linear:
169 return static_cast<const OMPLinearClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000170 case OMPC_schedule:
171 case OMPC_dist_schedule:
172 case OMPC_firstprivate:
173 case OMPC_default:
174 case OMPC_proc_bind:
175 case OMPC_if:
176 case OMPC_final:
177 case OMPC_num_threads:
178 case OMPC_safelen:
179 case OMPC_simdlen:
Alexey Bataev9cc10fc2019-03-12 18:52:33 +0000180 case OMPC_allocator:
Alexey Bataeve04483e2019-03-27 14:14:31 +0000181 case OMPC_allocate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000182 case OMPC_collapse:
183 case OMPC_private:
Alexey Bataev3392d762016-02-16 11:18:12 +0000184 case OMPC_shared:
Alexey Bataev3392d762016-02-16 11:18:12 +0000185 case OMPC_aligned:
186 case OMPC_copyin:
187 case OMPC_copyprivate:
188 case OMPC_ordered:
189 case OMPC_nowait:
190 case OMPC_untied:
191 case OMPC_mergeable:
192 case OMPC_threadprivate:
193 case OMPC_flush:
Alexey Bataevc112e942020-02-28 09:52:15 -0500194 case OMPC_depobj:
Alexey Bataev3392d762016-02-16 11:18:12 +0000195 case OMPC_read:
196 case OMPC_write:
197 case OMPC_update:
198 case OMPC_capture:
199 case OMPC_seq_cst:
Alexey Bataevea9166b2020-02-06 16:30:23 -0500200 case OMPC_acq_rel:
Alexey Bataev04a830f2020-02-10 14:30:39 -0500201 case OMPC_acquire:
Alexey Bataev95598342020-02-10 15:49:05 -0500202 case OMPC_release:
Alexey Bataev9a8defc2020-02-11 11:10:43 -0500203 case OMPC_relaxed:
Alexey Bataev3392d762016-02-16 11:18:12 +0000204 case OMPC_depend:
205 case OMPC_device:
206 case OMPC_threads:
207 case OMPC_simd:
208 case OMPC_map:
209 case OMPC_num_teams:
210 case OMPC_thread_limit:
211 case OMPC_priority:
212 case OMPC_grainsize:
213 case OMPC_nogroup:
214 case OMPC_num_tasks:
215 case OMPC_hint:
216 case OMPC_defaultmap:
217 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000218 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000219 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000220 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000221 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000222 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000223 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000224 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000225 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000226 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000227 case OMPC_atomic_default_mem_order:
Alexey Bataev729e2422019-08-23 16:11:14 +0000228 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +0000229 case OMPC_match:
Alexey Bataevb6e70842019-12-16 15:54:17 -0500230 case OMPC_nontemporal:
Alexey Bataevcb8e6912020-01-31 16:09:26 -0500231 case OMPC_order:
Alexey Bataev375437a2020-03-02 14:21:20 -0500232 case OMPC_destroy:
Alexey Bataev3392d762016-02-16 11:18:12 +0000233 break;
234 }
235
236 return nullptr;
237}
238
Alexey Bataev655cb4a2019-07-16 14:51:46 +0000239/// Gets the address of the original, non-captured, expression used in the
240/// clause as the preinitializer.
241static Stmt **getAddrOfExprAsWritten(Stmt *S) {
242 if (!S)
243 return nullptr;
244 if (auto *DS = dyn_cast<DeclStmt>(S)) {
245 assert(DS->isSingleDecl() && "Only single expression must be captured.");
246 if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
247 return OED->getInitAddress();
248 }
249 return nullptr;
250}
251
252OMPClause::child_range OMPIfClause::used_children() {
253 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
254 return child_range(C, C + 1);
255 return child_range(&Condition, &Condition + 1);
256}
257
Alexey Bataevb9c55e22019-10-14 19:29:52 +0000258OMPClause::child_range OMPGrainsizeClause::used_children() {
259 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
260 return child_range(C, C + 1);
261 return child_range(&Grainsize, &Grainsize + 1);
262}
263
Alexey Bataevd88c7de2019-10-14 20:44:34 +0000264OMPClause::child_range OMPNumTasksClause::used_children() {
265 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
266 return child_range(C, C + 1);
267 return child_range(&NumTasks, &NumTasks + 1);
268}
269
Alexey Bataev3a842ec2019-10-15 19:37:05 +0000270OMPClause::child_range OMPFinalClause::used_children() {
271 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
272 return child_range(C, C + 1);
273 return child_range(&Condition, &Condition + 1);
274}
275
Alexey Bataev31ba4762019-10-16 18:09:37 +0000276OMPClause::child_range OMPPriorityClause::used_children() {
277 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
278 return child_range(C, C + 1);
279 return child_range(&Priority, &Priority + 1);
280}
281
Alexey Bataevf138fda2018-08-13 19:04:24 +0000282OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
283 unsigned NumLoops,
284 SourceLocation StartLoc,
285 SourceLocation LParenLoc,
286 SourceLocation EndLoc) {
287 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
288 auto *Clause =
289 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
290 for (unsigned I = 0; I < NumLoops; ++I) {
291 Clause->setLoopNumIterations(I, nullptr);
292 Clause->setLoopCounter(I, nullptr);
293 }
294 return Clause;
295}
296
297OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
298 unsigned NumLoops) {
299 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
300 auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
301 for (unsigned I = 0; I < NumLoops; ++I) {
302 Clause->setLoopNumIterations(I, nullptr);
303 Clause->setLoopCounter(I, nullptr);
304 }
305 return Clause;
306}
307
308void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
309 Expr *NumIterations) {
310 assert(NumLoop < NumberOfLoops && "out of loops number.");
311 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
312}
313
314ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
315 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
316}
317
318void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
319 assert(NumLoop < NumberOfLoops && "out of loops number.");
320 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
321}
322
Mike Rice0ed46662018-09-20 17:19:41 +0000323Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000324 assert(NumLoop < NumberOfLoops && "out of loops number.");
325 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
326}
327
Mike Rice0ed46662018-09-20 17:19:41 +0000328const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000329 assert(NumLoop < NumberOfLoops && "out of loops number.");
330 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
331}
332
James Y Knightb8bfd962015-10-02 13:41:04 +0000333void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
334 assert(VL.size() == varlist_size() &&
335 "Number of private copies is not the same as the preallocated buffer");
336 std::copy(VL.begin(), VL.end(), varlist_end());
337}
338
339OMPPrivateClause *
340OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
341 SourceLocation LParenLoc, SourceLocation EndLoc,
342 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
343 // Allocate space for private variables and initializer expressions.
James Y Knight374fd202016-01-01 00:38:24 +0000344 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000345 OMPPrivateClause *Clause =
346 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
347 Clause->setVarRefs(VL);
348 Clause->setPrivateCopies(PrivateVL);
349 return Clause;
350}
351
352OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
353 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000354 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000355 return new (Mem) OMPPrivateClause(N);
356}
357
358void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
359 assert(VL.size() == varlist_size() &&
360 "Number of private copies is not the same as the preallocated buffer");
361 std::copy(VL.begin(), VL.end(), varlist_end());
362}
363
364void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
365 assert(VL.size() == varlist_size() &&
366 "Number of inits is not the same as the preallocated buffer");
367 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
368}
369
370OMPFirstprivateClause *
371OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
372 SourceLocation LParenLoc, SourceLocation EndLoc,
373 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
Alexey Bataev417089f2016-02-17 13:19:37 +0000374 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
James Y Knight374fd202016-01-01 00:38:24 +0000375 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000376 OMPFirstprivateClause *Clause =
377 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
378 Clause->setVarRefs(VL);
379 Clause->setPrivateCopies(PrivateVL);
380 Clause->setInits(InitVL);
Alexey Bataev417089f2016-02-17 13:19:37 +0000381 Clause->setPreInitStmt(PreInit);
James Y Knightb8bfd962015-10-02 13:41:04 +0000382 return Clause;
383}
384
385OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
386 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000387 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000388 return new (Mem) OMPFirstprivateClause(N);
389}
390
391void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
392 assert(PrivateCopies.size() == varlist_size() &&
393 "Number of private copies is not the same as the preallocated buffer");
394 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
395}
396
397void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
398 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
399 "not the same as the "
400 "preallocated buffer");
401 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
402}
403
404void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
405 assert(DstExprs.size() == varlist_size() && "Number of destination "
406 "expressions is not the same as "
407 "the preallocated buffer");
408 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
409}
410
411void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
412 assert(AssignmentOps.size() == varlist_size() &&
413 "Number of assignment expressions is not the same as the preallocated "
414 "buffer");
415 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
416 getDestinationExprs().end());
417}
418
419OMPLastprivateClause *OMPLastprivateClause::Create(
420 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
421 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
Alexey Bataev93dc40d2019-12-20 11:04:57 -0500422 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
423 OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
424 SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000425 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
Alexey Bataev93dc40d2019-12-20 11:04:57 -0500426 OMPLastprivateClause *Clause = new (Mem) OMPLastprivateClause(
427 StartLoc, LParenLoc, EndLoc, LPKind, LPKindLoc, ColonLoc, VL.size());
James Y Knightb8bfd962015-10-02 13:41:04 +0000428 Clause->setVarRefs(VL);
429 Clause->setSourceExprs(SrcExprs);
430 Clause->setDestinationExprs(DstExprs);
431 Clause->setAssignmentOps(AssignmentOps);
Alexey Bataev005248a2016-02-25 05:25:57 +0000432 Clause->setPreInitStmt(PreInit);
433 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000434 return Clause;
435}
436
437OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
438 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000439 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000440 return new (Mem) OMPLastprivateClause(N);
441}
442
443OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
444 SourceLocation StartLoc,
445 SourceLocation LParenLoc,
446 SourceLocation EndLoc,
447 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000448 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000449 OMPSharedClause *Clause =
450 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
451 Clause->setVarRefs(VL);
452 return Clause;
453}
454
455OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000456 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000457 return new (Mem) OMPSharedClause(N);
458}
459
460void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
461 assert(PL.size() == varlist_size() &&
462 "Number of privates is not the same as the preallocated buffer");
463 std::copy(PL.begin(), PL.end(), varlist_end());
464}
465
466void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
467 assert(IL.size() == varlist_size() &&
468 "Number of inits is not the same as the preallocated buffer");
469 std::copy(IL.begin(), IL.end(), getPrivates().end());
470}
471
472void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
473 assert(UL.size() == varlist_size() &&
474 "Number of updates is not the same as the preallocated buffer");
475 std::copy(UL.begin(), UL.end(), getInits().end());
476}
477
478void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
479 assert(FL.size() == varlist_size() &&
480 "Number of final updates is not the same as the preallocated buffer");
481 std::copy(FL.begin(), FL.end(), getUpdates().end());
482}
483
Alexey Bataev195ae902019-08-08 13:42:45 +0000484void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) {
485 assert(
486 UE.size() == varlist_size() + 1 &&
487 "Number of used expressions is not the same as the preallocated buffer");
488 std::copy(UE.begin(), UE.end(), getFinals().end() + 2);
489}
490
James Y Knightb8bfd962015-10-02 13:41:04 +0000491OMPLinearClause *OMPLinearClause::Create(
492 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
493 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
494 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
Alexey Bataev78849fb2016-03-09 09:49:00 +0000495 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
496 Stmt *PreInit, Expr *PostUpdate) {
Alexey Bataev195ae902019-08-08 13:42:45 +0000497 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
498 // (Step and CalcStep), list of used expression + step.
499 void *Mem =
500 C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000501 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
502 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
503 Clause->setVarRefs(VL);
504 Clause->setPrivates(PL);
505 Clause->setInits(IL);
506 // Fill update and final expressions with zeroes, they are provided later,
507 // after the directive construction.
508 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
509 nullptr);
510 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
511 nullptr);
Alexey Bataev195ae902019-08-08 13:42:45 +0000512 std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(),
513 nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000514 Clause->setStep(Step);
515 Clause->setCalcStep(CalcStep);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000516 Clause->setPreInitStmt(PreInit);
517 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000518 return Clause;
519}
520
521OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
522 unsigned NumVars) {
Alexey Bataev195ae902019-08-08 13:42:45 +0000523 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
524 // (Step and CalcStep), list of used expression + step.
525 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars +1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000526 return new (Mem) OMPLinearClause(NumVars);
527}
528
Alexey Bataev195ae902019-08-08 13:42:45 +0000529OMPClause::child_range OMPLinearClause::used_children() {
530 // Range includes only non-nullptr elements.
531 return child_range(
532 reinterpret_cast<Stmt **>(getUsedExprs().begin()),
533 reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr)));
534}
535
James Y Knightb8bfd962015-10-02 13:41:04 +0000536OMPAlignedClause *
537OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
538 SourceLocation LParenLoc, SourceLocation ColonLoc,
539 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
James Y Knight374fd202016-01-01 00:38:24 +0000540 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000541 OMPAlignedClause *Clause = new (Mem)
542 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
543 Clause->setVarRefs(VL);
544 Clause->setAlignment(A);
545 return Clause;
546}
547
548OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
549 unsigned NumVars) {
James Y Knight374fd202016-01-01 00:38:24 +0000550 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000551 return new (Mem) OMPAlignedClause(NumVars);
552}
553
554void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
555 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
556 "not the same as the "
557 "preallocated buffer");
558 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
559}
560
561void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
562 assert(DstExprs.size() == varlist_size() && "Number of destination "
563 "expressions is not the same as "
564 "the preallocated buffer");
565 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
566}
567
568void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
569 assert(AssignmentOps.size() == varlist_size() &&
570 "Number of assignment expressions is not the same as the preallocated "
571 "buffer");
572 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
573 getDestinationExprs().end());
574}
575
576OMPCopyinClause *OMPCopyinClause::Create(
577 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
578 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
579 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000580 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000581 OMPCopyinClause *Clause =
582 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
583 Clause->setVarRefs(VL);
584 Clause->setSourceExprs(SrcExprs);
585 Clause->setDestinationExprs(DstExprs);
586 Clause->setAssignmentOps(AssignmentOps);
587 return Clause;
588}
589
590OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000591 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000592 return new (Mem) OMPCopyinClause(N);
593}
594
595void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
596 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
597 "not the same as the "
598 "preallocated buffer");
599 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
600}
601
602void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
603 assert(DstExprs.size() == varlist_size() && "Number of destination "
604 "expressions is not the same as "
605 "the preallocated buffer");
606 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
607}
608
609void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
610 assert(AssignmentOps.size() == varlist_size() &&
611 "Number of assignment expressions is not the same as the preallocated "
612 "buffer");
613 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
614 getDestinationExprs().end());
615}
616
617OMPCopyprivateClause *OMPCopyprivateClause::Create(
618 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
619 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
620 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000621 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000622 OMPCopyprivateClause *Clause =
623 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
624 Clause->setVarRefs(VL);
625 Clause->setSourceExprs(SrcExprs);
626 Clause->setDestinationExprs(DstExprs);
627 Clause->setAssignmentOps(AssignmentOps);
628 return Clause;
629}
630
631OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
632 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) OMPCopyprivateClause(N);
635}
636
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000637void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
638 assert(Privates.size() == varlist_size() &&
639 "Number of private copies is not the same as the preallocated buffer");
640 std::copy(Privates.begin(), Privates.end(), varlist_end());
641}
642
James Y Knightb8bfd962015-10-02 13:41:04 +0000643void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
644 assert(
645 LHSExprs.size() == varlist_size() &&
646 "Number of LHS expressions is not the same as the preallocated buffer");
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000647 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
James Y Knightb8bfd962015-10-02 13:41:04 +0000648}
649
650void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
651 assert(
652 RHSExprs.size() == varlist_size() &&
653 "Number of RHS expressions is not the same as the preallocated buffer");
654 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
655}
656
657void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
658 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
659 "expressions is not the same "
660 "as the preallocated buffer");
661 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
662}
663
664OMPReductionClause *OMPReductionClause::Create(
665 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
666 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
667 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000668 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev61205072016-03-02 04:57:40 +0000669 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
670 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000671 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000672 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
673 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
674 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000675 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000676 Clause->setLHSExprs(LHSExprs);
677 Clause->setRHSExprs(RHSExprs);
678 Clause->setReductionOps(ReductionOps);
Alexey Bataev61205072016-03-02 04:57:40 +0000679 Clause->setPreInitStmt(PreInit);
680 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000681 return Clause;
682}
683
684OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
685 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000686 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000687 return new (Mem) OMPReductionClause(N);
688}
689
Alexey Bataev169d96a2017-07-18 20:17:46 +0000690void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
691 assert(Privates.size() == varlist_size() &&
692 "Number of private copies is not the same as the preallocated buffer");
693 std::copy(Privates.begin(), Privates.end(), varlist_end());
694}
695
696void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
697 assert(
698 LHSExprs.size() == varlist_size() &&
699 "Number of LHS expressions is not the same as the preallocated buffer");
700 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
701}
702
703void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
704 assert(
705 RHSExprs.size() == varlist_size() &&
706 "Number of RHS expressions is not the same as the preallocated buffer");
707 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
708}
709
710void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
711 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
712 "expressions is not the same "
713 "as the preallocated buffer");
714 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
715}
716
717OMPTaskReductionClause *OMPTaskReductionClause::Create(
718 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
719 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
720 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
721 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
722 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
723 Expr *PostUpdate) {
724 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
725 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
726 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
727 Clause->setVarRefs(VL);
728 Clause->setPrivates(Privates);
729 Clause->setLHSExprs(LHSExprs);
730 Clause->setRHSExprs(RHSExprs);
731 Clause->setReductionOps(ReductionOps);
732 Clause->setPreInitStmt(PreInit);
733 Clause->setPostUpdateExpr(PostUpdate);
734 return Clause;
735}
736
737OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
738 unsigned N) {
739 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
740 return new (Mem) OMPTaskReductionClause(N);
741}
742
Alexey Bataevfa312f32017-07-21 18:48:21 +0000743void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
744 assert(Privates.size() == varlist_size() &&
745 "Number of private copies is not the same as the preallocated buffer");
746 std::copy(Privates.begin(), Privates.end(), varlist_end());
747}
748
749void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
750 assert(
751 LHSExprs.size() == varlist_size() &&
752 "Number of LHS expressions is not the same as the preallocated buffer");
753 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
754}
755
756void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
757 assert(
758 RHSExprs.size() == varlist_size() &&
759 "Number of RHS expressions is not the same as the preallocated buffer");
760 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
761}
762
763void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
764 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
765 "expressions is not the same "
766 "as the preallocated buffer");
767 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
768}
769
Alexey Bataev88202be2017-07-27 13:20:36 +0000770void OMPInReductionClause::setTaskgroupDescriptors(
771 ArrayRef<Expr *> TaskgroupDescriptors) {
772 assert(TaskgroupDescriptors.size() == varlist_size() &&
773 "Number of in reduction descriptors is not the same as the "
774 "preallocated buffer");
775 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
776 getReductionOps().end());
777}
778
Alexey Bataevfa312f32017-07-21 18:48:21 +0000779OMPInReductionClause *OMPInReductionClause::Create(
780 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
781 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
782 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
783 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev88202be2017-07-27 13:20:36 +0000784 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
785 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
786 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000787 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
788 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
789 Clause->setVarRefs(VL);
790 Clause->setPrivates(Privates);
791 Clause->setLHSExprs(LHSExprs);
792 Clause->setRHSExprs(RHSExprs);
793 Clause->setReductionOps(ReductionOps);
Alexey Bataev88202be2017-07-27 13:20:36 +0000794 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000795 Clause->setPreInitStmt(PreInit);
796 Clause->setPostUpdateExpr(PostUpdate);
797 return Clause;
798}
799
800OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
801 unsigned N) {
Alexey Bataev88202be2017-07-27 13:20:36 +0000802 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000803 return new (Mem) OMPInReductionClause(N);
804}
805
Alexey Bataeve04483e2019-03-27 14:14:31 +0000806OMPAllocateClause *
807OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc,
808 SourceLocation LParenLoc, Expr *Allocator,
809 SourceLocation ColonLoc, SourceLocation EndLoc,
810 ArrayRef<Expr *> VL) {
811 // Allocate space for private variables and initializer expressions.
812 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
813 auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
814 ColonLoc, EndLoc, VL.size());
815 Clause->setVarRefs(VL);
816 return Clause;
817}
818
819OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
820 unsigned N) {
821 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
822 return new (Mem) OMPAllocateClause(N);
823}
824
James Y Knightb8bfd962015-10-02 13:41:04 +0000825OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
826 SourceLocation StartLoc,
827 SourceLocation LParenLoc,
828 SourceLocation EndLoc,
829 ArrayRef<Expr *> VL) {
Alexey Bataev8b427062016-05-25 12:36:08 +0000830 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000831 OMPFlushClause *Clause =
832 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
833 Clause->setVarRefs(VL);
834 return Clause;
835}
836
837OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000838 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000839 return new (Mem) OMPFlushClause(N);
840}
841
Alexey Bataevc112e942020-02-28 09:52:15 -0500842OMPDepobjClause *OMPDepobjClause::Create(const ASTContext &C,
843 SourceLocation StartLoc,
844 SourceLocation LParenLoc,
845 SourceLocation RParenLoc,
846 Expr *Depobj) {
847 auto *Clause = new (C) OMPDepobjClause(StartLoc, LParenLoc, RParenLoc);
848 Clause->setDepobj(Depobj);
849 return Clause;
850}
851
852OMPDepobjClause *OMPDepobjClause::CreateEmpty(const ASTContext &C) {
853 return new (C) OMPDepobjClause();
854}
855
Alexey Bataevf138fda2018-08-13 19:04:24 +0000856OMPDependClause *
857OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
858 SourceLocation LParenLoc, SourceLocation EndLoc,
859 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
860 SourceLocation ColonLoc, ArrayRef<Expr *> VL,
861 unsigned NumLoops) {
862 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
863 OMPDependClause *Clause = new (Mem)
864 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000865 Clause->setVarRefs(VL);
866 Clause->setDependencyKind(DepKind);
867 Clause->setDependencyLoc(DepLoc);
868 Clause->setColonLoc(ColonLoc);
Alexey Bataevf138fda2018-08-13 19:04:24 +0000869 for (unsigned I = 0 ; I < NumLoops; ++I)
870 Clause->setLoopData(I, nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000871 return Clause;
872}
873
Alexey Bataevf138fda2018-08-13 19:04:24 +0000874OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
875 unsigned NumLoops) {
876 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
877 return new (Mem) OMPDependClause(N, NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000878}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000879
Alexey Bataevf138fda2018-08-13 19:04:24 +0000880void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
881 assert((getDependencyKind() == OMPC_DEPEND_sink ||
882 getDependencyKind() == OMPC_DEPEND_source) &&
883 NumLoop < NumLoops &&
884 "Expected sink or source depend + loop index must be less number of "
885 "loops.");
886 auto It = std::next(getVarRefs().end(), NumLoop);
887 *It = Cnt;
Alexey Bataev8b427062016-05-25 12:36:08 +0000888}
889
Alexey Bataevf138fda2018-08-13 19:04:24 +0000890Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
891 assert((getDependencyKind() == OMPC_DEPEND_sink ||
892 getDependencyKind() == OMPC_DEPEND_source) &&
893 NumLoop < NumLoops &&
894 "Expected sink or source depend + loop index must be less number of "
895 "loops.");
896 auto It = std::next(getVarRefs().end(), NumLoop);
897 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000898}
899
Alexey Bataevf138fda2018-08-13 19:04:24 +0000900const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
901 assert((getDependencyKind() == OMPC_DEPEND_sink ||
902 getDependencyKind() == OMPC_DEPEND_source) &&
903 NumLoop < NumLoops &&
904 "Expected sink or source depend + loop index must be less number of "
905 "loops.");
906 auto It = std::next(getVarRefs().end(), NumLoop);
907 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000908}
909
Samuel Antao90927002016-04-26 14:54:23 +0000910unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
911 MappableExprComponentListsRef ComponentLists) {
912 unsigned TotalNum = 0u;
913 for (auto &C : ComponentLists)
914 TotalNum += C.size();
915 return TotalNum;
916}
917
918unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
Alexey Bataeve3727102018-04-18 15:57:46 +0000919 ArrayRef<const ValueDecl *> Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000920 unsigned TotalNum = 0u;
921 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
Alexey Bataeve3727102018-04-18 15:57:46 +0000922 for (const ValueDecl *D : Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000923 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
924 if (Cache.count(VD))
925 continue;
926 ++TotalNum;
927 Cache.insert(VD);
928 }
929 return TotalNum;
930}
931
Michael Kruse4304e9d2019-02-19 16:38:20 +0000932OMPMapClause *OMPMapClause::Create(
933 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
934 ArrayRef<ValueDecl *> Declarations,
935 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
936 ArrayRef<OpenMPMapModifierKind> MapModifiers,
937 ArrayRef<SourceLocation> MapModifiersLoc,
938 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
939 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
940 OMPMappableExprListSizeTy Sizes;
941 Sizes.NumVars = Vars.size();
942 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
943 Sizes.NumComponentLists = ComponentLists.size();
944 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao90927002016-04-26 14:54:23 +0000945
946 // We need to allocate:
Michael Kruse4304e9d2019-02-19 16:38:20 +0000947 // 2 x NumVars x Expr* - we have an original list expression and an associated
948 // user-defined mapper for each clause list entry.
Samuel Antao90927002016-04-26 14:54:23 +0000949 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
950 // with each component list.
951 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
952 // number of lists for each unique declaration and the size of each component
953 // list.
954 // NumComponents x MappableComponent - the total of all the components in all
955 // the lists.
956 void *Mem = C.Allocate(
957 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
958 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000959 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
960 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
961 Sizes.NumComponents));
962 OMPMapClause *Clause = new (Mem)
963 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
964 Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
Samuel Antao90927002016-04-26 14:54:23 +0000965
966 Clause->setVarRefs(Vars);
Michael Kruse4304e9d2019-02-19 16:38:20 +0000967 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao90927002016-04-26 14:54:23 +0000968 Clause->setClauseInfo(Declarations, ComponentLists);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000969 Clause->setMapType(Type);
970 Clause->setMapLoc(TypeLoc);
971 return Clause;
972}
973
Michael Kruse4304e9d2019-02-19 16:38:20 +0000974OMPMapClause *
975OMPMapClause::CreateEmpty(const ASTContext &C,
976 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao90927002016-04-26 14:54:23 +0000977 void *Mem = C.Allocate(
978 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
979 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000980 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
981 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
982 Sizes.NumComponents));
983 return new (Mem) OMPMapClause(Sizes);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000984}
Samuel Antao661c0902016-05-26 17:39:58 +0000985
Michael Kruse01f670d2019-02-22 22:29:42 +0000986OMPToClause *OMPToClause::Create(
987 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
988 ArrayRef<ValueDecl *> Declarations,
989 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
990 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000991 OMPMappableExprListSizeTy Sizes;
992 Sizes.NumVars = Vars.size();
993 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
994 Sizes.NumComponentLists = ComponentLists.size();
995 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao661c0902016-05-26 17:39:58 +0000996
997 // We need to allocate:
Michael Kruse01f670d2019-02-22 22:29:42 +0000998 // 2 x NumVars x Expr* - we have an original list expression and an associated
999 // user-defined mapper for each clause list entry.
Samuel Antao661c0902016-05-26 17:39:58 +00001000 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1001 // with each component list.
1002 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1003 // number of lists for each unique declaration and the size of each component
1004 // list.
1005 // NumComponents x MappableComponent - the total of all the components in all
1006 // the lists.
1007 void *Mem = C.Allocate(
1008 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1009 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +00001010 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001011 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1012 Sizes.NumComponents));
Samuel Antao661c0902016-05-26 17:39:58 +00001013
Michael Kruse01f670d2019-02-22 22:29:42 +00001014 auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +00001015
1016 Clause->setVarRefs(Vars);
Michael Kruse01f670d2019-02-22 22:29:42 +00001017 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao661c0902016-05-26 17:39:58 +00001018 Clause->setClauseInfo(Declarations, ComponentLists);
1019 return Clause;
1020}
1021
Michael Kruse4304e9d2019-02-19 16:38:20 +00001022OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
1023 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao661c0902016-05-26 17:39:58 +00001024 void *Mem = C.Allocate(
1025 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1026 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +00001027 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001028 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1029 Sizes.NumComponents));
1030 return new (Mem) OMPToClause(Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +00001031}
Samuel Antaoec172c62016-05-26 17:49:04 +00001032
Michael Kruse0336c752019-02-25 20:34:15 +00001033OMPFromClause *OMPFromClause::Create(
1034 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1035 ArrayRef<ValueDecl *> Declarations,
1036 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1037 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001038 OMPMappableExprListSizeTy Sizes;
1039 Sizes.NumVars = Vars.size();
1040 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1041 Sizes.NumComponentLists = ComponentLists.size();
1042 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaoec172c62016-05-26 17:49:04 +00001043
1044 // We need to allocate:
Michael Kruse0336c752019-02-25 20:34:15 +00001045 // 2 x NumVars x Expr* - we have an original list expression and an associated
1046 // user-defined mapper for each clause list entry.
Samuel Antaoec172c62016-05-26 17:49:04 +00001047 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1048 // with each component list.
1049 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1050 // number of lists for each unique declaration and the size of each component
1051 // list.
1052 // NumComponents x MappableComponent - the total of all the components in all
1053 // the lists.
1054 void *Mem = C.Allocate(
1055 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1056 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001057 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001058 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1059 Sizes.NumComponents));
Samuel Antaoec172c62016-05-26 17:49:04 +00001060
Michael Kruse0336c752019-02-25 20:34:15 +00001061 auto *Clause =
1062 new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001063
1064 Clause->setVarRefs(Vars);
Michael Kruse0336c752019-02-25 20:34:15 +00001065 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antaoec172c62016-05-26 17:49:04 +00001066 Clause->setClauseInfo(Declarations, ComponentLists);
1067 return Clause;
1068}
1069
Michael Kruse4304e9d2019-02-19 16:38:20 +00001070OMPFromClause *
1071OMPFromClause::CreateEmpty(const ASTContext &C,
1072 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaoec172c62016-05-26 17:49:04 +00001073 void *Mem = C.Allocate(
1074 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1075 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001076 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001077 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1078 Sizes.NumComponents));
1079 return new (Mem) OMPFromClause(Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001080}
Carlo Bertolli2404b172016-07-13 15:37:16 +00001081
Samuel Antaocc10b852016-07-28 14:23:26 +00001082void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1083 assert(VL.size() == varlist_size() &&
1084 "Number of private copies is not the same as the preallocated buffer");
1085 std::copy(VL.begin(), VL.end(), varlist_end());
1086}
1087
1088void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
1089 assert(VL.size() == varlist_size() &&
1090 "Number of inits is not the same as the preallocated buffer");
1091 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1092}
1093
1094OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001095 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1096 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
1097 ArrayRef<ValueDecl *> Declarations,
Samuel Antaocc10b852016-07-28 14:23:26 +00001098 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001099 OMPMappableExprListSizeTy Sizes;
1100 Sizes.NumVars = Vars.size();
1101 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1102 Sizes.NumComponentLists = ComponentLists.size();
1103 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaocc10b852016-07-28 14:23:26 +00001104
1105 // We need to allocate:
1106 // 3 x NumVars x Expr* - we have an original list expression for each clause
1107 // list entry and an equal number of private copies and inits.
1108 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1109 // with each component list.
1110 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1111 // number of lists for each unique declaration and the size of each component
1112 // list.
1113 // NumComponents x MappableComponent - the total of all the components in all
1114 // the lists.
1115 void *Mem = C.Allocate(
1116 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1117 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001118 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1119 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1120 Sizes.NumComponents));
Samuel Antaocc10b852016-07-28 14:23:26 +00001121
Michael Kruse4304e9d2019-02-19 16:38:20 +00001122 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
Samuel Antaocc10b852016-07-28 14:23:26 +00001123
1124 Clause->setVarRefs(Vars);
1125 Clause->setPrivateCopies(PrivateVars);
1126 Clause->setInits(Inits);
1127 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001128 return Clause;
1129}
1130
Michael Kruse4304e9d2019-02-19 16:38:20 +00001131OMPUseDevicePtrClause *
1132OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
1133 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaocc10b852016-07-28 14:23:26 +00001134 void *Mem = C.Allocate(
1135 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1136 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001137 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1138 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1139 Sizes.NumComponents));
1140 return new (Mem) OMPUseDevicePtrClause(Sizes);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001141}
Carlo Bertolli70594e92016-07-13 17:16:49 +00001142
Samuel Antao6890b092016-07-28 14:25:09 +00001143OMPIsDevicePtrClause *
Michael Kruse4304e9d2019-02-19 16:38:20 +00001144OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
Samuel Antao6890b092016-07-28 14:25:09 +00001145 ArrayRef<Expr *> Vars,
1146 ArrayRef<ValueDecl *> Declarations,
1147 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001148 OMPMappableExprListSizeTy Sizes;
1149 Sizes.NumVars = Vars.size();
1150 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1151 Sizes.NumComponentLists = ComponentLists.size();
1152 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao6890b092016-07-28 14:25:09 +00001153
1154 // We need to allocate:
1155 // NumVars x Expr* - we have an original list expression for each clause list
1156 // entry.
1157 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1158 // with each component list.
1159 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1160 // number of lists for each unique declaration and the size of each component
1161 // list.
1162 // NumComponents x MappableComponent - the total of all the components in all
1163 // the lists.
1164 void *Mem = C.Allocate(
1165 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1166 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001167 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1168 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1169 Sizes.NumComponents));
Samuel Antao6890b092016-07-28 14:25:09 +00001170
Michael Kruse4304e9d2019-02-19 16:38:20 +00001171 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
Samuel Antao6890b092016-07-28 14:25:09 +00001172
1173 Clause->setVarRefs(Vars);
1174 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001175 return Clause;
1176}
1177
Michael Kruse4304e9d2019-02-19 16:38:20 +00001178OMPIsDevicePtrClause *
1179OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1180 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao6890b092016-07-28 14:25:09 +00001181 void *Mem = C.Allocate(
1182 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1183 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001184 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1185 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1186 Sizes.NumComponents));
1187 return new (Mem) OMPIsDevicePtrClause(Sizes);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001188}
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001189
Alexey Bataevb6e70842019-12-16 15:54:17 -05001190OMPNontemporalClause *OMPNontemporalClause::Create(const ASTContext &C,
1191 SourceLocation StartLoc,
1192 SourceLocation LParenLoc,
1193 SourceLocation EndLoc,
1194 ArrayRef<Expr *> VL) {
Alexey Bataev0860db92019-12-19 10:01:10 -05001195 // Allocate space for nontemporal variables + private references.
1196 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
Alexey Bataevb6e70842019-12-16 15:54:17 -05001197 auto *Clause =
1198 new (Mem) OMPNontemporalClause(StartLoc, LParenLoc, EndLoc, VL.size());
1199 Clause->setVarRefs(VL);
1200 return Clause;
1201}
1202
1203OMPNontemporalClause *OMPNontemporalClause::CreateEmpty(const ASTContext &C,
1204 unsigned N) {
Alexey Bataev0860db92019-12-19 10:01:10 -05001205 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
Alexey Bataevb6e70842019-12-16 15:54:17 -05001206 return new (Mem) OMPNontemporalClause(N);
1207}
1208
Alexey Bataev0860db92019-12-19 10:01:10 -05001209void OMPNontemporalClause::setPrivateRefs(ArrayRef<Expr *> VL) {
1210 assert(VL.size() == varlist_size() && "Number of private references is not "
1211 "the same as the preallocated buffer");
1212 std::copy(VL.begin(), VL.end(), varlist_end());
1213}
1214
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001215//===----------------------------------------------------------------------===//
1216// OpenMP clauses printing methods
1217//===----------------------------------------------------------------------===//
1218
1219void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1220 OS << "if(";
Johannes Doerferteb3e81f2019-11-04 22:00:49 -06001221 if (Node->getNameModifier() != llvm::omp::OMPD_unknown)
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001222 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1223 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1224 OS << ")";
1225}
1226
1227void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1228 OS << "final(";
1229 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1230 OS << ")";
1231}
1232
1233void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1234 OS << "num_threads(";
1235 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1236 OS << ")";
1237}
1238
1239void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1240 OS << "safelen(";
1241 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1242 OS << ")";
1243}
1244
1245void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1246 OS << "simdlen(";
1247 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1248 OS << ")";
1249}
1250
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00001251void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
1252 OS << "allocator(";
1253 Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
1254 OS << ")";
1255}
1256
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001257void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1258 OS << "collapse(";
1259 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1260 OS << ")";
1261}
1262
1263void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1264 OS << "default("
Atmn Patel577c9b02020-02-14 21:45:49 -06001265 << getOpenMPSimpleClauseTypeName(OMPC_default,
1266 unsigned(Node->getDefaultKind()))
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001267 << ")";
1268}
1269
1270void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1271 OS << "proc_bind("
Johannes Doerfert6c5d1f402019-12-25 18:15:36 -06001272 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind,
1273 unsigned(Node->getProcBindKind()))
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001274 << ")";
1275}
1276
1277void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1278 OS << "unified_address";
1279}
1280
1281void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1282 OMPUnifiedSharedMemoryClause *) {
1283 OS << "unified_shared_memory";
1284}
1285
1286void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1287 OS << "reverse_offload";
1288}
1289
1290void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1291 OMPDynamicAllocatorsClause *) {
1292 OS << "dynamic_allocators";
1293}
1294
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00001295void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1296 OMPAtomicDefaultMemOrderClause *Node) {
1297 OS << "atomic_default_mem_order("
1298 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1299 Node->getAtomicDefaultMemOrderKind())
1300 << ")";
1301}
1302
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001303void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1304 OS << "schedule(";
1305 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1306 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1307 Node->getFirstScheduleModifier());
1308 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1309 OS << ", ";
1310 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1311 Node->getSecondScheduleModifier());
1312 }
1313 OS << ": ";
1314 }
1315 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1316 if (auto *E = Node->getChunkSize()) {
1317 OS << ", ";
1318 E->printPretty(OS, nullptr, Policy);
1319 }
1320 OS << ")";
1321}
1322
1323void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1324 OS << "ordered";
1325 if (auto *Num = Node->getNumForLoops()) {
1326 OS << "(";
1327 Num->printPretty(OS, nullptr, Policy, 0);
1328 OS << ")";
1329 }
1330}
1331
1332void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1333 OS << "nowait";
1334}
1335
1336void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1337 OS << "untied";
1338}
1339
1340void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1341 OS << "nogroup";
1342}
1343
1344void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1345 OS << "mergeable";
1346}
1347
1348void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1349
1350void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1351
1352void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
1353 OS << "update";
1354}
1355
1356void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1357 OS << "capture";
1358}
1359
1360void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1361 OS << "seq_cst";
1362}
1363
Alexey Bataevea9166b2020-02-06 16:30:23 -05001364void OMPClausePrinter::VisitOMPAcqRelClause(OMPAcqRelClause *) {
1365 OS << "acq_rel";
1366}
1367
Alexey Bataev04a830f2020-02-10 14:30:39 -05001368void OMPClausePrinter::VisitOMPAcquireClause(OMPAcquireClause *) {
1369 OS << "acquire";
1370}
1371
Alexey Bataev95598342020-02-10 15:49:05 -05001372void OMPClausePrinter::VisitOMPReleaseClause(OMPReleaseClause *) {
1373 OS << "release";
1374}
1375
Alexey Bataev9a8defc2020-02-11 11:10:43 -05001376void OMPClausePrinter::VisitOMPRelaxedClause(OMPRelaxedClause *) {
1377 OS << "relaxed";
1378}
1379
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001380void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1381 OS << "threads";
1382}
1383
1384void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1385
1386void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1387 OS << "device(";
1388 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1389 OS << ")";
1390}
1391
1392void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1393 OS << "num_teams(";
1394 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1395 OS << ")";
1396}
1397
1398void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1399 OS << "thread_limit(";
1400 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1401 OS << ")";
1402}
1403
1404void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1405 OS << "priority(";
1406 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1407 OS << ")";
1408}
1409
1410void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1411 OS << "grainsize(";
1412 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1413 OS << ")";
1414}
1415
1416void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1417 OS << "num_tasks(";
1418 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1419 OS << ")";
1420}
1421
1422void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1423 OS << "hint(";
1424 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1425 OS << ")";
1426}
1427
Alexey Bataev375437a2020-03-02 14:21:20 -05001428void OMPClausePrinter::VisitOMPDestroyClause(OMPDestroyClause *) {
1429 OS << "destroy";
1430}
1431
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001432template<typename T>
1433void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1434 for (typename T::varlist_iterator I = Node->varlist_begin(),
1435 E = Node->varlist_end();
1436 I != E; ++I) {
1437 assert(*I && "Expected non-null Stmt");
1438 OS << (I == Node->varlist_begin() ? StartSym : ',');
1439 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1440 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1441 DRE->printPretty(OS, nullptr, Policy, 0);
1442 else
1443 DRE->getDecl()->printQualifiedName(OS);
1444 } else
1445 (*I)->printPretty(OS, nullptr, Policy, 0);
1446 }
1447}
1448
Alexey Bataeve04483e2019-03-27 14:14:31 +00001449void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
1450 if (Node->varlist_empty())
1451 return;
1452 OS << "allocate";
1453 if (Expr *Allocator = Node->getAllocator()) {
1454 OS << "(";
1455 Allocator->printPretty(OS, nullptr, Policy, 0);
1456 OS << ":";
1457 VisitOMPClauseList(Node, ' ');
1458 } else {
1459 VisitOMPClauseList(Node, '(');
1460 }
1461 OS << ")";
1462}
1463
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001464void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1465 if (!Node->varlist_empty()) {
1466 OS << "private";
1467 VisitOMPClauseList(Node, '(');
1468 OS << ")";
1469 }
1470}
1471
1472void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1473 if (!Node->varlist_empty()) {
1474 OS << "firstprivate";
1475 VisitOMPClauseList(Node, '(');
1476 OS << ")";
1477 }
1478}
1479
1480void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1481 if (!Node->varlist_empty()) {
1482 OS << "lastprivate";
Alexey Bataev93dc40d2019-12-20 11:04:57 -05001483 OpenMPLastprivateModifier LPKind = Node->getKind();
1484 if (LPKind != OMPC_LASTPRIVATE_unknown) {
1485 OS << "("
1486 << getOpenMPSimpleClauseTypeName(OMPC_lastprivate, Node->getKind())
1487 << ":";
1488 }
1489 VisitOMPClauseList(Node, LPKind == OMPC_LASTPRIVATE_unknown ? '(' : ' ');
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001490 OS << ")";
1491 }
1492}
1493
1494void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1495 if (!Node->varlist_empty()) {
1496 OS << "shared";
1497 VisitOMPClauseList(Node, '(');
1498 OS << ")";
1499 }
1500}
1501
1502void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1503 if (!Node->varlist_empty()) {
1504 OS << "reduction(";
1505 NestedNameSpecifier *QualifierLoc =
1506 Node->getQualifierLoc().getNestedNameSpecifier();
1507 OverloadedOperatorKind OOK =
1508 Node->getNameInfo().getName().getCXXOverloadedOperator();
1509 if (QualifierLoc == nullptr && OOK != OO_None) {
1510 // Print reduction identifier in C format
1511 OS << getOperatorSpelling(OOK);
1512 } else {
1513 // Use C++ format
1514 if (QualifierLoc != nullptr)
1515 QualifierLoc->print(OS, Policy);
1516 OS << Node->getNameInfo();
1517 }
1518 OS << ":";
1519 VisitOMPClauseList(Node, ' ');
1520 OS << ")";
1521 }
1522}
1523
1524void OMPClausePrinter::VisitOMPTaskReductionClause(
1525 OMPTaskReductionClause *Node) {
1526 if (!Node->varlist_empty()) {
1527 OS << "task_reduction(";
1528 NestedNameSpecifier *QualifierLoc =
1529 Node->getQualifierLoc().getNestedNameSpecifier();
1530 OverloadedOperatorKind OOK =
1531 Node->getNameInfo().getName().getCXXOverloadedOperator();
1532 if (QualifierLoc == nullptr && OOK != OO_None) {
1533 // Print reduction identifier in C format
1534 OS << getOperatorSpelling(OOK);
1535 } else {
1536 // Use C++ format
1537 if (QualifierLoc != nullptr)
1538 QualifierLoc->print(OS, Policy);
1539 OS << Node->getNameInfo();
1540 }
1541 OS << ":";
1542 VisitOMPClauseList(Node, ' ');
1543 OS << ")";
1544 }
1545}
1546
1547void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1548 if (!Node->varlist_empty()) {
1549 OS << "in_reduction(";
1550 NestedNameSpecifier *QualifierLoc =
1551 Node->getQualifierLoc().getNestedNameSpecifier();
1552 OverloadedOperatorKind OOK =
1553 Node->getNameInfo().getName().getCXXOverloadedOperator();
1554 if (QualifierLoc == nullptr && OOK != OO_None) {
1555 // Print reduction identifier in C format
1556 OS << getOperatorSpelling(OOK);
1557 } else {
1558 // Use C++ format
1559 if (QualifierLoc != nullptr)
1560 QualifierLoc->print(OS, Policy);
1561 OS << Node->getNameInfo();
1562 }
1563 OS << ":";
1564 VisitOMPClauseList(Node, ' ');
1565 OS << ")";
1566 }
1567}
1568
1569void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1570 if (!Node->varlist_empty()) {
1571 OS << "linear";
1572 if (Node->getModifierLoc().isValid()) {
1573 OS << '('
1574 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1575 }
1576 VisitOMPClauseList(Node, '(');
1577 if (Node->getModifierLoc().isValid())
1578 OS << ')';
1579 if (Node->getStep() != nullptr) {
1580 OS << ": ";
1581 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1582 }
1583 OS << ")";
1584 }
1585}
1586
1587void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1588 if (!Node->varlist_empty()) {
1589 OS << "aligned";
1590 VisitOMPClauseList(Node, '(');
1591 if (Node->getAlignment() != nullptr) {
1592 OS << ": ";
1593 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1594 }
1595 OS << ")";
1596 }
1597}
1598
1599void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1600 if (!Node->varlist_empty()) {
1601 OS << "copyin";
1602 VisitOMPClauseList(Node, '(');
1603 OS << ")";
1604 }
1605}
1606
1607void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1608 if (!Node->varlist_empty()) {
1609 OS << "copyprivate";
1610 VisitOMPClauseList(Node, '(');
1611 OS << ")";
1612 }
1613}
1614
1615void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1616 if (!Node->varlist_empty()) {
1617 VisitOMPClauseList(Node, '(');
1618 OS << ")";
1619 }
1620}
1621
Alexey Bataevc112e942020-02-28 09:52:15 -05001622void OMPClausePrinter::VisitOMPDepobjClause(OMPDepobjClause *Node) {
1623 OS << "(";
1624 Node->getDepobj()->printPretty(OS, nullptr, Policy, 0);
1625 OS << ")";
1626}
1627
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001628void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1629 OS << "depend(";
1630 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1631 Node->getDependencyKind());
1632 if (!Node->varlist_empty()) {
1633 OS << " :";
1634 VisitOMPClauseList(Node, ' ');
1635 }
1636 OS << ")";
1637}
1638
1639void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1640 if (!Node->varlist_empty()) {
1641 OS << "map(";
1642 if (Node->getMapType() != OMPC_MAP_unknown) {
Kelvin Lief579432018-12-18 22:18:41 +00001643 for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1644 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1645 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1646 Node->getMapTypeModifier(I));
Michael Kruse4304e9d2019-02-19 16:38:20 +00001647 if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1648 OS << '(';
1649 NestedNameSpecifier *MapperNNS =
1650 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1651 if (MapperNNS)
1652 MapperNNS->print(OS, Policy);
1653 OS << Node->getMapperIdInfo() << ')';
1654 }
Kelvin Lief579432018-12-18 22:18:41 +00001655 OS << ',';
1656 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001657 }
1658 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1659 OS << ':';
1660 }
1661 VisitOMPClauseList(Node, ' ');
1662 OS << ")";
1663 }
1664}
1665
1666void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1667 if (!Node->varlist_empty()) {
1668 OS << "to";
Michael Kruse01f670d2019-02-22 22:29:42 +00001669 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1670 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1671 OS << '(';
1672 OS << "mapper(";
1673 NestedNameSpecifier *MapperNNS =
1674 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1675 if (MapperNNS)
1676 MapperNNS->print(OS, Policy);
1677 OS << MapperId << "):";
1678 VisitOMPClauseList(Node, ' ');
1679 } else {
1680 VisitOMPClauseList(Node, '(');
1681 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001682 OS << ")";
1683 }
1684}
1685
1686void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1687 if (!Node->varlist_empty()) {
1688 OS << "from";
Michael Kruse0336c752019-02-25 20:34:15 +00001689 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1690 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1691 OS << '(';
1692 OS << "mapper(";
1693 NestedNameSpecifier *MapperNNS =
1694 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1695 if (MapperNNS)
1696 MapperNNS->print(OS, Policy);
1697 OS << MapperId << "):";
1698 VisitOMPClauseList(Node, ' ');
1699 } else {
1700 VisitOMPClauseList(Node, '(');
1701 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001702 OS << ")";
1703 }
1704}
1705
1706void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1707 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1708 OMPC_dist_schedule, Node->getDistScheduleKind());
1709 if (auto *E = Node->getChunkSize()) {
1710 OS << ", ";
1711 E->printPretty(OS, nullptr, Policy);
1712 }
1713 OS << ")";
1714}
1715
1716void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1717 OS << "defaultmap(";
1718 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1719 Node->getDefaultmapModifier());
1720 OS << ": ";
1721 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1722 Node->getDefaultmapKind());
1723 OS << ")";
1724}
1725
1726void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1727 if (!Node->varlist_empty()) {
1728 OS << "use_device_ptr";
1729 VisitOMPClauseList(Node, '(');
1730 OS << ")";
1731 }
1732}
1733
1734void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1735 if (!Node->varlist_empty()) {
1736 OS << "is_device_ptr";
1737 VisitOMPClauseList(Node, '(');
1738 OS << ")";
1739 }
1740}
1741
Alexey Bataevb6e70842019-12-16 15:54:17 -05001742void OMPClausePrinter::VisitOMPNontemporalClause(OMPNontemporalClause *Node) {
1743 if (!Node->varlist_empty()) {
1744 OS << "nontemporal";
1745 VisitOMPClauseList(Node, '(');
1746 OS << ")";
1747 }
1748}
Alexey Bataevcb8e6912020-01-31 16:09:26 -05001749
1750void OMPClausePrinter::VisitOMPOrderClause(OMPOrderClause *Node) {
1751 OS << "order(" << getOpenMPSimpleClauseTypeName(OMPC_order, Node->getKind())
1752 << ")";
1753}
Johannes Doerfert1228d422019-12-19 20:42:12 -06001754
1755void OMPTraitInfo::getAsVariantMatchInfo(
1756 ASTContext &ASTCtx, llvm::omp::VariantMatchInfo &VMI) const {
1757 for (const OMPTraitSet &Set : Sets) {
1758 for (const OMPTraitSelector &Selector : Set.Selectors) {
1759
1760 // User conditions are special as we evaluate the condition here.
1761 if (Selector.Kind == llvm::omp::TraitSelector::user_condition) {
1762 assert(Selector.ScoreOrCondition &&
1763 "Ill-formed user condition, expected condition expression!");
1764 assert(Selector.Properties.size() == 1 &&
1765 Selector.Properties.front().Kind ==
1766 llvm::omp::TraitProperty::user_condition_unknown &&
1767 "Ill-formed user condition, expected unknown trait property!");
1768
1769 llvm::APInt CondVal =
1770 Selector.ScoreOrCondition->EvaluateKnownConstInt(ASTCtx);
1771 VMI.addTrait(CondVal.isNullValue()
1772 ? llvm::omp::TraitProperty::user_condition_false
1773 : llvm::omp::TraitProperty::user_condition_true);
1774 continue;
1775 }
1776
1777 llvm::APInt Score;
1778 llvm::APInt *ScorePtr = nullptr;
1779 if (Selector.ScoreOrCondition) {
1780 Score = Selector.ScoreOrCondition->EvaluateKnownConstInt(ASTCtx);
1781 ScorePtr = &Score;
1782 }
1783 for (const OMPTraitProperty &Property : Selector.Properties)
1784 VMI.addTrait(Set.Kind, Property.Kind, ScorePtr);
1785
1786 if (Set.Kind != llvm::omp::TraitSet::construct)
1787 continue;
1788
1789 // TODO: This might not hold once we implement SIMD properly.
1790 assert(Selector.Properties.size() == 1 &&
1791 Selector.Properties.front().Kind ==
1792 llvm::omp::getOpenMPContextTraitPropertyForSelector(
1793 Selector.Kind) &&
1794 "Ill-formed construct selector!");
1795
1796 VMI.ConstructTraits.push_back(Selector.Properties.front().Kind);
1797 }
1798 }
1799}
1800
1801void OMPTraitInfo::print(llvm::raw_ostream &OS,
1802 const PrintingPolicy &Policy) const {
1803 bool FirstSet = true;
1804 for (const OMPTraitInfo::OMPTraitSet &Set : Sets) {
1805 if (!FirstSet)
1806 OS << ", ";
1807 FirstSet = false;
1808 OS << llvm::omp::getOpenMPContextTraitSetName(Set.Kind) << "={";
1809
1810 bool FirstSelector = true;
1811 for (const OMPTraitInfo::OMPTraitSelector &Selector : Set.Selectors) {
1812 if (!FirstSelector)
1813 OS << ", ";
1814 FirstSelector = false;
1815 OS << llvm::omp::getOpenMPContextTraitSelectorName(Selector.Kind);
1816
1817 bool AllowsTraitScore = false;
1818 bool RequiresProperty = false;
1819 llvm::omp::isValidTraitSelectorForTraitSet(
1820 Selector.Kind, Set.Kind, AllowsTraitScore, RequiresProperty);
1821
1822 if (!RequiresProperty)
1823 continue;
1824
1825 OS << "(";
1826 if (Selector.Kind == llvm::omp::TraitSelector::user_condition) {
1827 Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy);
1828 } else {
1829
1830 if (Selector.ScoreOrCondition) {
1831 OS << "score(";
1832 Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy);
1833 OS << "): ";
1834 }
1835
1836 bool FirstProperty = true;
1837 for (const OMPTraitInfo::OMPTraitProperty &Property :
1838 Selector.Properties) {
1839 if (!FirstProperty)
1840 OS << ", ";
1841 FirstProperty = false;
1842 OS << llvm::omp::getOpenMPContextTraitPropertyName(Property.Kind);
1843 }
1844 }
1845 OS << ")";
1846 }
1847 OS << "}";
1848 }
1849}
1850
1851llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS,
1852 const OMPTraitInfo &TI) {
1853 LangOptions LO;
1854 PrintingPolicy Policy(LO);
1855 TI.print(OS, Policy);
1856 return OS;
1857}