GCC Middle and Back End API Reference
profile_count Struct Reference

#include <profile-count.h>

Public Member Functions

bool compatible_p (const profile_count other) const
 
gcov_type to_gcov_type () const
 
bool initialized_p () const
 
bool reliable_p () const
 
bool ipa_p () const
 
bool precise_p () const
 
uint64_t value () const
 
enum profile_quality quality () const
 
bool ok_for_merging (profile_count other) const
 
profile_count merge (profile_count other) const
 
bool operator== (const profile_count &other) const
 
profile_count operator+ (const profile_count &other) const
 
profile_countoperator+= (const profile_count &other)
 
profile_count operator- (const profile_count &other) const
 
profile_countoperator-= (const profile_count &other)
 
bool verify () const
 
bool operator< (const profile_count &other) const
 
bool operator> (const profile_count &other) const
 
bool operator< (const gcov_type other) const
 
bool operator> (const gcov_type other) const
 
bool operator<= (const profile_count &other) const
 
bool operator>= (const profile_count &other) const
 
bool operator<= (const gcov_type other) const
 
bool operator>= (const gcov_type other) const
 
profile_count operator* (int64_t num) const
 
profile_count operator*= (int64_t num)
 
profile_count operator/ (int64_t den) const
 
profile_count operator/= (int64_t den)
 
bool nonzero_p () const
 
profile_count force_nonzero () const
 
profile_count max (profile_count other) const
 
profile_count apply_probability (int prob) const
 
profile_count apply_probability (profile_probability prob) const
 
profile_count apply_scale (int64_t num, int64_t den) const
 
profile_count apply_scale (profile_count num, profile_count den) const
 
profile_count guessed_local () const
 
profile_count global0 () const
 
profile_count global0adjusted () const
 
profile_count guessed () const
 
profile_count ipa () const
 
profile_count afdo () const
 
profile_probability probability_in (const profile_count overall) const
 
bool very_large_p ()
 
int to_frequency (struct function *fun) const
 
int to_cgraph_frequency (profile_count entry_bb_count) const
 
sreal to_sreal_scale (profile_count in, bool *known=NULL) const
 
void dump (FILE *f, struct function *fun=NULL) const
 
void debug () const
 
bool differs_from_p (profile_count other) const
 
profile_count combine_with_ipa_count (profile_count ipa)
 
profile_count combine_with_ipa_count_within (profile_count ipa, profile_count ipa2)
 
void stream_out (struct output_block *)
 
void stream_out (struct lto_output_stream *)
 

Static Public Member Functions

static profile_count zero ()
 
static profile_count adjusted_zero ()
 
static profile_count guessed_zero ()
 
static profile_count one ()
 
static profile_count uninitialized ()
 
static void adjust_for_ipa_scaling (profile_count *num, profile_count *den)
 
static profile_count from_gcov_type (gcov_type v, profile_quality quality=PRECISE)
 
static profile_count stream_in (class lto_input_block *)
 

Static Public Attributes

static const int n_bits = 61
 
static const uint64_t max_count = ((uint64_t) 1 << n_bits) - 2
 

Private Attributes

uint64_t UINT64_BIT_FIELD_ALIGN m_val: n_bits
 
enum profile_quality m_quality: 3
 

Static Private Attributes

static const uint64_t uninitialized_count = ((uint64_t) 1 << n_bits) - 1
 

Detailed Description

Main data type to hold profile counters in GCC. Profile counts originate
 either from profile feedback, static profile estimation or both.  We do not
 perform whole program profile propagation and thus profile estimation
 counters are often local to function, while counters from profile feedback
 (or special cases of profile estimation) can be used inter-procedurally.

 There are 3 basic types
   1) local counters which are result of intra-procedural static profile
      estimation.
   2) ipa counters which are result of profile feedback or special case
      of static profile estimation (such as in function main).
   3) counters which counts as 0 inter-procedurally (because given function
      was never run in train feedback) but they hold local static profile
      estimate.

 Counters of type 1 and 3 cannot be mixed with counters of different type
 within operation (because whole function should use one type of counter)
 with exception that global zero mix in most operations where outcome is
 well defined.

 To take local counter and use it inter-procedurally use ipa member function
 which strips information irrelevant at the inter-procedural level.

 Counters are 61bit integers representing number of executions during the
 train run or normalized frequency within the function.

 As the profile is maintained during the compilation, many adjustments are
 made.  Not all transformations can be made precisely, most importantly
 when code is being duplicated.  It also may happen that part of CFG has
 profile counts known while other do not - for example when LTO optimizing
 partly profiled program or when profile was lost due to COMDAT merging.

 For this reason profile_count tracks more information than
 just unsigned integer and it is also ready for profile mismatches.
 The API of this data type represent operations that are natural
 on profile counts - sum, difference and operation with scales and
 probabilities.  All operations are safe by never getting negative counts
 and they do end up in uninitialized scale if any of the parameters is
 uninitialized.

 All comparisons that are three state and handling of probabilities.  Thus
 a < b is not equal to !(a >= b).

 The following pre-defined counts are available:

 profile_count::zero ()  for code that is known to execute zero times at
    runtime (this can be detected statically i.e. for paths leading to
    abort ();
 profile_count::one () for code that is known to execute once (such as
    main () function
 profile_count::uninitialized ()  for unknown execution count.

Member Function Documentation

◆ adjust_for_ipa_scaling()

void profile_count::adjust_for_ipa_scaling ( profile_count * num,
profile_count * den )
static
We want to scale profile across function boundary from NUM to DEN.
Take care of the side case when DEN is zeros.  We still want to behave
sanely here which means
  - scale to profile_count::zero () if NUM is profile_count::zero
  - do not affect anything if NUM == DEN
  - preserve counter value but adjust quality in other cases.   

References force_nonzero(), ggc_alloc(), and zero().

Referenced by cgraph_edge::clone(), copy_bb(), copy_cfg_body(), execute_fixup_cfg(), initialize_cfun(), inline_transform(), scale_ipa_profile_for_fn(), update_counts_for_self_gen_clones(), update_noncloned_counts(), and update_profiling_info().

◆ adjusted_zero()

static profile_count profile_count::adjusted_zero ( )
inlinestatic

References ADJUSTED, m_quality, and m_val.

Referenced by ipa(), and update_profiling_info().

◆ afdo()

◆ apply_probability() [1/2]

◆ apply_probability() [2/2]

◆ apply_scale() [1/2]

◆ apply_scale() [2/2]

◆ combine_with_ipa_count()

profile_count profile_count::combine_with_ipa_count ( profile_count ipa)
THIS is a count of bb which is known to be executed IPA times.
Combine this information into bb counter.  This means returning IPA
if it is nonzero, not changing anything if IPA is uninitialized
and if IPA is zero, turning THIS into corresponding local profile with
global0.   

References global0(), global0adjusted(), initialized_p(), ipa(), nonzero_p(), and zero().

Referenced by combine_with_ipa_count_within(), cgraph_node::create_clone(), and estimate_bb_frequencies().

◆ combine_with_ipa_count_within()

profile_count profile_count::combine_with_ipa_count_within ( profile_count ipa,
profile_count ipa2 )
Sae as profile_count::combine_with_ipa_count but within function with count
IPA2.   

References combine_with_ipa_count(), gcc_checking_assert, ggc_alloc(), initialized_p(), and ipa().

Referenced by cgraph_edge::clone(), and cgraph_node::create_clone().

◆ compatible_p()

◆ debug()

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

References cfun, dump(), and ggc_alloc().

Referenced by cgraph_node::verify_node().

◆ differs_from_p()

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

References compatible_p(), gcc_checking_assert, ggc_alloc(), initialized_p(), m_val, and safe_scale_64bit().

Referenced by cgraph_node::dump(), and cgraph_node::verify_node().

◆ dump()

◆ force_nonzero()

profile_count profile_count::force_nonzero ( ) const
inline

◆ from_gcov_type()

profile_count profile_count::from_gcov_type ( gcov_type v,
profile_quality quality = PRECISE )
static

◆ global0()

profile_count profile_count::global0 ( ) const
inline

◆ global0adjusted()

profile_count profile_count::global0adjusted ( ) const
inline

◆ guessed()

profile_count profile_count::guessed ( ) const
inline

References ggc_alloc(), GUESSED, and MIN.

Referenced by update_bb_profile_for_threading().

◆ guessed_local()

◆ guessed_zero()

static profile_count profile_count::guessed_zero ( )
inlinestatic

References GUESSED, m_quality, and m_val.

Referenced by compute_branch_probabilities().

◆ initialized_p()

bool profile_count::initialized_p ( ) const
inline

References m_val, and uninitialized_count.

Referenced by apply_probability(), apply_probability(), apply_scale(), apply_scale(), combine_with_ipa_count(), combine_with_ipa_count_within(), compatible_p(), differs_from_p(), cgraph_node::dump(), dump(), dump_basic_block_info(), dump_bb_for_graph(), dump_bb_info(), cgraph_edge::dump_edge_flags(), dump_function_to_file(), dump_gimple_bb_header(), dump_inline_stats(), dump_overall_stats(), dump_prediction(), edge_badness(), execute_fixup_cfg(), expensive_function_p(), expr_expected_value_1(), find_best_predecessor(), force_nonzero(), gather_caller_stats(), get_info_about_necessary_edges(), gimple_account_profile_record(), gimple_duplicate_sese_tail(), gimple_verify_flow_info(), global0(), global0adjusted(), guessed_local(), handle_missing_profiles(), inline_small_functions(), inline_transform(), ipa_merge_profiles(), ipa_p(), ipa_profile(), ipa_profile_generate_summary(), ipcp_cloning_candidate_p(), ipcp_propagate_stage(), max(), cgraph_edge::maybe_hot_p(), merge(), nonzero_p(), operator+(), operator+=(), operator-(), operator-=(), operator<(), operator<(), operator<=(), operator<=(), operator>(), operator>(), operator>=(), operator>=(), perhaps_add_new_callers(), probability_in(), profile_record_check_consistency(), rebuild_frequencies(), report_unroll(), rtl_account_profile_record(), to_cgraph_frequency(), to_frequency(), to_gcov_type(), to_sreal_scale(), try_unroll_loop_completely(), update_bb_profile_for_threading(), verify_flow_info(), very_large_p(), and want_inline_small_function_p().

◆ ipa()

◆ ipa_p()

◆ max()

◆ merge()

profile_count profile_count::merge ( profile_count other) const
inline

References initialized_p(), and m_quality.

◆ nonzero_p()

◆ ok_for_merging()

bool profile_count::ok_for_merging ( profile_count other) const
inline

References ADJUSTED, and m_quality.

◆ one()

static profile_count profile_count::one ( )
inlinestatic

References from_gcov_type().

Referenced by expand_call_inline().

◆ operator*()

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

References apply_scale().

◆ operator*=()

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

References apply_scale().

◆ operator+()

◆ operator+=()

◆ operator-()

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

◆ operator-=()

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

◆ operator/()

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

References apply_scale(), and ggc_alloc().

◆ operator/=()

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

References apply_scale(), and ggc_alloc().

◆ operator<() [1/2]

bool profile_count::operator< ( const gcov_type other) const
inline

◆ operator<() [2/2]

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

◆ operator<=() [1/2]

bool profile_count::operator<= ( const gcov_type other) const
inline

◆ operator<=() [2/2]

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

◆ operator==()

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

References m_quality, and m_val.

◆ operator>() [1/2]

bool profile_count::operator> ( const gcov_type other) const
inline

◆ operator>() [2/2]

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

◆ operator>=() [1/2]

bool profile_count::operator>= ( const gcov_type other) const
inline

◆ operator>=() [2/2]

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

◆ precise_p()

bool profile_count::precise_p ( ) const
inline

◆ probability_in()

◆ quality()

enum profile_quality profile_count::quality ( ) const
inline

◆ reliable_p()

bool profile_count::reliable_p ( ) const
inline

References ADJUSTED, and m_quality.

◆ stream_in()

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

References ggc_alloc(), streamer_read_gcov_count(), and streamer_read_uhwi().

Referenced by input_bb(), input_edge(), and input_node().

◆ stream_out() [1/2]

void profile_count::stream_out ( struct lto_output_stream * ob)

◆ stream_out() [2/2]

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

References m_quality, m_val, streamer_write_gcov_count(), and streamer_write_uhwi().

Referenced by lto_output_node(), and output_bb().

◆ to_cgraph_frequency()

int profile_count::to_cgraph_frequency ( profile_count entry_bb_count) const
Return count as frequency within FUN scaled in range 0 to CGRAPH_FREQ_MAX
where CGRAPH_FREQ_BASE means that count equals to entry block count.
Used for legacy code and should not be used anymore.   

References CGRAPH_FREQ_BASE, CGRAPH_FREQ_MAX, compatible_p(), gcc_checking_assert, ggc_alloc(), initialized_p(), m_val, MAX, MIN, safe_scale_64bit(), and zero().

Referenced by compute_call_stmt_bb_frequency(), and cgraph_edge::frequency().

◆ to_frequency()

◆ to_gcov_type()

◆ to_sreal_scale()

◆ uninitialized()

◆ value()

uint64_t profile_count::value ( ) const
inline

References m_val.

Referenced by dump_function_to_file(), and dump_gimple_bb_header().

◆ verify()

◆ very_large_p()

bool profile_count::very_large_p ( )
inline

References initialized_p(), m_val, and max_count.

◆ zero()

static profile_count profile_count::zero ( )
inlinestatic

References from_gcov_type().

Referenced by adjust_clone_incoming_counts(), adjust_for_ipa_scaling(), autofdo::afdo_annotate_cfg(), autofdo::afdo_calculate_branch_prob(), autofdo::afdo_propagate_circuit(), autofdo::afdo_propagate_edge(), apply_probability(), apply_scale(), check_bb_profile(), profile_probability::combine_with_count(), combine_with_ipa_count(), compatible_p(), compute_alignments(), compute_branch_probabilities(), compute_function_frequency(), compute_path_counts(), consider_split(), copy_bb(), copy_cfg_body(), decide_about_value(), determine_unlikely_bbs(), drop_profile(), cgraph_node::dump(), duplicate_loop_body_to_header_edge(), eliminate_partially_redundant_load(), estimate_bb_frequencies(), execute_sm_if_changed(), expensive_function_p(), find_subloop_latch_edge_by_profile(), find_traces(), force_edge_cold(), get_info_about_necessary_edges(), gimple_find_sub_bbs(), final_warning_record::grow_type_warnings(), handle_missing_profiles(), init_caller_stats(), insert_check_and_trap(), ipa(), ipa_devirt(), ipa_inline(), ipa_merge_profiles(), ipa_propagate_frequency(), ipa_propagate_frequency_1(), ipcp_cloning_candidate_p(), isolate_path(), loop_count_in(), make_forwarder_block(), make_forwarders_with_degenerate_phis(), max(), maybe_hot_count_p(), move_sese_region_to_fn(), operator+(), operator+=(), operator-(), operator-=(), operator<(), operator<=(), operator>(), operator>=(), optimize_bb_for_size_p(), cgraph_node::optimize_for_size_p(), perhaps_add_new_callers(), possible_polymorphic_call_targets(), probability_in(), probably_never_executed(), profile_record_check_consistency(), propagate_freq(), propagate_unlikely_bbs_forward(), rebuild_frequencies(), redirect_to_unreachable(), sanitize_hot_paths(), scale_bbs_frequencies_profile_count(), scale_dominated_blocks_in_loop(), scale_strictly_dominated_blocks(), shrink_wrap_one_built_in_call_with_conds(), simd_clone_adjust(), split_function(), ssa_fix_duplicate_block_edges(), to_cgraph_frequency(), to_frequency(), to_sreal_scale(), try_shrink_wrapping(), unlikely_executed_bb_p(), unlikely_executed_edge_p(), unloop_loops(), update_bb_profile_for_threading(), update_counts_for_self_gen_clones(), update_profile(), update_profile_for_new_sub_basic_block(), update_profiling_info(), and update_specialized_profile().

Field Documentation

◆ m_quality

◆ m_val

◆ max_count

◆ n_bits

const int profile_count::n_bits = 61
static

Referenced by estimate_bb_frequencies().

◆ uninitialized_count

const uint64_t profile_count::uninitialized_count = ((uint64_t) 1 << n_bits) - 1
staticprivate

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