2008-05-30 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / ipa-prop.h
blob3be7502ae8c16c86d4aaa02658cf2117404805ea
1 /* Interprocedural analyses.
2 Copyright (C) 2005, 2007 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"
25 /* The following definitions and interfaces are used by
26 interprocedural analyses. */
28 /* A jump function for a callsite represents the values passed as actual
29 arguments of the callsite. There are three main types of values :
30 Formal - the caller's formal parameter is passed as an actual argument.
31 Constant - a constant is passed as an actual argument.
32 Unknown - neither of the above.
33 Integer and real constants are represented as IPA_CONST and Fortran
34 constants are represented as IPA_CONST_REF. */
35 enum jump_func_type
37 IPA_UNKNOWN,
38 IPA_CONST,
39 IPA_CONST_REF,
40 IPA_PASS_THROUGH
43 /* All formal parameters in the program have a lattice associated with it
44 computed by the interprocedural stage of IPCP.
45 There are three main values of the lattice:
46 TOP - unknown.
47 BOTTOM - non constant.
48 CONSTANT_TYPE - constant value.
49 Cval of formal f will have a constant value if all callsites to this
50 function have the same constant value passed to f.
51 Integer and real constants are represented as IPA_CONST and Fortran
52 constants are represented as IPA_CONST_REF. */
53 enum ipa_lattice_type
55 IPA_BOTTOM,
56 IPA_CONST_VALUE,
57 IPA_CONST_VALUE_REF,
58 IPA_TOP
61 /* Represents a value of a jump function.
62 value represents a constant.
63 formal_id is used only in jump function context and represents
64 pass-through parameter (the formal of caller is passed as argument). */
65 union jump_func_value
67 unsigned int formal_id;
68 tree constant;
71 /* A jump function for a callsite represents the values passed as actual
72 arguments of the callsite. See enum jump_func_type for the various
73 types of jump functions supported. */
74 struct ipa_jump_func
76 enum jump_func_type type;
77 union jump_func_value value;
80 /* All formal parameters in the program have a cval computed by
81 the interprocedural stage of IPCP. See enum ipa_lattice_type for
82 the various types of lattices supported */
83 struct ipcp_lattice
85 enum ipa_lattice_type type;
86 tree constant;
89 /* Represent which DECL tree (or reference to such tree)
90 will be replaced by another tree while versioning. */
91 struct ipa_replace_map
93 /* The tree that will be replaced. */
94 tree old_tree;
95 /* The new (replacing) tree. */
96 tree new_tree;
97 /* True when a substitution should be done, false otherwise. */
98 bool replace_p;
99 /* True when we replace a reference to old_tree. */
100 bool ref_p;
103 /* Return the field in cgraph_node/cgraph_edge struct that points
104 to ipa_node_params/ipa_edge_args struct. */
105 #define IPA_NODE_REF(MT) ((struct ipa_node_params *)(MT)->aux)
106 #define IPA_EDGE_REF(EDGE) ((struct ipa_edge_args *)(EDGE)->aux)
107 /* This macro checks validity of index returned by
108 ipa_get_param_decl_index function. */
109 #define IS_VALID_JUMP_FUNC_INDEX(I) ((I) != -1)
111 /* ipa_node_params stores information related to formal parameters of functions
112 and some other information for interprocedural passes that operate on
113 parameters (such as ipa-cp). */
115 struct ipa_node_params
117 /* Number of formal parameters of this function. When set to 0,
118 this functions's parameters would not be analyzed by the different
119 stages of IPA CP. */
120 int param_count;
121 /* Array of lattices. */
122 struct ipcp_lattice *ipcp_lattices;
123 /* Mapping each parameter to its PARM_DECL tree. */
124 tree *param_decls;
125 /* Indicating which parameter is modified in its function. */
126 bool *modified_flags;
127 /* Only for versioned nodes this field would not be NULL,
128 it points to the node that IPA cp cloned from. */
129 struct cgraph_node *ipcp_orig_node;
130 /* Meaningful only for original functions. Expresses the
131 ratio between the direct calls and sum of all invocations of
132 this function (given by profiling info). It is used to calculate
133 the profiling information of the original function and the versioned
134 one. */
135 gcov_type count_scale;
137 /* Whether this fynction is called with variable number of actual
138 arguments. */
139 unsigned called_with_var_arguments : 1;
142 /* ipa_node_params access functions. Please use these to access fields that
143 are or will be shared among various passes. */
145 /* Set the number of formal parameters. */
146 static inline void
147 ipa_set_param_count (struct ipa_node_params *info, int count)
149 info->param_count = count;
152 /* Return the number of formal parameters. */
153 static inline int
154 ipa_get_param_count (struct ipa_node_params *info)
156 return info->param_count;
159 /* Returns the declaration of ith param of the corresponding node. Note there
160 is no setter function as this array is built just once using
161 ipa_create_param_decls_array. */
162 static inline tree
163 ipa_get_ith_param (struct ipa_node_params *info, int i)
165 return info->param_decls[i];
168 /* Returns the modification flag corresponding o the ith paramterer. Note
169 there is no setter method as the goal is to set all flags when building the
170 array in ipa_detect_param_modifications. */
171 static inline bool
172 ipa_is_ith_param_modified (struct ipa_node_params *info, int i)
174 return info->modified_flags[i];
177 /* Flag this node as having callers with variable number of arguments. */
178 static inline void
179 ipa_set_called_with_variable_arg (struct ipa_node_params *info)
181 info->called_with_var_arguments = 1;
184 /* Have we detected this node was called with variable number of arguments? */
185 static inline bool
186 ipa_is_called_with_var_arguments (struct ipa_node_params *info)
188 return info->called_with_var_arguments;
193 /* ipa_edge_args stores information related to a callsite and particularly
194 its arguments. It is pointed to by a field in the
195 callsite's corresponding cgraph_edge. */
196 struct ipa_edge_args
198 /* Number of actual arguments in this callsite. When set to 0,
199 this callsite's parameters would not be analyzed by the different
200 stages of IPA CP. */
201 int argument_count;
202 /* Array of the callsite's jump function of each parameter. */
203 struct ipa_jump_func *jump_functions;
206 /* ipa_edge_args access functions. Please use these to access fields that
207 are or will be shared among various passes. */
209 /* Set the number of actual arguments. */
210 static inline void
211 ipa_set_cs_argument_count (struct ipa_edge_args *args, int count)
213 args->argument_count = count;
216 /* Return the number of actual arguments. */
217 static inline int
218 ipa_get_cs_argument_count (struct ipa_edge_args *args)
220 return args->argument_count;
223 /* Returns a pointer to the jump function for the ith argument. Please note
224 there is no setter function as jump functions are all set up in
225 ipa_compute_jump_functions. */
226 static inline struct ipa_jump_func *
227 ipa_get_ith_jump_func (struct ipa_edge_args *args, int i)
229 return &args->jump_functions[i];
232 /* A function list element. It is used to create a temporary worklist used in
233 the propagation stage of IPCP. (can be used for more IPA optimizations) */
234 struct ipa_func_list
236 struct cgraph_node *node;
237 struct ipa_func_list *next;
240 /* ipa_func_list interface. */
241 struct ipa_func_list *ipa_init_func_list (void);
242 void ipa_push_func_to_list (struct ipa_func_list **, struct cgraph_node *);
243 struct cgraph_node *ipa_pop_func_from_list (struct ipa_func_list **);
245 /* Callsite related calculations. */
246 void ipa_compute_jump_functions (struct cgraph_edge *);
247 void ipa_count_arguments (struct cgraph_edge *);
249 /* Function parameters related computations. */
250 void ipa_count_formal_params (struct cgraph_node *);
251 void ipa_create_param_decls_array (struct cgraph_node *);
252 void ipa_detect_param_modifications (struct cgraph_node *);
254 /* Creating and freeing ipa_node_params and ipa_edge_args. */
255 void ipa_create_node_params (struct cgraph_node *);
256 void ipa_free_all_node_params (void);
257 void ipa_create_all_node_params (void);
258 void ipa_create_all_edge_args (void);
259 void ipa_free_all_edge_args (void);
261 /* Debugging interface. */
262 void ipa_print_all_tree_maps (FILE *);
263 void ipa_print_all_params_modified (FILE *);
265 #endif /* IPA_PROP_H */