OSDN Git Service

PR c++/31074
[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 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 /* This macro checks validity of index returned by
110    ipa_method_tree_map function.  */
111 #define IS_VALID_TREE_MAP_INDEX(I) ((I) != -1)
112
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.
116
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
121 {
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;
141 };
142
143 struct ipa_edge
144 {
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;
151 };
152
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
158 {
159   struct cgraph_node *method_p;
160   struct ipa_methodlist *next_method;
161 };
162
163 /* A pointer to a methodlist element.  */
164 typedef struct ipa_methodlist *ipa_methodlist_p;
165
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 *);
171
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 *);
179
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 *);
187
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 *);
191
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);
199
200
201 /* Debugging interface.  */
202 void ipa_method_tree_print (FILE *);
203 void ipa_method_modify_print (FILE *);
204
205 #endif /* IPA_PROP_H */