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