1125733Sgrehan/* Definitions for transformations based on profile information for values.
2125733Sgrehan   Copyright (C) 2003-2015 Free Software Foundation, Inc.
3125733Sgrehan
4125733SgrehanThis file is part of GCC.
5125733Sgrehan
6125733SgrehanGCC is free software; you can redistribute it and/or modify it under
7125733Sgrehanthe terms of the GNU General Public License as published by the Free
8125733SgrehanSoftware Foundation; either version 3, or (at your option) any later
9125733Sgrehanversion.
10125733Sgrehan
11125733SgrehanGCC is distributed in the hope that it will be useful, but WITHOUT ANY
12125733SgrehanWARRANTY; without even the implied warranty of MERCHANTABILITY or
13125733SgrehanFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14125733Sgrehanfor more details.
15125733Sgrehan
16125733SgrehanYou should have received a copy of the GNU General Public License
17125733Sgrehanalong with GCC; see the file COPYING3.  If not see
18125733Sgrehan<http://www.gnu.org/licenses/>.  */
19125733Sgrehan
20125733Sgrehan#ifndef GCC_VALUE_PROF_H
21125733Sgrehan#define GCC_VALUE_PROF_H
22125733Sgrehan
23125733Sgrehan/* Supported histogram types.  */
24125733Sgrehanenum hist_type
25125733Sgrehan{
26125733Sgrehan  HIST_TYPE_INTERVAL,	/* Measures histogram of values inside a specified
27125733Sgrehan			   interval.  */
28125733Sgrehan  HIST_TYPE_POW2,	/* Histogram of power of 2 values.  */
29125733Sgrehan  HIST_TYPE_SINGLE_VALUE, /* Tries to identify the value that is (almost)
30125733Sgrehan			   always constant.  */
31125733Sgrehan  HIST_TYPE_CONST_DELTA, /* Tries to identify the (almost) always constant
32125733Sgrehan			   difference between two evaluations of a value.  */
33125733Sgrehan  HIST_TYPE_INDIR_CALL,   /* Tries to identify the function that is (almost)
34125733Sgrehan			    called in indirect call */
35125733Sgrehan  HIST_TYPE_AVERAGE,	/* Compute average value (sum of all values).  */
36125733Sgrehan  HIST_TYPE_IOR,	/* Used to compute expected alignment.  */
37125733Sgrehan  HIST_TYPE_TIME_PROFILE, /* Used for time profile */
38125733Sgrehan  HIST_TYPE_INDIR_CALL_TOPN, /* Tries to identify the top N most frequently
39125733Sgrehan                                called functions in indirect call.  */
40125733Sgrehan  HIST_TYPE_MAX
41125733Sgrehan};
42125733Sgrehan
43125733Sgrehan#define COUNTER_FOR_HIST_TYPE(TYPE) ((int) (TYPE) + GCOV_FIRST_VALUE_COUNTER)
44125733Sgrehan#define HIST_TYPE_FOR_COUNTER(COUNTER) \
45125733Sgrehan  ((enum hist_type) ((COUNTER) - GCOV_FIRST_VALUE_COUNTER))
46125733Sgrehan
47125733Sgrehan
48125733Sgrehan/* The value to measure.  */
49125733Sgrehanstruct histogram_value_t
50125733Sgrehan{
51125733Sgrehan  struct
52125733Sgrehan    {
53125733Sgrehan      tree value;		/* The value to profile.  */
54125733Sgrehan      gimple stmt;		/* Insn containing the value.  */
55125733Sgrehan      gcov_type *counters;		        /* Pointer to first counter.  */
56125733Sgrehan      struct histogram_value_t *next;		/* Linked list pointer.  */
57125733Sgrehan    } hvalue;
58  enum hist_type type;			/* Type of information to measure.  */
59  unsigned n_counters;			/* Number of required counters.  */
60  struct function *fun;
61  union
62    {
63      struct
64	{
65	  int int_start;	/* First value in interval.  */
66	  unsigned int steps;	/* Number of values in it.  */
67	} intvl;	/* Interval histogram data.  */
68    } hdata;		/* Profiled information specific data.  */
69};
70
71typedef struct histogram_value_t *histogram_value;
72typedef const struct histogram_value_t *const_histogram_value;
73
74
75typedef vec<histogram_value> histogram_values;
76
77extern void gimple_find_values_to_profile (histogram_values *);
78extern bool gimple_value_profile_transformations (void);
79
80histogram_value gimple_alloc_histogram_value (struct function *, enum hist_type,
81					      gimple stmt, tree);
82histogram_value gimple_histogram_value (struct function *, gimple);
83histogram_value gimple_histogram_value_of_type (struct function *, gimple,
84						enum hist_type);
85void gimple_add_histogram_value (struct function *, gimple, histogram_value);
86void dump_histograms_for_stmt (struct function *, FILE *, gimple);
87void gimple_remove_histogram_value (struct function *, gimple, histogram_value);
88void gimple_remove_stmt_histograms (struct function *, gimple);
89void gimple_duplicate_stmt_histograms (struct function *, gimple,
90				       struct function *, gimple);
91void gimple_move_stmt_histograms (struct function *, gimple, gimple);
92void verify_histograms (void);
93void free_histograms (void);
94void stringop_block_profile (gimple, unsigned int *, HOST_WIDE_INT *);
95gcall *gimple_ic (gcall *, struct cgraph_node *, int, gcov_type,
96		  gcov_type);
97bool check_ic_target (gcall *, struct cgraph_node *);
98
99
100/* In tree-profile.c.  */
101extern void gimple_init_edge_profiler (void);
102extern void gimple_gen_edge_profiler (int, edge);
103extern void gimple_gen_interval_profiler (histogram_value, unsigned, unsigned);
104extern void gimple_gen_pow2_profiler (histogram_value, unsigned, unsigned);
105extern void gimple_gen_one_value_profiler (histogram_value, unsigned, unsigned);
106extern void gimple_gen_ic_profiler (histogram_value, unsigned, unsigned);
107extern void gimple_gen_ic_func_profiler (void);
108extern void gimple_gen_time_profiler (unsigned, unsigned,
109                                      gimple_stmt_iterator &);
110extern void gimple_gen_const_delta_profiler (histogram_value,
111					     unsigned, unsigned);
112extern void gimple_gen_average_profiler (histogram_value, unsigned, unsigned);
113extern void gimple_gen_ior_profiler (histogram_value, unsigned, unsigned);
114extern void stream_out_histogram_value (struct output_block *, histogram_value);
115extern void stream_in_histogram_value (struct lto_input_block *, gimple);
116extern struct cgraph_node* find_func_by_profile_id (int func_id);
117
118
119/* In profile.c.  */
120extern void init_branch_prob (void);
121extern void branch_prob (void);
122extern void end_branch_prob (void);
123
124#endif	/* GCC_VALUE_PROF_H */
125
126