public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, fortran] [10/21] Remove coarray support in the scalarizer: Factor bound evaluation
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
  2011-09-15 23:09 ` [Patch, fortran] [01/21] Remove coarray support in the scalarizer: Remove is_coarray Mikael Morin
  2011-09-15 23:09 ` [Patch, fortran] [02/21] Remove coarray support in the scalarizer: Move coarray resolution code around Mikael Morin
@ 2011-09-15 23:09 ` Mikael Morin
  2011-09-15 23:10 ` [Patch, fortran] [08/21] Remove coarray support in the scalarizer: Factor array ref references Mikael Morin
                   ` (19 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Mikael Morin @ 2011-09-15 23:09 UTC (permalink / raw)
  To: gfortran, GCC patches

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

In the following patches, we are going to use gfc_conv_section_startstride
to calculate cobounds. The problem is that we don't want to calculate the last
ucobound. As a result, we should have a way to evaluate the lower bound
and the upper bound independently.
This patch moves bound evaluation to a function of its own, and use that new
function in gfc_conv_section_startstride.

OK?

PS: I could have kept the current flag trick to separate lower vs upper bound
evaluation, but besides the fact that I don't like flags in general, having
coarray in their name finished to convince me that they deserved to die. ;-)


[-- Attachment #2: no_coarray_in_scalarizer-10.CL --]
[-- Type: text/plain, Size: 182 bytes --]

2011-09-14  Mikael Morin  <mikael.morin@sfr.fr>

	* trans-array.c (gfc_conv_section_startstride): Move code to
	evaluate_bound.  Use evaluate_bound.
	(evaluate_bound): New function.

[-- Attachment #3: no_coarray_in_scalarizer-10.diff --]
[-- Type: text/x-diff, Size: 3408 bytes --]

diff --git a/trans-array.c b/trans-array.c
index 7f44514..ee5761b 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -3175,14 +3175,46 @@ gfc_trans_scalarized_loop_boundary (gfc_loopinfo * loop, stmtblock_t * body)
 }
 
 
+/* Precalculate (either lower or upper) bound of an array section.
+     BLOCK: Block in which the (pre)calculation code will go.
+     BOUNDS[DIM]: Where the bound value will be stored once evaluated.
+     VALUES[DIM]: Specified bound (NULL <=> unspecified).
+     DESC: Array descriptor from which the bound will be picked if unspecified
+       (either lower or upper bound according to LBOUND).  */
+
+static void
+evaluate_bound (stmtblock_t *block, tree *bounds, gfc_expr ** values,
+		tree desc, int dim, bool lbound)
+{
+  gfc_se se;
+  gfc_expr * input_val = values[dim];
+  tree *output = &bounds[dim];
+
+
+  if (input_val)
+    {
+      /* Specified section bound.  */
+      gfc_init_se (&se, NULL);
+      gfc_conv_expr_type (&se, input_val, gfc_array_index_type);
+      gfc_add_block_to_block (block, &se.pre);
+      *output = se.expr;
+    }
+  else
+    {
+      /* No specific bound specified so use the bound of the array.  */
+      *output = lbound ? gfc_conv_array_lbound (desc, dim) :
+			 gfc_conv_array_ubound (desc, dim);
+    }
+  *output = gfc_evaluate_now (*output, block);
+}
+
+
 /* Calculate the lower bound of an array section.  */
 
 static void
 gfc_conv_section_startstride (gfc_loopinfo * loop, gfc_ss * ss, int dim,
 			      bool coarray, bool coarray_last)
 {
-  gfc_expr *start;
-  gfc_expr *end;
   gfc_expr *stride = NULL;
   tree desc;
   gfc_se se;
@@ -3207,48 +3239,18 @@ gfc_conv_section_startstride (gfc_loopinfo * loop, gfc_ss * ss, int dim,
   gcc_assert (ar->dimen_type[dim] == DIMEN_RANGE
 	      || ar->dimen_type[dim] == DIMEN_THIS_IMAGE);
   desc = info->descriptor;
-  start = ar->start[dim];
-  end = ar->end[dim];
   if (!coarray)
     stride = ar->stride[dim];
 
   /* Calculate the start of the range.  For vector subscripts this will
      be the range of the vector.  */
-  if (start)
-    {
-      /* Specified section start.  */
-      gfc_init_se (&se, NULL);
-      gfc_conv_expr_type (&se, start, gfc_array_index_type);
-      gfc_add_block_to_block (&loop->pre, &se.pre);
-      info->start[dim] = se.expr;
-    }
-  else
-    {
-      /* No lower bound specified so use the bound of the array.  */
-      info->start[dim] = gfc_conv_array_lbound (desc, dim);
-    }
-  info->start[dim] = gfc_evaluate_now (info->start[dim], &loop->pre);
+  evaluate_bound (&loop->pre, info->start, ar->start, desc, dim, true);
 
   /* Similarly calculate the end.  Although this is not used in the
      scalarizer, it is needed when checking bounds and where the end
      is an expression with side-effects.  */
   if (!coarray_last)
-    {
-      if (end)
-	{
-	  /* Specified section start.  */
-	  gfc_init_se (&se, NULL);
-	  gfc_conv_expr_type (&se, end, gfc_array_index_type);
-	  gfc_add_block_to_block (&loop->pre, &se.pre);
-	  info->end[dim] = se.expr;
-	}
-      else
-	{
-	  /* No upper bound specified so use the bound of the array.  */
-	  info->end[dim] = gfc_conv_array_ubound (desc, dim);
-	}
-      info->end[dim] = gfc_evaluate_now (info->end[dim], &loop->pre);
-    }
+    evaluate_bound (&loop->pre, info->end, ar->end, desc, dim, false);
 
   /* Calculate the stride.  */
   if (!coarray && stride == NULL)

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

* [Patch, fortran] [00/21] Remove coarray support in the scalarizer
@ 2011-09-15 23:09 Mikael Morin
  2011-09-15 23:09 ` [Patch, fortran] [01/21] Remove coarray support in the scalarizer: Remove is_coarray Mikael Morin
                   ` (22 more replies)
  0 siblings, 23 replies; 26+ messages in thread
From: Mikael Morin @ 2011-09-15 23:09 UTC (permalink / raw)
  To: gfortran, GCC patches

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

Hello,

the scalarizer is there to generate loops for assignments over more than
one element. Tobias extended it at various places to support coarrays,
but this should not be necessary as coarrays in assignments either refer
to the array present on the local image or to the one on the remote image
(in which case a local temporary is created). In either case the coarray
is seen as a normal array by the assignment code, which makes the point
of having coarray-specific handling in the scalarizer moot.

In fact the reason for the presence of coarrays in the scalarizer is that
gfc_conv_expr_descriptor uses the scalarizer to setup array (co)bounds.

This patch serie removes the coarray-specific code in the scalarizer, and
replaces it with some additional cobound setup code in gfc_conv_expr_descriptor.
It is supposed to make the code easier to grasp by having a scalarizer free of
coarray stuff (it is complicated enough without it), and by having cobound
setup code gathered in a single place.
The downside is that it makes gfc_conv_expr_descriptor even bigger than it was
already.

Every patch has been tested by incremental bootstrap and running the fortran
testsuite with RUNTESTLAGS=caf.exp and RUNTESTFLAGS="dg.exp=*coarray*".
The last one has also passed a full fortran regression test.

OK for trunk?

Mikael


patchset layout:
 - patches 1..4: 
	Preliminary cleanups.
	Those are quite independant on the rest.
	Patch 4 is optional.

 - patches 5..13: 
	Step by step move from scalarizer-provided cobounds setup code
	to explicit specific code in gfc_conv_expr_descriptor.
	Patch 6 is a request for explaination and is not intended for check-in.

 - patch 14:
	Fixes a regression.

 - patches 15..21:
	This is the point of all the rest: remove coarray-specific code in the
	scalarizer.

 check.c           |   34 +-------
 expr.c            |    6 ++
 resolve.c         |   35 ++++++--
 trans-array.c     |  248 +++++++++++++++++++++++------------------------------
 trans-expr.c      |    6 +-
 trans-intrinsic.c |   52 +++++++-----
 trans.h           |    8 +-
 7 files changed, 180 insertions(+), 209 deletions(-)


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

* [Patch, fortran] [01/21] Remove coarray support in the scalarizer: Remove is_coarray
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
@ 2011-09-15 23:09 ` Mikael Morin
  2011-09-15 23:09 ` [Patch, fortran] [02/21] Remove coarray support in the scalarizer: Move coarray resolution code around Mikael Morin
                   ` (21 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Mikael Morin @ 2011-09-15 23:09 UTC (permalink / raw)
  To: gfortran, GCC patches

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

There are two functions checking that an expression is a coarray.
This keeps the public one (which seems to be the more complete) and removes
the other one.

OK?

PS: As this changes a rejects-valid into an ice-on-valid (see PR 50420
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50420), it can be delayed if
preferred; unfortunately, patch 14 fails without this one.


[-- Attachment #2: no_coarray_in_scalarizer-1.CL --]
[-- Type: text/plain, Size: 120 bytes --]

2011-09-14  Mikael Morin  <mikael.morin@sfr.fr>

	* check.c (is_coarray): Remove.
	(coarray_check): Use gfc_is_coarray.

[-- Attachment #3: no_coarray_in_scalarizer-1.diff --]
[-- Type: text/x-diff, Size: 1157 bytes --]

diff --git a/check.c b/check.c
index 3d4f4c8..81f7b30 100644
--- a/check.c
+++ b/check.c
@@ -203,42 +203,10 @@ double_check (gfc_expr *d, int n)
 }
 
 
-/* Check whether an expression is a coarray (without array designator).  */
-
-static bool
-is_coarray (gfc_expr *e)
-{
-  bool coarray = false;
-  gfc_ref *ref;
-
-  if (e->expr_type != EXPR_VARIABLE)
-    return false;
-
-  coarray = e->symtree->n.sym->attr.codimension;
-
-  for (ref = e->ref; ref; ref = ref->next)
-    {
-      if (ref->type == REF_COMPONENT)
-	coarray = ref->u.c.component->attr.codimension;
-      else if (ref->type != REF_ARRAY || ref->u.ar.dimen != 0)
-	coarray = false;
-      else if (ref->type == REF_ARRAY && ref->u.ar.codimen != 0) 
-	{
-	  int n;
-	  for (n = 0; n < ref->u.ar.codimen; n++)
-	    if (ref->u.ar.dimen_type[n] != DIMEN_THIS_IMAGE)
-	      coarray = false;
-	}
-    }
-
-  return coarray;
-}
-
-
 static gfc_try
 coarray_check (gfc_expr *e, int n)
 {
-  if (!is_coarray (e))
+  if (!gfc_is_coarray (e))
     {
       gfc_error ("Expected coarray variable as '%s' argument to the %s "
                  "intrinsic at %L", gfc_current_intrinsic_arg[n]->name,

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

* [Patch, fortran] [02/21] Remove coarray support in the scalarizer: Move coarray resolution code around
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
  2011-09-15 23:09 ` [Patch, fortran] [01/21] Remove coarray support in the scalarizer: Remove is_coarray Mikael Morin
@ 2011-09-15 23:09 ` Mikael Morin
  2011-09-15 23:09 ` [Patch, fortran] [10/21] Remove coarray support in the scalarizer: Factor bound evaluation Mikael Morin
                   ` (20 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Mikael Morin @ 2011-09-15 23:09 UTC (permalink / raw)
  To: gfortran, GCC patches

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

compare_spec_to_ref, despite its name, has the side effect of writing to the
array ref it is supposed to check (in the coarray case). I found this very
surprising, hence this patch which moves the relevant code to
resolve_array_ref, just after the call to compare_spec_to_ref (so that the
code path is exactly the same).

OK?


[-- Attachment #2: no_coarray_in_scalarizer-2.CL --]
[-- Type: text/plain, Size: 158 bytes --]

2011-09-14  Mikael Morin  <mikael.morin@sfr.fr>

	* resolve.c (compare_spec_to_ref): Move coarray ref initialization
	code...
	(resolve_array_ref): ... here.

[-- Attachment #3: no_coarray_in_scalarizer-2.diff --]
[-- Type: text/x-diff, Size: 806 bytes --]

diff --git a/resolve.c b/resolve.c
index b038402..4c991c8 100644
--- a/resolve.c
+++ b/resolve.c
@@ -4389,14 +4389,6 @@ compare_spec_to_ref (gfc_array_ref *ar)
 	  return FAILURE;
       }
 
-  if (as->corank && ar->codimen == 0)
-    {
-      int n;
-      ar->codimen = as->corank;
-      for (n = ar->dimen; n < ar->dimen + ar->codimen; n++)
-	ar->dimen_type[n] = DIMEN_THIS_IMAGE;
-    }
-
   return SUCCESS;
 }
 
@@ -4665,6 +4657,14 @@ resolve_array_ref (gfc_array_ref *ar)
   if (!ar->as->cray_pointee && compare_spec_to_ref (ar) == FAILURE)
     return FAILURE;
 
+  if (ar->as->corank && ar->codimen == 0)
+    {
+      int n;
+      ar->codimen = ar->as->corank;
+      for (n = ar->dimen; n < ar->dimen + ar->codimen; n++)
+	ar->dimen_type[n] = DIMEN_THIS_IMAGE;
+    }
+
   return SUCCESS;
 }
 

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

* [Patch, fortran] [20/21] Remove coarray support in the scalarizer: Remove coarray argument
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
                   ` (13 preceding siblings ...)
  2011-09-15 23:10 ` [Patch, fortran] [06/21] Remove coarray support in the scalarizer: Request coarray for an actual arg associed with a coarray dummy Mikael Morin
@ 2011-09-15 23:10 ` Mikael Morin
  2011-09-15 23:10 ` [Patch, fortran] [04/21] Remove coarray support in the scalarizer: Fix gfc_get_corank Mikael Morin
                   ` (7 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Mikael Morin @ 2011-09-15 23:10 UTC (permalink / raw)
  To: gfortran, GCC patches

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

This patch, like the previous one, removes one argument from
gfc_conv_section_startstride.
We have to be more careful here as the two callers use different values
for the flag.
gfc_conv_ss_startstride calls gfc_conv_section_startstride with coarray=false.
Thus removing every !coarray condition should not be worrying.

gfc_conv_expr_descriptor on the other hand calls it with coarray=true; we have
to be more careful.

The first "if (!coarray)" is under an if (ar->dimen_type[dim] == DIMEN_VECTOR),
irrelevant for coarrays. We add an assertion that 
ar->dimen_type[dim] == DIMEN_THIS_IMAGE in gfc_conv_expr_descriptor and can
remove that condition.

The second one protects the stride initialization. As stride is
a local variable, we can remove that condition safely.
 
The third and four ones protect initialisation of info->stride[dim].
For codimensions, the stride is ignored, so we can remove that one two.
To make sure that we don't add unnecessary (and possibly costly) stride
evaluation code, that is the (stride == NULL) branch is taken, we add an
assertion in gfc_conv_expr_descriptor to check that ar->stride[dim] == NULL.
Then we can remove the flag.

OK?

[-- Attachment #2: no_coarray_in_scalarizer-20.CL --]
[-- Type: text/plain, Size: 295 bytes --]

2011-09-14  Mikael Morin  <mikael.morin@sfr.fr>

	* trans-array.c (gfc_conv_section_startstride): Remove coarray argument.
	Remove conditions on coarray.
	(gfc_conv_ss_startstride): Update call to gfc_conv_section_startstride.
	(gfc_conv_expr_descriptor): Ditto. Add assertions before the call.

[-- Attachment #3: no_coarray_in_scalarizer-20.diff --]
[-- Type: text/x-diff, Size: 2647 bytes --]

diff --git a/trans-array.c b/trans-array.c
index 95ebf6c..a034886 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -3200,8 +3200,7 @@ evaluate_bound (stmtblock_t *block, tree *bounds, gfc_expr ** values,
 /* Calculate the lower bound of an array section.  */
 
 static void
-gfc_conv_section_startstride (gfc_loopinfo * loop, gfc_ss * ss, int dim,
-			      bool coarray)
+gfc_conv_section_startstride (gfc_loopinfo * loop, gfc_ss * ss, int dim)
 {
   gfc_expr *stride = NULL;
   tree desc;
@@ -3219,16 +3218,14 @@ gfc_conv_section_startstride (gfc_loopinfo * loop, gfc_ss * ss, int dim,
       /* We use a zero-based index to access the vector.  */
       info->start[dim] = gfc_index_zero_node;
       info->end[dim] = NULL;
-      if (!coarray)
-	info->stride[dim] = gfc_index_one_node;
+      info->stride[dim] = gfc_index_one_node;
       return;
     }
 
   gcc_assert (ar->dimen_type[dim] == DIMEN_RANGE
 	      || ar->dimen_type[dim] == DIMEN_THIS_IMAGE);
   desc = info->descriptor;
-  if (!coarray)
-    stride = ar->stride[dim];
+  stride = ar->stride[dim];
 
   /* Calculate the start of the range.  For vector subscripts this will
      be the range of the vector.  */
@@ -3240,9 +3237,9 @@ gfc_conv_section_startstride (gfc_loopinfo * loop, gfc_ss * ss, int dim,
   evaluate_bound (&loop->pre, info->end, ar->end, desc, dim, false);
 
   /* Calculate the stride.  */
-  if (!coarray && stride == NULL)
+  if (stride == NULL)
     info->stride[dim] = gfc_index_one_node;
-  else if (!coarray)
+  else
     {
       gfc_init_se (&se, NULL);
       gfc_conv_expr_type (&se, stride, gfc_array_index_type);
@@ -3319,8 +3316,7 @@ done:
 	  gfc_conv_ss_descriptor (&loop->pre, ss, !loop->array_parameter);
 
 	  for (n = 0; n < ss->data.info.dimen; n++)
-	    gfc_conv_section_startstride (loop, ss, ss->data.info.dim[n],
-					  false);
+	    gfc_conv_section_startstride (loop, ss, ss->data.info.dim[n]);
 	  break;
 
 	case GFC_SS_INTRINSIC:
@@ -5975,7 +5971,14 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss)
 	  for (n = ss->data.info.dimen; n < ss->data.info.dimen + codim - 1;
 	       n++)
 	    {
-	      gfc_conv_section_startstride (&loop, ss, n, true);
+	      /* Make sure we are not lost somehow.  */
+	      gcc_assert (info->ref->u.ar.dimen_type[n] == DIMEN_THIS_IMAGE);
+
+	      /* Make sure the call to gfc_conv_section_startstride won't 
+	         generate unnecessary code to calculate stride.  */
+	      gcc_assert (info->ref->u.ar.stride[n] == NULL);
+
+	      gfc_conv_section_startstride (&loop, ss, n);
 	      loop.from[n] = info->start[n];
 	      loop.to[n]   = info->end[n];
 	    }

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

* [Patch, fortran] [03/21] Remove coarray support in the scalarizer: Simplify coarray descriptor setup.
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
                   ` (5 preceding siblings ...)
  2011-09-15 23:10 ` [Patch, fortran] [14/21] Remove coarray support in the scalarizer: Fix full array dimension type Mikael Morin
@ 2011-09-15 23:10 ` Mikael Morin
  2011-09-15 23:10 ` [Patch, fortran] [19/21] Remove coarray support in the scalarizer: Remove coarray_last argument Mikael Morin
                   ` (15 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Mikael Morin @ 2011-09-15 23:10 UTC (permalink / raw)
  To: gfortran, GCC patches

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

In gfc_conv_expr_descriptor, the code setting the descriptor cobounds (copied
from the non-coarray case) has unnecessary stuff irrelevant to coarrays:
as codimensions can't be transposed, the condition dim[n] == n is guaranteed
to hold true for the codimensions.
This patch removes unnecessary code based on that assumption.

OK?


[-- Attachment #2: no_coarray_in_scalarizer-3.CL --]
[-- Type: text/plain, Size: 136 bytes --]

2011-09-14  Mikael Morin  <mikael.morin@sfr.fr>

	* trans-array.c (gfc_conv_expr_descriptor): Simplify coarray
	descriptor setup code. 

[-- Attachment #3: no_coarray_in_scalarizer-3.diff --]
[-- Type: text/x-diff, Size: 940 bytes --]

diff --git a/trans-array.c b/trans-array.c
index 37cdeb5..88849ef 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -6140,22 +6140,13 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss)
 
       for (n = ndim; n < ndim + codim; n++)
 	{
-	  /* look for the corresponding scalarizer dimension: dim.  */
-	  for (dim = 0; dim < ndim + codim; dim++)
-	    if (info->dim[dim] == n)
-	      break;
-
-	  /* loop exited early: the DIM being looked for has been found.  */
-	  gcc_assert (dim < ndim + codim);
-
-	  from = loop.from[dim];
-	  to = loop.to[dim];
+	  from = loop.from[n];
+	  to = loop.to[n];
 	  gfc_conv_descriptor_lbound_set (&loop.pre, parm,
-					  gfc_rank_cst[dim], from);
+					  gfc_rank_cst[n], from);
 	  if (n < ndim + codim - 1)
 	    gfc_conv_descriptor_ubound_set (&loop.pre, parm,
-					    gfc_rank_cst[dim], to);
-	  dim++;
+					    gfc_rank_cst[n], to);
 	}
 
       if (se->data_not_needed)

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

* [Patch, fortran] [21/21] Remove coarray support in the scalarizer: Final cleanup
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
                   ` (7 preceding siblings ...)
  2011-09-15 23:10 ` [Patch, fortran] [19/21] Remove coarray support in the scalarizer: Remove coarray_last argument Mikael Morin
@ 2011-09-15 23:10 ` Mikael Morin
  2011-09-15 23:10 ` [Patch, fortran] [16/21] Remove coarray support in the scalarizer: Remove gfc_loopinfo::codimen Mikael Morin
                   ` (13 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Mikael Morin @ 2011-09-15 23:10 UTC (permalink / raw)
  To: gfortran, GCC patches

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

This merges two identical switch cases. It didn't fit anywhere else, so here
it is, alone.

OK?


[-- Attachment #2: no_coarray_in_scalarizer-21.CL --]
[-- Type: text/plain, Size: 117 bytes --]

2011-09-14  Mikael Morin  <mikael.morin@sfr.fr>

	* trans-array.c	(gfc_conv_ss_startstride): Merge two switch cases.

[-- Attachment #3: no_coarray_in_scalarizer-21.diff --]
[-- Type: text/x-diff, Size: 401 bytes --]

diff --git a/trans-array.c b/trans-array.c
index a034886..86eb6c8 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -3280,9 +3280,6 @@ gfc_conv_ss_startstride (gfc_loopinfo * loop)
 	    {
 	    case GFC_ISYM_LBOUND:
 	    case GFC_ISYM_UBOUND:
-	      loop->dimen = ss->data.info.dimen;
-	      goto done;
-
 	    case GFC_ISYM_LCOBOUND:
 	    case GFC_ISYM_UCOBOUND:
 	    case GFC_ISYM_THIS_IMAGE:

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

* [Patch, fortran] [16/21] Remove coarray support in the scalarizer: Remove gfc_loopinfo::codimen
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
                   ` (8 preceding siblings ...)
  2011-09-15 23:10 ` [Patch, fortran] [21/21] Remove coarray support in the scalarizer: Final cleanup Mikael Morin
@ 2011-09-15 23:10 ` Mikael Morin
  2011-09-15 23:10 ` [Patch, fortran] [13/21] Remove coarray support in the scalarizer: Add specific walk_coarray function Mikael Morin
                   ` (12 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Mikael Morin @ 2011-09-15 23:10 UTC (permalink / raw)
  To: gfortran, GCC patches

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

This removes the gfc_loopinfo::codimen field and the code associated with it.

OK?


[-- Attachment #2: no_coarray_in_scalarizer-16.CL --]
[-- Type: text/plain, Size: 560 bytes --]

2011-09-14  Mikael Morin  <mikael.morin@sfr.fr>

	* trans.h (gfc_loopinfo): Remove codimen field.
	* trans-array.c (gfc_set_vector_loop_bounds,
	gfc_trans_scalarizing_loops, gfc_conv_loop_setup): Update loop upper
	limit.
	* trans-array.c (gfc_set_loop_bounds_from_array_spec): 
	Ditto. Remove skip on last codimension.
	(gfc_start_scalarized_body): Update loop lower limit.
	(gfc_conv_ss_startstride): Don't set loop's codimen field.
	(gfc_conv_loop_setup): Remove unnecessary condition.
	(gfc_conv_expr_descriptor): Don't use loop's codimen field as corank.

[-- Attachment #3: no_coarray_in_scalarizer-16.diff --]
[-- Type: text/x-diff, Size: 4388 bytes --]

diff --git a/trans-array.c b/trans-array.c
index 9d4ef5a..0a9d281 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -641,7 +641,7 @@ gfc_set_loop_bounds_from_array_spec (gfc_interface_mapping * mapping,
   tree tmp;
 
   if (as && as->type == AS_EXPLICIT)
-    for (n = 0; n < se->loop->dimen + se->loop->codimen; n++)
+    for (n = 0; n < se->loop->dimen; n++)
       {
 	dim = se->ss->data.info.dim[n];
 	gcc_assert (dim < as->rank);
@@ -655,22 +655,18 @@ gfc_set_loop_bounds_from_array_spec (gfc_interface_mapping * mapping,
 	    gfc_add_block_to_block (&se->post, &tmpse.post);
 	    lower = fold_convert (gfc_array_index_type, tmpse.expr);
 
-	    if (se->loop->codimen == 0
-		|| n < se->loop->dimen + se->loop->codimen - 1)
-	      {
-		/* ...and the upper bound.  */
-		gfc_init_se (&tmpse, NULL);
-		gfc_apply_interface_mapping (mapping, &tmpse, as->upper[dim]);
-		gfc_add_block_to_block (&se->pre, &tmpse.pre);
-		gfc_add_block_to_block (&se->post, &tmpse.post);
-		upper = fold_convert (gfc_array_index_type, tmpse.expr);
-
-		/* Set the upper bound of the loop to UPPER - LOWER.  */
-		tmp = fold_build2_loc (input_location, MINUS_EXPR,
-				       gfc_array_index_type, upper, lower);
-		tmp = gfc_evaluate_now (tmp, &se->pre);
-		se->loop->to[n] = tmp;
-	      }
+	    /* ...and the upper bound.  */
+	    gfc_init_se (&tmpse, NULL);
+	    gfc_apply_interface_mapping (mapping, &tmpse, as->upper[dim]);
+	    gfc_add_block_to_block (&se->pre, &tmpse.pre);
+	    gfc_add_block_to_block (&se->post, &tmpse.post);
+	    upper = fold_convert (gfc_array_index_type, tmpse.expr);
+
+	    /* Set the upper bound of the loop to UPPER - LOWER.  */
+	    tmp = fold_build2_loc (input_location, MINUS_EXPR,
+				   gfc_array_index_type, upper, lower);
+	    tmp = gfc_evaluate_now (tmp, &se->pre);
+	    se->loop->to[n] = tmp;
 	  }
       }
 }
@@ -2116,7 +2112,7 @@ gfc_set_vector_loop_bounds (gfc_loopinfo * loop, gfc_ss_info * info)
   int n;
   int dim;
 
-  for (n = 0; n < loop->dimen + loop->codimen; n++)
+  for (n = 0; n < loop->dimen; n++)
     {
       dim = info->dim[n];
       if (info->ref->u.ar.dimen_type[dim] == DIMEN_VECTOR
@@ -2948,7 +2944,7 @@ gfc_start_scalarized_body (gfc_loopinfo * loop, stmtblock_t * pbody)
 
   gcc_assert (!loop->array_parameter);
 
-  for (dim = loop->dimen + loop->codimen - 1; dim >= 0; dim--)
+  for (dim = loop->dimen - 1; dim >= 0; dim--)
     {
       n = loop->order[dim];
 
@@ -3102,7 +3098,7 @@ gfc_trans_scalarizing_loops (gfc_loopinfo * loop, stmtblock_t * body)
 
   pblock = body;
   /* Generate the loops.  */
-  for (dim = 0; dim < loop->dimen + loop->codimen; dim++)
+  for (dim = 0; dim < loop->dimen; dim++)
     {
       n = loop->order[dim];
       gfc_trans_scalarized_loop_end (loop, n, pblock);
@@ -3288,7 +3284,6 @@ gfc_conv_ss_startstride (gfc_loopinfo * loop)
 	case GFC_SS_FUNCTION:
 	case GFC_SS_COMPONENT:
 	  loop->dimen = ss->data.info.dimen;
-	  loop->codimen = ss->data.info.codimen;
 	  goto done;
 
 	/* As usual, lbound and ubound are exceptions!.  */
@@ -3298,14 +3293,12 @@ gfc_conv_ss_startstride (gfc_loopinfo * loop)
 	    case GFC_ISYM_LBOUND:
 	    case GFC_ISYM_UBOUND:
 	      loop->dimen = ss->data.info.dimen;
-	      loop->codimen = 0;
 	      goto done;
 
 	    case GFC_ISYM_LCOBOUND:
 	    case GFC_ISYM_UCOBOUND:
 	    case GFC_ISYM_THIS_IMAGE:
 	      loop->dimen = ss->data.info.dimen;
-	      loop->codimen = ss->data.info.codimen;
 	      goto done;
 
 	    default:
@@ -3888,7 +3881,7 @@ gfc_conv_loop_setup (gfc_loopinfo * loop, locus * where)
   mpz_t i;
 
   mpz_init (i);
-  for (n = 0; n < loop->dimen + loop->codimen; n++)
+  for (n = 0; n < loop->dimen; n++)
     {
       loopspec[n] = NULL;
       dynamic[n] = false;
@@ -3997,7 +3990,7 @@ gfc_conv_loop_setup (gfc_loopinfo * loop, locus * where)
 
       /* Set the extents of this range.  */
       cshape = loopspec[n]->shape;
-      if (n < loop->dimen && cshape && INTEGER_CST_P (info->start[dim])
+      if (cshape && INTEGER_CST_P (info->start[dim])
 	  && INTEGER_CST_P (info->stride[dim]))
 	{
 	  loop->from[n] = info->start[dim];
diff --git a/trans.h b/trans.h
index 3404123..085334c 100644
--- a/trans.h
+++ b/trans.h
@@ -245,7 +245,7 @@ typedef struct gfc_loopinfo
   stmtblock_t pre;
   stmtblock_t post;
 
-  int dimen, codimen;
+  int dimen;
 
   /* All the SS involved with this loop.  */
   gfc_ss *ss;

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

* [Patch, fortran] [05/21] Remove coarray support in the scalarizer: Calculate codim earlier.
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
                   ` (11 preceding siblings ...)
  2011-09-15 23:10 ` [Patch, fortran] [07/21] Remove coarray support in the scalarizer: Use codim as argument gfc_get_array_type_bounds Mikael Morin
@ 2011-09-15 23:10 ` Mikael Morin
  2011-09-15 23:10 ` [Patch, fortran] [06/21] Remove coarray support in the scalarizer: Request coarray for an actual arg associed with a coarray dummy Mikael Morin
                   ` (9 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Mikael Morin @ 2011-09-15 23:10 UTC (permalink / raw)
  To: gfortran, GCC patches

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

In the next patches, we are going to evaluate cobounds out of the scalarizer.
This needs to be done before the call to gfc_get_array_type_bounds (which takes
[co]bounds as input).
As a result we need to know the corank before that call.
Furthermore, as we are going to remove coarray support in the scalarizer, let's
calculate the corank without relying on the scalarizer.
This patch just does that.

A new want_coarray flag is introduced as sometimes we want to treat coarrays
as normal arrays, that is we want a descriptor for the local image only.

OK?


[-- Attachment #2: no_coarray_in_scalarizer-5.CL --]
[-- Type: text/plain, Size: 163 bytes --]

2011-09-14  Mikael Morin  <mikael.morin@sfr.fr>

	* trans_array.c (gfc_conv_expr_descriptor): Evaluate codimension
	earlier and without relying on the scalarizer.

[-- Attachment #3: no_coarray_in_scalarizer-5.diff --]
[-- Type: text/x-diff, Size: 2328 bytes --]

diff --git a/trans-array.c b/trans-array.c
index 88849ef..88998de 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -5988,6 +5988,11 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss)
       tree to;
       tree base;
 
+      if (se->want_coarray)
+	codim = gfc_get_corank (expr);
+      else
+	codim = 0;
+
       /* Set the string_length for a character array.  */
       if (expr->ts.type == BT_CHARACTER)
 	se->string_length =  gfc_get_expr_charlen (expr);
@@ -6036,7 +6041,6 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss)
 	base = NULL_TREE;
 
       ndim = info->ref ? info->ref->u.ar.dimen : info->dimen;
-      codim = info->codimen;
       for (n = 0; n < ndim; n++)
 	{
 	  stride = gfc_conv_array_stride (desc, n);
diff --git a/trans-intrinsic.c b/trans-intrinsic.c
index de5a809..c216873 100644
--- a/trans-intrinsic.c
+++ b/trans-intrinsic.c
@@ -974,6 +974,7 @@ trans_this_image (gfc_se * se, gfc_expr *expr)
   ss = gfc_walk_expr (expr->value.function.actual->expr);
   gcc_assert (ss != gfc_ss_terminator);
   ss->data.info.codimen = corank;
+  argse.want_coarray = 1;
   gfc_conv_expr_descriptor (&argse, expr->value.function.actual->expr, ss);
   gfc_add_block_to_block (&se->pre, &argse.pre);
   gfc_add_block_to_block (&se->post, &argse.post);
@@ -1161,6 +1162,7 @@ trans_image_index (gfc_se * se, gfc_expr *expr)
   ss = gfc_walk_expr (expr->value.function.actual->expr);
   gcc_assert (ss != gfc_ss_terminator);
   ss->data.info.codimen = corank;
+  argse.want_coarray = 1;
   gfc_conv_expr_descriptor (&argse, expr->value.function.actual->expr, ss);
   gfc_add_block_to_block (&se->pre, &argse.pre);
   gfc_add_block_to_block (&se->post, &argse.post);
@@ -1488,6 +1490,7 @@ conv_intrinsic_cobound (gfc_se * se, gfc_expr * expr)
   gcc_assert (ss != gfc_ss_terminator);
   ss->data.info.codimen = corank;
   gfc_init_se (&argse, NULL);
+  argse.want_coarray = 1;
 
   gfc_conv_expr_descriptor (&argse, arg->expr, ss);
   gfc_add_block_to_block (&se->pre, &argse.pre);
diff --git a/trans.h b/trans.h
index 0c249a6..6157a88 100644
--- a/trans.h
+++ b/trans.h
@@ -86,6 +86,8 @@ typedef struct gfc_se
      args alias.  */
   unsigned force_tmp:1;
 
+  unsigned want_coarray:1;
+
   /* Scalarization parameters.  */
   struct gfc_se *parent;
   struct gfc_ss *ss;

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

* [Patch, fortran] [13/21] Remove coarray support in the scalarizer: Add specific walk_coarray function.
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
                   ` (9 preceding siblings ...)
  2011-09-15 23:10 ` [Patch, fortran] [16/21] Remove coarray support in the scalarizer: Remove gfc_loopinfo::codimen Mikael Morin
@ 2011-09-15 23:10 ` Mikael Morin
  2011-09-15 23:10 ` [Patch, fortran] [07/21] Remove coarray support in the scalarizer: Use codim as argument gfc_get_array_type_bounds Mikael Morin
                   ` (11 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Mikael Morin @ 2011-09-15 23:10 UTC (permalink / raw)
  To: gfortran, GCC patches

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

We have two contradictory needs: 
we want to make gfc_walk_expr free of coarray hacks as much as possible,
we want to have a gfc_ss generated for scalar coarrays suitable for
gfc_conv_expr_descriptor.

This patch creates a wrapper around gfc_walk_expr, so that in the scalar case
(i.e. value returned is gfc_ss_terminator) we generate the needed gfc_ss struct.

The new function includes at the same time the code (made slightly more
assertive) previously present in convert_element_to_coarray_ref.

OK?

Note: I haven't understood why walk_coarray is needed in the intrinsic case, 
but not in the general function call case (cf also my comment about patch 6).
On the other hand, it was also the case for the convert_element_to_coarray_ref
function before the patch.

Note2: This patch may need some adjustments to fix PR50420.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50420

[-- Attachment #2: no_coarray_in_scalarizer-13.CL --]
[-- Type: text/plain, Size: 253 bytes --]

2011-09-14  Mikael Morin  <mikael.morin@sfr.fr>

	* trans-intrinsic.c (walk_coarray): New function.
	(convert_element_to_coarray_ref): Move code to walk_coarray. Remove.
	(trans-this_image, trans_image_index, conv_intrinsic_cobound):
	Use walk_coarray.

[-- Attachment #3: no_coarray_in_scalarizer-13.diff --]
[-- Type: text/x-diff, Size: 2583 bytes --]

diff --git a/trans-intrinsic.c b/trans-intrinsic.c
index c216873..bc21b02 100644
--- a/trans-intrinsic.c
+++ b/trans-intrinsic.c
@@ -924,18 +924,32 @@ gfc_conv_intrinsic_exponent (gfc_se *se, gfc_expr *expr)
 /* Convert the last ref of a scalar coarray from an AR_ELEMENT to an
    AR_FULL, suitable for the scalarizer.  */
 
-static void
-convert_element_to_coarray_ref (gfc_expr *expr)
+static gfc_ss *
+walk_coarray (gfc_expr *e)
 {
-  gfc_ref *ref;
+  gfc_ss *ss;
 
-  for (ref = expr->ref; ref; ref = ref->next)
-    if (ref->type == REF_ARRAY && ref->next == NULL
-	&& ref->u.ar.codimen)
-      {
-	ref->u.ar.type = AR_FULL;
-	break;
-      }
+  gcc_assert (gfc_get_corank (e) > 0);
+
+  ss = gfc_walk_expr (e);
+
+  /* Fix scalar coarray.  */
+  if (ss == gfc_ss_terminator)
+    {
+      gfc_ref *ref;
+
+      ss = gfc_get_array_ss (gfc_ss_terminator, e, 0, GFC_SS_SECTION);
+
+      ref = e->ref;
+      while (ref->next)
+	ref = ref->next;
+
+      gcc_assert (ref->type == REF_ARRAY && ref->u.ar.codimen > 0);
+      ref->u.ar.type = AR_FULL;
+      ss->data.info.ref = ref;
+    }
+
+  return ss;
 }
 
 
@@ -969,9 +983,7 @@ trans_this_image (gfc_se * se, gfc_expr *expr)
 
   /* Obtain the descriptor of the COARRAY.  */
   gfc_init_se (&argse, NULL);
-  if (expr->value.function.actual->expr->rank == 0)
-    convert_element_to_coarray_ref (expr->value.function.actual->expr);
-  ss = gfc_walk_expr (expr->value.function.actual->expr);
+  ss = walk_coarray (expr->value.function.actual->expr);
   gcc_assert (ss != gfc_ss_terminator);
   ss->data.info.codimen = corank;
   argse.want_coarray = 1;
@@ -1157,9 +1169,7 @@ trans_image_index (gfc_se * se, gfc_expr *expr)
 
   /* Obtain the descriptor of the COARRAY.  */
   gfc_init_se (&argse, NULL);
-  if (expr->value.function.actual->expr->rank == 0)
-    convert_element_to_coarray_ref (expr->value.function.actual->expr);
-  ss = gfc_walk_expr (expr->value.function.actual->expr);
+  ss = walk_coarray (expr->value.function.actual->expr);
   gcc_assert (ss != gfc_ss_terminator);
   ss->data.info.codimen = corank;
   argse.want_coarray = 1;
@@ -1484,9 +1494,7 @@ conv_intrinsic_cobound (gfc_se * se, gfc_expr * expr)
   gcc_assert (arg->expr->expr_type == EXPR_VARIABLE);
   corank = gfc_get_corank (arg->expr);
 
-  if (expr->value.function.actual->expr->rank == 0)
-    convert_element_to_coarray_ref (expr->value.function.actual->expr);
-  ss = gfc_walk_expr (arg->expr);
+  ss = walk_coarray (arg->expr);
   gcc_assert (ss != gfc_ss_terminator);
   ss->data.info.codimen = corank;
   gfc_init_se (&argse, NULL);

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

* [Patch, fortran] [19/21] Remove coarray support in the scalarizer: Remove coarray_last argument
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
                   ` (6 preceding siblings ...)
  2011-09-15 23:10 ` [Patch, fortran] [03/21] Remove coarray support in the scalarizer: Simplify coarray descriptor setup Mikael Morin
@ 2011-09-15 23:10 ` Mikael Morin
  2011-09-15 23:10 ` [Patch, fortran] [21/21] Remove coarray support in the scalarizer: Final cleanup Mikael Morin
                   ` (14 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Mikael Morin @ 2011-09-15 23:10 UTC (permalink / raw)
  To: gfortran, GCC patches

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

At this point, gfc_conv_section_startstride has two callers, and for both
of them, the last argument (coarray_last) has the value false.
This patch removes the argument.

OK?


[-- Attachment #2: no_coarray_in_scalarizer-19.CL --]
[-- Type: text/plain, Size: 272 bytes --]

2011-09-14  Mikael Morin  <mikael.morin@sfr.fr>

	* trans-array.c (gfc_conv_section_startstride): Remove coarray_last
	argument. Remove condition on coarray_last.
	(gfc_conv_ss_startstride): Update call to gfc_conv_section_startstride.
	(gfc_conv_expr_descriptor): Ditto.

[-- Attachment #3: no_coarray_in_scalarizer-19.diff --]
[-- Type: text/x-diff, Size: 1533 bytes --]

diff --git a/trans-array.c b/trans-array.c
index 87d5200..95ebf6c 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -3201,7 +3201,7 @@ evaluate_bound (stmtblock_t *block, tree *bounds, gfc_expr ** values,
 
 static void
 gfc_conv_section_startstride (gfc_loopinfo * loop, gfc_ss * ss, int dim,
-			      bool coarray, bool coarray_last)
+			      bool coarray)
 {
   gfc_expr *stride = NULL;
   tree desc;
@@ -3237,8 +3237,7 @@ gfc_conv_section_startstride (gfc_loopinfo * loop, gfc_ss * ss, int dim,
   /* Similarly calculate the end.  Although this is not used in the
      scalarizer, it is needed when checking bounds and where the end
      is an expression with side-effects.  */
-  if (!coarray_last)
-    evaluate_bound (&loop->pre, info->end, ar->end, desc, dim, false);
+  evaluate_bound (&loop->pre, info->end, ar->end, desc, dim, false);
 
   /* Calculate the stride.  */
   if (!coarray && stride == NULL)
@@ -3321,7 +3320,7 @@ done:
 
 	  for (n = 0; n < ss->data.info.dimen; n++)
 	    gfc_conv_section_startstride (loop, ss, ss->data.info.dim[n],
-					  false, false);
+					  false);
 	  break;
 
 	case GFC_SS_INTRINSIC:
@@ -5976,7 +5975,7 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss)
 	  for (n = ss->data.info.dimen; n < ss->data.info.dimen + codim - 1;
 	       n++)
 	    {
-	      gfc_conv_section_startstride (&loop, ss, n, true, false);
+	      gfc_conv_section_startstride (&loop, ss, n, true);
 	      loop.from[n] = info->start[n];
 	      loop.to[n]   = info->end[n];
 	    }

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

* [Patch, fortran] [04/21] Remove coarray support in the scalarizer: Fix gfc_get_corank
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
                   ` (14 preceding siblings ...)
  2011-09-15 23:10 ` [Patch, fortran] [20/21] Remove coarray support in the scalarizer: Remove coarray argument Mikael Morin
@ 2011-09-15 23:10 ` Mikael Morin
  2011-09-15 23:10 ` [Patch, fortran] [09/21] Remove coarray support in the scalarizer: Accept coarray dimensions in gfc_conv_section_startstride Mikael Morin
                   ` (6 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Mikael Morin @ 2011-09-15 23:10 UTC (permalink / raw)
  To: gfortran, GCC patches

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

This patch was necessary on a previous version of the patchset (I was calling
gfc_get_corank on non-coarrays with e->symtree == NULL, and it was segfaulting
on the first e->symtree dereferencing). In the current version, it is optional,
but I propose it anyway as (I think) it makes some sense. 

The patch itself doesn't need extra explanations.
We could add an early return dealing with non-coarray cases (this is the variant
proposed), an assertion that input is really a coarray, or nothing at all.
Either works. Which one is best?

[-- Attachment #2: no_coarray_in_scalarizer-4.CL --]
[-- Type: text/plain, Size: 118 bytes --]

2011-09-14  Morin  <mikael.morin@sfr.fr>

	* expr.c (gfc_get_corank): Return 0 if input expression is not a
	coarray.

[-- Attachment #3: no_coarray_in_scalarizer-4.diff --]
[-- Type: text/x-diff, Size: 492 bytes --]

diff --git a/expr.c b/expr.c
index 3c09a2a..056da71 100644
--- a/expr.c
+++ b/expr.c
@@ -4293,13 +4293,19 @@ gfc_get_corank (gfc_expr *e)
 {
   int corank;
   gfc_ref *ref;
+
+  if (!gfc_is_coarray (e))
+    return 0;
+
   corank = e->symtree->n.sym->as ? e->symtree->n.sym->as->corank : 0;
+
   for (ref = e->ref; ref; ref = ref->next)
     {
       if (ref->type == REF_ARRAY)
 	corank = ref->u.ar.as->corank;
       gcc_assert (ref->type != REF_SUBSTRING);
     }
+
   return corank;
 }
 

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

* [Patch, fortran] [09/21] Remove coarray support in the scalarizer: Accept coarray dimensions in gfc_conv_section_startstride
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
                   ` (15 preceding siblings ...)
  2011-09-15 23:10 ` [Patch, fortran] [04/21] Remove coarray support in the scalarizer: Fix gfc_get_corank Mikael Morin
@ 2011-09-15 23:10 ` Mikael Morin
  2011-09-16  0:43 ` [Patch, fortran] [12/21] Remove coarray support in the scalarizer: Get cobounds without the scalarizer Mikael Morin
                   ` (5 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Mikael Morin @ 2011-09-15 23:10 UTC (permalink / raw)
  To: gfortran, GCC patches

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

Currently, gfc_walk_variable_expr changes codimension's type from
DIMEN_THIS_IMAGE to DIMEN_RANGE so that it looks like a regular array. 
We are going to remove that but still want to call gfc_conv_section_startstride
on the coarray dimensions to get the cobounds.
This patch relaxes an assertion in gfc_conv_section_startstride to accept
coarray dimensions.

OK?

[-- Attachment #2: no_coarray_in_scalarizer-9.CL --]
[-- Type: text/plain, Size: 141 bytes --]

2011-09-14  Mikael Morin  <mikael.morin@sfr.fr>

	* trans-array.c (gfc_conv_section_startstride): Update assertion to
	also accept coarrays.

[-- Attachment #3: no_coarray_in_scalarizer-9.diff --]
[-- Type: text/x-diff, Size: 465 bytes --]

diff --git a/trans-array.c b/trans-array.c
index 7cc86ba..7f44514 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -3204,7 +3204,8 @@ gfc_conv_section_startstride (gfc_loopinfo * loop, gfc_ss * ss, int dim,
       return;
     }
 
-  gcc_assert (ar->dimen_type[dim] == DIMEN_RANGE);
+  gcc_assert (ar->dimen_type[dim] == DIMEN_RANGE
+	      || ar->dimen_type[dim] == DIMEN_THIS_IMAGE);
   desc = info->descriptor;
   start = ar->start[dim];
   end = ar->end[dim];

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

* [Patch, fortran] [14/21] Remove coarray support in the scalarizer: Fix full array dimension type
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
                   ` (4 preceding siblings ...)
  2011-09-15 23:10 ` [Patch, fortran] [17/21] Remove coarray support in the scalarizer: Remove gfc_ss::dimen field Mikael Morin
@ 2011-09-15 23:10 ` Mikael Morin
  2011-09-15 23:10 ` [Patch, fortran] [03/21] Remove coarray support in the scalarizer: Simplify coarray descriptor setup Mikael Morin
                   ` (16 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Mikael Morin @ 2011-09-15 23:10 UTC (permalink / raw)
  To: gfortran, GCC patches

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

This prevents a regression.
The problem is in the full array case, ar->dimen is not set at resolution time.
As a result, the code seting ar->dimen_type to DIMEN_THIS_IMAGE (see patch 2)
sets codimensions' types starting at index 0 (as if it was a scalar coarray).
Later, gfc_walk_variable_expr sets ar->dimen and the associated ar->dimen_type,
overwriting the DIMEN_THIS_IMAGE from resolve_array_ref.
There is code in gfc_walk_variable_expr which sets ar->dimen_type
to DIMEN_RANGE for codimensions too, so there is no bug until we remove that 
code (patch 18).
After patch 18, some codimensions can have dimen_type unset, more exactly set
to 0, which is not an enum valid value, and everything breaks from there.

This patch copies the code present in gfc_walk_variable expr
to set dimension types for full array references. Then we can overwrite
array dimen_type part as much as we want, the coarray dimen_type part
will be left untouched (and properly set).

The duplicate code in gfc_walk_variable_expr can't be removed, as it seems that
some array references are not passed through resolve_array_ref (I didn't
investigate further).

OK?

[-- Attachment #2: no_coarray_in_scalarizer-14.CL --]
[-- Type: text/plain, Size: 172 bytes --]

2011-09-14  Mikael Morin  <mikael.morin@sfr.fr>

	* resolve.c (resolve_array_ref): Set array_ref's dimen field (and the
	associated dimen_type) in the full array ref case.

[-- Attachment #3: no_coarray_in_scalarizer-14.diff --]
[-- Type: text/x-diff, Size: 771 bytes --]

diff --git a/resolve.c b/resolve.c
index 4c991c8..c594ebf 100644
--- a/resolve.c
+++ b/resolve.c
@@ -4637,8 +4637,23 @@ resolve_array_ref (gfc_array_ref *ar)
 	}
     }
 
-  if (ar->type == AR_FULL && ar->as->rank == 0)
-    ar->type = AR_ELEMENT;
+  if (ar->type == AR_FULL)
+    {
+      if (ar->as->rank == 0)
+	ar->type = AR_ELEMENT;
+
+      /* Make sure array is the same as array(:,:), this way
+	 we don't need to special case all the time.  */
+      ar->dimen = ar->as->rank;
+      for (i = 0; i < ar->dimen; i++)
+	{
+	  ar->dimen_type[i] = DIMEN_RANGE;
+
+	  gcc_assert (ar->start[i] == NULL);
+	  gcc_assert (ar->end[i] == NULL);
+	  gcc_assert (ar->stride[i] == NULL);
+	}
+    }
 
   /* If the reference type is unknown, figure out what kind it is.  */
 

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

* [Patch, fortran] [07/21] Remove coarray support in the scalarizer: Use codim as argument gfc_get_array_type_bounds
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
                   ` (10 preceding siblings ...)
  2011-09-15 23:10 ` [Patch, fortran] [13/21] Remove coarray support in the scalarizer: Add specific walk_coarray function Mikael Morin
@ 2011-09-15 23:10 ` Mikael Morin
  2011-09-15 23:10 ` [Patch, fortran] [05/21] Remove coarray support in the scalarizer: Calculate codim earlier Mikael Morin
                   ` (10 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Mikael Morin @ 2011-09-15 23:10 UTC (permalink / raw)
  To: gfortran, GCC patches

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

This uses the just set codim (see patch 5) as argument to
gfc_get_array_type_bounds.

OK?

[-- Attachment #2: no_coarray_in_scalarizer-7.CL --]
[-- Type: text/plain, Size: 171 bytes --]

2011-09-14  Mikael Morin  <mikael.morin@sfr.fr>

	* trans-array.c (gfc_conv_expr_descriptor): Use codim instead of
	loop.codimen as argument to gfc_get_array_type_bounds.

[-- Attachment #3: no_coarray_in_scalarizer-7.diff --]
[-- Type: text/x-diff, Size: 601 bytes --]

diff --git a/trans-array.c b/trans-array.c
index 88998de..0f5f29c 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -6008,9 +6008,8 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss)
 	{
 	  /* Otherwise make a new one.  */
 	  parmtype = gfc_get_element_type (TREE_TYPE (desc));
-	  parmtype = gfc_get_array_type_bounds (parmtype, loop.dimen,
-						loop.codimen, loop.from,
-						loop.to, 0,
+	  parmtype = gfc_get_array_type_bounds (parmtype, loop.dimen, codim,
+						loop.from, loop.to, 0,
 						GFC_ARRAY_UNKNOWN, false);
 	  parm = gfc_create_var (parmtype, "parm");
 	}

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

* [Patch, fortran] [06/21] Remove coarray support in the scalarizer: Request coarray for an actual arg associed with a coarray dummy
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
                   ` (12 preceding siblings ...)
  2011-09-15 23:10 ` [Patch, fortran] [05/21] Remove coarray support in the scalarizer: Calculate codim earlier Mikael Morin
@ 2011-09-15 23:10 ` Mikael Morin
  2011-10-02 16:35   ` Tobias Burnus
  2011-09-15 23:10 ` [Patch, fortran] [20/21] Remove coarray support in the scalarizer: Remove coarray argument Mikael Morin
                   ` (8 subsequent siblings)
  22 siblings, 1 reply; 26+ messages in thread
From: Mikael Morin @ 2011-09-15 23:10 UTC (permalink / raw)
  To: gfortran, GCC patches

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

This one is more controversial and I need input from a coarray-fluent guy, for
example Tobias.

As I introduced the want_coarray flag (see previous patch), it made sense to me
to also set want_coarray for coarray dummies. After some more thought,
I decided to restrict further want_coarray to assumed shape coarray
dummies. The patch does that.

However, what comes up from testing is that neither is needed.
I'm not submiting this patch for approval, I'm submitting it to understand why
it is not necessary.
How are cobounds passed to a coarray dummy?


[-- Attachment #2: no_coarray_in_scalarizer-6.CL --]
[-- Type: text/plain, Size: 167 bytes --]

2011-09-14  Mikael Morin  <mikael.morin@sfr.fr>

	* trans-expr.c (gfc_conv_procedure_call): Set want_coarray flag if the
	dummy argument is an assumed-shape coarray.


[-- Attachment #3: no_coarray_in_scalarizer-6.diff --]
[-- Type: text/x-diff, Size: 586 bytes --]

diff --git a/trans-expr.c b/trans-expr.c
index 131927c..80447fa 100644
--- a/trans-expr.c
+++ b/trans-expr.c
@@ -2990,8 +2990,12 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
 	{
 	  /* A scalar or transformational function.  */
 	  gfc_init_se (&parmse, NULL);
-	  argss = gfc_walk_expr (e);
+	  if (fsym && fsym->attr.codimension
+	      && (fsym->as->cotype == AS_ASSUMED_SHAPE
+		  || fsym->as->cotype == AS_DEFERRED))
+	    parmse.want_coarray = 1;
 
+	  argss = gfc_walk_expr (e);
 	  if (argss == gfc_ss_terminator)
 	    {
 	      if (e->expr_type == EXPR_VARIABLE

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

* [Patch, fortran] [08/21] Remove coarray support in the scalarizer: Factor array ref references
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
                   ` (2 preceding siblings ...)
  2011-09-15 23:09 ` [Patch, fortran] [10/21] Remove coarray support in the scalarizer: Factor bound evaluation Mikael Morin
@ 2011-09-15 23:10 ` Mikael Morin
  2011-09-15 23:10 ` [Patch, fortran] [17/21] Remove coarray support in the scalarizer: Remove gfc_ss::dimen field Mikael Morin
                   ` (18 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Mikael Morin @ 2011-09-15 23:10 UTC (permalink / raw)
  To: gfortran, GCC patches

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

The Changelog says it all.

OK?

[-- Attachment #2: no_coarray_in_scalarizer-8.CL --]
[-- Type: text/plain, Size: 136 bytes --]

2011-09-14  Mikael Morin  <mikael.morin@sfr.fr>

	* trans-array.c (gfc_conv_section_startstride): Factor common
	array ref references.


[-- Attachment #3: no_coarray_in_scalarizer-8.diff --]
[-- Type: text/x-diff, Size: 1193 bytes --]

diff --git a/trans-array.c b/trans-array.c
index 0f5f29c..7cc86ba 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -3187,12 +3187,14 @@ gfc_conv_section_startstride (gfc_loopinfo * loop, gfc_ss * ss, int dim,
   tree desc;
   gfc_se se;
   gfc_ss_info *info;
+  gfc_array_ref *ar;
 
   gcc_assert (ss->type == GFC_SS_SECTION);
 
   info = &ss->data.info;
+  ar = &info->ref->u.ar;
 
-  if (info->ref->u.ar.dimen_type[dim] == DIMEN_VECTOR)
+  if (ar->dimen_type[dim] == DIMEN_VECTOR)
     {
       /* We use a zero-based index to access the vector.  */
       info->start[dim] = gfc_index_zero_node;
@@ -3202,12 +3204,12 @@ gfc_conv_section_startstride (gfc_loopinfo * loop, gfc_ss * ss, int dim,
       return;
     }
 
-  gcc_assert (info->ref->u.ar.dimen_type[dim] == DIMEN_RANGE);
+  gcc_assert (ar->dimen_type[dim] == DIMEN_RANGE);
   desc = info->descriptor;
-  start = info->ref->u.ar.start[dim];
-  end = info->ref->u.ar.end[dim];
+  start = ar->start[dim];
+  end = ar->end[dim];
   if (!coarray)
-    stride = info->ref->u.ar.stride[dim];
+    stride = ar->stride[dim];
 
   /* Calculate the start of the range.  For vector subscripts this will
      be the range of the vector.  */

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

* [Patch, fortran] [17/21] Remove coarray support in the scalarizer: Remove gfc_ss::dimen field
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
                   ` (3 preceding siblings ...)
  2011-09-15 23:10 ` [Patch, fortran] [08/21] Remove coarray support in the scalarizer: Factor array ref references Mikael Morin
@ 2011-09-15 23:10 ` Mikael Morin
  2011-09-15 23:10 ` [Patch, fortran] [14/21] Remove coarray support in the scalarizer: Fix full array dimension type Mikael Morin
                   ` (17 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Mikael Morin @ 2011-09-15 23:10 UTC (permalink / raw)
  To: gfortran, GCC patches

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

This patch removes gfc_ss::codimen field and any code depending on it.

OK?


[-- Attachment #2: no_coarray_in_scalarizer-17.CL --]
[-- Type: text/plain, Size: 539 bytes --]

2011-09-14  Mikael Morin  <mikael.morin@sfr.fr>

	* trans.h (gfc_ss_info): Remove codimen field.
	* trans-array.c (gfc_get_array_ss): Don't set codimen field.
	(gfc_trans_create_temp_array): Don't set descriptor's cobounds.
	(gfc_trans_constant_array_constructor): Update loop upper limit.
	(gfc_conv_ss_startstride): Don't set codimen field.
	Don't get descriptor's cobounds.
	(gfc_walk_variable_expr): Update dimension index.
	* trans-intrinsic.c (trans_this_image, trans_image_index,
	conv_intrinsic_cobound): Don't set codimen field



[-- Attachment #3: no_coarray_in_scalarizer-17.diff --]
[-- Type: text/x-diff, Size: 4031 bytes --]

diff --git a/trans-array.c b/trans-array.c
index 0a9d281..fa05d2b 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -526,7 +526,6 @@ gfc_get_array_ss (gfc_ss *next, gfc_expr *expr, int dimen, gfc_ss_type type)
   ss->expr = expr;
   info = &ss->data.info;
   info->dimen = dimen;
-  info->codimen = 0;
   for (i = 0; i < info->dimen; i++)
     info->dim[i] = i;
 
@@ -973,13 +972,6 @@ gfc_trans_create_temp_array (stmtblock_t * pre, stmtblock_t * post,
 			      size, tmp);
       size = gfc_evaluate_now (size, pre);
     }
-  for (n = info->dimen; n < info->dimen + info->codimen; n++)
-    {
-      gfc_conv_descriptor_lbound_set (pre, desc, gfc_rank_cst[n],
-                                      gfc_index_zero_node);
-      if (n < info->dimen + info->codimen - 1)
-	gfc_conv_descriptor_ubound_set (pre, desc, gfc_rank_cst[n], loop->to[n]);
-    }
 
   /* Get the size of the array.  */
 
@@ -1872,7 +1864,7 @@ gfc_trans_constant_array_constructor (gfc_loopinfo * loop,
   info->data = gfc_build_addr_expr (NULL_TREE, tmp);
   info->offset = gfc_index_zero_node;
 
-  for (i = 0; i < info->dimen + info->codimen; i++)
+  for (i = 0; i < info->dimen; i++)
     {
       info->delta[i] = gfc_index_zero_node;
       info->start[i] = gfc_index_zero_node;
@@ -3330,12 +3322,6 @@ done:
 	  for (n = 0; n < ss->data.info.dimen; n++)
 	    gfc_conv_section_startstride (loop, ss, ss->data.info.dim[n],
 					  false, false);
-	  for (n = ss->data.info.dimen;
-	       n < ss->data.info.dimen + ss->data.info.codimen; n++)
-	    gfc_conv_section_startstride (loop, ss, ss->data.info.dim[n], true,
-					  n == ss->data.info.dimen
-					       + ss->data.info.codimen -1);
-
 	  break;
 
 	case GFC_SS_INTRINSIC:
@@ -7690,8 +7676,7 @@ gfc_walk_variable_expr (gfc_ss * ss, gfc_expr * expr)
 		case DIMEN_RANGE:
                   /* We don't add anything for sections, just remember this
                      dimension for later.  */
-		  newss->data.info.dim[newss->data.info.dimen
-				       + newss->data.info.codimen] = n;
+		  newss->data.info.dim[newss->data.info.dimen] = n;
 		  if (n < ar->dimen)
 		    newss->data.info.dimen++;
 		  break;
@@ -7703,8 +7688,7 @@ gfc_walk_variable_expr (gfc_ss * ss, gfc_expr * expr)
 					      1, GFC_SS_VECTOR);
 		  indexss->loop_chain = gfc_ss_terminator;
 		  newss->data.info.subscript[n] = indexss;
-		  newss->data.info.dim[newss->data.info.dimen
-				       + newss->data.info.codimen] = n;
+		  newss->data.info.dim[newss->data.info.dimen] = n;
 		  if (n < ar->dimen)
 		    newss->data.info.dimen++;
 		  break;
diff --git a/trans-intrinsic.c b/trans-intrinsic.c
index bc21b02..c47e678 100644
--- a/trans-intrinsic.c
+++ b/trans-intrinsic.c
@@ -985,7 +985,6 @@ trans_this_image (gfc_se * se, gfc_expr *expr)
   gfc_init_se (&argse, NULL);
   ss = walk_coarray (expr->value.function.actual->expr);
   gcc_assert (ss != gfc_ss_terminator);
-  ss->data.info.codimen = corank;
   argse.want_coarray = 1;
   gfc_conv_expr_descriptor (&argse, expr->value.function.actual->expr, ss);
   gfc_add_block_to_block (&se->pre, &argse.pre);
@@ -1171,7 +1170,6 @@ trans_image_index (gfc_se * se, gfc_expr *expr)
   gfc_init_se (&argse, NULL);
   ss = walk_coarray (expr->value.function.actual->expr);
   gcc_assert (ss != gfc_ss_terminator);
-  ss->data.info.codimen = corank;
   argse.want_coarray = 1;
   gfc_conv_expr_descriptor (&argse, expr->value.function.actual->expr, ss);
   gfc_add_block_to_block (&se->pre, &argse.pre);
@@ -1496,7 +1494,6 @@ conv_intrinsic_cobound (gfc_se * se, gfc_expr * expr)
 
   ss = walk_coarray (arg->expr);
   gcc_assert (ss != gfc_ss_terminator);
-  ss->data.info.codimen = corank;
   gfc_init_se (&argse, NULL);
   argse.want_coarray = 1;
 
diff --git a/trans.h b/trans.h
index 085334c..535c207 100644
--- a/trans.h
+++ b/trans.h
@@ -118,7 +118,7 @@ gfc_coarray_type;
 
 typedef struct gfc_ss_info
 {
-  int dimen, codimen;
+  int dimen;
   /* The ref that holds information on this section.  */
   gfc_ref *ref;
   /* The descriptor of this array.  */

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

* [Patch, fortran] [12/21] Remove coarray support in the scalarizer: Get cobounds without the scalarizer
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
                   ` (16 preceding siblings ...)
  2011-09-15 23:10 ` [Patch, fortran] [09/21] Remove coarray support in the scalarizer: Accept coarray dimensions in gfc_conv_section_startstride Mikael Morin
@ 2011-09-16  0:43 ` Mikael Morin
  2011-09-16  5:25 ` [Patch, fortran] [15/21] Remove coarray support in the scalarizer: Remove gfc_ss::data::temp_ss::codimen field Mikael Morin
                   ` (4 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Mikael Morin @ 2011-09-16  0:43 UTC (permalink / raw)
  To: gfortran, GCC patches

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

This patch sets cobounds in a coarray's gfc_ss struct without relying on the
scalarizer doing it automatically.
The convention to have the bounds and cobounds stored in the loop::from
and loop::to arrays while calling gfc_get_array_type_bounds is not changed,
so we need to set the loop.from[n] and loop.to[n] "by hand".

OK?

[-- Attachment #2: no_coarray_in_scalarizer-12.CL --]
[-- Type: text/plain, Size: 142 bytes --]

2011-09-14  Mikael Morin  <mikael.morin@sfr.fr>

	* trans-array.c (gfc_conv_expr_descriptor): Add out-of-the-scalarizer
	cobounds evaluation.

[-- Attachment #3: no_coarray_in_scalarizer-12.diff --]
[-- Type: text/x-diff, Size: 793 bytes --]

diff --git a/trans-array.c b/trans-array.c
index 067fe0b..b132bf6 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -5994,7 +5994,21 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss)
       tree base;
 
       if (se->want_coarray)
-	codim = gfc_get_corank (expr);
+	{
+	  codim = gfc_get_corank (expr);
+	  for (n = ss->data.info.dimen; n < ss->data.info.dimen + codim - 1;
+	       n++)
+	    {
+	      gfc_conv_section_startstride (&loop, ss, n, true, false);
+	      loop.from[n] = info->start[n];
+	      loop.to[n]   = info->end[n];
+	    }
+
+	  gcc_assert (n == ss->data.info.dimen + codim - 1);
+	  evaluate_bound (&loop.pre, info->start, info->ref->u.ar.start,
+			  info->descriptor, n, true);
+	  loop.from[n] = info->start[n];
+	}
       else
 	codim = 0;
 

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

* [Patch, fortran] [15/21] Remove coarray support in the scalarizer: Remove gfc_ss::data::temp_ss::codimen field
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
                   ` (17 preceding siblings ...)
  2011-09-16  0:43 ` [Patch, fortran] [12/21] Remove coarray support in the scalarizer: Get cobounds without the scalarizer Mikael Morin
@ 2011-09-16  5:25 ` Mikael Morin
  2011-09-16  5:47 ` [Patch, fortran] [11/21] Remove coarray support in the scalarizer: Support 0-rank loop in gfc_conv_ss_startstride Mikael Morin
                   ` (3 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Mikael Morin @ 2011-09-16  5:25 UTC (permalink / raw)
  To: gfortran, GCC patches

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

This removes the gfc_ss::data::temp::codimen field and the code depending on
it.

OK?


[-- Attachment #2: no_coarray_in_scalarizer-15.CL --]
[-- Type: text/plain, Size: 211 bytes --]

2011-09-14  Mikael Morin  <mikael.morin@sfr.fr>

	* trans.h (gfc_ss): Remove data.temp.codimen field.
	* trans-array.c (gfc_conv_resolve_dependencies,
	gfc_conv_expr_descriptor): Don't set temp's codimen field.

[-- Attachment #3: no_coarray_in_scalarizer-15.diff --]
[-- Type: text/x-diff, Size: 1065 bytes --]

diff --git a/trans-array.c b/trans-array.c
index b132bf6..9d4ef5a 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -3861,7 +3861,6 @@ temporary:
 	base_type = gfc_get_element_type (base_type);
       loop->temp_ss = gfc_get_temp_ss (base_type, dest->string_length,
 				       loop->dimen);
-      loop->temp_ss->data.temp.codimen = loop->codimen;
       gfc_add_ss_to_loop (loop, loop->temp_ss);
     }
   else
@@ -5920,7 +5919,6 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss)
 
       se->string_length = loop.temp_ss->string_length;
       gcc_assert (loop.temp_ss->data.temp.dimen == loop.dimen);
-      loop.temp_ss->data.temp.codimen = loop.codimen;
       gfc_add_ss_to_loop (&loop, loop.temp_ss);
     }
 
diff --git a/trans.h b/trans.h
index 6157a88..3404123 100644
--- a/trans.h
+++ b/trans.h
@@ -212,7 +212,7 @@ typedef struct gfc_ss
     {
       /* The rank of the temporary.  May be less than the rank of the
          assigned expression.  */
-      int dimen, codimen;
+      int dimen;
       tree type;
     }
     temp;

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

* [Patch, fortran] [11/21] Remove coarray support in the scalarizer: Support 0-rank loop in gfc_conv_ss_startstride
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
                   ` (18 preceding siblings ...)
  2011-09-16  5:25 ` [Patch, fortran] [15/21] Remove coarray support in the scalarizer: Remove gfc_ss::data::temp_ss::codimen field Mikael Morin
@ 2011-09-16  5:47 ` Mikael Morin
  2011-09-16  6:18 ` [Patch, fortran] [18/21] Remove coarray support in the scalarizer: Cleanup gfc_walk_variable_expr Mikael Morin
                   ` (2 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Mikael Morin @ 2011-09-16  5:47 UTC (permalink / raw)
  To: gfortran, GCC patches

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


We are going to remove the gfc_loopinfo::codimen field.
The following assertion in gfc_conv_ss_startstride:
  gcc_assert (loop->dimen + loop->codimen != 0);
is going to fail for scalar coarrays when updated to
  gcc_assert (loop->dimen != 0);

However, gfc_conv_expr_descriptor, requires (if we don't want to rewrite it
completely) that the expression's gfc_ss struct passes through the scalarizer
(in the scalar coarray case, it will do nothing but get the descriptor).

This patch changes the assertion so that zero rank loops are accepted.

OK?


[-- Attachment #2: no_coarray_in_scalarizer-11.CL --]
[-- Type: text/plain, Size: 117 bytes --]

2011-09-14  Mikael Morin  <mikael.morin@sfr.fr>

	* trans-array.c (gfc_conv_ss_startstride): Support zero rank loop.

[-- Attachment #3: no_coarray_in_scalarizer-11.diff --]
[-- Type: text/x-diff, Size: 1557 bytes --]

diff --git a/trans-array.c b/trans-array.c
index ee5761b..067fe0b 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -3279,8 +3279,7 @@ gfc_conv_ss_startstride (gfc_loopinfo * loop)
 
   loop->dimen = 0;
   /* Determine the rank of the loop.  */
-  for (ss = loop->ss;
-       ss != gfc_ss_terminator && loop->dimen == 0; ss = ss->loop_chain)
+  for (ss = loop->ss; ss != gfc_ss_terminator; ss = ss->loop_chain)
     {
       switch (ss->type)
 	{
@@ -3290,7 +3289,7 @@ gfc_conv_ss_startstride (gfc_loopinfo * loop)
 	case GFC_SS_COMPONENT:
 	  loop->dimen = ss->data.info.dimen;
 	  loop->codimen = ss->data.info.codimen;
-	  break;
+	  goto done;
 
 	/* As usual, lbound and ubound are exceptions!.  */
 	case GFC_SS_INTRINSIC:
@@ -3300,14 +3299,14 @@ gfc_conv_ss_startstride (gfc_loopinfo * loop)
 	    case GFC_ISYM_UBOUND:
 	      loop->dimen = ss->data.info.dimen;
 	      loop->codimen = 0;
-	      break;
+	      goto done;
 
 	    case GFC_ISYM_LCOBOUND:
 	    case GFC_ISYM_UCOBOUND:
 	    case GFC_ISYM_THIS_IMAGE:
 	      loop->dimen = ss->data.info.dimen;
 	      loop->codimen = ss->data.info.codimen;
-	      break;
+	      goto done;
 
 	    default:
 	      break;
@@ -3320,8 +3319,9 @@ gfc_conv_ss_startstride (gfc_loopinfo * loop)
 
   /* We should have determined the rank of the expression by now.  If
      not, that's bad news.  */
-  gcc_assert (loop->dimen + loop->codimen != 0);
+  gcc_unreachable ();
 
+done:
   /* Loop over all the SS in the chain.  */
   for (ss = loop->ss; ss != gfc_ss_terminator; ss = ss->loop_chain)
     {

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

* [Patch, fortran] [18/21] Remove coarray support in the scalarizer: Cleanup gfc_walk_variable_expr
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
                   ` (19 preceding siblings ...)
  2011-09-16  5:47 ` [Patch, fortran] [11/21] Remove coarray support in the scalarizer: Support 0-rank loop in gfc_conv_ss_startstride Mikael Morin
@ 2011-09-16  6:18 ` Mikael Morin
  2011-09-23  7:36 ` [Patch, fortran] [00/21] Remove coarray support in the scalarizer Steve Kargl
  2011-09-30 18:18 ` Steve Kargl
  22 siblings, 0 replies; 26+ messages in thread
From: Mikael Morin @ 2011-09-16  6:18 UTC (permalink / raw)
  To: gfortran, GCC patches

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

This removes the coarray code in gfc_walk_variable_expr.
See the ChangeLog for details.

OK?


[-- Attachment #2: no_coarray_in_scalarizer-18.CL --]
[-- Type: text/plain, Size: 299 bytes --]

2011-09-14  Mikael Morin  <mikael.morin@sfr.fr>

	* trans-array.c (gfc_walk_variable_expr): Remove scalar coarray
	handling.  Don't reset array ref's corank and codimensions' types
	in the full array ref case.  Update loop upper limit.
	Remove DIMEN_THIS_IMAGE case.  Remove unnecessary conditions.

[-- Attachment #3: no_coarray_in_scalarizer-18.diff --]
[-- Type: text/x-diff, Size: 2347 bytes --]

diff --git a/trans-array.c b/trans-array.c
index fa05d2b..87d5200 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -7612,12 +7612,6 @@ gfc_walk_variable_expr (gfc_ss * ss, gfc_expr * expr)
 
       ar = &ref->u.ar;
 
-      if (ar->as->rank == 0 && ref->next != NULL)
-	{
-	  /* Scalar coarray.  */
-	  continue;
-	}
-
       switch (ar->type)
 	{
 	case AR_ELEMENT:
@@ -7632,7 +7626,6 @@ gfc_walk_variable_expr (gfc_ss * ss, gfc_expr * expr)
 	  /* Make sure array is the same as array(:,:), this way
 	     we don't need to special case all the time.  */
 	  ar->dimen = ar->as->rank;
-	  ar->codimen = 0;
 	  for (n = 0; n < ar->dimen; n++)
 	    {
 	      ar->dimen_type[n] = DIMEN_RANGE;
@@ -7641,14 +7634,6 @@ gfc_walk_variable_expr (gfc_ss * ss, gfc_expr * expr)
 	      gcc_assert (ar->end[n] == NULL);
 	      gcc_assert (ar->stride[n] == NULL);
 	    }
-	  for (n = ar->dimen; n < ar->dimen + ar->as->corank; n++)
-	    {
-	      newss->data.info.dim[n] = n;
-	      ar->dimen_type[n] = DIMEN_RANGE;
-
-	      gcc_assert (ar->start[n] == NULL);
-	      gcc_assert (ar->end[n] == NULL);
-	    }
 	  ss = newss;
 	  break;
 
@@ -7657,14 +7642,12 @@ gfc_walk_variable_expr (gfc_ss * ss, gfc_expr * expr)
 	  newss->data.info.ref = ref;
 
 	  /* We add SS chains for all the subscripts in the section.  */
-	  for (n = 0; n < ar->dimen + ar->codimen; n++)
+	  for (n = 0; n < ar->dimen; n++)
 	    {
 	      gfc_ss *indexss;
 
 	      switch (ar->dimen_type[n])
 		{
-	        case DIMEN_THIS_IMAGE:
-		  continue;
 		case DIMEN_ELEMENT:
 		  /* Add SS for elemental (scalar) subscripts.  */
 		  gcc_assert (ar->start[n]);
@@ -7677,8 +7660,7 @@ gfc_walk_variable_expr (gfc_ss * ss, gfc_expr * expr)
                   /* We don't add anything for sections, just remember this
                      dimension for later.  */
 		  newss->data.info.dim[newss->data.info.dimen] = n;
-		  if (n < ar->dimen)
-		    newss->data.info.dimen++;
+		  newss->data.info.dimen++;
 		  break;
 
 		case DIMEN_VECTOR:
@@ -7689,8 +7671,7 @@ gfc_walk_variable_expr (gfc_ss * ss, gfc_expr * expr)
 		  indexss->loop_chain = gfc_ss_terminator;
 		  newss->data.info.subscript[n] = indexss;
 		  newss->data.info.dim[newss->data.info.dimen] = n;
-		  if (n < ar->dimen)
-		    newss->data.info.dimen++;
+		  newss->data.info.dimen++;
 		  break;
 
 		default:

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

* Re: [Patch, fortran] [00/21] Remove coarray support in the scalarizer
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
                   ` (20 preceding siblings ...)
  2011-09-16  6:18 ` [Patch, fortran] [18/21] Remove coarray support in the scalarizer: Cleanup gfc_walk_variable_expr Mikael Morin
@ 2011-09-23  7:36 ` Steve Kargl
  2011-09-30 18:18 ` Steve Kargl
  22 siblings, 0 replies; 26+ messages in thread
From: Steve Kargl @ 2011-09-23  7:36 UTC (permalink / raw)
  To: Mikael Morin; +Cc: gfortran, GCC patches

On Fri, Sep 16, 2011 at 01:08:13AM +0200, Mikael Morin wrote:
> Hello,
> 
> the scalarizer is there to generate loops for assignments over more than
> one element. Tobias extended it at various places to support coarrays,
> but this should not be necessary as coarrays in assignments either refer
> to the array present on the local image or to the one on the remote image
> (in which case a local temporary is created). In either case the coarray
> is seen as a normal array by the assignment code, which makes the point
> of having coarray-specific handling in the scalarizer moot.
> 
> In fact the reason for the presence of coarrays in the scalarizer is that
> gfc_conv_expr_descriptor uses the scalarizer to setup array (co)bounds.
> 
> This patch serie removes the coarray-specific code in the scalarizer, and
> replaces it with some additional cobound setup code in gfc_conv_expr_descriptor.
> It is supposed to make the code easier to grasp by having a scalarizer free of
> coarray stuff (it is complicated enough without it), and by having cobound
> setup code gathered in a single place.
> The downside is that it makes gfc_conv_expr_descriptor even bigger than it was
> already.
> 
> Every patch has been tested by incremental bootstrap and running the fortran
> testsuite with RUNTESTLAGS=caf.exp and RUNTESTFLAGS="dg.exp=*coarray*".
> The last one has also passed a full fortran regression test.
> 
> OK for trunk?
> 

I've read through the first 10 patches, and in general I like
the clean separation that you're trying to achieve.  Given that
this effects co-arrays I was expecting Tobias to quickly respond,
but it seems he is busy with other obligations.  I'll try to go
through the entire patch set on Saturday.

-- 
Steve

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

* Re: [Patch, fortran] [00/21] Remove coarray support in the scalarizer
  2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
                   ` (21 preceding siblings ...)
  2011-09-23  7:36 ` [Patch, fortran] [00/21] Remove coarray support in the scalarizer Steve Kargl
@ 2011-09-30 18:18 ` Steve Kargl
  2011-10-07 21:14   ` Commit revisions (was: Re: [Patch, fortran] [00/21] Remove coarray support in the scalarizer) Mikael Morin
  22 siblings, 1 reply; 26+ messages in thread
From: Steve Kargl @ 2011-09-30 18:18 UTC (permalink / raw)
  To: Mikael Morin; +Cc: gfortran, GCC patches

On Fri, Sep 16, 2011 at 01:08:13AM +0200, Mikael Morin wrote:
> 
> OK for trunk?
> 
> Mikael
> 
> patchset layout:
>  - patches 1..4: 
> 	Preliminary cleanups.
> 	Those are quite independant on the rest.
> 	Patch 4 is optional.
> 
>  - patches 5..13: 
> 	Step by step move from scalarizer-provided cobounds setup code
> 	to explicit specific code in gfc_conv_expr_descriptor.
> 	Patch 6 is a request for explaination and is not intended for check-in.
> 
>  - patch 14:
> 	Fixes a regression.
> 
>  - patches 15..21:
> 	This is the point of all the rest: remove coarray-specific code in the
> 	scalarizer.

Mikael,

I've finally made it through the set of patches,
and did not find anything that raised a red flag.
I'll note that I did not study the issue/question
you raised with patch 6.  Tobias is probably the
best person to offer an opinion.  After pinging
patch 6 off of Tobias, I think the code can be
committed.

-- 
Steve

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

* Re: [Patch, fortran] [06/21] Remove coarray support in the scalarizer: Request coarray for an actual arg associed with a coarray dummy
  2011-09-15 23:10 ` [Patch, fortran] [06/21] Remove coarray support in the scalarizer: Request coarray for an actual arg associed with a coarray dummy Mikael Morin
@ 2011-10-02 16:35   ` Tobias Burnus
  0 siblings, 0 replies; 26+ messages in thread
From: Tobias Burnus @ 2011-10-02 16:35 UTC (permalink / raw)
  To: Mikael Morin; +Cc: gcc-patches, 'fortran@gcc.gnu.org'

On 16.09.2011 01:08, Mikael Morin wrote:
> How are cobounds passed to a coarray dummy?

For explicit shape, assumed-size and assumed shape coarrays: The value 
is not passed but is set for the dummy argument. While that's not 
surprising for explicit shape/assumed shape arrays, e.g.
   integer :: A(5,7,n)[1:4, 4:*]
   integer :: B(2:*)[*]
it might be slightly surprising for assumed-shape coarrays. However, 
also for normal assumed-shape arrays, only the rank and not the lower 
bound is preserved (default lbound value: 1). For coarrays, also the 
upper bound needs to be given:
   integer :: B(1:, 5:)[4,*]
Note: In all those cases, the corank can differ between actual and dummy 
argument.

The only case where the the cobounds are passed are deferred-shape 
coarrays, i.e. allocatable ones, e.g.
   integer, allocatable :: A(:)[:,:]
here, the corank needs to agree and the lower/upper bounds are kept.

For deferred-shape coarrays, the array descriptor contains behind the 
array dimension triplets, additional triplets for the cobounds.

Except for the small difference for deferred-shape coarrays, with 
-fcoarray=single the normal data as with noncoarrays is transferred. For 
-fcoarray=lib one transfers in all cases additional information: A token 
identifying the coarray and the offset between the first coarray memory 
location and the one one passes (e.g., for a coarray "A(5)[*]", the 
element A(3) is also a coarray and the offset would be the one between 
A(1) and A(3)). For deferred-shape coarrays, the token is part of the 
array descriptor and no offset exists. For all other cases, there is a 
hidden additional argument for offset and token. See CoarrayLib in the 
wiki for details.

> However, what comes up from testing is that neither is needed.
> I'm not submiting this patch for approval, I'm submitting it to understand why
> it is not necessary.

I do not immediately see whether it is needed or not. However, as this 
is about the scalarizer: You cannot pass an allocatable array (coarray) 
to an (impure) elemental function which has a scalar *allocatable* dummy 
argument.* You can only do so if the dummy argument is not allocatable. 
However, in that case the cobounds are not taken from the actual 
argument but are constructed in the called procedure.

(* Separately allocating an single argument does not make sense. I have 
not checked the standard, but I don't think it can be valid.)

Does this answer the question?

Tobias

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

* Commit revisions (was: Re: [Patch, fortran] [00/21] Remove coarray support in the scalarizer)
  2011-09-30 18:18 ` Steve Kargl
@ 2011-10-07 21:14   ` Mikael Morin
  0 siblings, 0 replies; 26+ messages in thread
From: Mikael Morin @ 2011-10-07 21:14 UTC (permalink / raw)
  To: fortran; +Cc: Steve Kargl, GCC patches

On Friday 30 September 2011 18:51:21 Steve Kargl wrote:
> Mikael,
> 
> I've finally made it through the set of patches,
> and did not find anything that raised a red flag.
> I'll note that I did not study the issue/question
> you raised with patch 6.  Tobias is probably the
> best person to offer an opinion.  After pinging
> patch 6 off of Tobias, I think the code can be
> committed.

Thanks, I have (finally) committed the patches.
Here are the commit revisions:
01: 179671
02: 179672
03: 179674
04: 179675
05: 179676
06: skipped
07: 179677
08: 179679
09: 179680
10: 179681
11: 179682
12: 179683
13: 179684
14: 179685
15: 179686
16: 179689
17: 179690
18: 179691
19: 179692
20: 179693
21: 179694

Mikael

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

end of thread, other threads:[~2011-10-07 20:41 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-15 23:09 [Patch, fortran] [00/21] Remove coarray support in the scalarizer Mikael Morin
2011-09-15 23:09 ` [Patch, fortran] [01/21] Remove coarray support in the scalarizer: Remove is_coarray Mikael Morin
2011-09-15 23:09 ` [Patch, fortran] [02/21] Remove coarray support in the scalarizer: Move coarray resolution code around Mikael Morin
2011-09-15 23:09 ` [Patch, fortran] [10/21] Remove coarray support in the scalarizer: Factor bound evaluation Mikael Morin
2011-09-15 23:10 ` [Patch, fortran] [08/21] Remove coarray support in the scalarizer: Factor array ref references Mikael Morin
2011-09-15 23:10 ` [Patch, fortran] [17/21] Remove coarray support in the scalarizer: Remove gfc_ss::dimen field Mikael Morin
2011-09-15 23:10 ` [Patch, fortran] [14/21] Remove coarray support in the scalarizer: Fix full array dimension type Mikael Morin
2011-09-15 23:10 ` [Patch, fortran] [03/21] Remove coarray support in the scalarizer: Simplify coarray descriptor setup Mikael Morin
2011-09-15 23:10 ` [Patch, fortran] [19/21] Remove coarray support in the scalarizer: Remove coarray_last argument Mikael Morin
2011-09-15 23:10 ` [Patch, fortran] [21/21] Remove coarray support in the scalarizer: Final cleanup Mikael Morin
2011-09-15 23:10 ` [Patch, fortran] [16/21] Remove coarray support in the scalarizer: Remove gfc_loopinfo::codimen Mikael Morin
2011-09-15 23:10 ` [Patch, fortran] [13/21] Remove coarray support in the scalarizer: Add specific walk_coarray function Mikael Morin
2011-09-15 23:10 ` [Patch, fortran] [07/21] Remove coarray support in the scalarizer: Use codim as argument gfc_get_array_type_bounds Mikael Morin
2011-09-15 23:10 ` [Patch, fortran] [05/21] Remove coarray support in the scalarizer: Calculate codim earlier Mikael Morin
2011-09-15 23:10 ` [Patch, fortran] [06/21] Remove coarray support in the scalarizer: Request coarray for an actual arg associed with a coarray dummy Mikael Morin
2011-10-02 16:35   ` Tobias Burnus
2011-09-15 23:10 ` [Patch, fortran] [20/21] Remove coarray support in the scalarizer: Remove coarray argument Mikael Morin
2011-09-15 23:10 ` [Patch, fortran] [04/21] Remove coarray support in the scalarizer: Fix gfc_get_corank Mikael Morin
2011-09-15 23:10 ` [Patch, fortran] [09/21] Remove coarray support in the scalarizer: Accept coarray dimensions in gfc_conv_section_startstride Mikael Morin
2011-09-16  0:43 ` [Patch, fortran] [12/21] Remove coarray support in the scalarizer: Get cobounds without the scalarizer Mikael Morin
2011-09-16  5:25 ` [Patch, fortran] [15/21] Remove coarray support in the scalarizer: Remove gfc_ss::data::temp_ss::codimen field Mikael Morin
2011-09-16  5:47 ` [Patch, fortran] [11/21] Remove coarray support in the scalarizer: Support 0-rank loop in gfc_conv_ss_startstride Mikael Morin
2011-09-16  6:18 ` [Patch, fortran] [18/21] Remove coarray support in the scalarizer: Cleanup gfc_walk_variable_expr Mikael Morin
2011-09-23  7:36 ` [Patch, fortran] [00/21] Remove coarray support in the scalarizer Steve Kargl
2011-09-30 18:18 ` Steve Kargl
2011-10-07 21:14   ` Commit revisions (was: Re: [Patch, fortran] [00/21] Remove coarray support in the scalarizer) Mikael Morin

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).