Skip to content

[flang][openacc] Support labeled DO loop after acc combined directive #66296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions flang/lib/Parser/openacc-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ TYPE_PARSER(startAccLine >>

TYPE_PARSER(construct<OpenACCCombinedConstruct>(
sourced(Parser<AccBeginCombinedDirective>{} / endAccLine),
withMessage("A DO loop must follow the combined construct"_err_en_US,
Parser<DoConstruct>{}),
maybe(Parser<DoConstruct>{}),
maybe(Parser<AccEndCombinedDirective>{} / endAccLine)))

} // namespace Fortran::parser
20 changes: 15 additions & 5 deletions flang/lib/Semantics/canonicalize-acc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,24 @@ class CanonicalizationOfAcc {
parser::Block::iterator nextIt;
auto &beginDir{std::get<parser::AccBeginCombinedDirective>(x.t)};
auto &dir{std::get<parser::AccCombinedDirective>(beginDir.t)};
const auto &doConstruct{std::get<std::optional<parser::DoConstruct>>(x.t)};
auto &nestedDo{std::get<std::optional<parser::DoConstruct>>(x.t)};

if (!nestedDo) {
nextIt = it;
if (++nextIt != block.end()) {
if (auto *doCons{parser::Unwrap<parser::DoConstruct>(*nextIt)}) {
nestedDo = std::move(*doCons);
nextIt = block.erase(nextIt);
}
}
}

if (doConstruct) {
if (nestedDo) {
CheckDoConcurrentClauseRestriction<parser::OpenACCCombinedConstruct,
parser::AccBeginCombinedDirective>(x, *doConstruct);
parser::AccBeginCombinedDirective>(x, *nestedDo);
CheckTileClauseRestriction<parser::OpenACCCombinedConstruct,
parser::AccBeginCombinedDirective>(x, *doConstruct);
if (!doConstruct->GetLoopControl()) {
parser::AccBeginCombinedDirective>(x, *nestedDo);
if (!nestedDo->GetLoopControl()) {
messages_.Say(dir.source,
"DO loop after the %s directive must have loop control"_err_en_US,
parser::ToUpperCaseLetters(dir.source.ToString()));
Expand Down
7 changes: 7 additions & 0 deletions flang/test/Lower/OpenACC/acc-parallel-loop.f90
Original file line number Diff line number Diff line change
Expand Up @@ -803,4 +803,11 @@ subroutine acc_parallel_loop
! CHECK: acc.yield
! CHECK-NEXT: }{{$}}

!$acc parallel loop
do 10 i=0, n
10 continue
! CHECK: acc.parallel
! CHECK: acc.loop
! CHECK: fir.do_loop

end subroutine acc_parallel_loop
18 changes: 15 additions & 3 deletions flang/test/Semantics/OpenACC/acc-combined-loop.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,28 @@ program openacc_combined_loop

i = 1

!ERROR: A DO loop must follow the PARALLEL LOOP directive
!$acc parallel loop
!ERROR: A DO loop must follow the combined construct
i = 1

!ERROR: A DO loop must follow the KERNELS LOOP directive
!$acc kernels loop
!ERROR: A DO loop must follow the combined construct
i = 1

!ERROR: A DO loop must follow the SERIAL LOOP directive
!$acc serial loop
!ERROR: A DO loop must follow the combined construct
i = 1

!$acc parallel loop
do 10 i=0, n
10 continue

!$acc kernels loop
do 20 i=0, n
20 continue

!$acc serial loop
do 30 i=0, n
30 continue

end