08f4d0043e3e96870e5ead3ecd2965a98295de9c
[gcc.git] / gcc / value-prof.h
1 /* Definitions for transformations based on profile information for values.
2 Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA. */
20
21 #ifndef GCC_VALUE_PROF_H
22 #define GCC_VALUE_PROF_H
23
24 /* Supported histogram types. */
25 enum hist_type
26 {
27 HIST_TYPE_INTERVAL, /* Measures histogram of values inside a specified
28 interval. */
29 HIST_TYPE_POW2, /* Histogram of power of 2 values. */
30 HIST_TYPE_SINGLE_VALUE, /* Tries to identify the value that is (almost)
31 always constant. */
32 HIST_TYPE_CONST_DELTA /* Tries to identify the (almost) always constant
33 difference between two evaluations of a value. */
34 };
35
36 #define COUNTER_FOR_HIST_TYPE(TYPE) ((int) (TYPE) + GCOV_FIRST_VALUE_COUNTER)
37 #define HIST_TYPE_FOR_COUNTER(COUNTER) \
38 ((enum hist_type) ((COUNTER) - GCOV_FIRST_VALUE_COUNTER))
39
40 /* The value to measure. */
41 struct histogram_value_t
42 {
43 union
44 {
45 struct
46 {
47 rtx value; /* The value to profile. */
48 rtx seq; /* Insns required to count the profiled value. */
49 rtx insn; /* Insn before that to measure. */
50 enum machine_mode mode; /* Mode of value to profile. */
51 } rtl;
52 struct
53 {
54 tree value; /* The value to profile. */
55 tree stmt; /* Insn containing the value. */
56 gcov_type *counters; /* Pointer to first counter. */
57 struct histogram_value_t *next; /* Linked list pointer. */
58 } tree;
59 } hvalue;
60 enum hist_type type; /* Type of information to measure. */
61 unsigned n_counters; /* Number of required counters. */
62 union
63 {
64 struct
65 {
66 int int_start; /* First value in interval. */
67 unsigned int steps; /* Number of values in it. */
68 } intvl; /* Interval histogram data. */
69 struct
70 {
71 int may_be_other; /* If the value may be non-positive or not 2^k. */
72 } pow2; /* Power of 2 histogram data. */
73 } hdata; /* Profiled information specific data. */
74 };
75
76 typedef struct histogram_value_t *histogram_value;
77
78 DEF_VEC_MALLOC_P(histogram_value);
79
80 typedef VEC(histogram_value) *histogram_values;
81
82 /* Hooks registration. */
83 extern void rtl_register_value_prof_hooks (void);
84 extern void tree_register_value_prof_hooks (void);
85
86 /* IR-independent entry points. */
87 extern void find_values_to_profile (histogram_values *);
88 extern bool value_profile_transformations (void);
89 \f
90 /* External declarations for edge-based profiling. */
91 struct profile_hooks {
92
93 /* Insert code to initialize edge profiler. */
94 void (*init_edge_profiler) (void);
95
96 /* Insert code to increment an edge count. */
97 void (*gen_edge_profiler) (int, edge);
98
99 /* Insert code to increment the interval histogram counter. */
100 void (*gen_interval_profiler) (histogram_value, unsigned, unsigned);
101
102 /* Insert code to increment the power of two histogram counter. */
103 void (*gen_pow2_profiler) (histogram_value, unsigned, unsigned);
104
105 /* Insert code to find the most common value. */
106 void (*gen_one_value_profiler) (histogram_value, unsigned, unsigned);
107
108 /* Insert code to find the most common value of a difference between two
109 evaluations of an expression. */
110 void (*gen_const_delta_profiler) (histogram_value, unsigned, unsigned);
111 FILE * (*profile_dump_file) (void);
112 };
113
114 /* In profile.c. */
115 extern void init_branch_prob (void);
116 extern void branch_prob (void);
117 extern void end_branch_prob (void);
118 extern void tree_register_profile_hooks (void);
119 extern void rtl_register_profile_hooks (void);
120
121 /* In tree-profile.c. */
122 extern struct profile_hooks tree_profile_hooks;
123
124 /* In rtl-profile.c. */
125 extern struct profile_hooks rtl_profile_hooks;
126
127 #endif /* GCC_VALUE_PROF_H */
128