[lno]: Fix some varray misuse

Daniel Berlin dberlin@dberlin.org
Fri Feb 27 20:58:00 GMT 2004


You can't pass varrays by value, then push to them, then use them later 
in the calling functions. Pushing might realloc them varray, which 
might return new memory, which in turn means your original function no 
longer has a pointer to the correct memory.

Fixed thusly (It fixes some bootstrap problems on powerpc-darwin with 
-fscalar-evolutions turned on)

I'll commit later today.

--Dan


2003-02-26  Daniel Berlin  <dberlin@dberlin.org>

    * tree-scalar-evolution.c (get_exit_conditions_rec): Pass varray as a
    pointer to the varray (because we push to it).
    (find_var_scev_info): Ditto.
    (select_loops_exit_conditions): Ditto.
    (initialize_scalar_evolutions_analyzer): Ditto.
    (scev_anal): Ditto.
    (scev_init): Ditto.
    (scev_info): Make this a pointer to a varray.
    * tree-scalar-evolution.h (select_loops_exit_conditions): Update 
proto.
    (initialize_scalar_evolutions_analyzer): Ditto.

Index: tree-scalar-evolution.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-scalar-evolution.c,v
retrieving revision 1.1.2.14
diff -u -3 -p -r1.1.2.14 tree-scalar-evolution.c
--- tree-scalar-evolution.c	16 Feb 2004 21:59:28 -0000	1.1.2.14
+++ tree-scalar-evolution.c	27 Feb 2004 02:24:45 -0000
@@ -209,7 +209,7 @@ static void wolfe_scc_recurse (unsigned
  			       varray_type, varray_type, unsigned int *);

  /* Selection functions.  */
-static void get_exit_conditions_rec    (struct loop *, varray_type);
+static void get_exit_conditions_rec    (struct loop *, varray_type *);
  static bool analyzable_condition       (tree);

  /* Debugging functions.  */
@@ -240,7 +240,7 @@ tree chrec_bot;
  tree chrec_symbolic_parameter;

  static struct loops *scev_loops;
-static varray_type scev_info;
+static varray_type *scev_info;

  

@@ -2128,16 +2128,16 @@ find_var_scev_info (tree var)
    unsigned int i;
    struct scev_info_str *res;

-  for (i = 0; i < VARRAY_ACTIVE_SIZE (scev_info); i++)
+  for (i = 0; i < VARRAY_ACTIVE_SIZE (*scev_info); i++)
      {
-      res = VARRAY_GENERIC_PTR (scev_info, i);
+      res = VARRAY_GENERIC_PTR (*scev_info, i);
        if (MI_VAR (res) == var)
  	return res;
      }

    /* The variable is not in the table, create a new entry for it.  */
    res = new_scev_info_str (var);
-  VARRAY_PUSH_GENERIC_PTR (scev_info, res);
+  VARRAY_PUSH_GENERIC_PTR (*scev_info, res);

    return res;
  }
@@ -3219,6 +3219,7 @@ record_dependences_for_modify_expr (unsi

    switch (TREE_CODE_LENGTH (TREE_CODE (rhs)))
      {
+    case 3:
      case 2:
        record_dependences_for_opnd
  	(loop_nb, lhs, TREE_OPERAND (rhs, 1), sdd_graph,
@@ -3576,7 +3577,7 @@ analyze_scalars_from_schedule (varray_ty

  void
  select_loops_exit_conditions (struct loops *loops,
-			      varray_type exit_conditions)
+			      varray_type *exit_conditions)
  {
    struct loop *function_body = loops->parray[0];

@@ -3595,7 +3596,7 @@ select_loops_exit_conditions (struct loo
  	  tree loop_condition = get_loop_exit_condition (function_body);

  	  if (loop_condition)
-	    VARRAY_PUSH_TREE (exit_conditions, loop_condition);
+	    VARRAY_PUSH_TREE (*exit_conditions, loop_condition);
  	}
      }
  }
@@ -3604,7 +3605,7 @@ select_loops_exit_conditions (struct loo

  static void
  get_exit_conditions_rec (struct loop *loop,
-			 varray_type exit_conditions)
+			 varray_type *exit_conditions)
  {
    if (!loop)
      return;
@@ -3619,7 +3620,7 @@ get_exit_conditions_rec (struct loop *lo
        tree loop_condition = get_loop_exit_condition (loop);

        if (loop_condition)
-	VARRAY_PUSH_TREE (exit_conditions, loop_condition);
+	VARRAY_PUSH_TREE (*exit_conditions, loop_condition);
      }
  }

@@ -3859,7 +3860,7 @@ sdd2dot (FILE *file,

  void
  initialize_scalar_evolutions_analyzer (struct loops *loops,
-				       varray_type ev_info)
+				       varray_type *ev_info)
  {
    scev_loops = loops;
    scev_info = ev_info;
@@ -4248,12 +4249,12 @@ static void
  scev_init (void)
  {
    current_loops = loop_optimizer_init (NULL);
-	
+  ev_info = NULL;
    if (!current_loops)
      return;

    VARRAY_GENERIC_PTR_INIT (ev_info, 37, "ev_info");
-  initialize_scalar_evolutions_analyzer (current_loops, ev_info);
+  initialize_scalar_evolutions_analyzer (current_loops, &ev_info);
  }

  static void
@@ -4262,7 +4263,7 @@ scev_anal (void)
    varray_type exit_conditions;

    VARRAY_GENERIC_PTR_INIT (exit_conditions, 37, "exit_conditions");
-  select_loops_exit_conditions (current_loops, exit_conditions);
+  select_loops_exit_conditions (current_loops, &exit_conditions);
    number_of_iterations_for_all_loops (exit_conditions);
    varray_clear (exit_conditions);
  }
@@ -4286,7 +4295,7 @@ scev_done (void)
  {
    if (current_loops)
      {
-      varray_clear (ev_info);
+      VARRAY_CLEAR (ev_info);
        finalize_scalar_evolutions_analyzer ();
        loop_optimizer_finalize (current_loops, NULL);
        current_loops = NULL;
Index: tree-scalar-evolution.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-scalar-evolution.h,v
retrieving revision 1.1.2.4
diff -u -3 -p -r1.1.2.4 tree-scalar-evolution.h
--- tree-scalar-evolution.h	29 Jan 2004 18:36:36 -0000	1.1.2.4
+++ tree-scalar-evolution.h	27 Feb 2004 02:24:45 -0000
@@ -31,11 +31,11 @@ extern tree number_of_iterations_in_loop
  extern void number_of_iterations_for_all_loops (varray_type);
  extern tree get_loop_exit_condition (struct loop *);

-extern void select_loops_exit_conditions (struct loops *, varray_type);
+extern void select_loops_exit_conditions (struct loops *, varray_type 
*);
  extern tree analyze_scalar_evolution (unsigned, tree);
  extern tree instantiate_parameters (unsigned, tree, tree);
  extern void initialize_scalar_evolutions_analyzer (struct loops *,
-						   varray_type);
+						   varray_type *);
  extern void finalize_scalar_evolutions_analyzer (void);




More information about the Gcc-patches mailing list