rephrase text
[official-gcc.git] / gcc / ipa-prop.c
blobc6d58b1d4526592429aea6974ea386ec1876ace5
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
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
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/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tree.h"
25 #include "langhooks.h"
26 #include "ggc.h"
27 #include "target.h"
28 #include "cgraph.h"
29 #include "ipa-prop.h"
30 #include "tree-flow.h"
31 #include "tree-pass.h"
32 #include "tree-inline.h"
33 #include "flags.h"
34 #include "timevar.h"
35 #include "flags.h"
36 #include "diagnostic.h"
37 #include "lto-streamer.h"
39 /* Vector where the parameter infos are actually stored. */
40 VEC (ipa_node_params_t, heap) *ipa_node_params_vector;
41 /* Vector where the parameter infos are actually stored. */
42 VEC (ipa_edge_args_t, gc) *ipa_edge_args_vector;
44 /* Holders of ipa cgraph hooks: */
45 static struct cgraph_edge_hook_list *edge_removal_hook_holder;
46 static struct cgraph_node_hook_list *node_removal_hook_holder;
47 static struct cgraph_2edge_hook_list *edge_duplication_hook_holder;
48 static struct cgraph_2node_hook_list *node_duplication_hook_holder;
50 /* Add cgraph NODE described by INFO to the worklist WL regardless of whether
51 it is in one or not. It should almost never be used directly, as opposed to
52 ipa_push_func_to_list. */
54 void
55 ipa_push_func_to_list_1 (struct ipa_func_list **wl,
56 struct cgraph_node *node,
57 struct ipa_node_params *info)
59 struct ipa_func_list *temp;
61 info->node_enqueued = 1;
62 temp = XCNEW (struct ipa_func_list);
63 temp->node = node;
64 temp->next = *wl;
65 *wl = temp;
68 /* Initialize worklist to contain all functions. */
70 struct ipa_func_list *
71 ipa_init_func_list (void)
73 struct cgraph_node *node;
74 struct ipa_func_list * wl;
76 wl = NULL;
77 for (node = cgraph_nodes; node; node = node->next)
78 if (node->analyzed)
80 struct ipa_node_params *info = IPA_NODE_REF (node);
81 /* Unreachable nodes should have been eliminated before ipcp and
82 inlining. */
83 gcc_assert (node->needed || node->reachable);
84 ipa_push_func_to_list_1 (&wl, node, info);
87 return wl;
90 /* Remove a function from the worklist WL and return it. */
92 struct cgraph_node *
93 ipa_pop_func_from_list (struct ipa_func_list **wl)
95 struct ipa_node_params *info;
96 struct ipa_func_list *first;
97 struct cgraph_node *node;
99 first = *wl;
100 *wl = (*wl)->next;
101 node = first->node;
102 free (first);
104 info = IPA_NODE_REF (node);
105 info->node_enqueued = 0;
106 return node;
109 /* Return index of the formal whose tree is PTREE in function which corresponds
110 to INFO. */
112 static int
113 ipa_get_param_decl_index (struct ipa_node_params *info, tree ptree)
115 int i, count;
117 count = ipa_get_param_count (info);
118 for (i = 0; i < count; i++)
119 if (ipa_get_param(info, i) == ptree)
120 return i;
122 return -1;
125 /* Populate the param_decl field in parameter descriptors of INFO that
126 corresponds to NODE. */
128 static void
129 ipa_populate_param_decls (struct cgraph_node *node,
130 struct ipa_node_params *info)
132 tree fndecl;
133 tree fnargs;
134 tree parm;
135 int param_num;
137 fndecl = node->decl;
138 fnargs = DECL_ARGUMENTS (fndecl);
139 param_num = 0;
140 for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
142 info->params[param_num].decl = parm;
143 param_num++;
147 /* Return how many formal parameters FNDECL has. */
149 static inline int
150 count_formal_params_1 (tree fndecl)
152 tree parm;
153 int count = 0;
155 for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm))
156 count++;
158 return count;
161 /* Count number of formal parameters in NOTE. Store the result to the
162 appropriate field of INFO. */
164 static void
165 ipa_count_formal_params (struct cgraph_node *node,
166 struct ipa_node_params *info)
168 int param_num;
170 param_num = count_formal_params_1 (node->decl);
171 ipa_set_param_count (info, param_num);
174 /* Initialize the ipa_node_params structure associated with NODE by counting
175 the function parameters, creating the descriptors and populating their
176 param_decls. */
178 void
179 ipa_initialize_node_params (struct cgraph_node *node)
181 struct ipa_node_params *info = IPA_NODE_REF (node);
183 if (!info->params)
185 ipa_count_formal_params (node, info);
186 info->params = XCNEWVEC (struct ipa_param_descriptor,
187 ipa_get_param_count (info));
188 ipa_populate_param_decls (node, info);
192 /* Callback of walk_stmt_load_store_addr_ops for the visit_store and visit_addr
193 parameters. If OP is a parameter declaration, mark it as modified in the
194 info structure passed in DATA. */
196 static bool
197 visit_store_addr_for_mod_analysis (gimple stmt ATTRIBUTE_UNUSED,
198 tree op, void *data)
200 struct ipa_node_params *info = (struct ipa_node_params *) data;
202 op = get_base_address (op);
203 if (op
204 && TREE_CODE (op) == PARM_DECL)
206 int index = ipa_get_param_decl_index (info, op);
207 gcc_assert (index >= 0);
208 info->params[index].modified = true;
211 return false;
214 /* Compute which formal parameters of function associated with NODE are locally
215 modified or their address is taken. Note that this does not apply on
216 parameters with SSA names but those can and should be analyzed
217 differently. */
219 void
220 ipa_detect_param_modifications (struct cgraph_node *node)
222 tree decl = node->decl;
223 basic_block bb;
224 struct function *func;
225 gimple_stmt_iterator gsi;
226 struct ipa_node_params *info = IPA_NODE_REF (node);
228 if (ipa_get_param_count (info) == 0 || info->modification_analysis_done)
229 return;
231 func = DECL_STRUCT_FUNCTION (decl);
232 FOR_EACH_BB_FN (bb, func)
233 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
234 walk_stmt_load_store_addr_ops (gsi_stmt (gsi), info, NULL,
235 visit_store_addr_for_mod_analysis,
236 visit_store_addr_for_mod_analysis);
238 info->modification_analysis_done = 1;
241 /* Count number of arguments callsite CS has and store it in
242 ipa_edge_args structure corresponding to this callsite. */
244 void
245 ipa_count_arguments (struct cgraph_edge *cs)
247 gimple stmt;
248 int arg_num;
250 stmt = cs->call_stmt;
251 gcc_assert (is_gimple_call (stmt));
252 arg_num = gimple_call_num_args (stmt);
253 if (VEC_length (ipa_edge_args_t, ipa_edge_args_vector)
254 <= (unsigned) cgraph_edge_max_uid)
255 VEC_safe_grow_cleared (ipa_edge_args_t, gc,
256 ipa_edge_args_vector, cgraph_edge_max_uid + 1);
257 ipa_set_cs_argument_count (IPA_EDGE_REF (cs), arg_num);
260 /* Print the jump functions of all arguments on all call graph edges going from
261 NODE to file F. */
263 void
264 ipa_print_node_jump_functions (FILE *f, struct cgraph_node *node)
266 int i, count;
267 struct cgraph_edge *cs;
268 struct ipa_jump_func *jump_func;
269 enum jump_func_type type;
271 fprintf (f, " Jump functions of caller %s:\n", cgraph_node_name (node));
272 for (cs = node->callees; cs; cs = cs->next_callee)
274 if (!ipa_edge_args_info_available_for_edge_p (cs))
275 continue;
277 fprintf (f, " callsite %s ", cgraph_node_name (node));
278 fprintf (f, "-> %s :: \n", cgraph_node_name (cs->callee));
280 count = ipa_get_cs_argument_count (IPA_EDGE_REF (cs));
281 for (i = 0; i < count; i++)
283 jump_func = ipa_get_ith_jump_func (IPA_EDGE_REF (cs), i);
284 type = jump_func->type;
286 fprintf (f, " param %d: ", i);
287 if (type == IPA_JF_UNKNOWN)
288 fprintf (f, "UNKNOWN\n");
289 else if (type == IPA_JF_CONST)
291 tree val = jump_func->value.constant;
292 fprintf (f, "CONST: ");
293 print_generic_expr (f, val, 0);
294 if (TREE_CODE (val) == ADDR_EXPR
295 && TREE_CODE (TREE_OPERAND (val, 0)) == CONST_DECL)
297 fprintf (f, " -> ");
298 print_generic_expr (f, DECL_INITIAL (TREE_OPERAND (val, 0)),
301 fprintf (f, "\n");
303 else if (type == IPA_JF_CONST_MEMBER_PTR)
305 fprintf (f, "CONST MEMBER PTR: ");
306 print_generic_expr (f, jump_func->value.member_cst.pfn, 0);
307 fprintf (f, ", ");
308 print_generic_expr (f, jump_func->value.member_cst.delta, 0);
309 fprintf (f, "\n");
311 else if (type == IPA_JF_PASS_THROUGH)
313 fprintf (f, "PASS THROUGH: ");
314 fprintf (f, "%d, op %s ",
315 jump_func->value.pass_through.formal_id,
316 tree_code_name[(int)
317 jump_func->value.pass_through.operation]);
318 if (jump_func->value.pass_through.operation != NOP_EXPR)
319 print_generic_expr (dump_file,
320 jump_func->value.pass_through.operand, 0);
321 fprintf (dump_file, "\n");
323 else if (type == IPA_JF_ANCESTOR)
325 fprintf (f, "ANCESTOR: ");
326 fprintf (f, "%d, offset "HOST_WIDE_INT_PRINT_DEC"\n",
327 jump_func->value.ancestor.formal_id,
328 jump_func->value.ancestor.offset);
334 /* Print ipa_jump_func data structures of all nodes in the call graph to F. */
336 void
337 ipa_print_all_jump_functions (FILE *f)
339 struct cgraph_node *node;
341 fprintf (f, "\nJump functions:\n");
342 for (node = cgraph_nodes; node; node = node->next)
344 ipa_print_node_jump_functions (f, node);
348 /* Determine whether passing ssa name NAME constitutes a polynomial
349 pass-through function or getting an address of an acestor and if so, write
350 such a jump function to JFUNC. INFO describes the caller. */
352 static void
353 compute_complex_pass_through (struct ipa_node_params *info,
354 struct ipa_jump_func *jfunc,
355 tree name)
357 HOST_WIDE_INT offset, size, max_size;
358 tree op1, op2, type;
359 int index;
360 gimple stmt = SSA_NAME_DEF_STMT (name);
362 if (!is_gimple_assign (stmt))
363 return;
364 op1 = gimple_assign_rhs1 (stmt);
365 op2 = gimple_assign_rhs2 (stmt);
367 if (op2)
369 if (TREE_CODE (op1) != SSA_NAME
370 || !SSA_NAME_IS_DEFAULT_DEF (op1)
371 || (TREE_CODE_CLASS (gimple_expr_code (stmt)) != tcc_comparison
372 && !useless_type_conversion_p (TREE_TYPE (name),
373 TREE_TYPE (op1)))
374 || !is_gimple_ip_invariant (op2))
375 return;
377 index = ipa_get_param_decl_index (info, SSA_NAME_VAR (op1));
378 if (index >= 0)
380 jfunc->type = IPA_JF_PASS_THROUGH;
381 jfunc->value.pass_through.formal_id = index;
382 jfunc->value.pass_through.operation = gimple_assign_rhs_code (stmt);
383 jfunc->value.pass_through.operand = op2;
385 return;
388 if (TREE_CODE (op1) != ADDR_EXPR)
389 return;
390 op1 = TREE_OPERAND (op1, 0);
391 type = TREE_TYPE (op1);
393 op1 = get_ref_base_and_extent (op1, &offset, &size, &max_size);
394 if (TREE_CODE (op1) != INDIRECT_REF
395 /* If this is a varying address, punt. */
396 || max_size == -1
397 || max_size != size)
398 return;
399 op1 = TREE_OPERAND (op1, 0);
400 if (TREE_CODE (op1) != SSA_NAME
401 || !SSA_NAME_IS_DEFAULT_DEF (op1))
402 return;
404 index = ipa_get_param_decl_index (info, SSA_NAME_VAR (op1));
405 if (index >= 0)
407 jfunc->type = IPA_JF_ANCESTOR;
408 jfunc->value.ancestor.formal_id = index;
409 jfunc->value.ancestor.offset = offset;
410 jfunc->value.ancestor.type = type;
415 /* Determine the jump functions of scalar arguments. Scalar means SSA names
416 and constants of a number of selected types. INFO is the ipa_node_params
417 structure associated with the caller, FUNCTIONS is a pointer to an array of
418 jump function structures associated with CALL which is the call statement
419 being examined.*/
421 static void
422 compute_scalar_jump_functions (struct ipa_node_params *info,
423 struct ipa_jump_func *functions,
424 gimple call)
426 tree arg;
427 unsigned num = 0;
429 for (num = 0; num < gimple_call_num_args (call); num++)
431 arg = gimple_call_arg (call, num);
433 if (is_gimple_ip_invariant (arg))
435 functions[num].type = IPA_JF_CONST;
436 functions[num].value.constant = arg;
438 else if (TREE_CODE (arg) == SSA_NAME)
440 if (SSA_NAME_IS_DEFAULT_DEF (arg))
442 int index = ipa_get_param_decl_index (info, SSA_NAME_VAR (arg));
444 if (index >= 0)
446 functions[num].type = IPA_JF_PASS_THROUGH;
447 functions[num].value.pass_through.formal_id = index;
448 functions[num].value.pass_through.operation = NOP_EXPR;
451 else
452 compute_complex_pass_through (info, &functions[num], arg);
457 /* Inspect the given TYPE and return true iff it has the same structure (the
458 same number of fields of the same types) as a C++ member pointer. If
459 METHOD_PTR and DELTA are non-NULL, store the trees representing the
460 corresponding fields there. */
462 static bool
463 type_like_member_ptr_p (tree type, tree *method_ptr, tree *delta)
465 tree fld;
467 if (TREE_CODE (type) != RECORD_TYPE)
468 return false;
470 fld = TYPE_FIELDS (type);
471 if (!fld || !POINTER_TYPE_P (TREE_TYPE (fld))
472 || TREE_CODE (TREE_TYPE (TREE_TYPE (fld))) != METHOD_TYPE)
473 return false;
475 if (method_ptr)
476 *method_ptr = fld;
478 fld = TREE_CHAIN (fld);
479 if (!fld || INTEGRAL_TYPE_P (fld))
480 return false;
481 if (delta)
482 *delta = fld;
484 if (TREE_CHAIN (fld))
485 return false;
487 return true;
490 /* Go through arguments of the CALL and for every one that looks like a member
491 pointer, check whether it can be safely declared pass-through and if so,
492 mark that to the corresponding item of jump FUNCTIONS. Return true iff
493 there are non-pass-through member pointers within the arguments. INFO
494 describes formal parameters of the caller. */
496 static bool
497 compute_pass_through_member_ptrs (struct ipa_node_params *info,
498 struct ipa_jump_func *functions,
499 gimple call)
501 bool undecided_members = false;
502 unsigned num;
503 tree arg;
505 for (num = 0; num < gimple_call_num_args (call); num++)
507 arg = gimple_call_arg (call, num);
509 if (type_like_member_ptr_p (TREE_TYPE (arg), NULL, NULL))
511 if (TREE_CODE (arg) == PARM_DECL)
513 int index = ipa_get_param_decl_index (info, arg);
515 gcc_assert (index >=0);
516 if (!ipa_is_param_modified (info, index))
518 functions[num].type = IPA_JF_PASS_THROUGH;
519 functions[num].value.pass_through.formal_id = index;
520 functions[num].value.pass_through.operation = NOP_EXPR;
522 else
523 undecided_members = true;
525 else
526 undecided_members = true;
530 return undecided_members;
533 /* Simple function filling in a member pointer constant jump function (with PFN
534 and DELTA as the constant value) into JFUNC. */
536 static void
537 fill_member_ptr_cst_jump_function (struct ipa_jump_func *jfunc,
538 tree pfn, tree delta)
540 jfunc->type = IPA_JF_CONST_MEMBER_PTR;
541 jfunc->value.member_cst.pfn = pfn;
542 jfunc->value.member_cst.delta = delta;
545 /* If RHS is an SSA_NAMe and it is defined by a simple copy assign statement,
546 return the rhs of its defining statement. */
548 static inline tree
549 get_ssa_def_if_simple_copy (tree rhs)
551 while (TREE_CODE (rhs) == SSA_NAME && !SSA_NAME_IS_DEFAULT_DEF (rhs))
553 gimple def_stmt = SSA_NAME_DEF_STMT (rhs);
555 if (gimple_assign_single_p (def_stmt))
556 rhs = gimple_assign_rhs1 (def_stmt);
557 else
558 break;
560 return rhs;
563 /* Traverse statements from CALL backwards, scanning whether the argument ARG
564 which is a member pointer is filled in with constant values. If it is, fill
565 the jump function JFUNC in appropriately. METHOD_FIELD and DELTA_FIELD are
566 fields of the record type of the member pointer. To give an example, we
567 look for a pattern looking like the following:
569 D.2515.__pfn ={v} printStuff;
570 D.2515.__delta ={v} 0;
571 i_1 = doprinting (D.2515); */
573 static void
574 determine_cst_member_ptr (gimple call, tree arg, tree method_field,
575 tree delta_field, struct ipa_jump_func *jfunc)
577 gimple_stmt_iterator gsi;
578 tree method = NULL_TREE;
579 tree delta = NULL_TREE;
581 gsi = gsi_for_stmt (call);
583 gsi_prev (&gsi);
584 for (; !gsi_end_p (gsi); gsi_prev (&gsi))
586 gimple stmt = gsi_stmt (gsi);
587 tree lhs, rhs, fld;
589 if (!gimple_assign_single_p (stmt))
590 return;
592 lhs = gimple_assign_lhs (stmt);
593 rhs = gimple_assign_rhs1 (stmt);
595 if (TREE_CODE (lhs) != COMPONENT_REF
596 || TREE_OPERAND (lhs, 0) != arg)
597 continue;
599 fld = TREE_OPERAND (lhs, 1);
600 if (!method && fld == method_field)
602 rhs = get_ssa_def_if_simple_copy (rhs);
603 if (TREE_CODE (rhs) == ADDR_EXPR
604 && TREE_CODE (TREE_OPERAND (rhs, 0)) == FUNCTION_DECL
605 && TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 0))) == METHOD_TYPE)
607 method = TREE_OPERAND (rhs, 0);
608 if (delta)
610 fill_member_ptr_cst_jump_function (jfunc, rhs, delta);
611 return;
614 else
615 return;
618 if (!delta && fld == delta_field)
620 rhs = get_ssa_def_if_simple_copy (rhs);
621 if (TREE_CODE (rhs) == INTEGER_CST)
623 delta = rhs;
624 if (method)
626 fill_member_ptr_cst_jump_function (jfunc, rhs, delta);
627 return;
630 else
631 return;
635 return;
638 /* Go through the arguments of the CALL and for every member pointer within
639 tries determine whether it is a constant. If it is, create a corresponding
640 constant jump function in FUNCTIONS which is an array of jump functions
641 associated with the call. */
643 static void
644 compute_cst_member_ptr_arguments (struct ipa_jump_func *functions,
645 gimple call)
647 unsigned num;
648 tree arg, method_field, delta_field;
650 for (num = 0; num < gimple_call_num_args (call); num++)
652 arg = gimple_call_arg (call, num);
654 if (functions[num].type == IPA_JF_UNKNOWN
655 && type_like_member_ptr_p (TREE_TYPE (arg), &method_field,
656 &delta_field))
657 determine_cst_member_ptr (call, arg, method_field, delta_field,
658 &functions[num]);
662 /* Compute jump function for all arguments of callsite CS and insert the
663 information in the jump_functions array in the ipa_edge_args corresponding
664 to this callsite. */
666 void
667 ipa_compute_jump_functions (struct cgraph_edge *cs)
669 struct ipa_node_params *info = IPA_NODE_REF (cs->caller);
670 struct ipa_edge_args *arguments = IPA_EDGE_REF (cs);
671 gimple call;
673 if (ipa_get_cs_argument_count (arguments) == 0 || arguments->jump_functions)
674 return;
675 arguments->jump_functions = GGC_CNEWVEC (struct ipa_jump_func,
676 ipa_get_cs_argument_count (arguments));
678 call = cs->call_stmt;
679 gcc_assert (is_gimple_call (call));
681 /* We will deal with constants and SSA scalars first: */
682 compute_scalar_jump_functions (info, arguments->jump_functions, call);
684 /* Let's check whether there are any potential member pointers and if so,
685 whether we can determine their functions as pass_through. */
686 if (!compute_pass_through_member_ptrs (info, arguments->jump_functions, call))
687 return;
689 /* Finally, let's check whether we actually pass a new constant member
690 pointer here... */
691 compute_cst_member_ptr_arguments (arguments->jump_functions, call);
694 /* If RHS looks like a rhs of a statement loading pfn from a member
695 pointer formal parameter, return the parameter, otherwise return
696 NULL. If USE_DELTA, then we look for a use of the delta field
697 rather than the pfn. */
699 static tree
700 ipa_get_member_ptr_load_param (tree rhs, bool use_delta)
702 tree rec, fld;
703 tree ptr_field;
704 tree delta_field;
706 if (TREE_CODE (rhs) != COMPONENT_REF)
707 return NULL_TREE;
709 rec = TREE_OPERAND (rhs, 0);
710 if (TREE_CODE (rec) != PARM_DECL
711 || !type_like_member_ptr_p (TREE_TYPE (rec), &ptr_field, &delta_field))
712 return NULL_TREE;
714 fld = TREE_OPERAND (rhs, 1);
715 if (use_delta ? (fld == delta_field) : (fld == ptr_field))
716 return rec;
717 else
718 return NULL_TREE;
721 /* If STMT looks like a statement loading a value from a member pointer formal
722 parameter, this function returns that parameter. */
724 static tree
725 ipa_get_stmt_member_ptr_load_param (gimple stmt, bool use_delta)
727 tree rhs;
729 if (!gimple_assign_single_p (stmt))
730 return NULL_TREE;
732 rhs = gimple_assign_rhs1 (stmt);
733 return ipa_get_member_ptr_load_param (rhs, use_delta);
736 /* Returns true iff T is an SSA_NAME defined by a statement. */
738 static bool
739 ipa_is_ssa_with_stmt_def (tree t)
741 if (TREE_CODE (t) == SSA_NAME
742 && !SSA_NAME_IS_DEFAULT_DEF (t))
743 return true;
744 else
745 return false;
748 /* Creates a new note describing a call to a parameter number FORMAL_ID and
749 attaches it to the linked list of INFO. It also sets the called flag of the
750 parameter. STMT is the corresponding call statement. */
752 static void
753 ipa_note_param_call (struct ipa_node_params *info, int formal_id,
754 gimple stmt)
756 struct ipa_param_call_note *note;
757 basic_block bb = gimple_bb (stmt);
759 note = XCNEW (struct ipa_param_call_note);
760 note->formal_id = formal_id;
761 note->stmt = stmt;
762 note->lto_stmt_uid = gimple_uid (stmt);
763 note->count = bb->count;
764 note->frequency = compute_call_stmt_bb_frequency (current_function_decl, bb);
765 note->loop_nest = bb->loop_depth;
767 note->next = info->param_calls;
768 info->param_calls = note;
770 return;
773 /* Analyze the CALL and examine uses of formal parameters of the caller
774 (described by INFO). Currently it checks whether the call calls a pointer
775 that is a formal parameter and if so, the parameter is marked with the
776 called flag and a note describing the call is created. This is very simple
777 for ordinary pointers represented in SSA but not-so-nice when it comes to
778 member pointers. The ugly part of this function does nothing more than
779 tries to match the pattern of such a call. An example of such a pattern is
780 the gimple dump below, the call is on the last line:
782 <bb 2>:
783 f$__delta_5 = f.__delta;
784 f$__pfn_24 = f.__pfn;
785 D.2496_3 = (int) f$__pfn_24;
786 D.2497_4 = D.2496_3 & 1;
787 if (D.2497_4 != 0)
788 goto <bb 3>;
789 else
790 goto <bb 4>;
792 <bb 3>:
793 D.2500_7 = (unsigned int) f$__delta_5;
794 D.2501_8 = &S + D.2500_7;
795 D.2502_9 = (int (*__vtbl_ptr_type) (void) * *) D.2501_8;
796 D.2503_10 = *D.2502_9;
797 D.2504_12 = f$__pfn_24 + -1;
798 D.2505_13 = (unsigned int) D.2504_12;
799 D.2506_14 = D.2503_10 + D.2505_13;
800 D.2507_15 = *D.2506_14;
801 iftmp.11_16 = (String:: *) D.2507_15;
803 <bb 4>:
804 # iftmp.11_1 = PHI <iftmp.11_16(3), f$__pfn_24(2)>
805 D.2500_19 = (unsigned int) f$__delta_5;
806 D.2508_20 = &S + D.2500_19;
807 D.2493_21 = iftmp.11_1 (D.2508_20, 4);
809 Such patterns are results of simple calls to a member pointer:
811 int doprinting (int (MyString::* f)(int) const)
813 MyString S ("somestring");
815 return (S.*f)(4);
819 static void
820 ipa_analyze_call_uses (struct ipa_node_params *info, gimple call)
822 tree target = gimple_call_fn (call);
823 gimple def;
824 tree var;
825 tree n1, n2;
826 gimple d1, d2;
827 tree rec, rec2, cond;
828 gimple branch;
829 int index;
830 basic_block bb, virt_bb, join;
832 if (TREE_CODE (target) != SSA_NAME)
833 return;
835 var = SSA_NAME_VAR (target);
836 if (SSA_NAME_IS_DEFAULT_DEF (target))
838 /* assuming TREE_CODE (var) == PARM_DECL */
839 index = ipa_get_param_decl_index (info, var);
840 if (index >= 0)
841 ipa_note_param_call (info, index, call);
842 return;
845 /* Now we need to try to match the complex pattern of calling a member
846 pointer. */
848 if (!POINTER_TYPE_P (TREE_TYPE (target))
849 || TREE_CODE (TREE_TYPE (TREE_TYPE (target))) != METHOD_TYPE)
850 return;
852 def = SSA_NAME_DEF_STMT (target);
853 if (gimple_code (def) != GIMPLE_PHI)
854 return;
856 if (gimple_phi_num_args (def) != 2)
857 return;
859 /* First, we need to check whether one of these is a load from a member
860 pointer that is a parameter to this function. */
861 n1 = PHI_ARG_DEF (def, 0);
862 n2 = PHI_ARG_DEF (def, 1);
863 if (!ipa_is_ssa_with_stmt_def (n1) || !ipa_is_ssa_with_stmt_def (n2))
864 return;
865 d1 = SSA_NAME_DEF_STMT (n1);
866 d2 = SSA_NAME_DEF_STMT (n2);
868 if ((rec = ipa_get_stmt_member_ptr_load_param (d1, false)))
870 if (ipa_get_stmt_member_ptr_load_param (d2, false))
871 return;
873 bb = gimple_bb (d1);
874 virt_bb = gimple_bb (d2);
876 else if ((rec = ipa_get_stmt_member_ptr_load_param (d2, false)))
878 bb = gimple_bb (d2);
879 virt_bb = gimple_bb (d1);
881 else
882 return;
884 /* Second, we need to check that the basic blocks are laid out in the way
885 corresponding to the pattern. */
887 join = gimple_bb (def);
888 if (!single_pred_p (virt_bb) || !single_succ_p (virt_bb)
889 || single_pred (virt_bb) != bb
890 || single_succ (virt_bb) != join)
891 return;
893 /* Third, let's see that the branching is done depending on the least
894 significant bit of the pfn. */
896 branch = last_stmt (bb);
897 if (gimple_code (branch) != GIMPLE_COND)
898 return;
900 if (gimple_cond_code (branch) != NE_EXPR
901 || !integer_zerop (gimple_cond_rhs (branch)))
902 return;
904 cond = gimple_cond_lhs (branch);
905 if (!ipa_is_ssa_with_stmt_def (cond))
906 return;
908 def = SSA_NAME_DEF_STMT (cond);
909 if (!is_gimple_assign (def)
910 || gimple_assign_rhs_code (def) != BIT_AND_EXPR
911 || !integer_onep (gimple_assign_rhs2 (def)))
912 return;
914 cond = gimple_assign_rhs1 (def);
915 if (!ipa_is_ssa_with_stmt_def (cond))
916 return;
918 def = SSA_NAME_DEF_STMT (cond);
920 if (is_gimple_assign (def)
921 && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def)))
923 cond = gimple_assign_rhs1 (def);
924 if (!ipa_is_ssa_with_stmt_def (cond))
925 return;
926 def = SSA_NAME_DEF_STMT (cond);
929 rec2 = ipa_get_stmt_member_ptr_load_param (def,
930 (TARGET_PTRMEMFUNC_VBIT_LOCATION
931 == ptrmemfunc_vbit_in_delta));
933 if (rec != rec2)
934 return;
936 index = ipa_get_param_decl_index (info, rec);
937 if (index >= 0 && !ipa_is_param_modified (info, index))
938 ipa_note_param_call (info, index, call);
940 return;
943 /* Analyze the statement STMT with respect to formal parameters (described in
944 INFO) and their uses. Currently it only checks whether formal parameters
945 are called. */
947 static void
948 ipa_analyze_stmt_uses (struct ipa_node_params *info, gimple stmt)
950 if (is_gimple_call (stmt))
951 ipa_analyze_call_uses (info, stmt);
954 /* Scan the function body of NODE and inspect the uses of formal parameters.
955 Store the findings in various structures of the associated ipa_node_params
956 structure, such as parameter flags, notes etc. */
958 void
959 ipa_analyze_params_uses (struct cgraph_node *node)
961 tree decl = node->decl;
962 basic_block bb;
963 struct function *func;
964 gimple_stmt_iterator gsi;
965 struct ipa_node_params *info = IPA_NODE_REF (node);
967 if (ipa_get_param_count (info) == 0 || info->uses_analysis_done)
968 return;
970 func = DECL_STRUCT_FUNCTION (decl);
971 FOR_EACH_BB_FN (bb, func)
973 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
975 gimple stmt = gsi_stmt (gsi);
976 ipa_analyze_stmt_uses (info, stmt);
980 info->uses_analysis_done = 1;
983 /* Update the jump functions associated with call graph edge E when the call
984 graph edge CS is being inlined, assuming that E->caller is already (possibly
985 indirectly) inlined into CS->callee and that E has not been inlined.
987 We keep pass through functions only if they do not contain any operation.
988 This is sufficient for inlining and greately simplifies things. */
990 static void
991 update_jump_functions_after_inlining (struct cgraph_edge *cs,
992 struct cgraph_edge *e)
994 struct ipa_edge_args *top = IPA_EDGE_REF (cs);
995 struct ipa_edge_args *args = IPA_EDGE_REF (e);
996 int count = ipa_get_cs_argument_count (args);
997 int i;
999 for (i = 0; i < count; i++)
1001 struct ipa_jump_func *src, *dst = ipa_get_ith_jump_func (args, i);
1003 if (dst->type == IPA_JF_ANCESTOR)
1005 dst->type = IPA_JF_UNKNOWN;
1006 continue;
1009 if (dst->type != IPA_JF_PASS_THROUGH)
1010 continue;
1012 /* We must check range due to calls with variable number of arguments and
1013 we cannot combine jump functions with operations. */
1014 if (dst->value.pass_through.operation != NOP_EXPR
1015 || (dst->value.pass_through.formal_id
1016 >= ipa_get_cs_argument_count (top)))
1018 dst->type = IPA_JF_UNKNOWN;
1019 continue;
1022 src = ipa_get_ith_jump_func (top, dst->value.pass_through.formal_id);
1023 *dst = *src;
1027 /* Print out a debug message to file F that we have discovered that an indirect
1028 call described by NT is in fact a call of a known constant function described
1029 by JFUNC. NODE is the node where the call is. */
1031 static void
1032 print_edge_addition_message (FILE *f, struct ipa_param_call_note *nt,
1033 struct ipa_jump_func *jfunc,
1034 struct cgraph_node *node)
1036 fprintf (f, "ipa-prop: Discovered an indirect call to a known target (");
1037 if (jfunc->type == IPA_JF_CONST_MEMBER_PTR)
1039 print_node_brief (f, "", jfunc->value.member_cst.pfn, 0);
1040 print_node_brief (f, ", ", jfunc->value.member_cst.delta, 0);
1042 else
1043 print_node_brief(f, "", jfunc->value.constant, 0);
1045 fprintf (f, ") in %s: ", cgraph_node_name (node));
1046 print_gimple_stmt (f, nt->stmt, 2, TDF_SLIM);
1049 /* Update the param called notes associated with NODE when CS is being inlined,
1050 assuming NODE is (potentially indirectly) inlined into CS->callee.
1051 Moreover, if the callee is discovered to be constant, create a new cgraph
1052 edge for it. Newly discovered indirect edges will be added to *NEW_EDGES,
1053 unless NEW_EDGES is NULL. Return true iff a new edge(s) were created. */
1055 static bool
1056 update_call_notes_after_inlining (struct cgraph_edge *cs,
1057 struct cgraph_node *node,
1058 VEC (cgraph_edge_p, heap) **new_edges)
1060 struct ipa_node_params *info = IPA_NODE_REF (node);
1061 struct ipa_edge_args *top = IPA_EDGE_REF (cs);
1062 struct ipa_param_call_note *nt;
1063 bool res = false;
1065 for (nt = info->param_calls; nt; nt = nt->next)
1067 struct ipa_jump_func *jfunc;
1069 if (nt->processed)
1070 continue;
1072 /* We must check range due to calls with variable number of arguments: */
1073 if (nt->formal_id >= ipa_get_cs_argument_count (top))
1075 nt->processed = true;
1076 continue;
1079 jfunc = ipa_get_ith_jump_func (top, nt->formal_id);
1080 if (jfunc->type == IPA_JF_PASS_THROUGH
1081 && jfunc->value.pass_through.operation == NOP_EXPR)
1082 nt->formal_id = jfunc->value.pass_through.formal_id;
1083 else if (jfunc->type == IPA_JF_CONST
1084 || jfunc->type == IPA_JF_CONST_MEMBER_PTR)
1086 struct cgraph_node *callee;
1087 struct cgraph_edge *new_indirect_edge;
1088 tree decl;
1090 nt->processed = true;
1091 if (jfunc->type == IPA_JF_CONST_MEMBER_PTR)
1092 decl = jfunc->value.member_cst.pfn;
1093 else
1094 decl = jfunc->value.constant;
1096 if (TREE_CODE (decl) != ADDR_EXPR)
1097 continue;
1098 decl = TREE_OPERAND (decl, 0);
1100 if (TREE_CODE (decl) != FUNCTION_DECL)
1101 continue;
1102 callee = cgraph_node (decl);
1103 if (!callee || !callee->local.inlinable)
1104 continue;
1106 res = true;
1107 if (dump_file)
1108 print_edge_addition_message (dump_file, nt, jfunc, node);
1110 new_indirect_edge = cgraph_create_edge (node, callee, nt->stmt,
1111 nt->count, nt->frequency,
1112 nt->loop_nest);
1113 new_indirect_edge->lto_stmt_uid = nt->lto_stmt_uid;
1114 new_indirect_edge->indirect_call = 1;
1115 ipa_check_create_edge_args ();
1116 if (new_edges)
1117 VEC_safe_push (cgraph_edge_p, heap, *new_edges, new_indirect_edge);
1118 top = IPA_EDGE_REF (cs);
1120 else
1122 /* Ancestor jum functions and pass theoughs with operations should
1123 not be used on parameters that then get called. */
1124 gcc_assert (jfunc->type == IPA_JF_UNKNOWN);
1125 nt->processed = true;
1128 return res;
1131 /* Recursively traverse subtree of NODE (including node) made of inlined
1132 cgraph_edges when CS has been inlined and invoke
1133 update_call_notes_after_inlining on all nodes and
1134 update_jump_functions_after_inlining on all non-inlined edges that lead out
1135 of this subtree. Newly discovered indirect edges will be added to
1136 *NEW_EDGES, unless NEW_EDGES is NULL. Return true iff a new edge(s) were
1137 created. */
1139 static bool
1140 propagate_info_to_inlined_callees (struct cgraph_edge *cs,
1141 struct cgraph_node *node,
1142 VEC (cgraph_edge_p, heap) **new_edges)
1144 struct cgraph_edge *e;
1145 bool res;
1147 res = update_call_notes_after_inlining (cs, node, new_edges);
1149 for (e = node->callees; e; e = e->next_callee)
1150 if (!e->inline_failed)
1151 res |= propagate_info_to_inlined_callees (cs, e->callee, new_edges);
1152 else
1153 update_jump_functions_after_inlining (cs, e);
1155 return res;
1158 /* Update jump functions and call note functions on inlining the call site CS.
1159 CS is expected to lead to a node already cloned by
1160 cgraph_clone_inline_nodes. Newly discovered indirect edges will be added to
1161 *NEW_EDGES, unless NEW_EDGES is NULL. Return true iff a new edge(s) were +
1162 created. */
1164 bool
1165 ipa_propagate_indirect_call_infos (struct cgraph_edge *cs,
1166 VEC (cgraph_edge_p, heap) **new_edges)
1168 /* FIXME lto: We do not stream out indirect call information. */
1169 if (flag_wpa)
1170 return false;
1172 /* Do nothing if the preparation phase has not been carried out yet
1173 (i.e. during early inlining). */
1174 if (!ipa_node_params_vector)
1175 return false;
1176 gcc_assert (ipa_edge_args_vector);
1178 return propagate_info_to_inlined_callees (cs, cs->callee, new_edges);
1181 /* Frees all dynamically allocated structures that the argument info points
1182 to. */
1184 void
1185 ipa_free_edge_args_substructures (struct ipa_edge_args *args)
1187 if (args->jump_functions)
1188 ggc_free (args->jump_functions);
1190 memset (args, 0, sizeof (*args));
1193 /* Free all ipa_edge structures. */
1195 void
1196 ipa_free_all_edge_args (void)
1198 int i;
1199 struct ipa_edge_args *args;
1201 for (i = 0;
1202 VEC_iterate (ipa_edge_args_t, ipa_edge_args_vector, i, args);
1203 i++)
1204 ipa_free_edge_args_substructures (args);
1206 VEC_free (ipa_edge_args_t, gc, ipa_edge_args_vector);
1207 ipa_edge_args_vector = NULL;
1210 /* Frees all dynamically allocated structures that the param info points
1211 to. */
1213 void
1214 ipa_free_node_params_substructures (struct ipa_node_params *info)
1216 if (info->params)
1217 free (info->params);
1219 while (info->param_calls)
1221 struct ipa_param_call_note *note = info->param_calls;
1222 info->param_calls = note->next;
1223 free (note);
1226 memset (info, 0, sizeof (*info));
1229 /* Free all ipa_node_params structures. */
1231 void
1232 ipa_free_all_node_params (void)
1234 int i;
1235 struct ipa_node_params *info;
1237 for (i = 0;
1238 VEC_iterate (ipa_node_params_t, ipa_node_params_vector, i, info);
1239 i++)
1240 ipa_free_node_params_substructures (info);
1242 VEC_free (ipa_node_params_t, heap, ipa_node_params_vector);
1243 ipa_node_params_vector = NULL;
1246 /* Hook that is called by cgraph.c when an edge is removed. */
1248 static void
1249 ipa_edge_removal_hook (struct cgraph_edge *cs, void *data ATTRIBUTE_UNUSED)
1251 /* During IPA-CP updating we can be called on not-yet analyze clones. */
1252 if (VEC_length (ipa_edge_args_t, ipa_edge_args_vector)
1253 <= (unsigned)cs->uid)
1254 return;
1255 ipa_free_edge_args_substructures (IPA_EDGE_REF (cs));
1258 /* Hook that is called by cgraph.c when a node is removed. */
1260 static void
1261 ipa_node_removal_hook (struct cgraph_node *node, void *data ATTRIBUTE_UNUSED)
1263 ipa_free_node_params_substructures (IPA_NODE_REF (node));
1266 /* Helper function to duplicate an array of size N that is at SRC and store a
1267 pointer to it to DST. Nothing is done if SRC is NULL. */
1269 static void *
1270 duplicate_array (void *src, size_t n)
1272 void *p;
1274 if (!src)
1275 return NULL;
1277 p = xmalloc (n);
1278 memcpy (p, src, n);
1279 return p;
1282 /* Like duplicate_array byt in GGC memory. */
1284 static void *
1285 duplicate_ggc_array (void *src, size_t n)
1287 void *p;
1289 if (!src)
1290 return NULL;
1292 p = ggc_alloc (n);
1293 memcpy (p, src, n);
1294 return p;
1297 /* Hook that is called by cgraph.c when a node is duplicated. */
1299 static void
1300 ipa_edge_duplication_hook (struct cgraph_edge *src, struct cgraph_edge *dst,
1301 __attribute__((unused)) void *data)
1303 struct ipa_edge_args *old_args, *new_args;
1304 int arg_count;
1306 ipa_check_create_edge_args ();
1308 old_args = IPA_EDGE_REF (src);
1309 new_args = IPA_EDGE_REF (dst);
1311 arg_count = ipa_get_cs_argument_count (old_args);
1312 ipa_set_cs_argument_count (new_args, arg_count);
1313 new_args->jump_functions = (struct ipa_jump_func *)
1314 duplicate_ggc_array (old_args->jump_functions,
1315 sizeof (struct ipa_jump_func) * arg_count);
1318 /* Hook that is called by cgraph.c when a node is duplicated. */
1320 static void
1321 ipa_node_duplication_hook (struct cgraph_node *src, struct cgraph_node *dst,
1322 __attribute__((unused)) void *data)
1324 struct ipa_node_params *old_info, *new_info;
1325 struct ipa_param_call_note *note;
1326 int param_count;
1328 ipa_check_create_node_params ();
1329 old_info = IPA_NODE_REF (src);
1330 new_info = IPA_NODE_REF (dst);
1331 param_count = ipa_get_param_count (old_info);
1333 ipa_set_param_count (new_info, param_count);
1334 new_info->params = (struct ipa_param_descriptor *)
1335 duplicate_array (old_info->params,
1336 sizeof (struct ipa_param_descriptor) * param_count);
1337 new_info->ipcp_orig_node = old_info->ipcp_orig_node;
1338 new_info->count_scale = old_info->count_scale;
1340 for (note = old_info->param_calls; note; note = note->next)
1342 struct ipa_param_call_note *nn;
1344 nn = (struct ipa_param_call_note *)
1345 xcalloc (1, sizeof (struct ipa_param_call_note));
1346 memcpy (nn, note, sizeof (struct ipa_param_call_note));
1347 nn->next = new_info->param_calls;
1348 new_info->param_calls = nn;
1352 /* Register our cgraph hooks if they are not already there. */
1354 void
1355 ipa_register_cgraph_hooks (void)
1357 if (!edge_removal_hook_holder)
1358 edge_removal_hook_holder =
1359 cgraph_add_edge_removal_hook (&ipa_edge_removal_hook, NULL);
1360 if (!node_removal_hook_holder)
1361 node_removal_hook_holder =
1362 cgraph_add_node_removal_hook (&ipa_node_removal_hook, NULL);
1363 if (!edge_duplication_hook_holder)
1364 edge_duplication_hook_holder =
1365 cgraph_add_edge_duplication_hook (&ipa_edge_duplication_hook, NULL);
1366 if (!node_duplication_hook_holder)
1367 node_duplication_hook_holder =
1368 cgraph_add_node_duplication_hook (&ipa_node_duplication_hook, NULL);
1371 /* Unregister our cgraph hooks if they are not already there. */
1373 static void
1374 ipa_unregister_cgraph_hooks (void)
1376 cgraph_remove_edge_removal_hook (edge_removal_hook_holder);
1377 edge_removal_hook_holder = NULL;
1378 cgraph_remove_node_removal_hook (node_removal_hook_holder);
1379 node_removal_hook_holder = NULL;
1380 cgraph_remove_edge_duplication_hook (edge_duplication_hook_holder);
1381 edge_duplication_hook_holder = NULL;
1382 cgraph_remove_node_duplication_hook (node_duplication_hook_holder);
1383 node_duplication_hook_holder = NULL;
1386 /* Free all ipa_node_params and all ipa_edge_args structures if they are no
1387 longer needed after ipa-cp. */
1389 void
1390 free_all_ipa_structures_after_ipa_cp (void)
1392 if (!flag_indirect_inlining)
1394 ipa_free_all_edge_args ();
1395 ipa_free_all_node_params ();
1396 ipa_unregister_cgraph_hooks ();
1400 /* Free all ipa_node_params and all ipa_edge_args structures if they are no
1401 longer needed after indirect inlining. */
1403 void
1404 free_all_ipa_structures_after_iinln (void)
1406 ipa_free_all_edge_args ();
1407 ipa_free_all_node_params ();
1408 ipa_unregister_cgraph_hooks ();
1411 /* Print ipa_tree_map data structures of all functions in the
1412 callgraph to F. */
1414 void
1415 ipa_print_node_params (FILE * f, struct cgraph_node *node)
1417 int i, count;
1418 tree temp;
1419 struct ipa_node_params *info;
1421 if (!node->analyzed)
1422 return;
1423 info = IPA_NODE_REF (node);
1424 fprintf (f, " function %s Trees :: \n", cgraph_node_name (node));
1425 count = ipa_get_param_count (info);
1426 for (i = 0; i < count; i++)
1428 temp = ipa_get_param (info, i);
1429 if (TREE_CODE (temp) == PARM_DECL)
1430 fprintf (f, " param %d : %s", i,
1431 (DECL_NAME (temp)
1432 ? (*lang_hooks.decl_printable_name) (temp, 2)
1433 : "(unnamed)"));
1434 if (ipa_is_param_modified (info, i))
1435 fprintf (f, " modified");
1436 fprintf (f, "\n");
1440 /* Print ipa_tree_map data structures of all functions in the
1441 callgraph to F. */
1443 void
1444 ipa_print_all_params (FILE * f)
1446 struct cgraph_node *node;
1448 fprintf (f, "\nFunction parameters:\n");
1449 for (node = cgraph_nodes; node; node = node->next)
1450 ipa_print_node_params (f, node);
1453 /* Return a heap allocated vector containing formal parameters of FNDECL. */
1455 VEC(tree, heap) *
1456 ipa_get_vector_of_formal_parms (tree fndecl)
1458 VEC(tree, heap) *args;
1459 int count;
1460 tree parm;
1462 count = count_formal_params_1 (fndecl);
1463 args = VEC_alloc (tree, heap, count);
1464 for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm))
1465 VEC_quick_push (tree, args, parm);
1467 return args;
1470 /* Return a heap allocated vector containing types of formal parameters of
1471 function type FNTYPE. */
1473 static inline VEC(tree, heap) *
1474 get_vector_of_formal_parm_types (tree fntype)
1476 VEC(tree, heap) *types;
1477 int count = 0;
1478 tree t;
1480 for (t = TYPE_ARG_TYPES (fntype); t; t = TREE_CHAIN (t))
1481 count++;
1483 types = VEC_alloc (tree, heap, count);
1484 for (t = TYPE_ARG_TYPES (fntype); t; t = TREE_CHAIN (t))
1485 VEC_quick_push (tree, types, TREE_VALUE (t));
1487 return types;
1490 /* Modify the function declaration FNDECL and its type according to the plan in
1491 ADJUSTMENTS. It also sets base fields of individual adjustments structures
1492 to reflect the actual parameters being modified which are determined by the
1493 base_index field. */
1495 void
1496 ipa_modify_formal_parameters (tree fndecl, ipa_parm_adjustment_vec adjustments,
1497 const char *synth_parm_prefix)
1499 VEC(tree, heap) *oparms, *otypes;
1500 tree orig_type, new_type = NULL;
1501 tree old_arg_types, t, new_arg_types = NULL;
1502 tree parm, *link = &DECL_ARGUMENTS (fndecl);
1503 int i, len = VEC_length (ipa_parm_adjustment_t, adjustments);
1504 tree new_reversed = NULL;
1505 bool care_for_types, last_parm_void;
1507 if (!synth_parm_prefix)
1508 synth_parm_prefix = "SYNTH";
1510 oparms = ipa_get_vector_of_formal_parms (fndecl);
1511 orig_type = TREE_TYPE (fndecl);
1512 old_arg_types = TYPE_ARG_TYPES (orig_type);
1514 /* The following test is an ugly hack, some functions simply don't have any
1515 arguments in their type. This is probably a bug but well... */
1516 care_for_types = (old_arg_types != NULL_TREE);
1517 if (care_for_types)
1519 last_parm_void = (TREE_VALUE (tree_last (old_arg_types))
1520 == void_type_node);
1521 otypes = get_vector_of_formal_parm_types (orig_type);
1522 if (last_parm_void)
1523 gcc_assert (VEC_length (tree, oparms) + 1 == VEC_length (tree, otypes));
1524 else
1525 gcc_assert (VEC_length (tree, oparms) == VEC_length (tree, otypes));
1527 else
1529 last_parm_void = false;
1530 otypes = NULL;
1533 for (i = 0; i < len; i++)
1535 struct ipa_parm_adjustment *adj;
1536 gcc_assert (link);
1538 adj = VEC_index (ipa_parm_adjustment_t, adjustments, i);
1539 parm = VEC_index (tree, oparms, adj->base_index);
1540 adj->base = parm;
1542 if (adj->copy_param)
1544 if (care_for_types)
1545 new_arg_types = tree_cons (NULL_TREE, VEC_index (tree, otypes,
1546 adj->base_index),
1547 new_arg_types);
1548 *link = parm;
1549 link = &TREE_CHAIN (parm);
1551 else if (!adj->remove_param)
1553 tree new_parm;
1554 tree ptype;
1556 if (adj->by_ref)
1557 ptype = build_pointer_type (adj->type);
1558 else
1559 ptype = adj->type;
1561 if (care_for_types)
1562 new_arg_types = tree_cons (NULL_TREE, ptype, new_arg_types);
1564 new_parm = build_decl (UNKNOWN_LOCATION, PARM_DECL, NULL_TREE,
1565 ptype);
1566 DECL_NAME (new_parm) = create_tmp_var_name (synth_parm_prefix);
1568 DECL_ARTIFICIAL (new_parm) = 1;
1569 DECL_ARG_TYPE (new_parm) = ptype;
1570 DECL_CONTEXT (new_parm) = fndecl;
1571 TREE_USED (new_parm) = 1;
1572 DECL_IGNORED_P (new_parm) = 1;
1573 layout_decl (new_parm, 0);
1575 add_referenced_var (new_parm);
1576 mark_sym_for_renaming (new_parm);
1577 adj->base = parm;
1578 adj->reduction = new_parm;
1580 *link = new_parm;
1582 link = &TREE_CHAIN (new_parm);
1586 *link = NULL_TREE;
1588 if (care_for_types)
1590 new_reversed = nreverse (new_arg_types);
1591 if (last_parm_void)
1593 if (new_reversed)
1594 TREE_CHAIN (new_arg_types) = void_list_node;
1595 else
1596 new_reversed = void_list_node;
1600 /* Use copy_node to preserve as much as possible from original type
1601 (debug info, attribute lists etc.)
1602 Exception is METHOD_TYPEs must have THIS argument.
1603 When we are asked to remove it, we need to build new FUNCTION_TYPE
1604 instead. */
1605 if (TREE_CODE (orig_type) != METHOD_TYPE
1606 || (VEC_index (ipa_parm_adjustment_t, adjustments, 0)->copy_param
1607 && VEC_index (ipa_parm_adjustment_t, adjustments, 0)->base_index == 0))
1609 new_type = copy_node (orig_type);
1610 TYPE_ARG_TYPES (new_type) = new_reversed;
1612 else
1614 new_type
1615 = build_distinct_type_copy (build_function_type (TREE_TYPE (orig_type),
1616 new_reversed));
1617 TYPE_CONTEXT (new_type) = TYPE_CONTEXT (orig_type);
1618 DECL_VINDEX (fndecl) = NULL_TREE;
1621 /* This is a new type, not a copy of an old type. Need to reassociate
1622 variants. We can handle everything except the main variant lazily. */
1623 t = TYPE_MAIN_VARIANT (orig_type);
1624 if (orig_type != t)
1626 TYPE_MAIN_VARIANT (new_type) = t;
1627 TYPE_NEXT_VARIANT (new_type) = TYPE_NEXT_VARIANT (t);
1628 TYPE_NEXT_VARIANT (t) = new_type;
1630 else
1632 TYPE_MAIN_VARIANT (new_type) = new_type;
1633 TYPE_NEXT_VARIANT (new_type) = NULL;
1636 TREE_TYPE (fndecl) = new_type;
1637 if (otypes)
1638 VEC_free (tree, heap, otypes);
1639 VEC_free (tree, heap, oparms);
1642 /* Modify actual arguments of a function call CS as indicated in ADJUSTMENTS.
1643 If this is a directly recursive call, CS must be NULL. Otherwise it must
1644 contain the corresponding call graph edge. */
1646 void
1647 ipa_modify_call_arguments (struct cgraph_edge *cs, gimple stmt,
1648 ipa_parm_adjustment_vec adjustments)
1650 VEC(tree, heap) *vargs;
1651 gimple new_stmt;
1652 gimple_stmt_iterator gsi;
1653 tree callee_decl;
1654 int i, len;
1656 len = VEC_length (ipa_parm_adjustment_t, adjustments);
1657 vargs = VEC_alloc (tree, heap, len);
1659 gsi = gsi_for_stmt (stmt);
1660 for (i = 0; i < len; i++)
1662 struct ipa_parm_adjustment *adj;
1664 adj = VEC_index (ipa_parm_adjustment_t, adjustments, i);
1666 if (adj->copy_param)
1668 tree arg = gimple_call_arg (stmt, adj->base_index);
1670 VEC_quick_push (tree, vargs, arg);
1672 else if (!adj->remove_param)
1674 tree expr, orig_expr;
1675 bool allow_ptr, repl_found;
1677 orig_expr = expr = gimple_call_arg (stmt, adj->base_index);
1678 if (TREE_CODE (expr) == ADDR_EXPR)
1680 allow_ptr = false;
1681 expr = TREE_OPERAND (expr, 0);
1683 else
1684 allow_ptr = true;
1686 repl_found = build_ref_for_offset (&expr, TREE_TYPE (expr),
1687 adj->offset, adj->type,
1688 allow_ptr);
1689 if (repl_found)
1691 if (adj->by_ref)
1692 expr = build_fold_addr_expr (expr);
1694 else
1696 tree ptrtype = build_pointer_type (adj->type);
1697 expr = orig_expr;
1698 if (!POINTER_TYPE_P (TREE_TYPE (expr)))
1699 expr = build_fold_addr_expr (expr);
1700 if (!useless_type_conversion_p (ptrtype, TREE_TYPE (expr)))
1701 expr = fold_convert (ptrtype, expr);
1702 expr = fold_build2 (POINTER_PLUS_EXPR, ptrtype, expr,
1703 build_int_cst (size_type_node,
1704 adj->offset / BITS_PER_UNIT));
1705 if (!adj->by_ref)
1706 expr = fold_build1 (INDIRECT_REF, adj->type, expr);
1708 expr = force_gimple_operand_gsi (&gsi, expr,
1709 adj->by_ref
1710 || is_gimple_reg_type (adj->type),
1711 NULL, true, GSI_SAME_STMT);
1712 VEC_quick_push (tree, vargs, expr);
1716 if (dump_file && (dump_flags & TDF_DETAILS))
1718 fprintf (dump_file, "replacing stmt:");
1719 print_gimple_stmt (dump_file, gsi_stmt (gsi), 0, 0);
1722 callee_decl = !cs ? gimple_call_fndecl (stmt) : cs->callee->decl;
1723 new_stmt = gimple_build_call_vec (callee_decl, vargs);
1724 VEC_free (tree, heap, vargs);
1725 if (gimple_call_lhs (stmt))
1726 gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt));
1728 gimple_set_block (new_stmt, gimple_block (stmt));
1729 if (gimple_has_location (stmt))
1730 gimple_set_location (new_stmt, gimple_location (stmt));
1731 gimple_call_copy_flags (new_stmt, stmt);
1732 gimple_call_set_chain (new_stmt, gimple_call_chain (stmt));
1734 if (dump_file && (dump_flags & TDF_DETAILS))
1736 fprintf (dump_file, "with stmt:");
1737 print_gimple_stmt (dump_file, new_stmt, 0, 0);
1738 fprintf (dump_file, "\n");
1740 gsi_replace (&gsi, new_stmt, true);
1741 if (cs)
1742 cgraph_set_call_stmt (cs, new_stmt);
1743 update_ssa (TODO_update_ssa);
1744 free_dominance_info (CDI_DOMINATORS);
1747 /* Return true iff BASE_INDEX is in ADJUSTMENTS more than once. */
1749 static bool
1750 index_in_adjustments_multiple_times_p (int base_index,
1751 ipa_parm_adjustment_vec adjustments)
1753 int i, len = VEC_length (ipa_parm_adjustment_t, adjustments);
1754 bool one = false;
1756 for (i = 0; i < len; i++)
1758 struct ipa_parm_adjustment *adj;
1759 adj = VEC_index (ipa_parm_adjustment_t, adjustments, i);
1761 if (adj->base_index == base_index)
1763 if (one)
1764 return true;
1765 else
1766 one = true;
1769 return false;
1773 /* Return adjustments that should have the same effect on function parameters
1774 and call arguments as if they were first changed according to adjustments in
1775 INNER and then by adjustments in OUTER. */
1777 ipa_parm_adjustment_vec
1778 ipa_combine_adjustments (ipa_parm_adjustment_vec inner,
1779 ipa_parm_adjustment_vec outer)
1781 int i, outlen = VEC_length (ipa_parm_adjustment_t, outer);
1782 int inlen = VEC_length (ipa_parm_adjustment_t, inner);
1783 int removals = 0;
1784 ipa_parm_adjustment_vec adjustments, tmp;
1786 tmp = VEC_alloc (ipa_parm_adjustment_t, heap, inlen);
1787 for (i = 0; i < inlen; i++)
1789 struct ipa_parm_adjustment *n;
1790 n = VEC_index (ipa_parm_adjustment_t, inner, i);
1792 if (n->remove_param)
1793 removals++;
1794 else
1795 VEC_quick_push (ipa_parm_adjustment_t, tmp, n);
1798 adjustments = VEC_alloc (ipa_parm_adjustment_t, heap, outlen + removals);
1799 for (i = 0; i < outlen; i++)
1801 struct ipa_parm_adjustment *r;
1802 struct ipa_parm_adjustment *out = VEC_index (ipa_parm_adjustment_t,
1803 outer, i);
1804 struct ipa_parm_adjustment *in = VEC_index (ipa_parm_adjustment_t, tmp,
1805 out->base_index);
1807 gcc_assert (!in->remove_param);
1808 if (out->remove_param)
1810 if (!index_in_adjustments_multiple_times_p (in->base_index, tmp))
1812 r = VEC_quick_push (ipa_parm_adjustment_t, adjustments, NULL);
1813 memset (r, 0, sizeof (*r));
1814 r->remove_param = true;
1816 continue;
1819 r = VEC_quick_push (ipa_parm_adjustment_t, adjustments, NULL);
1820 memset (r, 0, sizeof (*r));
1821 r->base_index = in->base_index;
1822 r->type = out->type;
1824 /* FIXME: Create nonlocal value too. */
1826 if (in->copy_param && out->copy_param)
1827 r->copy_param = true;
1828 else if (in->copy_param)
1829 r->offset = out->offset;
1830 else if (out->copy_param)
1831 r->offset = in->offset;
1832 else
1833 r->offset = in->offset + out->offset;
1836 for (i = 0; i < inlen; i++)
1838 struct ipa_parm_adjustment *n = VEC_index (ipa_parm_adjustment_t,
1839 inner, i);
1841 if (n->remove_param)
1842 VEC_quick_push (ipa_parm_adjustment_t, adjustments, n);
1845 VEC_free (ipa_parm_adjustment_t, heap, tmp);
1846 return adjustments;
1849 /* Dump the adjustments in the vector ADJUSTMENTS to dump_file in a human
1850 friendly way, assuming they are meant to be applied to FNDECL. */
1852 void
1853 ipa_dump_param_adjustments (FILE *file, ipa_parm_adjustment_vec adjustments,
1854 tree fndecl)
1856 int i, len = VEC_length (ipa_parm_adjustment_t, adjustments);
1857 bool first = true;
1858 VEC(tree, heap) *parms = ipa_get_vector_of_formal_parms (fndecl);
1860 fprintf (file, "IPA param adjustments: ");
1861 for (i = 0; i < len; i++)
1863 struct ipa_parm_adjustment *adj;
1864 adj = VEC_index (ipa_parm_adjustment_t, adjustments, i);
1866 if (!first)
1867 fprintf (file, " ");
1868 else
1869 first = false;
1871 fprintf (file, "%i. base_index: %i - ", i, adj->base_index);
1872 print_generic_expr (file, VEC_index (tree, parms, adj->base_index), 0);
1873 if (adj->base)
1875 fprintf (file, ", base: ");
1876 print_generic_expr (file, adj->base, 0);
1878 if (adj->reduction)
1880 fprintf (file, ", reduction: ");
1881 print_generic_expr (file, adj->reduction, 0);
1883 if (adj->new_ssa_base)
1885 fprintf (file, ", new_ssa_base: ");
1886 print_generic_expr (file, adj->new_ssa_base, 0);
1889 if (adj->copy_param)
1890 fprintf (file, ", copy_param");
1891 else if (adj->remove_param)
1892 fprintf (file, ", remove_param");
1893 else
1894 fprintf (file, ", offset %li", (long) adj->offset);
1895 if (adj->by_ref)
1896 fprintf (file, ", by_ref");
1897 print_node_brief (file, ", type: ", adj->type, 0);
1898 fprintf (file, "\n");
1900 VEC_free (tree, heap, parms);
1903 /* Stream out jump function JUMP_FUNC to OB. */
1905 static void
1906 ipa_write_jump_function (struct output_block *ob,
1907 struct ipa_jump_func *jump_func)
1909 lto_output_uleb128_stream (ob->main_stream,
1910 jump_func->type);
1912 switch (jump_func->type)
1914 case IPA_JF_UNKNOWN:
1915 break;
1916 case IPA_JF_CONST:
1917 lto_output_tree (ob, jump_func->value.constant, true);
1918 break;
1919 case IPA_JF_PASS_THROUGH:
1920 lto_output_tree (ob, jump_func->value.pass_through.operand, true);
1921 lto_output_uleb128_stream (ob->main_stream,
1922 jump_func->value.pass_through.formal_id);
1923 lto_output_uleb128_stream (ob->main_stream,
1924 jump_func->value.pass_through.operation);
1925 break;
1926 case IPA_JF_ANCESTOR:
1927 lto_output_uleb128_stream (ob->main_stream,
1928 jump_func->value.ancestor.offset);
1929 lto_output_tree (ob, jump_func->value.ancestor.type, true);
1930 lto_output_uleb128_stream (ob->main_stream,
1931 jump_func->value.ancestor.formal_id);
1932 break;
1933 case IPA_JF_CONST_MEMBER_PTR:
1934 lto_output_tree (ob, jump_func->value.member_cst.pfn, true);
1935 lto_output_tree (ob, jump_func->value.member_cst.delta, false);
1936 break;
1940 /* Read in jump function JUMP_FUNC from IB. */
1942 static void
1943 ipa_read_jump_function (struct lto_input_block *ib,
1944 struct ipa_jump_func *jump_func,
1945 struct data_in *data_in)
1947 jump_func->type = (enum jump_func_type) lto_input_uleb128 (ib);
1949 switch (jump_func->type)
1951 case IPA_JF_UNKNOWN:
1952 break;
1953 case IPA_JF_CONST:
1954 jump_func->value.constant = lto_input_tree (ib, data_in);
1955 break;
1956 case IPA_JF_PASS_THROUGH:
1957 jump_func->value.pass_through.operand = lto_input_tree (ib, data_in);
1958 jump_func->value.pass_through.formal_id = lto_input_uleb128 (ib);
1959 jump_func->value.pass_through.operation = (enum tree_code) lto_input_uleb128 (ib);
1960 break;
1961 case IPA_JF_ANCESTOR:
1962 jump_func->value.ancestor.offset = lto_input_uleb128 (ib);
1963 jump_func->value.ancestor.type = lto_input_tree (ib, data_in);
1964 jump_func->value.ancestor.formal_id = lto_input_uleb128 (ib);
1965 break;
1966 case IPA_JF_CONST_MEMBER_PTR:
1967 jump_func->value.member_cst.pfn = lto_input_tree (ib, data_in);
1968 jump_func->value.member_cst.delta = lto_input_tree (ib, data_in);
1969 break;
1973 /* Stream out a parameter call note. */
1975 static void
1976 ipa_write_param_call_note (struct output_block *ob,
1977 struct ipa_param_call_note *note)
1979 gcc_assert (!note->processed);
1980 lto_output_uleb128_stream (ob->main_stream, gimple_uid (note->stmt));
1981 lto_output_sleb128_stream (ob->main_stream, note->formal_id);
1982 lto_output_sleb128_stream (ob->main_stream, note->count);
1983 lto_output_sleb128_stream (ob->main_stream, note->frequency);
1984 lto_output_sleb128_stream (ob->main_stream, note->loop_nest);
1987 /* Read in a parameter call note. */
1989 static void
1990 ipa_read_param_call_note (struct lto_input_block *ib,
1991 struct ipa_node_params *info)
1994 struct ipa_param_call_note *note = XCNEW (struct ipa_param_call_note);
1996 note->lto_stmt_uid = (unsigned int) lto_input_uleb128 (ib);
1997 note->formal_id = (int) lto_input_sleb128 (ib);
1998 note->count = (gcov_type) lto_input_sleb128 (ib);
1999 note->frequency = (int) lto_input_sleb128 (ib);
2000 note->loop_nest = (int) lto_input_sleb128 (ib);
2002 note->next = info->param_calls;
2003 info->param_calls = note;
2007 /* Stream out NODE info to OB. */
2009 static void
2010 ipa_write_node_info (struct output_block *ob, struct cgraph_node *node)
2012 int node_ref;
2013 lto_cgraph_encoder_t encoder;
2014 struct ipa_node_params *info = IPA_NODE_REF (node);
2015 int j;
2016 struct cgraph_edge *e;
2017 struct bitpack_d *bp;
2018 int note_count = 0;
2019 struct ipa_param_call_note *note;
2021 encoder = ob->decl_state->cgraph_node_encoder;
2022 node_ref = lto_cgraph_encoder_encode (encoder, node);
2023 lto_output_uleb128_stream (ob->main_stream, node_ref);
2025 bp = bitpack_create ();
2026 bp_pack_value (bp, info->called_with_var_arguments, 1);
2027 bp_pack_value (bp, info->uses_analysis_done, 1);
2028 gcc_assert (info->modification_analysis_done
2029 || ipa_get_param_count (info) == 0);
2030 gcc_assert (!info->node_enqueued);
2031 gcc_assert (!info->ipcp_orig_node);
2032 for (j = 0; j < ipa_get_param_count (info); j++)
2033 bp_pack_value (bp, info->params[j].modified, 1);
2034 lto_output_bitpack (ob->main_stream, bp);
2035 bitpack_delete (bp);
2036 for (e = node->callees; e; e = e->next_callee)
2038 struct ipa_edge_args *args = IPA_EDGE_REF (e);
2040 lto_output_uleb128_stream (ob->main_stream,
2041 ipa_get_cs_argument_count (args));
2042 for (j = 0; j < ipa_get_cs_argument_count (args); j++)
2043 ipa_write_jump_function (ob, ipa_get_ith_jump_func (args, j));
2046 for (note = info->param_calls; note; note = note->next)
2047 note_count++;
2048 lto_output_uleb128_stream (ob->main_stream, note_count);
2049 for (note = info->param_calls; note; note = note->next)
2050 ipa_write_param_call_note (ob, note);
2053 /* Srtream in NODE info from IB. */
2055 static void
2056 ipa_read_node_info (struct lto_input_block *ib, struct cgraph_node *node,
2057 struct data_in *data_in)
2059 struct ipa_node_params *info = IPA_NODE_REF (node);
2060 int k;
2061 struct cgraph_edge *e;
2062 struct bitpack_d *bp;
2063 int i, note_count;
2065 ipa_initialize_node_params (node);
2067 bp = lto_input_bitpack (ib);
2068 info->called_with_var_arguments = bp_unpack_value (bp, 1);
2069 info->uses_analysis_done = bp_unpack_value (bp, 1);
2070 if (ipa_get_param_count (info) != 0)
2072 info->modification_analysis_done = true;
2073 info->uses_analysis_done = true;
2075 info->node_enqueued = false;
2076 for (k = 0; k < ipa_get_param_count (info); k++)
2077 info->params[k].modified = bp_unpack_value (bp, 1);
2078 bitpack_delete (bp);
2079 for (e = node->callees; e; e = e->next_callee)
2081 struct ipa_edge_args *args = IPA_EDGE_REF (e);
2082 int count = lto_input_uleb128 (ib);
2084 ipa_set_cs_argument_count (args, count);
2085 if (!count)
2086 continue;
2088 args->jump_functions = GGC_CNEWVEC (struct ipa_jump_func,
2089 ipa_get_cs_argument_count (args));
2090 for (k = 0; k < ipa_get_cs_argument_count (args); k++)
2091 ipa_read_jump_function (ib, ipa_get_ith_jump_func (args, k), data_in);
2094 note_count = lto_input_uleb128 (ib);
2095 for (i = 0; i < note_count; i++)
2096 ipa_read_param_call_note (ib, info);
2099 /* Write jump functions for nodes in SET. */
2101 void
2102 ipa_prop_write_jump_functions (cgraph_node_set set)
2104 struct cgraph_node *node;
2105 struct output_block *ob = create_output_block (LTO_section_jump_functions);
2106 unsigned int count = 0;
2107 cgraph_node_set_iterator csi;
2109 ob->cgraph_node = NULL;
2111 for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
2113 node = csi_node (csi);
2114 if (node->analyzed && IPA_NODE_REF (node) != NULL)
2115 count++;
2118 lto_output_uleb128_stream (ob->main_stream, count);
2120 /* Process all of the functions. */
2121 for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
2123 node = csi_node (csi);
2124 if (node->analyzed && IPA_NODE_REF (node) != NULL)
2125 ipa_write_node_info (ob, node);
2127 lto_output_1_stream (ob->main_stream, 0);
2128 produce_asm (ob, NULL);
2129 destroy_output_block (ob);
2132 /* Read section in file FILE_DATA of length LEN with data DATA. */
2134 static void
2135 ipa_prop_read_section (struct lto_file_decl_data *file_data, const char *data,
2136 size_t len)
2138 const struct lto_function_header *header =
2139 (const struct lto_function_header *) data;
2140 const int32_t cfg_offset = sizeof (struct lto_function_header);
2141 const int32_t main_offset = cfg_offset + header->cfg_size;
2142 const int32_t string_offset = main_offset + header->main_size;
2143 struct data_in *data_in;
2144 struct lto_input_block ib_main;
2145 unsigned int i;
2146 unsigned int count;
2148 LTO_INIT_INPUT_BLOCK (ib_main, (const char *) data + main_offset, 0,
2149 header->main_size);
2151 data_in =
2152 lto_data_in_create (file_data, (const char *) data + string_offset,
2153 header->string_size, NULL);
2154 count = lto_input_uleb128 (&ib_main);
2156 for (i = 0; i < count; i++)
2158 unsigned int index;
2159 struct cgraph_node *node;
2160 lto_cgraph_encoder_t encoder;
2162 index = lto_input_uleb128 (&ib_main);
2163 encoder = file_data->cgraph_node_encoder;
2164 node = lto_cgraph_encoder_deref (encoder, index);
2165 ipa_read_node_info (&ib_main, node, data_in);
2167 lto_free_section_data (file_data, LTO_section_jump_functions, NULL, data,
2168 len);
2169 lto_data_in_delete (data_in);
2172 /* Read ipcp jump functions. */
2174 void
2175 ipa_prop_read_jump_functions (void)
2177 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
2178 struct lto_file_decl_data *file_data;
2179 unsigned int j = 0;
2181 ipa_check_create_node_params ();
2182 ipa_check_create_edge_args ();
2183 ipa_register_cgraph_hooks ();
2185 while ((file_data = file_data_vec[j++]))
2187 size_t len;
2188 const char *data = lto_get_section_data (file_data, LTO_section_jump_functions, NULL, &len);
2190 if (data)
2191 ipa_prop_read_section (file_data, data, len);
2195 /* After merging units, we can get mismatch in argument counts.
2196 Also decl merging might've rendered parameter lists obsolette.
2197 Also compute called_with_variable_arg info. */
2199 void
2200 ipa_update_after_lto_read (void)
2202 struct cgraph_node *node;
2203 struct cgraph_edge *cs;
2205 ipa_check_create_node_params ();
2206 ipa_check_create_edge_args ();
2208 for (node = cgraph_nodes; node; node = node->next)
2209 if (node->analyzed)
2210 ipa_initialize_node_params (node);
2212 for (node = cgraph_nodes; node; node = node->next)
2213 if (node->analyzed)
2214 for (cs = node->callees; cs; cs = cs->next_callee)
2216 if (ipa_get_cs_argument_count (IPA_EDGE_REF (cs))
2217 != ipa_get_param_count (IPA_NODE_REF (cs->callee)))
2218 ipa_set_called_with_variable_arg (IPA_NODE_REF (cs->callee));
2222 /* Walk param call notes of NODE and set their call statements given the uid
2223 stored in each note and STMTS which is an array of statements indexed by the
2224 uid. */
2226 void
2227 lto_ipa_fixup_call_notes (struct cgraph_node *node, gimple *stmts)
2229 struct ipa_node_params *info;
2230 struct ipa_param_call_note *note;
2232 ipa_check_create_node_params ();
2233 info = IPA_NODE_REF (node);
2234 note = info->param_calls;
2235 /* If there are no notes or they have already been fixed up (the same fixup
2236 is called for both inlining and ipa-cp), there's nothing to do. */
2237 if (!note || note->stmt)
2238 return;
2242 note->stmt = stmts[note->lto_stmt_uid];
2243 note = note->next;
2245 while (note);