GCC Middle and Back End API Reference
value-prof.c File Reference

Functions

static tree gimple_divmod_fixed_value (gimple, tree, int, gcov_type, gcov_type)
static tree gimple_mod_pow2 (gimple, int, gcov_type, gcov_type)
static tree gimple_mod_subtract (gimple, int, int, int, gcov_type, gcov_type, gcov_type)
static bool gimple_divmod_fixed_value_transform (gimple_stmt_iterator *)
static bool gimple_mod_pow2_value_transform (gimple_stmt_iterator *)
static bool gimple_mod_subtract_transform (gimple_stmt_iterator *)
static bool gimple_stringops_transform (gimple_stmt_iterator *)
static bool gimple_ic_transform (gimple_stmt_iterator *)
static histogram_value gimple_alloc_histogram_value (struct function *fun, enum hist_type type, gimple stmt, tree value)
static hashval_t histogram_hash ()
static int histogram_eq ()
static void set_histogram_value ()
histogram_value gimple_histogram_value ()
void gimple_add_histogram_value (struct function *fun, gimple stmt, histogram_value hist)
void gimple_remove_histogram_value (struct function *fun, gimple stmt, histogram_value hist)
histogram_value gimple_histogram_value_of_type (struct function *fun, gimple stmt, enum hist_type type)
static void dump_histogram_value ()
void stream_out_histogram_value ()
void stream_in_histogram_value ()
void dump_histograms_for_stmt ()
void gimple_remove_stmt_histograms ()
void gimple_duplicate_stmt_histograms (struct function *fun, gimple stmt, struct function *ofun, gimple ostmt)
void gimple_move_stmt_histograms ()
static int visit_hist ()
DEBUG_FUNCTION void verify_histograms ()
static int free_hist ()
void free_histograms ()
static bool check_counter (gimple stmt, const char *name, gcov_type *count, gcov_type *all, gcov_type bb_count)
bool gimple_value_profile_transformations ()
static bool gimple_divmod_fixed_value_transform ()
static tree gimple_mod_pow2 ()
static bool gimple_mod_pow2_value_transform ()
static bool gimple_mod_subtract_transform ()
void init_node_map ()
void del_node_map ()
struct cgraph_nodefind_func_by_profile_id ()
static bool check_ic_target ()
gimple gimple_ic (gimple icall_stmt, struct cgraph_node *direct_call, int prob, gcov_type count, gcov_type all)
static bool gimple_ic_transform ()
static bool interesting_stringop_to_profile_p ()
static void gimple_stringop_fixed_value (gimple vcall_stmt, tree icall_size, int prob, gcov_type count, gcov_type all)
static bool gimple_stringops_transform ()
void stringop_block_profile (gimple stmt, unsigned int *expected_align, HOST_WIDE_INT *expected_size)
static void gimple_divmod_values_to_profile ()
static void gimple_indirect_call_to_profile ()
static void gimple_stringops_values_to_profile ()
static void gimple_values_to_profile ()
void gimple_find_values_to_profile ()

Variables

static bool error_found = false
static pointer_map_tcgraph_node_map

Function Documentation

static bool check_counter ( gimple  stmt,
const char *  name,
gcov_type count,
gcov_type all,
gcov_type  bb_count 
)
static
The overall number of invocations of the counter should match
   execution count of basic block.  Report it as error rather than
   internal error as it might mean that user has misused the profile
   somehow.   

References current_function_decl, error_at(), gimple_location(), and inform().

Referenced by gimple_divmod_fixed_value_transform(), gimple_ic_transform(), gimple_mod_pow2_value_transform(), gimple_mod_subtract_transform(), and gimple_stringops_transform().

static bool check_ic_target ( )
static
Perform sanity check on the indirect call target. Due to race conditions,
   false function target may be attributed to an indirect call site. If the
   call expression type mismatches with the target function's type, expand_call
   may ICE. Here we only do very minimal sanity check just to make compiler happy.
   Returns true if TARGET is considered ok for call CALL_STMT.   

References cgraph_node_name(), symtab_node_base::decl, gimple_check_call_matching_types(), gimple_location(), inform(), and cgraph_node::symbol.

Referenced by gimple_ic_transform().

void del_node_map ( void  )
Delete the CGRAPH_NODE_MAP.   

References pointer_map_destroy().

Referenced by ipa_profile(), and tree_profiling().

void dump_histograms_for_stmt ( )
struct cgraph_node* find_func_by_profile_id ( )
read
Return cgraph node for function with pid  

References pointer_map_contains().

Referenced by gimple_ic_transform(), and ipa_profile().

static int free_hist ( )
static
Helper function for verify_histograms.  For each histogram reachable via htab
   walk verify that it was reached via statement walk.   

References histogram_value_t::counters, free(), histogram_value_t::hvalue, and memset().

Referenced by free_histograms().

void free_histograms ( void  )

References cfun, and free_hist().

Referenced by gimple_expand_cfg(), and release_function_body().

void gimple_add_histogram_value ( struct function fun,
gimple  stmt,
histogram_value  hist 
)
static tree gimple_divmod_fixed_value ( gimple  stmt,
tree  value,
int  prob,
gcov_type  count,
gcov_type  all 
)
static
@verbatim Transformations based on profile information for values.

Copyright (C) 2003-2013 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/.

In this file value profile based optimizations are placed.  Currently the
   following optimizations are implemented (for more detailed descriptions
   see comments at value_profile_transformations):

   1) Division/modulo specialization.  Provided that we can determine that the
      operands of the division have some special properties, we may use it to
      produce more effective code.

   2) Indirect/virtual call specialization. If we can determine most
      common function callee in indirect/virtual call. We can use this
      information to improve code effectiveness (especially info for
      the inliner).

   3) Speculative prefetching.  If we are able to determine that the difference
      between addresses accessed by a memory reference is usually constant, we
      may add the prefetch instructions.
      FIXME: This transformation was removed together with RTL based value
      profiling.


   Value profiling internals
   ==========================

   Every value profiling transformation starts with defining what values
   to profile.  There are different histogram types (see HIST_TYPE_* in
   value-prof.h) and each transformation can request one or more histogram
   types per GIMPLE statement.  The function gimple_find_values_to_profile()
   collects the values to profile in a vec, and adds the number of counters
   required for the different histogram types.

   For a -fprofile-generate run, the statements for which values should be
   recorded, are instrumented in instrument_values().  The instrumentation
   is done by helper functions that can be found in tree-profile.c, where
   new types of histograms can be added if necessary.

   After a -fprofile-use, the value profiling data is read back in by
   compute_value_histograms() that translates the collected data to
   histograms and attaches them to the profiled statements via
   gimple_add_histogram_value().  Histograms are stored in a hash table
   that is attached to every intrumented function, see VALUE_HISTOGRAMS
   in function.h.
   
   The value-profile transformations driver is the function
   gimple_value_profile_transformations().  It traverses all statements in
   the to-be-transformed function, and looks for statements with one or
   more histograms attached to it.  If a statement has histograms, the
   transformation functions are called on the statement.

   Limitations / FIXME / TODO:
   * Only one histogram of each type can be associated with a statement.
   * Currently, HIST_TYPE_CONST_DELTA is not implemented.
     (This type of histogram was originally used to implement a form of
     stride profiling based speculative prefetching to improve SPEC2000
     scores for memory-bound benchmarks, mcf and equake.  However, this
     was an RTL value-profiling transformation, and those have all been
     removed.)
   * Some value profile transformations are done in builtins.c (?!)
   * Updating of histograms needs some TLC.
   * The value profiling code could be used to record analysis results
     from non-profiling (e.g. VRP).
   * Adding new profilers should be simplified, starting with a cleanup
     of what-happens-where andwith making gimple_find_values_to_profile
     and gimple_value_profile_transformations table-driven, perhaps...
Generate code for transformation 1 (with parent gimple assignment
   STMT and probability of taking the optimal path PROB, which is
   equivalent to COUNT/ALL within roundoff error).  This generates the
   result into a temp and returns the temp; it does not replace or
   alter the original STMT.   

References count, edge_def::count, basic_block_def::count, create_tmp_reg(), edge_def::dest, edge_def::flags, gimple_assign_lhs(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), gimple_bb(), gimple_build_assign_with_ops(), gimple_build_cond(), gsi_for_stmt(), gsi_insert_before(), GSI_SAME_STMT, is_gimple_assign(), make_edge(), make_temp_ssa_name(), prob, edge_def::probability, remove_edge(), and split_block().

Referenced by gimple_divmod_fixed_value_transform().

static bool gimple_divmod_fixed_value_transform ( gimple_stmt_iterator )
static
static void gimple_divmod_values_to_profile ( )
static
static bool gimple_ic_transform ( gimple_stmt_iterator )
static
static void gimple_indirect_call_to_profile ( )
static
Find calls inside STMT for that we want to measure histograms for
   indirect/virtual call optimization.  

References cfun, gimple_alloc_histogram_value(), gimple_call_fn(), gimple_call_fndecl(), gimple_call_internal_p(), and HIST_TYPE_INDIR_CALL.

Referenced by gimple_values_to_profile().

static tree gimple_mod_pow2 ( gimple  ,
int  ,
gcov_type  ,
gcov_type   
)
static
static tree gimple_mod_pow2 ( )
static
Generate code for transformation 2 (with parent gimple assign STMT and
   probability of taking the optimal path PROB, which is equivalent to COUNT/ALL
   within roundoff error).  This generates the result into a temp and returns
   the temp; it does not replace or alter the original STMT.   

References build_int_cst(), count, edge_def::count, basic_block_def::count, create_tmp_reg(), edge_def::dest, edge_def::flags, gimple_assign_lhs(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), gimple_bb(), gimple_build_assign_with_ops(), gimple_build_cond(), gsi_for_stmt(), gsi_insert_before(), GSI_SAME_STMT, is_gimple_assign(), make_edge(), make_temp_ssa_name(), prob, edge_def::probability, remove_edge(), and split_block().

static bool gimple_mod_pow2_value_transform ( gimple_stmt_iterator )
static
static tree gimple_mod_subtract ( gimple  stmt,
int  prob1,
int  prob2,
int  ncounts,
gcov_type  count1,
gcov_type  count2,
gcov_type  all 
)
static
Generate code for transformations 3 and 4 (with parent gimple assign STMT, and
   NCOUNTS the number of cases to support.  Currently only NCOUNTS==0 or 1 is
   supported and this is built into this interface.  The probabilities of taking
   the optimal paths are PROB1 and PROB2, which are equivalent to COUNT1/ALL and
   COUNT2/ALL respectively within roundoff error).  This generates the
   result into a temp and returns the temp; it does not replace or alter
   the original STMT.   
FIXME: Generalize the interface to handle NCOUNTS > 1.   

References edge_def::count, basic_block_def::count, create_tmp_reg(), edge_def::dest, edge_def::flags, gimple_assign_lhs(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), gimple_bb(), gimple_build_assign_with_ops(), gimple_build_cond(), gsi_for_stmt(), gsi_insert_before(), GSI_SAME_STMT, is_gimple_assign(), make_edge(), make_temp_ssa_name(), edge_def::probability, and split_block().

Referenced by gimple_mod_subtract_transform().

static bool gimple_mod_subtract_transform ( gimple_stmt_iterator )
static
void gimple_move_stmt_histograms ( )
void gimple_remove_stmt_histograms ( )
Remove all histograms associated with STMT.   

References gimple_histogram_value(), and gimple_remove_histogram_value().

Referenced by execute_fold_all_builtins(), gsi_remove(), gsi_replace(), and move_block_to_fn().

static void gimple_stringop_fixed_value ( gimple  vcall_stmt,
tree  icall_size,
int  prob,
gcov_type  count,
gcov_type  all 
)
static
static bool gimple_stringops_transform ( gimple_stmt_iterator )
static
static void gimple_stringops_values_to_profile ( )
static
Find values inside STMT for that we want to measure histograms for
   string operations.   

References cfun, gimple_alloc_histogram_value(), gimple_call_arg(), gimple_call_fndecl(), HIST_TYPE_AVERAGE, HIST_TYPE_IOR, HIST_TYPE_SINGLE_VALUE, and interesting_stringop_to_profile_p().

Referenced by gimple_values_to_profile().

static void gimple_values_to_profile ( )
static
Find values inside STMT for that we want to measure histograms and adds
   them to list VALUES.   

References gimple_divmod_values_to_profile(), gimple_indirect_call_to_profile(), and gimple_stringops_values_to_profile().

Referenced by gimple_find_values_to_profile().

static int histogram_eq ( )
static
Return nonzero if statement for histogram_value X is Y.   

Referenced by set_histogram_value().

static hashval_t histogram_hash ( )
static
Hash value for histogram.   
void init_node_map ( )
Initialize map from PROFILE_ID to CGRAPH_NODE.
   When LOCAL is true, the PROFILE_IDs are computed.  when it is false we assume
   that the PROFILE_IDs was already assigned.   

References cgraph_function_with_gimple_body_p(), cgraph_node_name(), cgraph_only_called_directly_p(), coverage_compute_profile_id(), dump_file, symtab_node_base::order, pointer_map_contains(), pointer_map_create(), pointer_map_insert(), cgraph_node::profile_id, cgraph_node::symbol, and symtab_node_name().

static bool interesting_stringop_to_profile_p ( )
static
Return true if the stringop CALL with FNDECL shall be profiled.
   SIZE_ARG be set to the argument index for the size of the string
   operation.

References validate_gimple_arglist().

Referenced by gimple_stringop_fixed_value(), gimple_stringops_transform(), and gimple_stringops_values_to_profile().

static void set_histogram_value ( )
static
static int visit_hist ( )
static
Helper function for verify_histograms.  For each histogram reachable via htab
   walk verify that it was reached via statement walk.   

References debug_gimple_stmt(), dump_histogram_value(), error(), error_found, histogram_value_t::hvalue, pointer_set_contains(), histogram_value_t::stmt, and visited.

Referenced by verify_histograms().


Variable Documentation

pointer_map_t* cgraph_node_map
static