OSDN Git Service

2006-12-05 H.J. Lu <hongjiu.lu@intel.com>
[pf3gnuchains/gcc-fork.git] / gcc / tree-scalar-evolution.c
index 13cbe42..0c59557 100644 (file)
@@ -966,8 +966,7 @@ tree
 get_loop_exit_condition (struct loop *loop)
 {
   tree res = NULL_TREE;
-  edge exit_edge = loop->single_exit;
-
+  edge exit_edge = single_exit (loop);
   
   if (dump_file && (dump_flags & TDF_DETAILS))
     fprintf (dump_file, "(get_loop_exit_condition \n  ");
@@ -1003,7 +1002,7 @@ get_exit_conditions_rec (struct loop *loop,
   get_exit_conditions_rec (loop->inner, exit_conditions);
   get_exit_conditions_rec (loop->next, exit_conditions);
   
-  if (loop->single_exit)
+  if (single_exit (loop))
     {
       tree loop_condition = get_loop_exit_condition (loop);
       
@@ -1016,10 +1015,9 @@ get_exit_conditions_rec (struct loop *loop,
    initializes the EXIT_CONDITIONS array.  */
 
 static void
-select_loops_exit_conditions (struct loops *loops, 
-                             VEC(tree,heap) **exit_conditions)
+select_loops_exit_conditions (VEC(tree,heap) **exit_conditions)
 {
-  struct loop *function_body = loops->parray[0];
+  struct loop *function_body = current_loops->tree_root;
   
   get_exit_conditions_rec (function_body->inner, exit_conditions);
 }
@@ -1765,7 +1763,8 @@ pointer_offset_p (tree expr)
 /* EXPR is a scalar evolution of a pointer that is dereferenced or used in
    comparison.  This means that it must point to a part of some object in
    memory, which enables us to argue about overflows and possibly simplify
-   the EXPR.  Returns the simplified value.
+   the EXPR.  AT_STMT is the statement in which this conversion has to be
+   performed.  Returns the simplified value.
 
    Currently, for
 
@@ -1820,7 +1819,7 @@ pointer_offset_p (tree expr)
    bugs.  */
 
 static tree
-fold_used_pointer (tree expr)
+fold_used_pointer (tree expr, tree at_stmt)
 {
   tree op0, op1, new0, new1;
   enum tree_code code = TREE_CODE (expr);
@@ -1833,13 +1832,13 @@ fold_used_pointer (tree expr)
 
       if (pointer_offset_p (op1))
        {
-         new0 = fold_used_pointer (op0);
+         new0 = fold_used_pointer (op0, at_stmt);
          new1 = fold_used_pointer_cast (op1);
        }
       else if (code == PLUS_EXPR && pointer_offset_p (op0))
        {
          new0 = fold_used_pointer_cast (op0);
-         new1 = fold_used_pointer (op1);
+         new1 = fold_used_pointer (op1, at_stmt);
        }
       else
        return expr;
@@ -1847,6 +1846,9 @@ fold_used_pointer (tree expr)
       if (new0 == op0 && new1 == op1)
        return expr;
 
+      new0 = chrec_convert (TREE_TYPE (expr), new0, at_stmt);
+      new1 = chrec_convert (TREE_TYPE (expr), new1, at_stmt);
+
       if (code == PLUS_EXPR)
        expr = chrec_fold_plus (TREE_TYPE (expr), new0, new1);
       else
@@ -1948,7 +1950,7 @@ analyze_scalar_evolution_1 (struct loop *loop, tree var, tree res)
       if (POINTER_TYPE_P (type)
          && !automatically_generated_chrec_p (res)
          && pointer_used_p (var))
-       res = fold_used_pointer (res);
+       res = fold_used_pointer (res, def);
       break;
 
     case PHI_NODE:
@@ -2103,7 +2105,7 @@ loop_closed_phi_def (tree var)
     return NULL_TREE;
 
   loop = loop_containing_stmt (SSA_NAME_DEF_STMT (var));
-  exit = loop->single_exit;
+  exit = single_exit (loop);
   if (!exit)
     return NULL_TREE;
 
@@ -2481,7 +2483,7 @@ number_of_iterations_in_loop (struct loop *loop)
   if (dump_file && (dump_flags & TDF_DETAILS))
     fprintf (dump_file, "(number_of_iterations_in_loop\n");
   
-  exit = loop->single_exit;
+  exit = single_exit (loop);
   if (!exit)
     goto end;
 
@@ -2742,10 +2744,9 @@ initialize_scalar_evolutions_analyzer (void)
 /* Initialize the analysis of scalar evolutions for LOOPS.  */
 
 void
-scev_initialize (struct loops *loops)
+scev_initialize (void)
 {
   unsigned i;
-  current_loops = loops;
 
   scalar_evolution_info = htab_create (100, hash_scev_info,
                                       eq_scev_info, del_scev_info);
@@ -2753,9 +2754,9 @@ scev_initialize (struct loops *loops)
   
   initialize_scalar_evolutions_analyzer ();
 
-  for (i = 1; i < loops->num; i++)
-    if (loops->parray[i])
-      loops->parray[i]->nb_iterations = NULL_TREE;
+  for (i = 1; i < current_loops->num; i++)
+    if (current_loops->parray[i])
+      current_loops->parray[i]->nb_iterations = NULL_TREE;
 }
 
 /* Cleans up the information cached by the scalar evolutions analysis.  */
@@ -2847,7 +2848,7 @@ scev_analysis (void)
   VEC(tree,heap) *exit_conditions;
   
   exit_conditions = VEC_alloc (tree, heap, 37);
-  select_loops_exit_conditions (current_loops, &exit_conditions);
+  select_loops_exit_conditions (&exit_conditions);
 
   if (dump_file && (dump_flags & TDF_STATS))
     analyze_scalar_evolution_for_all_loop_phi_nodes (&exit_conditions);
@@ -2957,7 +2958,7 @@ scev_const_prop (void)
 
       /* If we do not know exact number of iterations of the loop, we cannot
         replace the final value.  */
-      exit = loop->single_exit;
+      exit = single_exit (loop);
       if (!exit)
        continue;