1 /* Interprocedural analyses.
2 Copyright (C) 2005-2019 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
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
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/>. */
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
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
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. */
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. */
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. */
94 /* Number of the caller's formal parameter being passed. */
96 /* Operation that is performed on the argument before it is passed on.
97 NOP_EXPR means no operation. Otherwise oper must be a simple binary
98 arithmetic operation where the caller's parameter is the first operand and
99 operand field from this structure is the second one. */
100 enum tree_code operation
;
101 /* When the passed value is a pointer, it is set to true only when we are
102 certain that no write to the object it points to has occurred since the
103 caller functions started execution, except for changes noted in the
104 aggregate part of the jump function (see description of
105 ipa_agg_jump_function). The flag is used only when the operation is
107 unsigned agg_preserved
: 1;
110 /* Structure holding data required to describe a load-value-from-aggregate
113 struct GTY(()) ipa_load_agg_data
115 /* Inherit from pass through jump function, describing unary/binary
116 operation on the value loaded from aggregate that is represented or
117 pointed to by the formal parameter, specified by formal_id in this
118 pass_through jump function data structure. */
119 struct ipa_pass_through_data pass_through
;
120 /* Type of the value loaded from the aggregate. */
122 /* Offset at which the value is located within the aggregate. */
123 HOST_WIDE_INT offset
;
124 /* True if loaded by reference (the aggregate is pointed to by the formal
125 parameter) or false if loaded by value (the aggregate is represented
126 by the formal parameter). */
130 /* Structure holding data required to describe an ancestor pass-through
133 struct GTY(()) ipa_ancestor_jf_data
135 /* Offset of the field representing the ancestor. */
136 HOST_WIDE_INT offset
;
137 /* Number of the caller's formal parameter being passed. */
139 /* Flag with the same meaning like agg_preserve in ipa_pass_through_data. */
140 unsigned agg_preserved
: 1;
143 /* A jump function for an aggregate part at a given offset, which describes how
144 it content value is generated. All unlisted positions are assumed to have a
145 value defined in an unknown way. */
147 struct GTY(()) ipa_agg_jf_item
149 /* The offset for the aggregate part. */
150 HOST_WIDE_INT offset
;
152 /* Data type of the aggregate part. */
155 /* Jump function type. */
156 enum jump_func_type jftype
;
158 /* Represents a value of jump function. constant represents the actual constant
159 in constant jump function content. pass_through is used only in simple pass
160 through jump function context. load_agg is for load-value-from-aggregate
161 jump function context. */
162 union jump_func_agg_value
164 tree
GTY ((tag ("IPA_JF_CONST"))) constant
;
165 struct ipa_pass_through_data
GTY ((tag ("IPA_JF_PASS_THROUGH"))) pass_through
;
166 struct ipa_load_agg_data
GTY ((tag ("IPA_JF_LOAD_AGG"))) load_agg
;
167 } GTY ((desc ("%1.jftype"))) value
;
170 /* Jump functions describing a set of aggregate contents. */
172 struct GTY(()) ipa_agg_jump_function
174 /* Description of the individual jump function item. */
175 vec
<ipa_agg_jf_item
, va_gc
> *items
;
176 /* True if the data was passed by reference (as opposed to by value). */
180 /* An element in an aggregate part describing a known value at a given offset.
181 All unlisted positions are assumed to be unknown and all listed values must
182 fulfill is_gimple_ip_invariant. */
186 /* The offset at which the known value is located within the aggregate. */
187 HOST_WIDE_INT offset
;
189 /* The known constant. */
192 /* Return true if OTHER describes same agg value. */
193 bool equal_to (const ipa_agg_value
&other
);
196 /* Structure describing a set of known offset/value for aggregate. */
198 struct ipa_agg_value_set
200 /* Description of the individual item. */
201 vec
<ipa_agg_value
> items
;
202 /* True if the data was passed by reference (as opposed to by value). */
205 /* Return true if OTHER describes same agg values. */
206 bool equal_to (const ipa_agg_value_set
&other
)
208 if (by_ref
!= other
.by_ref
)
210 if (items
.length () != other
.items
.length ())
212 for (unsigned int i
= 0; i
< items
.length (); i
++)
213 if (!items
[i
].equal_to (other
.items
[i
]))
218 /* Return true if there is any value for aggregate. */
219 bool is_empty () const
221 return items
.is_empty ();
224 ipa_agg_value_set
copy () const
226 ipa_agg_value_set new_copy
;
228 new_copy
.items
= items
.copy ();
229 new_copy
.by_ref
= by_ref
;
240 /* Return copy of a vec<ipa_agg_value_set>. */
242 static inline vec
<ipa_agg_value_set
>
243 ipa_copy_agg_values (const vec
<ipa_agg_value_set
> &aggs
)
245 vec
<ipa_agg_value_set
> aggs_copy
= vNULL
;
247 if (!aggs
.is_empty ())
249 ipa_agg_value_set
*agg
;
252 aggs_copy
.reserve_exact (aggs
.length ());
254 FOR_EACH_VEC_ELT (aggs
, i
, agg
)
255 aggs_copy
.quick_push (agg
->copy ());
261 /* For vec<ipa_agg_value_set>, DO NOT call release(), use below function
262 instead. Because ipa_agg_value_set contains a field of vector type, we
263 should release this child vector in each element before reclaiming the
267 ipa_release_agg_values (vec
<ipa_agg_value_set
> &aggs
)
269 ipa_agg_value_set
*agg
;
272 FOR_EACH_VEC_ELT (aggs
, i
, agg
)
277 /* Information about zero/non-zero bits. */
278 class GTY(()) ipa_bits
281 /* The propagated value. */
283 /* Mask corresponding to the value.
284 Similar to ccp_lattice_t, if xth bit of mask is 0,
285 implies xth bit of value is constant. */
289 /* Info about value ranges. */
294 /* The data fields below are valid only if known is true. */
296 enum value_range_kind type
;
299 bool nonzero_p (tree
) const;
302 /* A jump function for a callsite represents the values passed as actual
303 arguments of the callsite. See enum jump_func_type for the various
304 types of jump functions supported. */
305 struct GTY (()) ipa_jump_func
307 /* Aggregate jump function description. See struct ipa_agg_jump_function
308 and its description. */
309 struct ipa_agg_jump_function agg
;
311 /* Information about zero/non-zero bits. The pointed to structure is shared
312 betweed different jump functions. Use ipa_set_jfunc_bits to set this
314 class ipa_bits
*bits
;
316 /* Information about value range, containing valid data only when vr_known is
317 true. The pointed to structure is shared betweed different jump
318 functions. Use ipa_set_jfunc_vr to set this field. */
319 class value_range
*m_vr
;
321 enum jump_func_type type
;
322 /* Represents a value of a jump function. pass_through is used only in jump
323 function context. constant represents the actual constant in constant jump
324 functions and member_cst holds constant c++ member functions. */
325 union jump_func_value
327 struct ipa_constant_data
GTY ((tag ("IPA_JF_CONST"))) constant
;
328 struct ipa_pass_through_data
GTY ((tag ("IPA_JF_PASS_THROUGH"))) pass_through
;
329 struct ipa_ancestor_jf_data
GTY ((tag ("IPA_JF_ANCESTOR"))) ancestor
;
330 } GTY ((desc ("%1.type"))) value
;
334 /* Return the constant stored in a constant jump functin JFUNC. */
337 ipa_get_jf_constant (struct ipa_jump_func
*jfunc
)
339 gcc_checking_assert (jfunc
->type
== IPA_JF_CONST
);
340 return jfunc
->value
.constant
.value
;
343 static inline struct ipa_cst_ref_desc
*
344 ipa_get_jf_constant_rdesc (struct ipa_jump_func
*jfunc
)
346 gcc_checking_assert (jfunc
->type
== IPA_JF_CONST
);
347 return jfunc
->value
.constant
.rdesc
;
350 /* Return the operand of a pass through jmp function JFUNC. */
353 ipa_get_jf_pass_through_operand (struct ipa_jump_func
*jfunc
)
355 gcc_checking_assert (jfunc
->type
== IPA_JF_PASS_THROUGH
);
356 return jfunc
->value
.pass_through
.operand
;
359 /* Return the number of the caller's formal parameter that a pass through jump
360 function JFUNC refers to. */
363 ipa_get_jf_pass_through_formal_id (struct ipa_jump_func
*jfunc
)
365 gcc_checking_assert (jfunc
->type
== IPA_JF_PASS_THROUGH
);
366 return jfunc
->value
.pass_through
.formal_id
;
369 /* Return operation of a pass through jump function JFUNC. */
371 static inline enum tree_code
372 ipa_get_jf_pass_through_operation (struct ipa_jump_func
*jfunc
)
374 gcc_checking_assert (jfunc
->type
== IPA_JF_PASS_THROUGH
);
375 return jfunc
->value
.pass_through
.operation
;
378 /* Return the agg_preserved flag of a pass through jump function JFUNC. */
381 ipa_get_jf_pass_through_agg_preserved (struct ipa_jump_func
*jfunc
)
383 gcc_checking_assert (jfunc
->type
== IPA_JF_PASS_THROUGH
);
384 return jfunc
->value
.pass_through
.agg_preserved
;
387 /* Return true if pass through jump function JFUNC preserves type
391 ipa_get_jf_pass_through_type_preserved (struct ipa_jump_func
*jfunc
)
393 gcc_checking_assert (jfunc
->type
== IPA_JF_PASS_THROUGH
);
394 return jfunc
->value
.pass_through
.agg_preserved
;
397 /* Return the offset of an ancestor jump function JFUNC. */
399 static inline HOST_WIDE_INT
400 ipa_get_jf_ancestor_offset (struct ipa_jump_func
*jfunc
)
402 gcc_checking_assert (jfunc
->type
== IPA_JF_ANCESTOR
);
403 return jfunc
->value
.ancestor
.offset
;
406 /* Return the number of the caller's formal parameter that an ancestor jump
407 function JFUNC refers to. */
410 ipa_get_jf_ancestor_formal_id (struct ipa_jump_func
*jfunc
)
412 gcc_checking_assert (jfunc
->type
== IPA_JF_ANCESTOR
);
413 return jfunc
->value
.ancestor
.formal_id
;
416 /* Return the agg_preserved flag of an ancestor jump function JFUNC. */
419 ipa_get_jf_ancestor_agg_preserved (struct ipa_jump_func
*jfunc
)
421 gcc_checking_assert (jfunc
->type
== IPA_JF_ANCESTOR
);
422 return jfunc
->value
.ancestor
.agg_preserved
;
425 /* Return true if ancestor jump function JFUNC presrves type information. */
428 ipa_get_jf_ancestor_type_preserved (struct ipa_jump_func
*jfunc
)
430 gcc_checking_assert (jfunc
->type
== IPA_JF_ANCESTOR
);
431 return jfunc
->value
.ancestor
.agg_preserved
;
434 /* Summary describing a single formal parameter. */
436 struct GTY(()) ipa_param_descriptor
438 /* In analysis and modification phase, this is the PARAM_DECL of this
439 parameter, in IPA LTO phase, this is the type of the the described
440 parameter or NULL if not known. Do not read this field directly but
441 through ipa_get_param and ipa_get_type as appropriate. */
443 /* If all uses of the parameter are described by ipa-prop structures, this
444 says how many there are. If any use could not be described by means of
445 ipa-prop structures, this is IPA_UNDESCRIBED_USE. */
447 unsigned int move_cost
: 28;
448 /* The parameter is used. */
450 unsigned used_by_ipa_predicates
: 1;
451 unsigned used_by_indirect_call
: 1;
452 unsigned used_by_polymorphic_call
: 1;
455 /* ipa_node_params stores information related to formal parameters of functions
456 and some other information for interprocedural passes that operate on
457 parameters (such as ipa-cp). */
459 class GTY((for_user
)) ipa_node_params
462 /* Default constructor. */
465 /* Default destructor. */
468 /* Information about individual formal parameters that are gathered when
469 summaries are generated. */
470 vec
<ipa_param_descriptor
, va_gc
> *descriptors
;
471 /* Pointer to an array of structures describing individual formal
473 class ipcp_param_lattices
* GTY((skip
)) lattices
;
474 /* Only for versioned nodes this field would not be NULL,
475 it points to the node that IPA cp cloned from. */
476 struct cgraph_node
* GTY((skip
)) ipcp_orig_node
;
477 /* If this node is an ipa-cp clone, these are the known constants that
478 describe what it has been specialized for. */
479 vec
<tree
> GTY((skip
)) known_csts
;
480 /* If this node is an ipa-cp clone, these are the known polymorphic contexts
481 that describe what it has been specialized for. */
482 vec
<ipa_polymorphic_call_context
> GTY((skip
)) known_contexts
;
483 /* Whether the param uses analysis and jump function computation has already
485 unsigned analysis_done
: 1;
486 /* Whether the function is enqueued in ipa-cp propagation stack. */
487 unsigned node_enqueued
: 1;
488 /* Whether we should create a specialized version based on values that are
489 known to be constant in all contexts. */
490 unsigned do_clone_for_all_contexts
: 1;
491 /* Set if this is an IPA-CP clone for all contexts. */
492 unsigned is_all_contexts_clone
: 1;
493 /* Node has been completely replaced by clones and will be removed after
494 ipa-cp is finished. */
495 unsigned node_dead
: 1;
496 /* Node is involved in a recursion, potentionally indirect. */
497 unsigned node_within_scc
: 1;
498 /* Node is calling a private function called only once. */
499 unsigned node_calling_single_call
: 1;
500 /* False when there is something makes versioning impossible. */
501 unsigned versionable
: 1;
505 ipa_node_params::ipa_node_params ()
506 : descriptors (NULL
), lattices (NULL
), ipcp_orig_node (NULL
),
507 known_csts (vNULL
), known_contexts (vNULL
), analysis_done (0),
508 node_enqueued (0), do_clone_for_all_contexts (0), is_all_contexts_clone (0),
509 node_dead (0), node_within_scc (0), node_calling_single_call (0),
515 ipa_node_params::~ipa_node_params ()
518 known_csts
.release ();
519 known_contexts
.release ();
522 /* Intermediate information that we get from alias analysis about a particular
523 parameter in a particular basic_block. When a parameter or the memory it
524 references is marked modified, we use that information in all dominated
525 blocks without consulting alias analysis oracle. */
527 struct ipa_param_aa_status
529 /* Set when this structure contains meaningful information. If not, the
530 structure describing a dominating BB should be used instead. */
533 /* Whether we have seen something which might have modified the data in
534 question. PARM is for the parameter itself, REF is for data it points to
535 but using the alias type of individual accesses and PT is the same thing
536 but for computing aggregate pass-through functions using a very inclusive
538 bool parm_modified
, ref_modified
, pt_modified
;
541 /* Information related to a given BB that used only when looking at function
546 /* Call graph edges going out of this BB. */
547 vec
<cgraph_edge
*> cg_edges
;
548 /* Alias analysis statuses of each formal parameter at this bb. */
549 vec
<ipa_param_aa_status
> param_aa_statuses
;
552 /* Structure with global information that is only used when looking at function
555 struct ipa_func_body_info
557 /* The node that is being analyzed. */
561 class ipa_node_params
*info
;
563 /* Information about individual BBs. */
564 vec
<ipa_bb_info
> bb_infos
;
566 /* Number of parameters. */
569 /* Number of statements we are still allowed to walked by when analyzing this
571 unsigned int aa_walk_budget
;
574 /* ipa_node_params access functions. Please use these to access fields that
575 are or will be shared among various passes. */
577 /* Return the number of formal parameters. */
580 ipa_get_param_count (class ipa_node_params
*info
)
582 return vec_safe_length (info
->descriptors
);
585 /* Return the declaration of Ith formal parameter of the function corresponding
586 to INFO. Note there is no setter function as this array is built just once
587 using ipa_initialize_node_params. This function should not be called in
591 ipa_get_param (class ipa_node_params
*info
, int i
)
593 gcc_checking_assert (info
->descriptors
);
594 tree t
= (*info
->descriptors
)[i
].decl_or_type
;
595 gcc_checking_assert (TREE_CODE (t
) == PARM_DECL
);
599 /* Return the type of Ith formal parameter of the function corresponding
600 to INFO if it is known or NULL if not. */
603 ipa_get_type (class ipa_node_params
*info
, int i
)
605 if (vec_safe_length (info
->descriptors
) <= (unsigned) i
)
607 tree t
= (*info
->descriptors
)[i
].decl_or_type
;
612 gcc_checking_assert (TREE_CODE (t
) == PARM_DECL
);
613 return TREE_TYPE (t
);
616 /* Return the move cost of Ith formal parameter of the function corresponding
620 ipa_get_param_move_cost (class ipa_node_params
*info
, int i
)
622 gcc_checking_assert (info
->descriptors
);
623 return (*info
->descriptors
)[i
].move_cost
;
626 /* Set the used flag corresponding to the Ith formal parameter of the function
627 associated with INFO to VAL. */
630 ipa_set_param_used (class ipa_node_params
*info
, int i
, bool val
)
632 gcc_checking_assert (info
->descriptors
);
633 (*info
->descriptors
)[i
].used
= val
;
636 /* Set the used_by_ipa_predicates flag corresponding to the Ith formal
637 parameter of the function associated with INFO to VAL. */
640 ipa_set_param_used_by_ipa_predicates (class ipa_node_params
*info
, int i
, bool val
)
642 gcc_checking_assert (info
->descriptors
);
643 (*info
->descriptors
)[i
].used_by_ipa_predicates
= val
;
646 /* Set the used_by_indirect_call flag corresponding to the Ith formal
647 parameter of the function associated with INFO to VAL. */
650 ipa_set_param_used_by_indirect_call (class ipa_node_params
*info
, int i
, bool val
)
652 gcc_checking_assert (info
->descriptors
);
653 (*info
->descriptors
)[i
].used_by_indirect_call
= val
;
656 /* Set the .used_by_polymorphic_call flag corresponding to the Ith formal
657 parameter of the function associated with INFO to VAL. */
660 ipa_set_param_used_by_polymorphic_call (class ipa_node_params
*info
, int i
, bool val
)
662 gcc_checking_assert (info
->descriptors
);
663 (*info
->descriptors
)[i
].used_by_polymorphic_call
= val
;
666 /* Return how many uses described by ipa-prop a parameter has or
667 IPA_UNDESCRIBED_USE if there is a use that is not described by these
670 ipa_get_controlled_uses (class ipa_node_params
*info
, int i
)
672 /* FIXME: introducing speculation causes out of bounds access here. */
673 if (vec_safe_length (info
->descriptors
) > (unsigned)i
)
674 return (*info
->descriptors
)[i
].controlled_uses
;
675 return IPA_UNDESCRIBED_USE
;
678 /* Set the controlled counter of a given parameter. */
681 ipa_set_controlled_uses (class ipa_node_params
*info
, int i
, int val
)
683 gcc_checking_assert (info
->descriptors
);
684 (*info
->descriptors
)[i
].controlled_uses
= val
;
687 /* Return the used flag corresponding to the Ith formal parameter of the
688 function associated with INFO. */
691 ipa_is_param_used (class ipa_node_params
*info
, int i
)
693 gcc_checking_assert (info
->descriptors
);
694 return (*info
->descriptors
)[i
].used
;
697 /* Return the used_by_ipa_predicates flag corresponding to the Ith formal
698 parameter of the function associated with INFO. */
701 ipa_is_param_used_by_ipa_predicates (class ipa_node_params
*info
, int i
)
703 gcc_checking_assert (info
->descriptors
);
704 return (*info
->descriptors
)[i
].used_by_ipa_predicates
;
707 /* Return the used_by_indirect_call flag corresponding to the Ith formal
708 parameter of the function associated with INFO. */
711 ipa_is_param_used_by_indirect_call (class ipa_node_params
*info
, int i
)
713 gcc_checking_assert (info
->descriptors
);
714 return (*info
->descriptors
)[i
].used_by_indirect_call
;
717 /* Return the used_by_polymorphic_call flag corresponding to the Ith formal
718 parameter of the function associated with INFO. */
721 ipa_is_param_used_by_polymorphic_call (class ipa_node_params
*info
, int i
)
723 gcc_checking_assert (info
->descriptors
);
724 return (*info
->descriptors
)[i
].used_by_polymorphic_call
;
727 /* Information about replacements done in aggregates for a given node (each
728 node has its linked list). */
729 struct GTY(()) ipa_agg_replacement_value
731 /* Next item in the linked list. */
732 struct ipa_agg_replacement_value
*next
;
733 /* Offset within the aggregate. */
734 HOST_WIDE_INT offset
;
735 /* The constant value. */
737 /* The paramter index. */
739 /* Whether the value was passed by reference. */
743 /* Structure holding information for the transformation phase of IPA-CP. */
745 struct GTY(()) ipcp_transformation
747 /* Linked list of known aggregate values. */
748 ipa_agg_replacement_value
*agg_values
;
749 /* Known bits information. */
750 vec
<ipa_bits
*, va_gc
> *bits
;
751 /* Value range information. */
752 vec
<ipa_vr
, va_gc
> *m_vr
;
754 /* Default constructor. */
755 ipcp_transformation ()
756 : agg_values (NULL
), bits (NULL
), m_vr (NULL
)
759 /* Default destructor. */
760 ~ipcp_transformation ()
762 ipa_agg_replacement_value
*agg
= agg_values
;
765 ipa_agg_replacement_value
*next
= agg
->next
;
774 void ipa_set_node_agg_value_chain (struct cgraph_node
*node
,
775 struct ipa_agg_replacement_value
*aggvals
);
776 void ipcp_transformation_initialize (void);
777 void ipcp_free_transformation_sum (void);
779 /* ipa_edge_args stores information related to a callsite and particularly its
780 arguments. It can be accessed by the IPA_EDGE_REF macro. */
782 class GTY((for_user
)) ipa_edge_args
786 /* Default constructor. */
787 ipa_edge_args () : jump_functions (NULL
), polymorphic_call_contexts (NULL
)
793 vec_free (jump_functions
);
794 vec_free (polymorphic_call_contexts
);
797 /* Vectors of the callsite's jump function and polymorphic context
798 information of each parameter. */
799 vec
<ipa_jump_func
, va_gc
> *jump_functions
;
800 vec
<ipa_polymorphic_call_context
, va_gc
> *polymorphic_call_contexts
;
803 /* ipa_edge_args access functions. Please use these to access fields that
804 are or will be shared among various passes. */
806 /* Return the number of actual arguments. */
809 ipa_get_cs_argument_count (class ipa_edge_args
*args
)
811 return vec_safe_length (args
->jump_functions
);
814 /* Returns a pointer to the jump function for the ith argument. Please note
815 there is no setter function as jump functions are all set up in
816 ipa_compute_jump_functions. */
818 static inline struct ipa_jump_func
*
819 ipa_get_ith_jump_func (class ipa_edge_args
*args
, int i
)
821 return &(*args
->jump_functions
)[i
];
824 /* Returns a pointer to the polymorphic call context for the ith argument.
825 NULL if contexts are not computed. */
826 static inline class ipa_polymorphic_call_context
*
827 ipa_get_ith_polymorhic_call_context (class ipa_edge_args
*args
, int i
)
829 if (!args
->polymorphic_call_contexts
)
831 return &(*args
->polymorphic_call_contexts
)[i
];
834 /* Function summary for ipa_node_params. */
835 class GTY((user
)) ipa_node_params_t
: public function_summary
<ipa_node_params
*>
838 ipa_node_params_t (symbol_table
*table
, bool ggc
):
839 function_summary
<ipa_node_params
*> (table
, ggc
) { }
841 /* Hook that is called by summary when a node is duplicated. */
842 virtual void duplicate (cgraph_node
*node
,
844 ipa_node_params
*data
,
845 ipa_node_params
*data2
);
848 /* Summary to manange ipa_edge_args structures. */
850 class GTY((user
)) ipa_edge_args_sum_t
: public call_summary
<ipa_edge_args
*>
853 ipa_edge_args_sum_t (symbol_table
*table
, bool ggc
)
854 : call_summary
<ipa_edge_args
*> (table
, ggc
) { }
856 void remove (cgraph_edge
*edge
)
858 call_summary
<ipa_edge_args
*>::remove (edge
);
861 /* Hook that is called by summary when an edge is removed. */
862 virtual void remove (cgraph_edge
*cs
, ipa_edge_args
*args
);
863 /* Hook that is called by summary when an edge is duplicated. */
864 virtual void duplicate (cgraph_edge
*src
,
866 ipa_edge_args
*old_args
,
867 ipa_edge_args
*new_args
);
870 /* Function summary where the parameter infos are actually stored. */
871 extern GTY(()) ipa_node_params_t
* ipa_node_params_sum
;
872 /* Call summary to store information about edges such as jump functions. */
873 extern GTY(()) ipa_edge_args_sum_t
*ipa_edge_args_sum
;
875 /* Function summary for IPA-CP transformation. */
876 class ipcp_transformation_t
877 : public function_summary
<ipcp_transformation
*>
880 ipcp_transformation_t (symbol_table
*table
, bool ggc
):
881 function_summary
<ipcp_transformation
*> (table
, ggc
) {}
883 ~ipcp_transformation_t () {}
885 static ipcp_transformation_t
*create_ggc (symbol_table
*symtab
)
887 ipcp_transformation_t
*summary
888 = new (ggc_alloc_no_dtor
<ipcp_transformation_t
> ())
889 ipcp_transformation_t (symtab
, true);
892 /* Hook that is called by summary when a node is duplicated. */
893 virtual void duplicate (cgraph_node
*node
,
895 ipcp_transformation
*data
,
896 ipcp_transformation
*data2
);
899 /* Function summary where the IPA CP transformations are actually stored. */
900 extern GTY(()) function_summary
<ipcp_transformation
*> *ipcp_transformation_sum
;
902 /* Return the associated parameter/argument info corresponding to the given
904 #define IPA_NODE_REF(NODE) (ipa_node_params_sum->get (NODE))
905 #define IPA_NODE_REF_GET_CREATE(NODE) (ipa_node_params_sum->get_create (NODE))
906 #define IPA_EDGE_REF(EDGE) (ipa_edge_args_sum->get (EDGE))
907 #define IPA_EDGE_REF_GET_CREATE(EDGE) (ipa_edge_args_sum->get_create (EDGE))
908 /* This macro checks validity of index returned by
909 ipa_get_param_decl_index function. */
910 #define IS_VALID_JUMP_FUNC_INDEX(I) ((I) != -1)
912 /* Creating and freeing ipa_node_params and ipa_edge_args. */
913 void ipa_create_all_node_params (void);
914 void ipa_create_all_edge_args (void);
915 void ipa_check_create_edge_args (void);
916 void ipa_free_all_node_params (void);
917 void ipa_free_all_edge_args (void);
918 void ipa_free_all_structures_after_ipa_cp (void);
919 void ipa_free_all_structures_after_iinln (void);
921 void ipa_register_cgraph_hooks (void);
922 int count_formal_params (tree fndecl
);
924 /* This function ensures the array of node param infos is big enough to
925 accommodate a structure for all nodes and reallocates it if not. */
928 ipa_check_create_node_params (void)
930 if (!ipa_node_params_sum
)
932 = (new (ggc_alloc_no_dtor
<ipa_node_params_t
> ())
933 ipa_node_params_t (symtab
, true));
936 /* Returns true if edge summary contains a record for EDGE. The main purpose
937 of this function is that debug dumping function can check info availability
938 without causing allocations. */
941 ipa_edge_args_info_available_for_edge_p (struct cgraph_edge
*edge
)
943 return ipa_edge_args_sum
->exists (edge
);
946 static inline ipcp_transformation
*
947 ipcp_get_transformation_summary (cgraph_node
*node
)
949 if (ipcp_transformation_sum
== NULL
)
952 return ipcp_transformation_sum
->get (node
);
955 /* Return the aggregate replacements for NODE, if there are any. */
957 static inline struct ipa_agg_replacement_value
*
958 ipa_get_agg_replacements_for_node (cgraph_node
*node
)
960 ipcp_transformation
*ts
= ipcp_get_transformation_summary (node
);
961 return ts
? ts
->agg_values
: NULL
;
964 /* Function formal parameters related computations. */
965 void ipa_initialize_node_params (struct cgraph_node
*node
);
966 bool ipa_propagate_indirect_call_infos (struct cgraph_edge
*cs
,
967 vec
<cgraph_edge
*> *new_edges
);
969 /* Indirect edge and binfo processing. */
970 tree
ipa_get_indirect_edge_target (struct cgraph_edge
*ie
,
972 vec
<ipa_polymorphic_call_context
>,
973 vec
<ipa_agg_value_set
>,
975 struct cgraph_edge
*ipa_make_edge_direct_to_target (struct cgraph_edge
*, tree
,
976 bool speculative
= false);
977 tree
ipa_impossible_devirt_target (struct cgraph_edge
*, tree
);
978 ipa_bits
*ipa_get_ipa_bits_for_value (const widest_int
&value
,
979 const widest_int
&mask
);
982 /* Functions related to both. */
983 void ipa_analyze_node (struct cgraph_node
*);
985 /* Aggregate jump function related functions. */
986 tree
ipa_find_agg_cst_for_param (struct ipa_agg_value_set
*agg
, tree scalar
,
987 HOST_WIDE_INT offset
, bool by_ref
,
988 bool *from_global_constant
= NULL
);
989 bool ipa_load_from_parm_agg (struct ipa_func_body_info
*fbi
,
990 vec
<ipa_param_descriptor
, va_gc
> *descriptors
,
991 gimple
*stmt
, tree op
, int *index_p
,
992 HOST_WIDE_INT
*offset_p
, poly_int64
*size_p
,
993 bool *by_ref
, bool *guaranteed_unmodified
= NULL
);
995 /* Debugging interface. */
996 void ipa_print_node_params (FILE *, struct cgraph_node
*node
);
997 void ipa_print_all_params (FILE *);
998 void ipa_print_node_jump_functions (FILE *f
, struct cgraph_node
*node
);
999 void ipa_print_all_jump_functions (FILE * f
);
1000 void ipcp_verify_propagated_values (void);
1002 template <typename value
>
1005 extern object_allocator
<ipcp_value
<tree
> > ipcp_cst_values_pool
;
1006 extern object_allocator
<ipcp_value
<ipa_polymorphic_call_context
> >
1007 ipcp_poly_ctx_values_pool
;
1009 template <typename valtype
>
1010 struct ipcp_value_source
;
1012 extern object_allocator
<ipcp_value_source
<tree
> > ipcp_sources_pool
;
1014 struct ipcp_agg_lattice
;
1016 extern object_allocator
<ipcp_agg_lattice
> ipcp_agg_lattice_pool
;
1018 void ipa_dump_agg_replacement_values (FILE *f
,
1019 struct ipa_agg_replacement_value
*av
);
1020 void ipa_prop_write_jump_functions (void);
1021 void ipa_prop_read_jump_functions (void);
1022 void ipcp_write_transformation_summaries (void);
1023 void ipcp_read_transformation_summaries (void);
1024 int ipa_get_param_decl_index (class ipa_node_params
*, tree
);
1025 tree
ipa_value_from_jfunc (class ipa_node_params
*info
,
1026 struct ipa_jump_func
*jfunc
, tree type
);
1027 unsigned int ipcp_transform_function (struct cgraph_node
*node
);
1028 ipa_polymorphic_call_context
ipa_context_from_jfunc (ipa_node_params
*,
1032 ipa_agg_value_set
ipa_agg_value_set_from_jfunc (ipa_node_params
*,
1034 ipa_agg_jump_function
*);
1035 void ipa_dump_param (FILE *, class ipa_node_params
*info
, int i
);
1036 void ipa_release_body_info (struct ipa_func_body_info
*);
1037 tree
ipa_get_callee_param_type (struct cgraph_edge
*e
, int i
);
1039 /* From tree-sra.c: */
1040 tree
build_ref_for_offset (location_t
, tree
, poly_int64
, bool, tree
,
1041 gimple_stmt_iterator
*, bool);
1044 void ipa_cp_c_finalize (void);
1046 #endif /* IPA_PROP_H */