Branch data Line data Source code
1 : : /* Tree inlining.
2 : : Copyright (C) 2001-2025 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 : : #include "config.h"
22 : : #include "system.h"
23 : : #include "coretypes.h"
24 : : #include "backend.h"
25 : : #include "target.h"
26 : : #include "rtl.h"
27 : : #include "tree.h"
28 : : #include "gimple.h"
29 : : #include "cfghooks.h"
30 : : #include "tree-pass.h"
31 : : #include "ssa.h"
32 : : #include "cgraph.h"
33 : : #include "tree-pretty-print.h"
34 : : #include "diagnostic-core.h"
35 : : #include "gimple-predict.h"
36 : : #include "fold-const.h"
37 : : #include "stor-layout.h"
38 : : #include "calls.h"
39 : : #include "tree-inline.h"
40 : : #include "langhooks.h"
41 : : #include "cfganal.h"
42 : : #include "tree-iterator.h"
43 : : #include "intl.h"
44 : : #include "gimple-iterator.h"
45 : : #include "gimple-fold.h"
46 : : #include "tree-eh.h"
47 : : #include "gimplify.h"
48 : : #include "gimplify-me.h"
49 : : #include "gimple-walk.h"
50 : : #include "tree-cfg.h"
51 : : #include "tree-into-ssa.h"
52 : : #include "tree-dfa.h"
53 : : #include "tree-ssa.h"
54 : : #include "except.h"
55 : : #include "debug.h"
56 : : #include "value-prof.h"
57 : : #include "cfgloop.h"
58 : : #include "builtins.h"
59 : : #include "stringpool.h"
60 : : #include "attribs.h"
61 : : #include "sreal.h"
62 : : #include "tree-cfgcleanup.h"
63 : : #include "tree-ssa-live.h"
64 : : #include "alloc-pool.h"
65 : : #include "symbol-summary.h"
66 : : #include "symtab-thunks.h"
67 : : #include "symtab-clones.h"
68 : : #include "asan.h"
69 : :
70 : : /* I'm not real happy about this, but we need to handle gimple and
71 : : non-gimple trees. */
72 : :
73 : : /* Inlining, Cloning, Versioning, Parallelization
74 : :
75 : : Inlining: a function body is duplicated, but the PARM_DECLs are
76 : : remapped into VAR_DECLs, and non-void RETURN_EXPRs become
77 : : MODIFY_EXPRs that store to a dedicated returned-value variable.
78 : : The duplicated eh_region info of the copy will later be appended
79 : : to the info for the caller; the eh_region info in copied throwing
80 : : statements and RESX statements are adjusted accordingly.
81 : :
82 : : Cloning: (only in C++) We have one body for a con/de/structor, and
83 : : multiple function decls, each with a unique parameter list.
84 : : Duplicate the body, using the given splay tree; some parameters
85 : : will become constants (like 0 or 1).
86 : :
87 : : Versioning: a function body is duplicated and the result is a new
88 : : function rather than into blocks of an existing function as with
89 : : inlining. Some parameters will become constants.
90 : :
91 : : Parallelization: a region of a function is duplicated resulting in
92 : : a new function. Variables may be replaced with complex expressions
93 : : to enable shared variable semantics.
94 : :
95 : : All of these will simultaneously lookup any callgraph edges. If
96 : : we're going to inline the duplicated function body, and the given
97 : : function has some cloned callgraph nodes (one for each place this
98 : : function will be inlined) those callgraph edges will be duplicated.
99 : : If we're cloning the body, those callgraph edges will be
100 : : updated to point into the new body. (Note that the original
101 : : callgraph node and edge list will not be altered.)
102 : :
103 : : See the CALL_EXPR handling case in copy_tree_body_r (). */
104 : :
105 : : /* To Do:
106 : :
107 : : o In order to make inlining-on-trees work, we pessimized
108 : : function-local static constants. In particular, they are now
109 : : always output, even when not addressed. Fix this by treating
110 : : function-local static constants just like global static
111 : : constants; the back-end already knows not to output them if they
112 : : are not needed.
113 : :
114 : : o Provide heuristics to clamp inlining of recursive template
115 : : calls? */
116 : :
117 : :
118 : : /* Weights that estimate_num_insns uses to estimate the size of the
119 : : produced code. */
120 : :
121 : : eni_weights eni_size_weights;
122 : :
123 : : /* Weights that estimate_num_insns uses to estimate the time necessary
124 : : to execute the produced code. */
125 : :
126 : : eni_weights eni_time_weights;
127 : :
128 : : /* Prototypes. */
129 : :
130 : : static tree declare_return_variable (copy_body_data *, tree, tree,
131 : : basic_block);
132 : : static void remap_block (tree *, copy_body_data *);
133 : : static void copy_bind_expr (tree *, int *, copy_body_data *);
134 : : static void declare_inline_vars (tree, tree);
135 : : static void remap_save_expr (tree *, hash_map<tree, tree> *, int *);
136 : : static void prepend_lexical_block (tree current_block, tree new_block);
137 : : static tree copy_result_decl_to_var (tree, copy_body_data *);
138 : : static tree copy_decl_maybe_to_var (tree, copy_body_data *);
139 : : static gimple_seq remap_gimple_stmt (gimple *, copy_body_data *);
140 : : static void insert_init_stmt (copy_body_data *, basic_block, gimple *);
141 : :
142 : : /* Insert a tree->tree mapping for ID. Despite the name suggests
143 : : that the trees should be variables, it is used for more than that. */
144 : :
145 : : void
146 : 458461343 : insert_decl_map (copy_body_data *id, tree key, tree value)
147 : : {
148 : 458461343 : id->decl_map->put (key, value);
149 : :
150 : : /* Always insert an identity map as well. If we see this same new
151 : : node again, we won't want to duplicate it a second time. */
152 : 458461343 : if (key != value && value)
153 : 152358946 : id->decl_map->put (value, value);
154 : 458461343 : }
155 : :
156 : : /* If nonzero, we're remapping the contents of inlined debug
157 : : statements. If negative, an error has occurred, such as a
158 : : reference to a variable that isn't available in the inlined
159 : : context. */
160 : : static int processing_debug_stmt = 0;
161 : :
162 : : /* Construct new SSA name for old NAME. ID is the inline context. */
163 : :
164 : : static tree
165 : 67246292 : remap_ssa_name (tree name, copy_body_data *id)
166 : : {
167 : 67246292 : tree new_tree, var;
168 : 67246292 : tree *n;
169 : :
170 : 67246292 : gcc_assert (TREE_CODE (name) == SSA_NAME);
171 : :
172 : 67246292 : n = id->decl_map->get (name);
173 : 67246292 : if (n)
174 : : {
175 : : /* When we perform edge redirection as part of CFG copy, IPA-SRA can
176 : : remove an unused LHS from a call statement. Such LHS can however
177 : : still appear in debug statements, but their value is lost in this
178 : : function and we do not want to map them. */
179 : 49354869 : if (id->killed_new_ssa_names
180 : 49354869 : && id->killed_new_ssa_names->contains (*n))
181 : : {
182 : 967 : gcc_assert (processing_debug_stmt);
183 : 967 : processing_debug_stmt = -1;
184 : 967 : return name;
185 : : }
186 : :
187 : 49353902 : return unshare_expr (*n);
188 : : }
189 : :
190 : 17891423 : if (processing_debug_stmt)
191 : : {
192 : 102009 : if (SSA_NAME_IS_DEFAULT_DEF (name)
193 : 101948 : && TREE_CODE (SSA_NAME_VAR (name)) == PARM_DECL
194 : 101901 : && id->entry_bb == NULL
195 : 203909 : && single_succ_p (ENTRY_BLOCK_PTR_FOR_FN (cfun)))
196 : : {
197 : 101900 : gimple *def_temp;
198 : 101900 : gimple_stmt_iterator gsi;
199 : 101900 : tree val = SSA_NAME_VAR (name);
200 : :
201 : 101900 : n = id->decl_map->get (val);
202 : 101900 : if (n != NULL)
203 : 101900 : val = *n;
204 : 101900 : if (TREE_CODE (val) != PARM_DECL
205 : 101900 : && !(VAR_P (val) && DECL_ABSTRACT_ORIGIN (val)))
206 : : {
207 : 0 : processing_debug_stmt = -1;
208 : 0 : return name;
209 : : }
210 : 101900 : n = id->decl_map->get (val);
211 : 101900 : if (n && TREE_CODE (*n) == DEBUG_EXPR_DECL)
212 : : return *n;
213 : 33500 : tree vexpr = build_debug_expr_decl (TREE_TYPE (name));
214 : : /* FIXME: Is setting the mode really necessary? */
215 : 33500 : SET_DECL_MODE (vexpr, DECL_MODE (SSA_NAME_VAR (name)));
216 : 33500 : def_temp = gimple_build_debug_source_bind (vexpr, val, NULL);
217 : 33500 : gsi = gsi_after_labels (single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
218 : 33500 : gsi_insert_before (&gsi, def_temp, GSI_SAME_STMT);
219 : 33500 : insert_decl_map (id, val, vexpr);
220 : 33500 : return vexpr;
221 : : }
222 : :
223 : 109 : processing_debug_stmt = -1;
224 : 109 : return name;
225 : : }
226 : :
227 : : /* Remap anonymous SSA names or SSA names of anonymous decls. */
228 : 17789414 : var = SSA_NAME_VAR (name);
229 : 3556619 : if (!var
230 : 3556619 : || (!SSA_NAME_IS_DEFAULT_DEF (name)
231 : 3189633 : && VAR_P (var)
232 : 2982801 : && !VAR_DECL_IS_VIRTUAL_OPERAND (var)
233 : 2982801 : && DECL_ARTIFICIAL (var)
234 : 508847 : && DECL_IGNORED_P (var)
235 : 162293 : && !DECL_NAME (var)))
236 : : {
237 : 14238215 : struct ptr_info_def *pi;
238 : 14238215 : new_tree = make_ssa_name (remap_type (TREE_TYPE (name), id));
239 : 14238215 : if (!var && SSA_NAME_IDENTIFIER (name))
240 : 1886618 : SET_SSA_NAME_VAR_OR_IDENTIFIER (new_tree, SSA_NAME_IDENTIFIER (name));
241 : 14238215 : insert_decl_map (id, name, new_tree);
242 : 28476430 : SSA_NAME_OCCURS_IN_ABNORMAL_PHI (new_tree)
243 : 14238215 : = SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name);
244 : : /* At least IPA points-to info can be directly transferred. */
245 : 14238215 : if (id->src_cfun->gimple_df
246 : 14238215 : && id->src_cfun->gimple_df->ipa_pta
247 : 14729 : && POINTER_TYPE_P (TREE_TYPE (name))
248 : 2595 : && (pi = SSA_NAME_PTR_INFO (name))
249 : 14240805 : && !pi->pt.anything)
250 : : {
251 : 2569 : struct ptr_info_def *new_pi = get_ptr_info (new_tree);
252 : 2569 : new_pi->pt = pi->pt;
253 : : }
254 : : /* So can range-info. */
255 : 23436211 : if (!POINTER_TYPE_P (TREE_TYPE (name))
256 : 22882645 : && SSA_NAME_RANGE_INFO (name))
257 : 2956873 : duplicate_ssa_name_range_info (new_tree, name);
258 : 14238215 : return new_tree;
259 : : }
260 : :
261 : : /* Do not set DEF_STMT yet as statement is not copied yet. We do that
262 : : in copy_bb. */
263 : 3551199 : new_tree = remap_decl (var, id);
264 : :
265 : : /* We might've substituted constant or another SSA_NAME for
266 : : the variable.
267 : :
268 : : Replace the SSA name representing RESULT_DECL by variable during
269 : : inlining: this saves us from need to introduce PHI node in a case
270 : : return value is just partly initialized. */
271 : 350427 : if ((VAR_P (new_tree) || TREE_CODE (new_tree) == PARM_DECL)
272 : 3901626 : && (!SSA_NAME_VAR (name)
273 : 3551199 : || TREE_CODE (SSA_NAME_VAR (name)) != RESULT_DECL
274 : 0 : || !id->transform_return_to_modify))
275 : : {
276 : 3551199 : struct ptr_info_def *pi;
277 : 3551199 : new_tree = make_ssa_name (new_tree);
278 : 3551199 : insert_decl_map (id, name, new_tree);
279 : 7102398 : SSA_NAME_OCCURS_IN_ABNORMAL_PHI (new_tree)
280 : 3551199 : = SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name);
281 : : /* At least IPA points-to info can be directly transferred. */
282 : 3551199 : if (id->src_cfun->gimple_df
283 : 3551199 : && id->src_cfun->gimple_df->ipa_pta
284 : 2515 : && POINTER_TYPE_P (TREE_TYPE (name))
285 : 284 : && (pi = SSA_NAME_PTR_INFO (name))
286 : 3551477 : && !pi->pt.anything)
287 : : {
288 : 278 : struct ptr_info_def *new_pi = get_ptr_info (new_tree);
289 : 278 : new_pi->pt = pi->pt;
290 : : }
291 : : /* So can range-info. */
292 : 6275339 : if (!POINTER_TYPE_P (TREE_TYPE (name))
293 : 6191012 : && SSA_NAME_RANGE_INFO (name))
294 : 950119 : duplicate_ssa_name_range_info (new_tree, name);
295 : 3551199 : if (SSA_NAME_IS_DEFAULT_DEF (name))
296 : : {
297 : : /* By inlining function having uninitialized variable, we might
298 : : extend the lifetime (variable might get reused). This cause
299 : : ICE in the case we end up extending lifetime of SSA name across
300 : : abnormal edge, but also increase register pressure.
301 : :
302 : : We simply initialize all uninitialized vars by 0 except
303 : : for case we are inlining to very first BB. We can avoid
304 : : this for all BBs that are not inside strongly connected
305 : : regions of the CFG, but this is expensive to test. */
306 : 366986 : if (id->entry_bb
307 : 41585 : && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name)
308 : 0 : && (!SSA_NAME_VAR (name)
309 : 0 : || TREE_CODE (SSA_NAME_VAR (name)) != PARM_DECL)
310 : 366986 : && (id->entry_bb != EDGE_SUCC (ENTRY_BLOCK_PTR_FOR_FN (cfun),
311 : 0 : 0)->dest
312 : 0 : || EDGE_COUNT (id->entry_bb->preds) != 1))
313 : : {
314 : 0 : gimple_stmt_iterator gsi = gsi_last_bb (id->entry_bb);
315 : 0 : gimple *init_stmt;
316 : 0 : tree zero = build_zero_cst (TREE_TYPE (new_tree));
317 : :
318 : 0 : init_stmt = gimple_build_assign (new_tree, zero);
319 : 0 : gsi_insert_after (&gsi, init_stmt, GSI_NEW_STMT);
320 : 0 : SSA_NAME_IS_DEFAULT_DEF (new_tree) = 0;
321 : : }
322 : : else
323 : : {
324 : 366986 : SSA_NAME_DEF_STMT (new_tree) = gimple_build_nop ();
325 : 366986 : set_ssa_default_def (cfun, SSA_NAME_VAR (new_tree), new_tree);
326 : : }
327 : : }
328 : : }
329 : : else
330 : 0 : insert_decl_map (id, name, new_tree);
331 : : return new_tree;
332 : : }
333 : :
334 : : /* Remap DECL during the copying of the BLOCK tree for the function. */
335 : :
336 : : tree
337 : 227412430 : remap_decl (tree decl, copy_body_data *id)
338 : : {
339 : 227412430 : tree *n;
340 : :
341 : : /* We only remap local variables in the current function. */
342 : :
343 : : /* See if we have remapped this declaration. */
344 : :
345 : 227412430 : n = id->decl_map->get (decl);
346 : :
347 : 227412430 : if (!n && processing_debug_stmt)
348 : : {
349 : 664396 : processing_debug_stmt = -1;
350 : 664396 : return decl;
351 : : }
352 : :
353 : : /* When remapping a type within copy_gimple_seq_and_replace_locals, all
354 : : necessary DECLs have already been remapped and we do not want to duplicate
355 : : a decl coming from outside of the sequence we are copying. */
356 : 79861564 : if (!n
357 : 79861564 : && id->prevent_decl_creation_for_types
358 : 0 : && id->remapping_type_depth > 0
359 : 0 : && (VAR_P (decl) || TREE_CODE (decl) == PARM_DECL))
360 : : return decl;
361 : :
362 : : /* If we didn't already have an equivalent for this declaration, create one
363 : : now. */
364 : 226748034 : if (!n)
365 : : {
366 : : /* Make a copy of the variable or label. */
367 : 79861564 : tree t = id->copy_decl (decl, id);
368 : :
369 : : /* Remember it, so that if we encounter this local entity again
370 : : we can reuse this copy. Do this early because remap_type may
371 : : need this decl for TYPE_STUB_DECL. */
372 : 79861564 : insert_decl_map (id, decl, t);
373 : :
374 : 79861564 : if (!DECL_P (t) || t == decl)
375 : : return t;
376 : :
377 : : /* Remap types, if necessary. */
378 : 78369893 : TREE_TYPE (t) = remap_type (TREE_TYPE (t), id);
379 : 78369893 : if (TREE_CODE (t) == TYPE_DECL)
380 : : {
381 : 1316141 : DECL_ORIGINAL_TYPE (t) = remap_type (DECL_ORIGINAL_TYPE (t), id);
382 : :
383 : : /* Preserve the invariant that DECL_ORIGINAL_TYPE != TREE_TYPE,
384 : : which is enforced in gen_typedef_die when DECL_ABSTRACT_ORIGIN
385 : : is not set on the TYPE_DECL, for example in LTO mode. */
386 : 1316141 : if (DECL_ORIGINAL_TYPE (t) == TREE_TYPE (t))
387 : : {
388 : 10 : tree x = build_variant_type_copy (TREE_TYPE (t));
389 : 10 : TYPE_STUB_DECL (x) = TYPE_STUB_DECL (TREE_TYPE (t));
390 : 10 : TYPE_NAME (x) = TYPE_NAME (TREE_TYPE (t));
391 : 10 : DECL_ORIGINAL_TYPE (t) = x;
392 : : }
393 : : }
394 : :
395 : : /* Remap sizes as necessary. */
396 : 78369893 : walk_tree (&DECL_SIZE (t), copy_tree_body_r, id, NULL);
397 : 78369893 : walk_tree (&DECL_SIZE_UNIT (t), copy_tree_body_r, id, NULL);
398 : :
399 : : /* If fields, do likewise for offset and qualifier. */
400 : 78369893 : if (TREE_CODE (t) == FIELD_DECL)
401 : : {
402 : 764 : walk_tree (&DECL_FIELD_OFFSET (t), copy_tree_body_r, id, NULL);
403 : 764 : if (TREE_CODE (DECL_CONTEXT (t)) == QUAL_UNION_TYPE)
404 : 0 : walk_tree (&DECL_QUALIFIER (t), copy_tree_body_r, id, NULL);
405 : : }
406 : :
407 : 78369893 : return t;
408 : : }
409 : :
410 : 146886470 : if (id->do_not_unshare)
411 : 70545413 : return *n;
412 : : else
413 : 76341057 : return unshare_expr (*n);
414 : : }
415 : :
416 : : static tree
417 : 98125 : remap_type_1 (tree type, copy_body_data *id)
418 : : {
419 : 98125 : tree new_tree, t;
420 : :
421 : : /* We do need a copy. build and register it now. If this is a pointer or
422 : : reference type, remap the designated type and make a new pointer or
423 : : reference type. */
424 : 98125 : if (TREE_CODE (type) == POINTER_TYPE)
425 : : {
426 : 27062 : new_tree = build_pointer_type_for_mode (remap_type (TREE_TYPE (type), id),
427 : 27062 : TYPE_MODE (type),
428 : 27062 : TYPE_REF_CAN_ALIAS_ALL (type));
429 : 27062 : if (TYPE_ATTRIBUTES (type) || TYPE_QUALS (type))
430 : 14339 : new_tree = build_type_attribute_qual_variant (new_tree,
431 : 14339 : TYPE_ATTRIBUTES (type),
432 : 14339 : TYPE_QUALS (type));
433 : 27062 : insert_decl_map (id, type, new_tree);
434 : 27062 : return new_tree;
435 : : }
436 : 71063 : else if (TREE_CODE (type) == REFERENCE_TYPE)
437 : : {
438 : 7669 : new_tree = build_reference_type_for_mode (remap_type (TREE_TYPE (type), id),
439 : 7669 : TYPE_MODE (type),
440 : 7669 : TYPE_REF_CAN_ALIAS_ALL (type));
441 : 7669 : if (TYPE_ATTRIBUTES (type) || TYPE_QUALS (type))
442 : 5336 : new_tree = build_type_attribute_qual_variant (new_tree,
443 : 5336 : TYPE_ATTRIBUTES (type),
444 : 5336 : TYPE_QUALS (type));
445 : 7669 : insert_decl_map (id, type, new_tree);
446 : 7669 : return new_tree;
447 : : }
448 : : else
449 : 63394 : new_tree = copy_node (type);
450 : :
451 : 63394 : insert_decl_map (id, type, new_tree);
452 : :
453 : : /* This is a new type, not a copy of an old type. Need to reassociate
454 : : variants. We can handle everything except the main variant lazily. */
455 : 63394 : t = TYPE_MAIN_VARIANT (type);
456 : 63394 : if (type != t)
457 : : {
458 : 78 : t = remap_type (t, id);
459 : 78 : TYPE_MAIN_VARIANT (new_tree) = t;
460 : 78 : TYPE_NEXT_VARIANT (new_tree) = TYPE_NEXT_VARIANT (t);
461 : 78 : TYPE_NEXT_VARIANT (t) = new_tree;
462 : : }
463 : : else
464 : : {
465 : 63316 : TYPE_MAIN_VARIANT (new_tree) = new_tree;
466 : 63316 : TYPE_NEXT_VARIANT (new_tree) = NULL;
467 : : }
468 : :
469 : 63394 : if (TYPE_STUB_DECL (type))
470 : 177 : TYPE_STUB_DECL (new_tree) = remap_decl (TYPE_STUB_DECL (type), id);
471 : :
472 : : /* Lazily create pointer and reference types. */
473 : 63394 : TYPE_POINTER_TO (new_tree) = NULL;
474 : 63394 : TYPE_REFERENCE_TO (new_tree) = NULL;
475 : :
476 : : /* Copy all types that may contain references to local variables; be sure to
477 : : preserve sharing in between type and its main variant when possible. */
478 : 63394 : switch (TREE_CODE (new_tree))
479 : : {
480 : 30381 : case INTEGER_TYPE:
481 : 30381 : case REAL_TYPE:
482 : 30381 : case FIXED_POINT_TYPE:
483 : 30381 : case ENUMERAL_TYPE:
484 : 30381 : case BOOLEAN_TYPE:
485 : 30381 : if (TYPE_MAIN_VARIANT (new_tree) != new_tree)
486 : : {
487 : 0 : gcc_checking_assert (TYPE_MIN_VALUE (type) == TYPE_MIN_VALUE (TYPE_MAIN_VARIANT (type)));
488 : 0 : gcc_checking_assert (TYPE_MAX_VALUE (type) == TYPE_MAX_VALUE (TYPE_MAIN_VARIANT (type)));
489 : :
490 : 0 : TYPE_MIN_VALUE (new_tree) = TYPE_MIN_VALUE (TYPE_MAIN_VARIANT (new_tree));
491 : 0 : TYPE_MAX_VALUE (new_tree) = TYPE_MAX_VALUE (TYPE_MAIN_VARIANT (new_tree));
492 : : }
493 : : else
494 : : {
495 : 30381 : t = TYPE_MIN_VALUE (new_tree);
496 : 30381 : if (t && TREE_CODE (t) != INTEGER_CST)
497 : 0 : walk_tree (&TYPE_MIN_VALUE (new_tree), copy_tree_body_r, id, NULL);
498 : :
499 : 30381 : t = TYPE_MAX_VALUE (new_tree);
500 : 30381 : if (t && TREE_CODE (t) != INTEGER_CST)
501 : 30381 : walk_tree (&TYPE_MAX_VALUE (new_tree), copy_tree_body_r, id, NULL);
502 : : }
503 : : return new_tree;
504 : :
505 : 16 : case FUNCTION_TYPE:
506 : 16 : if (TYPE_MAIN_VARIANT (new_tree) != new_tree
507 : 16 : && TREE_TYPE (type) == TREE_TYPE (TYPE_MAIN_VARIANT (type)))
508 : 0 : TREE_TYPE (new_tree) = TREE_TYPE (TYPE_MAIN_VARIANT (new_tree));
509 : : else
510 : 16 : TREE_TYPE (new_tree) = remap_type (TREE_TYPE (new_tree), id);
511 : 16 : if (TYPE_MAIN_VARIANT (new_tree) != new_tree
512 : 16 : && TYPE_ARG_TYPES (type) == TYPE_ARG_TYPES (TYPE_MAIN_VARIANT (type)))
513 : 0 : TYPE_ARG_TYPES (new_tree) = TYPE_ARG_TYPES (TYPE_MAIN_VARIANT (new_tree));
514 : : else
515 : 16 : walk_tree (&TYPE_ARG_TYPES (new_tree), copy_tree_body_r, id, NULL);
516 : : return new_tree;
517 : :
518 : 32771 : case ARRAY_TYPE:
519 : 32771 : if (TYPE_MAIN_VARIANT (new_tree) != new_tree
520 : 32771 : && TREE_TYPE (type) == TREE_TYPE (TYPE_MAIN_VARIANT (type)))
521 : 28 : TREE_TYPE (new_tree) = TREE_TYPE (TYPE_MAIN_VARIANT (new_tree));
522 : : else
523 : 32743 : TREE_TYPE (new_tree) = remap_type (TREE_TYPE (new_tree), id);
524 : :
525 : 32771 : if (TYPE_MAIN_VARIANT (new_tree) != new_tree)
526 : : {
527 : 61 : gcc_checking_assert (TYPE_DOMAIN (type)
528 : : == TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)));
529 : 61 : TYPE_DOMAIN (new_tree) = TYPE_DOMAIN (TYPE_MAIN_VARIANT (new_tree));
530 : : }
531 : : else
532 : : {
533 : 32710 : TYPE_DOMAIN (new_tree) = remap_type (TYPE_DOMAIN (new_tree), id);
534 : : /* For array bounds where we have decided not to copy over the bounds
535 : : variable which isn't used in OpenMP/OpenACC region, change them to
536 : : an uninitialized VAR_DECL temporary. */
537 : 32710 : if (id->adjust_array_error_bounds
538 : 3634 : && TYPE_DOMAIN (new_tree)
539 : 3634 : && TYPE_MAX_VALUE (TYPE_DOMAIN (new_tree)) == error_mark_node
540 : 35589 : && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != error_mark_node)
541 : : {
542 : 2879 : tree v = create_tmp_var (TREE_TYPE (TYPE_DOMAIN (new_tree)));
543 : 2879 : DECL_ATTRIBUTES (v)
544 : 2879 : = tree_cons (get_identifier ("omp dummy var"), NULL_TREE,
545 : 2879 : DECL_ATTRIBUTES (v));
546 : 2879 : TYPE_MAX_VALUE (TYPE_DOMAIN (new_tree)) = v;
547 : : }
548 : : }
549 : : break;
550 : :
551 : 226 : case RECORD_TYPE:
552 : 226 : case UNION_TYPE:
553 : 226 : case QUAL_UNION_TYPE:
554 : 226 : if (TYPE_MAIN_VARIANT (type) != type
555 : 226 : && TYPE_FIELDS (type) == TYPE_FIELDS (TYPE_MAIN_VARIANT (type)))
556 : 17 : TYPE_FIELDS (new_tree) = TYPE_FIELDS (TYPE_MAIN_VARIANT (new_tree));
557 : : else
558 : : {
559 : 209 : tree f, nf = NULL;
560 : :
561 : 973 : for (f = TYPE_FIELDS (new_tree); f ; f = DECL_CHAIN (f))
562 : : {
563 : 764 : t = remap_decl (f, id);
564 : 764 : DECL_CONTEXT (t) = new_tree;
565 : 764 : DECL_CHAIN (t) = nf;
566 : 764 : nf = t;
567 : : }
568 : 209 : TYPE_FIELDS (new_tree) = nreverse (nf);
569 : : }
570 : : break;
571 : :
572 : 0 : case OFFSET_TYPE:
573 : 0 : default:
574 : : /* Shouldn't have been thought variable sized. */
575 : 0 : gcc_unreachable ();
576 : : }
577 : :
578 : : /* All variants of type share the same size, so use the already remaped data. */
579 : 32997 : if (TYPE_MAIN_VARIANT (new_tree) != new_tree)
580 : : {
581 : 78 : tree s = TYPE_SIZE (type);
582 : 78 : tree mvs = TYPE_SIZE (TYPE_MAIN_VARIANT (type));
583 : 78 : tree su = TYPE_SIZE_UNIT (type);
584 : 78 : tree mvsu = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (type));
585 : 78 : gcc_checking_assert ((TREE_CODE (s) == PLACEHOLDER_EXPR
586 : : && (TREE_CODE (mvs) == PLACEHOLDER_EXPR))
587 : : || s == mvs);
588 : 78 : gcc_checking_assert ((TREE_CODE (su) == PLACEHOLDER_EXPR
589 : : && (TREE_CODE (mvsu) == PLACEHOLDER_EXPR))
590 : : || su == mvsu);
591 : 78 : TYPE_SIZE (new_tree) = TYPE_SIZE (TYPE_MAIN_VARIANT (new_tree));
592 : 78 : TYPE_SIZE_UNIT (new_tree) = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (new_tree));
593 : : }
594 : : else
595 : : {
596 : 32919 : walk_tree (&TYPE_SIZE (new_tree), copy_tree_body_r, id, NULL);
597 : 32919 : walk_tree (&TYPE_SIZE_UNIT (new_tree), copy_tree_body_r, id, NULL);
598 : : }
599 : :
600 : : return new_tree;
601 : : }
602 : :
603 : : /* Helper function for remap_type_2, called through walk_tree. */
604 : :
605 : : static tree
606 : 30303 : remap_type_3 (tree *tp, int *walk_subtrees, void *data)
607 : : {
608 : 30303 : copy_body_data *id = (copy_body_data *) data;
609 : :
610 : 30303 : if (TYPE_P (*tp))
611 : 0 : *walk_subtrees = 0;
612 : :
613 : 30303 : else if (DECL_P (*tp) && remap_decl (*tp, id) != *tp)
614 : : return *tp;
615 : :
616 : : return NULL_TREE;
617 : : }
618 : :
619 : : /* Return true if TYPE needs to be remapped because remap_decl on any
620 : : needed embedded decl returns something other than that decl. */
621 : :
622 : : static bool
623 : 50694 : remap_type_2 (tree type, copy_body_data *id)
624 : : {
625 : 61109 : tree t;
626 : :
627 : : #define RETURN_TRUE_IF_VAR(T) \
628 : : do \
629 : : { \
630 : : tree _t = (T); \
631 : : if (_t) \
632 : : { \
633 : : if (DECL_P (_t) && remap_decl (_t, id) != _t) \
634 : : return true; \
635 : : if (!TYPE_SIZES_GIMPLIFIED (type) \
636 : : && walk_tree (&_t, remap_type_3, id, NULL)) \
637 : : return true; \
638 : : } \
639 : : } \
640 : : while (0)
641 : :
642 : 61109 : switch (TREE_CODE (type))
643 : : {
644 : 10415 : case POINTER_TYPE:
645 : 10415 : case REFERENCE_TYPE:
646 : 10415 : case FUNCTION_TYPE:
647 : 10415 : case METHOD_TYPE:
648 : 10415 : return remap_type_2 (TREE_TYPE (type), id);
649 : :
650 : 34086 : case INTEGER_TYPE:
651 : 34086 : case REAL_TYPE:
652 : 34086 : case FIXED_POINT_TYPE:
653 : 34086 : case ENUMERAL_TYPE:
654 : 34086 : case BOOLEAN_TYPE:
655 : 34086 : RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
656 : 34086 : RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
657 : 22366 : return false;
658 : :
659 : 16137 : case ARRAY_TYPE:
660 : 16137 : if (remap_type_2 (TREE_TYPE (type), id)
661 : 31660 : || (TYPE_DOMAIN (type) && remap_type_2 (TYPE_DOMAIN (type), id)))
662 : 8940 : return true;
663 : : break;
664 : :
665 : 357 : case RECORD_TYPE:
666 : 357 : case UNION_TYPE:
667 : 357 : case QUAL_UNION_TYPE:
668 : 3561 : for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t))
669 : 3204 : if (TREE_CODE (t) == FIELD_DECL)
670 : : {
671 : 1242 : RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
672 : 1242 : RETURN_TRUE_IF_VAR (DECL_SIZE (t));
673 : 1242 : RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
674 : 1242 : if (TREE_CODE (type) == QUAL_UNION_TYPE)
675 : 0 : RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
676 : : }
677 : : break;
678 : :
679 : : default:
680 : : return false;
681 : : }
682 : :
683 : 7554 : RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
684 : 7545 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type));
685 : 6942 : return false;
686 : : #undef RETURN_TRUE_IF_VAR
687 : : }
688 : :
689 : : tree
690 : 898422826 : remap_type (tree type, copy_body_data *id)
691 : : {
692 : 898422826 : tree *node;
693 : 898422826 : tree tmp;
694 : :
695 : 898422826 : if (type == NULL)
696 : : return type;
697 : :
698 : : /* See if we have remapped this type. */
699 : 898293745 : node = id->decl_map->get (type);
700 : 898293745 : if (node)
701 : 594105877 : return *node;
702 : :
703 : : /* The type only needs remapping if it's variably modified. */
704 : 304187868 : if (! variably_modified_type_p (type, id->src_fn)
705 : : /* Don't remap if copy_decl method doesn't always return a new
706 : : decl and for all embedded decls returns the passed in decl. */
707 : 304187868 : || (id->dont_remap_vla_if_no_change && !remap_type_2 (type, id)))
708 : : {
709 : 304089805 : insert_decl_map (id, type, type);
710 : 304089805 : return type;
711 : : }
712 : :
713 : 98063 : id->remapping_type_depth++;
714 : 98063 : tmp = remap_type_1 (type, id);
715 : 98063 : id->remapping_type_depth--;
716 : :
717 : 98063 : return tmp;
718 : : }
719 : :
720 : : /* Decide if DECL can be put into BLOCK_NONLOCAL_VARs. */
721 : :
722 : : static bool
723 : 36435217 : can_be_nonlocal (tree decl, copy_body_data *id)
724 : : {
725 : : /* We cannot duplicate function decls. */
726 : 36435217 : if (TREE_CODE (decl) == FUNCTION_DECL)
727 : : return true;
728 : :
729 : : /* Local static vars must be non-local or we get multiple declaration
730 : : problems. */
731 : 36417526 : if (VAR_P (decl) && !auto_var_in_fn_p (decl, id->src_fn))
732 : : return true;
733 : :
734 : : return false;
735 : : }
736 : :
737 : : static tree
738 : 40853318 : remap_decls (tree decls, vec<tree, va_gc> **nonlocalized_list,
739 : : copy_body_data *id)
740 : : {
741 : 40853318 : tree old_var;
742 : 40853318 : tree new_decls = NULL_TREE;
743 : :
744 : : /* Remap its variables. */
745 : 73229259 : for (old_var = decls; old_var; old_var = DECL_CHAIN (old_var))
746 : : {
747 : 32375941 : tree new_var;
748 : :
749 : 32375941 : if (can_be_nonlocal (old_var, id))
750 : : {
751 : : /* We need to add this variable to the local decls as otherwise
752 : : nothing else will do so. */
753 : 104564 : if (VAR_P (old_var) && ! DECL_EXTERNAL (old_var) && cfun)
754 : 86784 : add_local_decl (cfun, old_var);
755 : 85002 : if ((!optimize || debug_info_level > DINFO_LEVEL_TERSE)
756 : 78901 : && !DECL_IGNORED_P (old_var)
757 : 183395 : && nonlocalized_list)
758 : 57676 : vec_safe_push (*nonlocalized_list, old_var);
759 : 104564 : continue;
760 : : }
761 : :
762 : : /* Remap the variable. */
763 : 32271377 : new_var = remap_decl (old_var, id);
764 : :
765 : : /* If we didn't remap this variable, we can't mess with its
766 : : TREE_CHAIN. If we remapped this variable to the return slot, it's
767 : : already declared somewhere else, so don't declare it here. */
768 : :
769 : 32271377 : if (new_var == old_var || new_var == id->retvar)
770 : : ;
771 : 29722635 : else if (!new_var)
772 : : {
773 : 0 : if ((!optimize || debug_info_level > DINFO_LEVEL_TERSE)
774 : 0 : && !DECL_IGNORED_P (old_var)
775 : 0 : && nonlocalized_list)
776 : 0 : vec_safe_push (*nonlocalized_list, old_var);
777 : : }
778 : : else
779 : : {
780 : 29722635 : gcc_assert (DECL_P (new_var));
781 : 29722635 : DECL_CHAIN (new_var) = new_decls;
782 : 29722635 : new_decls = new_var;
783 : :
784 : : /* Also copy value-expressions. */
785 : 29722635 : if (VAR_P (new_var) && DECL_HAS_VALUE_EXPR_P (new_var))
786 : : {
787 : 1071934 : tree tem = DECL_VALUE_EXPR (new_var);
788 : 1071934 : bool old_regimplify = id->regimplify;
789 : 1071934 : id->remapping_type_depth++;
790 : 1071934 : walk_tree (&tem, copy_tree_body_r, id, NULL);
791 : 1071934 : id->remapping_type_depth--;
792 : 1071934 : id->regimplify = old_regimplify;
793 : 1071934 : SET_DECL_VALUE_EXPR (new_var, tem);
794 : : }
795 : : }
796 : : }
797 : :
798 : 40853318 : return nreverse (new_decls);
799 : : }
800 : :
801 : : /* Copy the BLOCK to contain remapped versions of the variables
802 : : therein. And hook the new block into the block-tree. */
803 : :
804 : : static void
805 : 38220330 : remap_block (tree *block, copy_body_data *id)
806 : : {
807 : 38220330 : tree old_block;
808 : 38220330 : tree new_block;
809 : :
810 : : /* Make the new block. */
811 : 38220330 : old_block = *block;
812 : 38220330 : new_block = make_node (BLOCK);
813 : 38220330 : TREE_USED (new_block) = TREE_USED (old_block);
814 : 38220330 : BLOCK_ABSTRACT_ORIGIN (new_block) = BLOCK_ORIGIN (old_block);
815 : 38220330 : BLOCK_SOURCE_LOCATION (new_block) = BLOCK_SOURCE_LOCATION (old_block);
816 : 38220330 : BLOCK_NONLOCALIZED_VARS (new_block)
817 : 38287149 : = vec_safe_copy (BLOCK_NONLOCALIZED_VARS (old_block));
818 : 38220330 : *block = new_block;
819 : :
820 : : /* Remap its variables. */
821 : 76440660 : BLOCK_VARS (new_block) = remap_decls (BLOCK_VARS (old_block),
822 : 38220330 : &BLOCK_NONLOCALIZED_VARS (new_block),
823 : : id);
824 : :
825 : : /* Remember the remapped block. */
826 : 38220330 : insert_decl_map (id, old_block, new_block);
827 : 38220330 : }
828 : :
829 : : /* Copy the whole block tree and root it in id->block. */
830 : :
831 : : static tree
832 : 24998467 : remap_blocks (tree block, copy_body_data *id)
833 : : {
834 : 24998467 : tree t;
835 : 24998467 : tree new_tree = block;
836 : :
837 : 24998467 : if (!block)
838 : : return NULL;
839 : :
840 : 24998467 : remap_block (&new_tree, id);
841 : 24998467 : gcc_assert (new_tree != block);
842 : 45225361 : for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t))
843 : 20226894 : prepend_lexical_block (new_tree, remap_blocks (t, id));
844 : : /* Blocks are in arbitrary order, but make things slightly prettier and do
845 : : not swap order when producing a copy. */
846 : 24998467 : BLOCK_SUBBLOCKS (new_tree) = blocks_nreverse (BLOCK_SUBBLOCKS (new_tree));
847 : 24998467 : return new_tree;
848 : : }
849 : :
850 : : /* Remap the block tree rooted at BLOCK to nothing. */
851 : :
852 : : static void
853 : 77764 : remap_blocks_to_null (tree block, copy_body_data *id)
854 : : {
855 : 77764 : tree t;
856 : 77764 : insert_decl_map (id, block, NULL_TREE);
857 : 127001 : for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t))
858 : 49237 : remap_blocks_to_null (t, id);
859 : 77764 : }
860 : :
861 : : /* Remap the location info pointed to by LOCUS. */
862 : :
863 : : static location_t
864 : 25117747 : remap_location (location_t locus, copy_body_data *id)
865 : : {
866 : 25117747 : if (LOCATION_BLOCK (locus))
867 : : {
868 : 10499101 : tree *n = id->decl_map->get (LOCATION_BLOCK (locus));
869 : 10499101 : gcc_assert (n);
870 : 10499101 : if (*n)
871 : 10462036 : return set_block (locus, *n);
872 : : }
873 : :
874 : 14655711 : locus = LOCATION_LOCUS (locus);
875 : :
876 : 14655711 : if (locus != UNKNOWN_LOCATION && id->block)
877 : 24 : return set_block (locus, id->block);
878 : :
879 : : return locus;
880 : : }
881 : :
882 : : static void
883 : 30099459 : copy_statement_list (tree *tp)
884 : : {
885 : 30099459 : tree_stmt_iterator oi, ni;
886 : 30099459 : tree new_tree;
887 : :
888 : 30099459 : new_tree = alloc_stmt_list ();
889 : 30099459 : ni = tsi_start (new_tree);
890 : 30099459 : oi = tsi_start (*tp);
891 : 30099459 : TREE_TYPE (new_tree) = TREE_TYPE (*tp);
892 : 30099459 : *tp = new_tree;
893 : :
894 : 92656340 : for (; !tsi_end_p (oi); tsi_next (&oi))
895 : : {
896 : 62556881 : tree stmt = tsi_stmt (oi);
897 : 62556881 : if (TREE_CODE (stmt) == STATEMENT_LIST)
898 : : /* This copy is not redundant; tsi_link_after will smash this
899 : : STATEMENT_LIST into the end of the one we're building, and we
900 : : don't want to do that with the original. */
901 : 48298 : copy_statement_list (&stmt);
902 : 62556881 : tsi_link_after (&ni, stmt, TSI_CONTINUE_LINKING);
903 : : }
904 : 30099459 : }
905 : :
906 : : static void
907 : 13222041 : copy_bind_expr (tree *tp, int *walk_subtrees, copy_body_data *id)
908 : : {
909 : 13222041 : tree block = BIND_EXPR_BLOCK (*tp);
910 : : /* Copy (and replace) the statement. */
911 : 13222041 : copy_tree_r (tp, walk_subtrees, NULL);
912 : 13222041 : if (block)
913 : : {
914 : 13221576 : remap_block (&block, id);
915 : 13221576 : BIND_EXPR_BLOCK (*tp) = block;
916 : : }
917 : :
918 : 13222041 : if (BIND_EXPR_VARS (*tp))
919 : : /* This will remap a lot of the same decls again, but this should be
920 : : harmless. */
921 : 2632820 : BIND_EXPR_VARS (*tp) = remap_decls (BIND_EXPR_VARS (*tp), NULL, id);
922 : 13222041 : }
923 : :
924 : :
925 : : /* Create a new gimple_seq by remapping all the statements in BODY
926 : : using the inlining information in ID. */
927 : :
928 : : static gimple_seq
929 : 67 : remap_gimple_seq (gimple_seq body, copy_body_data *id)
930 : : {
931 : 67 : gimple_stmt_iterator si;
932 : 67 : gimple_seq new_body = NULL;
933 : :
934 : 67 : for (si = gsi_start (body); !gsi_end_p (si); gsi_next (&si))
935 : : {
936 : 0 : gimple_seq new_stmts = remap_gimple_stmt (gsi_stmt (si), id);
937 : 0 : gimple_seq_add_seq (&new_body, new_stmts);
938 : : }
939 : :
940 : 67 : return new_body;
941 : : }
942 : :
943 : :
944 : : /* Copy a GIMPLE_BIND statement STMT, remapping all the symbols in its
945 : : block using the mapping information in ID. */
946 : :
947 : : static gimple *
948 : 0 : copy_gimple_bind (gbind *stmt, copy_body_data *id)
949 : : {
950 : 0 : gimple *new_bind;
951 : 0 : tree new_block, new_vars;
952 : 0 : gimple_seq body, new_body;
953 : :
954 : : /* Copy the statement. Note that we purposely don't use copy_stmt
955 : : here because we need to remap statements as we copy. */
956 : 0 : body = gimple_bind_body (stmt);
957 : 0 : new_body = remap_gimple_seq (body, id);
958 : :
959 : 0 : new_block = gimple_bind_block (stmt);
960 : 0 : if (new_block)
961 : 0 : remap_block (&new_block, id);
962 : :
963 : : /* This will remap a lot of the same decls again, but this should be
964 : : harmless. */
965 : 0 : new_vars = gimple_bind_vars (stmt);
966 : 0 : if (new_vars)
967 : 0 : new_vars = remap_decls (new_vars, NULL, id);
968 : :
969 : 0 : new_bind = gimple_build_bind (new_vars, new_body, new_block);
970 : :
971 : 0 : return new_bind;
972 : : }
973 : :
974 : : /* Return true if DECL is a parameter or a SSA_NAME for a parameter. */
975 : :
976 : : static bool
977 : 30066 : is_parm (tree decl)
978 : : {
979 : 30066 : if (TREE_CODE (decl) == SSA_NAME)
980 : : {
981 : 28363 : decl = SSA_NAME_VAR (decl);
982 : : if (!decl)
983 : : return false;
984 : : }
985 : :
986 : 17549 : return (TREE_CODE (decl) == PARM_DECL);
987 : : }
988 : :
989 : : /* Copy the TREE_THIS_NOTRAP flag from OLD to T if it is appropriate to do so.
990 : : T and OLD must be both either INDIRECT_REF or MEM_REF. */
991 : :
992 : : static void
993 : 19772910 : maybe_copy_this_notrap (copy_body_data *id, tree t, tree old)
994 : : {
995 : 19772910 : gcc_assert (TREE_CODE (t) == TREE_CODE (old));
996 : :
997 : : /* We cannot blindly propagate the TREE_THIS_NOTRAP flag if we have remapped
998 : : a parameter as the property might be valid only for the parameter itself,
999 : : typically when it is passed by reference. But we propagate the flag when
1000 : : this is the dereference of an entire object done in a type that has self-
1001 : : referential size, to avoid the static size check in tree_could_trap_p. */
1002 : 19772910 : if (TREE_THIS_NOTRAP (old)
1003 : 19772910 : && (!is_parm (TREE_OPERAND (old, 0))
1004 : 12460 : || (!id->transform_parameter && is_parm (TREE_OPERAND (t, 0)))
1005 : 9469 : || ((TREE_CODE (t) == INDIRECT_REF
1006 : 9469 : || integer_zerop (TREE_OPERAND (t, 1)))
1007 : 9469 : && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR
1008 : 8804 : && DECL_P (TREE_OPERAND (TREE_OPERAND (t, 0), 0))
1009 : 8804 : && type_contains_placeholder_p (TREE_TYPE (t)))))
1010 : 17606 : TREE_THIS_NOTRAP (t) = 1;
1011 : 19772910 : }
1012 : :
1013 : : /* Remap the dependence CLIQUE from the source to the destination function
1014 : : as specified in ID. */
1015 : :
1016 : : static unsigned short
1017 : 3759617 : remap_dependence_clique (copy_body_data *id, unsigned short clique)
1018 : : {
1019 : 3759617 : if (clique == 0 || processing_debug_stmt)
1020 : : return 0;
1021 : 3723410 : if (!id->dependence_map)
1022 : 774452 : id->dependence_map = new hash_map<dependence_hash, unsigned short>;
1023 : 3723410 : bool existed;
1024 : 3723410 : unsigned short &newc = id->dependence_map->get_or_insert (clique, &existed);
1025 : 3723410 : if (!existed)
1026 : : {
1027 : : /* Clique 1 is reserved for local ones set by PTA. */
1028 : 1231004 : if (cfun->last_clique == 0)
1029 : 350999 : cfun->last_clique = 1;
1030 : 2462008 : newc = get_new_clique (cfun);
1031 : : }
1032 : 3723410 : return newc;
1033 : : }
1034 : :
1035 : : /* Remap the GIMPLE operand pointed to by *TP. DATA is really a
1036 : : 'struct walk_stmt_info *'. DATA->INFO is a 'copy_body_data *'.
1037 : : WALK_SUBTREES is used to indicate walk_gimple_op whether to keep
1038 : : recursing into the children nodes of *TP. */
1039 : :
1040 : : static tree
1041 : 193349464 : remap_gimple_op_r (tree *tp, int *walk_subtrees, void *data)
1042 : : {
1043 : 193349464 : struct walk_stmt_info *wi_p = (struct walk_stmt_info *) data;
1044 : 193349464 : copy_body_data *id = (copy_body_data *) wi_p->info;
1045 : 193349464 : tree fn = id->src_fn;
1046 : :
1047 : : /* For recursive invocations this is no longer the LHS itself. */
1048 : 193349464 : bool is_lhs = wi_p->is_lhs;
1049 : 193349464 : wi_p->is_lhs = false;
1050 : :
1051 : 193349464 : if (TREE_CODE (*tp) == SSA_NAME)
1052 : : {
1053 : 63403721 : *tp = remap_ssa_name (*tp, id);
1054 : 63403721 : *walk_subtrees = 0;
1055 : 63403721 : if (is_lhs)
1056 : 15791261 : SSA_NAME_DEF_STMT (*tp) = wi_p->stmt;
1057 : 63403721 : return NULL;
1058 : : }
1059 : 129945743 : else if (auto_var_in_fn_p (*tp, fn))
1060 : : {
1061 : : /* Local variables and labels need to be replaced by equivalent
1062 : : variables. We don't want to copy static variables; there's
1063 : : only one of those, no matter how many times we inline the
1064 : : containing function. Similarly for globals from an outer
1065 : : function. */
1066 : 41239997 : tree new_decl;
1067 : :
1068 : : /* Remap the declaration. */
1069 : 41239997 : new_decl = remap_decl (*tp, id);
1070 : 41239997 : gcc_assert (new_decl);
1071 : : /* Replace this variable with the copy. */
1072 : 41239997 : STRIP_TYPE_NOPS (new_decl);
1073 : : /* ??? The C++ frontend uses void * pointer zero to initialize
1074 : : any other type. This confuses the middle-end type verification.
1075 : : As cloned bodies do not go through gimplification again the fixup
1076 : : there doesn't trigger. */
1077 : 41239997 : if (TREE_CODE (new_decl) == INTEGER_CST
1078 : 41239997 : && !useless_type_conversion_p (TREE_TYPE (*tp), TREE_TYPE (new_decl)))
1079 : 0 : new_decl = fold_convert (TREE_TYPE (*tp), new_decl);
1080 : 41239997 : *tp = new_decl;
1081 : 41239997 : *walk_subtrees = 0;
1082 : : }
1083 : 88705746 : else if (TREE_CODE (*tp) == STATEMENT_LIST)
1084 : 0 : gcc_unreachable ();
1085 : 88705746 : else if (TREE_CODE (*tp) == SAVE_EXPR)
1086 : 0 : gcc_unreachable ();
1087 : 88705746 : else if (TREE_CODE (*tp) == LABEL_DECL
1088 : 88705746 : && (!DECL_CONTEXT (*tp)
1089 : 441 : || decl_function_context (*tp) == id->src_fn))
1090 : : /* These may need to be remapped for EH handling. */
1091 : 0 : *tp = remap_decl (*tp, id);
1092 : 88705746 : else if (TREE_CODE (*tp) == FIELD_DECL)
1093 : : {
1094 : : /* If the enclosing record type is variably_modified_type_p, the field
1095 : : has already been remapped. Otherwise, it need not be. */
1096 : 15529756 : tree *n = id->decl_map->get (*tp);
1097 : 15529756 : if (n)
1098 : 71 : *tp = *n;
1099 : 15529756 : *walk_subtrees = 0;
1100 : : }
1101 : 73175990 : else if (TYPE_P (*tp))
1102 : : /* Types may need remapping as well. */
1103 : 0 : *tp = remap_type (*tp, id);
1104 : 73175990 : else if (CONSTANT_CLASS_P (*tp))
1105 : : {
1106 : : /* If this is a constant, we have to copy the node iff the type
1107 : : will be remapped. copy_tree_r will not copy a constant. */
1108 : 11235774 : tree new_type = remap_type (TREE_TYPE (*tp), id);
1109 : :
1110 : 11235774 : if (new_type == TREE_TYPE (*tp))
1111 : 11231919 : *walk_subtrees = 0;
1112 : :
1113 : 3855 : else if (TREE_CODE (*tp) == INTEGER_CST)
1114 : 3855 : *tp = wide_int_to_tree (new_type, wi::to_wide (*tp));
1115 : : else
1116 : : {
1117 : 0 : *tp = copy_node (*tp);
1118 : 0 : TREE_TYPE (*tp) = new_type;
1119 : : }
1120 : : }
1121 : : else
1122 : : {
1123 : : /* Otherwise, just copy the node. Note that copy_tree_r already
1124 : : knows not to copy VAR_DECLs, etc., so this is safe. */
1125 : :
1126 : 61940216 : if (TREE_CODE (*tp) == MEM_REF && !id->do_not_fold)
1127 : : {
1128 : : /* We need to re-canonicalize MEM_REFs from inline substitutions
1129 : : that can happen when a pointer argument is an ADDR_EXPR.
1130 : : Recurse here manually to allow that. */
1131 : 14549387 : tree ptr = TREE_OPERAND (*tp, 0);
1132 : 14549387 : tree type = remap_type (TREE_TYPE (*tp), id);
1133 : 14549387 : tree old = *tp;
1134 : 14549387 : walk_tree (&ptr, remap_gimple_op_r, data, NULL);
1135 : 14549387 : *tp = fold_build2 (MEM_REF, type, ptr, TREE_OPERAND (*tp, 1));
1136 : 14549387 : TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old);
1137 : 14549387 : TREE_SIDE_EFFECTS (*tp) = TREE_SIDE_EFFECTS (old);
1138 : 14549387 : copy_warning (*tp, old);
1139 : 14549387 : if (MR_DEPENDENCE_CLIQUE (old) != 0)
1140 : : {
1141 : 3681971 : MR_DEPENDENCE_CLIQUE (*tp)
1142 : 3681971 : = remap_dependence_clique (id, MR_DEPENDENCE_CLIQUE (old));
1143 : 3681971 : MR_DEPENDENCE_BASE (*tp) = MR_DEPENDENCE_BASE (old);
1144 : : }
1145 : 14549387 : maybe_copy_this_notrap (id, *tp, old);
1146 : 14549387 : REF_REVERSE_STORAGE_ORDER (*tp) = REF_REVERSE_STORAGE_ORDER (old);
1147 : 14549387 : *walk_subtrees = 0;
1148 : 14549387 : return NULL;
1149 : : }
1150 : :
1151 : : /* Here is the "usual case". Copy this tree node, and then
1152 : : tweak some special cases. */
1153 : 47390829 : copy_tree_r (tp, walk_subtrees, NULL);
1154 : :
1155 : 47390829 : if (TREE_CODE (*tp) != OMP_CLAUSE)
1156 : 47390829 : TREE_TYPE (*tp) = remap_type (TREE_TYPE (*tp), id);
1157 : :
1158 : 47390829 : if (TREE_CODE (*tp) == TARGET_EXPR && TREE_OPERAND (*tp, 3))
1159 : : {
1160 : : /* The copied TARGET_EXPR has never been expanded, even if the
1161 : : original node was expanded already. */
1162 : 0 : TREE_OPERAND (*tp, 1) = TREE_OPERAND (*tp, 3);
1163 : 0 : TREE_OPERAND (*tp, 3) = NULL_TREE;
1164 : : }
1165 : 47390829 : else if (TREE_CODE (*tp) == ADDR_EXPR)
1166 : : {
1167 : : /* Variable substitution need not be simple. In particular,
1168 : : the MEM_REF substitution above. Make sure that
1169 : : TREE_CONSTANT and friends are up-to-date. */
1170 : 14598852 : int invariant = is_gimple_min_invariant (*tp);
1171 : 14598852 : walk_tree (&TREE_OPERAND (*tp, 0), remap_gimple_op_r, data, NULL);
1172 : 14598852 : recompute_tree_invariant_for_addr_expr (*tp);
1173 : :
1174 : : /* If this used to be invariant, but is not any longer,
1175 : : then regimplification is probably needed. */
1176 : 14598852 : if (invariant && !is_gimple_min_invariant (*tp))
1177 : 6647 : id->regimplify = true;
1178 : :
1179 : 14598852 : *walk_subtrees = 0;
1180 : : }
1181 : 32791977 : else if (TREE_CODE (*tp) == OMP_NEXT_VARIANT)
1182 : : {
1183 : : /* Neither operand is interesting, and walking the selector
1184 : : causes problems because it's not an expression. */
1185 : 288 : gcc_assert (TREE_CODE (TREE_OPERAND (*tp, 0)) == INTEGER_CST);
1186 : 288 : *walk_subtrees = 0;
1187 : : }
1188 : : }
1189 : :
1190 : : /* Update the TREE_BLOCK for the cloned expr. */
1191 : 115396356 : if (EXPR_P (*tp))
1192 : : {
1193 : 31203746 : tree new_block = id->remapping_type_depth == 0 ? id->block : NULL;
1194 : 31203746 : tree old_block = TREE_BLOCK (*tp);
1195 : 31203746 : if (old_block)
1196 : : {
1197 : 17288986 : tree *n;
1198 : 17288986 : n = id->decl_map->get (TREE_BLOCK (*tp));
1199 : 17288986 : if (n)
1200 : 17288582 : new_block = *n;
1201 : : }
1202 : 31203746 : TREE_SET_BLOCK (*tp, new_block);
1203 : : }
1204 : :
1205 : : /* Keep iterating. */
1206 : : return NULL_TREE;
1207 : : }
1208 : :
1209 : :
1210 : : /* Called from copy_body_id via walk_tree. DATA is really a
1211 : : `copy_body_data *'. */
1212 : :
1213 : : tree
1214 : 878081100 : copy_tree_body_r (tree *tp, int *walk_subtrees, void *data)
1215 : : {
1216 : 878081100 : copy_body_data *id = (copy_body_data *) data;
1217 : 878081100 : tree fn = id->src_fn;
1218 : 878081100 : tree new_block;
1219 : :
1220 : : /* Begin by recognizing trees that we'll completely rewrite for the
1221 : : inlining context. Our output for these trees is completely
1222 : : different from out input (e.g. RETURN_EXPR is deleted, and morphs
1223 : : into an edge). Further down, we'll handle trees that get
1224 : : duplicated and/or tweaked. */
1225 : :
1226 : : /* When requested, RETURN_EXPRs should be transformed to just the
1227 : : contained MODIFY_EXPR. The branch semantics of the return will
1228 : : be handled elsewhere by manipulating the CFG rather than a statement. */
1229 : 878081100 : if (TREE_CODE (*tp) == RETURN_EXPR && id->transform_return_to_modify)
1230 : : {
1231 : 0 : tree assignment = TREE_OPERAND (*tp, 0);
1232 : :
1233 : : /* If we're returning something, just turn that into an
1234 : : assignment into the equivalent of the original RESULT_DECL.
1235 : : If the "assignment" is just the result decl, the result
1236 : : decl has already been set (e.g. a recent "foo (&result_decl,
1237 : : ...)"); just toss the entire RETURN_EXPR. */
1238 : 0 : if (assignment && TREE_CODE (assignment) == MODIFY_EXPR)
1239 : : {
1240 : : /* Replace the RETURN_EXPR with (a copy of) the
1241 : : MODIFY_EXPR hanging underneath. */
1242 : 0 : *tp = copy_node (assignment);
1243 : : }
1244 : : else /* Else the RETURN_EXPR returns no value. */
1245 : : {
1246 : 0 : *tp = NULL;
1247 : 0 : return (tree) (void *)1;
1248 : : }
1249 : 0 : }
1250 : 878081100 : else if (TREE_CODE (*tp) == SSA_NAME)
1251 : : {
1252 : 3798064 : *tp = remap_ssa_name (*tp, id);
1253 : 3798064 : *walk_subtrees = 0;
1254 : 3798064 : return NULL;
1255 : : }
1256 : :
1257 : : /* Local variables and labels need to be replaced by equivalent
1258 : : variables. We don't want to copy static variables; there's only
1259 : : one of those, no matter how many times we inline the containing
1260 : : function. Similarly for globals from an outer function. */
1261 : 874283036 : else if (auto_var_in_fn_p (*tp, fn))
1262 : : {
1263 : 101956635 : tree new_decl;
1264 : :
1265 : : /* Remap the declaration. */
1266 : 101956635 : new_decl = remap_decl (*tp, id);
1267 : 101956635 : gcc_assert (new_decl);
1268 : : /* Replace this variable with the copy. */
1269 : 101956635 : STRIP_TYPE_NOPS (new_decl);
1270 : 101956635 : *tp = new_decl;
1271 : 101956635 : *walk_subtrees = 0;
1272 : : }
1273 : 772326401 : else if (TREE_CODE (*tp) == STATEMENT_LIST)
1274 : 30050921 : copy_statement_list (tp);
1275 : 742275480 : else if (TREE_CODE (*tp) == SAVE_EXPR
1276 : 741933742 : || TREE_CODE (*tp) == TARGET_EXPR)
1277 : 7068618 : remap_save_expr (tp, id->decl_map, walk_subtrees);
1278 : 735206862 : else if (TREE_CODE (*tp) == LABEL_DECL
1279 : 735206862 : && (! DECL_CONTEXT (*tp)
1280 : 14 : || decl_function_context (*tp) == id->src_fn))
1281 : : /* These may need to be remapped for EH handling. */
1282 : 0 : *tp = remap_decl (*tp, id);
1283 : 735206862 : else if (TREE_CODE (*tp) == BIND_EXPR)
1284 : 13222041 : copy_bind_expr (tp, walk_subtrees, id);
1285 : : /* Types may need remapping as well. */
1286 : 721984821 : else if (TYPE_P (*tp))
1287 : 173160 : *tp = remap_type (*tp, id);
1288 : :
1289 : : /* If this is a constant, we have to copy the node iff the type will be
1290 : : remapped. copy_tree_r will not copy a constant. */
1291 : 721811661 : else if (CONSTANT_CLASS_P (*tp))
1292 : : {
1293 : 213474266 : tree new_type = remap_type (TREE_TYPE (*tp), id);
1294 : :
1295 : 213474266 : if (new_type == TREE_TYPE (*tp))
1296 : 213473065 : *walk_subtrees = 0;
1297 : :
1298 : 1201 : else if (TREE_CODE (*tp) == INTEGER_CST)
1299 : 1201 : *tp = wide_int_to_tree (new_type, wi::to_wide (*tp));
1300 : : else
1301 : : {
1302 : 0 : *tp = copy_node (*tp);
1303 : 0 : TREE_TYPE (*tp) = new_type;
1304 : : }
1305 : : }
1306 : :
1307 : : /* Otherwise, just copy the node. Note that copy_tree_r already
1308 : : knows not to copy VAR_DECLs, etc., so this is safe. */
1309 : : else
1310 : : {
1311 : : /* Here we handle trees that are not completely rewritten.
1312 : : First we detect some inlining-induced bogosities for
1313 : : discarding. */
1314 : 508337395 : if (TREE_CODE (*tp) == MODIFY_EXPR
1315 : 6431893 : && TREE_OPERAND (*tp, 0) == TREE_OPERAND (*tp, 1)
1316 : 508337415 : && (auto_var_in_fn_p (TREE_OPERAND (*tp, 0), fn)))
1317 : : {
1318 : : /* Some assignments VAR = VAR; don't generate any rtl code
1319 : : and thus don't count as variable modification. Avoid
1320 : : keeping bogosities like 0 = 0. */
1321 : 0 : tree decl = TREE_OPERAND (*tp, 0), value;
1322 : 0 : tree *n;
1323 : :
1324 : 0 : n = id->decl_map->get (decl);
1325 : 0 : if (n)
1326 : : {
1327 : 0 : value = *n;
1328 : 0 : STRIP_TYPE_NOPS (value);
1329 : 0 : if (TREE_CONSTANT (value) || TREE_READONLY (value))
1330 : : {
1331 : 0 : *tp = build_empty_stmt (EXPR_LOCATION (*tp));
1332 : 0 : return copy_tree_body_r (tp, walk_subtrees, data);
1333 : : }
1334 : : }
1335 : : }
1336 : 508337395 : else if (INDIRECT_REF_P (*tp))
1337 : : {
1338 : : /* Get rid of *& from inline substitutions that can happen when a
1339 : : pointer argument is an ADDR_EXPR. */
1340 : 35186513 : tree decl = TREE_OPERAND (*tp, 0);
1341 : 35186513 : tree *n = id->decl_map->get (decl);
1342 : 35186513 : if (n)
1343 : : {
1344 : : /* If we happen to get an ADDR_EXPR in n->value, strip
1345 : : it manually here as we'll eventually get ADDR_EXPRs
1346 : : which lie about their types pointed to. In this case
1347 : : build_fold_indirect_ref wouldn't strip the INDIRECT_REF,
1348 : : but we absolutely rely on that. As fold_indirect_ref
1349 : : does other useful transformations, try that first, though. */
1350 : 5154486 : tree type = TREE_TYPE (*tp);
1351 : 5154486 : tree ptr = id->do_not_unshare ? *n : unshare_expr (*n);
1352 : 5154486 : tree old = *tp;
1353 : 5154486 : *tp = id->do_not_fold ? NULL : gimple_fold_indirect_ref (ptr);
1354 : 5154486 : if (! *tp)
1355 : : {
1356 : 5154349 : type = remap_type (type, id);
1357 : 5154349 : if (TREE_CODE (ptr) == ADDR_EXPR && !id->do_not_fold)
1358 : : {
1359 : 0 : *tp
1360 : 0 : = fold_indirect_ref_1 (EXPR_LOCATION (ptr), type, ptr);
1361 : : /* ??? We should either assert here or build
1362 : : a VIEW_CONVERT_EXPR instead of blindly leaking
1363 : : incompatible types to our IL. */
1364 : 0 : if (! *tp)
1365 : 0 : *tp = TREE_OPERAND (ptr, 0);
1366 : : }
1367 : : else
1368 : : {
1369 : 5154349 : *tp = build1 (INDIRECT_REF, type, ptr);
1370 : 5154349 : TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old);
1371 : 5154349 : TREE_SIDE_EFFECTS (*tp) = TREE_SIDE_EFFECTS (old);
1372 : 5154349 : TREE_READONLY (*tp) = TREE_READONLY (old);
1373 : 5154349 : maybe_copy_this_notrap (id, *tp, old);
1374 : : }
1375 : : }
1376 : 5154486 : *walk_subtrees = 0;
1377 : 5154486 : return NULL;
1378 : : }
1379 : : }
1380 : 473150882 : else if (TREE_CODE (*tp) == MEM_REF && !id->do_not_fold)
1381 : : {
1382 : : /* We need to re-canonicalize MEM_REFs from inline substitutions
1383 : : that can happen when a pointer argument is an ADDR_EXPR.
1384 : : Recurse here manually to allow that. */
1385 : 69174 : tree ptr = TREE_OPERAND (*tp, 0);
1386 : 69174 : tree type = remap_type (TREE_TYPE (*tp), id);
1387 : 69174 : tree old = *tp;
1388 : 69174 : walk_tree (&ptr, copy_tree_body_r, data, NULL);
1389 : 69174 : *tp = fold_build2 (MEM_REF, type, ptr, TREE_OPERAND (*tp, 1));
1390 : 69174 : TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old);
1391 : 69174 : TREE_SIDE_EFFECTS (*tp) = TREE_SIDE_EFFECTS (old);
1392 : 69174 : copy_warning (*tp, old);
1393 : 69174 : if (MR_DEPENDENCE_CLIQUE (old) != 0)
1394 : : {
1395 : 5766 : MR_DEPENDENCE_CLIQUE (*tp)
1396 : 5766 : = remap_dependence_clique (id, MR_DEPENDENCE_CLIQUE (old));
1397 : 5766 : MR_DEPENDENCE_BASE (*tp) = MR_DEPENDENCE_BASE (old);
1398 : : }
1399 : 69174 : maybe_copy_this_notrap (id, *tp, old);
1400 : 69174 : REF_REVERSE_STORAGE_ORDER (*tp) = REF_REVERSE_STORAGE_ORDER (old);
1401 : 69174 : *walk_subtrees = 0;
1402 : 69174 : return NULL;
1403 : : }
1404 : :
1405 : : /* Here is the "usual case". Copy this tree node, and then
1406 : : tweak some special cases. */
1407 : 503113735 : copy_tree_r (tp, walk_subtrees, NULL);
1408 : :
1409 : : /* If EXPR has block defined, map it to newly constructed block.
1410 : : When inlining we want EXPRs without block appear in the block
1411 : : of function call if we are not remapping a type. */
1412 : 503113735 : if (EXPR_P (*tp))
1413 : : {
1414 : 433707325 : new_block = id->remapping_type_depth == 0 ? id->block : NULL;
1415 : 433707325 : if (TREE_BLOCK (*tp))
1416 : : {
1417 : 13004 : tree *n;
1418 : 13004 : n = id->decl_map->get (TREE_BLOCK (*tp));
1419 : 13004 : if (n)
1420 : 13004 : new_block = *n;
1421 : : }
1422 : 433707325 : TREE_SET_BLOCK (*tp, new_block);
1423 : : }
1424 : :
1425 : 503113735 : if (TREE_CODE (*tp) != OMP_CLAUSE)
1426 : 503113644 : TREE_TYPE (*tp) = remap_type (TREE_TYPE (*tp), id);
1427 : :
1428 : : /* The copied TARGET_EXPR has never been expanded, even if the
1429 : : original node was expanded already. */
1430 : 503113735 : if (TREE_CODE (*tp) == TARGET_EXPR && TREE_OPERAND (*tp, 3))
1431 : : {
1432 : 0 : TREE_OPERAND (*tp, 1) = TREE_OPERAND (*tp, 3);
1433 : 0 : TREE_OPERAND (*tp, 3) = NULL_TREE;
1434 : : }
1435 : :
1436 : : /* Variable substitution need not be simple. In particular, the
1437 : : INDIRECT_REF substitution above. Make sure that TREE_CONSTANT
1438 : : and friends are up-to-date. */
1439 : 503113735 : else if (TREE_CODE (*tp) == ADDR_EXPR)
1440 : : {
1441 : 45139250 : int invariant = is_gimple_min_invariant (*tp);
1442 : 45139250 : walk_tree (&TREE_OPERAND (*tp, 0), copy_tree_body_r, id, NULL);
1443 : :
1444 : : /* Handle the case where we substituted an INDIRECT_REF
1445 : : into the operand of the ADDR_EXPR. */
1446 : 45139250 : if (INDIRECT_REF_P (TREE_OPERAND (*tp, 0))
1447 : 45139250 : && !id->do_not_fold)
1448 : : {
1449 : 147 : tree t = TREE_OPERAND (TREE_OPERAND (*tp, 0), 0);
1450 : 147 : if (TREE_TYPE (t) != TREE_TYPE (*tp))
1451 : 147 : t = fold_convert (remap_type (TREE_TYPE (*tp), id), t);
1452 : 147 : *tp = t;
1453 : : }
1454 : : else
1455 : 45139103 : recompute_tree_invariant_for_addr_expr (*tp);
1456 : :
1457 : : /* If this used to be invariant, but is not any longer,
1458 : : then regimplification is probably needed. */
1459 : 45139250 : if (invariant && !is_gimple_min_invariant (*tp))
1460 : 16 : id->regimplify = true;
1461 : :
1462 : 45139250 : *walk_subtrees = 0;
1463 : : }
1464 : 457974485 : else if (TREE_CODE (*tp) == OMP_CLAUSE
1465 : 457974485 : && (OMP_CLAUSE_CODE (*tp) == OMP_CLAUSE_AFFINITY
1466 : 76 : || OMP_CLAUSE_CODE (*tp) == OMP_CLAUSE_DEPEND))
1467 : : {
1468 : 30 : tree t = OMP_CLAUSE_DECL (*tp);
1469 : 30 : if (t && OMP_ITERATOR_DECL_P (t))
1470 : : {
1471 : 18 : *walk_subtrees = 0;
1472 : 18 : OMP_CLAUSE_DECL (*tp) = copy_node (t);
1473 : 18 : t = OMP_CLAUSE_DECL (*tp);
1474 : 18 : TREE_PURPOSE (t) = copy_node (TREE_PURPOSE (t));
1475 : 108 : for (int i = 0; i <= 4; i++)
1476 : 90 : walk_tree (&TREE_VEC_ELT (TREE_PURPOSE (t), i),
1477 : : copy_tree_body_r, id, NULL);
1478 : 18 : if (TREE_VEC_ELT (TREE_PURPOSE (t), 5))
1479 : 18 : remap_block (&TREE_VEC_ELT (TREE_PURPOSE (t), 5), id);
1480 : 18 : walk_tree (&TREE_VALUE (t), copy_tree_body_r, id, NULL);
1481 : : }
1482 : : }
1483 : : }
1484 : :
1485 : : /* Keep iterating. */
1486 : : return NULL_TREE;
1487 : : }
1488 : :
1489 : : /* Helper for remap_gimple_stmt. Given an EH region number for the
1490 : : source function, map that to the duplicate EH region number in
1491 : : the destination function. */
1492 : :
1493 : : static int
1494 : 103277 : remap_eh_region_nr (int old_nr, copy_body_data *id)
1495 : : {
1496 : 103277 : eh_region old_r, new_r;
1497 : :
1498 : 103277 : old_r = get_eh_region_from_number_fn (id->src_cfun, old_nr);
1499 : 103277 : new_r = static_cast<eh_region> (*id->eh_map->get (old_r));
1500 : :
1501 : 103277 : return new_r->index;
1502 : : }
1503 : :
1504 : : /* Similar, but operate on INTEGER_CSTs. */
1505 : :
1506 : : static tree
1507 : 7899 : remap_eh_region_tree_nr (tree old_t_nr, copy_body_data *id)
1508 : : {
1509 : 7899 : int old_nr, new_nr;
1510 : :
1511 : 7899 : old_nr = tree_to_shwi (old_t_nr);
1512 : 7899 : new_nr = remap_eh_region_nr (old_nr, id);
1513 : :
1514 : 7899 : return build_int_cst (integer_type_node, new_nr);
1515 : : }
1516 : :
1517 : : /* Helper for copy_bb. Remap statement STMT using the inlining
1518 : : information in ID. Return the new statement copy. */
1519 : :
1520 : : static gimple_seq
1521 : 87867895 : remap_gimple_stmt (gimple *stmt, copy_body_data *id)
1522 : : {
1523 : 87867895 : gimple *copy = NULL;
1524 : 87867895 : struct walk_stmt_info wi;
1525 : 87867895 : bool skip_first = false;
1526 : 87867895 : gimple_seq stmts = NULL;
1527 : :
1528 : 87867895 : if (is_gimple_debug (stmt)
1529 : 87867895 : && (gimple_debug_nonbind_marker_p (stmt)
1530 : 12613196 : ? !DECL_STRUCT_FUNCTION (id->dst_fn)->debug_nonbind_markers
1531 : 40246307 : : !opt_for_fn (id->dst_fn, flag_var_tracking_assignments)))
1532 : : return NULL;
1533 : :
1534 : 87841865 : if (!is_gimple_debug (stmt)
1535 : 35008392 : && id->param_body_adjs
1536 : 90984882 : && id->param_body_adjs->m_dead_stmts.contains (stmt))
1537 : : {
1538 : 1926 : tree *dval = id->param_body_adjs->m_dead_stmt_debug_equiv.get (stmt);
1539 : 1926 : if (!dval)
1540 : : return NULL;
1541 : :
1542 : 778 : gcc_assert (is_gimple_assign (stmt));
1543 : 778 : tree lhs = gimple_assign_lhs (stmt);
1544 : 778 : tree *dvar = id->param_body_adjs->m_dead_ssa_debug_equiv.get (lhs);
1545 : 778 : gdebug *bind = gimple_build_debug_bind (*dvar, *dval, stmt);
1546 : 778 : if (id->reset_location)
1547 : 0 : gimple_set_location (bind, input_location);
1548 : 778 : id->debug_stmts.safe_push (bind);
1549 : 778 : gimple_seq_add_stmt_without_update (&stmts, bind);
1550 : 778 : return stmts;
1551 : : }
1552 : :
1553 : : /* Begin by recognizing trees that we'll completely rewrite for the
1554 : : inlining context. Our output for these trees is completely
1555 : : different from our input (e.g. RETURN_EXPR is deleted and morphs
1556 : : into an edge). Further down, we'll handle trees that get
1557 : : duplicated and/or tweaked. */
1558 : :
1559 : : /* When requested, GIMPLE_RETURN should be transformed to just the
1560 : : contained GIMPLE_ASSIGN. The branch semantics of the return will
1561 : : be handled elsewhere by manipulating the CFG rather than the
1562 : : statement. */
1563 : 87839939 : if (gimple_code (stmt) == GIMPLE_RETURN && id->transform_return_to_modify)
1564 : : {
1565 : 4532535 : tree retval = gimple_return_retval (as_a <greturn *> (stmt));
1566 : :
1567 : : /* If we're returning something, just turn that into an
1568 : : assignment to the equivalent of the original RESULT_DECL.
1569 : : If RETVAL is just the result decl, the result decl has
1570 : : already been set (e.g. a recent "foo (&result_decl, ...)");
1571 : : just toss the entire GIMPLE_RETURN. Likewise for when the
1572 : : call doesn't want the return value. */
1573 : 4532535 : if (retval
1574 : 4532535 : && (TREE_CODE (retval) != RESULT_DECL
1575 : 2327142 : && (!id->call_stmt
1576 : 2327142 : || gimple_call_lhs (id->call_stmt) != NULL_TREE)
1577 : 2208249 : && (TREE_CODE (retval) != SSA_NAME
1578 : 1766941 : || ! SSA_NAME_VAR (retval)
1579 : 412466 : || TREE_CODE (SSA_NAME_VAR (retval)) != RESULT_DECL)))
1580 : : {
1581 : 4256064 : copy = gimple_build_assign (id->do_not_unshare
1582 : 2128032 : ? id->retvar : unshare_expr (id->retvar),
1583 : : retval);
1584 : : /* id->retvar is already substituted. Skip it on later remapping. */
1585 : 2128032 : skip_first = true;
1586 : : }
1587 : : else
1588 : : return NULL;
1589 : : }
1590 : 83307404 : else if (gimple_has_substatements (stmt))
1591 : : {
1592 : 67 : gimple_seq s1, s2;
1593 : :
1594 : : /* When cloning bodies from the C++ front end, we will be handed bodies
1595 : : in High GIMPLE form. Handle here all the High GIMPLE statements that
1596 : : have embedded statements. */
1597 : 67 : switch (gimple_code (stmt))
1598 : : {
1599 : 0 : case GIMPLE_BIND:
1600 : 0 : copy = copy_gimple_bind (as_a <gbind *> (stmt), id);
1601 : 0 : break;
1602 : :
1603 : 0 : case GIMPLE_CATCH:
1604 : 0 : {
1605 : 0 : gcatch *catch_stmt = as_a <gcatch *> (stmt);
1606 : 0 : s1 = remap_gimple_seq (gimple_catch_handler (catch_stmt), id);
1607 : 0 : copy = gimple_build_catch (gimple_catch_types (catch_stmt), s1);
1608 : : }
1609 : 0 : break;
1610 : :
1611 : 0 : case GIMPLE_EH_FILTER:
1612 : 0 : s1 = remap_gimple_seq (gimple_eh_filter_failure (stmt), id);
1613 : 0 : copy = gimple_build_eh_filter (gimple_eh_filter_types (stmt), s1);
1614 : 0 : break;
1615 : :
1616 : 0 : case GIMPLE_TRY:
1617 : 0 : s1 = remap_gimple_seq (gimple_try_eval (stmt), id);
1618 : 0 : s2 = remap_gimple_seq (gimple_try_cleanup (stmt), id);
1619 : 0 : copy = gimple_build_try (s1, s2, gimple_try_kind (stmt));
1620 : 0 : break;
1621 : :
1622 : 0 : case GIMPLE_WITH_CLEANUP_EXPR:
1623 : 0 : s1 = remap_gimple_seq (gimple_wce_cleanup (stmt), id);
1624 : 0 : copy = gimple_build_wce (s1);
1625 : 0 : break;
1626 : :
1627 : 0 : case GIMPLE_OMP_PARALLEL:
1628 : 0 : {
1629 : 0 : gomp_parallel *omp_par_stmt = as_a <gomp_parallel *> (stmt);
1630 : 0 : s1 = remap_gimple_seq (gimple_omp_body (omp_par_stmt), id);
1631 : 0 : copy = gimple_build_omp_parallel
1632 : 0 : (s1,
1633 : : gimple_omp_parallel_clauses (omp_par_stmt),
1634 : : gimple_omp_parallel_child_fn (omp_par_stmt),
1635 : : gimple_omp_parallel_data_arg (omp_par_stmt));
1636 : : }
1637 : 0 : break;
1638 : :
1639 : 0 : case GIMPLE_OMP_TASK:
1640 : 0 : s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
1641 : 0 : copy = gimple_build_omp_task
1642 : 0 : (s1,
1643 : : gimple_omp_task_clauses (stmt),
1644 : : gimple_omp_task_child_fn (stmt),
1645 : : gimple_omp_task_data_arg (stmt),
1646 : : gimple_omp_task_copy_fn (stmt),
1647 : : gimple_omp_task_arg_size (stmt),
1648 : : gimple_omp_task_arg_align (stmt));
1649 : 0 : break;
1650 : :
1651 : 0 : case GIMPLE_OMP_FOR:
1652 : 0 : s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
1653 : 0 : s2 = remap_gimple_seq (gimple_omp_for_pre_body (stmt), id);
1654 : 0 : copy = gimple_build_omp_for (s1, gimple_omp_for_kind (stmt),
1655 : : gimple_omp_for_clauses (stmt),
1656 : : gimple_omp_for_collapse (stmt), s2);
1657 : 0 : {
1658 : 0 : size_t i;
1659 : 0 : for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
1660 : : {
1661 : 0 : gimple_omp_for_set_index (copy, i,
1662 : : gimple_omp_for_index (stmt, i));
1663 : 0 : gimple_omp_for_set_initial (copy, i,
1664 : : gimple_omp_for_initial (stmt, i));
1665 : 0 : gimple_omp_for_set_final (copy, i,
1666 : : gimple_omp_for_final (stmt, i));
1667 : 0 : gimple_omp_for_set_incr (copy, i,
1668 : : gimple_omp_for_incr (stmt, i));
1669 : 0 : gimple_omp_for_set_cond (copy, i,
1670 : : gimple_omp_for_cond (stmt, i));
1671 : : }
1672 : : }
1673 : : break;
1674 : :
1675 : 0 : case GIMPLE_OMP_MASTER:
1676 : 0 : s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
1677 : 0 : copy = gimple_build_omp_master (s1);
1678 : 0 : break;
1679 : :
1680 : 0 : case GIMPLE_OMP_MASKED:
1681 : 0 : s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
1682 : 0 : copy = gimple_build_omp_masked
1683 : 0 : (s1, gimple_omp_masked_clauses (stmt));
1684 : 0 : break;
1685 : :
1686 : 0 : case GIMPLE_OMP_SCOPE:
1687 : 0 : s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
1688 : 0 : copy = gimple_build_omp_scope
1689 : 0 : (s1, gimple_omp_scope_clauses (stmt));
1690 : 0 : break;
1691 : :
1692 : 0 : case GIMPLE_OMP_DISPATCH:
1693 : 0 : s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
1694 : 0 : copy = gimple_build_omp_dispatch (s1,
1695 : : gimple_omp_dispatch_clauses (stmt));
1696 : 0 : break;
1697 : :
1698 : 0 : case GIMPLE_OMP_TASKGROUP:
1699 : 0 : s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
1700 : 0 : copy = gimple_build_omp_taskgroup
1701 : 0 : (s1, gimple_omp_taskgroup_clauses (stmt));
1702 : 0 : break;
1703 : :
1704 : 0 : case GIMPLE_OMP_ORDERED:
1705 : 0 : s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
1706 : 0 : copy = gimple_build_omp_ordered
1707 : 0 : (s1,
1708 : 0 : gimple_omp_ordered_clauses (as_a <gomp_ordered *> (stmt)));
1709 : 0 : break;
1710 : :
1711 : 0 : case GIMPLE_OMP_SCAN:
1712 : 0 : s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
1713 : 0 : copy = gimple_build_omp_scan
1714 : 0 : (s1, gimple_omp_scan_clauses (as_a <gomp_scan *> (stmt)));
1715 : 0 : break;
1716 : :
1717 : 0 : case GIMPLE_OMP_SECTION:
1718 : 0 : s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
1719 : 0 : copy = gimple_build_omp_section (s1);
1720 : 0 : break;
1721 : :
1722 : 0 : case GIMPLE_OMP_SECTIONS:
1723 : 0 : s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
1724 : 0 : copy = gimple_build_omp_sections
1725 : 0 : (s1, gimple_omp_sections_clauses (stmt));
1726 : 0 : break;
1727 : :
1728 : 0 : case GIMPLE_OMP_STRUCTURED_BLOCK:
1729 : 0 : s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
1730 : 0 : copy = gimple_build_omp_structured_block (s1);
1731 : 0 : break;
1732 : :
1733 : 0 : case GIMPLE_OMP_SINGLE:
1734 : 0 : s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
1735 : 0 : copy = gimple_build_omp_single
1736 : 0 : (s1, gimple_omp_single_clauses (stmt));
1737 : 0 : break;
1738 : :
1739 : 0 : case GIMPLE_OMP_TARGET:
1740 : 0 : s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
1741 : 0 : copy = gimple_build_omp_target
1742 : 0 : (s1, gimple_omp_target_kind (stmt),
1743 : : gimple_omp_target_clauses (stmt));
1744 : 0 : break;
1745 : :
1746 : 0 : case GIMPLE_OMP_TEAMS:
1747 : 0 : s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
1748 : 0 : copy = gimple_build_omp_teams
1749 : 0 : (s1, gimple_omp_teams_clauses (stmt));
1750 : 0 : break;
1751 : :
1752 : 0 : case GIMPLE_OMP_CRITICAL:
1753 : 0 : s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
1754 : 0 : copy = gimple_build_omp_critical (s1,
1755 : : gimple_omp_critical_name
1756 : 0 : (as_a <gomp_critical *> (stmt)),
1757 : : gimple_omp_critical_clauses
1758 : 0 : (as_a <gomp_critical *> (stmt)));
1759 : 0 : break;
1760 : :
1761 : 0 : case GIMPLE_ASSUME:
1762 : 0 : s1 = remap_gimple_seq (gimple_assume_body (stmt), id);
1763 : 0 : copy = gimple_build_assume (gimple_assume_guard (stmt), s1);
1764 : 0 : break;
1765 : :
1766 : 67 : case GIMPLE_TRANSACTION:
1767 : 67 : {
1768 : 67 : gtransaction *old_trans_stmt = as_a <gtransaction *> (stmt);
1769 : 67 : gtransaction *new_trans_stmt;
1770 : 67 : s1 = remap_gimple_seq (gimple_transaction_body (old_trans_stmt),
1771 : : id);
1772 : 67 : copy = new_trans_stmt = gimple_build_transaction (s1);
1773 : 67 : gimple_transaction_set_subcode (new_trans_stmt,
1774 : : gimple_transaction_subcode (old_trans_stmt));
1775 : 67 : gimple_transaction_set_label_norm (new_trans_stmt,
1776 : : gimple_transaction_label_norm (old_trans_stmt));
1777 : 67 : gimple_transaction_set_label_uninst (new_trans_stmt,
1778 : : gimple_transaction_label_uninst (old_trans_stmt));
1779 : 67 : gimple_transaction_set_label_over (new_trans_stmt,
1780 : : gimple_transaction_label_over (old_trans_stmt));
1781 : : }
1782 : 67 : break;
1783 : :
1784 : 0 : default:
1785 : 0 : gcc_unreachable ();
1786 : : }
1787 : : }
1788 : : else
1789 : : {
1790 : 83307337 : if (gimple_assign_single_p (stmt)
1791 : 14046284 : && gimple_assign_lhs (stmt) == gimple_assign_rhs1 (stmt)
1792 : 83307337 : && auto_var_in_fn_p (gimple_assign_lhs (stmt), id->src_fn))
1793 : : {
1794 : : /* Here we handle statements that are not completely rewritten.
1795 : : First we detect some inlining-induced bogosities for
1796 : : discarding. */
1797 : :
1798 : : /* Some assignments VAR = VAR; don't generate any rtl code
1799 : : and thus don't count as variable modification. Avoid
1800 : : keeping bogosities like 0 = 0. */
1801 : 0 : tree decl = gimple_assign_lhs (stmt), value;
1802 : 0 : tree *n;
1803 : :
1804 : 0 : n = id->decl_map->get (decl);
1805 : 0 : if (n)
1806 : : {
1807 : 0 : value = *n;
1808 : 0 : STRIP_TYPE_NOPS (value);
1809 : 0 : if (TREE_CONSTANT (value) || TREE_READONLY (value))
1810 : 0 : return NULL;
1811 : : }
1812 : : }
1813 : :
1814 : : /* For *ptr_N ={v} {CLOBBER}, if ptr_N is SSA_NAME defined
1815 : : in a block that we aren't copying during tree_function_versioning,
1816 : : just drop the clobber stmt. */
1817 : 83307337 : if (id->blocks_to_copy && gimple_clobber_p (stmt))
1818 : : {
1819 : 22423 : tree lhs = gimple_assign_lhs (stmt);
1820 : 22423 : if (TREE_CODE (lhs) == MEM_REF
1821 : 22423 : && TREE_CODE (TREE_OPERAND (lhs, 0)) == SSA_NAME)
1822 : : {
1823 : 1091 : gimple *def_stmt = SSA_NAME_DEF_STMT (TREE_OPERAND (lhs, 0));
1824 : 1091 : if (gimple_bb (def_stmt)
1825 : 1585 : && !bitmap_bit_p (id->blocks_to_copy,
1826 : 494 : gimple_bb (def_stmt)->index))
1827 : : return NULL;
1828 : : }
1829 : : }
1830 : :
1831 : : /* We do not allow CLOBBERs of handled components. In case
1832 : : returned value is stored via such handled component, remove
1833 : : the clobber so stmt verifier is happy. */
1834 : 83307334 : if (gimple_clobber_p (stmt)
1835 : 83307334 : && TREE_CODE (gimple_assign_lhs (stmt)) == RESULT_DECL)
1836 : : {
1837 : 14 : tree remapped = remap_decl (gimple_assign_lhs (stmt), id);
1838 : 14 : if (!DECL_P (remapped)
1839 : 0 : && TREE_CODE (remapped) != MEM_REF)
1840 : : return NULL;
1841 : : }
1842 : :
1843 : 83307334 : if (gimple_debug_bind_p (stmt))
1844 : : {
1845 : 39766769 : tree var = gimple_debug_bind_get_var (stmt);
1846 : 39766769 : tree value = gimple_debug_bind_get_value (stmt);
1847 : 39766769 : if (id->param_body_adjs
1848 : 39766769 : && id->param_body_adjs->m_dead_stmts.contains (stmt))
1849 : : {
1850 : 7526 : value = unshare_expr_without_location (value);
1851 : 7526 : id->param_body_adjs->remap_with_debug_expressions (&value);
1852 : : }
1853 : :
1854 : 39766769 : gdebug *copy = gimple_build_debug_bind (var, value, stmt);
1855 : 39766769 : if (id->reset_location)
1856 : 4 : gimple_set_location (copy, input_location);
1857 : 39766769 : id->debug_stmts.safe_push (copy);
1858 : 39766769 : gimple_seq_add_stmt_without_update (&stmts, copy);
1859 : 39766769 : return stmts;
1860 : : }
1861 : 43540565 : if (gimple_debug_source_bind_p (stmt))
1862 : : {
1863 : 479538 : gdebug *copy = gimple_build_debug_source_bind
1864 : 479538 : (gimple_debug_source_bind_get_var (stmt),
1865 : : gimple_debug_source_bind_get_value (stmt),
1866 : 479538 : stmt);
1867 : 479538 : if (id->reset_location)
1868 : 0 : gimple_set_location (copy, input_location);
1869 : 479538 : id->debug_stmts.safe_push (copy);
1870 : 479538 : gimple_seq_add_stmt_without_update (&stmts, copy);
1871 : 479538 : return stmts;
1872 : : }
1873 : 43061027 : if (gimple_debug_nonbind_marker_p (stmt))
1874 : : {
1875 : : /* If the inlined function has too many debug markers,
1876 : : don't copy them. */
1877 : 12587166 : if (id->src_cfun->debug_marker_count
1878 : 12587166 : > param_max_debug_marker_count
1879 : 12587166 : || id->reset_location)
1880 : 0 : return stmts;
1881 : :
1882 : 12587166 : gdebug *copy = as_a <gdebug *> (gimple_copy (stmt));
1883 : 12587166 : id->debug_stmts.safe_push (copy);
1884 : 12587166 : gimple_seq_add_stmt_without_update (&stmts, copy);
1885 : 12587166 : return stmts;
1886 : : }
1887 : :
1888 : : /* Create a new deep copy of the statement. */
1889 : 30473861 : copy = gimple_copy (stmt);
1890 : :
1891 : : /* Clear flags that need revisiting. */
1892 : 30473861 : if (gcall *call_stmt = dyn_cast <gcall *> (copy))
1893 : : {
1894 : 4645758 : if (gimple_call_tail_p (call_stmt))
1895 : 83 : gimple_call_set_tail (call_stmt, false);
1896 : 4645758 : if (gimple_call_from_thunk_p (call_stmt))
1897 : 123 : gimple_call_set_from_thunk (call_stmt, false);
1898 : : /* Silently clear musttail flag when inlining a function
1899 : : with must tail call from a non-musttail call. The inlining
1900 : : removes one frame so acts like musttail's intent, and we
1901 : : can be inlining a function with musttail calls in the middle
1902 : : of caller where musttail will always error. */
1903 : 4645758 : if (gimple_call_must_tail_p (call_stmt)
1904 : 49 : && id->call_stmt
1905 : 4645799 : && !gimple_call_must_tail_p (id->call_stmt))
1906 : 14 : gimple_call_set_must_tail (call_stmt, false);
1907 : 4645758 : if (gimple_call_internal_p (call_stmt))
1908 : 32043 : switch (gimple_call_internal_fn (call_stmt))
1909 : : {
1910 : 135 : case IFN_GOMP_SIMD_LANE:
1911 : 135 : case IFN_GOMP_SIMD_VF:
1912 : 135 : case IFN_GOMP_SIMD_LAST_LANE:
1913 : 135 : case IFN_GOMP_SIMD_ORDERED_START:
1914 : 135 : case IFN_GOMP_SIMD_ORDERED_END:
1915 : 135 : DECL_STRUCT_FUNCTION (id->dst_fn)->has_simduid_loops = true;
1916 : 135 : break;
1917 : : default:
1918 : : break;
1919 : : }
1920 : : }
1921 : :
1922 : : /* Remap the region numbers for __builtin_eh_{pointer,filter},
1923 : : RESX and EH_DISPATCH. */
1924 : 30473861 : if (id->eh_map)
1925 : 30473861 : switch (gimple_code (copy))
1926 : : {
1927 : 4645758 : case GIMPLE_CALL:
1928 : 4645758 : {
1929 : 4645758 : tree r, fndecl = gimple_call_fndecl (copy);
1930 : 4645758 : if (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
1931 : 1242284 : switch (DECL_FUNCTION_CODE (fndecl))
1932 : : {
1933 : 0 : case BUILT_IN_EH_COPY_VALUES:
1934 : 0 : r = gimple_call_arg (copy, 1);
1935 : 0 : r = remap_eh_region_tree_nr (r, id);
1936 : 0 : gimple_call_set_arg (copy, 1, r);
1937 : : /* FALLTHRU */
1938 : :
1939 : 7899 : case BUILT_IN_EH_POINTER:
1940 : 7899 : case BUILT_IN_EH_FILTER:
1941 : 7899 : r = gimple_call_arg (copy, 0);
1942 : 7899 : r = remap_eh_region_tree_nr (r, id);
1943 : 7899 : gimple_call_set_arg (copy, 0, r);
1944 : 7899 : break;
1945 : :
1946 : : default:
1947 : : break;
1948 : : }
1949 : :
1950 : : /* Reset alias info if we didn't apply measures to
1951 : : keep it valid over inlining by setting DECL_PT_UID. */
1952 : 4645758 : if (!id->src_cfun->gimple_df
1953 : 4645758 : || !id->src_cfun->gimple_df->ipa_pta)
1954 : 4639242 : gimple_call_reset_alias_info (as_a <gcall *> (copy));
1955 : : }
1956 : : break;
1957 : :
1958 : 86173 : case GIMPLE_RESX:
1959 : 86173 : {
1960 : 86173 : gresx *resx_stmt = as_a <gresx *> (copy);
1961 : 86173 : int r = gimple_resx_region (resx_stmt);
1962 : 86173 : r = remap_eh_region_nr (r, id);
1963 : 86173 : gimple_resx_set_region (resx_stmt, r);
1964 : : }
1965 : 86173 : break;
1966 : :
1967 : 9205 : case GIMPLE_EH_DISPATCH:
1968 : 9205 : {
1969 : 9205 : geh_dispatch *eh_dispatch = as_a <geh_dispatch *> (copy);
1970 : 9205 : int r = gimple_eh_dispatch_region (eh_dispatch);
1971 : 9205 : r = remap_eh_region_nr (r, id);
1972 : 9205 : gimple_eh_dispatch_set_region (eh_dispatch, r);
1973 : : }
1974 : 9205 : break;
1975 : :
1976 : : default:
1977 : : break;
1978 : : }
1979 : : }
1980 : :
1981 : : /* If STMT has a block defined, map it to the newly constructed block. */
1982 : 32601960 : if (tree block = gimple_block (copy))
1983 : : {
1984 : 29391792 : tree *n;
1985 : 29391792 : n = id->decl_map->get (block);
1986 : 29391792 : gcc_assert (n);
1987 : 29391792 : gimple_set_block (copy, *n);
1988 : : }
1989 : 32601960 : if (id->param_body_adjs)
1990 : : {
1991 : 3141091 : gimple_seq extra_stmts = NULL;
1992 : 3141091 : id->param_body_adjs->modify_gimple_stmt (©, &extra_stmts, stmt);
1993 : 3141091 : if (!gimple_seq_empty_p (extra_stmts))
1994 : : {
1995 : 3 : memset (&wi, 0, sizeof (wi));
1996 : 3 : wi.info = id;
1997 : 3 : for (gimple_stmt_iterator egsi = gsi_start (extra_stmts);
1998 : 6 : !gsi_end_p (egsi);
1999 : 3 : gsi_next (&egsi))
2000 : 3 : walk_gimple_op (gsi_stmt (egsi), remap_gimple_op_r, &wi);
2001 : 3 : gimple_seq_add_seq_without_update (&stmts, extra_stmts);
2002 : : }
2003 : : }
2004 : :
2005 : 32601960 : if (id->reset_location)
2006 : 576 : gimple_set_location (copy, input_location);
2007 : :
2008 : : /* Debug statements ought to be rebuilt and not copied. */
2009 : 32601960 : gcc_checking_assert (!is_gimple_debug (copy));
2010 : :
2011 : : /* Remap all the operands in COPY. */
2012 : 32601960 : memset (&wi, 0, sizeof (wi));
2013 : 32601960 : wi.info = id;
2014 : 32601960 : if (skip_first)
2015 : 2128032 : walk_tree (gimple_op_ptr (copy, 1), remap_gimple_op_r, &wi, NULL);
2016 : : else
2017 : 30473928 : walk_gimple_op (copy, remap_gimple_op_r, &wi);
2018 : :
2019 : : /* Clear the copied virtual operands. We are not remapping them here
2020 : : but are going to recreate them from scratch. */
2021 : 32601960 : if (gimple_has_mem_ops (copy))
2022 : : {
2023 : 28202157 : gimple_set_vdef (copy, NULL_TREE);
2024 : 28202157 : gimple_set_vuse (copy, NULL_TREE);
2025 : : }
2026 : :
2027 : 32601960 : if (cfun->can_throw_non_call_exceptions)
2028 : : {
2029 : : /* When inlining a function which does not have non-call exceptions
2030 : : enabled into a function that has (which only happens with
2031 : : always-inline) we have to fixup stmts that cannot throw. */
2032 : 1711925 : if (gcond *cond = dyn_cast <gcond *> (copy))
2033 : 199354 : if (gimple_could_trap_p (cond))
2034 : : {
2035 : 1 : gassign *cmp
2036 : 1 : = gimple_build_assign (make_ssa_name (boolean_type_node),
2037 : : gimple_cond_code (cond),
2038 : : gimple_cond_lhs (cond),
2039 : : gimple_cond_rhs (cond));
2040 : 1 : gimple_seq_add_stmt_without_update (&stmts, cmp);
2041 : 1 : gimple_cond_set_code (cond, NE_EXPR);
2042 : 1 : gimple_cond_set_lhs (cond, gimple_assign_lhs (cmp));
2043 : 1 : gimple_cond_set_rhs (cond, boolean_false_node);
2044 : : }
2045 : : }
2046 : :
2047 : 32601960 : gimple_seq_add_stmt_without_update (&stmts, copy);
2048 : 32601960 : return stmts;
2049 : : }
2050 : :
2051 : :
2052 : : /* Copy basic block, scale profile accordingly. Edges will be taken care of
2053 : : later */
2054 : :
2055 : : static basic_block
2056 : 13973963 : copy_bb (copy_body_data *id, basic_block bb,
2057 : : profile_count num, profile_count den)
2058 : : {
2059 : 13973963 : gimple_stmt_iterator gsi, copy_gsi, seq_gsi;
2060 : 13973963 : basic_block copy_basic_block;
2061 : 13973963 : tree decl;
2062 : 13973963 : basic_block prev;
2063 : :
2064 : 13973963 : profile_count::adjust_for_ipa_scaling (&num, &den);
2065 : :
2066 : : /* Search for previous copied basic block. */
2067 : 13973963 : prev = bb->prev_bb;
2068 : 14129931 : while (!prev->aux)
2069 : 155968 : prev = prev->prev_bb;
2070 : :
2071 : : /* create_basic_block() will append every new block to
2072 : : basic_block_info automatically. */
2073 : 13973963 : copy_basic_block = create_basic_block (NULL, (basic_block) prev->aux);
2074 : 13973963 : copy_basic_block->count = bb->count.apply_scale (num, den);
2075 : :
2076 : 13973963 : copy_gsi = gsi_start_bb (copy_basic_block);
2077 : :
2078 : 13973963 : unsigned min_cond_uid = 0;
2079 : 13973963 : if (id->src_cfun->cond_uids)
2080 : : {
2081 : 23 : if (!cfun->cond_uids)
2082 : 3 : cfun->cond_uids = new hash_map <gcond*, unsigned> ();
2083 : :
2084 : 92 : for (auto itr : *id->src_cfun->cond_uids)
2085 : 23 : if (itr.second >= min_cond_uid)
2086 : 23 : min_cond_uid = itr.second + 1;
2087 : : }
2088 : :
2089 : 115815821 : for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2090 : : {
2091 : 87867895 : gimple_seq stmts;
2092 : 87867895 : gimple *stmt = gsi_stmt (gsi);
2093 : 87867895 : gimple *orig_stmt = stmt;
2094 : 87867895 : gimple_stmt_iterator stmts_gsi;
2095 : 87867895 : bool stmt_added = false;
2096 : :
2097 : 87867895 : id->regimplify = false;
2098 : 87867895 : stmts = remap_gimple_stmt (stmt, id);
2099 : :
2100 : 87867895 : if (gimple_seq_empty_p (stmts))
2101 : 2431866 : continue;
2102 : :
2103 : 85436211 : seq_gsi = copy_gsi;
2104 : :
2105 : 85436211 : for (stmts_gsi = gsi_start (stmts);
2106 : 170872426 : !gsi_end_p (stmts_gsi); )
2107 : : {
2108 : 85436215 : stmt = gsi_stmt (stmts_gsi);
2109 : :
2110 : : /* Advance iterator now before stmt is moved to seq_gsi. */
2111 : 85436215 : gsi_next (&stmts_gsi);
2112 : :
2113 : 85436215 : if (gimple_nop_p (stmt))
2114 : 182 : continue;
2115 : :
2116 : : /* If -fcondition-coverage is used, register the inlined conditions
2117 : : in the cond->expression mapping of the caller. The expression tag
2118 : : is shifted conditions from the two bodies are not mixed. */
2119 : 85436033 : if (id->src_cfun->cond_uids && is_a <gcond*> (stmt))
2120 : : {
2121 : 5 : gcond *orig_cond = as_a <gcond*> (orig_stmt);
2122 : 5 : gcond *cond = as_a <gcond*> (stmt);
2123 : 5 : unsigned *v = id->src_cfun->cond_uids->get (orig_cond);
2124 : 5 : if (v)
2125 : 5 : cfun->cond_uids->put (cond, *v + min_cond_uid);
2126 : : }
2127 : :
2128 : 85436033 : gimple_duplicate_stmt_histograms (cfun, stmt, id->src_cfun,
2129 : : orig_stmt);
2130 : :
2131 : 85436033 : gsi_insert_after (&seq_gsi, stmt, GSI_NEW_STMT);
2132 : :
2133 : 85436033 : if (id->regimplify)
2134 : 6605 : gimple_regimplify_operands (stmt, &seq_gsi);
2135 : :
2136 : : stmt_added = true;
2137 : : }
2138 : :
2139 : 85436211 : if (!stmt_added)
2140 : 182 : continue;
2141 : :
2142 : : /* If copy_basic_block has been empty at the start of this iteration,
2143 : : call gsi_start_bb again to get at the newly added statements. */
2144 : 85436029 : if (gsi_end_p (copy_gsi))
2145 : 24579230 : copy_gsi = gsi_start_bb (copy_basic_block);
2146 : : else
2147 : 73146414 : gsi_next (©_gsi);
2148 : :
2149 : : /* Process the new statement. The call to gimple_regimplify_operands
2150 : : possibly turned the statement into multiple statements, we
2151 : : need to process all of them. */
2152 : 85436040 : do
2153 : : {
2154 : 85436040 : tree fn;
2155 : 85436040 : gcall *call_stmt;
2156 : :
2157 : 85436040 : stmt = gsi_stmt (copy_gsi);
2158 : 85436040 : call_stmt = dyn_cast <gcall *> (stmt);
2159 : 4645758 : if (call_stmt
2160 : 4645758 : && gimple_call_va_arg_pack_p (call_stmt)
2161 : 321 : && id->call_stmt
2162 : 319 : && ! gimple_call_va_arg_pack_p (id->call_stmt))
2163 : : {
2164 : : /* __builtin_va_arg_pack () should be replaced by
2165 : : all arguments corresponding to ... in the caller. */
2166 : 305 : tree p;
2167 : 305 : gcall *new_call;
2168 : 305 : vec<tree> argarray;
2169 : 305 : size_t nargs_caller = gimple_call_num_args (id->call_stmt);
2170 : 305 : size_t nargs = nargs_caller;
2171 : :
2172 : 785 : for (p = DECL_ARGUMENTS (id->src_fn); p; p = DECL_CHAIN (p))
2173 : : {
2174 : : /* Avoid crashing on invalid IL that doesn't have a
2175 : : varargs function or that passes not enough arguments. */
2176 : 496 : if (nargs == 0)
2177 : : break;
2178 : 480 : nargs--;
2179 : : }
2180 : :
2181 : : /* Create the new array of arguments. */
2182 : 305 : size_t nargs_callee = gimple_call_num_args (call_stmt);
2183 : 305 : size_t n = nargs + nargs_callee;
2184 : 305 : argarray.create (n);
2185 : 305 : argarray.safe_grow_cleared (n, true);
2186 : :
2187 : : /* Copy all the arguments before '...' */
2188 : 305 : if (nargs_callee)
2189 : 610 : memcpy (argarray.address (),
2190 : 305 : gimple_call_arg_ptr (call_stmt, 0),
2191 : : nargs_callee * sizeof (tree));
2192 : :
2193 : : /* Append the arguments passed in '...' */
2194 : 305 : if (nargs)
2195 : 171 : memcpy (argarray.address () + nargs_callee,
2196 : 171 : gimple_call_arg_ptr (id->call_stmt, 0)
2197 : 171 : + (nargs_caller - nargs), nargs * sizeof (tree));
2198 : :
2199 : 305 : new_call = gimple_build_call_vec (gimple_call_fn (call_stmt),
2200 : : argarray);
2201 : :
2202 : 305 : argarray.release ();
2203 : :
2204 : : /* Copy all GIMPLE_CALL flags, location and block, except
2205 : : GF_CALL_VA_ARG_PACK. */
2206 : 305 : gimple_call_copy_flags (new_call, call_stmt);
2207 : 305 : gimple_call_set_va_arg_pack (new_call, false);
2208 : 610 : gimple_call_set_fntype (new_call, gimple_call_fntype (call_stmt));
2209 : : /* location includes block. */
2210 : 305 : gimple_set_location (new_call, gimple_location (stmt));
2211 : 305 : gimple_call_set_lhs (new_call, gimple_call_lhs (call_stmt));
2212 : :
2213 : 305 : gsi_replace (©_gsi, new_call, false);
2214 : 305 : stmt = new_call;
2215 : : }
2216 : 85435735 : else if (call_stmt
2217 : 4645453 : && id->call_stmt
2218 : 3798874 : && (decl = gimple_call_fndecl (stmt))
2219 : 89113153 : && fndecl_built_in_p (decl, BUILT_IN_VA_ARG_PACK_LEN))
2220 : : {
2221 : : /* __builtin_va_arg_pack_len () should be replaced by
2222 : : the number of anonymous arguments. */
2223 : 147 : size_t nargs = gimple_call_num_args (id->call_stmt);
2224 : 147 : tree count, p;
2225 : 147 : gimple *new_stmt;
2226 : :
2227 : 423 : for (p = DECL_ARGUMENTS (id->src_fn); p; p = DECL_CHAIN (p))
2228 : 276 : nargs--;
2229 : :
2230 : 147 : if (!gimple_call_lhs (stmt))
2231 : : {
2232 : : /* Drop unused calls. */
2233 : 1 : gsi_remove (©_gsi, false);
2234 : 1 : continue;
2235 : : }
2236 : 146 : else if (!gimple_call_va_arg_pack_p (id->call_stmt))
2237 : : {
2238 : 124 : count = build_int_cst (integer_type_node, nargs);
2239 : 124 : new_stmt = gimple_build_assign (gimple_call_lhs (stmt), count);
2240 : 124 : gsi_replace (©_gsi, new_stmt, false);
2241 : 124 : stmt = new_stmt;
2242 : : }
2243 : 22 : else if (nargs != 0)
2244 : : {
2245 : 7 : tree newlhs = make_ssa_name (integer_type_node);
2246 : 7 : count = build_int_cst (integer_type_node, nargs);
2247 : 7 : new_stmt = gimple_build_assign (gimple_call_lhs (stmt),
2248 : : PLUS_EXPR, newlhs, count);
2249 : 7 : gimple_call_set_lhs (stmt, newlhs);
2250 : 7 : gsi_insert_after (©_gsi, new_stmt, GSI_NEW_STMT);
2251 : : }
2252 : : }
2253 : 85435588 : else if (call_stmt
2254 : 4645306 : && id->call_stmt
2255 : 89234315 : && gimple_call_internal_p (stmt))
2256 : 25805 : switch (gimple_call_internal_fn (stmt))
2257 : : {
2258 : 134 : case IFN_TSAN_FUNC_EXIT:
2259 : : /* Drop .TSAN_FUNC_EXIT () internal calls during inlining. */
2260 : 134 : gsi_remove (©_gsi, false);
2261 : 134 : continue;
2262 : 1042 : case IFN_ASAN_MARK:
2263 : : /* Drop .ASAN_MARK internal calls during inlining into
2264 : : no_sanitize functions. */
2265 : 1042 : if (!sanitize_flags_p (SANITIZE_ADDRESS, id->dst_fn)
2266 : 1042 : && !sanitize_flags_p (SANITIZE_HWADDRESS, id->dst_fn))
2267 : : {
2268 : 14 : gsi_remove (©_gsi, false);
2269 : 14 : continue;
2270 : : }
2271 : : break;
2272 : : default:
2273 : : break;
2274 : : }
2275 : :
2276 : : /* Statements produced by inlining can be unfolded, especially
2277 : : when we constant propagated some operands. We can't fold
2278 : : them right now for two reasons:
2279 : : 1) folding require SSA_NAME_DEF_STMTs to be correct
2280 : : 2) we can't change function calls to builtins.
2281 : : So we just mark statement for later folding. We mark
2282 : : all new statements, instead just statements that has changed
2283 : : by some nontrivial substitution so even statements made
2284 : : foldable indirectly are updated. If this turns out to be
2285 : : expensive, copy_body can be told to watch for nontrivial
2286 : : changes. */
2287 : 85435891 : if (id->statements_to_fold)
2288 : 85435891 : id->statements_to_fold->add (stmt);
2289 : :
2290 : : /* We're duplicating a CALL_EXPR. Find any corresponding
2291 : : callgraph edges and update or duplicate them. */
2292 : 85435891 : if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
2293 : : {
2294 : 4645485 : struct cgraph_edge *edge;
2295 : :
2296 : 4645485 : switch (id->transform_call_graph_edges)
2297 : : {
2298 : 3798906 : case CB_CGE_DUPLICATE:
2299 : 3798906 : edge = id->src_node->get_edge (orig_stmt);
2300 : 3798906 : if (edge)
2301 : : {
2302 : 3773249 : struct cgraph_edge *old_edge = edge;
2303 : :
2304 : : /* A speculative call is consist of multiple
2305 : : edges - indirect edge and one or more direct edges
2306 : : Duplicate the whole thing and distribute frequencies
2307 : : accordingly. */
2308 : 3773249 : if (edge->speculative)
2309 : : {
2310 : 12280 : int n = 0;
2311 : 12280 : profile_count direct_cnt
2312 : 12280 : = profile_count::zero ();
2313 : :
2314 : : /* First figure out the distribution of counts
2315 : : so we can re-scale BB profile accordingly. */
2316 : 24561 : for (cgraph_edge *e = old_edge; e;
2317 : 12281 : e = e->next_speculative_call_target ())
2318 : 12281 : direct_cnt = direct_cnt + e->count;
2319 : :
2320 : 12280 : cgraph_edge *indirect
2321 : 12280 : = old_edge->speculative_call_indirect_edge ();
2322 : 12280 : profile_count indir_cnt = indirect->count;
2323 : :
2324 : : /* Next iterate all direct edges, clone it and its
2325 : : corresponding reference and update profile. */
2326 : 12280 : for (cgraph_edge *e = old_edge;
2327 : 24561 : e;
2328 : 12281 : e = e->next_speculative_call_target ())
2329 : : {
2330 : 12281 : profile_count cnt = e->count;
2331 : :
2332 : 12281 : id->dst_node->clone_reference
2333 : 12281 : (e->speculative_call_target_ref (), stmt);
2334 : 12281 : edge = e->clone (id->dst_node, call_stmt,
2335 : : gimple_uid (stmt), num, den,
2336 : : true);
2337 : 12281 : profile_probability prob
2338 : 12281 : = cnt.probability_in (direct_cnt
2339 : : + indir_cnt);
2340 : 12281 : edge->count
2341 : : = copy_basic_block->count.apply_probability
2342 : 12281 : (prob);
2343 : 12281 : n++;
2344 : : }
2345 : 12280 : gcc_checking_assert
2346 : : (indirect->num_speculative_call_targets_p ()
2347 : : == n);
2348 : :
2349 : : /* Duplicate the indirect edge after all direct edges
2350 : : cloned. */
2351 : 12280 : indirect = indirect->clone (id->dst_node, call_stmt,
2352 : : gimple_uid (stmt),
2353 : : num, den,
2354 : : true);
2355 : :
2356 : 12280 : profile_probability prob
2357 : 12280 : = indir_cnt.probability_in (direct_cnt
2358 : : + indir_cnt);
2359 : 12280 : indirect->count
2360 : 12280 : = copy_basic_block->count.apply_probability (prob);
2361 : : }
2362 : : else
2363 : : {
2364 : 3760969 : edge = edge->clone (id->dst_node, call_stmt,
2365 : : gimple_uid (stmt),
2366 : : num, den,
2367 : : true);
2368 : 3760969 : edge->count = copy_basic_block->count;
2369 : : }
2370 : : }
2371 : : break;
2372 : :
2373 : 655482 : case CB_CGE_MOVE_CLONES:
2374 : 655482 : id->dst_node->set_call_stmt_including_clones (orig_stmt,
2375 : : call_stmt);
2376 : 655482 : edge = id->dst_node->get_edge (stmt);
2377 : 655482 : break;
2378 : :
2379 : 191097 : case CB_CGE_MOVE:
2380 : 191097 : edge = id->dst_node->get_edge (orig_stmt);
2381 : 191097 : if (edge)
2382 : 190889 : edge = cgraph_edge::set_call_stmt (edge, call_stmt);
2383 : : break;
2384 : :
2385 : 0 : default:
2386 : 0 : gcc_unreachable ();
2387 : : }
2388 : :
2389 : : /* Constant propagation on argument done during inlining
2390 : : may create new direct call. Produce an edge for it. */
2391 : 3760969 : if ((!edge
2392 : 4515106 : || (edge->indirect_inlining_edge
2393 : 3756 : && id->transform_call_graph_edges == CB_CGE_MOVE_CLONES))
2394 : 130850 : && id->dst_node->definition
2395 : 890051 : && (fn = gimple_call_fndecl (stmt)) != NULL)
2396 : : {
2397 : 0 : struct cgraph_node *dest = cgraph_node::get_create (fn);
2398 : :
2399 : : /* We have missing edge in the callgraph. This can happen
2400 : : when previous inlining turned an indirect call into a
2401 : : direct call by constant propagating arguments or we are
2402 : : producing dead clone (for further cloning). In all
2403 : : other cases we hit a bug (incorrect node sharing is the
2404 : : most common reason for missing edges). */
2405 : 0 : gcc_assert (!dest->definition
2406 : : || dest->address_taken
2407 : : || !id->src_node->definition
2408 : : || !id->dst_node->definition);
2409 : 0 : if (id->transform_call_graph_edges == CB_CGE_MOVE_CLONES)
2410 : 0 : id->dst_node->create_edge_including_clones
2411 : 0 : (dest, orig_stmt, call_stmt, bb->count,
2412 : : CIF_ORIGINALLY_INDIRECT_CALL);
2413 : : else
2414 : 0 : id->dst_node->create_edge (dest, call_stmt,
2415 : : bb->count)->inline_failed
2416 : 0 : = CIF_ORIGINALLY_INDIRECT_CALL;
2417 : 0 : if (dump_file)
2418 : : {
2419 : 0 : fprintf (dump_file, "Created new direct edge to %s\n",
2420 : : dest->dump_name ());
2421 : : }
2422 : : }
2423 : :
2424 : 4645485 : notice_special_calls (as_a <gcall *> (stmt));
2425 : : }
2426 : :
2427 : 85435891 : maybe_duplicate_eh_stmt_fn (cfun, stmt, id->src_cfun, orig_stmt,
2428 : : id->eh_map, id->eh_lp_nr);
2429 : :
2430 : 85435891 : gsi_next (©_gsi);
2431 : : }
2432 : 85436040 : while (!gsi_end_p (copy_gsi));
2433 : :
2434 : 170872058 : copy_gsi = gsi_last_bb (copy_basic_block);
2435 : : }
2436 : :
2437 : 13973963 : return copy_basic_block;
2438 : : }
2439 : :
2440 : : /* Inserting Single Entry Multiple Exit region in SSA form into code in SSA
2441 : : form is quite easy, since dominator relationship for old basic blocks does
2442 : : not change.
2443 : :
2444 : : There is however exception where inlining might change dominator relation
2445 : : across EH edges from basic block within inlined functions destinating
2446 : : to landing pads in function we inline into.
2447 : :
2448 : : The function fills in PHI_RESULTs of such PHI nodes if they refer
2449 : : to gimple regs. Otherwise, the function mark PHI_RESULT of such
2450 : : PHI nodes for renaming. For non-gimple regs, renaming is safe: the
2451 : : EH edges are abnormal and SSA_NAME_OCCURS_IN_ABNORMAL_PHI must be
2452 : : set, and this means that there will be no overlapping live ranges
2453 : : for the underlying symbol.
2454 : :
2455 : : This might change in future if we allow redirecting of EH edges and
2456 : : we might want to change way build CFG pre-inlining to include
2457 : : all the possible edges then. */
2458 : : static void
2459 : 748805 : update_ssa_across_abnormal_edges (basic_block bb, basic_block ret_bb,
2460 : : bool can_throw, bool nonlocal_goto)
2461 : : {
2462 : 748805 : edge e;
2463 : 748805 : edge_iterator ei;
2464 : :
2465 : 2078944 : FOR_EACH_EDGE (e, ei, bb->succs)
2466 : 1330139 : if (!e->dest->aux
2467 : 734421 : || ((basic_block)e->dest->aux)->index == ENTRY_BLOCK)
2468 : : {
2469 : 595718 : gphi *phi;
2470 : 595718 : gphi_iterator si;
2471 : :
2472 : 595718 : if (!nonlocal_goto)
2473 : 595476 : gcc_assert (e->flags & EDGE_EH);
2474 : :
2475 : 595718 : if (!can_throw)
2476 : 187 : gcc_assert (!(e->flags & EDGE_EH));
2477 : :
2478 : 1007319 : for (si = gsi_start_phis (e->dest); !gsi_end_p (si); gsi_next (&si))
2479 : : {
2480 : 411601 : edge re;
2481 : :
2482 : 411601 : phi = si.phi ();
2483 : :
2484 : : /* For abnormal goto/call edges the receiver can be the
2485 : : ENTRY_BLOCK. Do not assert this cannot happen. */
2486 : :
2487 : 411601 : gcc_assert ((e->flags & EDGE_EH)
2488 : : || SSA_NAME_OCCURS_IN_ABNORMAL_PHI (PHI_RESULT (phi)));
2489 : :
2490 : 411601 : re = find_edge (ret_bb, e->dest);
2491 : 411601 : gcc_checking_assert (re);
2492 : 411601 : gcc_assert ((re->flags & (EDGE_EH | EDGE_ABNORMAL))
2493 : : == (e->flags & (EDGE_EH | EDGE_ABNORMAL)));
2494 : :
2495 : 411601 : SET_USE (PHI_ARG_DEF_PTR_FROM_EDGE (phi, e),
2496 : : USE_FROM_PTR (PHI_ARG_DEF_PTR_FROM_EDGE (phi, re)));
2497 : : }
2498 : : }
2499 : 748805 : }
2500 : :
2501 : : /* Insert clobbers for automatic variables of inlined ID->src_fn
2502 : : function at the start of basic block ID->eh_landing_pad_dest. */
2503 : :
2504 : : static void
2505 : 433427 : add_clobbers_to_eh_landing_pad (copy_body_data *id)
2506 : : {
2507 : 433427 : tree var;
2508 : 433427 : basic_block bb = id->eh_landing_pad_dest;
2509 : 433427 : live_vars_map *vars = NULL;
2510 : 433427 : unsigned int cnt = 0;
2511 : 433427 : unsigned int i;
2512 : 1016057 : FOR_EACH_VEC_SAFE_ELT (id->src_cfun->local_decls, i, var)
2513 : 582630 : if (VAR_P (var)
2514 : 582630 : && !DECL_HARD_REGISTER (var)
2515 : 582630 : && !TREE_THIS_VOLATILE (var)
2516 : 582610 : && !DECL_HAS_VALUE_EXPR_P (var)
2517 : 573934 : && !is_gimple_reg (var)
2518 : 241159 : && auto_var_in_fn_p (var, id->src_fn)
2519 : 821772 : && !lookup_attribute ("omp simd array", DECL_ATTRIBUTES (var)))
2520 : : {
2521 : 239142 : tree *t = id->decl_map->get (var);
2522 : 239142 : if (!t)
2523 : 0 : continue;
2524 : 239142 : tree new_var = *t;
2525 : 239142 : if (VAR_P (new_var)
2526 : 239142 : && !DECL_HARD_REGISTER (new_var)
2527 : 239142 : && !TREE_THIS_VOLATILE (new_var)
2528 : 239142 : && !DECL_HAS_VALUE_EXPR_P (new_var)
2529 : 239142 : && !is_gimple_reg (new_var)
2530 : 478284 : && auto_var_in_fn_p (new_var, id->dst_fn))
2531 : : {
2532 : 239142 : if (vars == NULL)
2533 : 144204 : vars = new live_vars_map;
2534 : 239142 : vars->put (DECL_UID (var), cnt++);
2535 : : }
2536 : : }
2537 : 433427 : if (vars == NULL)
2538 : 289223 : return;
2539 : :
2540 : 144204 : vec<bitmap_head> live = compute_live_vars (id->src_cfun, vars);
2541 : 512247 : FOR_EACH_VEC_SAFE_ELT (id->src_cfun->local_decls, i, var)
2542 : 368043 : if (VAR_P (var))
2543 : : {
2544 : 368043 : edge e;
2545 : 368043 : edge_iterator ei;
2546 : 368043 : bool needed = false;
2547 : 368043 : unsigned int *v = vars->get (DECL_UID (var));
2548 : 368043 : if (v == NULL)
2549 : 128901 : continue;
2550 : 4799754 : FOR_EACH_EDGE (e, ei, bb->preds)
2551 : 4700021 : if ((e->flags & EDGE_EH) != 0
2552 : 4699997 : && e->src->index >= id->add_clobbers_to_eh_landing_pads)
2553 : : {
2554 : 443792 : basic_block src_bb = (basic_block) e->src->aux;
2555 : :
2556 : 443792 : if (bitmap_bit_p (&live[src_bb->index], *v))
2557 : : {
2558 : : needed = true;
2559 : : break;
2560 : : }
2561 : : }
2562 : 239142 : if (needed)
2563 : : {
2564 : 139409 : tree new_var = *id->decl_map->get (var);
2565 : 139409 : gimple_stmt_iterator gsi = gsi_after_labels (bb);
2566 : 139409 : tree clobber = build_clobber (TREE_TYPE (new_var));
2567 : 139409 : gimple *clobber_stmt = gimple_build_assign (new_var, clobber);
2568 : 139409 : gsi_insert_before (&gsi, clobber_stmt, GSI_NEW_STMT);
2569 : : }
2570 : : }
2571 : 144204 : destroy_live_vars (live);
2572 : 144204 : delete vars;
2573 : : }
2574 : :
2575 : : /* Copy edges from BB into its copy constructed earlier, scale profile
2576 : : accordingly. Edges will be taken care of later. Assume aux
2577 : : pointers to point to the copies of each BB. Return true if any
2578 : : debug stmts are left after a statement that must end the basic block. */
2579 : :
2580 : : static bool
2581 : 23474055 : copy_edges_for_bb (basic_block bb, profile_count num, profile_count den,
2582 : : basic_block ret_bb, basic_block abnormal_goto_dest,
2583 : : copy_body_data *id)
2584 : : {
2585 : 23474055 : basic_block new_bb = (basic_block) bb->aux;
2586 : 23474055 : edge_iterator ei;
2587 : 23474055 : edge old_edge;
2588 : 23474055 : gimple_stmt_iterator si;
2589 : 23474055 : bool need_debug_cleanup = false;
2590 : :
2591 : : /* Use the indices from the original blocks to create edges for the
2592 : : new ones. */
2593 : 45149798 : FOR_EACH_EDGE (old_edge, ei, bb->succs)
2594 : 21675743 : if (!(old_edge->flags & EDGE_EH))
2595 : : {
2596 : 21522487 : edge new_edge;
2597 : 21522487 : int flags = old_edge->flags;
2598 : 21522487 : location_t locus = old_edge->goto_locus;
2599 : :
2600 : : /* Return edges do get a FALLTHRU flag when they get inlined. */
2601 : 21522487 : if (old_edge->dest->index == EXIT_BLOCK
2602 : 4751353 : && !(flags & (EDGE_TRUE_VALUE|EDGE_FALSE_VALUE|EDGE_FAKE))
2603 : 4751353 : && old_edge->dest->aux != EXIT_BLOCK_PTR_FOR_FN (cfun))
2604 : 4532535 : flags |= EDGE_FALLTHRU;
2605 : :
2606 : 21522487 : new_edge
2607 : 21522487 : = make_edge (new_bb, (basic_block) old_edge->dest->aux, flags);
2608 : 21522487 : new_edge->probability = old_edge->probability;
2609 : 21522487 : if (!id->reset_location)
2610 : 21522094 : new_edge->goto_locus = remap_location (locus, id);
2611 : : }
2612 : :
2613 : 23474055 : if (bb->index == ENTRY_BLOCK || bb->index == EXIT_BLOCK)
2614 : : return false;
2615 : :
2616 : : /* When doing function splitting, we must decrease count of the return block
2617 : : which was previously reachable by block we did not copy. */
2618 : 13973963 : if (single_succ_p (bb) && single_succ_edge (bb)->dest->index == EXIT_BLOCK)
2619 : 11178055 : FOR_EACH_EDGE (old_edge, ei, bb->preds)
2620 : 6426702 : if (old_edge->src->index != ENTRY_BLOCK
2621 : 3566875 : && !old_edge->src->aux)
2622 : 46544 : new_bb->count -= old_edge->count ().apply_scale (num, den);
2623 : :
2624 : : /* Walk stmts from end to start so that splitting will adjust the BB
2625 : : pointer for each stmt at most once, even when we split the block
2626 : : multiple times. */
2627 : 13973963 : bool seen_nondebug = false;
2628 : 13973963 : for (si = gsi_last_bb (new_bb); !gsi_end_p (si);)
2629 : : {
2630 : 85435898 : bool can_throw, nonlocal_goto;
2631 : 85435898 : gimple *copy_stmt = gsi_stmt (si);
2632 : :
2633 : : /* Do this before the possible split_block. */
2634 : 85435898 : gsi_prev (&si);
2635 : :
2636 : : /* If this tree could throw an exception, there are two
2637 : : cases where we need to add abnormal edge(s): the
2638 : : tree wasn't in a region and there is a "current
2639 : : region" in the caller; or the original tree had
2640 : : EH edges. In both cases split the block after the tree,
2641 : : and add abnormal edge(s) as needed; we need both
2642 : : those from the callee and the caller.
2643 : : We check whether the copy can throw, because the const
2644 : : propagation can change an INDIRECT_REF which throws
2645 : : into a COMPONENT_REF which doesn't. If the copy
2646 : : can throw, the original could also throw. */
2647 : 85435898 : can_throw = stmt_can_throw_internal (cfun, copy_stmt);
2648 : 85435898 : nonlocal_goto
2649 : 85435898 : = (stmt_can_make_abnormal_goto (copy_stmt)
2650 : 85435898 : && !computed_goto_p (copy_stmt));
2651 : :
2652 : 85435611 : if (can_throw || nonlocal_goto)
2653 : : {
2654 : : /* If there's only debug insns after copy_stmt don't split
2655 : : the block but instead mark the block for cleanup. */
2656 : 748873 : if (!seen_nondebug)
2657 : : need_debug_cleanup = true;
2658 : : else
2659 : : {
2660 : : /* Note that bb's predecessor edges aren't necessarily
2661 : : right at this point; split_block doesn't care. */
2662 : 259765 : edge e = split_block (new_bb, copy_stmt);
2663 : 259765 : e->dest->aux = new_bb->aux;
2664 : 259765 : seen_nondebug = false;
2665 : : }
2666 : : }
2667 : :
2668 : 85435898 : if (!is_gimple_debug (copy_stmt))
2669 : 32601647 : seen_nondebug = true;
2670 : :
2671 : 85435898 : bool update_probs = false;
2672 : :
2673 : 85435898 : if (gimple_code (copy_stmt) == GIMPLE_EH_DISPATCH)
2674 : : {
2675 : 9205 : make_eh_dispatch_edges (as_a <geh_dispatch *> (copy_stmt));
2676 : 9205 : update_probs = true;
2677 : : }
2678 : 85426693 : else if (can_throw)
2679 : : {
2680 : 748618 : make_eh_edge (copy_stmt);
2681 : 748618 : update_probs = true;
2682 : : }
2683 : :
2684 : : /* EH edges may not match old edges. Copy as much as possible. */
2685 : 757823 : if (update_probs)
2686 : : {
2687 : 757823 : edge e;
2688 : 757823 : edge_iterator ei;
2689 : 757823 : basic_block copy_stmt_bb = gimple_bb (copy_stmt);
2690 : :
2691 : 1542401 : FOR_EACH_EDGE (old_edge, ei, bb->succs)
2692 : 784578 : if ((old_edge->flags & EDGE_EH)
2693 : 163149 : && (e = find_edge (copy_stmt_bb,
2694 : 163149 : (basic_block) old_edge->dest->aux))
2695 : 937697 : && (e->flags & EDGE_EH))
2696 : 153119 : e->probability = old_edge->probability;
2697 : :
2698 : 2097773 : FOR_EACH_EDGE (e, ei, copy_stmt_bb->succs)
2699 : 1339950 : if (e->flags & EDGE_EH)
2700 : : {
2701 : 748618 : if (!e->probability.initialized_p ())
2702 : 595706 : e->probability = profile_probability::never ();
2703 : 748618 : if (e->dest->index < id->add_clobbers_to_eh_landing_pads)
2704 : : {
2705 : 594779 : if (id->eh_landing_pad_dest == NULL)
2706 : 433427 : id->eh_landing_pad_dest = e->dest;
2707 : : else
2708 : 161352 : gcc_assert (id->eh_landing_pad_dest == e->dest);
2709 : : }
2710 : : }
2711 : : }
2712 : :
2713 : :
2714 : : /* If the call we inline cannot make abnormal goto do not add
2715 : : additional abnormal edges but only retain those already present
2716 : : in the original function body. */
2717 : 85435898 : if (abnormal_goto_dest == NULL)
2718 : : nonlocal_goto = false;
2719 : 744 : if (nonlocal_goto)
2720 : : {
2721 : 219 : basic_block copy_stmt_bb = gimple_bb (copy_stmt);
2722 : :
2723 : 219 : if (get_abnormal_succ_dispatcher (copy_stmt_bb))
2724 : : nonlocal_goto = false;
2725 : : /* ABNORMAL_DISPATCHER (1) is for longjmp/setjmp or nonlocal gotos
2726 : : in OpenMP regions which aren't allowed to be left abnormally.
2727 : : So, no need to add abnormal edge in that case. */
2728 : 219 : else if (is_gimple_call (copy_stmt)
2729 : 219 : && gimple_call_internal_p (copy_stmt)
2730 : 0 : && (gimple_call_internal_fn (copy_stmt)
2731 : : == IFN_ABNORMAL_DISPATCHER)
2732 : 219 : && gimple_call_arg (copy_stmt, 0) == boolean_true_node)
2733 : : nonlocal_goto = false;
2734 : : else
2735 : : {
2736 : 219 : make_single_succ_edge (copy_stmt_bb, abnormal_goto_dest,
2737 : : EDGE_ABNORMAL);
2738 : 219 : gimple_call_set_ctrl_altering (copy_stmt, true);
2739 : : }
2740 : : }
2741 : :
2742 : 85435898 : if ((can_throw || nonlocal_goto)
2743 : 184845759 : && gimple_in_ssa_p (cfun))
2744 : 748805 : update_ssa_across_abnormal_edges (gimple_bb (copy_stmt), ret_bb,
2745 : : can_throw, nonlocal_goto);
2746 : : }
2747 : : return need_debug_cleanup;
2748 : : }
2749 : :
2750 : : /* Copy the PHIs. All blocks and edges are copied, some blocks
2751 : : was possibly split and new outgoing EH edges inserted.
2752 : : BB points to the block of original function and AUX pointers links
2753 : : the original and newly copied blocks. */
2754 : :
2755 : : static void
2756 : 23474055 : copy_phis_for_bb (basic_block bb, copy_body_data *id)
2757 : : {
2758 : 23474055 : basic_block const new_bb = (basic_block) bb->aux;
2759 : 23474055 : edge_iterator ei;
2760 : 23474055 : gphi *phi;
2761 : 23474055 : gphi_iterator si;
2762 : 23474055 : edge new_edge;
2763 : 23474055 : bool inserted = false;
2764 : :
2765 : 26439469 : for (si = gsi_start_phis (bb); !gsi_end_p (si); gsi_next (&si))
2766 : : {
2767 : 2965414 : tree res, new_res;
2768 : 2965414 : gphi *new_phi;
2769 : :
2770 : 2965414 : phi = si.phi ();
2771 : 2965414 : res = PHI_RESULT (phi);
2772 : 2965414 : new_res = res;
2773 : 2965414 : if (!virtual_operand_p (res)
2774 : 2965414 : && (!id->param_body_adjs
2775 : 1529729 : || !id->param_body_adjs->m_dead_stmts.contains (phi)))
2776 : : {
2777 : 1618893 : walk_tree (&new_res, copy_tree_body_r, id, NULL);
2778 : 1618893 : if (EDGE_COUNT (new_bb->preds) == 0)
2779 : : {
2780 : : /* Technically we'd want a SSA_DEFAULT_DEF here... */
2781 : 0 : SSA_NAME_DEF_STMT (new_res) = gimple_build_nop ();
2782 : : }
2783 : : else
2784 : : {
2785 : 1618893 : new_phi = create_phi_node (new_res, new_bb);
2786 : 5214546 : FOR_EACH_EDGE (new_edge, ei, new_bb->preds)
2787 : : {
2788 : 3595653 : edge old_edge = find_edge ((basic_block) new_edge->src->aux,
2789 : 3595653 : bb);
2790 : 3595653 : tree arg;
2791 : 3595653 : tree new_arg;
2792 : 3595653 : edge_iterator ei2;
2793 : 3595653 : location_t locus;
2794 : :
2795 : : /* When doing partial cloning, we allow PHIs on the entry
2796 : : block as long as all the arguments are the same.
2797 : : Find any input edge to see argument to copy. */
2798 : 3595653 : if (!old_edge)
2799 : 1846 : FOR_EACH_EDGE (old_edge, ei2, bb->preds)
2800 : 1846 : if (!old_edge->src->aux)
2801 : : break;
2802 : :
2803 : 3595653 : arg = PHI_ARG_DEF_FROM_EDGE (phi, old_edge);
2804 : 3595653 : new_arg = arg;
2805 : 3595653 : walk_tree (&new_arg, copy_tree_body_r, id, NULL);
2806 : 3595653 : gcc_assert (new_arg);
2807 : : /* With return slot optimization we can end up with
2808 : : non-gimple (foo *)&this->m, fix that here. */
2809 : 3595653 : if (TREE_CODE (new_arg) != SSA_NAME
2810 : 1466436 : && TREE_CODE (new_arg) != FUNCTION_DECL
2811 : 5062089 : && !is_gimple_val (new_arg))
2812 : : {
2813 : 12 : gimple_seq stmts = NULL;
2814 : 12 : new_arg = force_gimple_operand (new_arg, &stmts, true,
2815 : : NULL);
2816 : 12 : gsi_insert_seq_on_edge (new_edge, stmts);
2817 : 12 : inserted = true;
2818 : : }
2819 : 3595653 : locus = gimple_phi_arg_location_from_edge (phi, old_edge);
2820 : 3595653 : if (id->reset_location)
2821 : 0 : locus = input_location;
2822 : : else
2823 : 3595653 : locus = remap_location (locus, id);
2824 : 3595653 : add_phi_arg (new_phi, new_arg, new_edge, locus);
2825 : : }
2826 : : }
2827 : : }
2828 : : }
2829 : :
2830 : : /* Commit the delayed edge insertions. */
2831 : 23474055 : if (inserted)
2832 : 36 : FOR_EACH_EDGE (new_edge, ei, new_bb->preds)
2833 : 24 : gsi_commit_one_edge_insert (new_edge, NULL);
2834 : 23474055 : }
2835 : :
2836 : :
2837 : : /* Wrapper for remap_decl so it can be used as a callback. */
2838 : :
2839 : : static tree
2840 : 105435 : remap_decl_1 (tree decl, void *data)
2841 : : {
2842 : 105435 : return remap_decl (decl, (copy_body_data *) data);
2843 : : }
2844 : :
2845 : : /* Build struct function and associated datastructures for the new clone
2846 : : NEW_FNDECL to be build. CALLEE_FNDECL is the original. Function changes
2847 : : the cfun to the function of new_fndecl (and current_function_decl too). */
2848 : :
2849 : : static void
2850 : 232984 : initialize_cfun (tree new_fndecl, tree callee_fndecl, profile_count count)
2851 : : {
2852 : 232984 : struct function *src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl);
2853 : :
2854 : : /* Register specific tree functions. */
2855 : 232984 : gimple_register_cfg_hooks ();
2856 : :
2857 : : /* Get clean struct function. */
2858 : 232984 : push_struct_function (new_fndecl, true);
2859 : 232984 : targetm.target_option.relayout_function (new_fndecl);
2860 : :
2861 : : /* We will rebuild these, so just sanity check that they are empty. */
2862 : 232984 : gcc_assert (VALUE_HISTOGRAMS (cfun) == NULL);
2863 : 232984 : gcc_assert (cfun->local_decls == NULL);
2864 : 232984 : gcc_assert (cfun->cfg == NULL);
2865 : 232984 : gcc_assert (cfun->decl == new_fndecl);
2866 : :
2867 : : /* Copy items we preserve during cloning. */
2868 : 232984 : cfun->static_chain_decl = src_cfun->static_chain_decl;
2869 : 232984 : cfun->nonlocal_goto_save_area = src_cfun->nonlocal_goto_save_area;
2870 : 232984 : cfun->function_end_locus = src_cfun->function_end_locus;
2871 : 232984 : cfun->curr_properties = src_cfun->curr_properties;
2872 : 232984 : cfun->va_list_gpr_size = src_cfun->va_list_gpr_size;
2873 : 232984 : cfun->va_list_fpr_size = src_cfun->va_list_fpr_size;
2874 : 232984 : cfun->has_nonlocal_label = src_cfun->has_nonlocal_label;
2875 : 232984 : cfun->calls_eh_return = src_cfun->calls_eh_return;
2876 : 232984 : cfun->stdarg = src_cfun->stdarg;
2877 : 232984 : cfun->after_inlining = src_cfun->after_inlining;
2878 : 232984 : cfun->can_throw_non_call_exceptions
2879 : 232984 : = src_cfun->can_throw_non_call_exceptions;
2880 : 232984 : cfun->can_delete_dead_exceptions = src_cfun->can_delete_dead_exceptions;
2881 : 232984 : cfun->returns_struct = src_cfun->returns_struct;
2882 : 232984 : cfun->returns_pcc_struct = src_cfun->returns_pcc_struct;
2883 : :
2884 : 232984 : init_empty_tree_cfg ();
2885 : :
2886 : 232984 : profile_status_for_fn (cfun) = profile_status_for_fn (src_cfun);
2887 : 232984 : cfun->cfg->full_profile = src_cfun->cfg->full_profile;
2888 : :
2889 : 232984 : profile_count num = count;
2890 : 232984 : profile_count den = ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count;
2891 : 232984 : profile_count::adjust_for_ipa_scaling (&num, &den);
2892 : :
2893 : 232984 : ENTRY_BLOCK_PTR_FOR_FN (cfun)->count =
2894 : 232984 : ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count.apply_scale (num, den);
2895 : 232984 : EXIT_BLOCK_PTR_FOR_FN (cfun)->count =
2896 : 232984 : EXIT_BLOCK_PTR_FOR_FN (src_cfun)->count.apply_scale (num, den);
2897 : 232984 : if (src_cfun->eh)
2898 : 232984 : init_eh_for_function ();
2899 : :
2900 : 232984 : if (src_cfun->gimple_df)
2901 : : {
2902 : 232984 : init_tree_ssa (cfun);
2903 : 232984 : cfun->gimple_df->in_ssa_p = src_cfun->gimple_df->in_ssa_p;
2904 : 232984 : if (cfun->gimple_df->in_ssa_p)
2905 : 232984 : init_ssa_operands (cfun);
2906 : : }
2907 : 232984 : }
2908 : :
2909 : : /* Helper function for copy_cfg_body. Move debug stmts from the end
2910 : : of NEW_BB to the beginning of successor basic blocks when needed. If the
2911 : : successor has multiple predecessors, reset them, otherwise keep
2912 : : their value. */
2913 : :
2914 : : static void
2915 : 1545033 : maybe_move_debug_stmts_to_successors (copy_body_data *id, basic_block new_bb)
2916 : : {
2917 : 1545033 : edge e;
2918 : 1545033 : edge_iterator ei;
2919 : 1545033 : gimple_stmt_iterator si = gsi_last_nondebug_bb (new_bb);
2920 : :
2921 : 1545033 : if (gsi_end_p (si)
2922 : 1612265 : || gsi_one_before_end_p (si)
2923 : 1715002 : || !(stmt_can_throw_internal (cfun, gsi_stmt (si))
2924 : 67232 : || stmt_can_make_abnormal_goto (gsi_stmt (si))))
2925 : 1509528 : return;
2926 : :
2927 : 106516 : FOR_EACH_EDGE (e, ei, new_bb->succs)
2928 : : {
2929 : 71011 : gimple_stmt_iterator ssi = gsi_last_bb (new_bb);
2930 : 71011 : gimple_stmt_iterator dsi = gsi_after_labels (e->dest);
2931 : 227419 : while (is_gimple_debug (gsi_stmt (ssi)))
2932 : : {
2933 : 156408 : gimple *stmt = gsi_stmt (ssi);
2934 : 156408 : gdebug *new_stmt;
2935 : 156408 : tree var;
2936 : 156408 : tree value;
2937 : :
2938 : : /* For the last edge move the debug stmts instead of copying
2939 : : them. */
2940 : 156408 : if (ei_one_before_end_p (ei))
2941 : : {
2942 : 78203 : si = ssi;
2943 : 78203 : gsi_prev (&ssi);
2944 : 78203 : if (!single_pred_p (e->dest) && gimple_debug_bind_p (stmt))
2945 : : {
2946 : 76648 : gimple_debug_bind_reset_value (stmt);
2947 : 152558 : gimple_set_location (stmt, UNKNOWN_LOCATION);
2948 : : }
2949 : 78203 : gsi_remove (&si, false);
2950 : 78203 : gsi_insert_before (&dsi, stmt, GSI_NEW_STMT);
2951 : 78203 : continue;
2952 : : }
2953 : :
2954 : 78205 : if (gimple_debug_bind_p (stmt))
2955 : : {
2956 : 76650 : var = gimple_debug_bind_get_var (stmt);
2957 : 76650 : if (single_pred_p (e->dest))
2958 : : {
2959 : 52421 : value = gimple_debug_bind_get_value (stmt);
2960 : 52421 : value = unshare_expr (value);
2961 : 52421 : new_stmt = gimple_build_debug_bind (var, value, stmt);
2962 : : }
2963 : : else
2964 : 24229 : new_stmt = gimple_build_debug_bind (var, NULL_TREE, NULL);
2965 : : }
2966 : 1555 : else if (gimple_debug_source_bind_p (stmt))
2967 : : {
2968 : 0 : var = gimple_debug_source_bind_get_var (stmt);
2969 : 0 : value = gimple_debug_source_bind_get_value (stmt);
2970 : 0 : new_stmt = gimple_build_debug_source_bind (var, value, stmt);
2971 : : }
2972 : 1555 : else if (gimple_debug_nonbind_marker_p (stmt))
2973 : 1555 : new_stmt = as_a <gdebug *> (gimple_copy (stmt));
2974 : : else
2975 : 0 : gcc_unreachable ();
2976 : 78205 : gsi_insert_before (&dsi, new_stmt, GSI_NEW_STMT);
2977 : 78205 : id->debug_stmts.safe_push (new_stmt);
2978 : 78205 : gsi_prev (&ssi);
2979 : : }
2980 : : }
2981 : : }
2982 : :
2983 : : /* Make a copy of the sub-loops of SRC_PARENT and place them
2984 : : as siblings of DEST_PARENT. */
2985 : :
2986 : : static void
2987 : 5414673 : copy_loops (copy_body_data *id,
2988 : : class loop *dest_parent, class loop *src_parent)
2989 : : {
2990 : 5414673 : class loop *src_loop = src_parent->inner;
2991 : 6032467 : while (src_loop)
2992 : : {
2993 : 617794 : if (!id->blocks_to_copy
2994 : 617794 : || bitmap_bit_p (id->blocks_to_copy, src_loop->header->index))
2995 : : {
2996 : 614573 : class loop *dest_loop = alloc_loop ();
2997 : :
2998 : : /* Assign the new loop its header and latch and associate
2999 : : those with the new loop. */
3000 : 614573 : dest_loop->header = (basic_block)src_loop->header->aux;
3001 : 614573 : dest_loop->header->loop_father = dest_loop;
3002 : 614573 : if (src_loop->latch != NULL)
3003 : : {
3004 : 614557 : dest_loop->latch = (basic_block)src_loop->latch->aux;
3005 : 614557 : dest_loop->latch->loop_father = dest_loop;
3006 : : }
3007 : :
3008 : : /* Copy loop meta-data. */
3009 : 614573 : copy_loop_info (src_loop, dest_loop);
3010 : 614573 : if (dest_loop->unroll)
3011 : 2558 : cfun->has_unroll = true;
3012 : 614573 : if (dest_loop->force_vectorize)
3013 : 101 : cfun->has_force_vectorize_loops = true;
3014 : 614573 : if (id->src_cfun->last_clique != 0)
3015 : 71880 : dest_loop->owned_clique
3016 : 71880 : = remap_dependence_clique (id,
3017 : 71880 : src_loop->owned_clique
3018 : : ? src_loop->owned_clique : 1);
3019 : :
3020 : : /* Finally place it into the loop array and the loop tree. */
3021 : 614573 : place_new_loop (cfun, dest_loop);
3022 : 614573 : flow_loop_tree_node_add (dest_parent, dest_loop);
3023 : :
3024 : 614573 : if (src_loop->simduid)
3025 : : {
3026 : 53 : dest_loop->simduid = remap_decl (src_loop->simduid, id);
3027 : 53 : cfun->has_simduid_loops = true;
3028 : : }
3029 : :
3030 : : /* Recurse. */
3031 : 614573 : copy_loops (id, dest_loop, src_loop);
3032 : : }
3033 : 617794 : src_loop = src_loop->next;
3034 : : }
3035 : 5414673 : }
3036 : :
3037 : : /* Call redirect_call_stmt_to_callee on all calls in BB. */
3038 : :
3039 : : void
3040 : 12517381 : redirect_all_calls (copy_body_data * id, basic_block bb)
3041 : : {
3042 : 12517381 : gimple_stmt_iterator si;
3043 : 12517381 : gimple *last = last_nondebug_stmt (bb);
3044 : 99552070 : for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
3045 : : {
3046 : 74517308 : gimple *stmt = gsi_stmt (si);
3047 : 74517308 : if (is_gimple_call (stmt))
3048 : : {
3049 : 3823468 : struct cgraph_edge *edge = id->dst_node->get_edge (stmt);
3050 : 3823468 : if (edge)
3051 : : {
3052 : 3797811 : if (!id->killed_new_ssa_names)
3053 : 2122276 : id->killed_new_ssa_names = new hash_set<tree> (16);
3054 : 3797811 : cgraph_edge::redirect_call_stmt_to_callee (edge,
3055 : : id->killed_new_ssa_names);
3056 : :
3057 : 3797811 : if (stmt == last && id->call_stmt && maybe_clean_eh_stmt (stmt))
3058 : 41297 : gimple_purge_dead_eh_edges (bb);
3059 : : }
3060 : : }
3061 : : }
3062 : 12517381 : }
3063 : :
3064 : : /* Make a copy of the body of FN so that it can be inserted inline in
3065 : : another function. Walks FN via CFG, returns new fndecl. */
3066 : :
3067 : : static tree
3068 : 4800100 : copy_cfg_body (copy_body_data * id,
3069 : : basic_block entry_block_map, basic_block exit_block_map,
3070 : : basic_block new_entry)
3071 : : {
3072 : 4800100 : tree callee_fndecl = id->src_fn;
3073 : : /* Original cfun for the callee, doesn't change. */
3074 : 4800100 : struct function *src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl);
3075 : 4800100 : struct function *cfun_to_copy;
3076 : 4800100 : basic_block bb;
3077 : 4800100 : tree new_fndecl = NULL;
3078 : 4800100 : bool need_debug_cleanup = false;
3079 : 4800100 : int last;
3080 : 4800100 : profile_count den = ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count;
3081 : 4800100 : profile_count num = entry_block_map->count;
3082 : :
3083 : 4800100 : cfun_to_copy = id->src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl);
3084 : :
3085 : : /* Register specific tree functions. */
3086 : 4800100 : gimple_register_cfg_hooks ();
3087 : :
3088 : : /* If we are offlining region of the function, make sure to connect
3089 : : new entry to ENTRY_BLOCK_PTR_FOR_FN (cfun). Since new entry can be
3090 : : part of loop, we must compute frequency and probability of
3091 : : ENTRY_BLOCK_PTR_FOR_FN (cfun) based on the frequencies and
3092 : : probabilities of edges incoming from nonduplicated region. */
3093 : 4800100 : if (new_entry)
3094 : : {
3095 : 50054 : edge e;
3096 : 50054 : edge_iterator ei;
3097 : 50054 : ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = profile_count::zero ();
3098 : :
3099 : 108556 : FOR_EACH_EDGE (e, ei, new_entry->preds)
3100 : 58502 : if (!e->src->aux)
3101 : 58502 : ENTRY_BLOCK_PTR_FOR_FN (cfun)->count += e->count ();
3102 : : /* Do not scale - the profile of offlined region should
3103 : : remain unchanged. */
3104 : 50054 : num = den = profile_count::one ();
3105 : : }
3106 : :
3107 : 4800100 : profile_count::adjust_for_ipa_scaling (&num, &den);
3108 : :
3109 : : /* Must have a CFG here at this point. */
3110 : 4800100 : gcc_assert (ENTRY_BLOCK_PTR_FOR_FN
3111 : : (DECL_STRUCT_FUNCTION (callee_fndecl)));
3112 : :
3113 : :
3114 : 4800100 : ENTRY_BLOCK_PTR_FOR_FN (cfun_to_copy)->aux = entry_block_map;
3115 : 4800100 : EXIT_BLOCK_PTR_FOR_FN (cfun_to_copy)->aux = exit_block_map;
3116 : 4800100 : entry_block_map->aux = ENTRY_BLOCK_PTR_FOR_FN (cfun_to_copy);
3117 : 4800100 : exit_block_map->aux = EXIT_BLOCK_PTR_FOR_FN (cfun_to_copy);
3118 : :
3119 : : /* Duplicate any exception-handling regions. */
3120 : 4800100 : if (cfun->eh)
3121 : 4800100 : id->eh_map = duplicate_eh_regions (cfun_to_copy, NULL, id->eh_lp_nr,
3122 : : remap_decl_1, id);
3123 : :
3124 : : /* Use aux pointers to map the original blocks to copy. */
3125 : 18948081 : FOR_EACH_BB_FN (bb, cfun_to_copy)
3126 : 14147981 : if (!id->blocks_to_copy || bitmap_bit_p (id->blocks_to_copy, bb->index))
3127 : : {
3128 : 13973963 : basic_block new_bb = copy_bb (id, bb, num, den);
3129 : 13973963 : bb->aux = new_bb;
3130 : 13973963 : new_bb->aux = bb;
3131 : 13973963 : new_bb->loop_father = entry_block_map->loop_father;
3132 : : }
3133 : :
3134 : 4800100 : last = last_basic_block_for_fn (cfun);
3135 : :
3136 : : /* Now that we've duplicated the blocks, duplicate their edges. */
3137 : 4800100 : basic_block abnormal_goto_dest = NULL;
3138 : 4800100 : if (id->call_stmt
3139 : 4800100 : && stmt_can_make_abnormal_goto (id->call_stmt))
3140 : : {
3141 : 248 : gimple_stmt_iterator gsi = gsi_for_stmt (id->call_stmt);
3142 : :
3143 : 248 : bb = gimple_bb (id->call_stmt);
3144 : 248 : gsi_next (&gsi);
3145 : 248 : if (gsi_end_p (gsi))
3146 : 248 : abnormal_goto_dest = get_abnormal_succ_dispatcher (bb);
3147 : : }
3148 : 28548281 : FOR_ALL_BB_FN (bb, cfun_to_copy)
3149 : 23748181 : if (!id->blocks_to_copy
3150 : 23748181 : || (bb->index > 0 && bitmap_bit_p (id->blocks_to_copy, bb->index)))
3151 : 23474055 : need_debug_cleanup |= copy_edges_for_bb (bb, num, den, exit_block_map,
3152 : : abnormal_goto_dest, id);
3153 : :
3154 : 4800100 : if (id->eh_landing_pad_dest)
3155 : : {
3156 : 433427 : add_clobbers_to_eh_landing_pad (id);
3157 : 433427 : id->eh_landing_pad_dest = NULL;
3158 : : }
3159 : :
3160 : 4800100 : if (new_entry)
3161 : : {
3162 : 50054 : edge e = make_edge (entry_block_map, (basic_block)new_entry->aux,
3163 : : EDGE_FALLTHRU);
3164 : 50054 : e->probability = profile_probability::always ();
3165 : : }
3166 : :
3167 : : /* Duplicate the loop tree, if available and wanted. */
3168 : 4800100 : if (loops_for_fn (src_cfun) != NULL
3169 : 4800100 : && current_loops != NULL)
3170 : : {
3171 : 4800100 : copy_loops (id, entry_block_map->loop_father,
3172 : : get_loop (src_cfun, 0));
3173 : : /* Defer to cfgcleanup to update loop-father fields of basic-blocks. */
3174 : 4800100 : loops_state_set (LOOPS_NEED_FIXUP);
3175 : : }
3176 : :
3177 : : /* If the loop tree in the source function needed fixup, mark the
3178 : : destination loop tree for fixup, too. */
3179 : 4800100 : if (loops_for_fn (src_cfun)->state & LOOPS_NEED_FIXUP)
3180 : 3 : loops_state_set (LOOPS_NEED_FIXUP);
3181 : :
3182 : 4800100 : if (gimple_in_ssa_p (cfun))
3183 : 28548281 : FOR_ALL_BB_FN (bb, cfun_to_copy)
3184 : 23748181 : if (!id->blocks_to_copy
3185 : 23748181 : || (bb->index > 0 && bitmap_bit_p (id->blocks_to_copy, bb->index)))
3186 : 23474055 : copy_phis_for_bb (bb, id);
3187 : :
3188 : 28548281 : FOR_ALL_BB_FN (bb, cfun_to_copy)
3189 : 23748181 : if (bb->aux)
3190 : : {
3191 : 23574163 : if (need_debug_cleanup
3192 : 2061826 : && bb->index != ENTRY_BLOCK
3193 : 1751036 : && bb->index != EXIT_BLOCK)
3194 : 1440246 : maybe_move_debug_stmts_to_successors (id, (basic_block) bb->aux);
3195 : : /* Update call edge destinations. This cannot be done before loop
3196 : : info is updated, because we may split basic blocks. */
3197 : 23574163 : if (id->transform_call_graph_edges == CB_CGE_DUPLICATE
3198 : 21355005 : && bb->index != ENTRY_BLOCK
3199 : 16787889 : && bb->index != EXIT_BLOCK)
3200 : 12220773 : redirect_all_calls (id, (basic_block)bb->aux);
3201 : 23574163 : ((basic_block)bb->aux)->aux = NULL;
3202 : 23574163 : bb->aux = NULL;
3203 : : }
3204 : :
3205 : : /* Zero out AUX fields of newly created block during EH edge
3206 : : insertion. */
3207 : 5096708 : for (; last < last_basic_block_for_fn (cfun); last++)
3208 : : {
3209 : 296608 : if (need_debug_cleanup)
3210 : 104787 : maybe_move_debug_stmts_to_successors (id,
3211 : 104787 : BASIC_BLOCK_FOR_FN (cfun, last));
3212 : 296608 : BASIC_BLOCK_FOR_FN (cfun, last)->aux = NULL;
3213 : : /* Update call edge destinations. This cannot be done before loop
3214 : : info is updated, because we may split basic blocks. */
3215 : 296608 : if (id->transform_call_graph_edges == CB_CGE_DUPLICATE)
3216 : 296608 : redirect_all_calls (id, BASIC_BLOCK_FOR_FN (cfun, last));
3217 : : }
3218 : 4800100 : entry_block_map->aux = NULL;
3219 : 4800100 : exit_block_map->aux = NULL;
3220 : :
3221 : 4800100 : if (id->eh_map)
3222 : : {
3223 : 4800100 : delete id->eh_map;
3224 : 4800100 : id->eh_map = NULL;
3225 : : }
3226 : 4800100 : if (id->dependence_map)
3227 : : {
3228 : 774452 : delete id->dependence_map;
3229 : 774452 : id->dependence_map = NULL;
3230 : : }
3231 : :
3232 : 4800100 : return new_fndecl;
3233 : : }
3234 : :
3235 : : /* Copy the debug STMT using ID. We deal with these statements in a
3236 : : special way: if any variable in their VALUE expression wasn't
3237 : : remapped yet, we won't remap it, because that would get decl uids
3238 : : out of sync, causing codegen differences between -g and -g0. If
3239 : : this arises, we drop the VALUE expression altogether. */
3240 : :
3241 : : static void
3242 : 52912456 : copy_debug_stmt (gdebug *stmt, copy_body_data *id)
3243 : : {
3244 : 52912456 : tree t, *n;
3245 : 52912456 : struct walk_stmt_info wi;
3246 : :
3247 : 52912456 : if (tree block = gimple_block (stmt))
3248 : : {
3249 : 35110020 : n = id->decl_map->get (block);
3250 : 35110020 : gimple_set_block (stmt, n ? *n : id->block);
3251 : : }
3252 : :
3253 : 52912456 : if (gimple_debug_nonbind_marker_p (stmt))
3254 : : {
3255 : 12588721 : if (id->call_stmt && !gimple_block (stmt))
3256 : : {
3257 : 38243 : gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
3258 : 38243 : gsi_remove (&gsi, true);
3259 : : }
3260 : 12588721 : return;
3261 : : }
3262 : :
3263 : : /* Remap all the operands in COPY. */
3264 : 40323735 : memset (&wi, 0, sizeof (wi));
3265 : 40323735 : wi.info = id;
3266 : :
3267 : 40323735 : processing_debug_stmt = 1;
3268 : :
3269 : 40323735 : if (gimple_debug_source_bind_p (stmt))
3270 : 479538 : t = gimple_debug_source_bind_get_var (stmt);
3271 : 39844197 : else if (gimple_debug_bind_p (stmt))
3272 : 39844197 : t = gimple_debug_bind_get_var (stmt);
3273 : : else
3274 : 0 : gcc_unreachable ();
3275 : :
3276 : 40323735 : if (TREE_CODE (t) == PARM_DECL
3277 : 223835 : && id->debug_map
3278 : 40325314 : && (n = id->debug_map->get (t)))
3279 : : {
3280 : 0 : gcc_assert (VAR_P (*n));
3281 : 0 : t = *n;
3282 : : }
3283 : 40323735 : else if (VAR_P (t) && !is_global_var (t) && !id->decl_map->get (t))
3284 : : /* T is a non-localized variable. */;
3285 : : else
3286 : 35994683 : walk_tree (&t, remap_gimple_op_r, &wi, NULL);
3287 : :
3288 : 40323735 : if (gimple_debug_bind_p (stmt))
3289 : : {
3290 : 39844197 : gimple_debug_bind_set_var (stmt, t);
3291 : :
3292 : 39844197 : if (gimple_debug_bind_has_value_p (stmt))
3293 : 22467276 : walk_tree (gimple_debug_bind_get_value_ptr (stmt),
3294 : : remap_gimple_op_r, &wi, NULL);
3295 : :
3296 : : /* Punt if any decl couldn't be remapped. */
3297 : 39844197 : if (processing_debug_stmt < 0)
3298 : 665450 : gimple_debug_bind_reset_value (stmt);
3299 : : }
3300 : 479538 : else if (gimple_debug_source_bind_p (stmt))
3301 : : {
3302 : 479538 : gimple_debug_source_bind_set_var (stmt, t);
3303 : : /* When inlining and source bind refers to one of the optimized
3304 : : away parameters, change the source bind into normal debug bind
3305 : : referring to the corresponding DEBUG_EXPR_DECL that should have
3306 : : been bound before the call stmt. */
3307 : 479538 : t = gimple_debug_source_bind_get_value (stmt);
3308 : 479538 : if (t != NULL_TREE
3309 : 479538 : && TREE_CODE (t) == PARM_DECL
3310 : 363140 : && id->call_stmt)
3311 : : {
3312 : 358847 : vec<tree, va_gc> **debug_args = decl_debug_args_lookup (id->src_fn);
3313 : 358847 : unsigned int i;
3314 : 358847 : if (debug_args != NULL)
3315 : : {
3316 : 479597 : for (i = 0; i < vec_safe_length (*debug_args); i += 2)
3317 : 479596 : if ((**debug_args)[i] == DECL_ORIGIN (t)
3318 : 479596 : && TREE_CODE ((**debug_args)[i + 1]) == DEBUG_EXPR_DECL)
3319 : : {
3320 : 357977 : t = (**debug_args)[i + 1];
3321 : 357977 : stmt->subcode = GIMPLE_DEBUG_BIND;
3322 : 357977 : gimple_debug_bind_set_value (stmt, t);
3323 : 357977 : break;
3324 : : }
3325 : : }
3326 : : }
3327 : 479538 : if (gimple_debug_source_bind_p (stmt))
3328 : 121561 : walk_tree (gimple_debug_source_bind_get_value_ptr (stmt),
3329 : : remap_gimple_op_r, &wi, NULL);
3330 : : }
3331 : :
3332 : 40323735 : processing_debug_stmt = 0;
3333 : :
3334 : 40323735 : update_stmt (stmt);
3335 : : }
3336 : :
3337 : : /* Process deferred debug stmts. In order to give values better odds
3338 : : of being successfully remapped, we delay the processing of debug
3339 : : stmts until all other stmts that might require remapping are
3340 : : processed. */
3341 : :
3342 : : static void
3343 : 4800100 : copy_debug_stmts (copy_body_data *id)
3344 : : {
3345 : 4800100 : if (!id->debug_stmts.exists ())
3346 : : return;
3347 : :
3348 : 55945574 : for (gdebug *stmt : id->debug_stmts)
3349 : 52912456 : copy_debug_stmt (stmt, id);
3350 : :
3351 : 3033118 : id->debug_stmts.release ();
3352 : : }
3353 : :
3354 : : /* Make a copy of the body of SRC_FN so that it can be inserted inline in
3355 : : another function. */
3356 : :
3357 : : static tree
3358 : 18379184 : copy_tree_body (copy_body_data *id)
3359 : : {
3360 : 18379184 : tree fndecl = id->src_fn;
3361 : 18379184 : tree body = DECL_SAVED_TREE (fndecl);
3362 : :
3363 : 18379184 : walk_tree (&body, copy_tree_body_r, id, NULL);
3364 : :
3365 : 18379184 : return body;
3366 : : }
3367 : :
3368 : : /* Make a copy of the body of FN so that it can be inserted inline in
3369 : : another function. */
3370 : :
3371 : : static tree
3372 : 4800100 : copy_body (copy_body_data *id,
3373 : : basic_block entry_block_map, basic_block exit_block_map,
3374 : : basic_block new_entry)
3375 : : {
3376 : 4800100 : tree fndecl = id->src_fn;
3377 : 4800100 : tree body;
3378 : :
3379 : : /* If this body has a CFG, walk CFG and copy. */
3380 : 4800100 : gcc_assert (ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (fndecl)));
3381 : 4800100 : body = copy_cfg_body (id, entry_block_map, exit_block_map,
3382 : : new_entry);
3383 : 4800100 : copy_debug_stmts (id);
3384 : 4800100 : if (id->killed_new_ssa_names)
3385 : : {
3386 : 2122276 : ipa_release_ssas_in_hash (id->killed_new_ssa_names);
3387 : 4244552 : delete id->killed_new_ssa_names;
3388 : 2122276 : id->killed_new_ssa_names = NULL;
3389 : : }
3390 : :
3391 : 4800100 : return body;
3392 : : }
3393 : :
3394 : : /* Return true if VALUE is an ADDR_EXPR of an automatic variable
3395 : : defined in function FN, or of a data member thereof. */
3396 : :
3397 : : static bool
3398 : 100705 : self_inlining_addr_expr (tree value, tree fn)
3399 : : {
3400 : 100705 : tree var;
3401 : :
3402 : 100705 : if (TREE_CODE (value) != ADDR_EXPR)
3403 : : return false;
3404 : :
3405 : 94789 : var = get_base_address (TREE_OPERAND (value, 0));
3406 : :
3407 : 94789 : return var && auto_var_in_fn_p (var, fn);
3408 : : }
3409 : :
3410 : : /* Append to BB a debug annotation that binds VAR to VALUE, inheriting
3411 : : lexical block and line number information from base_stmt, if given,
3412 : : or from the last stmt of the block otherwise. */
3413 : :
3414 : : static gimple *
3415 : 7778186 : insert_init_debug_bind (copy_body_data *id,
3416 : : basic_block bb, tree var, tree value,
3417 : : gimple *base_stmt)
3418 : : {
3419 : 7778186 : gimple *note;
3420 : 7778186 : gimple_stmt_iterator gsi;
3421 : 7778186 : tree tracked_var;
3422 : :
3423 : 9329147 : if (!gimple_in_ssa_p (id->src_cfun))
3424 : : return NULL;
3425 : :
3426 : 7778186 : if (!opt_for_fn (id->dst_fn, flag_var_tracking_assignments))
3427 : : return NULL;
3428 : :
3429 : 6886552 : tracked_var = target_for_debug_bind (var);
3430 : 6886552 : if (!tracked_var)
3431 : : return NULL;
3432 : :
3433 : 6227225 : if (bb)
3434 : : {
3435 : 6221193 : gsi = gsi_last_bb (bb);
3436 : 6221193 : if (!base_stmt && !gsi_end_p (gsi))
3437 : 6227225 : base_stmt = gsi_stmt (gsi);
3438 : : }
3439 : :
3440 : 6227225 : note = gimple_build_debug_bind (tracked_var,
3441 : 6227225 : value == error_mark_node
3442 : 6227225 : ? NULL_TREE : unshare_expr (value),
3443 : : base_stmt);
3444 : :
3445 : 6227225 : if (bb)
3446 : : {
3447 : 6221193 : if (!gsi_end_p (gsi))
3448 : 5280676 : gsi_insert_after (&gsi, note, GSI_SAME_STMT);
3449 : : else
3450 : 940517 : gsi_insert_before (&gsi, note, GSI_SAME_STMT);
3451 : : }
3452 : :
3453 : : return note;
3454 : : }
3455 : :
3456 : : static void
3457 : 478116 : insert_init_stmt (copy_body_data *id, basic_block bb, gimple *init_stmt)
3458 : : {
3459 : : /* If VAR represents a zero-sized variable, it's possible that the
3460 : : assignment statement may result in no gimple statements. */
3461 : 478116 : if (init_stmt)
3462 : : {
3463 : 478116 : gimple_stmt_iterator si = gsi_last_bb (bb);
3464 : :
3465 : : /* We can end up with init statements that store to a non-register
3466 : : from a rhs with a conversion. Handle that here by forcing the
3467 : : rhs into a temporary. gimple_regimplify_operands is not
3468 : : prepared to do this for us. */
3469 : 478116 : if (!is_gimple_debug (init_stmt)
3470 : 472084 : && !is_gimple_reg (gimple_assign_lhs (init_stmt))
3471 : 369111 : && is_gimple_reg_type (TREE_TYPE (gimple_assign_lhs (init_stmt)))
3472 : 510096 : && gimple_assign_rhs_class (init_stmt) == GIMPLE_UNARY_RHS)
3473 : : {
3474 : 2 : tree rhs = build1 (gimple_assign_rhs_code (init_stmt),
3475 : 1 : TREE_TYPE (gimple_assign_lhs (init_stmt)),
3476 : : gimple_assign_rhs1 (init_stmt));
3477 : 1 : rhs = force_gimple_operand_gsi (&si, rhs, true, NULL_TREE, false,
3478 : : GSI_NEW_STMT);
3479 : 1 : gimple_assign_set_rhs_code (init_stmt, TREE_CODE (rhs));
3480 : 1 : gimple_assign_set_rhs1 (init_stmt, rhs);
3481 : : }
3482 : 478116 : gsi_insert_after (&si, init_stmt, GSI_NEW_STMT);
3483 : 478116 : if (!is_gimple_debug (init_stmt))
3484 : : {
3485 : 472084 : gimple_regimplify_operands (init_stmt, &si);
3486 : :
3487 : 472084 : tree def = gimple_assign_lhs (init_stmt);
3488 : 472084 : insert_init_debug_bind (id, bb, def, def, init_stmt);
3489 : : }
3490 : : }
3491 : 478116 : }
3492 : :
3493 : : /* Deal with mismatched formal/actual parameters, in a rather brute-force way
3494 : : if need be (which should only be necessary for invalid programs). Attempt
3495 : : to convert VAL to TYPE and return the result if it is possible, just return
3496 : : a zero constant of the given type if it fails. */
3497 : :
3498 : : tree
3499 : 2071 : force_value_to_type (tree type, tree value)
3500 : : {
3501 : : /* If we can match up types by promotion/demotion do so. */
3502 : 2071 : if (fold_convertible_p (type, value))
3503 : 541 : return fold_convert (type, value);
3504 : :
3505 : : /* ??? For valid programs we should not end up here.
3506 : : Still if we end up with truly mismatched types here, fall back
3507 : : to using a VIEW_CONVERT_EXPR or a literal zero to not leak invalid
3508 : : GIMPLE to the following passes. */
3509 : 1530 : if (TREE_CODE (value) == WITH_SIZE_EXPR)
3510 : 0 : return error_mark_node;
3511 : 1530 : else if (!is_gimple_reg_type (TREE_TYPE (value))
3512 : 1530 : || TYPE_SIZE (type) == TYPE_SIZE (TREE_TYPE (value)))
3513 : 1239 : return fold_build1 (VIEW_CONVERT_EXPR, type, value);
3514 : : else
3515 : 291 : return build_zero_cst (type);
3516 : : }
3517 : :
3518 : : /* Initialize parameter P with VALUE. If needed, produce init statement
3519 : : at the end of BB. When BB is NULL, we return init statement to be
3520 : : output later. */
3521 : : static gimple *
3522 : 7756933 : setup_one_parameter (copy_body_data *id, tree p, tree value, tree fn,
3523 : : basic_block bb, tree *vars)
3524 : : {
3525 : 7756933 : gimple *init_stmt = NULL;
3526 : 7756933 : tree var;
3527 : 7756933 : tree def = (gimple_in_ssa_p (cfun)
3528 : 7756933 : ? ssa_default_def (id->src_cfun, p) : NULL);
3529 : :
3530 : : /* Make an equivalent VAR_DECL. Note that we must NOT remap the type
3531 : : here since the type of this decl must be visible to the calling
3532 : : function. */
3533 : 7756933 : var = copy_decl_to_var (p, id);
3534 : :
3535 : : /* Declare this new variable. */
3536 : 7756933 : DECL_CHAIN (var) = *vars;
3537 : 7756933 : *vars = var;
3538 : :
3539 : : /* Make gimplifier happy about this variable. */
3540 : 7756933 : DECL_SEEN_IN_BIND_EXPR_P (var) = 1;
3541 : :
3542 : : /* If the parameter is never assigned to, has no SSA_NAMEs created,
3543 : : we would not need to create a new variable here at all, if it
3544 : : weren't for debug info. Still, we can just use the argument
3545 : : value. */
3546 : 7756933 : if (TREE_READONLY (p)
3547 : 4190542 : && !TREE_ADDRESSABLE (p)
3548 : 4189290 : && value
3549 : 4189281 : && !TREE_SIDE_EFFECTS (value)
3550 : 11946208 : && !def)
3551 : : {
3552 : : /* We may produce non-gimple trees by adding NOPs or introduce invalid
3553 : : sharing when the value is not constant or DECL. And we need to make
3554 : : sure that it cannot be modified from another path in the callee. */
3555 : 300707 : if (((is_gimple_min_invariant (value)
3556 : : /* When the parameter is used in a context that forces it to
3557 : : not be a GIMPLE register avoid substituting something that
3558 : : is not a decl there. */
3559 : 100442 : && ! DECL_NOT_GIMPLE_REG_P (p))
3560 : 200276 : || (DECL_P (value) && TREE_READONLY (value))
3561 : 200192 : || (auto_var_in_fn_p (value, id->dst_fn)
3562 : 196 : && !TREE_ADDRESSABLE (value)))
3563 : 100708 : && useless_type_conversion_p (TREE_TYPE (p), TREE_TYPE (value))
3564 : : /* We have to be very careful about ADDR_EXPR. Make sure
3565 : : the base variable isn't a local variable of the inlined
3566 : : function, e.g., when doing recursive inlining, direct or
3567 : : mutually-recursive or whatever, which is why we don't
3568 : : just test whether fn == current_function_decl. */
3569 : 401412 : && ! self_inlining_addr_expr (value, fn))
3570 : : {
3571 : 100705 : insert_decl_map (id, p, value);
3572 : 100705 : if (!id->debug_map)
3573 : 96279 : id->debug_map = new hash_map<tree, tree>;
3574 : 100705 : id->debug_map->put (p, var);
3575 : 100705 : return insert_init_debug_bind (id, bb, var, value, NULL);
3576 : : }
3577 : : }
3578 : :
3579 : : /* Register the VAR_DECL as the equivalent for the PARM_DECL;
3580 : : that way, when the PARM_DECL is encountered, it will be
3581 : : automatically replaced by the VAR_DECL. */
3582 : 7656228 : insert_decl_map (id, p, var);
3583 : :
3584 : : /* Even if P was TREE_READONLY, the new VAR should not be. In the original
3585 : : code, we would have constructed a temporary, and then the function body
3586 : : would have never changed the value of P. However, now, we will be
3587 : : constructing VAR directly. Therefore, it must not be TREE_READONLY. */
3588 : 7656228 : TREE_READONLY (var) = 0;
3589 : :
3590 : 7656228 : tree rhs = value;
3591 : 7656228 : if (value
3592 : 7655315 : && value != error_mark_node
3593 : 15311543 : && !useless_type_conversion_p (TREE_TYPE (p), TREE_TYPE (value)))
3594 : 2060 : rhs = force_value_to_type (TREE_TYPE (p), value);
3595 : :
3596 : : /* If there is no setup required and we are in SSA, take the easy route
3597 : : replacing all SSA names representing the function parameter by the
3598 : : SSA name passed to function.
3599 : :
3600 : : We need to construct map for the variable anyway as it might be used
3601 : : in different SSA names when parameter is set in function.
3602 : :
3603 : : Do replacement at -O0 for const arguments replaced by constant.
3604 : : This is important for builtin_constant_p and other construct requiring
3605 : : constant argument to be visible in inlined function body. */
3606 : 15312456 : if (gimple_in_ssa_p (cfun) && rhs && def && is_gimple_reg (p)
3607 : 6900645 : && (optimize
3608 : 23591 : || (TREE_READONLY (p)
3609 : 11602 : && is_gimple_min_invariant (rhs)))
3610 : 6880973 : && (TREE_CODE (rhs) == SSA_NAME
3611 : 2732993 : || is_gimple_min_invariant (rhs))
3612 : 6880686 : && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (def))
3613 : : {
3614 : 6880686 : insert_decl_map (id, def, rhs);
3615 : 6880686 : return insert_init_debug_bind (id, bb, var, rhs, NULL);
3616 : : }
3617 : :
3618 : : /* If the value of argument is never used, don't care about initializing
3619 : : it. */
3620 : 1527911 : if (optimize && gimple_in_ssa_p (cfun) && !def && is_gimple_reg (p))
3621 : : {
3622 : : /* When there's a gross type mismatch between the passed value
3623 : : and the declared argument type drop it on the floor and do
3624 : : not bother to insert a debug bind. */
3625 : 324725 : if (value && !is_gimple_reg_type (TREE_TYPE (value)))
3626 : : return NULL;
3627 : 324711 : return insert_init_debug_bind (id, bb, var, rhs, NULL);
3628 : : }
3629 : :
3630 : : /* Initialize this VAR_DECL from the equivalent argument. Convert
3631 : : the argument to the proper type in case it was promoted. */
3632 : 450817 : if (value)
3633 : : {
3634 : 450730 : if (rhs == error_mark_node)
3635 : : {
3636 : 0 : insert_decl_map (id, p, var);
3637 : 0 : return insert_init_debug_bind (id, bb, var, rhs, NULL);
3638 : : }
3639 : :
3640 : 450730 : STRIP_USELESS_TYPE_CONVERSION (rhs);
3641 : :
3642 : : /* If we are in SSA form properly remap the default definition. */
3643 : 901460 : if (gimple_in_ssa_p (cfun) && is_gimple_reg (p))
3644 : : {
3645 : 22700 : if (def)
3646 : : {
3647 : 19959 : def = remap_ssa_name (def, id);
3648 : 19959 : init_stmt = gimple_build_assign (def, rhs);
3649 : 19959 : SSA_NAME_IS_DEFAULT_DEF (def) = 0;
3650 : 19959 : set_ssa_default_def (cfun, var, NULL);
3651 : : }
3652 : : }
3653 : 428030 : else if (!is_empty_type (TREE_TYPE (var)))
3654 : 369111 : init_stmt = gimple_build_assign (var, rhs);
3655 : :
3656 : 450730 : if (bb && init_stmt)
3657 : 388616 : insert_init_stmt (id, bb, init_stmt);
3658 : : }
3659 : : return init_stmt;
3660 : : }
3661 : :
3662 : : /* Generate code to initialize the parameters of the function at the
3663 : : top of the stack in ID from the GIMPLE_CALL STMT. */
3664 : :
3665 : : static void
3666 : 4567116 : initialize_inlined_parameters (copy_body_data *id, gimple *stmt,
3667 : : tree fn, basic_block bb)
3668 : : {
3669 : 4567116 : tree parms;
3670 : 4567116 : size_t i;
3671 : 4567116 : tree p;
3672 : 4567116 : tree vars = NULL_TREE;
3673 : 4567116 : tree static_chain = gimple_call_chain (stmt);
3674 : :
3675 : : /* Figure out what the parameters are. */
3676 : 4567116 : parms = DECL_ARGUMENTS (fn);
3677 : :
3678 : : /* Loop through the parameter declarations, replacing each with an
3679 : : equivalent VAR_DECL, appropriately initialized. */
3680 : 12300606 : for (p = parms, i = 0; p; p = DECL_CHAIN (p), i++)
3681 : : {
3682 : 7733490 : tree val;
3683 : 7733490 : val = i < gimple_call_num_args (stmt) ? gimple_call_arg (stmt, i) : NULL;
3684 : 7733490 : setup_one_parameter (id, p, val, fn, bb, &vars);
3685 : : }
3686 : : /* After remapping parameters remap their types. This has to be done
3687 : : in a second loop over all parameters to appropriately remap
3688 : : variable sized arrays when the size is specified in a
3689 : : parameter following the array. */
3690 : 12300606 : for (p = parms, i = 0; p; p = DECL_CHAIN (p), i++)
3691 : : {
3692 : 7733490 : tree *varp = id->decl_map->get (p);
3693 : 7733490 : if (varp && VAR_P (*varp))
3694 : : {
3695 : 15269442 : tree def = (gimple_in_ssa_p (cfun) && is_gimple_reg (p)
3696 : 7206911 : ? ssa_default_def (id->src_cfun, p) : NULL);
3697 : 7634721 : tree var = *varp;
3698 : 7634721 : TREE_TYPE (var) = remap_type (TREE_TYPE (var), id);
3699 : : /* Also remap the default definition if it was remapped
3700 : : to the default definition of the parameter replacement
3701 : : by the parameter setup. */
3702 : 7634721 : if (def)
3703 : : {
3704 : 6881154 : tree *defp = id->decl_map->get (def);
3705 : 6881154 : if (defp
3706 : 6881068 : && TREE_CODE (*defp) == SSA_NAME
3707 : 13290158 : && SSA_NAME_VAR (*defp) == var)
3708 : 19959 : TREE_TYPE (*defp) = TREE_TYPE (var);
3709 : : }
3710 : : /* When not optimizing and the parameter is unused, assign to
3711 : : a dummy SSA name. Do this after remapping the type above. */
3712 : 753567 : else if (!optimize
3713 : 3501 : && is_gimple_reg (p)
3714 : 756308 : && i < gimple_call_num_args (stmt))
3715 : : {
3716 : 2741 : tree val = gimple_call_arg (stmt, i);
3717 : 2741 : if (val != error_mark_node)
3718 : : {
3719 : 2741 : if (!useless_type_conversion_p (TREE_TYPE (p),
3720 : 2741 : TREE_TYPE (val)))
3721 : 0 : val = force_value_to_type (TREE_TYPE (p), val);
3722 : 2741 : def = make_ssa_name (var);
3723 : 2741 : gimple *init_stmt = gimple_build_assign (def, val);
3724 : 2741 : insert_init_stmt (id, bb, init_stmt);
3725 : : }
3726 : : }
3727 : : }
3728 : : }
3729 : :
3730 : : /* Initialize the static chain. */
3731 : 4567116 : p = DECL_STRUCT_FUNCTION (fn)->static_chain_decl;
3732 : 4567116 : gcc_assert (fn != current_function_decl);
3733 : 4567116 : if (p)
3734 : : {
3735 : : /* No static chain? Seems like a bug in tree-nested.cc. */
3736 : 2274 : gcc_assert (static_chain);
3737 : :
3738 : 2274 : setup_one_parameter (id, p, static_chain, fn, bb, &vars);
3739 : : }
3740 : :
3741 : : /* Reverse so the variables appear in the correct order in DWARF
3742 : : debug info. */
3743 : 4567116 : vars = nreverse (vars);
3744 : :
3745 : 4567116 : declare_inline_vars (id->block, vars);
3746 : 4567116 : }
3747 : :
3748 : :
3749 : : /* Declare a return variable to replace the RESULT_DECL for the
3750 : : function we are calling. An appropriate DECL_STMT is returned.
3751 : : The USE_STMT is filled to contain a use of the declaration to
3752 : : indicate the return value of the function.
3753 : :
3754 : : RETURN_SLOT, if non-null is place where to store the result. It
3755 : : is set only for CALL_EXPR_RETURN_SLOT_OPT. MODIFY_DEST, if non-null,
3756 : : was the LHS of the MODIFY_EXPR to which this call is the RHS.
3757 : :
3758 : : The return value is a (possibly null) value that holds the result
3759 : : as seen by the caller. */
3760 : :
3761 : : static tree
3762 : 4567116 : declare_return_variable (copy_body_data *id, tree return_slot, tree modify_dest,
3763 : : basic_block entry_bb)
3764 : : {
3765 : 4567116 : tree callee = id->src_fn;
3766 : 4567116 : tree result = DECL_RESULT (callee);
3767 : 4567116 : tree callee_type = TREE_TYPE (result);
3768 : 4567116 : tree caller_type;
3769 : 4567116 : tree var, use;
3770 : :
3771 : : /* Handle type-mismatches in the function declaration return type
3772 : : vs. the call expression. */
3773 : 4567116 : if (modify_dest)
3774 : 2111626 : caller_type = TREE_TYPE (modify_dest);
3775 : 2455490 : else if (return_slot)
3776 : 138366 : caller_type = TREE_TYPE (return_slot);
3777 : : else /* No LHS on the call. */
3778 : 2317124 : caller_type = TREE_TYPE (TREE_TYPE (callee));
3779 : :
3780 : : /* We don't need to do anything for functions that don't return anything. */
3781 : 4567116 : if (VOID_TYPE_P (callee_type))
3782 : : return NULL_TREE;
3783 : :
3784 : : /* If there was a return slot, then the return value is the
3785 : : dereferenced address of that object. */
3786 : 2403129 : if (return_slot)
3787 : : {
3788 : : /* The front end shouldn't have used both return_slot and
3789 : : a modify expression. */
3790 : 138366 : gcc_assert (!modify_dest);
3791 : 138366 : if (DECL_BY_REFERENCE (result))
3792 : : {
3793 : 80273 : tree return_slot_addr = build_fold_addr_expr (return_slot);
3794 : 80273 : STRIP_USELESS_TYPE_CONVERSION (return_slot_addr);
3795 : :
3796 : : /* We are going to construct *&return_slot and we can't do that
3797 : : for variables believed to be not addressable.
3798 : :
3799 : : FIXME: This check possibly can match, because values returned
3800 : : via return slot optimization are not believed to have address
3801 : : taken by alias analysis. */
3802 : 80273 : gcc_assert (TREE_CODE (return_slot) != SSA_NAME);
3803 : 80273 : var = return_slot_addr;
3804 : 80273 : mark_addressable (return_slot);
3805 : : }
3806 : : else
3807 : : {
3808 : 58093 : var = return_slot;
3809 : 58093 : gcc_assert (TREE_CODE (var) != SSA_NAME);
3810 : 58093 : if (TREE_ADDRESSABLE (result))
3811 : 20970 : mark_addressable (var);
3812 : : }
3813 : 138366 : if (DECL_NOT_GIMPLE_REG_P (result)
3814 : 138366 : && DECL_P (var))
3815 : 0 : DECL_NOT_GIMPLE_REG_P (var) = 1;
3816 : :
3817 : 138366 : if (!useless_type_conversion_p (callee_type, caller_type))
3818 : 80274 : var = build1 (VIEW_CONVERT_EXPR, callee_type, var);
3819 : :
3820 : 138366 : use = NULL;
3821 : 138366 : goto done;
3822 : : }
3823 : :
3824 : : /* All types requiring non-trivial constructors should have been handled. */
3825 : 2264763 : gcc_assert (!TREE_ADDRESSABLE (callee_type));
3826 : :
3827 : : /* Attempt to avoid creating a new temporary variable. */
3828 : 2264763 : if (modify_dest
3829 : 2111605 : && TREE_CODE (modify_dest) != SSA_NAME)
3830 : : {
3831 : 328326 : bool use_it = false;
3832 : :
3833 : : /* We can't use MODIFY_DEST if there's type promotion involved. */
3834 : 328326 : if (!useless_type_conversion_p (callee_type, caller_type))
3835 : : use_it = false;
3836 : :
3837 : : /* ??? If we're assigning to a variable sized type, then we must
3838 : : reuse the destination variable, because we've no good way to
3839 : : create variable sized temporaries at this point. */
3840 : 328324 : else if (!poly_int_tree_p (TYPE_SIZE_UNIT (caller_type)))
3841 : : use_it = true;
3842 : :
3843 : : /* If the callee cannot possibly modify MODIFY_DEST, then we can
3844 : : reuse it as the result of the call directly. Don't do this if
3845 : : it would promote MODIFY_DEST to addressable. */
3846 : 328324 : else if (TREE_ADDRESSABLE (result))
3847 : : use_it = false;
3848 : : else
3849 : : {
3850 : 327545 : tree base_m = get_base_address (modify_dest);
3851 : :
3852 : : /* If the base isn't a decl, then it's a pointer, and we don't
3853 : : know where that's going to go. */
3854 : 327545 : if (!DECL_P (base_m))
3855 : : use_it = false;
3856 : 322165 : else if (is_global_var (base_m))
3857 : : use_it = false;
3858 : 321805 : else if (DECL_NOT_GIMPLE_REG_P (result)
3859 : 321805 : && !DECL_NOT_GIMPLE_REG_P (base_m))
3860 : : use_it = false;
3861 : 321805 : else if (!TREE_ADDRESSABLE (base_m))
3862 : : use_it = true;
3863 : : }
3864 : :
3865 : : if (use_it)
3866 : : {
3867 : 221582 : var = modify_dest;
3868 : 221582 : use = NULL;
3869 : 221582 : goto done;
3870 : : }
3871 : : }
3872 : :
3873 : 2043181 : gcc_assert (poly_int_tree_p (TYPE_SIZE_UNIT (callee_type)));
3874 : :
3875 : 2043181 : var = copy_result_decl_to_var (result, id);
3876 : 2043181 : DECL_SEEN_IN_BIND_EXPR_P (var) = 1;
3877 : :
3878 : : /* Do not have the rest of GCC warn about this variable as it should
3879 : : not be visible to the user. */
3880 : 2043181 : suppress_warning (var /* OPT_Wuninitialized? */);
3881 : :
3882 : 2043181 : declare_inline_vars (id->block, var);
3883 : :
3884 : : /* Build the use expr. If the return type of the function was
3885 : : promoted, convert it back to the expected type. */
3886 : 2043181 : use = var;
3887 : 2043181 : if (!useless_type_conversion_p (caller_type, TREE_TYPE (var)))
3888 : : {
3889 : : /* If we can match up types by promotion/demotion do so. */
3890 : 7 : if (fold_convertible_p (caller_type, var))
3891 : 0 : use = fold_convert (caller_type, var);
3892 : : else
3893 : : {
3894 : : /* ??? For valid programs we should not end up here.
3895 : : Still if we end up with truly mismatched types here, fall back
3896 : : to using a MEM_REF to not leak invalid GIMPLE to the following
3897 : : passes. */
3898 : : /* Prevent var from being written into SSA form. */
3899 : 7 : if (is_gimple_reg_type (TREE_TYPE (var)))
3900 : 7 : DECL_NOT_GIMPLE_REG_P (var) = true;
3901 : 7 : use = fold_build2 (MEM_REF, caller_type,
3902 : : build_fold_addr_expr (var),
3903 : : build_int_cst (ptr_type_node, 0));
3904 : : }
3905 : : }
3906 : :
3907 : 2043181 : STRIP_USELESS_TYPE_CONVERSION (use);
3908 : :
3909 : 2043181 : if (DECL_BY_REFERENCE (result))
3910 : : {
3911 : 0 : TREE_ADDRESSABLE (var) = 1;
3912 : 0 : var = build_fold_addr_expr (var);
3913 : : }
3914 : :
3915 : 2043181 : done:
3916 : : /* Register the VAR_DECL as the equivalent for the RESULT_DECL; that
3917 : : way, when the RESULT_DECL is encountered, it will be
3918 : : automatically replaced by the VAR_DECL.
3919 : :
3920 : : When returning by reference, ensure that RESULT_DECL remaps to
3921 : : gimple_val. */
3922 : 2403129 : if (DECL_BY_REFERENCE (result)
3923 : 2403129 : && !is_gimple_val (var))
3924 : : {
3925 : 80273 : tree temp = create_tmp_var (TREE_TYPE (result), "retvalptr");
3926 : 80273 : insert_decl_map (id, result, temp);
3927 : : /* When RESULT_DECL is in SSA form, we need to remap and initialize
3928 : : it's default_def SSA_NAME. */
3929 : 80273 : if (gimple_in_ssa_p (id->src_cfun)
3930 : 80273 : && is_gimple_reg (result))
3931 : 80273 : if (tree default_def = ssa_default_def (id->src_cfun, result))
3932 : : {
3933 : 80236 : temp = make_ssa_name (temp);
3934 : 80236 : insert_decl_map (id, default_def, temp);
3935 : : }
3936 : 80273 : insert_init_stmt (id, entry_bb, gimple_build_assign (temp, var));
3937 : : }
3938 : : else
3939 : 2322856 : insert_decl_map (id, result, var);
3940 : :
3941 : : /* Remember this so we can ignore it in remap_decls. */
3942 : 2403129 : id->retvar = var;
3943 : 2403129 : return use;
3944 : : }
3945 : :
3946 : : /* Determine if the function can be copied. If so return NULL. If
3947 : : not return a string describng the reason for failure. */
3948 : :
3949 : : const char *
3950 : 17264258 : copy_forbidden (struct function *fun)
3951 : : {
3952 : 17264258 : const char *reason = fun->cannot_be_copied_reason;
3953 : :
3954 : : /* Only examine the function once. */
3955 : 17264258 : if (fun->cannot_be_copied_set)
3956 : : return reason;
3957 : :
3958 : : /* We cannot copy a function that receives a non-local goto
3959 : : because we cannot remap the destination label used in the
3960 : : function that is performing the non-local goto. */
3961 : : /* ??? Actually, this should be possible, if we work at it.
3962 : : No doubt there's just a handful of places that simply
3963 : : assume it doesn't happen and don't substitute properly. */
3964 : 9854514 : if (fun->has_nonlocal_label)
3965 : : {
3966 : 778 : reason = G_("function %q+F can never be copied "
3967 : : "because it receives a non-local goto");
3968 : 778 : goto fail;
3969 : : }
3970 : :
3971 : 9853736 : if (fun->has_forced_label_in_static)
3972 : : {
3973 : 223 : reason = G_("function %q+F can never be copied because it saves "
3974 : : "address of local label in a static variable");
3975 : 223 : goto fail;
3976 : : }
3977 : :
3978 : 9853513 : fail:
3979 : 9854514 : fun->cannot_be_copied_reason = reason;
3980 : 9854514 : fun->cannot_be_copied_set = true;
3981 : 9854514 : return reason;
3982 : : }
3983 : :
3984 : :
3985 : : static const char *inline_forbidden_reason;
3986 : :
3987 : : /* A callback for walk_gimple_seq to handle statements. Returns non-null
3988 : : iff a function cannot be inlined. Also sets the reason why. */
3989 : :
3990 : : static tree
3991 : 170733878 : inline_forbidden_p_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
3992 : : struct walk_stmt_info *wip)
3993 : : {
3994 : 170733878 : tree fn = (tree) wip->info;
3995 : 170733878 : tree t;
3996 : 170733878 : gimple *stmt = gsi_stmt (*gsi);
3997 : :
3998 : 170733878 : switch (gimple_code (stmt))
3999 : : {
4000 : 18679016 : case GIMPLE_CALL:
4001 : : /* Refuse to inline alloca call unless user explicitly forced so as
4002 : : this may change program's memory overhead drastically when the
4003 : : function using alloca is called in loop. In GCC present in
4004 : : SPEC2000 inlining into schedule_block cause it to require 2GB of
4005 : : RAM instead of 256MB. Don't do so for alloca calls emitted for
4006 : : VLA objects as those can't cause unbounded growth (they're always
4007 : : wrapped inside stack_save/stack_restore regions. */
4008 : 18679016 : if (gimple_maybe_alloca_call_p (stmt)
4009 : 9544 : && !gimple_call_alloca_for_var_p (as_a <gcall *> (stmt))
4010 : 18683942 : && !lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)))
4011 : : {
4012 : 4798 : inline_forbidden_reason
4013 : 4798 : = G_("function %q+F can never be inlined because it uses "
4014 : : "alloca (override using the always_inline attribute)");
4015 : 4798 : *handled_ops_p = true;
4016 : 4798 : return fn;
4017 : : }
4018 : :
4019 : 18674218 : t = gimple_call_fndecl (stmt);
4020 : 18674218 : if (t == NULL_TREE)
4021 : : break;
4022 : :
4023 : : /* We cannot inline functions that call setjmp. */
4024 : 18152735 : if (setjmp_call_p (t))
4025 : : {
4026 : 929 : inline_forbidden_reason
4027 : 929 : = G_("function %q+F can never be inlined because it uses setjmp");
4028 : 929 : *handled_ops_p = true;
4029 : 929 : return t;
4030 : : }
4031 : :
4032 : 18151806 : if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL)
4033 : 3626767 : switch (DECL_FUNCTION_CODE (t))
4034 : : {
4035 : : /* We cannot inline functions that take a variable number of
4036 : : arguments. */
4037 : 2695 : case BUILT_IN_VA_START:
4038 : 2695 : case BUILT_IN_NEXT_ARG:
4039 : 2695 : case BUILT_IN_VA_END:
4040 : 2695 : inline_forbidden_reason
4041 : 2695 : = G_("function %q+F can never be inlined because it "
4042 : : "uses variable argument lists");
4043 : 2695 : *handled_ops_p = true;
4044 : 2695 : return t;
4045 : :
4046 : 226 : case BUILT_IN_LONGJMP:
4047 : : /* We can't inline functions that call __builtin_longjmp at
4048 : : all. The non-local goto machinery really requires the
4049 : : destination be in a different function. If we allow the
4050 : : function calling __builtin_longjmp to be inlined into the
4051 : : function calling __builtin_setjmp, Things will Go Awry. */
4052 : 226 : inline_forbidden_reason
4053 : 226 : = G_("function %q+F can never be inlined because "
4054 : : "it uses setjmp-longjmp exception handling");
4055 : 226 : *handled_ops_p = true;
4056 : 226 : return t;
4057 : :
4058 : 269 : case BUILT_IN_NONLOCAL_GOTO:
4059 : : /* Similarly. */
4060 : 269 : inline_forbidden_reason
4061 : 269 : = G_("function %q+F can never be inlined because "
4062 : : "it uses non-local goto");
4063 : 269 : *handled_ops_p = true;
4064 : 269 : return t;
4065 : :
4066 : 384 : case BUILT_IN_RETURN:
4067 : 384 : case BUILT_IN_APPLY_ARGS:
4068 : : /* If a __builtin_apply_args caller would be inlined,
4069 : : it would be saving arguments of the function it has
4070 : : been inlined into. Similarly __builtin_return would
4071 : : return from the function the inline has been inlined into. */
4072 : 384 : inline_forbidden_reason
4073 : 384 : = G_("function %q+F can never be inlined because "
4074 : : "it uses %<__builtin_return%> or %<__builtin_apply_args%>");
4075 : 384 : *handled_ops_p = true;
4076 : 384 : return t;
4077 : :
4078 : : default:
4079 : : break;
4080 : : }
4081 : : break;
4082 : :
4083 : 284 : case GIMPLE_GOTO:
4084 : 284 : t = gimple_goto_dest (stmt);
4085 : :
4086 : : /* We will not inline a function which uses computed goto. The
4087 : : addresses of its local labels, which may be tucked into
4088 : : global storage, are of course not constant across
4089 : : instantiations, which causes unexpected behavior. */
4090 : 284 : if (TREE_CODE (t) != LABEL_DECL)
4091 : : {
4092 : 284 : inline_forbidden_reason
4093 : 284 : = G_("function %q+F can never be inlined "
4094 : : "because it contains a computed goto");
4095 : 284 : *handled_ops_p = true;
4096 : 284 : return t;
4097 : : }
4098 : : break;
4099 : :
4100 : : default:
4101 : : break;
4102 : : }
4103 : :
4104 : 170724293 : *handled_ops_p = false;
4105 : 170724293 : return NULL_TREE;
4106 : : }
4107 : :
4108 : : /* Return true if FNDECL is a function that cannot be inlined into
4109 : : another one. */
4110 : :
4111 : : static bool
4112 : 5899753 : inline_forbidden_p (tree fndecl)
4113 : : {
4114 : 5899753 : struct function *fun = DECL_STRUCT_FUNCTION (fndecl);
4115 : 5899753 : struct walk_stmt_info wi;
4116 : 5899753 : basic_block bb;
4117 : 5899753 : bool forbidden_p = false;
4118 : :
4119 : : /* First check for shared reasons not to copy the code. */
4120 : 5899753 : inline_forbidden_reason = copy_forbidden (fun);
4121 : 5899753 : if (inline_forbidden_reason != NULL)
4122 : : return true;
4123 : :
4124 : : /* Next, walk the statements of the function looking for
4125 : : constraucts we can't handle, or are non-optimal for inlining. */
4126 : 5899057 : hash_set<tree> visited_nodes;
4127 : 5899057 : memset (&wi, 0, sizeof (wi));
4128 : 5899057 : wi.info = (void *) fndecl;
4129 : 5899057 : wi.pset = &visited_nodes;
4130 : :
4131 : : /* We cannot inline a function with a variable-sized parameter because we
4132 : : cannot materialize a temporary of such a type in the caller if need be.
4133 : : Note that the return case is not symmetrical because we can guarantee
4134 : : that a temporary is not needed by means of CALL_EXPR_RETURN_SLOT_OPT. */
4135 : 18665032 : for (tree parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm))
4136 : 12765977 : if (!poly_int_tree_p (DECL_SIZE (parm)))
4137 : : {
4138 : 2 : inline_forbidden_reason
4139 : 2 : = G_("function %q+F can never be inlined because "
4140 : : "it has a VLA argument");
4141 : 2 : return true;
4142 : : }
4143 : :
4144 : 38098046 : FOR_EACH_BB_FN (bb, fun)
4145 : : {
4146 : 32208576 : gimple *ret;
4147 : 32208576 : gimple_seq seq = bb_seq (bb);
4148 : 32208576 : ret = walk_gimple_seq (seq, inline_forbidden_p_stmt, NULL, &wi);
4149 : 32208576 : forbidden_p = (ret != NULL);
4150 : 32208576 : if (forbidden_p)
4151 : : break;
4152 : : }
4153 : :
4154 : : return forbidden_p;
4155 : 5899057 : }
4156 : :
4157 : : /* Return false if the function FNDECL cannot be inlined on account of its
4158 : : attributes, true otherwise. */
4159 : : static bool
4160 : 5899753 : function_attribute_inlinable_p (const_tree fndecl)
4161 : : {
4162 : 11777623 : for (auto scoped_attributes : targetm.attribute_table)
4163 : : {
4164 : 5899753 : const_tree a;
4165 : :
4166 : 7738404 : for (a = DECL_ATTRIBUTES (fndecl); a; a = TREE_CHAIN (a))
4167 : : {
4168 : 1860534 : const_tree name = get_attribute_name (a);
4169 : :
4170 : 53410104 : for (const attribute_spec &attribute : scoped_attributes->attributes)
4171 : 51571453 : if (is_attribute_p (attribute.name, name))
4172 : 21883 : return targetm.function_attribute_inlinable_p (fndecl);
4173 : : }
4174 : : }
4175 : :
4176 : : return true;
4177 : : }
4178 : :
4179 : : /* Returns nonzero if FN is a function that does not have any
4180 : : fundamental inline blocking properties. */
4181 : :
4182 : : bool
4183 : 6532690 : tree_inlinable_function_p (tree fn)
4184 : : {
4185 : 6532690 : bool inlinable = true;
4186 : 6532690 : bool do_warning;
4187 : 6532690 : tree always_inline;
4188 : :
4189 : : /* If we've already decided this function shouldn't be inlined,
4190 : : there's no need to check again. */
4191 : 6532690 : if (DECL_UNINLINABLE (fn))
4192 : : return false;
4193 : :
4194 : : /* We only warn for functions declared `inline' by the user. */
4195 : 5930345 : do_warning = (opt_for_fn (fn, warn_inline)
4196 : 597 : && DECL_DECLARED_INLINE_P (fn)
4197 : 468 : && !DECL_NO_INLINE_WARNING_P (fn)
4198 : 5930570 : && !DECL_IN_SYSTEM_HEADER (fn));
4199 : :
4200 : 5930345 : always_inline = lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn));
4201 : :
4202 : 5930345 : if (flag_no_inline
4203 : 106272 : && always_inline == NULL)
4204 : : {
4205 : 30592 : if (do_warning)
4206 : 0 : warning (OPT_Winline, "function %q+F can never be inlined because it "
4207 : : "is suppressed using %<-fno-inline%>", fn);
4208 : : inlinable = false;
4209 : : }
4210 : :
4211 : 5899753 : else if (!function_attribute_inlinable_p (fn))
4212 : : {
4213 : 0 : if (do_warning)
4214 : 0 : warning (OPT_Winline, "function %q+F can never be inlined because it "
4215 : : "uses attributes conflicting with inlining", fn);
4216 : : inlinable = false;
4217 : : }
4218 : :
4219 : 5899753 : else if (inline_forbidden_p (fn))
4220 : : {
4221 : : /* See if we should warn about uninlinable functions. Previously,
4222 : : some of these warnings would be issued while trying to expand
4223 : : the function inline, but that would cause multiple warnings
4224 : : about functions that would for example call alloca. But since
4225 : : this a property of the function, just one warning is enough.
4226 : : As a bonus we can now give more details about the reason why a
4227 : : function is not inlinable. */
4228 : 10283 : if (always_inline)
4229 : 2 : error (inline_forbidden_reason, fn);
4230 : 10281 : else if (do_warning)
4231 : 2 : warning (OPT_Winline, inline_forbidden_reason, fn);
4232 : :
4233 : : inlinable = false;
4234 : : }
4235 : :
4236 : : /* Squirrel away the result so that we don't have to check again. */
4237 : 5930345 : DECL_UNINLINABLE (fn) = !inlinable;
4238 : :
4239 : 5930345 : return inlinable;
4240 : : }
4241 : :
4242 : : /* Estimate the cost of a memory move of type TYPE. Use machine dependent
4243 : : word size and take possible memcpy call into account and return
4244 : : cost based on whether optimizing for size or speed according to SPEED_P. */
4245 : :
4246 : : int
4247 : 340507269 : estimate_move_cost (tree type, bool ARG_UNUSED (speed_p))
4248 : : {
4249 : 340507269 : HOST_WIDE_INT size;
4250 : :
4251 : 340507269 : gcc_assert (!VOID_TYPE_P (type));
4252 : :
4253 : 340507269 : if (VECTOR_TYPE_P (type))
4254 : : {
4255 : 3938452 : scalar_mode inner = SCALAR_TYPE_MODE (TREE_TYPE (type));
4256 : 3938452 : machine_mode simd = targetm.vectorize.preferred_simd_mode (inner);
4257 : 3938452 : int orig_mode_size
4258 : 7876904 : = estimated_poly_value (GET_MODE_SIZE (TYPE_MODE (type)));
4259 : 7876904 : int simd_mode_size = estimated_poly_value (GET_MODE_SIZE (simd));
4260 : 3938452 : return ((orig_mode_size + simd_mode_size - 1)
4261 : 3938452 : / simd_mode_size);
4262 : : }
4263 : :
4264 : 336568817 : size = int_size_in_bytes (type);
4265 : :
4266 : 336571285 : if (size < 0 || size > MOVE_MAX_PIECES * MOVE_RATIO (speed_p))
4267 : : /* Cost of a memcpy call, 3 arguments and the call. */
4268 : : return 4;
4269 : : else
4270 : 335659870 : return ((size + MOVE_MAX_PIECES - 1) / MOVE_MAX_PIECES);
4271 : : }
4272 : :
4273 : : /* Returns cost of operation CODE, according to WEIGHTS */
4274 : :
4275 : : static int
4276 : 462872667 : estimate_operator_cost (enum tree_code code, eni_weights *weights,
4277 : : tree op1 ATTRIBUTE_UNUSED, tree op2)
4278 : : {
4279 : 462872667 : switch (code)
4280 : : {
4281 : : /* These are "free" conversions, or their presumed cost
4282 : : is folded into other operations. */
4283 : : case RANGE_EXPR:
4284 : : CASE_CONVERT:
4285 : : case COMPLEX_EXPR:
4286 : : case PAREN_EXPR:
4287 : : case VIEW_CONVERT_EXPR:
4288 : : return 0;
4289 : :
4290 : : /* Assign cost of 1 to usual operations.
4291 : : ??? We may consider mapping RTL costs to this. */
4292 : : case COND_EXPR:
4293 : : case VEC_COND_EXPR:
4294 : : case VEC_PERM_EXPR:
4295 : :
4296 : : case PLUS_EXPR:
4297 : : case POINTER_PLUS_EXPR:
4298 : : case POINTER_DIFF_EXPR:
4299 : : case MINUS_EXPR:
4300 : : case MULT_EXPR:
4301 : : case MULT_HIGHPART_EXPR:
4302 : :
4303 : : case ADDR_SPACE_CONVERT_EXPR:
4304 : : case FIXED_CONVERT_EXPR:
4305 : : case FIX_TRUNC_EXPR:
4306 : :
4307 : : case NEGATE_EXPR:
4308 : : case FLOAT_EXPR:
4309 : : case MIN_EXPR:
4310 : : case MAX_EXPR:
4311 : : case ABS_EXPR:
4312 : : case ABSU_EXPR:
4313 : :
4314 : : case LSHIFT_EXPR:
4315 : : case RSHIFT_EXPR:
4316 : : case LROTATE_EXPR:
4317 : : case RROTATE_EXPR:
4318 : :
4319 : : case BIT_IOR_EXPR:
4320 : : case BIT_XOR_EXPR:
4321 : : case BIT_AND_EXPR:
4322 : : case BIT_NOT_EXPR:
4323 : :
4324 : : case TRUTH_ANDIF_EXPR:
4325 : : case TRUTH_ORIF_EXPR:
4326 : : case TRUTH_AND_EXPR:
4327 : : case TRUTH_OR_EXPR:
4328 : : case TRUTH_XOR_EXPR:
4329 : : case TRUTH_NOT_EXPR:
4330 : :
4331 : : case LT_EXPR:
4332 : : case LE_EXPR:
4333 : : case GT_EXPR:
4334 : : case GE_EXPR:
4335 : : case EQ_EXPR:
4336 : : case NE_EXPR:
4337 : : case ORDERED_EXPR:
4338 : : case UNORDERED_EXPR:
4339 : :
4340 : : case UNLT_EXPR:
4341 : : case UNLE_EXPR:
4342 : : case UNGT_EXPR:
4343 : : case UNGE_EXPR:
4344 : : case UNEQ_EXPR:
4345 : : case LTGT_EXPR:
4346 : :
4347 : : case CONJ_EXPR:
4348 : :
4349 : : case PREDECREMENT_EXPR:
4350 : : case PREINCREMENT_EXPR:
4351 : : case POSTDECREMENT_EXPR:
4352 : : case POSTINCREMENT_EXPR:
4353 : :
4354 : : case REALIGN_LOAD_EXPR:
4355 : :
4356 : : case WIDEN_SUM_EXPR:
4357 : : case WIDEN_MULT_EXPR:
4358 : : case DOT_PROD_EXPR:
4359 : : case SAD_EXPR:
4360 : : case WIDEN_MULT_PLUS_EXPR:
4361 : : case WIDEN_MULT_MINUS_EXPR:
4362 : : case WIDEN_LSHIFT_EXPR:
4363 : :
4364 : : case VEC_WIDEN_MULT_HI_EXPR:
4365 : : case VEC_WIDEN_MULT_LO_EXPR:
4366 : : case VEC_WIDEN_MULT_EVEN_EXPR:
4367 : : case VEC_WIDEN_MULT_ODD_EXPR:
4368 : : case VEC_UNPACK_HI_EXPR:
4369 : : case VEC_UNPACK_LO_EXPR:
4370 : : case VEC_UNPACK_FLOAT_HI_EXPR:
4371 : : case VEC_UNPACK_FLOAT_LO_EXPR:
4372 : : case VEC_UNPACK_FIX_TRUNC_HI_EXPR:
4373 : : case VEC_UNPACK_FIX_TRUNC_LO_EXPR:
4374 : : case VEC_PACK_TRUNC_EXPR:
4375 : : case VEC_PACK_SAT_EXPR:
4376 : : case VEC_PACK_FIX_TRUNC_EXPR:
4377 : : case VEC_PACK_FLOAT_EXPR:
4378 : : case VEC_WIDEN_LSHIFT_HI_EXPR:
4379 : : case VEC_WIDEN_LSHIFT_LO_EXPR:
4380 : : case VEC_DUPLICATE_EXPR:
4381 : : case VEC_SERIES_EXPR:
4382 : :
4383 : : return 1;
4384 : :
4385 : : /* Few special cases of expensive operations. This is useful
4386 : : to avoid inlining on functions having too many of these. */
4387 : 2966999 : case TRUNC_DIV_EXPR:
4388 : 2966999 : case CEIL_DIV_EXPR:
4389 : 2966999 : case FLOOR_DIV_EXPR:
4390 : 2966999 : case ROUND_DIV_EXPR:
4391 : 2966999 : case EXACT_DIV_EXPR:
4392 : 2966999 : case TRUNC_MOD_EXPR:
4393 : 2966999 : case CEIL_MOD_EXPR:
4394 : 2966999 : case FLOOR_MOD_EXPR:
4395 : 2966999 : case ROUND_MOD_EXPR:
4396 : 2966999 : case RDIV_EXPR:
4397 : 2966999 : if (TREE_CODE (op2) != INTEGER_CST)
4398 : 1305059 : return weights->div_mod_cost;
4399 : : return 1;
4400 : :
4401 : : /* Bit-field insertion needs several shift and mask operations. */
4402 : : case BIT_INSERT_EXPR:
4403 : : return 3;
4404 : :
4405 : 190628473 : default:
4406 : : /* We expect a copy assignment with no operator. */
4407 : 190628473 : gcc_assert (get_gimple_rhs_class (code) == GIMPLE_SINGLE_RHS);
4408 : : return 0;
4409 : : }
4410 : : }
4411 : :
4412 : :
4413 : : /* Estimate number of instructions that will be created by expanding
4414 : : the statements in the statement sequence STMTS.
4415 : : WEIGHTS contains weights attributed to various constructs. */
4416 : :
4417 : : int
4418 : 233981 : estimate_num_insns_seq (gimple_seq stmts, eni_weights *weights)
4419 : : {
4420 : 233981 : int cost;
4421 : 233981 : gimple_stmt_iterator gsi;
4422 : :
4423 : 233981 : cost = 0;
4424 : 622981 : for (gsi = gsi_start (stmts); !gsi_end_p (gsi); gsi_next (&gsi))
4425 : 389000 : cost += estimate_num_insns (gsi_stmt (gsi), weights);
4426 : :
4427 : 233981 : return cost;
4428 : : }
4429 : :
4430 : :
4431 : : /* Estimate number of instructions that will be created by expanding STMT.
4432 : : WEIGHTS contains weights attributed to various constructs. */
4433 : :
4434 : : int
4435 : 632615219 : estimate_num_insns (gimple *stmt, eni_weights *weights)
4436 : : {
4437 : 632615219 : unsigned cost, i;
4438 : 632615219 : enum gimple_code code = gimple_code (stmt);
4439 : 632615219 : tree lhs;
4440 : 632615219 : tree rhs;
4441 : :
4442 : 632615219 : switch (code)
4443 : : {
4444 : 358927683 : case GIMPLE_ASSIGN:
4445 : : /* Try to estimate the cost of assignments. We have three cases to
4446 : : deal with:
4447 : : 1) Simple assignments to registers;
4448 : : 2) Stores to things that must live in memory. This includes
4449 : : "normal" stores to scalars, but also assignments of large
4450 : : structures, or constructors of big arrays;
4451 : :
4452 : : Let us look at the first two cases, assuming we have "a = b + C":
4453 : : <GIMPLE_ASSIGN <var_decl "a">
4454 : : <plus_expr <var_decl "b"> <constant C>>
4455 : : If "a" is a GIMPLE register, the assignment to it is free on almost
4456 : : any target, because "a" usually ends up in a real register. Hence
4457 : : the only cost of this expression comes from the PLUS_EXPR, and we
4458 : : can ignore the GIMPLE_ASSIGN.
4459 : : If "a" is not a GIMPLE register, the assignment to "a" will most
4460 : : likely be a real store, so the cost of the GIMPLE_ASSIGN is the cost
4461 : : of moving something into "a", which we compute using the function
4462 : : estimate_move_cost. */
4463 : 358927683 : if (gimple_clobber_p (stmt))
4464 : : return 0; /* ={v} {CLOBBER} stmt expands to nothing. */
4465 : :
4466 : 337472550 : lhs = gimple_assign_lhs (stmt);
4467 : 337472550 : rhs = gimple_assign_rhs1 (stmt);
4468 : :
4469 : 337472550 : cost = 0;
4470 : :
4471 : : /* Account for the cost of moving to / from memory. */
4472 : 337472550 : if (gimple_store_p (stmt))
4473 : 77536072 : cost += estimate_move_cost (TREE_TYPE (lhs), weights->time_based);
4474 : 337472550 : if (gimple_assign_load_p (stmt))
4475 : 91035380 : cost += estimate_move_cost (TREE_TYPE (rhs), weights->time_based);
4476 : :
4477 : 443299092 : cost += estimate_operator_cost (gimple_assign_rhs_code (stmt), weights,
4478 : : gimple_assign_rhs1 (stmt),
4479 : 337472550 : get_gimple_rhs_class (gimple_assign_rhs_code (stmt))
4480 : : == GIMPLE_BINARY_RHS
4481 : 105826542 : ? gimple_assign_rhs2 (stmt) : NULL);
4482 : 337472550 : break;
4483 : :
4484 : 125400117 : case GIMPLE_COND:
4485 : 125400117 : cost = 1 + estimate_operator_cost (gimple_cond_code (stmt), weights,
4486 : : gimple_op (stmt, 0),
4487 : : gimple_op (stmt, 1));
4488 : 125400117 : break;
4489 : :
4490 : 912277 : case GIMPLE_SWITCH:
4491 : 912277 : {
4492 : 912277 : gswitch *switch_stmt = as_a <gswitch *> (stmt);
4493 : : /* Take into account cost of the switch + guess 2 conditional jumps for
4494 : : each case label.
4495 : :
4496 : : TODO: once the switch expansion logic is sufficiently separated, we can
4497 : : do better job on estimating cost of the switch. */
4498 : 912277 : if (weights->time_based)
4499 : 132237 : cost = floor_log2 (gimple_switch_num_labels (switch_stmt)) * 2;
4500 : : else
4501 : 780040 : cost = gimple_switch_num_labels (switch_stmt) * 2;
4502 : : }
4503 : : break;
4504 : :
4505 : 72383434 : case GIMPLE_CALL:
4506 : 72383434 : {
4507 : 72383434 : tree decl;
4508 : :
4509 : 72383434 : if (gimple_call_internal_p (stmt))
4510 : : return 0;
4511 : 70019764 : else if ((decl = gimple_call_fndecl (stmt))
4512 : 70019764 : && fndecl_built_in_p (decl))
4513 : : {
4514 : : /* Do not special case builtins where we see the body.
4515 : : This just confuse inliner. */
4516 : 17595348 : struct cgraph_node *node;
4517 : 17595348 : if ((node = cgraph_node::get (decl))
4518 : 17595348 : && node->definition)
4519 : : ;
4520 : : /* For buitins that are likely expanded to nothing or
4521 : : inlined do not account operand costs. */
4522 : 17565440 : else if (is_simple_builtin (decl))
4523 : : return 0;
4524 : 15103863 : else if (is_inexpensive_builtin (decl))
4525 : 1982044 : return weights->target_builtin_call_cost;
4526 : 13121819 : else if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
4527 : : {
4528 : : /* We canonicalize x * x to pow (x, 2.0) with -ffast-math, so
4529 : : specialize the cheap expansion we do here.
4530 : : ??? This asks for a more general solution. */
4531 : 12887850 : switch (DECL_FUNCTION_CODE (decl))
4532 : : {
4533 : 9010 : case BUILT_IN_POW:
4534 : 9010 : case BUILT_IN_POWF:
4535 : 9010 : case BUILT_IN_POWL:
4536 : 9010 : if (TREE_CODE (gimple_call_arg (stmt, 1)) == REAL_CST
4537 : 12764 : && (real_equal
4538 : 3754 : (&TREE_REAL_CST (gimple_call_arg (stmt, 1)),
4539 : : &dconst2)))
4540 : 446 : return estimate_operator_cost
4541 : 446 : (MULT_EXPR, weights, gimple_call_arg (stmt, 0),
4542 : 446 : gimple_call_arg (stmt, 0));
4543 : : break;
4544 : :
4545 : : default:
4546 : : break;
4547 : : }
4548 : : }
4549 : : }
4550 : :
4551 : 65575697 : cost = decl ? weights->call_cost : weights->indirect_call_cost;
4552 : 65575697 : if (gimple_call_lhs (stmt))
4553 : 25741591 : cost += estimate_move_cost (TREE_TYPE (gimple_call_lhs (stmt)),
4554 : 25741591 : weights->time_based);
4555 : 197538070 : for (i = 0; i < gimple_call_num_args (stmt); i++)
4556 : : {
4557 : 131962373 : tree arg = gimple_call_arg (stmt, i);
4558 : 131962373 : cost += estimate_move_cost (TREE_TYPE (arg),
4559 : 131962373 : weights->time_based);
4560 : : }
4561 : : break;
4562 : : }
4563 : :
4564 : 18162169 : case GIMPLE_RETURN:
4565 : 18162169 : return weights->return_cost;
4566 : :
4567 : : case GIMPLE_GOTO:
4568 : : case GIMPLE_LABEL:
4569 : : case GIMPLE_NOP:
4570 : : case GIMPLE_PHI:
4571 : : case GIMPLE_PREDICT:
4572 : : case GIMPLE_DEBUG:
4573 : : return 0;
4574 : :
4575 : 735952 : case GIMPLE_ASM:
4576 : 735952 : {
4577 : 735952 : int count = asm_str_count (gimple_asm_string (as_a <gasm *> (stmt)));
4578 : : /* 1000 means infinity. This avoids overflows later
4579 : : with very long asm statements. */
4580 : 735952 : if (count > 1000)
4581 : : count = 1000;
4582 : : /* If this asm is asm inline, count anything as minimum size. */
4583 : 735952 : if (gimple_asm_inline_p (as_a <gasm *> (stmt)))
4584 : 662 : count = MIN (1, count);
4585 : 735952 : return MAX (1, count);
4586 : : }
4587 : :
4588 : : case GIMPLE_RESX:
4589 : : /* This is either going to be an external function call with one
4590 : : argument, or two register copy statements plus a goto. */
4591 : : return 2;
4592 : :
4593 : 14260 : case GIMPLE_EH_DISPATCH:
4594 : : /* ??? This is going to turn into a switch statement. Ideally
4595 : : we'd have a look at the eh region and estimate the number of
4596 : : edges involved. */
4597 : 14260 : return 10;
4598 : :
4599 : 0 : case GIMPLE_BIND:
4600 : 0 : return estimate_num_insns_seq (
4601 : 0 : gimple_bind_body (as_a <gbind *> (stmt)),
4602 : 0 : weights);
4603 : :
4604 : 0 : case GIMPLE_EH_FILTER:
4605 : 0 : return estimate_num_insns_seq (gimple_eh_filter_failure (stmt), weights);
4606 : :
4607 : 8292 : case GIMPLE_CATCH:
4608 : 8292 : return estimate_num_insns_seq (gimple_catch_handler (
4609 : 8292 : as_a <gcatch *> (stmt)),
4610 : 8292 : weights);
4611 : :
4612 : 8297 : case GIMPLE_TRY:
4613 : 8297 : return (estimate_num_insns_seq (gimple_try_eval (stmt), weights)
4614 : 8297 : + estimate_num_insns_seq (gimple_try_cleanup (stmt), weights));
4615 : :
4616 : : /* OMP directives are generally very expensive. */
4617 : :
4618 : : case GIMPLE_OMP_RETURN:
4619 : : case GIMPLE_OMP_SECTIONS_SWITCH:
4620 : : case GIMPLE_OMP_ATOMIC_STORE:
4621 : : case GIMPLE_OMP_CONTINUE:
4622 : : /* ...except these, which are cheap. */
4623 : : return 0;
4624 : :
4625 : 0 : case GIMPLE_OMP_ATOMIC_LOAD:
4626 : 0 : return weights->omp_cost;
4627 : :
4628 : 0 : case GIMPLE_OMP_FOR:
4629 : 0 : return (weights->omp_cost
4630 : 0 : + estimate_num_insns_seq (gimple_omp_body (stmt), weights)
4631 : 0 : + estimate_num_insns_seq (gimple_omp_for_pre_body (stmt), weights));
4632 : :
4633 : 0 : case GIMPLE_OMP_PARALLEL:
4634 : 0 : case GIMPLE_OMP_TASK:
4635 : 0 : case GIMPLE_OMP_CRITICAL:
4636 : 0 : case GIMPLE_OMP_MASTER:
4637 : 0 : case GIMPLE_OMP_MASKED:
4638 : 0 : case GIMPLE_OMP_SCOPE:
4639 : 0 : case GIMPLE_OMP_DISPATCH:
4640 : 0 : case GIMPLE_OMP_TASKGROUP:
4641 : 0 : case GIMPLE_OMP_ORDERED:
4642 : 0 : case GIMPLE_OMP_SCAN:
4643 : 0 : case GIMPLE_OMP_SECTION:
4644 : 0 : case GIMPLE_OMP_SECTIONS:
4645 : 0 : case GIMPLE_OMP_STRUCTURED_BLOCK:
4646 : 0 : case GIMPLE_OMP_SINGLE:
4647 : 0 : case GIMPLE_OMP_TARGET:
4648 : 0 : case GIMPLE_OMP_TEAMS:
4649 : 0 : return (weights->omp_cost
4650 : 0 : + estimate_num_insns_seq (gimple_omp_body (stmt), weights));
4651 : :
4652 : 82 : case GIMPLE_TRANSACTION:
4653 : 82 : return (weights->tm_cost
4654 : 82 : + estimate_num_insns_seq (gimple_transaction_body (
4655 : 82 : as_a <gtransaction *> (stmt)),
4656 : 82 : weights));
4657 : :
4658 : 0 : default:
4659 : 0 : gcc_unreachable ();
4660 : : }
4661 : :
4662 : 529360641 : return cost;
4663 : : }
4664 : :
4665 : : /* Estimate number of instructions that will be created by expanding
4666 : : function FNDECL. WEIGHTS contains weights attributed to various
4667 : : constructs. */
4668 : :
4669 : : int
4670 : 0 : estimate_num_insns_fn (tree fndecl, eni_weights *weights)
4671 : : {
4672 : 0 : struct function *my_function = DECL_STRUCT_FUNCTION (fndecl);
4673 : 0 : gimple_stmt_iterator bsi;
4674 : 0 : basic_block bb;
4675 : 0 : int n = 0;
4676 : :
4677 : 0 : gcc_assert (my_function && my_function->cfg);
4678 : 0 : FOR_EACH_BB_FN (bb, my_function)
4679 : : {
4680 : 0 : for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi))
4681 : 0 : n += estimate_num_insns (gsi_stmt (bsi), weights);
4682 : : }
4683 : :
4684 : 0 : return n;
4685 : : }
4686 : :
4687 : :
4688 : : /* Initializes weights used by estimate_num_insns. */
4689 : :
4690 : : void
4691 : 278547 : init_inline_once (void)
4692 : : {
4693 : 278547 : eni_size_weights.call_cost = 1;
4694 : 278547 : eni_size_weights.indirect_call_cost = 3;
4695 : 278547 : eni_size_weights.target_builtin_call_cost = 1;
4696 : 278547 : eni_size_weights.div_mod_cost = 1;
4697 : 278547 : eni_size_weights.omp_cost = 40;
4698 : 278547 : eni_size_weights.tm_cost = 10;
4699 : 278547 : eni_size_weights.time_based = false;
4700 : 278547 : eni_size_weights.return_cost = 1;
4701 : :
4702 : : /* Estimating time for call is difficult, since we have no idea what the
4703 : : called function does. In the current uses of eni_time_weights,
4704 : : underestimating the cost does less harm than overestimating it, so
4705 : : we choose a rather small value here. */
4706 : 278547 : eni_time_weights.call_cost = 10;
4707 : 278547 : eni_time_weights.indirect_call_cost = 15;
4708 : 278547 : eni_time_weights.target_builtin_call_cost = 1;
4709 : 278547 : eni_time_weights.div_mod_cost = 10;
4710 : 278547 : eni_time_weights.omp_cost = 40;
4711 : 278547 : eni_time_weights.tm_cost = 40;
4712 : 278547 : eni_time_weights.time_based = true;
4713 : 278547 : eni_time_weights.return_cost = 2;
4714 : 278547 : }
4715 : :
4716 : :
4717 : : /* Install new lexical TREE_BLOCK underneath 'current_block'. */
4718 : :
4719 : : static void
4720 : 29304072 : prepend_lexical_block (tree current_block, tree new_block)
4721 : : {
4722 : 29304072 : BLOCK_CHAIN (new_block) = BLOCK_SUBBLOCKS (current_block);
4723 : 29304072 : BLOCK_SUBBLOCKS (current_block) = new_block;
4724 : 29304072 : BLOCK_SUPERCONTEXT (new_block) = current_block;
4725 : 29304072 : }
4726 : :
4727 : : /* Add local variables from CALLEE to CALLER. */
4728 : :
4729 : : static inline void
4730 : 4702235 : add_local_variables (struct function *callee, struct function *caller,
4731 : : copy_body_data *id)
4732 : : {
4733 : 4702235 : tree var;
4734 : 4702235 : unsigned ix;
4735 : :
4736 : 12738553 : FOR_EACH_LOCAL_DECL (callee, ix, var)
4737 : 4058916 : if (!can_be_nonlocal (var, id))
4738 : : {
4739 : 3972395 : tree new_var = remap_decl (var, id);
4740 : :
4741 : : /* Remap debug-expressions. */
4742 : 3972395 : if (VAR_P (new_var)
4743 : 3972395 : && DECL_HAS_DEBUG_EXPR_P (var)
4744 : 4238781 : && new_var != var)
4745 : : {
4746 : 266386 : tree tem = DECL_DEBUG_EXPR (var);
4747 : 266386 : bool old_regimplify = id->regimplify;
4748 : 266386 : id->remapping_type_depth++;
4749 : 266386 : walk_tree (&tem, copy_tree_body_r, id, NULL);
4750 : 266386 : id->remapping_type_depth--;
4751 : 266386 : id->regimplify = old_regimplify;
4752 : 266386 : SET_DECL_DEBUG_EXPR (new_var, tem);
4753 : 266386 : DECL_HAS_DEBUG_EXPR_P (new_var) = 1;
4754 : : }
4755 : 3972395 : add_local_decl (caller, new_var);
4756 : : }
4757 : 4702235 : }
4758 : :
4759 : : /* Add to BINDINGS a debug stmt resetting SRCVAR if inlining might
4760 : : have brought in or introduced any debug stmts for SRCVAR. */
4761 : :
4762 : : static inline void
4763 : 9482562 : reset_debug_binding (copy_body_data *id, tree srcvar, gimple_seq *bindings)
4764 : : {
4765 : 9482562 : tree *remappedvarp = id->decl_map->get (srcvar);
4766 : :
4767 : 9482562 : if (!remappedvarp)
4768 : : return;
4769 : :
4770 : 9426657 : if (!VAR_P (*remappedvarp))
4771 : : return;
4772 : :
4773 : 9340159 : if (*remappedvarp == id->retvar)
4774 : : return;
4775 : :
4776 : 9340159 : tree tvar = target_for_debug_bind (*remappedvarp);
4777 : 9340159 : if (!tvar)
4778 : : return;
4779 : :
4780 : 15202100 : gdebug *stmt = gimple_build_debug_bind (tvar, NULL_TREE,
4781 : 7601050 : id->call_stmt);
4782 : 7601050 : gimple_seq_add_stmt (bindings, stmt);
4783 : : }
4784 : :
4785 : : /* For each inlined variable for which we may have debug bind stmts,
4786 : : add before GSI a final debug stmt resetting it, marking the end of
4787 : : its life, so that var-tracking knows it doesn't have to compute
4788 : : further locations for it. */
4789 : :
4790 : : static inline void
4791 : 4567116 : reset_debug_bindings (copy_body_data *id, gimple_stmt_iterator gsi)
4792 : : {
4793 : 4567116 : tree var;
4794 : 4567116 : unsigned ix;
4795 : 4567116 : gimple_seq bindings = NULL;
4796 : :
4797 : 4567116 : if (!gimple_in_ssa_p (id->src_cfun))
4798 : 530995 : return;
4799 : :
4800 : 4567116 : if (!opt_for_fn (id->dst_fn, flag_var_tracking_assignments))
4801 : : return;
4802 : :
4803 : 4036121 : for (var = DECL_ARGUMENTS (id->src_fn);
4804 : 10895658 : var; var = DECL_CHAIN (var))
4805 : 6859537 : reset_debug_binding (id, var, &bindings);
4806 : :
4807 : 10071738 : FOR_EACH_LOCAL_DECL (id->src_cfun, ix, var)
4808 : 2623025 : reset_debug_binding (id, var, &bindings);
4809 : :
4810 : 4036121 : gsi_insert_seq_before_without_update (&gsi, bindings, GSI_SAME_STMT);
4811 : : }
4812 : :
4813 : : /* If STMT is a GIMPLE_CALL, replace it with its inline expansion. */
4814 : :
4815 : : static bool
4816 : 15368101 : expand_call_inline (basic_block bb, gimple *stmt, copy_body_data *id,
4817 : : bitmap to_purge)
4818 : : {
4819 : 15368101 : tree use_retvar;
4820 : 15368101 : tree fn;
4821 : 15368101 : hash_map<tree, tree> *dst;
4822 : 15368101 : hash_map<tree, tree> *st = NULL;
4823 : 15368101 : tree return_slot;
4824 : 15368101 : tree modify_dest;
4825 : 15368101 : struct cgraph_edge *cg_edge;
4826 : 15368101 : cgraph_inline_failed_t reason;
4827 : 15368101 : basic_block return_block;
4828 : 15368101 : edge e;
4829 : 15368101 : gimple_stmt_iterator gsi, stmt_gsi;
4830 : 15368101 : bool successfully_inlined = false;
4831 : 15368101 : bool purge_dead_abnormal_edges;
4832 : 15368101 : gcall *call_stmt;
4833 : 15368101 : unsigned int prop_mask, src_properties;
4834 : 15368101 : struct function *dst_cfun;
4835 : 15368101 : tree simduid;
4836 : 15368101 : use_operand_p use;
4837 : 15368101 : gimple *simtenter_stmt = NULL;
4838 : 15368101 : vec<tree> *simtvars_save;
4839 : 15368101 : tree save_stack = NULL_TREE;
4840 : :
4841 : : /* The gimplifier uses input_location in too many places, such as
4842 : : internal_get_tmp_var (). */
4843 : 15368101 : location_t saved_location = input_location;
4844 : 15368101 : input_location = gimple_location (stmt);
4845 : :
4846 : : /* From here on, we're only interested in CALL_EXPRs. */
4847 : 15368101 : call_stmt = dyn_cast <gcall *> (stmt);
4848 : 15368101 : if (!call_stmt)
4849 : 0 : goto egress;
4850 : :
4851 : 15368101 : cg_edge = id->dst_node->get_edge (stmt);
4852 : : /* Edge should exist and speculations should be resolved at this
4853 : : stage. */
4854 : 15368101 : gcc_checking_assert (cg_edge && !cg_edge->speculative);
4855 : : /* First, see if we can figure out what function is being called.
4856 : : If we cannot, then there is no hope of inlining the function. */
4857 : 15368101 : if (cg_edge->indirect_unknown_callee)
4858 : 249304 : goto egress;
4859 : 15118797 : fn = cg_edge->callee->decl;
4860 : 15118797 : gcc_checking_assert (fn);
4861 : :
4862 : : /* If FN is a declaration of a function in a nested scope that was
4863 : : globally declared inline, we don't set its DECL_INITIAL.
4864 : : However, we can't blindly follow DECL_ABSTRACT_ORIGIN because the
4865 : : C++ front-end uses it for cdtors to refer to their internal
4866 : : declarations, that are not real functions. Fortunately those
4867 : : don't have trees to be saved, so we can tell by checking their
4868 : : gimple_body. */
4869 : 15118797 : if (!DECL_INITIAL (fn)
4870 : 6519108 : && DECL_ABSTRACT_ORIGIN (fn)
4871 : 15263697 : && gimple_has_body_p (DECL_ABSTRACT_ORIGIN (fn)))
4872 : 320 : fn = DECL_ABSTRACT_ORIGIN (fn);
4873 : :
4874 : : /* Don't try to inline functions that are not well-suited to inlining. */
4875 : 15118797 : if (cg_edge->inline_failed)
4876 : : {
4877 : 10551487 : reason = cg_edge->inline_failed;
4878 : : /* If this call was originally indirect, we do not want to emit any
4879 : : inlining related warnings or sorry messages because there are no
4880 : : guarantees regarding those. */
4881 : 10551487 : if (cg_edge->indirect_inlining_edge)
4882 : 1887 : goto egress;
4883 : :
4884 : 10549600 : if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn))
4885 : : /* For extern inline functions that get redefined we always
4886 : : silently ignored always_inline flag. Better behavior would
4887 : : be to be able to keep both bodies and use extern inline body
4888 : : for inlining, but we can't do that because frontends overwrite
4889 : : the body. */
4890 : 53 : && !cg_edge->callee->redefined_extern_inline
4891 : : /* During early inline pass, report only when optimization is
4892 : : not turned on. */
4893 : 53 : && (symtab->global_info_ready
4894 : 51 : || !optimize
4895 : 41 : || cgraph_inline_failed_type (reason) == CIF_FINAL_ERROR)
4896 : : /* PR 20090218-1_0.c. Body can be provided by another module. */
4897 : 10549634 : && (reason != CIF_BODY_NOT_AVAILABLE || !flag_generate_lto))
4898 : : {
4899 : 27 : error ("inlining failed in call to %<always_inline%> %q+F: %s", fn,
4900 : : cgraph_inline_failed_string (reason));
4901 : 27 : if (gimple_location (stmt) != UNKNOWN_LOCATION)
4902 : 27 : inform (gimple_location (stmt), "called from here");
4903 : 0 : else if (DECL_SOURCE_LOCATION (cfun->decl) != UNKNOWN_LOCATION)
4904 : 0 : inform (DECL_SOURCE_LOCATION (cfun->decl),
4905 : : "called from this function");
4906 : : }
4907 : 10549573 : else if (opt_for_fn (fn, warn_inline)
4908 : 257 : && DECL_DECLARED_INLINE_P (fn)
4909 : 106 : && !DECL_NO_INLINE_WARNING_P (fn)
4910 : 38 : && !DECL_IN_SYSTEM_HEADER (fn)
4911 : 38 : && reason != CIF_UNSPECIFIED
4912 : 38 : && !lookup_attribute ("noinline", DECL_ATTRIBUTES (fn))
4913 : : /* Do not warn about not inlined recursive calls. */
4914 : 38 : && !cg_edge->recursive_p ()
4915 : : /* Avoid warnings during early inline pass. */
4916 : 10549611 : && symtab->global_info_ready)
4917 : : {
4918 : 8 : auto_diagnostic_group d;
4919 : 8 : if (warning (OPT_Winline, "inlining failed in call to %q+F: %s",
4920 : : fn, _(cgraph_inline_failed_string (reason))))
4921 : : {
4922 : 8 : if (gimple_location (stmt) != UNKNOWN_LOCATION)
4923 : 8 : inform (gimple_location (stmt), "called from here");
4924 : 0 : else if (DECL_SOURCE_LOCATION (cfun->decl) != UNKNOWN_LOCATION)
4925 : 0 : inform (DECL_SOURCE_LOCATION (cfun->decl),
4926 : : "called from this function");
4927 : : }
4928 : 8 : }
4929 : 10549600 : goto egress;
4930 : : }
4931 : 4567310 : id->src_node = cg_edge->callee;
4932 : :
4933 : : /* If callee is thunk, all we need is to adjust the THIS pointer
4934 : : and redirect to function being thunked. */
4935 : 4567310 : if (id->src_node->thunk)
4936 : : {
4937 : 194 : cgraph_edge *edge;
4938 : 194 : tree virtual_offset = NULL;
4939 : 194 : profile_count count = cg_edge->count;
4940 : 194 : tree op;
4941 : 194 : gimple_stmt_iterator iter = gsi_for_stmt (stmt);
4942 : 194 : thunk_info *info = thunk_info::get (id->src_node);
4943 : :
4944 : 194 : cgraph_edge::remove (cg_edge);
4945 : 388 : edge = id->src_node->callees->clone (id->dst_node, call_stmt,
4946 : : gimple_uid (stmt),
4947 : : profile_count::one (),
4948 : : profile_count::one (),
4949 : : true);
4950 : 194 : edge->count = count;
4951 : 194 : if (info->virtual_offset_p)
4952 : 7 : virtual_offset = size_int (info->virtual_value);
4953 : 194 : op = create_tmp_reg_fn (cfun, TREE_TYPE (gimple_call_arg (stmt, 0)),
4954 : : NULL);
4955 : 194 : gsi_insert_before (&iter, gimple_build_assign (op,
4956 : : gimple_call_arg (stmt, 0)),
4957 : : GSI_NEW_STMT);
4958 : 194 : gcc_assert (info->this_adjusting);
4959 : 194 : op = thunk_adjust (&iter, op, 1, info->fixed_offset,
4960 : : virtual_offset, info->indirect_offset);
4961 : :
4962 : 194 : gimple_call_set_arg (stmt, 0, op);
4963 : 194 : gimple_call_set_fndecl (stmt, edge->callee->decl);
4964 : 194 : update_stmt (stmt);
4965 : 194 : id->src_node->remove ();
4966 : 194 : successfully_inlined = expand_call_inline (bb, stmt, id, to_purge);
4967 : 194 : maybe_remove_unused_call_args (cfun, stmt);
4968 : : /* This used to return true even though we do fail to inline in
4969 : : some cases. See PR98525. */
4970 : 194 : goto egress;
4971 : : }
4972 : 4567116 : fn = cg_edge->callee->decl;
4973 : 4567116 : cg_edge->callee->get_untransformed_body ();
4974 : :
4975 : 4567116 : if (flag_checking && cg_edge->callee->decl != id->dst_node->decl)
4976 : 4567107 : cg_edge->callee->verify ();
4977 : :
4978 : : /* We will be inlining this callee. */
4979 : 4567116 : id->eh_lp_nr = lookup_stmt_eh_lp (stmt);
4980 : :
4981 : : /* Update the callers EH personality. */
4982 : 4567116 : if (DECL_FUNCTION_PERSONALITY (fn))
4983 : 294394 : DECL_FUNCTION_PERSONALITY (cg_edge->caller->decl)
4984 : 147197 : = DECL_FUNCTION_PERSONALITY (fn);
4985 : :
4986 : : /* Split the block before the GIMPLE_CALL. */
4987 : 4567116 : stmt_gsi = gsi_for_stmt (stmt);
4988 : 4567116 : gsi_prev (&stmt_gsi);
4989 : 4567116 : e = split_block (bb, gsi_end_p (stmt_gsi) ? NULL : gsi_stmt (stmt_gsi));
4990 : 4567116 : bb = e->src;
4991 : 4567116 : return_block = e->dest;
4992 : 4567116 : remove_edge (e);
4993 : :
4994 : : /* If the GIMPLE_CALL was in the last statement of BB, it may have
4995 : : been the source of abnormal edges. In this case, schedule
4996 : : the removal of dead abnormal edges. */
4997 : 4567116 : gsi = gsi_start_bb (return_block);
4998 : 4567116 : gsi_next (&gsi);
4999 : 4567116 : purge_dead_abnormal_edges = gsi_end_p (gsi);
5000 : :
5001 : 4567116 : stmt_gsi = gsi_start_bb (return_block);
5002 : :
5003 : : /* Build a block containing code to initialize the arguments, the
5004 : : actual inline expansion of the body, and a label for the return
5005 : : statements within the function to jump to. The type of the
5006 : : statement expression is the return type of the function call.
5007 : : ??? If the call does not have an associated block then we will
5008 : : remap all callee blocks to NULL, effectively dropping most of
5009 : : its debug information. This should only happen for calls to
5010 : : artificial decls inserted by the compiler itself. We need to
5011 : : either link the inlined blocks into the caller block tree or
5012 : : not refer to them in any way to not break GC for locations. */
5013 : 4567116 : if (tree block = gimple_block (stmt))
5014 : : {
5015 : : /* We do want to assign a not UNKNOWN_LOCATION BLOCK_SOURCE_LOCATION
5016 : : to make inlined_function_outer_scope_p return true on this BLOCK. */
5017 : 4538589 : location_t loc = LOCATION_LOCUS (gimple_location (stmt));
5018 : 4538589 : if (loc == UNKNOWN_LOCATION)
5019 : 254587 : loc = LOCATION_LOCUS (DECL_SOURCE_LOCATION (fn));
5020 : 254587 : if (loc == UNKNOWN_LOCATION)
5021 : : loc = BUILTINS_LOCATION;
5022 : 4538589 : if (has_discriminator (gimple_location (stmt)))
5023 : 1466846 : loc = location_with_discriminator
5024 : 1466846 : (loc, get_discriminator_from_loc (gimple_location (stmt)));
5025 : 4538589 : id->block = make_node (BLOCK);
5026 : 7821000 : BLOCK_ABSTRACT_ORIGIN (id->block) = DECL_ORIGIN (fn);
5027 : 4538589 : BLOCK_SOURCE_LOCATION (id->block) = loc;
5028 : 4538589 : prepend_lexical_block (block, id->block);
5029 : : }
5030 : :
5031 : : /* Local declarations will be replaced by their equivalents in this map. */
5032 : 4567116 : st = id->decl_map;
5033 : 4567116 : id->decl_map = new hash_map<tree, tree>;
5034 : 4567116 : dst = id->debug_map;
5035 : 4567116 : id->debug_map = NULL;
5036 : 4567116 : if (flag_stack_reuse != SR_NONE)
5037 : 4561214 : id->add_clobbers_to_eh_landing_pads = last_basic_block_for_fn (cfun);
5038 : :
5039 : : /* Record the function we are about to inline. */
5040 : 4567116 : id->src_fn = fn;
5041 : 4567116 : id->src_cfun = DECL_STRUCT_FUNCTION (fn);
5042 : 4567116 : id->reset_location = DECL_IGNORED_P (fn);
5043 : 4567116 : id->call_stmt = call_stmt;
5044 : 4567116 : cfun->cfg->full_profile &= id->src_cfun->cfg->full_profile;
5045 : :
5046 : : /* When inlining into an OpenMP SIMD-on-SIMT loop, arrange for new automatic
5047 : : variables to be added to IFN_GOMP_SIMT_ENTER argument list. */
5048 : 4567116 : dst_cfun = DECL_STRUCT_FUNCTION (id->dst_fn);
5049 : 4567116 : simtvars_save = id->dst_simt_vars;
5050 : 4567116 : if (!(dst_cfun->curr_properties & PROP_gimple_lomp_dev)
5051 : 20249 : && (simduid = bb->loop_father->simduid) != NULL_TREE
5052 : 0 : && (simduid = ssa_default_def (dst_cfun, simduid)) != NULL_TREE
5053 : 0 : && single_imm_use (simduid, &use, &simtenter_stmt)
5054 : 0 : && is_gimple_call (simtenter_stmt)
5055 : 4567116 : && gimple_call_internal_p (simtenter_stmt, IFN_GOMP_SIMT_ENTER))
5056 : 0 : vec_alloc (id->dst_simt_vars, 0);
5057 : : else
5058 : 4567116 : id->dst_simt_vars = NULL;
5059 : :
5060 : 4567116 : if (profile_status_for_fn (id->src_cfun) == PROFILE_ABSENT)
5061 : 28255 : profile_status_for_fn (dst_cfun) = PROFILE_ABSENT;
5062 : :
5063 : : /* If the src function contains an IFN_VA_ARG, then so will the dst
5064 : : function after inlining. Likewise for IFN_GOMP_USE_SIMT. */
5065 : 4567116 : prop_mask = PROP_gimple_lva | PROP_gimple_lomp_dev;
5066 : 4567116 : src_properties = id->src_cfun->curr_properties & prop_mask;
5067 : 4567116 : if (src_properties != prop_mask)
5068 : 950 : dst_cfun->curr_properties &= src_properties | ~prop_mask;
5069 : 4567116 : dst_cfun->calls_eh_return |= id->src_cfun->calls_eh_return;
5070 : 4567116 : id->dst_node->has_omp_variant_constructs
5071 : 4567116 : |= id->src_node->has_omp_variant_constructs;
5072 : :
5073 : 4567116 : gcc_assert (!id->src_cfun->after_inlining);
5074 : :
5075 : 4567116 : id->entry_bb = bb;
5076 : 4567116 : if (lookup_attribute ("cold", DECL_ATTRIBUTES (fn)))
5077 : : {
5078 : 72 : gimple_stmt_iterator si = gsi_last_bb (bb);
5079 : 72 : gsi_insert_after (&si, gimple_build_predict (PRED_COLD_FUNCTION,
5080 : : NOT_TAKEN),
5081 : : GSI_NEW_STMT);
5082 : : }
5083 : 4567116 : initialize_inlined_parameters (id, stmt, fn, bb);
5084 : 4036139 : if (debug_nonbind_markers_p && debug_inline_points && id->block
5085 : 8588618 : && inlined_function_outer_scope_p (id->block))
5086 : : {
5087 : 4021502 : gimple_stmt_iterator si = gsi_last_bb (bb);
5088 : 4021502 : gsi_insert_after (&si, gimple_build_debug_inline_entry
5089 : 4021502 : (id->block, DECL_SOURCE_LOCATION (id->src_fn)),
5090 : : GSI_NEW_STMT);
5091 : : }
5092 : :
5093 : : /* If function to be inlined calls alloca, wrap the inlined function
5094 : : in between save_stack = __builtin_stack_save (); and
5095 : : __builtin_stack_restore (save_stack); calls. */
5096 : 4567116 : if (id->src_cfun->calls_alloca && !gimple_call_noreturn_p (stmt))
5097 : : /* Don't do this for VLA allocations though, just for user alloca
5098 : : calls. */
5099 : 5378 : for (struct cgraph_edge *e = id->src_node->callees; e; e = e->next_callee)
5100 : 4979 : if (gimple_maybe_alloca_call_p (e->call_stmt)
5101 : 4979 : && !gimple_call_alloca_for_var_p (e->call_stmt))
5102 : : {
5103 : 88 : tree fn = builtin_decl_implicit (BUILT_IN_STACK_SAVE);
5104 : 88 : gcall *call = gimple_build_call (fn, 0);
5105 : 88 : save_stack = make_ssa_name (ptr_type_node);
5106 : 88 : gimple_call_set_lhs (call, save_stack);
5107 : 88 : gimple_stmt_iterator si = gsi_last_bb (bb);
5108 : 88 : gsi_insert_after (&si, call, GSI_NEW_STMT);
5109 : 88 : struct cgraph_node *dest = cgraph_node::get_create (fn);
5110 : 88 : id->dst_node->create_edge (dest, call, bb->count)->inline_failed
5111 : 88 : = CIF_BODY_NOT_AVAILABLE;
5112 : 88 : break;
5113 : : }
5114 : :
5115 : 4567116 : if (DECL_INITIAL (fn))
5116 : : {
5117 : 4567116 : if (gimple_block (stmt))
5118 : : {
5119 : 4538589 : tree *var;
5120 : :
5121 : 4538589 : prepend_lexical_block (id->block,
5122 : 4538589 : remap_blocks (DECL_INITIAL (fn), id));
5123 : 4538589 : gcc_checking_assert (BLOCK_SUBBLOCKS (id->block)
5124 : : && (BLOCK_CHAIN (BLOCK_SUBBLOCKS (id->block))
5125 : : == NULL_TREE));
5126 : : /* Move vars for PARM_DECLs from DECL_INITIAL block to id->block,
5127 : : otherwise for DWARF DW_TAG_formal_parameter will not be children of
5128 : : DW_TAG_inlined_subroutine, but of a DW_TAG_lexical_block
5129 : : under it. The parameters can be then evaluated in the debugger,
5130 : : but don't show in backtraces. */
5131 : 6513346 : for (var = &BLOCK_VARS (BLOCK_SUBBLOCKS (id->block)); *var; )
5132 : 1974757 : if (TREE_CODE (DECL_ORIGIN (*var)) == PARM_DECL)
5133 : : {
5134 : 515215 : tree v = *var;
5135 : 515215 : *var = TREE_CHAIN (v);
5136 : 515215 : TREE_CHAIN (v) = BLOCK_VARS (id->block);
5137 : 515215 : BLOCK_VARS (id->block) = v;
5138 : : }
5139 : : else
5140 : 1459542 : var = &TREE_CHAIN (*var);
5141 : : }
5142 : : else
5143 : 28527 : remap_blocks_to_null (DECL_INITIAL (fn), id);
5144 : : }
5145 : :
5146 : : /* Return statements in the function body will be replaced by jumps
5147 : : to the RET_LABEL. */
5148 : 4567116 : gcc_assert (DECL_INITIAL (fn));
5149 : 4567116 : gcc_assert (TREE_CODE (DECL_INITIAL (fn)) == BLOCK);
5150 : :
5151 : : /* Find the LHS to which the result of this call is assigned. */
5152 : 4567116 : return_slot = NULL;
5153 : 4567116 : if (gimple_call_lhs (stmt))
5154 : : {
5155 : 2269313 : modify_dest = gimple_call_lhs (stmt);
5156 : :
5157 : : /* The function which we are inlining might not return a value,
5158 : : in which case we should issue a warning that the function
5159 : : does not return a value. In that case the optimizers will
5160 : : see that the variable to which the value is assigned was not
5161 : : initialized. We do not want to issue a warning about that
5162 : : uninitialized variable. */
5163 : 2269313 : if (DECL_P (modify_dest))
5164 : 436620 : suppress_warning (modify_dest, OPT_Wuninitialized);
5165 : :
5166 : : /* If we have a return slot, we can assign it the result directly,
5167 : : except in the case where it is a global variable that is only
5168 : : written to because, the callee being permitted to read or take
5169 : : the address of its DECL_RESULT, this could invalidate the flag
5170 : : on the global variable; instead we preventively remove the store,
5171 : : which would have happened later if the call was not inlined. */
5172 : 2269313 : if (gimple_call_return_slot_opt_p (call_stmt))
5173 : : {
5174 : 138366 : tree base = get_base_address (modify_dest);
5175 : :
5176 : 138366 : if (VAR_P (base)
5177 : 112642 : && (TREE_STATIC (base) || DECL_EXTERNAL (base))
5178 : 138436 : && varpool_node::get (base)->writeonly)
5179 : : return_slot = NULL;
5180 : : else
5181 : : return_slot = modify_dest;
5182 : :
5183 : : modify_dest = NULL;
5184 : : }
5185 : : }
5186 : : else
5187 : : modify_dest = NULL;
5188 : :
5189 : : /* If we are inlining a call to the C++ operator new, we don't want
5190 : : to use type based alias analysis on the return value. Otherwise
5191 : : we may get confused if the compiler sees that the inlined new
5192 : : function returns a pointer which was just deleted. See bug
5193 : : 33407. */
5194 : 4567116 : if (DECL_IS_OPERATOR_NEW_P (fn))
5195 : : {
5196 : 19330 : return_slot = NULL;
5197 : 19330 : modify_dest = NULL;
5198 : : }
5199 : :
5200 : : /* Declare the return variable for the function. */
5201 : 4567116 : use_retvar = declare_return_variable (id, return_slot, modify_dest, bb);
5202 : :
5203 : : /* Add local vars in this inlined callee to caller. */
5204 : 4567116 : add_local_variables (id->src_cfun, cfun, id);
5205 : :
5206 : 4567116 : if (dump_enabled_p ())
5207 : : {
5208 : 629 : char buf[128];
5209 : 629 : snprintf (buf, sizeof(buf), "%4.2f",
5210 : 629 : cg_edge->sreal_frequency ().to_double ());
5211 : 629 : dump_printf_loc (MSG_NOTE | MSG_PRIORITY_INTERNALS,
5212 : 629 : call_stmt,
5213 : : "Inlining %C to %C with frequency %s\n",
5214 : : id->src_node, id->dst_node, buf);
5215 : 629 : if (dump_file && (dump_flags & TDF_DETAILS))
5216 : : {
5217 : 192 : id->src_node->dump (dump_file);
5218 : 192 : id->dst_node->dump (dump_file);
5219 : : }
5220 : : }
5221 : :
5222 : : /* This is it. Duplicate the callee body. Assume callee is
5223 : : pre-gimplified. Note that we must not alter the caller
5224 : : function in any way before this point, as this CALL_EXPR may be
5225 : : a self-referential call; if we're calling ourselves, we need to
5226 : : duplicate our body before altering anything. */
5227 : 4567116 : copy_body (id, bb, return_block, NULL);
5228 : :
5229 : 4567116 : reset_debug_bindings (id, stmt_gsi);
5230 : :
5231 : 4567116 : if (flag_stack_reuse != SR_NONE)
5232 : 12286227 : for (tree p = DECL_ARGUMENTS (id->src_fn); p; p = DECL_CHAIN (p))
5233 : 7725013 : if (!TREE_THIS_VOLATILE (p))
5234 : : {
5235 : : /* The value associated with P is a local temporary only if
5236 : : there is no value associated with P in the debug map. */
5237 : 7724760 : tree *varp = id->decl_map->get (p);
5238 : 7724760 : if (varp
5239 : 7724760 : && VAR_P (*varp)
5240 : 7626042 : && !is_gimple_reg (*varp)
5241 : 8152085 : && !(id->debug_map && id->debug_map->get (p)))
5242 : : {
5243 : 427092 : tree clobber = build_clobber (TREE_TYPE (*varp),
5244 : : CLOBBER_STORAGE_END);
5245 : 427092 : gimple *clobber_stmt;
5246 : 427092 : clobber_stmt = gimple_build_assign (*varp, clobber);
5247 : 427092 : gimple_set_location (clobber_stmt, gimple_location (stmt));
5248 : 427092 : gsi_insert_before (&stmt_gsi, clobber_stmt, GSI_SAME_STMT);
5249 : : }
5250 : : }
5251 : :
5252 : 4567116 : if (save_stack)
5253 : : {
5254 : 88 : tree fn = builtin_decl_implicit (BUILT_IN_STACK_RESTORE);
5255 : 88 : gcall *call = gimple_build_call (fn, 1, save_stack);
5256 : 88 : gsi_insert_before (&stmt_gsi, call, GSI_SAME_STMT);
5257 : 88 : struct cgraph_node *dest = cgraph_node::get_create (fn);
5258 : 88 : id->dst_node->create_edge (dest, call,
5259 : : return_block->count)->inline_failed
5260 : 88 : = CIF_BODY_NOT_AVAILABLE;
5261 : : }
5262 : :
5263 : : /* Reset the escaped solution. */
5264 : 4567116 : if (cfun->gimple_df)
5265 : : {
5266 : 4567116 : pt_solution_reset (&cfun->gimple_df->escaped);
5267 : 4567116 : pt_solution_reset (&cfun->gimple_df->escaped_return);
5268 : : }
5269 : :
5270 : : /* Add new automatic variables to IFN_GOMP_SIMT_ENTER arguments. */
5271 : 4567116 : if (id->dst_simt_vars && id->dst_simt_vars->length () > 0)
5272 : : {
5273 : 0 : size_t nargs = gimple_call_num_args (simtenter_stmt);
5274 : 0 : vec<tree> *vars = id->dst_simt_vars;
5275 : 0 : auto_vec<tree> newargs (nargs + vars->length ());
5276 : 0 : for (size_t i = 0; i < nargs; i++)
5277 : 0 : newargs.quick_push (gimple_call_arg (simtenter_stmt, i));
5278 : 0 : for (tree *pvar = vars->begin (); pvar != vars->end (); pvar++)
5279 : : {
5280 : 0 : tree ptrtype = build_pointer_type (TREE_TYPE (*pvar));
5281 : 0 : newargs.quick_push (build1 (ADDR_EXPR, ptrtype, *pvar));
5282 : : }
5283 : 0 : gcall *g = gimple_build_call_internal_vec (IFN_GOMP_SIMT_ENTER, newargs);
5284 : 0 : gimple_call_set_lhs (g, gimple_call_lhs (simtenter_stmt));
5285 : 0 : gimple_stmt_iterator gsi = gsi_for_stmt (simtenter_stmt);
5286 : 0 : gsi_replace (&gsi, g, false);
5287 : 0 : }
5288 : 4567116 : vec_free (id->dst_simt_vars);
5289 : 4567116 : id->dst_simt_vars = simtvars_save;
5290 : :
5291 : : /* Clean up. */
5292 : 4567116 : if (id->debug_map)
5293 : : {
5294 : 94849 : delete id->debug_map;
5295 : 94849 : id->debug_map = dst;
5296 : : }
5297 : 9134232 : delete id->decl_map;
5298 : 4567116 : id->decl_map = st;
5299 : :
5300 : : /* Unlink the calls virtual operands before replacing it. */
5301 : 4567116 : unlink_stmt_vdef (stmt);
5302 : 4567116 : if (gimple_vdef (stmt)
5303 : 4567116 : && TREE_CODE (gimple_vdef (stmt)) == SSA_NAME)
5304 : 2141729 : release_ssa_name (gimple_vdef (stmt));
5305 : :
5306 : : /* If the inlined function returns a result that we care about,
5307 : : substitute the GIMPLE_CALL with an assignment of the return
5308 : : variable to the LHS of the call. That is, if STMT was
5309 : : 'a = foo (...)', substitute the call with 'a = USE_RETVAR'. */
5310 : 4567116 : if (use_retvar && gimple_call_lhs (stmt))
5311 : : {
5312 : 1909344 : gimple *old_stmt = stmt;
5313 : 1909344 : stmt = gimple_build_assign (gimple_call_lhs (stmt), use_retvar);
5314 : 1909344 : gimple_set_location (stmt, gimple_location (old_stmt));
5315 : 1909344 : gsi_replace (&stmt_gsi, stmt, false);
5316 : 1909344 : maybe_clean_or_replace_eh_stmt (old_stmt, stmt);
5317 : : /* Append a clobber for id->retvar if easily possible. */
5318 : 1909344 : if (flag_stack_reuse != SR_NONE
5319 : 1907438 : && id->retvar
5320 : 1907438 : && VAR_P (id->retvar)
5321 : 1907438 : && id->retvar != return_slot
5322 : 1907438 : && id->retvar != modify_dest
5323 : 1907438 : && !TREE_THIS_VOLATILE (id->retvar)
5324 : 1907412 : && !is_gimple_reg (id->retvar)
5325 : 2017018 : && !stmt_ends_bb_p (stmt))
5326 : : {
5327 : 107674 : tree clobber = build_clobber (TREE_TYPE (id->retvar),
5328 : : CLOBBER_STORAGE_END);
5329 : 107674 : gimple *clobber_stmt;
5330 : 107674 : clobber_stmt = gimple_build_assign (id->retvar, clobber);
5331 : 107674 : gimple_set_location (clobber_stmt, gimple_location (old_stmt));
5332 : 107674 : gsi_insert_after (&stmt_gsi, clobber_stmt, GSI_SAME_STMT);
5333 : : }
5334 : : }
5335 : : else
5336 : : {
5337 : : /* Handle the case of inlining a function with no return
5338 : : statement, which causes the return value to become undefined. */
5339 : 2657772 : if (gimple_call_lhs (stmt)
5340 : 2657772 : && TREE_CODE (gimple_call_lhs (stmt)) == SSA_NAME)
5341 : : {
5342 : 21 : tree name = gimple_call_lhs (stmt);
5343 : 21 : tree var = SSA_NAME_VAR (name);
5344 : 6 : tree def = var ? ssa_default_def (cfun, var) : NULL;
5345 : :
5346 : 6 : if (def)
5347 : : {
5348 : : /* If the variable is used undefined, make this name
5349 : : undefined via a move. */
5350 : 0 : stmt = gimple_build_assign (gimple_call_lhs (stmt), def);
5351 : 0 : gsi_replace (&stmt_gsi, stmt, true);
5352 : : }
5353 : : else
5354 : : {
5355 : 21 : if (!var)
5356 : : {
5357 : 15 : var = create_tmp_reg_fn (cfun, TREE_TYPE (name), NULL);
5358 : 30 : SET_SSA_NAME_VAR_OR_IDENTIFIER (name, var);
5359 : : }
5360 : : /* Otherwise make this variable undefined. */
5361 : 21 : gsi_remove (&stmt_gsi, true);
5362 : 21 : set_ssa_default_def (cfun, var, name);
5363 : 21 : SSA_NAME_DEF_STMT (name) = gimple_build_nop ();
5364 : : }
5365 : : }
5366 : : /* Replace with a clobber for id->retvar. */
5367 : 2657751 : else if (flag_stack_reuse != SR_NONE
5368 : 2653755 : && id->retvar
5369 : 493300 : && VAR_P (id->retvar)
5370 : 403251 : && id->retvar != return_slot
5371 : 353695 : && id->retvar != modify_dest
5372 : 133636 : && !TREE_THIS_VOLATILE (id->retvar)
5373 : 2791387 : && !is_gimple_reg (id->retvar))
5374 : : {
5375 : 12823 : tree clobber = build_clobber (TREE_TYPE (id->retvar));
5376 : 12823 : gimple *clobber_stmt;
5377 : 12823 : clobber_stmt = gimple_build_assign (id->retvar, clobber);
5378 : 12823 : gimple_set_location (clobber_stmt, gimple_location (stmt));
5379 : 12823 : gsi_replace (&stmt_gsi, clobber_stmt, false);
5380 : 12823 : maybe_clean_or_replace_eh_stmt (stmt, clobber_stmt);
5381 : : }
5382 : : else
5383 : 2644928 : gsi_remove (&stmt_gsi, true);
5384 : : }
5385 : :
5386 : 4567116 : if (purge_dead_abnormal_edges)
5387 : 1087001 : bitmap_set_bit (to_purge, return_block->index);
5388 : :
5389 : : /* If the value of the new expression is ignored, that's OK. We
5390 : : don't warn about this for CALL_EXPRs, so we shouldn't warn about
5391 : : the equivalent inlined version either. */
5392 : 4567116 : if (is_gimple_assign (stmt))
5393 : : {
5394 : 1909344 : gcc_assert (gimple_assign_single_p (stmt)
5395 : : || CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (stmt)));
5396 : 1909344 : TREE_USED (gimple_assign_rhs1 (stmt)) = 1;
5397 : : }
5398 : :
5399 : 4567116 : id->add_clobbers_to_eh_landing_pads = 0;
5400 : :
5401 : : /* Output the inlining info for this abstract function, since it has been
5402 : : inlined. If we don't do this now, we can lose the information about the
5403 : : variables in the function when the blocks get blown away as soon as we
5404 : : remove the cgraph node. */
5405 : 4567116 : if (gimple_block (stmt))
5406 : 4538589 : (*debug_hooks->outlining_inline_function) (fn);
5407 : :
5408 : : /* Update callgraph if needed. */
5409 : 4567116 : cg_edge->callee->remove ();
5410 : :
5411 : 4567116 : id->block = NULL_TREE;
5412 : 4567116 : id->retvar = NULL_TREE;
5413 : 4567116 : successfully_inlined = true;
5414 : :
5415 : 15368101 : egress:
5416 : 15368101 : input_location = saved_location;
5417 : 15368101 : return successfully_inlined;
5418 : : }
5419 : :
5420 : : /* Expand call statements reachable from STMT_P.
5421 : : We can only have CALL_EXPRs as the "toplevel" tree code or nested
5422 : : in a MODIFY_EXPR. */
5423 : :
5424 : : static bool
5425 : 31981483 : gimple_expand_calls_inline (basic_block bb, copy_body_data *id,
5426 : : bitmap to_purge)
5427 : : {
5428 : 31981483 : gimple_stmt_iterator gsi;
5429 : 31981483 : bool inlined = false;
5430 : :
5431 : 233261393 : for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi);)
5432 : : {
5433 : 169298427 : gimple *stmt = gsi_stmt (gsi);
5434 : 169298427 : gsi_prev (&gsi);
5435 : :
5436 : 169298427 : if (is_gimple_call (stmt)
5437 : 169298427 : && !gimple_call_internal_p (stmt))
5438 : 15367907 : inlined |= expand_call_inline (bb, stmt, id, to_purge);
5439 : : }
5440 : :
5441 : 31981483 : return inlined;
5442 : : }
5443 : :
5444 : :
5445 : : /* Walk all basic blocks created after FIRST and try to fold every statement
5446 : : in the STATEMENTS pointer set. */
5447 : :
5448 : : static void
5449 : 1640394 : fold_marked_statements (int first, hash_set<gimple *> *statements)
5450 : : {
5451 : 1640394 : auto_bitmap to_purge;
5452 : 1640394 : auto_bitmap to_purge_abnormal;
5453 : :
5454 : 1640394 : auto_vec<edge, 20> stack (n_basic_blocks_for_fn (cfun) + 2);
5455 : 1640394 : auto_sbitmap visited (last_basic_block_for_fn (cfun));
5456 : 1640394 : bitmap_clear (visited);
5457 : :
5458 : 1640394 : stack.quick_push (single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
5459 : 39053683 : while (!stack.is_empty ())
5460 : : {
5461 : : /* Look at the edge on the top of the stack. */
5462 : 37413289 : edge e = stack.pop ();
5463 : 37413289 : basic_block dest = e->dest;
5464 : :
5465 : 46013551 : if (dest == EXIT_BLOCK_PTR_FOR_FN (cfun)
5466 : 35796889 : || bitmap_bit_p (visited, dest->index))
5467 : 8600262 : continue;
5468 : :
5469 : 28813027 : bitmap_set_bit (visited, dest->index);
5470 : :
5471 : 28813027 : if (dest->index >= first)
5472 : 36628074 : for (gimple_stmt_iterator gsi = gsi_start_bb (dest);
5473 : 124316067 : !gsi_end_p (gsi); gsi_next (&gsi))
5474 : : {
5475 : 106002030 : if (!statements->contains (gsi_stmt (gsi)))
5476 : 23511795 : continue;
5477 : :
5478 : 82490235 : gimple *old_stmt = gsi_stmt (gsi);
5479 : 82490235 : bool can_make_abnormal_goto = false;
5480 : 82490235 : tree old_decl = NULL_TREE;
5481 : :
5482 : 82490235 : if (is_gimple_call (old_stmt))
5483 : : {
5484 : 3673820 : old_decl = gimple_call_fndecl (old_stmt);
5485 : 3673820 : if (stmt_can_make_abnormal_goto (old_stmt))
5486 : : can_make_abnormal_goto = true;
5487 : : }
5488 : :
5489 : 3673820 : if (old_decl && fndecl_built_in_p (old_decl))
5490 : : {
5491 : : /* Folding builtins can create multiple instructions,
5492 : : we need to look at all of them. */
5493 : 1301562 : gimple_stmt_iterator i2 = gsi;
5494 : 1301562 : gsi_prev (&i2);
5495 : 1301562 : if (fold_stmt (&gsi))
5496 : : {
5497 : 98065 : gimple *new_stmt;
5498 : : /* If a builtin at the end of a bb folded into nothing,
5499 : : the following loop won't work. */
5500 : 98065 : if (gsi_end_p (gsi))
5501 : : {
5502 : 0 : cgraph_update_edges_for_call_stmt (old_stmt,
5503 : : old_decl, NULL);
5504 : 0 : if (can_make_abnormal_goto)
5505 : 0 : bitmap_set_bit (to_purge_abnormal, dest->index);
5506 : 18314037 : break;
5507 : : }
5508 : 98065 : if (gsi_end_p (i2))
5509 : 125206 : i2 = gsi_start_bb (dest);
5510 : : else
5511 : 35462 : gsi_next (&i2);
5512 : 418 : while (1)
5513 : : {
5514 : 98483 : new_stmt = gsi_stmt (i2);
5515 : 98483 : update_stmt (new_stmt);
5516 : 98483 : cgraph_update_edges_for_call_stmt (old_stmt, old_decl,
5517 : : new_stmt);
5518 : :
5519 : 98483 : if (new_stmt == gsi_stmt (gsi))
5520 : : {
5521 : : /* It is okay to check only for the very last
5522 : : of these statements. If it is a throwing
5523 : : statement nothing will change. If it isn't
5524 : : this can remove EH edges. If that weren't
5525 : : correct then because some intermediate stmts
5526 : : throw, but not the last one. That would mean
5527 : : we'd have to split the block, which we can't
5528 : : here and we'd loose anyway. And as builtins
5529 : : probably never throw, this all
5530 : : is mood anyway. */
5531 : 98065 : if (maybe_clean_or_replace_eh_stmt (old_stmt,
5532 : : new_stmt))
5533 : 7 : bitmap_set_bit (to_purge, dest->index);
5534 : 98065 : if (can_make_abnormal_goto
5535 : 98065 : && !stmt_can_make_abnormal_goto (new_stmt))
5536 : 0 : bitmap_set_bit (to_purge_abnormal, dest->index);
5537 : : break;
5538 : : }
5539 : 418 : gsi_next (&i2);
5540 : : }
5541 : : }
5542 : : }
5543 : 81188673 : else if (fold_stmt (&gsi))
5544 : : {
5545 : : /* Re-read the statement from GSI as fold_stmt() may
5546 : : have changed it. */
5547 : 3017835 : gimple *new_stmt = gsi_stmt (gsi);
5548 : 3017835 : update_stmt (new_stmt);
5549 : :
5550 : 3017835 : if (is_gimple_call (old_stmt)
5551 : 3017835 : || is_gimple_call (new_stmt))
5552 : 4403 : cgraph_update_edges_for_call_stmt (old_stmt, old_decl,
5553 : : new_stmt);
5554 : :
5555 : 3017835 : if (maybe_clean_or_replace_eh_stmt (old_stmt, new_stmt))
5556 : 167 : bitmap_set_bit (to_purge, dest->index);
5557 : 3017835 : if (can_make_abnormal_goto
5558 : 3017835 : && !stmt_can_make_abnormal_goto (new_stmt))
5559 : 7 : bitmap_set_bit (to_purge_abnormal, dest->index);
5560 : : }
5561 : : }
5562 : :
5563 : 56115735 : if (EDGE_COUNT (dest->succs) > 0)
5564 : : {
5565 : : /* Avoid warnings emitted from folding statements that
5566 : : became unreachable because of inlined function parameter
5567 : : propagation. */
5568 : 27302708 : e = find_taken_edge (dest, NULL_TREE);
5569 : 27302708 : if (e)
5570 : 19018813 : stack.quick_push (e);
5571 : : else
5572 : : {
5573 : 8283895 : edge_iterator ei;
5574 : 25037977 : FOR_EACH_EDGE (e, ei, dest->succs)
5575 : 16754082 : stack.safe_push (e);
5576 : : }
5577 : : }
5578 : : }
5579 : :
5580 : 1640394 : gimple_purge_all_dead_eh_edges (to_purge);
5581 : 1640394 : gimple_purge_all_dead_abnormal_call_edges (to_purge_abnormal);
5582 : 1640394 : }
5583 : :
5584 : : /* Expand calls to inline functions in the body of FN. */
5585 : :
5586 : : unsigned int
5587 : 2025107 : optimize_inline_calls (tree fn)
5588 : : {
5589 : 2025107 : copy_body_data id;
5590 : 2025107 : basic_block bb;
5591 : 2025107 : int last = n_basic_blocks_for_fn (cfun);
5592 : 2025107 : bool inlined_p = false;
5593 : :
5594 : : /* Clear out ID. */
5595 : 2025107 : memset (&id, 0, sizeof (id));
5596 : :
5597 : 2025107 : id.src_node = id.dst_node = cgraph_node::get (fn);
5598 : 2025107 : gcc_assert (id.dst_node->definition);
5599 : 2025107 : id.dst_fn = fn;
5600 : : /* Or any functions that aren't finished yet. */
5601 : 2025107 : if (current_function_decl)
5602 : 2025107 : id.dst_fn = current_function_decl;
5603 : :
5604 : 2025107 : id.copy_decl = copy_decl_maybe_to_var;
5605 : 2025107 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
5606 : 2025107 : id.transform_new_cfg = false;
5607 : 2025107 : id.transform_return_to_modify = true;
5608 : 2025107 : id.transform_parameter = true;
5609 : 2025107 : id.statements_to_fold = new hash_set<gimple *>;
5610 : :
5611 : 2025107 : push_gimplify_context ();
5612 : :
5613 : : /* We make no attempts to keep dominance info up-to-date. */
5614 : 2025107 : free_dominance_info (CDI_DOMINATORS);
5615 : 2025107 : free_dominance_info (CDI_POST_DOMINATORS);
5616 : :
5617 : : /* Register specific gimple functions. */
5618 : 2025107 : gimple_register_cfg_hooks ();
5619 : :
5620 : : /* Reach the trees by walking over the CFG, and note the
5621 : : enclosing basic-blocks in the call edges. */
5622 : : /* We walk the blocks going forward, because inlined function bodies
5623 : : will split id->current_basic_block, and the new blocks will
5624 : : follow it; we'll trudge through them, processing their CALL_EXPRs
5625 : : along the way. */
5626 : 2025107 : auto_bitmap to_purge;
5627 : 34006590 : FOR_EACH_BB_FN (bb, cfun)
5628 : 31981483 : inlined_p |= gimple_expand_calls_inline (bb, &id, to_purge);
5629 : :
5630 : 2025107 : pop_gimplify_context (NULL);
5631 : :
5632 : 2025107 : if (flag_checking)
5633 : : {
5634 : 2025089 : struct cgraph_edge *e;
5635 : :
5636 : 2025089 : id.dst_node->verify ();
5637 : :
5638 : : /* Double check that we inlined everything we are supposed to inline. */
5639 : 11867116 : for (e = id.dst_node->callees; e; e = e->next_callee)
5640 : 9842027 : gcc_assert (e->inline_failed);
5641 : : }
5642 : :
5643 : : /* If we didn't inline into the function there is nothing to do. */
5644 : 2025107 : if (!inlined_p)
5645 : : {
5646 : 1235394 : delete id.statements_to_fold;
5647 : 617697 : return 0;
5648 : : }
5649 : :
5650 : : /* Fold queued statements. */
5651 : 1407410 : update_max_bb_count ();
5652 : 1407410 : fold_marked_statements (last, id.statements_to_fold);
5653 : 2814820 : delete id.statements_to_fold;
5654 : :
5655 : : /* Finally purge EH and abnormal edges from the call stmts we inlined.
5656 : : We need to do this after fold_marked_statements since that may walk
5657 : : the SSA use-def chain. */
5658 : 1407410 : unsigned i;
5659 : 1407410 : bitmap_iterator bi;
5660 : 2494411 : EXECUTE_IF_SET_IN_BITMAP (to_purge, 0, i, bi)
5661 : : {
5662 : 1087001 : basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
5663 : 1087001 : if (bb)
5664 : : {
5665 : 1087001 : gimple_purge_dead_eh_edges (bb);
5666 : 1087001 : gimple_purge_dead_abnormal_call_edges (bb);
5667 : : }
5668 : : }
5669 : :
5670 : 1407410 : gcc_assert (!id.debug_stmts.exists ());
5671 : :
5672 : : /* Renumber the lexical scoping (non-code) blocks consecutively. */
5673 : 1407410 : number_blocks (fn);
5674 : :
5675 : 1407410 : delete_unreachable_blocks_update_callgraph (id.dst_node, false);
5676 : 1407410 : id.dst_node->calls_comdat_local = id.dst_node->check_calls_comdat_local_p ();
5677 : :
5678 : 1407410 : if (flag_checking)
5679 : 1407401 : id.dst_node->verify ();
5680 : :
5681 : : /* It would be nice to check SSA/CFG/statement consistency here, but it is
5682 : : not possible yet - the IPA passes might make various functions to not
5683 : : throw and they don't care to proactively update local EH info. This is
5684 : : done later in fixup_cfg pass that also execute the verification. */
5685 : 1407410 : return (TODO_update_ssa
5686 : : | TODO_cleanup_cfg
5687 : 1407410 : | (gimple_in_ssa_p (cfun) ? TODO_remove_unused_locals : 0)
5688 : 2814820 : | (gimple_in_ssa_p (cfun) ? TODO_update_address_taken : 0));
5689 : 2025107 : }
5690 : :
5691 : : /* Passed to walk_tree. Copies the node pointed to, if appropriate. */
5692 : :
5693 : : tree
5694 : 1463142261 : copy_tree_r (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
5695 : : {
5696 : 1463142261 : enum tree_code code = TREE_CODE (*tp);
5697 : 1463142261 : enum tree_code_class cl = TREE_CODE_CLASS (code);
5698 : :
5699 : : /* We make copies of most nodes. */
5700 : 1463142261 : if (IS_EXPR_CODE_CLASS (cl)
5701 : : || code == TREE_LIST
5702 : 251150563 : || code == TREE_VEC
5703 : 246947076 : || code == TYPE_DECL
5704 : 246947076 : || code == OMP_CLAUSE)
5705 : : {
5706 : : /* Because the chain gets clobbered when we make a copy, we save it
5707 : : here. */
5708 : 1216218336 : tree chain = NULL_TREE, new_tree;
5709 : :
5710 : 1216218336 : if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
5711 : 4226638 : chain = TREE_CHAIN (*tp);
5712 : :
5713 : : /* Copy the node. */
5714 : 1216218336 : new_tree = copy_node (*tp);
5715 : :
5716 : 1216218336 : *tp = new_tree;
5717 : :
5718 : : /* Now, restore the chain, if appropriate. That will cause
5719 : : walk_tree to walk into the chain as well. */
5720 : 1216218336 : if (code == PARM_DECL
5721 : 1216218336 : || code == TREE_LIST
5722 : 1214322252 : || code == OMP_CLAUSE)
5723 : 1919211 : TREE_CHAIN (*tp) = chain;
5724 : :
5725 : : /* For now, we don't update BLOCKs when we make copies. So, we
5726 : : have to nullify all BIND_EXPRs. */
5727 : 1216218336 : if (TREE_CODE (*tp) == BIND_EXPR)
5728 : 13222042 : BIND_EXPR_BLOCK (*tp) = NULL_TREE;
5729 : : }
5730 : 246923925 : else if (code == CONSTRUCTOR)
5731 : : {
5732 : : /* CONSTRUCTOR nodes need special handling because
5733 : : we need to duplicate the vector of elements. */
5734 : 22006596 : tree new_tree;
5735 : :
5736 : 22006596 : new_tree = copy_node (*tp);
5737 : 28600154 : CONSTRUCTOR_ELTS (new_tree) = vec_safe_copy (CONSTRUCTOR_ELTS (*tp));
5738 : 22006596 : *tp = new_tree;
5739 : : }
5740 : 224917329 : else if (code == STATEMENT_LIST)
5741 : : /* We used to just abort on STATEMENT_LIST, but we can run into them
5742 : : with statement-expressions (c++/40975). */
5743 : 240 : copy_statement_list (tp);
5744 : 224917089 : else if (TREE_CODE_CLASS (code) == tcc_type)
5745 : 320 : *walk_subtrees = 0;
5746 : 224916769 : else if (TREE_CODE_CLASS (code) == tcc_declaration)
5747 : 77250948 : *walk_subtrees = 0;
5748 : 147665821 : else if (TREE_CODE_CLASS (code) == tcc_constant)
5749 : 0 : *walk_subtrees = 0;
5750 : 1463142261 : return NULL_TREE;
5751 : : }
5752 : :
5753 : : /* The SAVE_EXPR pointed to by TP is being copied. If ST contains
5754 : : information indicating to what new SAVE_EXPR this one should be mapped,
5755 : : use that one. Otherwise, create a new node and enter it in ST. FN is
5756 : : the function into which the copy will be placed. */
5757 : :
5758 : : static void
5759 : 7068618 : remap_save_expr (tree *tp, hash_map<tree, tree> *st, int *walk_subtrees)
5760 : : {
5761 : 7068618 : tree *n;
5762 : 7068618 : tree t;
5763 : :
5764 : : /* See if we already encountered this SAVE_EXPR. */
5765 : 7068618 : n = st->get (*tp);
5766 : :
5767 : : /* If we didn't already remap this SAVE_EXPR, do so now. */
5768 : 7068618 : if (!n)
5769 : : {
5770 : 6780151 : t = copy_node (*tp);
5771 : :
5772 : : /* Remember this SAVE_EXPR. */
5773 : 6780151 : st->put (*tp, t);
5774 : : /* Make sure we don't remap an already-remapped SAVE_EXPR. */
5775 : 6780151 : st->put (t, t);
5776 : : }
5777 : : else
5778 : : {
5779 : : /* We've already walked into this SAVE_EXPR; don't do it again. */
5780 : 288467 : *walk_subtrees = 0;
5781 : 288467 : t = *n;
5782 : : }
5783 : :
5784 : : /* Replace this SAVE_EXPR with the copy. */
5785 : 7068618 : *tp = t;
5786 : 7068618 : }
5787 : :
5788 : : /* Called via walk_gimple_seq. If *GSIP points to a GIMPLE_LABEL for a local
5789 : : label, copies the declaration and enters it in the splay_tree in DATA (which
5790 : : is really a 'copy_body_data *'. */
5791 : :
5792 : : static tree
5793 : 1595335 : mark_local_labels_stmt (gimple_stmt_iterator *gsip,
5794 : : bool *handled_ops_p ATTRIBUTE_UNUSED,
5795 : : struct walk_stmt_info *wi)
5796 : : {
5797 : 1595335 : copy_body_data *id = (copy_body_data *) wi->info;
5798 : 1595335 : glabel *stmt = dyn_cast <glabel *> (gsi_stmt (*gsip));
5799 : :
5800 : 52082 : if (stmt)
5801 : : {
5802 : 52082 : tree decl = gimple_label_label (stmt);
5803 : :
5804 : : /* Copy the decl and remember the copy. */
5805 : 52082 : insert_decl_map (id, decl, id->copy_decl (decl, id));
5806 : : }
5807 : :
5808 : 1595335 : return NULL_TREE;
5809 : : }
5810 : :
5811 : : static gimple_seq duplicate_remap_omp_clause_seq (gimple_seq seq,
5812 : : struct walk_stmt_info *wi);
5813 : :
5814 : : /* Called via walk_gimple_seq by copy_gimple_seq_and_replace_local.
5815 : : Using the splay_tree pointed to by ST (which is really a `splay_tree'),
5816 : : remaps all local declarations to appropriate replacements in gimple
5817 : : operands. */
5818 : :
5819 : : static tree
5820 : 3498055 : replace_locals_op (tree *tp, int *walk_subtrees, void *data)
5821 : : {
5822 : 3498055 : struct walk_stmt_info *wi = (struct walk_stmt_info*) data;
5823 : 3498055 : copy_body_data *id = (copy_body_data *) wi->info;
5824 : 3498055 : hash_map<tree, tree> *st = id->decl_map;
5825 : 3498055 : tree *n;
5826 : 3498055 : tree expr = *tp;
5827 : :
5828 : : /* For recursive invocations this is no longer the LHS itself. */
5829 : 3498055 : bool is_lhs = wi->is_lhs;
5830 : 3498055 : wi->is_lhs = false;
5831 : :
5832 : 3498055 : if (TREE_CODE (expr) == SSA_NAME)
5833 : : {
5834 : 24548 : *tp = remap_ssa_name (*tp, id);
5835 : 24548 : *walk_subtrees = 0;
5836 : 24548 : if (is_lhs)
5837 : 12274 : SSA_NAME_DEF_STMT (*tp) = gsi_stmt (wi->gsi);
5838 : : }
5839 : : /* Only a local declaration (variable or label). */
5840 : 3473507 : else if ((VAR_P (expr) && !TREE_STATIC (expr))
5841 : 2030183 : || TREE_CODE (expr) == LABEL_DECL)
5842 : : {
5843 : : /* Lookup the declaration. */
5844 : 1549544 : n = st->get (expr);
5845 : :
5846 : : /* If it's there, remap it. */
5847 : 1549544 : if (n)
5848 : 104878 : *tp = *n;
5849 : 1549544 : *walk_subtrees = 0;
5850 : : }
5851 : 1923963 : else if (TREE_CODE (expr) == STATEMENT_LIST
5852 : 1923963 : || TREE_CODE (expr) == BIND_EXPR
5853 : 1923963 : || TREE_CODE (expr) == SAVE_EXPR)
5854 : 0 : gcc_unreachable ();
5855 : 1923963 : else if (TREE_CODE (expr) == TARGET_EXPR)
5856 : : {
5857 : : /* Don't mess with a TARGET_EXPR that hasn't been expanded.
5858 : : It's OK for this to happen if it was part of a subtree that
5859 : : isn't immediately expanded, such as operand 2 of another
5860 : : TARGET_EXPR. */
5861 : 0 : if (!TREE_OPERAND (expr, 1))
5862 : : {
5863 : 0 : TREE_OPERAND (expr, 1) = TREE_OPERAND (expr, 3);
5864 : 0 : TREE_OPERAND (expr, 3) = NULL_TREE;
5865 : : }
5866 : : }
5867 : 1923963 : else if (TREE_CODE (expr) == OMP_CLAUSE)
5868 : : {
5869 : : /* Before the omplower pass completes, some OMP clauses can contain
5870 : : sequences that are neither copied by gimple_seq_copy nor walked by
5871 : : walk_gimple_seq. To make copy_gimple_seq_and_replace_locals work even
5872 : : in those situations, we have to copy and process them explicitely. */
5873 : :
5874 : 552 : if (OMP_CLAUSE_CODE (expr) == OMP_CLAUSE_LASTPRIVATE)
5875 : : {
5876 : 14 : gimple_seq seq = OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (expr);
5877 : 14 : seq = duplicate_remap_omp_clause_seq (seq, wi);
5878 : 14 : OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (expr) = seq;
5879 : : }
5880 : 538 : else if (OMP_CLAUSE_CODE (expr) == OMP_CLAUSE_LINEAR)
5881 : : {
5882 : 77 : gimple_seq seq = OMP_CLAUSE_LINEAR_GIMPLE_SEQ (expr);
5883 : 77 : seq = duplicate_remap_omp_clause_seq (seq, wi);
5884 : 77 : OMP_CLAUSE_LINEAR_GIMPLE_SEQ (expr) = seq;
5885 : : }
5886 : 461 : else if (OMP_CLAUSE_CODE (expr) == OMP_CLAUSE_REDUCTION)
5887 : : {
5888 : 99 : gimple_seq seq = OMP_CLAUSE_REDUCTION_GIMPLE_INIT (expr);
5889 : 99 : seq = duplicate_remap_omp_clause_seq (seq, wi);
5890 : 99 : OMP_CLAUSE_REDUCTION_GIMPLE_INIT (expr) = seq;
5891 : 99 : seq = OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (expr);
5892 : 99 : seq = duplicate_remap_omp_clause_seq (seq, wi);
5893 : 99 : OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (expr) = seq;
5894 : : }
5895 : : }
5896 : :
5897 : : /* Keep iterating. */
5898 : 3498055 : return NULL_TREE;
5899 : : }
5900 : :
5901 : :
5902 : : /* Called via walk_gimple_seq by copy_gimple_seq_and_replace_local.
5903 : : Using the splay_tree pointed to by ST (which is really a `splay_tree'),
5904 : : remaps all local declarations to appropriate replacements in gimple
5905 : : statements. */
5906 : :
5907 : : static tree
5908 : 1595335 : replace_locals_stmt (gimple_stmt_iterator *gsip,
5909 : : bool *handled_ops_p ATTRIBUTE_UNUSED,
5910 : : struct walk_stmt_info *wi)
5911 : : {
5912 : 1595335 : copy_body_data *id = (copy_body_data *) wi->info;
5913 : 1595335 : gimple *gs = gsi_stmt (*gsip);
5914 : :
5915 : 1595335 : if (gbind *stmt = dyn_cast <gbind *> (gs))
5916 : : {
5917 : 349 : tree block = gimple_bind_block (stmt);
5918 : :
5919 : 349 : if (block)
5920 : : {
5921 : 269 : remap_block (&block, id);
5922 : 269 : gimple_bind_set_block (stmt, block);
5923 : : }
5924 : :
5925 : : /* This will remap a lot of the same decls again, but this should be
5926 : : harmless. */
5927 : 349 : if (gimple_bind_vars (stmt))
5928 : : {
5929 : : tree old_var, decls = gimple_bind_vars (stmt);
5930 : :
5931 : 528 : for (old_var = decls; old_var; old_var = DECL_CHAIN (old_var))
5932 : 360 : if (!can_be_nonlocal (old_var, id)
5933 : 360 : && ! variably_modified_type_p (TREE_TYPE (old_var), id->src_fn))
5934 : 360 : remap_decl (old_var, id);
5935 : :
5936 : 168 : gcc_checking_assert (!id->prevent_decl_creation_for_types);
5937 : 168 : id->prevent_decl_creation_for_types = true;
5938 : 168 : gimple_bind_set_vars (stmt, remap_decls (decls, NULL, id));
5939 : 168 : id->prevent_decl_creation_for_types = false;
5940 : : }
5941 : : }
5942 : :
5943 : : /* Keep iterating. */
5944 : 1595335 : return NULL_TREE;
5945 : : }
5946 : :
5947 : : /* Create a copy of SEQ and remap all decls in it. */
5948 : :
5949 : : static gimple_seq
5950 : 289 : duplicate_remap_omp_clause_seq (gimple_seq seq, struct walk_stmt_info *wi)
5951 : : {
5952 : 289 : if (!seq)
5953 : : return NULL;
5954 : :
5955 : : /* If there are any labels in OMP sequences, they can be only referred to in
5956 : : the sequence itself and therefore we can do both here. */
5957 : 60 : walk_gimple_seq (seq, mark_local_labels_stmt, NULL, wi);
5958 : 60 : gimple_seq copy = gimple_seq_copy (seq);
5959 : 60 : walk_gimple_seq (copy, replace_locals_stmt, replace_locals_op, wi);
5960 : 60 : return copy;
5961 : : }
5962 : :
5963 : : /* Copies everything in SEQ and replaces variables and labels local to
5964 : : current_function_decl. */
5965 : :
5966 : : gimple_seq
5967 : 1065707 : copy_gimple_seq_and_replace_locals (gimple_seq seq)
5968 : : {
5969 : 1065707 : copy_body_data id;
5970 : 1065707 : struct walk_stmt_info wi;
5971 : 1065707 : gimple_seq copy;
5972 : :
5973 : : /* There's nothing to do for NULL_TREE. */
5974 : 1065707 : if (seq == NULL)
5975 : : return seq;
5976 : :
5977 : : /* Set up ID. */
5978 : 1065691 : memset (&id, 0, sizeof (id));
5979 : 1065691 : id.src_fn = current_function_decl;
5980 : 1065691 : id.dst_fn = current_function_decl;
5981 : 1065691 : id.src_cfun = cfun;
5982 : 1065691 : id.decl_map = new hash_map<tree, tree>;
5983 : 1065691 : id.debug_map = NULL;
5984 : :
5985 : 1065691 : id.copy_decl = copy_decl_no_change;
5986 : 1065691 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
5987 : 1065691 : id.transform_new_cfg = false;
5988 : 1065691 : id.transform_return_to_modify = false;
5989 : 1065691 : id.transform_parameter = false;
5990 : :
5991 : : /* Walk the tree once to find local labels. */
5992 : 1065691 : memset (&wi, 0, sizeof (wi));
5993 : 1065691 : hash_set<tree> visited;
5994 : 1065691 : wi.info = &id;
5995 : 1065691 : wi.pset = &visited;
5996 : 1065691 : walk_gimple_seq (seq, mark_local_labels_stmt, NULL, &wi);
5997 : :
5998 : 1065691 : copy = gimple_seq_copy (seq);
5999 : :
6000 : : /* Walk the copy, remapping decls. */
6001 : 1065691 : memset (&wi, 0, sizeof (wi));
6002 : 1065691 : wi.info = &id;
6003 : 1065691 : walk_gimple_seq (copy, replace_locals_stmt, replace_locals_op, &wi);
6004 : :
6005 : : /* Clean up. */
6006 : 2131382 : delete id.decl_map;
6007 : 1065691 : if (id.debug_map)
6008 : 0 : delete id.debug_map;
6009 : 1065691 : if (id.dependence_map)
6010 : : {
6011 : 0 : delete id.dependence_map;
6012 : 0 : id.dependence_map = NULL;
6013 : : }
6014 : :
6015 : 1065691 : return copy;
6016 : 1065691 : }
6017 : :
6018 : :
6019 : : /* Allow someone to determine if SEARCH is a child of TOP from gdb. */
6020 : :
6021 : : static tree
6022 : 0 : debug_find_tree_1 (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED, void *data)
6023 : : {
6024 : 0 : if (*tp == data)
6025 : : return (tree) data;
6026 : : else
6027 : 0 : return NULL;
6028 : : }
6029 : :
6030 : : DEBUG_FUNCTION bool
6031 : 0 : debug_find_tree (tree top, tree search)
6032 : : {
6033 : 0 : return walk_tree_without_duplicates (&top, debug_find_tree_1, search) != 0;
6034 : : }
6035 : :
6036 : :
6037 : : /* Declare the variables created by the inliner. Add all the variables in
6038 : : VARS to BIND_EXPR. */
6039 : :
6040 : : static void
6041 : 6883888 : declare_inline_vars (tree block, tree vars)
6042 : : {
6043 : 6883888 : tree t;
6044 : 16885054 : for (t = vars; t; t = DECL_CHAIN (t))
6045 : : {
6046 : 10001166 : DECL_SEEN_IN_BIND_EXPR_P (t) = 1;
6047 : 10001166 : gcc_assert (!TREE_STATIC (t) && !TREE_ASM_WRITTEN (t));
6048 : 10001166 : add_local_decl (cfun, t);
6049 : : }
6050 : :
6051 : 6883888 : if (block)
6052 : 6801980 : BLOCK_VARS (block) = chainon (BLOCK_VARS (block), vars);
6053 : 6883888 : }
6054 : :
6055 : : /* Copy NODE (which must be a DECL). The DECL originally was in the FROM_FN,
6056 : : but now it will be in the TO_FN. PARM_TO_VAR means enable PARM_DECL to
6057 : : VAR_DECL translation. */
6058 : :
6059 : : tree
6060 : 88184739 : copy_decl_for_dup_finish (copy_body_data *id, tree decl, tree copy)
6061 : : {
6062 : : /* Don't generate debug information for the copy if we wouldn't have
6063 : : generated it for the copy either. */
6064 : 88184739 : DECL_ARTIFICIAL (copy) = DECL_ARTIFICIAL (decl);
6065 : 88184739 : DECL_IGNORED_P (copy) = DECL_IGNORED_P (decl);
6066 : :
6067 : : /* Set the DECL_ABSTRACT_ORIGIN so the debugging routines know what
6068 : : declaration inspired this copy. */
6069 : 117263053 : DECL_ABSTRACT_ORIGIN (copy) = DECL_ORIGIN (decl);
6070 : :
6071 : : /* The new variable/label has no RTL, yet. */
6072 : 88184739 : if (HAS_RTL_P (copy)
6073 : 88184739 : && !TREE_STATIC (copy) && !DECL_EXTERNAL (copy))
6074 : 88180111 : SET_DECL_RTL (copy, 0);
6075 : : /* For vector typed decls make sure to update DECL_MODE according
6076 : : to the new function context. */
6077 : 88184739 : if (VECTOR_TYPE_P (TREE_TYPE (copy)))
6078 : 163527 : SET_DECL_MODE (copy, TYPE_MODE (TREE_TYPE (copy)));
6079 : :
6080 : : /* These args would always appear unused, if not for this. */
6081 : 88184739 : TREE_USED (copy) = 1;
6082 : :
6083 : : /* Set the context for the new declaration. */
6084 : 88184739 : if (!DECL_CONTEXT (decl))
6085 : : /* Globals stay global. */
6086 : : ;
6087 : 88184589 : else if (DECL_CONTEXT (decl) != id->src_fn)
6088 : : /* Things that weren't in the scope of the function we're inlining
6089 : : from aren't in the scope we're inlining to, either. */
6090 : : ;
6091 : 88182473 : else if (TREE_STATIC (decl))
6092 : : /* Function-scoped static variables should stay in the original
6093 : : function. */
6094 : : ;
6095 : : else
6096 : : {
6097 : : /* Ordinary automatic local variables are now in the scope of the
6098 : : new function. */
6099 : 88179186 : DECL_CONTEXT (copy) = id->dst_fn;
6100 : 88179186 : if (VAR_P (copy) && id->dst_simt_vars && !is_gimple_reg (copy))
6101 : : {
6102 : 0 : if (!lookup_attribute ("omp simt private", DECL_ATTRIBUTES (copy)))
6103 : 0 : DECL_ATTRIBUTES (copy)
6104 : 0 : = tree_cons (get_identifier ("omp simt private"), NULL,
6105 : 0 : DECL_ATTRIBUTES (copy));
6106 : 0 : id->dst_simt_vars->safe_push (copy);
6107 : : }
6108 : : }
6109 : :
6110 : 88184739 : return copy;
6111 : : }
6112 : :
6113 : : /* Create a new VAR_DECL that is indentical in all respect to DECL except that
6114 : : DECL can be either a VAR_DECL, a PARM_DECL or RESULT_DECL. The original
6115 : : DECL must come from ID->src_fn and the copy will be part of ID->dst_fn. */
6116 : :
6117 : : tree
6118 : 7929623 : copy_decl_to_var (tree decl, copy_body_data *id)
6119 : : {
6120 : 7929623 : tree copy, type;
6121 : :
6122 : 7929623 : gcc_assert (TREE_CODE (decl) == PARM_DECL
6123 : : || TREE_CODE (decl) == RESULT_DECL);
6124 : :
6125 : 7929623 : type = TREE_TYPE (decl);
6126 : :
6127 : 7929623 : copy = build_decl (DECL_SOURCE_LOCATION (id->dst_fn),
6128 : 7929623 : VAR_DECL, DECL_NAME (decl), type);
6129 : 7929623 : if (DECL_PT_UID_SET_P (decl))
6130 : 289 : SET_DECL_PT_UID (copy, DECL_PT_UID (decl));
6131 : 7929623 : TREE_ADDRESSABLE (copy) = TREE_ADDRESSABLE (decl);
6132 : 7929623 : TREE_READONLY (copy) = TREE_READONLY (decl);
6133 : 7929623 : TREE_THIS_VOLATILE (copy) = TREE_THIS_VOLATILE (decl);
6134 : 7929623 : DECL_NOT_GIMPLE_REG_P (copy) = DECL_NOT_GIMPLE_REG_P (decl);
6135 : 7929623 : DECL_BY_REFERENCE (copy) = DECL_BY_REFERENCE (decl);
6136 : :
6137 : 7929623 : return copy_decl_for_dup_finish (id, decl, copy);
6138 : : }
6139 : :
6140 : : /* Like copy_decl_to_var, but create a return slot object instead of a
6141 : : pointer variable for return by invisible reference. */
6142 : :
6143 : : static tree
6144 : 2083788 : copy_result_decl_to_var (tree decl, copy_body_data *id)
6145 : : {
6146 : 2083788 : tree copy, type;
6147 : :
6148 : 2083788 : gcc_assert (TREE_CODE (decl) == PARM_DECL
6149 : : || TREE_CODE (decl) == RESULT_DECL);
6150 : :
6151 : 2083788 : type = TREE_TYPE (decl);
6152 : 2083788 : if (DECL_BY_REFERENCE (decl))
6153 : 73 : type = TREE_TYPE (type);
6154 : :
6155 : 2083788 : copy = build_decl (DECL_SOURCE_LOCATION (id->dst_fn),
6156 : 2083788 : VAR_DECL, DECL_NAME (decl), type);
6157 : 2083788 : if (DECL_PT_UID_SET_P (decl))
6158 : 0 : SET_DECL_PT_UID (copy, DECL_PT_UID (decl));
6159 : 2083788 : TREE_READONLY (copy) = TREE_READONLY (decl);
6160 : 2083788 : TREE_THIS_VOLATILE (copy) = TREE_THIS_VOLATILE (decl);
6161 : 2083788 : if (!DECL_BY_REFERENCE (decl))
6162 : : {
6163 : 2083715 : TREE_ADDRESSABLE (copy) = TREE_ADDRESSABLE (decl);
6164 : 2083715 : DECL_NOT_GIMPLE_REG_P (copy)
6165 : 4167430 : = (DECL_NOT_GIMPLE_REG_P (decl)
6166 : : /* RESULT_DECLs are treated special by needs_to_live_in_memory,
6167 : : mirror that to the created VAR_DECL. */
6168 : 2083715 : || (TREE_CODE (decl) == RESULT_DECL
6169 : 2083559 : && aggregate_value_p (decl, id->src_fn)));
6170 : : }
6171 : :
6172 : 2083788 : return copy_decl_for_dup_finish (id, decl, copy);
6173 : : }
6174 : :
6175 : : tree
6176 : 78171158 : copy_decl_no_change (tree decl, copy_body_data *id)
6177 : : {
6178 : 78171158 : tree copy;
6179 : :
6180 : 78171158 : copy = copy_node (decl);
6181 : :
6182 : : /* The COPY is not abstract; it will be generated in DST_FN. */
6183 : 78171158 : DECL_ABSTRACT_P (copy) = false;
6184 : 78171158 : lang_hooks.dup_lang_specific_decl (copy);
6185 : :
6186 : : /* TREE_ADDRESSABLE isn't used to indicate that a label's address has
6187 : : been taken; it's for internal bookkeeping in expand_goto_internal. */
6188 : 78171158 : if (TREE_CODE (copy) == LABEL_DECL)
6189 : : {
6190 : 1295966 : TREE_ADDRESSABLE (copy) = 0;
6191 : 1295966 : LABEL_DECL_UID (copy) = -1;
6192 : : }
6193 : :
6194 : 78171158 : return copy_decl_for_dup_finish (id, decl, copy);
6195 : : }
6196 : :
6197 : : static tree
6198 : 21578293 : copy_decl_maybe_to_var (tree decl, copy_body_data *id)
6199 : : {
6200 : 21578293 : if (TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL)
6201 : 12245 : return copy_decl_to_var (decl, id);
6202 : : else
6203 : 21566048 : return copy_decl_no_change (decl, id);
6204 : : }
6205 : :
6206 : : /* Return a copy of the function's argument tree without any modifications. */
6207 : :
6208 : : static tree
6209 : 73410 : copy_arguments_nochange (tree orig_parm, copy_body_data * id)
6210 : : {
6211 : 73410 : tree arg, *parg;
6212 : 73410 : tree new_parm = NULL;
6213 : :
6214 : 73410 : parg = &new_parm;
6215 : 219960 : for (arg = orig_parm; arg; arg = DECL_CHAIN (arg))
6216 : : {
6217 : 146550 : tree new_tree = remap_decl (arg, id);
6218 : 146550 : if (TREE_CODE (new_tree) != PARM_DECL)
6219 : 4044 : new_tree = id->copy_decl (arg, id);
6220 : 146550 : lang_hooks.dup_lang_specific_decl (new_tree);
6221 : 146550 : *parg = new_tree;
6222 : 146550 : parg = &DECL_CHAIN (new_tree);
6223 : : }
6224 : 73410 : return new_parm;
6225 : : }
6226 : :
6227 : : /* Return a copy of the function's static chain. */
6228 : : static tree
6229 : 964 : copy_static_chain (tree static_chain, copy_body_data * id)
6230 : : {
6231 : 964 : tree *chain_copy, *pvar;
6232 : :
6233 : 964 : chain_copy = &static_chain;
6234 : 1928 : for (pvar = chain_copy; *pvar; pvar = &DECL_CHAIN (*pvar))
6235 : : {
6236 : 964 : tree new_tree = remap_decl (*pvar, id);
6237 : 964 : lang_hooks.dup_lang_specific_decl (new_tree);
6238 : 964 : DECL_CHAIN (new_tree) = DECL_CHAIN (*pvar);
6239 : 964 : *pvar = new_tree;
6240 : : }
6241 : 964 : return static_chain;
6242 : : }
6243 : :
6244 : : /* Return true if the function is allowed to be versioned.
6245 : : This is a guard for the versioning functionality. */
6246 : :
6247 : : bool
6248 : 11631804 : tree_versionable_function_p (tree fndecl)
6249 : : {
6250 : 11631804 : return (!lookup_attribute ("noclone", DECL_ATTRIBUTES (fndecl))
6251 : 22996307 : && copy_forbidden (DECL_STRUCT_FUNCTION (fndecl)) == NULL);
6252 : : }
6253 : :
6254 : : /* Update clone info after duplication. */
6255 : :
6256 : : static void
6257 : 232984 : update_clone_info (copy_body_data * id)
6258 : : {
6259 : 232984 : struct cgraph_node *this_node = id->dst_node;
6260 : 232984 : if (!this_node->clones)
6261 : : return;
6262 : 589250 : for (cgraph_node *node = this_node->clones; node != this_node;)
6263 : : {
6264 : : /* First update replace maps to match the new body. */
6265 : 517188 : clone_info *info = clone_info::get (node);
6266 : 517188 : if (info && info->tree_map)
6267 : : {
6268 : : unsigned int i;
6269 : 0 : for (i = 0; i < vec_safe_length (info->tree_map); i++)
6270 : : {
6271 : 0 : struct ipa_replace_map *replace_info;
6272 : 0 : replace_info = (*info->tree_map)[i];
6273 : 0 : walk_tree (&replace_info->new_tree, copy_tree_body_r, id, NULL);
6274 : : }
6275 : : }
6276 : :
6277 : 517188 : if (node->clones)
6278 : : node = node->clones;
6279 : 497977 : else if (node->next_sibling_clone)
6280 : : node = node->next_sibling_clone;
6281 : : else
6282 : : {
6283 : 174305 : while (node != id->dst_node && !node->next_sibling_clone)
6284 : 91273 : node = node->clone_of;
6285 : 83032 : if (node != id->dst_node)
6286 : 10970 : node = node->next_sibling_clone;
6287 : : }
6288 : : }
6289 : : }
6290 : :
6291 : : /* Create a copy of a function's tree.
6292 : : OLD_DECL and NEW_DECL are FUNCTION_DECL tree nodes
6293 : : of the original function and the new copied function
6294 : : respectively. In case we want to replace a DECL
6295 : : tree with another tree while duplicating the function's
6296 : : body, TREE_MAP represents the mapping between these
6297 : : trees. If UPDATE_CLONES is set, the call_stmt fields
6298 : : of edges of clones of the function will be updated.
6299 : :
6300 : : If non-NULL PARAM_ADJUSTMENTS determines how function prototype (i.e. the
6301 : : function parameters and return value) should be modified).
6302 : : If non-NULL BLOCKS_TO_COPY determine what basic blocks to copy.
6303 : : If non_NULL NEW_ENTRY determine new entry BB of the clone.
6304 : : */
6305 : : void
6306 : 232984 : tree_function_versioning (tree old_decl, tree new_decl,
6307 : : vec<ipa_replace_map *, va_gc> *tree_map,
6308 : : ipa_param_adjustments *param_adjustments,
6309 : : bool update_clones, bitmap blocks_to_copy,
6310 : : basic_block new_entry)
6311 : : {
6312 : 232984 : struct cgraph_node *old_version_node;
6313 : 232984 : struct cgraph_node *new_version_node;
6314 : 232984 : copy_body_data id;
6315 : 232984 : tree p;
6316 : 232984 : unsigned i;
6317 : 232984 : struct ipa_replace_map *replace_info;
6318 : 232984 : basic_block old_entry_block, bb;
6319 : 232984 : auto_vec<gimple *, 10> init_stmts;
6320 : 232984 : tree vars = NULL_TREE;
6321 : :
6322 : : /* We can get called recursively from expand_call_inline via clone
6323 : : materialization. While expand_call_inline maintains input_location
6324 : : we cannot tolerate it to leak into the materialized clone. */
6325 : 232984 : location_t saved_location = input_location;
6326 : 232984 : input_location = UNKNOWN_LOCATION;
6327 : :
6328 : 232984 : gcc_assert (TREE_CODE (old_decl) == FUNCTION_DECL
6329 : : && TREE_CODE (new_decl) == FUNCTION_DECL);
6330 : 232984 : DECL_POSSIBLY_INLINED (old_decl) = 1;
6331 : :
6332 : 232984 : old_version_node = cgraph_node::get (old_decl);
6333 : 232984 : gcc_checking_assert (old_version_node);
6334 : 232984 : new_version_node = cgraph_node::get (new_decl);
6335 : 232984 : gcc_checking_assert (new_version_node);
6336 : :
6337 : : /* Copy over debug args. */
6338 : 232984 : if (DECL_HAS_DEBUG_ARGS_P (old_decl))
6339 : : {
6340 : 3293 : vec<tree, va_gc> **new_debug_args, **old_debug_args;
6341 : 3293 : gcc_checking_assert (decl_debug_args_lookup (new_decl) == NULL);
6342 : 3293 : DECL_HAS_DEBUG_ARGS_P (new_decl) = 0;
6343 : 3293 : old_debug_args = decl_debug_args_lookup (old_decl);
6344 : 3293 : if (old_debug_args)
6345 : : {
6346 : 3293 : new_debug_args = decl_debug_args_insert (new_decl);
6347 : 6586 : *new_debug_args = vec_safe_copy (*old_debug_args);
6348 : : }
6349 : : }
6350 : :
6351 : : /* Output the inlining info for this abstract function, since it has been
6352 : : inlined. If we don't do this now, we can lose the information about the
6353 : : variables in the function when the blocks get blown away as soon as we
6354 : : remove the cgraph node. */
6355 : 232984 : (*debug_hooks->outlining_inline_function) (old_decl);
6356 : :
6357 : 232984 : DECL_ARTIFICIAL (new_decl) = 1;
6358 : 421647 : DECL_ABSTRACT_ORIGIN (new_decl) = DECL_ORIGIN (old_decl);
6359 : 421647 : if (DECL_ORIGIN (old_decl) == old_decl)
6360 : 205621 : old_version_node->used_as_abstract_origin = true;
6361 : 232984 : DECL_FUNCTION_PERSONALITY (new_decl) = DECL_FUNCTION_PERSONALITY (old_decl);
6362 : :
6363 : : /* Prepare the data structures for the tree copy. */
6364 : 232984 : memset (&id, 0, sizeof (id));
6365 : :
6366 : : /* Generate a new name for the new version. */
6367 : 232984 : id.statements_to_fold = new hash_set<gimple *>;
6368 : :
6369 : 232984 : id.decl_map = new hash_map<tree, tree>;
6370 : 232984 : id.debug_map = NULL;
6371 : 232984 : id.src_fn = old_decl;
6372 : 232984 : id.dst_fn = new_decl;
6373 : 232984 : id.src_node = old_version_node;
6374 : 232984 : id.dst_node = new_version_node;
6375 : 232984 : id.src_cfun = DECL_STRUCT_FUNCTION (old_decl);
6376 : 232984 : id.blocks_to_copy = blocks_to_copy;
6377 : :
6378 : 232984 : id.copy_decl = copy_decl_no_change;
6379 : 232984 : id.transform_call_graph_edges
6380 : 232984 : = update_clones ? CB_CGE_MOVE_CLONES : CB_CGE_MOVE;
6381 : 232984 : id.transform_new_cfg = true;
6382 : 232984 : id.transform_return_to_modify = false;
6383 : 232984 : id.transform_parameter = false;
6384 : :
6385 : 232984 : old_entry_block = ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (old_decl));
6386 : 232984 : DECL_RESULT (new_decl) = DECL_RESULT (old_decl);
6387 : 232984 : DECL_ARGUMENTS (new_decl) = DECL_ARGUMENTS (old_decl);
6388 : 232984 : initialize_cfun (new_decl, old_decl,
6389 : 232984 : new_entry ? new_entry->count : old_entry_block->count);
6390 : 232984 : new_version_node->has_omp_variant_constructs
6391 : 232984 : = old_version_node->has_omp_variant_constructs;
6392 : 232984 : if (DECL_STRUCT_FUNCTION (new_decl)->gimple_df)
6393 : 232984 : DECL_STRUCT_FUNCTION (new_decl)->gimple_df->ipa_pta
6394 : 232984 : = id.src_cfun->gimple_df->ipa_pta;
6395 : :
6396 : : /* Copy the function's static chain. */
6397 : 232984 : p = DECL_STRUCT_FUNCTION (old_decl)->static_chain_decl;
6398 : 232984 : if (p)
6399 : 1928 : DECL_STRUCT_FUNCTION (new_decl)->static_chain_decl
6400 : 964 : = copy_static_chain (p, &id);
6401 : :
6402 : 232984 : auto_vec<int, 16> new_param_indices;
6403 : 232984 : clone_info *info = clone_info::get (old_version_node);
6404 : 238549 : ipa_param_adjustments *old_param_adjustments
6405 : 232984 : = info ? info->param_adjustments : NULL;
6406 : 5565 : if (old_param_adjustments)
6407 : 5483 : old_param_adjustments->get_updated_indices (&new_param_indices);
6408 : :
6409 : : /* If there's a tree_map, prepare for substitution. */
6410 : 232984 : if (tree_map)
6411 : 33944 : for (i = 0; i < tree_map->length (); i++)
6412 : : {
6413 : 21169 : gimple *init;
6414 : 21169 : replace_info = (*tree_map)[i];
6415 : :
6416 : 21169 : int p = replace_info->parm_num;
6417 : 21169 : if (old_param_adjustments)
6418 : 0 : p = new_param_indices[p];
6419 : :
6420 : 21169 : tree parm;
6421 : 63563 : for (parm = DECL_ARGUMENTS (old_decl); p;
6422 : 42394 : parm = DECL_CHAIN (parm))
6423 : 42394 : p--;
6424 : 21169 : gcc_assert (parm);
6425 : 21169 : init = setup_one_parameter (&id, parm, replace_info->new_tree,
6426 : : id.src_fn, NULL, &vars);
6427 : 21169 : if (init)
6428 : 6486 : init_stmts.safe_push (init);
6429 : : }
6430 : :
6431 : 232984 : ipa_param_body_adjustments *param_body_adjs = NULL;
6432 : 232984 : if (param_adjustments)
6433 : : {
6434 : 307922 : param_body_adjs = new ipa_param_body_adjustments (param_adjustments,
6435 : : new_decl, old_decl,
6436 : 153961 : &id, &vars, tree_map);
6437 : 153961 : id.param_body_adjs = param_body_adjs;
6438 : 153961 : DECL_ARGUMENTS (new_decl) = param_body_adjs->get_new_param_chain ();
6439 : : }
6440 : 79023 : else if (DECL_ARGUMENTS (old_decl) != NULL_TREE)
6441 : 146820 : DECL_ARGUMENTS (new_decl)
6442 : 73410 : = copy_arguments_nochange (DECL_ARGUMENTS (old_decl), &id);
6443 : :
6444 : 232984 : DECL_INITIAL (new_decl) = remap_blocks (DECL_INITIAL (id.src_fn), &id);
6445 : 232984 : BLOCK_SUPERCONTEXT (DECL_INITIAL (new_decl)) = new_decl;
6446 : :
6447 : 232984 : declare_inline_vars (DECL_INITIAL (new_decl), vars);
6448 : :
6449 : 232984 : if (!vec_safe_is_empty (DECL_STRUCT_FUNCTION (old_decl)->local_decls))
6450 : : /* Add local vars. */
6451 : 135119 : add_local_variables (DECL_STRUCT_FUNCTION (old_decl), cfun, &id);
6452 : :
6453 : 232984 : if (DECL_RESULT (old_decl) == NULL_TREE)
6454 : : ;
6455 : 153961 : else if (param_adjustments && param_adjustments->m_skip_return
6456 : 280742 : && !VOID_TYPE_P (TREE_TYPE (DECL_RESULT (old_decl))))
6457 : : {
6458 : 40607 : tree resdecl_repl = copy_result_decl_to_var (DECL_RESULT (old_decl),
6459 : : &id);
6460 : 40607 : declare_inline_vars (NULL, resdecl_repl);
6461 : 40607 : if (DECL_BY_REFERENCE (DECL_RESULT (old_decl)))
6462 : 73 : resdecl_repl = build_fold_addr_expr (resdecl_repl);
6463 : 40607 : insert_decl_map (&id, DECL_RESULT (old_decl), resdecl_repl);
6464 : :
6465 : 81214 : DECL_RESULT (new_decl)
6466 : 40607 : = build_decl (DECL_SOURCE_LOCATION (DECL_RESULT (old_decl)),
6467 : : RESULT_DECL, NULL_TREE, void_type_node);
6468 : 40607 : DECL_CONTEXT (DECL_RESULT (new_decl)) = new_decl;
6469 : 40607 : DECL_IS_MALLOC (new_decl) = false;
6470 : 40607 : cfun->returns_struct = 0;
6471 : 40607 : cfun->returns_pcc_struct = 0;
6472 : : }
6473 : : else
6474 : : {
6475 : 192377 : tree old_name;
6476 : 192377 : DECL_RESULT (new_decl) = remap_decl (DECL_RESULT (old_decl), &id);
6477 : 192377 : lang_hooks.dup_lang_specific_decl (DECL_RESULT (new_decl));
6478 : 384754 : if (gimple_in_ssa_p (id.src_cfun)
6479 : 192377 : && DECL_BY_REFERENCE (DECL_RESULT (old_decl))
6480 : 4838 : && (old_name = ssa_default_def (id.src_cfun, DECL_RESULT (old_decl))))
6481 : : {
6482 : 4819 : tree new_name = make_ssa_name (DECL_RESULT (new_decl));
6483 : 4819 : insert_decl_map (&id, old_name, new_name);
6484 : 4819 : SSA_NAME_DEF_STMT (new_name) = gimple_build_nop ();
6485 : 4819 : set_ssa_default_def (cfun, DECL_RESULT (new_decl), new_name);
6486 : : }
6487 : : }
6488 : :
6489 : : /* Set up the destination functions loop tree. */
6490 : 232984 : if (loops_for_fn (DECL_STRUCT_FUNCTION (old_decl)) != NULL)
6491 : : {
6492 : 232984 : cfun->curr_properties &= ~PROP_loops;
6493 : 232984 : loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
6494 : 232984 : cfun->curr_properties |= PROP_loops;
6495 : : }
6496 : :
6497 : : /* Copy the Function's body. */
6498 : 232984 : copy_body (&id, ENTRY_BLOCK_PTR_FOR_FN (cfun), EXIT_BLOCK_PTR_FOR_FN (cfun),
6499 : : new_entry);
6500 : :
6501 : : /* Renumber the lexical scoping (non-code) blocks consecutively. */
6502 : 232984 : number_blocks (new_decl);
6503 : :
6504 : : /* We want to create the BB unconditionally, so that the addition of
6505 : : debug stmts doesn't affect BB count, which may in the end cause
6506 : : codegen differences. */
6507 : 232984 : bb = split_edge (single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
6508 : 472454 : while (init_stmts.length ())
6509 : 6486 : insert_init_stmt (&id, bb, init_stmts.pop ());
6510 : 232984 : if (param_body_adjs)
6511 : 153961 : param_body_adjs->append_init_stmts (bb);
6512 : 232984 : update_clone_info (&id);
6513 : :
6514 : : /* Remap the nonlocal_goto_save_area, if any. */
6515 : 232984 : if (cfun->nonlocal_goto_save_area)
6516 : : {
6517 : 0 : struct walk_stmt_info wi;
6518 : :
6519 : 0 : memset (&wi, 0, sizeof (wi));
6520 : 0 : wi.info = &id;
6521 : 0 : walk_tree (&cfun->nonlocal_goto_save_area, remap_gimple_op_r, &wi, NULL);
6522 : : }
6523 : :
6524 : : /* Clean up. */
6525 : 465968 : delete id.decl_map;
6526 : 232984 : if (id.debug_map)
6527 : 1430 : delete id.debug_map;
6528 : 232984 : free_dominance_info (CDI_DOMINATORS);
6529 : 232984 : free_dominance_info (CDI_POST_DOMINATORS);
6530 : :
6531 : 232984 : update_max_bb_count ();
6532 : 232984 : fold_marked_statements (0, id.statements_to_fold);
6533 : 465968 : delete id.statements_to_fold;
6534 : 232984 : delete_unreachable_blocks_update_callgraph (id.dst_node, update_clones);
6535 : 232984 : if (id.dst_node->definition)
6536 : 228576 : cgraph_edge::rebuild_references ();
6537 : 232984 : if (loops_state_satisfies_p (LOOPS_NEED_FIXUP))
6538 : : {
6539 : 232984 : calculate_dominance_info (CDI_DOMINATORS);
6540 : 232984 : fix_loop_structure (NULL);
6541 : : }
6542 : 232984 : update_ssa (TODO_update_ssa);
6543 : :
6544 : : /* After partial cloning we need to rescale frequencies, so they are
6545 : : within proper range in the cloned function. */
6546 : 232984 : if (new_entry)
6547 : : {
6548 : 50054 : struct cgraph_edge *e;
6549 : 50054 : rebuild_frequencies ();
6550 : :
6551 : 50054 : new_version_node->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
6552 : 228652 : for (e = new_version_node->callees; e; e = e->next_callee)
6553 : : {
6554 : 178598 : basic_block bb = gimple_bb (e->call_stmt);
6555 : 178598 : e->count = bb->count;
6556 : : }
6557 : 55256 : for (e = new_version_node->indirect_calls; e; e = e->next_callee)
6558 : : {
6559 : 5202 : basic_block bb = gimple_bb (e->call_stmt);
6560 : 5202 : e->count = bb->count;
6561 : : }
6562 : : }
6563 : :
6564 : 232984 : if (param_body_adjs && MAY_HAVE_DEBUG_BIND_STMTS)
6565 : : {
6566 : 131386 : vec<tree, va_gc> **debug_args = NULL;
6567 : 131386 : unsigned int len = 0;
6568 : 131386 : unsigned reset_len = param_body_adjs->m_reset_debug_decls.length ();
6569 : :
6570 : 238512 : for (i = 0; i < reset_len; i++)
6571 : : {
6572 : 107126 : tree parm = param_body_adjs->m_reset_debug_decls[i];
6573 : 107126 : gcc_assert (is_gimple_reg (parm));
6574 : 107126 : tree ddecl;
6575 : :
6576 : 107126 : if (debug_args == NULL)
6577 : : {
6578 : 78956 : debug_args = decl_debug_args_insert (new_decl);
6579 : 78956 : len = vec_safe_length (*debug_args);
6580 : : }
6581 : 107126 : ddecl = build_debug_expr_decl (TREE_TYPE (parm));
6582 : : /* FIXME: Is setting the mode really necessary? */
6583 : 107126 : SET_DECL_MODE (ddecl, DECL_MODE (parm));
6584 : 107126 : vec_safe_push (*debug_args, DECL_ORIGIN (parm));
6585 : 107126 : vec_safe_push (*debug_args, ddecl);
6586 : : }
6587 : 131386 : if (debug_args != NULL)
6588 : : {
6589 : : /* On the callee side, add
6590 : : DEBUG D#Y s=> parm
6591 : : DEBUG var => D#Y
6592 : : stmts to the first bb where var is a VAR_DECL created for the
6593 : : optimized away parameter in DECL_INITIAL block. This hints
6594 : : in the debug info that var (whole DECL_ORIGIN is the parm
6595 : : PARM_DECL) is optimized away, but could be looked up at the
6596 : : call site as value of D#X there. */
6597 : 78956 : gimple_stmt_iterator cgsi
6598 : 78956 : = gsi_after_labels (single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
6599 : 78956 : gimple *def_temp;
6600 : 78956 : tree var = vars;
6601 : 78956 : i = vec_safe_length (*debug_args);
6602 : 107126 : do
6603 : : {
6604 : 107126 : tree vexpr = NULL_TREE;
6605 : 107126 : i -= 2;
6606 : 107126 : while (var != NULL_TREE
6607 : 143701 : && DECL_ABSTRACT_ORIGIN (var) != (**debug_args)[i])
6608 : 36575 : var = TREE_CHAIN (var);
6609 : 107126 : if (var == NULL_TREE)
6610 : : break;
6611 : 107126 : tree parm = (**debug_args)[i];
6612 : 107126 : if (tree parm_ddef = ssa_default_def (id.src_cfun, parm))
6613 : 144970 : if (tree *d
6614 : 72485 : = param_body_adjs->m_dead_ssa_debug_equiv.get (parm_ddef))
6615 : 25047 : vexpr = *d;
6616 : 107126 : if (!vexpr)
6617 : : {
6618 : 82079 : vexpr = build_debug_expr_decl (TREE_TYPE (parm));
6619 : : /* FIXME: Is setting the mode really necessary? */
6620 : 82079 : SET_DECL_MODE (vexpr, DECL_MODE (parm));
6621 : : }
6622 : 107126 : def_temp = gimple_build_debug_bind (var, vexpr, NULL);
6623 : 107126 : gsi_insert_before (&cgsi, def_temp, GSI_NEW_STMT);
6624 : 107126 : def_temp = gimple_build_debug_source_bind (vexpr, parm, NULL);
6625 : 107126 : gsi_insert_before (&cgsi, def_temp, GSI_NEW_STMT);
6626 : : }
6627 : 107126 : while (i > len);
6628 : : }
6629 : : }
6630 : 153961 : delete param_body_adjs;
6631 : 232984 : free_dominance_info (CDI_DOMINATORS);
6632 : 232984 : free_dominance_info (CDI_POST_DOMINATORS);
6633 : :
6634 : 232984 : gcc_assert (!id.debug_stmts.exists ());
6635 : 232984 : pop_cfun ();
6636 : 232984 : input_location = saved_location;
6637 : 232984 : return;
6638 : 232984 : }
6639 : :
6640 : : /* EXP is CALL_EXPR present in a GENERIC expression tree. Try to integrate
6641 : : the callee and return the inlined body on success. */
6642 : :
6643 : : tree
6644 : 0 : maybe_inline_call_in_expr (tree exp)
6645 : : {
6646 : 0 : tree fn = get_callee_fndecl (exp);
6647 : :
6648 : : /* We can only try to inline "const" functions. */
6649 : 0 : if (fn && TREE_READONLY (fn) && DECL_SAVED_TREE (fn))
6650 : : {
6651 : 0 : call_expr_arg_iterator iter;
6652 : 0 : copy_body_data id;
6653 : 0 : tree param, arg, t;
6654 : 0 : hash_map<tree, tree> decl_map;
6655 : :
6656 : : /* Remap the parameters. */
6657 : 0 : for (param = DECL_ARGUMENTS (fn), arg = first_call_expr_arg (exp, &iter);
6658 : 0 : param;
6659 : 0 : param = DECL_CHAIN (param), arg = next_call_expr_arg (&iter))
6660 : 0 : decl_map.put (param, arg);
6661 : :
6662 : 0 : memset (&id, 0, sizeof (id));
6663 : 0 : id.src_fn = fn;
6664 : 0 : id.dst_fn = current_function_decl;
6665 : 0 : id.src_cfun = DECL_STRUCT_FUNCTION (fn);
6666 : 0 : id.decl_map = &decl_map;
6667 : :
6668 : 0 : id.copy_decl = copy_decl_no_change;
6669 : 0 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
6670 : 0 : id.transform_new_cfg = false;
6671 : 0 : id.transform_return_to_modify = true;
6672 : 0 : id.transform_parameter = true;
6673 : :
6674 : : /* Make sure not to unshare trees behind the front-end's back
6675 : : since front-end specific mechanisms may rely on sharing. */
6676 : 0 : id.regimplify = false;
6677 : 0 : id.do_not_unshare = true;
6678 : :
6679 : : /* We're not inside any EH region. */
6680 : 0 : id.eh_lp_nr = 0;
6681 : :
6682 : 0 : t = copy_tree_body (&id);
6683 : :
6684 : : /* We can only return something suitable for use in a GENERIC
6685 : : expression tree. */
6686 : 0 : if (TREE_CODE (t) == MODIFY_EXPR)
6687 : 0 : return TREE_OPERAND (t, 1);
6688 : 0 : }
6689 : :
6690 : : return NULL_TREE;
6691 : : }
6692 : :
6693 : : /* Duplicate a type, fields and all. */
6694 : :
6695 : : tree
6696 : 62 : build_duplicate_type (tree type)
6697 : : {
6698 : 62 : struct copy_body_data id;
6699 : :
6700 : 62 : memset (&id, 0, sizeof (id));
6701 : 62 : id.src_fn = current_function_decl;
6702 : 62 : id.dst_fn = current_function_decl;
6703 : 62 : id.src_cfun = cfun;
6704 : 62 : id.decl_map = new hash_map<tree, tree>;
6705 : 62 : id.debug_map = NULL;
6706 : 62 : id.copy_decl = copy_decl_no_change;
6707 : :
6708 : 62 : type = remap_type_1 (type, &id);
6709 : :
6710 : 124 : delete id.decl_map;
6711 : 62 : if (id.debug_map)
6712 : 0 : delete id.debug_map;
6713 : :
6714 : 62 : TYPE_CANONICAL (type) = type;
6715 : :
6716 : 62 : return type;
6717 : : }
6718 : :
6719 : : /* Unshare the entire DECL_SAVED_TREE of FN and return the remapped
6720 : : parameters and RESULT_DECL in PARMS and RESULT. Used by C++ constexpr
6721 : : evaluation. */
6722 : :
6723 : : tree
6724 : 18379184 : copy_fn (tree fn, tree& parms, tree& result)
6725 : : {
6726 : 18379184 : copy_body_data id;
6727 : 18379184 : tree param;
6728 : 18379184 : hash_map<tree, tree> decl_map;
6729 : :
6730 : 18379184 : tree *p = &parms;
6731 : 18379184 : *p = NULL_TREE;
6732 : :
6733 : 18379184 : memset (&id, 0, sizeof (id));
6734 : 18379184 : id.src_fn = fn;
6735 : 18379184 : id.dst_fn = current_function_decl;
6736 : 18379184 : id.src_cfun = DECL_STRUCT_FUNCTION (fn);
6737 : 18379184 : id.decl_map = &decl_map;
6738 : :
6739 : 71110817 : id.copy_decl = [] (tree decl, copy_body_data *id)
6740 : : {
6741 : 52731633 : if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
6742 : : /* Don't make copies of local types or injected enumerators,
6743 : : the C++ constexpr evaluator doesn't need them and they
6744 : : confuse modules streaming. */
6745 : : return decl;
6746 : 51457262 : return copy_decl_no_change (decl, id);
6747 : : };
6748 : 18379184 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
6749 : 18379184 : id.transform_new_cfg = false;
6750 : 18379184 : id.transform_return_to_modify = false;
6751 : 18379184 : id.transform_parameter = true;
6752 : :
6753 : : /* Make sure not to unshare trees behind the front-end's back
6754 : : since front-end specific mechanisms may rely on sharing. */
6755 : 18379184 : id.regimplify = false;
6756 : 18379184 : id.do_not_unshare = true;
6757 : 18379184 : id.do_not_fold = true;
6758 : :
6759 : : /* We're not inside any EH region. */
6760 : 18379184 : id.eh_lp_nr = 0;
6761 : :
6762 : : /* Remap the parameters and result and return them to the caller. */
6763 : 18379184 : for (param = DECL_ARGUMENTS (fn);
6764 : 41613022 : param;
6765 : 23233838 : param = DECL_CHAIN (param))
6766 : : {
6767 : 23233838 : *p = remap_decl (param, &id);
6768 : 23233838 : p = &DECL_CHAIN (*p);
6769 : : }
6770 : :
6771 : 18379184 : if (DECL_RESULT (fn))
6772 : 18379184 : result = remap_decl (DECL_RESULT (fn), &id);
6773 : : else
6774 : 0 : result = NULL_TREE;
6775 : :
6776 : 18379184 : return copy_tree_body (&id);
6777 : 18379184 : }
|