public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Ondrej Kubanek <kubaneko@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/users/kubaneko/heads/histogram)] Added histogram params to libgcov
Date: Sun, 26 Feb 2023 19:17:57 +0000 (GMT)	[thread overview]
Message-ID: <20230226191757.C71B53858D1E@sourceware.org> (raw)

https://gcc.gnu.org/g:b2ac41c1390c4bf9da1b800d28d33ddf8aca1a61

commit b2ac41c1390c4bf9da1b800d28d33ddf8aca1a61
Author: kubaneko <kubanek0ondrej@gmail.com>
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<edge> 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_value<lin_size){
     counters[value]++;
   }else{
-    gcc_assert(value>0);
-    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 && value<param_profile_histogram_size_lin){
-//    counters[value]++;
-//  }else{
-//    gcc_assert(value>0);
-//    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_value<lin_size){
     __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);
+    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);

                 reply	other threads:[~2023-02-26 19:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230226191757.C71B53858D1E@sourceware.org \
    --to=kubaneko@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).