]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/ipa-prop.h
parser.c (cp_parser_parameter_declaration_list): Initialize parenthesized_p.
[thirdparty/gcc.git] / gcc / ipa-prop.h
CommitLineData
518dc859 1/* Interprocedural analyses.
d652f226 2 Copyright (C) 2005, 2007, 2008, 2009, 2010
c75c517d 3 Free Software Foundation, Inc.
518dc859
RL
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9dcd6f09 9Software Foundation; either version 3, or (at your option) any later
518dc859
RL
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
9dcd6f09
NC
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
518dc859
RL
20
21#ifndef IPA_PROP_H
22#define IPA_PROP_H
23
24#include "tree.h"
771578a0 25#include "vec.h"
3e293154 26#include "cgraph.h"
d242d063 27#include "gimple.h"
518dc859
RL
28
29/* The following definitions and interfaces are used by
133f9369
MJ
30 interprocedural analyses or parameters. */
31
32/* ipa-prop.c stuff (ipa-cp, indirect inlining): */
518dc859 33
be95e2b9 34/* A jump function for a callsite represents the values passed as actual
518dc859 35 arguments of the callsite. There are three main types of values :
685b0d13
MJ
36
37 Pass-through - the caller's formal parameter is passed as an actual
38 argument, possibly one simple operation performed on it.
39 Constant - a constant (is_gimple_ip_invariant)is passed as an actual
40 argument.
41 Unknown - neither of the above.
42
b258210c
MJ
43 IPA_JF_CONST_MEMBER_PTR stands for C++ member pointers, it is a special
44 constant in this regard. Other constants are represented with IPA_JF_CONST.
45
46 IPA_JF_ANCESTOR is a special pass-through jump function, which means that
47 the result is an address of a part of the object pointed to by the formal
48 parameter to which the function refers. It is mainly intended to represent
49 getting addresses of of ancestor fields in C++
50 (e.g. &this_1(D)->D.1766.D.1756). Note that if the original pointer is
51 NULL, ancestor jump function must behave like a simple pass-through.
52
53 Other pass-through functions can either simply pass on an unchanged formal
54 parameter or can apply one simple binary operation to it (such jump
55 functions are called polynomial).
56
57 IPA_JF_KNOWN_TYPE is a special type of an "unknown" function that applies
58 only to pointer parameters. It means that even though we cannot prove that
59 the passed value is an interprocedural constant, we still know the exact
60 type of the containing object which may be valuable for devirtualization.
61
62 Jump functions are computed in ipa-prop.c by function
63 update_call_notes_after_inlining. Some information can be lost and jump
64 functions degraded accordingly when inlining, see
65 update_call_notes_after_inlining in the same file. */
685b0d13 66
518dc859
RL
67enum jump_func_type
68{
133f9369 69 IPA_JF_UNKNOWN = 0, /* newly allocated and zeroed jump functions default */
b258210c
MJ
70 IPA_JF_KNOWN_TYPE, /* represented by field base_binfo */
71 IPA_JF_CONST, /* represented by field costant */
72 IPA_JF_CONST_MEMBER_PTR, /* represented by field member_cst */
73 IPA_JF_PASS_THROUGH, /* represented by field pass_through */
74 IPA_JF_ANCESTOR /* represented by field ancestor */
518dc859
RL
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;
91};
92
b258210c
MJ
93/* Structure holding data required to describe an ancestor pass-through
94 jump function. */
685b0d13 95
fb3f88cc 96struct GTY(()) ipa_ancestor_jf_data
685b0d13
MJ
97{
98 /* Offset of the field representing the ancestor. */
99 HOST_WIDE_INT offset;
100 /* TYpe of the result. */
101 tree type;
102 /* Number of the caller's formal parameter being passed. */
103 int formal_id;
104};
105
3e293154
MJ
106/* Structure holding a C++ member pointer constant. Holds a pointer to the
107 method and delta offset. */
fb3f88cc 108struct GTY(()) ipa_member_ptr_cst
3e293154
MJ
109{
110 tree pfn;
111 tree delta;
112};
113
be95e2b9
MJ
114/* A jump function for a callsite represents the values passed as actual
115 arguments of the callsite. See enum jump_func_type for the various
518dc859 116 types of jump functions supported. */
fb3f88cc 117struct GTY (()) ipa_jump_func
518dc859
RL
118{
119 enum jump_func_type type;
fb3f88cc
JH
120 /* Represents a value of a jump function. pass_through is used only in jump
121 function context. constant represents the actual constant in constant jump
122 functions and member_cst holds constant c++ member functions. */
123 union jump_func_value
124 {
b258210c 125 tree GTY ((tag ("IPA_JF_KNOWN_TYPE"))) base_binfo;
fb3f88cc 126 tree GTY ((tag ("IPA_JF_CONST"))) constant;
b258210c 127 struct ipa_member_ptr_cst GTY ((tag ("IPA_JF_CONST_MEMBER_PTR"))) member_cst;
fb3f88cc
JH
128 struct ipa_pass_through_data GTY ((tag ("IPA_JF_PASS_THROUGH"))) pass_through;
129 struct ipa_ancestor_jf_data GTY ((tag ("IPA_JF_ANCESTOR"))) ancestor;
fb3f88cc 130 } GTY ((desc ("%1.type"))) value;
518dc859
RL
131};
132
b258210c
MJ
133/* All formal parameters in the program have a lattice associated with it
134 computed by the interprocedural stage of IPCP.
135 There are three main values of the lattice:
136 IPA_TOP - unknown,
3949c4a7 137 IPA_BOTTOM - variable,
b258210c 138 IPA_CONST_VALUE - simple scalar constant,
3949c4a7
MJ
139
140 We also use this type to propagate types accross the call graph for the
141 purpose of devirtualization. In that case, IPA_CONST_VALUE denotes a known
142 type, rather than a constant. */
b258210c
MJ
143enum ipa_lattice_type
144{
145 IPA_BOTTOM,
146 IPA_CONST_VALUE,
147 IPA_TOP
148};
149
be95e2b9 150/* All formal parameters in the program have a cval computed by
dcd416e3
MJ
151 the interprocedural stage of IPCP. See enum ipa_lattice_type for
152 the various types of lattices supported */
153struct ipcp_lattice
518dc859 154{
dcd416e3
MJ
155 enum ipa_lattice_type type;
156 tree constant;
518dc859
RL
157};
158
f8e2a1ed
MJ
159/* Structure describing a single formal parameter. */
160struct ipa_param_descriptor
161{
162 /* IPA-CP lattice. */
163 struct ipcp_lattice ipcp_lattice;
164 /* PARAM_DECL of this parameter. */
165 tree decl;
3949c4a7
MJ
166 /* Vector of BINFOs of types that this argument might encounter. NULL
167 basically means a top value, bottom is marked by the cannot_devirtualize
168 flag below.*/
169 VEC (tree, heap) *types;
339f49ec
JH
170 /* The parameter is used. */
171 unsigned used : 1;
3949c4a7
MJ
172 /* Set when parameter type cannot be used for devirtualization. */
173 unsigned cannot_devirtualize : 1;
f8e2a1ed
MJ
174};
175
dcd416e3
MJ
176/* ipa_node_params stores information related to formal parameters of functions
177 and some other information for interprocedural passes that operate on
178 parameters (such as ipa-cp). */
dcd416e3 179struct ipa_node_params
518dc859 180{
93c594a3
MJ
181 /* Number of formal parameters of this function. When set to 0, this
182 function's parameters would not be analyzed by IPA CP. */
dcd416e3 183 int param_count;
448f65db
NF
184 /* Whether this function is called with variable number of actual
185 arguments. */
186 unsigned called_with_var_arguments : 1;
448f65db
NF
187 /* Whether the param uses analysis has already been performed. */
188 unsigned uses_analysis_done : 1;
189 /* Whether the function is enqueued in an ipa_func_list. */
190 unsigned node_enqueued : 1;
f8e2a1ed
MJ
191 /* Pointer to an array of structures describing individual formal
192 parameters. */
193 struct ipa_param_descriptor *params;
518dc859
RL
194 /* Only for versioned nodes this field would not be NULL,
195 it points to the node that IPA cp cloned from. */
196 struct cgraph_node *ipcp_orig_node;
dcd416e3 197 /* Meaningful only for original functions. Expresses the
be95e2b9
MJ
198 ratio between the direct calls and sum of all invocations of
199 this function (given by profiling info). It is used to calculate
518dc859
RL
200 the profiling information of the original function and the versioned
201 one. */
202 gcov_type count_scale;
203};
204
dcd416e3
MJ
205/* ipa_node_params access functions. Please use these to access fields that
206 are or will be shared among various passes. */
207
208/* Set the number of formal parameters. */
be95e2b9 209
dcd416e3
MJ
210static inline void
211ipa_set_param_count (struct ipa_node_params *info, int count)
212{
213 info->param_count = count;
214}
215
216/* Return the number of formal parameters. */
be95e2b9 217
dcd416e3
MJ
218static inline int
219ipa_get_param_count (struct ipa_node_params *info)
220{
221 return info->param_count;
222}
223
f8e2a1ed
MJ
224/* Return the declaration of Ith formal parameter of the function corresponding
225 to INFO. Note there is no setter function as this array is built just once
226 using ipa_initialize_node_params. */
be95e2b9 227
dcd416e3 228static inline tree
f8e2a1ed 229ipa_get_param (struct ipa_node_params *info, int i)
dcd416e3 230{
f3181aa2 231 gcc_assert (i >= 0 && i <= info->param_count);
f8e2a1ed 232 return info->params[i].decl;
dcd416e3
MJ
233}
234
339f49ec
JH
235/* Return the used flag corresponding to the Ith formal parameter of
236 the function associated with INFO. */
237
238static inline bool
239ipa_is_param_used (struct ipa_node_params *info, int i)
240{
f3181aa2 241 gcc_assert (i >= 0 && i <= info->param_count);
339f49ec
JH
242 return info->params[i].used;
243}
244
3949c4a7
MJ
245/* Return the cannot_devirtualize flag corresponding to the Ith formal
246 parameter of the function associated with INFO. The corresponding function
247 to set the flag is ipa_set_param_cannot_devirtualize. */
248
249static inline bool
250ipa_param_cannot_devirtualize_p (struct ipa_node_params *info, int i)
251{
f3181aa2 252 gcc_assert (i >= 0 && i <= info->param_count);
3949c4a7
MJ
253 return info->params[i].cannot_devirtualize;
254}
255
256/* Return true iff the vector of possible types of the Ith formal parameter of
257 the function associated with INFO is empty. */
258
259static inline bool
260ipa_param_types_vec_empty (struct ipa_node_params *info, int i)
261{
f3181aa2 262 gcc_assert (i >= 0 && i <= info->param_count);
3949c4a7
MJ
263 return info->params[i].types == NULL;
264}
265
dcd416e3 266/* Flag this node as having callers with variable number of arguments. */
be95e2b9 267
dcd416e3
MJ
268static inline void
269ipa_set_called_with_variable_arg (struct ipa_node_params *info)
270{
271 info->called_with_var_arguments = 1;
272}
273
274/* Have we detected this node was called with variable number of arguments? */
be95e2b9 275
dcd416e3
MJ
276static inline bool
277ipa_is_called_with_var_arguments (struct ipa_node_params *info)
278{
279 return info->called_with_var_arguments;
280}
281
282
283
93c594a3
MJ
284/* ipa_edge_args stores information related to a callsite and particularly its
285 arguments. It can be accessed by the IPA_EDGE_REF macro. */
fb3f88cc 286typedef struct GTY(()) ipa_edge_args
518dc859
RL
287{
288 /* Number of actual arguments in this callsite. When set to 0,
289 this callsite's parameters would not be analyzed by the different
290 stages of IPA CP. */
dcd416e3 291 int argument_count;
518dc859 292 /* Array of the callsite's jump function of each parameter. */
fb3f88cc
JH
293 struct ipa_jump_func GTY ((length ("%h.argument_count"))) *jump_functions;
294} ipa_edge_args_t;
518dc859 295
dcd416e3
MJ
296/* ipa_edge_args access functions. Please use these to access fields that
297 are or will be shared among various passes. */
298
299/* Set the number of actual arguments. */
be95e2b9 300
dcd416e3
MJ
301static inline void
302ipa_set_cs_argument_count (struct ipa_edge_args *args, int count)
518dc859 303{
dcd416e3
MJ
304 args->argument_count = count;
305}
306
307/* Return the number of actual arguments. */
be95e2b9 308
dcd416e3
MJ
309static inline int
310ipa_get_cs_argument_count (struct ipa_edge_args *args)
311{
312 return args->argument_count;
313}
314
315/* Returns a pointer to the jump function for the ith argument. Please note
316 there is no setter function as jump functions are all set up in
317 ipa_compute_jump_functions. */
be95e2b9 318
dcd416e3
MJ
319static inline struct ipa_jump_func *
320ipa_get_ith_jump_func (struct ipa_edge_args *args, int i)
321{
f3181aa2 322 gcc_assert (i >= 0 && i <= args->argument_count);
dcd416e3
MJ
323 return &args->jump_functions[i];
324}
325
771578a0
MJ
326/* Vectors need to have typedefs of structures. */
327typedef struct ipa_node_params ipa_node_params_t;
771578a0 328
be95e2b9 329/* Types of vectors holding the infos. */
771578a0
MJ
330DEF_VEC_O (ipa_node_params_t);
331DEF_VEC_ALLOC_O (ipa_node_params_t, heap);
332DEF_VEC_O (ipa_edge_args_t);
fb3f88cc 333DEF_VEC_ALLOC_O (ipa_edge_args_t, gc);
771578a0
MJ
334
335/* Vector where the parameter infos are actually stored. */
336extern VEC (ipa_node_params_t, heap) *ipa_node_params_vector;
337/* Vector where the parameter infos are actually stored. */
fb3f88cc 338extern GTY(()) VEC (ipa_edge_args_t, gc) *ipa_edge_args_vector;
771578a0
MJ
339
340/* Return the associated parameter/argument info corresponding to the given
341 node/edge. */
342#define IPA_NODE_REF(NODE) (VEC_index (ipa_node_params_t, \
343 ipa_node_params_vector, (NODE)->uid))
344#define IPA_EDGE_REF(EDGE) (VEC_index (ipa_edge_args_t, \
345 ipa_edge_args_vector, (EDGE)->uid))
346/* This macro checks validity of index returned by
347 ipa_get_param_decl_index function. */
348#define IS_VALID_JUMP_FUNC_INDEX(I) ((I) != -1)
349
350/* Creating and freeing ipa_node_params and ipa_edge_args. */
351void ipa_create_all_node_params (void);
352void ipa_create_all_edge_args (void);
353void ipa_free_edge_args_substructures (struct ipa_edge_args *);
354void ipa_free_node_params_substructures (struct ipa_node_params *);
355void ipa_free_all_node_params (void);
356void ipa_free_all_edge_args (void);
e33c6cd6
MJ
357void ipa_create_all_structures_for_iinln (void);
358void ipa_free_all_structures_after_ipa_cp (void);
359void ipa_free_all_structures_after_iinln (void);
771578a0
MJ
360void ipa_register_cgraph_hooks (void);
361
362/* This function ensures the array of node param infos is big enough to
be95e2b9
MJ
363 accommodate a structure for all nodes and reallocates it if not. */
364
771578a0
MJ
365static inline void
366ipa_check_create_node_params (void)
367{
368 if (!ipa_node_params_vector)
369 ipa_node_params_vector = VEC_alloc (ipa_node_params_t, heap,
370 cgraph_max_uid);
371
372 if (VEC_length (ipa_node_params_t, ipa_node_params_vector)
373 <= (unsigned) cgraph_max_uid)
374 VEC_safe_grow_cleared (ipa_node_params_t, heap,
375 ipa_node_params_vector, cgraph_max_uid + 1);
376}
377
be95e2b9
MJ
378/* This function ensures the array of edge arguments infos is big enough to
379 accommodate a structure for all edges and reallocates it if not. */
380
771578a0
MJ
381static inline void
382ipa_check_create_edge_args (void)
383{
384 if (!ipa_edge_args_vector)
fb3f88cc 385 ipa_edge_args_vector = VEC_alloc (ipa_edge_args_t, gc,
771578a0
MJ
386 cgraph_edge_max_uid);
387
388 if (VEC_length (ipa_edge_args_t, ipa_edge_args_vector)
389 <= (unsigned) cgraph_edge_max_uid)
fb3f88cc 390 VEC_safe_grow_cleared (ipa_edge_args_t, gc, ipa_edge_args_vector,
771578a0
MJ
391 cgraph_edge_max_uid + 1);
392}
393
be95e2b9 394/* Returns true if the array of edge infos is large enough to accommodate an
0eae6bab
MJ
395 info for EDGE. The main purpose of this function is that debug dumping
396 function can check info availability without causing reallocations. */
be95e2b9 397
0eae6bab
MJ
398static inline bool
399ipa_edge_args_info_available_for_edge_p (struct cgraph_edge *edge)
400{
401 return ((unsigned) edge->uid < VEC_length (ipa_edge_args_t,
402 ipa_edge_args_vector));
403}
404
dcd416e3
MJ
405/* A function list element. It is used to create a temporary worklist used in
406 the propagation stage of IPCP. (can be used for more IPA optimizations) */
407struct ipa_func_list
408{
409 struct cgraph_node *node;
410 struct ipa_func_list *next;
518dc859
RL
411};
412
dcd416e3
MJ
413/* ipa_func_list interface. */
414struct ipa_func_list *ipa_init_func_list (void);
5b9633c8
MJ
415void ipa_push_func_to_list_1 (struct ipa_func_list **, struct cgraph_node *,
416 struct ipa_node_params *);
dcd416e3
MJ
417struct cgraph_node *ipa_pop_func_from_list (struct ipa_func_list **);
418
5b9633c8
MJ
419/* Add cgraph NODE to the worklist WL if it is not already in one. */
420
421static inline void
422ipa_push_func_to_list (struct ipa_func_list **wl, struct cgraph_node *node)
423{
424 struct ipa_node_params *info = IPA_NODE_REF (node);
425
426 if (!info->node_enqueued)
427 ipa_push_func_to_list_1 (wl, node, info);
428}
429
062c604f 430void ipa_analyze_node (struct cgraph_node *);
dcd416e3 431
f8e2a1ed
MJ
432/* Function formal parameters related computations. */
433void ipa_initialize_node_params (struct cgraph_node *node);
f8e2a1ed 434bool ipa_propagate_indirect_call_infos (struct cgraph_edge *cs,
e56f5f3e 435 VEC (cgraph_edge_p, heap) **new_edges);
518dc859 436
3949c4a7 437/* Indirect edge and binfo processing. */
ceeffab0
MJ
438struct cgraph_edge *ipa_make_edge_direct_to_target (struct cgraph_edge *, tree,
439 tree);
3949c4a7
MJ
440
441
518dc859 442/* Debugging interface. */
ca30a539
JH
443void ipa_print_node_params (FILE *, struct cgraph_node *node);
444void ipa_print_all_params (FILE *);
3e293154
MJ
445void ipa_print_node_jump_functions (FILE *f, struct cgraph_node *node);
446void ipa_print_all_jump_functions (FILE * f);
518dc859 447
3f84bf08
MJ
448/* Structure to describe transformations of formal parameters and actual
449 arguments. Each instance describes one new parameter and they are meant to
450 be stored in a vector. Additionally, most users will probably want to store
451 adjustments about parameters that are being removed altogether so that SSA
452 names belonging to them can be replaced by SSA names of an artificial
453 variable. */
454struct ipa_parm_adjustment
455{
456 /* The original PARM_DECL itself, helpful for processing of the body of the
457 function itself. Intended for traversing function bodies.
458 ipa_modify_formal_parameters, ipa_modify_call_arguments and
459 ipa_combine_adjustments ignore this and use base_index.
460 ipa_modify_formal_parameters actually sets this. */
461 tree base;
462
463 /* Type of the new parameter. However, if by_ref is true, the real type will
464 be a pointer to this type. */
465 tree type;
466
82d49829
MJ
467 /* Alias refrerence type to be used in MEM_REFs when adjusting caller
468 arguments. */
469 tree alias_ptr_type;
470
3f84bf08
MJ
471 /* The new declaration when creating/replacing a parameter. Created by
472 ipa_modify_formal_parameters, useful for functions modifying the body
473 accordingly. */
474 tree reduction;
475
476 /* New declaration of a substitute variable that we may use to replace all
477 non-default-def ssa names when a parm decl is going away. */
478 tree new_ssa_base;
479
480 /* If non-NULL and the original parameter is to be removed (copy_param below
481 is NULL), this is going to be its nonlocalized vars value. */
482 tree nonlocal_value;
483
484 /* Offset into the original parameter (for the cases when the new parameter
485 is a component of an original one). */
486 HOST_WIDE_INT offset;
487
488 /* Zero based index of the original parameter this one is based on. (ATM
489 there is no way to insert a new parameter out of the blue because there is
490 no need but if it arises the code can be easily exteded to do so.) */
491 int base_index;
492
493 /* This new parameter is an unmodified parameter at index base_index. */
494 unsigned copy_param : 1;
495
496 /* This adjustment describes a parameter that is about to be removed
497 completely. Most users will probably need to book keep those so that they
498 don't leave behinfd any non default def ssa names belonging to them. */
499 unsigned remove_param : 1;
500
501 /* The parameter is to be passed by reference. */
502 unsigned by_ref : 1;
503};
504
505typedef struct ipa_parm_adjustment ipa_parm_adjustment_t;
506DEF_VEC_O (ipa_parm_adjustment_t);
507DEF_VEC_ALLOC_O (ipa_parm_adjustment_t, heap);
508
509typedef VEC (ipa_parm_adjustment_t, heap) *ipa_parm_adjustment_vec;
510
511VEC(tree, heap) *ipa_get_vector_of_formal_parms (tree fndecl);
512void ipa_modify_formal_parameters (tree fndecl, ipa_parm_adjustment_vec,
513 const char *);
514void ipa_modify_call_arguments (struct cgraph_edge *, gimple,
515 ipa_parm_adjustment_vec);
516ipa_parm_adjustment_vec ipa_combine_adjustments (ipa_parm_adjustment_vec,
517 ipa_parm_adjustment_vec);
518void ipa_dump_param_adjustments (FILE *, ipa_parm_adjustment_vec, tree);
519
fb3f88cc
JH
520void ipa_prop_write_jump_functions (cgraph_node_set set);
521void ipa_prop_read_jump_functions (void);
522void ipa_update_after_lto_read (void);
632b4f8e 523int ipa_get_param_decl_index (struct ipa_node_params *, tree);
411a20d6
MJ
524void ipa_lattice_from_jfunc (struct ipa_node_params *info,
525 struct ipcp_lattice *lat,
632b4f8e 526 struct ipa_jump_func *jfunc);
411a20d6
MJ
527tree ipa_cst_from_jfunc (struct ipa_node_params *info,
528 struct ipa_jump_func *jfunc);
529
fb3f88cc 530
3f84bf08 531/* From tree-sra.c: */
e4b5cace
MJ
532tree build_ref_for_offset (location_t, tree, HOST_WIDE_INT, tree,
533 gimple_stmt_iterator *, bool);
3f84bf08 534
632b4f8e
JH
535/* Return the lattice corresponding to the Ith formal parameter of the function
536 described by INFO. */
537static inline struct ipcp_lattice *
538ipa_get_lattice (struct ipa_node_params *info, int i)
539{
f3181aa2 540 gcc_assert (i >= 0 && i <= info->param_count);
632b4f8e
JH
541 return &(info->params[i].ipcp_lattice);
542}
543
518dc859 544#endif /* IPA_PROP_H */