21 #include "llvm/ADT/SmallPtrSet.h"
22 #include "llvm/Support/Casting.h"
23 #include "llvm/Support/ErrorHandling.h"
27 using namespace clang;
32 switch (getClauseKind()) {
35 #define GEN_CLANG_CLAUSE_CLASS
36 #define CLAUSE_CLASS(Enum, Str, Class) \
38 return static_cast<Class *>(this)->children();
39 #include "llvm/Frontend/OpenMP/OMP.inc"
41 llvm_unreachable(
"unknown OMPClause");
45 switch (getClauseKind()) {
46 #define GEN_CLANG_CLAUSE_CLASS
47 #define CLAUSE_CLASS(Enum, Str, Class) \
49 return static_cast<Class *>(this)->used_children();
50 #define CLAUSE_NO_CLASS(Enum, Str) \
53 #include "llvm/Frontend/OpenMP/OMP.inc"
55 llvm_unreachable(
"unknown OMPClause");
64 switch (C->getClauseKind()) {
67 case OMPC_dist_schedule:
69 case OMPC_firstprivate:
71 case OMPC_lastprivate:
75 case OMPC_task_reduction:
77 case OMPC_in_reduction:
83 case OMPC_num_threads:
87 case OMPC_thread_limit:
111 case OMPC_copyprivate:
116 case OMPC_threadprivate:
134 case OMPC_defaultmap:
139 case OMPC_use_device_ptr:
140 case OMPC_use_device_addr:
141 case OMPC_is_device_ptr:
142 case OMPC_unified_address:
143 case OMPC_unified_shared_memory:
144 case OMPC_reverse_offload:
145 case OMPC_dynamic_allocators:
146 case OMPC_atomic_default_mem_order:
147 case OMPC_device_type:
149 case OMPC_nontemporal:
155 case OMPC_uses_allocators:
171 switch (C->getClauseKind()) {
172 case OMPC_lastprivate:
176 case OMPC_task_reduction:
178 case OMPC_in_reduction:
183 case OMPC_dist_schedule:
184 case OMPC_firstprivate:
189 case OMPC_num_threads:
200 case OMPC_copyprivate:
205 case OMPC_threadprivate:
223 case OMPC_thread_limit:
229 case OMPC_defaultmap:
234 case OMPC_use_device_ptr:
235 case OMPC_use_device_addr:
236 case OMPC_is_device_ptr:
237 case OMPC_unified_address:
238 case OMPC_unified_shared_memory:
239 case OMPC_reverse_offload:
240 case OMPC_dynamic_allocators:
241 case OMPC_atomic_default_mem_order:
242 case OMPC_device_type:
244 case OMPC_nontemporal:
250 case OMPC_uses_allocators:
265 if (
auto *DS = dyn_cast<DeclStmt>(S)) {
266 assert(DS->isSingleDecl() &&
"Only single expression must be captured.");
267 if (
auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
268 return OED->getInitAddress();
308 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
311 for (
unsigned I = 0; I < NumLoops; ++I) {
313 Clause->setLoopCounter(I,
nullptr);
320 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
322 for (
unsigned I = 0; I < NumLoops; ++I) {
324 Clause->setLoopCounter(I,
nullptr);
330 Expr *NumIterations) {
331 assert(NumLoop < NumberOfLoops &&
"out of loops number.");
332 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
336 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
340 assert(NumLoop < NumberOfLoops &&
"out of loops number.");
341 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
345 assert(NumLoop < NumberOfLoops &&
"out of loops number.");
346 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
350 assert(NumLoop < NumberOfLoops &&
"out of loops number.");
351 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
365 C.Allocate(totalSizeToAlloc<SourceLocation, OpenMPDependClauseKind>(2, 1),
369 Clause->setLParenLoc(LParenLoc);
370 Clause->setArgumentLoc(ArgumentLoc);
371 Clause->setDependencyKind(DK);
380 C.Allocate(totalSizeToAlloc<SourceLocation, OpenMPDependClauseKind>(2, 1),
383 Clause->IsExtended =
true;
388 assert(VL.size() == varlist_size() &&
389 "Number of private copies is not the same as the preallocated buffer");
390 std::copy(VL.begin(), VL.end(), varlist_end());
398 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
402 Clause->setPrivateCopies(PrivateVL);
408 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
413 assert(VL.size() == varlist_size() &&
414 "Number of private copies is not the same as the preallocated buffer");
415 std::copy(VL.begin(), VL.end(), varlist_end());
419 assert(VL.size() == varlist_size() &&
420 "Number of inits is not the same as the preallocated buffer");
421 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
429 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
433 Clause->setPrivateCopies(PrivateVL);
434 Clause->setInits(InitVL);
441 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
446 assert(PrivateCopies.size() == varlist_size() &&
447 "Number of private copies is not the same as the preallocated buffer");
448 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
452 assert(SrcExprs.size() == varlist_size() &&
"Number of source expressions is "
453 "not the same as the "
454 "preallocated buffer");
455 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
459 assert(DstExprs.size() == varlist_size() &&
"Number of destination "
460 "expressions is not the same as "
461 "the preallocated buffer");
462 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
465 void OMPLastprivateClause::setAssignmentOps(
ArrayRef<Expr *> AssignmentOps) {
466 assert(AssignmentOps.size() == varlist_size() &&
467 "Number of assignment expressions is not the same as the preallocated "
469 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
470 getDestinationExprs().end());
479 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
481 StartLoc, LParenLoc, EndLoc, LPKind, LPKindLoc, ColonLoc, VL.size());
483 Clause->setSourceExprs(SrcExprs);
484 Clause->setDestinationExprs(DstExprs);
485 Clause->setAssignmentOps(AssignmentOps);
493 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
502 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
510 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
515 assert(PL.size() == varlist_size() &&
516 "Number of privates is not the same as the preallocated buffer");
517 std::copy(PL.begin(), PL.end(), varlist_end());
521 assert(IL.size() == varlist_size() &&
522 "Number of inits is not the same as the preallocated buffer");
523 std::copy(IL.begin(), IL.end(), getPrivates().end());
527 assert(UL.size() == varlist_size() &&
528 "Number of updates is not the same as the preallocated buffer");
529 std::copy(UL.begin(), UL.end(), getInits().end());
533 assert(FL.size() == varlist_size() &&
534 "Number of final updates is not the same as the preallocated buffer");
535 std::copy(FL.begin(), FL.end(), getUpdates().end());
540 UE.size() == varlist_size() + 1 &&
541 "Number of used expressions is not the same as the preallocated buffer");
542 std::copy(UE.begin(), UE.end(), getFinals().end() + 2);
554 C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1));
556 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
558 Clause->setPrivates(PL);
559 Clause->setInits(IL);
562 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
564 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
566 std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(),
568 Clause->setStep(Step);
569 Clause->setCalcStep(CalcStep);
579 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars +1));
586 reinterpret_cast<Stmt **
>(getUsedExprs().begin()),
587 reinterpret_cast<Stmt **
>(llvm::find(getUsedExprs(),
nullptr)));
594 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
598 Clause->setAlignment(A);
604 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
609 assert(SrcExprs.size() == varlist_size() &&
"Number of source expressions is "
610 "not the same as the "
611 "preallocated buffer");
612 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
616 assert(DstExprs.size() == varlist_size() &&
"Number of destination "
617 "expressions is not the same as "
618 "the preallocated buffer");
619 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
623 assert(AssignmentOps.size() == varlist_size() &&
624 "Number of assignment expressions is not the same as the preallocated "
626 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
627 getDestinationExprs().end());
634 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
638 Clause->setSourceExprs(SrcExprs);
639 Clause->setDestinationExprs(DstExprs);
640 Clause->setAssignmentOps(AssignmentOps);
645 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
650 assert(SrcExprs.size() == varlist_size() &&
"Number of source expressions is "
651 "not the same as the "
652 "preallocated buffer");
653 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
657 assert(DstExprs.size() == varlist_size() &&
"Number of destination "
658 "expressions is not the same as "
659 "the preallocated buffer");
660 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
663 void OMPCopyprivateClause::setAssignmentOps(
ArrayRef<Expr *> AssignmentOps) {
664 assert(AssignmentOps.size() == varlist_size() &&
665 "Number of assignment expressions is not the same as the preallocated "
667 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
668 getDestinationExprs().end());
675 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
679 Clause->setSourceExprs(SrcExprs);
680 Clause->setDestinationExprs(DstExprs);
681 Clause->setAssignmentOps(AssignmentOps);
687 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
692 assert(Privates.size() == varlist_size() &&
693 "Number of private copies is not the same as the preallocated buffer");
694 std::copy(Privates.begin(), Privates.end(), varlist_end());
699 LHSExprs.size() == varlist_size() &&
700 "Number of LHS expressions is not the same as the preallocated buffer");
701 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
706 RHSExprs.size() == varlist_size() &&
707 "Number of RHS expressions is not the same as the preallocated buffer");
708 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
712 assert(ReductionOps.size() == varlist_size() &&
"Number of reduction "
713 "expressions is not the same "
714 "as the preallocated buffer");
715 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
719 assert(Modifier == OMPC_REDUCTION_inscan &&
"Expected inscan reduction.");
720 assert(Ops.size() == varlist_size() &&
"Number of copy "
721 "expressions is not the same "
722 "as the preallocated buffer");
723 llvm::copy(Ops, getReductionOps().end());
726 void OMPReductionClause::setInscanCopyArrayTemps(
728 assert(Modifier == OMPC_REDUCTION_inscan &&
"Expected inscan reduction.");
729 assert(CopyArrayTemps.size() == varlist_size() &&
730 "Number of copy temp expressions is not the same as the preallocated "
732 llvm::copy(CopyArrayTemps, getInscanCopyOps().end());
735 void OMPReductionClause::setInscanCopyArrayElems(
737 assert(Modifier == OMPC_REDUCTION_inscan &&
"Expected inscan reduction.");
738 assert(CopyArrayElems.size() == varlist_size() &&
739 "Number of copy temp expressions is not the same as the preallocated "
741 llvm::copy(CopyArrayElems, getInscanCopyArrayTemps().end());
753 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(
754 (Modifier == OMPC_REDUCTION_inscan ? 8 : 5) * VL.size()));
755 auto *Clause =
new (Mem)
757 Modifier, VL.size(), QualifierLoc, NameInfo);
759 Clause->setPrivates(Privates);
760 Clause->setLHSExprs(LHSExprs);
761 Clause->setRHSExprs(RHSExprs);
762 Clause->setReductionOps(ReductionOps);
763 Clause->setPreInitStmt(PreInit);
764 Clause->setPostUpdateExpr(PostUpdate);
765 if (Modifier == OMPC_REDUCTION_inscan) {
766 Clause->setInscanCopyOps(CopyOps);
767 Clause->setInscanCopyArrayTemps(CopyArrayTemps);
768 Clause->setInscanCopyArrayElems(CopyArrayElems);
770 assert(CopyOps.empty() &&
771 "copy operations are expected in inscan reductions only.");
772 assert(CopyArrayTemps.empty() &&
773 "copy array temps are expected in inscan reductions only.");
774 assert(CopyArrayElems.empty() &&
775 "copy array temps are expected in inscan reductions only.");
783 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(
784 (Modifier == OMPC_REDUCTION_inscan ? 8 : 5) * N));
786 Clause->setModifier(Modifier);
791 assert(Privates.size() == varlist_size() &&
792 "Number of private copies is not the same as the preallocated buffer");
793 std::copy(Privates.begin(), Privates.end(), varlist_end());
798 LHSExprs.size() == varlist_size() &&
799 "Number of LHS expressions is not the same as the preallocated buffer");
800 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
805 RHSExprs.size() == varlist_size() &&
806 "Number of RHS expressions is not the same as the preallocated buffer");
807 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
810 void OMPTaskReductionClause::setReductionOps(
ArrayRef<Expr *> ReductionOps) {
811 assert(ReductionOps.size() == varlist_size() &&
"Number of task reduction "
812 "expressions is not the same "
813 "as the preallocated buffer");
814 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
824 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
826 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
828 Clause->setPrivates(Privates);
829 Clause->setLHSExprs(LHSExprs);
830 Clause->setRHSExprs(RHSExprs);
831 Clause->setReductionOps(ReductionOps);
839 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
844 assert(Privates.size() == varlist_size() &&
845 "Number of private copies is not the same as the preallocated buffer");
846 std::copy(Privates.begin(), Privates.end(), varlist_end());
851 LHSExprs.size() == varlist_size() &&
852 "Number of LHS expressions is not the same as the preallocated buffer");
853 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
858 RHSExprs.size() == varlist_size() &&
859 "Number of RHS expressions is not the same as the preallocated buffer");
860 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
864 assert(ReductionOps.size() == varlist_size() &&
"Number of in reduction "
865 "expressions is not the same "
866 "as the preallocated buffer");
867 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
870 void OMPInReductionClause::setTaskgroupDescriptors(
872 assert(TaskgroupDescriptors.size() == varlist_size() &&
873 "Number of in reduction descriptors is not the same as the "
874 "preallocated buffer");
875 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
876 getReductionOps().end());
886 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
888 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
890 Clause->setPrivates(Privates);
891 Clause->setLHSExprs(LHSExprs);
892 Clause->setRHSExprs(RHSExprs);
893 Clause->setReductionOps(ReductionOps);
894 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
902 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
921 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumSizes));
931 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
933 ColonLoc, EndLoc, VL.size());
940 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
949 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
957 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
966 auto *Clause =
new (C)
OMPDepobjClause(StartLoc, LParenLoc, RParenLoc);
967 Clause->setDepobj(Depobj);
981 void *Mem = C.Allocate(
982 totalSizeToAlloc<Expr *>(VL.size() + 1 + NumLoops),
987 Clause->setDependencyKind(DepKind);
988 Clause->setDependencyLoc(DepLoc);
989 Clause->setColonLoc(ColonLoc);
990 Clause->setModifier(DepModifier);
991 for (
unsigned I = 0 ; I < NumLoops; ++I)
999 C.Allocate(totalSizeToAlloc<Expr *>(N + 1 + NumLoops),
1005 assert((getDependencyKind() == OMPC_DEPEND_sink ||
1006 getDependencyKind() == OMPC_DEPEND_source) &&
1007 NumLoop < NumLoops &&
1008 "Expected sink or source depend + loop index must be less number of "
1010 auto *It = std::next(getVarRefs().end(), NumLoop + 1);
1015 assert((getDependencyKind() == OMPC_DEPEND_sink ||
1016 getDependencyKind() == OMPC_DEPEND_source) &&
1017 NumLoop < NumLoops &&
1018 "Expected sink or source depend + loop index must be less number of "
1020 auto *It = std::next(getVarRefs().end(), NumLoop + 1);
1025 assert((getDependencyKind() == OMPC_DEPEND_sink ||
1026 getDependencyKind() == OMPC_DEPEND_source) &&
1027 NumLoop < NumLoops &&
1028 "Expected sink or source depend + loop index must be less number of "
1030 const auto *It = std::next(getVarRefs().end(), NumLoop + 1);
1034 void OMPDependClause::setModifier(
Expr *DepModifier) {
1035 *getVarRefs().end() = DepModifier;
1041 unsigned TotalNum = 0u;
1042 for (
auto &C : ComponentLists)
1043 TotalNum += C.size();
1049 unsigned TotalNum = 0u;
1051 for (
const ValueDecl *D : Declarations) {
1052 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) :
nullptr;
1053 if (
Cache.count(VD))
1073 Sizes.
NumComponents = getComponentsTotalNumber(ComponentLists);
1085 void *Mem = C.Allocate(
1092 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
1098 Clause->setMapType(
Type);
1106 void *Mem = C.Allocate(
1126 Sizes.
NumComponents = getComponentsTotalNumber(ComponentLists);
1138 void *Mem = C.Allocate(
1145 auto *Clause =
new (Mem)
OMPToClause(MotionModifiers, MotionModifiersLoc,
1146 UDMQualifierLoc, MapperId, Locs, Sizes);
1149 Clause->setUDMapperRefs(UDMapperRefs);
1150 Clause->setClauseInfo(Declarations, ComponentLists);
1156 void *Mem = C.Allocate(
1176 Sizes.
NumComponents = getComponentsTotalNumber(ComponentLists);
1188 void *Mem = C.Allocate(
1196 new (Mem)
OMPFromClause(MotionModifiers, MotionModifiersLoc,
1197 UDMQualifierLoc, MapperId, Locs, Sizes);
1200 Clause->setUDMapperRefs(UDMapperRefs);
1201 Clause->setClauseInfo(Declarations, ComponentLists);
1208 void *Mem = C.Allocate(
1218 assert(VL.size() == varlist_size() &&
1219 "Number of private copies is not the same as the preallocated buffer");
1220 std::copy(VL.begin(), VL.end(), varlist_end());
1224 assert(VL.size() == varlist_size() &&
1225 "Number of inits is not the same as the preallocated buffer");
1226 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1238 Sizes.
NumComponents = getComponentsTotalNumber(ComponentLists);
1250 void *Mem = C.Allocate(
1260 Clause->setPrivateCopies(PrivateVars);
1261 Clause->setInits(Inits);
1269 void *Mem = C.Allocate(
1287 Sizes.
NumComponents = getComponentsTotalNumber(ComponentLists);
1299 void *Mem = C.Allocate(
1309 Clause->setClauseInfo(Declarations, ComponentLists);
1316 void *Mem = C.Allocate(
1334 Sizes.
NumComponents = getComponentsTotalNumber(ComponentLists);
1346 void *Mem = C.Allocate(
1363 void *Mem = C.Allocate(
1378 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
1387 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
1392 assert(VL.size() == varlist_size() &&
"Number of private references is not "
1393 "the same as the preallocated buffer");
1394 std::copy(VL.begin(), VL.end(), varlist_end());
1402 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
1411 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
1420 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
1429 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
1433 void OMPUsesAllocatorsClause::setAllocatorsData(
1435 assert(Data.size() == NumOfAllocators &&
1436 "Size of allocators data is not the same as the preallocated buffer.");
1437 for (
unsigned I = 0, E = Data.size(); I < E; ++I) {
1439 getTrailingObjects<Expr *>()[I *
static_cast<int>(ExprOffsets::Total) +
1440 static_cast<int>(ExprOffsets::Allocator)] =
1442 getTrailingObjects<Expr *>()[I *
static_cast<int>(ExprOffsets::Total) +
1444 ExprOffsets::AllocatorTraits)] =
1447 SourceLocation>()[I *
static_cast<int>(ParenLocsOffsets::Total) +
1448 static_cast<int>(ParenLocsOffsets::LParen)] =
1451 SourceLocation>()[I *
static_cast<int>(ParenLocsOffsets::Total) +
1452 static_cast<int>(ParenLocsOffsets::RParen)] =
1461 getTrailingObjects<Expr *>()[I *
static_cast<int>(ExprOffsets::Total) +
1462 static_cast<int>(ExprOffsets::Allocator)];
1464 getTrailingObjects<Expr *>()[I *
static_cast<int>(ExprOffsets::Total) +
1466 ExprOffsets::AllocatorTraits)];
1468 SourceLocation>()[I *
static_cast<int>(ParenLocsOffsets::Total) +
1469 static_cast<int>(ParenLocsOffsets::LParen)];
1471 SourceLocation>()[I *
static_cast<int>(ParenLocsOffsets::Total) +
1472 static_cast<int>(ParenLocsOffsets::RParen)];
1480 void *Mem = C.Allocate(totalSizeToAlloc<Expr *, SourceLocation>(
1481 static_cast<int>(ExprOffsets::Total) *
Data.size(),
1482 static_cast<int>(ParenLocsOffsets::Total) *
Data.size()));
1483 auto *Clause =
new (Mem)
1485 Clause->setAllocatorsData(
Data);
1491 void *Mem = C.Allocate(totalSizeToAlloc<Expr *, SourceLocation>(
1492 static_cast<int>(ExprOffsets::Total) * N,
1493 static_cast<int>(ParenLocsOffsets::Total) * N));
1502 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(Locators.size() + 1));
1503 auto *Clause =
new (Mem)
1505 Clause->setModifier(Modifier);
1506 Clause->setVarRefs(Locators);
1512 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + 1));
1522 if (
Node->getNameModifier() != OMPD_unknown)
1523 OS << getOpenMPDirectiveName(
Node->getNameModifier()) <<
": ";
1524 Node->getCondition()->printPretty(OS,
nullptr, Policy, 0);
1530 Node->getCondition()->printPretty(OS,
nullptr, Policy, 0);
1535 OS <<
"num_threads(";
1536 Node->getNumThreads()->printPretty(OS,
nullptr, Policy, 0);
1542 Node->getSafelen()->printPretty(OS,
nullptr, Policy, 0);
1548 Node->getSimdlen()->printPretty(OS,
nullptr, Policy, 0);
1555 for (
auto Size :
Node->getSizesRefs()) {
1558 Size->printPretty(OS,
nullptr, Policy, 0);
1566 Node->getAllocator()->printPretty(OS,
nullptr, Policy, 0);
1572 Node->getNumForLoops()->printPretty(OS,
nullptr, Policy, 0);
1578 Node->getEventHandler()->printPretty(OS,
nullptr, Policy, 0);
1585 unsigned(
Node->getDefaultKind()))
1592 unsigned(
Node->getProcBindKind()))
1597 OS <<
"unified_address";
1600 void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1602 OS <<
"unified_shared_memory";
1606 OS <<
"reverse_offload";
1609 void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1611 OS <<
"dynamic_allocators";
1614 void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1616 OS <<
"atomic_default_mem_order("
1618 Node->getAtomicDefaultMemOrderKind())
1626 Node->getFirstScheduleModifier());
1630 Node->getSecondScheduleModifier());
1635 if (
auto *E =
Node->getChunkSize()) {
1637 E->printPretty(OS,
nullptr, Policy);
1644 if (
auto *Num =
Node->getNumForLoops()) {
1646 Num->printPretty(OS,
nullptr, Policy, 0);
1667 void OMPClausePrinter::VisitOMPReadClause(
OMPReadClause *) {
OS <<
"read"; }
1669 void OMPClausePrinter::VisitOMPWriteClause(
OMPWriteClause *) {
OS <<
"write"; }
1673 if (
Node->isExtended()) {
1676 Node->getDependencyKind());
1709 void OMPClausePrinter::VisitOMPSIMDClause(
OMPSIMDClause *) {
OS <<
"simd"; }
1718 Node->getDevice()->printPretty(OS,
nullptr, Policy, 0);
1724 Node->getNumTeams()->printPretty(OS,
nullptr, Policy, 0);
1729 OS <<
"thread_limit(";
1730 Node->getThreadLimit()->printPretty(OS,
nullptr, Policy, 0);
1736 Node->getPriority()->printPretty(OS,
nullptr, Policy, 0);
1742 Node->getGrainsize()->printPretty(OS,
nullptr, Policy, 0);
1748 Node->getNumTasks()->printPretty(OS,
nullptr, Policy, 0);
1754 Node->getHint()->printPretty(OS,
nullptr, Policy, 0);
1762 template<
typename T>
1763 void OMPClausePrinter::VisitOMPClauseList(T *
Node,
char StartSym) {
1764 for (
typename T::varlist_iterator I =
Node->varlist_begin(),
1765 E =
Node->varlist_end();
1767 assert(*I &&
"Expected non-null Stmt");
1768 OS << (I ==
Node->varlist_begin() ? StartSym :
',');
1769 if (
auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1770 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1771 DRE->printPretty(OS,
nullptr, Policy, 0);
1773 DRE->getDecl()->printQualifiedName(OS);
1775 (*I)->printPretty(OS,
nullptr, Policy, 0);
1780 if (
Node->varlist_empty())
1783 if (
Expr *Allocator =
Node->getAllocator()) {
1785 Allocator->printPretty(OS,
nullptr, Policy, 0);
1787 VisitOMPClauseList(
Node,
' ');
1789 VisitOMPClauseList(
Node,
'(');
1795 if (!
Node->varlist_empty()) {
1797 VisitOMPClauseList(
Node,
'(');
1803 if (!
Node->varlist_empty()) {
1804 OS <<
"firstprivate";
1805 VisitOMPClauseList(
Node,
'(');
1811 if (!
Node->varlist_empty()) {
1812 OS <<
"lastprivate";
1825 if (!
Node->varlist_empty()) {
1827 VisitOMPClauseList(
Node,
'(');
1833 if (!
Node->varlist_empty()) {
1835 if (
Node->getModifierLoc().isValid())
1839 Node->getQualifierLoc().getNestedNameSpecifier();
1841 Node->getNameInfo().getName().getCXXOverloadedOperator();
1842 if (QualifierLoc ==
nullptr && OOK !=
OO_None) {
1847 if (QualifierLoc !=
nullptr)
1848 QualifierLoc->
print(OS, Policy);
1849 OS <<
Node->getNameInfo();
1852 VisitOMPClauseList(
Node,
' ');
1857 void OMPClausePrinter::VisitOMPTaskReductionClause(
1859 if (!
Node->varlist_empty()) {
1860 OS <<
"task_reduction(";
1862 Node->getQualifierLoc().getNestedNameSpecifier();
1864 Node->getNameInfo().getName().getCXXOverloadedOperator();
1865 if (QualifierLoc ==
nullptr && OOK !=
OO_None) {
1870 if (QualifierLoc !=
nullptr)
1871 QualifierLoc->
print(OS, Policy);
1872 OS <<
Node->getNameInfo();
1875 VisitOMPClauseList(
Node,
' ');
1881 if (!
Node->varlist_empty()) {
1882 OS <<
"in_reduction(";
1884 Node->getQualifierLoc().getNestedNameSpecifier();
1886 Node->getNameInfo().getName().getCXXOverloadedOperator();
1887 if (QualifierLoc ==
nullptr && OOK !=
OO_None) {
1892 if (QualifierLoc !=
nullptr)
1893 QualifierLoc->
print(OS, Policy);
1894 OS <<
Node->getNameInfo();
1897 VisitOMPClauseList(
Node,
' ');
1903 if (!
Node->varlist_empty()) {
1905 if (
Node->getModifierLoc().isValid()) {
1909 VisitOMPClauseList(
Node,
'(');
1910 if (
Node->getModifierLoc().isValid())
1912 if (
Node->getStep() !=
nullptr) {
1914 Node->getStep()->printPretty(OS,
nullptr, Policy, 0);
1921 if (!
Node->varlist_empty()) {
1923 VisitOMPClauseList(
Node,
'(');
1924 if (
Node->getAlignment() !=
nullptr) {
1926 Node->getAlignment()->printPretty(OS,
nullptr, Policy, 0);
1933 if (!
Node->varlist_empty()) {
1935 VisitOMPClauseList(
Node,
'(');
1941 if (!
Node->varlist_empty()) {
1942 OS <<
"copyprivate";
1943 VisitOMPClauseList(
Node,
'(');
1949 if (!
Node->varlist_empty()) {
1950 VisitOMPClauseList(
Node,
'(');
1957 Node->getDepobj()->printPretty(OS,
nullptr, Policy, 0);
1963 if (
Expr *DepModifier =
Node->getModifier()) {
1968 Node->getDependencyKind());
1969 if (!
Node->varlist_empty()) {
1971 VisitOMPClauseList(
Node,
' ');
1976 template <
typename T>
1981 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1983 MapperNNS->
print(OS, Policy);
1984 OS <<
Node->getMapperIdInfo() <<
')';
1988 if (!
Node->varlist_empty()) {
1994 Node->getMapTypeModifier(I));
1995 if (
Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper)
2003 VisitOMPClauseList(
Node,
' ');
2008 template <
typename T>
void OMPClausePrinter::VisitOMPMotionClause(T *
Node) {
2009 if (
Node->varlist_empty())
2011 OS << getOpenMPClauseName(
Node->getClauseKind());
2012 unsigned ModifierCount = 0;
2017 if (ModifierCount) {
2022 Node->getMotionModifier(I));
2023 if (
Node->getMotionModifier(I) == OMPC_MOTION_MODIFIER_mapper)
2025 if (I < ModifierCount - 1)
2030 VisitOMPClauseList(
Node,
' ');
2032 VisitOMPClauseList(
Node,
'(');
2038 VisitOMPMotionClause(
Node);
2042 VisitOMPMotionClause(
Node);
2047 OMPC_dist_schedule,
Node->getDistScheduleKind());
2048 if (
auto *E =
Node->getChunkSize()) {
2050 E->printPretty(OS,
nullptr, Policy);
2056 OS <<
"defaultmap(";
2058 Node->getDefaultmapModifier());
2062 Node->getDefaultmapKind());
2068 if (!
Node->varlist_empty()) {
2069 OS <<
"use_device_ptr";
2070 VisitOMPClauseList(
Node,
'(');
2075 void OMPClausePrinter::VisitOMPUseDeviceAddrClause(
2077 if (!
Node->varlist_empty()) {
2078 OS <<
"use_device_addr";
2079 VisitOMPClauseList(
Node,
'(');
2085 if (!
Node->varlist_empty()) {
2086 OS <<
"is_device_ptr";
2087 VisitOMPClauseList(
Node,
'(');
2093 if (!
Node->varlist_empty()) {
2094 OS <<
"nontemporal";
2095 VisitOMPClauseList(
Node,
'(');
2106 if (!
Node->varlist_empty()) {
2108 VisitOMPClauseList(
Node,
'(');
2114 if (!
Node->varlist_empty()) {
2116 VisitOMPClauseList(
Node,
'(');
2121 void OMPClausePrinter::VisitOMPUsesAllocatorsClause(
2123 if (
Node->getNumberOfAllocators() == 0)
2125 OS <<
"uses_allocators(";
2126 for (
unsigned I = 0, E =
Node->getNumberOfAllocators(); I < E; ++I) {
2141 if (
Node->varlist_empty())
2144 char StartSym =
'(';
2145 if (
Expr *Modifier =
Node->getModifier()) {
2147 Modifier->printPretty(OS,
nullptr, Policy);
2151 VisitOMPClauseList(
Node, StartSym);
2156 VariantMatchInfo &VMI)
const {
2161 if (
Selector.Kind == TraitSelector::user_condition) {
2162 assert(
Selector.ScoreOrCondition &&
2163 "Ill-formed user condition, expected condition expression!");
2164 assert(
Selector.Properties.size() == 1 &&
2165 Selector.Properties.front().Kind ==
2166 TraitProperty::user_condition_unknown &&
2167 "Ill-formed user condition, expected unknown trait property!");
2170 Selector.ScoreOrCondition->getIntegerConstantExpr(ASTCtx))
2171 VMI.addTrait(CondVal->isNullValue()
2172 ? TraitProperty::user_condition_false
2173 : TraitProperty::user_condition_true,
2176 VMI.addTrait(TraitProperty::user_condition_false,
"<condition>");
2183 if ((Score =
Selector.ScoreOrCondition->getIntegerConstantExpr(ASTCtx)))
2186 VMI.addTrait(TraitProperty::user_condition_false,
2187 "<non-constant-score>");
2193 if (Set.Kind != TraitSet::construct)
2197 assert(
Selector.Properties.size() == 1 &&
2198 Selector.Properties.front().Kind ==
2199 getOpenMPContextTraitPropertyForSelector(
2201 "Ill-formed construct selector!");
2203 VMI.ConstructTraits.push_back(
Selector.Properties.front().Kind);
2210 bool FirstSet =
true;
2215 OS << getOpenMPContextTraitSetName(Set.Kind) <<
"={";
2217 bool FirstSelector =
true;
2221 FirstSelector =
false;
2222 OS << getOpenMPContextTraitSelectorName(
Selector.Kind);
2224 bool AllowsTraitScore =
false;
2225 bool RequiresProperty =
false;
2226 isValidTraitSelectorForTraitSet(
2227 Selector.Kind, Set.Kind, AllowsTraitScore, RequiresProperty);
2229 if (!RequiresProperty)
2233 if (
Selector.Kind == TraitSelector::user_condition) {
2235 Selector.ScoreOrCondition->printPretty(OS,
nullptr, Policy);
2242 Selector.ScoreOrCondition->printPretty(OS,
nullptr, Policy);
2246 bool FirstProperty =
true;
2250 FirstProperty =
false;
2251 OS << getOpenMPContextTraitPropertyName(
Property.Kind,
2262 std::string MangledName;
2263 llvm::raw_string_ostream OS(MangledName);
2265 OS <<
'$' <<
'S' <<
unsigned(Set.Kind);
2268 bool AllowsTraitScore =
false;
2269 bool RequiresProperty =
false;
2270 isValidTraitSelectorForTraitSet(
2271 Selector.Kind, Set.Kind, AllowsTraitScore, RequiresProperty);
2274 if (!RequiresProperty ||
2275 Selector.Kind == TraitSelector::user_condition)
2280 << getOpenMPContextTraitPropertyName(
Property.Kind,
2287 OMPTraitInfo::OMPTraitInfo(StringRef MangledName) {
2290 if (!MangledName.consume_front(
"$S"))
2292 if (MangledName.consumeInteger(10,
U))
2296 Set.
Kind = TraitSet(
U);
2298 if (!MangledName.consume_front(
"$s"))
2300 if (MangledName.consumeInteger(10,
U))
2306 if (!MangledName.consume_front(
"$P"))
2310 std::pair<StringRef, StringRef> PropRestPair = MangledName.split(
'$');
2311 Property.RawString = PropRestPair.first;
2312 Property.Kind = getOpenMPContextTraitPropertyKind(
2314 MangledName = MangledName.drop_front(PropRestPair.first.size());
2324 TI.
print(OS, Policy);
2329 return TI ? OS << *TI : OS;
2333 ASTContext &ASTCtx, std::function<
void(StringRef)> &&DiagUnknownTrait,
2335 :
OMPContext(ASTCtx.getLangOpts().OpenMPIsDevice,
2336 ASTCtx.getTargetInfo().getTriple()),
2337 FeatureValidityCheck([&](StringRef FeatureName) {
2340 DiagUnknownTrait(std::move(DiagUnknownTrait)) {
2345 auto It = FeatureMap.find(RawString);
2346 if (It != FeatureMap.end())
2348 if (!FeatureValidityCheck(RawString))
2349 DiagUnknownTrait(RawString);