1 /* Interprocedural analyses.
2 Copyright (C) 2005, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
5 This file is part of GCC.
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
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
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/>. */
23 #include "coretypes.h"
25 #include "langhooks.h"
30 #include "tree-flow.h"
31 #include "tree-pass.h"
32 #include "tree-inline.h"
37 #include "diagnostic.h"
38 #include "lto-streamer.h"
40 /* Vector where the parameter infos are actually stored. */
41 VEC (ipa_node_params_t, heap) *ipa_node_params_vector;
42 /* Vector where the parameter infos are actually stored. */
43 VEC (ipa_edge_args_t, gc) *ipa_edge_args_vector;
45 /* Bitmap with all UIDs of call graph edges that have been already processed
46 by indirect inlining. */
47 static bitmap iinlining_processed_edges;
49 /* Holders of ipa cgraph hooks: */
50 static struct cgraph_edge_hook_list *edge_removal_hook_holder;
51 static struct cgraph_node_hook_list *node_removal_hook_holder;
52 static struct cgraph_2edge_hook_list *edge_duplication_hook_holder;
53 static struct cgraph_2node_hook_list *node_duplication_hook_holder;
55 /* Add cgraph NODE described by INFO to the worklist WL regardless of whether
56 it is in one or not. It should almost never be used directly, as opposed to
57 ipa_push_func_to_list. */
60 ipa_push_func_to_list_1 (struct ipa_func_list **wl,
61 struct cgraph_node *node,
62 struct ipa_node_params *info)
64 struct ipa_func_list *temp;
66 info->node_enqueued = 1;
67 temp = XCNEW (struct ipa_func_list);
73 /* Initialize worklist to contain all functions. */
75 struct ipa_func_list *
76 ipa_init_func_list (void)
78 struct cgraph_node *node;
79 struct ipa_func_list * wl;
82 for (node = cgraph_nodes; node; node = node->next)
85 struct ipa_node_params *info = IPA_NODE_REF (node);
86 /* Unreachable nodes should have been eliminated before ipcp and
88 gcc_assert (node->needed || node->reachable);
89 ipa_push_func_to_list_1 (&wl, node, info);
95 /* Remove a function from the worklist WL and return it. */
98 ipa_pop_func_from_list (struct ipa_func_list **wl)
100 struct ipa_node_params *info;
101 struct ipa_func_list *first;
102 struct cgraph_node *node;
109 info = IPA_NODE_REF (node);
110 info->node_enqueued = 0;
114 /* Return index of the formal whose tree is PTREE in function which corresponds
118 ipa_get_param_decl_index (struct ipa_node_params *info, tree ptree)
122 count = ipa_get_param_count (info);
123 for (i = 0; i < count; i++)
124 if (ipa_get_param(info, i) == ptree)
130 /* Populate the param_decl field in parameter descriptors of INFO that
131 corresponds to NODE. */
134 ipa_populate_param_decls (struct cgraph_node *node,
135 struct ipa_node_params *info)
143 fnargs = DECL_ARGUMENTS (fndecl);
145 for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
147 info->params[param_num].decl = parm;
152 /* Return how many formal parameters FNDECL has. */
155 count_formal_params_1 (tree fndecl)
160 for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm))
166 /* Count number of formal parameters in NOTE. Store the result to the
167 appropriate field of INFO. */
170 ipa_count_formal_params (struct cgraph_node *node,
171 struct ipa_node_params *info)
175 param_num = count_formal_params_1 (node->decl);
176 ipa_set_param_count (info, param_num);
179 /* Initialize the ipa_node_params structure associated with NODE by counting
180 the function parameters, creating the descriptors and populating their
184 ipa_initialize_node_params (struct cgraph_node *node)
186 struct ipa_node_params *info = IPA_NODE_REF (node);
190 ipa_count_formal_params (node, info);
191 info->params = XCNEWVEC (struct ipa_param_descriptor,
192 ipa_get_param_count (info));
193 ipa_populate_param_decls (node, info);
197 /* Callback of walk_stmt_load_store_addr_ops for the visit_store and visit_addr
198 parameters. If OP is a parameter declaration, mark it as modified in the
199 info structure passed in DATA. */
202 visit_store_addr_for_mod_analysis (gimple stmt ATTRIBUTE_UNUSED,
205 struct ipa_node_params *info = (struct ipa_node_params *) data;
207 op = get_base_address (op);
209 && TREE_CODE (op) == PARM_DECL)
211 int index = ipa_get_param_decl_index (info, op);
212 gcc_assert (index >= 0);
213 info->params[index].modified = true;
214 info->params[index].used = true;
220 /* Callback of walk_stmt_load_store_addr_ops for the visit_load.
221 If OP is a parameter declaration, mark it as used in the info structure
225 visit_load_for_mod_analysis (gimple stmt ATTRIBUTE_UNUSED,
228 struct ipa_node_params *info = (struct ipa_node_params *) data;
230 op = get_base_address (op);
232 && TREE_CODE (op) == PARM_DECL)
234 int index = ipa_get_param_decl_index (info, op);
235 gcc_assert (index >= 0);
236 info->params[index].used = true;
242 /* Compute which formal parameters of function associated with NODE are locally
243 modified or their address is taken. Note that this does not apply on
244 parameters with SSA names but those can and should be analyzed
248 ipa_detect_param_modifications (struct cgraph_node *node)
250 tree decl = node->decl;
252 struct function *func;
253 gimple_stmt_iterator gsi;
254 struct ipa_node_params *info = IPA_NODE_REF (node);
257 if (ipa_get_param_count (info) == 0 || info->modification_analysis_done)
260 for (i = 0; i < ipa_get_param_count (info); i++)
262 tree parm = ipa_get_param (info, i);
263 /* For SSA regs see if parameter is used. For non-SSA we compute
264 the flag during modification analysis. */
265 if (is_gimple_reg (parm)
266 && gimple_default_def (DECL_STRUCT_FUNCTION (node->decl), parm))
267 info->params[i].used = true;
270 func = DECL_STRUCT_FUNCTION (decl);
271 FOR_EACH_BB_FN (bb, func)
273 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
274 walk_stmt_load_store_addr_ops (gsi_stmt (gsi), info,
275 visit_load_for_mod_analysis,
276 visit_store_addr_for_mod_analysis,
277 visit_store_addr_for_mod_analysis);
278 for (gsi = gsi_start (phi_nodes (bb)); !gsi_end_p (gsi); gsi_next (&gsi))
279 walk_stmt_load_store_addr_ops (gsi_stmt (gsi), info,
280 visit_load_for_mod_analysis,
281 visit_store_addr_for_mod_analysis,
282 visit_store_addr_for_mod_analysis);
285 info->modification_analysis_done = 1;
288 /* Count number of arguments callsite CS has and store it in
289 ipa_edge_args structure corresponding to this callsite. */
292 ipa_count_arguments (struct cgraph_edge *cs)
297 stmt = cs->call_stmt;
298 gcc_assert (is_gimple_call (stmt));
299 arg_num = gimple_call_num_args (stmt);
300 if (VEC_length (ipa_edge_args_t, ipa_edge_args_vector)
301 <= (unsigned) cgraph_edge_max_uid)
302 VEC_safe_grow_cleared (ipa_edge_args_t, gc,
303 ipa_edge_args_vector, cgraph_edge_max_uid + 1);
304 ipa_set_cs_argument_count (IPA_EDGE_REF (cs), arg_num);
307 /* Print the jump functions associated with call graph edge CS to file F. */
310 ipa_print_node_jump_functions_for_edge (FILE *f, struct cgraph_edge *cs)
314 count = ipa_get_cs_argument_count (IPA_EDGE_REF (cs));
315 for (i = 0; i < count; i++)
317 struct ipa_jump_func *jump_func;
318 enum jump_func_type type;
320 jump_func = ipa_get_ith_jump_func (IPA_EDGE_REF (cs), i);
321 type = jump_func->type;
323 fprintf (f, " param %d: ", i);
324 if (type == IPA_JF_UNKNOWN)
325 fprintf (f, "UNKNOWN\n");
326 else if (type == IPA_JF_KNOWN_TYPE)
328 tree binfo_type = TREE_TYPE (jump_func->value.base_binfo);
329 fprintf (f, "KNOWN TYPE, type in binfo is: ");
330 print_generic_expr (f, binfo_type, 0);
331 fprintf (f, " (%u)\n", TYPE_UID (binfo_type));
333 else if (type == IPA_JF_CONST)
335 tree val = jump_func->value.constant;
336 fprintf (f, "CONST: ");
337 print_generic_expr (f, val, 0);
338 if (TREE_CODE (val) == ADDR_EXPR
339 && TREE_CODE (TREE_OPERAND (val, 0)) == CONST_DECL)
342 print_generic_expr (f, DECL_INITIAL (TREE_OPERAND (val, 0)),
347 else if (type == IPA_JF_CONST_MEMBER_PTR)
349 fprintf (f, "CONST MEMBER PTR: ");
350 print_generic_expr (f, jump_func->value.member_cst.pfn, 0);
352 print_generic_expr (f, jump_func->value.member_cst.delta, 0);
355 else if (type == IPA_JF_PASS_THROUGH)
357 fprintf (f, "PASS THROUGH: ");
358 fprintf (f, "%d, op %s ",
359 jump_func->value.pass_through.formal_id,
361 jump_func->value.pass_through.operation]);
362 if (jump_func->value.pass_through.operation != NOP_EXPR)
363 print_generic_expr (dump_file,
364 jump_func->value.pass_through.operand, 0);
365 fprintf (dump_file, "\n");
367 else if (type == IPA_JF_ANCESTOR)
369 fprintf (f, "ANCESTOR: ");
370 fprintf (f, "%d, offset "HOST_WIDE_INT_PRINT_DEC", ",
371 jump_func->value.ancestor.formal_id,
372 jump_func->value.ancestor.offset);
373 print_generic_expr (f, jump_func->value.ancestor.type, 0);
374 fprintf (dump_file, "\n");
380 /* Print the jump functions of all arguments on all call graph edges going from
384 ipa_print_node_jump_functions (FILE *f, struct cgraph_node *node)
386 struct cgraph_edge *cs;
389 fprintf (f, " Jump functions of caller %s:\n", cgraph_node_name (node));
390 for (cs = node->callees; cs; cs = cs->next_callee)
392 if (!ipa_edge_args_info_available_for_edge_p (cs))
395 fprintf (f, " callsite %s/%i -> %s/%i : \n",
396 cgraph_node_name (node), node->uid,
397 cgraph_node_name (cs->callee), cs->callee->uid);
398 ipa_print_node_jump_functions_for_edge (f, cs);
401 for (cs = node->indirect_calls, i = 0; cs; cs = cs->next_callee, i++)
403 if (!ipa_edge_args_info_available_for_edge_p (cs))
408 fprintf (f, " indirect callsite %d for stmt ", i);
409 print_gimple_stmt (f, cs->call_stmt, 0, TDF_SLIM);
412 fprintf (f, " indirect callsite %d :\n", i);
413 ipa_print_node_jump_functions_for_edge (f, cs);
418 /* Print ipa_jump_func data structures of all nodes in the call graph to F. */
421 ipa_print_all_jump_functions (FILE *f)
423 struct cgraph_node *node;
425 fprintf (f, "\nJump functions:\n");
426 for (node = cgraph_nodes; node; node = node->next)
428 ipa_print_node_jump_functions (f, node);
432 /* Given that an actual argument is an SSA_NAME (given in NAME) and is a result
433 of an assignment statement STMT, try to find out whether NAME can be
434 described by a (possibly polynomial) pass-through jump-function or an
435 ancestor jump function and if so, write the appropriate function into
439 compute_complex_assign_jump_func (struct ipa_node_params *info,
440 struct ipa_jump_func *jfunc,
441 gimple stmt, tree name)
443 HOST_WIDE_INT offset, size, max_size;
447 op1 = gimple_assign_rhs1 (stmt);
448 op2 = gimple_assign_rhs2 (stmt);
450 if (TREE_CODE (op1) == SSA_NAME
451 && SSA_NAME_IS_DEFAULT_DEF (op1))
453 index = ipa_get_param_decl_index (info, SSA_NAME_VAR (op1));
459 if (!is_gimple_ip_invariant (op2)
460 || (TREE_CODE_CLASS (gimple_expr_code (stmt)) != tcc_comparison
461 && !useless_type_conversion_p (TREE_TYPE (name),
465 jfunc->type = IPA_JF_PASS_THROUGH;
466 jfunc->value.pass_through.formal_id = index;
467 jfunc->value.pass_through.operation = gimple_assign_rhs_code (stmt);
468 jfunc->value.pass_through.operand = op2;
470 else if (gimple_assign_unary_nop_p (stmt))
472 jfunc->type = IPA_JF_PASS_THROUGH;
473 jfunc->value.pass_through.formal_id = index;
474 jfunc->value.pass_through.operation = NOP_EXPR;
479 if (TREE_CODE (op1) != ADDR_EXPR)
482 op1 = TREE_OPERAND (op1, 0);
483 type = TREE_TYPE (op1);
484 if (TREE_CODE (type) != RECORD_TYPE)
486 op1 = get_ref_base_and_extent (op1, &offset, &size, &max_size);
487 if (TREE_CODE (op1) != INDIRECT_REF
488 /* If this is a varying address, punt. */
492 op1 = TREE_OPERAND (op1, 0);
493 if (TREE_CODE (op1) != SSA_NAME
494 || !SSA_NAME_IS_DEFAULT_DEF (op1))
497 index = ipa_get_param_decl_index (info, SSA_NAME_VAR (op1));
500 jfunc->type = IPA_JF_ANCESTOR;
501 jfunc->value.ancestor.formal_id = index;
502 jfunc->value.ancestor.offset = offset;
503 jfunc->value.ancestor.type = type;
508 /* Given that an actual argument is an SSA_NAME that is a result of a phi
509 statement PHI, try to find out whether NAME is in fact a
510 multiple-inheritance typecast from a descendant into an ancestor of a formal
511 parameter and thus can be described by an ancestor jump function and if so,
512 write the appropriate function into JFUNC.
514 Essentially we want to match the following pattern:
522 iftmp.1_3 = &obj_2(D)->D.1762;
525 # iftmp.1_1 = PHI <iftmp.1_3(3), 0B(2)>
526 D.1879_6 = middleman_1 (iftmp.1_1, i_5(D));
530 compute_complex_ancestor_jump_func (struct ipa_node_params *info,
531 struct ipa_jump_func *jfunc,
534 HOST_WIDE_INT offset, size, max_size;
536 basic_block phi_bb, assign_bb, cond_bb;
537 tree tmp, parm, expr;
540 if (gimple_phi_num_args (phi) != 2
541 || !integer_zerop (PHI_ARG_DEF (phi, 1)))
544 tmp = PHI_ARG_DEF (phi, 0);
545 if (TREE_CODE (tmp) != SSA_NAME
546 || SSA_NAME_IS_DEFAULT_DEF (tmp)
547 || !POINTER_TYPE_P (TREE_TYPE (tmp))
548 || TREE_CODE (TREE_TYPE (TREE_TYPE (tmp))) != RECORD_TYPE)
551 assign = SSA_NAME_DEF_STMT (tmp);
552 assign_bb = gimple_bb (assign);
553 if (!single_pred_p (assign_bb)
554 || !gimple_assign_single_p (assign))
556 expr = gimple_assign_rhs1 (assign);
558 if (TREE_CODE (expr) != ADDR_EXPR)
560 expr = TREE_OPERAND (expr, 0);
561 expr = get_ref_base_and_extent (expr, &offset, &size, &max_size);
563 if (TREE_CODE (expr) != INDIRECT_REF
564 /* If this is a varying address, punt. */
568 parm = TREE_OPERAND (expr, 0);
569 if (TREE_CODE (parm) != SSA_NAME
570 || !SSA_NAME_IS_DEFAULT_DEF (parm))
573 index = ipa_get_param_decl_index (info, SSA_NAME_VAR (parm));
577 cond_bb = single_pred (assign_bb);
578 cond = last_stmt (cond_bb);
580 || gimple_code (cond) != GIMPLE_COND
581 || gimple_cond_code (cond) != NE_EXPR
582 || gimple_cond_lhs (cond) != parm
583 || !integer_zerop (gimple_cond_rhs (cond)))
587 phi_bb = gimple_bb (phi);
588 for (i = 0; i < 2; i++)
590 basic_block pred = EDGE_PRED (phi_bb, i)->src;
591 if (pred != assign_bb && pred != cond_bb)
595 jfunc->type = IPA_JF_ANCESTOR;
596 jfunc->value.ancestor.formal_id = index;
597 jfunc->value.ancestor.offset = offset;
598 jfunc->value.ancestor.type = TREE_TYPE (TREE_TYPE (tmp));
601 /* Given OP whch is passed as an actual argument to a called function,
602 determine if it is possible to construct a KNOWN_TYPE jump function for it
603 and if so, create one and store it to JFUNC. */
606 compute_known_type_jump_func (tree op, struct ipa_jump_func *jfunc)
610 if (TREE_CODE (op) != ADDR_EXPR)
613 op = TREE_OPERAND (op, 0);
614 binfo = gimple_get_relevant_ref_binfo (op, NULL_TREE);
617 jfunc->type = IPA_JF_KNOWN_TYPE;
618 jfunc->value.base_binfo = binfo;
623 /* Determine the jump functions of scalar arguments. Scalar means SSA names
624 and constants of a number of selected types. INFO is the ipa_node_params
625 structure associated with the caller, FUNCTIONS is a pointer to an array of
626 jump function structures associated with CALL which is the call statement
630 compute_scalar_jump_functions (struct ipa_node_params *info,
631 struct ipa_jump_func *functions,
637 for (num = 0; num < gimple_call_num_args (call); num++)
639 arg = gimple_call_arg (call, num);
641 if (is_gimple_ip_invariant (arg))
643 functions[num].type = IPA_JF_CONST;
644 functions[num].value.constant = arg;
646 else if (TREE_CODE (arg) == SSA_NAME)
648 if (SSA_NAME_IS_DEFAULT_DEF (arg))
650 int index = ipa_get_param_decl_index (info, SSA_NAME_VAR (arg));
654 functions[num].type = IPA_JF_PASS_THROUGH;
655 functions[num].value.pass_through.formal_id = index;
656 functions[num].value.pass_through.operation = NOP_EXPR;
661 gimple stmt = SSA_NAME_DEF_STMT (arg);
662 if (is_gimple_assign (stmt))
663 compute_complex_assign_jump_func (info, &functions[num],
665 else if (gimple_code (stmt) == GIMPLE_PHI)
666 compute_complex_ancestor_jump_func (info, &functions[num],
671 compute_known_type_jump_func (arg, &functions[num]);
675 /* Inspect the given TYPE and return true iff it has the same structure (the
676 same number of fields of the same types) as a C++ member pointer. If
677 METHOD_PTR and DELTA are non-NULL, store the trees representing the
678 corresponding fields there. */
681 type_like_member_ptr_p (tree type, tree *method_ptr, tree *delta)
685 if (TREE_CODE (type) != RECORD_TYPE)
688 fld = TYPE_FIELDS (type);
689 if (!fld || !POINTER_TYPE_P (TREE_TYPE (fld))
690 || TREE_CODE (TREE_TYPE (TREE_TYPE (fld))) != METHOD_TYPE)
696 fld = TREE_CHAIN (fld);
697 if (!fld || INTEGRAL_TYPE_P (fld))
702 if (TREE_CHAIN (fld))
708 /* Go through arguments of the CALL and for every one that looks like a member
709 pointer, check whether it can be safely declared pass-through and if so,
710 mark that to the corresponding item of jump FUNCTIONS. Return true iff
711 there are non-pass-through member pointers within the arguments. INFO
712 describes formal parameters of the caller. */
715 compute_pass_through_member_ptrs (struct ipa_node_params *info,
716 struct ipa_jump_func *functions,
719 bool undecided_members = false;
723 for (num = 0; num < gimple_call_num_args (call); num++)
725 arg = gimple_call_arg (call, num);
727 if (type_like_member_ptr_p (TREE_TYPE (arg), NULL, NULL))
729 if (TREE_CODE (arg) == PARM_DECL)
731 int index = ipa_get_param_decl_index (info, arg);
733 gcc_assert (index >=0);
734 if (!ipa_is_param_modified (info, index))
736 functions[num].type = IPA_JF_PASS_THROUGH;
737 functions[num].value.pass_through.formal_id = index;
738 functions[num].value.pass_through.operation = NOP_EXPR;
741 undecided_members = true;
744 undecided_members = true;
748 return undecided_members;
751 /* Simple function filling in a member pointer constant jump function (with PFN
752 and DELTA as the constant value) into JFUNC. */
755 fill_member_ptr_cst_jump_function (struct ipa_jump_func *jfunc,
756 tree pfn, tree delta)
758 jfunc->type = IPA_JF_CONST_MEMBER_PTR;
759 jfunc->value.member_cst.pfn = pfn;
760 jfunc->value.member_cst.delta = delta;
763 /* If RHS is an SSA_NAMe and it is defined by a simple copy assign statement,
764 return the rhs of its defining statement. */
767 get_ssa_def_if_simple_copy (tree rhs)
769 while (TREE_CODE (rhs) == SSA_NAME && !SSA_NAME_IS_DEFAULT_DEF (rhs))
771 gimple def_stmt = SSA_NAME_DEF_STMT (rhs);
773 if (gimple_assign_single_p (def_stmt))
774 rhs = gimple_assign_rhs1 (def_stmt);
781 /* Traverse statements from CALL backwards, scanning whether the argument ARG
782 which is a member pointer is filled in with constant values. If it is, fill
783 the jump function JFUNC in appropriately. METHOD_FIELD and DELTA_FIELD are
784 fields of the record type of the member pointer. To give an example, we
785 look for a pattern looking like the following:
787 D.2515.__pfn ={v} printStuff;
788 D.2515.__delta ={v} 0;
789 i_1 = doprinting (D.2515); */
792 determine_cst_member_ptr (gimple call, tree arg, tree method_field,
793 tree delta_field, struct ipa_jump_func *jfunc)
795 gimple_stmt_iterator gsi;
796 tree method = NULL_TREE;
797 tree delta = NULL_TREE;
799 gsi = gsi_for_stmt (call);
802 for (; !gsi_end_p (gsi); gsi_prev (&gsi))
804 gimple stmt = gsi_stmt (gsi);
807 if (!gimple_assign_single_p (stmt))
810 lhs = gimple_assign_lhs (stmt);
811 rhs = gimple_assign_rhs1 (stmt);
813 if (TREE_CODE (lhs) != COMPONENT_REF
814 || TREE_OPERAND (lhs, 0) != arg)
817 fld = TREE_OPERAND (lhs, 1);
818 if (!method && fld == method_field)
820 rhs = get_ssa_def_if_simple_copy (rhs);
821 if (TREE_CODE (rhs) == ADDR_EXPR
822 && TREE_CODE (TREE_OPERAND (rhs, 0)) == FUNCTION_DECL
823 && TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 0))) == METHOD_TYPE)
825 method = TREE_OPERAND (rhs, 0);
828 fill_member_ptr_cst_jump_function (jfunc, rhs, delta);
836 if (!delta && fld == delta_field)
838 rhs = get_ssa_def_if_simple_copy (rhs);
839 if (TREE_CODE (rhs) == INTEGER_CST)
844 fill_member_ptr_cst_jump_function (jfunc, rhs, delta);
856 /* Go through the arguments of the CALL and for every member pointer within
857 tries determine whether it is a constant. If it is, create a corresponding
858 constant jump function in FUNCTIONS which is an array of jump functions
859 associated with the call. */
862 compute_cst_member_ptr_arguments (struct ipa_jump_func *functions,
866 tree arg, method_field, delta_field;
868 for (num = 0; num < gimple_call_num_args (call); num++)
870 arg = gimple_call_arg (call, num);
872 if (functions[num].type == IPA_JF_UNKNOWN
873 && type_like_member_ptr_p (TREE_TYPE (arg), &method_field,
875 determine_cst_member_ptr (call, arg, method_field, delta_field,
880 /* Compute jump function for all arguments of callsite CS and insert the
881 information in the jump_functions array in the ipa_edge_args corresponding
885 ipa_compute_jump_functions_for_edge (struct cgraph_edge *cs)
887 struct ipa_node_params *info = IPA_NODE_REF (cs->caller);
888 struct ipa_edge_args *arguments = IPA_EDGE_REF (cs);
891 if (ipa_get_cs_argument_count (arguments) == 0 || arguments->jump_functions)
893 arguments->jump_functions = GGC_CNEWVEC (struct ipa_jump_func,
894 ipa_get_cs_argument_count (arguments));
896 call = cs->call_stmt;
897 gcc_assert (is_gimple_call (call));
899 /* We will deal with constants and SSA scalars first: */
900 compute_scalar_jump_functions (info, arguments->jump_functions, call);
902 /* Let's check whether there are any potential member pointers and if so,
903 whether we can determine their functions as pass_through. */
904 if (!compute_pass_through_member_ptrs (info, arguments->jump_functions, call))
907 /* Finally, let's check whether we actually pass a new constant member
909 compute_cst_member_ptr_arguments (arguments->jump_functions, call);
912 /* Compute jump functions for all edges - both direct and indirect - outgoing
913 from NODE. Also count the actual arguments in the process. */
916 ipa_compute_jump_functions (struct cgraph_node *node)
918 struct cgraph_edge *cs;
920 for (cs = node->callees; cs; cs = cs->next_callee)
922 /* We do not need to bother analyzing calls to unknown
923 functions unless they may become known during lto/whopr. */
924 if (!cs->callee->analyzed && !flag_lto && !flag_whopr)
926 ipa_count_arguments (cs);
927 if (ipa_get_cs_argument_count (IPA_EDGE_REF (cs))
928 != ipa_get_param_count (IPA_NODE_REF (cs->callee)))
929 ipa_set_called_with_variable_arg (IPA_NODE_REF (cs->callee));
930 ipa_compute_jump_functions_for_edge (cs);
933 for (cs = node->indirect_calls; cs; cs = cs->next_callee)
935 ipa_count_arguments (cs);
936 ipa_compute_jump_functions_for_edge (cs);
940 /* If RHS looks like a rhs of a statement loading pfn from a member
941 pointer formal parameter, return the parameter, otherwise return
942 NULL. If USE_DELTA, then we look for a use of the delta field
943 rather than the pfn. */
946 ipa_get_member_ptr_load_param (tree rhs, bool use_delta)
952 if (TREE_CODE (rhs) != COMPONENT_REF)
955 rec = TREE_OPERAND (rhs, 0);
956 if (TREE_CODE (rec) != PARM_DECL
957 || !type_like_member_ptr_p (TREE_TYPE (rec), &ptr_field, &delta_field))
960 fld = TREE_OPERAND (rhs, 1);
961 if (use_delta ? (fld == delta_field) : (fld == ptr_field))
967 /* If STMT looks like a statement loading a value from a member pointer formal
968 parameter, this function returns that parameter. */
971 ipa_get_stmt_member_ptr_load_param (gimple stmt, bool use_delta)
975 if (!gimple_assign_single_p (stmt))
978 rhs = gimple_assign_rhs1 (stmt);
979 return ipa_get_member_ptr_load_param (rhs, use_delta);
982 /* Returns true iff T is an SSA_NAME defined by a statement. */
985 ipa_is_ssa_with_stmt_def (tree t)
987 if (TREE_CODE (t) == SSA_NAME
988 && !SSA_NAME_IS_DEFAULT_DEF (t))
994 /* Find the indirect call graph edge corresponding to STMT and add to it all
995 information necessary to describe a call to a parameter number PARAM_INDEX.
996 NODE is the caller. POLYMORPHIC should be set to true iff the call is a
1000 ipa_note_param_call (struct cgraph_node *node, int param_index, gimple stmt,
1003 struct cgraph_edge *cs;
1005 cs = cgraph_edge (node, stmt);
1006 cs->indirect_info->param_index = param_index;
1007 cs->indirect_info->anc_offset = 0;
1008 cs->indirect_info->polymorphic = polymorphic;
1011 tree otr = gimple_call_fn (stmt);
1012 tree type, token = OBJ_TYPE_REF_TOKEN (otr);
1013 cs->indirect_info->otr_token = tree_low_cst (token, 1);
1014 type = TREE_TYPE (TREE_TYPE (OBJ_TYPE_REF_OBJECT (otr)));
1015 cs->indirect_info->otr_type = type;
1019 /* Analyze the CALL and examine uses of formal parameters of the caller NODE
1020 (described by INFO). Currently it checks whether the call calls a pointer
1021 that is a formal parameter and if so, the parameter is marked with the
1022 called flag and an indirect call graph edge describing the call is created.
1023 This is very simple for ordinary pointers represented in SSA but not-so-nice
1024 when it comes to member pointers. The ugly part of this function does
1025 nothing more than trying to match the pattern of such a call. An example of
1026 such a pattern is the gimple dump below, the call is on the last line:
1029 f$__delta_5 = f.__delta;
1030 f$__pfn_24 = f.__pfn;
1031 D.2496_3 = (int) f$__pfn_24;
1032 D.2497_4 = D.2496_3 & 1;
1039 D.2500_7 = (unsigned int) f$__delta_5;
1040 D.2501_8 = &S + D.2500_7;
1041 D.2502_9 = (int (*__vtbl_ptr_type) (void) * *) D.2501_8;
1042 D.2503_10 = *D.2502_9;
1043 D.2504_12 = f$__pfn_24 + -1;
1044 D.2505_13 = (unsigned int) D.2504_12;
1045 D.2506_14 = D.2503_10 + D.2505_13;
1046 D.2507_15 = *D.2506_14;
1047 iftmp.11_16 = (String:: *) D.2507_15;
1050 # iftmp.11_1 = PHI <iftmp.11_16(3), f$__pfn_24(2)>
1051 D.2500_19 = (unsigned int) f$__delta_5;
1052 D.2508_20 = &S + D.2500_19;
1053 D.2493_21 = iftmp.11_1 (D.2508_20, 4);
1055 Such patterns are results of simple calls to a member pointer:
1057 int doprinting (int (MyString::* f)(int) const)
1059 MyString S ("somestring");
1066 ipa_analyze_indirect_call_uses (struct cgraph_node *node,
1067 struct ipa_node_params *info,
1068 gimple call, tree target)
1073 tree rec, rec2, cond;
1076 basic_block bb, virt_bb, join;
1078 if (SSA_NAME_IS_DEFAULT_DEF (target))
1080 tree var = SSA_NAME_VAR (target);
1081 index = ipa_get_param_decl_index (info, var);
1083 ipa_note_param_call (node, index, call, false);
1087 /* Now we need to try to match the complex pattern of calling a member
1090 if (!POINTER_TYPE_P (TREE_TYPE (target))
1091 || TREE_CODE (TREE_TYPE (TREE_TYPE (target))) != METHOD_TYPE)
1094 def = SSA_NAME_DEF_STMT (target);
1095 if (gimple_code (def) != GIMPLE_PHI)
1098 if (gimple_phi_num_args (def) != 2)
1101 /* First, we need to check whether one of these is a load from a member
1102 pointer that is a parameter to this function. */
1103 n1 = PHI_ARG_DEF (def, 0);
1104 n2 = PHI_ARG_DEF (def, 1);
1105 if (!ipa_is_ssa_with_stmt_def (n1) || !ipa_is_ssa_with_stmt_def (n2))
1107 d1 = SSA_NAME_DEF_STMT (n1);
1108 d2 = SSA_NAME_DEF_STMT (n2);
1110 if ((rec = ipa_get_stmt_member_ptr_load_param (d1, false)))
1112 if (ipa_get_stmt_member_ptr_load_param (d2, false))
1115 bb = gimple_bb (d1);
1116 virt_bb = gimple_bb (d2);
1118 else if ((rec = ipa_get_stmt_member_ptr_load_param (d2, false)))
1120 bb = gimple_bb (d2);
1121 virt_bb = gimple_bb (d1);
1126 /* Second, we need to check that the basic blocks are laid out in the way
1127 corresponding to the pattern. */
1129 join = gimple_bb (def);
1130 if (!single_pred_p (virt_bb) || !single_succ_p (virt_bb)
1131 || single_pred (virt_bb) != bb
1132 || single_succ (virt_bb) != join)
1135 /* Third, let's see that the branching is done depending on the least
1136 significant bit of the pfn. */
1138 branch = last_stmt (bb);
1139 if (gimple_code (branch) != GIMPLE_COND)
1142 if (gimple_cond_code (branch) != NE_EXPR
1143 || !integer_zerop (gimple_cond_rhs (branch)))
1146 cond = gimple_cond_lhs (branch);
1147 if (!ipa_is_ssa_with_stmt_def (cond))
1150 def = SSA_NAME_DEF_STMT (cond);
1151 if (!is_gimple_assign (def)
1152 || gimple_assign_rhs_code (def) != BIT_AND_EXPR
1153 || !integer_onep (gimple_assign_rhs2 (def)))
1156 cond = gimple_assign_rhs1 (def);
1157 if (!ipa_is_ssa_with_stmt_def (cond))
1160 def = SSA_NAME_DEF_STMT (cond);
1162 if (is_gimple_assign (def)
1163 && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def)))
1165 cond = gimple_assign_rhs1 (def);
1166 if (!ipa_is_ssa_with_stmt_def (cond))
1168 def = SSA_NAME_DEF_STMT (cond);
1171 rec2 = ipa_get_stmt_member_ptr_load_param (def,
1172 (TARGET_PTRMEMFUNC_VBIT_LOCATION
1173 == ptrmemfunc_vbit_in_delta));
1178 index = ipa_get_param_decl_index (info, rec);
1179 if (index >= 0 && !ipa_is_param_modified (info, index))
1180 ipa_note_param_call (node, index, call, false);
1185 /* Analyze a CALL to an OBJ_TYPE_REF which is passed in TARGET and if the
1186 object referenced in the expression is a formal parameter of the caller
1187 (described by INFO), create a call note for the statement. */
1190 ipa_analyze_virtual_call_uses (struct cgraph_node *node,
1191 struct ipa_node_params *info, gimple call,
1194 tree obj = OBJ_TYPE_REF_OBJECT (target);
1198 if (TREE_CODE (obj) == ADDR_EXPR)
1202 obj = TREE_OPERAND (obj, 0);
1204 while (TREE_CODE (obj) == COMPONENT_REF);
1205 if (TREE_CODE (obj) != INDIRECT_REF)
1207 obj = TREE_OPERAND (obj, 0);
1210 if (TREE_CODE (obj) != SSA_NAME
1211 || !SSA_NAME_IS_DEFAULT_DEF (obj))
1214 var = SSA_NAME_VAR (obj);
1215 index = ipa_get_param_decl_index (info, var);
1218 ipa_note_param_call (node, index, call, true);
1221 /* Analyze a call statement CALL whether and how it utilizes formal parameters
1222 of the caller (described by INFO). */
1225 ipa_analyze_call_uses (struct cgraph_node *node,
1226 struct ipa_node_params *info, gimple call)
1228 tree target = gimple_call_fn (call);
1230 if (TREE_CODE (target) == SSA_NAME)
1231 ipa_analyze_indirect_call_uses (node, info, call, target);
1232 else if (TREE_CODE (target) == OBJ_TYPE_REF)
1233 ipa_analyze_virtual_call_uses (node, info, call, target);
1237 /* Analyze the call statement STMT with respect to formal parameters (described
1238 in INFO) of caller given by NODE. Currently it only checks whether formal
1239 parameters are called. */
1242 ipa_analyze_stmt_uses (struct cgraph_node *node, struct ipa_node_params *info,
1245 if (is_gimple_call (stmt))
1246 ipa_analyze_call_uses (node, info, stmt);
1249 /* Scan the function body of NODE and inspect the uses of formal parameters.
1250 Store the findings in various structures of the associated ipa_node_params
1251 structure, such as parameter flags, notes etc. */
1254 ipa_analyze_params_uses (struct cgraph_node *node)
1256 tree decl = node->decl;
1258 struct function *func;
1259 gimple_stmt_iterator gsi;
1260 struct ipa_node_params *info = IPA_NODE_REF (node);
1262 if (ipa_get_param_count (info) == 0 || info->uses_analysis_done)
1265 func = DECL_STRUCT_FUNCTION (decl);
1266 FOR_EACH_BB_FN (bb, func)
1268 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1270 gimple stmt = gsi_stmt (gsi);
1271 ipa_analyze_stmt_uses (node, info, stmt);
1275 info->uses_analysis_done = 1;
1278 /* Update the jump function DST when the call graph edge correspondng to SRC is
1279 is being inlined, knowing that DST is of type ancestor and src of known
1283 combine_known_type_and_ancestor_jfs (struct ipa_jump_func *src,
1284 struct ipa_jump_func *dst)
1288 new_binfo = get_binfo_at_offset (src->value.base_binfo,
1289 dst->value.ancestor.offset,
1290 dst->value.ancestor.type);
1293 dst->type = IPA_JF_KNOWN_TYPE;
1294 dst->value.base_binfo = new_binfo;
1297 dst->type = IPA_JF_UNKNOWN;
1300 /* Update the jump functions associated with call graph edge E when the call
1301 graph edge CS is being inlined, assuming that E->caller is already (possibly
1302 indirectly) inlined into CS->callee and that E has not been inlined. */
1305 update_jump_functions_after_inlining (struct cgraph_edge *cs,
1306 struct cgraph_edge *e)
1308 struct ipa_edge_args *top = IPA_EDGE_REF (cs);
1309 struct ipa_edge_args *args = IPA_EDGE_REF (e);
1310 int count = ipa_get_cs_argument_count (args);
1313 for (i = 0; i < count; i++)
1315 struct ipa_jump_func *dst = ipa_get_ith_jump_func (args, i);
1317 if (dst->type == IPA_JF_ANCESTOR)
1319 struct ipa_jump_func *src;
1321 /* Variable number of arguments can cause havoc if we try to access
1322 one that does not exist in the inlined edge. So make sure we
1324 if (dst->value.ancestor.formal_id >= ipa_get_cs_argument_count (top))
1326 dst->type = IPA_JF_UNKNOWN;
1330 src = ipa_get_ith_jump_func (top, dst->value.ancestor.formal_id);
1331 if (src->type == IPA_JF_KNOWN_TYPE)
1332 combine_known_type_and_ancestor_jfs (src, dst);
1333 else if (src->type == IPA_JF_CONST)
1335 struct ipa_jump_func kt_func;
1337 kt_func.type = IPA_JF_UNKNOWN;
1338 compute_known_type_jump_func (src->value.constant, &kt_func);
1339 if (kt_func.type == IPA_JF_KNOWN_TYPE)
1340 combine_known_type_and_ancestor_jfs (&kt_func, dst);
1342 dst->type = IPA_JF_UNKNOWN;
1344 else if (src->type == IPA_JF_PASS_THROUGH
1345 && src->value.pass_through.operation == NOP_EXPR)
1346 dst->value.ancestor.formal_id = src->value.pass_through.formal_id;
1347 else if (src->type == IPA_JF_ANCESTOR)
1349 dst->value.ancestor.formal_id = src->value.ancestor.formal_id;
1350 dst->value.ancestor.offset += src->value.ancestor.offset;
1353 dst->type = IPA_JF_UNKNOWN;
1355 else if (dst->type == IPA_JF_PASS_THROUGH)
1357 struct ipa_jump_func *src;
1358 /* We must check range due to calls with variable number of arguments
1359 and we cannot combine jump functions with operations. */
1360 if (dst->value.pass_through.operation == NOP_EXPR
1361 && (dst->value.pass_through.formal_id
1362 < ipa_get_cs_argument_count (top)))
1364 src = ipa_get_ith_jump_func (top,
1365 dst->value.pass_through.formal_id);
1369 dst->type = IPA_JF_UNKNOWN;
1374 /* If TARGET is an addr_expr of a function declaration, make it the destination
1375 of an indirect edge IE and return the edge. Otherwise, return NULL. */
1377 static struct cgraph_edge *
1378 make_edge_direct_to_target (struct cgraph_edge *ie, tree target)
1380 struct cgraph_node *callee;
1382 if (TREE_CODE (target) != ADDR_EXPR)
1384 target = TREE_OPERAND (target, 0);
1385 if (TREE_CODE (target) != FUNCTION_DECL)
1387 callee = cgraph_node (target);
1391 cgraph_make_edge_direct (ie, callee);
1394 fprintf (dump_file, "ipa-prop: Discovered %s call to a known target "
1395 "(%s/%i -> %s/%i) for stmt ",
1396 ie->indirect_info->polymorphic ? "a virtual" : "an indirect",
1397 cgraph_node_name (ie->caller), ie->caller->uid,
1398 cgraph_node_name (ie->callee), ie->callee->uid);
1401 print_gimple_stmt (dump_file, ie->call_stmt, 2, TDF_SLIM);
1403 fprintf (dump_file, "with uid %i\n", ie->lto_stmt_uid);
1406 if (ipa_get_cs_argument_count (IPA_EDGE_REF (ie))
1407 != ipa_get_param_count (IPA_NODE_REF (callee)))
1408 ipa_set_called_with_variable_arg (IPA_NODE_REF (callee));
1413 /* Try to find a destination for indirect edge IE that corresponds to a simple
1414 call or a call of a member function pointer and where the destination is a
1415 pointer formal parameter described by jump function JFUNC. If it can be
1416 determined, return the newly direct edge, otherwise return NULL. */
1418 static struct cgraph_edge *
1419 try_make_edge_direct_simple_call (struct cgraph_edge *ie,
1420 struct ipa_jump_func *jfunc)
1424 if (jfunc->type == IPA_JF_CONST)
1425 target = jfunc->value.constant;
1426 else if (jfunc->type == IPA_JF_CONST_MEMBER_PTR)
1427 target = jfunc->value.member_cst.pfn;
1431 return make_edge_direct_to_target (ie, target);
1434 /* Try to find a destination for indirect edge IE that corresponds to a
1435 virtuall call based on a formal parameter which is described by jump
1436 function JFUNC and if it can be determined, make it direct and return the
1437 direct edge. Otherwise, return NULL. */
1439 static struct cgraph_edge *
1440 try_make_edge_direct_virtual_call (struct cgraph_edge *ie,
1441 struct ipa_jump_func *jfunc)
1443 tree binfo, type, target;
1444 HOST_WIDE_INT token;
1446 if (jfunc->type == IPA_JF_KNOWN_TYPE)
1447 binfo = jfunc->value.base_binfo;
1448 else if (jfunc->type == IPA_JF_CONST)
1450 tree cst = jfunc->value.constant;
1451 if (TREE_CODE (cst) == ADDR_EXPR)
1452 binfo = gimple_get_relevant_ref_binfo (TREE_OPERAND (cst, 0),
1463 token = ie->indirect_info->otr_token;
1464 type = ie->indirect_info->otr_type;
1465 binfo = get_binfo_at_offset (binfo, ie->indirect_info->anc_offset, type);
1467 target = gimple_fold_obj_type_ref_known_binfo (token, binfo);
1472 return make_edge_direct_to_target (ie, target);
1477 /* Update the param called notes associated with NODE when CS is being inlined,
1478 assuming NODE is (potentially indirectly) inlined into CS->callee.
1479 Moreover, if the callee is discovered to be constant, create a new cgraph
1480 edge for it. Newly discovered indirect edges will be added to *NEW_EDGES,
1481 unless NEW_EDGES is NULL. Return true iff a new edge(s) were created. */
1484 update_indirect_edges_after_inlining (struct cgraph_edge *cs,
1485 struct cgraph_node *node,
1486 VEC (cgraph_edge_p, heap) **new_edges)
1488 struct ipa_edge_args *top = IPA_EDGE_REF (cs);
1489 struct cgraph_edge *ie, *next_ie, *new_direct_edge;
1492 ipa_check_create_edge_args ();
1494 for (ie = node->indirect_calls; ie; ie = next_ie)
1496 struct cgraph_indirect_call_info *ici = ie->indirect_info;
1497 struct ipa_jump_func *jfunc;
1499 next_ie = ie->next_callee;
1500 if (bitmap_bit_p (iinlining_processed_edges, ie->uid))
1503 /* If we ever use indirect edges for anything other than indirect
1504 inlining, we will need to skip those with negative param_indices. */
1505 if (ici->param_index == -1)
1508 /* We must check range due to calls with variable number of arguments: */
1509 if (ici->param_index >= ipa_get_cs_argument_count (top))
1511 bitmap_set_bit (iinlining_processed_edges, ie->uid);
1515 jfunc = ipa_get_ith_jump_func (top, ici->param_index);
1516 if (jfunc->type == IPA_JF_PASS_THROUGH
1517 && jfunc->value.pass_through.operation == NOP_EXPR)
1518 ici->param_index = jfunc->value.pass_through.formal_id;
1519 else if (jfunc->type == IPA_JF_ANCESTOR)
1521 ici->param_index = jfunc->value.ancestor.formal_id;
1522 ici->anc_offset += jfunc->value.ancestor.offset;
1525 /* Either we can find a destination for this edge now or never. */
1526 bitmap_set_bit (iinlining_processed_edges, ie->uid);
1528 if (ici->polymorphic)
1529 new_direct_edge = try_make_edge_direct_virtual_call (ie, jfunc);
1531 new_direct_edge = try_make_edge_direct_simple_call (ie, jfunc);
1533 if (new_direct_edge)
1535 new_direct_edge->indirect_inlining_edge = 1;
1538 VEC_safe_push (cgraph_edge_p, heap, *new_edges,
1540 top = IPA_EDGE_REF (cs);
1549 /* Recursively traverse subtree of NODE (including node) made of inlined
1550 cgraph_edges when CS has been inlined and invoke
1551 update_indirect_edges_after_inlining on all nodes and
1552 update_jump_functions_after_inlining on all non-inlined edges that lead out
1553 of this subtree. Newly discovered indirect edges will be added to
1554 *NEW_EDGES, unless NEW_EDGES is NULL. Return true iff a new edge(s) were
1558 propagate_info_to_inlined_callees (struct cgraph_edge *cs,
1559 struct cgraph_node *node,
1560 VEC (cgraph_edge_p, heap) **new_edges)
1562 struct cgraph_edge *e;
1565 res = update_indirect_edges_after_inlining (cs, node, new_edges);
1567 for (e = node->callees; e; e = e->next_callee)
1568 if (!e->inline_failed)
1569 res |= propagate_info_to_inlined_callees (cs, e->callee, new_edges);
1571 update_jump_functions_after_inlining (cs, e);
1576 /* Update jump functions and call note functions on inlining the call site CS.
1577 CS is expected to lead to a node already cloned by
1578 cgraph_clone_inline_nodes. Newly discovered indirect edges will be added to
1579 *NEW_EDGES, unless NEW_EDGES is NULL. Return true iff a new edge(s) were +
1583 ipa_propagate_indirect_call_infos (struct cgraph_edge *cs,
1584 VEC (cgraph_edge_p, heap) **new_edges)
1586 /* FIXME lto: We do not stream out indirect call information. */
1590 /* Do nothing if the preparation phase has not been carried out yet
1591 (i.e. during early inlining). */
1592 if (!ipa_node_params_vector)
1594 gcc_assert (ipa_edge_args_vector);
1596 return propagate_info_to_inlined_callees (cs, cs->callee, new_edges);
1599 /* Frees all dynamically allocated structures that the argument info points
1603 ipa_free_edge_args_substructures (struct ipa_edge_args *args)
1605 if (args->jump_functions)
1606 ggc_free (args->jump_functions);
1608 memset (args, 0, sizeof (*args));
1611 /* Free all ipa_edge structures. */
1614 ipa_free_all_edge_args (void)
1617 struct ipa_edge_args *args;
1620 VEC_iterate (ipa_edge_args_t, ipa_edge_args_vector, i, args);
1622 ipa_free_edge_args_substructures (args);
1624 VEC_free (ipa_edge_args_t, gc, ipa_edge_args_vector);
1625 ipa_edge_args_vector = NULL;
1628 /* Frees all dynamically allocated structures that the param info points
1632 ipa_free_node_params_substructures (struct ipa_node_params *info)
1635 free (info->params);
1637 memset (info, 0, sizeof (*info));
1640 /* Free all ipa_node_params structures. */
1643 ipa_free_all_node_params (void)
1646 struct ipa_node_params *info;
1649 VEC_iterate (ipa_node_params_t, ipa_node_params_vector, i, info);
1651 ipa_free_node_params_substructures (info);
1653 VEC_free (ipa_node_params_t, heap, ipa_node_params_vector);
1654 ipa_node_params_vector = NULL;
1657 /* Hook that is called by cgraph.c when an edge is removed. */
1660 ipa_edge_removal_hook (struct cgraph_edge *cs, void *data ATTRIBUTE_UNUSED)
1662 /* During IPA-CP updating we can be called on not-yet analyze clones. */
1663 if (VEC_length (ipa_edge_args_t, ipa_edge_args_vector)
1664 <= (unsigned)cs->uid)
1666 ipa_free_edge_args_substructures (IPA_EDGE_REF (cs));
1669 /* Hook that is called by cgraph.c when a node is removed. */
1672 ipa_node_removal_hook (struct cgraph_node *node, void *data ATTRIBUTE_UNUSED)
1674 /* During IPA-CP updating we can be called on not-yet analyze clones. */
1675 if (VEC_length (ipa_node_params_t, ipa_node_params_vector)
1676 <= (unsigned)node->uid)
1678 ipa_free_node_params_substructures (IPA_NODE_REF (node));
1681 /* Helper function to duplicate an array of size N that is at SRC and store a
1682 pointer to it to DST. Nothing is done if SRC is NULL. */
1685 duplicate_array (void *src, size_t n)
1697 /* Like duplicate_array byt in GGC memory. */
1700 duplicate_ggc_array (void *src, size_t n)
1712 /* Hook that is called by cgraph.c when a node is duplicated. */
1715 ipa_edge_duplication_hook (struct cgraph_edge *src, struct cgraph_edge *dst,
1716 __attribute__((unused)) void *data)
1718 struct ipa_edge_args *old_args, *new_args;
1721 ipa_check_create_edge_args ();
1723 old_args = IPA_EDGE_REF (src);
1724 new_args = IPA_EDGE_REF (dst);
1726 arg_count = ipa_get_cs_argument_count (old_args);
1727 ipa_set_cs_argument_count (new_args, arg_count);
1728 new_args->jump_functions = (struct ipa_jump_func *)
1729 duplicate_ggc_array (old_args->jump_functions,
1730 sizeof (struct ipa_jump_func) * arg_count);
1732 if (iinlining_processed_edges
1733 && bitmap_bit_p (iinlining_processed_edges, src->uid))
1734 bitmap_set_bit (iinlining_processed_edges, dst->uid);
1737 /* Hook that is called by cgraph.c when a node is duplicated. */
1740 ipa_node_duplication_hook (struct cgraph_node *src, struct cgraph_node *dst,
1741 __attribute__((unused)) void *data)
1743 struct ipa_node_params *old_info, *new_info;
1746 ipa_check_create_node_params ();
1747 old_info = IPA_NODE_REF (src);
1748 new_info = IPA_NODE_REF (dst);
1749 param_count = ipa_get_param_count (old_info);
1751 ipa_set_param_count (new_info, param_count);
1752 new_info->params = (struct ipa_param_descriptor *)
1753 duplicate_array (old_info->params,
1754 sizeof (struct ipa_param_descriptor) * param_count);
1755 new_info->ipcp_orig_node = old_info->ipcp_orig_node;
1756 new_info->count_scale = old_info->count_scale;
1759 /* Register our cgraph hooks if they are not already there. */
1762 ipa_register_cgraph_hooks (void)
1764 if (!edge_removal_hook_holder)
1765 edge_removal_hook_holder =
1766 cgraph_add_edge_removal_hook (&ipa_edge_removal_hook, NULL);
1767 if (!node_removal_hook_holder)
1768 node_removal_hook_holder =
1769 cgraph_add_node_removal_hook (&ipa_node_removal_hook, NULL);
1770 if (!edge_duplication_hook_holder)
1771 edge_duplication_hook_holder =
1772 cgraph_add_edge_duplication_hook (&ipa_edge_duplication_hook, NULL);
1773 if (!node_duplication_hook_holder)
1774 node_duplication_hook_holder =
1775 cgraph_add_node_duplication_hook (&ipa_node_duplication_hook, NULL);
1778 /* Unregister our cgraph hooks if they are not already there. */
1781 ipa_unregister_cgraph_hooks (void)
1783 cgraph_remove_edge_removal_hook (edge_removal_hook_holder);
1784 edge_removal_hook_holder = NULL;
1785 cgraph_remove_node_removal_hook (node_removal_hook_holder);
1786 node_removal_hook_holder = NULL;
1787 cgraph_remove_edge_duplication_hook (edge_duplication_hook_holder);
1788 edge_duplication_hook_holder = NULL;
1789 cgraph_remove_node_duplication_hook (node_duplication_hook_holder);
1790 node_duplication_hook_holder = NULL;
1793 /* Allocate all necessary data strucutures necessary for indirect inlining. */
1796 ipa_create_all_structures_for_iinln (void)
1798 iinlining_processed_edges = BITMAP_ALLOC (NULL);
1801 /* Free all ipa_node_params and all ipa_edge_args structures if they are no
1802 longer needed after ipa-cp. */
1805 ipa_free_all_structures_after_ipa_cp (void)
1807 if (!flag_indirect_inlining)
1809 ipa_free_all_edge_args ();
1810 ipa_free_all_node_params ();
1811 ipa_unregister_cgraph_hooks ();
1815 /* Free all ipa_node_params and all ipa_edge_args structures if they are no
1816 longer needed after indirect inlining. */
1819 ipa_free_all_structures_after_iinln (void)
1821 BITMAP_FREE (iinlining_processed_edges);
1823 ipa_free_all_edge_args ();
1824 ipa_free_all_node_params ();
1825 ipa_unregister_cgraph_hooks ();
1828 /* Print ipa_tree_map data structures of all functions in the
1832 ipa_print_node_params (FILE * f, struct cgraph_node *node)
1836 struct ipa_node_params *info;
1838 if (!node->analyzed)
1840 info = IPA_NODE_REF (node);
1841 fprintf (f, " function %s parameter descriptors:\n",
1842 cgraph_node_name (node));
1843 count = ipa_get_param_count (info);
1844 for (i = 0; i < count; i++)
1846 temp = ipa_get_param (info, i);
1847 if (TREE_CODE (temp) == PARM_DECL)
1848 fprintf (f, " param %d : %s", i,
1850 ? (*lang_hooks.decl_printable_name) (temp, 2)
1852 if (ipa_is_param_modified (info, i))
1853 fprintf (f, " modified");
1854 if (ipa_is_param_used (info, i))
1855 fprintf (f, " used");
1860 /* Print ipa_tree_map data structures of all functions in the
1864 ipa_print_all_params (FILE * f)
1866 struct cgraph_node *node;
1868 fprintf (f, "\nFunction parameters:\n");
1869 for (node = cgraph_nodes; node; node = node->next)
1870 ipa_print_node_params (f, node);
1873 /* Return a heap allocated vector containing formal parameters of FNDECL. */
1876 ipa_get_vector_of_formal_parms (tree fndecl)
1878 VEC(tree, heap) *args;
1882 count = count_formal_params_1 (fndecl);
1883 args = VEC_alloc (tree, heap, count);
1884 for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm))
1885 VEC_quick_push (tree, args, parm);
1890 /* Return a heap allocated vector containing types of formal parameters of
1891 function type FNTYPE. */
1893 static inline VEC(tree, heap) *
1894 get_vector_of_formal_parm_types (tree fntype)
1896 VEC(tree, heap) *types;
1900 for (t = TYPE_ARG_TYPES (fntype); t; t = TREE_CHAIN (t))
1903 types = VEC_alloc (tree, heap, count);
1904 for (t = TYPE_ARG_TYPES (fntype); t; t = TREE_CHAIN (t))
1905 VEC_quick_push (tree, types, TREE_VALUE (t));
1910 /* Modify the function declaration FNDECL and its type according to the plan in
1911 ADJUSTMENTS. It also sets base fields of individual adjustments structures
1912 to reflect the actual parameters being modified which are determined by the
1913 base_index field. */
1916 ipa_modify_formal_parameters (tree fndecl, ipa_parm_adjustment_vec adjustments,
1917 const char *synth_parm_prefix)
1919 VEC(tree, heap) *oparms, *otypes;
1920 tree orig_type, new_type = NULL;
1921 tree old_arg_types, t, new_arg_types = NULL;
1922 tree parm, *link = &DECL_ARGUMENTS (fndecl);
1923 int i, len = VEC_length (ipa_parm_adjustment_t, adjustments);
1924 tree new_reversed = NULL;
1925 bool care_for_types, last_parm_void;
1927 if (!synth_parm_prefix)
1928 synth_parm_prefix = "SYNTH";
1930 oparms = ipa_get_vector_of_formal_parms (fndecl);
1931 orig_type = TREE_TYPE (fndecl);
1932 old_arg_types = TYPE_ARG_TYPES (orig_type);
1934 /* The following test is an ugly hack, some functions simply don't have any
1935 arguments in their type. This is probably a bug but well... */
1936 care_for_types = (old_arg_types != NULL_TREE);
1939 last_parm_void = (TREE_VALUE (tree_last (old_arg_types))
1941 otypes = get_vector_of_formal_parm_types (orig_type);
1943 gcc_assert (VEC_length (tree, oparms) + 1 == VEC_length (tree, otypes));
1945 gcc_assert (VEC_length (tree, oparms) == VEC_length (tree, otypes));
1949 last_parm_void = false;
1953 for (i = 0; i < len; i++)
1955 struct ipa_parm_adjustment *adj;
1958 adj = VEC_index (ipa_parm_adjustment_t, adjustments, i);
1959 parm = VEC_index (tree, oparms, adj->base_index);
1962 if (adj->copy_param)
1965 new_arg_types = tree_cons (NULL_TREE, VEC_index (tree, otypes,
1969 link = &TREE_CHAIN (parm);
1971 else if (!adj->remove_param)
1977 ptype = build_pointer_type (adj->type);
1982 new_arg_types = tree_cons (NULL_TREE, ptype, new_arg_types);
1984 new_parm = build_decl (UNKNOWN_LOCATION, PARM_DECL, NULL_TREE,
1986 DECL_NAME (new_parm) = create_tmp_var_name (synth_parm_prefix);
1988 DECL_ARTIFICIAL (new_parm) = 1;
1989 DECL_ARG_TYPE (new_parm) = ptype;
1990 DECL_CONTEXT (new_parm) = fndecl;
1991 TREE_USED (new_parm) = 1;
1992 DECL_IGNORED_P (new_parm) = 1;
1993 layout_decl (new_parm, 0);
1995 add_referenced_var (new_parm);
1996 mark_sym_for_renaming (new_parm);
1998 adj->reduction = new_parm;
2002 link = &TREE_CHAIN (new_parm);
2010 new_reversed = nreverse (new_arg_types);
2014 TREE_CHAIN (new_arg_types) = void_list_node;
2016 new_reversed = void_list_node;
2020 /* Use copy_node to preserve as much as possible from original type
2021 (debug info, attribute lists etc.)
2022 Exception is METHOD_TYPEs must have THIS argument.
2023 When we are asked to remove it, we need to build new FUNCTION_TYPE
2025 if (TREE_CODE (orig_type) != METHOD_TYPE
2026 || (VEC_index (ipa_parm_adjustment_t, adjustments, 0)->copy_param
2027 && VEC_index (ipa_parm_adjustment_t, adjustments, 0)->base_index == 0))
2029 new_type = copy_node (orig_type);
2030 TYPE_ARG_TYPES (new_type) = new_reversed;
2035 = build_distinct_type_copy (build_function_type (TREE_TYPE (orig_type),
2037 TYPE_CONTEXT (new_type) = TYPE_CONTEXT (orig_type);
2038 DECL_VINDEX (fndecl) = NULL_TREE;
2041 /* This is a new type, not a copy of an old type. Need to reassociate
2042 variants. We can handle everything except the main variant lazily. */
2043 t = TYPE_MAIN_VARIANT (orig_type);
2046 TYPE_MAIN_VARIANT (new_type) = t;
2047 TYPE_NEXT_VARIANT (new_type) = TYPE_NEXT_VARIANT (t);
2048 TYPE_NEXT_VARIANT (t) = new_type;
2052 TYPE_MAIN_VARIANT (new_type) = new_type;
2053 TYPE_NEXT_VARIANT (new_type) = NULL;
2056 TREE_TYPE (fndecl) = new_type;
2058 VEC_free (tree, heap, otypes);
2059 VEC_free (tree, heap, oparms);
2062 /* Modify actual arguments of a function call CS as indicated in ADJUSTMENTS.
2063 If this is a directly recursive call, CS must be NULL. Otherwise it must
2064 contain the corresponding call graph edge. */
2067 ipa_modify_call_arguments (struct cgraph_edge *cs, gimple stmt,
2068 ipa_parm_adjustment_vec adjustments)
2070 VEC(tree, heap) *vargs;
2072 gimple_stmt_iterator gsi;
2076 len = VEC_length (ipa_parm_adjustment_t, adjustments);
2077 vargs = VEC_alloc (tree, heap, len);
2079 gsi = gsi_for_stmt (stmt);
2080 for (i = 0; i < len; i++)
2082 struct ipa_parm_adjustment *adj;
2084 adj = VEC_index (ipa_parm_adjustment_t, adjustments, i);
2086 if (adj->copy_param)
2088 tree arg = gimple_call_arg (stmt, adj->base_index);
2090 VEC_quick_push (tree, vargs, arg);
2092 else if (!adj->remove_param)
2094 tree expr, orig_expr;
2095 bool allow_ptr, repl_found;
2097 orig_expr = expr = gimple_call_arg (stmt, adj->base_index);
2098 if (TREE_CODE (expr) == ADDR_EXPR)
2101 expr = TREE_OPERAND (expr, 0);
2106 repl_found = build_ref_for_offset (&expr, TREE_TYPE (expr),
2107 adj->offset, adj->type,
2112 expr = build_fold_addr_expr (expr);
2116 tree ptrtype = build_pointer_type (adj->type);
2118 if (!POINTER_TYPE_P (TREE_TYPE (expr)))
2119 expr = build_fold_addr_expr (expr);
2120 if (!useless_type_conversion_p (ptrtype, TREE_TYPE (expr)))
2121 expr = fold_convert (ptrtype, expr);
2122 expr = fold_build2 (POINTER_PLUS_EXPR, ptrtype, expr,
2123 build_int_cst (sizetype,
2124 adj->offset / BITS_PER_UNIT));
2126 expr = fold_build1 (INDIRECT_REF, adj->type, expr);
2128 expr = force_gimple_operand_gsi (&gsi, expr,
2130 || is_gimple_reg_type (adj->type),
2131 NULL, true, GSI_SAME_STMT);
2132 VEC_quick_push (tree, vargs, expr);
2136 if (dump_file && (dump_flags & TDF_DETAILS))
2138 fprintf (dump_file, "replacing stmt:");
2139 print_gimple_stmt (dump_file, gsi_stmt (gsi), 0, 0);
2142 callee_decl = !cs ? gimple_call_fndecl (stmt) : cs->callee->decl;
2143 new_stmt = gimple_build_call_vec (callee_decl, vargs);
2144 VEC_free (tree, heap, vargs);
2145 if (gimple_call_lhs (stmt))
2146 gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt));
2148 gimple_set_block (new_stmt, gimple_block (stmt));
2149 if (gimple_has_location (stmt))
2150 gimple_set_location (new_stmt, gimple_location (stmt));
2151 gimple_call_copy_flags (new_stmt, stmt);
2152 gimple_call_set_chain (new_stmt, gimple_call_chain (stmt));
2154 if (dump_file && (dump_flags & TDF_DETAILS))
2156 fprintf (dump_file, "with stmt:");
2157 print_gimple_stmt (dump_file, new_stmt, 0, 0);
2158 fprintf (dump_file, "\n");
2160 gsi_replace (&gsi, new_stmt, true);
2162 cgraph_set_call_stmt (cs, new_stmt);
2163 update_ssa (TODO_update_ssa);
2164 free_dominance_info (CDI_DOMINATORS);
2167 /* Return true iff BASE_INDEX is in ADJUSTMENTS more than once. */
2170 index_in_adjustments_multiple_times_p (int base_index,
2171 ipa_parm_adjustment_vec adjustments)
2173 int i, len = VEC_length (ipa_parm_adjustment_t, adjustments);
2176 for (i = 0; i < len; i++)
2178 struct ipa_parm_adjustment *adj;
2179 adj = VEC_index (ipa_parm_adjustment_t, adjustments, i);
2181 if (adj->base_index == base_index)
2193 /* Return adjustments that should have the same effect on function parameters
2194 and call arguments as if they were first changed according to adjustments in
2195 INNER and then by adjustments in OUTER. */
2197 ipa_parm_adjustment_vec
2198 ipa_combine_adjustments (ipa_parm_adjustment_vec inner,
2199 ipa_parm_adjustment_vec outer)
2201 int i, outlen = VEC_length (ipa_parm_adjustment_t, outer);
2202 int inlen = VEC_length (ipa_parm_adjustment_t, inner);
2204 ipa_parm_adjustment_vec adjustments, tmp;
2206 tmp = VEC_alloc (ipa_parm_adjustment_t, heap, inlen);
2207 for (i = 0; i < inlen; i++)
2209 struct ipa_parm_adjustment *n;
2210 n = VEC_index (ipa_parm_adjustment_t, inner, i);
2212 if (n->remove_param)
2215 VEC_quick_push (ipa_parm_adjustment_t, tmp, n);
2218 adjustments = VEC_alloc (ipa_parm_adjustment_t, heap, outlen + removals);
2219 for (i = 0; i < outlen; i++)
2221 struct ipa_parm_adjustment *r;
2222 struct ipa_parm_adjustment *out = VEC_index (ipa_parm_adjustment_t,
2224 struct ipa_parm_adjustment *in = VEC_index (ipa_parm_adjustment_t, tmp,
2227 gcc_assert (!in->remove_param);
2228 if (out->remove_param)
2230 if (!index_in_adjustments_multiple_times_p (in->base_index, tmp))
2232 r = VEC_quick_push (ipa_parm_adjustment_t, adjustments, NULL);
2233 memset (r, 0, sizeof (*r));
2234 r->remove_param = true;
2239 r = VEC_quick_push (ipa_parm_adjustment_t, adjustments, NULL);
2240 memset (r, 0, sizeof (*r));
2241 r->base_index = in->base_index;
2242 r->type = out->type;
2244 /* FIXME: Create nonlocal value too. */
2246 if (in->copy_param && out->copy_param)
2247 r->copy_param = true;
2248 else if (in->copy_param)
2249 r->offset = out->offset;
2250 else if (out->copy_param)
2251 r->offset = in->offset;
2253 r->offset = in->offset + out->offset;
2256 for (i = 0; i < inlen; i++)
2258 struct ipa_parm_adjustment *n = VEC_index (ipa_parm_adjustment_t,
2261 if (n->remove_param)
2262 VEC_quick_push (ipa_parm_adjustment_t, adjustments, n);
2265 VEC_free (ipa_parm_adjustment_t, heap, tmp);
2269 /* Dump the adjustments in the vector ADJUSTMENTS to dump_file in a human
2270 friendly way, assuming they are meant to be applied to FNDECL. */
2273 ipa_dump_param_adjustments (FILE *file, ipa_parm_adjustment_vec adjustments,
2276 int i, len = VEC_length (ipa_parm_adjustment_t, adjustments);
2278 VEC(tree, heap) *parms = ipa_get_vector_of_formal_parms (fndecl);
2280 fprintf (file, "IPA param adjustments: ");
2281 for (i = 0; i < len; i++)
2283 struct ipa_parm_adjustment *adj;
2284 adj = VEC_index (ipa_parm_adjustment_t, adjustments, i);
2287 fprintf (file, " ");
2291 fprintf (file, "%i. base_index: %i - ", i, adj->base_index);
2292 print_generic_expr (file, VEC_index (tree, parms, adj->base_index), 0);
2295 fprintf (file, ", base: ");
2296 print_generic_expr (file, adj->base, 0);
2300 fprintf (file, ", reduction: ");
2301 print_generic_expr (file, adj->reduction, 0);
2303 if (adj->new_ssa_base)
2305 fprintf (file, ", new_ssa_base: ");
2306 print_generic_expr (file, adj->new_ssa_base, 0);
2309 if (adj->copy_param)
2310 fprintf (file, ", copy_param");
2311 else if (adj->remove_param)
2312 fprintf (file, ", remove_param");
2314 fprintf (file, ", offset %li", (long) adj->offset);
2316 fprintf (file, ", by_ref");
2317 print_node_brief (file, ", type: ", adj->type, 0);
2318 fprintf (file, "\n");
2320 VEC_free (tree, heap, parms);
2323 /* Stream out jump function JUMP_FUNC to OB. */
2326 ipa_write_jump_function (struct output_block *ob,
2327 struct ipa_jump_func *jump_func)
2329 lto_output_uleb128_stream (ob->main_stream,
2332 switch (jump_func->type)
2334 case IPA_JF_UNKNOWN:
2336 case IPA_JF_KNOWN_TYPE:
2337 lto_output_tree (ob, jump_func->value.base_binfo, true);
2340 lto_output_tree (ob, jump_func->value.constant, true);
2342 case IPA_JF_PASS_THROUGH:
2343 lto_output_tree (ob, jump_func->value.pass_through.operand, true);
2344 lto_output_uleb128_stream (ob->main_stream,
2345 jump_func->value.pass_through.formal_id);
2346 lto_output_uleb128_stream (ob->main_stream,
2347 jump_func->value.pass_through.operation);
2349 case IPA_JF_ANCESTOR:
2350 lto_output_uleb128_stream (ob->main_stream,
2351 jump_func->value.ancestor.offset);
2352 lto_output_tree (ob, jump_func->value.ancestor.type, true);
2353 lto_output_uleb128_stream (ob->main_stream,
2354 jump_func->value.ancestor.formal_id);
2356 case IPA_JF_CONST_MEMBER_PTR:
2357 lto_output_tree (ob, jump_func->value.member_cst.pfn, true);
2358 lto_output_tree (ob, jump_func->value.member_cst.delta, false);
2363 /* Read in jump function JUMP_FUNC from IB. */
2366 ipa_read_jump_function (struct lto_input_block *ib,
2367 struct ipa_jump_func *jump_func,
2368 struct data_in *data_in)
2370 jump_func->type = (enum jump_func_type) lto_input_uleb128 (ib);
2372 switch (jump_func->type)
2374 case IPA_JF_UNKNOWN:
2376 case IPA_JF_KNOWN_TYPE:
2377 jump_func->value.base_binfo = lto_input_tree (ib, data_in);
2380 jump_func->value.constant = lto_input_tree (ib, data_in);
2382 case IPA_JF_PASS_THROUGH:
2383 jump_func->value.pass_through.operand = lto_input_tree (ib, data_in);
2384 jump_func->value.pass_through.formal_id = lto_input_uleb128 (ib);
2385 jump_func->value.pass_through.operation = (enum tree_code) lto_input_uleb128 (ib);
2387 case IPA_JF_ANCESTOR:
2388 jump_func->value.ancestor.offset = lto_input_uleb128 (ib);
2389 jump_func->value.ancestor.type = lto_input_tree (ib, data_in);
2390 jump_func->value.ancestor.formal_id = lto_input_uleb128 (ib);
2392 case IPA_JF_CONST_MEMBER_PTR:
2393 jump_func->value.member_cst.pfn = lto_input_tree (ib, data_in);
2394 jump_func->value.member_cst.delta = lto_input_tree (ib, data_in);
2399 /* Stream out parts of cgraph_indirect_call_info corresponding to CS that are
2400 relevant to indirect inlining to OB. */
2403 ipa_write_indirect_edge_info (struct output_block *ob,
2404 struct cgraph_edge *cs)
2406 struct cgraph_indirect_call_info *ii = cs->indirect_info;
2407 struct bitpack_d *bp;
2409 lto_output_sleb128_stream (ob->main_stream, ii->param_index);
2410 lto_output_sleb128_stream (ob->main_stream, ii->anc_offset);
2411 bp = bitpack_create ();
2412 bp_pack_value (bp, ii->polymorphic, 1);
2413 lto_output_bitpack (ob->main_stream, bp);
2414 bitpack_delete (bp);
2416 if (ii->polymorphic)
2418 lto_output_sleb128_stream (ob->main_stream, ii->otr_token);
2419 lto_output_tree (ob, ii->otr_type, true);
2423 /* Read in parts of cgraph_indirect_call_info corresponding to CS that are
2424 relevant to indirect inlining from IB. */
2427 ipa_read_indirect_edge_info (struct lto_input_block *ib,
2428 struct data_in *data_in ATTRIBUTE_UNUSED,
2429 struct cgraph_edge *cs)
2431 struct cgraph_indirect_call_info *ii = cs->indirect_info;
2432 struct bitpack_d *bp;
2434 ii->param_index = (int) lto_input_sleb128 (ib);
2435 ii->anc_offset = (HOST_WIDE_INT) lto_input_sleb128 (ib);
2436 bp = lto_input_bitpack (ib);
2437 ii->polymorphic = bp_unpack_value (bp, 1);
2438 bitpack_delete (bp);
2439 if (ii->polymorphic)
2441 ii->otr_token = (HOST_WIDE_INT) lto_input_sleb128 (ib);
2442 ii->otr_type = lto_input_tree (ib, data_in);
2446 /* Stream out NODE info to OB. */
2449 ipa_write_node_info (struct output_block *ob, struct cgraph_node *node)
2452 lto_cgraph_encoder_t encoder;
2453 struct ipa_node_params *info = IPA_NODE_REF (node);
2455 struct cgraph_edge *e;
2456 struct bitpack_d *bp;
2458 encoder = ob->decl_state->cgraph_node_encoder;
2459 node_ref = lto_cgraph_encoder_encode (encoder, node);
2460 lto_output_uleb128_stream (ob->main_stream, node_ref);
2462 bp = bitpack_create ();
2463 bp_pack_value (bp, info->called_with_var_arguments, 1);
2464 bp_pack_value (bp, info->uses_analysis_done, 1);
2465 gcc_assert (info->modification_analysis_done
2466 || ipa_get_param_count (info) == 0);
2467 gcc_assert (!info->node_enqueued);
2468 gcc_assert (!info->ipcp_orig_node);
2469 for (j = 0; j < ipa_get_param_count (info); j++)
2471 bp_pack_value (bp, info->params[j].modified, 1);
2472 bp_pack_value (bp, info->params[j].used, 1);
2474 lto_output_bitpack (ob->main_stream, bp);
2475 bitpack_delete (bp);
2476 for (e = node->callees; e; e = e->next_callee)
2478 struct ipa_edge_args *args = IPA_EDGE_REF (e);
2480 lto_output_uleb128_stream (ob->main_stream,
2481 ipa_get_cs_argument_count (args));
2482 for (j = 0; j < ipa_get_cs_argument_count (args); j++)
2483 ipa_write_jump_function (ob, ipa_get_ith_jump_func (args, j));
2485 for (e = node->indirect_calls; e; e = e->next_callee)
2486 ipa_write_indirect_edge_info (ob, e);
2489 /* Srtream in NODE info from IB. */
2492 ipa_read_node_info (struct lto_input_block *ib, struct cgraph_node *node,
2493 struct data_in *data_in)
2495 struct ipa_node_params *info = IPA_NODE_REF (node);
2497 struct cgraph_edge *e;
2498 struct bitpack_d *bp;
2500 ipa_initialize_node_params (node);
2502 bp = lto_input_bitpack (ib);
2503 info->called_with_var_arguments = bp_unpack_value (bp, 1);
2504 info->uses_analysis_done = bp_unpack_value (bp, 1);
2505 if (ipa_get_param_count (info) != 0)
2507 info->modification_analysis_done = true;
2508 info->uses_analysis_done = true;
2510 info->node_enqueued = false;
2511 for (k = 0; k < ipa_get_param_count (info); k++)
2513 info->params[k].modified = bp_unpack_value (bp, 1);
2514 info->params[k].used = bp_unpack_value (bp, 1);
2516 bitpack_delete (bp);
2517 for (e = node->callees; e; e = e->next_callee)
2519 struct ipa_edge_args *args = IPA_EDGE_REF (e);
2520 int count = lto_input_uleb128 (ib);
2522 ipa_set_cs_argument_count (args, count);
2526 args->jump_functions = GGC_CNEWVEC (struct ipa_jump_func,
2527 ipa_get_cs_argument_count (args));
2528 for (k = 0; k < ipa_get_cs_argument_count (args); k++)
2529 ipa_read_jump_function (ib, ipa_get_ith_jump_func (args, k), data_in);
2531 for (e = node->indirect_calls; e; e = e->next_callee)
2532 ipa_read_indirect_edge_info (ib, data_in, e);
2535 /* Write jump functions for nodes in SET. */
2538 ipa_prop_write_jump_functions (cgraph_node_set set)
2540 struct cgraph_node *node;
2541 struct output_block *ob = create_output_block (LTO_section_jump_functions);
2542 unsigned int count = 0;
2543 cgraph_node_set_iterator csi;
2545 ob->cgraph_node = NULL;
2547 for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
2549 node = csi_node (csi);
2550 if (node->analyzed && IPA_NODE_REF (node) != NULL)
2554 lto_output_uleb128_stream (ob->main_stream, count);
2556 /* Process all of the functions. */
2557 for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
2559 node = csi_node (csi);
2560 if (node->analyzed && IPA_NODE_REF (node) != NULL)
2561 ipa_write_node_info (ob, node);
2563 lto_output_1_stream (ob->main_stream, 0);
2564 produce_asm (ob, NULL);
2565 destroy_output_block (ob);
2568 /* Read section in file FILE_DATA of length LEN with data DATA. */
2571 ipa_prop_read_section (struct lto_file_decl_data *file_data, const char *data,
2574 const struct lto_function_header *header =
2575 (const struct lto_function_header *) data;
2576 const int32_t cfg_offset = sizeof (struct lto_function_header);
2577 const int32_t main_offset = cfg_offset + header->cfg_size;
2578 const int32_t string_offset = main_offset + header->main_size;
2579 struct data_in *data_in;
2580 struct lto_input_block ib_main;
2584 LTO_INIT_INPUT_BLOCK (ib_main, (const char *) data + main_offset, 0,
2588 lto_data_in_create (file_data, (const char *) data + string_offset,
2589 header->string_size, NULL);
2590 count = lto_input_uleb128 (&ib_main);
2592 for (i = 0; i < count; i++)
2595 struct cgraph_node *node;
2596 lto_cgraph_encoder_t encoder;
2598 index = lto_input_uleb128 (&ib_main);
2599 encoder = file_data->cgraph_node_encoder;
2600 node = lto_cgraph_encoder_deref (encoder, index);
2601 gcc_assert (node->analyzed);
2602 ipa_read_node_info (&ib_main, node, data_in);
2604 lto_free_section_data (file_data, LTO_section_jump_functions, NULL, data,
2606 lto_data_in_delete (data_in);
2609 /* Read ipcp jump functions. */
2612 ipa_prop_read_jump_functions (void)
2614 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
2615 struct lto_file_decl_data *file_data;
2618 ipa_check_create_node_params ();
2619 ipa_check_create_edge_args ();
2620 ipa_register_cgraph_hooks ();
2622 while ((file_data = file_data_vec[j++]))
2625 const char *data = lto_get_section_data (file_data, LTO_section_jump_functions, NULL, &len);
2628 ipa_prop_read_section (file_data, data, len);
2632 /* After merging units, we can get mismatch in argument counts.
2633 Also decl merging might've rendered parameter lists obsolette.
2634 Also compute called_with_variable_arg info. */
2637 ipa_update_after_lto_read (void)
2639 struct cgraph_node *node;
2640 struct cgraph_edge *cs;
2642 ipa_check_create_node_params ();
2643 ipa_check_create_edge_args ();
2645 for (node = cgraph_nodes; node; node = node->next)
2647 ipa_initialize_node_params (node);
2649 for (node = cgraph_nodes; node; node = node->next)
2651 for (cs = node->callees; cs; cs = cs->next_callee)
2653 if (ipa_get_cs_argument_count (IPA_EDGE_REF (cs))
2654 != ipa_get_param_count (IPA_NODE_REF (cs->callee)))
2655 ipa_set_called_with_variable_arg (IPA_NODE_REF (cs->callee));