Fix ICE on view conversion between struct and integer
[official-gcc.git] / gcc / ipa-prop.h
blob8811e0ea98741e6e7b296e5d9e6bc56ee5fbd25a
1 /* Interprocedural analyses.
2 Copyright (C) 2005-2022 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef IPA_PROP_H
21 #define IPA_PROP_H
23 /* The following definitions and interfaces are used by
24 interprocedural analyses or parameters. */
26 #define IPA_UNDESCRIBED_USE -1
28 /* ipa-prop.cc stuff (ipa-cp, indirect inlining): */
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 :
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.
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.
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.
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).
62 Jump functions are computed in ipa-prop.cc 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. */
67 enum jump_func_type
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 */
76 struct ipa_cst_ref_desc;
78 /* Structure holding data required to describe a constant jump function. */
79 struct GTY(()) ipa_constant_data
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;
87 /* Structure holding data required to describe a pass-through jump function. */
89 struct GTY(()) ipa_pass_through_data
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 Special values which have other meaning than in normal contexts:
98 - NOP_EXPR means no operation, not even type conversion.
99 - ASSERT_EXPR means that only the value in operand is allowed to pass
100 through (without any change), for all other values the result is
101 unknown.
102 Otherwise operation must be a simple binary or unary arithmetic operation
103 where the caller's parameter is the first operand and (for binary
104 operations) the operand field from this structure is the second one. */
105 enum tree_code operation;
106 /* When the passed value is a pointer, it is set to true only when we are
107 certain that no write to the object it points to has occurred since the
108 caller functions started execution, except for changes noted in the
109 aggregate part of the jump function (see description of
110 ipa_agg_jump_function). The flag is used only when the operation is
111 NOP_EXPR. */
112 unsigned agg_preserved : 1;
115 /* Structure holding data required to describe a load-value-from-aggregate
116 jump function. */
118 struct GTY(()) ipa_load_agg_data
120 /* Inherit from pass through jump function, describing unary/binary
121 operation on the value loaded from aggregate that is represented or
122 pointed to by the formal parameter, specified by formal_id in this
123 pass_through jump function data structure. */
124 struct ipa_pass_through_data pass_through;
125 /* Type of the value loaded from the aggregate. */
126 tree type;
127 /* Offset at which the value is located within the aggregate. */
128 HOST_WIDE_INT offset;
129 /* True if loaded by reference (the aggregate is pointed to by the formal
130 parameter) or false if loaded by value (the aggregate is represented
131 by the formal parameter). */
132 bool by_ref;
135 /* Structure holding data required to describe an ancestor pass-through
136 jump function. */
138 struct GTY(()) ipa_ancestor_jf_data
140 /* Offset of the field representing the ancestor. */
141 HOST_WIDE_INT offset;
142 /* Number of the caller's formal parameter being passed. */
143 int formal_id;
144 /* Flag with the same meaning like agg_preserve in ipa_pass_through_data. */
145 unsigned agg_preserved : 1;
146 /* When set, the operation should not have any effect on NULL pointers. */
147 unsigned keep_null : 1;
150 /* A jump function for an aggregate part at a given offset, which describes how
151 it content value is generated. All unlisted positions are assumed to have a
152 value defined in an unknown way. */
154 struct GTY(()) ipa_agg_jf_item
156 /* The offset for the aggregate part. */
157 HOST_WIDE_INT offset;
159 /* Data type of the aggregate part. */
160 tree type;
162 /* Jump function type. */
163 enum jump_func_type jftype;
165 /* Represents a value of jump function. constant represents the actual constant
166 in constant jump function content. pass_through is used only in simple pass
167 through jump function context. load_agg is for load-value-from-aggregate
168 jump function context. */
169 union jump_func_agg_value
171 tree GTY ((tag ("IPA_JF_CONST"))) constant;
172 struct ipa_pass_through_data GTY ((tag ("IPA_JF_PASS_THROUGH"))) pass_through;
173 struct ipa_load_agg_data GTY ((tag ("IPA_JF_LOAD_AGG"))) load_agg;
174 } GTY ((desc ("%1.jftype"))) value;
177 /* Jump functions describing a set of aggregate contents. */
179 struct GTY(()) ipa_agg_jump_function
181 /* Description of the individual jump function item. */
182 vec<ipa_agg_jf_item, va_gc> *items;
183 /* True if the data was passed by reference (as opposed to by value). */
184 bool by_ref;
187 /* An element in an aggregate part describing a known value at a given offset.
188 All unlisted positions are assumed to be unknown and all listed values must
189 fulfill is_gimple_ip_invariant. */
191 struct ipa_agg_value
193 /* The offset at which the known value is located within the aggregate. */
194 HOST_WIDE_INT offset;
196 /* The known constant. */
197 tree value;
199 /* Return true if OTHER describes same agg value. */
200 bool equal_to (const ipa_agg_value &other);
203 /* Structure describing a set of known offset/value for aggregate. */
205 struct ipa_agg_value_set
207 /* Description of the individual item. */
208 vec<ipa_agg_value> items;
209 /* True if the data was passed by reference (as opposed to by value). */
210 bool by_ref;
212 /* Return true if OTHER describes same agg values. */
213 bool equal_to (const ipa_agg_value_set &other)
215 if (by_ref != other.by_ref)
216 return false;
217 if (items.length () != other.items.length ())
218 return false;
219 for (unsigned int i = 0; i < items.length (); i++)
220 if (!items[i].equal_to (other.items[i]))
221 return false;
222 return true;
225 /* Return true if there is any value for aggregate. */
226 bool is_empty () const
228 return items.is_empty ();
231 ipa_agg_value_set copy () const
233 ipa_agg_value_set new_copy;
235 new_copy.items = items.copy ();
236 new_copy.by_ref = by_ref;
238 return new_copy;
241 void release ()
243 items.release ();
247 /* Return copy of a vec<ipa_agg_value_set>. */
249 static inline vec<ipa_agg_value_set>
250 ipa_copy_agg_values (const vec<ipa_agg_value_set> &aggs)
252 vec<ipa_agg_value_set> aggs_copy = vNULL;
254 if (!aggs.is_empty ())
256 ipa_agg_value_set *agg;
257 int i;
259 aggs_copy.reserve_exact (aggs.length ());
261 FOR_EACH_VEC_ELT (aggs, i, agg)
262 aggs_copy.quick_push (agg->copy ());
265 return aggs_copy;
268 /* For vec<ipa_agg_value_set>, DO NOT call release(), use below function
269 instead. Because ipa_agg_value_set contains a field of vector type, we
270 should release this child vector in each element before reclaiming the
271 whole vector. */
273 static inline void
274 ipa_release_agg_values (vec<ipa_agg_value_set> &aggs,
275 bool release_vector = true)
277 ipa_agg_value_set *agg;
278 int i;
280 FOR_EACH_VEC_ELT (aggs, i, agg)
281 agg->release ();
282 if (release_vector)
283 aggs.release ();
286 /* Information about zero/non-zero bits. */
287 class GTY(()) ipa_bits
289 public:
290 /* The propagated value. */
291 widest_int value;
292 /* Mask corresponding to the value.
293 Similar to ccp_lattice_t, if xth bit of mask is 0,
294 implies xth bit of value is constant. */
295 widest_int mask;
298 /* Info about value ranges. */
300 class GTY(()) ipa_vr
302 public:
303 /* The data fields below are valid only if known is true. */
304 bool known;
305 enum value_range_kind type;
306 wide_int min;
307 wide_int max;
308 bool nonzero_p (tree) const;
311 /* A jump function for a callsite represents the values passed as actual
312 arguments of the callsite. See enum jump_func_type for the various
313 types of jump functions supported. */
314 struct GTY (()) ipa_jump_func
316 /* Aggregate jump function description. See struct ipa_agg_jump_function
317 and its description. */
318 struct ipa_agg_jump_function agg;
320 /* Information about zero/non-zero bits. The pointed to structure is shared
321 betweed different jump functions. Use ipa_set_jfunc_bits to set this
322 field. */
323 class ipa_bits *bits;
325 /* Information about value range, containing valid data only when vr_known is
326 true. The pointed to structure is shared betweed different jump
327 functions. Use ipa_set_jfunc_vr to set this field. */
328 value_range *m_vr;
330 enum jump_func_type type;
331 /* Represents a value of a jump function. pass_through is used only in jump
332 function context. constant represents the actual constant in constant jump
333 functions and member_cst holds constant c++ member functions. */
334 union jump_func_value
336 struct ipa_constant_data GTY ((tag ("IPA_JF_CONST"))) constant;
337 struct ipa_pass_through_data GTY ((tag ("IPA_JF_PASS_THROUGH"))) pass_through;
338 struct ipa_ancestor_jf_data GTY ((tag ("IPA_JF_ANCESTOR"))) ancestor;
339 } GTY ((desc ("%1.type"))) value;
343 /* Return the constant stored in a constant jump functin JFUNC. */
345 static inline tree
346 ipa_get_jf_constant (struct ipa_jump_func *jfunc)
348 gcc_checking_assert (jfunc->type == IPA_JF_CONST);
349 return jfunc->value.constant.value;
352 static inline struct ipa_cst_ref_desc *
353 ipa_get_jf_constant_rdesc (struct ipa_jump_func *jfunc)
355 gcc_checking_assert (jfunc->type == IPA_JF_CONST);
356 return jfunc->value.constant.rdesc;
359 /* Return the operand of a pass through jmp function JFUNC. */
361 static inline tree
362 ipa_get_jf_pass_through_operand (struct ipa_jump_func *jfunc)
364 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
365 return jfunc->value.pass_through.operand;
368 /* Return the number of the caller's formal parameter that a pass through jump
369 function JFUNC refers to. */
371 static inline int
372 ipa_get_jf_pass_through_formal_id (struct ipa_jump_func *jfunc)
374 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
375 return jfunc->value.pass_through.formal_id;
378 /* Return operation of a pass through jump function JFUNC. */
380 static inline enum tree_code
381 ipa_get_jf_pass_through_operation (struct ipa_jump_func *jfunc)
383 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
384 return jfunc->value.pass_through.operation;
387 /* Return the agg_preserved flag of a pass through jump function JFUNC. */
389 static inline bool
390 ipa_get_jf_pass_through_agg_preserved (struct ipa_jump_func *jfunc)
392 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
393 return jfunc->value.pass_through.agg_preserved;
396 /* Return true if pass through jump function JFUNC preserves type
397 information. */
399 static inline bool
400 ipa_get_jf_pass_through_type_preserved (struct ipa_jump_func *jfunc)
402 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
403 return jfunc->value.pass_through.agg_preserved;
406 /* Return the offset of an ancestor jump function JFUNC. */
408 static inline HOST_WIDE_INT
409 ipa_get_jf_ancestor_offset (struct ipa_jump_func *jfunc)
411 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
412 return jfunc->value.ancestor.offset;
415 /* Return the number of the caller's formal parameter that an ancestor jump
416 function JFUNC refers to. */
418 static inline int
419 ipa_get_jf_ancestor_formal_id (struct ipa_jump_func *jfunc)
421 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
422 return jfunc->value.ancestor.formal_id;
425 /* Return the agg_preserved flag of an ancestor jump function JFUNC. */
427 static inline bool
428 ipa_get_jf_ancestor_agg_preserved (struct ipa_jump_func *jfunc)
430 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
431 return jfunc->value.ancestor.agg_preserved;
434 /* Return true if ancestor jump function JFUNC presrves type information. */
436 static inline bool
437 ipa_get_jf_ancestor_type_preserved (struct ipa_jump_func *jfunc)
439 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
440 return jfunc->value.ancestor.agg_preserved;
443 /* Return if jfunc represents an operation whether we first check the formal
444 parameter for non-NULLness unless it does not matter because the offset is
445 zero anyway. */
447 static inline bool
448 ipa_get_jf_ancestor_keep_null (struct ipa_jump_func *jfunc)
450 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
451 return jfunc->value.ancestor.keep_null;
454 /* Class for allocating a bundle of various potentially known properties about
455 actual arguments of a particular call on stack for the usual case and on
456 heap only if there are unusually many arguments. The data is deallocated
457 when the instance of this class goes out of scope or is otherwise
458 destructed. */
460 class ipa_auto_call_arg_values
462 public:
463 ~ipa_auto_call_arg_values ();
465 /* If m_known_vals (vector of known "scalar" values) is sufficiantly long,
466 return its element at INDEX, otherwise return NULL. */
467 tree safe_sval_at (int index)
469 /* TODO: Assert non-negative index here and test. */
470 if ((unsigned) index < m_known_vals.length ())
471 return m_known_vals[index];
472 return NULL;
475 /* If m_known_aggs is sufficiantly long, return the pointer rto its element
476 at INDEX, otherwise return NULL. */
477 ipa_agg_value_set *safe_aggval_at (int index)
479 /* TODO: Assert non-negative index here and test. */
480 if ((unsigned) index < m_known_aggs.length ())
481 return &m_known_aggs[index];
482 return NULL;
485 /* Vector describing known values of parameters. */
486 auto_vec<tree, 32> m_known_vals;
488 /* Vector describing known polymorphic call contexts. */
489 auto_vec<ipa_polymorphic_call_context, 32> m_known_contexts;
491 /* Vector describing known aggregate values. */
492 auto_vec<ipa_agg_value_set, 32> m_known_aggs;
494 /* Vector describing known value ranges of arguments. */
495 auto_vec<value_range, 32> m_known_value_ranges;
498 /* Class bundling the various potentially known properties about actual
499 arguments of a particular call. This variant does not deallocate the
500 bundled data in any way. */
502 class ipa_call_arg_values
504 public:
505 /* Default constructor, setting the vectors to empty ones. */
506 ipa_call_arg_values ()
509 /* Construct this general variant of the bundle from the variant which uses
510 auto_vecs to hold the vectors. This means that vectors of objects
511 constructed with this constructor should not be changed because if they
512 get reallocated, the member vectors and the underlying auto_vecs would get
513 out of sync. */
514 ipa_call_arg_values (ipa_auto_call_arg_values *aavals)
515 : m_known_vals (aavals->m_known_vals.to_vec_legacy ()),
516 m_known_contexts (aavals->m_known_contexts.to_vec_legacy ()),
517 m_known_aggs (aavals->m_known_aggs.to_vec_legacy ()),
518 m_known_value_ranges (aavals->m_known_value_ranges.to_vec_legacy ())
521 /* If m_known_vals (vector of known "scalar" values) is sufficiantly long,
522 return its element at INDEX, otherwise return NULL. */
523 tree safe_sval_at (int index)
525 /* TODO: Assert non-negative index here and test. */
526 if ((unsigned) index < m_known_vals.length ())
527 return m_known_vals[index];
528 return NULL;
531 /* If m_known_aggs is sufficiantly long, return the pointer rto its element
532 at INDEX, otherwise return NULL. */
533 ipa_agg_value_set *safe_aggval_at (int index)
535 /* TODO: Assert non-negative index here and test. */
536 if ((unsigned) index < m_known_aggs.length ())
537 return &m_known_aggs[index];
538 return NULL;
541 /* Vector describing known values of parameters. */
542 vec<tree> m_known_vals = vNULL;
544 /* Vector describing known polymorphic call contexts. */
545 vec<ipa_polymorphic_call_context> m_known_contexts = vNULL;
547 /* Vector describing known aggregate values. */
548 vec<ipa_agg_value_set> m_known_aggs = vNULL;
550 /* Vector describing known value ranges of arguments. */
551 vec<value_range> m_known_value_ranges = vNULL;
555 /* Summary describing a single formal parameter. */
557 struct GTY(()) ipa_param_descriptor
559 /* In analysis and modification phase, this is the PARAM_DECL of this
560 parameter, in IPA LTO phase, this is the type of the described
561 parameter or NULL if not known. Do not read this field directly but
562 through ipa_get_param and ipa_get_type as appropriate. */
563 tree decl_or_type;
564 /* If all uses of the parameter are described by ipa-prop structures, this
565 says how many there are. If any use could not be described by means of
566 ipa-prop structures (which include flag dereferenced below), this is
567 IPA_UNDESCRIBED_USE. */
568 int controlled_uses;
569 unsigned int move_cost : 27;
570 /* The parameter is used. */
571 unsigned used : 1;
572 unsigned used_by_ipa_predicates : 1;
573 unsigned used_by_indirect_call : 1;
574 unsigned used_by_polymorphic_call : 1;
575 /* Set to true when in addition to being used in call statements, the
576 parameter has also been used for loads (but not for writes, does not
577 escape, etc.). This allows us to identify parameters p which are only
578 used as *p, and so when we propagate a constant to them, we can generate a
579 LOAD and not ADDR reference to them. */
580 unsigned load_dereferenced : 1;
583 /* ipa_node_params stores information related to formal parameters of functions
584 and some other information for interprocedural passes that operate on
585 parameters (such as ipa-cp). */
587 class GTY((for_user)) ipa_node_params
589 public:
590 /* Default constructor. */
591 ipa_node_params ();
593 /* Default destructor. */
594 ~ipa_node_params ();
596 /* Information about individual formal parameters that are gathered when
597 summaries are generated. */
598 vec<ipa_param_descriptor, va_gc> *descriptors;
599 /* Pointer to an array of structures describing individual formal
600 parameters. */
601 class ipcp_param_lattices * GTY((skip)) lattices;
602 /* Only for versioned nodes this field would not be NULL,
603 it points to the node that IPA cp cloned from. */
604 struct cgraph_node * GTY((skip)) ipcp_orig_node;
605 /* If this node is an ipa-cp clone, these are the known constants that
606 describe what it has been specialized for. */
607 vec<tree> GTY((skip)) known_csts;
608 /* If this node is an ipa-cp clone, these are the known polymorphic contexts
609 that describe what it has been specialized for. */
610 vec<ipa_polymorphic_call_context> GTY((skip)) known_contexts;
611 /* Whether the param uses analysis and jump function computation has already
612 been performed. */
613 unsigned analysis_done : 1;
614 /* Whether the function is enqueued in ipa-cp propagation stack. */
615 unsigned node_enqueued : 1;
616 /* Whether we should create a specialized version based on values that are
617 known to be constant in all contexts. */
618 unsigned do_clone_for_all_contexts : 1;
619 /* Set if this is an IPA-CP clone for all contexts. */
620 unsigned is_all_contexts_clone : 1;
621 /* Node has been completely replaced by clones and will be removed after
622 ipa-cp is finished. */
623 unsigned node_dead : 1;
624 /* Node is involved in a recursion, potentionally indirect. */
625 unsigned node_within_scc : 1;
626 /* Node contains only direct recursion. */
627 unsigned node_is_self_scc : 1;
628 /* Node is calling a private function called only once. */
629 unsigned node_calling_single_call : 1;
630 /* False when there is something makes versioning impossible. */
631 unsigned versionable : 1;
634 inline
635 ipa_node_params::ipa_node_params ()
636 : descriptors (NULL), lattices (NULL), ipcp_orig_node (NULL),
637 known_csts (vNULL), known_contexts (vNULL), analysis_done (0),
638 node_enqueued (0), do_clone_for_all_contexts (0), is_all_contexts_clone (0),
639 node_dead (0), node_within_scc (0), node_is_self_scc (0),
640 node_calling_single_call (0), versionable (0)
644 inline
645 ipa_node_params::~ipa_node_params ()
647 free (lattices);
648 vec_free (descriptors);
649 known_csts.release ();
650 known_contexts.release ();
653 /* Intermediate information that we get from alias analysis about a particular
654 parameter in a particular basic_block. When a parameter or the memory it
655 references is marked modified, we use that information in all dominated
656 blocks without consulting alias analysis oracle. */
658 struct ipa_param_aa_status
660 /* Set when this structure contains meaningful information. If not, the
661 structure describing a dominating BB should be used instead. */
662 bool valid;
664 /* Whether we have seen something which might have modified the data in
665 question. PARM is for the parameter itself, REF is for data it points to
666 but using the alias type of individual accesses and PT is the same thing
667 but for computing aggregate pass-through functions using a very inclusive
668 ao_ref. */
669 bool parm_modified, ref_modified, pt_modified;
672 /* Information related to a given BB that used only when looking at function
673 body. */
675 struct ipa_bb_info
677 /* Call graph edges going out of this BB. */
678 vec<cgraph_edge *> cg_edges;
679 /* Alias analysis statuses of each formal parameter at this bb. */
680 vec<ipa_param_aa_status> param_aa_statuses;
683 /* Structure with global information that is only used when looking at function
684 body. */
686 struct ipa_func_body_info
688 /* The node that is being analyzed. */
689 cgraph_node *node;
691 /* Its info. */
692 class ipa_node_params *info;
694 /* Information about individual BBs. */
695 vec<ipa_bb_info> bb_infos;
697 /* Number of parameters. */
698 int param_count;
700 /* Number of statements we are still allowed to walked by when analyzing this
701 function. */
702 unsigned int aa_walk_budget;
705 /* ipa_node_params access functions. Please use these to access fields that
706 are or will be shared among various passes. */
708 /* Return the number of formal parameters. */
710 static inline int
711 ipa_get_param_count (class ipa_node_params *info)
713 return vec_safe_length (info->descriptors);
716 /* Return the parameter declaration in DESCRIPTORS at index I and assert it is
717 indeed a PARM_DECL. */
719 static inline tree
720 ipa_get_param (const vec<ipa_param_descriptor, va_gc> &descriptors, int i)
722 tree t = descriptors[i].decl_or_type;
723 gcc_checking_assert (TREE_CODE (t) == PARM_DECL);
724 return t;
727 /* Return the declaration of Ith formal parameter of the function corresponding
728 to INFO. Note there is no setter function as this array is built just once
729 using ipa_initialize_node_params. This function should not be called in
730 WPA. */
732 static inline tree
733 ipa_get_param (class ipa_node_params *info, int i)
735 gcc_checking_assert (info->descriptors);
736 return ipa_get_param (*info->descriptors, i);
739 /* Return the type of Ith formal parameter of the function corresponding
740 to INFO if it is known or NULL if not. */
742 static inline tree
743 ipa_get_type (class ipa_node_params *info, int i)
745 if (vec_safe_length (info->descriptors) <= (unsigned) i)
746 return NULL;
747 tree t = (*info->descriptors)[i].decl_or_type;
748 if (!t)
749 return NULL;
750 if (TYPE_P (t))
751 return t;
752 gcc_checking_assert (TREE_CODE (t) == PARM_DECL);
753 return TREE_TYPE (t);
756 /* Return the move cost of Ith formal parameter of the function corresponding
757 to INFO. */
759 static inline int
760 ipa_get_param_move_cost (class ipa_node_params *info, int i)
762 gcc_checking_assert (info->descriptors);
763 return (*info->descriptors)[i].move_cost;
766 /* Set the used flag corresponding to the Ith formal parameter of the function
767 associated with INFO to VAL. */
769 static inline void
770 ipa_set_param_used (class ipa_node_params *info, int i, bool val)
772 gcc_checking_assert (info->descriptors);
773 (*info->descriptors)[i].used = val;
776 /* Set the used_by_ipa_predicates flag corresponding to the Ith formal
777 parameter of the function associated with INFO to VAL. */
779 static inline void
780 ipa_set_param_used_by_ipa_predicates (class ipa_node_params *info, int i, bool val)
782 gcc_checking_assert (info->descriptors);
783 (*info->descriptors)[i].used_by_ipa_predicates = val;
786 /* Set the used_by_indirect_call flag corresponding to the Ith formal
787 parameter of the function associated with INFO to VAL. */
789 static inline void
790 ipa_set_param_used_by_indirect_call (class ipa_node_params *info, int i, bool val)
792 gcc_checking_assert (info->descriptors);
793 (*info->descriptors)[i].used_by_indirect_call = val;
796 /* Set the .used_by_polymorphic_call flag corresponding to the Ith formal
797 parameter of the function associated with INFO to VAL. */
799 static inline void
800 ipa_set_param_used_by_polymorphic_call (class ipa_node_params *info, int i, bool val)
802 gcc_checking_assert (info->descriptors);
803 (*info->descriptors)[i].used_by_polymorphic_call = val;
806 /* Return how many uses described by ipa-prop a parameter has or
807 IPA_UNDESCRIBED_USE if there is a use that is not described by these
808 structures. */
809 static inline int
810 ipa_get_controlled_uses (class ipa_node_params *info, int i)
812 /* FIXME: introducing speculation causes out of bounds access here. */
813 if (vec_safe_length (info->descriptors) > (unsigned)i)
814 return (*info->descriptors)[i].controlled_uses;
815 return IPA_UNDESCRIBED_USE;
818 /* Set the controlled counter of a given parameter. */
820 static inline void
821 ipa_set_controlled_uses (class ipa_node_params *info, int i, int val)
823 gcc_checking_assert (info->descriptors);
824 (*info->descriptors)[i].controlled_uses = val;
827 /* Assuming a parameter does not have IPA_UNDESCRIBED_USE controlled uses,
828 return flag which indicates it has been dereferenced but only in a load. */
829 static inline int
830 ipa_get_param_load_dereferenced (class ipa_node_params *info, int i)
832 gcc_assert (ipa_get_controlled_uses (info, i) != IPA_UNDESCRIBED_USE);
833 return (*info->descriptors)[i].load_dereferenced;
836 /* Set the load_dereferenced flag of a given parameter. */
838 static inline void
839 ipa_set_param_load_dereferenced (class ipa_node_params *info, int i, bool val)
841 gcc_checking_assert (info->descriptors);
842 (*info->descriptors)[i].load_dereferenced = val;
845 /* Return the used flag corresponding to the Ith formal parameter of the
846 function associated with INFO. */
848 static inline bool
849 ipa_is_param_used (class ipa_node_params *info, int i)
851 gcc_checking_assert (info->descriptors);
852 return (*info->descriptors)[i].used;
855 /* Return the used_by_ipa_predicates flag corresponding to the Ith formal
856 parameter of the function associated with INFO. */
858 static inline bool
859 ipa_is_param_used_by_ipa_predicates (class ipa_node_params *info, int i)
861 gcc_checking_assert (info->descriptors);
862 return (*info->descriptors)[i].used_by_ipa_predicates;
865 /* Return the used_by_indirect_call flag corresponding to the Ith formal
866 parameter of the function associated with INFO. */
868 static inline bool
869 ipa_is_param_used_by_indirect_call (class ipa_node_params *info, int i)
871 gcc_checking_assert (info->descriptors);
872 return (*info->descriptors)[i].used_by_indirect_call;
875 /* Return the used_by_polymorphic_call flag corresponding to the Ith formal
876 parameter of the function associated with INFO. */
878 static inline bool
879 ipa_is_param_used_by_polymorphic_call (class ipa_node_params *info, int i)
881 gcc_checking_assert (info->descriptors);
882 return (*info->descriptors)[i].used_by_polymorphic_call;
885 /* Information about replacements done in aggregates for a given node (each
886 node has its linked list). */
887 struct GTY(()) ipa_agg_replacement_value
889 /* Next item in the linked list. */
890 struct ipa_agg_replacement_value *next;
891 /* Offset within the aggregate. */
892 HOST_WIDE_INT offset;
893 /* The constant value. */
894 tree value;
895 /* The parameter index. */
896 int index;
897 /* Whether the value was passed by reference. */
898 bool by_ref;
901 /* Structure holding information for the transformation phase of IPA-CP. */
903 struct GTY(()) ipcp_transformation
905 /* Linked list of known aggregate values. */
906 ipa_agg_replacement_value *agg_values;
907 /* Known bits information. */
908 vec<ipa_bits *, va_gc> *bits;
909 /* Value range information. */
910 vec<ipa_vr, va_gc> *m_vr;
912 /* Default constructor. */
913 ipcp_transformation ()
914 : agg_values (NULL), bits (NULL), m_vr (NULL)
917 /* Default destructor. */
918 ~ipcp_transformation ()
920 ipa_agg_replacement_value *agg = agg_values;
921 while (agg)
923 ipa_agg_replacement_value *next = agg->next;
924 ggc_free (agg);
925 agg = next;
927 vec_free (bits);
928 vec_free (m_vr);
932 void ipa_set_node_agg_value_chain (struct cgraph_node *node,
933 struct ipa_agg_replacement_value *aggvals);
934 void ipcp_transformation_initialize (void);
935 void ipcp_free_transformation_sum (void);
937 /* ipa_edge_args stores information related to a callsite and particularly its
938 arguments. It can be accessed by the IPA_EDGE_REF macro. */
940 class GTY((for_user)) ipa_edge_args
942 public:
944 /* Default constructor. */
945 ipa_edge_args () : jump_functions (NULL), polymorphic_call_contexts (NULL)
948 /* Destructor. */
949 ~ipa_edge_args ()
951 unsigned int i;
952 ipa_jump_func *jf;
953 FOR_EACH_VEC_SAFE_ELT (jump_functions, i, jf)
954 vec_free (jf->agg.items);
955 vec_free (jump_functions);
956 vec_free (polymorphic_call_contexts);
959 /* Vectors of the callsite's jump function and polymorphic context
960 information of each parameter. */
961 vec<ipa_jump_func, va_gc> *jump_functions;
962 vec<ipa_polymorphic_call_context, va_gc> *polymorphic_call_contexts;
965 /* ipa_edge_args access functions. Please use these to access fields that
966 are or will be shared among various passes. */
968 /* Return the number of actual arguments. */
970 static inline int
971 ipa_get_cs_argument_count (class ipa_edge_args *args)
973 return vec_safe_length (args->jump_functions);
976 /* Returns a pointer to the jump function for the ith argument. Please note
977 there is no setter function as jump functions are all set up in
978 ipa_compute_jump_functions. */
980 static inline struct ipa_jump_func *
981 ipa_get_ith_jump_func (class ipa_edge_args *args, int i)
983 return &(*args->jump_functions)[i];
986 /* Returns a pointer to the polymorphic call context for the ith argument.
987 NULL if contexts are not computed. */
988 static inline class ipa_polymorphic_call_context *
989 ipa_get_ith_polymorhic_call_context (class ipa_edge_args *args, int i)
991 if (!args->polymorphic_call_contexts)
992 return NULL;
993 return &(*args->polymorphic_call_contexts)[i];
996 /* Function summary for ipa_node_params. */
997 class GTY((user)) ipa_node_params_t: public function_summary <ipa_node_params *>
999 public:
1000 ipa_node_params_t (symbol_table *table, bool ggc):
1001 function_summary<ipa_node_params *> (table, ggc)
1003 disable_insertion_hook ();
1006 /* Hook that is called by summary when a node is duplicated. */
1007 void duplicate (cgraph_node *node,
1008 cgraph_node *node2,
1009 ipa_node_params *data,
1010 ipa_node_params *data2) final override;
1013 /* Summary to manange ipa_edge_args structures. */
1015 class GTY((user)) ipa_edge_args_sum_t : public call_summary <ipa_edge_args *>
1017 public:
1018 ipa_edge_args_sum_t (symbol_table *table, bool ggc)
1019 : call_summary<ipa_edge_args *> (table, ggc) { }
1021 void remove (cgraph_edge *edge)
1023 call_summary <ipa_edge_args *>::remove (edge);
1026 /* Hook that is called by summary when an edge is removed. */
1027 void remove (cgraph_edge *cs, ipa_edge_args *args) final override;
1028 /* Hook that is called by summary when an edge is duplicated. */
1029 void duplicate (cgraph_edge *src,
1030 cgraph_edge *dst,
1031 ipa_edge_args *old_args,
1032 ipa_edge_args *new_args) final override;
1035 /* Function summary where the parameter infos are actually stored. */
1036 extern GTY(()) ipa_node_params_t * ipa_node_params_sum;
1037 /* Call summary to store information about edges such as jump functions. */
1038 extern GTY(()) ipa_edge_args_sum_t *ipa_edge_args_sum;
1040 /* Function summary for IPA-CP transformation. */
1041 class ipcp_transformation_t
1042 : public function_summary<ipcp_transformation *>
1044 public:
1045 ipcp_transformation_t (symbol_table *table, bool ggc):
1046 function_summary<ipcp_transformation *> (table, ggc) {}
1048 ~ipcp_transformation_t () {}
1050 static ipcp_transformation_t *create_ggc (symbol_table *symtab)
1052 ipcp_transformation_t *summary
1053 = new (ggc_alloc_no_dtor <ipcp_transformation_t> ())
1054 ipcp_transformation_t (symtab, true);
1055 return summary;
1057 /* Hook that is called by summary when a node is duplicated. */
1058 void duplicate (cgraph_node *node,
1059 cgraph_node *node2,
1060 ipcp_transformation *data,
1061 ipcp_transformation *data2) final override;
1064 /* Function summary where the IPA CP transformations are actually stored. */
1065 extern GTY(()) function_summary <ipcp_transformation *> *ipcp_transformation_sum;
1067 /* Creating and freeing ipa_node_params and ipa_edge_args. */
1068 void ipa_create_all_node_params (void);
1069 void ipa_create_all_edge_args (void);
1070 void ipa_check_create_edge_args (void);
1071 void ipa_free_all_node_params (void);
1072 void ipa_free_all_edge_args (void);
1073 void ipa_free_all_structures_after_ipa_cp (void);
1074 void ipa_free_all_structures_after_iinln (void);
1076 void ipa_register_cgraph_hooks (void);
1077 int count_formal_params (tree fndecl);
1079 /* This function ensures the array of node param infos is big enough to
1080 accommodate a structure for all nodes and reallocates it if not. */
1082 static inline void
1083 ipa_check_create_node_params (void)
1085 if (!ipa_node_params_sum)
1086 ipa_node_params_sum
1087 = (new (ggc_alloc_no_dtor <ipa_node_params_t> ())
1088 ipa_node_params_t (symtab, true));
1091 /* Returns true if edge summary contains a record for EDGE. The main purpose
1092 of this function is that debug dumping function can check info availability
1093 without causing allocations. */
1095 static inline bool
1096 ipa_edge_args_info_available_for_edge_p (struct cgraph_edge *edge)
1098 return ipa_edge_args_sum->exists (edge);
1101 static inline ipcp_transformation *
1102 ipcp_get_transformation_summary (cgraph_node *node)
1104 if (ipcp_transformation_sum == NULL)
1105 return NULL;
1107 return ipcp_transformation_sum->get (node);
1110 /* Return the aggregate replacements for NODE, if there are any. */
1112 static inline struct ipa_agg_replacement_value *
1113 ipa_get_agg_replacements_for_node (cgraph_node *node)
1115 ipcp_transformation *ts = ipcp_get_transformation_summary (node);
1116 return ts ? ts->agg_values : NULL;
1119 /* Function formal parameters related computations. */
1120 void ipa_initialize_node_params (struct cgraph_node *node);
1121 bool ipa_propagate_indirect_call_infos (struct cgraph_edge *cs,
1122 vec<cgraph_edge *> *new_edges);
1124 /* Indirect edge processing and target discovery. */
1125 tree ipa_get_indirect_edge_target (struct cgraph_edge *ie,
1126 ipa_call_arg_values *avals,
1127 bool *speculative);
1128 tree ipa_get_indirect_edge_target (struct cgraph_edge *ie,
1129 ipa_auto_call_arg_values *avals,
1130 bool *speculative);
1131 struct cgraph_edge *ipa_make_edge_direct_to_target (struct cgraph_edge *, tree,
1132 bool speculative = false);
1133 tree ipa_impossible_devirt_target (struct cgraph_edge *, tree);
1134 ipa_bits *ipa_get_ipa_bits_for_value (const widest_int &value,
1135 const widest_int &mask);
1138 /* Functions related to both. */
1139 void ipa_analyze_node (struct cgraph_node *);
1141 /* Aggregate jump function related functions. */
1142 tree ipa_find_agg_cst_for_param (const ipa_agg_value_set *agg, tree scalar,
1143 HOST_WIDE_INT offset, bool by_ref,
1144 bool *from_global_constant = NULL);
1145 bool ipa_load_from_parm_agg (struct ipa_func_body_info *fbi,
1146 vec<ipa_param_descriptor, va_gc> *descriptors,
1147 gimple *stmt, tree op, int *index_p,
1148 HOST_WIDE_INT *offset_p, poly_int64 *size_p,
1149 bool *by_ref, bool *guaranteed_unmodified = NULL);
1151 /* Debugging interface. */
1152 void ipa_print_node_params (FILE *, struct cgraph_node *node);
1153 void ipa_print_all_params (FILE *);
1154 void ipa_print_node_jump_functions (FILE *f, struct cgraph_node *node);
1155 void ipa_print_all_jump_functions (FILE * f);
1156 void ipcp_verify_propagated_values (void);
1158 template <typename value>
1159 class ipcp_value;
1161 extern object_allocator<ipcp_value<tree> > ipcp_cst_values_pool;
1162 extern object_allocator<ipcp_value<ipa_polymorphic_call_context> >
1163 ipcp_poly_ctx_values_pool;
1165 template <typename valtype>
1166 struct ipcp_value_source;
1168 extern object_allocator<ipcp_value_source<tree> > ipcp_sources_pool;
1170 struct ipcp_agg_lattice;
1172 extern object_allocator<ipcp_agg_lattice> ipcp_agg_lattice_pool;
1174 void ipa_dump_agg_replacement_values (FILE *f,
1175 struct ipa_agg_replacement_value *av);
1176 void ipa_prop_write_jump_functions (void);
1177 void ipa_prop_read_jump_functions (void);
1178 void ipcp_write_transformation_summaries (void);
1179 void ipcp_read_transformation_summaries (void);
1180 int ipa_get_param_decl_index (class ipa_node_params *, tree);
1181 tree ipa_value_from_jfunc (class ipa_node_params *info,
1182 struct ipa_jump_func *jfunc, tree type);
1183 unsigned int ipcp_transform_function (struct cgraph_node *node);
1184 ipa_polymorphic_call_context ipa_context_from_jfunc (ipa_node_params *,
1185 cgraph_edge *,
1186 int,
1187 ipa_jump_func *);
1188 value_range ipa_value_range_from_jfunc (ipa_node_params *, cgraph_edge *,
1189 ipa_jump_func *, tree);
1190 ipa_agg_value_set ipa_agg_value_set_from_jfunc (ipa_node_params *,
1191 cgraph_node *,
1192 ipa_agg_jump_function *);
1193 void ipa_dump_param (FILE *, class ipa_node_params *info, int i);
1194 void ipa_release_body_info (struct ipa_func_body_info *);
1195 tree ipa_get_callee_param_type (struct cgraph_edge *e, int i);
1196 bool ipcp_get_parm_bits (tree, tree *, widest_int *);
1197 bool unadjusted_ptr_and_unit_offset (tree op, tree *ret,
1198 poly_int64 *offset_ret);
1200 /* From tree-sra.cc: */
1201 tree build_ref_for_offset (location_t, tree, poly_int64, bool, tree,
1202 gimple_stmt_iterator *, bool);
1204 /* In ipa-cp.cc */
1205 void ipa_cp_cc_finalize (void);
1207 #endif /* IPA_PROP_H */