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 : 438963830 : insert_decl_map (copy_body_data *id, tree key, tree value)
147 : : {
148 : 438963830 : 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 : 438963830 : if (key != value && value)
153 : 147056979 : id->decl_map->put (value, value);
154 : 438963830 : }
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 : 65233060 : remap_ssa_name (tree name, copy_body_data *id)
166 : : {
167 : 65233060 : tree new_tree, var;
168 : 65233060 : tree *n;
169 : :
170 : 65233060 : gcc_assert (TREE_CODE (name) == SSA_NAME);
171 : :
172 : 65233060 : n = id->decl_map->get (name);
173 : 65233060 : 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 : 47662863 : if (id->killed_new_ssa_names
180 : 47662863 : && id->killed_new_ssa_names->contains (*n))
181 : : {
182 : 967 : gcc_assert (processing_debug_stmt);
183 : 967 : processing_debug_stmt = -1;
184 : 967 : return name;
185 : : }
186 : :
187 : 47661896 : return unshare_expr (*n);
188 : : }
189 : :
190 : 17570197 : if (processing_debug_stmt)
191 : : {
192 : 103985 : if (SSA_NAME_IS_DEFAULT_DEF (name)
193 : 103924 : && TREE_CODE (SSA_NAME_VAR (name)) == PARM_DECL
194 : 103877 : && id->entry_bb == NULL
195 : 207861 : && single_succ_p (ENTRY_BLOCK_PTR_FOR_FN (cfun)))
196 : : {
197 : 103876 : gimple *def_temp;
198 : 103876 : gimple_stmt_iterator gsi;
199 : 103876 : tree val = SSA_NAME_VAR (name);
200 : :
201 : 103876 : n = id->decl_map->get (val);
202 : 103876 : if (n != NULL)
203 : 103876 : val = *n;
204 : 103876 : if (TREE_CODE (val) != PARM_DECL
205 : 103876 : && !(VAR_P (val) && DECL_ABSTRACT_ORIGIN (val)))
206 : : {
207 : 0 : processing_debug_stmt = -1;
208 : 0 : return name;
209 : : }
210 : 103876 : n = id->decl_map->get (val);
211 : 103876 : if (n && TREE_CODE (*n) == DEBUG_EXPR_DECL)
212 : : return *n;
213 : 35165 : tree vexpr = build_debug_expr_decl (TREE_TYPE (name));
214 : : /* FIXME: Is setting the mode really necessary? */
215 : 35165 : SET_DECL_MODE (vexpr, DECL_MODE (SSA_NAME_VAR (name)));
216 : 35165 : def_temp = gimple_build_debug_source_bind (vexpr, val, NULL);
217 : 35165 : gsi = gsi_after_labels (single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
218 : 35165 : gsi_insert_before (&gsi, def_temp, GSI_SAME_STMT);
219 : 35165 : insert_decl_map (id, val, vexpr);
220 : 35165 : return vexpr;
221 : : }
222 : :
223 : 109 : processing_debug_stmt = -1;
224 : 109 : return name;
225 : : }
226 : :
227 : : /* Remap anonymous SSA names or SSA names of anonymous decls. */
228 : 17466212 : var = SSA_NAME_VAR (name);
229 : 3509690 : if (!var
230 : 3509690 : || (!SSA_NAME_IS_DEFAULT_DEF (name)
231 : 3145935 : && VAR_P (var)
232 : 2946259 : && !VAR_DECL_IS_VIRTUAL_OPERAND (var)
233 : 2946259 : && DECL_ARTIFICIAL (var)
234 : 517132 : && DECL_IGNORED_P (var)
235 : 193776 : && !DECL_NAME (var)))
236 : : {
237 : 13961798 : struct ptr_info_def *pi;
238 : 13961798 : new_tree = make_ssa_name (remap_type (TREE_TYPE (name), id));
239 : 13961798 : if (!var && SSA_NAME_IDENTIFIER (name))
240 : 1800214 : SET_SSA_NAME_VAR_OR_IDENTIFIER (new_tree, SSA_NAME_IDENTIFIER (name));
241 : 13961798 : insert_decl_map (id, name, new_tree);
242 : 27923596 : SSA_NAME_OCCURS_IN_ABNORMAL_PHI (new_tree)
243 : 13961798 : = SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name);
244 : : /* At least IPA points-to info can be directly transferred. */
245 : 13961798 : if (id->src_cfun->gimple_df
246 : 13961798 : && id->src_cfun->gimple_df->ipa_pta
247 : 14760 : && POINTER_TYPE_P (TREE_TYPE (name))
248 : 2605 : && (pi = SSA_NAME_PTR_INFO (name))
249 : 13964398 : && !pi->pt.anything)
250 : : {
251 : 2579 : struct ptr_info_def *new_pi = get_ptr_info (new_tree);
252 : 2579 : new_pi->pt = pi->pt;
253 : : }
254 : : /* So can range-info. */
255 : 23056339 : if (!POINTER_TYPE_P (TREE_TYPE (name))
256 : 22524116 : && SSA_NAME_RANGE_INFO (name))
257 : 3065649 : duplicate_ssa_name_range_info (new_tree, name);
258 : 13961798 : 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 : 3504414 : 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 : 347688 : if ((VAR_P (new_tree) || TREE_CODE (new_tree) == PARM_DECL)
272 : 3852102 : && (!SSA_NAME_VAR (name)
273 : 3504414 : || TREE_CODE (SSA_NAME_VAR (name)) != RESULT_DECL
274 : 0 : || !id->transform_return_to_modify))
275 : : {
276 : 3504414 : struct ptr_info_def *pi;
277 : 3504414 : new_tree = make_ssa_name (new_tree);
278 : 3504414 : insert_decl_map (id, name, new_tree);
279 : 7008828 : SSA_NAME_OCCURS_IN_ABNORMAL_PHI (new_tree)
280 : 3504414 : = SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name);
281 : : /* At least IPA points-to info can be directly transferred. */
282 : 3504414 : if (id->src_cfun->gimple_df
283 : 3504414 : && id->src_cfun->gimple_df->ipa_pta
284 : 2514 : && POINTER_TYPE_P (TREE_TYPE (name))
285 : 283 : && (pi = SSA_NAME_PTR_INFO (name))
286 : 3504692 : && !pi->pt.anything)
287 : : {
288 : 278 : struct ptr_info_def *new_pi = get_ptr_info (new_tree);
289 : 278 : new_pi->pt = pi->pt;
290 : : }
291 : : /* So can range-info. */
292 : 6205728 : if (!POINTER_TYPE_P (TREE_TYPE (name))
293 : 6121238 : && SSA_NAME_RANGE_INFO (name))
294 : 966143 : duplicate_ssa_name_range_info (new_tree, name);
295 : 3504414 : 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 : 363755 : if (id->entry_bb
307 : 41122 : && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name)
308 : 0 : && (!SSA_NAME_VAR (name)
309 : 0 : || TREE_CODE (SSA_NAME_VAR (name)) != PARM_DECL)
310 : 363755 : && (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 : 363755 : SSA_NAME_DEF_STMT (new_tree) = gimple_build_nop ();
325 : 363755 : 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 : 218502523 : remap_decl (tree decl, copy_body_data *id)
338 : : {
339 : 218502523 : tree *n;
340 : :
341 : : /* We only remap local variables in the current function. */
342 : :
343 : : /* See if we have remapped this declaration. */
344 : :
345 : 218502523 : n = id->decl_map->get (decl);
346 : :
347 : 218502523 : if (!n && processing_debug_stmt)
348 : : {
349 : 701499 : processing_debug_stmt = -1;
350 : 701499 : 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 : 77026041 : if (!n
357 : 77026041 : && 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 : 217801024 : if (!n)
365 : : {
366 : : /* Make a copy of the variable or label. */
367 : 77026041 : 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 : 77026041 : insert_decl_map (id, decl, t);
373 : :
374 : 77026041 : if (!DECL_P (t) || t == decl)
375 : : return t;
376 : :
377 : : /* Remap types, if necessary. */
378 : 75663565 : TREE_TYPE (t) = remap_type (TREE_TYPE (t), id);
379 : 75663565 : if (TREE_CODE (t) == TYPE_DECL)
380 : : {
381 : 1634528 : 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 : 1634528 : 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 : 75663565 : walk_tree (&DECL_SIZE (t), copy_tree_body_r, id, NULL);
397 : 75663565 : walk_tree (&DECL_SIZE_UNIT (t), copy_tree_body_r, id, NULL);
398 : :
399 : : /* If fields, do likewise for offset and qualifier. */
400 : 75663565 : if (TREE_CODE (t) == FIELD_DECL)
401 : : {
402 : 764 : walk_tree (&DECL_FIELD_OFFSET (t), copy_tree_body_r, id, NULL);
403 : 764 : if (TREE_CODE (DECL_CONTEXT (t)) == QUAL_UNION_TYPE)
404 : 0 : walk_tree (&DECL_QUALIFIER (t), copy_tree_body_r, id, NULL);
405 : : }
406 : :
407 : 75663565 : return t;
408 : : }
409 : :
410 : 140774983 : if (id->do_not_unshare)
411 : 66928966 : return *n;
412 : : else
413 : 73846017 : return unshare_expr (*n);
414 : : }
415 : :
416 : : static tree
417 : 96819 : remap_type_1 (tree type, copy_body_data *id)
418 : : {
419 : 96819 : 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 : 96819 : if (TREE_CODE (type) == POINTER_TYPE)
425 : : {
426 : 26513 : new_tree = build_pointer_type_for_mode (remap_type (TREE_TYPE (type), id),
427 : 26513 : TYPE_MODE (type),
428 : 26513 : TYPE_REF_CAN_ALIAS_ALL (type));
429 : 26513 : if (TYPE_ATTRIBUTES (type) || TYPE_QUALS (type))
430 : 14313 : new_tree = build_type_attribute_qual_variant (new_tree,
431 : 14313 : TYPE_ATTRIBUTES (type),
432 : 14313 : TYPE_QUALS (type));
433 : 26513 : insert_decl_map (id, type, new_tree);
434 : 26513 : return new_tree;
435 : : }
436 : 70306 : else if (TREE_CODE (type) == REFERENCE_TYPE)
437 : : {
438 : 7630 : new_tree = build_reference_type_for_mode (remap_type (TREE_TYPE (type), id),
439 : 7630 : TYPE_MODE (type),
440 : 7630 : TYPE_REF_CAN_ALIAS_ALL (type));
441 : 7630 : if (TYPE_ATTRIBUTES (type) || TYPE_QUALS (type))
442 : 5326 : new_tree = build_type_attribute_qual_variant (new_tree,
443 : 5326 : TYPE_ATTRIBUTES (type),
444 : 5326 : TYPE_QUALS (type));
445 : 7630 : insert_decl_map (id, type, new_tree);
446 : 7630 : return new_tree;
447 : : }
448 : : else
449 : 62676 : new_tree = copy_node (type);
450 : :
451 : 62676 : 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 : 62676 : t = TYPE_MAIN_VARIANT (type);
456 : 62676 : if (type != t)
457 : : {
458 : 58 : t = remap_type (t, id);
459 : 58 : TYPE_MAIN_VARIANT (new_tree) = t;
460 : 58 : TYPE_NEXT_VARIANT (new_tree) = TYPE_NEXT_VARIANT (t);
461 : 58 : TYPE_NEXT_VARIANT (t) = new_tree;
462 : : }
463 : : else
464 : : {
465 : 62618 : TYPE_MAIN_VARIANT (new_tree) = new_tree;
466 : 62618 : TYPE_NEXT_VARIANT (new_tree) = NULL;
467 : : }
468 : :
469 : 62676 : if (TYPE_STUB_DECL (type))
470 : 177 : TYPE_STUB_DECL (new_tree) = remap_decl (TYPE_STUB_DECL (type), id);
471 : :
472 : : /* Lazily create pointer and reference types. */
473 : 62676 : TYPE_POINTER_TO (new_tree) = NULL;
474 : 62676 : 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 : 62676 : switch (TREE_CODE (new_tree))
479 : : {
480 : 30251 : case INTEGER_TYPE:
481 : 30251 : case REAL_TYPE:
482 : 30251 : case FIXED_POINT_TYPE:
483 : 30251 : case ENUMERAL_TYPE:
484 : 30251 : case BOOLEAN_TYPE:
485 : 30251 : 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 : 30251 : t = TYPE_MIN_VALUE (new_tree);
496 : 30251 : if (t && TREE_CODE (t) != INTEGER_CST)
497 : 0 : walk_tree (&TYPE_MIN_VALUE (new_tree), copy_tree_body_r, id, NULL);
498 : :
499 : 30251 : t = TYPE_MAX_VALUE (new_tree);
500 : 30251 : if (t && TREE_CODE (t) != INTEGER_CST)
501 : 29825 : 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 : 32183 : case ARRAY_TYPE:
519 : 32183 : if (TYPE_MAIN_VARIANT (new_tree) != new_tree
520 : 32183 : && 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 : 32155 : TREE_TYPE (new_tree) = remap_type (TREE_TYPE (new_tree), id);
524 : :
525 : 32183 : if (TYPE_MAIN_VARIANT (new_tree) != new_tree)
526 : : {
527 : 41 : gcc_checking_assert (TYPE_DOMAIN (type)
528 : : == TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)));
529 : 41 : TYPE_DOMAIN (new_tree) = TYPE_DOMAIN (TYPE_MAIN_VARIANT (new_tree));
530 : : }
531 : : else
532 : : {
533 : 32142 : 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 : 32142 : if (id->adjust_array_error_bounds
538 : 3634 : && TYPE_DOMAIN (new_tree)
539 : 3634 : && TYPE_MAX_VALUE (TYPE_DOMAIN (new_tree)) == error_mark_node
540 : 35021 : && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != error_mark_node)
541 : : {
542 : 2879 : tree v = create_tmp_var (TREE_TYPE (TYPE_DOMAIN (new_tree)));
543 : 2879 : DECL_ATTRIBUTES (v)
544 : 2879 : = tree_cons (get_identifier ("omp dummy var"), NULL_TREE,
545 : 2879 : DECL_ATTRIBUTES (v));
546 : 2879 : TYPE_MAX_VALUE (TYPE_DOMAIN (new_tree)) = v;
547 : : }
548 : : }
549 : : break;
550 : :
551 : 226 : case RECORD_TYPE:
552 : 226 : case UNION_TYPE:
553 : 226 : case QUAL_UNION_TYPE:
554 : 226 : if (TYPE_MAIN_VARIANT (type) != type
555 : 226 : && TYPE_FIELDS (type) == TYPE_FIELDS (TYPE_MAIN_VARIANT (type)))
556 : 17 : TYPE_FIELDS (new_tree) = TYPE_FIELDS (TYPE_MAIN_VARIANT (new_tree));
557 : : else
558 : : {
559 : 209 : tree f, nf = NULL;
560 : :
561 : 973 : for (f = TYPE_FIELDS (new_tree); f ; f = DECL_CHAIN (f))
562 : : {
563 : 764 : t = remap_decl (f, id);
564 : 764 : DECL_CONTEXT (t) = new_tree;
565 : 764 : DECL_CHAIN (t) = nf;
566 : 764 : nf = t;
567 : : }
568 : 209 : TYPE_FIELDS (new_tree) = nreverse (nf);
569 : : }
570 : : break;
571 : :
572 : 0 : case OFFSET_TYPE:
573 : 0 : default:
574 : : /* Shouldn't have been thought variable sized. */
575 : 0 : gcc_unreachable ();
576 : : }
577 : :
578 : : /* All variants of type share the same size, so use the already remaped data. */
579 : 32409 : if (TYPE_MAIN_VARIANT (new_tree) != new_tree)
580 : : {
581 : 58 : tree s = TYPE_SIZE (type);
582 : 58 : tree mvs = TYPE_SIZE (TYPE_MAIN_VARIANT (type));
583 : 58 : tree su = TYPE_SIZE_UNIT (type);
584 : 58 : tree mvsu = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (type));
585 : 58 : gcc_checking_assert ((TREE_CODE (s) == PLACEHOLDER_EXPR
586 : : && (TREE_CODE (mvs) == PLACEHOLDER_EXPR))
587 : : || s == mvs);
588 : 58 : gcc_checking_assert ((TREE_CODE (su) == PLACEHOLDER_EXPR
589 : : && (TREE_CODE (mvsu) == PLACEHOLDER_EXPR))
590 : : || su == mvsu);
591 : 58 : TYPE_SIZE (new_tree) = TYPE_SIZE (TYPE_MAIN_VARIANT (new_tree));
592 : 58 : TYPE_SIZE_UNIT (new_tree) = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (new_tree));
593 : : }
594 : : else
595 : : {
596 : 32351 : walk_tree (&TYPE_SIZE (new_tree), copy_tree_body_r, id, NULL);
597 : 32351 : walk_tree (&TYPE_SIZE_UNIT (new_tree), copy_tree_body_r, id, NULL);
598 : : }
599 : :
600 : : return new_tree;
601 : : }
602 : :
603 : : /* Helper function for remap_type_2, called through walk_tree. */
604 : :
605 : : static tree
606 : 30303 : remap_type_3 (tree *tp, int *walk_subtrees, void *data)
607 : : {
608 : 30303 : copy_body_data *id = (copy_body_data *) data;
609 : :
610 : 30303 : if (TYPE_P (*tp))
611 : 0 : *walk_subtrees = 0;
612 : :
613 : 30303 : else if (DECL_P (*tp) && remap_decl (*tp, id) != *tp)
614 : : return *tp;
615 : :
616 : : return NULL_TREE;
617 : : }
618 : :
619 : : /* Return true if TYPE needs to be remapped because remap_decl on any
620 : : needed embedded decl returns something other than that decl. */
621 : :
622 : : static bool
623 : 50694 : remap_type_2 (tree type, copy_body_data *id)
624 : : {
625 : 61109 : tree t;
626 : :
627 : : #define RETURN_TRUE_IF_VAR(T) \
628 : : do \
629 : : { \
630 : : tree _t = (T); \
631 : : if (_t) \
632 : : { \
633 : : if (DECL_P (_t) && remap_decl (_t, id) != _t) \
634 : : return true; \
635 : : if (!TYPE_SIZES_GIMPLIFIED (type) \
636 : : && walk_tree (&_t, remap_type_3, id, NULL)) \
637 : : return true; \
638 : : } \
639 : : } \
640 : : while (0)
641 : :
642 : 61109 : switch (TREE_CODE (type))
643 : : {
644 : 10415 : case POINTER_TYPE:
645 : 10415 : case REFERENCE_TYPE:
646 : 10415 : case FUNCTION_TYPE:
647 : 10415 : case METHOD_TYPE:
648 : 10415 : return remap_type_2 (TREE_TYPE (type), id);
649 : :
650 : 34086 : case INTEGER_TYPE:
651 : 34086 : case REAL_TYPE:
652 : 34086 : case FIXED_POINT_TYPE:
653 : 34086 : case ENUMERAL_TYPE:
654 : 34086 : case BOOLEAN_TYPE:
655 : 34086 : RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
656 : 34086 : RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
657 : 22366 : return false;
658 : :
659 : 16137 : case ARRAY_TYPE:
660 : 16137 : if (remap_type_2 (TREE_TYPE (type), id)
661 : 31660 : || (TYPE_DOMAIN (type) && remap_type_2 (TYPE_DOMAIN (type), id)))
662 : 8940 : return true;
663 : : break;
664 : :
665 : 357 : case RECORD_TYPE:
666 : 357 : case UNION_TYPE:
667 : 357 : case QUAL_UNION_TYPE:
668 : 3561 : for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t))
669 : 3204 : if (TREE_CODE (t) == FIELD_DECL)
670 : : {
671 : 1242 : RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
672 : 1242 : RETURN_TRUE_IF_VAR (DECL_SIZE (t));
673 : 1242 : RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
674 : 1242 : if (TREE_CODE (type) == QUAL_UNION_TYPE)
675 : 0 : RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
676 : : }
677 : : break;
678 : :
679 : : default:
680 : : return false;
681 : : }
682 : :
683 : 7554 : RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
684 : 7545 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type));
685 : 6942 : return false;
686 : : #undef RETURN_TRUE_IF_VAR
687 : : }
688 : :
689 : : tree
690 : 859057480 : remap_type (tree type, copy_body_data *id)
691 : : {
692 : 859057480 : tree *node;
693 : 859057480 : tree tmp;
694 : :
695 : 859057480 : if (type == NULL)
696 : : return type;
697 : :
698 : : /* See if we have remapped this type. */
699 : 858941961 : node = id->decl_map->get (type);
700 : 858941961 : if (node)
701 : 568821714 : return *node;
702 : :
703 : : /* The type only needs remapping if it's variably modified. */
704 : 290120247 : 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 : 290120247 : || (id->dont_remap_vla_if_no_change && !remap_type_2 (type, id)))
708 : : {
709 : 290023916 : insert_decl_map (id, type, type);
710 : 290023916 : return type;
711 : : }
712 : :
713 : 96331 : id->remapping_type_depth++;
714 : 96331 : tmp = remap_type_1 (type, id);
715 : 96331 : id->remapping_type_depth--;
716 : :
717 : 96331 : return tmp;
718 : : }
719 : :
720 : : /* Decide if DECL can be put into BLOCK_NONLOCAL_VARs. */
721 : :
722 : : static bool
723 : 35486673 : can_be_nonlocal (tree decl, copy_body_data *id)
724 : : {
725 : : /* We cannot duplicate function decls. */
726 : 35486673 : 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 : 35469064 : 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 : 38954071 : remap_decls (tree decls, vec<tree, va_gc> **nonlocalized_list,
739 : : copy_body_data *id)
740 : : {
741 : 38954071 : tree old_var;
742 : 38954071 : tree new_decls = NULL_TREE;
743 : :
744 : : /* Remap its variables. */
745 : 70369911 : for (old_var = decls; old_var; old_var = DECL_CHAIN (old_var))
746 : : {
747 : 31415840 : tree new_var;
748 : :
749 : 31415840 : 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 : 91464 : if (VAR_P (old_var) && ! DECL_EXTERNAL (old_var) && cfun)
754 : 73766 : add_local_decl (cfun, old_var);
755 : 72272 : if ((!optimize || debug_info_level > DINFO_LEVEL_TERSE)
756 : 66041 : && !DECL_IGNORED_P (old_var)
757 : 157435 : && nonlocalized_list)
758 : 50902 : vec_safe_push (*nonlocalized_list, old_var);
759 : 91464 : continue;
760 : : }
761 : :
762 : : /* Remap the variable. */
763 : 31324376 : 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 : 31324376 : if (new_var == old_var || new_var == id->retvar)
770 : : ;
771 : 29033888 : 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 : 29033888 : gcc_assert (DECL_P (new_var));
781 : 29033888 : DECL_CHAIN (new_var) = new_decls;
782 : 29033888 : new_decls = new_var;
783 : :
784 : : /* Also copy value-expressions. */
785 : 29033888 : if (VAR_P (new_var) && DECL_HAS_VALUE_EXPR_P (new_var))
786 : : {
787 : 932020 : tree tem = DECL_VALUE_EXPR (new_var);
788 : 932020 : bool old_regimplify = id->regimplify;
789 : 932020 : id->remapping_type_depth++;
790 : 932020 : walk_tree (&tem, copy_tree_body_r, id, NULL);
791 : 932020 : id->remapping_type_depth--;
792 : 932020 : id->regimplify = old_regimplify;
793 : 932020 : SET_DECL_VALUE_EXPR (new_var, tem);
794 : : }
795 : : }
796 : : }
797 : :
798 : 38954071 : 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 : 36574338 : remap_block (tree *block, copy_body_data *id)
806 : : {
807 : 36574338 : tree old_block;
808 : 36574338 : tree new_block;
809 : :
810 : : /* Make the new block. */
811 : 36574338 : old_block = *block;
812 : 36574338 : new_block = make_node (BLOCK);
813 : 36574338 : TREE_USED (new_block) = TREE_USED (old_block);
814 : 36574338 : BLOCK_ABSTRACT_ORIGIN (new_block) = BLOCK_ORIGIN (old_block);
815 : 36574338 : BLOCK_SOURCE_LOCATION (new_block) = BLOCK_SOURCE_LOCATION (old_block);
816 : 36574338 : BLOCK_NONLOCALIZED_VARS (new_block)
817 : 36638046 : = vec_safe_copy (BLOCK_NONLOCALIZED_VARS (old_block));
818 : 36574338 : *block = new_block;
819 : :
820 : : /* Remap its variables. */
821 : 73148676 : BLOCK_VARS (new_block) = remap_decls (BLOCK_VARS (old_block),
822 : 36574338 : &BLOCK_NONLOCALIZED_VARS (new_block),
823 : : id);
824 : :
825 : : /* Remember the remapped block. */
826 : 36574338 : insert_decl_map (id, old_block, new_block);
827 : 36574338 : }
828 : :
829 : : /* Copy the whole block tree and root it in id->block. */
830 : :
831 : : static tree
832 : 24308670 : remap_blocks (tree block, copy_body_data *id)
833 : : {
834 : 24308670 : tree t;
835 : 24308670 : tree new_tree = block;
836 : :
837 : 24308670 : if (!block)
838 : : return NULL;
839 : :
840 : 24308670 : remap_block (&new_tree, id);
841 : 24308670 : gcc_assert (new_tree != block);
842 : 44033681 : for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t))
843 : 19725011 : 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 : 24308670 : BLOCK_SUBBLOCKS (new_tree) = blocks_nreverse (BLOCK_SUBBLOCKS (new_tree));
847 : 24308670 : return new_tree;
848 : : }
849 : :
850 : : /* Remap the block tree rooted at BLOCK to nothing. */
851 : :
852 : : static void
853 : 78509 : remap_blocks_to_null (tree block, copy_body_data *id)
854 : : {
855 : 78509 : tree t;
856 : 78509 : insert_decl_map (id, block, NULL_TREE);
857 : 128768 : for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t))
858 : 50259 : remap_blocks_to_null (t, id);
859 : 78509 : }
860 : :
861 : : /* Remap the location info pointed to by LOCUS. */
862 : :
863 : : static location_t
864 : 24321638 : remap_location (location_t locus, copy_body_data *id)
865 : : {
866 : 24321638 : if (LOCATION_BLOCK (locus))
867 : : {
868 : 16151594 : tree *n = id->decl_map->get (LOCATION_BLOCK (locus));
869 : 16151594 : gcc_assert (n);
870 : 16151594 : if (*n)
871 : 16108503 : return set_block (locus, *n);
872 : : }
873 : :
874 : 8213135 : locus = LOCATION_LOCUS (locus);
875 : :
876 : 8213135 : if (locus != UNKNOWN_LOCATION && id->block)
877 : 16 : return set_block (locus, id->block);
878 : :
879 : : return locus;
880 : : }
881 : :
882 : : static void
883 : 28651577 : copy_statement_list (tree *tp)
884 : : {
885 : 28651577 : tree_stmt_iterator oi, ni;
886 : 28651577 : tree new_tree;
887 : :
888 : 28651577 : new_tree = alloc_stmt_list ();
889 : 28651577 : ni = tsi_start (new_tree);
890 : 28651577 : oi = tsi_start (*tp);
891 : 28651577 : TREE_TYPE (new_tree) = TREE_TYPE (*tp);
892 : 28651577 : *tp = new_tree;
893 : :
894 : 88364206 : for (; !tsi_end_p (oi); tsi_next (&oi))
895 : : {
896 : 59712629 : tree stmt = tsi_stmt (oi);
897 : 59712629 : 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 : 48504 : copy_statement_list (&stmt);
902 : 59712629 : tsi_link_after (&ni, stmt, TSI_CONTINUE_LINKING);
903 : : }
904 : 28651577 : }
905 : :
906 : : static void
907 : 12265842 : copy_bind_expr (tree *tp, int *walk_subtrees, copy_body_data *id)
908 : : {
909 : 12265842 : tree block = BIND_EXPR_BLOCK (*tp);
910 : : /* Copy (and replace) the statement. */
911 : 12265842 : copy_tree_r (tp, walk_subtrees, NULL);
912 : 12265842 : if (block)
913 : : {
914 : 12265381 : remap_block (&block, id);
915 : 12265381 : BIND_EXPR_BLOCK (*tp) = block;
916 : : }
917 : :
918 : 12265842 : if (BIND_EXPR_VARS (*tp))
919 : : /* This will remap a lot of the same decls again, but this should be
920 : : harmless. */
921 : 2379565 : BIND_EXPR_VARS (*tp) = remap_decls (BIND_EXPR_VARS (*tp), NULL, id);
922 : 12265842 : }
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 : 30029 : is_parm (tree decl)
978 : : {
979 : 30029 : if (TREE_CODE (decl) == SSA_NAME)
980 : : {
981 : 28326 : decl = SSA_NAME_VAR (decl);
982 : : if (!decl)
983 : : return false;
984 : : }
985 : :
986 : 17480 : 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 : 3615459 : remap_dependence_clique (copy_body_data *id, unsigned short clique)
994 : : {
995 : 3615459 : if (clique == 0 || processing_debug_stmt)
996 : : return 0;
997 : 3579617 : if (!id->dependence_map)
998 : 755396 : id->dependence_map = new hash_map<dependence_hash, unsigned short>;
999 : 3579617 : bool existed;
1000 : 3579617 : unsigned short &newc = id->dependence_map->get_or_insert (clique, &existed);
1001 : 3579617 : if (!existed)
1002 : : {
1003 : : /* Clique 1 is reserved for local ones set by PTA. */
1004 : 1184156 : if (cfun->last_clique == 0)
1005 : 343362 : cfun->last_clique = 1;
1006 : 2368312 : newc = get_new_clique (cfun);
1007 : : }
1008 : 3579617 : 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 : 187263307 : remap_gimple_op_r (tree *tp, int *walk_subtrees, void *data)
1018 : : {
1019 : 187263307 : struct walk_stmt_info *wi_p = (struct walk_stmt_info *) data;
1020 : 187263307 : copy_body_data *id = (copy_body_data *) wi_p->info;
1021 : 187263307 : tree fn = id->src_fn;
1022 : :
1023 : : /* For recursive invocations this is no longer the LHS itself. */
1024 : 187263307 : bool is_lhs = wi_p->is_lhs;
1025 : 187263307 : wi_p->is_lhs = false;
1026 : :
1027 : 187263307 : if (TREE_CODE (*tp) == SSA_NAME)
1028 : : {
1029 : 61456575 : *tp = remap_ssa_name (*tp, id);
1030 : 61456575 : *walk_subtrees = 0;
1031 : 61456575 : if (is_lhs)
1032 : 15496494 : SSA_NAME_DEF_STMT (*tp) = wi_p->stmt;
1033 : 61456575 : return NULL;
1034 : : }
1035 : 125806732 : 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 : 39817070 : tree new_decl;
1043 : :
1044 : : /* Remap the declaration. */
1045 : 39817070 : new_decl = remap_decl (*tp, id);
1046 : 39817070 : gcc_assert (new_decl);
1047 : : /* Replace this variable with the copy. */
1048 : 39817070 : 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 : 39817070 : if (TREE_CODE (new_decl) == INTEGER_CST
1054 : 39817070 : && !useless_type_conversion_p (TREE_TYPE (*tp), TREE_TYPE (new_decl)))
1055 : 0 : new_decl = fold_convert (TREE_TYPE (*tp), new_decl);
1056 : 39817070 : *tp = new_decl;
1057 : 39817070 : *walk_subtrees = 0;
1058 : : }
1059 : 85989662 : else if (TREE_CODE (*tp) == STATEMENT_LIST)
1060 : 0 : gcc_unreachable ();
1061 : 85989662 : else if (TREE_CODE (*tp) == SAVE_EXPR)
1062 : 0 : gcc_unreachable ();
1063 : 85989662 : else if (TREE_CODE (*tp) == LABEL_DECL
1064 : 85989662 : && (!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 : 85989662 : 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 : 14883812 : tree *n = id->decl_map->get (*tp);
1073 : 14883812 : if (n)
1074 : 71 : *tp = *n;
1075 : 14883812 : *walk_subtrees = 0;
1076 : : }
1077 : 71105850 : else if (TYPE_P (*tp))
1078 : : /* Types may need remapping as well. */
1079 : 0 : *tp = remap_type (*tp, id);
1080 : 71105850 : 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 : 11266605 : tree new_type = remap_type (TREE_TYPE (*tp), id);
1085 : :
1086 : 11266605 : if (new_type == TREE_TYPE (*tp))
1087 : 11262769 : *walk_subtrees = 0;
1088 : :
1089 : 3836 : else if (TREE_CODE (*tp) == INTEGER_CST)
1090 : 3836 : *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 : 59839245 : 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 : 14015878 : tree ptr = TREE_OPERAND (*tp, 0);
1108 : 14015878 : tree type = remap_type (TREE_TYPE (*tp), id);
1109 : 14015878 : tree old = *tp;
1110 : 14015878 : walk_tree (&ptr, remap_gimple_op_r, data, NULL);
1111 : 14015878 : *tp = fold_build2 (MEM_REF, type, ptr, TREE_OPERAND (*tp, 1));
1112 : 14015878 : TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old);
1113 : 14015878 : TREE_SIDE_EFFECTS (*tp) = TREE_SIDE_EFFECTS (old);
1114 : 14015878 : copy_warning (*tp, old);
1115 : 14015878 : if (MR_DEPENDENCE_CLIQUE (old) != 0)
1116 : : {
1117 : 3538208 : MR_DEPENDENCE_CLIQUE (*tp)
1118 : 3538208 : = remap_dependence_clique (id, MR_DEPENDENCE_CLIQUE (old));
1119 : 3538208 : 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 : 14015878 : if (TREE_THIS_NOTRAP (old)
1125 : 14015878 : && (!is_parm (TREE_OPERAND (old, 0))
1126 : 11926 : || (!id->transform_parameter && is_parm (ptr))))
1127 : 16404 : TREE_THIS_NOTRAP (*tp) = 1;
1128 : 14015878 : REF_REVERSE_STORAGE_ORDER (*tp) = REF_REVERSE_STORAGE_ORDER (old);
1129 : 14015878 : *walk_subtrees = 0;
1130 : 14015878 : return NULL;
1131 : : }
1132 : :
1133 : : /* Here is the "usual case". Copy this tree node, and then
1134 : : tweak some special cases. */
1135 : 45823367 : copy_tree_r (tp, walk_subtrees, NULL);
1136 : :
1137 : 45823367 : if (TREE_CODE (*tp) != OMP_CLAUSE)
1138 : 45823367 : TREE_TYPE (*tp) = remap_type (TREE_TYPE (*tp), id);
1139 : :
1140 : 45823367 : 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 : 45823367 : 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 : 14262725 : int invariant = is_gimple_min_invariant (*tp);
1153 : 14262725 : walk_tree (&TREE_OPERAND (*tp, 0), remap_gimple_op_r, data, NULL);
1154 : 14262725 : 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 : 14262725 : if (invariant && !is_gimple_min_invariant (*tp))
1159 : 5573 : id->regimplify = true;
1160 : :
1161 : 14262725 : *walk_subtrees = 0;
1162 : : }
1163 : 31560642 : 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 : 111790854 : if (EXPR_P (*tp))
1174 : : {
1175 : 30271679 : tree new_block = id->remapping_type_depth == 0 ? id->block : NULL;
1176 : 30271679 : tree old_block = TREE_BLOCK (*tp);
1177 : 30271679 : if (old_block)
1178 : : {
1179 : 16746895 : tree *n;
1180 : 16746895 : n = id->decl_map->get (TREE_BLOCK (*tp));
1181 : 16746895 : if (n)
1182 : 16746477 : new_block = *n;
1183 : : }
1184 : 30271679 : 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 : 836328690 : copy_tree_body_r (tree *tp, int *walk_subtrees, void *data)
1197 : : {
1198 : 836328690 : copy_body_data *id = (copy_body_data *) data;
1199 : 836328690 : tree fn = id->src_fn;
1200 : 836328690 : 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 : 836328690 : 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 : 836328690 : else if (TREE_CODE (*tp) == SSA_NAME)
1233 : : {
1234 : 3732985 : *tp = remap_ssa_name (*tp, id);
1235 : 3732985 : *walk_subtrees = 0;
1236 : 3732985 : 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 : 832595705 : else if (auto_var_in_fn_p (*tp, fn))
1244 : : {
1245 : 97374996 : tree new_decl;
1246 : :
1247 : : /* Remap the declaration. */
1248 : 97374996 : new_decl = remap_decl (*tp, id);
1249 : 97374996 : gcc_assert (new_decl);
1250 : : /* Replace this variable with the copy. */
1251 : 97374996 : STRIP_TYPE_NOPS (new_decl);
1252 : 97374996 : *tp = new_decl;
1253 : 97374996 : *walk_subtrees = 0;
1254 : : }
1255 : 735220709 : else if (TREE_CODE (*tp) == STATEMENT_LIST)
1256 : 28603049 : copy_statement_list (tp);
1257 : 706617660 : else if (TREE_CODE (*tp) == SAVE_EXPR
1258 : 706284581 : || TREE_CODE (*tp) == TARGET_EXPR)
1259 : 6710153 : remap_save_expr (tp, id->decl_map, walk_subtrees);
1260 : 699907507 : else if (TREE_CODE (*tp) == LABEL_DECL
1261 : 699907507 : && (! 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 : 699907507 : else if (TREE_CODE (*tp) == BIND_EXPR)
1266 : 12265842 : copy_bind_expr (tp, walk_subtrees, id);
1267 : : /* Types may need remapping as well. */
1268 : 687641665 : else if (TYPE_P (*tp))
1269 : 167606 : *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 : 687474059 : else if (CONSTANT_CLASS_P (*tp))
1274 : : {
1275 : 203972323 : tree new_type = remap_type (TREE_TYPE (*tp), id);
1276 : :
1277 : 203972323 : if (new_type == TREE_TYPE (*tp))
1278 : 203971122 : *walk_subtrees = 0;
1279 : :
1280 : 1201 : else if (TREE_CODE (*tp) == INTEGER_CST)
1281 : 1201 : *tp = wide_int_to_tree (new_type, wi::to_wide (*tp));
1282 : : else
1283 : : {
1284 : 0 : *tp = copy_node (*tp);
1285 : 0 : TREE_TYPE (*tp) = new_type;
1286 : : }
1287 : : }
1288 : :
1289 : : /* Otherwise, just copy the node. Note that copy_tree_r already
1290 : : knows not to copy VAR_DECLs, etc., so this is safe. */
1291 : : else
1292 : : {
1293 : : /* Here we handle trees that are not completely rewritten.
1294 : : First we detect some inlining-induced bogosities for
1295 : : discarding. */
1296 : 483501736 : if (TREE_CODE (*tp) == MODIFY_EXPR
1297 : 11867836 : && TREE_OPERAND (*tp, 0) == TREE_OPERAND (*tp, 1)
1298 : 483501736 : && (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 : 483501736 : 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 : 33360313 : tree decl = TREE_OPERAND (*tp, 0);
1323 : 33360313 : tree *n = id->decl_map->get (decl);
1324 : 33360313 : 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 : 4703673 : tree type = TREE_TYPE (*tp);
1333 : 4703673 : tree ptr = id->do_not_unshare ? *n : unshare_expr (*n);
1334 : 4703673 : tree old = *tp;
1335 : 4703673 : *tp = id->do_not_fold ? NULL : gimple_fold_indirect_ref (ptr);
1336 : 4703673 : if (! *tp)
1337 : : {
1338 : 4703538 : type = remap_type (type, id);
1339 : 4703538 : 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 : 4703538 : *tp = build1 (INDIRECT_REF, type, ptr);
1352 : 4703538 : TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old);
1353 : 4703538 : TREE_SIDE_EFFECTS (*tp) = TREE_SIDE_EFFECTS (old);
1354 : 4703538 : 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 : 4703538 : if (TREE_THIS_NOTRAP (old)
1359 : 4703538 : && (!is_parm (TREE_OPERAND (old, 0))
1360 : 0 : || (!id->transform_parameter && is_parm (ptr))))
1361 : 1116 : TREE_THIS_NOTRAP (*tp) = 1;
1362 : : }
1363 : : }
1364 : 4703673 : *walk_subtrees = 0;
1365 : 4703673 : return NULL;
1366 : : }
1367 : : }
1368 : 450141423 : 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 : 74029 : tree ptr = TREE_OPERAND (*tp, 0);
1374 : 74029 : tree type = remap_type (TREE_TYPE (*tp), id);
1375 : 74029 : tree old = *tp;
1376 : 74029 : walk_tree (&ptr, copy_tree_body_r, data, NULL);
1377 : 74029 : *tp = fold_build2 (MEM_REF, type, ptr, TREE_OPERAND (*tp, 1));
1378 : 74029 : TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old);
1379 : 74029 : TREE_SIDE_EFFECTS (*tp) = TREE_SIDE_EFFECTS (old);
1380 : 74029 : copy_warning (*tp, old);
1381 : 74029 : if (MR_DEPENDENCE_CLIQUE (old) != 0)
1382 : : {
1383 : 8282 : MR_DEPENDENCE_CLIQUE (*tp)
1384 : 8282 : = remap_dependence_clique (id, MR_DEPENDENCE_CLIQUE (old));
1385 : 8282 : 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 : 74029 : if (TREE_THIS_NOTRAP (old)
1391 : 74029 : && (!is_parm (TREE_OPERAND (old, 0))
1392 : 513 : || (!id->transform_parameter && is_parm (ptr))))
1393 : 70 : TREE_THIS_NOTRAP (*tp) = 1;
1394 : 74029 : REF_REVERSE_STORAGE_ORDER (*tp) = REF_REVERSE_STORAGE_ORDER (old);
1395 : 74029 : *walk_subtrees = 0;
1396 : 74029 : return NULL;
1397 : : }
1398 : :
1399 : : /* Here is the "usual case". Copy this tree node, and then
1400 : : tweak some special cases. */
1401 : 478724034 : 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 : 478724034 : if (EXPR_P (*tp))
1407 : : {
1408 : 413148259 : new_block = id->remapping_type_depth == 0 ? id->block : NULL;
1409 : 413148259 : if (TREE_BLOCK (*tp))
1410 : : {
1411 : 18793 : tree *n;
1412 : 18793 : n = id->decl_map->get (TREE_BLOCK (*tp));
1413 : 18793 : if (n)
1414 : 18793 : new_block = *n;
1415 : : }
1416 : 413148259 : TREE_SET_BLOCK (*tp, new_block);
1417 : : }
1418 : :
1419 : 478724034 : if (TREE_CODE (*tp) != OMP_CLAUSE)
1420 : 478723943 : 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 : 478724034 : 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 : 478724034 : else if (TREE_CODE (*tp) == ADDR_EXPR)
1434 : : {
1435 : 42657181 : int invariant = is_gimple_min_invariant (*tp);
1436 : 42657181 : 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 : 42657181 : if (INDIRECT_REF_P (TREE_OPERAND (*tp, 0))
1441 : 42657181 : && !id->do_not_fold)
1442 : : {
1443 : 147 : tree t = TREE_OPERAND (TREE_OPERAND (*tp, 0), 0);
1444 : 147 : if (TREE_TYPE (t) != TREE_TYPE (*tp))
1445 : 147 : t = fold_convert (remap_type (TREE_TYPE (*tp), id), t);
1446 : 147 : *tp = t;
1447 : : }
1448 : : else
1449 : 42657034 : 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 : 42657181 : if (invariant && !is_gimple_min_invariant (*tp))
1454 : 16 : id->regimplify = true;
1455 : :
1456 : 42657181 : *walk_subtrees = 0;
1457 : : }
1458 : 436066853 : else if (TREE_CODE (*tp) == OMP_CLAUSE
1459 : 436066853 : && (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 : 104760 : remap_eh_region_nr (int old_nr, copy_body_data *id)
1492 : : {
1493 : 104760 : eh_region old_r, new_r;
1494 : :
1495 : 104760 : old_r = get_eh_region_from_number_fn (id->src_cfun, old_nr);
1496 : 104760 : new_r = static_cast<eh_region> (*id->eh_map->get (old_r));
1497 : :
1498 : 104760 : return new_r->index;
1499 : : }
1500 : :
1501 : : /* Similar, but operate on INTEGER_CSTs. */
1502 : :
1503 : : static tree
1504 : 7664 : remap_eh_region_tree_nr (tree old_t_nr, copy_body_data *id)
1505 : : {
1506 : 7664 : int old_nr, new_nr;
1507 : :
1508 : 7664 : old_nr = tree_to_shwi (old_t_nr);
1509 : 7664 : new_nr = remap_eh_region_nr (old_nr, id);
1510 : :
1511 : 7664 : 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 : 85214567 : remap_gimple_stmt (gimple *stmt, copy_body_data *id)
1519 : : {
1520 : 85214567 : gimple *copy = NULL;
1521 : 85214567 : struct walk_stmt_info wi;
1522 : 85214567 : bool skip_first = false;
1523 : 85214567 : gimple_seq stmts = NULL;
1524 : :
1525 : 85214567 : if (is_gimple_debug (stmt)
1526 : 85214567 : && (gimple_debug_nonbind_marker_p (stmt)
1527 : 12485758 : ? !DECL_STRUCT_FUNCTION (id->dst_fn)->debug_nonbind_markers
1528 : 38554016 : : !opt_for_fn (id->dst_fn, flag_var_tracking_assignments)))
1529 : : return NULL;
1530 : :
1531 : 85188310 : if (!is_gimple_debug (stmt)
1532 : 34174793 : && id->param_body_adjs
1533 : 88352057 : && id->param_body_adjs->m_dead_stmts.contains (stmt))
1534 : : {
1535 : 1868 : tree *dval = id->param_body_adjs->m_dead_stmt_debug_equiv.get (stmt);
1536 : 1868 : if (!dval)
1537 : : return NULL;
1538 : :
1539 : 717 : gcc_assert (is_gimple_assign (stmt));
1540 : 717 : tree lhs = gimple_assign_lhs (stmt);
1541 : 717 : tree *dvar = id->param_body_adjs->m_dead_ssa_debug_equiv.get (lhs);
1542 : 717 : gdebug *bind = gimple_build_debug_bind (*dvar, *dval, stmt);
1543 : 717 : if (id->reset_location)
1544 : 0 : gimple_set_location (bind, input_location);
1545 : 717 : id->debug_stmts.safe_push (bind);
1546 : 717 : gimple_seq_add_stmt_without_update (&stmts, bind);
1547 : 717 : 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 : 85186442 : if (gimple_code (stmt) == GIMPLE_RETURN && id->transform_return_to_modify)
1561 : : {
1562 : 4336870 : 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 : 4336870 : if (retval
1571 : 4336870 : && (TREE_CODE (retval) != RESULT_DECL
1572 : 2264554 : && (!id->call_stmt
1573 : 2264554 : || gimple_call_lhs (id->call_stmt) != NULL_TREE)
1574 : 2153789 : && (TREE_CODE (retval) != SSA_NAME
1575 : 1702260 : || ! SSA_NAME_VAR (retval)
1576 : 402268 : || TREE_CODE (SSA_NAME_VAR (retval)) != RESULT_DECL)))
1577 : : {
1578 : 4148754 : copy = gimple_build_assign (id->do_not_unshare
1579 : 2074377 : ? id->retvar : unshare_expr (id->retvar),
1580 : : retval);
1581 : : /* id->retvar is already substituted. Skip it on later remapping. */
1582 : 2074377 : skip_first = true;
1583 : : }
1584 : : else
1585 : : return NULL;
1586 : : }
1587 : 80849572 : 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 : 80849505 : if (gimple_assign_single_p (stmt)
1788 : 13671118 : && gimple_assign_lhs (stmt) == gimple_assign_rhs1 (stmt)
1789 : 80849505 : && 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 : 80849505 : if (id->blocks_to_copy && gimple_clobber_p (stmt))
1815 : : {
1816 : 22509 : tree lhs = gimple_assign_lhs (stmt);
1817 : 22509 : if (TREE_CODE (lhs) == MEM_REF
1818 : 22509 : && TREE_CODE (TREE_OPERAND (lhs, 0)) == SSA_NAME)
1819 : : {
1820 : 987 : gimple *def_stmt = SSA_NAME_DEF_STMT (TREE_OPERAND (lhs, 0));
1821 : 987 : if (gimple_bb (def_stmt)
1822 : 1414 : && !bitmap_bit_p (id->blocks_to_copy,
1823 : 427 : 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 : 80849502 : if (gimple_clobber_p (stmt)
1832 : 80849502 : && 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 : 80849502 : if (gimple_debug_bind_p (stmt))
1841 : : {
1842 : 38085771 : tree var = gimple_debug_bind_get_var (stmt);
1843 : 38085771 : tree value = gimple_debug_bind_get_value (stmt);
1844 : 38085771 : if (id->param_body_adjs
1845 : 38085771 : && id->param_body_adjs->m_dead_stmts.contains (stmt))
1846 : : {
1847 : 7368 : value = unshare_expr_without_location (value);
1848 : 7368 : id->param_body_adjs->remap_with_debug_expressions (&value);
1849 : : }
1850 : :
1851 : 38085771 : gdebug *copy = gimple_build_debug_bind (var, value, stmt);
1852 : 38085771 : if (id->reset_location)
1853 : 4 : gimple_set_location (copy, input_location);
1854 : 38085771 : id->debug_stmts.safe_push (copy);
1855 : 38085771 : gimple_seq_add_stmt_without_update (&stmts, copy);
1856 : 38085771 : return stmts;
1857 : : }
1858 : 42763731 : if (gimple_debug_source_bind_p (stmt))
1859 : : {
1860 : 468245 : gdebug *copy = gimple_build_debug_source_bind
1861 : 468245 : (gimple_debug_source_bind_get_var (stmt),
1862 : : gimple_debug_source_bind_get_value (stmt),
1863 : 468245 : stmt);
1864 : 468245 : if (id->reset_location)
1865 : 0 : gimple_set_location (copy, input_location);
1866 : 468245 : id->debug_stmts.safe_push (copy);
1867 : 468245 : gimple_seq_add_stmt_without_update (&stmts, copy);
1868 : 468245 : return stmts;
1869 : : }
1870 : 42295486 : if (gimple_debug_nonbind_marker_p (stmt))
1871 : : {
1872 : : /* If the inlined function has too many debug markers,
1873 : : don't copy them. */
1874 : 12459501 : if (id->src_cfun->debug_marker_count
1875 : 12459501 : > param_max_debug_marker_count
1876 : 12459501 : || id->reset_location)
1877 : 0 : return stmts;
1878 : :
1879 : 12459501 : gdebug *copy = as_a <gdebug *> (gimple_copy (stmt));
1880 : 12459501 : id->debug_stmts.safe_push (copy);
1881 : 12459501 : gimple_seq_add_stmt_without_update (&stmts, copy);
1882 : 12459501 : return stmts;
1883 : : }
1884 : :
1885 : : /* Create a new deep copy of the statement. */
1886 : 29835985 : copy = gimple_copy (stmt);
1887 : :
1888 : : /* Clear flags that need revisiting. */
1889 : 29835985 : if (gcall *call_stmt = dyn_cast <gcall *> (copy))
1890 : : {
1891 : 4482117 : if (gimple_call_tail_p (call_stmt))
1892 : 82 : gimple_call_set_tail (call_stmt, false);
1893 : 4482117 : if (gimple_call_from_thunk_p (call_stmt))
1894 : 122 : gimple_call_set_from_thunk (call_stmt, false);
1895 : : /* Silently clear musttail flag when inlining a function
1896 : : with must tail call from a non-musttail call. The inlining
1897 : : removes one frame so acts like musttail's intent, and we
1898 : : can be inlining a function with musttail calls in the middle
1899 : : of caller where musttail will always error. */
1900 : 4482117 : if (gimple_call_must_tail_p (call_stmt)
1901 : 45 : && id->call_stmt
1902 : 4482158 : && !gimple_call_must_tail_p (id->call_stmt))
1903 : 14 : gimple_call_set_must_tail (call_stmt, false);
1904 : 4482117 : if (gimple_call_internal_p (call_stmt))
1905 : 31433 : switch (gimple_call_internal_fn (call_stmt))
1906 : : {
1907 : 134 : case IFN_GOMP_SIMD_LANE:
1908 : 134 : case IFN_GOMP_SIMD_VF:
1909 : 134 : case IFN_GOMP_SIMD_LAST_LANE:
1910 : 134 : case IFN_GOMP_SIMD_ORDERED_START:
1911 : 134 : case IFN_GOMP_SIMD_ORDERED_END:
1912 : 134 : DECL_STRUCT_FUNCTION (id->dst_fn)->has_simduid_loops = true;
1913 : 134 : break;
1914 : : default:
1915 : : break;
1916 : : }
1917 : : }
1918 : :
1919 : : /* Remap the region numbers for __builtin_eh_{pointer,filter},
1920 : : RESX and EH_DISPATCH. */
1921 : 29835985 : if (id->eh_map)
1922 : 29835985 : switch (gimple_code (copy))
1923 : : {
1924 : 4482117 : case GIMPLE_CALL:
1925 : 4482117 : {
1926 : 4482117 : tree r, fndecl = gimple_call_fndecl (copy);
1927 : 4482117 : if (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
1928 : 1184296 : 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 : 7664 : case BUILT_IN_EH_POINTER:
1937 : 7664 : case BUILT_IN_EH_FILTER:
1938 : 7664 : r = gimple_call_arg (copy, 0);
1939 : 7664 : r = remap_eh_region_tree_nr (r, id);
1940 : 7664 : gimple_call_set_arg (copy, 0, r);
1941 : 7664 : 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 : 4482117 : if (!id->src_cfun->gimple_df
1950 : 4482117 : || !id->src_cfun->gimple_df->ipa_pta)
1951 : 4475580 : gimple_call_reset_alias_info (as_a <gcall *> (copy));
1952 : : }
1953 : : break;
1954 : :
1955 : 88126 : case GIMPLE_RESX:
1956 : 88126 : {
1957 : 88126 : gresx *resx_stmt = as_a <gresx *> (copy);
1958 : 88126 : int r = gimple_resx_region (resx_stmt);
1959 : 88126 : r = remap_eh_region_nr (r, id);
1960 : 88126 : gimple_resx_set_region (resx_stmt, r);
1961 : : }
1962 : 88126 : break;
1963 : :
1964 : 8970 : case GIMPLE_EH_DISPATCH:
1965 : 8970 : {
1966 : 8970 : geh_dispatch *eh_dispatch = as_a <geh_dispatch *> (copy);
1967 : 8970 : int r = gimple_eh_dispatch_region (eh_dispatch);
1968 : 8970 : r = remap_eh_region_nr (r, id);
1969 : 8970 : gimple_eh_dispatch_set_region (eh_dispatch, r);
1970 : : }
1971 : 8970 : break;
1972 : :
1973 : : default:
1974 : : break;
1975 : : }
1976 : : }
1977 : :
1978 : : /* If STMT has a block defined, map it to the newly constructed block. */
1979 : 31910429 : if (tree block = gimple_block (copy))
1980 : : {
1981 : 28883864 : tree *n;
1982 : 28883864 : n = id->decl_map->get (block);
1983 : 28883864 : gcc_assert (n);
1984 : 28883864 : gimple_set_block (copy, *n);
1985 : : }
1986 : 31910429 : if (id->param_body_adjs)
1987 : : {
1988 : 3161879 : gimple_seq extra_stmts = NULL;
1989 : 3161879 : id->param_body_adjs->modify_gimple_stmt (©, &extra_stmts, stmt);
1990 : 3161879 : if (!gimple_seq_empty_p (extra_stmts))
1991 : : {
1992 : 1 : memset (&wi, 0, sizeof (wi));
1993 : 1 : wi.info = id;
1994 : 1 : for (gimple_stmt_iterator egsi = gsi_start (extra_stmts);
1995 : 2 : !gsi_end_p (egsi);
1996 : 1 : gsi_next (&egsi))
1997 : 1 : walk_gimple_op (gsi_stmt (egsi), remap_gimple_op_r, &wi);
1998 : 1 : gimple_seq_add_seq_without_update (&stmts, extra_stmts);
1999 : : }
2000 : : }
2001 : :
2002 : 31910429 : if (id->reset_location)
2003 : 564 : gimple_set_location (copy, input_location);
2004 : :
2005 : : /* Debug statements ought to be rebuilt and not copied. */
2006 : 31910429 : gcc_checking_assert (!is_gimple_debug (copy));
2007 : :
2008 : : /* Remap all the operands in COPY. */
2009 : 31910429 : memset (&wi, 0, sizeof (wi));
2010 : 31910429 : wi.info = id;
2011 : 31910429 : if (skip_first)
2012 : 2074377 : walk_tree (gimple_op_ptr (copy, 1), remap_gimple_op_r, &wi, NULL);
2013 : : else
2014 : 29836052 : 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 : 31910429 : if (gimple_has_mem_ops (copy))
2019 : : {
2020 : 27614509 : gimple_set_vdef (copy, NULL_TREE);
2021 : 27614509 : gimple_set_vuse (copy, NULL_TREE);
2022 : : }
2023 : :
2024 : 31910429 : 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 : 1708407 : if (gcond *cond = dyn_cast <gcond *> (copy))
2030 : 198946 : 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 : 31910429 : gimple_seq_add_stmt_without_update (&stmts, copy);
2045 : 31910429 : 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 : 13485467 : copy_bb (copy_body_data *id, basic_block bb,
2054 : : profile_count num, profile_count den)
2055 : : {
2056 : 13485467 : gimple_stmt_iterator gsi, copy_gsi, seq_gsi;
2057 : 13485467 : basic_block copy_basic_block;
2058 : 13485467 : tree decl;
2059 : 13485467 : basic_block prev;
2060 : :
2061 : 13485467 : profile_count::adjust_for_ipa_scaling (&num, &den);
2062 : :
2063 : : /* Search for previous copied basic block. */
2064 : 13485467 : prev = bb->prev_bb;
2065 : 13638105 : while (!prev->aux)
2066 : 152638 : prev = prev->prev_bb;
2067 : :
2068 : : /* create_basic_block() will append every new block to
2069 : : basic_block_info automatically. */
2070 : 13485467 : copy_basic_block = create_basic_block (NULL, (basic_block) prev->aux);
2071 : 13485467 : copy_basic_block->count = bb->count.apply_scale (num, den);
2072 : :
2073 : 13485467 : copy_gsi = gsi_start_bb (copy_basic_block);
2074 : :
2075 : 13485467 : unsigned min_cond_uid = 0;
2076 : 13485467 : 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 : 112185501 : for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2087 : : {
2088 : 85214567 : gimple_seq stmts;
2089 : 85214567 : gimple *stmt = gsi_stmt (gsi);
2090 : 85214567 : gimple *orig_stmt = stmt;
2091 : 85214567 : gimple_stmt_iterator stmts_gsi;
2092 : 85214567 : bool stmt_added = false;
2093 : :
2094 : 85214567 : id->regimplify = false;
2095 : 85214567 : stmts = remap_gimple_stmt (stmt, id);
2096 : :
2097 : 85214567 : if (gimple_seq_empty_p (stmts))
2098 : 2290086 : continue;
2099 : :
2100 : 82924663 : seq_gsi = copy_gsi;
2101 : :
2102 : 82924663 : for (stmts_gsi = gsi_start (stmts);
2103 : 165849328 : !gsi_end_p (stmts_gsi); )
2104 : : {
2105 : 82924665 : stmt = gsi_stmt (stmts_gsi);
2106 : :
2107 : : /* Advance iterator now before stmt is moved to seq_gsi. */
2108 : 82924665 : gsi_next (&stmts_gsi);
2109 : :
2110 : 82924665 : if (gimple_nop_p (stmt))
2111 : 182 : continue;
2112 : :
2113 : : /* If -fcondition-coverage is used, register the inlined conditions
2114 : : in the cond->expression mapping of the caller. The expression tag
2115 : : is shifted conditions from the two bodies are not mixed. */
2116 : 82924483 : 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 : 82924483 : gimple_duplicate_stmt_histograms (cfun, stmt, id->src_cfun,
2126 : : orig_stmt);
2127 : :
2128 : 82924483 : gsi_insert_after (&seq_gsi, stmt, GSI_NEW_STMT);
2129 : :
2130 : 82924483 : if (id->regimplify)
2131 : 5531 : gimple_regimplify_operands (stmt, &seq_gsi);
2132 : :
2133 : : stmt_added = true;
2134 : : }
2135 : :
2136 : 82924663 : if (!stmt_added)
2137 : 182 : continue;
2138 : :
2139 : : /* If copy_basic_block has been empty at the start of this iteration,
2140 : : call gsi_start_bb again to get at the newly added statements. */
2141 : 82924481 : if (gsi_end_p (copy_gsi))
2142 : 23763582 : copy_gsi = gsi_start_bb (copy_basic_block);
2143 : : else
2144 : 71042690 : 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 : 82924490 : do
2150 : : {
2151 : 82924490 : tree fn;
2152 : 82924490 : gcall *call_stmt;
2153 : :
2154 : 82924490 : stmt = gsi_stmt (copy_gsi);
2155 : 82924490 : call_stmt = dyn_cast <gcall *> (stmt);
2156 : 4482117 : if (call_stmt
2157 : 4482117 : && 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 : 82924185 : else if (call_stmt
2214 : 4481812 : && id->call_stmt
2215 : 3629802 : && (decl = gimple_call_fndecl (stmt))
2216 : 86435866 : && fndecl_built_in_p (decl, BUILT_IN_VA_ARG_PACK_LEN))
2217 : : {
2218 : : /* __builtin_va_arg_pack_len () should be replaced by
2219 : : the number of anonymous arguments. */
2220 : 147 : size_t nargs = gimple_call_num_args (id->call_stmt);
2221 : 147 : tree count, p;
2222 : 147 : gimple *new_stmt;
2223 : :
2224 : 423 : for (p = DECL_ARGUMENTS (id->src_fn); p; p = DECL_CHAIN (p))
2225 : 276 : nargs--;
2226 : :
2227 : 147 : if (!gimple_call_lhs (stmt))
2228 : : {
2229 : : /* Drop unused calls. */
2230 : 1 : gsi_remove (©_gsi, false);
2231 : 1 : continue;
2232 : : }
2233 : 146 : else if (!gimple_call_va_arg_pack_p (id->call_stmt))
2234 : : {
2235 : 124 : count = build_int_cst (integer_type_node, nargs);
2236 : 124 : new_stmt = gimple_build_assign (gimple_call_lhs (stmt), count);
2237 : 124 : gsi_replace (©_gsi, new_stmt, false);
2238 : 124 : stmt = new_stmt;
2239 : : }
2240 : 22 : else if (nargs != 0)
2241 : : {
2242 : 7 : tree newlhs = make_ssa_name (integer_type_node);
2243 : 7 : count = build_int_cst (integer_type_node, nargs);
2244 : 7 : new_stmt = gimple_build_assign (gimple_call_lhs (stmt),
2245 : : PLUS_EXPR, newlhs, count);
2246 : 7 : gimple_call_set_lhs (stmt, newlhs);
2247 : 7 : gsi_insert_after (©_gsi, new_stmt, GSI_NEW_STMT);
2248 : : }
2249 : : }
2250 : 82924038 : else if (call_stmt
2251 : 4481665 : && id->call_stmt
2252 : 86553693 : && gimple_call_internal_p (stmt))
2253 : 25429 : switch (gimple_call_internal_fn (stmt))
2254 : : {
2255 : 107 : case IFN_TSAN_FUNC_EXIT:
2256 : : /* Drop .TSAN_FUNC_EXIT () internal calls during inlining. */
2257 : 107 : gsi_remove (©_gsi, false);
2258 : 107 : continue;
2259 : 1044 : case IFN_ASAN_MARK:
2260 : : /* Drop .ASAN_MARK internal calls during inlining into
2261 : : no_sanitize functions. */
2262 : 1044 : if (!sanitize_flags_p (SANITIZE_ADDRESS, id->dst_fn)
2263 : 1044 : && !sanitize_flags_p (SANITIZE_HWADDRESS, id->dst_fn))
2264 : : {
2265 : 14 : gsi_remove (©_gsi, false);
2266 : 14 : continue;
2267 : : }
2268 : : break;
2269 : : default:
2270 : : break;
2271 : : }
2272 : :
2273 : : /* Statements produced by inlining can be unfolded, especially
2274 : : when we constant propagated some operands. We can't fold
2275 : : them right now for two reasons:
2276 : : 1) folding require SSA_NAME_DEF_STMTs to be correct
2277 : : 2) we can't change function calls to builtins.
2278 : : So we just mark statement for later folding. We mark
2279 : : all new statements, instead just statements that has changed
2280 : : by some nontrivial substitution so even statements made
2281 : : foldable indirectly are updated. If this turns out to be
2282 : : expensive, copy_body can be told to watch for nontrivial
2283 : : changes. */
2284 : 82924368 : if (id->statements_to_fold)
2285 : 82924368 : 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 : 82924368 : if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
2290 : : {
2291 : 4481871 : struct cgraph_edge *edge;
2292 : :
2293 : 4481871 : switch (id->transform_call_graph_edges)
2294 : : {
2295 : 3629861 : case CB_CGE_DUPLICATE:
2296 : 3629861 : edge = id->src_node->get_edge (orig_stmt);
2297 : 3629861 : if (edge)
2298 : : {
2299 : 3604553 : 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 : 3604553 : if (edge->speculative)
2306 : : {
2307 : 9703 : int n = 0;
2308 : 9703 : profile_count direct_cnt
2309 : 9703 : = profile_count::zero ();
2310 : :
2311 : : /* First figure out the distribution of counts
2312 : : so we can re-scale BB profile accordingly. */
2313 : 19407 : for (cgraph_edge *e = old_edge; e;
2314 : 9704 : e = e->next_speculative_call_target ())
2315 : 9704 : direct_cnt = direct_cnt + e->count;
2316 : :
2317 : 9703 : cgraph_edge *indirect
2318 : 9703 : = old_edge->speculative_call_indirect_edge ();
2319 : 9703 : profile_count indir_cnt = indirect->count;
2320 : :
2321 : : /* Next iterate all direct edges, clone it and its
2322 : : corresponding reference and update profile. */
2323 : 9703 : for (cgraph_edge *e = old_edge;
2324 : 19407 : e;
2325 : 9704 : e = e->next_speculative_call_target ())
2326 : : {
2327 : 9704 : profile_count cnt = e->count;
2328 : :
2329 : 9704 : id->dst_node->clone_reference
2330 : 9704 : (e->speculative_call_target_ref (), stmt);
2331 : 9704 : edge = e->clone (id->dst_node, call_stmt,
2332 : : gimple_uid (stmt), num, den,
2333 : : true);
2334 : 9704 : profile_probability prob
2335 : 9704 : = cnt.probability_in (direct_cnt
2336 : : + indir_cnt);
2337 : 9704 : edge->count
2338 : : = copy_basic_block->count.apply_probability
2339 : 9704 : (prob);
2340 : 9704 : n++;
2341 : : }
2342 : 9703 : 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 : 9703 : indirect = indirect->clone (id->dst_node, call_stmt,
2349 : : gimple_uid (stmt),
2350 : : num, den,
2351 : : true);
2352 : :
2353 : 9703 : profile_probability prob
2354 : 9703 : = indir_cnt.probability_in (direct_cnt
2355 : : + indir_cnt);
2356 : 9703 : indirect->count
2357 : 9703 : = copy_basic_block->count.apply_probability (prob);
2358 : : }
2359 : : else
2360 : : {
2361 : 3594850 : edge = edge->clone (id->dst_node, call_stmt,
2362 : : gimple_uid (stmt),
2363 : : num, den,
2364 : : true);
2365 : 3594850 : edge->count = copy_basic_block->count;
2366 : : }
2367 : : }
2368 : : break;
2369 : :
2370 : 663690 : case CB_CGE_MOVE_CLONES:
2371 : 663690 : id->dst_node->set_call_stmt_including_clones (orig_stmt,
2372 : : call_stmt);
2373 : 663690 : edge = id->dst_node->get_edge (stmt);
2374 : 663690 : break;
2375 : :
2376 : 188320 : case CB_CGE_MOVE:
2377 : 188320 : edge = id->dst_node->get_edge (orig_stmt);
2378 : 188320 : if (edge)
2379 : 188125 : 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 : 3594850 : if ((!edge
2389 : 4353043 : || (edge->indirect_inlining_edge
2390 : 3310 : && id->transform_call_graph_edges == CB_CGE_MOVE_CLONES))
2391 : 129270 : && id->dst_node->definition
2392 : 892376 : && (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 : 4481871 : notice_special_calls (as_a <gcall *> (stmt));
2422 : : }
2423 : :
2424 : 82924368 : maybe_duplicate_eh_stmt_fn (cfun, stmt, id->src_cfun, orig_stmt,
2425 : : id->eh_map, id->eh_lp_nr);
2426 : :
2427 : 82924368 : gsi_next (©_gsi);
2428 : : }
2429 : 82924490 : while (!gsi_end_p (copy_gsi));
2430 : :
2431 : 165848962 : copy_gsi = gsi_last_bb (copy_basic_block);
2432 : : }
2433 : :
2434 : 13485467 : 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 : 711512 : update_ssa_across_abnormal_edges (basic_block bb, basic_block ret_bb,
2457 : : bool can_throw, bool nonlocal_goto)
2458 : : {
2459 : 711512 : edge e;
2460 : 711512 : edge_iterator ei;
2461 : :
2462 : 1965564 : FOR_EACH_EDGE (e, ei, bb->succs)
2463 : 1254052 : if (!e->dest->aux
2464 : 700704 : || ((basic_block)e->dest->aux)->index == ENTRY_BLOCK)
2465 : : {
2466 : 553348 : gphi *phi;
2467 : 553348 : gphi_iterator si;
2468 : :
2469 : 553348 : if (!nonlocal_goto)
2470 : 553107 : gcc_assert (e->flags & EDGE_EH);
2471 : :
2472 : 553348 : if (!can_throw)
2473 : 186 : gcc_assert (!(e->flags & EDGE_EH));
2474 : :
2475 : 929149 : for (si = gsi_start_phis (e->dest); !gsi_end_p (si); gsi_next (&si))
2476 : : {
2477 : 375801 : edge re;
2478 : :
2479 : 375801 : 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 : 375801 : gcc_assert ((e->flags & EDGE_EH)
2485 : : || SSA_NAME_OCCURS_IN_ABNORMAL_PHI (PHI_RESULT (phi)));
2486 : :
2487 : 375801 : re = find_edge (ret_bb, e->dest);
2488 : 375801 : gcc_checking_assert (re);
2489 : 375801 : gcc_assert ((re->flags & (EDGE_EH | EDGE_ABNORMAL))
2490 : : == (e->flags & (EDGE_EH | EDGE_ABNORMAL)));
2491 : :
2492 : 375801 : 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 : 711512 : }
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 : 407540 : add_clobbers_to_eh_landing_pad (copy_body_data *id)
2503 : : {
2504 : 407540 : tree var;
2505 : 407540 : basic_block bb = id->eh_landing_pad_dest;
2506 : 407540 : live_vars_map *vars = NULL;
2507 : 407540 : unsigned int cnt = 0;
2508 : 407540 : unsigned int i;
2509 : 938534 : FOR_EACH_VEC_SAFE_ELT (id->src_cfun->local_decls, i, var)
2510 : 530994 : if (VAR_P (var)
2511 : 530994 : && !DECL_HARD_REGISTER (var)
2512 : 530994 : && !TREE_THIS_VOLATILE (var)
2513 : 530974 : && !DECL_HAS_VALUE_EXPR_P (var)
2514 : 523126 : && !is_gimple_reg (var)
2515 : 226818 : && auto_var_in_fn_p (var, id->src_fn)
2516 : 755763 : && !lookup_attribute ("omp simd array", DECL_ATTRIBUTES (var)))
2517 : : {
2518 : 224769 : tree *t = id->decl_map->get (var);
2519 : 224769 : if (!t)
2520 : 0 : continue;
2521 : 224769 : tree new_var = *t;
2522 : 224769 : if (VAR_P (new_var)
2523 : 224769 : && !DECL_HARD_REGISTER (new_var)
2524 : 224769 : && !TREE_THIS_VOLATILE (new_var)
2525 : 224769 : && !DECL_HAS_VALUE_EXPR_P (new_var)
2526 : 224769 : && !is_gimple_reg (new_var)
2527 : 449538 : && auto_var_in_fn_p (new_var, id->dst_fn))
2528 : : {
2529 : 224769 : if (vars == NULL)
2530 : 126597 : vars = new live_vars_map;
2531 : 224769 : vars->put (DECL_UID (var), cnt++);
2532 : : }
2533 : : }
2534 : 407540 : if (vars == NULL)
2535 : 280943 : return;
2536 : :
2537 : 126597 : vec<bitmap_head> live = compute_live_vars (id->src_cfun, vars);
2538 : 460610 : FOR_EACH_VEC_SAFE_ELT (id->src_cfun->local_decls, i, var)
2539 : 334013 : if (VAR_P (var))
2540 : : {
2541 : 334013 : edge e;
2542 : 334013 : edge_iterator ei;
2543 : 334013 : bool needed = false;
2544 : 334013 : unsigned int *v = vars->get (DECL_UID (var));
2545 : 334013 : if (v == NULL)
2546 : 109244 : continue;
2547 : 4877889 : FOR_EACH_EDGE (e, ei, bb->preds)
2548 : 4785625 : if ((e->flags & EDGE_EH) != 0
2549 : 4785625 : && e->src->index >= id->add_clobbers_to_eh_landing_pads)
2550 : : {
2551 : 461876 : basic_block src_bb = (basic_block) e->src->aux;
2552 : :
2553 : 461876 : if (bitmap_bit_p (&live[src_bb->index], *v))
2554 : : {
2555 : : needed = true;
2556 : : break;
2557 : : }
2558 : : }
2559 : 224769 : if (needed)
2560 : : {
2561 : 132505 : tree new_var = *id->decl_map->get (var);
2562 : 132505 : gimple_stmt_iterator gsi = gsi_after_labels (bb);
2563 : 132505 : tree clobber = build_clobber (TREE_TYPE (new_var));
2564 : 132505 : gimple *clobber_stmt = gimple_build_assign (new_var, clobber);
2565 : 132505 : gsi_insert_before (&gsi, clobber_stmt, GSI_NEW_STMT);
2566 : : }
2567 : : }
2568 : 126597 : destroy_live_vars (live);
2569 : 126597 : 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 : 22612741 : 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 : 22612741 : basic_block new_bb = (basic_block) bb->aux;
2583 : 22612741 : edge_iterator ei;
2584 : 22612741 : edge old_edge;
2585 : 22612741 : gimple_stmt_iterator si;
2586 : 22612741 : bool need_debug_cleanup = false;
2587 : :
2588 : : /* Use the indices from the original blocks to create edges for the
2589 : : new ones. */
2590 : 43544685 : FOR_EACH_EDGE (old_edge, ei, bb->succs)
2591 : 20931944 : if (!(old_edge->flags & EDGE_EH))
2592 : : {
2593 : 20773573 : edge new_edge;
2594 : 20773573 : int flags = old_edge->flags;
2595 : 20773573 : location_t locus = old_edge->goto_locus;
2596 : :
2597 : : /* Return edges do get a FALLTHRU flag when they get inlined. */
2598 : 20773573 : if (old_edge->dest->index == EXIT_BLOCK
2599 : 4548464 : && !(flags & (EDGE_TRUE_VALUE|EDGE_FALSE_VALUE|EDGE_FAKE))
2600 : 4548464 : && old_edge->dest->aux != EXIT_BLOCK_PTR_FOR_FN (cfun))
2601 : 4336870 : flags |= EDGE_FALLTHRU;
2602 : :
2603 : 20773573 : new_edge
2604 : 20773573 : = make_edge (new_bb, (basic_block) old_edge->dest->aux, flags);
2605 : 20773573 : new_edge->probability = old_edge->probability;
2606 : 20773573 : if (!id->reset_location)
2607 : 20773192 : new_edge->goto_locus = remap_location (locus, id);
2608 : : }
2609 : :
2610 : 22612741 : 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 : 13485467 : if (single_succ_p (bb) && single_succ_edge (bb)->dest->index == EXIT_BLOCK)
2616 : 10720051 : FOR_EACH_EDGE (old_edge, ei, bb->preds)
2617 : 6171587 : if (old_edge->src->index != ENTRY_BLOCK
2618 : 3412976 : && !old_edge->src->aux)
2619 : 45777 : 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 : 13485467 : bool seen_nondebug = false;
2625 : 13485467 : for (si = gsi_last_bb (new_bb); !gsi_end_p (si);)
2626 : : {
2627 : 82924375 : bool can_throw, nonlocal_goto;
2628 : 82924375 : gimple *copy_stmt = gsi_stmt (si);
2629 : :
2630 : : /* Do this before the possible split_block. */
2631 : 82924375 : 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 : 82924375 : can_throw = stmt_can_throw_internal (cfun, copy_stmt);
2645 : 82924375 : nonlocal_goto
2646 : 82924375 : = (stmt_can_make_abnormal_goto (copy_stmt)
2647 : 82924375 : && !computed_goto_p (copy_stmt));
2648 : :
2649 : 82924089 : 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 : 711580 : 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 : 243101 : edge e = split_block (new_bb, copy_stmt);
2660 : 243101 : e->dest->aux = new_bb->aux;
2661 : 243101 : seen_nondebug = false;
2662 : : }
2663 : : }
2664 : :
2665 : 82924375 : if (!is_gimple_debug (copy_stmt))
2666 : 31910141 : seen_nondebug = true;
2667 : :
2668 : 82924375 : bool update_probs = false;
2669 : :
2670 : 82924375 : if (gimple_code (copy_stmt) == GIMPLE_EH_DISPATCH)
2671 : : {
2672 : 8970 : make_eh_dispatch_edges (as_a <geh_dispatch *> (copy_stmt));
2673 : 8970 : update_probs = true;
2674 : : }
2675 : 82915405 : else if (can_throw)
2676 : : {
2677 : 711326 : make_eh_edge (copy_stmt);
2678 : 711326 : update_probs = true;
2679 : : }
2680 : :
2681 : : /* EH edges may not match old edges. Copy as much as possible. */
2682 : 720296 : if (update_probs)
2683 : : {
2684 : 720296 : edge e;
2685 : 720296 : edge_iterator ei;
2686 : 720296 : basic_block copy_stmt_bb = gimple_bb (copy_stmt);
2687 : :
2688 : 1469523 : FOR_EACH_EDGE (old_edge, ei, bb->succs)
2689 : 749227 : if ((old_edge->flags & EDGE_EH)
2690 : 167699 : && (e = find_edge (copy_stmt_bb,
2691 : 167699 : (basic_block) old_edge->dest->aux))
2692 : 907423 : && (e->flags & EDGE_EH))
2693 : 158196 : e->probability = old_edge->probability;
2694 : :
2695 : 1983918 : FOR_EACH_EDGE (e, ei, copy_stmt_bb->succs)
2696 : 1263622 : if (e->flags & EDGE_EH)
2697 : : {
2698 : 711326 : if (!e->probability.initialized_p ())
2699 : 553351 : e->probability = profile_probability::never ();
2700 : 711326 : if (e->dest->index < id->add_clobbers_to_eh_landing_pads)
2701 : : {
2702 : 552410 : if (id->eh_landing_pad_dest == NULL)
2703 : 407540 : id->eh_landing_pad_dest = e->dest;
2704 : : else
2705 : 144870 : 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 : 82924375 : if (abnormal_goto_dest == NULL)
2715 : : nonlocal_goto = false;
2716 : 743 : if (nonlocal_goto)
2717 : : {
2718 : 218 : basic_block copy_stmt_bb = gimple_bb (copy_stmt);
2719 : :
2720 : 218 : if (get_abnormal_succ_dispatcher (copy_stmt_bb))
2721 : : nonlocal_goto = false;
2722 : : /* ABNORMAL_DISPATCHER (1) is for longjmp/setjmp or nonlocal gotos
2723 : : in OpenMP regions which aren't allowed to be left abnormally.
2724 : : So, no need to add abnormal edge in that case. */
2725 : 218 : else if (is_gimple_call (copy_stmt)
2726 : 218 : && gimple_call_internal_p (copy_stmt)
2727 : 0 : && (gimple_call_internal_fn (copy_stmt)
2728 : : == IFN_ABNORMAL_DISPATCHER)
2729 : 218 : && gimple_call_arg (copy_stmt, 0) == boolean_true_node)
2730 : : nonlocal_goto = false;
2731 : : else
2732 : : {
2733 : 218 : make_single_succ_edge (copy_stmt_bb, abnormal_goto_dest,
2734 : : EDGE_ABNORMAL);
2735 : 218 : gimple_call_set_ctrl_altering (copy_stmt, true);
2736 : : }
2737 : : }
2738 : :
2739 : 82924375 : if ((can_throw || nonlocal_goto)
2740 : 179334217 : && gimple_in_ssa_p (cfun))
2741 : 711512 : update_ssa_across_abnormal_edges (gimple_bb (copy_stmt), ret_bb,
2742 : : can_throw, nonlocal_goto);
2743 : : }
2744 : : return need_debug_cleanup;
2745 : : }
2746 : :
2747 : : /* Copy the PHIs. All blocks and edges are copied, some blocks
2748 : : was possibly split and new outgoing EH edges inserted.
2749 : : BB points to the block of original function and AUX pointers links
2750 : : the original and newly copied blocks. */
2751 : :
2752 : : static void
2753 : 22612741 : copy_phis_for_bb (basic_block bb, copy_body_data *id)
2754 : : {
2755 : 22612741 : basic_block const new_bb = (basic_block) bb->aux;
2756 : 22612741 : edge_iterator ei;
2757 : 22612741 : gphi *phi;
2758 : 22612741 : gphi_iterator si;
2759 : 22612741 : edge new_edge;
2760 : 22612741 : bool inserted = false;
2761 : :
2762 : 25509944 : for (si = gsi_start_phis (bb); !gsi_end_p (si); gsi_next (&si))
2763 : : {
2764 : 2897203 : tree res, new_res;
2765 : 2897203 : gphi *new_phi;
2766 : :
2767 : 2897203 : phi = si.phi ();
2768 : 2897203 : res = PHI_RESULT (phi);
2769 : 2897203 : new_res = res;
2770 : 2897203 : if (!virtual_operand_p (res)
2771 : 2897203 : && (!id->param_body_adjs
2772 : 1484897 : || !id->param_body_adjs->m_dead_stmts.contains (phi)))
2773 : : {
2774 : 1594130 : walk_tree (&new_res, copy_tree_body_r, id, NULL);
2775 : 1594130 : if (EDGE_COUNT (new_bb->preds) == 0)
2776 : : {
2777 : : /* Technically we'd want a SSA_DEFAULT_DEF here... */
2778 : 3 : SSA_NAME_DEF_STMT (new_res) = gimple_build_nop ();
2779 : : }
2780 : : else
2781 : : {
2782 : 1594127 : new_phi = create_phi_node (new_res, new_bb);
2783 : 5142573 : FOR_EACH_EDGE (new_edge, ei, new_bb->preds)
2784 : : {
2785 : 3548446 : edge old_edge = find_edge ((basic_block) new_edge->src->aux,
2786 : 3548446 : bb);
2787 : 3548446 : tree arg;
2788 : 3548446 : tree new_arg;
2789 : 3548446 : edge_iterator ei2;
2790 : 3548446 : location_t locus;
2791 : :
2792 : : /* When doing partial cloning, we allow PHIs on the entry
2793 : : block as long as all the arguments are the same.
2794 : : Find any input edge to see argument to copy. */
2795 : 3548446 : if (!old_edge)
2796 : 1977 : FOR_EACH_EDGE (old_edge, ei2, bb->preds)
2797 : 1977 : if (!old_edge->src->aux)
2798 : : break;
2799 : :
2800 : 3548446 : arg = PHI_ARG_DEF_FROM_EDGE (phi, old_edge);
2801 : 3548446 : new_arg = arg;
2802 : 3548446 : walk_tree (&new_arg, copy_tree_body_r, id, NULL);
2803 : 3548446 : gcc_assert (new_arg);
2804 : : /* With return slot optimization we can end up with
2805 : : non-gimple (foo *)&this->m, fix that here. */
2806 : 3548446 : if (TREE_CODE (new_arg) != SSA_NAME
2807 : 1457379 : && TREE_CODE (new_arg) != FUNCTION_DECL
2808 : 5005825 : && !is_gimple_val (new_arg))
2809 : : {
2810 : 12 : gimple_seq stmts = NULL;
2811 : 12 : new_arg = force_gimple_operand (new_arg, &stmts, true,
2812 : : NULL);
2813 : 12 : gsi_insert_seq_on_edge (new_edge, stmts);
2814 : 12 : inserted = true;
2815 : : }
2816 : 3548446 : locus = gimple_phi_arg_location_from_edge (phi, old_edge);
2817 : 3548446 : if (id->reset_location)
2818 : 0 : locus = input_location;
2819 : : else
2820 : 3548446 : locus = remap_location (locus, id);
2821 : 3548446 : add_phi_arg (new_phi, new_arg, new_edge, locus);
2822 : : }
2823 : : }
2824 : : }
2825 : : }
2826 : :
2827 : : /* Commit the delayed edge insertions. */
2828 : 22612741 : if (inserted)
2829 : 36 : FOR_EACH_EDGE (new_edge, ei, new_bb->preds)
2830 : 24 : gsi_commit_one_edge_insert (new_edge, NULL);
2831 : 22612741 : }
2832 : :
2833 : :
2834 : : /* Wrapper for remap_decl so it can be used as a callback. */
2835 : :
2836 : : static tree
2837 : 107700 : remap_decl_1 (tree decl, void *data)
2838 : : {
2839 : 107700 : return remap_decl (decl, (copy_body_data *) data);
2840 : : }
2841 : :
2842 : : /* Build struct function and associated datastructures for the new clone
2843 : : NEW_FNDECL to be build. CALLEE_FNDECL is the original. Function changes
2844 : : the cfun to the function of new_fndecl (and current_function_decl too). */
2845 : :
2846 : : static void
2847 : 225405 : initialize_cfun (tree new_fndecl, tree callee_fndecl, profile_count count)
2848 : : {
2849 : 225405 : struct function *src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl);
2850 : :
2851 : : /* Register specific tree functions. */
2852 : 225405 : gimple_register_cfg_hooks ();
2853 : :
2854 : : /* Get clean struct function. */
2855 : 225405 : push_struct_function (new_fndecl, true);
2856 : 225405 : targetm.target_option.relayout_function (new_fndecl);
2857 : :
2858 : : /* We will rebuild these, so just sanity check that they are empty. */
2859 : 225405 : gcc_assert (VALUE_HISTOGRAMS (cfun) == NULL);
2860 : 225405 : gcc_assert (cfun->local_decls == NULL);
2861 : 225405 : gcc_assert (cfun->cfg == NULL);
2862 : 225405 : gcc_assert (cfun->decl == new_fndecl);
2863 : :
2864 : : /* Copy items we preserve during cloning. */
2865 : 225405 : cfun->static_chain_decl = src_cfun->static_chain_decl;
2866 : 225405 : cfun->nonlocal_goto_save_area = src_cfun->nonlocal_goto_save_area;
2867 : 225405 : cfun->function_end_locus = src_cfun->function_end_locus;
2868 : 225405 : cfun->curr_properties = src_cfun->curr_properties;
2869 : 225405 : cfun->va_list_gpr_size = src_cfun->va_list_gpr_size;
2870 : 225405 : cfun->va_list_fpr_size = src_cfun->va_list_fpr_size;
2871 : 225405 : cfun->has_nonlocal_label = src_cfun->has_nonlocal_label;
2872 : 225405 : cfun->calls_eh_return = src_cfun->calls_eh_return;
2873 : 225405 : cfun->stdarg = src_cfun->stdarg;
2874 : 225405 : cfun->after_inlining = src_cfun->after_inlining;
2875 : 225405 : cfun->can_throw_non_call_exceptions
2876 : 225405 : = src_cfun->can_throw_non_call_exceptions;
2877 : 225405 : cfun->can_delete_dead_exceptions = src_cfun->can_delete_dead_exceptions;
2878 : 225405 : cfun->returns_struct = src_cfun->returns_struct;
2879 : 225405 : cfun->returns_pcc_struct = src_cfun->returns_pcc_struct;
2880 : :
2881 : 225405 : init_empty_tree_cfg ();
2882 : :
2883 : 225405 : profile_status_for_fn (cfun) = profile_status_for_fn (src_cfun);
2884 : 225405 : cfun->cfg->full_profile = src_cfun->cfg->full_profile;
2885 : :
2886 : 225405 : profile_count num = count;
2887 : 225405 : profile_count den = ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count;
2888 : 225405 : profile_count::adjust_for_ipa_scaling (&num, &den);
2889 : :
2890 : 225405 : ENTRY_BLOCK_PTR_FOR_FN (cfun)->count =
2891 : 225405 : ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count.apply_scale (count,
2892 : : ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count);
2893 : 225405 : EXIT_BLOCK_PTR_FOR_FN (cfun)->count =
2894 : 225405 : EXIT_BLOCK_PTR_FOR_FN (src_cfun)->count.apply_scale (count,
2895 : 225405 : ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count);
2896 : 225405 : if (src_cfun->eh)
2897 : 225405 : init_eh_for_function ();
2898 : :
2899 : 225405 : if (src_cfun->gimple_df)
2900 : : {
2901 : 225405 : init_tree_ssa (cfun);
2902 : 225405 : cfun->gimple_df->in_ssa_p = src_cfun->gimple_df->in_ssa_p;
2903 : 225405 : if (cfun->gimple_df->in_ssa_p)
2904 : 225405 : init_ssa_operands (cfun);
2905 : : }
2906 : 225405 : }
2907 : :
2908 : : /* Helper function for copy_cfg_body. Move debug stmts from the end
2909 : : of NEW_BB to the beginning of successor basic blocks when needed. If the
2910 : : successor has multiple predecessors, reset them, otherwise keep
2911 : : their value. */
2912 : :
2913 : : static void
2914 : 1509701 : maybe_move_debug_stmts_to_successors (copy_body_data *id, basic_block new_bb)
2915 : : {
2916 : 1509701 : edge e;
2917 : 1509701 : edge_iterator ei;
2918 : 1509701 : gimple_stmt_iterator si = gsi_last_nondebug_bb (new_bb);
2919 : :
2920 : 1509701 : if (gsi_end_p (si)
2921 : 1581682 : || gsi_one_before_end_p (si)
2922 : 1679392 : || !(stmt_can_throw_internal (cfun, gsi_stmt (si))
2923 : 71981 : || stmt_can_make_abnormal_goto (gsi_stmt (si))))
2924 : 1483972 : return;
2925 : :
2926 : 77188 : FOR_EACH_EDGE (e, ei, new_bb->succs)
2927 : : {
2928 : 51459 : gimple_stmt_iterator ssi = gsi_last_bb (new_bb);
2929 : 51459 : gimple_stmt_iterator dsi = gsi_after_labels (e->dest);
2930 : 185651 : while (is_gimple_debug (gsi_stmt (ssi)))
2931 : : {
2932 : 134192 : gimple *stmt = gsi_stmt (ssi);
2933 : 134192 : gdebug *new_stmt;
2934 : 134192 : tree var;
2935 : 134192 : tree value;
2936 : :
2937 : : /* For the last edge move the debug stmts instead of copying
2938 : : them. */
2939 : 134192 : if (ei_one_before_end_p (ei))
2940 : : {
2941 : 67095 : si = ssi;
2942 : 67095 : gsi_prev (&ssi);
2943 : 67095 : if (!single_pred_p (e->dest) && gimple_debug_bind_p (stmt))
2944 : : {
2945 : 65558 : gimple_debug_bind_reset_value (stmt);
2946 : 130449 : gimple_set_location (stmt, UNKNOWN_LOCATION);
2947 : : }
2948 : 67095 : gsi_remove (&si, false);
2949 : 67095 : gsi_insert_before (&dsi, stmt, GSI_NEW_STMT);
2950 : 67095 : continue;
2951 : : }
2952 : :
2953 : 67097 : if (gimple_debug_bind_p (stmt))
2954 : : {
2955 : 65560 : var = gimple_debug_bind_get_var (stmt);
2956 : 65560 : if (single_pred_p (e->dest))
2957 : : {
2958 : 48851 : value = gimple_debug_bind_get_value (stmt);
2959 : 48851 : value = unshare_expr (value);
2960 : 48851 : new_stmt = gimple_build_debug_bind (var, value, stmt);
2961 : : }
2962 : : else
2963 : 16709 : new_stmt = gimple_build_debug_bind (var, NULL_TREE, NULL);
2964 : : }
2965 : 1537 : else if (gimple_debug_source_bind_p (stmt))
2966 : : {
2967 : 0 : var = gimple_debug_source_bind_get_var (stmt);
2968 : 0 : value = gimple_debug_source_bind_get_value (stmt);
2969 : 0 : new_stmt = gimple_build_debug_source_bind (var, value, stmt);
2970 : : }
2971 : 1537 : else if (gimple_debug_nonbind_marker_p (stmt))
2972 : 1537 : new_stmt = as_a <gdebug *> (gimple_copy (stmt));
2973 : : else
2974 : 0 : gcc_unreachable ();
2975 : 67097 : gsi_insert_before (&dsi, new_stmt, GSI_NEW_STMT);
2976 : 67097 : id->debug_stmts.safe_push (new_stmt);
2977 : 67097 : gsi_prev (&ssi);
2978 : : }
2979 : : }
2980 : : }
2981 : :
2982 : : /* Make a copy of the sub-loops of SRC_PARENT and place them
2983 : : as siblings of DEST_PARENT. */
2984 : :
2985 : : static void
2986 : 5216245 : copy_loops (copy_body_data *id,
2987 : : class loop *dest_parent, class loop *src_parent)
2988 : : {
2989 : 5216245 : class loop *src_loop = src_parent->inner;
2990 : 5823811 : while (src_loop)
2991 : : {
2992 : 607566 : if (!id->blocks_to_copy
2993 : 607566 : || bitmap_bit_p (id->blocks_to_copy, src_loop->header->index))
2994 : : {
2995 : 604336 : class loop *dest_loop = alloc_loop ();
2996 : :
2997 : : /* Assign the new loop its header and latch and associate
2998 : : those with the new loop. */
2999 : 604336 : dest_loop->header = (basic_block)src_loop->header->aux;
3000 : 604336 : dest_loop->header->loop_father = dest_loop;
3001 : 604336 : if (src_loop->latch != NULL)
3002 : : {
3003 : 604320 : dest_loop->latch = (basic_block)src_loop->latch->aux;
3004 : 604320 : dest_loop->latch->loop_father = dest_loop;
3005 : : }
3006 : :
3007 : : /* Copy loop meta-data. */
3008 : 604336 : copy_loop_info (src_loop, dest_loop);
3009 : 604336 : if (dest_loop->unroll)
3010 : 2233 : cfun->has_unroll = true;
3011 : 604336 : if (dest_loop->force_vectorize)
3012 : 101 : cfun->has_force_vectorize_loops = true;
3013 : 604336 : if (id->src_cfun->last_clique != 0)
3014 : 68969 : dest_loop->owned_clique
3015 : 68969 : = remap_dependence_clique (id,
3016 : 68969 : src_loop->owned_clique
3017 : : ? src_loop->owned_clique : 1);
3018 : :
3019 : : /* Finally place it into the loop array and the loop tree. */
3020 : 604336 : place_new_loop (cfun, dest_loop);
3021 : 604336 : flow_loop_tree_node_add (dest_parent, dest_loop);
3022 : :
3023 : 604336 : if (src_loop->simduid)
3024 : : {
3025 : 53 : dest_loop->simduid = remap_decl (src_loop->simduid, id);
3026 : 53 : cfun->has_simduid_loops = true;
3027 : : }
3028 : :
3029 : : /* Recurse. */
3030 : 604336 : copy_loops (id, dest_loop, src_loop);
3031 : : }
3032 : 607566 : src_loop = src_loop->next;
3033 : : }
3034 : 5216245 : }
3035 : :
3036 : : /* Call redirect_call_stmt_to_callee on all calls in BB. */
3037 : :
3038 : : void
3039 : 12008973 : redirect_all_calls (copy_body_data * id, basic_block bb)
3040 : : {
3041 : 12008973 : gimple_stmt_iterator si;
3042 : 12008973 : gimple *last = last_nondebug_stmt (bb);
3043 : 96120055 : for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
3044 : : {
3045 : 72102109 : gimple *stmt = gsi_stmt (si);
3046 : 72102109 : if (is_gimple_call (stmt))
3047 : : {
3048 : 3649269 : struct cgraph_edge *edge = id->dst_node->get_edge (stmt);
3049 : 3649269 : if (edge)
3050 : : {
3051 : 3623961 : if (!id->killed_new_ssa_names)
3052 : 2005941 : id->killed_new_ssa_names = new hash_set<tree> (16);
3053 : 3623961 : cgraph_edge::redirect_call_stmt_to_callee (edge,
3054 : : id->killed_new_ssa_names);
3055 : :
3056 : 3623961 : if (stmt == last && id->call_stmt && maybe_clean_eh_stmt (stmt))
3057 : 37307 : gimple_purge_dead_eh_edges (bb);
3058 : : }
3059 : : }
3060 : : }
3061 : 12008973 : }
3062 : :
3063 : : /* Make a copy of the body of FN so that it can be inserted inline in
3064 : : another function. Walks FN via CFG, returns new fndecl. */
3065 : :
3066 : : static tree
3067 : 4611909 : copy_cfg_body (copy_body_data * id,
3068 : : basic_block entry_block_map, basic_block exit_block_map,
3069 : : basic_block new_entry)
3070 : : {
3071 : 4611909 : tree callee_fndecl = id->src_fn;
3072 : : /* Original cfun for the callee, doesn't change. */
3073 : 4611909 : struct function *src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl);
3074 : 4611909 : struct function *cfun_to_copy;
3075 : 4611909 : basic_block bb;
3076 : 4611909 : tree new_fndecl = NULL;
3077 : 4611909 : bool need_debug_cleanup = false;
3078 : 4611909 : int last;
3079 : 4611909 : profile_count den = ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count;
3080 : 4611909 : profile_count num = entry_block_map->count;
3081 : :
3082 : 4611909 : cfun_to_copy = id->src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl);
3083 : :
3084 : : /* Register specific tree functions. */
3085 : 4611909 : gimple_register_cfg_hooks ();
3086 : :
3087 : : /* If we are inlining just region of the function, make sure to connect
3088 : : new entry to ENTRY_BLOCK_PTR_FOR_FN (cfun). Since new entry can be
3089 : : part of loop, we must compute frequency and probability of
3090 : : ENTRY_BLOCK_PTR_FOR_FN (cfun) based on the frequencies and
3091 : : probabilities of edges incoming from nonduplicated region. */
3092 : 4611909 : if (new_entry)
3093 : : {
3094 : 48272 : edge e;
3095 : 48272 : edge_iterator ei;
3096 : 48272 : den = profile_count::zero ();
3097 : :
3098 : 105108 : FOR_EACH_EDGE (e, ei, new_entry->preds)
3099 : 56836 : if (!e->src->aux)
3100 : 56836 : den += e->count ();
3101 : 48272 : ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = den;
3102 : : }
3103 : :
3104 : 4611909 : profile_count::adjust_for_ipa_scaling (&num, &den);
3105 : :
3106 : : /* Must have a CFG here at this point. */
3107 : 4611909 : gcc_assert (ENTRY_BLOCK_PTR_FOR_FN
3108 : : (DECL_STRUCT_FUNCTION (callee_fndecl)));
3109 : :
3110 : :
3111 : 4611909 : ENTRY_BLOCK_PTR_FOR_FN (cfun_to_copy)->aux = entry_block_map;
3112 : 4611909 : EXIT_BLOCK_PTR_FOR_FN (cfun_to_copy)->aux = exit_block_map;
3113 : 4611909 : entry_block_map->aux = ENTRY_BLOCK_PTR_FOR_FN (cfun_to_copy);
3114 : 4611909 : exit_block_map->aux = EXIT_BLOCK_PTR_FOR_FN (cfun_to_copy);
3115 : :
3116 : : /* Duplicate any exception-handling regions. */
3117 : 4611909 : if (cfun->eh)
3118 : 4611909 : id->eh_map = duplicate_eh_regions (cfun_to_copy, NULL, id->eh_lp_nr,
3119 : : remap_decl_1, id);
3120 : :
3121 : : /* Use aux pointers to map the original blocks to copy. */
3122 : 18267619 : FOR_EACH_BB_FN (bb, cfun_to_copy)
3123 : 13655710 : if (!id->blocks_to_copy || bitmap_bit_p (id->blocks_to_copy, bb->index))
3124 : : {
3125 : 13485467 : basic_block new_bb = copy_bb (id, bb, num, den);
3126 : 13485467 : bb->aux = new_bb;
3127 : 13485467 : new_bb->aux = bb;
3128 : 13485467 : new_bb->loop_father = entry_block_map->loop_father;
3129 : : }
3130 : :
3131 : 4611909 : last = last_basic_block_for_fn (cfun);
3132 : :
3133 : : /* Now that we've duplicated the blocks, duplicate their edges. */
3134 : 4611909 : basic_block abnormal_goto_dest = NULL;
3135 : 4611909 : if (id->call_stmt
3136 : 4611909 : && stmt_can_make_abnormal_goto (id->call_stmt))
3137 : : {
3138 : 247 : gimple_stmt_iterator gsi = gsi_for_stmt (id->call_stmt);
3139 : :
3140 : 247 : bb = gimple_bb (id->call_stmt);
3141 : 247 : gsi_next (&gsi);
3142 : 247 : if (gsi_end_p (gsi))
3143 : 247 : abnormal_goto_dest = get_abnormal_succ_dispatcher (bb);
3144 : : }
3145 : 27491437 : FOR_ALL_BB_FN (bb, cfun_to_copy)
3146 : 22879528 : if (!id->blocks_to_copy
3147 : 22879528 : || (bb->index > 0 && bitmap_bit_p (id->blocks_to_copy, bb->index)))
3148 : 22612741 : need_debug_cleanup |= copy_edges_for_bb (bb, num, den, exit_block_map,
3149 : : abnormal_goto_dest, id);
3150 : :
3151 : 4611909 : if (id->eh_landing_pad_dest)
3152 : : {
3153 : 407540 : add_clobbers_to_eh_landing_pad (id);
3154 : 407540 : id->eh_landing_pad_dest = NULL;
3155 : : }
3156 : :
3157 : 4611909 : if (new_entry)
3158 : : {
3159 : 48272 : edge e = make_edge (entry_block_map, (basic_block)new_entry->aux,
3160 : : EDGE_FALLTHRU);
3161 : 48272 : e->probability = profile_probability::always ();
3162 : : }
3163 : :
3164 : : /* Duplicate the loop tree, if available and wanted. */
3165 : 4611909 : if (loops_for_fn (src_cfun) != NULL
3166 : 4611909 : && current_loops != NULL)
3167 : : {
3168 : 4611909 : copy_loops (id, entry_block_map->loop_father,
3169 : : get_loop (src_cfun, 0));
3170 : : /* Defer to cfgcleanup to update loop-father fields of basic-blocks. */
3171 : 4611909 : loops_state_set (LOOPS_NEED_FIXUP);
3172 : : }
3173 : :
3174 : : /* If the loop tree in the source function needed fixup, mark the
3175 : : destination loop tree for fixup, too. */
3176 : 4611909 : if (loops_for_fn (src_cfun)->state & LOOPS_NEED_FIXUP)
3177 : 3 : loops_state_set (LOOPS_NEED_FIXUP);
3178 : :
3179 : 4611909 : if (gimple_in_ssa_p (cfun))
3180 : 27491437 : FOR_ALL_BB_FN (bb, cfun_to_copy)
3181 : 22879528 : if (!id->blocks_to_copy
3182 : 22879528 : || (bb->index > 0 && bitmap_bit_p (id->blocks_to_copy, bb->index)))
3183 : 22612741 : copy_phis_for_bb (bb, id);
3184 : :
3185 : 27491437 : FOR_ALL_BB_FN (bb, cfun_to_copy)
3186 : 22879528 : if (bb->aux)
3187 : : {
3188 : 22709285 : if (need_debug_cleanup
3189 : 2017600 : && bb->index != ENTRY_BLOCK
3190 : 1718348 : && bb->index != EXIT_BLOCK)
3191 : 1419096 : maybe_move_debug_stmts_to_successors (id, (basic_block) bb->aux);
3192 : : /* Update call edge destinations. This cannot be done before loop
3193 : : info is updated, because we may split basic blocks. */
3194 : 22709285 : if (id->transform_call_graph_edges == CB_CGE_DUPLICATE
3195 : 20509768 : && bb->index != ENTRY_BLOCK
3196 : 16123264 : && bb->index != EXIT_BLOCK)
3197 : 11736760 : redirect_all_calls (id, (basic_block)bb->aux);
3198 : 22709285 : ((basic_block)bb->aux)->aux = NULL;
3199 : 22709285 : bb->aux = NULL;
3200 : : }
3201 : :
3202 : : /* Zero out AUX fields of newly created block during EH edge
3203 : : insertion. */
3204 : 4884122 : for (; last < last_basic_block_for_fn (cfun); last++)
3205 : : {
3206 : 272213 : if (need_debug_cleanup)
3207 : 90605 : maybe_move_debug_stmts_to_successors (id,
3208 : 90605 : BASIC_BLOCK_FOR_FN (cfun, last));
3209 : 272213 : BASIC_BLOCK_FOR_FN (cfun, last)->aux = NULL;
3210 : : /* Update call edge destinations. This cannot be done before loop
3211 : : info is updated, because we may split basic blocks. */
3212 : 272213 : if (id->transform_call_graph_edges == CB_CGE_DUPLICATE)
3213 : 272213 : redirect_all_calls (id, BASIC_BLOCK_FOR_FN (cfun, last));
3214 : : }
3215 : 4611909 : entry_block_map->aux = NULL;
3216 : 4611909 : exit_block_map->aux = NULL;
3217 : :
3218 : 4611909 : if (id->eh_map)
3219 : : {
3220 : 4611909 : delete id->eh_map;
3221 : 4611909 : id->eh_map = NULL;
3222 : : }
3223 : 4611909 : if (id->dependence_map)
3224 : : {
3225 : 755396 : delete id->dependence_map;
3226 : 755396 : id->dependence_map = NULL;
3227 : : }
3228 : :
3229 : 4611909 : return new_fndecl;
3230 : : }
3231 : :
3232 : : /* Copy the debug STMT using ID. We deal with these statements in a
3233 : : special way: if any variable in their VALUE expression wasn't
3234 : : remapped yet, we won't remap it, because that would get decl uids
3235 : : out of sync, causing codegen differences between -g and -g0. If
3236 : : this arises, we drop the VALUE expression altogether. */
3237 : :
3238 : : static void
3239 : 51081331 : copy_debug_stmt (gdebug *stmt, copy_body_data *id)
3240 : : {
3241 : 51081331 : tree t, *n;
3242 : 51081331 : struct walk_stmt_info wi;
3243 : :
3244 : 51081331 : if (tree block = gimple_block (stmt))
3245 : : {
3246 : 34239643 : n = id->decl_map->get (block);
3247 : 34239643 : gimple_set_block (stmt, n ? *n : id->block);
3248 : : }
3249 : :
3250 : 51081331 : if (gimple_debug_nonbind_marker_p (stmt))
3251 : : {
3252 : 12461038 : if (id->call_stmt && !gimple_block (stmt))
3253 : : {
3254 : 40211 : gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
3255 : 40211 : gsi_remove (&gsi, true);
3256 : : }
3257 : 12461038 : return;
3258 : : }
3259 : :
3260 : : /* Remap all the operands in COPY. */
3261 : 38620293 : memset (&wi, 0, sizeof (wi));
3262 : 38620293 : wi.info = id;
3263 : :
3264 : 38620293 : processing_debug_stmt = 1;
3265 : :
3266 : 38620293 : if (gimple_debug_source_bind_p (stmt))
3267 : 468245 : t = gimple_debug_source_bind_get_var (stmt);
3268 : 38152048 : else if (gimple_debug_bind_p (stmt))
3269 : 38152048 : t = gimple_debug_bind_get_var (stmt);
3270 : : else
3271 : 0 : gcc_unreachable ();
3272 : :
3273 : 38620293 : if (TREE_CODE (t) == PARM_DECL
3274 : 214188 : && id->debug_map
3275 : 38621717 : && (n = id->debug_map->get (t)))
3276 : : {
3277 : 0 : gcc_assert (VAR_P (*n));
3278 : 0 : t = *n;
3279 : : }
3280 : 38620293 : else if (VAR_P (t) && !is_global_var (t) && !id->decl_map->get (t))
3281 : : /* T is a non-localized variable. */;
3282 : : else
3283 : 34302432 : walk_tree (&t, remap_gimple_op_r, &wi, NULL);
3284 : :
3285 : 38620293 : if (gimple_debug_bind_p (stmt))
3286 : : {
3287 : 38152048 : gimple_debug_bind_set_var (stmt, t);
3288 : :
3289 : 38152048 : if (gimple_debug_bind_has_value_p (stmt))
3290 : 21572657 : walk_tree (gimple_debug_bind_get_value_ptr (stmt),
3291 : : remap_gimple_op_r, &wi, NULL);
3292 : :
3293 : : /* Punt if any decl couldn't be remapped. */
3294 : 38152048 : if (processing_debug_stmt < 0)
3295 : 702553 : gimple_debug_bind_reset_value (stmt);
3296 : : }
3297 : 468245 : else if (gimple_debug_source_bind_p (stmt))
3298 : : {
3299 : 468245 : gimple_debug_source_bind_set_var (stmt, t);
3300 : : /* When inlining and source bind refers to one of the optimized
3301 : : away parameters, change the source bind into normal debug bind
3302 : : referring to the corresponding DEBUG_EXPR_DECL that should have
3303 : : been bound before the call stmt. */
3304 : 468245 : t = gimple_debug_source_bind_get_value (stmt);
3305 : 468245 : if (t != NULL_TREE
3306 : 468245 : && TREE_CODE (t) == PARM_DECL
3307 : 350178 : && id->call_stmt)
3308 : : {
3309 : 346007 : vec<tree, va_gc> **debug_args = decl_debug_args_lookup (id->src_fn);
3310 : 346007 : unsigned int i;
3311 : 346007 : if (debug_args != NULL)
3312 : : {
3313 : 467516 : for (i = 0; i < vec_safe_length (*debug_args); i += 2)
3314 : 467515 : if ((**debug_args)[i] == DECL_ORIGIN (t)
3315 : 467515 : && TREE_CODE ((**debug_args)[i + 1]) == DEBUG_EXPR_DECL)
3316 : : {
3317 : 345112 : t = (**debug_args)[i + 1];
3318 : 345112 : stmt->subcode = GIMPLE_DEBUG_BIND;
3319 : 345112 : gimple_debug_bind_set_value (stmt, t);
3320 : 345112 : break;
3321 : : }
3322 : : }
3323 : : }
3324 : 468245 : if (gimple_debug_source_bind_p (stmt))
3325 : 123133 : walk_tree (gimple_debug_source_bind_get_value_ptr (stmt),
3326 : : remap_gimple_op_r, &wi, NULL);
3327 : : }
3328 : :
3329 : 38620293 : processing_debug_stmt = 0;
3330 : :
3331 : 38620293 : update_stmt (stmt);
3332 : : }
3333 : :
3334 : : /* Process deferred debug stmts. In order to give values better odds
3335 : : of being successfully remapped, we delay the processing of debug
3336 : : stmts until all other stmts that might require remapping are
3337 : : processed. */
3338 : :
3339 : : static void
3340 : 4611909 : copy_debug_stmts (copy_body_data *id)
3341 : : {
3342 : 4611909 : if (!id->debug_stmts.exists ())
3343 : : return;
3344 : :
3345 : 53980480 : for (gdebug *stmt : id->debug_stmts)
3346 : 51081331 : copy_debug_stmt (stmt, id);
3347 : :
3348 : 2899149 : id->debug_stmts.release ();
3349 : : }
3350 : :
3351 : : /* Make a copy of the body of SRC_FN so that it can be inserted inline in
3352 : : another function. */
3353 : :
3354 : : static tree
3355 : 17470458 : copy_tree_body (copy_body_data *id)
3356 : : {
3357 : 17470458 : tree fndecl = id->src_fn;
3358 : 17470458 : tree body = DECL_SAVED_TREE (fndecl);
3359 : :
3360 : 17470458 : walk_tree (&body, copy_tree_body_r, id, NULL);
3361 : :
3362 : 17470458 : return body;
3363 : : }
3364 : :
3365 : : /* Make a copy of the body of FN so that it can be inserted inline in
3366 : : another function. */
3367 : :
3368 : : static tree
3369 : 4611909 : copy_body (copy_body_data *id,
3370 : : basic_block entry_block_map, basic_block exit_block_map,
3371 : : basic_block new_entry)
3372 : : {
3373 : 4611909 : tree fndecl = id->src_fn;
3374 : 4611909 : tree body;
3375 : :
3376 : : /* If this body has a CFG, walk CFG and copy. */
3377 : 4611909 : gcc_assert (ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (fndecl)));
3378 : 4611909 : body = copy_cfg_body (id, entry_block_map, exit_block_map,
3379 : : new_entry);
3380 : 4611909 : copy_debug_stmts (id);
3381 : 4611909 : if (id->killed_new_ssa_names)
3382 : : {
3383 : 2005941 : ipa_release_ssas_in_hash (id->killed_new_ssa_names);
3384 : 4011882 : delete id->killed_new_ssa_names;
3385 : 2005941 : id->killed_new_ssa_names = NULL;
3386 : : }
3387 : :
3388 : 4611909 : return body;
3389 : : }
3390 : :
3391 : : /* Return true if VALUE is an ADDR_EXPR of an automatic variable
3392 : : defined in function FN, or of a data member thereof. */
3393 : :
3394 : : static bool
3395 : 89714 : self_inlining_addr_expr (tree value, tree fn)
3396 : : {
3397 : 89714 : tree var;
3398 : :
3399 : 89714 : if (TREE_CODE (value) != ADDR_EXPR)
3400 : : return false;
3401 : :
3402 : 83788 : var = get_base_address (TREE_OPERAND (value, 0));
3403 : :
3404 : 83788 : return var && auto_var_in_fn_p (var, fn);
3405 : : }
3406 : :
3407 : : /* Append to BB a debug annotation that binds VAR to VALUE, inheriting
3408 : : lexical block and line number information from base_stmt, if given,
3409 : : or from the last stmt of the block otherwise. */
3410 : :
3411 : : static gimple *
3412 : 7484998 : insert_init_debug_bind (copy_body_data *id,
3413 : : basic_block bb, tree var, tree value,
3414 : : gimple *base_stmt)
3415 : : {
3416 : 7484998 : gimple *note;
3417 : 7484998 : gimple_stmt_iterator gsi;
3418 : 7484998 : tree tracked_var;
3419 : :
3420 : 8995905 : if (!gimple_in_ssa_p (id->src_cfun))
3421 : : return NULL;
3422 : :
3423 : 7484998 : if (!opt_for_fn (id->dst_fn, flag_var_tracking_assignments))
3424 : : return NULL;
3425 : :
3426 : 6619828 : tracked_var = target_for_debug_bind (var);
3427 : 6619828 : if (!tracked_var)
3428 : : return NULL;
3429 : :
3430 : 5974091 : if (bb)
3431 : : {
3432 : 5968649 : gsi = gsi_last_bb (bb);
3433 : 5968649 : if (!base_stmt && !gsi_end_p (gsi))
3434 : 5974091 : base_stmt = gsi_stmt (gsi);
3435 : : }
3436 : :
3437 : 5974091 : note = gimple_build_debug_bind (tracked_var,
3438 : 5974091 : value == error_mark_node
3439 : 5974091 : ? NULL_TREE : unshare_expr (value),
3440 : : base_stmt);
3441 : :
3442 : 5974091 : if (bb)
3443 : : {
3444 : 5968649 : if (!gsi_end_p (gsi))
3445 : 5075830 : gsi_insert_after (&gsi, note, GSI_SAME_STMT);
3446 : : else
3447 : 892819 : gsi_insert_before (&gsi, note, GSI_SAME_STMT);
3448 : : }
3449 : :
3450 : : return note;
3451 : : }
3452 : :
3453 : : static void
3454 : 467600 : insert_init_stmt (copy_body_data *id, basic_block bb, gimple *init_stmt)
3455 : : {
3456 : : /* If VAR represents a zero-sized variable, it's possible that the
3457 : : assignment statement may result in no gimple statements. */
3458 : 467600 : if (init_stmt)
3459 : : {
3460 : 467600 : gimple_stmt_iterator si = gsi_last_bb (bb);
3461 : :
3462 : : /* We can end up with init statements that store to a non-register
3463 : : from a rhs with a conversion. Handle that here by forcing the
3464 : : rhs into a temporary. gimple_regimplify_operands is not
3465 : : prepared to do this for us. */
3466 : 467600 : if (!is_gimple_debug (init_stmt)
3467 : 462158 : && !is_gimple_reg (gimple_assign_lhs (init_stmt))
3468 : 360109 : && is_gimple_reg_type (TREE_TYPE (gimple_assign_lhs (init_stmt)))
3469 : 497335 : && gimple_assign_rhs_class (init_stmt) == GIMPLE_UNARY_RHS)
3470 : : {
3471 : 2 : tree rhs = build1 (gimple_assign_rhs_code (init_stmt),
3472 : 1 : TREE_TYPE (gimple_assign_lhs (init_stmt)),
3473 : : gimple_assign_rhs1 (init_stmt));
3474 : 1 : rhs = force_gimple_operand_gsi (&si, rhs, true, NULL_TREE, false,
3475 : : GSI_NEW_STMT);
3476 : 1 : gimple_assign_set_rhs_code (init_stmt, TREE_CODE (rhs));
3477 : 1 : gimple_assign_set_rhs1 (init_stmt, rhs);
3478 : : }
3479 : 467600 : gsi_insert_after (&si, init_stmt, GSI_NEW_STMT);
3480 : 467600 : if (!is_gimple_debug (init_stmt))
3481 : : {
3482 : 462158 : gimple_regimplify_operands (init_stmt, &si);
3483 : :
3484 : 462158 : tree def = gimple_assign_lhs (init_stmt);
3485 : 462158 : insert_init_debug_bind (id, bb, def, def, init_stmt);
3486 : : }
3487 : : }
3488 : 467600 : }
3489 : :
3490 : : /* Deal with mismatched formal/actual parameters, in a rather brute-force way
3491 : : if need be (which should only be necessary for invalid programs). Attempt
3492 : : to convert VAL to TYPE and return the result if it is possible, just return
3493 : : a zero constant of the given type if it fails. */
3494 : :
3495 : : tree
3496 : 2042 : force_value_to_type (tree type, tree value)
3497 : : {
3498 : : /* If we can match up types by promotion/demotion do so. */
3499 : 2042 : if (fold_convertible_p (type, value))
3500 : 533 : return fold_convert (type, value);
3501 : :
3502 : : /* ??? For valid programs we should not end up here.
3503 : : Still if we end up with truly mismatched types here, fall back
3504 : : to using a VIEW_CONVERT_EXPR or a literal zero to not leak invalid
3505 : : GIMPLE to the following passes. */
3506 : 1509 : if (TREE_CODE (value) == WITH_SIZE_EXPR)
3507 : 0 : return error_mark_node;
3508 : 1509 : else if (!is_gimple_reg_type (TREE_TYPE (value))
3509 : 1509 : || TYPE_SIZE (type) == TYPE_SIZE (TREE_TYPE (value)))
3510 : 1218 : return fold_build1 (VIEW_CONVERT_EXPR, type, value);
3511 : : else
3512 : 291 : return build_zero_cst (type);
3513 : : }
3514 : :
3515 : : /* Initialize parameter P with VALUE. If needed, produce init statement
3516 : : at the end of BB. When BB is NULL, we return init statement to be
3517 : : output later. */
3518 : : static gimple *
3519 : 7463903 : setup_one_parameter (copy_body_data *id, tree p, tree value, tree fn,
3520 : : basic_block bb, tree *vars)
3521 : : {
3522 : 7463903 : gimple *init_stmt = NULL;
3523 : 7463903 : tree var;
3524 : 7463903 : tree def = (gimple_in_ssa_p (cfun)
3525 : 7463903 : ? ssa_default_def (id->src_cfun, p) : NULL);
3526 : :
3527 : : /* Make an equivalent VAR_DECL. Note that we must NOT remap the type
3528 : : here since the type of this decl must be visible to the calling
3529 : : function. */
3530 : 7463903 : var = copy_decl_to_var (p, id);
3531 : :
3532 : : /* Declare this new variable. */
3533 : 7463903 : DECL_CHAIN (var) = *vars;
3534 : 7463903 : *vars = var;
3535 : :
3536 : : /* Make gimplifier happy about this variable. */
3537 : 7463903 : DECL_SEEN_IN_BIND_EXPR_P (var) = 1;
3538 : :
3539 : : /* If the parameter is never assigned to, has no SSA_NAMEs created,
3540 : : we would not need to create a new variable here at all, if it
3541 : : weren't for debug info. Still, we can just use the argument
3542 : : value. */
3543 : 7463903 : if (TREE_READONLY (p)
3544 : 4033242 : && !TREE_ADDRESSABLE (p)
3545 : 4031996 : && value
3546 : 4031987 : && !TREE_SIDE_EFFECTS (value)
3547 : 11495884 : && !def)
3548 : : {
3549 : : /* We may produce non-gimple trees by adding NOPs or introduce invalid
3550 : : sharing when the value is not constant or DECL. And we need to make
3551 : : sure that it cannot be modified from another path in the callee. */
3552 : 289355 : if (((is_gimple_min_invariant (value)
3553 : : /* When the parameter is used in a context that forces it to
3554 : : not be a GIMPLE register avoid substituting something that
3555 : : is not a decl there. */
3556 : 89445 : && ! DECL_NOT_GIMPLE_REG_P (p))
3557 : 199921 : || (DECL_P (value) && TREE_READONLY (value))
3558 : 199837 : || (auto_var_in_fn_p (value, id->dst_fn)
3559 : 202 : && !TREE_ADDRESSABLE (value)))
3560 : 89717 : && useless_type_conversion_p (TREE_TYPE (p), TREE_TYPE (value))
3561 : : /* We have to be very careful about ADDR_EXPR. Make sure
3562 : : the base variable isn't a local variable of the inlined
3563 : : function, e.g., when doing recursive inlining, direct or
3564 : : mutually-recursive or whatever, which is why we don't
3565 : : just test whether fn == current_function_decl. */
3566 : 379069 : && ! self_inlining_addr_expr (value, fn))
3567 : : {
3568 : 89714 : insert_decl_map (id, p, value);
3569 : 89714 : if (!id->debug_map)
3570 : 85404 : id->debug_map = new hash_map<tree, tree>;
3571 : 89714 : id->debug_map->put (p, var);
3572 : 89714 : return insert_init_debug_bind (id, bb, var, value, NULL);
3573 : : }
3574 : : }
3575 : :
3576 : : /* Register the VAR_DECL as the equivalent for the PARM_DECL;
3577 : : that way, when the PARM_DECL is encountered, it will be
3578 : : automatically replaced by the VAR_DECL. */
3579 : 7374189 : insert_decl_map (id, p, var);
3580 : :
3581 : : /* Even if P was TREE_READONLY, the new VAR should not be. In the original
3582 : : code, we would have constructed a temporary, and then the function body
3583 : : would have never changed the value of P. However, now, we will be
3584 : : constructing VAR directly. Therefore, it must not be TREE_READONLY. */
3585 : 7374189 : TREE_READONLY (var) = 0;
3586 : :
3587 : 7374189 : tree rhs = value;
3588 : 7374189 : if (value
3589 : 7373276 : && value != error_mark_node
3590 : 14747465 : && !useless_type_conversion_p (TREE_TYPE (p), TREE_TYPE (value)))
3591 : 2031 : rhs = force_value_to_type (TREE_TYPE (p), value);
3592 : :
3593 : : /* If there is no setup required and we are in SSA, take the easy route
3594 : : replacing all SSA names representing the function parameter by the
3595 : : SSA name passed to function.
3596 : :
3597 : : We need to construct map for the variable anyway as it might be used
3598 : : in different SSA names when parameter is set in function.
3599 : :
3600 : : Do replacement at -O0 for const arguments replaced by constant.
3601 : : This is important for builtin_constant_p and other construct requiring
3602 : : constant argument to be visible in inlined function body. */
3603 : 14748378 : if (gimple_in_ssa_p (cfun) && rhs && def && is_gimple_reg (p)
3604 : 6632180 : && (optimize
3605 : 23437 : || (TREE_READONLY (p)
3606 : 11421 : && is_gimple_min_invariant (rhs)))
3607 : 6612625 : && (TREE_CODE (rhs) == SSA_NAME
3608 : 2611252 : || is_gimple_min_invariant (rhs))
3609 : 6612346 : && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (def))
3610 : : {
3611 : 6612346 : insert_decl_map (id, def, rhs);
3612 : 6612346 : return insert_init_debug_bind (id, bb, var, rhs, NULL);
3613 : : }
3614 : :
3615 : : /* If the value of argument is never used, don't care about initializing
3616 : : it. */
3617 : 1500538 : if (optimize && gimple_in_ssa_p (cfun) && !def && is_gimple_reg (p))
3618 : : {
3619 : : /* When there's a gross type mismatch between the passed value
3620 : : and the declared argument type drop it on the floor and do
3621 : : not bother to insert a debug bind. */
3622 : 320794 : if (value && !is_gimple_reg_type (TREE_TYPE (value)))
3623 : : return NULL;
3624 : 320780 : return insert_init_debug_bind (id, bb, var, rhs, NULL);
3625 : : }
3626 : :
3627 : : /* Initialize this VAR_DECL from the equivalent argument. Convert
3628 : : the argument to the proper type in case it was promoted. */
3629 : 441049 : if (value)
3630 : : {
3631 : 440962 : if (rhs == error_mark_node)
3632 : : {
3633 : 0 : insert_decl_map (id, p, var);
3634 : 0 : return insert_init_debug_bind (id, bb, var, rhs, NULL);
3635 : : }
3636 : :
3637 : 440962 : STRIP_USELESS_TYPE_CONVERSION (rhs);
3638 : :
3639 : : /* If we are in SSA form properly remap the default definition. */
3640 : 881924 : if (gimple_in_ssa_p (cfun) && is_gimple_reg (p))
3641 : : {
3642 : 22581 : if (def)
3643 : : {
3644 : 19834 : def = remap_ssa_name (def, id);
3645 : 19834 : init_stmt = gimple_build_assign (def, rhs);
3646 : 19834 : SSA_NAME_IS_DEFAULT_DEF (def) = 0;
3647 : 19834 : set_ssa_default_def (cfun, var, NULL);
3648 : : }
3649 : : }
3650 : 418381 : else if (!is_empty_type (TREE_TYPE (var)))
3651 : 360109 : init_stmt = gimple_build_assign (var, rhs);
3652 : :
3653 : 440962 : if (bb && init_stmt)
3654 : 379503 : insert_init_stmt (id, bb, init_stmt);
3655 : : }
3656 : : return init_stmt;
3657 : : }
3658 : :
3659 : : /* Generate code to initialize the parameters of the function at the
3660 : : top of the stack in ID from the GIMPLE_CALL STMT. */
3661 : :
3662 : : static void
3663 : 4386504 : initialize_inlined_parameters (copy_body_data *id, gimple *stmt,
3664 : : tree fn, basic_block bb)
3665 : : {
3666 : 4386504 : tree parms;
3667 : 4386504 : size_t i;
3668 : 4386504 : tree p;
3669 : 4386504 : tree vars = NULL_TREE;
3670 : 4386504 : tree static_chain = gimple_call_chain (stmt);
3671 : :
3672 : : /* Figure out what the parameters are. */
3673 : 4386504 : parms = DECL_ARGUMENTS (fn);
3674 : :
3675 : : /* Loop through the parameter declarations, replacing each with an
3676 : : equivalent VAR_DECL, appropriately initialized. */
3677 : 11827559 : for (p = parms, i = 0; p; p = DECL_CHAIN (p), i++)
3678 : : {
3679 : 7441055 : tree val;
3680 : 7441055 : val = i < gimple_call_num_args (stmt) ? gimple_call_arg (stmt, i) : NULL;
3681 : 7441055 : setup_one_parameter (id, p, val, fn, bb, &vars);
3682 : : }
3683 : : /* After remapping parameters remap their types. This has to be done
3684 : : in a second loop over all parameters to appropriately remap
3685 : : variable sized arrays when the size is specified in a
3686 : : parameter following the array. */
3687 : 11827559 : for (p = parms, i = 0; p; p = DECL_CHAIN (p), i++)
3688 : : {
3689 : 7441055 : tree *varp = id->decl_map->get (p);
3690 : 7441055 : if (varp && VAR_P (*varp))
3691 : : {
3692 : 14705900 : tree def = (gimple_in_ssa_p (cfun) && is_gimple_reg (p)
3693 : 6934769 : ? ssa_default_def (id->src_cfun, p) : NULL);
3694 : 7352950 : tree var = *varp;
3695 : 7352950 : TREE_TYPE (var) = remap_type (TREE_TYPE (var), id);
3696 : : /* Also remap the default definition if it was remapped
3697 : : to the default definition of the parameter replacement
3698 : : by the parameter setup. */
3699 : 7352950 : if (def)
3700 : : {
3701 : 6612942 : tree *defp = id->decl_map->get (def);
3702 : 6612942 : if (defp
3703 : 6612856 : && TREE_CODE (*defp) == SSA_NAME
3704 : 12773575 : && SSA_NAME_VAR (*defp) == var)
3705 : 19834 : TREE_TYPE (*defp) = TREE_TYPE (var);
3706 : : }
3707 : : /* When not optimizing and the parameter is unused, assign to
3708 : : a dummy SSA name. Do this after remapping the type above. */
3709 : 740008 : else if (!optimize
3710 : 3593 : && is_gimple_reg (p)
3711 : 742755 : && i < gimple_call_num_args (stmt))
3712 : : {
3713 : 2747 : tree val = gimple_call_arg (stmt, i);
3714 : 2747 : if (val != error_mark_node)
3715 : : {
3716 : 2747 : if (!useless_type_conversion_p (TREE_TYPE (p),
3717 : 2747 : TREE_TYPE (val)))
3718 : 0 : val = force_value_to_type (TREE_TYPE (p), val);
3719 : 2747 : def = make_ssa_name (var);
3720 : 2747 : gimple *init_stmt = gimple_build_assign (def, val);
3721 : 2747 : insert_init_stmt (id, bb, init_stmt);
3722 : : }
3723 : : }
3724 : : }
3725 : : }
3726 : :
3727 : : /* Initialize the static chain. */
3728 : 4386504 : p = DECL_STRUCT_FUNCTION (fn)->static_chain_decl;
3729 : 4386504 : gcc_assert (fn != current_function_decl);
3730 : 4386504 : if (p)
3731 : : {
3732 : : /* No static chain? Seems like a bug in tree-nested.cc. */
3733 : 2243 : gcc_assert (static_chain);
3734 : :
3735 : 2243 : setup_one_parameter (id, p, static_chain, fn, bb, &vars);
3736 : : }
3737 : :
3738 : : /* Reverse so the variables appear in the correct order in DWARF
3739 : : debug info. */
3740 : 4386504 : vars = nreverse (vars);
3741 : :
3742 : 4386504 : declare_inline_vars (id->block, vars);
3743 : 4386504 : }
3744 : :
3745 : :
3746 : : /* Declare a return variable to replace the RESULT_DECL for the
3747 : : function we are calling. An appropriate DECL_STMT is returned.
3748 : : The USE_STMT is filled to contain a use of the declaration to
3749 : : indicate the return value of the function.
3750 : :
3751 : : RETURN_SLOT, if non-null is place where to store the result. It
3752 : : is set only for CALL_EXPR_RETURN_SLOT_OPT. MODIFY_DEST, if non-null,
3753 : : was the LHS of the MODIFY_EXPR to which this call is the RHS.
3754 : :
3755 : : The return value is a (possibly null) value that holds the result
3756 : : as seen by the caller. */
3757 : :
3758 : : static tree
3759 : 4386504 : declare_return_variable (copy_body_data *id, tree return_slot, tree modify_dest,
3760 : : basic_block entry_bb)
3761 : : {
3762 : 4386504 : tree callee = id->src_fn;
3763 : 4386504 : tree result = DECL_RESULT (callee);
3764 : 4386504 : tree callee_type = TREE_TYPE (result);
3765 : 4386504 : tree caller_type;
3766 : 4386504 : tree var, use;
3767 : :
3768 : : /* Handle type-mismatches in the function declaration return type
3769 : : vs. the call expression. */
3770 : 4386504 : if (modify_dest)
3771 : 2058402 : caller_type = TREE_TYPE (modify_dest);
3772 : 2328102 : else if (return_slot)
3773 : 133147 : caller_type = TREE_TYPE (return_slot);
3774 : : else /* No LHS on the call. */
3775 : 2194955 : caller_type = TREE_TYPE (TREE_TYPE (callee));
3776 : :
3777 : : /* We don't need to do anything for functions that don't return anything. */
3778 : 4386504 : if (VOID_TYPE_P (callee_type))
3779 : : return NULL_TREE;
3780 : :
3781 : : /* If there was a return slot, then the return value is the
3782 : : dereferenced address of that object. */
3783 : 2350413 : if (return_slot)
3784 : : {
3785 : : /* The front end shouldn't have used both return_slot and
3786 : : a modify expression. */
3787 : 133147 : gcc_assert (!modify_dest);
3788 : 133147 : if (DECL_BY_REFERENCE (result))
3789 : : {
3790 : 79468 : tree return_slot_addr = build_fold_addr_expr (return_slot);
3791 : 79468 : STRIP_USELESS_TYPE_CONVERSION (return_slot_addr);
3792 : :
3793 : : /* We are going to construct *&return_slot and we can't do that
3794 : : for variables believed to be not addressable.
3795 : :
3796 : : FIXME: This check possibly can match, because values returned
3797 : : via return slot optimization are not believed to have address
3798 : : taken by alias analysis. */
3799 : 79468 : gcc_assert (TREE_CODE (return_slot) != SSA_NAME);
3800 : 79468 : var = return_slot_addr;
3801 : 79468 : mark_addressable (return_slot);
3802 : : }
3803 : : else
3804 : : {
3805 : 53679 : var = return_slot;
3806 : 53679 : gcc_assert (TREE_CODE (var) != SSA_NAME);
3807 : 53679 : if (TREE_ADDRESSABLE (result))
3808 : 18621 : mark_addressable (var);
3809 : : }
3810 : 133147 : if (DECL_NOT_GIMPLE_REG_P (result)
3811 : 133147 : && DECL_P (var))
3812 : 0 : DECL_NOT_GIMPLE_REG_P (var) = 1;
3813 : :
3814 : 133147 : if (!useless_type_conversion_p (callee_type, caller_type))
3815 : 79469 : var = build1 (VIEW_CONVERT_EXPR, callee_type, var);
3816 : :
3817 : 133147 : use = NULL;
3818 : 133147 : goto done;
3819 : : }
3820 : :
3821 : : /* All types requiring non-trivial constructors should have been handled. */
3822 : 2217266 : gcc_assert (!TREE_ADDRESSABLE (callee_type));
3823 : :
3824 : : /* Attempt to avoid creating a new temporary variable. */
3825 : 2217266 : if (modify_dest
3826 : 2058381 : && TREE_CODE (modify_dest) != SSA_NAME)
3827 : : {
3828 : 342585 : bool use_it = false;
3829 : :
3830 : : /* We can't use MODIFY_DEST if there's type promotion involved. */
3831 : 342585 : if (!useless_type_conversion_p (callee_type, caller_type))
3832 : : use_it = false;
3833 : :
3834 : : /* ??? If we're assigning to a variable sized type, then we must
3835 : : reuse the destination variable, because we've no good way to
3836 : : create variable sized temporaries at this point. */
3837 : 342583 : else if (!poly_int_tree_p (TYPE_SIZE_UNIT (caller_type)))
3838 : : use_it = true;
3839 : :
3840 : : /* If the callee cannot possibly modify MODIFY_DEST, then we can
3841 : : reuse it as the result of the call directly. Don't do this if
3842 : : it would promote MODIFY_DEST to addressable. */
3843 : 342583 : else if (TREE_ADDRESSABLE (result))
3844 : : use_it = false;
3845 : : else
3846 : : {
3847 : 341860 : tree base_m = get_base_address (modify_dest);
3848 : :
3849 : : /* If the base isn't a decl, then it's a pointer, and we don't
3850 : : know where that's going to go. */
3851 : 341860 : if (!DECL_P (base_m))
3852 : : use_it = false;
3853 : 338153 : else if (is_global_var (base_m))
3854 : : use_it = false;
3855 : 337801 : else if (DECL_NOT_GIMPLE_REG_P (result)
3856 : 337801 : && !DECL_NOT_GIMPLE_REG_P (base_m))
3857 : : use_it = false;
3858 : 337801 : else if (!TREE_ADDRESSABLE (base_m))
3859 : : use_it = true;
3860 : : }
3861 : :
3862 : : if (use_it)
3863 : : {
3864 : 221899 : var = modify_dest;
3865 : 221899 : use = NULL;
3866 : 221899 : goto done;
3867 : : }
3868 : : }
3869 : :
3870 : 1995367 : gcc_assert (poly_int_tree_p (TYPE_SIZE_UNIT (callee_type)));
3871 : :
3872 : 1995367 : var = copy_result_decl_to_var (result, id);
3873 : 1995367 : DECL_SEEN_IN_BIND_EXPR_P (var) = 1;
3874 : :
3875 : : /* Do not have the rest of GCC warn about this variable as it should
3876 : : not be visible to the user. */
3877 : 1995367 : suppress_warning (var /* OPT_Wuninitialized? */);
3878 : :
3879 : 1995367 : declare_inline_vars (id->block, var);
3880 : :
3881 : : /* Build the use expr. If the return type of the function was
3882 : : promoted, convert it back to the expected type. */
3883 : 1995367 : use = var;
3884 : 1995367 : if (!useless_type_conversion_p (caller_type, TREE_TYPE (var)))
3885 : : {
3886 : : /* If we can match up types by promotion/demotion do so. */
3887 : 7 : if (fold_convertible_p (caller_type, var))
3888 : 0 : use = fold_convert (caller_type, var);
3889 : : else
3890 : : {
3891 : : /* ??? For valid programs we should not end up here.
3892 : : Still if we end up with truly mismatched types here, fall back
3893 : : to using a MEM_REF to not leak invalid GIMPLE to the following
3894 : : passes. */
3895 : : /* Prevent var from being written into SSA form. */
3896 : 7 : if (is_gimple_reg_type (TREE_TYPE (var)))
3897 : 7 : DECL_NOT_GIMPLE_REG_P (var) = true;
3898 : 7 : use = fold_build2 (MEM_REF, caller_type,
3899 : : build_fold_addr_expr (var),
3900 : : build_int_cst (ptr_type_node, 0));
3901 : : }
3902 : : }
3903 : :
3904 : 1995367 : STRIP_USELESS_TYPE_CONVERSION (use);
3905 : :
3906 : 1995367 : if (DECL_BY_REFERENCE (result))
3907 : : {
3908 : 0 : TREE_ADDRESSABLE (var) = 1;
3909 : 0 : var = build_fold_addr_expr (var);
3910 : : }
3911 : :
3912 : 1995367 : done:
3913 : : /* Register the VAR_DECL as the equivalent for the RESULT_DECL; that
3914 : : way, when the RESULT_DECL is encountered, it will be
3915 : : automatically replaced by the VAR_DECL.
3916 : :
3917 : : When returning by reference, ensure that RESULT_DECL remaps to
3918 : : gimple_val. */
3919 : 2350413 : if (DECL_BY_REFERENCE (result)
3920 : 2350413 : && !is_gimple_val (var))
3921 : : {
3922 : 79468 : tree temp = create_tmp_var (TREE_TYPE (result), "retvalptr");
3923 : 79468 : insert_decl_map (id, result, temp);
3924 : : /* When RESULT_DECL is in SSA form, we need to remap and initialize
3925 : : it's default_def SSA_NAME. */
3926 : 79468 : if (gimple_in_ssa_p (id->src_cfun)
3927 : 79468 : && is_gimple_reg (result))
3928 : 79468 : if (tree default_def = ssa_default_def (id->src_cfun, result))
3929 : : {
3930 : 79431 : temp = make_ssa_name (temp);
3931 : 79431 : insert_decl_map (id, default_def, temp);
3932 : : }
3933 : 79468 : insert_init_stmt (id, entry_bb, gimple_build_assign (temp, var));
3934 : : }
3935 : : else
3936 : 2270945 : insert_decl_map (id, result, var);
3937 : :
3938 : : /* Remember this so we can ignore it in remap_decls. */
3939 : 2350413 : id->retvar = var;
3940 : 2350413 : return use;
3941 : : }
3942 : :
3943 : : /* Determine if the function can be copied. If so return NULL. If
3944 : : not return a string describng the reason for failure. */
3945 : :
3946 : : const char *
3947 : 16791250 : copy_forbidden (struct function *fun)
3948 : : {
3949 : 16791250 : const char *reason = fun->cannot_be_copied_reason;
3950 : :
3951 : : /* Only examine the function once. */
3952 : 16791250 : if (fun->cannot_be_copied_set)
3953 : : return reason;
3954 : :
3955 : : /* We cannot copy a function that receives a non-local goto
3956 : : because we cannot remap the destination label used in the
3957 : : function that is performing the non-local goto. */
3958 : : /* ??? Actually, this should be possible, if we work at it.
3959 : : No doubt there's just a handful of places that simply
3960 : : assume it doesn't happen and don't substitute properly. */
3961 : 9541787 : if (fun->has_nonlocal_label)
3962 : : {
3963 : 778 : reason = G_("function %q+F can never be copied "
3964 : : "because it receives a non-local goto");
3965 : 778 : goto fail;
3966 : : }
3967 : :
3968 : 9541009 : if (fun->has_forced_label_in_static)
3969 : : {
3970 : 223 : reason = G_("function %q+F can never be copied because it saves "
3971 : : "address of local label in a static variable");
3972 : 223 : goto fail;
3973 : : }
3974 : :
3975 : 9540786 : fail:
3976 : 9541787 : fun->cannot_be_copied_reason = reason;
3977 : 9541787 : fun->cannot_be_copied_set = true;
3978 : 9541787 : return reason;
3979 : : }
3980 : :
3981 : :
3982 : : static const char *inline_forbidden_reason;
3983 : :
3984 : : /* A callback for walk_gimple_seq to handle statements. Returns non-null
3985 : : iff a function cannot be inlined. Also sets the reason why. */
3986 : :
3987 : : static tree
3988 : 168394282 : inline_forbidden_p_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
3989 : : struct walk_stmt_info *wip)
3990 : : {
3991 : 168394282 : tree fn = (tree) wip->info;
3992 : 168394282 : tree t;
3993 : 168394282 : gimple *stmt = gsi_stmt (*gsi);
3994 : :
3995 : 168394282 : switch (gimple_code (stmt))
3996 : : {
3997 : 18472834 : case GIMPLE_CALL:
3998 : : /* Refuse to inline alloca call unless user explicitly forced so as
3999 : : this may change program's memory overhead drastically when the
4000 : : function using alloca is called in loop. In GCC present in
4001 : : SPEC2000 inlining into schedule_block cause it to require 2GB of
4002 : : RAM instead of 256MB. Don't do so for alloca calls emitted for
4003 : : VLA objects as those can't cause unbounded growth (they're always
4004 : : wrapped inside stack_save/stack_restore regions. */
4005 : 18472834 : if (gimple_maybe_alloca_call_p (stmt)
4006 : 8882 : && !gimple_call_alloca_for_var_p (as_a <gcall *> (stmt))
4007 : 18477122 : && !lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)))
4008 : : {
4009 : 4160 : inline_forbidden_reason
4010 : 4160 : = G_("function %q+F can never be inlined because it uses "
4011 : : "alloca (override using the always_inline attribute)");
4012 : 4160 : *handled_ops_p = true;
4013 : 4160 : return fn;
4014 : : }
4015 : :
4016 : 18468674 : t = gimple_call_fndecl (stmt);
4017 : 18468674 : if (t == NULL_TREE)
4018 : : break;
4019 : :
4020 : : /* We cannot inline functions that call setjmp. */
4021 : 17953485 : if (setjmp_call_p (t))
4022 : : {
4023 : 929 : inline_forbidden_reason
4024 : 929 : = G_("function %q+F can never be inlined because it uses setjmp");
4025 : 929 : *handled_ops_p = true;
4026 : 929 : return t;
4027 : : }
4028 : :
4029 : 17952556 : if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL)
4030 : 3602302 : switch (DECL_FUNCTION_CODE (t))
4031 : : {
4032 : : /* We cannot inline functions that take a variable number of
4033 : : arguments. */
4034 : 2692 : case BUILT_IN_VA_START:
4035 : 2692 : case BUILT_IN_NEXT_ARG:
4036 : 2692 : case BUILT_IN_VA_END:
4037 : 2692 : inline_forbidden_reason
4038 : 2692 : = G_("function %q+F can never be inlined because it "
4039 : : "uses variable argument lists");
4040 : 2692 : *handled_ops_p = true;
4041 : 2692 : return t;
4042 : :
4043 : 226 : case BUILT_IN_LONGJMP:
4044 : : /* We can't inline functions that call __builtin_longjmp at
4045 : : all. The non-local goto machinery really requires the
4046 : : destination be in a different function. If we allow the
4047 : : function calling __builtin_longjmp to be inlined into the
4048 : : function calling __builtin_setjmp, Things will Go Awry. */
4049 : 226 : inline_forbidden_reason
4050 : 226 : = G_("function %q+F can never be inlined because "
4051 : : "it uses setjmp-longjmp exception handling");
4052 : 226 : *handled_ops_p = true;
4053 : 226 : return t;
4054 : :
4055 : 269 : case BUILT_IN_NONLOCAL_GOTO:
4056 : : /* Similarly. */
4057 : 269 : inline_forbidden_reason
4058 : 269 : = G_("function %q+F can never be inlined because "
4059 : : "it uses non-local goto");
4060 : 269 : *handled_ops_p = true;
4061 : 269 : return t;
4062 : :
4063 : 384 : case BUILT_IN_RETURN:
4064 : 384 : case BUILT_IN_APPLY_ARGS:
4065 : : /* If a __builtin_apply_args caller would be inlined,
4066 : : it would be saving arguments of the function it has
4067 : : been inlined into. Similarly __builtin_return would
4068 : : return from the function the inline has been inlined into. */
4069 : 384 : inline_forbidden_reason
4070 : 384 : = G_("function %q+F can never be inlined because "
4071 : : "it uses %<__builtin_return%> or %<__builtin_apply_args%>");
4072 : 384 : *handled_ops_p = true;
4073 : 384 : return t;
4074 : :
4075 : : default:
4076 : : break;
4077 : : }
4078 : : break;
4079 : :
4080 : 284 : case GIMPLE_GOTO:
4081 : 284 : t = gimple_goto_dest (stmt);
4082 : :
4083 : : /* We will not inline a function which uses computed goto. The
4084 : : addresses of its local labels, which may be tucked into
4085 : : global storage, are of course not constant across
4086 : : instantiations, which causes unexpected behavior. */
4087 : 284 : if (TREE_CODE (t) != LABEL_DECL)
4088 : : {
4089 : 284 : inline_forbidden_reason
4090 : 284 : = G_("function %q+F can never be inlined "
4091 : : "because it contains a computed goto");
4092 : 284 : *handled_ops_p = true;
4093 : 284 : return t;
4094 : : }
4095 : : break;
4096 : :
4097 : : default:
4098 : : break;
4099 : : }
4100 : :
4101 : 168385338 : *handled_ops_p = false;
4102 : 168385338 : return NULL_TREE;
4103 : : }
4104 : :
4105 : : /* Return true if FNDECL is a function that cannot be inlined into
4106 : : another one. */
4107 : :
4108 : : static bool
4109 : 5760685 : inline_forbidden_p (tree fndecl)
4110 : : {
4111 : 5760685 : struct function *fun = DECL_STRUCT_FUNCTION (fndecl);
4112 : 5760685 : struct walk_stmt_info wi;
4113 : 5760685 : basic_block bb;
4114 : 5760685 : bool forbidden_p = false;
4115 : :
4116 : : /* First check for shared reasons not to copy the code. */
4117 : 5760685 : inline_forbidden_reason = copy_forbidden (fun);
4118 : 5760685 : if (inline_forbidden_reason != NULL)
4119 : : return true;
4120 : :
4121 : : /* Next, walk the statements of the function looking for
4122 : : constraucts we can't handle, or are non-optimal for inlining. */
4123 : 5759989 : hash_set<tree> visited_nodes;
4124 : 5759989 : memset (&wi, 0, sizeof (wi));
4125 : 5759989 : wi.info = (void *) fndecl;
4126 : 5759989 : wi.pset = &visited_nodes;
4127 : :
4128 : : /* We cannot inline a function with a variable-sized parameter because we
4129 : : cannot materialize a temporary of such a type in the caller if need be.
4130 : : Note that the return case is not symmetrical because we can guarantee
4131 : : that a temporary is not needed by means of CALL_EXPR_RETURN_SLOT_OPT. */
4132 : 18354392 : for (tree parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm))
4133 : 12594405 : if (!poly_int_tree_p (DECL_SIZE (parm)))
4134 : : {
4135 : 2 : inline_forbidden_reason
4136 : 2 : = G_("function %q+F can never be inlined because "
4137 : : "it has a VLA argument");
4138 : 2 : return true;
4139 : : }
4140 : :
4141 : 37549818 : FOR_EACH_BB_FN (bb, fun)
4142 : : {
4143 : 31798775 : gimple *ret;
4144 : 31798775 : gimple_seq seq = bb_seq (bb);
4145 : 31798775 : ret = walk_gimple_seq (seq, inline_forbidden_p_stmt, NULL, &wi);
4146 : 31798775 : forbidden_p = (ret != NULL);
4147 : 31798775 : if (forbidden_p)
4148 : : break;
4149 : : }
4150 : :
4151 : : return forbidden_p;
4152 : 5759989 : }
4153 : :
4154 : : /* Return false if the function FNDECL cannot be inlined on account of its
4155 : : attributes, true otherwise. */
4156 : : static bool
4157 : 5760685 : function_attribute_inlinable_p (const_tree fndecl)
4158 : : {
4159 : 11502315 : for (auto scoped_attributes : targetm.attribute_table)
4160 : : {
4161 : 5760685 : const_tree a;
4162 : :
4163 : 7501685 : for (a = DECL_ATTRIBUTES (fndecl); a; a = TREE_CHAIN (a))
4164 : : {
4165 : 1760055 : const_tree name = get_attribute_name (a);
4166 : :
4167 : 48825829 : for (const attribute_spec &attribute : scoped_attributes->attributes)
4168 : 47084829 : if (is_attribute_p (attribute.name, name))
4169 : 19055 : return targetm.function_attribute_inlinable_p (fndecl);
4170 : : }
4171 : : }
4172 : :
4173 : : return true;
4174 : : }
4175 : :
4176 : : /* Returns nonzero if FN is a function that does not have any
4177 : : fundamental inline blocking properties. */
4178 : :
4179 : : bool
4180 : 6359684 : tree_inlinable_function_p (tree fn)
4181 : : {
4182 : 6359684 : bool inlinable = true;
4183 : 6359684 : bool do_warning;
4184 : 6359684 : tree always_inline;
4185 : :
4186 : : /* If we've already decided this function shouldn't be inlined,
4187 : : there's no need to check again. */
4188 : 6359684 : if (DECL_UNINLINABLE (fn))
4189 : : return false;
4190 : :
4191 : : /* We only warn for functions declared `inline' by the user. */
4192 : 5779625 : do_warning = (opt_for_fn (fn, warn_inline)
4193 : 597 : && DECL_DECLARED_INLINE_P (fn)
4194 : 468 : && !DECL_NO_INLINE_WARNING_P (fn)
4195 : 5779850 : && !DECL_IN_SYSTEM_HEADER (fn));
4196 : :
4197 : 5779625 : always_inline = lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn));
4198 : :
4199 : 5779625 : if (flag_no_inline
4200 : 90596 : && always_inline == NULL)
4201 : : {
4202 : 18940 : if (do_warning)
4203 : 0 : warning (OPT_Winline, "function %q+F can never be inlined because it "
4204 : : "is suppressed using %<-fno-inline%>", fn);
4205 : : inlinable = false;
4206 : : }
4207 : :
4208 : 5760685 : else if (!function_attribute_inlinable_p (fn))
4209 : : {
4210 : 0 : if (do_warning)
4211 : 0 : warning (OPT_Winline, "function %q+F can never be inlined because it "
4212 : : "uses attributes conflicting with inlining", fn);
4213 : : inlinable = false;
4214 : : }
4215 : :
4216 : 5760685 : else if (inline_forbidden_p (fn))
4217 : : {
4218 : : /* See if we should warn about uninlinable functions. Previously,
4219 : : some of these warnings would be issued while trying to expand
4220 : : the function inline, but that would cause multiple warnings
4221 : : about functions that would for example call alloca. But since
4222 : : this a property of the function, just one warning is enough.
4223 : : As a bonus we can now give more details about the reason why a
4224 : : function is not inlinable. */
4225 : 9642 : if (always_inline)
4226 : 2 : error (inline_forbidden_reason, fn);
4227 : 9640 : else if (do_warning)
4228 : 2 : warning (OPT_Winline, inline_forbidden_reason, fn);
4229 : :
4230 : : inlinable = false;
4231 : : }
4232 : :
4233 : : /* Squirrel away the result so that we don't have to check again. */
4234 : 5779625 : DECL_UNINLINABLE (fn) = !inlinable;
4235 : :
4236 : 5779625 : return inlinable;
4237 : : }
4238 : :
4239 : : /* Estimate the cost of a memory move of type TYPE. Use machine dependent
4240 : : word size and take possible memcpy call into account and return
4241 : : cost based on whether optimizing for size or speed according to SPEED_P. */
4242 : :
4243 : : int
4244 : 336954045 : estimate_move_cost (tree type, bool ARG_UNUSED (speed_p))
4245 : : {
4246 : 336954045 : HOST_WIDE_INT size;
4247 : :
4248 : 336954045 : gcc_assert (!VOID_TYPE_P (type));
4249 : :
4250 : 336954045 : if (VECTOR_TYPE_P (type))
4251 : : {
4252 : 3856722 : scalar_mode inner = SCALAR_TYPE_MODE (TREE_TYPE (type));
4253 : 3856722 : machine_mode simd = targetm.vectorize.preferred_simd_mode (inner);
4254 : 3856722 : int orig_mode_size
4255 : 7713444 : = estimated_poly_value (GET_MODE_SIZE (TYPE_MODE (type)));
4256 : 7713444 : int simd_mode_size = estimated_poly_value (GET_MODE_SIZE (simd));
4257 : 3856722 : return ((orig_mode_size + simd_mode_size - 1)
4258 : 3856722 : / simd_mode_size);
4259 : : }
4260 : :
4261 : 333097323 : size = int_size_in_bytes (type);
4262 : :
4263 : 333099791 : if (size < 0 || size > MOVE_MAX_PIECES * MOVE_RATIO (speed_p))
4264 : : /* Cost of a memcpy call, 3 arguments and the call. */
4265 : : return 4;
4266 : : else
4267 : 332145718 : return ((size + MOVE_MAX_PIECES - 1) / MOVE_MAX_PIECES);
4268 : : }
4269 : :
4270 : : /* Returns cost of operation CODE, according to WEIGHTS */
4271 : :
4272 : : static int
4273 : 457661882 : estimate_operator_cost (enum tree_code code, eni_weights *weights,
4274 : : tree op1 ATTRIBUTE_UNUSED, tree op2)
4275 : : {
4276 : 457661882 : switch (code)
4277 : : {
4278 : : /* These are "free" conversions, or their presumed cost
4279 : : is folded into other operations. */
4280 : : case RANGE_EXPR:
4281 : : CASE_CONVERT:
4282 : : case COMPLEX_EXPR:
4283 : : case PAREN_EXPR:
4284 : : case VIEW_CONVERT_EXPR:
4285 : : return 0;
4286 : :
4287 : : /* Assign cost of 1 to usual operations.
4288 : : ??? We may consider mapping RTL costs to this. */
4289 : : case COND_EXPR:
4290 : : case VEC_COND_EXPR:
4291 : : case VEC_PERM_EXPR:
4292 : :
4293 : : case PLUS_EXPR:
4294 : : case POINTER_PLUS_EXPR:
4295 : : case POINTER_DIFF_EXPR:
4296 : : case MINUS_EXPR:
4297 : : case MULT_EXPR:
4298 : : case MULT_HIGHPART_EXPR:
4299 : :
4300 : : case ADDR_SPACE_CONVERT_EXPR:
4301 : : case FIXED_CONVERT_EXPR:
4302 : : case FIX_TRUNC_EXPR:
4303 : :
4304 : : case NEGATE_EXPR:
4305 : : case FLOAT_EXPR:
4306 : : case MIN_EXPR:
4307 : : case MAX_EXPR:
4308 : : case ABS_EXPR:
4309 : : case ABSU_EXPR:
4310 : :
4311 : : case LSHIFT_EXPR:
4312 : : case RSHIFT_EXPR:
4313 : : case LROTATE_EXPR:
4314 : : case RROTATE_EXPR:
4315 : :
4316 : : case BIT_IOR_EXPR:
4317 : : case BIT_XOR_EXPR:
4318 : : case BIT_AND_EXPR:
4319 : : case BIT_NOT_EXPR:
4320 : :
4321 : : case TRUTH_ANDIF_EXPR:
4322 : : case TRUTH_ORIF_EXPR:
4323 : : case TRUTH_AND_EXPR:
4324 : : case TRUTH_OR_EXPR:
4325 : : case TRUTH_XOR_EXPR:
4326 : : case TRUTH_NOT_EXPR:
4327 : :
4328 : : case LT_EXPR:
4329 : : case LE_EXPR:
4330 : : case GT_EXPR:
4331 : : case GE_EXPR:
4332 : : case EQ_EXPR:
4333 : : case NE_EXPR:
4334 : : case ORDERED_EXPR:
4335 : : case UNORDERED_EXPR:
4336 : :
4337 : : case UNLT_EXPR:
4338 : : case UNLE_EXPR:
4339 : : case UNGT_EXPR:
4340 : : case UNGE_EXPR:
4341 : : case UNEQ_EXPR:
4342 : : case LTGT_EXPR:
4343 : :
4344 : : case CONJ_EXPR:
4345 : :
4346 : : case PREDECREMENT_EXPR:
4347 : : case PREINCREMENT_EXPR:
4348 : : case POSTDECREMENT_EXPR:
4349 : : case POSTINCREMENT_EXPR:
4350 : :
4351 : : case REALIGN_LOAD_EXPR:
4352 : :
4353 : : case WIDEN_SUM_EXPR:
4354 : : case WIDEN_MULT_EXPR:
4355 : : case DOT_PROD_EXPR:
4356 : : case SAD_EXPR:
4357 : : case WIDEN_MULT_PLUS_EXPR:
4358 : : case WIDEN_MULT_MINUS_EXPR:
4359 : : case WIDEN_LSHIFT_EXPR:
4360 : :
4361 : : case VEC_WIDEN_MULT_HI_EXPR:
4362 : : case VEC_WIDEN_MULT_LO_EXPR:
4363 : : case VEC_WIDEN_MULT_EVEN_EXPR:
4364 : : case VEC_WIDEN_MULT_ODD_EXPR:
4365 : : case VEC_UNPACK_HI_EXPR:
4366 : : case VEC_UNPACK_LO_EXPR:
4367 : : case VEC_UNPACK_FLOAT_HI_EXPR:
4368 : : case VEC_UNPACK_FLOAT_LO_EXPR:
4369 : : case VEC_UNPACK_FIX_TRUNC_HI_EXPR:
4370 : : case VEC_UNPACK_FIX_TRUNC_LO_EXPR:
4371 : : case VEC_PACK_TRUNC_EXPR:
4372 : : case VEC_PACK_SAT_EXPR:
4373 : : case VEC_PACK_FIX_TRUNC_EXPR:
4374 : : case VEC_PACK_FLOAT_EXPR:
4375 : : case VEC_WIDEN_LSHIFT_HI_EXPR:
4376 : : case VEC_WIDEN_LSHIFT_LO_EXPR:
4377 : : case VEC_DUPLICATE_EXPR:
4378 : : case VEC_SERIES_EXPR:
4379 : :
4380 : : return 1;
4381 : :
4382 : : /* Few special cases of expensive operations. This is useful
4383 : : to avoid inlining on functions having too many of these. */
4384 : 3270999 : case TRUNC_DIV_EXPR:
4385 : 3270999 : case CEIL_DIV_EXPR:
4386 : 3270999 : case FLOOR_DIV_EXPR:
4387 : 3270999 : case ROUND_DIV_EXPR:
4388 : 3270999 : case EXACT_DIV_EXPR:
4389 : 3270999 : case TRUNC_MOD_EXPR:
4390 : 3270999 : case CEIL_MOD_EXPR:
4391 : 3270999 : case FLOOR_MOD_EXPR:
4392 : 3270999 : case ROUND_MOD_EXPR:
4393 : 3270999 : case RDIV_EXPR:
4394 : 3270999 : if (TREE_CODE (op2) != INTEGER_CST)
4395 : 1292259 : return weights->div_mod_cost;
4396 : : return 1;
4397 : :
4398 : : /* Bit-field insertion needs several shift and mask operations. */
4399 : : case BIT_INSERT_EXPR:
4400 : : return 3;
4401 : :
4402 : 187461360 : default:
4403 : : /* We expect a copy assignment with no operator. */
4404 : 187461360 : gcc_assert (get_gimple_rhs_class (code) == GIMPLE_SINGLE_RHS);
4405 : : return 0;
4406 : : }
4407 : : }
4408 : :
4409 : :
4410 : : /* Estimate number of instructions that will be created by expanding
4411 : : the statements in the statement sequence STMTS.
4412 : : WEIGHTS contains weights attributed to various constructs. */
4413 : :
4414 : : int
4415 : 242949 : estimate_num_insns_seq (gimple_seq stmts, eni_weights *weights)
4416 : : {
4417 : 242949 : int cost;
4418 : 242949 : gimple_stmt_iterator gsi;
4419 : :
4420 : 242949 : cost = 0;
4421 : 633058 : for (gsi = gsi_start (stmts); !gsi_end_p (gsi); gsi_next (&gsi))
4422 : 390109 : cost += estimate_num_insns (gsi_stmt (gsi), weights);
4423 : :
4424 : 242949 : return cost;
4425 : : }
4426 : :
4427 : :
4428 : : /* Estimate number of instructions that will be created by expanding STMT.
4429 : : WEIGHTS contains weights attributed to various constructs. */
4430 : :
4431 : : int
4432 : 624670884 : estimate_num_insns (gimple *stmt, eni_weights *weights)
4433 : : {
4434 : 624670884 : unsigned cost, i;
4435 : 624670884 : enum gimple_code code = gimple_code (stmt);
4436 : 624670884 : tree lhs;
4437 : 624670884 : tree rhs;
4438 : :
4439 : 624670884 : switch (code)
4440 : : {
4441 : 355930899 : case GIMPLE_ASSIGN:
4442 : : /* Try to estimate the cost of assignments. We have three cases to
4443 : : deal with:
4444 : : 1) Simple assignments to registers;
4445 : : 2) Stores to things that must live in memory. This includes
4446 : : "normal" stores to scalars, but also assignments of large
4447 : : structures, or constructors of big arrays;
4448 : :
4449 : : Let us look at the first two cases, assuming we have "a = b + C":
4450 : : <GIMPLE_ASSIGN <var_decl "a">
4451 : : <plus_expr <var_decl "b"> <constant C>>
4452 : : If "a" is a GIMPLE register, the assignment to it is free on almost
4453 : : any target, because "a" usually ends up in a real register. Hence
4454 : : the only cost of this expression comes from the PLUS_EXPR, and we
4455 : : can ignore the GIMPLE_ASSIGN.
4456 : : If "a" is not a GIMPLE register, the assignment to "a" will most
4457 : : likely be a real store, so the cost of the GIMPLE_ASSIGN is the cost
4458 : : of moving something into "a", which we compute using the function
4459 : : estimate_move_cost. */
4460 : 355930899 : if (gimple_clobber_p (stmt))
4461 : : return 0; /* ={v} {CLOBBER} stmt expands to nothing. */
4462 : :
4463 : 334523697 : lhs = gimple_assign_lhs (stmt);
4464 : 334523697 : rhs = gimple_assign_rhs1 (stmt);
4465 : :
4466 : 334523697 : cost = 0;
4467 : :
4468 : : /* Account for the cost of moving to / from memory. */
4469 : 334523697 : if (gimple_store_p (stmt))
4470 : 76945105 : cost += estimate_move_cost (TREE_TYPE (lhs), weights->time_based);
4471 : 334523697 : if (gimple_assign_load_p (stmt))
4472 : 89911746 : cost += estimate_move_cost (TREE_TYPE (rhs), weights->time_based);
4473 : :
4474 : 440366654 : cost += estimate_operator_cost (gimple_assign_rhs_code (stmt), weights,
4475 : : gimple_assign_rhs1 (stmt),
4476 : 334523697 : get_gimple_rhs_class (gimple_assign_rhs_code (stmt))
4477 : : == GIMPLE_BINARY_RHS
4478 : 105842957 : ? gimple_assign_rhs2 (stmt) : NULL);
4479 : 334523697 : break;
4480 : :
4481 : 123138185 : case GIMPLE_COND:
4482 : 123138185 : cost = 1 + estimate_operator_cost (gimple_cond_code (stmt), weights,
4483 : : gimple_op (stmt, 0),
4484 : : gimple_op (stmt, 1));
4485 : 123138185 : break;
4486 : :
4487 : 905113 : case GIMPLE_SWITCH:
4488 : 905113 : {
4489 : 905113 : gswitch *switch_stmt = as_a <gswitch *> (stmt);
4490 : : /* Take into account cost of the switch + guess 2 conditional jumps for
4491 : : each case label.
4492 : :
4493 : : TODO: once the switch expansion logic is sufficiently separated, we can
4494 : : do better job on estimating cost of the switch. */
4495 : 905113 : if (weights->time_based)
4496 : 131406 : cost = floor_log2 (gimple_switch_num_labels (switch_stmt)) * 2;
4497 : : else
4498 : 773707 : cost = gimple_switch_num_labels (switch_stmt) * 2;
4499 : : }
4500 : : break;
4501 : :
4502 : 71283756 : case GIMPLE_CALL:
4503 : 71283756 : {
4504 : 71283756 : tree decl;
4505 : :
4506 : 71283756 : if (gimple_call_internal_p (stmt))
4507 : : return 0;
4508 : 68946444 : else if ((decl = gimple_call_fndecl (stmt))
4509 : 68946444 : && fndecl_built_in_p (decl))
4510 : : {
4511 : : /* Do not special case builtins where we see the body.
4512 : : This just confuse inliner. */
4513 : 17381319 : struct cgraph_node *node;
4514 : 17381319 : if ((node = cgraph_node::get (decl))
4515 : 17381319 : && node->definition)
4516 : : ;
4517 : : /* For buitins that are likely expanded to nothing or
4518 : : inlined do not account operand costs. */
4519 : 17351411 : else if (is_simple_builtin (decl))
4520 : : return 0;
4521 : 14971215 : else if (is_inexpensive_builtin (decl))
4522 : 1922628 : return weights->target_builtin_call_cost;
4523 : 13048587 : else if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
4524 : : {
4525 : : /* We canonicalize x * x to pow (x, 2.0) with -ffast-math, so
4526 : : specialize the cheap expansion we do here.
4527 : : ??? This asks for a more general solution. */
4528 : 12833352 : switch (DECL_FUNCTION_CODE (decl))
4529 : : {
4530 : 8956 : case BUILT_IN_POW:
4531 : 8956 : case BUILT_IN_POWF:
4532 : 8956 : case BUILT_IN_POWL:
4533 : 8956 : if (TREE_CODE (gimple_call_arg (stmt, 1)) == REAL_CST
4534 : 12707 : && (real_equal
4535 : 3751 : (&TREE_REAL_CST (gimple_call_arg (stmt, 1)),
4536 : : &dconst2)))
4537 : 446 : return estimate_operator_cost
4538 : 446 : (MULT_EXPR, weights, gimple_call_arg (stmt, 0),
4539 : 446 : gimple_call_arg (stmt, 0));
4540 : : break;
4541 : :
4542 : : default:
4543 : : break;
4544 : : }
4545 : : }
4546 : : }
4547 : :
4548 : 64643174 : cost = decl ? weights->call_cost : weights->indirect_call_cost;
4549 : 64643174 : if (gimple_call_lhs (stmt))
4550 : 25718017 : cost += estimate_move_cost (TREE_TYPE (gimple_call_lhs (stmt)),
4551 : 25718017 : weights->time_based);
4552 : 195040767 : for (i = 0; i < gimple_call_num_args (stmt); i++)
4553 : : {
4554 : 130397593 : tree arg = gimple_call_arg (stmt, i);
4555 : 130397593 : cost += estimate_move_cost (TREE_TYPE (arg),
4556 : 130397593 : weights->time_based);
4557 : : }
4558 : : break;
4559 : : }
4560 : :
4561 : 17669939 : case GIMPLE_RETURN:
4562 : 17669939 : return weights->return_cost;
4563 : :
4564 : : case GIMPLE_GOTO:
4565 : : case GIMPLE_LABEL:
4566 : : case GIMPLE_NOP:
4567 : : case GIMPLE_PHI:
4568 : : case GIMPLE_PREDICT:
4569 : : case GIMPLE_DEBUG:
4570 : : return 0;
4571 : :
4572 : 731218 : case GIMPLE_ASM:
4573 : 731218 : {
4574 : 731218 : int count = asm_str_count (gimple_asm_string (as_a <gasm *> (stmt)));
4575 : : /* 1000 means infinity. This avoids overflows later
4576 : : with very long asm statements. */
4577 : 731218 : if (count > 1000)
4578 : : count = 1000;
4579 : : /* If this asm is asm inline, count anything as minimum size. */
4580 : 731218 : if (gimple_asm_inline_p (as_a <gasm *> (stmt)))
4581 : 694 : count = MIN (1, count);
4582 : 731218 : return MAX (1, count);
4583 : : }
4584 : :
4585 : : case GIMPLE_RESX:
4586 : : /* This is either going to be an external function call with one
4587 : : argument, or two register copy statements plus a goto. */
4588 : : return 2;
4589 : :
4590 : 13428 : case GIMPLE_EH_DISPATCH:
4591 : : /* ??? This is going to turn into a switch statement. Ideally
4592 : : we'd have a look at the eh region and estimate the number of
4593 : : edges involved. */
4594 : 13428 : return 10;
4595 : :
4596 : 0 : case GIMPLE_BIND:
4597 : 0 : return estimate_num_insns_seq (
4598 : 0 : gimple_bind_body (as_a <gbind *> (stmt)),
4599 : 0 : weights);
4600 : :
4601 : 0 : case GIMPLE_EH_FILTER:
4602 : 0 : return estimate_num_insns_seq (gimple_eh_filter_failure (stmt), weights);
4603 : :
4604 : 8292 : case GIMPLE_CATCH:
4605 : 8292 : return estimate_num_insns_seq (gimple_catch_handler (
4606 : 8292 : as_a <gcatch *> (stmt)),
4607 : 8292 : weights);
4608 : :
4609 : 8297 : case GIMPLE_TRY:
4610 : 8297 : return (estimate_num_insns_seq (gimple_try_eval (stmt), weights)
4611 : 8297 : + estimate_num_insns_seq (gimple_try_cleanup (stmt), weights));
4612 : :
4613 : : /* OMP directives are generally very expensive. */
4614 : :
4615 : : case GIMPLE_OMP_RETURN:
4616 : : case GIMPLE_OMP_SECTIONS_SWITCH:
4617 : : case GIMPLE_OMP_ATOMIC_STORE:
4618 : : case GIMPLE_OMP_CONTINUE:
4619 : : /* ...except these, which are cheap. */
4620 : : return 0;
4621 : :
4622 : 0 : case GIMPLE_OMP_ATOMIC_LOAD:
4623 : 0 : return weights->omp_cost;
4624 : :
4625 : 0 : case GIMPLE_OMP_FOR:
4626 : 0 : return (weights->omp_cost
4627 : 0 : + estimate_num_insns_seq (gimple_omp_body (stmt), weights)
4628 : 0 : + estimate_num_insns_seq (gimple_omp_for_pre_body (stmt), weights));
4629 : :
4630 : 0 : case GIMPLE_OMP_PARALLEL:
4631 : 0 : case GIMPLE_OMP_TASK:
4632 : 0 : case GIMPLE_OMP_CRITICAL:
4633 : 0 : case GIMPLE_OMP_MASTER:
4634 : 0 : case GIMPLE_OMP_MASKED:
4635 : 0 : case GIMPLE_OMP_SCOPE:
4636 : 0 : case GIMPLE_OMP_DISPATCH:
4637 : 0 : case GIMPLE_OMP_TASKGROUP:
4638 : 0 : case GIMPLE_OMP_ORDERED:
4639 : 0 : case GIMPLE_OMP_SCAN:
4640 : 0 : case GIMPLE_OMP_SECTION:
4641 : 0 : case GIMPLE_OMP_SECTIONS:
4642 : 0 : case GIMPLE_OMP_STRUCTURED_BLOCK:
4643 : 0 : case GIMPLE_OMP_SINGLE:
4644 : 0 : case GIMPLE_OMP_TARGET:
4645 : 0 : case GIMPLE_OMP_TEAMS:
4646 : 0 : return (weights->omp_cost
4647 : 0 : + estimate_num_insns_seq (gimple_omp_body (stmt), weights));
4648 : :
4649 : 82 : case GIMPLE_TRANSACTION:
4650 : 82 : return (weights->tm_cost
4651 : 82 : + estimate_num_insns_seq (gimple_transaction_body (
4652 : 82 : as_a <gtransaction *> (stmt)),
4653 : 82 : weights));
4654 : :
4655 : 0 : default:
4656 : 0 : gcc_unreachable ();
4657 : : }
4658 : :
4659 : 523210169 : return cost;
4660 : : }
4661 : :
4662 : : /* Estimate number of instructions that will be created by expanding
4663 : : function FNDECL. WEIGHTS contains weights attributed to various
4664 : : constructs. */
4665 : :
4666 : : int
4667 : 0 : estimate_num_insns_fn (tree fndecl, eni_weights *weights)
4668 : : {
4669 : 0 : struct function *my_function = DECL_STRUCT_FUNCTION (fndecl);
4670 : 0 : gimple_stmt_iterator bsi;
4671 : 0 : basic_block bb;
4672 : 0 : int n = 0;
4673 : :
4674 : 0 : gcc_assert (my_function && my_function->cfg);
4675 : 0 : FOR_EACH_BB_FN (bb, my_function)
4676 : : {
4677 : 0 : for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi))
4678 : 0 : n += estimate_num_insns (gsi_stmt (bsi), weights);
4679 : : }
4680 : :
4681 : 0 : return n;
4682 : : }
4683 : :
4684 : :
4685 : : /* Initializes weights used by estimate_num_insns. */
4686 : :
4687 : : void
4688 : 278687 : init_inline_once (void)
4689 : : {
4690 : 278687 : eni_size_weights.call_cost = 1;
4691 : 278687 : eni_size_weights.indirect_call_cost = 3;
4692 : 278687 : eni_size_weights.target_builtin_call_cost = 1;
4693 : 278687 : eni_size_weights.div_mod_cost = 1;
4694 : 278687 : eni_size_weights.omp_cost = 40;
4695 : 278687 : eni_size_weights.tm_cost = 10;
4696 : 278687 : eni_size_weights.time_based = false;
4697 : 278687 : eni_size_weights.return_cost = 1;
4698 : :
4699 : : /* Estimating time for call is difficult, since we have no idea what the
4700 : : called function does. In the current uses of eni_time_weights,
4701 : : underestimating the cost does less harm than overestimating it, so
4702 : : we choose a rather small value here. */
4703 : 278687 : eni_time_weights.call_cost = 10;
4704 : 278687 : eni_time_weights.indirect_call_cost = 15;
4705 : 278687 : eni_time_weights.target_builtin_call_cost = 1;
4706 : 278687 : eni_time_weights.div_mod_cost = 10;
4707 : 278687 : eni_time_weights.omp_cost = 40;
4708 : 278687 : eni_time_weights.tm_cost = 40;
4709 : 278687 : eni_time_weights.time_based = true;
4710 : 278687 : eni_time_weights.return_cost = 2;
4711 : 278687 : }
4712 : :
4713 : :
4714 : : /* Install new lexical TREE_BLOCK underneath 'current_block'. */
4715 : :
4716 : : static void
4717 : 28441519 : prepend_lexical_block (tree current_block, tree new_block)
4718 : : {
4719 : 28441519 : BLOCK_CHAIN (new_block) = BLOCK_SUBBLOCKS (current_block);
4720 : 28441519 : BLOCK_SUBBLOCKS (current_block) = new_block;
4721 : 28441519 : BLOCK_SUPERCONTEXT (new_block) = current_block;
4722 : 28441519 : }
4723 : :
4724 : : /* Add local variables from CALLEE to CALLER. */
4725 : :
4726 : : static inline void
4727 : 4519074 : add_local_variables (struct function *callee, struct function *caller,
4728 : : copy_body_data *id)
4729 : : {
4730 : 4519074 : tree var;
4731 : 4519074 : unsigned ix;
4732 : :
4733 : 12418434 : FOR_EACH_LOCAL_DECL (callee, ix, var)
4734 : 4070473 : if (!can_be_nonlocal (var, id))
4735 : : {
4736 : 3986063 : tree new_var = remap_decl (var, id);
4737 : :
4738 : : /* Remap debug-expressions. */
4739 : 3986063 : if (VAR_P (new_var)
4740 : 3986063 : && DECL_HAS_DEBUG_EXPR_P (var)
4741 : 4234438 : && new_var != var)
4742 : : {
4743 : 248375 : tree tem = DECL_DEBUG_EXPR (var);
4744 : 248375 : bool old_regimplify = id->regimplify;
4745 : 248375 : id->remapping_type_depth++;
4746 : 248375 : walk_tree (&tem, copy_tree_body_r, id, NULL);
4747 : 248375 : id->remapping_type_depth--;
4748 : 248375 : id->regimplify = old_regimplify;
4749 : 248375 : SET_DECL_DEBUG_EXPR (new_var, tem);
4750 : 248375 : DECL_HAS_DEBUG_EXPR_P (new_var) = 1;
4751 : : }
4752 : 3986063 : add_local_decl (caller, new_var);
4753 : : }
4754 : 4519074 : }
4755 : :
4756 : : /* Add to BINDINGS a debug stmt resetting SRCVAR if inlining might
4757 : : have brought in or introduced any debug stmts for SRCVAR. */
4758 : :
4759 : : static inline void
4760 : 9226206 : reset_debug_binding (copy_body_data *id, tree srcvar, gimple_seq *bindings)
4761 : : {
4762 : 9226206 : tree *remappedvarp = id->decl_map->get (srcvar);
4763 : :
4764 : 9226206 : if (!remappedvarp)
4765 : : return;
4766 : :
4767 : 9171942 : if (!VAR_P (*remappedvarp))
4768 : : return;
4769 : :
4770 : 9095997 : if (*remappedvarp == id->retvar)
4771 : : return;
4772 : :
4773 : 9095997 : tree tvar = target_for_debug_bind (*remappedvarp);
4774 : 9095997 : if (!tvar)
4775 : : return;
4776 : :
4777 : 14618156 : gdebug *stmt = gimple_build_debug_bind (tvar, NULL_TREE,
4778 : 7309078 : id->call_stmt);
4779 : 7309078 : gimple_seq_add_stmt (bindings, stmt);
4780 : : }
4781 : :
4782 : : /* For each inlined variable for which we may have debug bind stmts,
4783 : : add before GSI a final debug stmt resetting it, marking the end of
4784 : : its life, so that var-tracking knows it doesn't have to compute
4785 : : further locations for it. */
4786 : :
4787 : : static inline void
4788 : 4386504 : reset_debug_bindings (copy_body_data *id, gimple_stmt_iterator gsi)
4789 : : {
4790 : 4386504 : tree var;
4791 : 4386504 : unsigned ix;
4792 : 4386504 : gimple_seq bindings = NULL;
4793 : :
4794 : 4386504 : if (!gimple_in_ssa_p (id->src_cfun))
4795 : 513739 : return;
4796 : :
4797 : 4386504 : if (!opt_for_fn (id->dst_fn, flag_var_tracking_assignments))
4798 : : return;
4799 : :
4800 : 3872765 : for (var = DECL_ARGUMENTS (id->src_fn);
4801 : 10466248 : var; var = DECL_CHAIN (var))
4802 : 6593483 : reset_debug_binding (id, var, &bindings);
4803 : :
4804 : 9782568 : FOR_EACH_LOCAL_DECL (id->src_cfun, ix, var)
4805 : 2632723 : reset_debug_binding (id, var, &bindings);
4806 : :
4807 : 3872765 : gsi_insert_seq_before_without_update (&gsi, bindings, GSI_SAME_STMT);
4808 : : }
4809 : :
4810 : : /* If STMT is a GIMPLE_CALL, replace it with its inline expansion. */
4811 : :
4812 : : static bool
4813 : 14928363 : expand_call_inline (basic_block bb, gimple *stmt, copy_body_data *id,
4814 : : bitmap to_purge)
4815 : : {
4816 : 14928363 : tree use_retvar;
4817 : 14928363 : tree fn;
4818 : 14928363 : hash_map<tree, tree> *dst;
4819 : 14928363 : hash_map<tree, tree> *st = NULL;
4820 : 14928363 : tree return_slot;
4821 : 14928363 : tree modify_dest;
4822 : 14928363 : struct cgraph_edge *cg_edge;
4823 : 14928363 : cgraph_inline_failed_t reason;
4824 : 14928363 : basic_block return_block;
4825 : 14928363 : edge e;
4826 : 14928363 : gimple_stmt_iterator gsi, stmt_gsi;
4827 : 14928363 : bool successfully_inlined = false;
4828 : 14928363 : bool purge_dead_abnormal_edges;
4829 : 14928363 : gcall *call_stmt;
4830 : 14928363 : unsigned int prop_mask, src_properties;
4831 : 14928363 : struct function *dst_cfun;
4832 : 14928363 : tree simduid;
4833 : 14928363 : use_operand_p use;
4834 : 14928363 : gimple *simtenter_stmt = NULL;
4835 : 14928363 : vec<tree> *simtvars_save;
4836 : 14928363 : tree save_stack = NULL_TREE;
4837 : :
4838 : : /* The gimplifier uses input_location in too many places, such as
4839 : : internal_get_tmp_var (). */
4840 : 14928363 : location_t saved_location = input_location;
4841 : 14928363 : input_location = gimple_location (stmt);
4842 : :
4843 : : /* From here on, we're only interested in CALL_EXPRs. */
4844 : 14928363 : call_stmt = dyn_cast <gcall *> (stmt);
4845 : 14928363 : if (!call_stmt)
4846 : 0 : goto egress;
4847 : :
4848 : 14928363 : cg_edge = id->dst_node->get_edge (stmt);
4849 : : /* Edge should exist and speculations should be resolved at this
4850 : : stage. */
4851 : 14928363 : gcc_checking_assert (cg_edge && !cg_edge->speculative);
4852 : : /* First, see if we can figure out what function is being called.
4853 : : If we cannot, then there is no hope of inlining the function. */
4854 : 14928363 : if (cg_edge->indirect_unknown_callee)
4855 : 245915 : goto egress;
4856 : 14682448 : fn = cg_edge->callee->decl;
4857 : 14682448 : gcc_checking_assert (fn);
4858 : :
4859 : : /* If FN is a declaration of a function in a nested scope that was
4860 : : globally declared inline, we don't set its DECL_INITIAL.
4861 : : However, we can't blindly follow DECL_ABSTRACT_ORIGIN because the
4862 : : C++ front-end uses it for cdtors to refer to their internal
4863 : : declarations, that are not real functions. Fortunately those
4864 : : don't have trees to be saved, so we can tell by checking their
4865 : : gimple_body. */
4866 : 14682448 : if (!DECL_INITIAL (fn)
4867 : 6414784 : && DECL_ABSTRACT_ORIGIN (fn)
4868 : 14862280 : && gimple_has_body_p (DECL_ABSTRACT_ORIGIN (fn)))
4869 : 317 : fn = DECL_ABSTRACT_ORIGIN (fn);
4870 : :
4871 : : /* Don't try to inline functions that are not well-suited to inlining. */
4872 : 14682448 : if (cg_edge->inline_failed)
4873 : : {
4874 : 10295747 : reason = cg_edge->inline_failed;
4875 : : /* If this call was originally indirect, we do not want to emit any
4876 : : inlining related warnings or sorry messages because there are no
4877 : : guarantees regarding those. */
4878 : 10295747 : if (cg_edge->indirect_inlining_edge)
4879 : 1839 : goto egress;
4880 : :
4881 : 10293908 : if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn))
4882 : : /* For extern inline functions that get redefined we always
4883 : : silently ignored always_inline flag. Better behavior would
4884 : : be to be able to keep both bodies and use extern inline body
4885 : : for inlining, but we can't do that because frontends overwrite
4886 : : the body. */
4887 : 53 : && !cg_edge->callee->redefined_extern_inline
4888 : : /* During early inline pass, report only when optimization is
4889 : : not turned on. */
4890 : 53 : && (symtab->global_info_ready
4891 : 51 : || !optimize
4892 : 41 : || cgraph_inline_failed_type (reason) == CIF_FINAL_ERROR)
4893 : : /* PR 20090218-1_0.c. Body can be provided by another module. */
4894 : 10293942 : && (reason != CIF_BODY_NOT_AVAILABLE || !flag_generate_lto))
4895 : : {
4896 : 27 : error ("inlining failed in call to %<always_inline%> %q+F: %s", fn,
4897 : : cgraph_inline_failed_string (reason));
4898 : 27 : if (gimple_location (stmt) != UNKNOWN_LOCATION)
4899 : 27 : inform (gimple_location (stmt), "called from here");
4900 : 0 : else if (DECL_SOURCE_LOCATION (cfun->decl) != UNKNOWN_LOCATION)
4901 : 0 : inform (DECL_SOURCE_LOCATION (cfun->decl),
4902 : : "called from this function");
4903 : : }
4904 : 10293881 : else if (opt_for_fn (fn, warn_inline)
4905 : 257 : && DECL_DECLARED_INLINE_P (fn)
4906 : 106 : && !DECL_NO_INLINE_WARNING_P (fn)
4907 : 38 : && !DECL_IN_SYSTEM_HEADER (fn)
4908 : 38 : && reason != CIF_UNSPECIFIED
4909 : 38 : && !lookup_attribute ("noinline", DECL_ATTRIBUTES (fn))
4910 : : /* Do not warn about not inlined recursive calls. */
4911 : 38 : && !cg_edge->recursive_p ()
4912 : : /* Avoid warnings during early inline pass. */
4913 : 10293919 : && symtab->global_info_ready)
4914 : : {
4915 : 8 : auto_diagnostic_group d;
4916 : 8 : if (warning (OPT_Winline, "inlining failed in call to %q+F: %s",
4917 : : fn, _(cgraph_inline_failed_string (reason))))
4918 : : {
4919 : 8 : if (gimple_location (stmt) != UNKNOWN_LOCATION)
4920 : 8 : inform (gimple_location (stmt), "called from here");
4921 : 0 : else if (DECL_SOURCE_LOCATION (cfun->decl) != UNKNOWN_LOCATION)
4922 : 0 : inform (DECL_SOURCE_LOCATION (cfun->decl),
4923 : : "called from this function");
4924 : : }
4925 : 8 : }
4926 : 10293908 : goto egress;
4927 : : }
4928 : 4386701 : id->src_node = cg_edge->callee;
4929 : :
4930 : : /* If callee is thunk, all we need is to adjust the THIS pointer
4931 : : and redirect to function being thunked. */
4932 : 4386701 : if (id->src_node->thunk)
4933 : : {
4934 : 197 : cgraph_edge *edge;
4935 : 197 : tree virtual_offset = NULL;
4936 : 197 : profile_count count = cg_edge->count;
4937 : 197 : tree op;
4938 : 197 : gimple_stmt_iterator iter = gsi_for_stmt (stmt);
4939 : 197 : thunk_info *info = thunk_info::get (id->src_node);
4940 : :
4941 : 197 : cgraph_edge::remove (cg_edge);
4942 : 394 : edge = id->src_node->callees->clone (id->dst_node, call_stmt,
4943 : : gimple_uid (stmt),
4944 : : profile_count::one (),
4945 : : profile_count::one (),
4946 : : true);
4947 : 197 : edge->count = count;
4948 : 197 : if (info->virtual_offset_p)
4949 : 7 : virtual_offset = size_int (info->virtual_value);
4950 : 197 : op = create_tmp_reg_fn (cfun, TREE_TYPE (gimple_call_arg (stmt, 0)),
4951 : : NULL);
4952 : 197 : gsi_insert_before (&iter, gimple_build_assign (op,
4953 : : gimple_call_arg (stmt, 0)),
4954 : : GSI_NEW_STMT);
4955 : 197 : gcc_assert (info->this_adjusting);
4956 : 197 : op = thunk_adjust (&iter, op, 1, info->fixed_offset,
4957 : : virtual_offset, info->indirect_offset);
4958 : :
4959 : 197 : gimple_call_set_arg (stmt, 0, op);
4960 : 197 : gimple_call_set_fndecl (stmt, edge->callee->decl);
4961 : 197 : update_stmt (stmt);
4962 : 197 : id->src_node->remove ();
4963 : 197 : successfully_inlined = expand_call_inline (bb, stmt, id, to_purge);
4964 : 197 : maybe_remove_unused_call_args (cfun, stmt);
4965 : : /* This used to return true even though we do fail to inline in
4966 : : some cases. See PR98525. */
4967 : 197 : goto egress;
4968 : : }
4969 : 4386504 : fn = cg_edge->callee->decl;
4970 : 4386504 : cg_edge->callee->get_untransformed_body ();
4971 : :
4972 : 4386504 : if (flag_checking && cg_edge->callee->decl != id->dst_node->decl)
4973 : 4386495 : cg_edge->callee->verify ();
4974 : :
4975 : : /* We will be inlining this callee. */
4976 : 4386504 : id->eh_lp_nr = lookup_stmt_eh_lp (stmt);
4977 : :
4978 : : /* Update the callers EH personality. */
4979 : 4386504 : if (DECL_FUNCTION_PERSONALITY (fn))
4980 : 266078 : DECL_FUNCTION_PERSONALITY (cg_edge->caller->decl)
4981 : 133039 : = DECL_FUNCTION_PERSONALITY (fn);
4982 : :
4983 : : /* Split the block before the GIMPLE_CALL. */
4984 : 4386504 : stmt_gsi = gsi_for_stmt (stmt);
4985 : 4386504 : gsi_prev (&stmt_gsi);
4986 : 4386504 : e = split_block (bb, gsi_end_p (stmt_gsi) ? NULL : gsi_stmt (stmt_gsi));
4987 : 4386504 : bb = e->src;
4988 : 4386504 : return_block = e->dest;
4989 : 4386504 : remove_edge (e);
4990 : :
4991 : : /* If the GIMPLE_CALL was in the last statement of BB, it may have
4992 : : been the source of abnormal edges. In this case, schedule
4993 : : the removal of dead abnormal edges. */
4994 : 4386504 : gsi = gsi_start_bb (return_block);
4995 : 4386504 : gsi_next (&gsi);
4996 : 4386504 : purge_dead_abnormal_edges = gsi_end_p (gsi);
4997 : :
4998 : 4386504 : stmt_gsi = gsi_start_bb (return_block);
4999 : :
5000 : : /* Build a block containing code to initialize the arguments, the
5001 : : actual inline expansion of the body, and a label for the return
5002 : : statements within the function to jump to. The type of the
5003 : : statement expression is the return type of the function call.
5004 : : ??? If the call does not have an associated block then we will
5005 : : remap all callee blocks to NULL, effectively dropping most of
5006 : : its debug information. This should only happen for calls to
5007 : : artificial decls inserted by the compiler itself. We need to
5008 : : either link the inlined blocks into the caller block tree or
5009 : : not refer to them in any way to not break GC for locations. */
5010 : 4386504 : if (tree block = gimple_block (stmt))
5011 : : {
5012 : : /* We do want to assign a not UNKNOWN_LOCATION BLOCK_SOURCE_LOCATION
5013 : : to make inlined_function_outer_scope_p return true on this BLOCK. */
5014 : 4358254 : location_t loc = LOCATION_LOCUS (gimple_location (stmt));
5015 : 4358254 : if (loc == UNKNOWN_LOCATION)
5016 : 227816 : loc = LOCATION_LOCUS (DECL_SOURCE_LOCATION (fn));
5017 : 227816 : if (loc == UNKNOWN_LOCATION)
5018 : : loc = BUILTINS_LOCATION;
5019 : 4358254 : id->block = make_node (BLOCK);
5020 : 7494732 : BLOCK_ABSTRACT_ORIGIN (id->block) = DECL_ORIGIN (fn);
5021 : 4358254 : BLOCK_SOURCE_LOCATION (id->block) = loc;
5022 : 4358254 : prepend_lexical_block (block, id->block);
5023 : : }
5024 : :
5025 : : /* Local declarations will be replaced by their equivalents in this map. */
5026 : 4386504 : st = id->decl_map;
5027 : 4386504 : id->decl_map = new hash_map<tree, tree>;
5028 : 4386504 : dst = id->debug_map;
5029 : 4386504 : id->debug_map = NULL;
5030 : 4386504 : if (flag_stack_reuse != SR_NONE)
5031 : 4380621 : id->add_clobbers_to_eh_landing_pads = last_basic_block_for_fn (cfun);
5032 : :
5033 : : /* Record the function we are about to inline. */
5034 : 4386504 : id->src_fn = fn;
5035 : 4386504 : id->src_cfun = DECL_STRUCT_FUNCTION (fn);
5036 : 4386504 : id->reset_location = DECL_IGNORED_P (fn);
5037 : 4386504 : id->call_stmt = call_stmt;
5038 : 4386504 : cfun->cfg->full_profile &= id->src_cfun->cfg->full_profile;
5039 : :
5040 : : /* When inlining into an OpenMP SIMD-on-SIMT loop, arrange for new automatic
5041 : : variables to be added to IFN_GOMP_SIMT_ENTER argument list. */
5042 : 4386504 : dst_cfun = DECL_STRUCT_FUNCTION (id->dst_fn);
5043 : 4386504 : simtvars_save = id->dst_simt_vars;
5044 : 4386504 : if (!(dst_cfun->curr_properties & PROP_gimple_lomp_dev)
5045 : 19617 : && (simduid = bb->loop_father->simduid) != NULL_TREE
5046 : 0 : && (simduid = ssa_default_def (dst_cfun, simduid)) != NULL_TREE
5047 : 0 : && single_imm_use (simduid, &use, &simtenter_stmt)
5048 : 0 : && is_gimple_call (simtenter_stmt)
5049 : 4386504 : && gimple_call_internal_p (simtenter_stmt, IFN_GOMP_SIMT_ENTER))
5050 : 0 : vec_alloc (id->dst_simt_vars, 0);
5051 : : else
5052 : 4386504 : id->dst_simt_vars = NULL;
5053 : :
5054 : 4386504 : if (profile_status_for_fn (id->src_cfun) == PROFILE_ABSENT)
5055 : 28129 : profile_status_for_fn (dst_cfun) = PROFILE_ABSENT;
5056 : :
5057 : : /* If the src function contains an IFN_VA_ARG, then so will the dst
5058 : : function after inlining. Likewise for IFN_GOMP_USE_SIMT. */
5059 : 4386504 : prop_mask = PROP_gimple_lva | PROP_gimple_lomp_dev;
5060 : 4386504 : src_properties = id->src_cfun->curr_properties & prop_mask;
5061 : 4386504 : if (src_properties != prop_mask)
5062 : 945 : dst_cfun->curr_properties &= src_properties | ~prop_mask;
5063 : 4386504 : dst_cfun->calls_eh_return |= id->src_cfun->calls_eh_return;
5064 : 4386504 : id->dst_node->has_omp_variant_constructs
5065 : 4386504 : |= id->src_node->has_omp_variant_constructs;
5066 : :
5067 : 4386504 : gcc_assert (!id->src_cfun->after_inlining);
5068 : :
5069 : 4386504 : id->entry_bb = bb;
5070 : 4386504 : if (lookup_attribute ("cold", DECL_ATTRIBUTES (fn)))
5071 : : {
5072 : 72 : gimple_stmt_iterator si = gsi_last_bb (bb);
5073 : 72 : gsi_insert_after (&si, gimple_build_predict (PRED_COLD_FUNCTION,
5074 : : NOT_TAKEN),
5075 : : GSI_NEW_STMT);
5076 : : }
5077 : 4386504 : initialize_inlined_parameters (id, stmt, fn, bb);
5078 : 3872783 : if (debug_nonbind_markers_p && debug_inline_points && id->block
5079 : 8244304 : && inlined_function_outer_scope_p (id->block))
5080 : : {
5081 : 3857800 : gimple_stmt_iterator si = gsi_last_bb (bb);
5082 : 3857800 : gsi_insert_after (&si, gimple_build_debug_inline_entry
5083 : 3857800 : (id->block, DECL_SOURCE_LOCATION (id->src_fn)),
5084 : : GSI_NEW_STMT);
5085 : : }
5086 : :
5087 : : /* If function to be inlined calls alloca, wrap the inlined function
5088 : : in between save_stack = __builtin_stack_save (); and
5089 : : __builtin_stack_restore (save_stack); calls. */
5090 : 4386504 : if (id->src_cfun->calls_alloca && !gimple_call_noreturn_p (stmt))
5091 : : /* Don't do this for VLA allocations though, just for user alloca
5092 : : calls. */
5093 : 4715 : for (struct cgraph_edge *e = id->src_node->callees; e; e = e->next_callee)
5094 : 4322 : if (gimple_maybe_alloca_call_p (e->call_stmt)
5095 : 4322 : && !gimple_call_alloca_for_var_p (e->call_stmt))
5096 : : {
5097 : 88 : tree fn = builtin_decl_implicit (BUILT_IN_STACK_SAVE);
5098 : 88 : gcall *call = gimple_build_call (fn, 0);
5099 : 88 : save_stack = make_ssa_name (ptr_type_node);
5100 : 88 : gimple_call_set_lhs (call, save_stack);
5101 : 88 : gimple_stmt_iterator si = gsi_last_bb (bb);
5102 : 88 : gsi_insert_after (&si, call, GSI_NEW_STMT);
5103 : 88 : struct cgraph_node *dest = cgraph_node::get_create (fn);
5104 : 88 : id->dst_node->create_edge (dest, call, bb->count)->inline_failed
5105 : 88 : = CIF_BODY_NOT_AVAILABLE;
5106 : 88 : break;
5107 : : }
5108 : :
5109 : 4386504 : if (DECL_INITIAL (fn))
5110 : : {
5111 : 4386504 : if (gimple_block (stmt))
5112 : : {
5113 : 4358254 : tree *var;
5114 : :
5115 : 4358254 : prepend_lexical_block (id->block,
5116 : 4358254 : remap_blocks (DECL_INITIAL (fn), id));
5117 : 4358254 : gcc_checking_assert (BLOCK_SUBBLOCKS (id->block)
5118 : : && (BLOCK_CHAIN (BLOCK_SUBBLOCKS (id->block))
5119 : : == NULL_TREE));
5120 : : /* Move vars for PARM_DECLs from DECL_INITIAL block to id->block,
5121 : : otherwise for DWARF DW_TAG_formal_parameter will not be children of
5122 : : DW_TAG_inlined_subroutine, but of a DW_TAG_lexical_block
5123 : : under it. The parameters can be then evaluated in the debugger,
5124 : : but don't show in backtraces. */
5125 : 6320636 : for (var = &BLOCK_VARS (BLOCK_SUBBLOCKS (id->block)); *var; )
5126 : 1962382 : if (TREE_CODE (DECL_ORIGIN (*var)) == PARM_DECL)
5127 : : {
5128 : 490923 : tree v = *var;
5129 : 490923 : *var = TREE_CHAIN (v);
5130 : 490923 : TREE_CHAIN (v) = BLOCK_VARS (id->block);
5131 : 490923 : BLOCK_VARS (id->block) = v;
5132 : : }
5133 : : else
5134 : 1471459 : var = &TREE_CHAIN (*var);
5135 : : }
5136 : : else
5137 : 28250 : remap_blocks_to_null (DECL_INITIAL (fn), id);
5138 : : }
5139 : :
5140 : : /* Return statements in the function body will be replaced by jumps
5141 : : to the RET_LABEL. */
5142 : 4386504 : gcc_assert (DECL_INITIAL (fn));
5143 : 4386504 : gcc_assert (TREE_CODE (DECL_INITIAL (fn)) == BLOCK);
5144 : :
5145 : : /* Find the LHS to which the result of this call is assigned. */
5146 : 4386504 : return_slot = NULL;
5147 : 4386504 : if (gimple_call_lhs (stmt))
5148 : : {
5149 : 2210236 : modify_dest = gimple_call_lhs (stmt);
5150 : :
5151 : : /* The function which we are inlining might not return a value,
5152 : : in which case we should issue a warning that the function
5153 : : does not return a value. In that case the optimizers will
5154 : : see that the variable to which the value is assigned was not
5155 : : initialized. We do not want to issue a warning about that
5156 : : uninitialized variable. */
5157 : 2210236 : if (DECL_P (modify_dest))
5158 : 446279 : suppress_warning (modify_dest, OPT_Wuninitialized);
5159 : :
5160 : : /* If we have a return slot, we can assign it the result directly,
5161 : : except in the case where it is a global variable that is only
5162 : : written to because, the callee being permitted to read or take
5163 : : the address of its DECL_RESULT, this could invalidate the flag
5164 : : on the global variable; instead we preventively remove the store,
5165 : : which would have happened later if the call was not inlined. */
5166 : 2210236 : if (gimple_call_return_slot_opt_p (call_stmt))
5167 : : {
5168 : 133147 : tree base = get_base_address (modify_dest);
5169 : :
5170 : 133147 : if (VAR_P (base)
5171 : 108108 : && (TREE_STATIC (base) || DECL_EXTERNAL (base))
5172 : 133217 : && varpool_node::get (base)->writeonly)
5173 : : return_slot = NULL;
5174 : : else
5175 : : return_slot = modify_dest;
5176 : :
5177 : : modify_dest = NULL;
5178 : : }
5179 : : }
5180 : : else
5181 : : modify_dest = NULL;
5182 : :
5183 : : /* If we are inlining a call to the C++ operator new, we don't want
5184 : : to use type based alias analysis on the return value. Otherwise
5185 : : we may get confused if the compiler sees that the inlined new
5186 : : function returns a pointer which was just deleted. See bug
5187 : : 33407. */
5188 : 4386504 : if (DECL_IS_OPERATOR_NEW_P (fn))
5189 : : {
5190 : 18714 : return_slot = NULL;
5191 : 18714 : modify_dest = NULL;
5192 : : }
5193 : :
5194 : : /* Declare the return variable for the function. */
5195 : 4386504 : use_retvar = declare_return_variable (id, return_slot, modify_dest, bb);
5196 : :
5197 : : /* Add local vars in this inlined callee to caller. */
5198 : 4386504 : add_local_variables (id->src_cfun, cfun, id);
5199 : :
5200 : 4386504 : if (dump_enabled_p ())
5201 : : {
5202 : 629 : char buf[128];
5203 : 629 : snprintf (buf, sizeof(buf), "%4.2f",
5204 : 629 : cg_edge->sreal_frequency ().to_double ());
5205 : 629 : dump_printf_loc (MSG_NOTE | MSG_PRIORITY_INTERNALS,
5206 : 629 : call_stmt,
5207 : : "Inlining %C to %C with frequency %s\n",
5208 : : id->src_node, id->dst_node, buf);
5209 : 629 : if (dump_file && (dump_flags & TDF_DETAILS))
5210 : : {
5211 : 192 : id->src_node->dump (dump_file);
5212 : 192 : id->dst_node->dump (dump_file);
5213 : : }
5214 : : }
5215 : :
5216 : : /* This is it. Duplicate the callee body. Assume callee is
5217 : : pre-gimplified. Note that we must not alter the caller
5218 : : function in any way before this point, as this CALL_EXPR may be
5219 : : a self-referential call; if we're calling ourselves, we need to
5220 : : duplicate our body before altering anything. */
5221 : 4386504 : copy_body (id, bb, return_block, NULL);
5222 : :
5223 : 4386504 : reset_debug_bindings (id, stmt_gsi);
5224 : :
5225 : 4386504 : if (flag_stack_reuse != SR_NONE)
5226 : 11813207 : for (tree p = DECL_ARGUMENTS (id->src_fn); p; p = DECL_CHAIN (p))
5227 : 7432586 : if (!TREE_THIS_VOLATILE (p))
5228 : : {
5229 : : /* The value associated with P is a local temporary only if
5230 : : there is no value associated with P in the debug map. */
5231 : 7432574 : tree *varp = id->decl_map->get (p);
5232 : 7432574 : if (varp
5233 : 7432574 : && VAR_P (*varp)
5234 : 7344512 : && !is_gimple_reg (*varp)
5235 : 7850511 : && !(id->debug_map && id->debug_map->get (p)))
5236 : : {
5237 : 417698 : tree clobber = build_clobber (TREE_TYPE (*varp),
5238 : : CLOBBER_STORAGE_END);
5239 : 417698 : gimple *clobber_stmt;
5240 : 417698 : clobber_stmt = gimple_build_assign (*varp, clobber);
5241 : 417698 : gimple_set_location (clobber_stmt, gimple_location (stmt));
5242 : 417698 : gsi_insert_before (&stmt_gsi, clobber_stmt, GSI_SAME_STMT);
5243 : : }
5244 : : }
5245 : :
5246 : 4386504 : if (save_stack)
5247 : : {
5248 : 88 : tree fn = builtin_decl_implicit (BUILT_IN_STACK_RESTORE);
5249 : 88 : gcall *call = gimple_build_call (fn, 1, save_stack);
5250 : 88 : gsi_insert_before (&stmt_gsi, call, GSI_SAME_STMT);
5251 : 88 : struct cgraph_node *dest = cgraph_node::get_create (fn);
5252 : 88 : id->dst_node->create_edge (dest, call,
5253 : : return_block->count)->inline_failed
5254 : 88 : = CIF_BODY_NOT_AVAILABLE;
5255 : : }
5256 : :
5257 : : /* Reset the escaped solution. */
5258 : 4386504 : if (cfun->gimple_df)
5259 : : {
5260 : 4386504 : pt_solution_reset (&cfun->gimple_df->escaped);
5261 : 4386504 : pt_solution_reset (&cfun->gimple_df->escaped_return);
5262 : : }
5263 : :
5264 : : /* Add new automatic variables to IFN_GOMP_SIMT_ENTER arguments. */
5265 : 4386504 : if (id->dst_simt_vars && id->dst_simt_vars->length () > 0)
5266 : : {
5267 : 0 : size_t nargs = gimple_call_num_args (simtenter_stmt);
5268 : 0 : vec<tree> *vars = id->dst_simt_vars;
5269 : 0 : auto_vec<tree> newargs (nargs + vars->length ());
5270 : 0 : for (size_t i = 0; i < nargs; i++)
5271 : 0 : newargs.quick_push (gimple_call_arg (simtenter_stmt, i));
5272 : 0 : for (tree *pvar = vars->begin (); pvar != vars->end (); pvar++)
5273 : : {
5274 : 0 : tree ptrtype = build_pointer_type (TREE_TYPE (*pvar));
5275 : 0 : newargs.quick_push (build1 (ADDR_EXPR, ptrtype, *pvar));
5276 : : }
5277 : 0 : gcall *g = gimple_build_call_internal_vec (IFN_GOMP_SIMT_ENTER, newargs);
5278 : 0 : gimple_call_set_lhs (g, gimple_call_lhs (simtenter_stmt));
5279 : 0 : gimple_stmt_iterator gsi = gsi_for_stmt (simtenter_stmt);
5280 : 0 : gsi_replace (&gsi, g, false);
5281 : 0 : }
5282 : 4386504 : vec_free (id->dst_simt_vars);
5283 : 4386504 : id->dst_simt_vars = simtvars_save;
5284 : :
5285 : : /* Clean up. */
5286 : 4386504 : if (id->debug_map)
5287 : : {
5288 : 84295 : delete id->debug_map;
5289 : 84295 : id->debug_map = dst;
5290 : : }
5291 : 8773008 : delete id->decl_map;
5292 : 4386504 : id->decl_map = st;
5293 : :
5294 : : /* Unlink the calls virtual operands before replacing it. */
5295 : 4386504 : unlink_stmt_vdef (stmt);
5296 : 4386504 : if (gimple_vdef (stmt)
5297 : 4386504 : && TREE_CODE (gimple_vdef (stmt)) == SSA_NAME)
5298 : 2080710 : release_ssa_name (gimple_vdef (stmt));
5299 : :
5300 : : /* If the inlined function returns a result that we care about,
5301 : : substitute the GIMPLE_CALL with an assignment of the return
5302 : : variable to the LHS of the call. That is, if STMT was
5303 : : 'a = foo (...)', substitute the call with 'a = USE_RETVAR'. */
5304 : 4386504 : if (use_retvar && gimple_call_lhs (stmt))
5305 : : {
5306 : 1855169 : gimple *old_stmt = stmt;
5307 : 1855169 : stmt = gimple_build_assign (gimple_call_lhs (stmt), use_retvar);
5308 : 1855169 : gimple_set_location (stmt, gimple_location (old_stmt));
5309 : 1855169 : gsi_replace (&stmt_gsi, stmt, false);
5310 : 1855169 : maybe_clean_or_replace_eh_stmt (old_stmt, stmt);
5311 : : /* Append a clobber for id->retvar if easily possible. */
5312 : 1855169 : if (flag_stack_reuse != SR_NONE
5313 : 1853271 : && id->retvar
5314 : 1853271 : && VAR_P (id->retvar)
5315 : 1853271 : && id->retvar != return_slot
5316 : 1853271 : && id->retvar != modify_dest
5317 : 1853271 : && !TREE_THIS_VOLATILE (id->retvar)
5318 : 1853245 : && !is_gimple_reg (id->retvar)
5319 : 1976791 : && !stmt_ends_bb_p (stmt))
5320 : : {
5321 : 121619 : tree clobber = build_clobber (TREE_TYPE (id->retvar),
5322 : : CLOBBER_STORAGE_END);
5323 : 121619 : gimple *clobber_stmt;
5324 : 121619 : clobber_stmt = gimple_build_assign (id->retvar, clobber);
5325 : 121619 : gimple_set_location (clobber_stmt, gimple_location (old_stmt));
5326 : 121619 : gsi_insert_after (&stmt_gsi, clobber_stmt, GSI_SAME_STMT);
5327 : : }
5328 : : }
5329 : : else
5330 : : {
5331 : : /* Handle the case of inlining a function with no return
5332 : : statement, which causes the return value to become undefined. */
5333 : 2531335 : if (gimple_call_lhs (stmt)
5334 : 2531335 : && TREE_CODE (gimple_call_lhs (stmt)) == SSA_NAME)
5335 : : {
5336 : 21 : tree name = gimple_call_lhs (stmt);
5337 : 21 : tree var = SSA_NAME_VAR (name);
5338 : 6 : tree def = var ? ssa_default_def (cfun, var) : NULL;
5339 : :
5340 : 6 : if (def)
5341 : : {
5342 : : /* If the variable is used undefined, make this name
5343 : : undefined via a move. */
5344 : 0 : stmt = gimple_build_assign (gimple_call_lhs (stmt), def);
5345 : 0 : gsi_replace (&stmt_gsi, stmt, true);
5346 : : }
5347 : : else
5348 : : {
5349 : 21 : if (!var)
5350 : : {
5351 : 15 : var = create_tmp_reg_fn (cfun, TREE_TYPE (name), NULL);
5352 : 30 : SET_SSA_NAME_VAR_OR_IDENTIFIER (name, var);
5353 : : }
5354 : : /* Otherwise make this variable undefined. */
5355 : 21 : gsi_remove (&stmt_gsi, true);
5356 : 21 : set_ssa_default_def (cfun, var, name);
5357 : 21 : SSA_NAME_DEF_STMT (name) = gimple_build_nop ();
5358 : : }
5359 : : }
5360 : : /* Replace with a clobber for id->retvar. */
5361 : 2531314 : else if (flag_stack_reuse != SR_NONE
5362 : 2527329 : && id->retvar
5363 : 494757 : && VAR_P (id->retvar)
5364 : 404738 : && id->retvar != return_slot
5365 : 358322 : && id->retvar != modify_dest
5366 : 139997 : && !TREE_THIS_VOLATILE (id->retvar)
5367 : 2671311 : && !is_gimple_reg (id->retvar))
5368 : : {
5369 : 26820 : tree clobber = build_clobber (TREE_TYPE (id->retvar));
5370 : 26820 : gimple *clobber_stmt;
5371 : 26820 : clobber_stmt = gimple_build_assign (id->retvar, clobber);
5372 : 26820 : gimple_set_location (clobber_stmt, gimple_location (stmt));
5373 : 26820 : gsi_replace (&stmt_gsi, clobber_stmt, false);
5374 : 26820 : maybe_clean_or_replace_eh_stmt (stmt, clobber_stmt);
5375 : : }
5376 : : else
5377 : 2504494 : gsi_remove (&stmt_gsi, true);
5378 : : }
5379 : :
5380 : 4386504 : if (purge_dead_abnormal_edges)
5381 : 1030183 : bitmap_set_bit (to_purge, return_block->index);
5382 : :
5383 : : /* If the value of the new expression is ignored, that's OK. We
5384 : : don't warn about this for CALL_EXPRs, so we shouldn't warn about
5385 : : the equivalent inlined version either. */
5386 : 4386504 : if (is_gimple_assign (stmt))
5387 : : {
5388 : 1855169 : gcc_assert (gimple_assign_single_p (stmt)
5389 : : || CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (stmt)));
5390 : 1855169 : TREE_USED (gimple_assign_rhs1 (stmt)) = 1;
5391 : : }
5392 : :
5393 : 4386504 : id->add_clobbers_to_eh_landing_pads = 0;
5394 : :
5395 : : /* Output the inlining info for this abstract function, since it has been
5396 : : inlined. If we don't do this now, we can lose the information about the
5397 : : variables in the function when the blocks get blown away as soon as we
5398 : : remove the cgraph node. */
5399 : 4386504 : if (gimple_block (stmt))
5400 : 4358254 : (*debug_hooks->outlining_inline_function) (fn);
5401 : :
5402 : : /* Update callgraph if needed. */
5403 : 4386504 : cg_edge->callee->remove ();
5404 : :
5405 : 4386504 : id->block = NULL_TREE;
5406 : 4386504 : id->retvar = NULL_TREE;
5407 : 4386504 : successfully_inlined = true;
5408 : :
5409 : 14928363 : egress:
5410 : 14928363 : input_location = saved_location;
5411 : 14928363 : return successfully_inlined;
5412 : : }
5413 : :
5414 : : /* Expand call statements reachable from STMT_P.
5415 : : We can only have CALL_EXPRs as the "toplevel" tree code or nested
5416 : : in a MODIFY_EXPR. */
5417 : :
5418 : : static bool
5419 : 30909985 : gimple_expand_calls_inline (basic_block bb, copy_body_data *id,
5420 : : bitmap to_purge)
5421 : : {
5422 : 30909985 : gimple_stmt_iterator gsi;
5423 : 30909985 : bool inlined = false;
5424 : :
5425 : 226406923 : for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi);)
5426 : : {
5427 : 164586953 : gimple *stmt = gsi_stmt (gsi);
5428 : 164586953 : gsi_prev (&gsi);
5429 : :
5430 : 164586953 : if (is_gimple_call (stmt)
5431 : 164586953 : && !gimple_call_internal_p (stmt))
5432 : 14928166 : inlined |= expand_call_inline (bb, stmt, id, to_purge);
5433 : : }
5434 : :
5435 : 30909985 : return inlined;
5436 : : }
5437 : :
5438 : :
5439 : : /* Walk all basic blocks created after FIRST and try to fold every statement
5440 : : in the STATEMENTS pointer set. */
5441 : :
5442 : : static void
5443 : 1591490 : fold_marked_statements (int first, hash_set<gimple *> *statements)
5444 : : {
5445 : 1591490 : auto_bitmap to_purge;
5446 : 1591490 : auto_bitmap to_purge_abnormal;
5447 : :
5448 : 1591490 : auto_vec<edge, 20> stack (n_basic_blocks_for_fn (cfun) + 2);
5449 : 1591490 : auto_sbitmap visited (last_basic_block_for_fn (cfun));
5450 : 1591490 : bitmap_clear (visited);
5451 : :
5452 : 1591490 : stack.quick_push (single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
5453 : 37718376 : while (!stack.is_empty ())
5454 : : {
5455 : : /* Look at the edge on the top of the stack. */
5456 : 36126886 : edge e = stack.pop ();
5457 : 36126886 : basic_block dest = e->dest;
5458 : :
5459 : 44508293 : if (dest == EXIT_BLOCK_PTR_FOR_FN (cfun)
5460 : 34567375 : || bitmap_bit_p (visited, dest->index))
5461 : 8381407 : continue;
5462 : :
5463 : 27745479 : bitmap_set_bit (visited, dest->index);
5464 : :
5465 : 27745479 : if (dest->index >= first)
5466 : 35197774 : for (gimple_stmt_iterator gsi = gsi_start_bb (dest);
5467 : 120228097 : !gsi_end_p (gsi); gsi_next (&gsi))
5468 : : {
5469 : 102629210 : if (!statements->contains (gsi_stmt (gsi)))
5470 : 22609352 : continue;
5471 : :
5472 : 80019858 : gimple *old_stmt = gsi_stmt (gsi);
5473 : 80019858 : bool can_make_abnormal_goto = false;
5474 : 80019858 : tree old_decl = NULL_TREE;
5475 : :
5476 : 80019858 : if (is_gimple_call (old_stmt))
5477 : : {
5478 : 3563037 : old_decl = gimple_call_fndecl (old_stmt);
5479 : 3563037 : if (stmt_can_make_abnormal_goto (old_stmt))
5480 : : can_make_abnormal_goto = true;
5481 : : }
5482 : :
5483 : 3563037 : if (old_decl && fndecl_built_in_p (old_decl))
5484 : : {
5485 : : /* Folding builtins can create multiple instructions,
5486 : : we need to look at all of them. */
5487 : 1240654 : gimple_stmt_iterator i2 = gsi;
5488 : 1240654 : gsi_prev (&i2);
5489 : 1240654 : if (fold_stmt (&gsi))
5490 : : {
5491 : 90296 : gimple *new_stmt;
5492 : : /* If a builtin at the end of a bb folded into nothing,
5493 : : the following loop won't work. */
5494 : 90296 : if (gsi_end_p (gsi))
5495 : : {
5496 : 0 : cgraph_update_edges_for_call_stmt (old_stmt,
5497 : : old_decl, NULL);
5498 : 0 : if (can_make_abnormal_goto)
5499 : 0 : bitmap_set_bit (to_purge_abnormal, dest->index);
5500 : 17598887 : break;
5501 : : }
5502 : 90296 : if (gsi_end_p (i2))
5503 : 125194 : i2 = gsi_start_bb (dest);
5504 : : else
5505 : 27699 : gsi_next (&i2);
5506 : 414 : while (1)
5507 : : {
5508 : 90710 : new_stmt = gsi_stmt (i2);
5509 : 90710 : update_stmt (new_stmt);
5510 : 90710 : cgraph_update_edges_for_call_stmt (old_stmt, old_decl,
5511 : : new_stmt);
5512 : :
5513 : 90710 : if (new_stmt == gsi_stmt (gsi))
5514 : : {
5515 : : /* It is okay to check only for the very last
5516 : : of these statements. If it is a throwing
5517 : : statement nothing will change. If it isn't
5518 : : this can remove EH edges. If that weren't
5519 : : correct then because some intermediate stmts
5520 : : throw, but not the last one. That would mean
5521 : : we'd have to split the block, which we can't
5522 : : here and we'd loose anyway. And as builtins
5523 : : probably never throw, this all
5524 : : is mood anyway. */
5525 : 90296 : if (maybe_clean_or_replace_eh_stmt (old_stmt,
5526 : : new_stmt))
5527 : 7 : bitmap_set_bit (to_purge, dest->index);
5528 : 90296 : if (can_make_abnormal_goto
5529 : 90296 : && !stmt_can_make_abnormal_goto (new_stmt))
5530 : 0 : bitmap_set_bit (to_purge_abnormal, dest->index);
5531 : : break;
5532 : : }
5533 : 414 : gsi_next (&i2);
5534 : : }
5535 : : }
5536 : : }
5537 : 78779204 : else if (fold_stmt (&gsi))
5538 : : {
5539 : : /* Re-read the statement from GSI as fold_stmt() may
5540 : : have changed it. */
5541 : 2859345 : gimple *new_stmt = gsi_stmt (gsi);
5542 : 2859345 : update_stmt (new_stmt);
5543 : :
5544 : 2859345 : if (is_gimple_call (old_stmt)
5545 : 2859345 : || is_gimple_call (new_stmt))
5546 : 4515 : cgraph_update_edges_for_call_stmt (old_stmt, old_decl,
5547 : : new_stmt);
5548 : :
5549 : 2859345 : if (maybe_clean_or_replace_eh_stmt (old_stmt, new_stmt))
5550 : 167 : bitmap_set_bit (to_purge, dest->index);
5551 : 2859345 : if (can_make_abnormal_goto
5552 : 2859345 : && !stmt_can_make_abnormal_goto (new_stmt))
5553 : 7 : bitmap_set_bit (to_purge_abnormal, dest->index);
5554 : : }
5555 : : }
5556 : :
5557 : 54026307 : if (EDGE_COUNT (dest->succs) > 0)
5558 : : {
5559 : : /* Avoid warnings emitted from folding statements that
5560 : : became unreachable because of inlined function parameter
5561 : : propagation. */
5562 : 26280828 : e = find_taken_edge (dest, NULL_TREE);
5563 : 26280828 : if (e)
5564 : 18242168 : stack.quick_push (e);
5565 : : else
5566 : : {
5567 : 8038660 : edge_iterator ei;
5568 : 24331888 : FOR_EACH_EDGE (e, ei, dest->succs)
5569 : 16293228 : stack.safe_push (e);
5570 : : }
5571 : : }
5572 : : }
5573 : :
5574 : 1591490 : gimple_purge_all_dead_eh_edges (to_purge);
5575 : 1591490 : gimple_purge_all_dead_abnormal_call_edges (to_purge_abnormal);
5576 : 1591490 : }
5577 : :
5578 : : /* Expand calls to inline functions in the body of FN. */
5579 : :
5580 : : unsigned int
5581 : 1972315 : optimize_inline_calls (tree fn)
5582 : : {
5583 : 1972315 : copy_body_data id;
5584 : 1972315 : basic_block bb;
5585 : 1972315 : int last = n_basic_blocks_for_fn (cfun);
5586 : 1972315 : bool inlined_p = false;
5587 : :
5588 : : /* Clear out ID. */
5589 : 1972315 : memset (&id, 0, sizeof (id));
5590 : :
5591 : 1972315 : id.src_node = id.dst_node = cgraph_node::get (fn);
5592 : 1972315 : gcc_assert (id.dst_node->definition);
5593 : 1972315 : id.dst_fn = fn;
5594 : : /* Or any functions that aren't finished yet. */
5595 : 1972315 : if (current_function_decl)
5596 : 1972315 : id.dst_fn = current_function_decl;
5597 : :
5598 : 1972315 : id.copy_decl = copy_decl_maybe_to_var;
5599 : 1972315 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
5600 : 1972315 : id.transform_new_cfg = false;
5601 : 1972315 : id.transform_return_to_modify = true;
5602 : 1972315 : id.transform_parameter = true;
5603 : 1972315 : id.statements_to_fold = new hash_set<gimple *>;
5604 : :
5605 : 1972315 : push_gimplify_context ();
5606 : :
5607 : : /* We make no attempts to keep dominance info up-to-date. */
5608 : 1972315 : free_dominance_info (CDI_DOMINATORS);
5609 : 1972315 : free_dominance_info (CDI_POST_DOMINATORS);
5610 : :
5611 : : /* Register specific gimple functions. */
5612 : 1972315 : gimple_register_cfg_hooks ();
5613 : :
5614 : : /* Reach the trees by walking over the CFG, and note the
5615 : : enclosing basic-blocks in the call edges. */
5616 : : /* We walk the blocks going forward, because inlined function bodies
5617 : : will split id->current_basic_block, and the new blocks will
5618 : : follow it; we'll trudge through them, processing their CALL_EXPRs
5619 : : along the way. */
5620 : 1972315 : auto_bitmap to_purge;
5621 : 32882300 : FOR_EACH_BB_FN (bb, cfun)
5622 : 30909985 : inlined_p |= gimple_expand_calls_inline (bb, &id, to_purge);
5623 : :
5624 : 1972315 : pop_gimplify_context (NULL);
5625 : :
5626 : 1972315 : if (flag_checking)
5627 : : {
5628 : 1972297 : struct cgraph_edge *e;
5629 : :
5630 : 1972297 : id.dst_node->verify ();
5631 : :
5632 : : /* Double check that we inlined everything we are supposed to inline. */
5633 : 11584912 : for (e = id.dst_node->callees; e; e = e->next_callee)
5634 : 9612615 : gcc_assert (e->inline_failed);
5635 : : }
5636 : :
5637 : : /* If we didn't inline into the function there is nothing to do. */
5638 : 1972315 : if (!inlined_p)
5639 : : {
5640 : 1212460 : delete id.statements_to_fold;
5641 : 606230 : return 0;
5642 : : }
5643 : :
5644 : : /* Fold queued statements. */
5645 : 1366085 : update_max_bb_count ();
5646 : 1366085 : fold_marked_statements (last, id.statements_to_fold);
5647 : 2732170 : delete id.statements_to_fold;
5648 : :
5649 : : /* Finally purge EH and abnormal edges from the call stmts we inlined.
5650 : : We need to do this after fold_marked_statements since that may walk
5651 : : the SSA use-def chain. */
5652 : 1366085 : unsigned i;
5653 : 1366085 : bitmap_iterator bi;
5654 : 2396268 : EXECUTE_IF_SET_IN_BITMAP (to_purge, 0, i, bi)
5655 : : {
5656 : 1030183 : basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
5657 : 1030183 : if (bb)
5658 : : {
5659 : 1030183 : gimple_purge_dead_eh_edges (bb);
5660 : 1030183 : gimple_purge_dead_abnormal_call_edges (bb);
5661 : : }
5662 : : }
5663 : :
5664 : 1366085 : gcc_assert (!id.debug_stmts.exists ());
5665 : :
5666 : : /* Renumber the lexical scoping (non-code) blocks consecutively. */
5667 : 1366085 : number_blocks (fn);
5668 : :
5669 : 1366085 : delete_unreachable_blocks_update_callgraph (id.dst_node, false);
5670 : 1366085 : id.dst_node->calls_comdat_local = id.dst_node->check_calls_comdat_local_p ();
5671 : :
5672 : 1366085 : if (flag_checking)
5673 : 1366076 : id.dst_node->verify ();
5674 : :
5675 : : /* It would be nice to check SSA/CFG/statement consistency here, but it is
5676 : : not possible yet - the IPA passes might make various functions to not
5677 : : throw and they don't care to proactively update local EH info. This is
5678 : : done later in fixup_cfg pass that also execute the verification. */
5679 : 1366085 : return (TODO_update_ssa
5680 : : | TODO_cleanup_cfg
5681 : 1366085 : | (gimple_in_ssa_p (cfun) ? TODO_remove_unused_locals : 0)
5682 : 2732170 : | (gimple_in_ssa_p (cfun) ? TODO_update_address_taken : 0));
5683 : 1972315 : }
5684 : :
5685 : : /* Passed to walk_tree. Copies the node pointed to, if appropriate. */
5686 : :
5687 : : tree
5688 : 1406402042 : copy_tree_r (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
5689 : : {
5690 : 1406402042 : enum tree_code code = TREE_CODE (*tp);
5691 : 1406402042 : enum tree_code_class cl = TREE_CODE_CLASS (code);
5692 : :
5693 : : /* We make copies of most nodes. */
5694 : 1406402042 : if (IS_EXPR_CODE_CLASS (cl)
5695 : : || code == TREE_LIST
5696 : 242143025 : || code == TREE_VEC
5697 : 238114661 : || code == TYPE_DECL
5698 : 238114661 : || code == OMP_CLAUSE)
5699 : : {
5700 : : /* Because the chain gets clobbered when we make a copy, we save it
5701 : : here. */
5702 : 1168310526 : tree chain = NULL_TREE, new_tree;
5703 : :
5704 : 1168310526 : if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
5705 : 4051509 : chain = TREE_CHAIN (*tp);
5706 : :
5707 : : /* Copy the node. */
5708 : 1168310526 : new_tree = copy_node (*tp);
5709 : :
5710 : 1168310526 : *tp = new_tree;
5711 : :
5712 : : /* Now, restore the chain, if appropriate. That will cause
5713 : : walk_tree to walk into the chain as well. */
5714 : 1168310526 : if (code == PARM_DECL
5715 : 1168310526 : || code == TREE_LIST
5716 : 1166508733 : || code == OMP_CLAUSE)
5717 : 1824914 : TREE_CHAIN (*tp) = chain;
5718 : :
5719 : : /* For now, we don't update BLOCKs when we make copies. So, we
5720 : : have to nullify all BIND_EXPRs. */
5721 : 1168310526 : if (TREE_CODE (*tp) == BIND_EXPR)
5722 : 12265843 : BIND_EXPR_BLOCK (*tp) = NULL_TREE;
5723 : : }
5724 : 238091516 : else if (code == CONSTRUCTOR)
5725 : : {
5726 : : /* CONSTRUCTOR nodes need special handling because
5727 : : we need to duplicate the vector of elements. */
5728 : 21150593 : tree new_tree;
5729 : :
5730 : 21150593 : new_tree = copy_node (*tp);
5731 : 27365106 : CONSTRUCTOR_ELTS (new_tree) = vec_safe_copy (CONSTRUCTOR_ELTS (*tp));
5732 : 21150593 : *tp = new_tree;
5733 : : }
5734 : 216940923 : else if (code == STATEMENT_LIST)
5735 : : /* We used to just abort on STATEMENT_LIST, but we can run into them
5736 : : with statement-expressions (c++/40975). */
5737 : 24 : copy_statement_list (tp);
5738 : 216940899 : else if (TREE_CODE_CLASS (code) == tcc_type)
5739 : 104 : *walk_subtrees = 0;
5740 : 216940795 : else if (TREE_CODE_CLASS (code) == tcc_declaration)
5741 : 73242402 : *walk_subtrees = 0;
5742 : 143698393 : else if (TREE_CODE_CLASS (code) == tcc_constant)
5743 : 0 : *walk_subtrees = 0;
5744 : 1406402042 : return NULL_TREE;
5745 : : }
5746 : :
5747 : : /* The SAVE_EXPR pointed to by TP is being copied. If ST contains
5748 : : information indicating to what new SAVE_EXPR this one should be mapped,
5749 : : use that one. Otherwise, create a new node and enter it in ST. FN is
5750 : : the function into which the copy will be placed. */
5751 : :
5752 : : static void
5753 : 6710153 : remap_save_expr (tree *tp, hash_map<tree, tree> *st, int *walk_subtrees)
5754 : : {
5755 : 6710153 : tree *n;
5756 : 6710153 : tree t;
5757 : :
5758 : : /* See if we already encountered this SAVE_EXPR. */
5759 : 6710153 : n = st->get (*tp);
5760 : :
5761 : : /* If we didn't already remap this SAVE_EXPR, do so now. */
5762 : 6710153 : if (!n)
5763 : : {
5764 : 6428710 : t = copy_node (*tp);
5765 : :
5766 : : /* Remember this SAVE_EXPR. */
5767 : 6428710 : st->put (*tp, t);
5768 : : /* Make sure we don't remap an already-remapped SAVE_EXPR. */
5769 : 6428710 : st->put (t, t);
5770 : : }
5771 : : else
5772 : : {
5773 : : /* We've already walked into this SAVE_EXPR; don't do it again. */
5774 : 281443 : *walk_subtrees = 0;
5775 : 281443 : t = *n;
5776 : : }
5777 : :
5778 : : /* Replace this SAVE_EXPR with the copy. */
5779 : 6710153 : *tp = t;
5780 : 6710153 : }
5781 : :
5782 : : /* Called via walk_gimple_seq. If *GSIP points to a GIMPLE_LABEL for a local
5783 : : label, copies the declaration and enters it in the splay_tree in DATA (which
5784 : : is really a 'copy_body_data *'. */
5785 : :
5786 : : static tree
5787 : 1603586 : mark_local_labels_stmt (gimple_stmt_iterator *gsip,
5788 : : bool *handled_ops_p ATTRIBUTE_UNUSED,
5789 : : struct walk_stmt_info *wi)
5790 : : {
5791 : 1603586 : copy_body_data *id = (copy_body_data *) wi->info;
5792 : 1603586 : glabel *stmt = dyn_cast <glabel *> (gsi_stmt (*gsip));
5793 : :
5794 : 50627 : if (stmt)
5795 : : {
5796 : 50627 : tree decl = gimple_label_label (stmt);
5797 : :
5798 : : /* Copy the decl and remember the copy. */
5799 : 50627 : insert_decl_map (id, decl, id->copy_decl (decl, id));
5800 : : }
5801 : :
5802 : 1603586 : return NULL_TREE;
5803 : : }
5804 : :
5805 : : static gimple_seq duplicate_remap_omp_clause_seq (gimple_seq seq,
5806 : : struct walk_stmt_info *wi);
5807 : :
5808 : : /* Called via walk_gimple_seq by copy_gimple_seq_and_replace_local.
5809 : : Using the splay_tree pointed to by ST (which is really a `splay_tree'),
5810 : : remaps all local declarations to appropriate replacements in gimple
5811 : : operands. */
5812 : :
5813 : : static tree
5814 : 3512220 : replace_locals_op (tree *tp, int *walk_subtrees, void *data)
5815 : : {
5816 : 3512220 : struct walk_stmt_info *wi = (struct walk_stmt_info*) data;
5817 : 3512220 : copy_body_data *id = (copy_body_data *) wi->info;
5818 : 3512220 : hash_map<tree, tree> *st = id->decl_map;
5819 : 3512220 : tree *n;
5820 : 3512220 : tree expr = *tp;
5821 : :
5822 : : /* For recursive invocations this is no longer the LHS itself. */
5823 : 3512220 : bool is_lhs = wi->is_lhs;
5824 : 3512220 : wi->is_lhs = false;
5825 : :
5826 : 3512220 : if (TREE_CODE (expr) == SSA_NAME)
5827 : : {
5828 : 23666 : *tp = remap_ssa_name (*tp, id);
5829 : 23666 : *walk_subtrees = 0;
5830 : 23666 : if (is_lhs)
5831 : 11833 : SSA_NAME_DEF_STMT (*tp) = gsi_stmt (wi->gsi);
5832 : : }
5833 : : /* Only a local declaration (variable or label). */
5834 : 3488554 : else if ((VAR_P (expr) && !TREE_STATIC (expr))
5835 : 2034237 : || TREE_CODE (expr) == LABEL_DECL)
5836 : : {
5837 : : /* Lookup the declaration. */
5838 : 1557627 : n = st->get (expr);
5839 : :
5840 : : /* If it's there, remap it. */
5841 : 1557627 : if (n)
5842 : 101968 : *tp = *n;
5843 : 1557627 : *walk_subtrees = 0;
5844 : : }
5845 : 1930927 : else if (TREE_CODE (expr) == STATEMENT_LIST
5846 : 1930927 : || TREE_CODE (expr) == BIND_EXPR
5847 : 1930927 : || TREE_CODE (expr) == SAVE_EXPR)
5848 : 0 : gcc_unreachable ();
5849 : 1930927 : else if (TREE_CODE (expr) == TARGET_EXPR)
5850 : : {
5851 : : /* Don't mess with a TARGET_EXPR that hasn't been expanded.
5852 : : It's OK for this to happen if it was part of a subtree that
5853 : : isn't immediately expanded, such as operand 2 of another
5854 : : TARGET_EXPR. */
5855 : 0 : if (!TREE_OPERAND (expr, 1))
5856 : : {
5857 : 0 : TREE_OPERAND (expr, 1) = TREE_OPERAND (expr, 3);
5858 : 0 : TREE_OPERAND (expr, 3) = NULL_TREE;
5859 : : }
5860 : : }
5861 : 1930927 : else if (TREE_CODE (expr) == OMP_CLAUSE)
5862 : : {
5863 : : /* Before the omplower pass completes, some OMP clauses can contain
5864 : : sequences that are neither copied by gimple_seq_copy nor walked by
5865 : : walk_gimple_seq. To make copy_gimple_seq_and_replace_locals work even
5866 : : in those situations, we have to copy and process them explicitely. */
5867 : :
5868 : 552 : if (OMP_CLAUSE_CODE (expr) == OMP_CLAUSE_LASTPRIVATE)
5869 : : {
5870 : 14 : gimple_seq seq = OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (expr);
5871 : 14 : seq = duplicate_remap_omp_clause_seq (seq, wi);
5872 : 14 : OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (expr) = seq;
5873 : : }
5874 : 538 : else if (OMP_CLAUSE_CODE (expr) == OMP_CLAUSE_LINEAR)
5875 : : {
5876 : 77 : gimple_seq seq = OMP_CLAUSE_LINEAR_GIMPLE_SEQ (expr);
5877 : 77 : seq = duplicate_remap_omp_clause_seq (seq, wi);
5878 : 77 : OMP_CLAUSE_LINEAR_GIMPLE_SEQ (expr) = seq;
5879 : : }
5880 : 461 : else if (OMP_CLAUSE_CODE (expr) == OMP_CLAUSE_REDUCTION)
5881 : : {
5882 : 99 : gimple_seq seq = OMP_CLAUSE_REDUCTION_GIMPLE_INIT (expr);
5883 : 99 : seq = duplicate_remap_omp_clause_seq (seq, wi);
5884 : 99 : OMP_CLAUSE_REDUCTION_GIMPLE_INIT (expr) = seq;
5885 : 99 : seq = OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (expr);
5886 : 99 : seq = duplicate_remap_omp_clause_seq (seq, wi);
5887 : 99 : OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (expr) = seq;
5888 : : }
5889 : : }
5890 : :
5891 : : /* Keep iterating. */
5892 : 3512220 : return NULL_TREE;
5893 : : }
5894 : :
5895 : :
5896 : : /* Called via walk_gimple_seq by copy_gimple_seq_and_replace_local.
5897 : : Using the splay_tree pointed to by ST (which is really a `splay_tree'),
5898 : : remaps all local declarations to appropriate replacements in gimple
5899 : : statements. */
5900 : :
5901 : : static tree
5902 : 1603586 : replace_locals_stmt (gimple_stmt_iterator *gsip,
5903 : : bool *handled_ops_p ATTRIBUTE_UNUSED,
5904 : : struct walk_stmt_info *wi)
5905 : : {
5906 : 1603586 : copy_body_data *id = (copy_body_data *) wi->info;
5907 : 1603586 : gimple *gs = gsi_stmt (*gsip);
5908 : :
5909 : 1603586 : if (gbind *stmt = dyn_cast <gbind *> (gs))
5910 : : {
5911 : 349 : tree block = gimple_bind_block (stmt);
5912 : :
5913 : 349 : if (block)
5914 : : {
5915 : 269 : remap_block (&block, id);
5916 : 269 : gimple_bind_set_block (stmt, block);
5917 : : }
5918 : :
5919 : : /* This will remap a lot of the same decls again, but this should be
5920 : : harmless. */
5921 : 349 : if (gimple_bind_vars (stmt))
5922 : : {
5923 : : tree old_var, decls = gimple_bind_vars (stmt);
5924 : :
5925 : 528 : for (old_var = decls; old_var; old_var = DECL_CHAIN (old_var))
5926 : 360 : if (!can_be_nonlocal (old_var, id)
5927 : 360 : && ! variably_modified_type_p (TREE_TYPE (old_var), id->src_fn))
5928 : 360 : remap_decl (old_var, id);
5929 : :
5930 : 168 : gcc_checking_assert (!id->prevent_decl_creation_for_types);
5931 : 168 : id->prevent_decl_creation_for_types = true;
5932 : 168 : gimple_bind_set_vars (stmt, remap_decls (decls, NULL, id));
5933 : 168 : id->prevent_decl_creation_for_types = false;
5934 : : }
5935 : : }
5936 : :
5937 : : /* Keep iterating. */
5938 : 1603586 : return NULL_TREE;
5939 : : }
5940 : :
5941 : : /* Create a copy of SEQ and remap all decls in it. */
5942 : :
5943 : : static gimple_seq
5944 : 289 : duplicate_remap_omp_clause_seq (gimple_seq seq, struct walk_stmt_info *wi)
5945 : : {
5946 : 289 : if (!seq)
5947 : : return NULL;
5948 : :
5949 : : /* If there are any labels in OMP sequences, they can be only referred to in
5950 : : the sequence itself and therefore we can do both here. */
5951 : 60 : walk_gimple_seq (seq, mark_local_labels_stmt, NULL, wi);
5952 : 60 : gimple_seq copy = gimple_seq_copy (seq);
5953 : 60 : walk_gimple_seq (copy, replace_locals_stmt, replace_locals_op, wi);
5954 : 60 : return copy;
5955 : : }
5956 : :
5957 : : /* Copies everything in SEQ and replaces variables and labels local to
5958 : : current_function_decl. */
5959 : :
5960 : : gimple_seq
5961 : 1080263 : copy_gimple_seq_and_replace_locals (gimple_seq seq)
5962 : : {
5963 : 1080263 : copy_body_data id;
5964 : 1080263 : struct walk_stmt_info wi;
5965 : 1080263 : gimple_seq copy;
5966 : :
5967 : : /* There's nothing to do for NULL_TREE. */
5968 : 1080263 : if (seq == NULL)
5969 : : return seq;
5970 : :
5971 : : /* Set up ID. */
5972 : 1080247 : memset (&id, 0, sizeof (id));
5973 : 1080247 : id.src_fn = current_function_decl;
5974 : 1080247 : id.dst_fn = current_function_decl;
5975 : 1080247 : id.src_cfun = cfun;
5976 : 1080247 : id.decl_map = new hash_map<tree, tree>;
5977 : 1080247 : id.debug_map = NULL;
5978 : :
5979 : 1080247 : id.copy_decl = copy_decl_no_change;
5980 : 1080247 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
5981 : 1080247 : id.transform_new_cfg = false;
5982 : 1080247 : id.transform_return_to_modify = false;
5983 : 1080247 : id.transform_parameter = false;
5984 : :
5985 : : /* Walk the tree once to find local labels. */
5986 : 1080247 : memset (&wi, 0, sizeof (wi));
5987 : 1080247 : hash_set<tree> visited;
5988 : 1080247 : wi.info = &id;
5989 : 1080247 : wi.pset = &visited;
5990 : 1080247 : walk_gimple_seq (seq, mark_local_labels_stmt, NULL, &wi);
5991 : :
5992 : 1080247 : copy = gimple_seq_copy (seq);
5993 : :
5994 : : /* Walk the copy, remapping decls. */
5995 : 1080247 : memset (&wi, 0, sizeof (wi));
5996 : 1080247 : wi.info = &id;
5997 : 1080247 : walk_gimple_seq (copy, replace_locals_stmt, replace_locals_op, &wi);
5998 : :
5999 : : /* Clean up. */
6000 : 2160494 : delete id.decl_map;
6001 : 1080247 : if (id.debug_map)
6002 : 0 : delete id.debug_map;
6003 : 1080247 : if (id.dependence_map)
6004 : : {
6005 : 0 : delete id.dependence_map;
6006 : 0 : id.dependence_map = NULL;
6007 : : }
6008 : :
6009 : 1080247 : return copy;
6010 : 1080247 : }
6011 : :
6012 : :
6013 : : /* Allow someone to determine if SEARCH is a child of TOP from gdb. */
6014 : :
6015 : : static tree
6016 : 0 : debug_find_tree_1 (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED, void *data)
6017 : : {
6018 : 0 : if (*tp == data)
6019 : : return (tree) data;
6020 : : else
6021 : 0 : return NULL;
6022 : : }
6023 : :
6024 : : DEBUG_FUNCTION bool
6025 : 0 : debug_find_tree (tree top, tree search)
6026 : : {
6027 : 0 : return walk_tree_without_duplicates (&top, debug_find_tree_1, search) != 0;
6028 : : }
6029 : :
6030 : :
6031 : : /* Declare the variables created by the inliner. Add all the variables in
6032 : : VARS to BIND_EXPR. */
6033 : :
6034 : : static void
6035 : 6645027 : declare_inline_vars (tree block, tree vars)
6036 : : {
6037 : 6645027 : tree t;
6038 : 16297860 : for (t = vars; t; t = DECL_CHAIN (t))
6039 : : {
6040 : 9652833 : DECL_SEEN_IN_BIND_EXPR_P (t) = 1;
6041 : 9652833 : gcc_assert (!TREE_STATIC (t) && !TREE_ASM_WRITTEN (t));
6042 : 9652833 : add_local_decl (cfun, t);
6043 : : }
6044 : :
6045 : 6645027 : if (block)
6046 : 6566086 : BLOCK_VARS (block) = chainon (BLOCK_VARS (block), vars);
6047 : 6645027 : }
6048 : :
6049 : : /* Copy NODE (which must be a DECL). The DECL originally was in the FROM_FN,
6050 : : but now it will be in the TO_FN. PARM_TO_VAR means enable PARM_DECL to
6051 : : VAR_DECL translation. */
6052 : :
6053 : : tree
6054 : 85129581 : copy_decl_for_dup_finish (copy_body_data *id, tree decl, tree copy)
6055 : : {
6056 : : /* Don't generate debug information for the copy if we wouldn't have
6057 : : generated it for the copy either. */
6058 : 85129581 : DECL_ARTIFICIAL (copy) = DECL_ARTIFICIAL (decl);
6059 : 85129581 : DECL_IGNORED_P (copy) = DECL_IGNORED_P (decl);
6060 : :
6061 : : /* Set the DECL_ABSTRACT_ORIGIN so the debugging routines know what
6062 : : declaration inspired this copy. */
6063 : 113743025 : DECL_ABSTRACT_ORIGIN (copy) = DECL_ORIGIN (decl);
6064 : :
6065 : : /* The new variable/label has no RTL, yet. */
6066 : 85129581 : if (HAS_RTL_P (copy)
6067 : 85129581 : && !TREE_STATIC (copy) && !DECL_EXTERNAL (copy))
6068 : 85124961 : SET_DECL_RTL (copy, 0);
6069 : : /* For vector typed decls make sure to update DECL_MODE according
6070 : : to the new function context. */
6071 : 85129581 : if (VECTOR_TYPE_P (TREE_TYPE (copy)))
6072 : 163575 : SET_DECL_MODE (copy, TYPE_MODE (TREE_TYPE (copy)));
6073 : :
6074 : : /* These args would always appear unused, if not for this. */
6075 : 85129581 : TREE_USED (copy) = 1;
6076 : :
6077 : : /* Set the context for the new declaration. */
6078 : 85129581 : if (!DECL_CONTEXT (decl))
6079 : : /* Globals stay global. */
6080 : : ;
6081 : 85129431 : else if (DECL_CONTEXT (decl) != id->src_fn)
6082 : : /* Things that weren't in the scope of the function we're inlining
6083 : : from aren't in the scope we're inlining to, either. */
6084 : : ;
6085 : 85127346 : else if (TREE_STATIC (decl))
6086 : : /* Function-scoped static variables should stay in the original
6087 : : function. */
6088 : : ;
6089 : : else
6090 : : {
6091 : : /* Ordinary automatic local variables are now in the scope of the
6092 : : new function. */
6093 : 85124061 : DECL_CONTEXT (copy) = id->dst_fn;
6094 : 85124061 : if (VAR_P (copy) && id->dst_simt_vars && !is_gimple_reg (copy))
6095 : : {
6096 : 0 : if (!lookup_attribute ("omp simt private", DECL_ATTRIBUTES (copy)))
6097 : 0 : DECL_ATTRIBUTES (copy)
6098 : 0 : = tree_cons (get_identifier ("omp simt private"), NULL,
6099 : 0 : DECL_ATTRIBUTES (copy));
6100 : 0 : id->dst_simt_vars->safe_push (copy);
6101 : : }
6102 : : }
6103 : :
6104 : 85129581 : return copy;
6105 : : }
6106 : :
6107 : : /* Create a new VAR_DECL that is indentical in all respect to DECL except that
6108 : : DECL can be either a VAR_DECL, a PARM_DECL or RESULT_DECL. The original
6109 : : DECL must come from ID->src_fn and the copy will be part of ID->dst_fn. */
6110 : :
6111 : : tree
6112 : 7631889 : copy_decl_to_var (tree decl, copy_body_data *id)
6113 : : {
6114 : 7631889 : tree copy, type;
6115 : :
6116 : 7631889 : gcc_assert (TREE_CODE (decl) == PARM_DECL
6117 : : || TREE_CODE (decl) == RESULT_DECL);
6118 : :
6119 : 7631889 : type = TREE_TYPE (decl);
6120 : :
6121 : 7631889 : copy = build_decl (DECL_SOURCE_LOCATION (id->dst_fn),
6122 : 7631889 : VAR_DECL, DECL_NAME (decl), type);
6123 : 7631889 : if (DECL_PT_UID_SET_P (decl))
6124 : 289 : SET_DECL_PT_UID (copy, DECL_PT_UID (decl));
6125 : 7631889 : TREE_ADDRESSABLE (copy) = TREE_ADDRESSABLE (decl);
6126 : 7631889 : TREE_READONLY (copy) = TREE_READONLY (decl);
6127 : 7631889 : TREE_THIS_VOLATILE (copy) = TREE_THIS_VOLATILE (decl);
6128 : 7631889 : DECL_NOT_GIMPLE_REG_P (copy) = DECL_NOT_GIMPLE_REG_P (decl);
6129 : 7631889 : DECL_BY_REFERENCE (copy) = DECL_BY_REFERENCE (decl);
6130 : :
6131 : 7631889 : return copy_decl_for_dup_finish (id, decl, copy);
6132 : : }
6133 : :
6134 : : /* Like copy_decl_to_var, but create a return slot object instead of a
6135 : : pointer variable for return by invisible reference. */
6136 : :
6137 : : static tree
6138 : 2033118 : copy_result_decl_to_var (tree decl, copy_body_data *id)
6139 : : {
6140 : 2033118 : tree copy, type;
6141 : :
6142 : 2033118 : gcc_assert (TREE_CODE (decl) == PARM_DECL
6143 : : || TREE_CODE (decl) == RESULT_DECL);
6144 : :
6145 : 2033118 : type = TREE_TYPE (decl);
6146 : 2033118 : if (DECL_BY_REFERENCE (decl))
6147 : 73 : type = TREE_TYPE (type);
6148 : :
6149 : 2033118 : copy = build_decl (DECL_SOURCE_LOCATION (id->dst_fn),
6150 : 2033118 : VAR_DECL, DECL_NAME (decl), type);
6151 : 2033118 : if (DECL_PT_UID_SET_P (decl))
6152 : 0 : SET_DECL_PT_UID (copy, DECL_PT_UID (decl));
6153 : 2033118 : TREE_READONLY (copy) = TREE_READONLY (decl);
6154 : 2033118 : TREE_THIS_VOLATILE (copy) = TREE_THIS_VOLATILE (decl);
6155 : 2033118 : if (!DECL_BY_REFERENCE (decl))
6156 : : {
6157 : 2033045 : TREE_ADDRESSABLE (copy) = TREE_ADDRESSABLE (decl);
6158 : 2033045 : DECL_NOT_GIMPLE_REG_P (copy)
6159 : 4066090 : = (DECL_NOT_GIMPLE_REG_P (decl)
6160 : : /* RESULT_DECLs are treated special by needs_to_live_in_memory,
6161 : : mirror that to the created VAR_DECL. */
6162 : 2033045 : || (TREE_CODE (decl) == RESULT_DECL
6163 : 2032890 : && aggregate_value_p (decl, id->src_fn)));
6164 : : }
6165 : :
6166 : 2033118 : return copy_decl_for_dup_finish (id, decl, copy);
6167 : : }
6168 : :
6169 : : tree
6170 : 75464404 : copy_decl_no_change (tree decl, copy_body_data *id)
6171 : : {
6172 : 75464404 : tree copy;
6173 : :
6174 : 75464404 : copy = copy_node (decl);
6175 : :
6176 : : /* The COPY is not abstract; it will be generated in DST_FN. */
6177 : 75464404 : DECL_ABSTRACT_P (copy) = false;
6178 : 75464404 : lang_hooks.dup_lang_specific_decl (copy);
6179 : :
6180 : : /* TREE_ADDRESSABLE isn't used to indicate that a label's address has
6181 : : been taken; it's for internal bookkeeping in expand_goto_internal. */
6182 : 75464404 : if (TREE_CODE (copy) == LABEL_DECL)
6183 : : {
6184 : 1247948 : TREE_ADDRESSABLE (copy) = 0;
6185 : 1247948 : LABEL_DECL_UID (copy) = -1;
6186 : : }
6187 : :
6188 : 75464404 : return copy_decl_for_dup_finish (id, decl, copy);
6189 : : }
6190 : :
6191 : : static tree
6192 : 21274485 : copy_decl_maybe_to_var (tree decl, copy_body_data *id)
6193 : : {
6194 : 21274485 : if (TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL)
6195 : 12174 : return copy_decl_to_var (decl, id);
6196 : : else
6197 : 21262311 : return copy_decl_no_change (decl, id);
6198 : : }
6199 : :
6200 : : /* Return a copy of the function's argument tree without any modifications. */
6201 : :
6202 : : static tree
6203 : 71813 : copy_arguments_nochange (tree orig_parm, copy_body_data * id)
6204 : : {
6205 : 71813 : tree arg, *parg;
6206 : 71813 : tree new_parm = NULL;
6207 : :
6208 : 71813 : parg = &new_parm;
6209 : 216794 : for (arg = orig_parm; arg; arg = DECL_CHAIN (arg))
6210 : : {
6211 : 144981 : tree new_tree = remap_decl (arg, id);
6212 : 144981 : if (TREE_CODE (new_tree) != PARM_DECL)
6213 : 3986 : new_tree = id->copy_decl (arg, id);
6214 : 144981 : lang_hooks.dup_lang_specific_decl (new_tree);
6215 : 144981 : *parg = new_tree;
6216 : 144981 : parg = &DECL_CHAIN (new_tree);
6217 : : }
6218 : 71813 : return new_parm;
6219 : : }
6220 : :
6221 : : /* Return a copy of the function's static chain. */
6222 : : static tree
6223 : 944 : copy_static_chain (tree static_chain, copy_body_data * id)
6224 : : {
6225 : 944 : tree *chain_copy, *pvar;
6226 : :
6227 : 944 : chain_copy = &static_chain;
6228 : 1888 : for (pvar = chain_copy; *pvar; pvar = &DECL_CHAIN (*pvar))
6229 : : {
6230 : 944 : tree new_tree = remap_decl (*pvar, id);
6231 : 944 : lang_hooks.dup_lang_specific_decl (new_tree);
6232 : 944 : DECL_CHAIN (new_tree) = DECL_CHAIN (*pvar);
6233 : 944 : *pvar = new_tree;
6234 : : }
6235 : 944 : return static_chain;
6236 : : }
6237 : :
6238 : : /* Return true if the function is allowed to be versioned.
6239 : : This is a guard for the versioning functionality. */
6240 : :
6241 : : bool
6242 : 11296729 : tree_versionable_function_p (tree fndecl)
6243 : : {
6244 : 11296729 : return (!lookup_attribute ("noclone", DECL_ATTRIBUTES (fndecl))
6245 : 22327292 : && copy_forbidden (DECL_STRUCT_FUNCTION (fndecl)) == NULL);
6246 : : }
6247 : :
6248 : : /* Update clone info after duplication. */
6249 : :
6250 : : static void
6251 : 225405 : update_clone_info (copy_body_data * id)
6252 : : {
6253 : 225405 : struct cgraph_node *this_node = id->dst_node;
6254 : 225405 : if (!this_node->clones)
6255 : : return;
6256 : 551619 : for (cgraph_node *node = this_node->clones; node != this_node;)
6257 : : {
6258 : : /* First update replace maps to match the new body. */
6259 : 481727 : clone_info *info = clone_info::get (node);
6260 : 481727 : if (info && info->tree_map)
6261 : : {
6262 : : unsigned int i;
6263 : 0 : for (i = 0; i < vec_safe_length (info->tree_map); i++)
6264 : : {
6265 : 0 : struct ipa_replace_map *replace_info;
6266 : 0 : replace_info = (*info->tree_map)[i];
6267 : 0 : walk_tree (&replace_info->new_tree, copy_tree_body_r, id, NULL);
6268 : : }
6269 : : }
6270 : :
6271 : 481727 : if (node->clones)
6272 : : node = node->clones;
6273 : 462695 : else if (node->next_sibling_clone)
6274 : : node = node->next_sibling_clone;
6275 : : else
6276 : : {
6277 : 169382 : while (node != id->dst_node && !node->next_sibling_clone)
6278 : 88924 : node = node->clone_of;
6279 : 80458 : if (node != id->dst_node)
6280 : 10566 : node = node->next_sibling_clone;
6281 : : }
6282 : : }
6283 : : }
6284 : :
6285 : : /* Create a copy of a function's tree.
6286 : : OLD_DECL and NEW_DECL are FUNCTION_DECL tree nodes
6287 : : of the original function and the new copied function
6288 : : respectively. In case we want to replace a DECL
6289 : : tree with another tree while duplicating the function's
6290 : : body, TREE_MAP represents the mapping between these
6291 : : trees. If UPDATE_CLONES is set, the call_stmt fields
6292 : : of edges of clones of the function will be updated.
6293 : :
6294 : : If non-NULL PARAM_ADJUSTMENTS determines how function prototype (i.e. the
6295 : : function parameters and return value) should be modified).
6296 : : If non-NULL BLOCKS_TO_COPY determine what basic blocks to copy.
6297 : : If non_NULL NEW_ENTRY determine new entry BB of the clone.
6298 : : */
6299 : : void
6300 : 225405 : tree_function_versioning (tree old_decl, tree new_decl,
6301 : : vec<ipa_replace_map *, va_gc> *tree_map,
6302 : : ipa_param_adjustments *param_adjustments,
6303 : : bool update_clones, bitmap blocks_to_copy,
6304 : : basic_block new_entry)
6305 : : {
6306 : 225405 : struct cgraph_node *old_version_node;
6307 : 225405 : struct cgraph_node *new_version_node;
6308 : 225405 : copy_body_data id;
6309 : 225405 : tree p;
6310 : 225405 : unsigned i;
6311 : 225405 : struct ipa_replace_map *replace_info;
6312 : 225405 : basic_block old_entry_block, bb;
6313 : 225405 : auto_vec<gimple *, 10> init_stmts;
6314 : 225405 : tree vars = NULL_TREE;
6315 : :
6316 : : /* We can get called recursively from expand_call_inline via clone
6317 : : materialization. While expand_call_inline maintains input_location
6318 : : we cannot tolerate it to leak into the materialized clone. */
6319 : 225405 : location_t saved_location = input_location;
6320 : 225405 : input_location = UNKNOWN_LOCATION;
6321 : :
6322 : 225405 : gcc_assert (TREE_CODE (old_decl) == FUNCTION_DECL
6323 : : && TREE_CODE (new_decl) == FUNCTION_DECL);
6324 : 225405 : DECL_POSSIBLY_INLINED (old_decl) = 1;
6325 : :
6326 : 225405 : old_version_node = cgraph_node::get (old_decl);
6327 : 225405 : gcc_checking_assert (old_version_node);
6328 : 225405 : new_version_node = cgraph_node::get (new_decl);
6329 : 225405 : gcc_checking_assert (new_version_node);
6330 : :
6331 : : /* Copy over debug args. */
6332 : 225405 : if (DECL_HAS_DEBUG_ARGS_P (old_decl))
6333 : : {
6334 : 3297 : vec<tree, va_gc> **new_debug_args, **old_debug_args;
6335 : 3297 : gcc_checking_assert (decl_debug_args_lookup (new_decl) == NULL);
6336 : 3297 : DECL_HAS_DEBUG_ARGS_P (new_decl) = 0;
6337 : 3297 : old_debug_args = decl_debug_args_lookup (old_decl);
6338 : 3297 : if (old_debug_args)
6339 : : {
6340 : 3297 : new_debug_args = decl_debug_args_insert (new_decl);
6341 : 6594 : *new_debug_args = vec_safe_copy (*old_debug_args);
6342 : : }
6343 : : }
6344 : :
6345 : : /* Output the inlining info for this abstract function, since it has been
6346 : : inlined. If we don't do this now, we can lose the information about the
6347 : : variables in the function when the blocks get blown away as soon as we
6348 : : remove the cgraph node. */
6349 : 225405 : (*debug_hooks->outlining_inline_function) (old_decl);
6350 : :
6351 : 225405 : DECL_ARTIFICIAL (new_decl) = 1;
6352 : 407516 : DECL_ABSTRACT_ORIGIN (new_decl) = DECL_ORIGIN (old_decl);
6353 : 407516 : if (DECL_ORIGIN (old_decl) == old_decl)
6354 : 199159 : old_version_node->used_as_abstract_origin = true;
6355 : 225405 : DECL_FUNCTION_PERSONALITY (new_decl) = DECL_FUNCTION_PERSONALITY (old_decl);
6356 : :
6357 : : /* Prepare the data structures for the tree copy. */
6358 : 225405 : memset (&id, 0, sizeof (id));
6359 : :
6360 : : /* Generate a new name for the new version. */
6361 : 225405 : id.statements_to_fold = new hash_set<gimple *>;
6362 : :
6363 : 225405 : id.decl_map = new hash_map<tree, tree>;
6364 : 225405 : id.debug_map = NULL;
6365 : 225405 : id.src_fn = old_decl;
6366 : 225405 : id.dst_fn = new_decl;
6367 : 225405 : id.src_node = old_version_node;
6368 : 225405 : id.dst_node = new_version_node;
6369 : 225405 : id.src_cfun = DECL_STRUCT_FUNCTION (old_decl);
6370 : 225405 : id.blocks_to_copy = blocks_to_copy;
6371 : :
6372 : 225405 : id.copy_decl = copy_decl_no_change;
6373 : 225405 : id.transform_call_graph_edges
6374 : 225405 : = update_clones ? CB_CGE_MOVE_CLONES : CB_CGE_MOVE;
6375 : 225405 : id.transform_new_cfg = true;
6376 : 225405 : id.transform_return_to_modify = false;
6377 : 225405 : id.transform_parameter = false;
6378 : :
6379 : 225405 : old_entry_block = ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (old_decl));
6380 : 225405 : DECL_RESULT (new_decl) = DECL_RESULT (old_decl);
6381 : 225405 : DECL_ARGUMENTS (new_decl) = DECL_ARGUMENTS (old_decl);
6382 : 225405 : initialize_cfun (new_decl, old_decl,
6383 : 225405 : new_entry ? new_entry->count : old_entry_block->count);
6384 : 225405 : new_version_node->has_omp_variant_constructs
6385 : 225405 : = old_version_node->has_omp_variant_constructs;
6386 : 225405 : if (DECL_STRUCT_FUNCTION (new_decl)->gimple_df)
6387 : 225405 : DECL_STRUCT_FUNCTION (new_decl)->gimple_df->ipa_pta
6388 : 225405 : = id.src_cfun->gimple_df->ipa_pta;
6389 : :
6390 : : /* Copy the function's static chain. */
6391 : 225405 : p = DECL_STRUCT_FUNCTION (old_decl)->static_chain_decl;
6392 : 225405 : if (p)
6393 : 1888 : DECL_STRUCT_FUNCTION (new_decl)->static_chain_decl
6394 : 944 : = copy_static_chain (p, &id);
6395 : :
6396 : 225405 : auto_vec<int, 16> new_param_indices;
6397 : 225405 : clone_info *info = clone_info::get (old_version_node);
6398 : 230826 : ipa_param_adjustments *old_param_adjustments
6399 : 225405 : = info ? info->param_adjustments : NULL;
6400 : 5421 : if (old_param_adjustments)
6401 : 5342 : old_param_adjustments->get_updated_indices (&new_param_indices);
6402 : :
6403 : : /* If there's a tree_map, prepare for substitution. */
6404 : 225405 : if (tree_map)
6405 : 32773 : for (i = 0; i < tree_map->length (); i++)
6406 : : {
6407 : 20605 : gimple *init;
6408 : 20605 : replace_info = (*tree_map)[i];
6409 : :
6410 : 20605 : int p = replace_info->parm_num;
6411 : 20605 : if (old_param_adjustments)
6412 : 0 : p = new_param_indices[p];
6413 : :
6414 : 20605 : tree parm;
6415 : 62636 : for (parm = DECL_ARGUMENTS (old_decl); p;
6416 : 42031 : parm = DECL_CHAIN (parm))
6417 : 42031 : p--;
6418 : 20605 : gcc_assert (parm);
6419 : 20605 : init = setup_one_parameter (&id, parm, replace_info->new_tree,
6420 : : id.src_fn, NULL, &vars);
6421 : 20605 : if (init)
6422 : 5882 : init_stmts.safe_push (init);
6423 : : }
6424 : :
6425 : 225405 : ipa_param_body_adjustments *param_body_adjs = NULL;
6426 : 225405 : if (param_adjustments)
6427 : : {
6428 : 296136 : param_body_adjs = new ipa_param_body_adjustments (param_adjustments,
6429 : : new_decl, old_decl,
6430 : 148068 : &id, &vars, tree_map);
6431 : 148068 : id.param_body_adjs = param_body_adjs;
6432 : 148068 : DECL_ARGUMENTS (new_decl) = param_body_adjs->get_new_param_chain ();
6433 : : }
6434 : 77337 : else if (DECL_ARGUMENTS (old_decl) != NULL_TREE)
6435 : 143626 : DECL_ARGUMENTS (new_decl)
6436 : 71813 : = copy_arguments_nochange (DECL_ARGUMENTS (old_decl), &id);
6437 : :
6438 : 225405 : DECL_INITIAL (new_decl) = remap_blocks (DECL_INITIAL (id.src_fn), &id);
6439 : 225405 : BLOCK_SUPERCONTEXT (DECL_INITIAL (new_decl)) = new_decl;
6440 : :
6441 : 225405 : declare_inline_vars (DECL_INITIAL (new_decl), vars);
6442 : :
6443 : 225405 : if (!vec_safe_is_empty (DECL_STRUCT_FUNCTION (old_decl)->local_decls))
6444 : : /* Add local vars. */
6445 : 132570 : add_local_variables (DECL_STRUCT_FUNCTION (old_decl), cfun, &id);
6446 : :
6447 : 225405 : if (DECL_RESULT (old_decl) == NULL_TREE)
6448 : : ;
6449 : 148068 : else if (param_adjustments && param_adjustments->m_skip_return
6450 : 270024 : && !VOID_TYPE_P (TREE_TYPE (DECL_RESULT (old_decl))))
6451 : : {
6452 : 37751 : tree resdecl_repl = copy_result_decl_to_var (DECL_RESULT (old_decl),
6453 : : &id);
6454 : 37751 : declare_inline_vars (NULL, resdecl_repl);
6455 : 37751 : if (DECL_BY_REFERENCE (DECL_RESULT (old_decl)))
6456 : 73 : resdecl_repl = build_fold_addr_expr (resdecl_repl);
6457 : 37751 : insert_decl_map (&id, DECL_RESULT (old_decl), resdecl_repl);
6458 : :
6459 : 75502 : DECL_RESULT (new_decl)
6460 : 37751 : = build_decl (DECL_SOURCE_LOCATION (DECL_RESULT (old_decl)),
6461 : : RESULT_DECL, NULL_TREE, void_type_node);
6462 : 37751 : DECL_CONTEXT (DECL_RESULT (new_decl)) = new_decl;
6463 : 37751 : DECL_IS_MALLOC (new_decl) = false;
6464 : 37751 : cfun->returns_struct = 0;
6465 : 37751 : cfun->returns_pcc_struct = 0;
6466 : : }
6467 : : else
6468 : : {
6469 : 187654 : tree old_name;
6470 : 187654 : DECL_RESULT (new_decl) = remap_decl (DECL_RESULT (old_decl), &id);
6471 : 187654 : lang_hooks.dup_lang_specific_decl (DECL_RESULT (new_decl));
6472 : 375308 : if (gimple_in_ssa_p (id.src_cfun)
6473 : 187654 : && DECL_BY_REFERENCE (DECL_RESULT (old_decl))
6474 : 4827 : && (old_name = ssa_default_def (id.src_cfun, DECL_RESULT (old_decl))))
6475 : : {
6476 : 4808 : tree new_name = make_ssa_name (DECL_RESULT (new_decl));
6477 : 4808 : insert_decl_map (&id, old_name, new_name);
6478 : 4808 : SSA_NAME_DEF_STMT (new_name) = gimple_build_nop ();
6479 : 4808 : set_ssa_default_def (cfun, DECL_RESULT (new_decl), new_name);
6480 : : }
6481 : : }
6482 : :
6483 : : /* Set up the destination functions loop tree. */
6484 : 225405 : if (loops_for_fn (DECL_STRUCT_FUNCTION (old_decl)) != NULL)
6485 : : {
6486 : 225405 : cfun->curr_properties &= ~PROP_loops;
6487 : 225405 : loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
6488 : 225405 : cfun->curr_properties |= PROP_loops;
6489 : : }
6490 : :
6491 : : /* Copy the Function's body. */
6492 : 225405 : copy_body (&id, ENTRY_BLOCK_PTR_FOR_FN (cfun), EXIT_BLOCK_PTR_FOR_FN (cfun),
6493 : : new_entry);
6494 : :
6495 : : /* Renumber the lexical scoping (non-code) blocks consecutively. */
6496 : 225405 : number_blocks (new_decl);
6497 : :
6498 : : /* We want to create the BB unconditionally, so that the addition of
6499 : : debug stmts doesn't affect BB count, which may in the end cause
6500 : : codegen differences. */
6501 : 225405 : bb = split_edge (single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
6502 : 456692 : while (init_stmts.length ())
6503 : 5882 : insert_init_stmt (&id, bb, init_stmts.pop ());
6504 : 225405 : if (param_body_adjs)
6505 : 148068 : param_body_adjs->append_init_stmts (bb);
6506 : 225405 : update_clone_info (&id);
6507 : :
6508 : : /* Remap the nonlocal_goto_save_area, if any. */
6509 : 225405 : if (cfun->nonlocal_goto_save_area)
6510 : : {
6511 : 0 : struct walk_stmt_info wi;
6512 : :
6513 : 0 : memset (&wi, 0, sizeof (wi));
6514 : 0 : wi.info = &id;
6515 : 0 : walk_tree (&cfun->nonlocal_goto_save_area, remap_gimple_op_r, &wi, NULL);
6516 : : }
6517 : :
6518 : : /* Clean up. */
6519 : 450810 : delete id.decl_map;
6520 : 225405 : if (id.debug_map)
6521 : 1109 : delete id.debug_map;
6522 : 225405 : free_dominance_info (CDI_DOMINATORS);
6523 : 225405 : free_dominance_info (CDI_POST_DOMINATORS);
6524 : :
6525 : 225405 : update_max_bb_count ();
6526 : 225405 : fold_marked_statements (0, id.statements_to_fold);
6527 : 450810 : delete id.statements_to_fold;
6528 : 225405 : delete_unreachable_blocks_update_callgraph (id.dst_node, update_clones);
6529 : 225405 : if (id.dst_node->definition)
6530 : 221365 : cgraph_edge::rebuild_references ();
6531 : 225405 : if (loops_state_satisfies_p (LOOPS_NEED_FIXUP))
6532 : : {
6533 : 225405 : calculate_dominance_info (CDI_DOMINATORS);
6534 : 225405 : fix_loop_structure (NULL);
6535 : : }
6536 : 225405 : update_ssa (TODO_update_ssa);
6537 : :
6538 : : /* After partial cloning we need to rescale frequencies, so they are
6539 : : within proper range in the cloned function. */
6540 : 225405 : if (new_entry)
6541 : : {
6542 : 48272 : struct cgraph_edge *e;
6543 : 48272 : rebuild_frequencies ();
6544 : :
6545 : 48272 : new_version_node->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
6546 : 224372 : for (e = new_version_node->callees; e; e = e->next_callee)
6547 : : {
6548 : 176100 : basic_block bb = gimple_bb (e->call_stmt);
6549 : 176100 : e->count = bb->count;
6550 : : }
6551 : 53224 : for (e = new_version_node->indirect_calls; e; e = e->next_callee)
6552 : : {
6553 : 4952 : basic_block bb = gimple_bb (e->call_stmt);
6554 : 4952 : e->count = bb->count;
6555 : : }
6556 : : }
6557 : :
6558 : 225405 : if (param_body_adjs && MAY_HAVE_DEBUG_BIND_STMTS)
6559 : : {
6560 : 125940 : vec<tree, va_gc> **debug_args = NULL;
6561 : 125940 : unsigned int len = 0;
6562 : 125940 : unsigned reset_len = param_body_adjs->m_reset_debug_decls.length ();
6563 : :
6564 : 231772 : for (i = 0; i < reset_len; i++)
6565 : : {
6566 : 105832 : tree parm = param_body_adjs->m_reset_debug_decls[i];
6567 : 105832 : gcc_assert (is_gimple_reg (parm));
6568 : 105832 : tree ddecl;
6569 : :
6570 : 105832 : if (debug_args == NULL)
6571 : : {
6572 : 77504 : debug_args = decl_debug_args_insert (new_decl);
6573 : 77504 : len = vec_safe_length (*debug_args);
6574 : : }
6575 : 105832 : ddecl = build_debug_expr_decl (TREE_TYPE (parm));
6576 : : /* FIXME: Is setting the mode really necessary? */
6577 : 105832 : SET_DECL_MODE (ddecl, DECL_MODE (parm));
6578 : 105832 : vec_safe_push (*debug_args, DECL_ORIGIN (parm));
6579 : 105832 : vec_safe_push (*debug_args, ddecl);
6580 : : }
6581 : 125940 : if (debug_args != NULL)
6582 : : {
6583 : : /* On the callee side, add
6584 : : DEBUG D#Y s=> parm
6585 : : DEBUG var => D#Y
6586 : : stmts to the first bb where var is a VAR_DECL created for the
6587 : : optimized away parameter in DECL_INITIAL block. This hints
6588 : : in the debug info that var (whole DECL_ORIGIN is the parm
6589 : : PARM_DECL) is optimized away, but could be looked up at the
6590 : : call site as value of D#X there. */
6591 : 77504 : gimple_stmt_iterator cgsi
6592 : 77504 : = gsi_after_labels (single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
6593 : 77504 : gimple *def_temp;
6594 : 77504 : tree var = vars;
6595 : 77504 : i = vec_safe_length (*debug_args);
6596 : 105832 : do
6597 : : {
6598 : 105832 : tree vexpr = NULL_TREE;
6599 : 105832 : i -= 2;
6600 : 105832 : while (var != NULL_TREE
6601 : 141829 : && DECL_ABSTRACT_ORIGIN (var) != (**debug_args)[i])
6602 : 35997 : var = TREE_CHAIN (var);
6603 : 105832 : if (var == NULL_TREE)
6604 : : break;
6605 : 105832 : tree parm = (**debug_args)[i];
6606 : 105832 : if (tree parm_ddef = ssa_default_def (id.src_cfun, parm))
6607 : 145752 : if (tree *d
6608 : 72876 : = param_body_adjs->m_dead_ssa_debug_equiv.get (parm_ddef))
6609 : 23930 : vexpr = *d;
6610 : 105832 : if (!vexpr)
6611 : : {
6612 : 81902 : vexpr = build_debug_expr_decl (TREE_TYPE (parm));
6613 : : /* FIXME: Is setting the mode really necessary? */
6614 : 81902 : SET_DECL_MODE (vexpr, DECL_MODE (parm));
6615 : : }
6616 : 105832 : def_temp = gimple_build_debug_bind (var, vexpr, NULL);
6617 : 105832 : gsi_insert_before (&cgsi, def_temp, GSI_NEW_STMT);
6618 : 105832 : def_temp = gimple_build_debug_source_bind (vexpr, parm, NULL);
6619 : 105832 : gsi_insert_before (&cgsi, def_temp, GSI_NEW_STMT);
6620 : : }
6621 : 105832 : while (i > len);
6622 : : }
6623 : : }
6624 : 148068 : delete param_body_adjs;
6625 : 225405 : free_dominance_info (CDI_DOMINATORS);
6626 : 225405 : free_dominance_info (CDI_POST_DOMINATORS);
6627 : :
6628 : 225405 : gcc_assert (!id.debug_stmts.exists ());
6629 : 225405 : pop_cfun ();
6630 : 225405 : input_location = saved_location;
6631 : 225405 : return;
6632 : 225405 : }
6633 : :
6634 : : /* EXP is CALL_EXPR present in a GENERIC expression tree. Try to integrate
6635 : : the callee and return the inlined body on success. */
6636 : :
6637 : : tree
6638 : 0 : maybe_inline_call_in_expr (tree exp)
6639 : : {
6640 : 0 : tree fn = get_callee_fndecl (exp);
6641 : :
6642 : : /* We can only try to inline "const" functions. */
6643 : 0 : if (fn && TREE_READONLY (fn) && DECL_SAVED_TREE (fn))
6644 : : {
6645 : 0 : call_expr_arg_iterator iter;
6646 : 0 : copy_body_data id;
6647 : 0 : tree param, arg, t;
6648 : 0 : hash_map<tree, tree> decl_map;
6649 : :
6650 : : /* Remap the parameters. */
6651 : 0 : for (param = DECL_ARGUMENTS (fn), arg = first_call_expr_arg (exp, &iter);
6652 : 0 : param;
6653 : 0 : param = DECL_CHAIN (param), arg = next_call_expr_arg (&iter))
6654 : 0 : decl_map.put (param, arg);
6655 : :
6656 : 0 : memset (&id, 0, sizeof (id));
6657 : 0 : id.src_fn = fn;
6658 : 0 : id.dst_fn = current_function_decl;
6659 : 0 : id.src_cfun = DECL_STRUCT_FUNCTION (fn);
6660 : 0 : id.decl_map = &decl_map;
6661 : :
6662 : 0 : id.copy_decl = copy_decl_no_change;
6663 : 0 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
6664 : 0 : id.transform_new_cfg = false;
6665 : 0 : id.transform_return_to_modify = true;
6666 : 0 : id.transform_parameter = true;
6667 : :
6668 : : /* Make sure not to unshare trees behind the front-end's back
6669 : : since front-end specific mechanisms may rely on sharing. */
6670 : 0 : id.regimplify = false;
6671 : 0 : id.do_not_unshare = true;
6672 : :
6673 : : /* We're not inside any EH region. */
6674 : 0 : id.eh_lp_nr = 0;
6675 : :
6676 : 0 : t = copy_tree_body (&id);
6677 : :
6678 : : /* We can only return something suitable for use in a GENERIC
6679 : : expression tree. */
6680 : 0 : if (TREE_CODE (t) == MODIFY_EXPR)
6681 : 0 : return TREE_OPERAND (t, 1);
6682 : 0 : }
6683 : :
6684 : : return NULL_TREE;
6685 : : }
6686 : :
6687 : : /* Duplicate a type, fields and all. */
6688 : :
6689 : : tree
6690 : 488 : build_duplicate_type (tree type)
6691 : : {
6692 : 488 : struct copy_body_data id;
6693 : :
6694 : 488 : memset (&id, 0, sizeof (id));
6695 : 488 : id.src_fn = current_function_decl;
6696 : 488 : id.dst_fn = current_function_decl;
6697 : 488 : id.src_cfun = cfun;
6698 : 488 : id.decl_map = new hash_map<tree, tree>;
6699 : 488 : id.debug_map = NULL;
6700 : 488 : id.copy_decl = copy_decl_no_change;
6701 : :
6702 : 488 : type = remap_type_1 (type, &id);
6703 : :
6704 : 976 : delete id.decl_map;
6705 : 488 : if (id.debug_map)
6706 : 0 : delete id.debug_map;
6707 : :
6708 : 488 : TYPE_CANONICAL (type) = type;
6709 : :
6710 : 488 : return type;
6711 : : }
6712 : :
6713 : : /* Unshare the entire DECL_SAVED_TREE of FN and return the remapped
6714 : : parameters and RESULT_DECL in PARMS and RESULT. Used by C++ constexpr
6715 : : evaluation. */
6716 : :
6717 : : tree
6718 : 17470458 : copy_fn (tree fn, tree& parms, tree& result)
6719 : : {
6720 : 17470458 : copy_body_data id;
6721 : 17470458 : tree param;
6722 : 17470458 : hash_map<tree, tree> decl_map;
6723 : :
6724 : 17470458 : tree *p = &parms;
6725 : 17470458 : *p = NULL_TREE;
6726 : :
6727 : 17470458 : memset (&id, 0, sizeof (id));
6728 : 17470458 : id.src_fn = fn;
6729 : 17470458 : id.dst_fn = current_function_decl;
6730 : 17470458 : id.src_cfun = DECL_STRUCT_FUNCTION (fn);
6731 : 17470458 : id.decl_map = &decl_map;
6732 : :
6733 : 67574335 : id.copy_decl = [] (tree decl, copy_body_data *id)
6734 : : {
6735 : 50103877 : if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
6736 : : /* Don't make copies of local types or injected enumerators,
6737 : : the C++ constexpr evaluator doesn't need them and they
6738 : : confuse modules streaming. */
6739 : : return decl;
6740 : 48958633 : return copy_decl_no_change (decl, id);
6741 : : };
6742 : 17470458 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
6743 : 17470458 : id.transform_new_cfg = false;
6744 : 17470458 : id.transform_return_to_modify = false;
6745 : 17470458 : id.transform_parameter = true;
6746 : :
6747 : : /* Make sure not to unshare trees behind the front-end's back
6748 : : since front-end specific mechanisms may rely on sharing. */
6749 : 17470458 : id.regimplify = false;
6750 : 17470458 : id.do_not_unshare = true;
6751 : 17470458 : id.do_not_fold = true;
6752 : :
6753 : : /* We're not inside any EH region. */
6754 : 17470458 : id.eh_lp_nr = 0;
6755 : :
6756 : : /* Remap the parameters and result and return them to the caller. */
6757 : 17470458 : for (param = DECL_ARGUMENTS (fn);
6758 : 39699025 : param;
6759 : 22228567 : param = DECL_CHAIN (param))
6760 : : {
6761 : 22228567 : *p = remap_decl (param, &id);
6762 : 22228567 : p = &DECL_CHAIN (*p);
6763 : : }
6764 : :
6765 : 17470458 : if (DECL_RESULT (fn))
6766 : 17470458 : result = remap_decl (DECL_RESULT (fn), &id);
6767 : : else
6768 : 0 : result = NULL_TREE;
6769 : :
6770 : 17470458 : return copy_tree_body (&id);
6771 : 17470458 : }
|