xref: /dragonfly/contrib/gcc-8.0/gcc/value-prof.h (revision 58e805e6)
138fd1498Szrj /* Definitions for transformations based on profile information for values.
238fd1498Szrj    Copyright (C) 2003-2018 Free Software Foundation, Inc.
338fd1498Szrj 
438fd1498Szrj This file is part of GCC.
538fd1498Szrj 
638fd1498Szrj GCC is free software; you can redistribute it and/or modify it under
738fd1498Szrj the terms of the GNU General Public License as published by the Free
838fd1498Szrj Software Foundation; either version 3, or (at your option) any later
938fd1498Szrj version.
1038fd1498Szrj 
1138fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY
1238fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or
1338fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1438fd1498Szrj for more details.
1538fd1498Szrj 
1638fd1498Szrj You should have received a copy of the GNU General Public License
1738fd1498Szrj along with GCC; see the file COPYING3.  If not see
1838fd1498Szrj <http://www.gnu.org/licenses/>.  */
1938fd1498Szrj 
2038fd1498Szrj #ifndef GCC_VALUE_PROF_H
2138fd1498Szrj #define GCC_VALUE_PROF_H
2238fd1498Szrj 
2338fd1498Szrj /* Supported histogram types.  */
2438fd1498Szrj enum hist_type
2538fd1498Szrj {
2638fd1498Szrj   HIST_TYPE_INTERVAL,	/* Measures histogram of values inside a specified
2738fd1498Szrj 			   interval.  */
2838fd1498Szrj   HIST_TYPE_POW2,	/* Histogram of power of 2 values.  */
2938fd1498Szrj   HIST_TYPE_SINGLE_VALUE, /* Tries to identify the value that is (almost)
3038fd1498Szrj 			   always constant.  */
3138fd1498Szrj   HIST_TYPE_INDIR_CALL,   /* Tries to identify the function that is (almost)
3238fd1498Szrj 			    called in indirect call */
3338fd1498Szrj   HIST_TYPE_AVERAGE,	/* Compute average value (sum of all values).  */
3438fd1498Szrj   HIST_TYPE_IOR,	/* Used to compute expected alignment.  */
3538fd1498Szrj   HIST_TYPE_TIME_PROFILE, /* Used for time profile */
3638fd1498Szrj   HIST_TYPE_INDIR_CALL_TOPN, /* Tries to identify the top N most frequently
3738fd1498Szrj                                 called functions in indirect call.  */
3838fd1498Szrj   HIST_TYPE_MAX
3938fd1498Szrj };
4038fd1498Szrj 
4138fd1498Szrj #define COUNTER_FOR_HIST_TYPE(TYPE) ((int) (TYPE) + GCOV_FIRST_VALUE_COUNTER)
4238fd1498Szrj #define HIST_TYPE_FOR_COUNTER(COUNTER) \
4338fd1498Szrj   ((enum hist_type) ((COUNTER) - GCOV_FIRST_VALUE_COUNTER))
4438fd1498Szrj 
4538fd1498Szrj 
4638fd1498Szrj /* The value to measure.  */
4738fd1498Szrj struct histogram_value_t
4838fd1498Szrj {
4938fd1498Szrj   struct
5038fd1498Szrj     {
5138fd1498Szrj       tree value;		/* The value to profile.  */
5238fd1498Szrj       gimple *stmt;		/* Insn containing the value.  */
5338fd1498Szrj       gcov_type *counters;		        /* Pointer to first counter.  */
5438fd1498Szrj       struct histogram_value_t *next;		/* Linked list pointer.  */
5538fd1498Szrj     } hvalue;
5638fd1498Szrj   enum hist_type type;			/* Type of information to measure.  */
5738fd1498Szrj   unsigned n_counters;			/* Number of required counters.  */
5838fd1498Szrj   struct function *fun;
5938fd1498Szrj   union
6038fd1498Szrj     {
6138fd1498Szrj       struct
6238fd1498Szrj 	{
6338fd1498Szrj 	  int int_start;	/* First value in interval.  */
6438fd1498Szrj 	  unsigned int steps;	/* Number of values in it.  */
6538fd1498Szrj 	} intvl;	/* Interval histogram data.  */
6638fd1498Szrj     } hdata;		/* Profiled information specific data.  */
6738fd1498Szrj };
6838fd1498Szrj 
6938fd1498Szrj typedef struct histogram_value_t *histogram_value;
7038fd1498Szrj typedef const struct histogram_value_t *const_histogram_value;
7138fd1498Szrj 
7238fd1498Szrj 
7338fd1498Szrj typedef vec<histogram_value> histogram_values;
7438fd1498Szrj 
7538fd1498Szrj extern void gimple_find_values_to_profile (histogram_values *);
7638fd1498Szrj extern bool gimple_value_profile_transformations (void);
7738fd1498Szrj 
7838fd1498Szrj histogram_value gimple_alloc_histogram_value (struct function *, enum hist_type,
7938fd1498Szrj 					      gimple *stmt, tree);
8038fd1498Szrj histogram_value gimple_histogram_value (struct function *, gimple *);
8138fd1498Szrj histogram_value gimple_histogram_value_of_type (struct function *, gimple *,
8238fd1498Szrj 						enum hist_type);
8338fd1498Szrj void gimple_add_histogram_value (struct function *, gimple *, histogram_value);
8438fd1498Szrj void dump_histograms_for_stmt (struct function *, FILE *, gimple *);
8538fd1498Szrj void gimple_remove_histogram_value (struct function *, gimple *, histogram_value);
8638fd1498Szrj void gimple_remove_stmt_histograms (struct function *, gimple *);
8738fd1498Szrj void gimple_duplicate_stmt_histograms (struct function *, gimple *,
8838fd1498Szrj 				       struct function *, gimple *);
8938fd1498Szrj void gimple_move_stmt_histograms (struct function *, gimple *, gimple *);
9038fd1498Szrj void verify_histograms (void);
9138fd1498Szrj void free_histograms (function *);
9238fd1498Szrj void stringop_block_profile (gimple *, unsigned int *, HOST_WIDE_INT *);
9338fd1498Szrj gcall *gimple_ic (gcall *, struct cgraph_node *, profile_probability);
9438fd1498Szrj bool check_ic_target (gcall *, struct cgraph_node *);
9538fd1498Szrj 
9638fd1498Szrj 
9738fd1498Szrj /* In tree-profile.c.  */
9838fd1498Szrj extern void gimple_init_gcov_profiler (void);
9938fd1498Szrj extern void gimple_gen_edge_profiler (int, edge);
10038fd1498Szrj extern void gimple_gen_interval_profiler (histogram_value, unsigned, unsigned);
10138fd1498Szrj extern void gimple_gen_pow2_profiler (histogram_value, unsigned, unsigned);
10238fd1498Szrj extern void gimple_gen_one_value_profiler (histogram_value, unsigned, unsigned);
10338fd1498Szrj extern void gimple_gen_ic_profiler (histogram_value, unsigned, unsigned);
10438fd1498Szrj extern void gimple_gen_ic_func_profiler (void);
10538fd1498Szrj extern void gimple_gen_time_profiler (unsigned, unsigned);
10638fd1498Szrj extern void gimple_gen_average_profiler (histogram_value, unsigned, unsigned);
10738fd1498Szrj extern void gimple_gen_ior_profiler (histogram_value, unsigned, unsigned);
10838fd1498Szrj extern void stream_out_histogram_value (struct output_block *, histogram_value);
10938fd1498Szrj extern void stream_in_histogram_value (struct lto_input_block *, gimple *);
11038fd1498Szrj extern struct cgraph_node* find_func_by_profile_id (int func_id);
11138fd1498Szrj 
11238fd1498Szrj 
11338fd1498Szrj /* In profile.c.  */
11438fd1498Szrj extern void init_branch_prob (void);
115*58e805e6Szrj extern void branch_prob (bool);
116*58e805e6Szrj extern void read_thunk_profile (struct cgraph_node *);
11738fd1498Szrj extern void end_branch_prob (void);
11838fd1498Szrj 
11938fd1498Szrj #endif	/* GCC_VALUE_PROF_H */
12038fd1498Szrj 
121