This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa] Update loop analysis 1/2
- From: Pop Sébastian <pop at gauvain dot u-strasbg dot fr>
- To: gcc-patches at gcc dot gnu dot org
- Cc: dnovillo at redhat dot com
- Date: Thu, 31 Jul 2003 00:19:45 +0200
- Subject: [tree-ssa] Update loop analysis 1/2
Hi,
The problem with the main branch is that it uses the basic_block.aux
field for storing the number of back-edges during the loops detection.
This patch inserts the basic_block.num_latches field, and uses it
instead of the basic_block.aux field.
Bootstrapped (with --enable-languages=c,c++,f77,java) on x86,
with loop initialization disabled. For making the loop analyzer
usable I have to provide an implementation for split_basic_block.
This will be part of another patch since it still does not bootstrap
with loop detection enabled.
2003-07-25 Sebastian Pop <s.pop@laposte.net>
* basic-block.c (basic_block_def): Add num_latches.
* cfg.c (entry_exit_blocks): Initialize num_latches to 0 for
entry and exit blocks.
* cfghooks.h (HEADER_BLOCK): Use the num_latches field.
* cfgloop.c (canonicalize_loop_headers): Remove the initializations
and finalization of basic_block.aux fields.
* cfgrtl.c (rtl_make_forwarder_block,
redirect_edge_with_latch_update): Remove an allocation of
basic_block.aux field.
* loop-init.c (loop_optimizer_init, loop_optimizer_finalize):
Conditionally execute the cfg_layout specific parts only when
cfg_level is AT_RTL_LEVEL.
(loop_optimizer_finalize): Return if loops is a NULL pointer.
Index: basic-block.h
===================================================================
RCS file: /home/seb/cvsroot/gcc-cvs/gcc/gcc/basic-block.h,v
retrieving revision 1.153.2.27
diff -d -u -p -r1.153.2.27 basic-block.h
--- basic-block.h 23 Jul 2003 16:59:28 -0000 1.153.2.27
+++ basic-block.h 27 Jul 2003 15:15:00 -0000
@@ -251,6 +251,9 @@ typedef struct basic_block_def {
/* Additional data maintained by cfg_layout routines. */
struct reorder_block_def *rbi;
+
+ /* The number of back-edges to this block. */
+ int num_latches;
} *basic_block;
#define BB_FREQ_MAX 10000
Index: cfg.c
===================================================================
RCS file: /home/seb/cvsroot/gcc-cvs/gcc/gcc/cfg.c,v
retrieving revision 1.34.2.10
diff -d -u -p -r1.34.2.10 cfg.c
--- cfg.c 23 Jul 2003 16:59:32 -0000 1.34.2.10
+++ cfg.c 27 Jul 2003 15:15:29 -0000
@@ -114,7 +114,8 @@ struct basic_block_def entry_exit_blocks
0, /* count */
0, /* frequency */
0, /* flags */
- NULL /* rbi */
+ NULL, /* rbi */
+ 0 /* num_latches */
},
{
NULL, /* head */
@@ -136,7 +137,8 @@ struct basic_block_def entry_exit_blocks
0, /* count */
0, /* frequency */
0, /* flags */
- NULL /* rbi */
+ NULL, /* rbi */
+ 0 /* num_latches */
}
};
Index: cfghooks.h
===================================================================
RCS file: /home/seb/cvsroot/gcc-cvs/gcc/gcc/cfghooks.h,v
retrieving revision 1.1.2.3
diff -d -u -p -r1.1.2.3 cfghooks.h
--- cfghooks.h 23 Jul 2003 16:59:32 -0000 1.1.2.3
+++ cfghooks.h 27 Jul 2003 22:27:13 -0000
@@ -72,7 +72,7 @@ struct cfg_hooks
#define merge_blocks(a,b) cfg_hooks->merge_blocks (a,b)
#define make_forwarder_block(a, b, c, d, e) cfg_hooks->cfgh_make_forwarder_block (a, b, c, d, e)
-#define HEADER_BLOCK(B) (* (int *) (B)->aux)
+#define HEADER_BLOCK(B) ((B)->num_latches)
#define LATCH_EDGE(E) (*(int *) (E)->aux)
/* Hooks containers. */
Index: cfgloop.c
===================================================================
RCS file: /home/seb/cvsroot/gcc-cvs/gcc/gcc/cfgloop.c,v
retrieving revision 1.14.2.11
diff -d -u -p -r1.14.2.11 cfgloop.c
--- cfgloop.c 23 Jul 2003 16:59:32 -0000 1.14.2.11
+++ cfgloop.c 26 Jul 2003 14:31:17 -0000
@@ -563,7 +563,6 @@ canonicalize_loop_headers (void)
/* Compute the dominators. */
dom = calculate_dominance_info (CDI_DOMINATORS);
- alloc_aux_for_blocks (sizeof (int));
alloc_aux_for_edges (sizeof (int));
/* Split blocks so that each loop has only single latch. */
@@ -602,7 +601,6 @@ canonicalize_loop_headers (void)
alloc_aux_for_edge (bb->succ, sizeof (int));
LATCH_EDGE (bb->succ) = 0;
- alloc_aux_for_block (bb, sizeof (int));
HEADER_BLOCK (bb) = 0;
}
@@ -655,7 +653,6 @@ canonicalize_loop_headers (void)
make_forwarder_block (header, true, false, NULL, 1);
}
- free_aux_for_blocks ();
free_aux_for_edges ();
free_dominance_info (dom);
}
Index: cfgrtl.c
===================================================================
RCS file: /home/seb/cvsroot/gcc-cvs/gcc/gcc/cfgrtl.c,v
retrieving revision 1.57.2.12
diff -d -u -p -r1.57.2.12 cfgrtl.c
--- cfgrtl.c 23 Jul 2003 16:59:32 -0000 1.57.2.12
+++ cfgrtl.c 27 Jul 2003 22:27:55 -0000
@@ -2701,7 +2701,6 @@ rtl_make_forwarder_block (basic_block bb
dummy = fallthru->src;
bb = fallthru->dest;
- bb->aux = xmalloc (sizeof (int));
HEADER_BLOCK (dummy) = 0;
HEADER_BLOCK (bb) = 1;
@@ -2738,7 +2737,6 @@ redirect_edge_with_latch_update (edge e,
jump = redirect_edge_and_branch_force (e, to);
if (jump)
{
- alloc_aux_for_block (jump, sizeof (int));
HEADER_BLOCK (jump) = 0;
alloc_aux_for_edge (jump->pred, sizeof (int));
LATCH_EDGE (jump->succ) = LATCH_EDGE (e);
Index: loop-init.c
===================================================================
RCS file: /home/seb/cvsroot/gcc-cvs/gcc/gcc/loop-init.c,v
retrieving revision 1.2.2.5
diff -d -u -p -r1.2.2.5 loop-init.c
--- loop-init.c 23 Jul 2003 16:59:50 -0000 1.2.2.5
+++ loop-init.c 26 Jul 2003 14:42:46 -0000
@@ -36,16 +36,18 @@ loop_optimizer_init (FILE *dumpfile)
struct loops *loops = xcalloc (1, sizeof (struct loops));
edge e;
- /* Initialize structures for layout changes. */
- cfg_layout_initialize ();
-
- /* Avoid annoying special cases of edges going to exit
- block. */
if (cfg_level == AT_RTL_LEVEL)
- for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
- if ((e->flags & EDGE_FALLTHRU) && e->src->succ->succ_next)
- split_edge (e);
-
+ {
+ /* Initialize structures for layout changes. */
+ cfg_layout_initialize ();
+
+ /* Avoid annoying special cases of edges going to exit
+ block. */
+ for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
+ if ((e->flags & EDGE_FALLTHRU) && e->src->succ->succ_next)
+ split_edge (e);
+ }
+
/* Find the loops. */
if (flow_loops_find (loops, LOOP_TREE) <= 1)
@@ -55,11 +57,15 @@ loop_optimizer_init (FILE *dumpfile)
/* No loops. */
flow_loops_free (loops);
free (loops);
- /* Make chain. */
- FOR_EACH_BB (bb)
- if (bb->next_bb != EXIT_BLOCK_PTR)
- bb->rbi->next = bb->next_bb;
+
+ if (cfg_level == AT_RTL_LEVEL)
+ {
+ /* Make chain. */
+ FOR_EACH_BB (bb)
+ if (bb->next_bb != EXIT_BLOCK_PTR)
+ bb->rbi->next = bb->next_bb;
cfg_layout_finalize ();
+ }
return NULL;
}
@@ -95,6 +101,9 @@ void
loop_optimizer_finalize (struct loops *loops, FILE *dumpfile)
{
basic_block bb;
+
+ if (loops == NULL)
+ return;
/* Finalize layout changes. */
/* Make chain. */