[Ada] Fix deleted Compile_Time warnings causing crashes
[official-gcc.git] / gcc / ipa-prop.h
blob42842d9466a3c26dff80d1fd00d910601c2cea6e
1 /* Interprocedural analyses.
2 Copyright (C) 2005-2021 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.c 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.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. */
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;
148 /* A jump function for an aggregate part at a given offset, which describes how
149 it content value is generated. All unlisted positions are assumed to have a
150 value defined in an unknown way. */
152 struct GTY(()) ipa_agg_jf_item
154 /* The offset for the aggregate part. */
155 HOST_WIDE_INT offset;
157 /* Data type of the aggregate part. */
158 tree type;
160 /* Jump function type. */
161 enum jump_func_type jftype;
163 /* Represents a value of jump function. constant represents the actual constant
164 in constant jump function content. pass_through is used only in simple pass
165 through jump function context. load_agg is for load-value-from-aggregate
166 jump function context. */
167 union jump_func_agg_value
169 tree GTY ((tag ("IPA_JF_CONST"))) constant;
170 struct ipa_pass_through_data GTY ((tag ("IPA_JF_PASS_THROUGH"))) pass_through;
171 struct ipa_load_agg_data GTY ((tag ("IPA_JF_LOAD_AGG"))) load_agg;
172 } GTY ((desc ("%1.jftype"))) value;
175 /* Jump functions describing a set of aggregate contents. */
177 struct GTY(()) ipa_agg_jump_function
179 /* Description of the individual jump function item. */
180 vec<ipa_agg_jf_item, va_gc> *items;
181 /* True if the data was passed by reference (as opposed to by value). */
182 bool by_ref;
185 /* An element in an aggregate part describing a known value at a given offset.
186 All unlisted positions are assumed to be unknown and all listed values must
187 fulfill is_gimple_ip_invariant. */
189 struct ipa_agg_value
191 /* The offset at which the known value is located within the aggregate. */
192 HOST_WIDE_INT offset;
194 /* The known constant. */
195 tree value;
197 /* Return true if OTHER describes same agg value. */
198 bool equal_to (const ipa_agg_value &other);
201 /* Structure describing a set of known offset/value for aggregate. */
203 struct ipa_agg_value_set
205 /* Description of the individual item. */
206 vec<ipa_agg_value> items;
207 /* True if the data was passed by reference (as opposed to by value). */
208 bool by_ref;
210 /* Return true if OTHER describes same agg values. */
211 bool equal_to (const ipa_agg_value_set &other)
213 if (by_ref != other.by_ref)
214 return false;
215 if (items.length () != other.items.length ())
216 return false;
217 for (unsigned int i = 0; i < items.length (); i++)
218 if (!items[i].equal_to (other.items[i]))
219 return false;
220 return true;
223 /* Return true if there is any value for aggregate. */
224 bool is_empty () const
226 return items.is_empty ();
229 ipa_agg_value_set copy () const
231 ipa_agg_value_set new_copy;
233 new_copy.items = items.copy ();
234 new_copy.by_ref = by_ref;
236 return new_copy;
239 void release ()
241 items.release ();
245 /* Return copy of a vec<ipa_agg_value_set>. */
247 static inline vec<ipa_agg_value_set>
248 ipa_copy_agg_values (const vec<ipa_agg_value_set> &aggs)
250 vec<ipa_agg_value_set> aggs_copy = vNULL;
252 if (!aggs.is_empty ())
254 ipa_agg_value_set *agg;
255 int i;
257 aggs_copy.reserve_exact (aggs.length ());
259 FOR_EACH_VEC_ELT (aggs, i, agg)
260 aggs_copy.quick_push (agg->copy ());
263 return aggs_copy;
266 /* For vec<ipa_agg_value_set>, DO NOT call release(), use below function
267 instead. Because ipa_agg_value_set contains a field of vector type, we
268 should release this child vector in each element before reclaiming the
269 whole vector. */
271 static inline void
272 ipa_release_agg_values (vec<ipa_agg_value_set> &aggs,
273 bool release_vector = true)
275 ipa_agg_value_set *agg;
276 int i;
278 FOR_EACH_VEC_ELT (aggs, i, agg)
279 agg->release ();
280 if (release_vector)
281 aggs.release ();
284 /* Information about zero/non-zero bits. */
285 class GTY(()) ipa_bits
287 public:
288 /* The propagated value. */
289 widest_int value;
290 /* Mask corresponding to the value.
291 Similar to ccp_lattice_t, if xth bit of mask is 0,
292 implies xth bit of value is constant. */
293 widest_int mask;
296 /* Info about value ranges. */
298 class GTY(()) ipa_vr
300 public:
301 /* The data fields below are valid only if known is true. */
302 bool known;
303 enum value_range_kind type;
304 wide_int min;
305 wide_int max;
306 bool nonzero_p (tree) const;
309 /* A jump function for a callsite represents the values passed as actual
310 arguments of the callsite. See enum jump_func_type for the various
311 types of jump functions supported. */
312 struct GTY (()) ipa_jump_func
314 /* Aggregate jump function description. See struct ipa_agg_jump_function
315 and its description. */
316 struct ipa_agg_jump_function agg;
318 /* Information about zero/non-zero bits. The pointed to structure is shared
319 betweed different jump functions. Use ipa_set_jfunc_bits to set this
320 field. */
321 class ipa_bits *bits;
323 /* Information about value range, containing valid data only when vr_known is
324 true. The pointed to structure is shared betweed different jump
325 functions. Use ipa_set_jfunc_vr to set this field. */
326 value_range *m_vr;
328 enum jump_func_type type;
329 /* Represents a value of a jump function. pass_through is used only in jump
330 function context. constant represents the actual constant in constant jump
331 functions and member_cst holds constant c++ member functions. */
332 union jump_func_value
334 struct ipa_constant_data GTY ((tag ("IPA_JF_CONST"))) constant;
335 struct ipa_pass_through_data GTY ((tag ("IPA_JF_PASS_THROUGH"))) pass_through;
336 struct ipa_ancestor_jf_data GTY ((tag ("IPA_JF_ANCESTOR"))) ancestor;
337 } GTY ((desc ("%1.type"))) value;
341 /* Return the constant stored in a constant jump functin JFUNC. */
343 static inline tree
344 ipa_get_jf_constant (struct ipa_jump_func *jfunc)
346 gcc_checking_assert (jfunc->type == IPA_JF_CONST);
347 return jfunc->value.constant.value;
350 static inline struct ipa_cst_ref_desc *
351 ipa_get_jf_constant_rdesc (struct ipa_jump_func *jfunc)
353 gcc_checking_assert (jfunc->type == IPA_JF_CONST);
354 return jfunc->value.constant.rdesc;
357 /* Return the operand of a pass through jmp function JFUNC. */
359 static inline tree
360 ipa_get_jf_pass_through_operand (struct ipa_jump_func *jfunc)
362 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
363 return jfunc->value.pass_through.operand;
366 /* Return the number of the caller's formal parameter that a pass through jump
367 function JFUNC refers to. */
369 static inline int
370 ipa_get_jf_pass_through_formal_id (struct ipa_jump_func *jfunc)
372 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
373 return jfunc->value.pass_through.formal_id;
376 /* Return operation of a pass through jump function JFUNC. */
378 static inline enum tree_code
379 ipa_get_jf_pass_through_operation (struct ipa_jump_func *jfunc)
381 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
382 return jfunc->value.pass_through.operation;
385 /* Return the agg_preserved flag of a pass through jump function JFUNC. */
387 static inline bool
388 ipa_get_jf_pass_through_agg_preserved (struct ipa_jump_func *jfunc)
390 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
391 return jfunc->value.pass_through.agg_preserved;
394 /* Return true if pass through jump function JFUNC preserves type
395 information. */
397 static inline bool
398 ipa_get_jf_pass_through_type_preserved (struct ipa_jump_func *jfunc)
400 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
401 return jfunc->value.pass_through.agg_preserved;
404 /* Return the offset of an ancestor jump function JFUNC. */
406 static inline HOST_WIDE_INT
407 ipa_get_jf_ancestor_offset (struct ipa_jump_func *jfunc)
409 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
410 return jfunc->value.ancestor.offset;
413 /* Return the number of the caller's formal parameter that an ancestor jump
414 function JFUNC refers to. */
416 static inline int
417 ipa_get_jf_ancestor_formal_id (struct ipa_jump_func *jfunc)
419 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
420 return jfunc->value.ancestor.formal_id;
423 /* Return the agg_preserved flag of an ancestor jump function JFUNC. */
425 static inline bool
426 ipa_get_jf_ancestor_agg_preserved (struct ipa_jump_func *jfunc)
428 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
429 return jfunc->value.ancestor.agg_preserved;
432 /* Return true if ancestor jump function JFUNC presrves type information. */
434 static inline bool
435 ipa_get_jf_ancestor_type_preserved (struct ipa_jump_func *jfunc)
437 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
438 return jfunc->value.ancestor.agg_preserved;
441 /* Class for allocating a bundle of various potentially known properties about
442 actual arguments of a particular call on stack for the usual case and on
443 heap only if there are unusually many arguments. The data is deallocated
444 when the instance of this class goes out of scope or is otherwise
445 destructed. */
447 class ipa_auto_call_arg_values
449 public:
450 ~ipa_auto_call_arg_values ();
452 /* If m_known_vals (vector of known "scalar" values) is sufficiantly long,
453 return its element at INDEX, otherwise return NULL. */
454 tree safe_sval_at (int index)
456 /* TODO: Assert non-negative index here and test. */
457 if ((unsigned) index < m_known_vals.length ())
458 return m_known_vals[index];
459 return NULL;
462 /* If m_known_aggs is sufficiantly long, return the pointer rto its element
463 at INDEX, otherwise return NULL. */
464 ipa_agg_value_set *safe_aggval_at (int index)
466 /* TODO: Assert non-negative index here and test. */
467 if ((unsigned) index < m_known_aggs.length ())
468 return &m_known_aggs[index];
469 return NULL;
472 /* Vector describing known values of parameters. */
473 auto_vec<tree, 32> m_known_vals;
475 /* Vector describing known polymorphic call contexts. */
476 auto_vec<ipa_polymorphic_call_context, 32> m_known_contexts;
478 /* Vector describing known aggregate values. */
479 auto_vec<ipa_agg_value_set, 32> m_known_aggs;
481 /* Vector describing known value ranges of arguments. */
482 auto_vec<value_range, 32> m_known_value_ranges;
485 /* Class bundling the various potentially known properties about actual
486 arguments of a particular call. This variant does not deallocate the
487 bundled data in any way. */
489 class ipa_call_arg_values
491 public:
492 /* Default constructor, setting the vectors to empty ones. */
493 ipa_call_arg_values ()
496 /* Construct this general variant of the bundle from the variant which uses
497 auto_vecs to hold the vectors. This means that vectors of objects
498 constructed with this constructor should not be changed because if they
499 get reallocated, the member vectors and the underlying auto_vecs would get
500 out of sync. */
501 ipa_call_arg_values (ipa_auto_call_arg_values *aavals)
502 : m_known_vals (aavals->m_known_vals.to_vec_legacy ()),
503 m_known_contexts (aavals->m_known_contexts.to_vec_legacy ()),
504 m_known_aggs (aavals->m_known_aggs.to_vec_legacy ()),
505 m_known_value_ranges (aavals->m_known_value_ranges.to_vec_legacy ())
508 /* If m_known_vals (vector of known "scalar" values) is sufficiantly long,
509 return its element at INDEX, otherwise return NULL. */
510 tree safe_sval_at (int index)
512 /* TODO: Assert non-negative index here and test. */
513 if ((unsigned) index < m_known_vals.length ())
514 return m_known_vals[index];
515 return NULL;
518 /* If m_known_aggs is sufficiantly long, return the pointer rto its element
519 at INDEX, otherwise return NULL. */
520 ipa_agg_value_set *safe_aggval_at (int index)
522 /* TODO: Assert non-negative index here and test. */
523 if ((unsigned) index < m_known_aggs.length ())
524 return &m_known_aggs[index];
525 return NULL;
528 /* Vector describing known values of parameters. */
529 vec<tree> m_known_vals = vNULL;
531 /* Vector describing known polymorphic call contexts. */
532 vec<ipa_polymorphic_call_context> m_known_contexts = vNULL;
534 /* Vector describing known aggregate values. */
535 vec<ipa_agg_value_set> m_known_aggs = vNULL;
537 /* Vector describing known value ranges of arguments. */
538 vec<value_range> m_known_value_ranges = vNULL;
542 /* Summary describing a single formal parameter. */
544 struct GTY(()) ipa_param_descriptor
546 /* In analysis and modification phase, this is the PARAM_DECL of this
547 parameter, in IPA LTO phase, this is the type of the described
548 parameter or NULL if not known. Do not read this field directly but
549 through ipa_get_param and ipa_get_type as appropriate. */
550 tree decl_or_type;
551 /* If all uses of the parameter are described by ipa-prop structures, this
552 says how many there are. If any use could not be described by means of
553 ipa-prop structures (which include flag dereferenced below), this is
554 IPA_UNDESCRIBED_USE. */
555 int controlled_uses;
556 unsigned int move_cost : 27;
557 /* The parameter is used. */
558 unsigned used : 1;
559 unsigned used_by_ipa_predicates : 1;
560 unsigned used_by_indirect_call : 1;
561 unsigned used_by_polymorphic_call : 1;
562 /* Set to true when in addition to being used in call statements, the
563 parameter has also been used for loads (but not for writes, does not
564 escape, etc.). This allows us to identify parameters p which are only
565 used as *p, and so when we propagate a constant to them, we can generate a
566 LOAD and not ADDR reference to them. */
567 unsigned load_dereferenced : 1;
570 /* ipa_node_params stores information related to formal parameters of functions
571 and some other information for interprocedural passes that operate on
572 parameters (such as ipa-cp). */
574 class GTY((for_user)) ipa_node_params
576 public:
577 /* Default constructor. */
578 ipa_node_params ();
580 /* Default destructor. */
581 ~ipa_node_params ();
583 /* Information about individual formal parameters that are gathered when
584 summaries are generated. */
585 vec<ipa_param_descriptor, va_gc> *descriptors;
586 /* Pointer to an array of structures describing individual formal
587 parameters. */
588 class ipcp_param_lattices * GTY((skip)) lattices;
589 /* Only for versioned nodes this field would not be NULL,
590 it points to the node that IPA cp cloned from. */
591 struct cgraph_node * GTY((skip)) ipcp_orig_node;
592 /* If this node is an ipa-cp clone, these are the known constants that
593 describe what it has been specialized for. */
594 vec<tree> GTY((skip)) known_csts;
595 /* If this node is an ipa-cp clone, these are the known polymorphic contexts
596 that describe what it has been specialized for. */
597 vec<ipa_polymorphic_call_context> GTY((skip)) known_contexts;
598 /* Whether the param uses analysis and jump function computation has already
599 been performed. */
600 unsigned analysis_done : 1;
601 /* Whether the function is enqueued in ipa-cp propagation stack. */
602 unsigned node_enqueued : 1;
603 /* Whether we should create a specialized version based on values that are
604 known to be constant in all contexts. */
605 unsigned do_clone_for_all_contexts : 1;
606 /* Set if this is an IPA-CP clone for all contexts. */
607 unsigned is_all_contexts_clone : 1;
608 /* Node has been completely replaced by clones and will be removed after
609 ipa-cp is finished. */
610 unsigned node_dead : 1;
611 /* Node is involved in a recursion, potentionally indirect. */
612 unsigned node_within_scc : 1;
613 /* Node contains only direct recursion. */
614 unsigned node_is_self_scc : 1;
615 /* Node is calling a private function called only once. */
616 unsigned node_calling_single_call : 1;
617 /* False when there is something makes versioning impossible. */
618 unsigned versionable : 1;
621 inline
622 ipa_node_params::ipa_node_params ()
623 : descriptors (NULL), lattices (NULL), ipcp_orig_node (NULL),
624 known_csts (vNULL), known_contexts (vNULL), analysis_done (0),
625 node_enqueued (0), do_clone_for_all_contexts (0), is_all_contexts_clone (0),
626 node_dead (0), node_within_scc (0), node_calling_single_call (0),
627 versionable (0)
631 inline
632 ipa_node_params::~ipa_node_params ()
634 free (lattices);
635 vec_free (descriptors);
636 known_csts.release ();
637 known_contexts.release ();
640 /* Intermediate information that we get from alias analysis about a particular
641 parameter in a particular basic_block. When a parameter or the memory it
642 references is marked modified, we use that information in all dominated
643 blocks without consulting alias analysis oracle. */
645 struct ipa_param_aa_status
647 /* Set when this structure contains meaningful information. If not, the
648 structure describing a dominating BB should be used instead. */
649 bool valid;
651 /* Whether we have seen something which might have modified the data in
652 question. PARM is for the parameter itself, REF is for data it points to
653 but using the alias type of individual accesses and PT is the same thing
654 but for computing aggregate pass-through functions using a very inclusive
655 ao_ref. */
656 bool parm_modified, ref_modified, pt_modified;
659 /* Information related to a given BB that used only when looking at function
660 body. */
662 struct ipa_bb_info
664 /* Call graph edges going out of this BB. */
665 vec<cgraph_edge *> cg_edges;
666 /* Alias analysis statuses of each formal parameter at this bb. */
667 vec<ipa_param_aa_status> param_aa_statuses;
670 /* Structure with global information that is only used when looking at function
671 body. */
673 struct ipa_func_body_info
675 /* The node that is being analyzed. */
676 cgraph_node *node;
678 /* Its info. */
679 class ipa_node_params *info;
681 /* Information about individual BBs. */
682 vec<ipa_bb_info> bb_infos;
684 /* Number of parameters. */
685 int param_count;
687 /* Number of statements we are still allowed to walked by when analyzing this
688 function. */
689 unsigned int aa_walk_budget;
692 /* ipa_node_params access functions. Please use these to access fields that
693 are or will be shared among various passes. */
695 /* Return the number of formal parameters. */
697 static inline int
698 ipa_get_param_count (class ipa_node_params *info)
700 return vec_safe_length (info->descriptors);
703 /* Return the declaration of Ith formal parameter of the function corresponding
704 to INFO. Note there is no setter function as this array is built just once
705 using ipa_initialize_node_params. This function should not be called in
706 WPA. */
708 static inline tree
709 ipa_get_param (class ipa_node_params *info, int i)
711 gcc_checking_assert (info->descriptors);
712 tree t = (*info->descriptors)[i].decl_or_type;
713 gcc_checking_assert (TREE_CODE (t) == PARM_DECL);
714 return t;
717 /* Return the type of Ith formal parameter of the function corresponding
718 to INFO if it is known or NULL if not. */
720 static inline tree
721 ipa_get_type (class ipa_node_params *info, int i)
723 if (vec_safe_length (info->descriptors) <= (unsigned) i)
724 return NULL;
725 tree t = (*info->descriptors)[i].decl_or_type;
726 if (!t)
727 return NULL;
728 if (TYPE_P (t))
729 return t;
730 gcc_checking_assert (TREE_CODE (t) == PARM_DECL);
731 return TREE_TYPE (t);
734 /* Return the move cost of Ith formal parameter of the function corresponding
735 to INFO. */
737 static inline int
738 ipa_get_param_move_cost (class ipa_node_params *info, int i)
740 gcc_checking_assert (info->descriptors);
741 return (*info->descriptors)[i].move_cost;
744 /* Set the used flag corresponding to the Ith formal parameter of the function
745 associated with INFO to VAL. */
747 static inline void
748 ipa_set_param_used (class ipa_node_params *info, int i, bool val)
750 gcc_checking_assert (info->descriptors);
751 (*info->descriptors)[i].used = val;
754 /* Set the used_by_ipa_predicates flag corresponding to the Ith formal
755 parameter of the function associated with INFO to VAL. */
757 static inline void
758 ipa_set_param_used_by_ipa_predicates (class ipa_node_params *info, int i, bool val)
760 gcc_checking_assert (info->descriptors);
761 (*info->descriptors)[i].used_by_ipa_predicates = val;
764 /* Set the used_by_indirect_call flag corresponding to the Ith formal
765 parameter of the function associated with INFO to VAL. */
767 static inline void
768 ipa_set_param_used_by_indirect_call (class ipa_node_params *info, int i, bool val)
770 gcc_checking_assert (info->descriptors);
771 (*info->descriptors)[i].used_by_indirect_call = val;
774 /* Set the .used_by_polymorphic_call flag corresponding to the Ith formal
775 parameter of the function associated with INFO to VAL. */
777 static inline void
778 ipa_set_param_used_by_polymorphic_call (class ipa_node_params *info, int i, bool val)
780 gcc_checking_assert (info->descriptors);
781 (*info->descriptors)[i].used_by_polymorphic_call = val;
784 /* Return how many uses described by ipa-prop a parameter has or
785 IPA_UNDESCRIBED_USE if there is a use that is not described by these
786 structures. */
787 static inline int
788 ipa_get_controlled_uses (class ipa_node_params *info, int i)
790 /* FIXME: introducing speculation causes out of bounds access here. */
791 if (vec_safe_length (info->descriptors) > (unsigned)i)
792 return (*info->descriptors)[i].controlled_uses;
793 return IPA_UNDESCRIBED_USE;
796 /* Set the controlled counter of a given parameter. */
798 static inline void
799 ipa_set_controlled_uses (class ipa_node_params *info, int i, int val)
801 gcc_checking_assert (info->descriptors);
802 (*info->descriptors)[i].controlled_uses = val;
805 /* Assuming a parameter does not have IPA_UNDESCRIBED_USE controlled uses,
806 return flag which indicates it has been dereferenced but only in a load. */
807 static inline int
808 ipa_get_param_load_dereferenced (class ipa_node_params *info, int i)
810 gcc_assert (ipa_get_controlled_uses (info, i) != IPA_UNDESCRIBED_USE);
811 return (*info->descriptors)[i].load_dereferenced;
814 /* Set the load_dereferenced flag of a given parameter. */
816 static inline void
817 ipa_set_param_load_dereferenced (class ipa_node_params *info, int i, bool val)
819 gcc_checking_assert (info->descriptors);
820 (*info->descriptors)[i].load_dereferenced = val;
823 /* Return the used flag corresponding to the Ith formal parameter of the
824 function associated with INFO. */
826 static inline bool
827 ipa_is_param_used (class ipa_node_params *info, int i)
829 gcc_checking_assert (info->descriptors);
830 return (*info->descriptors)[i].used;
833 /* Return the used_by_ipa_predicates flag corresponding to the Ith formal
834 parameter of the function associated with INFO. */
836 static inline bool
837 ipa_is_param_used_by_ipa_predicates (class ipa_node_params *info, int i)
839 gcc_checking_assert (info->descriptors);
840 return (*info->descriptors)[i].used_by_ipa_predicates;
843 /* Return the used_by_indirect_call flag corresponding to the Ith formal
844 parameter of the function associated with INFO. */
846 static inline bool
847 ipa_is_param_used_by_indirect_call (class ipa_node_params *info, int i)
849 gcc_checking_assert (info->descriptors);
850 return (*info->descriptors)[i].used_by_indirect_call;
853 /* Return the used_by_polymorphic_call flag corresponding to the Ith formal
854 parameter of the function associated with INFO. */
856 static inline bool
857 ipa_is_param_used_by_polymorphic_call (class ipa_node_params *info, int i)
859 gcc_checking_assert (info->descriptors);
860 return (*info->descriptors)[i].used_by_polymorphic_call;
863 /* Information about replacements done in aggregates for a given node (each
864 node has its linked list). */
865 struct GTY(()) ipa_agg_replacement_value
867 /* Next item in the linked list. */
868 struct ipa_agg_replacement_value *next;
869 /* Offset within the aggregate. */
870 HOST_WIDE_INT offset;
871 /* The constant value. */
872 tree value;
873 /* The parameter index. */
874 int index;
875 /* Whether the value was passed by reference. */
876 bool by_ref;
879 /* Structure holding information for the transformation phase of IPA-CP. */
881 struct GTY(()) ipcp_transformation
883 /* Linked list of known aggregate values. */
884 ipa_agg_replacement_value *agg_values;
885 /* Known bits information. */
886 vec<ipa_bits *, va_gc> *bits;
887 /* Value range information. */
888 vec<ipa_vr, va_gc> *m_vr;
890 /* Default constructor. */
891 ipcp_transformation ()
892 : agg_values (NULL), bits (NULL), m_vr (NULL)
895 /* Default destructor. */
896 ~ipcp_transformation ()
898 ipa_agg_replacement_value *agg = agg_values;
899 while (agg)
901 ipa_agg_replacement_value *next = agg->next;
902 ggc_free (agg);
903 agg = next;
905 vec_free (bits);
906 vec_free (m_vr);
910 void ipa_set_node_agg_value_chain (struct cgraph_node *node,
911 struct ipa_agg_replacement_value *aggvals);
912 void ipcp_transformation_initialize (void);
913 void ipcp_free_transformation_sum (void);
915 /* ipa_edge_args stores information related to a callsite and particularly its
916 arguments. It can be accessed by the IPA_EDGE_REF macro. */
918 class GTY((for_user)) ipa_edge_args
920 public:
922 /* Default constructor. */
923 ipa_edge_args () : jump_functions (NULL), polymorphic_call_contexts (NULL)
926 /* Destructor. */
927 ~ipa_edge_args ()
929 unsigned int i;
930 ipa_jump_func *jf;
931 FOR_EACH_VEC_SAFE_ELT (jump_functions, i, jf)
932 vec_free (jf->agg.items);
933 vec_free (jump_functions);
934 vec_free (polymorphic_call_contexts);
937 /* Vectors of the callsite's jump function and polymorphic context
938 information of each parameter. */
939 vec<ipa_jump_func, va_gc> *jump_functions;
940 vec<ipa_polymorphic_call_context, va_gc> *polymorphic_call_contexts;
943 /* ipa_edge_args access functions. Please use these to access fields that
944 are or will be shared among various passes. */
946 /* Return the number of actual arguments. */
948 static inline int
949 ipa_get_cs_argument_count (class ipa_edge_args *args)
951 return vec_safe_length (args->jump_functions);
954 /* Returns a pointer to the jump function for the ith argument. Please note
955 there is no setter function as jump functions are all set up in
956 ipa_compute_jump_functions. */
958 static inline struct ipa_jump_func *
959 ipa_get_ith_jump_func (class ipa_edge_args *args, int i)
961 return &(*args->jump_functions)[i];
964 /* Returns a pointer to the polymorphic call context for the ith argument.
965 NULL if contexts are not computed. */
966 static inline class ipa_polymorphic_call_context *
967 ipa_get_ith_polymorhic_call_context (class ipa_edge_args *args, int i)
969 if (!args->polymorphic_call_contexts)
970 return NULL;
971 return &(*args->polymorphic_call_contexts)[i];
974 /* Function summary for ipa_node_params. */
975 class GTY((user)) ipa_node_params_t: public function_summary <ipa_node_params *>
977 public:
978 ipa_node_params_t (symbol_table *table, bool ggc):
979 function_summary<ipa_node_params *> (table, ggc)
981 disable_insertion_hook ();
984 /* Hook that is called by summary when a node is duplicated. */
985 virtual void duplicate (cgraph_node *node,
986 cgraph_node *node2,
987 ipa_node_params *data,
988 ipa_node_params *data2);
991 /* Summary to manange ipa_edge_args structures. */
993 class GTY((user)) ipa_edge_args_sum_t : public call_summary <ipa_edge_args *>
995 public:
996 ipa_edge_args_sum_t (symbol_table *table, bool ggc)
997 : call_summary<ipa_edge_args *> (table, ggc) { }
999 void remove (cgraph_edge *edge)
1001 call_summary <ipa_edge_args *>::remove (edge);
1004 /* Hook that is called by summary when an edge is removed. */
1005 virtual void remove (cgraph_edge *cs, ipa_edge_args *args);
1006 /* Hook that is called by summary when an edge is duplicated. */
1007 virtual void duplicate (cgraph_edge *src,
1008 cgraph_edge *dst,
1009 ipa_edge_args *old_args,
1010 ipa_edge_args *new_args);
1013 /* Function summary where the parameter infos are actually stored. */
1014 extern GTY(()) ipa_node_params_t * ipa_node_params_sum;
1015 /* Call summary to store information about edges such as jump functions. */
1016 extern GTY(()) ipa_edge_args_sum_t *ipa_edge_args_sum;
1018 /* Function summary for IPA-CP transformation. */
1019 class ipcp_transformation_t
1020 : public function_summary<ipcp_transformation *>
1022 public:
1023 ipcp_transformation_t (symbol_table *table, bool ggc):
1024 function_summary<ipcp_transformation *> (table, ggc) {}
1026 ~ipcp_transformation_t () {}
1028 static ipcp_transformation_t *create_ggc (symbol_table *symtab)
1030 ipcp_transformation_t *summary
1031 = new (ggc_alloc_no_dtor <ipcp_transformation_t> ())
1032 ipcp_transformation_t (symtab, true);
1033 return summary;
1035 /* Hook that is called by summary when a node is duplicated. */
1036 virtual void duplicate (cgraph_node *node,
1037 cgraph_node *node2,
1038 ipcp_transformation *data,
1039 ipcp_transformation *data2);
1042 /* Function summary where the IPA CP transformations are actually stored. */
1043 extern GTY(()) function_summary <ipcp_transformation *> *ipcp_transformation_sum;
1045 /* Creating and freeing ipa_node_params and ipa_edge_args. */
1046 void ipa_create_all_node_params (void);
1047 void ipa_create_all_edge_args (void);
1048 void ipa_check_create_edge_args (void);
1049 void ipa_free_all_node_params (void);
1050 void ipa_free_all_edge_args (void);
1051 void ipa_free_all_structures_after_ipa_cp (void);
1052 void ipa_free_all_structures_after_iinln (void);
1054 void ipa_register_cgraph_hooks (void);
1055 int count_formal_params (tree fndecl);
1057 /* This function ensures the array of node param infos is big enough to
1058 accommodate a structure for all nodes and reallocates it if not. */
1060 static inline void
1061 ipa_check_create_node_params (void)
1063 if (!ipa_node_params_sum)
1064 ipa_node_params_sum
1065 = (new (ggc_alloc_no_dtor <ipa_node_params_t> ())
1066 ipa_node_params_t (symtab, true));
1069 /* Returns true if edge summary contains a record for EDGE. The main purpose
1070 of this function is that debug dumping function can check info availability
1071 without causing allocations. */
1073 static inline bool
1074 ipa_edge_args_info_available_for_edge_p (struct cgraph_edge *edge)
1076 return ipa_edge_args_sum->exists (edge);
1079 static inline ipcp_transformation *
1080 ipcp_get_transformation_summary (cgraph_node *node)
1082 if (ipcp_transformation_sum == NULL)
1083 return NULL;
1085 return ipcp_transformation_sum->get (node);
1088 /* Return the aggregate replacements for NODE, if there are any. */
1090 static inline struct ipa_agg_replacement_value *
1091 ipa_get_agg_replacements_for_node (cgraph_node *node)
1093 ipcp_transformation *ts = ipcp_get_transformation_summary (node);
1094 return ts ? ts->agg_values : NULL;
1097 /* Function formal parameters related computations. */
1098 void ipa_initialize_node_params (struct cgraph_node *node);
1099 bool ipa_propagate_indirect_call_infos (struct cgraph_edge *cs,
1100 vec<cgraph_edge *> *new_edges);
1102 /* Indirect edge processing and target discovery. */
1103 tree ipa_get_indirect_edge_target (struct cgraph_edge *ie,
1104 ipa_call_arg_values *avals,
1105 bool *speculative);
1106 tree ipa_get_indirect_edge_target (struct cgraph_edge *ie,
1107 ipa_auto_call_arg_values *avals,
1108 bool *speculative);
1109 struct cgraph_edge *ipa_make_edge_direct_to_target (struct cgraph_edge *, tree,
1110 bool speculative = false);
1111 tree ipa_impossible_devirt_target (struct cgraph_edge *, tree);
1112 ipa_bits *ipa_get_ipa_bits_for_value (const widest_int &value,
1113 const widest_int &mask);
1116 /* Functions related to both. */
1117 void ipa_analyze_node (struct cgraph_node *);
1119 /* Aggregate jump function related functions. */
1120 tree ipa_find_agg_cst_for_param (const ipa_agg_value_set *agg, tree scalar,
1121 HOST_WIDE_INT offset, bool by_ref,
1122 bool *from_global_constant = NULL);
1123 bool ipa_load_from_parm_agg (struct ipa_func_body_info *fbi,
1124 vec<ipa_param_descriptor, va_gc> *descriptors,
1125 gimple *stmt, tree op, int *index_p,
1126 HOST_WIDE_INT *offset_p, poly_int64 *size_p,
1127 bool *by_ref, bool *guaranteed_unmodified = NULL);
1129 /* Debugging interface. */
1130 void ipa_print_node_params (FILE *, struct cgraph_node *node);
1131 void ipa_print_all_params (FILE *);
1132 void ipa_print_node_jump_functions (FILE *f, struct cgraph_node *node);
1133 void ipa_print_all_jump_functions (FILE * f);
1134 void ipcp_verify_propagated_values (void);
1136 template <typename value>
1137 class ipcp_value;
1139 extern object_allocator<ipcp_value<tree> > ipcp_cst_values_pool;
1140 extern object_allocator<ipcp_value<ipa_polymorphic_call_context> >
1141 ipcp_poly_ctx_values_pool;
1143 template <typename valtype>
1144 struct ipcp_value_source;
1146 extern object_allocator<ipcp_value_source<tree> > ipcp_sources_pool;
1148 struct ipcp_agg_lattice;
1150 extern object_allocator<ipcp_agg_lattice> ipcp_agg_lattice_pool;
1152 void ipa_dump_agg_replacement_values (FILE *f,
1153 struct ipa_agg_replacement_value *av);
1154 void ipa_prop_write_jump_functions (void);
1155 void ipa_prop_read_jump_functions (void);
1156 void ipcp_write_transformation_summaries (void);
1157 void ipcp_read_transformation_summaries (void);
1158 int ipa_get_param_decl_index (class ipa_node_params *, tree);
1159 tree ipa_value_from_jfunc (class ipa_node_params *info,
1160 struct ipa_jump_func *jfunc, tree type);
1161 unsigned int ipcp_transform_function (struct cgraph_node *node);
1162 ipa_polymorphic_call_context ipa_context_from_jfunc (ipa_node_params *,
1163 cgraph_edge *,
1164 int,
1165 ipa_jump_func *);
1166 value_range ipa_value_range_from_jfunc (ipa_node_params *, cgraph_edge *,
1167 ipa_jump_func *, tree);
1168 ipa_agg_value_set ipa_agg_value_set_from_jfunc (ipa_node_params *,
1169 cgraph_node *,
1170 ipa_agg_jump_function *);
1171 void ipa_dump_param (FILE *, class ipa_node_params *info, int i);
1172 void ipa_release_body_info (struct ipa_func_body_info *);
1173 tree ipa_get_callee_param_type (struct cgraph_edge *e, int i);
1174 bool ipcp_get_parm_bits (tree, tree *, widest_int *);
1175 bool unadjusted_ptr_and_unit_offset (tree op, tree *ret,
1176 poly_int64 *offset_ret);
1178 /* From tree-sra.c: */
1179 tree build_ref_for_offset (location_t, tree, poly_int64, bool, tree,
1180 gimple_stmt_iterator *, bool);
1182 /* In ipa-cp.c */
1183 void ipa_cp_c_finalize (void);
1185 #endif /* IPA_PROP_H */