1//===- OpenMPClause.cpp - Classes for OpenMP clauses ----------------------===//
2//
3// 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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the subclesses of Stmt class declared in OpenMPClause.h
10//
11//===----------------------------------------------------------------------===//
12
13#include "clang/AST/OpenMPClause.h"
14#include "clang/AST/ASTContext.h"
15#include "clang/AST/Attr.h"
16#include "clang/AST/Decl.h"
17#include "clang/AST/DeclOpenMP.h"
18#include "clang/Basic/LLVM.h"
19#include "clang/Basic/OpenMPKinds.h"
20#include "clang/Basic/TargetInfo.h"
21#include "llvm/ADT/SmallPtrSet.h"
22#include "llvm/Support/ErrorHandling.h"
23#include <algorithm>
24#include <cassert>
25#include <optional>
26
27using namespace clang;
28using namespace llvm;
29using namespace omp;
30
31OMPClause::child_range OMPClause::children() {
32 switch (getClauseKind()) {
33 default:
34 break;
35#define GEN_CLANG_CLAUSE_CLASS
36#define CLAUSE_CLASS(Enum, Str, Class) \
37 case Enum: \
38 return static_cast<Class *>(this)->children();
39#include "llvm/Frontend/OpenMP/OMP.inc"
40 }
41 llvm_unreachable("unknown OMPClause");
42}
43
44OMPClause::child_range OMPClause::used_children() {
45 switch (getClauseKind()) {
46#define GEN_CLANG_CLAUSE_CLASS
47#define CLAUSE_CLASS(Enum, Str, Class) \
48 case Enum: \
49 return static_cast<Class *>(this)->used_children();
50#define CLAUSE_NO_CLASS(Enum, Str) \
51 case Enum: \
52 break;
53#include "llvm/Frontend/OpenMP/OMP.inc"
54 }
55 llvm_unreachable("unknown OMPClause");
56}
57
58OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
59 auto *Res = OMPClauseWithPreInit::get(C: const_cast<const OMPClause *>(C));
60 return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr;
61}
62
63const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
64 switch (C->getClauseKind()) {
65 case OMPC_schedule:
66 return static_cast<const OMPScheduleClause *>(C);
67 case OMPC_dist_schedule:
68 return static_cast<const OMPDistScheduleClause *>(C);
69 case OMPC_firstprivate:
70 return static_cast<const OMPFirstprivateClause *>(C);
71 case OMPC_lastprivate:
72 return static_cast<const OMPLastprivateClause *>(C);
73 case OMPC_reduction:
74 return static_cast<const OMPReductionClause *>(C);
75 case OMPC_task_reduction:
76 return static_cast<const OMPTaskReductionClause *>(C);
77 case OMPC_in_reduction:
78 return static_cast<const OMPInReductionClause *>(C);
79 case OMPC_linear:
80 return static_cast<const OMPLinearClause *>(C);
81 case OMPC_if:
82 return static_cast<const OMPIfClause *>(C);
83 case OMPC_num_threads:
84 return static_cast<const OMPNumThreadsClause *>(C);
85 case OMPC_num_teams:
86 return static_cast<const OMPNumTeamsClause *>(C);
87 case OMPC_thread_limit:
88 return static_cast<const OMPThreadLimitClause *>(C);
89 case OMPC_device:
90 return static_cast<const OMPDeviceClause *>(C);
91 case OMPC_grainsize:
92 return static_cast<const OMPGrainsizeClause *>(C);
93 case OMPC_num_tasks:
94 return static_cast<const OMPNumTasksClause *>(C);
95 case OMPC_final:
96 return static_cast<const OMPFinalClause *>(C);
97 case OMPC_priority:
98 return static_cast<const OMPPriorityClause *>(C);
99 case OMPC_novariants:
100 return static_cast<const OMPNovariantsClause *>(C);
101 case OMPC_nocontext:
102 return static_cast<const OMPNocontextClause *>(C);
103 case OMPC_filter:
104 return static_cast<const OMPFilterClause *>(C);
105 case OMPC_ompx_dyn_cgroup_mem:
106 return static_cast<const OMPXDynCGroupMemClause *>(C);
107 case OMPC_default:
108 case OMPC_proc_bind:
109 case OMPC_safelen:
110 case OMPC_simdlen:
111 case OMPC_sizes:
112 case OMPC_allocator:
113 case OMPC_allocate:
114 case OMPC_collapse:
115 case OMPC_private:
116 case OMPC_shared:
117 case OMPC_aligned:
118 case OMPC_copyin:
119 case OMPC_copyprivate:
120 case OMPC_ordered:
121 case OMPC_nowait:
122 case OMPC_untied:
123 case OMPC_mergeable:
124 case OMPC_threadprivate:
125 case OMPC_flush:
126 case OMPC_depobj:
127 case OMPC_read:
128 case OMPC_write:
129 case OMPC_update:
130 case OMPC_capture:
131 case OMPC_compare:
132 case OMPC_fail:
133 case OMPC_seq_cst:
134 case OMPC_acq_rel:
135 case OMPC_acquire:
136 case OMPC_release:
137 case OMPC_relaxed:
138 case OMPC_depend:
139 case OMPC_threads:
140 case OMPC_simd:
141 case OMPC_map:
142 case OMPC_nogroup:
143 case OMPC_hint:
144 case OMPC_defaultmap:
145 case OMPC_unknown:
146 case OMPC_uniform:
147 case OMPC_to:
148 case OMPC_from:
149 case OMPC_use_device_ptr:
150 case OMPC_use_device_addr:
151 case OMPC_is_device_ptr:
152 case OMPC_has_device_addr:
153 case OMPC_unified_address:
154 case OMPC_unified_shared_memory:
155 case OMPC_reverse_offload:
156 case OMPC_dynamic_allocators:
157 case OMPC_atomic_default_mem_order:
158 case OMPC_self_maps:
159 case OMPC_at:
160 case OMPC_severity:
161 case OMPC_message:
162 case OMPC_device_type:
163 case OMPC_match:
164 case OMPC_nontemporal:
165 case OMPC_order:
166 case OMPC_destroy:
167 case OMPC_detach:
168 case OMPC_inclusive:
169 case OMPC_exclusive:
170 case OMPC_uses_allocators:
171 case OMPC_affinity:
172 case OMPC_when:
173 case OMPC_bind:
174 case OMPC_ompx_bare:
175 break;
176 default:
177 break;
178 }
179
180 return nullptr;
181}
182
183OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
184 auto *Res = OMPClauseWithPostUpdate::get(C: const_cast<const OMPClause *>(C));
185 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
186}
187
188const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
189 switch (C->getClauseKind()) {
190 case OMPC_lastprivate:
191 return static_cast<const OMPLastprivateClause *>(C);
192 case OMPC_reduction:
193 return static_cast<const OMPReductionClause *>(C);
194 case OMPC_task_reduction:
195 return static_cast<const OMPTaskReductionClause *>(C);
196 case OMPC_in_reduction:
197 return static_cast<const OMPInReductionClause *>(C);
198 case OMPC_linear:
199 return static_cast<const OMPLinearClause *>(C);
200 case OMPC_schedule:
201 case OMPC_dist_schedule:
202 case OMPC_firstprivate:
203 case OMPC_default:
204 case OMPC_proc_bind:
205 case OMPC_if:
206 case OMPC_final:
207 case OMPC_num_threads:
208 case OMPC_safelen:
209 case OMPC_simdlen:
210 case OMPC_sizes:
211 case OMPC_allocator:
212 case OMPC_allocate:
213 case OMPC_collapse:
214 case OMPC_private:
215 case OMPC_shared:
216 case OMPC_aligned:
217 case OMPC_copyin:
218 case OMPC_copyprivate:
219 case OMPC_ordered:
220 case OMPC_nowait:
221 case OMPC_untied:
222 case OMPC_mergeable:
223 case OMPC_threadprivate:
224 case OMPC_flush:
225 case OMPC_depobj:
226 case OMPC_read:
227 case OMPC_write:
228 case OMPC_update:
229 case OMPC_capture:
230 case OMPC_compare:
231 case OMPC_fail:
232 case OMPC_seq_cst:
233 case OMPC_acq_rel:
234 case OMPC_acquire:
235 case OMPC_release:
236 case OMPC_relaxed:
237 case OMPC_depend:
238 case OMPC_device:
239 case OMPC_threads:
240 case OMPC_simd:
241 case OMPC_map:
242 case OMPC_num_teams:
243 case OMPC_thread_limit:
244 case OMPC_priority:
245 case OMPC_grainsize:
246 case OMPC_nogroup:
247 case OMPC_num_tasks:
248 case OMPC_hint:
249 case OMPC_defaultmap:
250 case OMPC_unknown:
251 case OMPC_uniform:
252 case OMPC_to:
253 case OMPC_from:
254 case OMPC_use_device_ptr:
255 case OMPC_use_device_addr:
256 case OMPC_is_device_ptr:
257 case OMPC_has_device_addr:
258 case OMPC_unified_address:
259 case OMPC_unified_shared_memory:
260 case OMPC_reverse_offload:
261 case OMPC_dynamic_allocators:
262 case OMPC_atomic_default_mem_order:
263 case OMPC_self_maps:
264 case OMPC_at:
265 case OMPC_severity:
266 case OMPC_message:
267 case OMPC_device_type:
268 case OMPC_match:
269 case OMPC_nontemporal:
270 case OMPC_order:
271 case OMPC_destroy:
272 case OMPC_novariants:
273 case OMPC_nocontext:
274 case OMPC_detach:
275 case OMPC_inclusive:
276 case OMPC_exclusive:
277 case OMPC_uses_allocators:
278 case OMPC_affinity:
279 case OMPC_when:
280 case OMPC_bind:
281 break;
282 default:
283 break;
284 }
285
286 return nullptr;
287}
288
289/// Gets the address of the original, non-captured, expression used in the
290/// clause as the preinitializer.
291static Stmt **getAddrOfExprAsWritten(Stmt *S) {
292 if (!S)
293 return nullptr;
294 if (auto *DS = dyn_cast<DeclStmt>(Val: S)) {
295 assert(DS->isSingleDecl() && "Only single expression must be captured.");
296 if (auto *OED = dyn_cast<OMPCapturedExprDecl>(Val: DS->getSingleDecl()))
297 return OED->getInitAddress();
298 }
299 return nullptr;
300}
301
302OMPClause::child_range OMPIfClause::used_children() {
303 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
304 return child_range(C, C + 1);
305 return child_range(&Condition, &Condition + 1);
306}
307
308OMPClause::child_range OMPGrainsizeClause::used_children() {
309 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
310 return child_range(C, C + 1);
311 return child_range(&Grainsize, &Grainsize + 1);
312}
313
314OMPClause::child_range OMPNumTasksClause::used_children() {
315 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
316 return child_range(C, C + 1);
317 return child_range(&NumTasks, &NumTasks + 1);
318}
319
320OMPClause::child_range OMPFinalClause::used_children() {
321 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
322 return child_range(C, C + 1);
323 return children();
324}
325
326OMPClause::child_range OMPPriorityClause::used_children() {
327 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
328 return child_range(C, C + 1);
329 return child_range(&Priority, &Priority + 1);
330}
331
332OMPClause::child_range OMPNovariantsClause::used_children() {
333 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
334 return child_range(C, C + 1);
335 return children();
336}
337
338OMPClause::child_range OMPNocontextClause::used_children() {
339 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
340 return child_range(C, C + 1);
341 return children();
342}
343
344OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
345 unsigned NumLoops,
346 SourceLocation StartLoc,
347 SourceLocation LParenLoc,
348 SourceLocation EndLoc) {
349 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: 2 * NumLoops));
350 auto *Clause =
351 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
352 for (unsigned I = 0; I < NumLoops; ++I) {
353 Clause->setLoopNumIterations(NumLoop: I, NumIterations: nullptr);
354 Clause->setLoopCounter(NumLoop: I, Counter: nullptr);
355 }
356 return Clause;
357}
358
359OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
360 unsigned NumLoops) {
361 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: 2 * NumLoops));
362 auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
363 for (unsigned I = 0; I < NumLoops; ++I) {
364 Clause->setLoopNumIterations(NumLoop: I, NumIterations: nullptr);
365 Clause->setLoopCounter(NumLoop: I, Counter: nullptr);
366 }
367 return Clause;
368}
369
370void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
371 Expr *NumIterations) {
372 assert(NumLoop < NumberOfLoops && "out of loops number.");
373 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
374}
375
376ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
377 return getTrailingObjects<Expr *>(NumberOfLoops);
378}
379
380void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
381 assert(NumLoop < NumberOfLoops && "out of loops number.");
382 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
383}
384
385Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
386 assert(NumLoop < NumberOfLoops && "out of loops number.");
387 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
388}
389
390const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
391 assert(NumLoop < NumberOfLoops && "out of loops number.");
392 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
393}
394
395OMPUpdateClause *OMPUpdateClause::Create(const ASTContext &C,
396 SourceLocation StartLoc,
397 SourceLocation EndLoc) {
398 return new (C) OMPUpdateClause(StartLoc, EndLoc, /*IsExtended=*/false);
399}
400
401OMPUpdateClause *
402OMPUpdateClause::Create(const ASTContext &C, SourceLocation StartLoc,
403 SourceLocation LParenLoc, SourceLocation ArgumentLoc,
404 OpenMPDependClauseKind DK, SourceLocation EndLoc) {
405 void *Mem =
406 C.Allocate(Size: totalSizeToAlloc<SourceLocation, OpenMPDependClauseKind>(Counts: 2, Counts: 1),
407 Align: alignof(OMPUpdateClause));
408 auto *Clause =
409 new (Mem) OMPUpdateClause(StartLoc, EndLoc, /*IsExtended=*/true);
410 Clause->setLParenLoc(LParenLoc);
411 Clause->setArgumentLoc(ArgumentLoc);
412 Clause->setDependencyKind(DK);
413 return Clause;
414}
415
416OMPUpdateClause *OMPUpdateClause::CreateEmpty(const ASTContext &C,
417 bool IsExtended) {
418 if (!IsExtended)
419 return new (C) OMPUpdateClause(/*IsExtended=*/false);
420 void *Mem =
421 C.Allocate(Size: totalSizeToAlloc<SourceLocation, OpenMPDependClauseKind>(Counts: 2, Counts: 1),
422 Align: alignof(OMPUpdateClause));
423 auto *Clause = new (Mem) OMPUpdateClause(/*IsExtended=*/true);
424 Clause->IsExtended = true;
425 return Clause;
426}
427
428void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
429 assert(VL.size() == varlist_size() &&
430 "Number of private copies is not the same as the preallocated buffer");
431 std::copy(VL.begin(), VL.end(), varlist_end());
432}
433
434OMPPrivateClause *
435OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
436 SourceLocation LParenLoc, SourceLocation EndLoc,
437 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
438 // Allocate space for private variables and initializer expressions.
439 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: 2 * VL.size()));
440 OMPPrivateClause *Clause =
441 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
442 Clause->setVarRefs(VL);
443 Clause->setPrivateCopies(PrivateVL);
444 return Clause;
445}
446
447OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
448 unsigned N) {
449 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: 2 * N));
450 return new (Mem) OMPPrivateClause(N);
451}
452
453void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
454 assert(VL.size() == varlist_size() &&
455 "Number of private copies is not the same as the preallocated buffer");
456 std::copy(VL.begin(), VL.end(), varlist_end());
457}
458
459void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
460 assert(VL.size() == varlist_size() &&
461 "Number of inits is not the same as the preallocated buffer");
462 std::copy(first: VL.begin(), last: VL.end(), result: getPrivateCopies().end());
463}
464
465OMPFirstprivateClause *
466OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
467 SourceLocation LParenLoc, SourceLocation EndLoc,
468 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
469 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
470 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: 3 * VL.size()));
471 OMPFirstprivateClause *Clause =
472 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
473 Clause->setVarRefs(VL);
474 Clause->setPrivateCopies(PrivateVL);
475 Clause->setInits(InitVL);
476 Clause->setPreInitStmt(PreInit);
477 return Clause;
478}
479
480OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
481 unsigned N) {
482 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: 3 * N));
483 return new (Mem) OMPFirstprivateClause(N);
484}
485
486void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
487 assert(PrivateCopies.size() == varlist_size() &&
488 "Number of private copies is not the same as the preallocated buffer");
489 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
490}
491
492void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
493 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
494 "not the same as the "
495 "preallocated buffer");
496 std::copy(first: SrcExprs.begin(), last: SrcExprs.end(), result: getPrivateCopies().end());
497}
498
499void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
500 assert(DstExprs.size() == varlist_size() && "Number of destination "
501 "expressions is not the same as "
502 "the preallocated buffer");
503 std::copy(first: DstExprs.begin(), last: DstExprs.end(), result: getSourceExprs().end());
504}
505
506void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
507 assert(AssignmentOps.size() == varlist_size() &&
508 "Number of assignment expressions is not the same as the preallocated "
509 "buffer");
510 std::copy(first: AssignmentOps.begin(), last: AssignmentOps.end(),
511 result: getDestinationExprs().end());
512}
513
514OMPLastprivateClause *OMPLastprivateClause::Create(
515 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
516 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
517 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
518 OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
519 SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate) {
520 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: 5 * VL.size()));
521 OMPLastprivateClause *Clause = new (Mem) OMPLastprivateClause(
522 StartLoc, LParenLoc, EndLoc, LPKind, LPKindLoc, ColonLoc, VL.size());
523 Clause->setVarRefs(VL);
524 Clause->setSourceExprs(SrcExprs);
525 Clause->setDestinationExprs(DstExprs);
526 Clause->setAssignmentOps(AssignmentOps);
527 Clause->setPreInitStmt(PreInit);
528 Clause->setPostUpdateExpr(PostUpdate);
529 return Clause;
530}
531
532OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
533 unsigned N) {
534 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: 5 * N));
535 return new (Mem) OMPLastprivateClause(N);
536}
537
538OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
539 SourceLocation StartLoc,
540 SourceLocation LParenLoc,
541 SourceLocation EndLoc,
542 ArrayRef<Expr *> VL) {
543 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: VL.size()));
544 OMPSharedClause *Clause =
545 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
546 Clause->setVarRefs(VL);
547 return Clause;
548}
549
550OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
551 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: N));
552 return new (Mem) OMPSharedClause(N);
553}
554
555void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
556 assert(PL.size() == varlist_size() &&
557 "Number of privates is not the same as the preallocated buffer");
558 std::copy(PL.begin(), PL.end(), varlist_end());
559}
560
561void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
562 assert(IL.size() == varlist_size() &&
563 "Number of inits is not the same as the preallocated buffer");
564 std::copy(first: IL.begin(), last: IL.end(), result: getPrivates().end());
565}
566
567void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
568 assert(UL.size() == varlist_size() &&
569 "Number of updates is not the same as the preallocated buffer");
570 std::copy(first: UL.begin(), last: UL.end(), result: getInits().end());
571}
572
573void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
574 assert(FL.size() == varlist_size() &&
575 "Number of final updates is not the same as the preallocated buffer");
576 std::copy(first: FL.begin(), last: FL.end(), result: getUpdates().end());
577}
578
579void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) {
580 assert(
581 UE.size() == varlist_size() + 1 &&
582 "Number of used expressions is not the same as the preallocated buffer");
583 std::copy(first: UE.begin(), last: UE.end(), result: getFinals().end() + 2);
584}
585
586OMPLinearClause *OMPLinearClause::Create(
587 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
588 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
589 SourceLocation ColonLoc, SourceLocation StepModifierLoc,
590 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PL,
591 ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit,
592 Expr *PostUpdate) {
593 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
594 // (Step and CalcStep), list of used expression + step.
595 void *Mem =
596 C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: 5 * VL.size() + 2 + VL.size() + 1));
597 OMPLinearClause *Clause =
598 new (Mem) OMPLinearClause(StartLoc, LParenLoc, Modifier, ModifierLoc,
599 ColonLoc, StepModifierLoc, EndLoc, VL.size());
600 Clause->setVarRefs(VL);
601 Clause->setPrivates(PL);
602 Clause->setInits(IL);
603 // Fill update and final expressions with zeroes, they are provided later,
604 // after the directive construction.
605 std::fill(first: Clause->getInits().end(), last: Clause->getInits().end() + VL.size(),
606 value: nullptr);
607 std::fill(first: Clause->getUpdates().end(), last: Clause->getUpdates().end() + VL.size(),
608 value: nullptr);
609 std::fill(first: Clause->getUsedExprs().begin(), last: Clause->getUsedExprs().end(),
610 value: nullptr);
611 Clause->setStep(Step);
612 Clause->setCalcStep(CalcStep);
613 Clause->setPreInitStmt(PreInit);
614 Clause->setPostUpdateExpr(PostUpdate);
615 return Clause;
616}
617
618OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
619 unsigned NumVars) {
620 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
621 // (Step and CalcStep), list of used expression + step.
622 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: 5 * NumVars + 2 + NumVars +1));
623 return new (Mem) OMPLinearClause(NumVars);
624}
625
626OMPClause::child_range OMPLinearClause::used_children() {
627 // Range includes only non-nullptr elements.
628 return child_range(
629 reinterpret_cast<Stmt **>(getUsedExprs().begin()),
630 reinterpret_cast<Stmt **>(llvm::find(Range: getUsedExprs(), Val: nullptr)));
631}
632
633OMPAlignedClause *
634OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
635 SourceLocation LParenLoc, SourceLocation ColonLoc,
636 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
637 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: VL.size() + 1));
638 OMPAlignedClause *Clause = new (Mem)
639 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
640 Clause->setVarRefs(VL);
641 Clause->setAlignment(A);
642 return Clause;
643}
644
645OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
646 unsigned NumVars) {
647 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: NumVars + 1));
648 return new (Mem) OMPAlignedClause(NumVars);
649}
650
651OMPAlignClause *OMPAlignClause::Create(const ASTContext &C, Expr *A,
652 SourceLocation StartLoc,
653 SourceLocation LParenLoc,
654 SourceLocation EndLoc) {
655 return new (C) OMPAlignClause(A, StartLoc, LParenLoc, EndLoc);
656}
657
658void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
659 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
660 "not the same as the "
661 "preallocated buffer");
662 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
663}
664
665void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
666 assert(DstExprs.size() == varlist_size() && "Number of destination "
667 "expressions is not the same as "
668 "the preallocated buffer");
669 std::copy(first: DstExprs.begin(), last: DstExprs.end(), result: getSourceExprs().end());
670}
671
672void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
673 assert(AssignmentOps.size() == varlist_size() &&
674 "Number of assignment expressions is not the same as the preallocated "
675 "buffer");
676 std::copy(first: AssignmentOps.begin(), last: AssignmentOps.end(),
677 result: getDestinationExprs().end());
678}
679
680OMPCopyinClause *OMPCopyinClause::Create(
681 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
682 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
683 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
684 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: 4 * VL.size()));
685 OMPCopyinClause *Clause =
686 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
687 Clause->setVarRefs(VL);
688 Clause->setSourceExprs(SrcExprs);
689 Clause->setDestinationExprs(DstExprs);
690 Clause->setAssignmentOps(AssignmentOps);
691 return Clause;
692}
693
694OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
695 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: 4 * N));
696 return new (Mem) OMPCopyinClause(N);
697}
698
699void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
700 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
701 "not the same as the "
702 "preallocated buffer");
703 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
704}
705
706void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
707 assert(DstExprs.size() == varlist_size() && "Number of destination "
708 "expressions is not the same as "
709 "the preallocated buffer");
710 std::copy(first: DstExprs.begin(), last: DstExprs.end(), result: getSourceExprs().end());
711}
712
713void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
714 assert(AssignmentOps.size() == varlist_size() &&
715 "Number of assignment expressions is not the same as the preallocated "
716 "buffer");
717 std::copy(first: AssignmentOps.begin(), last: AssignmentOps.end(),
718 result: getDestinationExprs().end());
719}
720
721OMPCopyprivateClause *OMPCopyprivateClause::Create(
722 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
723 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
724 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
725 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: 4 * VL.size()));
726 OMPCopyprivateClause *Clause =
727 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
728 Clause->setVarRefs(VL);
729 Clause->setSourceExprs(SrcExprs);
730 Clause->setDestinationExprs(DstExprs);
731 Clause->setAssignmentOps(AssignmentOps);
732 return Clause;
733}
734
735OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
736 unsigned N) {
737 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: 4 * N));
738 return new (Mem) OMPCopyprivateClause(N);
739}
740
741void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
742 assert(Privates.size() == varlist_size() &&
743 "Number of private copies is not the same as the preallocated buffer");
744 std::copy(Privates.begin(), Privates.end(), varlist_end());
745}
746
747void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
748 assert(
749 LHSExprs.size() == varlist_size() &&
750 "Number of LHS expressions is not the same as the preallocated buffer");
751 std::copy(first: LHSExprs.begin(), last: LHSExprs.end(), result: getPrivates().end());
752}
753
754void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
755 assert(
756 RHSExprs.size() == varlist_size() &&
757 "Number of RHS expressions is not the same as the preallocated buffer");
758 std::copy(first: RHSExprs.begin(), last: RHSExprs.end(), result: getLHSExprs().end());
759}
760
761void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
762 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
763 "expressions is not the same "
764 "as the preallocated buffer");
765 std::copy(first: ReductionOps.begin(), last: ReductionOps.end(), result: getRHSExprs().end());
766}
767
768void OMPReductionClause::setInscanCopyOps(ArrayRef<Expr *> Ops) {
769 assert(Modifier == OMPC_REDUCTION_inscan && "Expected inscan reduction.");
770 assert(Ops.size() == varlist_size() && "Number of copy "
771 "expressions is not the same "
772 "as the preallocated buffer");
773 llvm::copy(Range&: Ops, Out: getReductionOps().end());
774}
775
776void OMPReductionClause::setInscanCopyArrayTemps(
777 ArrayRef<Expr *> CopyArrayTemps) {
778 assert(Modifier == OMPC_REDUCTION_inscan && "Expected inscan reduction.");
779 assert(CopyArrayTemps.size() == varlist_size() &&
780 "Number of copy temp expressions is not the same as the preallocated "
781 "buffer");
782 llvm::copy(Range&: CopyArrayTemps, Out: getInscanCopyOps().end());
783}
784
785void OMPReductionClause::setInscanCopyArrayElems(
786 ArrayRef<Expr *> CopyArrayElems) {
787 assert(Modifier == OMPC_REDUCTION_inscan && "Expected inscan reduction.");
788 assert(CopyArrayElems.size() == varlist_size() &&
789 "Number of copy temp expressions is not the same as the preallocated "
790 "buffer");
791 llvm::copy(Range&: CopyArrayElems, Out: getInscanCopyArrayTemps().end());
792}
793
794OMPReductionClause *OMPReductionClause::Create(
795 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
796 SourceLocation ModifierLoc, SourceLocation EndLoc, SourceLocation ColonLoc,
797 OpenMPReductionClauseModifier Modifier, ArrayRef<Expr *> VL,
798 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
799 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
800 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
801 ArrayRef<Expr *> CopyOps, ArrayRef<Expr *> CopyArrayTemps,
802 ArrayRef<Expr *> CopyArrayElems, Stmt *PreInit, Expr *PostUpdate,
803 ArrayRef<bool> IsPrivateVarReduction,
804 OpenMPOriginalSharingModifier OrignalSharingModifier) {
805 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *, bool>(
806 Counts: (Modifier == OMPC_REDUCTION_inscan ? 8 : 5) * VL.size(), Counts: VL.size()));
807 auto *Clause = new (Mem) OMPReductionClause(
808 StartLoc, LParenLoc, ModifierLoc, EndLoc, ColonLoc, Modifier,
809 OrignalSharingModifier, VL.size(), QualifierLoc, NameInfo);
810 Clause->setVarRefs(VL);
811 Clause->setPrivates(Privates);
812 Clause->setLHSExprs(LHSExprs);
813 Clause->setRHSExprs(RHSExprs);
814 Clause->setReductionOps(ReductionOps);
815 Clause->setPreInitStmt(PreInit);
816 Clause->setPostUpdateExpr(PostUpdate);
817 Clause->setPrivateVariableReductionFlags(IsPrivateVarReduction);
818 if (Modifier == OMPC_REDUCTION_inscan) {
819 Clause->setInscanCopyOps(CopyOps);
820 Clause->setInscanCopyArrayTemps(CopyArrayTemps);
821 Clause->setInscanCopyArrayElems(CopyArrayElems);
822 } else {
823 assert(CopyOps.empty() &&
824 "copy operations are expected in inscan reductions only.");
825 assert(CopyArrayTemps.empty() &&
826 "copy array temps are expected in inscan reductions only.");
827 assert(CopyArrayElems.empty() &&
828 "copy array temps are expected in inscan reductions only.");
829 }
830 return Clause;
831}
832
833OMPReductionClause *
834OMPReductionClause::CreateEmpty(const ASTContext &C, unsigned N,
835 OpenMPReductionClauseModifier Modifier) {
836 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *, bool>(
837 Counts: (Modifier == OMPC_REDUCTION_inscan ? 8 : 5) * N, Counts: N));
838 auto *Clause = new (Mem) OMPReductionClause(N);
839 Clause->setModifier(Modifier);
840 return Clause;
841}
842
843void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
844 assert(Privates.size() == varlist_size() &&
845 "Number of private copies is not the same as the preallocated buffer");
846 std::copy(Privates.begin(), Privates.end(), varlist_end());
847}
848
849void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
850 assert(
851 LHSExprs.size() == varlist_size() &&
852 "Number of LHS expressions is not the same as the preallocated buffer");
853 std::copy(first: LHSExprs.begin(), last: LHSExprs.end(), result: getPrivates().end());
854}
855
856void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
857 assert(
858 RHSExprs.size() == varlist_size() &&
859 "Number of RHS expressions is not the same as the preallocated buffer");
860 std::copy(first: RHSExprs.begin(), last: RHSExprs.end(), result: getLHSExprs().end());
861}
862
863void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
864 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
865 "expressions is not the same "
866 "as the preallocated buffer");
867 std::copy(first: ReductionOps.begin(), last: ReductionOps.end(), result: getRHSExprs().end());
868}
869
870OMPTaskReductionClause *OMPTaskReductionClause::Create(
871 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
872 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
873 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
874 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
875 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
876 Expr *PostUpdate) {
877 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: 5 * VL.size()));
878 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
879 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
880 Clause->setVarRefs(VL);
881 Clause->setPrivates(Privates);
882 Clause->setLHSExprs(LHSExprs);
883 Clause->setRHSExprs(RHSExprs);
884 Clause->setReductionOps(ReductionOps);
885 Clause->setPreInitStmt(PreInit);
886 Clause->setPostUpdateExpr(PostUpdate);
887 return Clause;
888}
889
890OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
891 unsigned N) {
892 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: 5 * N));
893 return new (Mem) OMPTaskReductionClause(N);
894}
895
896void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
897 assert(Privates.size() == varlist_size() &&
898 "Number of private copies is not the same as the preallocated buffer");
899 std::copy(Privates.begin(), Privates.end(), varlist_end());
900}
901
902void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
903 assert(
904 LHSExprs.size() == varlist_size() &&
905 "Number of LHS expressions is not the same as the preallocated buffer");
906 std::copy(first: LHSExprs.begin(), last: LHSExprs.end(), result: getPrivates().end());
907}
908
909void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
910 assert(
911 RHSExprs.size() == varlist_size() &&
912 "Number of RHS expressions is not the same as the preallocated buffer");
913 std::copy(first: RHSExprs.begin(), last: RHSExprs.end(), result: getLHSExprs().end());
914}
915
916void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
917 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
918 "expressions is not the same "
919 "as the preallocated buffer");
920 std::copy(first: ReductionOps.begin(), last: ReductionOps.end(), result: getRHSExprs().end());
921}
922
923void OMPInReductionClause::setTaskgroupDescriptors(
924 ArrayRef<Expr *> TaskgroupDescriptors) {
925 assert(TaskgroupDescriptors.size() == varlist_size() &&
926 "Number of in reduction descriptors is not the same as the "
927 "preallocated buffer");
928 std::copy(first: TaskgroupDescriptors.begin(), last: TaskgroupDescriptors.end(),
929 result: getReductionOps().end());
930}
931
932OMPInReductionClause *OMPInReductionClause::Create(
933 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
934 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
935 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
936 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
937 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
938 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
939 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: 6 * VL.size()));
940 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
941 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
942 Clause->setVarRefs(VL);
943 Clause->setPrivates(Privates);
944 Clause->setLHSExprs(LHSExprs);
945 Clause->setRHSExprs(RHSExprs);
946 Clause->setReductionOps(ReductionOps);
947 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
948 Clause->setPreInitStmt(PreInit);
949 Clause->setPostUpdateExpr(PostUpdate);
950 return Clause;
951}
952
953OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
954 unsigned N) {
955 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: 6 * N));
956 return new (Mem) OMPInReductionClause(N);
957}
958
959OMPSizesClause *OMPSizesClause::Create(const ASTContext &C,
960 SourceLocation StartLoc,
961 SourceLocation LParenLoc,
962 SourceLocation EndLoc,
963 ArrayRef<Expr *> Sizes) {
964 OMPSizesClause *Clause = CreateEmpty(C, NumSizes: Sizes.size());
965 Clause->setLocStart(StartLoc);
966 Clause->setLParenLoc(LParenLoc);
967 Clause->setLocEnd(EndLoc);
968 Clause->setSizesRefs(Sizes);
969 return Clause;
970}
971
972OMPSizesClause *OMPSizesClause::CreateEmpty(const ASTContext &C,
973 unsigned NumSizes) {
974 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: NumSizes));
975 return new (Mem) OMPSizesClause(NumSizes);
976}
977
978OMPPermutationClause *OMPPermutationClause::Create(const ASTContext &C,
979 SourceLocation StartLoc,
980 SourceLocation LParenLoc,
981 SourceLocation EndLoc,
982 ArrayRef<Expr *> Args) {
983 OMPPermutationClause *Clause = CreateEmpty(C, NumLoops: Args.size());
984 Clause->setLocStart(StartLoc);
985 Clause->setLParenLoc(LParenLoc);
986 Clause->setLocEnd(EndLoc);
987 Clause->setArgRefs(Args);
988 return Clause;
989}
990
991OMPPermutationClause *OMPPermutationClause::CreateEmpty(const ASTContext &C,
992 unsigned NumLoops) {
993 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: NumLoops));
994 return new (Mem) OMPPermutationClause(NumLoops);
995}
996
997OMPFullClause *OMPFullClause::Create(const ASTContext &C,
998 SourceLocation StartLoc,
999 SourceLocation EndLoc) {
1000 OMPFullClause *Clause = CreateEmpty(C);
1001 Clause->setLocStart(StartLoc);
1002 Clause->setLocEnd(EndLoc);
1003 return Clause;
1004}
1005
1006OMPFullClause *OMPFullClause::CreateEmpty(const ASTContext &C) {
1007 return new (C) OMPFullClause();
1008}
1009
1010OMPPartialClause *OMPPartialClause::Create(const ASTContext &C,
1011 SourceLocation StartLoc,
1012 SourceLocation LParenLoc,
1013 SourceLocation EndLoc,
1014 Expr *Factor) {
1015 OMPPartialClause *Clause = CreateEmpty(C);
1016 Clause->setLocStart(StartLoc);
1017 Clause->setLParenLoc(LParenLoc);
1018 Clause->setLocEnd(EndLoc);
1019 Clause->setFactor(Factor);
1020 return Clause;
1021}
1022
1023OMPPartialClause *OMPPartialClause::CreateEmpty(const ASTContext &C) {
1024 return new (C) OMPPartialClause();
1025}
1026
1027OMPAllocateClause *OMPAllocateClause::Create(
1028 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1029 Expr *Allocator, Expr *Alignment, SourceLocation ColonLoc,
1030 OpenMPAllocateClauseModifier Modifier1, SourceLocation Modifier1Loc,
1031 OpenMPAllocateClauseModifier Modifier2, SourceLocation Modifier2Loc,
1032 SourceLocation EndLoc, ArrayRef<Expr *> VL) {
1033
1034 // Allocate space for private variables and initializer expressions.
1035 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: VL.size()));
1036 auto *Clause = new (Mem) OMPAllocateClause(
1037 StartLoc, LParenLoc, Allocator, Alignment, ColonLoc, Modifier1,
1038 Modifier1Loc, Modifier2, Modifier2Loc, EndLoc, VL.size());
1039
1040 Clause->setVarRefs(VL);
1041 return Clause;
1042}
1043
1044OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
1045 unsigned N) {
1046 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: N));
1047 return new (Mem) OMPAllocateClause(N);
1048}
1049
1050OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
1051 SourceLocation StartLoc,
1052 SourceLocation LParenLoc,
1053 SourceLocation EndLoc,
1054 ArrayRef<Expr *> VL) {
1055 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: VL.size() + 1));
1056 OMPFlushClause *Clause =
1057 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
1058 Clause->setVarRefs(VL);
1059 return Clause;
1060}
1061
1062OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
1063 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: N));
1064 return new (Mem) OMPFlushClause(N);
1065}
1066
1067OMPDepobjClause *OMPDepobjClause::Create(const ASTContext &C,
1068 SourceLocation StartLoc,
1069 SourceLocation LParenLoc,
1070 SourceLocation RParenLoc,
1071 Expr *Depobj) {
1072 auto *Clause = new (C) OMPDepobjClause(StartLoc, LParenLoc, RParenLoc);
1073 Clause->setDepobj(Depobj);
1074 return Clause;
1075}
1076
1077OMPDepobjClause *OMPDepobjClause::CreateEmpty(const ASTContext &C) {
1078 return new (C) OMPDepobjClause();
1079}
1080
1081OMPDependClause *
1082OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
1083 SourceLocation LParenLoc, SourceLocation EndLoc,
1084 DependDataTy Data, Expr *DepModifier,
1085 ArrayRef<Expr *> VL, unsigned NumLoops) {
1086 void *Mem = C.Allocate(
1087 Size: totalSizeToAlloc<Expr *>(Counts: VL.size() + /*depend-modifier*/ 1 + NumLoops),
1088 Align: alignof(OMPDependClause));
1089 OMPDependClause *Clause = new (Mem)
1090 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
1091 Clause->setDependencyKind(Data.DepKind);
1092 Clause->setDependencyLoc(Data.DepLoc);
1093 Clause->setColonLoc(Data.ColonLoc);
1094 Clause->setOmpAllMemoryLoc(Data.OmpAllMemoryLoc);
1095 Clause->setModifier(DepModifier);
1096 Clause->setVarRefs(VL);
1097 for (unsigned I = 0 ; I < NumLoops; ++I)
1098 Clause->setLoopData(NumLoop: I, Cnt: nullptr);
1099 return Clause;
1100}
1101
1102OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
1103 unsigned NumLoops) {
1104 void *Mem =
1105 C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: N + /*depend-modifier*/ 1 + NumLoops),
1106 Align: alignof(OMPDependClause));
1107 return new (Mem) OMPDependClause(N, NumLoops);
1108}
1109
1110void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
1111 assert((getDependencyKind() == OMPC_DEPEND_sink ||
1112 getDependencyKind() == OMPC_DEPEND_source) &&
1113 NumLoop < NumLoops &&
1114 "Expected sink or source depend + loop index must be less number of "
1115 "loops.");
1116 auto *It = std::next(getVarRefs().end(), NumLoop + 1);
1117 *It = Cnt;
1118}
1119
1120Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
1121 assert((getDependencyKind() == OMPC_DEPEND_sink ||
1122 getDependencyKind() == OMPC_DEPEND_source) &&
1123 NumLoop < NumLoops &&
1124 "Expected sink or source depend + loop index must be less number of "
1125 "loops.");
1126 auto *It = std::next(getVarRefs().end(), NumLoop + 1);
1127 return *It;
1128}
1129
1130const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
1131 assert((getDependencyKind() == OMPC_DEPEND_sink ||
1132 getDependencyKind() == OMPC_DEPEND_source) &&
1133 NumLoop < NumLoops &&
1134 "Expected sink or source depend + loop index must be less number of "
1135 "loops.");
1136 const auto *It = std::next(getVarRefs().end(), NumLoop + 1);
1137 return *It;
1138}
1139
1140void OMPDependClause::setModifier(Expr *DepModifier) {
1141 *getVarRefs().end() = DepModifier;
1142}
1143Expr *OMPDependClause::getModifier() { return *getVarRefs().end(); }
1144
1145unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
1146 MappableExprComponentListsRef ComponentLists) {
1147 unsigned TotalNum = 0u;
1148 for (auto &C : ComponentLists)
1149 TotalNum += C.size();
1150 return TotalNum;
1151}
1152
1153unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
1154 ArrayRef<const ValueDecl *> Declarations) {
1155 llvm::SmallPtrSet<const ValueDecl *, 8> UniqueDecls;
1156 for (const ValueDecl *D : Declarations) {
1157 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
1158 UniqueDecls.insert(Ptr: VD);
1159 }
1160 return UniqueDecls.size();
1161}
1162
1163OMPMapClause *OMPMapClause::Create(
1164 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1165 ArrayRef<ValueDecl *> Declarations,
1166 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1167 Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapModifiers,
1168 ArrayRef<SourceLocation> MapModifiersLoc,
1169 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
1170 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
1171 OMPMappableExprListSizeTy Sizes;
1172 Sizes.NumVars = Vars.size();
1173 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1174 Sizes.NumComponentLists = ComponentLists.size();
1175 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1176
1177 // We need to allocate:
1178 // 2 x NumVars x Expr* - we have an original list expression and an associated
1179 // user-defined mapper for each clause list entry.
1180 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1181 // with each component list.
1182 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1183 // number of lists for each unique declaration and the size of each component
1184 // list.
1185 // NumComponents x MappableComponent - the total of all the components in all
1186 // the lists.
1187 void *Mem = C.Allocate(
1188 Size: totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1189 OMPClauseMappableExprCommon::MappableComponent>(
1190 Counts: 2 * Sizes.NumVars + 1, Counts: Sizes.NumUniqueDeclarations,
1191 Counts: Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1192 Counts: Sizes.NumComponents));
1193 OMPMapClause *Clause = new (Mem)
1194 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
1195 Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
1196
1197 Clause->setVarRefs(Vars);
1198 Clause->setUDMapperRefs(UDMapperRefs);
1199 Clause->setIteratorModifier(IteratorModifier);
1200 Clause->setClauseInfo(Declarations, ComponentLists);
1201 Clause->setMapType(Type);
1202 Clause->setMapLoc(TypeLoc);
1203 return Clause;
1204}
1205
1206OMPMapClause *
1207OMPMapClause::CreateEmpty(const ASTContext &C,
1208 const OMPMappableExprListSizeTy &Sizes) {
1209 void *Mem = C.Allocate(
1210 Size: totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1211 OMPClauseMappableExprCommon::MappableComponent>(
1212 Counts: 2 * Sizes.NumVars + 1, Counts: Sizes.NumUniqueDeclarations,
1213 Counts: Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1214 Counts: Sizes.NumComponents));
1215 OMPMapClause *Clause = new (Mem) OMPMapClause(Sizes);
1216 Clause->setIteratorModifier(nullptr);
1217 return Clause;
1218}
1219
1220OMPToClause *OMPToClause::Create(
1221 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1222 ArrayRef<ValueDecl *> Declarations,
1223 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1224 ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
1225 ArrayRef<SourceLocation> MotionModifiersLoc,
1226 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
1227 OMPMappableExprListSizeTy Sizes;
1228 Sizes.NumVars = Vars.size();
1229 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1230 Sizes.NumComponentLists = ComponentLists.size();
1231 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1232
1233 // We need to allocate:
1234 // 2 x NumVars x Expr* - we have an original list expression and an associated
1235 // user-defined mapper for each clause list entry.
1236 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1237 // with each component list.
1238 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1239 // number of lists for each unique declaration and the size of each component
1240 // list.
1241 // NumComponents x MappableComponent - the total of all the components in all
1242 // the lists.
1243 void *Mem = C.Allocate(
1244 Size: totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1245 OMPClauseMappableExprCommon::MappableComponent>(
1246 Counts: 2 * Sizes.NumVars, Counts: Sizes.NumUniqueDeclarations,
1247 Counts: Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1248 Counts: Sizes.NumComponents));
1249
1250 auto *Clause = new (Mem) OMPToClause(MotionModifiers, MotionModifiersLoc,
1251 UDMQualifierLoc, MapperId, Locs, Sizes);
1252
1253 Clause->setVarRefs(Vars);
1254 Clause->setUDMapperRefs(UDMapperRefs);
1255 Clause->setClauseInfo(Declarations, ComponentLists);
1256 return Clause;
1257}
1258
1259OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
1260 const OMPMappableExprListSizeTy &Sizes) {
1261 void *Mem = C.Allocate(
1262 Size: totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1263 OMPClauseMappableExprCommon::MappableComponent>(
1264 Counts: 2 * Sizes.NumVars, Counts: Sizes.NumUniqueDeclarations,
1265 Counts: Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1266 Counts: Sizes.NumComponents));
1267 return new (Mem) OMPToClause(Sizes);
1268}
1269
1270OMPFromClause *OMPFromClause::Create(
1271 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1272 ArrayRef<ValueDecl *> Declarations,
1273 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1274 ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
1275 ArrayRef<SourceLocation> MotionModifiersLoc,
1276 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
1277 OMPMappableExprListSizeTy Sizes;
1278 Sizes.NumVars = Vars.size();
1279 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1280 Sizes.NumComponentLists = ComponentLists.size();
1281 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1282
1283 // We need to allocate:
1284 // 2 x NumVars x Expr* - we have an original list expression and an associated
1285 // user-defined mapper for each clause list entry.
1286 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1287 // with each component list.
1288 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1289 // number of lists for each unique declaration and the size of each component
1290 // list.
1291 // NumComponents x MappableComponent - the total of all the components in all
1292 // the lists.
1293 void *Mem = C.Allocate(
1294 Size: totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1295 OMPClauseMappableExprCommon::MappableComponent>(
1296 Counts: 2 * Sizes.NumVars, Counts: Sizes.NumUniqueDeclarations,
1297 Counts: Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1298 Counts: Sizes.NumComponents));
1299
1300 auto *Clause =
1301 new (Mem) OMPFromClause(MotionModifiers, MotionModifiersLoc,
1302 UDMQualifierLoc, MapperId, Locs, Sizes);
1303
1304 Clause->setVarRefs(Vars);
1305 Clause->setUDMapperRefs(UDMapperRefs);
1306 Clause->setClauseInfo(Declarations, ComponentLists);
1307 return Clause;
1308}
1309
1310OMPFromClause *
1311OMPFromClause::CreateEmpty(const ASTContext &C,
1312 const OMPMappableExprListSizeTy &Sizes) {
1313 void *Mem = C.Allocate(
1314 Size: totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1315 OMPClauseMappableExprCommon::MappableComponent>(
1316 Counts: 2 * Sizes.NumVars, Counts: Sizes.NumUniqueDeclarations,
1317 Counts: Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1318 Counts: Sizes.NumComponents));
1319 return new (Mem) OMPFromClause(Sizes);
1320}
1321
1322void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1323 assert(VL.size() == varlist_size() &&
1324 "Number of private copies is not the same as the preallocated buffer");
1325 std::copy(VL.begin(), VL.end(), varlist_end());
1326}
1327
1328void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
1329 assert(VL.size() == varlist_size() &&
1330 "Number of inits is not the same as the preallocated buffer");
1331 std::copy(first: VL.begin(), last: VL.end(), result: getPrivateCopies().end());
1332}
1333
1334OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
1335 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1336 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
1337 ArrayRef<ValueDecl *> Declarations,
1338 MappableExprComponentListsRef ComponentLists) {
1339 OMPMappableExprListSizeTy Sizes;
1340 Sizes.NumVars = Vars.size();
1341 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1342 Sizes.NumComponentLists = ComponentLists.size();
1343 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1344
1345 // We need to allocate:
1346 // NumVars x Expr* - we have an original list expression for each clause
1347 // list entry.
1348 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1349 // with each component list.
1350 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1351 // number of lists for each unique declaration and the size of each component
1352 // list.
1353 // NumComponents x MappableComponent - the total of all the components in all
1354 // the lists.
1355 void *Mem = C.Allocate(
1356 Size: totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1357 OMPClauseMappableExprCommon::MappableComponent>(
1358 Counts: 3 * Sizes.NumVars, Counts: Sizes.NumUniqueDeclarations,
1359 Counts: Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1360 Counts: Sizes.NumComponents));
1361
1362 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
1363
1364 Clause->setVarRefs(Vars);
1365 Clause->setPrivateCopies(PrivateVars);
1366 Clause->setInits(Inits);
1367 Clause->setClauseInfo(Declarations, ComponentLists);
1368 return Clause;
1369}
1370
1371OMPUseDevicePtrClause *
1372OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
1373 const OMPMappableExprListSizeTy &Sizes) {
1374 void *Mem = C.Allocate(
1375 Size: totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1376 OMPClauseMappableExprCommon::MappableComponent>(
1377 Counts: 3 * Sizes.NumVars, Counts: Sizes.NumUniqueDeclarations,
1378 Counts: Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1379 Counts: Sizes.NumComponents));
1380 return new (Mem) OMPUseDevicePtrClause(Sizes);
1381}
1382
1383OMPUseDeviceAddrClause *
1384OMPUseDeviceAddrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
1385 ArrayRef<Expr *> Vars,
1386 ArrayRef<ValueDecl *> Declarations,
1387 MappableExprComponentListsRef ComponentLists) {
1388 OMPMappableExprListSizeTy Sizes;
1389 Sizes.NumVars = Vars.size();
1390 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1391 Sizes.NumComponentLists = ComponentLists.size();
1392 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1393
1394 // We need to allocate:
1395 // 3 x NumVars x Expr* - we have an original list expression for each clause
1396 // list entry and an equal number of private copies and inits.
1397 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1398 // with each component list.
1399 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1400 // number of lists for each unique declaration and the size of each component
1401 // list.
1402 // NumComponents x MappableComponent - the total of all the components in all
1403 // the lists.
1404 void *Mem = C.Allocate(
1405 Size: totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1406 OMPClauseMappableExprCommon::MappableComponent>(
1407 Counts: Sizes.NumVars, Counts: Sizes.NumUniqueDeclarations,
1408 Counts: Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1409 Counts: Sizes.NumComponents));
1410
1411 auto *Clause = new (Mem) OMPUseDeviceAddrClause(Locs, Sizes);
1412
1413 Clause->setVarRefs(Vars);
1414 Clause->setClauseInfo(Declarations, ComponentLists);
1415 return Clause;
1416}
1417
1418OMPUseDeviceAddrClause *
1419OMPUseDeviceAddrClause::CreateEmpty(const ASTContext &C,
1420 const OMPMappableExprListSizeTy &Sizes) {
1421 void *Mem = C.Allocate(
1422 Size: totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1423 OMPClauseMappableExprCommon::MappableComponent>(
1424 Counts: Sizes.NumVars, Counts: Sizes.NumUniqueDeclarations,
1425 Counts: Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1426 Counts: Sizes.NumComponents));
1427 return new (Mem) OMPUseDeviceAddrClause(Sizes);
1428}
1429
1430OMPIsDevicePtrClause *
1431OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
1432 ArrayRef<Expr *> Vars,
1433 ArrayRef<ValueDecl *> Declarations,
1434 MappableExprComponentListsRef ComponentLists) {
1435 OMPMappableExprListSizeTy Sizes;
1436 Sizes.NumVars = Vars.size();
1437 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1438 Sizes.NumComponentLists = ComponentLists.size();
1439 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1440
1441 // We need to allocate:
1442 // NumVars x Expr* - we have an original list expression for each clause list
1443 // entry.
1444 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1445 // with each component list.
1446 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1447 // number of lists for each unique declaration and the size of each component
1448 // list.
1449 // NumComponents x MappableComponent - the total of all the components in all
1450 // the lists.
1451 void *Mem = C.Allocate(
1452 Size: totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1453 OMPClauseMappableExprCommon::MappableComponent>(
1454 Counts: Sizes.NumVars, Counts: Sizes.NumUniqueDeclarations,
1455 Counts: Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1456 Counts: Sizes.NumComponents));
1457
1458 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
1459
1460 Clause->setVarRefs(Vars);
1461 Clause->setClauseInfo(Declarations, ComponentLists);
1462 return Clause;
1463}
1464
1465OMPIsDevicePtrClause *
1466OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1467 const OMPMappableExprListSizeTy &Sizes) {
1468 void *Mem = C.Allocate(
1469 Size: totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1470 OMPClauseMappableExprCommon::MappableComponent>(
1471 Counts: Sizes.NumVars, Counts: Sizes.NumUniqueDeclarations,
1472 Counts: Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1473 Counts: Sizes.NumComponents));
1474 return new (Mem) OMPIsDevicePtrClause(Sizes);
1475}
1476
1477OMPHasDeviceAddrClause *
1478OMPHasDeviceAddrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
1479 ArrayRef<Expr *> Vars,
1480 ArrayRef<ValueDecl *> Declarations,
1481 MappableExprComponentListsRef ComponentLists) {
1482 OMPMappableExprListSizeTy Sizes;
1483 Sizes.NumVars = Vars.size();
1484 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1485 Sizes.NumComponentLists = ComponentLists.size();
1486 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1487
1488 // We need to allocate:
1489 // NumVars x Expr* - we have an original list expression for each clause list
1490 // entry.
1491 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1492 // with each component list.
1493 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1494 // number of lists for each unique declaration and the size of each component
1495 // list.
1496 // NumComponents x MappableComponent - the total of all the components in all
1497 // the lists.
1498 void *Mem = C.Allocate(
1499 Size: totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1500 OMPClauseMappableExprCommon::MappableComponent>(
1501 Counts: Sizes.NumVars, Counts: Sizes.NumUniqueDeclarations,
1502 Counts: Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1503 Counts: Sizes.NumComponents));
1504
1505 auto *Clause = new (Mem) OMPHasDeviceAddrClause(Locs, Sizes);
1506
1507 Clause->setVarRefs(Vars);
1508 Clause->setClauseInfo(Declarations, ComponentLists);
1509 return Clause;
1510}
1511
1512OMPHasDeviceAddrClause *
1513OMPHasDeviceAddrClause::CreateEmpty(const ASTContext &C,
1514 const OMPMappableExprListSizeTy &Sizes) {
1515 void *Mem = C.Allocate(
1516 Size: totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1517 OMPClauseMappableExprCommon::MappableComponent>(
1518 Counts: Sizes.NumVars, Counts: Sizes.NumUniqueDeclarations,
1519 Counts: Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1520 Counts: Sizes.NumComponents));
1521 return new (Mem) OMPHasDeviceAddrClause(Sizes);
1522}
1523
1524OMPNontemporalClause *OMPNontemporalClause::Create(const ASTContext &C,
1525 SourceLocation StartLoc,
1526 SourceLocation LParenLoc,
1527 SourceLocation EndLoc,
1528 ArrayRef<Expr *> VL) {
1529 // Allocate space for nontemporal variables + private references.
1530 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: 2 * VL.size()));
1531 auto *Clause =
1532 new (Mem) OMPNontemporalClause(StartLoc, LParenLoc, EndLoc, VL.size());
1533 Clause->setVarRefs(VL);
1534 return Clause;
1535}
1536
1537OMPNontemporalClause *OMPNontemporalClause::CreateEmpty(const ASTContext &C,
1538 unsigned N) {
1539 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: 2 * N));
1540 return new (Mem) OMPNontemporalClause(N);
1541}
1542
1543void OMPNontemporalClause::setPrivateRefs(ArrayRef<Expr *> VL) {
1544 assert(VL.size() == varlist_size() && "Number of private references is not "
1545 "the same as the preallocated buffer");
1546 std::copy(VL.begin(), VL.end(), varlist_end());
1547}
1548
1549OMPInclusiveClause *OMPInclusiveClause::Create(const ASTContext &C,
1550 SourceLocation StartLoc,
1551 SourceLocation LParenLoc,
1552 SourceLocation EndLoc,
1553 ArrayRef<Expr *> VL) {
1554 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: VL.size()));
1555 auto *Clause =
1556 new (Mem) OMPInclusiveClause(StartLoc, LParenLoc, EndLoc, VL.size());
1557 Clause->setVarRefs(VL);
1558 return Clause;
1559}
1560
1561OMPInclusiveClause *OMPInclusiveClause::CreateEmpty(const ASTContext &C,
1562 unsigned N) {
1563 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: N));
1564 return new (Mem) OMPInclusiveClause(N);
1565}
1566
1567OMPExclusiveClause *OMPExclusiveClause::Create(const ASTContext &C,
1568 SourceLocation StartLoc,
1569 SourceLocation LParenLoc,
1570 SourceLocation EndLoc,
1571 ArrayRef<Expr *> VL) {
1572 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: VL.size()));
1573 auto *Clause =
1574 new (Mem) OMPExclusiveClause(StartLoc, LParenLoc, EndLoc, VL.size());
1575 Clause->setVarRefs(VL);
1576 return Clause;
1577}
1578
1579OMPExclusiveClause *OMPExclusiveClause::CreateEmpty(const ASTContext &C,
1580 unsigned N) {
1581 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: N));
1582 return new (Mem) OMPExclusiveClause(N);
1583}
1584
1585void OMPUsesAllocatorsClause::setAllocatorsData(
1586 ArrayRef<OMPUsesAllocatorsClause::Data> Data) {
1587 assert(Data.size() == NumOfAllocators &&
1588 "Size of allocators data is not the same as the preallocated buffer.");
1589 for (unsigned I = 0, E = Data.size(); I < E; ++I) {
1590 const OMPUsesAllocatorsClause::Data &D = Data[I];
1591 getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) +
1592 static_cast<int>(ExprOffsets::Allocator)] =
1593 D.Allocator;
1594 getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) +
1595 static_cast<int>(
1596 ExprOffsets::AllocatorTraits)] =
1597 D.AllocatorTraits;
1598 getTrailingObjects<
1599 SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) +
1600 static_cast<int>(ParenLocsOffsets::LParen)] =
1601 D.LParenLoc;
1602 getTrailingObjects<
1603 SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) +
1604 static_cast<int>(ParenLocsOffsets::RParen)] =
1605 D.RParenLoc;
1606 }
1607}
1608
1609OMPUsesAllocatorsClause::Data
1610OMPUsesAllocatorsClause::getAllocatorData(unsigned I) const {
1611 OMPUsesAllocatorsClause::Data Data;
1612 Data.Allocator =
1613 getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) +
1614 static_cast<int>(ExprOffsets::Allocator)];
1615 Data.AllocatorTraits =
1616 getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) +
1617 static_cast<int>(
1618 ExprOffsets::AllocatorTraits)];
1619 Data.LParenLoc = getTrailingObjects<
1620 SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) +
1621 static_cast<int>(ParenLocsOffsets::LParen)];
1622 Data.RParenLoc = getTrailingObjects<
1623 SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) +
1624 static_cast<int>(ParenLocsOffsets::RParen)];
1625 return Data;
1626}
1627
1628OMPUsesAllocatorsClause *
1629OMPUsesAllocatorsClause::Create(const ASTContext &C, SourceLocation StartLoc,
1630 SourceLocation LParenLoc, SourceLocation EndLoc,
1631 ArrayRef<OMPUsesAllocatorsClause::Data> Data) {
1632 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *, SourceLocation>(
1633 Counts: static_cast<int>(ExprOffsets::Total) * Data.size(),
1634 Counts: static_cast<int>(ParenLocsOffsets::Total) * Data.size()));
1635 auto *Clause = new (Mem)
1636 OMPUsesAllocatorsClause(StartLoc, LParenLoc, EndLoc, Data.size());
1637 Clause->setAllocatorsData(Data);
1638 return Clause;
1639}
1640
1641OMPUsesAllocatorsClause *
1642OMPUsesAllocatorsClause::CreateEmpty(const ASTContext &C, unsigned N) {
1643 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *, SourceLocation>(
1644 Counts: static_cast<int>(ExprOffsets::Total) * N,
1645 Counts: static_cast<int>(ParenLocsOffsets::Total) * N));
1646 return new (Mem) OMPUsesAllocatorsClause(N);
1647}
1648
1649OMPAffinityClause *
1650OMPAffinityClause::Create(const ASTContext &C, SourceLocation StartLoc,
1651 SourceLocation LParenLoc, SourceLocation ColonLoc,
1652 SourceLocation EndLoc, Expr *Modifier,
1653 ArrayRef<Expr *> Locators) {
1654 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: Locators.size() + 1));
1655 auto *Clause = new (Mem)
1656 OMPAffinityClause(StartLoc, LParenLoc, ColonLoc, EndLoc, Locators.size());
1657 Clause->setModifier(Modifier);
1658 Clause->setVarRefs(Locators);
1659 return Clause;
1660}
1661
1662OMPAffinityClause *OMPAffinityClause::CreateEmpty(const ASTContext &C,
1663 unsigned N) {
1664 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: N + 1));
1665 return new (Mem) OMPAffinityClause(N);
1666}
1667
1668OMPInitClause *OMPInitClause::Create(const ASTContext &C, Expr *InteropVar,
1669 OMPInteropInfo &InteropInfo,
1670 SourceLocation StartLoc,
1671 SourceLocation LParenLoc,
1672 SourceLocation VarLoc,
1673 SourceLocation EndLoc) {
1674
1675 void *Mem =
1676 C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: InteropInfo.PreferTypes.size() + 1));
1677 auto *Clause = new (Mem) OMPInitClause(
1678 InteropInfo.IsTarget, InteropInfo.IsTargetSync, StartLoc, LParenLoc,
1679 VarLoc, EndLoc, InteropInfo.PreferTypes.size() + 1);
1680 Clause->setInteropVar(InteropVar);
1681 llvm::copy(InteropInfo.PreferTypes, Clause->getTrailingObjects<Expr *>() + 1);
1682 return Clause;
1683}
1684
1685OMPInitClause *OMPInitClause::CreateEmpty(const ASTContext &C, unsigned N) {
1686 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: N));
1687 return new (Mem) OMPInitClause(N);
1688}
1689
1690OMPBindClause *
1691OMPBindClause::Create(const ASTContext &C, OpenMPBindClauseKind K,
1692 SourceLocation KLoc, SourceLocation StartLoc,
1693 SourceLocation LParenLoc, SourceLocation EndLoc) {
1694 return new (C) OMPBindClause(K, KLoc, StartLoc, LParenLoc, EndLoc);
1695}
1696
1697OMPBindClause *OMPBindClause::CreateEmpty(const ASTContext &C) {
1698 return new (C) OMPBindClause();
1699}
1700
1701OMPDoacrossClause *
1702OMPDoacrossClause::Create(const ASTContext &C, SourceLocation StartLoc,
1703 SourceLocation LParenLoc, SourceLocation EndLoc,
1704 OpenMPDoacrossClauseModifier DepType,
1705 SourceLocation DepLoc, SourceLocation ColonLoc,
1706 ArrayRef<Expr *> VL, unsigned NumLoops) {
1707 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops),
1708 alignof(OMPDoacrossClause));
1709 OMPDoacrossClause *Clause = new (Mem)
1710 OMPDoacrossClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
1711 Clause->setDependenceType(DepType);
1712 Clause->setDependenceLoc(DepLoc);
1713 Clause->setColonLoc(ColonLoc);
1714 Clause->setVarRefs(VL);
1715 for (unsigned I = 0; I < NumLoops; ++I)
1716 Clause->setLoopData(NumLoop: I, Cnt: nullptr);
1717 return Clause;
1718}
1719
1720OMPDoacrossClause *OMPDoacrossClause::CreateEmpty(const ASTContext &C,
1721 unsigned N,
1722 unsigned NumLoops) {
1723 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops),
1724 alignof(OMPDoacrossClause));
1725 return new (Mem) OMPDoacrossClause(N, NumLoops);
1726}
1727
1728void OMPDoacrossClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
1729 assert(NumLoop < NumLoops && "Loop index must be less number of loops.");
1730 auto *It = std::next(getVarRefs().end(), NumLoop);
1731 *It = Cnt;
1732}
1733
1734Expr *OMPDoacrossClause::getLoopData(unsigned NumLoop) {
1735 assert(NumLoop < NumLoops && "Loop index must be less number of loops.");
1736 auto *It = std::next(getVarRefs().end(), NumLoop);
1737 return *It;
1738}
1739
1740const Expr *OMPDoacrossClause::getLoopData(unsigned NumLoop) const {
1741 assert(NumLoop < NumLoops && "Loop index must be less number of loops.");
1742 const auto *It = std::next(getVarRefs().end(), NumLoop);
1743 return *It;
1744}
1745
1746OMPAbsentClause *OMPAbsentClause::Create(const ASTContext &C,
1747 ArrayRef<OpenMPDirectiveKind> DKVec,
1748 SourceLocation Loc,
1749 SourceLocation LLoc,
1750 SourceLocation RLoc) {
1751 void *Mem = C.Allocate(totalSizeToAlloc<OpenMPDirectiveKind>(DKVec.size()),
1752 alignof(OMPAbsentClause));
1753 auto *AC = new (Mem) OMPAbsentClause(Loc, LLoc, RLoc, DKVec.size());
1754 AC->setDirectiveKinds(DKVec);
1755 return AC;
1756}
1757
1758OMPAbsentClause *OMPAbsentClause::CreateEmpty(const ASTContext &C, unsigned K) {
1759 void *Mem = C.Allocate(totalSizeToAlloc<OpenMPDirectiveKind>(K),
1760 alignof(OMPAbsentClause));
1761 return new (Mem) OMPAbsentClause(K);
1762}
1763
1764OMPContainsClause *OMPContainsClause::Create(
1765 const ASTContext &C, ArrayRef<OpenMPDirectiveKind> DKVec,
1766 SourceLocation Loc, SourceLocation LLoc, SourceLocation RLoc) {
1767 void *Mem = C.Allocate(totalSizeToAlloc<OpenMPDirectiveKind>(DKVec.size()),
1768 alignof(OMPContainsClause));
1769 auto *CC = new (Mem) OMPContainsClause(Loc, LLoc, RLoc, DKVec.size());
1770 CC->setDirectiveKinds(DKVec);
1771 return CC;
1772}
1773
1774OMPContainsClause *OMPContainsClause::CreateEmpty(const ASTContext &C,
1775 unsigned K) {
1776 void *Mem = C.Allocate(totalSizeToAlloc<OpenMPDirectiveKind>(K),
1777 alignof(OMPContainsClause));
1778 return new (Mem) OMPContainsClause(K);
1779}
1780
1781OMPNumTeamsClause *OMPNumTeamsClause::Create(
1782 const ASTContext &C, OpenMPDirectiveKind CaptureRegion,
1783 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc,
1784 ArrayRef<Expr *> VL, Stmt *PreInit) {
1785 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: VL.size()));
1786 OMPNumTeamsClause *Clause =
1787 new (Mem) OMPNumTeamsClause(C, StartLoc, LParenLoc, EndLoc, VL.size());
1788 Clause->setVarRefs(VL);
1789 Clause->setPreInitStmt(PreInit, CaptureRegion);
1790 return Clause;
1791}
1792
1793OMPNumTeamsClause *OMPNumTeamsClause::CreateEmpty(const ASTContext &C,
1794 unsigned N) {
1795 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: N));
1796 return new (Mem) OMPNumTeamsClause(N);
1797}
1798
1799OMPThreadLimitClause *OMPThreadLimitClause::Create(
1800 const ASTContext &C, OpenMPDirectiveKind CaptureRegion,
1801 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc,
1802 ArrayRef<Expr *> VL, Stmt *PreInit) {
1803 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: VL.size()));
1804 OMPThreadLimitClause *Clause =
1805 new (Mem) OMPThreadLimitClause(C, StartLoc, LParenLoc, EndLoc, VL.size());
1806 Clause->setVarRefs(VL);
1807 Clause->setPreInitStmt(PreInit, CaptureRegion);
1808 return Clause;
1809}
1810
1811OMPThreadLimitClause *OMPThreadLimitClause::CreateEmpty(const ASTContext &C,
1812 unsigned N) {
1813 void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: N));
1814 return new (Mem) OMPThreadLimitClause(N);
1815}
1816
1817//===----------------------------------------------------------------------===//
1818// OpenMP clauses printing methods
1819//===----------------------------------------------------------------------===//
1820
1821void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1822 OS << "if(";
1823 if (Node->getNameModifier() != OMPD_unknown)
1824 OS << getOpenMPDirectiveName(Node->getNameModifier(), Version) << ": ";
1825 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1826 OS << ")";
1827}
1828
1829void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1830 OS << "final(";
1831 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1832 OS << ")";
1833}
1834
1835void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1836 OS << "num_threads(";
1837 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1838 OS << ")";
1839}
1840
1841void OMPClausePrinter::VisitOMPAlignClause(OMPAlignClause *Node) {
1842 OS << "align(";
1843 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1844 OS << ")";
1845}
1846
1847void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1848 OS << "safelen(";
1849 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1850 OS << ")";
1851}
1852
1853void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1854 OS << "simdlen(";
1855 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1856 OS << ")";
1857}
1858
1859void OMPClausePrinter::VisitOMPSizesClause(OMPSizesClause *Node) {
1860 OS << "sizes(";
1861 bool First = true;
1862 for (auto *Size : Node->getSizesRefs()) {
1863 if (!First)
1864 OS << ", ";
1865 Size->printPretty(OS, nullptr, Policy, 0);
1866 First = false;
1867 }
1868 OS << ")";
1869}
1870
1871void OMPClausePrinter::VisitOMPPermutationClause(OMPPermutationClause *Node) {
1872 OS << "permutation(";
1873 llvm::interleaveComma(c: Node->getArgsRefs(), os&: OS, each_fn: [&](const Expr *E) {
1874 E->printPretty(OS, nullptr, Policy, 0);
1875 });
1876 OS << ")";
1877}
1878
1879void OMPClausePrinter::VisitOMPFullClause(OMPFullClause *Node) { OS << "full"; }
1880
1881void OMPClausePrinter::VisitOMPPartialClause(OMPPartialClause *Node) {
1882 OS << "partial";
1883
1884 if (Expr *Factor = Node->getFactor()) {
1885 OS << '(';
1886 Factor->printPretty(OS, nullptr, Policy, 0);
1887 OS << ')';
1888 }
1889}
1890
1891void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
1892 OS << "allocator(";
1893 Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
1894 OS << ")";
1895}
1896
1897void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1898 OS << "collapse(";
1899 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1900 OS << ")";
1901}
1902
1903void OMPClausePrinter::VisitOMPDetachClause(OMPDetachClause *Node) {
1904 OS << "detach(";
1905 Node->getEventHandler()->printPretty(OS, nullptr, Policy, 0);
1906 OS << ")";
1907}
1908
1909void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1910 OS << "default("
1911 << getOpenMPSimpleClauseTypeName(OMPC_default,
1912 unsigned(Node->getDefaultKind()))
1913 << ")";
1914}
1915
1916void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1917 OS << "proc_bind("
1918 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind,
1919 unsigned(Node->getProcBindKind()))
1920 << ")";
1921}
1922
1923void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1924 OS << "unified_address";
1925}
1926
1927void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1928 OMPUnifiedSharedMemoryClause *) {
1929 OS << "unified_shared_memory";
1930}
1931
1932void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1933 OS << "reverse_offload";
1934}
1935
1936void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1937 OMPDynamicAllocatorsClause *) {
1938 OS << "dynamic_allocators";
1939}
1940
1941void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1942 OMPAtomicDefaultMemOrderClause *Node) {
1943 OS << "atomic_default_mem_order("
1944 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1945 Node->getAtomicDefaultMemOrderKind())
1946 << ")";
1947}
1948
1949void OMPClausePrinter::VisitOMPSelfMapsClause(OMPSelfMapsClause *) {
1950 OS << "self_maps";
1951}
1952
1953void OMPClausePrinter::VisitOMPAtClause(OMPAtClause *Node) {
1954 OS << "at(" << getOpenMPSimpleClauseTypeName(OMPC_at, Node->getAtKind())
1955 << ")";
1956}
1957
1958void OMPClausePrinter::VisitOMPSeverityClause(OMPSeverityClause *Node) {
1959 OS << "severity("
1960 << getOpenMPSimpleClauseTypeName(OMPC_severity, Node->getSeverityKind())
1961 << ")";
1962}
1963
1964void OMPClausePrinter::VisitOMPMessageClause(OMPMessageClause *Node) {
1965 OS << "message(\""
1966 << cast<StringLiteral>(Val: Node->getMessageString())->getString() << "\")";
1967}
1968
1969void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1970 OS << "schedule(";
1971 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1972 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1973 Node->getFirstScheduleModifier());
1974 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1975 OS << ", ";
1976 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1977 Node->getSecondScheduleModifier());
1978 }
1979 OS << ": ";
1980 }
1981 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1982 if (auto *E = Node->getChunkSize()) {
1983 OS << ", ";
1984 E->printPretty(OS, nullptr, Policy);
1985 }
1986 OS << ")";
1987}
1988
1989void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1990 OS << "ordered";
1991 if (auto *Num = Node->getNumForLoops()) {
1992 OS << "(";
1993 Num->printPretty(OS, nullptr, Policy, 0);
1994 OS << ")";
1995 }
1996}
1997
1998void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1999 OS << "nowait";
2000}
2001
2002void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
2003 OS << "untied";
2004}
2005
2006void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
2007 OS << "nogroup";
2008}
2009
2010void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
2011 OS << "mergeable";
2012}
2013
2014void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
2015
2016void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
2017
2018void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *Node) {
2019 OS << "update";
2020 if (Node->isExtended()) {
2021 OS << "(";
2022 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
2023 Node->getDependencyKind());
2024 OS << ")";
2025 }
2026}
2027
2028void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
2029 OS << "capture";
2030}
2031
2032void OMPClausePrinter::VisitOMPCompareClause(OMPCompareClause *) {
2033 OS << "compare";
2034}
2035
2036void OMPClausePrinter::VisitOMPFailClause(OMPFailClause *Node) {
2037 OS << "fail";
2038 if (Node) {
2039 OS << "(";
2040 OS << getOpenMPSimpleClauseTypeName(
2041 Node->getClauseKind(), static_cast<int>(Node->getFailParameter()));
2042 OS << ")";
2043 }
2044}
2045
2046void OMPClausePrinter::VisitOMPAbsentClause(OMPAbsentClause *Node) {
2047 OS << "absent(";
2048 bool First = true;
2049 for (auto &D : Node->getDirectiveKinds()) {
2050 if (!First)
2051 OS << ", ";
2052 OS << getOpenMPDirectiveName(D, Version);
2053 First = false;
2054 }
2055 OS << ")";
2056}
2057
2058void OMPClausePrinter::VisitOMPHoldsClause(OMPHoldsClause *Node) {
2059 OS << "holds(";
2060 Node->getExpr()->printPretty(OS, nullptr, Policy, 0);
2061 OS << ")";
2062}
2063
2064void OMPClausePrinter::VisitOMPContainsClause(OMPContainsClause *Node) {
2065 OS << "contains(";
2066 bool First = true;
2067 for (auto &D : Node->getDirectiveKinds()) {
2068 if (!First)
2069 OS << ", ";
2070 OS << getOpenMPDirectiveName(D, Version);
2071 First = false;
2072 }
2073 OS << ")";
2074}
2075
2076void OMPClausePrinter::VisitOMPNoOpenMPClause(OMPNoOpenMPClause *) {
2077 OS << "no_openmp";
2078}
2079
2080void OMPClausePrinter::VisitOMPNoOpenMPRoutinesClause(
2081 OMPNoOpenMPRoutinesClause *) {
2082 OS << "no_openmp_routines";
2083}
2084
2085void OMPClausePrinter::VisitOMPNoOpenMPConstructsClause(
2086 OMPNoOpenMPConstructsClause *) {
2087 OS << "no_openmp_constructs";
2088}
2089
2090void OMPClausePrinter::VisitOMPNoParallelismClause(OMPNoParallelismClause *) {
2091 OS << "no_parallelism";
2092}
2093
2094void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
2095 OS << "seq_cst";
2096}
2097
2098void OMPClausePrinter::VisitOMPAcqRelClause(OMPAcqRelClause *) {
2099 OS << "acq_rel";
2100}
2101
2102void OMPClausePrinter::VisitOMPAcquireClause(OMPAcquireClause *) {
2103 OS << "acquire";
2104}
2105
2106void OMPClausePrinter::VisitOMPReleaseClause(OMPReleaseClause *) {
2107 OS << "release";
2108}
2109
2110void OMPClausePrinter::VisitOMPRelaxedClause(OMPRelaxedClause *) {
2111 OS << "relaxed";
2112}
2113
2114void OMPClausePrinter::VisitOMPWeakClause(OMPWeakClause *) { OS << "weak"; }
2115
2116void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
2117 OS << "threads";
2118}
2119
2120void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
2121
2122void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
2123 OS << "device(";
2124 OpenMPDeviceClauseModifier Modifier = Node->getModifier();
2125 if (Modifier != OMPC_DEVICE_unknown) {
2126 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), Modifier)
2127 << ": ";
2128 }
2129 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
2130 OS << ")";
2131}
2132
2133void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
2134 if (!Node->varlist_empty()) {
2135 OS << "num_teams";
2136 VisitOMPClauseList(Node, StartSym: '(');
2137 OS << ")";
2138 }
2139}
2140
2141void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
2142 if (!Node->varlist_empty()) {
2143 OS << "thread_limit";
2144 VisitOMPClauseList(Node, StartSym: '(');
2145 OS << ")";
2146 }
2147}
2148
2149void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
2150 OS << "priority(";
2151 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
2152 OS << ")";
2153}
2154
2155void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
2156 OS << "grainsize(";
2157 OpenMPGrainsizeClauseModifier Modifier = Node->getModifier();
2158 if (Modifier != OMPC_GRAINSIZE_unknown) {
2159 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), Modifier)
2160 << ": ";
2161 }
2162 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
2163 OS << ")";
2164}
2165
2166void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
2167 OS << "num_tasks(";
2168 OpenMPNumTasksClauseModifier Modifier = Node->getModifier();
2169 if (Modifier != OMPC_NUMTASKS_unknown) {
2170 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), Modifier)
2171 << ": ";
2172 }
2173 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
2174 OS << ")";
2175}
2176
2177void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
2178 OS << "hint(";
2179 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
2180 OS << ")";
2181}
2182
2183void OMPClausePrinter::VisitOMPInitClause(OMPInitClause *Node) {
2184 OS << "init(";
2185 bool First = true;
2186 for (const Expr *E : Node->prefs()) {
2187 if (First)
2188 OS << "prefer_type(";
2189 else
2190 OS << ",";
2191 E->printPretty(OS, nullptr, Policy);
2192 First = false;
2193 }
2194 if (!First)
2195 OS << "), ";
2196 if (Node->getIsTarget())
2197 OS << "target";
2198 if (Node->getIsTargetSync()) {
2199 if (Node->getIsTarget())
2200 OS << ", ";
2201 OS << "targetsync";
2202 }
2203 OS << " : ";
2204 Node->getInteropVar()->printPretty(OS, nullptr, Policy);
2205 OS << ")";
2206}
2207
2208void OMPClausePrinter::VisitOMPUseClause(OMPUseClause *Node) {
2209 OS << "use(";
2210 Node->getInteropVar()->printPretty(OS, nullptr, Policy);
2211 OS << ")";
2212}
2213
2214void OMPClausePrinter::VisitOMPDestroyClause(OMPDestroyClause *Node) {
2215 OS << "destroy";
2216 if (Expr *E = Node->getInteropVar()) {
2217 OS << "(";
2218 E->printPretty(OS, nullptr, Policy);
2219 OS << ")";
2220 }
2221}
2222
2223void OMPClausePrinter::VisitOMPNovariantsClause(OMPNovariantsClause *Node) {
2224 OS << "novariants";
2225 if (Expr *E = Node->getCondition()) {
2226 OS << "(";
2227 E->printPretty(OS, nullptr, Policy, 0);
2228 OS << ")";
2229 }
2230}
2231
2232void OMPClausePrinter::VisitOMPNocontextClause(OMPNocontextClause *Node) {
2233 OS << "nocontext";
2234 if (Expr *E = Node->getCondition()) {
2235 OS << "(";
2236 E->printPretty(OS, nullptr, Policy, 0);
2237 OS << ")";
2238 }
2239}
2240
2241template<typename T>
2242void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
2243 for (typename T::varlist_iterator I = Node->varlist_begin(),
2244 E = Node->varlist_end();
2245 I != E; ++I) {
2246 assert(*I && "Expected non-null Stmt");
2247 OS << (I == Node->varlist_begin() ? StartSym : ',');
2248 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
2249 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
2250 DRE->printPretty(OS, nullptr, Policy, 0);
2251 else
2252 DRE->getDecl()->printQualifiedName(OS);
2253 } else
2254 (*I)->printPretty(OS, nullptr, Policy, 0);
2255 }
2256}
2257
2258void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
2259 if (Node->varlist_empty())
2260 return;
2261
2262 Expr *FirstModifier = nullptr;
2263 Expr *SecondModifier = nullptr;
2264 auto FirstAllocMod = Node->getFirstAllocateModifier();
2265 auto SecondAllocMod = Node->getSecondAllocateModifier();
2266 bool FirstUnknown = FirstAllocMod == OMPC_ALLOCATE_unknown;
2267 bool SecondUnknown = SecondAllocMod == OMPC_ALLOCATE_unknown;
2268 if (FirstAllocMod == OMPC_ALLOCATE_allocator ||
2269 (FirstAllocMod == OMPC_ALLOCATE_unknown && Node->getAllocator())) {
2270 FirstModifier = Node->getAllocator();
2271 SecondModifier = Node->getAlignment();
2272 } else {
2273 FirstModifier = Node->getAlignment();
2274 SecondModifier = Node->getAllocator();
2275 }
2276
2277 OS << "allocate";
2278 // If we have any explicit modifiers.
2279 if (FirstModifier) {
2280 OS << "(";
2281 if (!FirstUnknown) {
2282 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), FirstAllocMod);
2283 OS << "(";
2284 }
2285 FirstModifier->printPretty(OS, nullptr, Policy, 0);
2286 if (!FirstUnknown)
2287 OS << ")";
2288 if (SecondModifier) {
2289 OS << ", ";
2290 if (!SecondUnknown) {
2291 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
2292 SecondAllocMod);
2293 OS << "(";
2294 }
2295 SecondModifier->printPretty(OS, nullptr, Policy, 0);
2296 if (!SecondUnknown)
2297 OS << ")";
2298 }
2299 OS << ":";
2300 VisitOMPClauseList(Node, StartSym: ' ');
2301 } else {
2302 // No modifiers. Just print the variable list.
2303 VisitOMPClauseList(Node, StartSym: '(');
2304 }
2305 OS << ")";
2306}
2307
2308void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
2309 if (!Node->varlist_empty()) {
2310 OS << "private";
2311 VisitOMPClauseList(Node, StartSym: '(');
2312 OS << ")";
2313 }
2314}
2315
2316void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
2317 if (!Node->varlist_empty()) {
2318 OS << "firstprivate";
2319 VisitOMPClauseList(Node, StartSym: '(');
2320 OS << ")";
2321 }
2322}
2323
2324void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
2325 if (!Node->varlist_empty()) {
2326 OS << "lastprivate";
2327 OpenMPLastprivateModifier LPKind = Node->getKind();
2328 if (LPKind != OMPC_LASTPRIVATE_unknown) {
2329 OS << "("
2330 << getOpenMPSimpleClauseTypeName(OMPC_lastprivate, Node->getKind())
2331 << ":";
2332 }
2333 VisitOMPClauseList(Node, StartSym: LPKind == OMPC_LASTPRIVATE_unknown ? '(' : ' ');
2334 OS << ")";
2335 }
2336}
2337
2338void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
2339 if (!Node->varlist_empty()) {
2340 OS << "shared";
2341 VisitOMPClauseList(Node, StartSym: '(');
2342 OS << ")";
2343 }
2344}
2345
2346void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
2347 if (!Node->varlist_empty()) {
2348 OS << "reduction(";
2349 if (Node->getModifierLoc().isValid())
2350 OS << getOpenMPSimpleClauseTypeName(OMPC_reduction, Node->getModifier())
2351 << ", ";
2352 NestedNameSpecifier *QualifierLoc =
2353 Node->getQualifierLoc().getNestedNameSpecifier();
2354 OverloadedOperatorKind OOK =
2355 Node->getNameInfo().getName().getCXXOverloadedOperator();
2356 if (QualifierLoc == nullptr && OOK != OO_None) {
2357 // Print reduction identifier in C format
2358 OS << getOperatorSpelling(Operator: OOK);
2359 } else {
2360 // Use C++ format
2361 if (QualifierLoc != nullptr)
2362 QualifierLoc->print(OS, Policy);
2363 OS << Node->getNameInfo();
2364 }
2365 OS << ":";
2366 VisitOMPClauseList(Node, StartSym: ' ');
2367 OS << ")";
2368 }
2369}
2370
2371void OMPClausePrinter::VisitOMPTaskReductionClause(
2372 OMPTaskReductionClause *Node) {
2373 if (!Node->varlist_empty()) {
2374 OS << "task_reduction(";
2375 NestedNameSpecifier *QualifierLoc =
2376 Node->getQualifierLoc().getNestedNameSpecifier();
2377 OverloadedOperatorKind OOK =
2378 Node->getNameInfo().getName().getCXXOverloadedOperator();
2379 if (QualifierLoc == nullptr && OOK != OO_None) {
2380 // Print reduction identifier in C format
2381 OS << getOperatorSpelling(Operator: OOK);
2382 } else {
2383 // Use C++ format
2384 if (QualifierLoc != nullptr)
2385 QualifierLoc->print(OS, Policy);
2386 OS << Node->getNameInfo();
2387 }
2388 OS << ":";
2389 VisitOMPClauseList(Node, StartSym: ' ');
2390 OS << ")";
2391 }
2392}
2393
2394void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
2395 if (!Node->varlist_empty()) {
2396 OS << "in_reduction(";
2397 NestedNameSpecifier *QualifierLoc =
2398 Node->getQualifierLoc().getNestedNameSpecifier();
2399 OverloadedOperatorKind OOK =
2400 Node->getNameInfo().getName().getCXXOverloadedOperator();
2401 if (QualifierLoc == nullptr && OOK != OO_None) {
2402 // Print reduction identifier in C format
2403 OS << getOperatorSpelling(Operator: OOK);
2404 } else {
2405 // Use C++ format
2406 if (QualifierLoc != nullptr)
2407 QualifierLoc->print(OS, Policy);
2408 OS << Node->getNameInfo();
2409 }
2410 OS << ":";
2411 VisitOMPClauseList(Node, StartSym: ' ');
2412 OS << ")";
2413 }
2414}
2415
2416void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
2417 if (!Node->varlist_empty()) {
2418 OS << "linear";
2419 VisitOMPClauseList(Node, StartSym: '(');
2420 if (Node->getModifierLoc().isValid() || Node->getStep() != nullptr) {
2421 OS << ": ";
2422 }
2423 if (Node->getModifierLoc().isValid()) {
2424 OS << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
2425 }
2426 if (Node->getStep() != nullptr) {
2427 if (Node->getModifierLoc().isValid()) {
2428 OS << ", ";
2429 }
2430 OS << "step(";
2431 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
2432 OS << ")";
2433 }
2434 OS << ")";
2435 }
2436}
2437
2438void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
2439 if (!Node->varlist_empty()) {
2440 OS << "aligned";
2441 VisitOMPClauseList(Node, StartSym: '(');
2442 if (Node->getAlignment() != nullptr) {
2443 OS << ": ";
2444 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
2445 }
2446 OS << ")";
2447 }
2448}
2449
2450void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
2451 if (!Node->varlist_empty()) {
2452 OS << "copyin";
2453 VisitOMPClauseList(Node, StartSym: '(');
2454 OS << ")";
2455 }
2456}
2457
2458void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
2459 if (!Node->varlist_empty()) {
2460 OS << "copyprivate";
2461 VisitOMPClauseList(Node, StartSym: '(');
2462 OS << ")";
2463 }
2464}
2465
2466void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
2467 if (!Node->varlist_empty()) {
2468 VisitOMPClauseList(Node, StartSym: '(');
2469 OS << ")";
2470 }
2471}
2472
2473void OMPClausePrinter::VisitOMPDepobjClause(OMPDepobjClause *Node) {
2474 OS << "(";
2475 Node->getDepobj()->printPretty(OS, nullptr, Policy, 0);
2476 OS << ")";
2477}
2478
2479void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
2480 OS << "depend(";
2481 if (Expr *DepModifier = Node->getModifier()) {
2482 DepModifier->printPretty(OS, nullptr, Policy);
2483 OS << ", ";
2484 }
2485 OpenMPDependClauseKind DepKind = Node->getDependencyKind();
2486 OpenMPDependClauseKind PrintKind = DepKind;
2487 bool IsOmpAllMemory = false;
2488 if (PrintKind == OMPC_DEPEND_outallmemory) {
2489 PrintKind = OMPC_DEPEND_out;
2490 IsOmpAllMemory = true;
2491 } else if (PrintKind == OMPC_DEPEND_inoutallmemory) {
2492 PrintKind = OMPC_DEPEND_inout;
2493 IsOmpAllMemory = true;
2494 }
2495 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), PrintKind);
2496 if (!Node->varlist_empty() || IsOmpAllMemory)
2497 OS << " :";
2498 VisitOMPClauseList(Node, StartSym: ' ');
2499 if (IsOmpAllMemory) {
2500 OS << (Node->varlist_empty() ? " " : ",");
2501 OS << "omp_all_memory";
2502 }
2503 OS << ")";
2504}
2505
2506template <typename T>
2507static void PrintMapper(raw_ostream &OS, T *Node,
2508 const PrintingPolicy &Policy) {
2509 OS << '(';
2510 NestedNameSpecifier *MapperNNS =
2511 Node->getMapperQualifierLoc().getNestedNameSpecifier();
2512 if (MapperNNS)
2513 MapperNNS->print(OS, Policy);
2514 OS << Node->getMapperIdInfo() << ')';
2515}
2516
2517template <typename T>
2518static void PrintIterator(raw_ostream &OS, T *Node,
2519 const PrintingPolicy &Policy) {
2520 if (Expr *IteratorModifier = Node->getIteratorModifier())
2521 IteratorModifier->printPretty(OS, nullptr, Policy);
2522}
2523
2524void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
2525 if (!Node->varlist_empty()) {
2526 OS << "map(";
2527 if (Node->getMapType() != OMPC_MAP_unknown) {
2528 for (unsigned I = 0; I < NumberOfOMPMapClauseModifiers; ++I) {
2529 if (Node->getMapTypeModifier(Cnt: I) != OMPC_MAP_MODIFIER_unknown) {
2530 if (Node->getMapTypeModifier(Cnt: I) == OMPC_MAP_MODIFIER_iterator) {
2531 PrintIterator(OS, Node, Policy);
2532 } else {
2533 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
2534 Node->getMapTypeModifier(I));
2535 if (Node->getMapTypeModifier(Cnt: I) == OMPC_MAP_MODIFIER_mapper)
2536 PrintMapper(OS, Node, Policy);
2537 }
2538 OS << ',';
2539 }
2540 }
2541 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
2542 OS << ':';
2543 }
2544 VisitOMPClauseList(Node, StartSym: ' ');
2545 OS << ")";
2546 }
2547}
2548
2549template <typename T> void OMPClausePrinter::VisitOMPMotionClause(T *Node) {
2550 if (Node->varlist_empty())
2551 return;
2552 OS << getOpenMPClauseName(Node->getClauseKind());
2553 unsigned ModifierCount = 0;
2554 for (unsigned I = 0; I < NumberOfOMPMotionModifiers; ++I) {
2555 if (Node->getMotionModifier(I) != OMPC_MOTION_MODIFIER_unknown)
2556 ++ModifierCount;
2557 }
2558 if (ModifierCount) {
2559 OS << '(';
2560 for (unsigned I = 0; I < NumberOfOMPMotionModifiers; ++I) {
2561 if (Node->getMotionModifier(I) != OMPC_MOTION_MODIFIER_unknown) {
2562 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
2563 Node->getMotionModifier(I));
2564 if (Node->getMotionModifier(I) == OMPC_MOTION_MODIFIER_mapper)
2565 PrintMapper(OS, Node, Policy);
2566 if (I < ModifierCount - 1)
2567 OS << ", ";
2568 }
2569 }
2570 OS << ':';
2571 VisitOMPClauseList(Node, ' ');
2572 } else {
2573 VisitOMPClauseList(Node, '(');
2574 }
2575 OS << ")";
2576}
2577
2578void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
2579 VisitOMPMotionClause(Node);
2580}
2581
2582void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
2583 VisitOMPMotionClause(Node);
2584}
2585
2586void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
2587 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
2588 OMPC_dist_schedule, Node->getDistScheduleKind());
2589 if (auto *E = Node->getChunkSize()) {
2590 OS << ", ";
2591 E->printPretty(OS, nullptr, Policy);
2592 }
2593 OS << ")";
2594}
2595
2596void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
2597 OS << "defaultmap(";
2598 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
2599 Node->getDefaultmapModifier());
2600 if (Node->getDefaultmapKind() != OMPC_DEFAULTMAP_unknown) {
2601 OS << ": ";
2602 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
2603 Node->getDefaultmapKind());
2604 }
2605 OS << ")";
2606}
2607
2608void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
2609 if (!Node->varlist_empty()) {
2610 OS << "use_device_ptr";
2611 VisitOMPClauseList(Node, StartSym: '(');
2612 OS << ")";
2613 }
2614}
2615
2616void OMPClausePrinter::VisitOMPUseDeviceAddrClause(
2617 OMPUseDeviceAddrClause *Node) {
2618 if (!Node->varlist_empty()) {
2619 OS << "use_device_addr";
2620 VisitOMPClauseList(Node, StartSym: '(');
2621 OS << ")";
2622 }
2623}
2624
2625void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
2626 if (!Node->varlist_empty()) {
2627 OS << "is_device_ptr";
2628 VisitOMPClauseList(Node, StartSym: '(');
2629 OS << ")";
2630 }
2631}
2632
2633void OMPClausePrinter::VisitOMPHasDeviceAddrClause(OMPHasDeviceAddrClause *Node) {
2634 if (!Node->varlist_empty()) {
2635 OS << "has_device_addr";
2636 VisitOMPClauseList(Node, StartSym: '(');
2637 OS << ")";
2638 }
2639}
2640
2641void OMPClausePrinter::VisitOMPNontemporalClause(OMPNontemporalClause *Node) {
2642 if (!Node->varlist_empty()) {
2643 OS << "nontemporal";
2644 VisitOMPClauseList(Node, StartSym: '(');
2645 OS << ")";
2646 }
2647}
2648
2649void OMPClausePrinter::VisitOMPOrderClause(OMPOrderClause *Node) {
2650 OS << "order(";
2651 if (Node->getModifier() != OMPC_ORDER_MODIFIER_unknown) {
2652 OS << getOpenMPSimpleClauseTypeName(OMPC_order, Node->getModifier());
2653 OS << ": ";
2654 }
2655 OS << getOpenMPSimpleClauseTypeName(OMPC_order, Node->getKind()) << ")";
2656}
2657
2658void OMPClausePrinter::VisitOMPInclusiveClause(OMPInclusiveClause *Node) {
2659 if (!Node->varlist_empty()) {
2660 OS << "inclusive";
2661 VisitOMPClauseList(Node, StartSym: '(');
2662 OS << ")";
2663 }
2664}
2665
2666void OMPClausePrinter::VisitOMPExclusiveClause(OMPExclusiveClause *Node) {
2667 if (!Node->varlist_empty()) {
2668 OS << "exclusive";
2669 VisitOMPClauseList(Node, StartSym: '(');
2670 OS << ")";
2671 }
2672}
2673
2674void OMPClausePrinter::VisitOMPUsesAllocatorsClause(
2675 OMPUsesAllocatorsClause *Node) {
2676 if (Node->getNumberOfAllocators() == 0)
2677 return;
2678 OS << "uses_allocators(";
2679 for (unsigned I = 0, E = Node->getNumberOfAllocators(); I < E; ++I) {
2680 OMPUsesAllocatorsClause::Data Data = Node->getAllocatorData(I);
2681 Data.Allocator->printPretty(OS, nullptr, Policy);
2682 if (Data.AllocatorTraits) {
2683 OS << "(";
2684 Data.AllocatorTraits->printPretty(OS, nullptr, Policy);
2685 OS << ")";
2686 }
2687 if (I < E - 1)
2688 OS << ",";
2689 }
2690 OS << ")";
2691}
2692
2693void OMPClausePrinter::VisitOMPAffinityClause(OMPAffinityClause *Node) {
2694 if (Node->varlist_empty())
2695 return;
2696 OS << "affinity";
2697 char StartSym = '(';
2698 if (Expr *Modifier = Node->getModifier()) {
2699 OS << "(";
2700 Modifier->printPretty(OS, nullptr, Policy);
2701 OS << " :";
2702 StartSym = ' ';
2703 }
2704 VisitOMPClauseList(Node, StartSym);
2705 OS << ")";
2706}
2707
2708void OMPClausePrinter::VisitOMPFilterClause(OMPFilterClause *Node) {
2709 OS << "filter(";
2710 Node->getThreadID()->printPretty(OS, nullptr, Policy, 0);
2711 OS << ")";
2712}
2713
2714void OMPClausePrinter::VisitOMPBindClause(OMPBindClause *Node) {
2715 OS << "bind("
2716 << getOpenMPSimpleClauseTypeName(OMPC_bind, unsigned(Node->getBindKind()))
2717 << ")";
2718}
2719
2720void OMPClausePrinter::VisitOMPXDynCGroupMemClause(
2721 OMPXDynCGroupMemClause *Node) {
2722 OS << "ompx_dyn_cgroup_mem(";
2723 Node->getSize()->printPretty(OS, nullptr, Policy, 0);
2724 OS << ")";
2725}
2726
2727void OMPClausePrinter::VisitOMPDoacrossClause(OMPDoacrossClause *Node) {
2728 OS << "doacross(";
2729 OpenMPDoacrossClauseModifier DepType = Node->getDependenceType();
2730
2731 switch (DepType) {
2732 case OMPC_DOACROSS_source:
2733 OS << "source:";
2734 break;
2735 case OMPC_DOACROSS_sink:
2736 OS << "sink:";
2737 break;
2738 case OMPC_DOACROSS_source_omp_cur_iteration:
2739 OS << "source: omp_cur_iteration";
2740 break;
2741 case OMPC_DOACROSS_sink_omp_cur_iteration:
2742 OS << "sink: omp_cur_iteration - 1";
2743 break;
2744 default:
2745 llvm_unreachable("unknown docaross modifier");
2746 }
2747 VisitOMPClauseList(Node, StartSym: ' ');
2748 OS << ")";
2749}
2750
2751void OMPClausePrinter::VisitOMPXAttributeClause(OMPXAttributeClause *Node) {
2752 OS << "ompx_attribute(";
2753 bool IsFirst = true;
2754 for (auto &Attr : Node->getAttrs()) {
2755 if (!IsFirst)
2756 OS << ", ";
2757 Attr->printPretty(OS, Policy);
2758 IsFirst = false;
2759 }
2760 OS << ")";
2761}
2762
2763void OMPClausePrinter::VisitOMPXBareClause(OMPXBareClause *Node) {
2764 OS << "ompx_bare";
2765}
2766
2767void OMPTraitInfo::getAsVariantMatchInfo(ASTContext &ASTCtx,
2768 VariantMatchInfo &VMI) const {
2769 for (const OMPTraitSet &Set : Sets) {
2770 for (const OMPTraitSelector &Selector : Set.Selectors) {
2771
2772 // User conditions are special as we evaluate the condition here.
2773 if (Selector.Kind == TraitSelector::user_condition) {
2774 assert(Selector.ScoreOrCondition &&
2775 "Ill-formed user condition, expected condition expression!");
2776 assert(Selector.Properties.size() == 1 &&
2777 Selector.Properties.front().Kind ==
2778 TraitProperty::user_condition_unknown &&
2779 "Ill-formed user condition, expected unknown trait property!");
2780
2781 if (std::optional<APSInt> CondVal =
2782 Selector.ScoreOrCondition->getIntegerConstantExpr(ASTCtx))
2783 VMI.addTrait(CondVal->isZero() ? TraitProperty::user_condition_false
2784 : TraitProperty::user_condition_true,
2785 "<condition>");
2786 else
2787 VMI.addTrait(TraitProperty::user_condition_false, "<condition>");
2788 continue;
2789 }
2790
2791 std::optional<llvm::APSInt> Score;
2792 llvm::APInt *ScorePtr = nullptr;
2793 if (Selector.ScoreOrCondition) {
2794 if ((Score = Selector.ScoreOrCondition->getIntegerConstantExpr(ASTCtx)))
2795 ScorePtr = &*Score;
2796 else
2797 VMI.addTrait(TraitProperty::user_condition_false,
2798 "<non-constant-score>");
2799 }
2800
2801 for (const OMPTraitProperty &Property : Selector.Properties)
2802 VMI.addTrait(Set.Kind, Property.Kind, Property.RawString, ScorePtr);
2803
2804 if (Set.Kind != TraitSet::construct)
2805 continue;
2806
2807 // TODO: This might not hold once we implement SIMD properly.
2808 assert(Selector.Properties.size() == 1 &&
2809 Selector.Properties.front().Kind ==
2810 getOpenMPContextTraitPropertyForSelector(
2811 Selector.Kind) &&
2812 "Ill-formed construct selector!");
2813 }
2814 }
2815}
2816
2817void OMPTraitInfo::print(llvm::raw_ostream &OS,
2818 const PrintingPolicy &Policy) const {
2819 bool FirstSet = true;
2820 for (const OMPTraitSet &Set : Sets) {
2821 if (!FirstSet)
2822 OS << ", ";
2823 FirstSet = false;
2824 OS << getOpenMPContextTraitSetName(Set.Kind) << "={";
2825
2826 bool FirstSelector = true;
2827 for (const OMPTraitSelector &Selector : Set.Selectors) {
2828 if (!FirstSelector)
2829 OS << ", ";
2830 FirstSelector = false;
2831 OS << getOpenMPContextTraitSelectorName(Selector.Kind);
2832
2833 bool AllowsTraitScore = false;
2834 bool RequiresProperty = false;
2835 isValidTraitSelectorForTraitSet(
2836 Selector.Kind, Set.Kind, AllowsTraitScore, RequiresProperty);
2837
2838 if (!RequiresProperty)
2839 continue;
2840
2841 OS << "(";
2842 if (Selector.Kind == TraitSelector::user_condition) {
2843 if (Selector.ScoreOrCondition)
2844 Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy);
2845 else
2846 OS << "...";
2847 } else {
2848
2849 if (Selector.ScoreOrCondition) {
2850 OS << "score(";
2851 Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy);
2852 OS << "): ";
2853 }
2854
2855 bool FirstProperty = true;
2856 for (const OMPTraitProperty &Property : Selector.Properties) {
2857 if (!FirstProperty)
2858 OS << ", ";
2859 FirstProperty = false;
2860 OS << getOpenMPContextTraitPropertyName(Property.Kind,
2861 Property.RawString);
2862 }
2863 }
2864 OS << ")";
2865 }
2866 OS << "}";
2867 }
2868}
2869
2870std::string OMPTraitInfo::getMangledName() const {
2871 std::string MangledName;
2872 llvm::raw_string_ostream OS(MangledName);
2873 for (const OMPTraitSet &Set : Sets) {
2874 OS << '$' << 'S' << unsigned(Set.Kind);
2875 for (const OMPTraitSelector &Selector : Set.Selectors) {
2876
2877 bool AllowsTraitScore = false;
2878 bool RequiresProperty = false;
2879 isValidTraitSelectorForTraitSet(
2880 Selector.Kind, Set.Kind, AllowsTraitScore, RequiresProperty);
2881 OS << '$' << 's' << unsigned(Selector.Kind);
2882
2883 if (!RequiresProperty ||
2884 Selector.Kind == TraitSelector::user_condition)
2885 continue;
2886
2887 for (const OMPTraitProperty &Property : Selector.Properties)
2888 OS << '$' << 'P'
2889 << getOpenMPContextTraitPropertyName(Property.Kind,
2890 Property.RawString);
2891 }
2892 }
2893 return MangledName;
2894}
2895
2896OMPTraitInfo::OMPTraitInfo(StringRef MangledName) {
2897 unsigned long U;
2898 do {
2899 if (!MangledName.consume_front(Prefix: "$S"))
2900 break;
2901 if (MangledName.consumeInteger(Radix: 10, Result&: U))
2902 break;
2903 Sets.push_back(OMPTraitSet());
2904 OMPTraitSet &Set = Sets.back();
2905 Set.Kind = TraitSet(U);
2906 do {
2907 if (!MangledName.consume_front(Prefix: "$s"))
2908 break;
2909 if (MangledName.consumeInteger(Radix: 10, Result&: U))
2910 break;
2911 Set.Selectors.push_back(OMPTraitSelector());
2912 OMPTraitSelector &Selector = Set.Selectors.back();
2913 Selector.Kind = TraitSelector(U);
2914 do {
2915 if (!MangledName.consume_front(Prefix: "$P"))
2916 break;
2917 Selector.Properties.push_back(OMPTraitProperty());
2918 OMPTraitProperty &Property = Selector.Properties.back();
2919 std::pair<StringRef, StringRef> PropRestPair = MangledName.split(Separator: '$');
2920 Property.RawString = PropRestPair.first;
2921 Property.Kind = getOpenMPContextTraitPropertyKind(
2922 Set: Set.Kind, Selector: Selector.Kind, Str: PropRestPair.first);
2923 MangledName = MangledName.drop_front(N: PropRestPair.first.size());
2924 } while (true);
2925 } while (true);
2926 } while (true);
2927}
2928
2929llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS,
2930 const OMPTraitInfo &TI) {
2931 LangOptions LO;
2932 PrintingPolicy Policy(LO);
2933 TI.print(OS, Policy);
2934 return OS;
2935}
2936llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS,
2937 const OMPTraitInfo *TI) {
2938 return TI ? OS << *TI : OS;
2939}
2940
2941TargetOMPContext::TargetOMPContext(
2942 ASTContext &ASTCtx, std::function<void(StringRef)> &&DiagUnknownTrait,
2943 const FunctionDecl *CurrentFunctionDecl,
2944 ArrayRef<llvm::omp::TraitProperty> ConstructTraits, int DeviceNum)
2945 : OMPContext(ASTCtx.getLangOpts().OpenMPIsTargetDevice,
2946 ASTCtx.getTargetInfo().getTriple(),
2947 ASTCtx.getLangOpts().OMPTargetTriples.empty()
2948 ? llvm::Triple()
2949 : ASTCtx.getLangOpts().OMPTargetTriples[0],
2950 DeviceNum),
2951 FeatureValidityCheck([&](StringRef FeatureName) {
2952 return ASTCtx.getTargetInfo().isValidFeatureName(FeatureName);
2953 }),
2954 DiagUnknownTrait(std::move(DiagUnknownTrait)) {
2955 ASTCtx.getFunctionFeatureMap(FeatureMap, CurrentFunctionDecl);
2956
2957 for (llvm::omp::TraitProperty Property : ConstructTraits)
2958 addTrait(Property);
2959}
2960
2961bool TargetOMPContext::matchesISATrait(StringRef RawString) const {
2962 auto It = FeatureMap.find(RawString);
2963 if (It != FeatureMap.end())
2964 return It->second;
2965 if (!FeatureValidityCheck(RawString))
2966 DiagUnknownTrait(RawString);
2967 return false;
2968}
2969

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of clang/lib/AST/OpenMPClause.cpp