-/* Statically estimate the probability that a branch will be taken and produce
- estimated profile. When profile feedback is present never executed portions
- of function gets estimated. */
-
-void
-estimate_probability (struct loops *loops_info)
-{
- basic_block bb;
-
- connect_infinite_loops_to_exit ();
- calculate_dominance_info (CDI_DOMINATORS);
- calculate_dominance_info (CDI_POST_DOMINATORS);
-
- predict_loops (loops_info, true);
-
- iv_analysis_done ();
-
- /* Attempt to predict conditional jumps using a number of heuristics. */
- FOR_EACH_BB (bb)
- {
- rtx last_insn = BB_END (bb);
- edge e;
- edge_iterator ei;
-
- if (! can_predict_insn_p (last_insn))
- continue;
-
- FOR_EACH_EDGE (e, ei, bb->succs)
- {
- /* Predict early returns to be probable, as we've already taken
- care for error returns and other are often used for fast paths
- trought function. */
- if ((e->dest == EXIT_BLOCK_PTR
- || (single_succ_p (e->dest)
- && single_succ (e->dest) == EXIT_BLOCK_PTR))
- && !predicted_by_p (bb, PRED_NULL_RETURN)
- && !predicted_by_p (bb, PRED_CONST_RETURN)
- && !predicted_by_p (bb, PRED_NEGATIVE_RETURN)
- && !last_basic_block_p (e->dest))
- predict_edge_def (e, PRED_EARLY_RETURN, TAKEN);
-
- /* Look for block we are guarding (i.e. we dominate it,
- but it doesn't postdominate us). */
- if (e->dest != EXIT_BLOCK_PTR && e->dest != bb
- && dominated_by_p (CDI_DOMINATORS, e->dest, e->src)
- && !dominated_by_p (CDI_POST_DOMINATORS, e->src, e->dest))
- {
- rtx insn;
-
- /* The call heuristic claims that a guarded function call
- is improbable. This is because such calls are often used
- to signal exceptional situations such as printing error
- messages. */
- for (insn = BB_HEAD (e->dest); insn != NEXT_INSN (BB_END (e->dest));
- insn = NEXT_INSN (insn))
- if (CALL_P (insn)
- /* Constant and pure calls are hardly used to signalize
- something exceptional. */
- && ! CONST_OR_PURE_CALL_P (insn))
- {
- predict_edge_def (e, PRED_CALL, NOT_TAKEN);
- break;
- }
- }
- }
- bb_estimate_probability_locally (bb);
- }
-
- /* Attach the combined probability to each conditional jump. */
- FOR_EACH_BB (bb)
- combine_predictions_for_insn (BB_END (bb), bb);
-
- remove_fake_edges ();
- estimate_bb_frequencies (loops_info);
- free_dominance_info (CDI_POST_DOMINATORS);
- if (profile_status == PROFILE_ABSENT)
- profile_status = PROFILE_GUESSED;
-}
-