GCC Middle and Back End API Reference
predict.h File Reference
#include "profile-count.h"
#include "predict.def"
Include dependency graph for predict.h:

Go to the source code of this file.

Macros

#define PROB_VERY_UNLIKELY   (REG_BR_PROB_BASE / 2000 - 1)
 
#define PROB_EVEN   (REG_BR_PROB_BASE / 2)
 
#define PROB_VERY_LIKELY   (REG_BR_PROB_BASE - PROB_VERY_UNLIKELY)
 
#define PROB_ALWAYS   (REG_BR_PROB_BASE)
 
#define PROB_UNLIKELY   (REG_BR_PROB_BASE / 5 - 1)
 
#define PROB_LIKELY   (REG_BR_PROB_BASE - PROB_UNLIKELY)
 
#define PROB_UNINITIALIZED   (-1)
 
#define DEF_PREDICTOR(ENUM, NAME, HITRATE, FLAGS)   ENUM,
 

Enumerations

enum  br_predictor { END_PREDICTORS }
 
enum  prediction { NOT_TAKEN , TAKEN }
 

Functions

gcov_type get_hot_bb_threshold (void)
 
void set_hot_bb_threshold (gcov_type)
 
bool maybe_hot_count_p (struct function *, profile_count)
 
bool maybe_hot_bb_p (struct function *, const_basic_block)
 
bool maybe_hot_edge_p (edge)
 
bool probably_never_executed_bb_p (struct function *, const_basic_block)
 
bool probably_never_executed_edge_p (struct function *, edge)
 
enum optimize_size_level optimize_function_for_size_p (struct function *)
 
bool optimize_function_for_speed_p (struct function *)
 
optimization_type function_optimization_type (struct function *)
 
enum optimize_size_level optimize_bb_for_size_p (const_basic_block)
 
bool optimize_bb_for_speed_p (const_basic_block)
 
optimization_type bb_optimization_type (const_basic_block)
 
enum optimize_size_level optimize_edge_for_size_p (edge)
 
bool optimize_edge_for_speed_p (edge)
 
enum optimize_size_level optimize_insn_for_size_p (void)
 
bool optimize_insn_for_speed_p (void)
 
optimization_type insn_optimization_type ()
 
enum optimize_size_level optimize_loop_for_size_p (class loop *)
 
bool optimize_loop_for_speed_p (class loop *)
 
bool optimize_loop_nest_for_speed_p (class loop *)
 
enum optimize_size_level optimize_loop_nest_for_size_p (class loop *)
 
bool predictable_edge_p (edge)
 
void rtl_profile_for_bb (basic_block)
 
void rtl_profile_for_edge (edge)
 
void default_rtl_profile (void)
 
bool rtl_predicted_by_p (const_basic_block, enum br_predictor)
 
bool gimple_predicted_by_p (const_basic_block, enum br_predictor)
 
bool edge_probability_reliable_p (const_edge)
 
bool br_prob_note_reliable_p (const_rtx)
 
void predict_insn_def (rtx_insn *, enum br_predictor, enum prediction)
 
void rtl_predict_edge (edge, enum br_predictor, int)
 
void gimple_predict_edge (edge, enum br_predictor, int)
 
void remove_predictions_associated_with_edge (edge)
 
void predict_edge_def (edge, enum br_predictor, enum prediction)
 
void invert_br_probabilities (rtx)
 
void guess_outgoing_edge_probabilities (basic_block)
 
void tree_guess_outgoing_edge_probabilities (basic_block)
 
void tree_estimate_probability (bool)
 
void handle_missing_profiles (void)
 
bool update_max_bb_count (void)
 
bool expensive_function_p (int)
 
void compute_function_frequency (void)
 
tree build_predict_expr (enum br_predictor, enum prediction)
 
const char * predictor_name (enum br_predictor)
 
void rebuild_frequencies (void)
 
void report_predictor_hitrates (void)
 
void force_edge_cold (edge, bool)
 
void propagate_unlikely_bbs_forward (void)
 
void add_reg_br_prob_note (rtx_insn *, profile_probability)
 
void warn_function_cold (tree)
 

Variables

profile_probability split_branch_probability
 

Macro Definition Documentation

◆ DEF_PREDICTOR

#define DEF_PREDICTOR ( ENUM,
NAME,
HITRATE,
FLAGS )   ENUM,

◆ PROB_ALWAYS

#define PROB_ALWAYS   (REG_BR_PROB_BASE)

Referenced by expr_expected_value_1().

◆ PROB_EVEN

#define PROB_EVEN   (REG_BR_PROB_BASE / 2)

◆ PROB_LIKELY

#define PROB_LIKELY   (REG_BR_PROB_BASE - PROB_UNLIKELY)

◆ PROB_UNINITIALIZED

#define PROB_UNINITIALIZED   (-1)

Referenced by predict_insn_def().

◆ PROB_UNLIKELY

#define PROB_UNLIKELY   (REG_BR_PROB_BASE / 5 - 1)

◆ PROB_VERY_LIKELY

#define PROB_VERY_LIKELY   (REG_BR_PROB_BASE - PROB_VERY_UNLIKELY)

◆ PROB_VERY_UNLIKELY

#define PROB_VERY_UNLIKELY   (REG_BR_PROB_BASE / 2000 - 1)
Definitions for branch prediction routines in the GNU compiler.
   Copyright (C) 2001-2024 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.   
Random guesstimation given names.
PROB_VERY_UNLIKELY should be small enough so basic block predicted
by it gets below HOT_BB_FREQUENCY_FRACTION.   

Referenced by combine_predictions_for_bb().

Enumeration Type Documentation

◆ br_predictor

Enumerator
END_PREDICTORS 

◆ prediction

enum prediction
Enumerator
NOT_TAKEN 
TAKEN 

Function Documentation

◆ add_reg_br_prob_note()

◆ bb_optimization_type()

optimization_type bb_optimization_type ( const_basic_block bb)
extern
Return the optimization type that should be used for basic block BB.   

References optimize_bb_for_speed_p(), OPTIMIZE_FOR_SIZE, and OPTIMIZE_FOR_SPEED.

Referenced by convert_mult_to_fma(), reassociate_bb(), and replacement_internal_fn().

◆ br_prob_note_reliable_p()

bool br_prob_note_reliable_p ( const_rtx note)
extern
Same predicate as edge_probability_reliable_p, working on notes.   

References profile_probability::from_reg_br_prob_note(), gcc_assert, profile_probability::probably_reliable_p(), REG_NOTE_KIND, and XINT.

◆ build_predict_expr()

tree build_predict_expr ( enum br_predictor predictor,
enum prediction taken )
extern

◆ compute_function_frequency()

◆ default_rtl_profile()

void default_rtl_profile ( void )
extern

◆ edge_probability_reliable_p()

bool edge_probability_reliable_p ( const_edge e)
extern
Same predicate as above, working on edges.   

◆ expensive_function_p()

bool expensive_function_p ( int threshold)
extern
Return true if function is likely to be expensive, so there is no point to
optimize performance of prologue, epilogue or do inlining at the expense
of code size growth.  THRESHOLD is the limit of number of instructions
function can execute at average to be still considered not expensive.   

References active_insn_p(), cfun, basic_block_def::count, count, dump_file, ENTRY_BLOCK_PTR_FOR_FN, FOR_BB_INSNS, FOR_EACH_BB_FN, basic_block_def::index, profile_count::initialized_p(), and profile_count::zero().

◆ force_edge_cold()

void force_edge_cold ( edge e,
bool impossible )
extern
Force edge E to be cold.
If IMPOSSIBLE is true, for edge to have count and probability 0 otherwise
keep low probability to represent possible error in a guess.  This is used
i.e. in case we predict loop to likely iterate given number of times but
we are not 100% sure.

This function locally updates profile without attempt to keep global
consistency which cannot be reached in full generality without full profile
rebuild from probabilities alone.  Doing so is not necessarily a good idea
because frequencies and counts may be more realistic then probabilities.

In some cases (such as for elimination of early exits during full loop
unrolling) the caller can ensure that profile will get consistent
afterwards.   

References profile_probability::always(), cfun, current_ir_type(), profile_probability::dump(), dump_file, dump_flags, ENTRY_BLOCK_PTR_FOR_FN, FOR_EACH_EDGE, force_edge_cold(), gsi_end_p(), gsi_next(), gsi_start_bb(), gsi_stmt(), IR_GIMPLE, maybe_hot_bb_p(), MIN, profile_probability::never(), set_edge_probability_and_rescale_others(), single_pred_edge(), single_pred_p(), stmt_can_terminate_bb_p(), TDF_DETAILS, profile_count::to_frequency(), update_br_prob_note(), profile_probability::very_unlikely(), and profile_count::zero().

Referenced by duplicate_loop_body_to_header_edge(), force_edge_cold(), isolate_path(), and try_unroll_loop_completely().

◆ function_optimization_type()

optimization_type function_optimization_type ( struct function * fun)
extern
Return the optimization type that should be used for function FUN.   

References OPTIMIZE_FOR_SIZE, OPTIMIZE_FOR_SPEED, and optimize_function_for_speed_p().

◆ get_hot_bb_threshold()

gcov_type get_hot_bb_threshold ( void )
extern

◆ gimple_predict_edge()

void gimple_predict_edge ( edge e,
enum br_predictor predictor,
int probability )
extern
Predict edge E with the given PROBABILITY.   

References bb_predictions, cfun, EDGE_COUNT, ENTRY_BLOCK_PTR_FOR_FN, edge_prediction::ep_next, edge_prediction::ep_probability, and i.

◆ gimple_predicted_by_p()

bool gimple_predicted_by_p ( const_basic_block bb,
enum br_predictor predictor )
extern
Return true if the one of outgoing edges is already predicted by
PREDICTOR.   

References bb_predictions, edge_prediction::ep_next, and i.

◆ guess_outgoing_edge_probabilities()

void guess_outgoing_edge_probabilities ( basic_block bb)
extern
Set edge->probability for each successor edge of BB.   

References BB_END, bb_estimate_probability_locally(), and combine_predictions_for_insn().

Referenced by compute_outgoing_frequencies().

◆ handle_missing_profiles()

void handle_missing_profiles ( void )
extern
In the case of COMDAT routines, multiple object files will contain the same
function and the linker will select one for the binary. In that case
all the other copies from the profile instrument binary will be missing
profile counts. Look for cases where this happened, due to non-zero
call counts going to 0-count functions, and drop the profile to guessed
so that we can use the estimated probabilities and avoid optimizing only
for size.

The other case where the profile may be missing is when the routine
is not going to be emitted to the object file, e.g. for "extern template"
class methods. Those will be marked DECL_EXTERNAL. Emit a warning in
all other cases of non-zero calls to 0-count functions.   

References cgraph_edge::callee, cgraph_node::callees, cgraph_edge::caller, cgraph_node::callers, function::cfg, cgraph_edge::count, cgraph_node::count, symtab_node::decl, DECL_COMDAT, DECL_EXTERNAL, DECL_STRUCT_FUNCTION, drop_profile(), FOR_EACH_DEFINED_FUNCTION, profile_count::initialized_p(), profile_count::ipa(), cgraph_edge::next_caller, profile_count::nonzero_p(), profile_info, PROFILE_READ, profile_status_for_fn, gcov_summary::runs, cgraph_node::tp_first_run, worklist, and profile_count::zero().

Referenced by tree_profiling().

◆ insn_optimization_type()

optimization_type insn_optimization_type ( )
extern
Return the optimization type that should be used for the current
instruction.   

References OPTIMIZE_FOR_SIZE, OPTIMIZE_FOR_SPEED, and optimize_insn_for_speed_p().

Referenced by expand_sfix_optab().

◆ invert_br_probabilities()

void invert_br_probabilities ( rtx insn)
extern
Invert all branch predictions or probability notes in the INSN.  This needs
to be done each time we invert the condition used by the jump.   

References profile_probability::from_reg_br_prob_note(), GEN_INT, INTVAL, profile_probability::invert(), REG_BR_PROB_BASE, REG_NOTE_KIND, REG_NOTES, profile_probability::to_reg_br_prob_note(), XEXP, and XINT.

Referenced by redirect_jump_2().

◆ maybe_hot_bb_p()

bool maybe_hot_bb_p ( struct function * fun,
const_basic_block bb )
extern
Return true if basic block BB of function FUN can be CPU intensive
and should thus be optimized for maximum performance.   

References basic_block_def::count, gcc_checking_assert, and maybe_hot_count_p().

Referenced by compute_function_frequency(), dump_bb_info(), force_edge_cold(), optimize_bb_for_size_p(), and rtl_profile_for_bb().

◆ maybe_hot_count_p()

◆ maybe_hot_edge_p()

bool maybe_hot_edge_p ( edge e)
extern
Return true if edge E can be CPU intensive and should thus be optimized
for maximum performance.   

References cfun, and maybe_hot_count_p().

Referenced by optimize_edge_for_size_p(), and rtl_profile_for_edge().

◆ optimize_bb_for_size_p()

◆ optimize_bb_for_speed_p()

◆ optimize_edge_for_size_p()

enum optimize_size_level optimize_edge_for_size_p ( edge e)
extern

◆ optimize_edge_for_speed_p()

bool optimize_edge_for_speed_p ( edge e)
extern

◆ optimize_function_for_size_p()

◆ optimize_function_for_speed_p()

◆ optimize_insn_for_size_p()

enum optimize_size_level optimize_insn_for_size_p ( void )
extern

◆ optimize_insn_for_speed_p()

◆ optimize_loop_for_size_p()

enum optimize_size_level optimize_loop_for_size_p ( class loop * loop)
extern
Return TRUE if LOOP should be optimized for size.   

References loop::header, and optimize_bb_for_size_p().

Referenced by decide_unrolling(), optimize_loop_nest_for_size_p(), tree_ssa_split_loops(), and tree_ssa_unswitch_loops().

◆ optimize_loop_for_speed_p()

◆ optimize_loop_nest_for_size_p()

enum optimize_size_level optimize_loop_nest_for_size_p ( class loop * loop)
extern
Return TRUE if nest rooted at LOOP should be optimized for size.   

References loop::inner, loop_outer(), MIN, loop::next, optimize_loop_for_size_p(), and OPTIMIZE_SIZE_NO.

Referenced by loop_prefetch_arrays(), parallelize_loops(), and tree_loop_unroll_and_jam().

◆ optimize_loop_nest_for_speed_p()

bool optimize_loop_nest_for_speed_p ( class loop * loop)
extern

◆ predict_edge_def()

void predict_edge_def ( edge e,
enum br_predictor predictor,
enum prediction taken )
extern
Predict edge E by given predictor if possible.   

References predict_edge(), REG_BR_PROB_BASE, and TAKEN.

Referenced by maybe_predict_edge(), predict_iv_comparison(), tree_estimate_probability_bb(), and tree_predict_by_opcode().

◆ predict_insn_def()

void predict_insn_def ( rtx_insn * insn,
enum br_predictor predictor,
enum prediction taken )
extern

◆ predictable_edge_p()

bool predictable_edge_p ( edge e)
extern
Return true if edge E is likely to be well predictable by branch
predictor.   

References REG_BR_PROB_BASE.

Referenced by default_max_noce_ifcvt_seq_cost(), find_if_case_1(), and find_if_case_2().

◆ predictor_name()

const char * predictor_name ( enum br_predictor)
extern

◆ probably_never_executed_bb_p()

bool probably_never_executed_bb_p ( struct function * fun,
const_basic_block bb )
extern

◆ probably_never_executed_edge_p()

bool probably_never_executed_edge_p ( struct function * fun,
edge e )
extern

◆ propagate_unlikely_bbs_forward()

void propagate_unlikely_bbs_forward ( void )
extern

◆ rebuild_frequencies()

void rebuild_frequencies ( void )
extern
Rebuild function frequencies.  Passes are in general expected to
maintain profile by hand, however in some cases this is not possible:
for example when inlining several functions with loops freuqencies might run
out of scale and thus needs to be recomputed.   

References cfun, connect_infinite_loops_to_exit(), basic_block_def::count, count, profile_count::differs_from_p(), dump_file, ENTRY_BLOCK_PTR_FOR_FN, estimate_bb_frequencies(), FOR_BB_BETWEEN, FOR_EACH_EDGE, basic_block_def::index, profile_count::initialized_p(), loop_optimizer_finalize(), loop_optimizer_init(), LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS, NULL, basic_block_def::preds, PROFILE_ABSENT, profile_status_for_fn, remove_fake_exit_edges(), profile_count::uninitialized(), and profile_count::zero().

Referenced by tree_function_versioning().

◆ remove_predictions_associated_with_edge()

void remove_predictions_associated_with_edge ( edge e)
extern
Remove all predictions on given basic block that are attached
to edge E.   

References bb_predictions, filter_predictions(), and not_equal_edge_p().

Referenced by remove_edge_raw().

◆ report_predictor_hitrates()

void report_predictor_hitrates ( void )
extern
Perform a dry run of the branch prediction pass and report comparsion of
the predicted and real profile into the dump file.   

References cfun, dump_file, dump_flags, flow_loops_dump(), loop_optimizer_finalize(), loop_optimizer_init(), LOOPS_NORMAL, NULL, number_of_loops(), scev_finalize(), scev_initialize(), TDF_DETAILS, and tree_estimate_probability().

Referenced by branch_prob().

◆ rtl_predict_edge()

void rtl_predict_edge ( edge e,
enum br_predictor predictor,
int probability )
extern
Predict edge E with given probability if possible.   

References any_condjump_p(), BB_END, predict_insn(), and REG_BR_PROB_BASE.

◆ rtl_predicted_by_p()

bool rtl_predicted_by_p ( const_basic_block bb,
enum br_predictor predictor )
extern
Return true if the one of outgoing edges is already predicted by
PREDICTOR.   

References BB_END, INSN_P, INTVAL, REG_NOTE_KIND, REG_NOTES, and XEXP.

◆ rtl_profile_for_bb()

◆ rtl_profile_for_edge()

void rtl_profile_for_edge ( edge e)
extern
Set RTL expansion for edge profile.   

References crtl, and maybe_hot_edge_p().

◆ set_hot_bb_threshold()

void set_hot_bb_threshold ( gcov_type min)
extern
Set the threshold for hot BB counts.   

References min_count.

Referenced by get_hot_bb_threshold(), input_profile_summary(), and ipa_profile().

◆ tree_estimate_probability()

void tree_estimate_probability ( bool dry_run)
extern

◆ tree_guess_outgoing_edge_probabilities()

void tree_guess_outgoing_edge_probabilities ( basic_block bb)
extern
Set edge->probability for each successor edge of BB.   

References assert_is_empty(), bb_predictions, combine_predictions_for_bb(), NULL, and tree_estimate_probability_bb().

Referenced by gimple_find_sub_bbs().

◆ update_max_bb_count()

◆ warn_function_cold()

void warn_function_cold ( tree decl)
extern
In ipa-pure-const.cc    

References suggest_attribute().

Referenced by compute_function_frequency().

Variable Documentation

◆ split_branch_probability

profile_probability split_branch_probability
extern
In emit-rtl.cc.   
Probability of the conditional branch currently proceeded by try_split.   

Referenced by init_emit_regs(), and try_split().