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