public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/kubaneko/heads/histogram)] some refactoring and added lto-streaming for histograms
@ 2023-03-14 17:23 Ondrej Kubanek
0 siblings, 0 replies; only message in thread
From: Ondrej Kubanek @ 2023-03-14 17:23 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:e755feaf21fe3b58357ac90440e67733a032db47
commit e755feaf21fe3b58357ac90440e67733a032db47
Author: kubaneko <kubanek0ondrej@gmail.com>
Date: Mon Mar 13 21:31:03 2023 +0000
some refactoring and added lto-streaming for histograms
Diff:
---
gcc/cfgloop.h | 73 -------------------------------------------------
gcc/lto-streamer-in.cc | 11 ++++++++
gcc/lto-streamer-out.cc | 7 +++++
gcc/tree-vect-loop.cc | 9 ++----
4 files changed, 20 insertions(+), 80 deletions(-)
diff --git a/gcc/cfgloop.h b/gcc/cfgloop.h
index 48badc22648..6a7ef44b8e1 100644
--- a/gcc/cfgloop.h
+++ b/gcc/cfgloop.h
@@ -99,79 +99,6 @@ struct GTY(()) histogram_counters{
vec<gcov_type, va_heap, vl_embed> * GTY((skip)) hist;
};
-// void histogram_counters_minus_upper_bound (histogram_counters* hist_c, gcov_type_unsigned difference){
-// if (hist_c==NULL || difference==0)
-// return;
-// auto hist=*(hist_c->hist);
-// unsigned int lin_size=param_profile_histogram_size_lin;
-// unsigned int lin_pow2=floor_log2(lin_size-1);
-// unsigned int tot_size=param_profile_histogram_size;
-// gcov_type_unsigned log_diff=floor_log2(difference);
-// unsigned int i=1;
-// for(; i<lin_size-1 && i<tot_size-1; i++){
-// if (i<=difference){
-// hist[0]+=hist[i];
-// } else {
-// hist[i-difference]+=hist[i];
-// }
-// hist[i]=0;
-// }
-// // we try to restore some of the linear histogram
-// // for the last linear counter containing also lesser values then nearest pow2
-// // assumption is uniform
-// gcov_type_unsigned upper_bound_lin=(1<<(ceil_log2(lin_size)-1));
-// if (lin_size>2 && difference<upper_bound_lin && i<tot_size-1){
-// gcov_type_unsigned lin_size_val=hist[lin_size-1]/((upper_bound_lin-1)-(lin_size-2));
-// for (int j=int(i)-int(difference);j<gcov_type(upper_bound_lin)-gcov_type(difference)+1 && j<int(lin_size)-1;i++) {
-// if (j<0) {
-// hist[0]+=lin_size_val;
-// } else {
-// hist[j]+=lin_size_val;
-// }
-// hist[lin_size-1]-=lin_size_val;
-// }
-// i++;
-// }
-// // Index where difference would be placed
-// unsigned diff_index=log_diff+(lin_size-lin_pow2)-1;
-// for (; i<diff_index && difference<lin_size && i<tot_size-1;i++){
-// hist[0]+=hist[i];
-// hist[i]=0;
-// }
-// for (; i<tot_size-1 && (1<<(i-diff_index+2))<10000;i++){
-// // We assume uniform distribution
-// // tot_size -1 should not be touched We know little about it
-// gcov_type_unsigned share=hist[i]/(1<<(i-diff_index+2));
-// hist[i-1]+=share;
-// hist[i]-=share;
-// }
-// }
-//
-// void histogram_counters_div_upper_bound (histogram_counters* hist_c, unsigned int divisor){
-// if (hist_c==NULL || divisor<2)
-// return;
-// auto hist=*(hist_c->hist);
-// unsigned int lin_size=param_profile_histogram_size_lin;
-// unsigned int tot_size=param_profile_histogram_size;
-// gcov_type_unsigned log_div=floor_log2(divisor);
-// unsigned int i=1;
-// for(; i<lin_size-1 && i<tot_size-1; i++){
-// hist[i/divisor]+=hist[i];
-// hist[i]=0;
-// }
-//
-// for (;i<tot_size-1;i++){
-// gcov_type_unsigned upper_diff=((1<<(ceil_log2(lin_size)+i-lin_size))-1)/divisor;
-// if (upper_diff<lin_size-1 && lin_size>1){
-// hist[upper_diff==0 ? 1 : upper_diff]+=hist[i];
-// hist[i]=0;
-// } else {
-// hist[i-log_div>0?i-log_div : 1]+=hist[i];
-// hist[i]=0;
-// }
-// }
-// }
-
typedef class loop *loop_p;
/* An integer estimation of the number of iterations. Estimate_state
diff --git a/gcc/lto-streamer-in.cc b/gcc/lto-streamer-in.cc
index 03cb41cfa16..2cf59858a54 100644
--- a/gcc/lto-streamer-in.cc
+++ b/gcc/lto-streamer-in.cc
@@ -1126,6 +1126,17 @@ input_cfg (class lto_input_block *ib, class data_in *data_in,
loop->any_estimate = streamer_read_hwi (ib);
if (loop->any_estimate)
loop->nb_iterations_estimate = streamer_read_widest_int (ib);
+ // whether the loop has histogram counter
+ if (streamer_read_hwi (ib)){
+ loop->counters=ggc_alloc<histogram_counters>();
+ loop->counters->sum=streamer_read_gcov_count (ib);
+ loop->counters->hist=NULL;
+ vec_safe_grow_cleared(loop->counters->hist,param_profile_histogram_size);
+ for (int i=0;i<param_profile_histogram_size;++i){
+ (*loop->counters->hist)[i]=streamer_read_gcov_count (ib);
+ }
+ }
+
/* Read OMP SIMD related info. */
loop->safelen = streamer_read_hwi (ib);
diff --git a/gcc/lto-streamer-out.cc b/gcc/lto-streamer-out.cc
index 0bca530313c..8901a82dd67 100644
--- a/gcc/lto-streamer-out.cc
+++ b/gcc/lto-streamer-out.cc
@@ -2181,6 +2181,13 @@ output_cfg (struct output_block *ob, struct function *fn)
streamer_write_hwi (ob, loop->any_estimate);
if (loop->any_estimate)
streamer_write_widest_int (ob, loop->nb_iterations_estimate);
+ streamer_write_hwi (ob, loop->counters!=NULL);
+ if (loop->counters) {
+ streamer_write_gcov_count (ob, loop->counters->sum);
+ for (unsigned int i=0; i<param_profile_histogram_size; ++i) {
+ streamer_write_gcov_count (ob, (*loop->counters->hist)[i]);
+ }
+ }
/* Write OMP SIMD related info. */
streamer_write_hwi (ob, loop->safelen);
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 74622aef0f9..cc2ed78b52e 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -11067,13 +11067,8 @@ vect_transform_loop (loop_vec_info loop_vinfo, gimple *loop_vectorized_call)
lowest_vf) - 1
: wi::udiv_floor (loop->nb_iterations_upper_bound + bias_for_lowest,
lowest_vf) - 1);
- if (final_iter_may_be_partial){
- histogram_counters_div_upper_bound(loop->counters,lowest_vf);
- histogram_counters_minus_upper_bound(loop->counters,1);
- } else {
- histogram_counters_div_upper_bound(loop->counters,lowest_vf);
- histogram_counters_minus_upper_bound(loop->counters,1);
- }
+ histogram_counters_div_upper_bound(loop->counters,lowest_vf);
+ histogram_counters_minus_upper_bound(loop->counters,1);
if (main_vinfo
/* Both peeling for alignment and peeling for gaps can end up
with the scalar epilogue running for more than VF-1 iterations. */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-03-14 17:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-14 17:23 [gcc(refs/users/kubaneko/heads/histogram)] some refactoring and added lto-streaming for histograms 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).