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 698164484 : insert_decl_map (copy_body_data *id, tree key, tree value)
147 : {
148 698164484 : 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 698164484 : if (key != value && value)
153 213028002 : id->decl_map->put (value, value);
154 698164484 : }
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 71487699 : remap_ssa_name (tree name, copy_body_data *id)
166 : {
167 71487699 : tree new_tree, var;
168 71487699 : tree *n;
169 :
170 71487699 : gcc_assert (TREE_CODE (name) == SSA_NAME);
171 :
172 71487699 : n = id->decl_map->get (name);
173 71487699 : 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 52575597 : if (id->killed_new_ssa_names
180 52575597 : && id->killed_new_ssa_names->contains (*n))
181 : {
182 383 : gcc_assert (processing_debug_stmt);
183 383 : processing_debug_stmt = -1;
184 383 : return name;
185 : }
186 :
187 52575214 : return unshare_expr (*n);
188 : }
189 :
190 18912102 : if (processing_debug_stmt)
191 : {
192 100794 : if (SSA_NAME_IS_DEFAULT_DEF (name)
193 100751 : && TREE_CODE (SSA_NAME_VAR (name)) == PARM_DECL
194 100704 : && id->entry_bb == NULL
195 201497 : && single_succ_p (ENTRY_BLOCK_PTR_FOR_FN (cfun)))
196 : {
197 100703 : gimple *def_temp;
198 100703 : gimple_stmt_iterator gsi;
199 100703 : tree val = SSA_NAME_VAR (name);
200 :
201 100703 : n = id->decl_map->get (val);
202 100703 : if (n != NULL)
203 100703 : val = *n;
204 100703 : if (TREE_CODE (val) != PARM_DECL
205 100703 : && !(VAR_P (val) && DECL_ABSTRACT_ORIGIN (val)))
206 : {
207 0 : processing_debug_stmt = -1;
208 0 : return name;
209 : }
210 100703 : n = id->decl_map->get (val);
211 100703 : if (n && TREE_CODE (*n) == DEBUG_EXPR_DECL)
212 : return *n;
213 35284 : tree vexpr = build_debug_expr_decl (TREE_TYPE (name));
214 : /* FIXME: Is setting the mode really necessary? */
215 35284 : SET_DECL_MODE (vexpr, DECL_MODE (SSA_NAME_VAR (name)));
216 35284 : def_temp = gimple_build_debug_source_bind (vexpr, val, NULL);
217 35284 : gsi = gsi_after_labels (single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
218 35284 : gsi_insert_before (&gsi, def_temp, GSI_SAME_STMT);
219 35284 : insert_decl_map (id, val, vexpr);
220 35284 : 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 18811308 : var = SSA_NAME_VAR (name);
229 3738122 : if (!var
230 3738122 : || (!SSA_NAME_IS_DEFAULT_DEF (name)
231 3332303 : && VAR_P (var)
232 3122761 : && !VAR_DECL_IS_VIRTUAL_OPERAND (var)
233 3122761 : && DECL_ARTIFICIAL (var)
234 558990 : && DECL_IGNORED_P (var)
235 159076 : && !DECL_NAME (var)))
236 : {
237 15078552 : struct ptr_info_def *pi;
238 15078552 : new_tree = make_ssa_name (remap_type (TREE_TYPE (name), id));
239 15078552 : if (!var && SSA_NAME_IDENTIFIER (name))
240 1939950 : SET_SSA_NAME_VAR_OR_IDENTIFIER (new_tree, SSA_NAME_IDENTIFIER (name));
241 15078552 : insert_decl_map (id, name, new_tree);
242 30157104 : SSA_NAME_OCCURS_IN_ABNORMAL_PHI (new_tree)
243 15078552 : = SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name);
244 : /* At least IPA points-to info can be directly transferred. */
245 15078552 : if (id->src_cfun->gimple_df
246 15078552 : && id->src_cfun->gimple_df->ipa_pta
247 14710 : && POINTER_TYPE_P (TREE_TYPE (name))
248 2598 : && (pi = SSA_NAME_PTR_INFO (name))
249 15081145 : && !pi->pt.anything)
250 : {
251 2572 : struct ptr_info_def *new_pi = get_ptr_info (new_tree);
252 2572 : new_pi->pt = pi->pt;
253 : }
254 : /* So can range-info. */
255 25123448 : if (!POINTER_TYPE_P (TREE_TYPE (name))
256 24525842 : && SSA_NAME_RANGE_INFO (name))
257 3152275 : duplicate_ssa_name_range_info (new_tree, name);
258 15078552 : 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 3732756 : 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 390891 : if ((VAR_P (new_tree) || TREE_CODE (new_tree) == PARM_DECL)
272 4123647 : && (!SSA_NAME_VAR (name)
273 3732756 : || TREE_CODE (SSA_NAME_VAR (name)) != RESULT_DECL
274 0 : || !id->transform_return_to_modify))
275 : {
276 3732756 : struct ptr_info_def *pi;
277 3732756 : new_tree = make_ssa_name (new_tree);
278 3732756 : insert_decl_map (id, name, new_tree);
279 7465512 : SSA_NAME_OCCURS_IN_ABNORMAL_PHI (new_tree)
280 3732756 : = SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name);
281 : /* At least IPA points-to info can be directly transferred. */
282 3732756 : if (id->src_cfun->gimple_df
283 3732756 : && id->src_cfun->gimple_df->ipa_pta
284 2517 : && POINTER_TYPE_P (TREE_TYPE (name))
285 283 : && (pi = SSA_NAME_PTR_INFO (name))
286 3733033 : && !pi->pt.anything)
287 : {
288 277 : struct ptr_info_def *new_pi = get_ptr_info (new_tree);
289 277 : new_pi->pt = pi->pt;
290 : }
291 : /* So can range-info. */
292 6580165 : if (!POINTER_TYPE_P (TREE_TYPE (name))
293 6490109 : && SSA_NAME_RANGE_INFO (name))
294 982966 : duplicate_ssa_name_range_info (new_tree, name);
295 3732756 : 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 405819 : if (id->entry_bb
307 43692 : && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name)
308 0 : && (!SSA_NAME_VAR (name)
309 0 : || TREE_CODE (SSA_NAME_VAR (name)) != PARM_DECL)
310 405819 : && (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 405819 : SSA_NAME_DEF_STMT (new_tree) = gimple_build_nop ();
325 405819 : 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 355077567 : remap_decl (tree decl, copy_body_data *id)
338 : {
339 355077567 : tree *n;
340 :
341 : /* We only remap local variables in the current function. */
342 :
343 : /* See if we have remapped this declaration. */
344 :
345 355077567 : n = id->decl_map->get (decl);
346 :
347 355077567 : if (!n && processing_debug_stmt)
348 : {
349 668041 : processing_debug_stmt = -1;
350 668041 : 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 130886802 : if (!n
357 130886802 : && 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 354409526 : if (!n)
365 : {
366 : /* Make a copy of the variable or label. */
367 130886802 : 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 130886802 : insert_decl_map (id, decl, t);
373 :
374 130886802 : if (!DECL_P (t) || t == decl)
375 : return t;
376 :
377 : /* Remap types, if necessary. */
378 128506257 : TREE_TYPE (t) = remap_type (TREE_TYPE (t), id);
379 128506257 : if (TREE_CODE (t) == TYPE_DECL)
380 : {
381 1585266 : 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 1585266 : 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 128506257 : walk_tree (&DECL_SIZE (t), copy_tree_body_r, id, NULL);
397 128506257 : walk_tree (&DECL_SIZE_UNIT (t), copy_tree_body_r, id, NULL);
398 :
399 : /* If fields, do likewise for offset and qualifier. */
400 128506257 : if (TREE_CODE (t) == FIELD_DECL)
401 : {
402 773 : walk_tree (&DECL_FIELD_OFFSET (t), copy_tree_body_r, id, NULL);
403 773 : 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 128506257 : return t;
408 : }
409 :
410 223522724 : if (id->do_not_unshare)
411 141785899 : return *n;
412 : else
413 81736825 : return unshare_expr (*n);
414 : }
415 :
416 : static tree
417 101269 : remap_type_1 (tree type, copy_body_data *id)
418 : {
419 101269 : 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 101269 : if (TREE_CODE (type) == POINTER_TYPE)
425 : {
426 27481 : new_tree = build_pointer_type_for_mode (remap_type (TREE_TYPE (type), id),
427 27481 : TYPE_MODE (type),
428 27481 : TYPE_REF_CAN_ALIAS_ALL (type));
429 27481 : if (TYPE_ATTRIBUTES (type) || TYPE_QUALS (type))
430 14788 : new_tree = build_type_attribute_qual_variant (new_tree,
431 14788 : TYPE_ATTRIBUTES (type),
432 14788 : TYPE_QUALS (type));
433 27481 : insert_decl_map (id, type, new_tree);
434 27481 : return new_tree;
435 : }
436 73788 : else if (TREE_CODE (type) == REFERENCE_TYPE)
437 : {
438 7996 : new_tree = build_reference_type_for_mode (remap_type (TREE_TYPE (type), id),
439 7996 : TYPE_MODE (type),
440 7996 : TYPE_REF_CAN_ALIAS_ALL (type));
441 7996 : if (TYPE_ATTRIBUTES (type) || TYPE_QUALS (type))
442 5424 : new_tree = build_type_attribute_qual_variant (new_tree,
443 5424 : TYPE_ATTRIBUTES (type),
444 5424 : TYPE_QUALS (type));
445 7996 : insert_decl_map (id, type, new_tree);
446 7996 : return new_tree;
447 : }
448 : else
449 65792 : new_tree = copy_node (type);
450 :
451 65792 : 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 65792 : t = TYPE_MAIN_VARIANT (type);
456 65792 : if (type != t)
457 : {
458 79 : t = remap_type (t, id);
459 79 : TYPE_MAIN_VARIANT (new_tree) = t;
460 79 : TYPE_NEXT_VARIANT (new_tree) = TYPE_NEXT_VARIANT (t);
461 79 : TYPE_NEXT_VARIANT (t) = new_tree;
462 : }
463 : else
464 : {
465 65713 : TYPE_MAIN_VARIANT (new_tree) = new_tree;
466 65713 : TYPE_NEXT_VARIANT (new_tree) = NULL;
467 : }
468 :
469 65792 : if (TYPE_STUB_DECL (type))
470 182 : TYPE_STUB_DECL (new_tree) = remap_decl (TYPE_STUB_DECL (type), id);
471 :
472 : /* Lazily create pointer and reference types. */
473 65792 : TYPE_POINTER_TO (new_tree) = NULL;
474 65792 : 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 65792 : switch (TREE_CODE (new_tree))
479 : {
480 31572 : case INTEGER_TYPE:
481 31572 : case REAL_TYPE:
482 31572 : case FIXED_POINT_TYPE:
483 31572 : case ENUMERAL_TYPE:
484 31572 : case BOOLEAN_TYPE:
485 31572 : 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 31572 : t = TYPE_MIN_VALUE (new_tree);
496 31572 : if (t && TREE_CODE (t) != INTEGER_CST)
497 0 : walk_tree (&TYPE_MIN_VALUE (new_tree), copy_tree_body_r, id, NULL);
498 :
499 31572 : t = TYPE_MAX_VALUE (new_tree);
500 31572 : if (t && TREE_CODE (t) != INTEGER_CST)
501 31572 : 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 33973 : case ARRAY_TYPE:
519 33973 : if (TYPE_MAIN_VARIANT (new_tree) != new_tree
520 33973 : && 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 33944 : TREE_TYPE (new_tree) = remap_type (TREE_TYPE (new_tree), id);
524 :
525 33973 : if (TYPE_MAIN_VARIANT (new_tree) != new_tree)
526 : {
527 62 : gcc_checking_assert (TYPE_DOMAIN (type)
528 : == TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)));
529 62 : TYPE_DOMAIN (new_tree) = TYPE_DOMAIN (TYPE_MAIN_VARIANT (new_tree));
530 : }
531 : else
532 : {
533 33911 : 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 33911 : if (id->adjust_array_error_bounds
538 3723 : && TYPE_DOMAIN (new_tree)
539 3723 : && TYPE_MAX_VALUE (TYPE_DOMAIN (new_tree)) == error_mark_node
540 36787 : && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != error_mark_node)
541 : {
542 2876 : tree v = create_tmp_var (TREE_TYPE (TYPE_DOMAIN (new_tree)));
543 2876 : DECL_ATTRIBUTES (v)
544 2876 : = tree_cons (get_identifier ("omp dummy var"), NULL_TREE,
545 2876 : DECL_ATTRIBUTES (v));
546 2876 : TYPE_MAX_VALUE (TYPE_DOMAIN (new_tree)) = v;
547 : }
548 : }
549 : break;
550 :
551 231 : case RECORD_TYPE:
552 231 : case UNION_TYPE:
553 231 : case QUAL_UNION_TYPE:
554 231 : if (TYPE_MAIN_VARIANT (type) != type
555 231 : && 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 214 : tree f, nf = NULL;
560 :
561 987 : for (f = TYPE_FIELDS (new_tree); f ; f = DECL_CHAIN (f))
562 : {
563 773 : t = remap_decl (f, id);
564 773 : DECL_CONTEXT (t) = new_tree;
565 773 : DECL_CHAIN (t) = nf;
566 773 : nf = t;
567 : }
568 214 : 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 remapped data. */
579 34204 : if (TYPE_MAIN_VARIANT (new_tree) != new_tree)
580 : {
581 79 : tree s = TYPE_SIZE (type);
582 79 : tree mvs = TYPE_SIZE (TYPE_MAIN_VARIANT (type));
583 79 : tree su = TYPE_SIZE_UNIT (type);
584 79 : tree mvsu = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (type));
585 79 : gcc_checking_assert ((TREE_CODE (s) == PLACEHOLDER_EXPR
586 : && (TREE_CODE (mvs) == PLACEHOLDER_EXPR))
587 : || s == mvs);
588 79 : gcc_checking_assert ((TREE_CODE (su) == PLACEHOLDER_EXPR
589 : && (TREE_CODE (mvsu) == PLACEHOLDER_EXPR))
590 : || su == mvsu);
591 79 : TYPE_SIZE (new_tree) = TYPE_SIZE (TYPE_MAIN_VARIANT (new_tree));
592 79 : TYPE_SIZE_UNIT (new_tree) = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (new_tree));
593 : }
594 : else
595 : {
596 34125 : walk_tree (&TYPE_SIZE (new_tree), copy_tree_body_r, id, NULL);
597 34125 : 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 30877 : remap_type_3 (tree *tp, int *walk_subtrees, void *data)
607 : {
608 30877 : copy_body_data *id = (copy_body_data *) data;
609 :
610 30877 : if (TYPE_P (*tp))
611 0 : *walk_subtrees = 0;
612 :
613 30877 : 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 51716 : remap_type_2 (tree type, copy_body_data *id)
624 : {
625 62395 : 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 62395 : switch (TREE_CODE (type))
643 : {
644 10679 : case POINTER_TYPE:
645 10679 : case REFERENCE_TYPE:
646 10679 : case FUNCTION_TYPE:
647 10679 : case METHOD_TYPE:
648 10679 : return remap_type_2 (TREE_TYPE (type), id);
649 :
650 34757 : case INTEGER_TYPE:
651 34757 : case REAL_TYPE:
652 34757 : case FIXED_POINT_TYPE:
653 34757 : case ENUMERAL_TYPE:
654 34757 : case BOOLEAN_TYPE:
655 34757 : RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
656 34757 : RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
657 22941 : return false;
658 :
659 16484 : case ARRAY_TYPE:
660 16484 : if (remap_type_2 (TREE_TYPE (type), id)
661 32314 : || (TYPE_DOMAIN (type) && remap_type_2 (TYPE_DOMAIN (type), id)))
662 9056 : 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 7785 : RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
684 7776 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type));
685 7051 : return false;
686 : #undef RETURN_TRUE_IF_VAR
687 : }
688 :
689 : tree
690 1413279829 : remap_type (tree type, copy_body_data *id)
691 : {
692 1413279829 : tree *node;
693 1413279829 : tree tmp;
694 :
695 1413279829 : if (type == NULL)
696 : return type;
697 :
698 : /* See if we have remapped this type. */
699 1412922651 : node = id->decl_map->get (type);
700 1412922651 : if (node)
701 930590706 : return *node;
702 :
703 : /* The type only needs remapping if it's variably modified. */
704 482331945 : 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 482331945 : || (id->dont_remap_vla_if_no_change && !remap_type_2 (type, id)))
708 : {
709 482230739 : insert_decl_map (id, type, type);
710 482230739 : return type;
711 : }
712 :
713 101206 : id->remapping_type_depth++;
714 101206 : tmp = remap_type_1 (type, id);
715 101206 : id->remapping_type_depth--;
716 :
717 101206 : return tmp;
718 : }
719 :
720 : /* Decide if DECL can be put into BLOCK_NONLOCAL_VARs. */
721 :
722 : static bool
723 50877546 : can_be_nonlocal (tree decl, copy_body_data *id)
724 : {
725 : /* We cannot duplicate function decls. */
726 50877546 : 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 50859264 : 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 52772450 : remap_decls (tree decls, vec<tree, va_gc> **nonlocalized_list,
739 : copy_body_data *id)
740 : {
741 52772450 : tree old_var;
742 52772450 : tree new_decls = NULL_TREE;
743 :
744 : /* Remap its variables. */
745 99218090 : for (old_var = decls; old_var; old_var = DECL_CHAIN (old_var))
746 : {
747 46445640 : tree new_var;
748 :
749 46445640 : 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 157688 : if (VAR_P (old_var) && ! DECL_EXTERNAL (old_var) && cfun)
754 139142 : add_local_decl (cfun, old_var);
755 97173 : if ((!optimize || debug_info_level > DINFO_LEVEL_TERSE)
756 131000 : && !DECL_IGNORED_P (old_var)
757 288439 : && nonlocalized_list)
758 81736 : vec_safe_push (*nonlocalized_list, old_var);
759 157688 : continue;
760 : }
761 :
762 : /* Remap the variable. */
763 46287952 : 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 46287952 : if (new_var == old_var || new_var == id->retvar)
770 : ;
771 41963858 : 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 41963858 : gcc_assert (DECL_P (new_var));
781 41963858 : DECL_CHAIN (new_var) = new_decls;
782 41963858 : new_decls = new_var;
783 :
784 : /* Also copy value-expressions. */
785 41963858 : if (VAR_P (new_var) && DECL_HAS_VALUE_EXPR_P (new_var))
786 : {
787 1569276 : tree tem = DECL_VALUE_EXPR (new_var);
788 1569276 : bool old_regimplify = id->regimplify;
789 1569276 : id->remapping_type_depth++;
790 1569276 : walk_tree (&tem, copy_tree_body_r, id, NULL);
791 1569276 : id->remapping_type_depth--;
792 1569276 : id->regimplify = old_regimplify;
793 1569276 : SET_DECL_VALUE_EXPR (new_var, tem);
794 : }
795 : }
796 : }
797 :
798 52772450 : 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 47342115 : remap_block (tree *block, copy_body_data *id)
806 : {
807 47342115 : tree old_block;
808 47342115 : tree new_block;
809 :
810 : /* Make the new block. */
811 47342115 : old_block = *block;
812 47342115 : new_block = make_node (BLOCK);
813 47342115 : TREE_USED (new_block) = TREE_USED (old_block);
814 47342115 : BLOCK_ABSTRACT_ORIGIN (new_block) = BLOCK_ORIGIN (old_block);
815 47342115 : BLOCK_SOURCE_LOCATION (new_block) = BLOCK_SOURCE_LOCATION (old_block);
816 47342115 : BLOCK_NONLOCALIZED_VARS (new_block)
817 47423180 : = vec_safe_copy (BLOCK_NONLOCALIZED_VARS (old_block));
818 47342115 : *block = new_block;
819 :
820 : /* Remap its variables. */
821 94684230 : BLOCK_VARS (new_block) = remap_decls (BLOCK_VARS (old_block),
822 47342115 : &BLOCK_NONLOCALIZED_VARS (new_block),
823 : id);
824 :
825 : /* Remember the remapped block. */
826 47342115 : insert_decl_map (id, old_block, new_block);
827 47342115 : }
828 :
829 : /* Copy the whole block tree and root it in id->block. */
830 :
831 : static tree
832 26627150 : remap_blocks (tree block, copy_body_data *id)
833 : {
834 26627150 : tree t;
835 26627150 : tree new_tree = block;
836 :
837 26627150 : if (!block)
838 : return NULL;
839 :
840 26627150 : remap_block (&new_tree, id);
841 26627150 : gcc_assert (new_tree != block);
842 48378143 : for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t))
843 21750993 : 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 26627150 : BLOCK_SUBBLOCKS (new_tree) = blocks_nreverse (BLOCK_SUBBLOCKS (new_tree));
847 26627150 : return new_tree;
848 : }
849 :
850 : /* Remap the block tree rooted at BLOCK to nothing. */
851 :
852 : static void
853 70814 : remap_blocks_to_null (tree block, copy_body_data *id)
854 : {
855 70814 : tree t;
856 70814 : insert_decl_map (id, block, NULL_TREE);
857 115655 : for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t))
858 44841 : remap_blocks_to_null (t, id);
859 70814 : }
860 :
861 : /* Remap the location info pointed to by LOCUS. */
862 :
863 : static location_t
864 26665738 : remap_location (location_t locus, copy_body_data *id)
865 : {
866 26665738 : if (LOCATION_BLOCK (locus))
867 : {
868 10764761 : tree *n = id->decl_map->get (LOCATION_BLOCK (locus));
869 10764761 : gcc_assert (n);
870 10764761 : if (*n)
871 10732936 : return set_block (locus, *n);
872 : }
873 :
874 15932802 : locus = LOCATION_LOCUS (locus);
875 :
876 15932802 : if (locus != UNKNOWN_LOCATION && id->block)
877 15 : return set_block (locus, id->block);
878 :
879 : return locus;
880 : }
881 :
882 : static void
883 38080105 : copy_statement_list (tree *tp)
884 : {
885 38080105 : tree_stmt_iterator oi, ni;
886 38080105 : tree new_tree;
887 :
888 38080105 : new_tree = alloc_stmt_list ();
889 38080105 : ni = tsi_start (new_tree);
890 38080105 : oi = tsi_start (*tp);
891 38080105 : TREE_TYPE (new_tree) = TREE_TYPE (*tp);
892 38080105 : *tp = new_tree;
893 :
894 125073641 : for (; !tsi_end_p (oi); tsi_next (&oi))
895 : {
896 86993536 : tree stmt = tsi_stmt (oi);
897 86993536 : 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 77269 : copy_statement_list (&stmt);
902 86993536 : tsi_link_after (&ni, stmt, TSI_CONTINUE_LINKING);
903 : }
904 38080105 : }
905 :
906 : static void
907 20715246 : copy_bind_expr (tree *tp, int *walk_subtrees, copy_body_data *id)
908 : {
909 20715246 : tree block = BIND_EXPR_BLOCK (*tp);
910 : /* Copy (and replace) the statement. */
911 20715246 : copy_tree_r (tp, walk_subtrees, NULL);
912 20715246 : if (block)
913 : {
914 20714678 : remap_block (&block, id);
915 20714678 : BIND_EXPR_BLOCK (*tp) = block;
916 : }
917 :
918 20715246 : if (BIND_EXPR_VARS (*tp))
919 : /* This will remap a lot of the same decls again, but this should be
920 : harmless. */
921 5430167 : BIND_EXPR_VARS (*tp) = remap_decls (BIND_EXPR_VARS (*tp), NULL, id);
922 20715246 : }
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 31542 : is_parm (tree decl)
978 : {
979 31542 : if (TREE_CODE (decl) == SSA_NAME)
980 : {
981 29668 : decl = SSA_NAME_VAR (decl);
982 : if (!decl)
983 : return false;
984 : }
985 :
986 19013 : 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 21468563 : maybe_copy_this_notrap (copy_body_data *id, tree t, tree old)
994 : {
995 21468563 : 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 21468563 : if (TREE_THIS_NOTRAP (old)
1003 21468563 : && (!is_parm (TREE_OPERAND (old, 0))
1004 13380 : || (!id->transform_parameter && is_parm (TREE_OPERAND (t, 0)))
1005 9881 : || ((TREE_CODE (t) == INDIRECT_REF
1006 9881 : || integer_zerop (TREE_OPERAND (t, 1)))
1007 9881 : && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR
1008 9214 : && DECL_P (TREE_OPERAND (TREE_OPERAND (t, 0), 0))
1009 9214 : && type_contains_placeholder_p (TREE_TYPE (t)))))
1010 18162 : TREE_THIS_NOTRAP (t) = 1;
1011 21468563 : }
1012 :
1013 : /* Remap the dependence CLIQUE from the source to the destination function
1014 : as specified in ID. */
1015 :
1016 : static unsigned short
1017 2790366 : remap_dependence_clique (copy_body_data *id, unsigned short clique)
1018 : {
1019 2790366 : if (clique == 0 || processing_debug_stmt)
1020 : return 0;
1021 2756367 : if (!id->dependence_map)
1022 720200 : id->dependence_map = new hash_map<dependence_hash, unsigned short>;
1023 2756367 : bool existed;
1024 2756367 : unsigned short &newc = id->dependence_map->get_or_insert (clique, &existed);
1025 2756367 : if (!existed)
1026 : {
1027 : /* Clique 1 is reserved for local ones set by PTA. */
1028 1078844 : if (cfun->last_clique == 0)
1029 335116 : cfun->last_clique = 1;
1030 2157688 : newc = get_new_clique (cfun);
1031 : }
1032 2756367 : 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 209145906 : remap_gimple_op_r (tree *tp, int *walk_subtrees, void *data)
1042 : {
1043 209145906 : struct walk_stmt_info *wi_p = (struct walk_stmt_info *) data;
1044 209145906 : copy_body_data *id = (copy_body_data *) wi_p->info;
1045 209145906 : tree fn = id->src_fn;
1046 :
1047 : /* For recursive invocations this is no longer the LHS itself. */
1048 209145906 : bool is_lhs = wi_p->is_lhs;
1049 209145906 : wi_p->is_lhs = false;
1050 :
1051 209145906 : if (TREE_CODE (*tp) == SSA_NAME)
1052 : {
1053 67401710 : *tp = remap_ssa_name (*tp, id);
1054 67401710 : *walk_subtrees = 0;
1055 67401710 : if (is_lhs)
1056 16699648 : SSA_NAME_DEF_STMT (*tp) = wi_p->stmt;
1057 67401710 : return NULL;
1058 : }
1059 141744196 : 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 46813709 : tree new_decl;
1067 :
1068 : /* Remap the declaration. */
1069 46813709 : new_decl = remap_decl (*tp, id);
1070 46813709 : gcc_assert (new_decl);
1071 : /* Replace this variable with the copy. */
1072 46813709 : 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 46813709 : if (TREE_CODE (new_decl) == INTEGER_CST
1078 46813709 : && !useless_type_conversion_p (TREE_TYPE (*tp), TREE_TYPE (new_decl)))
1079 0 : new_decl = fold_convert (TREE_TYPE (*tp), new_decl);
1080 46813709 : *tp = new_decl;
1081 46813709 : *walk_subtrees = 0;
1082 : }
1083 94930487 : else if (TREE_CODE (*tp) == STATEMENT_LIST)
1084 0 : gcc_unreachable ();
1085 94930487 : else if (TREE_CODE (*tp) == SAVE_EXPR)
1086 0 : gcc_unreachable ();
1087 94930487 : else if (TREE_CODE (*tp) == LABEL_DECL
1088 94930487 : && (!DECL_CONTEXT (*tp)
1089 463 : || 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 94930487 : 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 16629521 : tree *n = id->decl_map->get (*tp);
1097 16629521 : if (n)
1098 83 : *tp = *n;
1099 16629521 : *walk_subtrees = 0;
1100 : }
1101 78300966 : else if (TYPE_P (*tp))
1102 : /* Types may need remapping as well. */
1103 0 : *tp = remap_type (*tp, id);
1104 78300966 : 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 13072004 : tree new_type = remap_type (TREE_TYPE (*tp), id);
1109 :
1110 13072004 : if (new_type == TREE_TYPE (*tp))
1111 13068822 : *walk_subtrees = 0;
1112 :
1113 3182 : else if (TREE_CODE (*tp) == INTEGER_CST)
1114 3182 : *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 65228962 : 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 14090827 : tree ptr = TREE_OPERAND (*tp, 0);
1132 14090827 : tree type = remap_type (TREE_TYPE (*tp), id);
1133 14090827 : tree old = *tp;
1134 14090827 : walk_tree (&ptr, remap_gimple_op_r, data, NULL);
1135 14090827 : *tp = fold_build2 (MEM_REF, type, ptr, TREE_OPERAND (*tp, 1));
1136 14090827 : TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old);
1137 14090827 : TREE_SIDE_EFFECTS (*tp) = TREE_SIDE_EFFECTS (old);
1138 14090827 : copy_warning (*tp, old);
1139 14090827 : if (MR_DEPENDENCE_CLIQUE (old) != 0)
1140 : {
1141 2709073 : MR_DEPENDENCE_CLIQUE (*tp)
1142 2709073 : = remap_dependence_clique (id, MR_DEPENDENCE_CLIQUE (old));
1143 2709073 : MR_DEPENDENCE_BASE (*tp) = MR_DEPENDENCE_BASE (old);
1144 : }
1145 14090827 : maybe_copy_this_notrap (id, *tp, old);
1146 14090827 : REF_REVERSE_STORAGE_ORDER (*tp) = REF_REVERSE_STORAGE_ORDER (old);
1147 14090827 : *walk_subtrees = 0;
1148 14090827 : return NULL;
1149 : }
1150 :
1151 : /* Here is the "usual case". Copy this tree node, and then
1152 : tweak some special cases. */
1153 51138135 : copy_tree_r (tp, walk_subtrees, NULL);
1154 :
1155 51138135 : if (TREE_CODE (*tp) != OMP_CLAUSE)
1156 51138135 : TREE_TYPE (*tp) = remap_type (TREE_TYPE (*tp), id);
1157 :
1158 51138135 : 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 51138135 : 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 15803045 : int invariant = is_gimple_min_invariant (*tp);
1171 15803045 : walk_tree (&TREE_OPERAND (*tp, 0), remap_gimple_op_r, data, NULL);
1172 15803045 : 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 15803045 : if (invariant && !is_gimple_min_invariant (*tp))
1177 4512 : id->regimplify = true;
1178 :
1179 15803045 : *walk_subtrees = 0;
1180 : }
1181 35335090 : 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 127653369 : if (EXPR_P (*tp))
1192 : {
1193 33827430 : tree new_block = id->remapping_type_depth == 0 ? id->block : NULL;
1194 33827430 : tree old_block = TREE_BLOCK (*tp);
1195 33827430 : if (old_block)
1196 : {
1197 19454126 : tree *n;
1198 19454126 : n = id->decl_map->get (TREE_BLOCK (*tp));
1199 19454126 : if (n)
1200 19447307 : new_block = *n;
1201 : }
1202 33827430 : 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 1434710902 : copy_tree_body_r (tree *tp, int *walk_subtrees, void *data)
1215 : {
1216 1434710902 : copy_body_data *id = (copy_body_data *) data;
1217 1434710902 : tree fn = id->src_fn;
1218 1434710902 : 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 1434710902 : 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 1434710902 : else if (TREE_CODE (*tp) == SSA_NAME)
1251 : {
1252 4038453 : *tp = remap_ssa_name (*tp, id);
1253 4038453 : *walk_subtrees = 0;
1254 4038453 : 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 1430672449 : else if (auto_var_in_fn_p (*tp, fn))
1262 : {
1263 176079929 : tree new_decl;
1264 :
1265 : /* Remap the declaration. */
1266 176079929 : new_decl = remap_decl (*tp, id);
1267 176079929 : gcc_assert (new_decl);
1268 : /* Replace this variable with the copy. */
1269 176079929 : STRIP_TYPE_NOPS (new_decl);
1270 176079929 : *tp = new_decl;
1271 176079929 : *walk_subtrees = 0;
1272 : }
1273 1254592520 : else if (TREE_CODE (*tp) == STATEMENT_LIST)
1274 38002638 : copy_statement_list (tp);
1275 1216589882 : else if (TREE_CODE (*tp) == SAVE_EXPR
1276 1215899902 : || TREE_CODE (*tp) == TARGET_EXPR)
1277 15572503 : remap_save_expr (tp, id->decl_map, walk_subtrees);
1278 1201017379 : else if (TREE_CODE (*tp) == LABEL_DECL
1279 1201017379 : && (! DECL_CONTEXT (*tp)
1280 7 : || 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 1201017379 : else if (TREE_CODE (*tp) == BIND_EXPR)
1284 20715246 : copy_bind_expr (tp, walk_subtrees, id);
1285 : /* Types may need remapping as well. */
1286 1180302133 : else if (TYPE_P (*tp))
1287 221827 : *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 1180080306 : else if (CONSTANT_CLASS_P (*tp))
1292 : {
1293 361840248 : tree new_type = remap_type (TREE_TYPE (*tp), id);
1294 :
1295 361840248 : if (new_type == TREE_TYPE (*tp))
1296 361839125 : *walk_subtrees = 0;
1297 :
1298 1123 : else if (TREE_CODE (*tp) == INTEGER_CST)
1299 1123 : *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 818240058 : if (TREE_CODE (*tp) == MODIFY_EXPR
1315 10970819 : && TREE_OPERAND (*tp, 0) == TREE_OPERAND (*tp, 1)
1316 818240079 : && (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 818240058 : 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 44433024 : tree decl = TREE_OPERAND (*tp, 0);
1341 44433024 : tree *n = id->decl_map->get (decl);
1342 44433024 : 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 7306590 : tree type = TREE_TYPE (*tp);
1351 7306590 : tree ptr = id->do_not_unshare ? *n : unshare_expr (*n);
1352 7306590 : tree old = *tp;
1353 7306590 : *tp = id->do_not_fold ? NULL : gimple_fold_indirect_ref (ptr);
1354 7306590 : if (! *tp)
1355 : {
1356 7306454 : type = remap_type (type, id);
1357 7306454 : 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 7306454 : *tp = build1 (INDIRECT_REF, type, ptr);
1370 7306454 : TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old);
1371 7306454 : TREE_SIDE_EFFECTS (*tp) = TREE_SIDE_EFFECTS (old);
1372 7306454 : TREE_READONLY (*tp) = TREE_READONLY (old);
1373 7306454 : maybe_copy_this_notrap (id, *tp, old);
1374 : }
1375 : }
1376 7306590 : *walk_subtrees = 0;
1377 7306590 : return NULL;
1378 : }
1379 : }
1380 773807034 : 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 71282 : tree ptr = TREE_OPERAND (*tp, 0);
1386 71282 : tree type = remap_type (TREE_TYPE (*tp), id);
1387 71282 : tree old = *tp;
1388 71282 : walk_tree (&ptr, copy_tree_body_r, data, NULL);
1389 71282 : *tp = fold_build2 (MEM_REF, type, ptr, TREE_OPERAND (*tp, 1));
1390 71282 : TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old);
1391 71282 : TREE_SIDE_EFFECTS (*tp) = TREE_SIDE_EFFECTS (old);
1392 71282 : copy_warning (*tp, old);
1393 71282 : if (MR_DEPENDENCE_CLIQUE (old) != 0)
1394 : {
1395 5601 : MR_DEPENDENCE_CLIQUE (*tp)
1396 5601 : = remap_dependence_clique (id, MR_DEPENDENCE_CLIQUE (old));
1397 5601 : MR_DEPENDENCE_BASE (*tp) = MR_DEPENDENCE_BASE (old);
1398 : }
1399 71282 : maybe_copy_this_notrap (id, *tp, old);
1400 71282 : REF_REVERSE_STORAGE_ORDER (*tp) = REF_REVERSE_STORAGE_ORDER (old);
1401 71282 : *walk_subtrees = 0;
1402 71282 : return NULL;
1403 : }
1404 :
1405 : /* Here is the "usual case". Copy this tree node, and then
1406 : tweak some special cases. */
1407 810862186 : 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 810862186 : if (EXPR_P (*tp))
1413 : {
1414 707676202 : new_block = id->remapping_type_depth == 0 ? id->block : NULL;
1415 707676202 : if (TREE_BLOCK (*tp))
1416 : {
1417 13777 : tree *n;
1418 13777 : n = id->decl_map->get (TREE_BLOCK (*tp));
1419 13777 : if (n)
1420 13777 : new_block = *n;
1421 : }
1422 707676202 : TREE_SET_BLOCK (*tp, new_block);
1423 : }
1424 :
1425 810862186 : if (TREE_CODE (*tp) != OMP_CLAUSE)
1426 810862095 : 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 810862186 : 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 810862186 : else if (TREE_CODE (*tp) == ADDR_EXPR)
1440 : {
1441 80102227 : int invariant = is_gimple_min_invariant (*tp);
1442 80102227 : 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 80102227 : if (INDIRECT_REF_P (TREE_OPERAND (*tp, 0))
1447 80102227 : && !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 80102080 : 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 80102227 : if (invariant && !is_gimple_min_invariant (*tp))
1460 19 : id->regimplify = true;
1461 :
1462 80102227 : *walk_subtrees = 0;
1463 : }
1464 730759959 : else if (TREE_CODE (*tp) == OMP_CLAUSE
1465 730759959 : && (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 (OMP_ITERATOR_BLOCK (TREE_PURPOSE (t)))
1479 18 : remap_block (&OMP_ITERATOR_BLOCK (TREE_PURPOSE (t)), 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 91225 : remap_eh_region_nr (int old_nr, copy_body_data *id)
1495 : {
1496 91225 : eh_region old_r, new_r;
1497 :
1498 91225 : old_r = get_eh_region_from_number_fn (id->src_cfun, old_nr);
1499 91225 : new_r = static_cast<eh_region> (*id->eh_map->get (old_r));
1500 :
1501 91225 : return new_r->index;
1502 : }
1503 :
1504 : /* Similar, but operate on INTEGER_CSTs. */
1505 :
1506 : static tree
1507 8397 : remap_eh_region_tree_nr (tree old_t_nr, copy_body_data *id)
1508 : {
1509 8397 : int old_nr, new_nr;
1510 :
1511 8397 : old_nr = tree_to_shwi (old_t_nr);
1512 8397 : new_nr = remap_eh_region_nr (old_nr, id);
1513 :
1514 8397 : 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 97072202 : remap_gimple_stmt (gimple *stmt, copy_body_data *id)
1522 : {
1523 97072202 : gimple *copy = NULL;
1524 97072202 : struct walk_stmt_info wi;
1525 97072202 : bool skip_first = false;
1526 97072202 : gimple_seq stmts = NULL;
1527 :
1528 97072202 : if (is_gimple_debug (stmt)
1529 97072202 : && (gimple_debug_nonbind_marker_p (stmt)
1530 13925459 : ? !DECL_STRUCT_FUNCTION (id->dst_fn)->debug_nonbind_markers
1531 46835037 : : !opt_for_fn (id->dst_fn, flag_var_tracking_assignments)))
1532 : return NULL;
1533 :
1534 97045876 : if (!is_gimple_debug (stmt)
1535 36311706 : && id->param_body_adjs
1536 100706567 : && id->param_body_adjs->m_dead_stmts.contains (stmt))
1537 : {
1538 6978 : tree *dval = id->param_body_adjs->m_dead_stmt_debug_equiv.get (stmt);
1539 6978 : if (!dval)
1540 : return NULL;
1541 :
1542 3457 : gcc_assert (is_gimple_assign (stmt));
1543 3457 : tree lhs = gimple_assign_lhs (stmt);
1544 3457 : tree *dvar = id->param_body_adjs->m_dead_ssa_debug_equiv.get (lhs);
1545 3457 : gdebug *bind = gimple_build_debug_bind (*dvar, *dval, stmt);
1546 3457 : if (id->reset_location)
1547 0 : gimple_set_location (bind, input_location);
1548 3457 : id->debug_stmts.safe_push (bind);
1549 3457 : gimple_seq_add_stmt_without_update (&stmts, bind);
1550 3457 : 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 97038898 : if (gimple_code (stmt) == GIMPLE_RETURN && id->transform_return_to_modify)
1564 : {
1565 4609759 : 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 4609759 : if (retval
1574 4609759 : && (TREE_CODE (retval) != RESULT_DECL
1575 2390806 : && (!id->call_stmt
1576 2390806 : || gimple_call_lhs (id->call_stmt) != NULL_TREE)
1577 2268870 : && (TREE_CODE (retval) != SSA_NAME
1578 1790158 : || ! SSA_NAME_VAR (retval)
1579 421149 : || TREE_CODE (SSA_NAME_VAR (retval)) != RESULT_DECL)))
1580 : {
1581 4380634 : copy = gimple_build_assign (id->do_not_unshare
1582 2190317 : ? id->retvar : unshare_expr (id->retvar),
1583 : retval);
1584 : /* id->retvar is already substituted. Skip it on later remapping. */
1585 2190317 : skip_first = true;
1586 : }
1587 : else
1588 : return NULL;
1589 : }
1590 92429139 : 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 92429072 : if (gimple_assign_single_p (stmt)
1791 13842666 : && gimple_assign_lhs (stmt) == gimple_assign_rhs1 (stmt)
1792 92429072 : && 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 92429072 : if (id->blocks_to_copy && gimple_clobber_p (stmt))
1818 : {
1819 17312 : tree lhs = gimple_assign_lhs (stmt);
1820 17312 : if (TREE_CODE (lhs) == MEM_REF
1821 17312 : && TREE_CODE (TREE_OPERAND (lhs, 0)) == SSA_NAME)
1822 : {
1823 937 : gimple *def_stmt = SSA_NAME_DEF_STMT (TREE_OPERAND (lhs, 0));
1824 937 : if (gimple_bb (def_stmt)
1825 1256 : && !bitmap_bit_p (id->blocks_to_copy,
1826 319 : 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 92429069 : if (gimple_clobber_p (stmt)
1835 92429069 : && 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 92429069 : if (gimple_debug_bind_p (stmt))
1844 : {
1845 46258236 : tree var = gimple_debug_bind_get_var (stmt);
1846 46258236 : tree value = gimple_debug_bind_get_value (stmt);
1847 46258236 : if (id->param_body_adjs
1848 46258236 : && id->param_body_adjs->m_dead_stmts.contains (stmt))
1849 : {
1850 16586 : value = unshare_expr_without_location (value);
1851 16586 : id->param_body_adjs->remap_with_debug_expressions (&value);
1852 : }
1853 :
1854 46258236 : gdebug *copy = gimple_build_debug_bind (var, value, stmt);
1855 46258236 : if (id->reset_location)
1856 4 : gimple_set_location (copy, input_location);
1857 46258236 : id->debug_stmts.safe_push (copy);
1858 46258236 : gimple_seq_add_stmt_without_update (&stmts, copy);
1859 46258236 : return stmts;
1860 : }
1861 46170833 : if (gimple_debug_source_bind_p (stmt))
1862 : {
1863 576801 : gdebug *copy = gimple_build_debug_source_bind
1864 576801 : (gimple_debug_source_bind_get_var (stmt),
1865 : gimple_debug_source_bind_get_value (stmt),
1866 576801 : stmt);
1867 576801 : if (id->reset_location)
1868 0 : gimple_set_location (copy, input_location);
1869 576801 : id->debug_stmts.safe_push (copy);
1870 576801 : gimple_seq_add_stmt_without_update (&stmts, copy);
1871 576801 : return stmts;
1872 : }
1873 45594032 : if (gimple_debug_nonbind_marker_p (stmt))
1874 : {
1875 : /* If the inlined function has too many debug markers,
1876 : don't copy them. */
1877 13899133 : if (id->src_cfun->debug_marker_count
1878 13899133 : > param_max_debug_marker_count
1879 13899133 : || id->reset_location)
1880 0 : return stmts;
1881 :
1882 13899133 : gdebug *copy = as_a <gdebug *> (gimple_copy (stmt));
1883 13899133 : id->debug_stmts.safe_push (copy);
1884 13899133 : gimple_seq_add_stmt_without_update (&stmts, copy);
1885 13899133 : return stmts;
1886 : }
1887 :
1888 : /* Create a new deep copy of the statement. */
1889 31694899 : copy = gimple_copy (stmt);
1890 :
1891 : /* Clear flags that need revisiting. */
1892 31694899 : if (gcall *call_stmt = dyn_cast <gcall *> (copy))
1893 : {
1894 5183853 : if (gimple_call_tail_p (call_stmt))
1895 145 : gimple_call_set_tail (call_stmt, false);
1896 5183853 : if (gimple_call_from_thunk_p (call_stmt))
1897 183 : 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 5183853 : if (gimple_call_must_tail_p (call_stmt)
1904 49 : && id->call_stmt
1905 5183894 : && !gimple_call_must_tail_p (id->call_stmt))
1906 14 : gimple_call_set_must_tail (call_stmt, false);
1907 5183853 : if (gimple_call_internal_p (call_stmt))
1908 58640 : switch (gimple_call_internal_fn (call_stmt))
1909 : {
1910 166 : case IFN_GOMP_SIMD_LANE:
1911 166 : case IFN_GOMP_SIMD_VF:
1912 166 : case IFN_GOMP_SIMD_LAST_LANE:
1913 166 : case IFN_GOMP_SIMD_ORDERED_START:
1914 166 : case IFN_GOMP_SIMD_ORDERED_END:
1915 166 : DECL_STRUCT_FUNCTION (id->dst_fn)->has_simduid_loops = true;
1916 166 : break;
1917 : default:
1918 : break;
1919 : }
1920 : }
1921 :
1922 : /* Remap the region numbers for __builtin_eh_{pointer,filter},
1923 : RESX and EH_DISPATCH. */
1924 31694899 : if (id->eh_map)
1925 31694899 : switch (gimple_code (copy))
1926 : {
1927 5183853 : case GIMPLE_CALL:
1928 5183853 : {
1929 5183853 : tree r, fndecl = gimple_call_fndecl (copy);
1930 5183853 : if (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
1931 1454276 : 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 8397 : case BUILT_IN_EH_POINTER:
1940 8397 : case BUILT_IN_EH_FILTER:
1941 8397 : r = gimple_call_arg (copy, 0);
1942 8397 : r = remap_eh_region_tree_nr (r, id);
1943 8397 : gimple_call_set_arg (copy, 0, r);
1944 8397 : 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 5183853 : if (!id->src_cfun->gimple_df
1953 5183853 : || !id->src_cfun->gimple_df->ipa_pta)
1954 5177326 : gimple_call_reset_alias_info (as_a <gcall *> (copy));
1955 : }
1956 : break;
1957 :
1958 73284 : case GIMPLE_RESX:
1959 73284 : {
1960 73284 : gresx *resx_stmt = as_a <gresx *> (copy);
1961 73284 : int r = gimple_resx_region (resx_stmt);
1962 73284 : r = remap_eh_region_nr (r, id);
1963 73284 : gimple_resx_set_region (resx_stmt, r);
1964 : }
1965 73284 : break;
1966 :
1967 9544 : case GIMPLE_EH_DISPATCH:
1968 9544 : {
1969 9544 : geh_dispatch *eh_dispatch = as_a <geh_dispatch *> (copy);
1970 9544 : int r = gimple_eh_dispatch_region (eh_dispatch);
1971 9544 : r = remap_eh_region_nr (r, id);
1972 9544 : gimple_eh_dispatch_set_region (eh_dispatch, r);
1973 : }
1974 9544 : break;
1975 :
1976 : default:
1977 : break;
1978 : }
1979 : }
1980 :
1981 : /* If STMT has a block defined, map it to the newly constructed block. */
1982 33885283 : if (tree block = gimple_block (copy))
1983 : {
1984 30652627 : tree *n;
1985 30652627 : n = id->decl_map->get (block);
1986 30652627 : gcc_assert (n);
1987 30652627 : gimple_set_block (copy, *n);
1988 : }
1989 33885283 : if (id->param_body_adjs)
1990 : {
1991 3653713 : gimple_seq extra_stmts = NULL;
1992 3653713 : id->param_body_adjs->modify_gimple_stmt (©, &extra_stmts, stmt);
1993 3653713 : if (!gimple_seq_empty_p (extra_stmts))
1994 : {
1995 58 : memset (&wi, 0, sizeof (wi));
1996 58 : wi.info = id;
1997 58 : for (gimple_stmt_iterator egsi = gsi_start (extra_stmts);
1998 172 : !gsi_end_p (egsi);
1999 114 : gsi_next (&egsi))
2000 114 : walk_gimple_op (gsi_stmt (egsi), remap_gimple_op_r, &wi);
2001 58 : gimple_seq_add_seq_without_update (&stmts, extra_stmts);
2002 : }
2003 : }
2004 :
2005 33885283 : if (id->reset_location)
2006 838 : gimple_set_location (copy, input_location);
2007 :
2008 : /* Debug statements ought to be rebuilt and not copied. */
2009 33885283 : gcc_checking_assert (!is_gimple_debug (copy));
2010 :
2011 : /* Remap all the operands in COPY. */
2012 33885283 : memset (&wi, 0, sizeof (wi));
2013 33885283 : wi.info = id;
2014 33885283 : if (skip_first)
2015 2190317 : walk_tree (gimple_op_ptr (copy, 1), remap_gimple_op_r, &wi, NULL);
2016 : else
2017 31694966 : 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 33885283 : if (gimple_has_mem_ops (copy))
2022 : {
2023 29057240 : gimple_set_vdef (copy, NULL_TREE);
2024 29057240 : gimple_set_vuse (copy, NULL_TREE);
2025 : }
2026 :
2027 33885283 : 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 1706963 : if (gcond *cond = dyn_cast <gcond *> (copy))
2033 199405 : 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 33885283 : gimple_seq_add_stmt_without_update (&stmts, copy);
2048 33885283 : 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 14835223 : copy_bb (copy_body_data *id, basic_block bb,
2057 : profile_count num, profile_count den)
2058 : {
2059 14835223 : gimple_stmt_iterator gsi, copy_gsi, seq_gsi;
2060 14835223 : basic_block copy_basic_block;
2061 14835223 : tree decl;
2062 14835223 : basic_block prev;
2063 :
2064 14835223 : profile_count::adjust_for_ipa_scaling (&num, &den);
2065 :
2066 : /* Search for previous copied basic block. */
2067 14835223 : prev = bb->prev_bb;
2068 14996000 : while (!prev->aux)
2069 160777 : prev = prev->prev_bb;
2070 :
2071 : /* create_basic_block() will append every new block to
2072 : basic_block_info automatically. */
2073 14835223 : copy_basic_block = create_basic_block (NULL, (basic_block) prev->aux);
2074 14835223 : copy_basic_block->count = bb->count.apply_scale (num, den);
2075 :
2076 14835223 : copy_gsi = gsi_start_bb (copy_basic_block);
2077 :
2078 14835223 : unsigned min_cond_uid = 0;
2079 14835223 : 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 126742648 : for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2090 : {
2091 97072202 : gimple_seq stmts;
2092 97072202 : gimple *stmt = gsi_stmt (gsi);
2093 97072202 : gimple *orig_stmt = stmt;
2094 97072202 : gimple_stmt_iterator stmts_gsi;
2095 97072202 : bool stmt_added = false;
2096 :
2097 97072202 : id->regimplify = false;
2098 97072202 : stmts = remap_gimple_stmt (stmt, id);
2099 :
2100 97072202 : if (gimple_seq_empty_p (stmts))
2101 2449474 : continue;
2102 :
2103 94622910 : seq_gsi = copy_gsi;
2104 :
2105 94622910 : for (stmts_gsi = gsi_start (stmts);
2106 189245935 : !gsi_end_p (stmts_gsi); )
2107 : {
2108 94623025 : stmt = gsi_stmt (stmts_gsi);
2109 :
2110 : /* Advance iterator now before stmt is moved to seq_gsi. */
2111 94623025 : gsi_next (&stmts_gsi);
2112 :
2113 94623025 : 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 94622843 : 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 94622843 : gimple_duplicate_stmt_histograms (cfun, stmt, id->src_cfun,
2129 : orig_stmt);
2130 :
2131 94622843 : gsi_insert_after (&seq_gsi, stmt, GSI_NEW_STMT);
2132 :
2133 94622843 : if (id->regimplify)
2134 4438 : gimple_regimplify_operands (stmt, &seq_gsi);
2135 :
2136 : stmt_added = true;
2137 : }
2138 :
2139 94622910 : 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 94622728 : if (gsi_end_p (copy_gsi))
2145 26207788 : copy_gsi = gsi_start_bb (copy_basic_block);
2146 : else
2147 81518834 : 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 94622847 : do
2153 : {
2154 94622847 : tree fn;
2155 94622847 : gcall *call_stmt;
2156 :
2157 94622847 : stmt = gsi_stmt (copy_gsi);
2158 94622847 : call_stmt = dyn_cast <gcall *> (stmt);
2159 5183853 : if (call_stmt
2160 5183853 : && 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 94622540 : else if (call_stmt
2217 5183546 : && id->call_stmt
2218 4235406 : && (decl = gimple_call_fndecl (stmt))
2219 98724538 : && 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 94622393 : else if (call_stmt
2254 5183399 : && id->call_stmt
2255 98857652 : && gimple_call_internal_p (stmt))
2256 44857 : switch (gimple_call_internal_fn (stmt))
2257 : {
2258 154 : case IFN_TSAN_FUNC_EXIT:
2259 : /* Drop .TSAN_FUNC_EXIT () internal calls during inlining. */
2260 154 : gsi_remove (©_gsi, false);
2261 154 : continue;
2262 1690 : case IFN_ASAN_MARK:
2263 : /* Drop .ASAN_MARK internal calls during inlining into
2264 : no_sanitize functions. */
2265 1690 : if (!sanitize_flags_p (SANITIZE_ADDRESS, id->dst_fn)
2266 1690 : && !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 94622678 : if (id->statements_to_fold)
2288 94622678 : 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 94622678 : if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
2293 : {
2294 5183560 : struct cgraph_edge *edge;
2295 :
2296 5183560 : switch (id->transform_call_graph_edges)
2297 : {
2298 4235420 : case CB_CGE_DUPLICATE:
2299 4235420 : edge = id->src_node->get_edge (orig_stmt);
2300 4235420 : if (edge)
2301 : {
2302 4190731 : 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 4190731 : if (edge->speculative)
2309 : {
2310 22094 : int n = 0;
2311 22094 : profile_count direct_cnt
2312 22094 : = profile_count::zero ();
2313 :
2314 : /* First figure out the distribution of counts
2315 : so we can re-scale BB profile accordingly. */
2316 50517 : for (cgraph_edge *e = old_edge; e;
2317 28423 : e = e->next_speculative_call_target ())
2318 28423 : direct_cnt = direct_cnt + e->count;
2319 :
2320 22094 : cgraph_edge *indirect
2321 22094 : = old_edge->speculative_call_indirect_edge ();
2322 22094 : profile_count indir_cnt = indirect->count;
2323 :
2324 : /* Next iterate all direct edges, clone it and its
2325 : corresponding reference and update profile. */
2326 22094 : for (cgraph_edge *e = old_edge;
2327 50517 : e;
2328 28423 : e = e->next_speculative_call_target ())
2329 : {
2330 28423 : profile_count cnt = e->count;
2331 :
2332 28423 : id->dst_node->clone_reference
2333 28423 : (e->speculative_call_target_ref (), stmt);
2334 28423 : edge = e->clone (id->dst_node, call_stmt,
2335 : gimple_uid (stmt), num, den,
2336 : true);
2337 28423 : profile_probability prob
2338 28423 : = cnt.probability_in (direct_cnt
2339 : + indir_cnt);
2340 28423 : edge->count
2341 : = copy_basic_block->count.apply_probability
2342 28423 : (prob);
2343 28423 : n++;
2344 : }
2345 22094 : 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 22094 : indirect = indirect->clone (id->dst_node, call_stmt,
2352 : gimple_uid (stmt),
2353 : num, den,
2354 : true);
2355 :
2356 22094 : profile_probability prob
2357 22094 : = indir_cnt.probability_in (direct_cnt
2358 : + indir_cnt);
2359 22094 : indirect->count
2360 22094 : = 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 4168637 : else if (edge->has_callback)
2365 : {
2366 2366 : edge
2367 2366 : = edge->clone (id->dst_node, call_stmt,
2368 : gimple_uid (stmt), num, den, true);
2369 2366 : cgraph_edge *e;
2370 2868 : for (e = old_edge->first_callback_edge (); e;
2371 502 : e = e->next_callback_edge ())
2372 502 : edge = e->clone (id->dst_node, call_stmt,
2373 : gimple_uid (stmt), num, den, true);
2374 : }
2375 : else
2376 : {
2377 4166271 : edge = edge->clone (id->dst_node, call_stmt,
2378 : gimple_uid (stmt),
2379 : num, den,
2380 : true);
2381 4166271 : edge->count = copy_basic_block->count;
2382 : }
2383 : }
2384 : break;
2385 :
2386 751647 : case CB_CGE_MOVE_CLONES:
2387 751647 : id->dst_node->set_call_stmt_including_clones (orig_stmt,
2388 : call_stmt);
2389 751647 : edge = id->dst_node->get_edge (stmt);
2390 751647 : break;
2391 :
2392 196493 : case CB_CGE_MOVE:
2393 196493 : edge = id->dst_node->get_edge (orig_stmt);
2394 196493 : if (edge)
2395 196125 : 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 4166271 : if ((!edge
2405 5027342 : || (edge->indirect_inlining_edge
2406 4004 : && id->transform_call_graph_edges == CB_CGE_MOVE_CLONES))
2407 156704 : && id->dst_node->definition
2408 1030239 : && (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 5183560 : notice_special_calls (as_a <gcall *> (stmt));
2438 : }
2439 :
2440 94622678 : maybe_duplicate_eh_stmt_fn (cfun, stmt, id->src_cfun, orig_stmt,
2441 : id->eh_map, id->eh_lp_nr);
2442 :
2443 94622678 : gsi_next (©_gsi);
2444 : }
2445 94622847 : while (!gsi_end_p (copy_gsi));
2446 :
2447 189245456 : copy_gsi = gsi_last_bb (copy_basic_block);
2448 : }
2449 :
2450 14835223 : 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 747030 : update_ssa_across_abnormal_edges (basic_block bb, basic_block ret_bb,
2473 : bool can_throw, bool nonlocal_goto)
2474 : {
2475 747030 : edge e;
2476 747030 : edge_iterator ei;
2477 :
2478 2058187 : FOR_EACH_EDGE (e, ei, bb->succs)
2479 1311157 : if (!e->dest->aux
2480 690172 : || ((basic_block)e->dest->aux)->index == ENTRY_BLOCK)
2481 : {
2482 620985 : gphi *phi;
2483 620985 : gphi_iterator si;
2484 :
2485 620985 : if (!nonlocal_goto)
2486 620549 : gcc_assert (e->flags & EDGE_EH);
2487 :
2488 620985 : if (!can_throw)
2489 227 : gcc_assert (!(e->flags & EDGE_EH));
2490 :
2491 1034503 : for (si = gsi_start_phis (e->dest); !gsi_end_p (si); gsi_next (&si))
2492 : {
2493 413518 : edge re;
2494 :
2495 413518 : 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 413518 : gcc_assert ((e->flags & EDGE_EH)
2501 : || SSA_NAME_OCCURS_IN_ABNORMAL_PHI (PHI_RESULT (phi)));
2502 :
2503 413518 : re = find_edge (ret_bb, e->dest);
2504 413518 : gcc_checking_assert (re);
2505 413518 : gcc_assert ((re->flags & (EDGE_EH | EDGE_ABNORMAL))
2506 : == (e->flags & (EDGE_EH | EDGE_ABNORMAL)));
2507 :
2508 413518 : 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 747030 : }
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 446585 : add_clobbers_to_eh_landing_pad (copy_body_data *id)
2519 : {
2520 446585 : tree var;
2521 446585 : basic_block bb = id->eh_landing_pad_dest;
2522 446585 : live_vars_map *vars = NULL;
2523 446585 : unsigned int cnt = 0;
2524 446585 : unsigned int i;
2525 1127017 : FOR_EACH_VEC_SAFE_ELT (id->src_cfun->local_decls, i, var)
2526 680432 : if (VAR_P (var)
2527 680432 : && !DECL_HARD_REGISTER (var)
2528 680432 : && !TREE_THIS_VOLATILE (var)
2529 680412 : && !DECL_HAS_VALUE_EXPR_P (var)
2530 671500 : && !is_gimple_reg (var)
2531 287912 : && auto_var_in_fn_p (var, id->src_fn)
2532 966308 : && !lookup_attribute ("omp simd array", DECL_ATTRIBUTES (var)))
2533 : {
2534 285876 : tree *t = id->decl_map->get (var);
2535 285876 : if (!t)
2536 0 : continue;
2537 285876 : tree new_var = *t;
2538 285876 : if (VAR_P (new_var)
2539 285876 : && !DECL_HARD_REGISTER (new_var)
2540 285876 : && !TREE_THIS_VOLATILE (new_var)
2541 285876 : && !DECL_HAS_VALUE_EXPR_P (new_var)
2542 285876 : && !is_gimple_reg (new_var)
2543 571752 : && auto_var_in_fn_p (new_var, id->dst_fn))
2544 : {
2545 285876 : if (vars == NULL)
2546 182423 : vars = new live_vars_map;
2547 285876 : vars->put (DECL_UID (var), cnt++);
2548 : }
2549 : }
2550 446585 : if (vars == NULL)
2551 264162 : return;
2552 :
2553 182423 : vec<bitmap_head> live = compute_live_vars (id->src_cfun, vars);
2554 683637 : FOR_EACH_VEC_SAFE_ELT (id->src_cfun->local_decls, i, var)
2555 501214 : if (VAR_P (var))
2556 : {
2557 501214 : edge e;
2558 501214 : edge_iterator ei;
2559 501214 : bool needed = false;
2560 501214 : unsigned int *v = vars->get (DECL_UID (var));
2561 501214 : if (v == NULL)
2562 215338 : continue;
2563 4938753 : FOR_EACH_EDGE (e, ei, bb->preds)
2564 4811891 : if ((e->flags & EDGE_EH) != 0
2565 4811851 : && e->src->index >= id->add_clobbers_to_eh_landing_pads)
2566 : {
2567 452547 : basic_block src_bb = (basic_block) e->src->aux;
2568 :
2569 452547 : if (bitmap_bit_p (&live[src_bb->index], *v))
2570 : {
2571 : needed = true;
2572 : break;
2573 : }
2574 : }
2575 285876 : if (needed)
2576 : {
2577 159014 : tree new_var = *id->decl_map->get (var);
2578 159014 : gimple_stmt_iterator gsi = gsi_after_labels (bb);
2579 159014 : tree clobber = build_clobber (TREE_TYPE (new_var));
2580 159014 : gimple *clobber_stmt = gimple_build_assign (new_var, clobber);
2581 159014 : gsi_insert_before (&gsi, clobber_stmt, GSI_NEW_STMT);
2582 : }
2583 : }
2584 182423 : destroy_live_vars (live);
2585 182423 : 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 24534207 : 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 24534207 : basic_block new_bb = (basic_block) bb->aux;
2599 24534207 : edge_iterator ei;
2600 24534207 : edge old_edge;
2601 24534207 : gimple_stmt_iterator si;
2602 24534207 : bool need_debug_cleanup = false;
2603 :
2604 : /* Use the indices from the original blocks to create edges for the
2605 : new ones. */
2606 47459842 : FOR_EACH_EDGE (old_edge, ei, bb->succs)
2607 22925635 : if (!(old_edge->flags & EDGE_EH))
2608 : {
2609 22799306 : edge new_edge;
2610 22799306 : int flags = old_edge->flags;
2611 22799306 : location_t locus = old_edge->goto_locus;
2612 :
2613 : /* Return edges do get a FALLTHRU flag when they get inlined. */
2614 22799306 : if (old_edge->dest->index == EXIT_BLOCK
2615 4848662 : && !(flags & (EDGE_TRUE_VALUE|EDGE_FALSE_VALUE|EDGE_FAKE))
2616 4848662 : && old_edge->dest->aux != EXIT_BLOCK_PTR_FOR_FN (cfun))
2617 4609759 : flags |= EDGE_FALLTHRU;
2618 :
2619 22799306 : new_edge
2620 22799306 : = make_edge (new_bb, (basic_block) old_edge->dest->aux, flags);
2621 22799306 : new_edge->probability = old_edge->probability;
2622 22799306 : if (!id->reset_location)
2623 22798657 : new_edge->goto_locus = remap_location (locus, id);
2624 : }
2625 :
2626 24534207 : 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 14835223 : if (single_succ_p (bb) && single_succ_edge (bb)->dest->index == EXIT_BLOCK)
2632 11540071 : FOR_EACH_EDGE (old_edge, ei, bb->preds)
2633 6691409 : if (old_edge->src->index != ENTRY_BLOCK
2634 3870651 : && !old_edge->src->aux)
2635 46611 : 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 14835223 : bool seen_nondebug = false;
2641 14835223 : for (si = gsi_last_bb (new_bb); !gsi_end_p (si);)
2642 : {
2643 94622685 : bool can_throw, nonlocal_goto;
2644 94622685 : gimple *copy_stmt = gsi_stmt (si);
2645 :
2646 : /* Do this before the possible split_block. */
2647 94622685 : 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 94622685 : can_throw = stmt_can_throw_internal (cfun, copy_stmt);
2661 94622685 : nonlocal_goto
2662 94622685 : = (stmt_can_make_abnormal_goto (copy_stmt)
2663 94622685 : && !computed_goto_p (copy_stmt));
2664 :
2665 94622191 : 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 747168 : 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 290599 : edge e = split_block (new_bb, copy_stmt);
2676 290599 : e->dest->aux = new_bb->aux;
2677 290599 : seen_nondebug = false;
2678 : }
2679 : }
2680 :
2681 94622685 : if (!is_gimple_debug (copy_stmt))
2682 33885058 : seen_nondebug = true;
2683 :
2684 94622685 : bool update_probs = false;
2685 :
2686 94622685 : if (gimple_code (copy_stmt) == GIMPLE_EH_DISPATCH)
2687 : {
2688 9544 : make_eh_dispatch_edges (as_a <geh_dispatch *> (copy_stmt));
2689 9544 : update_probs = true;
2690 : }
2691 94613141 : else if (can_throw)
2692 : {
2693 746803 : make_eh_edge (copy_stmt);
2694 746803 : update_probs = true;
2695 : }
2696 :
2697 : /* EH edges may not match old edges. Copy as much as possible. */
2698 756347 : if (update_probs)
2699 : {
2700 756347 : edge e;
2701 756347 : edge_iterator ei;
2702 756347 : basic_block copy_stmt_bb = gimple_bb (copy_stmt);
2703 :
2704 1492913 : FOR_EACH_EDGE (old_edge, ei, bb->succs)
2705 736566 : if ((old_edge->flags & EDGE_EH)
2706 135517 : && (e = find_edge (copy_stmt_bb,
2707 135517 : (basic_block) old_edge->dest->aux))
2708 862720 : && (e->flags & EDGE_EH))
2709 126154 : e->probability = old_edge->probability;
2710 :
2711 2077748 : FOR_EACH_EDGE (e, ei, copy_stmt_bb->succs)
2712 1321401 : if (e->flags & EDGE_EH)
2713 : {
2714 746803 : if (!e->probability.initialized_p ())
2715 621032 : e->probability = profile_probability::never ();
2716 746803 : if (e->dest->index < id->add_clobbers_to_eh_landing_pads)
2717 : {
2718 619609 : if (id->eh_landing_pad_dest == NULL)
2719 446585 : id->eh_landing_pad_dest = e->dest;
2720 : else
2721 173024 : 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 94622685 : if (abnormal_goto_dest == NULL)
2731 : nonlocal_goto = false;
2732 1095 : if (nonlocal_goto)
2733 : {
2734 336 : basic_block copy_stmt_bb = gimple_bb (copy_stmt);
2735 :
2736 336 : 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 336 : else if (is_gimple_call (copy_stmt)
2742 336 : && gimple_call_internal_p (copy_stmt)
2743 0 : && (gimple_call_internal_fn (copy_stmt)
2744 : == IFN_ABNORMAL_DISPATCHER)
2745 336 : && gimple_call_arg (copy_stmt, 0) == boolean_true_node)
2746 : nonlocal_goto = false;
2747 : else
2748 : {
2749 336 : make_single_succ_edge (copy_stmt_bb, abnormal_goto_dest,
2750 : EDGE_ABNORMAL);
2751 336 : gimple_call_set_ctrl_altering (copy_stmt, true);
2752 336 : if (is_a <gcall *> (copy_stmt)
2753 336 : && (gimple_call_flags (copy_stmt) & ECF_NORETURN))
2754 77 : fixup_noreturn_call (copy_stmt);
2755 : }
2756 : }
2757 :
2758 94622685 : if ((can_throw || nonlocal_goto)
2759 204080593 : && gimple_in_ssa_p (cfun))
2760 747030 : 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 24534207 : copy_phis_for_bb (basic_block bb, copy_body_data *id)
2773 : {
2774 24534207 : basic_block const new_bb = (basic_block) bb->aux;
2775 24534207 : edge_iterator ei;
2776 24534207 : gphi *phi;
2777 24534207 : gphi_iterator si;
2778 24534207 : edge new_edge;
2779 24534207 : bool inserted = false;
2780 :
2781 27585618 : for (si = gsi_start_phis (bb); !gsi_end_p (si); gsi_next (&si))
2782 : {
2783 3051411 : tree res, new_res;
2784 3051411 : gphi *new_phi;
2785 :
2786 3051411 : phi = si.phi ();
2787 3051411 : res = PHI_RESULT (phi);
2788 3051411 : new_res = res;
2789 3051411 : if (!virtual_operand_p (res)
2790 3051411 : && (!id->param_body_adjs
2791 1559511 : || !id->param_body_adjs->m_dead_stmts.contains (phi)))
2792 : {
2793 1693320 : walk_tree (&new_res, copy_tree_body_r, id, NULL);
2794 1693320 : 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 1693320 : new_phi = create_phi_node (new_res, new_bb);
2802 5560401 : FOR_EACH_EDGE (new_edge, ei, new_bb->preds)
2803 : {
2804 3867081 : edge old_edge = find_edge ((basic_block) new_edge->src->aux,
2805 3867081 : bb);
2806 3867081 : tree arg;
2807 3867081 : tree new_arg;
2808 3867081 : edge_iterator ei2;
2809 3867081 : 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 3867081 : if (!old_edge)
2815 2090 : FOR_EACH_EDGE (old_edge, ei2, bb->preds)
2816 2090 : if (!old_edge->src->aux)
2817 : break;
2818 :
2819 3867081 : arg = PHI_ARG_DEF_FROM_EDGE (phi, old_edge);
2820 3867081 : new_arg = arg;
2821 3867081 : walk_tree (&new_arg, copy_tree_body_r, id, NULL);
2822 3867081 : gcc_assert (new_arg);
2823 : /* With return slot optimization we can end up with
2824 : non-gimple (foo *)&this->m, fix that here. */
2825 3867081 : if (TREE_CODE (new_arg) != SSA_NAME
2826 1575688 : && TREE_CODE (new_arg) != FUNCTION_DECL
2827 5442769 : && !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 3867081 : locus = gimple_phi_arg_location_from_edge (phi, old_edge);
2836 3867081 : if (id->reset_location)
2837 0 : locus = input_location;
2838 : else
2839 3867081 : locus = remap_location (locus, id);
2840 3867081 : add_phi_arg (new_phi, new_arg, new_edge, locus);
2841 : }
2842 : }
2843 : }
2844 : }
2845 :
2846 : /* Commit the delayed edge insertions. */
2847 24534207 : if (inserted)
2848 36 : FOR_EACH_EDGE (new_edge, ei, new_bb->preds)
2849 24 : gsi_commit_one_edge_insert (new_edge, NULL);
2850 24534207 : }
2851 :
2852 :
2853 : /* Wrapper for remap_decl so it can be used as a callback. */
2854 :
2855 : static tree
2856 93915 : remap_decl_1 (tree decl, void *data)
2857 : {
2858 93915 : 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 254443 : initialize_cfun (tree new_fndecl, tree callee_fndecl, profile_count count)
2867 : {
2868 254443 : struct function *src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl);
2869 :
2870 : /* Register specific tree functions. */
2871 254443 : gimple_register_cfg_hooks ();
2872 :
2873 : /* Get clean struct function. */
2874 254443 : push_struct_function (new_fndecl, true);
2875 254443 : targetm.target_option.relayout_function (new_fndecl);
2876 :
2877 : /* We will rebuild these, so just sanity check that they are empty. */
2878 254443 : gcc_assert (VALUE_HISTOGRAMS (cfun) == NULL);
2879 254443 : gcc_assert (cfun->local_decls == NULL);
2880 254443 : gcc_assert (cfun->cfg == NULL);
2881 254443 : gcc_assert (cfun->decl == new_fndecl);
2882 :
2883 : /* Copy items we preserve during cloning. */
2884 254443 : cfun->static_chain_decl = src_cfun->static_chain_decl;
2885 254443 : cfun->nonlocal_goto_save_area = src_cfun->nonlocal_goto_save_area;
2886 254443 : cfun->function_end_locus = src_cfun->function_end_locus;
2887 254443 : cfun->curr_properties = src_cfun->curr_properties;
2888 254443 : cfun->va_list_gpr_size = src_cfun->va_list_gpr_size;
2889 254443 : cfun->va_list_fpr_size = src_cfun->va_list_fpr_size;
2890 254443 : cfun->has_nonlocal_label = src_cfun->has_nonlocal_label;
2891 254443 : cfun->calls_eh_return = src_cfun->calls_eh_return;
2892 254443 : cfun->stdarg = src_cfun->stdarg;
2893 254443 : cfun->after_inlining = src_cfun->after_inlining;
2894 254443 : cfun->can_throw_non_call_exceptions
2895 254443 : = src_cfun->can_throw_non_call_exceptions;
2896 254443 : cfun->can_delete_dead_exceptions = src_cfun->can_delete_dead_exceptions;
2897 254443 : cfun->returns_struct = src_cfun->returns_struct;
2898 254443 : cfun->returns_pcc_struct = src_cfun->returns_pcc_struct;
2899 :
2900 254443 : init_empty_tree_cfg ();
2901 :
2902 254443 : profile_status_for_fn (cfun) = profile_status_for_fn (src_cfun);
2903 254443 : cfun->cfg->full_profile = src_cfun->cfg->full_profile;
2904 :
2905 254443 : profile_count num = count;
2906 254443 : profile_count den = ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count;
2907 254443 : profile_count::adjust_for_ipa_scaling (&num, &den);
2908 :
2909 254443 : ENTRY_BLOCK_PTR_FOR_FN (cfun)->count =
2910 254443 : ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count.apply_scale (num, den);
2911 254443 : EXIT_BLOCK_PTR_FOR_FN (cfun)->count =
2912 254443 : EXIT_BLOCK_PTR_FOR_FN (src_cfun)->count.apply_scale (num, den);
2913 254443 : if (src_cfun->eh)
2914 254443 : init_eh_for_function ();
2915 :
2916 254443 : if (src_cfun->gimple_df)
2917 : {
2918 254443 : init_tree_ssa (cfun);
2919 254443 : cfun->gimple_df->in_ssa_p = src_cfun->gimple_df->in_ssa_p;
2920 254443 : if (cfun->gimple_df->in_ssa_p)
2921 254443 : init_ssa_operands (cfun);
2922 : }
2923 254443 : }
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 1592847 : maybe_move_debug_stmts_to_successors (copy_body_data *id, basic_block new_bb)
2932 : {
2933 1592847 : edge e;
2934 1592847 : edge_iterator ei;
2935 1592847 : gimple_stmt_iterator si = gsi_last_nondebug_bb (new_bb);
2936 :
2937 1592847 : if (gsi_end_p (si)
2938 1659755 : || gsi_one_before_end_p (si)
2939 1755129 : || !(stmt_can_throw_internal (cfun, gsi_stmt (si))
2940 66909 : || stmt_can_make_abnormal_goto (gsi_stmt (si))))
2941 1564382 : return;
2942 :
2943 85397 : FOR_EACH_EDGE (e, ei, new_bb->succs)
2944 : {
2945 56932 : gimple_stmt_iterator ssi = gsi_last_bb (new_bb);
2946 56932 : gimple_stmt_iterator dsi = gsi_after_labels (e->dest);
2947 177173 : while (is_gimple_debug (gsi_stmt (ssi)))
2948 : {
2949 120241 : gimple *stmt = gsi_stmt (ssi);
2950 120241 : gdebug *new_stmt;
2951 120241 : tree var;
2952 120241 : tree value;
2953 :
2954 : /* For the last edge move the debug stmts instead of copying
2955 : them. */
2956 120241 : if (ei_one_before_end_p (ei))
2957 : {
2958 60119 : si = ssi;
2959 60119 : gsi_prev (&ssi);
2960 60119 : if (!single_pred_p (e->dest) && gimple_debug_bind_p (stmt))
2961 : {
2962 58702 : gimple_debug_bind_reset_value (stmt);
2963 116874 : gimple_set_location (stmt, UNKNOWN_LOCATION);
2964 : }
2965 60119 : gsi_remove (&si, false);
2966 60119 : gsi_insert_before (&dsi, stmt, GSI_NEW_STMT);
2967 60119 : continue;
2968 : }
2969 :
2970 60122 : if (gimple_debug_bind_p (stmt))
2971 : {
2972 58705 : var = gimple_debug_bind_get_var (stmt);
2973 58705 : if (single_pred_p (e->dest))
2974 : {
2975 50042 : value = gimple_debug_bind_get_value (stmt);
2976 50042 : value = unshare_expr (value);
2977 50042 : new_stmt = gimple_build_debug_bind (var, value, stmt);
2978 : }
2979 : else
2980 8663 : new_stmt = gimple_build_debug_bind (var, NULL_TREE, NULL);
2981 : }
2982 1417 : 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 1417 : else if (gimple_debug_nonbind_marker_p (stmt))
2989 1417 : new_stmt = as_a <gdebug *> (gimple_copy (stmt));
2990 : else
2991 0 : gcc_unreachable ();
2992 60122 : gsi_insert_before (&dsi, new_stmt, GSI_NEW_STMT);
2993 60122 : id->debug_stmts.safe_push (new_stmt);
2994 60122 : 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 5509886 : copy_loops (copy_body_data *id,
3004 : class loop *dest_parent, class loop *src_parent)
3005 : {
3006 5509886 : class loop *src_loop = src_parent->inner;
3007 6121727 : while (src_loop)
3008 : {
3009 611841 : if (!id->blocks_to_copy
3010 611841 : || bitmap_bit_p (id->blocks_to_copy, src_loop->header->index))
3011 : {
3012 607756 : 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 607756 : dest_loop->header = (basic_block)src_loop->header->aux;
3017 607756 : dest_loop->header->loop_father = dest_loop;
3018 607756 : if (src_loop->latch != NULL)
3019 : {
3020 607740 : dest_loop->latch = (basic_block)src_loop->latch->aux;
3021 607740 : dest_loop->latch->loop_father = dest_loop;
3022 : }
3023 :
3024 : /* Copy loop meta-data. */
3025 607756 : copy_loop_info (src_loop, dest_loop);
3026 607756 : if (dest_loop->unroll)
3027 2385 : cfun->has_unroll = true;
3028 607756 : if (dest_loop->force_vectorize)
3029 154 : cfun->has_force_vectorize_loops = true;
3030 607756 : if (id->src_cfun->last_clique != 0)
3031 75692 : dest_loop->owned_clique
3032 75692 : = remap_dependence_clique (id,
3033 75692 : src_loop->owned_clique
3034 : ? src_loop->owned_clique : 1);
3035 :
3036 : /* Finally place it into the loop array and the loop tree. */
3037 607756 : place_new_loop (cfun, dest_loop);
3038 607756 : flow_loop_tree_node_add (dest_parent, dest_loop);
3039 :
3040 607756 : if (src_loop->simduid)
3041 : {
3042 68 : dest_loop->simduid = remap_decl (src_loop->simduid, id);
3043 68 : cfun->has_simduid_loops = true;
3044 : }
3045 :
3046 : /* Recurse. */
3047 607756 : copy_loops (id, dest_loop, src_loop);
3048 : }
3049 611841 : src_loop = src_loop->next;
3050 : }
3051 5509886 : }
3052 :
3053 : /* Call redirect_call_stmt_to_callee on all calls in BB. */
3054 :
3055 : void
3056 13299135 : redirect_all_calls (copy_body_data * id, basic_block bb)
3057 : {
3058 13299135 : gimple_stmt_iterator si;
3059 13299135 : gimple *last = last_nondebug_stmt (bb);
3060 108130331 : for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
3061 : {
3062 81532061 : gimple *stmt = gsi_stmt (si);
3063 81532061 : if (is_gimple_call (stmt))
3064 : {
3065 4292266 : struct cgraph_edge *edge = id->dst_node->get_edge (stmt);
3066 4292266 : if (edge)
3067 : {
3068 4247577 : if (!id->killed_new_ssa_names)
3069 2274818 : id->killed_new_ssa_names = new hash_set<tree> (16);
3070 4247577 : cgraph_edge::redirect_call_stmt_to_callee (
3071 : edge, id->killed_new_ssa_names);
3072 4247577 : if (edge->has_callback)
3073 : {
3074 : /* When redirecting a carrying edge, we need to redirect its
3075 : attached edges as well. */
3076 2366 : cgraph_edge *cbe;
3077 2868 : for (cbe = edge->first_callback_edge (); cbe;
3078 502 : cbe = cbe->next_callback_edge ())
3079 502 : cgraph_edge::redirect_call_stmt_to_callee (
3080 : cbe, id->killed_new_ssa_names);
3081 : }
3082 :
3083 4247577 : if (stmt == last && id->call_stmt && maybe_clean_eh_stmt (stmt))
3084 59803 : gimple_purge_dead_eh_edges (bb);
3085 : }
3086 : }
3087 : }
3088 13299135 : }
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 4902130 : 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 4902130 : tree callee_fndecl = id->src_fn;
3099 : /* Original cfun for the callee, doesn't change. */
3100 4902130 : struct function *src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl);
3101 4902130 : struct function *cfun_to_copy;
3102 4902130 : basic_block bb;
3103 4902130 : tree new_fndecl = NULL;
3104 4902130 : bool need_debug_cleanup = false;
3105 4902130 : int last;
3106 4902130 : profile_count den = ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count;
3107 4902130 : profile_count num = entry_block_map->count;
3108 :
3109 4902130 : cfun_to_copy = id->src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl);
3110 :
3111 : /* Register specific tree functions. */
3112 4902130 : 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 4902130 : if (new_entry)
3120 : {
3121 52638 : edge e;
3122 52638 : edge_iterator ei;
3123 52638 : ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = profile_count::zero ();
3124 :
3125 113270 : FOR_EACH_EDGE (e, ei, new_entry->preds)
3126 60632 : if (!e->src->aux)
3127 60632 : ENTRY_BLOCK_PTR_FOR_FN (cfun)->count += e->count ();
3128 : /* Do not scale - the profile of offlined region should
3129 : remain unchanged. */
3130 52638 : num = den = profile_count::one ();
3131 : }
3132 :
3133 4902130 : profile_count::adjust_for_ipa_scaling (&num, &den);
3134 :
3135 : /* Must have a CFG here at this point. */
3136 4902130 : gcc_assert (ENTRY_BLOCK_PTR_FOR_FN
3137 : (DECL_STRUCT_FUNCTION (callee_fndecl)));
3138 :
3139 :
3140 4902130 : ENTRY_BLOCK_PTR_FOR_FN (cfun_to_copy)->aux = entry_block_map;
3141 4902130 : EXIT_BLOCK_PTR_FOR_FN (cfun_to_copy)->aux = exit_block_map;
3142 4902130 : entry_block_map->aux = ENTRY_BLOCK_PTR_FOR_FN (cfun_to_copy);
3143 4902130 : exit_block_map->aux = EXIT_BLOCK_PTR_FOR_FN (cfun_to_copy);
3144 :
3145 : /* Duplicate any exception-handling regions. */
3146 4902130 : if (cfun->eh)
3147 4902130 : 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 19919836 : FOR_EACH_BB_FN (bb, cfun_to_copy)
3152 15017706 : if (!id->blocks_to_copy || bitmap_bit_p (id->blocks_to_copy, bb->index))
3153 : {
3154 14835223 : basic_block new_bb = copy_bb (id, bb, num, den);
3155 14835223 : bb->aux = new_bb;
3156 14835223 : new_bb->aux = bb;
3157 14835223 : new_bb->loop_father = entry_block_map->loop_father;
3158 : }
3159 :
3160 4902130 : last = last_basic_block_for_fn (cfun);
3161 :
3162 : /* Now that we've duplicated the blocks, duplicate their edges. */
3163 4902130 : basic_block abnormal_goto_dest = NULL;
3164 4902130 : if (id->call_stmt
3165 4902130 : && stmt_can_make_abnormal_goto (id->call_stmt))
3166 : {
3167 326 : gimple_stmt_iterator gsi = gsi_for_stmt (id->call_stmt);
3168 :
3169 326 : bb = gimple_bb (id->call_stmt);
3170 326 : gsi_next (&gsi);
3171 326 : if (gsi_end_p (gsi))
3172 326 : abnormal_goto_dest = get_abnormal_succ_dispatcher (bb);
3173 : }
3174 29724096 : FOR_ALL_BB_FN (bb, cfun_to_copy)
3175 24821966 : if (!id->blocks_to_copy
3176 24821966 : || (bb->index > 0 && bitmap_bit_p (id->blocks_to_copy, bb->index)))
3177 24534207 : need_debug_cleanup |= copy_edges_for_bb (bb, num, den, exit_block_map,
3178 : abnormal_goto_dest, id);
3179 :
3180 4902130 : if (id->eh_landing_pad_dest)
3181 : {
3182 446585 : add_clobbers_to_eh_landing_pad (id);
3183 446585 : id->eh_landing_pad_dest = NULL;
3184 : }
3185 :
3186 4902130 : if (new_entry)
3187 : {
3188 52638 : edge e = make_edge (entry_block_map, (basic_block)new_entry->aux,
3189 : EDGE_FALLTHRU);
3190 52638 : e->probability = profile_probability::always ();
3191 : }
3192 :
3193 : /* Duplicate the loop tree, if available and wanted. */
3194 4902130 : if (loops_for_fn (src_cfun) != NULL
3195 4902130 : && current_loops != NULL)
3196 : {
3197 4902130 : 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 4902130 : 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 4902130 : if (loops_for_fn (src_cfun)->state & LOOPS_NEED_FIXUP)
3206 0 : loops_state_set (LOOPS_NEED_FIXUP);
3207 :
3208 4902130 : if (gimple_in_ssa_p (cfun))
3209 29724096 : FOR_ALL_BB_FN (bb, cfun_to_copy)
3210 24821966 : if (!id->blocks_to_copy
3211 24821966 : || (bb->index > 0 && bitmap_bit_p (id->blocks_to_copy, bb->index)))
3212 24534207 : copy_phis_for_bb (bb, id);
3213 :
3214 29724096 : FOR_ALL_BB_FN (bb, cfun_to_copy)
3215 24821966 : if (bb->aux)
3216 : {
3217 24639483 : if (need_debug_cleanup
3218 2089843 : && bb->index != ENTRY_BLOCK
3219 1776783 : && bb->index != EXIT_BLOCK)
3220 1463723 : 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 24639483 : if (id->transform_call_graph_edges == CB_CGE_DUPLICATE
3224 22218641 : && bb->index != ENTRY_BLOCK
3225 17570954 : && bb->index != EXIT_BLOCK)
3226 12923267 : redirect_all_calls (id, (basic_block)bb->aux);
3227 24639483 : ((basic_block)bb->aux)->aux = NULL;
3228 24639483 : bb->aux = NULL;
3229 : }
3230 :
3231 : /* Zero out AUX fields of newly created block during EH edge
3232 : insertion. */
3233 5277998 : for (; last < last_basic_block_for_fn (cfun); last++)
3234 : {
3235 375868 : if (need_debug_cleanup)
3236 129124 : maybe_move_debug_stmts_to_successors (id,
3237 129124 : BASIC_BLOCK_FOR_FN (cfun, last));
3238 375868 : 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 375868 : if (id->transform_call_graph_edges == CB_CGE_DUPLICATE)
3242 375868 : redirect_all_calls (id, BASIC_BLOCK_FOR_FN (cfun, last));
3243 : }
3244 4902130 : entry_block_map->aux = NULL;
3245 4902130 : exit_block_map->aux = NULL;
3246 :
3247 4902130 : if (id->eh_map)
3248 : {
3249 4902130 : delete id->eh_map;
3250 4902130 : id->eh_map = NULL;
3251 : }
3252 4902130 : if (id->dependence_map)
3253 : {
3254 720200 : delete id->dependence_map;
3255 720200 : id->dependence_map = NULL;
3256 : }
3257 :
3258 4902130 : 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 60797749 : copy_debug_stmt (gdebug *stmt, copy_body_data *id)
3269 : {
3270 60797749 : tree t, *n;
3271 60797749 : struct walk_stmt_info wi;
3272 :
3273 60797749 : if (tree block = gimple_block (stmt))
3274 : {
3275 40251964 : n = id->decl_map->get (block);
3276 40251964 : gimple_set_block (stmt, n ? *n : id->block);
3277 : }
3278 :
3279 60797749 : if (gimple_debug_nonbind_marker_p (stmt))
3280 : {
3281 13900550 : if (id->call_stmt && !gimple_block (stmt))
3282 : {
3283 36535 : gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
3284 36535 : gsi_remove (&gsi, true);
3285 : }
3286 13900550 : return;
3287 : }
3288 :
3289 : /* Remap all the operands in COPY. */
3290 46897199 : memset (&wi, 0, sizeof (wi));
3291 46897199 : wi.info = id;
3292 :
3293 46897199 : processing_debug_stmt = 1;
3294 :
3295 46897199 : if (gimple_debug_source_bind_p (stmt))
3296 576801 : t = gimple_debug_source_bind_get_var (stmt);
3297 46320398 : else if (gimple_debug_bind_p (stmt))
3298 46320398 : t = gimple_debug_bind_get_var (stmt);
3299 : else
3300 0 : gcc_unreachable ();
3301 :
3302 46897199 : if (TREE_CODE (t) == PARM_DECL
3303 270132 : && id->debug_map
3304 46898331 : && (n = id->debug_map->get (t)))
3305 : {
3306 0 : gcc_assert (VAR_P (*n));
3307 0 : t = *n;
3308 : }
3309 46897199 : else if (VAR_P (t) && !is_global_var (t) && !id->decl_map->get (t))
3310 : /* T is a non-localized variable. */;
3311 : else
3312 41111713 : walk_tree (&t, remap_gimple_op_r, &wi, NULL);
3313 :
3314 46897199 : if (gimple_debug_bind_p (stmt))
3315 : {
3316 46320398 : gimple_debug_bind_set_var (stmt, t);
3317 :
3318 46320398 : if (gimple_debug_bind_has_value_p (stmt))
3319 25991848 : 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 46320398 : if (processing_debug_stmt < 0)
3324 668497 : gimple_debug_bind_reset_value (stmt);
3325 : }
3326 576801 : else if (gimple_debug_source_bind_p (stmt))
3327 : {
3328 576801 : 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 576801 : t = gimple_debug_source_bind_get_value (stmt);
3334 576801 : if (t != NULL_TREE
3335 576801 : && TREE_CODE (t) == PARM_DECL
3336 440310 : && id->call_stmt)
3337 : {
3338 435075 : vec<tree, va_gc> **debug_args = decl_debug_args_lookup (id->src_fn);
3339 435075 : unsigned int i;
3340 435075 : if (debug_args != NULL)
3341 : {
3342 541427 : for (i = 0; i < vec_safe_length (*debug_args); i += 2)
3343 541426 : if ((**debug_args)[i] == DECL_ORIGIN (t)
3344 541426 : && TREE_CODE ((**debug_args)[i + 1]) == DEBUG_EXPR_DECL)
3345 : {
3346 427422 : t = (**debug_args)[i + 1];
3347 427422 : stmt->subcode = GIMPLE_DEBUG_BIND;
3348 427422 : gimple_debug_bind_set_value (stmt, t);
3349 427422 : break;
3350 : }
3351 : }
3352 : }
3353 576801 : if (gimple_debug_source_bind_p (stmt))
3354 149379 : walk_tree (gimple_debug_source_bind_get_value_ptr (stmt),
3355 : remap_gimple_op_r, &wi, NULL);
3356 : }
3357 :
3358 46897199 : processing_debug_stmt = 0;
3359 :
3360 46897199 : 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 4902130 : copy_debug_stmts (copy_body_data *id)
3370 : {
3371 4902130 : if (!id->debug_stmts.exists ())
3372 : return;
3373 :
3374 63917153 : for (gdebug *stmt : id->debug_stmts)
3375 : /* But avoid re-processing debug stmts that have been elided. */
3376 60797749 : if (gimple_bb (stmt))
3377 60797749 : copy_debug_stmt (stmt, id);
3378 :
3379 3119404 : 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 31053102 : copy_tree_body (copy_body_data *id)
3387 : {
3388 31053102 : tree fndecl = id->src_fn;
3389 31053102 : tree body = DECL_SAVED_TREE (fndecl);
3390 :
3391 31053102 : walk_tree (&body, copy_tree_body_r, id, NULL);
3392 :
3393 31053102 : 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 4902130 : copy_body (copy_body_data *id,
3401 : basic_block entry_block_map, basic_block exit_block_map,
3402 : basic_block new_entry)
3403 : {
3404 4902130 : tree fndecl = id->src_fn;
3405 4902130 : tree body;
3406 :
3407 : /* If this body has a CFG, walk CFG and copy. */
3408 4902130 : gcc_assert (ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (fndecl)));
3409 4902130 : body = copy_cfg_body (id, entry_block_map, exit_block_map,
3410 : new_entry);
3411 4902130 : copy_debug_stmts (id);
3412 4902130 : if (id->killed_new_ssa_names)
3413 : {
3414 2274818 : ipa_release_ssas_in_hash (id->killed_new_ssa_names);
3415 4549636 : delete id->killed_new_ssa_names;
3416 2274818 : id->killed_new_ssa_names = NULL;
3417 : }
3418 :
3419 4902130 : 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 174114 : self_inlining_addr_expr (tree value, tree fn)
3427 : {
3428 174114 : tree var;
3429 :
3430 174114 : if (TREE_CODE (value) != ADDR_EXPR)
3431 : return false;
3432 :
3433 167137 : var = get_base_address (TREE_OPERAND (value, 0));
3434 :
3435 167137 : 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 7965625 : insert_init_debug_bind (copy_body_data *id,
3444 : basic_block bb, tree var, tree value,
3445 : gimple *base_stmt)
3446 : {
3447 7965625 : gimple *note;
3448 7965625 : gimple_stmt_iterator gsi;
3449 7965625 : tree tracked_var;
3450 :
3451 9529209 : if (!gimple_in_ssa_p (id->src_cfun))
3452 : return NULL;
3453 :
3454 7965625 : if (!opt_for_fn (id->dst_fn, flag_var_tracking_assignments))
3455 : return NULL;
3456 :
3457 7066315 : tracked_var = target_for_debug_bind (var);
3458 7066315 : if (!tracked_var)
3459 : return NULL;
3460 :
3461 6402041 : if (bb)
3462 : {
3463 6395190 : gsi = gsi_last_bb (bb);
3464 6395190 : if (!base_stmt && !gsi_end_p (gsi))
3465 6402041 : base_stmt = gsi_stmt (gsi);
3466 : }
3467 :
3468 6402041 : note = gimple_build_debug_bind (tracked_var,
3469 6402041 : value == error_mark_node
3470 6402041 : ? NULL_TREE : unshare_expr (value),
3471 : base_stmt);
3472 :
3473 6402041 : if (bb)
3474 : {
3475 6395190 : if (!gsi_end_p (gsi))
3476 5554940 : gsi_insert_after (&gsi, note, GSI_SAME_STMT);
3477 : else
3478 840250 : gsi_insert_before (&gsi, note, GSI_SAME_STMT);
3479 : }
3480 :
3481 : return note;
3482 : }
3483 :
3484 : static void
3485 467420 : 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 467420 : if (init_stmt)
3490 : {
3491 467420 : 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 467420 : if (!is_gimple_debug (init_stmt)
3498 460569 : && !is_gimple_reg (gimple_assign_lhs (init_stmt))
3499 356897 : && is_gimple_reg_type (TREE_TYPE (gimple_assign_lhs (init_stmt)))
3500 493900 : && 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 467420 : gsi_insert_after (&si, init_stmt, GSI_NEW_STMT);
3511 467420 : if (!is_gimple_debug (init_stmt))
3512 : {
3513 460569 : gimple_regimplify_operands (init_stmt, &si);
3514 :
3515 460569 : tree def = gimple_assign_lhs (init_stmt);
3516 460569 : insert_init_debug_bind (id, bb, def, def, init_stmt);
3517 : }
3518 : }
3519 467420 : }
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 7958563 : setup_one_parameter (copy_body_data *id, tree p, tree value, tree fn,
3551 : basic_block bb, tree *vars)
3552 : {
3553 7958563 : gimple *init_stmt = NULL;
3554 7958563 : tree var;
3555 7958563 : tree def = (gimple_in_ssa_p (cfun)
3556 7958563 : ? 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 7958563 : var = copy_decl_to_var (p, id);
3562 :
3563 : /* Declare this new variable. */
3564 7958563 : DECL_CHAIN (var) = *vars;
3565 7958563 : *vars = var;
3566 :
3567 : /* Make gimplifier happy about this variable. */
3568 7958563 : 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 7958563 : if (TREE_READONLY (p)
3575 4207944 : && !TREE_ADDRESSABLE (p)
3576 4206938 : && value
3577 4206932 : && !TREE_SIDE_EFFECTS (value)
3578 12165489 : && !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 390840 : 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 173668 : && ! DECL_NOT_GIMPLE_REG_P (p))
3588 217183 : || (DECL_P (value) && TREE_READONLY (value))
3589 217099 : || (auto_var_in_fn_p (value, id->dst_fn)
3590 381 : && !TREE_ADDRESSABLE (value)))
3591 174119 : && 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 564954 : && ! self_inlining_addr_expr (value, fn))
3598 : {
3599 174114 : insert_decl_map (id, p, value);
3600 174114 : if (!id->debug_map)
3601 168620 : id->debug_map = new hash_map<tree, tree>;
3602 174114 : id->debug_map->put (p, var);
3603 174114 : 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 7784449 : 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 7784449 : TREE_READONLY (var) = 0;
3617 :
3618 7784449 : tree rhs = value;
3619 7784449 : if (value
3620 7783540 : && value != error_mark_node
3621 15567989 : && !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 15568898 : if (gimple_in_ssa_p (cfun) && rhs && def && is_gimple_reg (p)
3635 6995482 : && (optimize
3636 25627 : || (TREE_READONLY (p)
3637 12118 : && is_gimple_min_invariant (rhs)))
3638 6973270 : && (TREE_CODE (rhs) == SSA_NAME
3639 2600861 : || is_gimple_min_invariant (rhs))
3640 6972988 : && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (def))
3641 : {
3642 6972988 : insert_decl_map (id, def, rhs);
3643 6972988 : 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 1597316 : 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 357968 : if (value && !is_gimple_reg_type (TREE_TYPE (value)))
3654 : return NULL;
3655 357954 : 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 453493 : if (value)
3661 : {
3662 453406 : 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 453406 : STRIP_USELESS_TYPE_CONVERSION (rhs);
3669 :
3670 : /* If we are in SSA form properly remap the default definition. */
3671 906812 : if (gimple_in_ssa_p (cfun) && is_gimple_reg (p))
3672 : {
3673 25063 : if (def)
3674 : {
3675 22494 : def = remap_ssa_name (def, id);
3676 22494 : init_stmt = gimple_build_assign (def, rhs);
3677 22494 : SSA_NAME_IS_DEFAULT_DEF (def) = 0;
3678 22494 : set_ssa_default_def (cfun, var, NULL);
3679 : }
3680 : }
3681 428343 : else if (!is_empty_type (TREE_TYPE (var)))
3682 356897 : init_stmt = gimple_build_assign (var, rhs);
3683 :
3684 453406 : if (bb && init_stmt)
3685 379092 : 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 4647687 : initialize_inlined_parameters (copy_body_data *id, gimple *stmt,
3695 : tree fn, basic_block bb)
3696 : {
3697 4647687 : tree parms;
3698 4647687 : size_t i;
3699 4647687 : tree p;
3700 4647687 : tree vars = NULL_TREE;
3701 4647687 : tree static_chain = gimple_call_chain (stmt);
3702 :
3703 : /* Figure out what the parameters are. */
3704 4647687 : parms = DECL_ARGUMENTS (fn);
3705 :
3706 : /* Loop through the parameter declarations, replacing each with an
3707 : equivalent VAR_DECL, appropriately initialized. */
3708 12579698 : for (p = parms, i = 0; p; p = DECL_CHAIN (p), i++)
3709 : {
3710 7932011 : tree val;
3711 7932011 : val = i < gimple_call_num_args (stmt) ? gimple_call_arg (stmt, i) : NULL;
3712 7932011 : 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 12579698 : for (p = parms, i = 0; p; p = DECL_CHAIN (p), i++)
3719 : {
3720 7932011 : tree *varp = id->decl_map->get (p);
3721 7932011 : if (varp && VAR_P (*varp))
3722 : {
3723 15519616 : tree def = (gimple_in_ssa_p (cfun) && is_gimple_reg (p)
3724 7331352 : ? ssa_default_def (id->src_cfun, p) : NULL);
3725 7759808 : tree var = *varp;
3726 7759808 : 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 7759808 : if (def)
3731 : {
3732 6972465 : tree *defp = id->decl_map->get (def);
3733 6972465 : if (defp
3734 6972379 : && TREE_CODE (*defp) == SSA_NAME
3735 13700330 : && SSA_NAME_VAR (*defp) == var)
3736 22494 : 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 787343 : else if (!optimize
3741 3394 : && is_gimple_reg (p)
3742 789912 : && i < gimple_call_num_args (stmt))
3743 : {
3744 2569 : tree val = gimple_call_arg (stmt, i);
3745 2569 : if (val != error_mark_node)
3746 : {
3747 2569 : if (!useless_type_conversion_p (TREE_TYPE (p),
3748 2569 : TREE_TYPE (val)))
3749 0 : val = force_value_to_type (TREE_TYPE (p), val);
3750 2569 : def = make_ssa_name (var);
3751 2569 : gimple *init_stmt = gimple_build_assign (def, val);
3752 2569 : insert_init_stmt (id, bb, init_stmt);
3753 : }
3754 : }
3755 : }
3756 : }
3757 :
3758 : /* Initialize the static chain. */
3759 4647687 : p = DECL_STRUCT_FUNCTION (fn)->static_chain_decl;
3760 4647687 : gcc_assert (fn != current_function_decl);
3761 4647687 : if (p)
3762 : {
3763 : /* Calling a function that requires a static chain directly
3764 : without setting up the static chain has undefined behavior
3765 : at run-time. */
3766 2257 : if (!static_chain)
3767 0 : static_chain = null_pointer_node;
3768 2257 : setup_one_parameter (id, p, static_chain, fn, bb, &vars);
3769 : }
3770 :
3771 : /* Reverse so the variables appear in the correct order in DWARF
3772 : debug info. */
3773 4647687 : vars = nreverse (vars);
3774 :
3775 4647687 : declare_inline_vars (id->block, vars);
3776 4647687 : }
3777 :
3778 :
3779 : /* Declare a return variable to replace the RESULT_DECL for the
3780 : function we are calling. An appropriate DECL_STMT is returned.
3781 : The USE_STMT is filled to contain a use of the declaration to
3782 : indicate the return value of the function.
3783 :
3784 : RETURN_SLOT, if non-null is place where to store the result. It
3785 : is set only for CALL_EXPR_RETURN_SLOT_OPT. MODIFY_DEST, if non-null,
3786 : was the LHS of the MODIFY_EXPR to which this call is the RHS.
3787 :
3788 : The return value is a (possibly null) value that holds the result
3789 : as seen by the caller. */
3790 :
3791 : static tree
3792 4647687 : declare_return_variable (copy_body_data *id, tree return_slot, tree modify_dest,
3793 : basic_block entry_bb)
3794 : {
3795 4647687 : tree callee = id->src_fn;
3796 4647687 : tree result = DECL_RESULT (callee);
3797 4647687 : tree callee_type = TREE_TYPE (result);
3798 4647687 : tree caller_type;
3799 4647687 : tree var, use;
3800 :
3801 : /* Handle type-mismatches in the function declaration return type
3802 : vs. the call expression. */
3803 4647687 : if (modify_dest)
3804 2173276 : caller_type = TREE_TYPE (modify_dest);
3805 2474411 : else if (return_slot)
3806 137266 : caller_type = TREE_TYPE (return_slot);
3807 : else /* No LHS on the call. */
3808 2337145 : caller_type = TREE_TYPE (TREE_TYPE (callee));
3809 :
3810 : /* We don't need to do anything for functions that don't return anything. */
3811 4647687 : if (VOID_TYPE_P (callee_type))
3812 : return NULL_TREE;
3813 :
3814 : /* If there was a return slot, then the return value is the
3815 : dereferenced address of that object. */
3816 2467415 : if (return_slot)
3817 : {
3818 : /* The front end shouldn't have used both return_slot and
3819 : a modify expression. */
3820 137266 : gcc_assert (!modify_dest);
3821 137266 : if (DECL_BY_REFERENCE (result))
3822 : {
3823 78609 : tree return_slot_addr = build_fold_addr_expr (return_slot);
3824 78609 : STRIP_USELESS_TYPE_CONVERSION (return_slot_addr);
3825 :
3826 : /* We are going to construct *&return_slot and we can't do that
3827 : for variables believed to be not addressable.
3828 :
3829 : FIXME: This check possibly can match, because values returned
3830 : via return slot optimization are not believed to have address
3831 : taken by alias analysis. */
3832 78609 : gcc_assert (TREE_CODE (return_slot) != SSA_NAME);
3833 78609 : var = return_slot_addr;
3834 78609 : mark_addressable (return_slot);
3835 : }
3836 : else
3837 : {
3838 58657 : var = return_slot;
3839 58657 : gcc_assert (TREE_CODE (var) != SSA_NAME);
3840 58657 : if (TREE_ADDRESSABLE (result))
3841 22714 : mark_addressable (var);
3842 : }
3843 137266 : if (DECL_NOT_GIMPLE_REG_P (result)
3844 137266 : && DECL_P (var))
3845 0 : DECL_NOT_GIMPLE_REG_P (var) = 1;
3846 :
3847 137266 : if (!useless_type_conversion_p (callee_type, caller_type))
3848 78610 : var = build1 (VIEW_CONVERT_EXPR, callee_type, var);
3849 :
3850 137266 : use = NULL;
3851 137266 : goto done;
3852 : }
3853 :
3854 : /* All types requiring non-trivial constructors should have been handled. */
3855 2330149 : gcc_assert (!TREE_ADDRESSABLE (callee_type));
3856 :
3857 : /* Attempt to avoid creating a new temporary variable. */
3858 2330149 : if (modify_dest
3859 2173255 : && TREE_CODE (modify_dest) != SSA_NAME)
3860 : {
3861 382148 : bool use_it = false;
3862 :
3863 : /* We can't use MODIFY_DEST if there's type promotion involved. */
3864 382148 : if (!useless_type_conversion_p (callee_type, caller_type))
3865 : use_it = false;
3866 :
3867 : /* ??? If we're assigning to a variable sized type, then we must
3868 : reuse the destination variable, because we've no good way to
3869 : create variable sized temporaries at this point. */
3870 382146 : else if (!poly_int_tree_p (TYPE_SIZE_UNIT (caller_type)))
3871 : use_it = true;
3872 :
3873 : /* If the callee cannot possibly modify MODIFY_DEST, then we can
3874 : reuse it as the result of the call directly. Don't do this if
3875 : it would promote MODIFY_DEST to addressable. */
3876 382146 : else if (TREE_ADDRESSABLE (result))
3877 : use_it = false;
3878 : else
3879 : {
3880 381256 : tree base_m = get_base_address (modify_dest);
3881 :
3882 : /* If the base isn't a decl, then it's a pointer, and we don't
3883 : know where that's going to go. */
3884 381256 : if (!DECL_P (base_m))
3885 : use_it = false;
3886 377407 : else if (is_global_var (base_m))
3887 : use_it = false;
3888 376957 : else if (DECL_NOT_GIMPLE_REG_P (result)
3889 376957 : && !DECL_NOT_GIMPLE_REG_P (base_m))
3890 : use_it = false;
3891 376957 : else if (!TREE_ADDRESSABLE (base_m))
3892 : use_it = true;
3893 : }
3894 :
3895 : if (use_it)
3896 : {
3897 277025 : var = modify_dest;
3898 277025 : use = NULL;
3899 277025 : goto done;
3900 : }
3901 : }
3902 :
3903 2053124 : gcc_assert (poly_int_tree_p (TYPE_SIZE_UNIT (callee_type)));
3904 :
3905 2053124 : var = copy_result_decl_to_var (result, id);
3906 2053124 : DECL_SEEN_IN_BIND_EXPR_P (var) = 1;
3907 :
3908 : /* Do not have the rest of GCC warn about this variable as it should
3909 : not be visible to the user. */
3910 2053124 : suppress_warning (var /* OPT_Wuninitialized? */);
3911 :
3912 2053124 : declare_inline_vars (id->block, var);
3913 :
3914 : /* Build the use expr. If the return type of the function was
3915 : promoted, convert it back to the expected type. */
3916 2053124 : use = var;
3917 2053124 : if (!useless_type_conversion_p (caller_type, TREE_TYPE (var)))
3918 : {
3919 : /* If we can match up types by promotion/demotion do so. */
3920 7 : if (fold_convertible_p (caller_type, var))
3921 0 : use = fold_convert (caller_type, var);
3922 : else
3923 : {
3924 : /* ??? For valid programs we should not end up here.
3925 : Still if we end up with truly mismatched types here, fall back
3926 : to using a MEM_REF to not leak invalid GIMPLE to the following
3927 : passes. */
3928 : /* Prevent var from being written into SSA form. */
3929 7 : if (is_gimple_reg_type (TREE_TYPE (var)))
3930 7 : DECL_NOT_GIMPLE_REG_P (var) = true;
3931 7 : use = fold_build2 (MEM_REF, caller_type,
3932 : build_fold_addr_expr (var),
3933 : build_int_cst (ptr_type_node, 0));
3934 : }
3935 : }
3936 :
3937 2053124 : STRIP_USELESS_TYPE_CONVERSION (use);
3938 :
3939 2053124 : if (DECL_BY_REFERENCE (result))
3940 : {
3941 0 : TREE_ADDRESSABLE (var) = 1;
3942 0 : var = build_fold_addr_expr (var);
3943 : }
3944 :
3945 2053124 : done:
3946 : /* Register the VAR_DECL as the equivalent for the RESULT_DECL; that
3947 : way, when the RESULT_DECL is encountered, it will be
3948 : automatically replaced by the VAR_DECL.
3949 :
3950 : When returning by reference, ensure that RESULT_DECL remaps to
3951 : gimple_val. */
3952 2467415 : if (DECL_BY_REFERENCE (result)
3953 2467415 : && !is_gimple_val (var))
3954 : {
3955 78609 : tree temp = create_tmp_var (TREE_TYPE (result), "retvalptr");
3956 78609 : insert_decl_map (id, result, temp);
3957 : /* When RESULT_DECL is in SSA form, we need to remap and initialize
3958 : it's default_def SSA_NAME. */
3959 78609 : if (gimple_in_ssa_p (id->src_cfun)
3960 78609 : && is_gimple_reg (result))
3961 78609 : if (tree default_def = ssa_default_def (id->src_cfun, result))
3962 : {
3963 78572 : temp = make_ssa_name (temp);
3964 78572 : insert_decl_map (id, default_def, temp);
3965 : }
3966 78609 : insert_init_stmt (id, entry_bb, gimple_build_assign (temp, var));
3967 : }
3968 : else
3969 2388806 : insert_decl_map (id, result, var);
3970 :
3971 : /* Remember this so we can ignore it in remap_decls. */
3972 2467415 : id->retvar = var;
3973 2467415 : return use;
3974 : }
3975 :
3976 : /* Determine if the function can be copied. If so return NULL. If
3977 : not return a string describing the reason for failure. */
3978 :
3979 : const char *
3980 18572220 : copy_forbidden (struct function *fun)
3981 : {
3982 18572220 : const char *reason = fun->cannot_be_copied_reason;
3983 :
3984 : /* Only examine the function once. */
3985 18572220 : if (fun->cannot_be_copied_set)
3986 : return reason;
3987 :
3988 : /* We cannot copy a function that receives a non-local goto
3989 : because we cannot remap the destination label used in the
3990 : function that is performing the non-local goto. */
3991 : /* ??? Actually, this should be possible, if we work at it.
3992 : No doubt there's just a handful of places that simply
3993 : assume it doesn't happen and don't substitute properly. */
3994 11115630 : if (fun->has_nonlocal_label)
3995 : {
3996 779 : reason = G_("function %q+F can never be copied "
3997 : "because it receives a non-local goto");
3998 779 : goto fail;
3999 : }
4000 :
4001 11114851 : if (fun->has_forced_label_in_static)
4002 : {
4003 225 : reason = G_("function %q+F can never be copied because it saves "
4004 : "address of local label in a static variable");
4005 225 : goto fail;
4006 : }
4007 :
4008 11114626 : fail:
4009 11115630 : fun->cannot_be_copied_reason = reason;
4010 11115630 : fun->cannot_be_copied_set = true;
4011 11115630 : return reason;
4012 : }
4013 :
4014 :
4015 : static const char *inline_forbidden_reason;
4016 :
4017 : /* A callback for walk_gimple_seq to handle statements. Returns non-null
4018 : iff a function cannot be inlined. Also sets the reason why. */
4019 :
4020 : static tree
4021 175288986 : inline_forbidden_p_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
4022 : struct walk_stmt_info *wip)
4023 : {
4024 175288986 : tree fn = (tree) wip->info;
4025 175288986 : tree t;
4026 175288986 : gimple *stmt = gsi_stmt (*gsi);
4027 :
4028 175288986 : switch (gimple_code (stmt))
4029 : {
4030 19208096 : case GIMPLE_CALL:
4031 : /* Refuse to inline alloca call unless user explicitly forced so as
4032 : this may change program's memory overhead drastically when the
4033 : function using alloca is called in loop. In GCC present in
4034 : SPEC2000 inlining into schedule_block cause it to require 2GB of
4035 : RAM instead of 256MB. Don't do so for alloca calls emitted for
4036 : VLA objects as those can't cause unbounded growth (they're always
4037 : wrapped inside stack_save/stack_restore regions. */
4038 19208096 : if (gimple_maybe_alloca_call_p (stmt)
4039 9445 : && !gimple_call_alloca_for_var_p (as_a <gcall *> (stmt))
4040 19212870 : && !lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)))
4041 : {
4042 4646 : inline_forbidden_reason
4043 4646 : = G_("function %q+F can never be inlined because it uses "
4044 : "alloca (override using the always_inline attribute)");
4045 4646 : *handled_ops_p = true;
4046 4646 : return fn;
4047 : }
4048 :
4049 19203450 : t = gimple_call_fndecl (stmt);
4050 19203450 : if (t == NULL_TREE)
4051 : break;
4052 :
4053 : /* We cannot inline functions that call setjmp. */
4054 18492418 : if (setjmp_call_p (t))
4055 : {
4056 992 : inline_forbidden_reason
4057 992 : = G_("function %q+F can never be inlined because it uses setjmp");
4058 992 : *handled_ops_p = true;
4059 992 : return t;
4060 : }
4061 :
4062 18491426 : if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL)
4063 3796965 : switch (DECL_FUNCTION_CODE (t))
4064 : {
4065 : /* We cannot inline functions that take a variable number of
4066 : arguments. */
4067 2807 : case BUILT_IN_VA_START:
4068 2807 : case BUILT_IN_NEXT_ARG:
4069 2807 : case BUILT_IN_VA_END:
4070 2807 : inline_forbidden_reason
4071 2807 : = G_("function %q+F can never be inlined because it "
4072 : "uses variable argument lists");
4073 2807 : *handled_ops_p = true;
4074 2807 : return t;
4075 :
4076 226 : case BUILT_IN_LONGJMP:
4077 : /* We can't inline functions that call __builtin_longjmp at
4078 : all. The non-local goto machinery really requires the
4079 : destination be in a different function. If we allow the
4080 : function calling __builtin_longjmp to be inlined into the
4081 : function calling __builtin_setjmp, Things will Go Awry. */
4082 226 : inline_forbidden_reason
4083 226 : = G_("function %q+F can never be inlined because "
4084 : "it uses setjmp-longjmp exception handling");
4085 226 : *handled_ops_p = true;
4086 226 : return t;
4087 :
4088 269 : case BUILT_IN_NONLOCAL_GOTO:
4089 : /* Similarly. */
4090 269 : inline_forbidden_reason
4091 269 : = G_("function %q+F can never be inlined because "
4092 : "it uses non-local goto");
4093 269 : *handled_ops_p = true;
4094 269 : return t;
4095 :
4096 384 : case BUILT_IN_RETURN:
4097 384 : case BUILT_IN_APPLY_ARGS:
4098 : /* If a __builtin_apply_args caller would be inlined,
4099 : it would be saving arguments of the function it has
4100 : been inlined into. Similarly __builtin_return would
4101 : return from the function the inline has been inlined into. */
4102 384 : inline_forbidden_reason
4103 384 : = G_("function %q+F can never be inlined because "
4104 : "it uses %<__builtin_return%> or %<__builtin_apply_args%>");
4105 384 : *handled_ops_p = true;
4106 384 : return t;
4107 :
4108 : default:
4109 : break;
4110 : }
4111 : break;
4112 :
4113 298 : case GIMPLE_GOTO:
4114 298 : t = gimple_goto_dest (stmt);
4115 :
4116 : /* We will not inline a function which uses computed goto. The
4117 : addresses of its local labels, which may be tucked into
4118 : global storage, are of course not constant across
4119 : instantiations, which causes unexpected behavior. */
4120 298 : if (TREE_CODE (t) != LABEL_DECL)
4121 : {
4122 298 : inline_forbidden_reason
4123 298 : = G_("function %q+F can never be inlined "
4124 : "because it contains a computed goto");
4125 298 : *handled_ops_p = true;
4126 298 : return t;
4127 : }
4128 : break;
4129 :
4130 : default:
4131 : break;
4132 : }
4133 :
4134 175279364 : *handled_ops_p = false;
4135 175279364 : return NULL_TREE;
4136 : }
4137 :
4138 : /* Return true if FNDECL is a function that cannot be inlined into
4139 : another one. */
4140 :
4141 : static bool
4142 5939573 : inline_forbidden_p (tree fndecl)
4143 : {
4144 5939573 : struct function *fun = DECL_STRUCT_FUNCTION (fndecl);
4145 5939573 : struct walk_stmt_info wi;
4146 5939573 : basic_block bb;
4147 5939573 : bool forbidden_p = false;
4148 :
4149 : /* First check for shared reasons not to copy the code. */
4150 5939573 : inline_forbidden_reason = copy_forbidden (fun);
4151 5939573 : if (inline_forbidden_reason != NULL)
4152 : return true;
4153 :
4154 : /* Next, walk the statements of the function looking for
4155 : constructs we can't handle, or are non-optimal for inlining. */
4156 5938875 : hash_set<tree> visited_nodes;
4157 5938875 : memset (&wi, 0, sizeof (wi));
4158 5938875 : wi.info = (void *) fndecl;
4159 5938875 : wi.pset = &visited_nodes;
4160 :
4161 : /* We cannot inline a function with a variable-sized parameter because we
4162 : cannot materialize a temporary of such a type in the caller if need be.
4163 : Note that the return case is not symmetrical because we can guarantee
4164 : that a temporary is not needed by means of CALL_EXPR_RETURN_SLOT_OPT. */
4165 18873269 : for (tree parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm))
4166 12934396 : if (!poly_int_tree_p (DECL_SIZE (parm)))
4167 : {
4168 2 : inline_forbidden_reason
4169 2 : = G_("function %q+F can never be inlined because "
4170 : "it has a VLA argument");
4171 2 : return true;
4172 : }
4173 :
4174 38300985 : FOR_EACH_BB_FN (bb, fun)
4175 : {
4176 32371734 : gimple *ret;
4177 32371734 : gimple_seq seq = bb_seq (bb);
4178 32371734 : ret = walk_gimple_seq (seq, inline_forbidden_p_stmt, NULL, &wi);
4179 32371734 : forbidden_p = (ret != NULL);
4180 32371734 : if (forbidden_p)
4181 : break;
4182 : }
4183 :
4184 : return forbidden_p;
4185 5938875 : }
4186 :
4187 : /* Return false if the function FNDECL cannot be inlined on account of its
4188 : attributes, true otherwise. */
4189 : static bool
4190 5939573 : function_attribute_inlinable_p (const_tree fndecl)
4191 : {
4192 11856386 : for (auto scoped_attributes : targetm.attribute_table)
4193 : {
4194 5939573 : const_tree a;
4195 :
4196 7843407 : for (a = DECL_ATTRIBUTES (fndecl); a; a = TREE_CHAIN (a))
4197 : {
4198 1926594 : const_tree name = get_attribute_name (a);
4199 :
4200 55303919 : for (const attribute_spec &attribute : scoped_attributes->attributes)
4201 53400085 : if (is_attribute_p (attribute.name, name))
4202 22760 : return targetm.function_attribute_inlinable_p (fndecl);
4203 : }
4204 : }
4205 :
4206 : return true;
4207 : }
4208 :
4209 : /* Returns nonzero if FN is a function that does not have any
4210 : fundamental inline blocking properties. */
4211 :
4212 : bool
4213 6584949 : tree_inlinable_function_p (tree fn)
4214 : {
4215 6584949 : bool inlinable = true;
4216 6584949 : bool do_warning;
4217 6584949 : tree always_inline;
4218 :
4219 : /* If we've already decided this function shouldn't be inlined,
4220 : there's no need to check again. */
4221 6584949 : if (DECL_UNINLINABLE (fn))
4222 : return false;
4223 :
4224 : /* We only warn for functions declared `inline' by the user. */
4225 5970491 : do_warning = (opt_for_fn (fn, warn_inline)
4226 643 : && DECL_DECLARED_INLINE_P (fn)
4227 514 : && !DECL_NO_INLINE_WARNING_P (fn)
4228 5970875 : && !DECL_IN_SYSTEM_HEADER (fn));
4229 :
4230 5970491 : always_inline = lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn));
4231 :
4232 5970491 : if (flag_no_inline
4233 109090 : && always_inline == NULL)
4234 : {
4235 30918 : if (do_warning)
4236 0 : warning (OPT_Winline, "function %q+F can never be inlined because it "
4237 : "is suppressed using %<-fno-inline%>", fn);
4238 : inlinable = false;
4239 : }
4240 :
4241 5939573 : else if (!function_attribute_inlinable_p (fn))
4242 : {
4243 0 : if (do_warning)
4244 0 : warning (OPT_Winline, "function %q+F can never be inlined because it "
4245 : "uses attributes conflicting with inlining", fn);
4246 : inlinable = false;
4247 : }
4248 :
4249 5939573 : else if (inline_forbidden_p (fn))
4250 : {
4251 : /* See if we should warn about uninlinable functions. Previously,
4252 : some of these warnings would be issued while trying to expand
4253 : the function inline, but that would cause multiple warnings
4254 : about functions that would for example call alloca. But since
4255 : this a property of the function, just one warning is enough.
4256 : As a bonus we can now give more details about the reason why a
4257 : function is not inlinable. */
4258 10322 : if (always_inline)
4259 2 : error (inline_forbidden_reason, fn);
4260 10320 : else if (do_warning)
4261 2 : warning (OPT_Winline, inline_forbidden_reason, fn);
4262 :
4263 : inlinable = false;
4264 : }
4265 :
4266 : /* Squirrel away the result so that we don't have to check again. */
4267 5970491 : DECL_UNINLINABLE (fn) = !inlinable;
4268 :
4269 5970491 : return inlinable;
4270 : }
4271 :
4272 : /* Estimate the cost of a memory move of type TYPE. Use machine dependent
4273 : word size and take possible memcpy call into account and return
4274 : cost based on whether optimizing for size or speed according to SPEED_P. */
4275 :
4276 : int
4277 344785214 : estimate_move_cost (tree type, bool ARG_UNUSED (speed_p))
4278 : {
4279 344785214 : HOST_WIDE_INT size;
4280 :
4281 344785214 : gcc_assert (!VOID_TYPE_P (type));
4282 :
4283 344785214 : if (VECTOR_TYPE_P (type))
4284 : {
4285 4156532 : scalar_mode inner = SCALAR_TYPE_MODE (TREE_TYPE (type));
4286 4156532 : machine_mode simd = targetm.vectorize.preferred_simd_mode (inner);
4287 4156532 : int orig_mode_size
4288 8313064 : = estimated_poly_value (GET_MODE_SIZE (TYPE_MODE (type)));
4289 8313064 : int simd_mode_size = estimated_poly_value (GET_MODE_SIZE (simd));
4290 4156532 : return ((orig_mode_size + simd_mode_size - 1)
4291 4156532 : / simd_mode_size);
4292 : }
4293 :
4294 340628682 : size = int_size_in_bytes (type);
4295 :
4296 340631144 : if (size < 0 || size > MOVE_MAX_PIECES * MOVE_RATIO (speed_p))
4297 : /* Cost of a memcpy call, 3 arguments and the call. */
4298 : return 4;
4299 : else
4300 339699025 : return ((size + MOVE_MAX_PIECES - 1) / MOVE_MAX_PIECES);
4301 : }
4302 :
4303 : /* Returns cost of operation CODE, according to WEIGHTS */
4304 :
4305 : static int
4306 465535935 : estimate_operator_cost (enum tree_code code, eni_weights *weights,
4307 : tree op1 ATTRIBUTE_UNUSED, tree op2)
4308 : {
4309 465535935 : switch (code)
4310 : {
4311 : /* These are "free" conversions, or their presumed cost
4312 : is folded into other operations. */
4313 : case RANGE_EXPR:
4314 : CASE_CONVERT:
4315 : case COMPLEX_EXPR:
4316 : case PAREN_EXPR:
4317 : case VIEW_CONVERT_EXPR:
4318 : return 0;
4319 :
4320 : /* Assign cost of 1 to usual operations.
4321 : ??? We may consider mapping RTL costs to this. */
4322 : case COND_EXPR:
4323 : case VEC_COND_EXPR:
4324 : case VEC_PERM_EXPR:
4325 :
4326 : case PLUS_EXPR:
4327 : case POINTER_PLUS_EXPR:
4328 : case POINTER_DIFF_EXPR:
4329 : case MINUS_EXPR:
4330 : case MULT_EXPR:
4331 : case MULT_HIGHPART_EXPR:
4332 :
4333 : case ADDR_SPACE_CONVERT_EXPR:
4334 : case FIXED_CONVERT_EXPR:
4335 : case FIX_TRUNC_EXPR:
4336 :
4337 : case NEGATE_EXPR:
4338 : case FLOAT_EXPR:
4339 : case MIN_EXPR:
4340 : case MAX_EXPR:
4341 : case ABS_EXPR:
4342 : case ABSU_EXPR:
4343 :
4344 : case LSHIFT_EXPR:
4345 : case RSHIFT_EXPR:
4346 : case LROTATE_EXPR:
4347 : case RROTATE_EXPR:
4348 :
4349 : case BIT_IOR_EXPR:
4350 : case BIT_XOR_EXPR:
4351 : case BIT_AND_EXPR:
4352 : case BIT_NOT_EXPR:
4353 :
4354 : case TRUTH_ANDIF_EXPR:
4355 : case TRUTH_ORIF_EXPR:
4356 : case TRUTH_AND_EXPR:
4357 : case TRUTH_OR_EXPR:
4358 : case TRUTH_XOR_EXPR:
4359 : case TRUTH_NOT_EXPR:
4360 :
4361 : case LT_EXPR:
4362 : case LE_EXPR:
4363 : case GT_EXPR:
4364 : case GE_EXPR:
4365 : case EQ_EXPR:
4366 : case NE_EXPR:
4367 : case ORDERED_EXPR:
4368 : case UNORDERED_EXPR:
4369 :
4370 : case UNLT_EXPR:
4371 : case UNLE_EXPR:
4372 : case UNGT_EXPR:
4373 : case UNGE_EXPR:
4374 : case UNEQ_EXPR:
4375 : case LTGT_EXPR:
4376 :
4377 : case CONJ_EXPR:
4378 :
4379 : case PREDECREMENT_EXPR:
4380 : case PREINCREMENT_EXPR:
4381 : case POSTDECREMENT_EXPR:
4382 : case POSTINCREMENT_EXPR:
4383 :
4384 : case REALIGN_LOAD_EXPR:
4385 :
4386 : case WIDEN_SUM_EXPR:
4387 : case WIDEN_MULT_EXPR:
4388 : case DOT_PROD_EXPR:
4389 : case SAD_EXPR:
4390 : case WIDEN_MULT_PLUS_EXPR:
4391 : case WIDEN_MULT_MINUS_EXPR:
4392 : case WIDEN_LSHIFT_EXPR:
4393 :
4394 : case VEC_WIDEN_MULT_HI_EXPR:
4395 : case VEC_WIDEN_MULT_LO_EXPR:
4396 : case VEC_WIDEN_MULT_EVEN_EXPR:
4397 : case VEC_WIDEN_MULT_ODD_EXPR:
4398 : case VEC_UNPACK_HI_EXPR:
4399 : case VEC_UNPACK_LO_EXPR:
4400 : case VEC_UNPACK_FLOAT_HI_EXPR:
4401 : case VEC_UNPACK_FLOAT_LO_EXPR:
4402 : case VEC_UNPACK_FIX_TRUNC_HI_EXPR:
4403 : case VEC_UNPACK_FIX_TRUNC_LO_EXPR:
4404 : case VEC_PACK_TRUNC_EXPR:
4405 : case VEC_PACK_SAT_EXPR:
4406 : case VEC_PACK_FIX_TRUNC_EXPR:
4407 : case VEC_PACK_FLOAT_EXPR:
4408 : case VEC_WIDEN_LSHIFT_HI_EXPR:
4409 : case VEC_WIDEN_LSHIFT_LO_EXPR:
4410 : case VEC_DUPLICATE_EXPR:
4411 : case VEC_SERIES_EXPR:
4412 :
4413 : return 1;
4414 :
4415 : /* Few special cases of expensive operations. This is useful
4416 : to avoid inlining on functions having too many of these. */
4417 3003447 : case TRUNC_DIV_EXPR:
4418 3003447 : case CEIL_DIV_EXPR:
4419 3003447 : case FLOOR_DIV_EXPR:
4420 3003447 : case ROUND_DIV_EXPR:
4421 3003447 : case EXACT_DIV_EXPR:
4422 3003447 : case TRUNC_MOD_EXPR:
4423 3003447 : case CEIL_MOD_EXPR:
4424 3003447 : case FLOOR_MOD_EXPR:
4425 3003447 : case ROUND_MOD_EXPR:
4426 3003447 : case RDIV_EXPR:
4427 3003447 : if (TREE_CODE (op2) != INTEGER_CST)
4428 1372784 : return weights->div_mod_cost;
4429 : return 1;
4430 :
4431 : /* Bit-field insertion needs several shift and mask operations. */
4432 : case BIT_INSERT_EXPR:
4433 : return 3;
4434 :
4435 192767364 : default:
4436 : /* We expect a copy assignment with no operator. */
4437 192767364 : gcc_assert (get_gimple_rhs_class (code) == GIMPLE_SINGLE_RHS);
4438 : return 0;
4439 : }
4440 : }
4441 :
4442 :
4443 : /* Estimate number of instructions that will be created by expanding
4444 : the statements in the statement sequence STMTS.
4445 : WEIGHTS contains weights attributed to various constructs. */
4446 :
4447 : int
4448 233641 : estimate_num_insns_seq (gimple_seq stmts, eni_weights *weights)
4449 : {
4450 233641 : int cost;
4451 233641 : gimple_stmt_iterator gsi;
4452 :
4453 233641 : cost = 0;
4454 618818 : for (gsi = gsi_start (stmts); !gsi_end_p (gsi); gsi_next (&gsi))
4455 385177 : cost += estimate_num_insns (gsi_stmt (gsi), weights);
4456 :
4457 233641 : return cost;
4458 : }
4459 :
4460 :
4461 : /* Estimate number of instructions that will be created by expanding STMT.
4462 : WEIGHTS contains weights attributed to various constructs. */
4463 :
4464 : int
4465 638336307 : estimate_num_insns (gimple *stmt, eni_weights *weights)
4466 : {
4467 638336307 : unsigned cost, i;
4468 638336307 : enum gimple_code code = gimple_code (stmt);
4469 638336307 : tree lhs;
4470 638336307 : tree rhs;
4471 :
4472 638336307 : switch (code)
4473 : {
4474 358508017 : case GIMPLE_ASSIGN:
4475 : /* Try to estimate the cost of assignments. We have three cases to
4476 : deal with:
4477 : 1) Simple assignments to registers;
4478 : 2) Stores to things that must live in memory. This includes
4479 : "normal" stores to scalars, but also assignments of large
4480 : structures, or constructors of big arrays;
4481 :
4482 : Let us look at the first two cases, assuming we have "a = b + C":
4483 : <GIMPLE_ASSIGN <var_decl "a">
4484 : <plus_expr <var_decl "b"> <constant C>>
4485 : If "a" is a GIMPLE register, the assignment to it is free on almost
4486 : any target, because "a" usually ends up in a real register. Hence
4487 : the only cost of this expression comes from the PLUS_EXPR, and we
4488 : can ignore the GIMPLE_ASSIGN.
4489 : If "a" is not a GIMPLE register, the assignment to "a" will most
4490 : likely be a real store, so the cost of the GIMPLE_ASSIGN is the cost
4491 : of moving something into "a", which we compute using the function
4492 : estimate_move_cost. */
4493 358508017 : if (gimple_clobber_p (stmt))
4494 : return 0; /* ={v} {CLOBBER} stmt expands to nothing. */
4495 :
4496 339496957 : lhs = gimple_assign_lhs (stmt);
4497 339496957 : rhs = gimple_assign_rhs1 (stmt);
4498 :
4499 339496957 : cost = 0;
4500 :
4501 : /* Account for the cost of moving to / from memory. */
4502 339496957 : if (gimple_store_p (stmt))
4503 78763389 : cost += estimate_move_cost (TREE_TYPE (lhs), weights->time_based);
4504 339496957 : if (gimple_assign_load_p (stmt))
4505 90977813 : cost += estimate_move_cost (TREE_TYPE (rhs), weights->time_based);
4506 :
4507 445596280 : cost += estimate_operator_cost (gimple_assign_rhs_code (stmt), weights,
4508 : gimple_assign_rhs1 (stmt),
4509 339496957 : get_gimple_rhs_class (gimple_assign_rhs_code (stmt))
4510 : == GIMPLE_BINARY_RHS
4511 106099323 : ? gimple_assign_rhs2 (stmt) : NULL);
4512 339496957 : break;
4513 :
4514 126038978 : case GIMPLE_COND:
4515 126038978 : cost = 1 + estimate_operator_cost (gimple_cond_code (stmt), weights,
4516 : gimple_op (stmt, 0),
4517 : gimple_op (stmt, 1));
4518 126038978 : break;
4519 :
4520 782648 : case GIMPLE_SWITCH:
4521 782648 : {
4522 782648 : gswitch *switch_stmt = as_a <gswitch *> (stmt);
4523 : /* Take into account cost of the switch + guess 2 conditional jumps for
4524 : each case label.
4525 :
4526 : TODO: once the switch expansion logic is sufficiently separated, we can
4527 : do better job on estimating cost of the switch. */
4528 782648 : if (weights->time_based)
4529 124274 : cost = floor_log2 (gimple_switch_num_labels (switch_stmt)) * 2;
4530 : else
4531 658374 : cost = gimple_switch_num_labels (switch_stmt) * 2;
4532 : }
4533 : break;
4534 :
4535 74412918 : case GIMPLE_CALL:
4536 74412918 : {
4537 74412918 : tree decl;
4538 :
4539 74412918 : if (gimple_call_internal_p (stmt))
4540 : return 0;
4541 71487742 : else if ((decl = gimple_call_fndecl (stmt))
4542 71487742 : && fndecl_built_in_p (decl))
4543 : {
4544 : /* Do not special case builtins where we see the body.
4545 : This just confuse inliner. */
4546 18386706 : struct cgraph_node *node;
4547 18386706 : if ((node = cgraph_node::get (decl))
4548 18386706 : && node->definition)
4549 : ;
4550 : /* For builtins that are likely expanded to nothing or
4551 : inlined do not account operand costs. */
4552 18356653 : else if (is_simple_builtin (decl))
4553 : return 0;
4554 15406916 : else if (is_inexpensive_builtin (decl))
4555 1991345 : return weights->target_builtin_call_cost;
4556 13415571 : else if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
4557 : {
4558 : /* We canonicalize x * x to pow (x, 2.0) with -ffast-math, so
4559 : specialize the cheap expansion we do here.
4560 : ??? This asks for a more general solution. */
4561 13186059 : switch (DECL_FUNCTION_CODE (decl))
4562 : {
4563 9091 : case BUILT_IN_POW:
4564 9091 : case BUILT_IN_POWF:
4565 9091 : case BUILT_IN_POWL:
4566 9091 : if (TREE_CODE (gimple_call_arg (stmt, 1)) == REAL_CST
4567 12954 : && (real_equal
4568 3863 : (&TREE_REAL_CST (gimple_call_arg (stmt, 1)),
4569 : &dconst2)))
4570 558 : return estimate_operator_cost
4571 558 : (MULT_EXPR, weights, gimple_call_arg (stmt, 0),
4572 558 : gimple_call_arg (stmt, 0));
4573 : break;
4574 :
4575 : default:
4576 : break;
4577 : }
4578 : }
4579 : }
4580 :
4581 66546102 : cost = decl ? weights->call_cost : weights->indirect_call_cost;
4582 66546102 : if (gimple_call_lhs (stmt))
4583 25915641 : cost += estimate_move_cost (TREE_TYPE (gimple_call_lhs (stmt)),
4584 25915641 : weights->time_based);
4585 200983827 : for (i = 0; i < gimple_call_num_args (stmt); i++)
4586 : {
4587 134437725 : tree arg = gimple_call_arg (stmt, i);
4588 134437725 : cost += estimate_move_cost (TREE_TYPE (arg),
4589 134437725 : weights->time_based);
4590 : }
4591 : break;
4592 : }
4593 :
4594 18315143 : case GIMPLE_RETURN:
4595 18315143 : return weights->return_cost;
4596 :
4597 : case GIMPLE_GOTO:
4598 : case GIMPLE_LABEL:
4599 : case GIMPLE_NOP:
4600 : case GIMPLE_PHI:
4601 : case GIMPLE_PREDICT:
4602 : case GIMPLE_DEBUG:
4603 : return 0;
4604 :
4605 768286 : case GIMPLE_ASM:
4606 768286 : {
4607 768286 : int count = asm_str_count (gimple_asm_string (as_a <gasm *> (stmt)));
4608 : /* 1000 means infinity. This avoids overflows later
4609 : with very long asm statements. */
4610 768286 : if (count > 1000)
4611 : count = 1000;
4612 : /* If this asm is asm inline, count anything as minimum size. */
4613 768286 : if (gimple_asm_inline_p (as_a <gasm *> (stmt)))
4614 662 : count = MIN (1, count);
4615 768286 : return MAX (1, count);
4616 : }
4617 :
4618 : case GIMPLE_RESX:
4619 : /* This is either going to be an external function call with one
4620 : argument, or two register copy statements plus a goto. */
4621 : return 2;
4622 :
4623 15470 : case GIMPLE_EH_DISPATCH:
4624 : /* ??? This is going to turn into a switch statement. Ideally
4625 : we'd have a look at the eh region and estimate the number of
4626 : edges involved. */
4627 15470 : return 10;
4628 :
4629 0 : case GIMPLE_BIND:
4630 0 : return estimate_num_insns_seq (
4631 0 : gimple_bind_body (as_a <gbind *> (stmt)),
4632 0 : weights);
4633 :
4634 0 : case GIMPLE_EH_FILTER:
4635 0 : return estimate_num_insns_seq (gimple_eh_filter_failure (stmt), weights);
4636 :
4637 8292 : case GIMPLE_CATCH:
4638 8292 : return estimate_num_insns_seq (gimple_catch_handler (
4639 8292 : as_a <gcatch *> (stmt)),
4640 8292 : weights);
4641 :
4642 8297 : case GIMPLE_TRY:
4643 8297 : return (estimate_num_insns_seq (gimple_try_eval (stmt), weights)
4644 8297 : + estimate_num_insns_seq (gimple_try_cleanup (stmt), weights));
4645 :
4646 : /* OMP directives are generally very expensive. */
4647 :
4648 : case GIMPLE_OMP_RETURN:
4649 : case GIMPLE_OMP_SECTIONS_SWITCH:
4650 : case GIMPLE_OMP_ATOMIC_STORE:
4651 : case GIMPLE_OMP_CONTINUE:
4652 : /* ...except these, which are cheap. */
4653 : return 0;
4654 :
4655 0 : case GIMPLE_OMP_ATOMIC_LOAD:
4656 0 : return weights->omp_cost;
4657 :
4658 0 : case GIMPLE_OMP_FOR:
4659 0 : return (weights->omp_cost
4660 0 : + estimate_num_insns_seq (gimple_omp_body (stmt), weights)
4661 0 : + estimate_num_insns_seq (gimple_omp_for_pre_body (stmt), weights));
4662 :
4663 0 : case GIMPLE_OMP_PARALLEL:
4664 0 : case GIMPLE_OMP_TASK:
4665 0 : case GIMPLE_OMP_CRITICAL:
4666 0 : case GIMPLE_OMP_MASTER:
4667 0 : case GIMPLE_OMP_MASKED:
4668 0 : case GIMPLE_OMP_SCOPE:
4669 0 : case GIMPLE_OMP_DISPATCH:
4670 0 : case GIMPLE_OMP_TASKGROUP:
4671 0 : case GIMPLE_OMP_ORDERED:
4672 0 : case GIMPLE_OMP_SCAN:
4673 0 : case GIMPLE_OMP_SECTION:
4674 0 : case GIMPLE_OMP_SECTIONS:
4675 0 : case GIMPLE_OMP_STRUCTURED_BLOCK:
4676 0 : case GIMPLE_OMP_SINGLE:
4677 0 : case GIMPLE_OMP_TARGET:
4678 0 : case GIMPLE_OMP_TEAMS:
4679 0 : return (weights->omp_cost
4680 0 : + estimate_num_insns_seq (gimple_omp_body (stmt), weights));
4681 :
4682 81 : case GIMPLE_TRANSACTION:
4683 81 : return (weights->tm_cost
4684 81 : + estimate_num_insns_seq (gimple_transaction_body (
4685 81 : as_a <gtransaction *> (stmt)),
4686 81 : weights));
4687 :
4688 0 : default:
4689 0 : gcc_unreachable ();
4690 : }
4691 :
4692 532864685 : return cost;
4693 : }
4694 :
4695 : /* Estimate number of instructions that will be created by expanding
4696 : function FNDECL. WEIGHTS contains weights attributed to various
4697 : constructs. */
4698 :
4699 : int
4700 0 : estimate_num_insns_fn (tree fndecl, eni_weights *weights)
4701 : {
4702 0 : struct function *my_function = DECL_STRUCT_FUNCTION (fndecl);
4703 0 : gimple_stmt_iterator bsi;
4704 0 : basic_block bb;
4705 0 : int n = 0;
4706 :
4707 0 : gcc_assert (my_function && my_function->cfg);
4708 0 : FOR_EACH_BB_FN (bb, my_function)
4709 : {
4710 0 : for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi))
4711 0 : n += estimate_num_insns (gsi_stmt (bsi), weights);
4712 : }
4713 :
4714 0 : return n;
4715 : }
4716 :
4717 :
4718 : /* Initializes weights used by estimate_num_insns. */
4719 :
4720 : void
4721 284790 : init_inline_once (void)
4722 : {
4723 284790 : eni_size_weights.call_cost = 1;
4724 284790 : eni_size_weights.indirect_call_cost = 3;
4725 284790 : eni_size_weights.target_builtin_call_cost = 1;
4726 284790 : eni_size_weights.div_mod_cost = 1;
4727 284790 : eni_size_weights.omp_cost = 40;
4728 284790 : eni_size_weights.tm_cost = 10;
4729 284790 : eni_size_weights.time_based = false;
4730 284790 : eni_size_weights.return_cost = 1;
4731 :
4732 : /* Estimating time for call is difficult, since we have no idea what the
4733 : called function does. In the current uses of eni_time_weights,
4734 : underestimating the cost does less harm than overestimating it, so
4735 : we choose a rather small value here. */
4736 284790 : eni_time_weights.call_cost = 10;
4737 284790 : eni_time_weights.indirect_call_cost = 15;
4738 284790 : eni_time_weights.target_builtin_call_cost = 1;
4739 284790 : eni_time_weights.div_mod_cost = 10;
4740 284790 : eni_time_weights.omp_cost = 40;
4741 284790 : eni_time_weights.tm_cost = 40;
4742 284790 : eni_time_weights.time_based = true;
4743 284790 : eni_time_weights.return_cost = 2;
4744 284790 : }
4745 :
4746 :
4747 : /* Install new lexical TREE_BLOCK underneath 'current_block'. */
4748 :
4749 : static void
4750 30994421 : prepend_lexical_block (tree current_block, tree new_block)
4751 : {
4752 30994421 : BLOCK_CHAIN (new_block) = BLOCK_SUBBLOCKS (current_block);
4753 30994421 : BLOCK_SUBBLOCKS (current_block) = new_block;
4754 30994421 : BLOCK_SUPERCONTEXT (new_block) = current_block;
4755 30994421 : }
4756 :
4757 : /* Add local variables from CALLEE to CALLER. */
4758 :
4759 : static inline void
4760 4799262 : add_local_variables (struct function *callee, struct function *caller,
4761 : copy_body_data *id)
4762 : {
4763 4799262 : tree var;
4764 4799262 : unsigned ix;
4765 :
4766 13245369 : FOR_EACH_LOCAL_DECL (callee, ix, var)
4767 4431546 : if (!can_be_nonlocal (var, id))
4768 : {
4769 4347429 : tree new_var = remap_decl (var, id);
4770 :
4771 : /* Remap debug-expressions. */
4772 4347429 : if (VAR_P (new_var)
4773 4347429 : && DECL_HAS_DEBUG_EXPR_P (var)
4774 4652883 : && new_var != var)
4775 : {
4776 305454 : tree tem = DECL_DEBUG_EXPR (var);
4777 305454 : bool old_regimplify = id->regimplify;
4778 305454 : id->remapping_type_depth++;
4779 305454 : walk_tree (&tem, copy_tree_body_r, id, NULL);
4780 305454 : id->remapping_type_depth--;
4781 305454 : id->regimplify = old_regimplify;
4782 305454 : SET_DECL_DEBUG_EXPR (new_var, tem);
4783 305454 : DECL_HAS_DEBUG_EXPR_P (new_var) = 1;
4784 : }
4785 4347429 : add_local_decl (caller, new_var);
4786 : }
4787 4799262 : }
4788 :
4789 : /* Add to BINDINGS a debug stmt resetting SRCVAR if inlining might
4790 : have brought in or introduced any debug stmts for SRCVAR. */
4791 :
4792 : static inline void
4793 9956484 : reset_debug_binding (copy_body_data *id, tree srcvar, gimple_seq *bindings)
4794 : {
4795 9956484 : tree *remappedvarp = id->decl_map->get (srcvar);
4796 :
4797 9956484 : if (!remappedvarp)
4798 : return;
4799 :
4800 9902730 : if (!VAR_P (*remappedvarp))
4801 : return;
4802 :
4803 9745413 : if (*remappedvarp == id->retvar)
4804 : return;
4805 :
4806 9745413 : tree tvar = target_for_debug_bind (*remappedvarp);
4807 9745413 : if (!tvar)
4808 : return;
4809 :
4810 15703170 : gdebug *stmt = gimple_build_debug_bind (tvar, NULL_TREE,
4811 7851585 : id->call_stmt);
4812 7851585 : gimple_seq_add_stmt (bindings, stmt);
4813 : }
4814 :
4815 : /* For each inlined variable for which we may have debug bind stmts,
4816 : add before GSI a final debug stmt resetting it, marking the end of
4817 : its life, so that var-tracking knows it doesn't have to compute
4818 : further locations for it. */
4819 :
4820 : static inline void
4821 4647687 : reset_debug_bindings (copy_body_data *id, gimple_stmt_iterator gsi)
4822 : {
4823 4647687 : tree var;
4824 4647687 : unsigned ix;
4825 4647687 : gimple_seq bindings = NULL;
4826 :
4827 4647687 : if (!gimple_in_ssa_p (id->src_cfun))
4828 545248 : return;
4829 :
4830 4647687 : if (!opt_for_fn (id->dst_fn, flag_var_tracking_assignments))
4831 : return;
4832 :
4833 4102439 : for (var = DECL_ARGUMENTS (id->src_fn);
4834 11155226 : var; var = DECL_CHAIN (var))
4835 7052787 : reset_debug_binding (id, var, &bindings);
4836 :
4837 10435424 : FOR_EACH_LOCAL_DECL (id->src_cfun, ix, var)
4838 2903697 : reset_debug_binding (id, var, &bindings);
4839 :
4840 4102439 : gsi_insert_seq_before_without_update (&gsi, bindings, GSI_SAME_STMT);
4841 : }
4842 :
4843 : /* If STMT is a GIMPLE_CALL, replace it with its inline expansion. */
4844 :
4845 : static bool
4846 15800007 : expand_call_inline (basic_block bb, gimple *stmt, copy_body_data *id,
4847 : bitmap to_purge)
4848 : {
4849 15800007 : tree use_retvar;
4850 15800007 : tree fn;
4851 15800007 : hash_map<tree, tree> *dst;
4852 15800007 : hash_map<tree, tree> *st = NULL;
4853 15800007 : tree return_slot;
4854 15800007 : tree modify_dest;
4855 15800007 : struct cgraph_edge *cg_edge;
4856 15800007 : cgraph_inline_failed_t reason;
4857 15800007 : basic_block return_block;
4858 15800007 : edge e;
4859 15800007 : gimple_stmt_iterator gsi, stmt_gsi;
4860 15800007 : bool successfully_inlined = false;
4861 15800007 : bool purge_dead_abnormal_edges;
4862 15800007 : gcall *call_stmt;
4863 15800007 : unsigned int prop_mask, src_properties;
4864 15800007 : struct function *dst_cfun;
4865 15800007 : tree simduid;
4866 15800007 : use_operand_p use;
4867 15800007 : gimple *simtenter_stmt = NULL;
4868 15800007 : vec<tree> *simtvars_save;
4869 15800007 : tree save_stack = NULL_TREE;
4870 :
4871 : /* The gimplifier uses input_location in too many places, such as
4872 : internal_get_tmp_var (). */
4873 15800007 : location_t saved_location = input_location;
4874 15800007 : input_location = gimple_location (stmt);
4875 :
4876 : /* From here on, we're only interested in CALL_EXPRs. */
4877 15800007 : call_stmt = dyn_cast <gcall *> (stmt);
4878 15800007 : if (!call_stmt)
4879 0 : goto egress;
4880 :
4881 15800007 : cg_edge = id->dst_node->get_edge (stmt);
4882 : /* Edge should exist and speculations should be resolved at this
4883 : stage. */
4884 15800007 : gcc_checking_assert (cg_edge && !cg_edge->speculative);
4885 : /* First, see if we can figure out what function is being called.
4886 : If we cannot, then there is no hope of inlining the function. */
4887 15800007 : if (cg_edge->indirect_unknown_callee)
4888 239200 : goto egress;
4889 15560807 : fn = cg_edge->callee->decl;
4890 15560807 : gcc_checking_assert (fn);
4891 :
4892 : /* If FN is a declaration of a function in a nested scope that was
4893 : globally declared inline, we don't set its DECL_INITIAL.
4894 : However, we can't blindly follow DECL_ABSTRACT_ORIGIN because the
4895 : C++ front-end uses it for cdtors to refer to their internal
4896 : declarations, that are not real functions. Fortunately those
4897 : don't have trees to be saved, so we can tell by checking their
4898 : gimple_body. */
4899 15560807 : if (!DECL_INITIAL (fn)
4900 6899235 : && DECL_ABSTRACT_ORIGIN (fn)
4901 15692094 : && gimple_has_body_p (DECL_ABSTRACT_ORIGIN (fn)))
4902 279 : fn = DECL_ABSTRACT_ORIGIN (fn);
4903 :
4904 : /* Don't try to inline functions that are not well-suited to inlining. */
4905 15560807 : if (cg_edge->inline_failed)
4906 : {
4907 10912922 : reason = cg_edge->inline_failed;
4908 : /* If this call was originally indirect, we do not want to emit any
4909 : inlining related warnings or sorry messages because there are no
4910 : guarantees regarding those. */
4911 10912922 : if (cg_edge->indirect_inlining_edge)
4912 1961 : goto egress;
4913 :
4914 10910961 : if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn))
4915 : /* For extern inline functions that get redefined we always
4916 : silently ignored always_inline flag. Better behavior would
4917 : be to be able to keep both bodies and use extern inline body
4918 : for inlining, but we can't do that because frontends overwrite
4919 : the body. */
4920 63 : && !cg_edge->callee->redefined_extern_inline
4921 : /* During early inline pass, report only when optimization is
4922 : not turned on. */
4923 63 : && (symtab->global_info_ready
4924 61 : || !optimize
4925 51 : || cgraph_inline_failed_type (reason) == CIF_FINAL_ERROR)
4926 : /* PR 20090218-1_0.c. Body can be provided by another module. */
4927 10910995 : && (reason != CIF_BODY_NOT_AVAILABLE || !flag_generate_lto))
4928 : {
4929 27 : error ("inlining failed in call to %<always_inline%> %q+F: %s", fn,
4930 : cgraph_inline_failed_string (reason));
4931 27 : if (gimple_location (stmt) != UNKNOWN_LOCATION)
4932 27 : inform (gimple_location (stmt), "called from here");
4933 0 : else if (DECL_SOURCE_LOCATION (cfun->decl) != UNKNOWN_LOCATION)
4934 0 : inform (DECL_SOURCE_LOCATION (cfun->decl),
4935 : "called from this function");
4936 : }
4937 10910934 : else if (opt_for_fn (fn, warn_inline)
4938 339 : && DECL_DECLARED_INLINE_P (fn)
4939 110 : && !DECL_NO_INLINE_WARNING_P (fn)
4940 77 : && !DECL_IN_SYSTEM_HEADER (fn)
4941 60 : && reason != CIF_UNSPECIFIED
4942 60 : && !lookup_attribute ("noinline", DECL_ATTRIBUTES (fn))
4943 : /* Do not warn about not inlined recursive calls. */
4944 60 : && !cg_edge->recursive_p ()
4945 : /* Avoid warnings during early inline pass. */
4946 10910994 : && symtab->global_info_ready)
4947 : {
4948 8 : auto_diagnostic_group d;
4949 8 : if (warning (OPT_Winline, "inlining failed in call to %q+F: %s",
4950 : fn, _(cgraph_inline_failed_string (reason))))
4951 : {
4952 8 : if (gimple_location (stmt) != UNKNOWN_LOCATION)
4953 8 : inform (gimple_location (stmt), "called from here");
4954 0 : else if (DECL_SOURCE_LOCATION (cfun->decl) != UNKNOWN_LOCATION)
4955 0 : inform (DECL_SOURCE_LOCATION (cfun->decl),
4956 : "called from this function");
4957 : }
4958 8 : }
4959 10910961 : goto egress;
4960 : }
4961 4647885 : id->src_node = cg_edge->callee;
4962 :
4963 : /* If callee is thunk, all we need is to adjust the THIS pointer
4964 : and redirect to function being thunked. */
4965 4647885 : if (id->src_node->thunk)
4966 : {
4967 198 : cgraph_edge *edge;
4968 198 : tree virtual_offset = NULL;
4969 198 : profile_count count = cg_edge->count;
4970 198 : tree op;
4971 198 : gimple_stmt_iterator iter = gsi_for_stmt (stmt);
4972 198 : thunk_info *info = thunk_info::get (id->src_node);
4973 :
4974 198 : cgraph_edge::remove (cg_edge);
4975 396 : edge = id->src_node->callees->clone (id->dst_node, call_stmt,
4976 : gimple_uid (stmt),
4977 : profile_count::one (),
4978 : profile_count::one (),
4979 : true);
4980 198 : edge->count = count;
4981 198 : if (info->virtual_offset_p)
4982 7 : virtual_offset = size_int (info->virtual_value);
4983 198 : op = create_tmp_reg_fn (cfun, TREE_TYPE (gimple_call_arg (stmt, 0)),
4984 : NULL);
4985 198 : gsi_insert_before (&iter, gimple_build_assign (op,
4986 : gimple_call_arg (stmt, 0)),
4987 : GSI_NEW_STMT);
4988 198 : gcc_assert (info->this_adjusting);
4989 198 : op = thunk_adjust (&iter, op, 1, info->fixed_offset,
4990 : virtual_offset, info->indirect_offset);
4991 :
4992 198 : gimple_call_set_arg (stmt, 0, op);
4993 198 : gimple_call_set_fndecl (stmt, edge->callee->decl);
4994 198 : update_stmt (stmt);
4995 198 : id->src_node->remove ();
4996 198 : successfully_inlined = expand_call_inline (bb, stmt, id, to_purge);
4997 198 : maybe_remove_unused_call_args (cfun, stmt);
4998 : /* This used to return true even though we do fail to inline in
4999 : some cases. See PR98525. */
5000 198 : goto egress;
5001 : }
5002 4647687 : fn = cg_edge->callee->decl;
5003 4647687 : cg_edge->callee->get_untransformed_body ();
5004 :
5005 4647687 : if (flag_checking && cg_edge->callee->decl != id->dst_node->decl)
5006 4647678 : cg_edge->callee->verify ();
5007 :
5008 : /* We will be inlining this callee. */
5009 4647687 : id->eh_lp_nr = lookup_stmt_eh_lp (stmt);
5010 :
5011 : /* Update the callers EH personality. */
5012 4647687 : if (DECL_FUNCTION_PERSONALITY (fn))
5013 294714 : DECL_FUNCTION_PERSONALITY (cg_edge->caller->decl)
5014 147357 : = DECL_FUNCTION_PERSONALITY (fn);
5015 :
5016 : /* Split the block before the GIMPLE_CALL. */
5017 4647687 : stmt_gsi = gsi_for_stmt (stmt);
5018 4647687 : gsi_prev (&stmt_gsi);
5019 4647687 : e = split_block (bb, gsi_end_p (stmt_gsi) ? NULL : gsi_stmt (stmt_gsi));
5020 4647687 : bb = e->src;
5021 4647687 : return_block = e->dest;
5022 4647687 : remove_edge (e);
5023 :
5024 : /* If the GIMPLE_CALL was in the last statement of BB, it may have
5025 : been the source of abnormal edges. In this case, schedule
5026 : the removal of dead abnormal edges. */
5027 4647687 : gsi = gsi_start_bb (return_block);
5028 4647687 : gsi_next (&gsi);
5029 4647687 : purge_dead_abnormal_edges = gsi_end_p (gsi);
5030 :
5031 4647687 : stmt_gsi = gsi_start_bb (return_block);
5032 :
5033 : /* Build a block containing code to initialize the arguments, the
5034 : actual inline expansion of the body, and a label for the return
5035 : statements within the function to jump to. The type of the
5036 : statement expression is the return type of the function call.
5037 : ??? If the call does not have an associated block then we will
5038 : remap all callee blocks to NULL, effectively dropping most of
5039 : its debug information. This should only happen for calls to
5040 : artificial decls inserted by the compiler itself. We need to
5041 : either link the inlined blocks into the caller block tree or
5042 : not refer to them in any way to not break GC for locations. */
5043 4647687 : if (tree block = gimple_block (stmt))
5044 : {
5045 : /* We do want to assign a not UNKNOWN_LOCATION BLOCK_SOURCE_LOCATION
5046 : to make inlined_function_outer_scope_p return true on this BLOCK. */
5047 4621714 : location_t loc = LOCATION_LOCUS (gimple_location (stmt));
5048 4621714 : if (loc == UNKNOWN_LOCATION)
5049 273312 : loc = LOCATION_LOCUS (DECL_SOURCE_LOCATION (fn));
5050 273312 : if (loc == UNKNOWN_LOCATION)
5051 : loc = BUILTINS_LOCATION;
5052 4621714 : if (has_discriminator (gimple_location (stmt)))
5053 1584417 : loc = location_with_discriminator
5054 1584417 : (loc, get_discriminator_from_loc (gimple_location (stmt)));
5055 4621714 : id->block = make_node (BLOCK);
5056 7959393 : BLOCK_ABSTRACT_ORIGIN (id->block) = DECL_ORIGIN (fn);
5057 4621714 : BLOCK_SOURCE_LOCATION (id->block) = loc;
5058 4621714 : prepend_lexical_block (block, id->block);
5059 : }
5060 :
5061 : /* Local declarations will be replaced by their equivalents in this map. */
5062 4647687 : st = id->decl_map;
5063 4647687 : id->decl_map = new hash_map<tree, tree>;
5064 4647687 : dst = id->debug_map;
5065 4647687 : id->debug_map = NULL;
5066 4647687 : if (flag_stack_reuse != SR_NONE)
5067 4640817 : id->add_clobbers_to_eh_landing_pads = last_basic_block_for_fn (cfun);
5068 :
5069 : /* Record the function we are about to inline. */
5070 4647687 : id->src_fn = fn;
5071 4647687 : id->src_cfun = DECL_STRUCT_FUNCTION (fn);
5072 4647687 : id->reset_location = DECL_IGNORED_P (fn);
5073 4647687 : id->call_stmt = call_stmt;
5074 4647687 : cfun->cfg->full_profile &= id->src_cfun->cfg->full_profile;
5075 :
5076 : /* When inlining into an OpenMP SIMD-on-SIMT loop, arrange for new automatic
5077 : variables to be added to IFN_GOMP_SIMT_ENTER argument list. */
5078 4647687 : dst_cfun = DECL_STRUCT_FUNCTION (id->dst_fn);
5079 4647687 : simtvars_save = id->dst_simt_vars;
5080 4647687 : if (!(dst_cfun->curr_properties & PROP_gimple_lomp_dev)
5081 20723 : && (simduid = bb->loop_father->simduid) != NULL_TREE
5082 0 : && (simduid = ssa_default_def (dst_cfun, simduid)) != NULL_TREE
5083 0 : && single_imm_use (simduid, &use, &simtenter_stmt)
5084 0 : && is_gimple_call (simtenter_stmt)
5085 4647687 : && gimple_call_internal_p (simtenter_stmt, IFN_GOMP_SIMT_ENTER))
5086 0 : vec_alloc (id->dst_simt_vars, 0);
5087 : else
5088 4647687 : id->dst_simt_vars = NULL;
5089 :
5090 4647687 : if (profile_status_for_fn (id->src_cfun) == PROFILE_ABSENT)
5091 30357 : profile_status_for_fn (dst_cfun) = PROFILE_ABSENT;
5092 :
5093 : /* If the src function contains an IFN_VA_ARG, then so will the dst
5094 : function after inlining. Likewise for IFN_GOMP_USE_SIMT. */
5095 4647687 : prop_mask = PROP_gimple_lva | PROP_gimple_lomp_dev;
5096 4647687 : src_properties = id->src_cfun->curr_properties & prop_mask;
5097 4647687 : if (src_properties != prop_mask)
5098 1058 : dst_cfun->curr_properties &= src_properties | ~prop_mask;
5099 4647687 : dst_cfun->calls_eh_return |= id->src_cfun->calls_eh_return;
5100 4647687 : id->dst_node->has_omp_variant_constructs
5101 4647687 : |= id->src_node->has_omp_variant_constructs;
5102 :
5103 4647687 : gcc_assert (!id->src_cfun->after_inlining);
5104 :
5105 4647687 : id->entry_bb = bb;
5106 4647687 : if (lookup_attribute ("cold", DECL_ATTRIBUTES (fn)))
5107 : {
5108 1434 : gimple_stmt_iterator si = gsi_last_bb (bb);
5109 1434 : gsi_insert_after (&si, gimple_build_predict (PRED_COLD_FUNCTION,
5110 : NOT_TAKEN),
5111 : GSI_NEW_STMT);
5112 : }
5113 4647687 : initialize_inlined_parameters (id, stmt, fn, bb);
5114 4102457 : if (debug_nonbind_markers_p && debug_inline_points && id->block
5115 8738311 : && inlined_function_outer_scope_p (id->block))
5116 : {
5117 4090624 : gimple_stmt_iterator si = gsi_last_bb (bb);
5118 4090624 : gsi_insert_after (&si, gimple_build_debug_inline_entry
5119 4090624 : (id->block, DECL_SOURCE_LOCATION (id->src_fn)),
5120 : GSI_NEW_STMT);
5121 : }
5122 :
5123 : /* If function to be inlined calls alloca, wrap the inlined function
5124 : in between save_stack = __builtin_stack_save (); and
5125 : __builtin_stack_restore (save_stack); calls. */
5126 4647687 : if (id->src_cfun->calls_alloca && !gimple_call_noreturn_p (stmt))
5127 : /* Don't do this for VLA allocations though, just for user alloca
5128 : calls. */
5129 4625 : for (struct cgraph_edge *e = id->src_node->callees; e; e = e->next_callee)
5130 4228 : if (gimple_maybe_alloca_call_p (e->call_stmt)
5131 4228 : && !gimple_call_alloca_for_var_p (e->call_stmt))
5132 : {
5133 88 : tree fn = builtin_decl_implicit (BUILT_IN_STACK_SAVE);
5134 88 : gcall *call = gimple_build_call (fn, 0);
5135 88 : save_stack = make_ssa_name (ptr_type_node);
5136 88 : gimple_call_set_lhs (call, save_stack);
5137 88 : gimple_stmt_iterator si = gsi_last_bb (bb);
5138 88 : gsi_insert_after (&si, call, GSI_NEW_STMT);
5139 88 : struct cgraph_node *dest = cgraph_node::get_create (fn);
5140 88 : id->dst_node->create_edge (dest, call, bb->count)->inline_failed
5141 88 : = CIF_BODY_NOT_AVAILABLE;
5142 88 : break;
5143 : }
5144 :
5145 4647687 : if (DECL_INITIAL (fn))
5146 : {
5147 4647687 : if (gimple_block (stmt))
5148 : {
5149 4621714 : tree *var;
5150 :
5151 4621714 : prepend_lexical_block (id->block,
5152 4621714 : remap_blocks (DECL_INITIAL (fn), id));
5153 4621714 : gcc_checking_assert (BLOCK_SUBBLOCKS (id->block)
5154 : && (BLOCK_CHAIN (BLOCK_SUBBLOCKS (id->block))
5155 : == NULL_TREE));
5156 : /* Move vars for PARM_DECLs from DECL_INITIAL block to id->block,
5157 : otherwise for DWARF DW_TAG_formal_parameter will not be children of
5158 : DW_TAG_inlined_subroutine, but of a DW_TAG_lexical_block
5159 : under it. The parameters can be then evaluated in the debugger,
5160 : but don't show in backtraces. */
5161 6780363 : for (var = &BLOCK_VARS (BLOCK_SUBBLOCKS (id->block)); *var; )
5162 2158649 : if (TREE_CODE (DECL_ORIGIN (*var)) == PARM_DECL)
5163 : {
5164 595953 : tree v = *var;
5165 595953 : *var = TREE_CHAIN (v);
5166 595953 : TREE_CHAIN (v) = BLOCK_VARS (id->block);
5167 595953 : BLOCK_VARS (id->block) = v;
5168 : }
5169 : else
5170 1562696 : var = &TREE_CHAIN (*var);
5171 : }
5172 : else
5173 25973 : remap_blocks_to_null (DECL_INITIAL (fn), id);
5174 : }
5175 :
5176 : /* Return statements in the function body will be replaced by jumps
5177 : to the RET_LABEL. */
5178 4647687 : gcc_assert (DECL_INITIAL (fn));
5179 4647687 : gcc_assert (TREE_CODE (DECL_INITIAL (fn)) == BLOCK);
5180 :
5181 : /* Find the LHS to which the result of this call is assigned. */
5182 4647687 : return_slot = NULL;
5183 4647687 : if (gimple_call_lhs (stmt))
5184 : {
5185 2330753 : modify_dest = gimple_call_lhs (stmt);
5186 :
5187 : /* The function which we are inlining might not return a value,
5188 : in which case we should issue a warning that the function
5189 : does not return a value. In that case the optimizers will
5190 : see that the variable to which the value is assigned was not
5191 : initialized. We do not want to issue a warning about that
5192 : uninitialized variable. */
5193 2330753 : if (DECL_P (modify_dest))
5194 493422 : suppress_warning (modify_dest, OPT_Wuninitialized);
5195 :
5196 : /* If we have a return slot, we can assign it the result directly,
5197 : except in the case where it is a global variable that is only
5198 : written to because, the callee being permitted to read or take
5199 : the address of its DECL_RESULT, this could invalidate the flag
5200 : on the global variable; instead we preventively remove the store,
5201 : which would have happened later if the call was not inlined. */
5202 2330753 : if (gimple_call_return_slot_opt_p (call_stmt))
5203 : {
5204 137266 : tree base = get_base_address (modify_dest);
5205 :
5206 137266 : if (VAR_P (base)
5207 113557 : && (TREE_STATIC (base) || DECL_EXTERNAL (base))
5208 137326 : && varpool_node::get (base)->writeonly)
5209 : return_slot = NULL;
5210 : else
5211 : return_slot = modify_dest;
5212 :
5213 : modify_dest = NULL;
5214 : }
5215 : }
5216 : else
5217 : modify_dest = NULL;
5218 :
5219 : /* If we are inlining a call to the C++ operator new, we don't want
5220 : to use type based alias analysis on the return value. Otherwise
5221 : we may get confused if the compiler sees that the inlined new
5222 : function returns a pointer which was just deleted. See bug
5223 : 33407. */
5224 4647687 : if (DECL_IS_OPERATOR_NEW_P (fn))
5225 : {
5226 20220 : return_slot = NULL;
5227 20220 : modify_dest = NULL;
5228 : }
5229 :
5230 : /* Declare the return variable for the function. */
5231 4647687 : use_retvar = declare_return_variable (id, return_slot, modify_dest, bb);
5232 :
5233 : /* Add local vars in this inlined callee to caller. */
5234 4647687 : add_local_variables (id->src_cfun, cfun, id);
5235 :
5236 4647687 : if (dump_enabled_p ())
5237 : {
5238 677 : char buf[128];
5239 677 : snprintf (buf, sizeof(buf), "%4.2f",
5240 677 : cg_edge->sreal_frequency ().to_double ());
5241 677 : dump_printf_loc (MSG_NOTE | MSG_PRIORITY_INTERNALS,
5242 677 : call_stmt,
5243 : "Inlining %C to %C with frequency %s\n",
5244 : id->src_node, id->dst_node, buf);
5245 677 : if (dump_file && (dump_flags & TDF_DETAILS))
5246 : {
5247 198 : id->src_node->dump (dump_file);
5248 198 : id->dst_node->dump (dump_file);
5249 : }
5250 : }
5251 :
5252 : /* This is it. Duplicate the callee body. Assume callee is
5253 : pre-gimplified. Note that we must not alter the caller
5254 : function in any way before this point, as this CALL_EXPR may be
5255 : a self-referential call; if we're calling ourselves, we need to
5256 : duplicate our body before altering anything. */
5257 4647687 : copy_body (id, bb, return_block, NULL);
5258 :
5259 4647687 : reset_debug_bindings (id, stmt_gsi);
5260 :
5261 4647687 : if (flag_stack_reuse != SR_NONE)
5262 12562573 : for (tree p = DECL_ARGUMENTS (id->src_fn); p; p = DECL_CHAIN (p))
5263 7921756 : if (!TREE_THIS_VOLATILE (p))
5264 : {
5265 : /* The value associated with P is a local temporary only if
5266 : there is no value associated with P in the debug map. */
5267 7921486 : tree *varp = id->decl_map->get (p);
5268 7921486 : if (varp
5269 7921486 : && VAR_P (*varp)
5270 7749425 : && !is_gimple_reg (*varp)
5271 8349451 : && !(id->debug_map && id->debug_map->get (p)))
5272 : {
5273 427554 : tree clobber = build_clobber (TREE_TYPE (*varp),
5274 : CLOBBER_STORAGE_END);
5275 427554 : gimple *clobber_stmt;
5276 427554 : clobber_stmt = gimple_build_assign (*varp, clobber);
5277 427554 : gimple_set_location (clobber_stmt, gimple_location (stmt));
5278 427554 : gsi_insert_before (&stmt_gsi, clobber_stmt, GSI_SAME_STMT);
5279 : }
5280 : }
5281 :
5282 4647687 : if (save_stack)
5283 : {
5284 88 : tree fn = builtin_decl_implicit (BUILT_IN_STACK_RESTORE);
5285 88 : gcall *call = gimple_build_call (fn, 1, save_stack);
5286 88 : gsi_insert_before (&stmt_gsi, call, GSI_SAME_STMT);
5287 88 : struct cgraph_node *dest = cgraph_node::get_create (fn);
5288 88 : id->dst_node->create_edge (dest, call,
5289 : return_block->count)->inline_failed
5290 88 : = CIF_BODY_NOT_AVAILABLE;
5291 : }
5292 :
5293 : /* Reset the escaped solution. */
5294 4647687 : if (cfun->gimple_df)
5295 : {
5296 4647687 : pt_solution_reset (&cfun->gimple_df->escaped);
5297 4647687 : pt_solution_reset (&cfun->gimple_df->escaped_return);
5298 : }
5299 :
5300 : /* Add new automatic variables to IFN_GOMP_SIMT_ENTER arguments. */
5301 4647687 : if (id->dst_simt_vars && id->dst_simt_vars->length () > 0)
5302 : {
5303 0 : size_t nargs = gimple_call_num_args (simtenter_stmt);
5304 0 : vec<tree> *vars = id->dst_simt_vars;
5305 0 : auto_vec<tree> newargs (nargs + vars->length ());
5306 0 : for (size_t i = 0; i < nargs; i++)
5307 0 : newargs.quick_push (gimple_call_arg (simtenter_stmt, i));
5308 0 : for (tree *pvar = vars->begin (); pvar != vars->end (); pvar++)
5309 : {
5310 0 : tree ptrtype = build_pointer_type (TREE_TYPE (*pvar));
5311 0 : newargs.quick_push (build1 (ADDR_EXPR, ptrtype, *pvar));
5312 : }
5313 0 : gcall *g = gimple_build_call_internal_vec (IFN_GOMP_SIMT_ENTER, newargs);
5314 0 : gimple_call_set_lhs (g, gimple_call_lhs (simtenter_stmt));
5315 0 : gimple_stmt_iterator gsi = gsi_for_stmt (simtenter_stmt);
5316 0 : gsi_replace (&gsi, g, false);
5317 0 : }
5318 4647687 : vec_free (id->dst_simt_vars);
5319 4647687 : id->dst_simt_vars = simtvars_save;
5320 :
5321 : /* Clean up. */
5322 4647687 : if (id->debug_map)
5323 : {
5324 167403 : delete id->debug_map;
5325 167403 : id->debug_map = dst;
5326 : }
5327 9295374 : delete id->decl_map;
5328 4647687 : id->decl_map = st;
5329 :
5330 : /* Unlink the calls virtual operands before replacing it. */
5331 4647687 : unlink_stmt_vdef (stmt);
5332 4647687 : if (gimple_vdef (stmt)
5333 4647687 : && TREE_CODE (gimple_vdef (stmt)) == SSA_NAME)
5334 2134549 : release_ssa_name (gimple_vdef (stmt));
5335 :
5336 : /* If the inlined function returns a result that we care about,
5337 : substitute the GIMPLE_CALL with an assignment of the return
5338 : variable to the LHS of the call. That is, if STMT was
5339 : 'a = foo (...)', substitute the call with 'a = USE_RETVAR'. */
5340 4647687 : if (use_retvar && gimple_call_lhs (stmt))
5341 : {
5342 1916441 : gimple *old_stmt = stmt;
5343 1916441 : tree lhs = gimple_call_lhs (stmt);
5344 1916441 : if (!is_gimple_reg (lhs)
5345 105123 : && !is_gimple_reg (use_retvar)
5346 2021522 : && is_gimple_reg_type (TREE_TYPE (lhs)))
5347 : {
5348 : /* If both lhs and use_retvar aren't gimple regs, yet have
5349 : gimple reg type, copy through a temporary SSA_NAME. */
5350 0 : gimple *g = gimple_build_assign (make_ssa_name (TREE_TYPE (lhs)),
5351 : use_retvar);
5352 0 : gimple_set_location (g, gimple_location (old_stmt));
5353 0 : gsi_insert_before (&stmt_gsi, g, GSI_SAME_STMT);
5354 0 : use_retvar = gimple_assign_lhs (g);
5355 : }
5356 1916441 : stmt = gimple_build_assign (lhs, use_retvar);
5357 1916441 : gimple_set_location (stmt, gimple_location (old_stmt));
5358 1916441 : gsi_replace (&stmt_gsi, stmt, false);
5359 1916441 : maybe_clean_or_replace_eh_stmt (old_stmt, stmt);
5360 : /* Append a clobber for id->retvar if easily possible. */
5361 1916441 : if (flag_stack_reuse != SR_NONE
5362 1914289 : && id->retvar
5363 1914289 : && VAR_P (id->retvar)
5364 1914289 : && id->retvar != return_slot
5365 1914289 : && id->retvar != modify_dest
5366 1914289 : && !TREE_THIS_VOLATILE (id->retvar)
5367 1914259 : && !is_gimple_reg (id->retvar)
5368 2022574 : && !stmt_ends_bb_p (stmt))
5369 : {
5370 106133 : tree clobber = build_clobber (TREE_TYPE (id->retvar),
5371 : CLOBBER_STORAGE_END);
5372 106133 : gimple *clobber_stmt;
5373 106133 : clobber_stmt = gimple_build_assign (id->retvar, clobber);
5374 106133 : gimple_set_location (clobber_stmt, gimple_location (old_stmt));
5375 106133 : gsi_insert_after (&stmt_gsi, clobber_stmt, GSI_SAME_STMT);
5376 : }
5377 : }
5378 : else
5379 : {
5380 : /* Handle the case of inlining a function with no return
5381 : statement, which causes the return value to become undefined. */
5382 2731246 : if (gimple_call_lhs (stmt)
5383 2731246 : && TREE_CODE (gimple_call_lhs (stmt)) == SSA_NAME)
5384 : {
5385 21 : tree name = gimple_call_lhs (stmt);
5386 21 : tree var = SSA_NAME_VAR (name);
5387 6 : tree def = var ? ssa_default_def (cfun, var) : NULL;
5388 :
5389 6 : if (def)
5390 : {
5391 : /* If the variable is used undefined, make this name
5392 : undefined via a move. */
5393 0 : stmt = gimple_build_assign (gimple_call_lhs (stmt), def);
5394 0 : gsi_replace (&stmt_gsi, stmt, true);
5395 : }
5396 : else
5397 : {
5398 21 : if (!var)
5399 : {
5400 15 : var = create_tmp_reg_fn (cfun, TREE_TYPE (name), NULL);
5401 30 : SET_SSA_NAME_VAR_OR_IDENTIFIER (name, var);
5402 : }
5403 : /* Otherwise make this variable undefined. */
5404 21 : gsi_remove (&stmt_gsi, true);
5405 21 : set_ssa_default_def (cfun, var, name);
5406 21 : SSA_NAME_DEF_STMT (name) = gimple_build_nop ();
5407 : }
5408 : }
5409 : /* Replace with a clobber for id->retvar. */
5410 2731225 : else if (flag_stack_reuse != SR_NONE
5411 2726507 : && id->retvar
5412 550284 : && VAR_P (id->retvar)
5413 463569 : && id->retvar != return_slot
5414 412183 : && id->retvar != modify_dest
5415 136464 : && !TREE_THIS_VOLATILE (id->retvar)
5416 2867689 : && !is_gimple_reg (id->retvar))
5417 : {
5418 14770 : tree clobber = build_clobber (TREE_TYPE (id->retvar));
5419 14770 : gimple *clobber_stmt;
5420 14770 : clobber_stmt = gimple_build_assign (id->retvar, clobber);
5421 14770 : gimple_set_location (clobber_stmt, gimple_location (stmt));
5422 14770 : gsi_replace (&stmt_gsi, clobber_stmt, false);
5423 14770 : maybe_clean_or_replace_eh_stmt (stmt, clobber_stmt);
5424 : }
5425 : else
5426 2716455 : gsi_remove (&stmt_gsi, true);
5427 : }
5428 :
5429 4647687 : if (purge_dead_abnormal_edges)
5430 1130458 : bitmap_set_bit (to_purge, return_block->index);
5431 :
5432 : /* If the value of the new expression is ignored, that's OK. We
5433 : don't warn about this for CALL_EXPRs, so we shouldn't warn about
5434 : the equivalent inlined version either. */
5435 4647687 : if (is_gimple_assign (stmt))
5436 : {
5437 1916441 : gcc_assert (gimple_assign_single_p (stmt)
5438 : || CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (stmt)));
5439 1916441 : TREE_USED (gimple_assign_rhs1 (stmt)) = 1;
5440 : }
5441 :
5442 4647687 : id->add_clobbers_to_eh_landing_pads = 0;
5443 :
5444 : /* Output the inlining info for this abstract function, since it has been
5445 : inlined. If we don't do this now, we can lose the information about the
5446 : variables in the function when the blocks get blown away as soon as we
5447 : remove the cgraph node. */
5448 4647687 : if (gimple_block (stmt))
5449 4621714 : (*debug_hooks->outlining_inline_function) (fn);
5450 :
5451 : /* Update callgraph if needed. */
5452 4647687 : cg_edge->callee->remove ();
5453 :
5454 4647687 : id->block = NULL_TREE;
5455 4647687 : id->retvar = NULL_TREE;
5456 4647687 : successfully_inlined = true;
5457 :
5458 15800007 : egress:
5459 15800007 : input_location = saved_location;
5460 15800007 : return successfully_inlined;
5461 : }
5462 :
5463 : /* Expand call statements reachable from STMT_P.
5464 : We can only have CALL_EXPRs as the "toplevel" tree code or nested
5465 : in a MODIFY_EXPR. */
5466 :
5467 : static bool
5468 32680112 : gimple_expand_calls_inline (basic_block bb, copy_body_data *id,
5469 : bitmap to_purge)
5470 : {
5471 32680112 : gimple_stmt_iterator gsi;
5472 32680112 : bool inlined = false;
5473 :
5474 242007549 : for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi);)
5475 : {
5476 176647325 : gimple *stmt = gsi_stmt (gsi);
5477 176647325 : gsi_prev (&gsi);
5478 :
5479 176647325 : if (is_gimple_call (stmt)
5480 176647325 : && !gimple_call_internal_p (stmt))
5481 15799809 : inlined |= expand_call_inline (bb, stmt, id, to_purge);
5482 : }
5483 :
5484 32680112 : return inlined;
5485 : }
5486 :
5487 :
5488 : /* Walk all basic blocks created after FIRST and try to fold every statement
5489 : in the STATEMENTS pointer set. */
5490 :
5491 : static void
5492 1672246 : fold_marked_statements (int first, hash_set<gimple *> *statements)
5493 : {
5494 1672246 : auto_bitmap to_purge;
5495 1672246 : auto_bitmap to_purge_abnormal;
5496 :
5497 1672246 : auto_vec<edge, 20> stack (n_basic_blocks_for_fn (cfun) + 2);
5498 1672246 : auto_sbitmap visited (last_basic_block_for_fn (cfun));
5499 1672246 : bitmap_clear (visited);
5500 :
5501 1672246 : stack.quick_push (single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
5502 40275902 : while (!stack.is_empty ())
5503 : {
5504 : /* Look at the edge on the top of the stack. */
5505 38603656 : edge e = stack.pop ();
5506 38603656 : basic_block dest = e->dest;
5507 :
5508 47433910 : if (dest == EXIT_BLOCK_PTR_FOR_FN (cfun)
5509 36956884 : || bitmap_bit_p (visited, dest->index))
5510 8830254 : continue;
5511 :
5512 29773402 : bitmap_set_bit (visited, dest->index);
5513 :
5514 29773402 : if (dest->index >= first)
5515 38990952 : for (gimple_stmt_iterator gsi = gsi_start_bb (dest);
5516 135595102 : !gsi_end_p (gsi); gsi_next (&gsi))
5517 : {
5518 116099626 : if (!statements->contains (gsi_stmt (gsi)))
5519 24242064 : continue;
5520 :
5521 91857562 : gimple *old_stmt = gsi_stmt (gsi);
5522 91857562 : bool can_make_abnormal_goto = false;
5523 91857562 : tree old_decl = NULL_TREE;
5524 :
5525 91857562 : if (is_gimple_call (old_stmt))
5526 : {
5527 4118569 : old_decl = gimple_call_fndecl (old_stmt);
5528 4118569 : if (stmt_can_make_abnormal_goto (old_stmt))
5529 : can_make_abnormal_goto = true;
5530 : }
5531 :
5532 4118569 : if (old_decl && fndecl_built_in_p (old_decl))
5533 : {
5534 : /* Folding builtins can create multiple instructions,
5535 : we need to look at all of them. */
5536 1587289 : gimple_stmt_iterator i2 = gsi;
5537 1587289 : gsi_prev (&i2);
5538 1587289 : if (fold_stmt (&gsi))
5539 : {
5540 96282 : gimple *new_stmt;
5541 : /* If a builtin at the end of a bb folded into nothing,
5542 : the following loop won't work. */
5543 96282 : if (gsi_end_p (gsi))
5544 : {
5545 0 : cgraph_update_edges_for_call_stmt (old_stmt,
5546 : old_decl, NULL);
5547 0 : if (can_make_abnormal_goto)
5548 0 : bitmap_set_bit (to_purge_abnormal, dest->index);
5549 19495476 : break;
5550 : }
5551 96282 : if (gsi_end_p (i2))
5552 124776 : i2 = gsi_start_bb (dest);
5553 : else
5554 33894 : gsi_next (&i2);
5555 436 : while (1)
5556 : {
5557 96718 : new_stmt = gsi_stmt (i2);
5558 96718 : update_stmt (new_stmt);
5559 96718 : cgraph_update_edges_for_call_stmt (old_stmt, old_decl,
5560 : new_stmt);
5561 :
5562 96718 : if (new_stmt == gsi_stmt (gsi))
5563 : {
5564 : /* It is okay to check only for the very last
5565 : of these statements. If it is a throwing
5566 : statement nothing will change. If it isn't
5567 : this can remove EH edges. If that weren't
5568 : correct then because some intermediate stmts
5569 : throw, but not the last one. That would mean
5570 : we'd have to split the block, which we can't
5571 : here and we'd loose anyway. And as builtins
5572 : probably never throw, this all
5573 : is mood anyway. */
5574 96282 : if (maybe_clean_or_replace_eh_stmt (old_stmt,
5575 : new_stmt))
5576 7 : bitmap_set_bit (to_purge, dest->index);
5577 96282 : if (can_make_abnormal_goto
5578 96282 : && !stmt_can_make_abnormal_goto (new_stmt))
5579 0 : bitmap_set_bit (to_purge_abnormal, dest->index);
5580 : break;
5581 : }
5582 436 : gsi_next (&i2);
5583 : }
5584 : }
5585 : }
5586 90270273 : else if (fold_stmt (&gsi))
5587 : {
5588 : /* Re-read the statement from GSI as fold_stmt() may
5589 : have changed it. */
5590 3021412 : gimple *new_stmt = gsi_stmt (gsi);
5591 3021412 : update_stmt (new_stmt);
5592 :
5593 3021412 : if (is_gimple_call (old_stmt)
5594 3021412 : || is_gimple_call (new_stmt))
5595 4766 : cgraph_update_edges_for_call_stmt (old_stmt, old_decl,
5596 : new_stmt);
5597 :
5598 3021412 : if (maybe_clean_or_replace_eh_stmt (old_stmt, new_stmt))
5599 155 : bitmap_set_bit (to_purge, dest->index);
5600 3021412 : if (can_make_abnormal_goto
5601 3021412 : && !stmt_can_make_abnormal_goto (new_stmt))
5602 7 : bitmap_set_bit (to_purge_abnormal, dest->index);
5603 : }
5604 : }
5605 :
5606 57881775 : if (EDGE_COUNT (dest->succs) > 0)
5607 : {
5608 : /* Avoid warnings emitted from folding statements that
5609 : became unreachable because of inlined function parameter
5610 : propagation. */
5611 28108373 : e = find_taken_edge (dest, NULL_TREE);
5612 28108373 : if (e)
5613 19459252 : stack.quick_push (e);
5614 : else
5615 : {
5616 8649121 : edge_iterator ei;
5617 26121279 : FOR_EACH_EDGE (e, ei, dest->succs)
5618 17472158 : stack.safe_push (e);
5619 : }
5620 : }
5621 : }
5622 :
5623 1672246 : gimple_purge_all_dead_eh_edges (to_purge);
5624 1672246 : gimple_purge_all_dead_abnormal_call_edges (to_purge_abnormal);
5625 1672246 : }
5626 :
5627 : /* Expand calls to inline functions in the body of FN. */
5628 :
5629 : unsigned int
5630 2042280 : optimize_inline_calls (tree fn)
5631 : {
5632 2042280 : copy_body_data id;
5633 2042280 : basic_block bb;
5634 2042280 : int last = n_basic_blocks_for_fn (cfun);
5635 2042280 : bool inlined_p = false;
5636 :
5637 : /* Clear out ID. */
5638 2042280 : memset (&id, 0, sizeof (id));
5639 :
5640 2042280 : id.src_node = id.dst_node = cgraph_node::get (fn);
5641 2042280 : gcc_assert (id.dst_node->definition);
5642 2042280 : id.dst_fn = fn;
5643 : /* Or any functions that aren't finished yet. */
5644 2042280 : if (current_function_decl)
5645 2042280 : id.dst_fn = current_function_decl;
5646 :
5647 2042280 : id.copy_decl = copy_decl_maybe_to_var;
5648 2042280 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
5649 2042280 : id.transform_new_cfg = false;
5650 2042280 : id.transform_return_to_modify = true;
5651 2042280 : id.transform_parameter = true;
5652 2042280 : id.statements_to_fold = new hash_set<gimple *>;
5653 :
5654 2042280 : push_gimplify_context ();
5655 :
5656 : /* We make no attempts to keep dominance info up-to-date. */
5657 2042280 : free_dominance_info (CDI_DOMINATORS);
5658 2042280 : free_dominance_info (CDI_POST_DOMINATORS);
5659 :
5660 : /* Register specific gimple functions. */
5661 2042280 : gimple_register_cfg_hooks ();
5662 :
5663 : /* Reach the trees by walking over the CFG, and note the
5664 : enclosing basic-blocks in the call edges. */
5665 : /* We walk the blocks going forward, because inlined function bodies
5666 : will split id->current_basic_block, and the new blocks will
5667 : follow it; we'll trudge through them, processing their CALL_EXPRs
5668 : along the way. */
5669 2042280 : auto_bitmap to_purge;
5670 34722392 : FOR_EACH_BB_FN (bb, cfun)
5671 32680112 : inlined_p |= gimple_expand_calls_inline (bb, &id, to_purge);
5672 :
5673 2042280 : pop_gimplify_context (NULL);
5674 :
5675 2042280 : if (flag_checking)
5676 : {
5677 2042262 : struct cgraph_edge *e;
5678 :
5679 2042262 : id.dst_node->verify ();
5680 :
5681 : /* Double check that we inlined everything we are supposed to inline. */
5682 12242386 : for (e = id.dst_node->callees; e; e = e->next_callee)
5683 10200124 : gcc_assert (e->inline_failed);
5684 : }
5685 :
5686 : /* If we didn't inline into the function there is nothing to do. */
5687 2042280 : if (!inlined_p)
5688 : {
5689 1248954 : delete id.statements_to_fold;
5690 624477 : return 0;
5691 : }
5692 :
5693 : /* Fold queued statements. */
5694 1417803 : update_max_bb_count ();
5695 1417803 : fold_marked_statements (last, id.statements_to_fold);
5696 2835606 : delete id.statements_to_fold;
5697 :
5698 : /* Finally purge EH and abnormal edges from the call stmts we inlined.
5699 : We need to do this after fold_marked_statements since that may walk
5700 : the SSA use-def chain. */
5701 1417803 : unsigned i;
5702 1417803 : bitmap_iterator bi;
5703 2548261 : EXECUTE_IF_SET_IN_BITMAP (to_purge, 0, i, bi)
5704 : {
5705 1130458 : basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
5706 1130458 : if (bb)
5707 : {
5708 1130458 : gimple_purge_dead_eh_edges (bb);
5709 1130458 : gimple_purge_dead_abnormal_call_edges (bb);
5710 : }
5711 : }
5712 :
5713 1417803 : gcc_assert (!id.debug_stmts.exists ());
5714 :
5715 : /* Renumber the lexical scoping (non-code) blocks consecutively. */
5716 1417803 : number_blocks (fn);
5717 :
5718 1417803 : delete_unreachable_blocks_update_callgraph (id.dst_node, false);
5719 1417803 : id.dst_node->calls_comdat_local = id.dst_node->check_calls_comdat_local_p ();
5720 :
5721 1417803 : if (flag_checking)
5722 1417794 : id.dst_node->verify ();
5723 :
5724 : /* It would be nice to check SSA/CFG/statement consistency here, but it is
5725 : not possible yet - the IPA passes might make various functions to not
5726 : throw and they don't care to proactively update local EH info. This is
5727 : done later in fixup_cfg pass that also execute the verification. */
5728 1417803 : return (TODO_update_ssa
5729 : | TODO_cleanup_cfg
5730 1417803 : | (gimple_in_ssa_p (cfun) ? TODO_remove_unused_locals : 0)
5731 2835606 : | (gimple_in_ssa_p (cfun) ? TODO_update_address_taken : 0));
5732 2042280 : }
5733 :
5734 : /* Passed to walk_tree. Copies the node pointed to, if appropriate. */
5735 :
5736 : tree
5737 1978160422 : copy_tree_r (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
5738 : {
5739 1978160422 : enum tree_code code = TREE_CODE (*tp);
5740 1978160422 : enum tree_code_class cl = TREE_CODE_CLASS (code);
5741 :
5742 : /* We make copies of most nodes. */
5743 1978160422 : if (IS_EXPR_CODE_CLASS (cl)
5744 : || code == TREE_LIST
5745 301904976 : || code == TREE_VEC
5746 296914706 : || code == TYPE_DECL
5747 296914706 : || code == OMP_CLAUSE)
5748 : {
5749 : /* Because the chain gets clobbered when we make a copy, we save it
5750 : here. */
5751 1681269648 : tree chain = NULL_TREE, new_tree;
5752 :
5753 1681269648 : if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
5754 5014202 : chain = TREE_CHAIN (*tp);
5755 :
5756 : /* Copy the node. */
5757 1681269648 : new_tree = copy_node (*tp);
5758 :
5759 1681269648 : *tp = new_tree;
5760 :
5761 : /* Now, restore the chain, if appropriate. That will cause
5762 : walk_tree to walk into the chain as well. */
5763 1681269648 : if (code == PARM_DECL
5764 1681269648 : || code == TREE_LIST
5765 1679052724 : || code == OMP_CLAUSE)
5766 2240828 : TREE_CHAIN (*tp) = chain;
5767 :
5768 : /* For now, we don't update BLOCKs when we make copies. So, we
5769 : have to nullify all BIND_EXPRs. */
5770 1681269648 : if (TREE_CODE (*tp) == BIND_EXPR)
5771 20715247 : BIND_EXPR_BLOCK (*tp) = NULL_TREE;
5772 : }
5773 296890774 : else if (code == CONSTRUCTOR)
5774 : {
5775 : /* CONSTRUCTOR nodes need special handling because
5776 : we need to duplicate the vector of elements. */
5777 18077778 : tree new_tree;
5778 :
5779 18077778 : new_tree = copy_node (*tp);
5780 26430973 : CONSTRUCTOR_ELTS (new_tree) = vec_safe_copy (CONSTRUCTOR_ELTS (*tp));
5781 18077778 : *tp = new_tree;
5782 : }
5783 278812996 : else if (code == STATEMENT_LIST)
5784 : /* We used to just abort on STATEMENT_LIST, but we can run into them
5785 : with statement-expressions (c++/40975). */
5786 198 : copy_statement_list (tp);
5787 278812798 : else if (TREE_CODE_CLASS (code) == tcc_type)
5788 278 : *walk_subtrees = 0;
5789 278812520 : else if (TREE_CODE_CLASS (code) == tcc_declaration)
5790 120998045 : *walk_subtrees = 0;
5791 157814475 : else if (TREE_CODE_CLASS (code) == tcc_constant)
5792 0 : *walk_subtrees = 0;
5793 1978160422 : return NULL_TREE;
5794 : }
5795 :
5796 : /* The SAVE_EXPR pointed to by TP is being copied. If ST contains
5797 : information indicating to what new SAVE_EXPR this one should be mapped,
5798 : use that one. Otherwise, create a new node and enter it in ST. FN is
5799 : the function into which the copy will be placed. */
5800 :
5801 : static void
5802 15572503 : remap_save_expr (tree *tp, hash_map<tree, tree> *st, int *walk_subtrees)
5803 : {
5804 15572503 : tree *n;
5805 15572503 : tree t;
5806 :
5807 : /* See if we already encountered this SAVE_EXPR. */
5808 15572503 : n = st->get (*tp);
5809 :
5810 : /* If we didn't already remap this SAVE_EXPR, do so now. */
5811 15572503 : if (!n)
5812 : {
5813 15113719 : t = copy_node (*tp);
5814 :
5815 : /* Remember this SAVE_EXPR. */
5816 15113719 : st->put (*tp, t);
5817 : /* Make sure we don't remap an already-remapped SAVE_EXPR. */
5818 15113719 : st->put (t, t);
5819 : }
5820 : else
5821 : {
5822 : /* We've already walked into this SAVE_EXPR; don't do it again. */
5823 458784 : *walk_subtrees = 0;
5824 458784 : t = *n;
5825 : }
5826 :
5827 : /* Replace this SAVE_EXPR with the copy. */
5828 15572503 : *tp = t;
5829 15572503 : }
5830 :
5831 : /* Called via walk_gimple_seq. If *GSIP points to a GIMPLE_LABEL for a local
5832 : label, copies the declaration and enters it in the splay_tree in DATA (which
5833 : is really a 'copy_body_data *'. */
5834 :
5835 : static tree
5836 1629602 : mark_local_labels_stmt (gimple_stmt_iterator *gsip,
5837 : bool *handled_ops_p ATTRIBUTE_UNUSED,
5838 : struct walk_stmt_info *wi)
5839 : {
5840 1629602 : copy_body_data *id = (copy_body_data *) wi->info;
5841 1629602 : glabel *stmt = dyn_cast <glabel *> (gsi_stmt (*gsip));
5842 :
5843 53316 : if (stmt)
5844 : {
5845 53316 : tree decl = gimple_label_label (stmt);
5846 :
5847 : /* Copy the decl and remember the copy. */
5848 53316 : insert_decl_map (id, decl, id->copy_decl (decl, id));
5849 : }
5850 :
5851 1629602 : return NULL_TREE;
5852 : }
5853 :
5854 : static gimple_seq duplicate_remap_omp_clause_seq (gimple_seq seq,
5855 : struct walk_stmt_info *wi);
5856 :
5857 : /* Called via walk_gimple_seq by copy_gimple_seq_and_replace_local.
5858 : Using the splay_tree pointed to by ST (which is really a `splay_tree'),
5859 : remaps all local declarations to appropriate replacements in gimple
5860 : operands. */
5861 :
5862 : static tree
5863 3570440 : replace_locals_op (tree *tp, int *walk_subtrees, void *data)
5864 : {
5865 3570440 : struct walk_stmt_info *wi = (struct walk_stmt_info*) data;
5866 3570440 : copy_body_data *id = (copy_body_data *) wi->info;
5867 3570440 : hash_map<tree, tree> *st = id->decl_map;
5868 3570440 : tree *n;
5869 3570440 : tree expr = *tp;
5870 :
5871 : /* For recursive invocations this is no longer the LHS itself. */
5872 3570440 : bool is_lhs = wi->is_lhs;
5873 3570440 : wi->is_lhs = false;
5874 :
5875 3570440 : if (TREE_CODE (expr) == SSA_NAME)
5876 : {
5877 25042 : *tp = remap_ssa_name (*tp, id);
5878 25042 : *walk_subtrees = 0;
5879 25042 : if (is_lhs)
5880 12521 : SSA_NAME_DEF_STMT (*tp) = gsi_stmt (wi->gsi);
5881 : }
5882 : /* Only a local declaration (variable or label). */
5883 3545398 : else if ((VAR_P (expr) && !TREE_STATIC (expr))
5884 2070178 : || TREE_CODE (expr) == LABEL_DECL)
5885 : {
5886 : /* Lookup the declaration. */
5887 1583908 : n = st->get (expr);
5888 :
5889 : /* If it's there, remap it. */
5890 1583908 : if (n)
5891 107346 : *tp = *n;
5892 1583908 : *walk_subtrees = 0;
5893 : }
5894 1961490 : else if (TREE_CODE (expr) == STATEMENT_LIST
5895 1961490 : || TREE_CODE (expr) == BIND_EXPR
5896 1961490 : || TREE_CODE (expr) == SAVE_EXPR)
5897 0 : gcc_unreachable ();
5898 1961490 : else if (TREE_CODE (expr) == TARGET_EXPR)
5899 : {
5900 : /* Don't mess with a TARGET_EXPR that hasn't been expanded.
5901 : It's OK for this to happen if it was part of a subtree that
5902 : isn't immediately expanded, such as operand 2 of another
5903 : TARGET_EXPR. */
5904 0 : if (!TREE_OPERAND (expr, 1))
5905 : {
5906 0 : TREE_OPERAND (expr, 1) = TREE_OPERAND (expr, 3);
5907 0 : TREE_OPERAND (expr, 3) = NULL_TREE;
5908 : }
5909 : }
5910 1961490 : else if (TREE_CODE (expr) == OMP_CLAUSE)
5911 : {
5912 : /* Before the omplower pass completes, some OMP clauses can contain
5913 : sequences that are neither copied by gimple_seq_copy nor walked by
5914 : walk_gimple_seq. To make copy_gimple_seq_and_replace_locals work even
5915 : in those situations, we have to copy and process them explicitly. */
5916 :
5917 556 : if (OMP_CLAUSE_CODE (expr) == OMP_CLAUSE_LASTPRIVATE)
5918 : {
5919 14 : gimple_seq seq = OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (expr);
5920 14 : seq = duplicate_remap_omp_clause_seq (seq, wi);
5921 14 : OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (expr) = seq;
5922 : }
5923 542 : else if (OMP_CLAUSE_CODE (expr) == OMP_CLAUSE_LINEAR)
5924 : {
5925 77 : gimple_seq seq = OMP_CLAUSE_LINEAR_GIMPLE_SEQ (expr);
5926 77 : seq = duplicate_remap_omp_clause_seq (seq, wi);
5927 77 : OMP_CLAUSE_LINEAR_GIMPLE_SEQ (expr) = seq;
5928 : }
5929 465 : else if (OMP_CLAUSE_CODE (expr) == OMP_CLAUSE_REDUCTION)
5930 : {
5931 99 : gimple_seq seq = OMP_CLAUSE_REDUCTION_GIMPLE_INIT (expr);
5932 99 : seq = duplicate_remap_omp_clause_seq (seq, wi);
5933 99 : OMP_CLAUSE_REDUCTION_GIMPLE_INIT (expr) = seq;
5934 99 : seq = OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (expr);
5935 99 : seq = duplicate_remap_omp_clause_seq (seq, wi);
5936 99 : OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (expr) = seq;
5937 : }
5938 : }
5939 :
5940 : /* Keep iterating. */
5941 3570440 : return NULL_TREE;
5942 : }
5943 :
5944 :
5945 : /* Called via walk_gimple_seq by copy_gimple_seq_and_replace_local.
5946 : Using the splay_tree pointed to by ST (which is really a `splay_tree'),
5947 : remaps all local declarations to appropriate replacements in gimple
5948 : statements. */
5949 :
5950 : static tree
5951 1629602 : replace_locals_stmt (gimple_stmt_iterator *gsip,
5952 : bool *handled_ops_p ATTRIBUTE_UNUSED,
5953 : struct walk_stmt_info *wi)
5954 : {
5955 1629602 : copy_body_data *id = (copy_body_data *) wi->info;
5956 1629602 : gimple *gs = gsi_stmt (*gsip);
5957 :
5958 1629602 : if (gbind *stmt = dyn_cast <gbind *> (gs))
5959 : {
5960 349 : tree block = gimple_bind_block (stmt);
5961 :
5962 349 : if (block)
5963 : {
5964 269 : remap_block (&block, id);
5965 269 : gimple_bind_set_block (stmt, block);
5966 : }
5967 :
5968 : /* This will remap a lot of the same decls again, but this should be
5969 : harmless. */
5970 349 : if (gimple_bind_vars (stmt))
5971 : {
5972 : tree old_var, decls = gimple_bind_vars (stmt);
5973 :
5974 528 : for (old_var = decls; old_var; old_var = DECL_CHAIN (old_var))
5975 360 : if (!can_be_nonlocal (old_var, id)
5976 360 : && ! variably_modified_type_p (TREE_TYPE (old_var), id->src_fn))
5977 360 : remap_decl (old_var, id);
5978 :
5979 168 : gcc_checking_assert (!id->prevent_decl_creation_for_types);
5980 168 : id->prevent_decl_creation_for_types = true;
5981 168 : gimple_bind_set_vars (stmt, remap_decls (decls, NULL, id));
5982 168 : id->prevent_decl_creation_for_types = false;
5983 : }
5984 : }
5985 :
5986 : /* Keep iterating. */
5987 1629602 : return NULL_TREE;
5988 : }
5989 :
5990 : /* Create a copy of SEQ and remap all decls in it. */
5991 :
5992 : static gimple_seq
5993 289 : duplicate_remap_omp_clause_seq (gimple_seq seq, struct walk_stmt_info *wi)
5994 : {
5995 289 : if (!seq)
5996 : return NULL;
5997 :
5998 : /* If there are any labels in OMP sequences, they can be only referred to in
5999 : the sequence itself and therefore we can do both here. */
6000 60 : walk_gimple_seq (seq, mark_local_labels_stmt, NULL, wi);
6001 60 : gimple_seq copy = gimple_seq_copy (seq);
6002 60 : walk_gimple_seq (copy, replace_locals_stmt, replace_locals_op, wi);
6003 60 : return copy;
6004 : }
6005 :
6006 : /* Copies everything in SEQ and replaces variables and labels local to
6007 : current_function_decl. */
6008 :
6009 : gimple_seq
6010 1103341 : copy_gimple_seq_and_replace_locals (gimple_seq seq)
6011 : {
6012 1103341 : copy_body_data id;
6013 1103341 : struct walk_stmt_info wi;
6014 1103341 : gimple_seq copy;
6015 :
6016 : /* There's nothing to do for NULL_TREE. */
6017 1103341 : if (seq == NULL)
6018 : return seq;
6019 :
6020 : /* Set up ID. */
6021 1103325 : memset (&id, 0, sizeof (id));
6022 1103325 : id.src_fn = current_function_decl;
6023 1103325 : id.dst_fn = current_function_decl;
6024 1103325 : id.src_cfun = cfun;
6025 1103325 : id.decl_map = new hash_map<tree, tree>;
6026 1103325 : id.debug_map = NULL;
6027 :
6028 1103325 : id.copy_decl = copy_decl_no_change;
6029 1103325 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
6030 1103325 : id.transform_new_cfg = false;
6031 1103325 : id.transform_return_to_modify = false;
6032 1103325 : id.transform_parameter = false;
6033 :
6034 : /* Walk the tree once to find local labels. */
6035 1103325 : memset (&wi, 0, sizeof (wi));
6036 1103325 : hash_set<tree> visited;
6037 1103325 : wi.info = &id;
6038 1103325 : wi.pset = &visited;
6039 1103325 : walk_gimple_seq (seq, mark_local_labels_stmt, NULL, &wi);
6040 :
6041 1103325 : copy = gimple_seq_copy (seq);
6042 :
6043 : /* Walk the copy, remapping decls. */
6044 1103325 : memset (&wi, 0, sizeof (wi));
6045 1103325 : wi.info = &id;
6046 1103325 : walk_gimple_seq (copy, replace_locals_stmt, replace_locals_op, &wi);
6047 :
6048 : /* Clean up. */
6049 2206650 : delete id.decl_map;
6050 1103325 : if (id.debug_map)
6051 0 : delete id.debug_map;
6052 1103325 : if (id.dependence_map)
6053 : {
6054 0 : delete id.dependence_map;
6055 0 : id.dependence_map = NULL;
6056 : }
6057 :
6058 1103325 : return copy;
6059 1103325 : }
6060 :
6061 :
6062 : /* Declare the variables created by the inliner. Add all the variables in
6063 : VARS to BIND_EXPR. */
6064 :
6065 : static void
6066 7000994 : declare_inline_vars (tree block, tree vars)
6067 : {
6068 7000994 : tree t;
6069 17226783 : for (t = vars; t; t = DECL_CHAIN (t))
6070 : {
6071 10225789 : DECL_SEEN_IN_BIND_EXPR_P (t) = 1;
6072 10225789 : gcc_assert (!TREE_STATIC (t) && !TREE_ASM_WRITTEN (t));
6073 10225789 : add_local_decl (cfun, t);
6074 : }
6075 :
6076 7000994 : if (block)
6077 6918704 : BLOCK_VARS (block) = chainon (BLOCK_VARS (block), vars);
6078 7000994 : }
6079 :
6080 : /* Copy NODE (which must be a DECL). The DECL originally was in the FROM_FN,
6081 : but now it will be in the TO_FN. PARM_TO_VAR means enable PARM_DECL to
6082 : VAR_DECL translation. */
6083 :
6084 : tree
6085 138543961 : copy_decl_for_dup_finish (copy_body_data *id, tree decl, tree copy)
6086 : {
6087 : /* Don't generate debug information for the copy if we wouldn't have
6088 : generated it for the copy either. */
6089 138543961 : DECL_ARTIFICIAL (copy) = DECL_ARTIFICIAL (decl);
6090 138543961 : DECL_IGNORED_P (copy) = DECL_IGNORED_P (decl);
6091 :
6092 : /* Set the DECL_ABSTRACT_ORIGIN so the debugging routines know what
6093 : declaration inspired this copy. */
6094 171718350 : DECL_ABSTRACT_ORIGIN (copy) = DECL_ORIGIN (decl);
6095 :
6096 : /* The new variable/label has no RTL, yet. */
6097 138543961 : if (HAS_RTL_P (copy)
6098 138543961 : && !TREE_STATIC (copy) && !DECL_EXTERNAL (copy))
6099 138538998 : SET_DECL_RTL (copy, 0);
6100 : /* For vector typed decls make sure to update DECL_MODE according
6101 : to the new function context. */
6102 138543961 : if (VECTOR_TYPE_P (TREE_TYPE (copy)))
6103 338454 : SET_DECL_MODE (copy, TYPE_MODE (TREE_TYPE (copy)));
6104 :
6105 : /* These args would always appear unused, if not for this. */
6106 138543961 : TREE_USED (copy) = 1;
6107 :
6108 : /* Set the context for the new declaration. */
6109 138543961 : if (!DECL_CONTEXT (decl))
6110 : /* Globals stay global. */
6111 : ;
6112 138543810 : else if (DECL_CONTEXT (decl) != id->src_fn)
6113 : /* Things that weren't in the scope of the function we're inlining
6114 : from aren't in the scope we're inlining to, either. */
6115 : ;
6116 138541537 : else if (TREE_STATIC (decl))
6117 : /* Function-scoped static variables should stay in the original
6118 : function. */
6119 : ;
6120 : else
6121 : {
6122 : /* Ordinary automatic local variables are now in the scope of the
6123 : new function. */
6124 138538115 : DECL_CONTEXT (copy) = id->dst_fn;
6125 138538115 : if (VAR_P (copy) && id->dst_simt_vars && !is_gimple_reg (copy))
6126 : {
6127 0 : if (!lookup_attribute ("omp simt private", DECL_ATTRIBUTES (copy)))
6128 0 : DECL_ATTRIBUTES (copy)
6129 0 : = tree_cons (get_identifier ("omp simt private"), NULL,
6130 0 : DECL_ATTRIBUTES (copy));
6131 0 : id->dst_simt_vars->safe_push (copy);
6132 : }
6133 : }
6134 :
6135 138543961 : return copy;
6136 : }
6137 :
6138 : /* Create a new VAR_DECL that is identical in all respect to DECL except that
6139 : DECL can be either a VAR_DECL, a PARM_DECL or RESULT_DECL. The original
6140 : DECL must come from ID->src_fn and the copy will be part of ID->dst_fn. */
6141 :
6142 : tree
6143 8141136 : copy_decl_to_var (tree decl, copy_body_data *id)
6144 : {
6145 8141136 : tree copy, type;
6146 :
6147 8141136 : gcc_assert (TREE_CODE (decl) == PARM_DECL
6148 : || TREE_CODE (decl) == RESULT_DECL);
6149 :
6150 8141136 : type = TREE_TYPE (decl);
6151 :
6152 8141136 : copy = build_decl (DECL_SOURCE_LOCATION (id->dst_fn),
6153 8141136 : VAR_DECL, DECL_NAME (decl), type);
6154 8141136 : if (DECL_PT_UID_SET_P (decl))
6155 289 : SET_DECL_PT_UID (copy, DECL_PT_UID (decl));
6156 8141136 : TREE_ADDRESSABLE (copy) = TREE_ADDRESSABLE (decl);
6157 8141136 : TREE_READONLY (copy) = TREE_READONLY (decl);
6158 8141136 : TREE_THIS_VOLATILE (copy) = TREE_THIS_VOLATILE (decl);
6159 8141136 : DECL_NOT_GIMPLE_REG_P (copy) = DECL_NOT_GIMPLE_REG_P (decl);
6160 8141136 : DECL_BY_REFERENCE (copy) = DECL_BY_REFERENCE (decl);
6161 :
6162 8141136 : return copy_decl_for_dup_finish (id, decl, copy);
6163 : }
6164 :
6165 : /* Like copy_decl_to_var, but create a return slot object instead of a
6166 : pointer variable for return by invisible reference. */
6167 :
6168 : static tree
6169 2098864 : copy_result_decl_to_var (tree decl, copy_body_data *id)
6170 : {
6171 2098864 : tree copy, type;
6172 :
6173 2098864 : gcc_assert (TREE_CODE (decl) == PARM_DECL
6174 : || TREE_CODE (decl) == RESULT_DECL);
6175 :
6176 2098864 : type = TREE_TYPE (decl);
6177 2098864 : if (DECL_BY_REFERENCE (decl))
6178 136 : type = TREE_TYPE (type);
6179 :
6180 2098864 : copy = build_decl (DECL_SOURCE_LOCATION (id->dst_fn),
6181 2098864 : VAR_DECL, DECL_NAME (decl), type);
6182 2098864 : if (DECL_PT_UID_SET_P (decl))
6183 0 : SET_DECL_PT_UID (copy, DECL_PT_UID (decl));
6184 2098864 : TREE_READONLY (copy) = TREE_READONLY (decl);
6185 2098864 : TREE_THIS_VOLATILE (copy) = TREE_THIS_VOLATILE (decl);
6186 2098864 : if (!DECL_BY_REFERENCE (decl))
6187 : {
6188 2098728 : TREE_ADDRESSABLE (copy) = TREE_ADDRESSABLE (decl);
6189 2098728 : DECL_NOT_GIMPLE_REG_P (copy)
6190 4197456 : = (DECL_NOT_GIMPLE_REG_P (decl)
6191 : /* RESULT_DECLs are treated special by needs_to_live_in_memory,
6192 : mirror that to the created VAR_DECL. */
6193 2098728 : || (TREE_CODE (decl) == RESULT_DECL
6194 2098561 : && aggregate_value_p (decl, id->src_fn)));
6195 : }
6196 :
6197 2098864 : return copy_decl_for_dup_finish (id, decl, copy);
6198 : }
6199 :
6200 : tree
6201 128303789 : copy_decl_no_change (tree decl, copy_body_data *id)
6202 : {
6203 128303789 : tree copy;
6204 :
6205 128303789 : copy = copy_node (decl);
6206 :
6207 : /* The COPY is not abstract; it will be generated in DST_FN. */
6208 128303789 : DECL_ABSTRACT_P (copy) = false;
6209 128303789 : lang_hooks.dup_lang_specific_decl (copy);
6210 :
6211 : /* TREE_ADDRESSABLE isn't used to indicate that a label's address has
6212 : been taken; it's for internal bookkeeping in expand_goto_internal. */
6213 128303789 : if (TREE_CODE (copy) == LABEL_DECL)
6214 : {
6215 1665851 : TREE_ADDRESSABLE (copy) = 0;
6216 1665851 : LABEL_DECL_UID (copy) = -1;
6217 : }
6218 :
6219 128303789 : return copy_decl_for_dup_finish (id, decl, copy);
6220 : }
6221 :
6222 : static tree
6223 24502715 : copy_decl_maybe_to_var (tree decl, copy_body_data *id)
6224 : {
6225 24502715 : if (TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL)
6226 14211 : return copy_decl_to_var (decl, id);
6227 : else
6228 24488504 : return copy_decl_no_change (decl, id);
6229 : }
6230 :
6231 : /* Return a copy of the function's argument tree without any modifications. */
6232 :
6233 : static tree
6234 79806 : copy_arguments_nochange (tree orig_parm, copy_body_data * id)
6235 : {
6236 79806 : tree arg, *parg;
6237 79806 : tree new_parm = NULL;
6238 :
6239 79806 : parg = &new_parm;
6240 241183 : for (arg = orig_parm; arg; arg = DECL_CHAIN (arg))
6241 : {
6242 161377 : tree new_tree = remap_decl (arg, id);
6243 161377 : if (TREE_CODE (new_tree) != PARM_DECL)
6244 3837 : new_tree = id->copy_decl (arg, id);
6245 161377 : lang_hooks.dup_lang_specific_decl (new_tree);
6246 161377 : *parg = new_tree;
6247 161377 : parg = &DECL_CHAIN (new_tree);
6248 : }
6249 79806 : return new_parm;
6250 : }
6251 :
6252 : /* Return a copy of the function's static chain. */
6253 : static tree
6254 937 : copy_static_chain (tree static_chain, copy_body_data * id)
6255 : {
6256 937 : tree *chain_copy, *pvar;
6257 :
6258 937 : chain_copy = &static_chain;
6259 1874 : for (pvar = chain_copy; *pvar; pvar = &DECL_CHAIN (*pvar))
6260 : {
6261 937 : tree new_tree = remap_decl (*pvar, id);
6262 937 : lang_hooks.dup_lang_specific_decl (new_tree);
6263 937 : DECL_CHAIN (new_tree) = DECL_CHAIN (*pvar);
6264 937 : *pvar = new_tree;
6265 : }
6266 937 : return static_chain;
6267 : }
6268 :
6269 : /* Return true if the function is allowed to be versioned.
6270 : This is a guard for the versioning functionality. */
6271 :
6272 : bool
6273 12906144 : tree_versionable_function_p (tree fndecl)
6274 : {
6275 12906144 : return (!lookup_attribute ("noclone", DECL_ATTRIBUTES (fndecl))
6276 25538789 : && copy_forbidden (DECL_STRUCT_FUNCTION (fndecl)) == NULL);
6277 : }
6278 :
6279 : /* Update clone info after duplication. */
6280 :
6281 : static void
6282 254443 : update_clone_info (copy_body_data * id)
6283 : {
6284 254443 : struct cgraph_node *this_node = id->dst_node;
6285 254443 : if (!this_node->clones)
6286 : return;
6287 656723 : for (cgraph_node *node = this_node->clones; node != this_node;)
6288 : {
6289 : /* First update replace maps to match the new body. */
6290 572066 : clone_info *info = clone_info::get (node);
6291 572066 : if (info && info->tree_map)
6292 : {
6293 : unsigned int i;
6294 0 : for (i = 0; i < vec_safe_length (info->tree_map); i++)
6295 : {
6296 0 : struct ipa_replace_map *replace_info;
6297 0 : replace_info = (*info->tree_map)[i];
6298 0 : walk_tree (&replace_info->new_tree, copy_tree_body_r, id, NULL);
6299 : }
6300 : }
6301 :
6302 572066 : if (node->clones)
6303 : node = node->clones;
6304 546930 : else if (node->next_sibling_clone)
6305 : node = node->next_sibling_clone;
6306 : else
6307 : {
6308 207345 : while (node != id->dst_node && !node->next_sibling_clone)
6309 109793 : node = node->clone_of;
6310 97552 : if (node != id->dst_node)
6311 12895 : node = node->next_sibling_clone;
6312 : }
6313 : }
6314 : }
6315 :
6316 : /* Create a copy of a function's tree.
6317 : OLD_DECL and NEW_DECL are FUNCTION_DECL tree nodes
6318 : of the original function and the new copied function
6319 : respectively. In case we want to replace a DECL
6320 : tree with another tree while duplicating the function's
6321 : body, TREE_MAP represents the mapping between these
6322 : trees. If UPDATE_CLONES is set, the call_stmt fields
6323 : of edges of clones of the function will be updated.
6324 :
6325 : If non-NULL PARAM_ADJUSTMENTS determines how function prototype (i.e. the
6326 : function parameters and return value) should be modified).
6327 : If non-NULL BLOCKS_TO_COPY determine what basic blocks to copy.
6328 : If non_NULL NEW_ENTRY determine new entry BB of the clone.
6329 : */
6330 : void
6331 254443 : tree_function_versioning (tree old_decl, tree new_decl,
6332 : vec<ipa_replace_map *, va_gc> *tree_map,
6333 : ipa_param_adjustments *param_adjustments,
6334 : bool update_clones, bitmap blocks_to_copy,
6335 : basic_block new_entry)
6336 : {
6337 254443 : struct cgraph_node *old_version_node;
6338 254443 : struct cgraph_node *new_version_node;
6339 254443 : copy_body_data id;
6340 254443 : tree p;
6341 254443 : unsigned i;
6342 254443 : struct ipa_replace_map *replace_info;
6343 254443 : basic_block old_entry_block, bb;
6344 254443 : auto_vec<gimple *, 10> init_stmts;
6345 254443 : tree vars = NULL_TREE;
6346 :
6347 : /* We can get called recursively from expand_call_inline via clone
6348 : materialization. While expand_call_inline maintains input_location
6349 : we cannot tolerate it to leak into the materialized clone. */
6350 254443 : location_t saved_location = input_location;
6351 254443 : input_location = UNKNOWN_LOCATION;
6352 :
6353 254443 : gcc_assert (TREE_CODE (old_decl) == FUNCTION_DECL
6354 : && TREE_CODE (new_decl) == FUNCTION_DECL);
6355 254443 : DECL_POSSIBLY_INLINED (old_decl) = 1;
6356 :
6357 254443 : old_version_node = cgraph_node::get (old_decl);
6358 254443 : gcc_checking_assert (old_version_node);
6359 254443 : new_version_node = cgraph_node::get (new_decl);
6360 254443 : gcc_checking_assert (new_version_node);
6361 :
6362 : /* Copy over debug args. */
6363 254443 : if (DECL_HAS_DEBUG_ARGS_P (old_decl))
6364 : {
6365 4041 : vec<tree, va_gc> **new_debug_args, **old_debug_args;
6366 4041 : gcc_checking_assert (decl_debug_args_lookup (new_decl) == NULL);
6367 4041 : DECL_HAS_DEBUG_ARGS_P (new_decl) = 0;
6368 4041 : old_debug_args = decl_debug_args_lookup (old_decl);
6369 4041 : if (old_debug_args)
6370 : {
6371 4041 : new_debug_args = decl_debug_args_insert (new_decl);
6372 8082 : *new_debug_args = vec_safe_copy (*old_debug_args);
6373 : }
6374 : }
6375 :
6376 : /* Output the inlining info for this abstract function, since it has been
6377 : inlined. If we don't do this now, we can lose the information about the
6378 : variables in the function when the blocks get blown away as soon as we
6379 : remove the cgraph node. */
6380 254443 : (*debug_hooks->outlining_inline_function) (old_decl);
6381 :
6382 254443 : DECL_ARTIFICIAL (new_decl) = 1;
6383 462079 : DECL_ABSTRACT_ORIGIN (new_decl) = DECL_ORIGIN (old_decl);
6384 462079 : if (DECL_ORIGIN (old_decl) == old_decl)
6385 225815 : old_version_node->used_as_abstract_origin = true;
6386 254443 : DECL_FUNCTION_PERSONALITY (new_decl) = DECL_FUNCTION_PERSONALITY (old_decl);
6387 :
6388 : /* Prepare the data structures for the tree copy. */
6389 254443 : memset (&id, 0, sizeof (id));
6390 :
6391 : /* Generate a new name for the new version. */
6392 254443 : id.statements_to_fold = new hash_set<gimple *>;
6393 :
6394 254443 : id.decl_map = new hash_map<tree, tree>;
6395 254443 : id.debug_map = NULL;
6396 254443 : id.src_fn = old_decl;
6397 254443 : id.dst_fn = new_decl;
6398 254443 : id.src_node = old_version_node;
6399 254443 : id.dst_node = new_version_node;
6400 254443 : id.src_cfun = DECL_STRUCT_FUNCTION (old_decl);
6401 254443 : id.blocks_to_copy = blocks_to_copy;
6402 :
6403 254443 : id.copy_decl = copy_decl_no_change;
6404 254443 : id.transform_call_graph_edges
6405 254443 : = update_clones ? CB_CGE_MOVE_CLONES : CB_CGE_MOVE;
6406 254443 : id.transform_new_cfg = true;
6407 254443 : id.transform_return_to_modify = false;
6408 254443 : id.transform_parameter = false;
6409 :
6410 254443 : old_entry_block = ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (old_decl));
6411 254443 : DECL_RESULT (new_decl) = DECL_RESULT (old_decl);
6412 254443 : DECL_ARGUMENTS (new_decl) = DECL_ARGUMENTS (old_decl);
6413 254443 : initialize_cfun (new_decl, old_decl,
6414 254443 : new_entry ? new_entry->count : old_entry_block->count);
6415 254443 : new_version_node->has_omp_variant_constructs
6416 254443 : = old_version_node->has_omp_variant_constructs;
6417 254443 : if (DECL_STRUCT_FUNCTION (new_decl)->gimple_df)
6418 254443 : DECL_STRUCT_FUNCTION (new_decl)->gimple_df->ipa_pta
6419 254443 : = id.src_cfun->gimple_df->ipa_pta;
6420 :
6421 : /* Copy the function's static chain. */
6422 254443 : p = DECL_STRUCT_FUNCTION (old_decl)->static_chain_decl;
6423 254443 : if (p)
6424 1874 : DECL_STRUCT_FUNCTION (new_decl)->static_chain_decl
6425 937 : = copy_static_chain (p, &id);
6426 :
6427 254443 : auto_vec<int, 16> new_param_indices;
6428 254443 : clone_info *info = clone_info::get (old_version_node);
6429 261280 : ipa_param_adjustments *old_param_adjustments
6430 254443 : = info ? info->param_adjustments : NULL;
6431 6837 : if (old_param_adjustments)
6432 6752 : old_param_adjustments->get_updated_indices (&new_param_indices);
6433 :
6434 : /* If there's a tree_map, prepare for substitution. */
6435 254443 : if (tree_map)
6436 38311 : for (i = 0; i < tree_map->length (); i++)
6437 : {
6438 24295 : gimple *init;
6439 24295 : replace_info = (*tree_map)[i];
6440 :
6441 24295 : int p = replace_info->parm_num;
6442 24295 : if (old_param_adjustments)
6443 0 : p = new_param_indices[p];
6444 :
6445 24295 : tree parm;
6446 70392 : for (parm = DECL_ARGUMENTS (old_decl); p;
6447 46097 : parm = DECL_CHAIN (parm))
6448 46097 : p--;
6449 24295 : gcc_assert (parm);
6450 24295 : init = setup_one_parameter (&id, parm, replace_info->new_tree,
6451 : id.src_fn, NULL, &vars);
6452 24295 : if (init)
6453 7150 : init_stmts.safe_push (init);
6454 : }
6455 :
6456 254443 : ipa_param_body_adjustments *param_body_adjs = NULL;
6457 254443 : if (param_adjustments)
6458 : {
6459 337252 : param_body_adjs = new ipa_param_body_adjustments (param_adjustments,
6460 : new_decl, old_decl,
6461 168626 : &id, &vars, tree_map);
6462 168626 : id.param_body_adjs = param_body_adjs;
6463 168626 : DECL_ARGUMENTS (new_decl) = param_body_adjs->get_new_param_chain ();
6464 : }
6465 85817 : else if (DECL_ARGUMENTS (old_decl) != NULL_TREE)
6466 159612 : DECL_ARGUMENTS (new_decl)
6467 79806 : = copy_arguments_nochange (DECL_ARGUMENTS (old_decl), &id);
6468 :
6469 254443 : DECL_INITIAL (new_decl) = remap_blocks (DECL_INITIAL (id.src_fn), &id);
6470 254443 : BLOCK_SUPERCONTEXT (DECL_INITIAL (new_decl)) = new_decl;
6471 :
6472 254443 : declare_inline_vars (DECL_INITIAL (new_decl), vars);
6473 :
6474 254443 : if (!vec_safe_is_empty (DECL_STRUCT_FUNCTION (old_decl)->local_decls))
6475 : /* Add local vars. */
6476 151575 : add_local_variables (DECL_STRUCT_FUNCTION (old_decl), cfun, &id);
6477 :
6478 254443 : if (DECL_RESULT (old_decl) == NULL_TREE)
6479 : ;
6480 168626 : else if (param_adjustments && param_adjustments->m_skip_return
6481 307711 : && !VOID_TYPE_P (TREE_TYPE (DECL_RESULT (old_decl))))
6482 : {
6483 45740 : tree resdecl_repl = copy_result_decl_to_var (DECL_RESULT (old_decl),
6484 : &id);
6485 45740 : declare_inline_vars (NULL, resdecl_repl);
6486 45740 : if (DECL_BY_REFERENCE (DECL_RESULT (old_decl)))
6487 136 : resdecl_repl = build_fold_addr_expr (resdecl_repl);
6488 45740 : insert_decl_map (&id, DECL_RESULT (old_decl), resdecl_repl);
6489 :
6490 91480 : DECL_RESULT (new_decl)
6491 45740 : = build_decl (DECL_SOURCE_LOCATION (DECL_RESULT (old_decl)),
6492 : RESULT_DECL, NULL_TREE, void_type_node);
6493 45740 : DECL_CONTEXT (DECL_RESULT (new_decl)) = new_decl;
6494 45740 : DECL_IS_MALLOC (new_decl) = false;
6495 45740 : cfun->returns_struct = 0;
6496 45740 : cfun->returns_pcc_struct = 0;
6497 : }
6498 : else
6499 : {
6500 208703 : tree old_name;
6501 208703 : DECL_RESULT (new_decl) = remap_decl (DECL_RESULT (old_decl), &id);
6502 208703 : lang_hooks.dup_lang_specific_decl (DECL_RESULT (new_decl));
6503 417406 : if (gimple_in_ssa_p (id.src_cfun)
6504 208703 : && DECL_BY_REFERENCE (DECL_RESULT (old_decl))
6505 4750 : && (old_name = ssa_default_def (id.src_cfun, DECL_RESULT (old_decl))))
6506 : {
6507 4731 : tree new_name = make_ssa_name (DECL_RESULT (new_decl));
6508 4731 : insert_decl_map (&id, old_name, new_name);
6509 4731 : SSA_NAME_DEF_STMT (new_name) = gimple_build_nop ();
6510 4731 : set_ssa_default_def (cfun, DECL_RESULT (new_decl), new_name);
6511 : }
6512 : }
6513 :
6514 : /* Set up the destination functions loop tree. */
6515 254443 : if (loops_for_fn (DECL_STRUCT_FUNCTION (old_decl)) != NULL)
6516 : {
6517 254443 : cfun->curr_properties &= ~PROP_loops;
6518 254443 : loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
6519 254443 : cfun->curr_properties |= PROP_loops;
6520 : }
6521 :
6522 : /* Copy the Function's body. */
6523 254443 : copy_body (&id, ENTRY_BLOCK_PTR_FOR_FN (cfun), EXIT_BLOCK_PTR_FOR_FN (cfun),
6524 : new_entry);
6525 :
6526 : /* Renumber the lexical scoping (non-code) blocks consecutively. */
6527 254443 : number_blocks (new_decl);
6528 :
6529 : /* We want to create the BB unconditionally, so that the addition of
6530 : debug stmts doesn't affect BB count, which may in the end cause
6531 : codegen differences. */
6532 254443 : bb = split_edge (single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
6533 516036 : while (init_stmts.length ())
6534 7150 : insert_init_stmt (&id, bb, init_stmts.pop ());
6535 254443 : if (param_body_adjs)
6536 168626 : param_body_adjs->append_init_stmts (bb);
6537 254443 : update_clone_info (&id);
6538 :
6539 : /* Remap the nonlocal_goto_save_area, if any. */
6540 254443 : if (cfun->nonlocal_goto_save_area)
6541 : {
6542 0 : struct walk_stmt_info wi;
6543 :
6544 0 : memset (&wi, 0, sizeof (wi));
6545 0 : wi.info = &id;
6546 0 : walk_tree (&cfun->nonlocal_goto_save_area, remap_gimple_op_r, &wi, NULL);
6547 : }
6548 :
6549 : /* Clean up. */
6550 508886 : delete id.decl_map;
6551 254443 : if (id.debug_map)
6552 1217 : delete id.debug_map;
6553 254443 : free_dominance_info (CDI_DOMINATORS);
6554 254443 : free_dominance_info (CDI_POST_DOMINATORS);
6555 :
6556 254443 : update_max_bb_count ();
6557 254443 : fold_marked_statements (0, id.statements_to_fold);
6558 508886 : delete id.statements_to_fold;
6559 254443 : delete_unreachable_blocks_update_callgraph (id.dst_node, update_clones);
6560 254443 : if (id.dst_node->definition)
6561 250137 : cgraph_edge::rebuild_references ();
6562 254443 : if (loops_state_satisfies_p (LOOPS_NEED_FIXUP))
6563 : {
6564 254443 : calculate_dominance_info (CDI_DOMINATORS);
6565 254443 : fix_loop_structure (NULL);
6566 : }
6567 254443 : update_ssa (TODO_update_ssa);
6568 :
6569 : /* After partial cloning we need to rescale frequencies, so they are
6570 : within proper range in the cloned function. */
6571 254443 : if (new_entry)
6572 : {
6573 52638 : struct cgraph_edge *e;
6574 52638 : rebuild_frequencies ();
6575 :
6576 52638 : new_version_node->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
6577 236542 : for (e = new_version_node->callees; e; e = e->next_callee)
6578 : {
6579 183904 : basic_block bb = gimple_bb (e->call_stmt);
6580 183904 : e->count = bb->count;
6581 : }
6582 57760 : for (e = new_version_node->indirect_calls; e; e = e->next_callee)
6583 : {
6584 5122 : basic_block bb = gimple_bb (e->call_stmt);
6585 5122 : e->count = bb->count;
6586 : }
6587 : }
6588 :
6589 254443 : if (param_body_adjs && MAY_HAVE_DEBUG_BIND_STMTS)
6590 : {
6591 145480 : vec<tree, va_gc> **debug_args = NULL;
6592 145480 : unsigned int len = 0;
6593 145480 : unsigned reset_len = param_body_adjs->m_reset_debug_decls.length ();
6594 :
6595 260950 : for (i = 0; i < reset_len; i++)
6596 : {
6597 115470 : tree parm = param_body_adjs->m_reset_debug_decls[i];
6598 115470 : gcc_assert (is_gimple_reg (parm));
6599 115470 : tree ddecl;
6600 :
6601 115470 : if (debug_args == NULL)
6602 : {
6603 87922 : debug_args = decl_debug_args_insert (new_decl);
6604 87922 : len = vec_safe_length (*debug_args);
6605 : }
6606 115470 : ddecl = build_debug_expr_decl (TREE_TYPE (parm));
6607 : /* FIXME: Is setting the mode really necessary? */
6608 115470 : SET_DECL_MODE (ddecl, DECL_MODE (parm));
6609 115470 : vec_safe_push (*debug_args, DECL_ORIGIN (parm));
6610 115470 : vec_safe_push (*debug_args, ddecl);
6611 : }
6612 145480 : if (debug_args != NULL)
6613 : {
6614 : /* On the callee side, add
6615 : DEBUG D#Y s=> parm
6616 : DEBUG var => D#Y
6617 : stmts to the first bb where var is a VAR_DECL created for the
6618 : optimized away parameter in DECL_INITIAL block. This hints
6619 : in the debug info that var (whole DECL_ORIGIN is the parm
6620 : PARM_DECL) is optimized away, but could be looked up at the
6621 : call site as value of D#X there. */
6622 87922 : gimple_stmt_iterator cgsi
6623 87922 : = gsi_after_labels (single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
6624 87922 : gimple *def_temp;
6625 87922 : tree var = vars;
6626 87922 : i = vec_safe_length (*debug_args);
6627 115470 : do
6628 : {
6629 115470 : tree vexpr = NULL_TREE;
6630 115470 : i -= 2;
6631 115470 : while (var != NULL_TREE
6632 152074 : && DECL_ABSTRACT_ORIGIN (var) != (**debug_args)[i])
6633 36604 : var = TREE_CHAIN (var);
6634 115470 : if (var == NULL_TREE)
6635 : break;
6636 115470 : tree parm = (**debug_args)[i];
6637 115470 : if (tree parm_ddef = ssa_default_def (id.src_cfun, parm))
6638 154276 : if (tree *d
6639 77138 : = param_body_adjs->m_dead_ssa_debug_equiv.get (parm_ddef))
6640 30964 : vexpr = *d;
6641 115470 : if (!vexpr)
6642 : {
6643 84506 : vexpr = build_debug_expr_decl (TREE_TYPE (parm));
6644 : /* FIXME: Is setting the mode really necessary? */
6645 84506 : SET_DECL_MODE (vexpr, DECL_MODE (parm));
6646 : }
6647 115470 : def_temp = gimple_build_debug_bind (var, vexpr, NULL);
6648 115470 : gsi_insert_before (&cgsi, def_temp, GSI_NEW_STMT);
6649 115470 : def_temp = gimple_build_debug_source_bind (vexpr, parm, NULL);
6650 115470 : gsi_insert_before (&cgsi, def_temp, GSI_NEW_STMT);
6651 : }
6652 115470 : while (i > len);
6653 : }
6654 : }
6655 168626 : delete param_body_adjs;
6656 254443 : free_dominance_info (CDI_DOMINATORS);
6657 254443 : free_dominance_info (CDI_POST_DOMINATORS);
6658 :
6659 254443 : gcc_assert (!id.debug_stmts.exists ());
6660 254443 : pop_cfun ();
6661 254443 : input_location = saved_location;
6662 254443 : return;
6663 254443 : }
6664 :
6665 : /* EXP is CALL_EXPR present in a GENERIC expression tree. Try to integrate
6666 : the callee and return the inlined body on success. */
6667 :
6668 : tree
6669 0 : maybe_inline_call_in_expr (tree exp)
6670 : {
6671 0 : tree fn = get_callee_fndecl (exp);
6672 :
6673 : /* We can only try to inline "const" functions. */
6674 0 : if (fn && TREE_READONLY (fn) && DECL_SAVED_TREE (fn))
6675 : {
6676 0 : call_expr_arg_iterator iter;
6677 0 : copy_body_data id;
6678 0 : tree param, arg, t;
6679 0 : hash_map<tree, tree> decl_map;
6680 :
6681 : /* Remap the parameters. */
6682 0 : for (param = DECL_ARGUMENTS (fn), arg = first_call_expr_arg (exp, &iter);
6683 0 : param;
6684 0 : param = DECL_CHAIN (param), arg = next_call_expr_arg (&iter))
6685 0 : decl_map.put (param, arg);
6686 :
6687 0 : memset (&id, 0, sizeof (id));
6688 0 : id.src_fn = fn;
6689 0 : id.dst_fn = current_function_decl;
6690 0 : id.src_cfun = DECL_STRUCT_FUNCTION (fn);
6691 0 : id.decl_map = &decl_map;
6692 :
6693 0 : id.copy_decl = copy_decl_no_change;
6694 0 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
6695 0 : id.transform_new_cfg = false;
6696 0 : id.transform_return_to_modify = true;
6697 0 : id.transform_parameter = true;
6698 :
6699 : /* Make sure not to unshare trees behind the front-end's back
6700 : since front-end specific mechanisms may rely on sharing. */
6701 0 : id.regimplify = false;
6702 0 : id.do_not_unshare = true;
6703 :
6704 : /* We're not inside any EH region. */
6705 0 : id.eh_lp_nr = 0;
6706 :
6707 0 : t = copy_tree_body (&id);
6708 :
6709 : /* We can only return something suitable for use in a GENERIC
6710 : expression tree. */
6711 0 : if (TREE_CODE (t) == MODIFY_EXPR)
6712 0 : return TREE_OPERAND (t, 1);
6713 0 : }
6714 :
6715 : return NULL_TREE;
6716 : }
6717 :
6718 : /* Duplicate a type, fields and all. */
6719 :
6720 : tree
6721 63 : build_duplicate_type (tree type)
6722 : {
6723 63 : struct copy_body_data id;
6724 :
6725 63 : memset (&id, 0, sizeof (id));
6726 63 : id.src_fn = current_function_decl;
6727 63 : id.dst_fn = current_function_decl;
6728 63 : id.src_cfun = cfun;
6729 63 : id.decl_map = new hash_map<tree, tree>;
6730 63 : id.debug_map = NULL;
6731 63 : id.copy_decl = copy_decl_no_change;
6732 :
6733 63 : type = remap_type_1 (type, &id);
6734 :
6735 126 : delete id.decl_map;
6736 63 : if (id.debug_map)
6737 0 : delete id.debug_map;
6738 :
6739 63 : TYPE_CANONICAL (type) = type;
6740 :
6741 63 : return type;
6742 : }
6743 :
6744 : /* Unshare the entire DECL_SAVED_TREE of FN and return the remapped
6745 : parameters and RESULT_DECL in PARMS and RESULT. Used by C++ constexpr
6746 : evaluation. */
6747 :
6748 : tree
6749 31053102 : copy_fn (tree fn, tree& parms, tree& result)
6750 : {
6751 31053102 : copy_body_data id;
6752 31053102 : tree param;
6753 31053102 : hash_map<tree, tree> decl_map;
6754 :
6755 31053102 : tree *p = &parms;
6756 31053102 : *p = NULL_TREE;
6757 :
6758 31053102 : memset (&id, 0, sizeof (id));
6759 31053102 : id.src_fn = fn;
6760 31053102 : id.dst_fn = current_function_decl;
6761 31053102 : id.src_cfun = DECL_STRUCT_FUNCTION (fn);
6762 31053102 : id.decl_map = &decl_map;
6763 :
6764 130546560 : id.copy_decl = [] (tree decl, copy_body_data *id)
6765 : {
6766 99493458 : if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
6767 : /* Don't make copies of local types or injected enumerators,
6768 : the C++ constexpr evaluator doesn't need them and they
6769 : confuse modules streaming. */
6770 : return decl;
6771 97331411 : return copy_decl_no_change (decl, id);
6772 : };
6773 31053102 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
6774 31053102 : id.transform_new_cfg = false;
6775 31053102 : id.transform_return_to_modify = false;
6776 31053102 : id.transform_parameter = true;
6777 :
6778 : /* Make sure not to unshare trees behind the front-end's back
6779 : since front-end specific mechanisms may rely on sharing. */
6780 31053102 : id.regimplify = false;
6781 31053102 : id.do_not_unshare = true;
6782 31053102 : id.do_not_fold = true;
6783 :
6784 : /* We're not inside any EH region. */
6785 31053102 : id.eh_lp_nr = 0;
6786 :
6787 : /* Remap the parameters and result and return them to the caller. */
6788 31053102 : for (param = DECL_ARGUMENTS (fn);
6789 74911942 : param;
6790 43858840 : param = DECL_CHAIN (param))
6791 : {
6792 43858840 : *p = remap_decl (param, &id);
6793 43858840 : p = &DECL_CHAIN (*p);
6794 : }
6795 :
6796 31053102 : if (DECL_RESULT (fn))
6797 31053102 : result = remap_decl (DECL_RESULT (fn), &id);
6798 : else
6799 0 : result = NULL_TREE;
6800 :
6801 31053102 : return copy_tree_body (&id);
6802 31053102 : }
|