OSDN Git Service

compiler: Avoid various crashes on error conditions.
[pf3gnuchains/gcc-fork.git] / gcc / graphite-sese-to-poly.c
index 11a73b3..d9bcf27 100644 (file)
@@ -190,8 +190,7 @@ free_data_refs_aux (VEC (data_reference_p, heap) *datarefs)
       {
        base_alias_pair *bap = (base_alias_pair *)(dr->aux);
 
-       if (bap->alias_set)
-         free (bap->alias_set);
+       free (bap->alias_set);
 
        free (bap);
        dr->aux = NULL;
@@ -1093,7 +1092,7 @@ build_loop_iteration_domains (scop_p scop, struct loop *loop,
       scan_tree_for_params (SCOP_REGION (scop), nb_iters, ub_expr, one);
       mpz_clear (one);
 
-      if (estimated_loop_iterations (loop, true, &nit))
+      if (max_stmt_executions (loop, true, &nit))
        add_upper_bounds_from_estimated_nit (scop, nit, dim, ub_expr);
 
       /* loop_i <= expr_nb_iters */
@@ -1721,7 +1720,7 @@ write_alias_graph_to_ascii_dimacs (FILE *file, char *comment,
 
   FOR_EACH_VEC_ELT (data_reference_p, drs, i, dr1)
     for (j = i + 1; VEC_iterate (data_reference_p, drs, j, dr2); j++)
-      if (dr_may_alias_p (dr1, dr2))
+      if (dr_may_alias_p (dr1, dr2, true))
        edge_num++;
 
   fprintf (file, "$\n");
@@ -1733,7 +1732,7 @@ write_alias_graph_to_ascii_dimacs (FILE *file, char *comment,
 
   FOR_EACH_VEC_ELT (data_reference_p, drs, i, dr1)
     for (j = i + 1; VEC_iterate (data_reference_p, drs, j, dr2); j++)
-      if (dr_may_alias_p (dr1, dr2))
+      if (dr_may_alias_p (dr1, dr2, true))
        fprintf (file, "e %d %d\n", i + 1, j + 1);
 
   return true;
@@ -1763,7 +1762,7 @@ write_alias_graph_to_ascii_dot (FILE *file, char *comment,
 
   FOR_EACH_VEC_ELT (data_reference_p, drs, i, dr1)
     for (j = i + 1; VEC_iterate (data_reference_p, drs, j, dr2); j++)
-      if (dr_may_alias_p (dr1, dr2))
+      if (dr_may_alias_p (dr1, dr2, true))
        fprintf (file, "n%d n%d\n", i, j);
 
   return true;
@@ -1789,7 +1788,7 @@ write_alias_graph_to_ascii_ecc (FILE *file, char *comment,
 
   FOR_EACH_VEC_ELT (data_reference_p, drs, i, dr1)
     for (j = i + 1; VEC_iterate (data_reference_p, drs, j, dr2); j++)
-      if (dr_may_alias_p (dr1, dr2))
+      if (dr_may_alias_p (dr1, dr2, true))
        fprintf (file, "%d %d\n", i, j);
 
   return true;
@@ -1825,7 +1824,7 @@ build_alias_set_optimal_p (VEC (data_reference_p, heap) *drs)
 
   FOR_EACH_VEC_ELT (data_reference_p, drs, i, dr1)
     for (j = i+1; VEC_iterate (data_reference_p, drs, j, dr2); j++)
-      if (dr_may_alias_p (dr1, dr2))
+      if (dr_may_alias_p (dr1, dr2, true))
        {
          add_edge (g, i, j);
          add_edge (g, j, i);
@@ -2898,6 +2897,30 @@ initial_value_for_loop_phi (gimple phi)
   return NULL_TREE;
 }
 
+/* Returns true when DEF is used outside the reduction cycle of
+   LOOP_PHI.  */
+
+static bool
+used_outside_reduction (tree def, gimple loop_phi)
+{
+  use_operand_p use_p;
+  imm_use_iterator imm_iter;
+  loop_p loop = loop_containing_stmt (loop_phi);
+
+  /* In LOOP, DEF should be used only in LOOP_PHI.  */
+  FOR_EACH_IMM_USE_FAST (use_p, imm_iter, def)
+    {
+      gimple stmt = USE_STMT (use_p);
+
+      if (stmt != loop_phi
+         && !is_gimple_debug (stmt)
+         && flow_bb_inside_loop_p (loop, gimple_bb (stmt)))
+       return true;
+    }
+
+  return false;
+}
+
 /* Detect commutative and associative scalar reductions belonging to
    the SCOP starting at the loop closed phi node STMT.  Return the phi
    node of the reduction cycle, or NULL.  */
@@ -2908,8 +2931,8 @@ detect_commutative_reduction (scop_p scop, gimple stmt, VEC (gimple, heap) **in,
 {
   if (scalar_close_phi_node_p (stmt))
     {
-      tree arg = gimple_phi_arg_def (stmt, 0);
-      gimple def, loop_phi;
+      gimple def, loop_phi, phi, close_phi = stmt;
+      tree init, lhs, arg = gimple_phi_arg_def (close_phi, 0);
 
       if (TREE_CODE (arg) != SSA_NAME)
        return NULL;
@@ -2917,26 +2940,24 @@ detect_commutative_reduction (scop_p scop, gimple stmt, VEC (gimple, heap) **in,
       /* Note that loop close phi nodes should have a single argument
         because we translated the representation into a canonical form
         before Graphite: see canonicalize_loop_closed_ssa_form.  */
-      gcc_assert (gimple_phi_num_args (stmt) == 1);
+      gcc_assert (gimple_phi_num_args (close_phi) == 1);
 
       def = SSA_NAME_DEF_STMT (arg);
-      if (!stmt_in_sese_p (def, SCOP_REGION (scop)))
+      if (!stmt_in_sese_p (def, SCOP_REGION (scop))
+         || !(loop_phi = detect_commutative_reduction (scop, def, in, out)))
        return NULL;
 
-      loop_phi = detect_commutative_reduction (scop, def, in, out);
-
-      if (loop_phi)
-       {
-         tree lhs = gimple_phi_result (stmt);
-         tree init = initial_value_for_loop_phi (loop_phi);
-         gimple phi = follow_inital_value_to_phi (init, lhs);
+      lhs = gimple_phi_result (close_phi);
+      init = initial_value_for_loop_phi (loop_phi);
+      phi = follow_inital_value_to_phi (init, lhs);
 
-         VEC_safe_push (gimple, heap, *in, loop_phi);
-         VEC_safe_push (gimple, heap, *out, stmt);
-         return phi;
-       }
-      else
+      if (phi && (used_outside_reduction (lhs, phi)
+                 || !has_single_use (gimple_phi_result (phi))))
        return NULL;
+
+      VEC_safe_push (gimple, heap, *in, loop_phi);
+      VEC_safe_push (gimple, heap, *out, close_phi);
+      return phi;
     }
 
   if (gimple_code (stmt) == GIMPLE_ASSIGN)
@@ -3139,7 +3160,7 @@ rewrite_commutative_reductions_out_of_ssa_close_phi (scop_p scop,
   VEC (gimple, heap) *out = VEC_alloc (gimple, heap, 10);
 
   detect_commutative_reduction (scop, close_phi, &in, &out);
-  res = VEC_length (gimple, in) > 0;
+  res = VEC_length (gimple, in) > 1;
   if (res)
     translate_scalar_reduction_to_array (scop, in, out);
 
@@ -3198,9 +3219,6 @@ rewrite_commutative_reductions_out_of_ssa (scop_p scop)
     }
 }
 
-/* Java does not initialize long_long_integer_type_node.  */
-#define my_long_long (long_long_integer_type_node ? long_long_integer_type_node : ssizetype)
-
 /* Can all ivs be represented by a signed integer?
    As CLooG might generate negative values in its expressions, signed loop ivs
    are required in the backend. */
@@ -3225,7 +3243,7 @@ scop_ivs_can_be_represented (scop_p scop)
          tree type = TREE_TYPE (res);
 
          if (TYPE_UNSIGNED (type)
-             && TYPE_PRECISION (type) >= TYPE_PRECISION (my_long_long))
+             && TYPE_PRECISION (type) >= TYPE_PRECISION (long_long_integer_type_node))
            return false;
        }
     }
@@ -3233,8 +3251,6 @@ scop_ivs_can_be_represented (scop_p scop)
   return true;
 }
 
-#undef my_long_long
-
 /* Builds the polyhedral representation for a SESE region.  */
 
 void