diff options
author | hubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-11-21 11:47:02 +0000 |
---|---|---|
committer | hubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-11-21 11:47:02 +0000 |
commit | ad73c2a0106c6ce360cb0fde9bf5feb27b941a65 (patch) | |
tree | b19b0cb46992c15fd662305fdbc553515cd42c12 /gcc/profile.c | |
parent | 0ba5f96cc686f4da46b64194e6b4a263db930cb5 (diff) | |
download | ppe42-gcc-ad73c2a0106c6ce360cb0fde9bf5feb27b941a65.tar.gz ppe42-gcc-ad73c2a0106c6ce360cb0fde9bf5feb27b941a65.zip |
* profile.c (compute_branch_probabilites): Compute probabilities
for entry/exit edges; estimate probabilities for zero counts.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@47242 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/profile.c')
-rw-r--r-- | gcc/profile.c | 72 |
1 files changed, 47 insertions, 25 deletions
diff --git a/gcc/profile.c b/gcc/profile.c index 57a1c72be38..1aea55969bd 100644 --- a/gcc/profile.c +++ b/gcc/profile.c @@ -411,38 +411,32 @@ compute_branch_probabilities () num_never_executed = 0; num_branches = 0; - for (i = 0; i < n_basic_blocks; i++) + for (i = 0; i <= n_basic_blocks + 1; i++) { - basic_block bb = BASIC_BLOCK (i); + basic_block bb = GCOV_INDEX_TO_BB (i); edge e; gcov_type total; rtx note; total = bb->count; if (total) - for (e = bb->succ; e; e = e->succ_next) - { - e->probability = (e->count * REG_BR_PROB_BASE + total / 2) / total; - if (e->probability < 0 || e->probability > REG_BR_PROB_BASE) - { - error ("Corrupted profile info: prob for %d-%d thought to be %d", - e->src->index, e->dest->index, e->probability); - e->probability = REG_BR_PROB_BASE / 2; - } - } - if (any_condjump_p (bb->end) - && bb->succ->succ_next) { - int prob; - edge e; - - if (total == 0) - prob = -1; - else - if (total == -1) - num_never_executed++; - else + for (e = bb->succ; e; e = e->succ_next) { + e->probability = (e->count * REG_BR_PROB_BASE + total / 2) / total; + if (e->probability < 0 || e->probability > REG_BR_PROB_BASE) + { + error ("Corrupted profile info: prob for %d-%d thought to be %d", + e->src->index, e->dest->index, e->probability); + e->probability = REG_BR_PROB_BASE / 2; + } + } + if (bb->index >= 0 + && any_condjump_p (bb->end) + && bb->succ->succ_next) + { + int prob; + edge e; int index; /* Find the branch edge. It is possible that we do have fake @@ -467,9 +461,37 @@ compute_branch_probabilities () REG_NOTES (bb->end) = gen_rtx_EXPR_LIST (REG_BR_PROB, GEN_INT (prob), REG_NOTES (bb->end)); + num_branches++; } - num_branches++; - + } + /* Otherwise distribute the probabilities evenly so we get sane sum. + Use simple heuristics that if there are normal edges, give all abnormals + frequency of 0, otherwise distribute the frequency over abnormals + (this is the case of noreturn calls). */ + else + { + for (e = bb->succ; e; e = e->succ_next) + if (!(e->flags & (EDGE_COMPLEX | EDGE_FAKE))) + total ++; + if (total) + { + for (e = bb->succ; e; e = e->succ_next) + if (!(e->flags & (EDGE_COMPLEX | EDGE_FAKE))) + e->probability = REG_BR_PROB_BASE / total; + else + e->probability = 0; + } + else + { + for (e = bb->succ; e; e = e->succ_next) + total ++; + for (e = bb->succ; e; e = e->succ_next) + e->probability = REG_BR_PROB_BASE / total; + } + if (bb->index >= 0 + && any_condjump_p (bb->end) + && bb->succ->succ_next) + num_branches++, num_never_executed; } } |