From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7880) id 75EC23858016; Wed, 28 Sep 2022 15:30:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 75EC23858016 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664379055; bh=xMHeLm9yS2JtmBTdLR+Rci1o4BTrZRNbocXKpQb/kGo=; h=From:To:Subject:Date:From; b=T18ReiuDTHTBxLeQKdxzxyHw0Yg6nHu+igiQ9u31WYcPly95HM64k5pZDK7w0cszz kJsLAbAM8uQElDv1wFOCEsr8DEm3p6Pvr+cSgzaZ5Mavcv4/G7czKtvQxd9IB2qYUT hv1P3Frt0VWP2o3J0CD5EjdZAREEMvOgvGm2cU0M= 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: dd9aed2c0701a8e0b0cd6225d90bbf871686db5a X-Git-Newrev: 2df5ad66bd60dfddd116a8d6f1a5cfcfa01bb709 Message-Id: <20220928153055.75EC23858016@sourceware.org> Date: Wed, 28 Sep 2022 15:30:55 +0000 (GMT) List-Id: https://gcc.gnu.org/g:2df5ad66bd60dfddd116a8d6f1a5cfcfa01bb709 commit 2df5ad66bd60dfddd116a8d6f1a5cfcfa01bb709 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 | 55 ++++++++++++++++++++++++++++++++++++++++------- gcc/value-prof.h | 6 ++++-- libgcc/libgcov-profiler.c | 9 ++++---- 6 files changed, 66 insertions(+), 30 deletions(-) diff --git a/gcc/cfgloop.h b/gcc/cfgloop.h index 528b1219bc3..062eeb5cc52 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 f2e67e5314d..8f259288ec4 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 9ee3e617bf1..924cac0edff 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 d9dbf4e5240..fe3d87a3108 100644 --- a/gcc/value-prof.cc +++ b/gcc/value-prof.cc @@ -1,4 +1,5 @@ /* Transformations based on profile information for values. + inum tree_code code; Copyright (C) 2003-2022 Free Software Foundation, Inc. This file is part of GCC. @@ -120,18 +121,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 +399,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 +634,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 +702,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 +1973,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 +2041,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 0718f167ab1..ae61f7f7fe2 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 f07f9c34021..eb944158a3c 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