]>
Commit | Line | Data |
---|---|---|
1 | /* Interprocedural analyses. | |
2 | Copyright (C) 2005-2019 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GCC. | |
5 | ||
6 | GCC is free software; you can redistribute it and/or modify it under | |
7 | the terms of the GNU General Public License as published by the Free | |
8 | Software Foundation; either version 3, or (at your option) any later | |
9 | version. | |
10 | ||
11 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 | for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GCC; see the file COPYING3. If not see | |
18 | <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #ifndef IPA_PROP_H | |
21 | #define IPA_PROP_H | |
22 | ||
23 | /* The following definitions and interfaces are used by | |
24 | interprocedural analyses or parameters. */ | |
25 | ||
26 | #define IPA_UNDESCRIBED_USE -1 | |
27 | ||
28 | /* ipa-prop.c stuff (ipa-cp, indirect inlining): */ | |
29 | ||
30 | /* A jump function for a callsite represents the values passed as actual | |
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 : | |
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 | ||
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 | |
45 | getting addresses of ancestor fields in C++ | |
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 | ||
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. */ | |
57 | ||
58 | enum jump_func_type | |
59 | { | |
60 | IPA_JF_UNKNOWN = 0, /* newly allocated and zeroed jump functions default */ | |
61 | IPA_JF_CONST, /* represented by field costant */ | |
62 | IPA_JF_PASS_THROUGH, /* represented by field pass_through */ | |
63 | IPA_JF_ANCESTOR /* represented by field ancestor */ | |
64 | }; | |
65 | ||
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 | ||
77 | /* Structure holding data required to describe a pass-through jump function. */ | |
78 | ||
79 | struct GTY(()) ipa_pass_through_data | |
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; | |
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. */ | |
97 | unsigned agg_preserved : 1; | |
98 | }; | |
99 | ||
100 | /* Structure holding data required to describe an ancestor pass-through | |
101 | jump function. */ | |
102 | ||
103 | struct GTY(()) ipa_ancestor_jf_data | |
104 | { | |
105 | /* Offset of the field representing the ancestor. */ | |
106 | HOST_WIDE_INT offset; | |
107 | /* Number of the caller's formal parameter being passed. */ | |
108 | int formal_id; | |
109 | /* Flag with the same meaning like agg_preserve in ipa_pass_through_data. */ | |
110 | unsigned agg_preserved : 1; | |
111 | }; | |
112 | ||
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 | |
121 | fulfill is_gimple_ip_invariant. */ | |
122 | ||
123 | struct GTY(()) ipa_agg_jf_item | |
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; | |
130 | }; | |
131 | ||
132 | ||
133 | /* Aggregate jump function - i.e. description of contents of aggregates passed | |
134 | either by reference or value. */ | |
135 | ||
136 | struct GTY(()) ipa_agg_jump_function | |
137 | { | |
138 | /* Description of the individual items. */ | |
139 | vec<ipa_agg_jf_item, va_gc> *items; | |
140 | /* True if the data was passed by reference (as opposed to by value). */ | |
141 | bool by_ref; | |
142 | }; | |
143 | ||
144 | typedef struct ipa_agg_jump_function *ipa_agg_jump_function_p; | |
145 | ||
146 | /* Information about zero/non-zero bits. */ | |
147 | class GTY(()) ipa_bits | |
148 | { | |
149 | public: | |
150 | /* The propagated value. */ | |
151 | widest_int value; | |
152 | /* Mask corresponding to the value. | |
153 | Similar to ccp_lattice_t, if xth bit of mask is 0, | |
154 | implies xth bit of value is constant. */ | |
155 | widest_int mask; | |
156 | }; | |
157 | ||
158 | /* Info about value ranges. */ | |
159 | ||
160 | class GTY(()) ipa_vr | |
161 | { | |
162 | public: | |
163 | /* The data fields below are valid only if known is true. */ | |
164 | bool known; | |
165 | enum value_range_kind type; | |
166 | wide_int min; | |
167 | wide_int max; | |
168 | }; | |
169 | ||
170 | /* A jump function for a callsite represents the values passed as actual | |
171 | arguments of the callsite. See enum jump_func_type for the various | |
172 | types of jump functions supported. */ | |
173 | struct GTY (()) ipa_jump_func | |
174 | { | |
175 | /* Aggregate contants description. See struct ipa_agg_jump_function and its | |
176 | description. */ | |
177 | struct ipa_agg_jump_function agg; | |
178 | ||
179 | /* Information about zero/non-zero bits. The pointed to structure is shared | |
180 | betweed different jump functions. Use ipa_set_jfunc_bits to set this | |
181 | field. */ | |
182 | class ipa_bits *bits; | |
183 | ||
184 | /* Information about value range, containing valid data only when vr_known is | |
185 | true. The pointed to structure is shared betweed different jump | |
186 | functions. Use ipa_set_jfunc_vr to set this field. */ | |
187 | class value_range_base *m_vr; | |
188 | ||
189 | enum jump_func_type type; | |
190 | /* Represents a value of a jump function. pass_through is used only in jump | |
191 | function context. constant represents the actual constant in constant jump | |
192 | functions and member_cst holds constant c++ member functions. */ | |
193 | union jump_func_value | |
194 | { | |
195 | struct ipa_constant_data GTY ((tag ("IPA_JF_CONST"))) constant; | |
196 | struct ipa_pass_through_data GTY ((tag ("IPA_JF_PASS_THROUGH"))) pass_through; | |
197 | struct ipa_ancestor_jf_data GTY ((tag ("IPA_JF_ANCESTOR"))) ancestor; | |
198 | } GTY ((desc ("%1.type"))) value; | |
199 | }; | |
200 | ||
201 | ||
202 | /* Return the constant stored in a constant jump functin JFUNC. */ | |
203 | ||
204 | static inline tree | |
205 | ipa_get_jf_constant (struct ipa_jump_func *jfunc) | |
206 | { | |
207 | gcc_checking_assert (jfunc->type == IPA_JF_CONST); | |
208 | return jfunc->value.constant.value; | |
209 | } | |
210 | ||
211 | static inline struct ipa_cst_ref_desc * | |
212 | ipa_get_jf_constant_rdesc (struct ipa_jump_func *jfunc) | |
213 | { | |
214 | gcc_checking_assert (jfunc->type == IPA_JF_CONST); | |
215 | return jfunc->value.constant.rdesc; | |
216 | } | |
217 | ||
218 | /* Return the operand of a pass through jmp function JFUNC. */ | |
219 | ||
220 | static inline tree | |
221 | ipa_get_jf_pass_through_operand (struct ipa_jump_func *jfunc) | |
222 | { | |
223 | gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH); | |
224 | return jfunc->value.pass_through.operand; | |
225 | } | |
226 | ||
227 | /* Return the number of the caller's formal parameter that a pass through jump | |
228 | function JFUNC refers to. */ | |
229 | ||
230 | static inline int | |
231 | ipa_get_jf_pass_through_formal_id (struct ipa_jump_func *jfunc) | |
232 | { | |
233 | gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH); | |
234 | return jfunc->value.pass_through.formal_id; | |
235 | } | |
236 | ||
237 | /* Return operation of a pass through jump function JFUNC. */ | |
238 | ||
239 | static inline enum tree_code | |
240 | ipa_get_jf_pass_through_operation (struct ipa_jump_func *jfunc) | |
241 | { | |
242 | gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH); | |
243 | return jfunc->value.pass_through.operation; | |
244 | } | |
245 | ||
246 | /* Return the agg_preserved flag of a pass through jump function JFUNC. */ | |
247 | ||
248 | static inline bool | |
249 | ipa_get_jf_pass_through_agg_preserved (struct ipa_jump_func *jfunc) | |
250 | { | |
251 | gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH); | |
252 | return jfunc->value.pass_through.agg_preserved; | |
253 | } | |
254 | ||
255 | /* Return true if pass through jump function JFUNC preserves type | |
256 | information. */ | |
257 | ||
258 | static inline bool | |
259 | ipa_get_jf_pass_through_type_preserved (struct ipa_jump_func *jfunc) | |
260 | { | |
261 | gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH); | |
262 | return jfunc->value.pass_through.agg_preserved; | |
263 | } | |
264 | ||
265 | /* Return the offset of an ancestor jump function JFUNC. */ | |
266 | ||
267 | static inline HOST_WIDE_INT | |
268 | ipa_get_jf_ancestor_offset (struct ipa_jump_func *jfunc) | |
269 | { | |
270 | gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR); | |
271 | return jfunc->value.ancestor.offset; | |
272 | } | |
273 | ||
274 | /* Return the number of the caller's formal parameter that an ancestor jump | |
275 | function JFUNC refers to. */ | |
276 | ||
277 | static inline int | |
278 | ipa_get_jf_ancestor_formal_id (struct ipa_jump_func *jfunc) | |
279 | { | |
280 | gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR); | |
281 | return jfunc->value.ancestor.formal_id; | |
282 | } | |
283 | ||
284 | /* Return the agg_preserved flag of an ancestor jump function JFUNC. */ | |
285 | ||
286 | static inline bool | |
287 | ipa_get_jf_ancestor_agg_preserved (struct ipa_jump_func *jfunc) | |
288 | { | |
289 | gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR); | |
290 | return jfunc->value.ancestor.agg_preserved; | |
291 | } | |
292 | ||
293 | /* Return true if ancestor jump function JFUNC presrves type information. */ | |
294 | ||
295 | static inline bool | |
296 | ipa_get_jf_ancestor_type_preserved (struct ipa_jump_func *jfunc) | |
297 | { | |
298 | gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR); | |
299 | return jfunc->value.ancestor.agg_preserved; | |
300 | } | |
301 | ||
302 | /* Summary describing a single formal parameter. */ | |
303 | ||
304 | struct GTY(()) ipa_param_descriptor | |
305 | { | |
306 | /* In analysis and modification phase, this is the PARAM_DECL of this | |
307 | parameter, in IPA LTO phase, this is the type of the the described | |
308 | parameter or NULL if not known. Do not read this field directly but | |
309 | through ipa_get_param and ipa_get_type as appropriate. */ | |
310 | tree decl_or_type; | |
311 | /* If all uses of the parameter are described by ipa-prop structures, this | |
312 | says how many there are. If any use could not be described by means of | |
313 | ipa-prop structures, this is IPA_UNDESCRIBED_USE. */ | |
314 | int controlled_uses; | |
315 | unsigned int move_cost : 31; | |
316 | /* The parameter is used. */ | |
317 | unsigned used : 1; | |
318 | }; | |
319 | ||
320 | /* ipa_node_params stores information related to formal parameters of functions | |
321 | and some other information for interprocedural passes that operate on | |
322 | parameters (such as ipa-cp). */ | |
323 | ||
324 | class GTY((for_user)) ipa_node_params | |
325 | { | |
326 | public: | |
327 | /* Default constructor. */ | |
328 | ipa_node_params (); | |
329 | ||
330 | /* Default destructor. */ | |
331 | ~ipa_node_params (); | |
332 | ||
333 | /* Information about individual formal parameters that are gathered when | |
334 | summaries are generated. */ | |
335 | vec<ipa_param_descriptor, va_gc> *descriptors; | |
336 | /* Pointer to an array of structures describing individual formal | |
337 | parameters. */ | |
338 | class ipcp_param_lattices * GTY((skip)) lattices; | |
339 | /* Only for versioned nodes this field would not be NULL, | |
340 | it points to the node that IPA cp cloned from. */ | |
341 | struct cgraph_node * GTY((skip)) ipcp_orig_node; | |
342 | /* If this node is an ipa-cp clone, these are the known constants that | |
343 | describe what it has been specialized for. */ | |
344 | vec<tree> GTY((skip)) known_csts; | |
345 | /* If this node is an ipa-cp clone, these are the known polymorphic contexts | |
346 | that describe what it has been specialized for. */ | |
347 | vec<ipa_polymorphic_call_context> GTY((skip)) known_contexts; | |
348 | /* Whether the param uses analysis and jump function computation has already | |
349 | been performed. */ | |
350 | unsigned analysis_done : 1; | |
351 | /* Whether the function is enqueued in ipa-cp propagation stack. */ | |
352 | unsigned node_enqueued : 1; | |
353 | /* Whether we should create a specialized version based on values that are | |
354 | known to be constant in all contexts. */ | |
355 | unsigned do_clone_for_all_contexts : 1; | |
356 | /* Set if this is an IPA-CP clone for all contexts. */ | |
357 | unsigned is_all_contexts_clone : 1; | |
358 | /* Node has been completely replaced by clones and will be removed after | |
359 | ipa-cp is finished. */ | |
360 | unsigned node_dead : 1; | |
361 | /* Node is involved in a recursion, potentionally indirect. */ | |
362 | unsigned node_within_scc : 1; | |
363 | /* Node is calling a private function called only once. */ | |
364 | unsigned node_calling_single_call : 1; | |
365 | /* False when there is something makes versioning impossible. */ | |
366 | unsigned versionable : 1; | |
367 | }; | |
368 | ||
369 | inline | |
370 | ipa_node_params::ipa_node_params () | |
371 | : descriptors (NULL), lattices (NULL), ipcp_orig_node (NULL), | |
372 | known_csts (vNULL), known_contexts (vNULL), analysis_done (0), | |
373 | node_enqueued (0), do_clone_for_all_contexts (0), is_all_contexts_clone (0), | |
374 | node_dead (0), node_within_scc (0), node_calling_single_call (0), | |
375 | versionable (0) | |
376 | { | |
377 | } | |
378 | ||
379 | inline | |
380 | ipa_node_params::~ipa_node_params () | |
381 | { | |
382 | free (lattices); | |
383 | known_csts.release (); | |
384 | known_contexts.release (); | |
385 | } | |
386 | ||
387 | /* Intermediate information that we get from alias analysis about a particular | |
388 | parameter in a particular basic_block. When a parameter or the memory it | |
389 | references is marked modified, we use that information in all dominated | |
390 | blocks without consulting alias analysis oracle. */ | |
391 | ||
392 | struct ipa_param_aa_status | |
393 | { | |
394 | /* Set when this structure contains meaningful information. If not, the | |
395 | structure describing a dominating BB should be used instead. */ | |
396 | bool valid; | |
397 | ||
398 | /* Whether we have seen something which might have modified the data in | |
399 | question. PARM is for the parameter itself, REF is for data it points to | |
400 | but using the alias type of individual accesses and PT is the same thing | |
401 | but for computing aggregate pass-through functions using a very inclusive | |
402 | ao_ref. */ | |
403 | bool parm_modified, ref_modified, pt_modified; | |
404 | }; | |
405 | ||
406 | /* Information related to a given BB that used only when looking at function | |
407 | body. */ | |
408 | ||
409 | struct ipa_bb_info | |
410 | { | |
411 | /* Call graph edges going out of this BB. */ | |
412 | vec<cgraph_edge *> cg_edges; | |
413 | /* Alias analysis statuses of each formal parameter at this bb. */ | |
414 | vec<ipa_param_aa_status> param_aa_statuses; | |
415 | }; | |
416 | ||
417 | /* Structure with global information that is only used when looking at function | |
418 | body. */ | |
419 | ||
420 | struct ipa_func_body_info | |
421 | { | |
422 | /* The node that is being analyzed. */ | |
423 | cgraph_node *node; | |
424 | ||
425 | /* Its info. */ | |
426 | class ipa_node_params *info; | |
427 | ||
428 | /* Information about individual BBs. */ | |
429 | vec<ipa_bb_info> bb_infos; | |
430 | ||
431 | /* Number of parameters. */ | |
432 | int param_count; | |
433 | ||
434 | /* Number of statements we are still allowed to walked by when analyzing this | |
435 | function. */ | |
436 | unsigned int aa_walk_budget; | |
437 | }; | |
438 | ||
439 | /* ipa_node_params access functions. Please use these to access fields that | |
440 | are or will be shared among various passes. */ | |
441 | ||
442 | /* Return the number of formal parameters. */ | |
443 | ||
444 | static inline int | |
445 | ipa_get_param_count (class ipa_node_params *info) | |
446 | { | |
447 | return vec_safe_length (info->descriptors); | |
448 | } | |
449 | ||
450 | /* Return the declaration of Ith formal parameter of the function corresponding | |
451 | to INFO. Note there is no setter function as this array is built just once | |
452 | using ipa_initialize_node_params. This function should not be called in | |
453 | WPA. */ | |
454 | ||
455 | static inline tree | |
456 | ipa_get_param (class ipa_node_params *info, int i) | |
457 | { | |
458 | gcc_checking_assert (info->descriptors); | |
459 | gcc_checking_assert (!flag_wpa); | |
460 | tree t = (*info->descriptors)[i].decl_or_type; | |
461 | gcc_checking_assert (TREE_CODE (t) == PARM_DECL); | |
462 | return t; | |
463 | } | |
464 | ||
465 | /* Return the type of Ith formal parameter of the function corresponding | |
466 | to INFO if it is known or NULL if not. */ | |
467 | ||
468 | static inline tree | |
469 | ipa_get_type (class ipa_node_params *info, int i) | |
470 | { | |
471 | if (vec_safe_length (info->descriptors) <= (unsigned) i) | |
472 | return NULL; | |
473 | tree t = (*info->descriptors)[i].decl_or_type; | |
474 | if (!t) | |
475 | return NULL; | |
476 | if (TYPE_P (t)) | |
477 | return t; | |
478 | gcc_checking_assert (TREE_CODE (t) == PARM_DECL); | |
479 | return TREE_TYPE (t); | |
480 | } | |
481 | ||
482 | /* Return the move cost of Ith formal parameter of the function corresponding | |
483 | to INFO. */ | |
484 | ||
485 | static inline int | |
486 | ipa_get_param_move_cost (class ipa_node_params *info, int i) | |
487 | { | |
488 | gcc_checking_assert (info->descriptors); | |
489 | return (*info->descriptors)[i].move_cost; | |
490 | } | |
491 | ||
492 | /* Set the used flag corresponding to the Ith formal parameter of the function | |
493 | associated with INFO to VAL. */ | |
494 | ||
495 | static inline void | |
496 | ipa_set_param_used (class ipa_node_params *info, int i, bool val) | |
497 | { | |
498 | gcc_checking_assert (info->descriptors); | |
499 | (*info->descriptors)[i].used = val; | |
500 | } | |
501 | ||
502 | /* Return how many uses described by ipa-prop a parameter has or | |
503 | IPA_UNDESCRIBED_USE if there is a use that is not described by these | |
504 | structures. */ | |
505 | static inline int | |
506 | ipa_get_controlled_uses (class ipa_node_params *info, int i) | |
507 | { | |
508 | /* FIXME: introducing speculation causes out of bounds access here. */ | |
509 | if (vec_safe_length (info->descriptors) > (unsigned)i) | |
510 | return (*info->descriptors)[i].controlled_uses; | |
511 | return IPA_UNDESCRIBED_USE; | |
512 | } | |
513 | ||
514 | /* Set the controlled counter of a given parameter. */ | |
515 | ||
516 | static inline void | |
517 | ipa_set_controlled_uses (class ipa_node_params *info, int i, int val) | |
518 | { | |
519 | gcc_checking_assert (info->descriptors); | |
520 | (*info->descriptors)[i].controlled_uses = val; | |
521 | } | |
522 | ||
523 | /* Return the used flag corresponding to the Ith formal parameter of the | |
524 | function associated with INFO. */ | |
525 | ||
526 | static inline bool | |
527 | ipa_is_param_used (class ipa_node_params *info, int i) | |
528 | { | |
529 | gcc_checking_assert (info->descriptors); | |
530 | return (*info->descriptors)[i].used; | |
531 | } | |
532 | ||
533 | /* Information about replacements done in aggregates for a given node (each | |
534 | node has its linked list). */ | |
535 | struct GTY(()) ipa_agg_replacement_value | |
536 | { | |
537 | /* Next item in the linked list. */ | |
538 | struct ipa_agg_replacement_value *next; | |
539 | /* Offset within the aggregate. */ | |
540 | HOST_WIDE_INT offset; | |
541 | /* The constant value. */ | |
542 | tree value; | |
543 | /* The paramter index. */ | |
544 | int index; | |
545 | /* Whether the value was passed by reference. */ | |
546 | bool by_ref; | |
547 | }; | |
548 | ||
549 | /* Structure holding information for the transformation phase of IPA-CP. */ | |
550 | ||
551 | struct GTY(()) ipcp_transformation | |
552 | { | |
553 | /* Linked list of known aggregate values. */ | |
554 | ipa_agg_replacement_value *agg_values; | |
555 | /* Known bits information. */ | |
556 | vec<ipa_bits *, va_gc> *bits; | |
557 | /* Value range information. */ | |
558 | vec<ipa_vr, va_gc> *m_vr; | |
559 | }; | |
560 | ||
561 | void ipa_set_node_agg_value_chain (struct cgraph_node *node, | |
562 | struct ipa_agg_replacement_value *aggvals); | |
563 | void ipcp_transformation_initialize (void); | |
564 | ||
565 | /* ipa_edge_args stores information related to a callsite and particularly its | |
566 | arguments. It can be accessed by the IPA_EDGE_REF macro. */ | |
567 | ||
568 | class GTY((for_user)) ipa_edge_args | |
569 | { | |
570 | public: | |
571 | ||
572 | /* Default constructor. */ | |
573 | ipa_edge_args () : jump_functions (NULL), polymorphic_call_contexts (NULL) | |
574 | {} | |
575 | ||
576 | /* Destructor. */ | |
577 | ~ipa_edge_args () | |
578 | { | |
579 | vec_free (jump_functions); | |
580 | vec_free (polymorphic_call_contexts); | |
581 | } | |
582 | ||
583 | /* Vectors of the callsite's jump function and polymorphic context | |
584 | information of each parameter. */ | |
585 | vec<ipa_jump_func, va_gc> *jump_functions; | |
586 | vec<ipa_polymorphic_call_context, va_gc> *polymorphic_call_contexts; | |
587 | }; | |
588 | ||
589 | /* ipa_edge_args access functions. Please use these to access fields that | |
590 | are or will be shared among various passes. */ | |
591 | ||
592 | /* Return the number of actual arguments. */ | |
593 | ||
594 | static inline int | |
595 | ipa_get_cs_argument_count (class ipa_edge_args *args) | |
596 | { | |
597 | return vec_safe_length (args->jump_functions); | |
598 | } | |
599 | ||
600 | /* Returns a pointer to the jump function for the ith argument. Please note | |
601 | there is no setter function as jump functions are all set up in | |
602 | ipa_compute_jump_functions. */ | |
603 | ||
604 | static inline struct ipa_jump_func * | |
605 | ipa_get_ith_jump_func (class ipa_edge_args *args, int i) | |
606 | { | |
607 | return &(*args->jump_functions)[i]; | |
608 | } | |
609 | ||
610 | /* Returns a pointer to the polymorphic call context for the ith argument. | |
611 | NULL if contexts are not computed. */ | |
612 | static inline class ipa_polymorphic_call_context * | |
613 | ipa_get_ith_polymorhic_call_context (class ipa_edge_args *args, int i) | |
614 | { | |
615 | if (!args->polymorphic_call_contexts) | |
616 | return NULL; | |
617 | return &(*args->polymorphic_call_contexts)[i]; | |
618 | } | |
619 | ||
620 | /* Function summary for ipa_node_params. */ | |
621 | class GTY((user)) ipa_node_params_t: public function_summary <ipa_node_params *> | |
622 | { | |
623 | public: | |
624 | ipa_node_params_t (symbol_table *table, bool ggc): | |
625 | function_summary<ipa_node_params *> (table, ggc) { } | |
626 | ||
627 | /* Hook that is called by summary when a node is duplicated. */ | |
628 | virtual void duplicate (cgraph_node *node, | |
629 | cgraph_node *node2, | |
630 | ipa_node_params *data, | |
631 | ipa_node_params *data2); | |
632 | }; | |
633 | ||
634 | /* Summary to manange ipa_edge_args structures. */ | |
635 | ||
636 | class GTY((user)) ipa_edge_args_sum_t : public call_summary <ipa_edge_args *> | |
637 | { | |
638 | public: | |
639 | ipa_edge_args_sum_t (symbol_table *table, bool ggc) | |
640 | : call_summary<ipa_edge_args *> (table, ggc) { } | |
641 | ||
642 | /* Hook that is called by summary when an edge is duplicated. */ | |
643 | virtual void remove (cgraph_edge *cs, ipa_edge_args *args); | |
644 | /* Hook that is called by summary when an edge is duplicated. */ | |
645 | virtual void duplicate (cgraph_edge *src, | |
646 | cgraph_edge *dst, | |
647 | ipa_edge_args *old_args, | |
648 | ipa_edge_args *new_args); | |
649 | }; | |
650 | ||
651 | /* Function summary where the parameter infos are actually stored. */ | |
652 | extern GTY(()) ipa_node_params_t * ipa_node_params_sum; | |
653 | /* Call summary to store information about edges such as jump functions. */ | |
654 | extern GTY(()) ipa_edge_args_sum_t *ipa_edge_args_sum; | |
655 | ||
656 | /* Function summary for IPA-CP transformation. */ | |
657 | class ipcp_transformation_t | |
658 | : public function_summary<ipcp_transformation *> | |
659 | { | |
660 | public: | |
661 | ipcp_transformation_t (symbol_table *table, bool ggc): | |
662 | function_summary<ipcp_transformation *> (table, ggc) {} | |
663 | ||
664 | ~ipcp_transformation_t () {} | |
665 | ||
666 | static ipcp_transformation_t *create_ggc (symbol_table *symtab) | |
667 | { | |
668 | ipcp_transformation_t *summary | |
669 | = new (ggc_cleared_alloc <ipcp_transformation_t> ()) | |
670 | ipcp_transformation_t (symtab, true); | |
671 | return summary; | |
672 | } | |
673 | }; | |
674 | ||
675 | /* Function summary where the IPA CP transformations are actually stored. */ | |
676 | extern GTY(()) function_summary <ipcp_transformation *> *ipcp_transformation_sum; | |
677 | ||
678 | /* Return the associated parameter/argument info corresponding to the given | |
679 | node/edge. */ | |
680 | #define IPA_NODE_REF(NODE) (ipa_node_params_sum->get_create (NODE)) | |
681 | #define IPA_EDGE_REF(EDGE) (ipa_edge_args_sum->get_create (EDGE)) | |
682 | /* This macro checks validity of index returned by | |
683 | ipa_get_param_decl_index function. */ | |
684 | #define IS_VALID_JUMP_FUNC_INDEX(I) ((I) != -1) | |
685 | ||
686 | /* Creating and freeing ipa_node_params and ipa_edge_args. */ | |
687 | void ipa_create_all_node_params (void); | |
688 | void ipa_create_all_edge_args (void); | |
689 | void ipa_check_create_edge_args (void); | |
690 | void ipa_free_all_node_params (void); | |
691 | void ipa_free_all_edge_args (void); | |
692 | void ipa_free_all_structures_after_ipa_cp (void); | |
693 | void ipa_free_all_structures_after_iinln (void); | |
694 | ||
695 | void ipa_register_cgraph_hooks (void); | |
696 | int count_formal_params (tree fndecl); | |
697 | ||
698 | /* This function ensures the array of node param infos is big enough to | |
699 | accommodate a structure for all nodes and reallocates it if not. */ | |
700 | ||
701 | static inline void | |
702 | ipa_check_create_node_params (void) | |
703 | { | |
704 | if (!ipa_node_params_sum) | |
705 | ipa_node_params_sum | |
706 | = (new (ggc_cleared_alloc <ipa_node_params_t> ()) | |
707 | ipa_node_params_t (symtab, true)); | |
708 | } | |
709 | ||
710 | /* Returns true if edge summary contains a record for EDGE. The main purpose | |
711 | of this function is that debug dumping function can check info availability | |
712 | without causing allocations. */ | |
713 | ||
714 | static inline bool | |
715 | ipa_edge_args_info_available_for_edge_p (struct cgraph_edge *edge) | |
716 | { | |
717 | return ipa_edge_args_sum->exists (edge); | |
718 | } | |
719 | ||
720 | static inline ipcp_transformation * | |
721 | ipcp_get_transformation_summary (cgraph_node *node) | |
722 | { | |
723 | if (ipcp_transformation_sum == NULL) | |
724 | return NULL; | |
725 | ||
726 | return ipcp_transformation_sum->get (node); | |
727 | } | |
728 | ||
729 | /* Return the aggregate replacements for NODE, if there are any. */ | |
730 | ||
731 | static inline struct ipa_agg_replacement_value * | |
732 | ipa_get_agg_replacements_for_node (cgraph_node *node) | |
733 | { | |
734 | ipcp_transformation *ts = ipcp_get_transformation_summary (node); | |
735 | return ts ? ts->agg_values : NULL; | |
736 | } | |
737 | ||
738 | /* Function formal parameters related computations. */ | |
739 | void ipa_initialize_node_params (struct cgraph_node *node); | |
740 | bool ipa_propagate_indirect_call_infos (struct cgraph_edge *cs, | |
741 | vec<cgraph_edge *> *new_edges); | |
742 | ||
743 | /* Indirect edge and binfo processing. */ | |
744 | tree ipa_get_indirect_edge_target (struct cgraph_edge *ie, | |
745 | vec<tree> , | |
746 | vec<ipa_polymorphic_call_context>, | |
747 | vec<ipa_agg_jump_function_p>, | |
748 | bool *); | |
749 | struct cgraph_edge *ipa_make_edge_direct_to_target (struct cgraph_edge *, tree, | |
750 | bool speculative = false); | |
751 | tree ipa_impossible_devirt_target (struct cgraph_edge *, tree); | |
752 | ipa_bits *ipa_get_ipa_bits_for_value (const widest_int &value, | |
753 | const widest_int &mask); | |
754 | ||
755 | ||
756 | /* Functions related to both. */ | |
757 | void ipa_analyze_node (struct cgraph_node *); | |
758 | ||
759 | /* Aggregate jump function related functions. */ | |
760 | tree ipa_find_agg_cst_for_param (struct ipa_agg_jump_function *agg, tree scalar, | |
761 | HOST_WIDE_INT offset, bool by_ref, | |
762 | bool *from_global_constant = NULL); | |
763 | bool ipa_load_from_parm_agg (struct ipa_func_body_info *fbi, | |
764 | vec<ipa_param_descriptor, va_gc> *descriptors, | |
765 | gimple *stmt, tree op, int *index_p, | |
766 | HOST_WIDE_INT *offset_p, poly_int64 *size_p, | |
767 | bool *by_ref, bool *guaranteed_unmodified = NULL); | |
768 | ||
769 | /* Debugging interface. */ | |
770 | void ipa_print_node_params (FILE *, struct cgraph_node *node); | |
771 | void ipa_print_all_params (FILE *); | |
772 | void ipa_print_node_jump_functions (FILE *f, struct cgraph_node *node); | |
773 | void ipa_print_all_jump_functions (FILE * f); | |
774 | void ipcp_verify_propagated_values (void); | |
775 | ||
776 | template <typename value> | |
777 | class ipcp_value; | |
778 | ||
779 | extern object_allocator<ipcp_value<tree> > ipcp_cst_values_pool; | |
780 | extern object_allocator<ipcp_value<ipa_polymorphic_call_context> > | |
781 | ipcp_poly_ctx_values_pool; | |
782 | ||
783 | template <typename valtype> | |
784 | struct ipcp_value_source; | |
785 | ||
786 | extern object_allocator<ipcp_value_source<tree> > ipcp_sources_pool; | |
787 | ||
788 | struct ipcp_agg_lattice; | |
789 | ||
790 | extern object_allocator<ipcp_agg_lattice> ipcp_agg_lattice_pool; | |
791 | ||
792 | void ipa_dump_agg_replacement_values (FILE *f, | |
793 | struct ipa_agg_replacement_value *av); | |
794 | void ipa_prop_write_jump_functions (void); | |
795 | void ipa_prop_read_jump_functions (void); | |
796 | void ipcp_write_transformation_summaries (void); | |
797 | void ipcp_read_transformation_summaries (void); | |
798 | int ipa_get_param_decl_index (class ipa_node_params *, tree); | |
799 | tree ipa_value_from_jfunc (class ipa_node_params *info, | |
800 | struct ipa_jump_func *jfunc, tree type); | |
801 | unsigned int ipcp_transform_function (struct cgraph_node *node); | |
802 | ipa_polymorphic_call_context ipa_context_from_jfunc (ipa_node_params *, | |
803 | cgraph_edge *, | |
804 | int, | |
805 | ipa_jump_func *); | |
806 | void ipa_dump_param (FILE *, class ipa_node_params *info, int i); | |
807 | void ipa_release_body_info (struct ipa_func_body_info *); | |
808 | tree ipa_get_callee_param_type (struct cgraph_edge *e, int i); | |
809 | ||
810 | /* From tree-sra.c: */ | |
811 | tree build_ref_for_offset (location_t, tree, poly_int64, bool, tree, | |
812 | gimple_stmt_iterator *, bool); | |
813 | ||
814 | /* In ipa-cp.c */ | |
815 | void ipa_cp_c_finalize (void); | |
816 | ||
817 | #endif /* IPA_PROP_H */ |