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)] fixed memory allocation for histogram_counters
Date: Thu, 23 Feb 2023 23:22:12 +0000 (GMT)	[thread overview]
Message-ID: <20230223232212.8BECA385840F@sourceware.org> (raw)

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

commit bb8a802b8162eef6934e0961acddc24c70b8ed15
Author: kubaneko <kubanek0ondrej@gmail.com>
Date:   Tue Nov 22 13:12:55 2022 +0000

    fixed memory allocation for histogram_counters

Diff:
---
 gcc/cfgloop.cc |  4 ++++
 gcc/cfgloop.h  | 55 ++++++++++++++++---------------------------------------
 gcc/profile.cc |  2 +-
 3 files changed, 21 insertions(+), 40 deletions(-)

diff --git a/gcc/cfgloop.cc b/gcc/cfgloop.cc
index 201893f1624..4293f7d3910 100644
--- a/gcc/cfgloop.cc
+++ b/gcc/cfgloop.cc
@@ -199,6 +199,10 @@ flow_loop_free (class loop *loop)
     }
 
   ggc_free (loop->exits);
+  if (loop->counters)
+    {
+      ggc_free (loop->counters);
+    }
   ggc_free (loop);
 }
 
diff --git a/gcc/cfgloop.h b/gcc/cfgloop.h
index 7b9a854f266..94a18e56e5e 100644
--- a/gcc/cfgloop.h
+++ b/gcc/cfgloop.h
@@ -94,50 +94,27 @@ struct loop_exit_hasher : ggc_ptr_hash<loop_exit>
 
 // Information about histogram of the loop from profiling
 
-struct histogram_counters{
-    gcov_type hist[69];
+struct GTY(()) histogram_counters{
     gcov_type sum;
+    int histogram_size;
+    gcov_type hist[69];
 
     // need to think about overflows
     // quantil function for the distribution
     // returns index under which is koef part of the distribution
-    int quantil(float koef){
-        gcc_assert(0<koef && koef<=1);
-        gcov_type quant=0;
-        int i=0;
-        for (;i<69;++i) {
-            if (quant+hist[i]<koef*sum) {
-                quant+=hist[i];
-            } else {
-                break;
-            }
-        }
-        return i;
-    };
-    // aproximate distribution mean value of the random variable to a power
-    float mean_value(int power){
-        gcov_type values=0;
-        for (int i=0;i<8;i++){
-            gcov_type val=1;
-            for (int j=1; j<=power;j++) {
-                val*=i;
-            }
-            values+=val*hist[i];
-        }
-        for (int i=8;i<69;i++){
-            gcov_type val=1;
-            for (int j=1; j<=power; j++) {
-                val*=1<<(i-5);
-            }
-            values+=val*hist[i];
-        }
-        return ((float)values)/sum;
-    };
-    // returns aproximate variance of the distribution
-    float variance(){
-        float one=mean_value(1);
-        return mean_value(2)-one*one;
-    };
+    // int quantil(float koef){
+    //     gcc_assert(0<koef && koef<=1);
+    //     gcov_type quant=0;
+    //     int i=0;
+    //     for (;i<69;++i) {
+    //         if (quant+hist[i]<koef*sum) {
+    //             quant+=hist[i];
+    //         } else {
+    //             break;
+    //         }
+    //     }
+    //     return i;
+    // };
 };
 
 
diff --git a/gcc/profile.cc b/gcc/profile.cc
index 675ad036e96..6e99a6501c3 100644
--- a/gcc/profile.cc
+++ b/gcc/profile.cc
@@ -928,7 +928,7 @@ compute_value_histograms (histogram_values values, unsigned cfg_checksum,
       {
         auto lp = hist->hvalue.lp;
         if (act_count[t]){
-           lp->counters=(histogram_counters*) xcalloc (1, sizeof (histogram_counters));
+           lp->counters=ggc_alloc<histogram_counters>();
            gcov_type sum=0;
            for (int i=0;i<69;++i){
                lp->counters->hist[i]=act_count[t][i];

             reply	other threads:[~2023-02-23 23:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-23 23:22 Ondrej Kubanek [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-02-16 16:28 Ondrej Kubanek
2022-11-22 13:14 Ondrej Kubanek

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=20230223232212.8BECA385840F@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).