Commit 5f0d2358 by Richard Kenner Committed by Richard Kenner

rtl.h (in_expr_list_p): New declaration.

	* rtl.h (in_expr_list_p): New declaration.
	* rtlanal.c (in_expr_list_p): New function.
	* cfgcleanup.c: Reformatting and minor code rearrangement.
	* cfglayout.c, cfgloop.c, cfgrtl.c: Likewise.

From-SVN: r48304
parent e88712b5
Mon Dec 24 10:24:59 2001 Richard Kenner <kenner@vlsi1.ultra.nyu.edu>
* rtl.h (in_expr_list_p): New declaration.
* rtlanal.c (in_expr_list_p): New function.
* cfgcleanup.c: Reformatting and minor code rearrangement.
* cfglayout.c, cfgloop.c, cfgrtl.c: Likewise.
2001-12-23 Richard Henderson <rth@redhat.com> 2001-12-23 Richard Henderson <rth@redhat.com>
PR c/5163: PR c/5163:
......
...@@ -31,11 +31,13 @@ static int flow_loop_nested_p PARAMS ((struct loop *, ...@@ -31,11 +31,13 @@ static int flow_loop_nested_p PARAMS ((struct loop *,
static int flow_loop_entry_edges_find PARAMS ((basic_block, const sbitmap, static int flow_loop_entry_edges_find PARAMS ((basic_block, const sbitmap,
edge **)); edge **));
static int flow_loop_exit_edges_find PARAMS ((const sbitmap, edge **)); static int flow_loop_exit_edges_find PARAMS ((const sbitmap, edge **));
static int flow_loop_nodes_find PARAMS ((basic_block, basic_block, sbitmap)); static int flow_loop_nodes_find PARAMS ((basic_block, basic_block,
sbitmap));
static void flow_loop_pre_header_scan PARAMS ((struct loop *)); static void flow_loop_pre_header_scan PARAMS ((struct loop *));
static basic_block flow_loop_pre_header_find PARAMS ((basic_block, static basic_block flow_loop_pre_header_find PARAMS ((basic_block,
const sbitmap *)); const sbitmap *));
static void flow_loop_tree_node_add PARAMS ((struct loop *, struct loop *)); static void flow_loop_tree_node_add PARAMS ((struct loop *,
struct loop *));
static void flow_loops_tree_build PARAMS ((struct loops *)); static void flow_loops_tree_build PARAMS ((struct loops *));
static int flow_loop_level_compute PARAMS ((struct loop *, int)); static int flow_loop_level_compute PARAMS ((struct loop *, int));
static int flow_loops_level_compute PARAMS ((struct loops *)); static int flow_loops_level_compute PARAMS ((struct loops *));
...@@ -68,14 +70,17 @@ flow_loops_cfg_dump (loops, file) ...@@ -68,14 +70,17 @@ flow_loops_cfg_dump (loops, file)
fputs (";; DFS order: ", file); fputs (";; DFS order: ", file);
for (i = 0; i < n_basic_blocks; i++) for (i = 0; i < n_basic_blocks; i++)
fprintf (file, "%d ", loops->cfg.dfs_order[i]); fprintf (file, "%d ", loops->cfg.dfs_order[i]);
fputs ("\n", file); fputs ("\n", file);
} }
/* Dump the reverse completion node order. */ /* Dump the reverse completion node order. */
if (loops->cfg.rc_order) if (loops->cfg.rc_order)
{ {
fputs (";; RC order: ", file); fputs (";; RC order: ", file);
for (i = 0; i < n_basic_blocks; i++) for (i = 0; i < n_basic_blocks; i++)
fprintf (file, "%d ", loops->cfg.rc_order[i]); fprintf (file, "%d ", loops->cfg.rc_order[i]);
fputs ("\n", file); fputs ("\n", file);
} }
} }
...@@ -107,12 +112,10 @@ flow_loop_dump (loop, file, loop_dump_aux, verbose) ...@@ -107,12 +112,10 @@ flow_loop_dump (loop, file, loop_dump_aux, verbose)
fprintf (file, ";;\n;; Loop %d (%d to %d):%s%s\n", fprintf (file, ";;\n;; Loop %d (%d to %d):%s%s\n",
loop->num, INSN_UID (loop->first->head), loop->num, INSN_UID (loop->first->head),
INSN_UID (loop->last->end), INSN_UID (loop->last->end),
loop->shared ? " shared" : "", loop->shared ? " shared" : "", loop->invalid ? " invalid" : "");
loop->invalid ? " invalid" : "");
else else
fprintf (file, ";;\n;; Loop %d:%s%s\n", loop->num, fprintf (file, ";;\n;; Loop %d:%s%s\n", loop->num,
loop->shared ? " shared" : "", loop->shared ? " shared" : "", loop->invalid ? " invalid" : "");
loop->invalid ? " invalid" : "");
fprintf (file, ";; header %d, latch %d, pre-header %d, first %d, last %d\n", fprintf (file, ";; header %d, latch %d, pre-header %d, first %d, last %d\n",
loop->header->index, loop->latch->index, loop->header->index, loop->latch->index,
...@@ -125,14 +128,17 @@ flow_loop_dump (loop, file, loop_dump_aux, verbose) ...@@ -125,14 +128,17 @@ flow_loop_dump (loop, file, loop_dump_aux, verbose)
if (loop->pre_header_edges) if (loop->pre_header_edges)
flow_edge_list_print (";; pre-header edges", loop->pre_header_edges, flow_edge_list_print (";; pre-header edges", loop->pre_header_edges,
loop->num_pre_header_edges, file); loop->num_pre_header_edges, file);
flow_edge_list_print (";; entry edges", loop->entry_edges, flow_edge_list_print (";; entry edges", loop->entry_edges,
loop->num_entries, file); loop->num_entries, file);
fprintf (file, ";; %d", loop->num_nodes); fprintf (file, ";; %d", loop->num_nodes);
flow_nodes_print (" nodes", loop->nodes, file); flow_nodes_print (" nodes", loop->nodes, file);
flow_edge_list_print (";; exit edges", loop->exit_edges, flow_edge_list_print (";; exit edges", loop->exit_edges,
loop->num_exits, file); loop->num_exits, file);
if (loop->exits_doms) if (loop->exits_doms)
flow_nodes_print (";; exit doms", loop->exits_doms, file); flow_nodes_print (";; exit doms", loop->exits_doms, file);
if (loop_dump_aux) if (loop_dump_aux)
loop_dump_aux (loop, file, verbose); loop_dump_aux (loop, file, verbose);
} }
...@@ -147,26 +153,20 @@ flow_loops_dump (loops, file, loop_dump_aux, verbose) ...@@ -147,26 +153,20 @@ flow_loops_dump (loops, file, loop_dump_aux, verbose)
void (*loop_dump_aux) PARAMS((const struct loop *, FILE *, int)); void (*loop_dump_aux) PARAMS((const struct loop *, FILE *, int));
int verbose; int verbose;
{ {
int i; int i, j;
int num_loops; int num_loops;
num_loops = loops->num; num_loops = loops->num;
if (! num_loops || ! file) if (! num_loops || ! file)
return; return;
fprintf (file, ";; %d loops found, %d levels\n", fprintf (file, ";; %d loops found, %d levels\n", num_loops, loops->levels);
num_loops, loops->levels);
for (i = 0; i < num_loops; i++) for (i = 0; i < num_loops; i++)
{ {
struct loop *loop = &loops->array[i]; struct loop *loop = &loops->array[i];
flow_loop_dump (loop, file, loop_dump_aux, verbose); flow_loop_dump (loop, file, loop_dump_aux, verbose);
if (loop->shared) if (loop->shared)
{
int j;
for (j = 0; j < i; j++) for (j = 0; j < i; j++)
{ {
struct loop *oloop = &loops->array[j]; struct loop *oloop = &loops->array[j];
...@@ -190,7 +190,6 @@ flow_loops_dump (loops, file, loop_dump_aux, verbose) ...@@ -190,7 +190,6 @@ flow_loops_dump (loops, file, loop_dump_aux, verbose)
} }
} }
} }
}
if (verbose) if (verbose)
flow_loops_cfg_dump (loops, file); flow_loops_cfg_dump (loops, file);
...@@ -225,11 +224,13 @@ flow_loops_free (loops) ...@@ -225,11 +224,13 @@ flow_loops_free (loops)
if (loop->exits_doms) if (loop->exits_doms)
sbitmap_free (loop->exits_doms); sbitmap_free (loop->exits_doms);
} }
free (loops->array); free (loops->array);
loops->array = NULL; loops->array = NULL;
if (loops->cfg.dom) if (loops->cfg.dom)
sbitmap_vector_free (loops->cfg.dom); sbitmap_vector_free (loops->cfg.dom);
if (loops->cfg.dfs_order) if (loops->cfg.dfs_order)
free (loops->cfg.dfs_order); free (loops->cfg.dfs_order);
...@@ -394,42 +395,33 @@ static void ...@@ -394,42 +395,33 @@ static void
flow_loop_pre_header_scan (loop) flow_loop_pre_header_scan (loop)
struct loop *loop; struct loop *loop;
{ {
int num = 0; int num;
basic_block ebb; basic_block ebb;
edge e;
loop->num_pre_header_edges = 0; loop->num_pre_header_edges = 0;
if (loop->num_entries != 1) if (loop->num_entries != 1)
return; return;
ebb = loop->entry_edges[0]->src; ebb = loop->entry_edges[0]->src;
if (ebb == ENTRY_BLOCK_PTR)
if (ebb != ENTRY_BLOCK_PTR) return;
{
edge e;
/* Count number of edges along trace from loop header to /* Count number of edges along trace from loop header to
root of pre-header extended basic block. Usually this is root of pre-header extended basic block. Usually this is
only one or two edges. */ only one or two edges. */
num++; for (num = 1; ebb->pred->src != ENTRY_BLOCK_PTR && ! ebb->pred->pred_next;
while (ebb->pred->src != ENTRY_BLOCK_PTR && ! ebb->pred->pred_next) num++)
{
ebb = ebb->pred->src; ebb = ebb->pred->src;
num++;
}
loop->pre_header_edges = (edge *) xmalloc (num * sizeof (edge *)); loop->pre_header_edges = (edge *) xmalloc (num * sizeof (edge *));
loop->num_pre_header_edges = num; loop->num_pre_header_edges = num;
/* Store edges in order that they are followed. The source /* Store edges in order that they are followed. The source of the first edge
of the first edge is the root node of the pre-header extended is the root node of the pre-header extended basic block and the
basic block and the destination of the last last edge is destination of the last last edge is the loop header. */
the loop header. */
for (e = loop->entry_edges[0]; num; e = e->src->pred) for (e = loop->entry_edges[0]; num; e = e->src->pred)
{
loop->pre_header_edges[--num] = e; loop->pre_header_edges[--num] = e;
}
}
} }
/* Return the block for the pre-header of the loop with header /* Return the block for the pre-header of the loop with header
...@@ -465,6 +457,7 @@ flow_loop_pre_header_find (header, dom) ...@@ -465,6 +457,7 @@ flow_loop_pre_header_find (header, dom)
} }
} }
} }
return pre_header; return pre_header;
} }
...@@ -485,16 +478,13 @@ flow_loop_tree_node_add (prevloop, loop) ...@@ -485,16 +478,13 @@ flow_loop_tree_node_add (prevloop, loop)
return; return;
} }
while (prevloop->outer) for (; prevloop->outer; prevloop = prevloop->outer)
{
if (flow_loop_nested_p (prevloop->outer, loop)) if (flow_loop_nested_p (prevloop->outer, loop))
{ {
prevloop->next = loop; prevloop->next = loop;
loop->outer = prevloop->outer; loop->outer = prevloop->outer;
return; return;
} }
prevloop = prevloop->outer;
}
prevloop->next = loop; prevloop->next = loop;
loop->outer = NULL; loop->outer = NULL;
...@@ -517,7 +507,8 @@ flow_loops_tree_build (loops) ...@@ -517,7 +507,8 @@ flow_loops_tree_build (loops)
Since we used a depth first search this should be the Since we used a depth first search this should be the
outermost loop. */ outermost loop. */
loops->tree_root = &loops->array[0]; loops->tree_root = &loops->array[0];
loops->tree_root->outer = loops->tree_root->inner = loops->tree_root->next = NULL; loops->tree_root->outer = loops->tree_root->inner
= loops->tree_root->next = NULL;
/* Add the remaining loops to the tree. */ /* Add the remaining loops to the tree. */
for (i = 1; i < num_loops; i++) for (i = 1; i < num_loops; i++)
...@@ -546,13 +537,11 @@ flow_loop_level_compute (loop, depth) ...@@ -546,13 +537,11 @@ flow_loop_level_compute (loop, depth)
itself). */ itself). */
for (inner = loop->inner; inner; inner = inner->next) for (inner = loop->inner; inner; inner = inner->next)
{ {
int ilevel; int ilevel = flow_loop_level_compute (inner, depth + 1) + 1;
ilevel = flow_loop_level_compute (inner, depth + 1) + 1;
if (ilevel > level) level = MAX (ilevel, level);
level = ilevel;
} }
loop->level = level; loop->level = level;
loop->depth = depth; loop->depth = depth;
return level; return level;
...@@ -566,17 +555,17 @@ static int ...@@ -566,17 +555,17 @@ static int
flow_loops_level_compute (loops) flow_loops_level_compute (loops)
struct loops *loops; struct loops *loops;
{ {
int levels = 0;
struct loop *loop; struct loop *loop;
int level; int level;
int levels = 0;
/* Traverse all the outer level loops. */ /* Traverse all the outer level loops. */
for (loop = loops->tree_root; loop; loop = loop->next) for (loop = loops->tree_root; loop; loop = loop->next)
{ {
level = flow_loop_level_compute (loop, 1); level = flow_loop_level_compute (loop, 1);
if (level > levels) levels = MAX (levels, level);
levels = level;
} }
return levels; return levels;
} }
...@@ -594,23 +583,15 @@ flow_loop_scan (loops, loop, flags) ...@@ -594,23 +583,15 @@ flow_loop_scan (loops, loop, flags)
flags |= LOOP_EXIT_EDGES; flags |= LOOP_EXIT_EDGES;
if (flags & LOOP_ENTRY_EDGES) if (flags & LOOP_ENTRY_EDGES)
{ /* Find edges which enter the loop header. Note that the entry edges
/* Find edges which enter the loop header. should only enter the header of a natural loop. */
Note that the entry edges should only loop->num_entries = flow_loop_entry_edges_find (loop->header, loop->nodes,
enter the header of a natural loop. */
loop->num_entries
= flow_loop_entry_edges_find (loop->header,
loop->nodes,
&loop->entry_edges); &loop->entry_edges);
}
if (flags & LOOP_EXIT_EDGES) if (flags & LOOP_EXIT_EDGES)
{
/* Find edges which exit the loop. */ /* Find edges which exit the loop. */
loop->num_exits loop->num_exits
= flow_loop_exit_edges_find (loop->nodes, = flow_loop_exit_edges_find (loop->nodes, &loop->exit_edges);
&loop->exit_edges);
}
if (flags & LOOP_EXITS_DOMS) if (flags & LOOP_EXITS_DOMS)
{ {
...@@ -640,13 +621,14 @@ flow_loop_scan (loops, loop, flags) ...@@ -640,13 +621,14 @@ flow_loop_scan (loops, loop, flags)
the loop pre-header. */ the loop pre-header. */
flow_loop_pre_header_scan (loop); flow_loop_pre_header_scan (loop);
} }
return 1; return 1;
} }
/* Find all the natural loops in the function and save in LOOPS structure /* Find all the natural loops in the function and save in LOOPS structure and
and recalculate loop_depth information in basic block structures. recalculate loop_depth information in basic block structures. FLAGS
FLAGS controls which loop information is collected. controls which loop information is collected. Return the number of natural
Return the number of natural loops found. */ loops found. */
int int
flow_loops_find (loops, flags) flow_loops_find (loops, flags)
...@@ -668,7 +650,7 @@ flow_loops_find (loops, flags) ...@@ -668,7 +650,7 @@ flow_loops_find (loops, flags)
if (! (flags & LOOP_TREE)) if (! (flags & LOOP_TREE))
abort (); abort ();
memset (loops, 0, sizeof (*loops)); memset (loops, 0, sizeof *loops);
/* Taking care of this degenerate case makes the rest of /* Taking care of this degenerate case makes the rest of
this code simpler. */ this code simpler. */
...@@ -684,7 +666,6 @@ flow_loops_find (loops, flags) ...@@ -684,7 +666,6 @@ flow_loops_find (loops, flags)
/* Count the number of loop edges (back edges). This should be the /* Count the number of loop edges (back edges). This should be the
same as the number of natural loops. */ same as the number of natural loops. */
num_loops = 0; num_loops = 0;
for (b = 0; b < n_basic_blocks; b++) for (b = 0; b < n_basic_blocks; b++)
{ {
...@@ -810,9 +791,7 @@ flow_loops_find (loops, flags) ...@@ -810,9 +791,7 @@ flow_loops_find (loops, flags)
sbitmap_free (headers); sbitmap_free (headers);
} }
else else
{
sbitmap_vector_free (dom); sbitmap_vector_free (dom);
}
loops->num = num_loops; loops->num = num_loops;
...@@ -828,6 +807,7 @@ flow_loops_find (loops, flags) ...@@ -828,6 +807,7 @@ flow_loops_find (loops, flags)
/* Update the information regarding the loops in the CFG /* Update the information regarding the loops in the CFG
specified by LOOPS. */ specified by LOOPS. */
int int
flow_loops_update (loops, flags) flow_loops_update (loops, flags)
struct loops *loops; struct loops *loops;
...@@ -850,5 +830,7 @@ flow_loop_outside_edge_p (loop, e) ...@@ -850,5 +830,7 @@ flow_loop_outside_edge_p (loop, e)
{ {
if (e->dest != loop->header) if (e->dest != loop->header)
abort (); abort ();
return (e->src == ENTRY_BLOCK_PTR) || ! TEST_BIT (loop->nodes, e->src->index);
return (e->src == ENTRY_BLOCK_PTR)
|| ! TEST_BIT (loop->nodes, e->src->index);
} }
...@@ -1483,6 +1483,7 @@ typedef int (*rtx_function) PARAMS ((rtx *, void *)); ...@@ -1483,6 +1483,7 @@ typedef int (*rtx_function) PARAMS ((rtx *, void *));
extern int for_each_rtx PARAMS ((rtx *, rtx_function, void *)); extern int for_each_rtx PARAMS ((rtx *, rtx_function, void *));
extern rtx regno_use_in PARAMS ((unsigned int, rtx)); extern rtx regno_use_in PARAMS ((unsigned int, rtx));
extern int auto_inc_p PARAMS ((rtx)); extern int auto_inc_p PARAMS ((rtx));
extern int in_expr_list_p PARAMS ((rtx, rtx));
extern void remove_node_from_expr_list PARAMS ((rtx, rtx *)); extern void remove_node_from_expr_list PARAMS ((rtx, rtx *));
extern int insns_safe_to_move_p PARAMS ((rtx, rtx, rtx *)); extern int insns_safe_to_move_p PARAMS ((rtx, rtx, rtx *));
extern int loc_mentioned_in_p PARAMS ((rtx *, rtx)); extern int loc_mentioned_in_p PARAMS ((rtx *, rtx));
......
...@@ -1954,6 +1954,24 @@ remove_note (insn, note) ...@@ -1954,6 +1954,24 @@ remove_note (insn, note)
} }
/* Search LISTP (an EXPR_LIST) for an entry whose first operand is NODE and /* Search LISTP (an EXPR_LIST) for an entry whose first operand is NODE and
return 1 if it is found. A simple equality test is used to determine if
NODE matches. */
int
in_expr_list_p (listp, node)
rtx listp;
rtx node;
{
rtx x;
for (x = listp; x; x = XEXP (x, 1))
if (node == XEXP (x, 0))
return 1;
return 0;
}
/* Search LISTP (an EXPR_LIST) for an entry whose first operand is NODE and
remove that entry from the list if it is found. remove that entry from the list if it is found.
A simple equality test is used to determine if NODE matches. */ A simple equality test is used to determine if NODE matches. */
......
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