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:
46 case OMPC_device_type:
51 llvm_unreachable("unknown OMPClause");
54 OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
55 auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
56 return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr;
59 const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
60 switch (C->getClauseKind()) {
62 return static_cast<const OMPScheduleClause *>(C);
63 case OMPC_dist_schedule:
64 return static_cast<const OMPDistScheduleClause *>(C);
65 case OMPC_firstprivate:
66 return static_cast<const OMPFirstprivateClause *>(C);
67 case OMPC_lastprivate:
68 return static_cast<const OMPLastprivateClause *>(C);
70 return static_cast<const OMPReductionClause *>(C);
71 case OMPC_task_reduction:
72 return static_cast<const OMPTaskReductionClause *>(C);
73 case OMPC_in_reduction:
74 return static_cast<const OMPInReductionClause *>(C);
76 return static_cast<const OMPLinearClause *>(C);
78 return static_cast<const OMPIfClause *>(C);
79 case OMPC_num_threads:
80 return static_cast<const OMPNumThreadsClause *>(C);
82 return static_cast<const OMPNumTeamsClause *>(C);
83 case OMPC_thread_limit:
84 return static_cast<const OMPThreadLimitClause *>(C);
86 return static_cast<const OMPDeviceClause *>(C);
88 return static_cast<const OMPGrainsizeClause *>(C);
90 return static_cast<const OMPNumTasksClause *>(C);
92 return static_cast<const OMPFinalClause *>(C);
94 return static_cast<const OMPPriorityClause *>(C);
106 case OMPC_copyprivate:
111 case OMPC_threadprivate:
124 case OMPC_defaultmap:
129 case OMPC_use_device_ptr:
130 case OMPC_is_device_ptr:
131 case OMPC_unified_address:
132 case OMPC_unified_shared_memory:
133 case OMPC_reverse_offload:
134 case OMPC_dynamic_allocators:
135 case OMPC_atomic_default_mem_order:
136 case OMPC_device_type:
144 OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
145 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
146 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
149 const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
150 switch (C->getClauseKind()) {
151 case OMPC_lastprivate:
152 return static_cast<const OMPLastprivateClause *>(C);
154 return static_cast<const OMPReductionClause *>(C);
155 case OMPC_task_reduction:
156 return static_cast<const OMPTaskReductionClause *>(C);
157 case OMPC_in_reduction:
158 return static_cast<const OMPInReductionClause *>(C);
160 return static_cast<const OMPLinearClause *>(C);
162 case OMPC_dist_schedule:
163 case OMPC_firstprivate:
168 case OMPC_num_threads:
178 case OMPC_copyprivate:
183 case OMPC_threadprivate:
196 case OMPC_thread_limit:
202 case OMPC_defaultmap:
207 case OMPC_use_device_ptr:
208 case OMPC_is_device_ptr:
209 case OMPC_unified_address:
210 case OMPC_unified_shared_memory:
211 case OMPC_reverse_offload:
212 case OMPC_dynamic_allocators:
213 case OMPC_atomic_default_mem_order:
214 case OMPC_device_type:
222 /// Gets the address of the original, non-captured, expression used in the
223 /// clause as the preinitializer.
224 static Stmt **getAddrOfExprAsWritten(Stmt *S) {
227 if (auto *DS = dyn_cast<DeclStmt>(S)) {
228 assert(DS->isSingleDecl() && "Only single expression must be captured.");
229 if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
230 return OED->getInitAddress();
235 OMPClause::child_range OMPIfClause::used_children() {
236 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
237 return child_range(C, C + 1);
238 return child_range(&Condition, &Condition + 1);
241 OMPClause::child_range OMPGrainsizeClause::used_children() {
242 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
243 return child_range(C, C + 1);
244 return child_range(&Grainsize, &Grainsize + 1);
247 OMPClause::child_range OMPNumTasksClause::used_children() {
248 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
249 return child_range(C, C + 1);
250 return child_range(&NumTasks, &NumTasks + 1);
253 OMPClause::child_range OMPFinalClause::used_children() {
254 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
255 return child_range(C, C + 1);
256 return child_range(&Condition, &Condition + 1);
259 OMPClause::child_range OMPPriorityClause::used_children() {
260 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
261 return child_range(C, C + 1);
262 return child_range(&Priority, &Priority + 1);
265 OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
267 SourceLocation StartLoc,
268 SourceLocation LParenLoc,
269 SourceLocation EndLoc) {
270 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
272 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
273 for (unsigned I = 0; I < NumLoops; ++I) {
274 Clause->setLoopNumIterations(I, nullptr);
275 Clause->setLoopCounter(I, nullptr);
280 OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
282 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
283 auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
284 for (unsigned I = 0; I < NumLoops; ++I) {
285 Clause->setLoopNumIterations(I, nullptr);
286 Clause->setLoopCounter(I, nullptr);
291 void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
292 Expr *NumIterations) {
293 assert(NumLoop < NumberOfLoops && "out of loops number.");
294 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
297 ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
298 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
301 void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
302 assert(NumLoop < NumberOfLoops && "out of loops number.");
303 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
306 Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
307 assert(NumLoop < NumberOfLoops && "out of loops number.");
308 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
311 const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
312 assert(NumLoop < NumberOfLoops && "out of loops number.");
313 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
316 void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
317 assert(VL.size() == varlist_size() &&
318 "Number of private copies is not the same as the preallocated buffer");
319 std::copy(VL.begin(), VL.end(), varlist_end());
323 OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
324 SourceLocation LParenLoc, SourceLocation EndLoc,
325 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
326 // Allocate space for private variables and initializer expressions.
327 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
328 OMPPrivateClause *Clause =
329 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
330 Clause->setVarRefs(VL);
331 Clause->setPrivateCopies(PrivateVL);
335 OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
337 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
338 return new (Mem) OMPPrivateClause(N);
341 void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
342 assert(VL.size() == varlist_size() &&
343 "Number of private copies is not the same as the preallocated buffer");
344 std::copy(VL.begin(), VL.end(), varlist_end());
347 void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
348 assert(VL.size() == varlist_size() &&
349 "Number of inits is not the same as the preallocated buffer");
350 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
353 OMPFirstprivateClause *
354 OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
355 SourceLocation LParenLoc, SourceLocation EndLoc,
356 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
357 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
358 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
359 OMPFirstprivateClause *Clause =
360 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
361 Clause->setVarRefs(VL);
362 Clause->setPrivateCopies(PrivateVL);
363 Clause->setInits(InitVL);
364 Clause->setPreInitStmt(PreInit);
368 OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
370 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
371 return new (Mem) OMPFirstprivateClause(N);
374 void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
375 assert(PrivateCopies.size() == varlist_size() &&
376 "Number of private copies is not the same as the preallocated buffer");
377 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
380 void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
381 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
382 "not the same as the "
383 "preallocated buffer");
384 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
387 void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
388 assert(DstExprs.size() == varlist_size() && "Number of destination "
389 "expressions is not the same as "
390 "the preallocated buffer");
391 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
394 void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
395 assert(AssignmentOps.size() == varlist_size() &&
396 "Number of assignment expressions is not the same as the preallocated "
398 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
399 getDestinationExprs().end());
402 OMPLastprivateClause *OMPLastprivateClause::Create(
403 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
404 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
405 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit,
407 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
408 OMPLastprivateClause *Clause =
409 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
410 Clause->setVarRefs(VL);
411 Clause->setSourceExprs(SrcExprs);
412 Clause->setDestinationExprs(DstExprs);
413 Clause->setAssignmentOps(AssignmentOps);
414 Clause->setPreInitStmt(PreInit);
415 Clause->setPostUpdateExpr(PostUpdate);
419 OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
421 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
422 return new (Mem) OMPLastprivateClause(N);
425 OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
426 SourceLocation StartLoc,
427 SourceLocation LParenLoc,
428 SourceLocation EndLoc,
429 ArrayRef<Expr *> VL) {
430 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
431 OMPSharedClause *Clause =
432 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
433 Clause->setVarRefs(VL);
437 OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
438 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
439 return new (Mem) OMPSharedClause(N);
442 void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
443 assert(PL.size() == varlist_size() &&
444 "Number of privates is not the same as the preallocated buffer");
445 std::copy(PL.begin(), PL.end(), varlist_end());
448 void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
449 assert(IL.size() == varlist_size() &&
450 "Number of inits is not the same as the preallocated buffer");
451 std::copy(IL.begin(), IL.end(), getPrivates().end());
454 void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
455 assert(UL.size() == varlist_size() &&
456 "Number of updates is not the same as the preallocated buffer");
457 std::copy(UL.begin(), UL.end(), getInits().end());
460 void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
461 assert(FL.size() == varlist_size() &&
462 "Number of final updates is not the same as the preallocated buffer");
463 std::copy(FL.begin(), FL.end(), getUpdates().end());
466 void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) {
468 UE.size() == varlist_size() + 1 &&
469 "Number of used expressions is not the same as the preallocated buffer");
470 std::copy(UE.begin(), UE.end(), getFinals().end() + 2);
473 OMPLinearClause *OMPLinearClause::Create(
474 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
475 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
476 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
477 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
478 Stmt *PreInit, Expr *PostUpdate) {
479 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
480 // (Step and CalcStep), list of used expression + step.
482 C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1));
483 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
484 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
485 Clause->setVarRefs(VL);
486 Clause->setPrivates(PL);
487 Clause->setInits(IL);
488 // Fill update and final expressions with zeroes, they are provided later,
489 // after the directive construction.
490 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
492 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
494 std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(),
496 Clause->setStep(Step);
497 Clause->setCalcStep(CalcStep);
498 Clause->setPreInitStmt(PreInit);
499 Clause->setPostUpdateExpr(PostUpdate);
503 OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
505 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
506 // (Step and CalcStep), list of used expression + step.
507 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars +1));
508 return new (Mem) OMPLinearClause(NumVars);
511 OMPClause::child_range OMPLinearClause::used_children() {
512 // Range includes only non-nullptr elements.
514 reinterpret_cast<Stmt **>(getUsedExprs().begin()),
515 reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr)));
519 OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
520 SourceLocation LParenLoc, SourceLocation ColonLoc,
521 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
522 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
523 OMPAlignedClause *Clause = new (Mem)
524 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
525 Clause->setVarRefs(VL);
526 Clause->setAlignment(A);
530 OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
532 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
533 return new (Mem) OMPAlignedClause(NumVars);
536 void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
537 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
538 "not the same as the "
539 "preallocated buffer");
540 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
543 void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
544 assert(DstExprs.size() == varlist_size() && "Number of destination "
545 "expressions is not the same as "
546 "the preallocated buffer");
547 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
550 void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
551 assert(AssignmentOps.size() == varlist_size() &&
552 "Number of assignment expressions is not the same as the preallocated "
554 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
555 getDestinationExprs().end());
558 OMPCopyinClause *OMPCopyinClause::Create(
559 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
560 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
561 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
562 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
563 OMPCopyinClause *Clause =
564 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
565 Clause->setVarRefs(VL);
566 Clause->setSourceExprs(SrcExprs);
567 Clause->setDestinationExprs(DstExprs);
568 Clause->setAssignmentOps(AssignmentOps);
572 OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
573 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
574 return new (Mem) OMPCopyinClause(N);
577 void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
578 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
579 "not the same as the "
580 "preallocated buffer");
581 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
584 void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
585 assert(DstExprs.size() == varlist_size() && "Number of destination "
586 "expressions is not the same as "
587 "the preallocated buffer");
588 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
591 void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
592 assert(AssignmentOps.size() == varlist_size() &&
593 "Number of assignment expressions is not the same as the preallocated "
595 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
596 getDestinationExprs().end());
599 OMPCopyprivateClause *OMPCopyprivateClause::Create(
600 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
601 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
602 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
603 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
604 OMPCopyprivateClause *Clause =
605 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
606 Clause->setVarRefs(VL);
607 Clause->setSourceExprs(SrcExprs);
608 Clause->setDestinationExprs(DstExprs);
609 Clause->setAssignmentOps(AssignmentOps);
613 OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
615 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
616 return new (Mem) OMPCopyprivateClause(N);
619 void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
620 assert(Privates.size() == varlist_size() &&
621 "Number of private copies is not the same as the preallocated buffer");
622 std::copy(Privates.begin(), Privates.end(), varlist_end());
625 void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
627 LHSExprs.size() == varlist_size() &&
628 "Number of LHS expressions is not the same as the preallocated buffer");
629 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
632 void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
634 RHSExprs.size() == varlist_size() &&
635 "Number of RHS expressions is not the same as the preallocated buffer");
636 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
639 void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
640 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
641 "expressions is not the same "
642 "as the preallocated buffer");
643 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
646 OMPReductionClause *OMPReductionClause::Create(
647 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
648 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
649 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
650 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
651 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
653 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
654 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
655 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
656 Clause->setVarRefs(VL);
657 Clause->setPrivates(Privates);
658 Clause->setLHSExprs(LHSExprs);
659 Clause->setRHSExprs(RHSExprs);
660 Clause->setReductionOps(ReductionOps);
661 Clause->setPreInitStmt(PreInit);
662 Clause->setPostUpdateExpr(PostUpdate);
666 OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
668 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
669 return new (Mem) OMPReductionClause(N);
672 void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
673 assert(Privates.size() == varlist_size() &&
674 "Number of private copies is not the same as the preallocated buffer");
675 std::copy(Privates.begin(), Privates.end(), varlist_end());
678 void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
680 LHSExprs.size() == varlist_size() &&
681 "Number of LHS expressions is not the same as the preallocated buffer");
682 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
685 void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
687 RHSExprs.size() == varlist_size() &&
688 "Number of RHS expressions is not the same as the preallocated buffer");
689 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
692 void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
693 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
694 "expressions is not the same "
695 "as the preallocated buffer");
696 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
699 OMPTaskReductionClause *OMPTaskReductionClause::Create(
700 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
701 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
702 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
703 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
704 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
706 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
707 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
708 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
709 Clause->setVarRefs(VL);
710 Clause->setPrivates(Privates);
711 Clause->setLHSExprs(LHSExprs);
712 Clause->setRHSExprs(RHSExprs);
713 Clause->setReductionOps(ReductionOps);
714 Clause->setPreInitStmt(PreInit);
715 Clause->setPostUpdateExpr(PostUpdate);
719 OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
721 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
722 return new (Mem) OMPTaskReductionClause(N);
725 void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
726 assert(Privates.size() == varlist_size() &&
727 "Number of private copies is not the same as the preallocated buffer");
728 std::copy(Privates.begin(), Privates.end(), varlist_end());
731 void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
733 LHSExprs.size() == varlist_size() &&
734 "Number of LHS expressions is not the same as the preallocated buffer");
735 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
738 void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
740 RHSExprs.size() == varlist_size() &&
741 "Number of RHS expressions is not the same as the preallocated buffer");
742 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
745 void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
746 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
747 "expressions is not the same "
748 "as the preallocated buffer");
749 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
752 void OMPInReductionClause::setTaskgroupDescriptors(
753 ArrayRef<Expr *> TaskgroupDescriptors) {
754 assert(TaskgroupDescriptors.size() == varlist_size() &&
755 "Number of in reduction descriptors is not the same as the "
756 "preallocated buffer");
757 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
758 getReductionOps().end());
761 OMPInReductionClause *OMPInReductionClause::Create(
762 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
763 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
764 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
765 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
766 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
767 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
768 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
769 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
770 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
771 Clause->setVarRefs(VL);
772 Clause->setPrivates(Privates);
773 Clause->setLHSExprs(LHSExprs);
774 Clause->setRHSExprs(RHSExprs);
775 Clause->setReductionOps(ReductionOps);
776 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
777 Clause->setPreInitStmt(PreInit);
778 Clause->setPostUpdateExpr(PostUpdate);
782 OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
784 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
785 return new (Mem) OMPInReductionClause(N);
789 OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc,
790 SourceLocation LParenLoc, Expr *Allocator,
791 SourceLocation ColonLoc, SourceLocation EndLoc,
792 ArrayRef<Expr *> VL) {
793 // Allocate space for private variables and initializer expressions.
794 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
795 auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
796 ColonLoc, EndLoc, VL.size());
797 Clause->setVarRefs(VL);
801 OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
803 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
804 return new (Mem) OMPAllocateClause(N);
807 OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
808 SourceLocation StartLoc,
809 SourceLocation LParenLoc,
810 SourceLocation EndLoc,
811 ArrayRef<Expr *> VL) {
812 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
813 OMPFlushClause *Clause =
814 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
815 Clause->setVarRefs(VL);
819 OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
820 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
821 return new (Mem) OMPFlushClause(N);
825 OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
826 SourceLocation LParenLoc, SourceLocation EndLoc,
827 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
828 SourceLocation ColonLoc, ArrayRef<Expr *> VL,
830 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
831 OMPDependClause *Clause = new (Mem)
832 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
833 Clause->setVarRefs(VL);
834 Clause->setDependencyKind(DepKind);
835 Clause->setDependencyLoc(DepLoc);
836 Clause->setColonLoc(ColonLoc);
837 for (unsigned I = 0 ; I < NumLoops; ++I)
838 Clause->setLoopData(I, nullptr);
842 OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
844 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
845 return new (Mem) OMPDependClause(N, NumLoops);
848 void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
849 assert((getDependencyKind() == OMPC_DEPEND_sink ||
850 getDependencyKind() == OMPC_DEPEND_source) &&
851 NumLoop < NumLoops &&
852 "Expected sink or source depend + loop index must be less number of "
854 auto It = std::next(getVarRefs().end(), NumLoop);
858 Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
859 assert((getDependencyKind() == OMPC_DEPEND_sink ||
860 getDependencyKind() == OMPC_DEPEND_source) &&
861 NumLoop < NumLoops &&
862 "Expected sink or source depend + loop index must be less number of "
864 auto It = std::next(getVarRefs().end(), NumLoop);
868 const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
869 assert((getDependencyKind() == OMPC_DEPEND_sink ||
870 getDependencyKind() == OMPC_DEPEND_source) &&
871 NumLoop < NumLoops &&
872 "Expected sink or source depend + loop index must be less number of "
874 auto It = std::next(getVarRefs().end(), NumLoop);
878 unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
879 MappableExprComponentListsRef ComponentLists) {
880 unsigned TotalNum = 0u;
881 for (auto &C : ComponentLists)
882 TotalNum += C.size();
886 unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
887 ArrayRef<const ValueDecl *> Declarations) {
888 unsigned TotalNum = 0u;
889 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
890 for (const ValueDecl *D : Declarations) {
891 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
900 OMPMapClause *OMPMapClause::Create(
901 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
902 ArrayRef<ValueDecl *> Declarations,
903 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
904 ArrayRef<OpenMPMapModifierKind> MapModifiers,
905 ArrayRef<SourceLocation> MapModifiersLoc,
906 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
907 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
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));
930 OMPMapClause *Clause = new (Mem)
931 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
932 Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
934 Clause->setVarRefs(Vars);
935 Clause->setUDMapperRefs(UDMapperRefs);
936 Clause->setClauseInfo(Declarations, ComponentLists);
937 Clause->setMapType(Type);
938 Clause->setMapLoc(TypeLoc);
943 OMPMapClause::CreateEmpty(const ASTContext &C,
944 const OMPMappableExprListSizeTy &Sizes) {
945 void *Mem = C.Allocate(
946 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
947 OMPClauseMappableExprCommon::MappableComponent>(
948 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
949 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
950 Sizes.NumComponents));
951 return new (Mem) OMPMapClause(Sizes);
954 OMPToClause *OMPToClause::Create(
955 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
956 ArrayRef<ValueDecl *> Declarations,
957 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
958 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
959 OMPMappableExprListSizeTy Sizes;
960 Sizes.NumVars = Vars.size();
961 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
962 Sizes.NumComponentLists = ComponentLists.size();
963 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
965 // We need to allocate:
966 // 2 x NumVars x Expr* - we have an original list expression and an associated
967 // user-defined mapper for each clause list entry.
968 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
969 // with each component list.
970 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
971 // number of lists for each unique declaration and the size of each component
973 // NumComponents x MappableComponent - the total of all the components in all
975 void *Mem = C.Allocate(
976 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
977 OMPClauseMappableExprCommon::MappableComponent>(
978 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
979 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
980 Sizes.NumComponents));
982 auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
984 Clause->setVarRefs(Vars);
985 Clause->setUDMapperRefs(UDMapperRefs);
986 Clause->setClauseInfo(Declarations, ComponentLists);
990 OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
991 const OMPMappableExprListSizeTy &Sizes) {
992 void *Mem = C.Allocate(
993 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
994 OMPClauseMappableExprCommon::MappableComponent>(
995 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
996 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
997 Sizes.NumComponents));
998 return new (Mem) OMPToClause(Sizes);
1001 OMPFromClause *OMPFromClause::Create(
1002 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1003 ArrayRef<ValueDecl *> Declarations,
1004 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1005 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
1006 OMPMappableExprListSizeTy Sizes;
1007 Sizes.NumVars = Vars.size();
1008 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1009 Sizes.NumComponentLists = ComponentLists.size();
1010 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1012 // We need to allocate:
1013 // 2 x NumVars x Expr* - we have an original list expression and an associated
1014 // user-defined mapper for each clause list entry.
1015 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1016 // with each component list.
1017 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1018 // number of lists for each unique declaration and the size of each component
1020 // NumComponents x MappableComponent - the total of all the components in all
1022 void *Mem = C.Allocate(
1023 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1024 OMPClauseMappableExprCommon::MappableComponent>(
1025 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1026 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1027 Sizes.NumComponents));
1030 new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
1032 Clause->setVarRefs(Vars);
1033 Clause->setUDMapperRefs(UDMapperRefs);
1034 Clause->setClauseInfo(Declarations, ComponentLists);
1039 OMPFromClause::CreateEmpty(const ASTContext &C,
1040 const OMPMappableExprListSizeTy &Sizes) {
1041 void *Mem = C.Allocate(
1042 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1043 OMPClauseMappableExprCommon::MappableComponent>(
1044 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1045 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1046 Sizes.NumComponents));
1047 return new (Mem) OMPFromClause(Sizes);
1050 void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1051 assert(VL.size() == varlist_size() &&
1052 "Number of private copies is not the same as the preallocated buffer");
1053 std::copy(VL.begin(), VL.end(), varlist_end());
1056 void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
1057 assert(VL.size() == varlist_size() &&
1058 "Number of inits is not the same as the preallocated buffer");
1059 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1062 OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
1063 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1064 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
1065 ArrayRef<ValueDecl *> Declarations,
1066 MappableExprComponentListsRef ComponentLists) {
1067 OMPMappableExprListSizeTy Sizes;
1068 Sizes.NumVars = Vars.size();
1069 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1070 Sizes.NumComponentLists = ComponentLists.size();
1071 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1073 // We need to allocate:
1074 // 3 x NumVars x Expr* - we have an original list expression for each clause
1075 // list entry and an equal number of private copies and inits.
1076 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1077 // with each component list.
1078 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1079 // number of lists for each unique declaration and the size of each component
1081 // NumComponents x MappableComponent - the total of all the components in all
1083 void *Mem = C.Allocate(
1084 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1085 OMPClauseMappableExprCommon::MappableComponent>(
1086 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1087 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1088 Sizes.NumComponents));
1090 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
1092 Clause->setVarRefs(Vars);
1093 Clause->setPrivateCopies(PrivateVars);
1094 Clause->setInits(Inits);
1095 Clause->setClauseInfo(Declarations, ComponentLists);
1099 OMPUseDevicePtrClause *
1100 OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
1101 const OMPMappableExprListSizeTy &Sizes) {
1102 void *Mem = C.Allocate(
1103 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1104 OMPClauseMappableExprCommon::MappableComponent>(
1105 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1106 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1107 Sizes.NumComponents));
1108 return new (Mem) OMPUseDevicePtrClause(Sizes);
1111 OMPIsDevicePtrClause *
1112 OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
1113 ArrayRef<Expr *> Vars,
1114 ArrayRef<ValueDecl *> Declarations,
1115 MappableExprComponentListsRef ComponentLists) {
1116 OMPMappableExprListSizeTy Sizes;
1117 Sizes.NumVars = Vars.size();
1118 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1119 Sizes.NumComponentLists = ComponentLists.size();
1120 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1122 // We need to allocate:
1123 // NumVars x Expr* - we have an original list expression for each clause list
1125 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1126 // with each component list.
1127 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1128 // number of lists for each unique declaration and the size of each component
1130 // NumComponents x MappableComponent - the total of all the components in all
1132 void *Mem = C.Allocate(
1133 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1134 OMPClauseMappableExprCommon::MappableComponent>(
1135 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1136 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1137 Sizes.NumComponents));
1139 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
1141 Clause->setVarRefs(Vars);
1142 Clause->setClauseInfo(Declarations, ComponentLists);
1146 OMPIsDevicePtrClause *
1147 OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1148 const OMPMappableExprListSizeTy &Sizes) {
1149 void *Mem = C.Allocate(
1150 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1151 OMPClauseMappableExprCommon::MappableComponent>(
1152 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1153 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1154 Sizes.NumComponents));
1155 return new (Mem) OMPIsDevicePtrClause(Sizes);
1158 //===----------------------------------------------------------------------===//
1159 // OpenMP clauses printing methods
1160 //===----------------------------------------------------------------------===//
1162 void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1164 if (Node->getNameModifier() != OMPD_unknown)
1165 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1166 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1170 void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1172 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1176 void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1177 OS << "num_threads(";
1178 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1182 void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1184 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1188 void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1190 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1194 void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
1196 Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
1200 void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1202 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1206 void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1208 << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
1212 void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1214 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, Node->getProcBindKind())
1218 void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1219 OS << "unified_address";
1222 void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1223 OMPUnifiedSharedMemoryClause *) {
1224 OS << "unified_shared_memory";
1227 void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1228 OS << "reverse_offload";
1231 void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1232 OMPDynamicAllocatorsClause *) {
1233 OS << "dynamic_allocators";
1236 void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1237 OMPAtomicDefaultMemOrderClause *Node) {
1238 OS << "atomic_default_mem_order("
1239 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1240 Node->getAtomicDefaultMemOrderKind())
1244 void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1246 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1247 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1248 Node->getFirstScheduleModifier());
1249 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1251 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1252 Node->getSecondScheduleModifier());
1256 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1257 if (auto *E = Node->getChunkSize()) {
1259 E->printPretty(OS, nullptr, Policy);
1264 void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1266 if (auto *Num = Node->getNumForLoops()) {
1268 Num->printPretty(OS, nullptr, Policy, 0);
1273 void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1277 void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1281 void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1285 void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1289 void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1291 void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1293 void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
1297 void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1301 void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1305 void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1309 void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1311 void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1313 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1317 void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1319 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1323 void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1324 OS << "thread_limit(";
1325 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1329 void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1331 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1335 void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1337 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1341 void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1343 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1347 void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1349 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1353 template<typename T>
1354 void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1355 for (typename T::varlist_iterator I = Node->varlist_begin(),
1356 E = Node->varlist_end();
1358 assert(*I && "Expected non-null Stmt");
1359 OS << (I == Node->varlist_begin() ? StartSym : ',');
1360 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1361 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1362 DRE->printPretty(OS, nullptr, Policy, 0);
1364 DRE->getDecl()->printQualifiedName(OS);
1366 (*I)->printPretty(OS, nullptr, Policy, 0);
1370 void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
1371 if (Node->varlist_empty())
1374 if (Expr *Allocator = Node->getAllocator()) {
1376 Allocator->printPretty(OS, nullptr, Policy, 0);
1378 VisitOMPClauseList(Node, ' ');
1380 VisitOMPClauseList(Node, '(');
1385 void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1386 if (!Node->varlist_empty()) {
1388 VisitOMPClauseList(Node, '(');
1393 void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1394 if (!Node->varlist_empty()) {
1395 OS << "firstprivate";
1396 VisitOMPClauseList(Node, '(');
1401 void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1402 if (!Node->varlist_empty()) {
1403 OS << "lastprivate";
1404 VisitOMPClauseList(Node, '(');
1409 void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1410 if (!Node->varlist_empty()) {
1412 VisitOMPClauseList(Node, '(');
1417 void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1418 if (!Node->varlist_empty()) {
1420 NestedNameSpecifier *QualifierLoc =
1421 Node->getQualifierLoc().getNestedNameSpecifier();
1422 OverloadedOperatorKind OOK =
1423 Node->getNameInfo().getName().getCXXOverloadedOperator();
1424 if (QualifierLoc == nullptr && OOK != OO_None) {
1425 // Print reduction identifier in C format
1426 OS << getOperatorSpelling(OOK);
1429 if (QualifierLoc != nullptr)
1430 QualifierLoc->print(OS, Policy);
1431 OS << Node->getNameInfo();
1434 VisitOMPClauseList(Node, ' ');
1439 void OMPClausePrinter::VisitOMPTaskReductionClause(
1440 OMPTaskReductionClause *Node) {
1441 if (!Node->varlist_empty()) {
1442 OS << "task_reduction(";
1443 NestedNameSpecifier *QualifierLoc =
1444 Node->getQualifierLoc().getNestedNameSpecifier();
1445 OverloadedOperatorKind OOK =
1446 Node->getNameInfo().getName().getCXXOverloadedOperator();
1447 if (QualifierLoc == nullptr && OOK != OO_None) {
1448 // Print reduction identifier in C format
1449 OS << getOperatorSpelling(OOK);
1452 if (QualifierLoc != nullptr)
1453 QualifierLoc->print(OS, Policy);
1454 OS << Node->getNameInfo();
1457 VisitOMPClauseList(Node, ' ');
1462 void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1463 if (!Node->varlist_empty()) {
1464 OS << "in_reduction(";
1465 NestedNameSpecifier *QualifierLoc =
1466 Node->getQualifierLoc().getNestedNameSpecifier();
1467 OverloadedOperatorKind OOK =
1468 Node->getNameInfo().getName().getCXXOverloadedOperator();
1469 if (QualifierLoc == nullptr && OOK != OO_None) {
1470 // Print reduction identifier in C format
1471 OS << getOperatorSpelling(OOK);
1474 if (QualifierLoc != nullptr)
1475 QualifierLoc->print(OS, Policy);
1476 OS << Node->getNameInfo();
1479 VisitOMPClauseList(Node, ' ');
1484 void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1485 if (!Node->varlist_empty()) {
1487 if (Node->getModifierLoc().isValid()) {
1489 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1491 VisitOMPClauseList(Node, '(');
1492 if (Node->getModifierLoc().isValid())
1494 if (Node->getStep() != nullptr) {
1496 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1502 void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1503 if (!Node->varlist_empty()) {
1505 VisitOMPClauseList(Node, '(');
1506 if (Node->getAlignment() != nullptr) {
1508 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1514 void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1515 if (!Node->varlist_empty()) {
1517 VisitOMPClauseList(Node, '(');
1522 void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1523 if (!Node->varlist_empty()) {
1524 OS << "copyprivate";
1525 VisitOMPClauseList(Node, '(');
1530 void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1531 if (!Node->varlist_empty()) {
1532 VisitOMPClauseList(Node, '(');
1537 void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1539 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1540 Node->getDependencyKind());
1541 if (!Node->varlist_empty()) {
1543 VisitOMPClauseList(Node, ' ');
1548 void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1549 if (!Node->varlist_empty()) {
1551 if (Node->getMapType() != OMPC_MAP_unknown) {
1552 for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1553 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1554 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1555 Node->getMapTypeModifier(I));
1556 if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1558 NestedNameSpecifier *MapperNNS =
1559 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1561 MapperNNS->print(OS, Policy);
1562 OS << Node->getMapperIdInfo() << ')';
1567 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1570 VisitOMPClauseList(Node, ' ');
1575 void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1576 if (!Node->varlist_empty()) {
1578 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1579 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1582 NestedNameSpecifier *MapperNNS =
1583 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1585 MapperNNS->print(OS, Policy);
1586 OS << MapperId << "):";
1587 VisitOMPClauseList(Node, ' ');
1589 VisitOMPClauseList(Node, '(');
1595 void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1596 if (!Node->varlist_empty()) {
1598 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1599 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1602 NestedNameSpecifier *MapperNNS =
1603 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1605 MapperNNS->print(OS, Policy);
1606 OS << MapperId << "):";
1607 VisitOMPClauseList(Node, ' ');
1609 VisitOMPClauseList(Node, '(');
1615 void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1616 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1617 OMPC_dist_schedule, Node->getDistScheduleKind());
1618 if (auto *E = Node->getChunkSize()) {
1620 E->printPretty(OS, nullptr, Policy);
1625 void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1626 OS << "defaultmap(";
1627 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1628 Node->getDefaultmapModifier());
1630 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1631 Node->getDefaultmapKind());
1635 void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1636 if (!Node->varlist_empty()) {
1637 OS << "use_device_ptr";
1638 VisitOMPClauseList(Node, '(');
1643 void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1644 if (!Node->varlist_empty()) {
1645 OS << "is_device_ptr";
1646 VisitOMPClauseList(Node, '(');