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