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 "clang/Basic/OpenMPKinds.h"
19 #include "llvm/ADT/SmallPtrSet.h"
20 #include "llvm/Support/Casting.h"
21 #include "llvm/Support/ErrorHandling.h"
25 using namespace clang;
27 OMPClause::child_range OMPClause::children() {
28 switch (getClauseKind()) {
31 #define OPENMP_CLAUSE(Name, Class) \
33 return static_cast<Class *>(this)->children();
34 #include "clang/Basic/OpenMPKinds.def"
36 llvm_unreachable("unknown OMPClause");
39 OMPClause::child_range OMPClause::used_children() {
40 switch (getClauseKind()) {
41 #define OPENMP_CLAUSE(Name, Class) \
43 return static_cast<Class *>(this)->used_children();
44 #include "clang/Basic/OpenMPKinds.def"
45 case OMPC_threadprivate:
47 case OMPC_device_type:
52 llvm_unreachable("unknown OMPClause");
55 OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
56 auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
57 return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr;
60 const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
61 switch (C->getClauseKind()) {
63 return static_cast<const OMPScheduleClause *>(C);
64 case OMPC_dist_schedule:
65 return static_cast<const OMPDistScheduleClause *>(C);
66 case OMPC_firstprivate:
67 return static_cast<const OMPFirstprivateClause *>(C);
68 case OMPC_lastprivate:
69 return static_cast<const OMPLastprivateClause *>(C);
71 return static_cast<const OMPReductionClause *>(C);
72 case OMPC_task_reduction:
73 return static_cast<const OMPTaskReductionClause *>(C);
74 case OMPC_in_reduction:
75 return static_cast<const OMPInReductionClause *>(C);
77 return static_cast<const OMPLinearClause *>(C);
79 return static_cast<const OMPIfClause *>(C);
80 case OMPC_num_threads:
81 return static_cast<const OMPNumThreadsClause *>(C);
83 return static_cast<const OMPNumTeamsClause *>(C);
84 case OMPC_thread_limit:
85 return static_cast<const OMPThreadLimitClause *>(C);
87 return static_cast<const OMPDeviceClause *>(C);
89 return static_cast<const OMPGrainsizeClause *>(C);
91 return static_cast<const OMPNumTasksClause *>(C);
93 return static_cast<const OMPFinalClause *>(C);
95 return static_cast<const OMPPriorityClause *>(C);
107 case OMPC_copyprivate:
112 case OMPC_threadprivate:
125 case OMPC_defaultmap:
130 case OMPC_use_device_ptr:
131 case OMPC_is_device_ptr:
132 case OMPC_unified_address:
133 case OMPC_unified_shared_memory:
134 case OMPC_reverse_offload:
135 case OMPC_dynamic_allocators:
136 case OMPC_atomic_default_mem_order:
137 case OMPC_device_type:
139 case OMPC_nontemporal:
146 OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
147 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
148 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
151 const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
152 switch (C->getClauseKind()) {
153 case OMPC_lastprivate:
154 return static_cast<const OMPLastprivateClause *>(C);
156 return static_cast<const OMPReductionClause *>(C);
157 case OMPC_task_reduction:
158 return static_cast<const OMPTaskReductionClause *>(C);
159 case OMPC_in_reduction:
160 return static_cast<const OMPInReductionClause *>(C);
162 return static_cast<const OMPLinearClause *>(C);
164 case OMPC_dist_schedule:
165 case OMPC_firstprivate:
170 case OMPC_num_threads:
180 case OMPC_copyprivate:
185 case OMPC_threadprivate:
198 case OMPC_thread_limit:
204 case OMPC_defaultmap:
209 case OMPC_use_device_ptr:
210 case OMPC_is_device_ptr:
211 case OMPC_unified_address:
212 case OMPC_unified_shared_memory:
213 case OMPC_reverse_offload:
214 case OMPC_dynamic_allocators:
215 case OMPC_atomic_default_mem_order:
216 case OMPC_device_type:
218 case OMPC_nontemporal:
225 /// Gets the address of the original, non-captured, expression used in the
226 /// clause as the preinitializer.
227 static Stmt **getAddrOfExprAsWritten(Stmt *S) {
230 if (auto *DS = dyn_cast<DeclStmt>(S)) {
231 assert(DS->isSingleDecl() && "Only single expression must be captured.");
232 if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
233 return OED->getInitAddress();
238 OMPClause::child_range OMPIfClause::used_children() {
239 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
240 return child_range(C, C + 1);
241 return child_range(&Condition, &Condition + 1);
244 OMPClause::child_range OMPGrainsizeClause::used_children() {
245 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
246 return child_range(C, C + 1);
247 return child_range(&Grainsize, &Grainsize + 1);
250 OMPClause::child_range OMPNumTasksClause::used_children() {
251 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
252 return child_range(C, C + 1);
253 return child_range(&NumTasks, &NumTasks + 1);
256 OMPClause::child_range OMPFinalClause::used_children() {
257 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
258 return child_range(C, C + 1);
259 return child_range(&Condition, &Condition + 1);
262 OMPClause::child_range OMPPriorityClause::used_children() {
263 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
264 return child_range(C, C + 1);
265 return child_range(&Priority, &Priority + 1);
268 OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
270 SourceLocation StartLoc,
271 SourceLocation LParenLoc,
272 SourceLocation EndLoc) {
273 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
275 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
276 for (unsigned I = 0; I < NumLoops; ++I) {
277 Clause->setLoopNumIterations(I, nullptr);
278 Clause->setLoopCounter(I, nullptr);
283 OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
285 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
286 auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
287 for (unsigned I = 0; I < NumLoops; ++I) {
288 Clause->setLoopNumIterations(I, nullptr);
289 Clause->setLoopCounter(I, nullptr);
294 void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
295 Expr *NumIterations) {
296 assert(NumLoop < NumberOfLoops && "out of loops number.");
297 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
300 ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
301 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
304 void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
305 assert(NumLoop < NumberOfLoops && "out of loops number.");
306 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
309 Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
310 assert(NumLoop < NumberOfLoops && "out of loops number.");
311 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
314 const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
315 assert(NumLoop < NumberOfLoops && "out of loops number.");
316 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
319 void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
320 assert(VL.size() == varlist_size() &&
321 "Number of private copies is not the same as the preallocated buffer");
322 std::copy(VL.begin(), VL.end(), varlist_end());
326 OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
327 SourceLocation LParenLoc, SourceLocation EndLoc,
328 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
329 // Allocate space for private variables and initializer expressions.
330 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
331 OMPPrivateClause *Clause =
332 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
333 Clause->setVarRefs(VL);
334 Clause->setPrivateCopies(PrivateVL);
338 OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
340 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
341 return new (Mem) OMPPrivateClause(N);
344 void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
345 assert(VL.size() == varlist_size() &&
346 "Number of private copies is not the same as the preallocated buffer");
347 std::copy(VL.begin(), VL.end(), varlist_end());
350 void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
351 assert(VL.size() == varlist_size() &&
352 "Number of inits is not the same as the preallocated buffer");
353 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
356 OMPFirstprivateClause *
357 OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
358 SourceLocation LParenLoc, SourceLocation EndLoc,
359 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
360 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
361 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
362 OMPFirstprivateClause *Clause =
363 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
364 Clause->setVarRefs(VL);
365 Clause->setPrivateCopies(PrivateVL);
366 Clause->setInits(InitVL);
367 Clause->setPreInitStmt(PreInit);
371 OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
373 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
374 return new (Mem) OMPFirstprivateClause(N);
377 void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
378 assert(PrivateCopies.size() == varlist_size() &&
379 "Number of private copies is not the same as the preallocated buffer");
380 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
383 void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
384 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
385 "not the same as the "
386 "preallocated buffer");
387 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
390 void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
391 assert(DstExprs.size() == varlist_size() && "Number of destination "
392 "expressions is not the same as "
393 "the preallocated buffer");
394 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
397 void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
398 assert(AssignmentOps.size() == varlist_size() &&
399 "Number of assignment expressions is not the same as the preallocated "
401 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
402 getDestinationExprs().end());
405 OMPLastprivateClause *OMPLastprivateClause::Create(
406 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
407 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
408 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
409 OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
410 SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate) {
411 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
412 OMPLastprivateClause *Clause = new (Mem) OMPLastprivateClause(
413 StartLoc, LParenLoc, EndLoc, LPKind, LPKindLoc, ColonLoc, VL.size());
414 Clause->setVarRefs(VL);
415 Clause->setSourceExprs(SrcExprs);
416 Clause->setDestinationExprs(DstExprs);
417 Clause->setAssignmentOps(AssignmentOps);
418 Clause->setPreInitStmt(PreInit);
419 Clause->setPostUpdateExpr(PostUpdate);
423 OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
425 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
426 return new (Mem) OMPLastprivateClause(N);
429 OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
430 SourceLocation StartLoc,
431 SourceLocation LParenLoc,
432 SourceLocation EndLoc,
433 ArrayRef<Expr *> VL) {
434 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
435 OMPSharedClause *Clause =
436 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
437 Clause->setVarRefs(VL);
441 OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
442 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
443 return new (Mem) OMPSharedClause(N);
446 void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
447 assert(PL.size() == varlist_size() &&
448 "Number of privates is not the same as the preallocated buffer");
449 std::copy(PL.begin(), PL.end(), varlist_end());
452 void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
453 assert(IL.size() == varlist_size() &&
454 "Number of inits is not the same as the preallocated buffer");
455 std::copy(IL.begin(), IL.end(), getPrivates().end());
458 void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
459 assert(UL.size() == varlist_size() &&
460 "Number of updates is not the same as the preallocated buffer");
461 std::copy(UL.begin(), UL.end(), getInits().end());
464 void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
465 assert(FL.size() == varlist_size() &&
466 "Number of final updates is not the same as the preallocated buffer");
467 std::copy(FL.begin(), FL.end(), getUpdates().end());
470 void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) {
472 UE.size() == varlist_size() + 1 &&
473 "Number of used expressions is not the same as the preallocated buffer");
474 std::copy(UE.begin(), UE.end(), getFinals().end() + 2);
477 OMPLinearClause *OMPLinearClause::Create(
478 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
479 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
480 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
481 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
482 Stmt *PreInit, Expr *PostUpdate) {
483 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
484 // (Step and CalcStep), list of used expression + step.
486 C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1));
487 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
488 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
489 Clause->setVarRefs(VL);
490 Clause->setPrivates(PL);
491 Clause->setInits(IL);
492 // Fill update and final expressions with zeroes, they are provided later,
493 // after the directive construction.
494 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
496 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
498 std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(),
500 Clause->setStep(Step);
501 Clause->setCalcStep(CalcStep);
502 Clause->setPreInitStmt(PreInit);
503 Clause->setPostUpdateExpr(PostUpdate);
507 OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
509 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
510 // (Step and CalcStep), list of used expression + step.
511 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars +1));
512 return new (Mem) OMPLinearClause(NumVars);
515 OMPClause::child_range OMPLinearClause::used_children() {
516 // Range includes only non-nullptr elements.
518 reinterpret_cast<Stmt **>(getUsedExprs().begin()),
519 reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr)));
523 OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
524 SourceLocation LParenLoc, SourceLocation ColonLoc,
525 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
526 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
527 OMPAlignedClause *Clause = new (Mem)
528 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
529 Clause->setVarRefs(VL);
530 Clause->setAlignment(A);
534 OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
536 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
537 return new (Mem) OMPAlignedClause(NumVars);
540 void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
541 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
542 "not the same as the "
543 "preallocated buffer");
544 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
547 void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
548 assert(DstExprs.size() == varlist_size() && "Number of destination "
549 "expressions is not the same as "
550 "the preallocated buffer");
551 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
554 void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
555 assert(AssignmentOps.size() == varlist_size() &&
556 "Number of assignment expressions is not the same as the preallocated "
558 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
559 getDestinationExprs().end());
562 OMPCopyinClause *OMPCopyinClause::Create(
563 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
564 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
565 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
566 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
567 OMPCopyinClause *Clause =
568 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
569 Clause->setVarRefs(VL);
570 Clause->setSourceExprs(SrcExprs);
571 Clause->setDestinationExprs(DstExprs);
572 Clause->setAssignmentOps(AssignmentOps);
576 OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
577 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
578 return new (Mem) OMPCopyinClause(N);
581 void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
582 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
583 "not the same as the "
584 "preallocated buffer");
585 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
588 void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
589 assert(DstExprs.size() == varlist_size() && "Number of destination "
590 "expressions is not the same as "
591 "the preallocated buffer");
592 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
595 void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
596 assert(AssignmentOps.size() == varlist_size() &&
597 "Number of assignment expressions is not the same as the preallocated "
599 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
600 getDestinationExprs().end());
603 OMPCopyprivateClause *OMPCopyprivateClause::Create(
604 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
605 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
606 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
607 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
608 OMPCopyprivateClause *Clause =
609 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
610 Clause->setVarRefs(VL);
611 Clause->setSourceExprs(SrcExprs);
612 Clause->setDestinationExprs(DstExprs);
613 Clause->setAssignmentOps(AssignmentOps);
617 OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
619 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
620 return new (Mem) OMPCopyprivateClause(N);
623 void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
624 assert(Privates.size() == varlist_size() &&
625 "Number of private copies is not the same as the preallocated buffer");
626 std::copy(Privates.begin(), Privates.end(), varlist_end());
629 void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
631 LHSExprs.size() == varlist_size() &&
632 "Number of LHS expressions is not the same as the preallocated buffer");
633 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
636 void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
638 RHSExprs.size() == varlist_size() &&
639 "Number of RHS expressions is not the same as the preallocated buffer");
640 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
643 void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
644 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
645 "expressions is not the same "
646 "as the preallocated buffer");
647 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
650 OMPReductionClause *OMPReductionClause::Create(
651 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
652 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
653 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
654 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
655 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
657 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
658 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
659 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
660 Clause->setVarRefs(VL);
661 Clause->setPrivates(Privates);
662 Clause->setLHSExprs(LHSExprs);
663 Clause->setRHSExprs(RHSExprs);
664 Clause->setReductionOps(ReductionOps);
665 Clause->setPreInitStmt(PreInit);
666 Clause->setPostUpdateExpr(PostUpdate);
670 OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
672 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
673 return new (Mem) OMPReductionClause(N);
676 void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
677 assert(Privates.size() == varlist_size() &&
678 "Number of private copies is not the same as the preallocated buffer");
679 std::copy(Privates.begin(), Privates.end(), varlist_end());
682 void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
684 LHSExprs.size() == varlist_size() &&
685 "Number of LHS expressions is not the same as the preallocated buffer");
686 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
689 void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
691 RHSExprs.size() == varlist_size() &&
692 "Number of RHS expressions is not the same as the preallocated buffer");
693 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
696 void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
697 assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
698 "expressions is not the same "
699 "as the preallocated buffer");
700 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
703 OMPTaskReductionClause *OMPTaskReductionClause::Create(
704 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
705 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
706 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
707 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
708 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
710 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
711 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
712 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
713 Clause->setVarRefs(VL);
714 Clause->setPrivates(Privates);
715 Clause->setLHSExprs(LHSExprs);
716 Clause->setRHSExprs(RHSExprs);
717 Clause->setReductionOps(ReductionOps);
718 Clause->setPreInitStmt(PreInit);
719 Clause->setPostUpdateExpr(PostUpdate);
723 OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
725 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
726 return new (Mem) OMPTaskReductionClause(N);
729 void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
730 assert(Privates.size() == varlist_size() &&
731 "Number of private copies is not the same as the preallocated buffer");
732 std::copy(Privates.begin(), Privates.end(), varlist_end());
735 void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
737 LHSExprs.size() == varlist_size() &&
738 "Number of LHS expressions is not the same as the preallocated buffer");
739 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
742 void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
744 RHSExprs.size() == varlist_size() &&
745 "Number of RHS expressions is not the same as the preallocated buffer");
746 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
749 void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
750 assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
751 "expressions is not the same "
752 "as the preallocated buffer");
753 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
756 void OMPInReductionClause::setTaskgroupDescriptors(
757 ArrayRef<Expr *> TaskgroupDescriptors) {
758 assert(TaskgroupDescriptors.size() == varlist_size() &&
759 "Number of in reduction descriptors is not the same as the "
760 "preallocated buffer");
761 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
762 getReductionOps().end());
765 OMPInReductionClause *OMPInReductionClause::Create(
766 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
767 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
768 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
769 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
770 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
771 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
772 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
773 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
774 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
775 Clause->setVarRefs(VL);
776 Clause->setPrivates(Privates);
777 Clause->setLHSExprs(LHSExprs);
778 Clause->setRHSExprs(RHSExprs);
779 Clause->setReductionOps(ReductionOps);
780 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
781 Clause->setPreInitStmt(PreInit);
782 Clause->setPostUpdateExpr(PostUpdate);
786 OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
788 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
789 return new (Mem) OMPInReductionClause(N);
793 OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc,
794 SourceLocation LParenLoc, Expr *Allocator,
795 SourceLocation ColonLoc, SourceLocation EndLoc,
796 ArrayRef<Expr *> VL) {
797 // Allocate space for private variables and initializer expressions.
798 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
799 auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
800 ColonLoc, EndLoc, VL.size());
801 Clause->setVarRefs(VL);
805 OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
807 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
808 return new (Mem) OMPAllocateClause(N);
811 OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
812 SourceLocation StartLoc,
813 SourceLocation LParenLoc,
814 SourceLocation EndLoc,
815 ArrayRef<Expr *> VL) {
816 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
817 OMPFlushClause *Clause =
818 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
819 Clause->setVarRefs(VL);
823 OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
824 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
825 return new (Mem) OMPFlushClause(N);
829 OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
830 SourceLocation LParenLoc, SourceLocation EndLoc,
831 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
832 SourceLocation ColonLoc, ArrayRef<Expr *> VL,
834 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
835 OMPDependClause *Clause = new (Mem)
836 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
837 Clause->setVarRefs(VL);
838 Clause->setDependencyKind(DepKind);
839 Clause->setDependencyLoc(DepLoc);
840 Clause->setColonLoc(ColonLoc);
841 for (unsigned I = 0 ; I < NumLoops; ++I)
842 Clause->setLoopData(I, nullptr);
846 OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
848 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
849 return new (Mem) OMPDependClause(N, NumLoops);
852 void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
853 assert((getDependencyKind() == OMPC_DEPEND_sink ||
854 getDependencyKind() == OMPC_DEPEND_source) &&
855 NumLoop < NumLoops &&
856 "Expected sink or source depend + loop index must be less number of "
858 auto It = std::next(getVarRefs().end(), NumLoop);
862 Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
863 assert((getDependencyKind() == OMPC_DEPEND_sink ||
864 getDependencyKind() == OMPC_DEPEND_source) &&
865 NumLoop < NumLoops &&
866 "Expected sink or source depend + loop index must be less number of "
868 auto It = std::next(getVarRefs().end(), NumLoop);
872 const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
873 assert((getDependencyKind() == OMPC_DEPEND_sink ||
874 getDependencyKind() == OMPC_DEPEND_source) &&
875 NumLoop < NumLoops &&
876 "Expected sink or source depend + loop index must be less number of "
878 auto It = std::next(getVarRefs().end(), NumLoop);
882 unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
883 MappableExprComponentListsRef ComponentLists) {
884 unsigned TotalNum = 0u;
885 for (auto &C : ComponentLists)
886 TotalNum += C.size();
890 unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
891 ArrayRef<const ValueDecl *> Declarations) {
892 unsigned TotalNum = 0u;
893 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
894 for (const ValueDecl *D : Declarations) {
895 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
904 OMPMapClause *OMPMapClause::Create(
905 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
906 ArrayRef<ValueDecl *> Declarations,
907 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
908 ArrayRef<OpenMPMapModifierKind> MapModifiers,
909 ArrayRef<SourceLocation> MapModifiersLoc,
910 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
911 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
912 OMPMappableExprListSizeTy Sizes;
913 Sizes.NumVars = Vars.size();
914 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
915 Sizes.NumComponentLists = ComponentLists.size();
916 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
918 // We need to allocate:
919 // 2 x NumVars x Expr* - we have an original list expression and an associated
920 // user-defined mapper for each clause list entry.
921 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
922 // with each component list.
923 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
924 // number of lists for each unique declaration and the size of each component
926 // NumComponents x MappableComponent - the total of all the components in all
928 void *Mem = C.Allocate(
929 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
930 OMPClauseMappableExprCommon::MappableComponent>(
931 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
932 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
933 Sizes.NumComponents));
934 OMPMapClause *Clause = new (Mem)
935 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
936 Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
938 Clause->setVarRefs(Vars);
939 Clause->setUDMapperRefs(UDMapperRefs);
940 Clause->setClauseInfo(Declarations, ComponentLists);
941 Clause->setMapType(Type);
942 Clause->setMapLoc(TypeLoc);
947 OMPMapClause::CreateEmpty(const ASTContext &C,
948 const OMPMappableExprListSizeTy &Sizes) {
949 void *Mem = C.Allocate(
950 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
951 OMPClauseMappableExprCommon::MappableComponent>(
952 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
953 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
954 Sizes.NumComponents));
955 return new (Mem) OMPMapClause(Sizes);
958 OMPToClause *OMPToClause::Create(
959 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
960 ArrayRef<ValueDecl *> Declarations,
961 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
962 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
963 OMPMappableExprListSizeTy Sizes;
964 Sizes.NumVars = Vars.size();
965 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
966 Sizes.NumComponentLists = ComponentLists.size();
967 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
969 // We need to allocate:
970 // 2 x NumVars x Expr* - we have an original list expression and an associated
971 // user-defined mapper for each clause list entry.
972 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
973 // with each component list.
974 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
975 // number of lists for each unique declaration and the size of each component
977 // NumComponents x MappableComponent - the total of all the components in all
979 void *Mem = C.Allocate(
980 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
981 OMPClauseMappableExprCommon::MappableComponent>(
982 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
983 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
984 Sizes.NumComponents));
986 auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
988 Clause->setVarRefs(Vars);
989 Clause->setUDMapperRefs(UDMapperRefs);
990 Clause->setClauseInfo(Declarations, ComponentLists);
994 OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
995 const OMPMappableExprListSizeTy &Sizes) {
996 void *Mem = C.Allocate(
997 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
998 OMPClauseMappableExprCommon::MappableComponent>(
999 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1000 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1001 Sizes.NumComponents));
1002 return new (Mem) OMPToClause(Sizes);
1005 OMPFromClause *OMPFromClause::Create(
1006 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1007 ArrayRef<ValueDecl *> Declarations,
1008 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1009 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
1010 OMPMappableExprListSizeTy Sizes;
1011 Sizes.NumVars = Vars.size();
1012 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1013 Sizes.NumComponentLists = ComponentLists.size();
1014 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1016 // We need to allocate:
1017 // 2 x NumVars x Expr* - we have an original list expression and an associated
1018 // user-defined mapper for each clause list entry.
1019 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1020 // with each component list.
1021 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1022 // number of lists for each unique declaration and the size of each component
1024 // NumComponents x MappableComponent - the total of all the components in all
1026 void *Mem = C.Allocate(
1027 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1028 OMPClauseMappableExprCommon::MappableComponent>(
1029 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1030 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1031 Sizes.NumComponents));
1034 new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
1036 Clause->setVarRefs(Vars);
1037 Clause->setUDMapperRefs(UDMapperRefs);
1038 Clause->setClauseInfo(Declarations, ComponentLists);
1043 OMPFromClause::CreateEmpty(const ASTContext &C,
1044 const OMPMappableExprListSizeTy &Sizes) {
1045 void *Mem = C.Allocate(
1046 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1047 OMPClauseMappableExprCommon::MappableComponent>(
1048 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1049 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1050 Sizes.NumComponents));
1051 return new (Mem) OMPFromClause(Sizes);
1054 void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1055 assert(VL.size() == varlist_size() &&
1056 "Number of private copies is not the same as the preallocated buffer");
1057 std::copy(VL.begin(), VL.end(), varlist_end());
1060 void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
1061 assert(VL.size() == varlist_size() &&
1062 "Number of inits is not the same as the preallocated buffer");
1063 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1066 OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
1067 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1068 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
1069 ArrayRef<ValueDecl *> Declarations,
1070 MappableExprComponentListsRef ComponentLists) {
1071 OMPMappableExprListSizeTy Sizes;
1072 Sizes.NumVars = Vars.size();
1073 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1074 Sizes.NumComponentLists = ComponentLists.size();
1075 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1077 // We need to allocate:
1078 // 3 x NumVars x Expr* - we have an original list expression for each clause
1079 // list entry and an equal number of private copies and inits.
1080 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1081 // with each component list.
1082 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1083 // number of lists for each unique declaration and the size of each component
1085 // NumComponents x MappableComponent - the total of all the components in all
1087 void *Mem = C.Allocate(
1088 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1089 OMPClauseMappableExprCommon::MappableComponent>(
1090 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1091 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1092 Sizes.NumComponents));
1094 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
1096 Clause->setVarRefs(Vars);
1097 Clause->setPrivateCopies(PrivateVars);
1098 Clause->setInits(Inits);
1099 Clause->setClauseInfo(Declarations, ComponentLists);
1103 OMPUseDevicePtrClause *
1104 OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
1105 const OMPMappableExprListSizeTy &Sizes) {
1106 void *Mem = C.Allocate(
1107 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1108 OMPClauseMappableExprCommon::MappableComponent>(
1109 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1110 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1111 Sizes.NumComponents));
1112 return new (Mem) OMPUseDevicePtrClause(Sizes);
1115 OMPIsDevicePtrClause *
1116 OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
1117 ArrayRef<Expr *> Vars,
1118 ArrayRef<ValueDecl *> Declarations,
1119 MappableExprComponentListsRef ComponentLists) {
1120 OMPMappableExprListSizeTy Sizes;
1121 Sizes.NumVars = Vars.size();
1122 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1123 Sizes.NumComponentLists = ComponentLists.size();
1124 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1126 // We need to allocate:
1127 // NumVars x Expr* - we have an original list expression for each clause list
1129 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1130 // with each component list.
1131 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1132 // number of lists for each unique declaration and the size of each component
1134 // NumComponents x MappableComponent - the total of all the components in all
1136 void *Mem = C.Allocate(
1137 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1138 OMPClauseMappableExprCommon::MappableComponent>(
1139 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1140 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1141 Sizes.NumComponents));
1143 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
1145 Clause->setVarRefs(Vars);
1146 Clause->setClauseInfo(Declarations, ComponentLists);
1150 OMPIsDevicePtrClause *
1151 OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1152 const OMPMappableExprListSizeTy &Sizes) {
1153 void *Mem = C.Allocate(
1154 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1155 OMPClauseMappableExprCommon::MappableComponent>(
1156 Sizes.NumVars, Sizes.NumUniqueDeclarations,
1157 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1158 Sizes.NumComponents));
1159 return new (Mem) OMPIsDevicePtrClause(Sizes);
1162 OMPNontemporalClause *OMPNontemporalClause::Create(const ASTContext &C,
1163 SourceLocation StartLoc,
1164 SourceLocation LParenLoc,
1165 SourceLocation EndLoc,
1166 ArrayRef<Expr *> VL) {
1167 // Allocate space for nontemporal variables + private references.
1168 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
1170 new (Mem) OMPNontemporalClause(StartLoc, LParenLoc, EndLoc, VL.size());
1171 Clause->setVarRefs(VL);
1175 OMPNontemporalClause *OMPNontemporalClause::CreateEmpty(const ASTContext &C,
1177 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
1178 return new (Mem) OMPNontemporalClause(N);
1181 void OMPNontemporalClause::setPrivateRefs(ArrayRef<Expr *> VL) {
1182 assert(VL.size() == varlist_size() && "Number of private references is not "
1183 "the same as the preallocated buffer");
1184 std::copy(VL.begin(), VL.end(), varlist_end());
1187 //===----------------------------------------------------------------------===//
1188 // OpenMP clauses printing methods
1189 //===----------------------------------------------------------------------===//
1191 void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1193 if (Node->getNameModifier() != llvm::omp::OMPD_unknown)
1194 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1195 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1199 void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1201 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1205 void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1206 OS << "num_threads(";
1207 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1211 void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1213 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1217 void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1219 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1223 void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
1225 Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
1229 void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1231 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1235 void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1237 << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
1241 void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1243 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind,
1244 unsigned(Node->getProcBindKind()))
1248 void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1249 OS << "unified_address";
1252 void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1253 OMPUnifiedSharedMemoryClause *) {
1254 OS << "unified_shared_memory";
1257 void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1258 OS << "reverse_offload";
1261 void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1262 OMPDynamicAllocatorsClause *) {
1263 OS << "dynamic_allocators";
1266 void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1267 OMPAtomicDefaultMemOrderClause *Node) {
1268 OS << "atomic_default_mem_order("
1269 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1270 Node->getAtomicDefaultMemOrderKind())
1274 void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1276 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1277 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1278 Node->getFirstScheduleModifier());
1279 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1281 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1282 Node->getSecondScheduleModifier());
1286 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1287 if (auto *E = Node->getChunkSize()) {
1289 E->printPretty(OS, nullptr, Policy);
1294 void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1296 if (auto *Num = Node->getNumForLoops()) {
1298 Num->printPretty(OS, nullptr, Policy, 0);
1303 void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1307 void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1311 void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1315 void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1319 void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1321 void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1323 void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
1327 void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1331 void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1335 void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1339 void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1341 void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1343 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1347 void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1349 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1353 void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1354 OS << "thread_limit(";
1355 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1359 void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1361 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1365 void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1367 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1371 void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1373 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1377 void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1379 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1383 template<typename T>
1384 void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1385 for (typename T::varlist_iterator I = Node->varlist_begin(),
1386 E = Node->varlist_end();
1388 assert(*I && "Expected non-null Stmt");
1389 OS << (I == Node->varlist_begin() ? StartSym : ',');
1390 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1391 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1392 DRE->printPretty(OS, nullptr, Policy, 0);
1394 DRE->getDecl()->printQualifiedName(OS);
1396 (*I)->printPretty(OS, nullptr, Policy, 0);
1400 void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
1401 if (Node->varlist_empty())
1404 if (Expr *Allocator = Node->getAllocator()) {
1406 Allocator->printPretty(OS, nullptr, Policy, 0);
1408 VisitOMPClauseList(Node, ' ');
1410 VisitOMPClauseList(Node, '(');
1415 void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1416 if (!Node->varlist_empty()) {
1418 VisitOMPClauseList(Node, '(');
1423 void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1424 if (!Node->varlist_empty()) {
1425 OS << "firstprivate";
1426 VisitOMPClauseList(Node, '(');
1431 void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1432 if (!Node->varlist_empty()) {
1433 OS << "lastprivate";
1434 OpenMPLastprivateModifier LPKind = Node->getKind();
1435 if (LPKind != OMPC_LASTPRIVATE_unknown) {
1437 << getOpenMPSimpleClauseTypeName(OMPC_lastprivate, Node->getKind())
1440 VisitOMPClauseList(Node, LPKind == OMPC_LASTPRIVATE_unknown ? '(' : ' ');
1445 void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1446 if (!Node->varlist_empty()) {
1448 VisitOMPClauseList(Node, '(');
1453 void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1454 if (!Node->varlist_empty()) {
1456 NestedNameSpecifier *QualifierLoc =
1457 Node->getQualifierLoc().getNestedNameSpecifier();
1458 OverloadedOperatorKind OOK =
1459 Node->getNameInfo().getName().getCXXOverloadedOperator();
1460 if (QualifierLoc == nullptr && OOK != OO_None) {
1461 // Print reduction identifier in C format
1462 OS << getOperatorSpelling(OOK);
1465 if (QualifierLoc != nullptr)
1466 QualifierLoc->print(OS, Policy);
1467 OS << Node->getNameInfo();
1470 VisitOMPClauseList(Node, ' ');
1475 void OMPClausePrinter::VisitOMPTaskReductionClause(
1476 OMPTaskReductionClause *Node) {
1477 if (!Node->varlist_empty()) {
1478 OS << "task_reduction(";
1479 NestedNameSpecifier *QualifierLoc =
1480 Node->getQualifierLoc().getNestedNameSpecifier();
1481 OverloadedOperatorKind OOK =
1482 Node->getNameInfo().getName().getCXXOverloadedOperator();
1483 if (QualifierLoc == nullptr && OOK != OO_None) {
1484 // Print reduction identifier in C format
1485 OS << getOperatorSpelling(OOK);
1488 if (QualifierLoc != nullptr)
1489 QualifierLoc->print(OS, Policy);
1490 OS << Node->getNameInfo();
1493 VisitOMPClauseList(Node, ' ');
1498 void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1499 if (!Node->varlist_empty()) {
1500 OS << "in_reduction(";
1501 NestedNameSpecifier *QualifierLoc =
1502 Node->getQualifierLoc().getNestedNameSpecifier();
1503 OverloadedOperatorKind OOK =
1504 Node->getNameInfo().getName().getCXXOverloadedOperator();
1505 if (QualifierLoc == nullptr && OOK != OO_None) {
1506 // Print reduction identifier in C format
1507 OS << getOperatorSpelling(OOK);
1510 if (QualifierLoc != nullptr)
1511 QualifierLoc->print(OS, Policy);
1512 OS << Node->getNameInfo();
1515 VisitOMPClauseList(Node, ' ');
1520 void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1521 if (!Node->varlist_empty()) {
1523 if (Node->getModifierLoc().isValid()) {
1525 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1527 VisitOMPClauseList(Node, '(');
1528 if (Node->getModifierLoc().isValid())
1530 if (Node->getStep() != nullptr) {
1532 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1538 void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1539 if (!Node->varlist_empty()) {
1541 VisitOMPClauseList(Node, '(');
1542 if (Node->getAlignment() != nullptr) {
1544 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1550 void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1551 if (!Node->varlist_empty()) {
1553 VisitOMPClauseList(Node, '(');
1558 void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1559 if (!Node->varlist_empty()) {
1560 OS << "copyprivate";
1561 VisitOMPClauseList(Node, '(');
1566 void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1567 if (!Node->varlist_empty()) {
1568 VisitOMPClauseList(Node, '(');
1573 void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1575 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1576 Node->getDependencyKind());
1577 if (!Node->varlist_empty()) {
1579 VisitOMPClauseList(Node, ' ');
1584 void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1585 if (!Node->varlist_empty()) {
1587 if (Node->getMapType() != OMPC_MAP_unknown) {
1588 for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1589 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1590 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1591 Node->getMapTypeModifier(I));
1592 if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1594 NestedNameSpecifier *MapperNNS =
1595 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1597 MapperNNS->print(OS, Policy);
1598 OS << Node->getMapperIdInfo() << ')';
1603 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1606 VisitOMPClauseList(Node, ' ');
1611 void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1612 if (!Node->varlist_empty()) {
1614 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1615 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1618 NestedNameSpecifier *MapperNNS =
1619 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1621 MapperNNS->print(OS, Policy);
1622 OS << MapperId << "):";
1623 VisitOMPClauseList(Node, ' ');
1625 VisitOMPClauseList(Node, '(');
1631 void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1632 if (!Node->varlist_empty()) {
1634 DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1635 if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1638 NestedNameSpecifier *MapperNNS =
1639 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1641 MapperNNS->print(OS, Policy);
1642 OS << MapperId << "):";
1643 VisitOMPClauseList(Node, ' ');
1645 VisitOMPClauseList(Node, '(');
1651 void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1652 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1653 OMPC_dist_schedule, Node->getDistScheduleKind());
1654 if (auto *E = Node->getChunkSize()) {
1656 E->printPretty(OS, nullptr, Policy);
1661 void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1662 OS << "defaultmap(";
1663 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1664 Node->getDefaultmapModifier());
1666 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1667 Node->getDefaultmapKind());
1671 void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1672 if (!Node->varlist_empty()) {
1673 OS << "use_device_ptr";
1674 VisitOMPClauseList(Node, '(');
1679 void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1680 if (!Node->varlist_empty()) {
1681 OS << "is_device_ptr";
1682 VisitOMPClauseList(Node, '(');
1687 void OMPClausePrinter::VisitOMPNontemporalClause(OMPNontemporalClause *Node) {
1688 if (!Node->varlist_empty()) {
1689 OS << "nontemporal";
1690 VisitOMPClauseList(Node, '(');