1 //===- OpenMPClause.cpp - Classes for OpenMP clauses ----------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the subclesses of Stmt class declared in OpenMPClause.h
11 //===----------------------------------------------------------------------===//
13 #include "clang/AST/OpenMPClause.h"
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/Attr.h"
16 #include "clang/AST/Decl.h"
17 #include "clang/AST/DeclOpenMP.h"
18 #include "clang/Basic/LLVM.h"
19 #include "clang/Basic/OpenMPKinds.h"
20 #include "clang/Basic/TargetInfo.h"
21 #include "llvm/ADT/SmallPtrSet.h"
22 #include "llvm/Support/Casting.h"
23 #include "llvm/Support/ErrorHandling.h"
28 using namespace clang
;
32 OMPClause::child_range
OMPClause::children() {
33 switch (getClauseKind()) {
36 #define GEN_CLANG_CLAUSE_CLASS
37 #define CLAUSE_CLASS(Enum, Str, Class) \
39 return static_cast<Class *>(this)->children();
40 #include "llvm/Frontend/OpenMP/OMP.inc"
42 llvm_unreachable("unknown OMPClause");
45 OMPClause::child_range
OMPClause::used_children() {
46 switch (getClauseKind()) {
47 #define GEN_CLANG_CLAUSE_CLASS
48 #define CLAUSE_CLASS(Enum, Str, Class) \
50 return static_cast<Class *>(this)->used_children();
51 #define CLAUSE_NO_CLASS(Enum, Str) \
54 #include "llvm/Frontend/OpenMP/OMP.inc"
56 llvm_unreachable("unknown OMPClause");
59 OMPClauseWithPreInit
*OMPClauseWithPreInit::get(OMPClause
*C
) {
60 auto *Res
= OMPClauseWithPreInit::get(const_cast<const OMPClause
*>(C
));
61 return Res
? const_cast<OMPClauseWithPreInit
*>(Res
) : nullptr;
64 const OMPClauseWithPreInit
*OMPClauseWithPreInit::get(const OMPClause
*C
) {
65 switch (C
->getClauseKind()) {
67 return static_cast<const OMPScheduleClause
*>(C
);
68 case OMPC_dist_schedule
:
69 return static_cast<const OMPDistScheduleClause
*>(C
);
70 case OMPC_firstprivate
:
71 return static_cast<const OMPFirstprivateClause
*>(C
);
72 case OMPC_lastprivate
:
73 return static_cast<const OMPLastprivateClause
*>(C
);
75 return static_cast<const OMPReductionClause
*>(C
);
76 case OMPC_task_reduction
:
77 return static_cast<const OMPTaskReductionClause
*>(C
);
78 case OMPC_in_reduction
:
79 return static_cast<const OMPInReductionClause
*>(C
);
81 return static_cast<const OMPLinearClause
*>(C
);
83 return static_cast<const OMPIfClause
*>(C
);
84 case OMPC_num_threads
:
85 return static_cast<const OMPNumThreadsClause
*>(C
);
87 return static_cast<const OMPNumTeamsClause
*>(C
);
88 case OMPC_thread_limit
:
89 return static_cast<const OMPThreadLimitClause
*>(C
);
91 return static_cast<const OMPDeviceClause
*>(C
);
93 return static_cast<const OMPGrainsizeClause
*>(C
);
95 return static_cast<const OMPNumTasksClause
*>(C
);
97 return static_cast<const OMPFinalClause
*>(C
);
99 return static_cast<const OMPPriorityClause
*>(C
);
100 case OMPC_novariants
:
101 return static_cast<const OMPNovariantsClause
*>(C
);
103 return static_cast<const OMPNocontextClause
*>(C
);
105 return static_cast<const OMPFilterClause
*>(C
);
106 case OMPC_ompx_dyn_cgroup_mem
:
107 return static_cast<const OMPXDynCGroupMemClause
*>(C
);
120 case OMPC_copyprivate
:
125 case OMPC_threadprivate
:
144 case OMPC_defaultmap
:
149 case OMPC_use_device_ptr
:
150 case OMPC_use_device_addr
:
151 case OMPC_is_device_ptr
:
152 case OMPC_has_device_addr
:
153 case OMPC_unified_address
:
154 case OMPC_unified_shared_memory
:
155 case OMPC_reverse_offload
:
156 case OMPC_dynamic_allocators
:
157 case OMPC_atomic_default_mem_order
:
161 case OMPC_device_type
:
163 case OMPC_nontemporal
:
169 case OMPC_uses_allocators
:
182 OMPClauseWithPostUpdate
*OMPClauseWithPostUpdate::get(OMPClause
*C
) {
183 auto *Res
= OMPClauseWithPostUpdate::get(const_cast<const OMPClause
*>(C
));
184 return Res
? const_cast<OMPClauseWithPostUpdate
*>(Res
) : nullptr;
187 const OMPClauseWithPostUpdate
*OMPClauseWithPostUpdate::get(const OMPClause
*C
) {
188 switch (C
->getClauseKind()) {
189 case OMPC_lastprivate
:
190 return static_cast<const OMPLastprivateClause
*>(C
);
192 return static_cast<const OMPReductionClause
*>(C
);
193 case OMPC_task_reduction
:
194 return static_cast<const OMPTaskReductionClause
*>(C
);
195 case OMPC_in_reduction
:
196 return static_cast<const OMPInReductionClause
*>(C
);
198 return static_cast<const OMPLinearClause
*>(C
);
200 case OMPC_dist_schedule
:
201 case OMPC_firstprivate
:
206 case OMPC_num_threads
:
217 case OMPC_copyprivate
:
222 case OMPC_threadprivate
:
241 case OMPC_thread_limit
:
247 case OMPC_defaultmap
:
252 case OMPC_use_device_ptr
:
253 case OMPC_use_device_addr
:
254 case OMPC_is_device_ptr
:
255 case OMPC_has_device_addr
:
256 case OMPC_unified_address
:
257 case OMPC_unified_shared_memory
:
258 case OMPC_reverse_offload
:
259 case OMPC_dynamic_allocators
:
260 case OMPC_atomic_default_mem_order
:
264 case OMPC_device_type
:
266 case OMPC_nontemporal
:
269 case OMPC_novariants
:
274 case OMPC_uses_allocators
:
286 /// Gets the address of the original, non-captured, expression used in the
287 /// clause as the preinitializer.
288 static Stmt
**getAddrOfExprAsWritten(Stmt
*S
) {
291 if (auto *DS
= dyn_cast
<DeclStmt
>(S
)) {
292 assert(DS
->isSingleDecl() && "Only single expression must be captured.");
293 if (auto *OED
= dyn_cast
<OMPCapturedExprDecl
>(DS
->getSingleDecl()))
294 return OED
->getInitAddress();
299 OMPClause::child_range
OMPIfClause::used_children() {
300 if (Stmt
**C
= getAddrOfExprAsWritten(getPreInitStmt()))
301 return child_range(C
, C
+ 1);
302 return child_range(&Condition
, &Condition
+ 1);
305 OMPClause::child_range
OMPGrainsizeClause::used_children() {
306 if (Stmt
**C
= getAddrOfExprAsWritten(getPreInitStmt()))
307 return child_range(C
, C
+ 1);
308 return child_range(&Grainsize
, &Grainsize
+ 1);
311 OMPClause::child_range
OMPNumTasksClause::used_children() {
312 if (Stmt
**C
= getAddrOfExprAsWritten(getPreInitStmt()))
313 return child_range(C
, C
+ 1);
314 return child_range(&NumTasks
, &NumTasks
+ 1);
317 OMPClause::child_range
OMPFinalClause::used_children() {
318 if (Stmt
**C
= getAddrOfExprAsWritten(getPreInitStmt()))
319 return child_range(C
, C
+ 1);
323 OMPClause::child_range
OMPPriorityClause::used_children() {
324 if (Stmt
**C
= getAddrOfExprAsWritten(getPreInitStmt()))
325 return child_range(C
, C
+ 1);
326 return child_range(&Priority
, &Priority
+ 1);
329 OMPClause::child_range
OMPNovariantsClause::used_children() {
330 if (Stmt
**C
= getAddrOfExprAsWritten(getPreInitStmt()))
331 return child_range(C
, C
+ 1);
335 OMPClause::child_range
OMPNocontextClause::used_children() {
336 if (Stmt
**C
= getAddrOfExprAsWritten(getPreInitStmt()))
337 return child_range(C
, C
+ 1);
341 OMPOrderedClause
*OMPOrderedClause::Create(const ASTContext
&C
, Expr
*Num
,
343 SourceLocation StartLoc
,
344 SourceLocation LParenLoc
,
345 SourceLocation EndLoc
) {
346 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(2 * NumLoops
));
348 new (Mem
) OMPOrderedClause(Num
, NumLoops
, StartLoc
, LParenLoc
, EndLoc
);
349 for (unsigned I
= 0; I
< NumLoops
; ++I
) {
350 Clause
->setLoopNumIterations(I
, nullptr);
351 Clause
->setLoopCounter(I
, nullptr);
356 OMPOrderedClause
*OMPOrderedClause::CreateEmpty(const ASTContext
&C
,
358 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(2 * NumLoops
));
359 auto *Clause
= new (Mem
) OMPOrderedClause(NumLoops
);
360 for (unsigned I
= 0; I
< NumLoops
; ++I
) {
361 Clause
->setLoopNumIterations(I
, nullptr);
362 Clause
->setLoopCounter(I
, nullptr);
367 void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop
,
368 Expr
*NumIterations
) {
369 assert(NumLoop
< NumberOfLoops
&& "out of loops number.");
370 getTrailingObjects
<Expr
*>()[NumLoop
] = NumIterations
;
373 ArrayRef
<Expr
*> OMPOrderedClause::getLoopNumIterations() const {
374 return llvm::ArrayRef(getTrailingObjects
<Expr
*>(), NumberOfLoops
);
377 void OMPOrderedClause::setLoopCounter(unsigned NumLoop
, Expr
*Counter
) {
378 assert(NumLoop
< NumberOfLoops
&& "out of loops number.");
379 getTrailingObjects
<Expr
*>()[NumberOfLoops
+ NumLoop
] = Counter
;
382 Expr
*OMPOrderedClause::getLoopCounter(unsigned NumLoop
) {
383 assert(NumLoop
< NumberOfLoops
&& "out of loops number.");
384 return getTrailingObjects
<Expr
*>()[NumberOfLoops
+ NumLoop
];
387 const Expr
*OMPOrderedClause::getLoopCounter(unsigned NumLoop
) const {
388 assert(NumLoop
< NumberOfLoops
&& "out of loops number.");
389 return getTrailingObjects
<Expr
*>()[NumberOfLoops
+ NumLoop
];
392 OMPUpdateClause
*OMPUpdateClause::Create(const ASTContext
&C
,
393 SourceLocation StartLoc
,
394 SourceLocation EndLoc
) {
395 return new (C
) OMPUpdateClause(StartLoc
, EndLoc
, /*IsExtended=*/false);
399 OMPUpdateClause::Create(const ASTContext
&C
, SourceLocation StartLoc
,
400 SourceLocation LParenLoc
, SourceLocation ArgumentLoc
,
401 OpenMPDependClauseKind DK
, SourceLocation EndLoc
) {
403 C
.Allocate(totalSizeToAlloc
<SourceLocation
, OpenMPDependClauseKind
>(2, 1),
404 alignof(OMPUpdateClause
));
406 new (Mem
) OMPUpdateClause(StartLoc
, EndLoc
, /*IsExtended=*/true);
407 Clause
->setLParenLoc(LParenLoc
);
408 Clause
->setArgumentLoc(ArgumentLoc
);
409 Clause
->setDependencyKind(DK
);
413 OMPUpdateClause
*OMPUpdateClause::CreateEmpty(const ASTContext
&C
,
416 return new (C
) OMPUpdateClause(/*IsExtended=*/false);
418 C
.Allocate(totalSizeToAlloc
<SourceLocation
, OpenMPDependClauseKind
>(2, 1),
419 alignof(OMPUpdateClause
));
420 auto *Clause
= new (Mem
) OMPUpdateClause(/*IsExtended=*/true);
421 Clause
->IsExtended
= true;
425 void OMPPrivateClause::setPrivateCopies(ArrayRef
<Expr
*> VL
) {
426 assert(VL
.size() == varlist_size() &&
427 "Number of private copies is not the same as the preallocated buffer");
428 std::copy(VL
.begin(), VL
.end(), varlist_end());
432 OMPPrivateClause::Create(const ASTContext
&C
, SourceLocation StartLoc
,
433 SourceLocation LParenLoc
, SourceLocation EndLoc
,
434 ArrayRef
<Expr
*> VL
, ArrayRef
<Expr
*> PrivateVL
) {
435 // Allocate space for private variables and initializer expressions.
436 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(2 * VL
.size()));
437 OMPPrivateClause
*Clause
=
438 new (Mem
) OMPPrivateClause(StartLoc
, LParenLoc
, EndLoc
, VL
.size());
439 Clause
->setVarRefs(VL
);
440 Clause
->setPrivateCopies(PrivateVL
);
444 OMPPrivateClause
*OMPPrivateClause::CreateEmpty(const ASTContext
&C
,
446 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(2 * N
));
447 return new (Mem
) OMPPrivateClause(N
);
450 void OMPFirstprivateClause::setPrivateCopies(ArrayRef
<Expr
*> VL
) {
451 assert(VL
.size() == varlist_size() &&
452 "Number of private copies is not the same as the preallocated buffer");
453 std::copy(VL
.begin(), VL
.end(), varlist_end());
456 void OMPFirstprivateClause::setInits(ArrayRef
<Expr
*> VL
) {
457 assert(VL
.size() == varlist_size() &&
458 "Number of inits is not the same as the preallocated buffer");
459 std::copy(VL
.begin(), VL
.end(), getPrivateCopies().end());
462 OMPFirstprivateClause
*
463 OMPFirstprivateClause::Create(const ASTContext
&C
, SourceLocation StartLoc
,
464 SourceLocation LParenLoc
, SourceLocation EndLoc
,
465 ArrayRef
<Expr
*> VL
, ArrayRef
<Expr
*> PrivateVL
,
466 ArrayRef
<Expr
*> InitVL
, Stmt
*PreInit
) {
467 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(3 * VL
.size()));
468 OMPFirstprivateClause
*Clause
=
469 new (Mem
) OMPFirstprivateClause(StartLoc
, LParenLoc
, EndLoc
, VL
.size());
470 Clause
->setVarRefs(VL
);
471 Clause
->setPrivateCopies(PrivateVL
);
472 Clause
->setInits(InitVL
);
473 Clause
->setPreInitStmt(PreInit
);
477 OMPFirstprivateClause
*OMPFirstprivateClause::CreateEmpty(const ASTContext
&C
,
479 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(3 * N
));
480 return new (Mem
) OMPFirstprivateClause(N
);
483 void OMPLastprivateClause::setPrivateCopies(ArrayRef
<Expr
*> PrivateCopies
) {
484 assert(PrivateCopies
.size() == varlist_size() &&
485 "Number of private copies is not the same as the preallocated buffer");
486 std::copy(PrivateCopies
.begin(), PrivateCopies
.end(), varlist_end());
489 void OMPLastprivateClause::setSourceExprs(ArrayRef
<Expr
*> SrcExprs
) {
490 assert(SrcExprs
.size() == varlist_size() && "Number of source expressions is "
491 "not the same as the "
492 "preallocated buffer");
493 std::copy(SrcExprs
.begin(), SrcExprs
.end(), getPrivateCopies().end());
496 void OMPLastprivateClause::setDestinationExprs(ArrayRef
<Expr
*> DstExprs
) {
497 assert(DstExprs
.size() == varlist_size() && "Number of destination "
498 "expressions is not the same as "
499 "the preallocated buffer");
500 std::copy(DstExprs
.begin(), DstExprs
.end(), getSourceExprs().end());
503 void OMPLastprivateClause::setAssignmentOps(ArrayRef
<Expr
*> AssignmentOps
) {
504 assert(AssignmentOps
.size() == varlist_size() &&
505 "Number of assignment expressions is not the same as the preallocated "
507 std::copy(AssignmentOps
.begin(), AssignmentOps
.end(),
508 getDestinationExprs().end());
511 OMPLastprivateClause
*OMPLastprivateClause::Create(
512 const ASTContext
&C
, SourceLocation StartLoc
, SourceLocation LParenLoc
,
513 SourceLocation EndLoc
, ArrayRef
<Expr
*> VL
, ArrayRef
<Expr
*> SrcExprs
,
514 ArrayRef
<Expr
*> DstExprs
, ArrayRef
<Expr
*> AssignmentOps
,
515 OpenMPLastprivateModifier LPKind
, SourceLocation LPKindLoc
,
516 SourceLocation ColonLoc
, Stmt
*PreInit
, Expr
*PostUpdate
) {
517 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(5 * VL
.size()));
518 OMPLastprivateClause
*Clause
= new (Mem
) OMPLastprivateClause(
519 StartLoc
, LParenLoc
, EndLoc
, LPKind
, LPKindLoc
, ColonLoc
, VL
.size());
520 Clause
->setVarRefs(VL
);
521 Clause
->setSourceExprs(SrcExprs
);
522 Clause
->setDestinationExprs(DstExprs
);
523 Clause
->setAssignmentOps(AssignmentOps
);
524 Clause
->setPreInitStmt(PreInit
);
525 Clause
->setPostUpdateExpr(PostUpdate
);
529 OMPLastprivateClause
*OMPLastprivateClause::CreateEmpty(const ASTContext
&C
,
531 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(5 * N
));
532 return new (Mem
) OMPLastprivateClause(N
);
535 OMPSharedClause
*OMPSharedClause::Create(const ASTContext
&C
,
536 SourceLocation StartLoc
,
537 SourceLocation LParenLoc
,
538 SourceLocation EndLoc
,
539 ArrayRef
<Expr
*> VL
) {
540 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(VL
.size()));
541 OMPSharedClause
*Clause
=
542 new (Mem
) OMPSharedClause(StartLoc
, LParenLoc
, EndLoc
, VL
.size());
543 Clause
->setVarRefs(VL
);
547 OMPSharedClause
*OMPSharedClause::CreateEmpty(const ASTContext
&C
, unsigned N
) {
548 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(N
));
549 return new (Mem
) OMPSharedClause(N
);
552 void OMPLinearClause::setPrivates(ArrayRef
<Expr
*> PL
) {
553 assert(PL
.size() == varlist_size() &&
554 "Number of privates is not the same as the preallocated buffer");
555 std::copy(PL
.begin(), PL
.end(), varlist_end());
558 void OMPLinearClause::setInits(ArrayRef
<Expr
*> IL
) {
559 assert(IL
.size() == varlist_size() &&
560 "Number of inits is not the same as the preallocated buffer");
561 std::copy(IL
.begin(), IL
.end(), getPrivates().end());
564 void OMPLinearClause::setUpdates(ArrayRef
<Expr
*> UL
) {
565 assert(UL
.size() == varlist_size() &&
566 "Number of updates is not the same as the preallocated buffer");
567 std::copy(UL
.begin(), UL
.end(), getInits().end());
570 void OMPLinearClause::setFinals(ArrayRef
<Expr
*> FL
) {
571 assert(FL
.size() == varlist_size() &&
572 "Number of final updates is not the same as the preallocated buffer");
573 std::copy(FL
.begin(), FL
.end(), getUpdates().end());
576 void OMPLinearClause::setUsedExprs(ArrayRef
<Expr
*> UE
) {
578 UE
.size() == varlist_size() + 1 &&
579 "Number of used expressions is not the same as the preallocated buffer");
580 std::copy(UE
.begin(), UE
.end(), getFinals().end() + 2);
583 OMPLinearClause
*OMPLinearClause::Create(
584 const ASTContext
&C
, SourceLocation StartLoc
, SourceLocation LParenLoc
,
585 OpenMPLinearClauseKind Modifier
, SourceLocation ModifierLoc
,
586 SourceLocation ColonLoc
, SourceLocation StepModifierLoc
,
587 SourceLocation EndLoc
, ArrayRef
<Expr
*> VL
, ArrayRef
<Expr
*> PL
,
588 ArrayRef
<Expr
*> IL
, Expr
*Step
, Expr
*CalcStep
, Stmt
*PreInit
,
590 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
591 // (Step and CalcStep), list of used expression + step.
593 C
.Allocate(totalSizeToAlloc
<Expr
*>(5 * VL
.size() + 2 + VL
.size() + 1));
594 OMPLinearClause
*Clause
=
595 new (Mem
) OMPLinearClause(StartLoc
, LParenLoc
, Modifier
, ModifierLoc
,
596 ColonLoc
, StepModifierLoc
, EndLoc
, VL
.size());
597 Clause
->setVarRefs(VL
);
598 Clause
->setPrivates(PL
);
599 Clause
->setInits(IL
);
600 // Fill update and final expressions with zeroes, they are provided later,
601 // after the directive construction.
602 std::fill(Clause
->getInits().end(), Clause
->getInits().end() + VL
.size(),
604 std::fill(Clause
->getUpdates().end(), Clause
->getUpdates().end() + VL
.size(),
606 std::fill(Clause
->getUsedExprs().begin(), Clause
->getUsedExprs().end(),
608 Clause
->setStep(Step
);
609 Clause
->setCalcStep(CalcStep
);
610 Clause
->setPreInitStmt(PreInit
);
611 Clause
->setPostUpdateExpr(PostUpdate
);
615 OMPLinearClause
*OMPLinearClause::CreateEmpty(const ASTContext
&C
,
617 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
618 // (Step and CalcStep), list of used expression + step.
619 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(5 * NumVars
+ 2 + NumVars
+1));
620 return new (Mem
) OMPLinearClause(NumVars
);
623 OMPClause::child_range
OMPLinearClause::used_children() {
624 // Range includes only non-nullptr elements.
626 reinterpret_cast<Stmt
**>(getUsedExprs().begin()),
627 reinterpret_cast<Stmt
**>(llvm::find(getUsedExprs(), nullptr)));
631 OMPAlignedClause::Create(const ASTContext
&C
, SourceLocation StartLoc
,
632 SourceLocation LParenLoc
, SourceLocation ColonLoc
,
633 SourceLocation EndLoc
, ArrayRef
<Expr
*> VL
, Expr
*A
) {
634 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(VL
.size() + 1));
635 OMPAlignedClause
*Clause
= new (Mem
)
636 OMPAlignedClause(StartLoc
, LParenLoc
, ColonLoc
, EndLoc
, VL
.size());
637 Clause
->setVarRefs(VL
);
638 Clause
->setAlignment(A
);
642 OMPAlignedClause
*OMPAlignedClause::CreateEmpty(const ASTContext
&C
,
644 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(NumVars
+ 1));
645 return new (Mem
) OMPAlignedClause(NumVars
);
648 OMPAlignClause
*OMPAlignClause::Create(const ASTContext
&C
, Expr
*A
,
649 SourceLocation StartLoc
,
650 SourceLocation LParenLoc
,
651 SourceLocation EndLoc
) {
652 return new (C
) OMPAlignClause(A
, StartLoc
, LParenLoc
, EndLoc
);
655 void OMPCopyinClause::setSourceExprs(ArrayRef
<Expr
*> SrcExprs
) {
656 assert(SrcExprs
.size() == varlist_size() && "Number of source expressions is "
657 "not the same as the "
658 "preallocated buffer");
659 std::copy(SrcExprs
.begin(), SrcExprs
.end(), varlist_end());
662 void OMPCopyinClause::setDestinationExprs(ArrayRef
<Expr
*> DstExprs
) {
663 assert(DstExprs
.size() == varlist_size() && "Number of destination "
664 "expressions is not the same as "
665 "the preallocated buffer");
666 std::copy(DstExprs
.begin(), DstExprs
.end(), getSourceExprs().end());
669 void OMPCopyinClause::setAssignmentOps(ArrayRef
<Expr
*> AssignmentOps
) {
670 assert(AssignmentOps
.size() == varlist_size() &&
671 "Number of assignment expressions is not the same as the preallocated "
673 std::copy(AssignmentOps
.begin(), AssignmentOps
.end(),
674 getDestinationExprs().end());
677 OMPCopyinClause
*OMPCopyinClause::Create(
678 const ASTContext
&C
, SourceLocation StartLoc
, SourceLocation LParenLoc
,
679 SourceLocation EndLoc
, ArrayRef
<Expr
*> VL
, ArrayRef
<Expr
*> SrcExprs
,
680 ArrayRef
<Expr
*> DstExprs
, ArrayRef
<Expr
*> AssignmentOps
) {
681 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(4 * VL
.size()));
682 OMPCopyinClause
*Clause
=
683 new (Mem
) OMPCopyinClause(StartLoc
, LParenLoc
, EndLoc
, VL
.size());
684 Clause
->setVarRefs(VL
);
685 Clause
->setSourceExprs(SrcExprs
);
686 Clause
->setDestinationExprs(DstExprs
);
687 Clause
->setAssignmentOps(AssignmentOps
);
691 OMPCopyinClause
*OMPCopyinClause::CreateEmpty(const ASTContext
&C
, unsigned N
) {
692 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(4 * N
));
693 return new (Mem
) OMPCopyinClause(N
);
696 void OMPCopyprivateClause::setSourceExprs(ArrayRef
<Expr
*> SrcExprs
) {
697 assert(SrcExprs
.size() == varlist_size() && "Number of source expressions is "
698 "not the same as the "
699 "preallocated buffer");
700 std::copy(SrcExprs
.begin(), SrcExprs
.end(), varlist_end());
703 void OMPCopyprivateClause::setDestinationExprs(ArrayRef
<Expr
*> DstExprs
) {
704 assert(DstExprs
.size() == varlist_size() && "Number of destination "
705 "expressions is not the same as "
706 "the preallocated buffer");
707 std::copy(DstExprs
.begin(), DstExprs
.end(), getSourceExprs().end());
710 void OMPCopyprivateClause::setAssignmentOps(ArrayRef
<Expr
*> AssignmentOps
) {
711 assert(AssignmentOps
.size() == varlist_size() &&
712 "Number of assignment expressions is not the same as the preallocated "
714 std::copy(AssignmentOps
.begin(), AssignmentOps
.end(),
715 getDestinationExprs().end());
718 OMPCopyprivateClause
*OMPCopyprivateClause::Create(
719 const ASTContext
&C
, SourceLocation StartLoc
, SourceLocation LParenLoc
,
720 SourceLocation EndLoc
, ArrayRef
<Expr
*> VL
, ArrayRef
<Expr
*> SrcExprs
,
721 ArrayRef
<Expr
*> DstExprs
, ArrayRef
<Expr
*> AssignmentOps
) {
722 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(4 * VL
.size()));
723 OMPCopyprivateClause
*Clause
=
724 new (Mem
) OMPCopyprivateClause(StartLoc
, LParenLoc
, EndLoc
, VL
.size());
725 Clause
->setVarRefs(VL
);
726 Clause
->setSourceExprs(SrcExprs
);
727 Clause
->setDestinationExprs(DstExprs
);
728 Clause
->setAssignmentOps(AssignmentOps
);
732 OMPCopyprivateClause
*OMPCopyprivateClause::CreateEmpty(const ASTContext
&C
,
734 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(4 * N
));
735 return new (Mem
) OMPCopyprivateClause(N
);
738 void OMPReductionClause::setPrivates(ArrayRef
<Expr
*> Privates
) {
739 assert(Privates
.size() == varlist_size() &&
740 "Number of private copies is not the same as the preallocated buffer");
741 std::copy(Privates
.begin(), Privates
.end(), varlist_end());
744 void OMPReductionClause::setLHSExprs(ArrayRef
<Expr
*> LHSExprs
) {
746 LHSExprs
.size() == varlist_size() &&
747 "Number of LHS expressions is not the same as the preallocated buffer");
748 std::copy(LHSExprs
.begin(), LHSExprs
.end(), getPrivates().end());
751 void OMPReductionClause::setRHSExprs(ArrayRef
<Expr
*> RHSExprs
) {
753 RHSExprs
.size() == varlist_size() &&
754 "Number of RHS expressions is not the same as the preallocated buffer");
755 std::copy(RHSExprs
.begin(), RHSExprs
.end(), getLHSExprs().end());
758 void OMPReductionClause::setReductionOps(ArrayRef
<Expr
*> ReductionOps
) {
759 assert(ReductionOps
.size() == varlist_size() && "Number of reduction "
760 "expressions is not the same "
761 "as the preallocated buffer");
762 std::copy(ReductionOps
.begin(), ReductionOps
.end(), getRHSExprs().end());
765 void OMPReductionClause::setInscanCopyOps(ArrayRef
<Expr
*> Ops
) {
766 assert(Modifier
== OMPC_REDUCTION_inscan
&& "Expected inscan reduction.");
767 assert(Ops
.size() == varlist_size() && "Number of copy "
768 "expressions is not the same "
769 "as the preallocated buffer");
770 llvm::copy(Ops
, getReductionOps().end());
773 void OMPReductionClause::setInscanCopyArrayTemps(
774 ArrayRef
<Expr
*> CopyArrayTemps
) {
775 assert(Modifier
== OMPC_REDUCTION_inscan
&& "Expected inscan reduction.");
776 assert(CopyArrayTemps
.size() == varlist_size() &&
777 "Number of copy temp expressions is not the same as the preallocated "
779 llvm::copy(CopyArrayTemps
, getInscanCopyOps().end());
782 void OMPReductionClause::setInscanCopyArrayElems(
783 ArrayRef
<Expr
*> CopyArrayElems
) {
784 assert(Modifier
== OMPC_REDUCTION_inscan
&& "Expected inscan reduction.");
785 assert(CopyArrayElems
.size() == varlist_size() &&
786 "Number of copy temp expressions is not the same as the preallocated "
788 llvm::copy(CopyArrayElems
, getInscanCopyArrayTemps().end());
791 OMPReductionClause
*OMPReductionClause::Create(
792 const ASTContext
&C
, SourceLocation StartLoc
, SourceLocation LParenLoc
,
793 SourceLocation ModifierLoc
, SourceLocation EndLoc
, SourceLocation ColonLoc
,
794 OpenMPReductionClauseModifier Modifier
, ArrayRef
<Expr
*> VL
,
795 NestedNameSpecifierLoc QualifierLoc
, const DeclarationNameInfo
&NameInfo
,
796 ArrayRef
<Expr
*> Privates
, ArrayRef
<Expr
*> LHSExprs
,
797 ArrayRef
<Expr
*> RHSExprs
, ArrayRef
<Expr
*> ReductionOps
,
798 ArrayRef
<Expr
*> CopyOps
, ArrayRef
<Expr
*> CopyArrayTemps
,
799 ArrayRef
<Expr
*> CopyArrayElems
, Stmt
*PreInit
, Expr
*PostUpdate
) {
800 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(
801 (Modifier
== OMPC_REDUCTION_inscan
? 8 : 5) * VL
.size()));
802 auto *Clause
= new (Mem
)
803 OMPReductionClause(StartLoc
, LParenLoc
, ModifierLoc
, EndLoc
, ColonLoc
,
804 Modifier
, VL
.size(), QualifierLoc
, NameInfo
);
805 Clause
->setVarRefs(VL
);
806 Clause
->setPrivates(Privates
);
807 Clause
->setLHSExprs(LHSExprs
);
808 Clause
->setRHSExprs(RHSExprs
);
809 Clause
->setReductionOps(ReductionOps
);
810 Clause
->setPreInitStmt(PreInit
);
811 Clause
->setPostUpdateExpr(PostUpdate
);
812 if (Modifier
== OMPC_REDUCTION_inscan
) {
813 Clause
->setInscanCopyOps(CopyOps
);
814 Clause
->setInscanCopyArrayTemps(CopyArrayTemps
);
815 Clause
->setInscanCopyArrayElems(CopyArrayElems
);
817 assert(CopyOps
.empty() &&
818 "copy operations are expected in inscan reductions only.");
819 assert(CopyArrayTemps
.empty() &&
820 "copy array temps are expected in inscan reductions only.");
821 assert(CopyArrayElems
.empty() &&
822 "copy array temps are expected in inscan reductions only.");
828 OMPReductionClause::CreateEmpty(const ASTContext
&C
, unsigned N
,
829 OpenMPReductionClauseModifier Modifier
) {
830 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(
831 (Modifier
== OMPC_REDUCTION_inscan
? 8 : 5) * N
));
832 auto *Clause
= new (Mem
) OMPReductionClause(N
);
833 Clause
->setModifier(Modifier
);
837 void OMPTaskReductionClause::setPrivates(ArrayRef
<Expr
*> Privates
) {
838 assert(Privates
.size() == varlist_size() &&
839 "Number of private copies is not the same as the preallocated buffer");
840 std::copy(Privates
.begin(), Privates
.end(), varlist_end());
843 void OMPTaskReductionClause::setLHSExprs(ArrayRef
<Expr
*> LHSExprs
) {
845 LHSExprs
.size() == varlist_size() &&
846 "Number of LHS expressions is not the same as the preallocated buffer");
847 std::copy(LHSExprs
.begin(), LHSExprs
.end(), getPrivates().end());
850 void OMPTaskReductionClause::setRHSExprs(ArrayRef
<Expr
*> RHSExprs
) {
852 RHSExprs
.size() == varlist_size() &&
853 "Number of RHS expressions is not the same as the preallocated buffer");
854 std::copy(RHSExprs
.begin(), RHSExprs
.end(), getLHSExprs().end());
857 void OMPTaskReductionClause::setReductionOps(ArrayRef
<Expr
*> ReductionOps
) {
858 assert(ReductionOps
.size() == varlist_size() && "Number of task reduction "
859 "expressions is not the same "
860 "as the preallocated buffer");
861 std::copy(ReductionOps
.begin(), ReductionOps
.end(), getRHSExprs().end());
864 OMPTaskReductionClause
*OMPTaskReductionClause::Create(
865 const ASTContext
&C
, SourceLocation StartLoc
, SourceLocation LParenLoc
,
866 SourceLocation EndLoc
, SourceLocation ColonLoc
, ArrayRef
<Expr
*> VL
,
867 NestedNameSpecifierLoc QualifierLoc
, const DeclarationNameInfo
&NameInfo
,
868 ArrayRef
<Expr
*> Privates
, ArrayRef
<Expr
*> LHSExprs
,
869 ArrayRef
<Expr
*> RHSExprs
, ArrayRef
<Expr
*> ReductionOps
, Stmt
*PreInit
,
871 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(5 * VL
.size()));
872 OMPTaskReductionClause
*Clause
= new (Mem
) OMPTaskReductionClause(
873 StartLoc
, LParenLoc
, EndLoc
, ColonLoc
, VL
.size(), QualifierLoc
, NameInfo
);
874 Clause
->setVarRefs(VL
);
875 Clause
->setPrivates(Privates
);
876 Clause
->setLHSExprs(LHSExprs
);
877 Clause
->setRHSExprs(RHSExprs
);
878 Clause
->setReductionOps(ReductionOps
);
879 Clause
->setPreInitStmt(PreInit
);
880 Clause
->setPostUpdateExpr(PostUpdate
);
884 OMPTaskReductionClause
*OMPTaskReductionClause::CreateEmpty(const ASTContext
&C
,
886 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(5 * N
));
887 return new (Mem
) OMPTaskReductionClause(N
);
890 void OMPInReductionClause::setPrivates(ArrayRef
<Expr
*> Privates
) {
891 assert(Privates
.size() == varlist_size() &&
892 "Number of private copies is not the same as the preallocated buffer");
893 std::copy(Privates
.begin(), Privates
.end(), varlist_end());
896 void OMPInReductionClause::setLHSExprs(ArrayRef
<Expr
*> LHSExprs
) {
898 LHSExprs
.size() == varlist_size() &&
899 "Number of LHS expressions is not the same as the preallocated buffer");
900 std::copy(LHSExprs
.begin(), LHSExprs
.end(), getPrivates().end());
903 void OMPInReductionClause::setRHSExprs(ArrayRef
<Expr
*> RHSExprs
) {
905 RHSExprs
.size() == varlist_size() &&
906 "Number of RHS expressions is not the same as the preallocated buffer");
907 std::copy(RHSExprs
.begin(), RHSExprs
.end(), getLHSExprs().end());
910 void OMPInReductionClause::setReductionOps(ArrayRef
<Expr
*> ReductionOps
) {
911 assert(ReductionOps
.size() == varlist_size() && "Number of in reduction "
912 "expressions is not the same "
913 "as the preallocated buffer");
914 std::copy(ReductionOps
.begin(), ReductionOps
.end(), getRHSExprs().end());
917 void OMPInReductionClause::setTaskgroupDescriptors(
918 ArrayRef
<Expr
*> TaskgroupDescriptors
) {
919 assert(TaskgroupDescriptors
.size() == varlist_size() &&
920 "Number of in reduction descriptors is not the same as the "
921 "preallocated buffer");
922 std::copy(TaskgroupDescriptors
.begin(), TaskgroupDescriptors
.end(),
923 getReductionOps().end());
926 OMPInReductionClause
*OMPInReductionClause::Create(
927 const ASTContext
&C
, SourceLocation StartLoc
, SourceLocation LParenLoc
,
928 SourceLocation EndLoc
, SourceLocation ColonLoc
, ArrayRef
<Expr
*> VL
,
929 NestedNameSpecifierLoc QualifierLoc
, const DeclarationNameInfo
&NameInfo
,
930 ArrayRef
<Expr
*> Privates
, ArrayRef
<Expr
*> LHSExprs
,
931 ArrayRef
<Expr
*> RHSExprs
, ArrayRef
<Expr
*> ReductionOps
,
932 ArrayRef
<Expr
*> TaskgroupDescriptors
, Stmt
*PreInit
, Expr
*PostUpdate
) {
933 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(6 * VL
.size()));
934 OMPInReductionClause
*Clause
= new (Mem
) OMPInReductionClause(
935 StartLoc
, LParenLoc
, EndLoc
, ColonLoc
, VL
.size(), QualifierLoc
, NameInfo
);
936 Clause
->setVarRefs(VL
);
937 Clause
->setPrivates(Privates
);
938 Clause
->setLHSExprs(LHSExprs
);
939 Clause
->setRHSExprs(RHSExprs
);
940 Clause
->setReductionOps(ReductionOps
);
941 Clause
->setTaskgroupDescriptors(TaskgroupDescriptors
);
942 Clause
->setPreInitStmt(PreInit
);
943 Clause
->setPostUpdateExpr(PostUpdate
);
947 OMPInReductionClause
*OMPInReductionClause::CreateEmpty(const ASTContext
&C
,
949 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(6 * N
));
950 return new (Mem
) OMPInReductionClause(N
);
953 OMPSizesClause
*OMPSizesClause::Create(const ASTContext
&C
,
954 SourceLocation StartLoc
,
955 SourceLocation LParenLoc
,
956 SourceLocation EndLoc
,
957 ArrayRef
<Expr
*> Sizes
) {
958 OMPSizesClause
*Clause
= CreateEmpty(C
, Sizes
.size());
959 Clause
->setLocStart(StartLoc
);
960 Clause
->setLParenLoc(LParenLoc
);
961 Clause
->setLocEnd(EndLoc
);
962 Clause
->setSizesRefs(Sizes
);
966 OMPSizesClause
*OMPSizesClause::CreateEmpty(const ASTContext
&C
,
968 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(NumSizes
));
969 return new (Mem
) OMPSizesClause(NumSizes
);
972 OMPFullClause
*OMPFullClause::Create(const ASTContext
&C
,
973 SourceLocation StartLoc
,
974 SourceLocation EndLoc
) {
975 OMPFullClause
*Clause
= CreateEmpty(C
);
976 Clause
->setLocStart(StartLoc
);
977 Clause
->setLocEnd(EndLoc
);
981 OMPFullClause
*OMPFullClause::CreateEmpty(const ASTContext
&C
) {
982 return new (C
) OMPFullClause();
985 OMPPartialClause
*OMPPartialClause::Create(const ASTContext
&C
,
986 SourceLocation StartLoc
,
987 SourceLocation LParenLoc
,
988 SourceLocation EndLoc
,
990 OMPPartialClause
*Clause
= CreateEmpty(C
);
991 Clause
->setLocStart(StartLoc
);
992 Clause
->setLParenLoc(LParenLoc
);
993 Clause
->setLocEnd(EndLoc
);
994 Clause
->setFactor(Factor
);
998 OMPPartialClause
*OMPPartialClause::CreateEmpty(const ASTContext
&C
) {
999 return new (C
) OMPPartialClause();
1003 OMPAllocateClause::Create(const ASTContext
&C
, SourceLocation StartLoc
,
1004 SourceLocation LParenLoc
, Expr
*Allocator
,
1005 SourceLocation ColonLoc
, SourceLocation EndLoc
,
1006 ArrayRef
<Expr
*> VL
) {
1007 // Allocate space for private variables and initializer expressions.
1008 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(VL
.size()));
1009 auto *Clause
= new (Mem
) OMPAllocateClause(StartLoc
, LParenLoc
, Allocator
,
1010 ColonLoc
, EndLoc
, VL
.size());
1011 Clause
->setVarRefs(VL
);
1015 OMPAllocateClause
*OMPAllocateClause::CreateEmpty(const ASTContext
&C
,
1017 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(N
));
1018 return new (Mem
) OMPAllocateClause(N
);
1021 OMPFlushClause
*OMPFlushClause::Create(const ASTContext
&C
,
1022 SourceLocation StartLoc
,
1023 SourceLocation LParenLoc
,
1024 SourceLocation EndLoc
,
1025 ArrayRef
<Expr
*> VL
) {
1026 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(VL
.size() + 1));
1027 OMPFlushClause
*Clause
=
1028 new (Mem
) OMPFlushClause(StartLoc
, LParenLoc
, EndLoc
, VL
.size());
1029 Clause
->setVarRefs(VL
);
1033 OMPFlushClause
*OMPFlushClause::CreateEmpty(const ASTContext
&C
, unsigned N
) {
1034 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(N
));
1035 return new (Mem
) OMPFlushClause(N
);
1038 OMPDepobjClause
*OMPDepobjClause::Create(const ASTContext
&C
,
1039 SourceLocation StartLoc
,
1040 SourceLocation LParenLoc
,
1041 SourceLocation RParenLoc
,
1043 auto *Clause
= new (C
) OMPDepobjClause(StartLoc
, LParenLoc
, RParenLoc
);
1044 Clause
->setDepobj(Depobj
);
1048 OMPDepobjClause
*OMPDepobjClause::CreateEmpty(const ASTContext
&C
) {
1049 return new (C
) OMPDepobjClause();
1053 OMPDependClause::Create(const ASTContext
&C
, SourceLocation StartLoc
,
1054 SourceLocation LParenLoc
, SourceLocation EndLoc
,
1055 DependDataTy Data
, Expr
*DepModifier
,
1056 ArrayRef
<Expr
*> VL
, unsigned NumLoops
) {
1057 void *Mem
= C
.Allocate(
1058 totalSizeToAlloc
<Expr
*>(VL
.size() + /*depend-modifier*/ 1 + NumLoops
),
1059 alignof(OMPDependClause
));
1060 OMPDependClause
*Clause
= new (Mem
)
1061 OMPDependClause(StartLoc
, LParenLoc
, EndLoc
, VL
.size(), NumLoops
);
1062 Clause
->setDependencyKind(Data
.DepKind
);
1063 Clause
->setDependencyLoc(Data
.DepLoc
);
1064 Clause
->setColonLoc(Data
.ColonLoc
);
1065 Clause
->setOmpAllMemoryLoc(Data
.OmpAllMemoryLoc
);
1066 Clause
->setModifier(DepModifier
);
1067 Clause
->setVarRefs(VL
);
1068 for (unsigned I
= 0 ; I
< NumLoops
; ++I
)
1069 Clause
->setLoopData(I
, nullptr);
1073 OMPDependClause
*OMPDependClause::CreateEmpty(const ASTContext
&C
, unsigned N
,
1074 unsigned NumLoops
) {
1076 C
.Allocate(totalSizeToAlloc
<Expr
*>(N
+ /*depend-modifier*/ 1 + NumLoops
),
1077 alignof(OMPDependClause
));
1078 return new (Mem
) OMPDependClause(N
, NumLoops
);
1081 void OMPDependClause::setLoopData(unsigned NumLoop
, Expr
*Cnt
) {
1082 assert((getDependencyKind() == OMPC_DEPEND_sink
||
1083 getDependencyKind() == OMPC_DEPEND_source
) &&
1084 NumLoop
< NumLoops
&&
1085 "Expected sink or source depend + loop index must be less number of "
1087 auto *It
= std::next(getVarRefs().end(), NumLoop
+ 1);
1091 Expr
*OMPDependClause::getLoopData(unsigned NumLoop
) {
1092 assert((getDependencyKind() == OMPC_DEPEND_sink
||
1093 getDependencyKind() == OMPC_DEPEND_source
) &&
1094 NumLoop
< NumLoops
&&
1095 "Expected sink or source depend + loop index must be less number of "
1097 auto *It
= std::next(getVarRefs().end(), NumLoop
+ 1);
1101 const Expr
*OMPDependClause::getLoopData(unsigned NumLoop
) const {
1102 assert((getDependencyKind() == OMPC_DEPEND_sink
||
1103 getDependencyKind() == OMPC_DEPEND_source
) &&
1104 NumLoop
< NumLoops
&&
1105 "Expected sink or source depend + loop index must be less number of "
1107 const auto *It
= std::next(getVarRefs().end(), NumLoop
+ 1);
1111 void OMPDependClause::setModifier(Expr
*DepModifier
) {
1112 *getVarRefs().end() = DepModifier
;
1114 Expr
*OMPDependClause::getModifier() { return *getVarRefs().end(); }
1116 unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
1117 MappableExprComponentListsRef ComponentLists
) {
1118 unsigned TotalNum
= 0u;
1119 for (auto &C
: ComponentLists
)
1120 TotalNum
+= C
.size();
1124 unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
1125 ArrayRef
<const ValueDecl
*> Declarations
) {
1126 unsigned TotalNum
= 0u;
1127 llvm::SmallPtrSet
<const ValueDecl
*, 8> Cache
;
1128 for (const ValueDecl
*D
: Declarations
) {
1129 const ValueDecl
*VD
= D
? cast
<ValueDecl
>(D
->getCanonicalDecl()) : nullptr;
1130 if (Cache
.count(VD
))
1138 OMPMapClause
*OMPMapClause::Create(
1139 const ASTContext
&C
, const OMPVarListLocTy
&Locs
, ArrayRef
<Expr
*> Vars
,
1140 ArrayRef
<ValueDecl
*> Declarations
,
1141 MappableExprComponentListsRef ComponentLists
, ArrayRef
<Expr
*> UDMapperRefs
,
1142 Expr
*IteratorModifier
, ArrayRef
<OpenMPMapModifierKind
> MapModifiers
,
1143 ArrayRef
<SourceLocation
> MapModifiersLoc
,
1144 NestedNameSpecifierLoc UDMQualifierLoc
, DeclarationNameInfo MapperId
,
1145 OpenMPMapClauseKind Type
, bool TypeIsImplicit
, SourceLocation TypeLoc
) {
1146 OMPMappableExprListSizeTy Sizes
;
1147 Sizes
.NumVars
= Vars
.size();
1148 Sizes
.NumUniqueDeclarations
= getUniqueDeclarationsTotalNumber(Declarations
);
1149 Sizes
.NumComponentLists
= ComponentLists
.size();
1150 Sizes
.NumComponents
= getComponentsTotalNumber(ComponentLists
);
1152 // We need to allocate:
1153 // 2 x NumVars x Expr* - we have an original list expression and an associated
1154 // user-defined mapper for each clause list entry.
1155 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1156 // with each component list.
1157 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1158 // number of lists for each unique declaration and the size of each component
1160 // NumComponents x MappableComponent - the total of all the components in all
1162 void *Mem
= C
.Allocate(
1163 totalSizeToAlloc
<Expr
*, ValueDecl
*, unsigned,
1164 OMPClauseMappableExprCommon::MappableComponent
>(
1165 2 * Sizes
.NumVars
+ 1, Sizes
.NumUniqueDeclarations
,
1166 Sizes
.NumUniqueDeclarations
+ Sizes
.NumComponentLists
,
1167 Sizes
.NumComponents
));
1168 OMPMapClause
*Clause
= new (Mem
)
1169 OMPMapClause(MapModifiers
, MapModifiersLoc
, UDMQualifierLoc
, MapperId
,
1170 Type
, TypeIsImplicit
, TypeLoc
, Locs
, Sizes
);
1172 Clause
->setVarRefs(Vars
);
1173 Clause
->setUDMapperRefs(UDMapperRefs
);
1174 Clause
->setIteratorModifier(IteratorModifier
);
1175 Clause
->setClauseInfo(Declarations
, ComponentLists
);
1176 Clause
->setMapType(Type
);
1177 Clause
->setMapLoc(TypeLoc
);
1182 OMPMapClause::CreateEmpty(const ASTContext
&C
,
1183 const OMPMappableExprListSizeTy
&Sizes
) {
1184 void *Mem
= C
.Allocate(
1185 totalSizeToAlloc
<Expr
*, ValueDecl
*, unsigned,
1186 OMPClauseMappableExprCommon::MappableComponent
>(
1187 2 * Sizes
.NumVars
+ 1, Sizes
.NumUniqueDeclarations
,
1188 Sizes
.NumUniqueDeclarations
+ Sizes
.NumComponentLists
,
1189 Sizes
.NumComponents
));
1190 OMPMapClause
*Clause
= new (Mem
) OMPMapClause(Sizes
);
1191 Clause
->setIteratorModifier(nullptr);
1195 OMPToClause
*OMPToClause::Create(
1196 const ASTContext
&C
, const OMPVarListLocTy
&Locs
, ArrayRef
<Expr
*> Vars
,
1197 ArrayRef
<ValueDecl
*> Declarations
,
1198 MappableExprComponentListsRef ComponentLists
, ArrayRef
<Expr
*> UDMapperRefs
,
1199 ArrayRef
<OpenMPMotionModifierKind
> MotionModifiers
,
1200 ArrayRef
<SourceLocation
> MotionModifiersLoc
,
1201 NestedNameSpecifierLoc UDMQualifierLoc
, DeclarationNameInfo MapperId
) {
1202 OMPMappableExprListSizeTy Sizes
;
1203 Sizes
.NumVars
= Vars
.size();
1204 Sizes
.NumUniqueDeclarations
= getUniqueDeclarationsTotalNumber(Declarations
);
1205 Sizes
.NumComponentLists
= ComponentLists
.size();
1206 Sizes
.NumComponents
= getComponentsTotalNumber(ComponentLists
);
1208 // We need to allocate:
1209 // 2 x NumVars x Expr* - we have an original list expression and an associated
1210 // user-defined mapper for each clause list entry.
1211 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1212 // with each component list.
1213 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1214 // number of lists for each unique declaration and the size of each component
1216 // NumComponents x MappableComponent - the total of all the components in all
1218 void *Mem
= C
.Allocate(
1219 totalSizeToAlloc
<Expr
*, ValueDecl
*, unsigned,
1220 OMPClauseMappableExprCommon::MappableComponent
>(
1221 2 * Sizes
.NumVars
, Sizes
.NumUniqueDeclarations
,
1222 Sizes
.NumUniqueDeclarations
+ Sizes
.NumComponentLists
,
1223 Sizes
.NumComponents
));
1225 auto *Clause
= new (Mem
) OMPToClause(MotionModifiers
, MotionModifiersLoc
,
1226 UDMQualifierLoc
, MapperId
, Locs
, Sizes
);
1228 Clause
->setVarRefs(Vars
);
1229 Clause
->setUDMapperRefs(UDMapperRefs
);
1230 Clause
->setClauseInfo(Declarations
, ComponentLists
);
1234 OMPToClause
*OMPToClause::CreateEmpty(const ASTContext
&C
,
1235 const OMPMappableExprListSizeTy
&Sizes
) {
1236 void *Mem
= C
.Allocate(
1237 totalSizeToAlloc
<Expr
*, ValueDecl
*, unsigned,
1238 OMPClauseMappableExprCommon::MappableComponent
>(
1239 2 * Sizes
.NumVars
, Sizes
.NumUniqueDeclarations
,
1240 Sizes
.NumUniqueDeclarations
+ Sizes
.NumComponentLists
,
1241 Sizes
.NumComponents
));
1242 return new (Mem
) OMPToClause(Sizes
);
1245 OMPFromClause
*OMPFromClause::Create(
1246 const ASTContext
&C
, const OMPVarListLocTy
&Locs
, ArrayRef
<Expr
*> Vars
,
1247 ArrayRef
<ValueDecl
*> Declarations
,
1248 MappableExprComponentListsRef ComponentLists
, ArrayRef
<Expr
*> UDMapperRefs
,
1249 ArrayRef
<OpenMPMotionModifierKind
> MotionModifiers
,
1250 ArrayRef
<SourceLocation
> MotionModifiersLoc
,
1251 NestedNameSpecifierLoc UDMQualifierLoc
, DeclarationNameInfo MapperId
) {
1252 OMPMappableExprListSizeTy Sizes
;
1253 Sizes
.NumVars
= Vars
.size();
1254 Sizes
.NumUniqueDeclarations
= getUniqueDeclarationsTotalNumber(Declarations
);
1255 Sizes
.NumComponentLists
= ComponentLists
.size();
1256 Sizes
.NumComponents
= getComponentsTotalNumber(ComponentLists
);
1258 // We need to allocate:
1259 // 2 x NumVars x Expr* - we have an original list expression and an associated
1260 // user-defined mapper for each clause list entry.
1261 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1262 // with each component list.
1263 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1264 // number of lists for each unique declaration and the size of each component
1266 // NumComponents x MappableComponent - the total of all the components in all
1268 void *Mem
= C
.Allocate(
1269 totalSizeToAlloc
<Expr
*, ValueDecl
*, unsigned,
1270 OMPClauseMappableExprCommon::MappableComponent
>(
1271 2 * Sizes
.NumVars
, Sizes
.NumUniqueDeclarations
,
1272 Sizes
.NumUniqueDeclarations
+ Sizes
.NumComponentLists
,
1273 Sizes
.NumComponents
));
1276 new (Mem
) OMPFromClause(MotionModifiers
, MotionModifiersLoc
,
1277 UDMQualifierLoc
, MapperId
, Locs
, Sizes
);
1279 Clause
->setVarRefs(Vars
);
1280 Clause
->setUDMapperRefs(UDMapperRefs
);
1281 Clause
->setClauseInfo(Declarations
, ComponentLists
);
1286 OMPFromClause::CreateEmpty(const ASTContext
&C
,
1287 const OMPMappableExprListSizeTy
&Sizes
) {
1288 void *Mem
= C
.Allocate(
1289 totalSizeToAlloc
<Expr
*, ValueDecl
*, unsigned,
1290 OMPClauseMappableExprCommon::MappableComponent
>(
1291 2 * Sizes
.NumVars
, Sizes
.NumUniqueDeclarations
,
1292 Sizes
.NumUniqueDeclarations
+ Sizes
.NumComponentLists
,
1293 Sizes
.NumComponents
));
1294 return new (Mem
) OMPFromClause(Sizes
);
1297 void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef
<Expr
*> VL
) {
1298 assert(VL
.size() == varlist_size() &&
1299 "Number of private copies is not the same as the preallocated buffer");
1300 std::copy(VL
.begin(), VL
.end(), varlist_end());
1303 void OMPUseDevicePtrClause::setInits(ArrayRef
<Expr
*> VL
) {
1304 assert(VL
.size() == varlist_size() &&
1305 "Number of inits is not the same as the preallocated buffer");
1306 std::copy(VL
.begin(), VL
.end(), getPrivateCopies().end());
1309 OMPUseDevicePtrClause
*OMPUseDevicePtrClause::Create(
1310 const ASTContext
&C
, const OMPVarListLocTy
&Locs
, ArrayRef
<Expr
*> Vars
,
1311 ArrayRef
<Expr
*> PrivateVars
, ArrayRef
<Expr
*> Inits
,
1312 ArrayRef
<ValueDecl
*> Declarations
,
1313 MappableExprComponentListsRef ComponentLists
) {
1314 OMPMappableExprListSizeTy Sizes
;
1315 Sizes
.NumVars
= Vars
.size();
1316 Sizes
.NumUniqueDeclarations
= getUniqueDeclarationsTotalNumber(Declarations
);
1317 Sizes
.NumComponentLists
= ComponentLists
.size();
1318 Sizes
.NumComponents
= getComponentsTotalNumber(ComponentLists
);
1320 // We need to allocate:
1321 // NumVars x Expr* - we have an original list expression for each clause
1323 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1324 // with each component list.
1325 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1326 // number of lists for each unique declaration and the size of each component
1328 // NumComponents x MappableComponent - the total of all the components in all
1330 void *Mem
= C
.Allocate(
1331 totalSizeToAlloc
<Expr
*, ValueDecl
*, unsigned,
1332 OMPClauseMappableExprCommon::MappableComponent
>(
1333 3 * Sizes
.NumVars
, Sizes
.NumUniqueDeclarations
,
1334 Sizes
.NumUniqueDeclarations
+ Sizes
.NumComponentLists
,
1335 Sizes
.NumComponents
));
1337 OMPUseDevicePtrClause
*Clause
= new (Mem
) OMPUseDevicePtrClause(Locs
, Sizes
);
1339 Clause
->setVarRefs(Vars
);
1340 Clause
->setPrivateCopies(PrivateVars
);
1341 Clause
->setInits(Inits
);
1342 Clause
->setClauseInfo(Declarations
, ComponentLists
);
1346 OMPUseDevicePtrClause
*
1347 OMPUseDevicePtrClause::CreateEmpty(const ASTContext
&C
,
1348 const OMPMappableExprListSizeTy
&Sizes
) {
1349 void *Mem
= C
.Allocate(
1350 totalSizeToAlloc
<Expr
*, ValueDecl
*, unsigned,
1351 OMPClauseMappableExprCommon::MappableComponent
>(
1352 3 * Sizes
.NumVars
, Sizes
.NumUniqueDeclarations
,
1353 Sizes
.NumUniqueDeclarations
+ Sizes
.NumComponentLists
,
1354 Sizes
.NumComponents
));
1355 return new (Mem
) OMPUseDevicePtrClause(Sizes
);
1358 OMPUseDeviceAddrClause
*
1359 OMPUseDeviceAddrClause::Create(const ASTContext
&C
, const OMPVarListLocTy
&Locs
,
1360 ArrayRef
<Expr
*> Vars
,
1361 ArrayRef
<ValueDecl
*> Declarations
,
1362 MappableExprComponentListsRef ComponentLists
) {
1363 OMPMappableExprListSizeTy Sizes
;
1364 Sizes
.NumVars
= Vars
.size();
1365 Sizes
.NumUniqueDeclarations
= getUniqueDeclarationsTotalNumber(Declarations
);
1366 Sizes
.NumComponentLists
= ComponentLists
.size();
1367 Sizes
.NumComponents
= getComponentsTotalNumber(ComponentLists
);
1369 // We need to allocate:
1370 // 3 x NumVars x Expr* - we have an original list expression for each clause
1371 // list entry and an equal number of private copies and inits.
1372 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1373 // with each component list.
1374 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1375 // number of lists for each unique declaration and the size of each component
1377 // NumComponents x MappableComponent - the total of all the components in all
1379 void *Mem
= C
.Allocate(
1380 totalSizeToAlloc
<Expr
*, ValueDecl
*, unsigned,
1381 OMPClauseMappableExprCommon::MappableComponent
>(
1382 Sizes
.NumVars
, Sizes
.NumUniqueDeclarations
,
1383 Sizes
.NumUniqueDeclarations
+ Sizes
.NumComponentLists
,
1384 Sizes
.NumComponents
));
1386 auto *Clause
= new (Mem
) OMPUseDeviceAddrClause(Locs
, Sizes
);
1388 Clause
->setVarRefs(Vars
);
1389 Clause
->setClauseInfo(Declarations
, ComponentLists
);
1393 OMPUseDeviceAddrClause
*
1394 OMPUseDeviceAddrClause::CreateEmpty(const ASTContext
&C
,
1395 const OMPMappableExprListSizeTy
&Sizes
) {
1396 void *Mem
= C
.Allocate(
1397 totalSizeToAlloc
<Expr
*, ValueDecl
*, unsigned,
1398 OMPClauseMappableExprCommon::MappableComponent
>(
1399 Sizes
.NumVars
, Sizes
.NumUniqueDeclarations
,
1400 Sizes
.NumUniqueDeclarations
+ Sizes
.NumComponentLists
,
1401 Sizes
.NumComponents
));
1402 return new (Mem
) OMPUseDeviceAddrClause(Sizes
);
1405 OMPIsDevicePtrClause
*
1406 OMPIsDevicePtrClause::Create(const ASTContext
&C
, const OMPVarListLocTy
&Locs
,
1407 ArrayRef
<Expr
*> Vars
,
1408 ArrayRef
<ValueDecl
*> Declarations
,
1409 MappableExprComponentListsRef ComponentLists
) {
1410 OMPMappableExprListSizeTy Sizes
;
1411 Sizes
.NumVars
= Vars
.size();
1412 Sizes
.NumUniqueDeclarations
= getUniqueDeclarationsTotalNumber(Declarations
);
1413 Sizes
.NumComponentLists
= ComponentLists
.size();
1414 Sizes
.NumComponents
= getComponentsTotalNumber(ComponentLists
);
1416 // We need to allocate:
1417 // NumVars x Expr* - we have an original list expression for each clause list
1419 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1420 // with each component list.
1421 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1422 // number of lists for each unique declaration and the size of each component
1424 // NumComponents x MappableComponent - the total of all the components in all
1426 void *Mem
= C
.Allocate(
1427 totalSizeToAlloc
<Expr
*, ValueDecl
*, unsigned,
1428 OMPClauseMappableExprCommon::MappableComponent
>(
1429 Sizes
.NumVars
, Sizes
.NumUniqueDeclarations
,
1430 Sizes
.NumUniqueDeclarations
+ Sizes
.NumComponentLists
,
1431 Sizes
.NumComponents
));
1433 OMPIsDevicePtrClause
*Clause
= new (Mem
) OMPIsDevicePtrClause(Locs
, Sizes
);
1435 Clause
->setVarRefs(Vars
);
1436 Clause
->setClauseInfo(Declarations
, ComponentLists
);
1440 OMPIsDevicePtrClause
*
1441 OMPIsDevicePtrClause::CreateEmpty(const ASTContext
&C
,
1442 const OMPMappableExprListSizeTy
&Sizes
) {
1443 void *Mem
= C
.Allocate(
1444 totalSizeToAlloc
<Expr
*, ValueDecl
*, unsigned,
1445 OMPClauseMappableExprCommon::MappableComponent
>(
1446 Sizes
.NumVars
, Sizes
.NumUniqueDeclarations
,
1447 Sizes
.NumUniqueDeclarations
+ Sizes
.NumComponentLists
,
1448 Sizes
.NumComponents
));
1449 return new (Mem
) OMPIsDevicePtrClause(Sizes
);
1452 OMPHasDeviceAddrClause
*
1453 OMPHasDeviceAddrClause::Create(const ASTContext
&C
, const OMPVarListLocTy
&Locs
,
1454 ArrayRef
<Expr
*> Vars
,
1455 ArrayRef
<ValueDecl
*> Declarations
,
1456 MappableExprComponentListsRef ComponentLists
) {
1457 OMPMappableExprListSizeTy Sizes
;
1458 Sizes
.NumVars
= Vars
.size();
1459 Sizes
.NumUniqueDeclarations
= getUniqueDeclarationsTotalNumber(Declarations
);
1460 Sizes
.NumComponentLists
= ComponentLists
.size();
1461 Sizes
.NumComponents
= getComponentsTotalNumber(ComponentLists
);
1463 // We need to allocate:
1464 // NumVars x Expr* - we have an original list expression for each clause list
1466 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1467 // with each component list.
1468 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1469 // number of lists for each unique declaration and the size of each component
1471 // NumComponents x MappableComponent - the total of all the components in all
1473 void *Mem
= C
.Allocate(
1474 totalSizeToAlloc
<Expr
*, ValueDecl
*, unsigned,
1475 OMPClauseMappableExprCommon::MappableComponent
>(
1476 Sizes
.NumVars
, Sizes
.NumUniqueDeclarations
,
1477 Sizes
.NumUniqueDeclarations
+ Sizes
.NumComponentLists
,
1478 Sizes
.NumComponents
));
1480 auto *Clause
= new (Mem
) OMPHasDeviceAddrClause(Locs
, Sizes
);
1482 Clause
->setVarRefs(Vars
);
1483 Clause
->setClauseInfo(Declarations
, ComponentLists
);
1487 OMPHasDeviceAddrClause
*
1488 OMPHasDeviceAddrClause::CreateEmpty(const ASTContext
&C
,
1489 const OMPMappableExprListSizeTy
&Sizes
) {
1490 void *Mem
= C
.Allocate(
1491 totalSizeToAlloc
<Expr
*, ValueDecl
*, unsigned,
1492 OMPClauseMappableExprCommon::MappableComponent
>(
1493 Sizes
.NumVars
, Sizes
.NumUniqueDeclarations
,
1494 Sizes
.NumUniqueDeclarations
+ Sizes
.NumComponentLists
,
1495 Sizes
.NumComponents
));
1496 return new (Mem
) OMPHasDeviceAddrClause(Sizes
);
1499 OMPNontemporalClause
*OMPNontemporalClause::Create(const ASTContext
&C
,
1500 SourceLocation StartLoc
,
1501 SourceLocation LParenLoc
,
1502 SourceLocation EndLoc
,
1503 ArrayRef
<Expr
*> VL
) {
1504 // Allocate space for nontemporal variables + private references.
1505 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(2 * VL
.size()));
1507 new (Mem
) OMPNontemporalClause(StartLoc
, LParenLoc
, EndLoc
, VL
.size());
1508 Clause
->setVarRefs(VL
);
1512 OMPNontemporalClause
*OMPNontemporalClause::CreateEmpty(const ASTContext
&C
,
1514 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(2 * N
));
1515 return new (Mem
) OMPNontemporalClause(N
);
1518 void OMPNontemporalClause::setPrivateRefs(ArrayRef
<Expr
*> VL
) {
1519 assert(VL
.size() == varlist_size() && "Number of private references is not "
1520 "the same as the preallocated buffer");
1521 std::copy(VL
.begin(), VL
.end(), varlist_end());
1524 OMPInclusiveClause
*OMPInclusiveClause::Create(const ASTContext
&C
,
1525 SourceLocation StartLoc
,
1526 SourceLocation LParenLoc
,
1527 SourceLocation EndLoc
,
1528 ArrayRef
<Expr
*> VL
) {
1529 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(VL
.size()));
1531 new (Mem
) OMPInclusiveClause(StartLoc
, LParenLoc
, EndLoc
, VL
.size());
1532 Clause
->setVarRefs(VL
);
1536 OMPInclusiveClause
*OMPInclusiveClause::CreateEmpty(const ASTContext
&C
,
1538 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(N
));
1539 return new (Mem
) OMPInclusiveClause(N
);
1542 OMPExclusiveClause
*OMPExclusiveClause::Create(const ASTContext
&C
,
1543 SourceLocation StartLoc
,
1544 SourceLocation LParenLoc
,
1545 SourceLocation EndLoc
,
1546 ArrayRef
<Expr
*> VL
) {
1547 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(VL
.size()));
1549 new (Mem
) OMPExclusiveClause(StartLoc
, LParenLoc
, EndLoc
, VL
.size());
1550 Clause
->setVarRefs(VL
);
1554 OMPExclusiveClause
*OMPExclusiveClause::CreateEmpty(const ASTContext
&C
,
1556 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(N
));
1557 return new (Mem
) OMPExclusiveClause(N
);
1560 void OMPUsesAllocatorsClause::setAllocatorsData(
1561 ArrayRef
<OMPUsesAllocatorsClause::Data
> Data
) {
1562 assert(Data
.size() == NumOfAllocators
&&
1563 "Size of allocators data is not the same as the preallocated buffer.");
1564 for (unsigned I
= 0, E
= Data
.size(); I
< E
; ++I
) {
1565 const OMPUsesAllocatorsClause::Data
&D
= Data
[I
];
1566 getTrailingObjects
<Expr
*>()[I
* static_cast<int>(ExprOffsets::Total
) +
1567 static_cast<int>(ExprOffsets::Allocator
)] =
1569 getTrailingObjects
<Expr
*>()[I
* static_cast<int>(ExprOffsets::Total
) +
1571 ExprOffsets::AllocatorTraits
)] =
1574 SourceLocation
>()[I
* static_cast<int>(ParenLocsOffsets::Total
) +
1575 static_cast<int>(ParenLocsOffsets::LParen
)] =
1578 SourceLocation
>()[I
* static_cast<int>(ParenLocsOffsets::Total
) +
1579 static_cast<int>(ParenLocsOffsets::RParen
)] =
1584 OMPUsesAllocatorsClause::Data
1585 OMPUsesAllocatorsClause::getAllocatorData(unsigned I
) const {
1586 OMPUsesAllocatorsClause::Data Data
;
1588 getTrailingObjects
<Expr
*>()[I
* static_cast<int>(ExprOffsets::Total
) +
1589 static_cast<int>(ExprOffsets::Allocator
)];
1590 Data
.AllocatorTraits
=
1591 getTrailingObjects
<Expr
*>()[I
* static_cast<int>(ExprOffsets::Total
) +
1593 ExprOffsets::AllocatorTraits
)];
1594 Data
.LParenLoc
= getTrailingObjects
<
1595 SourceLocation
>()[I
* static_cast<int>(ParenLocsOffsets::Total
) +
1596 static_cast<int>(ParenLocsOffsets::LParen
)];
1597 Data
.RParenLoc
= getTrailingObjects
<
1598 SourceLocation
>()[I
* static_cast<int>(ParenLocsOffsets::Total
) +
1599 static_cast<int>(ParenLocsOffsets::RParen
)];
1603 OMPUsesAllocatorsClause
*
1604 OMPUsesAllocatorsClause::Create(const ASTContext
&C
, SourceLocation StartLoc
,
1605 SourceLocation LParenLoc
, SourceLocation EndLoc
,
1606 ArrayRef
<OMPUsesAllocatorsClause::Data
> Data
) {
1607 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*, SourceLocation
>(
1608 static_cast<int>(ExprOffsets::Total
) * Data
.size(),
1609 static_cast<int>(ParenLocsOffsets::Total
) * Data
.size()));
1610 auto *Clause
= new (Mem
)
1611 OMPUsesAllocatorsClause(StartLoc
, LParenLoc
, EndLoc
, Data
.size());
1612 Clause
->setAllocatorsData(Data
);
1616 OMPUsesAllocatorsClause
*
1617 OMPUsesAllocatorsClause::CreateEmpty(const ASTContext
&C
, unsigned N
) {
1618 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*, SourceLocation
>(
1619 static_cast<int>(ExprOffsets::Total
) * N
,
1620 static_cast<int>(ParenLocsOffsets::Total
) * N
));
1621 return new (Mem
) OMPUsesAllocatorsClause(N
);
1625 OMPAffinityClause::Create(const ASTContext
&C
, SourceLocation StartLoc
,
1626 SourceLocation LParenLoc
, SourceLocation ColonLoc
,
1627 SourceLocation EndLoc
, Expr
*Modifier
,
1628 ArrayRef
<Expr
*> Locators
) {
1629 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(Locators
.size() + 1));
1630 auto *Clause
= new (Mem
)
1631 OMPAffinityClause(StartLoc
, LParenLoc
, ColonLoc
, EndLoc
, Locators
.size());
1632 Clause
->setModifier(Modifier
);
1633 Clause
->setVarRefs(Locators
);
1637 OMPAffinityClause
*OMPAffinityClause::CreateEmpty(const ASTContext
&C
,
1639 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(N
+ 1));
1640 return new (Mem
) OMPAffinityClause(N
);
1643 OMPInitClause
*OMPInitClause::Create(const ASTContext
&C
, Expr
*InteropVar
,
1644 OMPInteropInfo
&InteropInfo
,
1645 SourceLocation StartLoc
,
1646 SourceLocation LParenLoc
,
1647 SourceLocation VarLoc
,
1648 SourceLocation EndLoc
) {
1651 C
.Allocate(totalSizeToAlloc
<Expr
*>(InteropInfo
.PreferTypes
.size() + 1));
1652 auto *Clause
= new (Mem
) OMPInitClause(
1653 InteropInfo
.IsTarget
, InteropInfo
.IsTargetSync
, StartLoc
, LParenLoc
,
1654 VarLoc
, EndLoc
, InteropInfo
.PreferTypes
.size() + 1);
1655 Clause
->setInteropVar(InteropVar
);
1656 llvm::copy(InteropInfo
.PreferTypes
, Clause
->getTrailingObjects
<Expr
*>() + 1);
1660 OMPInitClause
*OMPInitClause::CreateEmpty(const ASTContext
&C
, unsigned N
) {
1661 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(N
));
1662 return new (Mem
) OMPInitClause(N
);
1666 OMPBindClause::Create(const ASTContext
&C
, OpenMPBindClauseKind K
,
1667 SourceLocation KLoc
, SourceLocation StartLoc
,
1668 SourceLocation LParenLoc
, SourceLocation EndLoc
) {
1669 return new (C
) OMPBindClause(K
, KLoc
, StartLoc
, LParenLoc
, EndLoc
);
1672 OMPBindClause
*OMPBindClause::CreateEmpty(const ASTContext
&C
) {
1673 return new (C
) OMPBindClause();
1677 OMPDoacrossClause::Create(const ASTContext
&C
, SourceLocation StartLoc
,
1678 SourceLocation LParenLoc
, SourceLocation EndLoc
,
1679 OpenMPDoacrossClauseModifier DepType
,
1680 SourceLocation DepLoc
, SourceLocation ColonLoc
,
1681 ArrayRef
<Expr
*> VL
, unsigned NumLoops
) {
1682 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(VL
.size() + NumLoops
),
1683 alignof(OMPDoacrossClause
));
1684 OMPDoacrossClause
*Clause
= new (Mem
)
1685 OMPDoacrossClause(StartLoc
, LParenLoc
, EndLoc
, VL
.size(), NumLoops
);
1686 Clause
->setDependenceType(DepType
);
1687 Clause
->setDependenceLoc(DepLoc
);
1688 Clause
->setColonLoc(ColonLoc
);
1689 Clause
->setVarRefs(VL
);
1690 for (unsigned I
= 0; I
< NumLoops
; ++I
)
1691 Clause
->setLoopData(I
, nullptr);
1695 OMPDoacrossClause
*OMPDoacrossClause::CreateEmpty(const ASTContext
&C
,
1697 unsigned NumLoops
) {
1698 void *Mem
= C
.Allocate(totalSizeToAlloc
<Expr
*>(N
+ NumLoops
),
1699 alignof(OMPDoacrossClause
));
1700 return new (Mem
) OMPDoacrossClause(N
, NumLoops
);
1703 void OMPDoacrossClause::setLoopData(unsigned NumLoop
, Expr
*Cnt
) {
1704 assert(NumLoop
< NumLoops
&& "Loop index must be less number of loops.");
1705 auto *It
= std::next(getVarRefs().end(), NumLoop
);
1709 Expr
*OMPDoacrossClause::getLoopData(unsigned NumLoop
) {
1710 assert(NumLoop
< NumLoops
&& "Loop index must be less number of loops.");
1711 auto *It
= std::next(getVarRefs().end(), NumLoop
);
1715 const Expr
*OMPDoacrossClause::getLoopData(unsigned NumLoop
) const {
1716 assert(NumLoop
< NumLoops
&& "Loop index must be less number of loops.");
1717 const auto *It
= std::next(getVarRefs().end(), NumLoop
);
1721 //===----------------------------------------------------------------------===//
1722 // OpenMP clauses printing methods
1723 //===----------------------------------------------------------------------===//
1725 void OMPClausePrinter::VisitOMPIfClause(OMPIfClause
*Node
) {
1727 if (Node
->getNameModifier() != OMPD_unknown
)
1728 OS
<< getOpenMPDirectiveName(Node
->getNameModifier()) << ": ";
1729 Node
->getCondition()->printPretty(OS
, nullptr, Policy
, 0);
1733 void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause
*Node
) {
1735 Node
->getCondition()->printPretty(OS
, nullptr, Policy
, 0);
1739 void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause
*Node
) {
1740 OS
<< "num_threads(";
1741 Node
->getNumThreads()->printPretty(OS
, nullptr, Policy
, 0);
1745 void OMPClausePrinter::VisitOMPAlignClause(OMPAlignClause
*Node
) {
1747 Node
->getAlignment()->printPretty(OS
, nullptr, Policy
, 0);
1751 void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause
*Node
) {
1753 Node
->getSafelen()->printPretty(OS
, nullptr, Policy
, 0);
1757 void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause
*Node
) {
1759 Node
->getSimdlen()->printPretty(OS
, nullptr, Policy
, 0);
1763 void OMPClausePrinter::VisitOMPSizesClause(OMPSizesClause
*Node
) {
1766 for (auto *Size
: Node
->getSizesRefs()) {
1769 Size
->printPretty(OS
, nullptr, Policy
, 0);
1775 void OMPClausePrinter::VisitOMPFullClause(OMPFullClause
*Node
) { OS
<< "full"; }
1777 void OMPClausePrinter::VisitOMPPartialClause(OMPPartialClause
*Node
) {
1780 if (Expr
*Factor
= Node
->getFactor()) {
1782 Factor
->printPretty(OS
, nullptr, Policy
, 0);
1787 void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause
*Node
) {
1789 Node
->getAllocator()->printPretty(OS
, nullptr, Policy
, 0);
1793 void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause
*Node
) {
1795 Node
->getNumForLoops()->printPretty(OS
, nullptr, Policy
, 0);
1799 void OMPClausePrinter::VisitOMPDetachClause(OMPDetachClause
*Node
) {
1801 Node
->getEventHandler()->printPretty(OS
, nullptr, Policy
, 0);
1805 void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause
*Node
) {
1807 << getOpenMPSimpleClauseTypeName(OMPC_default
,
1808 unsigned(Node
->getDefaultKind()))
1812 void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause
*Node
) {
1814 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind
,
1815 unsigned(Node
->getProcBindKind()))
1819 void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause
*) {
1820 OS
<< "unified_address";
1823 void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1824 OMPUnifiedSharedMemoryClause
*) {
1825 OS
<< "unified_shared_memory";
1828 void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause
*) {
1829 OS
<< "reverse_offload";
1832 void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1833 OMPDynamicAllocatorsClause
*) {
1834 OS
<< "dynamic_allocators";
1837 void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1838 OMPAtomicDefaultMemOrderClause
*Node
) {
1839 OS
<< "atomic_default_mem_order("
1840 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order
,
1841 Node
->getAtomicDefaultMemOrderKind())
1845 void OMPClausePrinter::VisitOMPAtClause(OMPAtClause
*Node
) {
1846 OS
<< "at(" << getOpenMPSimpleClauseTypeName(OMPC_at
, Node
->getAtKind())
1850 void OMPClausePrinter::VisitOMPSeverityClause(OMPSeverityClause
*Node
) {
1852 << getOpenMPSimpleClauseTypeName(OMPC_severity
, Node
->getSeverityKind())
1856 void OMPClausePrinter::VisitOMPMessageClause(OMPMessageClause
*Node
) {
1858 << cast
<StringLiteral
>(Node
->getMessageString())->getString() << "\")";
1861 void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause
*Node
) {
1863 if (Node
->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown
) {
1864 OS
<< getOpenMPSimpleClauseTypeName(OMPC_schedule
,
1865 Node
->getFirstScheduleModifier());
1866 if (Node
->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown
) {
1868 OS
<< getOpenMPSimpleClauseTypeName(OMPC_schedule
,
1869 Node
->getSecondScheduleModifier());
1873 OS
<< getOpenMPSimpleClauseTypeName(OMPC_schedule
, Node
->getScheduleKind());
1874 if (auto *E
= Node
->getChunkSize()) {
1876 E
->printPretty(OS
, nullptr, Policy
);
1881 void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause
*Node
) {
1883 if (auto *Num
= Node
->getNumForLoops()) {
1885 Num
->printPretty(OS
, nullptr, Policy
, 0);
1890 void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause
*) {
1894 void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause
*) {
1898 void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause
*) {
1902 void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause
*) {
1906 void OMPClausePrinter::VisitOMPReadClause(OMPReadClause
*) { OS
<< "read"; }
1908 void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause
*) { OS
<< "write"; }
1910 void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause
*Node
) {
1912 if (Node
->isExtended()) {
1914 OS
<< getOpenMPSimpleClauseTypeName(Node
->getClauseKind(),
1915 Node
->getDependencyKind());
1920 void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause
*) {
1924 void OMPClausePrinter::VisitOMPCompareClause(OMPCompareClause
*) {
1928 void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause
*) {
1932 void OMPClausePrinter::VisitOMPAcqRelClause(OMPAcqRelClause
*) {
1936 void OMPClausePrinter::VisitOMPAcquireClause(OMPAcquireClause
*) {
1940 void OMPClausePrinter::VisitOMPReleaseClause(OMPReleaseClause
*) {
1944 void OMPClausePrinter::VisitOMPRelaxedClause(OMPRelaxedClause
*) {
1948 void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause
*) {
1952 void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause
*) { OS
<< "simd"; }
1954 void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause
*Node
) {
1956 OpenMPDeviceClauseModifier Modifier
= Node
->getModifier();
1957 if (Modifier
!= OMPC_DEVICE_unknown
) {
1958 OS
<< getOpenMPSimpleClauseTypeName(Node
->getClauseKind(), Modifier
)
1961 Node
->getDevice()->printPretty(OS
, nullptr, Policy
, 0);
1965 void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause
*Node
) {
1967 Node
->getNumTeams()->printPretty(OS
, nullptr, Policy
, 0);
1971 void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause
*Node
) {
1972 OS
<< "thread_limit(";
1973 Node
->getThreadLimit()->printPretty(OS
, nullptr, Policy
, 0);
1977 void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause
*Node
) {
1979 Node
->getPriority()->printPretty(OS
, nullptr, Policy
, 0);
1983 void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause
*Node
) {
1985 OpenMPGrainsizeClauseModifier Modifier
= Node
->getModifier();
1986 if (Modifier
!= OMPC_GRAINSIZE_unknown
) {
1987 OS
<< getOpenMPSimpleClauseTypeName(Node
->getClauseKind(), Modifier
)
1990 Node
->getGrainsize()->printPretty(OS
, nullptr, Policy
, 0);
1994 void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause
*Node
) {
1996 OpenMPNumTasksClauseModifier Modifier
= Node
->getModifier();
1997 if (Modifier
!= OMPC_NUMTASKS_unknown
) {
1998 OS
<< getOpenMPSimpleClauseTypeName(Node
->getClauseKind(), Modifier
)
2001 Node
->getNumTasks()->printPretty(OS
, nullptr, Policy
, 0);
2005 void OMPClausePrinter::VisitOMPHintClause(OMPHintClause
*Node
) {
2007 Node
->getHint()->printPretty(OS
, nullptr, Policy
, 0);
2011 void OMPClausePrinter::VisitOMPInitClause(OMPInitClause
*Node
) {
2014 for (const Expr
*E
: Node
->prefs()) {
2016 OS
<< "prefer_type(";
2019 E
->printPretty(OS
, nullptr, Policy
);
2024 if (Node
->getIsTarget())
2026 if (Node
->getIsTargetSync()) {
2027 if (Node
->getIsTarget())
2032 Node
->getInteropVar()->printPretty(OS
, nullptr, Policy
);
2036 void OMPClausePrinter::VisitOMPUseClause(OMPUseClause
*Node
) {
2038 Node
->getInteropVar()->printPretty(OS
, nullptr, Policy
);
2042 void OMPClausePrinter::VisitOMPDestroyClause(OMPDestroyClause
*Node
) {
2044 if (Expr
*E
= Node
->getInteropVar()) {
2046 E
->printPretty(OS
, nullptr, Policy
);
2051 void OMPClausePrinter::VisitOMPNovariantsClause(OMPNovariantsClause
*Node
) {
2053 if (Expr
*E
= Node
->getCondition()) {
2055 E
->printPretty(OS
, nullptr, Policy
, 0);
2060 void OMPClausePrinter::VisitOMPNocontextClause(OMPNocontextClause
*Node
) {
2062 if (Expr
*E
= Node
->getCondition()) {
2064 E
->printPretty(OS
, nullptr, Policy
, 0);
2069 template<typename T
>
2070 void OMPClausePrinter::VisitOMPClauseList(T
*Node
, char StartSym
) {
2071 for (typename
T::varlist_iterator I
= Node
->varlist_begin(),
2072 E
= Node
->varlist_end();
2074 assert(*I
&& "Expected non-null Stmt");
2075 OS
<< (I
== Node
->varlist_begin() ? StartSym
: ',');
2076 if (auto *DRE
= dyn_cast
<DeclRefExpr
>(*I
)) {
2077 if (isa
<OMPCapturedExprDecl
>(DRE
->getDecl()))
2078 DRE
->printPretty(OS
, nullptr, Policy
, 0);
2080 DRE
->getDecl()->printQualifiedName(OS
);
2082 (*I
)->printPretty(OS
, nullptr, Policy
, 0);
2086 void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause
*Node
) {
2087 if (Node
->varlist_empty())
2090 if (Expr
*Allocator
= Node
->getAllocator()) {
2092 Allocator
->printPretty(OS
, nullptr, Policy
, 0);
2094 VisitOMPClauseList(Node
, ' ');
2096 VisitOMPClauseList(Node
, '(');
2101 void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause
*Node
) {
2102 if (!Node
->varlist_empty()) {
2104 VisitOMPClauseList(Node
, '(');
2109 void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause
*Node
) {
2110 if (!Node
->varlist_empty()) {
2111 OS
<< "firstprivate";
2112 VisitOMPClauseList(Node
, '(');
2117 void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause
*Node
) {
2118 if (!Node
->varlist_empty()) {
2119 OS
<< "lastprivate";
2120 OpenMPLastprivateModifier LPKind
= Node
->getKind();
2121 if (LPKind
!= OMPC_LASTPRIVATE_unknown
) {
2123 << getOpenMPSimpleClauseTypeName(OMPC_lastprivate
, Node
->getKind())
2126 VisitOMPClauseList(Node
, LPKind
== OMPC_LASTPRIVATE_unknown
? '(' : ' ');
2131 void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause
*Node
) {
2132 if (!Node
->varlist_empty()) {
2134 VisitOMPClauseList(Node
, '(');
2139 void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause
*Node
) {
2140 if (!Node
->varlist_empty()) {
2142 if (Node
->getModifierLoc().isValid())
2143 OS
<< getOpenMPSimpleClauseTypeName(OMPC_reduction
, Node
->getModifier())
2145 NestedNameSpecifier
*QualifierLoc
=
2146 Node
->getQualifierLoc().getNestedNameSpecifier();
2147 OverloadedOperatorKind OOK
=
2148 Node
->getNameInfo().getName().getCXXOverloadedOperator();
2149 if (QualifierLoc
== nullptr && OOK
!= OO_None
) {
2150 // Print reduction identifier in C format
2151 OS
<< getOperatorSpelling(OOK
);
2154 if (QualifierLoc
!= nullptr)
2155 QualifierLoc
->print(OS
, Policy
);
2156 OS
<< Node
->getNameInfo();
2159 VisitOMPClauseList(Node
, ' ');
2164 void OMPClausePrinter::VisitOMPTaskReductionClause(
2165 OMPTaskReductionClause
*Node
) {
2166 if (!Node
->varlist_empty()) {
2167 OS
<< "task_reduction(";
2168 NestedNameSpecifier
*QualifierLoc
=
2169 Node
->getQualifierLoc().getNestedNameSpecifier();
2170 OverloadedOperatorKind OOK
=
2171 Node
->getNameInfo().getName().getCXXOverloadedOperator();
2172 if (QualifierLoc
== nullptr && OOK
!= OO_None
) {
2173 // Print reduction identifier in C format
2174 OS
<< getOperatorSpelling(OOK
);
2177 if (QualifierLoc
!= nullptr)
2178 QualifierLoc
->print(OS
, Policy
);
2179 OS
<< Node
->getNameInfo();
2182 VisitOMPClauseList(Node
, ' ');
2187 void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause
*Node
) {
2188 if (!Node
->varlist_empty()) {
2189 OS
<< "in_reduction(";
2190 NestedNameSpecifier
*QualifierLoc
=
2191 Node
->getQualifierLoc().getNestedNameSpecifier();
2192 OverloadedOperatorKind OOK
=
2193 Node
->getNameInfo().getName().getCXXOverloadedOperator();
2194 if (QualifierLoc
== nullptr && OOK
!= OO_None
) {
2195 // Print reduction identifier in C format
2196 OS
<< getOperatorSpelling(OOK
);
2199 if (QualifierLoc
!= nullptr)
2200 QualifierLoc
->print(OS
, Policy
);
2201 OS
<< Node
->getNameInfo();
2204 VisitOMPClauseList(Node
, ' ');
2209 void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause
*Node
) {
2210 if (!Node
->varlist_empty()) {
2212 VisitOMPClauseList(Node
, '(');
2213 if (Node
->getModifierLoc().isValid() || Node
->getStep() != nullptr) {
2216 if (Node
->getModifierLoc().isValid()) {
2217 OS
<< getOpenMPSimpleClauseTypeName(OMPC_linear
, Node
->getModifier());
2219 if (Node
->getStep() != nullptr) {
2220 if (Node
->getModifierLoc().isValid()) {
2224 Node
->getStep()->printPretty(OS
, nullptr, Policy
, 0);
2231 void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause
*Node
) {
2232 if (!Node
->varlist_empty()) {
2234 VisitOMPClauseList(Node
, '(');
2235 if (Node
->getAlignment() != nullptr) {
2237 Node
->getAlignment()->printPretty(OS
, nullptr, Policy
, 0);
2243 void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause
*Node
) {
2244 if (!Node
->varlist_empty()) {
2246 VisitOMPClauseList(Node
, '(');
2251 void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause
*Node
) {
2252 if (!Node
->varlist_empty()) {
2253 OS
<< "copyprivate";
2254 VisitOMPClauseList(Node
, '(');
2259 void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause
*Node
) {
2260 if (!Node
->varlist_empty()) {
2261 VisitOMPClauseList(Node
, '(');
2266 void OMPClausePrinter::VisitOMPDepobjClause(OMPDepobjClause
*Node
) {
2268 Node
->getDepobj()->printPretty(OS
, nullptr, Policy
, 0);
2272 void OMPClausePrinter::VisitOMPDependClause(OMPDependClause
*Node
) {
2274 if (Expr
*DepModifier
= Node
->getModifier()) {
2275 DepModifier
->printPretty(OS
, nullptr, Policy
);
2278 OpenMPDependClauseKind DepKind
= Node
->getDependencyKind();
2279 OpenMPDependClauseKind PrintKind
= DepKind
;
2280 bool IsOmpAllMemory
= false;
2281 if (PrintKind
== OMPC_DEPEND_outallmemory
) {
2282 PrintKind
= OMPC_DEPEND_out
;
2283 IsOmpAllMemory
= true;
2284 } else if (PrintKind
== OMPC_DEPEND_inoutallmemory
) {
2285 PrintKind
= OMPC_DEPEND_inout
;
2286 IsOmpAllMemory
= true;
2288 OS
<< getOpenMPSimpleClauseTypeName(Node
->getClauseKind(), PrintKind
);
2289 if (!Node
->varlist_empty() || IsOmpAllMemory
)
2291 VisitOMPClauseList(Node
, ' ');
2292 if (IsOmpAllMemory
) {
2293 OS
<< (Node
->varlist_empty() ? " " : ",");
2294 OS
<< "omp_all_memory";
2299 template <typename T
>
2300 static void PrintMapper(raw_ostream
&OS
, T
*Node
,
2301 const PrintingPolicy
&Policy
) {
2303 NestedNameSpecifier
*MapperNNS
=
2304 Node
->getMapperQualifierLoc().getNestedNameSpecifier();
2306 MapperNNS
->print(OS
, Policy
);
2307 OS
<< Node
->getMapperIdInfo() << ')';
2310 template <typename T
>
2311 static void PrintIterator(raw_ostream
&OS
, T
*Node
,
2312 const PrintingPolicy
&Policy
) {
2313 if (Expr
*IteratorModifier
= Node
->getIteratorModifier())
2314 IteratorModifier
->printPretty(OS
, nullptr, Policy
);
2317 void OMPClausePrinter::VisitOMPMapClause(OMPMapClause
*Node
) {
2318 if (!Node
->varlist_empty()) {
2320 if (Node
->getMapType() != OMPC_MAP_unknown
) {
2321 for (unsigned I
= 0; I
< NumberOfOMPMapClauseModifiers
; ++I
) {
2322 if (Node
->getMapTypeModifier(I
) != OMPC_MAP_MODIFIER_unknown
) {
2323 if (Node
->getMapTypeModifier(I
) == OMPC_MAP_MODIFIER_iterator
) {
2324 PrintIterator(OS
, Node
, Policy
);
2326 OS
<< getOpenMPSimpleClauseTypeName(OMPC_map
,
2327 Node
->getMapTypeModifier(I
));
2328 if (Node
->getMapTypeModifier(I
) == OMPC_MAP_MODIFIER_mapper
)
2329 PrintMapper(OS
, Node
, Policy
);
2334 OS
<< getOpenMPSimpleClauseTypeName(OMPC_map
, Node
->getMapType());
2337 VisitOMPClauseList(Node
, ' ');
2342 template <typename T
> void OMPClausePrinter::VisitOMPMotionClause(T
*Node
) {
2343 if (Node
->varlist_empty())
2345 OS
<< getOpenMPClauseName(Node
->getClauseKind());
2346 unsigned ModifierCount
= 0;
2347 for (unsigned I
= 0; I
< NumberOfOMPMotionModifiers
; ++I
) {
2348 if (Node
->getMotionModifier(I
) != OMPC_MOTION_MODIFIER_unknown
)
2351 if (ModifierCount
) {
2353 for (unsigned I
= 0; I
< NumberOfOMPMotionModifiers
; ++I
) {
2354 if (Node
->getMotionModifier(I
) != OMPC_MOTION_MODIFIER_unknown
) {
2355 OS
<< getOpenMPSimpleClauseTypeName(Node
->getClauseKind(),
2356 Node
->getMotionModifier(I
));
2357 if (Node
->getMotionModifier(I
) == OMPC_MOTION_MODIFIER_mapper
)
2358 PrintMapper(OS
, Node
, Policy
);
2359 if (I
< ModifierCount
- 1)
2364 VisitOMPClauseList(Node
, ' ');
2366 VisitOMPClauseList(Node
, '(');
2371 void OMPClausePrinter::VisitOMPToClause(OMPToClause
*Node
) {
2372 VisitOMPMotionClause(Node
);
2375 void OMPClausePrinter::VisitOMPFromClause(OMPFromClause
*Node
) {
2376 VisitOMPMotionClause(Node
);
2379 void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause
*Node
) {
2380 OS
<< "dist_schedule(" << getOpenMPSimpleClauseTypeName(
2381 OMPC_dist_schedule
, Node
->getDistScheduleKind());
2382 if (auto *E
= Node
->getChunkSize()) {
2384 E
->printPretty(OS
, nullptr, Policy
);
2389 void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause
*Node
) {
2390 OS
<< "defaultmap(";
2391 OS
<< getOpenMPSimpleClauseTypeName(OMPC_defaultmap
,
2392 Node
->getDefaultmapModifier());
2393 if (Node
->getDefaultmapKind() != OMPC_DEFAULTMAP_unknown
) {
2395 OS
<< getOpenMPSimpleClauseTypeName(OMPC_defaultmap
,
2396 Node
->getDefaultmapKind());
2401 void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause
*Node
) {
2402 if (!Node
->varlist_empty()) {
2403 OS
<< "use_device_ptr";
2404 VisitOMPClauseList(Node
, '(');
2409 void OMPClausePrinter::VisitOMPUseDeviceAddrClause(
2410 OMPUseDeviceAddrClause
*Node
) {
2411 if (!Node
->varlist_empty()) {
2412 OS
<< "use_device_addr";
2413 VisitOMPClauseList(Node
, '(');
2418 void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause
*Node
) {
2419 if (!Node
->varlist_empty()) {
2420 OS
<< "is_device_ptr";
2421 VisitOMPClauseList(Node
, '(');
2426 void OMPClausePrinter::VisitOMPHasDeviceAddrClause(OMPHasDeviceAddrClause
*Node
) {
2427 if (!Node
->varlist_empty()) {
2428 OS
<< "has_device_addr";
2429 VisitOMPClauseList(Node
, '(');
2434 void OMPClausePrinter::VisitOMPNontemporalClause(OMPNontemporalClause
*Node
) {
2435 if (!Node
->varlist_empty()) {
2436 OS
<< "nontemporal";
2437 VisitOMPClauseList(Node
, '(');
2442 void OMPClausePrinter::VisitOMPOrderClause(OMPOrderClause
*Node
) {
2444 if (Node
->getModifier() != OMPC_ORDER_MODIFIER_unknown
) {
2445 OS
<< getOpenMPSimpleClauseTypeName(OMPC_order
, Node
->getModifier());
2448 OS
<< getOpenMPSimpleClauseTypeName(OMPC_order
, Node
->getKind()) << ")";
2451 void OMPClausePrinter::VisitOMPInclusiveClause(OMPInclusiveClause
*Node
) {
2452 if (!Node
->varlist_empty()) {
2454 VisitOMPClauseList(Node
, '(');
2459 void OMPClausePrinter::VisitOMPExclusiveClause(OMPExclusiveClause
*Node
) {
2460 if (!Node
->varlist_empty()) {
2462 VisitOMPClauseList(Node
, '(');
2467 void OMPClausePrinter::VisitOMPUsesAllocatorsClause(
2468 OMPUsesAllocatorsClause
*Node
) {
2469 if (Node
->getNumberOfAllocators() == 0)
2471 OS
<< "uses_allocators(";
2472 for (unsigned I
= 0, E
= Node
->getNumberOfAllocators(); I
< E
; ++I
) {
2473 OMPUsesAllocatorsClause::Data Data
= Node
->getAllocatorData(I
);
2474 Data
.Allocator
->printPretty(OS
, nullptr, Policy
);
2475 if (Data
.AllocatorTraits
) {
2477 Data
.AllocatorTraits
->printPretty(OS
, nullptr, Policy
);
2486 void OMPClausePrinter::VisitOMPAffinityClause(OMPAffinityClause
*Node
) {
2487 if (Node
->varlist_empty())
2490 char StartSym
= '(';
2491 if (Expr
*Modifier
= Node
->getModifier()) {
2493 Modifier
->printPretty(OS
, nullptr, Policy
);
2497 VisitOMPClauseList(Node
, StartSym
);
2501 void OMPClausePrinter::VisitOMPFilterClause(OMPFilterClause
*Node
) {
2503 Node
->getThreadID()->printPretty(OS
, nullptr, Policy
, 0);
2507 void OMPClausePrinter::VisitOMPBindClause(OMPBindClause
*Node
) {
2509 << getOpenMPSimpleClauseTypeName(OMPC_bind
, unsigned(Node
->getBindKind()))
2513 void OMPClausePrinter::VisitOMPXDynCGroupMemClause(
2514 OMPXDynCGroupMemClause
*Node
) {
2515 OS
<< "ompx_dyn_cgroup_mem(";
2516 Node
->getSize()->printPretty(OS
, nullptr, Policy
, 0);
2520 void OMPClausePrinter::VisitOMPDoacrossClause(OMPDoacrossClause
*Node
) {
2522 OpenMPDoacrossClauseModifier DepType
= Node
->getDependenceType();
2525 case OMPC_DOACROSS_source
:
2528 case OMPC_DOACROSS_sink
:
2531 case OMPC_DOACROSS_source_omp_cur_iteration
:
2532 OS
<< "source: omp_cur_iteration";
2534 case OMPC_DOACROSS_sink_omp_cur_iteration
:
2535 OS
<< "sink: omp_cur_iteration - 1";
2538 llvm_unreachable("unknown docaross modifier");
2540 VisitOMPClauseList(Node
, ' ');
2544 void OMPClausePrinter::VisitOMPXAttributeClause(OMPXAttributeClause
*Node
) {
2545 OS
<< "ompx_attribute(";
2546 bool IsFirst
= true;
2547 for (auto &Attr
: Node
->getAttrs()) {
2550 Attr
->printPretty(OS
, Policy
);
2556 void OMPClausePrinter::VisitOMPXBareClause(OMPXBareClause
*Node
) {
2560 void OMPTraitInfo::getAsVariantMatchInfo(ASTContext
&ASTCtx
,
2561 VariantMatchInfo
&VMI
) const {
2562 for (const OMPTraitSet
&Set
: Sets
) {
2563 for (const OMPTraitSelector
&Selector
: Set
.Selectors
) {
2565 // User conditions are special as we evaluate the condition here.
2566 if (Selector
.Kind
== TraitSelector::user_condition
) {
2567 assert(Selector
.ScoreOrCondition
&&
2568 "Ill-formed user condition, expected condition expression!");
2569 assert(Selector
.Properties
.size() == 1 &&
2570 Selector
.Properties
.front().Kind
==
2571 TraitProperty::user_condition_unknown
&&
2572 "Ill-formed user condition, expected unknown trait property!");
2574 if (std::optional
<APSInt
> CondVal
=
2575 Selector
.ScoreOrCondition
->getIntegerConstantExpr(ASTCtx
))
2576 VMI
.addTrait(CondVal
->isZero() ? TraitProperty::user_condition_false
2577 : TraitProperty::user_condition_true
,
2580 VMI
.addTrait(TraitProperty::user_condition_false
, "<condition>");
2584 std::optional
<llvm::APSInt
> Score
;
2585 llvm::APInt
*ScorePtr
= nullptr;
2586 if (Selector
.ScoreOrCondition
) {
2587 if ((Score
= Selector
.ScoreOrCondition
->getIntegerConstantExpr(ASTCtx
)))
2590 VMI
.addTrait(TraitProperty::user_condition_false
,
2591 "<non-constant-score>");
2594 for (const OMPTraitProperty
&Property
: Selector
.Properties
)
2595 VMI
.addTrait(Set
.Kind
, Property
.Kind
, Property
.RawString
, ScorePtr
);
2597 if (Set
.Kind
!= TraitSet::construct
)
2600 // TODO: This might not hold once we implement SIMD properly.
2601 assert(Selector
.Properties
.size() == 1 &&
2602 Selector
.Properties
.front().Kind
==
2603 getOpenMPContextTraitPropertyForSelector(
2605 "Ill-formed construct selector!");
2610 void OMPTraitInfo::print(llvm::raw_ostream
&OS
,
2611 const PrintingPolicy
&Policy
) const {
2612 bool FirstSet
= true;
2613 for (const OMPTraitSet
&Set
: Sets
) {
2617 OS
<< getOpenMPContextTraitSetName(Set
.Kind
) << "={";
2619 bool FirstSelector
= true;
2620 for (const OMPTraitSelector
&Selector
: Set
.Selectors
) {
2623 FirstSelector
= false;
2624 OS
<< getOpenMPContextTraitSelectorName(Selector
.Kind
);
2626 bool AllowsTraitScore
= false;
2627 bool RequiresProperty
= false;
2628 isValidTraitSelectorForTraitSet(
2629 Selector
.Kind
, Set
.Kind
, AllowsTraitScore
, RequiresProperty
);
2631 if (!RequiresProperty
)
2635 if (Selector
.Kind
== TraitSelector::user_condition
) {
2636 if (Selector
.ScoreOrCondition
)
2637 Selector
.ScoreOrCondition
->printPretty(OS
, nullptr, Policy
);
2642 if (Selector
.ScoreOrCondition
) {
2644 Selector
.ScoreOrCondition
->printPretty(OS
, nullptr, Policy
);
2648 bool FirstProperty
= true;
2649 for (const OMPTraitProperty
&Property
: Selector
.Properties
) {
2652 FirstProperty
= false;
2653 OS
<< getOpenMPContextTraitPropertyName(Property
.Kind
,
2654 Property
.RawString
);
2663 std::string
OMPTraitInfo::getMangledName() const {
2664 std::string MangledName
;
2665 llvm::raw_string_ostream
OS(MangledName
);
2666 for (const OMPTraitSet
&Set
: Sets
) {
2667 OS
<< '$' << 'S' << unsigned(Set
.Kind
);
2668 for (const OMPTraitSelector
&Selector
: Set
.Selectors
) {
2670 bool AllowsTraitScore
= false;
2671 bool RequiresProperty
= false;
2672 isValidTraitSelectorForTraitSet(
2673 Selector
.Kind
, Set
.Kind
, AllowsTraitScore
, RequiresProperty
);
2674 OS
<< '$' << 's' << unsigned(Selector
.Kind
);
2676 if (!RequiresProperty
||
2677 Selector
.Kind
== TraitSelector::user_condition
)
2680 for (const OMPTraitProperty
&Property
: Selector
.Properties
)
2682 << getOpenMPContextTraitPropertyName(Property
.Kind
,
2683 Property
.RawString
);
2689 OMPTraitInfo::OMPTraitInfo(StringRef MangledName
) {
2692 if (!MangledName
.consume_front("$S"))
2694 if (MangledName
.consumeInteger(10, U
))
2696 Sets
.push_back(OMPTraitSet());
2697 OMPTraitSet
&Set
= Sets
.back();
2698 Set
.Kind
= TraitSet(U
);
2700 if (!MangledName
.consume_front("$s"))
2702 if (MangledName
.consumeInteger(10, U
))
2704 Set
.Selectors
.push_back(OMPTraitSelector());
2705 OMPTraitSelector
&Selector
= Set
.Selectors
.back();
2706 Selector
.Kind
= TraitSelector(U
);
2708 if (!MangledName
.consume_front("$P"))
2710 Selector
.Properties
.push_back(OMPTraitProperty());
2711 OMPTraitProperty
&Property
= Selector
.Properties
.back();
2712 std::pair
<StringRef
, StringRef
> PropRestPair
= MangledName
.split('$');
2713 Property
.RawString
= PropRestPair
.first
;
2714 Property
.Kind
= getOpenMPContextTraitPropertyKind(
2715 Set
.Kind
, Selector
.Kind
, PropRestPair
.first
);
2716 MangledName
= MangledName
.drop_front(PropRestPair
.first
.size());
2722 llvm::raw_ostream
&clang::operator<<(llvm::raw_ostream
&OS
,
2723 const OMPTraitInfo
&TI
) {
2725 PrintingPolicy
Policy(LO
);
2726 TI
.print(OS
, Policy
);
2729 llvm::raw_ostream
&clang::operator<<(llvm::raw_ostream
&OS
,
2730 const OMPTraitInfo
*TI
) {
2731 return TI
? OS
<< *TI
: OS
;
2734 TargetOMPContext::TargetOMPContext(
2735 ASTContext
&ASTCtx
, std::function
<void(StringRef
)> &&DiagUnknownTrait
,
2736 const FunctionDecl
*CurrentFunctionDecl
,
2737 ArrayRef
<llvm::omp::TraitProperty
> ConstructTraits
)
2738 : OMPContext(ASTCtx
.getLangOpts().OpenMPIsTargetDevice
,
2739 ASTCtx
.getTargetInfo().getTriple()),
2740 FeatureValidityCheck([&](StringRef FeatureName
) {
2741 return ASTCtx
.getTargetInfo().isValidFeatureName(FeatureName
);
2743 DiagUnknownTrait(std::move(DiagUnknownTrait
)) {
2744 ASTCtx
.getFunctionFeatureMap(FeatureMap
, CurrentFunctionDecl
);
2746 for (llvm::omp::TraitProperty Property
: ConstructTraits
)
2750 bool TargetOMPContext::matchesISATrait(StringRef RawString
) const {
2751 auto It
= FeatureMap
.find(RawString
);
2752 if (It
!= FeatureMap
.end())
2754 if (!FeatureValidityCheck(RawString
))
2755 DiagUnknownTrait(RawString
);