]>
Commit | Line | Data |
---|---|---|
518dc859 | 1 | /* Interprocedural analyses. |
a5544970 | 2 | Copyright (C) 2005-2019 Free Software Foundation, Inc. |
518dc859 RL |
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 | |
9dcd6f09 | 8 | Software Foundation; either version 3, or (at your option) any later |
518dc859 RL |
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 | |
9dcd6f09 NC |
17 | along with GCC; see the file COPYING3. If not see |
18 | <http://www.gnu.org/licenses/>. */ | |
518dc859 RL |
19 | |
20 | #ifndef IPA_PROP_H | |
21 | #define IPA_PROP_H | |
22 | ||
518dc859 | 23 | /* The following definitions and interfaces are used by |
133f9369 MJ |
24 | interprocedural analyses or parameters. */ |
25 | ||
4502fe8d MJ |
26 | #define IPA_UNDESCRIBED_USE -1 |
27 | ||
133f9369 | 28 | /* ipa-prop.c stuff (ipa-cp, indirect inlining): */ |
518dc859 | 29 | |
be95e2b9 | 30 | /* A jump function for a callsite represents the values passed as actual |
310bc633 MJ |
31 | arguments of the callsite. They were originally proposed in a paper called |
32 | "Interprocedural Constant Propagation", by David Callahan, Keith D Cooper, | |
33 | Ken Kennedy, Linda Torczon in Comp86, pg 152-161. There are three main | |
34 | types of values : | |
685b0d13 MJ |
35 | |
36 | Pass-through - the caller's formal parameter is passed as an actual | |
37 | argument, possibly one simple operation performed on it. | |
38 | Constant - a constant (is_gimple_ip_invariant)is passed as an actual | |
39 | argument. | |
40 | Unknown - neither of the above. | |
41 | ||
b258210c MJ |
42 | IPA_JF_ANCESTOR is a special pass-through jump function, which means that |
43 | the result is an address of a part of the object pointed to by the formal | |
44 | parameter to which the function refers. It is mainly intended to represent | |
026c3cfd | 45 | getting addresses of ancestor fields in C++ |
b258210c MJ |
46 | (e.g. &this_1(D)->D.1766.D.1756). Note that if the original pointer is |
47 | NULL, ancestor jump function must behave like a simple pass-through. | |
48 | ||
49 | Other pass-through functions can either simply pass on an unchanged formal | |
50 | parameter or can apply one simple binary operation to it (such jump | |
51 | functions are called polynomial). | |
52 | ||
b258210c MJ |
53 | Jump functions are computed in ipa-prop.c by function |
54 | update_call_notes_after_inlining. Some information can be lost and jump | |
55 | functions degraded accordingly when inlining, see | |
56 | update_call_notes_after_inlining in the same file. */ | |
685b0d13 | 57 | |
518dc859 RL |
58 | enum jump_func_type |
59 | { | |
133f9369 | 60 | IPA_JF_UNKNOWN = 0, /* newly allocated and zeroed jump functions default */ |
b258210c | 61 | IPA_JF_CONST, /* represented by field costant */ |
b258210c MJ |
62 | IPA_JF_PASS_THROUGH, /* represented by field pass_through */ |
63 | IPA_JF_ANCESTOR /* represented by field ancestor */ | |
518dc859 RL |
64 | }; |
65 | ||
4502fe8d MJ |
66 | struct ipa_cst_ref_desc; |
67 | ||
68 | /* Structure holding data required to describe a constant jump function. */ | |
69 | struct GTY(()) ipa_constant_data | |
70 | { | |
71 | /* THe value of the constant. */ | |
72 | tree value; | |
73 | /* Pointer to the structure that describes the reference. */ | |
74 | struct ipa_cst_ref_desc GTY((skip)) *rdesc; | |
75 | }; | |
76 | ||
685b0d13 MJ |
77 | /* Structure holding data required to describe a pass-through jump function. */ |
78 | ||
fb3f88cc | 79 | struct GTY(()) ipa_pass_through_data |
685b0d13 MJ |
80 | { |
81 | /* If an operation is to be performed on the original parameter, this is the | |
82 | second (constant) operand. */ | |
83 | tree operand; | |
84 | /* Number of the caller's formal parameter being passed. */ | |
85 | int formal_id; | |
86 | /* Operation that is performed on the argument before it is passed on. | |
87 | NOP_EXPR means no operation. Otherwise oper must be a simple binary | |
88 | arithmetic operation where the caller's parameter is the first operand and | |
89 | operand field from this structure is the second one. */ | |
90 | enum tree_code operation; | |
8b7773a4 MJ |
91 | /* When the passed value is a pointer, it is set to true only when we are |
92 | certain that no write to the object it points to has occurred since the | |
93 | caller functions started execution, except for changes noted in the | |
94 | aggregate part of the jump function (see description of | |
95 | ipa_agg_jump_function). The flag is used only when the operation is | |
96 | NOP_EXPR. */ | |
b8f6e610 | 97 | unsigned agg_preserved : 1; |
685b0d13 MJ |
98 | }; |
99 | ||
b258210c MJ |
100 | /* Structure holding data required to describe an ancestor pass-through |
101 | jump function. */ | |
685b0d13 | 102 | |
fb3f88cc | 103 | struct GTY(()) ipa_ancestor_jf_data |
685b0d13 MJ |
104 | { |
105 | /* Offset of the field representing the ancestor. */ | |
106 | HOST_WIDE_INT offset; | |
685b0d13 MJ |
107 | /* Number of the caller's formal parameter being passed. */ |
108 | int formal_id; | |
8b7773a4 | 109 | /* Flag with the same meaning like agg_preserve in ipa_pass_through_data. */ |
b8f6e610 | 110 | unsigned agg_preserved : 1; |
685b0d13 MJ |
111 | }; |
112 | ||
8b7773a4 MJ |
113 | /* An element in an aggegate part of a jump function describing a known value |
114 | at a given offset. When it is part of a pass-through jump function with | |
115 | agg_preserved set or an ancestor jump function with agg_preserved set, all | |
116 | unlisted positions are assumed to be preserved but the value can be a type | |
117 | node, which means that the particular piece (starting at offset and having | |
118 | the size of the type) is clobbered with an unknown value. When | |
119 | agg_preserved is false or the type of the containing jump function is | |
120 | different, all unlisted parts are assumed to be unknown and all values must | |
688010ba | 121 | fulfill is_gimple_ip_invariant. */ |
8b7773a4 | 122 | |
84562394 | 123 | struct GTY(()) ipa_agg_jf_item |
8b7773a4 MJ |
124 | { |
125 | /* The offset at which the known value is located within the aggregate. */ | |
126 | HOST_WIDE_INT offset; | |
127 | ||
128 | /* The known constant or type if this is a clobber. */ | |
129 | tree value; | |
ac6f2e59 JH |
130 | |
131 | /* Return true if OTHER describes same agg item. */ | |
132 | bool equal_to (const ipa_agg_jf_item &other); | |
84562394 | 133 | }; |
8b7773a4 | 134 | |
8b7773a4 MJ |
135 | |
136 | /* Aggregate jump function - i.e. description of contents of aggregates passed | |
137 | either by reference or value. */ | |
138 | ||
139 | struct GTY(()) ipa_agg_jump_function | |
3e293154 | 140 | { |
8b7773a4 | 141 | /* Description of the individual items. */ |
84562394 | 142 | vec<ipa_agg_jf_item, va_gc> *items; |
8b7773a4 MJ |
143 | /* True if the data was passed by reference (as opposed to by value). */ |
144 | bool by_ref; | |
ac6f2e59 JH |
145 | |
146 | /* Return true if OTHER describes same agg items. */ | |
147 | bool equal_to (const ipa_agg_jump_function &other) | |
148 | { | |
149 | if (by_ref != other.by_ref) | |
150 | return false; | |
151 | if (items != NULL && other.items == NULL) | |
152 | return false; | |
153 | if (!items) | |
154 | return other.items == NULL; | |
155 | if (items->length () != other.items->length ()) | |
156 | return false; | |
157 | for (unsigned int i = 0; i < items->length (); i++) | |
158 | if (!(*items)[i].equal_to ((*other.items)[i])) | |
159 | return false; | |
160 | return true; | |
161 | } | |
3e293154 MJ |
162 | }; |
163 | ||
8b7773a4 | 164 | typedef struct ipa_agg_jump_function *ipa_agg_jump_function_p; |
8b7773a4 | 165 | |
209ca542 | 166 | /* Information about zero/non-zero bits. */ |
6c1dae73 | 167 | class GTY(()) ipa_bits |
209ca542 | 168 | { |
6c1dae73 | 169 | public: |
209ca542 PK |
170 | /* The propagated value. */ |
171 | widest_int value; | |
172 | /* Mask corresponding to the value. | |
173 | Similar to ccp_lattice_t, if xth bit of mask is 0, | |
174 | implies xth bit of value is constant. */ | |
175 | widest_int mask; | |
209ca542 PK |
176 | }; |
177 | ||
8bc5448f | 178 | /* Info about value ranges. */ |
86cd0334 | 179 | |
6c1dae73 | 180 | class GTY(()) ipa_vr |
8bc5448f | 181 | { |
6c1dae73 | 182 | public: |
8bc5448f KV |
183 | /* The data fields below are valid only if known is true. */ |
184 | bool known; | |
54994253 | 185 | enum value_range_kind type; |
8bc5448f KV |
186 | wide_int min; |
187 | wide_int max; | |
523fe5b6 | 188 | bool nonzero_p (tree) const; |
8bc5448f KV |
189 | }; |
190 | ||
be95e2b9 MJ |
191 | /* A jump function for a callsite represents the values passed as actual |
192 | arguments of the callsite. See enum jump_func_type for the various | |
518dc859 | 193 | types of jump functions supported. */ |
84562394 | 194 | struct GTY (()) ipa_jump_func |
518dc859 | 195 | { |
8b7773a4 MJ |
196 | /* Aggregate contants description. See struct ipa_agg_jump_function and its |
197 | description. */ | |
198 | struct ipa_agg_jump_function agg; | |
199 | ||
86cd0334 MJ |
200 | /* Information about zero/non-zero bits. The pointed to structure is shared |
201 | betweed different jump functions. Use ipa_set_jfunc_bits to set this | |
202 | field. */ | |
99b1c316 | 203 | class ipa_bits *bits; |
209ca542 | 204 | |
a5e14a42 | 205 | /* Information about value range, containing valid data only when vr_known is |
86cd0334 MJ |
206 | true. The pointed to structure is shared betweed different jump |
207 | functions. Use ipa_set_jfunc_vr to set this field. */ | |
028d81b1 | 208 | class value_range *m_vr; |
8bc5448f | 209 | |
518dc859 | 210 | enum jump_func_type type; |
fb3f88cc JH |
211 | /* Represents a value of a jump function. pass_through is used only in jump |
212 | function context. constant represents the actual constant in constant jump | |
213 | functions and member_cst holds constant c++ member functions. */ | |
214 | union jump_func_value | |
215 | { | |
4502fe8d | 216 | struct ipa_constant_data GTY ((tag ("IPA_JF_CONST"))) constant; |
fb3f88cc JH |
217 | struct ipa_pass_through_data GTY ((tag ("IPA_JF_PASS_THROUGH"))) pass_through; |
218 | struct ipa_ancestor_jf_data GTY ((tag ("IPA_JF_ANCESTOR"))) ancestor; | |
fb3f88cc | 219 | } GTY ((desc ("%1.type"))) value; |
84562394 | 220 | }; |
606d9a09 | 221 | |
518dc859 | 222 | |
7b872d9e MJ |
223 | /* Return the constant stored in a constant jump functin JFUNC. */ |
224 | ||
225 | static inline tree | |
226 | ipa_get_jf_constant (struct ipa_jump_func *jfunc) | |
227 | { | |
228 | gcc_checking_assert (jfunc->type == IPA_JF_CONST); | |
4502fe8d MJ |
229 | return jfunc->value.constant.value; |
230 | } | |
231 | ||
232 | static inline struct ipa_cst_ref_desc * | |
233 | ipa_get_jf_constant_rdesc (struct ipa_jump_func *jfunc) | |
234 | { | |
235 | gcc_checking_assert (jfunc->type == IPA_JF_CONST); | |
236 | return jfunc->value.constant.rdesc; | |
7b872d9e MJ |
237 | } |
238 | ||
239 | /* Return the operand of a pass through jmp function JFUNC. */ | |
240 | ||
241 | static inline tree | |
242 | ipa_get_jf_pass_through_operand (struct ipa_jump_func *jfunc) | |
243 | { | |
244 | gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH); | |
245 | return jfunc->value.pass_through.operand; | |
246 | } | |
247 | ||
248 | /* Return the number of the caller's formal parameter that a pass through jump | |
249 | function JFUNC refers to. */ | |
250 | ||
251 | static inline int | |
252 | ipa_get_jf_pass_through_formal_id (struct ipa_jump_func *jfunc) | |
253 | { | |
254 | gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH); | |
255 | return jfunc->value.pass_through.formal_id; | |
256 | } | |
257 | ||
258 | /* Return operation of a pass through jump function JFUNC. */ | |
259 | ||
260 | static inline enum tree_code | |
261 | ipa_get_jf_pass_through_operation (struct ipa_jump_func *jfunc) | |
262 | { | |
263 | gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH); | |
264 | return jfunc->value.pass_through.operation; | |
265 | } | |
266 | ||
b8f6e610 | 267 | /* Return the agg_preserved flag of a pass through jump function JFUNC. */ |
8b7773a4 MJ |
268 | |
269 | static inline bool | |
270 | ipa_get_jf_pass_through_agg_preserved (struct ipa_jump_func *jfunc) | |
271 | { | |
272 | gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH); | |
273 | return jfunc->value.pass_through.agg_preserved; | |
274 | } | |
275 | ||
44210a96 MJ |
276 | /* Return true if pass through jump function JFUNC preserves type |
277 | information. */ | |
b8f6e610 MJ |
278 | |
279 | static inline bool | |
280 | ipa_get_jf_pass_through_type_preserved (struct ipa_jump_func *jfunc) | |
281 | { | |
282 | gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH); | |
44210a96 | 283 | return jfunc->value.pass_through.agg_preserved; |
b8f6e610 MJ |
284 | } |
285 | ||
7b872d9e MJ |
286 | /* Return the offset of an ancestor jump function JFUNC. */ |
287 | ||
288 | static inline HOST_WIDE_INT | |
289 | ipa_get_jf_ancestor_offset (struct ipa_jump_func *jfunc) | |
290 | { | |
291 | gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR); | |
292 | return jfunc->value.ancestor.offset; | |
293 | } | |
294 | ||
7b872d9e MJ |
295 | /* Return the number of the caller's formal parameter that an ancestor jump |
296 | function JFUNC refers to. */ | |
297 | ||
298 | static inline int | |
299 | ipa_get_jf_ancestor_formal_id (struct ipa_jump_func *jfunc) | |
300 | { | |
301 | gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR); | |
302 | return jfunc->value.ancestor.formal_id; | |
303 | } | |
304 | ||
b8f6e610 | 305 | /* Return the agg_preserved flag of an ancestor jump function JFUNC. */ |
7b872d9e | 306 | |
8b7773a4 MJ |
307 | static inline bool |
308 | ipa_get_jf_ancestor_agg_preserved (struct ipa_jump_func *jfunc) | |
7b872d9e | 309 | { |
8b7773a4 MJ |
310 | gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR); |
311 | return jfunc->value.ancestor.agg_preserved; | |
7b872d9e MJ |
312 | } |
313 | ||
44210a96 | 314 | /* Return true if ancestor jump function JFUNC presrves type information. */ |
b8f6e610 MJ |
315 | |
316 | static inline bool | |
317 | ipa_get_jf_ancestor_type_preserved (struct ipa_jump_func *jfunc) | |
318 | { | |
319 | gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR); | |
44210a96 | 320 | return jfunc->value.ancestor.agg_preserved; |
b8f6e610 MJ |
321 | } |
322 | ||
310bc633 | 323 | /* Summary describing a single formal parameter. */ |
b258210c | 324 | |
f65f1ae3 | 325 | struct GTY(()) ipa_param_descriptor |
f8e2a1ed | 326 | { |
209ca542 PK |
327 | /* In analysis and modification phase, this is the PARAM_DECL of this |
328 | parameter, in IPA LTO phase, this is the type of the the described | |
329 | parameter or NULL if not known. Do not read this field directly but | |
330 | through ipa_get_param and ipa_get_type as appropriate. */ | |
331 | tree decl_or_type; | |
4502fe8d MJ |
332 | /* If all uses of the parameter are described by ipa-prop structures, this |
333 | says how many there are. If any use could not be described by means of | |
334 | ipa-prop structures, this is IPA_UNDESCRIBED_USE. */ | |
335 | int controlled_uses; | |
40a777e8 | 336 | unsigned int move_cost : 28; |
339f49ec JH |
337 | /* The parameter is used. */ |
338 | unsigned used : 1; | |
40a777e8 JH |
339 | unsigned used_by_ipa_predicates : 1; |
340 | unsigned used_by_indirect_call : 1; | |
341 | unsigned used_by_polymorphic_call : 1; | |
f8e2a1ed MJ |
342 | }; |
343 | ||
dcd416e3 MJ |
344 | /* ipa_node_params stores information related to formal parameters of functions |
345 | and some other information for interprocedural passes that operate on | |
346 | parameters (such as ipa-cp). */ | |
310bc633 | 347 | |
6c1dae73 | 348 | class GTY((for_user)) ipa_node_params |
518dc859 | 349 | { |
6c1dae73 | 350 | public: |
e806796d ML |
351 | /* Default constructor. */ |
352 | ipa_node_params (); | |
353 | ||
354 | /* Default destructor. */ | |
355 | ~ipa_node_params (); | |
356 | ||
310bc633 MJ |
357 | /* Information about individual formal parameters that are gathered when |
358 | summaries are generated. */ | |
f65f1ae3 | 359 | vec<ipa_param_descriptor, va_gc> *descriptors; |
310bc633 MJ |
360 | /* Pointer to an array of structures describing individual formal |
361 | parameters. */ | |
99b1c316 | 362 | class ipcp_param_lattices * GTY((skip)) lattices; |
310bc633 MJ |
363 | /* Only for versioned nodes this field would not be NULL, |
364 | it points to the node that IPA cp cloned from. */ | |
f65f1ae3 | 365 | struct cgraph_node * GTY((skip)) ipcp_orig_node; |
44210a96 MJ |
366 | /* If this node is an ipa-cp clone, these are the known constants that |
367 | describe what it has been specialized for. */ | |
f65f1ae3 | 368 | vec<tree> GTY((skip)) known_csts; |
44210a96 MJ |
369 | /* If this node is an ipa-cp clone, these are the known polymorphic contexts |
370 | that describe what it has been specialized for. */ | |
f65f1ae3 | 371 | vec<ipa_polymorphic_call_context> GTY((skip)) known_contexts; |
8aab5218 MJ |
372 | /* Whether the param uses analysis and jump function computation has already |
373 | been performed. */ | |
374 | unsigned analysis_done : 1; | |
310bc633 | 375 | /* Whether the function is enqueued in ipa-cp propagation stack. */ |
448f65db | 376 | unsigned node_enqueued : 1; |
310bc633 MJ |
377 | /* Whether we should create a specialized version based on values that are |
378 | known to be constant in all contexts. */ | |
eb20b778 MJ |
379 | unsigned do_clone_for_all_contexts : 1; |
380 | /* Set if this is an IPA-CP clone for all contexts. */ | |
381 | unsigned is_all_contexts_clone : 1; | |
310bc633 MJ |
382 | /* Node has been completely replaced by clones and will be removed after |
383 | ipa-cp is finished. */ | |
384 | unsigned node_dead : 1; | |
af21714c MJ |
385 | /* Node is involved in a recursion, potentionally indirect. */ |
386 | unsigned node_within_scc : 1; | |
387 | /* Node is calling a private function called only once. */ | |
388 | unsigned node_calling_single_call : 1; | |
7e729474 ML |
389 | /* False when there is something makes versioning impossible. */ |
390 | unsigned versionable : 1; | |
518dc859 RL |
391 | }; |
392 | ||
e806796d ML |
393 | inline |
394 | ipa_node_params::ipa_node_params () | |
395 | : descriptors (NULL), lattices (NULL), ipcp_orig_node (NULL), | |
396 | known_csts (vNULL), known_contexts (vNULL), analysis_done (0), | |
397 | node_enqueued (0), do_clone_for_all_contexts (0), is_all_contexts_clone (0), | |
398 | node_dead (0), node_within_scc (0), node_calling_single_call (0), | |
399 | versionable (0) | |
400 | { | |
401 | } | |
402 | ||
403 | inline | |
404 | ipa_node_params::~ipa_node_params () | |
405 | { | |
406 | free (lattices); | |
407 | known_csts.release (); | |
408 | known_contexts.release (); | |
409 | } | |
410 | ||
ff302741 PB |
411 | /* Intermediate information that we get from alias analysis about a particular |
412 | parameter in a particular basic_block. When a parameter or the memory it | |
56b40062 MJ |
413 | references is marked modified, we use that information in all dominated |
414 | blocks without consulting alias analysis oracle. */ | |
ff302741 | 415 | |
56b40062 | 416 | struct ipa_param_aa_status |
ff302741 PB |
417 | { |
418 | /* Set when this structure contains meaningful information. If not, the | |
419 | structure describing a dominating BB should be used instead. */ | |
420 | bool valid; | |
421 | ||
422 | /* Whether we have seen something which might have modified the data in | |
423 | question. PARM is for the parameter itself, REF is for data it points to | |
424 | but using the alias type of individual accesses and PT is the same thing | |
425 | but for computing aggregate pass-through functions using a very inclusive | |
426 | ao_ref. */ | |
427 | bool parm_modified, ref_modified, pt_modified; | |
428 | }; | |
429 | ||
430 | /* Information related to a given BB that used only when looking at function | |
431 | body. */ | |
432 | ||
433 | struct ipa_bb_info | |
434 | { | |
435 | /* Call graph edges going out of this BB. */ | |
436 | vec<cgraph_edge *> cg_edges; | |
437 | /* Alias analysis statuses of each formal parameter at this bb. */ | |
56b40062 | 438 | vec<ipa_param_aa_status> param_aa_statuses; |
ff302741 PB |
439 | }; |
440 | ||
441 | /* Structure with global information that is only used when looking at function | |
442 | body. */ | |
443 | ||
56b40062 | 444 | struct ipa_func_body_info |
ff302741 PB |
445 | { |
446 | /* The node that is being analyzed. */ | |
447 | cgraph_node *node; | |
448 | ||
449 | /* Its info. */ | |
99b1c316 | 450 | class ipa_node_params *info; |
ff302741 PB |
451 | |
452 | /* Information about individual BBs. */ | |
453 | vec<ipa_bb_info> bb_infos; | |
454 | ||
455 | /* Number of parameters. */ | |
456 | int param_count; | |
457 | ||
c628d1c3 MJ |
458 | /* Number of statements we are still allowed to walked by when analyzing this |
459 | function. */ | |
460 | unsigned int aa_walk_budget; | |
ff302741 PB |
461 | }; |
462 | ||
dcd416e3 MJ |
463 | /* ipa_node_params access functions. Please use these to access fields that |
464 | are or will be shared among various passes. */ | |
465 | ||
dcd416e3 | 466 | /* Return the number of formal parameters. */ |
be95e2b9 | 467 | |
dcd416e3 | 468 | static inline int |
99b1c316 | 469 | ipa_get_param_count (class ipa_node_params *info) |
dcd416e3 | 470 | { |
f65f1ae3 | 471 | return vec_safe_length (info->descriptors); |
dcd416e3 MJ |
472 | } |
473 | ||
f8e2a1ed MJ |
474 | /* Return the declaration of Ith formal parameter of the function corresponding |
475 | to INFO. Note there is no setter function as this array is built just once | |
209ca542 PK |
476 | using ipa_initialize_node_params. This function should not be called in |
477 | WPA. */ | |
be95e2b9 | 478 | |
dcd416e3 | 479 | static inline tree |
99b1c316 | 480 | ipa_get_param (class ipa_node_params *info, int i) |
dcd416e3 | 481 | { |
f65f1ae3 | 482 | gcc_checking_assert (info->descriptors); |
f65f1ae3 | 483 | tree t = (*info->descriptors)[i].decl_or_type; |
209ca542 PK |
484 | gcc_checking_assert (TREE_CODE (t) == PARM_DECL); |
485 | return t; | |
486 | } | |
487 | ||
488 | /* Return the type of Ith formal parameter of the function corresponding | |
489 | to INFO if it is known or NULL if not. */ | |
490 | ||
491 | static inline tree | |
99b1c316 | 492 | ipa_get_type (class ipa_node_params *info, int i) |
209ca542 | 493 | { |
e5cf5e11 PK |
494 | if (vec_safe_length (info->descriptors) <= (unsigned) i) |
495 | return NULL; | |
f65f1ae3 | 496 | tree t = (*info->descriptors)[i].decl_or_type; |
209ca542 PK |
497 | if (!t) |
498 | return NULL; | |
499 | if (TYPE_P (t)) | |
500 | return t; | |
501 | gcc_checking_assert (TREE_CODE (t) == PARM_DECL); | |
502 | return TREE_TYPE (t); | |
339f49ec JH |
503 | } |
504 | ||
0e8853ee JH |
505 | /* Return the move cost of Ith formal parameter of the function corresponding |
506 | to INFO. */ | |
507 | ||
508 | static inline int | |
99b1c316 | 509 | ipa_get_param_move_cost (class ipa_node_params *info, int i) |
0e8853ee | 510 | { |
f65f1ae3 MJ |
511 | gcc_checking_assert (info->descriptors); |
512 | return (*info->descriptors)[i].move_cost; | |
0e8853ee JH |
513 | } |
514 | ||
310bc633 MJ |
515 | /* Set the used flag corresponding to the Ith formal parameter of the function |
516 | associated with INFO to VAL. */ | |
3949c4a7 | 517 | |
310bc633 | 518 | static inline void |
99b1c316 | 519 | ipa_set_param_used (class ipa_node_params *info, int i, bool val) |
3949c4a7 | 520 | { |
f65f1ae3 MJ |
521 | gcc_checking_assert (info->descriptors); |
522 | (*info->descriptors)[i].used = val; | |
3949c4a7 MJ |
523 | } |
524 | ||
40a777e8 JH |
525 | /* Set the used_by_ipa_predicates flag corresponding to the Ith formal |
526 | parameter of the function associated with INFO to VAL. */ | |
527 | ||
528 | static inline void | |
529 | ipa_set_param_used_by_ipa_predicates (class ipa_node_params *info, int i, bool val) | |
530 | { | |
531 | gcc_checking_assert (info->descriptors); | |
532 | (*info->descriptors)[i].used_by_ipa_predicates = val; | |
533 | } | |
534 | ||
535 | /* Set the used_by_indirect_call flag corresponding to the Ith formal | |
536 | parameter of the function associated with INFO to VAL. */ | |
537 | ||
538 | static inline void | |
539 | ipa_set_param_used_by_indirect_call (class ipa_node_params *info, int i, bool val) | |
540 | { | |
541 | gcc_checking_assert (info->descriptors); | |
542 | (*info->descriptors)[i].used_by_indirect_call = val; | |
543 | } | |
544 | ||
545 | /* Set the .used_by_polymorphic_call flag corresponding to the Ith formal | |
546 | parameter of the function associated with INFO to VAL. */ | |
547 | ||
548 | static inline void | |
549 | ipa_set_param_used_by_polymorphic_call (class ipa_node_params *info, int i, bool val) | |
550 | { | |
551 | gcc_checking_assert (info->descriptors); | |
552 | (*info->descriptors)[i].used_by_polymorphic_call = val; | |
553 | } | |
554 | ||
4502fe8d MJ |
555 | /* Return how many uses described by ipa-prop a parameter has or |
556 | IPA_UNDESCRIBED_USE if there is a use that is not described by these | |
557 | structures. */ | |
558 | static inline int | |
99b1c316 | 559 | ipa_get_controlled_uses (class ipa_node_params *info, int i) |
4502fe8d | 560 | { |
f65f1ae3 MJ |
561 | /* FIXME: introducing speculation causes out of bounds access here. */ |
562 | if (vec_safe_length (info->descriptors) > (unsigned)i) | |
563 | return (*info->descriptors)[i].controlled_uses; | |
5ce97055 | 564 | return IPA_UNDESCRIBED_USE; |
4502fe8d MJ |
565 | } |
566 | ||
567 | /* Set the controlled counter of a given parameter. */ | |
568 | ||
569 | static inline void | |
99b1c316 | 570 | ipa_set_controlled_uses (class ipa_node_params *info, int i, int val) |
4502fe8d | 571 | { |
f65f1ae3 MJ |
572 | gcc_checking_assert (info->descriptors); |
573 | (*info->descriptors)[i].controlled_uses = val; | |
4502fe8d MJ |
574 | } |
575 | ||
310bc633 MJ |
576 | /* Return the used flag corresponding to the Ith formal parameter of the |
577 | function associated with INFO. */ | |
3949c4a7 MJ |
578 | |
579 | static inline bool | |
99b1c316 | 580 | ipa_is_param_used (class ipa_node_params *info, int i) |
3949c4a7 | 581 | { |
f65f1ae3 MJ |
582 | gcc_checking_assert (info->descriptors); |
583 | return (*info->descriptors)[i].used; | |
3949c4a7 MJ |
584 | } |
585 | ||
40a777e8 JH |
586 | /* Return the used_by_ipa_predicates flag corresponding to the Ith formal |
587 | parameter of the function associated with INFO. */ | |
588 | ||
589 | static inline bool | |
590 | ipa_is_param_used_by_ipa_predicates (class ipa_node_params *info, int i) | |
591 | { | |
592 | gcc_checking_assert (info->descriptors); | |
593 | return (*info->descriptors)[i].used_by_ipa_predicates; | |
594 | } | |
595 | ||
596 | /* Return the used_by_indirect_call flag corresponding to the Ith formal | |
597 | parameter of the function associated with INFO. */ | |
598 | ||
599 | static inline bool | |
600 | ipa_is_param_used_by_indirect_call (class ipa_node_params *info, int i) | |
601 | { | |
602 | gcc_checking_assert (info->descriptors); | |
603 | return (*info->descriptors)[i].used_by_indirect_call; | |
604 | } | |
605 | ||
606 | /* Return the used_by_polymorphic_call flag corresponding to the Ith formal | |
607 | parameter of the function associated with INFO. */ | |
608 | ||
609 | static inline bool | |
610 | ipa_is_param_used_by_polymorphic_call (class ipa_node_params *info, int i) | |
611 | { | |
612 | gcc_checking_assert (info->descriptors); | |
613 | return (*info->descriptors)[i].used_by_polymorphic_call; | |
614 | } | |
615 | ||
2c9561b5 MJ |
616 | /* Information about replacements done in aggregates for a given node (each |
617 | node has its linked list). */ | |
618 | struct GTY(()) ipa_agg_replacement_value | |
619 | { | |
620 | /* Next item in the linked list. */ | |
621 | struct ipa_agg_replacement_value *next; | |
622 | /* Offset within the aggregate. */ | |
623 | HOST_WIDE_INT offset; | |
624 | /* The constant value. */ | |
625 | tree value; | |
626 | /* The paramter index. */ | |
627 | int index; | |
7b920a9a MJ |
628 | /* Whether the value was passed by reference. */ |
629 | bool by_ref; | |
2c9561b5 MJ |
630 | }; |
631 | ||
04be694e MJ |
632 | /* Structure holding information for the transformation phase of IPA-CP. */ |
633 | ||
9d3e0adc | 634 | struct GTY(()) ipcp_transformation |
04be694e MJ |
635 | { |
636 | /* Linked list of known aggregate values. */ | |
637 | ipa_agg_replacement_value *agg_values; | |
209ca542 | 638 | /* Known bits information. */ |
86cd0334 | 639 | vec<ipa_bits *, va_gc> *bits; |
8bc5448f KV |
640 | /* Value range information. */ |
641 | vec<ipa_vr, va_gc> *m_vr; | |
04be694e | 642 | }; |
2c9561b5 MJ |
643 | |
644 | void ipa_set_node_agg_value_chain (struct cgraph_node *node, | |
645 | struct ipa_agg_replacement_value *aggvals); | |
9d3e0adc | 646 | void ipcp_transformation_initialize (void); |
12e088ba | 647 | void ipcp_free_transformation_sum (void); |
2c9561b5 | 648 | |
93c594a3 MJ |
649 | /* ipa_edge_args stores information related to a callsite and particularly its |
650 | arguments. It can be accessed by the IPA_EDGE_REF macro. */ | |
6fe906a3 MJ |
651 | |
652 | class GTY((for_user)) ipa_edge_args | |
518dc859 | 653 | { |
6fe906a3 MJ |
654 | public: |
655 | ||
656 | /* Default constructor. */ | |
657 | ipa_edge_args () : jump_functions (NULL), polymorphic_call_contexts (NULL) | |
658 | {} | |
659 | ||
660 | /* Destructor. */ | |
661 | ~ipa_edge_args () | |
662 | { | |
663 | vec_free (jump_functions); | |
664 | vec_free (polymorphic_call_contexts); | |
665 | } | |
666 | ||
667 | /* Vectors of the callsite's jump function and polymorphic context | |
668 | information of each parameter. */ | |
84562394 | 669 | vec<ipa_jump_func, va_gc> *jump_functions; |
5ce97055 | 670 | vec<ipa_polymorphic_call_context, va_gc> *polymorphic_call_contexts; |
84562394 | 671 | }; |
518dc859 | 672 | |
dcd416e3 MJ |
673 | /* ipa_edge_args access functions. Please use these to access fields that |
674 | are or will be shared among various passes. */ | |
675 | ||
dcd416e3 | 676 | /* Return the number of actual arguments. */ |
be95e2b9 | 677 | |
dcd416e3 | 678 | static inline int |
99b1c316 | 679 | ipa_get_cs_argument_count (class ipa_edge_args *args) |
dcd416e3 | 680 | { |
9771b263 | 681 | return vec_safe_length (args->jump_functions); |
dcd416e3 MJ |
682 | } |
683 | ||
684 | /* Returns a pointer to the jump function for the ith argument. Please note | |
685 | there is no setter function as jump functions are all set up in | |
686 | ipa_compute_jump_functions. */ | |
be95e2b9 | 687 | |
dcd416e3 | 688 | static inline struct ipa_jump_func * |
99b1c316 | 689 | ipa_get_ith_jump_func (class ipa_edge_args *args, int i) |
dcd416e3 | 690 | { |
9771b263 | 691 | return &(*args->jump_functions)[i]; |
dcd416e3 MJ |
692 | } |
693 | ||
5ce97055 JH |
694 | /* Returns a pointer to the polymorphic call context for the ith argument. |
695 | NULL if contexts are not computed. */ | |
99b1c316 MS |
696 | static inline class ipa_polymorphic_call_context * |
697 | ipa_get_ith_polymorhic_call_context (class ipa_edge_args *args, int i) | |
5ce97055 JH |
698 | { |
699 | if (!args->polymorphic_call_contexts) | |
700 | return NULL; | |
701 | return &(*args->polymorphic_call_contexts)[i]; | |
702 | } | |
703 | ||
9a1e784a | 704 | /* Function summary for ipa_node_params. */ |
f65f1ae3 | 705 | class GTY((user)) ipa_node_params_t: public function_summary <ipa_node_params *> |
dd912cb8 ML |
706 | { |
707 | public: | |
f65f1ae3 MJ |
708 | ipa_node_params_t (symbol_table *table, bool ggc): |
709 | function_summary<ipa_node_params *> (table, ggc) { } | |
771578a0 | 710 | |
dd912cb8 ML |
711 | /* Hook that is called by summary when a node is duplicated. */ |
712 | virtual void duplicate (cgraph_node *node, | |
713 | cgraph_node *node2, | |
714 | ipa_node_params *data, | |
715 | ipa_node_params *data2); | |
716 | }; | |
717 | ||
6fe906a3 MJ |
718 | /* Summary to manange ipa_edge_args structures. */ |
719 | ||
720 | class GTY((user)) ipa_edge_args_sum_t : public call_summary <ipa_edge_args *> | |
721 | { | |
722 | public: | |
723 | ipa_edge_args_sum_t (symbol_table *table, bool ggc) | |
724 | : call_summary<ipa_edge_args *> (table, ggc) { } | |
725 | ||
a33c028e JH |
726 | void remove (cgraph_edge *edge) |
727 | { | |
728 | call_summary <ipa_edge_args *>::remove (edge); | |
729 | } | |
730 | ||
f658ad30 | 731 | /* Hook that is called by summary when an edge is removed. */ |
6fe906a3 MJ |
732 | virtual void remove (cgraph_edge *cs, ipa_edge_args *args); |
733 | /* Hook that is called by summary when an edge is duplicated. */ | |
734 | virtual void duplicate (cgraph_edge *src, | |
735 | cgraph_edge *dst, | |
736 | ipa_edge_args *old_args, | |
737 | ipa_edge_args *new_args); | |
738 | }; | |
739 | ||
dd912cb8 | 740 | /* Function summary where the parameter infos are actually stored. */ |
f65f1ae3 | 741 | extern GTY(()) ipa_node_params_t * ipa_node_params_sum; |
6fe906a3 MJ |
742 | /* Call summary to store information about edges such as jump functions. */ |
743 | extern GTY(()) ipa_edge_args_sum_t *ipa_edge_args_sum; | |
f65f1ae3 | 744 | |
9d3e0adc ML |
745 | /* Function summary for IPA-CP transformation. */ |
746 | class ipcp_transformation_t | |
747 | : public function_summary<ipcp_transformation *> | |
748 | { | |
749 | public: | |
750 | ipcp_transformation_t (symbol_table *table, bool ggc): | |
751 | function_summary<ipcp_transformation *> (table, ggc) {} | |
752 | ||
753 | ~ipcp_transformation_t () {} | |
754 | ||
755 | static ipcp_transformation_t *create_ggc (symbol_table *symtab) | |
756 | { | |
757 | ipcp_transformation_t *summary | |
78cd68c0 | 758 | = new (ggc_alloc_no_dtor <ipcp_transformation_t> ()) |
9d3e0adc ML |
759 | ipcp_transformation_t (symtab, true); |
760 | return summary; | |
761 | } | |
762 | }; | |
763 | ||
764 | /* Function summary where the IPA CP transformations are actually stored. */ | |
765 | extern GTY(()) function_summary <ipcp_transformation *> *ipcp_transformation_sum; | |
f65f1ae3 | 766 | |
771578a0 MJ |
767 | /* Return the associated parameter/argument info corresponding to the given |
768 | node/edge. */ | |
99353fcf | 769 | #define IPA_NODE_REF(NODE) (ipa_node_params_sum->get_create (NODE)) |
a33c028e JH |
770 | #define IPA_EDGE_REF(EDGE) (ipa_edge_args_sum->get (EDGE)) |
771 | #define IPA_EDGE_REF_GET_CREATE(EDGE) (ipa_edge_args_sum->get_create (EDGE)) | |
771578a0 MJ |
772 | /* This macro checks validity of index returned by |
773 | ipa_get_param_decl_index function. */ | |
774 | #define IS_VALID_JUMP_FUNC_INDEX(I) ((I) != -1) | |
775 | ||
776 | /* Creating and freeing ipa_node_params and ipa_edge_args. */ | |
777 | void ipa_create_all_node_params (void); | |
778 | void ipa_create_all_edge_args (void); | |
86cd0334 | 779 | void ipa_check_create_edge_args (void); |
771578a0 MJ |
780 | void ipa_free_all_node_params (void); |
781 | void ipa_free_all_edge_args (void); | |
e33c6cd6 MJ |
782 | void ipa_free_all_structures_after_ipa_cp (void); |
783 | void ipa_free_all_structures_after_iinln (void); | |
dd912cb8 | 784 | |
771578a0 | 785 | void ipa_register_cgraph_hooks (void); |
fd29c024 | 786 | int count_formal_params (tree fndecl); |
771578a0 MJ |
787 | |
788 | /* This function ensures the array of node param infos is big enough to | |
be95e2b9 MJ |
789 | accommodate a structure for all nodes and reallocates it if not. */ |
790 | ||
771578a0 MJ |
791 | static inline void |
792 | ipa_check_create_node_params (void) | |
793 | { | |
dd912cb8 | 794 | if (!ipa_node_params_sum) |
f65f1ae3 | 795 | ipa_node_params_sum |
78cd68c0 | 796 | = (new (ggc_alloc_no_dtor <ipa_node_params_t> ()) |
f65f1ae3 | 797 | ipa_node_params_t (symtab, true)); |
771578a0 MJ |
798 | } |
799 | ||
6fe906a3 MJ |
800 | /* Returns true if edge summary contains a record for EDGE. The main purpose |
801 | of this function is that debug dumping function can check info availability | |
802 | without causing allocations. */ | |
be95e2b9 | 803 | |
0eae6bab MJ |
804 | static inline bool |
805 | ipa_edge_args_info_available_for_edge_p (struct cgraph_edge *edge) | |
806 | { | |
6fe906a3 | 807 | return ipa_edge_args_sum->exists (edge); |
0eae6bab MJ |
808 | } |
809 | ||
9d3e0adc | 810 | static inline ipcp_transformation * |
04be694e MJ |
811 | ipcp_get_transformation_summary (cgraph_node *node) |
812 | { | |
9d3e0adc | 813 | if (ipcp_transformation_sum == NULL) |
04be694e | 814 | return NULL; |
9d3e0adc ML |
815 | |
816 | return ipcp_transformation_sum->get (node); | |
04be694e MJ |
817 | } |
818 | ||
2c9561b5 MJ |
819 | /* Return the aggregate replacements for NODE, if there are any. */ |
820 | ||
821 | static inline struct ipa_agg_replacement_value * | |
04be694e | 822 | ipa_get_agg_replacements_for_node (cgraph_node *node) |
2c9561b5 | 823 | { |
9d3e0adc | 824 | ipcp_transformation *ts = ipcp_get_transformation_summary (node); |
04be694e | 825 | return ts ? ts->agg_values : NULL; |
2c9561b5 MJ |
826 | } |
827 | ||
f8e2a1ed MJ |
828 | /* Function formal parameters related computations. */ |
829 | void ipa_initialize_node_params (struct cgraph_node *node); | |
f8e2a1ed | 830 | bool ipa_propagate_indirect_call_infos (struct cgraph_edge *cs, |
d52f5295 | 831 | vec<cgraph_edge *> *new_edges); |
518dc859 | 832 | |
3949c4a7 | 833 | /* Indirect edge and binfo processing. */ |
d2d668fb | 834 | tree ipa_get_indirect_edge_target (struct cgraph_edge *ie, |
9771b263 | 835 | vec<tree> , |
44210a96 | 836 | vec<ipa_polymorphic_call_context>, |
231b4916 JH |
837 | vec<ipa_agg_jump_function_p>, |
838 | bool *); | |
5ce97055 JH |
839 | struct cgraph_edge *ipa_make_edge_direct_to_target (struct cgraph_edge *, tree, |
840 | bool speculative = false); | |
72972c22 | 841 | tree ipa_impossible_devirt_target (struct cgraph_edge *, tree); |
86cd0334 MJ |
842 | ipa_bits *ipa_get_ipa_bits_for_value (const widest_int &value, |
843 | const widest_int &mask); | |
844 | ||
3949c4a7 | 845 | |
310bc633 MJ |
846 | /* Functions related to both. */ |
847 | void ipa_analyze_node (struct cgraph_node *); | |
3949c4a7 | 848 | |
8b7773a4 | 849 | /* Aggregate jump function related functions. */ |
91bb9f80 MJ |
850 | tree ipa_find_agg_cst_for_param (struct ipa_agg_jump_function *agg, tree scalar, |
851 | HOST_WIDE_INT offset, bool by_ref, | |
852 | bool *from_global_constant = NULL); | |
853 | bool ipa_load_from_parm_agg (struct ipa_func_body_info *fbi, | |
f65f1ae3 | 854 | vec<ipa_param_descriptor, va_gc> *descriptors, |
91bb9f80 | 855 | gimple *stmt, tree op, int *index_p, |
86003645 | 856 | HOST_WIDE_INT *offset_p, poly_int64 *size_p, |
91bb9f80 | 857 | bool *by_ref, bool *guaranteed_unmodified = NULL); |
8b7773a4 | 858 | |
518dc859 | 859 | /* Debugging interface. */ |
ca30a539 JH |
860 | void ipa_print_node_params (FILE *, struct cgraph_node *node); |
861 | void ipa_print_all_params (FILE *); | |
3e293154 MJ |
862 | void ipa_print_node_jump_functions (FILE *f, struct cgraph_node *node); |
863 | void ipa_print_all_jump_functions (FILE * f); | |
310bc633 MJ |
864 | void ipcp_verify_propagated_values (void); |
865 | ||
2651e637 ML |
866 | template <typename value> |
867 | class ipcp_value; | |
868 | ||
fb0b2914 ML |
869 | extern object_allocator<ipcp_value<tree> > ipcp_cst_values_pool; |
870 | extern object_allocator<ipcp_value<ipa_polymorphic_call_context> > | |
2651e637 ML |
871 | ipcp_poly_ctx_values_pool; |
872 | ||
873 | template <typename valtype> | |
99b1c316 | 874 | struct ipcp_value_source; |
2651e637 | 875 | |
fb0b2914 | 876 | extern object_allocator<ipcp_value_source<tree> > ipcp_sources_pool; |
2651e637 | 877 | |
99b1c316 | 878 | struct ipcp_agg_lattice; |
2651e637 | 879 | |
fb0b2914 | 880 | extern object_allocator<ipcp_agg_lattice> ipcp_agg_lattice_pool; |
518dc859 | 881 | |
2c9561b5 MJ |
882 | void ipa_dump_agg_replacement_values (FILE *f, |
883 | struct ipa_agg_replacement_value *av); | |
f27c1867 | 884 | void ipa_prop_write_jump_functions (void); |
fb3f88cc | 885 | void ipa_prop_read_jump_functions (void); |
04be694e MJ |
886 | void ipcp_write_transformation_summaries (void); |
887 | void ipcp_read_transformation_summaries (void); | |
99b1c316 MS |
888 | int ipa_get_param_decl_index (class ipa_node_params *, tree); |
889 | tree ipa_value_from_jfunc (class ipa_node_params *info, | |
e5cf5e11 | 890 | struct ipa_jump_func *jfunc, tree type); |
2c9561b5 | 891 | unsigned int ipcp_transform_function (struct cgraph_node *node); |
44210a96 MJ |
892 | ipa_polymorphic_call_context ipa_context_from_jfunc (ipa_node_params *, |
893 | cgraph_edge *, | |
894 | int, | |
895 | ipa_jump_func *); | |
99b1c316 | 896 | void ipa_dump_param (FILE *, class ipa_node_params *info, int i); |
c3431191 | 897 | void ipa_release_body_info (struct ipa_func_body_info *); |
5d5f1e95 | 898 | tree ipa_get_callee_param_type (struct cgraph_edge *e, int i); |
fb3f88cc | 899 | |
3f84bf08 | 900 | /* From tree-sra.c: */ |
f7ed3195 | 901 | tree build_ref_for_offset (location_t, tree, poly_int64, bool, tree, |
e4b5cace | 902 | gimple_stmt_iterator *, bool); |
3f84bf08 | 903 | |
3edf64aa DM |
904 | /* In ipa-cp.c */ |
905 | void ipa_cp_c_finalize (void); | |
906 | ||
518dc859 | 907 | #endif /* IPA_PROP_H */ |