OSDN Git Service

libjava/classpath/
[pf3gnuchains/gcc-fork.git] / gcc / ipa-prop.h
1 /* Interprocedural analyses.
2    Copyright (C) 2005, 2007, 2008 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
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.
10
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.
15
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/>.  */
19
20 #ifndef IPA_PROP_H
21 #define IPA_PROP_H
22
23 #include "tree.h"
24 #include "vec.h"
25
26 /* The following definitions and interfaces are used by
27    interprocedural analyses.  */
28
29 /* A jump function for a callsite represents the values passed as actual 
30    arguments of the callsite. There are three main types of values :
31    Formal - the caller's formal parameter is passed as an actual argument.
32    Constant - a constant is passed as an actual argument.
33    Unknown - neither of the above.
34    Integer and real constants are represented as IPA_CONST and Fortran
35    constants are represented as IPA_CONST_REF.  */
36 enum jump_func_type
37 {
38   IPA_UNKNOWN,
39   IPA_CONST,
40   IPA_CONST_REF,
41   IPA_PASS_THROUGH
42 };
43
44 /* All formal parameters in the program have a lattice associated with it
45    computed by the interprocedural stage of IPCP.
46    There are three main values of the lattice:
47    TOP - unknown.
48    BOTTOM - non constant.
49    CONSTANT_TYPE - constant value.
50    Cval of formal f will have a constant value if all callsites to this
51    function have the same constant value passed to f.
52    Integer and real constants are represented as IPA_CONST and Fortran
53    constants are represented as IPA_CONST_REF.  */
54 enum ipa_lattice_type
55 {
56   IPA_BOTTOM,
57   IPA_CONST_VALUE,
58   IPA_CONST_VALUE_REF,
59   IPA_TOP
60 };
61
62 /* Represents a value of a jump function.
63    value represents a constant.
64    formal_id is used only in jump function context and represents 
65    pass-through parameter (the formal of caller is passed as argument).  */
66 union jump_func_value
67 {
68   unsigned int formal_id;
69   tree constant;
70 };
71
72 /* A jump function for a callsite represents the values passed as actual 
73    arguments of the callsite. See enum jump_func_type for the various 
74    types of jump functions supported.  */
75 struct ipa_jump_func
76 {
77   enum jump_func_type type;
78   union jump_func_value value;
79 };
80
81 /* All formal parameters in the program have a cval computed by 
82    the interprocedural stage of IPCP. See enum ipa_lattice_type for
83    the various types of lattices supported */
84 struct ipcp_lattice
85 {
86   enum ipa_lattice_type type;
87   tree constant;
88 };
89
90 /* Represent which DECL tree (or reference to such tree)
91    will be replaced by another tree while versioning.  */
92 struct ipa_replace_map
93 {
94   /* The tree that will be replaced.  */
95   tree old_tree;
96   /* The new (replacing) tree.  */ 
97   tree new_tree;
98   /* True when a substitution should be done, false otherwise.  */
99   bool replace_p;
100   /* True when we replace a reference to old_tree.  */
101   bool ref_p;
102 };
103
104 /* ipa_node_params stores information related to formal parameters of functions
105    and some other information for interprocedural passes that operate on
106    parameters (such as ipa-cp).  */
107
108 struct ipa_node_params
109 {
110   /* Number of formal parameters of this function.  When set to 0,
111      this function's parameters would not be analyzed by the different
112      stages of IPA CP.  */
113   int param_count;
114   /* Array of lattices.  */
115   struct ipcp_lattice *ipcp_lattices;
116   /* Mapping each parameter to its PARM_DECL tree.  */
117   tree *param_decls;
118   /* Indicating which parameter is modified in its function.  */
119   bool *modified_flags;
120   /* Only for versioned nodes this field would not be NULL,
121      it points to the node that IPA cp cloned from.  */
122   struct cgraph_node *ipcp_orig_node;
123   /* Meaningful only for original functions.  Expresses the
124      ratio between the direct calls and sum of all invocations of 
125      this function (given by profiling info).  It is used to calculate 
126      the profiling information of the original function and the versioned
127      one.  */
128   gcov_type count_scale;
129
130   /* Whether this function is called with variable number of actual
131      arguments.  */
132   unsigned called_with_var_arguments : 1;
133 };
134
135 /* ipa_node_params access functions.  Please use these to access fields that
136    are or will be shared among various passes.  */
137
138 /* Set the number of formal parameters. */
139 static inline void
140 ipa_set_param_count (struct ipa_node_params *info, int count)
141 {
142   info->param_count = count;
143 }
144
145 /* Return the number of formal parameters. */
146 static inline int
147 ipa_get_param_count (struct ipa_node_params *info)
148 {
149   return info->param_count;
150 }
151
152 /* Returns the declaration of ith param of the corresponding node.  Note there
153    is no setter function as this array is built just once using
154    ipa_create_param_decls_array. */
155 static inline tree
156 ipa_get_ith_param (struct ipa_node_params *info, int i)
157 {
158   return info->param_decls[i];
159 }
160
161 /* Returns the modification flag corresponding to the ith parameter.  Note
162    there is no setter method as the goal is to set all flags when building the
163    array in ipa_detect_param_modifications.  */
164 static inline bool
165 ipa_is_ith_param_modified (struct ipa_node_params *info, int i)
166 {
167   return info->modified_flags[i];
168 }
169
170 /* Flag this node as having callers with variable number of arguments.  */
171 static inline void
172 ipa_set_called_with_variable_arg (struct ipa_node_params *info)
173 {
174   info->called_with_var_arguments = 1;
175 }
176
177 /* Have we detected this node was called with variable number of arguments? */
178 static inline bool
179 ipa_is_called_with_var_arguments (struct ipa_node_params *info)
180 {
181   return info->called_with_var_arguments;
182 }
183
184
185
186 /* ipa_edge_args stores information related to a callsite and particularly
187    its arguments. It is pointed to by a field in the
188    callsite's corresponding cgraph_edge.  */
189 struct ipa_edge_args
190 {
191   /* Number of actual arguments in this callsite.  When set to 0,
192      this callsite's parameters would not be analyzed by the different
193      stages of IPA CP.  */
194   int argument_count;
195   /* Array of the callsite's jump function of each parameter.  */
196   struct ipa_jump_func *jump_functions;
197 };
198
199 /* ipa_edge_args access functions.  Please use these to access fields that
200    are or will be shared among various passes.  */
201
202 /* Set the number of actual arguments. */
203 static inline void
204 ipa_set_cs_argument_count (struct ipa_edge_args *args, int count)
205 {
206   args->argument_count = count;
207 }
208
209 /* Return the number of actual arguments. */
210 static inline int
211 ipa_get_cs_argument_count (struct ipa_edge_args *args)
212 {
213   return args->argument_count;
214 }
215
216 /* Returns a pointer to the jump function for the ith argument.  Please note
217    there is no setter function as jump functions are all set up in
218    ipa_compute_jump_functions. */
219 static inline struct ipa_jump_func *
220 ipa_get_ith_jump_func (struct ipa_edge_args *args, int i)
221 {
222   return &args->jump_functions[i];
223 }
224
225 /* Vectors need to have typedefs of structures.  */
226 typedef struct ipa_node_params ipa_node_params_t;
227 typedef struct ipa_edge_args ipa_edge_args_t;
228
229 /* Types of vectors hodling the infos.  */
230 DEF_VEC_O (ipa_node_params_t);
231 DEF_VEC_ALLOC_O (ipa_node_params_t, heap);
232 DEF_VEC_O (ipa_edge_args_t);
233 DEF_VEC_ALLOC_O (ipa_edge_args_t, heap);
234
235 /* Vector where the parameter infos are actually stored. */
236 extern VEC (ipa_node_params_t, heap) *ipa_node_params_vector;
237 /* Vector where the parameter infos are actually stored. */
238 extern VEC (ipa_edge_args_t, heap) *ipa_edge_args_vector;
239
240 /* Return the associated parameter/argument info corresponding to the given
241    node/edge.  */
242 #define IPA_NODE_REF(NODE) (VEC_index (ipa_node_params_t, \
243                                        ipa_node_params_vector, (NODE)->uid))
244 #define IPA_EDGE_REF(EDGE) (VEC_index (ipa_edge_args_t, \
245                                        ipa_edge_args_vector, (EDGE)->uid))
246 /* This macro checks validity of index returned by
247    ipa_get_param_decl_index function.  */
248 #define IS_VALID_JUMP_FUNC_INDEX(I) ((I) != -1)
249
250 /* Creating and freeing ipa_node_params and ipa_edge_args.  */
251 void ipa_create_all_node_params (void);
252 void ipa_create_all_edge_args (void);
253 void ipa_free_edge_args_substructures (struct ipa_edge_args *);
254 void ipa_free_node_params_substructures (struct ipa_node_params *);
255 void ipa_free_all_node_params (void);
256 void ipa_free_all_edge_args (void);
257 void free_all_ipa_structures_after_ipa_cp (void);
258 void ipa_register_cgraph_hooks (void);
259
260 /* This function ensures the array of node param infos is big enough to
261    accomdate a structure for all nodes and realloacates it if not.  */
262 static inline void
263 ipa_check_create_node_params (void)
264 {
265   if (!ipa_node_params_vector)
266     ipa_node_params_vector = VEC_alloc (ipa_node_params_t, heap,
267                                         cgraph_max_uid);
268
269   if (VEC_length (ipa_node_params_t, ipa_node_params_vector)
270       <= (unsigned) cgraph_max_uid)
271     VEC_safe_grow_cleared (ipa_node_params_t, heap,
272                            ipa_node_params_vector, cgraph_max_uid + 1);
273 }
274
275 /* This function ensures the array of adge arguments infos is big enough to
276    accomdate a structure for all edges and realloacates it if not.  */
277 static inline void
278 ipa_check_create_edge_args (void)
279 {
280   if (!ipa_edge_args_vector)
281     ipa_edge_args_vector = VEC_alloc (ipa_edge_args_t, heap,
282                                       cgraph_edge_max_uid);
283
284   if (VEC_length (ipa_edge_args_t, ipa_edge_args_vector)
285       <=  (unsigned) cgraph_edge_max_uid)
286     VEC_safe_grow_cleared (ipa_edge_args_t, heap, ipa_edge_args_vector,
287                            cgraph_edge_max_uid + 1);
288 }
289
290 /* A function list element.  It is used to create a temporary worklist used in
291    the propagation stage of IPCP. (can be used for more IPA optimizations)  */
292 struct ipa_func_list
293 {
294   struct cgraph_node *node;
295   struct ipa_func_list *next;
296 };
297
298 /* ipa_func_list interface.  */
299 struct ipa_func_list *ipa_init_func_list (void);
300 void ipa_push_func_to_list (struct ipa_func_list **, struct cgraph_node *);
301 struct cgraph_node *ipa_pop_func_from_list (struct ipa_func_list **);
302
303 /* Callsite related calculations.  */
304 void ipa_compute_jump_functions (struct cgraph_edge *);
305 void ipa_count_arguments (struct cgraph_edge *);
306
307 /* Function parameters related computations.  */
308 void ipa_count_formal_params (struct cgraph_node *);
309 void ipa_create_param_decls_array (struct cgraph_node *);
310 void ipa_detect_param_modifications (struct cgraph_node *);
311
312 /* Debugging interface.  */
313 void ipa_print_all_tree_maps (FILE *);
314 void ipa_print_all_params_modified (FILE *);
315
316 #endif /* IPA_PROP_H */