public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, Fortran, sync_alloc, v1] [Coarray] Do not add sync all call when allocating allocatable/pointer component
@ 2017-01-18 17:02 Andre Vehreschild
  2017-01-18 18:25 ` Jerry DeLisle
  0 siblings, 1 reply; 3+ messages in thread
From: Andre Vehreschild @ 2017-01-18 17:02 UTC (permalink / raw)
  To: GCC-Patches-ML, GCC-Fortran-ML

[-- Attachment #1: Type: text/plain, Size: 391 bytes --]

Hi all,

during discussing some other functionality in the caf-library, it occurred to
me that gfortran is adding a caf_sync_all()-call when allocating only
allocatable or pointer components of derived typed coarrays. The attached patch
fixes the behavior.

Bootstrapped and regtests ok on x86_64-linux/f25. Ok for trunk?

Regards,
	Andre
-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

[-- Attachment #2: caf_alloc_sync_v1.clog --]
[-- Type: text/plain, Size: 448 bytes --]

gcc/testsuite/ChangeLog:

2017-01-18  Andre Vehreschild  <vehre@gcc.gnu.org>

	* gfortran.dg/coarray_alloc_with_implicit_sync_2.f90: New test.


gcc/fortran/ChangeLog:

2017-01-18  Andre Vehreschild  <vehre@gcc.gnu.org>

	* primary.c (caf_variable_attr): Improve figuring whether the current
	component is the last one refed.
	* trans-stmt.c (gfc_trans_allocate): Do not generate sync_all calls
	when allocating pointer or allocatable components.


[-- Attachment #3: caf_alloc_sync_v1.patch --]
[-- Type: text/x-patch, Size: 4814 bytes --]

diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c
index d62f6bb1..02e6dc1 100644
--- a/gcc/fortran/primary.c
+++ b/gcc/fortran/primary.c
@@ -2449,7 +2449,7 @@ caf_variable_attr (gfc_expr *expr, bool in_allocate, bool *refs_comp)
   gfc_clear_attr (&attr);
 
   if (refs_comp)
-    *refs_comp = 0;
+    *refs_comp = false;
 
   if (sym->ts.type == BT_CLASS && sym->attr.class_ok)
     {
@@ -2527,8 +2527,10 @@ caf_variable_attr (gfc_expr *expr, bool in_allocate, bool *refs_comp)
 	    allocatable = comp->attr.allocatable;
 	  }
 
-	if (refs_comp && strcmp (comp->name, "_data") != 0)
-	  *refs_comp = 1;
+	if (refs_comp && strcmp (comp->name, "_data") != 0
+	    && (ref->next == NULL
+		|| (ref->next->type == REF_ARRAY && ref->next->next == NULL)))
+	  *refs_comp = true;
 
 	if (pointer || attr.proc_pointer)
 	  target = 1;
diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c
index 8560087..63f3304 100644
--- a/gcc/fortran/trans-stmt.c
+++ b/gcc/fortran/trans-stmt.c
@@ -5506,8 +5506,10 @@ gfc_trans_allocate (gfc_code * code)
   stmtblock_t block;
   stmtblock_t post;
   tree nelems;
-  bool upoly_expr, tmp_expr3_len_flag = false, al_len_needs_set, is_coarray ;
+  bool upoly_expr, tmp_expr3_len_flag = false, al_len_needs_set, is_coarray;
+  bool needs_caf_sync, caf_refs_comp;
   gfc_symtree *newsym = NULL;
+  symbol_attribute caf_attr;
 
   if (!code->ext.alloc.list)
     return NULL_TREE;
@@ -5516,7 +5518,7 @@ gfc_trans_allocate (gfc_code * code)
   expr3 = expr3_vptr = expr3_len = expr3_esize = NULL_TREE;
   label_errmsg = label_finish = errmsg = errlen = NULL_TREE;
   e3_is = E3_UNSET;
-  is_coarray = false;
+  is_coarray = needs_caf_sync = false;
 
   gfc_init_block (&block);
   gfc_init_block (&post);
@@ -6087,16 +6089,20 @@ gfc_trans_allocate (gfc_code * code)
 	    /* Handle size computation of the type declared to alloc.  */
 	    memsz = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (se.expr)));
 
-	  if (gfc_caf_attr (expr).codimension
-	      && flag_coarray == GFC_FCOARRAY_LIB)
+	  /* Store the caf-attributes for latter use.  */
+	  if (flag_coarray == GFC_FCOARRAY_LIB
+	      && (caf_attr = gfc_caf_attr (expr, true, &caf_refs_comp))
+		 .codimension)
 	    {
 	      /* Scalar allocatable components in coarray'ed derived types make
 		 it here and are treated now.  */
 	      tree caf_decl, token;
 	      gfc_se caf_se;
 
-	      /* Set flag, to add synchronize after the allocate.  */
 	      is_coarray = true;
+	      /* Set flag, to add synchronize after the allocate.  */
+	      needs_caf_sync = needs_caf_sync
+		  || caf_attr.coarray_comp || !caf_refs_comp;
 
 	      gfc_init_se (&caf_se, NULL);
 
@@ -6121,8 +6127,14 @@ gfc_trans_allocate (gfc_code * code)
 	{
 	  /* Allocating coarrays needs a sync after the allocate executed.
 	     Set the flag to add the sync after all objects are allocated.  */
-	  is_coarray = is_coarray || (gfc_caf_attr (expr).codimension
-				      && flag_coarray == GFC_FCOARRAY_LIB);
+	  if (flag_coarray == GFC_FCOARRAY_LIB
+	      && (caf_attr = gfc_caf_attr (expr, true, &caf_refs_comp))
+		 .codimension)
+	    {
+	      is_coarray = true;
+	      needs_caf_sync = needs_caf_sync
+		  || caf_attr.coarray_comp || !caf_refs_comp;
+	    }
 
 	  if (expr->ts.type == BT_CHARACTER && al_len != NULL_TREE
 	      && expr3_len != NULL_TREE)
@@ -6401,7 +6413,7 @@ gfc_trans_allocate (gfc_code * code)
       gfc_add_modify (&block, se.expr, tmp);
     }
 
-  if (is_coarray && flag_coarray == GFC_FCOARRAY_LIB)
+  if (needs_caf_sync)
     {
       /* Add a sync all after the allocation has been executed.  */
       tmp = build_call_expr_loc (input_location, gfor_fndecl_caf_sync_all,
diff --git a/gcc/testsuite/gfortran.dg/coarray_alloc_with_implicit_sync_2.f90 b/gcc/testsuite/gfortran.dg/coarray_alloc_with_implicit_sync_2.f90
new file mode 100644
index 0000000..967da81
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray_alloc_with_implicit_sync_2.f90
@@ -0,0 +1,30 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=lib -fdump-tree-original" }
+! 
+! Test that the compiler generates sync_all statements only at the required
+! locations. This program is not supposed to run (allocating already alloced).
+
+program test_alloc_sync
+
+  type :: T
+    integer, allocatable :: i
+  end type T
+  type :: T2
+    type(T), allocatable :: o[:]
+  end type T2
+
+  integer, allocatable :: caf[:]
+  type (T) :: obj[*]
+  type (T2) :: cafcomp
+
+  allocate(caf[*])             ! implicit sync_all
+  allocate(obj%i)              ! asynchronous
+  allocate(cafcomp%o[*])       ! sync
+  allocate(cafcomp%o%i)        ! async
+
+  allocate(obj%i, cafcomp%o%i) ! async
+  allocate(caf[*], obj%i, cafcomp%o%i) ! sync
+
+end program test_alloc_sync
+
+! { dg-final { scan-dump-tree-times "caf_sync_all" 3 "original" } }

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH, Fortran, sync_alloc, v1] [Coarray] Do not add sync all call when allocating allocatable/pointer component
  2017-01-18 17:02 [PATCH, Fortran, sync_alloc, v1] [Coarray] Do not add sync all call when allocating allocatable/pointer component Andre Vehreschild
@ 2017-01-18 18:25 ` Jerry DeLisle
  2017-01-18 19:04   ` Andre Vehreschild
  0 siblings, 1 reply; 3+ messages in thread
From: Jerry DeLisle @ 2017-01-18 18:25 UTC (permalink / raw)
  To: Andre Vehreschild, GCC-Patches-ML, GCC-Fortran-ML

On 01/18/2017 08:54 AM, Andre Vehreschild wrote:
> Hi all,
>
> during discussing some other functionality in the caf-library, it occurred to
> me that gfortran is adding a caf_sync_all()-call when allocating only
> allocatable or pointer components of derived typed coarrays. The attached patch
> fixes the behavior.
>
> Bootstrapped and regtests ok on x86_64-linux/f25. Ok for trunk?
>
> Regards,
> 	Andre
>

This looks OK, and thanks for the work.

Jerry

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH, Fortran, sync_alloc, v1] [Coarray] Do not add sync all call when allocating allocatable/pointer component
  2017-01-18 18:25 ` Jerry DeLisle
@ 2017-01-18 19:04   ` Andre Vehreschild
  0 siblings, 0 replies; 3+ messages in thread
From: Andre Vehreschild @ 2017-01-18 19:04 UTC (permalink / raw)
  To: Jerry DeLisle; +Cc: GCC-Patches-ML, GCC-Fortran-ML

[-- Attachment #1: Type: text/plain, Size: 793 bytes --]

Hi Jerry,

and also for this many thanks. Committed as r244590.

Regards,
	Andre

PS: Hopefully this mail is not declared SPAM by the mail-host like the last one.


On Wed, 18 Jan 2017 10:13:10 -0800
Jerry DeLisle <jvdelisle@charter.net> wrote:

> On 01/18/2017 08:54 AM, Andre Vehreschild wrote:
> > Hi all,
> >
> > during discussing some other functionality in the caf-library, it occurred
> > to me that gfortran is adding a caf_sync_all()-call when allocating only
> > allocatable or pointer components of derived typed coarrays. The attached
> > patch fixes the behavior.
> >
> > Bootstrapped and regtests ok on x86_64-linux/f25. Ok for trunk?
> >
> > Regards,
> > 	Andre
> >  
> 
> This looks OK, and thanks for the work.
> 
> Jerry


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

[-- Attachment #2: submit.diff --]
[-- Type: text/x-patch, Size: 5733 bytes --]

Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(Revision 244589)
+++ gcc/fortran/ChangeLog	(Arbeitskopie)
@@ -1,5 +1,12 @@
 2017-01-18  Andre Vehreschild  <vehre@gcc.gnu.org>
 
+	* primary.c (caf_variable_attr): Improve figuring whether the current
+	component is the last one refed.
+	* trans-stmt.c (gfc_trans_allocate): Do not generate sync_all calls
+	when allocating pointer or allocatable components.
+
+2017-01-18  Andre Vehreschild  <vehre@gcc.gnu.org>
+
 	* gfortran.texi: Add missing parameters to caf-API functions.  Correct
 	typos and clarify some descriptions.
 
Index: gcc/fortran/primary.c
===================================================================
--- gcc/fortran/primary.c	(Revision 244586)
+++ gcc/fortran/primary.c	(Arbeitskopie)
@@ -2449,7 +2449,7 @@
   gfc_clear_attr (&attr);
 
   if (refs_comp)
-    *refs_comp = 0;
+    *refs_comp = false;
 
   if (sym->ts.type == BT_CLASS && sym->attr.class_ok)
     {
@@ -2527,8 +2527,10 @@
 	    allocatable = comp->attr.allocatable;
 	  }
 
-	if (refs_comp && strcmp (comp->name, "_data") != 0)
-	  *refs_comp = 1;
+	if (refs_comp && strcmp (comp->name, "_data") != 0
+	    && (ref->next == NULL
+		|| (ref->next->type == REF_ARRAY && ref->next->next == NULL)))
+	  *refs_comp = true;
 
 	if (pointer || attr.proc_pointer)
 	  target = 1;
Index: gcc/fortran/trans-stmt.c
===================================================================
--- gcc/fortran/trans-stmt.c	(Revision 244586)
+++ gcc/fortran/trans-stmt.c	(Arbeitskopie)
@@ -5506,8 +5506,10 @@
   stmtblock_t block;
   stmtblock_t post;
   tree nelems;
-  bool upoly_expr, tmp_expr3_len_flag = false, al_len_needs_set, is_coarray ;
+  bool upoly_expr, tmp_expr3_len_flag = false, al_len_needs_set, is_coarray;
+  bool needs_caf_sync, caf_refs_comp;
   gfc_symtree *newsym = NULL;
+  symbol_attribute caf_attr;
 
   if (!code->ext.alloc.list)
     return NULL_TREE;
@@ -5516,7 +5518,7 @@
   expr3 = expr3_vptr = expr3_len = expr3_esize = NULL_TREE;
   label_errmsg = label_finish = errmsg = errlen = NULL_TREE;
   e3_is = E3_UNSET;
-  is_coarray = false;
+  is_coarray = needs_caf_sync = false;
 
   gfc_init_block (&block);
   gfc_init_block (&post);
@@ -6087,8 +6089,10 @@
 	    /* Handle size computation of the type declared to alloc.  */
 	    memsz = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (se.expr)));
 
-	  if (gfc_caf_attr (expr).codimension
-	      && flag_coarray == GFC_FCOARRAY_LIB)
+	  /* Store the caf-attributes for latter use.  */
+	  if (flag_coarray == GFC_FCOARRAY_LIB
+	      && (caf_attr = gfc_caf_attr (expr, true, &caf_refs_comp))
+		 .codimension)
 	    {
 	      /* Scalar allocatable components in coarray'ed derived types make
 		 it here and are treated now.  */
@@ -6095,8 +6099,10 @@
 	      tree caf_decl, token;
 	      gfc_se caf_se;
 
+	      is_coarray = true;
 	      /* Set flag, to add synchronize after the allocate.  */
-	      is_coarray = true;
+	      needs_caf_sync = needs_caf_sync
+		  || caf_attr.coarray_comp || !caf_refs_comp;
 
 	      gfc_init_se (&caf_se, NULL);
 
@@ -6121,8 +6127,14 @@
 	{
 	  /* Allocating coarrays needs a sync after the allocate executed.
 	     Set the flag to add the sync after all objects are allocated.  */
-	  is_coarray = is_coarray || (gfc_caf_attr (expr).codimension
-				      && flag_coarray == GFC_FCOARRAY_LIB);
+	  if (flag_coarray == GFC_FCOARRAY_LIB
+	      && (caf_attr = gfc_caf_attr (expr, true, &caf_refs_comp))
+		 .codimension)
+	    {
+	      is_coarray = true;
+	      needs_caf_sync = needs_caf_sync
+		  || caf_attr.coarray_comp || !caf_refs_comp;
+	    }
 
 	  if (expr->ts.type == BT_CHARACTER && al_len != NULL_TREE
 	      && expr3_len != NULL_TREE)
@@ -6401,7 +6413,7 @@
       gfc_add_modify (&block, se.expr, tmp);
     }
 
-  if (is_coarray && flag_coarray == GFC_FCOARRAY_LIB)
+  if (needs_caf_sync)
     {
       /* Add a sync all after the allocation has been executed.  */
       tmp = build_call_expr_loc (input_location, gfor_fndecl_caf_sync_all,
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(Revision 244587)
+++ gcc/testsuite/ChangeLog	(Arbeitskopie)
@@ -1,5 +1,9 @@
-2017-01-17  Andre Vehreschild  <vehre@gcc.gnu.org>
+2017-01-18  Andre Vehreschild  <vehre@gcc.gnu.org>
 
+	* gfortran.dg/coarray_alloc_with_implicit_sync_2.f90: New test.
+
+2017-01-18  Andre Vehreschild  <vehre@gcc.gnu.org>
+
 	PR fortran/70696
 	* gfortran.dg/coarray_event_1.f08: New test.
 
Index: gcc/testsuite/gfortran.dg/coarray_alloc_with_implicit_sync_2.f90
===================================================================
--- gcc/testsuite/gfortran.dg/coarray_alloc_with_implicit_sync_2.f90	(nicht existent)
+++ gcc/testsuite/gfortran.dg/coarray_alloc_with_implicit_sync_2.f90	(Arbeitskopie)
@@ -0,0 +1,30 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=lib -fdump-tree-original" }
+! 
+! Test that the compiler generates sync_all statements only at the required
+! locations. This program is not supposed to run (allocating already alloced).
+
+program test_alloc_sync
+
+  type :: T
+    integer, allocatable :: i
+  end type T
+  type :: T2
+    type(T), allocatable :: o[:]
+  end type T2
+
+  integer, allocatable :: caf[:]
+  type (T) :: obj[*]
+  type (T2) :: cafcomp
+
+  allocate(caf[*])             ! implicit sync_all
+  allocate(obj%i)              ! asynchronous
+  allocate(cafcomp%o[*])       ! sync
+  allocate(cafcomp%o%i)        ! async
+
+  allocate(obj%i, cafcomp%o%i) ! async
+  allocate(caf[*], obj%i, cafcomp%o%i) ! sync
+
+end program test_alloc_sync
+
+! { dg-final { scan-tree-dump-times "caf_sync_all" 3 "original" } }

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-01-18 19:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-18 17:02 [PATCH, Fortran, sync_alloc, v1] [Coarray] Do not add sync all call when allocating allocatable/pointer component Andre Vehreschild
2017-01-18 18:25 ` Jerry DeLisle
2017-01-18 19:04   ` Andre Vehreschild

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).