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