PR testsuite/39776
[official-gcc.git] / gcc / ipa-prop.h
blob5943a2af6f49a35b624c081b3ca71ff523066c5a
1 /* Interprocedural analyses.
2 Copyright (C) 2005, 2007, 2008 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef IPA_PROP_H
21 #define IPA_PROP_H
23 #include "tree.h"
24 #include "vec.h"
25 #include "cgraph.h"
27 /* The following definitions and interfaces are used by
28 interprocedural analyses or parameters. */
30 /* ipa-prop.c stuff (ipa-cp, indirect inlining): */
32 /* A jump function for a callsite represents the values passed as actual
33 arguments of the callsite. There are three main types of values :
34 Formal - the caller's formal parameter is passed as an actual argument.
35 Constant - a constant is passed as an actual argument.
36 Unknown - neither of the above.
37 Integer and real constants are represented as IPA_JF_CONST.
38 Finally, IPA_JF_CONST_MEMBER_PTR stands for C++ member pointers
39 constants. */
40 enum jump_func_type
42 IPA_JF_UNKNOWN = 0, /* newly allocated and zeroed jump functions default */
43 IPA_JF_CONST,
44 IPA_JF_CONST_MEMBER_PTR,
45 IPA_JF_PASS_THROUGH
48 /* All formal parameters in the program have a lattice associated with it
49 computed by the interprocedural stage of IPCP.
50 There are three main values of the lattice:
51 IPA_TOP - unknown,
52 IPA_BOTTOM - non constant,
53 IPA_CONST_VALUE - simple scalar constant,
54 Cval of formal f will have a constant value if all callsites to this
55 function have the same constant value passed to f.
56 Integer and real constants are represented as IPA_CONST_VALUE. */
57 enum ipa_lattice_type
59 IPA_BOTTOM,
60 IPA_CONST_VALUE,
61 IPA_TOP
64 /* Structure holding a C++ member pointer constant. Holds a pointer to the
65 method and delta offset. */
66 struct ipa_member_ptr_cst
68 tree pfn;
69 tree delta;
72 /* Represents a value of a jump function. formal_id is used only in jump
73 function context and represents pass-through parameter (the formal parameter
74 of the caller is passed as argument). constant represents the actual
75 constant in constant jump functions and member_cst holds constant c++ member
76 functions. */
77 union jump_func_value
79 unsigned int formal_id;
80 tree constant;
81 struct ipa_member_ptr_cst member_cst;
84 /* A jump function for a callsite represents the values passed as actual
85 arguments of the callsite. See enum jump_func_type for the various
86 types of jump functions supported. */
87 struct ipa_jump_func
89 enum jump_func_type type;
90 union jump_func_value value;
93 /* All formal parameters in the program have a cval computed by
94 the interprocedural stage of IPCP. See enum ipa_lattice_type for
95 the various types of lattices supported */
96 struct ipcp_lattice
98 enum ipa_lattice_type type;
99 tree constant;
102 /* Represent which DECL tree (or reference to such tree)
103 will be replaced by another tree while versioning. */
104 struct ipa_replace_map
106 /* The tree that will be replaced. */
107 tree old_tree;
108 /* The new (replacing) tree. */
109 tree new_tree;
110 /* True when a substitution should be done, false otherwise. */
111 bool replace_p;
112 /* True when we replace a reference to old_tree. */
113 bool ref_p;
116 /* Each instance of the following structure describes a statement that calls a
117 function parameter. Those referring to statements within the same function
118 are linked in a list. */
119 struct ipa_param_call_note
121 /* Linked list's next */
122 struct ipa_param_call_note *next;
123 /* Statement that contains the call to the parameter above. */
124 gimple stmt;
125 /* Index of the parameter that is called. */
126 unsigned int formal_id;
127 /* Expected number of executions: calculated in profile.c. */
128 gcov_type count;
129 /* Expected frequency of executions within the function. see cgraph_edge in
130 cgraph.h for more on this. */
131 int frequency;
132 /* Depth of loop nest, 1 means no loop nest. */
133 int loop_nest;
134 /* Set when we have already found the target to be a compile time constant
135 and turned this into an edge or when the note was found unusable for some
136 reason. */
137 bool processed;
140 /* Structure describing a single formal parameter. */
141 struct ipa_param_descriptor
143 /* IPA-CP lattice. */
144 struct ipcp_lattice ipcp_lattice;
145 /* PARAM_DECL of this parameter. */
146 tree decl;
147 /* Whether the value parameter has been modified within the function. */
148 unsigned modified : 1;
149 /* Whether the parameter has been used as a call destination. */
150 unsigned called : 1;
153 /* ipa_node_params stores information related to formal parameters of functions
154 and some other information for interprocedural passes that operate on
155 parameters (such as ipa-cp). */
156 struct ipa_node_params
158 /* Number of formal parameters of this function. When set to 0,
159 this function's parameters would not be analyzed by the different
160 stages of IPA CP. */
161 int param_count;
162 /* Pointer to an array of structures describing individual formal
163 parameters. */
164 struct ipa_param_descriptor *params;
165 /* List of structures enumerating calls to a formal parameter. */
166 struct ipa_param_call_note *param_calls;
167 /* Only for versioned nodes this field would not be NULL,
168 it points to the node that IPA cp cloned from. */
169 struct cgraph_node *ipcp_orig_node;
170 /* Meaningful only for original functions. Expresses the
171 ratio between the direct calls and sum of all invocations of
172 this function (given by profiling info). It is used to calculate
173 the profiling information of the original function and the versioned
174 one. */
175 gcov_type count_scale;
177 /* Whether this function is called with variable number of actual
178 arguments. */
179 unsigned called_with_var_arguments : 1;
180 /* Whether the modification analysis has already been performed. */
181 unsigned modification_analysis_done : 1;
182 /* Whether the param uses analysis has already been performed. */
183 unsigned uses_analysis_done : 1;
186 /* ipa_node_params access functions. Please use these to access fields that
187 are or will be shared among various passes. */
189 /* Set the number of formal parameters. */
191 static inline void
192 ipa_set_param_count (struct ipa_node_params *info, int count)
194 info->param_count = count;
197 /* Return the number of formal parameters. */
199 static inline int
200 ipa_get_param_count (struct ipa_node_params *info)
202 return info->param_count;
205 /* Return the declaration of Ith formal parameter of the function corresponding
206 to INFO. Note there is no setter function as this array is built just once
207 using ipa_initialize_node_params. */
209 static inline tree
210 ipa_get_param (struct ipa_node_params *info, int i)
212 return info->params[i].decl;
215 /* Return the modification flag corresponding to the Ith formal parameter of
216 the function associated with INFO. Note that there is no setter method as
217 the goal is to set all flags when building the array in
218 ipa_detect_param_modifications. */
220 static inline bool
221 ipa_is_param_modified (struct ipa_node_params *info, int i)
223 return info->params[i].modified;
226 /* Return the called flag corresponding to the Ith formal parameter of the
227 function associated with INFO. Note that there is no setter method as the
228 goal is to set all flags when building the array in
229 ipa_detect_called_params. */
231 static inline bool
232 ipa_is_param_called (struct ipa_node_params *info, int i)
234 return info->params[i].called;
237 /* Flag this node as having callers with variable number of arguments. */
239 static inline void
240 ipa_set_called_with_variable_arg (struct ipa_node_params *info)
242 info->called_with_var_arguments = 1;
245 /* Have we detected this node was called with variable number of arguments? */
247 static inline bool
248 ipa_is_called_with_var_arguments (struct ipa_node_params *info)
250 return info->called_with_var_arguments;
255 /* ipa_edge_args stores information related to a callsite and particularly
256 its arguments. It is pointed to by a field in the
257 callsite's corresponding cgraph_edge. */
258 struct ipa_edge_args
260 /* Number of actual arguments in this callsite. When set to 0,
261 this callsite's parameters would not be analyzed by the different
262 stages of IPA CP. */
263 int argument_count;
264 /* Array of the callsite's jump function of each parameter. */
265 struct ipa_jump_func *jump_functions;
268 /* ipa_edge_args access functions. Please use these to access fields that
269 are or will be shared among various passes. */
271 /* Set the number of actual arguments. */
273 static inline void
274 ipa_set_cs_argument_count (struct ipa_edge_args *args, int count)
276 args->argument_count = count;
279 /* Return the number of actual arguments. */
281 static inline int
282 ipa_get_cs_argument_count (struct ipa_edge_args *args)
284 return args->argument_count;
287 /* Returns a pointer to the jump function for the ith argument. Please note
288 there is no setter function as jump functions are all set up in
289 ipa_compute_jump_functions. */
291 static inline struct ipa_jump_func *
292 ipa_get_ith_jump_func (struct ipa_edge_args *args, int i)
294 return &args->jump_functions[i];
297 /* Vectors need to have typedefs of structures. */
298 typedef struct ipa_node_params ipa_node_params_t;
299 typedef struct ipa_edge_args ipa_edge_args_t;
301 /* Types of vectors holding the infos. */
302 DEF_VEC_O (ipa_node_params_t);
303 DEF_VEC_ALLOC_O (ipa_node_params_t, heap);
304 DEF_VEC_O (ipa_edge_args_t);
305 DEF_VEC_ALLOC_O (ipa_edge_args_t, heap);
307 /* Vector where the parameter infos are actually stored. */
308 extern VEC (ipa_node_params_t, heap) *ipa_node_params_vector;
309 /* Vector where the parameter infos are actually stored. */
310 extern VEC (ipa_edge_args_t, heap) *ipa_edge_args_vector;
312 /* Return the associated parameter/argument info corresponding to the given
313 node/edge. */
314 #define IPA_NODE_REF(NODE) (VEC_index (ipa_node_params_t, \
315 ipa_node_params_vector, (NODE)->uid))
316 #define IPA_EDGE_REF(EDGE) (VEC_index (ipa_edge_args_t, \
317 ipa_edge_args_vector, (EDGE)->uid))
318 /* This macro checks validity of index returned by
319 ipa_get_param_decl_index function. */
320 #define IS_VALID_JUMP_FUNC_INDEX(I) ((I) != -1)
322 /* Creating and freeing ipa_node_params and ipa_edge_args. */
323 void ipa_create_all_node_params (void);
324 void ipa_create_all_edge_args (void);
325 void ipa_free_edge_args_substructures (struct ipa_edge_args *);
326 void ipa_free_node_params_substructures (struct ipa_node_params *);
327 void ipa_free_all_node_params (void);
328 void ipa_free_all_edge_args (void);
329 void free_all_ipa_structures_after_ipa_cp (void);
330 void free_all_ipa_structures_after_iinln (void);
331 void ipa_register_cgraph_hooks (void);
333 /* This function ensures the array of node param infos is big enough to
334 accommodate a structure for all nodes and reallocates it if not. */
336 static inline void
337 ipa_check_create_node_params (void)
339 if (!ipa_node_params_vector)
340 ipa_node_params_vector = VEC_alloc (ipa_node_params_t, heap,
341 cgraph_max_uid);
343 if (VEC_length (ipa_node_params_t, ipa_node_params_vector)
344 <= (unsigned) cgraph_max_uid)
345 VEC_safe_grow_cleared (ipa_node_params_t, heap,
346 ipa_node_params_vector, cgraph_max_uid + 1);
349 /* This function ensures the array of edge arguments infos is big enough to
350 accommodate a structure for all edges and reallocates it if not. */
352 static inline void
353 ipa_check_create_edge_args (void)
355 if (!ipa_edge_args_vector)
356 ipa_edge_args_vector = VEC_alloc (ipa_edge_args_t, heap,
357 cgraph_edge_max_uid);
359 if (VEC_length (ipa_edge_args_t, ipa_edge_args_vector)
360 <= (unsigned) cgraph_edge_max_uid)
361 VEC_safe_grow_cleared (ipa_edge_args_t, heap, ipa_edge_args_vector,
362 cgraph_edge_max_uid + 1);
365 /* Returns true if the array of edge infos is large enough to accommodate an
366 info for EDGE. The main purpose of this function is that debug dumping
367 function can check info availability without causing reallocations. */
369 static inline bool
370 ipa_edge_args_info_available_for_edge_p (struct cgraph_edge *edge)
372 return ((unsigned) edge->uid < VEC_length (ipa_edge_args_t,
373 ipa_edge_args_vector));
376 /* A function list element. It is used to create a temporary worklist used in
377 the propagation stage of IPCP. (can be used for more IPA optimizations) */
378 struct ipa_func_list
380 struct cgraph_node *node;
381 struct ipa_func_list *next;
384 /* ipa_func_list interface. */
385 struct ipa_func_list *ipa_init_func_list (void);
386 void ipa_push_func_to_list (struct ipa_func_list **, struct cgraph_node *);
387 struct cgraph_node *ipa_pop_func_from_list (struct ipa_func_list **);
389 /* Callsite related calculations. */
390 void ipa_compute_jump_functions (struct cgraph_edge *);
391 void ipa_count_arguments (struct cgraph_edge *);
393 /* Function formal parameters related computations. */
394 void ipa_initialize_node_params (struct cgraph_node *node);
395 void ipa_detect_param_modifications (struct cgraph_node *);
396 void ipa_analyze_params_uses (struct cgraph_node *);
397 bool ipa_propagate_indirect_call_infos (struct cgraph_edge *cs,
398 VEC (cgraph_edge_p, heap) **new_edges);
400 /* Debugging interface. */
401 void ipa_print_node_params (FILE *, struct cgraph_node *node);
402 void ipa_print_all_params (FILE *);
403 void ipa_print_node_jump_functions (FILE *f, struct cgraph_node *node);
404 void ipa_print_all_jump_functions (FILE * f);
406 #endif /* IPA_PROP_H */