diff options
author | Steven Bosscher <steven@gcc.gnu.org> | 2012-07-23 09:24:21 +0000 |
---|---|---|
committer | Steven Bosscher <steven@gcc.gnu.org> | 2012-07-23 09:24:21 +0000 |
commit | 9696c52909efcdb631f5fd7e8a8261656a25cc1b (patch) | |
tree | 5452a2b7de063eb5483f6c69af68f3b173a2adc9 /gcc/value-prof.c | |
parent | 678400b3589e37edc90647ce3744347301effbed (diff) | |
download | gcc-9696c52909efcdb631f5fd7e8a8261656a25cc1b.zip gcc-9696c52909efcdb631f5fd7e8a8261656a25cc1b.tar.gz gcc-9696c52909efcdb631f5fd7e8a8261656a25cc1b.tar.bz2 |
opts.c (common_handle_option): Do not set flag_value_profile_transformations for -fprofile-generate.
* opts.c (common_handle_option): Do not set
flag_value_profile_transformations for -fprofile-generate.
* profile.c (instrument_values): Use COUNTER_FOR_HIST_TYPE.
(BB_TO_GCOV_INDEX): Remove.
(output_location): Don't use it.
(branch_prob): Likewise. Don't fiddle with the index of
ENTRY_BLOCK_PTR and EXIT_BLOCK_PTR. Use clear_aux_for_blocks.
(find_spanning_tree):
* gcov.c (struct function_info): Document that blocks 0 and 1
are the entry resp. exit blocks in gcov, too, like in GCC itself.
(solve_flow_graph): Use ENTRY_BLOCK and EXIT_BLOCK for special
blocks identification.
(output_lines): Likewise.
* value-prof.c (gimple_value_profile_transformations): Do not
test flag_value_profile_transformations again.
(gimple_ic_transform): Take a gimple_stmt_iterator like all other
transformation functions.
(gimple_values_to_profile):
Don't test flag_value_profile_transformations
* tree-profile.c (tree_profiling): Assert that the cgraph is in
the CGRAPH_STATE_IPA_SSA state.
Do not set, or look at, after_tree_profile.
* function.h (struct function): Remove after_tree_profile bit.
* omp-low.c (expand_omp_taskreg): Don't set after_tree_profile.
* tree-inline.c (initialize_cfun): Don't copy it.
* lto-streamer-out.c (output_struct_function_base): Don't stream it.
* lto-streamer-in.c (input_struct_function_base): Likewise.
From-SVN: r189778
Diffstat (limited to 'gcc/value-prof.c')
-rw-r--r-- | gcc/value-prof.c | 94 |
1 files changed, 63 insertions, 31 deletions
diff --git a/gcc/value-prof.c b/gcc/value-prof.c index 29c3e92..b75c36f 100644 --- a/gcc/value-prof.c +++ b/gcc/value-prof.c @@ -53,28 +53,63 @@ along with GCC; see the file COPYING3. If not see 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) 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. - 3) Indirect/virtual call specialization. If we can determine most + 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 - inliner). + the inliner). - Every such optimization should add its requirements for profiled values to - insn_values_to_profile function. This function is called from branch_prob - in profile.c and the requested values are instrumented by it in the first - compilation with -fprofile-arcs. The optimization may then read the - gathered data in the second compilation with -fbranch-probabilities. + 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. - The measured data is pointed to from the histograms - field of the statement annotation of the instrumented insns. It is - kept as a linked list of struct histogram_value_t's, which contain the - same information as above. */ + 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... +*/ static tree gimple_divmod_fixed_value (gimple, tree, int, gcov_type, gcov_type); static tree gimple_mod_pow2 (gimple, int, gcov_type, gcov_type); @@ -84,7 +119,7 @@ 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); +static bool gimple_ic_transform (gimple_stmt_iterator *); /* Allocate histogram value. */ @@ -309,7 +344,7 @@ dump_histograms_for_stmt (struct function *fun, FILE *dump_file, gimple stmt) { histogram_value hist; for (hist = gimple_histogram_value (fun, stmt); hist; hist = hist->hvalue.next) - dump_histogram_value (dump_file, hist); + dump_histogram_value (dump_file, hist); } /* Remove all histograms associated with STMT. */ @@ -519,12 +554,11 @@ gimple_value_profile_transformations (void) will be added before the current statement, and that the current statement remain valid (although possibly modified) upon return. */ - if (flag_value_profile_transformations - && (gimple_mod_subtract_transform (&gsi) - || gimple_divmod_fixed_value_transform (&gsi) - || gimple_mod_pow2_value_transform (&gsi) - || gimple_stringops_transform (&gsi) - || gimple_ic_transform (stmt))) + if (gimple_mod_subtract_transform (&gsi) + || gimple_divmod_fixed_value_transform (&gsi) + || gimple_mod_pow2_value_transform (&gsi) + || gimple_stringops_transform (&gsi) + || gimple_ic_transform (&gsi)) { stmt = gsi_stmt (gsi); changed = true; @@ -1283,8 +1317,9 @@ gimple_ic (gimple icall_stmt, struct cgraph_node *direct_call, */ static bool -gimple_ic_transform (gimple stmt) +gimple_ic_transform (gimple_stmt_iterator *gsi) { + gimple stmt = gsi_stmt (*gsi); histogram_value histogram; gcov_type val, count, all, bb_all; gcov_type prob; @@ -1749,12 +1784,9 @@ gimple_stringops_values_to_profile (gimple stmt, histogram_values *values) static void gimple_values_to_profile (gimple stmt, histogram_values *values) { - if (flag_value_profile_transformations) - { - gimple_divmod_values_to_profile (stmt, values); - gimple_stringops_values_to_profile (stmt, values); - gimple_indirect_call_to_profile (stmt, values); - } + gimple_divmod_values_to_profile (stmt, values); + gimple_stringops_values_to_profile (stmt, values); + gimple_indirect_call_to_profile (stmt, values); } void |