summaryrefslogtreecommitdiffstats
path: root/gcc/predict.c
diff options
context:
space:
mode:
authorrth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>2002-05-16 17:34:53 +0000
committerrth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>2002-05-16 17:34:53 +0000
commit4c5da23833f4604c04fb829abf1a39ab6976e7b2 (patch)
tree47d672ee2344eb156d43b4e6fc935c02ed904ce7 /gcc/predict.c
parent14abf9235794ba37b9ad3ef6381ad36c3606370d (diff)
downloadppe42-gcc-4c5da23833f4604c04fb829abf1a39ab6976e7b2.tar.gz
ppe42-gcc-4c5da23833f4604c04fb829abf1a39ab6976e7b2.zip
Basic block renumbering removal.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@53522 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/predict.c')
-rw-r--r--gcc/predict.c181
1 files changed, 75 insertions, 106 deletions
diff --git a/gcc/predict.c b/gcc/predict.c
index f457817956d..5eda98c31da 100644
--- a/gcc/predict.c
+++ b/gcc/predict.c
@@ -319,7 +319,7 @@ combine_predictions_for_insn (insn, bb)
if (rtl_dump_file)
fprintf (rtl_dump_file, "Predictions for insn %i bb %i\n", INSN_UID (insn),
- bb->index);
+ bb->sindex);
/* We implement "first match" heuristics and use probability guessed
by predictor with smallest index. In the future we will use better
@@ -409,10 +409,11 @@ estimate_probability (loops_info)
struct loops *loops_info;
{
sbitmap *dominators, *post_dominators;
+ basic_block bb;
int i;
- dominators = sbitmap_vector_alloc (n_basic_blocks, n_basic_blocks);
- post_dominators = sbitmap_vector_alloc (n_basic_blocks, n_basic_blocks);
+ dominators = sbitmap_vector_alloc (last_basic_block, last_basic_block);
+ post_dominators = sbitmap_vector_alloc (last_basic_block, last_basic_block);
calculate_dominance_info (NULL, dominators, CDI_DOMINATORS);
calculate_dominance_info (NULL, post_dominators, CDI_POST_DOMINATORS);
@@ -420,15 +421,14 @@ estimate_probability (loops_info)
natural loop. */
for (i = 0; i < loops_info->num; i++)
{
- int j;
int exits;
struct loop *loop = &loops_info->array[i];
flow_loop_scan (loops_info, loop, LOOP_EXIT_EDGES);
exits = loop->num_exits;
- for (j = loop->first->index; j <= loop->last->index; ++j)
- if (TEST_BIT (loop->nodes, j))
+ FOR_BB_BETWEEN (bb, loop->first, loop->last->next_bb, next_bb)
+ if (TEST_BIT (loop->nodes, bb->sindex))
{
int header_found = 0;
edge e;
@@ -437,12 +437,12 @@ estimate_probability (loops_info)
statements construct loops via "non-loop" constructs
in the source language and are better to be handled
separately. */
- if (predicted_by_p (BASIC_BLOCK (j), PRED_CONTINUE))
+ if (predicted_by_p (bb, PRED_CONTINUE))
continue;
/* Loop branch heuristics - predict an edge back to a
loop's head as taken. */
- for (e = BASIC_BLOCK(j)->succ; e; e = e->succ_next)
+ for (e = bb->succ; e; e = e->succ_next)
if (e->dest == loop->header
&& e->src == loop->latch)
{
@@ -453,9 +453,9 @@ estimate_probability (loops_info)
/* Loop exit heuristics - predict an edge exiting the loop if the
conditinal has no loop header successors as not taken. */
if (!header_found)
- for (e = BASIC_BLOCK(j)->succ; e; e = e->succ_next)
- if (e->dest->index < 0
- || !TEST_BIT (loop->nodes, e->dest->index))
+ for (e = bb->succ; e; e = e->succ_next)
+ if (e->dest->sindex < 0
+ || !TEST_BIT (loop->nodes, e->dest->sindex))
predict_edge
(e, PRED_LOOP_EXIT,
(REG_BR_PROB_BASE
@@ -465,9 +465,8 @@ estimate_probability (loops_info)
}
/* Attempt to predict conditional jumps using a number of heuristics. */
- for (i = 0; i < n_basic_blocks; i++)
+ FOR_ALL_BB (bb)
{
- basic_block bb = BASIC_BLOCK (i);
rtx last_insn = bb->end;
rtx cond, earliest;
edge e;
@@ -492,8 +491,8 @@ estimate_probability (loops_info)
/* Look for block we are guarding (ie we dominate it,
but it doesn't postdominate us). */
if (e->dest != EXIT_BLOCK_PTR && e->dest != bb
- && TEST_BIT (dominators[e->dest->index], e->src->index)
- && !TEST_BIT (post_dominators[e->src->index], e->dest->index))
+ && TEST_BIT (dominators[e->dest->sindex], e->src->sindex)
+ && !TEST_BIT (post_dominators[e->src->sindex], e->dest->sindex))
{
rtx insn;
@@ -604,11 +603,11 @@ estimate_probability (loops_info)
}
/* Attach the combined probability to each conditional jump. */
- for (i = 0; i < n_basic_blocks; i++)
- if (GET_CODE (BLOCK_END (i)) == JUMP_INSN
- && any_condjump_p (BLOCK_END (i))
- && BASIC_BLOCK (i)->succ->succ_next != NULL)
- combine_predictions_for_insn (BLOCK_END (i), BASIC_BLOCK (i));
+ FOR_ALL_BB (bb)
+ if (GET_CODE (bb->end) == JUMP_INSN
+ && any_condjump_p (bb->end)
+ && bb->succ->succ_next != NULL)
+ combine_predictions_for_insn (bb->end, bb);
sbitmap_vector_free (post_dominators);
sbitmap_vector_free (dominators);
@@ -695,13 +694,16 @@ static bool
last_basic_block_p (bb)
basic_block bb;
{
- return (bb->index == n_basic_blocks - 1
- || (bb->index == n_basic_blocks - 2
+ if (bb == EXIT_BLOCK_PTR)
+ return false;
+
+ return (bb->next_bb == EXIT_BLOCK_PTR
+ || (bb->next_bb->next_bb == EXIT_BLOCK_PTR
&& bb->succ && !bb->succ->succ_next
- && bb->succ->dest->index == n_basic_blocks - 1));
+ && bb->succ->dest->next_bb == EXIT_BLOCK_PTR));
}
-/* Sets branch probabilities according to PREDiction and FLAGS. HEADS[bb->index]
+/* Sets branch probabilities according to PREDiction and FLAGS. HEADS[bb->sindex]
should be index of basic block in that we need to alter branch predictions
(i.e. the first of our dominators such that we do not post-dominate it)
(but we fill this information on demand, so -1 may be there in case this
@@ -722,43 +724,43 @@ process_note_prediction (bb, heads, dominators, post_dominators, pred, flags)
taken = flags & IS_TAKEN;
- if (heads[bb->index] < 0)
+ if (heads[bb->sindex] < 0)
{
/* This is first time we need this field in heads array; so
find first dominator that we do not post-dominate (we are
using already known members of heads array). */
- int ai = bb->index;
- int next_ai = dominators[bb->index];
+ int ai = bb->sindex;
+ int next_ai = dominators[bb->sindex];
int head;
while (heads[next_ai] < 0)
{
- if (!TEST_BIT (post_dominators[next_ai], bb->index))
+ if (!TEST_BIT (post_dominators[next_ai], bb->sindex))
break;
heads[next_ai] = ai;
ai = next_ai;
next_ai = dominators[next_ai];
}
- if (!TEST_BIT (post_dominators[next_ai], bb->index))
+ if (!TEST_BIT (post_dominators[next_ai], bb->sindex))
head = next_ai;
else
head = heads[next_ai];
- while (next_ai != bb->index)
+ while (next_ai != bb->sindex)
{
next_ai = ai;
ai = heads[ai];
heads[next_ai] = head;
}
}
- y = heads[bb->index];
+ y = heads[bb->sindex];
/* Now find the edge that leads to our branch and aply the prediction. */
- if (y == n_basic_blocks)
+ if (y == last_basic_block)
return;
for (e = BASIC_BLOCK (y)->succ; e; e = e->succ_next)
- if (e->dest->index >= 0
- && TEST_BIT (post_dominators[e->dest->index], bb->index))
+ if (e->dest->sindex >= 0
+ && TEST_BIT (post_dominators[e->dest->sindex], bb->sindex))
predict_edge_def (e, pred, taken);
}
@@ -831,7 +833,7 @@ process_note_predictions (bb, heads, dominators, post_dominators)
void
note_prediction_to_br_prob ()
{
- int i;
+ basic_block bb;
sbitmap *post_dominators;
int *dominators, *heads;
@@ -839,23 +841,20 @@ note_prediction_to_br_prob ()
add_noreturn_fake_exit_edges ();
connect_infinite_loops_to_exit ();
- dominators = xmalloc (sizeof (int) * n_basic_blocks);
- memset (dominators, -1, sizeof (int) * n_basic_blocks);
- post_dominators = sbitmap_vector_alloc (n_basic_blocks, n_basic_blocks);
+ dominators = xmalloc (sizeof (int) * last_basic_block);
+ memset (dominators, -1, sizeof (int) * last_basic_block);
+ post_dominators = sbitmap_vector_alloc (last_basic_block, last_basic_block);
calculate_dominance_info (NULL, post_dominators, CDI_POST_DOMINATORS);
calculate_dominance_info (dominators, NULL, CDI_DOMINATORS);
- heads = xmalloc (sizeof (int) * n_basic_blocks);
- memset (heads, -1, sizeof (int) * n_basic_blocks);
- heads[0] = n_basic_blocks;
+ heads = xmalloc (sizeof (int) * last_basic_block);
+ memset (heads, -1, sizeof (int) * last_basic_block);
+ heads[ENTRY_BLOCK_PTR->next_bb->sindex] = last_basic_block;
/* Process all prediction notes. */
- for (i = 0; i < n_basic_blocks; ++i)
- {
- basic_block bb = BASIC_BLOCK (i);
- process_note_predictions (bb, heads, dominators, post_dominators);
- }
+ FOR_ALL_BB (bb)
+ process_note_predictions (bb, heads, dominators, post_dominators);
sbitmap_vector_free (post_dominators);
free (dominators);
@@ -903,17 +902,15 @@ static void
propagate_freq (head)
basic_block head;
{
- basic_block bb = head;
- basic_block last = bb;
+ basic_block bb;
+ basic_block last;
edge e;
basic_block nextbb;
- int n;
/* For each basic block we need to visit count number of his predecessors
we need to visit first. */
- for (n = 0; n < n_basic_blocks; n++)
+ FOR_ALL_BB (bb)
{
- basic_block bb = BASIC_BLOCK (n);
if (BLOCK_INFO (bb)->tovisit)
{
int count = 0;
@@ -925,13 +922,14 @@ propagate_freq (head)
&& rtl_dump_file && !EDGE_INFO (e)->back_edge)
fprintf (rtl_dump_file,
"Irreducible region hit, ignoring edge to %i->%i\n",
- e->src->index, bb->index);
+ e->src->sindex, bb->sindex);
BLOCK_INFO (bb)->npredecessors = count;
}
}
memcpy (&BLOCK_INFO (head)->frequency, &real_one, sizeof (real_one));
- for (; bb; bb = nextbb)
+ last = head;
+ for (bb = head; bb; bb = nextbb)
{
REAL_VALUE_TYPE cyclic_probability, frequency;
@@ -1074,24 +1072,13 @@ static void
counts_to_freqs ()
{
HOST_WIDEST_INT count_max = 1;
- int i;
-
- for (i = 0; i < n_basic_blocks; i++)
- count_max = MAX (BASIC_BLOCK (i)->count, count_max);
+ basic_block bb;
- for (i = -2; i < n_basic_blocks; i++)
- {
- basic_block bb;
-
- if (i == -2)
- bb = ENTRY_BLOCK_PTR;
- else if (i == -1)
- bb = EXIT_BLOCK_PTR;
- else
- bb = BASIC_BLOCK (i);
+ FOR_ALL_BB (bb)
+ count_max = MAX (bb->count, count_max);
- bb->frequency = (bb->count * BB_FREQ_MAX + count_max / 2) / count_max;
- }
+ FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
+ bb->frequency = (bb->count * BB_FREQ_MAX + count_max / 2) / count_max;
}
/* Return true if function is likely to be expensive, so there is no point to
@@ -1104,7 +1091,7 @@ expensive_function_p (threshold)
int threshold;
{
unsigned int sum = 0;
- int i;
+ basic_block bb;
unsigned int limit;
/* We can not compute accurately for large thresholds due to scaled
@@ -1120,9 +1107,8 @@ expensive_function_p (threshold)
/* Maximally BB_FREQ_MAX^2 so overflow won't happen. */
limit = ENTRY_BLOCK_PTR->frequency * threshold;
- for (i = 0; i < n_basic_blocks; i++)
+ FOR_ALL_BB (bb)
{
- basic_block bb = BASIC_BLOCK (i);
rtx insn;
for (insn = bb->head; insn != NEXT_INSN (bb->end);
@@ -1144,7 +1130,7 @@ static void
estimate_bb_frequencies (loops)
struct loops *loops;
{
- int i;
+ basic_block bb;
REAL_VALUE_TYPE freq_max;
enum machine_mode double_mode = TYPE_MODE (double_type_node);
@@ -1166,13 +1152,13 @@ estimate_bb_frequencies (loops)
mark_dfs_back_edges ();
/* Fill in the probability values in flowgraph based on the REG_BR_PROB
notes. */
- for (i = 0; i < n_basic_blocks; i++)
+ FOR_ALL_BB (bb)
{
- rtx last_insn = BLOCK_END (i);
+ rtx last_insn = bb->end;
if (GET_CODE (last_insn) != JUMP_INSN || !any_condjump_p (last_insn)
/* Avoid handling of conditional jumps jumping to fallthru edge. */
- || BASIC_BLOCK (i)->succ->succ_next == NULL)
+ || bb->succ->succ_next == NULL)
{
/* We can predict only conditional jumps at the moment.
Expect each edge to be equally probable.
@@ -1180,14 +1166,14 @@ estimate_bb_frequencies (loops)
int nedges = 0;
edge e;
- for (e = BASIC_BLOCK (i)->succ; e; e = e->succ_next)
+ for (e = bb->succ; e; e = e->succ_next)
{
nedges++;
if (e->probability != 0)
break;
}
if (!e)
- for (e = BASIC_BLOCK (i)->succ; e; e = e->succ_next)
+ for (e = bb->succ; e; e = e->succ_next)
e->probability = (REG_BR_PROB_BASE + nedges / 2) / nedges;
}
}
@@ -1197,17 +1183,10 @@ estimate_bb_frequencies (loops)
/* Set up block info for each basic block. */
alloc_aux_for_blocks (sizeof (struct block_info_def));
alloc_aux_for_edges (sizeof (struct edge_info_def));
- for (i = -2; i < n_basic_blocks; i++)
+
+ FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
{
edge e;
- basic_block bb;
-
- if (i == -2)
- bb = ENTRY_BLOCK_PTR;
- else if (i == -1)
- bb = EXIT_BLOCK_PTR;
- else
- bb = BASIC_BLOCK (i);
BLOCK_INFO (bb)->tovisit = 0;
for (e = bb->succ; e; e = e->succ_next)
@@ -1226,32 +1205,22 @@ estimate_bb_frequencies (loops)
estimate_loops_at_level (loops->tree_root);
/* Now fake loop around whole function to finalize probabilities. */
- for (i = 0; i < n_basic_blocks; i++)
- BLOCK_INFO (BASIC_BLOCK (i))->tovisit = 1;
+ FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
+ BLOCK_INFO (bb)->tovisit = 1;
- BLOCK_INFO (ENTRY_BLOCK_PTR)->tovisit = 1;
- BLOCK_INFO (EXIT_BLOCK_PTR)->tovisit = 1;
propagate_freq (ENTRY_BLOCK_PTR);
memcpy (&freq_max, &real_zero, sizeof (real_zero));
- for (i = 0; i < n_basic_blocks; i++)
+ FOR_ALL_BB (bb)
if (REAL_VALUES_LESS
- (freq_max, BLOCK_INFO (BASIC_BLOCK (i))->frequency))
- memcpy (&freq_max, &BLOCK_INFO (BASIC_BLOCK (i))->frequency,
+ (freq_max, BLOCK_INFO (bb)->frequency))
+ memcpy (&freq_max, &BLOCK_INFO (bb)->frequency,
sizeof (freq_max));
- for (i = -2; i < n_basic_blocks; i++)
+ FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
{
- basic_block bb;
REAL_VALUE_TYPE tmp;
- if (i == -2)
- bb = ENTRY_BLOCK_PTR;
- else if (i == -1)
- bb = EXIT_BLOCK_PTR;
- else
- bb = BASIC_BLOCK (i);
-
REAL_ARITHMETIC (tmp, MULT_EXPR, BLOCK_INFO (bb)->frequency,
real_bb_freq_max);
REAL_ARITHMETIC (tmp, RDIV_EXPR, tmp, freq_max);
@@ -1271,14 +1240,14 @@ estimate_bb_frequencies (loops)
static void
compute_function_frequency ()
{
- int i;
+ basic_block bb;
+
if (!profile_info.count_profiles_merged
|| !flag_branch_probabilities)
return;
cfun->function_frequency = FUNCTION_FREQUENCY_UNLIKELY_EXECUTED;
- for (i = 0; i < n_basic_blocks; i++)
+ FOR_ALL_BB (bb)
{
- basic_block bb = BASIC_BLOCK (i);
if (maybe_hot_bb_p (bb))
{
cfun->function_frequency = FUNCTION_FREQUENCY_HOT;
OpenPOWER on IntegriCloud