[llvm-branch-commits] [flang] c823d74 - [flang][openacc] Add missing loop construct restriction and validity tests
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Dec 8 11:16:40 PST 2020
Author: Valentin Clement
Date: 2020-12-08T14:12:12-05:00
New Revision: c823d74914a287e056eb311ce293e7d4a521eb25
URL: https://github.com/llvm/llvm-project/commit/c823d74914a287e056eb311ce293e7d4a521eb25
DIFF: https://github.com/llvm/llvm-project/commit/c823d74914a287e056eb311ce293e7d4a521eb25.diff
LOG: [flang][openacc] Add missing loop construct restriction and validity tests
Add restriction on loop construct associated with DO CONCURRENT. Add couple of tests to ensure
clause validity checks.
Reviewed By: sameeranjoshi
Differential Revision: https://reviews.llvm.org/D92533
Added:
Modified:
flang/lib/Semantics/canonicalize-acc.cpp
flang/test/Semantics/acc-canonicalization-validity.f90
flang/test/Semantics/acc-clause-validity.f90
Removed:
################################################################################
diff --git a/flang/lib/Semantics/canonicalize-acc.cpp b/flang/lib/Semantics/canonicalize-acc.cpp
index 4916f2269ceb..0241508543ba 100644
--- a/flang/lib/Semantics/canonicalize-acc.cpp
+++ b/flang/lib/Semantics/canonicalize-acc.cpp
@@ -64,6 +64,8 @@ class CanonicalizationOfAcc {
std::size_t tileArgNb = listTileExpr.size();
const auto &outer{std::get<std::optional<parser::DoConstruct>>(x.t)};
+ if (outer->IsDoConcurrent())
+ return; // Tile is not allowed on DO CONURRENT
for (const parser::DoConstruct *loop{&*outer}; loop && tileArgNb > 0;
--tileArgNb) {
const auto &block{std::get<parser::Block>(loop->t)};
@@ -82,6 +84,27 @@ class CanonicalizationOfAcc {
}
}
+ // Check constraint on line 1835 in Section 2.9
+ // A tile and collapse clause may not appear on loop that is associated with
+ // do concurrent.
+ template <typename C, typename D>
+ void CheckDoConcurrentClauseRestriction(const C &x) {
+ const auto &doCons{std::get<std::optional<parser::DoConstruct>>(x.t)};
+ if (!doCons->IsDoConcurrent())
+ return;
+ const auto &beginLoopDirective = std::get<D>(x.t);
+ const auto &accClauseList =
+ std::get<parser::AccClauseList>(beginLoopDirective.t);
+ for (const auto &clause : accClauseList.v) {
+ if (std::holds_alternative<parser::AccClause::Collapse>(clause.u) ||
+ std::holds_alternative<parser::AccClause::Tile>(clause.u)) {
+ messages_.Say(beginLoopDirective.source,
+ "TILE and COLLAPSE clause may not appear on loop construct "
+ "associated with DO CONCURRENT"_err_en_US);
+ }
+ }
+ }
+
void RewriteOpenACCLoopConstruct(parser::OpenACCLoopConstruct &x,
parser::Block &block, parser::Block::iterator it) {
// Check the sequence of DoConstruct in the same iteration
@@ -112,8 +135,12 @@ class CanonicalizationOfAcc {
"DO loop after the %s directive must have loop control"_err_en_US,
parser::ToUpperCaseLetters(dir.source.ToString()));
}
+
+ CheckDoConcurrentClauseRestriction<parser::OpenACCLoopConstruct,
+ parser::AccBeginLoopDirective>(x);
CheckTileClauseRestriction<parser::OpenACCLoopConstruct,
parser::AccBeginLoopDirective>(x);
+
return; // found do-loop
}
}
@@ -163,8 +190,12 @@ class CanonicalizationOfAcc {
"DO loop after the %s directive must have loop control"_err_en_US,
parser::ToUpperCaseLetters(dir.source.ToString()));
}
+
+ CheckDoConcurrentClauseRestriction<parser::OpenACCCombinedConstruct,
+ parser::AccBeginCombinedDirective>(x);
CheckTileClauseRestriction<parser::OpenACCCombinedConstruct,
parser::AccBeginCombinedDirective>(x);
+
return; // found do-loop
}
}
diff --git a/flang/test/Semantics/acc-canonicalization-validity.f90 b/flang/test/Semantics/acc-canonicalization-validity.f90
index 350f6315867c..bb7afaf463f1 100644
--- a/flang/test/Semantics/acc-canonicalization-validity.f90
+++ b/flang/test/Semantics/acc-canonicalization-validity.f90
@@ -13,6 +13,7 @@ program openacc_clause_validity
integer :: i, j
integer :: N = 256
real(8) :: a(256)
+ real(8) :: aa(256, 256)
!ERROR: A DO loop must follow the LOOP directive
!$acc loop
@@ -106,4 +107,20 @@ program openacc_clause_validity
a(i) = 3.14
end do
+ !$acc parallel
+ !ERROR: TILE and COLLAPSE clause may not appear on loop construct associated with DO CONCURRENT
+ !$acc loop collapse(2)
+ do concurrent (i = 1:N, j = 1:N)
+ aa(i, j) = 3.14
+ end do
+ !$acc end parallel
+
+ !$acc parallel
+ !ERROR: TILE and COLLAPSE clause may not appear on loop construct associated with DO CONCURRENT
+ !$acc loop tile(2, 2)
+ do concurrent (i = 1:N, j = 1:N)
+ aa(i, j) = 3.14
+ end do
+ !$acc end parallel
+
end program openacc_clause_validity
diff --git a/flang/test/Semantics/acc-clause-validity.f90 b/flang/test/Semantics/acc-clause-validity.f90
index 22b332841df4..993119871add 100644
--- a/flang/test/Semantics/acc-clause-validity.f90
+++ b/flang/test/Semantics/acc-clause-validity.f90
@@ -219,6 +219,14 @@ program openacc_clause_validity
end do
!$acc end parallel
+ !$acc parallel
+ !ERROR: SEQ and AUTO clauses are mutually exclusive and may not appear on the same LOOP directive
+ !$acc loop auto seq
+ do i = 1, N
+ a(i) = 3.14
+ end do
+ !$acc end parallel
+
!$acc parallel
!$acc loop tile(2)
do i = 1, N
@@ -287,6 +295,14 @@ program openacc_clause_validity
end do
!$acc end parallel
+ !$acc parallel
+ !ERROR: At most one VECTOR clause can appear on the LOOP directive
+ !$acc loop vector vector(128)
+ do i = 1, N
+ a(i) = 3.14
+ end do
+ !$acc end parallel
+
!$acc parallel
!$acc loop vector
do i = 1, N
@@ -315,6 +331,14 @@ program openacc_clause_validity
end do
!$acc end parallel
+ !$acc parallel
+ !ERROR: At most one WORKER clause can appear on the LOOP directive
+ !$acc loop worker worker(10)
+ do i = 1, N
+ a(i) = 3.14
+ end do
+ !$acc end parallel
+
!$acc parallel
!$acc loop worker
do i = 1, N
@@ -343,6 +367,14 @@ program openacc_clause_validity
end do
!$acc end parallel
+ !$acc parallel
+ !ERROR: At most one GANG clause can appear on the LOOP directive
+ !$acc loop gang gang(gang_size)
+ do i = 1, N
+ a(i) = 3.14
+ end do
+ !$acc end parallel
+
!$acc parallel
!$acc loop gang(gang_size)
do i = 1, N
@@ -528,6 +560,22 @@ program openacc_clause_validity
end do
!$acc end parallel
+ !$acc parallel
+ !ERROR: Clause WORKER is not allowed if clause SEQ appears on the LOOP directive
+ !$acc loop worker seq
+ do i = 1, N
+ a(i) = 3.14
+ end do
+ !$acc end parallel
+
+ !$acc parallel
+ !ERROR: Clause VECTOR is not allowed if clause SEQ appears on the LOOP directive
+ !$acc loop vector seq
+ do i = 1, N
+ a(i) = 3.14
+ end do
+ !$acc end parallel
+
!ERROR: Clause IF is not allowed after clause DEVICE_TYPE on the PARALLEL directive
!$acc parallel device_type(*) if(.TRUE.)
!$acc loop
More information about the llvm-branch-commits
mailing list