Commit 283a2545 by Robert Lipe Committed by Robert Lipe

gcse.c (expr_reaches_here_p): Use xcalloc and explit free instead of alloca.

        * gcse.c (expr_reaches_here_p): Use xcalloc and explit free instead
        of alloca.
        (pre_gcse): Likewise.
        (hoist_expr_reaches_here_p): Likewise.
        (hoist_code): Likewise.
        (pre_expr_reaches_here_p): Replace alloca with xcalloc.   Move core
        code to ...
        (pre_expr_reaches_here_p_work): ... here.
        (expr_reaches_here_p): Replace alloca with xcalloc.   Move core
        code to ...
        (expr_reaches_here_p_work): ... here.

From-SVN: r30207
parent d0247326
Wed Oct 27 00:14:13 1999 Robert Lipe <robertlipe@usa.net>
* gcse.c (expr_reaches_here_p): Use xcalloc and explit free instead
of alloca.
(pre_gcse): Likewise.
(hoist_expr_reaches_here_p): Likewise.
(hoist_code): Likewise.
(pre_expr_reaches_here_p): Replace alloca with xcalloc. Move core
code to ...
(pre_expr_reaches_here_p_work): ... here.
(expr_reaches_here_p): Replace alloca with xcalloc. Move core
code to ...
(expr_reaches_here_p_work): ... here.
Tue Oct 26 20:42:45 1999 Richard Henderson <rth@cygnus.com> Tue Oct 26 20:42:45 1999 Richard Henderson <rth@cygnus.com>
* resource.c (find_basic_block): Delete. * resource.c (find_basic_block): Delete.
......
...@@ -585,7 +585,7 @@ static void alloc_pre_mem PROTO ((int, int)); ...@@ -585,7 +585,7 @@ static void alloc_pre_mem PROTO ((int, int));
static void free_pre_mem PROTO ((void)); static void free_pre_mem PROTO ((void));
static void compute_pre_data PROTO ((void)); static void compute_pre_data PROTO ((void));
static int pre_expr_reaches_here_p PROTO ((int, struct expr *, static int pre_expr_reaches_here_p PROTO ((int, struct expr *,
int, int, char *)); int, int));
static void insert_insn_end_bb PROTO ((struct expr *, int, int)); static void insert_insn_end_bb PROTO ((struct expr *, int, int));
static void pre_insert_copy_insn PROTO ((struct expr *, rtx)); static void pre_insert_copy_insn PROTO ((struct expr *, rtx));
static void pre_insert_copies PROTO ((void)); static void pre_insert_copies PROTO ((void));
...@@ -614,7 +614,7 @@ static void compute_ae_gen PROTO ((void)); ...@@ -614,7 +614,7 @@ static void compute_ae_gen PROTO ((void));
static int expr_killed_p PROTO ((rtx, int)); static int expr_killed_p PROTO ((rtx, int));
static void compute_ae_kill PROTO ((sbitmap *, sbitmap *)); static void compute_ae_kill PROTO ((sbitmap *, sbitmap *));
static int expr_reaches_here_p PROTO ((struct occr *, struct expr *, static int expr_reaches_here_p PROTO ((struct occr *, struct expr *,
int, int, char *)); int, int));
static rtx computing_insn PROTO ((struct expr *, rtx)); static rtx computing_insn PROTO ((struct expr *, rtx));
static int def_reaches_here_p PROTO ((rtx, rtx)); static int def_reaches_here_p PROTO ((rtx, rtx));
static int can_disregard_other_sets PROTO ((struct reg_set **, rtx, int)); static int can_disregard_other_sets PROTO ((struct reg_set **, rtx, int));
...@@ -2881,7 +2881,7 @@ compute_ae_kill (ae_gen, ae_kill) ...@@ -2881,7 +2881,7 @@ compute_ae_kill (ae_gen, ae_kill)
the closest such expression. */ the closest such expression. */
static int static int
expr_reaches_here_p (occr, expr, bb, check_self_loop, visited) expr_reaches_here_p_work (occr, expr, bb, check_self_loop, visited)
struct occr *occr; struct occr *occr;
struct expr *expr; struct expr *expr;
int bb; int bb;
...@@ -2890,12 +2890,6 @@ expr_reaches_here_p (occr, expr, bb, check_self_loop, visited) ...@@ -2890,12 +2890,6 @@ expr_reaches_here_p (occr, expr, bb, check_self_loop, visited)
{ {
edge pred; edge pred;
if (visited == NULL)
{
visited = (char *) alloca (n_basic_blocks);
bzero (visited, n_basic_blocks);
}
for (pred = BASIC_BLOCK(bb)->pred; pred != NULL; pred = pred->pred_next) for (pred = BASIC_BLOCK(bb)->pred; pred != NULL; pred = pred->pred_next)
{ {
int pred_bb = pred->src->index; int pred_bb = pred->src->index;
...@@ -2932,7 +2926,8 @@ expr_reaches_here_p (occr, expr, bb, check_self_loop, visited) ...@@ -2932,7 +2926,8 @@ expr_reaches_here_p (occr, expr, bb, check_self_loop, visited)
else else
{ {
visited[pred_bb] = 1; visited[pred_bb] = 1;
if (expr_reaches_here_p (occr, expr, pred_bb, check_self_loop, visited)) if (expr_reaches_here_p_work (occr, expr, pred_bb, check_self_loop,
visited))
return 1; return 1;
} }
} }
...@@ -2941,6 +2936,26 @@ expr_reaches_here_p (occr, expr, bb, check_self_loop, visited) ...@@ -2941,6 +2936,26 @@ expr_reaches_here_p (occr, expr, bb, check_self_loop, visited)
return 0; return 0;
} }
/* This wrapper for expr_reaches_here_p_work() is to ensure that any
memory allocated for that function is returned. */
static int
expr_reaches_here_p (occr, expr, bb, check_self_loop)
struct occr *occr;
struct expr *expr;
int bb;
int check_self_loop;
{
int rval;
char * visited = (char *) xcalloc (n_basic_blocks, 1);
rval = expr_reaches_here_p_work(occr, expr, bb, check_self_loop, visited);
free (visited);
return (rval);
}
/* Return the instruction that computes EXPR that reaches INSN's basic block. /* Return the instruction that computes EXPR that reaches INSN's basic block.
If there is more than one such instruction, return NULL. If there is more than one such instruction, return NULL.
...@@ -2984,7 +2999,7 @@ computing_insn (expr, insn) ...@@ -2984,7 +2999,7 @@ computing_insn (expr, insn)
We let the normal cse pass handle the other cases. */ We let the normal cse pass handle the other cases. */
if (INSN_CUID (insn) < INSN_CUID (occr->insn)) if (INSN_CUID (insn) < INSN_CUID (occr->insn))
{ {
if (expr_reaches_here_p (occr, expr, bb, 1, NULL)) if (expr_reaches_here_p (occr, expr, bb, 1))
{ {
can_reach++; can_reach++;
if (can_reach > 1) if (can_reach > 1)
...@@ -2995,7 +3010,7 @@ computing_insn (expr, insn) ...@@ -2995,7 +3010,7 @@ computing_insn (expr, insn)
} }
else /* Computation of the pattern outside this block. */ else /* Computation of the pattern outside this block. */
{ {
if (expr_reaches_here_p (occr, expr, bb, 0, NULL)) if (expr_reaches_here_p (occr, expr, bb, 0))
{ {
can_reach++; can_reach++;
if (can_reach > 1) if (can_reach > 1)
...@@ -4178,7 +4193,7 @@ compute_pre_data () ...@@ -4178,7 +4193,7 @@ compute_pre_data ()
the closest such expression. */ the closest such expression. */
static int static int
pre_expr_reaches_here_p (occr_bb, expr, bb, check_pre_comp, visited) pre_expr_reaches_here_p_work (occr_bb, expr, bb, check_pre_comp, visited)
int occr_bb; int occr_bb;
struct expr *expr; struct expr *expr;
int bb; int bb;
...@@ -4187,12 +4202,6 @@ pre_expr_reaches_here_p (occr_bb, expr, bb, check_pre_comp, visited) ...@@ -4187,12 +4202,6 @@ pre_expr_reaches_here_p (occr_bb, expr, bb, check_pre_comp, visited)
{ {
edge pred; edge pred;
if (visited == NULL)
{
visited = (char *) alloca (n_basic_blocks);
bzero (visited, n_basic_blocks);
}
for (pred = BASIC_BLOCK (bb)->pred; pred != NULL; pred = pred->pred_next) for (pred = BASIC_BLOCK (bb)->pred; pred != NULL; pred = pred->pred_next)
{ {
int pred_bb = pred->src->index; int pred_bb = pred->src->index;
...@@ -4221,8 +4230,8 @@ pre_expr_reaches_here_p (occr_bb, expr, bb, check_pre_comp, visited) ...@@ -4221,8 +4230,8 @@ pre_expr_reaches_here_p (occr_bb, expr, bb, check_pre_comp, visited)
else else
{ {
visited[pred_bb] = 1; visited[pred_bb] = 1;
if (pre_expr_reaches_here_p (occr_bb, expr, pred_bb, if (pre_expr_reaches_here_p_work (occr_bb, expr, pred_bb,
check_pre_comp, visited)) check_pre_comp, visited))
return 1; return 1;
} }
} }
...@@ -4230,6 +4239,27 @@ pre_expr_reaches_here_p (occr_bb, expr, bb, check_pre_comp, visited) ...@@ -4230,6 +4239,27 @@ pre_expr_reaches_here_p (occr_bb, expr, bb, check_pre_comp, visited)
/* All paths have been checked. */ /* All paths have been checked. */
return 0; return 0;
} }
/* The wrapper for pre_expr_reaches_here_work that ensures that any
memory allocated for that function is returned. */
static int
pre_expr_reaches_here_p (occr_bb, expr, bb, check_pre_comp)
int occr_bb;
struct expr *expr;
int bb;
int check_pre_comp;
{
int rval;
char * visited = (char *) xcalloc (n_basic_blocks, 1);
rval = pre_expr_reaches_here_p_work(occr_bb, expr, bb, check_pre_comp,
visited);
free (visited);
return (rval);
}
/* Given an expr, generate RTL which we can insert at the end of a BB, /* Given an expr, generate RTL which we can insert at the end of a BB,
...@@ -4472,8 +4502,7 @@ pre_edge_insert (edge_list, index_map) ...@@ -4472,8 +4502,7 @@ pre_edge_insert (edge_list, index_map)
if (!TEST_BIT (inserted[e], j) if (!TEST_BIT (inserted[e], j)
&& (bb == ENTRY_BLOCK && (bb == ENTRY_BLOCK
|| pre_expr_reaches_here_p (bb, expr, || pre_expr_reaches_here_p (bb, expr,
BLOCK_NUM (occr->insn), 0, BLOCK_NUM (occr->insn), 0)))
NULL)))
{ {
rtx insn; rtx insn;
edge eg = INDEX_EDGE (edge_list, e); edge eg = INDEX_EDGE (edge_list, e);
...@@ -4597,8 +4626,7 @@ pre_insert_copies () ...@@ -4597,8 +4626,7 @@ pre_insert_copies ()
continue; continue;
/* Or if the expression doesn't reach the deleted one. */ /* Or if the expression doesn't reach the deleted one. */
if (! pre_expr_reaches_here_p (BLOCK_NUM (avail->insn), expr, if (! pre_expr_reaches_here_p (BLOCK_NUM (avail->insn), expr,
BLOCK_NUM (occr->insn), BLOCK_NUM (occr->insn),1))
1, NULL))
continue; continue;
/* Copy the result of avail to reaching_reg. */ /* Copy the result of avail to reaching_reg. */
...@@ -4719,8 +4747,7 @@ pre_gcse () ...@@ -4719,8 +4747,7 @@ pre_gcse ()
/* Compute a mapping from expression number (`bitmap_index') to /* Compute a mapping from expression number (`bitmap_index') to
hash table entry. */ hash table entry. */
index_map = (struct expr **) alloca (n_exprs * sizeof (struct expr *)); index_map = xcalloc (n_exprs, sizeof (struct expr *));
bzero ((char *) index_map, n_exprs * sizeof (struct expr *));
for (i = 0; i < expr_hash_table_size; i++) for (i = 0; i < expr_hash_table_size; i++)
{ {
struct expr *expr; struct expr *expr;
...@@ -4749,6 +4776,7 @@ pre_gcse () ...@@ -4749,6 +4776,7 @@ pre_gcse ()
changed = 1; changed = 1;
} }
free (index_map);
free (pre_redundant_insns); free (pre_redundant_insns);
return changed; return changed;
...@@ -4985,10 +5013,10 @@ delete_null_pointer_checks (f) ...@@ -4985,10 +5013,10 @@ delete_null_pointer_checks (f)
/* We need predecessor/successor lists as well as pred/succ counts for /* We need predecessor/successor lists as well as pred/succ counts for
each basic block. */ each basic block. */
s_preds = (int_list_ptr *) alloca (n_basic_blocks * sizeof (int_list_ptr)); s_preds = (int_list_ptr *) gmalloc (n_basic_blocks * sizeof (int_list_ptr));
s_succs = (int_list_ptr *) alloca (n_basic_blocks * sizeof (int_list_ptr)); s_succs = (int_list_ptr *) gmalloc (n_basic_blocks * sizeof (int_list_ptr));
num_preds = (int *) alloca (n_basic_blocks * sizeof (int)); num_preds = (int *) gmalloc (n_basic_blocks * sizeof (int));
num_succs = (int *) alloca (n_basic_blocks * sizeof (int)); num_succs = (int *) gmalloc (n_basic_blocks * sizeof (int));
compute_preds_succs (s_preds, s_succs, num_preds, num_succs); compute_preds_succs (s_preds, s_succs, num_preds, num_succs);
/* Allocate bitmaps to hold local and global properties. */ /* Allocate bitmaps to hold local and global properties. */
...@@ -5141,6 +5169,12 @@ delete_null_pointer_checks (f) ...@@ -5141,6 +5169,12 @@ delete_null_pointer_checks (f)
/* Free storage allocated by find_basic_blocks. */ /* Free storage allocated by find_basic_blocks. */
free_basic_block_vars (0); free_basic_block_vars (0);
/* Free our local predecessor/successor lists. */
free (s_preds);
free (s_succs);
free (num_preds);
free (num_succs);
/* Free bitmaps. */ /* Free bitmaps. */
free (nonnull_local); free (nonnull_local);
free (nonnull_killed); free (nonnull_killed);
...@@ -5273,11 +5307,13 @@ hoist_expr_reaches_here_p (expr_bb, expr_index, bb, visited) ...@@ -5273,11 +5307,13 @@ hoist_expr_reaches_here_p (expr_bb, expr_index, bb, visited)
char *visited; char *visited;
{ {
edge pred; edge pred;
int visited_allocated_locally = 0;
if (visited == NULL) if (visited == NULL)
{ {
visited = (char *) alloca (n_basic_blocks); visited_allocated_locally = 1;
bzero (visited, n_basic_blocks); visited = xcalloc (n_basic_blocks, 1);
} }
visited[expr_bb] = 1; visited[expr_bb] = 1;
...@@ -5303,7 +5339,8 @@ hoist_expr_reaches_here_p (expr_bb, expr_index, bb, visited) ...@@ -5303,7 +5339,8 @@ hoist_expr_reaches_here_p (expr_bb, expr_index, bb, visited)
break; break;
} }
} }
if (visited_allocated_locally)
free (visited);
return (pred == NULL); return (pred == NULL);
} }
...@@ -5319,8 +5356,7 @@ hoist_code () ...@@ -5319,8 +5356,7 @@ hoist_code ()
/* Compute a mapping from expression number (`bitmap_index') to /* Compute a mapping from expression number (`bitmap_index') to
hash table entry. */ hash table entry. */
index_map = (struct expr **) alloca (n_exprs * sizeof (struct expr *)); index_map = xcalloc (n_exprs, sizeof (struct expr *));
bzero ((char *) index_map, n_exprs * sizeof (struct expr *));
for (i = 0; i < expr_hash_table_size; i++) for (i = 0; i < expr_hash_table_size; i++)
{ {
struct expr *expr; struct expr *expr;
...@@ -5473,6 +5509,7 @@ hoist_code () ...@@ -5473,6 +5509,7 @@ hoist_code ()
} }
} }
} }
free (index_map);
} }
/* Top level routine to perform one code hoisting (aka unification) pass /* Top level routine to perform one code hoisting (aka unification) pass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment