OSDN Git Service

2008-03-01 Douglas Gregor <doug.gregor@gmail.com>
[pf3gnuchains/gcc-fork.git] / gcc / ipa-prop.h
1 /* Interprocedural analyses.
2    Copyright (C) 2005, 2007 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
25 /* The following definitions and interfaces are used by
26    interprocedural analyses.  */
27
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 CONST_IPATYPE and Fortran 
34    constants are represented as CONST_IPATYPE_REF.  */
35 enum jump_func_type
36 {
37   UNKNOWN_IPATYPE,
38   CONST_IPATYPE,
39   CONST_IPATYPE_REF,
40   FORMAL_IPATYPE
41 };
42
43 /* All formal parameters in the program have a cval computed by 
44    the interprocedural stage of IPCP.  
45    There are three main values of cval :
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 CONST_IPATYPE and Fortran
52    constants are represented as CONST_IPATYPE_REF.  */
53 enum cvalue_type
54 {
55   BOTTOM,
56   CONST_VALUE,
57   CONST_VALUE_REF,
58   TOP
59 };
60
61 /* Represents the value of either jump function or cval.
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 
65    as argument).  */
66 union parameter_info
67 {
68   unsigned int formal_id;
69   tree value;
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 parameter_info info_type;
79 };
80
81 /* All formal parameters in the program have a cval computed by 
82    the interprocedural stage of IPCP. See enum cvalue_type for 
83    the various types of cvals supported */
84 struct ipcp_formal
85 {
86   enum cvalue_type cval_type;
87   union parameter_info cvalue;
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 /* Return the field in cgraph_node/cgraph_edge struct that points
105    to ipa_node/ipa_edge struct.  */
106 #define IPA_NODE_REF(MT) ((struct ipa_node *)(MT)->aux)
107 #define IPA_EDGE_REF(EDGE) ((struct ipa_edge *)(EDGE)->aux)
108 /* This macro checks validity of index returned by
109    ipa_method_tree_map function.  */
110 #define IS_VALID_TREE_MAP_INDEX(I) ((I) != -1)
111
112 /* ipa_node stores information related to a method and
113    its formal parameters. It is pointed to by a field in the
114    method's corresponding cgraph_node.
115
116    ipa_edge stores information related to a callsite and
117    its arguments. It is pointed to by a field in the
118    callsite's corresponding cgraph_edge.  */
119 struct ipa_node
120 {
121   /* Number of formal parameters of this method.  When set to 0,
122      this method's parameters would not be analyzed by the different
123      stages of IPA CP.  */
124   int ipa_arg_num;
125   /* Array of cvals.  */
126   struct ipcp_formal *ipcp_cval;
127   /* Mapping each parameter to its PARM_DECL tree.  */
128   tree *ipa_param_tree;
129   /* Indicating which parameter is modified in its method.  */
130   bool *ipa_mod;
131   /* Only for versioned nodes this field would not be NULL,
132      it points to the node that IPA cp cloned from.  */
133   struct cgraph_node *ipcp_orig_node;
134   /* Meaningful only for original methods.  Expresses the 
135      ratio between the direct calls and sum of all invocations of 
136      this function (given by profiling info).  It is used to calculate 
137      the profiling information of the original function and the versioned
138      one.  */
139   gcov_type count_scale;
140 };
141
142 struct ipa_edge
143 {
144   /* Number of actual arguments in this callsite.  When set to 0,
145      this callsite's parameters would not be analyzed by the different
146      stages of IPA CP.  */
147   int ipa_param_num;
148   /* Array of the callsite's jump function of each parameter.  */
149   struct ipa_jump_func *ipa_param_map;
150 };
151
152 /* A methodlist element (referred to also as methodlist node). It is used 
153    to create a temporary worklist used in 
154    the propagation stage of IPCP. (can be used for more IPA 
155    optimizations)  */
156 struct ipa_methodlist
157 {
158   struct cgraph_node *method_p;
159   struct ipa_methodlist *next_method;
160 };
161
162 /* A pointer to a methodlist element.  */
163 typedef struct ipa_methodlist *ipa_methodlist_p;
164
165 /* ipa_methodlist interface.  */
166 ipa_methodlist_p ipa_methodlist_init (void);
167 bool ipa_methodlist_not_empty (ipa_methodlist_p);
168 void ipa_add_method (ipa_methodlist_p *, struct cgraph_node *);
169 struct cgraph_node *ipa_remove_method (ipa_methodlist_p *);
170
171 /* ipa_callsite interface.  */
172 int ipa_callsite_param_count (struct cgraph_edge *);
173 void ipa_callsite_param_count_set (struct cgraph_edge *, int);
174 struct ipa_jump_func *ipa_callsite_param (struct cgraph_edge *, int);
175 struct cgraph_node *ipa_callsite_callee (struct cgraph_edge *);
176 void ipa_callsite_compute_param (struct cgraph_edge *);
177 void ipa_callsite_compute_count (struct cgraph_edge *);
178
179 /* ipa_method interface.  */
180 int ipa_method_formal_count (struct cgraph_node *);
181 void ipa_method_formal_count_set (struct cgraph_node *, int);
182 tree ipa_method_get_tree (struct cgraph_node *, int);
183 void ipa_method_compute_tree_map (struct cgraph_node *);
184 void ipa_method_formal_compute_count (struct cgraph_node *);
185 void ipa_method_compute_modify (struct cgraph_node *);
186
187 /* jump function interface.  */
188 enum jump_func_type get_type (struct ipa_jump_func *);
189 union parameter_info *ipa_jf_get_info_type (struct ipa_jump_func *);
190
191 /* ipa_node and ipa_edge interfaces.  */
192 void ipa_node_create (struct cgraph_node *);
193 void ipa_free (void);
194 void ipa_nodes_create (void);
195 void ipa_edges_create (void);
196 void ipa_edges_free (void);
197 void ipa_nodes_free (void);
198
199
200 /* Debugging interface.  */
201 void ipa_method_tree_print (FILE *);
202 void ipa_method_modify_print (FILE *);
203
204 #endif /* IPA_PROP_H */