]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/ipa-prop.h
re PR tree-optimization/92260 (ICE in exact_div, at poly-int.h:2162)
[thirdparty/gcc.git] / gcc / ipa-prop.h
CommitLineData
518dc859 1/* Interprocedural analyses.
a5544970 2 Copyright (C) 2005-2019 Free Software Foundation, Inc.
518dc859
RL
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
9dcd6f09 8Software Foundation; either version 3, or (at your option) any later
518dc859
RL
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
9dcd6f09
NC
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
518dc859
RL
19
20#ifndef IPA_PROP_H
21#define IPA_PROP_H
22
518dc859 23/* The following definitions and interfaces are used by
133f9369
MJ
24 interprocedural analyses or parameters. */
25
4502fe8d
MJ
26#define IPA_UNDESCRIBED_USE -1
27
133f9369 28/* ipa-prop.c stuff (ipa-cp, indirect inlining): */
518dc859 29
be95e2b9 30/* A jump function for a callsite represents the values passed as actual
310bc633
MJ
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 :
685b0d13
MJ
35
36 Pass-through - the caller's formal parameter is passed as an actual
37 argument, possibly one simple operation performed on it.
38 Constant - a constant (is_gimple_ip_invariant)is passed as an actual
39 argument.
40 Unknown - neither of the above.
41
b258210c
MJ
42 IPA_JF_ANCESTOR is a special pass-through jump function, which means that
43 the result is an address of a part of the object pointed to by the formal
44 parameter to which the function refers. It is mainly intended to represent
026c3cfd 45 getting addresses of ancestor fields in C++
b258210c
MJ
46 (e.g. &this_1(D)->D.1766.D.1756). Note that if the original pointer is
47 NULL, ancestor jump function must behave like a simple pass-through.
48
49 Other pass-through functions can either simply pass on an unchanged formal
50 parameter or can apply one simple binary operation to it (such jump
51 functions are called polynomial).
52
b258210c
MJ
53 Jump functions are computed in ipa-prop.c by function
54 update_call_notes_after_inlining. Some information can be lost and jump
55 functions degraded accordingly when inlining, see
56 update_call_notes_after_inlining in the same file. */
685b0d13 57
518dc859
RL
58enum jump_func_type
59{
133f9369 60 IPA_JF_UNKNOWN = 0, /* newly allocated and zeroed jump functions default */
b258210c 61 IPA_JF_CONST, /* represented by field costant */
b258210c
MJ
62 IPA_JF_PASS_THROUGH, /* represented by field pass_through */
63 IPA_JF_ANCESTOR /* represented by field ancestor */
518dc859
RL
64};
65
4502fe8d
MJ
66struct ipa_cst_ref_desc;
67
68/* Structure holding data required to describe a constant jump function. */
69struct GTY(()) ipa_constant_data
70{
71 /* THe value of the constant. */
72 tree value;
73 /* Pointer to the structure that describes the reference. */
74 struct ipa_cst_ref_desc GTY((skip)) *rdesc;
75};
76
685b0d13
MJ
77/* Structure holding data required to describe a pass-through jump function. */
78
fb3f88cc 79struct GTY(()) ipa_pass_through_data
685b0d13
MJ
80{
81 /* If an operation is to be performed on the original parameter, this is the
82 second (constant) operand. */
83 tree operand;
84 /* Number of the caller's formal parameter being passed. */
85 int formal_id;
86 /* Operation that is performed on the argument before it is passed on.
87 NOP_EXPR means no operation. Otherwise oper must be a simple binary
88 arithmetic operation where the caller's parameter is the first operand and
89 operand field from this structure is the second one. */
90 enum tree_code operation;
8b7773a4
MJ
91 /* When the passed value is a pointer, it is set to true only when we are
92 certain that no write to the object it points to has occurred since the
93 caller functions started execution, except for changes noted in the
94 aggregate part of the jump function (see description of
95 ipa_agg_jump_function). The flag is used only when the operation is
96 NOP_EXPR. */
b8f6e610 97 unsigned agg_preserved : 1;
685b0d13
MJ
98};
99
b258210c
MJ
100/* Structure holding data required to describe an ancestor pass-through
101 jump function. */
685b0d13 102
fb3f88cc 103struct GTY(()) ipa_ancestor_jf_data
685b0d13
MJ
104{
105 /* Offset of the field representing the ancestor. */
106 HOST_WIDE_INT offset;
685b0d13
MJ
107 /* Number of the caller's formal parameter being passed. */
108 int formal_id;
8b7773a4 109 /* Flag with the same meaning like agg_preserve in ipa_pass_through_data. */
b8f6e610 110 unsigned agg_preserved : 1;
685b0d13
MJ
111};
112
8b7773a4
MJ
113/* An element in an aggegate part of a jump function describing a known value
114 at a given offset. When it is part of a pass-through jump function with
115 agg_preserved set or an ancestor jump function with agg_preserved set, all
116 unlisted positions are assumed to be preserved but the value can be a type
117 node, which means that the particular piece (starting at offset and having
118 the size of the type) is clobbered with an unknown value. When
119 agg_preserved is false or the type of the containing jump function is
120 different, all unlisted parts are assumed to be unknown and all values must
688010ba 121 fulfill is_gimple_ip_invariant. */
8b7773a4 122
84562394 123struct GTY(()) ipa_agg_jf_item
8b7773a4
MJ
124{
125 /* The offset at which the known value is located within the aggregate. */
126 HOST_WIDE_INT offset;
127
128 /* The known constant or type if this is a clobber. */
129 tree value;
84562394 130};
8b7773a4 131
8b7773a4
MJ
132
133/* Aggregate jump function - i.e. description of contents of aggregates passed
134 either by reference or value. */
135
136struct GTY(()) ipa_agg_jump_function
3e293154 137{
8b7773a4 138 /* Description of the individual items. */
84562394 139 vec<ipa_agg_jf_item, va_gc> *items;
8b7773a4
MJ
140 /* True if the data was passed by reference (as opposed to by value). */
141 bool by_ref;
3e293154
MJ
142};
143
8b7773a4 144typedef struct ipa_agg_jump_function *ipa_agg_jump_function_p;
8b7773a4 145
209ca542 146/* Information about zero/non-zero bits. */
6c1dae73 147class GTY(()) ipa_bits
209ca542 148{
6c1dae73 149public:
209ca542
PK
150 /* The propagated value. */
151 widest_int value;
152 /* Mask corresponding to the value.
153 Similar to ccp_lattice_t, if xth bit of mask is 0,
154 implies xth bit of value is constant. */
155 widest_int mask;
209ca542
PK
156};
157
8bc5448f 158/* Info about value ranges. */
86cd0334 159
6c1dae73 160class GTY(()) ipa_vr
8bc5448f 161{
6c1dae73 162public:
8bc5448f
KV
163 /* The data fields below are valid only if known is true. */
164 bool known;
54994253 165 enum value_range_kind type;
8bc5448f
KV
166 wide_int min;
167 wide_int max;
523fe5b6 168 bool nonzero_p (tree) const;
8bc5448f
KV
169};
170
be95e2b9
MJ
171/* A jump function for a callsite represents the values passed as actual
172 arguments of the callsite. See enum jump_func_type for the various
518dc859 173 types of jump functions supported. */
84562394 174struct GTY (()) ipa_jump_func
518dc859 175{
8b7773a4
MJ
176 /* Aggregate contants description. See struct ipa_agg_jump_function and its
177 description. */
178 struct ipa_agg_jump_function agg;
179
86cd0334
MJ
180 /* Information about zero/non-zero bits. The pointed to structure is shared
181 betweed different jump functions. Use ipa_set_jfunc_bits to set this
182 field. */
99b1c316 183 class ipa_bits *bits;
209ca542 184
a5e14a42 185 /* Information about value range, containing valid data only when vr_known is
86cd0334
MJ
186 true. The pointed to structure is shared betweed different jump
187 functions. Use ipa_set_jfunc_vr to set this field. */
99b1c316 188 class value_range_base *m_vr;
8bc5448f 189
518dc859 190 enum jump_func_type type;
fb3f88cc
JH
191 /* Represents a value of a jump function. pass_through is used only in jump
192 function context. constant represents the actual constant in constant jump
193 functions and member_cst holds constant c++ member functions. */
194 union jump_func_value
195 {
4502fe8d 196 struct ipa_constant_data GTY ((tag ("IPA_JF_CONST"))) constant;
fb3f88cc
JH
197 struct ipa_pass_through_data GTY ((tag ("IPA_JF_PASS_THROUGH"))) pass_through;
198 struct ipa_ancestor_jf_data GTY ((tag ("IPA_JF_ANCESTOR"))) ancestor;
fb3f88cc 199 } GTY ((desc ("%1.type"))) value;
84562394 200};
606d9a09 201
518dc859 202
7b872d9e
MJ
203/* Return the constant stored in a constant jump functin JFUNC. */
204
205static inline tree
206ipa_get_jf_constant (struct ipa_jump_func *jfunc)
207{
208 gcc_checking_assert (jfunc->type == IPA_JF_CONST);
4502fe8d
MJ
209 return jfunc->value.constant.value;
210}
211
212static inline struct ipa_cst_ref_desc *
213ipa_get_jf_constant_rdesc (struct ipa_jump_func *jfunc)
214{
215 gcc_checking_assert (jfunc->type == IPA_JF_CONST);
216 return jfunc->value.constant.rdesc;
7b872d9e
MJ
217}
218
219/* Return the operand of a pass through jmp function JFUNC. */
220
221static inline tree
222ipa_get_jf_pass_through_operand (struct ipa_jump_func *jfunc)
223{
224 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
225 return jfunc->value.pass_through.operand;
226}
227
228/* Return the number of the caller's formal parameter that a pass through jump
229 function JFUNC refers to. */
230
231static inline int
232ipa_get_jf_pass_through_formal_id (struct ipa_jump_func *jfunc)
233{
234 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
235 return jfunc->value.pass_through.formal_id;
236}
237
238/* Return operation of a pass through jump function JFUNC. */
239
240static inline enum tree_code
241ipa_get_jf_pass_through_operation (struct ipa_jump_func *jfunc)
242{
243 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
244 return jfunc->value.pass_through.operation;
245}
246
b8f6e610 247/* Return the agg_preserved flag of a pass through jump function JFUNC. */
8b7773a4
MJ
248
249static inline bool
250ipa_get_jf_pass_through_agg_preserved (struct ipa_jump_func *jfunc)
251{
252 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
253 return jfunc->value.pass_through.agg_preserved;
254}
255
44210a96
MJ
256/* Return true if pass through jump function JFUNC preserves type
257 information. */
b8f6e610
MJ
258
259static inline bool
260ipa_get_jf_pass_through_type_preserved (struct ipa_jump_func *jfunc)
261{
262 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
44210a96 263 return jfunc->value.pass_through.agg_preserved;
b8f6e610
MJ
264}
265
7b872d9e
MJ
266/* Return the offset of an ancestor jump function JFUNC. */
267
268static inline HOST_WIDE_INT
269ipa_get_jf_ancestor_offset (struct ipa_jump_func *jfunc)
270{
271 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
272 return jfunc->value.ancestor.offset;
273}
274
7b872d9e
MJ
275/* Return the number of the caller's formal parameter that an ancestor jump
276 function JFUNC refers to. */
277
278static inline int
279ipa_get_jf_ancestor_formal_id (struct ipa_jump_func *jfunc)
280{
281 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
282 return jfunc->value.ancestor.formal_id;
283}
284
b8f6e610 285/* Return the agg_preserved flag of an ancestor jump function JFUNC. */
7b872d9e 286
8b7773a4
MJ
287static inline bool
288ipa_get_jf_ancestor_agg_preserved (struct ipa_jump_func *jfunc)
7b872d9e 289{
8b7773a4
MJ
290 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
291 return jfunc->value.ancestor.agg_preserved;
7b872d9e
MJ
292}
293
44210a96 294/* Return true if ancestor jump function JFUNC presrves type information. */
b8f6e610
MJ
295
296static inline bool
297ipa_get_jf_ancestor_type_preserved (struct ipa_jump_func *jfunc)
298{
299 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
44210a96 300 return jfunc->value.ancestor.agg_preserved;
b8f6e610
MJ
301}
302
310bc633 303/* Summary describing a single formal parameter. */
b258210c 304
f65f1ae3 305struct GTY(()) ipa_param_descriptor
f8e2a1ed 306{
209ca542
PK
307 /* In analysis and modification phase, this is the PARAM_DECL of this
308 parameter, in IPA LTO phase, this is the type of the the described
309 parameter or NULL if not known. Do not read this field directly but
310 through ipa_get_param and ipa_get_type as appropriate. */
311 tree decl_or_type;
4502fe8d
MJ
312 /* If all uses of the parameter are described by ipa-prop structures, this
313 says how many there are. If any use could not be described by means of
314 ipa-prop structures, this is IPA_UNDESCRIBED_USE. */
315 int controlled_uses;
0e8853ee 316 unsigned int move_cost : 31;
339f49ec
JH
317 /* The parameter is used. */
318 unsigned used : 1;
f8e2a1ed
MJ
319};
320
dcd416e3
MJ
321/* ipa_node_params stores information related to formal parameters of functions
322 and some other information for interprocedural passes that operate on
323 parameters (such as ipa-cp). */
310bc633 324
6c1dae73 325class GTY((for_user)) ipa_node_params
518dc859 326{
6c1dae73 327public:
e806796d
ML
328 /* Default constructor. */
329 ipa_node_params ();
330
331 /* Default destructor. */
332 ~ipa_node_params ();
333
310bc633
MJ
334 /* Information about individual formal parameters that are gathered when
335 summaries are generated. */
f65f1ae3 336 vec<ipa_param_descriptor, va_gc> *descriptors;
310bc633
MJ
337 /* Pointer to an array of structures describing individual formal
338 parameters. */
99b1c316 339 class ipcp_param_lattices * GTY((skip)) lattices;
310bc633
MJ
340 /* Only for versioned nodes this field would not be NULL,
341 it points to the node that IPA cp cloned from. */
f65f1ae3 342 struct cgraph_node * GTY((skip)) ipcp_orig_node;
44210a96
MJ
343 /* If this node is an ipa-cp clone, these are the known constants that
344 describe what it has been specialized for. */
f65f1ae3 345 vec<tree> GTY((skip)) known_csts;
44210a96
MJ
346 /* If this node is an ipa-cp clone, these are the known polymorphic contexts
347 that describe what it has been specialized for. */
f65f1ae3 348 vec<ipa_polymorphic_call_context> GTY((skip)) known_contexts;
8aab5218
MJ
349 /* Whether the param uses analysis and jump function computation has already
350 been performed. */
351 unsigned analysis_done : 1;
310bc633 352 /* Whether the function is enqueued in ipa-cp propagation stack. */
448f65db 353 unsigned node_enqueued : 1;
310bc633
MJ
354 /* Whether we should create a specialized version based on values that are
355 known to be constant in all contexts. */
eb20b778
MJ
356 unsigned do_clone_for_all_contexts : 1;
357 /* Set if this is an IPA-CP clone for all contexts. */
358 unsigned is_all_contexts_clone : 1;
310bc633
MJ
359 /* Node has been completely replaced by clones and will be removed after
360 ipa-cp is finished. */
361 unsigned node_dead : 1;
af21714c
MJ
362 /* Node is involved in a recursion, potentionally indirect. */
363 unsigned node_within_scc : 1;
364 /* Node is calling a private function called only once. */
365 unsigned node_calling_single_call : 1;
7e729474
ML
366 /* False when there is something makes versioning impossible. */
367 unsigned versionable : 1;
518dc859
RL
368};
369
e806796d
ML
370inline
371ipa_node_params::ipa_node_params ()
372: descriptors (NULL), lattices (NULL), ipcp_orig_node (NULL),
373 known_csts (vNULL), known_contexts (vNULL), analysis_done (0),
374 node_enqueued (0), do_clone_for_all_contexts (0), is_all_contexts_clone (0),
375 node_dead (0), node_within_scc (0), node_calling_single_call (0),
376 versionable (0)
377{
378}
379
380inline
381ipa_node_params::~ipa_node_params ()
382{
383 free (lattices);
384 known_csts.release ();
385 known_contexts.release ();
386}
387
ff302741
PB
388/* Intermediate information that we get from alias analysis about a particular
389 parameter in a particular basic_block. When a parameter or the memory it
56b40062
MJ
390 references is marked modified, we use that information in all dominated
391 blocks without consulting alias analysis oracle. */
ff302741 392
56b40062 393struct ipa_param_aa_status
ff302741
PB
394{
395 /* Set when this structure contains meaningful information. If not, the
396 structure describing a dominating BB should be used instead. */
397 bool valid;
398
399 /* Whether we have seen something which might have modified the data in
400 question. PARM is for the parameter itself, REF is for data it points to
401 but using the alias type of individual accesses and PT is the same thing
402 but for computing aggregate pass-through functions using a very inclusive
403 ao_ref. */
404 bool parm_modified, ref_modified, pt_modified;
405};
406
407/* Information related to a given BB that used only when looking at function
408 body. */
409
410struct ipa_bb_info
411{
412 /* Call graph edges going out of this BB. */
413 vec<cgraph_edge *> cg_edges;
414 /* Alias analysis statuses of each formal parameter at this bb. */
56b40062 415 vec<ipa_param_aa_status> param_aa_statuses;
ff302741
PB
416};
417
418/* Structure with global information that is only used when looking at function
419 body. */
420
56b40062 421struct ipa_func_body_info
ff302741
PB
422{
423 /* The node that is being analyzed. */
424 cgraph_node *node;
425
426 /* Its info. */
99b1c316 427 class ipa_node_params *info;
ff302741
PB
428
429 /* Information about individual BBs. */
430 vec<ipa_bb_info> bb_infos;
431
432 /* Number of parameters. */
433 int param_count;
434
c628d1c3
MJ
435 /* Number of statements we are still allowed to walked by when analyzing this
436 function. */
437 unsigned int aa_walk_budget;
ff302741
PB
438};
439
dcd416e3
MJ
440/* ipa_node_params access functions. Please use these to access fields that
441 are or will be shared among various passes. */
442
dcd416e3 443/* Return the number of formal parameters. */
be95e2b9 444
dcd416e3 445static inline int
99b1c316 446ipa_get_param_count (class ipa_node_params *info)
dcd416e3 447{
f65f1ae3 448 return vec_safe_length (info->descriptors);
dcd416e3
MJ
449}
450
f8e2a1ed
MJ
451/* Return the declaration of Ith formal parameter of the function corresponding
452 to INFO. Note there is no setter function as this array is built just once
209ca542
PK
453 using ipa_initialize_node_params. This function should not be called in
454 WPA. */
be95e2b9 455
dcd416e3 456static inline tree
99b1c316 457ipa_get_param (class ipa_node_params *info, int i)
dcd416e3 458{
f65f1ae3 459 gcc_checking_assert (info->descriptors);
f65f1ae3 460 tree t = (*info->descriptors)[i].decl_or_type;
209ca542
PK
461 gcc_checking_assert (TREE_CODE (t) == PARM_DECL);
462 return t;
463}
464
465/* Return the type of Ith formal parameter of the function corresponding
466 to INFO if it is known or NULL if not. */
467
468static inline tree
99b1c316 469ipa_get_type (class ipa_node_params *info, int i)
209ca542 470{
e5cf5e11
PK
471 if (vec_safe_length (info->descriptors) <= (unsigned) i)
472 return NULL;
f65f1ae3 473 tree t = (*info->descriptors)[i].decl_or_type;
209ca542
PK
474 if (!t)
475 return NULL;
476 if (TYPE_P (t))
477 return t;
478 gcc_checking_assert (TREE_CODE (t) == PARM_DECL);
479 return TREE_TYPE (t);
339f49ec
JH
480}
481
0e8853ee
JH
482/* Return the move cost of Ith formal parameter of the function corresponding
483 to INFO. */
484
485static inline int
99b1c316 486ipa_get_param_move_cost (class ipa_node_params *info, int i)
0e8853ee 487{
f65f1ae3
MJ
488 gcc_checking_assert (info->descriptors);
489 return (*info->descriptors)[i].move_cost;
0e8853ee
JH
490}
491
310bc633
MJ
492/* Set the used flag corresponding to the Ith formal parameter of the function
493 associated with INFO to VAL. */
3949c4a7 494
310bc633 495static inline void
99b1c316 496ipa_set_param_used (class ipa_node_params *info, int i, bool val)
3949c4a7 497{
f65f1ae3
MJ
498 gcc_checking_assert (info->descriptors);
499 (*info->descriptors)[i].used = val;
3949c4a7
MJ
500}
501
4502fe8d
MJ
502/* Return how many uses described by ipa-prop a parameter has or
503 IPA_UNDESCRIBED_USE if there is a use that is not described by these
504 structures. */
505static inline int
99b1c316 506ipa_get_controlled_uses (class ipa_node_params *info, int i)
4502fe8d 507{
f65f1ae3
MJ
508 /* FIXME: introducing speculation causes out of bounds access here. */
509 if (vec_safe_length (info->descriptors) > (unsigned)i)
510 return (*info->descriptors)[i].controlled_uses;
5ce97055 511 return IPA_UNDESCRIBED_USE;
4502fe8d
MJ
512}
513
514/* Set the controlled counter of a given parameter. */
515
516static inline void
99b1c316 517ipa_set_controlled_uses (class ipa_node_params *info, int i, int val)
4502fe8d 518{
f65f1ae3
MJ
519 gcc_checking_assert (info->descriptors);
520 (*info->descriptors)[i].controlled_uses = val;
4502fe8d
MJ
521}
522
310bc633
MJ
523/* Return the used flag corresponding to the Ith formal parameter of the
524 function associated with INFO. */
3949c4a7
MJ
525
526static inline bool
99b1c316 527ipa_is_param_used (class ipa_node_params *info, int i)
3949c4a7 528{
f65f1ae3
MJ
529 gcc_checking_assert (info->descriptors);
530 return (*info->descriptors)[i].used;
3949c4a7
MJ
531}
532
2c9561b5
MJ
533/* Information about replacements done in aggregates for a given node (each
534 node has its linked list). */
535struct GTY(()) ipa_agg_replacement_value
536{
537 /* Next item in the linked list. */
538 struct ipa_agg_replacement_value *next;
539 /* Offset within the aggregate. */
540 HOST_WIDE_INT offset;
541 /* The constant value. */
542 tree value;
543 /* The paramter index. */
544 int index;
7b920a9a
MJ
545 /* Whether the value was passed by reference. */
546 bool by_ref;
2c9561b5
MJ
547};
548
04be694e
MJ
549/* Structure holding information for the transformation phase of IPA-CP. */
550
9d3e0adc 551struct GTY(()) ipcp_transformation
04be694e
MJ
552{
553 /* Linked list of known aggregate values. */
554 ipa_agg_replacement_value *agg_values;
209ca542 555 /* Known bits information. */
86cd0334 556 vec<ipa_bits *, va_gc> *bits;
8bc5448f
KV
557 /* Value range information. */
558 vec<ipa_vr, va_gc> *m_vr;
04be694e 559};
2c9561b5
MJ
560
561void ipa_set_node_agg_value_chain (struct cgraph_node *node,
562 struct ipa_agg_replacement_value *aggvals);
9d3e0adc 563void ipcp_transformation_initialize (void);
12e088ba 564void ipcp_free_transformation_sum (void);
2c9561b5 565
93c594a3
MJ
566/* ipa_edge_args stores information related to a callsite and particularly its
567 arguments. It can be accessed by the IPA_EDGE_REF macro. */
6fe906a3
MJ
568
569class GTY((for_user)) ipa_edge_args
518dc859 570{
6fe906a3
MJ
571 public:
572
573 /* Default constructor. */
574 ipa_edge_args () : jump_functions (NULL), polymorphic_call_contexts (NULL)
575 {}
576
577 /* Destructor. */
578 ~ipa_edge_args ()
579 {
580 vec_free (jump_functions);
581 vec_free (polymorphic_call_contexts);
582 }
583
584 /* Vectors of the callsite's jump function and polymorphic context
585 information of each parameter. */
84562394 586 vec<ipa_jump_func, va_gc> *jump_functions;
5ce97055 587 vec<ipa_polymorphic_call_context, va_gc> *polymorphic_call_contexts;
84562394 588};
518dc859 589
dcd416e3
MJ
590/* ipa_edge_args access functions. Please use these to access fields that
591 are or will be shared among various passes. */
592
dcd416e3 593/* Return the number of actual arguments. */
be95e2b9 594
dcd416e3 595static inline int
99b1c316 596ipa_get_cs_argument_count (class ipa_edge_args *args)
dcd416e3 597{
9771b263 598 return vec_safe_length (args->jump_functions);
dcd416e3
MJ
599}
600
601/* Returns a pointer to the jump function for the ith argument. Please note
602 there is no setter function as jump functions are all set up in
603 ipa_compute_jump_functions. */
be95e2b9 604
dcd416e3 605static inline struct ipa_jump_func *
99b1c316 606ipa_get_ith_jump_func (class ipa_edge_args *args, int i)
dcd416e3 607{
9771b263 608 return &(*args->jump_functions)[i];
dcd416e3
MJ
609}
610
5ce97055
JH
611/* Returns a pointer to the polymorphic call context for the ith argument.
612 NULL if contexts are not computed. */
99b1c316
MS
613static inline class ipa_polymorphic_call_context *
614ipa_get_ith_polymorhic_call_context (class ipa_edge_args *args, int i)
5ce97055
JH
615{
616 if (!args->polymorphic_call_contexts)
617 return NULL;
618 return &(*args->polymorphic_call_contexts)[i];
619}
620
9a1e784a 621/* Function summary for ipa_node_params. */
f65f1ae3 622class GTY((user)) ipa_node_params_t: public function_summary <ipa_node_params *>
dd912cb8
ML
623{
624public:
f65f1ae3
MJ
625 ipa_node_params_t (symbol_table *table, bool ggc):
626 function_summary<ipa_node_params *> (table, ggc) { }
771578a0 627
dd912cb8
ML
628 /* Hook that is called by summary when a node is duplicated. */
629 virtual void duplicate (cgraph_node *node,
630 cgraph_node *node2,
631 ipa_node_params *data,
632 ipa_node_params *data2);
633};
634
6fe906a3
MJ
635/* Summary to manange ipa_edge_args structures. */
636
637class GTY((user)) ipa_edge_args_sum_t : public call_summary <ipa_edge_args *>
638{
639 public:
640 ipa_edge_args_sum_t (symbol_table *table, bool ggc)
641 : call_summary<ipa_edge_args *> (table, ggc) { }
642
a33c028e
JH
643 void remove (cgraph_edge *edge)
644 {
645 call_summary <ipa_edge_args *>::remove (edge);
646 }
647
f658ad30 648 /* Hook that is called by summary when an edge is removed. */
6fe906a3
MJ
649 virtual void remove (cgraph_edge *cs, ipa_edge_args *args);
650 /* Hook that is called by summary when an edge is duplicated. */
651 virtual void duplicate (cgraph_edge *src,
652 cgraph_edge *dst,
653 ipa_edge_args *old_args,
654 ipa_edge_args *new_args);
655};
656
dd912cb8 657/* Function summary where the parameter infos are actually stored. */
f65f1ae3 658extern GTY(()) ipa_node_params_t * ipa_node_params_sum;
6fe906a3
MJ
659/* Call summary to store information about edges such as jump functions. */
660extern GTY(()) ipa_edge_args_sum_t *ipa_edge_args_sum;
f65f1ae3 661
9d3e0adc
ML
662/* Function summary for IPA-CP transformation. */
663class ipcp_transformation_t
664: public function_summary<ipcp_transformation *>
665{
666public:
667 ipcp_transformation_t (symbol_table *table, bool ggc):
668 function_summary<ipcp_transformation *> (table, ggc) {}
669
670 ~ipcp_transformation_t () {}
671
672 static ipcp_transformation_t *create_ggc (symbol_table *symtab)
673 {
674 ipcp_transformation_t *summary
675 = new (ggc_cleared_alloc <ipcp_transformation_t> ())
676 ipcp_transformation_t (symtab, true);
677 return summary;
678 }
679};
680
681/* Function summary where the IPA CP transformations are actually stored. */
682extern GTY(()) function_summary <ipcp_transformation *> *ipcp_transformation_sum;
f65f1ae3 683
771578a0
MJ
684/* Return the associated parameter/argument info corresponding to the given
685 node/edge. */
99353fcf 686#define IPA_NODE_REF(NODE) (ipa_node_params_sum->get_create (NODE))
a33c028e
JH
687#define IPA_EDGE_REF(EDGE) (ipa_edge_args_sum->get (EDGE))
688#define IPA_EDGE_REF_GET_CREATE(EDGE) (ipa_edge_args_sum->get_create (EDGE))
771578a0
MJ
689/* This macro checks validity of index returned by
690 ipa_get_param_decl_index function. */
691#define IS_VALID_JUMP_FUNC_INDEX(I) ((I) != -1)
692
693/* Creating and freeing ipa_node_params and ipa_edge_args. */
694void ipa_create_all_node_params (void);
695void ipa_create_all_edge_args (void);
86cd0334 696void ipa_check_create_edge_args (void);
771578a0
MJ
697void ipa_free_all_node_params (void);
698void ipa_free_all_edge_args (void);
e33c6cd6
MJ
699void ipa_free_all_structures_after_ipa_cp (void);
700void ipa_free_all_structures_after_iinln (void);
dd912cb8 701
771578a0 702void ipa_register_cgraph_hooks (void);
fd29c024 703int count_formal_params (tree fndecl);
771578a0
MJ
704
705/* This function ensures the array of node param infos is big enough to
be95e2b9
MJ
706 accommodate a structure for all nodes and reallocates it if not. */
707
771578a0
MJ
708static inline void
709ipa_check_create_node_params (void)
710{
dd912cb8 711 if (!ipa_node_params_sum)
f65f1ae3
MJ
712 ipa_node_params_sum
713 = (new (ggc_cleared_alloc <ipa_node_params_t> ())
714 ipa_node_params_t (symtab, true));
771578a0
MJ
715}
716
6fe906a3
MJ
717/* Returns true if edge summary contains a record for EDGE. The main purpose
718 of this function is that debug dumping function can check info availability
719 without causing allocations. */
be95e2b9 720
0eae6bab
MJ
721static inline bool
722ipa_edge_args_info_available_for_edge_p (struct cgraph_edge *edge)
723{
6fe906a3 724 return ipa_edge_args_sum->exists (edge);
0eae6bab
MJ
725}
726
9d3e0adc 727static inline ipcp_transformation *
04be694e
MJ
728ipcp_get_transformation_summary (cgraph_node *node)
729{
9d3e0adc 730 if (ipcp_transformation_sum == NULL)
04be694e 731 return NULL;
9d3e0adc
ML
732
733 return ipcp_transformation_sum->get (node);
04be694e
MJ
734}
735
2c9561b5
MJ
736/* Return the aggregate replacements for NODE, if there are any. */
737
738static inline struct ipa_agg_replacement_value *
04be694e 739ipa_get_agg_replacements_for_node (cgraph_node *node)
2c9561b5 740{
9d3e0adc 741 ipcp_transformation *ts = ipcp_get_transformation_summary (node);
04be694e 742 return ts ? ts->agg_values : NULL;
2c9561b5
MJ
743}
744
f8e2a1ed
MJ
745/* Function formal parameters related computations. */
746void ipa_initialize_node_params (struct cgraph_node *node);
f8e2a1ed 747bool ipa_propagate_indirect_call_infos (struct cgraph_edge *cs,
d52f5295 748 vec<cgraph_edge *> *new_edges);
518dc859 749
3949c4a7 750/* Indirect edge and binfo processing. */
d2d668fb 751tree ipa_get_indirect_edge_target (struct cgraph_edge *ie,
9771b263 752 vec<tree> ,
44210a96 753 vec<ipa_polymorphic_call_context>,
231b4916
JH
754 vec<ipa_agg_jump_function_p>,
755 bool *);
5ce97055
JH
756struct cgraph_edge *ipa_make_edge_direct_to_target (struct cgraph_edge *, tree,
757 bool speculative = false);
72972c22 758tree ipa_impossible_devirt_target (struct cgraph_edge *, tree);
86cd0334
MJ
759ipa_bits *ipa_get_ipa_bits_for_value (const widest_int &value,
760 const widest_int &mask);
761
3949c4a7 762
310bc633
MJ
763/* Functions related to both. */
764void ipa_analyze_node (struct cgraph_node *);
3949c4a7 765
8b7773a4 766/* Aggregate jump function related functions. */
91bb9f80
MJ
767tree ipa_find_agg_cst_for_param (struct ipa_agg_jump_function *agg, tree scalar,
768 HOST_WIDE_INT offset, bool by_ref,
769 bool *from_global_constant = NULL);
770bool ipa_load_from_parm_agg (struct ipa_func_body_info *fbi,
f65f1ae3 771 vec<ipa_param_descriptor, va_gc> *descriptors,
91bb9f80 772 gimple *stmt, tree op, int *index_p,
86003645 773 HOST_WIDE_INT *offset_p, poly_int64 *size_p,
91bb9f80 774 bool *by_ref, bool *guaranteed_unmodified = NULL);
8b7773a4 775
518dc859 776/* Debugging interface. */
ca30a539
JH
777void ipa_print_node_params (FILE *, struct cgraph_node *node);
778void ipa_print_all_params (FILE *);
3e293154
MJ
779void ipa_print_node_jump_functions (FILE *f, struct cgraph_node *node);
780void ipa_print_all_jump_functions (FILE * f);
310bc633
MJ
781void ipcp_verify_propagated_values (void);
782
2651e637
ML
783template <typename value>
784class ipcp_value;
785
fb0b2914
ML
786extern object_allocator<ipcp_value<tree> > ipcp_cst_values_pool;
787extern object_allocator<ipcp_value<ipa_polymorphic_call_context> >
2651e637
ML
788 ipcp_poly_ctx_values_pool;
789
790template <typename valtype>
99b1c316 791struct ipcp_value_source;
2651e637 792
fb0b2914 793extern object_allocator<ipcp_value_source<tree> > ipcp_sources_pool;
2651e637 794
99b1c316 795struct ipcp_agg_lattice;
2651e637 796
fb0b2914 797extern object_allocator<ipcp_agg_lattice> ipcp_agg_lattice_pool;
518dc859 798
2c9561b5
MJ
799void ipa_dump_agg_replacement_values (FILE *f,
800 struct ipa_agg_replacement_value *av);
f27c1867 801void ipa_prop_write_jump_functions (void);
fb3f88cc 802void ipa_prop_read_jump_functions (void);
04be694e
MJ
803void ipcp_write_transformation_summaries (void);
804void ipcp_read_transformation_summaries (void);
99b1c316
MS
805int ipa_get_param_decl_index (class ipa_node_params *, tree);
806tree ipa_value_from_jfunc (class ipa_node_params *info,
e5cf5e11 807 struct ipa_jump_func *jfunc, tree type);
2c9561b5 808unsigned int ipcp_transform_function (struct cgraph_node *node);
44210a96
MJ
809ipa_polymorphic_call_context ipa_context_from_jfunc (ipa_node_params *,
810 cgraph_edge *,
811 int,
812 ipa_jump_func *);
99b1c316 813void ipa_dump_param (FILE *, class ipa_node_params *info, int i);
c3431191 814void ipa_release_body_info (struct ipa_func_body_info *);
5d5f1e95 815tree ipa_get_callee_param_type (struct cgraph_edge *e, int i);
fb3f88cc 816
3f84bf08 817/* From tree-sra.c: */
f7ed3195 818tree build_ref_for_offset (location_t, tree, poly_int64, bool, tree,
e4b5cace 819 gimple_stmt_iterator *, bool);
3f84bf08 820
3edf64aa
DM
821/* In ipa-cp.c */
822void ipa_cp_c_finalize (void);
823
518dc859 824#endif /* IPA_PROP_H */