]>
Commit | Line | Data |
---|---|---|
518dc859 | 1 | /* Interprocedural analyses. |
7adcbafe | 2 | Copyright (C) 2005-2022 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 | ||
e53b6e56 | 28 | /* ipa-prop.cc 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 | ||
eb270950 FX |
42 | IPA_JF_LOAD_AGG is a compound pass-through jump function, in which primary |
43 | operation on formal parameter is memory dereference that loads a value from | |
44 | a part of an aggregate, which is represented or pointed to by the formal | |
45 | parameter. Moreover, an additional unary/binary operation can be applied on | |
46 | the loaded value, and final result is passed as actual argument of callee | |
47 | (e.g. *(param_1(D) + 4) op 24 ). It is meant to describe usage of aggregate | |
48 | parameter or by-reference parameter referenced in argument passing, commonly | |
49 | found in C++ and Fortran. | |
50 | ||
b258210c MJ |
51 | IPA_JF_ANCESTOR is a special pass-through jump function, which means that |
52 | the result is an address of a part of the object pointed to by the formal | |
53 | parameter to which the function refers. It is mainly intended to represent | |
026c3cfd | 54 | getting addresses of ancestor fields in C++ |
b258210c MJ |
55 | (e.g. &this_1(D)->D.1766.D.1756). Note that if the original pointer is |
56 | NULL, ancestor jump function must behave like a simple pass-through. | |
57 | ||
58 | Other pass-through functions can either simply pass on an unchanged formal | |
59 | parameter or can apply one simple binary operation to it (such jump | |
60 | functions are called polynomial). | |
61 | ||
e53b6e56 | 62 | Jump functions are computed in ipa-prop.cc by function |
b258210c MJ |
63 | update_call_notes_after_inlining. Some information can be lost and jump |
64 | functions degraded accordingly when inlining, see | |
65 | update_call_notes_after_inlining in the same file. */ | |
685b0d13 | 66 | |
518dc859 RL |
67 | enum jump_func_type |
68 | { | |
133f9369 | 69 | IPA_JF_UNKNOWN = 0, /* newly allocated and zeroed jump functions default */ |
b258210c | 70 | IPA_JF_CONST, /* represented by field costant */ |
b258210c | 71 | IPA_JF_PASS_THROUGH, /* represented by field pass_through */ |
eb270950 | 72 | IPA_JF_LOAD_AGG, /* represented by field load_agg */ |
b258210c | 73 | IPA_JF_ANCESTOR /* represented by field ancestor */ |
518dc859 RL |
74 | }; |
75 | ||
4502fe8d MJ |
76 | struct ipa_cst_ref_desc; |
77 | ||
78 | /* Structure holding data required to describe a constant jump function. */ | |
79 | struct GTY(()) ipa_constant_data | |
80 | { | |
81 | /* THe value of the constant. */ | |
82 | tree value; | |
83 | /* Pointer to the structure that describes the reference. */ | |
84 | struct ipa_cst_ref_desc GTY((skip)) *rdesc; | |
85 | }; | |
86 | ||
685b0d13 MJ |
87 | /* Structure holding data required to describe a pass-through jump function. */ |
88 | ||
fb3f88cc | 89 | struct GTY(()) ipa_pass_through_data |
685b0d13 MJ |
90 | { |
91 | /* If an operation is to be performed on the original parameter, this is the | |
92 | second (constant) operand. */ | |
93 | tree operand; | |
94 | /* Number of the caller's formal parameter being passed. */ | |
95 | int formal_id; | |
96 | /* Operation that is performed on the argument before it is passed on. | |
f38a33a2 MJ |
97 | Special values which have other meaning than in normal contexts: |
98 | - NOP_EXPR means no operation, not even type conversion. | |
99 | - ASSERT_EXPR means that only the value in operand is allowed to pass | |
100 | through (without any change), for all other values the result is | |
101 | unknown. | |
102 | Otherwise operation must be a simple binary or unary arithmetic operation | |
103 | where the caller's parameter is the first operand and (for binary | |
104 | operations) the operand field from this structure is the second one. */ | |
685b0d13 | 105 | enum tree_code operation; |
8b7773a4 MJ |
106 | /* When the passed value is a pointer, it is set to true only when we are |
107 | certain that no write to the object it points to has occurred since the | |
108 | caller functions started execution, except for changes noted in the | |
109 | aggregate part of the jump function (see description of | |
110 | ipa_agg_jump_function). The flag is used only when the operation is | |
111 | NOP_EXPR. */ | |
b8f6e610 | 112 | unsigned agg_preserved : 1; |
685b0d13 MJ |
113 | }; |
114 | ||
eb270950 FX |
115 | /* Structure holding data required to describe a load-value-from-aggregate |
116 | jump function. */ | |
117 | ||
118 | struct GTY(()) ipa_load_agg_data | |
119 | { | |
120 | /* Inherit from pass through jump function, describing unary/binary | |
121 | operation on the value loaded from aggregate that is represented or | |
122 | pointed to by the formal parameter, specified by formal_id in this | |
123 | pass_through jump function data structure. */ | |
124 | struct ipa_pass_through_data pass_through; | |
125 | /* Type of the value loaded from the aggregate. */ | |
126 | tree type; | |
127 | /* Offset at which the value is located within the aggregate. */ | |
128 | HOST_WIDE_INT offset; | |
129 | /* True if loaded by reference (the aggregate is pointed to by the formal | |
130 | parameter) or false if loaded by value (the aggregate is represented | |
131 | by the formal parameter). */ | |
132 | bool by_ref; | |
133 | }; | |
134 | ||
b258210c MJ |
135 | /* Structure holding data required to describe an ancestor pass-through |
136 | jump function. */ | |
685b0d13 | 137 | |
fb3f88cc | 138 | struct GTY(()) ipa_ancestor_jf_data |
685b0d13 MJ |
139 | { |
140 | /* Offset of the field representing the ancestor. */ | |
141 | HOST_WIDE_INT offset; | |
685b0d13 MJ |
142 | /* Number of the caller's formal parameter being passed. */ |
143 | int formal_id; | |
8b7773a4 | 144 | /* Flag with the same meaning like agg_preserve in ipa_pass_through_data. */ |
b8f6e610 | 145 | unsigned agg_preserved : 1; |
685b0d13 MJ |
146 | }; |
147 | ||
eb270950 FX |
148 | /* A jump function for an aggregate part at a given offset, which describes how |
149 | it content value is generated. All unlisted positions are assumed to have a | |
150 | value defined in an unknown way. */ | |
8b7773a4 | 151 | |
84562394 | 152 | struct GTY(()) ipa_agg_jf_item |
8b7773a4 | 153 | { |
eb270950 | 154 | /* The offset for the aggregate part. */ |
8b7773a4 MJ |
155 | HOST_WIDE_INT offset; |
156 | ||
eb270950 FX |
157 | /* Data type of the aggregate part. */ |
158 | tree type; | |
ac6f2e59 | 159 | |
eb270950 FX |
160 | /* Jump function type. */ |
161 | enum jump_func_type jftype; | |
8b7773a4 | 162 | |
eb270950 FX |
163 | /* Represents a value of jump function. constant represents the actual constant |
164 | in constant jump function content. pass_through is used only in simple pass | |
165 | through jump function context. load_agg is for load-value-from-aggregate | |
166 | jump function context. */ | |
167 | union jump_func_agg_value | |
168 | { | |
169 | tree GTY ((tag ("IPA_JF_CONST"))) constant; | |
170 | struct ipa_pass_through_data GTY ((tag ("IPA_JF_PASS_THROUGH"))) pass_through; | |
171 | struct ipa_load_agg_data GTY ((tag ("IPA_JF_LOAD_AGG"))) load_agg; | |
172 | } GTY ((desc ("%1.jftype"))) value; | |
173 | }; | |
8b7773a4 | 174 | |
eb270950 | 175 | /* Jump functions describing a set of aggregate contents. */ |
8b7773a4 MJ |
176 | |
177 | struct GTY(()) ipa_agg_jump_function | |
3e293154 | 178 | { |
eb270950 | 179 | /* Description of the individual jump function item. */ |
84562394 | 180 | vec<ipa_agg_jf_item, va_gc> *items; |
eb270950 | 181 | /* True if the data was passed by reference (as opposed to by value). */ |
8b7773a4 | 182 | bool by_ref; |
eb270950 FX |
183 | }; |
184 | ||
185 | /* An element in an aggregate part describing a known value at a given offset. | |
186 | All unlisted positions are assumed to be unknown and all listed values must | |
187 | fulfill is_gimple_ip_invariant. */ | |
188 | ||
189 | struct ipa_agg_value | |
190 | { | |
191 | /* The offset at which the known value is located within the aggregate. */ | |
192 | HOST_WIDE_INT offset; | |
ac6f2e59 | 193 | |
eb270950 FX |
194 | /* The known constant. */ |
195 | tree value; | |
196 | ||
197 | /* Return true if OTHER describes same agg value. */ | |
198 | bool equal_to (const ipa_agg_value &other); | |
199 | }; | |
200 | ||
201 | /* Structure describing a set of known offset/value for aggregate. */ | |
202 | ||
203 | struct ipa_agg_value_set | |
204 | { | |
205 | /* Description of the individual item. */ | |
206 | vec<ipa_agg_value> items; | |
207 | /* True if the data was passed by reference (as opposed to by value). */ | |
208 | bool by_ref; | |
209 | ||
210 | /* Return true if OTHER describes same agg values. */ | |
211 | bool equal_to (const ipa_agg_value_set &other) | |
ac6f2e59 JH |
212 | { |
213 | if (by_ref != other.by_ref) | |
214 | return false; | |
eb270950 | 215 | if (items.length () != other.items.length ()) |
ac6f2e59 | 216 | return false; |
eb270950 FX |
217 | for (unsigned int i = 0; i < items.length (); i++) |
218 | if (!items[i].equal_to (other.items[i])) | |
ac6f2e59 JH |
219 | return false; |
220 | return true; | |
221 | } | |
eb270950 FX |
222 | |
223 | /* Return true if there is any value for aggregate. */ | |
224 | bool is_empty () const | |
225 | { | |
226 | return items.is_empty (); | |
227 | } | |
228 | ||
229 | ipa_agg_value_set copy () const | |
230 | { | |
231 | ipa_agg_value_set new_copy; | |
232 | ||
233 | new_copy.items = items.copy (); | |
234 | new_copy.by_ref = by_ref; | |
235 | ||
236 | return new_copy; | |
237 | } | |
238 | ||
239 | void release () | |
240 | { | |
241 | items.release (); | |
242 | } | |
3e293154 MJ |
243 | }; |
244 | ||
eb270950 FX |
245 | /* Return copy of a vec<ipa_agg_value_set>. */ |
246 | ||
247 | static inline vec<ipa_agg_value_set> | |
248 | ipa_copy_agg_values (const vec<ipa_agg_value_set> &aggs) | |
249 | { | |
250 | vec<ipa_agg_value_set> aggs_copy = vNULL; | |
251 | ||
252 | if (!aggs.is_empty ()) | |
253 | { | |
254 | ipa_agg_value_set *agg; | |
255 | int i; | |
256 | ||
257 | aggs_copy.reserve_exact (aggs.length ()); | |
258 | ||
259 | FOR_EACH_VEC_ELT (aggs, i, agg) | |
260 | aggs_copy.quick_push (agg->copy ()); | |
261 | } | |
262 | ||
263 | return aggs_copy; | |
264 | } | |
265 | ||
266 | /* For vec<ipa_agg_value_set>, DO NOT call release(), use below function | |
267 | instead. Because ipa_agg_value_set contains a field of vector type, we | |
268 | should release this child vector in each element before reclaiming the | |
269 | whole vector. */ | |
270 | ||
271 | static inline void | |
9c572192 JH |
272 | ipa_release_agg_values (vec<ipa_agg_value_set> &aggs, |
273 | bool release_vector = true) | |
eb270950 FX |
274 | { |
275 | ipa_agg_value_set *agg; | |
276 | int i; | |
277 | ||
278 | FOR_EACH_VEC_ELT (aggs, i, agg) | |
279 | agg->release (); | |
9c572192 JH |
280 | if (release_vector) |
281 | aggs.release (); | |
eb270950 | 282 | } |
8b7773a4 | 283 | |
209ca542 | 284 | /* Information about zero/non-zero bits. */ |
6c1dae73 | 285 | class GTY(()) ipa_bits |
209ca542 | 286 | { |
6c1dae73 | 287 | public: |
209ca542 PK |
288 | /* The propagated value. */ |
289 | widest_int value; | |
290 | /* Mask corresponding to the value. | |
291 | Similar to ccp_lattice_t, if xth bit of mask is 0, | |
292 | implies xth bit of value is constant. */ | |
293 | widest_int mask; | |
209ca542 PK |
294 | }; |
295 | ||
8bc5448f | 296 | /* Info about value ranges. */ |
86cd0334 | 297 | |
6c1dae73 | 298 | class GTY(()) ipa_vr |
8bc5448f | 299 | { |
6c1dae73 | 300 | public: |
8bc5448f KV |
301 | /* The data fields below are valid only if known is true. */ |
302 | bool known; | |
54994253 | 303 | enum value_range_kind type; |
8bc5448f KV |
304 | wide_int min; |
305 | wide_int max; | |
523fe5b6 | 306 | bool nonzero_p (tree) const; |
8bc5448f KV |
307 | }; |
308 | ||
be95e2b9 MJ |
309 | /* A jump function for a callsite represents the values passed as actual |
310 | arguments of the callsite. See enum jump_func_type for the various | |
518dc859 | 311 | types of jump functions supported. */ |
84562394 | 312 | struct GTY (()) ipa_jump_func |
518dc859 | 313 | { |
eb270950 FX |
314 | /* Aggregate jump function description. See struct ipa_agg_jump_function |
315 | and its description. */ | |
8b7773a4 MJ |
316 | struct ipa_agg_jump_function agg; |
317 | ||
86cd0334 MJ |
318 | /* Information about zero/non-zero bits. The pointed to structure is shared |
319 | betweed different jump functions. Use ipa_set_jfunc_bits to set this | |
320 | field. */ | |
99b1c316 | 321 | class ipa_bits *bits; |
209ca542 | 322 | |
a5e14a42 | 323 | /* Information about value range, containing valid data only when vr_known is |
86cd0334 MJ |
324 | true. The pointed to structure is shared betweed different jump |
325 | functions. Use ipa_set_jfunc_vr to set this field. */ | |
4ba9fb0a | 326 | value_range *m_vr; |
8bc5448f | 327 | |
518dc859 | 328 | enum jump_func_type type; |
fb3f88cc JH |
329 | /* Represents a value of a jump function. pass_through is used only in jump |
330 | function context. constant represents the actual constant in constant jump | |
331 | functions and member_cst holds constant c++ member functions. */ | |
332 | union jump_func_value | |
333 | { | |
4502fe8d | 334 | struct ipa_constant_data GTY ((tag ("IPA_JF_CONST"))) constant; |
fb3f88cc JH |
335 | struct ipa_pass_through_data GTY ((tag ("IPA_JF_PASS_THROUGH"))) pass_through; |
336 | struct ipa_ancestor_jf_data GTY ((tag ("IPA_JF_ANCESTOR"))) ancestor; | |
fb3f88cc | 337 | } GTY ((desc ("%1.type"))) value; |
84562394 | 338 | }; |
606d9a09 | 339 | |
518dc859 | 340 | |
7b872d9e MJ |
341 | /* Return the constant stored in a constant jump functin JFUNC. */ |
342 | ||
343 | static inline tree | |
344 | ipa_get_jf_constant (struct ipa_jump_func *jfunc) | |
345 | { | |
346 | gcc_checking_assert (jfunc->type == IPA_JF_CONST); | |
4502fe8d MJ |
347 | return jfunc->value.constant.value; |
348 | } | |
349 | ||
350 | static inline struct ipa_cst_ref_desc * | |
351 | ipa_get_jf_constant_rdesc (struct ipa_jump_func *jfunc) | |
352 | { | |
353 | gcc_checking_assert (jfunc->type == IPA_JF_CONST); | |
354 | return jfunc->value.constant.rdesc; | |
7b872d9e MJ |
355 | } |
356 | ||
357 | /* Return the operand of a pass through jmp function JFUNC. */ | |
358 | ||
359 | static inline tree | |
360 | ipa_get_jf_pass_through_operand (struct ipa_jump_func *jfunc) | |
361 | { | |
362 | gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH); | |
363 | return jfunc->value.pass_through.operand; | |
364 | } | |
365 | ||
366 | /* Return the number of the caller's formal parameter that a pass through jump | |
367 | function JFUNC refers to. */ | |
368 | ||
369 | static inline int | |
370 | ipa_get_jf_pass_through_formal_id (struct ipa_jump_func *jfunc) | |
371 | { | |
372 | gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH); | |
373 | return jfunc->value.pass_through.formal_id; | |
374 | } | |
375 | ||
376 | /* Return operation of a pass through jump function JFUNC. */ | |
377 | ||
378 | static inline enum tree_code | |
379 | ipa_get_jf_pass_through_operation (struct ipa_jump_func *jfunc) | |
380 | { | |
381 | gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH); | |
382 | return jfunc->value.pass_through.operation; | |
383 | } | |
384 | ||
b8f6e610 | 385 | /* Return the agg_preserved flag of a pass through jump function JFUNC. */ |
8b7773a4 MJ |
386 | |
387 | static inline bool | |
388 | ipa_get_jf_pass_through_agg_preserved (struct ipa_jump_func *jfunc) | |
389 | { | |
390 | gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH); | |
391 | return jfunc->value.pass_through.agg_preserved; | |
392 | } | |
393 | ||
44210a96 MJ |
394 | /* Return true if pass through jump function JFUNC preserves type |
395 | information. */ | |
b8f6e610 MJ |
396 | |
397 | static inline bool | |
398 | ipa_get_jf_pass_through_type_preserved (struct ipa_jump_func *jfunc) | |
399 | { | |
400 | gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH); | |
44210a96 | 401 | return jfunc->value.pass_through.agg_preserved; |
b8f6e610 MJ |
402 | } |
403 | ||
7b872d9e MJ |
404 | /* Return the offset of an ancestor jump function JFUNC. */ |
405 | ||
406 | static inline HOST_WIDE_INT | |
407 | ipa_get_jf_ancestor_offset (struct ipa_jump_func *jfunc) | |
408 | { | |
409 | gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR); | |
410 | return jfunc->value.ancestor.offset; | |
411 | } | |
412 | ||
7b872d9e MJ |
413 | /* Return the number of the caller's formal parameter that an ancestor jump |
414 | function JFUNC refers to. */ | |
415 | ||
416 | static inline int | |
417 | ipa_get_jf_ancestor_formal_id (struct ipa_jump_func *jfunc) | |
418 | { | |
419 | gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR); | |
420 | return jfunc->value.ancestor.formal_id; | |
421 | } | |
422 | ||
b8f6e610 | 423 | /* Return the agg_preserved flag of an ancestor jump function JFUNC. */ |
7b872d9e | 424 | |
8b7773a4 MJ |
425 | static inline bool |
426 | ipa_get_jf_ancestor_agg_preserved (struct ipa_jump_func *jfunc) | |
7b872d9e | 427 | { |
8b7773a4 MJ |
428 | gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR); |
429 | return jfunc->value.ancestor.agg_preserved; | |
7b872d9e MJ |
430 | } |
431 | ||
44210a96 | 432 | /* Return true if ancestor jump function JFUNC presrves type information. */ |
b8f6e610 MJ |
433 | |
434 | static inline bool | |
435 | ipa_get_jf_ancestor_type_preserved (struct ipa_jump_func *jfunc) | |
436 | { | |
437 | gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR); | |
44210a96 | 438 | return jfunc->value.ancestor.agg_preserved; |
b8f6e610 MJ |
439 | } |
440 | ||
9d5af1db MJ |
441 | /* Class for allocating a bundle of various potentially known properties about |
442 | actual arguments of a particular call on stack for the usual case and on | |
443 | heap only if there are unusually many arguments. The data is deallocated | |
444 | when the instance of this class goes out of scope or is otherwise | |
445 | destructed. */ | |
446 | ||
447 | class ipa_auto_call_arg_values | |
448 | { | |
449 | public: | |
450 | ~ipa_auto_call_arg_values (); | |
451 | ||
452 | /* If m_known_vals (vector of known "scalar" values) is sufficiantly long, | |
453 | return its element at INDEX, otherwise return NULL. */ | |
454 | tree safe_sval_at (int index) | |
455 | { | |
456 | /* TODO: Assert non-negative index here and test. */ | |
457 | if ((unsigned) index < m_known_vals.length ()) | |
458 | return m_known_vals[index]; | |
459 | return NULL; | |
460 | } | |
461 | ||
462 | /* If m_known_aggs is sufficiantly long, return the pointer rto its element | |
463 | at INDEX, otherwise return NULL. */ | |
464 | ipa_agg_value_set *safe_aggval_at (int index) | |
465 | { | |
466 | /* TODO: Assert non-negative index here and test. */ | |
467 | if ((unsigned) index < m_known_aggs.length ()) | |
468 | return &m_known_aggs[index]; | |
469 | return NULL; | |
470 | } | |
471 | ||
472 | /* Vector describing known values of parameters. */ | |
473 | auto_vec<tree, 32> m_known_vals; | |
474 | ||
475 | /* Vector describing known polymorphic call contexts. */ | |
476 | auto_vec<ipa_polymorphic_call_context, 32> m_known_contexts; | |
477 | ||
478 | /* Vector describing known aggregate values. */ | |
479 | auto_vec<ipa_agg_value_set, 32> m_known_aggs; | |
480 | ||
481 | /* Vector describing known value ranges of arguments. */ | |
482 | auto_vec<value_range, 32> m_known_value_ranges; | |
483 | }; | |
484 | ||
485 | /* Class bundling the various potentially known properties about actual | |
486 | arguments of a particular call. This variant does not deallocate the | |
487 | bundled data in any way. */ | |
488 | ||
489 | class ipa_call_arg_values | |
490 | { | |
491 | public: | |
492 | /* Default constructor, setting the vectors to empty ones. */ | |
493 | ipa_call_arg_values () | |
494 | {} | |
495 | ||
496 | /* Construct this general variant of the bundle from the variant which uses | |
497 | auto_vecs to hold the vectors. This means that vectors of objects | |
498 | constructed with this constructor should not be changed because if they | |
499 | get reallocated, the member vectors and the underlying auto_vecs would get | |
500 | out of sync. */ | |
501 | ipa_call_arg_values (ipa_auto_call_arg_values *aavals) | |
a3d3e8c3 MS |
502 | : m_known_vals (aavals->m_known_vals.to_vec_legacy ()), |
503 | m_known_contexts (aavals->m_known_contexts.to_vec_legacy ()), | |
504 | m_known_aggs (aavals->m_known_aggs.to_vec_legacy ()), | |
505 | m_known_value_ranges (aavals->m_known_value_ranges.to_vec_legacy ()) | |
9d5af1db MJ |
506 | {} |
507 | ||
508 | /* If m_known_vals (vector of known "scalar" values) is sufficiantly long, | |
509 | return its element at INDEX, otherwise return NULL. */ | |
510 | tree safe_sval_at (int index) | |
511 | { | |
512 | /* TODO: Assert non-negative index here and test. */ | |
513 | if ((unsigned) index < m_known_vals.length ()) | |
514 | return m_known_vals[index]; | |
515 | return NULL; | |
516 | } | |
517 | ||
518 | /* If m_known_aggs is sufficiantly long, return the pointer rto its element | |
519 | at INDEX, otherwise return NULL. */ | |
520 | ipa_agg_value_set *safe_aggval_at (int index) | |
521 | { | |
522 | /* TODO: Assert non-negative index here and test. */ | |
523 | if ((unsigned) index < m_known_aggs.length ()) | |
524 | return &m_known_aggs[index]; | |
525 | return NULL; | |
526 | } | |
527 | ||
528 | /* Vector describing known values of parameters. */ | |
529 | vec<tree> m_known_vals = vNULL; | |
530 | ||
531 | /* Vector describing known polymorphic call contexts. */ | |
532 | vec<ipa_polymorphic_call_context> m_known_contexts = vNULL; | |
533 | ||
534 | /* Vector describing known aggregate values. */ | |
535 | vec<ipa_agg_value_set> m_known_aggs = vNULL; | |
536 | ||
537 | /* Vector describing known value ranges of arguments. */ | |
538 | vec<value_range> m_known_value_ranges = vNULL; | |
539 | }; | |
540 | ||
541 | ||
310bc633 | 542 | /* Summary describing a single formal parameter. */ |
b258210c | 543 | |
f65f1ae3 | 544 | struct GTY(()) ipa_param_descriptor |
f8e2a1ed | 545 | { |
209ca542 | 546 | /* In analysis and modification phase, this is the PARAM_DECL of this |
700d4cb0 | 547 | parameter, in IPA LTO phase, this is the type of the described |
209ca542 PK |
548 | parameter or NULL if not known. Do not read this field directly but |
549 | through ipa_get_param and ipa_get_type as appropriate. */ | |
550 | tree decl_or_type; | |
4502fe8d MJ |
551 | /* If all uses of the parameter are described by ipa-prop structures, this |
552 | says how many there are. If any use could not be described by means of | |
13586172 MJ |
553 | ipa-prop structures (which include flag dereferenced below), this is |
554 | IPA_UNDESCRIBED_USE. */ | |
4502fe8d | 555 | int controlled_uses; |
13586172 | 556 | unsigned int move_cost : 27; |
339f49ec JH |
557 | /* The parameter is used. */ |
558 | unsigned used : 1; | |
40a777e8 JH |
559 | unsigned used_by_ipa_predicates : 1; |
560 | unsigned used_by_indirect_call : 1; | |
561 | unsigned used_by_polymorphic_call : 1; | |
13586172 MJ |
562 | /* Set to true when in addition to being used in call statements, the |
563 | parameter has also been used for loads (but not for writes, does not | |
564 | escape, etc.). This allows us to identify parameters p which are only | |
565 | used as *p, and so when we propagate a constant to them, we can generate a | |
566 | LOAD and not ADDR reference to them. */ | |
567 | unsigned load_dereferenced : 1; | |
f8e2a1ed MJ |
568 | }; |
569 | ||
dcd416e3 MJ |
570 | /* ipa_node_params stores information related to formal parameters of functions |
571 | and some other information for interprocedural passes that operate on | |
572 | parameters (such as ipa-cp). */ | |
310bc633 | 573 | |
6c1dae73 | 574 | class GTY((for_user)) ipa_node_params |
518dc859 | 575 | { |
6c1dae73 | 576 | public: |
e806796d ML |
577 | /* Default constructor. */ |
578 | ipa_node_params (); | |
579 | ||
580 | /* Default destructor. */ | |
581 | ~ipa_node_params (); | |
582 | ||
310bc633 MJ |
583 | /* Information about individual formal parameters that are gathered when |
584 | summaries are generated. */ | |
f65f1ae3 | 585 | vec<ipa_param_descriptor, va_gc> *descriptors; |
310bc633 MJ |
586 | /* Pointer to an array of structures describing individual formal |
587 | parameters. */ | |
99b1c316 | 588 | class ipcp_param_lattices * GTY((skip)) lattices; |
310bc633 MJ |
589 | /* Only for versioned nodes this field would not be NULL, |
590 | it points to the node that IPA cp cloned from. */ | |
f65f1ae3 | 591 | struct cgraph_node * GTY((skip)) ipcp_orig_node; |
44210a96 MJ |
592 | /* If this node is an ipa-cp clone, these are the known constants that |
593 | describe what it has been specialized for. */ | |
f65f1ae3 | 594 | vec<tree> GTY((skip)) known_csts; |
44210a96 MJ |
595 | /* If this node is an ipa-cp clone, these are the known polymorphic contexts |
596 | that describe what it has been specialized for. */ | |
f65f1ae3 | 597 | vec<ipa_polymorphic_call_context> GTY((skip)) known_contexts; |
8aab5218 MJ |
598 | /* Whether the param uses analysis and jump function computation has already |
599 | been performed. */ | |
600 | unsigned analysis_done : 1; | |
310bc633 | 601 | /* Whether the function is enqueued in ipa-cp propagation stack. */ |
448f65db | 602 | unsigned node_enqueued : 1; |
310bc633 MJ |
603 | /* Whether we should create a specialized version based on values that are |
604 | known to be constant in all contexts. */ | |
eb20b778 MJ |
605 | unsigned do_clone_for_all_contexts : 1; |
606 | /* Set if this is an IPA-CP clone for all contexts. */ | |
607 | unsigned is_all_contexts_clone : 1; | |
310bc633 MJ |
608 | /* Node has been completely replaced by clones and will be removed after |
609 | ipa-cp is finished. */ | |
610 | unsigned node_dead : 1; | |
af21714c MJ |
611 | /* Node is involved in a recursion, potentionally indirect. */ |
612 | unsigned node_within_scc : 1; | |
9b14fc33 FX |
613 | /* Node contains only direct recursion. */ |
614 | unsigned node_is_self_scc : 1; | |
af21714c MJ |
615 | /* Node is calling a private function called only once. */ |
616 | unsigned node_calling_single_call : 1; | |
7e729474 ML |
617 | /* False when there is something makes versioning impossible. */ |
618 | unsigned versionable : 1; | |
518dc859 RL |
619 | }; |
620 | ||
e806796d ML |
621 | inline |
622 | ipa_node_params::ipa_node_params () | |
623 | : descriptors (NULL), lattices (NULL), ipcp_orig_node (NULL), | |
624 | known_csts (vNULL), known_contexts (vNULL), analysis_done (0), | |
625 | node_enqueued (0), do_clone_for_all_contexts (0), is_all_contexts_clone (0), | |
a2ae4e9a JH |
626 | node_dead (0), node_within_scc (0), node_is_self_scc (0), |
627 | node_calling_single_call (0), versionable (0) | |
e806796d ML |
628 | { |
629 | } | |
630 | ||
631 | inline | |
632 | ipa_node_params::~ipa_node_params () | |
633 | { | |
634 | free (lattices); | |
7ee0681e | 635 | vec_free (descriptors); |
e806796d ML |
636 | known_csts.release (); |
637 | known_contexts.release (); | |
638 | } | |
639 | ||
ff302741 PB |
640 | /* Intermediate information that we get from alias analysis about a particular |
641 | parameter in a particular basic_block. When a parameter or the memory it | |
56b40062 MJ |
642 | references is marked modified, we use that information in all dominated |
643 | blocks without consulting alias analysis oracle. */ | |
ff302741 | 644 | |
56b40062 | 645 | struct ipa_param_aa_status |
ff302741 PB |
646 | { |
647 | /* Set when this structure contains meaningful information. If not, the | |
648 | structure describing a dominating BB should be used instead. */ | |
649 | bool valid; | |
650 | ||
651 | /* Whether we have seen something which might have modified the data in | |
652 | question. PARM is for the parameter itself, REF is for data it points to | |
653 | but using the alias type of individual accesses and PT is the same thing | |
654 | but for computing aggregate pass-through functions using a very inclusive | |
655 | ao_ref. */ | |
656 | bool parm_modified, ref_modified, pt_modified; | |
657 | }; | |
658 | ||
659 | /* Information related to a given BB that used only when looking at function | |
660 | body. */ | |
661 | ||
662 | struct ipa_bb_info | |
663 | { | |
664 | /* Call graph edges going out of this BB. */ | |
665 | vec<cgraph_edge *> cg_edges; | |
666 | /* Alias analysis statuses of each formal parameter at this bb. */ | |
56b40062 | 667 | vec<ipa_param_aa_status> param_aa_statuses; |
ff302741 PB |
668 | }; |
669 | ||
670 | /* Structure with global information that is only used when looking at function | |
671 | body. */ | |
672 | ||
56b40062 | 673 | struct ipa_func_body_info |
ff302741 PB |
674 | { |
675 | /* The node that is being analyzed. */ | |
676 | cgraph_node *node; | |
677 | ||
678 | /* Its info. */ | |
99b1c316 | 679 | class ipa_node_params *info; |
ff302741 PB |
680 | |
681 | /* Information about individual BBs. */ | |
682 | vec<ipa_bb_info> bb_infos; | |
683 | ||
684 | /* Number of parameters. */ | |
685 | int param_count; | |
686 | ||
c628d1c3 MJ |
687 | /* Number of statements we are still allowed to walked by when analyzing this |
688 | function. */ | |
689 | unsigned int aa_walk_budget; | |
ff302741 PB |
690 | }; |
691 | ||
dcd416e3 MJ |
692 | /* ipa_node_params access functions. Please use these to access fields that |
693 | are or will be shared among various passes. */ | |
694 | ||
dcd416e3 | 695 | /* Return the number of formal parameters. */ |
be95e2b9 | 696 | |
dcd416e3 | 697 | static inline int |
99b1c316 | 698 | ipa_get_param_count (class ipa_node_params *info) |
dcd416e3 | 699 | { |
f65f1ae3 | 700 | return vec_safe_length (info->descriptors); |
dcd416e3 MJ |
701 | } |
702 | ||
5bc4cb04 MJ |
703 | /* Return the parameter declaration in DESCRIPTORS at index I and assert it is |
704 | indeed a PARM_DECL. */ | |
705 | ||
706 | static inline tree | |
707 | ipa_get_param (const vec<ipa_param_descriptor, va_gc> &descriptors, int i) | |
708 | { | |
709 | tree t = descriptors[i].decl_or_type; | |
710 | gcc_checking_assert (TREE_CODE (t) == PARM_DECL); | |
711 | return t; | |
712 | } | |
713 | ||
f8e2a1ed MJ |
714 | /* Return the declaration of Ith formal parameter of the function corresponding |
715 | to INFO. Note there is no setter function as this array is built just once | |
209ca542 PK |
716 | using ipa_initialize_node_params. This function should not be called in |
717 | WPA. */ | |
be95e2b9 | 718 | |
dcd416e3 | 719 | static inline tree |
99b1c316 | 720 | ipa_get_param (class ipa_node_params *info, int i) |
dcd416e3 | 721 | { |
f65f1ae3 | 722 | gcc_checking_assert (info->descriptors); |
5bc4cb04 | 723 | return ipa_get_param (*info->descriptors, i); |
209ca542 PK |
724 | } |
725 | ||
726 | /* Return the type of Ith formal parameter of the function corresponding | |
727 | to INFO if it is known or NULL if not. */ | |
728 | ||
729 | static inline tree | |
99b1c316 | 730 | ipa_get_type (class ipa_node_params *info, int i) |
209ca542 | 731 | { |
e5cf5e11 PK |
732 | if (vec_safe_length (info->descriptors) <= (unsigned) i) |
733 | return NULL; | |
f65f1ae3 | 734 | tree t = (*info->descriptors)[i].decl_or_type; |
209ca542 PK |
735 | if (!t) |
736 | return NULL; | |
737 | if (TYPE_P (t)) | |
738 | return t; | |
739 | gcc_checking_assert (TREE_CODE (t) == PARM_DECL); | |
740 | return TREE_TYPE (t); | |
339f49ec JH |
741 | } |
742 | ||
0e8853ee JH |
743 | /* Return the move cost of Ith formal parameter of the function corresponding |
744 | to INFO. */ | |
745 | ||
746 | static inline int | |
99b1c316 | 747 | ipa_get_param_move_cost (class ipa_node_params *info, int i) |
0e8853ee | 748 | { |
f65f1ae3 MJ |
749 | gcc_checking_assert (info->descriptors); |
750 | return (*info->descriptors)[i].move_cost; | |
0e8853ee JH |
751 | } |
752 | ||
310bc633 MJ |
753 | /* Set the used flag corresponding to the Ith formal parameter of the function |
754 | associated with INFO to VAL. */ | |
3949c4a7 | 755 | |
310bc633 | 756 | static inline void |
99b1c316 | 757 | ipa_set_param_used (class ipa_node_params *info, int i, bool val) |
3949c4a7 | 758 | { |
f65f1ae3 MJ |
759 | gcc_checking_assert (info->descriptors); |
760 | (*info->descriptors)[i].used = val; | |
3949c4a7 MJ |
761 | } |
762 | ||
40a777e8 JH |
763 | /* Set the used_by_ipa_predicates flag corresponding to the Ith formal |
764 | parameter of the function associated with INFO to VAL. */ | |
765 | ||
766 | static inline void | |
767 | ipa_set_param_used_by_ipa_predicates (class ipa_node_params *info, int i, bool val) | |
768 | { | |
769 | gcc_checking_assert (info->descriptors); | |
770 | (*info->descriptors)[i].used_by_ipa_predicates = val; | |
771 | } | |
772 | ||
773 | /* Set the used_by_indirect_call flag corresponding to the Ith formal | |
774 | parameter of the function associated with INFO to VAL. */ | |
775 | ||
776 | static inline void | |
777 | ipa_set_param_used_by_indirect_call (class ipa_node_params *info, int i, bool val) | |
778 | { | |
779 | gcc_checking_assert (info->descriptors); | |
780 | (*info->descriptors)[i].used_by_indirect_call = val; | |
781 | } | |
782 | ||
783 | /* Set the .used_by_polymorphic_call flag corresponding to the Ith formal | |
784 | parameter of the function associated with INFO to VAL. */ | |
785 | ||
786 | static inline void | |
787 | ipa_set_param_used_by_polymorphic_call (class ipa_node_params *info, int i, bool val) | |
788 | { | |
789 | gcc_checking_assert (info->descriptors); | |
790 | (*info->descriptors)[i].used_by_polymorphic_call = val; | |
791 | } | |
792 | ||
4502fe8d MJ |
793 | /* Return how many uses described by ipa-prop a parameter has or |
794 | IPA_UNDESCRIBED_USE if there is a use that is not described by these | |
795 | structures. */ | |
796 | static inline int | |
99b1c316 | 797 | ipa_get_controlled_uses (class ipa_node_params *info, int i) |
4502fe8d | 798 | { |
f65f1ae3 MJ |
799 | /* FIXME: introducing speculation causes out of bounds access here. */ |
800 | if (vec_safe_length (info->descriptors) > (unsigned)i) | |
801 | return (*info->descriptors)[i].controlled_uses; | |
5ce97055 | 802 | return IPA_UNDESCRIBED_USE; |
4502fe8d MJ |
803 | } |
804 | ||
805 | /* Set the controlled counter of a given parameter. */ | |
806 | ||
807 | static inline void | |
99b1c316 | 808 | ipa_set_controlled_uses (class ipa_node_params *info, int i, int val) |
4502fe8d | 809 | { |
f65f1ae3 MJ |
810 | gcc_checking_assert (info->descriptors); |
811 | (*info->descriptors)[i].controlled_uses = val; | |
4502fe8d MJ |
812 | } |
813 | ||
13586172 MJ |
814 | /* Assuming a parameter does not have IPA_UNDESCRIBED_USE controlled uses, |
815 | return flag which indicates it has been dereferenced but only in a load. */ | |
816 | static inline int | |
817 | ipa_get_param_load_dereferenced (class ipa_node_params *info, int i) | |
818 | { | |
819 | gcc_assert (ipa_get_controlled_uses (info, i) != IPA_UNDESCRIBED_USE); | |
820 | return (*info->descriptors)[i].load_dereferenced; | |
821 | } | |
822 | ||
823 | /* Set the load_dereferenced flag of a given parameter. */ | |
824 | ||
825 | static inline void | |
826 | ipa_set_param_load_dereferenced (class ipa_node_params *info, int i, bool val) | |
827 | { | |
828 | gcc_checking_assert (info->descriptors); | |
829 | (*info->descriptors)[i].load_dereferenced = val; | |
830 | } | |
831 | ||
310bc633 MJ |
832 | /* Return the used flag corresponding to the Ith formal parameter of the |
833 | function associated with INFO. */ | |
3949c4a7 MJ |
834 | |
835 | static inline bool | |
99b1c316 | 836 | ipa_is_param_used (class ipa_node_params *info, int i) |
3949c4a7 | 837 | { |
f65f1ae3 MJ |
838 | gcc_checking_assert (info->descriptors); |
839 | return (*info->descriptors)[i].used; | |
3949c4a7 MJ |
840 | } |
841 | ||
40a777e8 JH |
842 | /* Return the used_by_ipa_predicates flag corresponding to the Ith formal |
843 | parameter of the function associated with INFO. */ | |
844 | ||
845 | static inline bool | |
846 | ipa_is_param_used_by_ipa_predicates (class ipa_node_params *info, int i) | |
847 | { | |
848 | gcc_checking_assert (info->descriptors); | |
849 | return (*info->descriptors)[i].used_by_ipa_predicates; | |
850 | } | |
851 | ||
852 | /* Return the used_by_indirect_call flag corresponding to the Ith formal | |
853 | parameter of the function associated with INFO. */ | |
854 | ||
855 | static inline bool | |
856 | ipa_is_param_used_by_indirect_call (class ipa_node_params *info, int i) | |
857 | { | |
858 | gcc_checking_assert (info->descriptors); | |
859 | return (*info->descriptors)[i].used_by_indirect_call; | |
860 | } | |
861 | ||
862 | /* Return the used_by_polymorphic_call flag corresponding to the Ith formal | |
863 | parameter of the function associated with INFO. */ | |
864 | ||
865 | static inline bool | |
866 | ipa_is_param_used_by_polymorphic_call (class ipa_node_params *info, int i) | |
867 | { | |
868 | gcc_checking_assert (info->descriptors); | |
869 | return (*info->descriptors)[i].used_by_polymorphic_call; | |
870 | } | |
871 | ||
2c9561b5 MJ |
872 | /* Information about replacements done in aggregates for a given node (each |
873 | node has its linked list). */ | |
874 | struct GTY(()) ipa_agg_replacement_value | |
875 | { | |
876 | /* Next item in the linked list. */ | |
877 | struct ipa_agg_replacement_value *next; | |
878 | /* Offset within the aggregate. */ | |
879 | HOST_WIDE_INT offset; | |
880 | /* The constant value. */ | |
881 | tree value; | |
71837f64 | 882 | /* The parameter index. */ |
2c9561b5 | 883 | int index; |
7b920a9a MJ |
884 | /* Whether the value was passed by reference. */ |
885 | bool by_ref; | |
2c9561b5 MJ |
886 | }; |
887 | ||
04be694e MJ |
888 | /* Structure holding information for the transformation phase of IPA-CP. */ |
889 | ||
9d3e0adc | 890 | struct GTY(()) ipcp_transformation |
04be694e MJ |
891 | { |
892 | /* Linked list of known aggregate values. */ | |
893 | ipa_agg_replacement_value *agg_values; | |
209ca542 | 894 | /* Known bits information. */ |
86cd0334 | 895 | vec<ipa_bits *, va_gc> *bits; |
8bc5448f KV |
896 | /* Value range information. */ |
897 | vec<ipa_vr, va_gc> *m_vr; | |
98aad294 JH |
898 | |
899 | /* Default constructor. */ | |
900 | ipcp_transformation () | |
901 | : agg_values (NULL), bits (NULL), m_vr (NULL) | |
902 | { } | |
903 | ||
904 | /* Default destructor. */ | |
905 | ~ipcp_transformation () | |
906 | { | |
907 | ipa_agg_replacement_value *agg = agg_values; | |
908 | while (agg) | |
909 | { | |
910 | ipa_agg_replacement_value *next = agg->next; | |
911 | ggc_free (agg); | |
912 | agg = next; | |
913 | } | |
914 | vec_free (bits); | |
915 | vec_free (m_vr); | |
916 | } | |
04be694e | 917 | }; |
2c9561b5 MJ |
918 | |
919 | void ipa_set_node_agg_value_chain (struct cgraph_node *node, | |
920 | struct ipa_agg_replacement_value *aggvals); | |
9d3e0adc | 921 | void ipcp_transformation_initialize (void); |
12e088ba | 922 | void ipcp_free_transformation_sum (void); |
2c9561b5 | 923 | |
93c594a3 MJ |
924 | /* ipa_edge_args stores information related to a callsite and particularly its |
925 | arguments. It can be accessed by the IPA_EDGE_REF macro. */ | |
6fe906a3 MJ |
926 | |
927 | class GTY((for_user)) ipa_edge_args | |
518dc859 | 928 | { |
6fe906a3 MJ |
929 | public: |
930 | ||
931 | /* Default constructor. */ | |
932 | ipa_edge_args () : jump_functions (NULL), polymorphic_call_contexts (NULL) | |
933 | {} | |
934 | ||
935 | /* Destructor. */ | |
936 | ~ipa_edge_args () | |
937 | { | |
7ee0681e JH |
938 | unsigned int i; |
939 | ipa_jump_func *jf; | |
940 | FOR_EACH_VEC_SAFE_ELT (jump_functions, i, jf) | |
941 | vec_free (jf->agg.items); | |
6fe906a3 MJ |
942 | vec_free (jump_functions); |
943 | vec_free (polymorphic_call_contexts); | |
944 | } | |
945 | ||
946 | /* Vectors of the callsite's jump function and polymorphic context | |
947 | information of each parameter. */ | |
84562394 | 948 | vec<ipa_jump_func, va_gc> *jump_functions; |
5ce97055 | 949 | vec<ipa_polymorphic_call_context, va_gc> *polymorphic_call_contexts; |
84562394 | 950 | }; |
518dc859 | 951 | |
dcd416e3 MJ |
952 | /* ipa_edge_args access functions. Please use these to access fields that |
953 | are or will be shared among various passes. */ | |
954 | ||
dcd416e3 | 955 | /* Return the number of actual arguments. */ |
be95e2b9 | 956 | |
dcd416e3 | 957 | static inline int |
99b1c316 | 958 | ipa_get_cs_argument_count (class ipa_edge_args *args) |
dcd416e3 | 959 | { |
9771b263 | 960 | return vec_safe_length (args->jump_functions); |
dcd416e3 MJ |
961 | } |
962 | ||
963 | /* Returns a pointer to the jump function for the ith argument. Please note | |
964 | there is no setter function as jump functions are all set up in | |
965 | ipa_compute_jump_functions. */ | |
be95e2b9 | 966 | |
dcd416e3 | 967 | static inline struct ipa_jump_func * |
99b1c316 | 968 | ipa_get_ith_jump_func (class ipa_edge_args *args, int i) |
dcd416e3 | 969 | { |
9771b263 | 970 | return &(*args->jump_functions)[i]; |
dcd416e3 MJ |
971 | } |
972 | ||
5ce97055 JH |
973 | /* Returns a pointer to the polymorphic call context for the ith argument. |
974 | NULL if contexts are not computed. */ | |
99b1c316 MS |
975 | static inline class ipa_polymorphic_call_context * |
976 | ipa_get_ith_polymorhic_call_context (class ipa_edge_args *args, int i) | |
5ce97055 JH |
977 | { |
978 | if (!args->polymorphic_call_contexts) | |
979 | return NULL; | |
980 | return &(*args->polymorphic_call_contexts)[i]; | |
981 | } | |
982 | ||
9a1e784a | 983 | /* Function summary for ipa_node_params. */ |
f65f1ae3 | 984 | class GTY((user)) ipa_node_params_t: public function_summary <ipa_node_params *> |
dd912cb8 ML |
985 | { |
986 | public: | |
f65f1ae3 | 987 | ipa_node_params_t (symbol_table *table, bool ggc): |
40e67ab8 JH |
988 | function_summary<ipa_node_params *> (table, ggc) |
989 | { | |
990 | disable_insertion_hook (); | |
991 | } | |
771578a0 | 992 | |
dd912cb8 ML |
993 | /* Hook that is called by summary when a node is duplicated. */ |
994 | virtual void duplicate (cgraph_node *node, | |
995 | cgraph_node *node2, | |
996 | ipa_node_params *data, | |
997 | ipa_node_params *data2); | |
998 | }; | |
999 | ||
6fe906a3 MJ |
1000 | /* Summary to manange ipa_edge_args structures. */ |
1001 | ||
1002 | class GTY((user)) ipa_edge_args_sum_t : public call_summary <ipa_edge_args *> | |
1003 | { | |
1004 | public: | |
1005 | ipa_edge_args_sum_t (symbol_table *table, bool ggc) | |
1006 | : call_summary<ipa_edge_args *> (table, ggc) { } | |
1007 | ||
a33c028e JH |
1008 | void remove (cgraph_edge *edge) |
1009 | { | |
1010 | call_summary <ipa_edge_args *>::remove (edge); | |
1011 | } | |
1012 | ||
f658ad30 | 1013 | /* Hook that is called by summary when an edge is removed. */ |
6fe906a3 MJ |
1014 | virtual void remove (cgraph_edge *cs, ipa_edge_args *args); |
1015 | /* Hook that is called by summary when an edge is duplicated. */ | |
1016 | virtual void duplicate (cgraph_edge *src, | |
1017 | cgraph_edge *dst, | |
1018 | ipa_edge_args *old_args, | |
1019 | ipa_edge_args *new_args); | |
1020 | }; | |
1021 | ||
dd912cb8 | 1022 | /* Function summary where the parameter infos are actually stored. */ |
f65f1ae3 | 1023 | extern GTY(()) ipa_node_params_t * ipa_node_params_sum; |
6fe906a3 MJ |
1024 | /* Call summary to store information about edges such as jump functions. */ |
1025 | extern GTY(()) ipa_edge_args_sum_t *ipa_edge_args_sum; | |
f65f1ae3 | 1026 | |
9d3e0adc ML |
1027 | /* Function summary for IPA-CP transformation. */ |
1028 | class ipcp_transformation_t | |
1029 | : public function_summary<ipcp_transformation *> | |
1030 | { | |
1031 | public: | |
1032 | ipcp_transformation_t (symbol_table *table, bool ggc): | |
1033 | function_summary<ipcp_transformation *> (table, ggc) {} | |
1034 | ||
1035 | ~ipcp_transformation_t () {} | |
1036 | ||
1037 | static ipcp_transformation_t *create_ggc (symbol_table *symtab) | |
1038 | { | |
1039 | ipcp_transformation_t *summary | |
78cd68c0 | 1040 | = new (ggc_alloc_no_dtor <ipcp_transformation_t> ()) |
9d3e0adc ML |
1041 | ipcp_transformation_t (symtab, true); |
1042 | return summary; | |
1043 | } | |
98aad294 JH |
1044 | /* Hook that is called by summary when a node is duplicated. */ |
1045 | virtual void duplicate (cgraph_node *node, | |
1046 | cgraph_node *node2, | |
1047 | ipcp_transformation *data, | |
1048 | ipcp_transformation *data2); | |
9d3e0adc ML |
1049 | }; |
1050 | ||
1051 | /* Function summary where the IPA CP transformations are actually stored. */ | |
1052 | extern GTY(()) function_summary <ipcp_transformation *> *ipcp_transformation_sum; | |
f65f1ae3 | 1053 | |
771578a0 MJ |
1054 | /* Creating and freeing ipa_node_params and ipa_edge_args. */ |
1055 | void ipa_create_all_node_params (void); | |
1056 | void ipa_create_all_edge_args (void); | |
86cd0334 | 1057 | void ipa_check_create_edge_args (void); |
771578a0 MJ |
1058 | void ipa_free_all_node_params (void); |
1059 | void ipa_free_all_edge_args (void); | |
e33c6cd6 MJ |
1060 | void ipa_free_all_structures_after_ipa_cp (void); |
1061 | void ipa_free_all_structures_after_iinln (void); | |
dd912cb8 | 1062 | |
771578a0 | 1063 | void ipa_register_cgraph_hooks (void); |
fd29c024 | 1064 | int count_formal_params (tree fndecl); |
771578a0 MJ |
1065 | |
1066 | /* This function ensures the array of node param infos is big enough to | |
be95e2b9 MJ |
1067 | accommodate a structure for all nodes and reallocates it if not. */ |
1068 | ||
771578a0 MJ |
1069 | static inline void |
1070 | ipa_check_create_node_params (void) | |
1071 | { | |
dd912cb8 | 1072 | if (!ipa_node_params_sum) |
f65f1ae3 | 1073 | ipa_node_params_sum |
78cd68c0 | 1074 | = (new (ggc_alloc_no_dtor <ipa_node_params_t> ()) |
f65f1ae3 | 1075 | ipa_node_params_t (symtab, true)); |
771578a0 MJ |
1076 | } |
1077 | ||
6fe906a3 MJ |
1078 | /* Returns true if edge summary contains a record for EDGE. The main purpose |
1079 | of this function is that debug dumping function can check info availability | |
1080 | without causing allocations. */ | |
be95e2b9 | 1081 | |
0eae6bab MJ |
1082 | static inline bool |
1083 | ipa_edge_args_info_available_for_edge_p (struct cgraph_edge *edge) | |
1084 | { | |
6fe906a3 | 1085 | return ipa_edge_args_sum->exists (edge); |
0eae6bab MJ |
1086 | } |
1087 | ||
9d3e0adc | 1088 | static inline ipcp_transformation * |
04be694e MJ |
1089 | ipcp_get_transformation_summary (cgraph_node *node) |
1090 | { | |
9d3e0adc | 1091 | if (ipcp_transformation_sum == NULL) |
04be694e | 1092 | return NULL; |
9d3e0adc ML |
1093 | |
1094 | return ipcp_transformation_sum->get (node); | |
04be694e MJ |
1095 | } |
1096 | ||
2c9561b5 MJ |
1097 | /* Return the aggregate replacements for NODE, if there are any. */ |
1098 | ||
1099 | static inline struct ipa_agg_replacement_value * | |
04be694e | 1100 | ipa_get_agg_replacements_for_node (cgraph_node *node) |
2c9561b5 | 1101 | { |
9d3e0adc | 1102 | ipcp_transformation *ts = ipcp_get_transformation_summary (node); |
04be694e | 1103 | return ts ? ts->agg_values : NULL; |
2c9561b5 MJ |
1104 | } |
1105 | ||
f8e2a1ed MJ |
1106 | /* Function formal parameters related computations. */ |
1107 | void ipa_initialize_node_params (struct cgraph_node *node); | |
f8e2a1ed | 1108 | bool ipa_propagate_indirect_call_infos (struct cgraph_edge *cs, |
d52f5295 | 1109 | vec<cgraph_edge *> *new_edges); |
518dc859 | 1110 | |
9d5af1db MJ |
1111 | /* Indirect edge processing and target discovery. */ |
1112 | tree ipa_get_indirect_edge_target (struct cgraph_edge *ie, | |
1113 | ipa_call_arg_values *avals, | |
1114 | bool *speculative); | |
d2d668fb | 1115 | tree ipa_get_indirect_edge_target (struct cgraph_edge *ie, |
9d5af1db MJ |
1116 | ipa_auto_call_arg_values *avals, |
1117 | bool *speculative); | |
5ce97055 JH |
1118 | struct cgraph_edge *ipa_make_edge_direct_to_target (struct cgraph_edge *, tree, |
1119 | bool speculative = false); | |
72972c22 | 1120 | tree ipa_impossible_devirt_target (struct cgraph_edge *, tree); |
86cd0334 MJ |
1121 | ipa_bits *ipa_get_ipa_bits_for_value (const widest_int &value, |
1122 | const widest_int &mask); | |
1123 | ||
3949c4a7 | 1124 | |
310bc633 MJ |
1125 | /* Functions related to both. */ |
1126 | void ipa_analyze_node (struct cgraph_node *); | |
3949c4a7 | 1127 | |
8b7773a4 | 1128 | /* Aggregate jump function related functions. */ |
00dcc88a | 1129 | tree ipa_find_agg_cst_for_param (const ipa_agg_value_set *agg, tree scalar, |
91bb9f80 MJ |
1130 | HOST_WIDE_INT offset, bool by_ref, |
1131 | bool *from_global_constant = NULL); | |
1132 | bool ipa_load_from_parm_agg (struct ipa_func_body_info *fbi, | |
f65f1ae3 | 1133 | vec<ipa_param_descriptor, va_gc> *descriptors, |
91bb9f80 | 1134 | gimple *stmt, tree op, int *index_p, |
86003645 | 1135 | HOST_WIDE_INT *offset_p, poly_int64 *size_p, |
91bb9f80 | 1136 | bool *by_ref, bool *guaranteed_unmodified = NULL); |
8b7773a4 | 1137 | |
518dc859 | 1138 | /* Debugging interface. */ |
ca30a539 JH |
1139 | void ipa_print_node_params (FILE *, struct cgraph_node *node); |
1140 | void ipa_print_all_params (FILE *); | |
3e293154 MJ |
1141 | void ipa_print_node_jump_functions (FILE *f, struct cgraph_node *node); |
1142 | void ipa_print_all_jump_functions (FILE * f); | |
310bc633 MJ |
1143 | void ipcp_verify_propagated_values (void); |
1144 | ||
2651e637 ML |
1145 | template <typename value> |
1146 | class ipcp_value; | |
1147 | ||
fb0b2914 ML |
1148 | extern object_allocator<ipcp_value<tree> > ipcp_cst_values_pool; |
1149 | extern object_allocator<ipcp_value<ipa_polymorphic_call_context> > | |
2651e637 ML |
1150 | ipcp_poly_ctx_values_pool; |
1151 | ||
1152 | template <typename valtype> | |
99b1c316 | 1153 | struct ipcp_value_source; |
2651e637 | 1154 | |
fb0b2914 | 1155 | extern object_allocator<ipcp_value_source<tree> > ipcp_sources_pool; |
2651e637 | 1156 | |
99b1c316 | 1157 | struct ipcp_agg_lattice; |
2651e637 | 1158 | |
fb0b2914 | 1159 | extern object_allocator<ipcp_agg_lattice> ipcp_agg_lattice_pool; |
518dc859 | 1160 | |
2c9561b5 MJ |
1161 | void ipa_dump_agg_replacement_values (FILE *f, |
1162 | struct ipa_agg_replacement_value *av); | |
f27c1867 | 1163 | void ipa_prop_write_jump_functions (void); |
fb3f88cc | 1164 | void ipa_prop_read_jump_functions (void); |
04be694e MJ |
1165 | void ipcp_write_transformation_summaries (void); |
1166 | void ipcp_read_transformation_summaries (void); | |
99b1c316 MS |
1167 | int ipa_get_param_decl_index (class ipa_node_params *, tree); |
1168 | tree ipa_value_from_jfunc (class ipa_node_params *info, | |
e5cf5e11 | 1169 | struct ipa_jump_func *jfunc, tree type); |
2c9561b5 | 1170 | unsigned int ipcp_transform_function (struct cgraph_node *node); |
44210a96 MJ |
1171 | ipa_polymorphic_call_context ipa_context_from_jfunc (ipa_node_params *, |
1172 | cgraph_edge *, | |
1173 | int, | |
1174 | ipa_jump_func *); | |
68718e8e JH |
1175 | value_range ipa_value_range_from_jfunc (ipa_node_params *, cgraph_edge *, |
1176 | ipa_jump_func *, tree); | |
eb270950 FX |
1177 | ipa_agg_value_set ipa_agg_value_set_from_jfunc (ipa_node_params *, |
1178 | cgraph_node *, | |
1179 | ipa_agg_jump_function *); | |
99b1c316 | 1180 | void ipa_dump_param (FILE *, class ipa_node_params *info, int i); |
c3431191 | 1181 | void ipa_release_body_info (struct ipa_func_body_info *); |
5d5f1e95 | 1182 | tree ipa_get_callee_param_type (struct cgraph_edge *e, int i); |
c7ac9a0c | 1183 | bool ipcp_get_parm_bits (tree, tree *, widest_int *); |
c7b6a758 JH |
1184 | bool unadjusted_ptr_and_unit_offset (tree op, tree *ret, |
1185 | poly_int64 *offset_ret); | |
fb3f88cc | 1186 | |
e53b6e56 | 1187 | /* From tree-sra.cc: */ |
f7ed3195 | 1188 | tree build_ref_for_offset (location_t, tree, poly_int64, bool, tree, |
e4b5cace | 1189 | gimple_stmt_iterator *, bool); |
3f84bf08 | 1190 | |
e53b6e56 | 1191 | /* In ipa-cp.cc */ |
3edf64aa DM |
1192 | void ipa_cp_c_finalize (void); |
1193 | ||
518dc859 | 1194 | #endif /* IPA_PROP_H */ |