From 1e13a5c75fb694d94c057fe267a3b62dd8545d3e Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Mon, 17 Nov 2025 09:36:28 -0600 Subject: [PATCH 1/3] [flang][OpenMP] Fix some typo-like things in test case --- .../loop-transformation-construct01.f90 | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/flang/test/Semantics/OpenMP/loop-transformation-construct01.f90 b/flang/test/Semantics/OpenMP/loop-transformation-construct01.f90 index f718efc32aabf..f4628c9533db8 100644 --- a/flang/test/Semantics/OpenMP/loop-transformation-construct01.f90 +++ b/flang/test/Semantics/OpenMP/loop-transformation-construct01.f90 @@ -13,13 +13,13 @@ subroutine loop_transformation_construct1 subroutine loop_transformation_construct2 implicit none integer :: i = 5 - integer :: y + integer :: x integer :: v(i) !$omp do !$omp tile do x = 1, i - v(x) = x(x) * 2 + v(x) = v(x) * 2 end do !$omp end tile !$omp end do @@ -30,26 +30,26 @@ subroutine loop_transformation_construct2 subroutine loop_transformation_construct2 implicit none integer :: i = 5 - integer :: y + integer :: x integer :: v(i) !$omp do !ERROR: Only Loop Transformation Constructs or Loop Nests can be nested within Loop Constructs !$omp parallel do do x = 1, i - v(x) = x(x) * 2 + v(x) = v(x) * 2 end do end subroutine subroutine loop_transformation_construct3 implicit none integer :: i = 5 - integer :: y + integer :: x integer :: v(i) !$omp do do x = 1, i - v(x) = x(x) * 2 + v(x) = v(x) * 2 end do !ERROR: A DO loop must follow the TILE directive !$omp tile @@ -58,7 +58,7 @@ subroutine loop_transformation_construct3 subroutine loop_transformation_construct4 implicit none integer :: i = 5 - integer :: y + integer :: x integer :: v(i) !$omp do @@ -66,14 +66,14 @@ subroutine loop_transformation_construct4 !$omp tile !$omp unroll full do x = 1, i - v(x) = x(x) * 2 + v(x) = v(x) * 2 end do end subroutine subroutine loop_transformation_construct5 implicit none integer :: i = 5 - integer :: y + integer :: x integer :: v(i) !$omp do @@ -81,20 +81,20 @@ subroutine loop_transformation_construct5 !$omp tile !$omp unroll do x = 1, i - v(x) = x(x) * 2 + v(x) = v(x) * 2 end do end subroutine subroutine loop_transformation_construct6 implicit none integer :: i = 5 - integer :: y + integer :: x integer :: v(i) !$omp do !$omp tile !$omp unroll partial(2) do x = 1, i - v(x) = x(x) * 2 + v(x) = v(x) * 2 end do end subroutine From aaea8e6b47808333581569d40e3721050be52bf1 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Fri, 14 Nov 2025 15:52:11 -0600 Subject: [PATCH 2/3] [flang][OpenMP] Implement loop nest parser Previously, loop constructs were parsed in a piece-wise manner: the begin directive, the body, and the end directive were parsed separately. Later on in canonicalization they were all coalesced into a loop construct. To facilitate that end-loop directives were given a special treatment, namely they were parsed as OpenMP constructs. As a result syntax errors caused by misplaced end-loop directives were handled differently from those cause by misplaced non-loop end directives. The new loop nest parser constructs the complete loop construct, removing the need for the canonicalization step. Additionally, it is the basis for parsing loop-sequence-associated constructs in the future. It also removes the need for the special treatment of end-loop directives. While this patch temporarily degrades the error messaging for misplaced end-loop directives, it enables uniform handling of any misplaced end-directives in the future. --- flang/include/flang/Parser/parse-tree.h | 3 +- flang/lib/Parser/executable-parsers.cpp | 1 - flang/lib/Parser/openmp-parsers.cpp | 143 ++++++++++++++- flang/lib/Parser/parse-tree.cpp | 35 +++- flang/lib/Semantics/canonicalize-omp.cpp | 163 ------------------ flang/lib/Semantics/check-omp-loop.cpp | 74 ++++++++ flang/lib/Semantics/check-omp-structure.h | 4 + flang/lib/Semantics/resolve-directives.cpp | 7 - ...nested-loop-transformation-construct02.f90 | 2 +- .../loop-transformation-construct01.f90 | 7 +- .../loop-transformation-construct02.f90 | 7 +- flang/test/Parser/OpenMP/tile-fail.f90 | 5 +- flang/test/Semantics/OpenMP/do21.f90 | 10 +- .../Semantics/OpenMP/loop-association.f90 | 33 ++-- .../loop-transformation-construct01.f90 | 40 +++-- flang/test/Semantics/OpenMP/tile02.f90 | 2 +- 16 files changed, 293 insertions(+), 243 deletions(-) diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h index 60d2ad0b764b9..9795a0d2ae25e 100644 --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -271,7 +271,6 @@ struct OpenACCRoutineConstruct; struct OpenMPConstruct; struct OpenMPLoopConstruct; struct OpenMPDeclarativeConstruct; -struct OmpEndLoopDirective; struct CUFKernelDoConstruct; // Cooked character stream locations @@ -539,7 +538,6 @@ struct ExecutableConstruct { common::Indirection, common::Indirection, common::Indirection, - common::Indirection, common::Indirection> u; }; @@ -5359,6 +5357,7 @@ struct OpenMPLoopConstruct { const DoConstruct *GetNestedLoop() const; const OpenMPLoopConstruct *GetNestedConstruct() const; + CharBlock source; std::tuple> t; }; diff --git a/flang/lib/Parser/executable-parsers.cpp b/flang/lib/Parser/executable-parsers.cpp index fadec1f11d1db..8d777a6671495 100644 --- a/flang/lib/Parser/executable-parsers.cpp +++ b/flang/lib/Parser/executable-parsers.cpp @@ -49,7 +49,6 @@ constexpr auto executableConstruct{first( construct(indirect(Parser{})), construct(indirect(whereConstruct)), construct(indirect(forallConstruct)), - construct(indirect(ompEndLoopDirective)), construct(indirect(openmpConstruct)), construct(indirect(Parser{})), construct(indirect(compilerDirective)), diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp index e2da60ed19de8..d50f45794230b 100644 --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -17,6 +17,7 @@ #include "type-parser-implementation.h" #include "flang/Parser/openmp-utils.h" #include "flang/Parser/parse-tree.h" +#include "flang/Parser/tools.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/Bitset.h" #include "llvm/ADT/STLExtras.h" @@ -30,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -1656,6 +1658,100 @@ struct LooselyStructuredBlockParser { } }; +struct NonBlockDoConstructParser { + using resultType = Block; + + std::optional Parse(ParseState &state) const { + std::set