1 /* Interprocedural constant propagation
2 Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4 Contributed by Razya Ladelsky <RAZYA@il.ibm.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* Interprocedural constant propagation. The aim of interprocedural constant
23 propagation (IPCP) is to find which function's argument has the same
24 constant value in each invocation throughout the whole program. For example,
25 consider the following program:
29 printf ("value is %d",y);
49 The IPCP algorithm will find that g's formal argument y is always called
52 The algorithm used is based on "Interprocedural Constant Propagation", by
53 Challahan David, Keith D Cooper, Ken Kennedy, Linda Torczon, Comp86, pg
56 The optimization is divided into three stages:
58 First stage - intraprocedural analysis
59 =======================================
60 This phase computes jump_function and modification flags.
62 A jump function for a callsite represents the values passed as an actual
63 arguments of a given callsite. There are three types of values:
64 Pass through - the caller's formal parameter is passed as an actual argument.
65 Constant - a constant is passed as an actual argument.
66 Unknown - neither of the above.
68 The jump function info, ipa_jump_func, is stored in ipa_edge_args
69 structure (defined in ipa_prop.h and pointed to by cgraph_node->aux)
70 modified_flags are defined in ipa_node_params structure
71 (defined in ipa_prop.h and pointed to by cgraph_edge->aux).
73 -ipcp_generate_summary() is the first stage driver.
75 Second stage - interprocedural analysis
76 ========================================
77 This phase does the interprocedural constant propagation.
78 It computes lattices for all formal parameters in the program
79 and their value that may be:
81 BOTTOM - non constant.
82 CONSTANT - constant value.
84 Lattice describing a formal parameter p will have a constant value if all
85 callsites invoking this function have the same constant value passed to p.
87 The lattices are stored in ipcp_lattice which is itself in ipa_node_params
88 structure (defined in ipa_prop.h and pointed to by cgraph_edge->aux).
90 -ipcp_iterate_stage() is the second stage driver.
92 Third phase - transformation of function code
93 ============================================
94 Propagates the constant-valued formals into the function.
95 For each function whose parameters are constants, we create its clone.
97 Then we process the clone in two ways:
98 1. We insert an assignment statement 'parameter = const' at the beginning
99 of the cloned function.
100 2. For read-only parameters that do not live in memory, we replace all their
101 uses with the constant.
103 We also need to modify some callsites to call the cloned functions instead
104 of the original ones. For a callsite passing an argument found to be a
105 constant by IPCP, there are two different cases to handle:
106 1. A constant is passed as an argument. In this case the callsite in the
107 should be redirected to call the cloned callee.
108 2. A parameter (of the caller) passed as an argument (pass through
109 argument). In such cases both the caller and the callee have clones and
110 only the callsite in the cloned caller is redirected to call to the
113 This update is done in two steps: First all cloned functions are created
114 during a traversal of the call graph, during which all callsites are
115 redirected to call the cloned function. Then the callsites are traversed
116 and many calls redirected back to fit the description above.
118 -ipcp_insert_stage() is the third phase driver.
121 This pass also performs devirtualization - turns virtual calls into direct
122 ones if it can prove that all invocations of the function call the same
123 callee. This is achieved by building a list of all base types (actually,
124 their BINFOs) that individual parameters can have in an iterative matter
125 just like propagating scalar constants and then examining whether virtual
126 calls which take a parameter as their object fold to the same target for all
127 these types. If we cannot enumerate all types or there is a type which does
128 not have any BINFO associated with it, cannot_devirtualize of the associated
129 parameter descriptor is set which is an equivalent of BOTTOM lattice value
130 in standard IPA constant propagation.
135 #include "coretypes.h"
140 #include "ipa-prop.h"
141 #include "tree-flow.h"
142 #include "tree-pass.h"
145 #include "diagnostic.h"
146 #include "tree-pretty-print.h"
147 #include "tree-dump.h"
148 #include "tree-inline.h"
152 /* Number of functions identified as candidates for cloning. When not cloning
153 we can simplify iterate stage not forcing it to go through the decision
154 on what is profitable and what not. */
155 static int n_cloning_candidates
;
157 /* Maximal count found in program. */
158 static gcov_type max_count
;
160 /* Cgraph nodes that has been completely replaced by cloning during iterate
161 * stage and will be removed after ipcp is finished. */
162 static bitmap dead_nodes
;
164 static void ipcp_print_profile_data (FILE *);
165 static void ipcp_function_scale_print (FILE *);
167 /* Get the original node field of ipa_node_params associated with node NODE. */
168 static inline struct cgraph_node
*
169 ipcp_get_orig_node (struct cgraph_node
*node
)
171 return IPA_NODE_REF (node
)->ipcp_orig_node
;
174 /* Return true if NODE describes a cloned/versioned function. */
176 ipcp_node_is_clone (struct cgraph_node
*node
)
178 return (ipcp_get_orig_node (node
) != NULL
);
181 /* Create ipa_node_params and its data structures for NEW_NODE. Set ORIG_NODE
182 as the ipcp_orig_node field in ipa_node_params. */
184 ipcp_init_cloned_node (struct cgraph_node
*orig_node
,
185 struct cgraph_node
*new_node
)
187 gcc_checking_assert (ipa_node_params_vector
188 && (VEC_length (ipa_node_params_t
,
189 ipa_node_params_vector
)
190 > (unsigned) cgraph_max_uid
));
191 gcc_checking_assert (IPA_NODE_REF (new_node
)->params
);
192 IPA_NODE_REF (new_node
)->ipcp_orig_node
= orig_node
;
195 /* Return scale for NODE. */
196 static inline gcov_type
197 ipcp_get_node_scale (struct cgraph_node
*node
)
199 return IPA_NODE_REF (node
)->count_scale
;
202 /* Set COUNT as scale for NODE. */
204 ipcp_set_node_scale (struct cgraph_node
*node
, gcov_type count
)
206 IPA_NODE_REF (node
)->count_scale
= count
;
209 /* Return whether LAT is a constant lattice. */
211 ipcp_lat_is_const (struct ipcp_lattice
*lat
)
213 if (lat
->type
== IPA_CONST_VALUE
)
219 /* Return whether LAT is a constant lattice that ipa-cp can actually insert
220 into the code (i.e. constants excluding member pointers and pointers). */
222 ipcp_lat_is_insertable (struct ipcp_lattice
*lat
)
224 return lat
->type
== IPA_CONST_VALUE
;
227 /* Return true if LAT1 and LAT2 are equal. */
229 ipcp_lats_are_equal (struct ipcp_lattice
*lat1
, struct ipcp_lattice
*lat2
)
231 gcc_assert (ipcp_lat_is_const (lat1
) && ipcp_lat_is_const (lat2
));
232 if (lat1
->type
!= lat2
->type
)
235 if (TREE_CODE (lat1
->constant
) == ADDR_EXPR
236 && TREE_CODE (lat2
->constant
) == ADDR_EXPR
237 && TREE_CODE (TREE_OPERAND (lat1
->constant
, 0)) == CONST_DECL
238 && TREE_CODE (TREE_OPERAND (lat2
->constant
, 0)) == CONST_DECL
)
239 return operand_equal_p (DECL_INITIAL (TREE_OPERAND (lat1
->constant
, 0)),
240 DECL_INITIAL (TREE_OPERAND (lat2
->constant
, 0)), 0);
242 return operand_equal_p (lat1
->constant
, lat2
->constant
, 0);
245 /* Compute Meet arithmetics:
246 Meet (IPA_BOTTOM, x) = IPA_BOTTOM
248 Meet (const_a,const_b) = IPA_BOTTOM, if const_a != const_b.
249 MEET (const_a,const_b) = const_a, if const_a == const_b.*/
251 ipa_lattice_meet (struct ipcp_lattice
*res
, struct ipcp_lattice
*lat1
,
252 struct ipcp_lattice
*lat2
)
254 if (lat1
->type
== IPA_BOTTOM
|| lat2
->type
== IPA_BOTTOM
)
256 res
->type
= IPA_BOTTOM
;
259 if (lat1
->type
== IPA_TOP
)
261 res
->type
= lat2
->type
;
262 res
->constant
= lat2
->constant
;
265 if (lat2
->type
== IPA_TOP
)
267 res
->type
= lat1
->type
;
268 res
->constant
= lat1
->constant
;
271 if (!ipcp_lats_are_equal (lat1
, lat2
))
273 res
->type
= IPA_BOTTOM
;
276 res
->type
= lat1
->type
;
277 res
->constant
= lat1
->constant
;
280 /* Return the lattice corresponding to the Ith formal parameter of the function
281 described by INFO. */
282 static inline struct ipcp_lattice
*
283 ipcp_get_lattice (struct ipa_node_params
*info
, int i
)
285 return &(info
->params
[i
].ipcp_lattice
);
288 /* Given the jump function JFUNC, compute the lattice LAT that describes the
289 value coming down the callsite. INFO describes the caller node so that
290 pass-through jump functions can be evaluated. */
292 ipcp_lattice_from_jfunc (struct ipa_node_params
*info
, struct ipcp_lattice
*lat
,
293 struct ipa_jump_func
*jfunc
)
295 if (jfunc
->type
== IPA_JF_CONST
)
297 lat
->type
= IPA_CONST_VALUE
;
298 lat
->constant
= jfunc
->value
.constant
;
300 else if (jfunc
->type
== IPA_JF_PASS_THROUGH
)
302 struct ipcp_lattice
*caller_lat
;
305 caller_lat
= ipcp_get_lattice (info
, jfunc
->value
.pass_through
.formal_id
);
306 lat
->type
= caller_lat
->type
;
307 if (caller_lat
->type
!= IPA_CONST_VALUE
)
309 cst
= caller_lat
->constant
;
311 if (jfunc
->value
.pass_through
.operation
!= NOP_EXPR
)
314 if (TREE_CODE_CLASS (jfunc
->value
.pass_through
.operation
)
316 restype
= boolean_type_node
;
318 restype
= TREE_TYPE (cst
);
319 cst
= fold_binary (jfunc
->value
.pass_through
.operation
,
320 restype
, cst
, jfunc
->value
.pass_through
.operand
);
322 if (!cst
|| !is_gimple_ip_invariant (cst
))
323 lat
->type
= IPA_BOTTOM
;
326 else if (jfunc
->type
== IPA_JF_ANCESTOR
)
328 struct ipcp_lattice
*caller_lat
;
332 caller_lat
= ipcp_get_lattice (info
, jfunc
->value
.ancestor
.formal_id
);
333 lat
->type
= caller_lat
->type
;
334 if (caller_lat
->type
!= IPA_CONST_VALUE
)
336 if (TREE_CODE (caller_lat
->constant
) != ADDR_EXPR
)
338 /* This can happen when the constant is a NULL pointer. */
339 lat
->type
= IPA_BOTTOM
;
342 t
= TREE_OPERAND (caller_lat
->constant
, 0);
343 ok
= build_ref_for_offset (&t
, TREE_TYPE (t
),
344 jfunc
->value
.ancestor
.offset
,
345 jfunc
->value
.ancestor
.type
, false);
348 lat
->type
= IPA_BOTTOM
;
349 lat
->constant
= NULL_TREE
;
352 lat
->constant
= build_fold_addr_expr (t
);
355 lat
->type
= IPA_BOTTOM
;
358 /* True when OLD_LAT and NEW_LAT values are not the same. */
361 ipcp_lattice_changed (struct ipcp_lattice
*old_lat
,
362 struct ipcp_lattice
*new_lat
)
364 if (old_lat
->type
== new_lat
->type
)
366 if (!ipcp_lat_is_const (old_lat
))
368 if (ipcp_lats_are_equal (old_lat
, new_lat
))
374 /* Print all ipcp_lattices of all functions to F. */
376 ipcp_print_all_lattices (FILE * f
)
378 struct cgraph_node
*node
;
381 fprintf (f
, "\nLattice:\n");
382 for (node
= cgraph_nodes
; node
; node
= node
->next
)
384 struct ipa_node_params
*info
;
388 info
= IPA_NODE_REF (node
);
389 fprintf (f
, " Node: %s:\n", cgraph_node_name (node
));
390 count
= ipa_get_param_count (info
);
391 for (i
= 0; i
< count
; i
++)
393 struct ipcp_lattice
*lat
= ipcp_get_lattice (info
, i
);
395 fprintf (f
, " param [%d]: ", i
);
396 if (lat
->type
== IPA_CONST_VALUE
)
398 tree cst
= lat
->constant
;
399 fprintf (f
, "type is CONST ");
400 print_generic_expr (f
, cst
, 0);
401 if (TREE_CODE (cst
) == ADDR_EXPR
402 && TREE_CODE (TREE_OPERAND (cst
, 0)) == CONST_DECL
)
405 print_generic_expr (f
, DECL_INITIAL (TREE_OPERAND (cst
, 0)),
409 else if (lat
->type
== IPA_TOP
)
410 fprintf (f
, "type is TOP");
412 fprintf (f
, "type is BOTTOM");
413 if (ipa_param_cannot_devirtualize_p (info
, i
))
414 fprintf (f
, " - cannot_devirtualize set\n");
415 else if (ipa_param_types_vec_empty (info
, i
))
416 fprintf (f
, " - type list empty\n");
423 /* Return true if ipcp algorithms would allow cloning NODE. */
426 ipcp_versionable_function_p (struct cgraph_node
*node
)
428 struct cgraph_edge
*edge
;
430 /* There are a number of generic reasons functions cannot be versioned. We
431 also cannot remove parameters if there are type attributes such as fnspec
433 if (!node
->local
.versionable
434 || TYPE_ATTRIBUTES (TREE_TYPE (node
->decl
)))
437 /* Removing arguments doesn't work if the function takes varargs
438 or use __builtin_apply_args. */
439 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
441 tree t
= edge
->callee
->decl
;
442 if (DECL_BUILT_IN_CLASS (t
) == BUILT_IN_NORMAL
443 && (DECL_FUNCTION_CODE (t
) == BUILT_IN_APPLY_ARGS
444 || DECL_FUNCTION_CODE (t
) == BUILT_IN_VA_START
))
451 /* Return true if this NODE is viable candidate for cloning. */
453 ipcp_cloning_candidate_p (struct cgraph_node
*node
)
457 gcov_type direct_call_sum
= 0;
458 struct cgraph_edge
*e
;
460 /* We never clone functions that are not visible from outside.
461 FIXME: in future we should clone such functions when they are called with
462 different constants, but current ipcp implementation is not good on this.
464 if (cgraph_only_called_directly_p (node
) || !node
->analyzed
)
467 if (cgraph_function_body_availability (node
) <= AVAIL_OVERWRITABLE
)
470 fprintf (dump_file
, "Not considering %s for cloning; body is overwrittable.\n",
471 cgraph_node_name (node
));
474 if (!ipcp_versionable_function_p (node
))
477 fprintf (dump_file
, "Not considering %s for cloning; body is not versionable.\n",
478 cgraph_node_name (node
));
481 for (e
= node
->callers
; e
; e
= e
->next_caller
)
483 direct_call_sum
+= e
->count
;
485 if (cgraph_maybe_hot_edge_p (e
))
492 fprintf (dump_file
, "Not considering %s for cloning; no direct calls.\n",
493 cgraph_node_name (node
));
496 if (node
->local
.inline_summary
.self_size
< n_calls
)
499 fprintf (dump_file
, "Considering %s for cloning; code would shrink.\n",
500 cgraph_node_name (node
));
504 if (!flag_ipa_cp_clone
)
507 fprintf (dump_file
, "Not considering %s for cloning; -fipa-cp-clone disabled.\n",
508 cgraph_node_name (node
));
512 if (!optimize_function_for_speed_p (DECL_STRUCT_FUNCTION (node
->decl
)))
515 fprintf (dump_file
, "Not considering %s for cloning; optimizing it for size.\n",
516 cgraph_node_name (node
));
520 /* When profile is available and function is hot, propagate into it even if
521 calls seems cold; constant propagation can improve function's speed
525 if (direct_call_sum
> node
->count
* 90 / 100)
528 fprintf (dump_file
, "Considering %s for cloning; usually called directly.\n",
529 cgraph_node_name (node
));
536 fprintf (dump_file
, "Not considering %s for cloning; no hot calls.\n",
537 cgraph_node_name (node
));
541 fprintf (dump_file
, "Considering %s for cloning.\n",
542 cgraph_node_name (node
));
546 /* Mark parameter with index I of function described by INFO as unsuitable for
547 devirtualization. Return true if it has already been marked so. */
550 ipa_set_param_cannot_devirtualize (struct ipa_node_params
*info
, int i
)
552 bool ret
= info
->params
[i
].cannot_devirtualize
;
553 info
->params
[i
].cannot_devirtualize
= true;
554 if (info
->params
[i
].types
)
555 VEC_free (tree
, heap
, info
->params
[i
].types
);
559 /* Initialize ipcp_lattices array. The lattices corresponding to supported
560 types (integers, real types and Fortran constants defined as const_decls)
561 are initialized to IPA_TOP, the rest of them to IPA_BOTTOM. */
563 ipcp_initialize_node_lattices (struct cgraph_node
*node
)
566 struct ipa_node_params
*info
= IPA_NODE_REF (node
);
567 enum ipa_lattice_type type
;
569 if (ipa_is_called_with_var_arguments (info
))
571 else if (cgraph_only_called_directly_p (node
))
573 /* When cloning is allowed, we can assume that externally visible functions
574 are not called. We will compensate this by cloning later. */
575 else if (ipcp_cloning_candidate_p (node
))
576 type
= IPA_TOP
, n_cloning_candidates
++;
580 for (i
= 0; i
< ipa_get_param_count (info
) ; i
++)
582 ipcp_get_lattice (info
, i
)->type
= type
;
583 if (type
== IPA_BOTTOM
)
584 ipa_set_param_cannot_devirtualize (info
, i
);
588 /* build INTEGER_CST tree with type TREE_TYPE and value according to LAT.
591 build_const_val (struct ipcp_lattice
*lat
, tree tree_type
)
595 gcc_assert (ipcp_lat_is_const (lat
));
598 if (!useless_type_conversion_p (tree_type
, TREE_TYPE (val
)))
600 if (fold_convertible_p (tree_type
, val
))
601 return fold_build1 (NOP_EXPR
, tree_type
, val
);
603 return fold_build1 (VIEW_CONVERT_EXPR
, tree_type
, val
);
608 /* Compute the proper scale for NODE. It is the ratio between the number of
609 direct calls (represented on the incoming cgraph_edges) and sum of all
610 invocations of NODE (represented as count in cgraph_node).
612 FIXME: This code is wrong. Since the callers can be also clones and
613 the clones are not scaled yet, the sums gets unrealistically high.
614 To properly compute the counts, we would need to do propagation across
615 callgraph (as external call to A might imply call to non-clonned B
616 if A's clone calls clonned B). */
618 ipcp_compute_node_scale (struct cgraph_node
*node
)
621 struct cgraph_edge
*cs
;
624 /* Compute sum of all counts of callers. */
625 for (cs
= node
->callers
; cs
!= NULL
; cs
= cs
->next_caller
)
627 /* Work around the unrealistically high sum problem. We just don't want
628 the non-cloned body to have negative or very low frequency. Since
629 majority of execution time will be spent in clones anyway, this should
630 give good enough profile. */
631 if (sum
> node
->count
* 9 / 10)
632 sum
= node
->count
* 9 / 10;
633 if (node
->count
== 0)
634 ipcp_set_node_scale (node
, 0);
636 ipcp_set_node_scale (node
, sum
* REG_BR_PROB_BASE
/ node
->count
);
639 /* Return true if there are some formal parameters whose value is IPA_TOP (in
640 the whole compilation unit). Change their values to IPA_BOTTOM, since they
641 most probably get their values from outside of this compilation unit. */
643 ipcp_change_tops_to_bottom (void)
646 struct cgraph_node
*node
;
650 for (node
= cgraph_nodes
; node
; node
= node
->next
)
652 struct ipa_node_params
*info
= IPA_NODE_REF (node
);
653 count
= ipa_get_param_count (info
);
654 for (i
= 0; i
< count
; i
++)
656 struct ipcp_lattice
*lat
= ipcp_get_lattice (info
, i
);
657 if (lat
->type
== IPA_TOP
)
662 fprintf (dump_file
, "Forcing param ");
663 print_generic_expr (dump_file
, ipa_get_param (info
, i
), 0);
664 fprintf (dump_file
, " of node %s to bottom.\n",
665 cgraph_node_name (node
));
667 lat
->type
= IPA_BOTTOM
;
669 if (!ipa_param_cannot_devirtualize_p (info
, i
)
670 && ipa_param_types_vec_empty (info
, i
))
673 ipa_set_param_cannot_devirtualize (info
, i
);
676 fprintf (dump_file
, "Marking param ");
677 print_generic_expr (dump_file
, ipa_get_param (info
, i
), 0);
678 fprintf (dump_file
, " of node %s as unusable for "
679 "devirtualization.\n",
680 cgraph_node_name (node
));
688 /* Insert BINFO to the list of known types of parameter number I of the
689 function described by CALLEE_INFO. Return true iff the type information
690 associated with the callee parameter changed in any way. */
693 ipcp_add_param_type (struct ipa_node_params
*callee_info
, int i
, tree binfo
)
697 if (ipa_param_cannot_devirtualize_p (callee_info
, i
))
700 if (callee_info
->params
[i
].types
)
702 count
= VEC_length (tree
, callee_info
->params
[i
].types
);
703 for (j
= 0; j
< count
; j
++)
704 if (VEC_index (tree
, callee_info
->params
[i
].types
, j
) == binfo
)
708 if (VEC_length (tree
, callee_info
->params
[i
].types
)
709 == (unsigned) PARAM_VALUE (PARAM_DEVIRT_TYPE_LIST_SIZE
))
710 return !ipa_set_param_cannot_devirtualize (callee_info
, i
);
712 VEC_safe_push (tree
, heap
, callee_info
->params
[i
].types
, binfo
);
716 /* Copy known types information for parameter number CALLEE_IDX of CALLEE_INFO
717 from a parameter of CALLER_INFO as described by JF. Return true iff the
718 type information changed in any way. JF must be a pass-through or an
719 ancestor jump function. */
722 ipcp_copy_types (struct ipa_node_params
*caller_info
,
723 struct ipa_node_params
*callee_info
,
724 int callee_idx
, struct ipa_jump_func
*jf
)
726 int caller_idx
, j
, count
;
729 if (ipa_param_cannot_devirtualize_p (callee_info
, callee_idx
))
732 if (jf
->type
== IPA_JF_PASS_THROUGH
)
734 if (jf
->value
.pass_through
.operation
!= NOP_EXPR
)
736 ipa_set_param_cannot_devirtualize (callee_info
, callee_idx
);
739 caller_idx
= jf
->value
.pass_through
.formal_id
;
742 caller_idx
= jf
->value
.ancestor
.formal_id
;
744 if (ipa_param_cannot_devirtualize_p (caller_info
, caller_idx
))
746 ipa_set_param_cannot_devirtualize (callee_info
, callee_idx
);
750 if (!caller_info
->params
[caller_idx
].types
)
754 count
= VEC_length (tree
, caller_info
->params
[caller_idx
].types
);
755 for (j
= 0; j
< count
; j
++)
757 tree binfo
= VEC_index (tree
, caller_info
->params
[caller_idx
].types
, j
);
758 if (jf
->type
== IPA_JF_ANCESTOR
)
760 binfo
= get_binfo_at_offset (binfo
, jf
->value
.ancestor
.offset
,
761 jf
->value
.ancestor
.type
);
764 ipa_set_param_cannot_devirtualize (callee_info
, callee_idx
);
768 res
|= ipcp_add_param_type (callee_info
, callee_idx
, binfo
);
773 /* Propagate type information for parameter of CALLEE_INFO number I as
774 described by JF. CALLER_INFO describes the caller. Return true iff the
775 type information changed in any way. */
778 ipcp_propagate_types (struct ipa_node_params
*caller_info
,
779 struct ipa_node_params
*callee_info
,
780 struct ipa_jump_func
*jf
, int i
)
787 case IPA_JF_CONST_MEMBER_PTR
:
790 case IPA_JF_KNOWN_TYPE
:
791 return ipcp_add_param_type (callee_info
, i
, jf
->value
.base_binfo
);
794 cst
= jf
->value
.constant
;
795 if (TREE_CODE (cst
) != ADDR_EXPR
)
797 binfo
= gimple_get_relevant_ref_binfo (TREE_OPERAND (cst
, 0), NULL_TREE
);
800 return ipcp_add_param_type (callee_info
, i
, binfo
);
802 case IPA_JF_PASS_THROUGH
:
803 case IPA_JF_ANCESTOR
:
804 return ipcp_copy_types (caller_info
, callee_info
, i
, jf
);
807 /* If we reach this we cannot use this parameter for devirtualization. */
808 return !ipa_set_param_cannot_devirtualize (callee_info
, i
);
811 /* Interprocedural analysis. The algorithm propagates constants from the
812 caller's parameters to the callee's arguments. */
814 ipcp_propagate_stage (void)
817 struct ipcp_lattice inc_lat
= { IPA_BOTTOM
, NULL
};
818 struct ipcp_lattice new_lat
= { IPA_BOTTOM
, NULL
};
819 struct ipcp_lattice
*dest_lat
;
820 struct cgraph_edge
*cs
;
821 struct ipa_jump_func
*jump_func
;
822 struct ipa_func_list
*wl
;
825 ipa_check_create_node_params ();
826 ipa_check_create_edge_args ();
828 /* Initialize worklist to contain all functions. */
829 wl
= ipa_init_func_list ();
832 struct cgraph_node
*node
= ipa_pop_func_from_list (&wl
);
833 struct ipa_node_params
*info
= IPA_NODE_REF (node
);
835 for (cs
= node
->callees
; cs
; cs
= cs
->next_callee
)
837 struct ipa_node_params
*callee_info
= IPA_NODE_REF (cs
->callee
);
838 struct ipa_edge_args
*args
= IPA_EDGE_REF (cs
);
840 if (ipa_is_called_with_var_arguments (callee_info
)
841 || !cs
->callee
->analyzed
842 || ipa_is_called_with_var_arguments (callee_info
))
845 count
= ipa_get_cs_argument_count (args
);
846 for (i
= 0; i
< count
; i
++)
848 jump_func
= ipa_get_ith_jump_func (args
, i
);
849 ipcp_lattice_from_jfunc (info
, &inc_lat
, jump_func
);
850 dest_lat
= ipcp_get_lattice (callee_info
, i
);
851 ipa_lattice_meet (&new_lat
, &inc_lat
, dest_lat
);
852 if (ipcp_lattice_changed (&new_lat
, dest_lat
))
854 dest_lat
->type
= new_lat
.type
;
855 dest_lat
->constant
= new_lat
.constant
;
856 ipa_push_func_to_list (&wl
, cs
->callee
);
859 if (ipcp_propagate_types (info
, callee_info
, jump_func
, i
))
860 ipa_push_func_to_list (&wl
, cs
->callee
);
866 /* Call the constant propagation algorithm and re-call it if necessary
867 (if there are undetermined values left). */
869 ipcp_iterate_stage (void)
871 struct cgraph_node
*node
;
872 n_cloning_candidates
= 0;
875 fprintf (dump_file
, "\nIPA iterate stage:\n\n");
878 ipa_update_after_lto_read ();
880 for (node
= cgraph_nodes
; node
; node
= node
->next
)
882 ipcp_initialize_node_lattices (node
);
883 ipcp_compute_node_scale (node
);
885 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
887 ipcp_print_all_lattices (dump_file
);
888 ipcp_function_scale_print (dump_file
);
891 ipcp_propagate_stage ();
892 if (ipcp_change_tops_to_bottom ())
893 /* Some lattices have changed from IPA_TOP to IPA_BOTTOM.
894 This change should be propagated. */
896 gcc_assert (n_cloning_candidates
);
897 ipcp_propagate_stage ();
901 fprintf (dump_file
, "\nIPA lattices after propagation:\n");
902 ipcp_print_all_lattices (dump_file
);
903 if (dump_flags
& TDF_DETAILS
)
904 ipcp_print_profile_data (dump_file
);
908 /* Check conditions to forbid constant insertion to function described by
911 ipcp_node_modifiable_p (struct cgraph_node
*node
)
913 /* Once we will be able to do in-place replacement, we can be more
915 return ipcp_versionable_function_p (node
);
918 /* Print count scale data structures. */
920 ipcp_function_scale_print (FILE * f
)
922 struct cgraph_node
*node
;
924 for (node
= cgraph_nodes
; node
; node
= node
->next
)
928 fprintf (f
, "printing scale for %s: ", cgraph_node_name (node
));
929 fprintf (f
, "value is " HOST_WIDE_INT_PRINT_DEC
930 " \n", (HOST_WIDE_INT
) ipcp_get_node_scale (node
));
934 /* Print counts of all cgraph nodes. */
936 ipcp_print_func_profile_counts (FILE * f
)
938 struct cgraph_node
*node
;
940 for (node
= cgraph_nodes
; node
; node
= node
->next
)
942 fprintf (f
, "function %s: ", cgraph_node_name (node
));
943 fprintf (f
, "count is " HOST_WIDE_INT_PRINT_DEC
944 " \n", (HOST_WIDE_INT
) node
->count
);
948 /* Print counts of all cgraph edges. */
950 ipcp_print_call_profile_counts (FILE * f
)
952 struct cgraph_node
*node
;
953 struct cgraph_edge
*cs
;
955 for (node
= cgraph_nodes
; node
; node
= node
->next
)
957 for (cs
= node
->callees
; cs
; cs
= cs
->next_callee
)
959 fprintf (f
, "%s -> %s ", cgraph_node_name (cs
->caller
),
960 cgraph_node_name (cs
->callee
));
961 fprintf (f
, "count is " HOST_WIDE_INT_PRINT_DEC
" \n",
962 (HOST_WIDE_INT
) cs
->count
);
967 /* Print profile info for all functions. */
969 ipcp_print_profile_data (FILE * f
)
971 fprintf (f
, "\nNODE COUNTS :\n");
972 ipcp_print_func_profile_counts (f
);
973 fprintf (f
, "\nCS COUNTS stage:\n");
974 ipcp_print_call_profile_counts (f
);
977 /* Build and initialize ipa_replace_map struct according to LAT. This struct is
978 processed by versioning, which operates according to the flags set.
979 PARM_TREE is the formal parameter found to be constant. LAT represents the
981 static struct ipa_replace_map
*
982 ipcp_create_replace_map (tree parm_tree
, struct ipcp_lattice
*lat
)
984 struct ipa_replace_map
*replace_map
;
987 replace_map
= ggc_alloc_ipa_replace_map ();
988 const_val
= build_const_val (lat
, TREE_TYPE (parm_tree
));
991 fprintf (dump_file
, " replacing param ");
992 print_generic_expr (dump_file
, parm_tree
, 0);
993 fprintf (dump_file
, " with const ");
994 print_generic_expr (dump_file
, const_val
, 0);
995 fprintf (dump_file
, "\n");
997 replace_map
->old_tree
= parm_tree
;
998 replace_map
->new_tree
= const_val
;
999 replace_map
->replace_p
= true;
1000 replace_map
->ref_p
= false;
1005 /* Return true if this callsite should be redirected to the original callee
1006 (instead of the cloned one). */
1008 ipcp_need_redirect_p (struct cgraph_edge
*cs
)
1010 struct ipa_node_params
*orig_callee_info
;
1012 struct cgraph_node
*node
= cs
->callee
, *orig
;
1014 if (!n_cloning_candidates
)
1017 if ((orig
= ipcp_get_orig_node (node
)) != NULL
)
1019 if (ipcp_get_orig_node (cs
->caller
))
1022 orig_callee_info
= IPA_NODE_REF (node
);
1023 count
= ipa_get_param_count (orig_callee_info
);
1024 for (i
= 0; i
< count
; i
++)
1026 struct ipcp_lattice
*lat
= ipcp_get_lattice (orig_callee_info
, i
);
1027 struct ipa_jump_func
*jump_func
;
1029 jump_func
= ipa_get_ith_jump_func (IPA_EDGE_REF (cs
), i
);
1030 if ((ipcp_lat_is_const (lat
)
1031 && jump_func
->type
!= IPA_JF_CONST
)
1032 || (!ipa_param_cannot_devirtualize_p (orig_callee_info
, i
)
1033 && !ipa_param_types_vec_empty (orig_callee_info
, i
)
1034 && jump_func
->type
!= IPA_JF_CONST
1035 && jump_func
->type
!= IPA_JF_KNOWN_TYPE
))
1042 /* Fix the callsites and the call graph after function cloning was done. */
1044 ipcp_update_callgraph (void)
1046 struct cgraph_node
*node
;
1048 for (node
= cgraph_nodes
; node
; node
= node
->next
)
1049 if (node
->analyzed
&& ipcp_node_is_clone (node
))
1051 bitmap args_to_skip
= BITMAP_ALLOC (NULL
);
1052 struct cgraph_node
*orig_node
= ipcp_get_orig_node (node
);
1053 struct ipa_node_params
*info
= IPA_NODE_REF (orig_node
);
1054 int i
, count
= ipa_get_param_count (info
);
1055 struct cgraph_edge
*cs
, *next
;
1057 for (i
= 0; i
< count
; i
++)
1059 struct ipcp_lattice
*lat
= ipcp_get_lattice (info
, i
);
1061 /* We can proactively remove obviously unused arguments. */
1062 if (!ipa_is_param_used (info
, i
))
1064 bitmap_set_bit (args_to_skip
, i
);
1068 if (lat
->type
== IPA_CONST_VALUE
)
1069 bitmap_set_bit (args_to_skip
, i
);
1071 for (cs
= node
->callers
; cs
; cs
= next
)
1073 next
= cs
->next_caller
;
1074 if (!ipcp_node_is_clone (cs
->caller
) && ipcp_need_redirect_p (cs
))
1077 fprintf (dump_file
, "Redirecting edge %s/%i -> %s/%i "
1079 cgraph_node_name (cs
->caller
), cs
->caller
->uid
,
1080 cgraph_node_name (cs
->callee
), cs
->callee
->uid
,
1081 cgraph_node_name (orig_node
), orig_node
->uid
);
1082 cgraph_redirect_edge_callee (cs
, orig_node
);
1088 /* Update profiling info for versioned functions and the functions they were
1091 ipcp_update_profiling (void)
1093 struct cgraph_node
*node
, *orig_node
;
1094 gcov_type scale
, scale_complement
;
1095 struct cgraph_edge
*cs
;
1097 for (node
= cgraph_nodes
; node
; node
= node
->next
)
1099 if (ipcp_node_is_clone (node
))
1101 orig_node
= ipcp_get_orig_node (node
);
1102 scale
= ipcp_get_node_scale (orig_node
);
1103 node
->count
= orig_node
->count
* scale
/ REG_BR_PROB_BASE
;
1104 scale_complement
= REG_BR_PROB_BASE
- scale
;
1106 orig_node
->count
* scale_complement
/ REG_BR_PROB_BASE
;
1107 for (cs
= node
->callees
; cs
; cs
= cs
->next_callee
)
1108 cs
->count
= cs
->count
* scale
/ REG_BR_PROB_BASE
;
1109 for (cs
= orig_node
->callees
; cs
; cs
= cs
->next_callee
)
1110 cs
->count
= cs
->count
* scale_complement
/ REG_BR_PROB_BASE
;
1115 /* If NODE was cloned, how much would program grow? */
1117 ipcp_estimate_growth (struct cgraph_node
*node
)
1119 struct cgraph_edge
*cs
;
1120 int redirectable_node_callers
= 0;
1121 int removable_args
= 0;
1123 = !cgraph_will_be_removed_from_program_if_no_direct_calls (node
);
1124 struct ipa_node_params
*info
;
1128 for (cs
= node
->callers
; cs
!= NULL
; cs
= cs
->next_caller
)
1129 if (cs
->caller
== node
|| !ipcp_need_redirect_p (cs
))
1130 redirectable_node_callers
++;
1132 need_original
= true;
1134 /* If we will be able to fully replace orignal node, we never increase
1139 info
= IPA_NODE_REF (node
);
1140 count
= ipa_get_param_count (info
);
1141 for (i
= 0; i
< count
; i
++)
1143 struct ipcp_lattice
*lat
= ipcp_get_lattice (info
, i
);
1145 /* We can proactively remove obviously unused arguments. */
1146 if (!ipa_is_param_used (info
, i
))
1149 if (lat
->type
== IPA_CONST_VALUE
)
1153 /* We make just very simple estimate of savings for removal of operand from
1154 call site. Precise cost is dificult to get, as our size metric counts
1155 constants and moves as free. Generally we are looking for cases that
1156 small function is called very many times. */
1157 growth
= node
->local
.inline_summary
.self_size
1158 - removable_args
* redirectable_node_callers
;
1165 /* Estimate cost of cloning NODE. */
1167 ipcp_estimate_cloning_cost (struct cgraph_node
*node
)
1170 gcov_type count_sum
= 1;
1171 struct cgraph_edge
*e
;
1174 cost
= ipcp_estimate_growth (node
) * 1000;
1178 fprintf (dump_file
, "Versioning of %s will save code size\n",
1179 cgraph_node_name (node
));
1183 for (e
= node
->callers
; e
; e
= e
->next_caller
)
1184 if (!bitmap_bit_p (dead_nodes
, e
->caller
->uid
)
1185 && !ipcp_need_redirect_p (e
))
1187 count_sum
+= e
->count
;
1188 freq_sum
+= e
->frequency
+ 1;
1192 cost
/= count_sum
* 1000 / max_count
+ 1;
1194 cost
/= freq_sum
* 1000 / REG_BR_PROB_BASE
+ 1;
1196 fprintf (dump_file
, "Cost of versioning %s is %i, (size: %i, freq: %i)\n",
1197 cgraph_node_name (node
), cost
, node
->local
.inline_summary
.self_size
,
1202 /* Walk indirect calls of NODE and if any polymorphic can be turned into a
1203 direct one now, do so. */
1206 ipcp_process_devirtualization_opportunities (struct cgraph_node
*node
)
1208 struct ipa_node_params
*info
= IPA_NODE_REF (node
);
1209 struct cgraph_edge
*ie
, *next_ie
;
1211 for (ie
= node
->indirect_calls
; ie
; ie
= next_ie
)
1213 int param_index
, types_count
, j
;
1214 HOST_WIDE_INT token
;
1217 next_ie
= ie
->next_callee
;
1218 if (!ie
->indirect_info
->polymorphic
)
1220 param_index
= ie
->indirect_info
->param_index
;
1221 if (param_index
== -1
1222 || ipa_param_cannot_devirtualize_p (info
, param_index
)
1223 || ipa_param_types_vec_empty (info
, param_index
))
1226 token
= ie
->indirect_info
->otr_token
;
1228 types_count
= VEC_length (tree
, info
->params
[param_index
].types
);
1229 for (j
= 0; j
< types_count
; j
++)
1231 tree binfo
= VEC_index (tree
, info
->params
[param_index
].types
, j
);
1232 tree t
= gimple_fold_obj_type_ref_known_binfo (token
, binfo
);
1241 else if (target
!= t
)
1249 ipa_make_edge_direct_to_target (ie
, target
);
1253 /* Return number of live constant parameters. */
1255 ipcp_const_param_count (struct cgraph_node
*node
)
1257 int const_param
= 0;
1258 struct ipa_node_params
*info
= IPA_NODE_REF (node
);
1259 int count
= ipa_get_param_count (info
);
1262 for (i
= 0; i
< count
; i
++)
1264 struct ipcp_lattice
*lat
= ipcp_get_lattice (info
, i
);
1265 if ((ipcp_lat_is_insertable (lat
)
1266 /* Do not count obviously unused arguments. */
1267 && ipa_is_param_used (info
, i
))
1268 || (!ipa_param_cannot_devirtualize_p (info
, i
)
1269 && !ipa_param_types_vec_empty (info
, i
)))
1275 /* Given that a formal parameter of NODE given by INDEX is known to be constant
1276 CST, try to find any indirect edges that can be made direct and make them
1277 so. Note that INDEX is the number the parameter at the time of analyzing
1278 parameter uses and parameter removals should not be considered for it. (In
1279 fact, the parameter itself has just been removed.) */
1282 ipcp_discover_new_direct_edges (struct cgraph_node
*node
, int index
, tree cst
)
1284 struct cgraph_edge
*ie
, *next_ie
;
1286 for (ie
= node
->indirect_calls
; ie
; ie
= next_ie
)
1288 struct cgraph_indirect_call_info
*ici
= ie
->indirect_info
;
1290 next_ie
= ie
->next_callee
;
1291 if (ici
->param_index
!= index
)
1294 if (ici
->polymorphic
)
1297 HOST_WIDE_INT token
;
1299 if (TREE_CODE (cst
) != ADDR_EXPR
)
1302 binfo
= gimple_get_relevant_ref_binfo (TREE_OPERAND (cst
, 0),
1306 gcc_assert (ie
->indirect_info
->anc_offset
== 0);
1307 token
= ie
->indirect_info
->otr_token
;
1308 cst
= gimple_fold_obj_type_ref_known_binfo (token
, binfo
);
1313 ipa_make_edge_direct_to_target (ie
, cst
);
1318 /* Propagate the constant parameters found by ipcp_iterate_stage()
1319 to the function's code. */
1321 ipcp_insert_stage (void)
1323 struct cgraph_node
*node
, *node1
= NULL
;
1325 VEC (cgraph_edge_p
, heap
) * redirect_callers
;
1326 VEC (ipa_replace_map_p
,gc
)* replace_trees
;
1327 int node_callers
, count
;
1329 struct ipa_replace_map
*replace_param
;
1331 long overall_size
= 0, new_size
= 0;
1334 ipa_check_create_node_params ();
1335 ipa_check_create_edge_args ();
1337 fprintf (dump_file
, "\nIPA insert stage:\n\n");
1339 dead_nodes
= BITMAP_ALLOC (NULL
);
1341 for (node
= cgraph_nodes
; node
; node
= node
->next
)
1344 if (node
->count
> max_count
)
1345 max_count
= node
->count
;
1346 overall_size
+= node
->local
.inline_summary
.self_size
;
1349 max_new_size
= overall_size
;
1350 if (max_new_size
< PARAM_VALUE (PARAM_LARGE_UNIT_INSNS
))
1351 max_new_size
= PARAM_VALUE (PARAM_LARGE_UNIT_INSNS
);
1352 max_new_size
= max_new_size
* PARAM_VALUE (PARAM_IPCP_UNIT_GROWTH
) / 100 + 1;
1354 /* First collect all functions we proved to have constant arguments to
1356 heap
= fibheap_new ();
1357 for (node
= cgraph_nodes
; node
; node
= node
->next
)
1359 struct ipa_node_params
*info
;
1360 /* Propagation of the constant is forbidden in certain conditions. */
1361 if (!node
->analyzed
|| !ipcp_node_modifiable_p (node
))
1363 info
= IPA_NODE_REF (node
);
1364 if (ipa_is_called_with_var_arguments (info
))
1366 if (ipcp_const_param_count (node
))
1367 node
->aux
= fibheap_insert (heap
, ipcp_estimate_cloning_cost (node
),
1371 /* Now clone in priority order until code size growth limits are met or
1373 while (!fibheap_empty (heap
))
1375 struct ipa_node_params
*info
;
1377 bitmap args_to_skip
;
1378 struct cgraph_edge
*cs
;
1380 node
= (struct cgraph_node
*)fibheap_extract_min (heap
);
1383 fprintf (dump_file
, "considering function %s\n",
1384 cgraph_node_name (node
));
1386 growth
= ipcp_estimate_growth (node
);
1388 if (new_size
+ growth
> max_new_size
)
1391 && optimize_function_for_size_p (DECL_STRUCT_FUNCTION (node
->decl
)))
1394 fprintf (dump_file
, "Not versioning, cold code would grow");
1400 /* Look if original function becomes dead after clonning. */
1401 for (cs
= node
->callers
; cs
!= NULL
; cs
= cs
->next_caller
)
1402 if (cs
->caller
== node
|| ipcp_need_redirect_p (cs
))
1404 if (!cs
&& cgraph_will_be_removed_from_program_if_no_direct_calls (node
))
1405 bitmap_set_bit (dead_nodes
, node
->uid
);
1407 info
= IPA_NODE_REF (node
);
1408 count
= ipa_get_param_count (info
);
1410 replace_trees
= VEC_alloc (ipa_replace_map_p
, gc
, 1);
1411 args_to_skip
= BITMAP_GGC_ALLOC ();
1412 for (i
= 0; i
< count
; i
++)
1414 struct ipcp_lattice
*lat
= ipcp_get_lattice (info
, i
);
1415 parm_tree
= ipa_get_param (info
, i
);
1417 /* We can proactively remove obviously unused arguments. */
1418 if (!ipa_is_param_used (info
, i
))
1420 bitmap_set_bit (args_to_skip
, i
);
1424 if (lat
->type
== IPA_CONST_VALUE
)
1427 ipcp_create_replace_map (parm_tree
, lat
);
1428 VEC_safe_push (ipa_replace_map_p
, gc
, replace_trees
, replace_param
);
1429 bitmap_set_bit (args_to_skip
, i
);
1433 /* Compute how many callers node has. */
1435 for (cs
= node
->callers
; cs
!= NULL
; cs
= cs
->next_caller
)
1437 redirect_callers
= VEC_alloc (cgraph_edge_p
, heap
, node_callers
);
1438 for (cs
= node
->callers
; cs
!= NULL
; cs
= cs
->next_caller
)
1439 if (!cs
->indirect_inlining_edge
)
1440 VEC_quick_push (cgraph_edge_p
, redirect_callers
, cs
);
1442 /* Redirecting all the callers of the node to the
1443 new versioned node. */
1445 cgraph_create_virtual_clone (node
, redirect_callers
, replace_trees
,
1446 args_to_skip
, "constprop");
1447 args_to_skip
= NULL
;
1448 VEC_free (cgraph_edge_p
, heap
, redirect_callers
);
1449 replace_trees
= NULL
;
1453 ipcp_process_devirtualization_opportunities (node1
);
1456 fprintf (dump_file
, "versioned function %s with growth %i, overall %i\n",
1457 cgraph_node_name (node
), (int)growth
, (int)new_size
);
1458 ipcp_init_cloned_node (node
, node1
);
1460 info
= IPA_NODE_REF (node
);
1461 for (i
= 0; i
< count
; i
++)
1463 struct ipcp_lattice
*lat
= ipcp_get_lattice (info
, i
);
1464 if (lat
->type
== IPA_CONST_VALUE
)
1465 ipcp_discover_new_direct_edges (node1
, i
, lat
->constant
);
1469 dump_function_to_file (node1
->decl
, dump_file
, dump_flags
);
1471 for (cs
= node
->callees
; cs
; cs
= cs
->next_callee
)
1472 if (cs
->callee
->aux
)
1474 fibheap_delete_node (heap
, (fibnode_t
) cs
->callee
->aux
);
1475 cs
->callee
->aux
= fibheap_insert (heap
,
1476 ipcp_estimate_cloning_cost (cs
->callee
),
1481 while (!fibheap_empty (heap
))
1484 fprintf (dump_file
, "skipping function %s\n",
1485 cgraph_node_name (node
));
1486 node
= (struct cgraph_node
*) fibheap_extract_min (heap
);
1489 fibheap_delete (heap
);
1490 BITMAP_FREE (dead_nodes
);
1491 ipcp_update_callgraph ();
1492 ipcp_update_profiling ();
1495 /* The IPCP driver. */
1499 cgraph_remove_unreachable_nodes (true,dump_file
);
1502 fprintf (dump_file
, "\nIPA structures before propagation:\n");
1503 if (dump_flags
& TDF_DETAILS
)
1504 ipa_print_all_params (dump_file
);
1505 ipa_print_all_jump_functions (dump_file
);
1507 /* 2. Do the interprocedural propagation. */
1508 ipcp_iterate_stage ();
1509 /* 3. Insert the constants found to the functions. */
1510 ipcp_insert_stage ();
1511 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1513 fprintf (dump_file
, "\nProfiling info after insert stage:\n");
1514 ipcp_print_profile_data (dump_file
);
1516 /* Free all IPCP structures. */
1517 ipa_free_all_structures_after_ipa_cp ();
1519 fprintf (dump_file
, "\nIPA constant propagation end\n");
1523 /* Initialization and computation of IPCP data structures. This is the initial
1524 intraprocedural analysis of functions, which gathers information to be
1525 propagated later on. */
1528 ipcp_generate_summary (void)
1530 struct cgraph_node
*node
;
1533 fprintf (dump_file
, "\nIPA constant propagation start:\n");
1534 ipa_check_create_node_params ();
1535 ipa_check_create_edge_args ();
1536 ipa_register_cgraph_hooks ();
1538 for (node
= cgraph_nodes
; node
; node
= node
->next
)
1541 /* Unreachable nodes should have been eliminated before ipcp. */
1542 gcc_assert (node
->needed
|| node
->reachable
);
1544 node
->local
.versionable
= tree_versionable_function_p (node
->decl
);
1545 ipa_analyze_node (node
);
1549 /* Write ipcp summary for nodes in SET. */
1551 ipcp_write_summary (cgraph_node_set set
,
1552 varpool_node_set vset ATTRIBUTE_UNUSED
)
1554 ipa_prop_write_jump_functions (set
);
1557 /* Read ipcp summary. */
1559 ipcp_read_summary (void)
1561 ipa_prop_read_jump_functions ();
1564 /* Gate for IPCP optimization. */
1566 cgraph_gate_cp (void)
1568 /* FIXME: We should remove the optimize check after we ensure we never run
1569 IPA passes when not optimizng. */
1570 return flag_ipa_cp
&& optimize
;
1573 struct ipa_opt_pass_d pass_ipa_cp
=
1578 cgraph_gate_cp
, /* gate */
1579 ipcp_driver
, /* execute */
1582 0, /* static_pass_number */
1583 TV_IPA_CONSTANT_PROP
, /* tv_id */
1584 0, /* properties_required */
1585 0, /* properties_provided */
1586 0, /* properties_destroyed */
1587 0, /* todo_flags_start */
1588 TODO_dump_cgraph
| TODO_dump_func
|
1589 TODO_remove_functions
| TODO_ggc_collect
/* todo_flags_finish */
1591 ipcp_generate_summary
, /* generate_summary */
1592 ipcp_write_summary
, /* write_summary */
1593 ipcp_read_summary
, /* read_summary */
1594 NULL
, /* write_optimization_summary */
1595 NULL
, /* read_optimization_summary */
1596 NULL
, /* stmt_fixup */
1598 NULL
, /* function_transform */
1599 NULL
, /* variable_transform */