OSDN Git Service

2010-05-20 Segher Boessenkool <segher@kernel.crashing.org>
[pf3gnuchains/gcc-fork.git] / gcc / ipa-prop.c
1 /* Interprocedural analyses.
2    Copyright (C) 2005, 2007, 2008, 2009, 2010
3    Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3.  If not see
19 <http://www.gnu.org/licenses/>.  */
20
21 #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 "gimple.h"
34 #include "flags.h"
35 #include "timevar.h"
36 #include "flags.h"
37 #include "diagnostic.h"
38 #include "lto-streamer.h"
39
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;
44
45 /* Bitmap with all UIDs of call graph edges that have been already processed
46    by indirect inlining.  */
47 static bitmap iinlining_processed_edges;
48
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;
54
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.  */
58
59 void
60 ipa_push_func_to_list_1 (struct ipa_func_list **wl,
61                          struct cgraph_node *node,
62                          struct ipa_node_params *info)
63 {
64   struct ipa_func_list *temp;
65
66   info->node_enqueued = 1;
67   temp = XCNEW (struct ipa_func_list);
68   temp->node = node;
69   temp->next = *wl;
70   *wl = temp;
71 }
72
73 /* Initialize worklist to contain all functions.  */
74
75 struct ipa_func_list *
76 ipa_init_func_list (void)
77 {
78   struct cgraph_node *node;
79   struct ipa_func_list * wl;
80
81   wl = NULL;
82   for (node = cgraph_nodes; node; node = node->next)
83     if (node->analyzed)
84       {
85         struct ipa_node_params *info = IPA_NODE_REF (node);
86         /* Unreachable nodes should have been eliminated before ipcp and
87            inlining.  */
88         gcc_assert (node->needed || node->reachable);
89         ipa_push_func_to_list_1 (&wl, node, info);
90       }
91
92   return wl;
93 }
94
95 /* Remove a function from the worklist WL and return it.  */
96
97 struct cgraph_node *
98 ipa_pop_func_from_list (struct ipa_func_list **wl)
99 {
100   struct ipa_node_params *info;
101   struct ipa_func_list *first;
102   struct cgraph_node *node;
103
104   first = *wl;
105   *wl = (*wl)->next;
106   node = first->node;
107   free (first);
108
109   info = IPA_NODE_REF (node);
110   info->node_enqueued = 0;
111   return node;
112 }
113
114 /* Return index of the formal whose tree is PTREE in function which corresponds
115    to INFO.  */
116
117 static int
118 ipa_get_param_decl_index (struct ipa_node_params *info, tree ptree)
119 {
120   int i, count;
121
122   count = ipa_get_param_count (info);
123   for (i = 0; i < count; i++)
124     if (ipa_get_param(info, i) == ptree)
125       return i;
126
127   return -1;
128 }
129
130 /* Populate the param_decl field in parameter descriptors of INFO that
131    corresponds to NODE.  */
132
133 static void
134 ipa_populate_param_decls (struct cgraph_node *node,
135                           struct ipa_node_params *info)
136 {
137   tree fndecl;
138   tree fnargs;
139   tree parm;
140   int param_num;
141
142   fndecl = node->decl;
143   fnargs = DECL_ARGUMENTS (fndecl);
144   param_num = 0;
145   for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
146     {
147       info->params[param_num].decl = parm;
148       param_num++;
149     }
150 }
151
152 /* Return how many formal parameters FNDECL has.  */
153
154 static inline int
155 count_formal_params_1 (tree fndecl)
156 {
157   tree parm;
158   int count = 0;
159
160   for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm))
161     count++;
162
163   return count;
164 }
165
166 /* Count number of formal parameters in NOTE. Store the result to the
167    appropriate field of INFO.  */
168
169 static void
170 ipa_count_formal_params (struct cgraph_node *node,
171                          struct ipa_node_params *info)
172 {
173   int param_num;
174
175   param_num = count_formal_params_1 (node->decl);
176   ipa_set_param_count (info, param_num);
177 }
178
179 /* Initialize the ipa_node_params structure associated with NODE by counting
180    the function parameters, creating the descriptors and populating their
181    param_decls.  */
182
183 void
184 ipa_initialize_node_params (struct cgraph_node *node)
185 {
186   struct ipa_node_params *info = IPA_NODE_REF (node);
187
188   if (!info->params)
189     {
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);
194     }
195 }
196
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.  */
200
201 static bool
202 visit_store_addr_for_mod_analysis (gimple stmt ATTRIBUTE_UNUSED,
203                                    tree op, void *data)
204 {
205   struct ipa_node_params *info = (struct ipa_node_params *) data;
206
207   op = get_base_address (op);
208   if (op
209       && TREE_CODE (op) == PARM_DECL)
210     {
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;
215     }
216
217   return false;
218 }
219
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
222    passed in DATA.  */
223
224 static bool
225 visit_load_for_mod_analysis (gimple stmt ATTRIBUTE_UNUSED,
226                              tree op, void *data)
227 {
228   struct ipa_node_params *info = (struct ipa_node_params *) data;
229
230   op = get_base_address (op);
231   if (op
232       && TREE_CODE (op) == PARM_DECL)
233     {
234       int index = ipa_get_param_decl_index (info, op);
235       gcc_assert (index >= 0);
236       info->params[index].used = true;
237     }
238
239   return false;
240 }
241
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
245    differently.  */
246
247 void
248 ipa_detect_param_modifications (struct cgraph_node *node)
249 {
250   tree decl = node->decl;
251   basic_block bb;
252   struct function *func;
253   gimple_stmt_iterator gsi;
254   struct ipa_node_params *info = IPA_NODE_REF (node);
255   int i;
256
257   if (ipa_get_param_count (info) == 0 || info->modification_analysis_done)
258     return;
259
260   for (i = 0; i < ipa_get_param_count (info); i++)
261     {
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;
268     }
269
270   func = DECL_STRUCT_FUNCTION (decl);
271   FOR_EACH_BB_FN (bb, func)
272     {
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);
283     }
284
285   info->modification_analysis_done = 1;
286 }
287
288 /* Count number of arguments callsite CS has and store it in
289    ipa_edge_args structure corresponding to this callsite.  */
290
291 void
292 ipa_count_arguments (struct cgraph_edge *cs)
293 {
294   gimple stmt;
295   int arg_num;
296
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);
305 }
306
307 /* Print the jump functions associated with call graph edge CS to file F.  */
308
309 static void
310 ipa_print_node_jump_functions_for_edge (FILE *f, struct cgraph_edge *cs)
311 {
312   int i, count;
313
314   count = ipa_get_cs_argument_count (IPA_EDGE_REF (cs));
315   for (i = 0; i < count; i++)
316     {
317       struct ipa_jump_func *jump_func;
318       enum jump_func_type type;
319
320       jump_func = ipa_get_ith_jump_func (IPA_EDGE_REF (cs), i);
321       type = jump_func->type;
322
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)
327         {
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));
332         }
333       else if (type == IPA_JF_CONST)
334         {
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)
340             {
341               fprintf (f, " -> ");
342               print_generic_expr (f, DECL_INITIAL (TREE_OPERAND (val, 0)),
343                                   0);
344             }
345           fprintf (f, "\n");
346         }
347       else if (type == IPA_JF_CONST_MEMBER_PTR)
348         {
349           fprintf (f, "CONST MEMBER PTR: ");
350           print_generic_expr (f, jump_func->value.member_cst.pfn, 0);
351           fprintf (f, ", ");
352           print_generic_expr (f, jump_func->value.member_cst.delta, 0);
353           fprintf (f, "\n");
354         }
355       else if (type == IPA_JF_PASS_THROUGH)
356         {
357           fprintf (f, "PASS THROUGH: ");
358           fprintf (f, "%d, op %s ",
359                    jump_func->value.pass_through.formal_id,
360                    tree_code_name[(int)
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");
366         }
367       else if (type == IPA_JF_ANCESTOR)
368         {
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");
375         }
376     }
377 }
378
379
380 /* Print the jump functions of all arguments on all call graph edges going from
381    NODE to file F.  */
382
383 void
384 ipa_print_node_jump_functions (FILE *f, struct cgraph_node *node)
385 {
386   struct cgraph_edge *cs;
387   int i;
388
389   fprintf (f, "  Jump functions of caller  %s:\n", cgraph_node_name (node));
390   for (cs = node->callees; cs; cs = cs->next_callee)
391     {
392       if (!ipa_edge_args_info_available_for_edge_p (cs))
393         continue;
394
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);
399     }
400
401   for (cs = node->indirect_calls, i = 0; cs; cs = cs->next_callee, i++)
402     {
403       if (!ipa_edge_args_info_available_for_edge_p (cs))
404         continue;
405
406       if (cs->call_stmt)
407         {
408           fprintf (f, "    indirect callsite %d for stmt ", i);
409           print_gimple_stmt (f, cs->call_stmt, 0, TDF_SLIM);
410         }
411       else
412         fprintf (f, "    indirect callsite %d :\n", i);
413       ipa_print_node_jump_functions_for_edge (f, cs);
414
415     }
416 }
417
418 /* Print ipa_jump_func data structures of all nodes in the call graph to F.  */
419
420 void
421 ipa_print_all_jump_functions (FILE *f)
422 {
423   struct cgraph_node *node;
424
425   fprintf (f, "\nJump functions:\n");
426   for (node = cgraph_nodes; node; node = node->next)
427     {
428       ipa_print_node_jump_functions (f, node);
429     }
430 }
431
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
436    JFUNC */
437
438 static void
439 compute_complex_assign_jump_func (struct ipa_node_params *info,
440                                   struct ipa_jump_func *jfunc,
441                                   gimple stmt, tree name)
442 {
443   HOST_WIDE_INT offset, size, max_size;
444   tree op1, op2, type;
445   int index;
446
447   op1 = gimple_assign_rhs1 (stmt);
448   op2 = gimple_assign_rhs2 (stmt);
449
450   if (TREE_CODE (op1) == SSA_NAME
451       && SSA_NAME_IS_DEFAULT_DEF (op1))
452     {
453       index = ipa_get_param_decl_index (info, SSA_NAME_VAR (op1));
454       if (index < 0)
455         return;
456
457       if (op2)
458         {
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),
462                                                  TREE_TYPE (op1))))
463             return;
464
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;
469         }
470       else if (gimple_assign_unary_nop_p (stmt))
471         {
472           jfunc->type = IPA_JF_PASS_THROUGH;
473           jfunc->value.pass_through.formal_id = index;
474           jfunc->value.pass_through.operation = NOP_EXPR;
475         }
476       return;
477     }
478
479   if (TREE_CODE (op1) != ADDR_EXPR)
480     return;
481
482   op1 = TREE_OPERAND (op1, 0);
483   type = TREE_TYPE (op1);
484   if (TREE_CODE (type) != RECORD_TYPE)
485     return;
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.  */
489       || max_size == -1
490       || max_size != size)
491     return;
492   op1 = TREE_OPERAND (op1, 0);
493   if (TREE_CODE (op1) != SSA_NAME
494       || !SSA_NAME_IS_DEFAULT_DEF (op1))
495     return;
496
497   index = ipa_get_param_decl_index (info, SSA_NAME_VAR (op1));
498   if (index >= 0)
499     {
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;
504     }
505 }
506
507
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.
513
514    Essentially we want to match the following pattern:
515
516      if (obj_2(D) != 0B)
517        goto <bb 3>;
518      else
519        goto <bb 4>;
520
521    <bb 3>:
522      iftmp.1_3 = &obj_2(D)->D.1762;
523
524    <bb 4>:
525      # iftmp.1_1 = PHI <iftmp.1_3(3), 0B(2)>
526      D.1879_6 = middleman_1 (iftmp.1_1, i_5(D));
527      return D.1879_6;  */
528
529 static void
530 compute_complex_ancestor_jump_func (struct ipa_node_params *info,
531                                     struct ipa_jump_func *jfunc,
532                                     gimple phi)
533 {
534   HOST_WIDE_INT offset, size, max_size;
535   gimple assign, cond;
536   basic_block phi_bb, assign_bb, cond_bb;
537   tree tmp, parm, expr;
538   int index, i;
539
540   if (gimple_phi_num_args (phi) != 2
541       || !integer_zerop (PHI_ARG_DEF (phi, 1)))
542     return;
543
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)
549     return;
550
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))
555     return;
556   expr = gimple_assign_rhs1 (assign);
557
558   if (TREE_CODE (expr) != ADDR_EXPR)
559     return;
560   expr = TREE_OPERAND (expr, 0);
561   expr = get_ref_base_and_extent (expr, &offset, &size, &max_size);
562
563   if (TREE_CODE (expr) != INDIRECT_REF
564       /* If this is a varying address, punt.  */
565       || max_size == -1
566       || max_size != size)
567     return;
568   parm = TREE_OPERAND (expr, 0);
569   if (TREE_CODE (parm) != SSA_NAME
570       || !SSA_NAME_IS_DEFAULT_DEF (parm))
571     return;
572
573   index = ipa_get_param_decl_index (info, SSA_NAME_VAR (parm));
574   if (index < 0)
575     return;
576
577   cond_bb = single_pred (assign_bb);
578   cond = last_stmt (cond_bb);
579   if (!cond
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)))
584     return;
585
586
587   phi_bb = gimple_bb (phi);
588   for (i = 0; i < 2; i++)
589     {
590       basic_block pred = EDGE_PRED (phi_bb, i)->src;
591       if (pred != assign_bb && pred != cond_bb)
592         return;
593     }
594
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));
599 }
600
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.  */
604
605 static void
606 compute_known_type_jump_func (tree op, struct ipa_jump_func *jfunc)
607 {
608   tree binfo;
609
610   if (TREE_CODE (op) != ADDR_EXPR)
611     return;
612
613   op = TREE_OPERAND (op, 0);
614   binfo = gimple_get_relevant_ref_binfo (op, NULL_TREE);
615   if (binfo)
616     {
617       jfunc->type = IPA_JF_KNOWN_TYPE;
618       jfunc->value.base_binfo = binfo;
619     }
620 }
621
622
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
627    being examined.*/
628
629 static void
630 compute_scalar_jump_functions (struct ipa_node_params *info,
631                                struct ipa_jump_func *functions,
632                                gimple call)
633 {
634   tree arg;
635   unsigned num = 0;
636
637   for (num = 0; num < gimple_call_num_args (call); num++)
638     {
639       arg = gimple_call_arg (call, num);
640
641       if (is_gimple_ip_invariant (arg))
642         {
643           functions[num].type = IPA_JF_CONST;
644           functions[num].value.constant = arg;
645         }
646       else if (TREE_CODE (arg) == SSA_NAME)
647         {
648           if (SSA_NAME_IS_DEFAULT_DEF (arg))
649             {
650               int index = ipa_get_param_decl_index (info, SSA_NAME_VAR (arg));
651
652               if (index >= 0)
653                 {
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;
657                 }
658             }
659           else
660             {
661               gimple stmt = SSA_NAME_DEF_STMT (arg);
662               if (is_gimple_assign (stmt))
663                 compute_complex_assign_jump_func (info, &functions[num],
664                                                   stmt, arg);
665               else if (gimple_code (stmt) == GIMPLE_PHI)
666                 compute_complex_ancestor_jump_func (info, &functions[num],
667                                                     stmt);
668             }
669         }
670       else
671         compute_known_type_jump_func (arg, &functions[num]);
672     }
673 }
674
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.  */
679
680 static bool
681 type_like_member_ptr_p (tree type, tree *method_ptr, tree *delta)
682 {
683   tree fld;
684
685   if (TREE_CODE (type) != RECORD_TYPE)
686     return false;
687
688   fld = TYPE_FIELDS (type);
689   if (!fld || !POINTER_TYPE_P (TREE_TYPE (fld))
690       || TREE_CODE (TREE_TYPE (TREE_TYPE (fld))) != METHOD_TYPE)
691     return false;
692
693   if (method_ptr)
694     *method_ptr = fld;
695
696   fld = TREE_CHAIN (fld);
697   if (!fld || INTEGRAL_TYPE_P (fld))
698     return false;
699   if (delta)
700     *delta = fld;
701
702   if (TREE_CHAIN (fld))
703     return false;
704
705   return true;
706 }
707
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.  */
713
714 static bool
715 compute_pass_through_member_ptrs (struct ipa_node_params *info,
716                                   struct ipa_jump_func *functions,
717                                   gimple call)
718 {
719   bool undecided_members = false;
720   unsigned num;
721   tree arg;
722
723   for (num = 0; num < gimple_call_num_args (call); num++)
724     {
725       arg = gimple_call_arg (call, num);
726
727       if (type_like_member_ptr_p (TREE_TYPE (arg), NULL, NULL))
728         {
729           if (TREE_CODE (arg) == PARM_DECL)
730             {
731               int index = ipa_get_param_decl_index (info, arg);
732
733               gcc_assert (index >=0);
734               if (!ipa_is_param_modified (info, index))
735                 {
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;
739                 }
740               else
741                 undecided_members = true;
742             }
743           else
744             undecided_members = true;
745         }
746     }
747
748   return undecided_members;
749 }
750
751 /* Simple function filling in a member pointer constant jump function (with PFN
752    and DELTA as the constant value) into JFUNC.  */
753
754 static void
755 fill_member_ptr_cst_jump_function (struct ipa_jump_func *jfunc,
756                                    tree pfn, tree delta)
757 {
758   jfunc->type = IPA_JF_CONST_MEMBER_PTR;
759   jfunc->value.member_cst.pfn = pfn;
760   jfunc->value.member_cst.delta = delta;
761 }
762
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.  */
765
766 static inline tree
767 get_ssa_def_if_simple_copy (tree rhs)
768 {
769   while (TREE_CODE (rhs) == SSA_NAME && !SSA_NAME_IS_DEFAULT_DEF (rhs))
770     {
771       gimple def_stmt = SSA_NAME_DEF_STMT (rhs);
772
773       if (gimple_assign_single_p (def_stmt))
774         rhs = gimple_assign_rhs1 (def_stmt);
775       else
776         break;
777     }
778   return rhs;
779 }
780
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:
786
787      D.2515.__pfn ={v} printStuff;
788      D.2515.__delta ={v} 0;
789      i_1 = doprinting (D.2515);  */
790
791 static void
792 determine_cst_member_ptr (gimple call, tree arg, tree method_field,
793                           tree delta_field, struct ipa_jump_func *jfunc)
794 {
795   gimple_stmt_iterator gsi;
796   tree method = NULL_TREE;
797   tree delta = NULL_TREE;
798
799   gsi = gsi_for_stmt (call);
800
801   gsi_prev (&gsi);
802   for (; !gsi_end_p (gsi); gsi_prev (&gsi))
803     {
804       gimple stmt = gsi_stmt (gsi);
805       tree lhs, rhs, fld;
806
807       if (!gimple_assign_single_p (stmt))
808         return;
809
810       lhs = gimple_assign_lhs (stmt);
811       rhs = gimple_assign_rhs1 (stmt);
812
813       if (TREE_CODE (lhs) != COMPONENT_REF
814           || TREE_OPERAND (lhs, 0) != arg)
815         continue;
816
817       fld = TREE_OPERAND (lhs, 1);
818       if (!method && fld == method_field)
819         {
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)
824             {
825               method = TREE_OPERAND (rhs, 0);
826               if (delta)
827                 {
828                   fill_member_ptr_cst_jump_function (jfunc, rhs, delta);
829                   return;
830                 }
831             }
832           else
833             return;
834         }
835
836       if (!delta && fld == delta_field)
837         {
838           rhs = get_ssa_def_if_simple_copy (rhs);
839           if (TREE_CODE (rhs) == INTEGER_CST)
840             {
841               delta = rhs;
842               if (method)
843                 {
844                   fill_member_ptr_cst_jump_function (jfunc, rhs, delta);
845                   return;
846                 }
847             }
848           else
849             return;
850         }
851     }
852
853   return;
854 }
855
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.  */
860
861 static void
862 compute_cst_member_ptr_arguments (struct ipa_jump_func *functions,
863                                   gimple call)
864 {
865   unsigned num;
866   tree arg, method_field, delta_field;
867
868   for (num = 0; num < gimple_call_num_args (call); num++)
869     {
870       arg = gimple_call_arg (call, num);
871
872       if (functions[num].type == IPA_JF_UNKNOWN
873           && type_like_member_ptr_p (TREE_TYPE (arg), &method_field,
874                                      &delta_field))
875         determine_cst_member_ptr (call, arg, method_field, delta_field,
876                                   &functions[num]);
877     }
878 }
879
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
882    to this callsite.  */
883
884 static void
885 ipa_compute_jump_functions_for_edge (struct cgraph_edge *cs)
886 {
887   struct ipa_node_params *info = IPA_NODE_REF (cs->caller);
888   struct ipa_edge_args *arguments = IPA_EDGE_REF (cs);
889   gimple call;
890
891   if (ipa_get_cs_argument_count (arguments) == 0 || arguments->jump_functions)
892     return;
893   arguments->jump_functions = GGC_CNEWVEC (struct ipa_jump_func,
894                                            ipa_get_cs_argument_count (arguments));
895
896   call = cs->call_stmt;
897   gcc_assert (is_gimple_call (call));
898
899   /* We will deal with constants and SSA scalars first:  */
900   compute_scalar_jump_functions (info, arguments->jump_functions, call);
901
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))
905     return;
906
907   /* Finally, let's check whether we actually pass a new constant member
908      pointer here...  */
909   compute_cst_member_ptr_arguments (arguments->jump_functions, call);
910 }
911
912 /* Compute jump functions for all edges - both direct and indirect - outgoing
913    from NODE.  Also count the actual arguments in the process.  */
914
915 void
916 ipa_compute_jump_functions (struct cgraph_node *node)
917 {
918   struct cgraph_edge *cs;
919
920   for (cs = node->callees; cs; cs = cs->next_callee)
921     {
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)
925         continue;
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);
931     }
932
933   for (cs = node->indirect_calls; cs; cs = cs->next_callee)
934     {
935       ipa_count_arguments (cs);
936       ipa_compute_jump_functions_for_edge (cs);
937     }
938 }
939
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.  */
944
945 static tree
946 ipa_get_member_ptr_load_param (tree rhs, bool use_delta)
947 {
948   tree rec, fld;
949   tree ptr_field;
950   tree delta_field;
951
952   if (TREE_CODE (rhs) != COMPONENT_REF)
953     return NULL_TREE;
954
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))
958     return NULL_TREE;
959
960   fld = TREE_OPERAND (rhs, 1);
961   if (use_delta ? (fld == delta_field) : (fld == ptr_field))
962     return rec;
963   else
964     return NULL_TREE;
965 }
966
967 /* If STMT looks like a statement loading a value from a member pointer formal
968    parameter, this function returns that parameter.  */
969
970 static tree
971 ipa_get_stmt_member_ptr_load_param (gimple stmt, bool use_delta)
972 {
973   tree rhs;
974
975   if (!gimple_assign_single_p (stmt))
976     return NULL_TREE;
977
978   rhs = gimple_assign_rhs1 (stmt);
979   return ipa_get_member_ptr_load_param (rhs, use_delta);
980 }
981
982 /* Returns true iff T is an SSA_NAME defined by a statement.  */
983
984 static bool
985 ipa_is_ssa_with_stmt_def (tree t)
986 {
987   if (TREE_CODE (t) == SSA_NAME
988       && !SSA_NAME_IS_DEFAULT_DEF (t))
989     return true;
990   else
991     return false;
992 }
993
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
997    virtual one.  */
998
999 static void
1000 ipa_note_param_call (struct cgraph_node *node, int param_index, gimple stmt,
1001                      bool polymorphic)
1002 {
1003   struct cgraph_edge *cs;
1004
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;
1009   if (polymorphic)
1010     {
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;
1016     }
1017 }
1018
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:
1027
1028      <bb 2>:
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;
1033        if (D.2497_4 != 0)
1034          goto <bb 3>;
1035        else
1036          goto <bb 4>;
1037
1038      <bb 3>:
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;
1048
1049      <bb 4>:
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);
1054
1055    Such patterns are results of simple calls to a member pointer:
1056
1057      int doprinting (int (MyString::* f)(int) const)
1058      {
1059        MyString S ("somestring");
1060
1061        return (S.*f)(4);
1062      }
1063 */
1064
1065 static void
1066 ipa_analyze_indirect_call_uses (struct cgraph_node *node,
1067                                 struct ipa_node_params *info,
1068                                 gimple call, tree target)
1069 {
1070   gimple def;
1071   tree n1, n2;
1072   gimple d1, d2;
1073   tree rec, rec2, cond;
1074   gimple branch;
1075   int index;
1076   basic_block bb, virt_bb, join;
1077
1078   if (SSA_NAME_IS_DEFAULT_DEF (target))
1079     {
1080       tree var = SSA_NAME_VAR (target);
1081       index = ipa_get_param_decl_index (info, var);
1082       if (index >= 0)
1083         ipa_note_param_call (node, index, call, false);
1084       return;
1085     }
1086
1087   /* Now we need to try to match the complex pattern of calling a member
1088      pointer. */
1089
1090   if (!POINTER_TYPE_P (TREE_TYPE (target))
1091       || TREE_CODE (TREE_TYPE (TREE_TYPE (target))) != METHOD_TYPE)
1092     return;
1093
1094   def = SSA_NAME_DEF_STMT (target);
1095   if (gimple_code (def) != GIMPLE_PHI)
1096     return;
1097
1098   if (gimple_phi_num_args (def) != 2)
1099     return;
1100
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))
1106     return;
1107   d1 = SSA_NAME_DEF_STMT (n1);
1108   d2 = SSA_NAME_DEF_STMT (n2);
1109
1110   if ((rec = ipa_get_stmt_member_ptr_load_param (d1, false)))
1111     {
1112       if (ipa_get_stmt_member_ptr_load_param (d2, false))
1113         return;
1114
1115       bb = gimple_bb (d1);
1116       virt_bb = gimple_bb (d2);
1117     }
1118   else if ((rec = ipa_get_stmt_member_ptr_load_param (d2, false)))
1119     {
1120       bb = gimple_bb (d2);
1121       virt_bb = gimple_bb (d1);
1122     }
1123   else
1124     return;
1125
1126   /* Second, we need to check that the basic blocks are laid out in the way
1127      corresponding to the pattern. */
1128
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)
1133     return;
1134
1135   /* Third, let's see that the branching is done depending on the least
1136      significant bit of the pfn. */
1137
1138   branch = last_stmt (bb);
1139   if (gimple_code (branch) != GIMPLE_COND)
1140     return;
1141
1142   if (gimple_cond_code (branch) != NE_EXPR
1143       || !integer_zerop (gimple_cond_rhs (branch)))
1144     return;
1145
1146   cond = gimple_cond_lhs (branch);
1147   if (!ipa_is_ssa_with_stmt_def (cond))
1148     return;
1149
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)))
1154     return;
1155
1156   cond = gimple_assign_rhs1 (def);
1157   if (!ipa_is_ssa_with_stmt_def (cond))
1158     return;
1159
1160   def = SSA_NAME_DEF_STMT (cond);
1161
1162   if (is_gimple_assign (def)
1163       && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def)))
1164     {
1165       cond = gimple_assign_rhs1 (def);
1166       if (!ipa_is_ssa_with_stmt_def (cond))
1167         return;
1168       def = SSA_NAME_DEF_STMT (cond);
1169     }
1170
1171   rec2 = ipa_get_stmt_member_ptr_load_param (def,
1172                                              (TARGET_PTRMEMFUNC_VBIT_LOCATION
1173                                               == ptrmemfunc_vbit_in_delta));
1174
1175   if (rec != rec2)
1176     return;
1177
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);
1181
1182   return;
1183 }
1184
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. */
1188
1189 static void
1190 ipa_analyze_virtual_call_uses (struct cgraph_node *node,
1191                                struct ipa_node_params *info, gimple call,
1192                                tree target)
1193 {
1194   tree obj = OBJ_TYPE_REF_OBJECT (target);
1195   tree var;
1196   int index;
1197
1198   if (TREE_CODE (obj) == ADDR_EXPR)
1199     {
1200       do
1201         {
1202           obj = TREE_OPERAND (obj, 0);
1203         }
1204       while (TREE_CODE (obj) == COMPONENT_REF);
1205       if (TREE_CODE (obj) != INDIRECT_REF)
1206         return;
1207       obj = TREE_OPERAND (obj, 0);
1208     }
1209
1210   if (TREE_CODE (obj) != SSA_NAME
1211       || !SSA_NAME_IS_DEFAULT_DEF (obj))
1212     return;
1213
1214   var = SSA_NAME_VAR (obj);
1215   index = ipa_get_param_decl_index (info, var);
1216
1217   if (index >= 0)
1218     ipa_note_param_call (node, index, call, true);
1219 }
1220
1221 /* Analyze a call statement CALL whether and how it utilizes formal parameters
1222    of the caller (described by INFO). */
1223
1224 static void
1225 ipa_analyze_call_uses (struct cgraph_node *node,
1226                        struct ipa_node_params *info, gimple call)
1227 {
1228   tree target = gimple_call_fn (call);
1229
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);
1234 }
1235
1236
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.  */
1240
1241 static void
1242 ipa_analyze_stmt_uses (struct cgraph_node *node, struct ipa_node_params *info,
1243                        gimple stmt)
1244 {
1245   if (is_gimple_call (stmt))
1246     ipa_analyze_call_uses (node, info, stmt);
1247 }
1248
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.  */
1252
1253 void
1254 ipa_analyze_params_uses (struct cgraph_node *node)
1255 {
1256   tree decl = node->decl;
1257   basic_block bb;
1258   struct function *func;
1259   gimple_stmt_iterator gsi;
1260   struct ipa_node_params *info = IPA_NODE_REF (node);
1261
1262   if (ipa_get_param_count (info) == 0 || info->uses_analysis_done)
1263     return;
1264
1265   func = DECL_STRUCT_FUNCTION (decl);
1266   FOR_EACH_BB_FN (bb, func)
1267     {
1268       for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1269         {
1270           gimple stmt = gsi_stmt (gsi);
1271           ipa_analyze_stmt_uses (node, info, stmt);
1272         }
1273     }
1274
1275   info->uses_analysis_done = 1;
1276 }
1277
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
1280    type.  */
1281
1282 static void
1283 combine_known_type_and_ancestor_jfs (struct ipa_jump_func *src,
1284                                      struct ipa_jump_func *dst)
1285 {
1286   tree new_binfo;
1287
1288   new_binfo = get_binfo_at_offset (src->value.base_binfo,
1289                                    dst->value.ancestor.offset,
1290                                    dst->value.ancestor.type);
1291   if (new_binfo)
1292     {
1293       dst->type = IPA_JF_KNOWN_TYPE;
1294       dst->value.base_binfo = new_binfo;
1295     }
1296   else
1297     dst->type = IPA_JF_UNKNOWN;
1298 }
1299
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.  */
1303
1304 static void
1305 update_jump_functions_after_inlining (struct cgraph_edge *cs,
1306                                       struct cgraph_edge *e)
1307 {
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);
1311   int i;
1312
1313   for (i = 0; i < count; i++)
1314     {
1315       struct ipa_jump_func *dst = ipa_get_ith_jump_func (args, i);
1316
1317       if (dst->type == IPA_JF_ANCESTOR)
1318         {
1319           struct ipa_jump_func *src;
1320
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
1323              don't.  */
1324           if (dst->value.ancestor.formal_id >= ipa_get_cs_argument_count (top))
1325             {
1326               dst->type = IPA_JF_UNKNOWN;
1327               continue;
1328             }
1329
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)
1334             {
1335               struct ipa_jump_func kt_func;
1336
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);
1341               else
1342                 dst->type = IPA_JF_UNKNOWN;
1343             }
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)
1348             {
1349               dst->value.ancestor.formal_id = src->value.ancestor.formal_id;
1350               dst->value.ancestor.offset += src->value.ancestor.offset;
1351             }
1352           else
1353             dst->type = IPA_JF_UNKNOWN;
1354         }
1355       else if (dst->type == IPA_JF_PASS_THROUGH)
1356         {
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)))
1363             {
1364               src = ipa_get_ith_jump_func (top,
1365                                            dst->value.pass_through.formal_id);
1366               *dst = *src;
1367             }
1368           else
1369             dst->type = IPA_JF_UNKNOWN;
1370         }
1371     }
1372 }
1373
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.  */
1376
1377 static struct cgraph_edge *
1378 make_edge_direct_to_target (struct cgraph_edge *ie, tree target)
1379 {
1380   struct cgraph_node *callee;
1381
1382   if (TREE_CODE (target) != ADDR_EXPR)
1383     return NULL;
1384   target = TREE_OPERAND (target, 0);
1385   if (TREE_CODE (target) != FUNCTION_DECL)
1386     return NULL;
1387   callee = cgraph_node (target);
1388   if (!callee)
1389     return NULL;
1390
1391   cgraph_make_edge_direct (ie, callee);
1392   if (dump_file)
1393     {
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);
1399
1400       if (ie->call_stmt)
1401         print_gimple_stmt (dump_file, ie->call_stmt, 2, TDF_SLIM);
1402       else
1403         fprintf (dump_file, "with uid %i\n", ie->lto_stmt_uid);
1404     }
1405
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));
1409
1410   return ie;
1411 }
1412
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.  */
1417
1418 static struct cgraph_edge *
1419 try_make_edge_direct_simple_call (struct cgraph_edge *ie,
1420                                   struct ipa_jump_func *jfunc)
1421 {
1422   tree target;
1423
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;
1428   else
1429     return NULL;
1430
1431   return make_edge_direct_to_target (ie, target);
1432 }
1433
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.  */
1438
1439 static struct cgraph_edge *
1440 try_make_edge_direct_virtual_call (struct cgraph_edge *ie,
1441                                    struct ipa_jump_func *jfunc)
1442 {
1443   tree binfo, type, target;
1444   HOST_WIDE_INT token;
1445
1446   if (jfunc->type == IPA_JF_KNOWN_TYPE)
1447     binfo = jfunc->value.base_binfo;
1448   else if (jfunc->type == IPA_JF_CONST)
1449     {
1450       tree cst = jfunc->value.constant;
1451       if (TREE_CODE (cst) == ADDR_EXPR)
1452         binfo = gimple_get_relevant_ref_binfo (TREE_OPERAND (cst, 0),
1453                                                NULL_TREE);
1454       else
1455         return NULL;
1456     }
1457   else
1458     return NULL;
1459
1460   if (!binfo)
1461     return NULL;
1462
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);
1466   if (binfo)
1467     target = gimple_fold_obj_type_ref_known_binfo (token, binfo);
1468   else
1469     return NULL;
1470
1471   if (target)
1472     return make_edge_direct_to_target (ie, target);
1473   else
1474     return NULL;
1475 }
1476
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.  */
1482
1483 static bool
1484 update_indirect_edges_after_inlining (struct cgraph_edge *cs,
1485                                       struct cgraph_node *node,
1486                                       VEC (cgraph_edge_p, heap) **new_edges)
1487 {
1488   struct ipa_edge_args *top = IPA_EDGE_REF (cs);
1489   struct cgraph_edge *ie, *next_ie, *new_direct_edge;
1490   bool res = false;
1491
1492   ipa_check_create_edge_args ();
1493
1494   for (ie = node->indirect_calls; ie; ie = next_ie)
1495     {
1496       struct cgraph_indirect_call_info *ici = ie->indirect_info;
1497       struct ipa_jump_func *jfunc;
1498
1499       next_ie = ie->next_callee;
1500       if (bitmap_bit_p (iinlining_processed_edges, ie->uid))
1501         continue;
1502
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)
1506         continue;
1507
1508       /* We must check range due to calls with variable number of arguments:  */
1509       if (ici->param_index >= ipa_get_cs_argument_count (top))
1510         {
1511           bitmap_set_bit (iinlining_processed_edges, ie->uid);
1512           continue;
1513         }
1514
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)
1520         {
1521           ici->param_index = jfunc->value.ancestor.formal_id;
1522           ici->anc_offset += jfunc->value.ancestor.offset;
1523         }
1524       else
1525         /* Either we can find a destination for this edge now or never. */
1526         bitmap_set_bit (iinlining_processed_edges, ie->uid);
1527
1528       if (ici->polymorphic)
1529         new_direct_edge = try_make_edge_direct_virtual_call (ie, jfunc);
1530       else
1531         new_direct_edge = try_make_edge_direct_simple_call (ie, jfunc);
1532
1533       if (new_direct_edge)
1534         {
1535           new_direct_edge->indirect_inlining_edge = 1;
1536           if (new_edges)
1537             {
1538               VEC_safe_push (cgraph_edge_p, heap, *new_edges,
1539                              new_direct_edge);
1540               top = IPA_EDGE_REF (cs);
1541               res = true;
1542             }
1543         }
1544     }
1545
1546   return res;
1547 }
1548
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
1555    created.  */
1556
1557 static bool
1558 propagate_info_to_inlined_callees (struct cgraph_edge *cs,
1559                                    struct cgraph_node *node,
1560                                    VEC (cgraph_edge_p, heap) **new_edges)
1561 {
1562   struct cgraph_edge *e;
1563   bool res;
1564
1565   res = update_indirect_edges_after_inlining (cs, node, new_edges);
1566
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);
1570     else
1571       update_jump_functions_after_inlining (cs, e);
1572
1573   return res;
1574 }
1575
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 +
1580    created.  */
1581
1582 bool
1583 ipa_propagate_indirect_call_infos (struct cgraph_edge *cs,
1584                                    VEC (cgraph_edge_p, heap) **new_edges)
1585 {
1586   /* FIXME lto: We do not stream out indirect call information.  */
1587   if (flag_wpa)
1588     return false;
1589
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)
1593     return false;
1594   gcc_assert (ipa_edge_args_vector);
1595
1596   return propagate_info_to_inlined_callees (cs, cs->callee, new_edges);
1597 }
1598
1599 /* Frees all dynamically allocated structures that the argument info points
1600    to.  */
1601
1602 void
1603 ipa_free_edge_args_substructures (struct ipa_edge_args *args)
1604 {
1605   if (args->jump_functions)
1606     ggc_free (args->jump_functions);
1607
1608   memset (args, 0, sizeof (*args));
1609 }
1610
1611 /* Free all ipa_edge structures.  */
1612
1613 void
1614 ipa_free_all_edge_args (void)
1615 {
1616   int i;
1617   struct ipa_edge_args *args;
1618
1619   for (i = 0;
1620        VEC_iterate (ipa_edge_args_t, ipa_edge_args_vector, i, args);
1621        i++)
1622     ipa_free_edge_args_substructures (args);
1623
1624   VEC_free (ipa_edge_args_t, gc, ipa_edge_args_vector);
1625   ipa_edge_args_vector = NULL;
1626 }
1627
1628 /* Frees all dynamically allocated structures that the param info points
1629    to.  */
1630
1631 void
1632 ipa_free_node_params_substructures (struct ipa_node_params *info)
1633 {
1634   if (info->params)
1635     free (info->params);
1636
1637   memset (info, 0, sizeof (*info));
1638 }
1639
1640 /* Free all ipa_node_params structures.  */
1641
1642 void
1643 ipa_free_all_node_params (void)
1644 {
1645   int i;
1646   struct ipa_node_params *info;
1647
1648   for (i = 0;
1649        VEC_iterate (ipa_node_params_t, ipa_node_params_vector, i, info);
1650        i++)
1651     ipa_free_node_params_substructures (info);
1652
1653   VEC_free (ipa_node_params_t, heap, ipa_node_params_vector);
1654   ipa_node_params_vector = NULL;
1655 }
1656
1657 /* Hook that is called by cgraph.c when an edge is removed.  */
1658
1659 static void
1660 ipa_edge_removal_hook (struct cgraph_edge *cs, void *data ATTRIBUTE_UNUSED)
1661 {
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)
1665     return;
1666   ipa_free_edge_args_substructures (IPA_EDGE_REF (cs));
1667 }
1668
1669 /* Hook that is called by cgraph.c when a node is removed.  */
1670
1671 static void
1672 ipa_node_removal_hook (struct cgraph_node *node, void *data ATTRIBUTE_UNUSED)
1673 {
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)
1677     return;
1678   ipa_free_node_params_substructures (IPA_NODE_REF (node));
1679 }
1680
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.  */
1683
1684 static void *
1685 duplicate_array (void *src, size_t n)
1686 {
1687   void *p;
1688
1689   if (!src)
1690     return NULL;
1691
1692   p = xmalloc (n);
1693   memcpy (p, src, n);
1694   return p;
1695 }
1696
1697 /* Like duplicate_array byt in GGC memory.  */
1698
1699 static void *
1700 duplicate_ggc_array (void *src, size_t n)
1701 {
1702   void *p;
1703
1704   if (!src)
1705     return NULL;
1706
1707   p = ggc_alloc (n);
1708   memcpy (p, src, n);
1709   return p;
1710 }
1711
1712 /* Hook that is called by cgraph.c when a node is duplicated.  */
1713
1714 static void
1715 ipa_edge_duplication_hook (struct cgraph_edge *src, struct cgraph_edge *dst,
1716                            __attribute__((unused)) void *data)
1717 {
1718   struct ipa_edge_args *old_args, *new_args;
1719   int arg_count;
1720
1721   ipa_check_create_edge_args ();
1722
1723   old_args = IPA_EDGE_REF (src);
1724   new_args = IPA_EDGE_REF (dst);
1725
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);
1731
1732   if (iinlining_processed_edges
1733       && bitmap_bit_p (iinlining_processed_edges, src->uid))
1734     bitmap_set_bit (iinlining_processed_edges, dst->uid);
1735 }
1736
1737 /* Hook that is called by cgraph.c when a node is duplicated.  */
1738
1739 static void
1740 ipa_node_duplication_hook (struct cgraph_node *src, struct cgraph_node *dst,
1741                            __attribute__((unused)) void *data)
1742 {
1743   struct ipa_node_params *old_info, *new_info;
1744   int param_count;
1745
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);
1750
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;
1757 }
1758
1759 /* Register our cgraph hooks if they are not already there.  */
1760
1761 void
1762 ipa_register_cgraph_hooks (void)
1763 {
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);
1776 }
1777
1778 /* Unregister our cgraph hooks if they are not already there.  */
1779
1780 static void
1781 ipa_unregister_cgraph_hooks (void)
1782 {
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;
1791 }
1792
1793 /* Allocate all necessary data strucutures necessary for indirect inlining.  */
1794
1795 void
1796 ipa_create_all_structures_for_iinln (void)
1797 {
1798   iinlining_processed_edges = BITMAP_ALLOC (NULL);
1799 }
1800
1801 /* Free all ipa_node_params and all ipa_edge_args structures if they are no
1802    longer needed after ipa-cp.  */
1803
1804 void
1805 ipa_free_all_structures_after_ipa_cp (void)
1806 {
1807   if (!flag_indirect_inlining)
1808     {
1809       ipa_free_all_edge_args ();
1810       ipa_free_all_node_params ();
1811       ipa_unregister_cgraph_hooks ();
1812     }
1813 }
1814
1815 /* Free all ipa_node_params and all ipa_edge_args structures if they are no
1816    longer needed after indirect inlining.  */
1817
1818 void
1819 ipa_free_all_structures_after_iinln (void)
1820 {
1821   BITMAP_FREE (iinlining_processed_edges);
1822
1823   ipa_free_all_edge_args ();
1824   ipa_free_all_node_params ();
1825   ipa_unregister_cgraph_hooks ();
1826 }
1827
1828 /* Print ipa_tree_map data structures of all functions in the
1829    callgraph to F.  */
1830
1831 void
1832 ipa_print_node_params (FILE * f, struct cgraph_node *node)
1833 {
1834   int i, count;
1835   tree temp;
1836   struct ipa_node_params *info;
1837
1838   if (!node->analyzed)
1839     return;
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++)
1845     {
1846       temp = ipa_get_param (info, i);
1847       if (TREE_CODE (temp) == PARM_DECL)
1848         fprintf (f, "    param %d : %s", i,
1849                  (DECL_NAME (temp)
1850                   ? (*lang_hooks.decl_printable_name) (temp, 2)
1851                   : "(unnamed)"));
1852       if (ipa_is_param_modified (info, i))
1853         fprintf (f, " modified");
1854       if (ipa_is_param_used (info, i))
1855         fprintf (f, " used");
1856       fprintf (f, "\n");
1857     }
1858 }
1859
1860 /* Print ipa_tree_map data structures of all functions in the
1861    callgraph to F.  */
1862
1863 void
1864 ipa_print_all_params (FILE * f)
1865 {
1866   struct cgraph_node *node;
1867
1868   fprintf (f, "\nFunction parameters:\n");
1869   for (node = cgraph_nodes; node; node = node->next)
1870     ipa_print_node_params (f, node);
1871 }
1872
1873 /* Return a heap allocated vector containing formal parameters of FNDECL.  */
1874
1875 VEC(tree, heap) *
1876 ipa_get_vector_of_formal_parms (tree fndecl)
1877 {
1878   VEC(tree, heap) *args;
1879   int count;
1880   tree parm;
1881
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);
1886
1887   return args;
1888 }
1889
1890 /* Return a heap allocated vector containing types of formal parameters of
1891    function type FNTYPE.  */
1892
1893 static inline VEC(tree, heap) *
1894 get_vector_of_formal_parm_types (tree fntype)
1895 {
1896   VEC(tree, heap) *types;
1897   int count = 0;
1898   tree t;
1899
1900   for (t = TYPE_ARG_TYPES (fntype); t; t = TREE_CHAIN (t))
1901     count++;
1902
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));
1906
1907   return types;
1908 }
1909
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.  */
1914
1915 void
1916 ipa_modify_formal_parameters (tree fndecl, ipa_parm_adjustment_vec adjustments,
1917                               const char *synth_parm_prefix)
1918 {
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;
1926
1927   if (!synth_parm_prefix)
1928     synth_parm_prefix = "SYNTH";
1929
1930   oparms = ipa_get_vector_of_formal_parms (fndecl);
1931   orig_type = TREE_TYPE (fndecl);
1932   old_arg_types = TYPE_ARG_TYPES (orig_type);
1933
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);
1937   if (care_for_types)
1938     {
1939       last_parm_void = (TREE_VALUE (tree_last (old_arg_types))
1940                         == void_type_node);
1941       otypes = get_vector_of_formal_parm_types (orig_type);
1942       if (last_parm_void)
1943         gcc_assert (VEC_length (tree, oparms) + 1 == VEC_length (tree, otypes));
1944       else
1945         gcc_assert (VEC_length (tree, oparms) == VEC_length (tree, otypes));
1946     }
1947   else
1948     {
1949       last_parm_void = false;
1950       otypes = NULL;
1951     }
1952
1953   for (i = 0; i < len; i++)
1954     {
1955       struct ipa_parm_adjustment *adj;
1956       gcc_assert (link);
1957
1958       adj = VEC_index (ipa_parm_adjustment_t, adjustments, i);
1959       parm = VEC_index (tree, oparms, adj->base_index);
1960       adj->base = parm;
1961
1962       if (adj->copy_param)
1963         {
1964           if (care_for_types)
1965             new_arg_types = tree_cons (NULL_TREE, VEC_index (tree, otypes,
1966                                                              adj->base_index),
1967                                        new_arg_types);
1968           *link = parm;
1969           link = &TREE_CHAIN (parm);
1970         }
1971       else if (!adj->remove_param)
1972         {
1973           tree new_parm;
1974           tree ptype;
1975
1976           if (adj->by_ref)
1977             ptype = build_pointer_type (adj->type);
1978           else
1979             ptype = adj->type;
1980
1981           if (care_for_types)
1982             new_arg_types = tree_cons (NULL_TREE, ptype, new_arg_types);
1983
1984           new_parm = build_decl (UNKNOWN_LOCATION, PARM_DECL, NULL_TREE,
1985                                  ptype);
1986           DECL_NAME (new_parm) = create_tmp_var_name (synth_parm_prefix);
1987
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);
1994
1995           add_referenced_var (new_parm);
1996           mark_sym_for_renaming (new_parm);
1997           adj->base = parm;
1998           adj->reduction = new_parm;
1999
2000           *link = new_parm;
2001
2002           link = &TREE_CHAIN (new_parm);
2003         }
2004     }
2005
2006   *link = NULL_TREE;
2007
2008   if (care_for_types)
2009     {
2010       new_reversed = nreverse (new_arg_types);
2011       if (last_parm_void)
2012         {
2013           if (new_reversed)
2014             TREE_CHAIN (new_arg_types) = void_list_node;
2015           else
2016             new_reversed = void_list_node;
2017         }
2018     }
2019
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
2024      instead.  */
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))
2028     {
2029       new_type = copy_node (orig_type);
2030       TYPE_ARG_TYPES (new_type) = new_reversed;
2031     }
2032   else
2033     {
2034       new_type
2035         = build_distinct_type_copy (build_function_type (TREE_TYPE (orig_type),
2036                                                          new_reversed));
2037       TYPE_CONTEXT (new_type) = TYPE_CONTEXT (orig_type);
2038       DECL_VINDEX (fndecl) = NULL_TREE;
2039     }
2040
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);
2044   if (orig_type != t)
2045     {
2046       TYPE_MAIN_VARIANT (new_type) = t;
2047       TYPE_NEXT_VARIANT (new_type) = TYPE_NEXT_VARIANT (t);
2048       TYPE_NEXT_VARIANT (t) = new_type;
2049     }
2050   else
2051     {
2052       TYPE_MAIN_VARIANT (new_type) = new_type;
2053       TYPE_NEXT_VARIANT (new_type) = NULL;
2054     }
2055
2056   TREE_TYPE (fndecl) = new_type;
2057   if (otypes)
2058     VEC_free (tree, heap, otypes);
2059   VEC_free (tree, heap, oparms);
2060 }
2061
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.  */
2065
2066 void
2067 ipa_modify_call_arguments (struct cgraph_edge *cs, gimple stmt,
2068                            ipa_parm_adjustment_vec adjustments)
2069 {
2070   VEC(tree, heap) *vargs;
2071   gimple new_stmt;
2072   gimple_stmt_iterator gsi;
2073   tree callee_decl;
2074   int i, len;
2075
2076   len = VEC_length (ipa_parm_adjustment_t, adjustments);
2077   vargs = VEC_alloc (tree, heap, len);
2078
2079   gsi = gsi_for_stmt (stmt);
2080   for (i = 0; i < len; i++)
2081     {
2082       struct ipa_parm_adjustment *adj;
2083
2084       adj = VEC_index (ipa_parm_adjustment_t, adjustments, i);
2085
2086       if (adj->copy_param)
2087         {
2088           tree arg = gimple_call_arg (stmt, adj->base_index);
2089
2090           VEC_quick_push (tree, vargs, arg);
2091         }
2092       else if (!adj->remove_param)
2093         {
2094           tree expr, orig_expr;
2095           bool allow_ptr, repl_found;
2096
2097           orig_expr = expr = gimple_call_arg (stmt, adj->base_index);
2098           if (TREE_CODE (expr) == ADDR_EXPR)
2099             {
2100               allow_ptr = false;
2101               expr = TREE_OPERAND (expr, 0);
2102             }
2103           else
2104             allow_ptr = true;
2105
2106           repl_found = build_ref_for_offset (&expr, TREE_TYPE (expr),
2107                                              adj->offset, adj->type,
2108                                              allow_ptr);
2109           if (repl_found)
2110             {
2111               if (adj->by_ref)
2112                 expr = build_fold_addr_expr (expr);
2113             }
2114           else
2115             {
2116               tree ptrtype = build_pointer_type (adj->type);
2117               expr = orig_expr;
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));
2125               if (!adj->by_ref)
2126                 expr = fold_build1 (INDIRECT_REF, adj->type, expr);
2127             }
2128           expr = force_gimple_operand_gsi (&gsi, expr,
2129                                            adj->by_ref
2130                                            || is_gimple_reg_type (adj->type),
2131                                            NULL, true, GSI_SAME_STMT);
2132           VEC_quick_push (tree, vargs, expr);
2133         }
2134     }
2135
2136   if (dump_file && (dump_flags & TDF_DETAILS))
2137     {
2138       fprintf (dump_file, "replacing stmt:");
2139       print_gimple_stmt (dump_file, gsi_stmt (gsi), 0, 0);
2140     }
2141
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));
2147
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));
2153
2154   if (dump_file && (dump_flags & TDF_DETAILS))
2155     {
2156       fprintf (dump_file, "with stmt:");
2157       print_gimple_stmt (dump_file, new_stmt, 0, 0);
2158       fprintf (dump_file, "\n");
2159     }
2160   gsi_replace (&gsi, new_stmt, true);
2161   if (cs)
2162     cgraph_set_call_stmt (cs, new_stmt);
2163   update_ssa (TODO_update_ssa);
2164   free_dominance_info (CDI_DOMINATORS);
2165 }
2166
2167 /* Return true iff BASE_INDEX is in ADJUSTMENTS more than once.  */
2168
2169 static bool
2170 index_in_adjustments_multiple_times_p (int base_index,
2171                                        ipa_parm_adjustment_vec adjustments)
2172 {
2173   int i, len = VEC_length (ipa_parm_adjustment_t, adjustments);
2174   bool one = false;
2175
2176   for (i = 0; i < len; i++)
2177     {
2178       struct ipa_parm_adjustment *adj;
2179       adj = VEC_index (ipa_parm_adjustment_t, adjustments, i);
2180
2181       if (adj->base_index == base_index)
2182         {
2183           if (one)
2184             return true;
2185           else
2186             one = true;
2187         }
2188     }
2189   return false;
2190 }
2191
2192
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.  */
2196
2197 ipa_parm_adjustment_vec
2198 ipa_combine_adjustments (ipa_parm_adjustment_vec inner,
2199                          ipa_parm_adjustment_vec outer)
2200 {
2201   int i, outlen = VEC_length (ipa_parm_adjustment_t, outer);
2202   int inlen = VEC_length (ipa_parm_adjustment_t, inner);
2203   int removals = 0;
2204   ipa_parm_adjustment_vec adjustments, tmp;
2205
2206   tmp = VEC_alloc (ipa_parm_adjustment_t, heap, inlen);
2207   for (i = 0; i < inlen; i++)
2208     {
2209       struct ipa_parm_adjustment *n;
2210       n = VEC_index (ipa_parm_adjustment_t, inner, i);
2211
2212       if (n->remove_param)
2213         removals++;
2214       else
2215         VEC_quick_push (ipa_parm_adjustment_t, tmp, n);
2216     }
2217
2218   adjustments = VEC_alloc (ipa_parm_adjustment_t, heap, outlen + removals);
2219   for (i = 0; i < outlen; i++)
2220     {
2221       struct ipa_parm_adjustment *r;
2222       struct ipa_parm_adjustment *out = VEC_index (ipa_parm_adjustment_t,
2223                                                    outer, i);
2224       struct ipa_parm_adjustment *in = VEC_index (ipa_parm_adjustment_t, tmp,
2225                                                   out->base_index);
2226
2227       gcc_assert (!in->remove_param);
2228       if (out->remove_param)
2229         {
2230           if (!index_in_adjustments_multiple_times_p (in->base_index, tmp))
2231             {
2232               r = VEC_quick_push (ipa_parm_adjustment_t, adjustments, NULL);
2233               memset (r, 0, sizeof (*r));
2234               r->remove_param = true;
2235             }
2236           continue;
2237         }
2238
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;
2243
2244       /* FIXME:  Create nonlocal value too.  */
2245
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;
2252       else
2253         r->offset = in->offset + out->offset;
2254     }
2255
2256   for (i = 0; i < inlen; i++)
2257     {
2258       struct ipa_parm_adjustment *n = VEC_index (ipa_parm_adjustment_t,
2259                                                  inner, i);
2260
2261       if (n->remove_param)
2262         VEC_quick_push (ipa_parm_adjustment_t, adjustments, n);
2263     }
2264
2265   VEC_free (ipa_parm_adjustment_t, heap, tmp);
2266   return adjustments;
2267 }
2268
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.  */
2271
2272 void
2273 ipa_dump_param_adjustments (FILE *file, ipa_parm_adjustment_vec adjustments,
2274                             tree fndecl)
2275 {
2276   int i, len = VEC_length (ipa_parm_adjustment_t, adjustments);
2277   bool first = true;
2278   VEC(tree, heap) *parms = ipa_get_vector_of_formal_parms (fndecl);
2279
2280   fprintf (file, "IPA param adjustments: ");
2281   for (i = 0; i < len; i++)
2282     {
2283       struct ipa_parm_adjustment *adj;
2284       adj = VEC_index (ipa_parm_adjustment_t, adjustments, i);
2285
2286       if (!first)
2287         fprintf (file, "                 ");
2288       else
2289         first = false;
2290
2291       fprintf (file, "%i. base_index: %i - ", i, adj->base_index);
2292       print_generic_expr (file, VEC_index (tree, parms, adj->base_index), 0);
2293       if (adj->base)
2294         {
2295           fprintf (file, ", base: ");
2296           print_generic_expr (file, adj->base, 0);
2297         }
2298       if (adj->reduction)
2299         {
2300           fprintf (file, ", reduction: ");
2301           print_generic_expr (file, adj->reduction, 0);
2302         }
2303       if (adj->new_ssa_base)
2304         {
2305           fprintf (file, ", new_ssa_base: ");
2306           print_generic_expr (file, adj->new_ssa_base, 0);
2307         }
2308
2309       if (adj->copy_param)
2310         fprintf (file, ", copy_param");
2311       else if (adj->remove_param)
2312         fprintf (file, ", remove_param");
2313       else
2314         fprintf (file, ", offset %li", (long) adj->offset);
2315       if (adj->by_ref)
2316         fprintf (file, ", by_ref");
2317       print_node_brief (file, ", type: ", adj->type, 0);
2318       fprintf (file, "\n");
2319     }
2320   VEC_free (tree, heap, parms);
2321 }
2322
2323 /* Stream out jump function JUMP_FUNC to OB.  */
2324
2325 static void
2326 ipa_write_jump_function (struct output_block *ob,
2327                          struct ipa_jump_func *jump_func)
2328 {
2329   lto_output_uleb128_stream (ob->main_stream,
2330                              jump_func->type);
2331
2332   switch (jump_func->type)
2333     {
2334     case IPA_JF_UNKNOWN:
2335       break;
2336     case IPA_JF_KNOWN_TYPE:
2337       lto_output_tree (ob, jump_func->value.base_binfo, true);
2338       break;
2339     case IPA_JF_CONST:
2340       lto_output_tree (ob, jump_func->value.constant, true);
2341       break;
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);
2348       break;
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);
2355       break;
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);
2359       break;
2360     }
2361 }
2362
2363 /* Read in jump function JUMP_FUNC from IB.  */
2364
2365 static void
2366 ipa_read_jump_function (struct lto_input_block *ib,
2367                         struct ipa_jump_func *jump_func,
2368                         struct data_in *data_in)
2369 {
2370   jump_func->type = (enum jump_func_type) lto_input_uleb128 (ib);
2371
2372   switch (jump_func->type)
2373     {
2374     case IPA_JF_UNKNOWN:
2375       break;
2376     case IPA_JF_KNOWN_TYPE:
2377       jump_func->value.base_binfo = lto_input_tree (ib, data_in);
2378       break;
2379     case IPA_JF_CONST:
2380       jump_func->value.constant = lto_input_tree (ib, data_in);
2381       break;
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);
2386       break;
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);
2391       break;
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);
2395       break;
2396     }
2397 }
2398
2399 /* Stream out parts of cgraph_indirect_call_info corresponding to CS that are
2400    relevant to indirect inlining to OB.  */
2401
2402 static void
2403 ipa_write_indirect_edge_info (struct output_block *ob,
2404                               struct cgraph_edge *cs)
2405 {
2406   struct cgraph_indirect_call_info *ii = cs->indirect_info;
2407   struct bitpack_d *bp;
2408
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);
2415
2416   if (ii->polymorphic)
2417     {
2418       lto_output_sleb128_stream (ob->main_stream, ii->otr_token);
2419       lto_output_tree (ob, ii->otr_type, true);
2420     }
2421 }
2422
2423 /* Read in parts of cgraph_indirect_call_info corresponding to CS that are
2424    relevant to indirect inlining from IB.  */
2425
2426 static void
2427 ipa_read_indirect_edge_info (struct lto_input_block *ib,
2428                              struct data_in *data_in ATTRIBUTE_UNUSED,
2429                              struct cgraph_edge *cs)
2430 {
2431   struct cgraph_indirect_call_info *ii = cs->indirect_info;
2432   struct bitpack_d *bp;
2433
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)
2440     {
2441       ii->otr_token = (HOST_WIDE_INT) lto_input_sleb128 (ib);
2442       ii->otr_type = lto_input_tree (ib, data_in);
2443     }
2444 }
2445
2446 /* Stream out NODE info to OB.  */
2447
2448 static void
2449 ipa_write_node_info (struct output_block *ob, struct cgraph_node *node)
2450 {
2451   int node_ref;
2452   lto_cgraph_encoder_t encoder;
2453   struct ipa_node_params *info = IPA_NODE_REF (node);
2454   int j;
2455   struct cgraph_edge *e;
2456   struct bitpack_d *bp;
2457
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);
2461
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++)
2470     {
2471       bp_pack_value (bp, info->params[j].modified, 1);
2472       bp_pack_value (bp, info->params[j].used, 1);
2473     }
2474   lto_output_bitpack (ob->main_stream, bp);
2475   bitpack_delete (bp);
2476   for (e = node->callees; e; e = e->next_callee)
2477     {
2478       struct ipa_edge_args *args = IPA_EDGE_REF (e);
2479
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));
2484     }
2485   for (e = node->indirect_calls; e; e = e->next_callee)
2486     ipa_write_indirect_edge_info (ob, e);
2487 }
2488
2489 /* Srtream in NODE info from IB.  */
2490
2491 static void
2492 ipa_read_node_info (struct lto_input_block *ib, struct cgraph_node *node,
2493                     struct data_in *data_in)
2494 {
2495   struct ipa_node_params *info = IPA_NODE_REF (node);
2496   int k;
2497   struct cgraph_edge *e;
2498   struct bitpack_d *bp;
2499
2500   ipa_initialize_node_params (node);
2501
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)
2506     {
2507       info->modification_analysis_done = true;
2508       info->uses_analysis_done = true;
2509     }
2510   info->node_enqueued = false;
2511   for (k = 0; k < ipa_get_param_count (info); k++)
2512     {
2513       info->params[k].modified = bp_unpack_value (bp, 1);
2514       info->params[k].used = bp_unpack_value (bp, 1);
2515     }
2516   bitpack_delete (bp);
2517   for (e = node->callees; e; e = e->next_callee)
2518     {
2519       struct ipa_edge_args *args = IPA_EDGE_REF (e);
2520       int count = lto_input_uleb128 (ib);
2521
2522       ipa_set_cs_argument_count (args, count);
2523       if (!count)
2524         continue;
2525
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);
2530     }
2531   for (e = node->indirect_calls; e; e = e->next_callee)
2532     ipa_read_indirect_edge_info (ib, data_in, e);
2533 }
2534
2535 /* Write jump functions for nodes in SET.  */
2536
2537 void
2538 ipa_prop_write_jump_functions (cgraph_node_set set)
2539 {
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;
2544
2545   ob->cgraph_node = NULL;
2546
2547   for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
2548     {
2549       node = csi_node (csi);
2550       if (node->analyzed && IPA_NODE_REF (node) != NULL)
2551         count++;
2552     }
2553
2554   lto_output_uleb128_stream (ob->main_stream, count);
2555
2556   /* Process all of the functions.  */
2557   for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
2558     {
2559       node = csi_node (csi);
2560       if (node->analyzed && IPA_NODE_REF (node) != NULL)
2561         ipa_write_node_info (ob, node);
2562     }
2563   lto_output_1_stream (ob->main_stream, 0);
2564   produce_asm (ob, NULL);
2565   destroy_output_block (ob);
2566 }
2567
2568 /* Read section in file FILE_DATA of length LEN with data DATA.  */
2569
2570 static void
2571 ipa_prop_read_section (struct lto_file_decl_data *file_data, const char *data,
2572                        size_t len)
2573 {
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;
2581   unsigned int i;
2582   unsigned int count;
2583
2584   LTO_INIT_INPUT_BLOCK (ib_main, (const char *) data + main_offset, 0,
2585                         header->main_size);
2586
2587   data_in =
2588     lto_data_in_create (file_data, (const char *) data + string_offset,
2589                         header->string_size, NULL);
2590   count = lto_input_uleb128 (&ib_main);
2591
2592   for (i = 0; i < count; i++)
2593     {
2594       unsigned int index;
2595       struct cgraph_node *node;
2596       lto_cgraph_encoder_t encoder;
2597
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);
2603     }
2604   lto_free_section_data (file_data, LTO_section_jump_functions, NULL, data,
2605                          len);
2606   lto_data_in_delete (data_in);
2607 }
2608
2609 /* Read ipcp jump functions.  */
2610
2611 void
2612 ipa_prop_read_jump_functions (void)
2613 {
2614   struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
2615   struct lto_file_decl_data *file_data;
2616   unsigned int j = 0;
2617
2618   ipa_check_create_node_params ();
2619   ipa_check_create_edge_args ();
2620   ipa_register_cgraph_hooks ();
2621
2622   while ((file_data = file_data_vec[j++]))
2623     {
2624       size_t len;
2625       const char *data = lto_get_section_data (file_data, LTO_section_jump_functions, NULL, &len);
2626
2627       if (data)
2628         ipa_prop_read_section (file_data, data, len);
2629     }
2630 }
2631
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.  */
2635
2636 void
2637 ipa_update_after_lto_read (void)
2638 {
2639   struct cgraph_node *node;
2640   struct cgraph_edge *cs;
2641
2642   ipa_check_create_node_params ();
2643   ipa_check_create_edge_args ();
2644
2645   for (node = cgraph_nodes; node; node = node->next)
2646     if (node->analyzed)
2647       ipa_initialize_node_params (node);
2648
2649   for (node = cgraph_nodes; node; node = node->next)
2650     if (node->analyzed)
2651       for (cs = node->callees; cs; cs = cs->next_callee)
2652         {
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));
2656         }
2657 }