Generalize get_most_common_single_value to return k_th value & count
diff mbox series

Message ID 20190715024211.114554-1-luoxhu@linux.ibm.com
State New
Headers show
Series
  • Generalize get_most_common_single_value to return k_th value & count
Related show

Commit Message

luoxhu July 15, 2019, 2:42 a.m. UTC
Currently get_most_common_single_value could only return the max hist
<value, count>, add two paramter to enable this function return kth
value if needed.

gcc/ChangeLog:

	2019-07-15  Xiong Hu Luo  <luoxhu@linux.ibm.com>

	* value-prof.c (get_most_common_single_value): Add input params
	k_th and k, return the k_th <value, count> if k_th is true.
	* value-prof.h (get_most_common_single_value): Add input params
	k_th and k, default to false.
---
 gcc/value-prof.c | 16 ++++++++++++----
 gcc/value-prof.h |  7 +++----
 2 files changed, 15 insertions(+), 8 deletions(-)

Comments

Martin Liška July 15, 2019, 6:50 a.m. UTC | #1
On 7/15/19 4:42 AM, Xiong Hu Luo wrote:
> Currently get_most_common_single_value could only return the max hist
> <value, count>, add two paramter to enable this function return kth
> value if needed.
> 
> gcc/ChangeLog:
> 
> 	2019-07-15  Xiong Hu Luo  <luoxhu@linux.ibm.com>
> 
> 	* value-prof.c (get_most_common_single_value): Add input params
> 	k_th and k, return the k_th <value, count> if k_th is true.
> 	* value-prof.h (get_most_common_single_value): Add input params
> 	k_th and k, default to false.
> ---
>  gcc/value-prof.c | 16 ++++++++++++----
>  gcc/value-prof.h |  7 +++----
>  2 files changed, 15 insertions(+), 8 deletions(-)
> 
> diff --git a/gcc/value-prof.c b/gcc/value-prof.c
> index 32e6ddd8165..e1a3e0bd4b5 100644
> --- a/gcc/value-prof.c
> +++ b/gcc/value-prof.c
> @@ -719,9 +719,9 @@ gimple_divmod_fixed_value (gassign *stmt, tree value, profile_probability prob,
>  
>  bool
>  get_most_common_single_value (gimple *stmt, const char *counter_type,

Hi.

I would rename the function as it's not going to return only the most common value.

> -			      histogram_value hist,
> -			      gcov_type *value, gcov_type *count,
> -			      gcov_type *all)
> +			      histogram_value hist, gcov_type *value,
> +			      gcov_type *count, gcov_type *all, bool k_th,
> +			      unsigned k)
>  {
>    if (hist->hvalue.counters[2] == -1)
>      return false;
> @@ -743,7 +743,15 @@ get_most_common_single_value (gimple *stmt, const char *counter_type,
>  
>        *all = read_all;
>  
> -      if (c > *count)
> +      /* Return the kth value in hist instead of the max value for indirect
> +	 multiple call usage.  */
> +      if (k_th && i == k)

This is probably wrong as the tuples in a histogram are not sorted by count. I would recommend
to sort them when we read them. And then this function can be quite simple to return N-th tuple.

Thanks,
Martin

> +	{
> +	  *value = v;
> +	  *count = c;
> +	  break;
> +      }
> +      else if (c > *count)
>  	{
>  	  *value = v;
>  	  *count = c;
> diff --git a/gcc/value-prof.h b/gcc/value-prof.h
> index ca846d08cbd..0a064a71f7d 100644
> --- a/gcc/value-prof.h
> +++ b/gcc/value-prof.h
> @@ -90,10 +90,9 @@ void stringop_block_profile (gimple *, unsigned int *, HOST_WIDE_INT *);
>  gcall *gimple_ic (gcall *, struct cgraph_node *, profile_probability);
>  bool check_ic_target (gcall *, struct cgraph_node *);
>  bool get_most_common_single_value (gimple *stmt, const char *counter_type,
> -				   histogram_value hist,
> -				   gcov_type *value, gcov_type *count,
> -				   gcov_type *all);
> -
> +				   histogram_value hist, gcov_type *value,
> +				   gcov_type *count, gcov_type *all,
> +				   bool k_th = false, unsigned k = 0);
>  
>  /* In tree-profile.c.  */
>  extern void gimple_init_gcov_profiler (void);
>

Patch
diff mbox series

diff --git a/gcc/value-prof.c b/gcc/value-prof.c
index 32e6ddd8165..e1a3e0bd4b5 100644
--- a/gcc/value-prof.c
+++ b/gcc/value-prof.c
@@ -719,9 +719,9 @@  gimple_divmod_fixed_value (gassign *stmt, tree value, profile_probability prob,
 
 bool
 get_most_common_single_value (gimple *stmt, const char *counter_type,
-			      histogram_value hist,
-			      gcov_type *value, gcov_type *count,
-			      gcov_type *all)
+			      histogram_value hist, gcov_type *value,
+			      gcov_type *count, gcov_type *all, bool k_th,
+			      unsigned k)
 {
   if (hist->hvalue.counters[2] == -1)
     return false;
@@ -743,7 +743,15 @@  get_most_common_single_value (gimple *stmt, const char *counter_type,
 
       *all = read_all;
 
-      if (c > *count)
+      /* Return the kth value in hist instead of the max value for indirect
+	 multiple call usage.  */
+      if (k_th && i == k)
+	{
+	  *value = v;
+	  *count = c;
+	  break;
+      }
+      else if (c > *count)
 	{
 	  *value = v;
 	  *count = c;
diff --git a/gcc/value-prof.h b/gcc/value-prof.h
index ca846d08cbd..0a064a71f7d 100644
--- a/gcc/value-prof.h
+++ b/gcc/value-prof.h
@@ -90,10 +90,9 @@  void stringop_block_profile (gimple *, unsigned int *, HOST_WIDE_INT *);
 gcall *gimple_ic (gcall *, struct cgraph_node *, profile_probability);
 bool check_ic_target (gcall *, struct cgraph_node *);
 bool get_most_common_single_value (gimple *stmt, const char *counter_type,
-				   histogram_value hist,
-				   gcov_type *value, gcov_type *count,
-				   gcov_type *all);
-
+				   histogram_value hist, gcov_type *value,
+				   gcov_type *count, gcov_type *all,
+				   bool k_th = false, unsigned k = 0);
 
 /* In tree-profile.c.  */
 extern void gimple_init_gcov_profiler (void);