Mercurial > hg > CbC > CbC_gcc
annotate gcc/ipa-reference.c @ 143:76e1cf5455ef
add cbc_gc test
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 23 Dec 2018 19:24:05 +0900 |
parents | 84e7813d76e9 |
children | 1830386684a0 |
rev | line source |
---|---|
0 | 1 /* Callgraph based analysis of static variables. |
131 | 2 Copyright (C) 2004-2018 Free Software Foundation, Inc. |
0 | 3 Contributed by Kenneth Zadeck <zadeck@naturalbridge.com> |
4 | |
5 This file is part of GCC. | |
6 | |
7 GCC is free software; you can redistribute it and/or modify it under | |
8 the terms of the GNU General Public License as published by the Free | |
9 Software Foundation; either version 3, or (at your option) any later | |
10 version. | |
11 | |
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with GCC; see the file COPYING3. If not see | |
19 <http://www.gnu.org/licenses/>. */ | |
20 | |
21 /* This file gathers information about how variables whose scope is | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
22 confined to the compilation unit are used. |
0 | 23 |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
24 The transitive call site specific clobber effects are computed |
0 | 25 for the variables whose scope is contained within this compilation |
26 unit. | |
27 | |
28 First each function and static variable initialization is analyzed | |
29 to determine which local static variables are either read, written, | |
30 or have their address taken. Any local static that has its address | |
31 taken is removed from consideration. Once the local read and | |
32 writes are determined, a transitive closure of this information is | |
33 performed over the call graph to determine the worst case set of | |
34 side effects of each call. In later parts of the compiler, these | |
35 local and global sets are examined to make the call clobbering less | |
36 traumatic, promote some statics to registers, and improve aliasing | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
37 information. */ |
0 | 38 |
39 #include "config.h" | |
40 #include "system.h" | |
41 #include "coretypes.h" | |
111 | 42 #include "backend.h" |
0 | 43 #include "tree.h" |
111 | 44 #include "gimple.h" |
0 | 45 #include "tree-pass.h" |
111 | 46 #include "cgraph.h" |
47 #include "data-streamer.h" | |
48 #include "calls.h" | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
49 #include "splay-tree.h" |
0 | 50 #include "ipa-utils.h" |
51 #include "ipa-reference.h" | |
131 | 52 #include "symbol-summary.h" |
0 | 53 |
54 /* The static variables defined within the compilation unit that are | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
55 loaded or stored directly by function that owns this structure. */ |
0 | 56 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
57 struct ipa_reference_local_vars_info_d |
0 | 58 { |
59 bitmap statics_read; | |
60 bitmap statics_written; | |
61 }; | |
62 | |
63 /* Statics that are read and written by some set of functions. The | |
64 local ones are based on the loads and stores local to the function. | |
65 The global ones are based on the local info as well as the | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
66 transitive closure of the functions that are called. */ |
0 | 67 |
68 struct ipa_reference_global_vars_info_d | |
69 { | |
70 bitmap statics_read; | |
71 bitmap statics_written; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
72 }; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
73 |
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
|
74 /* Information we save about every function after ipa-reference is completed. */ |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
75 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
76 struct ipa_reference_optimization_summary_d |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
77 { |
0 | 78 bitmap statics_not_read; |
79 bitmap statics_not_written; | |
80 }; | |
81 | |
131 | 82 typedef ipa_reference_local_vars_info_d *ipa_reference_local_vars_info_t; |
83 typedef ipa_reference_global_vars_info_d *ipa_reference_global_vars_info_t; | |
84 typedef ipa_reference_optimization_summary_d * | |
85 ipa_reference_optimization_summary_t; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
86 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
87 struct ipa_reference_vars_info_d |
0 | 88 { |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
89 struct ipa_reference_local_vars_info_d local; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
90 struct ipa_reference_global_vars_info_d global; |
0 | 91 }; |
92 | |
93 typedef struct ipa_reference_vars_info_d *ipa_reference_vars_info_t; | |
94 | |
95 /* This splay tree contains all of the static variables that are | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
96 being considered by the compilation level alias analysis. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
97 static splay_tree reference_vars_to_consider; |
0 | 98 |
111 | 99 /* Set of all interesting module statics. A bit is set for every module |
100 static we are considering. This is added to the local info when asm | |
101 code is found that clobbers all memory. */ | |
0 | 102 static bitmap all_module_statics; |
111 | 103 /* Set of all statics that should be ignored because they are touched by |
104 -fno-ipa-reference code. */ | |
105 static bitmap ignore_module_statics; | |
0 | 106 |
107 /* Obstack holding bitmaps of local analysis (live from analysis to | |
108 propagation) */ | |
109 static bitmap_obstack local_info_obstack; | |
110 /* Obstack holding global analysis live forever. */ | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
111 static bitmap_obstack optimization_summary_obstack; |
0 | 112 |
131 | 113 class ipa_ref_var_info_summary_t: public function_summary |
114 <ipa_reference_vars_info_d *> | |
115 { | |
116 public: | |
117 ipa_ref_var_info_summary_t (symbol_table *symtab): | |
118 function_summary <ipa_reference_vars_info_d *> (symtab) {} | |
119 }; | |
120 | |
121 static ipa_ref_var_info_summary_t *ipa_ref_var_info_summaries = NULL; | |
0 | 122 |
131 | 123 class ipa_ref_opt_summary_t: public function_summary |
124 <ipa_reference_optimization_summary_d *> | |
125 { | |
126 public: | |
127 ipa_ref_opt_summary_t (symbol_table *symtab): | |
128 function_summary <ipa_reference_optimization_summary_d *> (symtab) {} | |
129 | |
111 | 130 |
131 | 131 virtual void remove (cgraph_node *src_node, |
132 ipa_reference_optimization_summary_d *data); | |
133 virtual void duplicate (cgraph_node *src_node, cgraph_node *dst_node, | |
134 ipa_reference_optimization_summary_d *src_data, | |
135 ipa_reference_optimization_summary_d *dst_data); | |
136 }; | |
137 | |
138 static ipa_ref_opt_summary_t *ipa_ref_opt_sum_summaries = NULL; | |
0 | 139 |
140 /* Return the ipa_reference_vars structure starting from the cgraph NODE. */ | |
141 static inline ipa_reference_vars_info_t | |
142 get_reference_vars_info (struct cgraph_node *node) | |
143 { | |
131 | 144 if (ipa_ref_var_info_summaries == NULL) |
0 | 145 return NULL; |
131 | 146 |
147 ipa_reference_vars_info_t v = ipa_ref_var_info_summaries->get (node); | |
148 return v == NULL ? NULL : v; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
149 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
150 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
151 /* Return the ipa_reference_vars structure starting from the cgraph NODE. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
152 static inline ipa_reference_optimization_summary_t |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
153 get_reference_optimization_summary (struct cgraph_node *node) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
154 { |
131 | 155 if (ipa_ref_opt_sum_summaries == NULL) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
156 return NULL; |
0 | 157 |
131 | 158 ipa_reference_optimization_summary_t v |
159 = ipa_ref_opt_sum_summaries->get (node); | |
0 | 160 |
131 | 161 return v == NULL ? NULL : v; |
0 | 162 } |
163 | |
111 | 164 /* Return a bitmap indexed by ipa_reference_var_uid for the static variables |
165 that are *not* read during the execution of the function FN. Returns | |
0 | 166 NULL if no data is available. */ |
167 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
168 bitmap |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
169 ipa_reference_get_not_read_global (struct cgraph_node *fn) |
0 | 170 { |
111 | 171 if (!opt_for_fn (current_function_decl, flag_ipa_reference)) |
172 return NULL; | |
173 | |
174 enum availability avail; | |
175 struct cgraph_node *fn2 = fn->function_symbol (&avail); | |
176 ipa_reference_optimization_summary_t info = | |
177 get_reference_optimization_summary (fn2); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
178 |
111 | 179 if (info |
180 && (avail >= AVAIL_AVAILABLE | |
181 || (avail == AVAIL_INTERPOSABLE | |
182 && flags_from_decl_or_type (fn->decl) & ECF_LEAF)) | |
183 && opt_for_fn (fn2->decl, flag_ipa_reference)) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
184 return info->statics_not_read; |
111 | 185 else if (avail == AVAIL_NOT_AVAILABLE |
186 && flags_from_decl_or_type (fn->decl) & ECF_LEAF) | |
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
|
187 return all_module_statics; |
0 | 188 else |
189 return NULL; | |
190 } | |
191 | |
111 | 192 /* Return a bitmap indexed by ipa_reference_var_uid for the static variables |
193 that are *not* written during the execution of the function FN. Note | |
0 | 194 that variables written may or may not be read during the function |
195 call. Returns NULL if no data is available. */ | |
196 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
197 bitmap |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
198 ipa_reference_get_not_written_global (struct cgraph_node *fn) |
0 | 199 { |
111 | 200 if (!opt_for_fn (current_function_decl, flag_ipa_reference)) |
201 return NULL; | |
202 | |
203 enum availability avail; | |
204 struct cgraph_node *fn2 = fn->function_symbol (&avail); | |
205 ipa_reference_optimization_summary_t info = | |
206 get_reference_optimization_summary (fn2); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
207 |
111 | 208 if (info |
209 && (avail >= AVAIL_AVAILABLE | |
210 || (avail == AVAIL_INTERPOSABLE | |
211 && flags_from_decl_or_type (fn->decl) & ECF_LEAF)) | |
212 && opt_for_fn (fn2->decl, flag_ipa_reference)) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
213 return info->statics_not_written; |
111 | 214 else if (avail == AVAIL_NOT_AVAILABLE |
215 && flags_from_decl_or_type (fn->decl) & ECF_LEAF) | |
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
|
216 return all_module_statics; |
0 | 217 else |
218 return NULL; | |
219 } | |
220 | |
221 | |
111 | 222 /* Hepler for is_proper_for_analysis. */ |
223 static bool | |
224 is_improper (symtab_node *n, void *v ATTRIBUTE_UNUSED) | |
0 | 225 { |
111 | 226 tree t = n->decl; |
227 /* If the variable has the "used" attribute, treat it as if it had a | |
228 been touched by the devil. */ | |
229 if (DECL_PRESERVE_P (t)) | |
230 return true; | |
231 | |
232 /* Do not want to do anything with volatile except mark any | |
233 function that uses one to be not const or pure. */ | |
234 if (TREE_THIS_VOLATILE (t)) | |
235 return true; | |
236 | |
237 /* We do not need to analyze readonly vars, we already know they do not | |
238 alias. */ | |
239 if (TREE_READONLY (t)) | |
240 return true; | |
241 | |
242 /* We can not track variables with address taken. */ | |
243 if (TREE_ADDRESSABLE (t)) | |
244 return true; | |
245 | |
246 /* TODO: We could track public variables that are not addressable, but | |
247 currently frontends don't give us those. */ | |
248 if (TREE_PUBLIC (t)) | |
249 return true; | |
250 | |
251 return false; | |
0 | 252 } |
253 | |
254 /* Return true if the variable T is the right kind of static variable to | |
255 perform compilation unit scope escape analysis. */ | |
256 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
257 static inline bool |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
258 is_proper_for_analysis (tree t) |
0 | 259 { |
111 | 260 if (bitmap_bit_p (ignore_module_statics, ipa_reference_var_uid (t))) |
0 | 261 return false; |
262 | |
111 | 263 if (symtab_node::get (t) |
264 ->call_for_symbol_and_aliases (is_improper, NULL, true)) | |
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
|
265 return false; |
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
|
266 |
0 | 267 return true; |
268 } | |
269 | |
270 /* Lookup the tree node for the static variable that has UID and | |
271 convert the name to a string for debugging. */ | |
272 | |
273 static const char * | |
274 get_static_name (int index) | |
275 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
276 splay_tree_node stn = |
0 | 277 splay_tree_lookup (reference_vars_to_consider, index); |
111 | 278 return fndecl_name ((tree)(stn->value)); |
279 } | |
280 | |
281 /* Dump a set of static vars to FILE. */ | |
282 static void | |
283 dump_static_vars_set_to_file (FILE *f, bitmap set) | |
284 { | |
285 unsigned int index; | |
286 bitmap_iterator bi; | |
287 if (set == NULL) | |
288 return; | |
289 else if (set == all_module_statics) | |
290 fprintf (f, "ALL"); | |
291 else | |
292 EXECUTE_IF_SET_IN_BITMAP (set, 0, index, bi) | |
293 { | |
294 fprintf (f, "%s ", get_static_name (index)); | |
295 } | |
0 | 296 } |
297 | |
111 | 298 /* Compute X |= Y, taking into account the possibility that |
299 either X or Y is already the maximum set. | |
300 Return true if X is the maximum set after taking the union with Y. */ | |
301 | |
302 static bool | |
303 union_static_var_sets (bitmap &x, bitmap y) | |
304 { | |
305 if (x != all_module_statics) | |
306 { | |
307 if (y == all_module_statics) | |
308 { | |
309 BITMAP_FREE (x); | |
310 x = all_module_statics; | |
311 } | |
312 else if (bitmap_ior_into (x, y)) | |
313 { | |
314 /* The union may have reduced X to the maximum set. | |
315 In that case, we want to make that visible explicitly. | |
316 Even though bitmap_equal_p can be very expensive, it | |
317 turns out to be an overall win to check this here for | |
318 an LTO bootstrap of GCC itself. Liberally extrapoliate | |
319 that result to be applicable to all cases. */ | |
320 if (bitmap_equal_p (x, all_module_statics)) | |
321 { | |
322 BITMAP_FREE (x); | |
323 x = all_module_statics; | |
324 } | |
325 } | |
326 } | |
327 return x == all_module_statics; | |
328 } | |
329 | |
330 /* Return a copy of SET on the bitmap obstack containing SET. | |
331 But if SET is NULL or the maximum set, return that instead. */ | |
332 | |
333 static bitmap | |
334 copy_static_var_set (bitmap set) | |
335 { | |
336 if (set == NULL || set == all_module_statics) | |
337 return set; | |
338 bitmap_obstack *o = set->obstack; | |
339 gcc_checking_assert (o); | |
340 bitmap copy = BITMAP_ALLOC (o); | |
341 bitmap_copy (copy, set); | |
342 return copy; | |
343 } | |
344 | |
345 /* Compute the union all of the statics read and written by every callee of X | |
346 into X_GLOBAL->statics_read and X_GLOBAL->statics_written. X_GLOBAL is | |
347 actually the set representing the cycle containing X. If the read and | |
348 written sets of X_GLOBAL has been reduced to the maximum set, we don't | |
349 have to look at the remaining callees. */ | |
0 | 350 |
351 static void | |
352 propagate_bits (ipa_reference_global_vars_info_t x_global, struct cgraph_node *x) | |
353 { | |
354 struct cgraph_edge *e; | |
111 | 355 bool read_all = x_global->statics_read == all_module_statics; |
356 bool write_all = x_global->statics_written == all_module_statics; | |
357 for (e = x->callees; | |
358 e && !(read_all && write_all); | |
359 e = e->next_callee) | |
0 | 360 { |
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
|
361 enum availability avail; |
111 | 362 struct cgraph_node *y = e->callee->function_symbol (&avail); |
363 if (!y) | |
364 continue; | |
0 | 365 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
366 /* Only look into nodes we can propagate something. */ |
111 | 367 int flags = flags_from_decl_or_type (y->decl); |
368 if (opt_for_fn (y->decl, flag_ipa_reference) | |
369 && (avail > AVAIL_INTERPOSABLE | |
370 || (avail == AVAIL_INTERPOSABLE && (flags & ECF_LEAF)))) | |
0 | 371 { |
372 if (get_reference_vars_info (y)) | |
373 { | |
111 | 374 ipa_reference_vars_info_t y_info = get_reference_vars_info (y); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
375 ipa_reference_global_vars_info_t y_global = &y_info->global; |
0 | 376 |
111 | 377 /* Calls in the current cycle do not have their global set |
378 computed yet (but everything else does because we're | |
379 visiting nodes in topological order). */ | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
380 if (!y_global->statics_read) |
0 | 381 continue; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
382 |
111 | 383 /* If the function is const, it reads no memory even if it |
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
|
384 seems so to local analysis. */ |
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
|
385 if (flags & ECF_CONST) |
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
|
386 continue; |
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
|
387 |
111 | 388 union_static_var_sets (x_global->statics_read, |
0 | 389 y_global->statics_read); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
390 |
111 | 391 /* If the function is pure, it has no stores even if it |
392 seems so to local analysis. If we cannot return from | |
393 the function, we can safely ignore the call. */ | |
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
|
394 if ((flags & ECF_PURE) |
111 | 395 || e->cannot_lead_to_return_p ()) |
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
|
396 continue; |
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
|
397 |
111 | 398 union_static_var_sets (x_global->statics_written, |
0 | 399 y_global->statics_written); |
400 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
401 else |
0 | 402 gcc_unreachable (); |
403 } | |
404 } | |
405 } | |
406 | |
111 | 407 static bool ipa_init_p = false; |
408 | |
0 | 409 /* The init routine for analyzing global static variable usage. See |
410 comments at top for description. */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
411 static void |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
412 ipa_init (void) |
0 | 413 { |
111 | 414 if (ipa_init_p) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
415 return; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
416 |
111 | 417 ipa_init_p = true; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
418 |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
419 if (dump_file) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
420 reference_vars_to_consider = splay_tree_new (splay_tree_compare_ints, 0, 0); |
0 | 421 |
422 bitmap_obstack_initialize (&local_info_obstack); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
423 bitmap_obstack_initialize (&optimization_summary_obstack); |
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
|
424 all_module_statics = BITMAP_ALLOC (&optimization_summary_obstack); |
111 | 425 ignore_module_statics = BITMAP_ALLOC (&optimization_summary_obstack); |
0 | 426 |
131 | 427 if (ipa_ref_var_info_summaries == NULL) |
428 ipa_ref_var_info_summaries = new ipa_ref_var_info_summary_t (symtab); | |
429 | |
430 if (ipa_ref_opt_sum_summaries != NULL) | |
431 { | |
432 delete ipa_ref_opt_sum_summaries; | |
433 ipa_ref_opt_sum_summaries = NULL; | |
434 } | |
0 | 435 } |
436 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
437 |
0 | 438 /* Set up the persistent info for FN. */ |
439 | |
440 static ipa_reference_local_vars_info_t | |
441 init_function_info (struct cgraph_node *fn) | |
442 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
443 ipa_reference_vars_info_t info |
131 | 444 = ipa_ref_var_info_summaries->get_create (fn); |
0 | 445 |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
446 info->local.statics_read = BITMAP_ALLOC (&local_info_obstack); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
447 info->local.statics_written = BITMAP_ALLOC (&local_info_obstack); |
0 | 448 |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
449 return &info->local; |
0 | 450 } |
451 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
452 |
0 | 453 /* This is the main routine for finding the reference patterns for |
454 global variables within a function FN. */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
455 |
0 | 456 static void |
457 analyze_function (struct cgraph_node *fn) | |
458 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
459 ipa_reference_local_vars_info_t local; |
111 | 460 struct ipa_ref *ref = NULL; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
461 int i; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
462 tree var; |
0 | 463 |
111 | 464 if (!opt_for_fn (fn->decl, flag_ipa_reference)) |
465 return; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
466 local = init_function_info (fn); |
111 | 467 for (i = 0; fn->iterate_reference (i, ref); i++) |
0 | 468 { |
111 | 469 if (!is_a <varpool_node *> (ref->referred)) |
470 continue; | |
471 var = ref->referred->decl; | |
472 if (!is_proper_for_analysis (var)) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
473 continue; |
111 | 474 /* This is a variable we care about. Check if we have seen it |
475 before, and if not add it the set of variables we care about. */ | |
476 if (all_module_statics | |
477 && bitmap_set_bit (all_module_statics, ipa_reference_var_uid (var))) | |
478 { | |
479 if (dump_file) | |
480 splay_tree_insert (reference_vars_to_consider, | |
481 ipa_reference_var_uid (var), | |
482 (splay_tree_value)var); | |
483 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
484 switch (ref->use) |
0 | 485 { |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
486 case IPA_REF_LOAD: |
111 | 487 bitmap_set_bit (local->statics_read, ipa_reference_var_uid (var)); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
488 break; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
489 case IPA_REF_STORE: |
111 | 490 if (ref->cannot_lead_to_return ()) |
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
|
491 break; |
111 | 492 bitmap_set_bit (local->statics_written, ipa_reference_var_uid (var)); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
493 break; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
494 case IPA_REF_ADDR: |
111 | 495 break; |
496 default: | |
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
|
497 gcc_unreachable (); |
0 | 498 } |
499 } | |
500 | |
111 | 501 if (fn->cannot_return_p ()) |
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
|
502 bitmap_clear (local->statics_written); |
0 | 503 } |
504 | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
505 |
0 | 506 /* Called when new clone is inserted to callgraph late. */ |
507 | |
131 | 508 void |
509 ipa_ref_opt_summary_t::duplicate (cgraph_node *, cgraph_node *, | |
510 ipa_reference_optimization_summary_d *ginfo, | |
511 ipa_reference_optimization_summary_d | |
512 *dst_ginfo) | |
0 | 513 { |
111 | 514 dst_ginfo->statics_not_read = |
515 copy_static_var_set (ginfo->statics_not_read); | |
516 dst_ginfo->statics_not_written = | |
517 copy_static_var_set (ginfo->statics_not_written); | |
0 | 518 } |
519 | |
520 /* Called when node is removed. */ | |
521 | |
131 | 522 void |
523 ipa_ref_opt_summary_t::remove (cgraph_node *, | |
524 ipa_reference_optimization_summary_d *ginfo) | |
0 | 525 { |
131 | 526 if (ginfo->statics_not_read |
527 && ginfo->statics_not_read != all_module_statics) | |
528 BITMAP_FREE (ginfo->statics_not_read); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
529 |
131 | 530 if (ginfo->statics_not_written |
531 && ginfo->statics_not_written != all_module_statics) | |
532 BITMAP_FREE (ginfo->statics_not_written); | |
0 | 533 } |
534 | |
535 /* Analyze each function in the cgraph to see which global or statics | |
536 are read or written. */ | |
537 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
538 static void |
0 | 539 generate_summary (void) |
540 { | |
541 struct cgraph_node *node; | |
542 unsigned int index; | |
543 bitmap_iterator bi; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
544 |
0 | 545 ipa_init (); |
546 | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
547 /* Process all of the functions next. */ |
111 | 548 FOR_EACH_DEFINED_FUNCTION (node) |
549 if (!node->alias && !opt_for_fn (node->decl, flag_ipa_reference)) | |
550 { | |
551 struct ipa_ref *ref = NULL; | |
552 int i; | |
553 tree var; | |
554 for (i = 0; node->iterate_reference (i, ref); i++) | |
555 { | |
556 if (!is_a <varpool_node *> (ref->referred)) | |
557 continue; | |
558 var = ref->referred->decl; | |
559 if (!is_proper_for_analysis (var)) | |
560 continue; | |
561 bitmap_set_bit (ignore_module_statics, ipa_reference_var_uid (var)); | |
562 } | |
563 } | |
564 FOR_EACH_DEFINED_FUNCTION (node) | |
565 analyze_function (node); | |
0 | 566 |
567 if (dump_file) | |
568 EXECUTE_IF_SET_IN_BITMAP (all_module_statics, 0, index, bi) | |
569 { | |
111 | 570 fprintf (dump_file, "\nPromotable global:%s (uid=%u)\n", |
571 get_static_name (index), index); | |
0 | 572 } |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
573 |
0 | 574 if (dump_file) |
111 | 575 FOR_EACH_DEFINED_FUNCTION (node) |
576 if (node->get_availability () >= AVAIL_INTERPOSABLE | |
577 && opt_for_fn (node->decl, flag_ipa_reference)) | |
0 | 578 { |
579 ipa_reference_local_vars_info_t l; | |
580 unsigned int index; | |
581 bitmap_iterator bi; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
582 |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
583 l = &get_reference_vars_info (node)->local; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
584 fprintf (dump_file, |
111 | 585 "\nFunction name:%s:", node->dump_name ()); |
0 | 586 fprintf (dump_file, "\n locals read: "); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
587 if (l->statics_read) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
588 EXECUTE_IF_SET_IN_BITMAP (l->statics_read, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
589 0, index, bi) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
590 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
591 fprintf (dump_file, "%s ", |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
592 get_static_name (index)); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
593 } |
0 | 594 fprintf (dump_file, "\n locals written: "); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
595 if (l->statics_written) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
596 EXECUTE_IF_SET_IN_BITMAP (l->statics_written, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
597 0, index, bi) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
598 { |
111 | 599 fprintf (dump_file, "%s ", get_static_name (index)); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
600 } |
0 | 601 } |
602 } | |
603 | |
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
|
604 /* Set READ_ALL/WRITE_ALL based on decl flags of NODE. */ |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
605 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
606 static void |
111 | 607 read_write_all_from_decl (struct cgraph_node *node, |
608 bool &read_all, bool &write_all) | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
609 { |
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
|
610 tree decl = node->decl; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
611 int flags = flags_from_decl_or_type (decl); |
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
|
612 if ((flags & ECF_LEAF) |
111 | 613 && node->get_availability () < AVAIL_INTERPOSABLE) |
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
|
614 ; |
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
|
615 else if (flags & ECF_CONST) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
616 ; |
111 | 617 else if ((flags & ECF_PURE) || node->cannot_return_p ()) |
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
|
618 { |
111 | 619 read_all = true; |
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
|
620 if (dump_file && (dump_flags & TDF_DETAILS)) |
111 | 621 fprintf (dump_file, " %s -> read all\n", node->dump_name ()); |
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
|
622 } |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
623 else |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
624 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
625 /* TODO: To be able to produce sane results, we should also handle |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
626 common builtins, in particular throw. */ |
111 | 627 read_all = true; |
628 write_all = true; | |
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
|
629 if (dump_file && (dump_flags & TDF_DETAILS)) |
111 | 630 fprintf (dump_file, " %s -> read all, write all\n", |
631 node->dump_name ()); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
632 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
633 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
634 |
111 | 635 /* Set READ_ALL/WRITE_ALL based on decl flags of NODE or any member |
636 in the cycle of NODE. */ | |
637 | |
638 static void | |
639 get_read_write_all_from_node (struct cgraph_node *node, | |
640 bool &read_all, bool &write_all) | |
641 { | |
642 struct cgraph_edge *e, *ie; | |
643 | |
644 /* When function is overwritable, we can not assume anything. */ | |
645 if (node->get_availability () <= AVAIL_INTERPOSABLE | |
646 || (node->analyzed && !opt_for_fn (node->decl, flag_ipa_reference))) | |
647 read_write_all_from_decl (node, read_all, write_all); | |
648 | |
649 for (e = node->callees; | |
650 e && !(read_all && write_all); | |
651 e = e->next_callee) | |
652 { | |
653 enum availability avail; | |
654 struct cgraph_node *callee = e->callee->function_symbol (&avail); | |
655 gcc_checking_assert (callee); | |
656 if (avail <= AVAIL_INTERPOSABLE | |
131 | 657 || (callee->analyzed && !opt_for_fn (callee->decl, |
658 flag_ipa_reference))) | |
111 | 659 read_write_all_from_decl (callee, read_all, write_all); |
660 } | |
661 | |
662 for (ie = node->indirect_calls; | |
663 ie && !(read_all && write_all); | |
664 ie = ie->next_callee) | |
665 if (!(ie->indirect_info->ecf_flags & ECF_CONST)) | |
666 { | |
667 read_all = true; | |
668 if (dump_file && (dump_flags & TDF_DETAILS)) | |
669 fprintf (dump_file, " indirect call -> read all\n"); | |
670 if (!ie->cannot_lead_to_return_p () | |
671 && !(ie->indirect_info->ecf_flags & ECF_PURE)) | |
672 { | |
673 if (dump_file && (dump_flags & TDF_DETAILS)) | |
674 fprintf (dump_file, " indirect call -> write all\n"); | |
675 write_all = true; | |
676 } | |
677 } | |
678 } | |
679 | |
680 /* Skip edges from and to nodes without ipa_reference enables. This leave | |
681 them out of strongy connected coponents and makes them easyto skip in the | |
682 propagation loop bellow. */ | |
683 | |
684 static bool | |
685 ignore_edge_p (cgraph_edge *e) | |
686 { | |
687 return (!opt_for_fn (e->caller->decl, flag_ipa_reference) | |
688 || !opt_for_fn (e->callee->function_symbol ()->decl, | |
689 flag_ipa_reference)); | |
690 } | |
691 | |
0 | 692 /* Produce the global information by preforming a transitive closure |
111 | 693 on the local information that was produced by ipa_analyze_function. */ |
0 | 694 |
695 static unsigned int | |
696 propagate (void) | |
697 { | |
698 struct cgraph_node *node; | |
699 struct cgraph_node **order = | |
111 | 700 XCNEWVEC (struct cgraph_node *, symtab->cgraph_count); |
701 int order_pos; | |
0 | 702 int i; |
111 | 703 bool remove_p; |
0 | 704 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
705 if (dump_file) |
111 | 706 cgraph_node::dump_cgraph (dump_file); |
0 | 707 |
111 | 708 remove_p = ipa_discover_readonly_nonaddressable_vars (); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
709 generate_summary (); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
710 |
111 | 711 /* Propagate the local information through the call graph to produce |
0 | 712 the global information. All the nodes within a cycle will have |
713 the same info so we collapse cycles first. Then we can do the | |
714 propagation in one pass from the leaves to the roots. */ | |
111 | 715 order_pos = ipa_reduced_postorder (order, true, true, ignore_edge_p); |
0 | 716 if (dump_file) |
111 | 717 ipa_print_order (dump_file, "reduced", order, order_pos); |
0 | 718 |
719 for (i = 0; i < order_pos; i++ ) | |
720 { | |
111 | 721 unsigned x; |
722 struct cgraph_node *w; | |
0 | 723 ipa_reference_vars_info_t node_info; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
724 ipa_reference_global_vars_info_t node_g; |
0 | 725 ipa_reference_local_vars_info_t node_l; |
111 | 726 bool read_all = false; |
727 bool write_all = false; | |
0 | 728 |
729 node = order[i]; | |
111 | 730 if (node->alias || !opt_for_fn (node->decl, flag_ipa_reference)) |
731 continue; | |
732 | |
0 | 733 node_info = get_reference_vars_info (node); |
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
|
734 gcc_assert (node_info); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
735 node_l = &node_info->local; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
736 node_g = &node_info->global; |
0 | 737 |
111 | 738 if (dump_file && (dump_flags & TDF_DETAILS)) |
739 fprintf (dump_file, "Starting cycle with %s\n", node->dump_name ()); | |
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
|
740 |
111 | 741 vec<cgraph_node *> cycle_nodes = ipa_get_nodes_in_cycle (node); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
742 |
111 | 743 /* If any node in a cycle is read_all or write_all, they all are. */ |
744 FOR_EACH_VEC_ELT (cycle_nodes, x, w) | |
0 | 745 { |
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
|
746 if (dump_file && (dump_flags & TDF_DETAILS)) |
111 | 747 fprintf (dump_file, " Visiting %s\n", w->dump_asm_name ()); |
748 get_read_write_all_from_node (w, read_all, write_all); | |
749 if (read_all && write_all) | |
750 break; | |
0 | 751 } |
752 | |
111 | 753 /* Initialized the bitmaps global sets for the reduced node. */ |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
754 if (read_all) |
0 | 755 node_g->statics_read = all_module_statics; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
756 else |
111 | 757 node_g->statics_read = copy_static_var_set (node_l->statics_read); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
758 if (write_all) |
0 | 759 node_g->statics_written = all_module_statics; |
760 else | |
111 | 761 node_g->statics_written = copy_static_var_set (node_l->statics_written); |
0 | 762 |
111 | 763 /* Merge the sets of this cycle with all sets of callees reached |
764 from this cycle. */ | |
765 FOR_EACH_VEC_ELT (cycle_nodes, x, w) | |
0 | 766 { |
111 | 767 if (read_all && write_all) |
768 break; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
769 |
111 | 770 if (w != node) |
771 { | |
772 ipa_reference_vars_info_t w_ri = get_reference_vars_info (w); | |
773 ipa_reference_local_vars_info_t w_l = &w_ri->local; | |
774 int flags = flags_from_decl_or_type (w->decl); | |
775 | |
776 if (!(flags & ECF_CONST)) | |
777 read_all = union_static_var_sets (node_g->statics_read, | |
778 w_l->statics_read); | |
779 if (!(flags & ECF_PURE) | |
780 && !w->cannot_return_p ()) | |
781 write_all = union_static_var_sets (node_g->statics_written, | |
782 w_l->statics_written); | |
783 } | |
784 | |
0 | 785 propagate_bits (node_g, w); |
786 } | |
787 | |
788 /* All nodes within a cycle have the same global info bitmaps. */ | |
111 | 789 FOR_EACH_VEC_ELT (cycle_nodes, x, w) |
0 | 790 { |
111 | 791 ipa_reference_vars_info_t w_ri = get_reference_vars_info (w); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
792 w_ri->global = *node_g; |
111 | 793 } |
0 | 794 |
111 | 795 cycle_nodes.release (); |
0 | 796 } |
797 | |
798 if (dump_file) | |
799 { | |
111 | 800 for (i = 0; i < order_pos; i++) |
0 | 801 { |
111 | 802 unsigned x; |
803 struct cgraph_node *w; | |
0 | 804 |
805 node = order[i]; | |
111 | 806 if (node->alias || !opt_for_fn (node->decl, flag_ipa_reference)) |
807 continue; | |
808 | |
809 fprintf (dump_file, "\nFunction name:%s:", node->dump_asm_name ()); | |
810 | |
811 ipa_reference_vars_info_t node_info = get_reference_vars_info (node); | |
812 ipa_reference_global_vars_info_t node_g = &node_info->global; | |
0 | 813 |
111 | 814 vec<cgraph_node *> cycle_nodes = ipa_get_nodes_in_cycle (node); |
815 FOR_EACH_VEC_ELT (cycle_nodes, x, w) | |
0 | 816 { |
111 | 817 ipa_reference_vars_info_t w_ri = get_reference_vars_info (w); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
818 ipa_reference_local_vars_info_t w_l = &w_ri->local; |
111 | 819 if (w != node) |
820 fprintf (dump_file, "\n next cycle: %s ", w->dump_asm_name ()); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
821 fprintf (dump_file, "\n locals read: "); |
111 | 822 dump_static_vars_set_to_file (dump_file, w_l->statics_read); |
0 | 823 fprintf (dump_file, "\n locals written: "); |
111 | 824 dump_static_vars_set_to_file (dump_file, w_l->statics_written); |
0 | 825 } |
111 | 826 cycle_nodes.release (); |
827 | |
0 | 828 fprintf (dump_file, "\n globals read: "); |
111 | 829 dump_static_vars_set_to_file (dump_file, node_g->statics_read); |
0 | 830 fprintf (dump_file, "\n globals written: "); |
111 | 831 dump_static_vars_set_to_file (dump_file, node_g->statics_written); |
832 fprintf (dump_file, "\n"); | |
0 | 833 } |
834 } | |
835 | |
131 | 836 if (ipa_ref_opt_sum_summaries == NULL) |
837 ipa_ref_opt_sum_summaries = new ipa_ref_opt_summary_t (symtab); | |
838 | |
0 | 839 /* Cleanup. */ |
111 | 840 FOR_EACH_DEFINED_FUNCTION (node) |
0 | 841 { |
842 ipa_reference_vars_info_t node_info; | |
843 ipa_reference_global_vars_info_t node_g; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
844 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
845 node_info = get_reference_vars_info (node); |
111 | 846 if (!node->alias && opt_for_fn (node->decl, flag_ipa_reference) |
847 && (node->get_availability () > AVAIL_INTERPOSABLE | |
848 || (flags_from_decl_or_type (node->decl) & ECF_LEAF))) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
849 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
850 node_g = &node_info->global; |
0 | 851 |
131 | 852 ipa_reference_optimization_summary_d *opt |
853 = ipa_ref_opt_sum_summaries->get_create (node); | |
0 | 854 |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
855 /* Create the complimentary sets. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
856 |
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
|
857 if (bitmap_empty_p (node_g->statics_read)) |
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
|
858 opt->statics_not_read = all_module_statics; |
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
|
859 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
|
860 { |
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
|
861 opt->statics_not_read |
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
|
862 = BITMAP_ALLOC (&optimization_summary_obstack); |
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
|
863 if (node_g->statics_read != all_module_statics) |
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
|
864 bitmap_and_compl (opt->statics_not_read, |
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
|
865 all_module_statics, |
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
|
866 node_g->statics_read); |
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
|
867 } |
0 | 868 |
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
|
869 if (bitmap_empty_p (node_g->statics_written)) |
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
|
870 opt->statics_not_written = all_module_statics; |
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
|
871 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
|
872 { |
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
|
873 opt->statics_not_written |
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
|
874 = BITMAP_ALLOC (&optimization_summary_obstack); |
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
|
875 if (node_g->statics_written != all_module_statics) |
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
|
876 bitmap_and_compl (opt->statics_not_written, |
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
|
877 all_module_statics, |
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
|
878 node_g->statics_written); |
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
|
879 } |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
880 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
881 } |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
882 |
111 | 883 ipa_free_postorder_info (); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
884 free (order); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
885 |
0 | 886 bitmap_obstack_release (&local_info_obstack); |
131 | 887 |
888 if (ipa_ref_var_info_summaries == NULL) | |
889 { | |
890 delete ipa_ref_var_info_summaries; | |
891 ipa_ref_var_info_summaries = NULL; | |
892 } | |
893 | |
894 ipa_ref_var_info_summaries = NULL; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
895 if (dump_file) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
896 splay_tree_delete (reference_vars_to_consider); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
897 reference_vars_to_consider = NULL; |
111 | 898 return remove_p ? TODO_remove_functions : 0; |
0 | 899 } |
900 | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
901 /* Return true if we need to write summary of NODE. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
902 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
903 static bool |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
904 write_node_summary_p (struct cgraph_node *node, |
111 | 905 lto_symtab_encoder_t encoder, |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
906 bitmap ltrans_statics) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
907 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
908 ipa_reference_optimization_summary_t info; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
909 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
910 /* See if we have (non-empty) info. */ |
111 | 911 if (!node->definition || node->global.inlined_to) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
912 return false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
913 info = get_reference_optimization_summary (node); |
131 | 914 if (!info |
915 || (bitmap_empty_p (info->statics_not_read) | |
916 && bitmap_empty_p (info->statics_not_written))) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
917 return false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
918 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
919 /* See if we want to encode it. |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
920 Encode also referenced functions since constant folding might turn it into |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
921 a direct call. |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
922 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
923 In future we might also want to include summaries of functions references |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
924 by initializers of constant variables references in current unit. */ |
111 | 925 if (!reachable_from_this_partition_p (node, encoder) |
926 && !referenced_from_this_partition_p (node, encoder)) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
927 return false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
928 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
929 /* See if the info has non-empty intersections with vars we want to encode. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
930 if (!bitmap_intersect_p (info->statics_not_read, ltrans_statics) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
931 && !bitmap_intersect_p (info->statics_not_written, ltrans_statics)) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
932 return false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
933 return true; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
934 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
935 |
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
|
936 /* Stream out BITS<RANS_STATICS as list of decls to OB. |
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
|
937 LTRANS_STATICS_BITCOUNT specify number of bits in LTRANS_STATICS |
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
|
938 or -1. When it is positive, just output -1 when |
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
|
939 BITS<RANS_STATICS == BITS<RANS_STATICS. */ |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
940 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
941 static void |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
942 stream_out_bitmap (struct lto_simple_output_block *ob, |
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
|
943 bitmap bits, bitmap ltrans_statics, |
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
|
944 int ltrans_statics_bitcount) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
945 { |
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
|
946 int count = 0; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
947 unsigned int index; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
948 bitmap_iterator bi; |
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
|
949 if (bits == all_module_statics) |
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
|
950 { |
111 | 951 streamer_write_hwi_stream (ob->main_stream, -1); |
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
|
952 return; |
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
|
953 } |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
954 EXECUTE_IF_AND_IN_BITMAP (bits, ltrans_statics, 0, index, bi) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
955 count ++; |
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
|
956 if (count == ltrans_statics_bitcount) |
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
|
957 { |
111 | 958 streamer_write_hwi_stream (ob->main_stream, -1); |
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
|
959 return; |
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
|
960 } |
111 | 961 streamer_write_hwi_stream (ob->main_stream, count); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
962 if (!count) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
963 return; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
964 EXECUTE_IF_AND_IN_BITMAP (bits, ltrans_statics, 0, index, bi) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
965 { |
131 | 966 tree decl = (tree)splay_tree_lookup (reference_vars_to_consider, |
967 index)->value; | |
111 | 968 lto_output_var_decl_index (ob->decl_state, ob->main_stream, decl); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
969 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
970 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
971 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
972 /* Serialize the ipa info for lto. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
973 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
974 static void |
111 | 975 ipa_reference_write_optimization_summary (void) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
976 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
977 struct lto_simple_output_block *ob |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
978 = lto_create_simple_output_block (LTO_section_ipa_reference); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
979 unsigned int count = 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
|
980 int ltrans_statics_bitcount = 0; |
111 | 981 lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder; |
982 auto_bitmap ltrans_statics; | |
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
|
983 int i; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
984 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
985 reference_vars_to_consider = splay_tree_new (splay_tree_compare_ints, 0, 0); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
986 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
987 /* See what variables we are interested in. */ |
111 | 988 for (i = 0; i < lto_symtab_encoder_size (encoder); i++) |
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
|
989 { |
111 | 990 symtab_node *snode = lto_symtab_encoder_deref (encoder, i); |
991 varpool_node *vnode = dyn_cast <varpool_node *> (snode); | |
992 if (vnode | |
993 && bitmap_bit_p (all_module_statics, | |
994 ipa_reference_var_uid (vnode->decl)) | |
995 && referenced_from_this_partition_p (vnode, encoder)) | |
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
|
996 { |
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
|
997 tree decl = vnode->decl; |
111 | 998 bitmap_set_bit (ltrans_statics, ipa_reference_var_uid (decl)); |
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
|
999 splay_tree_insert (reference_vars_to_consider, |
111 | 1000 ipa_reference_var_uid (decl), |
1001 (splay_tree_value)decl); | |
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
|
1002 ltrans_statics_bitcount ++; |
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
|
1003 } |
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
|
1004 } |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1005 |
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
|
1006 |
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
|
1007 if (ltrans_statics_bitcount) |
111 | 1008 for (i = 0; i < lto_symtab_encoder_size (encoder); i++) |
1009 { | |
1010 symtab_node *snode = lto_symtab_encoder_deref (encoder, i); | |
1011 cgraph_node *cnode = dyn_cast <cgraph_node *> (snode); | |
1012 if (cnode && write_node_summary_p (cnode, encoder, ltrans_statics)) | |
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
|
1013 count++; |
111 | 1014 } |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1015 |
111 | 1016 streamer_write_uhwi_stream (ob->main_stream, count); |
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
|
1017 if (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
|
1018 stream_out_bitmap (ob, ltrans_statics, ltrans_statics, |
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
|
1019 -1); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1020 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1021 /* Process all of the functions. */ |
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
|
1022 if (ltrans_statics_bitcount) |
111 | 1023 for (i = 0; i < lto_symtab_encoder_size (encoder); i++) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1024 { |
111 | 1025 symtab_node *snode = lto_symtab_encoder_deref (encoder, i); |
1026 cgraph_node *cnode = dyn_cast <cgraph_node *> (snode); | |
1027 if (cnode && write_node_summary_p (cnode, encoder, ltrans_statics)) | |
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
|
1028 { |
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
|
1029 ipa_reference_optimization_summary_t info; |
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
|
1030 int node_ref; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1031 |
111 | 1032 info = get_reference_optimization_summary (cnode); |
1033 node_ref = lto_symtab_encoder_encode (encoder, snode); | |
1034 streamer_write_uhwi_stream (ob->main_stream, node_ref); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1035 |
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
|
1036 stream_out_bitmap (ob, info->statics_not_read, ltrans_statics, |
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
|
1037 ltrans_statics_bitcount); |
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
|
1038 stream_out_bitmap (ob, info->statics_not_written, ltrans_statics, |
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
|
1039 ltrans_statics_bitcount); |
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
|
1040 } |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1041 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1042 lto_destroy_simple_output_block (ob); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1043 splay_tree_delete (reference_vars_to_consider); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1044 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1045 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1046 /* Deserialize the ipa info for lto. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1047 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1048 static void |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1049 ipa_reference_read_optimization_summary (void) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1050 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1051 struct lto_file_decl_data ** file_data_vec |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1052 = lto_get_file_decl_data (); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1053 struct lto_file_decl_data * file_data; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1054 unsigned int j = 0; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1055 bitmap_obstack_initialize (&optimization_summary_obstack); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1056 |
131 | 1057 if (ipa_ref_opt_sum_summaries == NULL) |
1058 ipa_ref_opt_sum_summaries = new ipa_ref_opt_summary_t (symtab); | |
1059 | |
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
|
1060 all_module_statics = BITMAP_ALLOC (&optimization_summary_obstack); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1061 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1062 while ((file_data = file_data_vec[j++])) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1063 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1064 const char *data; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1065 size_t len; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1066 struct lto_input_block *ib |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1067 = lto_create_simple_input_block (file_data, |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1068 LTO_section_ipa_reference, |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1069 &data, &len); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1070 if (ib) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1071 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1072 unsigned int i; |
111 | 1073 unsigned int f_count = streamer_read_uhwi (ib); |
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
|
1074 int b_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
|
1075 if (!f_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
|
1076 continue; |
111 | 1077 b_count = streamer_read_hwi (ib); |
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
|
1078 if (dump_file) |
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
|
1079 fprintf (dump_file, "all module statics:"); |
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
|
1080 for (i = 0; i < (unsigned int)b_count; i++) |
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
|
1081 { |
111 | 1082 unsigned int var_index = streamer_read_uhwi (ib); |
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
|
1083 tree v_decl = lto_file_decl_data_get_var_decl (file_data, |
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
|
1084 var_index); |
111 | 1085 bitmap_set_bit (all_module_statics, |
1086 ipa_reference_var_uid (v_decl)); | |
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
|
1087 if (dump_file) |
111 | 1088 fprintf (dump_file, " %s", fndecl_name (v_decl)); |
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
|
1089 } |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1090 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1091 for (i = 0; i < f_count; i++) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1092 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1093 unsigned int j, index; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1094 struct cgraph_node *node; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1095 int v_count; |
111 | 1096 lto_symtab_encoder_t encoder; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1097 |
111 | 1098 index = streamer_read_uhwi (ib); |
1099 encoder = file_data->symtab_node_encoder; | |
1100 node = dyn_cast<cgraph_node *> (lto_symtab_encoder_deref | |
1101 (encoder, index)); | |
131 | 1102 |
1103 ipa_reference_optimization_summary_d *info | |
1104 = ipa_ref_opt_sum_summaries->get_create (node); | |
1105 | |
1106 info->statics_not_read = BITMAP_ALLOC | |
1107 (&optimization_summary_obstack); | |
1108 info->statics_not_written = BITMAP_ALLOC | |
1109 (&optimization_summary_obstack); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1110 if (dump_file) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1111 fprintf (dump_file, |
111 | 1112 "\nFunction name:%s:\n static not read:", |
1113 node->dump_asm_name ()); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1114 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1115 /* Set the statics not read. */ |
111 | 1116 v_count = streamer_read_hwi (ib); |
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
|
1117 if (v_count == -1) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1118 { |
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
|
1119 info->statics_not_read = all_module_statics; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1120 if (dump_file) |
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
|
1121 fprintf (dump_file, " all module statics"); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1122 } |
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
|
1123 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
|
1124 for (j = 0; j < (unsigned int)v_count; j++) |
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
|
1125 { |
111 | 1126 unsigned int var_index = streamer_read_uhwi (ib); |
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
|
1127 tree v_decl = lto_file_decl_data_get_var_decl (file_data, |
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
|
1128 var_index); |
111 | 1129 bitmap_set_bit (info->statics_not_read, |
1130 ipa_reference_var_uid (v_decl)); | |
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
|
1131 if (dump_file) |
111 | 1132 fprintf (dump_file, " %s", fndecl_name (v_decl)); |
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
|
1133 } |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1134 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1135 if (dump_file) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1136 fprintf (dump_file, |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1137 "\n static not written:"); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1138 /* Set the statics not written. */ |
111 | 1139 v_count = streamer_read_hwi (ib); |
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
|
1140 if (v_count == -1) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1141 { |
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
|
1142 info->statics_not_written = all_module_statics; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1143 if (dump_file) |
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
|
1144 fprintf (dump_file, " all module statics"); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1145 } |
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
|
1146 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
|
1147 for (j = 0; j < (unsigned int)v_count; j++) |
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
|
1148 { |
111 | 1149 unsigned int var_index = streamer_read_uhwi (ib); |
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
|
1150 tree v_decl = lto_file_decl_data_get_var_decl (file_data, |
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
|
1151 var_index); |
111 | 1152 bitmap_set_bit (info->statics_not_written, |
1153 ipa_reference_var_uid (v_decl)); | |
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
|
1154 if (dump_file) |
111 | 1155 fprintf (dump_file, " %s", fndecl_name (v_decl)); |
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
|
1156 } |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1157 if (dump_file) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1158 fprintf (dump_file, "\n"); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1159 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1160 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1161 lto_destroy_simple_input_block (file_data, |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1162 LTO_section_ipa_reference, |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1163 ib, data, len); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1164 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1165 else |
131 | 1166 /* Fatal error here. We do not want to support compiling ltrans units |
1167 with different version of compiler or different flags than | |
1168 the WPA unit, so this should never happen. */ | |
111 | 1169 fatal_error (input_location, |
1170 "ipa reference summary is missing in ltrans unit"); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1171 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1172 } |
0 | 1173 |
111 | 1174 namespace { |
1175 | |
1176 const pass_data pass_data_ipa_reference = | |
1177 { | |
1178 IPA_PASS, /* type */ | |
1179 "static-var", /* name */ | |
1180 OPTGROUP_NONE, /* optinfo_flags */ | |
1181 TV_IPA_REFERENCE, /* tv_id */ | |
1182 0, /* properties_required */ | |
1183 0, /* properties_provided */ | |
1184 0, /* properties_destroyed */ | |
1185 0, /* todo_flags_start */ | |
1186 0, /* todo_flags_finish */ | |
1187 }; | |
1188 | |
1189 class pass_ipa_reference : public ipa_opt_pass_d | |
0 | 1190 { |
111 | 1191 public: |
1192 pass_ipa_reference (gcc::context *ctxt) | |
1193 : ipa_opt_pass_d (pass_data_ipa_reference, ctxt, | |
1194 NULL, /* generate_summary */ | |
1195 NULL, /* write_summary */ | |
1196 NULL, /* read_summary */ | |
1197 ipa_reference_write_optimization_summary, /* | |
1198 write_optimization_summary */ | |
1199 ipa_reference_read_optimization_summary, /* | |
1200 read_optimization_summary */ | |
1201 NULL, /* stmt_fixup */ | |
1202 0, /* function_transform_todo_flags_start */ | |
1203 NULL, /* function_transform */ | |
1204 NULL) /* variable_transform */ | |
1205 {} | |
1206 | |
1207 /* opt_pass methods: */ | |
1208 virtual bool gate (function *) | |
1209 { | |
1210 return ((in_lto_p || flag_ipa_reference) | |
1211 /* Don't bother doing anything if the program has errors. */ | |
1212 && !seen_error ()); | |
1213 } | |
1214 | |
1215 virtual unsigned int execute (function *) { return propagate (); } | |
1216 | |
1217 }; // class pass_ipa_reference | |
1218 | |
1219 } // anon namespace | |
1220 | |
1221 ipa_opt_pass_d * | |
1222 make_pass_ipa_reference (gcc::context *ctxt) | |
1223 { | |
1224 return new pass_ipa_reference (ctxt); | |
0 | 1225 } |
1226 | |
111 | 1227 /* Reset all state within ipa-reference.c so that we can rerun the compiler |
1228 within the same process. For use by toplev::finalize. */ | |
1229 | |
1230 void | |
1231 ipa_reference_c_finalize (void) | |
0 | 1232 { |
131 | 1233 if (ipa_ref_opt_sum_summaries != NULL) |
1234 { | |
1235 delete ipa_ref_opt_sum_summaries; | |
1236 ipa_ref_opt_sum_summaries = NULL; | |
1237 } | |
1238 | |
111 | 1239 if (ipa_init_p) |
1240 { | |
1241 bitmap_obstack_release (&optimization_summary_obstack); | |
1242 ipa_init_p = false; | |
1243 } | |
1244 } |