@@ -719,27 +719,52 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitNumGangsClause(
719
719
<< /* NoArgs=*/ 1 << Clause.getDirectiveKind () << MaxArgs
720
720
<< Clause.getIntExprs ().size ();
721
721
722
+ // OpenACC 3.3 Section 2.9.11: A reduction clause may not appear on a loop
723
+ // directive that has a gang clause and is within a compute construct that has
724
+ // a num_gangs clause with more than one explicit argument.
725
+ if (Clause.getIntExprs ().size () > 1 &&
726
+ isOpenACCCombinedDirectiveKind (Clause.getDirectiveKind ())) {
727
+ auto *GangClauseItr =
728
+ llvm::find_if (ExistingClauses, llvm::IsaPred<OpenACCGangClause>);
729
+ auto *ReductionClauseItr =
730
+ llvm::find_if (ExistingClauses, llvm::IsaPred<OpenACCReductionClause>);
731
+
732
+ if (GangClauseItr != ExistingClauses.end () &&
733
+ ReductionClauseItr != ExistingClauses.end ()) {
734
+ SemaRef.Diag (Clause.getBeginLoc (),
735
+ diag::err_acc_gang_reduction_numgangs_conflict)
736
+ << OpenACCClauseKind::Reduction << OpenACCClauseKind::Gang
737
+ << Clause.getDirectiveKind () << /* is on combined directive=*/ 1 ;
738
+ SemaRef.Diag ((*ReductionClauseItr)->getBeginLoc (),
739
+ diag::note_acc_previous_clause_here);
740
+ SemaRef.Diag ((*GangClauseItr)->getBeginLoc (),
741
+ diag::note_acc_previous_clause_here);
742
+ return nullptr ;
743
+ }
744
+ }
745
+
722
746
// OpenACC 3.3 Section 2.5.4:
723
747
// A reduction clause may not appear on a parallel construct with a
724
748
// num_gangs clause that has more than one argument.
725
- // TODO: OpenACC: Reduction on Combined Construct needs to do this too.
726
- if ( Clause.getDirectiveKind () == OpenACCDirectiveKind::Parallel &&
749
+ if ((Clause. getDirectiveKind () == OpenACCDirectiveKind::Parallel ||
750
+ Clause.getDirectiveKind () == OpenACCDirectiveKind::ParallelLoop) &&
727
751
Clause.getIntExprs ().size () > 1 ) {
728
752
auto *Parallel =
729
753
llvm::find_if (ExistingClauses, llvm::IsaPred<OpenACCReductionClause>);
730
754
731
755
if (Parallel != ExistingClauses.end ()) {
732
756
SemaRef.Diag (Clause.getBeginLoc (),
733
757
diag::err_acc_reduction_num_gangs_conflict)
734
- << Clause.getIntExprs ().size ();
758
+ << /* >1 arg in first loc=*/ 1 << Clause.getClauseKind ()
759
+ << Clause.getDirectiveKind () << OpenACCClauseKind::Reduction;
735
760
SemaRef.Diag ((*Parallel)->getBeginLoc (),
736
761
diag::note_acc_previous_clause_here);
737
762
return nullptr ;
738
763
}
739
764
}
740
765
741
766
// OpenACC 3.3 Section 2.9.2:
742
- // An argument with no keyword or with the 'num' wkeyword is allowed only when
767
+ // An argument with no keyword or with the 'num' keyword is allowed only when
743
768
// the 'num_gangs' does not appear on the 'kernel' construct.
744
769
if (Clause.getDirectiveKind () == OpenACCDirectiveKind::KernelsLoop) {
745
770
auto GangClauses = llvm::make_filter_range (
@@ -1457,32 +1482,36 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitGangClause(
1457
1482
// OpenACC 3.3 Section 2.9.11: A reduction clause may not appear on a loop
1458
1483
// directive that has a gang clause and is within a compute construct that has
1459
1484
// a num_gangs clause with more than one explicit argument.
1460
- // TODO OpenACC: When we implement reduction on combined constructs, we need
1461
- // to do this too.
1462
- if (Clause.getDirectiveKind () == OpenACCDirectiveKind::Loop &&
1463
- SemaRef.getActiveComputeConstructInfo ().Kind !=
1464
- OpenACCDirectiveKind::Invalid) {
1485
+ if ((Clause.getDirectiveKind () == OpenACCDirectiveKind::Loop &&
1486
+ SemaRef.getActiveComputeConstructInfo ().Kind !=
1487
+ OpenACCDirectiveKind::Invalid) ||
1488
+ isOpenACCCombinedDirectiveKind (Clause.getDirectiveKind ())) {
1465
1489
// num_gangs clause on the active compute construct.
1466
- auto *NumGangsClauseItr =
1467
- llvm::find_if (SemaRef.getActiveComputeConstructInfo ().Clauses ,
1468
- llvm::IsaPred<OpenACCNumGangsClause>);
1469
-
1470
- auto *ReductionClauseItr =
1471
- llvm::find_if (ExistingClauses, llvm::IsaPred<OpenACCReductionClause>);
1472
-
1473
- if (ReductionClauseItr != ExistingClauses.end () &&
1474
- NumGangsClauseItr !=
1475
- SemaRef.getActiveComputeConstructInfo ().Clauses .end () &&
1490
+ auto ActiveComputeConstructContainer =
1491
+ isOpenACCCombinedDirectiveKind (Clause.getDirectiveKind ())
1492
+ ? ExistingClauses
1493
+ : SemaRef.getActiveComputeConstructInfo ().Clauses ;
1494
+ auto *NumGangsClauseItr = llvm::find_if (
1495
+ ActiveComputeConstructContainer, llvm::IsaPred<OpenACCNumGangsClause>);
1496
+
1497
+ if (NumGangsClauseItr != ActiveComputeConstructContainer.end () &&
1476
1498
cast<OpenACCNumGangsClause>(*NumGangsClauseItr)->getIntExprs ().size () >
1477
1499
1 ) {
1478
- SemaRef.Diag (Clause.getBeginLoc (),
1479
- diag::err_acc_gang_reduction_numgangs_conflict)
1480
- << OpenACCClauseKind::Gang << OpenACCClauseKind::Reduction;
1481
- SemaRef.Diag ((*ReductionClauseItr)->getBeginLoc (),
1482
- diag::note_acc_previous_clause_here);
1483
- SemaRef.Diag ((*NumGangsClauseItr)->getBeginLoc (),
1484
- diag::note_acc_previous_clause_here);
1485
- return nullptr ;
1500
+ auto *ReductionClauseItr =
1501
+ llvm::find_if (ExistingClauses, llvm::IsaPred<OpenACCReductionClause>);
1502
+
1503
+ if (ReductionClauseItr != ExistingClauses.end ()) {
1504
+ SemaRef.Diag (Clause.getBeginLoc (),
1505
+ diag::err_acc_gang_reduction_numgangs_conflict)
1506
+ << OpenACCClauseKind::Gang << OpenACCClauseKind::Reduction
1507
+ << Clause.getDirectiveKind ()
1508
+ << isOpenACCCombinedDirectiveKind (Clause.getDirectiveKind ());
1509
+ SemaRef.Diag ((*ReductionClauseItr)->getBeginLoc (),
1510
+ diag::note_acc_previous_clause_here);
1511
+ SemaRef.Diag ((*NumGangsClauseItr)->getBeginLoc (),
1512
+ diag::note_acc_previous_clause_here);
1513
+ return nullptr ;
1514
+ }
1486
1515
}
1487
1516
}
1488
1517
@@ -1563,9 +1592,9 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitGangClause(
1563
1592
}
1564
1593
}
1565
1594
1566
- return SemaRef.CheckGangClause (ExistingClauses, Clause.getBeginLoc () ,
1567
- Clause.getLParenLoc (), GangKinds, IntExprs ,
1568
- Clause.getEndLoc ());
1595
+ return SemaRef.CheckGangClause (Clause.getDirectiveKind (), ExistingClauses ,
1596
+ Clause.getBeginLoc (), Clause. getLParenLoc () ,
1597
+ GangKinds, IntExprs, Clause.getEndLoc ());
1569
1598
}
1570
1599
1571
1600
OpenACCClause *SemaOpenACCClauseVisitor::VisitSeqClause (
@@ -1609,41 +1638,39 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitSeqClause(
1609
1638
1610
1639
OpenACCClause *SemaOpenACCClauseVisitor::VisitReductionClause (
1611
1640
SemaOpenACC::OpenACCParsedClause &Clause) {
1612
- // Restrictions only properly implemented on 'compute' constructs, and
1613
- // 'compute' constructs are the only construct that can do anything with
1614
- // this yet, so skip/treat as unimplemented in this case.
1615
- // TODO: OpenACC: Remove check once we get combined constructs for this clause.
1616
- if (!isOpenACCComputeDirectiveKind (Clause.getDirectiveKind ()) &&
1617
- Clause.getDirectiveKind () != OpenACCDirectiveKind::Loop)
1618
- return isNotImplemented ();
1619
-
1620
1641
// OpenACC 3.3 Section 2.9.11: A reduction clause may not appear on a loop
1621
1642
// directive that has a gang clause and is within a compute construct that has
1622
1643
// a num_gangs clause with more than one explicit argument.
1623
- if (Clause.getDirectiveKind () == OpenACCDirectiveKind::Loop &&
1624
- SemaRef.getActiveComputeConstructInfo ().Kind !=
1625
- OpenACCDirectiveKind::Invalid) {
1644
+ if ((Clause.getDirectiveKind () == OpenACCDirectiveKind::Loop &&
1645
+ SemaRef.getActiveComputeConstructInfo ().Kind !=
1646
+ OpenACCDirectiveKind::Invalid) ||
1647
+ isOpenACCCombinedDirectiveKind (Clause.getDirectiveKind ())) {
1626
1648
// num_gangs clause on the active compute construct.
1627
- auto *NumGangsClauseItr =
1628
- llvm::find_if (SemaRef.getActiveComputeConstructInfo ().Clauses ,
1629
- llvm::IsaPred<OpenACCNumGangsClause>);
1630
-
1631
- auto *GangClauseItr =
1632
- llvm::find_if (ExistingClauses, llvm::IsaPred<OpenACCGangClause>);
1633
-
1634
- if (GangClauseItr != ExistingClauses.end () &&
1635
- NumGangsClauseItr !=
1636
- SemaRef.getActiveComputeConstructInfo ().Clauses .end () &&
1649
+ auto ActiveComputeConstructContainer =
1650
+ isOpenACCCombinedDirectiveKind (Clause.getDirectiveKind ())
1651
+ ? ExistingClauses
1652
+ : SemaRef.getActiveComputeConstructInfo ().Clauses ;
1653
+ auto *NumGangsClauseItr = llvm::find_if (
1654
+ ActiveComputeConstructContainer, llvm::IsaPred<OpenACCNumGangsClause>);
1655
+
1656
+ if (NumGangsClauseItr != ActiveComputeConstructContainer.end () &&
1637
1657
cast<OpenACCNumGangsClause>(*NumGangsClauseItr)->getIntExprs ().size () >
1638
1658
1 ) {
1639
- SemaRef.Diag (Clause.getBeginLoc (),
1640
- diag::err_acc_gang_reduction_numgangs_conflict)
1641
- << OpenACCClauseKind::Reduction << OpenACCClauseKind::Gang;
1642
- SemaRef.Diag ((*GangClauseItr)->getBeginLoc (),
1643
- diag::note_acc_previous_clause_here);
1644
- SemaRef.Diag ((*NumGangsClauseItr)->getBeginLoc (),
1645
- diag::note_acc_previous_clause_here);
1646
- return nullptr ;
1659
+ auto *GangClauseItr =
1660
+ llvm::find_if (ExistingClauses, llvm::IsaPred<OpenACCGangClause>);
1661
+
1662
+ if (GangClauseItr != ExistingClauses.end ()) {
1663
+ SemaRef.Diag (Clause.getBeginLoc (),
1664
+ diag::err_acc_gang_reduction_numgangs_conflict)
1665
+ << OpenACCClauseKind::Reduction << OpenACCClauseKind::Gang
1666
+ << Clause.getDirectiveKind ()
1667
+ << isOpenACCCombinedDirectiveKind (Clause.getDirectiveKind ());
1668
+ SemaRef.Diag ((*GangClauseItr)->getBeginLoc (),
1669
+ diag::note_acc_previous_clause_here);
1670
+ SemaRef.Diag ((*NumGangsClauseItr)->getBeginLoc (),
1671
+ diag::note_acc_previous_clause_here);
1672
+ return nullptr ;
1673
+ }
1647
1674
}
1648
1675
}
1649
1676
@@ -1667,7 +1694,8 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitReductionClause(
1667
1694
// OpenACC 3.3 Section 2.5.4:
1668
1695
// A reduction clause may not appear on a parallel construct with a
1669
1696
// num_gangs clause that has more than one argument.
1670
- if (Clause.getDirectiveKind () == OpenACCDirectiveKind::Parallel) {
1697
+ if (Clause.getDirectiveKind () == OpenACCDirectiveKind::Parallel ||
1698
+ Clause.getDirectiveKind () == OpenACCDirectiveKind::ParallelLoop) {
1671
1699
auto NumGangsClauses = llvm::make_filter_range (
1672
1700
ExistingClauses, llvm::IsaPred<OpenACCNumGangsClause>);
1673
1701
@@ -1678,7 +1706,8 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitReductionClause(
1678
1706
if (NumExprs > 1 ) {
1679
1707
SemaRef.Diag (Clause.getBeginLoc (),
1680
1708
diag::err_acc_reduction_num_gangs_conflict)
1681
- << NumExprs;
1709
+ << /* >1 arg in first loc=*/ 0 << Clause.getClauseKind ()
1710
+ << Clause.getDirectiveKind () << OpenACCClauseKind::NumGangs;
1682
1711
SemaRef.Diag (NGC->getBeginLoc (), diag::note_acc_previous_clause_here);
1683
1712
return nullptr ;
1684
1713
}
@@ -2624,7 +2653,8 @@ SemaOpenACC::CheckGangExpr(ArrayRef<const OpenACCClause *> ExistingClauses,
2624
2653
}
2625
2654
2626
2655
OpenACCClause *
2627
- SemaOpenACC::CheckGangClause (ArrayRef<const OpenACCClause *> ExistingClauses,
2656
+ SemaOpenACC::CheckGangClause (OpenACCDirectiveKind DirKind,
2657
+ ArrayRef<const OpenACCClause *> ExistingClauses,
2628
2658
SourceLocation BeginLoc, SourceLocation LParenLoc,
2629
2659
ArrayRef<OpenACCGangKind> GangKinds,
2630
2660
ArrayRef<Expr *> IntExprs, SourceLocation EndLoc) {
@@ -2649,7 +2679,7 @@ SemaOpenACC::CheckGangClause(ArrayRef<const OpenACCClause *> ExistingClauses,
2649
2679
if (const auto *DimVal = dyn_cast<ConstantExpr>(DimExpr);
2650
2680
DimVal && DimVal->getResultAsAPSInt () > 1 ) {
2651
2681
Diag (DimVal->getBeginLoc (), diag::err_acc_gang_reduction_conflict)
2652
- << /* gang/reduction=*/ 0 ;
2682
+ << /* gang/reduction=*/ 0 << DirKind ;
2653
2683
Diag ((*ReductionItr)->getBeginLoc (),
2654
2684
diag::note_acc_previous_clause_here);
2655
2685
return nullptr ;
@@ -2666,30 +2696,29 @@ OpenACCClause *SemaOpenACC::CheckReductionClause(
2666
2696
OpenACCDirectiveKind DirectiveKind, SourceLocation BeginLoc,
2667
2697
SourceLocation LParenLoc, OpenACCReductionOperator ReductionOp,
2668
2698
ArrayRef<Expr *> Vars, SourceLocation EndLoc) {
2669
- if (DirectiveKind == OpenACCDirectiveKind::Loop) {
2699
+ if (DirectiveKind == OpenACCDirectiveKind::Loop ||
2700
+ isOpenACCCombinedDirectiveKind (DirectiveKind)) {
2670
2701
// OpenACC 3.3 2.9.11: A reduction clause may not appear on a loop directive
2671
2702
// that has a gang clause with a dim: argument whose value is greater
2672
2703
// than 1.
2673
- const auto *GangItr =
2674
- llvm::find_if ( ExistingClauses, llvm::IsaPred<OpenACCGangClause>);
2704
+ const auto GangClauses = llvm::make_filter_range (
2705
+ ExistingClauses, llvm::IsaPred<OpenACCGangClause>);
2675
2706
2676
- while (GangItr != ExistingClauses. end () ) {
2677
- auto *GangClause = cast<OpenACCGangClause>(*GangItr );
2707
+ for ( auto *GC : GangClauses ) {
2708
+ const auto *GangClause = cast<OpenACCGangClause>(GC );
2678
2709
for (unsigned I = 0 ; I < GangClause->getNumExprs (); ++I) {
2679
2710
std::pair<OpenACCGangKind, const Expr *> EPair = GangClause->getExpr (I);
2680
- // We know there is only 1 on this gang, so move onto the next gang.
2681
2711
if (EPair.first != OpenACCGangKind::Dim)
2682
- break ;
2712
+ continue ;
2683
2713
2684
2714
if (const auto *DimVal = dyn_cast<ConstantExpr>(EPair.second );
2685
2715
DimVal && DimVal->getResultAsAPSInt () > 1 ) {
2686
2716
Diag (BeginLoc, diag::err_acc_gang_reduction_conflict)
2687
- << /* reduction/gang=*/ 1 ;
2688
- Diag ((*GangItr) ->getBeginLoc (), diag::note_acc_previous_clause_here);
2717
+ << /* reduction/gang=*/ 1 << DirectiveKind ;
2718
+ Diag (GangClause ->getBeginLoc (), diag::note_acc_previous_clause_here);
2689
2719
return nullptr ;
2690
2720
}
2691
2721
}
2692
- ++GangItr;
2693
2722
}
2694
2723
}
2695
2724
0 commit comments