Fix typo in t-dimode
[official-gcc.git] / gcc / ipa-prop.h
blobba49843a510f46778d89634be4026ec61c899aad
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_is_self_scc (0),
627 node_calling_single_call (0), 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 parameter declaration in DESCRIPTORS at index I and assert it is
704 indeed a PARM_DECL. */
706 static inline tree
707 ipa_get_param (const vec<ipa_param_descriptor, va_gc> &descriptors, int i)
709 tree t = descriptors[i].decl_or_type;
710 gcc_checking_assert (TREE_CODE (t) == PARM_DECL);
711 return t;
714 /* Return the declaration of Ith formal parameter of the function corresponding
715 to INFO. Note there is no setter function as this array is built just once
716 using ipa_initialize_node_params. This function should not be called in
717 WPA. */
719 static inline tree
720 ipa_get_param (class ipa_node_params *info, int i)
722 gcc_checking_assert (info->descriptors);
723 return ipa_get_param (*info->descriptors, i);
726 /* Return the type of Ith formal parameter of the function corresponding
727 to INFO if it is known or NULL if not. */
729 static inline tree
730 ipa_get_type (class ipa_node_params *info, int i)
732 if (vec_safe_length (info->descriptors) <= (unsigned) i)
733 return NULL;
734 tree t = (*info->descriptors)[i].decl_or_type;
735 if (!t)
736 return NULL;
737 if (TYPE_P (t))
738 return t;
739 gcc_checking_assert (TREE_CODE (t) == PARM_DECL);
740 return TREE_TYPE (t);
743 /* Return the move cost of Ith formal parameter of the function corresponding
744 to INFO. */
746 static inline int
747 ipa_get_param_move_cost (class ipa_node_params *info, int i)
749 gcc_checking_assert (info->descriptors);
750 return (*info->descriptors)[i].move_cost;
753 /* Set the used flag corresponding to the Ith formal parameter of the function
754 associated with INFO to VAL. */
756 static inline void
757 ipa_set_param_used (class ipa_node_params *info, int i, bool val)
759 gcc_checking_assert (info->descriptors);
760 (*info->descriptors)[i].used = val;
763 /* Set the used_by_ipa_predicates flag corresponding to the Ith formal
764 parameter of the function associated with INFO to VAL. */
766 static inline void
767 ipa_set_param_used_by_ipa_predicates (class ipa_node_params *info, int i, bool val)
769 gcc_checking_assert (info->descriptors);
770 (*info->descriptors)[i].used_by_ipa_predicates = val;
773 /* Set the used_by_indirect_call flag corresponding to the Ith formal
774 parameter of the function associated with INFO to VAL. */
776 static inline void
777 ipa_set_param_used_by_indirect_call (class ipa_node_params *info, int i, bool val)
779 gcc_checking_assert (info->descriptors);
780 (*info->descriptors)[i].used_by_indirect_call = val;
783 /* Set the .used_by_polymorphic_call flag corresponding to the Ith formal
784 parameter of the function associated with INFO to VAL. */
786 static inline void
787 ipa_set_param_used_by_polymorphic_call (class ipa_node_params *info, int i, bool val)
789 gcc_checking_assert (info->descriptors);
790 (*info->descriptors)[i].used_by_polymorphic_call = val;
793 /* Return how many uses described by ipa-prop a parameter has or
794 IPA_UNDESCRIBED_USE if there is a use that is not described by these
795 structures. */
796 static inline int
797 ipa_get_controlled_uses (class ipa_node_params *info, int i)
799 /* FIXME: introducing speculation causes out of bounds access here. */
800 if (vec_safe_length (info->descriptors) > (unsigned)i)
801 return (*info->descriptors)[i].controlled_uses;
802 return IPA_UNDESCRIBED_USE;
805 /* Set the controlled counter of a given parameter. */
807 static inline void
808 ipa_set_controlled_uses (class ipa_node_params *info, int i, int val)
810 gcc_checking_assert (info->descriptors);
811 (*info->descriptors)[i].controlled_uses = val;
814 /* Assuming a parameter does not have IPA_UNDESCRIBED_USE controlled uses,
815 return flag which indicates it has been dereferenced but only in a load. */
816 static inline int
817 ipa_get_param_load_dereferenced (class ipa_node_params *info, int i)
819 gcc_assert (ipa_get_controlled_uses (info, i) != IPA_UNDESCRIBED_USE);
820 return (*info->descriptors)[i].load_dereferenced;
823 /* Set the load_dereferenced flag of a given parameter. */
825 static inline void
826 ipa_set_param_load_dereferenced (class ipa_node_params *info, int i, bool val)
828 gcc_checking_assert (info->descriptors);
829 (*info->descriptors)[i].load_dereferenced = val;
832 /* Return the used flag corresponding to the Ith formal parameter of the
833 function associated with INFO. */
835 static inline bool
836 ipa_is_param_used (class ipa_node_params *info, int i)
838 gcc_checking_assert (info->descriptors);
839 return (*info->descriptors)[i].used;
842 /* Return the used_by_ipa_predicates flag corresponding to the Ith formal
843 parameter of the function associated with INFO. */
845 static inline bool
846 ipa_is_param_used_by_ipa_predicates (class ipa_node_params *info, int i)
848 gcc_checking_assert (info->descriptors);
849 return (*info->descriptors)[i].used_by_ipa_predicates;
852 /* Return the used_by_indirect_call flag corresponding to the Ith formal
853 parameter of the function associated with INFO. */
855 static inline bool
856 ipa_is_param_used_by_indirect_call (class ipa_node_params *info, int i)
858 gcc_checking_assert (info->descriptors);
859 return (*info->descriptors)[i].used_by_indirect_call;
862 /* Return the used_by_polymorphic_call flag corresponding to the Ith formal
863 parameter of the function associated with INFO. */
865 static inline bool
866 ipa_is_param_used_by_polymorphic_call (class ipa_node_params *info, int i)
868 gcc_checking_assert (info->descriptors);
869 return (*info->descriptors)[i].used_by_polymorphic_call;
872 /* Information about replacements done in aggregates for a given node (each
873 node has its linked list). */
874 struct GTY(()) ipa_agg_replacement_value
876 /* Next item in the linked list. */
877 struct ipa_agg_replacement_value *next;
878 /* Offset within the aggregate. */
879 HOST_WIDE_INT offset;
880 /* The constant value. */
881 tree value;
882 /* The parameter index. */
883 int index;
884 /* Whether the value was passed by reference. */
885 bool by_ref;
888 /* Structure holding information for the transformation phase of IPA-CP. */
890 struct GTY(()) ipcp_transformation
892 /* Linked list of known aggregate values. */
893 ipa_agg_replacement_value *agg_values;
894 /* Known bits information. */
895 vec<ipa_bits *, va_gc> *bits;
896 /* Value range information. */
897 vec<ipa_vr, va_gc> *m_vr;
899 /* Default constructor. */
900 ipcp_transformation ()
901 : agg_values (NULL), bits (NULL), m_vr (NULL)
904 /* Default destructor. */
905 ~ipcp_transformation ()
907 ipa_agg_replacement_value *agg = agg_values;
908 while (agg)
910 ipa_agg_replacement_value *next = agg->next;
911 ggc_free (agg);
912 agg = next;
914 vec_free (bits);
915 vec_free (m_vr);
919 void ipa_set_node_agg_value_chain (struct cgraph_node *node,
920 struct ipa_agg_replacement_value *aggvals);
921 void ipcp_transformation_initialize (void);
922 void ipcp_free_transformation_sum (void);
924 /* ipa_edge_args stores information related to a callsite and particularly its
925 arguments. It can be accessed by the IPA_EDGE_REF macro. */
927 class GTY((for_user)) ipa_edge_args
929 public:
931 /* Default constructor. */
932 ipa_edge_args () : jump_functions (NULL), polymorphic_call_contexts (NULL)
935 /* Destructor. */
936 ~ipa_edge_args ()
938 unsigned int i;
939 ipa_jump_func *jf;
940 FOR_EACH_VEC_SAFE_ELT (jump_functions, i, jf)
941 vec_free (jf->agg.items);
942 vec_free (jump_functions);
943 vec_free (polymorphic_call_contexts);
946 /* Vectors of the callsite's jump function and polymorphic context
947 information of each parameter. */
948 vec<ipa_jump_func, va_gc> *jump_functions;
949 vec<ipa_polymorphic_call_context, va_gc> *polymorphic_call_contexts;
952 /* ipa_edge_args access functions. Please use these to access fields that
953 are or will be shared among various passes. */
955 /* Return the number of actual arguments. */
957 static inline int
958 ipa_get_cs_argument_count (class ipa_edge_args *args)
960 return vec_safe_length (args->jump_functions);
963 /* Returns a pointer to the jump function for the ith argument. Please note
964 there is no setter function as jump functions are all set up in
965 ipa_compute_jump_functions. */
967 static inline struct ipa_jump_func *
968 ipa_get_ith_jump_func (class ipa_edge_args *args, int i)
970 return &(*args->jump_functions)[i];
973 /* Returns a pointer to the polymorphic call context for the ith argument.
974 NULL if contexts are not computed. */
975 static inline class ipa_polymorphic_call_context *
976 ipa_get_ith_polymorhic_call_context (class ipa_edge_args *args, int i)
978 if (!args->polymorphic_call_contexts)
979 return NULL;
980 return &(*args->polymorphic_call_contexts)[i];
983 /* Function summary for ipa_node_params. */
984 class GTY((user)) ipa_node_params_t: public function_summary <ipa_node_params *>
986 public:
987 ipa_node_params_t (symbol_table *table, bool ggc):
988 function_summary<ipa_node_params *> (table, ggc)
990 disable_insertion_hook ();
993 /* Hook that is called by summary when a node is duplicated. */
994 virtual void duplicate (cgraph_node *node,
995 cgraph_node *node2,
996 ipa_node_params *data,
997 ipa_node_params *data2);
1000 /* Summary to manange ipa_edge_args structures. */
1002 class GTY((user)) ipa_edge_args_sum_t : public call_summary <ipa_edge_args *>
1004 public:
1005 ipa_edge_args_sum_t (symbol_table *table, bool ggc)
1006 : call_summary<ipa_edge_args *> (table, ggc) { }
1008 void remove (cgraph_edge *edge)
1010 call_summary <ipa_edge_args *>::remove (edge);
1013 /* Hook that is called by summary when an edge is removed. */
1014 virtual void remove (cgraph_edge *cs, ipa_edge_args *args);
1015 /* Hook that is called by summary when an edge is duplicated. */
1016 virtual void duplicate (cgraph_edge *src,
1017 cgraph_edge *dst,
1018 ipa_edge_args *old_args,
1019 ipa_edge_args *new_args);
1022 /* Function summary where the parameter infos are actually stored. */
1023 extern GTY(()) ipa_node_params_t * ipa_node_params_sum;
1024 /* Call summary to store information about edges such as jump functions. */
1025 extern GTY(()) ipa_edge_args_sum_t *ipa_edge_args_sum;
1027 /* Function summary for IPA-CP transformation. */
1028 class ipcp_transformation_t
1029 : public function_summary<ipcp_transformation *>
1031 public:
1032 ipcp_transformation_t (symbol_table *table, bool ggc):
1033 function_summary<ipcp_transformation *> (table, ggc) {}
1035 ~ipcp_transformation_t () {}
1037 static ipcp_transformation_t *create_ggc (symbol_table *symtab)
1039 ipcp_transformation_t *summary
1040 = new (ggc_alloc_no_dtor <ipcp_transformation_t> ())
1041 ipcp_transformation_t (symtab, true);
1042 return summary;
1044 /* Hook that is called by summary when a node is duplicated. */
1045 virtual void duplicate (cgraph_node *node,
1046 cgraph_node *node2,
1047 ipcp_transformation *data,
1048 ipcp_transformation *data2);
1051 /* Function summary where the IPA CP transformations are actually stored. */
1052 extern GTY(()) function_summary <ipcp_transformation *> *ipcp_transformation_sum;
1054 /* Creating and freeing ipa_node_params and ipa_edge_args. */
1055 void ipa_create_all_node_params (void);
1056 void ipa_create_all_edge_args (void);
1057 void ipa_check_create_edge_args (void);
1058 void ipa_free_all_node_params (void);
1059 void ipa_free_all_edge_args (void);
1060 void ipa_free_all_structures_after_ipa_cp (void);
1061 void ipa_free_all_structures_after_iinln (void);
1063 void ipa_register_cgraph_hooks (void);
1064 int count_formal_params (tree fndecl);
1066 /* This function ensures the array of node param infos is big enough to
1067 accommodate a structure for all nodes and reallocates it if not. */
1069 static inline void
1070 ipa_check_create_node_params (void)
1072 if (!ipa_node_params_sum)
1073 ipa_node_params_sum
1074 = (new (ggc_alloc_no_dtor <ipa_node_params_t> ())
1075 ipa_node_params_t (symtab, true));
1078 /* Returns true if edge summary contains a record for EDGE. The main purpose
1079 of this function is that debug dumping function can check info availability
1080 without causing allocations. */
1082 static inline bool
1083 ipa_edge_args_info_available_for_edge_p (struct cgraph_edge *edge)
1085 return ipa_edge_args_sum->exists (edge);
1088 static inline ipcp_transformation *
1089 ipcp_get_transformation_summary (cgraph_node *node)
1091 if (ipcp_transformation_sum == NULL)
1092 return NULL;
1094 return ipcp_transformation_sum->get (node);
1097 /* Return the aggregate replacements for NODE, if there are any. */
1099 static inline struct ipa_agg_replacement_value *
1100 ipa_get_agg_replacements_for_node (cgraph_node *node)
1102 ipcp_transformation *ts = ipcp_get_transformation_summary (node);
1103 return ts ? ts->agg_values : NULL;
1106 /* Function formal parameters related computations. */
1107 void ipa_initialize_node_params (struct cgraph_node *node);
1108 bool ipa_propagate_indirect_call_infos (struct cgraph_edge *cs,
1109 vec<cgraph_edge *> *new_edges);
1111 /* Indirect edge processing and target discovery. */
1112 tree ipa_get_indirect_edge_target (struct cgraph_edge *ie,
1113 ipa_call_arg_values *avals,
1114 bool *speculative);
1115 tree ipa_get_indirect_edge_target (struct cgraph_edge *ie,
1116 ipa_auto_call_arg_values *avals,
1117 bool *speculative);
1118 struct cgraph_edge *ipa_make_edge_direct_to_target (struct cgraph_edge *, tree,
1119 bool speculative = false);
1120 tree ipa_impossible_devirt_target (struct cgraph_edge *, tree);
1121 ipa_bits *ipa_get_ipa_bits_for_value (const widest_int &value,
1122 const widest_int &mask);
1125 /* Functions related to both. */
1126 void ipa_analyze_node (struct cgraph_node *);
1128 /* Aggregate jump function related functions. */
1129 tree ipa_find_agg_cst_for_param (const ipa_agg_value_set *agg, tree scalar,
1130 HOST_WIDE_INT offset, bool by_ref,
1131 bool *from_global_constant = NULL);
1132 bool ipa_load_from_parm_agg (struct ipa_func_body_info *fbi,
1133 vec<ipa_param_descriptor, va_gc> *descriptors,
1134 gimple *stmt, tree op, int *index_p,
1135 HOST_WIDE_INT *offset_p, poly_int64 *size_p,
1136 bool *by_ref, bool *guaranteed_unmodified = NULL);
1138 /* Debugging interface. */
1139 void ipa_print_node_params (FILE *, struct cgraph_node *node);
1140 void ipa_print_all_params (FILE *);
1141 void ipa_print_node_jump_functions (FILE *f, struct cgraph_node *node);
1142 void ipa_print_all_jump_functions (FILE * f);
1143 void ipcp_verify_propagated_values (void);
1145 template <typename value>
1146 class ipcp_value;
1148 extern object_allocator<ipcp_value<tree> > ipcp_cst_values_pool;
1149 extern object_allocator<ipcp_value<ipa_polymorphic_call_context> >
1150 ipcp_poly_ctx_values_pool;
1152 template <typename valtype>
1153 struct ipcp_value_source;
1155 extern object_allocator<ipcp_value_source<tree> > ipcp_sources_pool;
1157 struct ipcp_agg_lattice;
1159 extern object_allocator<ipcp_agg_lattice> ipcp_agg_lattice_pool;
1161 void ipa_dump_agg_replacement_values (FILE *f,
1162 struct ipa_agg_replacement_value *av);
1163 void ipa_prop_write_jump_functions (void);
1164 void ipa_prop_read_jump_functions (void);
1165 void ipcp_write_transformation_summaries (void);
1166 void ipcp_read_transformation_summaries (void);
1167 int ipa_get_param_decl_index (class ipa_node_params *, tree);
1168 tree ipa_value_from_jfunc (class ipa_node_params *info,
1169 struct ipa_jump_func *jfunc, tree type);
1170 unsigned int ipcp_transform_function (struct cgraph_node *node);
1171 ipa_polymorphic_call_context ipa_context_from_jfunc (ipa_node_params *,
1172 cgraph_edge *,
1173 int,
1174 ipa_jump_func *);
1175 value_range ipa_value_range_from_jfunc (ipa_node_params *, cgraph_edge *,
1176 ipa_jump_func *, tree);
1177 ipa_agg_value_set ipa_agg_value_set_from_jfunc (ipa_node_params *,
1178 cgraph_node *,
1179 ipa_agg_jump_function *);
1180 void ipa_dump_param (FILE *, class ipa_node_params *info, int i);
1181 void ipa_release_body_info (struct ipa_func_body_info *);
1182 tree ipa_get_callee_param_type (struct cgraph_edge *e, int i);
1183 bool ipcp_get_parm_bits (tree, tree *, widest_int *);
1184 bool unadjusted_ptr_and_unit_offset (tree op, tree *ret,
1185 poly_int64 *offset_ret);
1187 /* From tree-sra.c: */
1188 tree build_ref_for_offset (location_t, tree, poly_int64, bool, tree,
1189 gimple_stmt_iterator *, bool);
1191 /* In ipa-cp.c */
1192 void ipa_cp_c_finalize (void);
1194 #endif /* IPA_PROP_H */