blob: fc7912d6fdcac103bbaaccec53447d0af8dc48f2 [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;
27
28OMPClause::child_range OMPClause::children() {
29 switch (getClauseKind()) {
30 default:
31 break;
32#define OPENMP_CLAUSE(Name, Class) \
33 case OMPC_##Name: \
34 return static_cast<Class *>(this)->children();
35#include "clang/Basic/OpenMPKinds.def"
36 }
37 llvm_unreachable("unknown OMPClause");
38}
39
Alexey Bataevc2c21ef2019-07-11 14:54:17 +000040OMPClause::child_range OMPClause::used_children() {
41 switch (getClauseKind()) {
42#define OPENMP_CLAUSE(Name, Class) \
43 case OMPC_##Name: \
44 return static_cast<Class *>(this)->used_children();
45#include "clang/Basic/OpenMPKinds.def"
46 case OMPC_threadprivate:
47 case OMPC_uniform:
Alexey Bataev729e2422019-08-23 16:11:14 +000048 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +000049 case OMPC_match:
Alexey Bataevc2c21ef2019-07-11 14:54:17 +000050 case OMPC_unknown:
51 break;
52 }
53 llvm_unreachable("unknown OMPClause");
54}
55
Alexey Bataev3392d762016-02-16 11:18:12 +000056OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
57 auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
58 return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr;
59}
60
61const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
62 switch (C->getClauseKind()) {
63 case OMPC_schedule:
64 return static_cast<const OMPScheduleClause *>(C);
65 case OMPC_dist_schedule:
66 return static_cast<const OMPDistScheduleClause *>(C);
Alexey Bataev417089f2016-02-17 13:19:37 +000067 case OMPC_firstprivate:
68 return static_cast<const OMPFirstprivateClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +000069 case OMPC_lastprivate:
70 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +000071 case OMPC_reduction:
72 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +000073 case OMPC_task_reduction:
74 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +000075 case OMPC_in_reduction:
76 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +000077 case OMPC_linear:
78 return static_cast<const OMPLinearClause *>(C);
Arpith Chacko Jacobfe4890a2017-01-18 20:40:48 +000079 case OMPC_if:
80 return static_cast<const OMPIfClause *>(C);
Arpith Chacko Jacob33c849a2017-01-25 00:57:16 +000081 case OMPC_num_threads:
82 return static_cast<const OMPNumThreadsClause *>(C);
Arpith Chacko Jacobbc126342017-01-25 11:28:18 +000083 case OMPC_num_teams:
84 return static_cast<const OMPNumTeamsClause *>(C);
Arpith Chacko Jacob7ecc0b72017-01-25 11:44:35 +000085 case OMPC_thread_limit:
86 return static_cast<const OMPThreadLimitClause *>(C);
Alexey Bataev931e19b2017-10-02 16:32:39 +000087 case OMPC_device:
88 return static_cast<const OMPDeviceClause *>(C);
Alexey Bataevb9c55e22019-10-14 19:29:52 +000089 case OMPC_grainsize:
90 return static_cast<const OMPGrainsizeClause *>(C);
Alexey Bataevd88c7de2019-10-14 20:44:34 +000091 case OMPC_num_tasks:
92 return static_cast<const OMPNumTasksClause *>(C);
Alexey Bataev3a842ec2019-10-15 19:37:05 +000093 case OMPC_final:
94 return static_cast<const OMPFinalClause *>(C);
Alexey Bataev31ba4762019-10-16 18:09:37 +000095 case OMPC_priority:
96 return static_cast<const OMPPriorityClause *>(C);
Alexey Bataev3392d762016-02-16 11:18:12 +000097 case OMPC_default:
98 case OMPC_proc_bind:
Alexey Bataev3392d762016-02-16 11:18:12 +000099 case OMPC_safelen:
100 case OMPC_simdlen:
Alexey Bataev9cc10fc2019-03-12 18:52:33 +0000101 case OMPC_allocator:
Alexey Bataeve04483e2019-03-27 14:14:31 +0000102 case OMPC_allocate:
Alexey Bataev3392d762016-02-16 11:18:12 +0000103 case OMPC_collapse:
104 case OMPC_private:
Alexey Bataev005248a2016-02-25 05:25:57 +0000105 case OMPC_shared:
Alexey Bataev005248a2016-02-25 05:25:57 +0000106 case OMPC_aligned:
107 case OMPC_copyin:
108 case OMPC_copyprivate:
109 case OMPC_ordered:
110 case OMPC_nowait:
111 case OMPC_untied:
112 case OMPC_mergeable:
113 case OMPC_threadprivate:
114 case OMPC_flush:
Alexey Bataevc112e942020-02-28 09:52:15 -0500115 case OMPC_depobj:
Alexey Bataev005248a2016-02-25 05:25:57 +0000116 case OMPC_read:
117 case OMPC_write:
118 case OMPC_update:
119 case OMPC_capture:
120 case OMPC_seq_cst:
Alexey Bataevea9166b2020-02-06 16:30:23 -0500121 case OMPC_acq_rel:
Alexey Bataev04a830f2020-02-10 14:30:39 -0500122 case OMPC_acquire:
Alexey Bataev95598342020-02-10 15:49:05 -0500123 case OMPC_release:
Alexey Bataev9a8defc2020-02-11 11:10:43 -0500124 case OMPC_relaxed:
Alexey Bataev005248a2016-02-25 05:25:57 +0000125 case OMPC_depend:
Alexey Bataev005248a2016-02-25 05:25:57 +0000126 case OMPC_threads:
127 case OMPC_simd:
128 case OMPC_map:
Alexey Bataev005248a2016-02-25 05:25:57 +0000129 case OMPC_nogroup:
Alexey Bataev005248a2016-02-25 05:25:57 +0000130 case OMPC_hint:
131 case OMPC_defaultmap:
132 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000133 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000134 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000135 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000136 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000137 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000138 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000139 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000140 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000141 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000142 case OMPC_atomic_default_mem_order:
Alexey Bataev729e2422019-08-23 16:11:14 +0000143 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +0000144 case OMPC_match:
Alexey Bataevb6e70842019-12-16 15:54:17 -0500145 case OMPC_nontemporal:
Alexey Bataevcb8e6912020-01-31 16:09:26 -0500146 case OMPC_order:
Alexey Bataev375437a2020-03-02 14:21:20 -0500147 case OMPC_destroy:
Alexey Bataev0f0564b2020-03-17 09:17:42 -0400148 case OMPC_detach:
Alexey Bataev06dea732020-03-20 09:41:22 -0400149 case OMPC_inclusive:
Alexey Bataev63828a32020-03-23 10:41:08 -0400150 case OMPC_exclusive:
Alexey Bataev005248a2016-02-25 05:25:57 +0000151 break;
152 }
153
154 return nullptr;
155}
156
157OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
158 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
159 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
160}
161
162const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
163 switch (C->getClauseKind()) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000164 case OMPC_lastprivate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000165 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000166 case OMPC_reduction:
167 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +0000168 case OMPC_task_reduction:
169 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000170 case OMPC_in_reduction:
171 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000172 case OMPC_linear:
173 return static_cast<const OMPLinearClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000174 case OMPC_schedule:
175 case OMPC_dist_schedule:
176 case OMPC_firstprivate:
177 case OMPC_default:
178 case OMPC_proc_bind:
179 case OMPC_if:
180 case OMPC_final:
181 case OMPC_num_threads:
182 case OMPC_safelen:
183 case OMPC_simdlen:
Alexey Bataev9cc10fc2019-03-12 18:52:33 +0000184 case OMPC_allocator:
Alexey Bataeve04483e2019-03-27 14:14:31 +0000185 case OMPC_allocate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000186 case OMPC_collapse:
187 case OMPC_private:
Alexey Bataev3392d762016-02-16 11:18:12 +0000188 case OMPC_shared:
Alexey Bataev3392d762016-02-16 11:18:12 +0000189 case OMPC_aligned:
190 case OMPC_copyin:
191 case OMPC_copyprivate:
192 case OMPC_ordered:
193 case OMPC_nowait:
194 case OMPC_untied:
195 case OMPC_mergeable:
196 case OMPC_threadprivate:
197 case OMPC_flush:
Alexey Bataevc112e942020-02-28 09:52:15 -0500198 case OMPC_depobj:
Alexey Bataev3392d762016-02-16 11:18:12 +0000199 case OMPC_read:
200 case OMPC_write:
201 case OMPC_update:
202 case OMPC_capture:
203 case OMPC_seq_cst:
Alexey Bataevea9166b2020-02-06 16:30:23 -0500204 case OMPC_acq_rel:
Alexey Bataev04a830f2020-02-10 14:30:39 -0500205 case OMPC_acquire:
Alexey Bataev95598342020-02-10 15:49:05 -0500206 case OMPC_release:
Alexey Bataev9a8defc2020-02-11 11:10:43 -0500207 case OMPC_relaxed:
Alexey Bataev3392d762016-02-16 11:18:12 +0000208 case OMPC_depend:
209 case OMPC_device:
210 case OMPC_threads:
211 case OMPC_simd:
212 case OMPC_map:
213 case OMPC_num_teams:
214 case OMPC_thread_limit:
215 case OMPC_priority:
216 case OMPC_grainsize:
217 case OMPC_nogroup:
218 case OMPC_num_tasks:
219 case OMPC_hint:
220 case OMPC_defaultmap:
221 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000222 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000223 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000224 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000225 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000226 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000227 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000228 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000229 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000230 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000231 case OMPC_atomic_default_mem_order:
Alexey Bataev729e2422019-08-23 16:11:14 +0000232 case OMPC_device_type:
Alexey Bataevdba792c2019-09-23 18:13:31 +0000233 case OMPC_match:
Alexey Bataevb6e70842019-12-16 15:54:17 -0500234 case OMPC_nontemporal:
Alexey Bataevcb8e6912020-01-31 16:09:26 -0500235 case OMPC_order:
Alexey Bataev375437a2020-03-02 14:21:20 -0500236 case OMPC_destroy:
Alexey Bataev0f0564b2020-03-17 09:17:42 -0400237 case OMPC_detach:
Alexey Bataev06dea732020-03-20 09:41:22 -0400238 case OMPC_inclusive:
Alexey Bataev63828a32020-03-23 10:41:08 -0400239 case OMPC_exclusive:
Alexey Bataev3392d762016-02-16 11:18:12 +0000240 break;
241 }
242
243 return nullptr;
244}
245
Alexey Bataev655cb4a2019-07-16 14:51:46 +0000246/// Gets the address of the original, non-captured, expression used in the
247/// clause as the preinitializer.
248static Stmt **getAddrOfExprAsWritten(Stmt *S) {
249 if (!S)
250 return nullptr;
251 if (auto *DS = dyn_cast<DeclStmt>(S)) {
252 assert(DS->isSingleDecl() && "Only single expression must be captured.");
253 if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
254 return OED->getInitAddress();
255 }
256 return nullptr;
257}
258
259OMPClause::child_range OMPIfClause::used_children() {
260 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
261 return child_range(C, C + 1);
262 return child_range(&Condition, &Condition + 1);
263}
264
Alexey Bataevb9c55e22019-10-14 19:29:52 +0000265OMPClause::child_range OMPGrainsizeClause::used_children() {
266 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
267 return child_range(C, C + 1);
268 return child_range(&Grainsize, &Grainsize + 1);
269}
270
Alexey Bataevd88c7de2019-10-14 20:44:34 +0000271OMPClause::child_range OMPNumTasksClause::used_children() {
272 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
273 return child_range(C, C + 1);
274 return child_range(&NumTasks, &NumTasks + 1);
275}
276
Alexey Bataev3a842ec2019-10-15 19:37:05 +0000277OMPClause::child_range OMPFinalClause::used_children() {
278 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
279 return child_range(C, C + 1);
280 return child_range(&Condition, &Condition + 1);
281}
282
Alexey Bataev31ba4762019-10-16 18:09:37 +0000283OMPClause::child_range OMPPriorityClause::used_children() {
284 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
285 return child_range(C, C + 1);
286 return child_range(&Priority, &Priority + 1);
287}
288
Alexey Bataevf138fda2018-08-13 19:04:24 +0000289OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
290 unsigned NumLoops,
291 SourceLocation StartLoc,
292 SourceLocation LParenLoc,
293 SourceLocation EndLoc) {
294 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
295 auto *Clause =
296 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
297 for (unsigned I = 0; I < NumLoops; ++I) {
298 Clause->setLoopNumIterations(I, nullptr);
299 Clause->setLoopCounter(I, nullptr);
300 }
301 return Clause;
302}
303
304OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
305 unsigned NumLoops) {
306 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
307 auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
308 for (unsigned I = 0; I < NumLoops; ++I) {
309 Clause->setLoopNumIterations(I, nullptr);
310 Clause->setLoopCounter(I, nullptr);
311 }
312 return Clause;
313}
314
315void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
316 Expr *NumIterations) {
317 assert(NumLoop < NumberOfLoops && "out of loops number.");
318 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
319}
320
321ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
322 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
323}
324
325void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
326 assert(NumLoop < NumberOfLoops && "out of loops number.");
327 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
328}
329
Mike Rice0ed46662018-09-20 17:19:41 +0000330Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000331 assert(NumLoop < NumberOfLoops && "out of loops number.");
332 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
333}
334
Mike Rice0ed46662018-09-20 17:19:41 +0000335const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000336 assert(NumLoop < NumberOfLoops && "out of loops number.");
337 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
338}
339
Alexey Bataev82f7c202020-03-03 13:22:35 -0500340OMPUpdateClause *OMPUpdateClause::Create(const ASTContext &C,
341 SourceLocation StartLoc,
342 SourceLocation EndLoc) {
343 return new (C) OMPUpdateClause(StartLoc, EndLoc, /*IsExtended=*/false);
344}
345
346OMPUpdateClause *
347OMPUpdateClause::Create(const ASTContext &C, SourceLocation StartLoc,
348 SourceLocation LParenLoc, SourceLocation ArgumentLoc,
349 OpenMPDependClauseKind DK, SourceLocation EndLoc) {
350 void *Mem =
351 C.Allocate(totalSizeToAlloc<SourceLocation, OpenMPDependClauseKind>(2, 1),
352 alignof(OMPUpdateClause));
353 auto *Clause =
354 new (Mem) OMPUpdateClause(StartLoc, EndLoc, /*IsExtended=*/true);
355 Clause->setLParenLoc(LParenLoc);
356 Clause->setArgumentLoc(ArgumentLoc);
357 Clause->setDependencyKind(DK);
358 return Clause;
359}
360
361OMPUpdateClause *OMPUpdateClause::CreateEmpty(const ASTContext &C,
362 bool IsExtended) {
363 if (!IsExtended)
364 return new (C) OMPUpdateClause(/*IsExtended=*/false);
365 void *Mem =
366 C.Allocate(totalSizeToAlloc<SourceLocation, OpenMPDependClauseKind>(2, 1),
367 alignof(OMPUpdateClause));
368 auto *Clause = new (Mem) OMPUpdateClause(/*IsExtended=*/true);
369 Clause->IsExtended = true;
370 return Clause;
371}
372
James Y Knightb8bfd962015-10-02 13:41:04 +0000373void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
374 assert(VL.size() == varlist_size() &&
375 "Number of private copies is not the same as the preallocated buffer");
376 std::copy(VL.begin(), VL.end(), varlist_end());
377}
378
379OMPPrivateClause *
380OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
381 SourceLocation LParenLoc, SourceLocation EndLoc,
382 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
383 // Allocate space for private variables and initializer expressions.
James Y Knight374fd202016-01-01 00:38:24 +0000384 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000385 OMPPrivateClause *Clause =
386 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
387 Clause->setVarRefs(VL);
388 Clause->setPrivateCopies(PrivateVL);
389 return Clause;
390}
391
392OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
393 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000394 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000395 return new (Mem) OMPPrivateClause(N);
396}
397
398void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
399 assert(VL.size() == varlist_size() &&
400 "Number of private copies is not the same as the preallocated buffer");
401 std::copy(VL.begin(), VL.end(), varlist_end());
402}
403
404void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
405 assert(VL.size() == varlist_size() &&
406 "Number of inits is not the same as the preallocated buffer");
407 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
408}
409
410OMPFirstprivateClause *
411OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
412 SourceLocation LParenLoc, SourceLocation EndLoc,
413 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
Alexey Bataev417089f2016-02-17 13:19:37 +0000414 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
James Y Knight374fd202016-01-01 00:38:24 +0000415 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000416 OMPFirstprivateClause *Clause =
417 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
418 Clause->setVarRefs(VL);
419 Clause->setPrivateCopies(PrivateVL);
420 Clause->setInits(InitVL);
Alexey Bataev417089f2016-02-17 13:19:37 +0000421 Clause->setPreInitStmt(PreInit);
James Y Knightb8bfd962015-10-02 13:41:04 +0000422 return Clause;
423}
424
425OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
426 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000427 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000428 return new (Mem) OMPFirstprivateClause(N);
429}
430
431void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
432 assert(PrivateCopies.size() == varlist_size() &&
433 "Number of private copies is not the same as the preallocated buffer");
434 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
435}
436
437void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
438 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
439 "not the same as the "
440 "preallocated buffer");
441 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
442}
443
444void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
445 assert(DstExprs.size() == varlist_size() && "Number of destination "
446 "expressions is not the same as "
447 "the preallocated buffer");
448 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
449}
450
451void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
452 assert(AssignmentOps.size() == varlist_size() &&
453 "Number of assignment expressions is not the same as the preallocated "
454 "buffer");
455 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
456 getDestinationExprs().end());
457}
458
459OMPLastprivateClause *OMPLastprivateClause::Create(
460 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
461 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
Alexey Bataev93dc40d2019-12-20 11:04:57 -0500462 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
463 OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
464 SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000465 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
Alexey Bataev93dc40d2019-12-20 11:04:57 -0500466 OMPLastprivateClause *Clause = new (Mem) OMPLastprivateClause(
467 StartLoc, LParenLoc, EndLoc, LPKind, LPKindLoc, ColonLoc, VL.size());
James Y Knightb8bfd962015-10-02 13:41:04 +0000468 Clause->setVarRefs(VL);
469 Clause->setSourceExprs(SrcExprs);
470 Clause->setDestinationExprs(DstExprs);
471 Clause->setAssignmentOps(AssignmentOps);
Alexey Bataev005248a2016-02-25 05:25:57 +0000472 Clause->setPreInitStmt(PreInit);
473 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000474 return Clause;
475}
476
477OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
478 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000479 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000480 return new (Mem) OMPLastprivateClause(N);
481}
482
483OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
484 SourceLocation StartLoc,
485 SourceLocation LParenLoc,
486 SourceLocation EndLoc,
487 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000488 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000489 OMPSharedClause *Clause =
490 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
491 Clause->setVarRefs(VL);
492 return Clause;
493}
494
495OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000496 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000497 return new (Mem) OMPSharedClause(N);
498}
499
500void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
501 assert(PL.size() == varlist_size() &&
502 "Number of privates is not the same as the preallocated buffer");
503 std::copy(PL.begin(), PL.end(), varlist_end());
504}
505
506void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
507 assert(IL.size() == varlist_size() &&
508 "Number of inits is not the same as the preallocated buffer");
509 std::copy(IL.begin(), IL.end(), getPrivates().end());
510}
511
512void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
513 assert(UL.size() == varlist_size() &&
514 "Number of updates is not the same as the preallocated buffer");
515 std::copy(UL.begin(), UL.end(), getInits().end());
516}
517
518void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
519 assert(FL.size() == varlist_size() &&
520 "Number of final updates is not the same as the preallocated buffer");
521 std::copy(FL.begin(), FL.end(), getUpdates().end());
522}
523
Alexey Bataev195ae902019-08-08 13:42:45 +0000524void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) {
525 assert(
526 UE.size() == varlist_size() + 1 &&
527 "Number of used expressions is not the same as the preallocated buffer");
528 std::copy(UE.begin(), UE.end(), getFinals().end() + 2);
529}
530
James Y Knightb8bfd962015-10-02 13:41:04 +0000531OMPLinearClause *OMPLinearClause::Create(
532 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
533 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
534 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
Alexey Bataev78849fb2016-03-09 09:49:00 +0000535 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
536 Stmt *PreInit, Expr *PostUpdate) {
Alexey Bataev195ae902019-08-08 13:42:45 +0000537 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
538 // (Step and CalcStep), list of used expression + step.
539 void *Mem =
540 C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000541 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
542 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
543 Clause->setVarRefs(VL);
544 Clause->setPrivates(PL);
545 Clause->setInits(IL);
546 // Fill update and final expressions with zeroes, they are provided later,
547 // after the directive construction.
548 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
549 nullptr);
550 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
551 nullptr);
Alexey Bataev195ae902019-08-08 13:42:45 +0000552 std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(),
553 nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000554 Clause->setStep(Step);
555 Clause->setCalcStep(CalcStep);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000556 Clause->setPreInitStmt(PreInit);
557 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000558 return Clause;
559}
560
561OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
562 unsigned NumVars) {
Alexey Bataev195ae902019-08-08 13:42:45 +0000563 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
564 // (Step and CalcStep), list of used expression + step.
565 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars +1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000566 return new (Mem) OMPLinearClause(NumVars);
567}
568
Alexey Bataev195ae902019-08-08 13:42:45 +0000569OMPClause::child_range OMPLinearClause::used_children() {
570 // Range includes only non-nullptr elements.
571 return child_range(
572 reinterpret_cast<Stmt **>(getUsedExprs().begin()),
573 reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr)));
574}
575
James Y Knightb8bfd962015-10-02 13:41:04 +0000576OMPAlignedClause *
577OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
578 SourceLocation LParenLoc, SourceLocation ColonLoc,
579 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
James Y Knight374fd202016-01-01 00:38:24 +0000580 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000581 OMPAlignedClause *Clause = new (Mem)
582 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
583 Clause->setVarRefs(VL);
584 Clause->setAlignment(A);
585 return Clause;
586}
587
588OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
589 unsigned NumVars) {
James Y Knight374fd202016-01-01 00:38:24 +0000590 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000591 return new (Mem) OMPAlignedClause(NumVars);
592}
593
594void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
595 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
596 "not the same as the "
597 "preallocated buffer");
598 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
599}
600
601void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
602 assert(DstExprs.size() == varlist_size() && "Number of destination "
603 "expressions is not the same as "
604 "the preallocated buffer");
605 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
606}
607
608void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
609 assert(AssignmentOps.size() == varlist_size() &&
610 "Number of assignment expressions is not the same as the preallocated "
611 "buffer");
612 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
613 getDestinationExprs().end());
614}
615
616OMPCopyinClause *OMPCopyinClause::Create(
617 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
618 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
619 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000620 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000621 OMPCopyinClause *Clause =
622 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
623 Clause->setVarRefs(VL);
624 Clause->setSourceExprs(SrcExprs);
625 Clause->setDestinationExprs(DstExprs);
626 Clause->setAssignmentOps(AssignmentOps);
627 return Clause;
628}
629
630OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000631 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000632 return new (Mem) OMPCopyinClause(N);
633}
634
635void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
636 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
637 "not the same as the "
638 "preallocated buffer");
639 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
640}
641
642void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
643 assert(DstExprs.size() == varlist_size() && "Number of destination "
644 "expressions is not the same as "
645 "the preallocated buffer");
646 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
647}
648
649void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
650 assert(AssignmentOps.size() == varlist_size() &&
651 "Number of assignment expressions is not the same as the preallocated "
652 "buffer");
653 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
654 getDestinationExprs().end());
655}
656
657OMPCopyprivateClause *OMPCopyprivateClause::Create(
658 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
659 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
660 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000661 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000662 OMPCopyprivateClause *Clause =
663 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
664 Clause->setVarRefs(VL);
665 Clause->setSourceExprs(SrcExprs);
666 Clause->setDestinationExprs(DstExprs);
667 Clause->setAssignmentOps(AssignmentOps);
668 return Clause;
669}
670
671OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
672 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000673 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000674 return new (Mem) OMPCopyprivateClause(N);
675}
676
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000677void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
678 assert(Privates.size() == varlist_size() &&
679 "Number of private copies is not the same as the preallocated buffer");
680 std::copy(Privates.begin(), Privates.end(), varlist_end());
681}
682
James Y Knightb8bfd962015-10-02 13:41:04 +0000683void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
684 assert(
685 LHSExprs.size() == varlist_size() &&
686 "Number of LHS expressions is not the same as the preallocated buffer");
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000687 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
James Y Knightb8bfd962015-10-02 13:41:04 +0000688}
689
690void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
691 assert(
692 RHSExprs.size() == varlist_size() &&
693 "Number of RHS expressions is not the same as the preallocated buffer");
694 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
695}
696
697void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
698 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
699 "expressions is not the same "
700 "as the preallocated buffer");
701 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
702}
703
704OMPReductionClause *OMPReductionClause::Create(
705 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
Alexey Bataev1236eb62020-03-23 17:30:38 -0400706 SourceLocation ModifierLoc, SourceLocation EndLoc, SourceLocation ColonLoc,
707 OpenMPReductionClauseModifier Modifier, ArrayRef<Expr *> VL,
James Y Knightb8bfd962015-10-02 13:41:04 +0000708 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000709 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev61205072016-03-02 04:57:40 +0000710 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
711 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000712 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
Alexey Bataev1236eb62020-03-23 17:30:38 -0400713 auto *Clause = new (Mem)
714 OMPReductionClause(StartLoc, LParenLoc, ModifierLoc, EndLoc, ColonLoc,
715 Modifier, VL.size(), QualifierLoc, NameInfo);
James Y Knightb8bfd962015-10-02 13:41:04 +0000716 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000717 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000718 Clause->setLHSExprs(LHSExprs);
719 Clause->setRHSExprs(RHSExprs);
720 Clause->setReductionOps(ReductionOps);
Alexey Bataev61205072016-03-02 04:57:40 +0000721 Clause->setPreInitStmt(PreInit);
722 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000723 return Clause;
724}
725
726OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
727 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000728 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000729 return new (Mem) OMPReductionClause(N);
730}
731
Alexey Bataev169d96a2017-07-18 20:17:46 +0000732void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
733 assert(Privates.size() == varlist_size() &&
734 "Number of private copies is not the same as the preallocated buffer");
735 std::copy(Privates.begin(), Privates.end(), varlist_end());
736}
737
738void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
739 assert(
740 LHSExprs.size() == varlist_size() &&
741 "Number of LHS expressions is not the same as the preallocated buffer");
742 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
743}
744
745void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
746 assert(
747 RHSExprs.size() == varlist_size() &&
748 "Number of RHS expressions is not the same as the preallocated buffer");
749 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
750}
751
752void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
753 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
754 "expressions is not the same "
755 "as the preallocated buffer");
756 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
757}
758
759OMPTaskReductionClause *OMPTaskReductionClause::Create(
760 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
761 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
762 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
763 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
764 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
765 Expr *PostUpdate) {
766 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
767 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
768 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
769 Clause->setVarRefs(VL);
770 Clause->setPrivates(Privates);
771 Clause->setLHSExprs(LHSExprs);
772 Clause->setRHSExprs(RHSExprs);
773 Clause->setReductionOps(ReductionOps);
774 Clause->setPreInitStmt(PreInit);
775 Clause->setPostUpdateExpr(PostUpdate);
776 return Clause;
777}
778
779OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
780 unsigned N) {
781 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
782 return new (Mem) OMPTaskReductionClause(N);
783}
784
Alexey Bataevfa312f32017-07-21 18:48:21 +0000785void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
786 assert(Privates.size() == varlist_size() &&
787 "Number of private copies is not the same as the preallocated buffer");
788 std::copy(Privates.begin(), Privates.end(), varlist_end());
789}
790
791void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
792 assert(
793 LHSExprs.size() == varlist_size() &&
794 "Number of LHS expressions is not the same as the preallocated buffer");
795 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
796}
797
798void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
799 assert(
800 RHSExprs.size() == varlist_size() &&
801 "Number of RHS expressions is not the same as the preallocated buffer");
802 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
803}
804
805void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
806 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
807 "expressions is not the same "
808 "as the preallocated buffer");
809 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
810}
811
Alexey Bataev88202be2017-07-27 13:20:36 +0000812void OMPInReductionClause::setTaskgroupDescriptors(
813 ArrayRef<Expr *> TaskgroupDescriptors) {
814 assert(TaskgroupDescriptors.size() == varlist_size() &&
815 "Number of in reduction descriptors is not the same as the "
816 "preallocated buffer");
817 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
818 getReductionOps().end());
819}
820
Alexey Bataevfa312f32017-07-21 18:48:21 +0000821OMPInReductionClause *OMPInReductionClause::Create(
822 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
823 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
824 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
825 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev88202be2017-07-27 13:20:36 +0000826 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
827 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
828 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000829 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
830 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
831 Clause->setVarRefs(VL);
832 Clause->setPrivates(Privates);
833 Clause->setLHSExprs(LHSExprs);
834 Clause->setRHSExprs(RHSExprs);
835 Clause->setReductionOps(ReductionOps);
Alexey Bataev88202be2017-07-27 13:20:36 +0000836 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000837 Clause->setPreInitStmt(PreInit);
838 Clause->setPostUpdateExpr(PostUpdate);
839 return Clause;
840}
841
842OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
843 unsigned N) {
Alexey Bataev88202be2017-07-27 13:20:36 +0000844 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000845 return new (Mem) OMPInReductionClause(N);
846}
847
Alexey Bataeve04483e2019-03-27 14:14:31 +0000848OMPAllocateClause *
849OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc,
850 SourceLocation LParenLoc, Expr *Allocator,
851 SourceLocation ColonLoc, SourceLocation EndLoc,
852 ArrayRef<Expr *> VL) {
853 // Allocate space for private variables and initializer expressions.
854 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
855 auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
856 ColonLoc, EndLoc, VL.size());
857 Clause->setVarRefs(VL);
858 return Clause;
859}
860
861OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
862 unsigned N) {
863 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
864 return new (Mem) OMPAllocateClause(N);
865}
866
James Y Knightb8bfd962015-10-02 13:41:04 +0000867OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
868 SourceLocation StartLoc,
869 SourceLocation LParenLoc,
870 SourceLocation EndLoc,
871 ArrayRef<Expr *> VL) {
Alexey Bataev8b427062016-05-25 12:36:08 +0000872 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000873 OMPFlushClause *Clause =
874 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
875 Clause->setVarRefs(VL);
876 return Clause;
877}
878
879OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000880 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000881 return new (Mem) OMPFlushClause(N);
882}
883
Alexey Bataevc112e942020-02-28 09:52:15 -0500884OMPDepobjClause *OMPDepobjClause::Create(const ASTContext &C,
885 SourceLocation StartLoc,
886 SourceLocation LParenLoc,
887 SourceLocation RParenLoc,
888 Expr *Depobj) {
889 auto *Clause = new (C) OMPDepobjClause(StartLoc, LParenLoc, RParenLoc);
890 Clause->setDepobj(Depobj);
891 return Clause;
892}
893
894OMPDepobjClause *OMPDepobjClause::CreateEmpty(const ASTContext &C) {
895 return new (C) OMPDepobjClause();
896}
897
Alexey Bataevf138fda2018-08-13 19:04:24 +0000898OMPDependClause *
899OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
900 SourceLocation LParenLoc, SourceLocation EndLoc,
901 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
902 SourceLocation ColonLoc, ArrayRef<Expr *> VL,
903 unsigned NumLoops) {
904 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
905 OMPDependClause *Clause = new (Mem)
906 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000907 Clause->setVarRefs(VL);
908 Clause->setDependencyKind(DepKind);
909 Clause->setDependencyLoc(DepLoc);
910 Clause->setColonLoc(ColonLoc);
Alexey Bataevf138fda2018-08-13 19:04:24 +0000911 for (unsigned I = 0 ; I < NumLoops; ++I)
912 Clause->setLoopData(I, nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000913 return Clause;
914}
915
Alexey Bataevf138fda2018-08-13 19:04:24 +0000916OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
917 unsigned NumLoops) {
918 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
919 return new (Mem) OMPDependClause(N, NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000920}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000921
Alexey Bataevf138fda2018-08-13 19:04:24 +0000922void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
923 assert((getDependencyKind() == OMPC_DEPEND_sink ||
924 getDependencyKind() == OMPC_DEPEND_source) &&
925 NumLoop < NumLoops &&
926 "Expected sink or source depend + loop index must be less number of "
927 "loops.");
928 auto It = std::next(getVarRefs().end(), NumLoop);
929 *It = Cnt;
Alexey Bataev8b427062016-05-25 12:36:08 +0000930}
931
Alexey Bataevf138fda2018-08-13 19:04:24 +0000932Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
933 assert((getDependencyKind() == OMPC_DEPEND_sink ||
934 getDependencyKind() == OMPC_DEPEND_source) &&
935 NumLoop < NumLoops &&
936 "Expected sink or source depend + loop index must be less number of "
937 "loops.");
938 auto It = std::next(getVarRefs().end(), NumLoop);
939 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000940}
941
Alexey Bataevf138fda2018-08-13 19:04:24 +0000942const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
943 assert((getDependencyKind() == OMPC_DEPEND_sink ||
944 getDependencyKind() == OMPC_DEPEND_source) &&
945 NumLoop < NumLoops &&
946 "Expected sink or source depend + loop index must be less number of "
947 "loops.");
948 auto It = std::next(getVarRefs().end(), NumLoop);
949 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000950}
951
Samuel Antao90927002016-04-26 14:54:23 +0000952unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
953 MappableExprComponentListsRef ComponentLists) {
954 unsigned TotalNum = 0u;
955 for (auto &C : ComponentLists)
956 TotalNum += C.size();
957 return TotalNum;
958}
959
960unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
Alexey Bataeve3727102018-04-18 15:57:46 +0000961 ArrayRef<const ValueDecl *> Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000962 unsigned TotalNum = 0u;
963 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
Alexey Bataeve3727102018-04-18 15:57:46 +0000964 for (const ValueDecl *D : Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000965 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
966 if (Cache.count(VD))
967 continue;
968 ++TotalNum;
969 Cache.insert(VD);
970 }
971 return TotalNum;
972}
973
Michael Kruse4304e9d2019-02-19 16:38:20 +0000974OMPMapClause *OMPMapClause::Create(
975 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
976 ArrayRef<ValueDecl *> Declarations,
977 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
978 ArrayRef<OpenMPMapModifierKind> MapModifiers,
979 ArrayRef<SourceLocation> MapModifiersLoc,
980 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
981 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
982 OMPMappableExprListSizeTy Sizes;
983 Sizes.NumVars = Vars.size();
984 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
985 Sizes.NumComponentLists = ComponentLists.size();
986 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao90927002016-04-26 14:54:23 +0000987
988 // We need to allocate:
Michael Kruse4304e9d2019-02-19 16:38:20 +0000989 // 2 x NumVars x Expr* - we have an original list expression and an associated
990 // user-defined mapper for each clause list entry.
Samuel Antao90927002016-04-26 14:54:23 +0000991 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
992 // with each component list.
993 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
994 // number of lists for each unique declaration and the size of each component
995 // list.
996 // NumComponents x MappableComponent - the total of all the components in all
997 // the lists.
998 void *Mem = C.Allocate(
999 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1000 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001001 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1002 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1003 Sizes.NumComponents));
1004 OMPMapClause *Clause = new (Mem)
1005 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
1006 Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
Samuel Antao90927002016-04-26 14:54:23 +00001007
1008 Clause->setVarRefs(Vars);
Michael Kruse4304e9d2019-02-19 16:38:20 +00001009 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao90927002016-04-26 14:54:23 +00001010 Clause->setClauseInfo(Declarations, ComponentLists);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001011 Clause->setMapType(Type);
1012 Clause->setMapLoc(TypeLoc);
1013 return Clause;
1014}
1015
Michael Kruse4304e9d2019-02-19 16:38:20 +00001016OMPMapClause *
1017OMPMapClause::CreateEmpty(const ASTContext &C,
1018 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao90927002016-04-26 14:54:23 +00001019 void *Mem = C.Allocate(
1020 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1021 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001022 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1023 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1024 Sizes.NumComponents));
1025 return new (Mem) OMPMapClause(Sizes);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001026}
Samuel Antao661c0902016-05-26 17:39:58 +00001027
Michael Kruse01f670d2019-02-22 22:29:42 +00001028OMPToClause *OMPToClause::Create(
1029 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1030 ArrayRef<ValueDecl *> Declarations,
1031 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1032 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001033 OMPMappableExprListSizeTy Sizes;
1034 Sizes.NumVars = Vars.size();
1035 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1036 Sizes.NumComponentLists = ComponentLists.size();
1037 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao661c0902016-05-26 17:39:58 +00001038
1039 // We need to allocate:
Michael Kruse01f670d2019-02-22 22:29:42 +00001040 // 2 x NumVars x Expr* - we have an original list expression and an associated
1041 // user-defined mapper for each clause list entry.
Samuel Antao661c0902016-05-26 17:39:58 +00001042 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1043 // with each component list.
1044 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1045 // number of lists for each unique declaration and the size of each component
1046 // list.
1047 // NumComponents x MappableComponent - the total of all the components in all
1048 // the lists.
1049 void *Mem = C.Allocate(
1050 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1051 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +00001052 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001053 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1054 Sizes.NumComponents));
Samuel Antao661c0902016-05-26 17:39:58 +00001055
Michael Kruse01f670d2019-02-22 22:29:42 +00001056 auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +00001057
1058 Clause->setVarRefs(Vars);
Michael Kruse01f670d2019-02-22 22:29:42 +00001059 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao661c0902016-05-26 17:39:58 +00001060 Clause->setClauseInfo(Declarations, ComponentLists);
1061 return Clause;
1062}
1063
Michael Kruse4304e9d2019-02-19 16:38:20 +00001064OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
1065 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao661c0902016-05-26 17:39:58 +00001066 void *Mem = C.Allocate(
1067 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1068 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +00001069 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001070 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1071 Sizes.NumComponents));
1072 return new (Mem) OMPToClause(Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +00001073}
Samuel Antaoec172c62016-05-26 17:49:04 +00001074
Michael Kruse0336c752019-02-25 20:34:15 +00001075OMPFromClause *OMPFromClause::Create(
1076 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1077 ArrayRef<ValueDecl *> Declarations,
1078 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1079 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001080 OMPMappableExprListSizeTy Sizes;
1081 Sizes.NumVars = Vars.size();
1082 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1083 Sizes.NumComponentLists = ComponentLists.size();
1084 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaoec172c62016-05-26 17:49:04 +00001085
1086 // We need to allocate:
Michael Kruse0336c752019-02-25 20:34:15 +00001087 // 2 x NumVars x Expr* - we have an original list expression and an associated
1088 // user-defined mapper for each clause list entry.
Samuel Antaoec172c62016-05-26 17:49:04 +00001089 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1090 // with each component list.
1091 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1092 // number of lists for each unique declaration and the size of each component
1093 // list.
1094 // NumComponents x MappableComponent - the total of all the components in all
1095 // the lists.
1096 void *Mem = C.Allocate(
1097 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1098 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001099 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001100 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1101 Sizes.NumComponents));
Samuel Antaoec172c62016-05-26 17:49:04 +00001102
Michael Kruse0336c752019-02-25 20:34:15 +00001103 auto *Clause =
1104 new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001105
1106 Clause->setVarRefs(Vars);
Michael Kruse0336c752019-02-25 20:34:15 +00001107 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antaoec172c62016-05-26 17:49:04 +00001108 Clause->setClauseInfo(Declarations, ComponentLists);
1109 return Clause;
1110}
1111
Michael Kruse4304e9d2019-02-19 16:38:20 +00001112OMPFromClause *
1113OMPFromClause::CreateEmpty(const ASTContext &C,
1114 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaoec172c62016-05-26 17:49:04 +00001115 void *Mem = C.Allocate(
1116 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1117 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001118 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001119 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1120 Sizes.NumComponents));
1121 return new (Mem) OMPFromClause(Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001122}
Carlo Bertolli2404b172016-07-13 15:37:16 +00001123
Samuel Antaocc10b852016-07-28 14:23:26 +00001124void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1125 assert(VL.size() == varlist_size() &&
1126 "Number of private copies is not the same as the preallocated buffer");
1127 std::copy(VL.begin(), VL.end(), varlist_end());
1128}
1129
1130void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
1131 assert(VL.size() == varlist_size() &&
1132 "Number of inits is not the same as the preallocated buffer");
1133 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1134}
1135
1136OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001137 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1138 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
1139 ArrayRef<ValueDecl *> Declarations,
Samuel Antaocc10b852016-07-28 14:23:26 +00001140 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001141 OMPMappableExprListSizeTy Sizes;
1142 Sizes.NumVars = Vars.size();
1143 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1144 Sizes.NumComponentLists = ComponentLists.size();
1145 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaocc10b852016-07-28 14:23:26 +00001146
1147 // We need to allocate:
1148 // 3 x NumVars x Expr* - we have an original list expression for each clause
1149 // list entry and an equal number of private copies and inits.
1150 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1151 // with each component list.
1152 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1153 // number of lists for each unique declaration and the size of each component
1154 // list.
1155 // NumComponents x MappableComponent - the total of all the components in all
1156 // the lists.
1157 void *Mem = C.Allocate(
1158 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1159 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001160 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1161 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1162 Sizes.NumComponents));
Samuel Antaocc10b852016-07-28 14:23:26 +00001163
Michael Kruse4304e9d2019-02-19 16:38:20 +00001164 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
Samuel Antaocc10b852016-07-28 14:23:26 +00001165
1166 Clause->setVarRefs(Vars);
1167 Clause->setPrivateCopies(PrivateVars);
1168 Clause->setInits(Inits);
1169 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001170 return Clause;
1171}
1172
Michael Kruse4304e9d2019-02-19 16:38:20 +00001173OMPUseDevicePtrClause *
1174OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
1175 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaocc10b852016-07-28 14:23:26 +00001176 void *Mem = C.Allocate(
1177 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1178 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001179 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1180 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1181 Sizes.NumComponents));
1182 return new (Mem) OMPUseDevicePtrClause(Sizes);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001183}
Carlo Bertolli70594e92016-07-13 17:16:49 +00001184
Samuel Antao6890b092016-07-28 14:25:09 +00001185OMPIsDevicePtrClause *
Michael Kruse4304e9d2019-02-19 16:38:20 +00001186OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
Samuel Antao6890b092016-07-28 14:25:09 +00001187 ArrayRef<Expr *> Vars,
1188 ArrayRef<ValueDecl *> Declarations,
1189 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001190 OMPMappableExprListSizeTy Sizes;
1191 Sizes.NumVars = Vars.size();
1192 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1193 Sizes.NumComponentLists = ComponentLists.size();
1194 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao6890b092016-07-28 14:25:09 +00001195
1196 // We need to allocate:
1197 // NumVars x Expr* - we have an original list expression for each clause list
1198 // entry.
1199 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1200 // with each component list.
1201 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1202 // number of lists for each unique declaration and the size of each component
1203 // list.
1204 // NumComponents x MappableComponent - the total of all the components in all
1205 // the lists.
1206 void *Mem = C.Allocate(
1207 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1208 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001209 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1210 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1211 Sizes.NumComponents));
Samuel Antao6890b092016-07-28 14:25:09 +00001212
Michael Kruse4304e9d2019-02-19 16:38:20 +00001213 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
Samuel Antao6890b092016-07-28 14:25:09 +00001214
1215 Clause->setVarRefs(Vars);
1216 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001217 return Clause;
1218}
1219
Michael Kruse4304e9d2019-02-19 16:38:20 +00001220OMPIsDevicePtrClause *
1221OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1222 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao6890b092016-07-28 14:25:09 +00001223 void *Mem = C.Allocate(
1224 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1225 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001226 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1227 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1228 Sizes.NumComponents));
1229 return new (Mem) OMPIsDevicePtrClause(Sizes);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001230}
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001231
Alexey Bataevb6e70842019-12-16 15:54:17 -05001232OMPNontemporalClause *OMPNontemporalClause::Create(const ASTContext &C,
1233 SourceLocation StartLoc,
1234 SourceLocation LParenLoc,
1235 SourceLocation EndLoc,
1236 ArrayRef<Expr *> VL) {
Alexey Bataev0860db92019-12-19 10:01:10 -05001237 // Allocate space for nontemporal variables + private references.
1238 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
Alexey Bataevb6e70842019-12-16 15:54:17 -05001239 auto *Clause =
1240 new (Mem) OMPNontemporalClause(StartLoc, LParenLoc, EndLoc, VL.size());
1241 Clause->setVarRefs(VL);
1242 return Clause;
1243}
1244
1245OMPNontemporalClause *OMPNontemporalClause::CreateEmpty(const ASTContext &C,
1246 unsigned N) {
Alexey Bataev0860db92019-12-19 10:01:10 -05001247 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
Alexey Bataevb6e70842019-12-16 15:54:17 -05001248 return new (Mem) OMPNontemporalClause(N);
1249}
1250
Alexey Bataev0860db92019-12-19 10:01:10 -05001251void OMPNontemporalClause::setPrivateRefs(ArrayRef<Expr *> VL) {
1252 assert(VL.size() == varlist_size() && "Number of private references is not "
1253 "the same as the preallocated buffer");
1254 std::copy(VL.begin(), VL.end(), varlist_end());
1255}
1256
Alexey Bataev06dea732020-03-20 09:41:22 -04001257OMPInclusiveClause *OMPInclusiveClause::Create(const ASTContext &C,
1258 SourceLocation StartLoc,
1259 SourceLocation LParenLoc,
1260 SourceLocation EndLoc,
1261 ArrayRef<Expr *> VL) {
1262 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
1263 auto *Clause =
1264 new (Mem) OMPInclusiveClause(StartLoc, LParenLoc, EndLoc, VL.size());
1265 Clause->setVarRefs(VL);
1266 return Clause;
1267}
1268
1269OMPInclusiveClause *OMPInclusiveClause::CreateEmpty(const ASTContext &C,
1270 unsigned N) {
1271 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
1272 return new (Mem) OMPInclusiveClause(N);
1273}
1274
Alexey Bataev63828a32020-03-23 10:41:08 -04001275OMPExclusiveClause *OMPExclusiveClause::Create(const ASTContext &C,
1276 SourceLocation StartLoc,
1277 SourceLocation LParenLoc,
1278 SourceLocation EndLoc,
1279 ArrayRef<Expr *> VL) {
1280 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
1281 auto *Clause =
1282 new (Mem) OMPExclusiveClause(StartLoc, LParenLoc, EndLoc, VL.size());
1283 Clause->setVarRefs(VL);
1284 return Clause;
1285}
1286
1287OMPExclusiveClause *OMPExclusiveClause::CreateEmpty(const ASTContext &C,
1288 unsigned N) {
1289 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
1290 return new (Mem) OMPExclusiveClause(N);
1291}
1292
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001293//===----------------------------------------------------------------------===//
1294// OpenMP clauses printing methods
1295//===----------------------------------------------------------------------===//
1296
1297void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1298 OS << "if(";
Johannes Doerferteb3e81f2019-11-04 22:00:49 -06001299 if (Node->getNameModifier() != llvm::omp::OMPD_unknown)
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001300 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1301 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1302 OS << ")";
1303}
1304
1305void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1306 OS << "final(";
1307 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1308 OS << ")";
1309}
1310
1311void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1312 OS << "num_threads(";
1313 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1314 OS << ")";
1315}
1316
1317void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1318 OS << "safelen(";
1319 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1320 OS << ")";
1321}
1322
1323void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1324 OS << "simdlen(";
1325 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1326 OS << ")";
1327}
1328
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00001329void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
1330 OS << "allocator(";
1331 Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
1332 OS << ")";
1333}
1334
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001335void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1336 OS << "collapse(";
1337 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1338 OS << ")";
1339}
1340
Alexey Bataev0f0564b2020-03-17 09:17:42 -04001341void OMPClausePrinter::VisitOMPDetachClause(OMPDetachClause *Node) {
1342 OS << "detach(";
1343 Node->getEventHandler()->printPretty(OS, nullptr, Policy, 0);
1344 OS << ")";
1345}
1346
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001347void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1348 OS << "default("
Atmn Patel577c9b02020-02-14 21:45:49 -06001349 << getOpenMPSimpleClauseTypeName(OMPC_default,
1350 unsigned(Node->getDefaultKind()))
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001351 << ")";
1352}
1353
1354void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1355 OS << "proc_bind("
Johannes Doerfert6c5d1f402019-12-25 18:15:36 -06001356 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind,
1357 unsigned(Node->getProcBindKind()))
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001358 << ")";
1359}
1360
1361void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1362 OS << "unified_address";
1363}
1364
1365void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1366 OMPUnifiedSharedMemoryClause *) {
1367 OS << "unified_shared_memory";
1368}
1369
1370void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1371 OS << "reverse_offload";
1372}
1373
1374void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1375 OMPDynamicAllocatorsClause *) {
1376 OS << "dynamic_allocators";
1377}
1378
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00001379void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1380 OMPAtomicDefaultMemOrderClause *Node) {
1381 OS << "atomic_default_mem_order("
1382 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1383 Node->getAtomicDefaultMemOrderKind())
1384 << ")";
1385}
1386
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001387void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1388 OS << "schedule(";
1389 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1390 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1391 Node->getFirstScheduleModifier());
1392 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1393 OS << ", ";
1394 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1395 Node->getSecondScheduleModifier());
1396 }
1397 OS << ": ";
1398 }
1399 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1400 if (auto *E = Node->getChunkSize()) {
1401 OS << ", ";
1402 E->printPretty(OS, nullptr, Policy);
1403 }
1404 OS << ")";
1405}
1406
1407void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1408 OS << "ordered";
1409 if (auto *Num = Node->getNumForLoops()) {
1410 OS << "(";
1411 Num->printPretty(OS, nullptr, Policy, 0);
1412 OS << ")";
1413 }
1414}
1415
1416void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1417 OS << "nowait";
1418}
1419
1420void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1421 OS << "untied";
1422}
1423
1424void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1425 OS << "nogroup";
1426}
1427
1428void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1429 OS << "mergeable";
1430}
1431
1432void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1433
1434void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1435
Alexey Bataev82f7c202020-03-03 13:22:35 -05001436void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *Node) {
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001437 OS << "update";
Alexey Bataev82f7c202020-03-03 13:22:35 -05001438 if (Node->isExtended()) {
1439 OS << "(";
1440 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1441 Node->getDependencyKind());
1442 OS << ")";
1443 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001444}
1445
1446void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1447 OS << "capture";
1448}
1449
1450void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1451 OS << "seq_cst";
1452}
1453
Alexey Bataevea9166b2020-02-06 16:30:23 -05001454void OMPClausePrinter::VisitOMPAcqRelClause(OMPAcqRelClause *) {
1455 OS << "acq_rel";
1456}
1457
Alexey Bataev04a830f2020-02-10 14:30:39 -05001458void OMPClausePrinter::VisitOMPAcquireClause(OMPAcquireClause *) {
1459 OS << "acquire";
1460}
1461
Alexey Bataev95598342020-02-10 15:49:05 -05001462void OMPClausePrinter::VisitOMPReleaseClause(OMPReleaseClause *) {
1463 OS << "release";
1464}
1465
Alexey Bataev9a8defc2020-02-11 11:10:43 -05001466void OMPClausePrinter::VisitOMPRelaxedClause(OMPRelaxedClause *) {
1467 OS << "relaxed";
1468}
1469
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001470void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1471 OS << "threads";
1472}
1473
1474void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1475
1476void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1477 OS << "device(";
Alexey Bataev2f8894a2020-03-18 15:01:15 -04001478 OpenMPDeviceClauseModifier Modifier = Node->getModifier();
1479 if (Modifier != OMPC_DEVICE_unknown) {
1480 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), Modifier)
1481 << ": ";
1482 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001483 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1484 OS << ")";
1485}
1486
1487void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1488 OS << "num_teams(";
1489 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1490 OS << ")";
1491}
1492
1493void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1494 OS << "thread_limit(";
1495 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1496 OS << ")";
1497}
1498
1499void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1500 OS << "priority(";
1501 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1502 OS << ")";
1503}
1504
1505void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1506 OS << "grainsize(";
1507 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1508 OS << ")";
1509}
1510
1511void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1512 OS << "num_tasks(";
1513 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1514 OS << ")";
1515}
1516
1517void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1518 OS << "hint(";
1519 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1520 OS << ")";
1521}
1522
Alexey Bataev375437a2020-03-02 14:21:20 -05001523void OMPClausePrinter::VisitOMPDestroyClause(OMPDestroyClause *) {
1524 OS << "destroy";
1525}
1526
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001527template<typename T>
1528void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1529 for (typename T::varlist_iterator I = Node->varlist_begin(),
1530 E = Node->varlist_end();
1531 I != E; ++I) {
1532 assert(*I && "Expected non-null Stmt");
1533 OS << (I == Node->varlist_begin() ? StartSym : ',');
1534 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1535 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1536 DRE->printPretty(OS, nullptr, Policy, 0);
1537 else
1538 DRE->getDecl()->printQualifiedName(OS);
1539 } else
1540 (*I)->printPretty(OS, nullptr, Policy, 0);
1541 }
1542}
1543
Alexey Bataeve04483e2019-03-27 14:14:31 +00001544void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
1545 if (Node->varlist_empty())
1546 return;
1547 OS << "allocate";
1548 if (Expr *Allocator = Node->getAllocator()) {
1549 OS << "(";
1550 Allocator->printPretty(OS, nullptr, Policy, 0);
1551 OS << ":";
1552 VisitOMPClauseList(Node, ' ');
1553 } else {
1554 VisitOMPClauseList(Node, '(');
1555 }
1556 OS << ")";
1557}
1558
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001559void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1560 if (!Node->varlist_empty()) {
1561 OS << "private";
1562 VisitOMPClauseList(Node, '(');
1563 OS << ")";
1564 }
1565}
1566
1567void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1568 if (!Node->varlist_empty()) {
1569 OS << "firstprivate";
1570 VisitOMPClauseList(Node, '(');
1571 OS << ")";
1572 }
1573}
1574
1575void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1576 if (!Node->varlist_empty()) {
1577 OS << "lastprivate";
Alexey Bataev93dc40d2019-12-20 11:04:57 -05001578 OpenMPLastprivateModifier LPKind = Node->getKind();
1579 if (LPKind != OMPC_LASTPRIVATE_unknown) {
1580 OS << "("
1581 << getOpenMPSimpleClauseTypeName(OMPC_lastprivate, Node->getKind())
1582 << ":";
1583 }
1584 VisitOMPClauseList(Node, LPKind == OMPC_LASTPRIVATE_unknown ? '(' : ' ');
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001585 OS << ")";
1586 }
1587}
1588
1589void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1590 if (!Node->varlist_empty()) {
1591 OS << "shared";
1592 VisitOMPClauseList(Node, '(');
1593 OS << ")";
1594 }
1595}
1596
1597void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1598 if (!Node->varlist_empty()) {
1599 OS << "reduction(";
Alexey Bataev1236eb62020-03-23 17:30:38 -04001600 if (Node->getModifierLoc().isValid())
1601 OS << getOpenMPSimpleClauseTypeName(OMPC_reduction, Node->getModifier())
1602 << ", ";
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001603 NestedNameSpecifier *QualifierLoc =
1604 Node->getQualifierLoc().getNestedNameSpecifier();
1605 OverloadedOperatorKind OOK =
1606 Node->getNameInfo().getName().getCXXOverloadedOperator();
1607 if (QualifierLoc == nullptr && OOK != OO_None) {
1608 // Print reduction identifier in C format
1609 OS << getOperatorSpelling(OOK);
1610 } else {
1611 // Use C++ format
1612 if (QualifierLoc != nullptr)
1613 QualifierLoc->print(OS, Policy);
1614 OS << Node->getNameInfo();
1615 }
1616 OS << ":";
1617 VisitOMPClauseList(Node, ' ');
1618 OS << ")";
1619 }
1620}
1621
1622void OMPClausePrinter::VisitOMPTaskReductionClause(
1623 OMPTaskReductionClause *Node) {
1624 if (!Node->varlist_empty()) {
1625 OS << "task_reduction(";
1626 NestedNameSpecifier *QualifierLoc =
1627 Node->getQualifierLoc().getNestedNameSpecifier();
1628 OverloadedOperatorKind OOK =
1629 Node->getNameInfo().getName().getCXXOverloadedOperator();
1630 if (QualifierLoc == nullptr && OOK != OO_None) {
1631 // Print reduction identifier in C format
1632 OS << getOperatorSpelling(OOK);
1633 } else {
1634 // Use C++ format
1635 if (QualifierLoc != nullptr)
1636 QualifierLoc->print(OS, Policy);
1637 OS << Node->getNameInfo();
1638 }
1639 OS << ":";
1640 VisitOMPClauseList(Node, ' ');
1641 OS << ")";
1642 }
1643}
1644
1645void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1646 if (!Node->varlist_empty()) {
1647 OS << "in_reduction(";
1648 NestedNameSpecifier *QualifierLoc =
1649 Node->getQualifierLoc().getNestedNameSpecifier();
1650 OverloadedOperatorKind OOK =
1651 Node->getNameInfo().getName().getCXXOverloadedOperator();
1652 if (QualifierLoc == nullptr && OOK != OO_None) {
1653 // Print reduction identifier in C format
1654 OS << getOperatorSpelling(OOK);
1655 } else {
1656 // Use C++ format
1657 if (QualifierLoc != nullptr)
1658 QualifierLoc->print(OS, Policy);
1659 OS << Node->getNameInfo();
1660 }
1661 OS << ":";
1662 VisitOMPClauseList(Node, ' ');
1663 OS << ")";
1664 }
1665}
1666
1667void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1668 if (!Node->varlist_empty()) {
1669 OS << "linear";
1670 if (Node->getModifierLoc().isValid()) {
1671 OS << '('
1672 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1673 }
1674 VisitOMPClauseList(Node, '(');
1675 if (Node->getModifierLoc().isValid())
1676 OS << ')';
1677 if (Node->getStep() != nullptr) {
1678 OS << ": ";
1679 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1680 }
1681 OS << ")";
1682 }
1683}
1684
1685void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1686 if (!Node->varlist_empty()) {
1687 OS << "aligned";
1688 VisitOMPClauseList(Node, '(');
1689 if (Node->getAlignment() != nullptr) {
1690 OS << ": ";
1691 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1692 }
1693 OS << ")";
1694 }
1695}
1696
1697void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1698 if (!Node->varlist_empty()) {
1699 OS << "copyin";
1700 VisitOMPClauseList(Node, '(');
1701 OS << ")";
1702 }
1703}
1704
1705void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1706 if (!Node->varlist_empty()) {
1707 OS << "copyprivate";
1708 VisitOMPClauseList(Node, '(');
1709 OS << ")";
1710 }
1711}
1712
1713void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1714 if (!Node->varlist_empty()) {
1715 VisitOMPClauseList(Node, '(');
1716 OS << ")";
1717 }
1718}
1719
Alexey Bataevc112e942020-02-28 09:52:15 -05001720void OMPClausePrinter::VisitOMPDepobjClause(OMPDepobjClause *Node) {
1721 OS << "(";
1722 Node->getDepobj()->printPretty(OS, nullptr, Policy, 0);
1723 OS << ")";
1724}
1725
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001726void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1727 OS << "depend(";
1728 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1729 Node->getDependencyKind());
1730 if (!Node->varlist_empty()) {
1731 OS << " :";
1732 VisitOMPClauseList(Node, ' ');
1733 }
1734 OS << ")";
1735}
1736
1737void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1738 if (!Node->varlist_empty()) {
1739 OS << "map(";
1740 if (Node->getMapType() != OMPC_MAP_unknown) {
Kelvin Lief579432018-12-18 22:18:41 +00001741 for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1742 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1743 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1744 Node->getMapTypeModifier(I));
Michael Kruse4304e9d2019-02-19 16:38:20 +00001745 if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1746 OS << '(';
1747 NestedNameSpecifier *MapperNNS =
1748 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1749 if (MapperNNS)
1750 MapperNNS->print(OS, Policy);
1751 OS << Node->getMapperIdInfo() << ')';
1752 }
Kelvin Lief579432018-12-18 22:18:41 +00001753 OS << ',';
1754 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001755 }
1756 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1757 OS << ':';
1758 }
1759 VisitOMPClauseList(Node, ' ');
1760 OS << ")";
1761 }
1762}
1763
1764void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1765 if (!Node->varlist_empty()) {
1766 OS << "to";
Michael Kruse01f670d2019-02-22 22:29:42 +00001767 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1768 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1769 OS << '(';
1770 OS << "mapper(";
1771 NestedNameSpecifier *MapperNNS =
1772 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1773 if (MapperNNS)
1774 MapperNNS->print(OS, Policy);
1775 OS << MapperId << "):";
1776 VisitOMPClauseList(Node, ' ');
1777 } else {
1778 VisitOMPClauseList(Node, '(');
1779 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001780 OS << ")";
1781 }
1782}
1783
1784void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1785 if (!Node->varlist_empty()) {
1786 OS << "from";
Michael Kruse0336c752019-02-25 20:34:15 +00001787 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1788 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1789 OS << '(';
1790 OS << "mapper(";
1791 NestedNameSpecifier *MapperNNS =
1792 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1793 if (MapperNNS)
1794 MapperNNS->print(OS, Policy);
1795 OS << MapperId << "):";
1796 VisitOMPClauseList(Node, ' ');
1797 } else {
1798 VisitOMPClauseList(Node, '(');
1799 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001800 OS << ")";
1801 }
1802}
1803
1804void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1805 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1806 OMPC_dist_schedule, Node->getDistScheduleKind());
1807 if (auto *E = Node->getChunkSize()) {
1808 OS << ", ";
1809 E->printPretty(OS, nullptr, Policy);
1810 }
1811 OS << ")";
1812}
1813
1814void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1815 OS << "defaultmap(";
1816 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1817 Node->getDefaultmapModifier());
1818 OS << ": ";
1819 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1820 Node->getDefaultmapKind());
1821 OS << ")";
1822}
1823
1824void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1825 if (!Node->varlist_empty()) {
1826 OS << "use_device_ptr";
1827 VisitOMPClauseList(Node, '(');
1828 OS << ")";
1829 }
1830}
1831
1832void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1833 if (!Node->varlist_empty()) {
1834 OS << "is_device_ptr";
1835 VisitOMPClauseList(Node, '(');
1836 OS << ")";
1837 }
1838}
1839
Alexey Bataevb6e70842019-12-16 15:54:17 -05001840void OMPClausePrinter::VisitOMPNontemporalClause(OMPNontemporalClause *Node) {
1841 if (!Node->varlist_empty()) {
1842 OS << "nontemporal";
1843 VisitOMPClauseList(Node, '(');
1844 OS << ")";
1845 }
1846}
Alexey Bataevcb8e6912020-01-31 16:09:26 -05001847
1848void OMPClausePrinter::VisitOMPOrderClause(OMPOrderClause *Node) {
1849 OS << "order(" << getOpenMPSimpleClauseTypeName(OMPC_order, Node->getKind())
1850 << ")";
1851}
Johannes Doerfert1228d422019-12-19 20:42:12 -06001852
Alexey Bataev06dea732020-03-20 09:41:22 -04001853void OMPClausePrinter::VisitOMPInclusiveClause(OMPInclusiveClause *Node) {
1854 if (!Node->varlist_empty()) {
1855 OS << "inclusive";
1856 VisitOMPClauseList(Node, '(');
1857 OS << ")";
1858 }
1859}
1860
Alexey Bataev63828a32020-03-23 10:41:08 -04001861void OMPClausePrinter::VisitOMPExclusiveClause(OMPExclusiveClause *Node) {
1862 if (!Node->varlist_empty()) {
1863 OS << "exclusive";
1864 VisitOMPClauseList(Node, '(');
1865 OS << ")";
1866 }
1867}
1868
Johannes Doerfert1228d422019-12-19 20:42:12 -06001869void OMPTraitInfo::getAsVariantMatchInfo(
1870 ASTContext &ASTCtx, llvm::omp::VariantMatchInfo &VMI) const {
1871 for (const OMPTraitSet &Set : Sets) {
1872 for (const OMPTraitSelector &Selector : Set.Selectors) {
1873
1874 // User conditions are special as we evaluate the condition here.
1875 if (Selector.Kind == llvm::omp::TraitSelector::user_condition) {
1876 assert(Selector.ScoreOrCondition &&
1877 "Ill-formed user condition, expected condition expression!");
1878 assert(Selector.Properties.size() == 1 &&
1879 Selector.Properties.front().Kind ==
1880 llvm::omp::TraitProperty::user_condition_unknown &&
1881 "Ill-formed user condition, expected unknown trait property!");
1882
1883 llvm::APInt CondVal =
1884 Selector.ScoreOrCondition->EvaluateKnownConstInt(ASTCtx);
1885 VMI.addTrait(CondVal.isNullValue()
1886 ? llvm::omp::TraitProperty::user_condition_false
1887 : llvm::omp::TraitProperty::user_condition_true);
1888 continue;
1889 }
1890
1891 llvm::APInt Score;
1892 llvm::APInt *ScorePtr = nullptr;
1893 if (Selector.ScoreOrCondition) {
1894 Score = Selector.ScoreOrCondition->EvaluateKnownConstInt(ASTCtx);
1895 ScorePtr = &Score;
1896 }
1897 for (const OMPTraitProperty &Property : Selector.Properties)
1898 VMI.addTrait(Set.Kind, Property.Kind, ScorePtr);
1899
1900 if (Set.Kind != llvm::omp::TraitSet::construct)
1901 continue;
1902
1903 // TODO: This might not hold once we implement SIMD properly.
1904 assert(Selector.Properties.size() == 1 &&
1905 Selector.Properties.front().Kind ==
1906 llvm::omp::getOpenMPContextTraitPropertyForSelector(
1907 Selector.Kind) &&
1908 "Ill-formed construct selector!");
1909
1910 VMI.ConstructTraits.push_back(Selector.Properties.front().Kind);
1911 }
1912 }
1913}
1914
1915void OMPTraitInfo::print(llvm::raw_ostream &OS,
1916 const PrintingPolicy &Policy) const {
1917 bool FirstSet = true;
1918 for (const OMPTraitInfo::OMPTraitSet &Set : Sets) {
1919 if (!FirstSet)
1920 OS << ", ";
1921 FirstSet = false;
1922 OS << llvm::omp::getOpenMPContextTraitSetName(Set.Kind) << "={";
1923
1924 bool FirstSelector = true;
1925 for (const OMPTraitInfo::OMPTraitSelector &Selector : Set.Selectors) {
1926 if (!FirstSelector)
1927 OS << ", ";
1928 FirstSelector = false;
1929 OS << llvm::omp::getOpenMPContextTraitSelectorName(Selector.Kind);
1930
1931 bool AllowsTraitScore = false;
1932 bool RequiresProperty = false;
1933 llvm::omp::isValidTraitSelectorForTraitSet(
1934 Selector.Kind, Set.Kind, AllowsTraitScore, RequiresProperty);
1935
1936 if (!RequiresProperty)
1937 continue;
1938
1939 OS << "(";
1940 if (Selector.Kind == llvm::omp::TraitSelector::user_condition) {
1941 Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy);
1942 } else {
1943
1944 if (Selector.ScoreOrCondition) {
1945 OS << "score(";
1946 Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy);
1947 OS << "): ";
1948 }
1949
1950 bool FirstProperty = true;
1951 for (const OMPTraitInfo::OMPTraitProperty &Property :
1952 Selector.Properties) {
1953 if (!FirstProperty)
1954 OS << ", ";
1955 FirstProperty = false;
1956 OS << llvm::omp::getOpenMPContextTraitPropertyName(Property.Kind);
1957 }
1958 }
1959 OS << ")";
1960 }
1961 OS << "}";
1962 }
1963}
1964
1965llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS,
1966 const OMPTraitInfo &TI) {
1967 LangOptions LO;
1968 PrintingPolicy Policy(LO);
1969 TI.print(OS, Policy);
1970 return OS;
1971}
Johannes Doerfert55eca282020-03-13 23:42:05 -05001972llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS,
1973 const OMPTraitInfo *TI) {
1974 return TI ? OS << *TI : OS;
1975}