blob: 0f1cb0258a62bc55eaff0b92fc0465efb73a0246 [file] [log] [blame]
Eugene Zelenkod1b2d222017-11-29 23:27:36 +00001//===- OpenMPClause.cpp - Classes for OpenMP clauses ----------------------===//
James Y Knightb8bfd962015-10-02 13:41:04 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
James Y Knightb8bfd962015-10-02 13:41:04 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the subclesses of Stmt class declared in OpenMPClause.h
10//
11//===----------------------------------------------------------------------===//
12
13#include "clang/AST/OpenMPClause.h"
James Y Knightb8bfd962015-10-02 13:41:04 +000014#include "clang/AST/ASTContext.h"
Eugene Zelenkod1b2d222017-11-29 23:27:36 +000015#include "clang/AST/Decl.h"
Patrick Lyster074c3ae22018-10-18 14:28:23 +000016#include "clang/AST/DeclOpenMP.h"
Eugene Zelenkod1b2d222017-11-29 23:27:36 +000017#include "clang/Basic/LLVM.h"
18#include "llvm/ADT/SmallPtrSet.h"
19#include "llvm/Support/Casting.h"
20#include "llvm/Support/ErrorHandling.h"
21#include <algorithm>
22#include <cassert>
James Y Knightb8bfd962015-10-02 13:41:04 +000023
24using namespace clang;
25
26OMPClause::child_range OMPClause::children() {
27 switch (getClauseKind()) {
28 default:
29 break;
30#define OPENMP_CLAUSE(Name, Class) \
31 case OMPC_##Name: \
32 return static_cast<Class *>(this)->children();
Roman Lebedev23019f92019-01-28 17:04:11 +000033 OPENMP_CLAUSE(flush, OMPFlushClause)
James Y Knightb8bfd962015-10-02 13:41:04 +000034#include "clang/Basic/OpenMPKinds.def"
35 }
36 llvm_unreachable("unknown OMPClause");
37}
38
Alexey Bataev3392d762016-02-16 11:18:12 +000039OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
40 auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
41 return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr;
42}
43
44const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
45 switch (C->getClauseKind()) {
46 case OMPC_schedule:
47 return static_cast<const OMPScheduleClause *>(C);
48 case OMPC_dist_schedule:
49 return static_cast<const OMPDistScheduleClause *>(C);
Alexey Bataev417089f2016-02-17 13:19:37 +000050 case OMPC_firstprivate:
51 return static_cast<const OMPFirstprivateClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +000052 case OMPC_lastprivate:
53 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +000054 case OMPC_reduction:
55 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +000056 case OMPC_task_reduction:
57 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +000058 case OMPC_in_reduction:
59 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +000060 case OMPC_linear:
61 return static_cast<const OMPLinearClause *>(C);
Arpith Chacko Jacobfe4890a2017-01-18 20:40:48 +000062 case OMPC_if:
63 return static_cast<const OMPIfClause *>(C);
Arpith Chacko Jacob33c849a2017-01-25 00:57:16 +000064 case OMPC_num_threads:
65 return static_cast<const OMPNumThreadsClause *>(C);
Arpith Chacko Jacobbc126342017-01-25 11:28:18 +000066 case OMPC_num_teams:
67 return static_cast<const OMPNumTeamsClause *>(C);
Arpith Chacko Jacob7ecc0b72017-01-25 11:44:35 +000068 case OMPC_thread_limit:
69 return static_cast<const OMPThreadLimitClause *>(C);
Alexey Bataev931e19b2017-10-02 16:32:39 +000070 case OMPC_device:
71 return static_cast<const OMPDeviceClause *>(C);
Alexey Bataev3392d762016-02-16 11:18:12 +000072 case OMPC_default:
73 case OMPC_proc_bind:
Alexey Bataev3392d762016-02-16 11:18:12 +000074 case OMPC_final:
Alexey Bataev3392d762016-02-16 11:18:12 +000075 case OMPC_safelen:
76 case OMPC_simdlen:
77 case OMPC_collapse:
78 case OMPC_private:
Alexey Bataev005248a2016-02-25 05:25:57 +000079 case OMPC_shared:
Alexey Bataev005248a2016-02-25 05:25:57 +000080 case OMPC_aligned:
81 case OMPC_copyin:
82 case OMPC_copyprivate:
83 case OMPC_ordered:
84 case OMPC_nowait:
85 case OMPC_untied:
86 case OMPC_mergeable:
87 case OMPC_threadprivate:
88 case OMPC_flush:
89 case OMPC_read:
90 case OMPC_write:
91 case OMPC_update:
92 case OMPC_capture:
93 case OMPC_seq_cst:
94 case OMPC_depend:
Alexey Bataev005248a2016-02-25 05:25:57 +000095 case OMPC_threads:
96 case OMPC_simd:
97 case OMPC_map:
Alexey Bataev005248a2016-02-25 05:25:57 +000098 case OMPC_priority:
99 case OMPC_grainsize:
100 case OMPC_nogroup:
101 case OMPC_num_tasks:
102 case OMPC_hint:
103 case OMPC_defaultmap:
104 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000105 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000106 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000107 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000108 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000109 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000110 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000111 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000112 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000113 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000114 case OMPC_atomic_default_mem_order:
Alexey Bataev005248a2016-02-25 05:25:57 +0000115 break;
116 }
117
118 return nullptr;
119}
120
121OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
122 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
123 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
124}
125
126const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
127 switch (C->getClauseKind()) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000128 case OMPC_lastprivate:
Alexey Bataev005248a2016-02-25 05:25:57 +0000129 return static_cast<const OMPLastprivateClause *>(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000130 case OMPC_reduction:
131 return static_cast<const OMPReductionClause *>(C);
Alexey Bataev169d96a2017-07-18 20:17:46 +0000132 case OMPC_task_reduction:
133 return static_cast<const OMPTaskReductionClause *>(C);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000134 case OMPC_in_reduction:
135 return static_cast<const OMPInReductionClause *>(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000136 case OMPC_linear:
137 return static_cast<const OMPLinearClause *>(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000138 case OMPC_schedule:
139 case OMPC_dist_schedule:
140 case OMPC_firstprivate:
141 case OMPC_default:
142 case OMPC_proc_bind:
143 case OMPC_if:
144 case OMPC_final:
145 case OMPC_num_threads:
146 case OMPC_safelen:
147 case OMPC_simdlen:
148 case OMPC_collapse:
149 case OMPC_private:
Alexey Bataev3392d762016-02-16 11:18:12 +0000150 case OMPC_shared:
Alexey Bataev3392d762016-02-16 11:18:12 +0000151 case OMPC_aligned:
152 case OMPC_copyin:
153 case OMPC_copyprivate:
154 case OMPC_ordered:
155 case OMPC_nowait:
156 case OMPC_untied:
157 case OMPC_mergeable:
158 case OMPC_threadprivate:
159 case OMPC_flush:
160 case OMPC_read:
161 case OMPC_write:
162 case OMPC_update:
163 case OMPC_capture:
164 case OMPC_seq_cst:
165 case OMPC_depend:
166 case OMPC_device:
167 case OMPC_threads:
168 case OMPC_simd:
169 case OMPC_map:
170 case OMPC_num_teams:
171 case OMPC_thread_limit:
172 case OMPC_priority:
173 case OMPC_grainsize:
174 case OMPC_nogroup:
175 case OMPC_num_tasks:
176 case OMPC_hint:
177 case OMPC_defaultmap:
178 case OMPC_unknown:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000179 case OMPC_uniform:
Samuel Antao661c0902016-05-26 17:39:58 +0000180 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +0000181 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +0000182 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +0000183 case OMPC_is_device_ptr:
Kelvin Li1408f912018-09-26 04:28:39 +0000184 case OMPC_unified_address:
Patrick Lyster4a370b92018-10-01 13:47:43 +0000185 case OMPC_unified_shared_memory:
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000186 case OMPC_reverse_offload:
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000187 case OMPC_dynamic_allocators:
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000188 case OMPC_atomic_default_mem_order:
Alexey Bataev3392d762016-02-16 11:18:12 +0000189 break;
190 }
191
192 return nullptr;
193}
194
Alexey Bataevf138fda2018-08-13 19:04:24 +0000195OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
196 unsigned NumLoops,
197 SourceLocation StartLoc,
198 SourceLocation LParenLoc,
199 SourceLocation EndLoc) {
200 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
201 auto *Clause =
202 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
203 for (unsigned I = 0; I < NumLoops; ++I) {
204 Clause->setLoopNumIterations(I, nullptr);
205 Clause->setLoopCounter(I, nullptr);
206 }
207 return Clause;
208}
209
210OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
211 unsigned NumLoops) {
212 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
213 auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
214 for (unsigned I = 0; I < NumLoops; ++I) {
215 Clause->setLoopNumIterations(I, nullptr);
216 Clause->setLoopCounter(I, nullptr);
217 }
218 return Clause;
219}
220
221void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
222 Expr *NumIterations) {
223 assert(NumLoop < NumberOfLoops && "out of loops number.");
224 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
225}
226
227ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
228 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
229}
230
231void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
232 assert(NumLoop < NumberOfLoops && "out of loops number.");
233 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
234}
235
Mike Rice0ed46662018-09-20 17:19:41 +0000236Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000237 assert(NumLoop < NumberOfLoops && "out of loops number.");
238 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
239}
240
Mike Rice0ed46662018-09-20 17:19:41 +0000241const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
Alexey Bataevf138fda2018-08-13 19:04:24 +0000242 assert(NumLoop < NumberOfLoops && "out of loops number.");
243 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
244}
245
James Y Knightb8bfd962015-10-02 13:41:04 +0000246void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
247 assert(VL.size() == varlist_size() &&
248 "Number of private copies is not the same as the preallocated buffer");
249 std::copy(VL.begin(), VL.end(), varlist_end());
250}
251
252OMPPrivateClause *
253OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
254 SourceLocation LParenLoc, SourceLocation EndLoc,
255 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
256 // Allocate space for private variables and initializer expressions.
James Y Knight374fd202016-01-01 00:38:24 +0000257 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000258 OMPPrivateClause *Clause =
259 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
260 Clause->setVarRefs(VL);
261 Clause->setPrivateCopies(PrivateVL);
262 return Clause;
263}
264
265OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
266 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000267 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000268 return new (Mem) OMPPrivateClause(N);
269}
270
271void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
272 assert(VL.size() == varlist_size() &&
273 "Number of private copies is not the same as the preallocated buffer");
274 std::copy(VL.begin(), VL.end(), varlist_end());
275}
276
277void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
278 assert(VL.size() == varlist_size() &&
279 "Number of inits is not the same as the preallocated buffer");
280 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
281}
282
283OMPFirstprivateClause *
284OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
285 SourceLocation LParenLoc, SourceLocation EndLoc,
286 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
Alexey Bataev417089f2016-02-17 13:19:37 +0000287 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
James Y Knight374fd202016-01-01 00:38:24 +0000288 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000289 OMPFirstprivateClause *Clause =
290 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
291 Clause->setVarRefs(VL);
292 Clause->setPrivateCopies(PrivateVL);
293 Clause->setInits(InitVL);
Alexey Bataev417089f2016-02-17 13:19:37 +0000294 Clause->setPreInitStmt(PreInit);
James Y Knightb8bfd962015-10-02 13:41:04 +0000295 return Clause;
296}
297
298OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
299 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000300 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000301 return new (Mem) OMPFirstprivateClause(N);
302}
303
304void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
305 assert(PrivateCopies.size() == varlist_size() &&
306 "Number of private copies is not the same as the preallocated buffer");
307 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
308}
309
310void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
311 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
312 "not the same as the "
313 "preallocated buffer");
314 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
315}
316
317void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
318 assert(DstExprs.size() == varlist_size() && "Number of destination "
319 "expressions is not the same as "
320 "the preallocated buffer");
321 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
322}
323
324void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
325 assert(AssignmentOps.size() == varlist_size() &&
326 "Number of assignment expressions is not the same as the preallocated "
327 "buffer");
328 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
329 getDestinationExprs().end());
330}
331
332OMPLastprivateClause *OMPLastprivateClause::Create(
333 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
334 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
Alexey Bataev005248a2016-02-25 05:25:57 +0000335 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit,
336 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000337 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000338 OMPLastprivateClause *Clause =
339 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
340 Clause->setVarRefs(VL);
341 Clause->setSourceExprs(SrcExprs);
342 Clause->setDestinationExprs(DstExprs);
343 Clause->setAssignmentOps(AssignmentOps);
Alexey Bataev005248a2016-02-25 05:25:57 +0000344 Clause->setPreInitStmt(PreInit);
345 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000346 return Clause;
347}
348
349OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
350 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000351 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000352 return new (Mem) OMPLastprivateClause(N);
353}
354
355OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
356 SourceLocation StartLoc,
357 SourceLocation LParenLoc,
358 SourceLocation EndLoc,
359 ArrayRef<Expr *> VL) {
James Y Knight374fd202016-01-01 00:38:24 +0000360 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000361 OMPSharedClause *Clause =
362 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
363 Clause->setVarRefs(VL);
364 return Clause;
365}
366
367OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000368 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000369 return new (Mem) OMPSharedClause(N);
370}
371
372void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
373 assert(PL.size() == varlist_size() &&
374 "Number of privates is not the same as the preallocated buffer");
375 std::copy(PL.begin(), PL.end(), varlist_end());
376}
377
378void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
379 assert(IL.size() == varlist_size() &&
380 "Number of inits is not the same as the preallocated buffer");
381 std::copy(IL.begin(), IL.end(), getPrivates().end());
382}
383
384void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
385 assert(UL.size() == varlist_size() &&
386 "Number of updates is not the same as the preallocated buffer");
387 std::copy(UL.begin(), UL.end(), getInits().end());
388}
389
390void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
391 assert(FL.size() == varlist_size() &&
392 "Number of final updates is not the same as the preallocated buffer");
393 std::copy(FL.begin(), FL.end(), getUpdates().end());
394}
395
396OMPLinearClause *OMPLinearClause::Create(
397 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
398 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
399 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
Alexey Bataev78849fb2016-03-09 09:49:00 +0000400 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
401 Stmt *PreInit, Expr *PostUpdate) {
James Y Knightb8bfd962015-10-02 13:41:04 +0000402 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
403 // (Step and CalcStep).
James Y Knight374fd202016-01-01 00:38:24 +0000404 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2));
James Y Knightb8bfd962015-10-02 13:41:04 +0000405 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
406 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
407 Clause->setVarRefs(VL);
408 Clause->setPrivates(PL);
409 Clause->setInits(IL);
410 // Fill update and final expressions with zeroes, they are provided later,
411 // after the directive construction.
412 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
413 nullptr);
414 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
415 nullptr);
416 Clause->setStep(Step);
417 Clause->setCalcStep(CalcStep);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000418 Clause->setPreInitStmt(PreInit);
419 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000420 return Clause;
421}
422
423OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
424 unsigned NumVars) {
425 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
426 // (Step and CalcStep).
James Y Knight374fd202016-01-01 00:38:24 +0000427 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2));
James Y Knightb8bfd962015-10-02 13:41:04 +0000428 return new (Mem) OMPLinearClause(NumVars);
429}
430
431OMPAlignedClause *
432OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
433 SourceLocation LParenLoc, SourceLocation ColonLoc,
434 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
James Y Knight374fd202016-01-01 00:38:24 +0000435 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000436 OMPAlignedClause *Clause = new (Mem)
437 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
438 Clause->setVarRefs(VL);
439 Clause->setAlignment(A);
440 return Clause;
441}
442
443OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
444 unsigned NumVars) {
James Y Knight374fd202016-01-01 00:38:24 +0000445 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000446 return new (Mem) OMPAlignedClause(NumVars);
447}
448
449void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
450 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
451 "not the same as the "
452 "preallocated buffer");
453 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
454}
455
456void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
457 assert(DstExprs.size() == varlist_size() && "Number of destination "
458 "expressions is not the same as "
459 "the preallocated buffer");
460 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
461}
462
463void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
464 assert(AssignmentOps.size() == varlist_size() &&
465 "Number of assignment expressions is not the same as the preallocated "
466 "buffer");
467 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
468 getDestinationExprs().end());
469}
470
471OMPCopyinClause *OMPCopyinClause::Create(
472 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
473 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
474 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000475 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000476 OMPCopyinClause *Clause =
477 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
478 Clause->setVarRefs(VL);
479 Clause->setSourceExprs(SrcExprs);
480 Clause->setDestinationExprs(DstExprs);
481 Clause->setAssignmentOps(AssignmentOps);
482 return Clause;
483}
484
485OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000486 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000487 return new (Mem) OMPCopyinClause(N);
488}
489
490void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
491 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
492 "not the same as the "
493 "preallocated buffer");
494 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
495}
496
497void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
498 assert(DstExprs.size() == varlist_size() && "Number of destination "
499 "expressions is not the same as "
500 "the preallocated buffer");
501 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
502}
503
504void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
505 assert(AssignmentOps.size() == varlist_size() &&
506 "Number of assignment expressions is not the same as the preallocated "
507 "buffer");
508 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
509 getDestinationExprs().end());
510}
511
512OMPCopyprivateClause *OMPCopyprivateClause::Create(
513 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
514 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
515 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
James Y Knight374fd202016-01-01 00:38:24 +0000516 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000517 OMPCopyprivateClause *Clause =
518 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
519 Clause->setVarRefs(VL);
520 Clause->setSourceExprs(SrcExprs);
521 Clause->setDestinationExprs(DstExprs);
522 Clause->setAssignmentOps(AssignmentOps);
523 return Clause;
524}
525
526OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
527 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000528 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000529 return new (Mem) OMPCopyprivateClause(N);
530}
531
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000532void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
533 assert(Privates.size() == varlist_size() &&
534 "Number of private copies is not the same as the preallocated buffer");
535 std::copy(Privates.begin(), Privates.end(), varlist_end());
536}
537
James Y Knightb8bfd962015-10-02 13:41:04 +0000538void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
539 assert(
540 LHSExprs.size() == varlist_size() &&
541 "Number of LHS expressions is not the same as the preallocated buffer");
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000542 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
James Y Knightb8bfd962015-10-02 13:41:04 +0000543}
544
545void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
546 assert(
547 RHSExprs.size() == varlist_size() &&
548 "Number of RHS expressions is not the same as the preallocated buffer");
549 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
550}
551
552void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
553 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
554 "expressions is not the same "
555 "as the preallocated buffer");
556 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
557}
558
559OMPReductionClause *OMPReductionClause::Create(
560 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
561 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
562 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000563 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev61205072016-03-02 04:57:40 +0000564 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
565 Expr *PostUpdate) {
James Y Knight374fd202016-01-01 00:38:24 +0000566 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
James Y Knightb8bfd962015-10-02 13:41:04 +0000567 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
568 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
569 Clause->setVarRefs(VL);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000570 Clause->setPrivates(Privates);
James Y Knightb8bfd962015-10-02 13:41:04 +0000571 Clause->setLHSExprs(LHSExprs);
572 Clause->setRHSExprs(RHSExprs);
573 Clause->setReductionOps(ReductionOps);
Alexey Bataev61205072016-03-02 04:57:40 +0000574 Clause->setPreInitStmt(PreInit);
575 Clause->setPostUpdateExpr(PostUpdate);
James Y Knightb8bfd962015-10-02 13:41:04 +0000576 return Clause;
577}
578
579OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
580 unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000581 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000582 return new (Mem) OMPReductionClause(N);
583}
584
Alexey Bataev169d96a2017-07-18 20:17:46 +0000585void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
586 assert(Privates.size() == varlist_size() &&
587 "Number of private copies is not the same as the preallocated buffer");
588 std::copy(Privates.begin(), Privates.end(), varlist_end());
589}
590
591void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
592 assert(
593 LHSExprs.size() == varlist_size() &&
594 "Number of LHS expressions is not the same as the preallocated buffer");
595 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
596}
597
598void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
599 assert(
600 RHSExprs.size() == varlist_size() &&
601 "Number of RHS expressions is not the same as the preallocated buffer");
602 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
603}
604
605void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
606 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
607 "expressions is not the same "
608 "as the preallocated buffer");
609 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
610}
611
612OMPTaskReductionClause *OMPTaskReductionClause::Create(
613 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
614 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
615 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
616 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
617 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
618 Expr *PostUpdate) {
619 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
620 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
621 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
622 Clause->setVarRefs(VL);
623 Clause->setPrivates(Privates);
624 Clause->setLHSExprs(LHSExprs);
625 Clause->setRHSExprs(RHSExprs);
626 Clause->setReductionOps(ReductionOps);
627 Clause->setPreInitStmt(PreInit);
628 Clause->setPostUpdateExpr(PostUpdate);
629 return Clause;
630}
631
632OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
633 unsigned N) {
634 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
635 return new (Mem) OMPTaskReductionClause(N);
636}
637
Alexey Bataevfa312f32017-07-21 18:48:21 +0000638void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
639 assert(Privates.size() == varlist_size() &&
640 "Number of private copies is not the same as the preallocated buffer");
641 std::copy(Privates.begin(), Privates.end(), varlist_end());
642}
643
644void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
645 assert(
646 LHSExprs.size() == varlist_size() &&
647 "Number of LHS expressions is not the same as the preallocated buffer");
648 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
649}
650
651void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
652 assert(
653 RHSExprs.size() == varlist_size() &&
654 "Number of RHS expressions is not the same as the preallocated buffer");
655 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
656}
657
658void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
659 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
660 "expressions is not the same "
661 "as the preallocated buffer");
662 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
663}
664
Alexey Bataev88202be2017-07-27 13:20:36 +0000665void OMPInReductionClause::setTaskgroupDescriptors(
666 ArrayRef<Expr *> TaskgroupDescriptors) {
667 assert(TaskgroupDescriptors.size() == varlist_size() &&
668 "Number of in reduction descriptors is not the same as the "
669 "preallocated buffer");
670 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
671 getReductionOps().end());
672}
673
Alexey Bataevfa312f32017-07-21 18:48:21 +0000674OMPInReductionClause *OMPInReductionClause::Create(
675 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
676 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
677 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
678 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
Alexey Bataev88202be2017-07-27 13:20:36 +0000679 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
680 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
681 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000682 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
683 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
684 Clause->setVarRefs(VL);
685 Clause->setPrivates(Privates);
686 Clause->setLHSExprs(LHSExprs);
687 Clause->setRHSExprs(RHSExprs);
688 Clause->setReductionOps(ReductionOps);
Alexey Bataev88202be2017-07-27 13:20:36 +0000689 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
Alexey Bataevfa312f32017-07-21 18:48:21 +0000690 Clause->setPreInitStmt(PreInit);
691 Clause->setPostUpdateExpr(PostUpdate);
692 return Clause;
693}
694
695OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
696 unsigned N) {
Alexey Bataev88202be2017-07-27 13:20:36 +0000697 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
Alexey Bataevfa312f32017-07-21 18:48:21 +0000698 return new (Mem) OMPInReductionClause(N);
699}
700
James Y Knightb8bfd962015-10-02 13:41:04 +0000701OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
702 SourceLocation StartLoc,
703 SourceLocation LParenLoc,
704 SourceLocation EndLoc,
705 ArrayRef<Expr *> VL) {
Alexey Bataev8b427062016-05-25 12:36:08 +0000706 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
James Y Knightb8bfd962015-10-02 13:41:04 +0000707 OMPFlushClause *Clause =
708 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
709 Clause->setVarRefs(VL);
710 return Clause;
711}
712
713OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
James Y Knight374fd202016-01-01 00:38:24 +0000714 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
James Y Knightb8bfd962015-10-02 13:41:04 +0000715 return new (Mem) OMPFlushClause(N);
716}
717
Alexey Bataevf138fda2018-08-13 19:04:24 +0000718OMPDependClause *
719OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
720 SourceLocation LParenLoc, SourceLocation EndLoc,
721 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
722 SourceLocation ColonLoc, ArrayRef<Expr *> VL,
723 unsigned NumLoops) {
724 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
725 OMPDependClause *Clause = new (Mem)
726 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000727 Clause->setVarRefs(VL);
728 Clause->setDependencyKind(DepKind);
729 Clause->setDependencyLoc(DepLoc);
730 Clause->setColonLoc(ColonLoc);
Alexey Bataevf138fda2018-08-13 19:04:24 +0000731 for (unsigned I = 0 ; I < NumLoops; ++I)
732 Clause->setLoopData(I, nullptr);
James Y Knightb8bfd962015-10-02 13:41:04 +0000733 return Clause;
734}
735
Alexey Bataevf138fda2018-08-13 19:04:24 +0000736OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
737 unsigned NumLoops) {
738 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
739 return new (Mem) OMPDependClause(N, NumLoops);
James Y Knightb8bfd962015-10-02 13:41:04 +0000740}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000741
Alexey Bataevf138fda2018-08-13 19:04:24 +0000742void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
743 assert((getDependencyKind() == OMPC_DEPEND_sink ||
744 getDependencyKind() == OMPC_DEPEND_source) &&
745 NumLoop < NumLoops &&
746 "Expected sink or source depend + loop index must be less number of "
747 "loops.");
748 auto It = std::next(getVarRefs().end(), NumLoop);
749 *It = Cnt;
Alexey Bataev8b427062016-05-25 12:36:08 +0000750}
751
Alexey Bataevf138fda2018-08-13 19:04:24 +0000752Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
753 assert((getDependencyKind() == OMPC_DEPEND_sink ||
754 getDependencyKind() == OMPC_DEPEND_source) &&
755 NumLoop < NumLoops &&
756 "Expected sink or source depend + loop index must be less number of "
757 "loops.");
758 auto It = std::next(getVarRefs().end(), NumLoop);
759 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000760}
761
Alexey Bataevf138fda2018-08-13 19:04:24 +0000762const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
763 assert((getDependencyKind() == OMPC_DEPEND_sink ||
764 getDependencyKind() == OMPC_DEPEND_source) &&
765 NumLoop < NumLoops &&
766 "Expected sink or source depend + loop index must be less number of "
767 "loops.");
768 auto It = std::next(getVarRefs().end(), NumLoop);
769 return *It;
Alexey Bataev8b427062016-05-25 12:36:08 +0000770}
771
Samuel Antao90927002016-04-26 14:54:23 +0000772unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
773 MappableExprComponentListsRef ComponentLists) {
774 unsigned TotalNum = 0u;
775 for (auto &C : ComponentLists)
776 TotalNum += C.size();
777 return TotalNum;
778}
779
780unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
Alexey Bataeve3727102018-04-18 15:57:46 +0000781 ArrayRef<const ValueDecl *> Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000782 unsigned TotalNum = 0u;
783 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
Alexey Bataeve3727102018-04-18 15:57:46 +0000784 for (const ValueDecl *D : Declarations) {
Samuel Antao90927002016-04-26 14:54:23 +0000785 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
786 if (Cache.count(VD))
787 continue;
788 ++TotalNum;
789 Cache.insert(VD);
790 }
791 return TotalNum;
792}
793
Michael Kruse4304e9d2019-02-19 16:38:20 +0000794OMPMapClause *OMPMapClause::Create(
795 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
796 ArrayRef<ValueDecl *> Declarations,
797 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
798 ArrayRef<OpenMPMapModifierKind> MapModifiers,
799 ArrayRef<SourceLocation> MapModifiersLoc,
800 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
801 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
802 OMPMappableExprListSizeTy Sizes;
803 Sizes.NumVars = Vars.size();
804 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
805 Sizes.NumComponentLists = ComponentLists.size();
806 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao90927002016-04-26 14:54:23 +0000807
808 // We need to allocate:
Michael Kruse4304e9d2019-02-19 16:38:20 +0000809 // 2 x NumVars x Expr* - we have an original list expression and an associated
810 // user-defined mapper for each clause list entry.
Samuel Antao90927002016-04-26 14:54:23 +0000811 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
812 // with each component list.
813 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
814 // number of lists for each unique declaration and the size of each component
815 // list.
816 // NumComponents x MappableComponent - the total of all the components in all
817 // the lists.
818 void *Mem = C.Allocate(
819 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
820 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000821 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
822 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
823 Sizes.NumComponents));
824 OMPMapClause *Clause = new (Mem)
825 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
826 Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
Samuel Antao90927002016-04-26 14:54:23 +0000827
828 Clause->setVarRefs(Vars);
Michael Kruse4304e9d2019-02-19 16:38:20 +0000829 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao90927002016-04-26 14:54:23 +0000830 Clause->setClauseInfo(Declarations, ComponentLists);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000831 Clause->setMapType(Type);
832 Clause->setMapLoc(TypeLoc);
833 return Clause;
834}
835
Michael Kruse4304e9d2019-02-19 16:38:20 +0000836OMPMapClause *
837OMPMapClause::CreateEmpty(const ASTContext &C,
838 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao90927002016-04-26 14:54:23 +0000839 void *Mem = C.Allocate(
840 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
841 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000842 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
843 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
844 Sizes.NumComponents));
845 return new (Mem) OMPMapClause(Sizes);
Kelvin Li0bff7af2015-11-23 05:32:03 +0000846}
Samuel Antao661c0902016-05-26 17:39:58 +0000847
Michael Kruse01f670d2019-02-22 22:29:42 +0000848OMPToClause *OMPToClause::Create(
849 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
850 ArrayRef<ValueDecl *> Declarations,
851 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
852 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000853 OMPMappableExprListSizeTy Sizes;
854 Sizes.NumVars = Vars.size();
855 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
856 Sizes.NumComponentLists = ComponentLists.size();
857 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao661c0902016-05-26 17:39:58 +0000858
859 // We need to allocate:
Michael Kruse01f670d2019-02-22 22:29:42 +0000860 // 2 x NumVars x Expr* - we have an original list expression and an associated
861 // user-defined mapper for each clause list entry.
Samuel Antao661c0902016-05-26 17:39:58 +0000862 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
863 // with each component list.
864 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
865 // number of lists for each unique declaration and the size of each component
866 // list.
867 // NumComponents x MappableComponent - the total of all the components in all
868 // the lists.
869 void *Mem = C.Allocate(
870 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
871 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +0000872 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000873 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
874 Sizes.NumComponents));
Samuel Antao661c0902016-05-26 17:39:58 +0000875
Michael Kruse01f670d2019-02-22 22:29:42 +0000876 auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +0000877
878 Clause->setVarRefs(Vars);
Michael Kruse01f670d2019-02-22 22:29:42 +0000879 Clause->setUDMapperRefs(UDMapperRefs);
Samuel Antao661c0902016-05-26 17:39:58 +0000880 Clause->setClauseInfo(Declarations, ComponentLists);
881 return Clause;
882}
883
Michael Kruse4304e9d2019-02-19 16:38:20 +0000884OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
885 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao661c0902016-05-26 17:39:58 +0000886 void *Mem = C.Allocate(
887 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
888 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse01f670d2019-02-22 22:29:42 +0000889 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
Michael Kruse4304e9d2019-02-19 16:38:20 +0000890 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
891 Sizes.NumComponents));
892 return new (Mem) OMPToClause(Sizes);
Samuel Antao661c0902016-05-26 17:39:58 +0000893}
Samuel Antaoec172c62016-05-26 17:49:04 +0000894
895OMPFromClause *
Michael Kruse4304e9d2019-02-19 16:38:20 +0000896OMPFromClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
Samuel Antaoec172c62016-05-26 17:49:04 +0000897 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
898 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000899 OMPMappableExprListSizeTy Sizes;
900 Sizes.NumVars = Vars.size();
901 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
902 Sizes.NumComponentLists = ComponentLists.size();
903 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaoec172c62016-05-26 17:49:04 +0000904
905 // We need to allocate:
906 // NumVars x Expr* - we have an original list expression for each clause list
907 // entry.
908 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
909 // with each component list.
910 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
911 // number of lists for each unique declaration and the size of each component
912 // list.
913 // NumComponents x MappableComponent - the total of all the components in all
914 // the lists.
915 void *Mem = C.Allocate(
916 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
917 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000918 Sizes.NumVars, Sizes.NumUniqueDeclarations,
919 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
920 Sizes.NumComponents));
Samuel Antaoec172c62016-05-26 17:49:04 +0000921
Michael Kruse4304e9d2019-02-19 16:38:20 +0000922 OMPFromClause *Clause = new (Mem) OMPFromClause(Locs, Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +0000923
924 Clause->setVarRefs(Vars);
925 Clause->setClauseInfo(Declarations, ComponentLists);
926 return Clause;
927}
928
Michael Kruse4304e9d2019-02-19 16:38:20 +0000929OMPFromClause *
930OMPFromClause::CreateEmpty(const ASTContext &C,
931 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaoec172c62016-05-26 17:49:04 +0000932 void *Mem = C.Allocate(
933 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
934 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000935 Sizes.NumVars, Sizes.NumUniqueDeclarations,
936 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
937 Sizes.NumComponents));
938 return new (Mem) OMPFromClause(Sizes);
Samuel Antaoec172c62016-05-26 17:49:04 +0000939}
Carlo Bertolli2404b172016-07-13 15:37:16 +0000940
Samuel Antaocc10b852016-07-28 14:23:26 +0000941void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
942 assert(VL.size() == varlist_size() &&
943 "Number of private copies is not the same as the preallocated buffer");
944 std::copy(VL.begin(), VL.end(), varlist_end());
945}
946
947void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
948 assert(VL.size() == varlist_size() &&
949 "Number of inits is not the same as the preallocated buffer");
950 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
951}
952
953OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000954 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
955 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
956 ArrayRef<ValueDecl *> Declarations,
Samuel Antaocc10b852016-07-28 14:23:26 +0000957 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +0000958 OMPMappableExprListSizeTy Sizes;
959 Sizes.NumVars = Vars.size();
960 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
961 Sizes.NumComponentLists = ComponentLists.size();
962 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antaocc10b852016-07-28 14:23:26 +0000963
964 // We need to allocate:
965 // 3 x NumVars x Expr* - we have an original list expression for each clause
966 // list entry and an equal number of private copies and inits.
967 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
968 // with each component list.
969 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
970 // number of lists for each unique declaration and the size of each component
971 // list.
972 // NumComponents x MappableComponent - the total of all the components in all
973 // the lists.
974 void *Mem = C.Allocate(
975 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
976 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000977 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
978 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
979 Sizes.NumComponents));
Samuel Antaocc10b852016-07-28 14:23:26 +0000980
Michael Kruse4304e9d2019-02-19 16:38:20 +0000981 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
Samuel Antaocc10b852016-07-28 14:23:26 +0000982
983 Clause->setVarRefs(Vars);
984 Clause->setPrivateCopies(PrivateVars);
985 Clause->setInits(Inits);
986 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli2404b172016-07-13 15:37:16 +0000987 return Clause;
988}
989
Michael Kruse4304e9d2019-02-19 16:38:20 +0000990OMPUseDevicePtrClause *
991OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
992 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antaocc10b852016-07-28 14:23:26 +0000993 void *Mem = C.Allocate(
994 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
995 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +0000996 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
997 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
998 Sizes.NumComponents));
999 return new (Mem) OMPUseDevicePtrClause(Sizes);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001000}
Carlo Bertolli70594e92016-07-13 17:16:49 +00001001
Samuel Antao6890b092016-07-28 14:25:09 +00001002OMPIsDevicePtrClause *
Michael Kruse4304e9d2019-02-19 16:38:20 +00001003OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
Samuel Antao6890b092016-07-28 14:25:09 +00001004 ArrayRef<Expr *> Vars,
1005 ArrayRef<ValueDecl *> Declarations,
1006 MappableExprComponentListsRef ComponentLists) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00001007 OMPMappableExprListSizeTy Sizes;
1008 Sizes.NumVars = Vars.size();
1009 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1010 Sizes.NumComponentLists = ComponentLists.size();
1011 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
Samuel Antao6890b092016-07-28 14:25:09 +00001012
1013 // We need to allocate:
1014 // NumVars x Expr* - we have an original list expression for each clause list
1015 // entry.
1016 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1017 // with each component list.
1018 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1019 // number of lists for each unique declaration and the size of each component
1020 // list.
1021 // NumComponents x MappableComponent - the total of all the components in all
1022 // the lists.
1023 void *Mem = C.Allocate(
1024 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1025 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001026 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1027 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1028 Sizes.NumComponents));
Samuel Antao6890b092016-07-28 14:25:09 +00001029
Michael Kruse4304e9d2019-02-19 16:38:20 +00001030 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
Samuel Antao6890b092016-07-28 14:25:09 +00001031
1032 Clause->setVarRefs(Vars);
1033 Clause->setClauseInfo(Declarations, ComponentLists);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001034 return Clause;
1035}
1036
Michael Kruse4304e9d2019-02-19 16:38:20 +00001037OMPIsDevicePtrClause *
1038OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1039 const OMPMappableExprListSizeTy &Sizes) {
Samuel Antao6890b092016-07-28 14:25:09 +00001040 void *Mem = C.Allocate(
1041 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1042 OMPClauseMappableExprCommon::MappableComponent>(
Michael Kruse4304e9d2019-02-19 16:38:20 +00001043 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1044 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1045 Sizes.NumComponents));
1046 return new (Mem) OMPIsDevicePtrClause(Sizes);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001047}
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001048
1049//===----------------------------------------------------------------------===//
1050// OpenMP clauses printing methods
1051//===----------------------------------------------------------------------===//
1052
1053void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1054 OS << "if(";
1055 if (Node->getNameModifier() != OMPD_unknown)
1056 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1057 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1058 OS << ")";
1059}
1060
1061void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1062 OS << "final(";
1063 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1064 OS << ")";
1065}
1066
1067void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1068 OS << "num_threads(";
1069 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1070 OS << ")";
1071}
1072
1073void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1074 OS << "safelen(";
1075 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1076 OS << ")";
1077}
1078
1079void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1080 OS << "simdlen(";
1081 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1082 OS << ")";
1083}
1084
1085void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1086 OS << "collapse(";
1087 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1088 OS << ")";
1089}
1090
1091void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1092 OS << "default("
1093 << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
1094 << ")";
1095}
1096
1097void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1098 OS << "proc_bind("
1099 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, Node->getProcBindKind())
1100 << ")";
1101}
1102
1103void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1104 OS << "unified_address";
1105}
1106
1107void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1108 OMPUnifiedSharedMemoryClause *) {
1109 OS << "unified_shared_memory";
1110}
1111
1112void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1113 OS << "reverse_offload";
1114}
1115
1116void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1117 OMPDynamicAllocatorsClause *) {
1118 OS << "dynamic_allocators";
1119}
1120
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00001121void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1122 OMPAtomicDefaultMemOrderClause *Node) {
1123 OS << "atomic_default_mem_order("
1124 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1125 Node->getAtomicDefaultMemOrderKind())
1126 << ")";
1127}
1128
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001129void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1130 OS << "schedule(";
1131 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1132 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1133 Node->getFirstScheduleModifier());
1134 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1135 OS << ", ";
1136 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1137 Node->getSecondScheduleModifier());
1138 }
1139 OS << ": ";
1140 }
1141 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1142 if (auto *E = Node->getChunkSize()) {
1143 OS << ", ";
1144 E->printPretty(OS, nullptr, Policy);
1145 }
1146 OS << ")";
1147}
1148
1149void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1150 OS << "ordered";
1151 if (auto *Num = Node->getNumForLoops()) {
1152 OS << "(";
1153 Num->printPretty(OS, nullptr, Policy, 0);
1154 OS << ")";
1155 }
1156}
1157
1158void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1159 OS << "nowait";
1160}
1161
1162void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1163 OS << "untied";
1164}
1165
1166void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1167 OS << "nogroup";
1168}
1169
1170void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1171 OS << "mergeable";
1172}
1173
1174void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1175
1176void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1177
1178void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
1179 OS << "update";
1180}
1181
1182void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1183 OS << "capture";
1184}
1185
1186void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1187 OS << "seq_cst";
1188}
1189
1190void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1191 OS << "threads";
1192}
1193
1194void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1195
1196void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1197 OS << "device(";
1198 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1199 OS << ")";
1200}
1201
1202void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1203 OS << "num_teams(";
1204 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1205 OS << ")";
1206}
1207
1208void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1209 OS << "thread_limit(";
1210 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1211 OS << ")";
1212}
1213
1214void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1215 OS << "priority(";
1216 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1217 OS << ")";
1218}
1219
1220void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1221 OS << "grainsize(";
1222 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1223 OS << ")";
1224}
1225
1226void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1227 OS << "num_tasks(";
1228 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1229 OS << ")";
1230}
1231
1232void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1233 OS << "hint(";
1234 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1235 OS << ")";
1236}
1237
1238template<typename T>
1239void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1240 for (typename T::varlist_iterator I = Node->varlist_begin(),
1241 E = Node->varlist_end();
1242 I != E; ++I) {
1243 assert(*I && "Expected non-null Stmt");
1244 OS << (I == Node->varlist_begin() ? StartSym : ',');
1245 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1246 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1247 DRE->printPretty(OS, nullptr, Policy, 0);
1248 else
1249 DRE->getDecl()->printQualifiedName(OS);
1250 } else
1251 (*I)->printPretty(OS, nullptr, Policy, 0);
1252 }
1253}
1254
1255void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1256 if (!Node->varlist_empty()) {
1257 OS << "private";
1258 VisitOMPClauseList(Node, '(');
1259 OS << ")";
1260 }
1261}
1262
1263void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1264 if (!Node->varlist_empty()) {
1265 OS << "firstprivate";
1266 VisitOMPClauseList(Node, '(');
1267 OS << ")";
1268 }
1269}
1270
1271void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1272 if (!Node->varlist_empty()) {
1273 OS << "lastprivate";
1274 VisitOMPClauseList(Node, '(');
1275 OS << ")";
1276 }
1277}
1278
1279void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1280 if (!Node->varlist_empty()) {
1281 OS << "shared";
1282 VisitOMPClauseList(Node, '(');
1283 OS << ")";
1284 }
1285}
1286
1287void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1288 if (!Node->varlist_empty()) {
1289 OS << "reduction(";
1290 NestedNameSpecifier *QualifierLoc =
1291 Node->getQualifierLoc().getNestedNameSpecifier();
1292 OverloadedOperatorKind OOK =
1293 Node->getNameInfo().getName().getCXXOverloadedOperator();
1294 if (QualifierLoc == nullptr && OOK != OO_None) {
1295 // Print reduction identifier in C format
1296 OS << getOperatorSpelling(OOK);
1297 } else {
1298 // Use C++ format
1299 if (QualifierLoc != nullptr)
1300 QualifierLoc->print(OS, Policy);
1301 OS << Node->getNameInfo();
1302 }
1303 OS << ":";
1304 VisitOMPClauseList(Node, ' ');
1305 OS << ")";
1306 }
1307}
1308
1309void OMPClausePrinter::VisitOMPTaskReductionClause(
1310 OMPTaskReductionClause *Node) {
1311 if (!Node->varlist_empty()) {
1312 OS << "task_reduction(";
1313 NestedNameSpecifier *QualifierLoc =
1314 Node->getQualifierLoc().getNestedNameSpecifier();
1315 OverloadedOperatorKind OOK =
1316 Node->getNameInfo().getName().getCXXOverloadedOperator();
1317 if (QualifierLoc == nullptr && OOK != OO_None) {
1318 // Print reduction identifier in C format
1319 OS << getOperatorSpelling(OOK);
1320 } else {
1321 // Use C++ format
1322 if (QualifierLoc != nullptr)
1323 QualifierLoc->print(OS, Policy);
1324 OS << Node->getNameInfo();
1325 }
1326 OS << ":";
1327 VisitOMPClauseList(Node, ' ');
1328 OS << ")";
1329 }
1330}
1331
1332void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1333 if (!Node->varlist_empty()) {
1334 OS << "in_reduction(";
1335 NestedNameSpecifier *QualifierLoc =
1336 Node->getQualifierLoc().getNestedNameSpecifier();
1337 OverloadedOperatorKind OOK =
1338 Node->getNameInfo().getName().getCXXOverloadedOperator();
1339 if (QualifierLoc == nullptr && OOK != OO_None) {
1340 // Print reduction identifier in C format
1341 OS << getOperatorSpelling(OOK);
1342 } else {
1343 // Use C++ format
1344 if (QualifierLoc != nullptr)
1345 QualifierLoc->print(OS, Policy);
1346 OS << Node->getNameInfo();
1347 }
1348 OS << ":";
1349 VisitOMPClauseList(Node, ' ');
1350 OS << ")";
1351 }
1352}
1353
1354void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1355 if (!Node->varlist_empty()) {
1356 OS << "linear";
1357 if (Node->getModifierLoc().isValid()) {
1358 OS << '('
1359 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1360 }
1361 VisitOMPClauseList(Node, '(');
1362 if (Node->getModifierLoc().isValid())
1363 OS << ')';
1364 if (Node->getStep() != nullptr) {
1365 OS << ": ";
1366 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1367 }
1368 OS << ")";
1369 }
1370}
1371
1372void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1373 if (!Node->varlist_empty()) {
1374 OS << "aligned";
1375 VisitOMPClauseList(Node, '(');
1376 if (Node->getAlignment() != nullptr) {
1377 OS << ": ";
1378 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1379 }
1380 OS << ")";
1381 }
1382}
1383
1384void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1385 if (!Node->varlist_empty()) {
1386 OS << "copyin";
1387 VisitOMPClauseList(Node, '(');
1388 OS << ")";
1389 }
1390}
1391
1392void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1393 if (!Node->varlist_empty()) {
1394 OS << "copyprivate";
1395 VisitOMPClauseList(Node, '(');
1396 OS << ")";
1397 }
1398}
1399
1400void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1401 if (!Node->varlist_empty()) {
1402 VisitOMPClauseList(Node, '(');
1403 OS << ")";
1404 }
1405}
1406
1407void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1408 OS << "depend(";
1409 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1410 Node->getDependencyKind());
1411 if (!Node->varlist_empty()) {
1412 OS << " :";
1413 VisitOMPClauseList(Node, ' ');
1414 }
1415 OS << ")";
1416}
1417
1418void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1419 if (!Node->varlist_empty()) {
1420 OS << "map(";
1421 if (Node->getMapType() != OMPC_MAP_unknown) {
Kelvin Lief579432018-12-18 22:18:41 +00001422 for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1423 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1424 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1425 Node->getMapTypeModifier(I));
Michael Kruse4304e9d2019-02-19 16:38:20 +00001426 if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1427 OS << '(';
1428 NestedNameSpecifier *MapperNNS =
1429 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1430 if (MapperNNS)
1431 MapperNNS->print(OS, Policy);
1432 OS << Node->getMapperIdInfo() << ')';
1433 }
Kelvin Lief579432018-12-18 22:18:41 +00001434 OS << ',';
1435 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001436 }
1437 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1438 OS << ':';
1439 }
1440 VisitOMPClauseList(Node, ' ');
1441 OS << ")";
1442 }
1443}
1444
1445void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1446 if (!Node->varlist_empty()) {
1447 OS << "to";
Michael Kruse01f670d2019-02-22 22:29:42 +00001448 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1449 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1450 OS << '(';
1451 OS << "mapper(";
1452 NestedNameSpecifier *MapperNNS =
1453 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1454 if (MapperNNS)
1455 MapperNNS->print(OS, Policy);
1456 OS << MapperId << "):";
1457 VisitOMPClauseList(Node, ' ');
1458 } else {
1459 VisitOMPClauseList(Node, '(');
1460 }
Patrick Lyster074c3ae22018-10-18 14:28:23 +00001461 OS << ")";
1462 }
1463}
1464
1465void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1466 if (!Node->varlist_empty()) {
1467 OS << "from";
1468 VisitOMPClauseList(Node, '(');
1469 OS << ")";
1470 }
1471}
1472
1473void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1474 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1475 OMPC_dist_schedule, Node->getDistScheduleKind());
1476 if (auto *E = Node->getChunkSize()) {
1477 OS << ", ";
1478 E->printPretty(OS, nullptr, Policy);
1479 }
1480 OS << ")";
1481}
1482
1483void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1484 OS << "defaultmap(";
1485 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1486 Node->getDefaultmapModifier());
1487 OS << ": ";
1488 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1489 Node->getDefaultmapKind());
1490 OS << ")";
1491}
1492
1493void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1494 if (!Node->varlist_empty()) {
1495 OS << "use_device_ptr";
1496 VisitOMPClauseList(Node, '(');
1497 OS << ")";
1498 }
1499}
1500
1501void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1502 if (!Node->varlist_empty()) {
1503 OS << "is_device_ptr";
1504 VisitOMPClauseList(Node, '(');
1505 OS << ")";
1506 }
1507}
1508