public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/kubaneko/heads/histogram)] added primitive peeling and stuff
@ 2023-02-23 18:38 Ondrej Kubanek
  0 siblings, 0 replies; 2+ messages in thread
From: Ondrej Kubanek @ 2023-02-23 18:38 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:4bcaa73f688cbd2dc330e60a36cbf4dc8c9537a8

commit 4bcaa73f688cbd2dc330e60a36cbf4dc8c9537a8
Author: kubaneko <kubanek0ondrej@gmail.com>
Date:   Thu Feb 23 17:04:31 2023 +0000

    added primitive peeling and stuff

Diff:
---
 gcc/cfgloop.h                |  2 +-
 gcc/tree-profile.cc          |  7 +++++--
 gcc/tree-ssa-loop-ivcanon.cc | 30 ++++++++++++++++--------------
 3 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/gcc/cfgloop.h b/gcc/cfgloop.h
index 0ee603893e7..187edd30b31 100644
--- a/gcc/cfgloop.h
+++ b/gcc/cfgloop.h
@@ -297,7 +297,7 @@ public:
      reused.  */
   basic_block former_header;
 
-  histogram_counters* counters=NULL;
+  histogram_counters* counters;
 };
 
 /* Set if the loop is known to be infinite.  */
diff --git a/gcc/tree-profile.cc b/gcc/tree-profile.cc
index 95f1f70fd7c..6f4f3712246 100644
--- a/gcc/tree-profile.cc
+++ b/gcc/tree-profile.cc
@@ -170,7 +170,7 @@ gimple_init_gcov_profiler (void)
       /* void (*) (gcov_type *, gcov_type)  */
       histogram_profiler_fn_type
 	      = build_function_type_list (void_type_node,
-					  gcov_type_ptr, gcov_type_node,
+					  gcov_type_ptr, gcov_type_node, gcov_type_node,
 					  NULL_TREE);
       fn_name = concat ("__gcov_histogram_profiler", fn_suffix, NULL);
       tree_histogram_profiler_fn = build_fn_decl (fn_name, histogram_profiler_fn_type);
@@ -364,11 +364,14 @@ gimple_gen_histogram_profiler (histogram_value value, unsigned tag) // , edge_de
   auto lp = value->hvalue.lp;
   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));
   gcall *call;
   auto_vec<edge> exits = get_loop_exit_edges (lp);
   for ( auto exit : exits ){
        if (!(exit->flags & (EDGE_COMPLEX | EDGE_FAKE))) {
-          call = gimple_build_call (tree_histogram_profiler_fn, 2, ref_ptr, value->hvalue.value);
+          call = gimple_build_call (tree_histogram_profiler_fn, 3, ref_ptr,
+                  value->hvalue.value, hist_size);
           gsi_insert_seq_on_edge (exit, call);
        }
   }
diff --git a/gcc/tree-ssa-loop-ivcanon.cc b/gcc/tree-ssa-loop-ivcanon.cc
index c36efe28dc2..be489f3197e 100644
--- a/gcc/tree-ssa-loop-ivcanon.cc
+++ b/gcc/tree-ssa-loop-ivcanon.cc
@@ -1037,20 +1037,22 @@ try_peel_loop (class loop *loop,
   npeel = estimated_loop_iterations_int (loop);
 
   // linear part most common number
-  //bool histogram_peeling=loop->counters!=NULL;
-  //if (histogram_peeling){
-  //  gcov_type max=0;
-  //  int most_common=-1;
-  //  for (int i=0;i<8; i++){
-  //      if (loop->counters->hist[i]>=max){
-  //          most_common=i;
-  //      }
-  //  }
-  //  if (most_common>0)
-  //  {
-  //      npeel=most_common+1;
-  //  }
-  //}
+  // peels if in linear portion there is more then 90% of iterations
+  bool histogram_peeling=loop->counters!=NULL;
+  if (histogram_peeling){
+    gcov_type psum=0;
+    gcov_type sum=loop->counters->sum;
+    if (sum!=0){
+    for (int i=0;i<param_profile_histogram_size_lin; i++){
+        psum+=(*(loop->counters->hist))[i];
+        if ((100*psum)/sum>=90)
+        {
+            npeel=i;
+            continue;
+        }
+    }
+    }
+  }
 
   if (npeel < 0)
     npeel = likely_max_loop_iterations_int (loop);

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [gcc(refs/users/kubaneko/heads/histogram)] added primitive peeling and stuff
@ 2023-02-23 23:22 Ondrej Kubanek
  0 siblings, 0 replies; 2+ messages in thread
From: Ondrej Kubanek @ 2023-02-23 23:22 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:1cf1f75ee797626b86ee0fcb35936726e8f2b801

commit 1cf1f75ee797626b86ee0fcb35936726e8f2b801
Author: kubaneko <kubanek0ondrej@gmail.com>
Date:   Thu Feb 23 17:04:31 2023 +0000

    added primitive peeling and stuff

Diff:
---
 gcc/cfgloop.h                |  2 +-
 gcc/tree-profile.cc          |  7 +++++--
 gcc/tree-ssa-loop-ivcanon.cc | 30 ++++++++++++++++--------------
 3 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/gcc/cfgloop.h b/gcc/cfgloop.h
index 6c8ff14a3e8..0c9c82c6ed3 100644
--- a/gcc/cfgloop.h
+++ b/gcc/cfgloop.h
@@ -297,7 +297,7 @@ public:
      reused.  */
   basic_block former_header;
 
-  histogram_counters* counters=NULL;
+  histogram_counters* counters;
 };
 
 /* Set if the loop is known to be infinite.  */
diff --git a/gcc/tree-profile.cc b/gcc/tree-profile.cc
index 1f2cc3ab5cc..d38ad80ba0f 100644
--- a/gcc/tree-profile.cc
+++ b/gcc/tree-profile.cc
@@ -170,7 +170,7 @@ gimple_init_gcov_profiler (void)
       /* void (*) (gcov_type *, gcov_type)  */
       histogram_profiler_fn_type
 	      = build_function_type_list (void_type_node,
-					  gcov_type_ptr, gcov_type_node,
+					  gcov_type_ptr, gcov_type_node, gcov_type_node,
 					  NULL_TREE);
       fn_name = concat ("__gcov_histogram_profiler", fn_suffix, NULL);
       tree_histogram_profiler_fn = build_fn_decl (fn_name, histogram_profiler_fn_type);
@@ -364,11 +364,14 @@ gimple_gen_histogram_profiler (histogram_value value, unsigned tag) // , edge_de
   auto lp = value->hvalue.lp;
   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));
   gcall *call;
   auto_vec<edge> exits = get_loop_exit_edges (lp);
   for ( auto exit : exits ){
        if (!(exit->flags & (EDGE_COMPLEX | EDGE_FAKE))) {
-          call = gimple_build_call (tree_histogram_profiler_fn, 2, ref_ptr, value->hvalue.value);
+          call = gimple_build_call (tree_histogram_profiler_fn, 3, ref_ptr,
+                  value->hvalue.value, hist_size);
           gsi_insert_seq_on_edge (exit, call);
        }
   }
diff --git a/gcc/tree-ssa-loop-ivcanon.cc b/gcc/tree-ssa-loop-ivcanon.cc
index bb95cdd491d..38f947f9e8a 100644
--- a/gcc/tree-ssa-loop-ivcanon.cc
+++ b/gcc/tree-ssa-loop-ivcanon.cc
@@ -1037,20 +1037,22 @@ try_peel_loop (class loop *loop,
   npeel = estimated_loop_iterations_int (loop);
 
   // linear part most common number
-  //bool histogram_peeling=loop->counters!=NULL;
-  //if (histogram_peeling){
-  //  gcov_type max=0;
-  //  int most_common=-1;
-  //  for (int i=0;i<8; i++){
-  //      if (loop->counters->hist[i]>=max){
-  //          most_common=i;
-  //      }
-  //  }
-  //  if (most_common>0)
-  //  {
-  //      npeel=most_common+1;
-  //  }
-  //}
+  // peels if in linear portion there is more then 90% of iterations
+  bool histogram_peeling=loop->counters!=NULL;
+  if (histogram_peeling){
+    gcov_type psum=0;
+    gcov_type sum=loop->counters->sum;
+    if (sum!=0){
+    for (int i=0;i<param_profile_histogram_size_lin; i++){
+        psum+=(*(loop->counters->hist))[i];
+        if ((100*psum)/sum>=90)
+        {
+            npeel=i;
+            continue;
+        }
+    }
+    }
+  }
 
   if (npeel < 0)
     npeel = likely_max_loop_iterations_int (loop);

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-23 23:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-23 18:38 [gcc(refs/users/kubaneko/heads/histogram)] added primitive peeling and stuff Ondrej Kubanek
2023-02-23 23:22 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).