From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7880) id D7415385B50A; Thu, 23 Feb 2023 23:21:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D7415385B50A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677194486; bh=t/1hQ8lASW+869kJLpLkSCW1skDcfpU7H6AErpocBa4=; h=From:To:Subject:Date:From; b=VOR0FhVrt8pkTE/sSp3Xujey6KNScMDH2U5KL80MC2oVje5dvEBTcdXC+WyQgqBFU VwHBYBHKJDIoWjHSc4JOJBOHz2AKtMUTMBGXh9gjgHmZJ9bLwEBC2q5dfcs3EOyPhW 5mmyfGt+MirigHYD/5KIFh7bv+C/hrDYJkWF36wo= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Ondrej Kubanek To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/kubaneko/heads/histogram)] squashed 2 commits X-Act-Checkin: gcc X-Git-Author: kubaneko X-Git-Refname: refs/users/kubaneko/heads/histogram X-Git-Oldrev: ffdd7efad3e558ebca67106207ac4202b17dca9c X-Git-Newrev: 8196f7c7de414f05dbe253edcbaaeee5e369732a Message-Id: <20230223232126.D7415385B50A@sourceware.org> Date: Thu, 23 Feb 2023 23:21:26 +0000 (GMT) List-Id: https://gcc.gnu.org/g:8196f7c7de414f05dbe253edcbaaeee5e369732a commit 8196f7c7de414f05dbe253edcbaaeee5e369732a Author: kubaneko Date: Thu Sep 22 19:05:13 2022 +0000 squashed 2 commits fixed function calls and tried to load histogram tried to add loading and failed Diff: --- gcc/cfgloop.h | 7 ++++++ gcc/tree-profile.cc | 15 +++---------- gcc/tree-ssa-loop-manip.h | 4 ---- gcc/value-prof.cc | 54 ++++++++++++++++++++++++++++++++++++++++------- gcc/value-prof.h | 6 ++++-- libgcc/libgcov-profiler.c | 9 ++++---- 6 files changed, 65 insertions(+), 30 deletions(-) diff --git a/gcc/cfgloop.h b/gcc/cfgloop.h index e7ac2b5f3db..ea49a8e891a 100644 --- a/gcc/cfgloop.h +++ b/gcc/cfgloop.h @@ -113,6 +113,8 @@ struct GTY ((chain_next ("%h.next"))) control_iv { struct control_iv *next; }; +#include "value-prof.h" + /* Structure to hold information for each natural loop. */ class GTY ((chain_next ("%h.next"))) loop { public: @@ -272,6 +274,11 @@ public: the basic-block from being collected but its index can still be reused. */ basic_block former_header; + + bool valid_hist = false; + + // We store histogram values here + gcov_type hist[69]; }; /* Set if the loop is known to be infinite. */ diff --git a/gcc/tree-profile.cc b/gcc/tree-profile.cc index 52e94ee95d9..1a7c8243427 100644 --- a/gcc/tree-profile.cc +++ b/gcc/tree-profile.cc @@ -52,6 +52,7 @@ along with GCC; see the file COPYING3. If not see #include "stringpool.h" #include "attribs.h" #include "tree-pretty-print.h" +#include "gimple-pretty-print.h" #include "langhooks.h" #include "stor-layout.h" #include "xregex.h" @@ -374,21 +375,11 @@ gimple_gen_histogram_profiler (histogram_value value, unsigned tag) // , edge_de } else { edge_def *edge = value->hvalue.edge; gcc_assert(edge); - gimple_stmt_iterator gsi; - gimple_seq seq = NULL; - gsi = gsi_start (seq); - tree ref_ptr = tree_coverage_counter_addr (tag, 0); gcall *call; - tree val; - - ref_ptr = force_gimple_operand_gsi (&gsi, ref_ptr, - true, NULL_TREE, true, GSI_SAME_STMT); - val = prepare_instrumented_value (&gsi, value); + tree val = prepare_instrumented_value (NULL, value); call = gimple_build_call (tree_histogram_profiler_fn, 2, ref_ptr, val); - seq = gsi_seq (gsi); - gsi_insert_before (&gsi, call, GSI_NEW_STMT); - gsi_insert_seq_on_edge (edge, seq); + gsi_insert_seq_on_edge (edge, call); } } diff --git a/gcc/tree-ssa-loop-manip.h b/gcc/tree-ssa-loop-manip.h index c71111fdef2..d49273a3987 100644 --- a/gcc/tree-ssa-loop-manip.h +++ b/gcc/tree-ssa-loop-manip.h @@ -24,10 +24,6 @@ typedef void (*transform_callback)(class loop *, void *); extern void create_iv (tree, tree, tree, class loop *, gimple_stmt_iterator *, bool, tree *, tree *); -extern void create_iv2 (tree, tree, tree, class loop *, gimple_stmt_iterator *, - bool, tree *, tree *); -extern void create_iv3 (tree, tree, tree, class loop *, gimple_stmt_iterator *, - bool, tree *, tree *); extern void rewrite_into_loop_closed_ssa (bitmap, unsigned); extern void verify_loop_closed_ssa (bool, class loop * = NULL); diff --git a/gcc/value-prof.cc b/gcc/value-prof.cc index 2331a1c0163..a0af432b23f 100644 --- a/gcc/value-prof.cc +++ b/gcc/value-prof.cc @@ -120,18 +120,20 @@ gimple_alloc_histogram_value (struct function *fun ATTRIBUTE_UNUSED, hist->hvalue.value = value; hist->hvalue.stmt = stmt; hist->hvalue.edge = NULL; + hist->hvalue.lp = NULL; hist->type = type; return hist; } histogram_value -gimple_alloc_histogram_value_edge (struct function *fun ATTRIBUTE_UNUSED, - enum hist_type type, tree value, edge_def *edge) +gimple_alloc_histogram_value_loop (struct function *fun ATTRIBUTE_UNUSED, + enum hist_type type, tree value, edge_def *edge, class loop *lp) { histogram_value hist = (histogram_value) xcalloc (1, sizeof (*hist)); hist->hvalue.value = value; hist->hvalue.stmt = NULL; hist->hvalue.edge = edge; + hist->hvalue.lp = lp; hist->type = type; return hist; } @@ -396,7 +398,7 @@ stream_in_histogram_value (class lto_input_block *ib, gimple *stmt) break; case HIST_TYPE_HISTOGRAM: - ncounters = 70; + ncounters = 69; break; case HIST_TYPE_POW2: case HIST_TYPE_AVERAGE: @@ -631,6 +633,39 @@ check_counter (gimple *stmt, const char * name, return false; } +static bool +gimple_loop_histogram_transform (gimple_stmt_iterator *si) +{ + histogram_value histogram; + gassign *stmt; + + stmt = dyn_cast (gsi_stmt (*si)); + histogram = gimple_histogram_value_of_type (cfun, stmt, HIST_TYPE_HISTOGRAM); + debug_gimple_stmt (stmt); + if (!histogram) + return false; + + gcov_type *counter = histogram->hvalue.counters; + auto lp = histogram->hvalue.lp; + + if (lp->valid_hist){ + for (int i=0;i<69;++i){ + lp->hist[i]+=counter[i]; + } + } else { + lp->valid_hist = true; + for (int i=0;i<69;++i){ + lp->hist[i]=counter[i]; + } + } + + gimple_remove_histogram_value (cfun, stmt, histogram); + + update_stmt (gsi_stmt (*si)); + + return true; +} + /* GIMPLE based transformations. */ bool @@ -666,7 +701,8 @@ gimple_value_profile_transformations (void) if (gimple_mod_subtract_transform (&gsi) || gimple_divmod_fixed_value_transform (&gsi) || gimple_mod_pow2_value_transform (&gsi) - || gimple_stringops_transform (&gsi)) + || gimple_stringops_transform (&gsi) + || gimple_loop_histogram_transform (&gsi)) { stmt = gsi_stmt (gsi); changed = true; @@ -1936,9 +1972,11 @@ gimple_histogram_values_to_profile(function *fun, histogram_values * values){ loop, &gsi, true, &var, NULL); auto_vec exits = get_loop_exit_edges (loop); for ( auto exit : exits ){ - values->safe_push (gimple_alloc_histogram_value_edge (fun, - HIST_TYPE_HISTOGRAM, - var, exit)); + if (!(exit->flags & (EDGE_COMPLEX | EDGE_FAKE))) { + values->safe_push (gimple_alloc_histogram_value_loop (fun, + HIST_TYPE_HISTOGRAM, + var, exit, loop)); + } } } free_dominance_info (CDI_DOMINATORS); @@ -2002,7 +2040,7 @@ gimple_find_values_to_profile (histogram_values *values) break; case HIST_TYPE_HISTOGRAM: - hist->n_counters = 70; + hist->n_counters = 69; break; default: diff --git a/gcc/value-prof.h b/gcc/value-prof.h index 0097c7a6f4f..6c9385fe53c 100644 --- a/gcc/value-prof.h +++ b/gcc/value-prof.h @@ -40,7 +40,8 @@ enum hist_type #define HIST_TYPE_FOR_COUNTER(COUNTER) \ ((enum hist_type) ((COUNTER) - GCOV_FIRST_VALUE_COUNTER)) - +class loop; + /* The value to measure. */ struct histogram_value_t { @@ -49,6 +50,7 @@ struct histogram_value_t tree value; /* The value to profile. */ gimple *stmt; /* Insn containing the value. */ edge_def *edge; /* For adding to empty bbs */ + class loop *lp; gcov_type *counters; /* Pointer to first counter. */ struct histogram_value_t *next; /* Linked list pointer. */ } hvalue; @@ -76,7 +78,7 @@ extern bool gimple_value_profile_transformations (void); histogram_value gimple_alloc_histogram_value (struct function *, enum hist_type, gimple *stmt = NULL, - tree value = NULL_TREE); + tree value = NULL); histogram_value gimple_histogram_value (struct function *, gimple *); histogram_value gimple_histogram_value_of_type (struct function *, gimple *, enum hist_type); diff --git a/libgcc/libgcov-profiler.c b/libgcc/libgcov-profiler.c index 619f1aafe8a..b36584723d5 100644 --- a/libgcc/libgcov-profiler.c +++ b/libgcc/libgcov-profiler.c @@ -35,9 +35,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see void __gcov_histogram_profiler (gcov_type *counters, gcov_type value) { - if (value>0 && value<8){ - counters[value-1]++; + if (value>=0 && value<8){ + counters[value]++; }else{ + gcc_assert(value>0); int pow2 = 3; while (1 << pow2 <= value || 1 << pow2 > 1 << (pow2 + 1)){ ++pow2; @@ -45,10 +46,10 @@ __gcov_histogram_profiler (gcov_type *counters, gcov_type value) // pow2 is first bigger power of 2 // we increment closer power of 2 if ((1<>1