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