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