GCC Middle and Back End API Reference
autofdo Namespace Reference

Data Structures

class  autofdo_source_profile
class  count_info
struct  decl_lineno
class  edge_info
class  function_instance
struct  scale
struct  string_compare
class  string_table

Typedefs

typedef auto_vec< decl_lineno, 20 > inline_stack
typedef auto_vec< char * > string_vector
typedef std::map< unsigned, gcov_typeicall_target_map
typedef std::set< gimple * > stmt_set
typedef hash_set< int_hash< int, -1, -2 > > name_index_set
typedef hash_map< int_hash< int, -1, -2 >, int > name_index_map
typedef std::set< basic_blockbb_set

Functions

static char * get_original_name (const char *name, bool alloc=true)
static unsigned get_combined_location (location_t loc, tree decl)
static tree get_function_decl_from_block (tree block)
static void dump_afdo_loc (FILE *f, unsigned loc)
static const char * raw_symbol_name (const char *asmname)
static const char * raw_symbol_name (tree decl)
static void dump_inline_stack (FILE *f, inline_stack *stack)
static void get_inline_stack (location_t locus, inline_stack *stack, tree fn=current_function_decl)
static void get_inline_stack_in_node (location_t locus, inline_stack *stack, cgraph_node *node)
static unsigned get_relative_location_for_locus (tree fn, tree block, location_t locus)
static unsigned get_relative_location_for_stmt (tree fn, gimple *stmt)
static int match_with_target (cgraph_node *n, gimple *stmt, function_instance *inlined_fn, cgraph_node *orig_callee)
static void dump_stmt (gimple *stmt, count_info *info, function_instance *inlined_fn, inline_stack &stack)
void mark_expr_locations (function_instance *f, tree t, cgraph_node *node, hash_set< const count_info * > &counts)
static void walk_block (tree fn, function_instance *s, tree block)
static void fake_read_autofdo_module_profile ()
static void read_profile (void)
static bool afdo_indirect_call (gcall *stmt, const icall_target_map &map, bool transform, cgraph_edge *indirect_edge)
static bool afdo_vpt (gcall *gs, const icall_target_map &map, bool transform, cgraph_edge *indirect_edge)
static bool is_bb_annotated (const basic_block bb, const bb_set &annotated)
static void set_bb_annotated (basic_block bb, bb_set *annotated)
static void update_count_by_afdo_count (profile_count *count, gcov_type c)
static void update_count_by_afdo_count (profile_count *count, profile_count c)
static bool afdo_set_bb_count (basic_block bb, hash_set< basic_block > &zero_bbs)
static void afdo_find_equiv_class (bb_set *annotated_bb)
static bool afdo_propagate_edge (bool is_succ, bb_set *annotated_bb)
static void afdo_propagate_circuit (const bb_set &annotated_bb)
static void afdo_propagate (bb_set *annotated_bb)
static int cmp (const void *a, const void *b)
static void add_scale (vec< scale > *scales, profile_count annotated, profile_count orig)
static void scale_bbs (const vec< basic_block > &bbs, sreal scale)
void afdo_adjust_guessed_profile (bb_set *annotated_bb)
static void afdo_calculate_branch_prob (bb_set *annotated_bb)
static void afdo_annotate_cfg (void)
static unsigned int auto_profile (void)

Variables

static string_tableafdo_string_table
static autofdo_source_profileafdo_source_profile
static gcov_summaryafdo_profile_info
static gcov_type afdo_count_scale = 1

Typedef Documentation

◆ bb_set

typedef std::set<basic_block> autofdo::bb_set

◆ icall_target_map

typedef std::map<unsigned, gcov_type> autofdo::icall_target_map
Map from function name's index in string_table to target's execution count.

◆ inline_stack

Represent an inline stack. vector[0] is the leaf node.

◆ name_index_map

typedef hash_map<int_hash <int, -1, -2>, int> autofdo::name_index_map

◆ name_index_set

typedef hash_set<int_hash <int, -1, -2> > autofdo::name_index_set
Set and map used to translate name indexes.

◆ stmt_set

typedef std::set<gimple *> autofdo::stmt_set
Set of gimple stmts. Used to track if the stmt has already been promoted to direct call.

◆ string_vector

String array that stores function names.

Function Documentation

◆ add_scale()

void autofdo::add_scale ( vec< scale > * scales,
profile_count annotated,
profile_count orig )
static

◆ afdo_adjust_guessed_profile()

void autofdo::afdo_adjust_guessed_profile ( bb_set * annotated_bb)
In case given basic block was fully optimized out, AutoFDO will have no data about it. In this case try to preserve static profile. Identify connected components (in undirected form of CFG) which has no annotations at all. Look at thir boundaries and try to determine scaling factor and scale.

References add_scale(), AFDO_EINFO, b, cfun, cmp(), basic_block_def::count, dump_file, FOR_ALL_BB_FN, gcc_checking_assert, profile_count::guessed_local(), basic_block_def::index, profile_count::initialized_p(), is_bb_annotated(), last_basic_block_for_fn, profile_count::max(), max_count, n_basic_blocks_for_fn, PRId64, scale_bbs(), profile_count::to_sreal_scale(), and profile_count::zero().

Referenced by afdo_calculate_branch_prob().

◆ afdo_annotate_cfg()

◆ afdo_calculate_branch_prob()

◆ afdo_find_equiv_class()

void autofdo::afdo_find_equiv_class ( bb_set * annotated_bb)
static
BB1 and BB2 are in an equivalent class iff: 1. BB1 dominates BB2. 2. BB2 post-dominates BB1. 3. BB1 and BB2 are in the same loop nest. This function finds the equivalent class for each basic block, and stores a pointer to the first BB in its equivalent class. Meanwhile, set bb counts for the same equivalent class to be idenical. Update ANNOTATED_BB for the first BB in its equivalent class.

References basic_block_def::aux, CDI_DOMINATORS, CDI_POST_DOMINATORS, cfun, basic_block_def::count, dominated_by_p(), dump_file, FOR_ALL_BB_FN, get_dominated_by(), basic_block_def::index, is_bb_annotated(), basic_block_def::loop_father, NULL, set_bb_annotated(), and update_count_by_afdo_count().

Referenced by afdo_calculate_branch_prob().

◆ afdo_indirect_call()

bool autofdo::afdo_indirect_call ( gcall * stmt,
const icall_target_map & map,
bool transform,
cgraph_edge * indirect_edge )
static
From AutoFDO profiles, find values inside STMT for that we want to measure histograms for indirect-call optimization. This function is actually served for 2 purposes: * before annotation, we need to mark histogram, promote and inline * after annotation, we just need to mark, and let follow-up logic to decide if it needs to promote and inline.

References afdo_count_scale, afdo_string_table, cfun, count, histogram_value_t::counters, symtab_node::decl, symtab_node::definition, dump_file, cgraph_node::get_for_asmname(), get_identifier(), gimple_add_histogram_value(), gimple_alloc_histogram_value(), gimple_bb(), gimple_call_fn(), gimple_call_fndecl(), gimple_call_internal_p(), HIST_TYPE_INDIR_CALL, histogram_value_t::hvalue, cgraph_edge::make_speculative(), map, histogram_value_t::n_counters, NULL, NULL_TREE, print_generic_expr(), print_gimple_stmt(), cgraph_node::profile_id, and TDF_SLIM.

Referenced by afdo_vpt().

◆ afdo_propagate()

void autofdo::afdo_propagate ( bb_set * annotated_bb)
static
Propagate the basic block count and edge count on the control flow graph. We do the propagation iteratively until stablize.

References afdo_propagate_circuit(), afdo_propagate_edge(), basic_block_def::aux, cfun, changed, basic_block_def::count, profile_count::dump(), dump_file, FOR_ALL_BB_FN, i, basic_block_def::index, is_bb_annotated(), set_bb_annotated(), and update_count_by_afdo_count().

Referenced by afdo_calculate_branch_prob().

◆ afdo_propagate_circuit()

void autofdo::afdo_propagate_circuit ( const bb_set & annotated_bb)
static
Special propagation for circuit expressions. Because GCC translates control flow into data flow for circuit expressions. E.g. BB1: if (a && b) BB2 else BB3 will be translated into: BB1: if (a) goto BB.t1 else goto BB.t3 BB.t1: if (b) goto BB.t2 else goto BB.t3 BB.t2: goto BB.t3 BB.t3: tmp = PHI (0 (BB1), 0 (BB.t1), 1 (BB.t2) if (tmp) goto BB2 else goto BB3 In this case, we need to propagate through PHI to determine the edge count of BB1->BB.t1, BB.t1->BB.t2.

References AFDO_EINFO, cfun, dyn_cast(), FOR_ALL_BB_FN, FOR_EACH_EDGE, gimple_assign_rhs1(), gimple_assign_single_p(), gimple_cond_code(), gimple_cond_lhs(), gimple_cond_rhs(), gimple_phi_arg_def(), gimple_phi_arg_edge(), gimple_phi_num_args(), i, integer_onep(), integer_zerop(), is_bb_annotated(), last_nondebug_stmt(), SSA_NAME_DEF_STMT, basic_block_def::succs, TREE_CODE, TREE_CONSTANT, and profile_count::zero().

Referenced by afdo_propagate().

◆ afdo_propagate_edge()

bool autofdo::afdo_propagate_edge ( bool is_succ,
bb_set * annotated_bb )
static
If a basic block's count is known, and only one of its in/out edges' count is unknown, its count can be calculated. Meanwhile, if all of the in/out edges' counts are known, then the basic block's unknown count can also be calculated. Also, if a block has a single predecessor or successor, the block's count can be propagated to that predecessor or successor. IS_SUCC is true if out edges of a basic blocks are examined. Update ANNOTATED_BB accordingly. Return TRUE if any basic block/edge count is changed.

References profile_count::afdo(), AFDO_EINFO, cfun, changed, basic_block_def::count, profile_count::dump(), dump_file, FOR_EACH_BB_FN, FOR_EACH_EDGE, gcc_assert, basic_block_def::index, is_bb_annotated(), profile_count::nonzero_p(), NULL, basic_block_def::preds, set_bb_annotated(), single_pred_edge(), single_pred_p(), single_succ_edge(), single_succ_p(), basic_block_def::succs, update_count_by_afdo_count(), and profile_count::zero().

Referenced by afdo_propagate().

◆ afdo_set_bb_count()

bool autofdo::afdo_set_bb_count ( basic_block bb,
hash_set< basic_block > & zero_bbs )
static

◆ afdo_vpt()

bool autofdo::afdo_vpt ( gcall * gs,
const icall_target_map & map,
bool transform,
cgraph_edge * indirect_edge )
static
From AutoFDO profiles, find values inside STMT for that we want to measure histograms and adds them to list VALUES.

References afdo_indirect_call(), and map.

Referenced by afdo_set_bb_count(), and afdo_vpt_for_early_inline().

◆ auto_profile()

◆ cmp()

int autofdo::cmp ( const void * a,
const void * b )
static
qsort comparator of sreals.

References a, and b.

Referenced by afdo_adjust_guessed_profile().

◆ dump_afdo_loc()

void autofdo::dump_afdo_loc ( FILE * f,
unsigned loc )
static

◆ dump_inline_stack()

void autofdo::dump_inline_stack ( FILE * f,
inline_stack * stack )
static

◆ dump_stmt()

void autofdo::dump_stmt ( gimple * stmt,
count_info * info,
function_instance * inlined_fn,
inline_stack & stack )
static

◆ fake_read_autofdo_module_profile()

void autofdo::fake_read_autofdo_module_profile ( )
static
Module profile is only used by LIPO. Here we simply ignore it.

References gcc_assert, and gcov_read_unsigned().

Referenced by read_profile().

◆ get_combined_location()

unsigned autofdo::get_combined_location ( location_t loc,
tree decl )
static
Return the combined location, which is a 32bit integer in which higher 16 bits stores the line offset of LOC to the start lineno of DECL, The lower 16 bits stores the discriminator.

References DECL_SOURCE_LINE, DECL_SOURCE_LOCATION, get_discriminator_from_loc(), inform(), LOCATION_LINE, and warning_at().

Referenced by get_inline_stack(), get_relative_location_for_locus(), and autofdo::function_instance::match().

◆ get_function_decl_from_block()

tree autofdo::get_function_decl_from_block ( tree block)
static
Return the function decl of a given lexical BLOCK.

References BLOCK_ABSTRACT_ORIGIN, inlined_function_outer_scope_p(), and NULL_TREE.

Referenced by get_inline_stack(), and get_relative_location_for_locus().

◆ get_inline_stack()

void autofdo::get_inline_stack ( location_t locus,
inline_stack * stack,
tree fn = current_function_decl )
static

◆ get_inline_stack_in_node()

◆ get_original_name()

char * autofdo::get_original_name ( const char * name,
bool alloc = true )
static
Helper functions.
Return the original name of NAME: strip the suffix that starts with '.' for names that are generetad after auto-profile pass. This is to match profiled names with the names in the IR at this stage. Note that we only have to strip sufix and not in the middle. Caller is responsible for freeing RET.

References get_original_name(), i, and NULL.

Referenced by get_original_name(), and autofdo::autofdo_source_profile::offline_external_functions().

◆ get_relative_location_for_locus()

unsigned autofdo::get_relative_location_for_locus ( tree fn,
tree block,
location_t locus )
static
Return combined location of LOCUS within BLOCK that is in function FN. This is a 32bit integer in which higher 16 bits stores the line offset of LOC to the start lineno of DECL, The lower 16 bits stores the discriminator.

References BLOCK_SUPERCONTEXT, get_combined_location(), get_function_decl_from_block(), inlined_function_outer_scope_p(), LOCATION_LOCUS, TREE_CODE, and UNKNOWN_LOCATION.

Referenced by get_relative_location_for_stmt(), and walk_block().

◆ get_relative_location_for_stmt()

unsigned autofdo::get_relative_location_for_stmt ( tree fn,
gimple * stmt )
static

◆ is_bb_annotated()

◆ mark_expr_locations()

◆ match_with_target()

int autofdo::match_with_target ( cgraph_node * n,
gimple * stmt,
function_instance * inlined_fn,
cgraph_node * orig_callee )
static

◆ raw_symbol_name() [1/2]

◆ raw_symbol_name() [2/2]

const char * autofdo::raw_symbol_name ( tree decl)
static
Convenience wrapper that looks up assembler name.

References DECL_ASSEMBLER_NAME, IDENTIFIER_POINTER, and raw_symbol_name().

◆ read_profile()

◆ scale_bbs()

void autofdo::scale_bbs ( const vec< basic_block > & bbs,
sreal scale )
static
Scale counts of all basic blocks in BBS by SCALE and convert them to IPA quality.

References profile_count::afdo(), b, profile_count::dump(), dump_file, profile_count::nonzero_p(), and profile_count::zero().

Referenced by afdo_adjust_guessed_profile().

◆ set_bb_annotated()

◆ update_count_by_afdo_count() [1/2]

void autofdo::update_count_by_afdo_count ( profile_count * count,
gcov_type c )
static

◆ update_count_by_afdo_count() [2/2]

void autofdo::update_count_by_afdo_count ( profile_count * count,
profile_count c )
static
Update COUNT by known autofdo count C.

References count.

◆ walk_block()

Variable Documentation

◆ afdo_count_scale

gcov_type autofdo::afdo_count_scale = 1
static
Scaling factor for afdo data. Compared to normal profile AFDO profile counts are much lower, depending on sampling frequency. We scale data up to reudce effects of roundoff errors.

Referenced by afdo_annotate_cfg(), afdo_indirect_call(), afdo_set_bb_count(), autofdo::function_instance::find_icall_target_map(), autofdo::autofdo_source_profile::get_callsite_total_count(), autofdo::autofdo_source_profile::read(), and autofdo::autofdo_source_profile::update_inlined_ind_target().

◆ afdo_profile_info

gcov_summary* autofdo::afdo_profile_info
static

◆ afdo_source_profile

◆ afdo_string_table