OSDN Git Service

2003-09-19 Joel Sherrill <joel@oarcorp.com>
[pf3gnuchains/gcc-fork.git] / gcc / value-prof.c
1 /* Transformations based on profile information for values.
2    Copyright (C) 2003 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 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "rtl.h"
26 #include "expr.h"
27 #include "hard-reg-set.h"
28 #include "basic-block.h"
29 #include "value-prof.h"
30 #include "output.h"
31 #include "flags.h"
32 #include "insn-config.h"
33 #include "recog.h"
34 #include "optabs.h"
35
36 /* In this file value profile based optimizations will be placed (none are
37    here just now, but they are hopefully coming soon).
38
39    Every such optimization should add its requirements for profiled values to
40    insn_values_to_profile function.  This function is called from branch_prob
41    in profile.c and the requested values are instrumented by it in the first
42    compilation with -fprofile-arcs.  The optimization may then read the
43    gathered data in the second compilation with -fbranch-probabilities.
44    The measured data is appended as REG_VALUE_PROFILE note to the instrumented
45    insn.  The argument to the note consists of an EXPR_LIST where its
46    members have the following meaning (from the first to the last):
47    
48    -- type of information gathered (HIST_TYPE*)
49    -- the expression that is profiled
50    -- list of counters starting from the first one.  */
51
52 static void insn_values_to_profile (rtx, unsigned *, struct histogram_value **);
53 \f
54 /* Release the list of VALUES of length N_VALUES for that we want to measure
55    histograms.  */
56 void
57 free_profiled_values (unsigned n_values ATTRIBUTE_UNUSED,
58                       struct histogram_value *values)
59 {
60   free (values);
61 }
62
63 /* Find values inside INSN for that we want to measure histograms and adds
64    them to list VALUES (increasing the record of its length in N_VALUES).  */
65 static void
66 insn_values_to_profile (rtx insn ATTRIBUTE_UNUSED,
67                         unsigned *n_values ATTRIBUTE_UNUSED,
68                         struct histogram_value **values ATTRIBUTE_UNUSED)
69 {
70 }
71
72 /* Find list of values for that we want to measure histograms.  */
73 void
74 find_values_to_profile (unsigned *n_values, struct histogram_value **values)
75 {
76   rtx insn;
77   unsigned i;
78
79   *n_values = 0;
80   *values = NULL;
81   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
82     insn_values_to_profile (insn, n_values, values);
83
84   for (i = 0; i < *n_values; i++)
85     {
86       switch ((*values)[i].type)
87         {
88         case HIST_TYPE_INTERVAL:
89           (*values)[i].n_counters = (*values)[i].hdata.intvl.steps +
90                   ((*values)[i].hdata.intvl.may_be_less ? 1 : 0) +
91                   ((*values)[i].hdata.intvl.may_be_more ? 1 : 0);
92           break;
93
94         case HIST_TYPE_POW2:
95           (*values)[i].n_counters = GET_MODE_BITSIZE ((*values)[i].mode) +
96                   ((*values)[i].hdata.pow2.may_be_other ? 1 : 0);
97           break;
98
99         case HIST_TYPE_SINGLE_VALUE:
100           (*values)[i].n_counters = 3;
101           break;
102
103         case HIST_TYPE_CONST_DELTA:
104           (*values)[i].n_counters = 4;
105           break;
106
107         default:
108           abort ();
109         }
110     }
111 }