OSDN Git Service

PR c++/10784
[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-probablities (the
44    description of an exact way how to do it will be added here once the
45    code responsible for reading of the data is merged).  */
46
47 static void insn_values_to_profile (rtx, unsigned *, struct histogram_value **);
48 \f
49 /* Release the list of VALUES of length N_VALUES for that we want to measure
50    histograms.  */
51 void
52 free_profiled_values (unsigned n_values ATTRIBUTE_UNUSED,
53                       struct histogram_value *values)
54 {
55   free (values);
56 }
57
58 /* Find values inside INSN for that we want to measure histograms and adds
59    them to list VALUES (increasing the record of its length in N_VALUES).  */
60 static void
61 insn_values_to_profile (rtx insn ATTRIBUTE_UNUSED,
62                         unsigned *n_values ATTRIBUTE_UNUSED,
63                         struct histogram_value **values ATTRIBUTE_UNUSED)
64 {
65 }
66
67 /* Find list of values for that we want to measure histograms.  */
68 void
69 find_values_to_profile (unsigned *n_values, struct histogram_value **values)
70 {
71   rtx insn;
72   unsigned i;
73
74   *n_values = 0;
75   *values = NULL;
76   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
77     insn_values_to_profile (insn, n_values, values);
78
79   for (i = 0; i < *n_values; i++)
80     {
81       switch ((*values)[i].type)
82         {
83         case HIST_TYPE_INTERVAL:
84           (*values)[i].n_counters = (*values)[i].hdata.intvl.steps +
85                   ((*values)[i].hdata.intvl.may_be_less ? 1 : 0) +
86                   ((*values)[i].hdata.intvl.may_be_more ? 1 : 0);
87           break;
88
89         case HIST_TYPE_POW2:
90           (*values)[i].n_counters = GET_MODE_BITSIZE ((*values)[i].mode) +
91                   ((*values)[i].hdata.pow2.may_be_other ? 1 : 0);
92           break;
93
94         case HIST_TYPE_SINGLE_VALUE:
95           (*values)[i].n_counters = 3;
96           break;
97
98         case HIST_TYPE_CONST_DELTA:
99           (*values)[i].n_counters = 4;
100           break;
101
102         default:
103           abort ();
104         }
105     }
106 }