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]

Re: [gfortran, committed] Remove if whose condition is always true


As a followup to my previous patch, I'd like to suggest the following, which
factors out some common code between generate_loop_for_temp_to_lhs() and
generate_loop_for_temp_to_lhs().  I didn't do this initially, because 1. I
don't know what this code really does, so the function name is a guess as to
what would make sense and 2. I don't know if the code should remain similar to
what it is currently, given that the related PR 15080 has remained unfixed for
quite a while, and therefore this code might well need a major overhaul anyway.

Bubblestrapped and regtested, ok?

- Tobi

2005-02-13  Tobias Schl"uter  <tobias.schlueter@physik.uni-muenchen.de>

	* trans-stmt.c (initial_assignment): New function, factors out common
	code from ...
	(generate_loop_for_temp_to_lhs, generate_loop_for_temp_to_lhs): ...
	these functions.


cvs diff: Diffing .
Index: trans-stmt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-stmt.c,v
retrieving revision 1.24
diff -u -p -r1.24 trans-stmt.c
--- trans-stmt.c        13 Feb 2005 15:32:45 -0000      1.24
+++ trans-stmt.c        13 Feb 2005 16:32:19 -0000
@@ -1495,6 +1495,38 @@ gfc_do_allocate (tree bytesize, tree siz
   return tmpvar;
 }

+/* Builds an assignment statement for assigning RSE to LSE using the
+   type of EXPR and adds it to BLOCK.  Also builds an assignment mask
+   from WHEREMASK and COUNT3 if WHEREMASK is non-NULL.  */
+
+static void
+initial_assignment (stmtblock_t *block, gfc_se *lse, gfc_se *rse,
+                   gfc_expr *expr, tree wheremask, tree count3)
+{
+  tree tmp, tmp1, tmp2;
+  tree wheremaskexpr;
+
+  /* Use the scalar assignment.  */
+  tmp = gfc_trans_scalar_assign (lse, rse, expr->ts.type);
+
+  /* Form the mask expression according to the mask tree list.  */
+  if (wheremask)
+    {
+      wheremaskexpr = gfc_build_array_ref (wheremask, count3);
+      tmp2 = TREE_CHAIN (wheremask);
+      while (tmp2)
+       {
+         tmp1 = gfc_build_array_ref (tmp2, count3);
+         wheremaskexpr = build2 (TRUTH_AND_EXPR, TREE_TYPE (tmp1),
+                                 wheremaskexpr, tmp1);
+         tmp2 = TREE_CHAIN (tmp2);
+       }
+      tmp = build3_v (COND_EXPR, wheremaskexpr, tmp, build_empty_stmt ());
+    }
+
+  gfc_add_expr_to_block (block, tmp);
+}
+

 /* Generate codes to copy the temporary to the actual lhs.  */

@@ -1506,9 +1538,8 @@ generate_loop_for_temp_to_lhs (gfc_expr
   gfc_se lse, rse;
   stmtblock_t block, body;
   gfc_loopinfo loop1;
-  tree tmp, tmp2;
+  tree tmp;
   tree index;
-  tree wheremaskexpr;

   /* Walk the lhs.  */
   lss = gfc_walk_expr (expr);
@@ -1572,25 +1603,7 @@ generate_loop_for_temp_to_lhs (gfc_expr
       /* Translate expr.  */
       gfc_conv_expr (&lse, expr);

-      /* Use the scalar assignment.  */
-      tmp = gfc_trans_scalar_assign (&lse, &rse, expr->ts.type);
-
-     /* Form the mask expression according to the mask tree list.  */
-     if (wheremask)
-       {
-        wheremaskexpr = gfc_build_array_ref (wheremask, count3);
-         tmp2 = TREE_CHAIN (wheremask);
-         while (tmp2)
-           {
-             tmp1 = gfc_build_array_ref (tmp2, count3);
-             wheremaskexpr = build2 (TRUTH_AND_EXPR, TREE_TYPE (tmp1),
-                                    wheremaskexpr, tmp1);
-             tmp2 = TREE_CHAIN (tmp2);
-           }
-         tmp = build3_v (COND_EXPR, wheremaskexpr, tmp, build_empty_stmt ());
-       }
-
-      gfc_add_expr_to_block (&body, tmp);
+      initial_assignment (&body, &lse, &rse, expr, wheremask, count3);

       /* Increment count2.  */
       tmp = fold (build2 (PLUS_EXPR, gfc_array_index_type,
@@ -1633,8 +1646,7 @@ generate_loop_for_rhs_to_temp (gfc_expr
   gfc_loopinfo loop;
   gfc_se lse;
   gfc_se rse;
-  tree tmp, tmp2, index;
-  tree wheremaskexpr;
+  tree tmp, index;

   gfc_start_block (&block);

@@ -1676,25 +1688,7 @@ generate_loop_for_rhs_to_temp (gfc_expr
       lse.expr = gfc_build_array_ref (tmp1, index);
     }

-  /* Use the scalar assignment.  */
-  tmp = gfc_trans_scalar_assign (&lse, &rse, expr2->ts.type);
-
-  /* Form the mask expression according to the mask tree list.  */
-  if (wheremask)
-    {
-      wheremaskexpr = gfc_build_array_ref (wheremask, count3);
-      tmp2 = TREE_CHAIN (wheremask);
-      while (tmp2)
-        {
-          tmp1 = gfc_build_array_ref (tmp2, count3);
-          wheremaskexpr = build2 (TRUTH_AND_EXPR, TREE_TYPE (tmp1),
-                                 wheremaskexpr, tmp1);
-          tmp2 = TREE_CHAIN (tmp2);
-        }
-      tmp = build3_v (COND_EXPR, wheremaskexpr, tmp, build_empty_stmt ());
-    }
-
-  gfc_add_expr_to_block (&body1, tmp);
+  initial_assignment (&body1, &lse, &rse, expr2, wheremask, count3);

   if (lss == gfc_ss_terminator)
     {


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