From 1628b2faf0011322be6ea4ad7b2484f720c595bf Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Fri, 23 Aug 2019 09:48:34 +0200 Subject: [PATCH] Clean up value-prof.c a bit. 2019-08-23 Martin Liska * profile.c (instrument_values): Do not set 0 as last argument. * tree-profile.c (gimple_gen_interval_profiler): Remove last argument. (gimple_gen_pow2_profiler): Likewise. (gimple_gen_topn_values_profiler): Likewise. (gimple_gen_ic_profiler): Likewise. (gimple_gen_time_profiler): Likewise. (gimple_gen_average_profiler): Likewise. (gimple_gen_ior_profiler): Likewise. * value-prof.c (dump_histogram_value): Use default in switch statement instead of HIST_TYPE_MAX. (stream_in_histogram_value): Likewise. (gimple_duplicate_stmt_histograms): Do not use NULL for implicitly set arguments. (gimple_divmod_values_to_profile): Do not use reserve+quick_push. (gimple_indirect_call_to_profile): Likewise. (gimple_find_values_to_profile): Use implicit function call arguments. * value-prof.h (gimple_alloc_histogram_value): Set default values. (gimple_gen_interval_profiler): Remove last argument. (gimple_gen_pow2_profiler): Likewise. (gimple_gen_topn_values_profiler): Likewise. (gimple_gen_ic_profiler): Likewise. (gimple_gen_time_profiler): Likewise. (gimple_gen_average_profiler): Likewise. (gimple_gen_ior_profiler): Likewise. From-SVN: r274844 --- gcc/ChangeLog | 32 ++++++++++++++++++++++++++++++++ gcc/profile.c | 14 +++++++------- gcc/tree-profile.c | 36 +++++++++++++++++------------------- gcc/value-prof.c | 36 ++++++++++++++++-------------------- gcc/value-prof.h | 18 +++++++++--------- 5 files changed, 81 insertions(+), 55 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2651ce2daf0..8e7ab45e761 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,35 @@ +2019-08-23 Martin Liska + + * profile.c (instrument_values): Do not set + 0 as last argument. + * tree-profile.c (gimple_gen_interval_profiler): Remove + last argument. + (gimple_gen_pow2_profiler): Likewise. + (gimple_gen_topn_values_profiler): Likewise. + (gimple_gen_ic_profiler): Likewise. + (gimple_gen_time_profiler): Likewise. + (gimple_gen_average_profiler): Likewise. + (gimple_gen_ior_profiler): Likewise. + * value-prof.c (dump_histogram_value): Use default + in switch statement instead of HIST_TYPE_MAX. + (stream_in_histogram_value): Likewise. + (gimple_duplicate_stmt_histograms): Do not + use NULL for implicitly set arguments. + (gimple_divmod_values_to_profile): Do not use + reserve+quick_push. + (gimple_indirect_call_to_profile): Likewise. + (gimple_find_values_to_profile): Use implicit + function call arguments. + * value-prof.h (gimple_alloc_histogram_value): + Set default values. + (gimple_gen_interval_profiler): Remove last argument. + (gimple_gen_pow2_profiler): Likewise. + (gimple_gen_topn_values_profiler): Likewise. + (gimple_gen_ic_profiler): Likewise. + (gimple_gen_time_profiler): Likewise. + (gimple_gen_average_profiler): Likewise. + (gimple_gen_ior_profiler): Likewise. + 2019-08-22 Martin Sebor PR middle-end/91490 diff --git a/gcc/profile.c b/gcc/profile.c index 6c8127ab3de..8d39a7d094e 100644 --- a/gcc/profile.c +++ b/gcc/profile.c @@ -160,31 +160,31 @@ instrument_values (histogram_values values) switch (hist->type) { case HIST_TYPE_INTERVAL: - gimple_gen_interval_profiler (hist, t, 0); + gimple_gen_interval_profiler (hist, t); break; case HIST_TYPE_POW2: - gimple_gen_pow2_profiler (hist, t, 0); + gimple_gen_pow2_profiler (hist, t); break; case HIST_TYPE_TOPN_VALUES: - gimple_gen_topn_values_profiler (hist, t, 0); + gimple_gen_topn_values_profiler (hist, t); break; case HIST_TYPE_INDIR_CALL: - gimple_gen_ic_profiler (hist, t, 0); + gimple_gen_ic_profiler (hist, t); break; case HIST_TYPE_AVERAGE: - gimple_gen_average_profiler (hist, t, 0); + gimple_gen_average_profiler (hist, t); break; case HIST_TYPE_IOR: - gimple_gen_ior_profiler (hist, t, 0); + gimple_gen_ior_profiler (hist, t); break; case HIST_TYPE_TIME_PROFILE: - gimple_gen_time_profiler (t, 0); + gimple_gen_time_profiler (t); break; default: diff --git a/gcc/tree-profile.c b/gcc/tree-profile.c index 554a8c98419..4c1ead5781f 100644 --- a/gcc/tree-profile.c +++ b/gcc/tree-profile.c @@ -293,11 +293,11 @@ prepare_instrumented_value (gimple_stmt_iterator *gsi, histogram_value value) tag of the section for counters, BASE is offset of the counter position. */ void -gimple_gen_interval_profiler (histogram_value value, unsigned tag, unsigned base) +gimple_gen_interval_profiler (histogram_value value, unsigned tag) { gimple *stmt = value->hvalue.stmt; gimple_stmt_iterator gsi = gsi_for_stmt (stmt); - tree ref = tree_coverage_counter_ref (tag, base), ref_ptr; + tree ref = tree_coverage_counter_ref (tag, 0), ref_ptr; gcall *call; tree val; tree start = build_int_cst_type (integer_type_node, @@ -316,14 +316,14 @@ gimple_gen_interval_profiler (histogram_value value, unsigned tag, unsigned base /* Output instructions as GIMPLE trees to increment the power of two histogram counter. VALUE is the expression whose value is profiled. TAG is the tag - of the section for counters, BASE is offset of the counter position. */ + of the section for counters. */ void -gimple_gen_pow2_profiler (histogram_value value, unsigned tag, unsigned base) +gimple_gen_pow2_profiler (histogram_value value, unsigned tag) { gimple *stmt = value->hvalue.stmt; gimple_stmt_iterator gsi = gsi_for_stmt (stmt); - tree ref_ptr = tree_coverage_counter_addr (tag, base); + tree ref_ptr = tree_coverage_counter_addr (tag, 0); gcall *call; tree val; @@ -336,15 +336,14 @@ gimple_gen_pow2_profiler (histogram_value value, unsigned tag, unsigned base) /* Output instructions as GIMPLE trees for code to find the most N common values. VALUE is the expression whose value is profiled. TAG is the tag - of the section for counters, BASE is offset of the counter position. */ + of the section for counters. */ void -gimple_gen_topn_values_profiler (histogram_value value, unsigned tag, - unsigned base) +gimple_gen_topn_values_profiler (histogram_value value, unsigned tag) { gimple *stmt = value->hvalue.stmt; gimple_stmt_iterator gsi = gsi_for_stmt (stmt); - tree ref_ptr = tree_coverage_counter_addr (tag, base); + tree ref_ptr = tree_coverage_counter_addr (tag, 0); gcall *call; tree val; @@ -359,17 +358,16 @@ gimple_gen_topn_values_profiler (histogram_value value, unsigned tag, /* Output instructions as GIMPLE trees for code to find the most common called function in indirect call. VALUE is the call expression whose indirect callee is profiled. - TAG is the tag of the section for counters, BASE is offset of the - counter position. */ + TAG is the tag of the section for counters. */ void -gimple_gen_ic_profiler (histogram_value value, unsigned tag, unsigned base) +gimple_gen_ic_profiler (histogram_value value, unsigned tag) { tree tmp1; gassign *stmt1, *stmt2, *stmt3; gimple *stmt = value->hvalue.stmt; gimple_stmt_iterator gsi = gsi_for_stmt (stmt); - tree ref_ptr = tree_coverage_counter_addr (tag, base); + tree ref_ptr = tree_coverage_counter_addr (tag, 0); ref_ptr = force_gimple_operand_gsi (&gsi, ref_ptr, true, NULL_TREE, true, GSI_SAME_STMT); @@ -485,7 +483,7 @@ gimple_gen_ic_func_profiler (void) counter position and GSI is the iterator we place the counter. */ void -gimple_gen_time_profiler (unsigned tag, unsigned base) +gimple_gen_time_profiler (unsigned tag) { tree type = get_gcov_type (); basic_block entry = ENTRY_BLOCK_PTR_FOR_FN (cfun); @@ -504,7 +502,7 @@ gimple_gen_time_profiler (unsigned tag, unsigned base) e->probability = true_edge->probability.invert (); gimple_stmt_iterator gsi = gsi_start_bb (cond_bb); - tree original_ref = tree_coverage_counter_ref (tag, base); + tree original_ref = tree_coverage_counter_ref (tag, 0); tree ref = force_gimple_operand_gsi (&gsi, original_ref, true, NULL_TREE, true, GSI_SAME_STMT); tree one = build_int_cst (type, 1); @@ -564,11 +562,11 @@ gimple_gen_time_profiler (unsigned tag, unsigned base) tag of the section for counters, BASE is offset of the counter position. */ void -gimple_gen_average_profiler (histogram_value value, unsigned tag, unsigned base) +gimple_gen_average_profiler (histogram_value value, unsigned tag) { gimple *stmt = value->hvalue.stmt; gimple_stmt_iterator gsi = gsi_for_stmt (stmt); - tree ref_ptr = tree_coverage_counter_addr (tag, base); + tree ref_ptr = tree_coverage_counter_addr (tag, 0); gcall *call; tree val; @@ -585,11 +583,11 @@ gimple_gen_average_profiler (histogram_value value, unsigned tag, unsigned base) tag of the section for counters, BASE is offset of the counter position. */ void -gimple_gen_ior_profiler (histogram_value value, unsigned tag, unsigned base) +gimple_gen_ior_profiler (histogram_value value, unsigned tag) { gimple *stmt = value->hvalue.stmt; gimple_stmt_iterator gsi = gsi_for_stmt (stmt); - tree ref_ptr = tree_coverage_counter_addr (tag, base); + tree ref_ptr = tree_coverage_counter_addr (tag, 0); gcall *call; tree val; diff --git a/gcc/value-prof.c b/gcc/value-prof.c index 00ede8d985f..55ea0973a03 100644 --- a/gcc/value-prof.c +++ b/gcc/value-prof.c @@ -300,7 +300,7 @@ dump_histogram_value (FILE *dump_file, histogram_value hist) fprintf (dump_file, "Time profile time:%" PRId64 ".\n", (int64_t) hist->hvalue.counters[0]); break; - case HIST_TYPE_MAX: + default: gcc_unreachable (); } } @@ -360,7 +360,7 @@ stream_in_histogram_value (class lto_input_block *ib, gimple *stmt) bp = streamer_read_bitpack (ib); type = bp_unpack_enum (&bp, hist_type, HIST_TYPE_MAX); next = bp_unpack_value (&bp, 1); - new_val = gimple_alloc_histogram_value (cfun, type, stmt, NULL); + new_val = gimple_alloc_histogram_value (cfun, type, stmt); switch (type) { case HIST_TYPE_INTERVAL: @@ -384,7 +384,7 @@ stream_in_histogram_value (class lto_input_block *ib, gimple *stmt) ncounters = 1; break; - case HIST_TYPE_MAX: + default: gcc_unreachable (); } new_val->hvalue.counters = XNEWVAR (gcov_type, sizeof (*new_val->hvalue.counters) * ncounters); @@ -429,7 +429,7 @@ gimple_duplicate_stmt_histograms (struct function *fun, gimple *stmt, histogram_value val; for (val = gimple_histogram_value (ofun, ostmt); val != NULL; val = val->hvalue.next) { - histogram_value new_val = gimple_alloc_histogram_value (fun, val->type, NULL, NULL); + histogram_value new_val = gimple_alloc_histogram_value (fun, val->type); memcpy (new_val, val, sizeof (*val)); new_val->hvalue.stmt = stmt; new_val->hvalue.counters = XNEWVAR (gcov_type, sizeof (*new_val->hvalue.counters) * new_val->n_counters); @@ -1791,14 +1791,12 @@ gimple_divmod_values_to_profile (gimple *stmt, histogram_values *values) divisor = gimple_assign_rhs2 (stmt); op0 = gimple_assign_rhs1 (stmt); - values->reserve (3); - if (TREE_CODE (divisor) == SSA_NAME) /* Check for the case where the divisor is the same value most of the time. */ - values->quick_push (gimple_alloc_histogram_value (cfun, - HIST_TYPE_TOPN_VALUES, - stmt, divisor)); + values->safe_push (gimple_alloc_histogram_value (cfun, + HIST_TYPE_TOPN_VALUES, + stmt, divisor)); /* For mod, check whether it is not often a noop (or replaceable by a few subtractions). */ @@ -1808,16 +1806,15 @@ gimple_divmod_values_to_profile (gimple *stmt, histogram_values *values) { tree val; /* Check for a special case where the divisor is power of 2. */ - values->quick_push (gimple_alloc_histogram_value (cfun, - HIST_TYPE_POW2, - stmt, divisor)); - + values->safe_push (gimple_alloc_histogram_value (cfun, + HIST_TYPE_POW2, + stmt, divisor)); val = build2 (TRUNC_DIV_EXPR, type, op0, divisor); hist = gimple_alloc_histogram_value (cfun, HIST_TYPE_INTERVAL, stmt, val); hist->hdata.intvl.int_start = 0; hist->hdata.intvl.steps = 2; - values->quick_push (hist); + values->safe_push (hist); } return; @@ -1840,11 +1837,9 @@ gimple_indirect_call_to_profile (gimple *stmt, histogram_values *values) return; callee = gimple_call_fn (stmt); - - values->reserve (3); - - values->quick_push (gimple_alloc_histogram_value (cfun, HIST_TYPE_INDIR_CALL, - stmt, callee)); + histogram_value v = gimple_alloc_histogram_value (cfun, HIST_TYPE_INDIR_CALL, + stmt, callee); + values->safe_push (v); return; } @@ -1911,7 +1906,8 @@ gimple_find_values_to_profile (histogram_values *values) for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) gimple_values_to_profile (gsi_stmt (gsi), values); - values->safe_push (gimple_alloc_histogram_value (cfun, HIST_TYPE_TIME_PROFILE, 0, 0)); + values->safe_push (gimple_alloc_histogram_value (cfun, + HIST_TYPE_TIME_PROFILE)); FOR_EACH_VEC_ELT (*values, i, hist) { diff --git a/gcc/value-prof.h b/gcc/value-prof.h index 1078722163b..77c06f60096 100644 --- a/gcc/value-prof.h +++ b/gcc/value-prof.h @@ -73,7 +73,8 @@ extern void gimple_find_values_to_profile (histogram_values *); extern bool gimple_value_profile_transformations (void); histogram_value gimple_alloc_histogram_value (struct function *, enum hist_type, - gimple *stmt, tree); + gimple *stmt = NULL, + tree value = NULL_TREE); histogram_value gimple_histogram_value (struct function *, gimple *); histogram_value gimple_histogram_value_of_type (struct function *, gimple *, enum hist_type); @@ -97,15 +98,14 @@ bool get_nth_most_common_value (gimple *stmt, const char *counter_type, /* In tree-profile.c. */ extern void gimple_init_gcov_profiler (void); extern void gimple_gen_edge_profiler (int, edge); -extern void gimple_gen_interval_profiler (histogram_value, unsigned, unsigned); -extern void gimple_gen_pow2_profiler (histogram_value, unsigned, unsigned); -extern void gimple_gen_topn_values_profiler (histogram_value, unsigned, - unsigned); -extern void gimple_gen_ic_profiler (histogram_value, unsigned, unsigned); +extern void gimple_gen_interval_profiler (histogram_value, unsigned); +extern void gimple_gen_pow2_profiler (histogram_value, unsigned); +extern void gimple_gen_topn_values_profiler (histogram_value, unsigned); +extern void gimple_gen_ic_profiler (histogram_value, unsigned); extern void gimple_gen_ic_func_profiler (void); -extern void gimple_gen_time_profiler (unsigned, unsigned); -extern void gimple_gen_average_profiler (histogram_value, unsigned, unsigned); -extern void gimple_gen_ior_profiler (histogram_value, unsigned, unsigned); +extern void gimple_gen_time_profiler (unsigned); +extern void gimple_gen_average_profiler (histogram_value, unsigned); +extern void gimple_gen_ior_profiler (histogram_value, unsigned); extern void stream_out_histogram_value (struct output_block *, histogram_value); extern void stream_in_histogram_value (class lto_input_block *, gimple *); extern struct cgraph_node* find_func_by_profile_id (int func_id);