1/* Interprocedural analyses.
2   Copyright (C) 2005-2020 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3.  If not see
18<http://www.gnu.org/licenses/>.  */
19
20#ifndef IPA_PROP_H
21#define IPA_PROP_H
22
23/* The following definitions and interfaces are used by
24   interprocedural analyses or parameters.  */
25
26#define IPA_UNDESCRIBED_USE -1
27
28/* ipa-prop.c stuff (ipa-cp, indirect inlining):  */
29
30/* A jump function for a callsite represents the values passed as actual
31   arguments of the callsite.  They were originally proposed in a paper called
32   "Interprocedural Constant Propagation", by David Callahan, Keith D Cooper,
33   Ken Kennedy, Linda Torczon in Comp86, pg 152-161.  There are three main
34   types of values :
35
36   Pass-through - the caller's formal parameter is passed as an actual
37                  argument, possibly one simple operation performed on it.
38   Constant     - a constant (is_gimple_ip_invariant)is passed as an actual
39                  argument.
40   Unknown      - neither of the above.
41
42   IPA_JF_LOAD_AGG is a compound pass-through jump function, in which primary
43   operation on formal parameter is memory dereference that loads a value from
44   a part of an aggregate, which is represented or pointed to by the formal
45   parameter.  Moreover, an additional unary/binary operation can be applied on
46   the loaded value, and final result is passed as actual argument of callee
47   (e.g. *(param_1(D) + 4) op 24 ).  It is meant to describe usage of aggregate
48   parameter or by-reference parameter referenced in argument passing, commonly
49   found in C++ and Fortran.
50
51   IPA_JF_ANCESTOR is a special pass-through jump function, which means that
52   the result is an address of a part of the object pointed to by the formal
53   parameter to which the function refers.  It is mainly intended to represent
54   getting addresses of ancestor fields in C++
55   (e.g. &this_1(D)->D.1766.D.1756).  Note that if the original pointer is
56   NULL, ancestor jump function must behave like a simple pass-through.
57
58   Other pass-through functions can either simply pass on an unchanged formal
59   parameter or can apply one simple binary operation to it (such jump
60   functions are called polynomial).
61
62   Jump functions are computed in ipa-prop.c by function
63   update_call_notes_after_inlining.  Some information can be lost and jump
64   functions degraded accordingly when inlining, see
65   update_call_notes_after_inlining in the same file.  */
66
67enum jump_func_type
68{
69  IPA_JF_UNKNOWN = 0,  /* newly allocated and zeroed jump functions default */
70  IPA_JF_CONST,             /* represented by field costant */
71  IPA_JF_PASS_THROUGH,	    /* represented by field pass_through */
72  IPA_JF_LOAD_AGG,	    /* represented by field load_agg */
73  IPA_JF_ANCESTOR	    /* represented by field ancestor */
74};
75
76struct ipa_cst_ref_desc;
77
78/* Structure holding data required to describe a constant jump function.  */
79struct GTY(()) ipa_constant_data
80{
81  /* THe value of the constant.  */
82  tree value;
83  /* Pointer to the structure that describes the reference.  */
84  struct ipa_cst_ref_desc GTY((skip)) *rdesc;
85};
86
87/* Structure holding data required to describe a pass-through jump function.  */
88
89struct GTY(()) ipa_pass_through_data
90{
91  /* If an operation is to be performed on the original parameter, this is the
92     second (constant) operand.  */
93  tree operand;
94  /* Number of the caller's formal parameter being passed.  */
95  int formal_id;
96  /* Operation that is performed on the argument before it is passed on.
97     NOP_EXPR means no operation.  Otherwise oper must be a simple binary
98     arithmetic operation where the caller's parameter is the first operand and
99     operand field from this structure is the second one.  */
100  enum tree_code operation;
101  /* When the passed value is a pointer, it is set to true only when we are
102     certain that no write to the object it points to has occurred since the
103     caller functions started execution, except for changes noted in the
104     aggregate part of the jump function (see description of
105     ipa_agg_jump_function).  The flag is used only when the operation is
106     NOP_EXPR.  */
107  unsigned agg_preserved : 1;
108};
109
110/* Structure holding data required to describe a load-value-from-aggregate
111   jump function.  */
112
113struct GTY(()) ipa_load_agg_data
114{
115  /* Inherit from pass through jump function, describing unary/binary
116     operation on the value loaded from aggregate that is represented or
117     pointed to by the formal parameter, specified by formal_id in this
118     pass_through jump function data structure.  */
119  struct ipa_pass_through_data pass_through;
120  /* Type of the value loaded from the aggregate.  */
121  tree type;
122  /* Offset at which the value is located within the aggregate.  */
123  HOST_WIDE_INT offset;
124  /* True if loaded by reference (the aggregate is pointed to by the formal
125     parameter) or false if loaded by value (the aggregate is represented
126     by the formal parameter).  */
127  bool by_ref;
128};
129
130/* Structure holding data required to describe an ancestor pass-through
131   jump function.  */
132
133struct GTY(()) ipa_ancestor_jf_data
134{
135  /* Offset of the field representing the ancestor.  */
136  HOST_WIDE_INT offset;
137  /* Number of the caller's formal parameter being passed.  */
138  int formal_id;
139  /* Flag with the same meaning like agg_preserve in ipa_pass_through_data.  */
140  unsigned agg_preserved : 1;
141  /* When set, the operation should not have any effect on NULL pointers.  */
142  unsigned keep_null : 1;
143};
144
145/* A jump function for an aggregate part at a given offset, which describes how
146   it content value is generated.  All unlisted positions are assumed to have a
147   value defined in an unknown way.  */
148
149struct GTY(()) ipa_agg_jf_item
150{
151  /* The offset for the aggregate part.  */
152  HOST_WIDE_INT offset;
153
154  /* Data type of the aggregate part.  */
155  tree type;
156
157  /* Jump function type.  */
158  enum jump_func_type jftype;
159
160  /* Represents a value of jump function. constant represents the actual constant
161     in constant jump function content.  pass_through is used only in simple pass
162     through jump function context.  load_agg is for load-value-from-aggregate
163     jump function context.  */
164  union jump_func_agg_value
165  {
166    tree GTY ((tag ("IPA_JF_CONST"))) constant;
167    struct ipa_pass_through_data GTY ((tag ("IPA_JF_PASS_THROUGH"))) pass_through;
168    struct ipa_load_agg_data GTY ((tag ("IPA_JF_LOAD_AGG"))) load_agg;
169  } GTY ((desc ("%1.jftype"))) value;
170};
171
172/* Jump functions describing a set of aggregate contents.  */
173
174struct GTY(()) ipa_agg_jump_function
175{
176  /* Description of the individual jump function item.  */
177  vec<ipa_agg_jf_item, va_gc> *items;
178  /* True if the data was passed by reference (as opposed to by value).  */
179  bool by_ref;
180};
181
182/* An element in an aggregate part describing a known value at a given offset.
183   All unlisted positions are assumed to be unknown and all listed values must
184   fulfill is_gimple_ip_invariant.  */
185
186struct ipa_agg_value
187{
188  /* The offset at which the known value is located within the aggregate.  */
189  HOST_WIDE_INT offset;
190
191  /* The known constant.  */
192  tree value;
193
194  /* Return true if OTHER describes same agg value.  */
195  bool equal_to (const ipa_agg_value &other);
196};
197
198/* Structure describing a set of known offset/value for aggregate.  */
199
200struct ipa_agg_value_set
201{
202  /* Description of the individual item.  */
203  vec<ipa_agg_value> items;
204  /* True if the data was passed by reference (as opposed to by value).  */
205  bool by_ref;
206
207  /* Return true if OTHER describes same agg values.  */
208  bool equal_to (const ipa_agg_value_set &other)
209  {
210    if (by_ref != other.by_ref)
211      return false;
212    if (items.length () != other.items.length ())
213      return false;
214    for (unsigned int i = 0; i < items.length (); i++)
215      if (!items[i].equal_to (other.items[i]))
216	return false;
217    return true;
218  }
219
220  /* Return true if there is any value for aggregate.  */
221  bool is_empty () const
222  {
223    return items.is_empty ();
224  }
225
226  ipa_agg_value_set copy () const
227  {
228    ipa_agg_value_set new_copy;
229
230    new_copy.items = items.copy ();
231    new_copy.by_ref = by_ref;
232
233    return new_copy;
234  }
235
236  void release ()
237  {
238    items.release ();
239  }
240};
241
242/* Return copy of a vec<ipa_agg_value_set>.  */
243
244static inline vec<ipa_agg_value_set>
245ipa_copy_agg_values (const vec<ipa_agg_value_set> &aggs)
246{
247  vec<ipa_agg_value_set> aggs_copy = vNULL;
248
249  if (!aggs.is_empty ())
250    {
251      ipa_agg_value_set *agg;
252      int i;
253
254      aggs_copy.reserve_exact (aggs.length ());
255
256      FOR_EACH_VEC_ELT (aggs, i, agg)
257	aggs_copy.quick_push (agg->copy ());
258    }
259
260  return aggs_copy;
261}
262
263/* For vec<ipa_agg_value_set>, DO NOT call release(), use below function
264   instead.  Because ipa_agg_value_set contains a field of vector type, we
265   should release this child vector in each element before reclaiming the
266   whole vector.  */
267
268static inline void
269ipa_release_agg_values (vec<ipa_agg_value_set> &aggs,
270			bool release_vector = true)
271{
272  ipa_agg_value_set *agg;
273  int i;
274
275  FOR_EACH_VEC_ELT (aggs, i, agg)
276    agg->release ();
277  if (release_vector)
278    aggs.release ();
279}
280
281/* Information about zero/non-zero bits.  */
282class GTY(()) ipa_bits
283{
284public:
285  /* The propagated value.  */
286  widest_int value;
287  /* Mask corresponding to the value.
288     Similar to ccp_lattice_t, if xth bit of mask is 0,
289     implies xth bit of value is constant.  */
290  widest_int mask;
291};
292
293/* Info about value ranges.  */
294
295class GTY(()) ipa_vr
296{
297public:
298  /* The data fields below are valid only if known is true.  */
299  bool known;
300  enum value_range_kind type;
301  wide_int min;
302  wide_int max;
303  bool nonzero_p (tree) const;
304};
305
306/* A jump function for a callsite represents the values passed as actual
307   arguments of the callsite. See enum jump_func_type for the various
308   types of jump functions supported.  */
309struct GTY (()) ipa_jump_func
310{
311  /* Aggregate jump function description.  See struct ipa_agg_jump_function
312     and its description.  */
313  struct ipa_agg_jump_function agg;
314
315  /* Information about zero/non-zero bits.  The pointed to structure is shared
316     betweed different jump functions.  Use ipa_set_jfunc_bits to set this
317     field.  */
318  class ipa_bits *bits;
319
320  /* Information about value range, containing valid data only when vr_known is
321     true.  The pointed to structure is shared betweed different jump
322     functions.  Use ipa_set_jfunc_vr to set this field.  */
323  class value_range *m_vr;
324
325  enum jump_func_type type;
326  /* Represents a value of a jump function.  pass_through is used only in jump
327     function context.  constant represents the actual constant in constant jump
328     functions and member_cst holds constant c++ member functions.  */
329  union jump_func_value
330  {
331    struct ipa_constant_data GTY ((tag ("IPA_JF_CONST"))) constant;
332    struct ipa_pass_through_data GTY ((tag ("IPA_JF_PASS_THROUGH"))) pass_through;
333    struct ipa_ancestor_jf_data GTY ((tag ("IPA_JF_ANCESTOR"))) ancestor;
334  } GTY ((desc ("%1.type"))) value;
335};
336
337
338/* Return the constant stored in a constant jump functin JFUNC.  */
339
340static inline tree
341ipa_get_jf_constant (struct ipa_jump_func *jfunc)
342{
343  gcc_checking_assert (jfunc->type == IPA_JF_CONST);
344  return jfunc->value.constant.value;
345}
346
347static inline struct ipa_cst_ref_desc *
348ipa_get_jf_constant_rdesc (struct ipa_jump_func *jfunc)
349{
350  gcc_checking_assert (jfunc->type == IPA_JF_CONST);
351  return jfunc->value.constant.rdesc;
352}
353
354/* Return the operand of a pass through jmp function JFUNC.  */
355
356static inline tree
357ipa_get_jf_pass_through_operand (struct ipa_jump_func *jfunc)
358{
359  gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
360  return jfunc->value.pass_through.operand;
361}
362
363/* Return the number of the caller's formal parameter that a pass through jump
364   function JFUNC refers to.  */
365
366static inline int
367ipa_get_jf_pass_through_formal_id (struct ipa_jump_func *jfunc)
368{
369  gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
370  return jfunc->value.pass_through.formal_id;
371}
372
373/* Return operation of a pass through jump function JFUNC.  */
374
375static inline enum tree_code
376ipa_get_jf_pass_through_operation (struct ipa_jump_func *jfunc)
377{
378  gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
379  return jfunc->value.pass_through.operation;
380}
381
382/* Return the agg_preserved flag of a pass through jump function JFUNC.  */
383
384static inline bool
385ipa_get_jf_pass_through_agg_preserved (struct ipa_jump_func *jfunc)
386{
387  gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
388  return jfunc->value.pass_through.agg_preserved;
389}
390
391/* Return true if pass through jump function JFUNC preserves type
392   information.  */
393
394static inline bool
395ipa_get_jf_pass_through_type_preserved (struct ipa_jump_func *jfunc)
396{
397  gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
398  return jfunc->value.pass_through.agg_preserved;
399}
400
401/* Return the offset of an ancestor jump function JFUNC.  */
402
403static inline HOST_WIDE_INT
404ipa_get_jf_ancestor_offset (struct ipa_jump_func *jfunc)
405{
406  gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
407  return jfunc->value.ancestor.offset;
408}
409
410/* Return the number of the caller's formal parameter that an ancestor jump
411   function JFUNC refers to.  */
412
413static inline int
414ipa_get_jf_ancestor_formal_id (struct ipa_jump_func *jfunc)
415{
416  gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
417  return jfunc->value.ancestor.formal_id;
418}
419
420/* Return the agg_preserved flag of an ancestor jump function JFUNC.  */
421
422static inline bool
423ipa_get_jf_ancestor_agg_preserved (struct ipa_jump_func *jfunc)
424{
425  gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
426  return jfunc->value.ancestor.agg_preserved;
427}
428
429/* Return true if ancestor jump function JFUNC presrves type information.  */
430
431static inline bool
432ipa_get_jf_ancestor_type_preserved (struct ipa_jump_func *jfunc)
433{
434  gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
435  return jfunc->value.ancestor.agg_preserved;
436}
437
438/* Return if jfunc represents an operation whether we first check the formal
439   parameter for non-NULLness unless it does not matter because the offset is
440   zero anyway.  */
441
442static inline bool
443ipa_get_jf_ancestor_keep_null (struct ipa_jump_func *jfunc)
444{
445  gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
446  return jfunc->value.ancestor.keep_null;
447}
448
449/* Summary describing a single formal parameter.  */
450
451struct GTY(()) ipa_param_descriptor
452{
453  /* In analysis and modification phase, this is the PARAM_DECL of this
454     parameter, in IPA LTO phase, this is the type of the described
455     parameter or NULL if not known.  Do not read this field directly but
456     through ipa_get_param and ipa_get_type as appropriate.  */
457  tree decl_or_type;
458  /* If all uses of the parameter are described by ipa-prop structures, this
459     says how many there are.  If any use could not be described by means of
460     ipa-prop structures, this is IPA_UNDESCRIBED_USE.  */
461  int controlled_uses;
462  unsigned int move_cost : 28;
463  /* The parameter is used.  */
464  unsigned used : 1;
465  unsigned used_by_ipa_predicates : 1;
466  unsigned used_by_indirect_call : 1;
467  unsigned used_by_polymorphic_call : 1;
468};
469
470/* ipa_node_params stores information related to formal parameters of functions
471   and some other information for interprocedural passes that operate on
472   parameters (such as ipa-cp).  */
473
474class GTY((for_user)) ipa_node_params
475{
476public:
477  /* Default constructor.  */
478  ipa_node_params ();
479
480  /* Default destructor.  */
481  ~ipa_node_params ();
482
483  /* Information about individual formal parameters that are gathered when
484     summaries are generated. */
485  vec<ipa_param_descriptor, va_gc> *descriptors;
486  /* Pointer to an array of structures describing individual formal
487     parameters.  */
488  class ipcp_param_lattices * GTY((skip)) lattices;
489  /* Only for versioned nodes this field would not be NULL,
490     it points to the node that IPA cp cloned from.  */
491  struct cgraph_node * GTY((skip)) ipcp_orig_node;
492  /* If this node is an ipa-cp clone, these are the known constants that
493     describe what it has been specialized for.  */
494  vec<tree> GTY((skip)) known_csts;
495  /* If this node is an ipa-cp clone, these are the known polymorphic contexts
496     that describe what it has been specialized for.  */
497  vec<ipa_polymorphic_call_context> GTY((skip)) known_contexts;
498  /* Whether the param uses analysis and jump function computation has already
499     been performed.  */
500  unsigned analysis_done : 1;
501  /* Whether the function is enqueued in ipa-cp propagation stack.  */
502  unsigned node_enqueued : 1;
503  /* Whether we should create a specialized version based on values that are
504     known to be constant in all contexts.  */
505  unsigned do_clone_for_all_contexts : 1;
506  /* Set if this is an IPA-CP clone for all contexts.  */
507  unsigned is_all_contexts_clone : 1;
508  /* Node has been completely replaced by clones and will be removed after
509     ipa-cp is finished.  */
510  unsigned node_dead : 1;
511  /* Node is involved in a recursion, potentionally indirect.  */
512  unsigned node_within_scc : 1;
513  /* Node contains only direct recursion.  */
514  unsigned node_is_self_scc : 1;
515  /* Node is calling a private function called only once.  */
516  unsigned node_calling_single_call : 1;
517  /* False when there is something makes versioning impossible.  */
518  unsigned versionable : 1;
519};
520
521inline
522ipa_node_params::ipa_node_params ()
523: descriptors (NULL), lattices (NULL), ipcp_orig_node (NULL),
524  known_csts (vNULL), known_contexts (vNULL), analysis_done (0),
525  node_enqueued (0), do_clone_for_all_contexts (0), is_all_contexts_clone (0),
526  node_dead (0), node_within_scc (0), node_calling_single_call (0),
527  versionable (0)
528{
529}
530
531inline
532ipa_node_params::~ipa_node_params ()
533{
534  free (lattices);
535  known_csts.release ();
536  known_contexts.release ();
537}
538
539/* Intermediate information that we get from alias analysis about a particular
540   parameter in a particular basic_block.  When a parameter or the memory it
541   references is marked modified, we use that information in all dominated
542   blocks without consulting alias analysis oracle.  */
543
544struct ipa_param_aa_status
545{
546  /* Set when this structure contains meaningful information.  If not, the
547     structure describing a dominating BB should be used instead.  */
548  bool valid;
549
550  /* Whether we have seen something which might have modified the data in
551     question.  PARM is for the parameter itself, REF is for data it points to
552     but using the alias type of individual accesses and PT is the same thing
553     but for computing aggregate pass-through functions using a very inclusive
554     ao_ref.  */
555  bool parm_modified, ref_modified, pt_modified;
556};
557
558/* Information related to a given BB that used only when looking at function
559   body.  */
560
561struct ipa_bb_info
562{
563  /* Call graph edges going out of this BB.  */
564  vec<cgraph_edge *> cg_edges;
565  /* Alias analysis statuses of each formal parameter at this bb.  */
566  vec<ipa_param_aa_status> param_aa_statuses;
567};
568
569/* Structure with global information that is only used when looking at function
570   body. */
571
572struct ipa_func_body_info
573{
574  /* The node that is being analyzed.  */
575  cgraph_node *node;
576
577  /* Its info.  */
578  class ipa_node_params *info;
579
580  /* Information about individual BBs. */
581  vec<ipa_bb_info> bb_infos;
582
583  /* Number of parameters.  */
584  int param_count;
585
586  /* Number of statements we are still allowed to walked by when analyzing this
587     function.  */
588  unsigned int aa_walk_budget;
589};
590
591/* ipa_node_params access functions.  Please use these to access fields that
592   are or will be shared among various passes.  */
593
594/* Return the number of formal parameters. */
595
596static inline int
597ipa_get_param_count (class ipa_node_params *info)
598{
599  return vec_safe_length (info->descriptors);
600}
601
602/* Return the declaration of Ith formal parameter of the function corresponding
603   to INFO.  Note there is no setter function as this array is built just once
604   using ipa_initialize_node_params.  This function should not be called in
605   WPA.  */
606
607static inline tree
608ipa_get_param (class ipa_node_params *info, int i)
609{
610  gcc_checking_assert (info->descriptors);
611  tree t = (*info->descriptors)[i].decl_or_type;
612  gcc_checking_assert (TREE_CODE (t) == PARM_DECL);
613  return t;
614}
615
616/* Return the type of Ith formal parameter of the function corresponding
617   to INFO if it is known or NULL if not.  */
618
619static inline tree
620ipa_get_type (class ipa_node_params *info, int i)
621{
622  if (vec_safe_length (info->descriptors) <= (unsigned) i)
623    return NULL;
624  tree t = (*info->descriptors)[i].decl_or_type;
625  if (!t)
626    return NULL;
627  if (TYPE_P (t))
628    return t;
629  gcc_checking_assert (TREE_CODE (t) == PARM_DECL);
630  return TREE_TYPE (t);
631}
632
633/* Return the move cost of Ith formal parameter of the function corresponding
634   to INFO.  */
635
636static inline int
637ipa_get_param_move_cost (class ipa_node_params *info, int i)
638{
639  gcc_checking_assert (info->descriptors);
640  return (*info->descriptors)[i].move_cost;
641}
642
643/* Set the used flag corresponding to the Ith formal parameter of the function
644   associated with INFO to VAL.  */
645
646static inline void
647ipa_set_param_used (class ipa_node_params *info, int i, bool val)
648{
649  gcc_checking_assert (info->descriptors);
650  (*info->descriptors)[i].used = val;
651}
652
653/* Set the used_by_ipa_predicates flag corresponding to the Ith formal
654   parameter of the function associated with INFO to VAL.  */
655
656static inline void
657ipa_set_param_used_by_ipa_predicates (class ipa_node_params *info, int i, bool val)
658{
659  gcc_checking_assert (info->descriptors);
660  (*info->descriptors)[i].used_by_ipa_predicates = val;
661}
662
663/* Set the used_by_indirect_call flag corresponding to the Ith formal
664   parameter of the function associated with INFO to VAL.  */
665
666static inline void
667ipa_set_param_used_by_indirect_call (class ipa_node_params *info, int i, bool val)
668{
669  gcc_checking_assert (info->descriptors);
670  (*info->descriptors)[i].used_by_indirect_call = val;
671}
672
673/* Set the .used_by_polymorphic_call flag corresponding to the Ith formal
674   parameter of the function associated with INFO to VAL.  */
675
676static inline void
677ipa_set_param_used_by_polymorphic_call (class ipa_node_params *info, int i, bool val)
678{
679  gcc_checking_assert (info->descriptors);
680  (*info->descriptors)[i].used_by_polymorphic_call = val;
681}
682
683/* Return how many uses described by ipa-prop a parameter has or
684   IPA_UNDESCRIBED_USE if there is a use that is not described by these
685   structures.  */
686static inline int
687ipa_get_controlled_uses (class ipa_node_params *info, int i)
688{
689  /* FIXME: introducing speculation causes out of bounds access here.  */
690  if (vec_safe_length (info->descriptors) > (unsigned)i)
691    return (*info->descriptors)[i].controlled_uses;
692  return IPA_UNDESCRIBED_USE;
693}
694
695/* Set the controlled counter of a given parameter.  */
696
697static inline void
698ipa_set_controlled_uses (class ipa_node_params *info, int i, int val)
699{
700  gcc_checking_assert (info->descriptors);
701  (*info->descriptors)[i].controlled_uses = val;
702}
703
704/* Return the used flag corresponding to the Ith formal parameter of the
705   function associated with INFO.  */
706
707static inline bool
708ipa_is_param_used (class ipa_node_params *info, int i)
709{
710  gcc_checking_assert (info->descriptors);
711  return (*info->descriptors)[i].used;
712}
713
714/* Return the used_by_ipa_predicates flag corresponding to the Ith formal
715   parameter of the function associated with INFO.  */
716
717static inline bool
718ipa_is_param_used_by_ipa_predicates (class ipa_node_params *info, int i)
719{
720  gcc_checking_assert (info->descriptors);
721  return (*info->descriptors)[i].used_by_ipa_predicates;
722}
723
724/* Return the used_by_indirect_call flag corresponding to the Ith formal
725   parameter of the function associated with INFO.  */
726
727static inline bool
728ipa_is_param_used_by_indirect_call (class ipa_node_params *info, int i)
729{
730  gcc_checking_assert (info->descriptors);
731  return (*info->descriptors)[i].used_by_indirect_call;
732}
733
734/* Return the used_by_polymorphic_call flag corresponding to the Ith formal
735   parameter of the function associated with INFO.  */
736
737static inline bool
738ipa_is_param_used_by_polymorphic_call (class ipa_node_params *info, int i)
739{
740  gcc_checking_assert (info->descriptors);
741  return (*info->descriptors)[i].used_by_polymorphic_call;
742}
743
744/* Information about replacements done in aggregates for a given node (each
745   node has its linked list).  */
746struct GTY(()) ipa_agg_replacement_value
747{
748  /* Next item in the linked list.  */
749  struct ipa_agg_replacement_value *next;
750  /* Offset within the aggregate.  */
751  HOST_WIDE_INT offset;
752  /* The constant value.  */
753  tree value;
754  /* The parameter index.  */
755  int index;
756  /* Whether the value was passed by reference.  */
757  bool by_ref;
758};
759
760/* Structure holding information for the transformation phase of IPA-CP.  */
761
762struct GTY(()) ipcp_transformation
763{
764  /* Linked list of known aggregate values.  */
765  ipa_agg_replacement_value *agg_values;
766  /* Known bits information.  */
767  vec<ipa_bits *, va_gc> *bits;
768  /* Value range information.  */
769  vec<ipa_vr, va_gc> *m_vr;
770
771  /* Default constructor.  */
772  ipcp_transformation ()
773  : agg_values (NULL), bits (NULL), m_vr (NULL)
774  { }
775
776  /* Default destructor.  */
777  ~ipcp_transformation ()
778  {
779    ipa_agg_replacement_value *agg = agg_values;
780    while (agg)
781      {
782	ipa_agg_replacement_value *next = agg->next;
783	ggc_free (agg);
784	agg = next;
785      }
786    vec_free (bits);
787    vec_free (m_vr);
788  }
789};
790
791void ipa_set_node_agg_value_chain (struct cgraph_node *node,
792				   struct ipa_agg_replacement_value *aggvals);
793void ipcp_transformation_initialize (void);
794void ipcp_free_transformation_sum (void);
795
796/* ipa_edge_args stores information related to a callsite and particularly its
797   arguments.  It can be accessed by the IPA_EDGE_REF macro.  */
798
799class GTY((for_user)) ipa_edge_args
800{
801 public:
802
803  /* Default constructor.  */
804  ipa_edge_args () : jump_functions (NULL), polymorphic_call_contexts (NULL)
805    {}
806
807  /* Destructor.  */
808  ~ipa_edge_args ()
809    {
810      vec_free (jump_functions);
811      vec_free (polymorphic_call_contexts);
812    }
813
814  /* Vectors of the callsite's jump function and polymorphic context
815     information of each parameter.  */
816  vec<ipa_jump_func, va_gc> *jump_functions;
817  vec<ipa_polymorphic_call_context, va_gc> *polymorphic_call_contexts;
818};
819
820/* ipa_edge_args access functions.  Please use these to access fields that
821   are or will be shared among various passes.  */
822
823/* Return the number of actual arguments. */
824
825static inline int
826ipa_get_cs_argument_count (class ipa_edge_args *args)
827{
828  return vec_safe_length (args->jump_functions);
829}
830
831/* Returns a pointer to the jump function for the ith argument.  Please note
832   there is no setter function as jump functions are all set up in
833   ipa_compute_jump_functions. */
834
835static inline struct ipa_jump_func *
836ipa_get_ith_jump_func (class ipa_edge_args *args, int i)
837{
838  return &(*args->jump_functions)[i];
839}
840
841/* Returns a pointer to the polymorphic call context for the ith argument.
842   NULL if contexts are not computed.  */
843static inline class ipa_polymorphic_call_context *
844ipa_get_ith_polymorhic_call_context (class ipa_edge_args *args, int i)
845{
846  if (!args->polymorphic_call_contexts)
847    return NULL;
848  return &(*args->polymorphic_call_contexts)[i];
849}
850
851/* Function summary for ipa_node_params.  */
852class GTY((user)) ipa_node_params_t: public function_summary <ipa_node_params *>
853{
854public:
855  ipa_node_params_t (symbol_table *table, bool ggc):
856    function_summary<ipa_node_params *> (table, ggc) { }
857
858  /* Hook that is called by summary when a node is duplicated.  */
859  virtual void duplicate (cgraph_node *node,
860			  cgraph_node *node2,
861			  ipa_node_params *data,
862			  ipa_node_params *data2);
863};
864
865/* Summary to manange ipa_edge_args structures.  */
866
867class GTY((user)) ipa_edge_args_sum_t : public call_summary <ipa_edge_args *>
868{
869 public:
870  ipa_edge_args_sum_t (symbol_table *table, bool ggc)
871    : call_summary<ipa_edge_args *> (table, ggc) { }
872
873  void remove (cgraph_edge *edge)
874  {
875    call_summary <ipa_edge_args *>::remove (edge);
876  }
877
878  /* Hook that is called by summary when an edge is removed.  */
879  virtual void remove (cgraph_edge *cs, ipa_edge_args *args);
880  /* Hook that is called by summary when an edge is duplicated.  */
881  virtual void duplicate (cgraph_edge *src,
882			  cgraph_edge *dst,
883			  ipa_edge_args *old_args,
884			  ipa_edge_args *new_args);
885};
886
887/* Function summary where the parameter infos are actually stored. */
888extern GTY(()) ipa_node_params_t * ipa_node_params_sum;
889/* Call summary to store information about edges such as jump functions.  */
890extern GTY(()) ipa_edge_args_sum_t *ipa_edge_args_sum;
891
892/* Function summary for IPA-CP transformation.  */
893class ipcp_transformation_t
894: public function_summary<ipcp_transformation *>
895{
896public:
897  ipcp_transformation_t (symbol_table *table, bool ggc):
898    function_summary<ipcp_transformation *> (table, ggc) {}
899
900  ~ipcp_transformation_t () {}
901
902  static ipcp_transformation_t *create_ggc (symbol_table *symtab)
903  {
904    ipcp_transformation_t *summary
905      = new (ggc_alloc_no_dtor <ipcp_transformation_t> ())
906      ipcp_transformation_t (symtab, true);
907    return summary;
908  }
909  /* Hook that is called by summary when a node is duplicated.  */
910  virtual void duplicate (cgraph_node *node,
911			  cgraph_node *node2,
912			  ipcp_transformation *data,
913			  ipcp_transformation *data2);
914};
915
916/* Function summary where the IPA CP transformations are actually stored.  */
917extern GTY(()) function_summary <ipcp_transformation *> *ipcp_transformation_sum;
918
919/* Return the associated parameter/argument info corresponding to the given
920   node/edge.  */
921#define IPA_NODE_REF(NODE) (ipa_node_params_sum->get (NODE))
922#define IPA_NODE_REF_GET_CREATE(NODE) (ipa_node_params_sum->get_create (NODE))
923#define IPA_EDGE_REF(EDGE) (ipa_edge_args_sum->get (EDGE))
924#define IPA_EDGE_REF_GET_CREATE(EDGE) (ipa_edge_args_sum->get_create (EDGE))
925/* This macro checks validity of index returned by
926   ipa_get_param_decl_index function.  */
927#define IS_VALID_JUMP_FUNC_INDEX(I) ((I) != -1)
928
929/* Creating and freeing ipa_node_params and ipa_edge_args.  */
930void ipa_create_all_node_params (void);
931void ipa_create_all_edge_args (void);
932void ipa_check_create_edge_args (void);
933void ipa_free_all_node_params (void);
934void ipa_free_all_edge_args (void);
935void ipa_free_all_structures_after_ipa_cp (void);
936void ipa_free_all_structures_after_iinln (void);
937
938void ipa_register_cgraph_hooks (void);
939int count_formal_params (tree fndecl);
940
941/* This function ensures the array of node param infos is big enough to
942   accommodate a structure for all nodes and reallocates it if not.  */
943
944static inline void
945ipa_check_create_node_params (void)
946{
947  if (!ipa_node_params_sum)
948    ipa_node_params_sum
949      = (new (ggc_alloc_no_dtor <ipa_node_params_t> ())
950	 ipa_node_params_t (symtab, true));
951}
952
953/* Returns true if edge summary contains a record for EDGE.  The main purpose
954   of this function is that debug dumping function can check info availability
955   without causing allocations.  */
956
957static inline bool
958ipa_edge_args_info_available_for_edge_p (struct cgraph_edge *edge)
959{
960  return ipa_edge_args_sum->exists (edge);
961}
962
963static inline ipcp_transformation *
964ipcp_get_transformation_summary (cgraph_node *node)
965{
966  if (ipcp_transformation_sum == NULL)
967    return NULL;
968
969  return ipcp_transformation_sum->get (node);
970}
971
972/* Return the aggregate replacements for NODE, if there are any.  */
973
974static inline struct ipa_agg_replacement_value *
975ipa_get_agg_replacements_for_node (cgraph_node *node)
976{
977  ipcp_transformation *ts = ipcp_get_transformation_summary (node);
978  return ts ? ts->agg_values : NULL;
979}
980
981/* Function formal parameters related computations.  */
982void ipa_initialize_node_params (struct cgraph_node *node);
983bool ipa_propagate_indirect_call_infos (struct cgraph_edge *cs,
984					vec<cgraph_edge *> *new_edges);
985
986/* Indirect edge and binfo processing.  */
987tree ipa_get_indirect_edge_target (struct cgraph_edge *ie,
988				   vec<tree>,
989				   vec<ipa_polymorphic_call_context>,
990				   vec<ipa_agg_value_set>,
991				   bool *);
992struct cgraph_edge *ipa_make_edge_direct_to_target (struct cgraph_edge *, tree,
993						    bool speculative = false);
994tree ipa_impossible_devirt_target (struct cgraph_edge *, tree);
995ipa_bits *ipa_get_ipa_bits_for_value (const widest_int &value,
996				      const widest_int &mask);
997
998
999/* Functions related to both.  */
1000void ipa_analyze_node (struct cgraph_node *);
1001
1002/* Aggregate jump function related functions.  */
1003tree ipa_find_agg_cst_for_param (struct ipa_agg_value_set *agg, tree scalar,
1004				 HOST_WIDE_INT offset, bool by_ref,
1005				 bool *from_global_constant = NULL);
1006bool ipa_load_from_parm_agg (struct ipa_func_body_info *fbi,
1007			     vec<ipa_param_descriptor, va_gc> *descriptors,
1008			     gimple *stmt, tree op, int *index_p,
1009			     HOST_WIDE_INT *offset_p, poly_int64 *size_p,
1010			     bool *by_ref, bool *guaranteed_unmodified = NULL);
1011
1012/* Debugging interface.  */
1013void ipa_print_node_params (FILE *, struct cgraph_node *node);
1014void ipa_print_all_params (FILE *);
1015void ipa_print_node_jump_functions (FILE *f, struct cgraph_node *node);
1016void ipa_print_all_jump_functions (FILE * f);
1017void ipcp_verify_propagated_values (void);
1018
1019template <typename value>
1020class ipcp_value;
1021
1022extern object_allocator<ipcp_value<tree> > ipcp_cst_values_pool;
1023extern object_allocator<ipcp_value<ipa_polymorphic_call_context> >
1024  ipcp_poly_ctx_values_pool;
1025
1026template <typename valtype>
1027struct ipcp_value_source;
1028
1029extern object_allocator<ipcp_value_source<tree> > ipcp_sources_pool;
1030
1031struct ipcp_agg_lattice;
1032
1033extern object_allocator<ipcp_agg_lattice> ipcp_agg_lattice_pool;
1034
1035void ipa_dump_agg_replacement_values (FILE *f,
1036				      struct ipa_agg_replacement_value *av);
1037void ipa_prop_write_jump_functions (void);
1038void ipa_prop_read_jump_functions (void);
1039void ipcp_write_transformation_summaries (void);
1040void ipcp_read_transformation_summaries (void);
1041int ipa_get_param_decl_index (class ipa_node_params *, tree);
1042tree ipa_value_from_jfunc (class ipa_node_params *info,
1043			   struct ipa_jump_func *jfunc, tree type);
1044unsigned int ipcp_transform_function (struct cgraph_node *node);
1045ipa_polymorphic_call_context ipa_context_from_jfunc (ipa_node_params *,
1046						     cgraph_edge *,
1047						     int,
1048						     ipa_jump_func *);
1049value_range ipa_value_range_from_jfunc (ipa_node_params *, cgraph_edge *,
1050					ipa_jump_func *, tree);
1051ipa_agg_value_set ipa_agg_value_set_from_jfunc (ipa_node_params *,
1052						cgraph_node *,
1053						ipa_agg_jump_function *);
1054void ipa_dump_param (FILE *, class ipa_node_params *info, int i);
1055void ipa_release_body_info (struct ipa_func_body_info *);
1056tree ipa_get_callee_param_type (struct cgraph_edge *e, int i);
1057bool ipcp_get_parm_bits (tree, tree *, widest_int *);
1058
1059/* From tree-sra.c:  */
1060tree build_ref_for_offset (location_t, tree, poly_int64, bool, tree,
1061			   gimple_stmt_iterator *, bool);
1062
1063/* In ipa-cp.c  */
1064void ipa_cp_c_finalize (void);
1065
1066#endif /* IPA_PROP_H */
1067