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