]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/ipa-prop.h
* doc/extend.texi (Common Function Attributes): Clarify
[thirdparty/gcc.git] / gcc / ipa-prop.h
CommitLineData
3b22db66 1/* Interprocedural analyses.
fbd26352 2 Copyright (C) 2005-2019 Free Software Foundation, Inc.
3b22db66 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
8c4c00c1 8Software Foundation; either version 3, or (at your option) any later
3b22db66 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
8c4c00c1 17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
3b22db66 19
20#ifndef IPA_PROP_H
21#define IPA_PROP_H
22
3b22db66 23/* The following definitions and interfaces are used by
ba3a7ba0 24 interprocedural analyses or parameters. */
25
096295f6 26#define IPA_UNDESCRIBED_USE -1
27
ba3a7ba0 28/* ipa-prop.c stuff (ipa-cp, indirect inlining): */
3b22db66 29
1917e945 30/* A jump function for a callsite represents the values passed as actual
821d0e0f 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 :
5215027d 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
6378ffb3 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
47ae02b7 45 getting addresses of ancestor fields in C++
6378ffb3 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
6378ffb3 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. */
5215027d 57
3b22db66 58enum jump_func_type
59{
ba3a7ba0 60 IPA_JF_UNKNOWN = 0, /* newly allocated and zeroed jump functions default */
6378ffb3 61 IPA_JF_CONST, /* represented by field costant */
6378ffb3 62 IPA_JF_PASS_THROUGH, /* represented by field pass_through */
63 IPA_JF_ANCESTOR /* represented by field ancestor */
3b22db66 64};
65
096295f6 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
5215027d 77/* Structure holding data required to describe a pass-through jump function. */
78
8867b500 79struct GTY(()) ipa_pass_through_data
5215027d 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;
0d491188 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. */
ad4a8b28 97 unsigned agg_preserved : 1;
5215027d 98};
99
6378ffb3 100/* Structure holding data required to describe an ancestor pass-through
101 jump function. */
5215027d 102
8867b500 103struct GTY(()) ipa_ancestor_jf_data
5215027d 104{
105 /* Offset of the field representing the ancestor. */
106 HOST_WIDE_INT offset;
5215027d 107 /* Number of the caller's formal parameter being passed. */
108 int formal_id;
0d491188 109 /* Flag with the same meaning like agg_preserve in ipa_pass_through_data. */
ad4a8b28 110 unsigned agg_preserved : 1;
5215027d 111};
112
0d491188 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
a04e8d62 121 fulfill is_gimple_ip_invariant. */
0d491188 122
b3e7c666 123struct GTY(()) ipa_agg_jf_item
0d491188 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;
b3e7c666 130};
0d491188 131
0d491188 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
f8daee9b 137{
0d491188 138 /* Description of the individual items. */
b3e7c666 139 vec<ipa_agg_jf_item, va_gc> *items;
0d491188 140 /* True if the data was passed by reference (as opposed to by value). */
141 bool by_ref;
f8daee9b 142};
143
0d491188 144typedef struct ipa_agg_jump_function *ipa_agg_jump_function_p;
0d491188 145
a54071b2 146/* Information about zero/non-zero bits. */
147struct GTY(()) ipa_bits
148{
149 /* The propagated value. */
150 widest_int value;
151 /* Mask corresponding to the value.
152 Similar to ccp_lattice_t, if xth bit of mask is 0,
153 implies xth bit of value is constant. */
154 widest_int mask;
a54071b2 155};
156
25a8e007 157/* Info about value ranges. */
97cb825b 158
25a8e007 159struct GTY(()) ipa_vr
160{
161 /* The data fields below are valid only if known is true. */
162 bool known;
be44111e 163 enum value_range_kind type;
25a8e007 164 wide_int min;
165 wide_int max;
166};
167
1917e945 168/* A jump function for a callsite represents the values passed as actual
169 arguments of the callsite. See enum jump_func_type for the various
3b22db66 170 types of jump functions supported. */
b3e7c666 171struct GTY (()) ipa_jump_func
3b22db66 172{
0d491188 173 /* Aggregate contants description. See struct ipa_agg_jump_function and its
174 description. */
175 struct ipa_agg_jump_function agg;
176
97cb825b 177 /* Information about zero/non-zero bits. The pointed to structure is shared
178 betweed different jump functions. Use ipa_set_jfunc_bits to set this
179 field. */
180 struct ipa_bits *bits;
a54071b2 181
72b16d90 182 /* Information about value range, containing valid data only when vr_known is
97cb825b 183 true. The pointed to structure is shared betweed different jump
184 functions. Use ipa_set_jfunc_vr to set this field. */
a1054504 185 struct value_range_base *m_vr;
25a8e007 186
3b22db66 187 enum jump_func_type type;
8867b500 188 /* Represents a value of a jump function. pass_through is used only in jump
189 function context. constant represents the actual constant in constant jump
190 functions and member_cst holds constant c++ member functions. */
191 union jump_func_value
192 {
096295f6 193 struct ipa_constant_data GTY ((tag ("IPA_JF_CONST"))) constant;
8867b500 194 struct ipa_pass_through_data GTY ((tag ("IPA_JF_PASS_THROUGH"))) pass_through;
195 struct ipa_ancestor_jf_data GTY ((tag ("IPA_JF_ANCESTOR"))) ancestor;
8867b500 196 } GTY ((desc ("%1.type"))) value;
b3e7c666 197};
b22832dc 198
3b22db66 199
4fa83f96 200/* Return the constant stored in a constant jump functin JFUNC. */
201
202static inline tree
203ipa_get_jf_constant (struct ipa_jump_func *jfunc)
204{
205 gcc_checking_assert (jfunc->type == IPA_JF_CONST);
096295f6 206 return jfunc->value.constant.value;
207}
208
209static inline struct ipa_cst_ref_desc *
210ipa_get_jf_constant_rdesc (struct ipa_jump_func *jfunc)
211{
212 gcc_checking_assert (jfunc->type == IPA_JF_CONST);
213 return jfunc->value.constant.rdesc;
4fa83f96 214}
215
216/* Return the operand of a pass through jmp function JFUNC. */
217
218static inline tree
219ipa_get_jf_pass_through_operand (struct ipa_jump_func *jfunc)
220{
221 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
222 return jfunc->value.pass_through.operand;
223}
224
225/* Return the number of the caller's formal parameter that a pass through jump
226 function JFUNC refers to. */
227
228static inline int
229ipa_get_jf_pass_through_formal_id (struct ipa_jump_func *jfunc)
230{
231 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
232 return jfunc->value.pass_through.formal_id;
233}
234
235/* Return operation of a pass through jump function JFUNC. */
236
237static inline enum tree_code
238ipa_get_jf_pass_through_operation (struct ipa_jump_func *jfunc)
239{
240 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
241 return jfunc->value.pass_through.operation;
242}
243
ad4a8b28 244/* Return the agg_preserved flag of a pass through jump function JFUNC. */
0d491188 245
246static inline bool
247ipa_get_jf_pass_through_agg_preserved (struct ipa_jump_func *jfunc)
248{
249 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
250 return jfunc->value.pass_through.agg_preserved;
251}
252
245ab191 253/* Return true if pass through jump function JFUNC preserves type
254 information. */
ad4a8b28 255
256static inline bool
257ipa_get_jf_pass_through_type_preserved (struct ipa_jump_func *jfunc)
258{
259 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
245ab191 260 return jfunc->value.pass_through.agg_preserved;
ad4a8b28 261}
262
4fa83f96 263/* Return the offset of an ancestor jump function JFUNC. */
264
265static inline HOST_WIDE_INT
266ipa_get_jf_ancestor_offset (struct ipa_jump_func *jfunc)
267{
268 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
269 return jfunc->value.ancestor.offset;
270}
271
4fa83f96 272/* Return the number of the caller's formal parameter that an ancestor jump
273 function JFUNC refers to. */
274
275static inline int
276ipa_get_jf_ancestor_formal_id (struct ipa_jump_func *jfunc)
277{
278 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
279 return jfunc->value.ancestor.formal_id;
280}
281
ad4a8b28 282/* Return the agg_preserved flag of an ancestor jump function JFUNC. */
4fa83f96 283
0d491188 284static inline bool
285ipa_get_jf_ancestor_agg_preserved (struct ipa_jump_func *jfunc)
4fa83f96 286{
0d491188 287 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
288 return jfunc->value.ancestor.agg_preserved;
4fa83f96 289}
290
245ab191 291/* Return true if ancestor jump function JFUNC presrves type information. */
ad4a8b28 292
293static inline bool
294ipa_get_jf_ancestor_type_preserved (struct ipa_jump_func *jfunc)
295{
296 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
245ab191 297 return jfunc->value.ancestor.agg_preserved;
ad4a8b28 298}
299
821d0e0f 300/* Summary describing a single formal parameter. */
6378ffb3 301
7af25a10 302struct GTY(()) ipa_param_descriptor
3f2ff969 303{
a54071b2 304 /* In analysis and modification phase, this is the PARAM_DECL of this
305 parameter, in IPA LTO phase, this is the type of the the described
306 parameter or NULL if not known. Do not read this field directly but
307 through ipa_get_param and ipa_get_type as appropriate. */
308 tree decl_or_type;
096295f6 309 /* If all uses of the parameter are described by ipa-prop structures, this
310 says how many there are. If any use could not be described by means of
311 ipa-prop structures, this is IPA_UNDESCRIBED_USE. */
312 int controlled_uses;
09ab6335 313 unsigned int move_cost : 31;
bc1b408a 314 /* The parameter is used. */
315 unsigned used : 1;
3f2ff969 316};
317
3889f2e2 318/* ipa_node_params stores information related to formal parameters of functions
319 and some other information for interprocedural passes that operate on
320 parameters (such as ipa-cp). */
821d0e0f 321
7af25a10 322struct GTY((for_user)) ipa_node_params
3b22db66 323{
3ca1e19c 324 /* Default constructor. */
325 ipa_node_params ();
326
327 /* Default destructor. */
328 ~ipa_node_params ();
329
821d0e0f 330 /* Information about individual formal parameters that are gathered when
331 summaries are generated. */
7af25a10 332 vec<ipa_param_descriptor, va_gc> *descriptors;
821d0e0f 333 /* Pointer to an array of structures describing individual formal
334 parameters. */
7af25a10 335 struct ipcp_param_lattices * GTY((skip)) lattices;
821d0e0f 336 /* Only for versioned nodes this field would not be NULL,
337 it points to the node that IPA cp cloned from. */
7af25a10 338 struct cgraph_node * GTY((skip)) ipcp_orig_node;
245ab191 339 /* If this node is an ipa-cp clone, these are the known constants that
340 describe what it has been specialized for. */
7af25a10 341 vec<tree> GTY((skip)) known_csts;
245ab191 342 /* If this node is an ipa-cp clone, these are the known polymorphic contexts
343 that describe what it has been specialized for. */
7af25a10 344 vec<ipa_polymorphic_call_context> GTY((skip)) known_contexts;
24430d08 345 /* Whether the param uses analysis and jump function computation has already
346 been performed. */
347 unsigned analysis_done : 1;
821d0e0f 348 /* Whether the function is enqueued in ipa-cp propagation stack. */
609c710b 349 unsigned node_enqueued : 1;
821d0e0f 350 /* Whether we should create a specialized version based on values that are
351 known to be constant in all contexts. */
87228246 352 unsigned do_clone_for_all_contexts : 1;
353 /* Set if this is an IPA-CP clone for all contexts. */
354 unsigned is_all_contexts_clone : 1;
821d0e0f 355 /* Node has been completely replaced by clones and will be removed after
356 ipa-cp is finished. */
357 unsigned node_dead : 1;
39fcd838 358 /* Node is involved in a recursion, potentionally indirect. */
359 unsigned node_within_scc : 1;
360 /* Node is calling a private function called only once. */
361 unsigned node_calling_single_call : 1;
b8681788 362 /* False when there is something makes versioning impossible. */
363 unsigned versionable : 1;
3b22db66 364};
365
3ca1e19c 366inline
367ipa_node_params::ipa_node_params ()
368: descriptors (NULL), lattices (NULL), ipcp_orig_node (NULL),
369 known_csts (vNULL), known_contexts (vNULL), analysis_done (0),
370 node_enqueued (0), do_clone_for_all_contexts (0), is_all_contexts_clone (0),
371 node_dead (0), node_within_scc (0), node_calling_single_call (0),
372 versionable (0)
373{
374}
375
376inline
377ipa_node_params::~ipa_node_params ()
378{
379 free (lattices);
380 known_csts.release ();
381 known_contexts.release ();
382}
383
1a673ff0 384/* Intermediate information that we get from alias analysis about a particular
385 parameter in a particular basic_block. When a parameter or the memory it
9ea91b78 386 references is marked modified, we use that information in all dominated
387 blocks without consulting alias analysis oracle. */
1a673ff0 388
9ea91b78 389struct ipa_param_aa_status
1a673ff0 390{
391 /* Set when this structure contains meaningful information. If not, the
392 structure describing a dominating BB should be used instead. */
393 bool valid;
394
395 /* Whether we have seen something which might have modified the data in
396 question. PARM is for the parameter itself, REF is for data it points to
397 but using the alias type of individual accesses and PT is the same thing
398 but for computing aggregate pass-through functions using a very inclusive
399 ao_ref. */
400 bool parm_modified, ref_modified, pt_modified;
401};
402
403/* Information related to a given BB that used only when looking at function
404 body. */
405
406struct ipa_bb_info
407{
408 /* Call graph edges going out of this BB. */
409 vec<cgraph_edge *> cg_edges;
410 /* Alias analysis statuses of each formal parameter at this bb. */
9ea91b78 411 vec<ipa_param_aa_status> param_aa_statuses;
1a673ff0 412};
413
414/* Structure with global information that is only used when looking at function
415 body. */
416
9ea91b78 417struct ipa_func_body_info
1a673ff0 418{
419 /* The node that is being analyzed. */
420 cgraph_node *node;
421
422 /* Its info. */
423 struct ipa_node_params *info;
424
425 /* Information about individual BBs. */
426 vec<ipa_bb_info> bb_infos;
427
428 /* Number of parameters. */
429 int param_count;
430
915df3d8 431 /* Number of statements we are still allowed to walked by when analyzing this
432 function. */
433 unsigned int aa_walk_budget;
1a673ff0 434};
435
3889f2e2 436/* ipa_node_params access functions. Please use these to access fields that
437 are or will be shared among various passes. */
438
3889f2e2 439/* Return the number of formal parameters. */
1917e945 440
3889f2e2 441static inline int
442ipa_get_param_count (struct ipa_node_params *info)
443{
7af25a10 444 return vec_safe_length (info->descriptors);
3889f2e2 445}
446
3f2ff969 447/* Return the declaration of Ith formal parameter of the function corresponding
448 to INFO. Note there is no setter function as this array is built just once
a54071b2 449 using ipa_initialize_node_params. This function should not be called in
450 WPA. */
1917e945 451
3889f2e2 452static inline tree
3f2ff969 453ipa_get_param (struct ipa_node_params *info, int i)
3889f2e2 454{
7af25a10 455 gcc_checking_assert (info->descriptors);
09ab6335 456 gcc_checking_assert (!flag_wpa);
7af25a10 457 tree t = (*info->descriptors)[i].decl_or_type;
a54071b2 458 gcc_checking_assert (TREE_CODE (t) == PARM_DECL);
459 return t;
460}
461
462/* Return the type of Ith formal parameter of the function corresponding
463 to INFO if it is known or NULL if not. */
464
465static inline tree
466ipa_get_type (struct ipa_node_params *info, int i)
467{
944ee40d 468 if (vec_safe_length (info->descriptors) <= (unsigned) i)
469 return NULL;
7af25a10 470 tree t = (*info->descriptors)[i].decl_or_type;
a54071b2 471 if (!t)
472 return NULL;
473 if (TYPE_P (t))
474 return t;
475 gcc_checking_assert (TREE_CODE (t) == PARM_DECL);
476 return TREE_TYPE (t);
bc1b408a 477}
478
09ab6335 479/* Return the move cost of Ith formal parameter of the function corresponding
480 to INFO. */
481
482static inline int
483ipa_get_param_move_cost (struct ipa_node_params *info, int i)
484{
7af25a10 485 gcc_checking_assert (info->descriptors);
486 return (*info->descriptors)[i].move_cost;
09ab6335 487}
488
821d0e0f 489/* Set the used flag corresponding to the Ith formal parameter of the function
490 associated with INFO to VAL. */
1caef38b 491
821d0e0f 492static inline void
493ipa_set_param_used (struct ipa_node_params *info, int i, bool val)
1caef38b 494{
7af25a10 495 gcc_checking_assert (info->descriptors);
496 (*info->descriptors)[i].used = val;
1caef38b 497}
498
096295f6 499/* Return how many uses described by ipa-prop a parameter has or
500 IPA_UNDESCRIBED_USE if there is a use that is not described by these
501 structures. */
502static inline int
503ipa_get_controlled_uses (struct ipa_node_params *info, int i)
504{
7af25a10 505 /* FIXME: introducing speculation causes out of bounds access here. */
506 if (vec_safe_length (info->descriptors) > (unsigned)i)
507 return (*info->descriptors)[i].controlled_uses;
072ec6eb 508 return IPA_UNDESCRIBED_USE;
096295f6 509}
510
511/* Set the controlled counter of a given parameter. */
512
513static inline void
514ipa_set_controlled_uses (struct ipa_node_params *info, int i, int val)
515{
7af25a10 516 gcc_checking_assert (info->descriptors);
517 (*info->descriptors)[i].controlled_uses = val;
096295f6 518}
519
821d0e0f 520/* Return the used flag corresponding to the Ith formal parameter of the
521 function associated with INFO. */
1caef38b 522
523static inline bool
821d0e0f 524ipa_is_param_used (struct ipa_node_params *info, int i)
1caef38b 525{
7af25a10 526 gcc_checking_assert (info->descriptors);
527 return (*info->descriptors)[i].used;
1caef38b 528}
529
803a7988 530/* Information about replacements done in aggregates for a given node (each
531 node has its linked list). */
532struct GTY(()) ipa_agg_replacement_value
533{
534 /* Next item in the linked list. */
535 struct ipa_agg_replacement_value *next;
536 /* Offset within the aggregate. */
537 HOST_WIDE_INT offset;
538 /* The constant value. */
539 tree value;
540 /* The paramter index. */
541 int index;
c42e4f2e 542 /* Whether the value was passed by reference. */
543 bool by_ref;
803a7988 544};
545
ae7b7bc8 546/* Structure holding information for the transformation phase of IPA-CP. */
547
00637f9c 548struct GTY(()) ipcp_transformation
ae7b7bc8 549{
550 /* Linked list of known aggregate values. */
551 ipa_agg_replacement_value *agg_values;
a54071b2 552 /* Known bits information. */
97cb825b 553 vec<ipa_bits *, va_gc> *bits;
25a8e007 554 /* Value range information. */
555 vec<ipa_vr, va_gc> *m_vr;
ae7b7bc8 556};
803a7988 557
558void ipa_set_node_agg_value_chain (struct cgraph_node *node,
559 struct ipa_agg_replacement_value *aggvals);
00637f9c 560void ipcp_transformation_initialize (void);
803a7988 561
10d560f3 562/* ipa_edge_args stores information related to a callsite and particularly its
563 arguments. It can be accessed by the IPA_EDGE_REF macro. */
322dd010 564
565class GTY((for_user)) ipa_edge_args
3b22db66 566{
322dd010 567 public:
568
569 /* Default constructor. */
570 ipa_edge_args () : jump_functions (NULL), polymorphic_call_contexts (NULL)
571 {}
572
573 /* Destructor. */
574 ~ipa_edge_args ()
575 {
576 vec_free (jump_functions);
577 vec_free (polymorphic_call_contexts);
578 }
579
580 /* Vectors of the callsite's jump function and polymorphic context
581 information of each parameter. */
b3e7c666 582 vec<ipa_jump_func, va_gc> *jump_functions;
072ec6eb 583 vec<ipa_polymorphic_call_context, va_gc> *polymorphic_call_contexts;
b3e7c666 584};
3b22db66 585
3889f2e2 586/* ipa_edge_args access functions. Please use these to access fields that
587 are or will be shared among various passes. */
588
3889f2e2 589/* Return the number of actual arguments. */
1917e945 590
3889f2e2 591static inline int
592ipa_get_cs_argument_count (struct ipa_edge_args *args)
593{
f1f41a6c 594 return vec_safe_length (args->jump_functions);
3889f2e2 595}
596
597/* Returns a pointer to the jump function for the ith argument. Please note
598 there is no setter function as jump functions are all set up in
599 ipa_compute_jump_functions. */
1917e945 600
3889f2e2 601static inline struct ipa_jump_func *
602ipa_get_ith_jump_func (struct ipa_edge_args *args, int i)
603{
f1f41a6c 604 return &(*args->jump_functions)[i];
3889f2e2 605}
606
072ec6eb 607/* Returns a pointer to the polymorphic call context for the ith argument.
608 NULL if contexts are not computed. */
609static inline struct ipa_polymorphic_call_context *
610ipa_get_ith_polymorhic_call_context (struct ipa_edge_args *args, int i)
611{
612 if (!args->polymorphic_call_contexts)
613 return NULL;
614 return &(*args->polymorphic_call_contexts)[i];
615}
616
b4bae7a0 617/* Function summary for ipa_node_params. */
7af25a10 618class GTY((user)) ipa_node_params_t: public function_summary <ipa_node_params *>
2cc80ac3 619{
620public:
7af25a10 621 ipa_node_params_t (symbol_table *table, bool ggc):
622 function_summary<ipa_node_params *> (table, ggc) { }
545eff8f 623
2cc80ac3 624 /* Hook that is called by summary when a node is duplicated. */
625 virtual void duplicate (cgraph_node *node,
626 cgraph_node *node2,
627 ipa_node_params *data,
628 ipa_node_params *data2);
629};
630
322dd010 631/* Summary to manange ipa_edge_args structures. */
632
633class GTY((user)) ipa_edge_args_sum_t : public call_summary <ipa_edge_args *>
634{
635 public:
636 ipa_edge_args_sum_t (symbol_table *table, bool ggc)
637 : call_summary<ipa_edge_args *> (table, ggc) { }
638
639 /* Hook that is called by summary when an edge is duplicated. */
640 virtual void remove (cgraph_edge *cs, ipa_edge_args *args);
641 /* Hook that is called by summary when an edge is duplicated. */
642 virtual void duplicate (cgraph_edge *src,
643 cgraph_edge *dst,
644 ipa_edge_args *old_args,
645 ipa_edge_args *new_args);
646};
647
2cc80ac3 648/* Function summary where the parameter infos are actually stored. */
7af25a10 649extern GTY(()) ipa_node_params_t * ipa_node_params_sum;
322dd010 650/* Call summary to store information about edges such as jump functions. */
651extern GTY(()) ipa_edge_args_sum_t *ipa_edge_args_sum;
7af25a10 652
00637f9c 653/* Function summary for IPA-CP transformation. */
654class ipcp_transformation_t
655: public function_summary<ipcp_transformation *>
656{
657public:
658 ipcp_transformation_t (symbol_table *table, bool ggc):
659 function_summary<ipcp_transformation *> (table, ggc) {}
660
661 ~ipcp_transformation_t () {}
662
663 static ipcp_transformation_t *create_ggc (symbol_table *symtab)
664 {
665 ipcp_transformation_t *summary
666 = new (ggc_cleared_alloc <ipcp_transformation_t> ())
667 ipcp_transformation_t (symtab, true);
668 return summary;
669 }
670};
671
672/* Function summary where the IPA CP transformations are actually stored. */
673extern GTY(()) function_summary <ipcp_transformation *> *ipcp_transformation_sum;
7af25a10 674
545eff8f 675/* Return the associated parameter/argument info corresponding to the given
676 node/edge. */
b53d4f56 677#define IPA_NODE_REF(NODE) (ipa_node_params_sum->get_create (NODE))
678#define IPA_EDGE_REF(EDGE) (ipa_edge_args_sum->get_create (EDGE))
545eff8f 679/* This macro checks validity of index returned by
680 ipa_get_param_decl_index function. */
681#define IS_VALID_JUMP_FUNC_INDEX(I) ((I) != -1)
682
683/* Creating and freeing ipa_node_params and ipa_edge_args. */
684void ipa_create_all_node_params (void);
685void ipa_create_all_edge_args (void);
97cb825b 686void ipa_check_create_edge_args (void);
545eff8f 687void ipa_free_all_node_params (void);
688void ipa_free_all_edge_args (void);
799c8711 689void ipa_free_all_structures_after_ipa_cp (void);
690void ipa_free_all_structures_after_iinln (void);
2cc80ac3 691
545eff8f 692void ipa_register_cgraph_hooks (void);
09809ecc 693int count_formal_params (tree fndecl);
545eff8f 694
695/* This function ensures the array of node param infos is big enough to
1917e945 696 accommodate a structure for all nodes and reallocates it if not. */
697
545eff8f 698static inline void
699ipa_check_create_node_params (void)
700{
2cc80ac3 701 if (!ipa_node_params_sum)
7af25a10 702 ipa_node_params_sum
703 = (new (ggc_cleared_alloc <ipa_node_params_t> ())
704 ipa_node_params_t (symtab, true));
545eff8f 705}
706
322dd010 707/* Returns true if edge summary contains a record for EDGE. The main purpose
708 of this function is that debug dumping function can check info availability
709 without causing allocations. */
1917e945 710
86c96e3a 711static inline bool
712ipa_edge_args_info_available_for_edge_p (struct cgraph_edge *edge)
713{
322dd010 714 return ipa_edge_args_sum->exists (edge);
86c96e3a 715}
716
00637f9c 717static inline ipcp_transformation *
ae7b7bc8 718ipcp_get_transformation_summary (cgraph_node *node)
719{
00637f9c 720 if (ipcp_transformation_sum == NULL)
ae7b7bc8 721 return NULL;
00637f9c 722
723 return ipcp_transformation_sum->get (node);
ae7b7bc8 724}
725
803a7988 726/* Return the aggregate replacements for NODE, if there are any. */
727
728static inline struct ipa_agg_replacement_value *
ae7b7bc8 729ipa_get_agg_replacements_for_node (cgraph_node *node)
803a7988 730{
00637f9c 731 ipcp_transformation *ts = ipcp_get_transformation_summary (node);
ae7b7bc8 732 return ts ? ts->agg_values : NULL;
803a7988 733}
734
3f2ff969 735/* Function formal parameters related computations. */
736void ipa_initialize_node_params (struct cgraph_node *node);
3f2ff969 737bool ipa_propagate_indirect_call_infos (struct cgraph_edge *cs,
415d1b9a 738 vec<cgraph_edge *> *new_edges);
3b22db66 739
1caef38b 740/* Indirect edge and binfo processing. */
20da2013 741tree ipa_get_indirect_edge_target (struct cgraph_edge *ie,
f1f41a6c 742 vec<tree> ,
245ab191 743 vec<ipa_polymorphic_call_context>,
f21a87d8 744 vec<ipa_agg_jump_function_p>,
745 bool *);
072ec6eb 746struct cgraph_edge *ipa_make_edge_direct_to_target (struct cgraph_edge *, tree,
747 bool speculative = false);
3bc62a51 748tree ipa_impossible_devirt_target (struct cgraph_edge *, tree);
97cb825b 749ipa_bits *ipa_get_ipa_bits_for_value (const widest_int &value,
750 const widest_int &mask);
751
1caef38b 752
821d0e0f 753/* Functions related to both. */
754void ipa_analyze_node (struct cgraph_node *);
1caef38b 755
0d491188 756/* Aggregate jump function related functions. */
665ff45b 757tree ipa_find_agg_cst_for_param (struct ipa_agg_jump_function *agg, tree scalar,
758 HOST_WIDE_INT offset, bool by_ref,
759 bool *from_global_constant = NULL);
760bool ipa_load_from_parm_agg (struct ipa_func_body_info *fbi,
7af25a10 761 vec<ipa_param_descriptor, va_gc> *descriptors,
665ff45b 762 gimple *stmt, tree op, int *index_p,
763 HOST_WIDE_INT *offset_p, HOST_WIDE_INT *size_p,
764 bool *by_ref, bool *guaranteed_unmodified = NULL);
0d491188 765
3b22db66 766/* Debugging interface. */
11b73810 767void ipa_print_node_params (FILE *, struct cgraph_node *node);
768void ipa_print_all_params (FILE *);
f8daee9b 769void ipa_print_node_jump_functions (FILE *f, struct cgraph_node *node);
770void ipa_print_all_jump_functions (FILE * f);
821d0e0f 771void ipcp_verify_propagated_values (void);
772
8361d32f 773template <typename value>
774class ipcp_value;
775
e16712b1 776extern object_allocator<ipcp_value<tree> > ipcp_cst_values_pool;
777extern object_allocator<ipcp_value<ipa_polymorphic_call_context> >
8361d32f 778 ipcp_poly_ctx_values_pool;
779
780template <typename valtype>
781class ipcp_value_source;
782
e16712b1 783extern object_allocator<ipcp_value_source<tree> > ipcp_sources_pool;
8361d32f 784
785class ipcp_agg_lattice;
786
e16712b1 787extern object_allocator<ipcp_agg_lattice> ipcp_agg_lattice_pool;
3b22db66 788
803a7988 789void ipa_dump_agg_replacement_values (FILE *f,
790 struct ipa_agg_replacement_value *av);
eab36a5a 791void ipa_prop_write_jump_functions (void);
8867b500 792void ipa_prop_read_jump_functions (void);
ae7b7bc8 793void ipcp_write_transformation_summaries (void);
794void ipcp_read_transformation_summaries (void);
a41f2a28 795int ipa_get_param_decl_index (struct ipa_node_params *, tree);
20da2013 796tree ipa_value_from_jfunc (struct ipa_node_params *info,
944ee40d 797 struct ipa_jump_func *jfunc, tree type);
803a7988 798unsigned int ipcp_transform_function (struct cgraph_node *node);
245ab191 799ipa_polymorphic_call_context ipa_context_from_jfunc (ipa_node_params *,
800 cgraph_edge *,
801 int,
802 ipa_jump_func *);
09ab6335 803void ipa_dump_param (FILE *, struct ipa_node_params *info, int i);
73bd7d5f 804void ipa_release_body_info (struct ipa_func_body_info *);
166f8178 805tree ipa_get_callee_param_type (struct cgraph_edge *e, int i);
8867b500 806
547f1802 807/* From tree-sra.c: */
68a46b44 808tree build_ref_for_offset (location_t, tree, poly_int64, bool, tree,
a60aac35 809 gimple_stmt_iterator *, bool);
547f1802 810
415309e2 811/* In ipa-cp.c */
812void ipa_cp_c_finalize (void);
813
3b22db66 814#endif /* IPA_PROP_H */