This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, fortran] [40..43/66] inline sum and product: Update the scalarizer: New gfc_ss::parent field.


We are going to loop over the parent array infos.
This introduces a new parent field to permit this loop (patch 40).
Then it will be used to loop over multiple parent ss:
 - gfc_set_loop_bounds_from_array_spec (patch 41 with context diff)
 - gfc_trans_array_constructor (patch 42)
 - set_vector_loop_bounds (patch 43)
OK?

Attachment: pr43829-40.CL
Description: Text document

diff --git a/trans-array.c b/trans-array.c
index d386a22..abff8b5 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -3193,7 +3193,8 @@ gfc_trans_scalarizing_loops (gfc_loopinfo * loop, stmtblock_t * body)
 
   /* Clear all the used flags.  */
   for (ss = loop->ss; ss != gfc_ss_terminator; ss = ss->loop_chain)
-    ss->info->useflags = 0;
+    if (ss->parent == NULL)
+      ss->info->useflags = 0;
 }
 
 
diff --git a/trans-expr.c b/trans-expr.c
index e091c89..72d35f8 100644
--- a/trans-expr.c
+++ b/trans-expr.c
@@ -83,6 +83,7 @@ void
 gfc_advance_se_ss_chain (gfc_se * se)
 {
   gfc_se *p;
+  gfc_ss *ss;
 
   gcc_assert (se != NULL && se->ss != NULL && se->ss != gfc_ss_terminator);
 
@@ -93,7 +94,15 @@ gfc_advance_se_ss_chain (gfc_se * se)
       /* Simple consistency check.  */
       gcc_assert (p->parent == NULL || p->parent->ss == p->ss);
 
-      p->ss = p->ss->next;
+      /* If we were in a nested loop, the next scalarized expression can be
+	 on the parent ss' next pointer.  Thus we should not take the next
+	 pointer blindly, but rather go up one nest level as long as next
+	 is the end of chain.  */
+      ss = p->ss;
+      while (ss->next == gfc_ss_terminator && ss->parent != NULL)
+	ss = ss->parent;
+
+      p->ss = ss->next;
 
       p = p->parent;
     }
diff --git a/trans.h b/trans.h
index 62bcc64..53c5ce2 100644
--- a/trans.h
+++ b/trans.h
@@ -246,6 +246,9 @@ typedef struct gfc_ss
   struct gfc_ss *loop_chain;
   struct gfc_ss *next;
 
+  /* Non-null if the ss is part of a nested loop.  */
+  struct gfc_ss *parent;
+
   /* The loop this gfc_ss is in.  */
   struct gfc_loopinfo *loop;
 

Attachment: pr43829-41.CL
Description: Text document

diff --git a/trans-array.c b/trans-array.c
index abff8b5..83542f6 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -688,41 +688,54 @@ void
 gfc_set_loop_bounds_from_array_spec (gfc_interface_mapping * mapping,
 				     gfc_se * se, gfc_array_spec * as)
 {
-  int n, dim;
+  int n, dim, total_dim;
   gfc_se tmpse;
+  gfc_ss *ss;
   tree lower;
   tree upper;
   tree tmp;
 
-  if (as && as->type == AS_EXPLICIT)
-    for (n = 0; n < se->loop->dimen; n++)
-      {
-	dim = se->ss->dim[n];
-	gcc_assert (dim < as->rank);
-	gcc_assert (se->loop->dimen == as->rank);
-	if (se->loop->to[n] == NULL_TREE)
-	  {
-	    /* Evaluate the lower bound.  */
-	    gfc_init_se (&tmpse, NULL);
-	    gfc_apply_interface_mapping (mapping, &tmpse, as->lower[dim]);
-	    gfc_add_block_to_block (&se->pre, &tmpse.pre);
-	    gfc_add_block_to_block (&se->post, &tmpse.post);
-	    lower = fold_convert (gfc_array_index_type, tmpse.expr);
-
-	    /* ...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;
-	  }
-      }
+  total_dim = 0;
+
+  if (!as || as->type != AS_EXPLICIT)
+    return;
+
+  for (ss = se->ss; ss; ss = ss->parent)
+    {
+      total_dim += ss->loop->dimen;
+      for (n = 0; n < ss->loop->dimen; n++)
+	{
+	  /* The bound is known, nothing to do.  */
+	  if (ss->loop->to[n] != NULL_TREE)
+	    continue;
+
+	  dim = ss->dim[n];
+	  gcc_assert (dim < as->rank);
+	  gcc_assert (ss->loop->dimen <= as->rank);
+
+	  /* Evaluate the lower bound.  */
+	  gfc_init_se (&tmpse, NULL);
+	  gfc_apply_interface_mapping (mapping, &tmpse, as->lower[dim]);
+	  gfc_add_block_to_block (&se->pre, &tmpse.pre);
+	  gfc_add_block_to_block (&se->post, &tmpse.post);
+	  lower = fold_convert (gfc_array_index_type, tmpse.expr);
+
+	  /* ...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);
+	  ss->loop->to[n] = tmp;
+	}
+    }
+
+  gcc_assert (total_dim == as->rank);
 }
 
 
diff --git a/trans-array.c b/trans-array.c
index abff8b5dc732457e5f31957c3728c51340354688..83542f668111b5e43261782ef91bcb2377bfdd46 100644
*** a/trans-array.c
--- b/trans-array.c
*************** void
*** 688,707 ****
  gfc_set_loop_bounds_from_array_spec (gfc_interface_mapping * mapping,
  				     gfc_se * se, gfc_array_spec * as)
  {
!   int n, dim;
    gfc_se tmpse;
    tree lower;
    tree upper;
    tree tmp;
  
!   if (as && as->type == AS_EXPLICIT)
!     for (n = 0; n < se->loop->dimen; n++)
        {
! 	dim = se->ss->dim[n];
! 	gcc_assert (dim < as->rank);
! 	gcc_assert (se->loop->dimen == as->rank);
! 	if (se->loop->to[n] == NULL_TREE)
  	  {
  	    /* Evaluate the lower bound.  */
  	    gfc_init_se (&tmpse, NULL);
  	    gfc_apply_interface_mapping (mapping, &tmpse, as->lower[dim]);
--- 688,718 ----
  gfc_set_loop_bounds_from_array_spec (gfc_interface_mapping * mapping,
  				     gfc_se * se, gfc_array_spec * as)
  {
!   int n, dim, total_dim;
    gfc_se tmpse;
+   gfc_ss *ss;
    tree lower;
    tree upper;
    tree tmp;
  
!   total_dim = 0;
! 
!   if (!as || as->type != AS_EXPLICIT)
!     return;
! 
!   for (ss = se->ss; ss; ss = ss->parent)
      {
!       total_dim += ss->loop->dimen;
!       for (n = 0; n < ss->loop->dimen; n++)
  	{
+ 	  /* The bound is known, nothing to do.  */
+ 	  if (ss->loop->to[n] != NULL_TREE)
+ 	    continue;
+ 
+ 	  dim = ss->dim[n];
+ 	  gcc_assert (dim < as->rank);
+ 	  gcc_assert (ss->loop->dimen <= as->rank);
+ 
  	  /* Evaluate the lower bound.  */
  	  gfc_init_se (&tmpse, NULL);
  	  gfc_apply_interface_mapping (mapping, &tmpse, as->lower[dim]);
*************** gfc_set_loop_bounds_from_array_spec (gfc
*** 720,728 ****
  	    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;
  	  }
        }
  }
  
  
--- 731,741 ----
  	  tmp = fold_build2_loc (input_location, MINUS_EXPR,
  				 gfc_array_index_type, upper, lower);
  	  tmp = gfc_evaluate_now (tmp, &se->pre);
! 	  ss->loop->to[n] = tmp;
  	}
      }
+ 
+   gcc_assert (total_dim == as->rank);
  }
  
  

Attachment: pr43829-42.CL
Description: Text document

diff --git a/trans-array.c b/trans-array.c
index 83542f6..463a0a2 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -1953,6 +1953,7 @@ trans_constant_array_constructor (gfc_ss * ss, tree type)
     }
 }
 
+
 /* Helper routine of gfc_trans_array_constructor to determine if the
    bounds of the loop specified by LOOP are constant and simple enough
    to use with trans_constant_array_constructor.  Returns the
@@ -2010,6 +2011,7 @@ trans_array_constructor (gfc_ss * ss, locus * where)
   gfc_loopinfo *loop;
   gfc_ss_info *ss_info;
   gfc_expr *expr;
+  gfc_ss *s;
 
   /* Save the old values for nested checking.  */
   old_first_len = first_len;
@@ -2078,16 +2080,20 @@ trans_array_constructor (gfc_ss * ss, locus * where)
   if (expr->shape && loop->dimen > 1 && loop->to[0] == NULL_TREE)
     {
       /* We have a multidimensional parameter.  */
-      int n;
-      for (n = 0; n < expr->rank; n++)
-      {
-	loop->from[n] = gfc_index_zero_node;
-	loop->to[n] = gfc_conv_mpz_to_tree (expr->shape [n],
-					    gfc_index_integer_kind);
-	loop->to[n] = fold_build2_loc (input_location, MINUS_EXPR,
-			  	       gfc_array_index_type,
-				       loop->to[n], gfc_index_one_node);
-      }
+      for (s = ss; s; s = s->parent)
+	{
+	  int n;
+	  for (n = 0; n < s->loop->dimen; n++)
+	    {
+	      s->loop->from[n] = gfc_index_zero_node;
+	      s->loop->to[n] = gfc_conv_mpz_to_tree (expr->shape[s->dim[n]],
+						     gfc_index_integer_kind);
+	      s->loop->to[n] = fold_build2_loc (input_location, MINUS_EXPR,
+						gfc_array_index_type,
+						s->loop->to[n],
+						gfc_index_one_node);
+	    }
+	}
     }
 
   if (loop->to[0] == NULL_TREE)

Attachment: pr43829-43.CL
Description: Text document

diff --git a/trans-array.c b/trans-array.c
index 463a0a2..25d9a37 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -2197,14 +2197,18 @@ set_vector_loop_bounds (gfc_ss * ss)
   int dim;
 
   info = &ss->info->data.array;
-  loop = ss->loop;
 
-  for (n = 0; n < loop->dimen; n++)
+  for (; ss; ss = ss->parent)
     {
-      dim = ss->dim[n];
-      if (info->ref->u.ar.dimen_type[dim] == DIMEN_VECTOR
-	  && loop->to[n] == NULL)
+      loop = ss->loop;
+
+      for (n = 0; n < loop->dimen; n++)
 	{
+	  dim = ss->dim[n];
+	  if (info->ref->u.ar.dimen_type[dim] != DIMEN_VECTOR
+	      || loop->to[n] != NULL)
+	    continue;
+
 	  /* Loop variable N indexes vector dimension DIM, and we don't
 	     yet know the upper bound of loop variable N.  Set it to the
 	     difference between the vector's upper and lower bounds.  */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]