Home | History | Annotate | Line # | Download | only in gcc
ipa-fnsummary.h revision 1.1
      1  1.1  mrg /* IPA function body analysis.
      2  1.1  mrg    Copyright (C) 2003-2018 Free Software Foundation, Inc.
      3  1.1  mrg    Contributed by Jan Hubicka
      4  1.1  mrg 
      5  1.1  mrg This file is part of GCC.
      6  1.1  mrg 
      7  1.1  mrg GCC is free software; you can redistribute it and/or modify it under
      8  1.1  mrg the terms of the GNU General Public License as published by the Free
      9  1.1  mrg Software Foundation; either version 3, or (at your option) any later
     10  1.1  mrg version.
     11  1.1  mrg 
     12  1.1  mrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
     13  1.1  mrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
     14  1.1  mrg FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     15  1.1  mrg for more details.
     16  1.1  mrg 
     17  1.1  mrg You should have received a copy of the GNU General Public License
     18  1.1  mrg along with GCC; see the file COPYING3.  If not see
     19  1.1  mrg <http://www.gnu.org/licenses/>.  */
     20  1.1  mrg 
     21  1.1  mrg #ifndef GCC_IPA_SUMMARY_H
     22  1.1  mrg #define GCC_IPA_SUMMARY_H
     23  1.1  mrg 
     24  1.1  mrg #include "sreal.h"
     25  1.1  mrg #include "ipa-predicate.h"
     26  1.1  mrg 
     27  1.1  mrg 
     28  1.1  mrg /* Hints are reasons why IPA heuristics should preffer specializing given
     29  1.1  mrg    function.  They are represtented as bitmap of the following values.  */
     30  1.1  mrg enum ipa_hints_vals {
     31  1.1  mrg   /* When specialization turns indirect call into a direct call,
     32  1.1  mrg      it is good idea to do so.  */
     33  1.1  mrg   INLINE_HINT_indirect_call = 1,
     34  1.1  mrg   /* Inlining may make loop iterations or loop stride known.  It is good idea
     35  1.1  mrg      to do so because it enables loop optimizatoins.  */
     36  1.1  mrg   INLINE_HINT_loop_iterations = 2,
     37  1.1  mrg   INLINE_HINT_loop_stride = 4,
     38  1.1  mrg   /* Inlining within same strongly connected component of callgraph is often
     39  1.1  mrg      a loss due to increased stack frame usage and prologue setup costs.  */
     40  1.1  mrg   INLINE_HINT_same_scc = 8,
     41  1.1  mrg   /* Inlining functions in strongly connected component is not such a great
     42  1.1  mrg      win.  */
     43  1.1  mrg   INLINE_HINT_in_scc = 16,
     44  1.1  mrg   /* If function is declared inline by user, it may be good idea to inline
     45  1.1  mrg      it.  Set by simple_edge_hints in ipa-inline-analysis.c.  */
     46  1.1  mrg   INLINE_HINT_declared_inline = 32,
     47  1.1  mrg   /* Programs are usually still organized for non-LTO compilation and thus
     48  1.1  mrg      if functions are in different modules, inlining may not be so important.
     49  1.1  mrg      Set by simple_edge_hints in ipa-inline-analysis.c.   */
     50  1.1  mrg   INLINE_HINT_cross_module = 64,
     51  1.1  mrg   /* If array indexes of loads/stores become known there may be room for
     52  1.1  mrg      further optimization.  */
     53  1.1  mrg   INLINE_HINT_array_index = 128,
     54  1.1  mrg   /* We know that the callee is hot by profile.  */
     55  1.1  mrg   INLINE_HINT_known_hot = 256
     56  1.1  mrg };
     57  1.1  mrg 
     58  1.1  mrg typedef int ipa_hints;
     59  1.1  mrg 
     60  1.1  mrg /* Simple description of whether a memory load or a condition refers to a load
     61  1.1  mrg    from an aggregate and if so, how and where from in the aggregate.
     62  1.1  mrg    Individual fields have the same meaning like fields with the same name in
     63  1.1  mrg    struct condition.  */
     64  1.1  mrg 
     65  1.1  mrg struct agg_position_info
     66  1.1  mrg {
     67  1.1  mrg   HOST_WIDE_INT offset;
     68  1.1  mrg   bool agg_contents;
     69  1.1  mrg   bool by_ref;
     70  1.1  mrg };
     71  1.1  mrg 
     72  1.1  mrg /* Representation of function body size and time depending on the call
     73  1.1  mrg    context.  We keep simple array of record, every containing of predicate
     74  1.1  mrg    and time/size to account.  */
     75  1.1  mrg struct GTY(()) size_time_entry
     76  1.1  mrg {
     77  1.1  mrg   /* Predicate for code to be executed.  */
     78  1.1  mrg   predicate exec_predicate;
     79  1.1  mrg   /* Predicate for value to be constant and optimized out in a specialized copy.
     80  1.1  mrg      When deciding on specialization this makes it possible to see how much
     81  1.1  mrg      the executed code paths will simplify.  */
     82  1.1  mrg   predicate nonconst_predicate;
     83  1.1  mrg   int size;
     84  1.1  mrg   sreal GTY((skip)) time;
     85  1.1  mrg };
     86  1.1  mrg 
     87  1.1  mrg /* Function inlining information.  */
     88  1.1  mrg struct GTY(()) ipa_fn_summary
     89  1.1  mrg {
     90  1.1  mrg   /* Information about the function body itself.  */
     91  1.1  mrg 
     92  1.1  mrg   /* Estimated stack frame consumption by the function.  */
     93  1.1  mrg   HOST_WIDE_INT estimated_self_stack_size;
     94  1.1  mrg   /* Size of the function body.  */
     95  1.1  mrg   int self_size;
     96  1.1  mrg   /* Minimal size increase after inlining.  */
     97  1.1  mrg   int min_size;
     98  1.1  mrg 
     99  1.1  mrg   /* False when there something makes inlining impossible (such as va_arg).  */
    100  1.1  mrg   unsigned inlinable : 1;
    101  1.1  mrg   /* True wen there is only one caller of the function before small function
    102  1.1  mrg      inlining.  */
    103  1.1  mrg   unsigned int single_caller : 1;
    104  1.1  mrg   /* True if function contains any floating point expressions.  */
    105  1.1  mrg   unsigned int fp_expressions : 1;
    106  1.1  mrg 
    107  1.1  mrg   /* Information about function that will result after applying all the
    108  1.1  mrg      inline decisions present in the callgraph.  Generally kept up to
    109  1.1  mrg      date only for functions that are not inline clones. */
    110  1.1  mrg 
    111  1.1  mrg   /* Estimated stack frame consumption by the function.  */
    112  1.1  mrg   HOST_WIDE_INT estimated_stack_size;
    113  1.1  mrg   /* Expected offset of the stack frame of function.  */
    114  1.1  mrg   HOST_WIDE_INT stack_frame_offset;
    115  1.1  mrg   /* Estimated size of the function after inlining.  */
    116  1.1  mrg   sreal GTY((skip)) time;
    117  1.1  mrg   int size;
    118  1.1  mrg 
    119  1.1  mrg   /* Conditional size/time information.  The summaries are being
    120  1.1  mrg      merged during inlining.  */
    121  1.1  mrg   conditions conds;
    122  1.1  mrg   vec<size_time_entry, va_gc> *size_time_table;
    123  1.1  mrg 
    124  1.1  mrg   /* Predicate on when some loop in the function becomes to have known
    125  1.1  mrg      bounds.   */
    126  1.1  mrg   predicate * GTY((skip)) loop_iterations;
    127  1.1  mrg   /* Predicate on when some loop in the function becomes to have known
    128  1.1  mrg      stride.   */
    129  1.1  mrg   predicate * GTY((skip)) loop_stride;
    130  1.1  mrg   /* Predicate on when some array indexes become constants.  */
    131  1.1  mrg   predicate * GTY((skip)) array_index;
    132  1.1  mrg   /* Estimated growth for inlining all copies of the function before start
    133  1.1  mrg      of small functions inlining.
    134  1.1  mrg      This value will get out of date as the callers are duplicated, but
    135  1.1  mrg      using up-to-date value in the badness metric mean a lot of extra
    136  1.1  mrg      expenses.  */
    137  1.1  mrg   int growth;
    138  1.1  mrg   /* Number of SCC on the beginning of inlining process.  */
    139  1.1  mrg   int scc_no;
    140  1.1  mrg 
    141  1.1  mrg   /* Keep all field empty so summary dumping works during its computation.
    142  1.1  mrg      This is useful for debugging.  */
    143  1.1  mrg   ipa_fn_summary ()
    144  1.1  mrg     : estimated_self_stack_size (0), self_size (0), min_size (0),
    145  1.1  mrg       inlinable (false), single_caller (false),
    146  1.1  mrg       fp_expressions (false), estimated_stack_size (false),
    147  1.1  mrg       stack_frame_offset (false), time (0), size (0), conds (NULL),
    148  1.1  mrg       size_time_table (NULL), loop_iterations (NULL), loop_stride (NULL),
    149  1.1  mrg       array_index (NULL), growth (0), scc_no (0)
    150  1.1  mrg     {
    151  1.1  mrg     }
    152  1.1  mrg 
    153  1.1  mrg   /* Record time and size under given predicates.  */
    154  1.1  mrg   void account_size_time (int, sreal, const predicate &, const predicate &);
    155  1.1  mrg 
    156  1.1  mrg   /* Reset summary to empty state.  */
    157  1.1  mrg   void reset (struct cgraph_node *node);
    158  1.1  mrg 
    159  1.1  mrg   /* We keep values scaled up, so fractional sizes can be accounted.  */
    160  1.1  mrg   static const int size_scale = 2;
    161  1.1  mrg };
    162  1.1  mrg 
    163  1.1  mrg class GTY((user)) ipa_fn_summary_t: public function_summary <ipa_fn_summary *>
    164  1.1  mrg {
    165  1.1  mrg public:
    166  1.1  mrg   ipa_fn_summary_t (symbol_table *symtab, bool ggc):
    167  1.1  mrg     function_summary <ipa_fn_summary *> (symtab, ggc) {}
    168  1.1  mrg 
    169  1.1  mrg   static ipa_fn_summary_t *create_ggc (symbol_table *symtab)
    170  1.1  mrg   {
    171  1.1  mrg     struct ipa_fn_summary_t *summary = new (ggc_alloc <ipa_fn_summary_t> ())
    172  1.1  mrg       ipa_fn_summary_t(symtab, true);
    173  1.1  mrg     summary->disable_insertion_hook ();
    174  1.1  mrg     return summary;
    175  1.1  mrg   }
    176  1.1  mrg 
    177  1.1  mrg 
    178  1.1  mrg   virtual void insert (cgraph_node *, ipa_fn_summary *);
    179  1.1  mrg   virtual void remove (cgraph_node *node, ipa_fn_summary *);
    180  1.1  mrg   virtual void duplicate (cgraph_node *src, cgraph_node *dst,
    181  1.1  mrg 			  ipa_fn_summary *src_data, ipa_fn_summary *dst_data);
    182  1.1  mrg };
    183  1.1  mrg 
    184  1.1  mrg extern GTY(()) function_summary <ipa_fn_summary *> *ipa_fn_summaries;
    185  1.1  mrg 
    186  1.1  mrg /* Information kept about callgraph edges.  */
    187  1.1  mrg struct ipa_call_summary
    188  1.1  mrg {
    189  1.1  mrg   class predicate *predicate;
    190  1.1  mrg   /* Vector indexed by parameters.  */
    191  1.1  mrg   vec<inline_param_summary> param;
    192  1.1  mrg   /* Estimated size and time of the call statement.  */
    193  1.1  mrg   int call_stmt_size;
    194  1.1  mrg   int call_stmt_time;
    195  1.1  mrg   /* Depth of loop nest, 0 means no nesting.  */
    196  1.1  mrg   unsigned int loop_depth;
    197  1.1  mrg   /* Indicates whether the caller returns the value of it's callee.  */
    198  1.1  mrg   bool is_return_callee_uncaptured;
    199  1.1  mrg 
    200  1.1  mrg   /* Keep all field empty so summary dumping works during its computation.
    201  1.1  mrg      This is useful for debugging.  */
    202  1.1  mrg   ipa_call_summary ()
    203  1.1  mrg     : predicate (NULL), param (vNULL), call_stmt_size (0), call_stmt_time (0),
    204  1.1  mrg       loop_depth (0)
    205  1.1  mrg     {
    206  1.1  mrg     }
    207  1.1  mrg 
    208  1.1  mrg   /* Reset inline summary to empty state.  */
    209  1.1  mrg   void reset ();
    210  1.1  mrg };
    211  1.1  mrg 
    212  1.1  mrg class ipa_call_summary_t: public call_summary <ipa_call_summary *>
    213  1.1  mrg {
    214  1.1  mrg public:
    215  1.1  mrg   ipa_call_summary_t (symbol_table *symtab, bool ggc):
    216  1.1  mrg     call_summary <ipa_call_summary *> (symtab, ggc) {}
    217  1.1  mrg 
    218  1.1  mrg   /* Hook that is called by summary when an edge is duplicated.  */
    219  1.1  mrg   virtual void remove (cgraph_edge *cs, ipa_call_summary *);
    220  1.1  mrg   /* Hook that is called by summary when an edge is duplicated.  */
    221  1.1  mrg   virtual void duplicate (cgraph_edge *src, cgraph_edge *dst,
    222  1.1  mrg 			  ipa_call_summary *src_data,
    223  1.1  mrg 			  ipa_call_summary *dst_data);
    224  1.1  mrg };
    225  1.1  mrg 
    226  1.1  mrg extern call_summary <ipa_call_summary *> *ipa_call_summaries;
    227  1.1  mrg 
    228  1.1  mrg /* In ipa-fnsummary.c  */
    229  1.1  mrg void ipa_debug_fn_summary (struct cgraph_node *);
    230  1.1  mrg void ipa_dump_fn_summaries (FILE *f);
    231  1.1  mrg void ipa_dump_fn_summary (FILE *f, struct cgraph_node *node);
    232  1.1  mrg void ipa_dump_hints (FILE *f, ipa_hints);
    233  1.1  mrg void ipa_free_fn_summary (void);
    234  1.1  mrg void inline_analyze_function (struct cgraph_node *node);
    235  1.1  mrg void estimate_ipcp_clone_size_and_time (struct cgraph_node *,
    236  1.1  mrg 					vec<tree>,
    237  1.1  mrg 					vec<ipa_polymorphic_call_context>,
    238  1.1  mrg 					vec<ipa_agg_jump_function_p>,
    239  1.1  mrg 					int *, sreal *, sreal *,
    240  1.1  mrg 				        ipa_hints *);
    241  1.1  mrg void ipa_merge_fn_summary_after_inlining (struct cgraph_edge *edge);
    242  1.1  mrg void ipa_update_overall_fn_summary (struct cgraph_node *node);
    243  1.1  mrg void compute_fn_summary (struct cgraph_node *, bool);
    244  1.1  mrg 
    245  1.1  mrg 
    246  1.1  mrg void evaluate_properties_for_edge (struct cgraph_edge *e, bool inline_p,
    247  1.1  mrg 				   clause_t *clause_ptr,
    248  1.1  mrg 				   clause_t *nonspec_clause_ptr,
    249  1.1  mrg 				   vec<tree> *known_vals_ptr,
    250  1.1  mrg 				   vec<ipa_polymorphic_call_context>
    251  1.1  mrg 				   *known_contexts_ptr,
    252  1.1  mrg 				   vec<ipa_agg_jump_function_p> *);
    253  1.1  mrg void estimate_node_size_and_time (struct cgraph_node *node,
    254  1.1  mrg 				  clause_t possible_truths,
    255  1.1  mrg 				  clause_t nonspec_possible_truths,
    256  1.1  mrg 				  vec<tree> known_vals,
    257  1.1  mrg 				  vec<ipa_polymorphic_call_context>,
    258  1.1  mrg 				  vec<ipa_agg_jump_function_p> known_aggs,
    259  1.1  mrg 				  int *ret_size, int *ret_min_size,
    260  1.1  mrg 				  sreal *ret_time,
    261  1.1  mrg 				  sreal *ret_nonspecialized_time,
    262  1.1  mrg 				  ipa_hints *ret_hints,
    263  1.1  mrg 				  vec<inline_param_summary>
    264  1.1  mrg 				  inline_param_summary);
    265  1.1  mrg 
    266  1.1  mrg void ipa_fnsummary_c_finalize (void);
    267  1.1  mrg 
    268  1.1  mrg #endif /* GCC_IPA_FNSUMMARY_H */
    269