public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/kubaneko/heads/histogram)] squashed 2 commits
@ 2022-09-28 15:30 Ondrej Kubanek
  0 siblings, 0 replies; only message in thread
From: Ondrej Kubanek @ 2022-09-28 15:30 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2df5ad66bd60dfddd116a8d6f1a5cfcfa01bb709

commit 2df5ad66bd60dfddd116a8d6f1a5cfcfa01bb709
Author: kubaneko <kubanek0ondrej@gmail.com>
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 <gassign *> (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<edge> 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))
 
-\f
+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<<pow2+1<<(pow2-1))>>1<value){
-      counters[6+(pow2-3)-1]++;
+      counters[6+(pow2-3)]++;
     }
     else{
-      counters[6+(pow2-3)]++;
+      counters[7+(pow2-3)]++;
     }
   }
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-09-28 15:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-28 15:30 [gcc(refs/users/kubaneko/heads/histogram)] squashed 2 commits Ondrej Kubanek

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).