1 /* Tree inlining hooks and declarations.
2    Copyright (C) 2001-2019 Free Software Foundation, Inc.
3    Contributed by Alexandre Oliva  <aoliva@redhat.com>
4 
5 This file is part of GCC.
6 
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11 
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3.  If not see
19 <http://www.gnu.org/licenses/>.  */
20 
21 #ifndef GCC_TREE_INLINE_H
22 #define GCC_TREE_INLINE_H
23 
24 
25 struct cgraph_edge;
26 
27 /* Indicate the desired behavior wrt call graph edges.  We can either
28    duplicate the edge (inlining, cloning), move the edge (versioning,
29    parallelization), or move the edges of the clones (saving).  */
30 
31 enum copy_body_cge_which
32 {
33   CB_CGE_DUPLICATE,
34   CB_CGE_MOVE,
35   CB_CGE_MOVE_CLONES
36 };
37 
38 typedef int_hash <unsigned short, 0> dependence_hash;
39 
40 /* Data required for function body duplication.  */
41 
42 struct copy_body_data
43 {
44   /* FUNCTION_DECL for function being inlined, or in general the
45      source function providing the original trees.  */
46   tree src_fn;
47 
48   /* FUNCTION_DECL for function being inlined into, or in general
49      the destination function receiving the new trees.  */
50   tree dst_fn;
51 
52   /* Callgraph node of the source function.  */
53   struct cgraph_node *src_node;
54 
55   /* Callgraph node of the destination function.  */
56   struct cgraph_node *dst_node;
57 
58   /* struct function for function being inlined.  Usually this is the same
59      as DECL_STRUCT_FUNCTION (src_fn), but can be different if saved_cfg
60      and saved_eh are in use.  */
61   struct function *src_cfun;
62 
63   /* The VAR_DECL for the return value.  */
64   tree retvar;
65 
66   /* The map from local declarations in the inlined function to
67      equivalents in the function into which it is being inlined.  */
68   hash_map<tree, tree> *decl_map;
69 
70   /* Create a new decl to replace DECL in the destination function.  */
71   tree (*copy_decl) (tree, struct copy_body_data *);
72 
73   /* Current BLOCK.  */
74   tree block;
75 
76   /* GIMPLE_CALL if va arg parameter packs should be expanded or NULL
77      is not.  */
78   gcall *call_stmt;
79 
80   /* > 0 if we are remapping a type currently.  */
81   int remapping_type_depth;
82 
83   /* Exception landing pad the inlined call lies in.  */
84   int eh_lp_nr;
85 
86   /* Maps region and landing pad structures from the function being copied
87      to duplicates created within the function we inline into.  */
88   hash_map<void *, void *> *eh_map;
89 
90   /* We use the same mechanism do all sorts of different things.  Rather
91      than enumerating the different cases, we categorize the behavior
92      in the various situations.  */
93 
94   /* What to do with call graph edges.  */
95   enum copy_body_cge_which transform_call_graph_edges;
96 
97   /* True if a new CFG should be created.  False for inlining, true for
98      everything else.  */
99   bool transform_new_cfg;
100 
101   /* True if RETURN_EXPRs should be transformed to just the contained
102      MODIFY_EXPR.  The branch semantics of the return will be handled
103      by manipulating the CFG rather than a statement.  */
104   bool transform_return_to_modify;
105 
106   /* True if the parameters of the source function are transformed.
107      Only true for inlining.  */
108   bool transform_parameter;
109 
110   /* True if this statement will need to be regimplified.  */
111   bool regimplify;
112 
113   /* True if trees may not be unshared.  */
114   bool do_not_unshare;
115 
116   /* True if new declarations may not be created during type remapping.  */
117   bool prevent_decl_creation_for_types;
118 
119   /* True if the location information will need to be reset.  */
120   bool reset_location;
121 
122   /* Replace error_mark_node as upper bound of array types with
123      an uninitialized VAR_DECL temporary.  */
124   bool adjust_array_error_bounds;
125 
126   /* Usually copy_decl callback always creates new decls, in that case
127      we want to remap all variably_modified_type_p types.  If this flag
128      is set, remap_type will do further checks to see if remap_decl
129      of any decls mentioned in the type will remap to anything but itself
130      and only in that case will actually remap the type.  */
131   bool dont_remap_vla_if_no_change;
132 
133   /* A function to be called when duplicating BLOCK nodes.  */
134   void (*transform_lang_insert_block) (tree);
135 
136   /* Statements that might be possibly folded.  */
137   hash_set<gimple *> *statements_to_fold;
138 
139   /* Entry basic block to currently copied body.  */
140   basic_block entry_bb;
141 
142   /* For partial function versioning, bitmap of bbs to be copied,
143      otherwise NULL.  */
144   bitmap blocks_to_copy;
145 
146   /* Debug statements that need processing.  */
147   vec<gdebug *> debug_stmts;
148 
149   /* A map from local declarations in the inlined function to
150      equivalents in the function into which it is being inlined, where
151      the originals have been mapped to a value rather than to a
152      variable.  */
153   hash_map<tree, tree> *debug_map;
154 
155   /* A map from the inlined functions dependence info cliques to
156      equivalents in the function into which it is being inlined.  */
157   hash_map<dependence_hash, unsigned short> *dependence_map;
158 
159   /* A list of addressable local variables remapped into the caller
160      when inlining a call within an OpenMP SIMD-on-SIMT loop.  */
161   vec<tree> *dst_simt_vars;
162 
163   /* If clobbers for local variables from the inline function
164      that need to live in memory should be added to EH landing pads
165      outside of the inlined function, this should be the number
166      of basic blocks in the caller before inlining.  Zero otherwise.  */
167   int add_clobbers_to_eh_landing_pads;
168 };
169 
170 /* Weights of constructions for estimate_num_insns.  */
171 
172 struct eni_weights
173 {
174   /* Cost per call.  */
175   unsigned call_cost;
176 
177   /* Cost per indirect call.  */
178   unsigned indirect_call_cost;
179 
180   /* Cost per call to a target specific builtin */
181   unsigned target_builtin_call_cost;
182 
183   /* Cost of "expensive" div and mod operations.  */
184   unsigned div_mod_cost;
185 
186   /* Cost for omp construct.  */
187   unsigned omp_cost;
188 
189   /* Cost for tm transaction.  */
190   unsigned tm_cost;
191 
192   /* Cost of return.  */
193   unsigned return_cost;
194 
195   /* True when time of statement should be estimated.  Thus, the
196      cost of a switch statement is logarithmic rather than linear in number
197      of cases.  */
198   bool time_based;
199 };
200 
201 /* Weights that estimate_num_insns uses for heuristics in inlining.  */
202 
203 extern eni_weights eni_inlining_weights;
204 
205 /* Weights that estimate_num_insns uses to estimate the size of the
206    produced code.  */
207 
208 extern eni_weights eni_size_weights;
209 
210 /* Weights that estimate_num_insns uses to estimate the time necessary
211    to execute the produced code.  */
212 
213 extern eni_weights eni_time_weights;
214 
215 /* Function prototypes.  */
216 void init_inline_once (void);
217 extern tree copy_tree_body_r (tree *, int *, void *);
218 extern void insert_decl_map (copy_body_data *, tree, tree);
219 unsigned int optimize_inline_calls (tree);
220 tree maybe_inline_call_in_expr (tree);
221 bool tree_inlinable_function_p (tree);
222 tree copy_tree_r (tree *, int *, void *);
223 tree copy_decl_no_change (tree decl, copy_body_data *id);
224 int estimate_move_cost (tree type, bool);
225 int estimate_num_insns (gimple *, eni_weights *);
226 int estimate_num_insns_fn (tree, eni_weights *);
227 int estimate_num_insns_seq (gimple_seq, eni_weights *);
228 bool tree_versionable_function_p (tree);
229 extern tree remap_decl (tree decl, copy_body_data *id);
230 extern tree remap_type (tree type, copy_body_data *id);
231 extern gimple_seq copy_gimple_seq_and_replace_locals (gimple_seq seq);
232 extern bool debug_find_tree (tree, tree);
233 extern tree copy_fn (tree, tree&, tree&);
234 extern const char *copy_forbidden (struct function *fun);
235 extern tree copy_decl_for_dup_finish (copy_body_data *id, tree decl, tree copy);
236 
237 /* This is in tree-inline.c since the routine uses
238    data structures from the inliner.  */
239 extern tree build_duplicate_type (tree);
240 
241 #endif /* GCC_TREE_INLINE_H */
242