annotate gcc/value-prof.c @ 136:4627f235cf2a

fix c-next example
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 08 Nov 2018 14:11:56 +0900
parents 84e7813d76e9
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Transformations based on profile information for values.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2003-2018 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 #include "config.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #include "system.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #include "coretypes.h"
111
kono
parents: 67
diff changeset
23 #include "backend.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 #include "rtl.h"
111
kono
parents: 67
diff changeset
25 #include "tree.h"
kono
parents: 67
diff changeset
26 #include "gimple.h"
kono
parents: 67
diff changeset
27 #include "cfghooks.h"
kono
parents: 67
diff changeset
28 #include "ssa.h"
kono
parents: 67
diff changeset
29 #include "cgraph.h"
kono
parents: 67
diff changeset
30 #include "coverage.h"
kono
parents: 67
diff changeset
31 #include "data-streamer.h"
kono
parents: 67
diff changeset
32 #include "diagnostic.h"
kono
parents: 67
diff changeset
33 #include "fold-const.h"
kono
parents: 67
diff changeset
34 #include "tree-nested.h"
kono
parents: 67
diff changeset
35 #include "calls.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 #include "expr.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 #include "value-prof.h"
111
kono
parents: 67
diff changeset
38 #include "tree-eh.h"
kono
parents: 67
diff changeset
39 #include "gimplify.h"
kono
parents: 67
diff changeset
40 #include "gimple-iterator.h"
kono
parents: 67
diff changeset
41 #include "tree-cfg.h"
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
42 #include "gimple-pretty-print.h"
111
kono
parents: 67
diff changeset
43 #include "dumpfile.h"
kono
parents: 67
diff changeset
44 #include "builtins.h"
kono
parents: 67
diff changeset
45 #include "params.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 /* In this file value profile based optimizations are placed. Currently the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 following optimizations are implemented (for more detailed descriptions
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 see comments at value_profile_transformations):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 1) Division/modulo specialization. Provided that we can determine that the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 operands of the division have some special properties, we may use it to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 produce more effective code.
111
kono
parents: 67
diff changeset
54
kono
parents: 67
diff changeset
55 2) Indirect/virtual call specialization. If we can determine most
kono
parents: 67
diff changeset
56 common function callee in indirect/virtual call. We can use this
kono
parents: 67
diff changeset
57 information to improve code effectiveness (especially info for
kono
parents: 67
diff changeset
58 the inliner).
kono
parents: 67
diff changeset
59
kono
parents: 67
diff changeset
60 3) Speculative prefetching. If we are able to determine that the difference
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 between addresses accessed by a memory reference is usually constant, we
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 may add the prefetch instructions.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 FIXME: This transformation was removed together with RTL based value
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 profiling.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65
111
kono
parents: 67
diff changeset
66
kono
parents: 67
diff changeset
67 Value profiling internals
kono
parents: 67
diff changeset
68 ==========================
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69
111
kono
parents: 67
diff changeset
70 Every value profiling transformation starts with defining what values
kono
parents: 67
diff changeset
71 to profile. There are different histogram types (see HIST_TYPE_* in
kono
parents: 67
diff changeset
72 value-prof.h) and each transformation can request one or more histogram
kono
parents: 67
diff changeset
73 types per GIMPLE statement. The function gimple_find_values_to_profile()
kono
parents: 67
diff changeset
74 collects the values to profile in a vec, and adds the number of counters
kono
parents: 67
diff changeset
75 required for the different histogram types.
kono
parents: 67
diff changeset
76
kono
parents: 67
diff changeset
77 For a -fprofile-generate run, the statements for which values should be
kono
parents: 67
diff changeset
78 recorded, are instrumented in instrument_values(). The instrumentation
kono
parents: 67
diff changeset
79 is done by helper functions that can be found in tree-profile.c, where
kono
parents: 67
diff changeset
80 new types of histograms can be added if necessary.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
111
kono
parents: 67
diff changeset
82 After a -fprofile-use, the value profiling data is read back in by
kono
parents: 67
diff changeset
83 compute_value_histograms() that translates the collected data to
kono
parents: 67
diff changeset
84 histograms and attaches them to the profiled statements via
kono
parents: 67
diff changeset
85 gimple_add_histogram_value(). Histograms are stored in a hash table
kono
parents: 67
diff changeset
86 that is attached to every intrumented function, see VALUE_HISTOGRAMS
kono
parents: 67
diff changeset
87 in function.h.
kono
parents: 67
diff changeset
88
kono
parents: 67
diff changeset
89 The value-profile transformations driver is the function
kono
parents: 67
diff changeset
90 gimple_value_profile_transformations(). It traverses all statements in
kono
parents: 67
diff changeset
91 the to-be-transformed function, and looks for statements with one or
kono
parents: 67
diff changeset
92 more histograms attached to it. If a statement has histograms, the
kono
parents: 67
diff changeset
93 transformation functions are called on the statement.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94
111
kono
parents: 67
diff changeset
95 Limitations / FIXME / TODO:
kono
parents: 67
diff changeset
96 * Only one histogram of each type can be associated with a statement.
kono
parents: 67
diff changeset
97 * Some value profile transformations are done in builtins.c (?!)
kono
parents: 67
diff changeset
98 * Updating of histograms needs some TLC.
kono
parents: 67
diff changeset
99 * The value profiling code could be used to record analysis results
kono
parents: 67
diff changeset
100 from non-profiling (e.g. VRP).
kono
parents: 67
diff changeset
101 * Adding new profilers should be simplified, starting with a cleanup
kono
parents: 67
diff changeset
102 of what-happens-where and with making gimple_find_values_to_profile
kono
parents: 67
diff changeset
103 and gimple_value_profile_transformations table-driven, perhaps...
kono
parents: 67
diff changeset
104 */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 static bool gimple_divmod_fixed_value_transform (gimple_stmt_iterator *);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 static bool gimple_mod_pow2_value_transform (gimple_stmt_iterator *);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 static bool gimple_mod_subtract_transform (gimple_stmt_iterator *);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 static bool gimple_stringops_transform (gimple_stmt_iterator *);
111
kono
parents: 67
diff changeset
110 static bool gimple_ic_transform (gimple_stmt_iterator *);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 /* Allocate histogram value. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113
111
kono
parents: 67
diff changeset
114 histogram_value
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 gimple_alloc_histogram_value (struct function *fun ATTRIBUTE_UNUSED,
111
kono
parents: 67
diff changeset
116 enum hist_type type, gimple *stmt, tree value)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 histogram_value hist = (histogram_value) xcalloc (1, sizeof (*hist));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 hist->hvalue.value = value;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 hist->hvalue.stmt = stmt;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 hist->type = type;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 return hist;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 /* Hash value for histogram. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 static hashval_t
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 histogram_hash (const void *x)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 return htab_hash_pointer (((const_histogram_value)x)->hvalue.stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132
111
kono
parents: 67
diff changeset
133 /* Return nonzero if statement for histogram_value X is Y. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 static int
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 histogram_eq (const void *x, const void *y)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 {
111
kono
parents: 67
diff changeset
138 return ((const_histogram_value) x)->hvalue.stmt == (const gimple *) y;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 /* Set histogram for STMT. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 static void
111
kono
parents: 67
diff changeset
144 set_histogram_value (struct function *fun, gimple *stmt, histogram_value hist)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 void **loc;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 if (!hist && !VALUE_HISTOGRAMS (fun))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 if (!VALUE_HISTOGRAMS (fun))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 VALUE_HISTOGRAMS (fun) = htab_create (1, histogram_hash,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 histogram_eq, NULL);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 loc = htab_find_slot_with_hash (VALUE_HISTOGRAMS (fun), stmt,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 htab_hash_pointer (stmt),
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 hist ? INSERT : NO_INSERT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 if (!hist)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 if (loc)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 htab_clear_slot (VALUE_HISTOGRAMS (fun), loc);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 *loc = hist;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 /* Get histogram list for STMT. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 histogram_value
111
kono
parents: 67
diff changeset
167 gimple_histogram_value (struct function *fun, gimple *stmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 if (!VALUE_HISTOGRAMS (fun))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 return NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 return (histogram_value) htab_find_with_hash (VALUE_HISTOGRAMS (fun), stmt,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 htab_hash_pointer (stmt));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 /* Add histogram for STMT. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 void
111
kono
parents: 67
diff changeset
178 gimple_add_histogram_value (struct function *fun, gimple *stmt,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 histogram_value hist)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 hist->hvalue.next = gimple_histogram_value (fun, stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 set_histogram_value (fun, stmt, hist);
111
kono
parents: 67
diff changeset
183 hist->fun = fun;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 /* Remove histogram HIST from STMT's histogram list. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
187
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 void
111
kono
parents: 67
diff changeset
189 gimple_remove_histogram_value (struct function *fun, gimple *stmt,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 histogram_value hist)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 histogram_value hist2 = gimple_histogram_value (fun, stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 if (hist == hist2)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 set_histogram_value (fun, stmt, hist->hvalue.next);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 while (hist2->hvalue.next != hist)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 hist2 = hist2->hvalue.next;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 hist2->hvalue.next = hist->hvalue.next;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 free (hist->hvalue.counters);
111
kono
parents: 67
diff changeset
204 if (flag_checking)
kono
parents: 67
diff changeset
205 memset (hist, 0xab, sizeof (*hist));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 free (hist);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
208
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 /* Lookup histogram of type TYPE in the STMT. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 histogram_value
111
kono
parents: 67
diff changeset
212 gimple_histogram_value_of_type (struct function *fun, gimple *stmt,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 enum hist_type type)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 histogram_value hist;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 for (hist = gimple_histogram_value (fun, stmt); hist;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 hist = hist->hvalue.next)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 if (hist->type == type)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 return hist;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 return NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
222
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 /* Dump information about HIST to DUMP_FILE. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 dump_histogram_value (FILE *dump_file, histogram_value hist)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 switch (hist->type)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 case HIST_TYPE_INTERVAL:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 fprintf (dump_file, "Interval counter range %d -- %d",
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 hist->hdata.intvl.int_start,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 (hist->hdata.intvl.int_start
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 + hist->hdata.intvl.steps - 1));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 if (hist->hvalue.counters)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 unsigned int i;
111
kono
parents: 67
diff changeset
238 fprintf (dump_file, " [");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 for (i = 0; i < hist->hdata.intvl.steps; i++)
111
kono
parents: 67
diff changeset
240 fprintf (dump_file, " %d:%" PRId64,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 hist->hdata.intvl.int_start + i,
111
kono
parents: 67
diff changeset
242 (int64_t) hist->hvalue.counters[i]);
kono
parents: 67
diff changeset
243 fprintf (dump_file, " ] outside range:%" PRId64,
kono
parents: 67
diff changeset
244 (int64_t) hist->hvalue.counters[i]);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 fprintf (dump_file, ".\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
248
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 case HIST_TYPE_POW2:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 fprintf (dump_file, "Pow2 counter ");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 if (hist->hvalue.counters)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 {
111
kono
parents: 67
diff changeset
253 fprintf (dump_file, "pow2:%" PRId64
kono
parents: 67
diff changeset
254 " nonpow2:%" PRId64,
kono
parents: 67
diff changeset
255 (int64_t) hist->hvalue.counters[1],
kono
parents: 67
diff changeset
256 (int64_t) hist->hvalue.counters[0]);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 fprintf (dump_file, ".\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
260
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 case HIST_TYPE_SINGLE_VALUE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 fprintf (dump_file, "Single value ");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 if (hist->hvalue.counters)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 {
111
kono
parents: 67
diff changeset
265 fprintf (dump_file, "value:%" PRId64
kono
parents: 67
diff changeset
266 " match:%" PRId64
kono
parents: 67
diff changeset
267 " wrong:%" PRId64,
kono
parents: 67
diff changeset
268 (int64_t) hist->hvalue.counters[0],
kono
parents: 67
diff changeset
269 (int64_t) hist->hvalue.counters[1],
kono
parents: 67
diff changeset
270 (int64_t) hist->hvalue.counters[2]);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 fprintf (dump_file, ".\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
274
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 case HIST_TYPE_AVERAGE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 fprintf (dump_file, "Average value ");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 if (hist->hvalue.counters)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 {
111
kono
parents: 67
diff changeset
279 fprintf (dump_file, "sum:%" PRId64
kono
parents: 67
diff changeset
280 " times:%" PRId64,
kono
parents: 67
diff changeset
281 (int64_t) hist->hvalue.counters[0],
kono
parents: 67
diff changeset
282 (int64_t) hist->hvalue.counters[1]);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 fprintf (dump_file, ".\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
286
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 case HIST_TYPE_IOR:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 fprintf (dump_file, "IOR value ");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 if (hist->hvalue.counters)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 {
111
kono
parents: 67
diff changeset
291 fprintf (dump_file, "ior:%" PRId64,
kono
parents: 67
diff changeset
292 (int64_t) hist->hvalue.counters[0]);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 fprintf (dump_file, ".\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
296
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 case HIST_TYPE_INDIR_CALL:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 fprintf (dump_file, "Indirect call ");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 if (hist->hvalue.counters)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 {
111
kono
parents: 67
diff changeset
301 fprintf (dump_file, "value:%" PRId64
kono
parents: 67
diff changeset
302 " match:%" PRId64
kono
parents: 67
diff changeset
303 " all:%" PRId64,
kono
parents: 67
diff changeset
304 (int64_t) hist->hvalue.counters[0],
kono
parents: 67
diff changeset
305 (int64_t) hist->hvalue.counters[1],
kono
parents: 67
diff changeset
306 (int64_t) hist->hvalue.counters[2]);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 fprintf (dump_file, ".\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 break;
111
kono
parents: 67
diff changeset
310 case HIST_TYPE_TIME_PROFILE:
kono
parents: 67
diff changeset
311 fprintf (dump_file, "Time profile ");
kono
parents: 67
diff changeset
312 if (hist->hvalue.counters)
kono
parents: 67
diff changeset
313 {
kono
parents: 67
diff changeset
314 fprintf (dump_file, "time:%" PRId64,
kono
parents: 67
diff changeset
315 (int64_t) hist->hvalue.counters[0]);
kono
parents: 67
diff changeset
316 }
kono
parents: 67
diff changeset
317 fprintf (dump_file, ".\n");
kono
parents: 67
diff changeset
318 break;
kono
parents: 67
diff changeset
319 case HIST_TYPE_INDIR_CALL_TOPN:
kono
parents: 67
diff changeset
320 fprintf (dump_file, "Indirect call topn ");
kono
parents: 67
diff changeset
321 if (hist->hvalue.counters)
kono
parents: 67
diff changeset
322 {
kono
parents: 67
diff changeset
323 int i;
kono
parents: 67
diff changeset
324
kono
parents: 67
diff changeset
325 fprintf (dump_file, "accu:%" PRId64, hist->hvalue.counters[0]);
kono
parents: 67
diff changeset
326 for (i = 1; i < (GCOV_ICALL_TOPN_VAL << 2); i += 2)
kono
parents: 67
diff changeset
327 {
kono
parents: 67
diff changeset
328 fprintf (dump_file, " target:%" PRId64 " value:%" PRId64,
kono
parents: 67
diff changeset
329 (int64_t) hist->hvalue.counters[i],
kono
parents: 67
diff changeset
330 (int64_t) hist->hvalue.counters[i+1]);
kono
parents: 67
diff changeset
331 }
kono
parents: 67
diff changeset
332 }
kono
parents: 67
diff changeset
333 fprintf (dump_file, ".\n");
kono
parents: 67
diff changeset
334 break;
kono
parents: 67
diff changeset
335 case HIST_TYPE_MAX:
kono
parents: 67
diff changeset
336 gcc_unreachable ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
337 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
339
111
kono
parents: 67
diff changeset
340 /* Dump information about HIST to DUMP_FILE. */
kono
parents: 67
diff changeset
341
kono
parents: 67
diff changeset
342 void
kono
parents: 67
diff changeset
343 stream_out_histogram_value (struct output_block *ob, histogram_value hist)
kono
parents: 67
diff changeset
344 {
kono
parents: 67
diff changeset
345 struct bitpack_d bp;
kono
parents: 67
diff changeset
346 unsigned int i;
kono
parents: 67
diff changeset
347
kono
parents: 67
diff changeset
348 bp = bitpack_create (ob->main_stream);
kono
parents: 67
diff changeset
349 bp_pack_enum (&bp, hist_type, HIST_TYPE_MAX, hist->type);
kono
parents: 67
diff changeset
350 bp_pack_value (&bp, hist->hvalue.next != NULL, 1);
kono
parents: 67
diff changeset
351 streamer_write_bitpack (&bp);
kono
parents: 67
diff changeset
352 switch (hist->type)
kono
parents: 67
diff changeset
353 {
kono
parents: 67
diff changeset
354 case HIST_TYPE_INTERVAL:
kono
parents: 67
diff changeset
355 streamer_write_hwi (ob, hist->hdata.intvl.int_start);
kono
parents: 67
diff changeset
356 streamer_write_uhwi (ob, hist->hdata.intvl.steps);
kono
parents: 67
diff changeset
357 break;
kono
parents: 67
diff changeset
358 default:
kono
parents: 67
diff changeset
359 break;
kono
parents: 67
diff changeset
360 }
kono
parents: 67
diff changeset
361 for (i = 0; i < hist->n_counters; i++)
kono
parents: 67
diff changeset
362 {
kono
parents: 67
diff changeset
363 /* When user uses an unsigned type with a big value, constant converted
kono
parents: 67
diff changeset
364 to gcov_type (a signed type) can be negative. */
kono
parents: 67
diff changeset
365 gcov_type value = hist->hvalue.counters[i];
kono
parents: 67
diff changeset
366 if (hist->type == HIST_TYPE_SINGLE_VALUE && i == 0)
kono
parents: 67
diff changeset
367 ;
kono
parents: 67
diff changeset
368 else
kono
parents: 67
diff changeset
369 gcc_assert (value >= 0);
kono
parents: 67
diff changeset
370
kono
parents: 67
diff changeset
371 streamer_write_gcov_count (ob, value);
kono
parents: 67
diff changeset
372 }
kono
parents: 67
diff changeset
373 if (hist->hvalue.next)
kono
parents: 67
diff changeset
374 stream_out_histogram_value (ob, hist->hvalue.next);
kono
parents: 67
diff changeset
375 }
kono
parents: 67
diff changeset
376
kono
parents: 67
diff changeset
377 /* Dump information about HIST to DUMP_FILE. */
kono
parents: 67
diff changeset
378
kono
parents: 67
diff changeset
379 void
kono
parents: 67
diff changeset
380 stream_in_histogram_value (struct lto_input_block *ib, gimple *stmt)
kono
parents: 67
diff changeset
381 {
kono
parents: 67
diff changeset
382 enum hist_type type;
kono
parents: 67
diff changeset
383 unsigned int ncounters = 0;
kono
parents: 67
diff changeset
384 struct bitpack_d bp;
kono
parents: 67
diff changeset
385 unsigned int i;
kono
parents: 67
diff changeset
386 histogram_value new_val;
kono
parents: 67
diff changeset
387 bool next;
kono
parents: 67
diff changeset
388 histogram_value *next_p = NULL;
kono
parents: 67
diff changeset
389
kono
parents: 67
diff changeset
390 do
kono
parents: 67
diff changeset
391 {
kono
parents: 67
diff changeset
392 bp = streamer_read_bitpack (ib);
kono
parents: 67
diff changeset
393 type = bp_unpack_enum (&bp, hist_type, HIST_TYPE_MAX);
kono
parents: 67
diff changeset
394 next = bp_unpack_value (&bp, 1);
kono
parents: 67
diff changeset
395 new_val = gimple_alloc_histogram_value (cfun, type, stmt, NULL);
kono
parents: 67
diff changeset
396 switch (type)
kono
parents: 67
diff changeset
397 {
kono
parents: 67
diff changeset
398 case HIST_TYPE_INTERVAL:
kono
parents: 67
diff changeset
399 new_val->hdata.intvl.int_start = streamer_read_hwi (ib);
kono
parents: 67
diff changeset
400 new_val->hdata.intvl.steps = streamer_read_uhwi (ib);
kono
parents: 67
diff changeset
401 ncounters = new_val->hdata.intvl.steps + 2;
kono
parents: 67
diff changeset
402 break;
kono
parents: 67
diff changeset
403
kono
parents: 67
diff changeset
404 case HIST_TYPE_POW2:
kono
parents: 67
diff changeset
405 case HIST_TYPE_AVERAGE:
kono
parents: 67
diff changeset
406 ncounters = 2;
kono
parents: 67
diff changeset
407 break;
kono
parents: 67
diff changeset
408
kono
parents: 67
diff changeset
409 case HIST_TYPE_SINGLE_VALUE:
kono
parents: 67
diff changeset
410 case HIST_TYPE_INDIR_CALL:
kono
parents: 67
diff changeset
411 ncounters = 3;
kono
parents: 67
diff changeset
412 break;
kono
parents: 67
diff changeset
413
kono
parents: 67
diff changeset
414 case HIST_TYPE_IOR:
kono
parents: 67
diff changeset
415 case HIST_TYPE_TIME_PROFILE:
kono
parents: 67
diff changeset
416 ncounters = 1;
kono
parents: 67
diff changeset
417 break;
kono
parents: 67
diff changeset
418
kono
parents: 67
diff changeset
419 case HIST_TYPE_INDIR_CALL_TOPN:
kono
parents: 67
diff changeset
420 ncounters = (GCOV_ICALL_TOPN_VAL << 2) + 1;
kono
parents: 67
diff changeset
421 break;
kono
parents: 67
diff changeset
422
kono
parents: 67
diff changeset
423 case HIST_TYPE_MAX:
kono
parents: 67
diff changeset
424 gcc_unreachable ();
kono
parents: 67
diff changeset
425 }
kono
parents: 67
diff changeset
426 new_val->hvalue.counters = XNEWVAR (gcov_type, sizeof (*new_val->hvalue.counters) * ncounters);
kono
parents: 67
diff changeset
427 new_val->n_counters = ncounters;
kono
parents: 67
diff changeset
428 for (i = 0; i < ncounters; i++)
kono
parents: 67
diff changeset
429 new_val->hvalue.counters[i] = streamer_read_gcov_count (ib);
kono
parents: 67
diff changeset
430 if (!next_p)
kono
parents: 67
diff changeset
431 gimple_add_histogram_value (cfun, stmt, new_val);
kono
parents: 67
diff changeset
432 else
kono
parents: 67
diff changeset
433 *next_p = new_val;
kono
parents: 67
diff changeset
434 next_p = &new_val->hvalue.next;
kono
parents: 67
diff changeset
435 }
kono
parents: 67
diff changeset
436 while (next);
kono
parents: 67
diff changeset
437 }
kono
parents: 67
diff changeset
438
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 /* Dump all histograms attached to STMT to DUMP_FILE. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
440
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 void
111
kono
parents: 67
diff changeset
442 dump_histograms_for_stmt (struct function *fun, FILE *dump_file, gimple *stmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
444 histogram_value hist;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
445 for (hist = gimple_histogram_value (fun, stmt); hist; hist = hist->hvalue.next)
111
kono
parents: 67
diff changeset
446 dump_histogram_value (dump_file, hist);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
447 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
448
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
449 /* Remove all histograms associated with STMT. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
450
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 void
111
kono
parents: 67
diff changeset
452 gimple_remove_stmt_histograms (struct function *fun, gimple *stmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
453 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
454 histogram_value val;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 while ((val = gimple_histogram_value (fun, stmt)) != NULL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
456 gimple_remove_histogram_value (fun, stmt, val);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
457 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
458
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 /* Duplicate all histograms associates with OSTMT to STMT. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
460
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
461 void
111
kono
parents: 67
diff changeset
462 gimple_duplicate_stmt_histograms (struct function *fun, gimple *stmt,
kono
parents: 67
diff changeset
463 struct function *ofun, gimple *ostmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
465 histogram_value val;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
466 for (val = gimple_histogram_value (ofun, ostmt); val != NULL; val = val->hvalue.next)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
467 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
468 histogram_value new_val = gimple_alloc_histogram_value (fun, val->type, NULL, NULL);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
469 memcpy (new_val, val, sizeof (*val));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 new_val->hvalue.stmt = stmt;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 new_val->hvalue.counters = XNEWVAR (gcov_type, sizeof (*new_val->hvalue.counters) * new_val->n_counters);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 memcpy (new_val->hvalue.counters, val->hvalue.counters, sizeof (*new_val->hvalue.counters) * new_val->n_counters);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
473 gimple_add_histogram_value (fun, stmt, new_val);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
474 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
475 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
476
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
477 /* Move all histograms associated with OSTMT to STMT. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
478
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
479 void
111
kono
parents: 67
diff changeset
480 gimple_move_stmt_histograms (struct function *fun, gimple *stmt, gimple *ostmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
481 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
482 histogram_value val = gimple_histogram_value (fun, ostmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
483 if (val)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
484 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 /* The following three statements can't be reordered,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
486 because histogram hashtab relies on stmt field value
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
487 for finding the exact slot. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 set_histogram_value (fun, ostmt, NULL);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
489 for (; val != NULL; val = val->hvalue.next)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
490 val->hvalue.stmt = stmt;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
491 set_histogram_value (fun, stmt, val);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
492 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
493 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
494
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 static bool error_found = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
496
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
497 /* Helper function for verify_histograms. For each histogram reachable via htab
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
498 walk verify that it was reached via statement walk. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
499
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
500 static int
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
501 visit_hist (void **slot, void *data)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
502 {
111
kono
parents: 67
diff changeset
503 hash_set<histogram_value> *visited = (hash_set<histogram_value> *) data;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
504 histogram_value hist = *(histogram_value *) slot;
111
kono
parents: 67
diff changeset
505
kono
parents: 67
diff changeset
506 if (!visited->contains (hist)
kono
parents: 67
diff changeset
507 && hist->type != HIST_TYPE_TIME_PROFILE)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 {
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
509 error ("dead histogram");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
510 dump_histogram_value (stderr, hist);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 debug_gimple_stmt (hist->hvalue.stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
512 error_found = true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
514 return 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
515 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
516
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
517 /* Verify sanity of the histograms. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
518
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
519 DEBUG_FUNCTION void
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
520 verify_histograms (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
521 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
522 basic_block bb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
523 gimple_stmt_iterator gsi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
524 histogram_value hist;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
525
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 error_found = false;
111
kono
parents: 67
diff changeset
527 hash_set<histogram_value> visited_hists;
kono
parents: 67
diff changeset
528 FOR_EACH_BB_FN (bb, cfun)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
529 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 {
111
kono
parents: 67
diff changeset
531 gimple *stmt = gsi_stmt (gsi);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
532
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 for (hist = gimple_histogram_value (cfun, stmt); hist;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 hist = hist->hvalue.next)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
536 if (hist->hvalue.stmt != stmt)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
537 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
538 error ("Histogram value statement does not correspond to "
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
539 "the statement it is associated with");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 debug_gimple_stmt (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
541 dump_histogram_value (stderr, hist);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
542 error_found = true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
543 }
111
kono
parents: 67
diff changeset
544 visited_hists.add (hist);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
545 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
546 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
547 if (VALUE_HISTOGRAMS (cfun))
111
kono
parents: 67
diff changeset
548 htab_traverse (VALUE_HISTOGRAMS (cfun), visit_hist, &visited_hists);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
549 if (error_found)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
550 internal_error ("verify_histograms failed");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
551 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
552
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
553 /* Helper function for verify_histograms. For each histogram reachable via htab
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
554 walk verify that it was reached via statement walk. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
555
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
556 static int
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
557 free_hist (void **slot, void *data ATTRIBUTE_UNUSED)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
558 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
559 histogram_value hist = *(histogram_value *) slot;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
560 free (hist->hvalue.counters);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
561 free (hist);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
562 return 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
563 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
564
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
565 void
111
kono
parents: 67
diff changeset
566 free_histograms (struct function *fn)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
567 {
111
kono
parents: 67
diff changeset
568 if (VALUE_HISTOGRAMS (fn))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
569 {
111
kono
parents: 67
diff changeset
570 htab_traverse (VALUE_HISTOGRAMS (fn), free_hist, NULL);
kono
parents: 67
diff changeset
571 htab_delete (VALUE_HISTOGRAMS (fn));
kono
parents: 67
diff changeset
572 VALUE_HISTOGRAMS (fn) = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
573 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
574 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
575
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
576 /* The overall number of invocations of the counter should match
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
577 execution count of basic block. Report it as error rather than
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
578 internal error as it might mean that user has misused the profile
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
579 somehow. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
580
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
581 static bool
111
kono
parents: 67
diff changeset
582 check_counter (gimple *stmt, const char * name,
kono
parents: 67
diff changeset
583 gcov_type *count, gcov_type *all, profile_count bb_count_d)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
584 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
585 gcov_type bb_count = bb_count_d.ipa ().to_gcov_type ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
586 if (*all != bb_count || *count > *all)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
587 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
588 dump_user_location_t locus;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
589 locus = ((stmt != NULL)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
590 ? dump_user_location_t (stmt)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
591 : dump_user_location_t::from_function_decl
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
592 (current_function_decl));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
593 if (flag_profile_correction)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
594 {
111
kono
parents: 67
diff changeset
595 if (dump_enabled_p ())
kono
parents: 67
diff changeset
596 dump_printf_loc (MSG_MISSED_OPTIMIZATION, locus,
kono
parents: 67
diff changeset
597 "correcting inconsistent value profile: %s "
kono
parents: 67
diff changeset
598 "profiler overall count (%d) does not match BB "
kono
parents: 67
diff changeset
599 "count (%d)\n", name, (int)*all, (int)bb_count);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
600 *all = bb_count;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
601 if (*count > *all)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
602 *count = *all;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
603 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
604 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
605 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
606 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
607 error_at (locus.get_location_t (), "corrupted value profile: %s "
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
608 "profile counter (%d out of %d) inconsistent with "
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
609 "basic-block count (%d)",
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
610 name,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
611 (int) *count,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
612 (int) *all,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
613 (int) bb_count);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
614 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
615 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
616 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
617
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
618 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
619 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
620
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
621 /* GIMPLE based transformations. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
622
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
623 bool
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
624 gimple_value_profile_transformations (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
625 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
626 basic_block bb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
627 gimple_stmt_iterator gsi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
628 bool changed = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
629
111
kono
parents: 67
diff changeset
630 /* Autofdo does its own transformations for indirect calls,
kono
parents: 67
diff changeset
631 and otherwise does not support value profiling. */
kono
parents: 67
diff changeset
632 if (flag_auto_profile)
kono
parents: 67
diff changeset
633 return false;
kono
parents: 67
diff changeset
634
kono
parents: 67
diff changeset
635 FOR_EACH_BB_FN (bb, cfun)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
636 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
637 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
638 {
111
kono
parents: 67
diff changeset
639 gimple *stmt = gsi_stmt (gsi);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
640 histogram_value th = gimple_histogram_value (cfun, stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
641 if (!th)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
642 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
643
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
644 if (dump_file)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
645 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
646 fprintf (dump_file, "Trying transformations on stmt ");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
647 print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
648 dump_histograms_for_stmt (cfun, dump_file, stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
649 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
650
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
651 /* Transformations: */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
652 /* The order of things in this conditional controls which
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
653 transformation is used when more than one is applicable. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
654 /* It is expected that any code added by the transformations
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
655 will be added before the current statement, and that the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
656 current statement remain valid (although possibly
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
657 modified) upon return. */
111
kono
parents: 67
diff changeset
658 if (gimple_mod_subtract_transform (&gsi)
kono
parents: 67
diff changeset
659 || gimple_divmod_fixed_value_transform (&gsi)
kono
parents: 67
diff changeset
660 || gimple_mod_pow2_value_transform (&gsi)
kono
parents: 67
diff changeset
661 || gimple_stringops_transform (&gsi)
kono
parents: 67
diff changeset
662 || gimple_ic_transform (&gsi))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
663 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
664 stmt = gsi_stmt (gsi);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
665 changed = true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
666 /* Original statement may no longer be in the same block. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
667 if (bb != gimple_bb (stmt))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
668 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
669 bb = gimple_bb (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
670 gsi = gsi_for_stmt (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
671 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
672 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
673 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
674 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
675
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
676 return changed;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
677 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
678
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
679 /* Generate code for transformation 1 (with parent gimple assignment
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
680 STMT and probability of taking the optimal path PROB, which is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
681 equivalent to COUNT/ALL within roundoff error). This generates the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
682 result into a temp and returns the temp; it does not replace or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
683 alter the original STMT. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
684
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
685 static tree
111
kono
parents: 67
diff changeset
686 gimple_divmod_fixed_value (gassign *stmt, tree value, profile_probability prob,
kono
parents: 67
diff changeset
687 gcov_type count, gcov_type all)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
688 {
111
kono
parents: 67
diff changeset
689 gassign *stmt1, *stmt2;
kono
parents: 67
diff changeset
690 gcond *stmt3;
kono
parents: 67
diff changeset
691 tree tmp0, tmp1, tmp2;
kono
parents: 67
diff changeset
692 gimple *bb1end, *bb2end, *bb3end;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
693 basic_block bb, bb2, bb3, bb4;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
694 tree optype, op1, op2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
695 edge e12, e13, e23, e24, e34;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
696 gimple_stmt_iterator gsi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
697
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
698 gcc_assert (is_gimple_assign (stmt)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
699 && (gimple_assign_rhs_code (stmt) == TRUNC_DIV_EXPR
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
700 || gimple_assign_rhs_code (stmt) == TRUNC_MOD_EXPR));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
701
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
702 optype = TREE_TYPE (gimple_assign_lhs (stmt));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
703 op1 = gimple_assign_rhs1 (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
704 op2 = gimple_assign_rhs2 (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
705
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
706 bb = gimple_bb (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
707 gsi = gsi_for_stmt (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
708
111
kono
parents: 67
diff changeset
709 tmp0 = make_temp_ssa_name (optype, NULL, "PROF");
kono
parents: 67
diff changeset
710 tmp1 = make_temp_ssa_name (optype, NULL, "PROF");
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
711 stmt1 = gimple_build_assign (tmp0, fold_convert (optype, value));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
712 stmt2 = gimple_build_assign (tmp1, op2);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
713 stmt3 = gimple_build_cond (NE_EXPR, tmp1, tmp0, NULL_TREE, NULL_TREE);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
714 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
715 gsi_insert_before (&gsi, stmt2, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
716 gsi_insert_before (&gsi, stmt3, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
717 bb1end = stmt3;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
718
111
kono
parents: 67
diff changeset
719 tmp2 = create_tmp_reg (optype, "PROF");
kono
parents: 67
diff changeset
720 stmt1 = gimple_build_assign (tmp2, gimple_assign_rhs_code (stmt), op1, tmp0);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
721 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
722 bb2end = stmt1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
723
111
kono
parents: 67
diff changeset
724 stmt1 = gimple_build_assign (tmp2, gimple_assign_rhs_code (stmt), op1, op2);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
725 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
726 bb3end = stmt1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
727
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
728 /* Fix CFG. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
729 /* Edge e23 connects bb2 to bb3, etc. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
730 e12 = split_block (bb, bb1end);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
731 bb2 = e12->dest;
111
kono
parents: 67
diff changeset
732 bb2->count = profile_count::from_gcov_type (count);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
733 e23 = split_block (bb2, bb2end);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
734 bb3 = e23->dest;
111
kono
parents: 67
diff changeset
735 bb3->count = profile_count::from_gcov_type (all - count);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
736 e34 = split_block (bb3, bb3end);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
737 bb4 = e34->dest;
111
kono
parents: 67
diff changeset
738 bb4->count = profile_count::from_gcov_type (all);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
739
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
740 e12->flags &= ~EDGE_FALLTHRU;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
741 e12->flags |= EDGE_FALSE_VALUE;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
742 e12->probability = prob;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
743
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
744 e13 = make_edge (bb, bb3, EDGE_TRUE_VALUE);
111
kono
parents: 67
diff changeset
745 e13->probability = prob.invert ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
746
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
747 remove_edge (e23);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
748
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
749 e24 = make_edge (bb2, bb4, EDGE_FALLTHRU);
111
kono
parents: 67
diff changeset
750 e24->probability = profile_probability::always ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
751
111
kono
parents: 67
diff changeset
752 e34->probability = profile_probability::always ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
753
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
754 return tmp2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
755 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
756
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
757 /* Do transform 1) on INSN if applicable. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
758
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
759 static bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
760 gimple_divmod_fixed_value_transform (gimple_stmt_iterator *si)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
761 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
762 histogram_value histogram;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
763 enum tree_code code;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
764 gcov_type val, count, all;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
765 tree result, value, tree_val;
111
kono
parents: 67
diff changeset
766 profile_probability prob;
kono
parents: 67
diff changeset
767 gassign *stmt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
768
111
kono
parents: 67
diff changeset
769 stmt = dyn_cast <gassign *> (gsi_stmt (*si));
kono
parents: 67
diff changeset
770 if (!stmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
771 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
772
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
773 if (!INTEGRAL_TYPE_P (TREE_TYPE (gimple_assign_lhs (stmt))))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
774 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
775
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
776 code = gimple_assign_rhs_code (stmt);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
777
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
778 if (code != TRUNC_DIV_EXPR && code != TRUNC_MOD_EXPR)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
779 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
780
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
781 histogram = gimple_histogram_value_of_type (cfun, stmt,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
782 HIST_TYPE_SINGLE_VALUE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
783 if (!histogram)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
784 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
785
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
786 value = histogram->hvalue.value;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
787 val = histogram->hvalue.counters[0];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
788 count = histogram->hvalue.counters[1];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
789 all = histogram->hvalue.counters[2];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
790 gimple_remove_histogram_value (cfun, stmt, histogram);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
791
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
792 /* We require that count is at least half of all; this means
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
793 that for the transformation to fire the value must be constant
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
794 at least 50% of time (and 75% gives the guarantee of usage). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
795 if (simple_cst_equal (gimple_assign_rhs2 (stmt), value) != 1
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
796 || 2 * count < all
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
797 || optimize_bb_for_size_p (gimple_bb (stmt)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
798 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
799
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
800 if (check_counter (stmt, "value", &count, &all, gimple_bb (stmt)->count))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
801 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
802
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
803 /* Compute probability of taking the optimal path. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
804 if (all > 0)
111
kono
parents: 67
diff changeset
805 prob = profile_probability::probability_in_gcov_type (count, all);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
806 else
111
kono
parents: 67
diff changeset
807 prob = profile_probability::never ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
808
111
kono
parents: 67
diff changeset
809 if (sizeof (gcov_type) == sizeof (HOST_WIDE_INT))
kono
parents: 67
diff changeset
810 tree_val = build_int_cst (get_gcov_type (), val);
kono
parents: 67
diff changeset
811 else
kono
parents: 67
diff changeset
812 {
kono
parents: 67
diff changeset
813 HOST_WIDE_INT a[2];
kono
parents: 67
diff changeset
814 a[0] = (unsigned HOST_WIDE_INT) val;
kono
parents: 67
diff changeset
815 a[1] = val >> (HOST_BITS_PER_WIDE_INT - 1) >> 1;
kono
parents: 67
diff changeset
816
kono
parents: 67
diff changeset
817 tree_val = wide_int_to_tree (get_gcov_type (), wide_int::from_array (a, 2,
kono
parents: 67
diff changeset
818 TYPE_PRECISION (get_gcov_type ()), false));
kono
parents: 67
diff changeset
819 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
820 result = gimple_divmod_fixed_value (stmt, tree_val, prob, count, all);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
821
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
822 if (dump_file)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
823 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
824 fprintf (dump_file, "Transformation done: div/mod by constant ");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
825 print_generic_expr (dump_file, tree_val, TDF_SLIM);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
826 fprintf (dump_file, "\n");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
827 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
828
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
829 gimple_assign_set_rhs_from_tree (si, result);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
830 update_stmt (gsi_stmt (*si));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
831
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
832 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
833 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
834
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
835 /* Generate code for transformation 2 (with parent gimple assign STMT and
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
836 probability of taking the optimal path PROB, which is equivalent to COUNT/ALL
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
837 within roundoff error). This generates the result into a temp and returns
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
838 the temp; it does not replace or alter the original STMT. */
111
kono
parents: 67
diff changeset
839
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
840 static tree
111
kono
parents: 67
diff changeset
841 gimple_mod_pow2 (gassign *stmt, profile_probability prob, gcov_type count, gcov_type all)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
842 {
111
kono
parents: 67
diff changeset
843 gassign *stmt1, *stmt2, *stmt3;
kono
parents: 67
diff changeset
844 gcond *stmt4;
kono
parents: 67
diff changeset
845 tree tmp2, tmp3;
kono
parents: 67
diff changeset
846 gimple *bb1end, *bb2end, *bb3end;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
847 basic_block bb, bb2, bb3, bb4;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
848 tree optype, op1, op2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
849 edge e12, e13, e23, e24, e34;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
850 gimple_stmt_iterator gsi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
851 tree result;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
852
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
853 gcc_assert (is_gimple_assign (stmt)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
854 && gimple_assign_rhs_code (stmt) == TRUNC_MOD_EXPR);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
855
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
856 optype = TREE_TYPE (gimple_assign_lhs (stmt));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
857 op1 = gimple_assign_rhs1 (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
858 op2 = gimple_assign_rhs2 (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
859
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
860 bb = gimple_bb (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
861 gsi = gsi_for_stmt (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
862
111
kono
parents: 67
diff changeset
863 result = create_tmp_reg (optype, "PROF");
kono
parents: 67
diff changeset
864 tmp2 = make_temp_ssa_name (optype, NULL, "PROF");
kono
parents: 67
diff changeset
865 tmp3 = make_temp_ssa_name (optype, NULL, "PROF");
kono
parents: 67
diff changeset
866 stmt2 = gimple_build_assign (tmp2, PLUS_EXPR, op2,
kono
parents: 67
diff changeset
867 build_int_cst (optype, -1));
kono
parents: 67
diff changeset
868 stmt3 = gimple_build_assign (tmp3, BIT_AND_EXPR, tmp2, op2);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
869 stmt4 = gimple_build_cond (NE_EXPR, tmp3, build_int_cst (optype, 0),
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
870 NULL_TREE, NULL_TREE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
871 gsi_insert_before (&gsi, stmt2, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
872 gsi_insert_before (&gsi, stmt3, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
873 gsi_insert_before (&gsi, stmt4, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
874 bb1end = stmt4;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
875
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
876 /* tmp2 == op2-1 inherited from previous block. */
111
kono
parents: 67
diff changeset
877 stmt1 = gimple_build_assign (result, BIT_AND_EXPR, op1, tmp2);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
878 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
879 bb2end = stmt1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
880
111
kono
parents: 67
diff changeset
881 stmt1 = gimple_build_assign (result, gimple_assign_rhs_code (stmt),
kono
parents: 67
diff changeset
882 op1, op2);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
883 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
884 bb3end = stmt1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
885
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
886 /* Fix CFG. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
887 /* Edge e23 connects bb2 to bb3, etc. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
888 e12 = split_block (bb, bb1end);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
889 bb2 = e12->dest;
111
kono
parents: 67
diff changeset
890 bb2->count = profile_count::from_gcov_type (count);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
891 e23 = split_block (bb2, bb2end);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
892 bb3 = e23->dest;
111
kono
parents: 67
diff changeset
893 bb3->count = profile_count::from_gcov_type (all - count);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
894 e34 = split_block (bb3, bb3end);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
895 bb4 = e34->dest;
111
kono
parents: 67
diff changeset
896 bb4->count = profile_count::from_gcov_type (all);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
897
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
898 e12->flags &= ~EDGE_FALLTHRU;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
899 e12->flags |= EDGE_FALSE_VALUE;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
900 e12->probability = prob;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
901
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
902 e13 = make_edge (bb, bb3, EDGE_TRUE_VALUE);
111
kono
parents: 67
diff changeset
903 e13->probability = prob.invert ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
904
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
905 remove_edge (e23);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
906
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
907 e24 = make_edge (bb2, bb4, EDGE_FALLTHRU);
111
kono
parents: 67
diff changeset
908 e24->probability = profile_probability::always ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
909
111
kono
parents: 67
diff changeset
910 e34->probability = profile_probability::always ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
911
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
912 return result;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
913 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
914
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
915 /* Do transform 2) on INSN if applicable. */
111
kono
parents: 67
diff changeset
916
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
917 static bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
918 gimple_mod_pow2_value_transform (gimple_stmt_iterator *si)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
919 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
920 histogram_value histogram;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
921 enum tree_code code;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
922 gcov_type count, wrong_values, all;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
923 tree lhs_type, result, value;
111
kono
parents: 67
diff changeset
924 profile_probability prob;
kono
parents: 67
diff changeset
925 gassign *stmt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
926
111
kono
parents: 67
diff changeset
927 stmt = dyn_cast <gassign *> (gsi_stmt (*si));
kono
parents: 67
diff changeset
928 if (!stmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
929 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
930
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
931 lhs_type = TREE_TYPE (gimple_assign_lhs (stmt));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
932 if (!INTEGRAL_TYPE_P (lhs_type))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
933 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
934
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
935 code = gimple_assign_rhs_code (stmt);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
936
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
937 if (code != TRUNC_MOD_EXPR || !TYPE_UNSIGNED (lhs_type))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
938 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
939
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
940 histogram = gimple_histogram_value_of_type (cfun, stmt, HIST_TYPE_POW2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
941 if (!histogram)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
942 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
943
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
944 value = histogram->hvalue.value;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
945 wrong_values = histogram->hvalue.counters[0];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
946 count = histogram->hvalue.counters[1];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
947
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
948 gimple_remove_histogram_value (cfun, stmt, histogram);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
949
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
950 /* We require that we hit a power of 2 at least half of all evaluations. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
951 if (simple_cst_equal (gimple_assign_rhs2 (stmt), value) != 1
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
952 || count < wrong_values
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
953 || optimize_bb_for_size_p (gimple_bb (stmt)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
954 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
955
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
956 /* Compute probability of taking the optimal path. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
957 all = count + wrong_values;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
958
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
959 if (check_counter (stmt, "pow2", &count, &all, gimple_bb (stmt)->count))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
960 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
961
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
962 if (dump_file)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
963 fprintf (dump_file, "Transformation done: mod power of 2\n");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
964
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
965 if (all > 0)
111
kono
parents: 67
diff changeset
966 prob = profile_probability::probability_in_gcov_type (count, all);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
967 else
111
kono
parents: 67
diff changeset
968 prob = profile_probability::never ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
969
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
970 result = gimple_mod_pow2 (stmt, prob, count, all);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
971
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
972 gimple_assign_set_rhs_from_tree (si, result);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
973 update_stmt (gsi_stmt (*si));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
974
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
975 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
976 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
977
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
978 /* Generate code for transformations 3 and 4 (with parent gimple assign STMT, and
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
979 NCOUNTS the number of cases to support. Currently only NCOUNTS==0 or 1 is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
980 supported and this is built into this interface. The probabilities of taking
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
981 the optimal paths are PROB1 and PROB2, which are equivalent to COUNT1/ALL and
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
982 COUNT2/ALL respectively within roundoff error). This generates the
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
983 result into a temp and returns the temp; it does not replace or alter
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
984 the original STMT. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
985 /* FIXME: Generalize the interface to handle NCOUNTS > 1. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
986
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
987 static tree
111
kono
parents: 67
diff changeset
988 gimple_mod_subtract (gassign *stmt, profile_probability prob1,
kono
parents: 67
diff changeset
989 profile_probability prob2, int ncounts,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
990 gcov_type count1, gcov_type count2, gcov_type all)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
991 {
111
kono
parents: 67
diff changeset
992 gassign *stmt1;
kono
parents: 67
diff changeset
993 gimple *stmt2;
kono
parents: 67
diff changeset
994 gcond *stmt3;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
995 tree tmp1;
111
kono
parents: 67
diff changeset
996 gimple *bb1end, *bb2end = NULL, *bb3end;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
997 basic_block bb, bb2, bb3, bb4;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
998 tree optype, op1, op2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
999 edge e12, e23 = 0, e24, e34, e14;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1000 gimple_stmt_iterator gsi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1001 tree result;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1002
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1003 gcc_assert (is_gimple_assign (stmt)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1004 && gimple_assign_rhs_code (stmt) == TRUNC_MOD_EXPR);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1005
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1006 optype = TREE_TYPE (gimple_assign_lhs (stmt));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1007 op1 = gimple_assign_rhs1 (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1008 op2 = gimple_assign_rhs2 (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1009
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1010 bb = gimple_bb (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1011 gsi = gsi_for_stmt (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1012
111
kono
parents: 67
diff changeset
1013 result = create_tmp_reg (optype, "PROF");
kono
parents: 67
diff changeset
1014 tmp1 = make_temp_ssa_name (optype, NULL, "PROF");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1015 stmt1 = gimple_build_assign (result, op1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1016 stmt2 = gimple_build_assign (tmp1, op2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1017 stmt3 = gimple_build_cond (LT_EXPR, result, tmp1, NULL_TREE, NULL_TREE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1018 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1019 gsi_insert_before (&gsi, stmt2, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1020 gsi_insert_before (&gsi, stmt3, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1021 bb1end = stmt3;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1022
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1023 if (ncounts) /* Assumed to be 0 or 1 */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1024 {
111
kono
parents: 67
diff changeset
1025 stmt1 = gimple_build_assign (result, MINUS_EXPR, result, tmp1);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1026 stmt2 = gimple_build_cond (LT_EXPR, result, tmp1, NULL_TREE, NULL_TREE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1027 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1028 gsi_insert_before (&gsi, stmt2, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1029 bb2end = stmt2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1030 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1031
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1032 /* Fallback case. */
111
kono
parents: 67
diff changeset
1033 stmt1 = gimple_build_assign (result, gimple_assign_rhs_code (stmt),
kono
parents: 67
diff changeset
1034 result, tmp1);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1035 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1036 bb3end = stmt1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1037
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1038 /* Fix CFG. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1039 /* Edge e23 connects bb2 to bb3, etc. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1040 /* However block 3 is optional; if it is not there, references
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1041 to 3 really refer to block 2. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1042 e12 = split_block (bb, bb1end);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1043 bb2 = e12->dest;
111
kono
parents: 67
diff changeset
1044 bb2->count = profile_count::from_gcov_type (all - count1);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1045
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1046 if (ncounts) /* Assumed to be 0 or 1. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1047 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1048 e23 = split_block (bb2, bb2end);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1049 bb3 = e23->dest;
111
kono
parents: 67
diff changeset
1050 bb3->count = profile_count::from_gcov_type (all - count1 - count2);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1051 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1052
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1053 e34 = split_block (ncounts ? bb3 : bb2, bb3end);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1054 bb4 = e34->dest;
111
kono
parents: 67
diff changeset
1055 bb4->count = profile_count::from_gcov_type (all);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1056
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1057 e12->flags &= ~EDGE_FALLTHRU;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1058 e12->flags |= EDGE_FALSE_VALUE;
111
kono
parents: 67
diff changeset
1059 e12->probability = prob1.invert ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1060
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1061 e14 = make_edge (bb, bb4, EDGE_TRUE_VALUE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1062 e14->probability = prob1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1063
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1064 if (ncounts) /* Assumed to be 0 or 1. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1065 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1066 e23->flags &= ~EDGE_FALLTHRU;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1067 e23->flags |= EDGE_FALSE_VALUE;
111
kono
parents: 67
diff changeset
1068 e23->probability = prob2.invert ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1069
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1070 e24 = make_edge (bb2, bb4, EDGE_TRUE_VALUE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1071 e24->probability = prob2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1072 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1073
111
kono
parents: 67
diff changeset
1074 e34->probability = profile_probability::always ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1075
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1076 return result;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1077 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1078
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1079 /* Do transforms 3) and 4) on the statement pointed-to by SI if applicable. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1080
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1081 static bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1082 gimple_mod_subtract_transform (gimple_stmt_iterator *si)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1083 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1084 histogram_value histogram;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1085 enum tree_code code;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1086 gcov_type count, wrong_values, all;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1087 tree lhs_type, result;
111
kono
parents: 67
diff changeset
1088 profile_probability prob1, prob2;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1089 unsigned int i, steps;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1090 gcov_type count1, count2;
111
kono
parents: 67
diff changeset
1091 gassign *stmt;
kono
parents: 67
diff changeset
1092 stmt = dyn_cast <gassign *> (gsi_stmt (*si));
kono
parents: 67
diff changeset
1093 if (!stmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1094 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1095
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1096 lhs_type = TREE_TYPE (gimple_assign_lhs (stmt));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1097 if (!INTEGRAL_TYPE_P (lhs_type))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1098 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1099
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1100 code = gimple_assign_rhs_code (stmt);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1101
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1102 if (code != TRUNC_MOD_EXPR || !TYPE_UNSIGNED (lhs_type))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1103 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1104
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1105 histogram = gimple_histogram_value_of_type (cfun, stmt, HIST_TYPE_INTERVAL);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1106 if (!histogram)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1107 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1108
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1109 all = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1110 wrong_values = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1111 for (i = 0; i < histogram->hdata.intvl.steps; i++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1112 all += histogram->hvalue.counters[i];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1113
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1114 wrong_values += histogram->hvalue.counters[i];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1115 wrong_values += histogram->hvalue.counters[i+1];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1116 steps = histogram->hdata.intvl.steps;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1117 all += wrong_values;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1118 count1 = histogram->hvalue.counters[0];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1119 count2 = histogram->hvalue.counters[1];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1120
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1121 /* Compute probability of taking the optimal path. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1122 if (check_counter (stmt, "interval", &count1, &all, gimple_bb (stmt)->count))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1123 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1124 gimple_remove_histogram_value (cfun, stmt, histogram);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1125 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1126 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1127
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1128 if (flag_profile_correction && count1 + count2 > all)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1129 all = count1 + count2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1130
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1131 gcc_assert (count1 + count2 <= all);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1132
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1133 /* We require that we use just subtractions in at least 50% of all
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1134 evaluations. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1135 count = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1136 for (i = 0; i < histogram->hdata.intvl.steps; i++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1137 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1138 count += histogram->hvalue.counters[i];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1139 if (count * 2 >= all)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1140 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1141 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1142 if (i == steps
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1143 || optimize_bb_for_size_p (gimple_bb (stmt)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1144 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1145
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1146 gimple_remove_histogram_value (cfun, stmt, histogram);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1147 if (dump_file)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1148 fprintf (dump_file, "Transformation done: mod subtract\n");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1149
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1150 /* Compute probability of taking the optimal path(s). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1151 if (all > 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1152 {
111
kono
parents: 67
diff changeset
1153 prob1 = profile_probability::probability_in_gcov_type (count1, all);
kono
parents: 67
diff changeset
1154 prob2 = profile_probability::probability_in_gcov_type (count2, all);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1155 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1156 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1157 {
111
kono
parents: 67
diff changeset
1158 prob1 = prob2 = profile_probability::never ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1159 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1160
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1161 /* In practice, "steps" is always 2. This interface reflects this,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1162 and will need to be changed if "steps" can change. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1163 result = gimple_mod_subtract (stmt, prob1, prob2, i, count1, count2, all);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1164
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1165 gimple_assign_set_rhs_from_tree (si, result);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1166 update_stmt (gsi_stmt (*si));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1167
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1168 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1169 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1170
111
kono
parents: 67
diff changeset
1171 typedef int_hash <unsigned int, 0, UINT_MAX> profile_id_hash;
kono
parents: 67
diff changeset
1172
kono
parents: 67
diff changeset
1173 static hash_map<profile_id_hash, cgraph_node *> *cgraph_node_map = 0;
kono
parents: 67
diff changeset
1174
kono
parents: 67
diff changeset
1175 /* Returns true if node graph is initialized. This
kono
parents: 67
diff changeset
1176 is used to test if profile_id has been created
kono
parents: 67
diff changeset
1177 for cgraph_nodes. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1178
111
kono
parents: 67
diff changeset
1179 bool
kono
parents: 67
diff changeset
1180 coverage_node_map_initialized_p (void)
kono
parents: 67
diff changeset
1181 {
kono
parents: 67
diff changeset
1182 return cgraph_node_map != 0;
kono
parents: 67
diff changeset
1183 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1184
111
kono
parents: 67
diff changeset
1185 /* Initialize map from PROFILE_ID to CGRAPH_NODE.
kono
parents: 67
diff changeset
1186 When LOCAL is true, the PROFILE_IDs are computed. when it is false we assume
kono
parents: 67
diff changeset
1187 that the PROFILE_IDs was already assigned. */
kono
parents: 67
diff changeset
1188
kono
parents: 67
diff changeset
1189 void
kono
parents: 67
diff changeset
1190 init_node_map (bool local)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1191 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1192 struct cgraph_node *n;
111
kono
parents: 67
diff changeset
1193 cgraph_node_map = new hash_map<profile_id_hash, cgraph_node *>;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1194
111
kono
parents: 67
diff changeset
1195 FOR_EACH_DEFINED_FUNCTION (n)
kono
parents: 67
diff changeset
1196 if (n->has_gimple_body_p ())
kono
parents: 67
diff changeset
1197 {
kono
parents: 67
diff changeset
1198 cgraph_node **val;
kono
parents: 67
diff changeset
1199 if (local)
kono
parents: 67
diff changeset
1200 {
kono
parents: 67
diff changeset
1201 n->profile_id = coverage_compute_profile_id (n);
kono
parents: 67
diff changeset
1202 while ((val = cgraph_node_map->get (n->profile_id))
kono
parents: 67
diff changeset
1203 || !n->profile_id)
kono
parents: 67
diff changeset
1204 {
kono
parents: 67
diff changeset
1205 if (dump_file)
kono
parents: 67
diff changeset
1206 fprintf (dump_file, "Local profile-id %i conflict"
kono
parents: 67
diff changeset
1207 " with nodes %s %s\n",
kono
parents: 67
diff changeset
1208 n->profile_id,
kono
parents: 67
diff changeset
1209 n->dump_name (),
kono
parents: 67
diff changeset
1210 (*val)->dump_name ());
kono
parents: 67
diff changeset
1211 n->profile_id = (n->profile_id + 1) & 0x7fffffff;
kono
parents: 67
diff changeset
1212 }
kono
parents: 67
diff changeset
1213 }
kono
parents: 67
diff changeset
1214 else if (!n->profile_id)
kono
parents: 67
diff changeset
1215 {
kono
parents: 67
diff changeset
1216 if (dump_file)
kono
parents: 67
diff changeset
1217 fprintf (dump_file,
kono
parents: 67
diff changeset
1218 "Node %s has no profile-id"
kono
parents: 67
diff changeset
1219 " (profile feedback missing?)\n",
kono
parents: 67
diff changeset
1220 n->dump_name ());
kono
parents: 67
diff changeset
1221 continue;
kono
parents: 67
diff changeset
1222 }
kono
parents: 67
diff changeset
1223 else if ((val = cgraph_node_map->get (n->profile_id)))
kono
parents: 67
diff changeset
1224 {
kono
parents: 67
diff changeset
1225 if (dump_file)
kono
parents: 67
diff changeset
1226 fprintf (dump_file,
kono
parents: 67
diff changeset
1227 "Node %s has IP profile-id %i conflict. "
kono
parents: 67
diff changeset
1228 "Giving up.\n",
kono
parents: 67
diff changeset
1229 n->dump_name (), n->profile_id);
kono
parents: 67
diff changeset
1230 *val = NULL;
kono
parents: 67
diff changeset
1231 continue;
kono
parents: 67
diff changeset
1232 }
kono
parents: 67
diff changeset
1233 cgraph_node_map->put (n->profile_id, n);
kono
parents: 67
diff changeset
1234 }
kono
parents: 67
diff changeset
1235 }
kono
parents: 67
diff changeset
1236
kono
parents: 67
diff changeset
1237 /* Delete the CGRAPH_NODE_MAP. */
kono
parents: 67
diff changeset
1238
kono
parents: 67
diff changeset
1239 void
kono
parents: 67
diff changeset
1240 del_node_map (void)
kono
parents: 67
diff changeset
1241 {
kono
parents: 67
diff changeset
1242 delete cgraph_node_map;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1243 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1244
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1245 /* Return cgraph node for function with pid */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1246
111
kono
parents: 67
diff changeset
1247 struct cgraph_node*
kono
parents: 67
diff changeset
1248 find_func_by_profile_id (int profile_id)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1249 {
111
kono
parents: 67
diff changeset
1250 cgraph_node **val = cgraph_node_map->get (profile_id);
kono
parents: 67
diff changeset
1251 if (val)
kono
parents: 67
diff changeset
1252 return *val;
kono
parents: 67
diff changeset
1253 else
kono
parents: 67
diff changeset
1254 return NULL;
kono
parents: 67
diff changeset
1255 }
kono
parents: 67
diff changeset
1256
kono
parents: 67
diff changeset
1257 /* Perform sanity check on the indirect call target. Due to race conditions,
kono
parents: 67
diff changeset
1258 false function target may be attributed to an indirect call site. If the
kono
parents: 67
diff changeset
1259 call expression type mismatches with the target function's type, expand_call
kono
parents: 67
diff changeset
1260 may ICE. Here we only do very minimal sanity check just to make compiler happy.
kono
parents: 67
diff changeset
1261 Returns true if TARGET is considered ok for call CALL_STMT. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1262
111
kono
parents: 67
diff changeset
1263 bool
kono
parents: 67
diff changeset
1264 check_ic_target (gcall *call_stmt, struct cgraph_node *target)
kono
parents: 67
diff changeset
1265 {
kono
parents: 67
diff changeset
1266 if (gimple_check_call_matching_types (call_stmt, target->decl, true))
kono
parents: 67
diff changeset
1267 return true;
kono
parents: 67
diff changeset
1268
kono
parents: 67
diff changeset
1269 if (dump_enabled_p ())
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1270 dump_printf_loc (MSG_MISSED_OPTIMIZATION, call_stmt,
111
kono
parents: 67
diff changeset
1271 "Skipping target %s with mismatching types for icall\n",
kono
parents: 67
diff changeset
1272 target->name ());
kono
parents: 67
diff changeset
1273 return false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1274 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1275
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1276 /* Do transformation
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1277
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1278 if (actual_callee_address == address_of_most_common_function/method)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1279 do direct call
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1280 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1281 old call
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1282 */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1283
111
kono
parents: 67
diff changeset
1284 gcall *
kono
parents: 67
diff changeset
1285 gimple_ic (gcall *icall_stmt, struct cgraph_node *direct_call,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1286 profile_probability prob)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1287 {
111
kono
parents: 67
diff changeset
1288 gcall *dcall_stmt;
kono
parents: 67
diff changeset
1289 gassign *load_stmt;
kono
parents: 67
diff changeset
1290 gcond *cond_stmt;
kono
parents: 67
diff changeset
1291 tree tmp0, tmp1, tmp;
kono
parents: 67
diff changeset
1292 basic_block cond_bb, dcall_bb, icall_bb, join_bb = NULL;
kono
parents: 67
diff changeset
1293 edge e_cd, e_ci, e_di, e_dj = NULL, e_ij;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1294 gimple_stmt_iterator gsi;
111
kono
parents: 67
diff changeset
1295 int lp_nr, dflags;
kono
parents: 67
diff changeset
1296 edge e_eh, e;
kono
parents: 67
diff changeset
1297 edge_iterator ei;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1298
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1299 cond_bb = gimple_bb (icall_stmt);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1300 gsi = gsi_for_stmt (icall_stmt);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1301
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1302 tmp0 = make_temp_ssa_name (ptr_type_node, NULL, "PROF");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1303 tmp1 = make_temp_ssa_name (ptr_type_node, NULL, "PROF");
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1304 tmp = unshare_expr (gimple_call_fn (icall_stmt));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1305 load_stmt = gimple_build_assign (tmp0, tmp);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1306 gsi_insert_before (&gsi, load_stmt, GSI_SAME_STMT);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1307
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1308 tmp = fold_convert (ptr_type_node, build_addr (direct_call->decl));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1309 load_stmt = gimple_build_assign (tmp1, tmp);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1310 gsi_insert_before (&gsi, load_stmt, GSI_SAME_STMT);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1311
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1312 cond_stmt = gimple_build_cond (EQ_EXPR, tmp1, tmp0, NULL_TREE, NULL_TREE);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1313 gsi_insert_before (&gsi, cond_stmt, GSI_SAME_STMT);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1314
111
kono
parents: 67
diff changeset
1315 if (TREE_CODE (gimple_vdef (icall_stmt)) == SSA_NAME)
kono
parents: 67
diff changeset
1316 {
kono
parents: 67
diff changeset
1317 unlink_stmt_vdef (icall_stmt);
kono
parents: 67
diff changeset
1318 release_ssa_name (gimple_vdef (icall_stmt));
kono
parents: 67
diff changeset
1319 }
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1320 gimple_set_vdef (icall_stmt, NULL_TREE);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1321 gimple_set_vuse (icall_stmt, NULL_TREE);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1322 update_stmt (icall_stmt);
111
kono
parents: 67
diff changeset
1323 dcall_stmt = as_a <gcall *> (gimple_copy (icall_stmt));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1324 gimple_call_set_fndecl (dcall_stmt, direct_call->decl);
111
kono
parents: 67
diff changeset
1325 dflags = flags_from_decl_or_type (direct_call->decl);
kono
parents: 67
diff changeset
1326 if ((dflags & ECF_NORETURN) != 0
kono
parents: 67
diff changeset
1327 && should_remove_lhs_p (gimple_call_lhs (dcall_stmt)))
kono
parents: 67
diff changeset
1328 gimple_call_set_lhs (dcall_stmt, NULL_TREE);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1329 gsi_insert_before (&gsi, dcall_stmt, GSI_SAME_STMT);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1330
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1331 /* Fix CFG. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1332 /* Edge e_cd connects cond_bb to dcall_bb, etc; note the first letters. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1333 e_cd = split_block (cond_bb, cond_stmt);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1334 dcall_bb = e_cd->dest;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1335 dcall_bb->count = cond_bb->count.apply_probability (prob);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1336
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1337 e_di = split_block (dcall_bb, dcall_stmt);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1338 icall_bb = e_di->dest;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1339 icall_bb->count = cond_bb->count - dcall_bb->count;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1340
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1341 /* Do not disturb existing EH edges from the indirect call. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1342 if (!stmt_ends_bb_p (icall_stmt))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1343 e_ij = split_block (icall_bb, icall_stmt);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1344 else
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1345 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1346 e_ij = find_fallthru_edge (icall_bb->succs);
111
kono
parents: 67
diff changeset
1347 /* The indirect call might be noreturn. */
kono
parents: 67
diff changeset
1348 if (e_ij != NULL)
kono
parents: 67
diff changeset
1349 {
kono
parents: 67
diff changeset
1350 e_ij->probability = profile_probability::always ();
kono
parents: 67
diff changeset
1351 e_ij = single_pred_edge (split_edge (e_ij));
kono
parents: 67
diff changeset
1352 }
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1353 }
111
kono
parents: 67
diff changeset
1354 if (e_ij != NULL)
kono
parents: 67
diff changeset
1355 {
kono
parents: 67
diff changeset
1356 join_bb = e_ij->dest;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1357 join_bb->count = cond_bb->count;
111
kono
parents: 67
diff changeset
1358 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1359
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1360 e_cd->flags = (e_cd->flags & ~EDGE_FALLTHRU) | EDGE_TRUE_VALUE;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1361 e_cd->probability = prob;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1362
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1363 e_ci = make_edge (cond_bb, icall_bb, EDGE_FALSE_VALUE);
111
kono
parents: 67
diff changeset
1364 e_ci->probability = prob.invert ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1365
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1366 remove_edge (e_di);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1367
111
kono
parents: 67
diff changeset
1368 if (e_ij != NULL)
kono
parents: 67
diff changeset
1369 {
kono
parents: 67
diff changeset
1370 if ((dflags & ECF_NORETURN) == 0)
kono
parents: 67
diff changeset
1371 {
kono
parents: 67
diff changeset
1372 e_dj = make_edge (dcall_bb, join_bb, EDGE_FALLTHRU);
kono
parents: 67
diff changeset
1373 e_dj->probability = profile_probability::always ();
kono
parents: 67
diff changeset
1374 }
kono
parents: 67
diff changeset
1375 e_ij->probability = profile_probability::always ();
kono
parents: 67
diff changeset
1376 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1377
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1378 /* Insert PHI node for the call result if necessary. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1379 if (gimple_call_lhs (icall_stmt)
111
kono
parents: 67
diff changeset
1380 && TREE_CODE (gimple_call_lhs (icall_stmt)) == SSA_NAME
kono
parents: 67
diff changeset
1381 && (dflags & ECF_NORETURN) == 0)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1382 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1383 tree result = gimple_call_lhs (icall_stmt);
111
kono
parents: 67
diff changeset
1384 gphi *phi = create_phi_node (result, join_bb);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1385 gimple_call_set_lhs (icall_stmt,
111
kono
parents: 67
diff changeset
1386 duplicate_ssa_name (result, icall_stmt));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1387 add_phi_arg (phi, gimple_call_lhs (icall_stmt), e_ij, UNKNOWN_LOCATION);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1388 gimple_call_set_lhs (dcall_stmt,
111
kono
parents: 67
diff changeset
1389 duplicate_ssa_name (result, dcall_stmt));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1390 add_phi_arg (phi, gimple_call_lhs (dcall_stmt), e_dj, UNKNOWN_LOCATION);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1391 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1392
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1393 /* Build an EH edge for the direct call if necessary. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1394 lp_nr = lookup_stmt_eh_lp (icall_stmt);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1395 if (lp_nr > 0 && stmt_could_throw_p (cfun, dcall_stmt))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1396 {
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1397 add_stmt_to_eh_lp (dcall_stmt, lp_nr);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1398 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1399
111
kono
parents: 67
diff changeset
1400 FOR_EACH_EDGE (e_eh, ei, icall_bb->succs)
kono
parents: 67
diff changeset
1401 if (e_eh->flags & (EDGE_EH | EDGE_ABNORMAL))
kono
parents: 67
diff changeset
1402 {
kono
parents: 67
diff changeset
1403 e = make_edge (dcall_bb, e_eh->dest, e_eh->flags);
kono
parents: 67
diff changeset
1404 e->probability = e_eh->probability;
kono
parents: 67
diff changeset
1405 for (gphi_iterator psi = gsi_start_phis (e_eh->dest);
kono
parents: 67
diff changeset
1406 !gsi_end_p (psi); gsi_next (&psi))
kono
parents: 67
diff changeset
1407 {
kono
parents: 67
diff changeset
1408 gphi *phi = psi.phi ();
kono
parents: 67
diff changeset
1409 SET_USE (PHI_ARG_DEF_PTR_FROM_EDGE (phi, e),
kono
parents: 67
diff changeset
1410 PHI_ARG_DEF_FROM_EDGE (phi, e_eh));
kono
parents: 67
diff changeset
1411 }
kono
parents: 67
diff changeset
1412 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1413 if (!stmt_could_throw_p (cfun, dcall_stmt))
111
kono
parents: 67
diff changeset
1414 gimple_purge_dead_eh_edges (dcall_bb);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1415 return dcall_stmt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1416 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1417
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1418 /*
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1419 For every checked indirect/virtual call determine if most common pid of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1420 function/class method has probability more than 50%. If yes modify code of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1421 this call to:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1422 */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1423
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1424 static bool
111
kono
parents: 67
diff changeset
1425 gimple_ic_transform (gimple_stmt_iterator *gsi)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1426 {
111
kono
parents: 67
diff changeset
1427 gcall *stmt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1428 histogram_value histogram;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1429 gcov_type val, count, all, bb_all;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1430 struct cgraph_node *direct_call;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1431
111
kono
parents: 67
diff changeset
1432 stmt = dyn_cast <gcall *> (gsi_stmt (*gsi));
kono
parents: 67
diff changeset
1433 if (!stmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1434 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1435
111
kono
parents: 67
diff changeset
1436 if (gimple_call_fndecl (stmt) != NULL_TREE)
kono
parents: 67
diff changeset
1437 return false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1438
111
kono
parents: 67
diff changeset
1439 if (gimple_call_internal_p (stmt))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1440 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1441
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1442 histogram = gimple_histogram_value_of_type (cfun, stmt, HIST_TYPE_INDIR_CALL);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1443 if (!histogram)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1444 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1445
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1446 val = histogram->hvalue.counters [0];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1447 count = histogram->hvalue.counters [1];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1448 all = histogram->hvalue.counters [2];
111
kono
parents: 67
diff changeset
1449
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1450 bb_all = gimple_bb (stmt)->count.ipa ().to_gcov_type ();
111
kono
parents: 67
diff changeset
1451 /* The order of CHECK_COUNTER calls is important -
kono
parents: 67
diff changeset
1452 since check_counter can correct the third parameter
kono
parents: 67
diff changeset
1453 and we want to make count <= all <= bb_all. */
kono
parents: 67
diff changeset
1454 if (check_counter (stmt, "ic", &all, &bb_all, gimple_bb (stmt)->count)
kono
parents: 67
diff changeset
1455 || check_counter (stmt, "ic", &count, &all,
kono
parents: 67
diff changeset
1456 profile_count::from_gcov_type (all)))
kono
parents: 67
diff changeset
1457 {
kono
parents: 67
diff changeset
1458 gimple_remove_histogram_value (cfun, stmt, histogram);
kono
parents: 67
diff changeset
1459 return false;
kono
parents: 67
diff changeset
1460 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1461
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1462 if (4 * count <= 3 * all)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1463 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1464
111
kono
parents: 67
diff changeset
1465 direct_call = find_func_by_profile_id ((int)val);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1466
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1467 if (direct_call == NULL)
111
kono
parents: 67
diff changeset
1468 {
kono
parents: 67
diff changeset
1469 if (val)
kono
parents: 67
diff changeset
1470 {
kono
parents: 67
diff changeset
1471 if (dump_file)
kono
parents: 67
diff changeset
1472 {
kono
parents: 67
diff changeset
1473 fprintf (dump_file, "Indirect call -> direct call from other module");
kono
parents: 67
diff changeset
1474 print_generic_expr (dump_file, gimple_call_fn (stmt), TDF_SLIM);
kono
parents: 67
diff changeset
1475 fprintf (dump_file, "=> %i (will resolve only with LTO)\n", (int)val);
kono
parents: 67
diff changeset
1476 }
kono
parents: 67
diff changeset
1477 }
kono
parents: 67
diff changeset
1478 return false;
kono
parents: 67
diff changeset
1479 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1480
111
kono
parents: 67
diff changeset
1481 if (!check_ic_target (stmt, direct_call))
kono
parents: 67
diff changeset
1482 {
kono
parents: 67
diff changeset
1483 if (dump_file)
kono
parents: 67
diff changeset
1484 {
kono
parents: 67
diff changeset
1485 fprintf (dump_file, "Indirect call -> direct call ");
kono
parents: 67
diff changeset
1486 print_generic_expr (dump_file, gimple_call_fn (stmt), TDF_SLIM);
kono
parents: 67
diff changeset
1487 fprintf (dump_file, "=> ");
kono
parents: 67
diff changeset
1488 print_generic_expr (dump_file, direct_call->decl, TDF_SLIM);
kono
parents: 67
diff changeset
1489 fprintf (dump_file, " transformation skipped because of type mismatch");
kono
parents: 67
diff changeset
1490 print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
kono
parents: 67
diff changeset
1491 }
kono
parents: 67
diff changeset
1492 gimple_remove_histogram_value (cfun, stmt, histogram);
kono
parents: 67
diff changeset
1493 return false;
kono
parents: 67
diff changeset
1494 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1495
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1496 if (dump_file)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1497 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1498 fprintf (dump_file, "Indirect call -> direct call ");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1499 print_generic_expr (dump_file, gimple_call_fn (stmt), TDF_SLIM);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1500 fprintf (dump_file, "=> ");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1501 print_generic_expr (dump_file, direct_call->decl, TDF_SLIM);
111
kono
parents: 67
diff changeset
1502 fprintf (dump_file, " transformation on insn postponned to ipa-profile");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1503 print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
111
kono
parents: 67
diff changeset
1504 fprintf (dump_file, "hist->count %" PRId64
kono
parents: 67
diff changeset
1505 " hist->all %" PRId64"\n", count, all);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1506 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1507
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1508 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1509 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1510
111
kono
parents: 67
diff changeset
1511 /* Return true if the stringop CALL shall be profiled. SIZE_ARG be
kono
parents: 67
diff changeset
1512 set to the argument index for the size of the string operation. */
kono
parents: 67
diff changeset
1513
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1514 static bool
111
kono
parents: 67
diff changeset
1515 interesting_stringop_to_profile_p (gcall *call, int *size_arg)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1516 {
111
kono
parents: 67
diff changeset
1517 enum built_in_function fcode;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1518
111
kono
parents: 67
diff changeset
1519 fcode = DECL_FUNCTION_CODE (gimple_call_fndecl (call));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1520 switch (fcode)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1521 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1522 case BUILT_IN_MEMCPY:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1523 case BUILT_IN_MEMPCPY:
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1524 case BUILT_IN_MEMMOVE:
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1525 *size_arg = 2;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1526 return validate_gimple_arglist (call, POINTER_TYPE, POINTER_TYPE,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1527 INTEGER_TYPE, VOID_TYPE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1528 case BUILT_IN_MEMSET:
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1529 *size_arg = 2;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1530 return validate_gimple_arglist (call, POINTER_TYPE, INTEGER_TYPE,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1531 INTEGER_TYPE, VOID_TYPE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1532 case BUILT_IN_BZERO:
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1533 *size_arg = 1;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1534 return validate_gimple_arglist (call, POINTER_TYPE, INTEGER_TYPE,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1535 VOID_TYPE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1536 default:
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1537 return false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1538 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1539 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1540
111
kono
parents: 67
diff changeset
1541 /* Convert stringop (..., vcall_size)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1542 into
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1543 if (vcall_size == icall_size)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1544 stringop (..., icall_size);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1545 else
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1546 stringop (..., vcall_size);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1547 assuming we'll propagate a true constant into ICALL_SIZE later. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1548
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1549 static void
111
kono
parents: 67
diff changeset
1550 gimple_stringop_fixed_value (gcall *vcall_stmt, tree icall_size, profile_probability prob,
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1551 gcov_type count, gcov_type all)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1552 {
111
kono
parents: 67
diff changeset
1553 gassign *tmp_stmt;
kono
parents: 67
diff changeset
1554 gcond *cond_stmt;
kono
parents: 67
diff changeset
1555 gcall *icall_stmt;
kono
parents: 67
diff changeset
1556 tree tmp0, tmp1, vcall_size, optype;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1557 basic_block cond_bb, icall_bb, vcall_bb, join_bb;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1558 edge e_ci, e_cv, e_iv, e_ij, e_vj;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1559 gimple_stmt_iterator gsi;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1560 int size_arg;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1561
111
kono
parents: 67
diff changeset
1562 if (!interesting_stringop_to_profile_p (vcall_stmt, &size_arg))
kono
parents: 67
diff changeset
1563 gcc_unreachable ();
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1564
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1565 cond_bb = gimple_bb (vcall_stmt);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1566 gsi = gsi_for_stmt (vcall_stmt);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1567
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1568 vcall_size = gimple_call_arg (vcall_stmt, size_arg);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1569 optype = TREE_TYPE (vcall_size);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1570
111
kono
parents: 67
diff changeset
1571 tmp0 = make_temp_ssa_name (optype, NULL, "PROF");
kono
parents: 67
diff changeset
1572 tmp1 = make_temp_ssa_name (optype, NULL, "PROF");
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1573 tmp_stmt = gimple_build_assign (tmp0, fold_convert (optype, icall_size));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1574 gsi_insert_before (&gsi, tmp_stmt, GSI_SAME_STMT);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1575
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1576 tmp_stmt = gimple_build_assign (tmp1, vcall_size);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1577 gsi_insert_before (&gsi, tmp_stmt, GSI_SAME_STMT);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1578
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1579 cond_stmt = gimple_build_cond (EQ_EXPR, tmp1, tmp0, NULL_TREE, NULL_TREE);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1580 gsi_insert_before (&gsi, cond_stmt, GSI_SAME_STMT);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1581
111
kono
parents: 67
diff changeset
1582 if (TREE_CODE (gimple_vdef (vcall_stmt)) == SSA_NAME)
kono
parents: 67
diff changeset
1583 {
kono
parents: 67
diff changeset
1584 unlink_stmt_vdef (vcall_stmt);
kono
parents: 67
diff changeset
1585 release_ssa_name (gimple_vdef (vcall_stmt));
kono
parents: 67
diff changeset
1586 }
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1587 gimple_set_vdef (vcall_stmt, NULL);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1588 gimple_set_vuse (vcall_stmt, NULL);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1589 update_stmt (vcall_stmt);
111
kono
parents: 67
diff changeset
1590 icall_stmt = as_a <gcall *> (gimple_copy (vcall_stmt));
kono
parents: 67
diff changeset
1591 gimple_call_set_arg (icall_stmt, size_arg,
kono
parents: 67
diff changeset
1592 fold_convert (optype, icall_size));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1593 gsi_insert_before (&gsi, icall_stmt, GSI_SAME_STMT);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1594
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1595 /* Fix CFG. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1596 /* Edge e_ci connects cond_bb to icall_bb, etc. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1597 e_ci = split_block (cond_bb, cond_stmt);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1598 icall_bb = e_ci->dest;
111
kono
parents: 67
diff changeset
1599 icall_bb->count = profile_count::from_gcov_type (count);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1600
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1601 e_iv = split_block (icall_bb, icall_stmt);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1602 vcall_bb = e_iv->dest;
111
kono
parents: 67
diff changeset
1603 vcall_bb->count = profile_count::from_gcov_type (all - count);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1604
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1605 e_vj = split_block (vcall_bb, vcall_stmt);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1606 join_bb = e_vj->dest;
111
kono
parents: 67
diff changeset
1607 join_bb->count = profile_count::from_gcov_type (all);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1608
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1609 e_ci->flags = (e_ci->flags & ~EDGE_FALLTHRU) | EDGE_TRUE_VALUE;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1610 e_ci->probability = prob;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1611
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1612 e_cv = make_edge (cond_bb, vcall_bb, EDGE_FALSE_VALUE);
111
kono
parents: 67
diff changeset
1613 e_cv->probability = prob.invert ();
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1614
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1615 remove_edge (e_iv);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1616
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1617 e_ij = make_edge (icall_bb, join_bb, EDGE_FALLTHRU);
111
kono
parents: 67
diff changeset
1618 e_ij->probability = profile_probability::always ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1619
111
kono
parents: 67
diff changeset
1620 e_vj->probability = profile_probability::always ();
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1621
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1622 /* Insert PHI node for the call result if necessary. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1623 if (gimple_call_lhs (vcall_stmt)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1624 && TREE_CODE (gimple_call_lhs (vcall_stmt)) == SSA_NAME)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1625 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1626 tree result = gimple_call_lhs (vcall_stmt);
111
kono
parents: 67
diff changeset
1627 gphi *phi = create_phi_node (result, join_bb);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1628 gimple_call_set_lhs (vcall_stmt,
111
kono
parents: 67
diff changeset
1629 duplicate_ssa_name (result, vcall_stmt));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1630 add_phi_arg (phi, gimple_call_lhs (vcall_stmt), e_vj, UNKNOWN_LOCATION);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1631 gimple_call_set_lhs (icall_stmt,
111
kono
parents: 67
diff changeset
1632 duplicate_ssa_name (result, icall_stmt));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1633 add_phi_arg (phi, gimple_call_lhs (icall_stmt), e_ij, UNKNOWN_LOCATION);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1634 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1635
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1636 /* Because these are all string op builtins, they're all nothrow. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1637 gcc_assert (!stmt_could_throw_p (cfun, vcall_stmt));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1638 gcc_assert (!stmt_could_throw_p (cfun, icall_stmt));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1639 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1640
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1641 /* Find values inside STMT for that we want to measure histograms for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1642 division/modulo optimization. */
111
kono
parents: 67
diff changeset
1643
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1644 static bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1645 gimple_stringops_transform (gimple_stmt_iterator *gsi)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1646 {
111
kono
parents: 67
diff changeset
1647 gcall *stmt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1648 tree blck_size;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1649 enum built_in_function fcode;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1650 histogram_value histogram;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1651 gcov_type count, all, val;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1652 tree dest, src;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1653 unsigned int dest_align, src_align;
111
kono
parents: 67
diff changeset
1654 profile_probability prob;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1655 tree tree_val;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1656 int size_arg;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1657
111
kono
parents: 67
diff changeset
1658 stmt = dyn_cast <gcall *> (gsi_stmt (*gsi));
kono
parents: 67
diff changeset
1659 if (!stmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1660 return false;
111
kono
parents: 67
diff changeset
1661
kono
parents: 67
diff changeset
1662 if (!gimple_call_builtin_p (gsi_stmt (*gsi), BUILT_IN_NORMAL))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1663 return false;
111
kono
parents: 67
diff changeset
1664
kono
parents: 67
diff changeset
1665 if (!interesting_stringop_to_profile_p (stmt, &size_arg))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1666 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1667
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1668 blck_size = gimple_call_arg (stmt, size_arg);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1669 if (TREE_CODE (blck_size) == INTEGER_CST)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1670 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1671
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1672 histogram = gimple_histogram_value_of_type (cfun, stmt, HIST_TYPE_SINGLE_VALUE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1673 if (!histogram)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1674 return false;
111
kono
parents: 67
diff changeset
1675
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1676 val = histogram->hvalue.counters[0];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1677 count = histogram->hvalue.counters[1];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1678 all = histogram->hvalue.counters[2];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1679 gimple_remove_histogram_value (cfun, stmt, histogram);
111
kono
parents: 67
diff changeset
1680
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1681 /* We require that count is at least half of all; this means
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1682 that for the transformation to fire the value must be constant
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1683 at least 80% of time. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1684 if ((6 * count / 5) < all || optimize_bb_for_size_p (gimple_bb (stmt)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1685 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1686 if (check_counter (stmt, "value", &count, &all, gimple_bb (stmt)->count))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1687 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1688 if (all > 0)
111
kono
parents: 67
diff changeset
1689 prob = profile_probability::probability_in_gcov_type (count, all);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1690 else
111
kono
parents: 67
diff changeset
1691 prob = profile_probability::never ();
kono
parents: 67
diff changeset
1692
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1693 dest = gimple_call_arg (stmt, 0);
111
kono
parents: 67
diff changeset
1694 dest_align = get_pointer_alignment (dest);
kono
parents: 67
diff changeset
1695 fcode = DECL_FUNCTION_CODE (gimple_call_fndecl (stmt));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1696 switch (fcode)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1697 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1698 case BUILT_IN_MEMCPY:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1699 case BUILT_IN_MEMPCPY:
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1700 case BUILT_IN_MEMMOVE:
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1701 src = gimple_call_arg (stmt, 1);
111
kono
parents: 67
diff changeset
1702 src_align = get_pointer_alignment (src);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1703 if (!can_move_by_pieces (val, MIN (dest_align, src_align)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1704 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1705 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1706 case BUILT_IN_MEMSET:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1707 if (!can_store_by_pieces (val, builtin_memset_read_str,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1708 gimple_call_arg (stmt, 1),
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1709 dest_align, true))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1710 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1711 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1712 case BUILT_IN_BZERO:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1713 if (!can_store_by_pieces (val, builtin_memset_read_str,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1714 integer_zero_node,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1715 dest_align, true))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1716 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1717 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1718 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1719 gcc_unreachable ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1720 }
111
kono
parents: 67
diff changeset
1721
kono
parents: 67
diff changeset
1722 if (sizeof (gcov_type) == sizeof (HOST_WIDE_INT))
kono
parents: 67
diff changeset
1723 tree_val = build_int_cst (get_gcov_type (), val);
kono
parents: 67
diff changeset
1724 else
kono
parents: 67
diff changeset
1725 {
kono
parents: 67
diff changeset
1726 HOST_WIDE_INT a[2];
kono
parents: 67
diff changeset
1727 a[0] = (unsigned HOST_WIDE_INT) val;
kono
parents: 67
diff changeset
1728 a[1] = val >> (HOST_BITS_PER_WIDE_INT - 1) >> 1;
kono
parents: 67
diff changeset
1729
kono
parents: 67
diff changeset
1730 tree_val = wide_int_to_tree (get_gcov_type (), wide_int::from_array (a, 2,
kono
parents: 67
diff changeset
1731 TYPE_PRECISION (get_gcov_type ()), false));
kono
parents: 67
diff changeset
1732 }
kono
parents: 67
diff changeset
1733
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1734 if (dump_file)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1735 fprintf (dump_file,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1736 "Transformation done: single value %i stringop for %s\n",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1737 (int)val, built_in_names[(int)fcode]);
111
kono
parents: 67
diff changeset
1738
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1739 gimple_stringop_fixed_value (stmt, tree_val, prob, count, all);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1740
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1741 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1742 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1743
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1744 void
111
kono
parents: 67
diff changeset
1745 stringop_block_profile (gimple *stmt, unsigned int *expected_align,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1746 HOST_WIDE_INT *expected_size)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1747 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1748 histogram_value histogram;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1749 histogram = gimple_histogram_value_of_type (cfun, stmt, HIST_TYPE_AVERAGE);
111
kono
parents: 67
diff changeset
1750
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1751 if (!histogram)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1752 *expected_size = -1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1753 else if (!histogram->hvalue.counters[1])
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1754 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1755 *expected_size = -1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1756 gimple_remove_histogram_value (cfun, stmt, histogram);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1757 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1758 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1759 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1760 gcov_type size;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1761 size = ((histogram->hvalue.counters[0]
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1762 + histogram->hvalue.counters[1] / 2)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1763 / histogram->hvalue.counters[1]);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1764 /* Even if we can hold bigger value in SIZE, INT_MAX
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1765 is safe "infinity" for code generation strategies. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1766 if (size > INT_MAX)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1767 size = INT_MAX;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1768 *expected_size = size;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1769 gimple_remove_histogram_value (cfun, stmt, histogram);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1770 }
111
kono
parents: 67
diff changeset
1771
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1772 histogram = gimple_histogram_value_of_type (cfun, stmt, HIST_TYPE_IOR);
111
kono
parents: 67
diff changeset
1773
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1774 if (!histogram)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1775 *expected_align = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1776 else if (!histogram->hvalue.counters[0])
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1777 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1778 gimple_remove_histogram_value (cfun, stmt, histogram);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1779 *expected_align = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1780 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1781 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1782 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1783 gcov_type count;
111
kono
parents: 67
diff changeset
1784 unsigned int alignment;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1785
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1786 count = histogram->hvalue.counters[0];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1787 alignment = 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1788 while (!(count & alignment)
111
kono
parents: 67
diff changeset
1789 && (alignment <= UINT_MAX / 2 / BITS_PER_UNIT))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1790 alignment <<= 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1791 *expected_align = alignment * BITS_PER_UNIT;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1792 gimple_remove_histogram_value (cfun, stmt, histogram);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1793 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1794 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1795
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1796
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1797 /* Find values inside STMT for that we want to measure histograms for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1798 division/modulo optimization. */
111
kono
parents: 67
diff changeset
1799
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1800 static void
111
kono
parents: 67
diff changeset
1801 gimple_divmod_values_to_profile (gimple *stmt, histogram_values *values)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1802 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1803 tree lhs, divisor, op0, type;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1804 histogram_value hist;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1805
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1806 if (gimple_code (stmt) != GIMPLE_ASSIGN)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1807 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1808
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1809 lhs = gimple_assign_lhs (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1810 type = TREE_TYPE (lhs);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1811 if (!INTEGRAL_TYPE_P (type))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1812 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1813
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1814 switch (gimple_assign_rhs_code (stmt))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1815 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1816 case TRUNC_DIV_EXPR:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1817 case TRUNC_MOD_EXPR:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1818 divisor = gimple_assign_rhs2 (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1819 op0 = gimple_assign_rhs1 (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1820
111
kono
parents: 67
diff changeset
1821 values->reserve (3);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1822
111
kono
parents: 67
diff changeset
1823 if (TREE_CODE (divisor) == SSA_NAME)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1824 /* Check for the case where the divisor is the same value most
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1825 of the time. */
111
kono
parents: 67
diff changeset
1826 values->quick_push (gimple_alloc_histogram_value (cfun,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1827 HIST_TYPE_SINGLE_VALUE,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1828 stmt, divisor));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1829
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1830 /* For mod, check whether it is not often a noop (or replaceable by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1831 a few subtractions). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1832 if (gimple_assign_rhs_code (stmt) == TRUNC_MOD_EXPR
111
kono
parents: 67
diff changeset
1833 && TYPE_UNSIGNED (type)
kono
parents: 67
diff changeset
1834 && TREE_CODE (divisor) == SSA_NAME)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1835 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1836 tree val;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1837 /* Check for a special case where the divisor is power of 2. */
111
kono
parents: 67
diff changeset
1838 values->quick_push (gimple_alloc_histogram_value (cfun,
kono
parents: 67
diff changeset
1839 HIST_TYPE_POW2,
kono
parents: 67
diff changeset
1840 stmt, divisor));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1841
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1842 val = build2 (TRUNC_DIV_EXPR, type, op0, divisor);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1843 hist = gimple_alloc_histogram_value (cfun, HIST_TYPE_INTERVAL,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1844 stmt, val);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1845 hist->hdata.intvl.int_start = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1846 hist->hdata.intvl.steps = 2;
111
kono
parents: 67
diff changeset
1847 values->quick_push (hist);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1848 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1849 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1850
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1851 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1852 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1853 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1854 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1855
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1856 /* Find calls inside STMT for that we want to measure histograms for
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1857 indirect/virtual call optimization. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1858
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1859 static void
111
kono
parents: 67
diff changeset
1860 gimple_indirect_call_to_profile (gimple *stmt, histogram_values *values)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1861 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1862 tree callee;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1863
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1864 if (gimple_code (stmt) != GIMPLE_CALL
111
kono
parents: 67
diff changeset
1865 || gimple_call_internal_p (stmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1866 || gimple_call_fndecl (stmt) != NULL_TREE)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1867 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1868
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1869 callee = gimple_call_fn (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1870
111
kono
parents: 67
diff changeset
1871 values->reserve (3);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1872
111
kono
parents: 67
diff changeset
1873 values->quick_push (gimple_alloc_histogram_value (
kono
parents: 67
diff changeset
1874 cfun,
kono
parents: 67
diff changeset
1875 PARAM_VALUE (PARAM_INDIR_CALL_TOPN_PROFILE) ?
kono
parents: 67
diff changeset
1876 HIST_TYPE_INDIR_CALL_TOPN :
kono
parents: 67
diff changeset
1877 HIST_TYPE_INDIR_CALL,
kono
parents: 67
diff changeset
1878 stmt, callee));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1879
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1880 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1881 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1882
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1883 /* Find values inside STMT for that we want to measure histograms for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1884 string operations. */
111
kono
parents: 67
diff changeset
1885
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1886 static void
111
kono
parents: 67
diff changeset
1887 gimple_stringops_values_to_profile (gimple *gs, histogram_values *values)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1888 {
111
kono
parents: 67
diff changeset
1889 gcall *stmt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1890 tree blck_size;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1891 tree dest;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1892 int size_arg;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1893
111
kono
parents: 67
diff changeset
1894 stmt = dyn_cast <gcall *> (gs);
kono
parents: 67
diff changeset
1895 if (!stmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1896 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1897
111
kono
parents: 67
diff changeset
1898 if (!gimple_call_builtin_p (gs, BUILT_IN_NORMAL))
kono
parents: 67
diff changeset
1899 return;
kono
parents: 67
diff changeset
1900
kono
parents: 67
diff changeset
1901 if (!interesting_stringop_to_profile_p (stmt, &size_arg))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1902 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1903
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1904 dest = gimple_call_arg (stmt, 0);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1905 blck_size = gimple_call_arg (stmt, size_arg);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1906
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1907 if (TREE_CODE (blck_size) != INTEGER_CST)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1908 {
111
kono
parents: 67
diff changeset
1909 values->safe_push (gimple_alloc_histogram_value (cfun,
kono
parents: 67
diff changeset
1910 HIST_TYPE_SINGLE_VALUE,
kono
parents: 67
diff changeset
1911 stmt, blck_size));
kono
parents: 67
diff changeset
1912 values->safe_push (gimple_alloc_histogram_value (cfun, HIST_TYPE_AVERAGE,
kono
parents: 67
diff changeset
1913 stmt, blck_size));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1914 }
111
kono
parents: 67
diff changeset
1915
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1916 if (TREE_CODE (blck_size) != INTEGER_CST)
111
kono
parents: 67
diff changeset
1917 values->safe_push (gimple_alloc_histogram_value (cfun, HIST_TYPE_IOR,
kono
parents: 67
diff changeset
1918 stmt, dest));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1919 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1920
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1921 /* Find values inside STMT for that we want to measure histograms and adds
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1922 them to list VALUES. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1923
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1924 static void
111
kono
parents: 67
diff changeset
1925 gimple_values_to_profile (gimple *stmt, histogram_values *values)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1926 {
111
kono
parents: 67
diff changeset
1927 gimple_divmod_values_to_profile (stmt, values);
kono
parents: 67
diff changeset
1928 gimple_stringops_values_to_profile (stmt, values);
kono
parents: 67
diff changeset
1929 gimple_indirect_call_to_profile (stmt, values);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1930 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1931
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1932 void
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1933 gimple_find_values_to_profile (histogram_values *values)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1934 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1935 basic_block bb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1936 gimple_stmt_iterator gsi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1937 unsigned i;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1938 histogram_value hist = NULL;
111
kono
parents: 67
diff changeset
1939 values->create (0);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1940
111
kono
parents: 67
diff changeset
1941 FOR_EACH_BB_FN (bb, cfun)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1942 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1943 gimple_values_to_profile (gsi_stmt (gsi), values);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1944
111
kono
parents: 67
diff changeset
1945 values->safe_push (gimple_alloc_histogram_value (cfun, HIST_TYPE_TIME_PROFILE, 0, 0));
kono
parents: 67
diff changeset
1946
kono
parents: 67
diff changeset
1947 FOR_EACH_VEC_ELT (*values, i, hist)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1948 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1949 switch (hist->type)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1950 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1951 case HIST_TYPE_INTERVAL:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1952 hist->n_counters = hist->hdata.intvl.steps + 2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1953 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1954
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1955 case HIST_TYPE_POW2:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1956 hist->n_counters = 2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1957 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1958
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1959 case HIST_TYPE_SINGLE_VALUE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1960 hist->n_counters = 3;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1961 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1962
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1963 case HIST_TYPE_INDIR_CALL:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1964 hist->n_counters = 3;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1965 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1966
111
kono
parents: 67
diff changeset
1967 case HIST_TYPE_TIME_PROFILE:
kono
parents: 67
diff changeset
1968 hist->n_counters = 1;
kono
parents: 67
diff changeset
1969 break;
kono
parents: 67
diff changeset
1970
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1971 case HIST_TYPE_AVERAGE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1972 hist->n_counters = 2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1973 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1974
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1975 case HIST_TYPE_IOR:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1976 hist->n_counters = 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1977 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1978
111
kono
parents: 67
diff changeset
1979 case HIST_TYPE_INDIR_CALL_TOPN:
kono
parents: 67
diff changeset
1980 hist->n_counters = GCOV_ICALL_TOPN_NCOUNTS;
kono
parents: 67
diff changeset
1981 break;
kono
parents: 67
diff changeset
1982
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1983 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1984 gcc_unreachable ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1985 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1986 if (dump_file && hist->hvalue.stmt != NULL)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1987 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1988 fprintf (dump_file, "Stmt ");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1989 print_gimple_stmt (dump_file, hist->hvalue.stmt, 0, TDF_SLIM);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1990 dump_histogram_value (dump_file, hist);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1991 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1992 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1993 }