1240616Sjimharris/* Definitions for transformations based on profile information for values.
2253112Sjimharris   Copyright (C) 2003-2020 Free Software Foundation, Inc.
3240616Sjimharris
4240616SjimharrisThis file is part of GCC.
5240616Sjimharris
6240616SjimharrisGCC is free software; you can redistribute it and/or modify it under
7240616Sjimharristhe terms of the GNU General Public License as published by the Free
8240616SjimharrisSoftware Foundation; either version 3, or (at your option) any later
9240616Sjimharrisversion.
10240616Sjimharris
11240616SjimharrisGCC is distributed in the hope that it will be useful, but WITHOUT ANY
12240616SjimharrisWARRANTY; without even the implied warranty of MERCHANTABILITY or
13240616SjimharrisFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14240616Sjimharrisfor more details.
15240616Sjimharris
16240616SjimharrisYou should have received a copy of the GNU General Public License
17240616Sjimharrisalong with GCC; see the file COPYING3.  If not see
18240616Sjimharris<http://www.gnu.org/licenses/>.  */
19240616Sjimharris
20240616Sjimharris#ifndef GCC_VALUE_PROF_H
21240616Sjimharris#define GCC_VALUE_PROF_H
22240616Sjimharris
23240616Sjimharris/* Supported histogram types.  */
24240616Sjimharrisenum hist_type
25240616Sjimharris{
26240616Sjimharris  HIST_TYPE_INTERVAL,	/* Measures histogram of values inside a specified
27240616Sjimharris			   interval.  */
28240616Sjimharris  HIST_TYPE_POW2,	/* Histogram of power of 2 values.  */
29240616Sjimharris  HIST_TYPE_TOPN_VALUES, /* Tries to identify the N most common values.  */
30240616Sjimharris  HIST_TYPE_INDIR_CALL,   /* Tries to identify the function that is (almost)
31240616Sjimharris			    called in indirect call */
32240616Sjimharris  HIST_TYPE_AVERAGE,	/* Compute average value (sum of all values).  */
33240616Sjimharris  HIST_TYPE_IOR,	/* Used to compute expected alignment.  */
34240616Sjimharris  HIST_TYPE_TIME_PROFILE, /* Used for time profile */
35240616Sjimharris  HIST_TYPE_MAX
36240616Sjimharris};
37240616Sjimharris
38240616Sjimharris#define COUNTER_FOR_HIST_TYPE(TYPE) ((int) (TYPE) + GCOV_FIRST_VALUE_COUNTER)
39240616Sjimharris#define HIST_TYPE_FOR_COUNTER(COUNTER) \
40240616Sjimharris  ((enum hist_type) ((COUNTER) - GCOV_FIRST_VALUE_COUNTER))
41240616Sjimharris
42240616Sjimharris
43240616Sjimharris/* The value to measure.  */
44240616Sjimharrisstruct histogram_value_t
45240616Sjimharris{
46240616Sjimharris  struct
47240616Sjimharris    {
48240616Sjimharris      tree value;		/* The value to profile.  */
49240616Sjimharris      gimple *stmt;		/* Insn containing the value.  */
50240616Sjimharris      gcov_type *counters;		        /* Pointer to first counter.  */
51240616Sjimharris      struct histogram_value_t *next;		/* Linked list pointer.  */
52240616Sjimharris    } hvalue;
53240616Sjimharris  enum hist_type type;			/* Type of information to measure.  */
54240616Sjimharris  unsigned n_counters;			/* Number of required counters.  */
55240616Sjimharris  struct function *fun;
56256152Sjimharris  union
57240616Sjimharris    {
58240616Sjimharris      struct
59240616Sjimharris	{
60240616Sjimharris	  int int_start;	/* First value in interval.  */
61240616Sjimharris	  unsigned int steps;	/* Number of values in it.  */
62240616Sjimharris	} intvl;	/* Interval histogram data.  */
63240616Sjimharris    } hdata;		/* Profiled information specific data.  */
64240616Sjimharris};
65240616Sjimharris
66240616Sjimharristypedef struct histogram_value_t *histogram_value;
67240616Sjimharristypedef const struct histogram_value_t *const_histogram_value;
68240616Sjimharris
69256152Sjimharris
70240616Sjimharristypedef vec<histogram_value> histogram_values;
71240616Sjimharris
72240616Sjimharrisextern void gimple_find_values_to_profile (histogram_values *);
73240616Sjimharrisextern bool gimple_value_profile_transformations (void);
74240616Sjimharris
75240616Sjimharrishistogram_value gimple_alloc_histogram_value (struct function *, enum hist_type,
76240616Sjimharris					      gimple *stmt = NULL,
77240616Sjimharris					      tree value = NULL_TREE);
78240616Sjimharrishistogram_value gimple_histogram_value (struct function *, gimple *);
79240616Sjimharrishistogram_value gimple_histogram_value_of_type (struct function *, gimple *,
80240616Sjimharris						enum hist_type);
81240616Sjimharrisvoid gimple_add_histogram_value (struct function *, gimple *, histogram_value);
82240616Sjimharrisvoid dump_histograms_for_stmt (struct function *, FILE *, gimple *);
83240616Sjimharrisvoid gimple_remove_histogram_value (struct function *, gimple *, histogram_value);
84240616Sjimharrisvoid gimple_remove_stmt_histograms (struct function *, gimple *);
85240616Sjimharrisvoid gimple_duplicate_stmt_histograms (struct function *, gimple *,
86240616Sjimharris				       struct function *, gimple *);
87240616Sjimharrisvoid gimple_move_stmt_histograms (struct function *, gimple *, gimple *);
88240616Sjimharrisvoid verify_histograms (void);
89240616Sjimharrisvoid free_histograms (function *);
90240616Sjimharrisvoid stringop_block_profile (gimple *, unsigned int *, HOST_WIDE_INT *);
91240616Sjimharrisgcall *gimple_ic (gcall *, struct cgraph_node *, profile_probability);
92240616Sjimharrisbool get_nth_most_common_value (gimple *stmt, const char *counter_type,
93256152Sjimharris				histogram_value hist, gcov_type *value,
94256152Sjimharris				gcov_type *count, gcov_type *all,
95240616Sjimharris				unsigned n = 0);
96240616Sjimharris
97240616Sjimharris/* In tree-profile.c.  */
98240616Sjimharrisextern void gimple_init_gcov_profiler (void);
99248770Sjimharrisextern void gimple_gen_edge_profiler (int, edge);
100240616Sjimharrisextern void gimple_gen_interval_profiler (histogram_value, unsigned);
101240616Sjimharrisextern void gimple_gen_pow2_profiler (histogram_value, unsigned);
102240616Sjimharrisextern void gimple_gen_topn_values_profiler (histogram_value, unsigned);
103240616Sjimharrisextern void gimple_gen_ic_profiler (histogram_value, unsigned);
104240616Sjimharrisextern void gimple_gen_ic_func_profiler (void);
105240616Sjimharrisextern void gimple_gen_time_profiler (unsigned);
106240616Sjimharrisextern void gimple_gen_average_profiler (histogram_value, unsigned);
107240616Sjimharrisextern void gimple_gen_ior_profiler (histogram_value, unsigned);
108240616Sjimharrisextern void stream_out_histogram_value (struct output_block *, histogram_value);
109240616Sjimharrisextern void stream_in_histogram_value (class lto_input_block *, gimple *);
110240616Sjimharrisextern struct cgraph_node* find_func_by_profile_id (int func_id);
111240616Sjimharris
112240616Sjimharris
113240616Sjimharris/* In profile.c.  */
114240616Sjimharrisextern void init_branch_prob (void);
115240616Sjimharrisextern void branch_prob (bool);
116240616Sjimharrisextern void read_thunk_profile (struct cgraph_node *);
117240616Sjimharrisextern void end_branch_prob (void);
118240616Sjimharris
119240616Sjimharris#endif	/* GCC_VALUE_PROF_H */
120240616Sjimharris
121240616Sjimharris