1 //===- OpenMPClause.cpp - Classes for OpenMP clauses ----------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file implements the subclesses of Stmt class declared in OpenMPClause.h
11 //===----------------------------------------------------------------------===//
13 #include "clang/AST/OpenMPClause.h"
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/Decl.h"
16 #include "clang/AST/DeclOpenMP.h"
17 #include "clang/Basic/LLVM.h"
18 #include "llvm/ADT/SmallPtrSet.h"
19 #include "llvm/Support/Casting.h"
20 #include "llvm/Support/ErrorHandling.h"
24 using namespace clang;
26 OMPClause::child_range OMPClause::children() {
27 switch (getClauseKind()) {
30 #define OPENMP_CLAUSE(Name, Class) \
32 return static_cast<Class *>(this)->children();
33 #include "clang/Basic/OpenMPKinds.def"
35 llvm_unreachable("unknown OMPClause");
38 OMPClause::child_range OMPClause::used_children() {
39 switch (getClauseKind()) {
40 #define OPENMP_CLAUSE(Name, Class) \
42 return static_cast<Class *>(this)->used_children();
43 #include "clang/Basic/OpenMPKinds.def"
44 case OMPC_threadprivate:
49 llvm_unreachable("unknown OMPClause");
52 OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
53 auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
54 return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr;
57 const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
58 switch (C->getClauseKind()) {
60 return static_cast<const OMPScheduleClause *>(C);
61 case OMPC_dist_schedule:
62 return static_cast<const OMPDistScheduleClause *>(C);
63 case OMPC_firstprivate:
64 return static_cast<const OMPFirstprivateClause *>(C);
65 case OMPC_lastprivate:
66 return static_cast<const OMPLastprivateClause *>(C);
68 return static_cast<const OMPReductionClause *>(C);
69 case OMPC_task_reduction:
70 return static_cast<const OMPTaskReductionClause *>(C);
71 case OMPC_in_reduction:
72 return static_cast<const OMPInReductionClause *>(C);
74 return static_cast<const OMPLinearClause *>(C);
76 return static_cast<const OMPIfClause *>(C);
77 case OMPC_num_threads:
78 return static_cast<const OMPNumThreadsClause *>(C);
80 return static_cast<const OMPNumTeamsClause *>(C);
81 case OMPC_thread_limit:
82 return static_cast<const OMPThreadLimitClause *>(C);
84 return static_cast<const OMPDeviceClause *>(C);
97 case OMPC_copyprivate:
102 case OMPC_threadprivate:
118 case OMPC_defaultmap:
123 case OMPC_use_device_ptr:
124 case OMPC_is_device_ptr:
125 case OMPC_unified_address:
126 case OMPC_unified_shared_memory:
127 case OMPC_reverse_offload:
128 case OMPC_dynamic_allocators:
129 case OMPC_atomic_default_mem_order:
136 OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
137 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
138 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
141 const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
142 switch (C->getClauseKind()) {
143 case OMPC_lastprivate:
144 return static_cast<const OMPLastprivateClause *>(C);
146 return static_cast<const OMPReductionClause *>(C);
147 case OMPC_task_reduction:
148 return static_cast<const OMPTaskReductionClause *>(C);
149 case OMPC_in_reduction:
150 return static_cast<const OMPInReductionClause *>(C);
152 return static_cast<const OMPLinearClause *>(C);
154 case OMPC_dist_schedule:
155 case OMPC_firstprivate:
160 case OMPC_num_threads:
170 case OMPC_copyprivate:
175 case OMPC_threadprivate:
188 case OMPC_thread_limit:
194 case OMPC_defaultmap:
199 case OMPC_use_device_ptr:
200 case OMPC_is_device_ptr:
201 case OMPC_unified_address:
202 case OMPC_unified_shared_memory:
203 case OMPC_reverse_offload:
204 case OMPC_dynamic_allocators:
205 case OMPC_atomic_default_mem_order:
212 /// Gets the address of the original, non-captured, expression used in the
213 /// clause as the preinitializer.
214 static Stmt **getAddrOfExprAsWritten(Stmt *S) {
217 if (auto *DS = dyn_cast<DeclStmt>(S)) {
218 assert(DS->isSingleDecl() && "Only single expression must be captured.");
219 if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
220 return OED->getInitAddress();
225 OMPClause::child_range OMPIfClause::used_children() {
226 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
227 return child_range(C, C + 1);
228 return child_range(&Condition, &Condition + 1);
231 OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
233 SourceLocation StartLoc,
234 SourceLocation LParenLoc,
235 SourceLocation EndLoc) {
236 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
238 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
239 for (unsigned I = 0; I < NumLoops; ++I) {
240 Clause->setLoopNumIterations(I, nullptr);
241 Clause->setLoopCounter(I, nullptr);
246 OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
248 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
249 auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
250 for (unsigned I = 0; I < NumLoops; ++I) {
251 Clause->setLoopNumIterations(I, nullptr);
252 Clause->setLoopCounter(I, nullptr);
257 void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
258 Expr *NumIterations) {
259 assert(NumLoop < NumberOfLoops && "out of loops number.");
260 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
263 ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
264 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
267 void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
268 assert(NumLoop < NumberOfLoops && "out of loops number.");
269 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
272 Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
273 assert(NumLoop < NumberOfLoops && "out of loops number.");
274 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
277 const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
278 assert(NumLoop < NumberOfLoops && "out of loops number.");
279 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
282 void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
283 assert(VL.size() == varlist_size() &&
284 "Number of private copies is not the same as the preallocated buffer");
285 std::copy(VL.begin(), VL.end(), varlist_end());
289 OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
290 SourceLocation LParenLoc, SourceLocation EndLoc,
291 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
292 // Allocate space for private variables and initializer expressions.
293 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
294 OMPPrivateClause *Clause =
295 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
296 Clause->setVarRefs(VL);
297 Clause->setPrivateCopies(PrivateVL);
301 OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
303 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
304 return new (Mem) OMPPrivateClause(N);
307 void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
308 assert(VL.size() == varlist_size() &&
309 "Number of private copies is not the same as the preallocated buffer");
310 std::copy(VL.begin(), VL.end(), varlist_end());
313 void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
314 assert(VL.size() == varlist_size() &&
315 "Number of inits is not the same as the preallocated buffer");
316 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
319 OMPFirstprivateClause *
320 OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
321 SourceLocation LParenLoc, SourceLocation EndLoc,
322 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
323 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
324 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
325 OMPFirstprivateClause *Clause =
326 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
327 Clause->setVarRefs(VL);
328 Clause->setPrivateCopies(PrivateVL);
329 Clause->setInits(InitVL);
330 Clause->setPreInitStmt(PreInit);
334 OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
336 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
337 return new (Mem) OMPFirstprivateClause(N);
340 void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
341 assert(PrivateCopies.size() == varlist_size() &&
342 "Number of private copies is not the same as the preallocated buffer");
343 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
346 void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
347 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
348 "not the same as the "
349 "preallocated buffer");
350 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
353 void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
354 assert(DstExprs.size() == varlist_size() && "Number of destination "
355 "expressions is not the same as "
356 "the preallocated buffer");
357 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
360 void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
361 assert(AssignmentOps.size() == varlist_size() &&
362 "Number of assignment expressions is not the same as the preallocated "
364 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
365 getDestinationExprs().end());
368 OMPLastprivateClause *OMPLastprivateClause::Create(
369 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
370 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
371 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit,
373 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
374 OMPLastprivateClause *Clause =
375 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
376 Clause->setVarRefs(VL);
377 Clause->setSourceExprs(SrcExprs);
378 Clause->setDestinationExprs(DstExprs);
379 Clause->setAssignmentOps(AssignmentOps);
380 Clause->setPreInitStmt(PreInit);
381 Clause->setPostUpdateExpr(PostUpdate);
385 OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
387 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
388 return new (Mem) OMPLastprivateClause(N);
391 OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
392 SourceLocation StartLoc,
393 SourceLocation LParenLoc,
394 SourceLocation EndLoc,
395 ArrayRef<Expr *> VL) {
396 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
397 OMPSharedClause *Clause =
398 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
399 Clause->setVarRefs(VL);
403 OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
404 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
405 return new (Mem) OMPSharedClause(N);
408 void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
409 assert(PL.size() == varlist_size() &&
410 "Number of privates is not the same as the preallocated buffer");
411 std::copy(PL.begin(), PL.end(), varlist_end());
414 void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
415 assert(IL.size() == varlist_size() &&
416 "Number of inits is not the same as the preallocated buffer");
417 std::copy(IL.begin(), IL.end(), getPrivates().end());
420 void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
421 assert(UL.size() == varlist_size() &&
422 "Number of updates is not the same as the preallocated buffer");
423 std::copy(UL.begin(), UL.end(), getInits().end());
426 void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
427 assert(FL.size() == varlist_size() &&
428 "Number of final updates is not the same as the preallocated buffer");
429 std::copy(FL.begin(), FL.end(), getUpdates().end());
432 OMPLinearClause *OMPLinearClause::Create(
433 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
434 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
435 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
436 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
437 Stmt *PreInit, Expr *PostUpdate) {
438 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
439 // (Step and CalcStep).
440 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2));
441 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
442 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
443 Clause->setVarRefs(VL);
444 Clause->setPrivates(PL);
445 Clause->setInits(IL);
446 // Fill update and final expressions with zeroes, they are provided later,
447 // after the directive construction.
448 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
450 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
452 Clause->setStep(Step);
453 Clause->setCalcStep(CalcStep);
454 Clause->setPreInitStmt(PreInit);
455 Clause->setPostUpdateExpr(PostUpdate);
459 OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
461 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
462 // (Step and CalcStep).
463 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2));
464 return new (Mem) OMPLinearClause(NumVars);
468 OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
469 SourceLocation LParenLoc, SourceLocation ColonLoc,
470 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
471 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
472 OMPAlignedClause *Clause = new (Mem)
473 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
474 Clause->setVarRefs(VL);
475 Clause->setAlignment(A);
479 OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
481 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
482 return new (Mem) OMPAlignedClause(NumVars);
485 void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
486 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
487 "not the same as the "
488 "preallocated buffer");
489 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
492 void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
493 assert(DstExprs.size() == varlist_size() && "Number of destination "
494 "expressions is not the same as "
495 "the preallocated buffer");
496 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
499 void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
500 assert(AssignmentOps.size() == varlist_size() &&
501 "Number of assignment expressions is not the same as the preallocated "
503 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
504 getDestinationExprs().end());
507 OMPCopyinClause *OMPCopyinClause::Create(
508 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
509 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
510 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
511 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
512 OMPCopyinClause *Clause =
513 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
514 Clause->setVarRefs(VL);
515 Clause->setSourceExprs(SrcExprs);
516 Clause->setDestinationExprs(DstExprs);
517 Clause->setAssignmentOps(AssignmentOps);
521 OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
522 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
523 return new (Mem) OMPCopyinClause(N);
526 void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
527 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
528 "not the same as the "
529 "preallocated buffer");
530 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
533 void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
534 assert(DstExprs.size() == varlist_size() && "Number of destination "
535 "expressions is not the same as "
536 "the preallocated buffer");
537 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
540 void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
541 assert(AssignmentOps.size() == varlist_size() &&
542 "Number of assignment expressions is not the same as the preallocated "
544 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
545 getDestinationExprs().end());
548 OMPCopyprivateClause *OMPCopyprivateClause::Create(
549 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
550 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
551 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
552 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
553 OMPCopyprivateClause *Clause =
554 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
555 Clause->setVarRefs(VL);
556 Clause->setSourceExprs(SrcExprs);
557 Clause->setDestinationExprs(DstExprs);
558 Clause->setAssignmentOps(AssignmentOps);
562 OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
564 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
565 return new (Mem) OMPCopyprivateClause(N);
568 void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
569 assert(Privates.size() == varlist_size() &&
570 "Number of private copies is not the same as the preallocated buffer");
571 std::copy(Privates.begin(), Privates.end(), varlist_end());
574 void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
576 LHSExprs.size() == varlist_size() &&
577 "Number of LHS expressions is not the same as the preallocated buffer");
578 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
581 void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
583 RHSExprs.size() == varlist_size() &&
584 "Number of RHS expressions is not the same as the preallocated buffer");
585 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
588 void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
589 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
590 "expressions is not the same "
591 "as the preallocated buffer");
592 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
595 OMPReductionClause *OMPReductionClause::Create(
596 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
597 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
598 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
599 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
600 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
602 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
603 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
604 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
605 Clause->setVarRefs(VL);
606 Clause->setPrivates(Privates);
607 Clause->setLHSExprs(LHSExprs);
608 Clause->setRHSExprs(RHSExprs);
609 Clause->setReductionOps(ReductionOps);
610 Clause->setPreInitStmt(PreInit);
611 Clause->setPostUpdateExpr(PostUpdate);
615 OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
617 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
618 return new (Mem) OMPReductionClause(N);
621 void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
622 assert(Privates.size() == varlist_size() &&
623 "Number of private copies is not the same as the preallocated buffer");
624 std::copy(Privates.begin(), Privates.end(), varlist_end());
627 void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
629 LHSExprs.size() == varlist_size() &&
630 "Number of LHS expressions is not the same as the preallocated buffer");
631 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
634 void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
636 RHSExprs.size() == varlist_size() &&
637 "Number of RHS expressions is not the same as the preallocated buffer");
638 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
641 void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
642 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
643 "expressions is not the same "
644 "as the preallocated buffer");
645 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
648 OMPTaskReductionClause *OMPTaskReductionClause::Create(
649 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
650 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
651 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
652 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
653 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
655 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
656 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
657 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
658 Clause->setVarRefs(VL);
659 Clause->setPrivates(Privates);
660 Clause->setLHSExprs(LHSExprs);
661 Clause->setRHSExprs(RHSExprs);
662 Clause->setReductionOps(ReductionOps);
663 Clause->setPreInitStmt(PreInit);
664 Clause->setPostUpdateExpr(PostUpdate);
668 OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
670 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
671 return new (Mem) OMPTaskReductionClause(N);
674 void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
675 assert(Privates.size() == varlist_size() &&
676 "Number of private copies is not the same as the preallocated buffer");
677 std::copy(Privates.begin(), Privates.end(), varlist_end());
680 void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
682 LHSExprs.size() == varlist_size() &&
683 "Number of LHS expressions is not the same as the preallocated buffer");
684 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
687 void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
689 RHSExprs.size() == varlist_size() &&
690 "Number of RHS expressions is not the same as the preallocated buffer");
691 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
694 void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
695 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
696 "expressions is not the same "
697 "as the preallocated buffer");
698 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
701 void OMPInReductionClause::setTaskgroupDescriptors(
702 ArrayRef<Expr *> TaskgroupDescriptors) {
703 assert(TaskgroupDescriptors.size() == varlist_size() &&
704 "Number of in reduction descriptors is not the same as the "
705 "preallocated buffer");
706 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
707 getReductionOps().end());
710 OMPInReductionClause *OMPInReductionClause::Create(
711 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
712 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
713 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
714 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
715 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
716 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
717 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
718 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
719 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
720 Clause->setVarRefs(VL);
721 Clause->setPrivates(Privates);
722 Clause->setLHSExprs(LHSExprs);
723 Clause->setRHSExprs(RHSExprs);
724 Clause->setReductionOps(ReductionOps);
725 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
726 Clause->setPreInitStmt(PreInit);
727 Clause->setPostUpdateExpr(PostUpdate);
731 OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
733 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
734 return new (Mem) OMPInReductionClause(N);
738 OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc,
739 SourceLocation LParenLoc, Expr *Allocator,
740 SourceLocation ColonLoc, SourceLocation EndLoc,
741 ArrayRef<Expr *> VL) {
742 // Allocate space for private variables and initializer expressions.
743 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
744 auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
745 ColonLoc, EndLoc, VL.size());
746 Clause->setVarRefs(VL);
750 OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
752 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
753 return new (Mem) OMPAllocateClause(N);
756 OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
757 SourceLocation StartLoc,
758 SourceLocation LParenLoc,
759 SourceLocation EndLoc,
760 ArrayRef<Expr *> VL) {
761 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
762 OMPFlushClause *Clause =
763 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
764 Clause->setVarRefs(VL);
768 OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
769 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
770 return new (Mem) OMPFlushClause(N);
774 OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
775 SourceLocation LParenLoc, SourceLocation EndLoc,
776 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
777 SourceLocation ColonLoc, ArrayRef<Expr *> VL,
779 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
780 OMPDependClause *Clause = new (Mem)
781 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
782 Clause->setVarRefs(VL);
783 Clause->setDependencyKind(DepKind);
784 Clause->setDependencyLoc(DepLoc);
785 Clause->setColonLoc(ColonLoc);
786 for (unsigned I = 0 ; I < NumLoops; ++I)
787 Clause->setLoopData(I, nullptr);
791 OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
793 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
794 return new (Mem) OMPDependClause(N, NumLoops);
797 void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
798 assert((getDependencyKind() == OMPC_DEPEND_sink ||
799 getDependencyKind() == OMPC_DEPEND_source) &&
800 NumLoop < NumLoops &&
801 "Expected sink or source depend + loop index must be less number of "
803 auto It = std::next(getVarRefs().end(), NumLoop);
807 Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
808 assert((getDependencyKind() == OMPC_DEPEND_sink ||
809 getDependencyKind() == OMPC_DEPEND_source) &&
810 NumLoop < NumLoops &&
811 "Expected sink or source depend + loop index must be less number of "
813 auto It = std::next(getVarRefs().end(), NumLoop);
817 const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
818 assert((getDependencyKind() == OMPC_DEPEND_sink ||
819 getDependencyKind() == OMPC_DEPEND_source) &&
820 NumLoop < NumLoops &&
821 "Expected sink or source depend + loop index must be less number of "
823 auto It = std::next(getVarRefs().end(), NumLoop);
827 unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
828 MappableExprComponentListsRef ComponentLists) {
829 unsigned TotalNum = 0u;
830 for (auto &C : ComponentLists)
831 TotalNum += C.size();
835 unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
836 ArrayRef<const ValueDecl *> Declarations) {
837 unsigned TotalNum = 0u;
838 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
839 for (const ValueDecl *D : Declarations) {
840 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
849 OMPMapClause *OMPMapClause::Create(
850 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
851 ArrayRef<ValueDecl *> Declarations,
852 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
853 ArrayRef<OpenMPMapModifierKind> MapModifiers,
854 ArrayRef<SourceLocation> MapModifiersLoc,
855 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
856 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
857 OMPMappableExprListSizeTy Sizes;
858 Sizes.NumVars = Vars.size();
859 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
860 Sizes.NumComponentLists = ComponentLists.size();
861 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
863 // We need to allocate:
864 // 2 x NumVars x Expr* - we have an original list expression and an associated
865 // user-defined mapper for each clause list entry.
866 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
867 // with each component list.
868 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
869 // number of lists for each unique declaration and the size of each component
871 // NumComponents x MappableComponent - the total of all the components in all
873 void *Mem = C.Allocate(
874 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
875 OMPClauseMappableExprCommon::MappableComponent>(
876 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
877 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
878 Sizes.NumComponents));
879 OMPMapClause *Clause = new (Mem)
880 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
881 Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
883 Clause->setVarRefs(Vars);
884 Clause->setUDMapperRefs(UDMapperRefs);
885 Clause->setClauseInfo(Declarations, ComponentLists);
886 Clause->setMapType(Type);
887 Clause->setMapLoc(TypeLoc);
892 OMPMapClause::CreateEmpty(const ASTContext &C,
893 const OMPMappableExprListSizeTy &Sizes) {
894 void *Mem = C.Allocate(
895 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
896 OMPClauseMappableExprCommon::MappableComponent>(
897 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
898 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
899 Sizes.NumComponents));
900 return new (Mem) OMPMapClause(Sizes);
903 OMPToClause *OMPToClause::Create(
904 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
905 ArrayRef<ValueDecl *> Declarations,
906 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
907 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
908 OMPMappableExprListSizeTy Sizes;
909 Sizes.NumVars = Vars.size();
910 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
911 Sizes.NumComponentLists = ComponentLists.size();
912 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
914 // We need to allocate:
915 // 2 x NumVars x Expr* - we have an original list expression and an associated
916 // user-defined mapper for each clause list entry.
917 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
918 // with each component list.
919 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
920 // number of lists for each unique declaration and the size of each component
922 // NumComponents x MappableComponent - the total of all the components in all
924 void *Mem = C.Allocate(
925 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
926 OMPClauseMappableExprCommon::MappableComponent>(
927 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
928 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
929 Sizes.NumComponents));
931 auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
933 Clause->setVarRefs(Vars);
934 Clause->setUDMapperRefs(UDMapperRefs);
935 Clause->setClauseInfo(Declarations, ComponentLists);
939 OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
940 const OMPMappableExprListSizeTy &Sizes) {
941 void *Mem = C.Allocate(
942 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
943 OMPClauseMappableExprCommon::MappableComponent>(
944 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
945 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
946 Sizes.NumComponents));
947 return new (Mem) OMPToClause(Sizes);
950 OMPFromClause *OMPFromClause::Create(
951 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
952 ArrayRef<ValueDecl *> Declarations,
953 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
954 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
955 OMPMappableExprListSizeTy Sizes;
956 Sizes.NumVars = Vars.size();
957 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
958 Sizes.NumComponentLists = ComponentLists.size();
959 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
961 // We need to allocate:
962 // 2 x NumVars x Expr* - we have an original list expression and an associated
963 // user-defined mapper for each clause list entry.
964 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
965 // with each component list.
966 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
967 // number of lists for each unique declaration and the size of each component
969 // NumComponents x MappableComponent - the total of all the components in all
971 void *Mem = C.Allocate(
972 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
973 OMPClauseMappableExprCommon::MappableComponent>(
974 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
975 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
976 Sizes.NumComponents));
979 new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
981 Clause->setVarRefs(Vars);
982 Clause->setUDMapperRefs(UDMapperRefs);
983 Clause->setClauseInfo(Declarations, ComponentLists);
988 OMPFromClause::CreateEmpty(const ASTContext &C,
989 const OMPMappableExprListSizeTy &Sizes) {
990 void *Mem = C.Allocate(
991 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
992 OMPClauseMappableExprCommon::MappableComponent>(
993 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
994 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
995 Sizes.NumComponents));
996 return new (Mem) OMPFromClause(Sizes);
999 void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1000 assert(VL.size() == varlist_size() &&
1001 "Number of private copies is not the same as the preallocated buffer");
1002 std::copy(VL.begin(), VL.end(), varlist_end());
1005 void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
1006 assert(VL.size() == varlist_size() &&
1007 "Number of inits is not the same as the preallocated buffer");
1008 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1011 OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
1012 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1013 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
1014 ArrayRef<ValueDecl *> Declarations,
1015 MappableExprComponentListsRef ComponentLists) {
1016 OMPMappableExprListSizeTy Sizes;
1017 Sizes.NumVars = Vars.size();
1018 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1019 Sizes.NumComponentLists = ComponentLists.size();
1020 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1022 // We need to allocate:
1023 // 3 x NumVars x Expr* - we have an original list expression for each clause
1024 // list entry and an equal number of private copies and inits.
1025 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1026 // with each component list.
1027 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1028 // number of lists for each unique declaration and the size of each component
1030 // NumComponents x MappableComponent - the total of all the components in all
1032 void *Mem = C.Allocate(
1033 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1034 OMPClauseMappableExprCommon::MappableComponent>(
1035 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1036 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1037 Sizes.NumComponents));
1039 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
1041 Clause->setVarRefs(Vars);
1042 Clause->setPrivateCopies(PrivateVars);
1043 Clause->setInits(Inits);
1044 Clause->setClauseInfo(Declarations, ComponentLists);
1048 OMPUseDevicePtrClause *
1049 OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
1050 const OMPMappableExprListSizeTy &Sizes) {
1051 void *Mem = C.Allocate(
1052 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1053 OMPClauseMappableExprCommon::MappableComponent>(
1054 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1055 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1056 Sizes.NumComponents));
1057 return new (Mem) OMPUseDevicePtrClause(Sizes);
1060 OMPIsDevicePtrClause *
1061 OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
1062 ArrayRef<Expr *> Vars,
1063 ArrayRef<ValueDecl *> Declarations,
1064 MappableExprComponentListsRef ComponentLists) {
1065 OMPMappableExprListSizeTy Sizes;
1066 Sizes.NumVars = Vars.size();
1067 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1068 Sizes.NumComponentLists = ComponentLists.size();
1069 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1071 // We need to allocate:
1072 // NumVars x Expr* - we have an original list expression for each clause list
1074 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1075 // with each component list.
1076 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1077 // number of lists for each unique declaration and the size of each component
1079 // NumComponents x MappableComponent - the total of all the components in all
1081 void *Mem = C.Allocate(
1082 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1083 OMPClauseMappableExprCommon::MappableComponent>(
1084 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1085 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1086 Sizes.NumComponents));
1088 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
1090 Clause->setVarRefs(Vars);
1091 Clause->setClauseInfo(Declarations, ComponentLists);
1095 OMPIsDevicePtrClause *
1096 OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1097 const OMPMappableExprListSizeTy &Sizes) {
1098 void *Mem = C.Allocate(
1099 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1100 OMPClauseMappableExprCommon::MappableComponent>(
1101 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1102 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1103 Sizes.NumComponents));
1104 return new (Mem) OMPIsDevicePtrClause(Sizes);
1107 //===----------------------------------------------------------------------===//
1108 // OpenMP clauses printing methods
1109 //===----------------------------------------------------------------------===//
1111 void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1113 if (Node->getNameModifier() != OMPD_unknown)
1114 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1115 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1119 void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1121 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1125 void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1126 OS << "num_threads(";
1127 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1131 void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1133 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1137 void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1139 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1143 void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
1145 Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
1149 void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1151 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1155 void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1157 << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
1161 void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1163 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, Node->getProcBindKind())
1167 void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1168 OS << "unified_address";
1171 void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1172 OMPUnifiedSharedMemoryClause *) {
1173 OS << "unified_shared_memory";
1176 void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1177 OS << "reverse_offload";
1180 void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1181 OMPDynamicAllocatorsClause *) {
1182 OS << "dynamic_allocators";
1185 void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1186 OMPAtomicDefaultMemOrderClause *Node) {
1187 OS << "atomic_default_mem_order("
1188 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1189 Node->getAtomicDefaultMemOrderKind())
1193 void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1195 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1196 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1197 Node->getFirstScheduleModifier());
1198 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1200 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1201 Node->getSecondScheduleModifier());
1205 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1206 if (auto *E = Node->getChunkSize()) {
1208 E->printPretty(OS, nullptr, Policy);
1213 void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1215 if (auto *Num = Node->getNumForLoops()) {
1217 Num->printPretty(OS, nullptr, Policy, 0);
1222 void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1226 void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1230 void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1234 void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1238 void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1240 void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1242 void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
1246 void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1250 void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1254 void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1258 void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1260 void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1262 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1266 void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1268 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1272 void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1273 OS << "thread_limit(";
1274 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1278 void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1280 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1284 void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1286 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1290 void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1292 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1296 void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1298 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1302 template<typename T>
1303 void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1304 for (typename T::varlist_iterator I = Node->varlist_begin(),
1305 E = Node->varlist_end();
1307 assert(*I && "Expected non-null Stmt");
1308 OS << (I == Node->varlist_begin() ? StartSym : ',');
1309 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1310 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1311 DRE->printPretty(OS, nullptr, Policy, 0);
1313 DRE->getDecl()->printQualifiedName(OS);
1315 (*I)->printPretty(OS, nullptr, Policy, 0);
1319 void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
1320 if (Node->varlist_empty())
1323 if (Expr *Allocator = Node->getAllocator()) {
1325 Allocator->printPretty(OS, nullptr, Policy, 0);
1327 VisitOMPClauseList(Node, ' ');
1329 VisitOMPClauseList(Node, '(');
1334 void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1335 if (!Node->varlist_empty()) {
1337 VisitOMPClauseList(Node, '(');
1342 void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1343 if (!Node->varlist_empty()) {
1344 OS << "firstprivate";
1345 VisitOMPClauseList(Node, '(');
1350 void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1351 if (!Node->varlist_empty()) {
1352 OS << "lastprivate";
1353 VisitOMPClauseList(Node, '(');
1358 void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1359 if (!Node->varlist_empty()) {
1361 VisitOMPClauseList(Node, '(');
1366 void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1367 if (!Node->varlist_empty()) {
1369 NestedNameSpecifier *QualifierLoc =
1370 Node->getQualifierLoc().getNestedNameSpecifier();
1371 OverloadedOperatorKind OOK =
1372 Node->getNameInfo().getName().getCXXOverloadedOperator();
1373 if (QualifierLoc == nullptr && OOK != OO_None) {
1374 // Print reduction identifier in C format
1375 OS << getOperatorSpelling(OOK);
1378 if (QualifierLoc != nullptr)
1379 QualifierLoc->print(OS, Policy);
1380 OS << Node->getNameInfo();
1383 VisitOMPClauseList(Node, ' ');
1388 void OMPClausePrinter::VisitOMPTaskReductionClause(
1389 OMPTaskReductionClause *Node) {
1390 if (!Node->varlist_empty()) {
1391 OS << "task_reduction(";
1392 NestedNameSpecifier *QualifierLoc =
1393 Node->getQualifierLoc().getNestedNameSpecifier();
1394 OverloadedOperatorKind OOK =
1395 Node->getNameInfo().getName().getCXXOverloadedOperator();
1396 if (QualifierLoc == nullptr && OOK != OO_None) {
1397 // Print reduction identifier in C format
1398 OS << getOperatorSpelling(OOK);
1401 if (QualifierLoc != nullptr)
1402 QualifierLoc->print(OS, Policy);
1403 OS << Node->getNameInfo();
1406 VisitOMPClauseList(Node, ' ');
1411 void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1412 if (!Node->varlist_empty()) {
1413 OS << "in_reduction(";
1414 NestedNameSpecifier *QualifierLoc =
1415 Node->getQualifierLoc().getNestedNameSpecifier();
1416 OverloadedOperatorKind OOK =
1417 Node->getNameInfo().getName().getCXXOverloadedOperator();
1418 if (QualifierLoc == nullptr && OOK != OO_None) {
1419 // Print reduction identifier in C format
1420 OS << getOperatorSpelling(OOK);
1423 if (QualifierLoc != nullptr)
1424 QualifierLoc->print(OS, Policy);
1425 OS << Node->getNameInfo();
1428 VisitOMPClauseList(Node, ' ');
1433 void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1434 if (!Node->varlist_empty()) {
1436 if (Node->getModifierLoc().isValid()) {
1438 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1440 VisitOMPClauseList(Node, '(');
1441 if (Node->getModifierLoc().isValid())
1443 if (Node->getStep() != nullptr) {
1445 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1451 void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1452 if (!Node->varlist_empty()) {
1454 VisitOMPClauseList(Node, '(');
1455 if (Node->getAlignment() != nullptr) {
1457 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1463 void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1464 if (!Node->varlist_empty()) {
1466 VisitOMPClauseList(Node, '(');
1471 void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1472 if (!Node->varlist_empty()) {
1473 OS << "copyprivate";
1474 VisitOMPClauseList(Node, '(');
1479 void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1480 if (!Node->varlist_empty()) {
1481 VisitOMPClauseList(Node, '(');
1486 void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1488 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1489 Node->getDependencyKind());
1490 if (!Node->varlist_empty()) {
1492 VisitOMPClauseList(Node, ' ');
1497 void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1498 if (!Node->varlist_empty()) {
1500 if (Node->getMapType() != OMPC_MAP_unknown) {
1501 for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1502 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1503 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1504 Node->getMapTypeModifier(I));
1505 if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1507 NestedNameSpecifier *MapperNNS =
1508 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1510 MapperNNS->print(OS, Policy);
1511 OS << Node->getMapperIdInfo() << ')';
1516 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1519 VisitOMPClauseList(Node, ' ');
1524 void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1525 if (!Node->varlist_empty()) {
1527 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1528 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1531 NestedNameSpecifier *MapperNNS =
1532 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1534 MapperNNS->print(OS, Policy);
1535 OS << MapperId << "):";
1536 VisitOMPClauseList(Node, ' ');
1538 VisitOMPClauseList(Node, '(');
1544 void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1545 if (!Node->varlist_empty()) {
1547 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1548 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1551 NestedNameSpecifier *MapperNNS =
1552 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1554 MapperNNS->print(OS, Policy);
1555 OS << MapperId << "):";
1556 VisitOMPClauseList(Node, ' ');
1558 VisitOMPClauseList(Node, '(');
1564 void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1565 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1566 OMPC_dist_schedule, Node->getDistScheduleKind());
1567 if (auto *E = Node->getChunkSize()) {
1569 E->printPretty(OS, nullptr, Policy);
1574 void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1575 OS << "defaultmap(";
1576 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1577 Node->getDefaultmapModifier());
1579 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1580 Node->getDefaultmapKind());
1584 void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1585 if (!Node->varlist_empty()) {
1586 OS << "use_device_ptr";
1587 VisitOMPClauseList(Node, '(');
1592 void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1593 if (!Node->varlist_empty()) {
1594 OS << "is_device_ptr";
1595 VisitOMPClauseList(Node, '(');