blob: 87ab3e333e22ea3722a37ddf0a6778e103a2d7ce [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,
706 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
707 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000708 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev61205072016-03-02 04:57:40 +0000709 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
710 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000711 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000712 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
713 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
714 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000715 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000716 Clause->setLHSExprs(LHSExprs);
717 Clause->setRHSExprs(RHSExprs);
718 Clause->setReductionOps(ReductionOps);
Alexey Bataev61205072016-03-02 04:57:40 +0000719 Clause->setPreInitStmt(PreInit);
720 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000721 return Clause;
722}
723
724OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
725 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000726 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000727 return new (Mem) OMPReductionClause(N);
728}
729
Alexey Bataev169d96a2017-07-18 20:17:46 +0000730void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
731 assert(Privates.size() == varlist_size() &&
732 "Number of private copies is not the same as the preallocated buffer");
733 std::copy(Privates.begin(), Privates.end(), varlist_end());
734}
735
736void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
737 assert(
738 LHSExprs.size() == varlist_size() &&
739 "Number of LHS expressions is not the same as the preallocated buffer");
740 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
741}
742
743void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
744 assert(
745 RHSExprs.size() == varlist_size() &&
746 "Number of RHS expressions is not the same as the preallocated buffer");
747 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
748}
749
750void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
751 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
752 "expressions is not the same "
753 "as the preallocated buffer");
754 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
755}
756
757OMPTaskReductionClause *OMPTaskReductionClause::Create(
758 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
759 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
760 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
761 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
762 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
763 Expr *PostUpdate) {
764 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
765 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
766 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
767 Clause->setVarRefs(VL);
768 Clause->setPrivates(Privates);
769 Clause->setLHSExprs(LHSExprs);
770 Clause->setRHSExprs(RHSExprs);
771 Clause->setReductionOps(ReductionOps);
772 Clause->setPreInitStmt(PreInit);
773 Clause->setPostUpdateExpr(PostUpdate);
774 return Clause;
775}
776
777OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
778 unsigned N) {
779 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
780 return new (Mem) OMPTaskReductionClause(N);
781}
782
Alexey Bataevfa312f32017-07-21 18:48:21 +0000783void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
784 assert(Privates.size() == varlist_size() &&
785 "Number of private copies is not the same as the preallocated buffer");
786 std::copy(Privates.begin(), Privates.end(), varlist_end());
787}
788
789void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
790 assert(
791 LHSExprs.size() == varlist_size() &&
792 "Number of LHS expressions is not the same as the preallocated buffer");
793 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
794}
795
796void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
797 assert(
798 RHSExprs.size() == varlist_size() &&
799 "Number of RHS expressions is not the same as the preallocated buffer");
800 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
801}
802
803void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
804 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
805 "expressions is not the same "
806 "as the preallocated buffer");
807 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
808}
809
Alexey Bataev88202be2017-07-27 13:20:36 +0000810void OMPInReductionClause::setTaskgroupDescriptors(
811 ArrayRef<Expr *> TaskgroupDescriptors) {
812 assert(TaskgroupDescriptors.size() == varlist_size() &&
813 "Number of in reduction descriptors is not the same as the "
814 "preallocated buffer");
815 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
816 getReductionOps().end());
817}
818
Alexey Bataevfa312f32017-07-21 18:48:21 +0000819OMPInReductionClause *OMPInReductionClause::Create(
820 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
821 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
822 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
823 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev88202be2017-07-27 13:20:36 +0000824 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
825 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
826 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000827 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
828 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
829 Clause->setVarRefs(VL);
830 Clause->setPrivates(Privates);
831 Clause->setLHSExprs(LHSExprs);
832 Clause->setRHSExprs(RHSExprs);
833 Clause->setReductionOps(ReductionOps);
Alexey Bataev88202be2017-07-27 13:20:36 +0000834 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000835 Clause->setPreInitStmt(PreInit);
836 Clause->setPostUpdateExpr(PostUpdate);
837 return Clause;
838}
839
840OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
841 unsigned N) {
Alexey Bataev88202be2017-07-27 13:20:36 +0000842 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000843 return new (Mem) OMPInReductionClause(N);
844}
845
Alexey Bataeve04483e2019-03-27 14:14:31 +0000846OMPAllocateClause *
847OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc,
848 SourceLocation LParenLoc, Expr *Allocator,
849 SourceLocation ColonLoc, SourceLocation EndLoc,
850 ArrayRef<Expr *> VL) {
851 // Allocate space for private variables and initializer expressions.
852 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
853 auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
854 ColonLoc, EndLoc, VL.size());
855 Clause->setVarRefs(VL);
856 return Clause;
857}
858
859OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
860 unsigned N) {
861 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
862 return new (Mem) OMPAllocateClause(N);
863}
864
James Y Knightb8bfd962015-10-02 13:41:04 +0000865OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
866 SourceLocation StartLoc,
867 SourceLocation LParenLoc,
868 SourceLocation EndLoc,
869 ArrayRef<Expr *> VL) {
Alexey Bataev8b427062016-05-25 12:36:08 +0000870 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000871 OMPFlushClause *Clause =
872 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
873 Clause->setVarRefs(VL);
874 return Clause;
875}
876
877OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000878 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000879 return new (Mem) OMPFlushClause(N);
880}
881
Alexey Bataevc112e942020-02-28 09:52:15 -0500882OMPDepobjClause *OMPDepobjClause::Create(const ASTContext &C,
883 SourceLocation StartLoc,
884 SourceLocation LParenLoc,
885 SourceLocation RParenLoc,
886 Expr *Depobj) {
887 auto *Clause = new (C) OMPDepobjClause(StartLoc, LParenLoc, RParenLoc);
888 Clause->setDepobj(Depobj);
889 return Clause;
890}
891
892OMPDepobjClause *OMPDepobjClause::CreateEmpty(const ASTContext &C) {
893 return new (C) OMPDepobjClause();
894}
895
Alexey Bataevf138fda2018-08-13 19:04:24 +0000896OMPDependClause *
897OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
898 SourceLocation LParenLoc, SourceLocation EndLoc,
899 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
900 SourceLocation ColonLoc, ArrayRef<Expr *> VL,
901 unsigned NumLoops) {
902 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
903 OMPDependClause *Clause = new (Mem)
904 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000905 Clause->setVarRefs(VL);
906 Clause->setDependencyKind(DepKind);
907 Clause->setDependencyLoc(DepLoc);
908 Clause->setColonLoc(ColonLoc);
Alexey Bataevf138fda2018-08-13 19:04:24 +0000909 for (unsigned I = 0 ; I < NumLoops; ++I)
910 Clause->setLoopData(I, nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000911 return Clause;
912}
913
Alexey Bataevf138fda2018-08-13 19:04:24 +0000914OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
915 unsigned NumLoops) {
916 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
917 return new (Mem) OMPDependClause(N, NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000918}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000919
Alexey Bataevf138fda2018-08-13 19:04:24 +0000920void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
921 assert((getDependencyKind() == OMPC_DEPEND_sink ||
922 getDependencyKind() == OMPC_DEPEND_source) &&
923 NumLoop < NumLoops &&
924 "Expected sink or source depend + loop index must be less number of "
925 "loops.");
926 auto It = std::next(getVarRefs().end(), NumLoop);
927 *It = Cnt;
Alexey Bataev8b427062016-05-25 12:36:08 +0000928}
929
Alexey Bataevf138fda2018-08-13 19:04:24 +0000930Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
931 assert((getDependencyKind() == OMPC_DEPEND_sink ||
932 getDependencyKind() == OMPC_DEPEND_source) &&
933 NumLoop < NumLoops &&
934 "Expected sink or source depend + loop index must be less number of "
935 "loops.");
936 auto It = std::next(getVarRefs().end(), NumLoop);
937 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000938}
939
Alexey Bataevf138fda2018-08-13 19:04:24 +0000940const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
941 assert((getDependencyKind() == OMPC_DEPEND_sink ||
942 getDependencyKind() == OMPC_DEPEND_source) &&
943 NumLoop < NumLoops &&
944 "Expected sink or source depend + loop index must be less number of "
945 "loops.");
946 auto It = std::next(getVarRefs().end(), NumLoop);
947 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000948}
949
Samuel Antao90927002016-04-26 14:54:23 +0000950unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
951 MappableExprComponentListsRef ComponentLists) {
952 unsigned TotalNum = 0u;
953 for (auto &C : ComponentLists)
954 TotalNum += C.size();
955 return TotalNum;
956}
957
958unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
Alexey Bataeve3727102018-04-18 15:57:46 +0000959 ArrayRef<const ValueDecl *> Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000960 unsigned TotalNum = 0u;
961 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
Alexey Bataeve3727102018-04-18 15:57:46 +0000962 for (const ValueDecl *D : Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000963 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
964 if (Cache.count(VD))
965 continue;
966 ++TotalNum;
967 Cache.insert(VD);
968 }
969 return TotalNum;
970}
971
Michael Kruse4304e9d2019-02-19 16:38:20 +0000972OMPMapClause *OMPMapClause::Create(
973 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
974 ArrayRef<ValueDecl *> Declarations,
975 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
976 ArrayRef<OpenMPMapModifierKind> MapModifiers,
977 ArrayRef<SourceLocation> MapModifiersLoc,
978 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
979 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
980 OMPMappableExprListSizeTy Sizes;
981 Sizes.NumVars = Vars.size();
982 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
983 Sizes.NumComponentLists = ComponentLists.size();
984 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao90927002016-04-26 14:54:23 +0000985
986 // We need to allocate:
Michael Kruse4304e9d2019-02-19 16:38:20 +0000987 // 2 x NumVars x Expr* - we have an original list expression and an associated
988 // user-defined mapper for each clause list entry.
Samuel Antao90927002016-04-26 14:54:23 +0000989 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
990 // with each component list.
991 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
992 // number of lists for each unique declaration and the size of each component
993 // list.
994 // NumComponents x MappableComponent - the total of all the components in all
995 // the lists.
996 void *Mem = C.Allocate(
997 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
998 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000999 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1000 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1001 Sizes.NumComponents));
1002 OMPMapClause *Clause = new (Mem)
1003 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
1004 Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
Samuel Antao90927002016-04-26 14:54:23 +00001005
1006 Clause->setVarRefs(Vars);
Michael Kruse4304e9d2019-02-19 16:38:20 +00001007 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao90927002016-04-26 14:54:23 +00001008 Clause->setClauseInfo(Declarations, ComponentLists);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001009 Clause->setMapType(Type);
1010 Clause->setMapLoc(TypeLoc);
1011 return Clause;
1012}
1013
Michael Kruse4304e9d2019-02-19 16:38:20 +00001014OMPMapClause *
1015OMPMapClause::CreateEmpty(const ASTContext &C,
1016 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao90927002016-04-26 14:54:23 +00001017 void *Mem = C.Allocate(
1018 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1019 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001020 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1021 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1022 Sizes.NumComponents));
1023 return new (Mem) OMPMapClause(Sizes);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001024}
Samuel Antao661c0902016-05-26 17:39:58 +00001025
Michael Kruse01f670d2019-02-22 22:29:42 +00001026OMPToClause *OMPToClause::Create(
1027 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1028 ArrayRef<ValueDecl *> Declarations,
1029 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1030 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001031 OMPMappableExprListSizeTy Sizes;
1032 Sizes.NumVars = Vars.size();
1033 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1034 Sizes.NumComponentLists = ComponentLists.size();
1035 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao661c0902016-05-26 17:39:58 +00001036
1037 // We need to allocate:
Michael Kruse01f670d2019-02-22 22:29:42 +00001038 // 2 x NumVars x Expr* - we have an original list expression and an associated
1039 // user-defined mapper for each clause list entry.
Samuel Antao661c0902016-05-26 17:39:58 +00001040 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1041 // with each component list.
1042 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1043 // number of lists for each unique declaration and the size of each component
1044 // list.
1045 // NumComponents x MappableComponent - the total of all the components in all
1046 // the lists.
1047 void *Mem = C.Allocate(
1048 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1049 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +00001050 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001051 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1052 Sizes.NumComponents));
Samuel Antao661c0902016-05-26 17:39:58 +00001053
Michael Kruse01f670d2019-02-22 22:29:42 +00001054 auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +00001055
1056 Clause->setVarRefs(Vars);
Michael Kruse01f670d2019-02-22 22:29:42 +00001057 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao661c0902016-05-26 17:39:58 +00001058 Clause->setClauseInfo(Declarations, ComponentLists);
1059 return Clause;
1060}
1061
Michael Kruse4304e9d2019-02-19 16:38:20 +00001062OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
1063 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao661c0902016-05-26 17:39:58 +00001064 void *Mem = C.Allocate(
1065 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1066 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +00001067 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001068 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1069 Sizes.NumComponents));
1070 return new (Mem) OMPToClause(Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +00001071}
Samuel Antaoec172c62016-05-26 17:49:04 +00001072
Michael Kruse0336c752019-02-25 20:34:15 +00001073OMPFromClause *OMPFromClause::Create(
1074 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1075 ArrayRef<ValueDecl *> Declarations,
1076 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1077 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001078 OMPMappableExprListSizeTy Sizes;
1079 Sizes.NumVars = Vars.size();
1080 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1081 Sizes.NumComponentLists = ComponentLists.size();
1082 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaoec172c62016-05-26 17:49:04 +00001083
1084 // We need to allocate:
Michael Kruse0336c752019-02-25 20:34:15 +00001085 // 2 x NumVars x Expr* - we have an original list expression and an associated
1086 // user-defined mapper for each clause list entry.
Samuel Antaoec172c62016-05-26 17:49:04 +00001087 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1088 // with each component list.
1089 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1090 // number of lists for each unique declaration and the size of each component
1091 // list.
1092 // NumComponents x MappableComponent - the total of all the components in all
1093 // the lists.
1094 void *Mem = C.Allocate(
1095 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1096 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001097 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001098 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1099 Sizes.NumComponents));
Samuel Antaoec172c62016-05-26 17:49:04 +00001100
Michael Kruse0336c752019-02-25 20:34:15 +00001101 auto *Clause =
1102 new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001103
1104 Clause->setVarRefs(Vars);
Michael Kruse0336c752019-02-25 20:34:15 +00001105 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antaoec172c62016-05-26 17:49:04 +00001106 Clause->setClauseInfo(Declarations, ComponentLists);
1107 return Clause;
1108}
1109
Michael Kruse4304e9d2019-02-19 16:38:20 +00001110OMPFromClause *
1111OMPFromClause::CreateEmpty(const ASTContext &C,
1112 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaoec172c62016-05-26 17:49:04 +00001113 void *Mem = C.Allocate(
1114 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1115 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse0336c752019-02-25 20:34:15 +00001116 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001117 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1118 Sizes.NumComponents));
1119 return new (Mem) OMPFromClause(Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +00001120}
Carlo Bertolli2404b172016-07-13 15:37:16 +00001121
Samuel Antaocc10b852016-07-28 14:23:26 +00001122void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1123 assert(VL.size() == varlist_size() &&
1124 "Number of private copies is not the same as the preallocated buffer");
1125 std::copy(VL.begin(), VL.end(), varlist_end());
1126}
1127
1128void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
1129 assert(VL.size() == varlist_size() &&
1130 "Number of inits is not the same as the preallocated buffer");
1131 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1132}
1133
1134OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001135 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1136 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
1137 ArrayRef<ValueDecl *> Declarations,
Samuel Antaocc10b852016-07-28 14:23:26 +00001138 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001139 OMPMappableExprListSizeTy Sizes;
1140 Sizes.NumVars = Vars.size();
1141 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1142 Sizes.NumComponentLists = ComponentLists.size();
1143 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaocc10b852016-07-28 14:23:26 +00001144
1145 // We need to allocate:
1146 // 3 x NumVars x Expr* - we have an original list expression for each clause
1147 // list entry and an equal number of private copies and inits.
1148 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1149 // with each component list.
1150 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1151 // number of lists for each unique declaration and the size of each component
1152 // list.
1153 // NumComponents x MappableComponent - the total of all the components in all
1154 // the lists.
1155 void *Mem = C.Allocate(
1156 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1157 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001158 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1159 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1160 Sizes.NumComponents));
Samuel Antaocc10b852016-07-28 14:23:26 +00001161
Michael Kruse4304e9d2019-02-19 16:38:20 +00001162 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
Samuel Antaocc10b852016-07-28 14:23:26 +00001163
1164 Clause->setVarRefs(Vars);
1165 Clause->setPrivateCopies(PrivateVars);
1166 Clause->setInits(Inits);
1167 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001168 return Clause;
1169}
1170
Michael Kruse4304e9d2019-02-19 16:38:20 +00001171OMPUseDevicePtrClause *
1172OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
1173 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaocc10b852016-07-28 14:23:26 +00001174 void *Mem = C.Allocate(
1175 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1176 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001177 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1178 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1179 Sizes.NumComponents));
1180 return new (Mem) OMPUseDevicePtrClause(Sizes);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001181}
Carlo Bertolli70594e92016-07-13 17:16:49 +00001182
Samuel Antao6890b092016-07-28 14:25:09 +00001183OMPIsDevicePtrClause *
Michael Kruse4304e9d2019-02-19 16:38:20 +00001184OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
Samuel Antao6890b092016-07-28 14:25:09 +00001185 ArrayRef<Expr *> Vars,
1186 ArrayRef<ValueDecl *> Declarations,
1187 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001188 OMPMappableExprListSizeTy Sizes;
1189 Sizes.NumVars = Vars.size();
1190 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1191 Sizes.NumComponentLists = ComponentLists.size();
1192 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao6890b092016-07-28 14:25:09 +00001193
1194 // We need to allocate:
1195 // NumVars x Expr* - we have an original list expression for each clause list
1196 // entry.
1197 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1198 // with each component list.
1199 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1200 // number of lists for each unique declaration and the size of each component
1201 // list.
1202 // NumComponents x MappableComponent - the total of all the components in all
1203 // the lists.
1204 void *Mem = C.Allocate(
1205 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1206 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001207 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1208 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1209 Sizes.NumComponents));
Samuel Antao6890b092016-07-28 14:25:09 +00001210
Michael Kruse4304e9d2019-02-19 16:38:20 +00001211 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
Samuel Antao6890b092016-07-28 14:25:09 +00001212
1213 Clause->setVarRefs(Vars);
1214 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001215 return Clause;
1216}
1217
Michael Kruse4304e9d2019-02-19 16:38:20 +00001218OMPIsDevicePtrClause *
1219OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1220 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao6890b092016-07-28 14:25:09 +00001221 void *Mem = C.Allocate(
1222 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1223 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001224 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1225 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1226 Sizes.NumComponents));
1227 return new (Mem) OMPIsDevicePtrClause(Sizes);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001228}
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001229
Alexey Bataevb6e70842019-12-16 15:54:17 -05001230OMPNontemporalClause *OMPNontemporalClause::Create(const ASTContext &C,
1231 SourceLocation StartLoc,
1232 SourceLocation LParenLoc,
1233 SourceLocation EndLoc,
1234 ArrayRef<Expr *> VL) {
Alexey Bataev0860db92019-12-19 10:01:10 -05001235 // Allocate space for nontemporal variables + private references.
1236 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
Alexey Bataevb6e70842019-12-16 15:54:17 -05001237 auto *Clause =
1238 new (Mem) OMPNontemporalClause(StartLoc, LParenLoc, EndLoc, VL.size());
1239 Clause->setVarRefs(VL);
1240 return Clause;
1241}
1242
1243OMPNontemporalClause *OMPNontemporalClause::CreateEmpty(const ASTContext &C,
1244 unsigned N) {
Alexey Bataev0860db92019-12-19 10:01:10 -05001245 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
Alexey Bataevb6e70842019-12-16 15:54:17 -05001246 return new (Mem) OMPNontemporalClause(N);
1247}
1248
Alexey Bataev0860db92019-12-19 10:01:10 -05001249void OMPNontemporalClause::setPrivateRefs(ArrayRef<Expr *> VL) {
1250 assert(VL.size() == varlist_size() && "Number of private references is not "
1251 "the same as the preallocated buffer");
1252 std::copy(VL.begin(), VL.end(), varlist_end());
1253}
1254
Alexey Bataev06dea732020-03-20 09:41:22 -04001255OMPInclusiveClause *OMPInclusiveClause::Create(const ASTContext &C,
1256 SourceLocation StartLoc,
1257 SourceLocation LParenLoc,
1258 SourceLocation EndLoc,
1259 ArrayRef<Expr *> VL) {
1260 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
1261 auto *Clause =
1262 new (Mem) OMPInclusiveClause(StartLoc, LParenLoc, EndLoc, VL.size());
1263 Clause->setVarRefs(VL);
1264 return Clause;
1265}
1266
1267OMPInclusiveClause *OMPInclusiveClause::CreateEmpty(const ASTContext &C,
1268 unsigned N) {
1269 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
1270 return new (Mem) OMPInclusiveClause(N);
1271}
1272
Alexey Bataev63828a32020-03-23 10:41:08 -04001273OMPExclusiveClause *OMPExclusiveClause::Create(const ASTContext &C,
1274 SourceLocation StartLoc,
1275 SourceLocation LParenLoc,
1276 SourceLocation EndLoc,
1277 ArrayRef<Expr *> VL) {
1278 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
1279 auto *Clause =
1280 new (Mem) OMPExclusiveClause(StartLoc, LParenLoc, EndLoc, VL.size());
1281 Clause->setVarRefs(VL);
1282 return Clause;
1283}
1284
1285OMPExclusiveClause *OMPExclusiveClause::CreateEmpty(const ASTContext &C,
1286 unsigned N) {
1287 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
1288 return new (Mem) OMPExclusiveClause(N);
1289}
1290
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001291//===----------------------------------------------------------------------===//
1292// OpenMP clauses printing methods
1293//===----------------------------------------------------------------------===//
1294
1295void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1296 OS << "if(";
Johannes Doerferteb3e81f2019-11-04 22:00:49 -06001297 if (Node->getNameModifier() != llvm::omp::OMPD_unknown)
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001298 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1299 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1300 OS << ")";
1301}
1302
1303void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1304 OS << "final(";
1305 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1306 OS << ")";
1307}
1308
1309void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1310 OS << "num_threads(";
1311 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1312 OS << ")";
1313}
1314
1315void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1316 OS << "safelen(";
1317 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1318 OS << ")";
1319}
1320
1321void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1322 OS << "simdlen(";
1323 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1324 OS << ")";
1325}
1326
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00001327void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
1328 OS << "allocator(";
1329 Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
1330 OS << ")";
1331}
1332
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001333void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1334 OS << "collapse(";
1335 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1336 OS << ")";
1337}
1338
Alexey Bataev0f0564b2020-03-17 09:17:42 -04001339void OMPClausePrinter::VisitOMPDetachClause(OMPDetachClause *Node) {
1340 OS << "detach(";
1341 Node->getEventHandler()->printPretty(OS, nullptr, Policy, 0);
1342 OS << ")";
1343}
1344
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001345void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1346 OS << "default("
Atmn Patel577c9b02020-02-14 21:45:49 -06001347 << getOpenMPSimpleClauseTypeName(OMPC_default,
1348 unsigned(Node->getDefaultKind()))
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001349 << ")";
1350}
1351
1352void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1353 OS << "proc_bind("
Johannes Doerfert6c5d1f402019-12-25 18:15:36 -06001354 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind,
1355 unsigned(Node->getProcBindKind()))
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001356 << ")";
1357}
1358
1359void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1360 OS << "unified_address";
1361}
1362
1363void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1364 OMPUnifiedSharedMemoryClause *) {
1365 OS << "unified_shared_memory";
1366}
1367
1368void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1369 OS << "reverse_offload";
1370}
1371
1372void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1373 OMPDynamicAllocatorsClause *) {
1374 OS << "dynamic_allocators";
1375}
1376
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00001377void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1378 OMPAtomicDefaultMemOrderClause *Node) {
1379 OS << "atomic_default_mem_order("
1380 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1381 Node->getAtomicDefaultMemOrderKind())
1382 << ")";
1383}
1384
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001385void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1386 OS << "schedule(";
1387 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1388 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1389 Node->getFirstScheduleModifier());
1390 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1391 OS << ", ";
1392 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1393 Node->getSecondScheduleModifier());
1394 }
1395 OS << ": ";
1396 }
1397 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1398 if (auto *E = Node->getChunkSize()) {
1399 OS << ", ";
1400 E->printPretty(OS, nullptr, Policy);
1401 }
1402 OS << ")";
1403}
1404
1405void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1406 OS << "ordered";
1407 if (auto *Num = Node->getNumForLoops()) {
1408 OS << "(";
1409 Num->printPretty(OS, nullptr, Policy, 0);
1410 OS << ")";
1411 }
1412}
1413
1414void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1415 OS << "nowait";
1416}
1417
1418void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1419 OS << "untied";
1420}
1421
1422void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1423 OS << "nogroup";
1424}
1425
1426void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1427 OS << "mergeable";
1428}
1429
1430void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1431
1432void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1433
Alexey Bataev82f7c202020-03-03 13:22:35 -05001434void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *Node) {
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001435 OS << "update";
Alexey Bataev82f7c202020-03-03 13:22:35 -05001436 if (Node->isExtended()) {
1437 OS << "(";
1438 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1439 Node->getDependencyKind());
1440 OS << ")";
1441 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001442}
1443
1444void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1445 OS << "capture";
1446}
1447
1448void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1449 OS << "seq_cst";
1450}
1451
Alexey Bataevea9166b2020-02-06 16:30:23 -05001452void OMPClausePrinter::VisitOMPAcqRelClause(OMPAcqRelClause *) {
1453 OS << "acq_rel";
1454}
1455
Alexey Bataev04a830f2020-02-10 14:30:39 -05001456void OMPClausePrinter::VisitOMPAcquireClause(OMPAcquireClause *) {
1457 OS << "acquire";
1458}
1459
Alexey Bataev95598342020-02-10 15:49:05 -05001460void OMPClausePrinter::VisitOMPReleaseClause(OMPReleaseClause *) {
1461 OS << "release";
1462}
1463
Alexey Bataev9a8defc2020-02-11 11:10:43 -05001464void OMPClausePrinter::VisitOMPRelaxedClause(OMPRelaxedClause *) {
1465 OS << "relaxed";
1466}
1467
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001468void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1469 OS << "threads";
1470}
1471
1472void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1473
1474void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1475 OS << "device(";
Alexey Bataev2f8894a2020-03-18 15:01:15 -04001476 OpenMPDeviceClauseModifier Modifier = Node->getModifier();
1477 if (Modifier != OMPC_DEVICE_unknown) {
1478 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), Modifier)
1479 << ": ";
1480 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001481 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1482 OS << ")";
1483}
1484
1485void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1486 OS << "num_teams(";
1487 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1488 OS << ")";
1489}
1490
1491void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1492 OS << "thread_limit(";
1493 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1494 OS << ")";
1495}
1496
1497void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1498 OS << "priority(";
1499 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1500 OS << ")";
1501}
1502
1503void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1504 OS << "grainsize(";
1505 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1506 OS << ")";
1507}
1508
1509void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1510 OS << "num_tasks(";
1511 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1512 OS << ")";
1513}
1514
1515void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1516 OS << "hint(";
1517 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1518 OS << ")";
1519}
1520
Alexey Bataev375437a2020-03-02 14:21:20 -05001521void OMPClausePrinter::VisitOMPDestroyClause(OMPDestroyClause *) {
1522 OS << "destroy";
1523}
1524
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001525template<typename T>
1526void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1527 for (typename T::varlist_iterator I = Node->varlist_begin(),
1528 E = Node->varlist_end();
1529 I != E; ++I) {
1530 assert(*I && "Expected non-null Stmt");
1531 OS << (I == Node->varlist_begin() ? StartSym : ',');
1532 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1533 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1534 DRE->printPretty(OS, nullptr, Policy, 0);
1535 else
1536 DRE->getDecl()->printQualifiedName(OS);
1537 } else
1538 (*I)->printPretty(OS, nullptr, Policy, 0);
1539 }
1540}
1541
Alexey Bataeve04483e2019-03-27 14:14:31 +00001542void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
1543 if (Node->varlist_empty())
1544 return;
1545 OS << "allocate";
1546 if (Expr *Allocator = Node->getAllocator()) {
1547 OS << "(";
1548 Allocator->printPretty(OS, nullptr, Policy, 0);
1549 OS << ":";
1550 VisitOMPClauseList(Node, ' ');
1551 } else {
1552 VisitOMPClauseList(Node, '(');
1553 }
1554 OS << ")";
1555}
1556
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001557void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1558 if (!Node->varlist_empty()) {
1559 OS << "private";
1560 VisitOMPClauseList(Node, '(');
1561 OS << ")";
1562 }
1563}
1564
1565void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1566 if (!Node->varlist_empty()) {
1567 OS << "firstprivate";
1568 VisitOMPClauseList(Node, '(');
1569 OS << ")";
1570 }
1571}
1572
1573void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1574 if (!Node->varlist_empty()) {
1575 OS << "lastprivate";
Alexey Bataev93dc40d2019-12-20 11:04:57 -05001576 OpenMPLastprivateModifier LPKind = Node->getKind();
1577 if (LPKind != OMPC_LASTPRIVATE_unknown) {
1578 OS << "("
1579 << getOpenMPSimpleClauseTypeName(OMPC_lastprivate, Node->getKind())
1580 << ":";
1581 }
1582 VisitOMPClauseList(Node, LPKind == OMPC_LASTPRIVATE_unknown ? '(' : ' ');
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001583 OS << ")";
1584 }
1585}
1586
1587void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1588 if (!Node->varlist_empty()) {
1589 OS << "shared";
1590 VisitOMPClauseList(Node, '(');
1591 OS << ")";
1592 }
1593}
1594
1595void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1596 if (!Node->varlist_empty()) {
1597 OS << "reduction(";
1598 NestedNameSpecifier *QualifierLoc =
1599 Node->getQualifierLoc().getNestedNameSpecifier();
1600 OverloadedOperatorKind OOK =
1601 Node->getNameInfo().getName().getCXXOverloadedOperator();
1602 if (QualifierLoc == nullptr && OOK != OO_None) {
1603 // Print reduction identifier in C format
1604 OS << getOperatorSpelling(OOK);
1605 } else {
1606 // Use C++ format
1607 if (QualifierLoc != nullptr)
1608 QualifierLoc->print(OS, Policy);
1609 OS << Node->getNameInfo();
1610 }
1611 OS << ":";
1612 VisitOMPClauseList(Node, ' ');
1613 OS << ")";
1614 }
1615}
1616
1617void OMPClausePrinter::VisitOMPTaskReductionClause(
1618 OMPTaskReductionClause *Node) {
1619 if (!Node->varlist_empty()) {
1620 OS << "task_reduction(";
1621 NestedNameSpecifier *QualifierLoc =
1622 Node->getQualifierLoc().getNestedNameSpecifier();
1623 OverloadedOperatorKind OOK =
1624 Node->getNameInfo().getName().getCXXOverloadedOperator();
1625 if (QualifierLoc == nullptr && OOK != OO_None) {
1626 // Print reduction identifier in C format
1627 OS << getOperatorSpelling(OOK);
1628 } else {
1629 // Use C++ format
1630 if (QualifierLoc != nullptr)
1631 QualifierLoc->print(OS, Policy);
1632 OS << Node->getNameInfo();
1633 }
1634 OS << ":";
1635 VisitOMPClauseList(Node, ' ');
1636 OS << ")";
1637 }
1638}
1639
1640void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1641 if (!Node->varlist_empty()) {
1642 OS << "in_reduction(";
1643 NestedNameSpecifier *QualifierLoc =
1644 Node->getQualifierLoc().getNestedNameSpecifier();
1645 OverloadedOperatorKind OOK =
1646 Node->getNameInfo().getName().getCXXOverloadedOperator();
1647 if (QualifierLoc == nullptr && OOK != OO_None) {
1648 // Print reduction identifier in C format
1649 OS << getOperatorSpelling(OOK);
1650 } else {
1651 // Use C++ format
1652 if (QualifierLoc != nullptr)
1653 QualifierLoc->print(OS, Policy);
1654 OS << Node->getNameInfo();
1655 }
1656 OS << ":";
1657 VisitOMPClauseList(Node, ' ');
1658 OS << ")";
1659 }
1660}
1661
1662void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1663 if (!Node->varlist_empty()) {
1664 OS << "linear";
1665 if (Node->getModifierLoc().isValid()) {
1666 OS << '('
1667 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1668 }
1669 VisitOMPClauseList(Node, '(');
1670 if (Node->getModifierLoc().isValid())
1671 OS << ')';
1672 if (Node->getStep() != nullptr) {
1673 OS << ": ";
1674 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1675 }
1676 OS << ")";
1677 }
1678}
1679
1680void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1681 if (!Node->varlist_empty()) {
1682 OS << "aligned";
1683 VisitOMPClauseList(Node, '(');
1684 if (Node->getAlignment() != nullptr) {
1685 OS << ": ";
1686 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1687 }
1688 OS << ")";
1689 }
1690}
1691
1692void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1693 if (!Node->varlist_empty()) {
1694 OS << "copyin";
1695 VisitOMPClauseList(Node, '(');
1696 OS << ")";
1697 }
1698}
1699
1700void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1701 if (!Node->varlist_empty()) {
1702 OS << "copyprivate";
1703 VisitOMPClauseList(Node, '(');
1704 OS << ")";
1705 }
1706}
1707
1708void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1709 if (!Node->varlist_empty()) {
1710 VisitOMPClauseList(Node, '(');
1711 OS << ")";
1712 }
1713}
1714
Alexey Bataevc112e942020-02-28 09:52:15 -05001715void OMPClausePrinter::VisitOMPDepobjClause(OMPDepobjClause *Node) {
1716 OS << "(";
1717 Node->getDepobj()->printPretty(OS, nullptr, Policy, 0);
1718 OS << ")";
1719}
1720
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001721void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1722 OS << "depend(";
1723 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1724 Node->getDependencyKind());
1725 if (!Node->varlist_empty()) {
1726 OS << " :";
1727 VisitOMPClauseList(Node, ' ');
1728 }
1729 OS << ")";
1730}
1731
1732void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1733 if (!Node->varlist_empty()) {
1734 OS << "map(";
1735 if (Node->getMapType() != OMPC_MAP_unknown) {
Kelvin Lief579432018-12-18 22:18:41 +00001736 for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1737 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1738 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1739 Node->getMapTypeModifier(I));
Michael Kruse4304e9d2019-02-19 16:38:20 +00001740 if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1741 OS << '(';
1742 NestedNameSpecifier *MapperNNS =
1743 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1744 if (MapperNNS)
1745 MapperNNS->print(OS, Policy);
1746 OS << Node->getMapperIdInfo() << ')';
1747 }
Kelvin Lief579432018-12-18 22:18:41 +00001748 OS << ',';
1749 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001750 }
1751 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1752 OS << ':';
1753 }
1754 VisitOMPClauseList(Node, ' ');
1755 OS << ")";
1756 }
1757}
1758
1759void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1760 if (!Node->varlist_empty()) {
1761 OS << "to";
Michael Kruse01f670d2019-02-22 22:29:42 +00001762 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1763 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1764 OS << '(';
1765 OS << "mapper(";
1766 NestedNameSpecifier *MapperNNS =
1767 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1768 if (MapperNNS)
1769 MapperNNS->print(OS, Policy);
1770 OS << MapperId << "):";
1771 VisitOMPClauseList(Node, ' ');
1772 } else {
1773 VisitOMPClauseList(Node, '(');
1774 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001775 OS << ")";
1776 }
1777}
1778
1779void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1780 if (!Node->varlist_empty()) {
1781 OS << "from";
Michael Kruse0336c752019-02-25 20:34:15 +00001782 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1783 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1784 OS << '(';
1785 OS << "mapper(";
1786 NestedNameSpecifier *MapperNNS =
1787 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1788 if (MapperNNS)
1789 MapperNNS->print(OS, Policy);
1790 OS << MapperId << "):";
1791 VisitOMPClauseList(Node, ' ');
1792 } else {
1793 VisitOMPClauseList(Node, '(');
1794 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001795 OS << ")";
1796 }
1797}
1798
1799void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1800 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1801 OMPC_dist_schedule, Node->getDistScheduleKind());
1802 if (auto *E = Node->getChunkSize()) {
1803 OS << ", ";
1804 E->printPretty(OS, nullptr, Policy);
1805 }
1806 OS << ")";
1807}
1808
1809void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1810 OS << "defaultmap(";
1811 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1812 Node->getDefaultmapModifier());
1813 OS << ": ";
1814 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1815 Node->getDefaultmapKind());
1816 OS << ")";
1817}
1818
1819void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1820 if (!Node->varlist_empty()) {
1821 OS << "use_device_ptr";
1822 VisitOMPClauseList(Node, '(');
1823 OS << ")";
1824 }
1825}
1826
1827void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1828 if (!Node->varlist_empty()) {
1829 OS << "is_device_ptr";
1830 VisitOMPClauseList(Node, '(');
1831 OS << ")";
1832 }
1833}
1834
Alexey Bataevb6e70842019-12-16 15:54:17 -05001835void OMPClausePrinter::VisitOMPNontemporalClause(OMPNontemporalClause *Node) {
1836 if (!Node->varlist_empty()) {
1837 OS << "nontemporal";
1838 VisitOMPClauseList(Node, '(');
1839 OS << ")";
1840 }
1841}
Alexey Bataevcb8e6912020-01-31 16:09:26 -05001842
1843void OMPClausePrinter::VisitOMPOrderClause(OMPOrderClause *Node) {
1844 OS << "order(" << getOpenMPSimpleClauseTypeName(OMPC_order, Node->getKind())
1845 << ")";
1846}
Johannes Doerfert1228d422019-12-19 20:42:12 -06001847
Alexey Bataev06dea732020-03-20 09:41:22 -04001848void OMPClausePrinter::VisitOMPInclusiveClause(OMPInclusiveClause *Node) {
1849 if (!Node->varlist_empty()) {
1850 OS << "inclusive";
1851 VisitOMPClauseList(Node, '(');
1852 OS << ")";
1853 }
1854}
1855
Alexey Bataev63828a32020-03-23 10:41:08 -04001856void OMPClausePrinter::VisitOMPExclusiveClause(OMPExclusiveClause *Node) {
1857 if (!Node->varlist_empty()) {
1858 OS << "exclusive";
1859 VisitOMPClauseList(Node, '(');
1860 OS << ")";
1861 }
1862}
1863
Johannes Doerfert1228d422019-12-19 20:42:12 -06001864void OMPTraitInfo::getAsVariantMatchInfo(
1865 ASTContext &ASTCtx, llvm::omp::VariantMatchInfo &VMI) const {
1866 for (const OMPTraitSet &Set : Sets) {
1867 for (const OMPTraitSelector &Selector : Set.Selectors) {
1868
1869 // User conditions are special as we evaluate the condition here.
1870 if (Selector.Kind == llvm::omp::TraitSelector::user_condition) {
1871 assert(Selector.ScoreOrCondition &&
1872 "Ill-formed user condition, expected condition expression!");
1873 assert(Selector.Properties.size() == 1 &&
1874 Selector.Properties.front().Kind ==
1875 llvm::omp::TraitProperty::user_condition_unknown &&
1876 "Ill-formed user condition, expected unknown trait property!");
1877
1878 llvm::APInt CondVal =
1879 Selector.ScoreOrCondition->EvaluateKnownConstInt(ASTCtx);
1880 VMI.addTrait(CondVal.isNullValue()
1881 ? llvm::omp::TraitProperty::user_condition_false
1882 : llvm::omp::TraitProperty::user_condition_true);
1883 continue;
1884 }
1885
1886 llvm::APInt Score;
1887 llvm::APInt *ScorePtr = nullptr;
1888 if (Selector.ScoreOrCondition) {
1889 Score = Selector.ScoreOrCondition->EvaluateKnownConstInt(ASTCtx);
1890 ScorePtr = &Score;
1891 }
1892 for (const OMPTraitProperty &Property : Selector.Properties)
1893 VMI.addTrait(Set.Kind, Property.Kind, ScorePtr);
1894
1895 if (Set.Kind != llvm::omp::TraitSet::construct)
1896 continue;
1897
1898 // TODO: This might not hold once we implement SIMD properly.
1899 assert(Selector.Properties.size() == 1 &&
1900 Selector.Properties.front().Kind ==
1901 llvm::omp::getOpenMPContextTraitPropertyForSelector(
1902 Selector.Kind) &&
1903 "Ill-formed construct selector!");
1904
1905 VMI.ConstructTraits.push_back(Selector.Properties.front().Kind);
1906 }
1907 }
1908}
1909
1910void OMPTraitInfo::print(llvm::raw_ostream &OS,
1911 const PrintingPolicy &Policy) const {
1912 bool FirstSet = true;
1913 for (const OMPTraitInfo::OMPTraitSet &Set : Sets) {
1914 if (!FirstSet)
1915 OS << ", ";
1916 FirstSet = false;
1917 OS << llvm::omp::getOpenMPContextTraitSetName(Set.Kind) << "={";
1918
1919 bool FirstSelector = true;
1920 for (const OMPTraitInfo::OMPTraitSelector &Selector : Set.Selectors) {
1921 if (!FirstSelector)
1922 OS << ", ";
1923 FirstSelector = false;
1924 OS << llvm::omp::getOpenMPContextTraitSelectorName(Selector.Kind);
1925
1926 bool AllowsTraitScore = false;
1927 bool RequiresProperty = false;
1928 llvm::omp::isValidTraitSelectorForTraitSet(
1929 Selector.Kind, Set.Kind, AllowsTraitScore, RequiresProperty);
1930
1931 if (!RequiresProperty)
1932 continue;
1933
1934 OS << "(";
1935 if (Selector.Kind == llvm::omp::TraitSelector::user_condition) {
1936 Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy);
1937 } else {
1938
1939 if (Selector.ScoreOrCondition) {
1940 OS << "score(";
1941 Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy);
1942 OS << "): ";
1943 }
1944
1945 bool FirstProperty = true;
1946 for (const OMPTraitInfo::OMPTraitProperty &Property :
1947 Selector.Properties) {
1948 if (!FirstProperty)
1949 OS << ", ";
1950 FirstProperty = false;
1951 OS << llvm::omp::getOpenMPContextTraitPropertyName(Property.Kind);
1952 }
1953 }
1954 OS << ")";
1955 }
1956 OS << "}";
1957 }
1958}
1959
1960llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS,
1961 const OMPTraitInfo &TI) {
1962 LangOptions LO;
1963 PrintingPolicy Policy(LO);
1964 TI.print(OS, Policy);
1965 return OS;
1966}
Johannes Doerfert55eca282020-03-13 23:42:05 -05001967llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS,
1968 const OMPTraitInfo *TI) {
1969 return TI ? OS << *TI : OS;
1970}