diff options
Diffstat (limited to 'gcc/df.c')
-rw-r--r-- | gcc/df.c | 244 |
1 files changed, 125 insertions, 119 deletions
@@ -171,6 +171,12 @@ Perhaps there should be a bitmap argument to df_analyse to specify #include "df.h" #include "fibheap.h" +#define FOR_ALL_BBS(BB, CODE) \ +do { \ + int node_; \ + for (node_ = 0; node_ < n_basic_blocks; node_++) \ + {(BB) = BASIC_BLOCK (node_); CODE;};} while (0) + #define FOR_EACH_BB_IN_BITMAP(BITMAP, MIN, BB, CODE) \ do { \ unsigned int node_; \ @@ -400,8 +406,8 @@ df_bitmaps_alloc (df, flags) struct df *df; int flags; { + unsigned int i; int dflags = 0; - basic_block bb; /* Free the bitmaps if they need resizing. */ if ((flags & DF_LR) && df->n_regs < (unsigned int)max_reg_num ()) @@ -417,8 +423,9 @@ df_bitmaps_alloc (df, flags) df->n_defs = df->def_id; df->n_uses = df->use_id; - FOR_ALL_BB (bb) + for (i = 0; i < df->n_bbs; i++) { + basic_block bb = BASIC_BLOCK (i); struct bb_info *bb_info = DF_BB_INFO (df, bb); if (flags & DF_RD && ! bb_info->rd_in) @@ -467,10 +474,11 @@ df_bitmaps_free (df, flags) struct df *df ATTRIBUTE_UNUSED; int flags; { - basic_block bb; + unsigned int i; - FOR_ALL_BB (bb) + for (i = 0; i < df->n_bbs; i++) { + basic_block bb = BASIC_BLOCK (i); struct bb_info *bb_info = DF_BB_INFO (df, bb); if (!bb_info) @@ -526,7 +534,7 @@ df_alloc (df, n_regs) int n_regs; { int n_insns; - basic_block bb; + int i; gcc_obstack_init (&df_ref_obstack); @@ -547,7 +555,7 @@ df_alloc (df, n_regs) df->uses = xmalloc (df->use_size * sizeof (*df->uses)); df->n_regs = n_regs; - df->n_bbs = last_basic_block; + df->n_bbs = n_basic_blocks; /* Allocate temporary working array used during local dataflow analysis. */ df->reg_def_last = xmalloc (df->n_regs * sizeof (struct ref *)); @@ -561,11 +569,11 @@ df_alloc (df, n_regs) df->flags = 0; - df->bbs = xcalloc (last_basic_block, sizeof (struct bb_info)); + df->bbs = xcalloc (df->n_bbs, sizeof (struct bb_info)); df->all_blocks = BITMAP_XMALLOC (); - FOR_ALL_BB (bb) - bitmap_set_bit (df->all_blocks, bb->sindex); + for (i = 0; i < n_basic_blocks; i++) + bitmap_set_bit (df->all_blocks, i); } @@ -1938,10 +1946,8 @@ df_analyse_1 (df, blocks, flags, update) int aflags; int dflags; int i; - basic_block bb; - dflags = 0; - aflags = flags; + aflags = flags; if (flags & DF_UD_CHAIN) aflags |= DF_RD | DF_RD_CHAIN; @@ -2003,16 +2009,16 @@ df_analyse_1 (df, blocks, flags, update) df_reg_use_chain_create (df, blocks); } - df->dfs_order = xmalloc (sizeof(int) * num_basic_blocks); - df->rc_order = xmalloc (sizeof(int) * num_basic_blocks); - df->rts_order = xmalloc (sizeof(int) * num_basic_blocks); - df->inverse_dfs_map = xmalloc (sizeof(int) * last_basic_block); - df->inverse_rc_map = xmalloc (sizeof(int) * last_basic_block); - df->inverse_rts_map = xmalloc (sizeof(int) * last_basic_block); - + df->dfs_order = xmalloc (sizeof(int) * n_basic_blocks); + df->rc_order = xmalloc (sizeof(int) * n_basic_blocks); + df->rts_order = xmalloc (sizeof(int) * n_basic_blocks); + df->inverse_dfs_map = xmalloc (sizeof(int) * n_basic_blocks); + df->inverse_rc_map = xmalloc (sizeof(int) * n_basic_blocks); + df->inverse_rts_map = xmalloc (sizeof(int) * n_basic_blocks); + flow_depth_first_order_compute (df->dfs_order, df->rc_order); flow_reverse_top_sort_order_compute (df->rts_order); - for (i = 0; i < num_basic_blocks; i ++) + for (i = 0; i < n_basic_blocks; i ++) { df->inverse_dfs_map[df->dfs_order[i]] = i; df->inverse_rc_map[df->rc_order[i]] = i; @@ -2023,16 +2029,17 @@ df_analyse_1 (df, blocks, flags, update) /* Compute the sets of gens and kills for the defs of each bb. */ df_rd_local_compute (df, df->flags & DF_RD ? blocks : df->all_blocks); { - bitmap *in = xmalloc (sizeof (bitmap) * last_basic_block); - bitmap *out = xmalloc (sizeof (bitmap) * last_basic_block); - bitmap *gen = xmalloc (sizeof (bitmap) * last_basic_block); - bitmap *kill = xmalloc (sizeof (bitmap) * last_basic_block); - FOR_ALL_BB (bb) + int i; + bitmap *in = xmalloc (sizeof (bitmap) * n_basic_blocks); + bitmap *out = xmalloc (sizeof (bitmap) * n_basic_blocks); + bitmap *gen = xmalloc (sizeof (bitmap) * n_basic_blocks); + bitmap *kill = xmalloc (sizeof (bitmap) * n_basic_blocks); + for (i = 0; i < n_basic_blocks; i ++) { - in[bb->sindex] = DF_BB_INFO (df, bb)->rd_in; - out[bb->sindex] = DF_BB_INFO (df, bb)->rd_out; - gen[bb->sindex] = DF_BB_INFO (df, bb)->rd_gen; - kill[bb->sindex] = DF_BB_INFO (df, bb)->rd_kill; + in[i] = DF_BB_INFO (df, BASIC_BLOCK (i))->rd_in; + out[i] = DF_BB_INFO (df, BASIC_BLOCK (i))->rd_out; + gen[i] = DF_BB_INFO (df, BASIC_BLOCK (i))->rd_gen; + kill[i] = DF_BB_INFO (df, BASIC_BLOCK (i))->rd_kill; } iterative_dataflow_bitmap (in, out, gen, kill, df->all_blocks, FORWARD, UNION, df_rd_transfer_function, @@ -2059,16 +2066,17 @@ df_analyse_1 (df, blocks, flags, update) uses in each bb. */ df_ru_local_compute (df, df->flags & DF_RU ? blocks : df->all_blocks); { - bitmap *in = xmalloc (sizeof (bitmap) * last_basic_block); - bitmap *out = xmalloc (sizeof (bitmap) * last_basic_block); - bitmap *gen = xmalloc (sizeof (bitmap) * last_basic_block); - bitmap *kill = xmalloc (sizeof (bitmap) * last_basic_block); - FOR_ALL_BB (bb) + int i; + bitmap *in = xmalloc (sizeof (bitmap) * n_basic_blocks); + bitmap *out = xmalloc (sizeof (bitmap) * n_basic_blocks); + bitmap *gen = xmalloc (sizeof (bitmap) * n_basic_blocks); + bitmap *kill = xmalloc (sizeof (bitmap) * n_basic_blocks); + for (i = 0; i < n_basic_blocks; i ++) { - in[bb->sindex] = DF_BB_INFO (df, bb)->ru_in; - out[bb->sindex] = DF_BB_INFO (df, bb)->ru_out; - gen[bb->sindex] = DF_BB_INFO (df, bb)->ru_gen; - kill[bb->sindex] = DF_BB_INFO (df, bb)->ru_kill; + in[i] = DF_BB_INFO (df, BASIC_BLOCK (i))->ru_in; + out[i] = DF_BB_INFO (df, BASIC_BLOCK (i))->ru_out; + gen[i] = DF_BB_INFO (df, BASIC_BLOCK (i))->ru_gen; + kill[i] = DF_BB_INFO (df, BASIC_BLOCK (i))->ru_kill; } iterative_dataflow_bitmap (in, out, gen, kill, df->all_blocks, BACKWARD, UNION, df_ru_transfer_function, @@ -2098,16 +2106,17 @@ df_analyse_1 (df, blocks, flags, update) /* Compute the sets of defs and uses of live variables. */ df_lr_local_compute (df, df->flags & DF_LR ? blocks : df->all_blocks); { - bitmap *in = xmalloc (sizeof (bitmap) * last_basic_block); - bitmap *out = xmalloc (sizeof (bitmap) * last_basic_block); - bitmap *use = xmalloc (sizeof (bitmap) * last_basic_block); - bitmap *def = xmalloc (sizeof (bitmap) * last_basic_block); - FOR_ALL_BB (bb) + int i; + bitmap *in = xmalloc (sizeof (bitmap) * n_basic_blocks); + bitmap *out = xmalloc (sizeof (bitmap) * n_basic_blocks); + bitmap *use = xmalloc (sizeof (bitmap) * n_basic_blocks); + bitmap *def = xmalloc (sizeof (bitmap) * n_basic_blocks); + for (i = 0; i < n_basic_blocks; i ++) { - in[bb->sindex] = DF_BB_INFO (df, bb)->lr_in; - out[bb->sindex] = DF_BB_INFO (df, bb)->lr_out; - use[bb->sindex] = DF_BB_INFO (df, bb)->lr_use; - def[bb->sindex] = DF_BB_INFO (df, bb)->lr_def; + in[i] = DF_BB_INFO (df, BASIC_BLOCK (i))->lr_in; + out[i] = DF_BB_INFO (df, BASIC_BLOCK (i))->lr_out; + use[i] = DF_BB_INFO (df, BASIC_BLOCK (i))->lr_use; + def[i] = DF_BB_INFO (df, BASIC_BLOCK (i))->lr_def; } iterative_dataflow_bitmap (in, out, use, def, df->all_blocks, BACKWARD, UNION, df_lr_transfer_function, @@ -2261,15 +2270,12 @@ df_modified_p (df, blocks) struct df *df; bitmap blocks; { + unsigned int j; int update = 0; - basic_block bb; - - if (!df->n_bbs) - return 0; - FOR_ALL_BB (bb) - if (bitmap_bit_p (df->bbs_modified, bb->sindex) - && (! blocks || (blocks == (bitmap) -1) || bitmap_bit_p (blocks, bb->sindex))) + for (j = 0; j < df->n_bbs; j++) + if (bitmap_bit_p (df->bbs_modified, j) + && (! blocks || (blocks == (bitmap) -1) || bitmap_bit_p (blocks, j))) { update = 1; break; @@ -2292,7 +2298,7 @@ df_analyse (df, blocks, flags) /* We could deal with additional basic blocks being created by rescanning everything again. */ - if (df->n_bbs && df->n_bbs != (unsigned int) last_basic_block) + if (df->n_bbs && df->n_bbs != (unsigned int)n_basic_blocks) abort (); update = df_modified_p (df, blocks); @@ -2402,8 +2408,10 @@ df_refs_unlink (df, blocks) } else { - FOR_ALL_BB (bb) + FOR_ALL_BBS (bb, + { df_bb_refs_unlink (df, bb); + }); } } #endif @@ -2451,7 +2459,7 @@ df_insn_modify (df, bb, insn) if (uid >= df->insn_size) df_insn_table_realloc (df, 0); - bitmap_set_bit (df->bbs_modified, bb->sindex); + bitmap_set_bit (df->bbs_modified, bb->index); bitmap_set_bit (df->insns_modified, uid); /* For incremental updating on the fly, perhaps we could make a copy @@ -3266,6 +3274,7 @@ df_dump (df, flags, file) int flags; FILE *file; { + unsigned int i; unsigned int j; if (! df || ! file) @@ -3277,23 +3286,22 @@ df_dump (df, flags, file) if (flags & DF_RD) { - basic_block bb; - fprintf (file, "Reaching defs:\n"); - FOR_ALL_BB (bb) + for (i = 0; i < df->n_bbs; i++) { + basic_block bb = BASIC_BLOCK (i); struct bb_info *bb_info = DF_BB_INFO (df, bb); if (! bb_info->rd_in) continue; - fprintf (file, "bb %d in \t", bb->sindex); + fprintf (file, "bb %d in \t", i); dump_bitmap (file, bb_info->rd_in); - fprintf (file, "bb %d gen \t", bb->sindex); + fprintf (file, "bb %d gen \t", i); dump_bitmap (file, bb_info->rd_gen); - fprintf (file, "bb %d kill\t", bb->sindex); + fprintf (file, "bb %d kill\t", i); dump_bitmap (file, bb_info->rd_kill); - fprintf (file, "bb %d out \t", bb->sindex); + fprintf (file, "bb %d out \t", i); dump_bitmap (file, bb_info->rd_out); } } @@ -3320,23 +3328,22 @@ df_dump (df, flags, file) if (flags & DF_RU) { - basic_block bb; - fprintf (file, "Reaching uses:\n"); - FOR_ALL_BB (bb) + for (i = 0; i < df->n_bbs; i++) { + basic_block bb = BASIC_BLOCK (i); struct bb_info *bb_info = DF_BB_INFO (df, bb); if (! bb_info->ru_in) continue; - fprintf (file, "bb %d in \t", bb->sindex); + fprintf (file, "bb %d in \t", i); dump_bitmap (file, bb_info->ru_in); - fprintf (file, "bb %d gen \t", bb->sindex); + fprintf (file, "bb %d gen \t", i); dump_bitmap (file, bb_info->ru_gen); - fprintf (file, "bb %d kill\t", bb->sindex); + fprintf (file, "bb %d kill\t", i); dump_bitmap (file, bb_info->ru_kill); - fprintf (file, "bb %d out \t", bb->sindex); + fprintf (file, "bb %d out \t", i); dump_bitmap (file, bb_info->ru_out); } } @@ -3363,23 +3370,22 @@ df_dump (df, flags, file) if (flags & DF_LR) { - basic_block bb; - fprintf (file, "Live regs:\n"); - FOR_ALL_BB (bb) + for (i = 0; i < df->n_bbs; i++) { + basic_block bb = BASIC_BLOCK (i); struct bb_info *bb_info = DF_BB_INFO (df, bb); if (! bb_info->lr_in) continue; - fprintf (file, "bb %d in \t", bb->sindex); + fprintf (file, "bb %d in \t", i); dump_bitmap (file, bb_info->lr_in); - fprintf (file, "bb %d use \t", bb->sindex); + fprintf (file, "bb %d use \t", i); dump_bitmap (file, bb_info->lr_use); - fprintf (file, "bb %d def \t", bb->sindex); + fprintf (file, "bb %d def \t", i); dump_bitmap (file, bb_info->lr_def); - fprintf (file, "bb %d out \t", bb->sindex); + fprintf (file, "bb %d out \t", i); dump_bitmap (file, bb_info->lr_out); } } @@ -3402,7 +3408,7 @@ df_dump (df, flags, file) basic_block bb = df_regno_bb (df, j); if (bb) - fprintf (file, " bb %d", bb->sindex); + fprintf (file, " bb %d", bb->index); else fprintf (file, " bb ?"); } @@ -3603,11 +3609,11 @@ hybrid_search_bitmap (block, in, out, gen, kill, dir, void *data; { int changed; - int i = block->sindex; + int i = block->index; edge e; - basic_block bb = block; - SET_BIT (visited, block->sindex); - if (TEST_BIT (pending, block->sindex)) + basic_block bb= block; + SET_BIT (visited, block->index); + if (TEST_BIT (pending, block->index)) { if (dir == FORWARD) { @@ -3620,10 +3626,10 @@ hybrid_search_bitmap (block, in, out, gen, kill, dir, switch (conf_op) { case UNION: - bitmap_a_or_b (in[i], in[i], out[e->src->sindex]); + bitmap_a_or_b (in[i], in[i], out[e->src->index]); break; case INTERSECTION: - bitmap_a_and_b (in[i], in[i], out[e->src->sindex]); + bitmap_a_and_b (in[i], in[i], out[e->src->index]); break; } } @@ -3639,10 +3645,10 @@ hybrid_search_bitmap (block, in, out, gen, kill, dir, switch (conf_op) { case UNION: - bitmap_a_or_b (out[i], out[i], in[e->dest->sindex]); + bitmap_a_or_b (out[i], out[i], in[e->dest->index]); break; case INTERSECTION: - bitmap_a_and_b (out[i], out[i], in[e->dest->sindex]); + bitmap_a_and_b (out[i], out[i], in[e->dest->index]); break; } } @@ -3656,18 +3662,18 @@ hybrid_search_bitmap (block, in, out, gen, kill, dir, { for (e = bb->succ; e != 0; e = e->succ_next) { - if (e->dest == EXIT_BLOCK_PTR || e->dest == block) + if (e->dest == EXIT_BLOCK_PTR || e->dest->index == i) continue; - SET_BIT (pending, e->dest->sindex); + SET_BIT (pending, e->dest->index); } } else { for (e = bb->pred; e != 0; e = e->pred_next) { - if (e->src == ENTRY_BLOCK_PTR || e->dest == block) + if (e->src == ENTRY_BLOCK_PTR || e->dest->index == i) continue; - SET_BIT (pending, e->src->sindex); + SET_BIT (pending, e->src->index); } } } @@ -3676,11 +3682,11 @@ hybrid_search_bitmap (block, in, out, gen, kill, dir, { for (e = bb->succ; e != 0; e = e->succ_next) { - if (e->dest == EXIT_BLOCK_PTR || e->dest == block) + if (e->dest == EXIT_BLOCK_PTR || e->dest->index == i) continue; - if (!TEST_BIT (visited, e->dest->sindex)) - hybrid_search_bitmap (e->dest, in, out, gen, kill, dir, - conf_op, transfun, visited, pending, + if (!TEST_BIT (visited, e->dest->index)) + hybrid_search_bitmap (e->dest, in, out, gen, kill, dir, + conf_op, transfun, visited, pending, data); } } @@ -3688,9 +3694,9 @@ hybrid_search_bitmap (block, in, out, gen, kill, dir, { for (e = bb->pred; e != 0; e = e->pred_next) { - if (e->src == ENTRY_BLOCK_PTR || e->src == block) + if (e->src == ENTRY_BLOCK_PTR || e->src->index == i) continue; - if (!TEST_BIT (visited, e->src->sindex)) + if (!TEST_BIT (visited, e->src->index)) hybrid_search_bitmap (e->src, in, out, gen, kill, dir, conf_op, transfun, visited, pending, data); @@ -3714,11 +3720,11 @@ hybrid_search_sbitmap (block, in, out, gen, kill, dir, void *data; { int changed; - int i = block->sindex; + int i = block->index; edge e; - basic_block bb = block; - SET_BIT (visited, block->sindex); - if (TEST_BIT (pending, block->sindex)) + basic_block bb= block; + SET_BIT (visited, block->index); + if (TEST_BIT (pending, block->index)) { if (dir == FORWARD) { @@ -3731,10 +3737,10 @@ hybrid_search_sbitmap (block, in, out, gen, kill, dir, switch (conf_op) { case UNION: - sbitmap_a_or_b (in[i], in[i], out[e->src->sindex]); + sbitmap_a_or_b (in[i], in[i], out[e->src->index]); break; case INTERSECTION: - sbitmap_a_and_b (in[i], in[i], out[e->src->sindex]); + sbitmap_a_and_b (in[i], in[i], out[e->src->index]); break; } } @@ -3750,10 +3756,10 @@ hybrid_search_sbitmap (block, in, out, gen, kill, dir, switch (conf_op) { case UNION: - sbitmap_a_or_b (out[i], out[i], in[e->dest->sindex]); + sbitmap_a_or_b (out[i], out[i], in[e->dest->index]); break; case INTERSECTION: - sbitmap_a_and_b (out[i], out[i], in[e->dest->sindex]); + sbitmap_a_and_b (out[i], out[i], in[e->dest->index]); break; } } @@ -3767,18 +3773,18 @@ hybrid_search_sbitmap (block, in, out, gen, kill, dir, { for (e = bb->succ; e != 0; e = e->succ_next) { - if (e->dest == EXIT_BLOCK_PTR || e->dest == block) + if (e->dest == EXIT_BLOCK_PTR || e->dest->index == i) continue; - SET_BIT (pending, e->dest->sindex); + SET_BIT (pending, e->dest->index); } } else { for (e = bb->pred; e != 0; e = e->pred_next) { - if (e->src == ENTRY_BLOCK_PTR || e->dest == block) + if (e->src == ENTRY_BLOCK_PTR || e->dest->index == i) continue; - SET_BIT (pending, e->src->sindex); + SET_BIT (pending, e->src->index); } } } @@ -3787,9 +3793,9 @@ hybrid_search_sbitmap (block, in, out, gen, kill, dir, { for (e = bb->succ; e != 0; e = e->succ_next) { - if (e->dest == EXIT_BLOCK_PTR || e->dest == block) + if (e->dest == EXIT_BLOCK_PTR || e->dest->index == i) continue; - if (!TEST_BIT (visited, e->dest->sindex)) + if (!TEST_BIT (visited, e->dest->index)) hybrid_search_sbitmap (e->dest, in, out, gen, kill, dir, conf_op, transfun, visited, pending, data); @@ -3799,9 +3805,9 @@ hybrid_search_sbitmap (block, in, out, gen, kill, dir, { for (e = bb->pred; e != 0; e = e->pred_next) { - if (e->src == ENTRY_BLOCK_PTR || e->src == block) + if (e->src == ENTRY_BLOCK_PTR || e->src->index == i) continue; - if (!TEST_BIT (visited, e->src->sindex)) + if (!TEST_BIT (visited, e->src->index)) hybrid_search_sbitmap (e->src, in, out, gen, kill, dir, conf_op, transfun, visited, pending, data); @@ -3847,8 +3853,8 @@ iterative_dataflow_sbitmap (in, out, gen, kill, blocks, fibheap_t worklist; basic_block bb; sbitmap visited, pending; - pending = sbitmap_alloc (last_basic_block); - visited = sbitmap_alloc (last_basic_block); + pending = sbitmap_alloc (n_basic_blocks); + visited = sbitmap_alloc (n_basic_blocks); sbitmap_zero (pending); sbitmap_zero (visited); worklist = fibheap_new (); @@ -3867,7 +3873,7 @@ iterative_dataflow_sbitmap (in, out, gen, kill, blocks, { i = (size_t) fibheap_extract_min (worklist); bb = BASIC_BLOCK (i); - if (!TEST_BIT (visited, bb->sindex)) + if (!TEST_BIT (visited, bb->index)) hybrid_search_sbitmap (bb, in, out, gen, kill, dir, conf_op, transfun, visited, pending, data); } @@ -3906,8 +3912,8 @@ iterative_dataflow_bitmap (in, out, gen, kill, blocks, fibheap_t worklist; basic_block bb; sbitmap visited, pending; - pending = sbitmap_alloc (last_basic_block); - visited = sbitmap_alloc (last_basic_block); + pending = sbitmap_alloc (n_basic_blocks); + visited = sbitmap_alloc (n_basic_blocks); sbitmap_zero (pending); sbitmap_zero (visited); worklist = fibheap_new (); @@ -3926,7 +3932,7 @@ iterative_dataflow_bitmap (in, out, gen, kill, blocks, { i = (size_t) fibheap_extract_min (worklist); bb = BASIC_BLOCK (i); - if (!TEST_BIT (visited, bb->sindex)) + if (!TEST_BIT (visited, bb->index)) hybrid_search_bitmap (bb, in, out, gen, kill, dir, conf_op, transfun, visited, pending, data); } |