-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-flang-parser @llvm/pr-subscribers-flang-fir-hlfir ChangesThis patch adds support for labeled do loop after combined directive. It relaxes the initial parser and canonicalize labeled do loop into the OpenACCCombinedConstruct. -- Full diff: https://github.com//pull/66296.diff4 Files Affected:
diff --git a/flang/lib/Parser/openacc-parsers.cpp b/flang/lib/Parser/openacc-parsers.cpp index afa12b88019bd9a..6f4341c29ab0346 100644 --- a/flang/lib/Parser/openacc-parsers.cpp +++ b/flang/lib/Parser/openacc-parsers.cpp @@ -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 diff --git a/flang/lib/Semantics/canonicalize-acc.cpp b/flang/lib/Semantics/canonicalize-acc.cpp index e79ab997637b083..595efd0be030a24 100644 --- a/flang/lib/Semantics/canonicalize-acc.cpp +++ b/flang/lib/Semantics/canonicalize-acc.cpp @@ -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())); diff --git a/flang/test/Lower/OpenACC/acc-parallel-loop.f90 b/flang/test/Lower/OpenACC/acc-parallel-loop.f90 index 4490a460afe969e..b9113437f86aa07 100644 --- a/flang/test/Lower/OpenACC/acc-parallel-loop.f90 +++ b/flang/test/Lower/OpenACC/acc-parallel-loop.f90 @@ -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 diff --git a/flang/test/Semantics/OpenACC/acc-combined-loop.f90 b/flang/test/Semantics/OpenACC/acc-combined-loop.f90 index 04ff6a308d55f4c..77ff8e1cc603c80 100644 --- a/flang/test/Semantics/OpenACC/acc-combined-loop.f90 +++ b/flang/test/Semantics/OpenACC/acc-combined-loop.f90 @@ -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 |
vzakhari
approved these changes
Sep 13, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
kstoimenov
pushed a commit
to kstoimenov/llvm-project
that referenced
this pull request
Sep 14, 2023
…llvm#66296) This patch adds support for labeled do loop after combined directive. It relaxes the initial parser and canonicalize labeled do loop into the OpenACCCombinedConstruct.
This was referenced Sep 14, 2023
ZijunZhaoCCK
pushed a commit
to ZijunZhaoCCK/llvm-project
that referenced
this pull request
Sep 19, 2023
…llvm#66296) This patch adds support for labeled do loop after combined directive. It relaxes the initial parser and canonicalize labeled do loop into the OpenACCCombinedConstruct.
Guzhu-AMD
pushed a commit
to GPUOpen-Drivers/llvm-project
that referenced
this pull request
Sep 21, 2023
Local branch amd-gfx 251b3d8 Merged main:19b664d35266 into amd-gfx:f205aef70eb5 Remote branch main 16cf9c9 [flang][openacc] Support labeled DO loop after acc combined directive (llvm#66296)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch adds support for labeled do loop after combined directive. It relaxes the initial parser and canonicalize labeled do loop into the OpenACCCombinedConstruct.