OSDN Git Service

2007-01-24 Andreas Tobler <a.tobler@schweiz.org>
[pf3gnuchains/gcc-fork.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, 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, 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   HIST_TYPE_INDIR_CALL   /* Tries to identify the function that is (almost) 
35                             called in indirect call */
36 };
37
38 #define COUNTER_FOR_HIST_TYPE(TYPE) ((int) (TYPE) + GCOV_FIRST_VALUE_COUNTER)
39 #define HIST_TYPE_FOR_COUNTER(COUNTER) \
40   ((enum hist_type) ((COUNTER) - GCOV_FIRST_VALUE_COUNTER))
41
42 /* The value to measure.  */
43 struct histogram_value_t
44 {
45   struct
46     {
47       tree value;               /* The value to profile.  */
48       tree stmt;                /* Insn containing the value.  */
49       gcov_type *counters;                      /* Pointer to first counter.  */
50       struct histogram_value_t *next;           /* Linked list pointer.  */
51     } hvalue;
52   enum hist_type type;                  /* Type of information to measure.  */
53   unsigned n_counters;                  /* Number of required counters.  */
54   union
55     {
56       struct
57         {
58           int int_start;        /* First value in interval.  */
59           unsigned int steps;   /* Number of values in it.  */
60         } intvl;        /* Interval histogram data.  */
61     } hdata;            /* Profiled information specific data.  */
62 };
63
64 typedef struct histogram_value_t *histogram_value;
65
66 DEF_VEC_P(histogram_value);
67 DEF_VEC_ALLOC_P(histogram_value,heap);
68
69 typedef VEC(histogram_value,heap) *histogram_values;
70
71 /* Hooks registration.  */
72 extern void tree_register_value_prof_hooks (void);
73
74 /* IR-independent entry points.  */
75 extern void find_values_to_profile (histogram_values *);
76 extern bool value_profile_transformations (void);
77 \f
78 /* External declarations for edge-based profiling.  */
79 struct profile_hooks {
80
81   /* Insert code to initialize edge profiler.  */
82   void (*init_edge_profiler) (void);
83
84   /* Insert code to increment an edge count.  */
85   void (*gen_edge_profiler) (int, edge);
86
87   /* Insert code to increment the interval histogram counter.  */
88   void (*gen_interval_profiler) (histogram_value, unsigned, unsigned);
89
90   /* Insert code to increment the power of two histogram counter.  */
91   void (*gen_pow2_profiler) (histogram_value, unsigned, unsigned);
92
93   /* Insert code to find the most common value.  */
94   void (*gen_one_value_profiler) (histogram_value, unsigned, unsigned);
95
96   /* Insert code to find the most common value of a difference between two
97      evaluations of an expression.  */
98   void (*gen_const_delta_profiler) (histogram_value, unsigned, unsigned);
99
100   /* Insert code to find the most common indirect call */
101   void (*gen_ic_profiler) (histogram_value, unsigned, unsigned);
102 };
103
104 histogram_value gimple_histogram_value (struct function *, tree);
105 histogram_value gimple_histogram_value_of_type (struct function *, tree, enum hist_type);
106 void gimple_add_histogram_value (struct function *, tree, histogram_value);
107 void gimple_remove_histogram_value (struct function *, tree, histogram_value);
108 void dump_histograms_for_stmt (struct function *, FILE *, tree);
109 void gimple_remove_histogram_value (struct function *, tree, histogram_value);
110 void gimple_remove_stmt_histograms (struct function *, tree);
111 void gimple_duplicate_stmt_histograms (struct function *, tree, struct function *, tree);
112 void verify_histograms (void);
113 void free_histograms (void);
114
115 /* In profile.c.  */
116 extern void init_branch_prob (void);
117 extern void branch_prob (void);
118 extern void end_branch_prob (void);
119 extern void tree_register_profile_hooks (void);
120
121 /* In tree-profile.c.  */
122 extern struct profile_hooks tree_profile_hooks;
123
124 #endif  /* GCC_VALUE_PROF_H */
125