mbox series

[V2,0/5] OpenMP: support for imperfectly-nested loops

Message ID 20230723221521.3739463-1-sandra@codesourcery.com
Headers show
Series OpenMP: support for imperfectly-nested loops | expand

Message

Sandra Loosemore July 23, 2023, 10:15 p.m. UTC
Here is the latest version of my imperfectly-nested loops patches.
Compared to the initial version I'd posted in April

https://gcc.gnu.org/pipermail/gcc-patches/2023-April/617103.html

this version includes many minor cosmetic fixes suggested by Jakub in
his initial review (also present in the version I committed to the
OG13 branch last month), many new test cases to cover various corner
cases, and code fixes so that C and C++ at least behave consistently
even if the spec is unclear.  The most intrusive of those fixes is
that I couldn't figure out how to make jumping between different
structured blocks of intervening code in the same OMP loop construct
produce errors without introducing new GENERIC and GIMPLE data
structures to represent a structured block without any other
associated OpenMP semantics; that's now part 1 of the patch series.

There are a few things from the review comments I haven't done anything
about:

* I left omp-api.h alone because the Fortran front end needs those
  declarations without everything else in omp-general.h.

* I didn't think I ought to be speculatively implementing extensions
  like allowing "do { ... } while (0);" in intervening code.  If it's
  really important for supporting macros, I suppose it will make it
  into a future version of the OpenMP spec.

* I didn't understand the comment about needing to add "#pragma omp
  ordered doacross(source) and sink" to the testcase for errors with
  the "ordered" clause.  Isn't that only for cross-iteration
  data dependencies?  There aren't any in that loop.  Also note that some
  of my new corner-case tests use the "ordered" clause to trigger an
  error to check that things are being correctly parsed as intervening
  code, so if there is something really bogus there that must be fixed,
  it now affects other test cases as well.

* Likewise I didn't know what to do with coming up with a better
  testcase for "scan".  I could not find an existing testcase with nested
  loops that I could just add intervening code to, and when I made
  another attempt to write a new one from scratch I quickly realized I
  couldn't do much better than the existing one, which Tobias had
  originally helped me with.

-Sandra


Sandra Loosemore (5):
  OpenMP: Add OMP_STRUCTURED_BLOCK and GIMPLE_OMP_STRUCTURED_BLOCK.
  OpenMP:  C front end support for imperfectly-nested loops
  OpenMP: C++ support for imperfectly-nested loops
  OpenMP: New C/C++ testcases for imperfectly nested loops.
  OpenMP: Fortran support for imperfectly-nested loops

 gcc/c-family/c-common.h                       |    1 +
 gcc/c-family/c-omp.cc                         |  151 ++
 gcc/c/c-parser.cc                             |  860 +++++++----
 gcc/cp/constexpr.cc                           |    1 +
 gcc/cp/cp-tree.h                              |    2 +-
 gcc/cp/parser.cc                              | 1315 ++++++++++++-----
 gcc/cp/parser.h                               |    3 +
 gcc/cp/pt.cc                                  |    4 +-
 gcc/cp/semantics.cc                           |  117 +-
 gcc/doc/generic.texi                          |   14 +
 gcc/doc/gimple.texi                           |   19 +
 gcc/fortran/gfortran.h                        |    3 +
 gcc/fortran/openmp.cc                         |  765 ++++++++--
 gcc/fortran/trans-stmt.cc                     |    7 +-
 gcc/gimple-low.cc                             |    5 +
 gcc/gimple-pretty-print.cc                    |    6 +-
 gcc/gimple-walk.cc                            |    1 +
 gcc/gimple.cc                                 |   15 +
 gcc/gimple.def                                |    5 +
 gcc/gimple.h                                  |    3 +
 gcc/gimplify.cc                               |    6 +
 gcc/omp-api.h                                 |   32 +
 gcc/omp-expand.cc                             |    5 +
 gcc/omp-general.cc                            |  134 ++
 gcc/omp-general.h                             |    1 +
 gcc/omp-low.cc                                |  140 +-
 gcc/testsuite/c-c++-common/goacc/collapse-1.c |   16 +-
 gcc/testsuite/c-c++-common/goacc/tile-2.c     |    4 +-
 .../c-c++-common/gomp/imperfect-attributes.c  |   81 +
 .../c-c++-common/gomp/imperfect-badloops.c    |   50 +
 .../c-c++-common/gomp/imperfect-blocks.c      |   75 +
 .../c-c++-common/gomp/imperfect-extension.c   |   55 +
 .../c-c++-common/gomp/imperfect-gotos.c       |  174 +++
 .../gomp/imperfect-invalid-scope.c            |   77 +
 .../c-c++-common/gomp/imperfect-labels.c      |   85 ++
 .../gomp/imperfect-legacy-syntax.c            |   44 +
 .../c-c++-common/gomp/imperfect-pragmas.c     |   85 ++
 gcc/testsuite/c-c++-common/gomp/imperfect1.c  |   38 +
 gcc/testsuite/c-c++-common/gomp/imperfect2.c  |   34 +
 gcc/testsuite/c-c++-common/gomp/imperfect3.c  |   33 +
 gcc/testsuite/c-c++-common/gomp/imperfect4.c  |   33 +
 gcc/testsuite/c-c++-common/gomp/imperfect5.c  |   57 +
 gcc/testsuite/g++.dg/gomp/attrs-imperfect1.C  |   38 +
 gcc/testsuite/g++.dg/gomp/attrs-imperfect2.C  |   34 +
 gcc/testsuite/g++.dg/gomp/attrs-imperfect3.C  |   33 +
 gcc/testsuite/g++.dg/gomp/attrs-imperfect4.C  |   33 +
 gcc/testsuite/g++.dg/gomp/attrs-imperfect5.C  |   57 +
 gcc/testsuite/g++.dg/gomp/pr41967.C           |    2 +-
 .../g++.dg/gomp/tpl-imperfect-gotos.C         |  161 ++
 .../g++.dg/gomp/tpl-imperfect-invalid-scope.C |   94 ++
 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 +-
 .../gfortran.dg/gomp/imperfect-gotos.f90      |   69 +
 .../gomp/imperfect-invalid-scope.f90          |   81 +
 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 +
 gcc/tree-inline.cc                            |    6 +
 gcc/tree-nested.cc                            |    3 +
 gcc/tree-pretty-print.cc                      |    4 +
 gcc/tree.def                                  |    9 +
 gcc/tree.h                                    |    3 +
 .../testsuite/libgomp.c++/attrs-imperfect1.C  |   76 +
 .../testsuite/libgomp.c++/attrs-imperfect2.C  |  114 ++
 .../testsuite/libgomp.c++/attrs-imperfect3.C  |  119 ++
 .../testsuite/libgomp.c++/attrs-imperfect4.C  |  117 ++
 .../testsuite/libgomp.c++/attrs-imperfect5.C  |   49 +
 .../testsuite/libgomp.c++/attrs-imperfect6.C  |  115 ++
 .../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/target-imperfect1.c  |   81 +
 .../libgomp.c-c++-common/target-imperfect2.c  |  122 ++
 .../libgomp.c-c++-common/target-imperfect3.c  |  125 ++
 .../libgomp.c-c++-common/target-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/target-imperfect1.f90     |   72 +
 .../libgomp.fortran/target-imperfect2.f90     |  110 ++
 .../libgomp.fortran/target-imperfect3.f90     |  116 ++
 .../libgomp.fortran/target-imperfect4.f90     |  126 ++
 97 files changed, 8270 insertions(+), 912 deletions(-)
 create mode 100644 gcc/omp-api.h
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect-attributes.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect-badloops.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect-blocks.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect-extension.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect-gotos.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect-invalid-scope.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect-labels.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect-legacy-syntax.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect-pragmas.c
 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/g++.dg/gomp/attrs-imperfect1.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-imperfect2.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-imperfect3.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-imperfect4.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-imperfect5.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/tpl-imperfect-gotos.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/tpl-imperfect-invalid-scope.C
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/imperfect-gotos.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/imperfect-invalid-scope.f90
 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++/attrs-imperfect1.C
 create mode 100644 libgomp/testsuite/libgomp.c++/attrs-imperfect2.C
 create mode 100644 libgomp/testsuite/libgomp.c++/attrs-imperfect3.C
 create mode 100644 libgomp/testsuite/libgomp.c++/attrs-imperfect4.C
 create mode 100644 libgomp/testsuite/libgomp.c++/attrs-imperfect5.C
 create mode 100644 libgomp/testsuite/libgomp.c++/attrs-imperfect6.C
 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/target-imperfect1.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/target-imperfect2.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/target-imperfect3.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/target-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/target-imperfect1.f90
 create mode 100644 libgomp/testsuite/libgomp.fortran/target-imperfect2.f90
 create mode 100644 libgomp/testsuite/libgomp.fortran/target-imperfect3.f90
 create mode 100644 libgomp/testsuite/libgomp.fortran/target-imperfect4.f90

Comments

Jakub Jelinek Aug. 22, 2023, 12:56 p.m. UTC | #1
On Sun, Jul 23, 2023 at 04:15:16PM -0600, Sandra Loosemore wrote:
> Here is the latest version of my imperfectly-nested loops patches.
> Compared to the initial version I'd posted in April
> 
> https://gcc.gnu.org/pipermail/gcc-patches/2023-April/617103.html
> 
> this version includes many minor cosmetic fixes suggested by Jakub in
> his initial review (also present in the version I committed to the
> OG13 branch last month), many new test cases to cover various corner
> cases, and code fixes so that C and C++ at least behave consistently
> even if the spec is unclear.  The most intrusive of those fixes is
> that I couldn't figure out how to make jumping between different
> structured blocks of intervening code in the same OMP loop construct
> produce errors without introducing new GENERIC and GIMPLE data
> structures to represent a structured block without any other
> associated OpenMP semantics; that's now part 1 of the patch series.
> 
> There are a few things from the review comments I haven't done anything
> about:
> 
> * I left omp-api.h alone because the Fortran front end needs those
>   declarations without everything else in omp-general.h.

Ok.

> * I didn't think I ought to be speculatively implementing extensions
>   like allowing "do { ... } while (0);" in intervening code.  If it's
>   really important for supporting macros, I suppose it will make it
>   into a future version of the OpenMP spec.

Ack.

> * I didn't understand the comment about needing to add "#pragma omp
>   ordered doacross(source) and sink" to the testcase for errors with
>   the "ordered" clause.  Isn't that only for cross-iteration
>   data dependencies?  There aren't any in that loop.  Also note that some
>   of my new corner-case tests use the "ordered" clause to trigger an
>   error to check that things are being correctly parsed as intervening
>   code, so if there is something really bogus there that must be fixed,
>   it now affects other test cases as well.

ordered(N) clause is meant to be used with doacross loops, where one uses
#pragma omp ordered depend/doacross in the body.
So, when one is testing the rejection of imperfectly nested loops with it,
it is better to actually test it on something properly formed except for the
extra code making the loop imperfectly nested, rather than test it on
something which doesn't have the ordered directives in the body at all.

> * Likewise I didn't know what to do with coming up with a better
>   testcase for "scan".  I could not find an existing testcase with nested
>   loops that I could just add intervening code to, and when I made

What about libgomp.c-c++-common/scan-1.c ?
Obviously, you can cut the initialization and checking, because that is a
runtime testcase and all you need is a compile time test; perhaps put each
of the 2 loop nests into a separate function and just add some code in
between the loops + dg-error.

	Jakub