File: | build/gcc/ipa-fnsummary.cc |
Warning: | line 201, column 7 Value stored to 'i' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* Function summary pass. |
2 | Copyright (C) 2003-2023 Free Software Foundation, Inc. |
3 | Contributed by Jan Hubicka |
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 | /* Analysis of function bodies used by inter-procedural passes |
22 | |
23 | We estimate for each function |
24 | - function body size and size after specializing into given context |
25 | - average function execution time in a given context |
26 | - function frame size |
27 | For each call |
28 | - call statement size, time and how often the parameters change |
29 | |
30 | ipa_fn_summary data structures store above information locally (i.e. |
31 | parameters of the function itself) and globally (i.e. parameters of |
32 | the function created by applying all the inline decisions already |
33 | present in the callgraph). |
34 | |
35 | We provide access to the ipa_fn_summary data structure and |
36 | basic logic updating the parameters when inlining is performed. |
37 | |
38 | The summaries are context sensitive. Context means |
39 | 1) partial assignment of known constant values of operands |
40 | 2) whether function is inlined into the call or not. |
41 | It is easy to add more variants. To represent function size and time |
42 | that depends on context (i.e. it is known to be optimized away when |
43 | context is known either by inlining or from IP-CP and cloning), |
44 | we use predicates. |
45 | |
46 | estimate_edge_size_and_time can be used to query |
47 | function size/time in the given context. ipa_merge_fn_summary_after_inlining merges |
48 | properties of caller and callee after inlining. |
49 | |
50 | Finally pass_inline_parameters is exported. This is used to drive |
51 | computation of function parameters used by the early inliner. IPA |
52 | inlined performs analysis via its analyze_function method. */ |
53 | |
54 | #include "config.h" |
55 | #define INCLUDE_VECTOR |
56 | #include "system.h" |
57 | #include "coretypes.h" |
58 | #include "backend.h" |
59 | #include "target.h" |
60 | #include "tree.h" |
61 | #include "gimple.h" |
62 | #include "alloc-pool.h" |
63 | #include "tree-pass.h" |
64 | #include "ssa.h" |
65 | #include "tree-streamer.h" |
66 | #include "cgraph.h" |
67 | #include "diagnostic.h" |
68 | #include "fold-const.h" |
69 | #include "print-tree.h" |
70 | #include "tree-inline.h" |
71 | #include "gimple-pretty-print.h" |
72 | #include "cfganal.h" |
73 | #include "gimple-iterator.h" |
74 | #include "tree-cfg.h" |
75 | #include "tree-ssa-loop-niter.h" |
76 | #include "tree-ssa-loop.h" |
77 | #include "symbol-summary.h" |
78 | #include "ipa-prop.h" |
79 | #include "ipa-fnsummary.h" |
80 | #include "cfgloop.h" |
81 | #include "tree-scalar-evolution.h" |
82 | #include "ipa-utils.h" |
83 | #include "cfgexpand.h" |
84 | #include "gimplify.h" |
85 | #include "stringpool.h" |
86 | #include "attribs.h" |
87 | #include "tree-into-ssa.h" |
88 | #include "symtab-clones.h" |
89 | #include "gimple-range.h" |
90 | #include "tree-dfa.h" |
91 | |
92 | /* Summaries. */ |
93 | fast_function_summary <ipa_fn_summary *, va_gc> *ipa_fn_summaries; |
94 | fast_function_summary <ipa_size_summary *, va_heap> *ipa_size_summaries; |
95 | fast_call_summary <ipa_call_summary *, va_heap> *ipa_call_summaries; |
96 | |
97 | /* Edge predicates goes here. */ |
98 | static object_allocator<ipa_predicate> edge_predicate_pool ("edge predicates"); |
99 | |
100 | |
101 | /* Dump IPA hints. */ |
102 | void |
103 | ipa_dump_hints (FILE *f, ipa_hints hints) |
104 | { |
105 | if (!hints) |
106 | return; |
107 | fprintf (f, "IPA hints:"); |
108 | if (hints & INLINE_HINT_indirect_call) |
109 | { |
110 | hints &= ~INLINE_HINT_indirect_call; |
111 | fprintf (f, " indirect_call"); |
112 | } |
113 | if (hints & INLINE_HINT_loop_iterations) |
114 | { |
115 | hints &= ~INLINE_HINT_loop_iterations; |
116 | fprintf (f, " loop_iterations"); |
117 | } |
118 | if (hints & INLINE_HINT_loop_stride) |
119 | { |
120 | hints &= ~INLINE_HINT_loop_stride; |
121 | fprintf (f, " loop_stride"); |
122 | } |
123 | if (hints & INLINE_HINT_same_scc) |
124 | { |
125 | hints &= ~INLINE_HINT_same_scc; |
126 | fprintf (f, " same_scc"); |
127 | } |
128 | if (hints & INLINE_HINT_in_scc) |
129 | { |
130 | hints &= ~INLINE_HINT_in_scc; |
131 | fprintf (f, " in_scc"); |
132 | } |
133 | if (hints & INLINE_HINT_cross_module) |
134 | { |
135 | hints &= ~INLINE_HINT_cross_module; |
136 | fprintf (f, " cross_module"); |
137 | } |
138 | if (hints & INLINE_HINT_declared_inline) |
139 | { |
140 | hints &= ~INLINE_HINT_declared_inline; |
141 | fprintf (f, " declared_inline"); |
142 | } |
143 | if (hints & INLINE_HINT_known_hot) |
144 | { |
145 | hints &= ~INLINE_HINT_known_hot; |
146 | fprintf (f, " known_hot"); |
147 | } |
148 | if (hints & INLINE_HINT_builtin_constant_p) |
149 | { |
150 | hints &= ~INLINE_HINT_builtin_constant_p; |
151 | fprintf (f, " builtin_constant_p"); |
152 | } |
153 | gcc_assert (!hints)((void)(!(!hints) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 153, __FUNCTION__), 0 : 0)); |
154 | } |
155 | |
156 | |
157 | /* Record SIZE and TIME to SUMMARY. |
158 | The accounted code will be executed when EXEC_PRED is true. |
159 | When NONCONST_PRED is false the code will evaluate to constant and |
160 | will get optimized out in specialized clones of the function. |
161 | If CALL is true account to call_size_time_table rather than |
162 | size_time_table. */ |
163 | |
164 | void |
165 | ipa_fn_summary::account_size_time (int size, sreal time, |
166 | const ipa_predicate &exec_pred, |
167 | const ipa_predicate &nonconst_pred_in, |
168 | bool call) |
169 | { |
170 | size_time_entry *e; |
171 | bool found = false; |
172 | int i; |
173 | ipa_predicate nonconst_pred; |
174 | vec<size_time_entry> *table = call ? &call_size_time_table : &size_time_table; |
175 | |
176 | if (exec_pred == false) |
177 | return; |
178 | |
179 | nonconst_pred = nonconst_pred_in & exec_pred; |
180 | |
181 | if (nonconst_pred == false) |
182 | return; |
183 | |
184 | /* We need to create initial empty unconditional clause, but otherwise |
185 | we don't need to account empty times and sizes. */ |
186 | if (!size && time == 0 && table->length ()) |
187 | return; |
188 | |
189 | /* Only for calls we are unaccounting what we previously recorded. */ |
190 | gcc_checking_assert (time >= 0 || call)((void)(!(time >= 0 || call) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 190, __FUNCTION__), 0 : 0)); |
191 | |
192 | for (i = 0; table->iterate (i, &e); i++) |
193 | if (e->exec_predicate == exec_pred |
194 | && e->nonconst_predicate == nonconst_pred) |
195 | { |
196 | found = true; |
197 | break; |
198 | } |
199 | if (i == max_size_time_table_size) |
200 | { |
201 | i = 0; |
Value stored to 'i' is never read | |
202 | found = true; |
203 | e = &(*table)[0]; |
204 | if (dump_file && (dump_flags & TDF_DETAILS)) |
205 | fprintf (dump_file, |
206 | "\t\tReached limit on number of entries, " |
207 | "ignoring the predicate."); |
208 | } |
209 | if (dump_file && (dump_flags & TDF_DETAILS) && (time != 0 || size)) |
210 | { |
211 | fprintf (dump_file, |
212 | "\t\tAccounting size:%3.2f, time:%3.2f on %spredicate exec:", |
213 | ((double) size) / ipa_fn_summary::size_scale, |
214 | (time.to_double ()), found ? "" : "new "); |
215 | exec_pred.dump (dump_file, conds, 0); |
216 | if (exec_pred != nonconst_pred) |
217 | { |
218 | fprintf (dump_file, " nonconst:"); |
219 | nonconst_pred.dump (dump_file, conds); |
220 | } |
221 | else |
222 | fprintf (dump_file, "\n"); |
223 | } |
224 | if (!found) |
225 | { |
226 | class size_time_entry new_entry; |
227 | new_entry.size = size; |
228 | new_entry.time = time; |
229 | new_entry.exec_predicate = exec_pred; |
230 | new_entry.nonconst_predicate = nonconst_pred; |
231 | if (call) |
232 | call_size_time_table.safe_push (new_entry); |
233 | else |
234 | size_time_table.safe_push (new_entry); |
235 | } |
236 | else |
237 | { |
238 | e->size += size; |
239 | e->time += time; |
240 | /* FIXME: PR bootstrap/92653 gcc_checking_assert (e->time >= -1); */ |
241 | /* Tolerate small roundoff issues. */ |
242 | if (e->time < 0) |
243 | e->time = 0; |
244 | } |
245 | } |
246 | |
247 | /* We proved E to be unreachable, redirect it to __builtin_unreachable. */ |
248 | |
249 | static struct cgraph_edge * |
250 | redirect_to_unreachable (struct cgraph_edge *e) |
251 | { |
252 | struct cgraph_node *callee = !e->inline_failed ? e->callee : NULLnullptr; |
253 | struct cgraph_node *target |
254 | = cgraph_node::get_create (builtin_decl_unreachable ()); |
255 | |
256 | if (e->speculative) |
257 | e = cgraph_edge::resolve_speculation (e, target->decl); |
258 | else if (!e->callee) |
259 | e = cgraph_edge::make_direct (e, target); |
260 | else |
261 | e->redirect_callee (target); |
262 | class ipa_call_summary *es = ipa_call_summaries->get (e); |
263 | e->inline_failed = CIF_UNREACHABLE; |
264 | e->count = profile_count::zero (); |
265 | es->call_stmt_size = 0; |
266 | es->call_stmt_time = 0; |
267 | if (callee) |
268 | callee->remove_symbol_and_inline_clones (); |
269 | return e; |
270 | } |
271 | |
272 | /* Set predicate for edge E. */ |
273 | |
274 | static void |
275 | edge_set_predicate (struct cgraph_edge *e, ipa_predicate *predicate) |
276 | { |
277 | /* If the edge is determined to be never executed, redirect it |
278 | to BUILTIN_UNREACHABLE to make it clear to IPA passes the call will |
279 | be optimized out. */ |
280 | if (predicate && *predicate == false |
281 | /* When handling speculative edges, we need to do the redirection |
282 | just once. Do it always on the direct edge, so we do not |
283 | attempt to resolve speculation while duplicating the edge. */ |
284 | && (!e->speculative || e->callee)) |
285 | e = redirect_to_unreachable (e); |
286 | |
287 | class ipa_call_summary *es = ipa_call_summaries->get (e); |
288 | if (predicate && *predicate != true) |
289 | { |
290 | if (!es->predicate) |
291 | es->predicate = edge_predicate_pool.allocate (); |
292 | *es->predicate = *predicate; |
293 | } |
294 | else |
295 | { |
296 | if (es->predicate) |
297 | edge_predicate_pool.remove (es->predicate); |
298 | es->predicate = NULLnullptr; |
299 | } |
300 | } |
301 | |
302 | /* Set predicate for hint *P. */ |
303 | |
304 | static void |
305 | set_hint_predicate (ipa_predicate **p, ipa_predicate new_predicate) |
306 | { |
307 | if (new_predicate == false || new_predicate == true) |
308 | { |
309 | if (*p) |
310 | edge_predicate_pool.remove (*p); |
311 | *p = NULLnullptr; |
312 | } |
313 | else |
314 | { |
315 | if (!*p) |
316 | *p = edge_predicate_pool.allocate (); |
317 | **p = new_predicate; |
318 | } |
319 | } |
320 | |
321 | /* Find if NEW_PREDICATE is already in V and if so, increment its freq. |
322 | Otherwise add a new item to the vector with this predicate and frerq equal |
323 | to add_freq, unless the number of predicates would exceed MAX_NUM_PREDICATES |
324 | in which case the function does nothing. */ |
325 | |
326 | static void |
327 | add_freqcounting_predicate (vec<ipa_freqcounting_predicate, va_gc> **v, |
328 | const ipa_predicate &new_predicate, sreal add_freq, |
329 | unsigned max_num_predicates) |
330 | { |
331 | if (new_predicate == false || new_predicate == true) |
332 | return; |
333 | ipa_freqcounting_predicate *f; |
334 | for (int i = 0; vec_safe_iterate (*v, i, &f); i++) |
335 | if (new_predicate == f->predicate) |
336 | { |
337 | f->freq += add_freq; |
338 | return; |
339 | } |
340 | if (vec_safe_length (*v) >= max_num_predicates) |
341 | /* Too many different predicates to account for. */ |
342 | return; |
343 | |
344 | ipa_freqcounting_predicate fcp; |
345 | fcp.predicate = NULLnullptr; |
346 | set_hint_predicate (&fcp.predicate, new_predicate); |
347 | fcp.freq = add_freq; |
348 | vec_safe_push (*v, fcp); |
349 | return; |
350 | } |
351 | |
352 | /* Compute what conditions may or may not hold given information about |
353 | parameters. RET_CLAUSE returns truths that may hold in a specialized copy, |
354 | while RET_NONSPEC_CLAUSE returns truths that may hold in an nonspecialized |
355 | copy when called in a given context. It is a bitmask of conditions. Bit |
356 | 0 means that condition is known to be false, while bit 1 means that condition |
357 | may or may not be true. These differs - for example NOT_INLINED condition |
358 | is always false in the second and also builtin_constant_p tests cannot use |
359 | the fact that parameter is indeed a constant. |
360 | |
361 | When INLINE_P is true, assume that we are inlining. AVAL contains known |
362 | information about argument values. The function does not modify its content |
363 | and so AVALs could also be of type ipa_call_arg_values but so far all |
364 | callers work with the auto version and so we avoid the conversion for |
365 | convenience. |
366 | |
367 | ERROR_MARK value of an argument means compile time invariant. */ |
368 | |
369 | static void |
370 | evaluate_conditions_for_known_args (struct cgraph_node *node, |
371 | bool inline_p, |
372 | ipa_auto_call_arg_values *avals, |
373 | clause_t *ret_clause, |
374 | clause_t *ret_nonspec_clause) |
375 | { |
376 | clause_t clause = inline_p ? 0 : 1 << ipa_predicate::not_inlined_condition; |
377 | clause_t nonspec_clause = 1 << ipa_predicate::not_inlined_condition; |
378 | class ipa_fn_summary *info = ipa_fn_summaries->get (node); |
379 | int i; |
380 | struct condition *c; |
381 | |
382 | for (i = 0; vec_safe_iterate (info->conds, i, &c); i++) |
383 | { |
384 | tree val = NULLnullptr; |
385 | tree res; |
386 | int j; |
387 | struct expr_eval_op *op; |
388 | |
389 | if (c->agg_contents) |
390 | { |
391 | if (c->code == ipa_predicate::changed |
392 | && !c->by_ref |
393 | && (avals->safe_sval_at(c->operand_num) == error_mark_nodeglobal_trees[TI_ERROR_MARK])) |
394 | continue; |
395 | |
396 | if (tree sval = avals->safe_sval_at (c->operand_num)) |
397 | val = ipa_find_agg_cst_from_init (sval, c->offset, c->by_ref); |
398 | if (!val) |
399 | { |
400 | ipa_argagg_value_list avs (avals); |
401 | val = avs.get_value (c->operand_num, c->offset / BITS_PER_UNIT(8), |
402 | c->by_ref); |
403 | } |
404 | } |
405 | else |
406 | { |
407 | val = avals->safe_sval_at (c->operand_num); |
408 | if (val && val == error_mark_nodeglobal_trees[TI_ERROR_MARK] |
409 | && c->code != ipa_predicate::changed) |
410 | val = NULL_TREE(tree) nullptr; |
411 | } |
412 | |
413 | if (!val |
414 | && (c->code == ipa_predicate::changed |
415 | || c->code == ipa_predicate::is_not_constant)) |
416 | { |
417 | clause |= 1 << (i + ipa_predicate::first_dynamic_condition); |
418 | nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition); |
419 | continue; |
420 | } |
421 | if (c->code == ipa_predicate::changed) |
422 | { |
423 | nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition); |
424 | continue; |
425 | } |
426 | |
427 | if (c->code == ipa_predicate::is_not_constant) |
428 | { |
429 | nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition); |
430 | continue; |
431 | } |
432 | |
433 | if (val && TYPE_SIZE (c->type)((tree_class_check ((c->type), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 433, __FUNCTION__))->type_common.size) == TYPE_SIZE (TREE_TYPE (val))((tree_class_check ((((contains_struct_check ((val), (TS_TYPED ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 433, __FUNCTION__))->typed.type)), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 433, __FUNCTION__))->type_common.size)) |
434 | { |
435 | if (c->type != TREE_TYPE (val)((contains_struct_check ((val), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 435, __FUNCTION__))->typed.type)) |
436 | val = fold_unary (VIEW_CONVERT_EXPR, c->type, val)fold_unary_loc (((location_t) 0), VIEW_CONVERT_EXPR, c->type , val); |
437 | for (j = 0; vec_safe_iterate (c->param_ops, j, &op); j++) |
438 | { |
439 | if (!val) |
440 | break; |
441 | if (!op->val[0]) |
442 | val = fold_unary (op->code, op->type, val)fold_unary_loc (((location_t) 0), op->code, op->type, val ); |
443 | else if (!op->val[1]) |
444 | val = fold_binary (op->code, op->type,fold_binary_loc (((location_t) 0), op->code, op->type, op ->index ? op->val[0] : val, op->index ? val : op-> val[0]) |
445 | op->index ? op->val[0] : val,fold_binary_loc (((location_t) 0), op->code, op->type, op ->index ? op->val[0] : val, op->index ? val : op-> val[0]) |
446 | op->index ? val : op->val[0])fold_binary_loc (((location_t) 0), op->code, op->type, op ->index ? op->val[0] : val, op->index ? val : op-> val[0]); |
447 | else if (op->index == 0) |
448 | val = fold_ternary (op->code, op->type,fold_ternary_loc (((location_t) 0), op->code, op->type, val, op->val[0], op->val[1]) |
449 | val, op->val[0], op->val[1])fold_ternary_loc (((location_t) 0), op->code, op->type, val, op->val[0], op->val[1]); |
450 | else if (op->index == 1) |
451 | val = fold_ternary (op->code, op->type,fold_ternary_loc (((location_t) 0), op->code, op->type, op->val[0], val, op->val[1]) |
452 | op->val[0], val, op->val[1])fold_ternary_loc (((location_t) 0), op->code, op->type, op->val[0], val, op->val[1]); |
453 | else if (op->index == 2) |
454 | val = fold_ternary (op->code, op->type,fold_ternary_loc (((location_t) 0), op->code, op->type, op->val[0], op->val[1], val) |
455 | op->val[0], op->val[1], val)fold_ternary_loc (((location_t) 0), op->code, op->type, op->val[0], op->val[1], val); |
456 | else |
457 | val = NULL_TREE(tree) nullptr; |
458 | } |
459 | |
460 | res = val |
461 | ? fold_binary_to_constant (c->code, boolean_type_nodeglobal_trees[TI_BOOLEAN_TYPE], val, c->val) |
462 | : NULLnullptr; |
463 | |
464 | if (res && integer_zerop (res)) |
465 | continue; |
466 | if (res && integer_onep (res)) |
467 | { |
468 | clause |= 1 << (i + ipa_predicate::first_dynamic_condition); |
469 | nonspec_clause |
470 | |= 1 << (i + ipa_predicate::first_dynamic_condition); |
471 | continue; |
472 | } |
473 | } |
474 | if (c->operand_num < (int) avals->m_known_value_ranges.length () |
475 | && !c->agg_contents |
476 | && (!val || TREE_CODE (val)((enum tree_code) (val)->base.code) != INTEGER_CST)) |
477 | { |
478 | value_range vr = avals->m_known_value_ranges[c->operand_num]; |
479 | if (!vr.undefined_p () |
480 | && !vr.varying_p () |
481 | && (TYPE_SIZE (c->type)((tree_class_check ((c->type), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 481, __FUNCTION__))->type_common.size) == TYPE_SIZE (vr.type ())((tree_class_check ((vr.type ()), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 481, __FUNCTION__))->type_common.size))) |
482 | { |
483 | if (!useless_type_conversion_p (c->type, vr.type ())) |
484 | { |
485 | value_range res; |
486 | range_fold_unary_expr (&res, NOP_EXPR, |
487 | c->type, &vr, vr.type ()); |
488 | vr = res; |
489 | } |
490 | tree type = c->type; |
491 | |
492 | for (j = 0; vec_safe_iterate (c->param_ops, j, &op); j++) |
493 | { |
494 | if (vr.varying_p () || vr.undefined_p ()) |
495 | break; |
496 | |
497 | value_range res; |
498 | if (!op->val[0]) |
499 | range_fold_unary_expr (&res, op->code, op->type, &vr, type); |
500 | else if (!op->val[1]) |
501 | { |
502 | value_range op0 (op->val[0], op->val[0]); |
503 | range_fold_binary_expr (&res, op->code, op->type, |
504 | op->index ? &op0 : &vr, |
505 | op->index ? &vr : &op0); |
506 | } |
507 | else |
508 | res.set_varying (op->type); |
509 | type = op->type; |
510 | vr = res; |
511 | } |
512 | if (!vr.varying_p () && !vr.undefined_p ()) |
513 | { |
514 | value_range res; |
515 | value_range val_vr (c->val, c->val); |
516 | range_fold_binary_expr (&res, c->code, boolean_type_nodeglobal_trees[TI_BOOLEAN_TYPE], |
517 | &vr, |
518 | &val_vr); |
519 | if (res.zero_p ()) |
520 | continue; |
521 | } |
522 | } |
523 | } |
524 | |
525 | clause |= 1 << (i + ipa_predicate::first_dynamic_condition); |
526 | nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition); |
527 | } |
528 | *ret_clause = clause; |
529 | if (ret_nonspec_clause) |
530 | *ret_nonspec_clause = nonspec_clause; |
531 | } |
532 | |
533 | /* Return true if VRP will be exectued on the function. |
534 | We do not want to anticipate optimizations that will not happen. |
535 | |
536 | FIXME: This can be confused with -fdisable and debug counters and thus |
537 | it should not be used for correctness (only to make heuristics work). |
538 | This means that inliner should do its own optimizations of expressions |
539 | that it predicts to be constant so wrong code can not be triggered by |
540 | builtin_constant_p. */ |
541 | |
542 | static bool |
543 | vrp_will_run_p (struct cgraph_node *node) |
544 | { |
545 | return (opt_for_fn (node->decl, optimize)(opts_for_fn (node->decl)->x_optimize) |
546 | && !opt_for_fn (node->decl, optimize_debug)(opts_for_fn (node->decl)->x_optimize_debug) |
547 | && opt_for_fn (node->decl, flag_tree_vrp)(opts_for_fn (node->decl)->x_flag_tree_vrp)); |
548 | } |
549 | |
550 | /* Similarly about FRE. */ |
551 | |
552 | static bool |
553 | fre_will_run_p (struct cgraph_node *node) |
554 | { |
555 | return (opt_for_fn (node->decl, optimize)(opts_for_fn (node->decl)->x_optimize) |
556 | && !opt_for_fn (node->decl, optimize_debug)(opts_for_fn (node->decl)->x_optimize_debug) |
557 | && opt_for_fn (node->decl, flag_tree_fre)(opts_for_fn (node->decl)->x_flag_tree_fre)); |
558 | } |
559 | |
560 | /* Work out what conditions might be true at invocation of E. |
561 | Compute costs for inlined edge if INLINE_P is true. |
562 | |
563 | Return in CLAUSE_PTR the evaluated conditions and in NONSPEC_CLAUSE_PTR |
564 | (if non-NULL) conditions evaluated for nonspecialized clone called |
565 | in a given context. |
566 | |
567 | Vectors in AVALS will be populated with useful known information about |
568 | argument values - information not known to have any uses will be omitted - |
569 | except for m_known_contexts which will only be calculated if |
570 | COMPUTE_CONTEXTS is true. */ |
571 | |
572 | void |
573 | evaluate_properties_for_edge (struct cgraph_edge *e, bool inline_p, |
574 | clause_t *clause_ptr, |
575 | clause_t *nonspec_clause_ptr, |
576 | ipa_auto_call_arg_values *avals, |
577 | bool compute_contexts) |
578 | { |
579 | struct cgraph_node *callee = e->callee->ultimate_alias_target (); |
580 | class ipa_fn_summary *info = ipa_fn_summaries->get (callee); |
581 | class ipa_edge_args *args; |
582 | |
583 | if (clause_ptr) |
584 | *clause_ptr = inline_p ? 0 : 1 << ipa_predicate::not_inlined_condition; |
585 | |
586 | if (ipa_node_params_sum |
587 | && !e->call_stmt_cannot_inline_p |
588 | && (info->conds || compute_contexts) |
589 | && (args = ipa_edge_args_sum->get (e)) != NULLnullptr) |
590 | { |
591 | struct cgraph_node *caller; |
592 | class ipa_node_params *caller_parms_info, *callee_pi = NULLnullptr; |
593 | class ipa_call_summary *es = ipa_call_summaries->get (e); |
594 | int i, count = ipa_get_cs_argument_count (args); |
595 | |
596 | if (count) |
597 | { |
598 | if (e->caller->inlined_to) |
599 | caller = e->caller->inlined_to; |
600 | else |
601 | caller = e->caller; |
602 | caller_parms_info = ipa_node_params_sum->get (caller); |
603 | callee_pi = ipa_node_params_sum->get (callee); |
604 | |
605 | /* Watch for thunks. */ |
606 | if (callee_pi) |
607 | /* Watch for variadic functions. */ |
608 | count = MIN (count, ipa_get_param_count (callee_pi))((count) < (ipa_get_param_count (callee_pi)) ? (count) : ( ipa_get_param_count (callee_pi))); |
609 | } |
610 | |
611 | if (callee_pi) |
612 | for (i = 0; i < count; i++) |
613 | { |
614 | struct ipa_jump_func *jf = ipa_get_ith_jump_func (args, i); |
615 | |
616 | if (ipa_is_param_used_by_indirect_call (callee_pi, i) |
617 | || ipa_is_param_used_by_ipa_predicates (callee_pi, i)) |
618 | { |
619 | /* Determine if we know constant value of the parameter. */ |
620 | tree cst = ipa_value_from_jfunc (caller_parms_info, jf, |
621 | ipa_get_type (callee_pi, i)); |
622 | |
623 | if (!cst && e->call_stmt |
624 | && i < (int)gimple_call_num_args (e->call_stmt)) |
625 | { |
626 | cst = gimple_call_arg (e->call_stmt, i); |
627 | if (!is_gimple_min_invariant (cst)) |
628 | cst = NULLnullptr; |
629 | } |
630 | if (cst) |
631 | { |
632 | gcc_checking_assert (TREE_CODE (cst) != TREE_BINFO)((void)(!(((enum tree_code) (cst)->base.code) != TREE_BINFO ) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 632, __FUNCTION__), 0 : 0)); |
633 | if (!avals->m_known_vals.length ()) |
634 | avals->m_known_vals.safe_grow_cleared (count, true); |
635 | avals->m_known_vals[i] = cst; |
636 | } |
637 | else if (inline_p && !es->param[i].change_prob) |
638 | { |
639 | if (!avals->m_known_vals.length ()) |
640 | avals->m_known_vals.safe_grow_cleared (count, true); |
641 | avals->m_known_vals[i] = error_mark_nodeglobal_trees[TI_ERROR_MARK]; |
642 | } |
643 | |
644 | /* If we failed to get simple constant, try value range. */ |
645 | if ((!cst || TREE_CODE (cst)((enum tree_code) (cst)->base.code) != INTEGER_CST) |
646 | && vrp_will_run_p (caller) |
647 | && ipa_is_param_used_by_ipa_predicates (callee_pi, i)) |
648 | { |
649 | value_range vr |
650 | = ipa_value_range_from_jfunc (caller_parms_info, e, jf, |
651 | ipa_get_type (callee_pi, |
652 | i)); |
653 | if (!vr.undefined_p () && !vr.varying_p ()) |
654 | { |
655 | if (!avals->m_known_value_ranges.length ()) |
656 | { |
657 | avals->m_known_value_ranges.safe_grow (count, true); |
658 | for (int i = 0; i < count; ++i) |
659 | new (&avals->m_known_value_ranges[i]) |
660 | value_range (); |
661 | } |
662 | avals->m_known_value_ranges[i] = vr; |
663 | } |
664 | } |
665 | |
666 | /* Determine known aggregate values. */ |
667 | if (fre_will_run_p (caller)) |
668 | ipa_push_agg_values_from_jfunc (caller_parms_info, |
669 | caller, &jf->agg, i, |
670 | &avals->m_known_aggs); |
671 | } |
672 | |
673 | /* For calls used in polymorphic calls we further determine |
674 | polymorphic call context. */ |
675 | if (compute_contexts |
676 | && ipa_is_param_used_by_polymorphic_call (callee_pi, i)) |
677 | { |
678 | ipa_polymorphic_call_context |
679 | ctx = ipa_context_from_jfunc (caller_parms_info, e, i, jf); |
680 | if (!ctx.useless_p ()) |
681 | { |
682 | if (!avals->m_known_contexts.length ()) |
683 | avals->m_known_contexts.safe_grow_cleared (count, true); |
684 | avals->m_known_contexts[i] |
685 | = ipa_context_from_jfunc (caller_parms_info, e, i, jf); |
686 | } |
687 | } |
688 | } |
689 | else |
690 | gcc_assert (!count || callee->thunk)((void)(!(!count || callee->thunk) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 690, __FUNCTION__), 0 : 0)); |
691 | } |
692 | else if (e->call_stmt && !e->call_stmt_cannot_inline_p && info->conds) |
693 | { |
694 | int i, count = (int)gimple_call_num_args (e->call_stmt); |
695 | |
696 | for (i = 0; i < count; i++) |
697 | { |
698 | tree cst = gimple_call_arg (e->call_stmt, i); |
699 | if (!is_gimple_min_invariant (cst)) |
700 | cst = NULLnullptr; |
701 | if (cst) |
702 | { |
703 | if (!avals->m_known_vals.length ()) |
704 | avals->m_known_vals.safe_grow_cleared (count, true); |
705 | avals->m_known_vals[i] = cst; |
706 | } |
707 | } |
708 | } |
709 | |
710 | evaluate_conditions_for_known_args (callee, inline_p, avals, clause_ptr, |
711 | nonspec_clause_ptr); |
712 | } |
713 | |
714 | |
715 | /* Allocate the function summary. */ |
716 | |
717 | static void |
718 | ipa_fn_summary_alloc (void) |
719 | { |
720 | gcc_checking_assert (!ipa_fn_summaries)((void)(!(!ipa_fn_summaries) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 720, __FUNCTION__), 0 : 0)); |
721 | ipa_size_summaries = new ipa_size_summary_t (symtab); |
722 | ipa_fn_summaries = ipa_fn_summary_t::create_ggc (symtab); |
723 | ipa_call_summaries = new ipa_call_summary_t (symtab); |
724 | } |
725 | |
726 | ipa_call_summary::~ipa_call_summary () |
727 | { |
728 | if (predicate) |
729 | edge_predicate_pool.remove (predicate); |
730 | |
731 | param.release (); |
732 | } |
733 | |
734 | ipa_fn_summary::~ipa_fn_summary () |
735 | { |
736 | unsigned len = vec_safe_length (loop_iterations); |
737 | for (unsigned i = 0; i < len; i++) |
738 | edge_predicate_pool.remove ((*loop_iterations)[i].predicate); |
739 | len = vec_safe_length (loop_strides); |
740 | for (unsigned i = 0; i < len; i++) |
741 | edge_predicate_pool.remove ((*loop_strides)[i].predicate); |
742 | vec_free (conds); |
743 | call_size_time_table.release (); |
744 | vec_free (loop_iterations); |
745 | vec_free (loop_strides); |
746 | builtin_constant_p_parms.release (); |
747 | } |
748 | |
749 | void |
750 | ipa_fn_summary_t::remove_callees (cgraph_node *node) |
751 | { |
752 | cgraph_edge *e; |
753 | for (e = node->callees; e; e = e->next_callee) |
754 | ipa_call_summaries->remove (e); |
755 | for (e = node->indirect_calls; e; e = e->next_callee) |
756 | ipa_call_summaries->remove (e); |
757 | } |
758 | |
759 | /* Duplicate predicates in loop hint vector, allocating memory for them and |
760 | remove and deallocate any uninteresting (true or false) ones. Return the |
761 | result. */ |
762 | |
763 | static vec<ipa_freqcounting_predicate, va_gc> * |
764 | remap_freqcounting_preds_after_dup (vec<ipa_freqcounting_predicate, va_gc> *v, |
765 | clause_t possible_truths) |
766 | { |
767 | if (vec_safe_length (v) == 0) |
768 | return NULLnullptr; |
769 | |
770 | vec<ipa_freqcounting_predicate, va_gc> *res = v->copy (); |
771 | int len = res->length(); |
772 | for (int i = len - 1; i >= 0; i--) |
773 | { |
774 | ipa_predicate new_predicate |
775 | = (*res)[i].predicate->remap_after_duplication (possible_truths); |
776 | /* We do not want to free previous predicate; it is used by node |
777 | origin. */ |
778 | (*res)[i].predicate = NULLnullptr; |
779 | set_hint_predicate (&(*res)[i].predicate, new_predicate); |
780 | |
781 | if (!(*res)[i].predicate) |
782 | res->unordered_remove (i); |
783 | } |
784 | |
785 | return res; |
786 | } |
787 | |
788 | |
789 | /* Hook that is called by cgraph.cc when a node is duplicated. */ |
790 | void |
791 | ipa_fn_summary_t::duplicate (cgraph_node *src, |
792 | cgraph_node *dst, |
793 | ipa_fn_summary *src_info, |
794 | ipa_fn_summary *info) |
795 | { |
796 | new (info) ipa_fn_summary (*src_info); |
797 | /* TODO: as an optimization, we may avoid copying conditions |
798 | that are known to be false or true. */ |
799 | info->conds = vec_safe_copy (info->conds); |
800 | |
801 | clone_info *cinfo = clone_info::get (dst); |
802 | /* When there are any replacements in the function body, see if we can figure |
803 | out that something was optimized out. */ |
804 | if (ipa_node_params_sum && cinfo && cinfo->tree_map) |
805 | { |
806 | /* Use SRC parm info since it may not be copied yet. */ |
807 | ipa_node_params *parms_info = ipa_node_params_sum->get (src); |
808 | ipa_auto_call_arg_values avals; |
809 | int count = ipa_get_param_count (parms_info); |
810 | int i, j; |
811 | clause_t possible_truths; |
812 | ipa_predicate true_pred = true; |
813 | size_time_entry *e; |
814 | int optimized_out_size = 0; |
815 | bool inlined_to_p = false; |
816 | struct cgraph_edge *edge, *next; |
817 | |
818 | info->size_time_table.release (); |
819 | avals.m_known_vals.safe_grow_cleared (count, true); |
820 | for (i = 0; i < count; i++) |
821 | { |
822 | struct ipa_replace_map *r; |
823 | |
824 | for (j = 0; vec_safe_iterate (cinfo->tree_map, j, &r); j++) |
825 | { |
826 | if (r->parm_num == i) |
827 | { |
828 | avals.m_known_vals[i] = r->new_tree; |
829 | break; |
830 | } |
831 | } |
832 | } |
833 | evaluate_conditions_for_known_args (dst, false, |
834 | &avals, |
835 | &possible_truths, |
836 | /* We are going to specialize, |
837 | so ignore nonspec truths. */ |
838 | NULLnullptr); |
839 | |
840 | info->account_size_time (0, 0, true_pred, true_pred); |
841 | |
842 | /* Remap size_time vectors. |
843 | Simplify the predicate by pruning out alternatives that are known |
844 | to be false. |
845 | TODO: as on optimization, we can also eliminate conditions known |
846 | to be true. */ |
847 | for (i = 0; src_info->size_time_table.iterate (i, &e); i++) |
848 | { |
849 | ipa_predicate new_exec_pred; |
850 | ipa_predicate new_nonconst_pred; |
851 | new_exec_pred = e->exec_predicate.remap_after_duplication |
852 | (possible_truths); |
853 | new_nonconst_pred = e->nonconst_predicate.remap_after_duplication |
854 | (possible_truths); |
855 | if (new_exec_pred == false || new_nonconst_pred == false) |
856 | optimized_out_size += e->size; |
857 | else |
858 | info->account_size_time (e->size, e->time, new_exec_pred, |
859 | new_nonconst_pred); |
860 | } |
861 | |
862 | /* Remap edge predicates with the same simplification as above. |
863 | Also copy constantness arrays. */ |
864 | for (edge = dst->callees; edge; edge = next) |
865 | { |
866 | ipa_predicate new_predicate; |
867 | class ipa_call_summary *es = ipa_call_summaries->get (edge); |
868 | next = edge->next_callee; |
869 | |
870 | if (!edge->inline_failed) |
871 | inlined_to_p = true; |
872 | if (!es->predicate) |
873 | continue; |
874 | new_predicate = es->predicate->remap_after_duplication |
875 | (possible_truths); |
876 | if (new_predicate == false && *es->predicate != false) |
877 | optimized_out_size += es->call_stmt_size * ipa_fn_summary::size_scale; |
878 | edge_set_predicate (edge, &new_predicate); |
879 | } |
880 | |
881 | /* Remap indirect edge predicates with the same simplification as above. |
882 | Also copy constantness arrays. */ |
883 | for (edge = dst->indirect_calls; edge; edge = next) |
884 | { |
885 | ipa_predicate new_predicate; |
886 | class ipa_call_summary *es = ipa_call_summaries->get (edge); |
887 | next = edge->next_callee; |
888 | |
889 | gcc_checking_assert (edge->inline_failed)((void)(!(edge->inline_failed) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 889, __FUNCTION__), 0 : 0)); |
890 | if (!es->predicate) |
891 | continue; |
892 | new_predicate = es->predicate->remap_after_duplication |
893 | (possible_truths); |
894 | if (new_predicate == false && *es->predicate != false) |
895 | optimized_out_size |
896 | += es->call_stmt_size * ipa_fn_summary::size_scale; |
897 | edge_set_predicate (edge, &new_predicate); |
898 | } |
899 | info->loop_iterations |
900 | = remap_freqcounting_preds_after_dup (info->loop_iterations, |
901 | possible_truths); |
902 | info->loop_strides |
903 | = remap_freqcounting_preds_after_dup (info->loop_strides, |
904 | possible_truths); |
905 | if (info->builtin_constant_p_parms.length()) |
906 | { |
907 | vec <int, va_heap, vl_ptr> parms = info->builtin_constant_p_parms; |
908 | int ip; |
909 | info->builtin_constant_p_parms = vNULL; |
910 | for (i = 0; parms.iterate (i, &ip); i++) |
911 | if (!avals.m_known_vals[ip]) |
912 | info->builtin_constant_p_parms.safe_push (ip); |
913 | } |
914 | |
915 | /* If inliner or someone after inliner will ever start producing |
916 | non-trivial clones, we will get trouble with lack of information |
917 | about updating self sizes, because size vectors already contains |
918 | sizes of the callees. */ |
919 | gcc_assert (!inlined_to_p || !optimized_out_size)((void)(!(!inlined_to_p || !optimized_out_size) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 919, __FUNCTION__), 0 : 0)); |
920 | } |
921 | else |
922 | { |
923 | info->size_time_table = src_info->size_time_table.copy (); |
924 | info->loop_iterations = vec_safe_copy (src_info->loop_iterations); |
925 | info->loop_strides = vec_safe_copy (info->loop_strides); |
926 | |
927 | info->builtin_constant_p_parms |
928 | = info->builtin_constant_p_parms.copy (); |
929 | |
930 | ipa_freqcounting_predicate *f; |
931 | for (int i = 0; vec_safe_iterate (info->loop_iterations, i, &f); i++) |
932 | { |
933 | ipa_predicate p = *f->predicate; |
934 | f->predicate = NULLnullptr; |
935 | set_hint_predicate (&f->predicate, p); |
936 | } |
937 | for (int i = 0; vec_safe_iterate (info->loop_strides, i, &f); i++) |
938 | { |
939 | ipa_predicate p = *f->predicate; |
940 | f->predicate = NULLnullptr; |
941 | set_hint_predicate (&f->predicate, p); |
942 | } |
943 | } |
944 | if (!dst->inlined_to) |
945 | ipa_update_overall_fn_summary (dst); |
946 | } |
947 | |
948 | |
949 | /* Hook that is called by cgraph.cc when a node is duplicated. */ |
950 | |
951 | void |
952 | ipa_call_summary_t::duplicate (struct cgraph_edge *src, |
953 | struct cgraph_edge *dst, |
954 | class ipa_call_summary *srcinfo, |
955 | class ipa_call_summary *info) |
956 | { |
957 | new (info) ipa_call_summary (*srcinfo); |
958 | info->predicate = NULLnullptr; |
959 | edge_set_predicate (dst, srcinfo->predicate); |
960 | info->param = srcinfo->param.copy (); |
961 | if (!dst->indirect_unknown_callee && src->indirect_unknown_callee) |
962 | { |
963 | info->call_stmt_size -= (eni_size_weights.indirect_call_cost |
964 | - eni_size_weights.call_cost); |
965 | info->call_stmt_time -= (eni_time_weights.indirect_call_cost |
966 | - eni_time_weights.call_cost); |
967 | } |
968 | } |
969 | |
970 | /* Dump edge summaries associated to NODE and recursively to all clones. |
971 | Indent by INDENT. */ |
972 | |
973 | static void |
974 | dump_ipa_call_summary (FILE *f, int indent, struct cgraph_node *node, |
975 | class ipa_fn_summary *info) |
976 | { |
977 | struct cgraph_edge *edge; |
978 | for (edge = node->callees; edge; edge = edge->next_callee) |
979 | { |
980 | class ipa_call_summary *es = ipa_call_summaries->get (edge); |
981 | struct cgraph_node *callee = edge->callee->ultimate_alias_target (); |
982 | int i; |
983 | |
984 | fprintf (f, |
985 | "%*s%s %s\n%*s freq:%4.2f", |
986 | indent, "", callee->dump_name (), |
987 | !edge->inline_failed |
988 | ? "inlined" : cgraph_inline_failed_string (edge-> inline_failed), |
989 | indent, "", edge->sreal_frequency ().to_double ()); |
990 | |
991 | if (cross_module_call_p (edge)) |
992 | fprintf (f, " cross module"); |
993 | |
994 | if (es) |
995 | fprintf (f, " loop depth:%2i size:%2i time: %2i", |
996 | es->loop_depth, es->call_stmt_size, es->call_stmt_time); |
997 | |
998 | ipa_fn_summary *s = ipa_fn_summaries->get (callee); |
999 | ipa_size_summary *ss = ipa_size_summaries->get (callee); |
1000 | if (s != NULLnullptr) |
1001 | fprintf (f, " callee size:%2i stack:%2i", |
1002 | (int) (ss->size / ipa_fn_summary::size_scale), |
1003 | (int) s->estimated_stack_size); |
1004 | |
1005 | if (es && es->predicate) |
1006 | { |
1007 | fprintf (f, " predicate: "); |
1008 | es->predicate->dump (f, info->conds); |
1009 | } |
1010 | else |
1011 | fprintf (f, "\n"); |
1012 | if (es && es->param.exists ()) |
1013 | for (i = 0; i < (int) es->param.length (); i++) |
1014 | { |
1015 | int prob = es->param[i].change_prob; |
1016 | |
1017 | if (!prob) |
1018 | fprintf (f, "%*s op%i is compile time invariant\n", |
1019 | indent + 2, "", i); |
1020 | else if (prob != REG_BR_PROB_BASE10000) |
1021 | fprintf (f, "%*s op%i change %f%% of time\n", indent + 2, "", i, |
1022 | prob * 100.0 / REG_BR_PROB_BASE10000); |
1023 | if (es->param[i].points_to_local_or_readonly_memory) |
1024 | fprintf (f, "%*s op%i points to local or readonly memory\n", |
1025 | indent + 2, "", i); |
1026 | } |
1027 | if (!edge->inline_failed) |
1028 | { |
1029 | ipa_size_summary *ss = ipa_size_summaries->get (callee); |
1030 | fprintf (f, "%*sStack frame offset %i, callee self size %i\n", |
1031 | indent + 2, "", |
1032 | (int) ipa_get_stack_frame_offset (callee), |
1033 | (int) ss->estimated_self_stack_size); |
1034 | dump_ipa_call_summary (f, indent + 2, callee, info); |
1035 | } |
1036 | } |
1037 | for (edge = node->indirect_calls; edge; edge = edge->next_callee) |
1038 | { |
1039 | class ipa_call_summary *es = ipa_call_summaries->get (edge); |
1040 | fprintf (f, "%*sindirect call loop depth:%2i freq:%4.2f size:%2i" |
1041 | " time: %2i", |
1042 | indent, "", |
1043 | es->loop_depth, |
1044 | edge->sreal_frequency ().to_double (), es->call_stmt_size, |
1045 | es->call_stmt_time); |
1046 | if (es->predicate) |
1047 | { |
1048 | fprintf (f, "predicate: "); |
1049 | es->predicate->dump (f, info->conds); |
1050 | } |
1051 | else |
1052 | fprintf (f, "\n"); |
1053 | } |
1054 | } |
1055 | |
1056 | |
1057 | void |
1058 | ipa_dump_fn_summary (FILE *f, struct cgraph_node *node) |
1059 | { |
1060 | if (node->definition) |
1061 | { |
1062 | class ipa_fn_summary *s = ipa_fn_summaries->get (node); |
1063 | class ipa_size_summary *ss = ipa_size_summaries->get (node); |
1064 | if (s != NULLnullptr) |
1065 | { |
1066 | size_time_entry *e; |
1067 | int i; |
1068 | fprintf (f, "IPA function summary for %s", node->dump_name ()); |
1069 | if (DECL_DISREGARD_INLINE_LIMITS (node->decl)((tree_check ((node->decl), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1069, __FUNCTION__, (FUNCTION_DECL)))->function_decl.disregard_inline_limits )) |
1070 | fprintf (f, " always_inline"); |
1071 | if (s->inlinable) |
1072 | fprintf (f, " inlinable"); |
1073 | if (s->fp_expressions) |
1074 | fprintf (f, " fp_expression"); |
1075 | if (s->builtin_constant_p_parms.length ()) |
1076 | { |
1077 | fprintf (f, " builtin_constant_p_parms"); |
1078 | for (unsigned int i = 0; |
1079 | i < s->builtin_constant_p_parms.length (); i++) |
1080 | fprintf (f, " %i", s->builtin_constant_p_parms[i]); |
1081 | } |
1082 | fprintf (f, "\n global time: %f\n", s->time.to_double ()); |
1083 | fprintf (f, " self size: %i\n", ss->self_size); |
1084 | fprintf (f, " global size: %i\n", ss->size); |
1085 | fprintf (f, " min size: %i\n", s->min_size); |
1086 | fprintf (f, " self stack: %i\n", |
1087 | (int) ss->estimated_self_stack_size); |
1088 | fprintf (f, " global stack: %i\n", (int) s->estimated_stack_size); |
1089 | if (s->growth) |
1090 | fprintf (f, " estimated growth:%i\n", (int) s->growth); |
1091 | if (s->scc_no) |
1092 | fprintf (f, " In SCC: %i\n", (int) s->scc_no); |
1093 | for (i = 0; s->size_time_table.iterate (i, &e); i++) |
1094 | { |
1095 | fprintf (f, " size:%f, time:%f", |
1096 | (double) e->size / ipa_fn_summary::size_scale, |
1097 | e->time.to_double ()); |
1098 | if (e->exec_predicate != true) |
1099 | { |
1100 | fprintf (f, ", executed if:"); |
1101 | e->exec_predicate.dump (f, s->conds, 0); |
1102 | } |
1103 | if (e->exec_predicate != e->nonconst_predicate) |
1104 | { |
1105 | fprintf (f, ", nonconst if:"); |
1106 | e->nonconst_predicate.dump (f, s->conds, 0); |
1107 | } |
1108 | fprintf (f, "\n"); |
1109 | } |
1110 | ipa_freqcounting_predicate *fcp; |
1111 | bool first_fcp = true; |
1112 | for (int i = 0; vec_safe_iterate (s->loop_iterations, i, &fcp); i++) |
1113 | { |
1114 | if (first_fcp) |
1115 | { |
1116 | fprintf (f, " loop iterations:"); |
1117 | first_fcp = false; |
1118 | } |
1119 | fprintf (f, " %3.2f for ", fcp->freq.to_double ()); |
1120 | fcp->predicate->dump (f, s->conds); |
1121 | } |
1122 | first_fcp = true; |
1123 | for (int i = 0; vec_safe_iterate (s->loop_strides, i, &fcp); i++) |
1124 | { |
1125 | if (first_fcp) |
1126 | { |
1127 | fprintf (f, " loop strides:"); |
1128 | first_fcp = false; |
1129 | } |
1130 | fprintf (f, " %3.2f for :", fcp->freq.to_double ()); |
1131 | fcp->predicate->dump (f, s->conds); |
1132 | } |
1133 | fprintf (f, " calls:\n"); |
1134 | dump_ipa_call_summary (f, 4, node, s); |
1135 | fprintf (f, "\n"); |
1136 | if (s->target_info) |
1137 | fprintf (f, " target_info: %x\n", s->target_info); |
1138 | } |
1139 | else |
1140 | fprintf (f, "IPA summary for %s is missing.\n", node->dump_name ()); |
1141 | } |
1142 | } |
1143 | |
1144 | DEBUG_FUNCTION__attribute__ ((__used__)) void |
1145 | ipa_debug_fn_summary (struct cgraph_node *node) |
1146 | { |
1147 | ipa_dump_fn_summary (stderrstderr, node); |
1148 | } |
1149 | |
1150 | void |
1151 | ipa_dump_fn_summaries (FILE *f) |
1152 | { |
1153 | struct cgraph_node *node; |
1154 | |
1155 | FOR_EACH_DEFINED_FUNCTION (node)for ((node) = symtab->first_defined_function (); (node); ( node) = symtab->next_defined_function ((node))) |
1156 | if (!node->inlined_to) |
1157 | ipa_dump_fn_summary (f, node); |
1158 | } |
1159 | |
1160 | /* Callback of walk_aliased_vdefs. Flags that it has been invoked to the |
1161 | boolean variable pointed to by DATA. */ |
1162 | |
1163 | static bool |
1164 | mark_modified (ao_ref *ao ATTRIBUTE_UNUSED__attribute__ ((__unused__)), tree vdef ATTRIBUTE_UNUSED__attribute__ ((__unused__)), |
1165 | void *data) |
1166 | { |
1167 | bool *b = (bool *) data; |
1168 | *b = true; |
1169 | return true; |
1170 | } |
1171 | |
1172 | /* If OP refers to value of function parameter, return the corresponding |
1173 | parameter. If non-NULL, the size of the memory load (or the SSA_NAME of the |
1174 | PARM_DECL) will be stored to *SIZE_P in that case too. */ |
1175 | |
1176 | static tree |
1177 | unmodified_parm_1 (ipa_func_body_info *fbi, gimple *stmt, tree op, |
1178 | poly_int64 *size_p) |
1179 | { |
1180 | /* SSA_NAME referring to parm default def? */ |
1181 | if (TREE_CODE (op)((enum tree_code) (op)->base.code) == SSA_NAME |
1182 | && SSA_NAME_IS_DEFAULT_DEF (op)(tree_check ((op), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1182, __FUNCTION__, (SSA_NAME)))->base.default_def_flag |
1183 | && TREE_CODE (SSA_NAME_VAR (op))((enum tree_code) (((tree_check ((op), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1183, __FUNCTION__, (SSA_NAME)))->ssa_name.var == (tree) nullptr || ((enum tree_code) ((op)->ssa_name.var)->base .code) == IDENTIFIER_NODE ? (tree) nullptr : (op)->ssa_name .var))->base.code) == PARM_DECL) |
1184 | { |
1185 | if (size_p) |
1186 | *size_p = tree_to_poly_int64 (TYPE_SIZE (TREE_TYPE (op))((tree_class_check ((((contains_struct_check ((op), (TS_TYPED ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1186, __FUNCTION__))->typed.type)), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1186, __FUNCTION__))->type_common.size)); |
1187 | return SSA_NAME_VAR (op)((tree_check ((op), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1187, __FUNCTION__, (SSA_NAME)))->ssa_name.var == (tree) nullptr || ((enum tree_code) ((op)->ssa_name.var)->base .code) == IDENTIFIER_NODE ? (tree) nullptr : (op)->ssa_name .var); |
1188 | } |
1189 | /* Non-SSA parm reference? */ |
1190 | if (TREE_CODE (op)((enum tree_code) (op)->base.code) == PARM_DECL |
1191 | && fbi->aa_walk_budget > 0) |
1192 | { |
1193 | bool modified = false; |
1194 | |
1195 | ao_ref refd; |
1196 | ao_ref_init (&refd, op); |
1197 | int walked = walk_aliased_vdefs (&refd, gimple_vuse (stmt), |
1198 | mark_modified, &modified, NULLnullptr, NULLnullptr, |
1199 | fbi->aa_walk_budget); |
1200 | if (walked < 0) |
1201 | { |
1202 | fbi->aa_walk_budget = 0; |
1203 | return NULL_TREE(tree) nullptr; |
1204 | } |
1205 | fbi->aa_walk_budget -= walked; |
1206 | if (!modified) |
1207 | { |
1208 | if (size_p) |
1209 | *size_p = tree_to_poly_int64 (TYPE_SIZE (TREE_TYPE (op))((tree_class_check ((((contains_struct_check ((op), (TS_TYPED ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1209, __FUNCTION__))->typed.type)), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1209, __FUNCTION__))->type_common.size)); |
1210 | return op; |
1211 | } |
1212 | } |
1213 | return NULL_TREE(tree) nullptr; |
1214 | } |
1215 | |
1216 | /* If OP refers to value of function parameter, return the corresponding |
1217 | parameter. Also traverse chains of SSA register assignments. If non-NULL, |
1218 | the size of the memory load (or the SSA_NAME of the PARM_DECL) will be |
1219 | stored to *SIZE_P in that case too. */ |
1220 | |
1221 | static tree |
1222 | unmodified_parm (ipa_func_body_info *fbi, gimple *stmt, tree op, |
1223 | poly_int64 *size_p) |
1224 | { |
1225 | tree res = unmodified_parm_1 (fbi, stmt, op, size_p); |
1226 | if (res) |
1227 | return res; |
1228 | |
1229 | if (TREE_CODE (op)((enum tree_code) (op)->base.code) == SSA_NAME |
1230 | && !SSA_NAME_IS_DEFAULT_DEF (op)(tree_check ((op), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1230, __FUNCTION__, (SSA_NAME)))->base.default_def_flag |
1231 | && gimple_assign_single_p (SSA_NAME_DEF_STMT (op)(tree_check ((op), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1231, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt)) |
1232 | return unmodified_parm (fbi, SSA_NAME_DEF_STMT (op)(tree_check ((op), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1232, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt, |
1233 | gimple_assign_rhs1 (SSA_NAME_DEF_STMT (op)(tree_check ((op), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1233, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt), |
1234 | size_p); |
1235 | return NULL_TREE(tree) nullptr; |
1236 | } |
1237 | |
1238 | /* If OP refers to a value of a function parameter or value loaded from an |
1239 | aggregate passed to a parameter (either by value or reference), return TRUE |
1240 | and store the number of the parameter to *INDEX_P, the access size into |
1241 | *SIZE_P, and information whether and how it has been loaded from an |
1242 | aggregate into *AGGPOS. INFO describes the function parameters, STMT is the |
1243 | statement in which OP is used or loaded. */ |
1244 | |
1245 | static bool |
1246 | unmodified_parm_or_parm_agg_item (struct ipa_func_body_info *fbi, |
1247 | gimple *stmt, tree op, int *index_p, |
1248 | poly_int64 *size_p, |
1249 | struct agg_position_info *aggpos) |
1250 | { |
1251 | tree res = unmodified_parm_1 (fbi, stmt, op, size_p); |
1252 | |
1253 | gcc_checking_assert (aggpos)((void)(!(aggpos) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1253, __FUNCTION__), 0 : 0)); |
1254 | if (res) |
1255 | { |
1256 | *index_p = ipa_get_param_decl_index (fbi->info, res); |
1257 | if (*index_p < 0) |
1258 | return false; |
1259 | aggpos->agg_contents = false; |
1260 | aggpos->by_ref = false; |
1261 | return true; |
1262 | } |
1263 | |
1264 | if (TREE_CODE (op)((enum tree_code) (op)->base.code) == SSA_NAME) |
1265 | { |
1266 | if (SSA_NAME_IS_DEFAULT_DEF (op)(tree_check ((op), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1266, __FUNCTION__, (SSA_NAME)))->base.default_def_flag |
1267 | || !gimple_assign_single_p (SSA_NAME_DEF_STMT (op)(tree_check ((op), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1267, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt)) |
1268 | return false; |
1269 | stmt = SSA_NAME_DEF_STMT (op)(tree_check ((op), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1269, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt; |
1270 | op = gimple_assign_rhs1 (stmt); |
1271 | if (!REFERENCE_CLASS_P (op)(tree_code_type_tmpl <0>::tree_code_type[(int) (((enum tree_code ) (op)->base.code))] == tcc_reference)) |
1272 | return unmodified_parm_or_parm_agg_item (fbi, stmt, op, index_p, size_p, |
1273 | aggpos); |
1274 | } |
1275 | |
1276 | aggpos->agg_contents = true; |
1277 | return ipa_load_from_parm_agg (fbi, fbi->info->descriptors, |
1278 | stmt, op, index_p, &aggpos->offset, |
1279 | size_p, &aggpos->by_ref); |
1280 | } |
1281 | |
1282 | /* See if statement might disappear after inlining. |
1283 | 0 - means not eliminated |
1284 | 1 - half of statements goes away |
1285 | 2 - for sure it is eliminated. |
1286 | We are not terribly sophisticated, basically looking for simple abstraction |
1287 | penalty wrappers. */ |
1288 | |
1289 | static int |
1290 | eliminated_by_inlining_prob (ipa_func_body_info *fbi, gimple *stmt) |
1291 | { |
1292 | enum gimple_code code = gimple_code (stmt); |
1293 | enum tree_code rhs_code; |
1294 | |
1295 | if (!optimizeglobal_options.x_optimize) |
1296 | return 0; |
1297 | |
1298 | switch (code) |
1299 | { |
1300 | case GIMPLE_RETURN: |
1301 | return 2; |
1302 | case GIMPLE_ASSIGN: |
1303 | if (gimple_num_ops (stmt) != 2) |
1304 | return 0; |
1305 | |
1306 | rhs_code = gimple_assign_rhs_code (stmt); |
1307 | |
1308 | /* Casts of parameters, loads from parameters passed by reference |
1309 | and stores to return value or parameters are often free after |
1310 | inlining due to SRA and further combining. |
1311 | Assume that half of statements goes away. */ |
1312 | if (CONVERT_EXPR_CODE_P (rhs_code)((rhs_code) == NOP_EXPR || (rhs_code) == CONVERT_EXPR) |
1313 | || rhs_code == VIEW_CONVERT_EXPR |
1314 | || rhs_code == ADDR_EXPR |
1315 | || gimple_assign_rhs_class (stmt) == GIMPLE_SINGLE_RHS) |
1316 | { |
1317 | tree rhs = gimple_assign_rhs1 (stmt); |
1318 | tree lhs = gimple_assign_lhs (stmt); |
1319 | tree inner_rhs = get_base_address (rhs); |
1320 | tree inner_lhs = get_base_address (lhs); |
1321 | bool rhs_free = false; |
1322 | bool lhs_free = false; |
1323 | |
1324 | if (!inner_rhs) |
1325 | inner_rhs = rhs; |
1326 | if (!inner_lhs) |
1327 | inner_lhs = lhs; |
1328 | |
1329 | /* Reads of parameter are expected to be free. */ |
1330 | if (unmodified_parm (fbi, stmt, inner_rhs, NULLnullptr)) |
1331 | rhs_free = true; |
1332 | /* Match expressions of form &this->field. Those will most likely |
1333 | combine with something upstream after inlining. */ |
1334 | else if (TREE_CODE (inner_rhs)((enum tree_code) (inner_rhs)->base.code) == ADDR_EXPR) |
1335 | { |
1336 | tree op = get_base_address (TREE_OPERAND (inner_rhs, 0)(*((const_cast<tree*> (tree_operand_check ((inner_rhs), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1336, __FUNCTION__)))))); |
1337 | if (TREE_CODE (op)((enum tree_code) (op)->base.code) == PARM_DECL) |
1338 | rhs_free = true; |
1339 | else if (TREE_CODE (op)((enum tree_code) (op)->base.code) == MEM_REF |
1340 | && unmodified_parm (fbi, stmt, TREE_OPERAND (op, 0)(*((const_cast<tree*> (tree_operand_check ((op), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1340, __FUNCTION__))))), |
1341 | NULLnullptr)) |
1342 | rhs_free = true; |
1343 | } |
1344 | |
1345 | /* When parameter is not SSA register because its address is taken |
1346 | and it is just copied into one, the statement will be completely |
1347 | free after inlining (we will copy propagate backward). */ |
1348 | if (rhs_free && is_gimple_reg (lhs)) |
1349 | return 2; |
1350 | |
1351 | /* Reads of parameters passed by reference |
1352 | expected to be free (i.e. optimized out after inlining). */ |
1353 | if (TREE_CODE (inner_rhs)((enum tree_code) (inner_rhs)->base.code) == MEM_REF |
1354 | && unmodified_parm (fbi, stmt, TREE_OPERAND (inner_rhs, 0)(*((const_cast<tree*> (tree_operand_check ((inner_rhs), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1354, __FUNCTION__))))), NULLnullptr)) |
1355 | rhs_free = true; |
1356 | |
1357 | /* Copying parameter passed by reference into gimple register is |
1358 | probably also going to copy propagate, but we can't be quite |
1359 | sure. */ |
1360 | if (rhs_free && is_gimple_reg (lhs)) |
1361 | lhs_free = true; |
1362 | |
1363 | /* Writes to parameters, parameters passed by value and return value |
1364 | (either directly or passed via invisible reference) are free. |
1365 | |
1366 | TODO: We ought to handle testcase like |
1367 | struct a {int a,b;}; |
1368 | struct a |
1369 | returnstruct (void) |
1370 | { |
1371 | struct a a ={1,2}; |
1372 | return a; |
1373 | } |
1374 | |
1375 | This translate into: |
1376 | |
1377 | returnstruct () |
1378 | { |
1379 | int a$b; |
1380 | int a$a; |
1381 | struct a a; |
1382 | struct a D.2739; |
1383 | |
1384 | <bb 2>: |
1385 | D.2739.a = 1; |
1386 | D.2739.b = 2; |
1387 | return D.2739; |
1388 | |
1389 | } |
1390 | For that we either need to copy ipa-split logic detecting writes |
1391 | to return value. */ |
1392 | if (TREE_CODE (inner_lhs)((enum tree_code) (inner_lhs)->base.code) == PARM_DECL |
1393 | || TREE_CODE (inner_lhs)((enum tree_code) (inner_lhs)->base.code) == RESULT_DECL |
1394 | || (TREE_CODE (inner_lhs)((enum tree_code) (inner_lhs)->base.code) == MEM_REF |
1395 | && (unmodified_parm (fbi, stmt, TREE_OPERAND (inner_lhs, 0)(*((const_cast<tree*> (tree_operand_check ((inner_lhs), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1395, __FUNCTION__))))), |
1396 | NULLnullptr) |
1397 | || (TREE_CODE (TREE_OPERAND (inner_lhs, 0))((enum tree_code) ((*((const_cast<tree*> (tree_operand_check ((inner_lhs), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1397, __FUNCTION__))))))->base.code) == SSA_NAME |
1398 | && SSA_NAME_VAR (TREE_OPERAND (inner_lhs, 0))((tree_check (((*((const_cast<tree*> (tree_operand_check ((inner_lhs), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1398, __FUNCTION__)))))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1398, __FUNCTION__, (SSA_NAME)))->ssa_name.var == (tree) nullptr || ((enum tree_code) (((*((const_cast<tree*> ( tree_operand_check ((inner_lhs), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1398, __FUNCTION__))))))->ssa_name.var)->base.code) == IDENTIFIER_NODE ? (tree) nullptr : ((*((const_cast<tree*> (tree_operand_check ((inner_lhs), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1398, __FUNCTION__))))))->ssa_name.var) |
1399 | && TREE_CODE (SSA_NAME_VAR (TREE_OPERAND((enum tree_code) (((tree_check (((*((const_cast<tree*> (tree_operand_check ((inner_lhs), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1401, __FUNCTION__)))))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1401, __FUNCTION__, (SSA_NAME)))->ssa_name.var == (tree) nullptr || ((enum tree_code) (((*((const_cast<tree*> ( tree_operand_check ((inner_lhs), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1401, __FUNCTION__))))))->ssa_name.var)->base.code) == IDENTIFIER_NODE ? (tree) nullptr : ((*((const_cast<tree*> (tree_operand_check ((inner_lhs), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1401, __FUNCTION__))))))->ssa_name.var))->base.code) |
1400 | (inner_lhs,((enum tree_code) (((tree_check (((*((const_cast<tree*> (tree_operand_check ((inner_lhs), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1401, __FUNCTION__)))))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1401, __FUNCTION__, (SSA_NAME)))->ssa_name.var == (tree) nullptr || ((enum tree_code) (((*((const_cast<tree*> ( tree_operand_check ((inner_lhs), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1401, __FUNCTION__))))))->ssa_name.var)->base.code) == IDENTIFIER_NODE ? (tree) nullptr : ((*((const_cast<tree*> (tree_operand_check ((inner_lhs), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1401, __FUNCTION__))))))->ssa_name.var))->base.code) |
1401 | 0)))((enum tree_code) (((tree_check (((*((const_cast<tree*> (tree_operand_check ((inner_lhs), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1401, __FUNCTION__)))))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1401, __FUNCTION__, (SSA_NAME)))->ssa_name.var == (tree) nullptr || ((enum tree_code) (((*((const_cast<tree*> ( tree_operand_check ((inner_lhs), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1401, __FUNCTION__))))))->ssa_name.var)->base.code) == IDENTIFIER_NODE ? (tree) nullptr : ((*((const_cast<tree*> (tree_operand_check ((inner_lhs), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1401, __FUNCTION__))))))->ssa_name.var))->base.code) == RESULT_DECL)))) |
1402 | lhs_free = true; |
1403 | if (lhs_free |
1404 | && (is_gimple_reg (rhs) || is_gimple_min_invariant (rhs))) |
1405 | rhs_free = true; |
1406 | if (lhs_free && rhs_free) |
1407 | return 1; |
1408 | } |
1409 | return 0; |
1410 | default: |
1411 | return 0; |
1412 | } |
1413 | } |
1414 | |
1415 | /* Analyze EXPR if it represents a series of simple operations performed on |
1416 | a function parameter and return true if so. FBI, STMT, EXPR, INDEX_P and |
1417 | AGGPOS have the same meaning like in unmodified_parm_or_parm_agg_item. |
1418 | Type of the parameter or load from an aggregate via the parameter is |
1419 | stored in *TYPE_P. Operations on the parameter are recorded to |
1420 | PARAM_OPS_P if it is not NULL. */ |
1421 | |
1422 | static bool |
1423 | decompose_param_expr (struct ipa_func_body_info *fbi, |
1424 | gimple *stmt, tree expr, |
1425 | int *index_p, tree *type_p, |
1426 | struct agg_position_info *aggpos, |
1427 | expr_eval_ops *param_ops_p = NULLnullptr) |
1428 | { |
1429 | int op_limit = opt_for_fn (fbi->node->decl, param_ipa_max_param_expr_ops)(opts_for_fn (fbi->node->decl)->x_param_ipa_max_param_expr_ops ); |
1430 | int op_count = 0; |
1431 | |
1432 | if (param_ops_p) |
1433 | *param_ops_p = NULLnullptr; |
1434 | |
1435 | while (true) |
1436 | { |
1437 | expr_eval_op eval_op; |
1438 | unsigned rhs_count; |
1439 | unsigned cst_count = 0; |
1440 | |
1441 | if (unmodified_parm_or_parm_agg_item (fbi, stmt, expr, index_p, NULLnullptr, |
1442 | aggpos)) |
1443 | { |
1444 | tree type = TREE_TYPE (expr)((contains_struct_check ((expr), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1444, __FUNCTION__))->typed.type); |
1445 | |
1446 | if (aggpos->agg_contents) |
1447 | { |
1448 | /* Stop if containing bit-field. */ |
1449 | if (TREE_CODE (expr)((enum tree_code) (expr)->base.code) == BIT_FIELD_REF |
1450 | || contains_bitfld_component_ref_p (expr)) |
1451 | break; |
1452 | } |
1453 | |
1454 | *type_p = type; |
1455 | return true; |
1456 | } |
1457 | |
1458 | if (TREE_CODE (expr)((enum tree_code) (expr)->base.code) != SSA_NAME || SSA_NAME_IS_DEFAULT_DEF (expr)(tree_check ((expr), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1458, __FUNCTION__, (SSA_NAME)))->base.default_def_flag) |
1459 | break; |
1460 | |
1461 | if (!is_gimple_assign (stmt = SSA_NAME_DEF_STMT (expr)(tree_check ((expr), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1461, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt)) |
1462 | break; |
1463 | |
1464 | switch (gimple_assign_rhs_class (stmt)) |
1465 | { |
1466 | case GIMPLE_SINGLE_RHS: |
1467 | expr = gimple_assign_rhs1 (stmt); |
1468 | continue; |
1469 | |
1470 | case GIMPLE_UNARY_RHS: |
1471 | rhs_count = 1; |
1472 | break; |
1473 | |
1474 | case GIMPLE_BINARY_RHS: |
1475 | rhs_count = 2; |
1476 | break; |
1477 | |
1478 | case GIMPLE_TERNARY_RHS: |
1479 | rhs_count = 3; |
1480 | break; |
1481 | |
1482 | default: |
1483 | goto fail; |
1484 | } |
1485 | |
1486 | /* Stop if expression is too complex. */ |
1487 | if (op_count++ == op_limit) |
1488 | break; |
1489 | |
1490 | if (param_ops_p) |
1491 | { |
1492 | eval_op.code = gimple_assign_rhs_code (stmt); |
1493 | eval_op.type = TREE_TYPE (gimple_assign_lhs (stmt))((contains_struct_check ((gimple_assign_lhs (stmt)), (TS_TYPED ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1493, __FUNCTION__))->typed.type); |
1494 | eval_op.val[0] = NULL_TREE(tree) nullptr; |
1495 | eval_op.val[1] = NULL_TREE(tree) nullptr; |
1496 | } |
1497 | |
1498 | expr = NULL_TREE(tree) nullptr; |
1499 | for (unsigned i = 0; i < rhs_count; i++) |
1500 | { |
1501 | tree op = gimple_op (stmt, i + 1); |
1502 | |
1503 | gcc_assert (op && !TYPE_P (op))((void)(!(op && !(tree_code_type_tmpl <0>::tree_code_type [(int) (((enum tree_code) (op)->base.code))] == tcc_type)) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1503, __FUNCTION__), 0 : 0)); |
1504 | if (is_gimple_ip_invariant (op)) |
1505 | { |
1506 | if (++cst_count == rhs_count) |
1507 | goto fail; |
1508 | |
1509 | eval_op.val[cst_count - 1] = op; |
1510 | } |
1511 | else if (!expr) |
1512 | { |
1513 | /* Found a non-constant operand, and record its index in rhs |
1514 | operands. */ |
1515 | eval_op.index = i; |
1516 | expr = op; |
1517 | } |
1518 | else |
1519 | { |
1520 | /* Found more than one non-constant operands. */ |
1521 | goto fail; |
1522 | } |
1523 | } |
1524 | |
1525 | if (param_ops_p) |
1526 | vec_safe_insert (*param_ops_p, 0, eval_op); |
1527 | } |
1528 | |
1529 | /* Failed to decompose, free resource and return. */ |
1530 | fail: |
1531 | if (param_ops_p) |
1532 | vec_free (*param_ops_p); |
1533 | |
1534 | return false; |
1535 | } |
1536 | |
1537 | /* Record to SUMMARY that PARM is used by builtin_constant_p. */ |
1538 | |
1539 | static void |
1540 | add_builtin_constant_p_parm (class ipa_fn_summary *summary, int parm) |
1541 | { |
1542 | int ip; |
1543 | |
1544 | /* Avoid duplicates. */ |
1545 | for (unsigned int i = 0; |
1546 | summary->builtin_constant_p_parms.iterate (i, &ip); i++) |
1547 | if (ip == parm) |
1548 | return; |
1549 | summary->builtin_constant_p_parms.safe_push (parm); |
1550 | } |
1551 | |
1552 | /* If BB ends by a conditional we can turn into predicates, attach corresponding |
1553 | predicates to the CFG edges. */ |
1554 | |
1555 | static void |
1556 | set_cond_stmt_execution_predicate (struct ipa_func_body_info *fbi, |
1557 | class ipa_fn_summary *summary, |
1558 | class ipa_node_params *params_summary, |
1559 | basic_block bb) |
1560 | { |
1561 | gimple *last; |
1562 | tree op, op2; |
1563 | int index; |
1564 | struct agg_position_info aggpos; |
1565 | enum tree_code code, inverted_code; |
1566 | edge e; |
1567 | edge_iterator ei; |
1568 | gimple *set_stmt; |
1569 | tree param_type; |
1570 | expr_eval_ops param_ops; |
1571 | |
1572 | last = last_stmt (bb); |
1573 | if (!last || gimple_code (last) != GIMPLE_COND) |
1574 | return; |
1575 | if (!is_gimple_ip_invariant (gimple_cond_rhs (last))) |
1576 | return; |
1577 | op = gimple_cond_lhs (last); |
1578 | |
1579 | if (decompose_param_expr (fbi, last, op, &index, ¶m_type, &aggpos, |
1580 | ¶m_ops)) |
1581 | { |
1582 | code = gimple_cond_code (last); |
1583 | inverted_code = invert_tree_comparison (code, HONOR_NANS (op)); |
1584 | |
1585 | FOR_EACH_EDGE (e, ei, bb->succs)for ((ei) = ei_start_1 (&((bb->succs))); ei_cond ((ei) , &(e)); ei_next (&(ei))) |
1586 | { |
1587 | enum tree_code this_code = (e->flags & EDGE_TRUE_VALUE |
1588 | ? code : inverted_code); |
1589 | /* invert_tree_comparison will return ERROR_MARK on FP |
1590 | comparisons that are not EQ/NE instead of returning proper |
1591 | unordered one. Be sure it is not confused with NON_CONSTANT. |
1592 | |
1593 | And if the edge's target is the final block of diamond CFG graph |
1594 | of this conditional statement, we do not need to compute |
1595 | predicate for the edge because the final block's predicate must |
1596 | be at least as that of the first block of the statement. */ |
1597 | if (this_code != ERROR_MARK |
1598 | && !dominated_by_p (CDI_POST_DOMINATORS, bb, e->dest)) |
1599 | { |
1600 | ipa_predicate p |
1601 | = add_condition (summary, params_summary, index, |
1602 | param_type, &aggpos, |
1603 | this_code, gimple_cond_rhs (last), param_ops); |
1604 | e->aux = edge_predicate_pool.allocate (); |
1605 | *(ipa_predicate *) e->aux = p; |
1606 | } |
1607 | } |
1608 | vec_free (param_ops); |
1609 | } |
1610 | |
1611 | if (TREE_CODE (op)((enum tree_code) (op)->base.code) != SSA_NAME) |
1612 | return; |
1613 | /* Special case |
1614 | if (builtin_constant_p (op)) |
1615 | constant_code |
1616 | else |
1617 | nonconstant_code. |
1618 | Here we can predicate nonconstant_code. We can't |
1619 | really handle constant_code since we have no predicate |
1620 | for this and also the constant code is not known to be |
1621 | optimized away when inliner doesn't see operand is constant. |
1622 | Other optimizers might think otherwise. */ |
1623 | if (gimple_cond_code (last) != NE_EXPR |
1624 | || !integer_zerop (gimple_cond_rhs (last))) |
1625 | return; |
1626 | set_stmt = SSA_NAME_DEF_STMT (op)(tree_check ((op), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1626, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt; |
1627 | if (!gimple_call_builtin_p (set_stmt, BUILT_IN_CONSTANT_P) |
1628 | || gimple_call_num_args (set_stmt) != 1) |
1629 | return; |
1630 | op2 = gimple_call_arg (set_stmt, 0); |
1631 | if (!decompose_param_expr (fbi, set_stmt, op2, &index, ¶m_type, &aggpos)) |
1632 | return; |
1633 | if (!aggpos.by_ref) |
1634 | add_builtin_constant_p_parm (summary, index); |
1635 | FOR_EACH_EDGE (e, ei, bb->succs)for ((ei) = ei_start_1 (&((bb->succs))); ei_cond ((ei) , &(e)); ei_next (&(ei))) if (e->flags & EDGE_FALSE_VALUE) |
1636 | { |
1637 | ipa_predicate p = add_condition (summary, params_summary, index, |
1638 | param_type, &aggpos, |
1639 | ipa_predicate::is_not_constant, NULL_TREE(tree) nullptr); |
1640 | e->aux = edge_predicate_pool.allocate (); |
1641 | *(ipa_predicate *) e->aux = p; |
1642 | } |
1643 | } |
1644 | |
1645 | |
1646 | /* If BB ends by a switch we can turn into predicates, attach corresponding |
1647 | predicates to the CFG edges. */ |
1648 | |
1649 | static void |
1650 | set_switch_stmt_execution_predicate (struct ipa_func_body_info *fbi, |
1651 | class ipa_fn_summary *summary, |
1652 | class ipa_node_params *params_summary, |
1653 | basic_block bb) |
1654 | { |
1655 | gimple *lastg; |
1656 | tree op; |
1657 | int index; |
1658 | struct agg_position_info aggpos; |
1659 | edge e; |
1660 | edge_iterator ei; |
1661 | size_t n; |
1662 | size_t case_idx; |
1663 | tree param_type; |
1664 | expr_eval_ops param_ops; |
1665 | |
1666 | lastg = last_stmt (bb); |
1667 | if (!lastg || gimple_code (lastg) != GIMPLE_SWITCH) |
1668 | return; |
1669 | gswitch *last = as_a <gswitch *> (lastg); |
1670 | op = gimple_switch_index (last); |
1671 | if (!decompose_param_expr (fbi, last, op, &index, ¶m_type, &aggpos, |
1672 | ¶m_ops)) |
1673 | return; |
1674 | |
1675 | auto_vec<std::pair<tree, tree> > ranges; |
1676 | tree type = TREE_TYPE (op)((contains_struct_check ((op), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1676, __FUNCTION__))->typed.type); |
1677 | int bound_limit = opt_for_fn (fbi->node->decl,(opts_for_fn (fbi->node->decl)->x_param_ipa_max_switch_predicate_bounds ) |
1678 | param_ipa_max_switch_predicate_bounds)(opts_for_fn (fbi->node->decl)->x_param_ipa_max_switch_predicate_bounds ); |
1679 | int bound_count = 0; |
1680 | value_range vr; |
1681 | |
1682 | get_range_query (cfun(cfun + 0))->range_of_expr (vr, op); |
1683 | if (vr.undefined_p ()) |
1684 | vr.set_varying (TREE_TYPE (op)((contains_struct_check ((op), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1684, __FUNCTION__))->typed.type)); |
1685 | value_range_kind vr_type = vr.kind (); |
1686 | wide_int vr_wmin = wi::to_wide (vr.min ()); |
1687 | wide_int vr_wmax = wi::to_wide (vr.max ()); |
1688 | |
1689 | FOR_EACH_EDGE (e, ei, bb->succs)for ((ei) = ei_start_1 (&((bb->succs))); ei_cond ((ei) , &(e)); ei_next (&(ei))) |
1690 | { |
1691 | e->aux = edge_predicate_pool.allocate (); |
1692 | *(ipa_predicate *) e->aux = false; |
1693 | } |
1694 | |
1695 | e = gimple_switch_edge (cfun(cfun + 0), last, 0); |
1696 | /* Set BOUND_COUNT to maximum count to bypass computing predicate for |
1697 | default case if its target basic block is in convergence point of all |
1698 | switch cases, which can be determined by checking whether it |
1699 | post-dominates the switch statement. */ |
1700 | if (dominated_by_p (CDI_POST_DOMINATORS, bb, e->dest)) |
1701 | bound_count = INT_MAX2147483647; |
1702 | |
1703 | n = gimple_switch_num_labels (last); |
1704 | for (case_idx = 1; case_idx < n; ++case_idx) |
1705 | { |
1706 | tree cl = gimple_switch_label (last, case_idx); |
1707 | tree min = CASE_LOW (cl)(*((const_cast<tree*> (tree_operand_check (((tree_check ((cl), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1707, __FUNCTION__, (CASE_LABEL_EXPR)))), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1707, __FUNCTION__))))); |
1708 | tree max = CASE_HIGH (cl)(*((const_cast<tree*> (tree_operand_check (((tree_check ((cl), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1708, __FUNCTION__, (CASE_LABEL_EXPR)))), (1), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1708, __FUNCTION__))))); |
1709 | ipa_predicate p; |
1710 | |
1711 | e = gimple_switch_edge (cfun(cfun + 0), last, case_idx); |
1712 | |
1713 | /* The case value might not have same type as switch expression, |
1714 | extend the value based on the expression type. */ |
1715 | if (TREE_TYPE (min)((contains_struct_check ((min), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1715, __FUNCTION__))->typed.type) != type) |
1716 | min = wide_int_to_tree (type, wi::to_wide (min)); |
1717 | |
1718 | if (!max) |
1719 | max = min; |
1720 | else if (TREE_TYPE (max)((contains_struct_check ((max), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1720, __FUNCTION__))->typed.type) != type) |
1721 | max = wide_int_to_tree (type, wi::to_wide (max)); |
1722 | |
1723 | /* The case's target basic block is in convergence point of all switch |
1724 | cases, its predicate should be at least as that of the switch |
1725 | statement. */ |
1726 | if (dominated_by_p (CDI_POST_DOMINATORS, bb, e->dest)) |
1727 | p = true; |
1728 | else if (min == max) |
1729 | p = add_condition (summary, params_summary, index, param_type, |
1730 | &aggpos, EQ_EXPR, min, param_ops); |
1731 | else |
1732 | { |
1733 | ipa_predicate p1, p2; |
1734 | p1 = add_condition (summary, params_summary, index, param_type, |
1735 | &aggpos, GE_EXPR, min, param_ops); |
1736 | p2 = add_condition (summary, params_summary,index, param_type, |
1737 | &aggpos, LE_EXPR, max, param_ops); |
1738 | p = p1 & p2; |
1739 | } |
1740 | *(ipa_predicate *) e->aux |
1741 | = p.or_with (summary->conds, *(ipa_predicate *) e->aux); |
1742 | |
1743 | /* If there are too many disjoint case ranges, predicate for default |
1744 | case might become too complicated. So add a limit here. */ |
1745 | if (bound_count > bound_limit) |
1746 | continue; |
1747 | |
1748 | bool new_range = true; |
1749 | |
1750 | if (!ranges.is_empty ()) |
1751 | { |
1752 | wide_int curr_wmin = wi::to_wide (min); |
1753 | wide_int last_wmax = wi::to_wide (ranges.last ().second); |
1754 | |
1755 | /* Merge case ranges if they are continuous. */ |
1756 | if (curr_wmin == last_wmax + 1) |
1757 | new_range = false; |
1758 | else if (vr_type == VR_ANTI_RANGE) |
1759 | { |
1760 | /* If two disjoint case ranges can be connected by anti-range |
1761 | of switch index, combine them to one range. */ |
1762 | if (wi::lt_p (vr_wmax, curr_wmin - 1, TYPE_SIGN (type)((signop) ((tree_class_check ((type), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1762, __FUNCTION__))->base.u.bits.unsigned_flag)))) |
1763 | vr_type = VR_UNDEFINED; |
1764 | else if (wi::le_p (vr_wmin, last_wmax + 1, TYPE_SIGN (type)((signop) ((tree_class_check ((type), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1764, __FUNCTION__))->base.u.bits.unsigned_flag)))) |
1765 | new_range = false; |
1766 | } |
1767 | } |
1768 | |
1769 | /* Create/extend a case range. And we count endpoints of range set, |
1770 | this number nearly equals to number of conditions that we will create |
1771 | for predicate of default case. */ |
1772 | if (new_range) |
1773 | { |
1774 | bound_count += (min == max) ? 1 : 2; |
1775 | ranges.safe_push (std::make_pair (min, max)); |
1776 | } |
1777 | else |
1778 | { |
1779 | bound_count += (ranges.last ().first == ranges.last ().second); |
1780 | ranges.last ().second = max; |
1781 | } |
1782 | } |
1783 | |
1784 | e = gimple_switch_edge (cfun(cfun + 0), last, 0); |
1785 | if (bound_count > bound_limit) |
1786 | { |
1787 | *(ipa_predicate *) e->aux = true; |
1788 | vec_free (param_ops); |
1789 | return; |
1790 | } |
1791 | |
1792 | ipa_predicate p_seg = true; |
1793 | ipa_predicate p_all = false; |
1794 | |
1795 | if (vr_type != VR_RANGE) |
1796 | { |
1797 | vr_wmin = wi::to_wide (TYPE_MIN_VALUE (type)((tree_check5 ((type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1797, __FUNCTION__, (INTEGER_TYPE), (ENUMERAL_TYPE), (BOOLEAN_TYPE ), (REAL_TYPE), (FIXED_POINT_TYPE)))->type_non_common.minval )); |
1798 | vr_wmax = wi::to_wide (TYPE_MAX_VALUE (type)((tree_check5 ((type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1798, __FUNCTION__, (INTEGER_TYPE), (ENUMERAL_TYPE), (BOOLEAN_TYPE ), (REAL_TYPE), (FIXED_POINT_TYPE)))->type_non_common.maxval )); |
1799 | } |
1800 | |
1801 | /* Construct predicate to represent default range set that is negation of |
1802 | all case ranges. Case range is classified as containing single/non-single |
1803 | values. Suppose a piece of case ranges in the following. |
1804 | |
1805 | [D1...D2] [S1] ... [Sn] [D3...D4] |
1806 | |
1807 | To represent default case's range sets between two non-single value |
1808 | case ranges (From D2 to D3), we construct predicate as: |
1809 | |
1810 | D2 < x < D3 && x != S1 && ... && x != Sn |
1811 | */ |
1812 | for (size_t i = 0; i < ranges.length (); i++) |
1813 | { |
1814 | tree min = ranges[i].first; |
1815 | tree max = ranges[i].second; |
1816 | |
1817 | if (min == max) |
1818 | p_seg &= add_condition (summary, params_summary, index, |
1819 | param_type, &aggpos, NE_EXPR, |
1820 | min, param_ops); |
1821 | else |
1822 | { |
1823 | /* Do not create sub-predicate for range that is beyond low bound |
1824 | of switch index. */ |
1825 | if (wi::lt_p (vr_wmin, wi::to_wide (min), TYPE_SIGN (type)((signop) ((tree_class_check ((type), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1825, __FUNCTION__))->base.u.bits.unsigned_flag)))) |
1826 | { |
1827 | p_seg &= add_condition (summary, params_summary, index, |
1828 | param_type, &aggpos, |
1829 | LT_EXPR, min, param_ops); |
1830 | p_all = p_all.or_with (summary->conds, p_seg); |
1831 | } |
1832 | |
1833 | /* Do not create sub-predicate for range that is beyond up bound |
1834 | of switch index. */ |
1835 | if (wi::le_p (vr_wmax, wi::to_wide (max), TYPE_SIGN (type)((signop) ((tree_class_check ((type), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1835, __FUNCTION__))->base.u.bits.unsigned_flag)))) |
1836 | { |
1837 | p_seg = false; |
1838 | break; |
1839 | } |
1840 | |
1841 | p_seg = add_condition (summary, params_summary, index, |
1842 | param_type, &aggpos, GT_EXPR, |
1843 | max, param_ops); |
1844 | } |
1845 | } |
1846 | |
1847 | p_all = p_all.or_with (summary->conds, p_seg); |
1848 | *(ipa_predicate *) e->aux |
1849 | = p_all.or_with (summary->conds, *(ipa_predicate *) e->aux); |
1850 | |
1851 | vec_free (param_ops); |
1852 | } |
1853 | |
1854 | |
1855 | /* For each BB in NODE attach to its AUX pointer predicate under |
1856 | which it is executable. */ |
1857 | |
1858 | static void |
1859 | compute_bb_predicates (struct ipa_func_body_info *fbi, |
1860 | struct cgraph_node *node, |
1861 | class ipa_fn_summary *summary, |
1862 | class ipa_node_params *params_summary) |
1863 | { |
1864 | struct function *my_function = DECL_STRUCT_FUNCTION (node->decl)((tree_check ((node->decl), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1864, __FUNCTION__, (FUNCTION_DECL)))->function_decl.f); |
1865 | bool done = false; |
1866 | basic_block bb; |
1867 | |
1868 | FOR_EACH_BB_FN (bb, my_function)for (bb = (my_function)->cfg->x_entry_block_ptr->next_bb ; bb != (my_function)->cfg->x_exit_block_ptr; bb = bb-> next_bb) |
1869 | { |
1870 | set_cond_stmt_execution_predicate (fbi, summary, params_summary, bb); |
1871 | set_switch_stmt_execution_predicate (fbi, summary, params_summary, bb); |
1872 | } |
1873 | |
1874 | /* Entry block is always executable. */ |
1875 | ENTRY_BLOCK_PTR_FOR_FN (my_function)((my_function)->cfg->x_entry_block_ptr)->aux |
1876 | = edge_predicate_pool.allocate (); |
1877 | *(ipa_predicate *) ENTRY_BLOCK_PTR_FOR_FN (my_function)((my_function)->cfg->x_entry_block_ptr)->aux = true; |
1878 | |
1879 | /* A simple dataflow propagation of predicates forward in the CFG. |
1880 | TODO: work in reverse postorder. */ |
1881 | while (!done) |
1882 | { |
1883 | done = true; |
1884 | FOR_EACH_BB_FN (bb, my_function)for (bb = (my_function)->cfg->x_entry_block_ptr->next_bb ; bb != (my_function)->cfg->x_exit_block_ptr; bb = bb-> next_bb) |
1885 | { |
1886 | ipa_predicate p = false; |
1887 | edge e; |
1888 | edge_iterator ei; |
1889 | FOR_EACH_EDGE (e, ei, bb->preds)for ((ei) = ei_start_1 (&((bb->preds))); ei_cond ((ei) , &(e)); ei_next (&(ei))) |
1890 | { |
1891 | if (e->src->aux) |
1892 | { |
1893 | ipa_predicate this_bb_predicate |
1894 | = *(ipa_predicate *) e->src->aux; |
1895 | if (e->aux) |
1896 | this_bb_predicate &= (*(ipa_predicate *) e->aux); |
1897 | p = p.or_with (summary->conds, this_bb_predicate); |
1898 | if (p == true) |
1899 | break; |
1900 | } |
1901 | } |
1902 | if (p != false) |
1903 | { |
1904 | basic_block pdom_bb; |
1905 | |
1906 | if (!bb->aux) |
1907 | { |
1908 | done = false; |
1909 | bb->aux = edge_predicate_pool.allocate (); |
1910 | *((ipa_predicate *) bb->aux) = p; |
1911 | } |
1912 | else if (p != *(ipa_predicate *) bb->aux) |
1913 | { |
1914 | /* This OR operation is needed to ensure monotonous data flow |
1915 | in the case we hit the limit on number of clauses and the |
1916 | and/or operations above give approximate answers. */ |
1917 | p = p.or_with (summary->conds, *(ipa_predicate *)bb->aux); |
1918 | if (p != *(ipa_predicate *)bb->aux) |
1919 | { |
1920 | done = false; |
1921 | *((ipa_predicate *)bb->aux) = p; |
1922 | } |
1923 | } |
1924 | |
1925 | /* For switch/if statement, we can OR-combine predicates of all |
1926 | its cases/branches to get predicate for basic block in their |
1927 | convergence point, but sometimes this will generate very |
1928 | complicated predicate. Actually, we can get simplified |
1929 | predicate in another way by using the fact that predicate |
1930 | for a basic block must also hold true for its post dominators. |
1931 | To be specific, basic block in convergence point of |
1932 | conditional statement should include predicate of the |
1933 | statement. */ |
1934 | pdom_bb = get_immediate_dominator (CDI_POST_DOMINATORS, bb); |
1935 | if (pdom_bb == EXIT_BLOCK_PTR_FOR_FN (my_function)((my_function)->cfg->x_exit_block_ptr) || !pdom_bb) |
1936 | ; |
1937 | else if (!pdom_bb->aux) |
1938 | { |
1939 | done = false; |
1940 | pdom_bb->aux = edge_predicate_pool.allocate (); |
1941 | *((ipa_predicate *)pdom_bb->aux) = p; |
1942 | } |
1943 | else if (p != *(ipa_predicate *)pdom_bb->aux) |
1944 | { |
1945 | p = p.or_with (summary->conds, |
1946 | *(ipa_predicate *)pdom_bb->aux); |
1947 | if (p != *(ipa_predicate *)pdom_bb->aux) |
1948 | { |
1949 | done = false; |
1950 | *((ipa_predicate *)pdom_bb->aux) = p; |
1951 | } |
1952 | } |
1953 | } |
1954 | } |
1955 | } |
1956 | } |
1957 | |
1958 | |
1959 | /* Return predicate specifying when the STMT might have result that is not |
1960 | a compile time constant. */ |
1961 | |
1962 | static ipa_predicate |
1963 | will_be_nonconstant_expr_predicate (ipa_func_body_info *fbi, |
1964 | class ipa_fn_summary *summary, |
1965 | class ipa_node_params *params_summary, |
1966 | tree expr, |
1967 | vec<ipa_predicate> nonconstant_names) |
1968 | { |
1969 | tree parm; |
1970 | int index; |
1971 | |
1972 | while (UNARY_CLASS_P (expr)(tree_code_type_tmpl <0>::tree_code_type[(int) (((enum tree_code ) (expr)->base.code))] == tcc_unary)) |
1973 | expr = TREE_OPERAND (expr, 0)(*((const_cast<tree*> (tree_operand_check ((expr), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1973, __FUNCTION__))))); |
1974 | |
1975 | parm = unmodified_parm (fbi, NULLnullptr, expr, NULLnullptr); |
1976 | if (parm && (index = ipa_get_param_decl_index (fbi->info, parm)) >= 0) |
1977 | return add_condition (summary, params_summary, index, TREE_TYPE (parm)((contains_struct_check ((parm), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1977, __FUNCTION__))->typed.type), NULLnullptr, |
1978 | ipa_predicate::changed, NULL_TREE(tree) nullptr); |
1979 | if (is_gimple_min_invariant (expr)) |
1980 | return false; |
1981 | if (TREE_CODE (expr)((enum tree_code) (expr)->base.code) == SSA_NAME) |
1982 | return nonconstant_names[SSA_NAME_VERSION (expr)(tree_check ((expr), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1982, __FUNCTION__, (SSA_NAME)))->base.u.version]; |
1983 | if (BINARY_CLASS_P (expr)(tree_code_type_tmpl <0>::tree_code_type[(int) (((enum tree_code ) (expr)->base.code))] == tcc_binary) || COMPARISON_CLASS_P (expr)(tree_code_type_tmpl <0>::tree_code_type[(int) (((enum tree_code ) (expr)->base.code))] == tcc_comparison)) |
1984 | { |
1985 | ipa_predicate p1 |
1986 | = will_be_nonconstant_expr_predicate (fbi, summary, |
1987 | params_summary, |
1988 | TREE_OPERAND (expr, 0)(*((const_cast<tree*> (tree_operand_check ((expr), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1988, __FUNCTION__))))), |
1989 | nonconstant_names); |
1990 | if (p1 == true) |
1991 | return p1; |
1992 | |
1993 | ipa_predicate p2 |
1994 | = will_be_nonconstant_expr_predicate (fbi, summary, |
1995 | params_summary, |
1996 | TREE_OPERAND (expr, 1)(*((const_cast<tree*> (tree_operand_check ((expr), (1), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 1996, __FUNCTION__))))), |
1997 | nonconstant_names); |
1998 | return p1.or_with (summary->conds, p2); |
1999 | } |
2000 | else if (TREE_CODE (expr)((enum tree_code) (expr)->base.code) == COND_EXPR) |
2001 | { |
2002 | ipa_predicate p1 |
2003 | = will_be_nonconstant_expr_predicate (fbi, summary, |
2004 | params_summary, |
2005 | TREE_OPERAND (expr, 0)(*((const_cast<tree*> (tree_operand_check ((expr), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2005, __FUNCTION__))))), |
2006 | nonconstant_names); |
2007 | if (p1 == true) |
2008 | return p1; |
2009 | |
2010 | ipa_predicate p2 |
2011 | = will_be_nonconstant_expr_predicate (fbi, summary, |
2012 | params_summary, |
2013 | TREE_OPERAND (expr, 1)(*((const_cast<tree*> (tree_operand_check ((expr), (1), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2013, __FUNCTION__))))), |
2014 | nonconstant_names); |
2015 | if (p2 == true) |
2016 | return p2; |
2017 | p1 = p1.or_with (summary->conds, p2); |
2018 | p2 = will_be_nonconstant_expr_predicate (fbi, summary, |
2019 | params_summary, |
2020 | TREE_OPERAND (expr, 2)(*((const_cast<tree*> (tree_operand_check ((expr), (2), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2020, __FUNCTION__))))), |
2021 | nonconstant_names); |
2022 | return p2.or_with (summary->conds, p1); |
2023 | } |
2024 | else if (TREE_CODE (expr)((enum tree_code) (expr)->base.code) == CALL_EXPR) |
2025 | return true; |
2026 | else |
2027 | { |
2028 | debug_tree (expr); |
2029 | gcc_unreachable ()(fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2029, __FUNCTION__)); |
2030 | } |
2031 | } |
2032 | |
2033 | |
2034 | /* Return predicate specifying when the STMT might have result that is not |
2035 | a compile time constant. */ |
2036 | |
2037 | static ipa_predicate |
2038 | will_be_nonconstant_predicate (struct ipa_func_body_info *fbi, |
2039 | class ipa_fn_summary *summary, |
2040 | class ipa_node_params *params_summary, |
2041 | gimple *stmt, |
2042 | vec<ipa_predicate> nonconstant_names) |
2043 | { |
2044 | ipa_predicate p = true; |
2045 | ssa_op_iter iter; |
2046 | tree use; |
2047 | tree param_type = NULL_TREE(tree) nullptr; |
2048 | ipa_predicate op_non_const; |
2049 | bool is_load; |
2050 | int base_index; |
2051 | struct agg_position_info aggpos; |
2052 | |
2053 | /* What statements might be optimized away |
2054 | when their arguments are constant. */ |
2055 | if (gimple_code (stmt) != GIMPLE_ASSIGN |
2056 | && gimple_code (stmt) != GIMPLE_COND |
2057 | && gimple_code (stmt) != GIMPLE_SWITCH |
2058 | && (gimple_code (stmt) != GIMPLE_CALL |
2059 | || !(gimple_call_flags (stmt) & ECF_CONST(1 << 0)))) |
2060 | return p; |
2061 | |
2062 | /* Stores will stay anyway. */ |
2063 | if (gimple_store_p (stmt)) |
2064 | return p; |
2065 | |
2066 | is_load = gimple_assign_load_p (stmt); |
2067 | |
2068 | /* Loads can be optimized when the value is known. */ |
2069 | if (is_load) |
2070 | { |
2071 | tree op = gimple_assign_rhs1 (stmt); |
2072 | if (!decompose_param_expr (fbi, stmt, op, &base_index, ¶m_type, |
2073 | &aggpos)) |
2074 | return p; |
2075 | } |
2076 | else |
2077 | base_index = -1; |
2078 | |
2079 | /* See if we understand all operands before we start |
2080 | adding conditionals. */ |
2081 | FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)for (use = op_iter_init_tree (&(iter), stmt, 0x01); !op_iter_done (&(iter)); (void) (use = op_iter_next_tree (&(iter)) )) |
2082 | { |
2083 | tree parm = unmodified_parm (fbi, stmt, use, NULLnullptr); |
2084 | /* For arguments we can build a condition. */ |
2085 | if (parm && ipa_get_param_decl_index (fbi->info, parm) >= 0) |
2086 | continue; |
2087 | if (TREE_CODE (use)((enum tree_code) (use)->base.code) != SSA_NAME) |
2088 | return p; |
2089 | /* If we know when operand is constant, |
2090 | we still can say something useful. */ |
2091 | if (nonconstant_names[SSA_NAME_VERSION (use)(tree_check ((use), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2091, __FUNCTION__, (SSA_NAME)))->base.u.version] != true) |
2092 | continue; |
2093 | return p; |
2094 | } |
2095 | |
2096 | if (is_load) |
2097 | op_non_const = |
2098 | add_condition (summary, params_summary, |
2099 | base_index, param_type, &aggpos, |
2100 | ipa_predicate::changed, NULL_TREE(tree) nullptr); |
2101 | else |
2102 | op_non_const = false; |
2103 | FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)for (use = op_iter_init_tree (&(iter), stmt, 0x01); !op_iter_done (&(iter)); (void) (use = op_iter_next_tree (&(iter)) )) |
2104 | { |
2105 | tree parm = unmodified_parm (fbi, stmt, use, NULLnullptr); |
2106 | int index; |
2107 | |
2108 | if (parm && (index = ipa_get_param_decl_index (fbi->info, parm)) >= 0) |
2109 | { |
2110 | if (index != base_index) |
2111 | p = add_condition (summary, params_summary, index, |
2112 | TREE_TYPE (parm)((contains_struct_check ((parm), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2112, __FUNCTION__))->typed.type), NULLnullptr, |
2113 | ipa_predicate::changed, NULL_TREE(tree) nullptr); |
2114 | else |
2115 | continue; |
2116 | } |
2117 | else |
2118 | p = nonconstant_names[SSA_NAME_VERSION (use)(tree_check ((use), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2118, __FUNCTION__, (SSA_NAME)))->base.u.version]; |
2119 | op_non_const = p.or_with (summary->conds, op_non_const); |
2120 | } |
2121 | if ((gimple_code (stmt) == GIMPLE_ASSIGN || gimple_code (stmt) == GIMPLE_CALL) |
2122 | && gimple_op (stmt, 0) |
2123 | && TREE_CODE (gimple_op (stmt, 0))((enum tree_code) (gimple_op (stmt, 0))->base.code) == SSA_NAME) |
2124 | nonconstant_names[SSA_NAME_VERSION (gimple_op (stmt, 0))(tree_check ((gimple_op (stmt, 0)), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2124, __FUNCTION__, (SSA_NAME)))->base.u.version] |
2125 | = op_non_const; |
2126 | return op_non_const; |
2127 | } |
2128 | |
2129 | struct record_modified_bb_info |
2130 | { |
2131 | tree op; |
2132 | bitmap bb_set; |
2133 | gimple *stmt; |
2134 | }; |
2135 | |
2136 | /* Value is initialized in INIT_BB and used in USE_BB. We want to compute |
2137 | probability how often it changes between USE_BB. |
2138 | INIT_BB->count/USE_BB->count is an estimate, but if INIT_BB |
2139 | is in different loop nest, we can do better. |
2140 | This is all just estimate. In theory we look for minimal cut separating |
2141 | INIT_BB and USE_BB, but we only want to anticipate loop invariant motion |
2142 | anyway. */ |
2143 | |
2144 | static basic_block |
2145 | get_minimal_bb (basic_block init_bb, basic_block use_bb) |
2146 | { |
2147 | class loop *l = find_common_loop (init_bb->loop_father, use_bb->loop_father); |
2148 | if (l && l->header->count < init_bb->count) |
2149 | return l->header; |
2150 | return init_bb; |
2151 | } |
2152 | |
2153 | /* Callback of walk_aliased_vdefs. Records basic blocks where the value may be |
2154 | set except for info->stmt. */ |
2155 | |
2156 | static bool |
2157 | record_modified (ao_ref *ao ATTRIBUTE_UNUSED__attribute__ ((__unused__)), tree vdef, void *data) |
2158 | { |
2159 | struct record_modified_bb_info *info = |
2160 | (struct record_modified_bb_info *) data; |
2161 | if (SSA_NAME_DEF_STMT (vdef)(tree_check ((vdef), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2161, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt == info->stmt) |
2162 | return false; |
2163 | if (gimple_clobber_p (SSA_NAME_DEF_STMT (vdef)(tree_check ((vdef), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2163, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt)) |
2164 | return false; |
2165 | bitmap_set_bit (info->bb_set, |
2166 | SSA_NAME_IS_DEFAULT_DEF (vdef)(tree_check ((vdef), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2166, __FUNCTION__, (SSA_NAME)))->base.default_def_flag |
2167 | ? ENTRY_BLOCK_PTR_FOR_FN (cfun)(((cfun + 0))->cfg->x_entry_block_ptr)->index |
2168 | : get_minimal_bb |
2169 | (gimple_bb (SSA_NAME_DEF_STMT (vdef)(tree_check ((vdef), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2169, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt), |
2170 | gimple_bb (info->stmt))->index); |
2171 | if (dump_file) |
2172 | { |
2173 | fprintf (dump_file, " Param "); |
2174 | print_generic_expr (dump_file, info->op, TDF_SLIM); |
2175 | fprintf (dump_file, " changed at bb %i, minimal: %i stmt: ", |
2176 | gimple_bb (SSA_NAME_DEF_STMT (vdef)(tree_check ((vdef), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2176, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt)->index, |
2177 | get_minimal_bb |
2178 | (gimple_bb (SSA_NAME_DEF_STMT (vdef)(tree_check ((vdef), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2178, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt), |
2179 | gimple_bb (info->stmt))->index); |
2180 | print_gimple_stmt (dump_file, SSA_NAME_DEF_STMT (vdef)(tree_check ((vdef), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2180, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt, 0); |
2181 | } |
2182 | return false; |
2183 | } |
2184 | |
2185 | /* Return probability (based on REG_BR_PROB_BASE) that I-th parameter of STMT |
2186 | will change since last invocation of STMT. |
2187 | |
2188 | Value 0 is reserved for compile time invariants. |
2189 | For common parameters it is REG_BR_PROB_BASE. For loop invariants it |
2190 | ought to be REG_BR_PROB_BASE / estimated_iters. */ |
2191 | |
2192 | static int |
2193 | param_change_prob (ipa_func_body_info *fbi, gimple *stmt, int i) |
2194 | { |
2195 | tree op = gimple_call_arg (stmt, i); |
2196 | basic_block bb = gimple_bb (stmt); |
2197 | |
2198 | if (TREE_CODE (op)((enum tree_code) (op)->base.code) == WITH_SIZE_EXPR) |
2199 | op = TREE_OPERAND (op, 0)(*((const_cast<tree*> (tree_operand_check ((op), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2199, __FUNCTION__))))); |
2200 | |
2201 | tree base = get_base_address (op); |
2202 | |
2203 | /* Global invariants never change. */ |
2204 | if (is_gimple_min_invariant (base)) |
2205 | return 0; |
2206 | |
2207 | /* We would have to do non-trivial analysis to really work out what |
2208 | is the probability of value to change (i.e. when init statement |
2209 | is in a sibling loop of the call). |
2210 | |
2211 | We do an conservative estimate: when call is executed N times more often |
2212 | than the statement defining value, we take the frequency 1/N. */ |
2213 | if (TREE_CODE (base)((enum tree_code) (base)->base.code) == SSA_NAME) |
2214 | { |
2215 | profile_count init_count; |
2216 | |
2217 | if (!bb->count.nonzero_p ()) |
2218 | return REG_BR_PROB_BASE10000; |
2219 | |
2220 | if (SSA_NAME_IS_DEFAULT_DEF (base)(tree_check ((base), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2220, __FUNCTION__, (SSA_NAME)))->base.default_def_flag) |
2221 | init_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)(((cfun + 0))->cfg->x_entry_block_ptr)->count; |
2222 | else |
2223 | init_count = get_minimal_bb |
2224 | (gimple_bb (SSA_NAME_DEF_STMT (base)(tree_check ((base), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2224, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt), |
2225 | gimple_bb (stmt))->count; |
2226 | |
2227 | if (init_count < bb->count) |
2228 | return MAX ((init_count.to_sreal_scale (bb->count)(((init_count.to_sreal_scale (bb->count) * 10000).to_int ( )) > (1) ? ((init_count.to_sreal_scale (bb->count) * 10000 ).to_int ()) : (1)) |
2229 | * REG_BR_PROB_BASE).to_int (), 1)(((init_count.to_sreal_scale (bb->count) * 10000).to_int ( )) > (1) ? ((init_count.to_sreal_scale (bb->count) * 10000 ).to_int ()) : (1)); |
2230 | return REG_BR_PROB_BASE10000; |
2231 | } |
2232 | else |
2233 | { |
2234 | ao_ref refd; |
2235 | profile_count max = ENTRY_BLOCK_PTR_FOR_FN (cfun)(((cfun + 0))->cfg->x_entry_block_ptr)->count; |
2236 | struct record_modified_bb_info info; |
2237 | tree init = ctor_for_folding (base); |
2238 | |
2239 | if (init != error_mark_nodeglobal_trees[TI_ERROR_MARK]) |
2240 | return 0; |
2241 | if (!bb->count.nonzero_p () || fbi->aa_walk_budget == 0) |
2242 | return REG_BR_PROB_BASE10000; |
2243 | if (dump_file) |
2244 | { |
2245 | fprintf (dump_file, " Analyzing param change probability of "); |
2246 | print_generic_expr (dump_file, op, TDF_SLIM); |
2247 | fprintf (dump_file, "\n"); |
2248 | } |
2249 | ao_ref_init (&refd, op); |
2250 | info.op = op; |
2251 | info.stmt = stmt; |
2252 | info.bb_set = BITMAP_ALLOCbitmap_alloc (NULLnullptr); |
2253 | int walked |
2254 | = walk_aliased_vdefs (&refd, gimple_vuse (stmt), record_modified, &info, |
2255 | NULLnullptr, NULLnullptr, fbi->aa_walk_budget); |
2256 | if (walked > 0) |
2257 | fbi->aa_walk_budget -= walked; |
2258 | if (walked < 0 || bitmap_bit_p (info.bb_set, bb->index)) |
2259 | { |
2260 | if (walked < 0) |
2261 | fbi->aa_walk_budget = 0; |
2262 | if (dump_file) |
2263 | { |
2264 | if (walked < 0) |
2265 | fprintf (dump_file, " Ran out of AA walking budget.\n"); |
2266 | else |
2267 | fprintf (dump_file, " Set in same BB as used.\n"); |
2268 | } |
2269 | BITMAP_FREE (info.bb_set)((void) (bitmap_obstack_free ((bitmap) info.bb_set), (info.bb_set ) = (bitmap) nullptr)); |
2270 | return REG_BR_PROB_BASE10000; |
2271 | } |
2272 | |
2273 | bitmap_iterator bi; |
2274 | unsigned index; |
2275 | /* Lookup the most frequent update of the value and believe that |
2276 | it dominates all the other; precise analysis here is difficult. */ |
2277 | EXECUTE_IF_SET_IN_BITMAP (info.bb_set, 0, index, bi)for (bmp_iter_set_init (&(bi), (info.bb_set), (0), &( index)); bmp_iter_set (&(bi), &(index)); bmp_iter_next (&(bi), &(index))) |
2278 | max = max.max (BASIC_BLOCK_FOR_FN (cfun, index)((*(((cfun + 0))->cfg->x_basic_block_info))[(index)])->count); |
2279 | if (dump_file) |
2280 | { |
2281 | fprintf (dump_file, " Set with count "); |
2282 | max.dump (dump_file); |
2283 | fprintf (dump_file, " and used with count "); |
2284 | bb->count.dump (dump_file); |
2285 | fprintf (dump_file, " freq %f\n", |
2286 | max.to_sreal_scale (bb->count).to_double ()); |
2287 | } |
2288 | |
2289 | BITMAP_FREE (info.bb_set)((void) (bitmap_obstack_free ((bitmap) info.bb_set), (info.bb_set ) = (bitmap) nullptr)); |
2290 | if (max < bb->count) |
2291 | return MAX ((max.to_sreal_scale (bb->count)(((max.to_sreal_scale (bb->count) * 10000).to_int ()) > (1) ? ((max.to_sreal_scale (bb->count) * 10000).to_int () ) : (1)) |
2292 | * REG_BR_PROB_BASE).to_int (), 1)(((max.to_sreal_scale (bb->count) * 10000).to_int ()) > (1) ? ((max.to_sreal_scale (bb->count) * 10000).to_int () ) : (1)); |
2293 | return REG_BR_PROB_BASE10000; |
2294 | } |
2295 | } |
2296 | |
2297 | /* Find whether a basic block BB is the final block of a (half) diamond CFG |
2298 | sub-graph and if the predicate the condition depends on is known. If so, |
2299 | return true and store the pointer the predicate in *P. */ |
2300 | |
2301 | static bool |
2302 | phi_result_unknown_predicate (ipa_func_body_info *fbi, |
2303 | ipa_fn_summary *summary, |
2304 | class ipa_node_params *params_summary, |
2305 | basic_block bb, |
2306 | ipa_predicate *p, |
2307 | vec<ipa_predicate> nonconstant_names) |
2308 | { |
2309 | edge e; |
2310 | edge_iterator ei; |
2311 | basic_block first_bb = NULLnullptr; |
2312 | gimple *stmt; |
2313 | |
2314 | if (single_pred_p (bb)) |
2315 | { |
2316 | *p = false; |
2317 | return true; |
2318 | } |
2319 | |
2320 | FOR_EACH_EDGE (e, ei, bb->preds)for ((ei) = ei_start_1 (&((bb->preds))); ei_cond ((ei) , &(e)); ei_next (&(ei))) |
2321 | { |
2322 | if (single_succ_p (e->src)) |
2323 | { |
2324 | if (!single_pred_p (e->src)) |
2325 | return false; |
2326 | if (!first_bb) |
2327 | first_bb = single_pred (e->src); |
2328 | else if (single_pred (e->src) != first_bb) |
2329 | return false; |
2330 | } |
2331 | else |
2332 | { |
2333 | if (!first_bb) |
2334 | first_bb = e->src; |
2335 | else if (e->src != first_bb) |
2336 | return false; |
2337 | } |
2338 | } |
2339 | |
2340 | if (!first_bb) |
2341 | return false; |
2342 | |
2343 | stmt = last_stmt (first_bb); |
2344 | if (!stmt |
2345 | || gimple_code (stmt) != GIMPLE_COND |
2346 | || !is_gimple_ip_invariant (gimple_cond_rhs (stmt))) |
2347 | return false; |
2348 | |
2349 | *p = will_be_nonconstant_expr_predicate (fbi, summary, params_summary, |
2350 | gimple_cond_lhs (stmt), |
2351 | nonconstant_names); |
2352 | if (*p == true) |
2353 | return false; |
2354 | else |
2355 | return true; |
2356 | } |
2357 | |
2358 | /* Given a PHI statement in a function described by inline properties SUMMARY |
2359 | and *P being the predicate describing whether the selected PHI argument is |
2360 | known, store a predicate for the result of the PHI statement into |
2361 | NONCONSTANT_NAMES, if possible. */ |
2362 | |
2363 | static void |
2364 | predicate_for_phi_result (class ipa_fn_summary *summary, gphi *phi, |
2365 | ipa_predicate *p, |
2366 | vec<ipa_predicate> nonconstant_names) |
2367 | { |
2368 | unsigned i; |
2369 | |
2370 | for (i = 0; i < gimple_phi_num_args (phi); i++) |
2371 | { |
2372 | tree arg = gimple_phi_arg (phi, i)->def; |
2373 | if (!is_gimple_min_invariant (arg)) |
2374 | { |
2375 | gcc_assert (TREE_CODE (arg) == SSA_NAME)((void)(!(((enum tree_code) (arg)->base.code) == SSA_NAME) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2375, __FUNCTION__), 0 : 0)); |
2376 | *p = p->or_with (summary->conds, |
2377 | nonconstant_names[SSA_NAME_VERSION (arg)(tree_check ((arg), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2377, __FUNCTION__, (SSA_NAME)))->base.u.version]); |
2378 | if (*p == true) |
2379 | return; |
2380 | } |
2381 | } |
2382 | |
2383 | if (dump_file && (dump_flags & TDF_DETAILS)) |
2384 | { |
2385 | fprintf (dump_file, "\t\tphi predicate: "); |
2386 | p->dump (dump_file, summary->conds); |
2387 | } |
2388 | nonconstant_names[SSA_NAME_VERSION (gimple_phi_result (phi))(tree_check ((gimple_phi_result (phi)), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2388, __FUNCTION__, (SSA_NAME)))->base.u.version] = *p; |
2389 | } |
2390 | |
2391 | /* For a typical usage of __builtin_expect (a<b, 1), we |
2392 | may introduce an extra relation stmt: |
2393 | With the builtin, we have |
2394 | t1 = a <= b; |
2395 | t2 = (long int) t1; |
2396 | t3 = __builtin_expect (t2, 1); |
2397 | if (t3 != 0) |
2398 | goto ... |
2399 | Without the builtin, we have |
2400 | if (a<=b) |
2401 | goto... |
2402 | This affects the size/time estimation and may have |
2403 | an impact on the earlier inlining. |
2404 | Here find this pattern and fix it up later. */ |
2405 | |
2406 | static gimple * |
2407 | find_foldable_builtin_expect (basic_block bb) |
2408 | { |
2409 | gimple_stmt_iterator bsi; |
2410 | |
2411 | for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi)) |
2412 | { |
2413 | gimple *stmt = gsi_stmt (bsi); |
2414 | if (gimple_call_builtin_p (stmt, BUILT_IN_EXPECT) |
2415 | || gimple_call_builtin_p (stmt, BUILT_IN_EXPECT_WITH_PROBABILITY) |
2416 | || gimple_call_internal_p (stmt, IFN_BUILTIN_EXPECT)) |
2417 | { |
2418 | tree var = gimple_call_lhs (stmt); |
2419 | tree arg = gimple_call_arg (stmt, 0); |
2420 | use_operand_p use_p; |
2421 | gimple *use_stmt; |
2422 | bool match = false; |
2423 | bool done = false; |
2424 | |
2425 | if (!var || !arg) |
2426 | continue; |
2427 | gcc_assert (TREE_CODE (var) == SSA_NAME)((void)(!(((enum tree_code) (var)->base.code) == SSA_NAME) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2427, __FUNCTION__), 0 : 0)); |
2428 | |
2429 | while (TREE_CODE (arg)((enum tree_code) (arg)->base.code) == SSA_NAME) |
2430 | { |
2431 | gimple *stmt_tmp = SSA_NAME_DEF_STMT (arg)(tree_check ((arg), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2431, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt; |
2432 | if (!is_gimple_assign (stmt_tmp)) |
2433 | break; |
2434 | switch (gimple_assign_rhs_code (stmt_tmp)) |
2435 | { |
2436 | case LT_EXPR: |
2437 | case LE_EXPR: |
2438 | case GT_EXPR: |
2439 | case GE_EXPR: |
2440 | case EQ_EXPR: |
2441 | case NE_EXPR: |
2442 | match = true; |
2443 | done = true; |
2444 | break; |
2445 | CASE_CONVERTcase NOP_EXPR: case CONVERT_EXPR: |
2446 | break; |
2447 | default: |
2448 | done = true; |
2449 | break; |
2450 | } |
2451 | if (done) |
2452 | break; |
2453 | arg = gimple_assign_rhs1 (stmt_tmp); |
2454 | } |
2455 | |
2456 | if (match && single_imm_use (var, &use_p, &use_stmt) |
2457 | && gimple_code (use_stmt) == GIMPLE_COND) |
2458 | return use_stmt; |
2459 | } |
2460 | } |
2461 | return NULLnullptr; |
2462 | } |
2463 | |
2464 | /* Return true when the basic blocks contains only clobbers followed by RESX. |
2465 | Such BBs are kept around to make removal of dead stores possible with |
2466 | presence of EH and will be optimized out by optimize_clobbers later in the |
2467 | game. |
2468 | |
2469 | NEED_EH is used to recurse in case the clobber has non-EH predecessors |
2470 | that can be clobber only, too.. When it is false, the RESX is not necessary |
2471 | on the end of basic block. */ |
2472 | |
2473 | static bool |
2474 | clobber_only_eh_bb_p (basic_block bb, bool need_eh = true) |
2475 | { |
2476 | gimple_stmt_iterator gsi = gsi_last_bb (bb); |
2477 | edge_iterator ei; |
2478 | edge e; |
2479 | |
2480 | if (need_eh) |
2481 | { |
2482 | if (gsi_end_p (gsi)) |
2483 | return false; |
2484 | if (gimple_code (gsi_stmt (gsi)) != GIMPLE_RESX) |
2485 | return false; |
2486 | gsi_prev (&gsi); |
2487 | } |
2488 | else if (!single_succ_p (bb)) |
2489 | return false; |
2490 | |
2491 | for (; !gsi_end_p (gsi); gsi_prev (&gsi)) |
2492 | { |
2493 | gimple *stmt = gsi_stmt (gsi); |
2494 | if (is_gimple_debug (stmt)) |
2495 | continue; |
2496 | if (gimple_clobber_p (stmt)) |
2497 | continue; |
2498 | if (gimple_code (stmt) == GIMPLE_LABEL) |
2499 | break; |
2500 | return false; |
2501 | } |
2502 | |
2503 | /* See if all predecessors are either throws or clobber only BBs. */ |
2504 | FOR_EACH_EDGE (e, ei, bb->preds)for ((ei) = ei_start_1 (&((bb->preds))); ei_cond ((ei) , &(e)); ei_next (&(ei))) |
2505 | if (!(e->flags & EDGE_EH) |
2506 | && !clobber_only_eh_bb_p (e->src, false)) |
2507 | return false; |
2508 | |
2509 | return true; |
2510 | } |
2511 | |
2512 | /* Return true if STMT compute a floating point expression that may be affected |
2513 | by -ffast-math and similar flags. */ |
2514 | |
2515 | static bool |
2516 | fp_expression_p (gimple *stmt) |
2517 | { |
2518 | ssa_op_iter i; |
2519 | tree op; |
2520 | |
2521 | FOR_EACH_SSA_TREE_OPERAND (op, stmt, i, SSA_OP_DEF|SSA_OP_USE)for (op = op_iter_init_tree (&(i), stmt, 0x02|0x01); !op_iter_done (&(i)); (void) (op = op_iter_next_tree (&(i)))) |
2522 | if (FLOAT_TYPE_P (TREE_TYPE (op))((((enum tree_code) (((contains_struct_check ((op), (TS_TYPED ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2522, __FUNCTION__))->typed.type))->base.code) == REAL_TYPE ) || ((((enum tree_code) (((contains_struct_check ((op), (TS_TYPED ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2522, __FUNCTION__))->typed.type))->base.code) == COMPLEX_TYPE || (((enum tree_code) (((contains_struct_check ((op), (TS_TYPED ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2522, __FUNCTION__))->typed.type))->base.code) == VECTOR_TYPE )) && (((enum tree_code) (((contains_struct_check ((( (contains_struct_check ((op), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2522, __FUNCTION__))->typed.type)), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2522, __FUNCTION__))->typed.type))->base.code) == REAL_TYPE )))) |
2523 | return true; |
2524 | return false; |
2525 | } |
2526 | |
2527 | /* Return true if T references memory location that is local |
2528 | for the function (that means, dead after return) or read-only. */ |
2529 | |
2530 | bool |
2531 | refs_local_or_readonly_memory_p (tree t) |
2532 | { |
2533 | /* Non-escaping memory is fine. */ |
2534 | t = get_base_address (t); |
2535 | if ((TREE_CODE (t)((enum tree_code) (t)->base.code) == MEM_REF |
2536 | || TREE_CODE (t)((enum tree_code) (t)->base.code) == TARGET_MEM_REF)) |
2537 | return points_to_local_or_readonly_memory_p (TREE_OPERAND (t, 0)(*((const_cast<tree*> (tree_operand_check ((t), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2537, __FUNCTION__)))))); |
2538 | |
2539 | /* Automatic variables are fine. */ |
2540 | if (DECL_P (t)(tree_code_type_tmpl <0>::tree_code_type[(int) (((enum tree_code ) (t)->base.code))] == tcc_declaration) |
2541 | && auto_var_in_fn_p (t, current_function_decl)) |
2542 | return true; |
2543 | |
2544 | /* Read-only variables are fine. */ |
2545 | if (DECL_P (t)(tree_code_type_tmpl <0>::tree_code_type[(int) (((enum tree_code ) (t)->base.code))] == tcc_declaration) && TREE_READONLY (t)((non_type_check ((t), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2545, __FUNCTION__))->base.readonly_flag)) |
2546 | return true; |
2547 | |
2548 | return false; |
2549 | } |
2550 | |
2551 | /* Return true if T is a pointer pointing to memory location that is local |
2552 | for the function (that means, dead after return) or read-only. */ |
2553 | |
2554 | bool |
2555 | points_to_local_or_readonly_memory_p (tree t) |
2556 | { |
2557 | /* See if memory location is clearly invalid. */ |
2558 | if (integer_zerop (t)) |
2559 | return flag_delete_null_pointer_checksglobal_options.x_flag_delete_null_pointer_checks; |
2560 | if (TREE_CODE (t)((enum tree_code) (t)->base.code) == SSA_NAME) |
2561 | { |
2562 | /* For IPA passes we can consinder accesses to return slot local |
2563 | even if it is not local in the sense that memory is dead by |
2564 | the end of founction. |
2565 | The outer function will see a store in the call assignment |
2566 | and thus this will do right thing for all uses of this |
2567 | function in the current IPA passes (modref, pure/const discovery |
2568 | and inlining heuristics). */ |
2569 | if (DECL_RESULT (current_function_decl)((tree_check ((current_function_decl), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2569, __FUNCTION__, (FUNCTION_DECL)))->decl_non_common.result ) |
2570 | && DECL_BY_REFERENCE (DECL_RESULT (current_function_decl))((tree_check3 ((((tree_check ((current_function_decl), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2570, __FUNCTION__, (FUNCTION_DECL)))->decl_non_common.result )), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2570, __FUNCTION__, (VAR_DECL), (PARM_DECL), (RESULT_DECL)) )->decl_common.decl_by_reference_flag) |
2571 | && t == ssa_default_def (cfun(cfun + 0), DECL_RESULT (current_function_decl)((tree_check ((current_function_decl), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2571, __FUNCTION__, (FUNCTION_DECL)))->decl_non_common.result ))) |
2572 | return true; |
2573 | return !ptr_deref_may_alias_global_p (t, false); |
2574 | } |
2575 | if (TREE_CODE (t)((enum tree_code) (t)->base.code) == ADDR_EXPR) |
2576 | return refs_local_or_readonly_memory_p (TREE_OPERAND (t, 0)(*((const_cast<tree*> (tree_operand_check ((t), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2576, __FUNCTION__)))))); |
2577 | return false; |
2578 | } |
2579 | |
2580 | |
2581 | /* Analyze function body for NODE. |
2582 | EARLY indicates run from early optimization pipeline. */ |
2583 | |
2584 | static void |
2585 | analyze_function_body (struct cgraph_node *node, bool early) |
2586 | { |
2587 | sreal time = opt_for_fn (node->decl, param_uninlined_function_time)(opts_for_fn (node->decl)->x_param_uninlined_function_time ); |
2588 | /* Estimate static overhead for function prologue/epilogue and alignment. */ |
2589 | int size = opt_for_fn (node->decl, param_uninlined_function_insns)(opts_for_fn (node->decl)->x_param_uninlined_function_insns ); |
2590 | /* Benefits are scaled by probability of elimination that is in range |
2591 | <0,2>. */ |
2592 | basic_block bb; |
2593 | struct function *my_function = DECL_STRUCT_FUNCTION (node->decl)((tree_check ((node->decl), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2593, __FUNCTION__, (FUNCTION_DECL)))->function_decl.f); |
2594 | sreal freq; |
2595 | class ipa_fn_summary *info = ipa_fn_summaries->get_create (node); |
2596 | ipa_node_params *params_summary |
2597 | = early ? NULLnullptr : ipa_node_params_sum->get (node); |
2598 | ipa_predicate bb_predicate; |
2599 | struct ipa_func_body_info fbi; |
2600 | vec<ipa_predicate> nonconstant_names = vNULL; |
2601 | int nblocks, n; |
2602 | int *order; |
2603 | gimple *fix_builtin_expect_stmt; |
2604 | |
2605 | gcc_assert (my_function && my_function->cfg)((void)(!(my_function && my_function->cfg) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2605, __FUNCTION__), 0 : 0)); |
2606 | gcc_assert (cfun == my_function)((void)(!((cfun + 0) == my_function) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2606, __FUNCTION__), 0 : 0)); |
2607 | |
2608 | memset(&fbi, 0, sizeof(fbi)); |
2609 | vec_free (info->conds); |
2610 | info->conds = NULLnullptr; |
2611 | info->size_time_table.release (); |
2612 | info->call_size_time_table.release (); |
2613 | |
2614 | /* When optimizing and analyzing for IPA inliner, initialize loop optimizer |
2615 | so we can produce proper inline hints. |
2616 | |
2617 | When optimizing and analyzing for early inliner, initialize node params |
2618 | so we can produce correct BB predicates. */ |
2619 | |
2620 | if (opt_for_fn (node->decl, optimize)(opts_for_fn (node->decl)->x_optimize)) |
2621 | { |
2622 | calculate_dominance_info (CDI_DOMINATORS); |
2623 | calculate_dominance_info (CDI_POST_DOMINATORS); |
2624 | if (!early) |
2625 | loop_optimizer_init (LOOPS_NORMAL(LOOPS_HAVE_PREHEADERS | LOOPS_HAVE_SIMPLE_LATCHES | LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS ) | LOOPS_HAVE_RECORDED_EXITS); |
2626 | else |
2627 | { |
2628 | ipa_check_create_node_params (); |
2629 | ipa_initialize_node_params (node); |
2630 | } |
2631 | |
2632 | if (ipa_node_params_sum) |
2633 | { |
2634 | fbi.node = node; |
2635 | fbi.info = ipa_node_params_sum->get (node); |
2636 | fbi.bb_infos = vNULL; |
2637 | fbi.bb_infos.safe_grow_cleared (last_basic_block_for_fn (cfun)(((cfun + 0))->cfg->x_last_basic_block), true); |
2638 | fbi.param_count = count_formal_params (node->decl); |
2639 | fbi.aa_walk_budget = opt_for_fn (node->decl, param_ipa_max_aa_steps)(opts_for_fn (node->decl)->x_param_ipa_max_aa_steps); |
2640 | |
2641 | nonconstant_names.safe_grow_cleared |
2642 | (SSANAMES (my_function)(my_function)->gimple_df->ssa_names->length (), true); |
2643 | } |
2644 | } |
2645 | |
2646 | if (dump_file) |
2647 | fprintf (dump_file, "\nAnalyzing function body size: %s\n", |
2648 | node->dump_name ()); |
2649 | |
2650 | /* When we run into maximal number of entries, we assign everything to the |
2651 | constant truth case. Be sure to have it in list. */ |
2652 | bb_predicate = true; |
2653 | info->account_size_time (0, 0, bb_predicate, bb_predicate); |
2654 | |
2655 | bb_predicate = ipa_predicate::not_inlined (); |
2656 | info->account_size_time (opt_for_fn (node->decl,(opts_for_fn (node->decl)->x_param_uninlined_function_insns ) |
2657 | param_uninlined_function_insns)(opts_for_fn (node->decl)->x_param_uninlined_function_insns ) |
2658 | * ipa_fn_summary::size_scale, |
2659 | opt_for_fn (node->decl,(opts_for_fn (node->decl)->x_param_uninlined_function_time ) |
2660 | param_uninlined_function_time)(opts_for_fn (node->decl)->x_param_uninlined_function_time ), |
2661 | bb_predicate, |
2662 | bb_predicate); |
2663 | |
2664 | /* Only look for target information for inlinable functions. */ |
2665 | bool scan_for_target_info = |
2666 | info->inlinable |
2667 | && targetm.target_option.need_ipa_fn_target_info (node->decl, |
2668 | info->target_info); |
2669 | |
2670 | if (fbi.info) |
2671 | compute_bb_predicates (&fbi, node, info, params_summary); |
2672 | const profile_count entry_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)(((cfun + 0))->cfg->x_entry_block_ptr)->count; |
2673 | order = XNEWVEC (int, n_basic_blocks_for_fn (cfun))((int *) xmalloc (sizeof (int) * ((((cfun + 0))->cfg->x_n_basic_blocks )))); |
2674 | nblocks = pre_and_rev_post_order_compute (NULLnullptr, order, false); |
2675 | for (n = 0; n < nblocks; n++) |
2676 | { |
2677 | bb = BASIC_BLOCK_FOR_FN (cfun, order[n])((*(((cfun + 0))->cfg->x_basic_block_info))[(order[n])] ); |
2678 | freq = bb->count.to_sreal_scale (entry_count); |
2679 | if (clobber_only_eh_bb_p (bb)) |
2680 | { |
2681 | if (dump_file && (dump_flags & TDF_DETAILS)) |
2682 | fprintf (dump_file, "\n Ignoring BB %i;" |
2683 | " it will be optimized away by cleanup_clobbers\n", |
2684 | bb->index); |
2685 | continue; |
2686 | } |
2687 | |
2688 | /* TODO: Obviously predicates can be propagated down across CFG. */ |
2689 | if (fbi.info) |
2690 | { |
2691 | if (bb->aux) |
2692 | bb_predicate = *(ipa_predicate *)bb->aux; |
2693 | else |
2694 | bb_predicate = false; |
2695 | } |
2696 | else |
2697 | bb_predicate = true; |
2698 | |
2699 | if (dump_file && (dump_flags & TDF_DETAILS)) |
2700 | { |
2701 | fprintf (dump_file, "\n BB %i predicate:", bb->index); |
2702 | bb_predicate.dump (dump_file, info->conds); |
2703 | } |
2704 | |
2705 | if (fbi.info && nonconstant_names.exists ()) |
2706 | { |
2707 | ipa_predicate phi_predicate; |
2708 | bool first_phi = true; |
2709 | |
2710 | for (gphi_iterator bsi = gsi_start_phis (bb); !gsi_end_p (bsi); |
2711 | gsi_next (&bsi)) |
2712 | { |
2713 | if (first_phi |
2714 | && !phi_result_unknown_predicate (&fbi, info, |
2715 | params_summary, |
2716 | bb, |
2717 | &phi_predicate, |
2718 | nonconstant_names)) |
2719 | break; |
2720 | first_phi = false; |
2721 | if (dump_file && (dump_flags & TDF_DETAILS)) |
2722 | { |
2723 | fprintf (dump_file, " "); |
2724 | print_gimple_stmt (dump_file, gsi_stmt (bsi), 0); |
2725 | } |
2726 | predicate_for_phi_result (info, bsi.phi (), &phi_predicate, |
2727 | nonconstant_names); |
2728 | } |
2729 | } |
2730 | |
2731 | fix_builtin_expect_stmt = find_foldable_builtin_expect (bb); |
2732 | |
2733 | for (gimple_stmt_iterator bsi = gsi_start_nondebug_bb (bb); |
2734 | !gsi_end_p (bsi); gsi_next_nondebug (&bsi)) |
2735 | { |
2736 | gimple *stmt = gsi_stmt (bsi); |
2737 | int this_size = estimate_num_insns (stmt, &eni_size_weights); |
2738 | int this_time = estimate_num_insns (stmt, &eni_time_weights); |
2739 | int prob; |
2740 | ipa_predicate will_be_nonconstant; |
2741 | |
2742 | /* This relation stmt should be folded after we remove |
2743 | __builtin_expect call. Adjust the cost here. */ |
2744 | if (stmt == fix_builtin_expect_stmt) |
2745 | { |
2746 | this_size--; |
2747 | this_time--; |
2748 | } |
2749 | |
2750 | if (dump_file && (dump_flags & TDF_DETAILS)) |
2751 | { |
2752 | fprintf (dump_file, " "); |
2753 | print_gimple_stmt (dump_file, stmt, 0); |
2754 | fprintf (dump_file, "\t\tfreq:%3.2f size:%3i time:%3i\n", |
2755 | freq.to_double (), this_size, |
2756 | this_time); |
2757 | } |
2758 | |
2759 | if (is_gimple_call (stmt) |
2760 | && !gimple_call_internal_p (stmt)) |
2761 | { |
2762 | struct cgraph_edge *edge = node->get_edge (stmt); |
2763 | ipa_call_summary *es = ipa_call_summaries->get_create (edge); |
2764 | |
2765 | /* Special case: results of BUILT_IN_CONSTANT_P will be always |
2766 | resolved as constant. We however don't want to optimize |
2767 | out the cgraph edges. */ |
2768 | if (nonconstant_names.exists () |
2769 | && gimple_call_builtin_p (stmt, BUILT_IN_CONSTANT_P) |
2770 | && gimple_call_lhs (stmt) |
2771 | && TREE_CODE (gimple_call_lhs (stmt))((enum tree_code) (gimple_call_lhs (stmt))->base.code) == SSA_NAME) |
2772 | { |
2773 | ipa_predicate false_p = false; |
2774 | nonconstant_names[SSA_NAME_VERSION (gimple_call_lhs (stmt))(tree_check ((gimple_call_lhs (stmt)), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2774, __FUNCTION__, (SSA_NAME)))->base.u.version] |
2775 | = false_p; |
2776 | } |
2777 | if (ipa_node_params_sum) |
2778 | { |
2779 | int count = gimple_call_num_args (stmt); |
2780 | int i; |
2781 | |
2782 | if (count) |
2783 | es->param.safe_grow_cleared (count, true); |
2784 | for (i = 0; i < count; i++) |
2785 | { |
2786 | int prob = param_change_prob (&fbi, stmt, i); |
2787 | gcc_assert (prob >= 0 && prob <= REG_BR_PROB_BASE)((void)(!(prob >= 0 && prob <= 10000) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2787, __FUNCTION__), 0 : 0)); |
2788 | es->param[i].change_prob = prob; |
2789 | es->param[i].points_to_local_or_readonly_memory |
2790 | = points_to_local_or_readonly_memory_p |
2791 | (gimple_call_arg (stmt, i)); |
2792 | } |
2793 | } |
2794 | /* We cannot setup VLA parameters during inlining. */ |
2795 | for (unsigned int i = 0; i < gimple_call_num_args (stmt); ++i) |
2796 | if (TREE_CODE (gimple_call_arg (stmt, i))((enum tree_code) (gimple_call_arg (stmt, i))->base.code) == WITH_SIZE_EXPR) |
2797 | { |
2798 | edge->inline_failed = CIF_FUNCTION_NOT_INLINABLE; |
2799 | break; |
2800 | } |
2801 | es->call_stmt_size = this_size; |
2802 | es->call_stmt_time = this_time; |
2803 | es->loop_depth = bb_loop_depth (bb); |
2804 | edge_set_predicate (edge, &bb_predicate); |
2805 | if (edge->speculative) |
2806 | { |
2807 | cgraph_edge *indirect |
2808 | = edge->speculative_call_indirect_edge (); |
2809 | ipa_call_summary *es2 |
2810 | = ipa_call_summaries->get_create (indirect); |
2811 | ipa_call_summaries->duplicate (edge, indirect, |
2812 | es, es2); |
2813 | |
2814 | /* Edge is the first direct call. |
2815 | create and duplicate call summaries for multiple |
2816 | speculative call targets. */ |
2817 | for (cgraph_edge *direct |
2818 | = edge->next_speculative_call_target (); |
2819 | direct; |
2820 | direct = direct->next_speculative_call_target ()) |
2821 | { |
2822 | ipa_call_summary *es3 |
2823 | = ipa_call_summaries->get_create (direct); |
2824 | ipa_call_summaries->duplicate (edge, direct, |
2825 | es, es3); |
2826 | } |
2827 | } |
2828 | } |
2829 | |
2830 | /* TODO: When conditional jump or switch is known to be constant, but |
2831 | we did not translate it into the predicates, we really can account |
2832 | just maximum of the possible paths. */ |
2833 | if (fbi.info) |
2834 | will_be_nonconstant |
2835 | = will_be_nonconstant_predicate (&fbi, info, params_summary, |
2836 | stmt, nonconstant_names); |
2837 | else |
2838 | will_be_nonconstant = true; |
2839 | if (this_time || this_size) |
2840 | { |
2841 | sreal final_time = (sreal)this_time * freq; |
2842 | |
2843 | prob = eliminated_by_inlining_prob (&fbi, stmt); |
2844 | if (prob == 1 && dump_file && (dump_flags & TDF_DETAILS)) |
2845 | fprintf (dump_file, |
2846 | "\t\t50%% will be eliminated by inlining\n"); |
2847 | if (prob == 2 && dump_file && (dump_flags & TDF_DETAILS)) |
2848 | fprintf (dump_file, "\t\tWill be eliminated by inlining\n"); |
2849 | |
2850 | ipa_predicate p = bb_predicate & will_be_nonconstant; |
2851 | |
2852 | /* We can ignore statement when we proved it is never going |
2853 | to happen, but we cannot do that for call statements |
2854 | because edges are accounted specially. */ |
2855 | |
2856 | if (*(is_gimple_call (stmt) ? &bb_predicate : &p) != false) |
2857 | { |
2858 | time += final_time; |
2859 | size += this_size; |
2860 | } |
2861 | |
2862 | /* We account everything but the calls. Calls have their own |
2863 | size/time info attached to cgraph edges. This is necessary |
2864 | in order to make the cost disappear after inlining. */ |
2865 | if (!is_gimple_call (stmt)) |
2866 | { |
2867 | if (prob) |
2868 | { |
2869 | ipa_predicate ip |
2870 | = bb_predicate & ipa_predicate::not_inlined (); |
2871 | info->account_size_time (this_size * prob, |
2872 | (final_time * prob) / 2, ip, |
2873 | p); |
2874 | } |
2875 | if (prob != 2) |
2876 | info->account_size_time (this_size * (2 - prob), |
2877 | (final_time * (2 - prob) / 2), |
2878 | bb_predicate, |
2879 | p); |
2880 | } |
2881 | |
2882 | if (!info->fp_expressions && fp_expression_p (stmt)) |
2883 | { |
2884 | info->fp_expressions = true; |
2885 | if (dump_file) |
2886 | fprintf (dump_file, " fp_expression set\n"); |
2887 | } |
2888 | } |
2889 | |
2890 | /* For target specific information, we want to scan all statements |
2891 | rather than those statements with non-zero weights, to avoid |
2892 | missing to scan something interesting for target information, |
2893 | such as: internal function calls. */ |
2894 | if (scan_for_target_info) |
2895 | scan_for_target_info = |
2896 | targetm.target_option.update_ipa_fn_target_info |
2897 | (info->target_info, stmt); |
2898 | |
2899 | /* Account cost of address calculations in the statements. */ |
2900 | for (unsigned int i = 0; i < gimple_num_ops (stmt); i++) |
2901 | { |
2902 | for (tree op = gimple_op (stmt, i); |
2903 | op && handled_component_p (op); |
2904 | op = TREE_OPERAND (op, 0)(*((const_cast<tree*> (tree_operand_check ((op), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2904, __FUNCTION__)))))) |
2905 | if ((TREE_CODE (op)((enum tree_code) (op)->base.code) == ARRAY_REF |
2906 | || TREE_CODE (op)((enum tree_code) (op)->base.code) == ARRAY_RANGE_REF) |
2907 | && TREE_CODE (TREE_OPERAND (op, 1))((enum tree_code) ((*((const_cast<tree*> (tree_operand_check ((op), (1), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2907, __FUNCTION__))))))->base.code) == SSA_NAME) |
2908 | { |
2909 | ipa_predicate p = bb_predicate; |
2910 | if (fbi.info) |
2911 | p = p & will_be_nonconstant_expr_predicate |
2912 | (&fbi, info, params_summary, |
2913 | TREE_OPERAND (op, 1)(*((const_cast<tree*> (tree_operand_check ((op), (1), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 2913, __FUNCTION__))))), |
2914 | nonconstant_names); |
2915 | if (p != false) |
2916 | { |
2917 | time += freq; |
2918 | size += 1; |
2919 | if (dump_file) |
2920 | fprintf (dump_file, |
2921 | "\t\tAccounting address calculation.\n"); |
2922 | info->account_size_time (ipa_fn_summary::size_scale, |
2923 | freq, |
2924 | bb_predicate, |
2925 | p); |
2926 | } |
2927 | } |
2928 | } |
2929 | |
2930 | } |
2931 | } |
2932 | free (order); |
2933 | |
2934 | if (nonconstant_names.exists () && !early) |
2935 | { |
2936 | ipa_fn_summary *s = ipa_fn_summaries->get (node); |
2937 | unsigned max_loop_predicates = opt_for_fn (node->decl,(opts_for_fn (node->decl)->x_param_ipa_max_loop_predicates ) |
2938 | param_ipa_max_loop_predicates)(opts_for_fn (node->decl)->x_param_ipa_max_loop_predicates ); |
2939 | |
2940 | if (dump_file && (dump_flags & TDF_DETAILS)) |
2941 | flow_loops_dump (dump_file, NULLnullptr, 0); |
2942 | scev_initialize (); |
2943 | for (auto loop : loops_list (cfun(cfun + 0), 0)) |
2944 | { |
2945 | ipa_predicate loop_iterations = true; |
2946 | sreal header_freq; |
2947 | edge ex; |
2948 | unsigned int j; |
2949 | class tree_niter_desc niter_desc; |
2950 | if (!loop->header->aux) |
2951 | continue; |
2952 | |
2953 | profile_count phdr_count = loop_preheader_edge (loop)->count (); |
2954 | sreal phdr_freq = phdr_count.to_sreal_scale (entry_count); |
2955 | |
2956 | bb_predicate = *(ipa_predicate *)loop->header->aux; |
2957 | auto_vec<edge> exits = get_loop_exit_edges (loop); |
2958 | FOR_EACH_VEC_ELT (exits, j, ex)for (j = 0; (exits).iterate ((j), &(ex)); ++(j)) |
2959 | if (number_of_iterations_exit (loop, ex, &niter_desc, false) |
2960 | && !is_gimple_min_invariant (niter_desc.niter)) |
2961 | { |
2962 | ipa_predicate will_be_nonconstant |
2963 | = will_be_nonconstant_expr_predicate (&fbi, info, |
2964 | params_summary, |
2965 | niter_desc.niter, |
2966 | nonconstant_names); |
2967 | if (will_be_nonconstant != true) |
2968 | will_be_nonconstant = bb_predicate & will_be_nonconstant; |
2969 | if (will_be_nonconstant != true |
2970 | && will_be_nonconstant != false) |
2971 | loop_iterations &= will_be_nonconstant; |
2972 | } |
2973 | add_freqcounting_predicate (&s->loop_iterations, loop_iterations, |
2974 | phdr_freq, max_loop_predicates); |
2975 | } |
2976 | |
2977 | /* To avoid quadratic behavior we analyze stride predicates only |
2978 | with respect to the containing loop. Thus we simply iterate |
2979 | over all defs in the outermost loop body. */ |
2980 | for (class loop *loop = loops_for_fn (cfun(cfun + 0))->tree_root->inner; |
2981 | loop != NULLnullptr; loop = loop->next) |
2982 | { |
2983 | ipa_predicate loop_stride = true; |
2984 | basic_block *body = get_loop_body (loop); |
2985 | profile_count phdr_count = loop_preheader_edge (loop)->count (); |
2986 | sreal phdr_freq = phdr_count.to_sreal_scale (entry_count); |
2987 | for (unsigned i = 0; i < loop->num_nodes; i++) |
2988 | { |
2989 | gimple_stmt_iterator gsi; |
2990 | if (!body[i]->aux) |
2991 | continue; |
2992 | |
2993 | bb_predicate = *(ipa_predicate *)body[i]->aux; |
2994 | for (gsi = gsi_start_bb (body[i]); !gsi_end_p (gsi); |
2995 | gsi_next (&gsi)) |
2996 | { |
2997 | gimple *stmt = gsi_stmt (gsi); |
2998 | |
2999 | if (!is_gimple_assign (stmt)) |
3000 | continue; |
3001 | |
3002 | tree def = gimple_assign_lhs (stmt); |
3003 | if (TREE_CODE (def)((enum tree_code) (def)->base.code) != SSA_NAME) |
3004 | continue; |
3005 | |
3006 | affine_iv iv; |
3007 | if (!simple_iv (loop_containing_stmt (stmt), |
3008 | loop_containing_stmt (stmt), |
3009 | def, &iv, true) |
3010 | || is_gimple_min_invariant (iv.step)) |
3011 | continue; |
3012 | |
3013 | ipa_predicate will_be_nonconstant |
3014 | = will_be_nonconstant_expr_predicate (&fbi, info, |
3015 | params_summary, |
3016 | iv.step, |
3017 | nonconstant_names); |
3018 | if (will_be_nonconstant != true) |
3019 | will_be_nonconstant = bb_predicate & will_be_nonconstant; |
3020 | if (will_be_nonconstant != true |
3021 | && will_be_nonconstant != false) |
3022 | loop_stride = loop_stride & will_be_nonconstant; |
3023 | } |
3024 | } |
3025 | add_freqcounting_predicate (&s->loop_strides, loop_stride, |
3026 | phdr_freq, max_loop_predicates); |
3027 | free (body); |
3028 | } |
3029 | scev_finalize (); |
3030 | } |
3031 | FOR_ALL_BB_FN (bb, my_function)for (bb = ((my_function)->cfg->x_entry_block_ptr); bb; bb = bb->next_bb) |
3032 | { |
3033 | edge e; |
3034 | edge_iterator ei; |
3035 | |
3036 | if (bb->aux) |
3037 | edge_predicate_pool.remove ((ipa_predicate *)bb->aux); |
3038 | bb->aux = NULLnullptr; |
3039 | FOR_EACH_EDGE (e, ei, bb->succs)for ((ei) = ei_start_1 (&((bb->succs))); ei_cond ((ei) , &(e)); ei_next (&(ei))) |
3040 | { |
3041 | if (e->aux) |
3042 | edge_predicate_pool.remove ((ipa_predicate *)e->aux); |
3043 | e->aux = NULLnullptr; |
3044 | } |
3045 | } |
3046 | ipa_fn_summary *s = ipa_fn_summaries->get (node); |
3047 | ipa_size_summary *ss = ipa_size_summaries->get (node); |
3048 | s->time = time; |
3049 | ss->self_size = size; |
3050 | nonconstant_names.release (); |
3051 | ipa_release_body_info (&fbi); |
3052 | if (opt_for_fn (node->decl, optimize)(opts_for_fn (node->decl)->x_optimize)) |
3053 | { |
3054 | if (!early) |
3055 | loop_optimizer_finalize (); |
3056 | else if (!ipa_edge_args_sum) |
3057 | ipa_free_all_node_params (); |
3058 | free_dominance_info (CDI_DOMINATORS); |
3059 | free_dominance_info (CDI_POST_DOMINATORS); |
3060 | } |
3061 | if (dump_file) |
3062 | { |
3063 | fprintf (dump_file, "\n"); |
3064 | ipa_dump_fn_summary (dump_file, node); |
3065 | } |
3066 | } |
3067 | |
3068 | |
3069 | /* Compute function summary. |
3070 | EARLY is true when we compute parameters during early opts. */ |
3071 | |
3072 | void |
3073 | compute_fn_summary (struct cgraph_node *node, bool early) |
3074 | { |
3075 | HOST_WIDE_INTlong self_stack_size; |
3076 | struct cgraph_edge *e; |
3077 | |
3078 | gcc_assert (!node->inlined_to)((void)(!(!node->inlined_to) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3078, __FUNCTION__), 0 : 0)); |
3079 | |
3080 | if (!ipa_fn_summaries) |
3081 | ipa_fn_summary_alloc (); |
3082 | |
3083 | /* Create a new ipa_fn_summary. */ |
3084 | ((ipa_fn_summary_t *)ipa_fn_summaries)->remove_callees (node); |
3085 | ipa_fn_summaries->remove (node); |
3086 | class ipa_fn_summary *info = ipa_fn_summaries->get_create (node); |
3087 | class ipa_size_summary *size_info = ipa_size_summaries->get_create (node); |
3088 | |
3089 | /* Estimate the stack size for the function if we're optimizing. */ |
3090 | self_stack_size = optimizeglobal_options.x_optimize && !node->thunk |
3091 | ? estimated_stack_frame_size (node) : 0; |
3092 | size_info->estimated_self_stack_size = self_stack_size; |
3093 | info->estimated_stack_size = self_stack_size; |
3094 | |
3095 | if (node->thunk) |
3096 | { |
3097 | ipa_call_summary *es = ipa_call_summaries->get_create (node->callees); |
3098 | ipa_predicate t = true; |
3099 | |
3100 | node->can_change_signature = false; |
3101 | es->call_stmt_size = eni_size_weights.call_cost; |
3102 | es->call_stmt_time = eni_time_weights.call_cost; |
3103 | info->account_size_time (ipa_fn_summary::size_scale |
3104 | * opt_for_fn (node->decl,(opts_for_fn (node->decl)->x_param_uninlined_function_thunk_insns ) |
3105 | param_uninlined_function_thunk_insns)(opts_for_fn (node->decl)->x_param_uninlined_function_thunk_insns ), |
3106 | opt_for_fn (node->decl,(opts_for_fn (node->decl)->x_param_uninlined_function_thunk_time ) |
3107 | param_uninlined_function_thunk_time)(opts_for_fn (node->decl)->x_param_uninlined_function_thunk_time ), t, t); |
3108 | t = ipa_predicate::not_inlined (); |
3109 | info->account_size_time (2 * ipa_fn_summary::size_scale, 0, t, t); |
3110 | ipa_update_overall_fn_summary (node); |
3111 | size_info->self_size = size_info->size; |
3112 | if (stdarg_p (TREE_TYPE (node->decl)((contains_struct_check ((node->decl), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3112, __FUNCTION__))->typed.type))) |
3113 | { |
3114 | info->inlinable = false; |
3115 | node->callees->inline_failed = CIF_VARIADIC_THUNK; |
3116 | } |
3117 | else |
3118 | info->inlinable = true; |
3119 | } |
3120 | else |
3121 | { |
3122 | /* Even is_gimple_min_invariant rely on current_function_decl. */ |
3123 | push_cfun (DECL_STRUCT_FUNCTION (node->decl)((tree_check ((node->decl), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3123, __FUNCTION__, (FUNCTION_DECL)))->function_decl.f)); |
3124 | |
3125 | /* During IPA profile merging we may be called w/o virtual SSA form |
3126 | built. */ |
3127 | update_ssa (TODO_update_ssa_only_virtuals(1 << 14)); |
3128 | |
3129 | /* Can this function be inlined at all? */ |
3130 | if (!opt_for_fn (node->decl, optimize)(opts_for_fn (node->decl)->x_optimize) |
3131 | && !lookup_attribute ("always_inline", |
3132 | DECL_ATTRIBUTES (node->decl)((contains_struct_check ((node->decl), (TS_DECL_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3132, __FUNCTION__))->decl_common.attributes))) |
3133 | info->inlinable = false; |
3134 | else |
3135 | info->inlinable = tree_inlinable_function_p (node->decl); |
3136 | |
3137 | bool no_signature = false; |
3138 | /* Type attributes can use parameter indices to describe them. |
3139 | Special case fn spec since we can safely preserve them in |
3140 | modref summaries. */ |
3141 | for (tree list = TYPE_ATTRIBUTES (TREE_TYPE (node->decl))((tree_class_check ((((contains_struct_check ((node->decl) , (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3141, __FUNCTION__))->typed.type)), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3141, __FUNCTION__))->type_common.attributes); |
3142 | list && !no_signature; list = TREE_CHAIN (list)((contains_struct_check ((list), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3142, __FUNCTION__))->common.chain)) |
3143 | if (!ipa_param_adjustments::type_attribute_allowed_p |
3144 | (get_attribute_name (list))) |
3145 | { |
3146 | if (dump_file) |
3147 | { |
3148 | fprintf (dump_file, "No signature change:" |
3149 | " function type has unhandled attribute %s.\n", |
3150 | IDENTIFIER_POINTER (get_attribute_name (list))((const char *) (tree_check ((get_attribute_name (list)), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3150, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str )); |
3151 | } |
3152 | no_signature = true; |
3153 | } |
3154 | for (tree parm = DECL_ARGUMENTS (node->decl)((tree_check ((node->decl), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3154, __FUNCTION__, (FUNCTION_DECL)))->function_decl.arguments ); |
3155 | parm && !no_signature; parm = DECL_CHAIN (parm)(((contains_struct_check (((contains_struct_check ((parm), (TS_DECL_MINIMAL ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3155, __FUNCTION__))), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3155, __FUNCTION__))->common.chain))) |
3156 | if (variably_modified_type_p (TREE_TYPE (parm)((contains_struct_check ((parm), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3156, __FUNCTION__))->typed.type), node->decl)) |
3157 | { |
3158 | if (dump_file) |
3159 | { |
3160 | fprintf (dump_file, "No signature change:" |
3161 | " has parameter with variably modified type.\n"); |
3162 | } |
3163 | no_signature = true; |
3164 | } |
3165 | |
3166 | /* Likewise for #pragma omp declare simd functions or functions |
3167 | with simd attribute. */ |
3168 | if (no_signature |
3169 | || lookup_attribute ("omp declare simd", |
3170 | DECL_ATTRIBUTES (node->decl)((contains_struct_check ((node->decl), (TS_DECL_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3170, __FUNCTION__))->decl_common.attributes))) |
3171 | node->can_change_signature = false; |
3172 | else |
3173 | { |
3174 | /* Otherwise, inlinable functions always can change signature. */ |
3175 | if (info->inlinable) |
3176 | node->can_change_signature = true; |
3177 | else |
3178 | { |
3179 | /* Functions calling builtin_apply cannot change signature. */ |
3180 | for (e = node->callees; e; e = e->next_callee) |
3181 | { |
3182 | tree cdecl = e->callee->decl; |
3183 | if (fndecl_built_in_p (cdecl, BUILT_IN_APPLY_ARGS) |
3184 | || fndecl_built_in_p (cdecl, BUILT_IN_VA_START)) |
3185 | break; |
3186 | } |
3187 | node->can_change_signature = !e; |
3188 | } |
3189 | } |
3190 | analyze_function_body (node, early); |
3191 | pop_cfun (); |
3192 | } |
3193 | |
3194 | /* Inlining characteristics are maintained by the cgraph_mark_inline. */ |
3195 | size_info->size = size_info->self_size; |
3196 | info->estimated_stack_size = size_info->estimated_self_stack_size; |
3197 | |
3198 | /* Code above should compute exactly the same result as |
3199 | ipa_update_overall_fn_summary except for case when speculative |
3200 | edges are present since these are accounted to size but not |
3201 | self_size. Do not compare time since different order the roundoff |
3202 | errors result in slight changes. */ |
3203 | ipa_update_overall_fn_summary (node); |
3204 | if (flag_checkingglobal_options.x_flag_checking) |
3205 | { |
3206 | for (e = node->indirect_calls; e; e = e->next_callee) |
3207 | if (e->speculative) |
3208 | break; |
3209 | gcc_assert (e || size_info->size == size_info->self_size)((void)(!(e || size_info->size == size_info->self_size) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3209, __FUNCTION__), 0 : 0)); |
3210 | } |
3211 | } |
3212 | |
3213 | |
3214 | /* Compute parameters of functions used by inliner using |
3215 | current_function_decl. */ |
3216 | |
3217 | static unsigned int |
3218 | compute_fn_summary_for_current (void) |
3219 | { |
3220 | compute_fn_summary (cgraph_node::get (current_function_decl), true); |
3221 | return 0; |
3222 | } |
3223 | |
3224 | /* Estimate benefit devirtualizing indirect edge IE and return true if it can |
3225 | be devirtualized and inlined, provided m_known_vals, m_known_contexts and |
3226 | m_known_aggs in AVALS. Return false straight away if AVALS is NULL. */ |
3227 | |
3228 | static bool |
3229 | estimate_edge_devirt_benefit (struct cgraph_edge *ie, |
3230 | int *size, int *time, |
3231 | ipa_call_arg_values *avals) |
3232 | { |
3233 | tree target; |
3234 | struct cgraph_node *callee; |
3235 | class ipa_fn_summary *isummary; |
3236 | enum availability avail; |
3237 | bool speculative; |
3238 | |
3239 | if (!avals |
3240 | || (!avals->m_known_vals.length() && !avals->m_known_contexts.length ())) |
3241 | return false; |
3242 | if (!opt_for_fn (ie->caller->decl, flag_indirect_inlining)(opts_for_fn (ie->caller->decl)->x_flag_indirect_inlining )) |
3243 | return false; |
3244 | |
3245 | target = ipa_get_indirect_edge_target (ie, avals, &speculative); |
3246 | if (!target || speculative) |
3247 | return false; |
3248 | |
3249 | /* Account for difference in cost between indirect and direct calls. */ |
3250 | *size -= (eni_size_weights.indirect_call_cost - eni_size_weights.call_cost); |
3251 | *time -= (eni_time_weights.indirect_call_cost - eni_time_weights.call_cost); |
3252 | gcc_checking_assert (*time >= 0)((void)(!(*time >= 0) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3252, __FUNCTION__), 0 : 0)); |
3253 | gcc_checking_assert (*size >= 0)((void)(!(*size >= 0) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3253, __FUNCTION__), 0 : 0)); |
3254 | |
3255 | callee = cgraph_node::get (target); |
3256 | if (!callee || !callee->definition) |
3257 | return false; |
3258 | callee = callee->function_symbol (&avail); |
3259 | if (avail < AVAIL_AVAILABLE) |
3260 | return false; |
3261 | isummary = ipa_fn_summaries->get (callee); |
3262 | if (isummary == NULLnullptr) |
3263 | return false; |
3264 | |
3265 | return isummary->inlinable; |
3266 | } |
3267 | |
3268 | /* Increase SIZE, MIN_SIZE (if non-NULL) and TIME for size and time needed to |
3269 | handle edge E with probability PROB. Set HINTS accordingly if edge may be |
3270 | devirtualized. AVALS, if non-NULL, describes the context of the call site |
3271 | as far as values of parameters are concerened. */ |
3272 | |
3273 | static inline void |
3274 | estimate_edge_size_and_time (struct cgraph_edge *e, int *size, int *min_size, |
3275 | sreal *time, ipa_call_arg_values *avals, |
3276 | ipa_hints *hints) |
3277 | { |
3278 | class ipa_call_summary *es = ipa_call_summaries->get (e); |
3279 | int call_size = es->call_stmt_size; |
3280 | int call_time = es->call_stmt_time; |
3281 | int cur_size; |
3282 | |
3283 | if (!e->callee && hints && e->maybe_hot_p () |
3284 | && estimate_edge_devirt_benefit (e, &call_size, &call_time, avals)) |
3285 | *hints |= INLINE_HINT_indirect_call; |
3286 | cur_size = call_size * ipa_fn_summary::size_scale; |
3287 | *size += cur_size; |
3288 | if (min_size) |
3289 | *min_size += cur_size; |
3290 | if (time) |
3291 | *time += ((sreal)call_time) * e->sreal_frequency (); |
3292 | } |
3293 | |
3294 | |
3295 | /* Increase SIZE, MIN_SIZE and TIME for size and time needed to handle all |
3296 | calls in NODE. POSSIBLE_TRUTHS and AVALS describe the context of the call |
3297 | site. |
3298 | |
3299 | Helper for estimate_calls_size_and_time which does the same but |
3300 | (in most cases) faster. */ |
3301 | |
3302 | static void |
3303 | estimate_calls_size_and_time_1 (struct cgraph_node *node, int *size, |
3304 | int *min_size, sreal *time, |
3305 | ipa_hints *hints, |
3306 | clause_t possible_truths, |
3307 | ipa_call_arg_values *avals) |
3308 | { |
3309 | struct cgraph_edge *e; |
3310 | for (e = node->callees; e; e = e->next_callee) |
3311 | { |
3312 | if (!e->inline_failed) |
3313 | { |
3314 | gcc_checking_assert (!ipa_call_summaries->get (e))((void)(!(!ipa_call_summaries->get (e)) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3314, __FUNCTION__), 0 : 0)); |
3315 | estimate_calls_size_and_time_1 (e->callee, size, min_size, time, |
3316 | hints, possible_truths, avals); |
3317 | |
3318 | continue; |
3319 | } |
3320 | class ipa_call_summary *es = ipa_call_summaries->get (e); |
3321 | |
3322 | /* Do not care about zero sized builtins. */ |
3323 | if (!es->call_stmt_size) |
3324 | { |
3325 | gcc_checking_assert (!es->call_stmt_time)((void)(!(!es->call_stmt_time) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3325, __FUNCTION__), 0 : 0)); |
3326 | continue; |
3327 | } |
3328 | if (!es->predicate |
3329 | || es->predicate->evaluate (possible_truths)) |
3330 | { |
3331 | /* Predicates of calls shall not use NOT_CHANGED codes, |
3332 | so we do not need to compute probabilities. */ |
3333 | estimate_edge_size_and_time (e, size, |
3334 | es->predicate ? NULLnullptr : min_size, |
3335 | time, avals, hints); |
3336 | } |
3337 | } |
3338 | for (e = node->indirect_calls; e; e = e->next_callee) |
3339 | { |
3340 | class ipa_call_summary *es = ipa_call_summaries->get (e); |
3341 | if (!es->predicate |
3342 | || es->predicate->evaluate (possible_truths)) |
3343 | estimate_edge_size_and_time (e, size, |
3344 | es->predicate ? NULLnullptr : min_size, |
3345 | time, avals, hints); |
3346 | } |
3347 | } |
3348 | |
3349 | /* Populate sum->call_size_time_table for edges from NODE. */ |
3350 | |
3351 | static void |
3352 | summarize_calls_size_and_time (struct cgraph_node *node, |
3353 | ipa_fn_summary *sum) |
3354 | { |
3355 | struct cgraph_edge *e; |
3356 | for (e = node->callees; e; e = e->next_callee) |
3357 | { |
3358 | if (!e->inline_failed) |
3359 | { |
3360 | gcc_checking_assert (!ipa_call_summaries->get (e))((void)(!(!ipa_call_summaries->get (e)) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3360, __FUNCTION__), 0 : 0)); |
3361 | summarize_calls_size_and_time (e->callee, sum); |
3362 | continue; |
3363 | } |
3364 | int size = 0; |
3365 | sreal time = 0; |
3366 | |
3367 | estimate_edge_size_and_time (e, &size, NULLnullptr, &time, NULLnullptr, NULLnullptr); |
3368 | |
3369 | ipa_predicate pred = true; |
3370 | class ipa_call_summary *es = ipa_call_summaries->get (e); |
3371 | |
3372 | if (es->predicate) |
3373 | pred = *es->predicate; |
3374 | sum->account_size_time (size, time, pred, pred, true); |
3375 | } |
3376 | for (e = node->indirect_calls; e; e = e->next_callee) |
3377 | { |
3378 | int size = 0; |
3379 | sreal time = 0; |
3380 | |
3381 | estimate_edge_size_and_time (e, &size, NULLnullptr, &time, NULLnullptr, NULLnullptr); |
3382 | ipa_predicate pred = true; |
3383 | class ipa_call_summary *es = ipa_call_summaries->get (e); |
3384 | |
3385 | if (es->predicate) |
3386 | pred = *es->predicate; |
3387 | sum->account_size_time (size, time, pred, pred, true); |
3388 | } |
3389 | } |
3390 | |
3391 | /* Increase SIZE, MIN_SIZE and TIME for size and time needed to handle all |
3392 | calls in NODE. POSSIBLE_TRUTHS and AVALS (the latter if non-NULL) describe |
3393 | context of the call site. */ |
3394 | |
3395 | static void |
3396 | estimate_calls_size_and_time (struct cgraph_node *node, int *size, |
3397 | int *min_size, sreal *time, |
3398 | ipa_hints *hints, |
3399 | clause_t possible_truths, |
3400 | ipa_call_arg_values *avals) |
3401 | { |
3402 | class ipa_fn_summary *sum = ipa_fn_summaries->get (node); |
3403 | bool use_table = true; |
3404 | |
3405 | gcc_assert (node->callees || node->indirect_calls)((void)(!(node->callees || node->indirect_calls) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3405, __FUNCTION__), 0 : 0)); |
3406 | |
3407 | /* During early inlining we do not calculate info for very |
3408 | large functions and thus there is no need for producing |
3409 | summaries. */ |
3410 | if (!ipa_node_params_sum) |
3411 | use_table = false; |
3412 | /* Do not calculate summaries for simple wrappers; it is waste |
3413 | of memory. */ |
3414 | else if (node->callees && node->indirect_calls |
3415 | && node->callees->inline_failed && !node->callees->next_callee) |
3416 | use_table = false; |
3417 | /* If there is an indirect edge that may be optimized, we need |
3418 | to go the slow way. */ |
3419 | else if (avals && hints |
3420 | && (avals->m_known_vals.length () |
3421 | || avals->m_known_contexts.length () |
3422 | || avals->m_known_aggs.length ())) |
3423 | { |
3424 | ipa_node_params *params_summary = ipa_node_params_sum->get (node); |
3425 | unsigned int nargs = params_summary |
3426 | ? ipa_get_param_count (params_summary) : 0; |
3427 | |
3428 | for (unsigned int i = 0; i < nargs && use_table; i++) |
3429 | { |
3430 | if (ipa_is_param_used_by_indirect_call (params_summary, i) |
3431 | && (avals->safe_sval_at (i) |
3432 | || (ipa_argagg_value_list (avals).value_for_index_p (i)))) |
3433 | use_table = false; |
3434 | else if (ipa_is_param_used_by_polymorphic_call (params_summary, i) |
3435 | && (avals->m_known_contexts.length () > i |
3436 | && !avals->m_known_contexts[i].useless_p ())) |
3437 | use_table = false; |
3438 | } |
3439 | } |
3440 | |
3441 | /* Fast path is via the call size time table. */ |
3442 | if (use_table) |
3443 | { |
3444 | /* Build summary if it is absent. */ |
3445 | if (!sum->call_size_time_table.length ()) |
3446 | { |
3447 | ipa_predicate true_pred = true; |
3448 | sum->account_size_time (0, 0, true_pred, true_pred, true); |
3449 | summarize_calls_size_and_time (node, sum); |
3450 | } |
3451 | |
3452 | int old_size = *size; |
3453 | sreal old_time = time ? *time : 0; |
3454 | |
3455 | if (min_size) |
3456 | *min_size += sum->call_size_time_table[0].size; |
3457 | |
3458 | unsigned int i; |
3459 | size_time_entry *e; |
3460 | |
3461 | /* Walk the table and account sizes and times. */ |
3462 | for (i = 0; sum->call_size_time_table.iterate (i, &e); |
3463 | i++) |
3464 | if (e->exec_predicate.evaluate (possible_truths)) |
3465 | { |
3466 | *size += e->size; |
3467 | if (time) |
3468 | *time += e->time; |
3469 | } |
3470 | |
3471 | /* Be careful and see if both methods agree. */ |
3472 | if ((flag_checkingglobal_options.x_flag_checking || dump_file) |
3473 | /* Do not try to sanity check when we know we lost some |
3474 | precision. */ |
3475 | && sum->call_size_time_table.length () |
3476 | < ipa_fn_summary::max_size_time_table_size) |
3477 | { |
3478 | estimate_calls_size_and_time_1 (node, &old_size, NULLnullptr, &old_time, NULLnullptr, |
3479 | possible_truths, avals); |
3480 | gcc_assert (*size == old_size)((void)(!(*size == old_size) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3480, __FUNCTION__), 0 : 0)); |
3481 | if (time && (*time - old_time > 1 || *time - old_time < -1) |
3482 | && dump_file) |
3483 | fprintf (dump_file, "Time mismatch in call summary %f!=%f\n", |
3484 | old_time.to_double (), |
3485 | time->to_double ()); |
3486 | } |
3487 | } |
3488 | /* Slow path by walking all edges. */ |
3489 | else |
3490 | estimate_calls_size_and_time_1 (node, size, min_size, time, hints, |
3491 | possible_truths, avals); |
3492 | } |
3493 | |
3494 | /* Main constructor for ipa call context. Memory allocation of ARG_VALUES |
3495 | is owned by the caller. INLINE_PARAM_SUMMARY is also owned by the |
3496 | caller. */ |
3497 | |
3498 | ipa_call_context::ipa_call_context (cgraph_node *node, clause_t possible_truths, |
3499 | clause_t nonspec_possible_truths, |
3500 | vec<inline_param_summary> |
3501 | inline_param_summary, |
3502 | ipa_auto_call_arg_values *arg_values) |
3503 | : m_node (node), m_possible_truths (possible_truths), |
3504 | m_nonspec_possible_truths (nonspec_possible_truths), |
3505 | m_inline_param_summary (inline_param_summary), |
3506 | m_avals (arg_values) |
3507 | { |
3508 | } |
3509 | |
3510 | /* Set THIS to be a duplicate of CTX. Copy all relevant info. */ |
3511 | |
3512 | void |
3513 | ipa_cached_call_context::duplicate_from (const ipa_call_context &ctx) |
3514 | { |
3515 | m_node = ctx.m_node; |
3516 | m_possible_truths = ctx.m_possible_truths; |
3517 | m_nonspec_possible_truths = ctx.m_nonspec_possible_truths; |
3518 | ipa_node_params *params_summary = ipa_node_params_sum->get (m_node); |
3519 | unsigned int nargs = params_summary |
3520 | ? ipa_get_param_count (params_summary) : 0; |
3521 | |
3522 | m_inline_param_summary = vNULL; |
3523 | /* Copy the info only if there is at least one useful entry. */ |
3524 | if (ctx.m_inline_param_summary.exists ()) |
3525 | { |
3526 | unsigned int n = MIN (ctx.m_inline_param_summary.length (), nargs)((ctx.m_inline_param_summary.length ()) < (nargs) ? (ctx.m_inline_param_summary .length ()) : (nargs)); |
3527 | |
3528 | for (unsigned int i = 0; i < n; i++) |
3529 | if (ipa_is_param_used_by_ipa_predicates (params_summary, i) |
3530 | && !ctx.m_inline_param_summary[i].useless_p ()) |
3531 | { |
3532 | m_inline_param_summary |
3533 | = ctx.m_inline_param_summary.copy (); |
3534 | break; |
3535 | } |
3536 | } |
3537 | m_avals.m_known_vals = vNULL; |
3538 | if (ctx.m_avals.m_known_vals.exists ()) |
3539 | { |
3540 | unsigned int n = MIN (ctx.m_avals.m_known_vals.length (), nargs)((ctx.m_avals.m_known_vals.length ()) < (nargs) ? (ctx.m_avals .m_known_vals.length ()) : (nargs)); |
3541 | |
3542 | for (unsigned int i = 0; i < n; i++) |
3543 | if (ipa_is_param_used_by_indirect_call (params_summary, i) |
3544 | && ctx.m_avals.m_known_vals[i]) |
3545 | { |
3546 | m_avals.m_known_vals = ctx.m_avals.m_known_vals.copy (); |
3547 | break; |
3548 | } |
3549 | } |
3550 | |
3551 | m_avals.m_known_contexts = vNULL; |
3552 | if (ctx.m_avals.m_known_contexts.exists ()) |
3553 | { |
3554 | unsigned int n = MIN (ctx.m_avals.m_known_contexts.length (), nargs)((ctx.m_avals.m_known_contexts.length ()) < (nargs) ? (ctx .m_avals.m_known_contexts.length ()) : (nargs)); |
3555 | |
3556 | for (unsigned int i = 0; i < n; i++) |
3557 | if (ipa_is_param_used_by_polymorphic_call (params_summary, i) |
3558 | && !ctx.m_avals.m_known_contexts[i].useless_p ()) |
3559 | { |
3560 | m_avals.m_known_contexts = ctx.m_avals.m_known_contexts.copy (); |
3561 | break; |
3562 | } |
3563 | } |
3564 | |
3565 | m_avals.m_known_aggs = vNULL; |
3566 | if (ctx.m_avals.m_known_aggs.exists ()) |
3567 | { |
3568 | const ipa_argagg_value_list avl (&ctx.m_avals); |
3569 | for (unsigned int i = 0; i < nargs; i++) |
3570 | if (ipa_is_param_used_by_indirect_call (params_summary, i) |
3571 | && avl.value_for_index_p (i)) |
3572 | { |
3573 | m_avals.m_known_aggs = ctx.m_avals.m_known_aggs.copy (); |
3574 | break; |
3575 | } |
3576 | } |
3577 | |
3578 | m_avals.m_known_value_ranges = vNULL; |
3579 | } |
3580 | |
3581 | /* Release memory used by known_vals/contexts/aggs vectors. and |
3582 | inline_param_summary. */ |
3583 | |
3584 | void |
3585 | ipa_cached_call_context::release () |
3586 | { |
3587 | /* See if context is initialized at first place. */ |
3588 | if (!m_node) |
3589 | return; |
3590 | m_avals.m_known_aggs.release (); |
3591 | m_avals.m_known_vals.release (); |
3592 | m_avals.m_known_contexts.release (); |
3593 | m_inline_param_summary.release (); |
3594 | } |
3595 | |
3596 | /* Return true if CTX describes the same call context as THIS. */ |
3597 | |
3598 | bool |
3599 | ipa_call_context::equal_to (const ipa_call_context &ctx) |
3600 | { |
3601 | if (m_node != ctx.m_node |
3602 | || m_possible_truths != ctx.m_possible_truths |
3603 | || m_nonspec_possible_truths != ctx.m_nonspec_possible_truths) |
3604 | return false; |
3605 | |
3606 | ipa_node_params *params_summary = ipa_node_params_sum->get (m_node); |
3607 | unsigned int nargs = params_summary |
3608 | ? ipa_get_param_count (params_summary) : 0; |
3609 | |
3610 | if (m_inline_param_summary.exists () || ctx.m_inline_param_summary.exists ()) |
3611 | { |
3612 | for (unsigned int i = 0; i < nargs; i++) |
3613 | { |
3614 | if (!ipa_is_param_used_by_ipa_predicates (params_summary, i)) |
3615 | continue; |
3616 | if (i >= m_inline_param_summary.length () |
3617 | || m_inline_param_summary[i].useless_p ()) |
3618 | { |
3619 | if (i < ctx.m_inline_param_summary.length () |
3620 | && !ctx.m_inline_param_summary[i].useless_p ()) |
3621 | return false; |
3622 | continue; |
3623 | } |
3624 | if (i >= ctx.m_inline_param_summary.length () |
3625 | || ctx.m_inline_param_summary[i].useless_p ()) |
3626 | { |
3627 | if (i < m_inline_param_summary.length () |
3628 | && !m_inline_param_summary[i].useless_p ()) |
3629 | return false; |
3630 | continue; |
3631 | } |
3632 | if (!m_inline_param_summary[i].equal_to |
3633 | (ctx.m_inline_param_summary[i])) |
3634 | return false; |
3635 | } |
3636 | } |
3637 | if (m_avals.m_known_vals.exists () || ctx.m_avals.m_known_vals.exists ()) |
3638 | { |
3639 | for (unsigned int i = 0; i < nargs; i++) |
3640 | { |
3641 | if (!ipa_is_param_used_by_indirect_call (params_summary, i)) |
3642 | continue; |
3643 | if (i >= m_avals.m_known_vals.length () || !m_avals.m_known_vals[i]) |
3644 | { |
3645 | if (i < ctx.m_avals.m_known_vals.length () |
3646 | && ctx.m_avals.m_known_vals[i]) |
3647 | return false; |
3648 | continue; |
3649 | } |
3650 | if (i >= ctx.m_avals.m_known_vals.length () |
3651 | || !ctx.m_avals.m_known_vals[i]) |
3652 | { |
3653 | if (i < m_avals.m_known_vals.length () && m_avals.m_known_vals[i]) |
3654 | return false; |
3655 | continue; |
3656 | } |
3657 | if (m_avals.m_known_vals[i] != ctx.m_avals.m_known_vals[i]) |
3658 | return false; |
3659 | } |
3660 | } |
3661 | if (m_avals.m_known_contexts.exists () |
3662 | || ctx.m_avals.m_known_contexts.exists ()) |
3663 | { |
3664 | for (unsigned int i = 0; i < nargs; i++) |
3665 | { |
3666 | if (!ipa_is_param_used_by_polymorphic_call (params_summary, i)) |
3667 | continue; |
3668 | if (i >= m_avals.m_known_contexts.length () |
3669 | || m_avals.m_known_contexts[i].useless_p ()) |
3670 | { |
3671 | if (i < ctx.m_avals.m_known_contexts.length () |
3672 | && !ctx.m_avals.m_known_contexts[i].useless_p ()) |
3673 | return false; |
3674 | continue; |
3675 | } |
3676 | if (i >= ctx.m_avals.m_known_contexts.length () |
3677 | || ctx.m_avals.m_known_contexts[i].useless_p ()) |
3678 | { |
3679 | if (i < m_avals.m_known_contexts.length () |
3680 | && !m_avals.m_known_contexts[i].useless_p ()) |
3681 | return false; |
3682 | continue; |
3683 | } |
3684 | if (!m_avals.m_known_contexts[i].equal_to |
3685 | (ctx.m_avals.m_known_contexts[i])) |
3686 | return false; |
3687 | } |
3688 | } |
3689 | if (m_avals.m_known_aggs.exists () || ctx.m_avals.m_known_aggs.exists ()) |
3690 | { |
3691 | unsigned i = 0, j = 0; |
3692 | while (i < m_avals.m_known_aggs.length () |
3693 | || j < ctx.m_avals.m_known_aggs.length ()) |
3694 | { |
3695 | if (i >= m_avals.m_known_aggs.length ()) |
3696 | { |
3697 | int idx2 = ctx.m_avals.m_known_aggs[j].index; |
3698 | if (ipa_is_param_used_by_indirect_call (params_summary, idx2)) |
3699 | return false; |
3700 | j++; |
3701 | continue; |
3702 | } |
3703 | if (j >= ctx.m_avals.m_known_aggs.length ()) |
3704 | { |
3705 | int idx1 = m_avals.m_known_aggs[i].index; |
3706 | if (ipa_is_param_used_by_indirect_call (params_summary, idx1)) |
3707 | return false; |
3708 | i++; |
3709 | continue; |
3710 | } |
3711 | |
3712 | int idx1 = m_avals.m_known_aggs[i].index; |
3713 | int idx2 = ctx.m_avals.m_known_aggs[j].index; |
3714 | if (idx1 < idx2) |
3715 | { |
3716 | if (ipa_is_param_used_by_indirect_call (params_summary, idx1)) |
3717 | return false; |
3718 | i++; |
3719 | continue; |
3720 | } |
3721 | if (idx1 > idx2) |
3722 | { |
3723 | if (ipa_is_param_used_by_indirect_call (params_summary, idx2)) |
3724 | return false; |
3725 | j++; |
3726 | continue; |
3727 | } |
3728 | if (!ipa_is_param_used_by_indirect_call (params_summary, idx1)) |
3729 | { |
3730 | i++; |
3731 | j++; |
3732 | continue; |
3733 | } |
3734 | |
3735 | if ((m_avals.m_known_aggs[i].unit_offset |
3736 | != ctx.m_avals.m_known_aggs[j].unit_offset) |
3737 | || (m_avals.m_known_aggs[i].by_ref |
3738 | != ctx.m_avals.m_known_aggs[j].by_ref) |
3739 | || !operand_equal_p (m_avals.m_known_aggs[i].value, |
3740 | ctx.m_avals.m_known_aggs[j].value)) |
3741 | return false; |
3742 | i++; |
3743 | j++; |
3744 | } |
3745 | } |
3746 | return true; |
3747 | } |
3748 | |
3749 | /* Fill in the selected fields in ESTIMATES with value estimated for call in |
3750 | this context. Always compute size and min_size. Only compute time and |
3751 | nonspecialized_time if EST_TIMES is true. Only compute hints if EST_HINTS |
3752 | is true. */ |
3753 | |
3754 | void |
3755 | ipa_call_context::estimate_size_and_time (ipa_call_estimates *estimates, |
3756 | bool est_times, bool est_hints) |
3757 | { |
3758 | class ipa_fn_summary *info = ipa_fn_summaries->get (m_node); |
3759 | size_time_entry *e; |
3760 | int size = 0; |
3761 | sreal time = 0; |
3762 | int min_size = 0; |
3763 | ipa_hints hints = 0; |
3764 | sreal loops_with_known_iterations = 0; |
3765 | sreal loops_with_known_strides = 0; |
3766 | int i; |
3767 | |
3768 | if (dump_file && (dump_flags & TDF_DETAILS)) |
3769 | { |
3770 | bool found = false; |
3771 | fprintf (dump_file, " Estimating body: %s\n" |
3772 | " Known to be false: ", m_node->dump_name ()); |
3773 | |
3774 | for (i = ipa_predicate::not_inlined_condition; |
3775 | i < (ipa_predicate::first_dynamic_condition |
3776 | + (int) vec_safe_length (info->conds)); i++) |
3777 | if (!(m_possible_truths & (1 << i))) |
3778 | { |
3779 | if (found) |
3780 | fprintf (dump_file, ", "); |
3781 | found = true; |
3782 | dump_condition (dump_file, info->conds, i); |
3783 | } |
3784 | } |
3785 | |
3786 | if (m_node->callees || m_node->indirect_calls) |
3787 | estimate_calls_size_and_time (m_node, &size, &min_size, |
3788 | est_times ? &time : NULLnullptr, |
3789 | est_hints ? &hints : NULLnullptr, m_possible_truths, |
3790 | &m_avals); |
3791 | |
3792 | sreal nonspecialized_time = time; |
3793 | |
3794 | min_size += info->size_time_table[0].size; |
3795 | for (i = 0; info->size_time_table.iterate (i, &e); i++) |
3796 | { |
3797 | bool exec = e->exec_predicate.evaluate (m_nonspec_possible_truths); |
3798 | |
3799 | /* Because predicates are conservative, it can happen that nonconst is 1 |
3800 | but exec is 0. */ |
3801 | if (exec) |
3802 | { |
3803 | bool nonconst = e->nonconst_predicate.evaluate (m_possible_truths); |
3804 | |
3805 | gcc_checking_assert (e->time >= 0)((void)(!(e->time >= 0) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3805, __FUNCTION__), 0 : 0)); |
3806 | gcc_checking_assert (time >= 0)((void)(!(time >= 0) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3806, __FUNCTION__), 0 : 0)); |
3807 | |
3808 | /* We compute specialized size only because size of nonspecialized |
3809 | copy is context independent. |
3810 | |
3811 | The difference between nonspecialized execution and specialized is |
3812 | that nonspecialized is not going to have optimized out computations |
3813 | known to be constant in a specialized setting. */ |
3814 | if (nonconst) |
3815 | size += e->size; |
3816 | if (!est_times) |
3817 | continue; |
3818 | nonspecialized_time += e->time; |
3819 | if (!nonconst) |
3820 | ; |
3821 | else if (!m_inline_param_summary.exists ()) |
3822 | { |
3823 | if (nonconst) |
3824 | time += e->time; |
3825 | } |
3826 | else |
3827 | { |
3828 | int prob = e->nonconst_predicate.probability |
3829 | (info->conds, m_possible_truths, |
3830 | m_inline_param_summary); |
3831 | gcc_checking_assert (prob >= 0)((void)(!(prob >= 0) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3831, __FUNCTION__), 0 : 0)); |
3832 | gcc_checking_assert (prob <= REG_BR_PROB_BASE)((void)(!(prob <= 10000) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3832, __FUNCTION__), 0 : 0)); |
3833 | if (prob == REG_BR_PROB_BASE10000) |
3834 | time += e->time; |
3835 | else |
3836 | time += e->time * prob / REG_BR_PROB_BASE10000; |
3837 | } |
3838 | gcc_checking_assert (time >= 0)((void)(!(time >= 0) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3838, __FUNCTION__), 0 : 0)); |
3839 | } |
3840 | } |
3841 | gcc_checking_assert (info->size_time_table[0].exec_predicate == true)((void)(!(info->size_time_table[0].exec_predicate == true) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3841, __FUNCTION__), 0 : 0)); |
3842 | gcc_checking_assert (info->size_time_table[0].nonconst_predicate == true)((void)(!(info->size_time_table[0].nonconst_predicate == true ) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3842, __FUNCTION__), 0 : 0)); |
3843 | gcc_checking_assert (min_size >= 0)((void)(!(min_size >= 0) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3843, __FUNCTION__), 0 : 0)); |
3844 | gcc_checking_assert (size >= 0)((void)(!(size >= 0) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3844, __FUNCTION__), 0 : 0)); |
3845 | gcc_checking_assert (time >= 0)((void)(!(time >= 0) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3845, __FUNCTION__), 0 : 0)); |
3846 | /* nonspecialized_time should be always bigger than specialized time. |
3847 | Roundoff issues however may get into the way. */ |
3848 | gcc_checking_assert ((nonspecialized_time - time * 99 / 100) >= -1)((void)(!((nonspecialized_time - time * 99 / 100) >= -1) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3848, __FUNCTION__), 0 : 0)); |
3849 | |
3850 | /* Roundoff issues may make specialized time bigger than nonspecialized |
3851 | time. We do not really want that to happen because some heuristics |
3852 | may get confused by seeing negative speedups. */ |
3853 | if (time > nonspecialized_time) |
3854 | time = nonspecialized_time; |
3855 | |
3856 | if (est_hints) |
3857 | { |
3858 | if (info->scc_no) |
3859 | hints |= INLINE_HINT_in_scc; |
3860 | if (DECL_DECLARED_INLINE_P (m_node->decl)((tree_check ((m_node->decl), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3860, __FUNCTION__, (FUNCTION_DECL)))->function_decl.declared_inline_flag )) |
3861 | hints |= INLINE_HINT_declared_inline; |
3862 | if (info->builtin_constant_p_parms.length () |
3863 | && DECL_DECLARED_INLINE_P (m_node->decl)((tree_check ((m_node->decl), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 3863, __FUNCTION__, (FUNCTION_DECL)))->function_decl.declared_inline_flag )) |
3864 | hints |= INLINE_HINT_builtin_constant_p; |
3865 | |
3866 | ipa_freqcounting_predicate *fcp; |
3867 | for (i = 0; vec_safe_iterate (info->loop_iterations, i, &fcp); i++) |
3868 | if (!fcp->predicate->evaluate (m_possible_truths)) |
3869 | { |
3870 | hints |= INLINE_HINT_loop_iterations; |
3871 | loops_with_known_iterations += fcp->freq; |
3872 | } |
3873 | estimates->loops_with_known_iterations = loops_with_known_iterations; |
3874 | |
3875 | for (i = 0; vec_safe_iterate (info->loop_strides, i, &fcp); i++) |
3876 | if (!fcp->predicate->evaluate (m_possible_truths)) |
3877 | { |
3878 | hints |= INLINE_HINT_loop_stride; |
3879 | loops_with_known_strides += fcp->freq; |
3880 | } |
3881 | estimates->loops_with_known_strides = loops_with_known_strides; |
3882 | } |
3883 | |
3884 | size = RDIV (size, ipa_fn_summary::size_scale)(((size) + (ipa_fn_summary::size_scale) / 2) / (ipa_fn_summary ::size_scale)); |
3885 | min_size = RDIV (min_size, ipa_fn_summary::size_scale)(((min_size) + (ipa_fn_summary::size_scale) / 2) / (ipa_fn_summary ::size_scale)); |
3886 | |
3887 | if (dump_file && (dump_flags & TDF_DETAILS)) |
3888 | { |
3889 | fprintf (dump_file, "\n size:%i", (int) size); |
3890 | if (est_times) |
3891 | fprintf (dump_file, " time:%f nonspec time:%f", |
3892 | time.to_double (), nonspecialized_time.to_double ()); |
3893 | if (est_hints) |
3894 | fprintf (dump_file, " loops with known iterations:%f " |
3895 | "known strides:%f", loops_with_known_iterations.to_double (), |
3896 | loops_with_known_strides.to_double ()); |
3897 | fprintf (dump_file, "\n"); |
3898 | } |
3899 | if (est_times) |
3900 | { |
3901 | estimates->time = time; |
3902 | estimates->nonspecialized_time = nonspecialized_time; |
3903 | } |
3904 | estimates->size = size; |
3905 | estimates->min_size = min_size; |
3906 | if (est_hints) |
3907 | estimates->hints = hints; |
3908 | return; |
3909 | } |
3910 | |
3911 | |
3912 | /* Estimate size and time needed to execute callee of EDGE assuming that |
3913 | parameters known to be constant at caller of EDGE are propagated. |
3914 | KNOWN_VALS and KNOWN_CONTEXTS are vectors of assumed known constant values |
3915 | and types for parameters. */ |
3916 | |
3917 | void |
3918 | estimate_ipcp_clone_size_and_time (struct cgraph_node *node, |
3919 | ipa_auto_call_arg_values *avals, |
3920 | ipa_call_estimates *estimates) |
3921 | { |
3922 | clause_t clause, nonspec_clause; |
3923 | |
3924 | evaluate_conditions_for_known_args (node, false, avals, &clause, |
3925 | &nonspec_clause); |
3926 | ipa_call_context ctx (node, clause, nonspec_clause, vNULL, avals); |
3927 | ctx.estimate_size_and_time (estimates); |
3928 | } |
3929 | |
3930 | /* Return stack frame offset where frame of NODE is supposed to start inside |
3931 | of the function it is inlined to. |
3932 | Return 0 for functions that are not inlined. */ |
3933 | |
3934 | HOST_WIDE_INTlong |
3935 | ipa_get_stack_frame_offset (struct cgraph_node *node) |
3936 | { |
3937 | HOST_WIDE_INTlong offset = 0; |
3938 | if (!node->inlined_to) |
3939 | return 0; |
3940 | node = node->callers->caller; |
3941 | while (true) |
3942 | { |
3943 | offset += ipa_size_summaries->get (node)->estimated_self_stack_size; |
3944 | if (!node->inlined_to) |
3945 | return offset; |
3946 | node = node->callers->caller; |
3947 | } |
3948 | } |
3949 | |
3950 | |
3951 | /* Update summary information of inline clones after inlining. |
3952 | Compute peak stack usage. */ |
3953 | |
3954 | static void |
3955 | inline_update_callee_summaries (struct cgraph_node *node, int depth) |
3956 | { |
3957 | struct cgraph_edge *e; |
3958 | |
3959 | ipa_propagate_frequency (node); |
3960 | for (e = node->callees; e; e = e->next_callee) |
3961 | { |
3962 | if (!e->inline_failed) |
3963 | inline_update_callee_summaries (e->callee, depth); |
3964 | else |
3965 | ipa_call_summaries->get (e)->loop_depth += depth; |
3966 | } |
3967 | for (e = node->indirect_calls; e; e = e->next_callee) |
3968 | ipa_call_summaries->get (e)->loop_depth += depth; |
3969 | } |
3970 | |
3971 | /* Update change_prob and points_to_local_or_readonly_memory of EDGE after |
3972 | INLINED_EDGE has been inlined. |
3973 | |
3974 | When function A is inlined in B and A calls C with parameter that |
3975 | changes with probability PROB1 and C is known to be passthrough |
3976 | of argument if B that change with probability PROB2, the probability |
3977 | of change is now PROB1*PROB2. */ |
3978 | |
3979 | static void |
3980 | remap_edge_params (struct cgraph_edge *inlined_edge, |
3981 | struct cgraph_edge *edge) |
3982 | { |
3983 | if (ipa_node_params_sum) |
3984 | { |
3985 | int i; |
3986 | ipa_edge_args *args = ipa_edge_args_sum->get (edge); |
3987 | if (!args) |
3988 | return; |
3989 | class ipa_call_summary *es = ipa_call_summaries->get (edge); |
3990 | class ipa_call_summary *inlined_es |
3991 | = ipa_call_summaries->get (inlined_edge); |
3992 | |
3993 | if (es->param.length () == 0) |
3994 | return; |
3995 | |
3996 | for (i = 0; i < ipa_get_cs_argument_count (args); i++) |
3997 | { |
3998 | struct ipa_jump_func *jfunc = ipa_get_ith_jump_func (args, i); |
3999 | if (jfunc->type == IPA_JF_PASS_THROUGH |
4000 | || jfunc->type == IPA_JF_ANCESTOR) |
4001 | { |
4002 | int id = jfunc->type == IPA_JF_PASS_THROUGH |
4003 | ? ipa_get_jf_pass_through_formal_id (jfunc) |
4004 | : ipa_get_jf_ancestor_formal_id (jfunc); |
4005 | if (id < (int) inlined_es->param.length ()) |
4006 | { |
4007 | int prob1 = es->param[i].change_prob; |
4008 | int prob2 = inlined_es->param[id].change_prob; |
4009 | int prob = combine_probabilities (prob1, prob2); |
4010 | |
4011 | if (prob1 && prob2 && !prob) |
4012 | prob = 1; |
4013 | |
4014 | es->param[i].change_prob = prob; |
4015 | |
4016 | if (inlined_es |
4017 | ->param[id].points_to_local_or_readonly_memory) |
4018 | es->param[i].points_to_local_or_readonly_memory = true; |
4019 | } |
4020 | if (!es->param[i].points_to_local_or_readonly_memory |
4021 | && jfunc->type == IPA_JF_CONST |
4022 | && points_to_local_or_readonly_memory_p |
4023 | (ipa_get_jf_constant (jfunc))) |
4024 | es->param[i].points_to_local_or_readonly_memory = true; |
4025 | } |
4026 | } |
4027 | } |
4028 | } |
4029 | |
4030 | /* Update edge summaries of NODE after INLINED_EDGE has been inlined. |
4031 | |
4032 | Remap predicates of callees of NODE. Rest of arguments match |
4033 | remap_predicate. |
4034 | |
4035 | Also update change probabilities. */ |
4036 | |
4037 | static void |
4038 | remap_edge_summaries (struct cgraph_edge *inlined_edge, |
4039 | struct cgraph_node *node, |
4040 | class ipa_fn_summary *info, |
4041 | class ipa_node_params *params_summary, |
4042 | class ipa_fn_summary *callee_info, |
4043 | const vec<int> &operand_map, |
4044 | const vec<HOST_WIDE_INTlong> &offset_map, |
4045 | clause_t possible_truths, |
4046 | ipa_predicate *toplev_predicate) |
4047 | { |
4048 | struct cgraph_edge *e, *next; |
4049 | for (e = node->callees; e; e = next) |
4050 | { |
4051 | ipa_predicate p; |
4052 | next = e->next_callee; |
4053 | |
4054 | if (e->inline_failed) |
4055 | { |
4056 | class ipa_call_summary *es = ipa_call_summaries->get (e); |
4057 | remap_edge_params (inlined_edge, e); |
4058 | |
4059 | if (es->predicate) |
4060 | { |
4061 | p = es->predicate->remap_after_inlining |
4062 | (info, params_summary, |
4063 | callee_info, operand_map, |
4064 | offset_map, possible_truths, |
4065 | *toplev_predicate); |
4066 | edge_set_predicate (e, &p); |
4067 | } |
4068 | else |
4069 | edge_set_predicate (e, toplev_predicate); |
4070 | } |
4071 | else |
4072 | remap_edge_summaries (inlined_edge, e->callee, info, |
4073 | params_summary, callee_info, |
4074 | operand_map, offset_map, possible_truths, |
4075 | toplev_predicate); |
4076 | } |
4077 | for (e = node->indirect_calls; e; e = next) |
4078 | { |
4079 | class ipa_call_summary *es = ipa_call_summaries->get (e); |
4080 | ipa_predicate p; |
4081 | next = e->next_callee; |
4082 | |
4083 | remap_edge_params (inlined_edge, e); |
4084 | if (es->predicate) |
4085 | { |
4086 | p = es->predicate->remap_after_inlining |
4087 | (info, params_summary, |
4088 | callee_info, operand_map, offset_map, |
4089 | possible_truths, *toplev_predicate); |
4090 | edge_set_predicate (e, &p); |
4091 | } |
4092 | else |
4093 | edge_set_predicate (e, toplev_predicate); |
4094 | } |
4095 | } |
4096 | |
4097 | /* Run remap_after_inlining on each predicate in V. */ |
4098 | |
4099 | static void |
4100 | remap_freqcounting_predicate (class ipa_fn_summary *info, |
4101 | class ipa_node_params *params_summary, |
4102 | class ipa_fn_summary *callee_info, |
4103 | vec<ipa_freqcounting_predicate, va_gc> *v, |
4104 | const vec<int> &operand_map, |
4105 | const vec<HOST_WIDE_INTlong> &offset_map, |
4106 | clause_t possible_truths, |
4107 | ipa_predicate *toplev_predicate) |
4108 | |
4109 | { |
4110 | ipa_freqcounting_predicate *fcp; |
4111 | for (int i = 0; vec_safe_iterate (v, i, &fcp); i++) |
4112 | { |
4113 | ipa_predicate p |
4114 | = fcp->predicate->remap_after_inlining (info, params_summary, |
4115 | callee_info, operand_map, |
4116 | offset_map, possible_truths, |
4117 | *toplev_predicate); |
4118 | if (p != false && p != true) |
4119 | *fcp->predicate &= p; |
4120 | } |
4121 | } |
4122 | |
4123 | /* We inlined EDGE. Update summary of the function we inlined into. */ |
4124 | |
4125 | void |
4126 | ipa_merge_fn_summary_after_inlining (struct cgraph_edge *edge) |
4127 | { |
4128 | ipa_fn_summary *callee_info = ipa_fn_summaries->get (edge->callee); |
4129 | struct cgraph_node *to = (edge->caller->inlined_to |
4130 | ? edge->caller->inlined_to : edge->caller); |
4131 | class ipa_fn_summary *info = ipa_fn_summaries->get (to); |
4132 | clause_t clause = 0; /* not_inline is known to be false. */ |
4133 | size_time_entry *e; |
4134 | auto_vec<int, 8> operand_map; |
4135 | auto_vec<HOST_WIDE_INTlong, 8> offset_map; |
4136 | int i; |
4137 | ipa_predicate toplev_predicate; |
4138 | class ipa_call_summary *es = ipa_call_summaries->get (edge); |
4139 | ipa_node_params *params_summary = (ipa_node_params_sum |
4140 | ? ipa_node_params_sum->get (to) : NULLnullptr); |
4141 | |
4142 | if (es->predicate) |
4143 | toplev_predicate = *es->predicate; |
4144 | else |
4145 | toplev_predicate = true; |
4146 | |
4147 | info->fp_expressions |= callee_info->fp_expressions; |
4148 | info->target_info |= callee_info->target_info; |
4149 | |
4150 | if (callee_info->conds) |
4151 | { |
4152 | ipa_auto_call_arg_values avals; |
4153 | evaluate_properties_for_edge (edge, true, &clause, NULLnullptr, &avals, false); |
4154 | } |
4155 | if (ipa_node_params_sum && callee_info->conds) |
4156 | { |
4157 | ipa_edge_args *args = ipa_edge_args_sum->get (edge); |
4158 | int count = args ? ipa_get_cs_argument_count (args) : 0; |
4159 | int i; |
4160 | |
4161 | if (count) |
4162 | { |
4163 | operand_map.safe_grow_cleared (count, true); |
4164 | offset_map.safe_grow_cleared (count, true); |
4165 | } |
4166 | for (i = 0; i < count; i++) |
4167 | { |
4168 | struct ipa_jump_func *jfunc = ipa_get_ith_jump_func (args, i); |
4169 | int map = -1; |
4170 | |
4171 | /* TODO: handle non-NOPs when merging. */ |
4172 | if (jfunc->type == IPA_JF_PASS_THROUGH) |
4173 | { |
4174 | if (ipa_get_jf_pass_through_operation (jfunc) == NOP_EXPR) |
4175 | map = ipa_get_jf_pass_through_formal_id (jfunc); |
4176 | if (!ipa_get_jf_pass_through_agg_preserved (jfunc)) |
4177 | offset_map[i] = -1; |
4178 | } |
4179 | else if (jfunc->type == IPA_JF_ANCESTOR) |
4180 | { |
4181 | HOST_WIDE_INTlong offset = ipa_get_jf_ancestor_offset (jfunc); |
4182 | if (offset >= 0 && offset < INT_MAX2147483647) |
4183 | { |
4184 | map = ipa_get_jf_ancestor_formal_id (jfunc); |
4185 | if (!ipa_get_jf_ancestor_agg_preserved (jfunc)) |
4186 | offset = -1; |
4187 | offset_map[i] = offset; |
4188 | } |
4189 | } |
4190 | operand_map[i] = map; |
4191 | gcc_assert (map < ipa_get_param_count (params_summary))((void)(!(map < ipa_get_param_count (params_summary)) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 4191, __FUNCTION__), 0 : 0)); |
4192 | } |
4193 | |
4194 | int ip; |
4195 | for (i = 0; callee_info->builtin_constant_p_parms.iterate (i, &ip); i++) |
4196 | if (ip < count && operand_map[ip] >= 0) |
4197 | add_builtin_constant_p_parm (info, operand_map[ip]); |
4198 | } |
4199 | sreal freq = edge->sreal_frequency (); |
4200 | for (i = 0; callee_info->size_time_table.iterate (i, &e); i++) |
4201 | { |
4202 | ipa_predicate p; |
4203 | p = e->exec_predicate.remap_after_inlining |
4204 | (info, params_summary, |
4205 | callee_info, operand_map, |
4206 | offset_map, clause, |
4207 | toplev_predicate); |
4208 | ipa_predicate nonconstp; |
4209 | nonconstp = e->nonconst_predicate.remap_after_inlining |
4210 | (info, params_summary, |
4211 | callee_info, operand_map, |
4212 | offset_map, clause, |
4213 | toplev_predicate); |
4214 | if (p != false && nonconstp != false) |
4215 | { |
4216 | sreal add_time = ((sreal)e->time * freq); |
4217 | int prob = e->nonconst_predicate.probability (callee_info->conds, |
4218 | clause, es->param); |
4219 | if (prob != REG_BR_PROB_BASE10000) |
4220 | add_time = add_time * prob / REG_BR_PROB_BASE10000; |
4221 | if (prob != REG_BR_PROB_BASE10000 |
4222 | && dump_file && (dump_flags & TDF_DETAILS)) |
4223 | { |
4224 | fprintf (dump_file, "\t\tScaling time by probability:%f\n", |
4225 | (double) prob / REG_BR_PROB_BASE10000); |
4226 | } |
4227 | info->account_size_time (e->size, add_time, p, nonconstp); |
4228 | } |
4229 | } |
4230 | remap_edge_summaries (edge, edge->callee, info, params_summary, |
4231 | callee_info, operand_map, |
4232 | offset_map, clause, &toplev_predicate); |
4233 | remap_freqcounting_predicate (info, params_summary, callee_info, |
4234 | info->loop_iterations, operand_map, |
4235 | offset_map, clause, &toplev_predicate); |
4236 | remap_freqcounting_predicate (info, params_summary, callee_info, |
4237 | info->loop_strides, operand_map, |
4238 | offset_map, clause, &toplev_predicate); |
4239 | |
4240 | HOST_WIDE_INTlong stack_frame_offset = ipa_get_stack_frame_offset (edge->callee); |
4241 | HOST_WIDE_INTlong peak = stack_frame_offset + callee_info->estimated_stack_size; |
4242 | |
4243 | if (info->estimated_stack_size < peak) |
4244 | info->estimated_stack_size = peak; |
4245 | |
4246 | inline_update_callee_summaries (edge->callee, es->loop_depth); |
4247 | if (info->call_size_time_table.length ()) |
4248 | { |
4249 | int edge_size = 0; |
4250 | sreal edge_time = 0; |
4251 | |
4252 | estimate_edge_size_and_time (edge, &edge_size, NULLnullptr, &edge_time, NULLnullptr, 0); |
4253 | /* Unaccount size and time of the optimized out call. */ |
4254 | info->account_size_time (-edge_size, -edge_time, |
4255 | es->predicate ? *es->predicate : true, |
4256 | es->predicate ? *es->predicate : true, |
4257 | true); |
4258 | /* Account new calls. */ |
4259 | summarize_calls_size_and_time (edge->callee, info); |
4260 | } |
4261 | |
4262 | /* Free summaries that are not maintained for inline clones/edges. */ |
4263 | ipa_call_summaries->remove (edge); |
4264 | ipa_fn_summaries->remove (edge->callee); |
4265 | ipa_remove_from_growth_caches (edge); |
4266 | } |
4267 | |
4268 | /* For performance reasons ipa_merge_fn_summary_after_inlining is not updating |
4269 | overall size and time. Recompute it. |
4270 | If RESET is true also recompute call_time_size_table. */ |
4271 | |
4272 | void |
4273 | ipa_update_overall_fn_summary (struct cgraph_node *node, bool reset) |
4274 | { |
4275 | class ipa_fn_summary *info = ipa_fn_summaries->get (node); |
4276 | class ipa_size_summary *size_info = ipa_size_summaries->get (node); |
4277 | size_time_entry *e; |
4278 | int i; |
4279 | |
4280 | size_info->size = 0; |
4281 | info->time = 0; |
4282 | for (i = 0; info->size_time_table.iterate (i, &e); i++) |
4283 | { |
4284 | size_info->size += e->size; |
4285 | info->time += e->time; |
4286 | } |
4287 | info->min_size = info->size_time_table[0].size; |
4288 | if (reset) |
4289 | info->call_size_time_table.release (); |
4290 | if (node->callees || node->indirect_calls) |
4291 | estimate_calls_size_and_time (node, &size_info->size, &info->min_size, |
4292 | &info->time, NULLnullptr, |
4293 | ~(clause_t) (1 << ipa_predicate::false_condition), |
4294 | NULLnullptr); |
4295 | size_info->size = RDIV (size_info->size, ipa_fn_summary::size_scale)(((size_info->size) + (ipa_fn_summary::size_scale) / 2) / ( ipa_fn_summary::size_scale)); |
4296 | info->min_size = RDIV (info->min_size, ipa_fn_summary::size_scale)(((info->min_size) + (ipa_fn_summary::size_scale) / 2) / ( ipa_fn_summary::size_scale)); |
4297 | } |
4298 | |
4299 | |
4300 | /* This function performs intraprocedural analysis in NODE that is required to |
4301 | inline indirect calls. */ |
4302 | |
4303 | static void |
4304 | inline_indirect_intraprocedural_analysis (struct cgraph_node *node) |
4305 | { |
4306 | ipa_analyze_node (node); |
4307 | if (dump_file && (dump_flags & TDF_DETAILS)) |
4308 | { |
4309 | ipa_print_node_params (dump_file, node); |
4310 | ipa_print_node_jump_functions (dump_file, node); |
4311 | } |
4312 | } |
4313 | |
4314 | |
4315 | /* Note function body size. */ |
4316 | |
4317 | void |
4318 | inline_analyze_function (struct cgraph_node *node) |
4319 | { |
4320 | push_cfun (DECL_STRUCT_FUNCTION (node->decl)((tree_check ((node->decl), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 4320, __FUNCTION__, (FUNCTION_DECL)))->function_decl.f)); |
4321 | |
4322 | if (dump_file) |
4323 | fprintf (dump_file, "\nAnalyzing function: %s\n", node->dump_name ()); |
4324 | if (opt_for_fn (node->decl, optimize)(opts_for_fn (node->decl)->x_optimize) && !node->thunk) |
4325 | inline_indirect_intraprocedural_analysis (node); |
4326 | compute_fn_summary (node, false); |
4327 | if (!optimizeglobal_options.x_optimize) |
4328 | { |
4329 | struct cgraph_edge *e; |
4330 | for (e = node->callees; e; e = e->next_callee) |
4331 | e->inline_failed = CIF_FUNCTION_NOT_OPTIMIZED; |
4332 | for (e = node->indirect_calls; e; e = e->next_callee) |
4333 | e->inline_failed = CIF_FUNCTION_NOT_OPTIMIZED; |
4334 | } |
4335 | |
4336 | pop_cfun (); |
4337 | } |
4338 | |
4339 | |
4340 | /* Called when new function is inserted to callgraph late. */ |
4341 | |
4342 | void |
4343 | ipa_fn_summary_t::insert (struct cgraph_node *node, ipa_fn_summary *) |
4344 | { |
4345 | inline_analyze_function (node); |
4346 | } |
4347 | |
4348 | /* Note function body size. */ |
4349 | |
4350 | static void |
4351 | ipa_fn_summary_generate (void) |
4352 | { |
4353 | struct cgraph_node *node; |
4354 | |
4355 | FOR_EACH_DEFINED_FUNCTION (node)for ((node) = symtab->first_defined_function (); (node); ( node) = symtab->next_defined_function ((node))) |
4356 | if (DECL_STRUCT_FUNCTION (node->decl)((tree_check ((node->decl), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 4356, __FUNCTION__, (FUNCTION_DECL)))->function_decl.f)) |
4357 | node->versionable = tree_versionable_function_p (node->decl); |
4358 | |
4359 | ipa_fn_summary_alloc (); |
4360 | |
4361 | ipa_fn_summaries->enable_insertion_hook (); |
4362 | |
4363 | ipa_register_cgraph_hooks (); |
4364 | |
4365 | FOR_EACH_DEFINED_FUNCTION (node)for ((node) = symtab->first_defined_function (); (node); ( node) = symtab->next_defined_function ((node))) |
4366 | if (!node->alias |
4367 | && (flag_generate_ltoglobal_options.x_flag_generate_lto || flag_generate_offloadglobal_options.x_flag_generate_offload|| flag_wpaglobal_options.x_flag_wpa |
4368 | || opt_for_fn (node->decl, optimize)(opts_for_fn (node->decl)->x_optimize))) |
4369 | inline_analyze_function (node); |
4370 | } |
4371 | |
4372 | |
4373 | /* Write inline summary for edge E to OB. */ |
4374 | |
4375 | static void |
4376 | read_ipa_call_summary (class lto_input_block *ib, struct cgraph_edge *e, |
4377 | bool prevails) |
4378 | { |
4379 | class ipa_call_summary *es = prevails |
4380 | ? ipa_call_summaries->get_create (e) : NULLnullptr; |
4381 | ipa_predicate p; |
4382 | int length, i; |
4383 | |
4384 | int size = streamer_read_uhwi (ib); |
4385 | int time = streamer_read_uhwi (ib); |
4386 | int depth = streamer_read_uhwi (ib); |
4387 | |
4388 | if (es) |
4389 | { |
4390 | es->call_stmt_size = size; |
4391 | es->call_stmt_time = time; |
4392 | es->loop_depth = depth; |
4393 | } |
4394 | |
4395 | bitpack_d bp = streamer_read_bitpack (ib); |
4396 | if (es) |
4397 | es->is_return_callee_uncaptured = bp_unpack_value (&bp, 1); |
4398 | else |
4399 | bp_unpack_value (&bp, 1); |
4400 | |
4401 | p.stream_in (ib); |
4402 | if (es) |
4403 | edge_set_predicate (e, &p); |
4404 | length = streamer_read_uhwi (ib); |
4405 | if (length && es |
4406 | && (e->possibly_call_in_translation_unit_p () |
4407 | /* Also stream in jump functions to builtins in hope that they |
4408 | will get fnspecs. */ |
4409 | || fndecl_built_in_p (e->callee->decl, BUILT_IN_NORMAL))) |
4410 | { |
4411 | es->param.safe_grow_cleared (length, true); |
4412 | for (i = 0; i < length; i++) |
4413 | { |
4414 | es->param[i].change_prob = streamer_read_uhwi (ib); |
4415 | es->param[i].points_to_local_or_readonly_memory |
4416 | = streamer_read_uhwi (ib); |
4417 | } |
4418 | } |
4419 | else |
4420 | { |
4421 | for (i = 0; i < length; i++) |
4422 | { |
4423 | streamer_read_uhwi (ib); |
4424 | streamer_read_uhwi (ib); |
4425 | } |
4426 | } |
4427 | } |
4428 | |
4429 | |
4430 | /* Stream in inline summaries from the section. */ |
4431 | |
4432 | static void |
4433 | inline_read_section (struct lto_file_decl_data *file_data, const char *data, |
4434 | size_t len) |
4435 | { |
4436 | const struct lto_function_header *header = |
4437 | (const struct lto_function_header *) data; |
4438 | const int cfg_offset = sizeof (struct lto_function_header); |
4439 | const int main_offset = cfg_offset + header->cfg_size; |
4440 | const int string_offset = main_offset + header->main_size; |
4441 | class data_in *data_in; |
4442 | unsigned int i, count2, j; |
4443 | unsigned int f_count; |
4444 | |
4445 | lto_input_block ib ((const char *) data + main_offset, header->main_size, |
4446 | file_data->mode_table); |
4447 | |
4448 | data_in = |
4449 | lto_data_in_create (file_data, (const char *) data + string_offset, |
4450 | header->string_size, vNULL); |
4451 | f_count = streamer_read_uhwi (&ib); |
4452 | for (i = 0; i < f_count; i++) |
4453 | { |
4454 | unsigned int index; |
4455 | struct cgraph_node *node; |
4456 | class ipa_fn_summary *info; |
4457 | class ipa_node_params *params_summary; |
4458 | class ipa_size_summary *size_info; |
4459 | lto_symtab_encoder_t encoder; |
4460 | struct bitpack_d bp; |
4461 | struct cgraph_edge *e; |
4462 | ipa_predicate p; |
4463 | |
4464 | index = streamer_read_uhwi (&ib); |
4465 | encoder = file_data->symtab_node_encoder; |
4466 | node = dyn_cast<cgraph_node *> (lto_symtab_encoder_deref (encoder, |
4467 | index)); |
4468 | info = node->prevailing_p () ? ipa_fn_summaries->get_create (node) : NULLnullptr; |
4469 | params_summary = node->prevailing_p () |
4470 | ? ipa_node_params_sum->get (node) : NULLnullptr; |
4471 | size_info = node->prevailing_p () |
4472 | ? ipa_size_summaries->get_create (node) : NULLnullptr; |
4473 | |
4474 | int stack_size = streamer_read_uhwi (&ib); |
4475 | int size = streamer_read_uhwi (&ib); |
4476 | sreal time = sreal::stream_in (&ib); |
4477 | |
4478 | if (info) |
4479 | { |
4480 | info->estimated_stack_size |
4481 | = size_info->estimated_self_stack_size = stack_size; |
4482 | size_info->size = size_info->self_size = size; |
4483 | info->time = time; |
4484 | } |
4485 | |
4486 | bp = streamer_read_bitpack (&ib); |
4487 | if (info) |
4488 | { |
4489 | info->inlinable = bp_unpack_value (&bp, 1); |
4490 | info->fp_expressions = bp_unpack_value (&bp, 1); |
4491 | if (!lto_stream_offload_p) |
4492 | info->target_info = streamer_read_uhwi (&ib); |
4493 | } |
4494 | else |
4495 | { |
4496 | bp_unpack_value (&bp, 1); |
4497 | bp_unpack_value (&bp, 1); |
4498 | if (!lto_stream_offload_p) |
4499 | streamer_read_uhwi (&ib); |
4500 | } |
4501 | |
4502 | count2 = streamer_read_uhwi (&ib); |
4503 | gcc_assert (!info || !info->conds)((void)(!(!info || !info->conds) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 4503, __FUNCTION__), 0 : 0)); |
4504 | if (info) |
4505 | vec_safe_reserve_exact (info->conds, count2); |
4506 | for (j = 0; j < count2; j++) |
4507 | { |
4508 | struct condition c; |
4509 | unsigned int k, count3; |
4510 | c.operand_num = streamer_read_uhwi (&ib); |
4511 | c.code = (enum tree_code) streamer_read_uhwi (&ib); |
4512 | c.type = stream_read_tree (&ib, data_in)streamer_hooks.read_tree (&ib, data_in); |
4513 | c.val = stream_read_tree (&ib, data_in)streamer_hooks.read_tree (&ib, data_in); |
4514 | bp = streamer_read_bitpack (&ib); |
4515 | c.agg_contents = bp_unpack_value (&bp, 1); |
4516 | c.by_ref = bp_unpack_value (&bp, 1); |
4517 | if (c.agg_contents) |
4518 | c.offset = streamer_read_uhwi (&ib); |
4519 | count3 = streamer_read_uhwi (&ib); |
4520 | c.param_ops = NULLnullptr; |
4521 | if (info) |
4522 | vec_safe_reserve_exact (c.param_ops, count3); |
4523 | if (params_summary) |
4524 | ipa_set_param_used_by_ipa_predicates |
4525 | (params_summary, c.operand_num, true); |
4526 | for (k = 0; k < count3; k++) |
4527 | { |
4528 | struct expr_eval_op op; |
4529 | enum gimple_rhs_class rhs_class; |
4530 | op.code = (enum tree_code) streamer_read_uhwi (&ib); |
4531 | op.type = stream_read_tree (&ib, data_in)streamer_hooks.read_tree (&ib, data_in); |
4532 | switch (rhs_class = get_gimple_rhs_class (op.code)) |
4533 | { |
4534 | case GIMPLE_UNARY_RHS: |
4535 | op.index = 0; |
4536 | op.val[0] = NULL_TREE(tree) nullptr; |
4537 | op.val[1] = NULL_TREE(tree) nullptr; |
4538 | break; |
4539 | |
4540 | case GIMPLE_BINARY_RHS: |
4541 | case GIMPLE_TERNARY_RHS: |
4542 | bp = streamer_read_bitpack (&ib); |
4543 | op.index = bp_unpack_value (&bp, 2); |
4544 | op.val[0] = stream_read_tree (&ib, data_in)streamer_hooks.read_tree (&ib, data_in); |
4545 | if (rhs_class == GIMPLE_BINARY_RHS) |
4546 | op.val[1] = NULL_TREE(tree) nullptr; |
4547 | else |
4548 | op.val[1] = stream_read_tree (&ib, data_in)streamer_hooks.read_tree (&ib, data_in); |
4549 | break; |
4550 | |
4551 | default: |
4552 | fatal_error (UNKNOWN_LOCATION((location_t) 0), |
4553 | "invalid fnsummary in LTO stream"); |
4554 | } |
4555 | if (info) |
4556 | c.param_ops->quick_push (op); |
4557 | } |
4558 | if (info) |
4559 | info->conds->quick_push (c); |
4560 | } |
4561 | count2 = streamer_read_uhwi (&ib); |
4562 | gcc_assert (!info || !info->size_time_table.length ())((void)(!(!info || !info->size_time_table.length ()) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 4562, __FUNCTION__), 0 : 0)); |
4563 | if (info && count2) |
4564 | info->size_time_table.reserve_exact (count2); |
4565 | for (j = 0; j < count2; j++) |
4566 | { |
4567 | class size_time_entry e; |
4568 | |
4569 | e.size = streamer_read_uhwi (&ib); |
4570 | e.time = sreal::stream_in (&ib); |
4571 | e.exec_predicate.stream_in (&ib); |
4572 | e.nonconst_predicate.stream_in (&ib); |
4573 | |
4574 | if (info) |
4575 | info->size_time_table.quick_push (e); |
4576 | } |
4577 | |
4578 | count2 = streamer_read_uhwi (&ib); |
4579 | for (j = 0; j < count2; j++) |
4580 | { |
4581 | p.stream_in (&ib); |
4582 | sreal fcp_freq = sreal::stream_in (&ib); |
4583 | if (info) |
4584 | { |
4585 | ipa_freqcounting_predicate fcp; |
4586 | fcp.predicate = NULLnullptr; |
4587 | set_hint_predicate (&fcp.predicate, p); |
4588 | fcp.freq = fcp_freq; |
4589 | vec_safe_push (info->loop_iterations, fcp); |
4590 | } |
4591 | } |
4592 | count2 = streamer_read_uhwi (&ib); |
4593 | for (j = 0; j < count2; j++) |
4594 | { |
4595 | p.stream_in (&ib); |
4596 | sreal fcp_freq = sreal::stream_in (&ib); |
4597 | if (info) |
4598 | { |
4599 | ipa_freqcounting_predicate fcp; |
4600 | fcp.predicate = NULLnullptr; |
4601 | set_hint_predicate (&fcp.predicate, p); |
4602 | fcp.freq = fcp_freq; |
4603 | vec_safe_push (info->loop_strides, fcp); |
4604 | } |
4605 | } |
4606 | count2 = streamer_read_uhwi (&ib); |
4607 | if (info && count2) |
4608 | info->builtin_constant_p_parms.reserve_exact (count2); |
4609 | for (j = 0; j < count2; j++) |
4610 | { |
4611 | int parm = streamer_read_uhwi (&ib); |
4612 | if (info) |
4613 | info->builtin_constant_p_parms.quick_push (parm); |
4614 | } |
4615 | for (e = node->callees; e; e = e->next_callee) |
4616 | read_ipa_call_summary (&ib, e, info != NULLnullptr); |
4617 | for (e = node->indirect_calls; e; e = e->next_callee) |
4618 | read_ipa_call_summary (&ib, e, info != NULLnullptr); |
4619 | } |
4620 | |
4621 | lto_free_section_data (file_data, LTO_section_ipa_fn_summary, NULLnullptr, data, |
4622 | len); |
4623 | lto_data_in_delete (data_in); |
4624 | } |
4625 | |
4626 | |
4627 | /* Read inline summary. Jump functions are shared among ipa-cp |
4628 | and inliner, so when ipa-cp is active, we don't need to write them |
4629 | twice. */ |
4630 | |
4631 | static void |
4632 | ipa_fn_summary_read (void) |
4633 | { |
4634 | struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data (); |
4635 | struct lto_file_decl_data *file_data; |
4636 | unsigned int j = 0; |
4637 | |
4638 | ipa_prop_read_jump_functions (); |
4639 | ipa_fn_summary_alloc (); |
4640 | |
4641 | while ((file_data = file_data_vec[j++])) |
4642 | { |
4643 | size_t len; |
4644 | const char *data |
4645 | = lto_get_summary_section_data (file_data, LTO_section_ipa_fn_summary, |
4646 | &len); |
4647 | if (data) |
4648 | inline_read_section (file_data, data, len); |
4649 | else |
4650 | /* Fatal error here. We do not want to support compiling ltrans units |
4651 | with different version of compiler or different flags than the WPA |
4652 | unit, so this should never happen. */ |
4653 | fatal_error (input_location, |
4654 | "ipa inline summary is missing in input file"); |
4655 | } |
4656 | ipa_register_cgraph_hooks (); |
4657 | |
4658 | gcc_assert (ipa_fn_summaries)((void)(!(ipa_fn_summaries) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 4658, __FUNCTION__), 0 : 0)); |
4659 | ipa_fn_summaries->enable_insertion_hook (); |
4660 | } |
4661 | |
4662 | |
4663 | /* Write inline summary for edge E to OB. */ |
4664 | |
4665 | static void |
4666 | write_ipa_call_summary (struct output_block *ob, struct cgraph_edge *e) |
4667 | { |
4668 | class ipa_call_summary *es = ipa_call_summaries->get (e); |
4669 | int i; |
4670 | |
4671 | streamer_write_uhwi (ob, es->call_stmt_size); |
4672 | streamer_write_uhwi (ob, es->call_stmt_time); |
4673 | streamer_write_uhwi (ob, es->loop_depth); |
4674 | |
4675 | bitpack_d bp = bitpack_create (ob->main_stream); |
4676 | bp_pack_value (&bp, es->is_return_callee_uncaptured, 1); |
4677 | streamer_write_bitpack (&bp); |
4678 | |
4679 | if (es->predicate) |
4680 | es->predicate->stream_out (ob); |
4681 | else |
4682 | streamer_write_uhwi (ob, 0); |
4683 | streamer_write_uhwi (ob, es->param.length ()); |
4684 | for (i = 0; i < (int) es->param.length (); i++) |
4685 | { |
4686 | streamer_write_uhwi (ob, es->param[i].change_prob); |
4687 | streamer_write_uhwi (ob, es->param[i].points_to_local_or_readonly_memory); |
4688 | } |
4689 | } |
4690 | |
4691 | |
4692 | /* Write inline summary for node in SET. |
4693 | Jump functions are shared among ipa-cp and inliner, so when ipa-cp is |
4694 | active, we don't need to write them twice. */ |
4695 | |
4696 | static void |
4697 | ipa_fn_summary_write (void) |
4698 | { |
4699 | struct output_block *ob = create_output_block (LTO_section_ipa_fn_summary); |
4700 | lto_symtab_encoder_iterator lsei; |
4701 | lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder; |
4702 | unsigned int count = 0; |
4703 | |
4704 | for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei); |
4705 | lsei_next_function_in_partition (&lsei)) |
4706 | { |
4707 | cgraph_node *cnode = lsei_cgraph_node (lsei); |
4708 | if (cnode->definition && !cnode->alias) |
4709 | count++; |
4710 | } |
4711 | streamer_write_uhwi (ob, count); |
4712 | |
4713 | for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei); |
4714 | lsei_next_function_in_partition (&lsei)) |
4715 | { |
4716 | cgraph_node *cnode = lsei_cgraph_node (lsei); |
4717 | if (cnode->definition && !cnode->alias) |
4718 | { |
4719 | class ipa_fn_summary *info = ipa_fn_summaries->get (cnode); |
4720 | class ipa_size_summary *size_info = ipa_size_summaries->get (cnode); |
4721 | struct bitpack_d bp; |
4722 | struct cgraph_edge *edge; |
4723 | int i; |
4724 | size_time_entry *e; |
4725 | struct condition *c; |
4726 | |
4727 | streamer_write_uhwi (ob, lto_symtab_encoder_encode (encoder, cnode)); |
4728 | streamer_write_hwi (ob, size_info->estimated_self_stack_size); |
4729 | streamer_write_hwi (ob, size_info->self_size); |
4730 | info->time.stream_out (ob); |
4731 | bp = bitpack_create (ob->main_stream); |
4732 | bp_pack_value (&bp, info->inlinable, 1); |
4733 | bp_pack_value (&bp, info->fp_expressions, 1); |
4734 | streamer_write_bitpack (&bp); |
4735 | if (!lto_stream_offload_p) |
4736 | streamer_write_uhwi (ob, info->target_info); |
4737 | streamer_write_uhwi (ob, vec_safe_length (info->conds)); |
4738 | for (i = 0; vec_safe_iterate (info->conds, i, &c); i++) |
4739 | { |
4740 | int j; |
4741 | struct expr_eval_op *op; |
4742 | |
4743 | streamer_write_uhwi (ob, c->operand_num); |
4744 | streamer_write_uhwi (ob, c->code); |
4745 | stream_write_tree (ob, c->type, true)streamer_hooks.write_tree (ob, c->type, true, true); |
4746 | stream_write_tree (ob, c->val, true)streamer_hooks.write_tree (ob, c->val, true, true); |
4747 | bp = bitpack_create (ob->main_stream); |
4748 | bp_pack_value (&bp, c->agg_contents, 1); |
4749 | bp_pack_value (&bp, c->by_ref, 1); |
4750 | streamer_write_bitpack (&bp); |
4751 | if (c->agg_contents) |
4752 | streamer_write_uhwi (ob, c->offset); |
4753 | streamer_write_uhwi (ob, vec_safe_length (c->param_ops)); |
4754 | for (j = 0; vec_safe_iterate (c->param_ops, j, &op); j++) |
4755 | { |
4756 | streamer_write_uhwi (ob, op->code); |
4757 | stream_write_tree (ob, op->type, true)streamer_hooks.write_tree (ob, op->type, true, true); |
4758 | if (op->val[0]) |
4759 | { |
4760 | bp = bitpack_create (ob->main_stream); |
4761 | bp_pack_value (&bp, op->index, 2); |
4762 | streamer_write_bitpack (&bp); |
4763 | stream_write_tree (ob, op->val[0], true)streamer_hooks.write_tree (ob, op->val[0], true, true); |
4764 | if (op->val[1]) |
4765 | stream_write_tree (ob, op->val[1], true)streamer_hooks.write_tree (ob, op->val[1], true, true); |
4766 | } |
4767 | } |
4768 | } |
4769 | streamer_write_uhwi (ob, info->size_time_table.length ()); |
4770 | for (i = 0; info->size_time_table.iterate (i, &e); i++) |
4771 | { |
4772 | streamer_write_uhwi (ob, e->size); |
4773 | e->time.stream_out (ob); |
4774 | e->exec_predicate.stream_out (ob); |
4775 | e->nonconst_predicate.stream_out (ob); |
4776 | } |
4777 | ipa_freqcounting_predicate *fcp; |
4778 | streamer_write_uhwi (ob, vec_safe_length (info->loop_iterations)); |
4779 | for (i = 0; vec_safe_iterate (info->loop_iterations, i, &fcp); i++) |
4780 | { |
4781 | fcp->predicate->stream_out (ob); |
4782 | fcp->freq.stream_out (ob); |
4783 | } |
4784 | streamer_write_uhwi (ob, vec_safe_length (info->loop_strides)); |
4785 | for (i = 0; vec_safe_iterate (info->loop_strides, i, &fcp); i++) |
4786 | { |
4787 | fcp->predicate->stream_out (ob); |
4788 | fcp->freq.stream_out (ob); |
4789 | } |
4790 | streamer_write_uhwi (ob, info->builtin_constant_p_parms.length ()); |
4791 | int ip; |
4792 | for (i = 0; info->builtin_constant_p_parms.iterate (i, &ip); |
4793 | i++) |
4794 | streamer_write_uhwi (ob, ip); |
4795 | for (edge = cnode->callees; edge; edge = edge->next_callee) |
4796 | write_ipa_call_summary (ob, edge); |
4797 | for (edge = cnode->indirect_calls; edge; edge = edge->next_callee) |
4798 | write_ipa_call_summary (ob, edge); |
4799 | } |
4800 | } |
4801 | streamer_write_char_stream (ob->main_stream, 0); |
4802 | produce_asm (ob, NULLnullptr); |
4803 | destroy_output_block (ob); |
4804 | |
4805 | ipa_prop_write_jump_functions (); |
4806 | } |
4807 | |
4808 | |
4809 | /* Release function summary. */ |
4810 | |
4811 | void |
4812 | ipa_free_fn_summary (void) |
4813 | { |
4814 | if (!ipa_call_summaries) |
4815 | return; |
4816 | ggc_delete (ipa_fn_summaries); |
4817 | ipa_fn_summaries = NULLnullptr; |
4818 | delete ipa_call_summaries; |
4819 | ipa_call_summaries = NULLnullptr; |
4820 | edge_predicate_pool.release (); |
4821 | /* During IPA this is one of largest datastructures to release. */ |
4822 | if (flag_wpaglobal_options.x_flag_wpa) |
4823 | ggc_trim (); |
4824 | } |
4825 | |
4826 | /* Release function summary. */ |
4827 | |
4828 | void |
4829 | ipa_free_size_summary (void) |
4830 | { |
4831 | if (!ipa_size_summaries) |
4832 | return; |
4833 | delete ipa_size_summaries; |
4834 | ipa_size_summaries = NULLnullptr; |
4835 | } |
4836 | |
4837 | namespace { |
4838 | |
4839 | const pass_data pass_data_local_fn_summary = |
4840 | { |
4841 | GIMPLE_PASS, /* type */ |
4842 | "local-fnsummary", /* name */ |
4843 | OPTGROUP_INLINE, /* optinfo_flags */ |
4844 | TV_INLINE_PARAMETERS, /* tv_id */ |
4845 | 0, /* properties_required */ |
4846 | 0, /* properties_provided */ |
4847 | 0, /* properties_destroyed */ |
4848 | 0, /* todo_flags_start */ |
4849 | 0, /* todo_flags_finish */ |
4850 | }; |
4851 | |
4852 | class pass_local_fn_summary : public gimple_opt_pass |
4853 | { |
4854 | public: |
4855 | pass_local_fn_summary (gcc::context *ctxt) |
4856 | : gimple_opt_pass (pass_data_local_fn_summary, ctxt) |
4857 | {} |
4858 | |
4859 | /* opt_pass methods: */ |
4860 | opt_pass * clone () final override |
4861 | { |
4862 | return new pass_local_fn_summary (m_ctxt); |
4863 | } |
4864 | unsigned int execute (function *) final override |
4865 | { |
4866 | return compute_fn_summary_for_current (); |
4867 | } |
4868 | |
4869 | }; // class pass_local_fn_summary |
4870 | |
4871 | } // anon namespace |
4872 | |
4873 | gimple_opt_pass * |
4874 | make_pass_local_fn_summary (gcc::context *ctxt) |
4875 | { |
4876 | return new pass_local_fn_summary (ctxt); |
4877 | } |
4878 | |
4879 | |
4880 | /* Free inline summary. */ |
4881 | |
4882 | namespace { |
4883 | |
4884 | const pass_data pass_data_ipa_free_fn_summary = |
4885 | { |
4886 | SIMPLE_IPA_PASS, /* type */ |
4887 | "free-fnsummary", /* name */ |
4888 | OPTGROUP_NONE, /* optinfo_flags */ |
4889 | TV_IPA_FREE_INLINE_SUMMARY, /* tv_id */ |
4890 | 0, /* properties_required */ |
4891 | 0, /* properties_provided */ |
4892 | 0, /* properties_destroyed */ |
4893 | 0, /* todo_flags_start */ |
4894 | 0, /* todo_flags_finish */ |
4895 | }; |
4896 | |
4897 | class pass_ipa_free_fn_summary : public simple_ipa_opt_pass |
4898 | { |
4899 | public: |
4900 | pass_ipa_free_fn_summary (gcc::context *ctxt) |
4901 | : simple_ipa_opt_pass (pass_data_ipa_free_fn_summary, ctxt), |
4902 | small_p (false) |
4903 | {} |
4904 | |
4905 | /* opt_pass methods: */ |
4906 | opt_pass *clone () final override |
4907 | { |
4908 | return new pass_ipa_free_fn_summary (m_ctxt); |
4909 | } |
4910 | void set_pass_param (unsigned int n, bool param) final override |
4911 | { |
4912 | gcc_assert (n == 0)((void)(!(n == 0) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ipa-fnsummary.cc" , 4912, __FUNCTION__), 0 : 0)); |
4913 | small_p = param; |
4914 | } |
4915 | bool gate (function *) final override { return true; } |
4916 | unsigned int execute (function *) final override |
4917 | { |
4918 | ipa_free_fn_summary (); |
4919 | /* Free ipa-prop structures if they are no longer needed. */ |
4920 | ipa_free_all_structures_after_iinln (); |
4921 | if (!flag_wpaglobal_options.x_flag_wpa) |
4922 | ipa_free_size_summary (); |
4923 | return 0; |
4924 | } |
4925 | |
4926 | private: |
4927 | bool small_p; |
4928 | }; // class pass_ipa_free_fn_summary |
4929 | |
4930 | } // anon namespace |
4931 | |
4932 | simple_ipa_opt_pass * |
4933 | make_pass_ipa_free_fn_summary (gcc::context *ctxt) |
4934 | { |
4935 | return new pass_ipa_free_fn_summary (ctxt); |
4936 | } |
4937 | |
4938 | namespace { |
4939 | |
4940 | const pass_data pass_data_ipa_fn_summary = |
4941 | { |
4942 | IPA_PASS, /* type */ |
4943 | "fnsummary", /* name */ |
4944 | OPTGROUP_INLINE, /* optinfo_flags */ |
4945 | TV_IPA_FNSUMMARY, /* tv_id */ |
4946 | 0, /* properties_required */ |
4947 | 0, /* properties_provided */ |
4948 | 0, /* properties_destroyed */ |
4949 | 0, /* todo_flags_start */ |
4950 | ( TODO_dump_symtab(1 << 7) ), /* todo_flags_finish */ |
4951 | }; |
4952 | |
4953 | class pass_ipa_fn_summary : public ipa_opt_pass_d |
4954 | { |
4955 | public: |
4956 | pass_ipa_fn_summary (gcc::context *ctxt) |
4957 | : ipa_opt_pass_d (pass_data_ipa_fn_summary, ctxt, |
4958 | ipa_fn_summary_generate, /* generate_summary */ |
4959 | ipa_fn_summary_write, /* write_summary */ |
4960 | ipa_fn_summary_read, /* read_summary */ |
4961 | NULLnullptr, /* write_optimization_summary */ |
4962 | NULLnullptr, /* read_optimization_summary */ |
4963 | NULLnullptr, /* stmt_fixup */ |
4964 | 0, /* function_transform_todo_flags_start */ |
4965 | NULLnullptr, /* function_transform */ |
4966 | NULLnullptr) /* variable_transform */ |
4967 | {} |
4968 | |
4969 | /* opt_pass methods: */ |
4970 | unsigned int execute (function *) final override { return 0; } |
4971 | |
4972 | }; // class pass_ipa_fn_summary |
4973 | |
4974 | } // anon namespace |
4975 | |
4976 | ipa_opt_pass_d * |
4977 | make_pass_ipa_fn_summary (gcc::context *ctxt) |
4978 | { |
4979 | return new pass_ipa_fn_summary (ctxt); |
4980 | } |
4981 | |
4982 | /* Reset all state within ipa-fnsummary.cc so that we can rerun the compiler |
4983 | within the same process. For use by toplev::finalize. */ |
4984 | |
4985 | void |
4986 | ipa_fnsummary_cc_finalize (void) |
4987 | { |
4988 | ipa_free_fn_summary (); |
4989 | } |