OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / tree-data-ref.c
index b1d1605..d48f020 100644 (file)
@@ -16,8 +16,8 @@ for more details.
 
 You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING.  If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.  */
+Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.  */
 
 /* This pass walks a given loop structure searching for array
    references.  The information about the array accesses is recorded
@@ -78,7 +78,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
-#include "errors.h"
 #include "ggc.h"
 #include "tree.h"
 
@@ -191,7 +190,7 @@ tree_fold_divides_p (tree type,
 {
   /* Determines whether (A == gcd (A, B)).  */
   return integer_zerop 
-    (fold (build (MINUS_EXPR, type, a, tree_fold_gcd (a, b))));
+    (fold_build2 (MINUS_EXPR, type, a, tree_fold_gcd (a, b)));
 }
 
 /* Compute the greatest common denominator of two numbers using
@@ -448,32 +447,21 @@ dump_ddrs (FILE *file, varray_type ddrs)
 
 \f
 
-/* Compute the lowest iteration bound for LOOP.  It is an
-   INTEGER_CST.  */
+/* Initialize LOOP->ESTIMATED_NB_ITERATIONS with the lowest safe
+   approximation of the number of iterations for LOOP.  */
 
 static void
 compute_estimated_nb_iterations (struct loop *loop)
 {
-  tree estimation;
-  struct nb_iter_bound *bound, *next;
-  
-  for (bound = loop->bounds; bound; bound = next)
-    {
-      next = bound->next;
-      estimation = bound->bound;
-
-      if (TREE_CODE (estimation) != INTEGER_CST)
-       continue;
-
-      if (loop->estimated_nb_iterations)
-       {
-         /* Update only if estimation is smaller.  */
-         if (tree_int_cst_lt (estimation, loop->estimated_nb_iterations))
-           loop->estimated_nb_iterations = estimation;
-       }
-      else
-       loop->estimated_nb_iterations = estimation;
-    }
+  struct nb_iter_bound *bound;
+  
+  for (bound = loop->bounds; bound; bound = bound->next)
+    if (TREE_CODE (bound->bound) == INTEGER_CST
+       /* Update only when there is no previous estimation.  */
+       && (chrec_contains_undetermined (loop->estimated_nb_iterations)
+           /* Or when the current estimation is smaller.  */
+           || tree_int_cst_lt (bound->bound, loop->estimated_nb_iterations)))
+      loop->estimated_nb_iterations = bound->bound;
 }
 
 /* Estimate the number of iterations from the size of the data and the
@@ -499,17 +487,17 @@ estimate_niter_from_size_of_data (struct loop *loop,
       || TREE_CODE (element_size) != INTEGER_CST)
     return;
 
-  data_size = fold (build2 (EXACT_DIV_EXPR, integer_type_node, 
-                           array_size, element_size));
+  data_size = fold_build2 (EXACT_DIV_EXPR, integer_type_node,
+                          array_size, element_size);
 
   if (init != NULL_TREE
       && step != NULL_TREE
       && TREE_CODE (init) == INTEGER_CST
       && TREE_CODE (step) == INTEGER_CST)
     {
-      estimation = fold (build2 (CEIL_DIV_EXPR, integer_type_node, 
-                                fold (build2 (MINUS_EXPR, integer_type_node, 
-                                              data_size, init)), step));
+      estimation = fold_build2 (CEIL_DIV_EXPR, integer_type_node,
+                               fold_build2 (MINUS_EXPR, integer_type_node,
+                                            data_size, init), step);
 
       record_estimate (loop, estimation, boolean_true_node, stmt);
     }
@@ -539,7 +527,7 @@ analyze_array_indexes (struct loop *loop,
   access_fn = instantiate_parameters 
     (loop, analyze_scalar_evolution (loop, opnd1));
 
-  if (loop->estimated_nb_iterations == NULL_TREE)
+  if (chrec_contains_undetermined (loop->estimated_nb_iterations))
     estimate_niter_from_size_of_data (loop, opnd0, access_fn, stmt);
   
   VEC_safe_push (tree, heap, *access_fns, access_fn);
@@ -932,10 +920,11 @@ analyze_siv_subscript_cst_affine (tree chrec_a,
                      (integer_type_node, CHREC_RIGHT (chrec_b), difference))
                    {
                      *overlaps_a = integer_zero_node;
-                     *overlaps_b = fold 
-                       (build (EXACT_DIV_EXPR, integer_type_node, 
-                               fold (build1 (ABS_EXPR, integer_type_node, difference)), 
-                               CHREC_RIGHT (chrec_b)));
+                     *overlaps_b = fold_build2 (EXACT_DIV_EXPR, integer_type_node,
+                                                fold_build1 (ABS_EXPR,
+                                                             integer_type_node,
+                                                             difference),
+                                                CHREC_RIGHT (chrec_b));
                      *last_conflicts = integer_one_node;
                      return;
                    }
@@ -1130,8 +1119,12 @@ compute_overlap_steps_for_affine_1_2 (tree chrec_a, tree chrec_b,
     numiter_z = current_loops->parray[CHREC_VARIABLE (chrec_b)]
       ->estimated_nb_iterations;
 
-  if (numiter_x == NULL_TREE || numiter_y == NULL_TREE 
-      || numiter_z == NULL_TREE)
+  if (chrec_contains_undetermined (numiter_x)
+      || chrec_contains_undetermined (numiter_y)
+      || chrec_contains_undetermined (numiter_z)
+      || TREE_CODE (numiter_x) != INTEGER_CST
+      || TREE_CODE (numiter_y) != INTEGER_CST
+      || TREE_CODE (numiter_z) != INTEGER_CST)
     {
       *overlaps_a = chrec_dont_know;
       *overlaps_b = chrec_dont_know;
@@ -1279,7 +1272,10 @@ analyze_subscript_affine_affine (tree chrec_a,
          if (TREE_CODE (numiter_b) != INTEGER_CST)
            numiter_b = current_loops->parray[CHREC_VARIABLE (chrec_b)]
              ->estimated_nb_iterations;
-         if (numiter_a == NULL_TREE || numiter_b == NULL_TREE)
+         if (chrec_contains_undetermined (numiter_a)
+             || chrec_contains_undetermined (numiter_b)
+             || TREE_CODE (numiter_a) != INTEGER_CST
+             || TREE_CODE (numiter_b) != INTEGER_CST)
            {
              *overlaps_a = chrec_dont_know;
              *overlaps_b = chrec_dont_know;
@@ -1380,7 +1376,10 @@ analyze_subscript_affine_affine (tree chrec_a,
          if (TREE_CODE (numiter_b) != INTEGER_CST)
            numiter_b = current_loops->parray[CHREC_VARIABLE (chrec_b)]
              ->estimated_nb_iterations;
-         if (numiter_a == NULL_TREE || numiter_b == NULL_TREE)
+         if (chrec_contains_undetermined (numiter_a)
+             || chrec_contains_undetermined (numiter_b)
+             || TREE_CODE (numiter_a) != INTEGER_CST
+             || TREE_CODE (numiter_b) != INTEGER_CST)
            {
              *overlaps_a = chrec_dont_know;
              *overlaps_b = chrec_dont_know;
@@ -2178,6 +2177,25 @@ compute_affine_dependence (struct data_dependence_relation *ddr)
     fprintf (dump_file, ")\n");
 }
 
+/* This computes the dependence relation for the same data
+   reference into DDR.  */
+
+static void
+compute_self_dependence (struct data_dependence_relation *ddr)
+{
+  unsigned int i;
+
+  for (i = 0; i < DDR_NUM_SUBSCRIPTS (ddr); i++)
+    {
+      struct subscript *subscript = DDR_SUBSCRIPT (ddr, i);
+      
+      /* The accessed index overlaps for each iteration.  */
+      SUB_CONFLICTS_IN_A (subscript) = integer_zero_node;
+      SUB_CONFLICTS_IN_B (subscript) = integer_zero_node;
+      SUB_LAST_CONFLICT (subscript) = chrec_dont_know;
+    }
+}
+
 
 typedef struct data_dependence_relation *ddr_p;
 DEF_VEC_P(ddr_p);
@@ -2197,8 +2215,11 @@ compute_all_dependences (varray_type datarefs,
 
   N = VARRAY_ACTIVE_SIZE (datarefs);
 
+  /* Note that we specifically skip i == j because it's a self dependence, and
+     use compute_self_dependence below.  */
+
   for (i = 0; i < N; i++)
-    for (j = i; j < N; j++)
+    for (j = i + 1; j < N; j++)
       {
        struct data_reference *a, *b;
        struct data_dependence_relation *ddr;
@@ -2211,6 +2232,22 @@ compute_all_dependences (varray_type datarefs,
        compute_affine_dependence (ddr);
        compute_subscript_distance (ddr);
       }
+
+  /* Compute self dependence relation of each dataref to itself.  */
+
+  for (i = 0; i < N; i++)
+    {
+      struct data_reference *a, *b;
+      struct data_dependence_relation *ddr;
+
+      a = VARRAY_GENERIC_PTR (datarefs, i);
+      b = VARRAY_GENERIC_PTR (datarefs, i);
+      ddr = initialize_data_dependence_relation (a, b);
+
+      VEC_safe_push (ddr_p, heap, *dependence_relations, ddr);
+      compute_self_dependence (ddr);
+      compute_subscript_distance (ddr);
+    }
 }
 
 /* Search the data references in LOOP, and record the information into
@@ -2307,11 +2344,11 @@ find_data_references_in_loop (struct loop *loop, varray_type *datarefs)
 
          /* When there are no defs in the loop, the loop is parallel.  */
          if (!ZERO_SSA_OPERANDS (stmt, SSA_OP_VIRTUAL_DEFS))
-           bb->loop_father->parallel_p = false;
+           loop->parallel_p = false;
        }
 
-      if (bb->loop_father->estimated_nb_iterations == NULL_TREE)
-       compute_estimated_nb_iterations (bb->loop_father);
+      if (chrec_contains_undetermined (loop->estimated_nb_iterations))
+       compute_estimated_nb_iterations (loop);
     }
 
   free (bbs);