2007-03-01 Paul Brook <paul@codesourcery.com>
[official-gcc.git] / gcc / ipa-prop.h
blob482b6e39b07e3e476d08e0f5a748ed44a0c6b49f
1 /* Interprocedural analyses.
2 Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA. */
21 #ifndef IPA_PROP_H
22 #define IPA_PROP_H
24 #include "tree.h"
26 /* The following definitions and interfaces are used by
27 interprocedural analyses. */
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 CONST_IPATYPE and Fortran
35 constants are represented as CONST_IPATYPE_REF. */
36 enum jump_func_type
38 UNKNOWN_IPATYPE,
39 CONST_IPATYPE,
40 CONST_IPATYPE_REF,
41 FORMAL_IPATYPE
44 /* All formal parameters in the program have a cval computed by
45 the interprocedural stage of IPCP.
46 There are three main values of cval :
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 CONST_IPATYPE and Fortran
53 constants are represented as CONST_IPATYPE_REF. */
54 enum cvalue_type
56 BOTTOM,
57 CONST_VALUE,
58 CONST_VALUE_REF,
59 TOP
62 /* Represents the value of either jump function or cval.
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
66 as argument). */
67 union parameter_info
69 unsigned int formal_id;
70 tree value;
73 /* A jump function for a callsite represents the values passed as actual
74 arguments of the callsite. See enum jump_func_type for the various
75 types of jump functions supported. */
76 struct ipa_jump_func
78 enum jump_func_type type;
79 union parameter_info info_type;
82 /* All formal parameters in the program have a cval computed by
83 the interprocedural stage of IPCP. See enum cvalue_type for
84 the various types of cvals supported */
85 struct ipcp_formal
87 enum cvalue_type cval_type;
88 union parameter_info cvalue;
91 /* Represent which DECL tree (or reference to such tree)
92 will be replaced by another tree while versioning. */
93 struct ipa_replace_map
95 /* The tree that will be replaced. */
96 tree old_tree;
97 /* The new (replacing) tree. */
98 tree new_tree;
99 /* True when a substitution should be done, false otherwise. */
100 bool replace_p;
101 /* True when we replace a reference to old_tree. */
102 bool ref_p;
105 /* Return the field in cgraph_node/cgraph_edge struct that points
106 to ipa_node/ipa_edge struct. */
107 #define IPA_NODE_REF(MT) ((struct ipa_node *)(MT)->aux)
108 #define IPA_EDGE_REF(EDGE) ((struct ipa_edge *)(EDGE)->aux)
109 /* This macro checks validity of index returned by
110 ipa_method_tree_map function. */
111 #define IS_VALID_TREE_MAP_INDEX(I) ((I) != -1)
113 /* ipa_node stores information related to a method and
114 its formal parameters. It is pointed to by a field in the
115 method's corresponding cgraph_node.
117 ipa_edge stores information related to a callsite and
118 its arguments. It is pointed to by a field in the
119 callsite's corresponding cgraph_edge. */
120 struct ipa_node
122 /* Number of formal parameters of this method. When set to 0,
123 this method's parameters would not be analyzed by the different
124 stages of IPA CP. */
125 int ipa_arg_num;
126 /* Array of cvals. */
127 struct ipcp_formal *ipcp_cval;
128 /* Mapping each parameter to its PARM_DECL tree. */
129 tree *ipa_param_tree;
130 /* Indicating which parameter is modified in its method. */
131 bool *ipa_mod;
132 /* Only for versioned nodes this field would not be NULL,
133 it points to the node that IPA cp cloned from. */
134 struct cgraph_node *ipcp_orig_node;
135 /* Meaningful only for original methods. Expresses the
136 ratio between the direct calls and sum of all invocations of
137 this function (given by profiling info). It is used to calculate
138 the profiling information of the original function and the versioned
139 one. */
140 gcov_type count_scale;
143 struct ipa_edge
145 /* Number of actual arguments in this callsite. When set to 0,
146 this callsite's parameters would not be analyzed by the different
147 stages of IPA CP. */
148 int ipa_param_num;
149 /* Array of the callsite's jump function of each parameter. */
150 struct ipa_jump_func *ipa_param_map;
153 /* A methodlist element (referred to also as methodlist node). It is used
154 to create a temporary worklist used in
155 the propagation stage of IPCP. (can be used for more IPA
156 optimizations) */
157 struct ipa_methodlist
159 struct cgraph_node *method_p;
160 struct ipa_methodlist *next_method;
163 /* A pointer to a methodlist element. */
164 typedef struct ipa_methodlist *ipa_methodlist_p;
166 /* ipa_methodlist interface. */
167 ipa_methodlist_p ipa_methodlist_init (void);
168 bool ipa_methodlist_not_empty (ipa_methodlist_p);
169 void ipa_add_method (ipa_methodlist_p *, struct cgraph_node *);
170 struct cgraph_node *ipa_remove_method (ipa_methodlist_p *);
172 /* ipa_callsite interface. */
173 int ipa_callsite_param_count (struct cgraph_edge *);
174 void ipa_callsite_param_count_set (struct cgraph_edge *, int);
175 struct ipa_jump_func *ipa_callsite_param (struct cgraph_edge *, int);
176 struct cgraph_node *ipa_callsite_callee (struct cgraph_edge *);
177 void ipa_callsite_compute_param (struct cgraph_edge *);
178 void ipa_callsite_compute_count (struct cgraph_edge *);
180 /* ipa_method interface. */
181 int ipa_method_formal_count (struct cgraph_node *);
182 void ipa_method_formal_count_set (struct cgraph_node *, int);
183 tree ipa_method_get_tree (struct cgraph_node *, int);
184 void ipa_method_compute_tree_map (struct cgraph_node *);
185 void ipa_method_formal_compute_count (struct cgraph_node *);
186 void ipa_method_compute_modify (struct cgraph_node *);
188 /* jump function interface. */
189 enum jump_func_type get_type (struct ipa_jump_func *);
190 union parameter_info *ipa_jf_get_info_type (struct ipa_jump_func *);
192 /* ipa_node and ipa_edge interfaces. */
193 void ipa_node_create (struct cgraph_node *);
194 void ipa_free (void);
195 void ipa_nodes_create (void);
196 void ipa_edges_create (void);
197 void ipa_edges_free (void);
198 void ipa_nodes_free (void);
201 /* Debugging interface. */
202 void ipa_method_tree_print (FILE *);
203 void ipa_method_modify_print (FILE *);
205 #endif /* IPA_PROP_H */