source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/hardware/tools/avr/lib/gcc/avr/4.8.1/plugin/include/ipa-prop.h @ 46

Last change on this file since 46 was 46, checked in by jrpelegrina, 4 years ago

First release to Xenial

File size: 22.1 KB
Line 
1/* Interprocedural analyses.
2   Copyright (C) 2005-2013 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along 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#include "tree.h"
24#include "vec.h"
25#include "cgraph.h"
26#include "gimple.h"
27#include "alloc-pool.h"
28
29/* The following definitions and interfaces are used by
30   interprocedural analyses or parameters.  */
31
32/* ipa-prop.c stuff (ipa-cp, indirect inlining):  */
33
34/* A jump function for a callsite represents the values passed as actual
35   arguments of the callsite.  They were originally proposed in a paper called
36   "Interprocedural Constant Propagation", by David Callahan, Keith D Cooper,
37   Ken Kennedy, Linda Torczon in Comp86, pg 152-161.  There are three main
38   types of values :
39
40   Pass-through - the caller's formal parameter is passed as an actual
41                  argument, possibly one simple operation performed on it.
42   Constant     - a constant (is_gimple_ip_invariant)is passed as an actual
43                  argument.
44   Unknown      - neither of the above.
45
46   IPA_JF_ANCESTOR is a special pass-through jump function, which means that
47   the result is an address of a part of the object pointed to by the formal
48   parameter to which the function refers.  It is mainly intended to represent
49   getting addresses of of ancestor fields in C++
50   (e.g. &this_1(D)->D.1766.D.1756).  Note that if the original pointer is
51   NULL, ancestor jump function must behave like a simple pass-through.
52
53   Other pass-through functions can either simply pass on an unchanged formal
54   parameter or can apply one simple binary operation to it (such jump
55   functions are called polynomial).
56
57   IPA_JF_KNOWN_TYPE is a special type of an "unknown" function that applies
58   only to pointer parameters.  It means that even though we cannot prove that
59   the passed value is an interprocedural constant, we still know the exact
60   type of the containing object which may be valuable for devirtualization.
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
67enum jump_func_type
68{
69  IPA_JF_UNKNOWN = 0,  /* newly allocated and zeroed jump functions default */
70  IPA_JF_KNOWN_TYPE,        /* represented by field known_type */
71  IPA_JF_CONST,             /* represented by field costant */
72  IPA_JF_PASS_THROUGH,      /* represented by field pass_through */
73  IPA_JF_ANCESTOR           /* represented by field ancestor */
74};
75
76/* Structure holding data required to describe a known type jump function.  */
77struct GTY(()) ipa_known_type_data
78{
79  /* Offset of the component of the base_type being described.  */
80  HOST_WIDE_INT offset;
81  /* Type of the whole object.  */
82  tree base_type;
83  /* Type of the component of the object that is being described.  */
84  tree component_type;
85};
86
87/* Structure holding data required to describe a pass-through jump function.  */
88
89struct 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  bool agg_preserved;
108};
109
110/* Structure holding data required to describe an ancestor pass-through
111   jump function.  */
112
113struct GTY(()) ipa_ancestor_jf_data
114{
115  /* Offset of the field representing the ancestor.  */
116  HOST_WIDE_INT offset;
117  /* Type of the result.  */
118  tree type;
119  /* Number of the caller's formal parameter being passed.  */
120  int formal_id;
121  /* Flag with the same meaning like agg_preserve in ipa_pass_through_data.  */
122  bool agg_preserved;
123};
124
125/* An element in an aggegate part of a jump function describing a known value
126   at a given offset.  When it is part of a pass-through jump function with
127   agg_preserved set or an ancestor jump function with agg_preserved set, all
128   unlisted positions are assumed to be preserved but the value can be a type
129   node, which means that the particular piece (starting at offset and having
130   the size of the type) is clobbered with an unknown value.  When
131   agg_preserved is false or the type of the containing jump function is
132   different, all unlisted parts are assumed to be unknown and all values must
133   fullfill is_gimple_ip_invariant.  */
134
135typedef struct GTY(()) ipa_agg_jf_item
136{
137  /* The offset at which the known value is located within the aggregate.  */
138  HOST_WIDE_INT offset;
139
140  /* The known constant or type if this is a clobber.  */
141  tree value;
142} ipa_agg_jf_item_t;
143
144
145/* Aggregate jump function - i.e. description of contents of aggregates passed
146   either by reference or value.  */
147
148struct GTY(()) ipa_agg_jump_function
149{
150  /* Description of the individual items.  */
151  vec<ipa_agg_jf_item_t, va_gc> *items;
152  /* True if the data was passed by reference (as opposed to by value). */
153  bool by_ref;
154};
155
156typedef struct ipa_agg_jump_function *ipa_agg_jump_function_p;
157typedef struct ipa_agg_jump_function ipa_agg_jump_function_t;
158
159/* A jump function for a callsite represents the values passed as actual
160   arguments of the callsite. See enum jump_func_type for the various
161   types of jump functions supported.  */
162typedef struct GTY (()) ipa_jump_func
163{
164  /* Aggregate contants description.  See struct ipa_agg_jump_function and its
165     description.  */
166  struct ipa_agg_jump_function agg;
167
168  enum jump_func_type type;
169  /* Represents a value of a jump function.  pass_through is used only in jump
170     function context.  constant represents the actual constant in constant jump
171     functions and member_cst holds constant c++ member functions.  */
172  union jump_func_value
173  {
174    struct ipa_known_type_data GTY ((tag ("IPA_JF_KNOWN_TYPE"))) known_type;
175    tree GTY ((tag ("IPA_JF_CONST"))) constant;
176    struct ipa_pass_through_data GTY ((tag ("IPA_JF_PASS_THROUGH"))) pass_through;
177    struct ipa_ancestor_jf_data GTY ((tag ("IPA_JF_ANCESTOR"))) ancestor;
178  } GTY ((desc ("%1.type"))) value;
179} ipa_jump_func_t;
180
181
182/* Return the offset of the component that is decribed by a known type jump
183   function JFUNC.  */
184
185static inline HOST_WIDE_INT
186ipa_get_jf_known_type_offset (struct ipa_jump_func *jfunc)
187{
188  gcc_checking_assert (jfunc->type == IPA_JF_KNOWN_TYPE);
189  return jfunc->value.known_type.offset;
190}
191
192/* Return the base type of a known type jump function JFUNC.  */
193
194static inline tree
195ipa_get_jf_known_type_base_type (struct ipa_jump_func *jfunc)
196{
197  gcc_checking_assert (jfunc->type == IPA_JF_KNOWN_TYPE);
198  return jfunc->value.known_type.base_type;
199}
200
201/* Return the component type of a known type jump function JFUNC.  */
202
203static inline tree
204ipa_get_jf_known_type_component_type (struct ipa_jump_func *jfunc)
205{
206  gcc_checking_assert (jfunc->type == IPA_JF_KNOWN_TYPE);
207  return jfunc->value.known_type.component_type;
208}
209
210/* Return the constant stored in a constant jump functin JFUNC.  */
211
212static inline tree
213ipa_get_jf_constant (struct ipa_jump_func *jfunc)
214{
215  gcc_checking_assert (jfunc->type == IPA_JF_CONST);
216  return jfunc->value.constant;
217}
218
219/* Return the operand of a pass through jmp function JFUNC.  */
220
221static inline tree
222ipa_get_jf_pass_through_operand (struct ipa_jump_func *jfunc)
223{
224  gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
225  return jfunc->value.pass_through.operand;
226}
227
228/* Return the number of the caller's formal parameter that a pass through jump
229   function JFUNC refers to.  */
230
231static inline int
232ipa_get_jf_pass_through_formal_id (struct ipa_jump_func *jfunc)
233{
234  gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
235  return jfunc->value.pass_through.formal_id;
236}
237
238/* Return operation of a pass through jump function JFUNC.  */
239
240static inline enum tree_code
241ipa_get_jf_pass_through_operation (struct ipa_jump_func *jfunc)
242{
243  gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
244  return jfunc->value.pass_through.operation;
245}
246
247/* Return the agg_preserved flag of a pass through jump functin JFUNC.  */
248
249static inline bool
250ipa_get_jf_pass_through_agg_preserved (struct ipa_jump_func *jfunc)
251{
252  gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
253  return jfunc->value.pass_through.agg_preserved;
254}
255
256/* Return the offset of an ancestor jump function JFUNC.  */
257
258static inline HOST_WIDE_INT
259ipa_get_jf_ancestor_offset (struct ipa_jump_func *jfunc)
260{
261  gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
262  return jfunc->value.ancestor.offset;
263}
264
265/* Return the result type of an ancestor jump function JFUNC.  */
266
267static inline tree
268ipa_get_jf_ancestor_type (struct ipa_jump_func *jfunc)
269{
270  gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
271  return jfunc->value.ancestor.type;
272}
273
274/* Return the number of the caller's formal parameter that an ancestor jump
275   function JFUNC refers to.  */
276
277static inline int
278ipa_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 functin JFUNC.  */
285
286static inline bool
287ipa_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/* Summary describing a single formal parameter.  */
294
295struct ipa_param_descriptor
296{
297  /* PARAM_DECL of this parameter.  */
298  tree decl;
299  /* The parameter is used.  */
300  unsigned used : 1;
301};
302
303typedef struct ipa_param_descriptor ipa_param_descriptor_t;
304struct ipcp_lattice;
305
306/* ipa_node_params stores information related to formal parameters of functions
307   and some other information for interprocedural passes that operate on
308   parameters (such as ipa-cp).  */
309
310struct ipa_node_params
311{
312  /* Information about individual formal parameters that are gathered when
313     summaries are generated. */
314  vec<ipa_param_descriptor_t> descriptors;
315  /* Pointer to an array of structures describing individual formal
316     parameters.  */
317  struct ipcp_param_lattices *lattices;
318  /* Only for versioned nodes this field would not be NULL,
319     it points to the node that IPA cp cloned from.  */
320  struct cgraph_node *ipcp_orig_node;
321  /* If this node is an ipa-cp clone, these are the known values that describe
322     what it has been specialized for.  */
323  vec<tree> known_vals;
324  /* Whether the param uses analysis has already been performed.  */
325  unsigned uses_analysis_done : 1;
326  /* Whether the function is enqueued in ipa-cp propagation stack.  */
327  unsigned node_enqueued : 1;
328  /* Whether we should create a specialized version based on values that are
329     known to be constant in all contexts.  */
330  unsigned do_clone_for_all_contexts : 1;
331  /* Set if this is an IPA-CP clone for all contexts.  */
332  unsigned is_all_contexts_clone : 1;
333  /* Node has been completely replaced by clones and will be removed after
334     ipa-cp is finished.  */
335  unsigned node_dead : 1;
336};
337
338/* ipa_node_params access functions.  Please use these to access fields that
339   are or will be shared among various passes.  */
340
341/* Return the number of formal parameters. */
342
343static inline int
344ipa_get_param_count (struct ipa_node_params *info)
345{
346  return info->descriptors.length ();
347}
348
349/* Return the declaration of Ith formal parameter of the function corresponding
350   to INFO.  Note there is no setter function as this array is built just once
351   using ipa_initialize_node_params. */
352
353static inline tree
354ipa_get_param (struct ipa_node_params *info, int i)
355{
356  return info->descriptors[i].decl;
357}
358
359/* Set the used flag corresponding to the Ith formal parameter of the function
360   associated with INFO to VAL.  */
361
362static inline void
363ipa_set_param_used (struct ipa_node_params *info, int i, bool val)
364{
365  info->descriptors[i].used = val;
366}
367
368/* Return the used flag corresponding to the Ith formal parameter of the
369   function associated with INFO.  */
370
371static inline bool
372ipa_is_param_used (struct ipa_node_params *info, int i)
373{
374  return info->descriptors[i].used;
375}
376
377/* Information about replacements done in aggregates for a given node (each
378   node has its linked list).  */
379struct GTY(()) ipa_agg_replacement_value
380{
381  /* Next item in the linked list.  */
382  struct ipa_agg_replacement_value *next;
383  /* Offset within the aggregate.  */
384  HOST_WIDE_INT offset;
385  /* The constant value.  */
386  tree value;
387  /* The paramter index.  */
388  int index;
389  /* Whether the value was passed by reference.  */
390  bool by_ref;
391};
392
393typedef struct ipa_agg_replacement_value *ipa_agg_replacement_value_p;
394
395void ipa_set_node_agg_value_chain (struct cgraph_node *node,
396                                   struct ipa_agg_replacement_value *aggvals);
397
398/* ipa_edge_args stores information related to a callsite and particularly its
399   arguments.  It can be accessed by the IPA_EDGE_REF macro.  */
400typedef struct GTY(()) ipa_edge_args
401{
402  /* Vector of the callsite's jump function of each parameter.  */
403  vec<ipa_jump_func_t, va_gc> *jump_functions;
404} ipa_edge_args_t;
405
406/* ipa_edge_args access functions.  Please use these to access fields that
407   are or will be shared among various passes.  */
408
409/* Return the number of actual arguments. */
410
411static inline int
412ipa_get_cs_argument_count (struct ipa_edge_args *args)
413{
414  return vec_safe_length (args->jump_functions);
415}
416
417/* Returns a pointer to the jump function for the ith argument.  Please note
418   there is no setter function as jump functions are all set up in
419   ipa_compute_jump_functions. */
420
421static inline struct ipa_jump_func *
422ipa_get_ith_jump_func (struct ipa_edge_args *args, int i)
423{
424  return &(*args->jump_functions)[i];
425}
426
427/* Vectors need to have typedefs of structures.  */
428typedef struct ipa_node_params ipa_node_params_t;
429
430/* Types of vectors holding the infos.  */
431
432/* Vector where the parameter infos are actually stored. */
433extern vec<ipa_node_params_t> ipa_node_params_vector;
434/* Vector of known aggregate values in cloned nodes.  */
435extern GTY(()) vec<ipa_agg_replacement_value_p, va_gc> *ipa_node_agg_replacements;
436/* Vector where the parameter infos are actually stored. */
437extern GTY(()) vec<ipa_edge_args_t, va_gc> *ipa_edge_args_vector;
438
439/* Return the associated parameter/argument info corresponding to the given
440   node/edge.  */
441#define IPA_NODE_REF(NODE) (&ipa_node_params_vector[(NODE)->uid])
442#define IPA_EDGE_REF(EDGE) (&(*ipa_edge_args_vector)[(EDGE)->uid])
443/* This macro checks validity of index returned by
444   ipa_get_param_decl_index function.  */
445#define IS_VALID_JUMP_FUNC_INDEX(I) ((I) != -1)
446
447/* Creating and freeing ipa_node_params and ipa_edge_args.  */
448void ipa_create_all_node_params (void);
449void ipa_create_all_edge_args (void);
450void ipa_free_edge_args_substructures (struct ipa_edge_args *);
451void ipa_free_node_params_substructures (struct ipa_node_params *);
452void ipa_free_all_node_params (void);
453void ipa_free_all_edge_args (void);
454void ipa_free_all_structures_after_ipa_cp (void);
455void ipa_free_all_structures_after_iinln (void);
456void ipa_register_cgraph_hooks (void);
457
458/* This function ensures the array of node param infos is big enough to
459   accommodate a structure for all nodes and reallocates it if not.  */
460
461static inline void
462ipa_check_create_node_params (void)
463{
464  if (!ipa_node_params_vector.exists ())
465    ipa_node_params_vector.create (cgraph_max_uid);
466
467  if (ipa_node_params_vector.length () <= (unsigned) cgraph_max_uid)
468    ipa_node_params_vector.safe_grow_cleared (cgraph_max_uid + 1);
469}
470
471/* This function ensures the array of edge arguments infos is big enough to
472   accommodate a structure for all edges and reallocates it if not.  */
473
474static inline void
475ipa_check_create_edge_args (void)
476{
477  if (vec_safe_length (ipa_edge_args_vector) <= (unsigned) cgraph_edge_max_uid)
478    vec_safe_grow_cleared (ipa_edge_args_vector, cgraph_edge_max_uid + 1);
479}
480
481/* Returns true if the array of edge infos is large enough to accommodate an
482   info for EDGE.  The main purpose of this function is that debug dumping
483   function can check info availability without causing reallocations.  */
484
485static inline bool
486ipa_edge_args_info_available_for_edge_p (struct cgraph_edge *edge)
487{
488  return ((unsigned) edge->uid < vec_safe_length (ipa_edge_args_vector));
489}
490
491/* Return the aggregate replacements for NODE, if there are any.  */
492
493static inline struct ipa_agg_replacement_value *
494ipa_get_agg_replacements_for_node (struct cgraph_node *node)
495{
496  if ((unsigned) node->uid >= vec_safe_length (ipa_node_agg_replacements))
497    return NULL;
498  return (*ipa_node_agg_replacements)[node->uid];
499}
500
501/* Function formal parameters related computations.  */
502void ipa_initialize_node_params (struct cgraph_node *node);
503bool ipa_propagate_indirect_call_infos (struct cgraph_edge *cs,
504                                        vec<cgraph_edge_p> *new_edges);
505
506/* Indirect edge and binfo processing.  */
507tree ipa_get_indirect_edge_target (struct cgraph_edge *ie,
508                                   vec<tree> ,
509                                   vec<tree> ,
510                                   vec<ipa_agg_jump_function_p> );
511struct cgraph_edge *ipa_make_edge_direct_to_target (struct cgraph_edge *, tree);
512
513/* Functions related to both.  */
514void ipa_analyze_node (struct cgraph_node *);
515
516/* Aggregate jump function related functions.  */
517tree ipa_find_agg_cst_for_param (struct ipa_agg_jump_function *, HOST_WIDE_INT,
518                                 bool);
519bool ipa_load_from_parm_agg (struct ipa_node_params *, gimple, tree, int *,
520                             HOST_WIDE_INT *, bool *);
521
522/* Debugging interface.  */
523void ipa_print_node_params (FILE *, struct cgraph_node *node);
524void ipa_print_all_params (FILE *);
525void ipa_print_node_jump_functions (FILE *f, struct cgraph_node *node);
526void ipa_print_all_jump_functions (FILE * f);
527void ipcp_verify_propagated_values (void);
528
529extern alloc_pool ipcp_values_pool;
530extern alloc_pool ipcp_sources_pool;
531extern alloc_pool ipcp_agg_lattice_pool;
532
533/* Structure to describe transformations of formal parameters and actual
534   arguments.  Each instance describes one new parameter and they are meant to
535   be stored in a vector.  Additionally, most users will probably want to store
536   adjustments about parameters that are being removed altogether so that SSA
537   names belonging to them can be replaced by SSA names of an artificial
538   variable.  */
539struct ipa_parm_adjustment
540{
541  /* The original PARM_DECL itself, helpful for processing of the body of the
542     function itself.  Intended for traversing function bodies.
543     ipa_modify_formal_parameters, ipa_modify_call_arguments and
544     ipa_combine_adjustments ignore this and use base_index.
545     ipa_modify_formal_parameters actually sets this.  */
546  tree base;
547
548  /* Type of the new parameter.  However, if by_ref is true, the real type will
549     be a pointer to this type.  */
550  tree type;
551
552  /* Alias refrerence type to be used in MEM_REFs when adjusting caller
553     arguments.  */
554  tree alias_ptr_type;
555
556  /* The new declaration when creating/replacing a parameter.  Created by
557     ipa_modify_formal_parameters, useful for functions modifying the body
558     accordingly. */
559  tree reduction;
560
561  /* New declaration of a substitute variable that we may use to replace all
562     non-default-def ssa names when a parm decl is going away.  */
563  tree new_ssa_base;
564
565  /* If non-NULL and the original parameter is to be removed (copy_param below
566     is NULL), this is going to be its nonlocalized vars value.  */
567  tree nonlocal_value;
568
569  /* Offset into the original parameter (for the cases when the new parameter
570     is a component of an original one).  */
571  HOST_WIDE_INT offset;
572
573  /* Zero based index of the original parameter this one is based on.  (ATM
574     there is no way to insert a new parameter out of the blue because there is
575     no need but if it arises the code can be easily exteded to do so.)  */
576  int base_index;
577
578  /* This new parameter is an unmodified parameter at index base_index. */
579  unsigned copy_param : 1;
580
581  /* This adjustment describes a parameter that is about to be removed
582     completely.  Most users will probably need to book keep those so that they
583     don't leave behinfd any non default def ssa names belonging to them.  */
584  unsigned remove_param : 1;
585
586  /* The parameter is to be passed by reference.  */
587  unsigned by_ref : 1;
588};
589
590typedef struct ipa_parm_adjustment ipa_parm_adjustment_t;
591
592typedef vec<ipa_parm_adjustment_t> ipa_parm_adjustment_vec;
593
594vec<tree> ipa_get_vector_of_formal_parms (tree fndecl);
595void ipa_modify_formal_parameters (tree fndecl, ipa_parm_adjustment_vec,
596                                   const char *);
597void ipa_modify_call_arguments (struct cgraph_edge *, gimple,
598                                ipa_parm_adjustment_vec);
599ipa_parm_adjustment_vec ipa_combine_adjustments (ipa_parm_adjustment_vec,
600                                                 ipa_parm_adjustment_vec);
601void ipa_dump_param_adjustments (FILE *, ipa_parm_adjustment_vec, tree);
602void ipa_dump_agg_replacement_values (FILE *f,
603                                      struct ipa_agg_replacement_value *av);
604void ipa_prop_write_jump_functions (void);
605void ipa_prop_read_jump_functions (void);
606void ipa_prop_write_all_agg_replacement (void);
607void ipa_prop_read_all_agg_replacement (void);
608void ipa_update_after_lto_read (void);
609int ipa_get_param_decl_index (struct ipa_node_params *, tree);
610tree ipa_value_from_jfunc (struct ipa_node_params *info,
611                           struct ipa_jump_func *jfunc);
612unsigned int ipcp_transform_function (struct cgraph_node *node);
613
614
615/* From tree-sra.c:  */
616tree build_ref_for_offset (location_t, tree, HOST_WIDE_INT, tree,
617                           gimple_stmt_iterator *, bool);
618
619#endif /* IPA_PROP_H */
Note: See TracBrowser for help on using the repository browser.