diff options
Diffstat (limited to 'gcc/cfgbuild.c')
-rw-r--r-- | gcc/cfgbuild.c | 126 |
1 files changed, 62 insertions, 64 deletions
diff --git a/gcc/cfgbuild.c b/gcc/cfgbuild.c index 5ce9d40f3b0..d531877597e 100644 --- a/gcc/cfgbuild.c +++ b/gcc/cfgbuild.c @@ -50,7 +50,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA static int count_basic_blocks PARAMS ((rtx)); static void find_basic_blocks_1 PARAMS ((rtx)); static rtx find_label_refs PARAMS ((rtx, rtx)); -static void make_edges PARAMS ((rtx, int, int, int)); +static void make_edges PARAMS ((rtx, basic_block, + basic_block, int)); static void make_label_edge PARAMS ((sbitmap *, basic_block, rtx, int)); static void make_eh_edge PARAMS ((sbitmap *, basic_block, rtx)); @@ -280,9 +281,10 @@ make_eh_edge (edge_cache, src, insn) static void make_edges (label_value_list, min, max, update_p) rtx label_value_list; - int min, max, update_p; + basic_block min, max; + int update_p; { - int i; + basic_block bb; sbitmap *edge_cache = NULL; /* Assume no computed jump; revise as we create edges. */ @@ -293,28 +295,26 @@ make_edges (label_value_list, min, max, update_p) amount of time searching the edge lists for duplicates. */ if (forced_labels || label_value_list) { - edge_cache = sbitmap_vector_alloc (n_basic_blocks, n_basic_blocks); - sbitmap_vector_zero (edge_cache, n_basic_blocks); + edge_cache = sbitmap_vector_alloc (last_basic_block, last_basic_block); + sbitmap_vector_zero (edge_cache, last_basic_block); if (update_p) - for (i = min; i <= max; ++i) + FOR_BB_BETWEEN (bb, min, max->next_bb, next_bb) { edge e; - for (e = BASIC_BLOCK (i)->succ; e ; e = e->succ_next) + for (e = bb->succ; e ; e = e->succ_next) if (e->dest != EXIT_BLOCK_PTR) - SET_BIT (edge_cache[i], e->dest->index); + SET_BIT (edge_cache[bb->sindex], e->dest->sindex); } } - /* By nature of the way these get numbered, block 0 is always the entry. */ - if (min == 0) - cached_make_edge (edge_cache, ENTRY_BLOCK_PTR, BASIC_BLOCK (0), + if (min == ENTRY_BLOCK_PTR->next_bb) + cached_make_edge (edge_cache, ENTRY_BLOCK_PTR, min, EDGE_FALLTHRU); - for (i = min; i <= max; ++i) + FOR_BB_BETWEEN (bb, min, max->next_bb, next_bb) { - basic_block bb = BASIC_BLOCK (i); rtx insn, x; enum rtx_code code; int force_fallthru = 0; @@ -443,15 +443,16 @@ make_edges (label_value_list, min, max, update_p) /* Find out if we can drop through to the next block. */ insn = next_nonnote_insn (insn); - if (!insn || (i + 1 == n_basic_blocks && force_fallthru)) + + if (!insn || (bb->next_bb == EXIT_BLOCK_PTR && force_fallthru)) cached_make_edge (edge_cache, bb, EXIT_BLOCK_PTR, EDGE_FALLTHRU); - else if (i + 1 < n_basic_blocks) + else if (bb->next_bb != EXIT_BLOCK_PTR) { - rtx tmp = BLOCK_HEAD (i + 1); + rtx tmp = bb->next_bb->head; if (GET_CODE (tmp) == NOTE) tmp = next_nonnote_insn (tmp); if (force_fallthru || insn == tmp) - cached_make_edge (edge_cache, bb, BASIC_BLOCK (i + 1), + cached_make_edge (edge_cache, bb, bb->next_bb, EDGE_FALLTHRU); } } @@ -470,12 +471,12 @@ find_basic_blocks_1 (f) rtx f; { rtx insn, next; - int i = 0; rtx bb_note = NULL_RTX; rtx lvl = NULL_RTX; rtx trll = NULL_RTX; rtx head = NULL_RTX; rtx end = NULL_RTX; + basic_block prev = ENTRY_BLOCK_PTR; /* We process the instructions in a slightly different way than we did previously. This is so that we see a NOTE_BASIC_BLOCK after we have @@ -492,7 +493,7 @@ find_basic_blocks_1 (f) if ((GET_CODE (insn) == CODE_LABEL || GET_CODE (insn) == BARRIER) && head) { - create_basic_block_structure (i++, head, end, bb_note); + prev = create_basic_block_structure (last_basic_block++, head, end, bb_note, prev); head = end = NULL_RTX; bb_note = NULL_RTX; } @@ -506,7 +507,7 @@ find_basic_blocks_1 (f) if (head && control_flow_insn_p (insn)) { - create_basic_block_structure (i++, head, end, bb_note); + prev = create_basic_block_structure (last_basic_block++, head, end, bb_note, prev); head = end = NULL_RTX; bb_note = NULL_RTX; } @@ -588,11 +589,11 @@ find_basic_blocks_1 (f) } if (head != NULL_RTX) - create_basic_block_structure (i++, head, end, bb_note); + create_basic_block_structure (last_basic_block++, head, end, bb_note, prev); else if (bb_note) delete_insn (bb_note); - if (i != n_basic_blocks) + if (last_basic_block != num_basic_blocks) abort (); label_value_list = lvl; @@ -612,6 +613,7 @@ find_basic_blocks (f, nregs, file) FILE *file ATTRIBUTE_UNUSED; { int max_uid; + basic_block bb; timevar_push (TV_CFG); basic_block_for_insn = 0; @@ -619,20 +621,21 @@ find_basic_blocks (f, nregs, file) /* Flush out existing data. */ if (basic_block_info != NULL) { - int i; - clear_edges (); /* Clear bb->aux on all extant basic blocks. We'll use this as a tag for reuse during create_basic_block, just in case some pass copies around basic block notes improperly. */ - for (i = 0; i < n_basic_blocks; ++i) - BASIC_BLOCK (i)->aux = NULL; + FOR_ALL_BB (bb) + bb->aux = NULL; VARRAY_FREE (basic_block_info); } - n_basic_blocks = count_basic_blocks (f); + num_basic_blocks = count_basic_blocks (f); + last_basic_block = 0; + ENTRY_BLOCK_PTR->next_bb = EXIT_BLOCK_PTR; + EXIT_BLOCK_PTR->prev_bb = ENTRY_BLOCK_PTR; /* Size the basic block table. The actual structures will be allocated by find_basic_blocks_1, since we want to keep the structure pointers @@ -642,7 +645,7 @@ find_basic_blocks (f, nregs, file) instructions at all until close to the end of compilation when we actually lay them out. */ - VARRAY_BB_INIT (basic_block_info, n_basic_blocks, "basic_block_info"); + VARRAY_BB_INIT (basic_block_info, num_basic_blocks, "basic_block_info"); find_basic_blocks_1 (f); @@ -661,7 +664,7 @@ find_basic_blocks (f, nregs, file) compute_bb_for_insn (max_uid); /* Discover the edges of our cfg. */ - make_edges (label_value_list, 0, n_basic_blocks - 1, 0); + make_edges (label_value_list, ENTRY_BLOCK_PTR->next_bb, EXIT_BLOCK_PTR->prev_bb, 0); /* Do very simple cleanup now, for the benefit of code that runs between here and cleanup_cfg, e.g. thread_prologue_and_epilogue_insns. */ @@ -790,25 +793,24 @@ void find_many_sub_basic_blocks (blocks) sbitmap blocks; { - int i; - int min, max; + basic_block bb, min, max; - for (i = 0; i < n_basic_blocks; i++) - SET_STATE (BASIC_BLOCK (i), - TEST_BIT (blocks, i) ? BLOCK_TO_SPLIT : BLOCK_ORIGINAL); + FOR_ALL_BB (bb) + SET_STATE (bb, + TEST_BIT (blocks, bb->sindex) ? BLOCK_TO_SPLIT : BLOCK_ORIGINAL); - for (i = 0; i < n_basic_blocks; i++) - if (STATE (BASIC_BLOCK (i)) == BLOCK_TO_SPLIT) - find_bb_boundaries (BASIC_BLOCK (i)); + FOR_ALL_BB (bb) + if (STATE (bb) == BLOCK_TO_SPLIT) + find_bb_boundaries (bb); - for (i = 0; i < n_basic_blocks; i++) - if (STATE (BASIC_BLOCK (i)) != BLOCK_ORIGINAL) + FOR_ALL_BB (bb) + if (STATE (bb) != BLOCK_ORIGINAL) break; - min = max = i; - for (; i < n_basic_blocks; i++) - if (STATE (BASIC_BLOCK (i)) != BLOCK_ORIGINAL) - max = i; + min = max = bb; + for (; bb != EXIT_BLOCK_PTR; bb = bb->next_bb) + if (STATE (bb) != BLOCK_ORIGINAL) + max = bb; /* Now re-scan and wire in all edges. This expect simple (conditional) jumps at the end of each new basic blocks. */ @@ -816,29 +818,28 @@ find_many_sub_basic_blocks (blocks) /* Update branch probabilities. Expect only (un)conditional jumps to be created with only the forward edges. */ - for (i = min; i <= max; i++) + FOR_BB_BETWEEN (bb, min, max->next_bb, next_bb) { edge e; - basic_block b = BASIC_BLOCK (i); - if (STATE (b) == BLOCK_ORIGINAL) + if (STATE (bb) == BLOCK_ORIGINAL) continue; - if (STATE (b) == BLOCK_NEW) + if (STATE (bb) == BLOCK_NEW) { - b->count = 0; - b->frequency = 0; - for (e = b->pred; e; e=e->pred_next) + bb->count = 0; + bb->frequency = 0; + for (e = bb->pred; e; e=e->pred_next) { - b->count += e->count; - b->frequency += EDGE_FREQUENCY (e); + bb->count += e->count; + bb->frequency += EDGE_FREQUENCY (e); } } - compute_outgoing_frequencies (b); + compute_outgoing_frequencies (bb); } - for (i = 0; i < n_basic_blocks; i++) - SET_STATE (BASIC_BLOCK (i), 0); + FOR_ALL_BB (bb) + SET_STATE (bb, 0); } /* Like above but for single basic block only. */ @@ -847,14 +848,12 @@ void find_sub_basic_blocks (bb) basic_block bb; { - int i; - int min, max; - basic_block next = (bb->index == n_basic_blocks - 1 - ? NULL : BASIC_BLOCK (bb->index + 1)); + basic_block min, max, b; + basic_block next = bb->next_bb; - min = bb->index; + min = bb; find_bb_boundaries (bb); - max = (next ? next->index : n_basic_blocks) - 1; + max = next->prev_bb; /* Now re-scan and wire in all edges. This expect simple (conditional) jumps at the end of each new basic blocks. */ @@ -862,12 +861,11 @@ find_sub_basic_blocks (bb) /* Update branch probabilities. Expect only (un)conditional jumps to be created with only the forward edges. */ - for (i = min; i <= max; i++) + FOR_BB_BETWEEN (b, min, max->next_bb, next_bb) { edge e; - basic_block b = BASIC_BLOCK (i); - if (i != min) + if (b != min) { b->count = 0; b->frequency = 0; |