Branch data Line data Source code
1 : : /* A pass for lowering trees to RTL.
2 : : Copyright (C) 2004-2025 Free Software Foundation, Inc.
3 : :
4 : : This file is part of GCC.
5 : :
6 : : GCC is free software; you can redistribute it and/or modify
7 : : it under the terms of the GNU General Public License as published by
8 : : the Free Software Foundation; either version 3, or (at your option)
9 : : any later version.
10 : :
11 : : GCC is distributed in the hope that it will be useful,
12 : : but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : : GNU General Public License for more details.
15 : :
16 : : You should have received a copy of the GNU General Public License
17 : : along with GCC; see the file COPYING3. If not see
18 : : <http://www.gnu.org/licenses/>. */
19 : :
20 : : #include "config.h"
21 : : #include "system.h"
22 : : #include "coretypes.h"
23 : : #include "backend.h"
24 : : #include "target.h"
25 : : #include "rtl.h"
26 : : #include "tree.h"
27 : : #include "gimple.h"
28 : : #include "cfghooks.h"
29 : : #include "tree-pass.h"
30 : : #include "memmodel.h"
31 : : #include "tm_p.h"
32 : : #include "ssa.h"
33 : : #include "optabs.h"
34 : : #include "regs.h" /* For reg_renumber. */
35 : : #include "emit-rtl.h"
36 : : #include "recog.h"
37 : : #include "cgraph.h"
38 : : #include "diagnostic.h"
39 : : #include "fold-const.h"
40 : : #include "varasm.h"
41 : : #include "stor-layout.h"
42 : : #include "stmt.h"
43 : : #include "print-tree.h"
44 : : #include "cfgrtl.h"
45 : : #include "cfganal.h"
46 : : #include "cfgbuild.h"
47 : : #include "cfgcleanup.h"
48 : : #include "dojump.h"
49 : : #include "explow.h"
50 : : #include "calls.h"
51 : : #include "expr.h"
52 : : #include "internal-fn.h"
53 : : #include "tree-eh.h"
54 : : #include "gimple-iterator.h"
55 : : #include "gimple-expr.h"
56 : : #include "gimple-walk.h"
57 : : #include "tree-cfg.h"
58 : : #include "tree-dfa.h"
59 : : #include "tree-ssa.h"
60 : : #include "except.h"
61 : : #include "gimple-pretty-print.h"
62 : : #include "toplev.h"
63 : : #include "debug.h"
64 : : #include "tree-inline.h"
65 : : #include "value-prof.h"
66 : : #include "tree-ssa-live.h"
67 : : #include "tree-outof-ssa.h"
68 : : #include "cfgloop.h"
69 : : #include "insn-attr.h" /* For INSN_SCHEDULING. */
70 : : #include "stringpool.h"
71 : : #include "attribs.h"
72 : : #include "asan.h"
73 : : #include "tree-ssa-address.h"
74 : : #include "output.h"
75 : : #include "builtins.h"
76 : : #include "opts.h"
77 : : #include "gimple-range.h"
78 : :
79 : : /* Some systems use __main in a way incompatible with its use in gcc, in these
80 : : cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
81 : : give the same symbol without quotes for an alternative entry point. You
82 : : must define both, or neither. */
83 : : #ifndef NAME__MAIN
84 : : #define NAME__MAIN "__main"
85 : : #endif
86 : :
87 : : /* This variable holds information helping the rewriting of SSA trees
88 : : into RTL. */
89 : : struct ssaexpand SA;
90 : :
91 : : /* This variable holds the currently expanded gimple statement for purposes
92 : : of comminucating the profile info to the builtin expanders. */
93 : : gimple *currently_expanding_gimple_stmt;
94 : :
95 : : static rtx expand_debug_expr (tree);
96 : :
97 : : static bool defer_stack_allocation (tree, bool);
98 : :
99 : : static void record_alignment_for_reg_var (unsigned int);
100 : :
101 : : /* Return an expression tree corresponding to the RHS of GIMPLE
102 : : statement STMT. */
103 : :
104 : : tree
105 : 3285833 : gimple_assign_rhs_to_tree (gimple *stmt)
106 : : {
107 : 3285833 : tree t;
108 : 3285833 : switch (gimple_assign_rhs_class (stmt))
109 : : {
110 : 855 : case GIMPLE_TERNARY_RHS:
111 : 855 : t = build3 (gimple_assign_rhs_code (stmt),
112 : 855 : TREE_TYPE (gimple_assign_lhs (stmt)),
113 : : gimple_assign_rhs1 (stmt), gimple_assign_rhs2 (stmt),
114 : : gimple_assign_rhs3 (stmt));
115 : 855 : break;
116 : 1183722 : case GIMPLE_BINARY_RHS:
117 : 1183722 : t = build2 (gimple_assign_rhs_code (stmt),
118 : 1183722 : TREE_TYPE (gimple_assign_lhs (stmt)),
119 : : gimple_assign_rhs1 (stmt), gimple_assign_rhs2 (stmt));
120 : 1183722 : break;
121 : 392216 : case GIMPLE_UNARY_RHS:
122 : 392216 : t = build1 (gimple_assign_rhs_code (stmt),
123 : 392216 : TREE_TYPE (gimple_assign_lhs (stmt)),
124 : : gimple_assign_rhs1 (stmt));
125 : 392216 : break;
126 : 1709040 : case GIMPLE_SINGLE_RHS:
127 : 1709040 : {
128 : 1709040 : t = gimple_assign_rhs1 (stmt);
129 : : /* Avoid modifying this tree in place below. */
130 : 3344442 : if ((gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (t)
131 : 1593980 : && gimple_location (stmt) != EXPR_LOCATION (t))
132 : 1911391 : || (gimple_block (stmt) && currently_expanding_to_rtl
133 : 45493 : && EXPR_P (t)))
134 : 1465005 : t = copy_node (t);
135 : : break;
136 : : }
137 : 0 : default:
138 : 0 : gcc_unreachable ();
139 : : }
140 : :
141 : 3285833 : if (gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (t))
142 : 3096442 : SET_EXPR_LOCATION (t, gimple_location (stmt));
143 : :
144 : 3285833 : return t;
145 : : }
146 : :
147 : :
148 : : #ifndef STACK_ALIGNMENT_NEEDED
149 : : #define STACK_ALIGNMENT_NEEDED 1
150 : : #endif
151 : :
152 : : #define SSAVAR(x) (TREE_CODE (x) == SSA_NAME ? SSA_NAME_VAR (x) : x)
153 : :
154 : : /* Choose either CUR or NEXT as the leader DECL for a partition.
155 : : Prefer ignored decls, to simplify debug dumps and reduce ambiguity
156 : : out of the same user variable being in multiple partitions (this is
157 : : less likely for compiler-introduced temps). */
158 : :
159 : : static tree
160 : 59405945 : leader_merge (tree cur, tree next)
161 : : {
162 : 59405945 : if (cur == NULL || cur == next)
163 : : return next;
164 : :
165 : 3196585 : if (DECL_P (cur) && DECL_IGNORED_P (cur))
166 : : return cur;
167 : :
168 : 2382033 : if (DECL_P (next) && DECL_IGNORED_P (next))
169 : 155479 : return next;
170 : :
171 : : return cur;
172 : : }
173 : :
174 : : /* Associate declaration T with storage space X. If T is no
175 : : SSA name this is exactly SET_DECL_RTL, otherwise make the
176 : : partition of T associated with X. */
177 : : static inline void
178 : 70512618 : set_rtl (tree t, rtx x)
179 : : {
180 : 70512618 : gcc_checking_assert (!x
181 : : || !(TREE_CODE (t) == SSA_NAME || is_gimple_reg (t))
182 : : || (use_register_for_decl (t)
183 : : ? (REG_P (x)
184 : : || (GET_CODE (x) == CONCAT
185 : : && (REG_P (XEXP (x, 0))
186 : : || SUBREG_P (XEXP (x, 0)))
187 : : && (REG_P (XEXP (x, 1))
188 : : || SUBREG_P (XEXP (x, 1))))
189 : : /* We need to accept PARALLELs for RESUT_DECLs
190 : : because of vector types with BLKmode returned
191 : : in multiple registers, but they are supposed
192 : : to be uncoalesced. */
193 : : || (GET_CODE (x) == PARALLEL
194 : : && SSAVAR (t)
195 : : && TREE_CODE (SSAVAR (t)) == RESULT_DECL
196 : : && (GET_MODE (x) == BLKmode
197 : : || !flag_tree_coalesce_vars)))
198 : : : (MEM_P (x) || x == pc_rtx
199 : : || (GET_CODE (x) == CONCAT
200 : : && MEM_P (XEXP (x, 0))
201 : : && MEM_P (XEXP (x, 1))))));
202 : : /* Check that the RTL for SSA_NAMEs and gimple-reg PARM_DECLs and
203 : : RESULT_DECLs has the expected mode. For memory, we accept
204 : : unpromoted modes, since that's what we're likely to get. For
205 : : PARM_DECLs and RESULT_DECLs, we'll have been called by
206 : : set_parm_rtl, which will give us the default def, so we don't
207 : : have to compute it ourselves. For RESULT_DECLs, we accept mode
208 : : mismatches too, as long as we have BLKmode or are not coalescing
209 : : across variables, so that we don't reject BLKmode PARALLELs or
210 : : unpromoted REGs. */
211 : 65226452 : gcc_checking_assert (!x || x == pc_rtx || TREE_CODE (t) != SSA_NAME
212 : : || (SSAVAR (t)
213 : : && TREE_CODE (SSAVAR (t)) == RESULT_DECL
214 : : && (promote_ssa_mode (t, NULL) == BLKmode
215 : : || !flag_tree_coalesce_vars))
216 : : || !use_register_for_decl (t)
217 : : || GET_MODE (x) == promote_ssa_mode (t, NULL));
218 : :
219 : : if (x)
220 : : {
221 : 65617150 : bool skip = false;
222 : 65617150 : tree cur = NULL_TREE;
223 : : rtx xm = x;
224 : :
225 : 65617150 : retry:
226 : 65617150 : if (MEM_P (xm))
227 : 4698643 : cur = MEM_EXPR (xm);
228 : : else if (REG_P (xm))
229 : 54707302 : cur = REG_EXPR (xm);
230 : : else if (SUBREG_P (xm))
231 : : {
232 : 0 : gcc_assert (subreg_lowpart_p (xm));
233 : 0 : xm = SUBREG_REG (xm);
234 : 0 : goto retry;
235 : : }
236 : : else if (GET_CODE (xm) == CONCAT)
237 : : {
238 : 387546 : xm = XEXP (xm, 0);
239 : 387546 : goto retry;
240 : : }
241 : : else if (GET_CODE (xm) == PARALLEL)
242 : : {
243 : 3152 : xm = XVECEXP (xm, 0, 0);
244 : 3152 : gcc_assert (GET_CODE (xm) == EXPR_LIST);
245 : 3152 : xm = XEXP (xm, 0);
246 : 3152 : goto retry;
247 : : }
248 : 5820507 : else if (xm == pc_rtx)
249 : : skip = true;
250 : : else
251 : 0 : gcc_unreachable ();
252 : :
253 : 59405945 : tree next = skip ? cur : leader_merge (cur, SSAVAR (t) ? SSAVAR (t) : t);
254 : :
255 : 65226452 : if (cur != next)
256 : : {
257 : 27497741 : if (MEM_P (x))
258 : 4008792 : set_mem_attributes (x,
259 : 2004396 : next && TREE_CODE (next) == SSA_NAME
260 : 12174 : ? TREE_TYPE (next)
261 : : : next, true);
262 : : else
263 : 25493345 : set_reg_attrs_for_decl_rtl (next, x);
264 : : }
265 : : }
266 : :
267 : 70512618 : if (TREE_CODE (t) == SSA_NAME)
268 : : {
269 : 56829218 : int part = var_to_partition (SA.map, t);
270 : 56829218 : if (part != NO_PARTITION)
271 : : {
272 : 56829218 : if (SA.partition_to_pseudo[part])
273 : 31113142 : gcc_assert (SA.partition_to_pseudo[part] == x);
274 : 25716076 : else if (x != pc_rtx)
275 : 25713214 : SA.partition_to_pseudo[part] = x;
276 : : }
277 : : /* For the benefit of debug information at -O0 (where
278 : : vartracking doesn't run) record the place also in the base
279 : : DECL. For PARMs and RESULTs, do so only when setting the
280 : : default def. */
281 : 113655574 : if (x && x != pc_rtx && SSA_NAME_VAR (t)
282 : 74557789 : && (VAR_P (SSA_NAME_VAR (t))
283 : 7316353 : || SSA_NAME_IS_DEFAULT_DEF (t)))
284 : : {
285 : 17547486 : tree var = SSA_NAME_VAR (t);
286 : : /* If we don't yet have something recorded, just record it now. */
287 : 17547486 : if (!DECL_RTL_SET_P (var))
288 : 7400273 : SET_DECL_RTL (var, x);
289 : : /* If we have it set already to "multiple places" don't
290 : : change this. */
291 : 10147213 : else if (DECL_RTL (var) == pc_rtx)
292 : : ;
293 : : /* If we have something recorded and it's not the same place
294 : : as we want to record now, we have multiple partitions for the
295 : : same base variable, with different places. We can't just
296 : : randomly chose one, hence we have to say that we don't know.
297 : : This only happens with optimization, and there var-tracking
298 : : will figure out the right thing. */
299 : 9055822 : else if (DECL_RTL (var) != x)
300 : 224747 : SET_DECL_RTL (var, pc_rtx);
301 : : }
302 : : }
303 : : else
304 : 13683400 : SET_DECL_RTL (t, x);
305 : 70512618 : }
306 : :
307 : : /* This structure holds data relevant to one variable that will be
308 : : placed in a stack slot. */
309 : : class stack_var
310 : : {
311 : : public:
312 : : /* The Variable. */
313 : : tree decl;
314 : :
315 : : /* Initially, the size of the variable. Later, the size of the partition,
316 : : if this variable becomes it's partition's representative. */
317 : : poly_uint64 size;
318 : :
319 : : /* The *byte* alignment required for this variable. Or as, with the
320 : : size, the alignment for this partition. */
321 : : unsigned int alignb;
322 : :
323 : : /* The partition representative. */
324 : : unsigned representative;
325 : :
326 : : /* The next stack variable in the partition, or EOC. */
327 : : unsigned next;
328 : :
329 : : /* The numbers of conflicting stack variables. */
330 : : bitmap conflicts;
331 : : };
332 : :
333 : : #define EOC ((unsigned)-1)
334 : :
335 : : /* We have an array of such objects while deciding allocation. */
336 : : static class stack_var *stack_vars;
337 : : static unsigned stack_vars_alloc;
338 : : static unsigned stack_vars_num;
339 : : static hash_map<tree, unsigned> *decl_to_stack_part;
340 : :
341 : : #define INVALID_STACK_INDEX ((unsigned)-1)
342 : :
343 : : /* Conflict bitmaps go on this obstack. This allows us to destroy
344 : : all of them in one big sweep. */
345 : : static bitmap_obstack stack_var_bitmap_obstack;
346 : :
347 : : /* An array of indices such that stack_vars[stack_vars_sorted[i]].size
348 : : is non-decreasing. */
349 : : static unsigned *stack_vars_sorted;
350 : :
351 : : /* The phase of the stack frame. This is the known misalignment of
352 : : virtual_stack_vars_rtx from PREFERRED_STACK_BOUNDARY. That is,
353 : : (frame_offset+frame_phase) % PREFERRED_STACK_BOUNDARY == 0. */
354 : : static int frame_phase;
355 : :
356 : : /* Used during expand_used_vars to remember if we saw any decls for
357 : : which we'd like to enable stack smashing protection. */
358 : : static bool has_protected_decls;
359 : :
360 : : /* Used during expand_used_vars. Remember if we say a character buffer
361 : : smaller than our cutoff threshold. Used for -Wstack-protector. */
362 : : static bool has_short_buffer;
363 : :
364 : : /* Compute the byte alignment to use for DECL. Ignore alignment
365 : : we can't do with expected alignment of the stack boundary. */
366 : :
367 : : static unsigned int
368 : 6607812 : align_local_variable (tree decl, bool really_expand)
369 : : {
370 : 6607812 : unsigned int align;
371 : :
372 : 6607812 : if (TREE_CODE (decl) == SSA_NAME)
373 : : {
374 : 439627 : tree type = TREE_TYPE (decl);
375 : 439627 : machine_mode mode = TYPE_MODE (type);
376 : :
377 : 439627 : align = TYPE_ALIGN (type);
378 : 439627 : if (mode != BLKmode
379 : 439627 : && align < GET_MODE_ALIGNMENT (mode))
380 : 456 : align = GET_MODE_ALIGNMENT (mode);
381 : : }
382 : : else
383 : 6168185 : align = LOCAL_DECL_ALIGNMENT (decl);
384 : :
385 : 6607812 : if (hwasan_sanitize_stack_p ())
386 : 265 : align = MAX (align, (unsigned) HWASAN_TAG_GRANULE_SIZE * BITS_PER_UNIT);
387 : :
388 : 6607812 : if (TREE_CODE (decl) != SSA_NAME && really_expand)
389 : : /* Don't change DECL_ALIGN when called from estimated_stack_frame_size.
390 : : That is done before IPA and could bump alignment based on host
391 : : backend even for offloaded code which wants different
392 : : LOCAL_DECL_ALIGNMENT. */
393 : 1556736 : SET_DECL_ALIGN (decl, align);
394 : :
395 : 6607812 : return align / BITS_PER_UNIT;
396 : : }
397 : :
398 : : /* Align given offset BASE with ALIGN. Truncate up if ALIGN_UP is true,
399 : : down otherwise. Return truncated BASE value. */
400 : :
401 : : static inline unsigned HOST_WIDE_INT
402 : : align_base (HOST_WIDE_INT base, unsigned HOST_WIDE_INT align, bool align_up)
403 : : {
404 : : return align_up ? (base + align - 1) & -align : base & -align;
405 : : }
406 : :
407 : : /* Allocate SIZE bytes at byte alignment ALIGN from the stack frame.
408 : : Return the frame offset. */
409 : :
410 : : static poly_int64
411 : 1731066 : alloc_stack_frame_space (poly_int64 size, unsigned HOST_WIDE_INT align)
412 : : {
413 : 1731066 : poly_int64 offset, new_frame_offset;
414 : :
415 : 1731066 : if (FRAME_GROWS_DOWNWARD)
416 : : {
417 : 1731066 : new_frame_offset
418 : 1731066 : = aligned_lower_bound (frame_offset - frame_phase - size,
419 : 1731066 : align) + frame_phase;
420 : 1731066 : offset = new_frame_offset;
421 : : }
422 : : else
423 : : {
424 : : new_frame_offset
425 : : = aligned_upper_bound (frame_offset - frame_phase,
426 : : align) + frame_phase;
427 : : offset = new_frame_offset;
428 : : new_frame_offset += size;
429 : : }
430 : 1731066 : frame_offset = new_frame_offset;
431 : :
432 : 1731066 : if (frame_offset_overflow (frame_offset, cfun->decl))
433 : 0 : frame_offset = offset = 0;
434 : :
435 : 1731066 : return offset;
436 : : }
437 : :
438 : : /* Ensure that the stack is aligned to ALIGN bytes.
439 : : Return the new frame offset. */
440 : : static poly_int64
441 : 1605 : align_frame_offset (unsigned HOST_WIDE_INT align)
442 : : {
443 : 0 : return alloc_stack_frame_space (0, align);
444 : : }
445 : :
446 : : /* Accumulate DECL into STACK_VARS. */
447 : :
448 : : static void
449 : 5820507 : add_stack_var (tree decl, bool really_expand)
450 : : {
451 : 5820507 : class stack_var *v;
452 : :
453 : 5820507 : if (stack_vars_num >= stack_vars_alloc)
454 : : {
455 : 1368584 : if (stack_vars_alloc)
456 : 33752 : stack_vars_alloc = stack_vars_alloc * 3 / 2;
457 : : else
458 : 1334832 : stack_vars_alloc = 32;
459 : 1368584 : stack_vars
460 : 1368584 : = XRESIZEVEC (class stack_var, stack_vars, stack_vars_alloc);
461 : : }
462 : 5820507 : if (!decl_to_stack_part)
463 : 0 : decl_to_stack_part = new hash_map<tree, unsigned>;
464 : :
465 : 5820507 : v = &stack_vars[stack_vars_num];
466 : 5820507 : decl_to_stack_part->put (decl, stack_vars_num);
467 : :
468 : 5820507 : v->decl = decl;
469 : 5820507 : tree size = TREE_CODE (decl) == SSA_NAME
470 : 5820507 : ? TYPE_SIZE_UNIT (TREE_TYPE (decl))
471 : 5820507 : : DECL_SIZE_UNIT (decl);
472 : 5820507 : v->size = tree_to_poly_uint64 (size);
473 : : /* Ensure that all variables have size, so that &a != &b for any two
474 : : variables that are simultaneously live. */
475 : 5820507 : if (known_eq (v->size, 0U))
476 : 23832 : v->size = 1;
477 : 5820507 : v->alignb = align_local_variable (decl, really_expand);
478 : : /* An alignment of zero can mightily confuse us later. */
479 : 5820507 : gcc_assert (v->alignb != 0);
480 : :
481 : : /* All variables are initially in their own partition. */
482 : 5820507 : v->representative = stack_vars_num;
483 : 5820507 : v->next = EOC;
484 : :
485 : : /* All variables initially conflict with no other. */
486 : 5820507 : v->conflicts = NULL;
487 : :
488 : : /* Ensure that this decl doesn't get put onto the list twice. */
489 : 5820507 : set_rtl (decl, pc_rtx);
490 : :
491 : 5820507 : stack_vars_num++;
492 : 5820507 : }
493 : :
494 : : /* Make the decls associated with luid's X and Y conflict. */
495 : :
496 : : static void
497 : 11152580 : add_stack_var_conflict (unsigned x, unsigned y)
498 : : {
499 : 11152580 : class stack_var *a = &stack_vars[x];
500 : 11152580 : class stack_var *b = &stack_vars[y];
501 : 11152580 : if (x == y)
502 : : return;
503 : 10081320 : if (!a->conflicts)
504 : 638645 : a->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack);
505 : 10081320 : if (!b->conflicts)
506 : 115583 : b->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack);
507 : 10081320 : bitmap_set_bit (a->conflicts, y);
508 : 10081320 : bitmap_set_bit (b->conflicts, x);
509 : : }
510 : :
511 : : /* Check whether the decls associated with luid's X and Y conflict. */
512 : :
513 : : static bool
514 : 11288358 : stack_var_conflict_p (unsigned x, unsigned y)
515 : : {
516 : 11288358 : class stack_var *a = &stack_vars[x];
517 : 11288358 : class stack_var *b = &stack_vars[y];
518 : 11288358 : if (x == y)
519 : : return false;
520 : : /* Partitions containing an SSA name result from gimple registers
521 : : with things like unsupported modes. They are top-level and
522 : : hence conflict with everything else. */
523 : 11288358 : if (TREE_CODE (a->decl) == SSA_NAME || TREE_CODE (b->decl) == SSA_NAME)
524 : : return true;
525 : :
526 : 11254090 : if (!a->conflicts || !b->conflicts)
527 : : return false;
528 : 11197507 : return bitmap_bit_p (a->conflicts, y);
529 : : }
530 : :
531 : : /* Returns the DECL's index into the stack_vars array.
532 : : If the DECL does not exist return INVALID_STACK_INDEX. */
533 : : static unsigned
534 : 46793471 : decl_stack_index (tree decl)
535 : : {
536 : 46793471 : if (!decl)
537 : : return INVALID_STACK_INDEX;
538 : 46793471 : if (!DECL_P (decl))
539 : : return INVALID_STACK_INDEX;
540 : 35998625 : if (DECL_RTL_IF_SET (decl) != pc_rtx)
541 : : return INVALID_STACK_INDEX;
542 : 24047226 : unsigned *v = decl_to_stack_part->get (decl);
543 : 24047226 : if (!v)
544 : : return INVALID_STACK_INDEX;
545 : :
546 : 24047226 : unsigned indx = *v;
547 : 24047226 : gcc_checking_assert (indx != INVALID_STACK_INDEX);
548 : 24047226 : gcc_checking_assert (indx < stack_vars_num);
549 : : return indx;
550 : : }
551 : :
552 : : /* Callback for walk_stmt_ops. If OP is a decl touched by add_stack_var
553 : : enter its partition number into bitmap DATA. */
554 : :
555 : : static bool
556 : 29840025 : visit_op (gimple *, tree op, tree, void *data)
557 : : {
558 : 29840025 : bitmap active = (bitmap)data;
559 : 29840025 : op = get_base_address (op);
560 : 29840025 : unsigned idx = decl_stack_index (op);
561 : 29840025 : if (idx != INVALID_STACK_INDEX)
562 : 14806095 : bitmap_set_bit (active, idx);
563 : 29840025 : return false;
564 : : }
565 : :
566 : : /* Callback for walk_stmt_ops. If OP is a decl touched by add_stack_var
567 : : record conflicts between it and all currently active other partitions
568 : : from bitmap DATA. */
569 : :
570 : : static bool
571 : 13616024 : visit_conflict (gimple *, tree op, tree, void *data)
572 : : {
573 : 13616024 : bitmap active = (bitmap)data;
574 : 13616024 : op = get_base_address (op);
575 : 13616024 : unsigned num = decl_stack_index (op);
576 : 13616024 : if (num != INVALID_STACK_INDEX
577 : 13616024 : && bitmap_set_bit (active, num))
578 : : {
579 : 985243 : bitmap_iterator bi;
580 : 985243 : unsigned i;
581 : 985243 : gcc_assert (num < stack_vars_num);
582 : 10677567 : EXECUTE_IF_SET_IN_BITMAP (active, 0, i, bi)
583 : 9692324 : add_stack_var_conflict (num, i);
584 : : }
585 : 13616024 : return false;
586 : : }
587 : :
588 : : /* A cache for ssa name to address of stack variables.
589 : : When taking into account if a ssa name refers to an
590 : : address of a stack variable, we need to walk the
591 : : expressions backwards to find the addresses. This
592 : : cache is there so we don't need to walk the expressions
593 : : all the time. */
594 : : struct vars_ssa_cache
595 : : {
596 : : private:
597 : : /* Currently an entry is a bitmap of all of the known stack variables
598 : : addresses that are referenced by the ssa name.
599 : : When the bitmap is the nullptr, then there is no cache.
600 : : Currently only empty bitmaps are shared.
601 : : The reason for why empty cache is not just a null is so we know the
602 : : cache for an entry is filled in. */
603 : : struct entry
604 : : {
605 : : bitmap bmap = nullptr;
606 : : };
607 : : entry *vars_ssa_caches;
608 : : public:
609 : :
610 : : vars_ssa_cache();
611 : : ~vars_ssa_cache();
612 : : const_bitmap operator() (tree name);
613 : : void dump (FILE *file);
614 : :
615 : : private:
616 : : /* Can't copy. */
617 : : vars_ssa_cache(const vars_ssa_cache&) = delete;
618 : : vars_ssa_cache(vars_ssa_cache&&) = delete;
619 : :
620 : : /* The shared empty bitmap. */
621 : : bitmap empty;
622 : :
623 : : /* Unshare the index, currently only need
624 : : to unshare if the entry was empty. */
625 : 1099673 : void unshare(int indx)
626 : : {
627 : 1099673 : if (vars_ssa_caches[indx].bmap == empty)
628 : 463585 : vars_ssa_caches[indx].bmap = BITMAP_ALLOC (&stack_var_bitmap_obstack);
629 : 1099673 : }
630 : : void create (tree);
631 : : bool exists (tree use);
632 : : void add_one (tree old_name, unsigned);
633 : : bool update (tree old_name, tree use);
634 : : };
635 : :
636 : : /* Constructor of the cache, create the cache array. */
637 : 150262 : vars_ssa_cache::vars_ssa_cache ()
638 : : {
639 : 32220559 : vars_ssa_caches = new entry[num_ssa_names]{};
640 : :
641 : : /* Create the shared empty bitmap too. */
642 : 150262 : empty = BITMAP_ALLOC (&stack_var_bitmap_obstack);
643 : 150262 : }
644 : :
645 : : /* Delete the array. The bitmaps will be freed
646 : : when stack_var_bitmap_obstack is freed. */
647 : 150262 : vars_ssa_cache::~vars_ssa_cache ()
648 : : {
649 : 150262 : delete []vars_ssa_caches;
650 : 150262 : }
651 : :
652 : : /* Create an empty entry for the USE ssa name. */
653 : : void
654 : 10945232 : vars_ssa_cache::create (tree use)
655 : : {
656 : 10945232 : int num = SSA_NAME_VERSION (use);
657 : 10945232 : if (vars_ssa_caches[num].bmap)
658 : : return;
659 : 10945232 : vars_ssa_caches[num].bmap = empty;
660 : : }
661 : :
662 : : /* Returns true if the cache for USE exists. */
663 : : bool
664 : 71385357 : vars_ssa_cache::exists (tree use)
665 : : {
666 : 71385357 : int num = SSA_NAME_VERSION (use);
667 : 71385357 : return vars_ssa_caches[num].bmap != nullptr;
668 : : }
669 : :
670 : : /* Add to USE's bitmap for stack variable IDX. */
671 : : void
672 : 162669 : vars_ssa_cache::add_one (tree use, unsigned idx)
673 : : {
674 : 162669 : gcc_assert (idx != INVALID_STACK_INDEX);
675 : 162669 : int num = SSA_NAME_VERSION (use);
676 : 162669 : gcc_assert (vars_ssa_caches[num].bmap);
677 : 162669 : unshare (num);
678 : 162669 : bitmap_set_bit (vars_ssa_caches[num].bmap, idx);
679 : 162669 : }
680 : :
681 : : /* Update cache of OLD_NAME from the USE's cache. */
682 : : bool
683 : 25435407 : vars_ssa_cache::update (tree old_name, tree use)
684 : : {
685 : 25435407 : if (old_name == use)
686 : : return false;
687 : 16295241 : int num = SSA_NAME_VERSION (use);
688 : 16295241 : int old_num = SSA_NAME_VERSION (old_name);
689 : :
690 : : /* If the old name was empty, then there is nothing to be updated. */
691 : 16295241 : if (vars_ssa_caches[num].bmap == empty)
692 : : return false;
693 : 937004 : unshare (old_num);
694 : 937004 : return bitmap_ior_into (vars_ssa_caches[old_num].bmap, vars_ssa_caches[num].bmap);
695 : : }
696 : :
697 : : /* Dump out the cache. Note empty and non-filled
698 : : in ssa names are not printed out. */
699 : : void
700 : 0 : vars_ssa_cache::dump (FILE *file)
701 : : {
702 : 0 : fprintf (file, "var ssa address cache\n");
703 : 0 : for (unsigned num = 0; num < num_ssa_names; num++)
704 : : {
705 : 0 : if (!vars_ssa_caches[num].bmap
706 : 0 : || vars_ssa_caches[num].bmap == empty)
707 : 0 : continue;
708 : 0 : fprintf (file, "_%d refers to:\n", num);
709 : 0 : bitmap_iterator bi;
710 : 0 : unsigned i;
711 : 0 : EXECUTE_IF_SET_IN_BITMAP (vars_ssa_caches[num].bmap, 0, i, bi)
712 : : {
713 : 0 : fputc ('\t', file);
714 : 0 : print_generic_expr (file, stack_vars[i].decl, dump_flags);
715 : : }
716 : 0 : fputc ('\n', file);
717 : : }
718 : 0 : fputc ('\n', file);
719 : 0 : }
720 : :
721 : : /* Returns the filled in cache for NAME.
722 : : This will fill in the cache if it does not exist already.
723 : : Returns an empty for ssa names that can't contain pointers
724 : : (only intergal types and pointer types will contain pointers). */
725 : :
726 : : const_bitmap
727 : 55739781 : vars_ssa_cache::operator() (tree name)
728 : : {
729 : 55739781 : gcc_assert (TREE_CODE (name) == SSA_NAME);
730 : :
731 : 91996199 : if (!POINTER_TYPE_P (TREE_TYPE (name))
732 : 90839387 : && !ANY_INTEGRAL_TYPE_P (TREE_TYPE (name)))
733 : 2432902 : return empty;
734 : :
735 : 53306879 : if (exists (name))
736 : 44211944 : return vars_ssa_caches[SSA_NAME_VERSION (name)].bmap;
737 : :
738 : 9094935 : auto_vec<std::pair<tree,tree>, 4> work_list;
739 : 9094935 : auto_vec<std::pair<tree,tree>, 4> update_cache_list;
740 : :
741 : 9094935 : work_list.safe_push (std::make_pair (name, name));
742 : :
743 : 33637455 : while (!work_list.is_empty ())
744 : : {
745 : 24542520 : auto item = work_list.pop();
746 : 24542520 : tree use = item.first;
747 : 24542520 : tree old_name = item.second;
748 : 24542520 : if (TREE_CODE (use) == ADDR_EXPR)
749 : : {
750 : 423362 : tree op = TREE_OPERAND (use, 0);
751 : 423362 : op = get_base_address (op);
752 : 423362 : unsigned idx = decl_stack_index (op);
753 : 423362 : if (idx != INVALID_STACK_INDEX)
754 : 162669 : add_one (old_name, idx);
755 : 13597288 : continue;
756 : 423362 : }
757 : :
758 : 24119158 : if (TREE_CODE (use) != SSA_NAME)
759 : 5965015 : continue;
760 : :
761 : 31711720 : if (!POINTER_TYPE_P (TREE_TYPE (use))
762 : 31587961 : && !ANY_INTEGRAL_TYPE_P (TREE_TYPE (use)))
763 : 75665 : continue;
764 : :
765 : : /* Mark the old ssa name needs to be update from the use. */
766 : 18078478 : update_cache_list.safe_push (item);
767 : :
768 : : /* If the cache exists for the use, don't try to recreate it. */
769 : 18078478 : if (exists (use))
770 : : {
771 : : /* Update the cache here, this can reduce the number of
772 : : times through the update loop below. */
773 : 7133246 : update (old_name, use);
774 : 7133246 : continue;
775 : : }
776 : :
777 : : /* Create the cache bitmap for the use and also
778 : : so we don't go into an infinite loop for some phi nodes with loops. */
779 : 10945232 : create (use);
780 : :
781 : 10945232 : gimple *g = SSA_NAME_DEF_STMT (use);
782 : :
783 : : /* CONSTRUCTOR here is always a vector initialization,
784 : : walk each element too. */
785 : 10945232 : if (gimple_assign_single_p (g)
786 : 10945232 : && TREE_CODE (gimple_assign_rhs1 (g)) == CONSTRUCTOR)
787 : : {
788 : : tree ctr = gimple_assign_rhs1 (g);
789 : : unsigned i;
790 : : tree elm;
791 : 313711 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctr), i, elm)
792 : 218428 : work_list.safe_push (std::make_pair (elm, use));
793 : : }
794 : : /* For assignments, walk each operand for possible addresses.
795 : : For PHI nodes, walk each argument. */
796 : 10849949 : else if (gassign *a = dyn_cast <gassign *> (g))
797 : : {
798 : : /* operand 0 is the lhs. */
799 : 19342756 : for (unsigned i = 1; i < gimple_num_ops (g); i++)
800 : 11179547 : work_list.safe_push (std::make_pair (gimple_op (a, i), use));
801 : : }
802 : 12562713 : else if (gphi *p = dyn_cast <gphi *> (g))
803 : 5667091 : for (unsigned i = 0; i < gimple_phi_num_args (p); ++i)
804 : 4049610 : work_list.safe_push (std::make_pair (gimple_phi_arg_def (p, i), use));
805 : : }
806 : :
807 : : /* Update the cache. Note a loop is needed as phi nodes could
808 : : cause a loop to form. The number of times through this loop
809 : : will be small though. */
810 : 9140134 : bool changed;
811 : 18280268 : do {
812 : 9140134 : changed = false;
813 : 9140134 : unsigned int i;
814 : 9140134 : std::pair<tree,tree> *e;
815 : 45677364 : FOR_EACH_VEC_ELT_REVERSE (update_cache_list, i, e)
816 : : {
817 : 18302161 : if (update (e->second, e->first))
818 : 51712 : changed = true;
819 : : }
820 : : } while (changed);
821 : :
822 : 9094935 : return vars_ssa_caches[SSA_NAME_VERSION (name)].bmap;
823 : 9094935 : }
824 : :
825 : : /* Helper function for add_scope_conflicts_1. For USE on
826 : : a stmt, if it is a SSA_NAME and in its defining statement
827 : : is known to be based on some ADDR_EXPR, invoke VISIT
828 : : on that ADDR_EXPR. */
829 : :
830 : : static inline void
831 : 55739781 : add_scope_conflicts_2 (vars_ssa_cache &cache, tree name,
832 : : bitmap work, walk_stmt_load_store_addr_fn visit)
833 : : {
834 : 55739781 : gcc_assert (TREE_CODE (name) == SSA_NAME);
835 : :
836 : : /* Querry the cache for the mapping of addresses that are referendd by
837 : : ssa name NAME. Querrying it will fill in it. */
838 : 55739781 : bitmap_iterator bi;
839 : 55739781 : unsigned i;
840 : 55739781 : const_bitmap bmap = cache (name);
841 : : /* Visit each stack variable that is referenced. */
842 : 58116890 : EXECUTE_IF_SET_IN_BITMAP (bmap, 0, i, bi)
843 : 2377109 : visit (nullptr, stack_vars[i].decl, nullptr, work);
844 : 55739781 : }
845 : :
846 : : /* Helper routine for add_scope_conflicts, calculating the active partitions
847 : : at the end of BB, leaving the result in WORK. We're called to generate
848 : : conflicts when FOR_CONFLICT is true, otherwise we're just tracking
849 : : liveness. */
850 : :
851 : : static void
852 : 16290386 : add_scope_conflicts_1 (vars_ssa_cache &cache, basic_block bb, bitmap work, bool for_conflict)
853 : : {
854 : 16290386 : edge e;
855 : 16290386 : edge_iterator ei;
856 : 16290386 : gimple_stmt_iterator gsi;
857 : 16290386 : walk_stmt_load_store_addr_fn visit;
858 : 16290386 : use_operand_p use_p;
859 : 16290386 : ssa_op_iter iter;
860 : 16290386 : bool had_non_clobbers = false;
861 : :
862 : 16290386 : bitmap_clear (work);
863 : : /* The copy what was alive out going from the edges. */
864 : 41163829 : FOR_EACH_EDGE (e, ei, bb->preds)
865 : 24873443 : bitmap_ior_into (work, (bitmap)e->src->aux);
866 : :
867 : 16290386 : visit = for_conflict ? visit_conflict : visit_op;
868 : :
869 : : /* Addresses coming into the bb via phis are alive at the entry point. */
870 : 21541290 : for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
871 : 5250904 : add_scope_conflicts_2 (cache, gimple_phi_result (gsi_stmt (gsi)), work, visit_op);
872 : :
873 : 177018422 : for (gsi = gsi_after_labels (bb); !gsi_end_p (gsi); gsi_next (&gsi))
874 : : {
875 : 160728036 : gimple *stmt = gsi_stmt (gsi);
876 : :
877 : : /* Debug statements are not considered for liveness. */
878 : 160728036 : if (is_gimple_debug (stmt))
879 : 97437279 : continue;
880 : :
881 : : /* If we had `var = {CLOBBER}`, then var is no longer
882 : : considered alive after this point but might become
883 : : alive later on. */
884 : 63290757 : if (gimple_clobber_p (stmt))
885 : : {
886 : 3656145 : tree lhs = gimple_assign_lhs (stmt);
887 : : /* Handle only plain var clobbers, not partial ones.
888 : : Nested functions lowering and C++ front-end inserts clobbers
889 : : which are partial clobbers. */
890 : 3656145 : if (!VAR_P (lhs))
891 : 742085 : continue;
892 : 2914060 : unsigned indx = decl_stack_index (lhs);
893 : 2914060 : if (indx != INVALID_STACK_INDEX)
894 : 2310431 : bitmap_clear_bit (work, indx);
895 : : }
896 : : else
897 : : {
898 : 59634612 : if (for_conflict && !had_non_clobbers)
899 : : {
900 : : /* When we are inheriting live variables from our predecessors
901 : : through a CFG merge we might not see an actual mention of
902 : : the variables to record the approprate conflict as defs/uses
903 : : might be through indirect stores/loads. For this reason
904 : : we have to make sure each live variable conflicts with
905 : : each other. When there's just a single predecessor the
906 : : set of conflicts is already up-to-date.
907 : : We perform this delayed at the first real instruction to
908 : : allow clobbers starting this block to remove variables from
909 : : the set of live variables. */
910 : 4904010 : bitmap_iterator bi;
911 : 4904010 : unsigned i;
912 : 4904010 : if (EDGE_COUNT (bb->preds) > 1)
913 : 12442714 : EXECUTE_IF_SET_IN_BITMAP (work, 0, i, bi)
914 : : {
915 : 10992486 : class stack_var *a = &stack_vars[i];
916 : 10992486 : if (!a->conflicts)
917 : 263681 : a->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack);
918 : 10992486 : bitmap_ior_into (a->conflicts, work);
919 : : }
920 : 4904010 : had_non_clobbers = true;
921 : : }
922 : 59634612 : walk_stmt_load_store_addr_ops (stmt, work, visit, visit, visit);
923 : 110123489 : FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
924 : 50488877 : add_scope_conflicts_2 (cache, USE_FROM_PTR (use_p), work, visit);
925 : : }
926 : : }
927 : :
928 : : /* When there was no real instruction but there's a CFG merge we need
929 : : to add the conflicts now. */
930 : 16290386 : if (for_conflict && !had_non_clobbers && EDGE_COUNT (bb->preds) > 1)
931 : : {
932 : 170407 : bitmap_iterator bi;
933 : 170407 : unsigned i;
934 : 1068951 : EXECUTE_IF_SET_IN_BITMAP (work, 0, i, bi)
935 : : {
936 : 898544 : class stack_var *a = &stack_vars[i];
937 : 898544 : if (!a->conflicts)
938 : 39461 : a->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack);
939 : 898544 : bitmap_ior_into (a->conflicts, work);
940 : : }
941 : : }
942 : 16290386 : }
943 : :
944 : : /* Generate stack partition conflicts between all partitions that are
945 : : simultaneously live. */
946 : :
947 : : static void
948 : 237493 : add_scope_conflicts (void)
949 : : {
950 : : /* If there is only one variable, there is nothing to be done as
951 : : there is only possible partition. */
952 : 237493 : if (stack_vars_num == 1)
953 : 87231 : return;
954 : :
955 : 150262 : basic_block bb;
956 : 150262 : bool changed;
957 : 150262 : bitmap work = BITMAP_ALLOC (NULL);
958 : 150262 : int *rpo;
959 : 150262 : int n_bbs;
960 : :
961 : 150262 : vars_ssa_cache cache;
962 : :
963 : : /* We approximate the live range of a stack variable by taking the first
964 : : mention of its name as starting point(s), and by the end-of-scope
965 : : death clobber added by gimplify as ending point(s) of the range.
966 : : This overapproximates in the case we for instance moved an address-taken
967 : : operation upward, without also moving a dereference to it upwards.
968 : : But it's conservatively correct as a variable never can hold values
969 : : before its name is mentioned at least once.
970 : :
971 : : We then do a mostly classical bitmap liveness algorithm. */
972 : :
973 : 5589238 : FOR_ALL_BB_FN (bb, cfun)
974 : 5438976 : bb->aux = BITMAP_ALLOC (&stack_var_bitmap_obstack);
975 : :
976 : 150262 : rpo = XNEWVEC (int, last_basic_block_for_fn (cfun));
977 : 150262 : n_bbs = pre_and_rev_post_order_compute (NULL, rpo, false);
978 : :
979 : 150262 : changed = true;
980 : 608694 : while (changed)
981 : : {
982 : : int i;
983 : : changed = false;
984 : 11460104 : for (i = 0; i < n_bbs; i++)
985 : : {
986 : 11151934 : bitmap active;
987 : 11151934 : bb = BASIC_BLOCK_FOR_FN (cfun, rpo[i]);
988 : 11151934 : active = (bitmap)bb->aux;
989 : 11151934 : add_scope_conflicts_1 (cache, bb, work, false);
990 : 11151934 : if (bitmap_ior_into (active, work))
991 : 4510406 : changed = true;
992 : : }
993 : : }
994 : :
995 : 5288714 : FOR_EACH_BB_FN (bb, cfun)
996 : 5138452 : add_scope_conflicts_1 (cache, bb, work, true);
997 : :
998 : 150262 : if (dump_file && (dump_flags & TDF_DETAILS))
999 : 0 : cache.dump (dump_file);
1000 : :
1001 : 150262 : free (rpo);
1002 : 150262 : BITMAP_FREE (work);
1003 : 5589238 : FOR_ALL_BB_FN (bb, cfun)
1004 : 5438976 : BITMAP_FREE (bb->aux);
1005 : 150262 : }
1006 : :
1007 : : /* A subroutine of partition_stack_vars. A comparison function for qsort,
1008 : : sorting an array of indices by the properties of the object. */
1009 : :
1010 : : static int
1011 : 19869200 : stack_var_cmp (const void *a, const void *b)
1012 : : {
1013 : 19869200 : unsigned ia = *(const unsigned *)a;
1014 : 19869200 : unsigned ib = *(const unsigned *)b;
1015 : 19869200 : unsigned int aligna = stack_vars[ia].alignb;
1016 : 19869200 : unsigned int alignb = stack_vars[ib].alignb;
1017 : 19869200 : poly_int64 sizea = stack_vars[ia].size;
1018 : 19869200 : poly_int64 sizeb = stack_vars[ib].size;
1019 : 19869200 : tree decla = stack_vars[ia].decl;
1020 : 19869200 : tree declb = stack_vars[ib].decl;
1021 : 19869200 : bool largea, largeb;
1022 : 19869200 : unsigned int uida, uidb;
1023 : :
1024 : : /* Primary compare on "large" alignment. Large comes first. */
1025 : 19869200 : largea = (aligna * BITS_PER_UNIT > MAX_SUPPORTED_STACK_ALIGNMENT);
1026 : 19869200 : largeb = (alignb * BITS_PER_UNIT > MAX_SUPPORTED_STACK_ALIGNMENT);
1027 : 19869200 : if (largea != largeb)
1028 : 0 : return (int)largeb - (int)largea;
1029 : :
1030 : : /* Secondary compare on size, decreasing */
1031 : 19869200 : int diff = compare_sizes_for_sort (sizeb, sizea);
1032 : 19869200 : if (diff != 0)
1033 : 8790604 : return diff;
1034 : :
1035 : : /* Tertiary compare on true alignment, decreasing. */
1036 : 11078596 : if (aligna < alignb)
1037 : : return -1;
1038 : 10731557 : if (aligna > alignb)
1039 : : return 1;
1040 : :
1041 : : /* Final compare on ID for sort stability, increasing.
1042 : : Two SSA names are compared by their version, SSA names come before
1043 : : non-SSA names, and two normal decls are compared by their DECL_UID. */
1044 : 10443455 : if (TREE_CODE (decla) == SSA_NAME)
1045 : : {
1046 : 36734 : if (TREE_CODE (declb) == SSA_NAME)
1047 : 32199 : uida = SSA_NAME_VERSION (decla), uidb = SSA_NAME_VERSION (declb);
1048 : : else
1049 : : return -1;
1050 : : }
1051 : 10406721 : else if (TREE_CODE (declb) == SSA_NAME)
1052 : : return 1;
1053 : : else
1054 : 10401268 : uida = DECL_UID (decla), uidb = DECL_UID (declb);
1055 : 10433467 : if (uida < uidb)
1056 : : return 1;
1057 : 5203930 : if (uida > uidb)
1058 : 5203930 : return -1;
1059 : : return 0;
1060 : : }
1061 : :
1062 : : struct part_traits : unbounded_int_hashmap_traits <unsigned , bitmap> {};
1063 : : typedef hash_map<unsigned, bitmap, part_traits> part_hashmap;
1064 : :
1065 : : /* If the points-to solution *PI points to variables that are in a partition
1066 : : together with other variables add all partition members to the pointed-to
1067 : : variables bitmap. */
1068 : :
1069 : : static void
1070 : 1673810 : add_partitioned_vars_to_ptset (struct pt_solution *pt,
1071 : : part_hashmap *decls_to_partitions,
1072 : : hash_set<bitmap> *visited, bitmap temp)
1073 : : {
1074 : 1673810 : bitmap_iterator bi;
1075 : 1673810 : unsigned i;
1076 : 1673810 : bitmap *part;
1077 : :
1078 : 1673810 : if (pt->anything
1079 : 1600927 : || pt->vars == NULL
1080 : : /* The pointed-to vars bitmap is shared, it is enough to
1081 : : visit it once. */
1082 : 3274737 : || visited->add (pt->vars))
1083 : 1375942 : return;
1084 : :
1085 : 297868 : bitmap_clear (temp);
1086 : :
1087 : : /* By using a temporary bitmap to store all members of the partitions
1088 : : we have to add we make sure to visit each of the partitions only
1089 : : once. */
1090 : 1324981 : EXECUTE_IF_SET_IN_BITMAP (pt->vars, 0, i, bi)
1091 : 1027113 : if ((!temp
1092 : 1027113 : || !bitmap_bit_p (temp, i))
1093 : 1654514 : && (part = decls_to_partitions->get (i)))
1094 : 185915 : bitmap_ior_into (temp, *part);
1095 : 297868 : if (!bitmap_empty_p (temp))
1096 : 156437 : bitmap_ior_into (pt->vars, temp);
1097 : : }
1098 : :
1099 : : /* Update points-to sets based on partition info, so we can use them on RTL.
1100 : : The bitmaps representing stack partitions will be saved until expand,
1101 : : where partitioned decls used as bases in memory expressions will be
1102 : : rewritten.
1103 : :
1104 : : It is not necessary to update TBAA info on accesses to the coalesced
1105 : : storage since our memory model doesn't allow TBAA to be used for
1106 : : WAW or WAR dependences. For RAW when the write is to an old object
1107 : : the new object would not have been initialized at the point of the
1108 : : read, invoking undefined behavior. */
1109 : :
1110 : : static void
1111 : 150262 : update_alias_info_with_stack_vars (void)
1112 : : {
1113 : 150262 : part_hashmap *decls_to_partitions = NULL;
1114 : 150262 : unsigned i, j;
1115 : 150262 : tree var = NULL_TREE;
1116 : :
1117 : 1272089 : for (i = 0; i < stack_vars_num; i++)
1118 : : {
1119 : 1121827 : bitmap part = NULL;
1120 : 1121827 : tree name;
1121 : 1121827 : struct ptr_info_def *pi;
1122 : :
1123 : : /* Not interested in partitions with single variable. */
1124 : 1121827 : if (stack_vars[i].representative != i
1125 : 853490 : || stack_vars[i].next == EOC)
1126 : 1048763 : continue;
1127 : :
1128 : 73064 : if (!decls_to_partitions)
1129 : : {
1130 : 45117 : decls_to_partitions = new part_hashmap;
1131 : 45117 : cfun->gimple_df->decls_to_pointers = new hash_map<tree, tree>;
1132 : : }
1133 : :
1134 : : /* Create an SSA_NAME that points to the partition for use
1135 : : as base during alias-oracle queries on RTL for bases that
1136 : : have been partitioned. */
1137 : 73064 : if (var == NULL_TREE)
1138 : 45117 : var = create_tmp_var (ptr_type_node);
1139 : 73064 : name = make_ssa_name (var);
1140 : :
1141 : : /* Create bitmaps representing partitions. They will be used for
1142 : : points-to sets later, so use GGC alloc. */
1143 : 73064 : part = BITMAP_GGC_ALLOC ();
1144 : 414465 : for (j = i; j != EOC; j = stack_vars[j].next)
1145 : : {
1146 : 341401 : tree decl = stack_vars[j].decl;
1147 : 341401 : unsigned int uid = DECL_PT_UID (decl);
1148 : 341401 : bitmap_set_bit (part, uid);
1149 : 341401 : decls_to_partitions->put (uid, part);
1150 : 341401 : cfun->gimple_df->decls_to_pointers->put (decl, name);
1151 : 341401 : if (TREE_ADDRESSABLE (decl))
1152 : 304975 : TREE_ADDRESSABLE (name) = 1;
1153 : : }
1154 : :
1155 : : /* Make the SSA name point to all partition members. */
1156 : 73064 : pi = get_ptr_info (name);
1157 : 73064 : pt_solution_set (&pi->pt, part, false);
1158 : : }
1159 : :
1160 : : /* Make all points-to sets that contain one member of a partition
1161 : : contain all members of the partition. */
1162 : 150262 : if (decls_to_partitions)
1163 : : {
1164 : 45117 : unsigned i;
1165 : 45117 : tree name;
1166 : 45117 : hash_set<bitmap> visited;
1167 : 45117 : bitmap temp = BITMAP_ALLOC (&stack_var_bitmap_obstack);
1168 : :
1169 : 16722305 : FOR_EACH_SSA_NAME (i, name, cfun)
1170 : : {
1171 : 10837965 : struct ptr_info_def *pi;
1172 : :
1173 : 19897706 : if (POINTER_TYPE_P (TREE_TYPE (name))
1174 : 10922711 : && ((pi = SSA_NAME_PTR_INFO (name)) != NULL))
1175 : 1583576 : add_partitioned_vars_to_ptset (&pi->pt, decls_to_partitions,
1176 : : &visited, temp);
1177 : : }
1178 : :
1179 : 45117 : add_partitioned_vars_to_ptset (&cfun->gimple_df->escaped,
1180 : : decls_to_partitions, &visited, temp);
1181 : 45117 : add_partitioned_vars_to_ptset (&cfun->gimple_df->escaped_return,
1182 : : decls_to_partitions, &visited, temp);
1183 : 45117 : delete decls_to_partitions;
1184 : 45117 : BITMAP_FREE (temp);
1185 : 45117 : }
1186 : 150262 : }
1187 : :
1188 : : /* A subroutine of partition_stack_vars. The UNION portion of a UNION/FIND
1189 : : partitioning algorithm. Partitions A and B are known to be non-conflicting.
1190 : : Merge them into a single partition A. */
1191 : :
1192 : : static void
1193 : 268337 : union_stack_vars (unsigned a, unsigned b)
1194 : : {
1195 : 268337 : class stack_var *vb = &stack_vars[b];
1196 : 268337 : bitmap_iterator bi;
1197 : 268337 : unsigned u;
1198 : :
1199 : 268337 : gcc_assert (stack_vars[b].next == EOC);
1200 : : /* Add B to A's partition. */
1201 : 268337 : stack_vars[b].next = stack_vars[a].next;
1202 : 268337 : stack_vars[b].representative = a;
1203 : 268337 : stack_vars[a].next = b;
1204 : :
1205 : : /* Make sure A is big enough to hold B. */
1206 : 268337 : stack_vars[a].size = upper_bound (stack_vars[a].size, stack_vars[b].size);
1207 : :
1208 : : /* Update the required alignment of partition A to account for B. */
1209 : 268337 : if (stack_vars[a].alignb < stack_vars[b].alignb)
1210 : 2628 : stack_vars[a].alignb = stack_vars[b].alignb;
1211 : :
1212 : : /* Update the interference graph and merge the conflicts. */
1213 : 268337 : if (vb->conflicts)
1214 : : {
1215 : 1673793 : EXECUTE_IF_SET_IN_BITMAP (vb->conflicts, 0, u, bi)
1216 : 1459934 : add_stack_var_conflict (a, stack_vars[u].representative);
1217 : 213859 : BITMAP_FREE (vb->conflicts);
1218 : : }
1219 : 268337 : }
1220 : :
1221 : : /* A subroutine of expand_used_vars. Binpack the variables into
1222 : : partitions constrained by the interference graph. The overall
1223 : : algorithm used is as follows:
1224 : :
1225 : : Sort the objects by size in descending order.
1226 : : For each object A {
1227 : : S = size(A)
1228 : : O = 0
1229 : : loop {
1230 : : Look for the largest non-conflicting object B with size <= S.
1231 : : UNION (A, B)
1232 : : }
1233 : : }
1234 : : */
1235 : :
1236 : : static void
1237 : 237493 : partition_stack_vars (void)
1238 : : {
1239 : 237493 : unsigned si, sj, n = stack_vars_num;
1240 : :
1241 : 237493 : stack_vars_sorted = XNEWVEC (unsigned, stack_vars_num);
1242 : 1446551 : for (si = 0; si < n; ++si)
1243 : 1209058 : stack_vars_sorted[si] = si;
1244 : :
1245 : 237493 : if (n == 1)
1246 : : return;
1247 : :
1248 : 150262 : qsort (stack_vars_sorted, n, sizeof (unsigned), stack_var_cmp);
1249 : :
1250 : 1272089 : for (si = 0; si < n; ++si)
1251 : : {
1252 : 1121827 : unsigned i = stack_vars_sorted[si];
1253 : 1121827 : unsigned int ialign = stack_vars[i].alignb;
1254 : 1121827 : poly_int64 isize = stack_vars[i].size;
1255 : :
1256 : : /* Ignore objects that aren't partition representatives. If we
1257 : : see a var that is not a partition representative, it must
1258 : : have been merged earlier. */
1259 : 1121827 : if (stack_vars[i].representative != i)
1260 : 268337 : continue;
1261 : :
1262 : 12730249 : for (sj = si + 1; sj < n; ++sj)
1263 : : {
1264 : 11877671 : unsigned j = stack_vars_sorted[sj];
1265 : 11877671 : unsigned int jalign = stack_vars[j].alignb;
1266 : 11877671 : poly_int64 jsize = stack_vars[j].size;
1267 : :
1268 : : /* Ignore objects that aren't partition representatives. */
1269 : 11877671 : if (stack_vars[j].representative != j)
1270 : 11876759 : continue;
1271 : :
1272 : : /* Do not mix objects of "small" (supported) alignment
1273 : : and "large" (unsupported) alignment. */
1274 : 11289270 : if ((ialign * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT)
1275 : 11289270 : != (jalign * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT))
1276 : : break;
1277 : :
1278 : : /* For Address Sanitizer do not mix objects with different
1279 : : sizes, as the shorter vars wouldn't be adequately protected.
1280 : : Don't do that for "large" (unsupported) alignment objects,
1281 : : those aren't protected anyway. */
1282 : 11289270 : if (asan_sanitize_stack_p ()
1283 : 4831 : && maybe_ne (isize, jsize)
1284 : 11290182 : && ialign * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT)
1285 : : break;
1286 : :
1287 : : /* Ignore conflicting objects. */
1288 : 11288358 : if (stack_var_conflict_p (i, j))
1289 : 11020021 : continue;
1290 : :
1291 : : /* UNION the objects, placing J at OFFSET. */
1292 : 268337 : union_stack_vars (i, j);
1293 : : }
1294 : : }
1295 : :
1296 : 150262 : update_alias_info_with_stack_vars ();
1297 : : }
1298 : :
1299 : : /* A debugging aid for expand_used_vars. Dump the generated partitions. */
1300 : :
1301 : : static void
1302 : 29 : dump_stack_var_partition (void)
1303 : : {
1304 : 29 : unsigned si, i, j, n = stack_vars_num;
1305 : :
1306 : 65 : for (si = 0; si < n; ++si)
1307 : : {
1308 : 36 : i = stack_vars_sorted[si];
1309 : :
1310 : : /* Skip variables that aren't partition representatives, for now. */
1311 : 36 : if (stack_vars[i].representative != i)
1312 : 3 : continue;
1313 : :
1314 : 33 : fprintf (dump_file, "Partition %u: size ", i);
1315 : 33 : print_dec (stack_vars[i].size, dump_file);
1316 : 33 : fprintf (dump_file, " align %u\n", stack_vars[i].alignb);
1317 : :
1318 : 102 : for (j = i; j != EOC; j = stack_vars[j].next)
1319 : : {
1320 : 36 : fputc ('\t', dump_file);
1321 : 36 : print_generic_expr (dump_file, stack_vars[j].decl, dump_flags);
1322 : : }
1323 : 33 : fputc ('\n', dump_file);
1324 : : }
1325 : 29 : }
1326 : :
1327 : : /* Assign rtl to DECL at BASE + OFFSET. */
1328 : :
1329 : : static void
1330 : 1996363 : expand_one_stack_var_at (tree decl, rtx base, unsigned base_align,
1331 : : poly_int64 offset)
1332 : : {
1333 : 1996363 : unsigned align;
1334 : 1996363 : rtx x;
1335 : :
1336 : : /* If this fails, we've overflowed the stack frame. Error nicely? */
1337 : 2281634 : gcc_assert (known_eq (offset, trunc_int_for_mode (offset, Pmode)));
1338 : :
1339 : 1996363 : if (hwasan_sanitize_stack_p ())
1340 : 85 : x = targetm.memtag.add_tag (base, offset,
1341 : 85 : hwasan_current_frame_tag ());
1342 : : else
1343 : 2281549 : x = plus_constant (Pmode, base, offset);
1344 : :
1345 : 3992726 : x = gen_rtx_MEM (TREE_CODE (decl) == SSA_NAME
1346 : 439627 : ? TYPE_MODE (TREE_TYPE (decl))
1347 : 1556736 : : DECL_MODE (decl), x);
1348 : :
1349 : : /* Set alignment we actually gave this decl if it isn't an SSA name.
1350 : : If it is we generate stack slots only accidentally so it isn't as
1351 : : important, we'll simply set the alignment directly on the MEM. */
1352 : :
1353 : 1996363 : if (stack_vars_base_reg_p (base))
1354 : 1993716 : offset -= frame_phase;
1355 : 1996363 : align = known_alignment (offset);
1356 : 1996363 : align *= BITS_PER_UNIT;
1357 : 1996363 : if (align == 0 || align > base_align)
1358 : 825607 : align = base_align;
1359 : :
1360 : 1996363 : if (TREE_CODE (decl) != SSA_NAME)
1361 : : {
1362 : : /* One would think that we could assert that we're not decreasing
1363 : : alignment here, but (at least) the i386 port does exactly this
1364 : : via the MINIMUM_ALIGNMENT hook. */
1365 : :
1366 : 1556736 : SET_DECL_ALIGN (decl, align);
1367 : 1556736 : DECL_USER_ALIGN (decl) = 0;
1368 : : }
1369 : :
1370 : 1996363 : set_rtl (decl, x);
1371 : :
1372 : 1996363 : set_mem_align (x, align);
1373 : 1996363 : }
1374 : :
1375 : 237493 : class stack_vars_data
1376 : : {
1377 : : public:
1378 : : /* Vector of offset pairs, always end of some padding followed
1379 : : by start of the padding that needs Address Sanitizer protection.
1380 : : The vector is in reversed, highest offset pairs come first. */
1381 : : auto_vec<HOST_WIDE_INT> asan_vec;
1382 : :
1383 : : /* Vector of partition representative decls in between the paddings. */
1384 : : auto_vec<tree> asan_decl_vec;
1385 : :
1386 : : /* Base pseudo register for Address Sanitizer protected automatic vars. */
1387 : : rtx asan_base;
1388 : :
1389 : : /* Alignment needed for the Address Sanitizer protected automatic vars. */
1390 : : unsigned int asan_alignb;
1391 : : };
1392 : :
1393 : : /* A subroutine of expand_used_vars. Give each partition representative
1394 : : a unique location within the stack frame. Update each partition member
1395 : : with that location. */
1396 : : static void
1397 : 239320 : expand_stack_vars (bool (*pred) (unsigned), class stack_vars_data *data)
1398 : : {
1399 : 239320 : unsigned si, i, j, n = stack_vars_num;
1400 : 239320 : poly_uint64 large_size = 0, large_alloc = 0;
1401 : 239320 : rtx large_base = NULL;
1402 : 239320 : rtx large_untagged_base = NULL;
1403 : 239320 : unsigned large_align = 0;
1404 : 239320 : bool large_allocation_done = false;
1405 : 239320 : tree decl;
1406 : :
1407 : : /* Determine if there are any variables requiring "large" alignment.
1408 : : Since these are dynamically allocated, we only process these if
1409 : : no predicate involved. */
1410 : 239320 : large_align = stack_vars[stack_vars_sorted[0]].alignb * BITS_PER_UNIT;
1411 : 239320 : if (pred == NULL && large_align > MAX_SUPPORTED_STACK_ALIGNMENT)
1412 : : {
1413 : : /* Find the total size of these variables. */
1414 : 0 : for (si = 0; si < n; ++si)
1415 : : {
1416 : 0 : unsigned alignb;
1417 : :
1418 : 0 : i = stack_vars_sorted[si];
1419 : 0 : alignb = stack_vars[i].alignb;
1420 : :
1421 : : /* All "large" alignment decls come before all "small" alignment
1422 : : decls, but "large" alignment decls are not sorted based on
1423 : : their alignment. Increase large_align to track the largest
1424 : : required alignment. */
1425 : 0 : if ((alignb * BITS_PER_UNIT) > large_align)
1426 : : large_align = alignb * BITS_PER_UNIT;
1427 : :
1428 : : /* Stop when we get to the first decl with "small" alignment. */
1429 : 0 : if (alignb * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT)
1430 : : break;
1431 : :
1432 : : /* Skip variables that aren't partition representatives. */
1433 : 0 : if (stack_vars[i].representative != i)
1434 : 0 : continue;
1435 : :
1436 : : /* Skip variables that have already had rtl assigned. See also
1437 : : add_stack_var where we perpetrate this pc_rtx hack. */
1438 : 0 : decl = stack_vars[i].decl;
1439 : 0 : if (TREE_CODE (decl) == SSA_NAME
1440 : 0 : ? SA.partition_to_pseudo[var_to_partition (SA.map, decl)] != NULL_RTX
1441 : 0 : : DECL_RTL (decl) != pc_rtx)
1442 : 0 : continue;
1443 : :
1444 : 0 : large_size = aligned_upper_bound (large_size, alignb);
1445 : 0 : large_size += stack_vars[i].size;
1446 : : }
1447 : : }
1448 : :
1449 : 1452185 : for (si = 0; si < n; ++si)
1450 : : {
1451 : 1212865 : rtx base;
1452 : 1212865 : unsigned base_align, alignb;
1453 : 1212865 : poly_int64 offset = 0;
1454 : :
1455 : 1212865 : i = stack_vars_sorted[si];
1456 : :
1457 : : /* Skip variables that aren't partition representatives, for now. */
1458 : 1212865 : if (stack_vars[i].representative != i)
1459 : 1481213 : continue;
1460 : :
1461 : : /* Skip variables that have already had rtl assigned. See also
1462 : : add_stack_var where we perpetrate this pc_rtx hack. */
1463 : 944517 : decl = stack_vars[i].decl;
1464 : 944517 : if (TREE_CODE (decl) == SSA_NAME
1465 : 944517 : ? SA.partition_to_pseudo[var_to_partition (SA.map, decl)] != NULL_RTX
1466 : 941103 : : DECL_RTL (decl) != pc_rtx)
1467 : 2901 : continue;
1468 : :
1469 : : /* Check the predicate to see whether this variable should be
1470 : : allocated in this pass. */
1471 : 941616 : if (pred && !pred (i))
1472 : 895 : continue;
1473 : :
1474 : 940721 : base = (hwasan_sanitize_stack_p ()
1475 : 940721 : ? hwasan_frame_base ()
1476 : 940665 : : virtual_stack_vars_rtx);
1477 : 940721 : alignb = stack_vars[i].alignb;
1478 : 940721 : if (alignb * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT)
1479 : : {
1480 : 940721 : poly_int64 hwasan_orig_offset;
1481 : 940721 : if (hwasan_sanitize_stack_p ())
1482 : : {
1483 : : /* There must be no tag granule "shared" between different
1484 : : objects. This means that no HWASAN_TAG_GRANULE_SIZE byte
1485 : : chunk can have more than one object in it.
1486 : :
1487 : : We ensure this by forcing the end of the last bit of data to
1488 : : be aligned to HWASAN_TAG_GRANULE_SIZE bytes here, and setting
1489 : : the start of each variable to be aligned to
1490 : : HWASAN_TAG_GRANULE_SIZE bytes in `align_local_variable`.
1491 : :
1492 : : We can't align just one of the start or end, since there are
1493 : : untagged things stored on the stack which we do not align to
1494 : : HWASAN_TAG_GRANULE_SIZE bytes. If we only aligned the start
1495 : : or the end of tagged objects then untagged objects could end
1496 : : up sharing the first granule of a tagged object or sharing the
1497 : : last granule of a tagged object respectively. */
1498 : 56 : hwasan_orig_offset = align_frame_offset (HWASAN_TAG_GRANULE_SIZE);
1499 : 56 : gcc_assert (stack_vars[i].alignb >= HWASAN_TAG_GRANULE_SIZE);
1500 : : }
1501 : : /* ASAN description strings don't yet have a syntax for expressing
1502 : : polynomial offsets. */
1503 : 940721 : HOST_WIDE_INT prev_offset;
1504 : 940721 : if (asan_sanitize_stack_p ()
1505 : 3244 : && pred
1506 : 2642 : && frame_offset.is_constant (&prev_offset)
1507 : 940721 : && stack_vars[i].size.is_constant ())
1508 : : {
1509 : 2642 : if (data->asan_vec.is_empty ())
1510 : : {
1511 : 1435 : align_frame_offset (ASAN_RED_ZONE_SIZE);
1512 : 1435 : prev_offset = frame_offset.to_constant ();
1513 : : }
1514 : 2642 : prev_offset = align_base (prev_offset,
1515 : : ASAN_MIN_RED_ZONE_SIZE,
1516 : : !FRAME_GROWS_DOWNWARD);
1517 : 2642 : tree repr_decl = NULL_TREE;
1518 : 2642 : unsigned HOST_WIDE_INT size
1519 : 2642 : = asan_var_and_redzone_size (stack_vars[i].size.to_constant ());
1520 : 2642 : if (data->asan_vec.is_empty ())
1521 : 1435 : size = MAX (size, ASAN_RED_ZONE_SIZE);
1522 : :
1523 : 2642 : unsigned HOST_WIDE_INT alignment = MAX (alignb,
1524 : : ASAN_MIN_RED_ZONE_SIZE);
1525 : 2642 : offset = alloc_stack_frame_space (size, alignment);
1526 : :
1527 : 2642 : data->asan_vec.safe_push (prev_offset);
1528 : : /* Allocating a constant amount of space from a constant
1529 : : starting offset must give a constant result. */
1530 : 2642 : data->asan_vec.safe_push ((offset + stack_vars[i].size)
1531 : 2642 : .to_constant ());
1532 : : /* Find best representative of the partition.
1533 : : Prefer those with DECL_NAME, even better
1534 : : satisfying asan_protect_stack_decl predicate. */
1535 : 3150 : for (j = i; j != EOC; j = stack_vars[j].next)
1536 : 2646 : if (asan_protect_stack_decl (stack_vars[j].decl)
1537 : 2646 : && DECL_NAME (stack_vars[j].decl))
1538 : : {
1539 : 2138 : repr_decl = stack_vars[j].decl;
1540 : 2138 : break;
1541 : : }
1542 : 508 : else if (repr_decl == NULL_TREE
1543 : 508 : && DECL_P (stack_vars[j].decl)
1544 : 1016 : && DECL_NAME (stack_vars[j].decl))
1545 : 0 : repr_decl = stack_vars[j].decl;
1546 : 2642 : if (repr_decl == NULL_TREE)
1547 : 504 : repr_decl = stack_vars[i].decl;
1548 : 2642 : data->asan_decl_vec.safe_push (repr_decl);
1549 : :
1550 : : /* Make sure a representative is unpoison if another
1551 : : variable in the partition is handled by
1552 : : use-after-scope sanitization. */
1553 : 2642 : if (asan_handled_variables != NULL
1554 : 2642 : && !asan_handled_variables->contains (repr_decl))
1555 : : {
1556 : 332 : for (j = i; j != EOC; j = stack_vars[j].next)
1557 : 168 : if (asan_handled_variables->contains (stack_vars[j].decl))
1558 : : break;
1559 : 166 : if (j != EOC)
1560 : 2 : asan_handled_variables->add (repr_decl);
1561 : : }
1562 : :
1563 : 2642 : data->asan_alignb = MAX (data->asan_alignb, alignb);
1564 : 2642 : if (data->asan_base == NULL)
1565 : 1435 : data->asan_base = gen_reg_rtx (Pmode);
1566 : 2642 : base = data->asan_base;
1567 : :
1568 : 2642 : if (!STRICT_ALIGNMENT)
1569 : 2642 : base_align = crtl->max_used_stack_slot_alignment;
1570 : : else
1571 : : base_align = MAX (crtl->max_used_stack_slot_alignment,
1572 : : GET_MODE_ALIGNMENT (SImode)
1573 : : << ASAN_SHADOW_SHIFT);
1574 : : }
1575 : : else
1576 : : {
1577 : 938079 : offset = alloc_stack_frame_space (stack_vars[i].size, alignb);
1578 : 938079 : base_align = crtl->max_used_stack_slot_alignment;
1579 : :
1580 : 938079 : if (hwasan_sanitize_stack_p ())
1581 : : {
1582 : : /* Align again since the point of this alignment is to handle
1583 : : the "end" of the object (i.e. smallest address after the
1584 : : stack object). For FRAME_GROWS_DOWNWARD that requires
1585 : : aligning the stack before allocating, but for a frame that
1586 : : grows upwards that requires aligning the stack after
1587 : : allocation.
1588 : :
1589 : : Use `frame_offset` to record the offset value rather than
1590 : : `offset` since the `frame_offset` describes the extent
1591 : : allocated for this particular variable while `offset`
1592 : : describes the address that this variable starts at. */
1593 : 56 : align_frame_offset (HWASAN_TAG_GRANULE_SIZE);
1594 : 56 : hwasan_record_stack_var (virtual_stack_vars_rtx, base,
1595 : : hwasan_orig_offset, frame_offset);
1596 : : }
1597 : : }
1598 : : }
1599 : : else
1600 : : {
1601 : : /* Large alignment is only processed in the last pass. */
1602 : 0 : if (pred)
1603 : 0 : continue;
1604 : :
1605 : : /* If there were any variables requiring "large" alignment, allocate
1606 : : space. */
1607 : 0 : if (maybe_ne (large_size, 0U) && ! large_allocation_done)
1608 : : {
1609 : 0 : poly_int64 loffset;
1610 : 0 : rtx large_allocsize;
1611 : :
1612 : 0 : large_allocsize = gen_int_mode (large_size, Pmode);
1613 : 0 : get_dynamic_stack_size (&large_allocsize, 0, large_align, NULL);
1614 : 0 : loffset = alloc_stack_frame_space
1615 : 0 : (rtx_to_poly_int64 (large_allocsize),
1616 : 0 : PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT);
1617 : 0 : large_base = get_dynamic_stack_base (loffset, large_align, base);
1618 : 0 : large_allocation_done = true;
1619 : : }
1620 : :
1621 : 0 : gcc_assert (large_base != NULL);
1622 : 0 : large_alloc = aligned_upper_bound (large_alloc, alignb);
1623 : 0 : offset = large_alloc;
1624 : 0 : large_alloc += stack_vars[i].size;
1625 : 0 : if (hwasan_sanitize_stack_p ())
1626 : : {
1627 : : /* An object with a large alignment requirement means that the
1628 : : alignment requirement is greater than the required alignment
1629 : : for tags. */
1630 : 0 : if (!large_untagged_base)
1631 : 0 : large_untagged_base
1632 : 0 : = targetm.memtag.untagged_pointer (large_base, NULL_RTX);
1633 : : /* Ensure the end of the variable is also aligned correctly. */
1634 : 0 : poly_int64 align_again
1635 : 0 : = aligned_upper_bound (large_alloc, HWASAN_TAG_GRANULE_SIZE);
1636 : : /* For large allocations we always allocate a chunk of space
1637 : : (which is addressed by large_untagged_base/large_base) and
1638 : : then use positive offsets from that. Hence the farthest
1639 : : offset is `align_again` and the nearest offset from the base
1640 : : is `offset`. */
1641 : 0 : hwasan_record_stack_var (large_untagged_base, large_base,
1642 : : offset, align_again);
1643 : : }
1644 : :
1645 : : base = large_base;
1646 : : base_align = large_align;
1647 : : }
1648 : :
1649 : : /* Create rtl for each variable based on their location within the
1650 : : partition. */
1651 : 2149779 : for (j = i; j != EOC; j = stack_vars[j].next)
1652 : : {
1653 : 1209058 : expand_one_stack_var_at (stack_vars[j].decl,
1654 : : base, base_align, offset);
1655 : : }
1656 : 940721 : if (hwasan_sanitize_stack_p ())
1657 : 56 : hwasan_increment_frame_tag ();
1658 : : }
1659 : :
1660 : 239320 : gcc_assert (known_eq (large_alloc, large_size));
1661 : 239320 : }
1662 : :
1663 : : /* Take into account all sizes of partitions and reset DECL_RTLs. */
1664 : : static poly_uint64
1665 : 1097339 : account_stack_vars (void)
1666 : : {
1667 : 1097339 : unsigned si, j, i, n = stack_vars_num;
1668 : 1097339 : poly_uint64 size = 0;
1669 : :
1670 : 5708788 : for (si = 0; si < n; ++si)
1671 : : {
1672 : 4611449 : i = stack_vars_sorted[si];
1673 : :
1674 : : /* Skip variables that aren't partition representatives, for now. */
1675 : 4611449 : if (stack_vars[i].representative != i)
1676 : 0 : continue;
1677 : :
1678 : 9222898 : size += stack_vars[i].size;
1679 : 9222898 : for (j = i; j != EOC; j = stack_vars[j].next)
1680 : 4611449 : set_rtl (stack_vars[j].decl, NULL);
1681 : : }
1682 : 1097339 : return size;
1683 : : }
1684 : :
1685 : : /* Record the RTL assignment X for the default def of PARM. */
1686 : :
1687 : : extern void
1688 : 4619104 : set_parm_rtl (tree parm, rtx x)
1689 : : {
1690 : 4619104 : gcc_assert (TREE_CODE (parm) == PARM_DECL
1691 : : || TREE_CODE (parm) == RESULT_DECL);
1692 : :
1693 : 4619104 : if (x && !MEM_P (x))
1694 : : {
1695 : 2999072 : unsigned int align = MINIMUM_ALIGNMENT (TREE_TYPE (parm),
1696 : : TYPE_MODE (TREE_TYPE (parm)),
1697 : : TYPE_ALIGN (TREE_TYPE (parm)));
1698 : :
1699 : : /* If the variable alignment is very large we'll dynamicaly
1700 : : allocate it, which means that in-frame portion is just a
1701 : : pointer. ??? We've got a pseudo for sure here, do we
1702 : : actually dynamically allocate its spilling area if needed?
1703 : : ??? Isn't it a problem when Pmode alignment also exceeds
1704 : : MAX_SUPPORTED_STACK_ALIGNMENT, as can happen on cris and lm32? */
1705 : 2999072 : if (align > MAX_SUPPORTED_STACK_ALIGNMENT)
1706 : 0 : align = GET_MODE_ALIGNMENT (Pmode);
1707 : :
1708 : 2999072 : record_alignment_for_reg_var (align);
1709 : : }
1710 : :
1711 : 4619104 : tree ssa = ssa_default_def (cfun, parm);
1712 : 4619104 : if (!ssa)
1713 : 1051470 : return set_rtl (parm, x);
1714 : :
1715 : 3567634 : int part = var_to_partition (SA.map, ssa);
1716 : 3567634 : gcc_assert (part != NO_PARTITION);
1717 : :
1718 : 3567634 : bool changed = bitmap_bit_p (SA.partitions_for_parm_default_defs, part);
1719 : 3567634 : gcc_assert (changed);
1720 : :
1721 : 3567634 : set_rtl (ssa, x);
1722 : 3567634 : gcc_assert (DECL_RTL (parm) == x);
1723 : : }
1724 : :
1725 : : /* A subroutine of expand_one_var. Called to immediately assign rtl
1726 : : to a variable to be allocated in the stack frame. */
1727 : :
1728 : : static void
1729 : 787305 : expand_one_stack_var_1 (tree var)
1730 : : {
1731 : 787305 : poly_uint64 size;
1732 : 787305 : poly_int64 offset;
1733 : 787305 : unsigned byte_align;
1734 : :
1735 : 787305 : if (TREE_CODE (var) == SSA_NAME)
1736 : : {
1737 : 436765 : tree type = TREE_TYPE (var);
1738 : 436765 : size = tree_to_poly_uint64 (TYPE_SIZE_UNIT (type));
1739 : : }
1740 : : else
1741 : 350540 : size = tree_to_poly_uint64 (DECL_SIZE_UNIT (var));
1742 : :
1743 : 787305 : byte_align = align_local_variable (var, true);
1744 : :
1745 : : /* We handle highly aligned variables in expand_stack_vars. */
1746 : 787305 : gcc_assert (byte_align * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT);
1747 : :
1748 : 787305 : rtx base;
1749 : 787305 : if (hwasan_sanitize_stack_p ())
1750 : : {
1751 : : /* Allocate zero bytes to align the stack. */
1752 : 29 : poly_int64 hwasan_orig_offset
1753 : 29 : = align_frame_offset (HWASAN_TAG_GRANULE_SIZE);
1754 : 29 : offset = alloc_stack_frame_space (size, byte_align);
1755 : 29 : align_frame_offset (HWASAN_TAG_GRANULE_SIZE);
1756 : 29 : base = hwasan_frame_base ();
1757 : : /* Use `frame_offset` to automatically account for machines where the
1758 : : frame grows upwards.
1759 : :
1760 : : `offset` will always point to the "start" of the stack object, which
1761 : : will be the smallest address, for ! FRAME_GROWS_DOWNWARD this is *not*
1762 : : the "furthest" offset from the base delimiting the current stack
1763 : : object. `frame_offset` will always delimit the extent that the frame.
1764 : : */
1765 : 29 : hwasan_record_stack_var (virtual_stack_vars_rtx, base,
1766 : : hwasan_orig_offset, frame_offset);
1767 : : }
1768 : : else
1769 : : {
1770 : 787276 : offset = alloc_stack_frame_space (size, byte_align);
1771 : 787276 : base = virtual_stack_vars_rtx;
1772 : : }
1773 : :
1774 : 787305 : expand_one_stack_var_at (var, base,
1775 : : crtl->max_used_stack_slot_alignment, offset);
1776 : :
1777 : 787305 : if (hwasan_sanitize_stack_p ())
1778 : 29 : hwasan_increment_frame_tag ();
1779 : 787305 : }
1780 : :
1781 : : /* Wrapper for expand_one_stack_var_1 that checks SSA_NAMEs are
1782 : : already assigned some MEM. */
1783 : :
1784 : : static void
1785 : 350540 : expand_one_stack_var (tree var)
1786 : : {
1787 : 350540 : if (TREE_CODE (var) == SSA_NAME)
1788 : : {
1789 : 0 : int part = var_to_partition (SA.map, var);
1790 : 0 : if (part != NO_PARTITION)
1791 : : {
1792 : 0 : rtx x = SA.partition_to_pseudo[part];
1793 : 0 : gcc_assert (x);
1794 : 0 : gcc_assert (MEM_P (x));
1795 : : return;
1796 : : }
1797 : : }
1798 : :
1799 : 350540 : return expand_one_stack_var_1 (var);
1800 : : }
1801 : :
1802 : : /* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL
1803 : : that will reside in a hard register. */
1804 : :
1805 : : static void
1806 : 1090 : expand_one_hard_reg_var (tree var)
1807 : : {
1808 : 0 : rest_of_decl_compilation (var, 0, 0);
1809 : 0 : }
1810 : :
1811 : : /* Record the alignment requirements of some variable assigned to a
1812 : : pseudo. */
1813 : :
1814 : : static void
1815 : 40522192 : record_alignment_for_reg_var (unsigned int align)
1816 : : {
1817 : 40522192 : if (SUPPORTS_STACK_ALIGNMENT
1818 : 40522192 : && crtl->stack_alignment_estimated < align)
1819 : : {
1820 : : /* stack_alignment_estimated shouldn't change after stack
1821 : : realign decision made */
1822 : 1691812 : gcc_assert (!crtl->stack_realign_processed);
1823 : 1691812 : crtl->stack_alignment_estimated = align;
1824 : : }
1825 : :
1826 : : /* stack_alignment_needed > PREFERRED_STACK_BOUNDARY is permitted.
1827 : : So here we only make sure stack_alignment_needed >= align. */
1828 : 40522192 : if (crtl->stack_alignment_needed < align)
1829 : 551078 : crtl->stack_alignment_needed = align;
1830 : 40522192 : if (crtl->max_used_stack_slot_alignment < align)
1831 : 551078 : crtl->max_used_stack_slot_alignment = align;
1832 : 40522192 : }
1833 : :
1834 : : /* Create RTL for an SSA partition. */
1835 : :
1836 : : static void
1837 : 22145580 : expand_one_ssa_partition (tree var)
1838 : : {
1839 : 22145580 : int part = var_to_partition (SA.map, var);
1840 : 22145580 : gcc_assert (part != NO_PARTITION);
1841 : :
1842 : 22145580 : if (SA.partition_to_pseudo[part])
1843 : : return;
1844 : :
1845 : 22145580 : unsigned int align = MINIMUM_ALIGNMENT (TREE_TYPE (var),
1846 : : TYPE_MODE (TREE_TYPE (var)),
1847 : : TYPE_ALIGN (TREE_TYPE (var)));
1848 : :
1849 : : /* If the variable alignment is very large we'll dynamicaly allocate
1850 : : it, which means that in-frame portion is just a pointer. */
1851 : 22145580 : if (align > MAX_SUPPORTED_STACK_ALIGNMENT)
1852 : 0 : align = GET_MODE_ALIGNMENT (Pmode);
1853 : :
1854 : 22145580 : record_alignment_for_reg_var (align);
1855 : :
1856 : 22145580 : if (!use_register_for_decl (var))
1857 : : {
1858 : 439627 : if (defer_stack_allocation (var, true))
1859 : 2862 : add_stack_var (var, true);
1860 : : else
1861 : 436765 : expand_one_stack_var_1 (var);
1862 : 439627 : return;
1863 : : }
1864 : :
1865 : 21705953 : machine_mode reg_mode = promote_ssa_mode (var, NULL);
1866 : 21705953 : rtx x = gen_reg_rtx (reg_mode);
1867 : :
1868 : 21705953 : set_rtl (var, x);
1869 : :
1870 : : /* For a promoted variable, X will not be used directly but wrapped in a
1871 : : SUBREG with SUBREG_PROMOTED_VAR_P set, which means that the RTL land
1872 : : will assume that its upper bits can be inferred from its lower bits.
1873 : : Therefore, if X isn't initialized on every path from the entry, then
1874 : : we must do it manually in order to fulfill the above assumption. */
1875 : 21705953 : if (reg_mode != TYPE_MODE (TREE_TYPE (var))
1876 : 21705953 : && bitmap_bit_p (SA.partitions_for_undefined_values, part))
1877 : 0 : emit_move_insn (x, CONST0_RTX (reg_mode));
1878 : : }
1879 : :
1880 : : /* Record the association between the RTL generated for partition PART
1881 : : and the underlying variable of the SSA_NAME VAR. */
1882 : :
1883 : : static void
1884 : 48519819 : adjust_one_expanded_partition_var (tree var)
1885 : : {
1886 : 48519819 : if (!var)
1887 : : return;
1888 : :
1889 : 48519819 : tree decl = SSA_NAME_VAR (var);
1890 : :
1891 : 48519819 : int part = var_to_partition (SA.map, var);
1892 : 48519819 : if (part == NO_PARTITION)
1893 : : return;
1894 : :
1895 : 31113142 : rtx x = SA.partition_to_pseudo[part];
1896 : :
1897 : 31113142 : gcc_assert (x);
1898 : :
1899 : 31113142 : set_rtl (var, x);
1900 : :
1901 : 31113142 : if (!REG_P (x))
1902 : : return;
1903 : :
1904 : : /* Note if the object is a user variable. */
1905 : 29161305 : if (decl && !DECL_ARTIFICIAL (decl))
1906 : 4176393 : mark_user_reg (x);
1907 : :
1908 : 29161305 : if (POINTER_TYPE_P (decl ? TREE_TYPE (decl) : TREE_TYPE (var)))
1909 : 7431189 : mark_reg_pointer (x, get_pointer_alignment (var));
1910 : : }
1911 : :
1912 : : /* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL
1913 : : that will reside in a pseudo register. */
1914 : :
1915 : : static void
1916 : 646100 : expand_one_register_var (tree var)
1917 : : {
1918 : 646100 : if (TREE_CODE (var) == SSA_NAME)
1919 : : {
1920 : 0 : int part = var_to_partition (SA.map, var);
1921 : 0 : if (part != NO_PARTITION)
1922 : : {
1923 : 0 : rtx x = SA.partition_to_pseudo[part];
1924 : 0 : gcc_assert (x);
1925 : 0 : gcc_assert (REG_P (x));
1926 : : return;
1927 : : }
1928 : 0 : gcc_unreachable ();
1929 : : }
1930 : :
1931 : 646100 : tree decl = var;
1932 : 646100 : tree type = TREE_TYPE (decl);
1933 : 646100 : machine_mode reg_mode = promote_decl_mode (decl, NULL);
1934 : 646100 : rtx x = gen_reg_rtx (reg_mode);
1935 : :
1936 : 646100 : set_rtl (var, x);
1937 : :
1938 : : /* Note if the object is a user variable. */
1939 : 646100 : if (!DECL_ARTIFICIAL (decl))
1940 : 122021 : mark_user_reg (x);
1941 : :
1942 : 646100 : if (POINTER_TYPE_P (type))
1943 : 173 : mark_reg_pointer (x, get_pointer_alignment (var));
1944 : : }
1945 : :
1946 : : /* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL that
1947 : : has some associated error, e.g. its type is error-mark. We just need
1948 : : to pick something that won't crash the rest of the compiler. */
1949 : :
1950 : : static void
1951 : 37 : expand_one_error_var (tree var)
1952 : : {
1953 : 37 : machine_mode mode = DECL_MODE (var);
1954 : 37 : rtx x;
1955 : :
1956 : 37 : if (mode == BLKmode)
1957 : 1 : x = gen_rtx_MEM (BLKmode, const0_rtx);
1958 : 36 : else if (mode == VOIDmode)
1959 : 0 : x = const0_rtx;
1960 : : else
1961 : 36 : x = gen_reg_rtx (mode);
1962 : :
1963 : 37 : SET_DECL_RTL (var, x);
1964 : 37 : }
1965 : :
1966 : : /* A subroutine of expand_one_var. VAR is a variable that will be
1967 : : allocated to the local stack frame. Return true if we wish to
1968 : : add VAR to STACK_VARS so that it will be coalesced with other
1969 : : variables. Return false to allocate VAR immediately.
1970 : :
1971 : : This function is used to reduce the number of variables considered
1972 : : for coalescing, which reduces the size of the quadratic problem. */
1973 : :
1974 : : static bool
1975 : 6740507 : defer_stack_allocation (tree var, bool toplevel)
1976 : : {
1977 : 6740507 : tree size_unit = TREE_CODE (var) == SSA_NAME
1978 : 6740507 : ? TYPE_SIZE_UNIT (TREE_TYPE (var))
1979 : 6740507 : : DECL_SIZE_UNIT (var);
1980 : 6740507 : poly_uint64 size;
1981 : :
1982 : : /* Whether the variable is small enough for immediate allocation not to be
1983 : : a problem with regard to the frame size. */
1984 : 6740507 : bool smallish
1985 : 6740507 : = (poly_int_tree_p (size_unit, &size)
1986 : 6740507 : && (estimated_poly_value (size)
1987 : 6740507 : < param_min_size_for_stack_sharing));
1988 : :
1989 : : /* If stack protection is enabled, *all* stack variables must be deferred,
1990 : : so that we can re-order the strings to the top of the frame.
1991 : : Similarly for Address Sanitizer. */
1992 : 6740507 : if (flag_stack_protect || asan_sanitize_stack_p ())
1993 : 10875 : return true;
1994 : :
1995 : 6729632 : unsigned int align = TREE_CODE (var) == SSA_NAME
1996 : 6729632 : ? TYPE_ALIGN (TREE_TYPE (var))
1997 : 6290560 : : DECL_ALIGN (var);
1998 : :
1999 : : /* We handle "large" alignment via dynamic allocation. We want to handle
2000 : : this extra complication in only one place, so defer them. */
2001 : : if (align > MAX_SUPPORTED_STACK_ALIGNMENT)
2002 : : return true;
2003 : :
2004 : 6729632 : bool ignored = TREE_CODE (var) == SSA_NAME
2005 : 6735770 : ? !SSAVAR (var) || DECL_IGNORED_P (SSA_NAME_VAR (var))
2006 : 6290560 : : DECL_IGNORED_P (var);
2007 : :
2008 : : /* When optimization is enabled, DECL_IGNORED_P variables originally scoped
2009 : : might be detached from their block and appear at toplevel when we reach
2010 : : here. We want to coalesce them with variables from other blocks when
2011 : : the immediate contribution to the frame size would be noticeable. */
2012 : 6729632 : if (toplevel && optimize > 0 && ignored && !smallish)
2013 : : return true;
2014 : :
2015 : : /* Variables declared in the outermost scope automatically conflict
2016 : : with every other variable. The only reason to want to defer them
2017 : : at all is that, after sorting, we can more efficiently pack
2018 : : small variables in the stack frame. Continue to defer at -O2. */
2019 : 5237732 : if (toplevel && optimize < 2)
2020 : : return false;
2021 : :
2022 : : /* Without optimization, *most* variables are allocated from the
2023 : : stack, which makes the quadratic problem large exactly when we
2024 : : want compilation to proceed as quickly as possible. On the
2025 : : other hand, we don't want the function's stack frame size to
2026 : : get completely out of hand. So we avoid adding scalars and
2027 : : "small" aggregates to the list at all. */
2028 : 4622965 : if (optimize == 0 && smallish)
2029 : : return false;
2030 : :
2031 : : return true;
2032 : : }
2033 : :
2034 : : /* A subroutine of expand_used_vars. Expand one variable according to
2035 : : its flavor. Variables to be placed on the stack are not actually
2036 : : expanded yet, merely recorded.
2037 : : When REALLY_EXPAND is false, only add stack values to be allocated.
2038 : : Return stack usage this variable is supposed to take.
2039 : : */
2040 : :
2041 : : static poly_uint64
2042 : 15671676 : expand_one_var (tree var, bool toplevel, bool really_expand,
2043 : : bitmap forced_stack_var = NULL)
2044 : : {
2045 : 15671676 : unsigned int align = BITS_PER_UNIT;
2046 : 15671676 : tree origvar = var;
2047 : :
2048 : 15671676 : var = SSAVAR (var);
2049 : :
2050 : 15671676 : if (TREE_TYPE (var) != error_mark_node && VAR_P (var))
2051 : : {
2052 : 15671676 : if (is_global_var (var))
2053 : 294136 : return 0;
2054 : :
2055 : : /* Because we don't know if VAR will be in register or on stack,
2056 : : we conservatively assume it will be on stack even if VAR is
2057 : : eventually put into register after RA pass. For non-automatic
2058 : : variables, which won't be on stack, we collect alignment of
2059 : : type and ignore user specified alignment. Similarly for
2060 : : SSA_NAMEs for which use_register_for_decl returns true. */
2061 : 15377540 : if (TREE_STATIC (var)
2062 : 15377540 : || DECL_EXTERNAL (var)
2063 : 30755080 : || (TREE_CODE (origvar) == SSA_NAME && use_register_for_decl (var)))
2064 : 0 : align = MINIMUM_ALIGNMENT (TREE_TYPE (var),
2065 : : TYPE_MODE (TREE_TYPE (var)),
2066 : : TYPE_ALIGN (TREE_TYPE (var)));
2067 : 15377540 : else if (DECL_HAS_VALUE_EXPR_P (var)
2068 : 15377540 : || (DECL_RTL_SET_P (var) && MEM_P (DECL_RTL (var))))
2069 : : /* Don't consider debug only variables with DECL_HAS_VALUE_EXPR_P set
2070 : : or variables which were assigned a stack slot already by
2071 : : expand_one_stack_var_at - in the latter case DECL_ALIGN has been
2072 : : changed from the offset chosen to it. */
2073 : 16106 : align = crtl->stack_alignment_estimated;
2074 : : else
2075 : 15361434 : align = MINIMUM_ALIGNMENT (var, DECL_MODE (var), DECL_ALIGN (var));
2076 : :
2077 : : /* If the variable alignment is very large we'll dynamicaly allocate
2078 : : it, which means that in-frame portion is just a pointer. */
2079 : 15377540 : if (align > MAX_SUPPORTED_STACK_ALIGNMENT)
2080 : 0 : align = GET_MODE_ALIGNMENT (Pmode);
2081 : : }
2082 : :
2083 : 15377540 : record_alignment_for_reg_var (align);
2084 : :
2085 : 15377540 : poly_uint64 size;
2086 : 15377540 : if (TREE_CODE (origvar) == SSA_NAME)
2087 : : {
2088 : 0 : gcc_assert (!VAR_P (var)
2089 : : || (!DECL_EXTERNAL (var)
2090 : : && !DECL_HAS_VALUE_EXPR_P (var)
2091 : : && !TREE_STATIC (var)
2092 : : && TREE_TYPE (var) != error_mark_node
2093 : : && !DECL_HARD_REGISTER (var)
2094 : : && really_expand));
2095 : : }
2096 : 15377540 : if (!VAR_P (var) && TREE_CODE (origvar) != SSA_NAME)
2097 : : ;
2098 : 15377540 : else if (DECL_EXTERNAL (var))
2099 : : ;
2100 : 15377540 : else if (DECL_HAS_VALUE_EXPR_P (var))
2101 : : ;
2102 : 15361579 : else if (TREE_STATIC (var))
2103 : : ;
2104 : 15361579 : else if (TREE_CODE (origvar) != SSA_NAME && DECL_RTL_SET_P (var))
2105 : : ;
2106 : 15361298 : else if (TREE_TYPE (var) == error_mark_node)
2107 : : {
2108 : 0 : if (really_expand)
2109 : 0 : expand_one_error_var (var);
2110 : : }
2111 : 15361298 : else if (VAR_P (var) && DECL_HARD_REGISTER (var))
2112 : : {
2113 : 4126 : if (really_expand)
2114 : : {
2115 : 1090 : expand_one_hard_reg_var (var);
2116 : 1090 : if (!DECL_HARD_REGISTER (var))
2117 : : /* Invalid register specification. */
2118 : 37 : expand_one_error_var (var);
2119 : : }
2120 : : }
2121 : 15357172 : else if (use_register_for_decl (var)
2122 : 15357172 : && (!forced_stack_var
2123 : 655962 : || !bitmap_bit_p (forced_stack_var, DECL_UID (var))))
2124 : : {
2125 : 9056292 : if (really_expand)
2126 : 646100 : expand_one_register_var (origvar);
2127 : : }
2128 : 6300880 : else if (!poly_int_tree_p (DECL_SIZE_UNIT (var), &size)
2129 : 6300880 : || !valid_constant_size_p (DECL_SIZE_UNIT (var)))
2130 : : {
2131 : : /* Reject variables which cover more than half of the address-space. */
2132 : 0 : if (really_expand)
2133 : : {
2134 : 0 : if (DECL_NONLOCAL_FRAME (var))
2135 : 0 : error_at (DECL_SOURCE_LOCATION (current_function_decl),
2136 : : "total size of local objects is too large");
2137 : : else
2138 : 0 : error_at (DECL_SOURCE_LOCATION (var),
2139 : : "size of variable %q+D is too large", var);
2140 : 0 : expand_one_error_var (var);
2141 : : }
2142 : : }
2143 : 6300880 : else if (defer_stack_allocation (var, toplevel))
2144 : 5817645 : add_stack_var (origvar, really_expand);
2145 : : else
2146 : : {
2147 : 483235 : if (really_expand)
2148 : : {
2149 : 350302 : if (lookup_attribute ("naked",
2150 : 350302 : DECL_ATTRIBUTES (current_function_decl)))
2151 : 0 : error ("cannot allocate stack for variable %q+D, naked function",
2152 : : var);
2153 : :
2154 : 350302 : expand_one_stack_var (origvar);
2155 : : }
2156 : 483235 : return size;
2157 : : }
2158 : 14894305 : return 0;
2159 : : }
2160 : :
2161 : : /* A subroutine of expand_used_vars. Walk down through the BLOCK tree
2162 : : expanding variables. Those variables that can be put into registers
2163 : : are allocated pseudos; those that can't are put on the stack.
2164 : :
2165 : : TOPLEVEL is true if this is the outermost BLOCK. */
2166 : :
2167 : : static void
2168 : 17087983 : expand_used_vars_for_block (tree block, bool toplevel, bitmap forced_stack_vars)
2169 : : {
2170 : 17087983 : tree t;
2171 : :
2172 : : /* Expand all variables at this level. */
2173 : 36287909 : for (t = BLOCK_VARS (block); t ; t = DECL_CHAIN (t))
2174 : 19199926 : if (TREE_USED (t)
2175 : 19199926 : && ((!VAR_P (t) && TREE_CODE (t) != RESULT_DECL)
2176 : 799984 : || !DECL_NONSHAREABLE (t)))
2177 : 799984 : expand_one_var (t, toplevel, true, forced_stack_vars);
2178 : :
2179 : : /* Expand all variables at containing levels. */
2180 : 32725337 : for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t))
2181 : 15637354 : expand_used_vars_for_block (t, false, forced_stack_vars);
2182 : 17087983 : }
2183 : :
2184 : : /* A subroutine of expand_used_vars. Walk down through the BLOCK tree
2185 : : and clear TREE_USED on all local variables. */
2186 : :
2187 : : static void
2188 : 17087983 : clear_tree_used (tree block)
2189 : : {
2190 : 17087983 : tree t;
2191 : :
2192 : 36287909 : for (t = BLOCK_VARS (block); t ; t = DECL_CHAIN (t))
2193 : : /* if (!TREE_STATIC (t) && !DECL_EXTERNAL (t)) */
2194 : 1192411 : if ((!VAR_P (t) && TREE_CODE (t) != RESULT_DECL)
2195 : 19199926 : || !DECL_NONSHAREABLE (t))
2196 : 19199926 : TREE_USED (t) = 0;
2197 : :
2198 : 32725337 : for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t))
2199 : 15637354 : clear_tree_used (t);
2200 : 17087983 : }
2201 : :
2202 : : /* Examine TYPE and determine a bit mask of the following features. */
2203 : :
2204 : : #define SPCT_HAS_LARGE_CHAR_ARRAY 1
2205 : : #define SPCT_HAS_SMALL_CHAR_ARRAY 2
2206 : : #define SPCT_HAS_ARRAY 4
2207 : : #define SPCT_HAS_AGGREGATE 8
2208 : :
2209 : : static unsigned int
2210 : 2623 : stack_protect_classify_type (tree type)
2211 : : {
2212 : 2623 : unsigned int ret = 0;
2213 : 2623 : tree t;
2214 : :
2215 : 2623 : switch (TREE_CODE (type))
2216 : : {
2217 : 623 : case ARRAY_TYPE:
2218 : 623 : t = TYPE_MAIN_VARIANT (TREE_TYPE (type));
2219 : 623 : if (t == char_type_node
2220 : 175 : || t == signed_char_type_node
2221 : 175 : || t == unsigned_char_type_node)
2222 : : {
2223 : 448 : unsigned HOST_WIDE_INT max = param_ssp_buffer_size;
2224 : 448 : unsigned HOST_WIDE_INT len;
2225 : :
2226 : 448 : if (!TYPE_SIZE_UNIT (type)
2227 : 448 : || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type)))
2228 : : len = max;
2229 : : else
2230 : 448 : len = tree_to_uhwi (TYPE_SIZE_UNIT (type));
2231 : :
2232 : 448 : if (len < max)
2233 : : ret = SPCT_HAS_SMALL_CHAR_ARRAY | SPCT_HAS_ARRAY;
2234 : : else
2235 : 424 : ret = SPCT_HAS_LARGE_CHAR_ARRAY | SPCT_HAS_ARRAY;
2236 : : }
2237 : : else
2238 : : ret = SPCT_HAS_ARRAY;
2239 : : break;
2240 : :
2241 : 1010 : case UNION_TYPE:
2242 : 1010 : case QUAL_UNION_TYPE:
2243 : 1010 : case RECORD_TYPE:
2244 : 1010 : ret = SPCT_HAS_AGGREGATE;
2245 : 10875 : for (t = TYPE_FIELDS (type); t ; t = TREE_CHAIN (t))
2246 : 9865 : if (TREE_CODE (t) == FIELD_DECL)
2247 : 1673 : ret |= stack_protect_classify_type (TREE_TYPE (t));
2248 : : break;
2249 : :
2250 : : default:
2251 : : break;
2252 : : }
2253 : :
2254 : 2623 : return ret;
2255 : : }
2256 : :
2257 : : /* Return nonzero if DECL should be segregated into the "vulnerable" upper
2258 : : part of the local stack frame. Remember if we ever return nonzero for
2259 : : any variable in this function. The return value is the phase number in
2260 : : which the variable should be allocated. */
2261 : :
2262 : : static int
2263 : 950 : stack_protect_decl_phase (tree decl)
2264 : : {
2265 : 950 : unsigned int bits = stack_protect_classify_type (TREE_TYPE (decl));
2266 : 950 : int ret = 0;
2267 : :
2268 : 950 : if (bits & SPCT_HAS_SMALL_CHAR_ARRAY)
2269 : 24 : has_short_buffer = true;
2270 : :
2271 : 950 : tree attribs = DECL_ATTRIBUTES (current_function_decl);
2272 : 950 : if (!lookup_attribute ("no_stack_protector", attribs)
2273 : 950 : && (flag_stack_protect == SPCT_FLAG_ALL
2274 : 950 : || flag_stack_protect == SPCT_FLAG_STRONG
2275 : 151 : || (flag_stack_protect == SPCT_FLAG_EXPLICIT
2276 : 5 : && lookup_attribute ("stack_protect", attribs))))
2277 : : {
2278 : 804 : if ((bits & (SPCT_HAS_SMALL_CHAR_ARRAY | SPCT_HAS_LARGE_CHAR_ARRAY))
2279 : 344 : && !(bits & SPCT_HAS_AGGREGATE))
2280 : : ret = 1;
2281 : 748 : else if (bits & SPCT_HAS_ARRAY)
2282 : : ret = 2;
2283 : : }
2284 : : else
2285 : 146 : ret = (bits & SPCT_HAS_LARGE_CHAR_ARRAY) != 0;
2286 : :
2287 : 146 : if (ret)
2288 : 613 : has_protected_decls = true;
2289 : :
2290 : 950 : return ret;
2291 : : }
2292 : :
2293 : : /* Two helper routines that check for phase 1 and phase 2. These are used
2294 : : as callbacks for expand_stack_vars. */
2295 : :
2296 : : static bool
2297 : 308 : stack_protect_decl_phase_1 (unsigned i)
2298 : : {
2299 : 308 : return stack_protect_decl_phase (stack_vars[i].decl) == 1;
2300 : : }
2301 : :
2302 : : static bool
2303 : 216 : stack_protect_decl_phase_2 (unsigned i)
2304 : : {
2305 : 216 : return stack_protect_decl_phase (stack_vars[i].decl) == 2;
2306 : : }
2307 : :
2308 : : /* And helper function that checks for asan phase (with stack protector
2309 : : it is phase 3). This is used as callback for expand_stack_vars.
2310 : : Returns true if any of the vars in the partition need to be protected. */
2311 : :
2312 : : static bool
2313 : 3160 : asan_decl_phase_3 (unsigned i)
2314 : : {
2315 : 3762 : while (i != EOC)
2316 : : {
2317 : 3160 : if (asan_protect_stack_decl (stack_vars[i].decl))
2318 : : return true;
2319 : 602 : i = stack_vars[i].next;
2320 : : }
2321 : : return false;
2322 : : }
2323 : :
2324 : : /* Ensure that variables in different stack protection phases conflict
2325 : : so that they are not merged and share the same stack slot.
2326 : : Return true if there are any address taken variables. */
2327 : :
2328 : : static bool
2329 : 222 : add_stack_protection_conflicts (void)
2330 : : {
2331 : 222 : unsigned i, j, n = stack_vars_num;
2332 : 222 : unsigned char *phase;
2333 : 222 : bool ret = false;
2334 : :
2335 : 222 : phase = XNEWVEC (unsigned char, n);
2336 : 870 : for (i = 0; i < n; ++i)
2337 : : {
2338 : 426 : phase[i] = stack_protect_decl_phase (stack_vars[i].decl);
2339 : 426 : if (TREE_ADDRESSABLE (stack_vars[i].decl))
2340 : 351 : ret = true;
2341 : : }
2342 : :
2343 : 648 : for (i = 0; i < n; ++i)
2344 : : {
2345 : 426 : unsigned char ph_i = phase[i];
2346 : 1135 : for (j = i + 1; j < n; ++j)
2347 : 709 : if (ph_i != phase[j])
2348 : 322 : add_stack_var_conflict (i, j);
2349 : : }
2350 : :
2351 : 222 : XDELETEVEC (phase);
2352 : 222 : return ret;
2353 : : }
2354 : :
2355 : : /* Create a decl for the guard at the top of the stack frame. */
2356 : :
2357 : : static void
2358 : 238 : create_stack_guard (void)
2359 : : {
2360 : 238 : tree guard = build_decl (DECL_SOURCE_LOCATION (current_function_decl),
2361 : : VAR_DECL, NULL, ptr_type_node);
2362 : 238 : TREE_THIS_VOLATILE (guard) = 1;
2363 : 238 : TREE_USED (guard) = 1;
2364 : 238 : expand_one_stack_var (guard);
2365 : 238 : crtl->stack_protect_guard = guard;
2366 : 238 : }
2367 : :
2368 : : /* Prepare for expanding variables. */
2369 : : static void
2370 : 7743523 : init_vars_expansion (void)
2371 : : {
2372 : : /* Conflict bitmaps, and a few related temporary bitmaps, go here. */
2373 : 7743523 : bitmap_obstack_initialize (&stack_var_bitmap_obstack);
2374 : :
2375 : : /* A map from decl to stack partition. */
2376 : 7743523 : decl_to_stack_part = new hash_map<tree, unsigned>;
2377 : :
2378 : : /* Initialize local stack smashing state. */
2379 : 7743523 : has_protected_decls = false;
2380 : 7743523 : has_short_buffer = false;
2381 : 7743523 : if (hwasan_sanitize_stack_p ())
2382 : 1190 : hwasan_record_frame_init ();
2383 : 7743523 : }
2384 : :
2385 : : /* Free up stack variable graph data. */
2386 : : static void
2387 : 7743523 : fini_vars_expansion (void)
2388 : : {
2389 : 7743523 : bitmap_obstack_release (&stack_var_bitmap_obstack);
2390 : 7743523 : if (stack_vars)
2391 : 1334832 : XDELETEVEC (stack_vars);
2392 : 7743523 : if (stack_vars_sorted)
2393 : 1334832 : XDELETEVEC (stack_vars_sorted);
2394 : 7743523 : stack_vars = NULL;
2395 : 7743523 : stack_vars_sorted = NULL;
2396 : 7743523 : stack_vars_alloc = stack_vars_num = 0;
2397 : 15487046 : delete decl_to_stack_part;
2398 : 7743523 : decl_to_stack_part = NULL;
2399 : 7743523 : }
2400 : :
2401 : : /* Make a fair guess for the size of the stack frame of the function
2402 : : in NODE. This doesn't have to be exact, the result is only used in
2403 : : the inline heuristics. So we don't want to run the full stack var
2404 : : packing algorithm (which is quadratic in the number of stack vars).
2405 : : Instead, we calculate the total size of all stack vars. This turns
2406 : : out to be a pretty fair estimate -- packing of stack vars doesn't
2407 : : happen very often. */
2408 : :
2409 : : HOST_WIDE_INT
2410 : 6292894 : estimated_stack_frame_size (struct cgraph_node *node)
2411 : : {
2412 : 6292894 : poly_int64 size = 0;
2413 : 6292894 : unsigned i;
2414 : 6292894 : tree var;
2415 : 6292894 : struct function *fn = DECL_STRUCT_FUNCTION (node->decl);
2416 : :
2417 : 6292894 : push_cfun (fn);
2418 : :
2419 : 6292894 : init_vars_expansion ();
2420 : :
2421 : 25158181 : FOR_EACH_LOCAL_DECL (fn, i, var)
2422 : 13729460 : if (auto_var_in_fn_p (var, fn->decl))
2423 : 13157732 : size += expand_one_var (var, true, false);
2424 : :
2425 : 6292894 : if (stack_vars_num > 0)
2426 : : {
2427 : : /* Fake sorting the stack vars for account_stack_vars (). */
2428 : 1097339 : stack_vars_sorted = XNEWVEC (unsigned , stack_vars_num);
2429 : 5708788 : for (i = 0; i < stack_vars_num; ++i)
2430 : 4611449 : stack_vars_sorted[i] = i;
2431 : 1097339 : size += account_stack_vars ();
2432 : : }
2433 : :
2434 : 6292894 : fini_vars_expansion ();
2435 : 6292894 : pop_cfun ();
2436 : 6292894 : return estimated_poly_value (size);
2437 : : }
2438 : :
2439 : : /* Check if the current function has calls that use a return slot. */
2440 : :
2441 : : static bool
2442 : 417 : stack_protect_return_slot_p ()
2443 : : {
2444 : 417 : basic_block bb;
2445 : :
2446 : 1859 : FOR_ALL_BB_FN (bb, cfun)
2447 : 2942 : for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
2448 : 3962 : !gsi_end_p (gsi); gsi_next (&gsi))
2449 : : {
2450 : 2520 : gimple *stmt = gsi_stmt (gsi);
2451 : : /* This assumes that calls to internal-only functions never
2452 : : use a return slot. */
2453 : 2520 : if (is_gimple_call (stmt)
2454 : 534 : && !gimple_call_internal_p (stmt)
2455 : 3045 : && aggregate_value_p (TREE_TYPE (gimple_call_fntype (stmt)),
2456 : 525 : gimple_call_fndecl (stmt)))
2457 : 417 : return true;
2458 : : }
2459 : : return false;
2460 : : }
2461 : :
2462 : : /* Expand all variables used in the function. */
2463 : :
2464 : : static rtx_insn *
2465 : 1450629 : expand_used_vars (bitmap forced_stack_vars)
2466 : : {
2467 : 1450629 : tree var, outer_block = DECL_INITIAL (current_function_decl);
2468 : 1450629 : auto_vec<tree> maybe_local_decls;
2469 : 1450629 : rtx_insn *var_end_seq = NULL;
2470 : 1450629 : unsigned i;
2471 : 1450629 : unsigned len;
2472 : 1450629 : bool gen_stack_protect_signal = false;
2473 : :
2474 : : /* Compute the phase of the stack frame for this function. */
2475 : 1450629 : {
2476 : 1450629 : int align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
2477 : 1450629 : int off = targetm.starting_frame_offset () % align;
2478 : 1450629 : frame_phase = off ? align - off : 0;
2479 : : }
2480 : :
2481 : : /* Set TREE_USED on all variables in the local_decls. */
2482 : 10460872 : FOR_EACH_LOCAL_DECL (cfun, i, var)
2483 : 7793874 : TREE_USED (var) = 1;
2484 : : /* Clear TREE_USED on all variables associated with a block scope. */
2485 : 1450629 : clear_tree_used (DECL_INITIAL (current_function_decl));
2486 : :
2487 : 1450629 : init_vars_expansion ();
2488 : :
2489 : 1450629 : if (targetm.use_pseudo_pic_reg ())
2490 : 79508 : pic_offset_table_rtx = gen_reg_rtx (Pmode);
2491 : :
2492 : 27163843 : for (i = 0; i < SA.map->num_partitions; i++)
2493 : : {
2494 : 25713214 : if (bitmap_bit_p (SA.partitions_for_parm_default_defs, i))
2495 : 3567634 : continue;
2496 : :
2497 : 22145580 : tree var = partition_to_var (SA.map, i);
2498 : :
2499 : 44291160 : gcc_assert (!virtual_operand_p (var));
2500 : :
2501 : 22145580 : expand_one_ssa_partition (var);
2502 : : }
2503 : :
2504 : 1450629 : if (flag_stack_protect == SPCT_FLAG_STRONG)
2505 : 417 : gen_stack_protect_signal = stack_protect_return_slot_p ();
2506 : :
2507 : : /* At this point all variables on the local_decls with TREE_USED
2508 : : set are not associated with any block scope. Lay them out. */
2509 : :
2510 : 1450629 : len = vec_safe_length (cfun->local_decls);
2511 : 9244503 : FOR_EACH_LOCAL_DECL (cfun, i, var)
2512 : : {
2513 : 7793874 : bool expand_now = false;
2514 : :
2515 : : /* Expanded above already. */
2516 : 7793874 : if (is_gimple_reg (var))
2517 : : {
2518 : 5363421 : TREE_USED (var) = 0;
2519 : 5363421 : goto next;
2520 : : }
2521 : : /* We didn't set a block for static or extern because it's hard
2522 : : to tell the difference between a global variable (re)declared
2523 : : in a local scope, and one that's really declared there to
2524 : : begin with. And it doesn't really matter much, since we're
2525 : : not giving them stack space. Expand them now. */
2526 : 2430453 : else if (TREE_STATIC (var) || DECL_EXTERNAL (var))
2527 : : expand_now = true;
2528 : :
2529 : : /* Expand variables not associated with any block now. Those created by
2530 : : the optimizers could be live anywhere in the function. Those that
2531 : : could possibly have been scoped originally and detached from their
2532 : : block will have their allocation deferred so we coalesce them with
2533 : : others when optimization is enabled. */
2534 : 2219808 : else if (TREE_USED (var))
2535 : 1713960 : expand_now = true;
2536 : :
2537 : : /* Finally, mark all variables on the list as used. We'll use
2538 : : this in a moment when we expand those associated with scopes. */
2539 : 2430453 : TREE_USED (var) = 1;
2540 : :
2541 : 2430453 : if (expand_now)
2542 : 1713960 : expand_one_var (var, true, true, forced_stack_vars);
2543 : :
2544 : 716493 : next:
2545 : 7793874 : if (DECL_ARTIFICIAL (var) && !DECL_IGNORED_P (var))
2546 : : {
2547 : 425465 : rtx rtl = DECL_RTL_IF_SET (var);
2548 : :
2549 : : /* Keep artificial non-ignored vars in cfun->local_decls
2550 : : chain until instantiate_decls. */
2551 : 320355 : if (rtl && (MEM_P (rtl) || GET_CODE (rtl) == CONCAT))
2552 : 18933 : add_local_decl (cfun, var);
2553 : 105110 : else if (rtl == NULL_RTX)
2554 : : /* If rtl isn't set yet, which can happen e.g. with
2555 : : -fstack-protector, retry before returning from this
2556 : : function. */
2557 : 105110 : maybe_local_decls.safe_push (var);
2558 : : }
2559 : : }
2560 : :
2561 : : /* We duplicated some of the decls in CFUN->LOCAL_DECLS.
2562 : :
2563 : : +-----------------+-----------------+
2564 : : | ...processed... | ...duplicates...|
2565 : : +-----------------+-----------------+
2566 : : ^
2567 : : +-- LEN points here.
2568 : :
2569 : : We just want the duplicates, as those are the artificial
2570 : : non-ignored vars that we want to keep until instantiate_decls.
2571 : : Move them down and truncate the array. */
2572 : 1450629 : if (!vec_safe_is_empty (cfun->local_decls))
2573 : 819963 : cfun->local_decls->block_remove (0, len);
2574 : :
2575 : : /* At this point, all variables within the block tree with TREE_USED
2576 : : set are actually used by the optimized function. Lay them out. */
2577 : 1450629 : expand_used_vars_for_block (outer_block, true, forced_stack_vars);
2578 : :
2579 : 1450629 : tree attribs = DECL_ATTRIBUTES (current_function_decl);
2580 : 1450629 : if (stack_vars_num > 0)
2581 : : {
2582 : 237493 : bool has_addressable_vars = false;
2583 : :
2584 : 237493 : add_scope_conflicts ();
2585 : :
2586 : : /* If stack protection is enabled, we don't share space between
2587 : : vulnerable data and non-vulnerable data. */
2588 : 237493 : if (flag_stack_protect != 0
2589 : 222 : && !lookup_attribute ("no_stack_protector", attribs)
2590 : 237715 : && (flag_stack_protect != SPCT_FLAG_EXPLICIT
2591 : : || (flag_stack_protect == SPCT_FLAG_EXPLICIT
2592 : 1 : && lookup_attribute ("stack_protect", attribs))))
2593 : 222 : has_addressable_vars = add_stack_protection_conflicts ();
2594 : :
2595 : 237493 : if (flag_stack_protect == SPCT_FLAG_STRONG && has_addressable_vars)
2596 : 237493 : gen_stack_protect_signal = true;
2597 : :
2598 : : /* Now that we have collected all stack variables, and have computed a
2599 : : minimal interference graph, attempt to save some stack space. */
2600 : 237493 : partition_stack_vars ();
2601 : 237493 : if (dump_file)
2602 : 29 : dump_stack_var_partition ();
2603 : : }
2604 : :
2605 : :
2606 : 1450629 : if (!lookup_attribute ("no_stack_protector", attribs))
2607 : 1450620 : switch (flag_stack_protect)
2608 : : {
2609 : 19 : case SPCT_FLAG_ALL:
2610 : 19 : create_stack_guard ();
2611 : 19 : break;
2612 : :
2613 : 417 : case SPCT_FLAG_STRONG:
2614 : 417 : if (gen_stack_protect_signal
2615 : 273 : || cfun->calls_alloca
2616 : 271 : || has_protected_decls
2617 : 680 : || lookup_attribute ("stack_protect", attribs))
2618 : 154 : create_stack_guard ();
2619 : : break;
2620 : :
2621 : 140 : case SPCT_FLAG_DEFAULT:
2622 : 140 : if (cfun->calls_alloca
2623 : 137 : || has_protected_decls
2624 : 225 : || lookup_attribute ("stack_protect", attribs))
2625 : 55 : create_stack_guard ();
2626 : : break;
2627 : :
2628 : 14 : case SPCT_FLAG_EXPLICIT:
2629 : 14 : if (lookup_attribute ("stack_protect", attribs))
2630 : 10 : create_stack_guard ();
2631 : : break;
2632 : :
2633 : : default:
2634 : : break;
2635 : : }
2636 : :
2637 : : /* Assign rtl to each variable based on these partitions. */
2638 : 1450629 : if (stack_vars_num > 0)
2639 : : {
2640 : 237493 : class stack_vars_data data;
2641 : :
2642 : 237493 : data.asan_base = NULL_RTX;
2643 : 237493 : data.asan_alignb = 0;
2644 : :
2645 : : /* Reorder decls to be protected by iterating over the variables
2646 : : array multiple times, and allocating out of each phase in turn. */
2647 : : /* ??? We could probably integrate this into the qsort we did
2648 : : earlier, such that we naturally see these variables first,
2649 : : and thus naturally allocate things in the right order. */
2650 : 237493 : if (has_protected_decls)
2651 : : {
2652 : : /* Phase 1 contains only character arrays. */
2653 : 128 : expand_stack_vars (stack_protect_decl_phase_1, &data);
2654 : :
2655 : : /* Phase 2 contains other kinds of arrays. */
2656 : 128 : if (!lookup_attribute ("no_stack_protector", attribs)
2657 : 128 : && (flag_stack_protect == SPCT_FLAG_ALL
2658 : 128 : || flag_stack_protect == SPCT_FLAG_STRONG
2659 : 53 : || (flag_stack_protect == SPCT_FLAG_EXPLICIT
2660 : 1 : && lookup_attribute ("stack_protect", attribs))))
2661 : 76 : expand_stack_vars (stack_protect_decl_phase_2, &data);
2662 : : }
2663 : :
2664 : 237493 : if (asan_sanitize_stack_p ())
2665 : : /* Phase 3, any partitions that need asan protection
2666 : : in addition to phase 1 and 2. */
2667 : 1623 : expand_stack_vars (asan_decl_phase_3, &data);
2668 : :
2669 : : /* ASAN description strings don't yet have a syntax for expressing
2670 : : polynomial offsets. */
2671 : 237493 : HOST_WIDE_INT prev_offset;
2672 : 238928 : if (!data.asan_vec.is_empty ()
2673 : 1435 : && frame_offset.is_constant (&prev_offset))
2674 : : {
2675 : 1435 : HOST_WIDE_INT offset, sz, redzonesz;
2676 : 1435 : redzonesz = ASAN_RED_ZONE_SIZE;
2677 : 1435 : sz = data.asan_vec[0] - prev_offset;
2678 : 1435 : if (data.asan_alignb > ASAN_RED_ZONE_SIZE
2679 : 1435 : && data.asan_alignb <= 4096
2680 : 45 : && sz + ASAN_RED_ZONE_SIZE >= (int) data.asan_alignb)
2681 : 45 : redzonesz = ((sz + ASAN_RED_ZONE_SIZE + data.asan_alignb - 1)
2682 : 45 : & ~(data.asan_alignb - HOST_WIDE_INT_1)) - sz;
2683 : : /* Allocating a constant amount of space from a constant
2684 : : starting offset must give a constant result. */
2685 : 1435 : offset = (alloc_stack_frame_space (redzonesz, ASAN_RED_ZONE_SIZE)
2686 : 1435 : .to_constant ());
2687 : 1435 : data.asan_vec.safe_push (prev_offset);
2688 : 1435 : data.asan_vec.safe_push (offset);
2689 : : /* Leave space for alignment if STRICT_ALIGNMENT. */
2690 : 1435 : if (STRICT_ALIGNMENT)
2691 : : alloc_stack_frame_space ((GET_MODE_ALIGNMENT (SImode)
2692 : : << ASAN_SHADOW_SHIFT)
2693 : : / BITS_PER_UNIT, 1);
2694 : :
2695 : 1435 : var_end_seq
2696 : 2870 : = asan_emit_stack_protection (virtual_stack_vars_rtx,
2697 : : data.asan_base,
2698 : : data.asan_alignb,
2699 : : data.asan_vec.address (),
2700 : : data.asan_decl_vec.address (),
2701 : 1435 : data.asan_vec.length ());
2702 : : }
2703 : :
2704 : 237493 : expand_stack_vars (NULL, &data);
2705 : 237493 : }
2706 : :
2707 : 1450629 : if (hwasan_sanitize_stack_p ())
2708 : 446 : hwasan_emit_prologue ();
2709 : 1450629 : if (asan_sanitize_allocas_p () && cfun->calls_alloca)
2710 : 178 : var_end_seq = asan_emit_allocas_unpoison (virtual_stack_dynamic_rtx,
2711 : : virtual_stack_vars_rtx,
2712 : : var_end_seq);
2713 : 1450451 : else if (hwasan_sanitize_allocas_p () && cfun->calls_alloca)
2714 : : /* When using out-of-line instrumentation we only want to emit one function
2715 : : call for clearing the tags in a region of shadow stack. When there are
2716 : : alloca calls in this frame we want to emit a call using the
2717 : : virtual_stack_dynamic_rtx, but when not we use the hwasan_frame_extent
2718 : : rtx we created in expand_stack_vars. */
2719 : 0 : var_end_seq = hwasan_emit_untag_frame (virtual_stack_dynamic_rtx,
2720 : : virtual_stack_vars_rtx);
2721 : 1450451 : else if (hwasan_sanitize_stack_p ())
2722 : : /* If no variables were stored on the stack, `hwasan_get_frame_extent`
2723 : : will return NULL_RTX and hence `hwasan_emit_untag_frame` will return
2724 : : NULL (i.e. an empty sequence). */
2725 : 446 : var_end_seq = hwasan_emit_untag_frame (hwasan_get_frame_extent (),
2726 : : virtual_stack_vars_rtx);
2727 : :
2728 : 1450629 : fini_vars_expansion ();
2729 : :
2730 : : /* If there were any artificial non-ignored vars without rtl
2731 : : found earlier, see if deferred stack allocation hasn't assigned
2732 : : rtl to them. */
2733 : 1597850 : FOR_EACH_VEC_ELT_REVERSE (maybe_local_decls, i, var)
2734 : : {
2735 : 105110 : rtx rtl = DECL_RTL_IF_SET (var);
2736 : :
2737 : : /* Keep artificial non-ignored vars in cfun->local_decls
2738 : : chain until instantiate_decls. */
2739 : 4156 : if (rtl && (MEM_P (rtl) || GET_CODE (rtl) == CONCAT))
2740 : 4037 : add_local_decl (cfun, var);
2741 : : }
2742 : :
2743 : : /* If the target requires that FRAME_OFFSET be aligned, do it. */
2744 : 1450629 : if (STACK_ALIGNMENT_NEEDED)
2745 : : {
2746 : 1450629 : HOST_WIDE_INT align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
2747 : 1450629 : if (FRAME_GROWS_DOWNWARD)
2748 : 1450629 : frame_offset = aligned_lower_bound (frame_offset, align);
2749 : : else
2750 : : frame_offset = aligned_upper_bound (frame_offset, align);
2751 : : }
2752 : :
2753 : 1450629 : return var_end_seq;
2754 : 1450629 : }
2755 : :
2756 : :
2757 : : /* If we need to produce a detailed dump, print the tree representation
2758 : : for STMT to the dump file. SINCE is the last RTX after which the RTL
2759 : : generated for STMT should have been appended. */
2760 : :
2761 : : static void
2762 : 41645668 : maybe_dump_rtl_for_gimple_stmt (gimple *stmt, rtx_insn *since)
2763 : : {
2764 : 41645668 : if (dump_file && (dump_flags & TDF_DETAILS))
2765 : : {
2766 : 367 : fprintf (dump_file, "\n;; ");
2767 : 367 : print_gimple_stmt (dump_file, stmt, 0,
2768 : : TDF_SLIM | (dump_flags & TDF_LINENO));
2769 : 367 : fprintf (dump_file, "\n");
2770 : :
2771 : 367 : print_rtl (dump_file, since ? NEXT_INSN (since) : since);
2772 : : }
2773 : 41645668 : }
2774 : :
2775 : : /* Temporary storage for BB_HEAD and BB_END of bbs until they are converted
2776 : : to BB_RTL. */
2777 : : static vec<std::pair <rtx_insn *, rtx_insn *>> head_end_for_bb;
2778 : :
2779 : : /* Maps the blocks that do not contain tree labels to rtx labels. */
2780 : :
2781 : : static hash_map<basic_block, rtx_code_label *> *lab_rtx_for_bb;
2782 : :
2783 : : /* Returns the label_rtx expression for a label starting basic block BB. */
2784 : :
2785 : : static rtx_code_label *
2786 : 7730962 : label_rtx_for_bb (basic_block bb)
2787 : : {
2788 : 7730962 : if (bb->flags & BB_RTL)
2789 : 0 : return block_label (bb);
2790 : :
2791 : 7730962 : if ((unsigned) bb->index < head_end_for_bb.length ()
2792 : 7730962 : && head_end_for_bb[bb->index].first)
2793 : : {
2794 : 1700235 : if (!LABEL_P (head_end_for_bb[bb->index].first))
2795 : : {
2796 : 1012009 : head_end_for_bb[bb->index].first
2797 : 2024018 : = emit_label_before (gen_label_rtx (),
2798 : 1012009 : head_end_for_bb[bb->index].first);
2799 : : }
2800 : 1700235 : return as_a <rtx_code_label *> (head_end_for_bb[bb->index].first);
2801 : : }
2802 : :
2803 : 6030727 : rtx_code_label **elt = lab_rtx_for_bb->get (bb);
2804 : 6030727 : if (elt)
2805 : 1197735 : return *elt;
2806 : :
2807 : : /* Find the tree label if it is present. */
2808 : 4832992 : gimple_stmt_iterator gsi = gsi_start_bb (bb);
2809 : 4832992 : glabel *lab_stmt;
2810 : 4832992 : if (!gsi_end_p (gsi)
2811 : 4698626 : && (lab_stmt = dyn_cast <glabel *> (gsi_stmt (gsi)))
2812 : 5043886 : && !DECL_NONLOCAL (gimple_label_label (lab_stmt)))
2813 : 210894 : return jump_target_rtx (gimple_label_label (lab_stmt));
2814 : :
2815 : 4622098 : rtx_code_label *l = gen_label_rtx ();
2816 : 4622098 : lab_rtx_for_bb->put (bb, l);
2817 : 4622098 : return l;
2818 : : }
2819 : :
2820 : :
2821 : : /* Wrapper around remove_edge during expansion. */
2822 : :
2823 : : void
2824 : 128991 : expand_remove_edge (edge e)
2825 : : {
2826 : 128991 : if (current_ir_type () != IR_GIMPLE
2827 : 128991 : && (e->dest->flags & BB_RTL) == 0
2828 : 194515 : && !gimple_seq_empty_p (phi_nodes (e->dest)))
2829 : 8290 : remove_phi_args (e);
2830 : 128991 : remove_edge (e);
2831 : 128991 : }
2832 : :
2833 : : /* Split edge E during expansion and instead of creating a new
2834 : : bb on that edge, add there BB. FLAGS should be flags on the
2835 : : new edge from BB to former E->dest. */
2836 : :
2837 : : static void
2838 : 1943705 : expand_split_edge (edge e, basic_block bb, int flags)
2839 : : {
2840 : 1943705 : unsigned int dest_idx = e->dest_idx;
2841 : 1943705 : basic_block dest = e->dest;
2842 : 1943705 : redirect_edge_succ (e, bb);
2843 : 1943705 : e = make_single_succ_edge (bb, dest, flags);
2844 : 1943705 : if ((dest->flags & BB_RTL) == 0
2845 : 1943705 : && phi_nodes (dest)
2846 : 2104647 : && e->dest_idx != dest_idx)
2847 : : {
2848 : : /* If there are any PHI nodes on dest, swap the new succ edge
2849 : : with the one moved into false_edge's former position, so that
2850 : : PHI arguments don't need adjustment. */
2851 : 99812 : edge e2 = EDGE_PRED (dest, dest_idx);
2852 : 99812 : std::swap (e->dest_idx, e2->dest_idx);
2853 : 99812 : std::swap (EDGE_PRED (dest, e->dest_idx),
2854 : : EDGE_PRED (dest, e2->dest_idx));
2855 : : }
2856 : 1943705 : }
2857 : :
2858 : :
2859 : : /* A subroutine of expand_gimple_cond. Given E, a fallthrough edge
2860 : : of a basic block where we just expanded the conditional at the end,
2861 : : possibly clean up the CFG and instruction sequence. LAST is the
2862 : : last instruction before the just emitted jump sequence. */
2863 : :
2864 : : static void
2865 : 5119936 : maybe_cleanup_end_of_block (edge e, rtx_insn *last)
2866 : : {
2867 : : /* Special case: when jumpif decides that the condition is
2868 : : trivial it emits an unconditional jump (and the necessary
2869 : : barrier). But we still have two edges, the fallthru one is
2870 : : wrong. purge_dead_edges would clean this up later. Unfortunately
2871 : : we have to insert insns (and split edges) before
2872 : : find_many_sub_basic_blocks and hence before purge_dead_edges.
2873 : : But splitting edges might create new blocks which depend on the
2874 : : fact that if there are two edges there's no barrier. So the
2875 : : barrier would get lost and verify_flow_info would ICE. Instead
2876 : : of auditing all edge splitters to care for the barrier (which
2877 : : normally isn't there in a cleaned CFG), fix it here. */
2878 : 5119936 : if (BARRIER_P (get_last_insn ()))
2879 : : {
2880 : 101 : rtx_insn *insn;
2881 : 101 : expand_remove_edge (e);
2882 : : /* Now, we have a single successor block, if we have insns to
2883 : : insert on the remaining edge we potentially will insert
2884 : : it at the end of this block (if the dest block isn't feasible)
2885 : : in order to avoid splitting the edge. This insertion will take
2886 : : place in front of the last jump. But we might have emitted
2887 : : multiple jumps (conditional and one unconditional) to the
2888 : : same destination. Inserting in front of the last one then
2889 : : is a problem. See PR 40021. We fix this by deleting all
2890 : : jumps except the last unconditional one. */
2891 : 101 : insn = PREV_INSN (get_last_insn ());
2892 : : /* Make sure we have an unconditional jump. Otherwise we're
2893 : : confused. */
2894 : 101 : gcc_assert (JUMP_P (insn) && !any_condjump_p (insn));
2895 : 202 : for (insn = PREV_INSN (insn); insn != last;)
2896 : : {
2897 : 0 : insn = PREV_INSN (insn);
2898 : 0 : if (JUMP_P (NEXT_INSN (insn)))
2899 : : {
2900 : 0 : if (!any_condjump_p (NEXT_INSN (insn)))
2901 : : {
2902 : 0 : gcc_assert (BARRIER_P (NEXT_INSN (NEXT_INSN (insn))));
2903 : 0 : delete_insn (NEXT_INSN (NEXT_INSN (insn)));
2904 : : }
2905 : 0 : delete_insn (NEXT_INSN (insn));
2906 : : }
2907 : : }
2908 : : }
2909 : 5119936 : }
2910 : :
2911 : : /* A subroutine of expand_gimple_basic_block. Expand one GIMPLE_COND.
2912 : : Returns a new basic block if we've terminated the current basic
2913 : : block and created a new one. */
2914 : :
2915 : : static basic_block
2916 : 5613012 : expand_gimple_cond (basic_block bb, gcond *stmt)
2917 : : {
2918 : 5613012 : basic_block new_bb, dest;
2919 : 5613012 : edge true_edge;
2920 : 5613012 : edge false_edge;
2921 : 5613012 : rtx_insn *last2, *last;
2922 : 5613012 : enum tree_code code;
2923 : 5613012 : tree op0, op1;
2924 : :
2925 : 5613012 : code = gimple_cond_code (stmt);
2926 : 5613012 : op0 = gimple_cond_lhs (stmt);
2927 : 5613012 : op1 = gimple_cond_rhs (stmt);
2928 : : /* We're sometimes presented with such code:
2929 : : D.123_1 = x < y;
2930 : : if (D.123_1 != 0)
2931 : : ...
2932 : : This would expand to two comparisons which then later might
2933 : : be cleaned up by combine. But some pattern matchers like if-conversion
2934 : : work better when there's only one compare, so make up for this
2935 : : here as special exception if TER would have made the same change. */
2936 : 5613012 : if (SA.values
2937 : 4116008 : && TREE_CODE (op0) == SSA_NAME
2938 : 4115450 : && TREE_CODE (TREE_TYPE (op0)) == BOOLEAN_TYPE
2939 : 389172 : && TREE_CODE (op1) == INTEGER_CST
2940 : 379631 : && ((gimple_cond_code (stmt) == NE_EXPR
2941 : 379619 : && integer_zerop (op1))
2942 : 12 : || (gimple_cond_code (stmt) == EQ_EXPR
2943 : 12 : && integer_onep (op1)))
2944 : 5992643 : && bitmap_bit_p (SA.values, SSA_NAME_VERSION (op0)))
2945 : : {
2946 : 203098 : gimple *second = SSA_NAME_DEF_STMT (op0);
2947 : 203098 : if (gimple_code (second) == GIMPLE_ASSIGN)
2948 : : {
2949 : 203098 : enum tree_code code2 = gimple_assign_rhs_code (second);
2950 : 203098 : if (TREE_CODE_CLASS (code2) == tcc_comparison)
2951 : : {
2952 : 737 : code = code2;
2953 : 737 : op0 = gimple_assign_rhs1 (second);
2954 : 737 : op1 = gimple_assign_rhs2 (second);
2955 : : }
2956 : : /* If jumps are cheap and the target does not support conditional
2957 : : compare, turn some more codes into jumpy sequences. */
2958 : 202361 : else if (BRANCH_COST (optimize_insn_for_speed_p (), false) < 4
2959 : 202361 : && !targetm.have_ccmp ())
2960 : : {
2961 : 202358 : if ((code2 == BIT_AND_EXPR
2962 : 58359 : && TYPE_PRECISION (TREE_TYPE (op0)) == 1
2963 : 58359 : && TREE_CODE (gimple_assign_rhs2 (second)) != INTEGER_CST)
2964 : 202358 : || code2 == TRUTH_AND_EXPR)
2965 : : {
2966 : 58359 : code = TRUTH_ANDIF_EXPR;
2967 : 58359 : op0 = gimple_assign_rhs1 (second);
2968 : 58359 : op1 = gimple_assign_rhs2 (second);
2969 : : }
2970 : 143999 : else if (code2 == BIT_IOR_EXPR || code2 == TRUTH_OR_EXPR)
2971 : : {
2972 : 63779 : code = TRUTH_ORIF_EXPR;
2973 : 63779 : op0 = gimple_assign_rhs1 (second);
2974 : 63779 : op1 = gimple_assign_rhs2 (second);
2975 : : }
2976 : : }
2977 : : }
2978 : : }
2979 : :
2980 : : /* Optimize (x % C1) == C2 or (x % C1) != C2 if it is beneficial
2981 : : into (x - C2) * C3 < C4. */
2982 : 5613012 : if ((code == EQ_EXPR || code == NE_EXPR)
2983 : 4394984 : && TREE_CODE (op0) == SSA_NAME
2984 : 4394226 : && TREE_CODE (op1) == INTEGER_CST)
2985 : 3083431 : code = maybe_optimize_mod_cmp (code, &op0, &op1);
2986 : :
2987 : : /* Optimize (x - y) < 0 into x < y if x - y has undefined overflow. */
2988 : 5613012 : if (!TYPE_UNSIGNED (TREE_TYPE (op0))
2989 : 2274528 : && (code == LT_EXPR || code == LE_EXPR
2990 : 2274528 : || code == GT_EXPR || code == GE_EXPR)
2991 : 686347 : && integer_zerop (op1)
2992 : 5810313 : && TREE_CODE (op0) == SSA_NAME)
2993 : 197301 : maybe_optimize_sub_cmp_0 (code, &op0, &op1);
2994 : :
2995 : 5613012 : last2 = last = get_last_insn ();
2996 : :
2997 : 5613012 : extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
2998 : 5613012 : set_curr_insn_location (gimple_location (stmt));
2999 : :
3000 : : /* We can either have a pure conditional jump with one fallthru edge or
3001 : : two-way jump that needs to be decomposed into two basic blocks. */
3002 : 5613012 : if (false_edge->dest == bb->next_bb)
3003 : : {
3004 : 2201109 : jumpif_1 (code, op0, op1, label_rtx_for_bb (true_edge->dest),
3005 : : true_edge->probability);
3006 : 2201109 : maybe_dump_rtl_for_gimple_stmt (stmt, last);
3007 : 2201109 : if (true_edge->goto_locus != UNKNOWN_LOCATION)
3008 : 1566610 : set_curr_insn_location (true_edge->goto_locus);
3009 : 2201109 : false_edge->flags |= EDGE_FALLTHRU;
3010 : 2201109 : maybe_cleanup_end_of_block (false_edge, last);
3011 : 2201109 : return NULL;
3012 : : }
3013 : 3411903 : if (true_edge->dest == bb->next_bb)
3014 : : {
3015 : 2918827 : jumpifnot_1 (code, op0, op1, label_rtx_for_bb (false_edge->dest),
3016 : : false_edge->probability);
3017 : 2918827 : maybe_dump_rtl_for_gimple_stmt (stmt, last);
3018 : 2918827 : if (false_edge->goto_locus != UNKNOWN_LOCATION)
3019 : 2591943 : set_curr_insn_location (false_edge->goto_locus);
3020 : 2918827 : true_edge->flags |= EDGE_FALLTHRU;
3021 : 2918827 : maybe_cleanup_end_of_block (true_edge, last);
3022 : 2918827 : return NULL;
3023 : : }
3024 : :
3025 : 493076 : jumpif_1 (code, op0, op1, label_rtx_for_bb (true_edge->dest),
3026 : : true_edge->probability);
3027 : 493076 : last = get_last_insn ();
3028 : 493076 : if (false_edge->goto_locus != UNKNOWN_LOCATION)
3029 : 269313 : set_curr_insn_location (false_edge->goto_locus);
3030 : 493076 : emit_jump (label_rtx_for_bb (false_edge->dest));
3031 : :
3032 : 493076 : head_end_for_bb[bb->index].second = last;
3033 : 493076 : if (BARRIER_P (head_end_for_bb[bb->index].second))
3034 : 148 : head_end_for_bb[bb->index].second
3035 : 74 : = PREV_INSN (head_end_for_bb[bb->index].second);
3036 : 986152 : update_bb_for_insn_chain (head_end_for_bb[bb->index].first,
3037 : 493076 : head_end_for_bb[bb->index].second, bb);
3038 : :
3039 : 493076 : new_bb = create_basic_block (NEXT_INSN (last), get_last_insn (), bb);
3040 : 493076 : dest = false_edge->dest;
3041 : 493076 : expand_split_edge (false_edge, new_bb, 0);
3042 : 493076 : false_edge->flags |= EDGE_FALLTHRU;
3043 : 493076 : new_bb->count = false_edge->count ();
3044 : 493076 : loop_p loop = find_common_loop (bb->loop_father, dest->loop_father);
3045 : 493076 : add_bb_to_loop (new_bb, loop);
3046 : 493076 : if (loop->latch == bb
3047 : 31261 : && loop->header == dest)
3048 : 31258 : loop->latch = new_bb;
3049 : 493076 : if (BARRIER_P (BB_END (new_bb)))
3050 : 493076 : BB_END (new_bb) = PREV_INSN (BB_END (new_bb));
3051 : 493076 : update_bb_for_insn (new_bb);
3052 : :
3053 : 493076 : maybe_dump_rtl_for_gimple_stmt (stmt, last2);
3054 : :
3055 : 493076 : if (true_edge->goto_locus != UNKNOWN_LOCATION)
3056 : : {
3057 : 269299 : set_curr_insn_location (true_edge->goto_locus);
3058 : 269299 : true_edge->goto_locus = curr_insn_location ();
3059 : : }
3060 : :
3061 : : return new_bb;
3062 : : }
3063 : :
3064 : : /* Mark all calls that can have a transaction restart. */
3065 : :
3066 : : static void
3067 : 6581899 : mark_transaction_restart_calls (gimple *stmt)
3068 : : {
3069 : 6581899 : struct tm_restart_node dummy;
3070 : 6581899 : tm_restart_node **slot;
3071 : :
3072 : 6581899 : if (!cfun->gimple_df->tm_restart)
3073 : 6578915 : return;
3074 : :
3075 : 2984 : dummy.stmt = stmt;
3076 : 2984 : slot = cfun->gimple_df->tm_restart->find_slot (&dummy, NO_INSERT);
3077 : 2984 : if (slot)
3078 : : {
3079 : 0 : struct tm_restart_node *n = *slot;
3080 : 0 : tree list = n->label_or_list;
3081 : 0 : rtx_insn *insn;
3082 : :
3083 : 0 : for (insn = next_real_insn (get_last_insn ());
3084 : 0 : !CALL_P (insn);
3085 : 0 : insn = next_real_insn (insn))
3086 : 0 : continue;
3087 : :
3088 : 0 : if (TREE_CODE (list) == LABEL_DECL)
3089 : 0 : add_reg_note (insn, REG_TM, label_rtx (list));
3090 : : else
3091 : 0 : for (; list ; list = TREE_CHAIN (list))
3092 : 0 : add_reg_note (insn, REG_TM, label_rtx (TREE_VALUE (list)));
3093 : 0 : }
3094 : : }
3095 : :
3096 : : /* A subroutine of expand_gimple_stmt_1, expanding one GIMPLE_CALL
3097 : : statement STMT. */
3098 : :
3099 : : static void
3100 : 6773071 : expand_call_stmt (gcall *stmt)
3101 : : {
3102 : 6773071 : tree exp, decl, lhs;
3103 : 6773071 : bool builtin_p;
3104 : 6773071 : size_t i;
3105 : :
3106 : 6773071 : if (gimple_call_internal_p (stmt))
3107 : : {
3108 : 154210 : expand_internal_call (stmt);
3109 : 154210 : return;
3110 : : }
3111 : :
3112 : : /* If this is a call to a built-in function and it has no effect other
3113 : : than setting the lhs, try to implement it using an internal function
3114 : : instead. */
3115 : 6618861 : decl = gimple_call_fndecl (stmt);
3116 : 6618861 : if (gimple_call_lhs (stmt)
3117 : 2363988 : && !gimple_has_side_effects (stmt)
3118 : 7337692 : && (optimize || (decl && called_as_built_in (decl))))
3119 : : {
3120 : 698745 : internal_fn ifn = replacement_internal_fn (stmt);
3121 : 698745 : if (ifn != IFN_LAST)
3122 : : {
3123 : 36962 : expand_internal_call (ifn, stmt);
3124 : 36962 : return;
3125 : : }
3126 : : }
3127 : :
3128 : 6581899 : exp = build_vl_exp (CALL_EXPR, gimple_call_num_args (stmt) + 3);
3129 : :
3130 : 6581899 : CALL_EXPR_FN (exp) = gimple_call_fn (stmt);
3131 : 6581899 : builtin_p = decl && fndecl_built_in_p (decl);
3132 : :
3133 : : /* If this is not a builtin function, the function type through which the
3134 : : call is made may be different from the type of the function. */
3135 : 4627855 : if (!builtin_p)
3136 : 9255710 : CALL_EXPR_FN (exp)
3137 : 13883565 : = fold_convert (build_pointer_type (gimple_call_fntype (stmt)),
3138 : : CALL_EXPR_FN (exp));
3139 : :
3140 : 6581899 : TREE_TYPE (exp) = gimple_call_return_type (stmt);
3141 : 6581899 : CALL_EXPR_STATIC_CHAIN (exp) = gimple_call_chain (stmt);
3142 : :
3143 : 19899953 : for (i = 0; i < gimple_call_num_args (stmt); i++)
3144 : : {
3145 : 13318054 : tree arg = gimple_call_arg (stmt, i);
3146 : 13318054 : gimple *def;
3147 : : /* TER addresses into arguments of builtin functions so we have a
3148 : : chance to infer more correct alignment information. See PR39954. */
3149 : 13318054 : if (builtin_p
3150 : 4013988 : && TREE_CODE (arg) == SSA_NAME
3151 : 1333216 : && (def = get_gimple_for_ssa_name (arg))
3152 : 328889 : && is_gimple_assign (def)
3153 : 13646782 : && gimple_assign_rhs_code (def) == ADDR_EXPR)
3154 : 14358 : arg = gimple_assign_rhs1 (def);
3155 : 13318054 : CALL_EXPR_ARG (exp, i) = arg;
3156 : : }
3157 : :
3158 : 6581899 : if (gimple_has_side_effects (stmt)
3159 : : /* ??? Downstream in expand_expr_real_1 we assume that expressions
3160 : : w/o side-effects do not throw so work around this here. */
3161 : 6581899 : || stmt_could_throw_p (cfun, stmt))
3162 : 5902321 : TREE_SIDE_EFFECTS (exp) = 1;
3163 : :
3164 : 6581899 : if (gimple_call_nothrow_p (stmt))
3165 : 2941915 : TREE_NOTHROW (exp) = 1;
3166 : :
3167 : 6581899 : CALL_EXPR_TAILCALL (exp) = gimple_call_tail_p (stmt);
3168 : 6581899 : CALL_EXPR_MUST_TAIL_CALL (exp) = gimple_call_must_tail_p (stmt);
3169 : 6581899 : CALL_EXPR_RETURN_SLOT_OPT (exp) = gimple_call_return_slot_opt_p (stmt);
3170 : 6581899 : if (decl
3171 : 6392793 : && fndecl_built_in_p (decl, BUILT_IN_NORMAL)
3172 : 8364828 : && ALLOCA_FUNCTION_CODE_P (DECL_FUNCTION_CODE (decl)))
3173 : 25431 : CALL_ALLOCA_FOR_VAR_P (exp) = gimple_call_alloca_for_var_p (stmt);
3174 : : else
3175 : 6556468 : CALL_FROM_THUNK_P (exp) = gimple_call_from_thunk_p (stmt);
3176 : 6581899 : CALL_EXPR_VA_ARG_PACK (exp) = gimple_call_va_arg_pack_p (stmt);
3177 : 6581899 : CALL_EXPR_BY_DESCRIPTOR (exp) = gimple_call_by_descriptor_p (stmt);
3178 : 6581899 : SET_EXPR_LOCATION (exp, gimple_location (stmt));
3179 : :
3180 : : /* Must come after copying location. */
3181 : 6581899 : copy_warning (exp, stmt);
3182 : :
3183 : : /* Ensure RTL is created for debug args. */
3184 : 12974692 : if (decl && DECL_HAS_DEBUG_ARGS_P (decl))
3185 : : {
3186 : 68416 : vec<tree, va_gc> **debug_args = decl_debug_args_lookup (decl);
3187 : 68416 : unsigned int ix;
3188 : 68416 : tree dtemp;
3189 : :
3190 : 68416 : if (debug_args)
3191 : 148013 : for (ix = 1; (*debug_args)->iterate (ix, &dtemp); ix += 2)
3192 : : {
3193 : 79597 : gcc_assert (TREE_CODE (dtemp) == DEBUG_EXPR_DECL);
3194 : 79597 : expand_debug_expr (dtemp);
3195 : : }
3196 : : }
3197 : :
3198 : 6581899 : rtx_insn *before_call = get_last_insn ();
3199 : 6581899 : lhs = gimple_call_lhs (stmt);
3200 : 6581899 : if (lhs)
3201 : 2327026 : expand_assignment (lhs, exp, false);
3202 : : else
3203 : 4254873 : expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL);
3204 : :
3205 : : /* If the gimple call is an indirect call and has 'nocf_check'
3206 : : attribute find a generated CALL insn to mark it as no
3207 : : control-flow verification is needed. */
3208 : 6581899 : if (gimple_call_nocf_check_p (stmt)
3209 : 6581920 : && !gimple_call_fndecl (stmt))
3210 : : {
3211 : 20 : rtx_insn *last = get_last_insn ();
3212 : 20 : while (!CALL_P (last)
3213 : 34 : && last != before_call)
3214 : 14 : last = PREV_INSN (last);
3215 : :
3216 : 20 : if (last != before_call)
3217 : 20 : add_reg_note (last, REG_CALL_NOCF_CHECK, const0_rtx);
3218 : : }
3219 : :
3220 : 6581899 : mark_transaction_restart_calls (stmt);
3221 : : }
3222 : :
3223 : :
3224 : : /* Generate RTL for an asm statement (explicit assembler code).
3225 : : STRING is a STRING_CST node containing the assembler code text,
3226 : : or an ADDR_EXPR containing a STRING_CST. VOL nonzero means the
3227 : : insn is volatile; don't optimize it. */
3228 : :
3229 : : static void
3230 : 2805 : expand_asm_loc (tree string, int vol, location_t locus)
3231 : : {
3232 : 2805 : rtx body;
3233 : :
3234 : 2805 : body = gen_rtx_ASM_INPUT_loc (VOIDmode,
3235 : : ggc_strdup (TREE_STRING_POINTER (string)),
3236 : : locus);
3237 : :
3238 : 2805 : MEM_VOLATILE_P (body) = vol;
3239 : :
3240 : : /* Non-empty basic ASM implicitly clobbers memory. */
3241 : 2805 : if (TREE_STRING_LENGTH (string) != 0)
3242 : : {
3243 : 936 : rtx asm_op, clob;
3244 : 936 : unsigned i, nclobbers;
3245 : 936 : auto_vec<rtx> input_rvec, output_rvec;
3246 : 936 : auto_vec<machine_mode> input_mode;
3247 : 936 : auto_vec<const char *> constraints;
3248 : 936 : auto_vec<rtx> use_rvec;
3249 : 936 : auto_vec<rtx> clobber_rvec;
3250 : 936 : HARD_REG_SET clobbered_regs;
3251 : 936 : CLEAR_HARD_REG_SET (clobbered_regs);
3252 : :
3253 : 936 : clob = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode));
3254 : 936 : clobber_rvec.safe_push (clob);
3255 : :
3256 : 936 : if (targetm.md_asm_adjust)
3257 : 936 : targetm.md_asm_adjust (output_rvec, input_rvec, input_mode,
3258 : : constraints, use_rvec, clobber_rvec,
3259 : : clobbered_regs, locus);
3260 : :
3261 : 936 : asm_op = body;
3262 : 936 : nclobbers = clobber_rvec.length ();
3263 : 936 : auto nuses = use_rvec.length ();
3264 : 936 : body = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (1 + nuses + nclobbers));
3265 : :
3266 : 936 : i = 0;
3267 : 936 : XVECEXP (body, 0, i++) = asm_op;
3268 : 936 : for (rtx use : use_rvec)
3269 : 0 : XVECEXP (body, 0, i++) = gen_rtx_USE (VOIDmode, use);
3270 : 4680 : for (rtx clobber : clobber_rvec)
3271 : 1872 : XVECEXP (body, 0, i++) = gen_rtx_CLOBBER (VOIDmode, clobber);
3272 : 936 : }
3273 : :
3274 : 2805 : emit_insn (body);
3275 : 2805 : }
3276 : :
3277 : : /* Return the number of times character C occurs in string S. */
3278 : : static int
3279 : 123462 : n_occurrences (int c, const char *s)
3280 : : {
3281 : 123462 : int n = 0;
3282 : 323261 : while (*s)
3283 : 199799 : n += (*s++ == c);
3284 : 123462 : return n;
3285 : : }
3286 : :
3287 : : /* A subroutine of expand_asm_operands. Check that all operands have
3288 : : the same number of alternatives. Return true if so. */
3289 : :
3290 : : static bool
3291 : 103790 : check_operand_nalternatives (const vec<const char *> &constraints)
3292 : : {
3293 : 103790 : unsigned len = constraints.length();
3294 : 103790 : if (len > 0)
3295 : : {
3296 : 39951 : int nalternatives = n_occurrences (',', constraints[0]);
3297 : :
3298 : 39951 : if (nalternatives + 1 > MAX_RECOG_ALTERNATIVES)
3299 : : {
3300 : 0 : error ("too many alternatives in %<asm%>");
3301 : 0 : return false;
3302 : : }
3303 : :
3304 : 123462 : for (unsigned i = 1; i < len; ++i)
3305 : 167022 : if (n_occurrences (',', constraints[i]) != nalternatives)
3306 : : {
3307 : 0 : error ("operand constraints for %<asm%> differ "
3308 : : "in number of alternatives");
3309 : 0 : return false;
3310 : : }
3311 : : }
3312 : : return true;
3313 : : }
3314 : :
3315 : : /* Check for overlap between registers marked in CLOBBERED_REGS and
3316 : : anything inappropriate in T. Emit error and return the register
3317 : : variable definition for error, NULL_TREE for ok. */
3318 : :
3319 : : static bool
3320 : 123453 : tree_conflicts_with_clobbers_p (tree t, HARD_REG_SET *clobbered_regs,
3321 : : location_t loc)
3322 : : {
3323 : : /* Conflicts between asm-declared register variables and the clobber
3324 : : list are not allowed. */
3325 : 123453 : tree overlap = tree_overlaps_hard_reg_set (t, clobbered_regs);
3326 : :
3327 : 123453 : if (overlap)
3328 : : {
3329 : 21 : error_at (loc, "%<asm%> specifier for variable %qE conflicts with "
3330 : 21 : "%<asm%> clobber list", DECL_NAME (overlap));
3331 : :
3332 : : /* Reset registerness to stop multiple errors emitted for a single
3333 : : variable. */
3334 : 21 : DECL_REGISTER (overlap) = 0;
3335 : 21 : return true;
3336 : : }
3337 : :
3338 : : return false;
3339 : : }
3340 : :
3341 : : /* Check that the given REGNO spanning NREGS is a valid
3342 : : asm clobber operand. Some HW registers cannot be
3343 : : saved/restored, hence they should not be clobbered by
3344 : : asm statements. */
3345 : : static bool
3346 : 41477 : asm_clobber_reg_is_valid (int regno, int nregs, const char *regname)
3347 : : {
3348 : 41477 : bool is_valid = true;
3349 : 41477 : HARD_REG_SET regset;
3350 : :
3351 : 41477 : CLEAR_HARD_REG_SET (regset);
3352 : :
3353 : 41477 : add_range_to_hard_reg_set (®set, regno, nregs);
3354 : :
3355 : : /* Clobbering the PIC register is an error. */
3356 : 41477 : if (PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
3357 : 0 : && overlaps_hard_reg_set_p (regset, Pmode, PIC_OFFSET_TABLE_REGNUM))
3358 : : {
3359 : : /* ??? Diagnose during gimplification? */
3360 : 0 : error ("PIC register clobbered by %qs in %<asm%>", regname);
3361 : 0 : is_valid = false;
3362 : : }
3363 : 41477 : else if (!in_hard_reg_set_p
3364 : 41477 : (accessible_reg_set, reg_raw_mode[regno], regno))
3365 : : {
3366 : : /* ??? Diagnose during gimplification? */
3367 : 0 : error ("the register %qs cannot be clobbered in %<asm%>"
3368 : : " for the current target", regname);
3369 : 0 : is_valid = false;
3370 : : }
3371 : :
3372 : : /* Clobbering the stack pointer register is deprecated. GCC expects
3373 : : the value of the stack pointer after an asm statement to be the same
3374 : : as it was before, so no asm can validly clobber the stack pointer in
3375 : : the usual sense. Adding the stack pointer to the clobber list has
3376 : : traditionally had some undocumented and somewhat obscure side-effects. */
3377 : 41477 : if (overlaps_hard_reg_set_p (regset, Pmode, STACK_POINTER_REGNUM))
3378 : : {
3379 : 1 : crtl->sp_is_clobbered_by_asm = true;
3380 : 1 : if (warning (OPT_Wdeprecated, "listing the stack pointer register"
3381 : : " %qs in a clobber list is deprecated", regname))
3382 : 1 : inform (input_location, "the value of the stack pointer after"
3383 : : " an %<asm%> statement must be the same as it was before"
3384 : : " the statement");
3385 : : }
3386 : :
3387 : 41477 : return is_valid;
3388 : : }
3389 : :
3390 : : /* Generate RTL for an asm statement with arguments.
3391 : : STRING is the instruction template.
3392 : : OUTPUTS is a list of output arguments (lvalues); INPUTS a list of inputs.
3393 : : Each output or input has an expression in the TREE_VALUE and
3394 : : a tree list in TREE_PURPOSE which in turn contains a constraint
3395 : : name in TREE_VALUE (or NULL_TREE) and a constraint string
3396 : : in TREE_PURPOSE.
3397 : : CLOBBERS is a list of STRING_CST nodes each naming a hard register
3398 : : that is clobbered by this insn.
3399 : :
3400 : : LABELS is a list of labels, and if LABELS is non-NULL, FALLTHRU_BB
3401 : : should be the fallthru basic block of the asm goto.
3402 : :
3403 : : Not all kinds of lvalue that may appear in OUTPUTS can be stored directly.
3404 : : Some elements of OUTPUTS may be replaced with trees representing temporary
3405 : : values. The caller should copy those temporary values to the originally
3406 : : specified lvalues.
3407 : :
3408 : : VOL nonzero means the insn is volatile; don't optimize it. */
3409 : :
3410 : : static void
3411 : 106600 : expand_asm_stmt (gasm *stmt)
3412 : : {
3413 : 106600 : class save_input_location
3414 : : {
3415 : : location_t old;
3416 : :
3417 : : public:
3418 : 103795 : explicit save_input_location(location_t where)
3419 : 103795 : {
3420 : 103795 : old = input_location;
3421 : 103795 : input_location = where;
3422 : : }
3423 : :
3424 : 103795 : ~save_input_location()
3425 : : {
3426 : 103795 : input_location = old;
3427 : 5 : }
3428 : : };
3429 : :
3430 : 106600 : location_t locus = gimple_location (stmt);
3431 : :
3432 : 106600 : if (gimple_asm_basic_p (stmt))
3433 : : {
3434 : 2805 : const char *s = gimple_asm_string (stmt);
3435 : 2805 : tree string = build_string (strlen (s), s);
3436 : 2805 : expand_asm_loc (string, gimple_asm_volatile_p (stmt), locus);
3437 : 5615 : return;
3438 : : }
3439 : :
3440 : : /* There are some legacy diagnostics in here. */
3441 : 103795 : save_input_location s_i_l(locus);
3442 : :
3443 : 103795 : unsigned noutputs = gimple_asm_noutputs (stmt);
3444 : 103795 : unsigned ninputs = gimple_asm_ninputs (stmt);
3445 : 103795 : unsigned nlabels = gimple_asm_nlabels (stmt);
3446 : 103795 : unsigned i;
3447 : 103795 : bool error_seen = false;
3448 : :
3449 : : /* ??? Diagnose during gimplification? */
3450 : 103795 : if (ninputs + noutputs + nlabels > MAX_RECOG_OPERANDS)
3451 : : {
3452 : 5 : error_at (locus, "more than %d operands in %<asm%>", MAX_RECOG_OPERANDS);
3453 : 5 : return;
3454 : : }
3455 : :
3456 : 103790 : auto_vec<tree, MAX_RECOG_OPERANDS> output_tvec;
3457 : 103790 : auto_vec<tree, MAX_RECOG_OPERANDS> input_tvec;
3458 : 103790 : auto_vec<const char *, MAX_RECOG_OPERANDS> constraints;
3459 : :
3460 : : /* Copy the gimple vectors into new vectors that we can manipulate. */
3461 : :
3462 : 103790 : output_tvec.safe_grow (noutputs, true);
3463 : 103790 : input_tvec.safe_grow (ninputs, true);
3464 : 103790 : constraints.safe_grow (noutputs + ninputs, true);
3465 : :
3466 : 175377 : for (i = 0; i < noutputs; ++i)
3467 : : {
3468 : 71587 : tree t = gimple_asm_output_op (stmt, i);
3469 : 71587 : output_tvec[i] = TREE_VALUE (t);
3470 : 71587 : constraints[i] = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
3471 : : }
3472 : 155665 : for (i = 0; i < ninputs; i++)
3473 : : {
3474 : 51875 : tree t = gimple_asm_input_op (stmt, i);
3475 : 51875 : input_tvec[i] = TREE_VALUE (t);
3476 : 51875 : constraints[i + noutputs]
3477 : 51875 : = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
3478 : : }
3479 : :
3480 : : /* ??? Diagnose during gimplification? */
3481 : 103790 : if (! check_operand_nalternatives (constraints))
3482 : : return;
3483 : :
3484 : : /* Count the number of meaningful clobbered registers, ignoring what
3485 : : we would ignore later. */
3486 : 103790 : auto_vec<rtx> clobber_rvec;
3487 : 103790 : HARD_REG_SET clobbered_regs;
3488 : 103790 : CLEAR_HARD_REG_SET (clobbered_regs);
3489 : :
3490 : 103790 : if (unsigned n = gimple_asm_nclobbers (stmt))
3491 : : {
3492 : 68503 : clobber_rvec.reserve (n);
3493 : 164527 : for (i = 0; i < n; i++)
3494 : : {
3495 : 96024 : tree t = gimple_asm_clobber_op (stmt, i);
3496 : 96024 : const char *regname = TREE_STRING_POINTER (TREE_VALUE (t));
3497 : 96024 : int nregs, j;
3498 : :
3499 : 96024 : j = decode_reg_name_and_count (regname, &nregs);
3500 : 96024 : if (j < 0)
3501 : : {
3502 : 54547 : if (j == -2)
3503 : : {
3504 : : /* ??? Diagnose during gimplification? */
3505 : 15 : error_at (locus, "unknown register name %qs in %<asm%>",
3506 : : regname);
3507 : 15 : error_seen = true;
3508 : : }
3509 : 54532 : else if (j == -4)
3510 : : {
3511 : 38807 : rtx x = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode));
3512 : 38807 : clobber_rvec.safe_push (x);
3513 : : }
3514 : 15725 : else if (j == -5)
3515 : : {
3516 : 2 : if (targetm.redzone_clobber)
3517 : 2 : if (rtx x = targetm.redzone_clobber ())
3518 : 2 : clobber_rvec.safe_push (x);
3519 : : }
3520 : : else
3521 : : {
3522 : : /* Otherwise we should have -1 == empty string
3523 : : or -3 == cc, which is not a register. */
3524 : 15723 : gcc_assert (j == -1 || j == -3);
3525 : : }
3526 : : }
3527 : : else
3528 : 82954 : for (int reg = j; reg < j + nregs; reg++)
3529 : : {
3530 : 41477 : if (!asm_clobber_reg_is_valid (reg, nregs, regname))
3531 : 0 : return;
3532 : :
3533 : 41477 : SET_HARD_REG_BIT (clobbered_regs, reg);
3534 : 41477 : rtx x = gen_rtx_REG (reg_raw_mode[reg], reg);
3535 : 41477 : clobber_rvec.safe_push (x);
3536 : : }
3537 : : }
3538 : : }
3539 : :
3540 : : /* First pass over inputs and outputs checks validity and sets
3541 : : mark_addressable if needed. */
3542 : : /* ??? Diagnose during gimplification? */
3543 : :
3544 : 175377 : for (i = 0; i < noutputs; ++i)
3545 : : {
3546 : 71587 : tree val = output_tvec[i];
3547 : 71587 : tree type = TREE_TYPE (val);
3548 : 71587 : const char *constraint;
3549 : 71587 : bool is_inout;
3550 : 71587 : bool allows_reg;
3551 : 71587 : bool allows_mem;
3552 : :
3553 : : /* Try to parse the output constraint. If that fails, there's
3554 : : no point in going further. */
3555 : 71587 : constraint = constraints[i];
3556 : 71587 : if (!parse_output_constraint (&constraint, i, ninputs, noutputs,
3557 : : &allows_mem, &allows_reg, &is_inout))
3558 : 0 : return;
3559 : :
3560 : : /* If the output is a hard register, verify it doesn't conflict with
3561 : : any other operand's possible hard register use. */
3562 : 71587 : if (DECL_P (val)
3563 : 7545 : && REG_P (DECL_RTL (val))
3564 : 72544 : && HARD_REGISTER_P (DECL_RTL (val)))
3565 : : {
3566 : 940 : unsigned j, output_hregno = REGNO (DECL_RTL (val));
3567 : 940 : bool early_clobber_p = strchr (constraints[i], '&') != NULL;
3568 : 940 : unsigned long match;
3569 : :
3570 : : /* Verify the other outputs do not use the same hard register. */
3571 : 1101 : for (j = i + 1; j < noutputs; ++j)
3572 : 161 : if (DECL_P (output_tvec[j])
3573 : 159 : && REG_P (DECL_RTL (output_tvec[j]))
3574 : 159 : && HARD_REGISTER_P (DECL_RTL (output_tvec[j]))
3575 : 320 : && output_hregno == REGNO (DECL_RTL (output_tvec[j])))
3576 : : {
3577 : 1 : error_at (locus, "invalid hard register usage between output "
3578 : : "operands");
3579 : 1 : error_seen = true;
3580 : : }
3581 : :
3582 : : /* Verify matching constraint operands use the same hard register
3583 : : and that the non-matching constraint operands do not use the same
3584 : : hard register if the output is an early clobber operand. */
3585 : 1853 : for (j = 0; j < ninputs; ++j)
3586 : 913 : if (DECL_P (input_tvec[j])
3587 : 774 : && REG_P (DECL_RTL (input_tvec[j]))
3588 : 1687 : && HARD_REGISTER_P (DECL_RTL (input_tvec[j])))
3589 : : {
3590 : 774 : unsigned input_hregno = REGNO (DECL_RTL (input_tvec[j]));
3591 : 774 : switch (*constraints[j + noutputs])
3592 : : {
3593 : 762 : case '0': case '1': case '2': case '3': case '4':
3594 : 762 : case '5': case '6': case '7': case '8': case '9':
3595 : 762 : match = strtoul (constraints[j + noutputs], NULL, 10);
3596 : 762 : break;
3597 : : default:
3598 : : match = ULONG_MAX;
3599 : : break;
3600 : : }
3601 : 762 : if (i == match
3602 : 661 : && output_hregno != input_hregno)
3603 : : {
3604 : 1 : error_at (locus, "invalid hard register usage between "
3605 : : "output operand and matching constraint operand");
3606 : 1 : error_seen = true;
3607 : : }
3608 : 773 : else if (early_clobber_p
3609 : 6 : && i != match
3610 : 4 : && output_hregno == input_hregno)
3611 : : {
3612 : 2 : error_at (locus, "invalid hard register usage between "
3613 : : "earlyclobber operand and input operand");
3614 : 2 : error_seen = true;
3615 : : }
3616 : : }
3617 : : }
3618 : :
3619 : 71587 : if (! allows_reg
3620 : 71587 : && (allows_mem
3621 : 0 : || is_inout
3622 : 0 : || (DECL_P (val)
3623 : 0 : && REG_P (DECL_RTL (val))
3624 : 0 : && GET_MODE (DECL_RTL (val)) != TYPE_MODE (type))))
3625 : 6275 : mark_addressable (val);
3626 : : }
3627 : :
3628 : 155665 : for (i = 0; i < ninputs; ++i)
3629 : : {
3630 : 51875 : bool allows_reg, allows_mem;
3631 : 51875 : const char *constraint;
3632 : :
3633 : 51875 : constraint = constraints[i + noutputs];
3634 : 51875 : if (! parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
3635 : 51875 : constraints.address (),
3636 : : &allows_mem, &allows_reg))
3637 : 0 : return;
3638 : :
3639 : 51875 : if (! allows_reg && allows_mem)
3640 : 6959 : mark_addressable (input_tvec[i]);
3641 : : }
3642 : :
3643 : : /* Second pass evaluates arguments. */
3644 : :
3645 : : /* Make sure stack is consistent for asm goto. */
3646 : 103790 : if (nlabels > 0)
3647 : 445 : do_pending_stack_adjust ();
3648 : 103790 : int old_generating_concat_p = generating_concat_p;
3649 : :
3650 : : /* Vector of RTX's of evaluated output operands. */
3651 : 207580 : auto_vec<rtx, MAX_RECOG_OPERANDS> output_rvec;
3652 : 103790 : auto_vec<int, MAX_RECOG_OPERANDS> inout_opnum;
3653 : 103790 : rtx_insn *after_rtl_seq = NULL, *after_rtl_end = NULL;
3654 : :
3655 : 103790 : output_rvec.safe_grow (noutputs, true);
3656 : :
3657 : 175377 : for (i = 0; i < noutputs; ++i)
3658 : : {
3659 : 71587 : tree val = output_tvec[i];
3660 : 71587 : tree type = TREE_TYPE (val);
3661 : 71587 : bool is_inout, allows_reg, allows_mem, ok;
3662 : 71587 : rtx op;
3663 : :
3664 : 71587 : ok = parse_output_constraint (&constraints[i], i, ninputs,
3665 : : noutputs, &allows_mem, &allows_reg,
3666 : : &is_inout);
3667 : 71587 : gcc_assert (ok);
3668 : :
3669 : : /* If an output operand is not a decl or indirect ref and our constraint
3670 : : allows a register, make a temporary to act as an intermediate.
3671 : : Make the asm insn write into that, then we will copy it to
3672 : : the real output operand. Likewise for promoted variables. */
3673 : :
3674 : 71587 : generating_concat_p = 0;
3675 : :
3676 : 71587 : gcc_assert (TREE_CODE (val) != INDIRECT_REF);
3677 : 71587 : if (((TREE_CODE (val) == MEM_REF
3678 : 2555 : && TREE_CODE (TREE_OPERAND (val, 0)) != ADDR_EXPR)
3679 : 2454 : && allows_mem)
3680 : 71193 : || (DECL_P (val)
3681 : 7545 : && (allows_mem || REG_P (DECL_RTL (val)))
3682 : 7799 : && ! (REG_P (DECL_RTL (val))
3683 : 957 : && GET_MODE (DECL_RTL (val)) != TYPE_MODE (type)))
3684 : 64351 : || ! allows_reg
3685 : 64147 : || is_inout
3686 : 64147 : || TREE_ADDRESSABLE (type)
3687 : 135734 : || (!tree_fits_poly_int64_p (TYPE_SIZE (type))
3688 : 0 : && !known_size_p (max_int_size_in_bytes (type))))
3689 : : {
3690 : 7440 : op = expand_expr (val, NULL_RTX, VOIDmode,
3691 : : !allows_reg ? EXPAND_MEMORY : EXPAND_WRITE);
3692 : 7440 : if (MEM_P (op))
3693 : 6483 : op = validize_mem (op);
3694 : :
3695 : 7440 : if (! allows_reg && !MEM_P (op))
3696 : : {
3697 : 0 : error_at (locus, "output number %d not directly addressable", i);
3698 : 0 : error_seen = true;
3699 : : }
3700 : 7440 : if ((! allows_mem && MEM_P (op) && GET_MODE (op) != BLKmode)
3701 : 7440 : || GET_CODE (op) == CONCAT)
3702 : : {
3703 : 0 : rtx old_op = op;
3704 : 0 : op = gen_reg_rtx (GET_MODE (op));
3705 : :
3706 : 0 : generating_concat_p = old_generating_concat_p;
3707 : :
3708 : 0 : if (is_inout)
3709 : 0 : emit_move_insn (op, old_op);
3710 : :
3711 : 0 : push_to_sequence2 (after_rtl_seq, after_rtl_end);
3712 : 0 : emit_move_insn (old_op, op);
3713 : 0 : after_rtl_seq = get_insns ();
3714 : 0 : after_rtl_end = get_last_insn ();
3715 : 0 : end_sequence ();
3716 : : }
3717 : : }
3718 : : else
3719 : : {
3720 : 64147 : op = assign_temp (type, 0, 1);
3721 : 64147 : op = validize_mem (op);
3722 : 64147 : if (!MEM_P (op) && TREE_CODE (val) == SSA_NAME)
3723 : 60633 : set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (val), op);
3724 : :
3725 : 64147 : generating_concat_p = old_generating_concat_p;
3726 : :
3727 : 64147 : push_to_sequence2 (after_rtl_seq, after_rtl_end);
3728 : 64147 : expand_assignment (val, make_tree (type, op), false);
3729 : 64147 : after_rtl_seq = get_insns ();
3730 : 64147 : after_rtl_end = get_last_insn ();
3731 : 64147 : end_sequence ();
3732 : : }
3733 : 71587 : output_rvec[i] = op;
3734 : :
3735 : 71587 : if (is_inout)
3736 : 0 : inout_opnum.safe_push (i);
3737 : : }
3738 : :
3739 : 103790 : const char *str = gimple_asm_string (stmt);
3740 : 103790 : if (error_seen)
3741 : : {
3742 : 19 : ninputs = 0;
3743 : 19 : noutputs = 0;
3744 : 19 : inout_opnum.truncate (0);
3745 : 19 : output_rvec.truncate (0);
3746 : 19 : clobber_rvec.truncate (0);
3747 : 19 : constraints.truncate (0);
3748 : 19 : CLEAR_HARD_REG_SET (clobbered_regs);
3749 : : str = "";
3750 : : }
3751 : :
3752 : 207580 : auto_vec<rtx, MAX_RECOG_OPERANDS> input_rvec;
3753 : 103790 : auto_vec<machine_mode, MAX_RECOG_OPERANDS> input_mode;
3754 : :
3755 : 103790 : input_rvec.safe_grow (ninputs, true);
3756 : 103790 : input_mode.safe_grow (ninputs, true);
3757 : :
3758 : 103790 : generating_concat_p = 0;
3759 : :
3760 : 155662 : for (i = 0; i < ninputs; ++i)
3761 : : {
3762 : 51872 : tree val = input_tvec[i];
3763 : 51872 : tree type = TREE_TYPE (val);
3764 : 51872 : bool allows_reg, allows_mem, ok;
3765 : 51872 : const char *constraint;
3766 : 51872 : rtx op;
3767 : :
3768 : 51872 : constraint = constraints[i + noutputs];
3769 : 51872 : ok = parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
3770 : 51872 : constraints.address (),
3771 : : &allows_mem, &allows_reg);
3772 : 51872 : gcc_assert (ok);
3773 : :
3774 : : /* EXPAND_INITIALIZER will not generate code for valid initializer
3775 : : constants, but will still generate code for other types of operand.
3776 : : This is the behavior we want for constant constraints. */
3777 : 51872 : op = expand_expr (val, NULL_RTX, VOIDmode,
3778 : : allows_reg ? EXPAND_NORMAL
3779 : 8194 : : allows_mem ? EXPAND_MEMORY
3780 : : : EXPAND_INITIALIZER);
3781 : :
3782 : : /* Never pass a CONCAT to an ASM. */
3783 : 51872 : if (GET_CODE (op) == CONCAT)
3784 : 2 : op = force_reg (GET_MODE (op), op);
3785 : 51870 : else if (MEM_P (op))
3786 : 12107 : op = validize_mem (op);
3787 : :
3788 : 51872 : if (asm_operand_ok (op, constraint, NULL) <= 0)
3789 : : {
3790 : 24483 : if (allows_reg && TYPE_MODE (type) != BLKmode)
3791 : 24096 : op = force_reg (TYPE_MODE (type), op);
3792 : 387 : else if (!allows_mem)
3793 : 20 : warning_at (locus, 0, "%<asm%> operand %d probably does not match "
3794 : : "constraints", i + noutputs);
3795 : 367 : else if (MEM_P (op))
3796 : : {
3797 : : /* We won't recognize either volatile memory or memory
3798 : : with a queued address as available a memory_operand
3799 : : at this point. Ignore it: clearly this *is* a memory. */
3800 : : }
3801 : : else
3802 : 0 : gcc_unreachable ();
3803 : : }
3804 : 51872 : input_rvec[i] = op;
3805 : 51872 : input_mode[i] = TYPE_MODE (type);
3806 : : }
3807 : :
3808 : : /* For in-out operands, copy output rtx to input rtx. */
3809 : 103790 : unsigned ninout = inout_opnum.length ();
3810 : 103790 : for (i = 0; i < ninout; i++)
3811 : : {
3812 : 0 : int j = inout_opnum[i];
3813 : 0 : rtx o = output_rvec[j];
3814 : :
3815 : 0 : input_rvec.safe_push (o);
3816 : 0 : input_mode.safe_push (GET_MODE (o));
3817 : :
3818 : 0 : char buffer[16];
3819 : 0 : sprintf (buffer, "%d", j);
3820 : 0 : constraints.safe_push (ggc_strdup (buffer));
3821 : : }
3822 : 103790 : ninputs += ninout;
3823 : :
3824 : : /* Sometimes we wish to automatically clobber registers across an asm.
3825 : : Case in point is when the i386 backend moved from cc0 to a hard reg --
3826 : : maintaining source-level compatibility means automatically clobbering
3827 : : the flags register. */
3828 : 103790 : rtx_insn *after_md_seq = NULL;
3829 : 207580 : auto_vec<rtx> use_rvec;
3830 : 103790 : if (targetm.md_asm_adjust)
3831 : 103790 : after_md_seq
3832 : 103790 : = targetm.md_asm_adjust (output_rvec, input_rvec, input_mode,
3833 : : constraints, use_rvec, clobber_rvec,
3834 : : clobbered_regs, locus);
3835 : :
3836 : : /* Do not allow the hook to change the output and input count,
3837 : : lest it mess up the operand numbering. */
3838 : 207580 : gcc_assert (output_rvec.length() == noutputs);
3839 : 207580 : gcc_assert (input_rvec.length() == ninputs);
3840 : 207580 : gcc_assert (constraints.length() == noutputs + ninputs);
3841 : :
3842 : : /* But it certainly can adjust the uses and clobbers. */
3843 : 103790 : unsigned nuses = use_rvec.length ();
3844 : 103790 : unsigned nclobbers = clobber_rvec.length ();
3845 : :
3846 : : /* Third pass checks for easy conflicts. */
3847 : : /* ??? Why are we doing this on trees instead of rtx. */
3848 : :
3849 : 103790 : bool clobber_conflict_found = 0;
3850 : 175371 : for (i = 0; i < noutputs; ++i)
3851 : 71581 : if (tree_conflicts_with_clobbers_p (output_tvec[i], &clobbered_regs, locus))
3852 : 10 : clobber_conflict_found = 1;
3853 : 155662 : for (i = 0; i < ninputs - ninout; ++i)
3854 : 51872 : if (tree_conflicts_with_clobbers_p (input_tvec[i], &clobbered_regs, locus))
3855 : 11 : clobber_conflict_found = 1;
3856 : :
3857 : : /* Make vectors for the expression-rtx, constraint strings,
3858 : : and named operands. */
3859 : :
3860 : 103790 : rtvec argvec = rtvec_alloc (ninputs);
3861 : 103790 : rtvec constraintvec = rtvec_alloc (ninputs);
3862 : 103790 : rtvec labelvec = rtvec_alloc (nlabels);
3863 : :
3864 : 136570 : rtx body = gen_rtx_ASM_OPERANDS ((noutputs == 0 ? VOIDmode
3865 : : : GET_MODE (output_rvec[0])),
3866 : : ggc_strdup (str),
3867 : : "", 0, argvec, constraintvec,
3868 : : labelvec, locus);
3869 : 103790 : MEM_VOLATILE_P (body) = gimple_asm_volatile_p (stmt);
3870 : :
3871 : 155662 : for (i = 0; i < ninputs; ++i)
3872 : : {
3873 : 51872 : ASM_OPERANDS_INPUT (body, i) = input_rvec[i];
3874 : 103744 : ASM_OPERANDS_INPUT_CONSTRAINT_EXP (body, i)
3875 : 51872 : = gen_rtx_ASM_INPUT_loc (input_mode[i],
3876 : : constraints[i + noutputs],
3877 : : locus);
3878 : : }
3879 : :
3880 : : /* Copy labels to the vector. */
3881 : 103790 : rtx_code_label *fallthru_label = NULL;
3882 : 103790 : if (nlabels > 0)
3883 : : {
3884 : 445 : basic_block fallthru_bb = NULL;
3885 : 445 : edge fallthru = find_fallthru_edge (gimple_bb (stmt)->succs);
3886 : 445 : if (fallthru)
3887 : 445 : fallthru_bb = fallthru->dest;
3888 : :
3889 : 1133 : for (i = 0; i < nlabels; ++i)
3890 : : {
3891 : 688 : tree label = TREE_VALUE (gimple_asm_label_op (stmt, i));
3892 : 688 : rtx_insn *r;
3893 : : /* If asm goto has any labels in the fallthru basic block, use
3894 : : a label that we emit immediately after the asm goto. Expansion
3895 : : may insert further instructions into the same basic block after
3896 : : asm goto and if we don't do this, insertion of instructions on
3897 : : the fallthru edge might misbehave. See PR58670. */
3898 : 688 : if (fallthru_bb && label_to_block (cfun, label) == fallthru_bb)
3899 : : {
3900 : 240 : if (fallthru_label == NULL_RTX)
3901 : 235 : fallthru_label = gen_label_rtx ();
3902 : : r = fallthru_label;
3903 : : }
3904 : : else
3905 : 448 : r = label_rtx (label);
3906 : 688 : ASM_OPERANDS_LABEL (body, i) = gen_rtx_LABEL_REF (Pmode, r);
3907 : : }
3908 : : }
3909 : :
3910 : : /* Now, for each output, construct an rtx
3911 : : (set OUTPUT (asm_operands INSN OUTPUTCONSTRAINT OUTPUTNUMBER
3912 : : ARGVEC CONSTRAINTS OPNAMES))
3913 : : If there is more than one, put them inside a PARALLEL. */
3914 : :
3915 : 103790 : if (noutputs == 0 && nuses == 0 && nclobbers == 0)
3916 : : {
3917 : : /* No output operands: put in a raw ASM_OPERANDS rtx. */
3918 : 0 : if (nlabels > 0)
3919 : 0 : emit_jump_insn (body);
3920 : : else
3921 : 0 : emit_insn (body);
3922 : : }
3923 : 103790 : else if (noutputs == 1 && nuses == 0 && nclobbers == 0)
3924 : : {
3925 : 62 : ASM_OPERANDS_OUTPUT_CONSTRAINT (body) = constraints[0];
3926 : 62 : if (nlabels > 0)
3927 : 0 : emit_jump_insn (gen_rtx_SET (output_rvec[0], body));
3928 : : else
3929 : 62 : emit_insn (gen_rtx_SET (output_rvec[0], body));
3930 : : }
3931 : : else
3932 : : {
3933 : 103728 : rtx obody = body;
3934 : 103728 : int num = noutputs;
3935 : :
3936 : 103728 : if (num == 0)
3937 : 71010 : num = 1;
3938 : :
3939 : 103728 : body = gen_rtx_PARALLEL (VOIDmode,
3940 : : rtvec_alloc (num + nuses + nclobbers));
3941 : :
3942 : : /* For each output operand, store a SET. */
3943 : 175247 : for (i = 0; i < noutputs; ++i)
3944 : : {
3945 : 71519 : rtx src, o = output_rvec[i];
3946 : 71519 : if (i == 0)
3947 : : {
3948 : 32718 : ASM_OPERANDS_OUTPUT_CONSTRAINT (obody) = constraints[0];
3949 : 32718 : src = obody;
3950 : : }
3951 : : else
3952 : : {
3953 : 38801 : src = gen_rtx_ASM_OPERANDS (GET_MODE (o),
3954 : : ASM_OPERANDS_TEMPLATE (obody),
3955 : : constraints[i], i, argvec,
3956 : : constraintvec, labelvec, locus);
3957 : 38801 : MEM_VOLATILE_P (src) = gimple_asm_volatile_p (stmt);
3958 : : }
3959 : 71519 : XVECEXP (body, 0, i) = gen_rtx_SET (o, src);
3960 : : }
3961 : :
3962 : : /* If there are no outputs (but there are some clobbers)
3963 : : store the bare ASM_OPERANDS into the PARALLEL. */
3964 : 103728 : if (i == 0)
3965 : 71010 : XVECEXP (body, 0, i++) = obody;
3966 : :
3967 : : /* Add the uses specified by the target hook. No checking should
3968 : : be needed since this doesn't come directly from user code. */
3969 : 103728 : for (rtx use : use_rvec)
3970 : 0 : XVECEXP (body, 0, i++) = gen_rtx_USE (VOIDmode, use);
3971 : :
3972 : : /* Store (clobber REG) for each clobbered register specified. */
3973 : 287730 : for (unsigned j = 0; j < nclobbers; ++j)
3974 : : {
3975 : 184002 : rtx clobbered_reg = clobber_rvec[j];
3976 : :
3977 : : /* Do sanity check for overlap between clobbers and respectively
3978 : : input and outputs that hasn't been handled. Such overlap
3979 : : should have been detected and reported above. */
3980 : 184002 : if (!clobber_conflict_found && REG_P (clobbered_reg))
3981 : : {
3982 : : /* We test the old body (obody) contents to avoid
3983 : : tripping over the under-construction body. */
3984 : 217625 : for (unsigned k = 0; k < noutputs; ++k)
3985 : 72462 : if (reg_overlap_mentioned_p (clobbered_reg, output_rvec[k]))
3986 : 0 : internal_error ("%<asm%> clobber conflict with "
3987 : : "output operand");
3988 : :
3989 : 199806 : for (unsigned k = 0; k < ninputs - ninout; ++k)
3990 : 54643 : if (reg_overlap_mentioned_p (clobbered_reg, input_rvec[k]))
3991 : 0 : internal_error ("%<asm%> clobber conflict with "
3992 : : "input operand");
3993 : : }
3994 : :
3995 : 184002 : XVECEXP (body, 0, i++) = gen_rtx_CLOBBER (VOIDmode, clobbered_reg);
3996 : : }
3997 : :
3998 : 103728 : if (nlabels > 0)
3999 : 445 : emit_jump_insn (body);
4000 : : else
4001 : 103283 : emit_insn (body);
4002 : : }
4003 : :
4004 : 103790 : generating_concat_p = old_generating_concat_p;
4005 : :
4006 : 103790 : if (fallthru_label)
4007 : 235 : emit_label (fallthru_label);
4008 : :
4009 : 103790 : if (after_md_seq)
4010 : 71 : emit_insn (after_md_seq);
4011 : 103790 : if (after_rtl_seq)
4012 : : {
4013 : 26034 : if (nlabels == 0)
4014 : 25909 : emit_insn (after_rtl_seq);
4015 : : else
4016 : : {
4017 : 125 : edge e;
4018 : 125 : edge_iterator ei;
4019 : 125 : unsigned int cnt = EDGE_COUNT (gimple_bb (stmt)->succs);
4020 : :
4021 : 458 : FOR_EACH_EDGE (e, ei, gimple_bb (stmt)->succs)
4022 : : {
4023 : 333 : rtx_insn *copy;
4024 : 333 : if (--cnt == 0)
4025 : : copy = after_rtl_seq;
4026 : : else
4027 : : {
4028 : 208 : start_sequence ();
4029 : 208 : duplicate_insn_chain (after_rtl_seq, after_rtl_end,
4030 : : NULL, NULL);
4031 : 208 : copy = end_sequence ();
4032 : : }
4033 : 333 : prepend_insn_to_edge (copy, e);
4034 : : }
4035 : : }
4036 : : }
4037 : :
4038 : 103790 : free_temp_slots ();
4039 : 103790 : crtl->has_asm_statement = 1;
4040 : 103795 : }
4041 : :
4042 : : /* Emit code to jump to the address
4043 : : specified by the pointer expression EXP. */
4044 : :
4045 : : static void
4046 : 394 : expand_computed_goto (tree exp)
4047 : : {
4048 : 394 : rtx x = expand_normal (exp);
4049 : :
4050 : 394 : do_pending_stack_adjust ();
4051 : 394 : emit_indirect_jump (x);
4052 : 394 : }
4053 : :
4054 : : /* Generate RTL code for a `goto' statement with target label LABEL.
4055 : : LABEL should be a LABEL_DECL tree node that was or will later be
4056 : : defined with `expand_label'. */
4057 : :
4058 : : static void
4059 : 0 : expand_goto (tree label)
4060 : : {
4061 : 0 : if (flag_checking)
4062 : : {
4063 : : /* Check for a nonlocal goto to a containing function. Should have
4064 : : gotten translated to __builtin_nonlocal_goto. */
4065 : 0 : tree context = decl_function_context (label);
4066 : 0 : gcc_assert (!context || context == current_function_decl);
4067 : : }
4068 : :
4069 : 0 : emit_jump (jump_target_rtx (label));
4070 : 0 : }
4071 : :
4072 : : /* Output a return with no value. */
4073 : :
4074 : : static void
4075 : 816584 : expand_null_return_1 (void)
4076 : : {
4077 : 816584 : clear_pending_stack_adjust ();
4078 : 816584 : do_pending_stack_adjust ();
4079 : 816584 : emit_jump (return_label);
4080 : 816584 : }
4081 : :
4082 : : /* Generate RTL to return from the current function, with no value.
4083 : : (That is, we do not do anything about returning any value.) */
4084 : :
4085 : : void
4086 : 72999 : expand_null_return (void)
4087 : : {
4088 : : /* If this function was declared to return a value, but we
4089 : : didn't, clobber the return registers so that they are not
4090 : : propagated live to the rest of the function. */
4091 : 72999 : clobber_return_register ();
4092 : :
4093 : 72999 : expand_null_return_1 ();
4094 : 72999 : }
4095 : :
4096 : : /* Generate RTL to return from the current function, with value VAL. */
4097 : :
4098 : : static void
4099 : 743585 : expand_value_return (rtx val)
4100 : : {
4101 : : /* Copy the value to the return location unless it's already there. */
4102 : :
4103 : 743585 : tree decl = DECL_RESULT (current_function_decl);
4104 : 743585 : rtx return_reg = DECL_RTL (decl);
4105 : 743585 : if (return_reg != val)
4106 : : {
4107 : 427673 : tree funtype = TREE_TYPE (current_function_decl);
4108 : 427673 : tree type = TREE_TYPE (decl);
4109 : 427673 : int unsignedp = TYPE_UNSIGNED (type);
4110 : 427673 : machine_mode old_mode = DECL_MODE (decl);
4111 : 427673 : machine_mode mode;
4112 : 427673 : if (DECL_BY_REFERENCE (decl))
4113 : 0 : mode = promote_function_mode (type, old_mode, &unsignedp, funtype, 2);
4114 : : else
4115 : 427673 : mode = promote_function_mode (type, old_mode, &unsignedp, funtype, 1);
4116 : :
4117 : 427673 : if (mode != old_mode)
4118 : : {
4119 : : /* Some ABIs require scalar floating point modes to be returned
4120 : : in a wider scalar integer mode. We need to explicitly
4121 : : reinterpret to an integer mode of the correct precision
4122 : : before extending to the desired result. */
4123 : 8 : if (SCALAR_INT_MODE_P (mode)
4124 : 8 : && SCALAR_FLOAT_MODE_P (old_mode)
4125 : 8 : && known_gt (GET_MODE_SIZE (mode), GET_MODE_SIZE (old_mode)))
4126 : 0 : val = convert_float_to_wider_int (mode, old_mode, val);
4127 : : else
4128 : 8 : val = convert_modes (mode, old_mode, val, unsignedp);
4129 : : }
4130 : :
4131 : 427673 : if (GET_CODE (return_reg) == PARALLEL)
4132 : 2955 : emit_group_load (return_reg, val, type, int_size_in_bytes (type));
4133 : : else
4134 : 424718 : emit_move_insn (return_reg, val);
4135 : : }
4136 : :
4137 : 743585 : expand_null_return_1 ();
4138 : 743585 : }
4139 : :
4140 : : /* Generate RTL to evaluate the expression RETVAL and return it
4141 : : from the current function. */
4142 : :
4143 : : static void
4144 : 746353 : expand_return (tree retval)
4145 : : {
4146 : 746353 : rtx result_rtl;
4147 : 746353 : rtx val = 0;
4148 : 746353 : tree retval_rhs;
4149 : :
4150 : : /* If function wants no value, give it none. */
4151 : 746353 : if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl))))
4152 : : {
4153 : 0 : expand_normal (retval);
4154 : 0 : expand_null_return ();
4155 : 0 : return;
4156 : : }
4157 : :
4158 : 746353 : if (retval == error_mark_node)
4159 : : {
4160 : : /* Treat this like a return of no value from a function that
4161 : : returns a value. */
4162 : 0 : expand_null_return ();
4163 : 0 : return;
4164 : : }
4165 : 746353 : else if ((TREE_CODE (retval) == MODIFY_EXPR
4166 : 746353 : || TREE_CODE (retval) == INIT_EXPR)
4167 : 746353 : && TREE_CODE (TREE_OPERAND (retval, 0)) == RESULT_DECL)
4168 : 684118 : retval_rhs = TREE_OPERAND (retval, 1);
4169 : : else
4170 : : retval_rhs = retval;
4171 : :
4172 : 746353 : result_rtl = DECL_RTL (DECL_RESULT (current_function_decl));
4173 : :
4174 : : /* If we are returning the RESULT_DECL, then the value has already
4175 : : been stored into it, so we don't have to do anything special. */
4176 : 746353 : if (TREE_CODE (retval_rhs) == RESULT_DECL)
4177 : 62235 : expand_value_return (result_rtl);
4178 : :
4179 : : /* If the result is an aggregate that is being returned in one (or more)
4180 : : registers, load the registers here. */
4181 : :
4182 : 684118 : else if (retval_rhs != 0
4183 : 684118 : && TYPE_MODE (TREE_TYPE (retval_rhs)) == BLKmode
4184 : 5442 : && REG_P (result_rtl))
4185 : : {
4186 : 3989 : val = copy_blkmode_to_reg (GET_MODE (result_rtl), retval_rhs);
4187 : 3989 : if (val)
4188 : : {
4189 : : /* Use the mode of the result value on the return register. */
4190 : 1221 : PUT_MODE (result_rtl, GET_MODE (val));
4191 : 1221 : expand_value_return (val);
4192 : : }
4193 : : else
4194 : 2768 : expand_null_return ();
4195 : : }
4196 : 680129 : else if (retval_rhs != 0
4197 : 680129 : && !VOID_TYPE_P (TREE_TYPE (retval_rhs))
4198 : 680129 : && (REG_P (result_rtl)
4199 : 5608 : || (GET_CODE (result_rtl) == PARALLEL)))
4200 : : {
4201 : : /* Compute the return value into a temporary (usually a pseudo reg). */
4202 : 677476 : val
4203 : 677476 : = assign_temp (TREE_TYPE (DECL_RESULT (current_function_decl)), 0, 1);
4204 : 677476 : val = expand_expr (retval_rhs, val, GET_MODE (val), EXPAND_NORMAL);
4205 : 677476 : val = force_not_mem (val);
4206 : 677476 : expand_value_return (val);
4207 : : }
4208 : : else
4209 : : {
4210 : : /* No hard reg used; calculate value into hard return reg. */
4211 : 2653 : expand_expr (retval, const0_rtx, VOIDmode, EXPAND_NORMAL);
4212 : 2653 : expand_value_return (result_rtl);
4213 : : }
4214 : : }
4215 : :
4216 : : /* Expand a clobber of LHS. If LHS is stored it in a multi-part
4217 : : register, tell the rtl optimizers that its value is no longer
4218 : : needed. */
4219 : :
4220 : : static void
4221 : 1555593 : expand_clobber (tree lhs)
4222 : : {
4223 : 1555593 : if (DECL_P (lhs))
4224 : : {
4225 : 1280458 : rtx decl_rtl = DECL_RTL_IF_SET (lhs);
4226 : 1280414 : if (decl_rtl && REG_P (decl_rtl))
4227 : : {
4228 : 203014 : machine_mode decl_mode = GET_MODE (decl_rtl);
4229 : 406028 : if (maybe_gt (GET_MODE_SIZE (decl_mode),
4230 : : REGMODE_NATURAL_SIZE (decl_mode)))
4231 : 157230 : emit_clobber (decl_rtl);
4232 : : }
4233 : : }
4234 : 1555593 : }
4235 : :
4236 : : /* A subroutine of expand_gimple_stmt, expanding one gimple statement
4237 : : STMT that doesn't require special handling for outgoing edges. That
4238 : : is no tailcalls and no GIMPLE_COND. */
4239 : :
4240 : : static void
4241 : 31410557 : expand_gimple_stmt_1 (gimple *stmt)
4242 : : {
4243 : 31410557 : tree op0;
4244 : :
4245 : 31410557 : set_curr_insn_location (gimple_location (stmt));
4246 : :
4247 : 31410557 : switch (gimple_code (stmt))
4248 : : {
4249 : 394 : case GIMPLE_GOTO:
4250 : 394 : op0 = gimple_goto_dest (stmt);
4251 : 394 : if (TREE_CODE (op0) == LABEL_DECL)
4252 : 0 : expand_goto (op0);
4253 : : else
4254 : 394 : expand_computed_goto (op0);
4255 : : break;
4256 : 630866 : case GIMPLE_LABEL:
4257 : 630866 : expand_label (gimple_label_label (as_a <glabel *> (stmt)));
4258 : 630866 : break;
4259 : : case GIMPLE_NOP:
4260 : : case GIMPLE_PREDICT:
4261 : : break;
4262 : 9843 : case GIMPLE_SWITCH:
4263 : 9843 : {
4264 : 9843 : gswitch *swtch = as_a <gswitch *> (stmt);
4265 : 9843 : if (gimple_switch_num_labels (swtch) == 1)
4266 : 0 : expand_goto (CASE_LABEL (gimple_switch_default_label (swtch)));
4267 : : else
4268 : 9843 : expand_case (swtch);
4269 : : }
4270 : : break;
4271 : 106600 : case GIMPLE_ASM:
4272 : 106600 : expand_asm_stmt (as_a <gasm *> (stmt));
4273 : 106600 : break;
4274 : 6773071 : case GIMPLE_CALL:
4275 : 6773071 : expand_call_stmt (as_a <gcall *> (stmt));
4276 : 6773071 : break;
4277 : :
4278 : 816584 : case GIMPLE_RETURN:
4279 : 816584 : {
4280 : 816584 : op0 = gimple_return_retval (as_a <greturn *> (stmt));
4281 : :
4282 : : /* If a return doesn't have a location, it very likely represents
4283 : : multiple user returns so we cannot let it inherit the location
4284 : : of the last statement of the previous basic block in RTL. */
4285 : 816584 : if (!gimple_has_location (stmt))
4286 : 219149 : set_curr_insn_location (cfun->function_end_locus);
4287 : :
4288 : 816584 : if (op0 && op0 != error_mark_node)
4289 : : {
4290 : 746353 : tree result = DECL_RESULT (current_function_decl);
4291 : :
4292 : : /* If we are not returning the current function's RESULT_DECL,
4293 : : build an assignment to it. */
4294 : 746353 : if (op0 != result)
4295 : : {
4296 : : /* I believe that a function's RESULT_DECL is unique. */
4297 : 684118 : gcc_assert (TREE_CODE (op0) != RESULT_DECL);
4298 : :
4299 : : /* ??? We'd like to use simply expand_assignment here,
4300 : : but this fails if the value is of BLKmode but the return
4301 : : decl is a register. expand_return has special handling
4302 : : for this combination, which eventually should move
4303 : : to common code. See comments there. Until then, let's
4304 : : build a modify expression :-/ */
4305 : 684118 : op0 = build2 (MODIFY_EXPR, TREE_TYPE (result),
4306 : : result, op0);
4307 : : }
4308 : : }
4309 : :
4310 : 746353 : if (!op0)
4311 : 70231 : expand_null_return ();
4312 : : else
4313 : 746353 : expand_return (op0);
4314 : : }
4315 : : break;
4316 : :
4317 : 23028795 : case GIMPLE_ASSIGN:
4318 : 23028795 : {
4319 : 23028795 : gassign *assign_stmt = as_a <gassign *> (stmt);
4320 : 23028795 : tree lhs = gimple_assign_lhs (assign_stmt);
4321 : :
4322 : : /* Tree expand used to fiddle with |= and &= of two bitfield
4323 : : COMPONENT_REFs here. This can't happen with gimple, the LHS
4324 : : of binary assigns must be a gimple reg. */
4325 : :
4326 : 23028795 : if (TREE_CODE (lhs) != SSA_NAME
4327 : 36456063 : || gimple_assign_rhs_class (assign_stmt) == GIMPLE_SINGLE_RHS)
4328 : : {
4329 : 17242711 : tree rhs = gimple_assign_rhs1 (assign_stmt);
4330 : 17242711 : gcc_assert (gimple_assign_rhs_class (assign_stmt)
4331 : : == GIMPLE_SINGLE_RHS);
4332 : 32849502 : if (gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (rhs)
4333 : : /* Do not put locations on possibly shared trees. */
4334 : 23164598 : && !is_gimple_min_invariant (rhs))
4335 : 4825300 : SET_EXPR_LOCATION (rhs, gimple_location (stmt));
4336 : 17242711 : if (TREE_CLOBBER_P (rhs))
4337 : : /* This is a clobber to mark the going out of scope for
4338 : : this LHS. */
4339 : 1555593 : expand_clobber (lhs);
4340 : : else
4341 : 15687118 : expand_assignment (lhs, rhs,
4342 : 15687118 : gimple_assign_nontemporal_move_p (
4343 : : assign_stmt));
4344 : : }
4345 : : else
4346 : : {
4347 : 5786084 : rtx target, temp;
4348 : 5786084 : gcc_assert (!gimple_assign_nontemporal_move_p (assign_stmt));
4349 : 5786084 : bool promoted = false;
4350 : :
4351 : 5786084 : target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
4352 : 5786084 : if (GET_CODE (target) == SUBREG && SUBREG_PROMOTED_VAR_P (target))
4353 : : promoted = true;
4354 : :
4355 : : /* If we store into a promoted register, don't directly
4356 : : expand to target. */
4357 : : temp = promoted ? NULL_RTX : target;
4358 : 11572168 : temp = expand_expr_real_gassign (assign_stmt, temp,
4359 : 5786084 : GET_MODE (target), EXPAND_NORMAL);
4360 : :
4361 : 5786084 : if (temp == target)
4362 : : ;
4363 : 779766 : else if (promoted)
4364 : : {
4365 : 3 : int unsignedp = SUBREG_PROMOTED_SIGN (target);
4366 : : /* If TEMP is a VOIDmode constant, use convert_modes to make
4367 : : sure that we properly convert it. */
4368 : 3 : if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode)
4369 : : {
4370 : 0 : temp = convert_modes (GET_MODE (target),
4371 : 0 : TYPE_MODE (TREE_TYPE (lhs)),
4372 : : temp, unsignedp);
4373 : 0 : temp = convert_modes (GET_MODE (SUBREG_REG (target)),
4374 : 0 : GET_MODE (target), temp, unsignedp);
4375 : : }
4376 : :
4377 : 3 : convert_move (SUBREG_REG (target), temp, unsignedp);
4378 : : }
4379 : : else
4380 : : {
4381 : 779763 : temp = force_operand (temp, target);
4382 : 779763 : if (temp == target)
4383 : : ;
4384 : 779763 : else if (GET_MODE (target) != BLKmode)
4385 : 779762 : emit_move_insn (target, temp);
4386 : : else
4387 : 1 : emit_block_move (target, temp, expr_size (lhs),
4388 : : BLOCK_OP_NORMAL);
4389 : : }
4390 : : }
4391 : : }
4392 : : break;
4393 : :
4394 : 0 : default:
4395 : 0 : gcc_unreachable ();
4396 : : }
4397 : 31410557 : }
4398 : :
4399 : : /* Expand one gimple statement STMT and return the last RTL instruction
4400 : : before any of the newly generated ones.
4401 : :
4402 : : In addition to generating the necessary RTL instructions this also
4403 : : sets REG_EH_REGION notes if necessary and sets the current source
4404 : : location for diagnostics. */
4405 : :
4406 : : static rtx_insn *
4407 : 31410557 : expand_gimple_stmt (gimple *stmt)
4408 : : {
4409 : 31410557 : location_t saved_location = input_location;
4410 : 31410557 : rtx_insn *last = get_last_insn ();
4411 : 31410557 : int lp_nr;
4412 : :
4413 : 31410557 : gcc_assert (cfun);
4414 : :
4415 : : /* We need to save and restore the current source location so that errors
4416 : : discovered during expansion are emitted with the right location. But
4417 : : it would be better if the diagnostic routines used the source location
4418 : : embedded in the tree nodes rather than globals. */
4419 : 31410557 : if (gimple_has_location (stmt))
4420 : 27484218 : input_location = gimple_location (stmt);
4421 : :
4422 : 31410557 : expand_gimple_stmt_1 (stmt);
4423 : :
4424 : : /* Free any temporaries used to evaluate this statement. */
4425 : 31410557 : free_temp_slots ();
4426 : :
4427 : 31410557 : input_location = saved_location;
4428 : :
4429 : : /* Mark all insns that may trap. */
4430 : 31410557 : lp_nr = lookup_stmt_eh_lp (stmt);
4431 : 31410557 : if (lp_nr)
4432 : : {
4433 : 724142 : rtx_insn *insn;
4434 : 4238546 : for (insn = next_real_insn (last); insn;
4435 : 3514404 : insn = next_real_insn (insn))
4436 : : {
4437 : 3514404 : if (! find_reg_note (insn, REG_EH_REGION, NULL_RTX)
4438 : : /* If we want exceptions for non-call insns, any
4439 : : may_trap_p instruction may throw. */
4440 : 3514399 : && GET_CODE (PATTERN (insn)) != CLOBBER
4441 : 3514329 : && GET_CODE (PATTERN (insn)) != USE
4442 : 7028733 : && insn_could_throw_p (insn))
4443 : 783126 : make_reg_eh_region_note (insn, 0, lp_nr);
4444 : : }
4445 : : }
4446 : :
4447 : 31410557 : return last;
4448 : : }
4449 : :
4450 : : /* A subroutine of expand_gimple_basic_block. Expand one GIMPLE_CALL
4451 : : that has CALL_EXPR_TAILCALL set. Returns non-null if we actually
4452 : : generated a tail call (something that might be denied by the ABI
4453 : : rules governing the call; see calls.cc).
4454 : :
4455 : : Sets CAN_FALLTHRU if we generated a *conditional* tail call, and
4456 : : can still reach the rest of BB. The case here is __builtin_sqrt,
4457 : : where the NaN result goes through the external function (with a
4458 : : tailcall) and the normal result happens via a sqrt instruction. */
4459 : :
4460 : : static basic_block
4461 : 173635 : expand_gimple_tailcall (basic_block bb, gcall *stmt, bool *can_fallthru)
4462 : : {
4463 : 173635 : rtx_insn *last2, *last;
4464 : 173635 : edge e;
4465 : 173635 : edge_iterator ei;
4466 : 173635 : profile_probability probability;
4467 : :
4468 : 173635 : last2 = last = expand_gimple_stmt (stmt);
4469 : :
4470 : 745875 : for (last = NEXT_INSN (last); last; last = NEXT_INSN (last))
4471 : 696895 : if (CALL_P (last) && SIBLING_CALL_P (last))
4472 : 124655 : goto found;
4473 : :
4474 : 48980 : maybe_dump_rtl_for_gimple_stmt (stmt, last2);
4475 : :
4476 : 48980 : *can_fallthru = true;
4477 : 48980 : return NULL;
4478 : :
4479 : 124655 : found:
4480 : : /* ??? Wouldn't it be better to just reset any pending stack adjust?
4481 : : Any instructions emitted here are about to be deleted. */
4482 : 124655 : do_pending_stack_adjust ();
4483 : :
4484 : : /* Remove any non-eh, non-abnormal edges that don't go to exit. */
4485 : : /* ??? I.e. the fallthrough edge. HOWEVER! If there were to be
4486 : : EH or abnormal edges, we shouldn't have created a tail call in
4487 : : the first place. So it seems to me we should just be removing
4488 : : all edges here, or redirecting the existing fallthru edge to
4489 : : the exit block. */
4490 : :
4491 : 124655 : probability = profile_probability::never ();
4492 : :
4493 : 249309 : for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
4494 : : {
4495 : 124654 : if (!(e->flags & (EDGE_ABNORMAL | EDGE_EH)))
4496 : : {
4497 : 124648 : if (e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
4498 : 61181 : e->dest->count -= e->count ();
4499 : 124648 : probability += e->probability;
4500 : 124648 : expand_remove_edge (e);
4501 : : }
4502 : : else
4503 : 6 : ei_next (&ei);
4504 : : }
4505 : :
4506 : : /* This is somewhat ugly: the call_expr expander often emits instructions
4507 : : after the sibcall (to perform the function return). These confuse the
4508 : : find_many_sub_basic_blocks code, so we need to get rid of these. */
4509 : 124655 : last = NEXT_INSN (last);
4510 : 124655 : gcc_assert (BARRIER_P (last));
4511 : :
4512 : 124655 : *can_fallthru = false;
4513 : 155097 : while (NEXT_INSN (last))
4514 : : {
4515 : : /* For instance an sqrt builtin expander expands if with
4516 : : sibcall in the then and label for `else`. */
4517 : 30442 : if (LABEL_P (NEXT_INSN (last)))
4518 : : {
4519 : 0 : *can_fallthru = true;
4520 : 0 : break;
4521 : : }
4522 : 30442 : delete_insn (NEXT_INSN (last));
4523 : : }
4524 : :
4525 : 124655 : e = make_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun), EDGE_ABNORMAL
4526 : : | EDGE_SIBCALL);
4527 : 124655 : e->probability = probability;
4528 : 124655 : head_end_for_bb[bb->index].second = last;
4529 : 249310 : update_bb_for_insn_chain (head_end_for_bb[bb->index].first,
4530 : 124655 : head_end_for_bb[bb->index].second, bb);
4531 : :
4532 : 124655 : if (NEXT_INSN (last))
4533 : : {
4534 : 0 : bb = create_basic_block (NEXT_INSN (last), get_last_insn (), bb);
4535 : :
4536 : 0 : last = BB_END (bb);
4537 : 0 : if (BARRIER_P (last))
4538 : 0 : BB_END (bb) = PREV_INSN (last);
4539 : : }
4540 : :
4541 : 124655 : maybe_dump_rtl_for_gimple_stmt (stmt, last2);
4542 : :
4543 : 124655 : return bb;
4544 : : }
4545 : :
4546 : : /* Return the difference between the floor and the truncated result of
4547 : : a signed division by OP1 with remainder MOD. */
4548 : : static rtx
4549 : 4 : floor_sdiv_adjust (machine_mode mode, rtx mod, rtx op1)
4550 : : {
4551 : : /* (mod != 0 ? (op1 / mod < 0 ? -1 : 0) : 0) */
4552 : 4 : return gen_rtx_IF_THEN_ELSE
4553 : : (mode, gen_rtx_NE (BImode, mod, const0_rtx),
4554 : : gen_rtx_IF_THEN_ELSE
4555 : : (mode, gen_rtx_LT (BImode,
4556 : : gen_rtx_DIV (mode, op1, mod),
4557 : : const0_rtx),
4558 : : constm1_rtx, const0_rtx),
4559 : : const0_rtx);
4560 : : }
4561 : :
4562 : : /* Return the difference between the ceil and the truncated result of
4563 : : a signed division by OP1 with remainder MOD. */
4564 : : static rtx
4565 : 3 : ceil_sdiv_adjust (machine_mode mode, rtx mod, rtx op1)
4566 : : {
4567 : : /* (mod != 0 ? (op1 / mod > 0 ? 1 : 0) : 0) */
4568 : 3 : return gen_rtx_IF_THEN_ELSE
4569 : : (mode, gen_rtx_NE (BImode, mod, const0_rtx),
4570 : : gen_rtx_IF_THEN_ELSE
4571 : : (mode, gen_rtx_GT (BImode,
4572 : : gen_rtx_DIV (mode, op1, mod),
4573 : : const0_rtx),
4574 : : const1_rtx, const0_rtx),
4575 : : const0_rtx);
4576 : : }
4577 : :
4578 : : /* Return the difference between the ceil and the truncated result of
4579 : : an unsigned division by OP1 with remainder MOD. */
4580 : : static rtx
4581 : 0 : ceil_udiv_adjust (machine_mode mode, rtx mod, rtx op1 ATTRIBUTE_UNUSED)
4582 : : {
4583 : : /* (mod != 0 ? 1 : 0) */
4584 : 0 : return gen_rtx_IF_THEN_ELSE
4585 : : (mode, gen_rtx_NE (BImode, mod, const0_rtx),
4586 : : const1_rtx, const0_rtx);
4587 : : }
4588 : :
4589 : : /* Return the difference between the rounded and the truncated result
4590 : : of a signed division by OP1 with remainder MOD. Halfway cases are
4591 : : rounded away from zero, rather than to the nearest even number. */
4592 : : static rtx
4593 : 0 : round_sdiv_adjust (machine_mode mode, rtx mod, rtx op1)
4594 : : {
4595 : : /* (abs (mod) >= abs (op1) - abs (mod)
4596 : : ? (op1 / mod > 0 ? 1 : -1)
4597 : : : 0) */
4598 : 0 : return gen_rtx_IF_THEN_ELSE
4599 : : (mode, gen_rtx_GE (BImode, gen_rtx_ABS (mode, mod),
4600 : : gen_rtx_MINUS (mode,
4601 : : gen_rtx_ABS (mode, op1),
4602 : : gen_rtx_ABS (mode, mod))),
4603 : : gen_rtx_IF_THEN_ELSE
4604 : : (mode, gen_rtx_GT (BImode,
4605 : : gen_rtx_DIV (mode, op1, mod),
4606 : : const0_rtx),
4607 : : const1_rtx, constm1_rtx),
4608 : : const0_rtx);
4609 : : }
4610 : :
4611 : : /* Return the difference between the rounded and the truncated result
4612 : : of a unsigned division by OP1 with remainder MOD. Halfway cases
4613 : : are rounded away from zero, rather than to the nearest even
4614 : : number. */
4615 : : static rtx
4616 : 0 : round_udiv_adjust (machine_mode mode, rtx mod, rtx op1)
4617 : : {
4618 : : /* (mod >= op1 - mod ? 1 : 0) */
4619 : 0 : return gen_rtx_IF_THEN_ELSE
4620 : : (mode, gen_rtx_GE (BImode, mod,
4621 : : gen_rtx_MINUS (mode, op1, mod)),
4622 : : const1_rtx, const0_rtx);
4623 : : }
4624 : :
4625 : : /* Convert X to MODE, that must be Pmode or ptr_mode, without emitting
4626 : : any rtl. */
4627 : :
4628 : : static rtx
4629 : 7099826 : convert_debug_memory_address (scalar_int_mode mode, rtx x,
4630 : : addr_space_t as)
4631 : : {
4632 : : #ifndef POINTERS_EXTEND_UNSIGNED
4633 : : gcc_assert (mode == Pmode
4634 : : || mode == targetm.addr_space.address_mode (as));
4635 : : gcc_assert (GET_MODE (x) == mode || GET_MODE (x) == VOIDmode);
4636 : : #else
4637 : 7099826 : rtx temp;
4638 : :
4639 : 7099826 : gcc_assert (targetm.addr_space.valid_pointer_mode (mode, as));
4640 : :
4641 : 7099826 : if (GET_MODE (x) == mode || GET_MODE (x) == VOIDmode)
4642 : : return x;
4643 : :
4644 : : /* X must have some form of address mode already. */
4645 : 0 : scalar_int_mode xmode = as_a <scalar_int_mode> (GET_MODE (x));
4646 : 0 : if (GET_MODE_PRECISION (mode) < GET_MODE_PRECISION (xmode))
4647 : 0 : x = lowpart_subreg (mode, x, xmode);
4648 : 0 : else if (POINTERS_EXTEND_UNSIGNED > 0)
4649 : 0 : x = gen_rtx_ZERO_EXTEND (mode, x);
4650 : : else if (!POINTERS_EXTEND_UNSIGNED)
4651 : : x = gen_rtx_SIGN_EXTEND (mode, x);
4652 : : else
4653 : : {
4654 : : switch (GET_CODE (x))
4655 : : {
4656 : : case SUBREG:
4657 : : if ((SUBREG_PROMOTED_VAR_P (x)
4658 : : || (REG_P (SUBREG_REG (x)) && REG_POINTER (SUBREG_REG (x)))
4659 : : || (GET_CODE (SUBREG_REG (x)) == PLUS
4660 : : && REG_P (XEXP (SUBREG_REG (x), 0))
4661 : : && REG_POINTER (XEXP (SUBREG_REG (x), 0))
4662 : : && CONST_INT_P (XEXP (SUBREG_REG (x), 1))))
4663 : : && GET_MODE (SUBREG_REG (x)) == mode)
4664 : : return SUBREG_REG (x);
4665 : : break;
4666 : : case LABEL_REF:
4667 : : temp = gen_rtx_LABEL_REF (mode, label_ref_label (x));
4668 : : LABEL_REF_NONLOCAL_P (temp) = LABEL_REF_NONLOCAL_P (x);
4669 : : return temp;
4670 : : case SYMBOL_REF:
4671 : : temp = shallow_copy_rtx (x);
4672 : : PUT_MODE (temp, mode);
4673 : : return temp;
4674 : : case CONST:
4675 : : temp = convert_debug_memory_address (mode, XEXP (x, 0), as);
4676 : : if (temp)
4677 : : temp = gen_rtx_CONST (mode, temp);
4678 : : return temp;
4679 : : case PLUS:
4680 : : case MINUS:
4681 : : if (CONST_INT_P (XEXP (x, 1)))
4682 : : {
4683 : : temp = convert_debug_memory_address (mode, XEXP (x, 0), as);
4684 : : if (temp)
4685 : : return gen_rtx_fmt_ee (GET_CODE (x), mode, temp, XEXP (x, 1));
4686 : : }
4687 : : break;
4688 : : default:
4689 : : break;
4690 : : }
4691 : : /* Don't know how to express ptr_extend as operation in debug info. */
4692 : : return NULL;
4693 : : }
4694 : : #endif /* POINTERS_EXTEND_UNSIGNED */
4695 : :
4696 : : return x;
4697 : : }
4698 : :
4699 : : /* Map from SSA_NAMEs to corresponding DEBUG_EXPR_DECLs created
4700 : : by avoid_deep_ter_for_debug. */
4701 : :
4702 : : static hash_map<tree, tree> *deep_ter_debug_map;
4703 : :
4704 : : /* Split too deep TER chains for debug stmts using debug temporaries. */
4705 : :
4706 : : static void
4707 : 38208833 : avoid_deep_ter_for_debug (gimple *stmt, int depth)
4708 : : {
4709 : 38208833 : use_operand_p use_p;
4710 : 38208833 : ssa_op_iter iter;
4711 : 47678468 : FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
4712 : : {
4713 : 9469635 : tree use = USE_FROM_PTR (use_p);
4714 : 9469635 : if (TREE_CODE (use) != SSA_NAME || SSA_NAME_IS_DEFAULT_DEF (use))
4715 : 7882551 : continue;
4716 : 8159025 : gimple *g = get_gimple_for_ssa_name (use);
4717 : 8159025 : if (g == NULL)
4718 : 6569488 : continue;
4719 : 1589537 : if ((depth > 6 || !is_gimple_assign (g)) && !stmt_ends_bb_p (g))
4720 : : {
4721 : 7986 : if (deep_ter_debug_map == NULL)
4722 : 1016 : deep_ter_debug_map = new hash_map<tree, tree>;
4723 : :
4724 : 7986 : tree &vexpr = deep_ter_debug_map->get_or_insert (use);
4725 : 7986 : if (vexpr != NULL)
4726 : 2453 : continue;
4727 : 5533 : vexpr = build_debug_expr_decl (TREE_TYPE (use));
4728 : 5533 : gimple *def_temp = gimple_build_debug_bind (vexpr, use, g);
4729 : 5533 : gimple_stmt_iterator gsi = gsi_for_stmt (g);
4730 : 5533 : gsi_insert_after (&gsi, def_temp, GSI_NEW_STMT);
4731 : 5533 : avoid_deep_ter_for_debug (def_temp, 0);
4732 : : }
4733 : : else
4734 : 1581551 : avoid_deep_ter_for_debug (g, depth + 1);
4735 : : }
4736 : 38208833 : }
4737 : :
4738 : : /* Return an RTX equivalent to the value of the parameter DECL. */
4739 : :
4740 : : static rtx
4741 : 168210 : expand_debug_parm_decl (tree decl)
4742 : : {
4743 : 168210 : rtx incoming = DECL_INCOMING_RTL (decl);
4744 : :
4745 : 168210 : if (incoming
4746 : 18331 : && GET_MODE (incoming) != BLKmode
4747 : 186537 : && ((REG_P (incoming) && HARD_REGISTER_P (incoming))
4748 : 1841 : || (MEM_P (incoming)
4749 : 1755 : && REG_P (XEXP (incoming, 0))
4750 : 765 : && HARD_REGISTER_P (XEXP (incoming, 0)))))
4751 : : {
4752 : 16514 : rtx rtl = gen_rtx_ENTRY_VALUE (GET_MODE (incoming));
4753 : :
4754 : : #ifdef HAVE_window_save
4755 : : /* DECL_INCOMING_RTL uses the INCOMING_REGNO of parameter registers.
4756 : : If the target machine has an explicit window save instruction, the
4757 : : actual entry value is the corresponding OUTGOING_REGNO instead. */
4758 : : if (REG_P (incoming)
4759 : : && OUTGOING_REGNO (REGNO (incoming)) != REGNO (incoming))
4760 : : incoming
4761 : : = gen_rtx_REG_offset (incoming, GET_MODE (incoming),
4762 : : OUTGOING_REGNO (REGNO (incoming)), 0);
4763 : : else if (MEM_P (incoming))
4764 : : {
4765 : : rtx reg = XEXP (incoming, 0);
4766 : : if (OUTGOING_REGNO (REGNO (reg)) != REGNO (reg))
4767 : : {
4768 : : reg = gen_raw_REG (GET_MODE (reg), OUTGOING_REGNO (REGNO (reg)));
4769 : : incoming = replace_equiv_address_nv (incoming, reg);
4770 : : }
4771 : : else
4772 : : incoming = copy_rtx (incoming);
4773 : : }
4774 : : #endif
4775 : :
4776 : 16514 : ENTRY_VALUE_EXP (rtl) = incoming;
4777 : 16514 : return rtl;
4778 : : }
4779 : :
4780 : 151696 : if (incoming
4781 : 1817 : && GET_MODE (incoming) != BLKmode
4782 : 1813 : && !TREE_ADDRESSABLE (decl)
4783 : 1813 : && MEM_P (incoming)
4784 : 1727 : && (XEXP (incoming, 0) == virtual_incoming_args_rtx
4785 : 990 : || (GET_CODE (XEXP (incoming, 0)) == PLUS
4786 : 990 : && XEXP (XEXP (incoming, 0), 0) == virtual_incoming_args_rtx
4787 : 976 : && CONST_INT_P (XEXP (XEXP (incoming, 0), 1)))))
4788 : 1713 : return copy_rtx (incoming);
4789 : :
4790 : : return NULL_RTX;
4791 : : }
4792 : :
4793 : : /* Return an RTX equivalent to the value of the tree expression EXP. */
4794 : :
4795 : : static rtx
4796 : 39552171 : expand_debug_expr (tree exp)
4797 : : {
4798 : 39552171 : rtx op0 = NULL_RTX, op1 = NULL_RTX, op2 = NULL_RTX;
4799 : 39552171 : machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
4800 : 39552171 : machine_mode inner_mode = VOIDmode;
4801 : 39552171 : int unsignedp = TYPE_UNSIGNED (TREE_TYPE (exp));
4802 : 39552171 : addr_space_t as;
4803 : 39552171 : scalar_int_mode op0_mode, op1_mode, addr_mode;
4804 : :
4805 : 39552171 : switch (TREE_CODE_CLASS (TREE_CODE (exp)))
4806 : : {
4807 : 6757669 : case tcc_expression:
4808 : 6757669 : switch (TREE_CODE (exp))
4809 : : {
4810 : 19175 : case COND_EXPR:
4811 : 19175 : case DOT_PROD_EXPR:
4812 : 19175 : case SAD_EXPR:
4813 : 19175 : case WIDEN_MULT_PLUS_EXPR:
4814 : 19175 : case WIDEN_MULT_MINUS_EXPR:
4815 : 19175 : goto ternary;
4816 : :
4817 : 0 : case TRUTH_ANDIF_EXPR:
4818 : 0 : case TRUTH_ORIF_EXPR:
4819 : 0 : case TRUTH_AND_EXPR:
4820 : 0 : case TRUTH_OR_EXPR:
4821 : 0 : case TRUTH_XOR_EXPR:
4822 : 0 : goto binary;
4823 : :
4824 : 0 : case TRUTH_NOT_EXPR:
4825 : 0 : goto unary;
4826 : :
4827 : : default:
4828 : : break;
4829 : : }
4830 : : break;
4831 : :
4832 : 19175 : ternary:
4833 : 19175 : op2 = expand_debug_expr (TREE_OPERAND (exp, 2));
4834 : 19175 : if (!op2)
4835 : : return NULL_RTX;
4836 : : /* Fall through. */
4837 : :
4838 : 19175 : binary:
4839 : 1325612 : case tcc_binary:
4840 : 1325612 : if (mode == BLKmode)
4841 : : return NULL_RTX;
4842 : 1325602 : op1 = expand_debug_expr (TREE_OPERAND (exp, 1));
4843 : 1325602 : if (!op1)
4844 : : return NULL_RTX;
4845 : 1324926 : switch (TREE_CODE (exp))
4846 : : {
4847 : 71903 : case LSHIFT_EXPR:
4848 : 71903 : case RSHIFT_EXPR:
4849 : 71903 : case LROTATE_EXPR:
4850 : 71903 : case RROTATE_EXPR:
4851 : 71903 : case WIDEN_LSHIFT_EXPR:
4852 : : /* Ensure second operand isn't wider than the first one. */
4853 : 71903 : inner_mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 1)));
4854 : 71903 : if (is_a <scalar_int_mode> (inner_mode, &op1_mode)
4855 : 71895 : && (GET_MODE_UNIT_PRECISION (mode)
4856 : 71895 : < GET_MODE_PRECISION (op1_mode)))
4857 : 5034 : op1 = lowpart_subreg (GET_MODE_INNER (mode), op1, op1_mode);
4858 : : break;
4859 : : default:
4860 : : break;
4861 : : }
4862 : : /* Fall through. */
4863 : :
4864 : 1937422 : unary:
4865 : 1937422 : case tcc_unary:
4866 : 1937422 : if (mode == BLKmode)
4867 : : return NULL_RTX;
4868 : 1937420 : inner_mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
4869 : 1937420 : op0 = expand_debug_expr (TREE_OPERAND (exp, 0));
4870 : 1937420 : if (!op0)
4871 : : return NULL_RTX;
4872 : : break;
4873 : :
4874 : 72601 : case tcc_comparison:
4875 : 72601 : unsignedp = TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0)));
4876 : 72601 : goto binary;
4877 : :
4878 : 0 : case tcc_type:
4879 : 0 : case tcc_statement:
4880 : 0 : gcc_unreachable ();
4881 : :
4882 : : case tcc_constant:
4883 : : case tcc_exceptional:
4884 : : case tcc_declaration:
4885 : : case tcc_reference:
4886 : : case tcc_vl_exp:
4887 : : break;
4888 : : }
4889 : :
4890 : 39549903 : switch (TREE_CODE (exp))
4891 : : {
4892 : 268402 : case STRING_CST:
4893 : 268402 : if (!lookup_constant_def (exp))
4894 : : {
4895 : 114118 : if (strlen (TREE_STRING_POINTER (exp)) + 1
4896 : 114118 : != (size_t) TREE_STRING_LENGTH (exp))
4897 : : return NULL_RTX;
4898 : 113576 : op0 = gen_rtx_CONST_STRING (Pmode, TREE_STRING_POINTER (exp));
4899 : 113017 : op0 = gen_rtx_MEM (BLKmode, op0);
4900 : 113017 : set_mem_attributes (op0, exp, 0);
4901 : 113017 : return op0;
4902 : : }
4903 : : /* Fall through. */
4904 : :
4905 : 5297511 : case INTEGER_CST:
4906 : 5297511 : if (TREE_CODE (TREE_TYPE (exp)) == BITINT_TYPE
4907 : 5297511 : && TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
4908 : : return NULL;
4909 : : /* FALLTHRU */
4910 : 5360193 : case REAL_CST:
4911 : 5360193 : case FIXED_CST:
4912 : 5360193 : op0 = expand_expr (exp, NULL_RTX, mode, EXPAND_INITIALIZER);
4913 : 5360193 : return op0;
4914 : :
4915 : 0 : case POLY_INT_CST:
4916 : 0 : return immed_wide_int_const (poly_int_cst_value (exp), mode);
4917 : :
4918 : 4436 : case COMPLEX_CST:
4919 : 4436 : gcc_assert (COMPLEX_MODE_P (mode));
4920 : 4436 : op0 = expand_debug_expr (TREE_REALPART (exp));
4921 : 4436 : op1 = expand_debug_expr (TREE_IMAGPART (exp));
4922 : 4436 : return gen_rtx_CONCAT (mode, op0, op1);
4923 : :
4924 : 5444060 : case DEBUG_EXPR_DECL:
4925 : 5444060 : op0 = DECL_RTL_IF_SET (exp);
4926 : :
4927 : 4266459 : if (op0)
4928 : : {
4929 : 4266459 : if (GET_MODE (op0) != mode)
4930 : 0 : gcc_assert (VECTOR_TYPE_P (TREE_TYPE (exp)));
4931 : : else
4932 : : return op0;
4933 : : }
4934 : :
4935 : 1177601 : op0 = gen_rtx_DEBUG_EXPR (mode);
4936 : 1177601 : DEBUG_EXPR_TREE_DECL (op0) = exp;
4937 : 1177601 : SET_DECL_RTL (exp, op0);
4938 : :
4939 : 1177601 : return op0;
4940 : :
4941 : 5286417 : case VAR_DECL:
4942 : 5286417 : case PARM_DECL:
4943 : 5286417 : case FUNCTION_DECL:
4944 : 5286417 : case LABEL_DECL:
4945 : 5286417 : case CONST_DECL:
4946 : 5286417 : case RESULT_DECL:
4947 : 5286417 : op0 = DECL_RTL_IF_SET (exp);
4948 : :
4949 : : /* This decl was probably optimized away. */
4950 : 3678456 : if (!op0
4951 : : /* At least label RTXen are sometimes replaced by
4952 : : NOTE_INSN_DELETED_LABEL. Any notes here are not
4953 : : handled by copy_rtx. */
4954 : 3678456 : || NOTE_P (op0))
4955 : : {
4956 : 1607962 : if (!VAR_P (exp)
4957 : 1598610 : || DECL_EXTERNAL (exp)
4958 : 1598036 : || !TREE_STATIC (exp)
4959 : 91948 : || !DECL_NAME (exp)
4960 : 91948 : || DECL_HARD_REGISTER (exp)
4961 : 91948 : || DECL_IN_CONSTANT_POOL (exp)
4962 : 91948 : || mode == VOIDmode
4963 : 1699910 : || symtab_node::get (exp) == NULL)
4964 : : return NULL;
4965 : :
4966 : 15337 : op0 = make_decl_rtl_for_debug (exp);
4967 : 15337 : if (!MEM_P (op0)
4968 : 15337 : || GET_CODE (XEXP (op0, 0)) != SYMBOL_REF
4969 : 30674 : || SYMBOL_REF_DECL (XEXP (op0, 0)) != exp)
4970 : : return NULL;
4971 : : }
4972 : 3678455 : else if (VAR_P (exp)
4973 : 3560089 : && is_global_var (exp)
4974 : 3893490 : && symtab_node::get (exp) == NULL)
4975 : : return NULL;
4976 : : else
4977 : 3678455 : op0 = copy_rtx (op0);
4978 : :
4979 : 3693792 : if (GET_MODE (op0) == BLKmode
4980 : : /* If op0 is not BLKmode, but mode is, adjust_mode
4981 : : below would ICE. While it is likely a FE bug,
4982 : : try to be robust here. See PR43166. */
4983 : 510266 : || mode == BLKmode
4984 : 510266 : || (mode == VOIDmode && GET_MODE (op0) != VOIDmode))
4985 : : {
4986 : 3183526 : gcc_assert (MEM_P (op0));
4987 : 3183526 : op0 = adjust_address_nv (op0, mode, 0);
4988 : 3183526 : return op0;
4989 : : }
4990 : :
4991 : : /* Fall through. */
4992 : :
4993 : 510266 : adjust_mode:
4994 : 10085873 : case PAREN_EXPR:
4995 : 10085873 : CASE_CONVERT:
4996 : 10085873 : {
4997 : 10085873 : inner_mode = GET_MODE (op0);
4998 : :
4999 : 10085873 : if (mode == inner_mode)
5000 : : return op0;
5001 : :
5002 : 183806 : if (inner_mode == VOIDmode)
5003 : : {
5004 : 6609 : if (TREE_CODE (exp) == SSA_NAME)
5005 : 12 : inner_mode = TYPE_MODE (TREE_TYPE (exp));
5006 : : else
5007 : 6597 : inner_mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
5008 : 6609 : if (mode == inner_mode)
5009 : : return op0;
5010 : : }
5011 : :
5012 : 180284 : if (FLOAT_MODE_P (mode) && FLOAT_MODE_P (inner_mode))
5013 : : {
5014 : 6156 : if (GET_MODE_UNIT_BITSIZE (mode)
5015 : 12312 : == GET_MODE_UNIT_BITSIZE (inner_mode))
5016 : 4 : op0 = simplify_gen_subreg (mode, op0, inner_mode, 0);
5017 : 6152 : else if (GET_MODE_UNIT_BITSIZE (mode)
5018 : 12304 : < GET_MODE_UNIT_BITSIZE (inner_mode))
5019 : 3517 : op0 = simplify_gen_unary (FLOAT_TRUNCATE, mode, op0, inner_mode);
5020 : : else
5021 : 2635 : op0 = simplify_gen_unary (FLOAT_EXTEND, mode, op0, inner_mode);
5022 : : }
5023 : 174128 : else if (FLOAT_MODE_P (mode))
5024 : : {
5025 : 0 : gcc_assert (TREE_CODE (exp) != SSA_NAME);
5026 : 0 : if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))))
5027 : 0 : op0 = simplify_gen_unary (UNSIGNED_FLOAT, mode, op0, inner_mode);
5028 : : else
5029 : 0 : op0 = simplify_gen_unary (FLOAT, mode, op0, inner_mode);
5030 : : }
5031 : 174128 : else if (FLOAT_MODE_P (inner_mode))
5032 : : {
5033 : 0 : if (unsignedp)
5034 : 0 : op0 = simplify_gen_unary (UNSIGNED_FIX, mode, op0, inner_mode);
5035 : : else
5036 : 0 : op0 = simplify_gen_unary (FIX, mode, op0, inner_mode);
5037 : : }
5038 : 348256 : else if (GET_MODE_UNIT_PRECISION (mode)
5039 : 174128 : == GET_MODE_UNIT_PRECISION (inner_mode))
5040 : 0 : op0 = lowpart_subreg (mode, op0, inner_mode);
5041 : 348256 : else if (GET_MODE_UNIT_PRECISION (mode)
5042 : 174128 : < GET_MODE_UNIT_PRECISION (inner_mode))
5043 : 81584 : op0 = simplify_gen_unary (TRUNCATE, mode, op0, inner_mode);
5044 : 92544 : else if (UNARY_CLASS_P (exp)
5045 : 92544 : ? TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0)))
5046 : 0 : : unsignedp)
5047 : 63301 : op0 = simplify_gen_unary (ZERO_EXTEND, mode, op0, inner_mode);
5048 : : else
5049 : 29243 : op0 = simplify_gen_unary (SIGN_EXTEND, mode, op0, inner_mode);
5050 : :
5051 : : return op0;
5052 : : }
5053 : :
5054 : 2139915 : case MEM_REF:
5055 : 2139915 : if (!is_gimple_mem_ref_addr (TREE_OPERAND (exp, 0)))
5056 : : {
5057 : 809209 : tree newexp = fold_binary (MEM_REF, TREE_TYPE (exp),
5058 : : TREE_OPERAND (exp, 0),
5059 : : TREE_OPERAND (exp, 1));
5060 : 809209 : if (newexp)
5061 : 0 : return expand_debug_expr (newexp);
5062 : : }
5063 : : /* FALLTHROUGH */
5064 : 2139915 : case INDIRECT_REF:
5065 : 2139915 : inner_mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
5066 : 2139915 : op0 = expand_debug_expr (TREE_OPERAND (exp, 0));
5067 : 2139915 : if (!op0)
5068 : : return NULL;
5069 : :
5070 : 2136315 : if (TREE_CODE (exp) == MEM_REF)
5071 : : {
5072 : 2136315 : if (GET_CODE (op0) == DEBUG_IMPLICIT_PTR
5073 : 2092923 : || (GET_CODE (op0) == PLUS
5074 : 316595 : && GET_CODE (XEXP (op0, 0)) == DEBUG_IMPLICIT_PTR))
5075 : : /* (mem (debug_implicit_ptr)) might confuse aliasing.
5076 : : Instead just use get_inner_reference. */
5077 : 43392 : goto component_ref;
5078 : :
5079 : 2092923 : op1 = expand_debug_expr (TREE_OPERAND (exp, 1));
5080 : 2092923 : poly_int64 offset;
5081 : 2092923 : if (!op1 || !poly_int_rtx_p (op1, &offset))
5082 : 0 : return NULL;
5083 : :
5084 : 2092923 : op0 = plus_constant (inner_mode, op0, offset);
5085 : : }
5086 : :
5087 : 2092923 : as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
5088 : :
5089 : 2092923 : op0 = convert_debug_memory_address (targetm.addr_space.address_mode (as),
5090 : : op0, as);
5091 : 2092923 : if (op0 == NULL_RTX)
5092 : : return NULL;
5093 : :
5094 : 2092923 : op0 = gen_rtx_MEM (mode, op0);
5095 : 2092923 : set_mem_attributes (op0, exp, 0);
5096 : 2092923 : if (TREE_CODE (exp) == MEM_REF
5097 : 2092923 : && !is_gimple_mem_ref_addr (TREE_OPERAND (exp, 0)))
5098 : 809209 : set_mem_expr (op0, NULL_TREE);
5099 : 2092923 : set_mem_addr_space (op0, as);
5100 : :
5101 : 2092923 : return op0;
5102 : :
5103 : 46059 : case TARGET_MEM_REF:
5104 : 46059 : if (TREE_CODE (TMR_BASE (exp)) == ADDR_EXPR
5105 : 46059 : && !DECL_RTL_SET_P (TREE_OPERAND (TMR_BASE (exp), 0)))
5106 : : return NULL;
5107 : :
5108 : 46049 : op0 = expand_debug_expr
5109 : 46049 : (tree_mem_ref_addr (build_pointer_type (TREE_TYPE (exp)), exp));
5110 : 46049 : if (!op0)
5111 : : return NULL;
5112 : :
5113 : 46049 : as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
5114 : 46049 : op0 = convert_debug_memory_address (targetm.addr_space.address_mode (as),
5115 : : op0, as);
5116 : 46049 : if (op0 == NULL_RTX)
5117 : : return NULL;
5118 : :
5119 : 46049 : op0 = gen_rtx_MEM (mode, op0);
5120 : :
5121 : 46049 : set_mem_attributes (op0, exp, 0);
5122 : 46049 : set_mem_addr_space (op0, as);
5123 : :
5124 : 46049 : return op0;
5125 : :
5126 : 3512637 : component_ref:
5127 : 3512637 : case ARRAY_REF:
5128 : 3512637 : case ARRAY_RANGE_REF:
5129 : 3512637 : case COMPONENT_REF:
5130 : 3512637 : case BIT_FIELD_REF:
5131 : 3512637 : case REALPART_EXPR:
5132 : 3512637 : case IMAGPART_EXPR:
5133 : 3512637 : case VIEW_CONVERT_EXPR:
5134 : 3512637 : {
5135 : 3512637 : machine_mode mode1;
5136 : 3512637 : poly_int64 bitsize, bitpos;
5137 : 3512637 : tree offset;
5138 : 3512637 : int reversep, volatilep = 0;
5139 : 3512637 : tree tem
5140 : 3512637 : = get_inner_reference (exp, &bitsize, &bitpos, &offset, &mode1,
5141 : : &unsignedp, &reversep, &volatilep);
5142 : 3512637 : rtx orig_op0;
5143 : :
5144 : 3512637 : if (known_eq (bitsize, 0))
5145 : : return NULL;
5146 : :
5147 : 3466325 : orig_op0 = op0 = expand_debug_expr (tem);
5148 : :
5149 : 3466325 : if (!op0)
5150 : : return NULL;
5151 : :
5152 : 3156714 : if (offset)
5153 : : {
5154 : 12903 : machine_mode addrmode, offmode;
5155 : :
5156 : 12903 : if (!MEM_P (op0))
5157 : : return NULL;
5158 : :
5159 : 12903 : op0 = XEXP (op0, 0);
5160 : 12903 : addrmode = GET_MODE (op0);
5161 : 12903 : if (addrmode == VOIDmode)
5162 : 0 : addrmode = Pmode;
5163 : :
5164 : 12903 : op1 = expand_debug_expr (offset);
5165 : 12903 : if (!op1)
5166 : : return NULL;
5167 : :
5168 : 12901 : offmode = GET_MODE (op1);
5169 : 12901 : if (offmode == VOIDmode)
5170 : 0 : offmode = TYPE_MODE (TREE_TYPE (offset));
5171 : :
5172 : 12901 : if (addrmode != offmode)
5173 : 0 : op1 = lowpart_subreg (addrmode, op1, offmode);
5174 : :
5175 : : /* Don't use offset_address here, we don't need a
5176 : : recognizable address, and we don't want to generate
5177 : : code. */
5178 : 12901 : op0 = gen_rtx_MEM (mode, simplify_gen_binary (PLUS, addrmode,
5179 : : op0, op1));
5180 : : }
5181 : :
5182 : 3156712 : if (MEM_P (op0))
5183 : : {
5184 : 3030030 : if (mode1 == VOIDmode)
5185 : : {
5186 : 4477 : if (maybe_gt (bitsize, MAX_BITSIZE_MODE_ANY_INT))
5187 : 355967 : return NULL;
5188 : : /* Bitfield. */
5189 : 4477 : mode1 = smallest_int_mode_for_size (bitsize).require ();
5190 : : }
5191 : 3030030 : poly_int64 bytepos = bits_to_bytes_round_down (bitpos);
5192 : 3030030 : if (maybe_ne (bytepos, 0))
5193 : : {
5194 : 1331529 : op0 = adjust_address_nv (op0, mode1, bytepos);
5195 : 1331529 : bitpos = num_trailing_bits (bitpos);
5196 : : }
5197 : 1698501 : else if (known_eq (bitpos, 0)
5198 : 3396247 : && known_eq (bitsize, GET_MODE_BITSIZE (mode)))
5199 : 480188 : op0 = adjust_address_nv (op0, mode, 0);
5200 : 1218313 : else if (GET_MODE (op0) != mode1)
5201 : 3909 : op0 = adjust_address_nv (op0, mode1, 0);
5202 : : else
5203 : 1214404 : op0 = copy_rtx (op0);
5204 : 3030030 : if (op0 == orig_op0)
5205 : 133949 : op0 = shallow_copy_rtx (op0);
5206 : 3030030 : if (TREE_CODE (tem) != SSA_NAME)
5207 : 3026901 : set_mem_attributes (op0, exp, 0);
5208 : : }
5209 : :
5210 : 3156712 : if (known_eq (bitpos, 0) && mode == GET_MODE (op0))
5211 : : return op0;
5212 : :
5213 : 104173 : if (maybe_lt (bitpos, 0))
5214 : : return NULL;
5215 : :
5216 : 104171 : if (GET_MODE (op0) == BLKmode || mode == BLKmode)
5217 : : return NULL;
5218 : :
5219 : 104160 : poly_int64 bytepos;
5220 : 104827 : if (multiple_p (bitpos, BITS_PER_UNIT, &bytepos)
5221 : 201892 : && known_eq (bitsize, GET_MODE_BITSIZE (mode1)))
5222 : : {
5223 : 100295 : machine_mode opmode = GET_MODE (op0);
5224 : :
5225 : 100295 : if (opmode == VOIDmode)
5226 : 0 : opmode = TYPE_MODE (TREE_TYPE (tem));
5227 : :
5228 : : /* This condition may hold if we're expanding the address
5229 : : right past the end of an array that turned out not to
5230 : : be addressable (i.e., the address was only computed in
5231 : : debug stmts). The gen_subreg below would rightfully
5232 : : crash, and the address doesn't really exist, so just
5233 : : drop it. */
5234 : 200590 : if (known_ge (bitpos, GET_MODE_BITSIZE (opmode)))
5235 : : return NULL;
5236 : :
5237 : 200532 : if (multiple_p (bitpos, GET_MODE_BITSIZE (mode)))
5238 : 100250 : return simplify_gen_subreg (mode, op0, opmode, bytepos);
5239 : : }
5240 : :
5241 : 7762 : return simplify_gen_ternary (SCALAR_INT_MODE_P (GET_MODE (op0))
5242 : 3443 : && TYPE_UNSIGNED (TREE_TYPE (exp))
5243 : : ? SIGN_EXTRACT
5244 : : : ZERO_EXTRACT, mode,
5245 : 3881 : GET_MODE (op0) != VOIDmode
5246 : : ? GET_MODE (op0)
5247 : 0 : : TYPE_MODE (TREE_TYPE (tem)),
5248 : : op0, gen_int_mode (bitsize, word_mode),
5249 : 3881 : gen_int_mode (bitpos, word_mode));
5250 : : }
5251 : :
5252 : 4450 : case ABS_EXPR:
5253 : 4450 : case ABSU_EXPR:
5254 : 4450 : return simplify_gen_unary (ABS, mode, op0, mode);
5255 : :
5256 : 13934 : case NEGATE_EXPR:
5257 : 13934 : return simplify_gen_unary (NEG, mode, op0, mode);
5258 : :
5259 : 15915 : case BIT_NOT_EXPR:
5260 : 15915 : return simplify_gen_unary (NOT, mode, op0, mode);
5261 : :
5262 : 2548 : case FLOAT_EXPR:
5263 : 2548 : return simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp,
5264 : : 0)))
5265 : : ? UNSIGNED_FLOAT : FLOAT, mode, op0,
5266 : 2548 : inner_mode);
5267 : :
5268 : 420 : case FIX_TRUNC_EXPR:
5269 : 420 : return simplify_gen_unary (unsignedp ? UNSIGNED_FIX : FIX, mode, op0,
5270 : 420 : inner_mode);
5271 : :
5272 : 197964 : case POINTER_PLUS_EXPR:
5273 : : /* For the rare target where pointers are not the same size as
5274 : : size_t, we need to check for mis-matched modes and correct
5275 : : the addend. */
5276 : 197964 : if (op0 && op1
5277 : 197964 : && is_a <scalar_int_mode> (GET_MODE (op0), &op0_mode)
5278 : 197863 : && is_a <scalar_int_mode> (GET_MODE (op1), &op1_mode)
5279 : 319008 : && op0_mode != op1_mode)
5280 : : {
5281 : 0 : if (GET_MODE_BITSIZE (op0_mode) < GET_MODE_BITSIZE (op1_mode)
5282 : : /* If OP0 is a partial mode, then we must truncate, even
5283 : : if it has the same bitsize as OP1 as GCC's
5284 : : representation of partial modes is opaque. */
5285 : 0 : || (GET_MODE_CLASS (op0_mode) == MODE_PARTIAL_INT
5286 : 0 : && (GET_MODE_BITSIZE (op0_mode)
5287 : 0 : == GET_MODE_BITSIZE (op1_mode))))
5288 : 0 : op1 = simplify_gen_unary (TRUNCATE, op0_mode, op1, op1_mode);
5289 : : else
5290 : : /* We always sign-extend, regardless of the signedness of
5291 : : the operand, because the operand is always unsigned
5292 : : here even if the original C expression is signed. */
5293 : 0 : op1 = simplify_gen_unary (SIGN_EXTEND, op0_mode, op1, op1_mode);
5294 : : }
5295 : : /* Fall through. */
5296 : 612856 : case PLUS_EXPR:
5297 : 612856 : return simplify_gen_binary (PLUS, mode, op0, op1);
5298 : :
5299 : 125025 : case MINUS_EXPR:
5300 : 125025 : case POINTER_DIFF_EXPR:
5301 : 125025 : return simplify_gen_binary (MINUS, mode, op0, op1);
5302 : :
5303 : 150394 : case MULT_EXPR:
5304 : 150394 : return simplify_gen_binary (MULT, mode, op0, op1);
5305 : :
5306 : 85538 : case RDIV_EXPR:
5307 : 85538 : case TRUNC_DIV_EXPR:
5308 : 85538 : case EXACT_DIV_EXPR:
5309 : 85538 : if (unsignedp)
5310 : 20670 : return simplify_gen_binary (UDIV, mode, op0, op1);
5311 : : else
5312 : 64868 : return simplify_gen_binary (DIV, mode, op0, op1);
5313 : :
5314 : 14585 : case TRUNC_MOD_EXPR:
5315 : 29170 : return simplify_gen_binary (unsignedp ? UMOD : MOD, mode, op0, op1);
5316 : :
5317 : 3 : case FLOOR_DIV_EXPR:
5318 : 3 : if (unsignedp)
5319 : 0 : return simplify_gen_binary (UDIV, mode, op0, op1);
5320 : : else
5321 : : {
5322 : 3 : rtx div = simplify_gen_binary (DIV, mode, op0, op1);
5323 : 3 : rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
5324 : 3 : rtx adj = floor_sdiv_adjust (mode, mod, op1);
5325 : 3 : return simplify_gen_binary (PLUS, mode, div, adj);
5326 : : }
5327 : :
5328 : 1 : case FLOOR_MOD_EXPR:
5329 : 1 : if (unsignedp)
5330 : 0 : return simplify_gen_binary (UMOD, mode, op0, op1);
5331 : : else
5332 : : {
5333 : 1 : rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
5334 : 1 : rtx adj = floor_sdiv_adjust (mode, mod, op1);
5335 : 1 : adj = simplify_gen_unary (NEG, mode,
5336 : : simplify_gen_binary (MULT, mode, adj, op1),
5337 : : mode);
5338 : 1 : return simplify_gen_binary (PLUS, mode, mod, adj);
5339 : : }
5340 : :
5341 : 3 : case CEIL_DIV_EXPR:
5342 : 3 : if (unsignedp)
5343 : : {
5344 : 0 : rtx div = simplify_gen_binary (UDIV, mode, op0, op1);
5345 : 0 : rtx mod = simplify_gen_binary (UMOD, mode, op0, op1);
5346 : 0 : rtx adj = ceil_udiv_adjust (mode, mod, op1);
5347 : 0 : return simplify_gen_binary (PLUS, mode, div, adj);
5348 : : }
5349 : : else
5350 : : {
5351 : 3 : rtx div = simplify_gen_binary (DIV, mode, op0, op1);
5352 : 3 : rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
5353 : 3 : rtx adj = ceil_sdiv_adjust (mode, mod, op1);
5354 : 3 : return simplify_gen_binary (PLUS, mode, div, adj);
5355 : : }
5356 : :
5357 : 0 : case CEIL_MOD_EXPR:
5358 : 0 : if (unsignedp)
5359 : : {
5360 : 0 : rtx mod = simplify_gen_binary (UMOD, mode, op0, op1);
5361 : 0 : rtx adj = ceil_udiv_adjust (mode, mod, op1);
5362 : 0 : adj = simplify_gen_unary (NEG, mode,
5363 : : simplify_gen_binary (MULT, mode, adj, op1),
5364 : : mode);
5365 : 0 : return simplify_gen_binary (PLUS, mode, mod, adj);
5366 : : }
5367 : : else
5368 : : {
5369 : 0 : rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
5370 : 0 : rtx adj = ceil_sdiv_adjust (mode, mod, op1);
5371 : 0 : adj = simplify_gen_unary (NEG, mode,
5372 : : simplify_gen_binary (MULT, mode, adj, op1),
5373 : : mode);
5374 : 0 : return simplify_gen_binary (PLUS, mode, mod, adj);
5375 : : }
5376 : :
5377 : 0 : case ROUND_DIV_EXPR:
5378 : 0 : if (unsignedp)
5379 : : {
5380 : 0 : rtx div = simplify_gen_binary (UDIV, mode, op0, op1);
5381 : 0 : rtx mod = simplify_gen_binary (UMOD, mode, op0, op1);
5382 : 0 : rtx adj = round_udiv_adjust (mode, mod, op1);
5383 : 0 : return simplify_gen_binary (PLUS, mode, div, adj);
5384 : : }
5385 : : else
5386 : : {
5387 : 0 : rtx div = simplify_gen_binary (DIV, mode, op0, op1);
5388 : 0 : rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
5389 : 0 : rtx adj = round_sdiv_adjust (mode, mod, op1);
5390 : 0 : return simplify_gen_binary (PLUS, mode, div, adj);
5391 : : }
5392 : :
5393 : 0 : case ROUND_MOD_EXPR:
5394 : 0 : if (unsignedp)
5395 : : {
5396 : 0 : rtx mod = simplify_gen_binary (UMOD, mode, op0, op1);
5397 : 0 : rtx adj = round_udiv_adjust (mode, mod, op1);
5398 : 0 : adj = simplify_gen_unary (NEG, mode,
5399 : : simplify_gen_binary (MULT, mode, adj, op1),
5400 : : mode);
5401 : 0 : return simplify_gen_binary (PLUS, mode, mod, adj);
5402 : : }
5403 : : else
5404 : : {
5405 : 0 : rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
5406 : 0 : rtx adj = round_sdiv_adjust (mode, mod, op1);
5407 : 0 : adj = simplify_gen_unary (NEG, mode,
5408 : : simplify_gen_binary (MULT, mode, adj, op1),
5409 : : mode);
5410 : 0 : return simplify_gen_binary (PLUS, mode, mod, adj);
5411 : : }
5412 : :
5413 : 14198 : case LSHIFT_EXPR:
5414 : 14198 : return simplify_gen_binary (ASHIFT, mode, op0, op1);
5415 : :
5416 : 56963 : case RSHIFT_EXPR:
5417 : 56963 : if (unsignedp)
5418 : 54039 : return simplify_gen_binary (LSHIFTRT, mode, op0, op1);
5419 : : else
5420 : 2924 : return simplify_gen_binary (ASHIFTRT, mode, op0, op1);
5421 : :
5422 : 2 : case LROTATE_EXPR:
5423 : 2 : return simplify_gen_binary (ROTATE, mode, op0, op1);
5424 : :
5425 : 483 : case RROTATE_EXPR:
5426 : 483 : return simplify_gen_binary (ROTATERT, mode, op0, op1);
5427 : :
5428 : 13874 : case MIN_EXPR:
5429 : 27748 : return simplify_gen_binary (unsignedp ? UMIN : SMIN, mode, op0, op1);
5430 : :
5431 : 14954 : case MAX_EXPR:
5432 : 29908 : return simplify_gen_binary (unsignedp ? UMAX : SMAX, mode, op0, op1);
5433 : :
5434 : 81369 : case BIT_AND_EXPR:
5435 : 81369 : case TRUTH_AND_EXPR:
5436 : 81369 : return simplify_gen_binary (AND, mode, op0, op1);
5437 : :
5438 : 40858 : case BIT_IOR_EXPR:
5439 : 40858 : case TRUTH_OR_EXPR:
5440 : 40858 : return simplify_gen_binary (IOR, mode, op0, op1);
5441 : :
5442 : 7592 : case BIT_XOR_EXPR:
5443 : 7592 : case TRUTH_XOR_EXPR:
5444 : 7592 : return simplify_gen_binary (XOR, mode, op0, op1);
5445 : :
5446 : 0 : case TRUTH_ANDIF_EXPR:
5447 : 0 : return gen_rtx_IF_THEN_ELSE (mode, op0, op1, const0_rtx);
5448 : :
5449 : 0 : case TRUTH_ORIF_EXPR:
5450 : 0 : return gen_rtx_IF_THEN_ELSE (mode, op0, const_true_rtx, op1);
5451 : :
5452 : 0 : case TRUTH_NOT_EXPR:
5453 : 0 : return simplify_gen_relational (EQ, mode, inner_mode, op0, const0_rtx);
5454 : :
5455 : 5389 : case LT_EXPR:
5456 : 5389 : return simplify_gen_relational (unsignedp ? LTU : LT, mode, inner_mode,
5457 : 5389 : op0, op1);
5458 : :
5459 : 3826 : case LE_EXPR:
5460 : 3826 : return simplify_gen_relational (unsignedp ? LEU : LE, mode, inner_mode,
5461 : 3826 : op0, op1);
5462 : :
5463 : 18288 : case GT_EXPR:
5464 : 18288 : return simplify_gen_relational (unsignedp ? GTU : GT, mode, inner_mode,
5465 : 18288 : op0, op1);
5466 : :
5467 : 1228 : case GE_EXPR:
5468 : 1228 : return simplify_gen_relational (unsignedp ? GEU : GE, mode, inner_mode,
5469 : 1228 : op0, op1);
5470 : :
5471 : 27717 : case EQ_EXPR:
5472 : 27717 : return simplify_gen_relational (EQ, mode, inner_mode, op0, op1);
5473 : :
5474 : 16131 : case NE_EXPR:
5475 : 16131 : return simplify_gen_relational (NE, mode, inner_mode, op0, op1);
5476 : :
5477 : 0 : case UNORDERED_EXPR:
5478 : 0 : return simplify_gen_relational (UNORDERED, mode, inner_mode, op0, op1);
5479 : :
5480 : 0 : case ORDERED_EXPR:
5481 : 0 : return simplify_gen_relational (ORDERED, mode, inner_mode, op0, op1);
5482 : :
5483 : 0 : case UNLT_EXPR:
5484 : 0 : return simplify_gen_relational (UNLT, mode, inner_mode, op0, op1);
5485 : :
5486 : 0 : case UNLE_EXPR:
5487 : 0 : return simplify_gen_relational (UNLE, mode, inner_mode, op0, op1);
5488 : :
5489 : 0 : case UNGT_EXPR:
5490 : 0 : return simplify_gen_relational (UNGT, mode, inner_mode, op0, op1);
5491 : :
5492 : 0 : case UNGE_EXPR:
5493 : 0 : return simplify_gen_relational (UNGE, mode, inner_mode, op0, op1);
5494 : :
5495 : 0 : case UNEQ_EXPR:
5496 : 0 : return simplify_gen_relational (UNEQ, mode, inner_mode, op0, op1);
5497 : :
5498 : 0 : case LTGT_EXPR:
5499 : 0 : return simplify_gen_relational (LTGT, mode, inner_mode, op0, op1);
5500 : :
5501 : 19175 : case COND_EXPR:
5502 : 19175 : return gen_rtx_IF_THEN_ELSE (mode, op0, op1, op2);
5503 : :
5504 : 9040 : case COMPLEX_EXPR:
5505 : 9040 : gcc_assert (COMPLEX_MODE_P (mode));
5506 : 9040 : if (GET_MODE (op0) == VOIDmode)
5507 : 0 : op0 = gen_rtx_CONST (GET_MODE_INNER (mode), op0);
5508 : 9040 : if (GET_MODE (op1) == VOIDmode)
5509 : 0 : op1 = gen_rtx_CONST (GET_MODE_INNER (mode), op1);
5510 : 9040 : return gen_rtx_CONCAT (mode, op0, op1);
5511 : :
5512 : 0 : case CONJ_EXPR:
5513 : 0 : if (GET_CODE (op0) == CONCAT)
5514 : 0 : return gen_rtx_CONCAT (mode, XEXP (op0, 0),
5515 : : simplify_gen_unary (NEG, GET_MODE_INNER (mode),
5516 : : XEXP (op0, 1),
5517 : : GET_MODE_INNER (mode)));
5518 : : else
5519 : : {
5520 : 0 : scalar_mode imode = GET_MODE_INNER (mode);
5521 : 0 : rtx re, im;
5522 : :
5523 : 0 : if (MEM_P (op0))
5524 : : {
5525 : 0 : re = adjust_address_nv (op0, imode, 0);
5526 : 0 : im = adjust_address_nv (op0, imode, GET_MODE_SIZE (imode));
5527 : : }
5528 : : else
5529 : : {
5530 : 0 : scalar_int_mode ifmode;
5531 : 0 : scalar_int_mode ihmode;
5532 : 0 : rtx halfsize;
5533 : 0 : if (!int_mode_for_mode (mode).exists (&ifmode)
5534 : 0 : || !int_mode_for_mode (imode).exists (&ihmode))
5535 : 0 : return NULL;
5536 : 0 : halfsize = GEN_INT (GET_MODE_BITSIZE (ihmode));
5537 : 0 : re = op0;
5538 : 0 : if (mode != ifmode)
5539 : 0 : re = gen_rtx_SUBREG (ifmode, re, 0);
5540 : 0 : re = gen_rtx_ZERO_EXTRACT (ihmode, re, halfsize, const0_rtx);
5541 : 0 : if (imode != ihmode)
5542 : 0 : re = gen_rtx_SUBREG (imode, re, 0);
5543 : 0 : im = copy_rtx (op0);
5544 : 0 : if (mode != ifmode)
5545 : 0 : im = gen_rtx_SUBREG (ifmode, im, 0);
5546 : 0 : im = gen_rtx_ZERO_EXTRACT (ihmode, im, halfsize, halfsize);
5547 : 0 : if (imode != ihmode)
5548 : 0 : im = gen_rtx_SUBREG (imode, im, 0);
5549 : : }
5550 : 0 : im = gen_rtx_NEG (imode, im);
5551 : 0 : return gen_rtx_CONCAT (mode, re, im);
5552 : : }
5553 : :
5554 : 6738155 : case ADDR_EXPR:
5555 : 6738155 : op0 = expand_debug_expr (TREE_OPERAND (exp, 0));
5556 : 6738155 : if (!op0 || !MEM_P (op0))
5557 : : {
5558 : 1777301 : if ((TREE_CODE (TREE_OPERAND (exp, 0)) == VAR_DECL
5559 : 396535 : || TREE_CODE (TREE_OPERAND (exp, 0)) == PARM_DECL
5560 : 345482 : || TREE_CODE (TREE_OPERAND (exp, 0)) == RESULT_DECL)
5561 : 1828354 : && (!TREE_ADDRESSABLE (TREE_OPERAND (exp, 0))
5562 : 125978 : || target_for_debug_bind (TREE_OPERAND (exp, 0))))
5563 : 1311756 : return gen_rtx_DEBUG_IMPLICIT_PTR (mode, TREE_OPERAND (exp, 0));
5564 : :
5565 : 465545 : if (handled_component_p (TREE_OPERAND (exp, 0)))
5566 : : {
5567 : 326913 : poly_int64 bitoffset, bitsize, maxsize, byteoffset;
5568 : 326913 : bool reverse;
5569 : 326913 : tree decl
5570 : 326913 : = get_ref_base_and_extent (TREE_OPERAND (exp, 0), &bitoffset,
5571 : : &bitsize, &maxsize, &reverse);
5572 : 326913 : if ((VAR_P (decl)
5573 : : || TREE_CODE (decl) == PARM_DECL
5574 : : || TREE_CODE (decl) == RESULT_DECL)
5575 : 290593 : && (!TREE_ADDRESSABLE (decl)
5576 : 22949 : || target_for_debug_bind (decl))
5577 : 61981 : && multiple_p (bitoffset, BITS_PER_UNIT, &byteoffset)
5578 : 267644 : && known_gt (bitsize, 0)
5579 : 264934 : && known_eq (bitsize, maxsize))
5580 : : {
5581 : 264932 : rtx base = gen_rtx_DEBUG_IMPLICIT_PTR (mode, decl);
5582 : 264932 : return plus_constant (mode, base, byteoffset);
5583 : : }
5584 : : }
5585 : :
5586 : 200613 : if (TREE_CODE (TREE_OPERAND (exp, 0)) == MEM_REF
5587 : 200613 : && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
5588 : : == ADDR_EXPR)
5589 : : {
5590 : 8290 : op0 = expand_debug_expr (TREE_OPERAND (TREE_OPERAND (exp, 0),
5591 : : 0));
5592 : 8290 : if (op0 != NULL
5593 : 4870 : && (GET_CODE (op0) == DEBUG_IMPLICIT_PTR
5594 : 0 : || (GET_CODE (op0) == PLUS
5595 : 0 : && GET_CODE (XEXP (op0, 0)) == DEBUG_IMPLICIT_PTR
5596 : 0 : && CONST_INT_P (XEXP (op0, 1)))))
5597 : : {
5598 : 4870 : op1 = expand_debug_expr (TREE_OPERAND (TREE_OPERAND (exp, 0),
5599 : : 1));
5600 : 4870 : poly_int64 offset;
5601 : 9740 : if (!op1 || !poly_int_rtx_p (op1, &offset))
5602 : : return NULL;
5603 : :
5604 : 4870 : return plus_constant (mode, op0, offset);
5605 : : }
5606 : : }
5607 : :
5608 : 195743 : return NULL;
5609 : : }
5610 : :
5611 : 4960854 : as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)));
5612 : 4960854 : addr_mode = SCALAR_INT_TYPE_MODE (TREE_TYPE (exp));
5613 : 4960854 : op0 = convert_debug_memory_address (addr_mode, XEXP (op0, 0), as);
5614 : :
5615 : 4960854 : return op0;
5616 : :
5617 : 992 : case VECTOR_CST:
5618 : 992 : {
5619 : 992 : unsigned HOST_WIDE_INT i, nelts;
5620 : :
5621 : 992 : if (!VECTOR_CST_NELTS (exp).is_constant (&nelts))
5622 : : return NULL;
5623 : :
5624 : 992 : op0 = gen_rtx_CONCATN (mode, rtvec_alloc (nelts));
5625 : :
5626 : 5243 : for (i = 0; i < nelts; ++i)
5627 : : {
5628 : 4251 : op1 = expand_debug_expr (VECTOR_CST_ELT (exp, i));
5629 : 4251 : if (!op1)
5630 : : return NULL;
5631 : 4251 : XVECEXP (op0, 0, i) = op1;
5632 : : }
5633 : :
5634 : : return op0;
5635 : : }
5636 : :
5637 : 281 : case CONSTRUCTOR:
5638 : 281 : if (TREE_CLOBBER_P (exp))
5639 : : return NULL;
5640 : 281 : else if (TREE_CODE (TREE_TYPE (exp)) == VECTOR_TYPE)
5641 : : {
5642 : 281 : unsigned i;
5643 : 281 : unsigned HOST_WIDE_INT nelts;
5644 : 281 : tree val;
5645 : :
5646 : 281 : if (!TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp)).is_constant (&nelts))
5647 : : goto flag_unsupported;
5648 : :
5649 : 281 : op0 = gen_rtx_CONCATN (mode, rtvec_alloc (nelts));
5650 : :
5651 : 1444 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), i, val)
5652 : : {
5653 : 1174 : op1 = expand_debug_expr (val);
5654 : 1174 : if (!op1)
5655 : 39552171 : return NULL;
5656 : 1163 : XVECEXP (op0, 0, i) = op1;
5657 : : }
5658 : :
5659 : 270 : if (i < nelts)
5660 : : {
5661 : 23 : op1 = expand_debug_expr
5662 : 23 : (build_zero_cst (TREE_TYPE (TREE_TYPE (exp))));
5663 : :
5664 : 23 : if (!op1)
5665 : : return NULL;
5666 : :
5667 : 166 : for (; i < nelts; i++)
5668 : 143 : XVECEXP (op0, 0, i) = op1;
5669 : : }
5670 : :
5671 : 270 : return op0;
5672 : : }
5673 : : else
5674 : 0 : goto flag_unsupported;
5675 : :
5676 : : case CALL_EXPR:
5677 : : /* ??? Maybe handle some builtins? */
5678 : : return NULL;
5679 : :
5680 : 9009815 : case SSA_NAME:
5681 : 9009815 : {
5682 : 9009815 : gimple *g = get_gimple_for_ssa_name (exp);
5683 : 9009815 : if (g)
5684 : : {
5685 : 1372988 : tree t = NULL_TREE;
5686 : 1372988 : if (deep_ter_debug_map)
5687 : : {
5688 : 138668 : tree *slot = deep_ter_debug_map->get (exp);
5689 : 138668 : if (slot)
5690 : 19333 : t = *slot;
5691 : : }
5692 : 19333 : if (t == NULL_TREE)
5693 : : {
5694 : 1359188 : if (is_gimple_assign (g))
5695 : 1358976 : t = gimple_assign_rhs_to_tree (g);
5696 : : else
5697 : : /* expand_debug_expr doesn't handle CALL_EXPR right now. */
5698 : : return NULL;
5699 : : }
5700 : 1372776 : op0 = expand_debug_expr (t);
5701 : 1372776 : if (!op0)
5702 : : return NULL;
5703 : : }
5704 : : else
5705 : : {
5706 : : /* If this is a reference to an incoming value of
5707 : : parameter that is never used in the code or where the
5708 : : incoming value is never used in the code, use
5709 : : PARM_DECL's DECL_RTL if set. */
5710 : 7636827 : if (SSA_NAME_IS_DEFAULT_DEF (exp)
5711 : 1278173 : && SSA_NAME_VAR (exp)
5712 : 1278173 : && TREE_CODE (SSA_NAME_VAR (exp)) == PARM_DECL
5713 : 8861511 : && has_zero_uses (exp))
5714 : : {
5715 : 17690 : op0 = expand_debug_parm_decl (SSA_NAME_VAR (exp));
5716 : 17690 : if (op0)
5717 : 17600 : goto adjust_mode;
5718 : 90 : op0 = expand_debug_expr (SSA_NAME_VAR (exp));
5719 : 90 : if (op0)
5720 : 90 : goto adjust_mode;
5721 : : }
5722 : :
5723 : 7619137 : int part = var_to_partition (SA.map, exp);
5724 : :
5725 : 7619137 : if (part == NO_PARTITION)
5726 : : return NULL;
5727 : :
5728 : 7613991 : gcc_assert (part >= 0 && (unsigned)part < SA.map->num_partitions);
5729 : :
5730 : 7613991 : op0 = copy_rtx (SA.partition_to_pseudo[part]);
5731 : : }
5732 : 8983510 : goto adjust_mode;
5733 : : }
5734 : :
5735 : : case ERROR_MARK:
5736 : : return NULL;
5737 : :
5738 : : /* Vector stuff. For most of the codes we don't have rtl codes. */
5739 : : case REALIGN_LOAD_EXPR:
5740 : : case VEC_COND_EXPR:
5741 : : case VEC_PACK_FIX_TRUNC_EXPR:
5742 : : case VEC_PACK_FLOAT_EXPR:
5743 : : case VEC_PACK_SAT_EXPR:
5744 : : case VEC_PACK_TRUNC_EXPR:
5745 : : case VEC_UNPACK_FIX_TRUNC_HI_EXPR:
5746 : : case VEC_UNPACK_FIX_TRUNC_LO_EXPR:
5747 : : case VEC_UNPACK_FLOAT_HI_EXPR:
5748 : : case VEC_UNPACK_FLOAT_LO_EXPR:
5749 : : case VEC_UNPACK_HI_EXPR:
5750 : : case VEC_UNPACK_LO_EXPR:
5751 : : case VEC_WIDEN_MULT_HI_EXPR:
5752 : : case VEC_WIDEN_MULT_LO_EXPR:
5753 : : case VEC_WIDEN_MULT_EVEN_EXPR:
5754 : : case VEC_WIDEN_MULT_ODD_EXPR:
5755 : : case VEC_WIDEN_LSHIFT_HI_EXPR:
5756 : : case VEC_WIDEN_LSHIFT_LO_EXPR:
5757 : : case VEC_PERM_EXPR:
5758 : : case VEC_DUPLICATE_EXPR:
5759 : : case VEC_SERIES_EXPR:
5760 : : case SAD_EXPR:
5761 : : return NULL;
5762 : :
5763 : : /* Misc codes. */
5764 : : case ADDR_SPACE_CONVERT_EXPR:
5765 : : case FIXED_CONVERT_EXPR:
5766 : : case OBJ_TYPE_REF:
5767 : : case WITH_SIZE_EXPR:
5768 : : case BIT_INSERT_EXPR:
5769 : : return NULL;
5770 : :
5771 : 0 : case DOT_PROD_EXPR:
5772 : 0 : if (SCALAR_INT_MODE_P (GET_MODE (op0))
5773 : 0 : && SCALAR_INT_MODE_P (mode))
5774 : : {
5775 : 0 : op0
5776 : 0 : = simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp,
5777 : : 0)))
5778 : : ? ZERO_EXTEND : SIGN_EXTEND, mode, op0,
5779 : : inner_mode);
5780 : 0 : op1
5781 : 0 : = simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp,
5782 : : 1)))
5783 : : ? ZERO_EXTEND : SIGN_EXTEND, mode, op1,
5784 : : inner_mode);
5785 : 0 : op0 = simplify_gen_binary (MULT, mode, op0, op1);
5786 : 0 : return simplify_gen_binary (PLUS, mode, op0, op2);
5787 : : }
5788 : : return NULL;
5789 : :
5790 : 4083 : case WIDEN_MULT_EXPR:
5791 : 4083 : case WIDEN_MULT_PLUS_EXPR:
5792 : 4083 : case WIDEN_MULT_MINUS_EXPR:
5793 : 4083 : if (SCALAR_INT_MODE_P (GET_MODE (op0))
5794 : 4083 : && SCALAR_INT_MODE_P (mode))
5795 : : {
5796 : 4083 : inner_mode = GET_MODE (op0);
5797 : 4083 : if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))))
5798 : 3464 : op0 = simplify_gen_unary (ZERO_EXTEND, mode, op0, inner_mode);
5799 : : else
5800 : 619 : op0 = simplify_gen_unary (SIGN_EXTEND, mode, op0, inner_mode);
5801 : 4083 : if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 1))))
5802 : 3464 : op1 = simplify_gen_unary (ZERO_EXTEND, mode, op1, inner_mode);
5803 : : else
5804 : 619 : op1 = simplify_gen_unary (SIGN_EXTEND, mode, op1, inner_mode);
5805 : 4083 : op0 = simplify_gen_binary (MULT, mode, op0, op1);
5806 : 4083 : if (TREE_CODE (exp) == WIDEN_MULT_EXPR)
5807 : : return op0;
5808 : 0 : else if (TREE_CODE (exp) == WIDEN_MULT_PLUS_EXPR)
5809 : 0 : return simplify_gen_binary (PLUS, mode, op0, op2);
5810 : : else
5811 : 0 : return simplify_gen_binary (MINUS, mode, op2, op0);
5812 : : }
5813 : : return NULL;
5814 : :
5815 : : case MULT_HIGHPART_EXPR:
5816 : : /* ??? Similar to the above. */
5817 : : return NULL;
5818 : :
5819 : 0 : case WIDEN_SUM_EXPR:
5820 : 0 : case WIDEN_LSHIFT_EXPR:
5821 : 0 : if (SCALAR_INT_MODE_P (GET_MODE (op0))
5822 : 0 : && SCALAR_INT_MODE_P (mode))
5823 : : {
5824 : 0 : op0
5825 : 0 : = simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp,
5826 : : 0)))
5827 : : ? ZERO_EXTEND : SIGN_EXTEND, mode, op0,
5828 : : inner_mode);
5829 : 0 : return simplify_gen_binary (TREE_CODE (exp) == WIDEN_LSHIFT_EXPR
5830 : 0 : ? ASHIFT : PLUS, mode, op0, op1);
5831 : : }
5832 : : return NULL;
5833 : :
5834 : 0 : default:
5835 : 0 : flag_unsupported:
5836 : 0 : if (flag_checking)
5837 : : {
5838 : 0 : debug_tree (exp);
5839 : 0 : gcc_unreachable ();
5840 : : }
5841 : : return NULL;
5842 : : }
5843 : : }
5844 : :
5845 : : /* Return an RTX equivalent to the source bind value of the tree expression
5846 : : EXP. */
5847 : :
5848 : : static rtx
5849 : 151037 : expand_debug_source_expr (tree exp)
5850 : : {
5851 : 285686 : rtx op0 = NULL_RTX;
5852 : 285686 : machine_mode mode = VOIDmode, inner_mode;
5853 : :
5854 : 285686 : switch (TREE_CODE (exp))
5855 : : {
5856 : 134649 : case VAR_DECL:
5857 : 134649 : if (DECL_ABSTRACT_ORIGIN (exp))
5858 : 134649 : return expand_debug_source_expr (DECL_ABSTRACT_ORIGIN (exp));
5859 : : break;
5860 : 150520 : case PARM_DECL:
5861 : 150520 : {
5862 : 150520 : mode = DECL_MODE (exp);
5863 : 150520 : op0 = expand_debug_parm_decl (exp);
5864 : 150520 : if (op0)
5865 : : break;
5866 : : /* See if this isn't an argument that has been completely
5867 : : optimized out. */
5868 : 149893 : if (!DECL_RTL_SET_P (exp)
5869 : 149879 : && !DECL_INCOMING_RTL (exp)
5870 : 299772 : && DECL_ABSTRACT_ORIGIN (current_function_decl))
5871 : : {
5872 : 41851 : tree aexp = DECL_ORIGIN (exp);
5873 : 41851 : if (DECL_CONTEXT (aexp)
5874 : 41851 : == DECL_ABSTRACT_ORIGIN (current_function_decl))
5875 : : {
5876 : 18884 : vec<tree, va_gc> **debug_args;
5877 : 18884 : unsigned int ix;
5878 : 18884 : tree ddecl;
5879 : 18884 : debug_args = decl_debug_args_lookup (current_function_decl);
5880 : 18884 : if (debug_args != NULL)
5881 : : {
5882 : 23414 : for (ix = 0; vec_safe_iterate (*debug_args, ix, &ddecl);
5883 : 4534 : ix += 2)
5884 : 23398 : if (ddecl == aexp)
5885 : 18864 : return gen_rtx_DEBUG_PARAMETER_REF (mode, aexp);
5886 : : }
5887 : : }
5888 : : }
5889 : : break;
5890 : : }
5891 : : default:
5892 : : break;
5893 : : }
5894 : :
5895 : 627 : if (op0 == NULL_RTX)
5896 : 131546 : return NULL_RTX;
5897 : :
5898 : 627 : inner_mode = GET_MODE (op0);
5899 : 627 : if (mode == inner_mode)
5900 : : return op0;
5901 : :
5902 : 21 : if (FLOAT_MODE_P (mode) && FLOAT_MODE_P (inner_mode))
5903 : : {
5904 : 7 : if (GET_MODE_UNIT_BITSIZE (mode)
5905 : 14 : == GET_MODE_UNIT_BITSIZE (inner_mode))
5906 : 0 : op0 = simplify_gen_subreg (mode, op0, inner_mode, 0);
5907 : 7 : else if (GET_MODE_UNIT_BITSIZE (mode)
5908 : 14 : < GET_MODE_UNIT_BITSIZE (inner_mode))
5909 : 7 : op0 = simplify_gen_unary (FLOAT_TRUNCATE, mode, op0, inner_mode);
5910 : : else
5911 : 0 : op0 = simplify_gen_unary (FLOAT_EXTEND, mode, op0, inner_mode);
5912 : : }
5913 : 14 : else if (FLOAT_MODE_P (mode))
5914 : 0 : gcc_unreachable ();
5915 : 14 : else if (FLOAT_MODE_P (inner_mode))
5916 : : {
5917 : 0 : if (TYPE_UNSIGNED (TREE_TYPE (exp)))
5918 : 0 : op0 = simplify_gen_unary (UNSIGNED_FIX, mode, op0, inner_mode);
5919 : : else
5920 : 0 : op0 = simplify_gen_unary (FIX, mode, op0, inner_mode);
5921 : : }
5922 : 28 : else if (GET_MODE_UNIT_PRECISION (mode)
5923 : 14 : == GET_MODE_UNIT_PRECISION (inner_mode))
5924 : 0 : op0 = lowpart_subreg (mode, op0, inner_mode);
5925 : 28 : else if (GET_MODE_UNIT_PRECISION (mode)
5926 : 14 : < GET_MODE_UNIT_PRECISION (inner_mode))
5927 : 14 : op0 = simplify_gen_unary (TRUNCATE, mode, op0, inner_mode);
5928 : 0 : else if (TYPE_UNSIGNED (TREE_TYPE (exp)))
5929 : 0 : op0 = simplify_gen_unary (ZERO_EXTEND, mode, op0, inner_mode);
5930 : : else
5931 : 0 : op0 = simplify_gen_unary (SIGN_EXTEND, mode, op0, inner_mode);
5932 : :
5933 : : return op0;
5934 : : }
5935 : :
5936 : : /* Ensure INSN_VAR_LOCATION_LOC (insn) doesn't have unbound complexity.
5937 : : Allow 4 levels of rtl nesting for most rtl codes, and if we see anything
5938 : : deeper than that, create DEBUG_EXPRs and emit DEBUG_INSNs before INSN. */
5939 : :
5940 : : static void
5941 : 48020406 : avoid_complex_debug_insns (rtx_insn *insn, rtx *exp_p, int depth)
5942 : : {
5943 : 48020406 : rtx exp = *exp_p;
5944 : :
5945 : 48020406 : if (exp == NULL_RTX)
5946 : : return;
5947 : :
5948 : 48020406 : if ((OBJECT_P (exp) && !MEM_P (exp)) || GET_CODE (exp) == CLOBBER)
5949 : : return;
5950 : :
5951 : 6476831 : if (depth == 4)
5952 : : {
5953 : : /* Create DEBUG_EXPR (and DEBUG_EXPR_DECL). */
5954 : 27384 : rtx dval = make_debug_expr_from_rtl (exp);
5955 : :
5956 : : /* Emit a debug bind insn before INSN. */
5957 : 27384 : rtx bind = gen_rtx_VAR_LOCATION (GET_MODE (exp),
5958 : : DEBUG_EXPR_TREE_DECL (dval), exp,
5959 : : VAR_INIT_STATUS_INITIALIZED);
5960 : :
5961 : 27384 : emit_debug_insn_before (bind, insn);
5962 : 27384 : *exp_p = dval;
5963 : 27384 : return;
5964 : : }
5965 : :
5966 : 6449447 : const char *format_ptr = GET_RTX_FORMAT (GET_CODE (exp));
5967 : 6449447 : int i, j;
5968 : 19237475 : for (i = 0; i < GET_RTX_LENGTH (GET_CODE (exp)); i++)
5969 : 12788028 : switch (*format_ptr++)
5970 : : {
5971 : 11744826 : case 'e':
5972 : 11744826 : avoid_complex_debug_insns (insn, &XEXP (exp, i), depth + 1);
5973 : 11744826 : break;
5974 : :
5975 : : case 'E':
5976 : : case 'V':
5977 : 0 : for (j = 0; j < XVECLEN (exp, i); j++)
5978 : 0 : avoid_complex_debug_insns (insn, &XVECEXP (exp, i, j), depth + 1);
5979 : : break;
5980 : :
5981 : : default:
5982 : : break;
5983 : : }
5984 : : }
5985 : :
5986 : : /* Expand the _LOCs in debug insns. We run this after expanding all
5987 : : regular insns, so that any variables referenced in the function
5988 : : will have their DECL_RTLs set. */
5989 : :
5990 : : static void
5991 : 496676 : expand_debug_locations (void)
5992 : : {
5993 : 496676 : rtx_insn *insn;
5994 : 496676 : rtx_insn *last = get_last_insn ();
5995 : 496676 : int save_strict_alias = flag_strict_aliasing;
5996 : :
5997 : : /* New alias sets while setting up memory attributes cause
5998 : : -fcompare-debug failures, even though it doesn't bring about any
5999 : : codegen changes. */
6000 : 496676 : flag_strict_aliasing = 0;
6001 : :
6002 : 103858039 : for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
6003 : 103361363 : if (DEBUG_BIND_INSN_P (insn))
6004 : : {
6005 : 36248196 : tree value = (tree)INSN_VAR_LOCATION_LOC (insn);
6006 : 36248196 : rtx val;
6007 : 36248196 : rtx_insn *prev_insn, *insn2;
6008 : 36248196 : machine_mode mode;
6009 : :
6010 : 36248196 : if (value == NULL_TREE)
6011 : : val = NULL_RTX;
6012 : : else
6013 : : {
6014 : 20444798 : if (INSN_VAR_LOCATION_STATUS (insn)
6015 : : == VAR_INIT_STATUS_UNINITIALIZED)
6016 : 151037 : val = expand_debug_source_expr (value);
6017 : : /* The avoid_deep_ter_for_debug function inserts
6018 : : debug bind stmts after SSA_NAME definition, with the
6019 : : SSA_NAME as the whole bind location. Disable temporarily
6020 : : expansion of that SSA_NAME into the DEBUG_EXPR_DECL
6021 : : being defined in this DEBUG_INSN. */
6022 : 20293761 : else if (deep_ter_debug_map && TREE_CODE (value) == SSA_NAME)
6023 : : {
6024 : 128169 : tree *slot = deep_ter_debug_map->get (value);
6025 : 128169 : if (slot)
6026 : : {
6027 : 6663 : if (*slot == INSN_VAR_LOCATION_DECL (insn))
6028 : 5533 : *slot = NULL_TREE;
6029 : : else
6030 : : slot = NULL;
6031 : : }
6032 : 128169 : val = expand_debug_expr (value);
6033 : 128169 : if (slot)
6034 : 5533 : *slot = INSN_VAR_LOCATION_DECL (insn);
6035 : : }
6036 : : else
6037 : 20165592 : val = expand_debug_expr (value);
6038 : 20444798 : gcc_assert (last == get_last_insn ());
6039 : : }
6040 : :
6041 : 20444798 : if (!val)
6042 : 16173785 : val = gen_rtx_UNKNOWN_VAR_LOC ();
6043 : : else
6044 : : {
6045 : 20074411 : mode = GET_MODE (INSN_VAR_LOCATION (insn));
6046 : :
6047 : 20074411 : gcc_assert (mode == GET_MODE (val)
6048 : : || (GET_MODE (val) == VOIDmode
6049 : : && (CONST_SCALAR_INT_P (val)
6050 : : || GET_CODE (val) == CONST_FIXED
6051 : : || GET_CODE (val) == LABEL_REF)));
6052 : : }
6053 : :
6054 : 36248196 : INSN_VAR_LOCATION_LOC (insn) = val;
6055 : 36248196 : prev_insn = PREV_INSN (insn);
6056 : 72523776 : for (insn2 = insn; insn2 != prev_insn; insn2 = PREV_INSN (insn2))
6057 : 36275580 : avoid_complex_debug_insns (insn2, &INSN_VAR_LOCATION_LOC (insn2), 0);
6058 : : }
6059 : :
6060 : 496676 : flag_strict_aliasing = save_strict_alias;
6061 : 496676 : }
6062 : :
6063 : : /* Performs swapping operands of commutative operations to expand
6064 : : the expensive one first. */
6065 : :
6066 : : static void
6067 : 9293450 : reorder_operands (basic_block bb)
6068 : : {
6069 : 9293450 : unsigned int *lattice; /* Hold cost of each statement. */
6070 : 9293450 : unsigned int i = 0, n = 0;
6071 : 9293450 : gimple_stmt_iterator gsi;
6072 : 9293450 : gimple_seq stmts;
6073 : 9293450 : gimple *stmt;
6074 : 9293450 : bool swap;
6075 : 9293450 : tree op0, op1;
6076 : 9293450 : ssa_op_iter iter;
6077 : 9293450 : use_operand_p use_p;
6078 : 9293450 : gimple *def0, *def1;
6079 : :
6080 : : /* Compute cost of each statement using estimate_num_insns. */
6081 : 9293450 : stmts = bb_seq (bb);
6082 : 91663537 : for (gsi = gsi_start (stmts); !gsi_end_p (gsi); gsi_next (&gsi))
6083 : : {
6084 : 82370087 : stmt = gsi_stmt (gsi);
6085 : 82370087 : if (!is_gimple_debug (stmt))
6086 : 34001569 : gimple_set_uid (stmt, n++);
6087 : : }
6088 : 9293450 : lattice = XNEWVEC (unsigned int, n);
6089 : 91663537 : for (gsi = gsi_start (stmts); !gsi_end_p (gsi); gsi_next (&gsi))
6090 : : {
6091 : 82370087 : unsigned cost;
6092 : 82370087 : stmt = gsi_stmt (gsi);
6093 : 82370087 : if (is_gimple_debug (stmt))
6094 : 48368518 : continue;
6095 : 34001569 : cost = estimate_num_insns (stmt, &eni_size_weights);
6096 : 34001569 : lattice[i] = cost;
6097 : 64280010 : FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
6098 : : {
6099 : 30278441 : tree use = USE_FROM_PTR (use_p);
6100 : 30278441 : gimple *def_stmt;
6101 : 30278441 : if (TREE_CODE (use) != SSA_NAME)
6102 : 0 : continue;
6103 : 30278441 : def_stmt = get_gimple_for_ssa_name (use);
6104 : 30278441 : if (!def_stmt)
6105 : 21438363 : continue;
6106 : 8840078 : lattice[i] += lattice[gimple_uid (def_stmt)];
6107 : : }
6108 : 34001569 : i++;
6109 : 34001569 : if (!is_gimple_assign (stmt)
6110 : 34001569 : || !commutative_tree_code (gimple_assign_rhs_code (stmt)))
6111 : 29901406 : continue;
6112 : 4100163 : op0 = gimple_op (stmt, 1);
6113 : 4100163 : op1 = gimple_op (stmt, 2);
6114 : 4100163 : if (TREE_CODE (op0) != SSA_NAME
6115 : 4099948 : || TREE_CODE (op1) != SSA_NAME)
6116 : 2633450 : continue;
6117 : : /* Swap operands if the second one is more expensive. */
6118 : 1466713 : def0 = get_gimple_for_ssa_name (op0);
6119 : 1466713 : def1 = get_gimple_for_ssa_name (op1);
6120 : 1466713 : if (!def1)
6121 : 805045 : continue;
6122 : 661668 : swap = false;
6123 : 661668 : if (!def0 || lattice[gimple_uid (def1)] > lattice[gimple_uid (def0)])
6124 : 315109 : swap = true;
6125 : 315109 : if (swap)
6126 : : {
6127 : 315109 : if (dump_file && (dump_flags & TDF_DETAILS))
6128 : : {
6129 : 2 : fprintf (dump_file, "Swap operands in stmt:\n");
6130 : 2 : print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
6131 : 2 : fprintf (dump_file, "Cost left opnd=%d, right opnd=%d\n",
6132 : 1 : def0 ? lattice[gimple_uid (def0)] : 0,
6133 : 2 : lattice[gimple_uid (def1)]);
6134 : : }
6135 : 315109 : swap_ssa_operands (stmt, gimple_assign_rhs1_ptr (stmt),
6136 : : gimple_assign_rhs2_ptr (stmt));
6137 : : }
6138 : : }
6139 : 9293450 : XDELETE (lattice);
6140 : 9293450 : }
6141 : :
6142 : : /* Expand basic block BB from GIMPLE trees to RTL. */
6143 : :
6144 : : static basic_block
6145 : 12576996 : expand_gimple_basic_block (basic_block bb, bool disable_tail_calls)
6146 : : {
6147 : 12576996 : gimple_stmt_iterator gsi;
6148 : 12576996 : gimple *stmt = NULL;
6149 : 12576996 : rtx_note *note = NULL;
6150 : 12576996 : rtx_insn *last;
6151 : 12576996 : edge e;
6152 : 12576996 : edge_iterator ei;
6153 : 12576996 : bool nondebug_stmt_seen = false;
6154 : :
6155 : 12576996 : if (dump_file)
6156 : 757 : fprintf (dump_file, "\n;; Generating RTL for gimple basic block %d\n",
6157 : : bb->index);
6158 : :
6159 : : /* Note that since we are now transitioning from GIMPLE to RTL, we
6160 : : cannot use the gsi_*_bb() routines because they expect the basic
6161 : : block to be in GIMPLE, instead of RTL. Therefore, we need to
6162 : : access the BB sequence directly. */
6163 : 12576996 : if (optimize)
6164 : 9293450 : reorder_operands (bb);
6165 : 12576996 : rtl_profile_for_bb (bb);
6166 : :
6167 : : /* Remove the RETURN_EXPR if we may fall though to the exit
6168 : : instead. */
6169 : 12576996 : gsi = gsi_last_bb (bb);
6170 : 12576996 : if (!gsi_end_p (gsi) && gimple_code (gsi_stmt (gsi)) == GIMPLE_RETURN)
6171 : : {
6172 : 1418785 : greturn *ret_stmt = as_a <greturn *> (gsi_stmt (gsi));
6173 : :
6174 : 1418785 : gcc_assert (single_succ_p (bb));
6175 : 1418785 : gcc_assert (single_succ (bb) == EXIT_BLOCK_PTR_FOR_FN (cfun));
6176 : :
6177 : 1418785 : if (bb->next_bb == EXIT_BLOCK_PTR_FOR_FN (cfun)
6178 : 1418785 : && !gimple_return_retval (ret_stmt))
6179 : : {
6180 : 586960 : gsi_remove (&gsi, false);
6181 : 586960 : single_succ_edge (bb)->flags |= EDGE_FALLTHRU;
6182 : : }
6183 : : }
6184 : :
6185 : 12576996 : gsi = gsi_start_bb (bb);
6186 : 12576996 : if (!gsi_end_p (gsi))
6187 : : {
6188 : 12034268 : stmt = gsi_stmt (gsi);
6189 : 12034268 : if (gimple_code (stmt) != GIMPLE_LABEL)
6190 : 11956448 : stmt = NULL;
6191 : : }
6192 : :
6193 : 12576996 : rtx_code_label **elt = lab_rtx_for_bb->get (bb);
6194 : 12576996 : if ((unsigned) bb->index >= head_end_for_bb.length ())
6195 : 12445529 : head_end_for_bb.safe_grow_cleared (bb->index + 1);
6196 : :
6197 : 12576996 : if (stmt || elt)
6198 : : {
6199 : 5242646 : gcc_checking_assert (!note);
6200 : 5242646 : last = get_last_insn ();
6201 : :
6202 : 5242646 : if (stmt)
6203 : : {
6204 : 620548 : expand_gimple_stmt (stmt);
6205 : 620548 : gsi_next (&gsi);
6206 : : }
6207 : :
6208 : 5242646 : if (elt)
6209 : 4622098 : emit_label (*elt);
6210 : :
6211 : 5242646 : head_end_for_bb[bb->index].first = NEXT_INSN (last);
6212 : 5242646 : if (NOTE_P (head_end_for_bb[bb->index].first))
6213 : 0 : head_end_for_bb[bb->index].first
6214 : 0 : = NEXT_INSN (head_end_for_bb[bb->index].first);
6215 : 5242646 : gcc_assert (LABEL_P (head_end_for_bb[bb->index].first));
6216 : 10485292 : note = emit_note_after (NOTE_INSN_BASIC_BLOCK,
6217 : 5242646 : head_end_for_bb[bb->index].first);
6218 : :
6219 : 5242646 : maybe_dump_rtl_for_gimple_stmt (stmt, last);
6220 : : }
6221 : : else
6222 : 7334350 : head_end_for_bb[bb->index].first = note = emit_note (NOTE_INSN_BASIC_BLOCK);
6223 : :
6224 : 12576996 : if (note)
6225 : 12576996 : NOTE_BASIC_BLOCK (note) = bb;
6226 : :
6227 : 65638442 : for (; !gsi_end_p (gsi); gsi_next (&gsi))
6228 : : {
6229 : 53679177 : basic_block new_bb;
6230 : :
6231 : 53679177 : stmt = gsi_stmt (gsi);
6232 : 53679177 : if (!is_gimple_debug (stmt))
6233 : 45242987 : nondebug_stmt_seen = true;
6234 : :
6235 : : /* If this statement is a non-debug one, and we generate debug
6236 : : insns, then this one might be the last real use of a TERed
6237 : : SSA_NAME, but where there are still some debug uses further
6238 : : down. Expanding the current SSA name in such further debug
6239 : : uses by their RHS might lead to wrong debug info, as coalescing
6240 : : might make the operands of such RHS be placed into the same
6241 : : pseudo as something else. Like so:
6242 : : a_1 = a_0 + 1; // Assume a_1 is TERed and a_0 is dead
6243 : : use(a_1);
6244 : : a_2 = ...
6245 : : #DEBUG ... => a_1
6246 : : As a_0 and a_2 don't overlap in lifetime, assume they are coalesced.
6247 : : If we now would expand a_1 by it's RHS (a_0 + 1) in the debug use,
6248 : : the write to a_2 would actually have clobbered the place which
6249 : : formerly held a_0.
6250 : :
6251 : : So, instead of that, we recognize the situation, and generate
6252 : : debug temporaries at the last real use of TERed SSA names:
6253 : : a_1 = a_0 + 1;
6254 : : #DEBUG #D1 => a_1
6255 : : use(a_1);
6256 : : a_2 = ...
6257 : : #DEBUG ... => #D1
6258 : : */
6259 : 53679177 : if (MAY_HAVE_DEBUG_BIND_INSNS
6260 : 29795019 : && SA.values
6261 : 82259844 : && !is_gimple_debug (stmt))
6262 : : {
6263 : 20537617 : ssa_op_iter iter;
6264 : 20537617 : tree op;
6265 : 20537617 : gimple *def;
6266 : :
6267 : 20537617 : location_t sloc = curr_insn_location ();
6268 : :
6269 : : /* Look for SSA names that have their last use here (TERed
6270 : : names always have only one real use). */
6271 : 39117362 : FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE)
6272 : 18579745 : if ((def = get_gimple_for_ssa_name (op))
6273 : 18579745 : && is_gimple_assign (def))
6274 : : {
6275 : 5154775 : imm_use_iterator imm_iter;
6276 : 5154775 : use_operand_p use_p;
6277 : 5154775 : bool have_debug_uses = false;
6278 : :
6279 : 10283205 : FOR_EACH_IMM_USE_FAST (use_p, imm_iter, op)
6280 : : {
6281 : 5180933 : if (gimple_debug_bind_p (USE_STMT (use_p)))
6282 : : {
6283 : : have_debug_uses = true;
6284 : : break;
6285 : : }
6286 : : }
6287 : :
6288 : 5154775 : if (have_debug_uses)
6289 : : {
6290 : : /* OP is a TERed SSA name, with DEF its defining
6291 : : statement, and where OP is used in further debug
6292 : : instructions. Generate a debug temporary, and
6293 : : replace all uses of OP in debug insns with that
6294 : : temporary. */
6295 : 52503 : gimple *debugstmt;
6296 : 52503 : tree value = gimple_assign_rhs_to_tree (def);
6297 : 52503 : tree vexpr = build_debug_expr_decl (TREE_TYPE (value));
6298 : 52503 : rtx val;
6299 : 52503 : machine_mode mode;
6300 : :
6301 : 52503 : set_curr_insn_location (gimple_location (def));
6302 : :
6303 : 52503 : if (DECL_P (value))
6304 : 375 : mode = DECL_MODE (value);
6305 : : else
6306 : 52128 : mode = TYPE_MODE (TREE_TYPE (value));
6307 : : /* FIXME: Is setting the mode really necessary? */
6308 : 52503 : SET_DECL_MODE (vexpr, mode);
6309 : :
6310 : 52503 : val = gen_rtx_VAR_LOCATION
6311 : 52503 : (mode, vexpr, (rtx)value, VAR_INIT_STATUS_INITIALIZED);
6312 : :
6313 : 52503 : emit_debug_insn (val);
6314 : :
6315 : 182232 : FOR_EACH_IMM_USE_STMT (debugstmt, imm_iter, op)
6316 : : {
6317 : 129729 : if (!gimple_debug_bind_p (debugstmt))
6318 : 52503 : continue;
6319 : :
6320 : 235680 : FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
6321 : 79227 : SET_USE (use_p, vexpr);
6322 : :
6323 : 77226 : update_stmt (debugstmt);
6324 : 52503 : }
6325 : : }
6326 : : }
6327 : 20537617 : set_curr_insn_location (sloc);
6328 : : }
6329 : :
6330 : 53679177 : currently_expanding_gimple_stmt = stmt;
6331 : :
6332 : : /* Expand this statement, then evaluate the resulting RTL and
6333 : : fixup the CFG accordingly. */
6334 : 53679177 : if (gimple_code (stmt) == GIMPLE_COND)
6335 : : {
6336 : 5613012 : new_bb = expand_gimple_cond (bb, as_a <gcond *> (stmt));
6337 : 5613012 : if (new_bb)
6338 : : {
6339 : 493076 : currently_expanding_gimple_stmt = NULL;
6340 : 493076 : return new_bb;
6341 : : }
6342 : : }
6343 : 48066165 : else if (is_gimple_debug (stmt))
6344 : : {
6345 : 8436190 : location_t sloc = curr_insn_location ();
6346 : 8436190 : gimple_stmt_iterator nsi = gsi;
6347 : :
6348 : 48251380 : for (;;)
6349 : : {
6350 : 48251380 : tree var;
6351 : 48251380 : tree value = NULL_TREE;
6352 : 48251380 : rtx val = NULL_RTX;
6353 : 48251380 : machine_mode mode;
6354 : :
6355 : 48251380 : if (!gimple_debug_nonbind_marker_p (stmt))
6356 : : {
6357 : 36675136 : if (gimple_debug_bind_p (stmt))
6358 : : {
6359 : 36524099 : var = gimple_debug_bind_get_var (stmt);
6360 : :
6361 : 36524099 : if (TREE_CODE (var) != DEBUG_EXPR_DECL
6362 : 33857317 : && TREE_CODE (var) != LABEL_DECL
6363 : 70372654 : && !target_for_debug_bind (var))
6364 : 479443 : goto delink_debug_stmt;
6365 : :
6366 : 36044656 : if (DECL_P (var) && !VECTOR_TYPE_P (TREE_TYPE (var)))
6367 : 36035429 : mode = DECL_MODE (var);
6368 : : else
6369 : 9227 : mode = TYPE_MODE (TREE_TYPE (var));
6370 : :
6371 : 36044656 : if (gimple_debug_bind_has_value_p (stmt))
6372 : 20241258 : value = gimple_debug_bind_get_value (stmt);
6373 : :
6374 : 36044656 : val = gen_rtx_VAR_LOCATION
6375 : 36044656 : (mode, var, (rtx)value, VAR_INIT_STATUS_INITIALIZED);
6376 : : }
6377 : 151037 : else if (gimple_debug_source_bind_p (stmt))
6378 : : {
6379 : 151037 : var = gimple_debug_source_bind_get_var (stmt);
6380 : :
6381 : 151037 : value = gimple_debug_source_bind_get_value (stmt);
6382 : :
6383 : 151037 : if (!VECTOR_TYPE_P (TREE_TYPE (var)))
6384 : 151037 : mode = DECL_MODE (var);
6385 : : else
6386 : 0 : mode = TYPE_MODE (TREE_TYPE (var));
6387 : :
6388 : 151037 : val = gen_rtx_VAR_LOCATION (mode, var, (rtx)value,
6389 : : VAR_INIT_STATUS_UNINITIALIZED);
6390 : : }
6391 : : else
6392 : 0 : gcc_unreachable ();
6393 : : }
6394 : : /* If this function was first compiled with markers
6395 : : enabled, but they're now disable (e.g. LTO), drop
6396 : : them on the floor. */
6397 : 11576244 : else if (gimple_debug_nonbind_marker_p (stmt)
6398 : 11576244 : && !MAY_HAVE_DEBUG_MARKER_INSNS)
6399 : 0 : goto delink_debug_stmt;
6400 : 11576244 : else if (gimple_debug_begin_stmt_p (stmt))
6401 : 4096445 : val = GEN_RTX_DEBUG_MARKER_BEGIN_STMT_PAT ();
6402 : 7479799 : else if (gimple_debug_inline_entry_p (stmt))
6403 : 7479799 : val = GEN_RTX_DEBUG_MARKER_INLINE_ENTRY_PAT ();
6404 : : else
6405 : : gcc_unreachable ();
6406 : :
6407 : 47771937 : last = get_last_insn ();
6408 : :
6409 : 47771937 : set_curr_insn_location (gimple_location (stmt));
6410 : :
6411 : 47771937 : emit_debug_insn (val);
6412 : :
6413 : 47771937 : if (dump_file && (dump_flags & TDF_DETAILS))
6414 : : {
6415 : : /* We can't dump the insn with a TREE where an RTX
6416 : : is expected. */
6417 : 1 : if (GET_CODE (val) == VAR_LOCATION)
6418 : : {
6419 : 0 : gcc_checking_assert (PAT_VAR_LOCATION_LOC (val) == (rtx)value);
6420 : 0 : PAT_VAR_LOCATION_LOC (val) = const0_rtx;
6421 : : }
6422 : 1 : maybe_dump_rtl_for_gimple_stmt (stmt, last);
6423 : 1 : if (GET_CODE (val) == VAR_LOCATION)
6424 : 0 : PAT_VAR_LOCATION_LOC (val) = (rtx)value;
6425 : : }
6426 : :
6427 : 48251380 : delink_debug_stmt:
6428 : : /* In order not to generate too many debug temporaries,
6429 : : we delink all uses of debug statements we already expanded.
6430 : : Therefore debug statements between definition and real
6431 : : use of TERed SSA names will continue to use the SSA name,
6432 : : and not be replaced with debug temps. */
6433 : 48251380 : delink_stmt_imm_use (stmt);
6434 : :
6435 : 48251380 : gsi = nsi;
6436 : 48251380 : gsi_next (&nsi);
6437 : 48251380 : if (gsi_end_p (nsi))
6438 : : break;
6439 : 47549452 : stmt = gsi_stmt (nsi);
6440 : 47549452 : if (!is_gimple_debug (stmt))
6441 : : break;
6442 : : }
6443 : :
6444 : 8436190 : set_curr_insn_location (sloc);
6445 : : }
6446 : : else
6447 : : {
6448 : 39629975 : gcall *call_stmt = dyn_cast <gcall *> (stmt);
6449 : 6805942 : if (call_stmt
6450 : 6805942 : && gimple_call_tail_p (call_stmt)
6451 : 173647 : && disable_tail_calls)
6452 : 12 : gimple_call_set_tail (call_stmt, false);
6453 : :
6454 : 39629975 : if (call_stmt && gimple_call_tail_p (call_stmt))
6455 : : {
6456 : 173635 : bool can_fallthru;
6457 : 173635 : new_bb = expand_gimple_tailcall (bb, call_stmt, &can_fallthru);
6458 : 173635 : if (new_bb)
6459 : : {
6460 : 124655 : if (can_fallthru)
6461 : 0 : bb = new_bb;
6462 : : else
6463 : : {
6464 : 124655 : currently_expanding_gimple_stmt = NULL;
6465 : 124655 : return new_bb;
6466 : : }
6467 : : }
6468 : : }
6469 : : else
6470 : : {
6471 : 39456340 : def_operand_p def_p;
6472 : 39456340 : def_p = SINGLE_SSA_DEF_OPERAND (stmt, SSA_OP_DEF);
6473 : :
6474 : 39456340 : if (def_p != NULL)
6475 : : {
6476 : : /* Ignore this stmt if it is in the list of
6477 : : replaceable expressions. */
6478 : 33215003 : if (SA.values
6479 : 41165595 : && bitmap_bit_p (SA.values,
6480 : 16790558 : SSA_NAME_VERSION (DEF_FROM_PTR (def_p))))
6481 : 8839966 : continue;
6482 : : }
6483 : 30616374 : last = expand_gimple_stmt (stmt);
6484 : 30616374 : maybe_dump_rtl_for_gimple_stmt (stmt, last);
6485 : : }
6486 : : }
6487 : : }
6488 : :
6489 : 11959265 : currently_expanding_gimple_stmt = NULL;
6490 : :
6491 : : /* Expand implicit goto and convert goto_locus. */
6492 : 29001946 : FOR_EACH_EDGE (e, ei, bb->succs)
6493 : : {
6494 : 17042681 : if (e->goto_locus != UNKNOWN_LOCATION || !nondebug_stmt_seen)
6495 : 11717532 : set_curr_insn_location (e->goto_locus);
6496 : 17042681 : if ((e->flags & EDGE_FALLTHRU) && e->dest != bb->next_bb)
6497 : : {
6498 : 1624874 : emit_jump (label_rtx_for_bb (e->dest));
6499 : 1624874 : e->flags &= ~EDGE_FALLTHRU;
6500 : : }
6501 : : }
6502 : :
6503 : : /* Expanded RTL can create a jump in the last instruction of block.
6504 : : This later might be assumed to be a jump to successor and break edge insertion.
6505 : : We need to insert dummy move to prevent this. PR41440. */
6506 : 11959265 : if (single_succ_p (bb)
6507 : 5458782 : && (single_succ_edge (bb)->flags & EDGE_FALLTHRU)
6508 : 3106719 : && (last = get_last_insn ())
6509 : 14898359 : && (JUMP_P (last)
6510 : 3106671 : || (DEBUG_INSN_P (last)
6511 : 383944 : && JUMP_P (prev_nondebug_insn (last)))))
6512 : : {
6513 : 53 : rtx dummy = gen_reg_rtx (SImode);
6514 : 53 : emit_insn_after_noloc (gen_move_insn (dummy, dummy), last, NULL);
6515 : : }
6516 : :
6517 : : /* A __builtin_unreachable () will insert a barrier that should end
6518 : : the basic block. In gimple, any code after it will have already
6519 : : deleted, even without optimization. If we emit additional code
6520 : : here, as we would to adjust the stack after a call, it should be
6521 : : eventually deleted, but it confuses internal checkers (PR118006)
6522 : : and optimizers before it does, because we don't expect to find
6523 : : barriers inside basic blocks. */
6524 : 11959265 : if (!BARRIER_P (get_last_insn ()))
6525 : 8708058 : do_pending_stack_adjust ();
6526 : : else
6527 : 3251207 : discard_pending_stack_adjust ();
6528 : :
6529 : : /* Find the block tail. The last insn in the block is the insn
6530 : : before a barrier and/or table jump insn. */
6531 : 11959265 : last = get_last_insn ();
6532 : 11959265 : if (BARRIER_P (last))
6533 : 3251207 : last = PREV_INSN (last);
6534 : 11959265 : if (JUMP_TABLE_DATA_P (last))
6535 : 9843 : last = PREV_INSN (PREV_INSN (last));
6536 : 11959265 : if (BARRIER_P (last))
6537 : 8874 : last = PREV_INSN (last);
6538 : 11959265 : head_end_for_bb[bb->index].second = last;
6539 : :
6540 : 23918530 : update_bb_for_insn_chain (head_end_for_bb[bb->index].first,
6541 : 11959265 : head_end_for_bb[bb->index].second, bb);
6542 : :
6543 : 11959265 : return bb;
6544 : : }
6545 : :
6546 : :
6547 : : /* Create a basic block for initialization code. */
6548 : :
6549 : : static basic_block
6550 : 1450629 : construct_init_block (void)
6551 : : {
6552 : 1450629 : basic_block init_block;
6553 : 1450629 : edge e = NULL;
6554 : 1450629 : int flags;
6555 : :
6556 : : /* Multiple entry points not supported yet. */
6557 : 1450629 : gcc_assert (EDGE_COUNT (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs) == 1);
6558 : 1450629 : init_rtl_bb_info (ENTRY_BLOCK_PTR_FOR_FN (cfun));
6559 : 1450629 : init_rtl_bb_info (EXIT_BLOCK_PTR_FOR_FN (cfun));
6560 : 1450629 : ENTRY_BLOCK_PTR_FOR_FN (cfun)->flags |= BB_RTL;
6561 : 1450629 : EXIT_BLOCK_PTR_FOR_FN (cfun)->flags |= BB_RTL;
6562 : :
6563 : 1450629 : e = EDGE_SUCC (ENTRY_BLOCK_PTR_FOR_FN (cfun), 0);
6564 : :
6565 : : /* When entry edge points to first basic block, we don't need jump,
6566 : : otherwise we have to jump into proper target. */
6567 : 1450629 : if (e && e->dest != ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb)
6568 : : {
6569 : 0 : tree label = gimple_block_label (e->dest);
6570 : :
6571 : 0 : emit_jump (jump_target_rtx (label));
6572 : 0 : flags = 0;
6573 : 0 : }
6574 : : else
6575 : : flags = EDGE_FALLTHRU;
6576 : :
6577 : 1450629 : init_block = create_basic_block (NEXT_INSN (get_insns ()),
6578 : : get_last_insn (),
6579 : 1450629 : ENTRY_BLOCK_PTR_FOR_FN (cfun));
6580 : 1450629 : init_block->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
6581 : 1450629 : add_bb_to_loop (init_block, ENTRY_BLOCK_PTR_FOR_FN (cfun)->loop_father);
6582 : 1450629 : if (e)
6583 : 1450629 : expand_split_edge (e, init_block, flags);
6584 : : else
6585 : 0 : make_single_succ_edge (init_block, EXIT_BLOCK_PTR_FOR_FN (cfun),
6586 : : EDGE_FALLTHRU);
6587 : :
6588 : 1450629 : update_bb_for_insn (init_block);
6589 : 1450629 : return init_block;
6590 : : }
6591 : :
6592 : : /* For each lexical block, set BLOCK_NUMBER to the depth at which it is
6593 : : found in the block tree. */
6594 : :
6595 : : static void
6596 : 18538612 : set_block_levels (tree block, int level)
6597 : : {
6598 : 35626595 : while (block)
6599 : : {
6600 : 17087983 : BLOCK_NUMBER (block) = level;
6601 : 17087983 : set_block_levels (BLOCK_SUBBLOCKS (block), level + 1);
6602 : 17087983 : block = BLOCK_CHAIN (block);
6603 : : }
6604 : 18538612 : }
6605 : :
6606 : : /* Create a block containing landing pads and similar stuff. */
6607 : :
6608 : : static void
6609 : 1450629 : construct_exit_block (void)
6610 : : {
6611 : 1450629 : rtx_insn *head = get_last_insn ();
6612 : 1450629 : rtx_insn *end;
6613 : 1450629 : basic_block exit_block;
6614 : 1450629 : edge e, e2;
6615 : 1450629 : unsigned ix;
6616 : 1450629 : edge_iterator ei;
6617 : 1450629 : basic_block prev_bb = EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb;
6618 : 1450629 : rtx_insn *orig_end = BB_END (prev_bb);
6619 : :
6620 : 1450629 : rtl_profile_for_bb (EXIT_BLOCK_PTR_FOR_FN (cfun));
6621 : :
6622 : : /* Make sure the locus is set to the end of the function, so that
6623 : : epilogue line numbers and warnings are set properly. */
6624 : 1450629 : if (LOCATION_LOCUS (cfun->function_end_locus) != UNKNOWN_LOCATION)
6625 : 1134107 : input_location = cfun->function_end_locus;
6626 : :
6627 : : /* Generate rtl for function exit. */
6628 : 1450629 : expand_function_end ();
6629 : :
6630 : 1450629 : end = get_last_insn ();
6631 : 1450629 : if (head == end)
6632 : 0 : return;
6633 : : /* While emitting the function end we could move end of the last basic
6634 : : block. */
6635 : 1450629 : BB_END (prev_bb) = orig_end;
6636 : 1450629 : while (NEXT_INSN (head) && NOTE_P (NEXT_INSN (head)))
6637 : : head = NEXT_INSN (head);
6638 : : /* But make sure exit_block starts with RETURN_LABEL, otherwise the
6639 : : bb count counting will be confused. Any instructions before that
6640 : : label are emitted for the case where PREV_BB falls through into the
6641 : : exit block, so append those instructions to prev_bb in that case. */
6642 : 1450629 : if (NEXT_INSN (head) != return_label)
6643 : : {
6644 : 14792 : while (NEXT_INSN (head) != return_label)
6645 : : {
6646 : 9807 : if (!NOTE_P (NEXT_INSN (head)))
6647 : 9807 : BB_END (prev_bb) = NEXT_INSN (head);
6648 : 9807 : head = NEXT_INSN (head);
6649 : : }
6650 : : }
6651 : 1450629 : exit_block = create_basic_block (NEXT_INSN (head), end, prev_bb);
6652 : 1450629 : exit_block->count = EXIT_BLOCK_PTR_FOR_FN (cfun)->count;
6653 : 1450629 : add_bb_to_loop (exit_block, EXIT_BLOCK_PTR_FOR_FN (cfun)->loop_father);
6654 : :
6655 : 1450629 : ix = 0;
6656 : 4381610 : while (ix < EDGE_COUNT (EXIT_BLOCK_PTR_FOR_FN (cfun)->preds))
6657 : : {
6658 : 1480352 : e = EDGE_PRED (EXIT_BLOCK_PTR_FOR_FN (cfun), ix);
6659 : 1480352 : if (!(e->flags & EDGE_ABNORMAL))
6660 : 1355697 : redirect_edge_succ (e, exit_block);
6661 : : else
6662 : 124655 : ix++;
6663 : : }
6664 : :
6665 : 1450629 : e = make_single_succ_edge (exit_block, EXIT_BLOCK_PTR_FOR_FN (cfun),
6666 : : EDGE_FALLTHRU);
6667 : 3025913 : FOR_EACH_EDGE (e2, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
6668 : 1575284 : if (e2 != e)
6669 : : {
6670 : 124655 : exit_block->count -= e2->count ();
6671 : : }
6672 : 1450629 : update_bb_for_insn (exit_block);
6673 : : }
6674 : :
6675 : : /* Helper function for discover_nonconstant_array_refs.
6676 : : Look for ARRAY_REF nodes with non-constant indexes and mark them
6677 : : addressable. */
6678 : :
6679 : : static tree
6680 : 163593266 : discover_nonconstant_array_refs_r (tree * tp, int *walk_subtrees,
6681 : : void *data)
6682 : : {
6683 : 163593266 : tree t = *tp;
6684 : 163593266 : bitmap forced_stack_vars = (bitmap)((walk_stmt_info *)data)->info;
6685 : :
6686 : 163593266 : if (IS_TYPE_OR_DECL_P (t))
6687 : 33993034 : *walk_subtrees = 0;
6688 : 129600232 : else if (REFERENCE_CLASS_P (t) && TREE_THIS_VOLATILE (t))
6689 : : {
6690 : 69896 : t = get_base_address (t);
6691 : 69896 : if (t && DECL_P (t)
6692 : 57775 : && DECL_MODE (t) != BLKmode
6693 : 106352 : && !TREE_ADDRESSABLE (t))
6694 : 32641 : bitmap_set_bit (forced_stack_vars, DECL_UID (t));
6695 : 69896 : *walk_subtrees = 0;
6696 : : }
6697 : 129530336 : else if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
6698 : : {
6699 : 5990735 : while (((TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
6700 : 2868011 : && is_gimple_min_invariant (TREE_OPERAND (t, 1))
6701 : 2405249 : && (!TREE_OPERAND (t, 2)
6702 : 29066 : || is_gimple_min_invariant (TREE_OPERAND (t, 2))))
6703 : 3613425 : || (TREE_CODE (t) == COMPONENT_REF
6704 : 902430 : && (!TREE_OPERAND (t,2)
6705 : 0 : || is_gimple_min_invariant (TREE_OPERAND (t, 2))))
6706 : 2710995 : || TREE_CODE (t) == BIT_FIELD_REF
6707 : : || TREE_CODE (t) == REALPART_EXPR
6708 : : || TREE_CODE (t) == IMAGPART_EXPR
6709 : : || TREE_CODE (t) == VIEW_CONVERT_EXPR
6710 : 5990735 : || CONVERT_EXPR_P (t))
6711 : 3289607 : t = TREE_OPERAND (t, 0);
6712 : :
6713 : 2701128 : if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
6714 : : {
6715 : 490701 : t = get_base_address (t);
6716 : 490701 : if (t && DECL_P (t)
6717 : 404708 : && DECL_MODE (t) != BLKmode
6718 : 515597 : && !TREE_ADDRESSABLE (t))
6719 : 16608 : bitmap_set_bit (forced_stack_vars, DECL_UID (t));
6720 : : }
6721 : :
6722 : 2701128 : *walk_subtrees = 0;
6723 : : }
6724 : : /* References of size POLY_INT_CST to a fixed-size object must go
6725 : : through memory. It's more efficient to force that here than
6726 : : to create temporary slots on the fly.
6727 : : RTL expansion expectes TARGET_MEM_REF to always address actual memory.
6728 : : Also, force to stack non-BLKmode vars accessed through VIEW_CONVERT_EXPR
6729 : : to BLKmode type. */
6730 : 126829208 : else if (TREE_CODE (t) == TARGET_MEM_REF
6731 : : || (TREE_CODE (t) == MEM_REF
6732 : 125985431 : && TYPE_SIZE (TREE_TYPE (t))
6733 : : && POLY_INT_CST_P (TYPE_SIZE (TREE_TYPE (t))))
6734 : 252814639 : || (TREE_CODE (t) == VIEW_CONVERT_EXPR
6735 : 313386 : && TYPE_MODE (TREE_TYPE (t)) == BLKmode))
6736 : : {
6737 : 921786 : tree base = get_base_address (t);
6738 : 921786 : if (base
6739 : 921786 : && DECL_P (base)
6740 : 269561 : && !TREE_ADDRESSABLE (base)
6741 : 126302 : && DECL_MODE (base) != BLKmode
6742 : 927707 : && GET_MODE_SIZE (DECL_MODE (base)).is_constant ())
6743 : 5921 : bitmap_set_bit (forced_stack_vars, DECL_UID (base));
6744 : 921786 : *walk_subtrees = 0;
6745 : : }
6746 : :
6747 : 163593266 : return NULL_TREE;
6748 : : }
6749 : :
6750 : : /* If there's a chance to get a pseudo for t then if it would be of float mode
6751 : : and the actual access is via an integer mode (lowered memcpy or similar
6752 : : access) then avoid the register expansion if the mode likely is not storage
6753 : : suitable for raw bits processing (like XFmode on i?86). */
6754 : :
6755 : : static void
6756 : 6741239 : avoid_type_punning_on_regs (tree t, bitmap forced_stack_vars)
6757 : : {
6758 : 6741239 : machine_mode access_mode = TYPE_MODE (TREE_TYPE (t));
6759 : 6741239 : if (access_mode != BLKmode
6760 : 6373811 : && !SCALAR_INT_MODE_P (access_mode))
6761 : : return;
6762 : 5776707 : tree base = get_base_address (t);
6763 : 5776707 : if (DECL_P (base)
6764 : 4366900 : && !TREE_ADDRESSABLE (base)
6765 : 1246227 : && FLOAT_MODE_P (DECL_MODE (base))
6766 : 62 : && maybe_lt (GET_MODE_PRECISION (DECL_MODE (base)),
6767 : 186 : GET_MODE_BITSIZE (GET_MODE_INNER (DECL_MODE (base))))
6768 : : /* Double check in the expensive way we really would get a pseudo. */
6769 : 5776712 : && use_register_for_decl (base))
6770 : 5 : bitmap_set_bit (forced_stack_vars, DECL_UID (base));
6771 : : }
6772 : :
6773 : : /* RTL expansion is not able to compile array references with variable
6774 : : offsets for arrays stored in single register. Discover such
6775 : : expressions and mark variables as addressable to avoid this
6776 : : scenario. */
6777 : :
6778 : : static void
6779 : 1450629 : discover_nonconstant_array_refs (bitmap forced_stack_vars)
6780 : : {
6781 : 1450629 : basic_block bb;
6782 : 1450629 : gimple_stmt_iterator gsi;
6783 : :
6784 : 1450629 : walk_stmt_info wi = {};
6785 : 1450629 : wi.info = forced_stack_vars;
6786 : 14013431 : FOR_EACH_BB_FN (bb, cfun)
6787 : 119952036 : for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
6788 : : {
6789 : 94826432 : gimple *stmt = gsi_stmt (gsi);
6790 : 94826432 : if (!is_gimple_debug (stmt))
6791 : : {
6792 : 46457898 : walk_gimple_op (stmt, discover_nonconstant_array_refs_r, &wi);
6793 : 46457898 : gcall *call = dyn_cast <gcall *> (stmt);
6794 : 6805944 : if (call && gimple_call_internal_p (call))
6795 : : {
6796 : 187081 : tree cand = NULL_TREE;
6797 : 187081 : switch (gimple_call_internal_fn (call))
6798 : : {
6799 : 0 : case IFN_LOAD_LANES:
6800 : : /* The source must be a MEM. */
6801 : 0 : cand = gimple_call_arg (call, 0);
6802 : 0 : break;
6803 : 0 : case IFN_STORE_LANES:
6804 : : /* The destination must be a MEM. */
6805 : 0 : cand = gimple_call_lhs (call);
6806 : 0 : break;
6807 : : default:
6808 : : break;
6809 : : }
6810 : 0 : if (cand)
6811 : 0 : cand = get_base_address (cand);
6812 : 0 : if (cand
6813 : 0 : && DECL_P (cand)
6814 : 0 : && use_register_for_decl (cand))
6815 : 0 : bitmap_set_bit (forced_stack_vars, DECL_UID (cand));
6816 : : }
6817 : 150585116 : if (gimple_vdef (stmt))
6818 : : {
6819 : 15540707 : tree t = gimple_get_lhs (stmt);
6820 : 15540707 : if (t && REFERENCE_CLASS_P (t))
6821 : 6741239 : avoid_type_punning_on_regs (t, forced_stack_vars);
6822 : : }
6823 : : }
6824 : : }
6825 : 1450629 : }
6826 : :
6827 : : /* This function sets crtl->args.internal_arg_pointer to a virtual
6828 : : register if DRAP is needed. Local register allocator will replace
6829 : : virtual_incoming_args_rtx with the virtual register. */
6830 : :
6831 : : static void
6832 : 1450629 : expand_stack_alignment (void)
6833 : : {
6834 : 1450629 : rtx drap_rtx;
6835 : 1450629 : unsigned int preferred_stack_boundary;
6836 : :
6837 : 1450629 : if (! SUPPORTS_STACK_ALIGNMENT)
6838 : : return;
6839 : :
6840 : 1450629 : if (cfun->calls_alloca
6841 : 1435778 : || cfun->has_nonlocal_label
6842 : 1434976 : || crtl->has_nonlocal_goto)
6843 : 16054 : crtl->need_drap = true;
6844 : :
6845 : : /* Call update_stack_boundary here again to update incoming stack
6846 : : boundary. It may set incoming stack alignment to a different
6847 : : value after RTL expansion. TARGET_FUNCTION_OK_FOR_SIBCALL may
6848 : : use the minimum incoming stack alignment to check if it is OK
6849 : : to perform sibcall optimization since sibcall optimization will
6850 : : only align the outgoing stack to incoming stack boundary. */
6851 : 1450629 : if (targetm.calls.update_stack_boundary)
6852 : 1450629 : targetm.calls.update_stack_boundary ();
6853 : :
6854 : : /* The incoming stack frame has to be aligned at least at
6855 : : parm_stack_boundary. */
6856 : 1450629 : gcc_assert (crtl->parm_stack_boundary <= INCOMING_STACK_BOUNDARY);
6857 : :
6858 : : /* Update crtl->stack_alignment_estimated and use it later to align
6859 : : stack. We check PREFERRED_STACK_BOUNDARY if there may be non-call
6860 : : exceptions since callgraph doesn't collect incoming stack alignment
6861 : : in this case. */
6862 : 1450629 : if (cfun->can_throw_non_call_exceptions
6863 : 262759 : && PREFERRED_STACK_BOUNDARY > crtl->preferred_stack_boundary)
6864 : : preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
6865 : : else
6866 : 1422675 : preferred_stack_boundary = crtl->preferred_stack_boundary;
6867 : 1450629 : if (preferred_stack_boundary > crtl->stack_alignment_estimated)
6868 : 697907 : crtl->stack_alignment_estimated = preferred_stack_boundary;
6869 : 1450629 : if (preferred_stack_boundary > crtl->stack_alignment_needed)
6870 : 649956 : crtl->stack_alignment_needed = preferred_stack_boundary;
6871 : :
6872 : 1450629 : gcc_assert (crtl->stack_alignment_needed
6873 : : <= crtl->stack_alignment_estimated);
6874 : :
6875 : 1450629 : crtl->stack_realign_needed
6876 : 1450629 : = INCOMING_STACK_BOUNDARY < crtl->stack_alignment_estimated;
6877 : 1450629 : crtl->stack_realign_tried = crtl->stack_realign_needed;
6878 : :
6879 : 1450629 : crtl->stack_realign_processed = true;
6880 : :
6881 : : /* Target has to redefine TARGET_GET_DRAP_RTX to support stack
6882 : : alignment. */
6883 : 1450629 : gcc_assert (targetm.calls.get_drap_rtx != NULL);
6884 : 1450629 : drap_rtx = targetm.calls.get_drap_rtx ();
6885 : :
6886 : : /* stack_realign_drap and drap_rtx must match. */
6887 : 1450629 : gcc_assert ((stack_realign_drap != 0) == (drap_rtx != NULL));
6888 : :
6889 : : /* Do nothing if NULL is returned, which means DRAP is not needed. */
6890 : 1450629 : if (drap_rtx != NULL)
6891 : : {
6892 : 7129 : crtl->args.internal_arg_pointer = drap_rtx;
6893 : :
6894 : : /* Call fixup_tail_calls to clean up REG_EQUIV note if DRAP is
6895 : : needed. */
6896 : 7129 : fixup_tail_calls ();
6897 : : }
6898 : : }
6899 : :
6900 : :
6901 : : static void
6902 : 0 : expand_main_function (void)
6903 : : {
6904 : : #if (defined(INVOKE__main) \
6905 : : || (!defined(HAS_INIT_SECTION) \
6906 : : && !defined(INIT_SECTION_ASM_OP) \
6907 : : && !defined(INIT_ARRAY_SECTION_ASM_OP)))
6908 : : emit_library_call (init_one_libfunc (NAME__MAIN), LCT_NORMAL, VOIDmode);
6909 : : #endif
6910 : 0 : }
6911 : :
6912 : :
6913 : : /* Expand code to initialize the stack_protect_guard. This is invoked at
6914 : : the beginning of a function to be protected. */
6915 : :
6916 : : static void
6917 : 237 : stack_protect_prologue (void)
6918 : : {
6919 : 237 : tree guard_decl = targetm.stack_protect_guard ();
6920 : 237 : rtx x, y;
6921 : :
6922 : 237 : crtl->stack_protect_guard_decl = guard_decl;
6923 : 237 : x = expand_normal (crtl->stack_protect_guard);
6924 : :
6925 : 237 : if (targetm.have_stack_protect_combined_set () && guard_decl)
6926 : : {
6927 : 0 : gcc_assert (DECL_P (guard_decl));
6928 : 0 : y = DECL_RTL (guard_decl);
6929 : :
6930 : : /* Allow the target to compute address of Y and copy it to X without
6931 : : leaking Y into a register. This combined address + copy pattern
6932 : : allows the target to prevent spilling of any intermediate results by
6933 : : splitting it after register allocator. */
6934 : 0 : if (rtx_insn *insn = targetm.gen_stack_protect_combined_set (x, y))
6935 : : {
6936 : 0 : emit_insn (insn);
6937 : 0 : return;
6938 : : }
6939 : : }
6940 : :
6941 : 237 : if (guard_decl)
6942 : 237 : y = expand_normal (guard_decl);
6943 : : else
6944 : 0 : y = const0_rtx;
6945 : :
6946 : : /* Allow the target to copy from Y to X without leaking Y into a
6947 : : register. */
6948 : 237 : if (targetm.have_stack_protect_set ())
6949 : 237 : if (rtx_insn *insn = targetm.gen_stack_protect_set (x, y))
6950 : : {
6951 : 237 : emit_insn (insn);
6952 : 237 : return;
6953 : : }
6954 : :
6955 : : /* Otherwise do a straight move. */
6956 : 0 : emit_move_insn (x, y);
6957 : : }
6958 : :
6959 : : /* Translate the intermediate representation contained in the CFG
6960 : : from GIMPLE trees to RTL.
6961 : :
6962 : : We do conversion per basic block and preserve/update the tree CFG.
6963 : : This implies we have to do some magic as the CFG can simultaneously
6964 : : consist of basic blocks containing RTL and GIMPLE trees. This can
6965 : : confuse the CFG hooks, so be careful to not manipulate CFG during
6966 : : the expansion. */
6967 : :
6968 : : namespace {
6969 : :
6970 : : const pass_data pass_data_expand =
6971 : : {
6972 : : RTL_PASS, /* type */
6973 : : "expand", /* name */
6974 : : OPTGROUP_NONE, /* optinfo_flags */
6975 : : TV_EXPAND, /* tv_id */
6976 : : ( PROP_ssa | PROP_gimple_leh | PROP_cfg
6977 : : | PROP_gimple_lcx
6978 : : | PROP_gimple_lvec
6979 : : | PROP_gimple_lva), /* properties_required */
6980 : : PROP_rtl, /* properties_provided */
6981 : : ( PROP_ssa | PROP_gimple ), /* properties_destroyed */
6982 : : 0, /* todo_flags_start */
6983 : : 0, /* todo_flags_finish */
6984 : : };
6985 : :
6986 : : class pass_expand : public rtl_opt_pass
6987 : : {
6988 : : public:
6989 : 285085 : pass_expand (gcc::context *ctxt)
6990 : 570170 : : rtl_opt_pass (pass_data_expand, ctxt)
6991 : : {}
6992 : :
6993 : : /* opt_pass methods: */
6994 : : unsigned int execute (function *) final override;
6995 : :
6996 : : }; // class pass_expand
6997 : :
6998 : : unsigned int
6999 : 1450629 : pass_expand::execute (function *fun)
7000 : : {
7001 : 1450629 : basic_block bb, init_block;
7002 : 1450629 : edge_iterator ei;
7003 : 1450629 : edge e;
7004 : 1450629 : rtx_insn *var_seq, *var_ret_seq;
7005 : 1450629 : unsigned i;
7006 : :
7007 : 1450629 : timevar_push (TV_OUT_OF_SSA);
7008 : 1450629 : rewrite_out_of_ssa (&SA);
7009 : 1450629 : timevar_pop (TV_OUT_OF_SSA);
7010 : 1450629 : SA.partition_to_pseudo = XCNEWVEC (rtx, SA.map->num_partitions);
7011 : :
7012 : 1450629 : if (MAY_HAVE_DEBUG_BIND_STMTS && flag_tree_ter)
7013 : : {
7014 : 496651 : gimple_stmt_iterator gsi;
7015 : 6842342 : FOR_EACH_BB_FN (bb, cfun)
7016 : 82857078 : for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
7017 : 106787445 : if (gimple_debug_bind_p (gsi_stmt (gsi)))
7018 : 36621749 : avoid_deep_ter_for_debug (gsi_stmt (gsi), 0);
7019 : : }
7020 : :
7021 : : /* Mark arrays indexed with non-constant indices with TREE_ADDRESSABLE. */
7022 : 1450629 : auto_bitmap forced_stack_vars;
7023 : 1450629 : discover_nonconstant_array_refs (forced_stack_vars);
7024 : :
7025 : : /* Make sure all values used by the optimization passes have sane
7026 : : defaults. */
7027 : 1450629 : reg_renumber = 0;
7028 : :
7029 : : /* Some backends want to know that we are expanding to RTL. */
7030 : 1450629 : currently_expanding_to_rtl = 1;
7031 : : /* Dominators are not kept up-to-date as we may create new basic-blocks. */
7032 : 1450629 : free_dominance_info (CDI_DOMINATORS);
7033 : :
7034 : 1450629 : rtl_profile_for_bb (ENTRY_BLOCK_PTR_FOR_FN (fun));
7035 : :
7036 : 1450629 : insn_locations_init ();
7037 : 1450629 : if (!DECL_IS_UNDECLARED_BUILTIN (current_function_decl))
7038 : : {
7039 : : /* Eventually, all FEs should explicitly set function_start_locus. */
7040 : 1331430 : if (LOCATION_LOCUS (fun->function_start_locus) == UNKNOWN_LOCATION)
7041 : 619898 : set_curr_insn_location
7042 : 619898 : (DECL_SOURCE_LOCATION (current_function_decl));
7043 : : else
7044 : 711532 : set_curr_insn_location (fun->function_start_locus);
7045 : : }
7046 : : else
7047 : 119199 : set_curr_insn_location (UNKNOWN_LOCATION);
7048 : 1450629 : prologue_location = curr_insn_location ();
7049 : :
7050 : : #ifdef INSN_SCHEDULING
7051 : 1450629 : init_sched_attrs ();
7052 : : #endif
7053 : :
7054 : : /* Make sure first insn is a note even if we don't want linenums.
7055 : : This makes sure the first insn will never be deleted.
7056 : : Also, final expects a note to appear there. */
7057 : 1450629 : emit_note (NOTE_INSN_DELETED);
7058 : :
7059 : 1450629 : targetm.expand_to_rtl_hook ();
7060 : 1450629 : crtl->init_stack_alignment ();
7061 : 1450629 : fun->cfg->max_jumptable_ents = 0;
7062 : :
7063 : : /* Resovle the function section. Some targets, like ARM EABI rely on knowledge
7064 : : of the function section at exapnsion time to predict distance of calls. */
7065 : 1450629 : resolve_unique_section (current_function_decl, 0, flag_function_sections);
7066 : :
7067 : : /* Expand the variables recorded during gimple lowering. */
7068 : 1450629 : timevar_push (TV_VAR_EXPAND);
7069 : 1450629 : start_sequence ();
7070 : :
7071 : 1450629 : var_ret_seq = expand_used_vars (forced_stack_vars);
7072 : :
7073 : 1450629 : var_seq = end_sequence ();
7074 : 1450629 : timevar_pop (TV_VAR_EXPAND);
7075 : :
7076 : : /* Honor stack protection warnings. */
7077 : 1450629 : if (warn_stack_protect)
7078 : : {
7079 : 0 : if (fun->calls_alloca)
7080 : 0 : warning (OPT_Wstack_protector,
7081 : : "stack protector not protecting local variables: "
7082 : : "variable length buffer");
7083 : 0 : if (has_short_buffer && !crtl->stack_protect_guard)
7084 : 0 : warning (OPT_Wstack_protector,
7085 : : "stack protector not protecting function: "
7086 : : "all local arrays are less than %d bytes long",
7087 : 0 : (int) param_ssp_buffer_size);
7088 : : }
7089 : :
7090 : : /* Temporarily mark PARM_DECLs and RESULT_DECLs we need to expand to
7091 : : memory addressable so expand_function_start can emit the required
7092 : : copies. */
7093 : 1450629 : auto_vec<tree, 16> marked_parms;
7094 : 4530639 : for (tree parm = DECL_ARGUMENTS (current_function_decl); parm;
7095 : 3080010 : parm = DECL_CHAIN (parm))
7096 : 3080010 : if (!TREE_ADDRESSABLE (parm)
7097 : 3080010 : && bitmap_bit_p (forced_stack_vars, DECL_UID (parm)))
7098 : : {
7099 : 135 : TREE_ADDRESSABLE (parm) = 1;
7100 : 135 : marked_parms.safe_push (parm);
7101 : : }
7102 : 1450629 : if (DECL_RESULT (current_function_decl)
7103 : 1450629 : && !TREE_ADDRESSABLE (DECL_RESULT (current_function_decl))
7104 : 2894628 : && bitmap_bit_p (forced_stack_vars,
7105 : 1443999 : DECL_UID (DECL_RESULT (current_function_decl))))
7106 : : {
7107 : 0 : TREE_ADDRESSABLE (DECL_RESULT (current_function_decl)) = 1;
7108 : 0 : marked_parms.safe_push (DECL_RESULT (current_function_decl));
7109 : : }
7110 : :
7111 : : /* Set up parameters and prepare for return, for the function. */
7112 : 1450629 : expand_function_start (current_function_decl);
7113 : :
7114 : : /* Clear TREE_ADDRESSABLE again. */
7115 : 2901393 : while (!marked_parms.is_empty ())
7116 : 135 : TREE_ADDRESSABLE (marked_parms.pop ()) = 0;
7117 : :
7118 : : /* If we emitted any instructions for setting up the variables,
7119 : : emit them before the FUNCTION_START note. */
7120 : 1450629 : if (var_seq)
7121 : : {
7122 : 1494 : emit_insn_before (var_seq, parm_birth_insn);
7123 : :
7124 : : /* In expand_function_end we'll insert the alloca save/restore
7125 : : before parm_birth_insn. We've just insertted an alloca call.
7126 : : Adjust the pointer to match. */
7127 : 1494 : parm_birth_insn = var_seq;
7128 : : }
7129 : :
7130 : : /* Now propagate the RTL assignment of each partition to the
7131 : : underlying var of each SSA_NAME. */
7132 : : tree name;
7133 : :
7134 : 72013728 : FOR_EACH_SSA_NAME (i, name, cfun)
7135 : : {
7136 : : /* We might have generated new SSA names in
7137 : : update_alias_info_with_stack_vars. They will have a NULL
7138 : : defining statements, and won't be part of the partitioning,
7139 : : so ignore those. */
7140 : 48592883 : if (!SSA_NAME_DEF_STMT (name))
7141 : 73064 : continue;
7142 : :
7143 : 48519819 : adjust_one_expanded_partition_var (name);
7144 : : }
7145 : :
7146 : : /* Clean up RTL of variables that straddle across multiple
7147 : : partitions, and check that the rtl of any PARM_DECLs that are not
7148 : : cleaned up is that of their default defs. */
7149 : 72013728 : FOR_EACH_SSA_NAME (i, name, cfun)
7150 : : {
7151 : 48592883 : int part;
7152 : :
7153 : : /* We might have generated new SSA names in
7154 : : update_alias_info_with_stack_vars. They will have a NULL
7155 : : defining statements, and won't be part of the partitioning,
7156 : : so ignore those. */
7157 : 48592883 : if (!SSA_NAME_DEF_STMT (name))
7158 : 73064 : continue;
7159 : 48519819 : part = var_to_partition (SA.map, name);
7160 : 48519819 : if (part == NO_PARTITION)
7161 : 17406677 : continue;
7162 : :
7163 : : /* If this decl was marked as living in multiple places, reset
7164 : : this now to NULL. */
7165 : 31113142 : tree var = SSA_NAME_VAR (name);
7166 : 10378698 : if (var && DECL_RTL_IF_SET (var) == pc_rtx)
7167 : 224747 : SET_DECL_RTL (var, NULL);
7168 : : /* Check that the pseudos chosen by assign_parms are those of
7169 : : the corresponding default defs. */
7170 : 30888395 : else if (SSA_NAME_IS_DEFAULT_DEF (name)
7171 : 30888395 : && (TREE_CODE (var) == PARM_DECL
7172 : 3624958 : || TREE_CODE (var) == RESULT_DECL))
7173 : : {
7174 : 3567634 : rtx in = DECL_RTL_IF_SET (var);
7175 : 3567634 : gcc_assert (in);
7176 : 3567634 : rtx out = SA.partition_to_pseudo[part];
7177 : 3567634 : gcc_assert (in == out);
7178 : :
7179 : : /* Now reset VAR's RTL to IN, so that the _EXPR attrs match
7180 : : those expected by debug backends for each parm and for
7181 : : the result. This is particularly important for stabs,
7182 : : whose register elimination from parm's DECL_RTL may cause
7183 : : -fcompare-debug differences as SET_DECL_RTL changes reg's
7184 : : attrs. So, make sure the RTL already has the parm as the
7185 : : EXPR, so that it won't change. */
7186 : 3567634 : SET_DECL_RTL (var, NULL_RTX);
7187 : 3567634 : if (MEM_P (in))
7188 : 753793 : set_mem_attributes (in, var, true);
7189 : 3567634 : SET_DECL_RTL (var, in);
7190 : : }
7191 : : }
7192 : :
7193 : : /* If this function is `main', emit a call to `__main'
7194 : : to run global initializers, etc. */
7195 : 1450629 : if (DECL_NAME (current_function_decl)
7196 : 1450629 : && MAIN_NAME_P (DECL_NAME (current_function_decl))
7197 : 1561004 : && DECL_FILE_SCOPE_P (current_function_decl))
7198 : 1450629 : expand_main_function ();
7199 : :
7200 : : /* Initialize the stack_protect_guard field. This must happen after the
7201 : : call to __main (if any) so that the external decl is initialized. */
7202 : 1450629 : if (crtl->stack_protect_guard && targetm.stack_protect_runtime_enabled_p ())
7203 : 237 : stack_protect_prologue ();
7204 : :
7205 : 1450629 : expand_phi_nodes (&SA);
7206 : :
7207 : : /* Release any stale SSA redirection data. */
7208 : 1450629 : redirect_edge_var_map_empty ();
7209 : :
7210 : : /* Register rtl specific functions for cfg. */
7211 : 1450629 : rtl_register_cfg_hooks ();
7212 : :
7213 : 1450629 : init_block = construct_init_block ();
7214 : :
7215 : : /* Clear EDGE_EXECUTABLE on the entry edge(s). It is cleaned from the
7216 : : remaining edges later. */
7217 : 2901258 : FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR_FOR_FN (fun)->succs)
7218 : 1450629 : e->flags &= ~EDGE_EXECUTABLE;
7219 : :
7220 : : /* If the function has too many markers, drop them while expanding. */
7221 : 1450629 : if (cfun->debug_marker_count
7222 : 1450629 : >= param_max_debug_marker_count)
7223 : 1 : cfun->debug_nonbind_markers = false;
7224 : :
7225 : 1450629 : enable_ranger (fun);
7226 : 1450629 : lab_rtx_for_bb = new hash_map<basic_block, rtx_code_label *>;
7227 : 1450629 : head_end_for_bb.create (last_basic_block_for_fn (fun));
7228 : 14027625 : FOR_BB_BETWEEN (bb, init_block->next_bb, EXIT_BLOCK_PTR_FOR_FN (fun),
7229 : : next_bb)
7230 : 12576996 : bb = expand_gimple_basic_block (bb, var_ret_seq != NULL_RTX);
7231 : 1450629 : disable_ranger (fun);
7232 : 14520701 : FOR_BB_BETWEEN (bb, init_block->next_bb, EXIT_BLOCK_PTR_FOR_FN (fun),
7233 : : next_bb)
7234 : : {
7235 : 13070072 : if ((bb->flags & BB_RTL) == 0)
7236 : : {
7237 : 12576996 : bb->il.gimple.seq = NULL;
7238 : 12576996 : bb->il.gimple.phi_nodes = NULL;
7239 : 12576996 : init_rtl_bb_info (bb);
7240 : 12576996 : bb->flags |= BB_RTL;
7241 : 12576996 : BB_HEAD (bb) = head_end_for_bb[bb->index].first;
7242 : 12576996 : BB_END (bb) = head_end_for_bb[bb->index].second;
7243 : : }
7244 : : /* These flags have no purpose in RTL land. */
7245 : 13070072 : if (EDGE_COUNT (bb->succs) == 2)
7246 : : {
7247 : 6237671 : EDGE_SUCC (bb, 0)->flags &= ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE);
7248 : 6237671 : EDGE_SUCC (bb, 1)->flags &= ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE);
7249 : : }
7250 : 19146579 : else if (single_succ_p (bb))
7251 : 6076507 : single_succ_edge (bb)->flags &= ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE);
7252 : : }
7253 : 1450629 : head_end_for_bb.release ();
7254 : :
7255 : 1450629 : if (MAY_HAVE_DEBUG_BIND_INSNS)
7256 : 496676 : expand_debug_locations ();
7257 : :
7258 : 1450629 : if (deep_ter_debug_map)
7259 : : {
7260 : 1016 : delete deep_ter_debug_map;
7261 : 1016 : deep_ter_debug_map = NULL;
7262 : : }
7263 : :
7264 : : /* Free stuff we no longer need after GIMPLE optimizations. */
7265 : 1450629 : free_dominance_info (CDI_DOMINATORS);
7266 : 1450629 : free_dominance_info (CDI_POST_DOMINATORS);
7267 : 1450629 : delete_tree_cfg_annotations (fun);
7268 : :
7269 : 1450629 : timevar_push (TV_OUT_OF_SSA);
7270 : 1450629 : finish_out_of_ssa (&SA);
7271 : 1450629 : timevar_pop (TV_OUT_OF_SSA);
7272 : :
7273 : 1450629 : timevar_push (TV_POST_EXPAND);
7274 : : /* We are no longer in SSA form. */
7275 : 1450629 : fun->gimple_df->in_ssa_p = false;
7276 : 1450629 : loops_state_clear (LOOP_CLOSED_SSA);
7277 : :
7278 : : /* Expansion is used by optimization passes too, set maybe_hot_insn_p
7279 : : conservatively to true until they are all profile aware. */
7280 : 2901258 : delete lab_rtx_for_bb;
7281 : 1450629 : free_histograms (fun);
7282 : :
7283 : 1450629 : construct_exit_block ();
7284 : 1450629 : insn_locations_finalize ();
7285 : :
7286 : 1450629 : if (var_ret_seq)
7287 : : {
7288 : 1634 : rtx_insn *after = return_label;
7289 : 1634 : rtx_insn *next = NEXT_INSN (after);
7290 : 1634 : if (next && NOTE_INSN_BASIC_BLOCK_P (next))
7291 : 1634 : after = next;
7292 : 1634 : emit_insn_after (var_ret_seq, after);
7293 : : }
7294 : :
7295 : 1450629 : if (hwasan_sanitize_stack_p ())
7296 : 446 : hwasan_maybe_emit_frame_base_init ();
7297 : :
7298 : : /* Zap the tree EH table. */
7299 : 1450629 : set_eh_throw_stmt_table (fun, NULL);
7300 : :
7301 : : /* We need JUMP_LABEL be set in order to redirect jumps, and hence
7302 : : split edges which edge insertions might do. */
7303 : 1450629 : rebuild_jump_labels (get_insns ());
7304 : :
7305 : : /* If we have a single successor to the entry block, put the pending insns
7306 : : after parm birth, but before NOTE_INSNS_FUNCTION_BEG. */
7307 : 1450629 : if (single_succ_p (ENTRY_BLOCK_PTR_FOR_FN (fun)))
7308 : : {
7309 : 1450629 : edge e = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (fun));
7310 : 1450629 : if (e->insns.r)
7311 : : {
7312 : 11 : rtx_insn *insns = e->insns.r;
7313 : 11 : e->insns.r = NULL;
7314 : 11 : rebuild_jump_labels_chain (insns);
7315 : 11 : if (NOTE_P (parm_birth_insn)
7316 : 11 : && NOTE_KIND (parm_birth_insn) == NOTE_INSN_FUNCTION_BEG)
7317 : 11 : emit_insn_before_noloc (insns, parm_birth_insn, e->dest);
7318 : : else
7319 : 0 : emit_insn_after_noloc (insns, parm_birth_insn, e->dest);
7320 : : }
7321 : : }
7322 : :
7323 : : /* Otherwise, as well as for other edges, take the usual way. */
7324 : 1450629 : commit_edge_insertions ();
7325 : :
7326 : : /* We're done expanding trees to RTL. */
7327 : 1450629 : currently_expanding_to_rtl = 0;
7328 : :
7329 : 1450629 : flush_mark_addressable_queue ();
7330 : :
7331 : 18160743 : FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (fun)->next_bb,
7332 : : EXIT_BLOCK_PTR_FOR_FN (fun), next_bb)
7333 : : {
7334 : 16710114 : edge e;
7335 : 16710114 : edge_iterator ei;
7336 : 38996726 : for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
7337 : : {
7338 : : /* Clear EDGE_EXECUTABLE. This flag is never used in the backend. */
7339 : 22286612 : e->flags &= ~EDGE_EXECUTABLE;
7340 : :
7341 : : /* At the moment not all abnormal edges match the RTL
7342 : : representation. It is safe to remove them here as
7343 : : find_many_sub_basic_blocks will rediscover them.
7344 : : In the future we should get this fixed properly. */
7345 : 22286612 : if ((e->flags & EDGE_ABNORMAL)
7346 : 134588 : && !(e->flags & EDGE_SIBCALL))
7347 : 9933 : remove_edge (e);
7348 : : else
7349 : 22276679 : ei_next (&ei);
7350 : : }
7351 : : }
7352 : :
7353 : 1450629 : auto_sbitmap blocks (last_basic_block_for_fn (fun));
7354 : 1450629 : bitmap_ones (blocks);
7355 : 1450629 : find_many_sub_basic_blocks (blocks);
7356 : 1450629 : purge_all_dead_edges ();
7357 : :
7358 : : /* After initial rtl generation, call back to finish generating
7359 : : exception support code. We need to do this before cleaning up
7360 : : the CFG as the code does not expect dead landing pads. */
7361 : 1450629 : if (fun->eh->region_tree != NULL)
7362 : 65046 : finish_eh_generation ();
7363 : :
7364 : : /* Call expand_stack_alignment after finishing all
7365 : : updates to crtl->preferred_stack_boundary. */
7366 : 1450629 : expand_stack_alignment ();
7367 : :
7368 : : /* Fixup REG_EQUIV notes in the prologue if there are tailcalls in this
7369 : : function. */
7370 : 1450629 : if (crtl->tail_call_emit)
7371 : 112478 : fixup_tail_calls ();
7372 : :
7373 : 1450629 : HOST_WIDE_INT patch_area_size, patch_area_entry;
7374 : 1450629 : parse_and_check_patch_area (flag_patchable_function_entry, false,
7375 : : &patch_area_size, &patch_area_entry);
7376 : :
7377 : 1450629 : tree patchable_function_entry_attr
7378 : 1450629 : = lookup_attribute ("patchable_function_entry",
7379 : 1450629 : DECL_ATTRIBUTES (cfun->decl));
7380 : 1450629 : if (patchable_function_entry_attr)
7381 : : {
7382 : 16 : tree pp_val = TREE_VALUE (patchable_function_entry_attr);
7383 : 16 : tree patchable_function_entry_value1 = TREE_VALUE (pp_val);
7384 : :
7385 : 16 : patch_area_size = tree_to_uhwi (patchable_function_entry_value1);
7386 : 16 : patch_area_entry = 0;
7387 : 16 : if (TREE_CHAIN (pp_val) != NULL_TREE)
7388 : : {
7389 : 8 : tree patchable_function_entry_value2
7390 : 8 : = TREE_VALUE (TREE_CHAIN (pp_val));
7391 : 8 : patch_area_entry = tree_to_uhwi (patchable_function_entry_value2);
7392 : : }
7393 : : }
7394 : :
7395 : 1450629 : if (patch_area_entry > patch_area_size)
7396 : : {
7397 : 0 : if (patch_area_size > 0)
7398 : 0 : warning (OPT_Wattributes,
7399 : : "patchable function entry %wu exceeds size %wu",
7400 : : patch_area_entry, patch_area_size);
7401 : 0 : patch_area_entry = 0;
7402 : : }
7403 : :
7404 : 1450629 : crtl->patch_area_size = patch_area_size;
7405 : 1450629 : crtl->patch_area_entry = patch_area_entry;
7406 : :
7407 : : /* BB subdivision may have created basic blocks that are only reachable
7408 : : from unlikely bbs but not marked as such in the profile. */
7409 : 1450629 : if (optimize)
7410 : 1024132 : propagate_unlikely_bbs_forward ();
7411 : :
7412 : : /* Remove unreachable blocks, otherwise we cannot compute dominators
7413 : : which are needed for loop state verification. As a side-effect
7414 : : this also compacts blocks.
7415 : : ??? We cannot remove trivially dead insns here as for example
7416 : : the DRAP reg on i?86 is not magically live at this point.
7417 : : gcc.c-torture/execute/ipa-sra-2.c execution, -Os -m32 fails otherwise. */
7418 : 1450629 : cleanup_cfg (CLEANUP_NO_INSN_DEL);
7419 : :
7420 : 1450629 : checking_verify_flow_info ();
7421 : :
7422 : : /* Initialize pseudos allocated for hard registers. */
7423 : 1450629 : emit_initial_value_sets ();
7424 : :
7425 : : /* And finally unshare all RTL. */
7426 : 1450629 : unshare_all_rtl ();
7427 : :
7428 : : /* There's no need to defer outputting this function any more; we
7429 : : know we want to output it. */
7430 : 1450629 : DECL_DEFER_OUTPUT (current_function_decl) = 0;
7431 : :
7432 : : /* Now that we're done expanding trees to RTL, we shouldn't have any
7433 : : more CONCATs anywhere. */
7434 : 1450629 : generating_concat_p = 0;
7435 : :
7436 : 1450629 : if (dump_file)
7437 : : {
7438 : 351 : fprintf (dump_file,
7439 : : "\n\n;;\n;; Full RTL generated for this function:\n;;\n");
7440 : : /* And the pass manager will dump RTL for us. */
7441 : : }
7442 : :
7443 : : /* If we're emitting a nested function, make sure its parent gets
7444 : : emitted as well. Doing otherwise confuses debug info. */
7445 : 1450629 : {
7446 : 1450629 : tree parent;
7447 : 1450629 : for (parent = DECL_CONTEXT (current_function_decl);
7448 : 3111870 : parent != NULL_TREE;
7449 : 1661241 : parent = get_containing_scope (parent))
7450 : 1661241 : if (TREE_CODE (parent) == FUNCTION_DECL)
7451 : 71329 : TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
7452 : : }
7453 : :
7454 : 1450629 : TREE_ASM_WRITTEN (current_function_decl) = 1;
7455 : :
7456 : : /* After expanding, the return labels are no longer needed. */
7457 : 1450629 : return_label = NULL;
7458 : 1450629 : naked_return_label = NULL;
7459 : :
7460 : : /* After expanding, the tm_restart map is no longer needed. */
7461 : 1450629 : if (fun->gimple_df->tm_restart)
7462 : 265 : fun->gimple_df->tm_restart = NULL;
7463 : :
7464 : : /* Tag the blocks with a depth number so that change_scope can find
7465 : : the common parent easily. */
7466 : 1450629 : set_block_levels (DECL_INITIAL (fun->decl), 0);
7467 : 1450629 : default_rtl_profile ();
7468 : :
7469 : : /* For -dx discard loops now, otherwise IL verify in clean_state will
7470 : : ICE. */
7471 : 1450629 : if (rtl_dump_and_exit)
7472 : : {
7473 : 79 : cfun->curr_properties &= ~PROP_loops;
7474 : 79 : loop_optimizer_finalize ();
7475 : : }
7476 : :
7477 : 1450629 : timevar_pop (TV_POST_EXPAND);
7478 : :
7479 : 1450629 : return 0;
7480 : 1450629 : }
7481 : :
7482 : : } // anon namespace
7483 : :
7484 : : rtl_opt_pass *
7485 : 285085 : make_pass_expand (gcc::context *ctxt)
7486 : : {
7487 : 285085 : return new pass_expand (ctxt);
7488 : : }
|