OSDN Git Service

2006-02-08 Paolo Bonzini <bonzini@gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / ipa-prop.h
1 /* Interprocedural analyses.
2    Copyright (C) 2005 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 2, 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 COPYING.  If not, write to the Free
18 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA.  */
20
21 #ifndef IPA_PROP_H
22 #define IPA_PROP_H
23
24 #include "tree.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 a 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
37 {
38   UNKNOWN_IPATYPE,
39   CONST_IPATYPE,
40   CONST_IPATYPE_REF,
41   FORMAL_IPATYPE
42 };
43
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
55 {
56   BOTTOM,
57   CONST_VALUE,
58   CONST_VALUE_REF,
59   TOP
60 };
61
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
68 {
69   unsigned int formal_id;
70   tree value;
71 };
72
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
77 {
78   enum jump_func_type type;
79   union parameter_info info_type;
80 };
81
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
86 {
87   enum cvalue_type cval_type;
88   union parameter_info cvalue;
89 };
90
91 /* Represent which DECL tree (or reference to such tree)
92    will be replaced by another tree while versioning.  */
93 struct ipa_replace_map
94 {
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;
103 };
104
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
110 /* ipa_node stores information related to a method and
111    its formal parameters. It is pointed to by a field in the
112    method's corresponding cgraph_node.
113
114    ipa_edge stores information related to a callsite and
115    its arguments. It is pointed to by a field in the
116    callsite's corresponding cgraph_edge.  */
117 struct ipa_node
118 {
119   /* Number of formal parameters of this method.  When set to 0,
120      this method's parameters would not be analyzed by the different
121      stages of IPA CP.  */
122   int ipa_arg_num;
123   /* Array of cvals.  */
124   struct ipcp_formal *ipcp_cval;
125   /* Mapping each parameter to its PARM_DECL tree.  */
126   tree *ipa_param_tree;
127   /* Indicating which parameter is modified in its method.  */
128   bool *ipa_mod;
129   /* Only for versioned nodes this field would not be NULL,
130      it points to the node that IPA cp cloned from.  */
131   struct cgraph_node *ipcp_orig_node;
132   /* Meaningful only for original methods.  Expresses the 
133      ratio between the direct calls and sum of all invocations of 
134      this function (given by profiling info).  It is used to calculate 
135      the profiling information of the original function and the versioned
136      one.  */
137   gcov_type count_scale;
138 };
139
140 struct ipa_edge
141 {
142   /* Number of actual arguments in this callsite.  When set to 0,
143      this callsite's parameters would not be analyzed by the different
144      stages of IPA CP.  */
145   int ipa_param_num;
146   /* Array of the callsite's jump function of each parameter.  */
147   struct ipa_jump_func *ipa_param_map;
148 };
149
150 /* A methodlist element (referred to also as methodlist node). It is used 
151    to create a temporary worklist used in 
152    the propagation stage of IPCP. (can be used for more IPA 
153    optimizations)  */
154 struct ipa_methodlist
155 {
156   struct cgraph_node *method_p;
157   struct ipa_methodlist *next_method;
158 };
159
160 /* A pointer to a methodlist element.  */
161 typedef struct ipa_methodlist *ipa_methodlist_p;
162
163 /* ipa_methodlist interface.  */
164 ipa_methodlist_p ipa_methodlist_init (void);
165 bool ipa_methodlist_not_empty (ipa_methodlist_p);
166 void ipa_add_method (ipa_methodlist_p *, struct cgraph_node *);
167 struct cgraph_node *ipa_remove_method (ipa_methodlist_p *);
168
169 /* ipa_callsite interface.  */
170 int ipa_callsite_param_count (struct cgraph_edge *);
171 void ipa_callsite_param_count_set (struct cgraph_edge *, int);
172 struct ipa_jump_func *ipa_callsite_param (struct cgraph_edge *, int);
173 struct cgraph_node *ipa_callsite_callee (struct cgraph_edge *);
174 void ipa_callsite_compute_param (struct cgraph_edge *);
175 void ipa_callsite_compute_count (struct cgraph_edge *);
176
177 /* ipa_method interface.  */
178 int ipa_method_formal_count (struct cgraph_node *);
179 void ipa_method_formal_count_set (struct cgraph_node *, int);
180 tree ipa_method_get_tree (struct cgraph_node *, int);
181 void ipa_method_compute_tree_map (struct cgraph_node *);
182 void ipa_method_formal_compute_count (struct cgraph_node *);
183 void ipa_method_compute_modify (struct cgraph_node *);
184
185 /* jump function interface.  */
186 enum jump_func_type get_type (struct ipa_jump_func *);
187 union parameter_info *ipa_jf_get_info_type (struct ipa_jump_func *);
188
189 /* ipa_node and ipa_edge interfaces.  */
190 void ipa_node_create (struct cgraph_node *);
191 void ipa_free (void);
192 void ipa_nodes_create (void);
193 void ipa_edges_create (void);
194 void ipa_edges_free (void);
195 void ipa_nodes_free (void);
196
197
198 /* Debugging interface.  */
199 void ipa_method_tree_print (FILE *);
200 void ipa_method_modify_print (FILE *);
201
202 void ipcp_driver (void);
203
204 #endif /* IPA_PROP_H */