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/Attr.h"
16 #include "clang/AST/Decl.h"
17 #include "clang/AST/DeclOpenMP.h"
18 #include "clang/Basic/LLVM.h"
19 #include "clang/Basic/OpenMPKinds.h"
20 #include "llvm/ADT/SmallPtrSet.h"
21 #include "llvm/Support/Casting.h"
22 #include "llvm/Support/ErrorHandling.h"
26 using namespace clang;
30 OMPClause::child_range OMPClause::children() {
31 switch (getClauseKind()) {
34 #define OMP_CLAUSE_CLASS(Enum, Str, Class) \
36 return static_cast<Class *>(this)->children();
37 #include "llvm/Frontend/OpenMP/OMPKinds.def"
39 llvm_unreachable("unknown OMPClause");
42 OMPClause::child_range OMPClause::used_children() {
43 switch (getClauseKind()) {
44 #define OMP_CLAUSE_CLASS(Enum, Str, Class) \
46 return static_cast<Class *>(this)->used_children();
47 #include "llvm/Frontend/OpenMP/OMPKinds.def"
48 case OMPC_threadprivate:
50 case OMPC_device_type:
57 llvm_unreachable("unknown OMPClause");
60 OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
61 auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
62 return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr;
65 const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
66 switch (C->getClauseKind()) {
68 return static_cast<const OMPScheduleClause *>(C);
69 case OMPC_dist_schedule:
70 return static_cast<const OMPDistScheduleClause *>(C);
71 case OMPC_firstprivate:
72 return static_cast<const OMPFirstprivateClause *>(C);
73 case OMPC_lastprivate:
74 return static_cast<const OMPLastprivateClause *>(C);
76 return static_cast<const OMPReductionClause *>(C);
77 case OMPC_task_reduction:
78 return static_cast<const OMPTaskReductionClause *>(C);
79 case OMPC_in_reduction:
80 return static_cast<const OMPInReductionClause *>(C);
82 return static_cast<const OMPLinearClause *>(C);
84 return static_cast<const OMPIfClause *>(C);
85 case OMPC_num_threads:
86 return static_cast<const OMPNumThreadsClause *>(C);
88 return static_cast<const OMPNumTeamsClause *>(C);
89 case OMPC_thread_limit:
90 return static_cast<const OMPThreadLimitClause *>(C);
92 return static_cast<const OMPDeviceClause *>(C);
94 return static_cast<const OMPGrainsizeClause *>(C);
96 return static_cast<const OMPNumTasksClause *>(C);
98 return static_cast<const OMPFinalClause *>(C);
100 return static_cast<const OMPPriorityClause *>(C);
112 case OMPC_copyprivate:
117 case OMPC_threadprivate:
135 case OMPC_defaultmap:
140 case OMPC_use_device_ptr:
141 case OMPC_use_device_addr:
142 case OMPC_is_device_ptr:
143 case OMPC_unified_address:
144 case OMPC_unified_shared_memory:
145 case OMPC_reverse_offload:
146 case OMPC_dynamic_allocators:
147 case OMPC_atomic_default_mem_order:
148 case OMPC_device_type:
150 case OMPC_nontemporal:
156 case OMPC_uses_allocators:
166 OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
167 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
168 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
171 const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
172 switch (C->getClauseKind()) {
173 case OMPC_lastprivate:
174 return static_cast<const OMPLastprivateClause *>(C);
176 return static_cast<const OMPReductionClause *>(C);
177 case OMPC_task_reduction:
178 return static_cast<const OMPTaskReductionClause *>(C);
179 case OMPC_in_reduction:
180 return static_cast<const OMPInReductionClause *>(C);
182 return static_cast<const OMPLinearClause *>(C);
184 case OMPC_dist_schedule:
185 case OMPC_firstprivate:
190 case OMPC_num_threads:
200 case OMPC_copyprivate:
205 case OMPC_threadprivate:
223 case OMPC_thread_limit:
229 case OMPC_defaultmap:
234 case OMPC_use_device_ptr:
235 case OMPC_use_device_addr:
236 case OMPC_is_device_ptr:
237 case OMPC_unified_address:
238 case OMPC_unified_shared_memory:
239 case OMPC_reverse_offload:
240 case OMPC_dynamic_allocators:
241 case OMPC_atomic_default_mem_order:
242 case OMPC_device_type:
244 case OMPC_nontemporal:
250 case OMPC_uses_allocators:
260 /// Gets the address of the original, non-captured, expression used in the
261 /// clause as the preinitializer.
262 static Stmt **getAddrOfExprAsWritten(Stmt *S) {
265 if (auto *DS = dyn_cast<DeclStmt>(S)) {
266 assert(DS->isSingleDecl() && "Only single expression must be captured.");
267 if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
268 return OED->getInitAddress();
273 OMPClause::child_range OMPIfClause::used_children() {
274 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
275 return child_range(C, C + 1);
276 return child_range(&Condition, &Condition + 1);
279 OMPClause::child_range OMPGrainsizeClause::used_children() {
280 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
281 return child_range(C, C + 1);
282 return child_range(&Grainsize, &Grainsize + 1);
285 OMPClause::child_range OMPNumTasksClause::used_children() {
286 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
287 return child_range(C, C + 1);
288 return child_range(&NumTasks, &NumTasks + 1);
291 OMPClause::child_range OMPFinalClause::used_children() {
292 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
293 return child_range(C, C + 1);
294 return child_range(&Condition, &Condition + 1);
297 OMPClause::child_range OMPPriorityClause::used_children() {
298 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
299 return child_range(C, C + 1);
300 return child_range(&Priority, &Priority + 1);
303 OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
305 SourceLocation StartLoc,
306 SourceLocation LParenLoc,
307 SourceLocation EndLoc) {
308 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
310 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
311 for (unsigned I = 0; I < NumLoops; ++I) {
312 Clause->setLoopNumIterations(I, nullptr);
313 Clause->setLoopCounter(I, nullptr);
318 OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
320 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
321 auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
322 for (unsigned I = 0; I < NumLoops; ++I) {
323 Clause->setLoopNumIterations(I, nullptr);
324 Clause->setLoopCounter(I, nullptr);
329 void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
330 Expr *NumIterations) {
331 assert(NumLoop < NumberOfLoops && "out of loops number.");
332 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
335 ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
336 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
339 void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
340 assert(NumLoop < NumberOfLoops && "out of loops number.");
341 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
344 Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
345 assert(NumLoop < NumberOfLoops && "out of loops number.");
346 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
349 const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
350 assert(NumLoop < NumberOfLoops && "out of loops number.");
351 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
354 OMPUpdateClause *OMPUpdateClause::Create(const ASTContext &C,
355 SourceLocation StartLoc,
356 SourceLocation EndLoc) {
357 return new (C) OMPUpdateClause(StartLoc, EndLoc, /*IsExtended=*/false);
361 OMPUpdateClause::Create(const ASTContext &C, SourceLocation StartLoc,
362 SourceLocation LParenLoc, SourceLocation ArgumentLoc,
363 OpenMPDependClauseKind DK, SourceLocation EndLoc) {
365 C.Allocate(totalSizeToAlloc<SourceLocation, OpenMPDependClauseKind>(2, 1),
366 alignof(OMPUpdateClause));
368 new (Mem) OMPUpdateClause(StartLoc, EndLoc, /*IsExtended=*/true);
369 Clause->setLParenLoc(LParenLoc);
370 Clause->setArgumentLoc(ArgumentLoc);
371 Clause->setDependencyKind(DK);
375 OMPUpdateClause *OMPUpdateClause::CreateEmpty(const ASTContext &C,
378 return new (C) OMPUpdateClause(/*IsExtended=*/false);
380 C.Allocate(totalSizeToAlloc<SourceLocation, OpenMPDependClauseKind>(2, 1),
381 alignof(OMPUpdateClause));
382 auto *Clause = new (Mem) OMPUpdateClause(/*IsExtended=*/true);
383 Clause->IsExtended = true;
387 void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
388 assert(VL.size() == varlist_size() &&
389 "Number of private copies is not the same as the preallocated buffer");
390 std::copy(VL.begin(), VL.end(), varlist_end());
394 OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
395 SourceLocation LParenLoc, SourceLocation EndLoc,
396 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
397 // Allocate space for private variables and initializer expressions.
398 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
399 OMPPrivateClause *Clause =
400 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
401 Clause->setVarRefs(VL);
402 Clause->setPrivateCopies(PrivateVL);
406 OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
408 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
409 return new (Mem) OMPPrivateClause(N);
412 void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
413 assert(VL.size() == varlist_size() &&
414 "Number of private copies is not the same as the preallocated buffer");
415 std::copy(VL.begin(), VL.end(), varlist_end());
418 void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
419 assert(VL.size() == varlist_size() &&
420 "Number of inits is not the same as the preallocated buffer");
421 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
424 OMPFirstprivateClause *
425 OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
426 SourceLocation LParenLoc, SourceLocation EndLoc,
427 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
428 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
429 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
430 OMPFirstprivateClause *Clause =
431 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
432 Clause->setVarRefs(VL);
433 Clause->setPrivateCopies(PrivateVL);
434 Clause->setInits(InitVL);
435 Clause->setPreInitStmt(PreInit);
439 OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
441 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
442 return new (Mem) OMPFirstprivateClause(N);
445 void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
446 assert(PrivateCopies.size() == varlist_size() &&
447 "Number of private copies is not the same as the preallocated buffer");
448 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
451 void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
452 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
453 "not the same as the "
454 "preallocated buffer");
455 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
458 void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
459 assert(DstExprs.size() == varlist_size() && "Number of destination "
460 "expressions is not the same as "
461 "the preallocated buffer");
462 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
465 void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
466 assert(AssignmentOps.size() == varlist_size() &&
467 "Number of assignment expressions is not the same as the preallocated "
469 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
470 getDestinationExprs().end());
473 OMPLastprivateClause *OMPLastprivateClause::Create(
474 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
475 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
476 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
477 OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
478 SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate) {
479 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
480 OMPLastprivateClause *Clause = new (Mem) OMPLastprivateClause(
481 StartLoc, LParenLoc, EndLoc, LPKind, LPKindLoc, ColonLoc, VL.size());
482 Clause->setVarRefs(VL);
483 Clause->setSourceExprs(SrcExprs);
484 Clause->setDestinationExprs(DstExprs);
485 Clause->setAssignmentOps(AssignmentOps);
486 Clause->setPreInitStmt(PreInit);
487 Clause->setPostUpdateExpr(PostUpdate);
491 OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
493 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
494 return new (Mem) OMPLastprivateClause(N);
497 OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
498 SourceLocation StartLoc,
499 SourceLocation LParenLoc,
500 SourceLocation EndLoc,
501 ArrayRef<Expr *> VL) {
502 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
503 OMPSharedClause *Clause =
504 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
505 Clause->setVarRefs(VL);
509 OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
510 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
511 return new (Mem) OMPSharedClause(N);
514 void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
515 assert(PL.size() == varlist_size() &&
516 "Number of privates is not the same as the preallocated buffer");
517 std::copy(PL.begin(), PL.end(), varlist_end());
520 void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
521 assert(IL.size() == varlist_size() &&
522 "Number of inits is not the same as the preallocated buffer");
523 std::copy(IL.begin(), IL.end(), getPrivates().end());
526 void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
527 assert(UL.size() == varlist_size() &&
528 "Number of updates is not the same as the preallocated buffer");
529 std::copy(UL.begin(), UL.end(), getInits().end());
532 void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
533 assert(FL.size() == varlist_size() &&
534 "Number of final updates is not the same as the preallocated buffer");
535 std::copy(FL.begin(), FL.end(), getUpdates().end());
538 void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) {
540 UE.size() == varlist_size() + 1 &&
541 "Number of used expressions is not the same as the preallocated buffer");
542 std::copy(UE.begin(), UE.end(), getFinals().end() + 2);
545 OMPLinearClause *OMPLinearClause::Create(
546 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
547 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
548 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
549 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
550 Stmt *PreInit, Expr *PostUpdate) {
551 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
552 // (Step and CalcStep), list of used expression + step.
554 C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1));
555 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
556 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
557 Clause->setVarRefs(VL);
558 Clause->setPrivates(PL);
559 Clause->setInits(IL);
560 // Fill update and final expressions with zeroes, they are provided later,
561 // after the directive construction.
562 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
564 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
566 std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(),
568 Clause->setStep(Step);
569 Clause->setCalcStep(CalcStep);
570 Clause->setPreInitStmt(PreInit);
571 Clause->setPostUpdateExpr(PostUpdate);
575 OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
577 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
578 // (Step and CalcStep), list of used expression + step.
579 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars +1));
580 return new (Mem) OMPLinearClause(NumVars);
583 OMPClause::child_range OMPLinearClause::used_children() {
584 // Range includes only non-nullptr elements.
586 reinterpret_cast<Stmt **>(getUsedExprs().begin()),
587 reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr)));
591 OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
592 SourceLocation LParenLoc, SourceLocation ColonLoc,
593 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
594 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
595 OMPAlignedClause *Clause = new (Mem)
596 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
597 Clause->setVarRefs(VL);
598 Clause->setAlignment(A);
602 OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
604 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
605 return new (Mem) OMPAlignedClause(NumVars);
608 void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
609 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
610 "not the same as the "
611 "preallocated buffer");
612 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
615 void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
616 assert(DstExprs.size() == varlist_size() && "Number of destination "
617 "expressions is not the same as "
618 "the preallocated buffer");
619 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
622 void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
623 assert(AssignmentOps.size() == varlist_size() &&
624 "Number of assignment expressions is not the same as the preallocated "
626 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
627 getDestinationExprs().end());
630 OMPCopyinClause *OMPCopyinClause::Create(
631 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
632 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
633 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
634 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
635 OMPCopyinClause *Clause =
636 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
637 Clause->setVarRefs(VL);
638 Clause->setSourceExprs(SrcExprs);
639 Clause->setDestinationExprs(DstExprs);
640 Clause->setAssignmentOps(AssignmentOps);
644 OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
645 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
646 return new (Mem) OMPCopyinClause(N);
649 void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
650 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
651 "not the same as the "
652 "preallocated buffer");
653 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
656 void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
657 assert(DstExprs.size() == varlist_size() && "Number of destination "
658 "expressions is not the same as "
659 "the preallocated buffer");
660 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
663 void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
664 assert(AssignmentOps.size() == varlist_size() &&
665 "Number of assignment expressions is not the same as the preallocated "
667 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
668 getDestinationExprs().end());
671 OMPCopyprivateClause *OMPCopyprivateClause::Create(
672 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
673 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
674 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
675 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
676 OMPCopyprivateClause *Clause =
677 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
678 Clause->setVarRefs(VL);
679 Clause->setSourceExprs(SrcExprs);
680 Clause->setDestinationExprs(DstExprs);
681 Clause->setAssignmentOps(AssignmentOps);
685 OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
687 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
688 return new (Mem) OMPCopyprivateClause(N);
691 void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
692 assert(Privates.size() == varlist_size() &&
693 "Number of private copies is not the same as the preallocated buffer");
694 std::copy(Privates.begin(), Privates.end(), varlist_end());
697 void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
699 LHSExprs.size() == varlist_size() &&
700 "Number of LHS expressions is not the same as the preallocated buffer");
701 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
704 void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
706 RHSExprs.size() == varlist_size() &&
707 "Number of RHS expressions is not the same as the preallocated buffer");
708 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
711 void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
712 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
713 "expressions is not the same "
714 "as the preallocated buffer");
715 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
718 void OMPReductionClause::setInscanCopyOps(ArrayRef<Expr *> Ops) {
719 assert(Modifier == OMPC_REDUCTION_inscan && "Expected inscan reduction.");
720 assert(Ops.size() == varlist_size() && "Number of copy "
721 "expressions is not the same "
722 "as the preallocated buffer");
723 llvm::copy(Ops, getReductionOps().end());
726 void OMPReductionClause::setInscanCopyArrayTemps(
727 ArrayRef<Expr *> CopyArrayTemps) {
728 assert(Modifier == OMPC_REDUCTION_inscan && "Expected inscan reduction.");
729 assert(CopyArrayTemps.size() == varlist_size() &&
730 "Number of copy temp expressions is not the same as the preallocated "
732 llvm::copy(CopyArrayTemps, getInscanCopyOps().end());
735 void OMPReductionClause::setInscanCopyArrayElems(
736 ArrayRef<Expr *> CopyArrayElems) {
737 assert(Modifier == OMPC_REDUCTION_inscan && "Expected inscan reduction.");
738 assert(CopyArrayElems.size() == varlist_size() &&
739 "Number of copy temp expressions is not the same as the preallocated "
741 llvm::copy(CopyArrayElems, getInscanCopyArrayTemps().end());
744 OMPReductionClause *OMPReductionClause::Create(
745 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
746 SourceLocation ModifierLoc, SourceLocation EndLoc, SourceLocation ColonLoc,
747 OpenMPReductionClauseModifier Modifier, ArrayRef<Expr *> VL,
748 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
749 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
750 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
751 ArrayRef<Expr *> CopyOps, ArrayRef<Expr *> CopyArrayTemps,
752 ArrayRef<Expr *> CopyArrayElems, Stmt *PreInit, Expr *PostUpdate) {
753 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(
754 (Modifier == OMPC_REDUCTION_inscan ? 8 : 5) * VL.size()));
755 auto *Clause = new (Mem)
756 OMPReductionClause(StartLoc, LParenLoc, ModifierLoc, EndLoc, ColonLoc,
757 Modifier, VL.size(), QualifierLoc, NameInfo);
758 Clause->setVarRefs(VL);
759 Clause->setPrivates(Privates);
760 Clause->setLHSExprs(LHSExprs);
761 Clause->setRHSExprs(RHSExprs);
762 Clause->setReductionOps(ReductionOps);
763 Clause->setPreInitStmt(PreInit);
764 Clause->setPostUpdateExpr(PostUpdate);
765 if (Modifier == OMPC_REDUCTION_inscan) {
766 Clause->setInscanCopyOps(CopyOps);
767 Clause->setInscanCopyArrayTemps(CopyArrayTemps);
768 Clause->setInscanCopyArrayElems(CopyArrayElems);
770 assert(CopyOps.empty() &&
771 "copy operations are expected in inscan reductions only.");
772 assert(CopyArrayTemps.empty() &&
773 "copy array temps are expected in inscan reductions only.");
774 assert(CopyArrayElems.empty() &&
775 "copy array temps are expected in inscan reductions only.");
781 OMPReductionClause::CreateEmpty(const ASTContext &C, unsigned N,
782 OpenMPReductionClauseModifier Modifier) {
783 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(
784 (Modifier == OMPC_REDUCTION_inscan ? 8 : 5) * N));
785 auto *Clause = new (Mem) OMPReductionClause(N);
786 Clause->setModifier(Modifier);
790 void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
791 assert(Privates.size() == varlist_size() &&
792 "Number of private copies is not the same as the preallocated buffer");
793 std::copy(Privates.begin(), Privates.end(), varlist_end());
796 void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
798 LHSExprs.size() == varlist_size() &&
799 "Number of LHS expressions is not the same as the preallocated buffer");
800 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
803 void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
805 RHSExprs.size() == varlist_size() &&
806 "Number of RHS expressions is not the same as the preallocated buffer");
807 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
810 void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
811 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
812 "expressions is not the same "
813 "as the preallocated buffer");
814 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
817 OMPTaskReductionClause *OMPTaskReductionClause::Create(
818 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
819 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
820 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
821 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
822 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
824 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
825 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
826 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
827 Clause->setVarRefs(VL);
828 Clause->setPrivates(Privates);
829 Clause->setLHSExprs(LHSExprs);
830 Clause->setRHSExprs(RHSExprs);
831 Clause->setReductionOps(ReductionOps);
832 Clause->setPreInitStmt(PreInit);
833 Clause->setPostUpdateExpr(PostUpdate);
837 OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
839 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
840 return new (Mem) OMPTaskReductionClause(N);
843 void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
844 assert(Privates.size() == varlist_size() &&
845 "Number of private copies is not the same as the preallocated buffer");
846 std::copy(Privates.begin(), Privates.end(), varlist_end());
849 void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
851 LHSExprs.size() == varlist_size() &&
852 "Number of LHS expressions is not the same as the preallocated buffer");
853 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
856 void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
858 RHSExprs.size() == varlist_size() &&
859 "Number of RHS expressions is not the same as the preallocated buffer");
860 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
863 void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
864 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
865 "expressions is not the same "
866 "as the preallocated buffer");
867 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
870 void OMPInReductionClause::setTaskgroupDescriptors(
871 ArrayRef<Expr *> TaskgroupDescriptors) {
872 assert(TaskgroupDescriptors.size() == varlist_size() &&
873 "Number of in reduction descriptors is not the same as the "
874 "preallocated buffer");
875 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
876 getReductionOps().end());
879 OMPInReductionClause *OMPInReductionClause::Create(
880 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
881 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
882 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
883 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
884 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
885 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
886 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
887 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
888 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
889 Clause->setVarRefs(VL);
890 Clause->setPrivates(Privates);
891 Clause->setLHSExprs(LHSExprs);
892 Clause->setRHSExprs(RHSExprs);
893 Clause->setReductionOps(ReductionOps);
894 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
895 Clause->setPreInitStmt(PreInit);
896 Clause->setPostUpdateExpr(PostUpdate);
900 OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
902 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
903 return new (Mem) OMPInReductionClause(N);
907 OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc,
908 SourceLocation LParenLoc, Expr *Allocator,
909 SourceLocation ColonLoc, SourceLocation EndLoc,
910 ArrayRef<Expr *> VL) {
911 // Allocate space for private variables and initializer expressions.
912 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
913 auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
914 ColonLoc, EndLoc, VL.size());
915 Clause->setVarRefs(VL);
919 OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
921 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
922 return new (Mem) OMPAllocateClause(N);
925 OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
926 SourceLocation StartLoc,
927 SourceLocation LParenLoc,
928 SourceLocation EndLoc,
929 ArrayRef<Expr *> VL) {
930 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
931 OMPFlushClause *Clause =
932 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
933 Clause->setVarRefs(VL);
937 OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
938 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
939 return new (Mem) OMPFlushClause(N);
942 OMPDepobjClause *OMPDepobjClause::Create(const ASTContext &C,
943 SourceLocation StartLoc,
944 SourceLocation LParenLoc,
945 SourceLocation RParenLoc,
947 auto *Clause = new (C) OMPDepobjClause(StartLoc, LParenLoc, RParenLoc);
948 Clause->setDepobj(Depobj);
952 OMPDepobjClause *OMPDepobjClause::CreateEmpty(const ASTContext &C) {
953 return new (C) OMPDepobjClause();
957 OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
958 SourceLocation LParenLoc, SourceLocation EndLoc,
959 Expr *DepModifier, OpenMPDependClauseKind DepKind,
960 SourceLocation DepLoc, SourceLocation ColonLoc,
961 ArrayRef<Expr *> VL, unsigned NumLoops) {
962 void *Mem = C.Allocate(
963 totalSizeToAlloc<Expr *>(VL.size() + /*depend-modifier*/ 1 + NumLoops),
964 alignof(OMPDependClause));
965 OMPDependClause *Clause = new (Mem)
966 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
967 Clause->setVarRefs(VL);
968 Clause->setDependencyKind(DepKind);
969 Clause->setDependencyLoc(DepLoc);
970 Clause->setColonLoc(ColonLoc);
971 Clause->setModifier(DepModifier);
972 for (unsigned I = 0 ; I < NumLoops; ++I)
973 Clause->setLoopData(I, nullptr);
977 OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
980 C.Allocate(totalSizeToAlloc<Expr *>(N + /*depend-modifier*/ 1 + NumLoops),
981 alignof(OMPDependClause));
982 return new (Mem) OMPDependClause(N, NumLoops);
985 void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
986 assert((getDependencyKind() == OMPC_DEPEND_sink ||
987 getDependencyKind() == OMPC_DEPEND_source) &&
988 NumLoop < NumLoops &&
989 "Expected sink or source depend + loop index must be less number of "
991 auto *It = std::next(getVarRefs().end(), NumLoop + 1);
995 Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
996 assert((getDependencyKind() == OMPC_DEPEND_sink ||
997 getDependencyKind() == OMPC_DEPEND_source) &&
998 NumLoop < NumLoops &&
999 "Expected sink or source depend + loop index must be less number of "
1001 auto *It = std::next(getVarRefs().end(), NumLoop + 1);
1005 const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
1006 assert((getDependencyKind() == OMPC_DEPEND_sink ||
1007 getDependencyKind() == OMPC_DEPEND_source) &&
1008 NumLoop < NumLoops &&
1009 "Expected sink or source depend + loop index must be less number of "
1011 const auto *It = std::next(getVarRefs().end(), NumLoop + 1);
1015 void OMPDependClause::setModifier(Expr *DepModifier) {
1016 *getVarRefs().end() = DepModifier;
1018 Expr *OMPDependClause::getModifier() { return *getVarRefs().end(); }
1020 unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
1021 MappableExprComponentListsRef ComponentLists) {
1022 unsigned TotalNum = 0u;
1023 for (auto &C : ComponentLists)
1024 TotalNum += C.size();
1028 unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
1029 ArrayRef<const ValueDecl *> Declarations) {
1030 unsigned TotalNum = 0u;
1031 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
1032 for (const ValueDecl *D : Declarations) {
1033 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
1034 if (Cache.count(VD))
1042 OMPMapClause *OMPMapClause::Create(
1043 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1044 ArrayRef<ValueDecl *> Declarations,
1045 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1046 ArrayRef<OpenMPMapModifierKind> MapModifiers,
1047 ArrayRef<SourceLocation> MapModifiersLoc,
1048 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
1049 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
1050 OMPMappableExprListSizeTy Sizes;
1051 Sizes.NumVars = Vars.size();
1052 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1053 Sizes.NumComponentLists = ComponentLists.size();
1054 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1056 // We need to allocate:
1057 // 2 x NumVars x Expr* - we have an original list expression and an associated
1058 // user-defined mapper for each clause list entry.
1059 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1060 // with each component list.
1061 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1062 // number of lists for each unique declaration and the size of each component
1064 // NumComponents x MappableComponent - the total of all the components in all
1066 void *Mem = C.Allocate(
1067 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1068 OMPClauseMappableExprCommon::MappableComponent>(
1069 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1070 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1071 Sizes.NumComponents));
1072 OMPMapClause *Clause = new (Mem)
1073 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
1074 Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
1076 Clause->setVarRefs(Vars);
1077 Clause->setUDMapperRefs(UDMapperRefs);
1078 Clause->setClauseInfo(Declarations, ComponentLists);
1079 Clause->setMapType(Type);
1080 Clause->setMapLoc(TypeLoc);
1085 OMPMapClause::CreateEmpty(const ASTContext &C,
1086 const OMPMappableExprListSizeTy &Sizes) {
1087 void *Mem = C.Allocate(
1088 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1089 OMPClauseMappableExprCommon::MappableComponent>(
1090 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1091 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1092 Sizes.NumComponents));
1093 return new (Mem) OMPMapClause(Sizes);
1096 OMPToClause *OMPToClause::Create(
1097 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1098 ArrayRef<ValueDecl *> Declarations,
1099 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1100 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
1101 OMPMappableExprListSizeTy Sizes;
1102 Sizes.NumVars = Vars.size();
1103 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1104 Sizes.NumComponentLists = ComponentLists.size();
1105 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1107 // We need to allocate:
1108 // 2 x NumVars x Expr* - we have an original list expression and an associated
1109 // user-defined mapper for each clause list entry.
1110 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1111 // with each component list.
1112 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1113 // number of lists for each unique declaration and the size of each component
1115 // NumComponents x MappableComponent - the total of all the components in all
1117 void *Mem = C.Allocate(
1118 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1119 OMPClauseMappableExprCommon::MappableComponent>(
1120 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1121 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1122 Sizes.NumComponents));
1124 auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
1126 Clause->setVarRefs(Vars);
1127 Clause->setUDMapperRefs(UDMapperRefs);
1128 Clause->setClauseInfo(Declarations, ComponentLists);
1132 OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
1133 const OMPMappableExprListSizeTy &Sizes) {
1134 void *Mem = C.Allocate(
1135 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1136 OMPClauseMappableExprCommon::MappableComponent>(
1137 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1138 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1139 Sizes.NumComponents));
1140 return new (Mem) OMPToClause(Sizes);
1143 OMPFromClause *OMPFromClause::Create(
1144 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1145 ArrayRef<ValueDecl *> Declarations,
1146 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1147 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
1148 OMPMappableExprListSizeTy Sizes;
1149 Sizes.NumVars = Vars.size();
1150 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1151 Sizes.NumComponentLists = ComponentLists.size();
1152 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1154 // We need to allocate:
1155 // 2 x NumVars x Expr* - we have an original list expression and an associated
1156 // user-defined mapper for each clause list entry.
1157 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1158 // with each component list.
1159 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1160 // number of lists for each unique declaration and the size of each component
1162 // NumComponents x MappableComponent - the total of all the components in all
1164 void *Mem = C.Allocate(
1165 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1166 OMPClauseMappableExprCommon::MappableComponent>(
1167 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1168 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1169 Sizes.NumComponents));
1172 new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
1174 Clause->setVarRefs(Vars);
1175 Clause->setUDMapperRefs(UDMapperRefs);
1176 Clause->setClauseInfo(Declarations, ComponentLists);
1181 OMPFromClause::CreateEmpty(const ASTContext &C,
1182 const OMPMappableExprListSizeTy &Sizes) {
1183 void *Mem = C.Allocate(
1184 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1185 OMPClauseMappableExprCommon::MappableComponent>(
1186 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1187 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1188 Sizes.NumComponents));
1189 return new (Mem) OMPFromClause(Sizes);
1192 void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1193 assert(VL.size() == varlist_size() &&
1194 "Number of private copies is not the same as the preallocated buffer");
1195 std::copy(VL.begin(), VL.end(), varlist_end());
1198 void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
1199 assert(VL.size() == varlist_size() &&
1200 "Number of inits is not the same as the preallocated buffer");
1201 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1204 OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
1205 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1206 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
1207 ArrayRef<ValueDecl *> Declarations,
1208 MappableExprComponentListsRef ComponentLists) {
1209 OMPMappableExprListSizeTy Sizes;
1210 Sizes.NumVars = Vars.size();
1211 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1212 Sizes.NumComponentLists = ComponentLists.size();
1213 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1215 // We need to allocate:
1216 // NumVars x Expr* - we have an original list expression for each clause
1218 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1219 // with each component list.
1220 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1221 // number of lists for each unique declaration and the size of each component
1223 // NumComponents x MappableComponent - the total of all the components in all
1225 void *Mem = C.Allocate(
1226 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1227 OMPClauseMappableExprCommon::MappableComponent>(
1228 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1229 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1230 Sizes.NumComponents));
1232 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
1234 Clause->setVarRefs(Vars);
1235 Clause->setPrivateCopies(PrivateVars);
1236 Clause->setInits(Inits);
1237 Clause->setClauseInfo(Declarations, ComponentLists);
1241 OMPUseDevicePtrClause *
1242 OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
1243 const OMPMappableExprListSizeTy &Sizes) {
1244 void *Mem = C.Allocate(
1245 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1246 OMPClauseMappableExprCommon::MappableComponent>(
1247 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1248 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1249 Sizes.NumComponents));
1250 return new (Mem) OMPUseDevicePtrClause(Sizes);
1253 OMPUseDeviceAddrClause *
1254 OMPUseDeviceAddrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
1255 ArrayRef<Expr *> Vars,
1256 ArrayRef<ValueDecl *> Declarations,
1257 MappableExprComponentListsRef ComponentLists) {
1258 OMPMappableExprListSizeTy Sizes;
1259 Sizes.NumVars = Vars.size();
1260 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1261 Sizes.NumComponentLists = ComponentLists.size();
1262 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1264 // We need to allocate:
1265 // 3 x NumVars x Expr* - we have an original list expression for each clause
1266 // list entry and an equal number of private copies and inits.
1267 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1268 // with each component list.
1269 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1270 // number of lists for each unique declaration and the size of each component
1272 // NumComponents x MappableComponent - the total of all the components in all
1274 void *Mem = C.Allocate(
1275 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1276 OMPClauseMappableExprCommon::MappableComponent>(
1277 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1278 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1279 Sizes.NumComponents));
1281 auto *Clause = new (Mem) OMPUseDeviceAddrClause(Locs, Sizes);
1283 Clause->setVarRefs(Vars);
1284 Clause->setClauseInfo(Declarations, ComponentLists);
1288 OMPUseDeviceAddrClause *
1289 OMPUseDeviceAddrClause::CreateEmpty(const ASTContext &C,
1290 const OMPMappableExprListSizeTy &Sizes) {
1291 void *Mem = C.Allocate(
1292 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1293 OMPClauseMappableExprCommon::MappableComponent>(
1294 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1295 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1296 Sizes.NumComponents));
1297 return new (Mem) OMPUseDeviceAddrClause(Sizes);
1300 OMPIsDevicePtrClause *
1301 OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
1302 ArrayRef<Expr *> Vars,
1303 ArrayRef<ValueDecl *> Declarations,
1304 MappableExprComponentListsRef ComponentLists) {
1305 OMPMappableExprListSizeTy Sizes;
1306 Sizes.NumVars = Vars.size();
1307 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1308 Sizes.NumComponentLists = ComponentLists.size();
1309 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1311 // We need to allocate:
1312 // NumVars x Expr* - we have an original list expression for each clause list
1314 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1315 // with each component list.
1316 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1317 // number of lists for each unique declaration and the size of each component
1319 // NumComponents x MappableComponent - the total of all the components in all
1321 void *Mem = C.Allocate(
1322 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1323 OMPClauseMappableExprCommon::MappableComponent>(
1324 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1325 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1326 Sizes.NumComponents));
1328 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
1330 Clause->setVarRefs(Vars);
1331 Clause->setClauseInfo(Declarations, ComponentLists);
1335 OMPIsDevicePtrClause *
1336 OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1337 const OMPMappableExprListSizeTy &Sizes) {
1338 void *Mem = C.Allocate(
1339 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1340 OMPClauseMappableExprCommon::MappableComponent>(
1341 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1342 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1343 Sizes.NumComponents));
1344 return new (Mem) OMPIsDevicePtrClause(Sizes);
1347 OMPNontemporalClause *OMPNontemporalClause::Create(const ASTContext &C,
1348 SourceLocation StartLoc,
1349 SourceLocation LParenLoc,
1350 SourceLocation EndLoc,
1351 ArrayRef<Expr *> VL) {
1352 // Allocate space for nontemporal variables + private references.
1353 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
1355 new (Mem) OMPNontemporalClause(StartLoc, LParenLoc, EndLoc, VL.size());
1356 Clause->setVarRefs(VL);
1360 OMPNontemporalClause *OMPNontemporalClause::CreateEmpty(const ASTContext &C,
1362 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
1363 return new (Mem) OMPNontemporalClause(N);
1366 void OMPNontemporalClause::setPrivateRefs(ArrayRef<Expr *> VL) {
1367 assert(VL.size() == varlist_size() && "Number of private references is not "
1368 "the same as the preallocated buffer");
1369 std::copy(VL.begin(), VL.end(), varlist_end());
1372 OMPInclusiveClause *OMPInclusiveClause::Create(const ASTContext &C,
1373 SourceLocation StartLoc,
1374 SourceLocation LParenLoc,
1375 SourceLocation EndLoc,
1376 ArrayRef<Expr *> VL) {
1377 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
1379 new (Mem) OMPInclusiveClause(StartLoc, LParenLoc, EndLoc, VL.size());
1380 Clause->setVarRefs(VL);
1384 OMPInclusiveClause *OMPInclusiveClause::CreateEmpty(const ASTContext &C,
1386 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
1387 return new (Mem) OMPInclusiveClause(N);
1390 OMPExclusiveClause *OMPExclusiveClause::Create(const ASTContext &C,
1391 SourceLocation StartLoc,
1392 SourceLocation LParenLoc,
1393 SourceLocation EndLoc,
1394 ArrayRef<Expr *> VL) {
1395 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
1397 new (Mem) OMPExclusiveClause(StartLoc, LParenLoc, EndLoc, VL.size());
1398 Clause->setVarRefs(VL);
1402 OMPExclusiveClause *OMPExclusiveClause::CreateEmpty(const ASTContext &C,
1404 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
1405 return new (Mem) OMPExclusiveClause(N);
1408 void OMPUsesAllocatorsClause::setAllocatorsData(
1409 ArrayRef<OMPUsesAllocatorsClause::Data> Data) {
1410 assert(Data.size() == NumOfAllocators &&
1411 "Size of allocators data is not the same as the preallocated buffer.");
1412 for (unsigned I = 0, E = Data.size(); I < E; ++I) {
1413 const OMPUsesAllocatorsClause::Data &D = Data[I];
1414 getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) +
1415 static_cast<int>(ExprOffsets::Allocator)] =
1417 getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) +
1419 ExprOffsets::AllocatorTraits)] =
1422 SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) +
1423 static_cast<int>(ParenLocsOffsets::LParen)] =
1426 SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) +
1427 static_cast<int>(ParenLocsOffsets::RParen)] =
1432 OMPUsesAllocatorsClause::Data
1433 OMPUsesAllocatorsClause::getAllocatorData(unsigned I) const {
1434 OMPUsesAllocatorsClause::Data Data;
1436 getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) +
1437 static_cast<int>(ExprOffsets::Allocator)];
1438 Data.AllocatorTraits =
1439 getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) +
1441 ExprOffsets::AllocatorTraits)];
1442 Data.LParenLoc = getTrailingObjects<
1443 SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) +
1444 static_cast<int>(ParenLocsOffsets::LParen)];
1445 Data.RParenLoc = getTrailingObjects<
1446 SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) +
1447 static_cast<int>(ParenLocsOffsets::RParen)];
1451 OMPUsesAllocatorsClause *
1452 OMPUsesAllocatorsClause::Create(const ASTContext &C, SourceLocation StartLoc,
1453 SourceLocation LParenLoc, SourceLocation EndLoc,
1454 ArrayRef<OMPUsesAllocatorsClause::Data> Data) {
1455 void *Mem = C.Allocate(totalSizeToAlloc<Expr *, SourceLocation>(
1456 static_cast<int>(ExprOffsets::Total) * Data.size(),
1457 static_cast<int>(ParenLocsOffsets::Total) * Data.size()));
1458 auto *Clause = new (Mem)
1459 OMPUsesAllocatorsClause(StartLoc, LParenLoc, EndLoc, Data.size());
1460 Clause->setAllocatorsData(Data);
1464 OMPUsesAllocatorsClause *
1465 OMPUsesAllocatorsClause::CreateEmpty(const ASTContext &C, unsigned N) {
1466 void *Mem = C.Allocate(totalSizeToAlloc<Expr *, SourceLocation>(
1467 static_cast<int>(ExprOffsets::Total) * N,
1468 static_cast<int>(ParenLocsOffsets::Total) * N));
1469 return new (Mem) OMPUsesAllocatorsClause(N);
1473 OMPAffinityClause::Create(const ASTContext &C, SourceLocation StartLoc,
1474 SourceLocation LParenLoc, SourceLocation ColonLoc,
1475 SourceLocation EndLoc, Expr *Modifier,
1476 ArrayRef<Expr *> Locators) {
1477 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(Locators.size() + 1));
1478 auto *Clause = new (Mem)
1479 OMPAffinityClause(StartLoc, LParenLoc, ColonLoc, EndLoc, Locators.size());
1480 Clause->setModifier(Modifier);
1481 Clause->setVarRefs(Locators);
1485 OMPAffinityClause *OMPAffinityClause::CreateEmpty(const ASTContext &C,
1487 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + 1));
1488 return new (Mem) OMPAffinityClause(N);
1491 //===----------------------------------------------------------------------===//
1492 // OpenMP clauses printing methods
1493 //===----------------------------------------------------------------------===//
1495 void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1497 if (Node->getNameModifier() != OMPD_unknown)
1498 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1499 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1503 void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1505 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1509 void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1510 OS << "num_threads(";
1511 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1515 void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1517 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1521 void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1523 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1527 void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
1529 Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
1533 void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1535 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1539 void OMPClausePrinter::VisitOMPDetachClause(OMPDetachClause *Node) {
1541 Node->getEventHandler()->printPretty(OS, nullptr, Policy, 0);
1545 void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1547 << getOpenMPSimpleClauseTypeName(OMPC_default,
1548 unsigned(Node->getDefaultKind()))
1552 void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1554 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind,
1555 unsigned(Node->getProcBindKind()))
1559 void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1560 OS << "unified_address";
1563 void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1564 OMPUnifiedSharedMemoryClause *) {
1565 OS << "unified_shared_memory";
1568 void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1569 OS << "reverse_offload";
1572 void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1573 OMPDynamicAllocatorsClause *) {
1574 OS << "dynamic_allocators";
1577 void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1578 OMPAtomicDefaultMemOrderClause *Node) {
1579 OS << "atomic_default_mem_order("
1580 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1581 Node->getAtomicDefaultMemOrderKind())
1585 void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1587 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1588 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1589 Node->getFirstScheduleModifier());
1590 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1592 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1593 Node->getSecondScheduleModifier());
1597 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1598 if (auto *E = Node->getChunkSize()) {
1600 E->printPretty(OS, nullptr, Policy);
1605 void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1607 if (auto *Num = Node->getNumForLoops()) {
1609 Num->printPretty(OS, nullptr, Policy, 0);
1614 void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1618 void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1622 void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1626 void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1630 void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1632 void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1634 void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *Node) {
1636 if (Node->isExtended()) {
1638 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1639 Node->getDependencyKind());
1644 void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1648 void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1652 void OMPClausePrinter::VisitOMPAcqRelClause(OMPAcqRelClause *) {
1656 void OMPClausePrinter::VisitOMPAcquireClause(OMPAcquireClause *) {
1660 void OMPClausePrinter::VisitOMPReleaseClause(OMPReleaseClause *) {
1664 void OMPClausePrinter::VisitOMPRelaxedClause(OMPRelaxedClause *) {
1668 void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1672 void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1674 void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1676 OpenMPDeviceClauseModifier Modifier = Node->getModifier();
1677 if (Modifier != OMPC_DEVICE_unknown) {
1678 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), Modifier)
1681 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1685 void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1687 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1691 void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1692 OS << "thread_limit(";
1693 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1697 void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1699 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1703 void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1705 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1709 void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1711 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1715 void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1717 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1721 void OMPClausePrinter::VisitOMPDestroyClause(OMPDestroyClause *) {
1725 template<typename T>
1726 void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1727 for (typename T::varlist_iterator I = Node->varlist_begin(),
1728 E = Node->varlist_end();
1730 assert(*I && "Expected non-null Stmt");
1731 OS << (I == Node->varlist_begin() ? StartSym : ',');
1732 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1733 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1734 DRE->printPretty(OS, nullptr, Policy, 0);
1736 DRE->getDecl()->printQualifiedName(OS);
1738 (*I)->printPretty(OS, nullptr, Policy, 0);
1742 void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
1743 if (Node->varlist_empty())
1746 if (Expr *Allocator = Node->getAllocator()) {
1748 Allocator->printPretty(OS, nullptr, Policy, 0);
1750 VisitOMPClauseList(Node, ' ');
1752 VisitOMPClauseList(Node, '(');
1757 void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1758 if (!Node->varlist_empty()) {
1760 VisitOMPClauseList(Node, '(');
1765 void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1766 if (!Node->varlist_empty()) {
1767 OS << "firstprivate";
1768 VisitOMPClauseList(Node, '(');
1773 void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1774 if (!Node->varlist_empty()) {
1775 OS << "lastprivate";
1776 OpenMPLastprivateModifier LPKind = Node->getKind();
1777 if (LPKind != OMPC_LASTPRIVATE_unknown) {
1779 << getOpenMPSimpleClauseTypeName(OMPC_lastprivate, Node->getKind())
1782 VisitOMPClauseList(Node, LPKind == OMPC_LASTPRIVATE_unknown ? '(' : ' ');
1787 void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1788 if (!Node->varlist_empty()) {
1790 VisitOMPClauseList(Node, '(');
1795 void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1796 if (!Node->varlist_empty()) {
1798 if (Node->getModifierLoc().isValid())
1799 OS << getOpenMPSimpleClauseTypeName(OMPC_reduction, Node->getModifier())
1801 NestedNameSpecifier *QualifierLoc =
1802 Node->getQualifierLoc().getNestedNameSpecifier();
1803 OverloadedOperatorKind OOK =
1804 Node->getNameInfo().getName().getCXXOverloadedOperator();
1805 if (QualifierLoc == nullptr && OOK != OO_None) {
1806 // Print reduction identifier in C format
1807 OS << getOperatorSpelling(OOK);
1810 if (QualifierLoc != nullptr)
1811 QualifierLoc->print(OS, Policy);
1812 OS << Node->getNameInfo();
1815 VisitOMPClauseList(Node, ' ');
1820 void OMPClausePrinter::VisitOMPTaskReductionClause(
1821 OMPTaskReductionClause *Node) {
1822 if (!Node->varlist_empty()) {
1823 OS << "task_reduction(";
1824 NestedNameSpecifier *QualifierLoc =
1825 Node->getQualifierLoc().getNestedNameSpecifier();
1826 OverloadedOperatorKind OOK =
1827 Node->getNameInfo().getName().getCXXOverloadedOperator();
1828 if (QualifierLoc == nullptr && OOK != OO_None) {
1829 // Print reduction identifier in C format
1830 OS << getOperatorSpelling(OOK);
1833 if (QualifierLoc != nullptr)
1834 QualifierLoc->print(OS, Policy);
1835 OS << Node->getNameInfo();
1838 VisitOMPClauseList(Node, ' ');
1843 void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1844 if (!Node->varlist_empty()) {
1845 OS << "in_reduction(";
1846 NestedNameSpecifier *QualifierLoc =
1847 Node->getQualifierLoc().getNestedNameSpecifier();
1848 OverloadedOperatorKind OOK =
1849 Node->getNameInfo().getName().getCXXOverloadedOperator();
1850 if (QualifierLoc == nullptr && OOK != OO_None) {
1851 // Print reduction identifier in C format
1852 OS << getOperatorSpelling(OOK);
1855 if (QualifierLoc != nullptr)
1856 QualifierLoc->print(OS, Policy);
1857 OS << Node->getNameInfo();
1860 VisitOMPClauseList(Node, ' ');
1865 void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1866 if (!Node->varlist_empty()) {
1868 if (Node->getModifierLoc().isValid()) {
1870 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1872 VisitOMPClauseList(Node, '(');
1873 if (Node->getModifierLoc().isValid())
1875 if (Node->getStep() != nullptr) {
1877 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1883 void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1884 if (!Node->varlist_empty()) {
1886 VisitOMPClauseList(Node, '(');
1887 if (Node->getAlignment() != nullptr) {
1889 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1895 void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1896 if (!Node->varlist_empty()) {
1898 VisitOMPClauseList(Node, '(');
1903 void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1904 if (!Node->varlist_empty()) {
1905 OS << "copyprivate";
1906 VisitOMPClauseList(Node, '(');
1911 void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1912 if (!Node->varlist_empty()) {
1913 VisitOMPClauseList(Node, '(');
1918 void OMPClausePrinter::VisitOMPDepobjClause(OMPDepobjClause *Node) {
1920 Node->getDepobj()->printPretty(OS, nullptr, Policy, 0);
1924 void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1926 if (Expr *DepModifier = Node->getModifier()) {
1927 DepModifier->printPretty(OS, nullptr, Policy);
1930 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1931 Node->getDependencyKind());
1932 if (!Node->varlist_empty()) {
1934 VisitOMPClauseList(Node, ' ');
1939 void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1940 if (!Node->varlist_empty()) {
1942 if (Node->getMapType() != OMPC_MAP_unknown) {
1943 for (unsigned I = 0; I < NumberOfOMPMapClauseModifiers; ++I) {
1944 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1945 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1946 Node->getMapTypeModifier(I));
1947 if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1949 NestedNameSpecifier *MapperNNS =
1950 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1952 MapperNNS->print(OS, Policy);
1953 OS << Node->getMapperIdInfo() << ')';
1958 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1961 VisitOMPClauseList(Node, ' ');
1966 void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1967 if (!Node->varlist_empty()) {
1969 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1970 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1973 NestedNameSpecifier *MapperNNS =
1974 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1976 MapperNNS->print(OS, Policy);
1977 OS << MapperId << "):";
1978 VisitOMPClauseList(Node, ' ');
1980 VisitOMPClauseList(Node, '(');
1986 void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1987 if (!Node->varlist_empty()) {
1989 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1990 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1993 NestedNameSpecifier *MapperNNS =
1994 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1996 MapperNNS->print(OS, Policy);
1997 OS << MapperId << "):";
1998 VisitOMPClauseList(Node, ' ');
2000 VisitOMPClauseList(Node, '(');
2006 void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
2007 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
2008 OMPC_dist_schedule, Node->getDistScheduleKind());
2009 if (auto *E = Node->getChunkSize()) {
2011 E->printPretty(OS, nullptr, Policy);
2016 void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
2017 OS << "defaultmap(";
2018 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
2019 Node->getDefaultmapModifier());
2020 if (Node->getDefaultmapKind() != OMPC_DEFAULTMAP_unknown) {
2022 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
2023 Node->getDefaultmapKind());
2028 void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
2029 if (!Node->varlist_empty()) {
2030 OS << "use_device_ptr";
2031 VisitOMPClauseList(Node, '(');
2036 void OMPClausePrinter::VisitOMPUseDeviceAddrClause(
2037 OMPUseDeviceAddrClause *Node) {
2038 if (!Node->varlist_empty()) {
2039 OS << "use_device_addr";
2040 VisitOMPClauseList(Node, '(');
2045 void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
2046 if (!Node->varlist_empty()) {
2047 OS << "is_device_ptr";
2048 VisitOMPClauseList(Node, '(');
2053 void OMPClausePrinter::VisitOMPNontemporalClause(OMPNontemporalClause *Node) {
2054 if (!Node->varlist_empty()) {
2055 OS << "nontemporal";
2056 VisitOMPClauseList(Node, '(');
2061 void OMPClausePrinter::VisitOMPOrderClause(OMPOrderClause *Node) {
2062 OS << "order(" << getOpenMPSimpleClauseTypeName(OMPC_order, Node->getKind())
2066 void OMPClausePrinter::VisitOMPInclusiveClause(OMPInclusiveClause *Node) {
2067 if (!Node->varlist_empty()) {
2069 VisitOMPClauseList(Node, '(');
2074 void OMPClausePrinter::VisitOMPExclusiveClause(OMPExclusiveClause *Node) {
2075 if (!Node->varlist_empty()) {
2077 VisitOMPClauseList(Node, '(');
2082 void OMPClausePrinter::VisitOMPUsesAllocatorsClause(
2083 OMPUsesAllocatorsClause *Node) {
2084 if (Node->getNumberOfAllocators() == 0)
2086 OS << "uses_allocators(";
2087 for (unsigned I = 0, E = Node->getNumberOfAllocators(); I < E; ++I) {
2088 OMPUsesAllocatorsClause::Data Data = Node->getAllocatorData(I);
2089 Data.Allocator->printPretty(OS, nullptr, Policy);
2090 if (Data.AllocatorTraits) {
2092 Data.AllocatorTraits->printPretty(OS, nullptr, Policy);
2101 void OMPClausePrinter::VisitOMPAffinityClause(OMPAffinityClause *Node) {
2102 if (Node->varlist_empty())
2105 char StartSym = '(';
2106 if (Expr *Modifier = Node->getModifier()) {
2108 Modifier->printPretty(OS, nullptr, Policy);
2112 VisitOMPClauseList(Node, StartSym);
2116 void OMPTraitInfo::getAsVariantMatchInfo(ASTContext &ASTCtx,
2117 VariantMatchInfo &VMI) const {
2118 for (const OMPTraitSet &Set : Sets) {
2119 for (const OMPTraitSelector &Selector : Set.Selectors) {
2121 // User conditions are special as we evaluate the condition here.
2122 if (Selector.Kind == TraitSelector::user_condition) {
2123 assert(Selector.ScoreOrCondition &&
2124 "Ill-formed user condition, expected condition expression!");
2125 assert(Selector.Properties.size() == 1 &&
2126 Selector.Properties.front().Kind ==
2127 TraitProperty::user_condition_unknown &&
2128 "Ill-formed user condition, expected unknown trait property!");
2130 llvm::APSInt CondVal;
2131 if (Selector.ScoreOrCondition->isIntegerConstantExpr(CondVal, ASTCtx))
2132 VMI.addTrait(CondVal.isNullValue()
2133 ? TraitProperty::user_condition_false
2134 : TraitProperty::user_condition_true);
2136 VMI.addTrait(TraitProperty::user_condition_false);
2141 llvm::APInt *ScorePtr = nullptr;
2142 if (Selector.ScoreOrCondition) {
2143 if (Selector.ScoreOrCondition->isIntegerConstantExpr(Score, ASTCtx))
2146 VMI.addTrait(TraitProperty::user_condition_false);
2149 for (const OMPTraitProperty &Property : Selector.Properties)
2150 VMI.addTrait(Set.Kind, Property.Kind, ScorePtr);
2152 if (Set.Kind != TraitSet::construct)
2155 // TODO: This might not hold once we implement SIMD properly.
2156 assert(Selector.Properties.size() == 1 &&
2157 Selector.Properties.front().Kind ==
2158 getOpenMPContextTraitPropertyForSelector(
2160 "Ill-formed construct selector!");
2162 VMI.ConstructTraits.push_back(Selector.Properties.front().Kind);
2167 void OMPTraitInfo::print(llvm::raw_ostream &OS,
2168 const PrintingPolicy &Policy) const {
2169 bool FirstSet = true;
2170 for (const OMPTraitSet &Set : Sets) {
2174 OS << getOpenMPContextTraitSetName(Set.Kind) << "={";
2176 bool FirstSelector = true;
2177 for (const OMPTraitSelector &Selector : Set.Selectors) {
2180 FirstSelector = false;
2181 OS << getOpenMPContextTraitSelectorName(Selector.Kind);
2183 bool AllowsTraitScore = false;
2184 bool RequiresProperty = false;
2185 isValidTraitSelectorForTraitSet(
2186 Selector.Kind, Set.Kind, AllowsTraitScore, RequiresProperty);
2188 if (!RequiresProperty)
2192 if (Selector.Kind == TraitSelector::user_condition) {
2193 Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy);
2196 if (Selector.ScoreOrCondition) {
2198 Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy);
2202 bool FirstProperty = true;
2203 for (const OMPTraitProperty &Property : Selector.Properties) {
2206 FirstProperty = false;
2207 OS << getOpenMPContextTraitPropertyName(Property.Kind);
2216 std::string OMPTraitInfo::getMangledName() const {
2217 std::string MangledName;
2218 llvm::raw_string_ostream OS(MangledName);
2219 for (const OMPTraitSet &Set : Sets) {
2220 OS << '$' << 'S' << unsigned(Set.Kind);
2221 for (const OMPTraitSelector &Selector : Set.Selectors) {
2223 bool AllowsTraitScore = false;
2224 bool RequiresProperty = false;
2225 isValidTraitSelectorForTraitSet(
2226 Selector.Kind, Set.Kind, AllowsTraitScore, RequiresProperty);
2227 OS << '$' << 's' << unsigned(Selector.Kind);
2229 if (!RequiresProperty ||
2230 Selector.Kind == TraitSelector::user_condition)
2233 for (const OMPTraitProperty &Property : Selector.Properties)
2234 OS << '$' << 'P' << getOpenMPContextTraitPropertyName(Property.Kind);
2240 OMPTraitInfo::OMPTraitInfo(StringRef MangledName) {
2243 if (!MangledName.consume_front("$S"))
2245 if (MangledName.consumeInteger(10, U))
2247 Sets.push_back(OMPTraitSet());
2248 OMPTraitSet &Set = Sets.back();
2249 Set.Kind = TraitSet(U);
2251 if (!MangledName.consume_front("$s"))
2253 if (MangledName.consumeInteger(10, U))
2255 Set.Selectors.push_back(OMPTraitSelector());
2256 OMPTraitSelector &Selector = Set.Selectors.back();
2257 Selector.Kind = TraitSelector(U);
2259 if (!MangledName.consume_front("$P"))
2261 Selector.Properties.push_back(OMPTraitProperty());
2262 OMPTraitProperty &Property = Selector.Properties.back();
2263 std::pair<StringRef, StringRef> PropRestPair = MangledName.split('$');
2265 getOpenMPContextTraitPropertyKind(Set.Kind, PropRestPair.first);
2266 MangledName = PropRestPair.second;
2272 llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS,
2273 const OMPTraitInfo &TI) {
2275 PrintingPolicy Policy(LO);
2276 TI.print(OS, Policy);
2279 llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS,
2280 const OMPTraitInfo *TI) {
2281 return TI ? OS << *TI : OS;