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