This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [tree-ssa] Update loop analysis 1/2
On Thu, Jul 31, 2003 at 08:15:06AM -0400, Diego Novillo wrote:
>
> Since you're cleaning up the CFG code, could you remove the AT_..._LEVEL
> enums and replace them with cfghooks? I think it will be cleaner in the
> long run.
>
The following patch removes the enum. It bootstrapped on x86 with c,c++,f77.
What about adding a field "bb_ann_t *tree_ann;" to the basic_block structure
and remove the "int num_latches;" as Jan suggested?
Index: basic-block.h
===================================================================
RCS file: /cvs/gcc/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 31 Jul 2003 15:42:17 -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: /cvs/gcc/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 31 Jul 2003 15:42:17 -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.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cfghooks.c,v
retrieving revision 1.1.2.2
diff -d -u -p -r1.1.2.2 cfghooks.c
--- cfghooks.c 21 Jul 2003 13:50:29 -0000 1.1.2.2
+++ cfghooks.c 31 Jul 2003 15:42:17 -0000
@@ -34,16 +34,11 @@ extern struct cfg_hooks cfg_layout_rtl_c
/* A pointer to one of the hooks containers. */
struct cfg_hooks *cfg_hooks;
-/* A global variable that keeps track of the state of the cfg. */
-enum cfg_level cfg_level;
-
-
/* Initialization of functions specific to the rtl IR. */
void
rtl_register_cfg_hooks ()
{
- cfg_level = AT_RTL_LEVEL;
cfg_hooks = &rtl_cfg_hooks;
}
Index: cfghooks.h
===================================================================
RCS file: /cvs/gcc/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 31 Jul 2003 15:42:17 -0000
@@ -24,6 +24,10 @@ Boston, MA 02111-1307, USA. */
struct cfg_hooks
{
+ /* Keep track of the underlying abstraction level. */
+ bool cfgh_at_tree_level;
+ bool cfgh_at_rtl_level;
+
/* Debugging. Do not use macros to hook these so they can be called from
debugger! */
int (*cfgh_verify_flow_info) (void);
@@ -62,6 +66,8 @@ struct cfg_hooks
basic_block (*cfgh_make_forwarder_block) (basic_block, int, int, edge, int);
};
+#define CFG_AT_TREE_LEVEL cfg_hooks->cfgh_at_tree_level
+#define CFG_AT_RTL_LEVEL cfg_hooks->cfgh_at_rtl_level
#define redirect_edge_and_branch(e,b) cfg_hooks->redirect_edge_and_branch (e,b)
#define redirect_edge_and_branch_force(e,b) cfg_hooks->redirect_edge_and_branch_force (e,b)
#define split_block(e,i) cfg_hooks->split_block (e,i)
@@ -72,7 +78,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. */
@@ -81,14 +87,6 @@ extern struct cfg_hooks rtl_cfg_hooks;
/* A pointer to one of the hooks containers. */
extern struct cfg_hooks *cfg_hooks;
-
-enum cfg_level {
- AT_TREE_LEVEL,
- AT_RTL_LEVEL
-};
-
-/* A global variable that keeps track of the state of the cfg. */
-extern enum cfg_level cfg_level;
/* Declarations. */
extern void rtl_register_cfg_hooks (void);
Index: cfgloop.c
===================================================================
RCS file: /cvs/gcc/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 31 Jul 2003 15:42: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: /cvs/gcc/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 31 Jul 2003 15:42:17 -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);
@@ -2748,6 +2746,8 @@ redirect_edge_with_latch_update (edge e,
/* Implementation of CFG manipulation for linearized RTL. */
struct cfg_hooks rtl_cfg_hooks = {
+ false, /* cfgh_at_tree_level */
+ true, /* cfgh_at_rtl_level */
rtl_verify_flow_info,
rtl_dump_bb,
rtl_create_basic_block,
@@ -2766,6 +2766,8 @@ struct cfg_hooks rtl_cfg_hooks = {
This representation will hopefully become the default one in future
version of the compiler. */
struct cfg_hooks cfg_layout_rtl_cfg_hooks = {
+ false, /* cfgh_at_tree_level */
+ true, /* cfgh_at_rtl_level */
rtl_verify_flow_info_1,
rtl_dump_bb,
cfg_layout_create_basic_block,
Index: loop-init.c
===================================================================
RCS file: /cvs/gcc/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 31 Jul 2003 15:42:17 -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);
-
+ if (CFG_AT_RTL_LEVEL)
+ {
+ /* 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_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;
}
@@ -70,7 +76,7 @@ loop_optimizer_init (FILE *dumpfile)
loops->cfg.dfs_order = NULL;
/* Create pre-headers. */
- if (cfg_level == AT_RTL_LEVEL)
+ if (CFG_AT_RTL_LEVEL)
create_preheaders (loops, CP_SIMPLE_PREHEADERS);
/* Force all latches to have only single successor. */
@@ -95,10 +101,13 @@ void
loop_optimizer_finalize (struct loops *loops, FILE *dumpfile)
{
basic_block bb;
+
+ if (loops == NULL)
+ return;
/* Finalize layout changes. */
/* Make chain. */
- if (cfg_level == AT_RTL_LEVEL)
+ if (CFG_AT_RTL_LEVEL)
FOR_EACH_BB (bb)
if (bb->next_bb != EXIT_BLOCK_PTR)
bb->rbi->next = bb->next_bb;
@@ -111,7 +120,7 @@ loop_optimizer_finalize (struct loops *l
free (loops);
/* Finalize changes. */
- if (cfg_level == AT_RTL_LEVEL)
+ if (CFG_AT_RTL_LEVEL)
cfg_layout_finalize ();
/* Checking. */
Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-cfg.c,v
retrieving revision 1.1.4.138
diff -d -u -p -r1.1.4.138 tree-cfg.c
--- tree-cfg.c 31 Jul 2003 00:50:49 -0000 1.1.4.138
+++ tree-cfg.c 31 Jul 2003 15:42:17 -0000
@@ -195,6 +195,8 @@ static tree_stmt_iterator find_insert_lo
/* FIXME These need to be filled in with appropriate pointers. But this
implies an ABI change in some functions. */
struct cfg_hooks tree_cfg_hooks = {
+ true, /* cfgh_at_tree_level */
+ false, /* cfgh_at_rtl_level */
tree_verify_flow_info,
NULL, /* dump_bb */
NULL, /* create_basic_block */
@@ -4854,6 +4856,5 @@ tree_make_forwarder_block (basic_block b
void
tree_register_cfg_hooks ()
{
- cfg_level = AT_TREE_LEVEL;
cfg_hooks = &tree_cfg_hooks;
}