OpenMP 5.0 removed the restriction that collapsed loops in "omp for/do" and related constructs must be perfectly nested; it now allows intervening code to appear before/after each nested loop level. The spec allows implementations considerable freedom in how many times this intervening code is executed, and it seemed to me that the simplest solution was to push it all into the loop body so that it is executed on every logical iteration. Implementing this in the respective front ends means that no changes are required in the OMP_FOR representation or in subsequent gimplification and lowering passes.
For C and C++, I refactored the OMP_FOR parsing code to use recursive descent and parallel the revised syntax in the OpenMP spec for canonical loop nest form. In C this was relatively straightforward, but in C++ the code that handles nested scopes for class iterators gave me fits. I ended up parsing the entire construct and then reassembling the bits of code, and I tried to make this at least better-documented than the code that was previously there. In the Fortran front end, I implemented the transformation during resolution. This patch series has some overlap with Frederik Harwath's tile/unroll patch set, but has been developed and tested independently of those changes. https://gcc.gnu.org/pipermail/gcc-patches/2023-March/614564.html Depending on what order they are reviewed/committed in, we will of course take care of merging and retesting them together. Frederik has already reviewed my patches and gave me some very helpful feedback, and Tobias also has helped out, especially when I got stuck on some unrelated bugs. -Sandra Sandra Loosemore (3): OpenMP: C support for imperfectly-nested loops OpenMP: C++ support for imperfectly-nested loops OpenMP: Fortran support for imperfectly-nested loops gcc/c/c-parser.cc | 692 ++++++---- gcc/cp/cp-tree.h | 2 +- gcc/cp/parser.cc | 1180 ++++++++++++----- gcc/cp/parser.h | 3 + gcc/cp/pt.cc | 3 +- gcc/cp/semantics.cc | 80 +- gcc/fortran/openmp.cc | 590 +++++++-- gcc/omp-api.h | 32 + gcc/omp-general.cc | 134 ++ gcc/omp-general.h | 1 + gcc/omp-low.cc | 129 -- gcc/testsuite/c-c++-common/goacc/collapse-1.c | 14 +- gcc/testsuite/c-c++-common/goacc/tile-2.c | 4 +- gcc/testsuite/c-c++-common/gomp/imperfect1.c | 40 + gcc/testsuite/c-c++-common/gomp/imperfect2.c | 36 + gcc/testsuite/c-c++-common/gomp/imperfect3.c | 35 + gcc/testsuite/c-c++-common/gomp/imperfect4.c | 35 + gcc/testsuite/c-c++-common/gomp/imperfect5.c | 59 + gcc/testsuite/g++.dg/gomp/pr41967.C | 2 +- gcc/testsuite/gcc.dg/gomp/collapse-1.c | 10 +- gcc/testsuite/gfortran.dg/gomp/collapse1.f90 | 6 +- gcc/testsuite/gfortran.dg/gomp/collapse2.f90 | 10 +- gcc/testsuite/gfortran.dg/gomp/imperfect1.f90 | 39 + gcc/testsuite/gfortran.dg/gomp/imperfect2.f90 | 56 + gcc/testsuite/gfortran.dg/gomp/imperfect3.f90 | 29 + gcc/testsuite/gfortran.dg/gomp/imperfect4.f90 | 36 + gcc/testsuite/gfortran.dg/gomp/imperfect5.f90 | 67 + .../testsuite/libgomp.c++/imperfect-class-1.C | 169 +++ .../testsuite/libgomp.c++/imperfect-class-2.C | 167 +++ .../testsuite/libgomp.c++/imperfect-class-3.C | 167 +++ .../libgomp.c++/imperfect-destructor.C | 135 ++ .../libgomp.c++/imperfect-template-1.C | 172 +++ .../libgomp.c++/imperfect-template-2.C | 170 +++ .../libgomp.c++/imperfect-template-3.C | 170 +++ .../libgomp.c-c++-common/imperfect1.c | 76 ++ .../libgomp.c-c++-common/imperfect2.c | 114 ++ .../libgomp.c-c++-common/imperfect3.c | 119 ++ .../libgomp.c-c++-common/imperfect4.c | 117 ++ .../libgomp.c-c++-common/imperfect5.c | 49 + .../libgomp.c-c++-common/imperfect6.c | 115 ++ .../libgomp.c-c++-common/offload-imperfect1.c | 81 ++ .../libgomp.c-c++-common/offload-imperfect2.c | 122 ++ .../libgomp.c-c++-common/offload-imperfect3.c | 125 ++ .../libgomp.c-c++-common/offload-imperfect4.c | 122 ++ .../libgomp.fortran/imperfect-destructor.f90 | 142 ++ .../testsuite/libgomp.fortran/imperfect1.f90 | 67 + .../testsuite/libgomp.fortran/imperfect2.f90 | 102 ++ .../testsuite/libgomp.fortran/imperfect3.f90 | 110 ++ .../testsuite/libgomp.fortran/imperfect4.f90 | 121 ++ .../libgomp.fortran/offload-imperfect1.f90 | 72 + .../libgomp.fortran/offload-imperfect2.f90 | 110 ++ .../libgomp.fortran/offload-imperfect3.f90 | 116 ++ .../libgomp.fortran/offload-imperfect4.f90 | 126 ++ 53 files changed, 5588 insertions(+), 892 deletions(-) create mode 100644 gcc/omp-api.h create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect1.c create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect2.c create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect3.c create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect4.c create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect5.c create mode 100644 gcc/testsuite/gfortran.dg/gomp/imperfect1.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/imperfect2.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/imperfect3.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/imperfect4.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/imperfect5.f90 create mode 100644 libgomp/testsuite/libgomp.c++/imperfect-class-1.C create mode 100644 libgomp/testsuite/libgomp.c++/imperfect-class-2.C create mode 100644 libgomp/testsuite/libgomp.c++/imperfect-class-3.C create mode 100644 libgomp/testsuite/libgomp.c++/imperfect-destructor.C create mode 100644 libgomp/testsuite/libgomp.c++/imperfect-template-1.C create mode 100644 libgomp/testsuite/libgomp.c++/imperfect-template-2.C create mode 100644 libgomp/testsuite/libgomp.c++/imperfect-template-3.C create mode 100644 libgomp/testsuite/libgomp.c-c++-common/imperfect1.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/imperfect2.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/imperfect3.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/imperfect4.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/imperfect5.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/imperfect6.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/offload-imperfect1.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/offload-imperfect2.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/offload-imperfect3.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/offload-imperfect4.c create mode 100644 libgomp/testsuite/libgomp.fortran/imperfect-destructor.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/imperfect1.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/imperfect2.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/imperfect3.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/imperfect4.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/offload-imperfect1.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/offload-imperfect2.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/offload-imperfect3.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/offload-imperfect4.f90 -- 2.31.1