* gcc.dg/vect/slp-perm-1.c (main): Make sure loops aren't vectorized.
[official-gcc.git] / gcc / ipa-prop.h
blobc73367a49455b9eb4d777af3714c0734de4bade0
1 /* Interprocedural analyses.
2 Copyright (C) 2005, 2007, 2008, 2009
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef IPA_PROP_H
22 #define IPA_PROP_H
24 #include "tree.h"
25 #include "vec.h"
26 #include "cgraph.h"
28 /* The following definitions and interfaces are used by
29 interprocedural analyses or parameters. */
31 /* ipa-prop.c stuff (ipa-cp, indirect inlining): */
33 /* A jump function for a callsite represents the values passed as actual
34 arguments of the callsite. There are three main types of values :
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.
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.
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.
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).
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.
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. */
66 enum jump_func_type
68 IPA_JF_UNKNOWN = 0, /* newly allocated and zeroed jump functions default */
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 */
76 /* Structure holding data required to describe a pass-through jump function. */
78 struct GTY(()) ipa_pass_through_data
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;
92 /* Structure holding data required to describe an ancestor pass-through
93 jump function. */
95 struct GTY(()) ipa_ancestor_jf_data
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;
105 /* Structure holding a C++ member pointer constant. Holds a pointer to the
106 method and delta offset. */
107 struct GTY(()) ipa_member_ptr_cst
109 tree pfn;
110 tree delta;
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
115 types of jump functions supported. */
116 struct GTY (()) ipa_jump_func
118 enum jump_func_type type;
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
124 tree GTY ((tag ("IPA_JF_KNOWN_TYPE"))) base_binfo;
125 tree GTY ((tag ("IPA_JF_CONST"))) constant;
126 struct ipa_member_ptr_cst GTY ((tag ("IPA_JF_CONST_MEMBER_PTR"))) member_cst;
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;
129 } GTY ((desc ("%1.type"))) value;
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. */
141 enum ipa_lattice_type
143 IPA_BOTTOM,
144 IPA_CONST_VALUE,
145 IPA_TOP
148 /* All formal parameters in the program have a cval computed by
149 the interprocedural stage of IPCP. See enum ipa_lattice_type for
150 the various types of lattices supported */
151 struct ipcp_lattice
153 enum ipa_lattice_type type;
154 tree constant;
157 /* Structure describing a single formal parameter. */
158 struct ipa_param_descriptor
160 /* IPA-CP lattice. */
161 struct ipcp_lattice ipcp_lattice;
162 /* PARAM_DECL of this parameter. */
163 tree decl;
164 /* The parameter is used. */
165 unsigned used : 1;
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). */
171 struct ipa_node_params
173 /* Number of formal parameters of this function. When set to 0,
174 this function's parameters would not be analyzed by the different
175 stages of IPA CP. */
176 int param_count;
177 /* Whether this function is called with variable number of actual
178 arguments. */
179 unsigned called_with_var_arguments : 1;
180 /* Whether the param uses analysis has already been performed. */
181 unsigned uses_analysis_done : 1;
182 /* Whether the function is enqueued in an ipa_func_list. */
183 unsigned node_enqueued : 1;
184 /* Pointer to an array of structures describing individual formal
185 parameters. */
186 struct ipa_param_descriptor *params;
187 /* Only for versioned nodes this field would not be NULL,
188 it points to the node that IPA cp cloned from. */
189 struct cgraph_node *ipcp_orig_node;
190 /* Meaningful only for original functions. Expresses the
191 ratio between the direct calls and sum of all invocations of
192 this function (given by profiling info). It is used to calculate
193 the profiling information of the original function and the versioned
194 one. */
195 gcov_type count_scale;
198 /* ipa_node_params access functions. Please use these to access fields that
199 are or will be shared among various passes. */
201 /* Set the number of formal parameters. */
203 static inline void
204 ipa_set_param_count (struct ipa_node_params *info, int count)
206 info->param_count = count;
209 /* Return the number of formal parameters. */
211 static inline int
212 ipa_get_param_count (struct ipa_node_params *info)
214 return info->param_count;
217 /* Return the declaration of Ith formal parameter of the function corresponding
218 to INFO. Note there is no setter function as this array is built just once
219 using ipa_initialize_node_params. */
221 static inline tree
222 ipa_get_param (struct ipa_node_params *info, int i)
224 return info->params[i].decl;
227 /* Return the used flag corresponding to the Ith formal parameter of
228 the function associated with INFO. */
230 static inline bool
231 ipa_is_param_used (struct ipa_node_params *info, int i)
233 return info->params[i].used;
236 /* Flag this node as having callers with variable number of arguments. */
238 static inline void
239 ipa_set_called_with_variable_arg (struct ipa_node_params *info)
241 info->called_with_var_arguments = 1;
244 /* Have we detected this node was called with variable number of arguments? */
246 static inline bool
247 ipa_is_called_with_var_arguments (struct ipa_node_params *info)
249 return info->called_with_var_arguments;
254 /* ipa_edge_args stores information related to a callsite and particularly
255 its arguments. It is pointed to by a field in the
256 callsite's corresponding cgraph_edge. */
257 typedef struct GTY(()) ipa_edge_args
259 /* Number of actual arguments in this callsite. When set to 0,
260 this callsite's parameters would not be analyzed by the different
261 stages of IPA CP. */
262 int argument_count;
263 /* Array of the callsite's jump function of each parameter. */
264 struct ipa_jump_func GTY ((length ("%h.argument_count"))) *jump_functions;
265 } ipa_edge_args_t;
267 /* ipa_edge_args access functions. Please use these to access fields that
268 are or will be shared among various passes. */
270 /* Set the number of actual arguments. */
272 static inline void
273 ipa_set_cs_argument_count (struct ipa_edge_args *args, int count)
275 args->argument_count = count;
278 /* Return the number of actual arguments. */
280 static inline int
281 ipa_get_cs_argument_count (struct ipa_edge_args *args)
283 return args->argument_count;
286 /* Returns a pointer to the jump function for the ith argument. Please note
287 there is no setter function as jump functions are all set up in
288 ipa_compute_jump_functions. */
290 static inline struct ipa_jump_func *
291 ipa_get_ith_jump_func (struct ipa_edge_args *args, int i)
293 return &args->jump_functions[i];
296 /* Vectors need to have typedefs of structures. */
297 typedef struct ipa_node_params ipa_node_params_t;
299 /* Types of vectors holding the infos. */
300 DEF_VEC_O (ipa_node_params_t);
301 DEF_VEC_ALLOC_O (ipa_node_params_t, heap);
302 DEF_VEC_O (ipa_edge_args_t);
303 DEF_VEC_ALLOC_O (ipa_edge_args_t, gc);
305 /* Vector where the parameter infos are actually stored. */
306 extern VEC (ipa_node_params_t, heap) *ipa_node_params_vector;
307 /* Vector where the parameter infos are actually stored. */
308 extern GTY(()) VEC (ipa_edge_args_t, gc) *ipa_edge_args_vector;
310 /* Return the associated parameter/argument info corresponding to the given
311 node/edge. */
312 #define IPA_NODE_REF(NODE) (VEC_index (ipa_node_params_t, \
313 ipa_node_params_vector, (NODE)->uid))
314 #define IPA_EDGE_REF(EDGE) (VEC_index (ipa_edge_args_t, \
315 ipa_edge_args_vector, (EDGE)->uid))
316 /* This macro checks validity of index returned by
317 ipa_get_param_decl_index function. */
318 #define IS_VALID_JUMP_FUNC_INDEX(I) ((I) != -1)
320 /* Creating and freeing ipa_node_params and ipa_edge_args. */
321 void ipa_create_all_node_params (void);
322 void ipa_create_all_edge_args (void);
323 void ipa_free_edge_args_substructures (struct ipa_edge_args *);
324 void ipa_free_node_params_substructures (struct ipa_node_params *);
325 void ipa_free_all_node_params (void);
326 void ipa_free_all_edge_args (void);
327 void ipa_create_all_structures_for_iinln (void);
328 void ipa_free_all_structures_after_ipa_cp (void);
329 void ipa_free_all_structures_after_iinln (void);
330 void ipa_register_cgraph_hooks (void);
332 /* This function ensures the array of node param infos is big enough to
333 accommodate a structure for all nodes and reallocates it if not. */
335 static inline void
336 ipa_check_create_node_params (void)
338 if (!ipa_node_params_vector)
339 ipa_node_params_vector = VEC_alloc (ipa_node_params_t, heap,
340 cgraph_max_uid);
342 if (VEC_length (ipa_node_params_t, ipa_node_params_vector)
343 <= (unsigned) cgraph_max_uid)
344 VEC_safe_grow_cleared (ipa_node_params_t, heap,
345 ipa_node_params_vector, cgraph_max_uid + 1);
348 /* This function ensures the array of edge arguments infos is big enough to
349 accommodate a structure for all edges and reallocates it if not. */
351 static inline void
352 ipa_check_create_edge_args (void)
354 if (!ipa_edge_args_vector)
355 ipa_edge_args_vector = VEC_alloc (ipa_edge_args_t, gc,
356 cgraph_edge_max_uid);
358 if (VEC_length (ipa_edge_args_t, ipa_edge_args_vector)
359 <= (unsigned) cgraph_edge_max_uid)
360 VEC_safe_grow_cleared (ipa_edge_args_t, gc, ipa_edge_args_vector,
361 cgraph_edge_max_uid + 1);
364 /* Returns true if the array of edge infos is large enough to accommodate an
365 info for EDGE. The main purpose of this function is that debug dumping
366 function can check info availability without causing reallocations. */
368 static inline bool
369 ipa_edge_args_info_available_for_edge_p (struct cgraph_edge *edge)
371 return ((unsigned) edge->uid < VEC_length (ipa_edge_args_t,
372 ipa_edge_args_vector));
375 /* A function list element. It is used to create a temporary worklist used in
376 the propagation stage of IPCP. (can be used for more IPA optimizations) */
377 struct ipa_func_list
379 struct cgraph_node *node;
380 struct ipa_func_list *next;
383 /* ipa_func_list interface. */
384 struct ipa_func_list *ipa_init_func_list (void);
385 void ipa_push_func_to_list_1 (struct ipa_func_list **, struct cgraph_node *,
386 struct ipa_node_params *);
387 struct cgraph_node *ipa_pop_func_from_list (struct ipa_func_list **);
389 /* Add cgraph NODE to the worklist WL if it is not already in one. */
391 static inline void
392 ipa_push_func_to_list (struct ipa_func_list **wl, struct cgraph_node *node)
394 struct ipa_node_params *info = IPA_NODE_REF (node);
396 if (!info->node_enqueued)
397 ipa_push_func_to_list_1 (wl, node, info);
400 void ipa_analyze_node (struct cgraph_node *);
402 /* Function formal parameters related computations. */
403 void ipa_initialize_node_params (struct cgraph_node *node);
404 bool ipa_propagate_indirect_call_infos (struct cgraph_edge *cs,
405 VEC (cgraph_edge_p, heap) **new_edges);
407 /* Debugging interface. */
408 void ipa_print_node_params (FILE *, struct cgraph_node *node);
409 void ipa_print_all_params (FILE *);
410 void ipa_print_node_jump_functions (FILE *f, struct cgraph_node *node);
411 void ipa_print_all_jump_functions (FILE * f);
413 /* Structure to describe transformations of formal parameters and actual
414 arguments. Each instance describes one new parameter and they are meant to
415 be stored in a vector. Additionally, most users will probably want to store
416 adjustments about parameters that are being removed altogether so that SSA
417 names belonging to them can be replaced by SSA names of an artificial
418 variable. */
419 struct ipa_parm_adjustment
421 /* The original PARM_DECL itself, helpful for processing of the body of the
422 function itself. Intended for traversing function bodies.
423 ipa_modify_formal_parameters, ipa_modify_call_arguments and
424 ipa_combine_adjustments ignore this and use base_index.
425 ipa_modify_formal_parameters actually sets this. */
426 tree base;
428 /* Type of the new parameter. However, if by_ref is true, the real type will
429 be a pointer to this type. */
430 tree type;
432 /* The new declaration when creating/replacing a parameter. Created by
433 ipa_modify_formal_parameters, useful for functions modifying the body
434 accordingly. */
435 tree reduction;
437 /* New declaration of a substitute variable that we may use to replace all
438 non-default-def ssa names when a parm decl is going away. */
439 tree new_ssa_base;
441 /* If non-NULL and the original parameter is to be removed (copy_param below
442 is NULL), this is going to be its nonlocalized vars value. */
443 tree nonlocal_value;
445 /* Offset into the original parameter (for the cases when the new parameter
446 is a component of an original one). */
447 HOST_WIDE_INT offset;
449 /* Zero based index of the original parameter this one is based on. (ATM
450 there is no way to insert a new parameter out of the blue because there is
451 no need but if it arises the code can be easily exteded to do so.) */
452 int base_index;
454 /* This new parameter is an unmodified parameter at index base_index. */
455 unsigned copy_param : 1;
457 /* This adjustment describes a parameter that is about to be removed
458 completely. Most users will probably need to book keep those so that they
459 don't leave behinfd any non default def ssa names belonging to them. */
460 unsigned remove_param : 1;
462 /* The parameter is to be passed by reference. */
463 unsigned by_ref : 1;
466 typedef struct ipa_parm_adjustment ipa_parm_adjustment_t;
467 DEF_VEC_O (ipa_parm_adjustment_t);
468 DEF_VEC_ALLOC_O (ipa_parm_adjustment_t, heap);
470 typedef VEC (ipa_parm_adjustment_t, heap) *ipa_parm_adjustment_vec;
472 VEC(tree, heap) *ipa_get_vector_of_formal_parms (tree fndecl);
473 void ipa_modify_formal_parameters (tree fndecl, ipa_parm_adjustment_vec,
474 const char *);
475 void ipa_modify_call_arguments (struct cgraph_edge *, gimple,
476 ipa_parm_adjustment_vec);
477 ipa_parm_adjustment_vec ipa_combine_adjustments (ipa_parm_adjustment_vec,
478 ipa_parm_adjustment_vec);
479 void ipa_dump_param_adjustments (FILE *, ipa_parm_adjustment_vec, tree);
481 void ipa_prop_write_jump_functions (cgraph_node_set set);
482 void ipa_prop_read_jump_functions (void);
483 void ipa_update_after_lto_read (void);
485 /* From tree-sra.c: */
486 bool build_ref_for_offset (tree *, tree, HOST_WIDE_INT, tree, bool);
488 #endif /* IPA_PROP_H */