[Patch] Fortran/OpenMP: align/allocator modifiers to the allocate clause

2022-12-09 Thread Tobias Burnus

Implementing the 5.1 syntax inside the 'allocate' clause. That's a
fallout of working on something else...

OK for mainline?

Tobias
-
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
München, HRB 106955
Fortran/OpenMP: align/allocator modifiers to the allocate clause

gcc/fortran/ChangeLog:

	* dump-parse-tree.cc (show_omp_namelist): Improve OMP_LIST_ALLOCATE
	output.
	* gfortran.h (struct gfc_omp_namelist): Add 'align' to 'u'.
	(gfc_free_omp_namelist): Add bool arg.
	* match.cc (gfc_free_omp_namelist): Likewise; free 'u.align'.
	* openmp.cc (gfc_free_omp_clauses, gfc_match_omp_clause_reduction,
	gfc_match_omp_flush): Update call.
	(gfc_match_omp_clauses): Match 'align/allocate modifers in
	'allocate' clause.
	(resolve_omp_clauses): Resolve align.
	* st.cc (gfc_free_statement): Update call
	* trans-openmp.cc (gfc_trans_omp_clauses): Handle 'align'.

libgomp/ChangeLog:

	* libgomp.texi (5.1 Impl. Status): Split allocate clause/directive
	item about 'align'; mark clause as 'Y' and directive as 'N'.
	* testsuite/libgomp.fortran/allocate-2.f90: New test.
	* testsuite/libgomp.fortran/allocate-3.f90: New test.

 gcc/fortran/dump-parse-tree.cc   |  23 +
 gcc/fortran/gfortran.h   |   3 +-
 gcc/fortran/match.cc |   4 +-
 gcc/fortran/openmp.cc| 106 +++
 gcc/fortran/st.cc|   2 +-
 gcc/fortran/trans-openmp.cc  |   8 ++
 libgomp/libgomp.texi |   4 +-
 libgomp/testsuite/libgomp.fortran/allocate-2.f90 |  25 ++
 libgomp/testsuite/libgomp.fortran/allocate-3.f90 |  28 ++
 9 files changed, 163 insertions(+), 40 deletions(-)

diff --git a/gcc/fortran/dump-parse-tree.cc b/gcc/fortran/dump-parse-tree.cc
index 2f042ab5142..5ae72dc1cac 100644
--- a/gcc/fortran/dump-parse-tree.cc
+++ b/gcc/fortran/dump-parse-tree.cc
@@ -1357,6 +1357,29 @@ show_omp_namelist (int list_type, gfc_omp_namelist *n)
 	}
 	  ns_iter = n->u2.ns;
 	}
+  if (list_type == OMP_LIST_ALLOCATE)
+	{
+	  if (n->expr)
+	{
+	  fputs ("allocator(", dumpfile);
+	  show_expr (n->expr);
+	  fputc (')', dumpfile);
+	}
+	  if (n->expr && n->u.align)
+	fputc (',', dumpfile);
+	  if (n->u.align)
+	{
+	  fputs ("allocator(", dumpfile);
+	  show_expr (n->u.align);
+	  fputc (')', dumpfile);
+	}
+	  if (n->expr || n->u.align)
+	fputc (':', dumpfile);
+	  fputs (n->sym->name, dumpfile);
+	  if (n->next)
+	fputs (") ALLOCATE(", dumpfile);
+	  continue;
+	}
   if (list_type == OMP_LIST_REDUCTION)
 	switch (n->u.reduction_op)
 	  {
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index b541a07e2c7..5f8a81ae4a1 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -1349,6 +1349,7 @@ typedef struct gfc_omp_namelist
   gfc_omp_reduction_op reduction_op;
   gfc_omp_depend_doacross_op depend_doacross_op;
   gfc_omp_map_op map_op;
+  gfc_expr *align;
   struct
 	{
 	  ENUM_BITFIELD (gfc_omp_linear_op) op:4;
@@ -3572,7 +3573,7 @@ void gfc_free_iterator (gfc_iterator *, int);
 void gfc_free_forall_iterator (gfc_forall_iterator *);
 void gfc_free_alloc_list (gfc_alloc *);
 void gfc_free_namelist (gfc_namelist *);
-void gfc_free_omp_namelist (gfc_omp_namelist *, bool);
+void gfc_free_omp_namelist (gfc_omp_namelist *, bool, bool);
 void gfc_free_equiv (gfc_equiv *);
 void gfc_free_equiv_until (gfc_equiv *, gfc_equiv *);
 void gfc_free_data (gfc_data *);
diff --git a/gcc/fortran/match.cc b/gcc/fortran/match.cc
index 8b8b6e79c8b..7ba0f349993 100644
--- a/gcc/fortran/match.cc
+++ b/gcc/fortran/match.cc
@@ -5524,13 +5524,15 @@ gfc_free_namelist (gfc_namelist *name)
 /* Free an OpenMP namelist structure.  */
 
 void
-gfc_free_omp_namelist (gfc_omp_namelist *name, bool free_ns)
+gfc_free_omp_namelist (gfc_omp_namelist *name, bool free_ns, bool free_align)
 {
   gfc_omp_namelist *n;
 
   for (; name; name = n)
 {
   gfc_free_expr (name->expr);
+  if (free_align)
+	gfc_free_expr (name->u.align);
   if (free_ns)
 	gfc_free_namespace (name->u2.ns);
   else if (name->u2.udr)
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 862c649b0b6..4b4e6ac6947 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -187,7 +187,8 @@ gfc_free_omp_clauses (gfc_omp_clauses *c)
   gfc_free_expr (c->vector_length_expr);
   for (i = 0; i < OMP_LIST_NUM; i++)
 gfc_free_omp_namelist (c->lists[i],
-			   i == OMP_LIST_AFFINITY || i == OMP_LIST_DEPEND);
+			   i == OMP_LIST_AFFINITY || i == OMP_LIST_DEPEND,
+			   i == OMP_LIST_ALLOCATE);
   gfc_free_expr_list (c->wait_list);
   gfc_free_expr_list (c->tile_list);
   free (CONST_CAST (char *, c->critical_name));
@@ -542,7 +543

Re: [Patch] Fortran/OpenMP: align/allocator modifiers to the allocate clause

2022-12-09 Thread Jakub Jelinek via Gcc-patches
On Fri, Dec 09, 2022 at 09:14:55PM +0100, Tobias Burnus wrote:
> Implementing the 5.1 syntax inside the 'allocate' clause. That's a
> fallout of working on something else...
> 
> OK for mainline?
> 
> Tobias
> -
> Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
> München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
> Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
> München, HRB 106955

> Fortran/OpenMP: align/allocator modifiers to the allocate clause
> 
> gcc/fortran/ChangeLog:
> 
>   * dump-parse-tree.cc (show_omp_namelist): Improve OMP_LIST_ALLOCATE
>   output.
>   * gfortran.h (struct gfc_omp_namelist): Add 'align' to 'u'.
>   (gfc_free_omp_namelist): Add bool arg.
>   * match.cc (gfc_free_omp_namelist): Likewise; free 'u.align'.
>   * openmp.cc (gfc_free_omp_clauses, gfc_match_omp_clause_reduction,
>   gfc_match_omp_flush): Update call.
>   (gfc_match_omp_clauses): Match 'align/allocate modifers in
>   'allocate' clause.
>   (resolve_omp_clauses): Resolve align.
>   * st.cc (gfc_free_statement): Update call
>   * trans-openmp.cc (gfc_trans_omp_clauses): Handle 'align'.
> 
> libgomp/ChangeLog:
> 
>   * libgomp.texi (5.1 Impl. Status): Split allocate clause/directive
>   item about 'align'; mark clause as 'Y' and directive as 'N'.
>   * testsuite/libgomp.fortran/allocate-2.f90: New test.
>   * testsuite/libgomp.fortran/allocate-3.f90: New test.

LGTM, thanks.

Jakub