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