From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7880) id C71B53858D1E; Sun, 26 Feb 2023 19:17:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C71B53858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677439077; bh=FRCcrLfiBFIIZ8rfZ6oFUsdD6KrhPZ7tZraIEZE5WN0=; h=From:To:Subject:Date:From; b=Y0d1lL/vHKuUXumfZrTL52F5AiuijqTDjcB9TplxURmsWV0kOiUfor/+thr1PRF9w 4m0lAdoY4ZiTc5pDtLY5qR3c87pG4vjdfsVJSYlYyOVS8YGwD02jNjqHuwtd66ABZD QIKDZ3I4dT27Dq0NWMQNPTh58VNbE5jM1OQjjfvs= 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)] Added histogram params to libgcov X-Act-Checkin: gcc X-Git-Author: kubaneko X-Git-Refname: refs/users/kubaneko/heads/histogram X-Git-Oldrev: 1cf1f75ee797626b86ee0fcb35936726e8f2b801 X-Git-Newrev: b2ac41c1390c4bf9da1b800d28d33ddf8aca1a61 Message-Id: <20230226191757.C71B53858D1E@sourceware.org> Date: Sun, 26 Feb 2023 19:17:57 +0000 (GMT) List-Id: https://gcc.gnu.org/g:b2ac41c1390c4bf9da1b800d28d33ddf8aca1a61 commit b2ac41c1390c4bf9da1b800d28d33ddf8aca1a61 Author: kubaneko Date: Sun Feb 26 19:17:42 2023 +0000 Added histogram params to libgcov Diff: --- gcc/tree-profile.cc | 2 +- libgcc/libgcov-profiler.c | 147 ++++++++++++++++++++++++++++------------------ libgcc/libgcov.h | 4 +- 3 files changed, 92 insertions(+), 61 deletions(-) diff --git a/gcc/tree-profile.cc b/gcc/tree-profile.cc index d38ad80ba0f..55289dc765e 100644 --- a/gcc/tree-profile.cc +++ b/gcc/tree-profile.cc @@ -365,7 +365,7 @@ gimple_gen_histogram_profiler (histogram_value value, unsigned tag) // , edge_de gcc_assert(lp); tree ref_ptr = tree_coverage_counter_addr (tag, 0); tree hist_size = build_int_cst_type (gcov_type_node, - param_profile_histogram_size_lin + (gcov_type(param_profile_histogram_size)<<32)); + param_profile_histogram_size_lin | (gcov_type(param_profile_histogram_size)<<32)); gcall *call; auto_vec exits = get_loop_exit_edges (lp); for ( auto exit : exits ){ diff --git a/libgcc/libgcov-profiler.c b/libgcc/libgcov-profiler.c index 739a30043c0..9625778d2c7 100644 --- a/libgcc/libgcov-profiler.c +++ b/libgcc/libgcov-profiler.c @@ -26,7 +26,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "libgcov.h" #if !defined(inhibit_libc) -#ifdef L_gcov_histogram_profiler +#ifndef floor_log2 + /* * If value is less then 8 we increment corresponding counter * otherwise we take its logarithm and increment corresponding counter @@ -34,90 +35,120 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see /* For convenience, define 0 -> word_size. */ static inline int -clz_hwi (gcov_type x) +clz_hwi (gcov_type_unsigned x) { if (x == 0) - return 64; -# if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG - return __builtin_clzl (x); -# elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG - return __builtin_clzll (x); -# else - return __builtin_clz (x); -# endif + return sizeof(gcov_type_unsigned)*8; + if (sizeof(gcov_type_unsigned)==sizeof(long)) + return __builtin_clzl (x); + if (sizeof(gcov_type_unsigned)==sizeof(long long)) + return __builtin_clzll (x); + else + return __builtin_clz (x); } -static inline int -floor_log2 (gcov_type x) +static inline gcov_type_unsigned +floor_log2 (gcov_type_unsigned x) { - return 63 - clz_hwi (x); + return sizeof(gcov_type_unsigned)*8 - clz_hwi (x)-1; } +#endif + +#ifdef L_gcov_histogram_profiler +/* + * If value is less then 8 we increment corresponding counter + * otherwise we take its logarithm and increment corresponding counter + */ + void -__gcov_histogram_profiler (gcov_type *counters, gcov_type value) +__gcov_histogram_profiler (gcov_type *counters, gcov_type value, gcov_type hist_sizes) { - if (value>=0 && value<8){ + fprintf (stderr, "profiling:Skip\n"); + assert(hist_sizes>=0 && value>=0); + gcov_type_unsigned hist_size=hist_sizes; + gcov_type_unsigned u_value=value; + gcov_type_unsigned tot_size=hist_size>>32; + gcov_type_unsigned lin_size=hist_size & ((((gcov_type_unsigned)1)<<32)-1); + if (u_value0); - int pow2=floor_log2(value); - counters[pow2+5]++; + gcov_type_unsigned pow2=floor_log2(u_value); + gcov_type_unsigned lin_pow2=floor_log2(lin_size-1); + if ((lin_pow2-lin_size)+tot_size>pow2){ + counters[pow2+(lin_size-lin_pow2)-1]++; + } else { + counters[tot_size-1]++; + } } } -// if (value>=0 && value0); -// int pow2=floor_log2(value); -// counters[pow2+(param_profile_histogram_size_lin-floor_log2 -// (param_profile_histogram_size_lin))]++; -// } + #endif #if defined(L_gcov_histogram_profiler_atomic) && GCOV_SUPPORTS_ATOMIC -/* - * If value is less then 8 we increment corresponding counter - * otherwise we take its logarithm and increment corresponding counter - */ - -/* For convenience, define 0 -> word_size. */ -static inline int -clz_hwi2 (gcov_type x) -{ - if (x == 0) - return 64; -# if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG - return __builtin_clzl (x); -# elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG - return __builtin_clzll (x); -# else - return __builtin_clz (x); -# endif -} - -static inline int -floor_log2_2 (gcov_type x) -{ - return 63 - clz_hwi2 (x); -} - - void -__gcov_histogram_profiler_atomic (gcov_type *counters, gcov_type value) +__gcov_histogram_profiler_atomic (gcov_type *counters, gcov_type value, gcov_type hist_sizes) { - if (value>=0 && value<8){ + fprintf (stderr, "profiling:Skip\n"); + assert(hist_sizes>=0 && value>=0); + gcov_type_unsigned hist_size=hist_sizes; + gcov_type_unsigned u_value=value; + gcov_type_unsigned tot_size=hist_size>>32; + gcov_type_unsigned lin_size=hist_size & ((((gcov_type_unsigned)1)<<32)-1); + if (u_value0); - int pow2=floor_log2_2(value); - __atomic_fetch_add (&counters[pow2+5], 1, __ATOMIC_RELAXED); + gcov_type_unsigned pow2=floor_log2(u_value); + gcov_type_unsigned lin_pow2=floor_log2(lin_size-1); + if ((lin_pow2-lin_size)+tot_size>pow2){ + __atomic_fetch_add (&counters[pow2+(lin_size-lin_pow2)-1], 1, __ATOMIC_RELAXED); + } else { + __atomic_fetch_add (&counters[tot_size-1], 1, __ATOMIC_RELAXED); + } } } + + + +// /* For convenience, define 0 -> word_size. */ +// static inline int +// clz_hwi2 (gcov_type x) +// { +// if (x == 0) +// return 64; +// # if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG +// return __builtin_clzl (x); +// # elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG +// return __builtin_clzll (x); +// # else +// return __builtin_clz (x); +// # endif +// } +// +// static inline int +// floor_log2_2 (gcov_type x) +// { +// return 63 - clz_hwi2 (x); +// } +// +// +// void +// __gcov_histogram_profiler_atomic (gcov_type *counters, gcov_type value, gcov_type hist_sizes) +// { +// if (value>=0 && value<8){ +// __atomic_fetch_add (&counters[value], 1, __ATOMIC_RELAXED); +// }else{ +// gcc_assert(value>0); +// int pow2=floor_log2_2(value); +// __atomic_fetch_add (&counters[pow2+5], 1, __ATOMIC_RELAXED); +// } +// } + #endif #ifdef L_gcov_interval_profiler diff --git a/libgcc/libgcov.h b/libgcc/libgcov.h index cd2f48c4d6d..fa0a95102b0 100644 --- a/libgcc/libgcov.h +++ b/libgcc/libgcov.h @@ -317,8 +317,8 @@ extern void __gcov_merge_ior (gcov_type *, unsigned) ATTRIBUTE_HIDDEN; extern void __gcov_interval_profiler (gcov_type *, gcov_type, int, unsigned); extern void __gcov_interval_profiler_atomic (gcov_type *, gcov_type, int, unsigned); -extern void __gcov_histogram_profiler (gcov_type *, gcov_type); -extern void __gcov_histogram_profiler_atomic (gcov_type *, gcov_type); +extern void __gcov_histogram_profiler (gcov_type *, gcov_type, gcov_type); +extern void __gcov_histogram_profiler_atomic (gcov_type *, gcov_type, gcov_type); extern void __gcov_pow2_profiler (gcov_type *, gcov_type); extern void __gcov_pow2_profiler_atomic (gcov_type *, gcov_type); extern void __gcov_topn_values_profiler (gcov_type *, gcov_type);