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:
117 case OMPC_copyprivate:
122 case OMPC_threadprivate:
141 case OMPC_defaultmap:
146 case OMPC_use_device_ptr:
147 case OMPC_use_device_addr:
148 case OMPC_is_device_ptr:
149 case OMPC_has_device_addr:
150 case OMPC_unified_address:
151 case OMPC_unified_shared_memory:
152 case OMPC_reverse_offload:
153 case OMPC_dynamic_allocators:
154 case OMPC_atomic_default_mem_order:
155 case OMPC_device_type:
157 case OMPC_nontemporal:
163 case OMPC_uses_allocators:
181 switch (C->getClauseKind()) {
182 case OMPC_lastprivate:
186 case OMPC_task_reduction:
188 case OMPC_in_reduction:
193 case OMPC_dist_schedule:
194 case OMPC_firstprivate:
199 case OMPC_num_threads:
210 case OMPC_copyprivate:
215 case OMPC_threadprivate:
234 case OMPC_thread_limit:
240 case OMPC_defaultmap:
245 case OMPC_use_device_ptr:
246 case OMPC_use_device_addr:
247 case OMPC_is_device_ptr:
248 case OMPC_has_device_addr:
249 case OMPC_unified_address:
250 case OMPC_unified_shared_memory:
251 case OMPC_reverse_offload:
252 case OMPC_dynamic_allocators:
253 case OMPC_atomic_default_mem_order:
254 case OMPC_device_type:
256 case OMPC_nontemporal:
259 case OMPC_novariants:
264 case OMPC_uses_allocators:
281 if (
auto *DS = dyn_cast<DeclStmt>(S)) {
282 assert(DS->isSingleDecl() &&
"Only single expression must be captured.");
283 if (
auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
284 return OED->getInitAddress();
336 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
339 for (
unsigned I = 0; I < NumLoops; ++I) {
341 Clause->setLoopCounter(I,
nullptr);
348 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
350 for (
unsigned I = 0; I < NumLoops; ++I) {
352 Clause->setLoopCounter(I,
nullptr);
358 Expr *NumIterations) {
359 assert(NumLoop < NumberOfLoops &&
"out of loops number.");
360 getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
364 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
368 assert(NumLoop < NumberOfLoops &&
"out of loops number.");
369 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
373 assert(NumLoop < NumberOfLoops &&
"out of loops number.");
374 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
378 assert(NumLoop < NumberOfLoops &&
"out of loops number.");
379 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
393 C.Allocate(totalSizeToAlloc<SourceLocation, OpenMPDependClauseKind>(2, 1),
397 Clause->setLParenLoc(LParenLoc);
398 Clause->setArgumentLoc(ArgumentLoc);
399 Clause->setDependencyKind(DK);
408 C.Allocate(totalSizeToAlloc<SourceLocation, OpenMPDependClauseKind>(2, 1),
411 Clause->IsExtended =
true;
416 assert(VL.size() == varlist_size() &&
417 "Number of private copies is not the same as the preallocated buffer");
418 std::copy(VL.begin(), VL.end(), varlist_end());
426 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
430 Clause->setPrivateCopies(PrivateVL);
436 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
441 assert(VL.size() == varlist_size() &&
442 "Number of private copies is not the same as the preallocated buffer");
443 std::copy(VL.begin(), VL.end(), varlist_end());
447 assert(VL.size() == varlist_size() &&
448 "Number of inits is not the same as the preallocated buffer");
449 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
457 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
461 Clause->setPrivateCopies(PrivateVL);
462 Clause->setInits(InitVL);
469 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
474 assert(PrivateCopies.size() == varlist_size() &&
475 "Number of private copies is not the same as the preallocated buffer");
476 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
480 assert(SrcExprs.size() == varlist_size() &&
"Number of source expressions is "
481 "not the same as the "
482 "preallocated buffer");
483 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
487 assert(DstExprs.size() == varlist_size() &&
"Number of destination "
488 "expressions is not the same as "
489 "the preallocated buffer");
490 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
493 void OMPLastprivateClause::setAssignmentOps(
ArrayRef<Expr *> AssignmentOps) {
494 assert(AssignmentOps.size() == varlist_size() &&
495 "Number of assignment expressions is not the same as the preallocated "
497 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
498 getDestinationExprs().end());
507 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
509 StartLoc, LParenLoc, EndLoc, LPKind, LPKindLoc, ColonLoc, VL.size());
511 Clause->setSourceExprs(SrcExprs);
512 Clause->setDestinationExprs(DstExprs);
513 Clause->setAssignmentOps(AssignmentOps);
521 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
530 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
538 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
543 assert(PL.size() == varlist_size() &&
544 "Number of privates is not the same as the preallocated buffer");
545 std::copy(PL.begin(), PL.end(), varlist_end());
549 assert(IL.size() == varlist_size() &&
550 "Number of inits is not the same as the preallocated buffer");
551 std::copy(IL.begin(), IL.end(), getPrivates().end());
555 assert(UL.size() == varlist_size() &&
556 "Number of updates is not the same as the preallocated buffer");
557 std::copy(UL.begin(), UL.end(), getInits().end());
561 assert(FL.size() == varlist_size() &&
562 "Number of final updates is not the same as the preallocated buffer");
563 std::copy(FL.begin(), FL.end(), getUpdates().end());
568 UE.size() == varlist_size() + 1 &&
569 "Number of used expressions is not the same as the preallocated buffer");
570 std::copy(UE.begin(), UE.end(), getFinals().end() + 2);
582 C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1));
584 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
586 Clause->setPrivates(PL);
587 Clause->setInits(IL);
590 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
592 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
594 std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(),
596 Clause->setStep(Step);
597 Clause->setCalcStep(CalcStep);
607 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars +1));
614 reinterpret_cast<Stmt **
>(getUsedExprs().begin()),
615 reinterpret_cast<Stmt **
>(llvm::find(getUsedExprs(),
nullptr)));
622 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
626 Clause->setAlignment(A);
632 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
644 assert(SrcExprs.size() == varlist_size() &&
"Number of source expressions is "
645 "not the same as the "
646 "preallocated buffer");
647 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
651 assert(DstExprs.size() == varlist_size() &&
"Number of destination "
652 "expressions is not the same as "
653 "the preallocated buffer");
654 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
658 assert(AssignmentOps.size() == varlist_size() &&
659 "Number of assignment expressions is not the same as the preallocated "
661 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
662 getDestinationExprs().end());
669 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
673 Clause->setSourceExprs(SrcExprs);
674 Clause->setDestinationExprs(DstExprs);
675 Clause->setAssignmentOps(AssignmentOps);
680 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
685 assert(SrcExprs.size() == varlist_size() &&
"Number of source expressions is "
686 "not the same as the "
687 "preallocated buffer");
688 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
692 assert(DstExprs.size() == varlist_size() &&
"Number of destination "
693 "expressions is not the same as "
694 "the preallocated buffer");
695 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
698 void OMPCopyprivateClause::setAssignmentOps(
ArrayRef<Expr *> AssignmentOps) {
699 assert(AssignmentOps.size() == varlist_size() &&
700 "Number of assignment expressions is not the same as the preallocated "
702 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
703 getDestinationExprs().end());
710 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
714 Clause->setSourceExprs(SrcExprs);
715 Clause->setDestinationExprs(DstExprs);
716 Clause->setAssignmentOps(AssignmentOps);
722 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
727 assert(Privates.size() == varlist_size() &&
728 "Number of private copies is not the same as the preallocated buffer");
729 std::copy(Privates.begin(), Privates.end(), varlist_end());
734 LHSExprs.size() == varlist_size() &&
735 "Number of LHS expressions is not the same as the preallocated buffer");
736 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
741 RHSExprs.size() == varlist_size() &&
742 "Number of RHS expressions is not the same as the preallocated buffer");
743 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
747 assert(ReductionOps.size() == varlist_size() &&
"Number of reduction "
748 "expressions is not the same "
749 "as the preallocated buffer");
750 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
754 assert(Modifier == OMPC_REDUCTION_inscan &&
"Expected inscan reduction.");
755 assert(Ops.size() == varlist_size() &&
"Number of copy "
756 "expressions is not the same "
757 "as the preallocated buffer");
758 llvm::copy(Ops, getReductionOps().end());
761 void OMPReductionClause::setInscanCopyArrayTemps(
763 assert(Modifier == OMPC_REDUCTION_inscan &&
"Expected inscan reduction.");
764 assert(CopyArrayTemps.size() == varlist_size() &&
765 "Number of copy temp expressions is not the same as the preallocated "
767 llvm::copy(CopyArrayTemps, getInscanCopyOps().end());
770 void OMPReductionClause::setInscanCopyArrayElems(
772 assert(Modifier == OMPC_REDUCTION_inscan &&
"Expected inscan reduction.");
773 assert(CopyArrayElems.size() == varlist_size() &&
774 "Number of copy temp expressions is not the same as the preallocated "
776 llvm::copy(CopyArrayElems, getInscanCopyArrayTemps().end());
788 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(
789 (Modifier == OMPC_REDUCTION_inscan ? 8 : 5) * VL.size()));
790 auto *Clause =
new (Mem)
792 Modifier, VL.size(), QualifierLoc, NameInfo);
794 Clause->setPrivates(Privates);
795 Clause->setLHSExprs(LHSExprs);
796 Clause->setRHSExprs(RHSExprs);
797 Clause->setReductionOps(ReductionOps);
798 Clause->setPreInitStmt(PreInit);
799 Clause->setPostUpdateExpr(PostUpdate);
800 if (Modifier == OMPC_REDUCTION_inscan) {
801 Clause->setInscanCopyOps(CopyOps);
802 Clause->setInscanCopyArrayTemps(CopyArrayTemps);
803 Clause->setInscanCopyArrayElems(CopyArrayElems);
805 assert(CopyOps.empty() &&
806 "copy operations are expected in inscan reductions only.");
807 assert(CopyArrayTemps.empty() &&
808 "copy array temps are expected in inscan reductions only.");
809 assert(CopyArrayElems.empty() &&
810 "copy array temps are expected in inscan reductions only.");
818 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(
819 (Modifier == OMPC_REDUCTION_inscan ? 8 : 5) * N));
821 Clause->setModifier(Modifier);
826 assert(Privates.size() == varlist_size() &&
827 "Number of private copies is not the same as the preallocated buffer");
828 std::copy(Privates.begin(), Privates.end(), varlist_end());
833 LHSExprs.size() == varlist_size() &&
834 "Number of LHS expressions is not the same as the preallocated buffer");
835 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
840 RHSExprs.size() == varlist_size() &&
841 "Number of RHS expressions is not the same as the preallocated buffer");
842 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
845 void OMPTaskReductionClause::setReductionOps(
ArrayRef<Expr *> ReductionOps) {
846 assert(ReductionOps.size() == varlist_size() &&
"Number of task reduction "
847 "expressions is not the same "
848 "as the preallocated buffer");
849 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
859 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
861 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
863 Clause->setPrivates(Privates);
864 Clause->setLHSExprs(LHSExprs);
865 Clause->setRHSExprs(RHSExprs);
866 Clause->setReductionOps(ReductionOps);
874 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
879 assert(Privates.size() == varlist_size() &&
880 "Number of private copies is not the same as the preallocated buffer");
881 std::copy(Privates.begin(), Privates.end(), varlist_end());
886 LHSExprs.size() == varlist_size() &&
887 "Number of LHS expressions is not the same as the preallocated buffer");
888 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
893 RHSExprs.size() == varlist_size() &&
894 "Number of RHS expressions is not the same as the preallocated buffer");
895 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
899 assert(ReductionOps.size() == varlist_size() &&
"Number of in reduction "
900 "expressions is not the same "
901 "as the preallocated buffer");
902 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
905 void OMPInReductionClause::setTaskgroupDescriptors(
907 assert(TaskgroupDescriptors.size() == varlist_size() &&
908 "Number of in reduction descriptors is not the same as the "
909 "preallocated buffer");
910 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
911 getReductionOps().end());
921 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
923 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
925 Clause->setPrivates(Privates);
926 Clause->setLHSExprs(LHSExprs);
927 Clause->setRHSExprs(RHSExprs);
928 Clause->setReductionOps(ReductionOps);
929 Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
937 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
956 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumSizes));
980 Clause->setLParenLoc(LParenLoc);
982 Clause->setFactor(Factor);
996 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
998 ColonLoc, EndLoc, VL.size());
1005 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
1014 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
1016 new (Mem)
OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
1022 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
1031 auto *Clause =
new (C)
OMPDepobjClause(StartLoc, LParenLoc, RParenLoc);
1032 Clause->setDepobj(Depobj);
1045 void *Mem = C.Allocate(
1046 totalSizeToAlloc<Expr *>(VL.size() + 1 + NumLoops),
1050 Clause->setDependencyKind(Data.
DepKind);
1051 Clause->setDependencyLoc(Data.
DepLoc);
1052 Clause->setColonLoc(Data.
ColonLoc);
1054 Clause->setModifier(DepModifier);
1056 for (
unsigned I = 0 ; I < NumLoops; ++I)
1062 unsigned NumLoops) {
1064 C.Allocate(totalSizeToAlloc<Expr *>(N + 1 + NumLoops),
1070 assert((getDependencyKind() == OMPC_DEPEND_sink ||
1071 getDependencyKind() == OMPC_DEPEND_source) &&
1072 NumLoop < NumLoops &&
1073 "Expected sink or source depend + loop index must be less number of "
1075 auto *It = std::next(getVarRefs().end(), NumLoop + 1);
1080 assert((getDependencyKind() == OMPC_DEPEND_sink ||
1081 getDependencyKind() == OMPC_DEPEND_source) &&
1082 NumLoop < NumLoops &&
1083 "Expected sink or source depend + loop index must be less number of "
1085 auto *It = std::next(getVarRefs().end(), NumLoop + 1);
1090 assert((getDependencyKind() == OMPC_DEPEND_sink ||
1091 getDependencyKind() == OMPC_DEPEND_source) &&
1092 NumLoop < NumLoops &&
1093 "Expected sink or source depend + loop index must be less number of "
1095 const auto *It = std::next(getVarRefs().end(), NumLoop + 1);
1099 void OMPDependClause::setModifier(
Expr *DepModifier) {
1100 *getVarRefs().end() = DepModifier;
1106 unsigned TotalNum = 0u;
1107 for (
auto &C : ComponentLists)
1108 TotalNum += C.size();
1114 unsigned TotalNum = 0u;
1116 for (
const ValueDecl *D : Declarations) {
1117 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) :
nullptr;
1118 if (
Cache.count(VD))
1138 Sizes.
NumComponents = getComponentsTotalNumber(ComponentLists);
1150 void *Mem = C.Allocate(
1157 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
1163 Clause->setMapType(
Type);
1171 void *Mem = C.Allocate(
1191 Sizes.
NumComponents = getComponentsTotalNumber(ComponentLists);
1203 void *Mem = C.Allocate(
1210 auto *Clause =
new (Mem)
OMPToClause(MotionModifiers, MotionModifiersLoc,
1211 UDMQualifierLoc, MapperId, Locs, Sizes);
1214 Clause->setUDMapperRefs(UDMapperRefs);
1215 Clause->setClauseInfo(Declarations, ComponentLists);
1221 void *Mem = C.Allocate(
1241 Sizes.
NumComponents = getComponentsTotalNumber(ComponentLists);
1253 void *Mem = C.Allocate(
1261 new (Mem)
OMPFromClause(MotionModifiers, MotionModifiersLoc,
1262 UDMQualifierLoc, MapperId, Locs, Sizes);
1265 Clause->setUDMapperRefs(UDMapperRefs);
1266 Clause->setClauseInfo(Declarations, ComponentLists);
1273 void *Mem = C.Allocate(
1283 assert(VL.size() == varlist_size() &&
1284 "Number of private copies is not the same as the preallocated buffer");
1285 std::copy(VL.begin(), VL.end(), varlist_end());
1289 assert(VL.size() == varlist_size() &&
1290 "Number of inits is not the same as the preallocated buffer");
1291 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1303 Sizes.
NumComponents = getComponentsTotalNumber(ComponentLists);
1315 void *Mem = C.Allocate(
1325 Clause->setPrivateCopies(PrivateVars);
1326 Clause->setInits(Inits);
1334 void *Mem = C.Allocate(
1352 Sizes.
NumComponents = getComponentsTotalNumber(ComponentLists);
1364 void *Mem = C.Allocate(
1374 Clause->setClauseInfo(Declarations, ComponentLists);
1381 void *Mem = C.Allocate(
1399 Sizes.
NumComponents = getComponentsTotalNumber(ComponentLists);
1411 void *Mem = C.Allocate(
1428 void *Mem = C.Allocate(
1446 Sizes.
NumComponents = getComponentsTotalNumber(ComponentLists);
1458 void *Mem = C.Allocate(
1468 Clause->setClauseInfo(Declarations, ComponentLists);
1475 void *Mem = C.Allocate(
1490 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
1499 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
1504 assert(VL.size() == varlist_size() &&
"Number of private references is not "
1505 "the same as the preallocated buffer");
1506 std::copy(VL.begin(), VL.end(), varlist_end());
1514 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
1523 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
1532 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
1541 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
1545 void OMPUsesAllocatorsClause::setAllocatorsData(
1547 assert(Data.size() == NumOfAllocators &&
1548 "Size of allocators data is not the same as the preallocated buffer.");
1549 for (
unsigned I = 0, E = Data.size(); I < E; ++I) {
1551 getTrailingObjects<Expr *>()[I *
static_cast<int>(ExprOffsets::Total) +
1552 static_cast<int>(ExprOffsets::Allocator)] =
1554 getTrailingObjects<Expr *>()[I *
static_cast<int>(ExprOffsets::Total) +
1556 ExprOffsets::AllocatorTraits)] =
1559 SourceLocation>()[I *
static_cast<int>(ParenLocsOffsets::Total) +
1560 static_cast<int>(ParenLocsOffsets::LParen)] =
1563 SourceLocation>()[I *
static_cast<int>(ParenLocsOffsets::Total) +
1564 static_cast<int>(ParenLocsOffsets::RParen)] =
1573 getTrailingObjects<Expr *>()[I *
static_cast<int>(ExprOffsets::Total) +
1574 static_cast<int>(ExprOffsets::Allocator)];
1576 getTrailingObjects<Expr *>()[I *
static_cast<int>(ExprOffsets::Total) +
1578 ExprOffsets::AllocatorTraits)];
1580 SourceLocation>()[I *
static_cast<int>(ParenLocsOffsets::Total) +
1581 static_cast<int>(ParenLocsOffsets::LParen)];
1583 SourceLocation>()[I *
static_cast<int>(ParenLocsOffsets::Total) +
1584 static_cast<int>(ParenLocsOffsets::RParen)];
1592 void *Mem = C.Allocate(totalSizeToAlloc<Expr *, SourceLocation>(
1593 static_cast<int>(ExprOffsets::Total) *
Data.size(),
1594 static_cast<int>(ParenLocsOffsets::Total) *
Data.size()));
1595 auto *Clause =
new (Mem)
1597 Clause->setAllocatorsData(
Data);
1603 void *Mem = C.Allocate(totalSizeToAlloc<Expr *, SourceLocation>(
1604 static_cast<int>(ExprOffsets::Total) * N,
1605 static_cast<int>(ParenLocsOffsets::Total) * N));
1614 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(Locators.size() + 1));
1615 auto *Clause =
new (Mem)
1617 Clause->setModifier(Modifier);
1618 Clause->setVarRefs(Locators);
1624 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + 1));
1635 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(PrefExprs.size() + 1));
1637 new (Mem)
OMPInitClause(IsTarget, IsTargetSync, StartLoc, LParenLoc,
1638 VarLoc, EndLoc, PrefExprs.size() + 1);
1639 Clause->setInteropVar(InteropVar);
1640 llvm::copy(PrefExprs, Clause->getTrailingObjects<
Expr *>() + 1);
1645 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
1653 return new (C)
OMPBindClause(K, KLoc, StartLoc, LParenLoc, EndLoc);
1665 if (
Node->getNameModifier() != OMPD_unknown)
1666 OS << getOpenMPDirectiveName(
Node->getNameModifier()) <<
": ";
1667 Node->getCondition()->printPretty(OS,
nullptr, Policy, 0);
1673 Node->getCondition()->printPretty(OS,
nullptr, Policy, 0);
1678 OS <<
"num_threads(";
1679 Node->getNumThreads()->printPretty(OS,
nullptr, Policy, 0);
1685 Node->getAlignment()->printPretty(OS,
nullptr, Policy, 0);
1691 Node->getSafelen()->printPretty(OS,
nullptr, Policy, 0);
1697 Node->getSimdlen()->printPretty(OS,
nullptr, Policy, 0);
1704 for (
auto Size :
Node->getSizesRefs()) {
1707 Size->printPretty(OS,
nullptr, Policy, 0);
1718 if (
Expr *Factor =
Node->getFactor()) {
1720 Factor->printPretty(OS,
nullptr, Policy, 0);
1727 Node->getAllocator()->printPretty(OS,
nullptr, Policy, 0);
1733 Node->getNumForLoops()->printPretty(OS,
nullptr, Policy, 0);
1739 Node->getEventHandler()->printPretty(OS,
nullptr, Policy, 0);
1746 unsigned(
Node->getDefaultKind()))
1753 unsigned(
Node->getProcBindKind()))
1758 OS <<
"unified_address";
1761 void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1763 OS <<
"unified_shared_memory";
1767 OS <<
"reverse_offload";
1770 void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1772 OS <<
"dynamic_allocators";
1775 void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1777 OS <<
"atomic_default_mem_order("
1779 Node->getAtomicDefaultMemOrderKind())
1787 Node->getFirstScheduleModifier());
1791 Node->getSecondScheduleModifier());
1796 if (
auto *E =
Node->getChunkSize()) {
1798 E->printPretty(OS,
nullptr, Policy);
1805 if (
auto *Num =
Node->getNumForLoops()) {
1807 Num->printPretty(OS,
nullptr, Policy, 0);
1828 void OMPClausePrinter::VisitOMPReadClause(
OMPReadClause *) {
OS <<
"read"; }
1830 void OMPClausePrinter::VisitOMPWriteClause(
OMPWriteClause *) {
OS <<
"write"; }
1834 if (
Node->isExtended()) {
1837 Node->getDependencyKind());
1874 void OMPClausePrinter::VisitOMPSIMDClause(
OMPSIMDClause *) {
OS <<
"simd"; }
1883 Node->getDevice()->printPretty(OS,
nullptr, Policy, 0);
1889 Node->getNumTeams()->printPretty(OS,
nullptr, Policy, 0);
1894 OS <<
"thread_limit(";
1895 Node->getThreadLimit()->printPretty(OS,
nullptr, Policy, 0);
1901 Node->getPriority()->printPretty(OS,
nullptr, Policy, 0);
1907 Node->getGrainsize()->printPretty(OS,
nullptr, Policy, 0);
1913 Node->getNumTasks()->printPretty(OS,
nullptr, Policy, 0);
1919 Node->getHint()->printPretty(OS,
nullptr, Policy, 0);
1926 for (
const Expr *E :
Node->prefs()) {
1928 OS <<
"prefer_type(";
1931 E->printPretty(OS,
nullptr, Policy);
1936 if (
Node->getIsTarget())
1938 if (
Node->getIsTargetSync()) {
1939 if (
Node->getIsTarget())
1944 Node->getInteropVar()->printPretty(OS,
nullptr, Policy);
1950 Node->getInteropVar()->printPretty(OS,
nullptr, Policy);
1956 if (
Expr *E =
Node->getInteropVar()) {
1958 E->printPretty(OS,
nullptr, Policy);
1965 if (
Expr *E =
Node->getCondition()) {
1967 E->printPretty(OS,
nullptr, Policy, 0);
1974 if (
Expr *E =
Node->getCondition()) {
1976 E->printPretty(OS,
nullptr, Policy, 0);
1981 template<
typename T>
1982 void OMPClausePrinter::VisitOMPClauseList(T *
Node,
char StartSym) {
1983 for (
typename T::varlist_iterator I =
Node->varlist_begin(),
1984 E =
Node->varlist_end();
1986 assert(*I &&
"Expected non-null Stmt");
1987 OS << (I ==
Node->varlist_begin() ? StartSym :
',');
1988 if (
auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1989 if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1990 DRE->printPretty(OS,
nullptr, Policy, 0);
1992 DRE->getDecl()->printQualifiedName(OS);
1994 (*I)->printPretty(OS,
nullptr, Policy, 0);
1999 if (
Node->varlist_empty())
2002 if (
Expr *Allocator =
Node->getAllocator()) {
2004 Allocator->printPretty(OS,
nullptr, Policy, 0);
2006 VisitOMPClauseList(
Node,
' ');
2008 VisitOMPClauseList(
Node,
'(');
2014 if (!
Node->varlist_empty()) {
2016 VisitOMPClauseList(
Node,
'(');
2022 if (!
Node->varlist_empty()) {
2023 OS <<
"firstprivate";
2024 VisitOMPClauseList(
Node,
'(');
2030 if (!
Node->varlist_empty()) {
2031 OS <<
"lastprivate";
2044 if (!
Node->varlist_empty()) {
2046 VisitOMPClauseList(
Node,
'(');
2052 if (!
Node->varlist_empty()) {
2054 if (
Node->getModifierLoc().isValid())
2058 Node->getQualifierLoc().getNestedNameSpecifier();
2060 Node->getNameInfo().getName().getCXXOverloadedOperator();
2061 if (QualifierLoc ==
nullptr && OOK !=
OO_None) {
2066 if (QualifierLoc !=
nullptr)
2067 QualifierLoc->
print(OS, Policy);
2068 OS <<
Node->getNameInfo();
2071 VisitOMPClauseList(
Node,
' ');
2076 void OMPClausePrinter::VisitOMPTaskReductionClause(
2078 if (!
Node->varlist_empty()) {
2079 OS <<
"task_reduction(";
2081 Node->getQualifierLoc().getNestedNameSpecifier();
2083 Node->getNameInfo().getName().getCXXOverloadedOperator();
2084 if (QualifierLoc ==
nullptr && OOK !=
OO_None) {
2089 if (QualifierLoc !=
nullptr)
2090 QualifierLoc->
print(OS, Policy);
2091 OS <<
Node->getNameInfo();
2094 VisitOMPClauseList(
Node,
' ');
2100 if (!
Node->varlist_empty()) {
2101 OS <<
"in_reduction(";
2103 Node->getQualifierLoc().getNestedNameSpecifier();
2105 Node->getNameInfo().getName().getCXXOverloadedOperator();
2106 if (QualifierLoc ==
nullptr && OOK !=
OO_None) {
2111 if (QualifierLoc !=
nullptr)
2112 QualifierLoc->
print(OS, Policy);
2113 OS <<
Node->getNameInfo();
2116 VisitOMPClauseList(
Node,
' ');
2122 if (!
Node->varlist_empty()) {
2124 if (
Node->getModifierLoc().isValid()) {
2128 VisitOMPClauseList(
Node,
'(');
2129 if (
Node->getModifierLoc().isValid())
2131 if (
Node->getStep() !=
nullptr) {
2133 Node->getStep()->printPretty(OS,
nullptr, Policy, 0);
2140 if (!
Node->varlist_empty()) {
2142 VisitOMPClauseList(
Node,
'(');
2143 if (
Node->getAlignment() !=
nullptr) {
2145 Node->getAlignment()->printPretty(OS,
nullptr, Policy, 0);
2152 if (!
Node->varlist_empty()) {
2154 VisitOMPClauseList(
Node,
'(');
2160 if (!
Node->varlist_empty()) {
2161 OS <<
"copyprivate";
2162 VisitOMPClauseList(
Node,
'(');
2168 if (!
Node->varlist_empty()) {
2169 VisitOMPClauseList(
Node,
'(');
2176 Node->getDepobj()->printPretty(OS,
nullptr, Policy, 0);
2182 if (
Expr *DepModifier =
Node->getModifier()) {
2188 bool IsOmpAllMemory =
false;
2189 if (PrintKind == OMPC_DEPEND_outallmemory) {
2190 PrintKind = OMPC_DEPEND_out;
2191 IsOmpAllMemory =
true;
2192 }
else if (PrintKind == OMPC_DEPEND_inoutallmemory) {
2193 PrintKind = OMPC_DEPEND_inout;
2194 IsOmpAllMemory =
true;
2197 if (!
Node->varlist_empty() || IsOmpAllMemory)
2199 VisitOMPClauseList(
Node,
' ');
2200 if (IsOmpAllMemory) {
2201 OS << (
Node->varlist_empty() ?
" " :
",");
2202 OS <<
"omp_all_memory";
2207 template <
typename T>
2212 Node->getMapperQualifierLoc().getNestedNameSpecifier();
2214 MapperNNS->
print(OS, Policy);
2215 OS <<
Node->getMapperIdInfo() <<
')';
2219 if (!
Node->varlist_empty()) {
2225 Node->getMapTypeModifier(I));
2226 if (
Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper)
2234 VisitOMPClauseList(
Node,
' ');
2239 template <
typename T>
void OMPClausePrinter::VisitOMPMotionClause(T *
Node) {
2240 if (
Node->varlist_empty())
2242 OS << getOpenMPClauseName(
Node->getClauseKind());
2243 unsigned ModifierCount = 0;
2248 if (ModifierCount) {
2253 Node->getMotionModifier(I));
2254 if (
Node->getMotionModifier(I) == OMPC_MOTION_MODIFIER_mapper)
2256 if (I < ModifierCount - 1)
2261 VisitOMPClauseList(
Node,
' ');
2263 VisitOMPClauseList(
Node,
'(');
2269 VisitOMPMotionClause(
Node);
2273 VisitOMPMotionClause(
Node);
2278 OMPC_dist_schedule,
Node->getDistScheduleKind());
2279 if (
auto *E =
Node->getChunkSize()) {
2281 E->printPretty(OS,
nullptr, Policy);
2287 OS <<
"defaultmap(";
2289 Node->getDefaultmapModifier());
2293 Node->getDefaultmapKind());
2299 if (!
Node->varlist_empty()) {
2300 OS <<
"use_device_ptr";
2301 VisitOMPClauseList(
Node,
'(');
2306 void OMPClausePrinter::VisitOMPUseDeviceAddrClause(
2308 if (!
Node->varlist_empty()) {
2309 OS <<
"use_device_addr";
2310 VisitOMPClauseList(
Node,
'(');
2316 if (!
Node->varlist_empty()) {
2317 OS <<
"is_device_ptr";
2318 VisitOMPClauseList(
Node,
'(');
2324 if (!
Node->varlist_empty()) {
2325 OS <<
"has_device_addr";
2326 VisitOMPClauseList(
Node,
'(');
2332 if (!
Node->varlist_empty()) {
2333 OS <<
"nontemporal";
2334 VisitOMPClauseList(
Node,
'(');
2345 if (!
Node->varlist_empty()) {
2347 VisitOMPClauseList(
Node,
'(');
2353 if (!
Node->varlist_empty()) {
2355 VisitOMPClauseList(
Node,
'(');
2360 void OMPClausePrinter::VisitOMPUsesAllocatorsClause(
2362 if (
Node->getNumberOfAllocators() == 0)
2364 OS <<
"uses_allocators(";
2365 for (
unsigned I = 0, E =
Node->getNumberOfAllocators(); I < E; ++I) {
2380 if (
Node->varlist_empty())
2383 char StartSym =
'(';
2384 if (
Expr *Modifier =
Node->getModifier()) {
2386 Modifier->printPretty(OS,
nullptr, Policy);
2390 VisitOMPClauseList(
Node, StartSym);
2396 Node->getThreadID()->printPretty(OS,
nullptr, Policy, 0);
2407 VariantMatchInfo &VMI)
const {
2412 if (
Selector.Kind == TraitSelector::user_condition) {
2413 assert(
Selector.ScoreOrCondition &&
2414 "Ill-formed user condition, expected condition expression!");
2415 assert(
Selector.Properties.size() == 1 &&
2416 Selector.Properties.front().Kind ==
2417 TraitProperty::user_condition_unknown &&
2418 "Ill-formed user condition, expected unknown trait property!");
2421 Selector.ScoreOrCondition->getIntegerConstantExpr(ASTCtx))
2422 VMI.addTrait(CondVal->isZero() ? TraitProperty::user_condition_false
2423 : TraitProperty::user_condition_true,
2426 VMI.addTrait(TraitProperty::user_condition_false,
"<condition>");
2433 if ((Score =
Selector.ScoreOrCondition->getIntegerConstantExpr(ASTCtx)))
2436 VMI.addTrait(TraitProperty::user_condition_false,
2437 "<non-constant-score>");
2443 if (Set.Kind != TraitSet::construct)
2447 assert(
Selector.Properties.size() == 1 &&
2448 Selector.Properties.front().Kind ==
2449 getOpenMPContextTraitPropertyForSelector(
2451 "Ill-formed construct selector!");
2458 bool FirstSet =
true;
2463 OS << getOpenMPContextTraitSetName(Set.Kind) <<
"={";
2465 bool FirstSelector =
true;
2469 FirstSelector =
false;
2470 OS << getOpenMPContextTraitSelectorName(
Selector.Kind);
2472 bool AllowsTraitScore =
false;
2473 bool RequiresProperty =
false;
2474 isValidTraitSelectorForTraitSet(
2475 Selector.Kind, Set.Kind, AllowsTraitScore, RequiresProperty);
2477 if (!RequiresProperty)
2481 if (
Selector.Kind == TraitSelector::user_condition) {
2483 Selector.ScoreOrCondition->printPretty(OS,
nullptr, Policy);
2490 Selector.ScoreOrCondition->printPretty(OS,
nullptr, Policy);
2494 bool FirstProperty =
true;
2498 FirstProperty =
false;
2499 OS << getOpenMPContextTraitPropertyName(
Property.Kind,
2511 llvm::raw_string_ostream OS(MangledName);
2513 OS <<
'$' <<
'S' <<
unsigned(Set.Kind);
2516 bool AllowsTraitScore =
false;
2517 bool RequiresProperty =
false;
2518 isValidTraitSelectorForTraitSet(
2519 Selector.Kind, Set.Kind, AllowsTraitScore, RequiresProperty);
2522 if (!RequiresProperty ||
2523 Selector.Kind == TraitSelector::user_condition)
2528 << getOpenMPContextTraitPropertyName(
Property.Kind,
2535 OMPTraitInfo::OMPTraitInfo(StringRef MangledName) {
2538 if (!MangledName.consume_front(
"$S"))
2540 if (MangledName.consumeInteger(10,
U))
2544 Set.
Kind = TraitSet(
U);
2546 if (!MangledName.consume_front(
"$s"))
2548 if (MangledName.consumeInteger(10,
U))
2554 if (!MangledName.consume_front(
"$P"))
2558 std::pair<StringRef, StringRef> PropRestPair = MangledName.split(
'$');
2559 Property.RawString = PropRestPair.first;
2560 Property.Kind = getOpenMPContextTraitPropertyKind(
2562 MangledName = MangledName.drop_front(PropRestPair.first.size());
2572 TI.
print(OS, Policy);
2577 return TI ? OS << *TI : OS;
2581 ASTContext &ASTCtx, std::function<
void(StringRef)> &&DiagUnknownTrait,
2584 :
OMPContext(ASTCtx.getLangOpts().OpenMPIsDevice,
2585 ASTCtx.getTargetInfo().getTriple()),
2586 FeatureValidityCheck([&](StringRef FeatureName) {
2589 DiagUnknownTrait(std::move(DiagUnknownTrait)) {
2592 for (llvm::omp::TraitProperty Property : ConstructTraits)
2597 auto It = FeatureMap.find(RawString);
2598 if (It != FeatureMap.end())
2600 if (!FeatureValidityCheck(RawString))
2601 DiagUnknownTrait(RawString);