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