GCC Middle and Back End API Reference
profile_probability Class Reference

#include <profile-count.h>

Public Member Functions

 profile_probability ()
 profile_probability (uint32_t val, profile_quality quality)
bool nonzero_p () const
bool initialized_p () const
bool reliable_p () const
profile_probability adjusted () const
int to_reg_br_prob_base () const
int to_reg_br_prob_note () const
bool operator== (const profile_probability &other) const
profile_probability operator+ (const profile_probability &other) const
profile_probabilityoperator+= (const profile_probability &other)
profile_probability operator- (const profile_probability &other) const
profile_probabilityoperator-= (const profile_probability &other)
profile_probability operator* (const profile_probability &other) const
profile_probabilityoperator*= (const profile_probability &other)
profile_probability operator/ (const profile_probability &other) const
profile_probabilityoperator/= (const profile_probability &other)
profile_probability split (const profile_probability &cprob)
gcov_type apply (gcov_type val) const
profile_probability invert () const
profile_probability guessed () const
profile_probability afdo () const
profile_probability apply_scale (int64_t num, int64_t den) const
profile_probability apply_scale (profile_probability num, profile_probability den) const
bool probably_reliable_p () const
bool verify () const
bool operator< (const profile_probability &other) const
bool operator> (const profile_probability &other) const
bool operator<= (const profile_probability &other) const
bool operator>= (const profile_probability &other) const
profile_probability operator* (int64_t num) const
profile_probability operator*= (int64_t num)
profile_probability operator/ (int64_t den) const
profile_probability operator/= (int64_t den)
profile_probability pow (int) const
profile_probability sqrt () const
uint32_t value () const
enum profile_quality quality () const
void dump (FILE *f) const
void dump (char *buffer) const
void debug () const
bool differs_from_p (profile_probability other) const
bool differs_lot_from_p (profile_probability other) const
profile_probability combine_with_count (profile_count count1, profile_probability other, profile_count count2) const
sreal to_sreal () const
void stream_out (struct output_block *)
void stream_out (struct lto_output_stream *)

Static Public Member Functions

static profile_probability never ()
static profile_probability guessed_never ()
static profile_probability very_unlikely ()
static profile_probability unlikely ()
static profile_probability even ()
static profile_probability very_likely ()
static profile_probability likely ()
static profile_probability guessed_always ()
static profile_probability always ()
static profile_probability uninitialized ()
static profile_probability from_reg_br_prob_base (int v)
static profile_probability from_reg_br_prob_note (int v)
static profile_probability probability_in_gcov_type (gcov_type val1, gcov_type val2)
static profile_probability stream_in (class lto_input_block *)

Private Member Functions

void set_quality (profile_quality quality)

Private Attributes

uint32_t m_val: 29
unsigned m_adjusted_quality: 3

Static Private Attributes

static const int n_bits = 29
static const uint32_t max_probability = (uint32_t) 1 << (n_bits - 2)
static const uint32_t uninitialized_probability = ((uint32_t) 1 << (n_bits - 1)) - 1
static const int min_quality = GUESSED

Friends

struct profile_count

Detailed Description

Data type to hold probabilities. It implements fixed point arithmetics with capping so probability is always in range [0,1] and scaling requiring values greater than 1 needs to be represented otherwise. In addition to actual value the quality of profile is tracked and propagated through all operations. Special value UNINITIALIZED_PROFILE is used for probabilities that has not been determined yet (for example because of -fno-guess-branch-probability) Typically probabilities are derived from profile feedback (via probability_in_gcov_type), autoFDO or guessed statically and then propagated thorough the compilation. Named probabilities are available: - never (0 probability) - guessed_never - very_unlikely (1/2000 probability) - unlikely (1/5 probability) - even (1/2 probability) - likely (4/5 probability) - very_likely (1999/2000 probability) - guessed_always - always Named probabilities except for never/always are assumed to be statically guessed and thus not necessarily accurate. The difference between never and guessed_never is that the first one should be used only in case that well behaving program will very likely not execute the "never" path. For example if the path is going to abort () call or it exception handling. Always and guessed_always probabilities are symmetric. For legacy code we support conversion to/from REG_BR_PROB_BASE based fixpoint integer arithmetics. Once the code is converted to branch probabilities, these conversions will probably go away because they are lossy.

Constructor & Destructor Documentation

◆ profile_probability() [1/2]

◆ profile_probability() [2/2]

profile_probability::profile_probability ( uint32_t val,
profile_quality quality )
inline

References m_val, quality(), and set_quality().

Member Function Documentation

◆ adjusted()

profile_probability profile_probability::adjusted ( ) const
inline

◆ afdo()

profile_probability profile_probability::afdo ( ) const
inline

◆ always()

profile_probability profile_probability::always ( )
inlinestatic

References m_val, max_probability, PRECISE, profile_probability(), and set_quality().

Referenced by autofdo::afdo_calculate_branch_prob(), profile_count::apply_probability(), rt_bb_visited::check(), check_bb_profile(), cleanup_empty_eh_move_lp(), combine_predictions_for_bb(), combine_predictions_for_insn(), compute_outgoing_frequencies(), copy_cfg_body(), determine_unlikely_bbs(), do_split_loop_on_cond(), duplicate_loop_body_to_header_edge(), back_jt_path_registry::duplicate_thread_path(), eliminate_tail_call(), tree_switch_conversion::bit_test_cluster::emit(), tree_switch_conversion::jump_table_cluster::emit(), estimate_bb_frequencies(), execute_sm_if_changed(), expand_omp_taskloop_for_inner(), expand_omp_taskloop_for_outer(), expand_thunk(), expand_transaction(), fold_loop_internal_call(), force_edge_cold(), force_nonfallthru_and_redirect(), tree_switch_conversion::switch_conversion::gen_inbound_check(), get_cond_branch_to_split_loop(), gimple_divmod_fixed_value(), gimple_ic(), gimple_mod_pow2(), gimple_mod_subtract(), gimple_stringop_fixed_value(), hoist_guard(), init_lowered_empty_function(), insert_check_and_trap(), rt_bb_visited::insert_exit_check_on_edge(), invert(), likely(), lower_resx(), make_single_succ_edge(), pow(), profile_count::probability_in(), purge_dead_edges(), remove_ctrl_stmt_and_useless_edges(), remove_dead_stmt(), remove_exits_and_undefined_stmts(), replace_phi_edge_with_variable(), scale_loop_profile(), scale_profile_for_vect_loop(), select_best_block(), set_edge_probability_and_rescale_others(), set_even_probabilities(), shrink_wrap_one_built_in_call_with_conds(), split(), split_edge(), split_loop(), sqrt(), tree_transform_and_unroll_loop(), try_redirect_by_replacing_jump(), try_unroll_loop_completely(), unroll_loop_runtime_iterations(), update_profile(), update_profile_after_ch(), update_profile_after_ifcombine(), vect_do_peeling(), vect_loop_versioning(), version_loop_for_if_conversion(), and very_likely().

◆ apply()

gcov_type profile_probability::apply ( gcov_type val) const
inline

◆ apply_scale() [1/2]

◆ apply_scale() [2/2]

◆ combine_with_count()

profile_probability profile_probability::combine_with_count ( profile_count count1,
profile_probability other,
profile_count count2 ) const
COUNT1 times event happens with *THIS probability, COUNT2 times OTHER happens with COUNT2 probability. Return probability that either *THIS or OTHER happens.

References even(), profile_count::nonzero_p(), profile_count::probability_in(), profile_count, profile_probability(), and profile_count::zero().

◆ debug()

void profile_probability::debug ( ) const
Dump THIS to stderr.

References dump().

◆ differs_from_p()

bool profile_probability::differs_from_p ( profile_probability other) const
Return true if THIS differs from OTHER; tolerate small differences.

References initialized_p(), m_val, max_probability, and profile_probability().

Referenced by check_bb_profile().

◆ differs_lot_from_p()

bool profile_probability::differs_lot_from_p ( profile_probability other) const
Return true if THIS differs significantly from OTHER.

References initialized_p(), m_val, max_probability, and profile_probability().

◆ dump() [1/2]

void profile_probability::dump ( char * buffer) const
Output THIS to BUFFER.

References ADJUSTED, AFDO, GUESSED, initialized_p(), m_val, max_probability, and quality().

◆ dump() [2/2]

◆ even()

◆ from_reg_br_prob_base()

◆ from_reg_br_prob_note()

◆ guessed()

◆ guessed_always()

◆ guessed_never()

◆ initialized_p()

◆ invert()

◆ likely()

◆ never()

◆ nonzero_p()

bool profile_probability::nonzero_p ( ) const
inline

References initialized_p(), and m_val.

Referenced by pow().

◆ operator*() [1/2]

profile_probability profile_probability::operator* ( const profile_probability & other) const
inline

◆ operator*() [2/2]

profile_probability profile_probability::operator* ( int64_t num) const
inline

◆ operator*=() [1/2]

◆ operator*=() [2/2]

profile_probability profile_probability::operator*= ( int64_t num)
inline

◆ operator+()

profile_probability profile_probability::operator+ ( const profile_probability & other) const
inline

◆ operator+=()

profile_probability & profile_probability::operator+= ( const profile_probability & other)
inline

◆ operator-()

profile_probability profile_probability::operator- ( const profile_probability & other) const
inline

◆ operator-=()

profile_probability & profile_probability::operator-= ( const profile_probability & other)
inline

◆ operator/() [1/2]

◆ operator/() [2/2]

profile_probability profile_probability::operator/ ( int64_t den) const
inline

◆ operator/=() [1/2]

◆ operator/=() [2/2]

profile_probability profile_probability::operator/= ( int64_t den)
inline

◆ operator<()

bool profile_probability::operator< ( const profile_probability & other) const
inline

◆ operator<=()

bool profile_probability::operator<= ( const profile_probability & other) const
inline

◆ operator==()

bool profile_probability::operator== ( const profile_probability & other) const
inline

◆ operator>()

bool profile_probability::operator> ( const profile_probability & other) const
inline

◆ operator>=()

bool profile_probability::operator>= ( const profile_probability & other) const
inline

◆ pow()

profile_probability profile_probability::pow ( int n) const
Compute n-th power of THIS.

References always(), initialized_p(), nonzero_p(), and profile_probability().

◆ probability_in_gcov_type()

◆ probably_reliable_p()

bool profile_probability::probably_reliable_p ( ) const
inline

◆ quality()

◆ reliable_p()

bool profile_probability::reliable_p ( ) const
inline

References ADJUSTED, and quality().

Referenced by get_cond_branch_to_split_loop().

◆ set_quality()

◆ split()

profile_probability profile_probability::split ( const profile_probability & cprob)
inline

◆ sqrt()

profile_probability profile_probability::sqrt ( ) const

◆ stream_in()

profile_probability profile_probability::stream_in ( class lto_input_block * ib)
static
Stream THIS from IB.

References m_adjusted_quality, m_val, profile_probability(), and streamer_read_uhwi().

Referenced by input_cfg().

◆ stream_out() [1/2]

void profile_probability::stream_out ( struct lto_output_stream * ob)
Stream THIS to OB.

References m_adjusted_quality, m_val, and streamer_write_uhwi_stream().

◆ stream_out() [2/2]

void profile_probability::stream_out ( struct output_block * ob)
Stream THIS to OB.

References m_adjusted_quality, m_val, and streamer_write_uhwi().

◆ to_reg_br_prob_base()

◆ to_reg_br_prob_note()

int profile_probability::to_reg_br_prob_note ( ) const
inline

◆ to_sreal()

sreal profile_probability::to_sreal ( ) const
Return probability as sreal in range [0, 1].

References gcc_checking_assert, initialized_p(), m_val, and n_bits.

Referenced by split_loop().

◆ uninitialized()

◆ unlikely()

◆ value()

uint32_t profile_probability::value ( ) const
inline

References m_val.

◆ verify()

bool profile_probability::verify ( ) const
inline

◆ very_likely()

◆ very_unlikely()

◆ profile_count

friend struct profile_count
friend

References profile_count.

Referenced by combine_with_count(), and profile_count.

Field Documentation

◆ m_adjusted_quality

unsigned profile_probability::m_adjusted_quality
private

◆ m_val

◆ max_probability

◆ min_quality

const int profile_probability::min_quality = GUESSED
staticprivate

Referenced by quality(), and set_quality().

◆ n_bits

const int profile_probability::n_bits = 29
staticprivate

Referenced by to_sreal().

◆ uninitialized_probability

const uint32_t profile_probability::uninitialized_probability = ((uint32_t) 1 << (n_bits - 1)) - 1
staticprivate

The documentation for this class was generated from the following files: