]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/ipa-prop.h
linux-common.h (LINK_MPX): New.
[thirdparty/gcc.git] / gcc / ipa-prop.h
CommitLineData
518dc859 1/* Interprocedural analyses.
5624e564 2 Copyright (C) 2005-2015 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
04be694e
MJ
146/* Info about pointer alignments. */
147struct GTY(()) ipa_alignment
148{
149 /* The data fields below are valid only if known is true. */
150 bool known;
151 /* See ptr_info_def and get_pointer_alignment_1 for description of these
152 two. */
153 unsigned align;
154 unsigned misalign;
155};
156
be95e2b9
MJ
157/* A jump function for a callsite represents the values passed as actual
158 arguments of the callsite. See enum jump_func_type for the various
518dc859 159 types of jump functions supported. */
84562394 160struct GTY (()) ipa_jump_func
518dc859 161{
8b7773a4
MJ
162 /* Aggregate contants description. See struct ipa_agg_jump_function and its
163 description. */
164 struct ipa_agg_jump_function agg;
165
04be694e
MJ
166 /* Information about alignment of pointers. */
167 struct ipa_alignment alignment;
168
518dc859 169 enum jump_func_type type;
fb3f88cc
JH
170 /* Represents a value of a jump function. pass_through is used only in jump
171 function context. constant represents the actual constant in constant jump
172 functions and member_cst holds constant c++ member functions. */
173 union jump_func_value
174 {
4502fe8d 175 struct ipa_constant_data GTY ((tag ("IPA_JF_CONST"))) constant;
fb3f88cc
JH
176 struct ipa_pass_through_data GTY ((tag ("IPA_JF_PASS_THROUGH"))) pass_through;
177 struct ipa_ancestor_jf_data GTY ((tag ("IPA_JF_ANCESTOR"))) ancestor;
fb3f88cc 178 } GTY ((desc ("%1.type"))) value;
84562394 179};
606d9a09 180
518dc859 181
7b872d9e
MJ
182/* Return the constant stored in a constant jump functin JFUNC. */
183
184static inline tree
185ipa_get_jf_constant (struct ipa_jump_func *jfunc)
186{
187 gcc_checking_assert (jfunc->type == IPA_JF_CONST);
4502fe8d
MJ
188 return jfunc->value.constant.value;
189}
190
191static inline struct ipa_cst_ref_desc *
192ipa_get_jf_constant_rdesc (struct ipa_jump_func *jfunc)
193{
194 gcc_checking_assert (jfunc->type == IPA_JF_CONST);
195 return jfunc->value.constant.rdesc;
7b872d9e
MJ
196}
197
198/* Return the operand of a pass through jmp function JFUNC. */
199
200static inline tree
201ipa_get_jf_pass_through_operand (struct ipa_jump_func *jfunc)
202{
203 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
204 return jfunc->value.pass_through.operand;
205}
206
207/* Return the number of the caller's formal parameter that a pass through jump
208 function JFUNC refers to. */
209
210static inline int
211ipa_get_jf_pass_through_formal_id (struct ipa_jump_func *jfunc)
212{
213 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
214 return jfunc->value.pass_through.formal_id;
215}
216
217/* Return operation of a pass through jump function JFUNC. */
218
219static inline enum tree_code
220ipa_get_jf_pass_through_operation (struct ipa_jump_func *jfunc)
221{
222 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
223 return jfunc->value.pass_through.operation;
224}
225
b8f6e610 226/* Return the agg_preserved flag of a pass through jump function JFUNC. */
8b7773a4
MJ
227
228static inline bool
229ipa_get_jf_pass_through_agg_preserved (struct ipa_jump_func *jfunc)
230{
231 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
232 return jfunc->value.pass_through.agg_preserved;
233}
234
44210a96
MJ
235/* Return true if pass through jump function JFUNC preserves type
236 information. */
b8f6e610
MJ
237
238static inline bool
239ipa_get_jf_pass_through_type_preserved (struct ipa_jump_func *jfunc)
240{
241 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
44210a96 242 return jfunc->value.pass_through.agg_preserved;
b8f6e610
MJ
243}
244
7b872d9e
MJ
245/* Return the offset of an ancestor jump function JFUNC. */
246
247static inline HOST_WIDE_INT
248ipa_get_jf_ancestor_offset (struct ipa_jump_func *jfunc)
249{
250 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
251 return jfunc->value.ancestor.offset;
252}
253
7b872d9e
MJ
254/* Return the number of the caller's formal parameter that an ancestor jump
255 function JFUNC refers to. */
256
257static inline int
258ipa_get_jf_ancestor_formal_id (struct ipa_jump_func *jfunc)
259{
260 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
261 return jfunc->value.ancestor.formal_id;
262}
263
b8f6e610 264/* Return the agg_preserved flag of an ancestor jump function JFUNC. */
7b872d9e 265
8b7773a4
MJ
266static inline bool
267ipa_get_jf_ancestor_agg_preserved (struct ipa_jump_func *jfunc)
7b872d9e 268{
8b7773a4
MJ
269 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
270 return jfunc->value.ancestor.agg_preserved;
7b872d9e
MJ
271}
272
44210a96 273/* Return true if ancestor jump function JFUNC presrves type information. */
b8f6e610
MJ
274
275static inline bool
276ipa_get_jf_ancestor_type_preserved (struct ipa_jump_func *jfunc)
277{
278 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
44210a96 279 return jfunc->value.ancestor.agg_preserved;
b8f6e610
MJ
280}
281
310bc633 282/* Summary describing a single formal parameter. */
b258210c 283
f8e2a1ed
MJ
284struct ipa_param_descriptor
285{
f8e2a1ed
MJ
286 /* PARAM_DECL of this parameter. */
287 tree decl;
4502fe8d
MJ
288 /* If all uses of the parameter are described by ipa-prop structures, this
289 says how many there are. If any use could not be described by means of
290 ipa-prop structures, this is IPA_UNDESCRIBED_USE. */
291 int controlled_uses;
0e8853ee 292 unsigned int move_cost : 31;
339f49ec
JH
293 /* The parameter is used. */
294 unsigned used : 1;
f8e2a1ed
MJ
295};
296
dcd416e3
MJ
297/* ipa_node_params stores information related to formal parameters of functions
298 and some other information for interprocedural passes that operate on
299 parameters (such as ipa-cp). */
310bc633 300
dcd416e3 301struct ipa_node_params
518dc859 302{
dd912cb8
ML
303 ~ipa_node_params ();
304
310bc633
MJ
305 /* Information about individual formal parameters that are gathered when
306 summaries are generated. */
84562394 307 vec<ipa_param_descriptor> descriptors;
310bc633
MJ
308 /* Pointer to an array of structures describing individual formal
309 parameters. */
2c9561b5 310 struct ipcp_param_lattices *lattices;
310bc633
MJ
311 /* Only for versioned nodes this field would not be NULL,
312 it points to the node that IPA cp cloned from. */
313 struct cgraph_node *ipcp_orig_node;
44210a96
MJ
314 /* If this node is an ipa-cp clone, these are the known constants that
315 describe what it has been specialized for. */
316 vec<tree> known_csts;
317 /* If this node is an ipa-cp clone, these are the known polymorphic contexts
318 that describe what it has been specialized for. */
319 vec<ipa_polymorphic_call_context> known_contexts;
8aab5218
MJ
320 /* Whether the param uses analysis and jump function computation has already
321 been performed. */
322 unsigned analysis_done : 1;
310bc633 323 /* Whether the function is enqueued in ipa-cp propagation stack. */
448f65db 324 unsigned node_enqueued : 1;
310bc633
MJ
325 /* Whether we should create a specialized version based on values that are
326 known to be constant in all contexts. */
eb20b778
MJ
327 unsigned do_clone_for_all_contexts : 1;
328 /* Set if this is an IPA-CP clone for all contexts. */
329 unsigned is_all_contexts_clone : 1;
310bc633
MJ
330 /* Node has been completely replaced by clones and will be removed after
331 ipa-cp is finished. */
332 unsigned node_dead : 1;
af21714c
MJ
333 /* Node is involved in a recursion, potentionally indirect. */
334 unsigned node_within_scc : 1;
335 /* Node is calling a private function called only once. */
336 unsigned node_calling_single_call : 1;
518dc859
RL
337};
338
ff302741
PB
339/* Intermediate information that we get from alias analysis about a particular
340 parameter in a particular basic_block. When a parameter or the memory it
341 references is marked modified, we use that information in all dominatd
342 blocks without cosulting alias analysis oracle. */
343
344struct param_aa_status
345{
346 /* Set when this structure contains meaningful information. If not, the
347 structure describing a dominating BB should be used instead. */
348 bool valid;
349
350 /* Whether we have seen something which might have modified the data in
351 question. PARM is for the parameter itself, REF is for data it points to
352 but using the alias type of individual accesses and PT is the same thing
353 but for computing aggregate pass-through functions using a very inclusive
354 ao_ref. */
355 bool parm_modified, ref_modified, pt_modified;
356};
357
358/* Information related to a given BB that used only when looking at function
359 body. */
360
361struct ipa_bb_info
362{
363 /* Call graph edges going out of this BB. */
364 vec<cgraph_edge *> cg_edges;
365 /* Alias analysis statuses of each formal parameter at this bb. */
366 vec<param_aa_status> param_aa_statuses;
367};
368
369/* Structure with global information that is only used when looking at function
370 body. */
371
372struct func_body_info
373{
374 /* The node that is being analyzed. */
375 cgraph_node *node;
376
377 /* Its info. */
378 struct ipa_node_params *info;
379
380 /* Information about individual BBs. */
381 vec<ipa_bb_info> bb_infos;
382
383 /* Number of parameters. */
384 int param_count;
385
386 /* Number of statements already walked by when analyzing this function. */
387 unsigned int aa_walked;
388};
389
dcd416e3
MJ
390/* ipa_node_params access functions. Please use these to access fields that
391 are or will be shared among various passes. */
392
dcd416e3 393/* Return the number of formal parameters. */
be95e2b9 394
dcd416e3
MJ
395static inline int
396ipa_get_param_count (struct ipa_node_params *info)
397{
9771b263 398 return info->descriptors.length ();
dcd416e3
MJ
399}
400
f8e2a1ed
MJ
401/* Return the declaration of Ith formal parameter of the function corresponding
402 to INFO. Note there is no setter function as this array is built just once
403 using ipa_initialize_node_params. */
be95e2b9 404
dcd416e3 405static inline tree
f8e2a1ed 406ipa_get_param (struct ipa_node_params *info, int i)
dcd416e3 407{
0e8853ee 408 gcc_checking_assert (!flag_wpa);
9771b263 409 return info->descriptors[i].decl;
339f49ec
JH
410}
411
0e8853ee
JH
412/* Return the move cost of Ith formal parameter of the function corresponding
413 to INFO. */
414
415static inline int
416ipa_get_param_move_cost (struct ipa_node_params *info, int i)
417{
418 return info->descriptors[i].move_cost;
419}
420
310bc633
MJ
421/* Set the used flag corresponding to the Ith formal parameter of the function
422 associated with INFO to VAL. */
3949c4a7 423
310bc633
MJ
424static inline void
425ipa_set_param_used (struct ipa_node_params *info, int i, bool val)
3949c4a7 426{
9771b263 427 info->descriptors[i].used = val;
3949c4a7
MJ
428}
429
4502fe8d
MJ
430/* Return how many uses described by ipa-prop a parameter has or
431 IPA_UNDESCRIBED_USE if there is a use that is not described by these
432 structures. */
433static inline int
434ipa_get_controlled_uses (struct ipa_node_params *info, int i)
435{
5ce97055
JH
436 /* FIXME: introducing speuclation causes out of bounds access here. */
437 if (info->descriptors.length () > (unsigned)i)
438 return info->descriptors[i].controlled_uses;
439 return IPA_UNDESCRIBED_USE;
4502fe8d
MJ
440}
441
442/* Set the controlled counter of a given parameter. */
443
444static inline void
445ipa_set_controlled_uses (struct ipa_node_params *info, int i, int val)
446{
447 info->descriptors[i].controlled_uses = val;
448}
449
310bc633
MJ
450/* Return the used flag corresponding to the Ith formal parameter of the
451 function associated with INFO. */
3949c4a7
MJ
452
453static inline bool
310bc633 454ipa_is_param_used (struct ipa_node_params *info, int i)
3949c4a7 455{
9771b263 456 return info->descriptors[i].used;
3949c4a7
MJ
457}
458
2c9561b5
MJ
459/* Information about replacements done in aggregates for a given node (each
460 node has its linked list). */
461struct GTY(()) ipa_agg_replacement_value
462{
463 /* Next item in the linked list. */
464 struct ipa_agg_replacement_value *next;
465 /* Offset within the aggregate. */
466 HOST_WIDE_INT offset;
467 /* The constant value. */
468 tree value;
469 /* The paramter index. */
470 int index;
7b920a9a
MJ
471 /* Whether the value was passed by reference. */
472 bool by_ref;
2c9561b5
MJ
473};
474
04be694e
MJ
475/* Structure holding information for the transformation phase of IPA-CP. */
476
477struct GTY(()) ipcp_transformation_summary
478{
479 /* Linked list of known aggregate values. */
480 ipa_agg_replacement_value *agg_values;
481 /* Alignment information for pointers. */
482 vec<ipa_alignment, va_gc> *alignments;
483};
2c9561b5
MJ
484
485void ipa_set_node_agg_value_chain (struct cgraph_node *node,
486 struct ipa_agg_replacement_value *aggvals);
04be694e 487void ipcp_grow_transformations_if_necessary (void);
2c9561b5 488
93c594a3
MJ
489/* ipa_edge_args stores information related to a callsite and particularly its
490 arguments. It can be accessed by the IPA_EDGE_REF macro. */
84562394 491struct GTY(()) ipa_edge_args
518dc859 492{
606d9a09 493 /* Vector of the callsite's jump function of each parameter. */
84562394 494 vec<ipa_jump_func, va_gc> *jump_functions;
5ce97055 495 vec<ipa_polymorphic_call_context, va_gc> *polymorphic_call_contexts;
84562394 496};
518dc859 497
dcd416e3
MJ
498/* ipa_edge_args access functions. Please use these to access fields that
499 are or will be shared among various passes. */
500
dcd416e3 501/* Return the number of actual arguments. */
be95e2b9 502
dcd416e3
MJ
503static inline int
504ipa_get_cs_argument_count (struct ipa_edge_args *args)
505{
9771b263 506 return vec_safe_length (args->jump_functions);
dcd416e3
MJ
507}
508
509/* Returns a pointer to the jump function for the ith argument. Please note
510 there is no setter function as jump functions are all set up in
511 ipa_compute_jump_functions. */
be95e2b9 512
dcd416e3
MJ
513static inline struct ipa_jump_func *
514ipa_get_ith_jump_func (struct ipa_edge_args *args, int i)
515{
9771b263 516 return &(*args->jump_functions)[i];
dcd416e3
MJ
517}
518
5ce97055
JH
519/* Returns a pointer to the polymorphic call context for the ith argument.
520 NULL if contexts are not computed. */
521static inline struct ipa_polymorphic_call_context *
522ipa_get_ith_polymorhic_call_context (struct ipa_edge_args *args, int i)
523{
524 if (!args->polymorphic_call_contexts)
525 return NULL;
526 return &(*args->polymorphic_call_contexts)[i];
527}
528
9a1e784a 529/* Function summary for ipa_node_params. */
dd912cb8
ML
530class ipa_node_params_t: public function_summary <ipa_node_params *>
531{
532public:
533 ipa_node_params_t (symbol_table *table):
534 function_summary<ipa_node_params *> (table) { }
771578a0 535
dd912cb8
ML
536 /* Hook that is called by summary when a node is duplicated. */
537 virtual void duplicate (cgraph_node *node,
538 cgraph_node *node2,
539 ipa_node_params *data,
540 ipa_node_params *data2);
541};
542
543/* Function summary where the parameter infos are actually stored. */
544extern ipa_node_params_t *ipa_node_params_sum;
04be694e
MJ
545/* Vector of IPA-CP transformation data for each clone. */
546extern GTY(()) vec<ipcp_transformation_summary, va_gc> *ipcp_transformations;
771578a0 547/* Vector where the parameter infos are actually stored. */
84562394 548extern GTY(()) vec<ipa_edge_args, va_gc> *ipa_edge_args_vector;
771578a0
MJ
549
550/* Return the associated parameter/argument info corresponding to the given
551 node/edge. */
dd912cb8 552#define IPA_NODE_REF(NODE) (ipa_node_params_sum->get (NODE))
9771b263 553#define IPA_EDGE_REF(EDGE) (&(*ipa_edge_args_vector)[(EDGE)->uid])
771578a0
MJ
554/* This macro checks validity of index returned by
555 ipa_get_param_decl_index function. */
556#define IS_VALID_JUMP_FUNC_INDEX(I) ((I) != -1)
557
558/* Creating and freeing ipa_node_params and ipa_edge_args. */
559void ipa_create_all_node_params (void);
560void ipa_create_all_edge_args (void);
561void ipa_free_edge_args_substructures (struct ipa_edge_args *);
771578a0
MJ
562void ipa_free_all_node_params (void);
563void ipa_free_all_edge_args (void);
e33c6cd6
MJ
564void ipa_free_all_structures_after_ipa_cp (void);
565void ipa_free_all_structures_after_iinln (void);
dd912cb8 566
771578a0 567void ipa_register_cgraph_hooks (void);
fd29c024 568int count_formal_params (tree fndecl);
771578a0
MJ
569
570/* This function ensures the array of node param infos is big enough to
be95e2b9
MJ
571 accommodate a structure for all nodes and reallocates it if not. */
572
771578a0
MJ
573static inline void
574ipa_check_create_node_params (void)
575{
dd912cb8
ML
576 if (!ipa_node_params_sum)
577 ipa_node_params_sum = new ipa_node_params_t (symtab);
771578a0
MJ
578}
579
be95e2b9
MJ
580/* This function ensures the array of edge arguments infos is big enough to
581 accommodate a structure for all edges and reallocates it if not. */
582
771578a0
MJ
583static inline void
584ipa_check_create_edge_args (void)
585{
3dafb85c
ML
586 if (vec_safe_length (ipa_edge_args_vector)
587 <= (unsigned) symtab->edges_max_uid)
588 vec_safe_grow_cleared (ipa_edge_args_vector, symtab->edges_max_uid + 1);
771578a0
MJ
589}
590
be95e2b9 591/* Returns true if the array of edge infos is large enough to accommodate an
0eae6bab
MJ
592 info for EDGE. The main purpose of this function is that debug dumping
593 function can check info availability without causing reallocations. */
be95e2b9 594
0eae6bab
MJ
595static inline bool
596ipa_edge_args_info_available_for_edge_p (struct cgraph_edge *edge)
597{
9771b263 598 return ((unsigned) edge->uid < vec_safe_length (ipa_edge_args_vector));
0eae6bab
MJ
599}
600
04be694e
MJ
601static inline ipcp_transformation_summary *
602ipcp_get_transformation_summary (cgraph_node *node)
603{
604 if ((unsigned) node->uid >= vec_safe_length (ipcp_transformations))
605 return NULL;
606 return &(*ipcp_transformations)[node->uid];
607}
608
2c9561b5
MJ
609/* Return the aggregate replacements for NODE, if there are any. */
610
611static inline struct ipa_agg_replacement_value *
04be694e 612ipa_get_agg_replacements_for_node (cgraph_node *node)
2c9561b5 613{
04be694e
MJ
614 ipcp_transformation_summary *ts = ipcp_get_transformation_summary (node);
615 return ts ? ts->agg_values : NULL;
2c9561b5
MJ
616}
617
f8e2a1ed
MJ
618/* Function formal parameters related computations. */
619void ipa_initialize_node_params (struct cgraph_node *node);
f8e2a1ed 620bool ipa_propagate_indirect_call_infos (struct cgraph_edge *cs,
d52f5295 621 vec<cgraph_edge *> *new_edges);
518dc859 622
3949c4a7 623/* Indirect edge and binfo processing. */
d2d668fb 624tree ipa_get_indirect_edge_target (struct cgraph_edge *ie,
9771b263 625 vec<tree> ,
44210a96 626 vec<ipa_polymorphic_call_context>,
231b4916
JH
627 vec<ipa_agg_jump_function_p>,
628 bool *);
5ce97055
JH
629struct cgraph_edge *ipa_make_edge_direct_to_target (struct cgraph_edge *, tree,
630 bool speculative = false);
72972c22 631tree ipa_impossible_devirt_target (struct cgraph_edge *, tree);
3949c4a7 632
310bc633
MJ
633/* Functions related to both. */
634void ipa_analyze_node (struct cgraph_node *);
3949c4a7 635
8b7773a4
MJ
636/* Aggregate jump function related functions. */
637tree ipa_find_agg_cst_for_param (struct ipa_agg_jump_function *, HOST_WIDE_INT,
638 bool);
ff302741
PB
639bool ipa_load_from_parm_agg (struct func_body_info *,
640 vec<ipa_param_descriptor>, gimple, tree, int *,
641 HOST_WIDE_INT *, HOST_WIDE_INT *, bool *);
8b7773a4 642
518dc859 643/* Debugging interface. */
ca30a539
JH
644void ipa_print_node_params (FILE *, struct cgraph_node *node);
645void ipa_print_all_params (FILE *);
3e293154
MJ
646void ipa_print_node_jump_functions (FILE *f, struct cgraph_node *node);
647void ipa_print_all_jump_functions (FILE * f);
310bc633
MJ
648void ipcp_verify_propagated_values (void);
649
2651e637
ML
650template <typename value>
651class ipcp_value;
652
653extern pool_allocator<ipcp_value<tree> > ipcp_cst_values_pool;
654extern pool_allocator<ipcp_value<ipa_polymorphic_call_context> >
655 ipcp_poly_ctx_values_pool;
656
657template <typename valtype>
658class ipcp_value_source;
659
660extern pool_allocator<ipcp_value_source<tree> > ipcp_sources_pool;
661
662class ipcp_agg_lattice;
663
664extern pool_allocator<ipcp_agg_lattice> ipcp_agg_lattice_pool;
518dc859 665
31519c38
AH
666/* Operation to be performed for the parameter in ipa_parm_adjustment
667 below. */
668enum ipa_parm_op {
669 IPA_PARM_OP_NONE,
670
671 /* This describes a brand new parameter.
672
673 The field `type' should be set to the new type, `arg_prefix'
674 should be set to the string prefix for the new DECL_NAME, and
675 `new_decl' will ultimately hold the newly created argument. */
676 IPA_PARM_OP_NEW,
677
678 /* This new parameter is an unmodified parameter at index base_index. */
679 IPA_PARM_OP_COPY,
680
681 /* This adjustment describes a parameter that is about to be removed
682 completely. Most users will probably need to book keep those so that they
683 don't leave behinfd any non default def ssa names belonging to them. */
684 IPA_PARM_OP_REMOVE
685};
686
3f84bf08
MJ
687/* Structure to describe transformations of formal parameters and actual
688 arguments. Each instance describes one new parameter and they are meant to
689 be stored in a vector. Additionally, most users will probably want to store
690 adjustments about parameters that are being removed altogether so that SSA
691 names belonging to them can be replaced by SSA names of an artificial
692 variable. */
693struct ipa_parm_adjustment
694{
695 /* The original PARM_DECL itself, helpful for processing of the body of the
696 function itself. Intended for traversing function bodies.
697 ipa_modify_formal_parameters, ipa_modify_call_arguments and
698 ipa_combine_adjustments ignore this and use base_index.
699 ipa_modify_formal_parameters actually sets this. */
700 tree base;
701
702 /* Type of the new parameter. However, if by_ref is true, the real type will
703 be a pointer to this type. */
704 tree type;
705
82d49829
MJ
706 /* Alias refrerence type to be used in MEM_REFs when adjusting caller
707 arguments. */
708 tree alias_ptr_type;
709
31519c38
AH
710 /* The new declaration when creating/replacing a parameter. Created
711 by ipa_modify_formal_parameters, useful for functions modifying
712 the body accordingly. For brand new arguments, this is the newly
713 created argument. */
714 tree new_decl;
3f84bf08
MJ
715
716 /* New declaration of a substitute variable that we may use to replace all
717 non-default-def ssa names when a parm decl is going away. */
718 tree new_ssa_base;
719
720 /* If non-NULL and the original parameter is to be removed (copy_param below
721 is NULL), this is going to be its nonlocalized vars value. */
722 tree nonlocal_value;
723
31519c38
AH
724 /* This holds the prefix to be used for the new DECL_NAME. */
725 const char *arg_prefix;
726
3f84bf08
MJ
727 /* Offset into the original parameter (for the cases when the new parameter
728 is a component of an original one). */
729 HOST_WIDE_INT offset;
730
31519c38 731 /* Zero based index of the original parameter this one is based on. */
3f84bf08
MJ
732 int base_index;
733
31519c38
AH
734 /* Whether this parameter is a new parameter, a copy of an old one,
735 or one about to be removed. */
736 enum ipa_parm_op op;
3f84bf08
MJ
737
738 /* The parameter is to be passed by reference. */
739 unsigned by_ref : 1;
740};
741
84562394 742typedef vec<ipa_parm_adjustment> ipa_parm_adjustment_vec;
3f84bf08 743
9771b263 744vec<tree> ipa_get_vector_of_formal_parms (tree fndecl);
31519c38
AH
745vec<tree> ipa_get_vector_of_formal_parm_types (tree fntype);
746void ipa_modify_formal_parameters (tree fndecl, ipa_parm_adjustment_vec);
538dd0b7 747void ipa_modify_call_arguments (struct cgraph_edge *, gcall *,
3f84bf08
MJ
748 ipa_parm_adjustment_vec);
749ipa_parm_adjustment_vec ipa_combine_adjustments (ipa_parm_adjustment_vec,
750 ipa_parm_adjustment_vec);
751void ipa_dump_param_adjustments (FILE *, ipa_parm_adjustment_vec, tree);
2c9561b5
MJ
752void ipa_dump_agg_replacement_values (FILE *f,
753 struct ipa_agg_replacement_value *av);
f27c1867 754void ipa_prop_write_jump_functions (void);
fb3f88cc 755void ipa_prop_read_jump_functions (void);
04be694e
MJ
756void ipcp_write_transformation_summaries (void);
757void ipcp_read_transformation_summaries (void);
fb3f88cc 758void ipa_update_after_lto_read (void);
632b4f8e 759int ipa_get_param_decl_index (struct ipa_node_params *, tree);
d2d668fb
MK
760tree ipa_value_from_jfunc (struct ipa_node_params *info,
761 struct ipa_jump_func *jfunc);
2c9561b5 762unsigned int ipcp_transform_function (struct cgraph_node *node);
44210a96
MJ
763ipa_polymorphic_call_context ipa_context_from_jfunc (ipa_node_params *,
764 cgraph_edge *,
765 int,
766 ipa_jump_func *);
0e8853ee 767void ipa_dump_param (FILE *, struct ipa_node_params *info, int i);
31519c38
AH
768bool ipa_modify_expr (tree *, bool, ipa_parm_adjustment_vec);
769ipa_parm_adjustment *ipa_get_adjustment_candidate (tree **, bool *,
770 ipa_parm_adjustment_vec,
771 bool);
411a20d6 772
fb3f88cc 773
3f84bf08 774/* From tree-sra.c: */
e4b5cace
MJ
775tree build_ref_for_offset (location_t, tree, HOST_WIDE_INT, tree,
776 gimple_stmt_iterator *, bool);
3f84bf08 777
3edf64aa
DM
778/* In ipa-cp.c */
779void ipa_cp_c_finalize (void);
780
518dc859 781#endif /* IPA_PROP_H */