gcc/
[official-gcc.git] / gcc / tree-inline.h
blob0bfd20c7776dbc88c6833a6964b5b1b92018c885
1 /* Tree inlining hooks and declarations.
2 Copyright (C) 2001-2015 Free Software Foundation, Inc.
3 Contributed by Alexandre Oliva <aoliva@redhat.com>
5 This file is part of GCC.
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.
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.
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/>. */
21 #ifndef GCC_TREE_INLINE_H
22 #define GCC_TREE_INLINE_H
25 struct cgraph_edge;
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). */
31 enum copy_body_cge_which
33 CB_CGE_DUPLICATE,
34 CB_CGE_MOVE,
35 CB_CGE_MOVE_CLONES
38 struct dependence_hasher : default_hashmap_traits
40 template<typename T>
41 static void
42 mark_deleted (T &e)
43 { gcc_unreachable (); }
45 template<typename T>
46 static void
47 mark_empty (T &e)
48 { e.m_key = 0; }
50 template<typename T>
51 static bool
52 is_deleted (T &)
53 { return false; }
55 template<typename T> static bool is_empty (T &e) { return e.m_key == 0; }
58 /* Data required for function body duplication. */
60 struct copy_body_data
62 /* FUNCTION_DECL for function being inlined, or in general the
63 source function providing the original trees. */
64 tree src_fn;
66 /* FUNCTION_DECL for function being inlined into, or in general
67 the destination function receiving the new trees. */
68 tree dst_fn;
70 /* Callgraph node of the source function. */
71 struct cgraph_node *src_node;
73 /* Callgraph node of the destination function. */
74 struct cgraph_node *dst_node;
76 /* struct function for function being inlined. Usually this is the same
77 as DECL_STRUCT_FUNCTION (src_fn), but can be different if saved_cfg
78 and saved_eh are in use. */
79 struct function *src_cfun;
81 /* The VAR_DECL for the return value. */
82 tree retvar;
84 /* The VAR_DECL for the return bounds. */
85 tree retbnd;
87 /* Assign statements that need bounds copy. */
88 vec<gimple> assign_stmts;
90 /* The map from local declarations in the inlined function to
91 equivalents in the function into which it is being inlined. */
92 hash_map<tree, tree> *decl_map;
94 /* Create a new decl to replace DECL in the destination function. */
95 tree (*copy_decl) (tree, struct copy_body_data *);
97 /* Current BLOCK. */
98 tree block;
100 /* GIMPLE_CALL if va arg parameter packs should be expanded or NULL
101 is not. */
102 gimple call_stmt;
104 /* Exception landing pad the inlined call lies in. */
105 int eh_lp_nr;
107 /* Maps region and landing pad structures from the function being copied
108 to duplicates created within the function we inline into. */
109 hash_map<void *, void *> *eh_map;
111 /* We use the same mechanism do all sorts of different things. Rather
112 than enumerating the different cases, we categorize the behavior
113 in the various situations. */
115 /* What to do with call graph edges. */
116 enum copy_body_cge_which transform_call_graph_edges;
118 /* True if a new CFG should be created. False for inlining, true for
119 everything else. */
120 bool transform_new_cfg;
122 /* True if RETURN_EXPRs should be transformed to just the contained
123 MODIFY_EXPR. The branch semantics of the return will be handled
124 by manipulating the CFG rather than a statement. */
125 bool transform_return_to_modify;
127 /* True if the parameters of the source function are transformed.
128 Only true for inlining. */
129 bool transform_parameter;
131 /* True if this statement will need to be regimplified. */
132 bool regimplify;
134 /* True if trees should not be unshared. */
135 bool do_not_unshare;
137 /* > 0 if we are remapping a type currently. */
138 int remapping_type_depth;
140 /* A function to be called when duplicating BLOCK nodes. */
141 void (*transform_lang_insert_block) (tree);
143 /* Statements that might be possibly folded. */
144 hash_set<gimple> *statements_to_fold;
146 /* Entry basic block to currently copied body. */
147 basic_block entry_bb;
149 /* For partial function versioning, bitmap of bbs to be copied,
150 otherwise NULL. */
151 bitmap blocks_to_copy;
153 /* Debug statements that need processing. */
154 vec<gdebug *> debug_stmts;
156 /* A map from local declarations in the inlined function to
157 equivalents in the function into which it is being inlined, where
158 the originals have been mapped to a value rather than to a
159 variable. */
160 hash_map<tree, tree> *debug_map;
162 /* Cilk keywords currently need to replace some variables that
163 ordinary nested functions do not. */
164 bool remap_var_for_cilk;
166 /* A map from the inlined functions dependence info cliques to
167 equivalents in the function into which it is being inlined. */
168 hash_map<unsigned short, unsigned short, dependence_hasher> *dependence_map;
171 /* Weights of constructions for estimate_num_insns. */
173 typedef struct eni_weights_d
175 /* Cost per call. */
176 unsigned call_cost;
178 /* Cost per indirect call. */
179 unsigned indirect_call_cost;
181 /* Cost per call to a target specific builtin */
182 unsigned target_builtin_call_cost;
184 /* Cost of "expensive" div and mod operations. */
185 unsigned div_mod_cost;
187 /* Cost for omp construct. */
188 unsigned omp_cost;
190 /* Cost for tm transaction. */
191 unsigned tm_cost;
193 /* Cost of return. */
194 unsigned return_cost;
196 /* True when time of statement should be estimated. Thus, the
197 cost of a switch statement is logarithmic rather than linear in number
198 of cases. */
199 bool time_based;
200 } eni_weights;
202 /* Weights that estimate_num_insns uses for heuristics in inlining. */
204 extern eni_weights eni_inlining_weights;
206 /* Weights that estimate_num_insns uses to estimate the size of the
207 produced code. */
209 extern eni_weights eni_size_weights;
211 /* Weights that estimate_num_insns uses to estimate the time necessary
212 to execute the produced code. */
214 extern eni_weights eni_time_weights;
216 /* Function prototypes. */
217 void init_inline_once (void);
218 extern tree copy_tree_body_r (tree *, int *, void *);
219 extern void insert_decl_map (copy_body_data *, tree, tree);
220 unsigned int optimize_inline_calls (tree);
221 tree maybe_inline_call_in_expr (tree);
222 bool tree_inlinable_function_p (tree);
223 tree copy_tree_r (tree *, int *, void *);
224 tree copy_decl_no_change (tree decl, copy_body_data *id);
225 int estimate_move_cost (tree type, bool);
226 int estimate_num_insns (gimple, eni_weights *);
227 int estimate_num_insns_fn (tree, eni_weights *);
228 int count_insns_seq (gimple_seq, eni_weights *);
229 bool tree_versionable_function_p (tree);
230 extern tree remap_decl (tree decl, copy_body_data *id);
231 extern tree remap_type (tree type, copy_body_data *id);
232 extern gimple_seq copy_gimple_seq_and_replace_locals (gimple_seq seq);
233 extern bool debug_find_tree (tree, tree);
234 extern tree copy_fn (tree, tree&, tree&);
235 extern const char *copy_forbidden (struct function *fun, tree fndecl);
237 /* This is in tree-inline.c since the routine uses
238 data structures from the inliner. */
239 extern tree build_duplicate_type (tree);
241 #endif /* GCC_TREE_INLINE_H */