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 3460433 : gimple_assign_rhs_to_tree (gimple *stmt)
107 : {
108 3460433 : tree t;
109 3460433 : switch (gimple_assign_rhs_class (stmt))
110 : {
111 3832 : case GIMPLE_TERNARY_RHS:
112 3832 : t = build3 (gimple_assign_rhs_code (stmt),
113 3832 : TREE_TYPE (gimple_assign_lhs (stmt)),
114 : gimple_assign_rhs1 (stmt), gimple_assign_rhs2 (stmt),
115 : gimple_assign_rhs3 (stmt));
116 3832 : break;
117 1347436 : case GIMPLE_BINARY_RHS:
118 1347436 : t = build2 (gimple_assign_rhs_code (stmt),
119 1347436 : TREE_TYPE (gimple_assign_lhs (stmt)),
120 : gimple_assign_rhs1 (stmt), gimple_assign_rhs2 (stmt));
121 1347436 : break;
122 365671 : case GIMPLE_UNARY_RHS:
123 365671 : t = build1 (gimple_assign_rhs_code (stmt),
124 365671 : TREE_TYPE (gimple_assign_lhs (stmt)),
125 : gimple_assign_rhs1 (stmt));
126 365671 : break;
127 1743494 : case GIMPLE_SINGLE_RHS:
128 1743494 : {
129 1743494 : t = gimple_assign_rhs1 (stmt);
130 : /* Avoid modifying this tree in place below. */
131 3402300 : if ((gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (t)
132 1627471 : && gimple_location (stmt) != EXPR_LOCATION (t))
133 1929589 : || (gimple_block (stmt) && currently_expanding_to_rtl
134 37511 : && EXPR_P (t)))
135 1502693 : t = copy_node (t);
136 : break;
137 : }
138 0 : default:
139 0 : gcc_unreachable ();
140 : }
141 :
142 3460433 : if (gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (t))
143 3217168 : SET_EXPR_LOCATION (t, gimple_location (stmt));
144 :
145 3460433 : 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 80773493 : expand_leader_merge (tree cur, tree next)
163 : {
164 80773493 : if (cur == NULL || cur == next)
165 : return next;
166 :
167 3896266 : if (DECL_P (cur) && DECL_IGNORED_P (cur))
168 : return cur;
169 :
170 2827450 : if (DECL_P (next) && DECL_IGNORED_P (next))
171 320980 : 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 73368531 : set_rtl (tree t, rtx x)
181 : {
182 73368531 : 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 67993843 : 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 67993843 : if (x)
222 : {
223 68437809 : bool skip = false;
224 68437809 : tree cur = NULL_TREE;
225 : rtx xm = x;
226 :
227 443966 : retry:
228 68437809 : if (MEM_P (xm))
229 4913114 : cur = MEM_EXPR (xm);
230 : else if (REG_P (xm))
231 57197614 : 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 440123 : xm = XEXP (xm, 0);
241 440123 : goto retry;
242 : }
243 : else if (GET_CODE (xm) == PARALLEL)
244 : {
245 3843 : xm = XVECEXP (xm, 0, 0);
246 3843 : gcc_assert (GET_CODE (xm) == EXPR_LIST);
247 3843 : xm = XEXP (xm, 0);
248 3843 : goto retry;
249 : }
250 5883115 : else if (xm == pc_rtx)
251 : skip = true;
252 : else
253 0 : gcc_unreachable ();
254 :
255 35631620 : tree next
256 62110728 : = skip ? cur : expand_leader_merge (cur, SSAVAR (t) ? SSAVAR (t) : t);
257 :
258 67993843 : if (cur != next)
259 : {
260 28700443 : if (MEM_P (x))
261 4119720 : set_mem_attributes (x,
262 2059860 : next && TREE_CODE (next) == SSA_NAME
263 12550 : ? TREE_TYPE (next)
264 : : next, true);
265 : else
266 26640583 : set_reg_attrs_for_decl_rtl (next, x);
267 : }
268 : }
269 :
270 73368531 : if (TREE_CODE (t) == SSA_NAME)
271 : {
272 59559459 : int part = var_to_partition (SA.map, t);
273 59559459 : if (part != NO_PARTITION)
274 : {
275 59559459 : if (SA.partition_to_pseudo[part])
276 32573731 : gcc_assert (SA.partition_to_pseudo[part] == x);
277 26985728 : else if (x != pc_rtx)
278 26982432 : 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 119115622 : if (x && x != pc_rtx && SSA_NAME_VAR (t)
285 78062691 : && (VAR_P (SSA_NAME_VAR (t))
286 7596241 : || SSA_NAME_IS_DEFAULT_DEF (t)))
287 : {
288 18323127 : tree var = SSA_NAME_VAR (t);
289 : /* If we don't yet have something recorded, just record it now. */
290 18323127 : if (!DECL_RTL_SET_P (var))
291 7707858 : SET_DECL_RTL (var, x);
292 : /* If we have it set already to "multiple places" don't
293 : change this. */
294 10615269 : 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 9440820 : else if (DECL_RTL (var) != x)
303 250701 : SET_DECL_RTL (var, pc_rtx);
304 : }
305 : }
306 : else
307 13809072 : SET_DECL_RTL (t, x);
308 73368531 : }
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 13540992 : align_local_variable (tree decl, bool really_expand)
372 : {
373 13540992 : unsigned int align;
374 :
375 13540992 : if (TREE_CODE (decl) == SSA_NAME)
376 : {
377 929472 : tree type = TREE_TYPE (decl);
378 929472 : machine_mode mode = TYPE_MODE (type);
379 :
380 929472 : align = TYPE_ALIGN (type);
381 929472 : if (mode != BLKmode
382 929472 : && align < GET_MODE_ALIGNMENT (mode))
383 924 : align = GET_MODE_ALIGNMENT (mode);
384 : }
385 : else
386 12611520 : align = LOCAL_DECL_ALIGNMENT (decl);
387 :
388 13540992 : if (hwassist_sanitize_stack_p ())
389 572 : align = MAX (align, (unsigned) HWASAN_TAG_GRANULE_SIZE * BITS_PER_UNIT);
390 :
391 13540992 : 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 1586390 : SET_DECL_ALIGN (decl, align);
397 :
398 13540992 : 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 1779305 : alloc_stack_frame_space (poly_int64 size, unsigned HOST_WIDE_INT align)
415 : {
416 1779305 : poly_int64 offset, new_frame_offset;
417 :
418 1779305 : if (FRAME_GROWS_DOWNWARD)
419 : {
420 1779305 : new_frame_offset
421 1779305 : = aligned_lower_bound (frame_offset - frame_phase - size,
422 1779305 : align) + frame_phase;
423 1779305 : 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 1779305 : frame_offset = new_frame_offset;
434 :
435 1779305 : if (frame_offset_overflow (frame_offset, cfun->decl))
436 0 : frame_offset = offset = 0;
437 :
438 1779305 : 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 1970 : 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 5883115 : add_stack_var (tree decl, bool really_expand)
453 : {
454 5883115 : class stack_var *v;
455 :
456 5883115 : if (stack_vars_num >= stack_vars_alloc)
457 : {
458 1371779 : if (stack_vars_alloc)
459 34961 : stack_vars_alloc = stack_vars_alloc * 3 / 2;
460 : else
461 : stack_vars_alloc = 32;
462 1371779 : stack_vars
463 1371779 : = XRESIZEVEC (class stack_var, stack_vars, stack_vars_alloc);
464 : }
465 5883115 : if (!decl_to_stack_part)
466 0 : decl_to_stack_part = new hash_map<tree, unsigned>;
467 :
468 5883115 : v = &stack_vars[stack_vars_num];
469 5883115 : decl_to_stack_part->put (decl, stack_vars_num);
470 :
471 5883115 : v->decl = decl;
472 5883115 : tree size = TREE_CODE (decl) == SSA_NAME
473 5883115 : ? TYPE_SIZE_UNIT (TREE_TYPE (decl))
474 5883115 : : DECL_SIZE_UNIT (decl);
475 5883115 : 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 5883115 : if (known_eq (v->size, 0U))
479 24514 : v->size = 1;
480 5883115 : v->alignb = align_local_variable (decl, really_expand);
481 : /* An alignment of zero can mightily confuse us later. */
482 5883115 : gcc_assert (v->alignb != 0);
483 :
484 : /* All variables are initially in their own partition. */
485 5883115 : v->representative = stack_vars_num;
486 5883115 : v->next = EOC;
487 :
488 : /* All variables initially conflict with no other. */
489 5883115 : v->conflicts = NULL;
490 :
491 : /* Ensure that this decl doesn't get put onto the list twice. */
492 5883115 : set_rtl (decl, pc_rtx);
493 :
494 5883115 : stack_vars_num++;
495 5883115 : }
496 :
497 : /* Make the decls associated with luid's X and Y conflict. */
498 :
499 : static void
500 11872637 : add_stack_var_conflict (unsigned x, unsigned y)
501 : {
502 11872637 : class stack_var *a = &stack_vars[x];
503 11872637 : class stack_var *b = &stack_vars[y];
504 11872637 : if (x == y)
505 : return;
506 10776638 : if (!a->conflicts)
507 677910 : a->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack);
508 10776638 : if (!b->conflicts)
509 121323 : b->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack);
510 10776638 : bitmap_set_bit (a->conflicts, y);
511 10776638 : 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 11642545 : stack_var_conflict_p (unsigned x, unsigned y)
518 : {
519 11642545 : class stack_var *a = &stack_vars[x];
520 11642545 : class stack_var *b = &stack_vars[y];
521 11642545 : 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 11642545 : if (TREE_CODE (a->decl) == SSA_NAME || TREE_CODE (b->decl) == SSA_NAME)
527 : return true;
528 :
529 11606918 : if (!a->conflicts || !b->conflicts)
530 : return false;
531 11555842 : 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 47881258 : decl_stack_index (tree decl)
538 : {
539 47881258 : if (!decl)
540 : return INVALID_STACK_INDEX;
541 47881258 : if (!DECL_P (decl))
542 : return INVALID_STACK_INDEX;
543 36776988 : if (DECL_RTL_IF_SET (decl) != pc_rtx)
544 : return INVALID_STACK_INDEX;
545 24757412 : unsigned *v = decl_to_stack_part->get (decl);
546 24757412 : if (!v)
547 : return INVALID_STACK_INDEX;
548 :
549 24757412 : unsigned indx = *v;
550 24757412 : gcc_checking_assert (indx != INVALID_STACK_INDEX);
551 24757412 : 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 30282177 : visit_op (gimple *, tree op, tree, void *data)
560 : {
561 30282177 : bitmap active = (bitmap)data;
562 30282177 : op = get_base_address (op);
563 30282177 : unsigned idx = decl_stack_index (op);
564 30282177 : if (idx != INVALID_STACK_INDEX)
565 14958792 : bitmap_set_bit (active, idx);
566 30282177 : 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 14018944 : visit_conflict (gimple *, tree op, tree, void *data)
575 : {
576 14018944 : bitmap active = (bitmap)data;
577 14018944 : op = get_base_address (op);
578 14018944 : unsigned num = decl_stack_index (op);
579 14018944 : if (num != INVALID_STACK_INDEX
580 14018944 : && bitmap_set_bit (active, num))
581 : {
582 1014583 : bitmap_iterator bi;
583 1014583 : unsigned i;
584 1014583 : gcc_assert (num < stack_vars_num);
585 11046243 : EXECUTE_IF_SET_IN_BITMAP (active, 0, i, bi)
586 10031660 : add_stack_var_conflict (num, i);
587 : }
588 14018944 : 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 1128594 : void unshare(int indx)
629 : {
630 1128594 : if (vars_ssa_caches[indx].bmap == empty)
631 485853 : vars_ssa_caches[indx].bmap = BITMAP_ALLOC (&stack_var_bitmap_obstack);
632 1128594 : }
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 150759 : vars_ssa_cache::vars_ssa_cache ()
641 : {
642 33447071 : vars_ssa_caches = new entry[num_ssa_names]{};
643 :
644 : /* Create the shared empty bitmap too. */
645 150759 : empty = BITMAP_ALLOC (&stack_var_bitmap_obstack);
646 150759 : }
647 :
648 : /* Delete the array. The bitmaps will be freed
649 : when stack_var_bitmap_obstack is freed. */
650 150759 : vars_ssa_cache::~vars_ssa_cache ()
651 : {
652 150759 : delete []vars_ssa_caches;
653 150759 : }
654 :
655 : /* Create an empty entry for the USE ssa name. */
656 : void
657 11067061 : vars_ssa_cache::create (tree use)
658 : {
659 11067061 : int num = SSA_NAME_VERSION (use);
660 11067061 : if (vars_ssa_caches[num].bmap)
661 : return;
662 11067061 : vars_ssa_caches[num].bmap = empty;
663 : }
664 :
665 : /* Returns true if the cache for USE exists. */
666 : bool
667 72428395 : vars_ssa_cache::exists (tree use)
668 : {
669 72428395 : int num = SSA_NAME_VERSION (use);
670 72428395 : return vars_ssa_caches[num].bmap != nullptr;
671 : }
672 :
673 : /* Add to USE's bitmap for stack variable IDX. */
674 : void
675 165911 : vars_ssa_cache::add_one (tree use, unsigned idx)
676 : {
677 165911 : gcc_assert (idx != INVALID_STACK_INDEX);
678 165911 : int num = SSA_NAME_VERSION (use);
679 165911 : gcc_assert (vars_ssa_caches[num].bmap);
680 165911 : unshare (num);
681 165911 : bitmap_set_bit (vars_ssa_caches[num].bmap, idx);
682 165911 : }
683 :
684 : /* Update cache of OLD_NAME from the USE's cache. */
685 : bool
686 25538401 : vars_ssa_cache::update (tree old_name, tree use)
687 : {
688 25538401 : if (old_name == use)
689 : return false;
690 16317086 : int num = SSA_NAME_VERSION (use);
691 16317086 : int old_num = SSA_NAME_VERSION (old_name);
692 :
693 : /* If the old name was empty, then there is nothing to be updated. */
694 16317086 : if (vars_ssa_caches[num].bmap == empty)
695 : return false;
696 962683 : unshare (old_num);
697 962683 : 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 56763609 : vars_ssa_cache::operator() (tree name)
731 : {
732 56763609 : gcc_assert (TREE_CODE (name) == SSA_NAME);
733 :
734 93497913 : if (!POINTER_TYPE_P (TREE_TYPE (name))
735 92327930 : && !ANY_INTEGRAL_TYPE_P (TREE_TYPE (name)))
736 2510448 : return empty;
737 :
738 54253161 : if (exists (name))
739 45085369 : return vars_ssa_caches[SSA_NAME_VERSION (name)].bmap;
740 :
741 9167792 : auto_vec<std::pair<tree,tree>, 4> work_list;
742 9167792 : auto_vec<std::pair<tree,tree>, 4> update_cache_list;
743 :
744 9167792 : work_list.safe_push (std::make_pair (name, name));
745 :
746 33778650 : while (!work_list.is_empty ())
747 : {
748 24610858 : auto item = work_list.pop();
749 24610858 : tree use = item.first;
750 24610858 : tree old_name = item.second;
751 24610858 : if (TREE_CODE (use) == ADDR_EXPR)
752 : {
753 419286 : tree op = TREE_OPERAND (use, 0);
754 419286 : op = get_base_address (op);
755 419286 : unsigned idx = decl_stack_index (op);
756 419286 : if (idx != INVALID_STACK_INDEX)
757 165911 : add_one (old_name, idx);
758 13543797 : continue;
759 419286 : }
760 :
761 24191572 : if (TREE_CODE (use) != SSA_NAME)
762 5937562 : continue;
763 :
764 31859604 : if (!POINTER_TYPE_P (TREE_TYPE (use))
765 31726560 : && !ANY_INTEGRAL_TYPE_P (TREE_TYPE (use)))
766 78776 : continue;
767 :
768 : /* Mark the old ssa name needs to be update from the use. */
769 18175234 : update_cache_list.safe_push (item);
770 :
771 : /* If the cache exists for the use, don't try to recreate it. */
772 18175234 : if (exists (use))
773 : {
774 : /* Update the cache here, this can reduce the number of
775 : times through the update loop below. */
776 7108173 : update (old_name, use);
777 7108173 : 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 11067061 : create (use);
783 :
784 11067061 : gimple *g = SSA_NAME_DEF_STMT (use);
785 :
786 : /* CONSTRUCTOR here is always a vector initialization,
787 : walk each element too. */
788 11067061 : if (gimple_assign_single_p (g)
789 11067061 : && TREE_CODE (gimple_assign_rhs1 (g)) == CONSTRUCTOR)
790 : {
791 : tree ctr = gimple_assign_rhs1 (g);
792 : unsigned i;
793 : tree elm;
794 312570 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctr), i, elm)
795 220001 : 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 10974492 : else if (gassign *a = dyn_cast <gassign *> (g))
800 : {
801 : /* operand 0 is the lhs. */
802 19602214 : for (unsigned i = 1; i < gimple_num_ops (g); i++)
803 11324360 : work_list.safe_push (std::make_pair (gimple_op (a, i), use));
804 : }
805 12651310 : else if (gphi *p = dyn_cast <gphi *> (g))
806 5482954 : for (unsigned i = 0; i < gimple_phi_num_args (p); ++i)
807 3898705 : 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 9221259 : bool changed;
814 18442518 : do {
815 9221259 : changed = false;
816 9221259 : unsigned int i;
817 9221259 : std::pair<tree,tree> *e;
818 46040538 : FOR_EACH_VEC_ELT_REVERSE (update_cache_list, i, e)
819 : {
820 18430228 : if (update (e->second, e->first))
821 60283 : changed = true;
822 : }
823 : } while (changed);
824 :
825 9167792 : return vars_ssa_caches[SSA_NAME_VERSION (name)].bmap;
826 9167792 : }
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 56763609 : add_scope_conflicts_2 (vars_ssa_cache &cache, tree name,
835 : bitmap work, walk_stmt_load_store_addr_fn visit)
836 : {
837 56763609 : 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 56763609 : bitmap_iterator bi;
842 56763609 : unsigned i;
843 56763609 : const_bitmap bmap = cache (name);
844 : /* Visit each stack variable that is referenced. */
845 59226429 : EXECUTE_IF_SET_IN_BITMAP (bmap, 0, i, bi)
846 2462820 : visit (nullptr, stack_vars[i].decl, nullptr, work);
847 56763609 : }
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 16535784 : add_scope_conflicts_1 (vars_ssa_cache &cache, basic_block bb, bitmap work, bool for_conflict)
856 : {
857 16535784 : edge e;
858 16535784 : edge_iterator ei;
859 16535784 : gimple_stmt_iterator gsi;
860 16535784 : walk_stmt_load_store_addr_fn visit;
861 16535784 : use_operand_p use_p;
862 16535784 : ssa_op_iter iter;
863 16535784 : bool had_non_clobbers = false;
864 :
865 16535784 : bitmap_clear (work);
866 : /* The copy what was alive out going from the edges. */
867 41776390 : FOR_EACH_EDGE (e, ei, bb->preds)
868 25240606 : bitmap_ior_into (work, (bitmap)e->src->aux);
869 :
870 16535784 : visit = for_conflict ? visit_conflict : visit_op;
871 :
872 : /* Addresses coming into the bb via phis are alive at the entry point. */
873 21700415 : for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
874 5164631 : add_scope_conflicts_2 (cache, gimple_phi_result (gsi_stmt (gsi)), work, visit);
875 :
876 188605303 : for (gsi = gsi_after_labels (bb); !gsi_end_p (gsi); gsi_next (&gsi))
877 : {
878 172069519 : gimple *stmt = gsi_stmt (gsi);
879 :
880 : /* Debug statements are not considered for liveness. */
881 172069519 : if (is_gimple_debug (stmt))
882 107721964 : 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 64347555 : if (gimple_clobber_p (stmt))
888 : {
889 3239520 : 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 3239520 : if (!VAR_P (lhs))
894 78669 : continue;
895 3160851 : unsigned indx = decl_stack_index (lhs);
896 3160851 : if (indx != INVALID_STACK_INDEX)
897 2600520 : bitmap_clear_bit (work, indx);
898 : }
899 : else
900 : {
901 61108035 : 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 4989877 : bitmap_iterator bi;
914 4989877 : unsigned i;
915 4989877 : if (EDGE_COUNT (bb->preds) > 1)
916 12724127 : EXECUTE_IF_SET_IN_BITMAP (work, 0, i, bi)
917 : {
918 11270250 : class stack_var *a = &stack_vars[i];
919 11270250 : if (!a->conflicts)
920 255687 : a->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack);
921 11270250 : bitmap_ior_into (a->conflicts, work);
922 : }
923 4989877 : had_non_clobbers = true;
924 : }
925 61108035 : walk_stmt_load_store_addr_ops (stmt, work, visit, visit, visit);
926 112707013 : FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
927 51598978 : 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 16535784 : if (for_conflict && !had_non_clobbers && EDGE_COUNT (bb->preds) > 1)
934 : {
935 130572 : bitmap_iterator bi;
936 130572 : unsigned i;
937 950653 : EXECUTE_IF_SET_IN_BITMAP (work, 0, i, bi)
938 : {
939 820081 : class stack_var *a = &stack_vars[i];
940 820081 : if (!a->conflicts)
941 22791 : a->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack);
942 820081 : bitmap_ior_into (a->conflicts, work);
943 : }
944 : }
945 16535784 : }
946 :
947 : /* Generate stack partition conflicts between all partitions that are
948 : simultaneously live. */
949 :
950 : static void
951 238898 : 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 238898 : if (stack_vars_num == 1)
956 88139 : return;
957 :
958 150759 : basic_block bb;
959 150759 : bool changed;
960 150759 : bitmap work = BITMAP_ALLOC (NULL);
961 150759 : int *rpo;
962 150759 : int n_bbs;
963 :
964 150759 : 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 5647863 : FOR_ALL_BB_FN (bb, cfun)
977 5497104 : bb->aux = BITMAP_ALLOC (&stack_var_bitmap_obstack);
978 :
979 150759 : rpo = XNEWVEC (int, last_basic_block_for_fn (cfun));
980 150759 : n_bbs = pre_and_rev_post_order_compute (NULL, rpo, false);
981 :
982 150759 : changed = true;
983 609651 : while (changed)
984 : {
985 : int i;
986 : changed = false;
987 11648331 : for (i = 0; i < n_bbs; i++)
988 : {
989 11340198 : bitmap active;
990 11340198 : bb = BASIC_BLOCK_FOR_FN (cfun, rpo[i]);
991 11340198 : active = (bitmap)bb->aux;
992 11340198 : add_scope_conflicts_1 (cache, bb, work, false);
993 11340198 : if (bitmap_ior_into (active, work))
994 4663428 : changed = true;
995 : }
996 : }
997 :
998 5346345 : FOR_EACH_BB_FN (bb, cfun)
999 5195586 : add_scope_conflicts_1 (cache, bb, work, true);
1000 :
1001 150759 : if (dump_file && (dump_flags & TDF_DETAILS))
1002 0 : cache.dump (dump_file);
1003 :
1004 150759 : free (rpo);
1005 150759 : BITMAP_FREE (work);
1006 5647863 : FOR_ALL_BB_FN (bb, cfun)
1007 5497104 : BITMAP_FREE (bb->aux);
1008 150759 : }
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 20538230 : stack_var_cmp (const void *a, const void *b)
1015 : {
1016 20538230 : unsigned ia = *(const unsigned *)a;
1017 20538230 : unsigned ib = *(const unsigned *)b;
1018 20538230 : unsigned int aligna = stack_vars[ia].alignb;
1019 20538230 : unsigned int alignb = stack_vars[ib].alignb;
1020 20538230 : poly_int64 sizea = stack_vars[ia].size;
1021 20538230 : poly_int64 sizeb = stack_vars[ib].size;
1022 20538230 : tree decla = stack_vars[ia].decl;
1023 20538230 : tree declb = stack_vars[ib].decl;
1024 20538230 : bool largea, largeb;
1025 20538230 : unsigned int uida, uidb;
1026 :
1027 : /* Primary compare on "large" alignment. Large comes first. */
1028 20538230 : largea = (aligna * BITS_PER_UNIT > MAX_SUPPORTED_STACK_ALIGNMENT);
1029 20538230 : largeb = (alignb * BITS_PER_UNIT > MAX_SUPPORTED_STACK_ALIGNMENT);
1030 20538230 : if (largea != largeb)
1031 0 : return (int)largeb - (int)largea;
1032 :
1033 : /* Secondary compare on size, decreasing */
1034 36992666 : int diff = compare_sizes_for_sort (sizeb, sizea);
1035 4741158 : if (diff != 0)
1036 : return diff;
1037 :
1038 : /* Tertiary compare on true alignment, decreasing. */
1039 11713278 : if (aligna < alignb)
1040 : return -1;
1041 11406723 : 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 11156805 : if (TREE_CODE (decla) == SSA_NAME)
1048 : {
1049 38616 : if (TREE_CODE (declb) == SSA_NAME)
1050 33777 : uida = SSA_NAME_VERSION (decla), uidb = SSA_NAME_VERSION (declb);
1051 : else
1052 : return -1;
1053 : }
1054 11118189 : else if (TREE_CODE (declb) == SSA_NAME)
1055 : return 1;
1056 : else
1057 11112287 : uida = DECL_UID (decla), uidb = DECL_UID (declb);
1058 11146064 : if (uida < uidb)
1059 : return 1;
1060 5547864 : if (uida > uidb)
1061 5547864 : 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 1632109 : add_partitioned_vars_to_ptset (const pt_solution *pt,
1074 : part_hashmap *decls_to_partitions,
1075 : hash_set<bitmap> *visited, bitmap temp)
1076 : {
1077 1632109 : bitmap_iterator bi;
1078 1632109 : unsigned i;
1079 1632109 : bitmap *part;
1080 :
1081 1632109 : if (pt->anything
1082 1587821 : || pt->vars == NULL
1083 : /* The pointed-to vars bitmap is shared, it is enough to
1084 : visit it once. */
1085 3219930 : || visited->add (pt->vars))
1086 1317836 : return;
1087 :
1088 314273 : 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 1356054 : EXECUTE_IF_SET_IN_BITMAP (pt->vars, 0, i, bi)
1094 1041781 : if ((!temp
1095 1041781 : || !bitmap_bit_p (temp, i))
1096 1690256 : && (part = decls_to_partitions->get (i)))
1097 177173 : bitmap_ior_into (temp, *part);
1098 314273 : if (!bitmap_empty_p (temp))
1099 149804 : 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 150759 : update_alias_info_with_stack_vars (void)
1115 : {
1116 150759 : part_hashmap *decls_to_partitions = NULL;
1117 150759 : unsigned i, j;
1118 150759 : tree var = NULL_TREE;
1119 :
1120 1288764 : for (i = 0; i < stack_vars_num; i++)
1121 : {
1122 1138005 : bitmap part = NULL;
1123 1138005 : tree name;
1124 :
1125 : /* Not interested in partitions with single variable. */
1126 1138005 : if (stack_vars[i].representative != i
1127 862026 : || stack_vars[i].next == EOC)
1128 1064820 : continue;
1129 :
1130 73185 : if (!decls_to_partitions)
1131 : {
1132 43515 : decls_to_partitions = new part_hashmap;
1133 43515 : cfun->gimple_df->decls_to_pointers = new hash_map<tree, tree>;
1134 : }
1135 :
1136 : /* Create an SSA_NAME that points to the partition for use
1137 : as base during alias-oracle queries on RTL for bases that
1138 : have been partitioned. */
1139 73185 : if (var == NULL_TREE)
1140 43515 : var = create_tmp_var (ptr_type_node);
1141 73185 : name = make_ssa_name (var);
1142 :
1143 : /* Create bitmaps representing partitions. They will be used for
1144 : points-to sets later, so use GGC alloc. */
1145 73185 : part = BITMAP_GGC_ALLOC ();
1146 422349 : for (j = i; j != EOC; j = stack_vars[j].next)
1147 : {
1148 349164 : tree decl = stack_vars[j].decl;
1149 349164 : unsigned int uid = DECL_PT_UID (decl);
1150 349164 : bitmap_set_bit (part, uid);
1151 349164 : decls_to_partitions->put (uid, part);
1152 349164 : cfun->gimple_df->decls_to_pointers->put (decl, name);
1153 349164 : if (TREE_ADDRESSABLE (decl))
1154 319020 : TREE_ADDRESSABLE (name) = 1;
1155 : }
1156 :
1157 : /* Make the SSA name point to all partition members. */
1158 73185 : pt_solution pt;
1159 73185 : pt_solution_set (&pt, part, false);
1160 73185 : set_ssa_name_pt_solution (name, pt);
1161 : }
1162 :
1163 : /* Make all points-to sets that contain one member of a partition
1164 : contain all members of the partition. */
1165 150759 : if (decls_to_partitions)
1166 : {
1167 43515 : unsigned i;
1168 43515 : tree name;
1169 43515 : hash_set<bitmap> visited;
1170 43515 : bitmap temp = BITMAP_ALLOC (&stack_var_bitmap_obstack);
1171 :
1172 17186658 : FOR_EACH_SSA_NAME (i, name, cfun)
1173 : {
1174 27687348 : const pt_solution *pt = ssa_name_pt_solution (name);
1175 :
1176 1554114 : if (pt)
1177 1545079 : add_partitioned_vars_to_ptset (pt, decls_to_partitions,
1178 : &visited, temp);
1179 : }
1180 :
1181 43515 : add_partitioned_vars_to_ptset (&cfun->gimple_df->escaped,
1182 : decls_to_partitions, &visited, temp);
1183 43515 : add_partitioned_vars_to_ptset (&cfun->gimple_df->escaped_return,
1184 : decls_to_partitions, &visited, temp);
1185 43515 : delete decls_to_partitions;
1186 43515 : BITMAP_FREE (temp);
1187 43515 : }
1188 150759 : }
1189 :
1190 : /* A subroutine of partition_stack_vars. The UNION portion of a UNION/FIND
1191 : partitioning algorithm. Partitions A and B are known to be non-conflicting.
1192 : Merge them into a single partition A. */
1193 :
1194 : static void
1195 275979 : union_stack_vars (unsigned a, unsigned b)
1196 : {
1197 275979 : class stack_var *vb = &stack_vars[b];
1198 275979 : bitmap_iterator bi;
1199 275979 : unsigned u;
1200 :
1201 275979 : gcc_assert (stack_vars[b].next == EOC);
1202 : /* Add B to A's partition. */
1203 275979 : stack_vars[b].next = stack_vars[a].next;
1204 275979 : stack_vars[b].representative = a;
1205 275979 : stack_vars[a].next = b;
1206 :
1207 : /* Make sure A is big enough to hold B. */
1208 275979 : stack_vars[a].size = upper_bound (stack_vars[a].size, stack_vars[b].size);
1209 :
1210 : /* Update the required alignment of partition A to account for B. */
1211 275979 : if (stack_vars[a].alignb < stack_vars[b].alignb)
1212 1851 : stack_vars[a].alignb = stack_vars[b].alignb;
1213 :
1214 : /* Update the interference graph and merge the conflicts. */
1215 275979 : if (vb->conflicts)
1216 : {
1217 2067434 : EXECUTE_IF_SET_IN_BITMAP (vb->conflicts, 0, u, bi)
1218 1840636 : add_stack_var_conflict (a, stack_vars[u].representative);
1219 226798 : BITMAP_FREE (vb->conflicts);
1220 : }
1221 275979 : }
1222 :
1223 : /* A subroutine of expand_used_vars. Binpack the variables into
1224 : partitions constrained by the interference graph. The overall
1225 : algorithm used is as follows:
1226 :
1227 : Sort the objects by size in descending order.
1228 : For each object A {
1229 : S = size(A)
1230 : O = 0
1231 : loop {
1232 : Look for the largest non-conflicting object B with size <= S.
1233 : UNION (A, B)
1234 : }
1235 : }
1236 : */
1237 :
1238 : static void
1239 238898 : partition_stack_vars (void)
1240 : {
1241 238898 : unsigned si, sj, n = stack_vars_num;
1242 :
1243 238898 : stack_vars_sorted = XNEWVEC (unsigned, stack_vars_num);
1244 1465042 : for (si = 0; si < n; ++si)
1245 1226144 : stack_vars_sorted[si] = si;
1246 :
1247 238898 : if (n == 1)
1248 : return;
1249 :
1250 150759 : qsort (stack_vars_sorted, n, sizeof (unsigned), stack_var_cmp);
1251 :
1252 1439523 : for (si = 0; si < n; ++si)
1253 : {
1254 1138005 : unsigned i = stack_vars_sorted[si];
1255 1138005 : unsigned int ialign = stack_vars[i].alignb;
1256 1138005 : poly_int64 isize = stack_vars[i].size;
1257 :
1258 : /* Ignore objects that aren't partition representatives. If we
1259 : see a var that is not a partition representative, it must
1260 : have been merged earlier. */
1261 1138005 : if (stack_vars[i].representative != i)
1262 275979 : continue;
1263 :
1264 13298122 : for (sj = si + 1; sj < n; ++sj)
1265 : {
1266 12437586 : unsigned j = stack_vars_sorted[sj];
1267 12437586 : unsigned int jalign = stack_vars[j].alignb;
1268 12437586 : poly_int64 jsize = stack_vars[j].size;
1269 :
1270 : /* Ignore objects that aren't partition representatives. */
1271 12437586 : if (stack_vars[j].representative != j)
1272 12436096 : continue;
1273 :
1274 : /* Do not mix objects of "small" (supported) alignment
1275 : and "large" (unsupported) alignment. */
1276 11644035 : if ((ialign * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT)
1277 11644035 : != (jalign * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT))
1278 : break;
1279 :
1280 : /* For Address Sanitizer do not mix objects with different
1281 : sizes, as the shorter vars wouldn't be adequately protected.
1282 : Don't do that for "large" (unsupported) alignment objects,
1283 : those aren't protected anyway. */
1284 11644035 : if (asan_sanitize_stack_p ()
1285 7976 : && maybe_ne (isize, jsize)
1286 11645525 : && ialign * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT)
1287 : break;
1288 :
1289 : /* Ignore conflicting objects. */
1290 11642545 : if (stack_var_conflict_p (i, j))
1291 11366566 : continue;
1292 :
1293 : /* UNION the objects, placing J at OFFSET. */
1294 275979 : union_stack_vars (i, j);
1295 : }
1296 : }
1297 :
1298 150759 : update_alias_info_with_stack_vars ();
1299 : }
1300 :
1301 : /* A debugging aid for expand_used_vars. Dump the generated partitions. */
1302 :
1303 : static void
1304 41 : dump_stack_var_partition (void)
1305 : {
1306 41 : unsigned si, i, j, n = stack_vars_num;
1307 :
1308 95 : for (si = 0; si < n; ++si)
1309 : {
1310 54 : i = stack_vars_sorted[si];
1311 :
1312 : /* Skip variables that aren't partition representatives, for now. */
1313 54 : if (stack_vars[i].representative != i)
1314 3 : continue;
1315 :
1316 51 : fprintf (dump_file, "Partition %u: size ", i);
1317 51 : print_dec (stack_vars[i].size, dump_file);
1318 51 : fprintf (dump_file, " align %u\n", stack_vars[i].alignb);
1319 :
1320 156 : for (j = i; j != EOC; j = stack_vars[j].next)
1321 : {
1322 54 : fputc ('\t', dump_file);
1323 54 : print_generic_expr (dump_file, stack_vars[j].decl, dump_flags);
1324 : }
1325 51 : fputc ('\n', dump_file);
1326 : }
1327 41 : }
1328 :
1329 : /* Assign rtl to DECL at BASE + OFFSET. */
1330 :
1331 : static void
1332 2051520 : expand_one_stack_var_at (tree decl, rtx base, unsigned base_align,
1333 : poly_int64 offset)
1334 : {
1335 2051520 : unsigned align;
1336 2051520 : rtx x;
1337 :
1338 : /* If this fails, we've overflowed the stack frame. Error nicely? */
1339 2327713 : gcc_assert (known_eq (offset, trunc_int_for_mode (offset, Pmode)));
1340 :
1341 2051520 : if (hwassist_sanitize_stack_p ())
1342 88 : x = targetm.memtag.add_tag (base, offset,
1343 : hwasan_current_frame_tag ());
1344 : else
1345 2327625 : x = plus_constant (Pmode, base, offset);
1346 :
1347 4103040 : x = gen_rtx_MEM (TREE_CODE (decl) == SSA_NAME
1348 465130 : ? TYPE_MODE (TREE_TYPE (decl))
1349 1586390 : : DECL_MODE (decl), x);
1350 :
1351 : /* Set alignment we actually gave this decl if it isn't an SSA name.
1352 : If it is we generate stack slots only accidentally so it isn't as
1353 : important, we'll simply set the alignment directly on the MEM. */
1354 :
1355 2051520 : if (stack_vars_base_reg_p (base))
1356 2047927 : offset -= frame_phase;
1357 2051520 : align = known_alignment (offset);
1358 2051520 : align *= BITS_PER_UNIT;
1359 2051520 : if (align == 0 || align > base_align)
1360 833096 : align = base_align;
1361 :
1362 2051520 : if (TREE_CODE (decl) != SSA_NAME)
1363 : {
1364 : /* One would think that we could assert that we're not decreasing
1365 : alignment here, but (at least) the i386 port does exactly this
1366 : via the MINIMUM_ALIGNMENT hook. */
1367 :
1368 1586390 : SET_DECL_ALIGN (decl, align);
1369 1586390 : DECL_USER_ALIGN (decl) = 0;
1370 : }
1371 :
1372 2051520 : set_rtl (decl, x);
1373 :
1374 2051520 : set_mem_align (x, align);
1375 2051520 : }
1376 :
1377 238898 : class stack_vars_data
1378 : {
1379 : public:
1380 : /* Vector of offset pairs, always end of some padding followed
1381 : by start of the padding that needs Address Sanitizer protection.
1382 : The vector is in reversed, highest offset pairs come first. */
1383 : auto_vec<HOST_WIDE_INT> asan_vec;
1384 :
1385 : /* Vector of partition representative decls in between the paddings. */
1386 : auto_vec<tree> asan_decl_vec;
1387 :
1388 : /* Base pseudo register for Address Sanitizer protected automatic vars. */
1389 : rtx asan_base;
1390 :
1391 : /* Alignment needed for the Address Sanitizer protected automatic vars. */
1392 : unsigned int asan_alignb;
1393 : };
1394 :
1395 : /* A subroutine of expand_used_vars. Give each partition representative
1396 : a unique location within the stack frame. Update each partition member
1397 : with that location. */
1398 : static void
1399 241185 : expand_stack_vars (bool (*pred) (unsigned), class stack_vars_data *data)
1400 : {
1401 241185 : unsigned si, i, j, n = stack_vars_num;
1402 241185 : poly_uint64 large_size = 0, large_alloc = 0;
1403 241185 : rtx large_base = NULL;
1404 241185 : rtx large_untagged_base = NULL;
1405 241185 : unsigned large_align = 0;
1406 241185 : bool large_allocation_done = false;
1407 241185 : tree decl;
1408 :
1409 : /* Determine if there are any variables requiring "large" alignment.
1410 : Since these are dynamically allocated, we only process these if
1411 : no predicate involved. */
1412 241185 : large_align = stack_vars[stack_vars_sorted[0]].alignb * BITS_PER_UNIT;
1413 241185 : if (pred == NULL && large_align > MAX_SUPPORTED_STACK_ALIGNMENT)
1414 : {
1415 : /* Find the total size of these variables. */
1416 0 : for (si = 0; si < n; ++si)
1417 : {
1418 0 : unsigned alignb;
1419 :
1420 0 : i = stack_vars_sorted[si];
1421 0 : alignb = stack_vars[i].alignb;
1422 :
1423 : /* All "large" alignment decls come before all "small" alignment
1424 : decls, but "large" alignment decls are not sorted based on
1425 : their alignment. Increase large_align to track the largest
1426 : required alignment. */
1427 0 : if ((alignb * BITS_PER_UNIT) > large_align)
1428 : large_align = alignb * BITS_PER_UNIT;
1429 :
1430 : /* Stop when we get to the first decl with "small" alignment. */
1431 0 : if (alignb * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT)
1432 : break;
1433 :
1434 : /* Skip variables that aren't partition representatives. */
1435 0 : if (stack_vars[i].representative != i)
1436 0 : continue;
1437 :
1438 : /* Skip variables that have already had rtl assigned. See also
1439 : add_stack_var where we perpetrate this pc_rtx hack. */
1440 0 : decl = stack_vars[i].decl;
1441 0 : if (TREE_CODE (decl) == SSA_NAME
1442 0 : ? SA.partition_to_pseudo[var_to_partition (SA.map, decl)] != NULL_RTX
1443 0 : : DECL_RTL (decl) != pc_rtx)
1444 0 : continue;
1445 :
1446 0 : large_size = aligned_upper_bound (large_size, alignb);
1447 0 : large_size += stack_vars[i].size;
1448 : }
1449 : }
1450 :
1451 1472572 : for (si = 0; si < n; ++si)
1452 : {
1453 1231387 : rtx base;
1454 1231387 : unsigned base_align, alignb;
1455 1231387 : poly_int64 offset = 0;
1456 :
1457 1231387 : i = stack_vars_sorted[si];
1458 :
1459 : /* Skip variables that aren't partition representatives, for now. */
1460 1231387 : if (stack_vars[i].representative != i)
1461 275990 : continue;
1462 :
1463 : /* Skip variables that have already had rtl assigned. See also
1464 : add_stack_var where we perpetrate this pc_rtx hack. */
1465 955397 : decl = stack_vars[i].decl;
1466 955397 : if (TREE_CODE (decl) == SSA_NAME
1467 955397 : ? SA.partition_to_pseudo[var_to_partition (SA.map, decl)] != NULL_RTX
1468 951316 : : DECL_RTL (decl) != pc_rtx)
1469 3921 : continue;
1470 :
1471 : /* Check the predicate to see whether this variable should be
1472 : allocated in this pass. */
1473 951476 : if (pred && !pred (i))
1474 1311 : continue;
1475 :
1476 950165 : base = (hwassist_sanitize_stack_p ()
1477 950165 : ? hwasan_frame_base ()
1478 950109 : : virtual_stack_vars_rtx);
1479 950165 : alignb = stack_vars[i].alignb;
1480 950165 : if (alignb * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT)
1481 : {
1482 950165 : poly_int64 hwasan_orig_offset;
1483 950165 : if (hwassist_sanitize_stack_p ())
1484 : {
1485 : /* There must be no tag granule "shared" between different
1486 : objects. This means that no HWASAN_TAG_GRANULE_SIZE byte
1487 : chunk can have more than one object in it.
1488 :
1489 : We ensure this by forcing the end of the last bit of data to
1490 : be aligned to HWASAN_TAG_GRANULE_SIZE bytes here, and setting
1491 : the start of each variable to be aligned to
1492 : HWASAN_TAG_GRANULE_SIZE bytes in `align_local_variable`.
1493 :
1494 : We can't align just one of the start or end, since there are
1495 : untagged things stored on the stack which we do not align to
1496 : HWASAN_TAG_GRANULE_SIZE bytes. If we only aligned the start
1497 : or the end of tagged objects then untagged objects could end
1498 : up sharing the first granule of a tagged object or sharing the
1499 : last granule of a tagged object respectively. */
1500 56 : hwasan_orig_offset = align_frame_offset (HWASAN_TAG_GRANULE_SIZE);
1501 56 : gcc_assert (stack_vars[i].alignb >= HWASAN_TAG_GRANULE_SIZE);
1502 : }
1503 : /* ASAN description strings don't yet have a syntax for expressing
1504 : polynomial offsets. */
1505 950165 : HOST_WIDE_INT prev_offset;
1506 950165 : if (asan_sanitize_stack_p ()
1507 4607 : && pred
1508 3588 : && frame_offset.is_constant (&prev_offset)
1509 950165 : && stack_vars[i].size.is_constant ())
1510 : {
1511 3588 : if (data->asan_vec.is_empty ())
1512 : {
1513 1794 : align_frame_offset (ASAN_RED_ZONE_SIZE);
1514 1794 : prev_offset = frame_offset.to_constant ();
1515 : }
1516 3588 : prev_offset = align_base (prev_offset,
1517 : ASAN_MIN_RED_ZONE_SIZE,
1518 : !FRAME_GROWS_DOWNWARD);
1519 3588 : tree repr_decl = NULL_TREE;
1520 3588 : unsigned HOST_WIDE_INT size
1521 3588 : = asan_var_and_redzone_size (stack_vars[i].size.to_constant ());
1522 3588 : if (data->asan_vec.is_empty ())
1523 1794 : size = MAX (size, ASAN_RED_ZONE_SIZE);
1524 :
1525 3588 : unsigned HOST_WIDE_INT alignment = MAX (alignb,
1526 : ASAN_MIN_RED_ZONE_SIZE);
1527 3588 : offset = alloc_stack_frame_space (size, alignment);
1528 :
1529 3588 : data->asan_vec.safe_push (prev_offset);
1530 : /* Allocating a constant amount of space from a constant
1531 : starting offset must give a constant result. */
1532 3588 : data->asan_vec.safe_push ((offset + stack_vars[i].size)
1533 3588 : .to_constant ());
1534 : /* Find best representative of the partition.
1535 : Prefer those with DECL_NAME, even better
1536 : satisfying asan_protect_stack_decl predicate. */
1537 4181 : for (j = i; j != EOC; j = stack_vars[j].next)
1538 3592 : if (asan_protect_stack_decl (stack_vars[j].decl)
1539 3592 : && DECL_NAME (stack_vars[j].decl))
1540 : {
1541 2999 : repr_decl = stack_vars[j].decl;
1542 2999 : break;
1543 : }
1544 593 : else if (repr_decl == NULL_TREE
1545 593 : && DECL_P (stack_vars[j].decl)
1546 1186 : && DECL_NAME (stack_vars[j].decl))
1547 0 : repr_decl = stack_vars[j].decl;
1548 3588 : if (repr_decl == NULL_TREE)
1549 589 : repr_decl = stack_vars[i].decl;
1550 3588 : data->asan_decl_vec.safe_push (repr_decl);
1551 :
1552 : /* Make sure a representative is unpoison if another
1553 : variable in the partition is handled by
1554 : use-after-scope sanitization. */
1555 3588 : if (asan_handled_variables != NULL
1556 3588 : && !asan_handled_variables->contains (repr_decl))
1557 : {
1558 440 : for (j = i; j != EOC; j = stack_vars[j].next)
1559 222 : if (asan_handled_variables->contains (stack_vars[j].decl))
1560 : break;
1561 220 : if (j != EOC)
1562 2 : asan_handled_variables->add (repr_decl);
1563 : }
1564 :
1565 3588 : data->asan_alignb = MAX (data->asan_alignb, alignb);
1566 3588 : if (data->asan_base == NULL)
1567 1794 : data->asan_base = gen_reg_rtx (Pmode);
1568 3588 : base = data->asan_base;
1569 :
1570 3588 : if (!STRICT_ALIGNMENT)
1571 3588 : base_align = crtl->max_used_stack_slot_alignment;
1572 : else
1573 : base_align = MAX (crtl->max_used_stack_slot_alignment,
1574 : GET_MODE_ALIGNMENT (SImode)
1575 : << ASAN_SHADOW_SHIFT);
1576 : }
1577 : else
1578 : {
1579 946577 : offset = alloc_stack_frame_space (stack_vars[i].size, alignb);
1580 946577 : base_align = crtl->max_used_stack_slot_alignment;
1581 :
1582 946577 : if (hwassist_sanitize_stack_p ())
1583 : {
1584 : /* Align again since the point of this alignment is to handle
1585 : the "end" of the object (i.e. smallest address after the
1586 : stack object). For FRAME_GROWS_DOWNWARD that requires
1587 : aligning the stack before allocating, but for a frame that
1588 : grows upwards that requires aligning the stack after
1589 : allocation.
1590 :
1591 : Use `frame_offset` to record the offset value rather than
1592 : `offset` since the `frame_offset` describes the extent
1593 : allocated for this particular variable while `offset`
1594 : describes the address that this variable starts at. */
1595 56 : align_frame_offset (HWASAN_TAG_GRANULE_SIZE);
1596 56 : hwasan_record_stack_var (virtual_stack_vars_rtx, base,
1597 : hwasan_orig_offset, frame_offset);
1598 : }
1599 : }
1600 : }
1601 : else
1602 : {
1603 : /* Large alignment is only processed in the last pass. */
1604 0 : if (pred)
1605 0 : continue;
1606 :
1607 : /* If there were any variables requiring "large" alignment, allocate
1608 : space. */
1609 0 : if (maybe_ne (large_size, 0U) && ! large_allocation_done)
1610 : {
1611 0 : poly_int64 loffset;
1612 0 : rtx large_allocsize;
1613 :
1614 0 : large_allocsize = gen_int_mode (large_size, Pmode);
1615 0 : get_dynamic_stack_size (&large_allocsize, 0, large_align, NULL);
1616 0 : loffset = alloc_stack_frame_space
1617 0 : (rtx_to_poly_int64 (large_allocsize),
1618 0 : PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT);
1619 0 : large_base = get_dynamic_stack_base (loffset, large_align, base);
1620 0 : large_allocation_done = true;
1621 : }
1622 :
1623 0 : gcc_assert (large_base != NULL);
1624 0 : large_alloc = aligned_upper_bound (large_alloc, alignb);
1625 0 : offset = large_alloc;
1626 0 : large_alloc += stack_vars[i].size;
1627 0 : if (hwassist_sanitize_stack_p ())
1628 : {
1629 : /* An object with a large alignment requirement means that the
1630 : alignment requirement is greater than the required alignment
1631 : for tags. */
1632 0 : if (!large_untagged_base)
1633 0 : large_untagged_base
1634 0 : = targetm.memtag.untagged_pointer (large_base, NULL_RTX);
1635 : /* Ensure the end of the variable is also aligned correctly. */
1636 0 : poly_int64 align_again
1637 0 : = aligned_upper_bound (large_alloc, HWASAN_TAG_GRANULE_SIZE);
1638 : /* For large allocations we always allocate a chunk of space
1639 : (which is addressed by large_untagged_base/large_base) and
1640 : then use positive offsets from that. Hence the farthest
1641 : offset is `align_again` and the nearest offset from the base
1642 : is `offset`. */
1643 0 : hwasan_record_stack_var (large_untagged_base, large_base,
1644 : offset, align_again);
1645 : }
1646 :
1647 : base = large_base;
1648 : base_align = large_align;
1649 : }
1650 :
1651 : /* Create rtl for each variable based on their location within the
1652 : partition. */
1653 2176309 : for (j = i; j != EOC; j = stack_vars[j].next)
1654 : {
1655 1226144 : expand_one_stack_var_at (stack_vars[j].decl,
1656 : base, base_align, offset);
1657 : }
1658 950165 : if (hwassist_sanitize_stack_p ())
1659 56 : hwasan_increment_frame_tag ();
1660 : }
1661 :
1662 241185 : gcc_assert (known_eq (large_alloc, large_size));
1663 241185 : }
1664 :
1665 : /* Take into account all sizes of partitions and reset DECL_RTLs. */
1666 : static poly_uint64
1667 1097920 : account_stack_vars (void)
1668 : {
1669 1097920 : unsigned si, j, i, n = stack_vars_num;
1670 1097920 : poly_uint64 size = 0;
1671 :
1672 5754891 : for (si = 0; si < n; ++si)
1673 : {
1674 4656971 : i = stack_vars_sorted[si];
1675 :
1676 : /* Skip variables that aren't partition representatives, for now. */
1677 4656971 : if (stack_vars[i].representative != i)
1678 0 : continue;
1679 :
1680 9313942 : size += stack_vars[i].size;
1681 9313942 : for (j = i; j != EOC; j = stack_vars[j].next)
1682 4656971 : set_rtl (stack_vars[j].decl, NULL);
1683 : }
1684 1097920 : return size;
1685 : }
1686 :
1687 : /* Record the RTL assignment X for the default def of PARM. */
1688 :
1689 : extern void
1690 4805147 : set_parm_rtl (tree parm, rtx x)
1691 : {
1692 4805147 : gcc_assert (TREE_CODE (parm) == PARM_DECL
1693 : || TREE_CODE (parm) == RESULT_DECL);
1694 :
1695 4805147 : if (x && !MEM_P (x))
1696 : {
1697 3092276 : unsigned int align = MINIMUM_ALIGNMENT (TREE_TYPE (parm),
1698 : TYPE_MODE (TREE_TYPE (parm)),
1699 : TYPE_ALIGN (TREE_TYPE (parm)));
1700 :
1701 : /* If the variable alignment is very large we'll dynamically
1702 : allocate it, which means that in-frame portion is just a
1703 : pointer. ??? We've got a pseudo for sure here, do we
1704 : actually dynamically allocate its spilling area if needed?
1705 : ??? Isn't it a problem when Pmode alignment also exceeds
1706 : MAX_SUPPORTED_STACK_ALIGNMENT, as can happen on cris and lm32? */
1707 3092276 : if (align > MAX_SUPPORTED_STACK_ALIGNMENT)
1708 0 : align = GET_MODE_ALIGNMENT (Pmode);
1709 :
1710 3092276 : record_alignment_for_reg_var (align);
1711 : }
1712 :
1713 4805147 : tree ssa = ssa_default_def (cfun, parm);
1714 4805147 : if (!ssa)
1715 1097079 : return set_rtl (parm, x);
1716 :
1717 3708068 : int part = var_to_partition (SA.map, ssa);
1718 3708068 : gcc_assert (part != NO_PARTITION);
1719 :
1720 3708068 : bool changed = bitmap_bit_p (SA.partitions_for_parm_default_defs, part);
1721 3708068 : gcc_assert (changed);
1722 :
1723 3708068 : set_rtl (ssa, x);
1724 3708068 : gcc_assert (DECL_RTL (parm) == x);
1725 : }
1726 :
1727 : /* A subroutine of expand_one_var. Called to immediately assign rtl
1728 : to a variable to be allocated in the stack frame. */
1729 :
1730 : static void
1731 825376 : expand_one_stack_var_1 (tree var)
1732 : {
1733 825376 : poly_uint64 size;
1734 825376 : poly_int64 offset;
1735 825376 : unsigned byte_align;
1736 :
1737 825376 : if (TREE_CODE (var) == SSA_NAME)
1738 : {
1739 461834 : tree type = TREE_TYPE (var);
1740 461834 : size = tree_to_poly_uint64 (TYPE_SIZE_UNIT (type));
1741 : }
1742 : else
1743 363542 : size = tree_to_poly_uint64 (DECL_SIZE_UNIT (var));
1744 :
1745 825376 : byte_align = align_local_variable (var, true);
1746 :
1747 : /* We handle highly aligned variables in expand_stack_vars. */
1748 825376 : gcc_assert (byte_align * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT);
1749 :
1750 825376 : rtx base;
1751 825376 : if (hwassist_sanitize_stack_p ())
1752 : {
1753 : /* Allocate zero bytes to align the stack. */
1754 32 : poly_int64 hwasan_orig_offset
1755 32 : = align_frame_offset (HWASAN_TAG_GRANULE_SIZE);
1756 32 : offset = alloc_stack_frame_space (size, byte_align);
1757 32 : align_frame_offset (HWASAN_TAG_GRANULE_SIZE);
1758 32 : base = hwasan_frame_base ();
1759 : /* Use `frame_offset` to automatically account for machines where the
1760 : frame grows upwards.
1761 :
1762 : `offset` will always point to the "start" of the stack object, which
1763 : will be the smallest address, for ! FRAME_GROWS_DOWNWARD this is *not*
1764 : the "furthest" offset from the base delimiting the current stack
1765 : object. `frame_offset` will always delimit the extent that the frame.
1766 : */
1767 32 : hwasan_record_stack_var (virtual_stack_vars_rtx, base,
1768 : hwasan_orig_offset, frame_offset);
1769 : }
1770 : else
1771 : {
1772 825344 : offset = alloc_stack_frame_space (size, byte_align);
1773 825344 : base = virtual_stack_vars_rtx;
1774 : }
1775 :
1776 825376 : expand_one_stack_var_at (var, base,
1777 : crtl->max_used_stack_slot_alignment, offset);
1778 :
1779 825376 : if (hwassist_sanitize_stack_p ())
1780 32 : hwasan_increment_frame_tag ();
1781 825376 : }
1782 :
1783 : /* Wrapper for expand_one_stack_var_1 that checks SSA_NAMEs are
1784 : already assigned some MEM. */
1785 :
1786 : static void
1787 363542 : expand_one_stack_var (tree var)
1788 : {
1789 363542 : if (TREE_CODE (var) == SSA_NAME)
1790 : {
1791 0 : int part = var_to_partition (SA.map, var);
1792 0 : if (part != NO_PARTITION)
1793 : {
1794 0 : rtx x = SA.partition_to_pseudo[part];
1795 0 : gcc_assert (x);
1796 0 : gcc_assert (MEM_P (x));
1797 : return;
1798 : }
1799 : }
1800 :
1801 363542 : return expand_one_stack_var_1 (var);
1802 : }
1803 :
1804 : /* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL
1805 : that will reside in a hard register. */
1806 :
1807 : static void
1808 1113 : expand_one_hard_reg_var (tree var)
1809 : {
1810 0 : rest_of_decl_compilation (var, 0, 0);
1811 0 : }
1812 :
1813 : /* Record the alignment requirements of some variable assigned to a
1814 : pseudo. */
1815 :
1816 : static void
1817 42142121 : record_alignment_for_reg_var (unsigned int align)
1818 : {
1819 42142121 : if (SUPPORTS_STACK_ALIGNMENT
1820 42142121 : && crtl->stack_alignment_estimated < align)
1821 : {
1822 : /* stack_alignment_estimated shouldn't change after stack
1823 : realign decision made */
1824 1768174 : gcc_assert (!crtl->stack_realign_processed);
1825 1768174 : crtl->stack_alignment_estimated = align;
1826 : }
1827 :
1828 : /* stack_alignment_needed > PREFERRED_STACK_BOUNDARY is permitted.
1829 : So here we only make sure stack_alignment_needed >= align. */
1830 42142121 : if (crtl->stack_alignment_needed < align)
1831 569893 : crtl->stack_alignment_needed = align;
1832 42142121 : if (crtl->max_used_stack_slot_alignment < align)
1833 569893 : crtl->max_used_stack_slot_alignment = align;
1834 42142121 : }
1835 :
1836 : /* Create RTL for an SSA partition. */
1837 :
1838 : static void
1839 23274364 : expand_one_ssa_partition (tree var)
1840 : {
1841 23274364 : int part = var_to_partition (SA.map, var);
1842 23274364 : gcc_assert (part != NO_PARTITION);
1843 :
1844 23274364 : if (SA.partition_to_pseudo[part])
1845 : return;
1846 :
1847 23274364 : unsigned int align = MINIMUM_ALIGNMENT (TREE_TYPE (var),
1848 : TYPE_MODE (TREE_TYPE (var)),
1849 : TYPE_ALIGN (TREE_TYPE (var)));
1850 :
1851 : /* If the variable alignment is very large we'll dynamically allocate
1852 : it, which means that in-frame portion is just a pointer. */
1853 23274364 : if (align > MAX_SUPPORTED_STACK_ALIGNMENT)
1854 0 : align = GET_MODE_ALIGNMENT (Pmode);
1855 :
1856 23274364 : record_alignment_for_reg_var (align);
1857 :
1858 23274364 : if (!use_register_for_decl (var))
1859 : {
1860 465130 : if (defer_stack_allocation (var, true))
1861 3296 : add_stack_var (var, true);
1862 : else
1863 461834 : expand_one_stack_var_1 (var);
1864 : return;
1865 : }
1866 :
1867 22809234 : machine_mode reg_mode = promote_ssa_mode (var, NULL);
1868 22809234 : rtx x = gen_reg_rtx (reg_mode);
1869 :
1870 22809234 : set_rtl (var, x);
1871 :
1872 : /* For a promoted variable, X will not be used directly but wrapped in a
1873 : SUBREG with SUBREG_PROMOTED_VAR_P set, which means that the RTL land
1874 : will assume that its upper bits can be inferred from its lower bits.
1875 : Therefore, if X isn't initialized on every path from the entry, then
1876 : we must do it manually in order to fulfill the above assumption. */
1877 22809234 : if (reg_mode != TYPE_MODE (TREE_TYPE (var))
1878 22809234 : && bitmap_bit_p (SA.partitions_for_undefined_values, part))
1879 0 : emit_move_insn (x, CONST0_RTX (reg_mode));
1880 : }
1881 :
1882 : /* Record the association between the RTL generated for partition PART
1883 : and the underlying variable of the SSA_NAME VAR. */
1884 :
1885 : static void
1886 50642132 : adjust_one_expanded_partition_var (tree var)
1887 : {
1888 50642132 : if (!var)
1889 : return;
1890 :
1891 50642132 : tree decl = SSA_NAME_VAR (var);
1892 :
1893 50642132 : int part = var_to_partition (SA.map, var);
1894 50642132 : if (part == NO_PARTITION)
1895 : return;
1896 :
1897 32573731 : rtx x = SA.partition_to_pseudo[part];
1898 :
1899 32573731 : gcc_assert (x);
1900 :
1901 32573731 : set_rtl (var, x);
1902 :
1903 32573731 : if (!REG_P (x))
1904 : return;
1905 :
1906 : /* Note if the object is a user variable. */
1907 30485614 : if (decl && !DECL_ARTIFICIAL (decl))
1908 4226851 : mark_user_reg (x);
1909 :
1910 30485614 : if (POINTER_TYPE_P (decl ? TREE_TYPE (decl) : TREE_TYPE (var)))
1911 7752040 : mark_reg_pointer (x, get_pointer_alignment (var));
1912 : }
1913 :
1914 : /* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL
1915 : that will reside in a pseudo register. */
1916 :
1917 : static void
1918 588813 : expand_one_register_var (tree var)
1919 : {
1920 588813 : if (TREE_CODE (var) == SSA_NAME)
1921 : {
1922 0 : int part = var_to_partition (SA.map, var);
1923 0 : if (part != NO_PARTITION)
1924 : {
1925 0 : rtx x = SA.partition_to_pseudo[part];
1926 0 : gcc_assert (x);
1927 0 : gcc_assert (REG_P (x));
1928 : return;
1929 : }
1930 0 : gcc_unreachable ();
1931 : }
1932 :
1933 588813 : tree decl = var;
1934 588813 : tree type = TREE_TYPE (decl);
1935 588813 : machine_mode reg_mode = promote_decl_mode (decl, NULL);
1936 588813 : rtx x = gen_reg_rtx (reg_mode);
1937 :
1938 588813 : set_rtl (var, x);
1939 :
1940 : /* Note if the object is a user variable. */
1941 588813 : if (!DECL_ARTIFICIAL (decl))
1942 95049 : mark_user_reg (x);
1943 :
1944 588813 : if (POINTER_TYPE_P (type))
1945 100 : mark_reg_pointer (x, get_pointer_alignment (var));
1946 : }
1947 :
1948 : /* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL that
1949 : has some associated error, e.g. its type is error-mark. We just need
1950 : to pick something that won't crash the rest of the compiler. */
1951 :
1952 : static void
1953 33 : expand_one_error_var (tree var)
1954 : {
1955 33 : machine_mode mode = DECL_MODE (var);
1956 33 : rtx x;
1957 :
1958 33 : if (mode == BLKmode)
1959 1 : x = gen_rtx_MEM (BLKmode, const0_rtx);
1960 32 : else if (mode == VOIDmode)
1961 0 : x = const0_rtx;
1962 : else
1963 32 : x = gen_reg_rtx (mode);
1964 :
1965 33 : SET_DECL_RTL (var, x);
1966 33 : }
1967 :
1968 : /* A subroutine of expand_one_var. VAR is a variable that will be
1969 : allocated to the local stack frame. Return true if we wish to
1970 : add VAR to STACK_VARS so that it will be coalesced with other
1971 : variables. Return false to allocate VAR immediately.
1972 :
1973 : This function is used to reduce the number of variables considered
1974 : for coalescing, which reduces the size of the quadratic problem. */
1975 :
1976 : static bool
1977 6848464 : defer_stack_allocation (tree var, bool toplevel)
1978 : {
1979 6848464 : tree size_unit = TREE_CODE (var) == SSA_NAME
1980 6848464 : ? TYPE_SIZE_UNIT (TREE_TYPE (var))
1981 6848464 : : DECL_SIZE_UNIT (var);
1982 6848464 : poly_uint64 size;
1983 :
1984 : /* Whether the variable is small enough for immediate allocation not to be
1985 : a problem with regard to the frame size. */
1986 6848464 : bool smallish
1987 6848464 : = (poly_int_tree_p (size_unit, &size)
1988 6848464 : && (estimated_poly_value (size)
1989 6848464 : < param_min_size_for_stack_sharing));
1990 :
1991 : /* If stack protection is enabled, *all* stack variables must be deferred,
1992 : so that we can re-order the strings to the top of the frame.
1993 : Similarly for Address Sanitizer. */
1994 6848464 : if (flag_stack_protect || asan_sanitize_stack_p ())
1995 : return true;
1996 :
1997 : /* Use the same effective alignment that expand_one_stack_var_1 would use.
1998 : If that alignment exceeds MAX_SUPPORTED_STACK_ALIGNMENT, defer
1999 : the variable so that expand_stack_vars handles its large alignment,
2000 : rather than calling expand_one_stack_var_1 and failing its assertion. */
2001 6832501 : unsigned int align = align_local_variable (var, false) * BITS_PER_UNIT;
2002 :
2003 : /* We handle "large" alignment via dynamic allocation. We want to handle
2004 : this extra complication in only one place, so defer them. */
2005 6832501 : if (align > MAX_SUPPORTED_STACK_ALIGNMENT)
2006 : return true;
2007 :
2008 6832501 : bool ignored = TREE_CODE (var) == SSA_NAME
2009 6838968 : ? !SSAVAR (var) || DECL_IGNORED_P (SSA_NAME_VAR (var))
2010 6368159 : : DECL_IGNORED_P (var);
2011 :
2012 : /* When optimization is enabled, DECL_IGNORED_P variables originally scoped
2013 : might be detached from their block and appear at toplevel when we reach
2014 : here. We want to coalesce them with variables from other blocks when
2015 : the immediate contribution to the frame size would be noticeable. */
2016 6832501 : if (toplevel && optimize > 0 && ignored && !smallish)
2017 : return true;
2018 :
2019 : /* Variables declared in the outermost scope automatically conflict
2020 : with every other variable. The only reason to want to defer them
2021 : at all is that, after sorting, we can more efficiently pack
2022 : small variables in the stack frame. Continue to defer at -O2. */
2023 5277335 : if (toplevel && optimize < 2)
2024 : return false;
2025 :
2026 : /* Without optimization, *most* variables are allocated from the
2027 : stack, which makes the quadratic problem large exactly when we
2028 : want compilation to proceed as quickly as possible. On the
2029 : other hand, we don't want the function's stack frame size to
2030 : get completely out of hand. So we avoid adding scalars and
2031 : "small" aggregates to the list at all. */
2032 4613640 : if (optimize == 0 && smallish)
2033 49981 : return false;
2034 :
2035 : return true;
2036 : }
2037 :
2038 : /* A subroutine of expand_used_vars. Expand one variable according to
2039 : its flavor. Variables to be placed on the stack are not actually
2040 : expanded yet, merely recorded.
2041 : When REALLY_EXPAND is false, only add stack values to be allocated.
2042 : Return stack usage this variable is supposed to take.
2043 : */
2044 :
2045 : static poly_uint64
2046 16083378 : expand_one_var (tree var, bool toplevel, bool really_expand,
2047 : bitmap forced_stack_var = NULL)
2048 : {
2049 16083378 : unsigned int align = BITS_PER_UNIT;
2050 16083378 : tree origvar = var;
2051 :
2052 16083378 : var = SSAVAR (var);
2053 :
2054 16083378 : if (TREE_TYPE (var) != error_mark_node && VAR_P (var))
2055 : {
2056 16083378 : if (is_global_var (var))
2057 307897 : return 0;
2058 :
2059 : /* Because we don't know if VAR will be in register or on stack,
2060 : we conservatively assume it will be on stack even if VAR is
2061 : eventually put into register after RA pass. For non-automatic
2062 : variables, which won't be on stack, we collect alignment of
2063 : type and ignore user specified alignment. Similarly for
2064 : SSA_NAMEs for which use_register_for_decl returns true. */
2065 15775481 : if (TREE_STATIC (var)
2066 15775481 : || DECL_EXTERNAL (var)
2067 31550962 : || (TREE_CODE (origvar) == SSA_NAME && use_register_for_decl (var)))
2068 0 : align = MINIMUM_ALIGNMENT (TREE_TYPE (var),
2069 : TYPE_MODE (TREE_TYPE (var)),
2070 : TYPE_ALIGN (TREE_TYPE (var)));
2071 15775481 : else if (DECL_HAS_VALUE_EXPR_P (var)
2072 15775481 : || (DECL_RTL_SET_P (var) && MEM_P (DECL_RTL (var))))
2073 : /* Don't consider debug only variables with DECL_HAS_VALUE_EXPR_P set
2074 : or variables which were assigned a stack slot already by
2075 : expand_one_stack_var_at - in the latter case DECL_ALIGN has been
2076 : changed from the offset chosen to it. */
2077 17793 : align = crtl->stack_alignment_estimated;
2078 : else
2079 15757688 : align = MINIMUM_ALIGNMENT (var, DECL_MODE (var), DECL_ALIGN (var));
2080 :
2081 : /* If the variable alignment is very large we'll dynamically allocate
2082 : it, which means that in-frame portion is just a pointer. */
2083 15775481 : if (align > MAX_SUPPORTED_STACK_ALIGNMENT)
2084 0 : align = GET_MODE_ALIGNMENT (Pmode);
2085 : }
2086 :
2087 15775481 : record_alignment_for_reg_var (align);
2088 :
2089 15775481 : poly_uint64 size;
2090 15775481 : if (TREE_CODE (origvar) == SSA_NAME)
2091 : {
2092 0 : gcc_assert (!VAR_P (var)
2093 : || (!DECL_EXTERNAL (var)
2094 : && !DECL_HAS_VALUE_EXPR_P (var)
2095 : && !TREE_STATIC (var)
2096 : && TREE_TYPE (var) != error_mark_node
2097 : && !DECL_HARD_REGISTER (var)
2098 : && really_expand));
2099 : }
2100 15775481 : if (!VAR_P (var) && TREE_CODE (origvar) != SSA_NAME)
2101 : ;
2102 15775481 : else if (DECL_EXTERNAL (var))
2103 : ;
2104 15775481 : else if (DECL_HAS_VALUE_EXPR_P (var))
2105 : ;
2106 15757693 : else if (TREE_STATIC (var))
2107 : ;
2108 15757693 : else if (TREE_CODE (origvar) != SSA_NAME && DECL_RTL_SET_P (var))
2109 : ;
2110 15757688 : else if (TREE_TYPE (var) == error_mark_node)
2111 : {
2112 0 : if (really_expand)
2113 0 : expand_one_error_var (var);
2114 : }
2115 15757688 : else if (VAR_P (var) && DECL_HARD_REGISTER (var))
2116 : {
2117 4170 : if (really_expand)
2118 : {
2119 1113 : expand_one_hard_reg_var (var);
2120 1113 : if (!DECL_HARD_REGISTER (var))
2121 : /* Invalid register specification. */
2122 33 : expand_one_error_var (var);
2123 : }
2124 : }
2125 15753518 : else if (use_register_for_decl (var)
2126 15753518 : && (!forced_stack_var
2127 598255 : || !bitmap_bit_p (forced_stack_var, DECL_UID (var))))
2128 : {
2129 9370184 : if (really_expand)
2130 588813 : expand_one_register_var (origvar);
2131 : }
2132 6383334 : else if (!poly_int_tree_p (DECL_SIZE_UNIT (var), &size)
2133 6383334 : || !valid_constant_size_p (DECL_SIZE_UNIT (var)))
2134 : {
2135 : /* Reject variables which cover more than half of the address-space. */
2136 0 : if (really_expand)
2137 : {
2138 0 : if (DECL_NONLOCAL_FRAME (var))
2139 0 : error_at (DECL_SOURCE_LOCATION (current_function_decl),
2140 : "total size of local objects is too large");
2141 : else
2142 0 : error_at (DECL_SOURCE_LOCATION (var),
2143 : "size of variable %q+D is too large", var);
2144 0 : expand_one_error_var (var);
2145 : }
2146 : }
2147 6383334 : else if (defer_stack_allocation (var, toplevel))
2148 5879819 : add_stack_var (origvar, really_expand);
2149 : else
2150 : {
2151 503515 : if (really_expand)
2152 : {
2153 363233 : if (lookup_attribute ("naked",
2154 363233 : DECL_ATTRIBUTES (current_function_decl)))
2155 0 : error ("cannot allocate stack for variable %q+D, naked function",
2156 : var);
2157 :
2158 363233 : expand_one_stack_var (origvar);
2159 : }
2160 503515 : return size;
2161 : }
2162 15271966 : return 0;
2163 : }
2164 :
2165 : /* A subroutine of expand_used_vars. Walk down through the BLOCK tree
2166 : expanding variables. Those variables that can be put into registers
2167 : are allocated pseudos; those that can't are put on the stack.
2168 :
2169 : TOPLEVEL is true if this is the outermost BLOCK. */
2170 :
2171 : static void
2172 17212640 : expand_used_vars_for_block (tree block, bool toplevel, bitmap forced_stack_vars)
2173 : {
2174 17212640 : tree t;
2175 :
2176 : /* Expand all variables at this level. */
2177 37506130 : for (t = BLOCK_VARS (block); t ; t = DECL_CHAIN (t))
2178 20293490 : if (TREE_USED (t)
2179 20293490 : && ((!VAR_P (t) && TREE_CODE (t) != RESULT_DECL)
2180 785809 : || !DECL_NONSHAREABLE (t)))
2181 785809 : expand_one_var (t, toplevel, true, forced_stack_vars);
2182 :
2183 : /* Expand all variables at containing levels. */
2184 32893390 : for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t))
2185 15680750 : expand_used_vars_for_block (t, false, forced_stack_vars);
2186 17212640 : }
2187 :
2188 : /* A subroutine of expand_used_vars. Walk down through the BLOCK tree
2189 : and clear TREE_USED on all local variables. */
2190 :
2191 : static void
2192 17212640 : clear_tree_used (tree block)
2193 : {
2194 17212640 : tree t;
2195 :
2196 37506130 : for (t = BLOCK_VARS (block); t ; t = DECL_CHAIN (t))
2197 : /* if (!TREE_STATIC (t) && !DECL_EXTERNAL (t)) */
2198 1129792 : if ((!VAR_P (t) && TREE_CODE (t) != RESULT_DECL)
2199 20293490 : || !DECL_NONSHAREABLE (t))
2200 20293490 : TREE_USED (t) = 0;
2201 :
2202 32893390 : for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t))
2203 15680750 : clear_tree_used (t);
2204 17212640 : }
2205 :
2206 : /* Examine TYPE and determine a bit mask of the following features. */
2207 :
2208 : #define SPCT_HAS_LARGE_CHAR_ARRAY 1
2209 : #define SPCT_HAS_SMALL_CHAR_ARRAY 2
2210 : #define SPCT_HAS_ARRAY 4
2211 : #define SPCT_HAS_AGGREGATE 8
2212 :
2213 : static unsigned int
2214 2875 : stack_protect_classify_type (tree type)
2215 : {
2216 2875 : unsigned int ret = 0;
2217 2875 : tree t;
2218 :
2219 2875 : switch (TREE_CODE (type))
2220 : {
2221 747 : case ARRAY_TYPE:
2222 747 : t = strip_array_types (type);
2223 : /* Test INTEGER_TYPE, not INTEGRAL_TYPE_P: arrays of enums (such as
2224 : std::byte), booleans and _BitInt types are not character arrays. */
2225 747 : if (TREE_CODE (t) == INTEGER_TYPE
2226 747 : && TYPE_PRECISION (t) == TYPE_PRECISION (char_type_node))
2227 : {
2228 658 : unsigned HOST_WIDE_INT max = param_ssp_buffer_size;
2229 658 : unsigned HOST_WIDE_INT len;
2230 :
2231 658 : if (!TYPE_SIZE_UNIT (type)
2232 658 : || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type)))
2233 : len = max;
2234 : else
2235 658 : len = tree_to_uhwi (TYPE_SIZE_UNIT (type));
2236 :
2237 658 : if (len < max)
2238 : ret = SPCT_HAS_SMALL_CHAR_ARRAY | SPCT_HAS_ARRAY;
2239 : else
2240 618 : ret = SPCT_HAS_LARGE_CHAR_ARRAY | SPCT_HAS_ARRAY;
2241 : }
2242 : else
2243 89 : ret = SPCT_HAS_ARRAY | stack_protect_classify_type (t);
2244 : break;
2245 :
2246 1026 : case UNION_TYPE:
2247 1026 : case QUAL_UNION_TYPE:
2248 1026 : case RECORD_TYPE:
2249 1026 : ret = SPCT_HAS_AGGREGATE;
2250 10967 : for (t = TYPE_FIELDS (type); t ; t = TREE_CHAIN (t))
2251 9941 : if (TREE_CODE (t) == FIELD_DECL)
2252 1710 : ret |= stack_protect_classify_type (TREE_TYPE (t));
2253 : break;
2254 :
2255 : default:
2256 : break;
2257 : }
2258 :
2259 2875 : 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 1076 : stack_protect_decl_phase (tree decl)
2269 : {
2270 1076 : unsigned int bits = stack_protect_classify_type (TREE_TYPE (decl));
2271 1076 : int ret = 0;
2272 :
2273 1076 : if (bits & SPCT_HAS_SMALL_CHAR_ARRAY)
2274 36 : has_short_buffer = true;
2275 :
2276 1076 : tree attribs = DECL_ATTRIBUTES (current_function_decl);
2277 1076 : if (!lookup_attribute ("no_stack_protector", attribs)
2278 1076 : && (flag_stack_protect == SPCT_FLAG_ALL
2279 1076 : || flag_stack_protect == SPCT_FLAG_STRONG
2280 253 : || (flag_stack_protect == SPCT_FLAG_EXPLICIT
2281 5 : && lookup_attribute ("stack_protect", attribs))))
2282 : {
2283 828 : if ((bits & (SPCT_HAS_SMALL_CHAR_ARRAY | SPCT_HAS_LARGE_CHAR_ARRAY))
2284 472 : && !(bits & SPCT_HAS_AGGREGATE))
2285 : ret = 1;
2286 728 : else if (bits & SPCT_HAS_ARRAY)
2287 : ret = 2;
2288 : }
2289 : else
2290 248 : ret = (bits & SPCT_HAS_LARGE_CHAR_ARRAY) != 0;
2291 :
2292 248 : if (ret)
2293 710 : has_protected_decls = true;
2294 :
2295 1076 : 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 366 : stack_protect_decl_phase_1 (unsigned i)
2303 : {
2304 366 : return stack_protect_decl_phase (stack_vars[i].decl) == 1;
2305 : }
2306 :
2307 : static bool
2308 209 : stack_protect_decl_phase_2 (unsigned i)
2309 : {
2310 209 : 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 4522 : asan_decl_phase_3 (unsigned i)
2319 : {
2320 5541 : while (i != EOC)
2321 : {
2322 4522 : if (asan_protect_stack_decl (stack_vars[i].decl))
2323 : return true;
2324 1019 : 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 290 : add_stack_protection_conflicts (void)
2335 : {
2336 290 : unsigned i, j, n = stack_vars_num;
2337 290 : unsigned char *phase;
2338 290 : bool ret = false;
2339 :
2340 290 : phase = XNEWVEC (unsigned char, n);
2341 1081 : for (i = 0; i < n; ++i)
2342 : {
2343 501 : phase[i] = stack_protect_decl_phase (stack_vars[i].decl);
2344 501 : if (TREE_ADDRESSABLE (stack_vars[i].decl))
2345 424 : ret = true;
2346 : }
2347 :
2348 791 : for (i = 0; i < n; ++i)
2349 : {
2350 501 : unsigned char ph_i = phase[i];
2351 1217 : for (j = i + 1; j < n; ++j)
2352 716 : if (ph_i != phase[j])
2353 341 : add_stack_var_conflict (i, j);
2354 : }
2355 :
2356 290 : XDELETEVEC (phase);
2357 290 : return ret;
2358 : }
2359 :
2360 : /* Create a decl for the guard at the top of the stack frame. */
2361 :
2362 : static void
2363 309 : create_stack_guard (void)
2364 : {
2365 309 : tree guard = build_decl (DECL_SOURCE_LOCATION (current_function_decl),
2366 : VAR_DECL, NULL, ptr_type_node);
2367 309 : TREE_THIS_VOLATILE (guard) = 1;
2368 309 : TREE_USED (guard) = 1;
2369 309 : expand_one_stack_var (guard);
2370 309 : crtl->stack_protect_guard = guard;
2371 309 : }
2372 :
2373 : /* Prepare for expanding variables. */
2374 : static void
2375 8058768 : init_vars_expansion (void)
2376 : {
2377 : /* Conflict bitmaps, and a few related temporary bitmaps, go here. */
2378 8058768 : bitmap_obstack_initialize (&stack_var_bitmap_obstack);
2379 :
2380 : /* A map from decl to stack partition. */
2381 8058768 : decl_to_stack_part = new hash_map<tree, unsigned>;
2382 :
2383 : /* Initialize local stack smashing state. */
2384 8058768 : has_protected_decls = false;
2385 8058768 : has_short_buffer = false;
2386 8058768 : if (hwassist_sanitize_stack_p ())
2387 1198 : hwasan_record_frame_init ();
2388 8058768 : }
2389 :
2390 : /* Free up stack variable graph data. */
2391 : static void
2392 8058768 : fini_vars_expansion (void)
2393 : {
2394 8058768 : bitmap_obstack_release (&stack_var_bitmap_obstack);
2395 8058768 : if (stack_vars)
2396 1336818 : XDELETEVEC (stack_vars);
2397 8058768 : if (stack_vars_sorted)
2398 1336818 : XDELETEVEC (stack_vars_sorted);
2399 8058768 : stack_vars = NULL;
2400 8058768 : stack_vars_sorted = NULL;
2401 8058768 : stack_vars_alloc = stack_vars_num = 0;
2402 16117536 : delete decl_to_stack_part;
2403 8058768 : decl_to_stack_part = NULL;
2404 8058768 : }
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 6526878 : estimated_stack_frame_size (struct cgraph_node *node)
2416 : {
2417 6526878 : poly_int64 size = 0;
2418 6526878 : unsigned i;
2419 6526878 : tree var;
2420 6526878 : struct function *fn = DECL_STRUCT_FUNCTION (node->decl);
2421 :
2422 6526878 : push_cfun (fn);
2423 :
2424 6526878 : init_vars_expansion ();
2425 :
2426 26077191 : FOR_EACH_LOCAL_DECL (fn, i, var)
2427 14191124 : if (auto_var_in_fn_p (var, fn->decl))
2428 13581682 : size += expand_one_var (var, true, false);
2429 :
2430 6526878 : if (stack_vars_num > 0)
2431 : {
2432 : /* Fake sorting the stack vars for account_stack_vars (). */
2433 1097920 : stack_vars_sorted = XNEWVEC (unsigned , stack_vars_num);
2434 5754891 : for (i = 0; i < stack_vars_num; ++i)
2435 4656971 : stack_vars_sorted[i] = i;
2436 1097920 : size += account_stack_vars ();
2437 : }
2438 :
2439 6526878 : fini_vars_expansion ();
2440 6526878 : pop_cfun ();
2441 6526878 : 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 1531870 : verify_partition_mem_exprs (void)
2481 : {
2482 1531870 : hash_map<tree, rtx> slots;
2483 30046113 : for (unsigned i = 0; i < num_var_partitions (SA.map); i++)
2484 : {
2485 26982373 : rtx x = SA.partition_to_pseudo[i];
2486 28245338 : if (!x || !MEM_P (x) || !MEM_EXPR (x))
2487 25725605 : continue;
2488 1256768 : bool existed;
2489 1256768 : rtx &known = slots.get_or_insert (MEM_EXPR (x), &existed);
2490 1256768 : if (!existed)
2491 1256768 : known = x;
2492 : else
2493 0 : gcc_assert (rtx_equal_p (XEXP (known, 0), XEXP (x, 0)));
2494 : }
2495 1531870 : }
2496 :
2497 : /* Expand all variables used in the function. */
2498 :
2499 : static rtx_insn *
2500 1531890 : expand_used_vars (bitmap forced_stack_vars)
2501 : {
2502 1531890 : tree var, outer_block = DECL_INITIAL (current_function_decl);
2503 1531890 : auto_vec<tree> maybe_local_decls;
2504 1531890 : rtx_insn *var_end_seq = NULL;
2505 1531890 : unsigned i;
2506 1531890 : unsigned len;
2507 1531890 : bool gen_stack_protect_signal = false;
2508 :
2509 : /* Compute the phase of the stack frame for this function. */
2510 1531890 : {
2511 1531890 : int align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
2512 1531890 : int off = targetm.starting_frame_offset () % align;
2513 1531890 : frame_phase = off ? align - off : 0;
2514 : }
2515 :
2516 : /* Set TREE_USED on all variables in the local_decls. */
2517 12197203 : FOR_EACH_LOCAL_DECL (cfun, i, var)
2518 8098821 : TREE_USED (var) = 1;
2519 : /* Clear TREE_USED on all variables associated with a block scope. */
2520 1531890 : clear_tree_used (DECL_INITIAL (current_function_decl));
2521 :
2522 1531890 : init_vars_expansion ();
2523 :
2524 1531890 : if (targetm.use_pseudo_pic_reg ())
2525 80999 : pic_offset_table_rtx = gen_reg_rtx (Pmode);
2526 :
2527 28514322 : for (i = 0; i < SA.map->num_partitions; i++)
2528 : {
2529 26982432 : if (bitmap_bit_p (SA.partitions_for_parm_default_defs, i))
2530 3708068 : continue;
2531 :
2532 23274364 : tree var = partition_to_var (SA.map, i);
2533 :
2534 46548728 : gcc_assert (!virtual_operand_p (var));
2535 :
2536 23274364 : expand_one_ssa_partition (var);
2537 : }
2538 :
2539 1531890 : 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 1531890 : len = vec_safe_length (cfun->local_decls);
2546 10913957 : FOR_EACH_LOCAL_DECL (cfun, i, var)
2547 : {
2548 8098821 : bool expand_now = false;
2549 :
2550 : /* Expanded above already. */
2551 8098821 : if (is_gimple_reg (var))
2552 : {
2553 5685308 : TREE_USED (var) = 0;
2554 5685308 : 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 2413513 : 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 2193799 : else if (TREE_USED (var))
2570 1715887 : 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 2413513 : TREE_USED (var) = 1;
2575 :
2576 2413513 : if (expand_now)
2577 1715887 : expand_one_var (var, true, true, forced_stack_vars);
2578 :
2579 697626 : next:
2580 8098821 : if (DECL_ARTIFICIAL (var) && !DECL_IGNORED_P (var))
2581 : {
2582 446155 : rtx rtl = DECL_RTL_IF_SET (var);
2583 :
2584 : /* Keep artificial non-ignored vars in cfun->local_decls
2585 : chain until instantiate_decls. */
2586 337256 : if (rtl && (MEM_P (rtl) || GET_CODE (rtl) == CONCAT))
2587 23515 : add_local_decl (cfun, var);
2588 108899 : 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 108899 : 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 1531890 : if (!vec_safe_is_empty (cfun->local_decls))
2608 867481 : 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 1531890 : expand_used_vars_for_block (outer_block, true, forced_stack_vars);
2613 :
2614 1531890 : tree attribs = DECL_ATTRIBUTES (current_function_decl);
2615 1531890 : if (stack_vars_num > 0)
2616 : {
2617 238898 : bool has_addressable_vars = false;
2618 :
2619 238898 : add_scope_conflicts ();
2620 :
2621 : /* If stack protection is enabled, we don't share space between
2622 : vulnerable data and non-vulnerable data. */
2623 238898 : if (flag_stack_protect != 0
2624 290 : && !lookup_attribute ("no_stack_protector", attribs)
2625 239188 : && (flag_stack_protect != SPCT_FLAG_EXPLICIT
2626 : || (flag_stack_protect == SPCT_FLAG_EXPLICIT
2627 1 : && lookup_attribute ("stack_protect", attribs))))
2628 290 : has_addressable_vars = add_stack_protection_conflicts ();
2629 :
2630 238898 : if (flag_stack_protect == SPCT_FLAG_STRONG && has_addressable_vars)
2631 238898 : 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 238898 : partition_stack_vars ();
2636 238898 : if (dump_file)
2637 41 : dump_stack_var_partition ();
2638 : }
2639 :
2640 :
2641 1531890 : if (!lookup_attribute ("no_stack_protector", attribs))
2642 1531881 : switch (flag_stack_protect)
2643 : {
2644 53 : case SPCT_FLAG_ALL:
2645 53 : create_stack_guard ();
2646 53 : 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 197 : case SPCT_FLAG_DEFAULT:
2657 197 : if (cfun->calls_alloca
2658 194 : || has_protected_decls
2659 303 : || lookup_attribute ("stack_protect", attribs))
2660 91 : 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 1531890 : if (stack_vars_num > 0)
2674 : {
2675 238898 : class stack_vars_data data;
2676 :
2677 238898 : data.asan_base = NULL_RTX;
2678 238898 : 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 238898 : if (has_protected_decls)
2686 : {
2687 : /* Phase 1 contains only character arrays. */
2688 179 : expand_stack_vars (stack_protect_decl_phase_1, &data);
2689 :
2690 : /* Phase 2 contains other kinds of arrays. */
2691 179 : if (!lookup_attribute ("no_stack_protector", attribs)
2692 179 : && (flag_stack_protect == SPCT_FLAG_ALL
2693 179 : || flag_stack_protect == SPCT_FLAG_STRONG
2694 89 : || (flag_stack_protect == SPCT_FLAG_EXPLICIT
2695 1 : && lookup_attribute ("stack_protect", attribs))))
2696 91 : expand_stack_vars (stack_protect_decl_phase_2, &data);
2697 : }
2698 :
2699 238898 : if (asan_sanitize_stack_p ())
2700 : /* Phase 3, any partitions that need asan protection
2701 : in addition to phase 1 and 2. */
2702 2017 : 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 238898 : HOST_WIDE_INT prev_offset;
2707 240692 : if (!data.asan_vec.is_empty ()
2708 1794 : && frame_offset.is_constant (&prev_offset))
2709 : {
2710 1794 : HOST_WIDE_INT offset, sz, redzonesz;
2711 1794 : redzonesz = ASAN_RED_ZONE_SIZE;
2712 1794 : sz = data.asan_vec[0] - prev_offset;
2713 1794 : data.asan_alignb = MAX (data.asan_alignb,
2714 : crtl->stack_alignment_needed
2715 : / BITS_PER_UNIT);
2716 1794 : if (data.asan_alignb > ASAN_RED_ZONE_SIZE
2717 1794 : && 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 1794 : offset = (alloc_stack_frame_space (redzonesz, ASAN_RED_ZONE_SIZE)
2724 1794 : .to_constant ());
2725 1794 : data.asan_vec.safe_push (prev_offset);
2726 1794 : data.asan_vec.safe_push (offset);
2727 : /* Leave space for alignment if STRICT_ALIGNMENT. */
2728 1794 : if (STRICT_ALIGNMENT)
2729 : alloc_stack_frame_space ((GET_MODE_ALIGNMENT (SImode)
2730 : << ASAN_SHADOW_SHIFT)
2731 : / BITS_PER_UNIT, 1);
2732 :
2733 1794 : var_end_seq
2734 3588 : = 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 1794 : data.asan_vec.length ());
2740 : }
2741 :
2742 238898 : expand_stack_vars (NULL, &data);
2743 238898 : }
2744 :
2745 1531890 : if (hwassist_sanitize_stack_p ())
2746 454 : hwasan_emit_prologue ();
2747 1531890 : 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 3062970 : else if ((hwasan_sanitize_allocas_p () || memtag_sanitize_p ())
2752 1531712 : && 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 1531712 : 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 454 : var_end_seq = hwasan_emit_untag_frame (hwasan_get_frame_extent (),
2765 : virtual_stack_vars_rtx);
2766 :
2767 1531890 : 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 1730147 : FOR_EACH_VEC_ELT_REVERSE (maybe_local_decls, i, var)
2773 : {
2774 108899 : rtx rtl = DECL_RTL_IF_SET (var);
2775 :
2776 : /* Keep artificial non-ignored vars in cfun->local_decls
2777 : chain until instantiate_decls. */
2778 5171 : if (rtl && (MEM_P (rtl) || GET_CODE (rtl) == CONCAT))
2779 4915 : add_local_decl (cfun, var);
2780 : }
2781 :
2782 : /* If the target requires that FRAME_OFFSET be aligned, do it. */
2783 1531890 : if (STACK_ALIGNMENT_NEEDED)
2784 : {
2785 1531890 : HOST_WIDE_INT align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
2786 1531890 : if (FRAME_GROWS_DOWNWARD)
2787 1531890 : frame_offset = aligned_lower_bound (frame_offset, align);
2788 : else
2789 : frame_offset = aligned_upper_bound (frame_offset, align);
2790 : }
2791 :
2792 1531890 : return var_end_seq;
2793 1531890 : }
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 43406811 : maybe_dump_rtl_for_gimple_stmt (gimple *stmt, rtx_insn *since)
2802 : {
2803 43406811 : if (dump_file && (dump_flags & TDF_DETAILS))
2804 : {
2805 401 : fprintf (dump_file, "\n;; ");
2806 401 : print_gimple_stmt (dump_file, stmt, 0,
2807 : TDF_SLIM | (dump_flags & TDF_LINENO));
2808 401 : fprintf (dump_file, "\n");
2809 :
2810 401 : print_rtl (dump_file, since ? NEXT_INSN (since) : since);
2811 : }
2812 43406811 : }
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 7902473 : label_rtx_for_bb (basic_block bb)
2826 : {
2827 7902473 : if (bb->flags & BB_RTL)
2828 0 : return block_label (bb);
2829 :
2830 7902473 : if ((unsigned) bb->index < head_end_for_bb.length ()
2831 7902473 : && head_end_for_bb[bb->index].first)
2832 : {
2833 1614329 : if (!LABEL_P (head_end_for_bb[bb->index].first))
2834 : {
2835 982307 : head_end_for_bb[bb->index].first
2836 1964614 : = emit_label_before (gen_label_rtx (),
2837 982307 : head_end_for_bb[bb->index].first);
2838 : }
2839 1614329 : return as_a <rtx_code_label *> (head_end_for_bb[bb->index].first);
2840 : }
2841 :
2842 6288144 : rtx_code_label **elt = lab_rtx_for_bb->get (bb);
2843 6288144 : if (elt)
2844 1314385 : return *elt;
2845 :
2846 : /* Find the tree label if it is present. */
2847 4973759 : gimple_stmt_iterator gsi = gsi_start_bb (bb);
2848 4973759 : glabel *lab_stmt;
2849 4973759 : if (!gsi_end_p (gsi)
2850 4823680 : && (lab_stmt = dyn_cast <glabel *> (gsi_stmt (gsi)))
2851 5217268 : && !DECL_NONLOCAL (gimple_label_label (lab_stmt)))
2852 243509 : return jump_target_rtx (gimple_label_label (lab_stmt));
2853 :
2854 4730250 : rtx_code_label *l = gen_label_rtx ();
2855 4730250 : lab_rtx_for_bb->put (bb, l);
2856 4730250 : return l;
2857 : }
2858 :
2859 :
2860 : /* Wrapper around remove_edge during expansion. */
2861 :
2862 : void
2863 128658 : expand_remove_edge (edge e)
2864 : {
2865 128658 : if (current_ir_type () != IR_GIMPLE
2866 128658 : && (e->dest->flags & BB_RTL) == 0
2867 189416 : && !gimple_seq_empty_p (phi_nodes (e->dest)))
2868 9135 : remove_phi_args (e);
2869 128658 : remove_edge (e);
2870 128658 : }
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 1933225 : expand_split_edge (edge e, basic_block bb, int flags)
2878 : {
2879 1933225 : unsigned int dest_idx = e->dest_idx;
2880 1933225 : basic_block dest = e->dest;
2881 1933225 : redirect_edge_succ (e, bb);
2882 1933225 : e = make_single_succ_edge (bb, dest, flags);
2883 1933225 : if ((dest->flags & BB_RTL) == 0
2884 1933225 : && phi_nodes (dest)
2885 2073172 : && 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 86680 : edge e2 = EDGE_PRED (dest, dest_idx);
2891 86680 : std::swap (e->dest_idx, e2->dest_idx);
2892 86680 : std::swap (EDGE_PRED (dest, e->dest_idx),
2893 : EDGE_PRED (dest, e2->dest_idx));
2894 : }
2895 1933225 : }
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 5425646 : 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 5425646 : 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 5425646 : }
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 5826981 : expand_gimple_cond (basic_block bb, gcond *stmt)
2956 : {
2957 5826981 : basic_block new_bb, dest;
2958 5826981 : edge true_edge;
2959 5826981 : edge false_edge;
2960 5826981 : rtx_insn *last2, *last;
2961 5826981 : enum tree_code code;
2962 5826981 : tree op0, op1;
2963 :
2964 5826981 : code = gimple_cond_code (stmt);
2965 5826981 : op0 = gimple_cond_lhs (stmt);
2966 5826981 : 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 5826981 : if (SA.values
2976 4266177 : && TREE_CODE (op0) == SSA_NAME
2977 4265464 : && TREE_CODE (TREE_TYPE (op0)) == BOOLEAN_TYPE
2978 403218 : && TREE_CODE (op1) == INTEGER_CST
2979 392414 : && ((gimple_cond_code (stmt) == NE_EXPR
2980 392412 : && integer_zerop (op1))
2981 2 : || (gimple_cond_code (stmt) == EQ_EXPR
2982 2 : && integer_onep (op1)))
2983 6219395 : && bitmap_bit_p (SA.values, SSA_NAME_VERSION (op0)))
2984 : {
2985 215645 : gimple *second = SSA_NAME_DEF_STMT (op0);
2986 215645 : if (gimple_code (second) == GIMPLE_ASSIGN)
2987 : {
2988 215626 : enum tree_code code2 = gimple_assign_rhs_code (second);
2989 215626 : if (TREE_CODE_CLASS (code2) == tcc_comparison)
2990 : {
2991 1222 : code = code2;
2992 1222 : op0 = gimple_assign_rhs1 (second);
2993 1222 : 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 214404 : else if (BRANCH_COST (optimize_insn_for_speed_p (), false) < 4
2998 214404 : && !targetm.have_ccmp ())
2999 : {
3000 214401 : if ((code2 == BIT_AND_EXPR
3001 72498 : && TYPE_PRECISION (TREE_TYPE (op0)) == 1
3002 72498 : && TREE_CODE (gimple_assign_rhs2 (second)) != INTEGER_CST)
3003 214401 : || code2 == TRUTH_AND_EXPR)
3004 : {
3005 72498 : code = TRUTH_ANDIF_EXPR;
3006 72498 : op0 = gimple_assign_rhs1 (second);
3007 72498 : op1 = gimple_assign_rhs2 (second);
3008 : }
3009 141903 : else if (code2 == BIT_IOR_EXPR || code2 == TRUTH_OR_EXPR)
3010 : {
3011 62835 : code = TRUTH_ORIF_EXPR;
3012 62835 : op0 = gimple_assign_rhs1 (second);
3013 62835 : 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 5826981 : if ((code == EQ_EXPR || code == NE_EXPR)
3022 4560002 : && TREE_CODE (op0) == SSA_NAME
3023 4559234 : && TREE_CODE (op1) == INTEGER_CST)
3024 3161815 : code = maybe_optimize_mod_cmp (code, &op0, &op1);
3025 :
3026 : /* Optimize (x - y) < 0 into x < y if x - y has undefined overflow. */
3027 5826981 : if (!TYPE_UNSIGNED (TREE_TYPE (op0))
3028 2349157 : && (code == LT_EXPR || code == LE_EXPR
3029 2349157 : || code == GT_EXPR || code == GE_EXPR)
3030 703238 : && integer_zerop (op1)
3031 6034942 : && TREE_CODE (op0) == SSA_NAME)
3032 207961 : maybe_optimize_sub_cmp_0 (code, &op0, &op1);
3033 :
3034 5826981 : last2 = last = get_last_insn ();
3035 :
3036 5826981 : extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
3037 5826981 : 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 5826981 : if (false_edge->dest == bb->next_bb)
3042 : {
3043 2339756 : jumpif_1 (code, op0, op1, label_rtx_for_bb (true_edge->dest),
3044 : true_edge->probability);
3045 2339756 : maybe_dump_rtl_for_gimple_stmt (stmt, last);
3046 2339756 : if (true_edge->goto_locus != UNKNOWN_LOCATION)
3047 346268 : set_curr_insn_location (true_edge->goto_locus);
3048 2339756 : false_edge->flags |= EDGE_FALLTHRU;
3049 2339756 : maybe_cleanup_end_of_block (false_edge, last);
3050 2339756 : return NULL;
3051 : }
3052 3487225 : if (true_edge->dest == bb->next_bb)
3053 : {
3054 3085890 : jumpifnot_1 (code, op0, op1, label_rtx_for_bb (false_edge->dest),
3055 : false_edge->probability);
3056 3085890 : maybe_dump_rtl_for_gimple_stmt (stmt, last);
3057 3085890 : if (false_edge->goto_locus != UNKNOWN_LOCATION)
3058 25137 : set_curr_insn_location (false_edge->goto_locus);
3059 3085890 : true_edge->flags |= EDGE_FALLTHRU;
3060 3085890 : maybe_cleanup_end_of_block (true_edge, last);
3061 3085890 : return NULL;
3062 : }
3063 :
3064 401335 : jumpif_1 (code, op0, op1, label_rtx_for_bb (true_edge->dest),
3065 : true_edge->probability);
3066 401335 : last = get_last_insn ();
3067 401335 : if (false_edge->goto_locus != UNKNOWN_LOCATION)
3068 1331 : set_curr_insn_location (false_edge->goto_locus);
3069 401335 : emit_jump (label_rtx_for_bb (false_edge->dest));
3070 :
3071 401335 : head_end_for_bb[bb->index].second = last;
3072 401335 : if (BARRIER_P (head_end_for_bb[bb->index].second))
3073 118 : head_end_for_bb[bb->index].second
3074 59 : = PREV_INSN (head_end_for_bb[bb->index].second);
3075 802670 : update_bb_for_insn_chain (head_end_for_bb[bb->index].first,
3076 401335 : head_end_for_bb[bb->index].second, bb);
3077 :
3078 401335 : new_bb = create_basic_block (NEXT_INSN (last), get_last_insn (), bb);
3079 401335 : dest = false_edge->dest;
3080 401335 : expand_split_edge (false_edge, new_bb, 0);
3081 401335 : false_edge->flags |= EDGE_FALLTHRU;
3082 401335 : new_bb->count = false_edge->count ();
3083 401335 : loop_p loop = find_common_loop (bb->loop_father, dest->loop_father);
3084 401335 : add_bb_to_loop (new_bb, loop);
3085 401335 : if (loop->latch == bb
3086 28401 : && loop->header == dest)
3087 28392 : loop->latch = new_bb;
3088 401335 : if (BARRIER_P (BB_END (new_bb)))
3089 401335 : BB_END (new_bb) = PREV_INSN (BB_END (new_bb));
3090 401335 : update_bb_for_insn (new_bb);
3091 :
3092 401335 : maybe_dump_rtl_for_gimple_stmt (stmt, last2);
3093 :
3094 401335 : if (true_edge->goto_locus != UNKNOWN_LOCATION)
3095 : {
3096 45646 : set_curr_insn_location (true_edge->goto_locus);
3097 45646 : 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 6869959 : mark_transaction_restart_calls (gimple *stmt)
3107 : {
3108 6869959 : struct tm_restart_node dummy;
3109 6869959 : tm_restart_node **slot;
3110 :
3111 6869959 : if (!cfun->gimple_df->tm_restart)
3112 6866975 : 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 7106670 : expand_call_stmt (gcall *stmt)
3140 : {
3141 7106670 : tree exp, decl, lhs;
3142 7106670 : bool builtin_p;
3143 7106670 : size_t i;
3144 :
3145 7106670 : if (gimple_call_internal_p (stmt))
3146 : {
3147 201688 : expand_internal_call (stmt);
3148 201688 : 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 6904982 : decl = gimple_call_fndecl (stmt);
3155 6904982 : if (gimple_call_lhs (stmt)
3156 2429038 : && !gimple_has_side_effects (stmt)
3157 7617312 : && (optimize || (decl && called_as_built_in (decl))))
3158 : {
3159 691326 : internal_fn ifn = replacement_internal_fn (stmt);
3160 691326 : if (ifn != IFN_LAST)
3161 : {
3162 35021 : expand_internal_call (ifn, stmt);
3163 35021 : return;
3164 : }
3165 : }
3166 :
3167 6869961 : exp = build_vl_exp (CALL_EXPR, gimple_call_num_args (stmt) + 3);
3168 :
3169 6869961 : CALL_EXPR_FN (exp) = gimple_call_fn (stmt);
3170 6869961 : 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 4821994 : if (!builtin_p)
3175 9643988 : CALL_EXPR_FN (exp)
3176 14465982 : = fold_convert (build_pointer_type (gimple_call_fntype (stmt)),
3177 : CALL_EXPR_FN (exp));
3178 :
3179 6869961 : TREE_TYPE (exp) = gimple_call_return_type (stmt);
3180 6869961 : CALL_EXPR_STATIC_CHAIN (exp) = gimple_call_chain (stmt);
3181 :
3182 20707944 : for (i = 0; i < gimple_call_num_args (stmt); i++)
3183 : {
3184 13837983 : tree arg = gimple_call_arg (stmt, i);
3185 13837983 : 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 13837983 : if (builtin_p
3189 4257453 : && TREE_CODE (arg) == SSA_NAME
3190 1451478 : && (def = get_gimple_for_ssa_name (arg))
3191 357051 : && is_gimple_assign (def)
3192 14194873 : && gimple_assign_rhs_code (def) == ADDR_EXPR)
3193 15028 : arg = gimple_assign_rhs1 (def);
3194 13837983 : CALL_EXPR_ARG (exp, i) = arg;
3195 : }
3196 :
3197 6869961 : 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 6869961 : || stmt_could_throw_p (cfun, stmt))
3201 6194627 : TREE_SIDE_EFFECTS (exp) = 1;
3202 :
3203 6869961 : if (gimple_call_nothrow_p (stmt))
3204 3075410 : TREE_NOTHROW (exp) = 1;
3205 :
3206 6869961 : CALL_EXPR_TAILCALL (exp) = gimple_call_tail_p (stmt);
3207 6869961 : CALL_EXPR_MUST_TAIL_CALL (exp) = gimple_call_must_tail_p (stmt);
3208 6869961 : CALL_EXPR_RETURN_SLOT_OPT (exp) = gimple_call_return_slot_opt_p (stmt);
3209 6869961 : if (decl
3210 6681968 : && fndecl_built_in_p (decl, BUILT_IN_NORMAL)
3211 8740137 : && ALLOCA_FUNCTION_CODE_P (DECL_FUNCTION_CODE (decl)))
3212 28032 : CALL_ALLOCA_FOR_VAR_P (exp) = gimple_call_alloca_for_var_p (stmt);
3213 : else
3214 6841929 : CALL_FROM_THUNK_P (exp) = gimple_call_from_thunk_p (stmt);
3215 6869961 : CALL_EXPR_VA_ARG_PACK (exp) = gimple_call_va_arg_pack_p (stmt);
3216 6869961 : CALL_EXPR_BY_DESCRIPTOR (exp) = gimple_call_by_descriptor_p (stmt);
3217 6869961 : SET_EXPR_LOCATION (exp, gimple_location (stmt));
3218 :
3219 : /* Must come after copying location. */
3220 6869961 : copy_warning (exp, stmt);
3221 :
3222 : /* Ensure RTL is created for debug args. */
3223 13551929 : if (decl && DECL_HAS_DEBUG_ARGS_P (decl))
3224 : {
3225 68312 : vec<tree, va_gc> **debug_args = decl_debug_args_lookup (decl);
3226 68312 : unsigned int ix;
3227 68312 : tree dtemp;
3228 :
3229 68312 : if (debug_args)
3230 149813 : for (ix = 1; (*debug_args)->iterate (ix, &dtemp); ix += 2)
3231 : {
3232 81501 : gcc_assert (TREE_CODE (dtemp) == DEBUG_EXPR_DECL);
3233 81501 : expand_debug_expr (dtemp);
3234 : }
3235 : }
3236 :
3237 6869961 : rtx_insn *before_call = get_last_insn ();
3238 6869961 : lhs = gimple_call_lhs (stmt);
3239 6869961 : if (lhs)
3240 2394017 : expand_assignment (lhs, exp, false);
3241 : else
3242 4475944 : 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 6869959 : if (gimple_call_nocf_check_p (stmt)
3248 6869980 : && !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 6869959 : 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 2912 : expand_asm_loc (tree string, int vol, location_t locus)
3270 : {
3271 2912 : rtx body;
3272 :
3273 2912 : body = gen_rtx_ASM_INPUT_loc (VOIDmode,
3274 : ggc_strdup (TREE_STRING_POINTER (string)),
3275 : locus);
3276 :
3277 2912 : MEM_VOLATILE_P (body) = vol;
3278 :
3279 : /* Non-empty basic ASM implicitly clobbers memory. */
3280 2912 : if (TREE_STRING_LENGTH (string) != 0)
3281 : {
3282 894 : rtx asm_op, clob;
3283 894 : unsigned i, nclobbers;
3284 894 : auto_vec<rtx> input_rvec, output_rvec;
3285 894 : auto_vec<machine_mode> input_mode;
3286 894 : auto_vec<const char *> constraints;
3287 894 : auto_vec<rtx> use_rvec;
3288 894 : auto_vec<rtx> clobber_rvec;
3289 894 : HARD_REG_SET clobbered_regs;
3290 894 : CLEAR_HARD_REG_SET (clobbered_regs);
3291 :
3292 894 : clob = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode));
3293 894 : clobber_rvec.safe_push (clob);
3294 :
3295 894 : if (targetm.md_asm_adjust)
3296 894 : targetm.md_asm_adjust (output_rvec, input_rvec, input_mode,
3297 : constraints, use_rvec, clobber_rvec,
3298 : clobbered_regs, locus);
3299 :
3300 894 : asm_op = body;
3301 894 : nclobbers = clobber_rvec.length ();
3302 894 : auto nuses = use_rvec.length ();
3303 894 : body = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (1 + nuses + nclobbers));
3304 :
3305 894 : i = 0;
3306 894 : XVECEXP (body, 0, i++) = asm_op;
3307 894 : for (rtx use : use_rvec)
3308 0 : XVECEXP (body, 0, i++) = gen_rtx_USE (VOIDmode, use);
3309 4470 : for (rtx clobber : clobber_rvec)
3310 1788 : XVECEXP (body, 0, i++) = gen_rtx_CLOBBER (VOIDmode, clobber);
3311 894 : }
3312 :
3313 2912 : emit_insn (body);
3314 2912 : }
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 140390 : 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 140390 : tree overlap = tree_overlaps_hard_reg_set (t, clobbered_regs);
3327 :
3328 140390 : 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 41660 : asm_clobber_reg_is_valid (int regno, int nregs, const char *regname)
3348 : {
3349 41660 : bool is_valid = true;
3350 41660 : HARD_REG_SET regset;
3351 :
3352 41660 : CLEAR_HARD_REG_SET (regset);
3353 :
3354 41660 : add_range_to_hard_reg_set (®set, regno, nregs);
3355 :
3356 : /* Clobbering the PIC register is an error. */
3357 41660 : 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 41660 : else if (!in_hard_reg_set_p
3365 41660 : (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 41680 : 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 41660 : 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 97092 : expand_asm_stmt (gasm *stmt)
3413 : {
3414 97092 : class save_input_location
3415 : {
3416 : location_t old;
3417 :
3418 : public:
3419 94180 : explicit save_input_location(location_t where)
3420 : {
3421 94180 : old = input_location;
3422 94180 : input_location = where;
3423 : }
3424 :
3425 94180 : ~save_input_location()
3426 : {
3427 94180 : input_location = old;
3428 5 : }
3429 : };
3430 :
3431 97092 : location_t locus = gimple_location (stmt);
3432 :
3433 97092 : if (gimple_asm_basic_p (stmt))
3434 : {
3435 2912 : const char *s = gimple_asm_string (stmt);
3436 2912 : tree string = build_string (strlen (s), s);
3437 2912 : expand_asm_loc (string, gimple_asm_volatile_p (stmt), locus);
3438 5829 : return;
3439 : }
3440 :
3441 : /* There are some legacy diagnostics in here. */
3442 94180 : save_input_location s_i_l(locus);
3443 :
3444 94180 : unsigned noutputs = gimple_asm_noutputs (stmt);
3445 94180 : unsigned ninputs = gimple_asm_ninputs (stmt);
3446 94180 : unsigned nlabels = gimple_asm_nlabels (stmt);
3447 94180 : unsigned i;
3448 94180 : bool error_seen = false;
3449 :
3450 : /* ??? Diagnose during gimplification? */
3451 94180 : 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 94175 : auto_vec<tree, MAX_RECOG_OPERANDS> output_tvec;
3458 94175 : auto_vec<tree, MAX_RECOG_OPERANDS> input_tvec;
3459 94175 : auto_vec<const char *, MAX_RECOG_OPERANDS> constraints;
3460 :
3461 : /* Copy the gimple vectors into new vectors that we can manipulate. */
3462 :
3463 94175 : output_tvec.safe_grow (noutputs, true);
3464 94175 : input_tvec.safe_grow (ninputs, true);
3465 94175 : constraints.safe_grow (noutputs + ninputs, true);
3466 :
3467 269423 : for (i = 0; i < noutputs; ++i)
3468 : {
3469 81073 : tree t = gimple_asm_output_op (stmt, i);
3470 81073 : output_tvec[i] = TREE_VALUE (t);
3471 81073 : constraints[i] = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
3472 : }
3473 153496 : for (i = 0; i < ninputs; i++)
3474 : {
3475 59321 : tree t = gimple_asm_input_op (stmt, i);
3476 59321 : input_tvec[i] = TREE_VALUE (t);
3477 59321 : constraints[i + noutputs]
3478 59321 : = 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 94175 : auto_vec<rtx> clobber_rvec;
3484 94175 : HARD_REG_SET clobbered_regs;
3485 94175 : CLEAR_HARD_REG_SET (clobbered_regs);
3486 :
3487 94175 : if (unsigned n = gimple_asm_nclobbers (stmt))
3488 : {
3489 54577 : clobber_rvec.reserve (n);
3490 191484 : for (i = 0; i < n; i++)
3491 : {
3492 82330 : tree t = gimple_asm_clobber_op (stmt, i);
3493 82330 : const char *regname = TREE_STRING_POINTER (TREE_VALUE (t));
3494 82330 : int nregs, j;
3495 :
3496 82330 : j = decode_reg_name_and_count (regname, &nregs);
3497 82330 : if (j < 0)
3498 : {
3499 40670 : 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 40655 : else if (j == -4)
3507 : {
3508 40276 : rtx x = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode));
3509 40276 : clobber_rvec.safe_push (x);
3510 : }
3511 379 : 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 377 : gcc_assert (j == -1 || j == -3);
3522 : }
3523 : }
3524 : else
3525 83320 : for (int reg = j; reg < j + nregs; reg++)
3526 : {
3527 41660 : if (!asm_clobber_reg_is_valid (reg, nregs, regname))
3528 0 : return;
3529 :
3530 41660 : SET_HARD_REG_BIT (clobbered_regs, reg);
3531 41660 : rtx x = gen_rtx_REG (reg_raw_mode[reg], reg);
3532 41660 : 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 175248 : for (i = 0; i < noutputs; ++i)
3542 : {
3543 81073 : tree val = output_tvec[i];
3544 81073 : tree type = TREE_TYPE (val);
3545 81073 : const char *constraint;
3546 81073 : bool is_inout;
3547 81073 : bool allows_reg;
3548 81073 : bool allows_mem;
3549 :
3550 : /* Try to parse the output constraint. If that fails, there's
3551 : no point in going further. */
3552 81073 : constraint = constraints[i];
3553 81073 : 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 81073 : if (DECL_P (val)
3561 7898 : && REG_P (DECL_RTL (val))
3562 82037 : && HARD_REGISTER_P (DECL_RTL (val)))
3563 : {
3564 944 : unsigned j, output_hregno = REGNO (DECL_RTL (val));
3565 944 : bool early_clobber_p = strchr (constraints[i], '&') != NULL;
3566 944 : unsigned long match;
3567 :
3568 : /* Verify the other outputs do not use the same hard register. */
3569 1104 : 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 1861 : for (j = 0; j < ninputs; ++j)
3584 917 : if (DECL_P (input_tvec[j])
3585 778 : && REG_P (DECL_RTL (input_tvec[j]))
3586 1695 : && HARD_REGISTER_P (DECL_RTL (input_tvec[j])))
3587 : {
3588 778 : unsigned input_hregno = REGNO (DECL_RTL (input_tvec[j]));
3589 778 : switch (*constraints[j + noutputs])
3590 : {
3591 767 : case '0': case '1': case '2': case '3': case '4':
3592 767 : case '5': case '6': case '7': case '8': case '9':
3593 767 : match = strtoul (constraints[j + noutputs], NULL, 10);
3594 767 : break;
3595 : default:
3596 : match = ULONG_MAX;
3597 : break;
3598 : }
3599 767 : if (i == match
3600 667 : && 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 777 : 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 81073 : if (! allows_reg
3618 81073 : && (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 8351 : mark_addressable (val);
3624 : }
3625 :
3626 153496 : for (i = 0; i < ninputs; ++i)
3627 : {
3628 59321 : bool allows_reg, allows_mem;
3629 59321 : const char *constraint;
3630 :
3631 59321 : constraint = constraints[i + noutputs];
3632 59321 : if (! parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
3633 59321 : constraints.address (), &allows_mem,
3634 : &allows_reg, nullptr))
3635 0 : return;
3636 :
3637 59321 : if (! allows_reg && allows_mem)
3638 9040 : mark_addressable (input_tvec[i]);
3639 : }
3640 :
3641 : /* Second pass evaluates arguments. */
3642 :
3643 : /* Make sure stack is consistent for asm goto. */
3644 94175 : if (nlabels > 0)
3645 635 : do_pending_stack_adjust ();
3646 94175 : int old_generating_concat_p = generating_concat_p;
3647 :
3648 : /* Vector of RTX's of evaluated output operands. */
3649 188350 : auto_vec<rtx, MAX_RECOG_OPERANDS> output_rvec;
3650 94175 : auto_vec<int, MAX_RECOG_OPERANDS> inout_opnum;
3651 94175 : rtx_insn *after_rtl_seq = NULL, *after_rtl_end = NULL;
3652 :
3653 94175 : output_rvec.safe_grow (noutputs, true);
3654 :
3655 269423 : for (i = 0; i < noutputs; ++i)
3656 : {
3657 81073 : tree val = output_tvec[i];
3658 81073 : tree type = TREE_TYPE (val);
3659 81073 : bool is_inout, allows_reg, allows_mem, ok;
3660 81073 : rtx op;
3661 :
3662 81073 : ok = parse_output_constraint (&constraints[i], i, ninputs,
3663 : noutputs, &allows_mem, &allows_reg,
3664 : &is_inout, nullptr);
3665 81073 : 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 81073 : generating_concat_p = 0;
3673 :
3674 81073 : gcc_assert (TREE_CODE (val) != INDIRECT_REF);
3675 81073 : if (((TREE_CODE (val) == MEM_REF
3676 4150 : && TREE_CODE (TREE_OPERAND (val, 0)) != ADDR_EXPR)
3677 4033 : && allows_mem)
3678 78936 : || (DECL_P (val)
3679 7898 : && (allows_mem || REG_P (DECL_RTL (val)))
3680 8148 : && ! (REG_P (DECL_RTL (val))
3681 964 : && GET_MODE (DECL_RTL (val)) != TYPE_MODE (type)))
3682 71752 : || ! allows_reg
3683 71541 : || is_inout
3684 71541 : || TREE_ADDRESSABLE (type)
3685 152614 : || (!tree_fits_poly_int64_p (TYPE_SIZE (type))
3686 0 : && !known_size_p (max_int_size_in_bytes (type))))
3687 : {
3688 9532 : op = expand_expr (val, NULL_RTX, VOIDmode,
3689 : !allows_reg ? EXPAND_MEMORY : EXPAND_WRITE);
3690 9532 : if (MEM_P (op))
3691 8568 : op = validize_mem (op);
3692 :
3693 9532 : 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 9532 : if ((! allows_mem && MEM_P (op) && GET_MODE (op) != BLKmode)
3699 9532 : || 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 71541 : op = assign_temp (type, 0, 1);
3719 71541 : op = validize_mem (op);
3720 71541 : if (!MEM_P (op) && TREE_CODE (val) == SSA_NAME)
3721 68166 : set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (val), op);
3722 :
3723 71541 : generating_concat_p = old_generating_concat_p;
3724 :
3725 71541 : push_to_sequence2 (after_rtl_seq, after_rtl_end);
3726 71541 : expand_assignment (val, make_tree (type, op), false);
3727 71541 : after_rtl_seq = get_insns ();
3728 71541 : after_rtl_end = get_last_insn ();
3729 71541 : end_sequence ();
3730 : }
3731 81073 : output_rvec[i] = op;
3732 :
3733 81073 : if (is_inout)
3734 0 : inout_opnum.safe_push (i);
3735 : }
3736 :
3737 94175 : const char *str = gimple_asm_string (stmt);
3738 94175 : 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 188350 : auto_vec<rtx, MAX_RECOG_OPERANDS> input_rvec;
3751 94175 : auto_vec<machine_mode, MAX_RECOG_OPERANDS> input_mode;
3752 :
3753 94175 : input_rvec.safe_grow (ninputs, true);
3754 94175 : input_mode.safe_grow (ninputs, true);
3755 :
3756 94175 : generating_concat_p = 0;
3757 :
3758 153495 : for (i = 0; i < ninputs; ++i)
3759 : {
3760 59320 : tree val = input_tvec[i];
3761 59320 : tree type = TREE_TYPE (val);
3762 59320 : bool allows_reg, allows_mem, ok;
3763 59320 : const char *constraint;
3764 59320 : rtx op;
3765 :
3766 59320 : constraint = constraints[i + noutputs];
3767 59320 : ok = parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
3768 59320 : constraints.address (),
3769 : &allows_mem, &allows_reg, nullptr);
3770 59320 : 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 59320 : op = expand_expr (val, NULL_RTX, VOIDmode,
3776 : allows_reg ? EXPAND_NORMAL
3777 10753 : : allows_mem ? EXPAND_MEMORY
3778 : : EXPAND_INITIALIZER);
3779 :
3780 : /* Never pass a CONCAT to an ASM. */
3781 59320 : if (GET_CODE (op) == CONCAT)
3782 2 : op = force_reg (GET_MODE (op), op);
3783 59318 : else if (MEM_P (op))
3784 : {
3785 14258 : op = validize_mem (op);
3786 14258 : MEM_NOTRAP_P (op) = !tree_could_trap_p (val);
3787 : }
3788 :
3789 59320 : if (asm_operand_ok (op, constraint, NULL) <= 0)
3790 : {
3791 26484 : if (allows_reg && TYPE_MODE (type) != BLKmode)
3792 26463 : 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 59320 : input_rvec[i] = op;
3806 59320 : input_mode[i] = TYPE_MODE (type);
3807 : }
3808 :
3809 : /* For in-out operands, copy output rtx to input rtx. */
3810 94175 : unsigned ninout = inout_opnum.length ();
3811 94175 : 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 94175 : 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 188350 : auto_vec<rtx> use_rvec;
3830 94175 : if (targetm.md_asm_adjust)
3831 : {
3832 94175 : rtx_insn *after_md_seq
3833 94175 : = targetm.md_asm_adjust (output_rvec, input_rvec, input_mode,
3834 : constraints, use_rvec, clobber_rvec,
3835 : clobbered_regs, locus);
3836 94175 : 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 188350 : gcc_assert (output_rvec.length() == noutputs);
3849 188350 : gcc_assert (input_rvec.length() == ninputs);
3850 188350 : gcc_assert (constraints.length() == noutputs + ninputs);
3851 :
3852 : /* But it certainly can adjust the uses and clobbers. */
3853 94175 : unsigned nuses = use_rvec.length ();
3854 94175 : 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 94175 : bool clobber_conflict_found = 0;
3860 175245 : for (i = 0; i < noutputs; ++i)
3861 81070 : if (tree_conflicts_with_clobbers_p (output_tvec[i], &clobbered_regs, locus))
3862 10 : clobber_conflict_found = 1;
3863 153495 : for (i = 0; i < ninputs - ninout; ++i)
3864 59320 : 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 94175 : rtvec argvec = rtvec_alloc (ninputs);
3871 94175 : rtvec constraintvec = rtvec_alloc (ninputs);
3872 94175 : rtvec labelvec = rtvec_alloc (nlabels);
3873 :
3874 130776 : 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 94175 : MEM_VOLATILE_P (body) = gimple_asm_volatile_p (stmt);
3880 :
3881 153495 : for (i = 0; i < ninputs; ++i)
3882 : {
3883 59320 : ASM_OPERANDS_INPUT (body, i) = input_rvec[i];
3884 118640 : ASM_OPERANDS_INPUT_CONSTRAINT_EXP (body, i)
3885 59320 : = gen_rtx_ASM_INPUT_loc (input_mode[i],
3886 : constraints[i + noutputs],
3887 : locus);
3888 : }
3889 :
3890 : /* Copy labels to the vector. */
3891 94175 : rtx_code_label *fallthru_label = NULL;
3892 94175 : if (nlabels > 0)
3893 : {
3894 635 : basic_block fallthru_bb = NULL;
3895 635 : edge fallthru = find_fallthru_edge (gimple_bb (stmt)->succs);
3896 635 : if (fallthru)
3897 635 : fallthru_bb = fallthru->dest;
3898 :
3899 1529 : for (i = 0; i < nlabels; ++i)
3900 : {
3901 894 : tree label = TREE_VALUE (gimple_asm_label_op (stmt, i));
3902 894 : 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 894 : if (fallthru_bb && label_to_block (cfun, label) == fallthru_bb)
3909 : {
3910 294 : if (fallthru_label == NULL_RTX)
3911 289 : fallthru_label = gen_label_rtx ();
3912 : r = fallthru_label;
3913 : }
3914 : else
3915 600 : r = label_rtx (label);
3916 894 : 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 94175 : 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 94175 : 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 94113 : rtx obody = body;
3944 94113 : int num = noutputs;
3945 :
3946 94113 : if (num == 0)
3947 57574 : num = 1;
3948 :
3949 94113 : body = gen_rtx_PARALLEL (VOIDmode,
3950 : rtvec_alloc (num + nuses + nclobbers));
3951 :
3952 : /* For each output operand, store a SET. */
3953 175121 : for (i = 0; i < noutputs; ++i)
3954 : {
3955 81008 : rtx src, o = output_rvec[i];
3956 81008 : if (i == 0)
3957 : {
3958 36539 : ASM_OPERANDS_OUTPUT_CONSTRAINT (obody) = constraints[0];
3959 36539 : src = obody;
3960 : }
3961 : else
3962 : {
3963 44469 : src = gen_rtx_ASM_OPERANDS (GET_MODE (o),
3964 : ASM_OPERANDS_TEMPLATE (obody),
3965 : constraints[i], i, argvec,
3966 : constraintvec, labelvec, locus);
3967 44469 : MEM_VOLATILE_P (src) = gimple_asm_volatile_p (stmt);
3968 : }
3969 81008 : 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 94113 : if (i == 0)
3975 57574 : 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 94113 : 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 270151 : for (unsigned j = 0; j < nclobbers; ++j)
3984 : {
3985 176038 : 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 176038 : 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 217797 : for (unsigned k = 0; k < noutputs; ++k)
3995 82067 : if (reg_overlap_mentioned_p (clobbered_reg, output_rvec[k]))
3996 0 : internal_error ("%<asm%> clobber conflict with "
3997 : "output operand");
3998 :
3999 198279 : for (unsigned k = 0; k < ninputs - ninout; ++k)
4000 62549 : if (reg_overlap_mentioned_p (clobbered_reg, input_rvec[k]))
4001 0 : internal_error ("%<asm%> clobber conflict with "
4002 : "input operand");
4003 : }
4004 :
4005 176038 : XVECEXP (body, 0, i++) = gen_rtx_CLOBBER (VOIDmode, clobbered_reg);
4006 : }
4007 :
4008 94113 : if (nlabels > 0)
4009 635 : emit_jump_insn (body);
4010 : else
4011 93478 : emit_insn (body);
4012 : }
4013 :
4014 94175 : generating_concat_p = old_generating_concat_p;
4015 :
4016 94175 : if (fallthru_label)
4017 289 : emit_label (fallthru_label);
4018 :
4019 94175 : if (after_rtl_seq)
4020 : {
4021 29525 : if (nlabels == 0)
4022 29388 : emit_insn (after_rtl_seq);
4023 : else
4024 : {
4025 137 : edge e;
4026 137 : edge_iterator ei;
4027 137 : unsigned int cnt = EDGE_COUNT (gimple_bb (stmt)->succs);
4028 :
4029 486 : FOR_EACH_EDGE (e, ei, gimple_bb (stmt)->succs)
4030 : {
4031 349 : rtx_insn *copy;
4032 349 : if (--cnt == 0)
4033 : copy = after_rtl_seq;
4034 : else
4035 : {
4036 212 : start_sequence ();
4037 212 : duplicate_insn_chain (after_rtl_seq, after_rtl_end,
4038 : NULL, NULL);
4039 212 : copy = end_sequence ();
4040 : }
4041 349 : prepend_insn_to_edge (copy, e);
4042 : }
4043 : }
4044 : }
4045 :
4046 94175 : free_temp_slots ();
4047 94175 : crtl->has_asm_statement = 1;
4048 94180 : }
4049 :
4050 : /* Emit code to jump to the address
4051 : specified by the pointer expression EXP. */
4052 :
4053 : static void
4054 444 : expand_computed_goto (tree exp)
4055 : {
4056 444 : rtx x = expand_normal (exp);
4057 :
4058 444 : do_pending_stack_adjust ();
4059 444 : emit_indirect_jump (x);
4060 444 : }
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 853120 : expand_null_return_1 (void)
4084 : {
4085 853120 : clear_pending_stack_adjust ();
4086 853120 : do_pending_stack_adjust ();
4087 853120 : emit_jump (return_label);
4088 853120 : }
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 72402 : 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 72402 : clobber_return_register ();
4100 :
4101 72402 : expand_null_return_1 ();
4102 72402 : }
4103 :
4104 : /* Generate RTL to return from the current function, with value VAL. */
4105 :
4106 : static void
4107 780718 : expand_value_return (rtx val)
4108 : {
4109 : /* Copy the value to the return location unless it's already there. */
4110 :
4111 780718 : tree decl = DECL_RESULT (current_function_decl);
4112 780718 : rtx return_reg = DECL_RTL (decl);
4113 780718 : if (return_reg != val)
4114 : {
4115 454423 : tree funtype = TREE_TYPE (current_function_decl);
4116 454423 : tree type = TREE_TYPE (decl);
4117 454423 : int unsignedp = TYPE_UNSIGNED (type);
4118 454423 : machine_mode old_mode = DECL_MODE (decl);
4119 454423 : machine_mode mode;
4120 454423 : if (DECL_BY_REFERENCE (decl))
4121 0 : mode = promote_function_mode (type, old_mode, &unsignedp, funtype, 2);
4122 : else
4123 454423 : mode = promote_function_mode (type, old_mode, &unsignedp, funtype, 1);
4124 :
4125 454423 : 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 454423 : if (GET_CODE (return_reg) == PARALLEL)
4140 3314 : emit_group_load (return_reg, val, type, int_size_in_bytes (type));
4141 : else
4142 451109 : emit_move_insn (return_reg, val);
4143 : }
4144 :
4145 780718 : expand_null_return_1 ();
4146 780718 : }
4147 :
4148 : /* Generate RTL to evaluate the expression RETVAL and return it
4149 : from the current function. */
4150 :
4151 : static void
4152 783259 : expand_return (tree retval)
4153 : {
4154 783259 : rtx result_rtl;
4155 783259 : rtx val = 0;
4156 783259 : tree retval_rhs;
4157 :
4158 : /* If function wants no value, give it none. */
4159 783259 : 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 783259 : 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 783259 : else if ((TREE_CODE (retval) == MODIFY_EXPR
4174 783259 : || TREE_CODE (retval) == INIT_EXPR)
4175 783259 : && TREE_CODE (TREE_OPERAND (retval, 0)) == RESULT_DECL)
4176 719762 : retval_rhs = TREE_OPERAND (retval, 1);
4177 : else
4178 : retval_rhs = retval;
4179 :
4180 783259 : 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 783259 : if (TREE_CODE (retval_rhs) == RESULT_DECL)
4185 63497 : 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 719762 : else if (retval_rhs != 0
4191 719762 : && TYPE_MODE (TREE_TYPE (retval_rhs)) == BLKmode
4192 5263 : && REG_P (result_rtl))
4193 : {
4194 3765 : val = copy_blkmode_to_reg (GET_MODE (result_rtl), retval_rhs);
4195 3765 : 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 2541 : expand_null_return ();
4203 : }
4204 715997 : else if (retval_rhs != 0
4205 715997 : && !VOID_TYPE_P (TREE_TYPE (retval_rhs))
4206 715997 : && (REG_P (result_rtl)
4207 6456 : || (GET_CODE (result_rtl) == PARALLEL)))
4208 : {
4209 : /* Compute the return value into a temporary (usually a pseudo reg). */
4210 712855 : val
4211 712855 : = assign_temp (TREE_TYPE (DECL_RESULT (current_function_decl)), 0, 1);
4212 712855 : val = expand_expr (retval_rhs, val, GET_MODE (val), EXPAND_NORMAL);
4213 712855 : val = force_not_mem (val);
4214 712855 : expand_value_return (val);
4215 : }
4216 : else
4217 : {
4218 : /* No hard reg used; calculate value into hard return reg. */
4219 3142 : expand_expr (retval, const0_rtx, VOIDmode, EXPAND_NORMAL);
4220 3142 : 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 1419049 : expand_clobber (tree lhs)
4230 : {
4231 1419049 : if (DECL_P (lhs))
4232 : {
4233 1390943 : rtx decl_rtl = DECL_RTL_IF_SET (lhs);
4234 1390852 : if (decl_rtl && REG_P (decl_rtl))
4235 : {
4236 191265 : machine_mode decl_mode = GET_MODE (decl_rtl);
4237 382530 : if (maybe_gt (GET_MODE_SIZE (decl_mode),
4238 : REGMODE_NATURAL_SIZE (decl_mode)))
4239 149004 : emit_clobber (decl_rtl);
4240 : }
4241 : }
4242 1419049 : }
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 32849581 : expand_gimple_stmt_1 (gimple *stmt)
4250 : {
4251 32849581 : tree op0;
4252 :
4253 32849581 : set_curr_insn_location (gimple_location (stmt));
4254 :
4255 32849581 : switch (gimple_code (stmt))
4256 : {
4257 444 : case GIMPLE_GOTO:
4258 444 : op0 = gimple_goto_dest (stmt);
4259 444 : if (TREE_CODE (op0) == LABEL_DECL)
4260 0 : expand_goto (op0);
4261 : else
4262 444 : expand_computed_goto (op0);
4263 : break;
4264 674520 : case GIMPLE_LABEL:
4265 674520 : expand_label (gimple_label_label (as_a <glabel *> (stmt)));
4266 674520 : break;
4267 : case GIMPLE_NOP:
4268 : case GIMPLE_PREDICT:
4269 : break;
4270 7648 : case GIMPLE_SWITCH:
4271 7648 : {
4272 7648 : gswitch *swtch = as_a <gswitch *> (stmt);
4273 7648 : if (gimple_switch_num_labels (swtch) == 1)
4274 0 : expand_goto (CASE_LABEL (gimple_switch_default_label (swtch)));
4275 : else
4276 7648 : expand_case (swtch);
4277 : }
4278 : break;
4279 97092 : case GIMPLE_ASM:
4280 97092 : expand_asm_stmt (as_a <gasm *> (stmt));
4281 97092 : break;
4282 7106670 : case GIMPLE_CALL:
4283 7106670 : expand_call_stmt (as_a <gcall *> (stmt));
4284 7106670 : break;
4285 :
4286 853120 : case GIMPLE_RETURN:
4287 853120 : {
4288 853120 : 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 853120 : if (!gimple_has_location (stmt))
4294 222192 : set_curr_insn_location (cfun->function_end_locus);
4295 :
4296 853120 : if (op0 && op0 != error_mark_node)
4297 : {
4298 783259 : 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 783259 : if (op0 != result)
4303 : {
4304 : /* I believe that a function's RESULT_DECL is unique. */
4305 719762 : 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 719762 : op0 = build2 (MODIFY_EXPR, TREE_TYPE (result),
4314 : result, op0);
4315 : }
4316 : }
4317 :
4318 783259 : if (!op0)
4319 69861 : expand_null_return ();
4320 : else
4321 783259 : expand_return (op0);
4322 : }
4323 : break;
4324 :
4325 24059899 : case GIMPLE_ASSIGN:
4326 24059899 : {
4327 24059899 : gassign *assign_stmt = as_a <gassign *> (stmt);
4328 24059899 : 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 24059899 : if (TREE_CODE (lhs) != SSA_NAME
4335 38265615 : || gimple_assign_rhs_class (assign_stmt) == GIMPLE_SINGLE_RHS)
4336 : {
4337 17879587 : tree rhs = gimple_assign_rhs1 (assign_stmt);
4338 17879587 : gcc_assert (gimple_assign_rhs_class (assign_stmt)
4339 : == GIMPLE_SINGLE_RHS);
4340 34106676 : if (gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (rhs)
4341 : /* Do not put locations on possibly shared trees. */
4342 24028014 : && !is_gimple_min_invariant (rhs))
4343 4991876 : SET_EXPR_LOCATION (rhs, gimple_location (stmt));
4344 17879587 : if (TREE_CLOBBER_P (rhs))
4345 : /* This is a clobber to mark the going out of scope for
4346 : this LHS. */
4347 1419049 : expand_clobber (lhs);
4348 : else
4349 16460538 : expand_assignment (lhs, rhs,
4350 : gimple_assign_nontemporal_move_p (
4351 : assign_stmt));
4352 : }
4353 : else
4354 : {
4355 6180312 : rtx target, temp;
4356 6180312 : gcc_assert (!gimple_assign_nontemporal_move_p (assign_stmt));
4357 6180312 : bool promoted = false;
4358 :
4359 6180312 : target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
4360 6180312 : 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 12360624 : temp = expand_expr_real_gassign (assign_stmt, temp,
4367 6180312 : GET_MODE (target), EXPAND_NORMAL);
4368 :
4369 6180312 : if (temp == target)
4370 : ;
4371 868899 : 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 868897 : temp = force_operand (temp, target);
4390 868897 : if (temp == target)
4391 : ;
4392 868897 : else if (GET_MODE (target) != BLKmode)
4393 868896 : 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 32849579 : }
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 32849581 : expand_gimple_stmt (gimple *stmt)
4416 : {
4417 32849581 : location_t saved_location = input_location;
4418 32849581 : rtx_insn *last = get_last_insn ();
4419 32849581 : int lp_nr;
4420 :
4421 32849581 : 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 32849581 : if (gimple_has_location (stmt))
4428 28774092 : input_location = gimple_location (stmt);
4429 :
4430 32849581 : expand_gimple_stmt_1 (stmt);
4431 :
4432 : /* Free any temporaries used to evaluate this statement. */
4433 32849579 : free_temp_slots ();
4434 :
4435 32849579 : input_location = saved_location;
4436 :
4437 : /* Mark all insns that may trap. */
4438 32849579 : lp_nr = lookup_stmt_eh_lp (stmt);
4439 32849579 : if (lp_nr)
4440 : {
4441 744012 : rtx_insn *insn;
4442 4263484 : for (insn = next_real_insn (last); insn;
4443 3519472 : insn = next_real_insn (insn))
4444 : {
4445 3519472 : 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 3519378 : && GET_CODE (PATTERN (insn)) != CLOBBER
4449 3519308 : && GET_CODE (PATTERN (insn)) != USE
4450 7038780 : && insn_could_throw_p (insn))
4451 801311 : make_reg_eh_region_note (insn, 0, lp_nr);
4452 : }
4453 : }
4454 :
4455 32849579 : 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 179094 : expand_gimple_tailcall (basic_block bb, gcall *stmt, bool *can_fallthru,
4470 : rtx_insn *asan_epilog_seq)
4471 : {
4472 179094 : rtx_insn *last2, *last, *first = get_last_insn ();
4473 179094 : edge e;
4474 179094 : edge_iterator ei;
4475 179094 : profile_probability probability;
4476 :
4477 179094 : last2 = last = expand_gimple_stmt (stmt);
4478 :
4479 982839 : for (last = NEXT_INSN (last); last; last = NEXT_INSN (last))
4480 753128 : if (CALL_P (last) && SIBLING_CALL_P (last))
4481 128477 : goto found;
4482 :
4483 50617 : maybe_dump_rtl_for_gimple_stmt (stmt, last2);
4484 :
4485 50617 : *can_fallthru = true;
4486 50617 : return NULL;
4487 :
4488 128477 : found:
4489 :
4490 128477 : 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_code_label *> 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, 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_code_label **lab
4525 234 : = label_map.get ((rtx) label_ref_label (*loc));
4526 234 : gcc_assert (lab);
4527 234 : set_label_ref_label (*loc, *lab);
4528 : }
4529 : }
4530 234 : if (JUMP_LABEL (insn))
4531 : {
4532 234 : rtx_code_label **lab = label_map.get (JUMP_LABEL (insn));
4533 234 : gcc_assert (lab);
4534 234 : JUMP_LABEL (insn) = *lab;
4535 : }
4536 234 : }
4537 117 : asan_epilog_seq = NEXT_INSN (get_insns ());
4538 117 : end_sequence ();
4539 117 : emit_insn_before (asan_epilog_seq, NEXT_INSN (first));
4540 117 : }
4541 :
4542 : /* ??? Wouldn't it be better to just reset any pending stack adjust?
4543 : Any instructions emitted here are about to be deleted. */
4544 128477 : do_pending_stack_adjust ();
4545 :
4546 : /* Remove any non-eh, non-abnormal edges that don't go to exit. */
4547 : /* ??? I.e. the fallthrough edge. HOWEVER! If there were to be
4548 : EH or abnormal edges, we shouldn't have created a tail call in
4549 : the first place. So it seems to me we should just be removing
4550 : all edges here, or redirecting the existing fallthru edge to
4551 : the exit block. */
4552 :
4553 128477 : probability = profile_probability::never ();
4554 :
4555 256948 : for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
4556 : {
4557 128471 : if (!(e->flags & (EDGE_ABNORMAL | EDGE_EH)))
4558 : {
4559 128465 : if (e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
4560 60565 : e->dest->count -= e->count ();
4561 128465 : probability += e->probability;
4562 128465 : expand_remove_edge (e);
4563 : }
4564 : else
4565 6 : ei_next (&ei);
4566 : }
4567 :
4568 : /* This is somewhat ugly: the call_expr expander often emits instructions
4569 : after the sibcall (to perform the function return). These confuse the
4570 : find_many_sub_basic_blocks code, so we need to get rid of these. */
4571 128477 : last = NEXT_INSN (last);
4572 128477 : gcc_assert (BARRIER_P (last));
4573 :
4574 128477 : *can_fallthru = false;
4575 158921 : while (NEXT_INSN (last))
4576 : {
4577 : /* For instance an sqrt builtin expander expands if with
4578 : sibcall in the then and label for `else`. */
4579 30444 : if (LABEL_P (NEXT_INSN (last)))
4580 : {
4581 0 : *can_fallthru = true;
4582 0 : break;
4583 : }
4584 30444 : delete_insn (NEXT_INSN (last));
4585 : }
4586 :
4587 128477 : e = make_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun), EDGE_ABNORMAL
4588 : | EDGE_SIBCALL);
4589 128477 : e->probability = probability;
4590 128477 : head_end_for_bb[bb->index].second = last;
4591 256954 : update_bb_for_insn_chain (head_end_for_bb[bb->index].first,
4592 128477 : head_end_for_bb[bb->index].second, bb);
4593 :
4594 128477 : if (NEXT_INSN (last))
4595 : {
4596 0 : bb = create_basic_block (NEXT_INSN (last), get_last_insn (), bb);
4597 :
4598 0 : last = BB_END (bb);
4599 0 : if (BARRIER_P (last))
4600 0 : BB_END (bb) = PREV_INSN (last);
4601 : }
4602 :
4603 128477 : maybe_dump_rtl_for_gimple_stmt (stmt, last2);
4604 :
4605 128477 : return bb;
4606 : }
4607 :
4608 : /* Return the difference between the floor and the truncated result of
4609 : a signed division by OP1 with remainder MOD. */
4610 : static rtx
4611 4 : floor_sdiv_adjust (machine_mode mode, rtx mod, rtx op1)
4612 : {
4613 : /* (mod != 0 ? (op1 / mod < 0 ? -1 : 0) : 0) */
4614 4 : return gen_rtx_IF_THEN_ELSE
4615 : (mode, gen_rtx_NE (BImode, mod, const0_rtx),
4616 : gen_rtx_IF_THEN_ELSE
4617 : (mode, gen_rtx_LT (BImode,
4618 : gen_rtx_DIV (mode, op1, mod),
4619 : const0_rtx),
4620 : constm1_rtx, const0_rtx),
4621 : const0_rtx);
4622 : }
4623 :
4624 : /* Return the difference between the ceil and the truncated result of
4625 : a signed division by OP1 with remainder MOD. */
4626 : static rtx
4627 3 : ceil_sdiv_adjust (machine_mode mode, rtx mod, rtx op1)
4628 : {
4629 : /* (mod != 0 ? (op1 / mod > 0 ? 1 : 0) : 0) */
4630 3 : return gen_rtx_IF_THEN_ELSE
4631 : (mode, gen_rtx_NE (BImode, mod, const0_rtx),
4632 : gen_rtx_IF_THEN_ELSE
4633 : (mode, gen_rtx_GT (BImode,
4634 : gen_rtx_DIV (mode, op1, mod),
4635 : const0_rtx),
4636 : const1_rtx, const0_rtx),
4637 : const0_rtx);
4638 : }
4639 :
4640 : /* Return the difference between the ceil and the truncated result of
4641 : an unsigned division by OP1 with remainder MOD. */
4642 : static rtx
4643 0 : ceil_udiv_adjust (machine_mode mode, rtx mod, rtx op1 ATTRIBUTE_UNUSED)
4644 : {
4645 : /* (mod != 0 ? 1 : 0) */
4646 0 : return gen_rtx_IF_THEN_ELSE
4647 : (mode, gen_rtx_NE (BImode, mod, const0_rtx),
4648 : const1_rtx, const0_rtx);
4649 : }
4650 :
4651 : /* Return the difference between the rounded and the truncated result
4652 : of a signed division by OP1 with remainder MOD. Halfway cases are
4653 : rounded away from zero, rather than to the nearest even number. */
4654 : static rtx
4655 0 : round_sdiv_adjust (machine_mode mode, rtx mod, rtx op1)
4656 : {
4657 : /* (abs (mod) >= abs (op1) - abs (mod)
4658 : ? (op1 / mod > 0 ? 1 : -1)
4659 : : 0) */
4660 0 : return gen_rtx_IF_THEN_ELSE
4661 : (mode, gen_rtx_GE (BImode, gen_rtx_ABS (mode, mod),
4662 : gen_rtx_MINUS (mode,
4663 : gen_rtx_ABS (mode, op1),
4664 : gen_rtx_ABS (mode, mod))),
4665 : gen_rtx_IF_THEN_ELSE
4666 : (mode, gen_rtx_GT (BImode,
4667 : gen_rtx_DIV (mode, op1, mod),
4668 : const0_rtx),
4669 : const1_rtx, constm1_rtx),
4670 : const0_rtx);
4671 : }
4672 :
4673 : /* Return the difference between the rounded and the truncated result
4674 : of a unsigned division by OP1 with remainder MOD. Halfway cases
4675 : are rounded away from zero, rather than to the nearest even
4676 : number. */
4677 : static rtx
4678 0 : round_udiv_adjust (machine_mode mode, rtx mod, rtx op1)
4679 : {
4680 : /* (mod >= op1 - mod ? 1 : 0) */
4681 0 : return gen_rtx_IF_THEN_ELSE
4682 : (mode, gen_rtx_GE (BImode, mod,
4683 : gen_rtx_MINUS (mode, op1, mod)),
4684 : const1_rtx, const0_rtx);
4685 : }
4686 :
4687 : /* Convert X to MODE, that must be Pmode or ptr_mode, without emitting
4688 : any rtl. */
4689 :
4690 : static rtx
4691 7414887 : convert_debug_memory_address (scalar_int_mode mode, rtx x,
4692 : addr_space_t as)
4693 : {
4694 : #ifndef POINTERS_EXTEND_UNSIGNED
4695 : gcc_assert (mode == Pmode
4696 : || mode == targetm.addr_space.address_mode (as));
4697 : gcc_assert (GET_MODE (x) == mode || GET_MODE (x) == VOIDmode);
4698 : #else
4699 7414887 : rtx temp;
4700 :
4701 7414887 : gcc_assert (targetm.addr_space.valid_pointer_mode (mode, as));
4702 :
4703 7414887 : if (GET_MODE (x) == mode || GET_MODE (x) == VOIDmode)
4704 : return x;
4705 :
4706 : /* X must have some form of address mode already. */
4707 0 : scalar_int_mode xmode = as_a <scalar_int_mode> (GET_MODE (x));
4708 0 : if (GET_MODE_PRECISION (mode) < GET_MODE_PRECISION (xmode))
4709 0 : x = lowpart_subreg (mode, x, xmode);
4710 0 : else if (POINTERS_EXTEND_UNSIGNED > 0)
4711 0 : x = gen_rtx_ZERO_EXTEND (mode, x);
4712 : else if (!POINTERS_EXTEND_UNSIGNED)
4713 : x = gen_rtx_SIGN_EXTEND (mode, x);
4714 : else
4715 : {
4716 : switch (GET_CODE (x))
4717 : {
4718 : case SUBREG:
4719 : if ((SUBREG_PROMOTED_VAR_P (x)
4720 : || (REG_P (SUBREG_REG (x)) && REG_POINTER (SUBREG_REG (x)))
4721 : || (GET_CODE (SUBREG_REG (x)) == PLUS
4722 : && REG_P (XEXP (SUBREG_REG (x), 0))
4723 : && REG_POINTER (XEXP (SUBREG_REG (x), 0))
4724 : && CONST_INT_P (XEXP (SUBREG_REG (x), 1))))
4725 : && GET_MODE (SUBREG_REG (x)) == mode)
4726 : return SUBREG_REG (x);
4727 : break;
4728 : case LABEL_REF:
4729 : temp = gen_rtx_LABEL_REF (mode, label_ref_label (x));
4730 : LABEL_REF_NONLOCAL_P (temp) = LABEL_REF_NONLOCAL_P (x);
4731 : return temp;
4732 : case SYMBOL_REF:
4733 : temp = shallow_copy_rtx (x);
4734 : PUT_MODE (temp, mode);
4735 : return temp;
4736 : case CONST:
4737 : temp = convert_debug_memory_address (mode, XEXP (x, 0), as);
4738 : if (temp)
4739 : temp = gen_rtx_CONST (mode, temp);
4740 : return temp;
4741 : case PLUS:
4742 : case MINUS:
4743 : if (CONST_INT_P (XEXP (x, 1)))
4744 : {
4745 : temp = convert_debug_memory_address (mode, XEXP (x, 0), as);
4746 : if (temp)
4747 : return gen_rtx_fmt_ee (GET_CODE (x), mode, temp, XEXP (x, 1));
4748 : }
4749 : break;
4750 : default:
4751 : break;
4752 : }
4753 : /* Don't know how to express ptr_extend as operation in debug info. */
4754 : return NULL;
4755 : }
4756 : #endif /* POINTERS_EXTEND_UNSIGNED */
4757 :
4758 : return x;
4759 : }
4760 :
4761 : /* Map from SSA_NAMEs to corresponding DEBUG_EXPR_DECLs created
4762 : by avoid_deep_ter_for_debug. */
4763 :
4764 : static hash_map<tree, tree> *deep_ter_debug_map;
4765 :
4766 : /* Split too deep TER chains for debug stmts using debug temporaries. */
4767 :
4768 : static void
4769 42582196 : avoid_deep_ter_for_debug (gimple *stmt, int depth)
4770 : {
4771 42582196 : use_operand_p use_p;
4772 42582196 : ssa_op_iter iter;
4773 52808919 : FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
4774 : {
4775 10226723 : tree use = USE_FROM_PTR (use_p);
4776 10226723 : if (TREE_CODE (use) != SSA_NAME || SSA_NAME_IS_DEFAULT_DEF (use))
4777 8496058 : continue;
4778 8867788 : gimple *g = get_gimple_for_ssa_name (use);
4779 8867788 : if (g == NULL)
4780 7133668 : continue;
4781 1734120 : if ((depth > 6 || !is_gimple_assign (g)) && !stmt_ends_bb_p (g))
4782 : {
4783 8884 : if (deep_ter_debug_map == NULL)
4784 736 : deep_ter_debug_map = new hash_map<tree, tree>;
4785 :
4786 8884 : tree &vexpr = deep_ter_debug_map->get_or_insert (use);
4787 8884 : if (vexpr != NULL)
4788 3455 : continue;
4789 5429 : vexpr = build_debug_expr_decl (TREE_TYPE (use));
4790 5429 : gimple *def_temp = gimple_build_debug_bind (vexpr, use, g);
4791 5429 : gimple_stmt_iterator gsi = gsi_for_stmt (g);
4792 5429 : gsi_insert_after (&gsi, def_temp, GSI_NEW_STMT);
4793 5429 : avoid_deep_ter_for_debug (def_temp, 0);
4794 : }
4795 : else
4796 1725236 : avoid_deep_ter_for_debug (g, depth + 1);
4797 : }
4798 42582196 : }
4799 :
4800 : /* Return an RTX equivalent to the value of the parameter DECL. */
4801 :
4802 : static rtx
4803 189363 : expand_debug_parm_decl (tree decl)
4804 : {
4805 189363 : rtx incoming = DECL_INCOMING_RTL (decl);
4806 :
4807 189363 : if (incoming
4808 19598 : && GET_MODE (incoming) != BLKmode
4809 208957 : && ((REG_P (incoming) && HARD_REGISTER_P (incoming))
4810 952 : || (MEM_P (incoming)
4811 948 : && REG_P (XEXP (incoming, 0))
4812 341 : && HARD_REGISTER_P (XEXP (incoming, 0)))))
4813 : {
4814 18669 : rtx rtl = gen_rtx_ENTRY_VALUE (GET_MODE (incoming));
4815 :
4816 : #ifdef HAVE_window_save
4817 : /* DECL_INCOMING_RTL uses the INCOMING_REGNO of parameter registers.
4818 : If the target machine has an explicit window save instruction, the
4819 : actual entry value is the corresponding OUTGOING_REGNO instead. */
4820 : if (REG_P (incoming)
4821 : && OUTGOING_REGNO (REGNO (incoming)) != REGNO (incoming))
4822 : incoming
4823 : = gen_rtx_REG_offset (incoming, GET_MODE (incoming),
4824 : OUTGOING_REGNO (REGNO (incoming)), 0);
4825 : else if (MEM_P (incoming))
4826 : {
4827 : rtx reg = XEXP (incoming, 0);
4828 : if (OUTGOING_REGNO (REGNO (reg)) != REGNO (reg))
4829 : {
4830 : reg = gen_raw_REG (GET_MODE (reg), OUTGOING_REGNO (REGNO (reg)));
4831 : incoming = replace_equiv_address_nv (incoming, reg);
4832 : }
4833 : else
4834 : incoming = copy_rtx (incoming);
4835 : }
4836 : #endif
4837 :
4838 18669 : ENTRY_VALUE_EXP (rtl) = incoming;
4839 18669 : return rtl;
4840 : }
4841 :
4842 170694 : if (incoming
4843 929 : && GET_MODE (incoming) != BLKmode
4844 925 : && !TREE_ADDRESSABLE (decl)
4845 925 : && MEM_P (incoming)
4846 921 : && (XEXP (incoming, 0) == virtual_incoming_args_rtx
4847 607 : || (GET_CODE (XEXP (incoming, 0)) == PLUS
4848 607 : && XEXP (XEXP (incoming, 0), 0) == virtual_incoming_args_rtx
4849 591 : && CONST_INT_P (XEXP (XEXP (incoming, 0), 1)))))
4850 905 : return copy_rtx (incoming);
4851 :
4852 : return NULL_RTX;
4853 : }
4854 :
4855 : /* Return an RTX equivalent to the value of the tree expression EXP. */
4856 :
4857 : static rtx
4858 43222178 : expand_debug_expr (tree exp)
4859 : {
4860 43222178 : rtx op0 = NULL_RTX, op1 = NULL_RTX, op2 = NULL_RTX;
4861 43222178 : machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
4862 43222178 : machine_mode inner_mode = VOIDmode;
4863 43222178 : int unsignedp = TYPE_UNSIGNED (TREE_TYPE (exp));
4864 43222178 : addr_space_t as;
4865 43222178 : scalar_int_mode op0_mode, op1_mode, addr_mode;
4866 :
4867 43222178 : switch (TREE_CODE_CLASS (TREE_CODE (exp)))
4868 : {
4869 7109170 : case tcc_expression:
4870 7109170 : switch (TREE_CODE (exp))
4871 : {
4872 8338 : case COND_EXPR:
4873 8338 : case DOT_PROD_EXPR:
4874 8338 : case SAD_EXPR:
4875 8338 : case WIDEN_MULT_PLUS_EXPR:
4876 8338 : case WIDEN_MULT_MINUS_EXPR:
4877 8338 : goto ternary;
4878 :
4879 0 : case TRUTH_ANDIF_EXPR:
4880 0 : case TRUTH_ORIF_EXPR:
4881 0 : case TRUTH_AND_EXPR:
4882 0 : case TRUTH_OR_EXPR:
4883 0 : case TRUTH_XOR_EXPR:
4884 0 : goto binary;
4885 :
4886 0 : case TRUTH_NOT_EXPR:
4887 0 : goto unary;
4888 :
4889 : default:
4890 : break;
4891 : }
4892 : break;
4893 :
4894 8338 : ternary:
4895 8338 : op2 = expand_debug_expr (TREE_OPERAND (exp, 2));
4896 8338 : if (!op2)
4897 : return NULL_RTX;
4898 : /* Fall through. */
4899 :
4900 8338 : binary:
4901 1533465 : case tcc_binary:
4902 1533465 : if (mode == BLKmode)
4903 : return NULL_RTX;
4904 1533455 : op1 = expand_debug_expr (TREE_OPERAND (exp, 1));
4905 1533455 : if (!op1)
4906 : return NULL_RTX;
4907 1533188 : switch (TREE_CODE (exp))
4908 : {
4909 82758 : case LSHIFT_EXPR:
4910 82758 : case RSHIFT_EXPR:
4911 82758 : case LROTATE_EXPR:
4912 82758 : case RROTATE_EXPR:
4913 82758 : case WIDEN_LSHIFT_EXPR:
4914 : /* Ensure second operand isn't wider than the first one. */
4915 82758 : inner_mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 1)));
4916 82758 : if (is_a <scalar_int_mode> (inner_mode, &op1_mode)
4917 82750 : && (GET_MODE_UNIT_PRECISION (mode)
4918 82750 : < GET_MODE_PRECISION (op1_mode)))
4919 5158 : op1 = lowpart_subreg (GET_MODE_INNER (mode), op1, op1_mode);
4920 : break;
4921 : default:
4922 : break;
4923 : }
4924 : /* Fall through. */
4925 :
4926 2118615 : unary:
4927 2118615 : case tcc_unary:
4928 2118615 : if (mode == BLKmode)
4929 : return NULL_RTX;
4930 2118613 : inner_mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
4931 2118613 : op0 = expand_debug_expr (TREE_OPERAND (exp, 0));
4932 2118613 : if (!op0)
4933 : return NULL_RTX;
4934 : break;
4935 :
4936 72897 : case tcc_comparison:
4937 72897 : unsignedp = TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0)));
4938 72897 : goto binary;
4939 :
4940 0 : case tcc_type:
4941 0 : case tcc_statement:
4942 0 : gcc_unreachable ();
4943 :
4944 : case tcc_constant:
4945 : case tcc_exceptional:
4946 : case tcc_declaration:
4947 : case tcc_reference:
4948 : case tcc_vl_exp:
4949 : break;
4950 : }
4951 :
4952 43217642 : switch (TREE_CODE (exp))
4953 : {
4954 272296 : case STRING_CST:
4955 272296 : if (!lookup_constant_def (exp))
4956 : {
4957 101223 : if (strlen (TREE_STRING_POINTER (exp)) + 1
4958 101223 : != (size_t) TREE_STRING_LENGTH (exp))
4959 : return NULL_RTX;
4960 101299 : op0 = gen_rtx_CONST_STRING (Pmode, TREE_STRING_POINTER (exp));
4961 100485 : op0 = gen_rtx_MEM (BLKmode, op0);
4962 100485 : set_mem_attributes (op0, exp, 0);
4963 100485 : return op0;
4964 : }
4965 : /* Fall through. */
4966 :
4967 6209823 : case INTEGER_CST:
4968 12419524 : if (BITINT_TYPE_P (TREE_TYPE (exp))
4969 6209823 : && TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
4970 : return NULL;
4971 : /* FALLTHRU */
4972 6282784 : case REAL_CST:
4973 6282784 : case FIXED_CST:
4974 6282784 : op0 = expand_expr (exp, NULL_RTX, mode, EXPAND_INITIALIZER);
4975 6282784 : return op0;
4976 :
4977 0 : case POLY_INT_CST:
4978 0 : return immed_wide_int_const (poly_int_cst_value (exp), mode);
4979 :
4980 4057 : case COMPLEX_CST:
4981 4057 : gcc_assert (COMPLEX_MODE_P (mode));
4982 4057 : op0 = expand_debug_expr (TREE_REALPART (exp));
4983 4057 : op1 = expand_debug_expr (TREE_IMAGPART (exp));
4984 4057 : return gen_rtx_CONCAT (mode, op0, op1);
4985 :
4986 6203094 : case DEBUG_EXPR_DECL:
4987 6203094 : op0 = DECL_RTL_IF_SET (exp);
4988 :
4989 5013609 : if (op0)
4990 : {
4991 5013609 : if (GET_MODE (op0) != mode)
4992 0 : gcc_assert (VECTOR_TYPE_P (TREE_TYPE (exp)));
4993 : else
4994 : return op0;
4995 : }
4996 :
4997 1189485 : op0 = gen_rtx_DEBUG_EXPR (mode);
4998 1189485 : DEBUG_EXPR_TREE_DECL (op0) = exp;
4999 1189485 : SET_DECL_RTL (exp, op0);
5000 :
5001 1189485 : return op0;
5002 :
5003 5577878 : case VAR_DECL:
5004 5577878 : case PARM_DECL:
5005 5577878 : case FUNCTION_DECL:
5006 5577878 : case LABEL_DECL:
5007 5577878 : case CONST_DECL:
5008 5577878 : case RESULT_DECL:
5009 5577878 : op0 = DECL_RTL_IF_SET (exp);
5010 :
5011 : /* This decl was probably optimized away. */
5012 3841586 : if (!op0
5013 : /* At least label RTXen are sometimes replaced by
5014 : NOTE_INSN_DELETED_LABEL. Any notes here are not
5015 : handled by copy_rtx. */
5016 3841586 : || NOTE_P (op0))
5017 : {
5018 1736293 : if (!VAR_P (exp)
5019 1723525 : || DECL_EXTERNAL (exp)
5020 1722904 : || !TREE_STATIC (exp)
5021 134621 : || !DECL_NAME (exp)
5022 134621 : || DECL_HARD_REGISTER (exp)
5023 134621 : || DECL_IN_CONSTANT_POOL (exp)
5024 134621 : || mode == VOIDmode
5025 1870914 : || symtab_node::get (exp) == NULL)
5026 : return NULL;
5027 :
5028 19673 : op0 = make_decl_rtl_for_debug (exp);
5029 19673 : if (!MEM_P (op0)
5030 19673 : || GET_CODE (XEXP (op0, 0)) != SYMBOL_REF
5031 39346 : || SYMBOL_REF_DECL (XEXP (op0, 0)) != exp)
5032 : return NULL;
5033 : }
5034 3841585 : else if (VAR_P (exp)
5035 3712934 : && is_global_var (exp)
5036 4066692 : && symtab_node::get (exp) == NULL)
5037 : return NULL;
5038 : else
5039 3841585 : op0 = copy_rtx (op0);
5040 :
5041 3861258 : if (GET_MODE (op0) == BLKmode
5042 : /* If op0 is not BLKmode, but mode is, adjust_mode
5043 : below would ICE. While it is likely a FE bug,
5044 : try to be robust here. See PR43166. */
5045 542607 : || mode == BLKmode
5046 542607 : || (mode == VOIDmode && GET_MODE (op0) != VOIDmode))
5047 : {
5048 3318651 : gcc_assert (MEM_P (op0));
5049 3318651 : op0 = adjust_address_nv (op0, mode, 0);
5050 3318651 : return op0;
5051 : }
5052 :
5053 : /* Fall through. */
5054 :
5055 542607 : adjust_mode:
5056 10804867 : case PAREN_EXPR:
5057 10804867 : CASE_CONVERT:
5058 10804867 : {
5059 10804867 : inner_mode = GET_MODE (op0);
5060 :
5061 10804867 : if (mode == inner_mode)
5062 : return op0;
5063 :
5064 156880 : if (inner_mode == VOIDmode)
5065 : {
5066 8491 : if (TREE_CODE (exp) == SSA_NAME)
5067 37 : inner_mode = TYPE_MODE (TREE_TYPE (exp));
5068 : else
5069 8454 : inner_mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
5070 8491 : if (mode == inner_mode)
5071 : return op0;
5072 : }
5073 :
5074 151128 : if (FLOAT_MODE_P (mode) && FLOAT_MODE_P (inner_mode))
5075 : {
5076 6253 : if (GET_MODE_UNIT_BITSIZE (mode)
5077 12506 : == GET_MODE_UNIT_BITSIZE (inner_mode))
5078 4 : op0 = simplify_gen_subreg (mode, op0, inner_mode, 0);
5079 6249 : else if (GET_MODE_UNIT_BITSIZE (mode)
5080 12498 : < GET_MODE_UNIT_BITSIZE (inner_mode))
5081 3560 : op0 = simplify_gen_unary (FLOAT_TRUNCATE, mode, op0, inner_mode);
5082 : else
5083 2689 : op0 = simplify_gen_unary (FLOAT_EXTEND, mode, op0, inner_mode);
5084 : }
5085 144875 : else if (FLOAT_MODE_P (mode))
5086 : {
5087 0 : gcc_assert (TREE_CODE (exp) != SSA_NAME);
5088 0 : if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))))
5089 0 : op0 = simplify_gen_unary (UNSIGNED_FLOAT, mode, op0, inner_mode);
5090 : else
5091 0 : op0 = simplify_gen_unary (FLOAT, mode, op0, inner_mode);
5092 : }
5093 144875 : else if (FLOAT_MODE_P (inner_mode))
5094 : {
5095 0 : if (unsignedp)
5096 0 : op0 = simplify_gen_unary (UNSIGNED_FIX, mode, op0, inner_mode);
5097 : else
5098 0 : op0 = simplify_gen_unary (FIX, mode, op0, inner_mode);
5099 : }
5100 289750 : else if (GET_MODE_UNIT_PRECISION (mode)
5101 144875 : == GET_MODE_UNIT_PRECISION (inner_mode))
5102 0 : op0 = lowpart_subreg (mode, op0, inner_mode);
5103 289750 : else if (GET_MODE_UNIT_PRECISION (mode)
5104 144875 : < GET_MODE_UNIT_PRECISION (inner_mode))
5105 71348 : op0 = simplify_gen_unary (TRUNCATE, mode, op0, inner_mode);
5106 73527 : else if (UNARY_CLASS_P (exp)
5107 73527 : ? TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0)))
5108 0 : : unsignedp)
5109 48573 : op0 = simplify_gen_unary (ZERO_EXTEND, mode, op0, inner_mode);
5110 : else
5111 24954 : op0 = simplify_gen_unary (SIGN_EXTEND, mode, op0, inner_mode);
5112 :
5113 : return op0;
5114 : }
5115 :
5116 2212380 : case MEM_REF:
5117 2212380 : if (!is_gimple_mem_ref_addr (TREE_OPERAND (exp, 0)))
5118 : {
5119 979748 : tree newexp = fold_binary (MEM_REF, TREE_TYPE (exp),
5120 : TREE_OPERAND (exp, 0),
5121 : TREE_OPERAND (exp, 1));
5122 979748 : if (newexp)
5123 0 : return expand_debug_expr (newexp);
5124 : }
5125 : /* FALLTHROUGH */
5126 2212380 : case INDIRECT_REF:
5127 2212380 : inner_mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
5128 2212380 : op0 = expand_debug_expr (TREE_OPERAND (exp, 0));
5129 2212380 : if (!op0)
5130 : return NULL;
5131 :
5132 2205829 : if (TREE_CODE (exp) == MEM_REF)
5133 : {
5134 2205829 : if (GET_CODE (op0) == DEBUG_IMPLICIT_PTR
5135 2159114 : || (GET_CODE (op0) == PLUS
5136 283215 : && GET_CODE (XEXP (op0, 0)) == DEBUG_IMPLICIT_PTR))
5137 : /* (mem (debug_implicit_ptr)) might confuse aliasing.
5138 : Instead just use get_inner_reference. */
5139 46715 : goto component_ref;
5140 :
5141 2159114 : op1 = expand_debug_expr (TREE_OPERAND (exp, 1));
5142 2159114 : poly_int64 offset;
5143 2159114 : if (!op1 || !poly_int_rtx_p (op1, &offset))
5144 0 : return NULL;
5145 :
5146 2159114 : op0 = plus_constant (inner_mode, op0, offset);
5147 : }
5148 :
5149 2159114 : as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
5150 :
5151 2159114 : op0 = convert_debug_memory_address (targetm.addr_space.address_mode (as),
5152 : op0, as);
5153 2159114 : if (op0 == NULL_RTX)
5154 : return NULL;
5155 :
5156 2159114 : op0 = gen_rtx_MEM (mode, op0);
5157 2159114 : set_mem_attributes (op0, exp, 0);
5158 2159114 : if (TREE_CODE (exp) == MEM_REF
5159 2159114 : && !is_gimple_mem_ref_addr (TREE_OPERAND (exp, 0)))
5160 979748 : set_mem_expr (op0, NULL_TREE);
5161 2159114 : set_mem_addr_space (op0, as);
5162 :
5163 2159114 : return op0;
5164 :
5165 53930 : case TARGET_MEM_REF:
5166 53930 : if (TREE_CODE (TMR_BASE (exp)) == ADDR_EXPR
5167 53930 : && !DECL_RTL_SET_P (TREE_OPERAND (TMR_BASE (exp), 0)))
5168 : return NULL;
5169 :
5170 53922 : op0 = expand_debug_expr
5171 53922 : (tree_mem_ref_addr (build_pointer_type (TREE_TYPE (exp)), exp));
5172 53922 : if (!op0)
5173 : return NULL;
5174 :
5175 53922 : as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
5176 53922 : op0 = convert_debug_memory_address (targetm.addr_space.address_mode (as),
5177 : op0, as);
5178 53922 : if (op0 == NULL_RTX)
5179 : return NULL;
5180 :
5181 53922 : op0 = gen_rtx_MEM (mode, op0);
5182 :
5183 53922 : set_mem_attributes (op0, exp, 0);
5184 53922 : set_mem_addr_space (op0, as);
5185 :
5186 53922 : return op0;
5187 :
5188 46715 : component_ref:
5189 3867260 : case ARRAY_REF:
5190 3867260 : case ARRAY_RANGE_REF:
5191 3867260 : case COMPONENT_REF:
5192 3867260 : case BIT_FIELD_REF:
5193 3867260 : case REALPART_EXPR:
5194 3867260 : case IMAGPART_EXPR:
5195 3867260 : case VIEW_CONVERT_EXPR:
5196 3867260 : {
5197 3867260 : machine_mode mode1;
5198 3867260 : poly_int64 bitsize, bitpos;
5199 3867260 : tree offset;
5200 3867260 : int reversep, volatilep = 0;
5201 3867260 : tree tem
5202 3867260 : = get_inner_reference (exp, &bitsize, &bitpos, &offset, &mode1,
5203 : &unsignedp, &reversep, &volatilep);
5204 3867260 : rtx orig_op0;
5205 :
5206 3867260 : if (known_eq (bitsize, 0))
5207 : return NULL;
5208 :
5209 3807908 : orig_op0 = op0 = expand_debug_expr (tem);
5210 :
5211 3807908 : if (!op0)
5212 : return NULL;
5213 :
5214 3458717 : if (offset)
5215 : {
5216 11080 : machine_mode addrmode, offmode;
5217 :
5218 11080 : if (!MEM_P (op0))
5219 : return NULL;
5220 :
5221 11072 : op0 = XEXP (op0, 0);
5222 11072 : addrmode = GET_MODE (op0);
5223 11072 : if (addrmode == VOIDmode)
5224 0 : addrmode = Pmode;
5225 :
5226 11072 : op1 = expand_debug_expr (offset);
5227 11072 : if (!op1)
5228 : return NULL;
5229 :
5230 11070 : offmode = GET_MODE (op1);
5231 11070 : if (offmode == VOIDmode)
5232 6 : offmode = TYPE_MODE (TREE_TYPE (offset));
5233 :
5234 11070 : if (addrmode != offmode)
5235 0 : op1 = lowpart_subreg (addrmode, op1, offmode);
5236 :
5237 : /* Don't use offset_address here, we don't need a
5238 : recognizable address, and we don't want to generate
5239 : code. */
5240 11070 : op0 = gen_rtx_MEM (mode, simplify_gen_binary (PLUS, addrmode,
5241 : op0, op1));
5242 : }
5243 :
5244 3458707 : if (MEM_P (op0))
5245 : {
5246 3321594 : if (mode1 == VOIDmode)
5247 : {
5248 3466 : if (maybe_gt (bitsize, MAX_BITSIZE_MODE_ANY_INT))
5249 3867260 : return NULL;
5250 : /* Bitfield. */
5251 3466 : mode1 = smallest_int_mode_for_size (bitsize).require ();
5252 : }
5253 3321594 : poly_int64 bytepos = bits_to_bytes_round_down (bitpos);
5254 3321594 : if (maybe_ne (bytepos, 0))
5255 : {
5256 1350923 : op0 = adjust_address_nv (op0, mode1, bytepos);
5257 1350923 : bitpos = num_trailing_bits (bitpos);
5258 : }
5259 1970671 : else if (known_eq (bitpos, 0)
5260 3940714 : && known_eq (bitsize, GET_MODE_BITSIZE (mode)))
5261 511859 : op0 = adjust_address_nv (op0, mode, 0);
5262 1458812 : else if (GET_MODE (op0) != mode1)
5263 3122 : op0 = adjust_address_nv (op0, mode1, 0);
5264 : else
5265 1455690 : op0 = copy_rtx (op0);
5266 3321594 : if (op0 == orig_op0)
5267 151674 : op0 = shallow_copy_rtx (op0);
5268 3321594 : if (TREE_CODE (tem) != SSA_NAME)
5269 3319058 : set_mem_attributes (op0, exp, 0);
5270 : }
5271 :
5272 3458707 : if (known_eq (bitpos, 0) && mode == GET_MODE (op0))
5273 : return op0;
5274 :
5275 102879 : if (maybe_lt (bitpos, 0))
5276 : return NULL;
5277 :
5278 102877 : if (GET_MODE (op0) == BLKmode || mode == BLKmode)
5279 : return NULL;
5280 :
5281 102852 : poly_int64 bytepos;
5282 102852 : if (multiple_p (bitpos, BITS_PER_UNIT, &bytepos)
5283 202526 : && known_eq (bitsize, GET_MODE_BITSIZE (mode1)))
5284 : {
5285 100433 : machine_mode opmode = GET_MODE (op0);
5286 :
5287 100433 : if (opmode == VOIDmode)
5288 0 : opmode = TYPE_MODE (TREE_TYPE (tem));
5289 :
5290 : /* This condition may hold if we're expanding the address
5291 : right past the end of an array that turned out not to
5292 : be addressable (i.e., the address was only computed in
5293 : debug stmts). The gen_subreg below would rightfully
5294 : crash, and the address doesn't really exist, so just
5295 : drop it. */
5296 200866 : if (known_ge (bitpos, GET_MODE_BITSIZE (opmode)))
5297 : return NULL;
5298 :
5299 203233 : if (multiple_p (bitpos, GET_MODE_BITSIZE (mode)))
5300 100361 : return simplify_gen_subreg (mode, op0, opmode, bytepos);
5301 : }
5302 :
5303 4930 : return simplify_gen_ternary (SCALAR_INT_MODE_P (GET_MODE (op0))
5304 1852 : && TYPE_UNSIGNED (TREE_TYPE (exp))
5305 : ? SIGN_EXTRACT
5306 : : ZERO_EXTRACT, mode,
5307 2465 : GET_MODE (op0) != VOIDmode
5308 : ? GET_MODE (op0)
5309 0 : : TYPE_MODE (TREE_TYPE (tem)),
5310 : op0, gen_int_mode (bitsize, word_mode),
5311 2465 : gen_int_mode (bitpos, word_mode));
5312 : }
5313 :
5314 3964 : case ABS_EXPR:
5315 3964 : case ABSU_EXPR:
5316 3964 : return simplify_gen_unary (ABS, mode, op0, mode);
5317 :
5318 14248 : case NEGATE_EXPR:
5319 14248 : return simplify_gen_unary (NEG, mode, op0, mode);
5320 :
5321 20629 : case BIT_NOT_EXPR:
5322 20629 : return simplify_gen_unary (NOT, mode, op0, mode);
5323 :
5324 3288 : case FLOAT_EXPR:
5325 3288 : return simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp,
5326 : 0)))
5327 : ? UNSIGNED_FLOAT : FLOAT, mode, op0,
5328 3288 : inner_mode);
5329 :
5330 458 : case FIX_TRUNC_EXPR:
5331 458 : return simplify_gen_unary (unsignedp ? UNSIGNED_FIX : FIX, mode, op0,
5332 458 : inner_mode);
5333 :
5334 237000 : case POINTER_PLUS_EXPR:
5335 : /* For the rare target where pointers are not the same size as
5336 : size_t, we need to check for mis-matched modes and correct
5337 : the addend. */
5338 237000 : if (op0 && op1
5339 237000 : && is_a <scalar_int_mode> (GET_MODE (op0), &op0_mode)
5340 236893 : && is_a <scalar_int_mode> (GET_MODE (op1), &op1_mode)
5341 376174 : && op0_mode != op1_mode)
5342 : {
5343 0 : if (GET_MODE_BITSIZE (op0_mode) < GET_MODE_BITSIZE (op1_mode)
5344 : /* If OP0 is a partial mode, then we must truncate, even
5345 : if it has the same bitsize as OP1 as GCC's
5346 : representation of partial modes is opaque. */
5347 0 : || (GET_MODE_CLASS (op0_mode) == MODE_PARTIAL_INT
5348 0 : && (GET_MODE_BITSIZE (op0_mode)
5349 0 : == GET_MODE_BITSIZE (op1_mode))))
5350 0 : op1 = simplify_gen_unary (TRUNCATE, op0_mode, op1, op1_mode);
5351 : else
5352 : /* We always sign-extend, regardless of the signedness of
5353 : the operand, because the operand is always unsigned
5354 : here even if the original C expression is signed. */
5355 0 : op1 = simplify_gen_unary (SIGN_EXTEND, op0_mode, op1, op1_mode);
5356 : }
5357 : /* Fall through. */
5358 729514 : case PLUS_EXPR:
5359 729514 : return simplify_gen_binary (PLUS, mode, op0, op1);
5360 :
5361 112209 : case MINUS_EXPR:
5362 112209 : case POINTER_DIFF_EXPR:
5363 112209 : return simplify_gen_binary (MINUS, mode, op0, op1);
5364 :
5365 177042 : case MULT_EXPR:
5366 177042 : return simplify_gen_binary (MULT, mode, op0, op1);
5367 :
5368 4117 : case RDIV_EXPR:
5369 4117 : gcc_assert (FLOAT_MODE_P (mode)
5370 : || ALL_FIXED_POINT_MODE_P (mode));
5371 : /* Fall through. */
5372 100550 : case TRUNC_DIV_EXPR:
5373 100550 : case EXACT_DIV_EXPR:
5374 100550 : if (unsignedp)
5375 10412 : return simplify_gen_binary (UDIV, mode, op0, op1);
5376 : else
5377 90138 : return simplify_gen_binary (DIV, mode, op0, op1);
5378 :
5379 4212 : case TRUNC_MOD_EXPR:
5380 8424 : return simplify_gen_binary (unsignedp ? UMOD : MOD, mode, op0, op1);
5381 :
5382 3 : case FLOOR_DIV_EXPR:
5383 3 : if (unsignedp)
5384 0 : return simplify_gen_binary (UDIV, mode, op0, op1);
5385 : else
5386 : {
5387 3 : rtx div = simplify_gen_binary (DIV, mode, op0, op1);
5388 3 : rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
5389 3 : rtx adj = floor_sdiv_adjust (mode, mod, op1);
5390 3 : return simplify_gen_binary (PLUS, mode, div, adj);
5391 : }
5392 :
5393 1 : case FLOOR_MOD_EXPR:
5394 1 : if (unsignedp)
5395 0 : return simplify_gen_binary (UMOD, mode, op0, op1);
5396 : else
5397 : {
5398 1 : rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
5399 1 : rtx adj = floor_sdiv_adjust (mode, mod, op1);
5400 1 : adj = simplify_gen_unary (NEG, mode,
5401 : simplify_gen_binary (MULT, mode, adj, op1),
5402 : mode);
5403 1 : return simplify_gen_binary (PLUS, mode, mod, adj);
5404 : }
5405 :
5406 3 : case CEIL_DIV_EXPR:
5407 3 : if (unsignedp)
5408 : {
5409 0 : rtx div = simplify_gen_binary (UDIV, mode, op0, op1);
5410 0 : rtx mod = simplify_gen_binary (UMOD, mode, op0, op1);
5411 0 : rtx adj = ceil_udiv_adjust (mode, mod, op1);
5412 0 : return simplify_gen_binary (PLUS, mode, div, adj);
5413 : }
5414 : else
5415 : {
5416 3 : rtx div = simplify_gen_binary (DIV, mode, op0, op1);
5417 3 : rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
5418 3 : rtx adj = ceil_sdiv_adjust (mode, mod, op1);
5419 3 : return simplify_gen_binary (PLUS, mode, div, adj);
5420 : }
5421 :
5422 0 : case CEIL_MOD_EXPR:
5423 0 : if (unsignedp)
5424 : {
5425 0 : rtx mod = simplify_gen_binary (UMOD, mode, op0, op1);
5426 0 : rtx adj = ceil_udiv_adjust (mode, mod, op1);
5427 0 : adj = simplify_gen_unary (NEG, mode,
5428 : simplify_gen_binary (MULT, mode, adj, op1),
5429 : mode);
5430 0 : return simplify_gen_binary (PLUS, mode, mod, adj);
5431 : }
5432 : else
5433 : {
5434 0 : rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
5435 0 : rtx adj = ceil_sdiv_adjust (mode, mod, op1);
5436 0 : adj = simplify_gen_unary (NEG, mode,
5437 : simplify_gen_binary (MULT, mode, adj, op1),
5438 : mode);
5439 0 : return simplify_gen_binary (PLUS, mode, mod, adj);
5440 : }
5441 :
5442 0 : case ROUND_DIV_EXPR:
5443 0 : if (unsignedp)
5444 : {
5445 0 : rtx div = simplify_gen_binary (UDIV, mode, op0, op1);
5446 0 : rtx mod = simplify_gen_binary (UMOD, mode, op0, op1);
5447 0 : rtx adj = round_udiv_adjust (mode, mod, op1);
5448 0 : return simplify_gen_binary (PLUS, mode, div, adj);
5449 : }
5450 : else
5451 : {
5452 0 : rtx div = simplify_gen_binary (DIV, mode, op0, op1);
5453 0 : rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
5454 0 : rtx adj = round_sdiv_adjust (mode, mod, op1);
5455 0 : return simplify_gen_binary (PLUS, mode, div, adj);
5456 : }
5457 :
5458 0 : case ROUND_MOD_EXPR:
5459 0 : if (unsignedp)
5460 : {
5461 0 : rtx mod = simplify_gen_binary (UMOD, mode, op0, op1);
5462 0 : rtx adj = round_udiv_adjust (mode, mod, op1);
5463 0 : adj = simplify_gen_unary (NEG, mode,
5464 : simplify_gen_binary (MULT, mode, adj, op1),
5465 : mode);
5466 0 : return simplify_gen_binary (PLUS, mode, mod, adj);
5467 : }
5468 : else
5469 : {
5470 0 : rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
5471 0 : rtx adj = round_sdiv_adjust (mode, mod, op1);
5472 0 : adj = simplify_gen_unary (NEG, mode,
5473 : simplify_gen_binary (MULT, mode, adj, op1),
5474 : mode);
5475 0 : return simplify_gen_binary (PLUS, mode, mod, adj);
5476 : }
5477 :
5478 14670 : case LSHIFT_EXPR:
5479 14670 : return simplify_gen_binary (ASHIFT, mode, op0, op1);
5480 :
5481 67159 : case RSHIFT_EXPR:
5482 67159 : if (unsignedp)
5483 60971 : return simplify_gen_binary (LSHIFTRT, mode, op0, op1);
5484 : else
5485 6188 : return simplify_gen_binary (ASHIFTRT, mode, op0, op1);
5486 :
5487 2 : case LROTATE_EXPR:
5488 2 : return simplify_gen_binary (ROTATE, mode, op0, op1);
5489 :
5490 883 : case RROTATE_EXPR:
5491 883 : return simplify_gen_binary (ROTATERT, mode, op0, op1);
5492 :
5493 39695 : case MIN_EXPR:
5494 79390 : return simplify_gen_binary (unsignedp ? UMIN : SMIN, mode, op0, op1);
5495 :
5496 39308 : case MAX_EXPR:
5497 78616 : return simplify_gen_binary (unsignedp ? UMAX : SMAX, mode, op0, op1);
5498 :
5499 92778 : case BIT_AND_EXPR:
5500 92778 : case TRUTH_AND_EXPR:
5501 92778 : return simplify_gen_binary (AND, mode, op0, op1);
5502 :
5503 43230 : case BIT_IOR_EXPR:
5504 43230 : case TRUTH_OR_EXPR:
5505 43230 : return simplify_gen_binary (IOR, mode, op0, op1);
5506 :
5507 11214 : case BIT_XOR_EXPR:
5508 11214 : case TRUTH_XOR_EXPR:
5509 11214 : return simplify_gen_binary (XOR, mode, op0, op1);
5510 :
5511 0 : case TRUTH_ANDIF_EXPR:
5512 0 : return gen_rtx_IF_THEN_ELSE (mode, op0, op1, const0_rtx);
5513 :
5514 0 : case TRUTH_ORIF_EXPR:
5515 0 : return gen_rtx_IF_THEN_ELSE (mode, op0, const_true_rtx, op1);
5516 :
5517 0 : case TRUTH_NOT_EXPR:
5518 0 : return simplify_gen_relational (EQ, mode, inner_mode, op0, const0_rtx);
5519 :
5520 5249 : case LT_EXPR:
5521 5249 : return simplify_gen_relational (unsignedp ? LTU : LT, mode, inner_mode,
5522 5249 : op0, op1);
5523 :
5524 6252 : case LE_EXPR:
5525 6252 : return simplify_gen_relational (unsignedp ? LEU : LE, mode, inner_mode,
5526 6252 : op0, op1);
5527 :
5528 9815 : case GT_EXPR:
5529 9815 : return simplify_gen_relational (unsignedp ? GTU : GT, mode, inner_mode,
5530 9815 : op0, op1);
5531 :
5532 3103 : case GE_EXPR:
5533 3103 : return simplify_gen_relational (unsignedp ? GEU : GE, mode, inner_mode,
5534 3103 : op0, op1);
5535 :
5536 30684 : case EQ_EXPR:
5537 30684 : return simplify_gen_relational (EQ, mode, inner_mode, op0, op1);
5538 :
5539 14597 : case NE_EXPR:
5540 14597 : return simplify_gen_relational (NE, mode, inner_mode, op0, op1);
5541 :
5542 1587 : case UNORDERED_EXPR:
5543 1587 : return simplify_gen_relational (UNORDERED, mode, inner_mode, op0, op1);
5544 :
5545 1 : case ORDERED_EXPR:
5546 1 : return simplify_gen_relational (ORDERED, mode, inner_mode, op0, op1);
5547 :
5548 0 : case UNLT_EXPR:
5549 0 : return simplify_gen_relational (UNLT, mode, inner_mode, op0, op1);
5550 :
5551 1576 : case UNLE_EXPR:
5552 1576 : return simplify_gen_relational (UNLE, mode, inner_mode, op0, op1);
5553 :
5554 0 : case UNGT_EXPR:
5555 0 : return simplify_gen_relational (UNGT, mode, inner_mode, op0, op1);
5556 :
5557 0 : case UNGE_EXPR:
5558 0 : return simplify_gen_relational (UNGE, mode, inner_mode, op0, op1);
5559 :
5560 0 : case UNEQ_EXPR:
5561 0 : return simplify_gen_relational (UNEQ, mode, inner_mode, op0, op1);
5562 :
5563 0 : case LTGT_EXPR:
5564 0 : return simplify_gen_relational (LTGT, mode, inner_mode, op0, op1);
5565 :
5566 8338 : case COND_EXPR:
5567 8338 : return gen_rtx_IF_THEN_ELSE (mode, op0, op1, op2);
5568 :
5569 10733 : case COMPLEX_EXPR:
5570 10733 : gcc_assert (COMPLEX_MODE_P (mode));
5571 10733 : if (GET_MODE (op0) == VOIDmode)
5572 4 : op0 = gen_rtx_CONST (GET_MODE_INNER (mode), op0);
5573 10733 : if (GET_MODE (op1) == VOIDmode)
5574 0 : op1 = gen_rtx_CONST (GET_MODE_INNER (mode), op1);
5575 10733 : return gen_rtx_CONCAT (mode, op0, op1);
5576 :
5577 0 : case CONJ_EXPR:
5578 0 : if (GET_CODE (op0) == CONCAT)
5579 0 : return gen_rtx_CONCAT (mode, XEXP (op0, 0),
5580 : simplify_gen_unary (NEG, GET_MODE_INNER (mode),
5581 : XEXP (op0, 1),
5582 : GET_MODE_INNER (mode)));
5583 : else
5584 : {
5585 0 : scalar_mode imode = GET_MODE_INNER (mode);
5586 0 : rtx re, im;
5587 :
5588 0 : if (MEM_P (op0))
5589 : {
5590 0 : re = adjust_address_nv (op0, imode, 0);
5591 0 : im = adjust_address_nv (op0, imode, GET_MODE_SIZE (imode));
5592 : }
5593 : else
5594 : {
5595 0 : scalar_int_mode ifmode;
5596 0 : scalar_int_mode ihmode;
5597 0 : rtx halfsize;
5598 0 : if (!int_mode_for_mode (mode).exists (&ifmode)
5599 0 : || !int_mode_for_mode (imode).exists (&ihmode))
5600 43222178 : return NULL;
5601 0 : halfsize = GEN_INT (GET_MODE_BITSIZE (ihmode));
5602 0 : re = op0;
5603 0 : if (mode != ifmode)
5604 0 : re = gen_rtx_SUBREG (ifmode, re, 0);
5605 0 : re = gen_rtx_ZERO_EXTRACT (ihmode, re, halfsize, const0_rtx);
5606 0 : if (imode != ihmode)
5607 0 : re = gen_rtx_SUBREG (imode, re, 0);
5608 0 : im = copy_rtx (op0);
5609 0 : if (mode != ifmode)
5610 0 : im = gen_rtx_SUBREG (ifmode, im, 0);
5611 0 : im = gen_rtx_ZERO_EXTRACT (ihmode, im, halfsize, halfsize);
5612 0 : if (imode != ihmode)
5613 0 : im = gen_rtx_SUBREG (imode, im, 0);
5614 : }
5615 0 : im = gen_rtx_NEG (imode, im);
5616 0 : return gen_rtx_CONCAT (mode, re, im);
5617 : }
5618 :
5619 7092782 : case ADDR_EXPR:
5620 7092782 : op0 = expand_debug_expr (TREE_OPERAND (exp, 0));
5621 7092782 : if (!op0 || !MEM_P (op0))
5622 : {
5623 1890931 : if ((TREE_CODE (TREE_OPERAND (exp, 0)) == VAR_DECL
5624 437657 : || TREE_CODE (TREE_OPERAND (exp, 0)) == PARM_DECL
5625 388740 : || TREE_CODE (TREE_OPERAND (exp, 0)) == RESULT_DECL)
5626 1939848 : && (!TREE_ADDRESSABLE (TREE_OPERAND (exp, 0))
5627 189305 : || target_for_debug_bind (TREE_OPERAND (exp, 0))))
5628 1324269 : return gen_rtx_DEBUG_IMPLICIT_PTR (mode, TREE_OPERAND (exp, 0));
5629 :
5630 566662 : if (handled_component_p (TREE_OPERAND (exp, 0)))
5631 : {
5632 363294 : poly_int64 bitoffset, bitsize, maxsize, byteoffset;
5633 363294 : bool reverse;
5634 363294 : tree decl
5635 363294 : = get_ref_base_and_extent (TREE_OPERAND (exp, 0), &bitoffset,
5636 : &bitsize, &maxsize, &reverse);
5637 363294 : if ((VAR_P (decl)
5638 : || TREE_CODE (decl) == PARM_DECL
5639 : || TREE_CODE (decl) == RESULT_DECL)
5640 331770 : && (!TREE_ADDRESSABLE (decl)
5641 30160 : || target_for_debug_bind (decl))
5642 78667 : && multiple_p (bitoffset, BITS_PER_UNIT, &byteoffset)
5643 301610 : && known_gt (bitsize, 0)
5644 284630 : && known_eq (bitsize, maxsize))
5645 : {
5646 284627 : rtx base = gen_rtx_DEBUG_IMPLICIT_PTR (mode, decl);
5647 284627 : return plus_constant (mode, base, byteoffset);
5648 : }
5649 : }
5650 :
5651 282035 : if (TREE_CODE (TREE_OPERAND (exp, 0)) == MEM_REF
5652 282035 : && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
5653 : == ADDR_EXPR)
5654 : {
5655 12098 : op0 = expand_debug_expr (TREE_OPERAND (TREE_OPERAND (exp, 0),
5656 : 0));
5657 12098 : if (op0 != NULL
5658 6372 : && (GET_CODE (op0) == DEBUG_IMPLICIT_PTR
5659 0 : || (GET_CODE (op0) == PLUS
5660 0 : && GET_CODE (XEXP (op0, 0)) == DEBUG_IMPLICIT_PTR
5661 0 : && CONST_INT_P (XEXP (op0, 1)))))
5662 : {
5663 6372 : op1 = expand_debug_expr (TREE_OPERAND (TREE_OPERAND (exp, 0),
5664 : 1));
5665 6372 : poly_int64 offset;
5666 12744 : if (!op1 || !poly_int_rtx_p (op1, &offset))
5667 : return NULL;
5668 :
5669 6372 : return plus_constant (mode, op0, offset);
5670 : }
5671 : }
5672 :
5673 : return NULL;
5674 : }
5675 :
5676 5201851 : as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)));
5677 5201851 : addr_mode = SCALAR_INT_TYPE_MODE (TREE_TYPE (exp));
5678 5201851 : op0 = convert_debug_memory_address (addr_mode, XEXP (op0, 0), as);
5679 :
5680 5201851 : return op0;
5681 :
5682 11860 : case VECTOR_CST:
5683 11860 : {
5684 11860 : unsigned HOST_WIDE_INT i, nelts;
5685 :
5686 11860 : if (!VECTOR_CST_NELTS (exp).is_constant (&nelts))
5687 : return NULL;
5688 :
5689 11860 : op0 = gen_rtx_CONCATN (mode, rtvec_alloc (nelts));
5690 :
5691 65986 : for (i = 0; i < nelts; ++i)
5692 : {
5693 54126 : op1 = expand_debug_expr (VECTOR_CST_ELT (exp, i));
5694 54126 : if (!op1)
5695 : return NULL;
5696 54126 : XVECEXP (op0, 0, i) = op1;
5697 : }
5698 :
5699 : return op0;
5700 : }
5701 :
5702 1114 : case CONSTRUCTOR:
5703 1114 : if (TREE_CLOBBER_P (exp))
5704 : return NULL;
5705 1114 : else if (TREE_CODE (TREE_TYPE (exp)) == VECTOR_TYPE)
5706 : {
5707 1114 : unsigned i;
5708 1114 : poly_uint64 elts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp));
5709 1114 : unsigned HOST_WIDE_INT nelts = constant_lower_bound (elts);
5710 1114 : tree val;
5711 :
5712 1114 : op0 = gen_rtx_CONCATN (mode, rtvec_alloc (nelts));
5713 :
5714 4931 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), i, val)
5715 : {
5716 3956 : op1 = expand_debug_expr (val);
5717 3956 : if (!op1)
5718 : return NULL;
5719 3817 : XVECEXP (op0, 0, i) = op1;
5720 : }
5721 :
5722 975 : if (i < nelts)
5723 : {
5724 117 : op1 = expand_debug_expr
5725 117 : (build_zero_cst (TREE_TYPE (TREE_TYPE (exp))));
5726 :
5727 117 : if (!op1)
5728 : return NULL;
5729 :
5730 384 : for (; i < nelts; i++)
5731 267 : XVECEXP (op0, 0, i) = op1;
5732 : }
5733 :
5734 : return op0;
5735 : }
5736 : else
5737 0 : goto flag_unsupported;
5738 :
5739 : case CALL_EXPR:
5740 : /* ??? Maybe handle some builtins? */
5741 : return NULL;
5742 :
5743 9733488 : case SSA_NAME:
5744 9733488 : {
5745 9733488 : gimple *g = get_gimple_for_ssa_name (exp);
5746 9733488 : if (g)
5747 : {
5748 1497978 : tree t = NULL_TREE;
5749 1497978 : if (deep_ter_debug_map)
5750 : {
5751 72805 : tree *slot = deep_ter_debug_map->get (exp);
5752 72805 : if (slot)
5753 19372 : t = *slot;
5754 : }
5755 19372 : if (t == NULL_TREE)
5756 : {
5757 1484035 : if (gassign *ga = dyn_cast<gassign *> (g))
5758 1483590 : t = gimple_assign_rhs_to_tree (ga);
5759 : else
5760 : /* expand_debug_expr doesn't handle CALL_EXPR right now. */
5761 : return NULL;
5762 : }
5763 1497533 : op0 = expand_debug_expr (t);
5764 1497533 : if (!op0)
5765 : return NULL;
5766 : }
5767 : else
5768 : {
5769 : /* If this is a reference to an incoming value of
5770 : parameter that is never used in the code or where the
5771 : incoming value is never used in the code, use
5772 : PARM_DECL's DECL_RTL if set. */
5773 8235510 : if (SSA_NAME_IS_DEFAULT_DEF (exp)
5774 1329707 : && SSA_NAME_VAR (exp)
5775 1329707 : && TREE_CODE (SSA_NAME_VAR (exp)) == PARM_DECL
5776 9505251 : && has_zero_uses (exp))
5777 : {
5778 18620 : op0 = expand_debug_parm_decl (SSA_NAME_VAR (exp));
5779 18620 : if (op0)
5780 18612 : goto adjust_mode;
5781 8 : op0 = expand_debug_expr (SSA_NAME_VAR (exp));
5782 8 : if (op0)
5783 8 : goto adjust_mode;
5784 : }
5785 :
5786 8216890 : int part = var_to_partition (SA.map, exp);
5787 :
5788 8216890 : if (part == NO_PARTITION)
5789 : return NULL;
5790 :
5791 8212616 : gcc_assert (part >= 0 && (unsigned)part < SA.map->num_partitions);
5792 :
5793 8212616 : op0 = copy_rtx (SA.partition_to_pseudo[part]);
5794 : }
5795 9703675 : goto adjust_mode;
5796 : }
5797 :
5798 : case ERROR_MARK:
5799 : return NULL;
5800 :
5801 : /* Vector stuff. For most of the codes we don't have rtl codes. */
5802 : case REALIGN_LOAD_EXPR:
5803 : case VEC_COND_EXPR:
5804 : case VEC_PACK_FIX_TRUNC_EXPR:
5805 : case VEC_PACK_FLOAT_EXPR:
5806 : case VEC_PACK_SAT_EXPR:
5807 : case VEC_PACK_TRUNC_EXPR:
5808 : case VEC_UNPACK_FIX_TRUNC_HI_EXPR:
5809 : case VEC_UNPACK_FIX_TRUNC_LO_EXPR:
5810 : case VEC_UNPACK_FLOAT_HI_EXPR:
5811 : case VEC_UNPACK_FLOAT_LO_EXPR:
5812 : case VEC_UNPACK_HI_EXPR:
5813 : case VEC_UNPACK_LO_EXPR:
5814 : case VEC_WIDEN_MULT_HI_EXPR:
5815 : case VEC_WIDEN_MULT_LO_EXPR:
5816 : case VEC_WIDEN_MULT_EVEN_EXPR:
5817 : case VEC_WIDEN_MULT_ODD_EXPR:
5818 : case VEC_WIDEN_LSHIFT_HI_EXPR:
5819 : case VEC_WIDEN_LSHIFT_LO_EXPR:
5820 : case VEC_PERM_EXPR:
5821 : case VEC_DUPLICATE_EXPR:
5822 : case VEC_SERIES_EXPR:
5823 : case SAD_EXPR:
5824 : return NULL;
5825 :
5826 : /* Misc codes. */
5827 : case ADDR_SPACE_CONVERT_EXPR:
5828 : case FIXED_CONVERT_EXPR:
5829 : case OBJ_TYPE_REF:
5830 : case WITH_SIZE_EXPR:
5831 : case BIT_INSERT_EXPR:
5832 : return NULL;
5833 :
5834 0 : case DOT_PROD_EXPR:
5835 0 : if (SCALAR_INT_MODE_P (GET_MODE (op0))
5836 0 : && SCALAR_INT_MODE_P (mode))
5837 : {
5838 0 : op0
5839 0 : = simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp,
5840 : 0)))
5841 : ? ZERO_EXTEND : SIGN_EXTEND, mode, op0,
5842 : inner_mode);
5843 0 : op1
5844 0 : = simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp,
5845 : 1)))
5846 : ? ZERO_EXTEND : SIGN_EXTEND, mode, op1,
5847 : inner_mode);
5848 0 : op0 = simplify_gen_binary (MULT, mode, op0, op1);
5849 0 : return simplify_gen_binary (PLUS, mode, op0, op2);
5850 : }
5851 : return NULL;
5852 :
5853 5954 : case WIDEN_MULT_EXPR:
5854 5954 : case WIDEN_MULT_PLUS_EXPR:
5855 5954 : case WIDEN_MULT_MINUS_EXPR:
5856 5954 : if (SCALAR_INT_MODE_P (GET_MODE (op0))
5857 5954 : && SCALAR_INT_MODE_P (mode))
5858 : {
5859 5954 : inner_mode = GET_MODE (op0);
5860 5954 : if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))))
5861 5338 : op0 = simplify_gen_unary (ZERO_EXTEND, mode, op0, inner_mode);
5862 : else
5863 616 : op0 = simplify_gen_unary (SIGN_EXTEND, mode, op0, inner_mode);
5864 5954 : if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 1))))
5865 5338 : op1 = simplify_gen_unary (ZERO_EXTEND, mode, op1, inner_mode);
5866 : else
5867 616 : op1 = simplify_gen_unary (SIGN_EXTEND, mode, op1, inner_mode);
5868 5954 : op0 = simplify_gen_binary (MULT, mode, op0, op1);
5869 5954 : if (TREE_CODE (exp) == WIDEN_MULT_EXPR)
5870 : return op0;
5871 0 : else if (TREE_CODE (exp) == WIDEN_MULT_PLUS_EXPR)
5872 0 : return simplify_gen_binary (PLUS, mode, op0, op2);
5873 : else
5874 0 : return simplify_gen_binary (MINUS, mode, op2, op0);
5875 : }
5876 : return NULL;
5877 :
5878 : case MULT_HIGHPART_EXPR:
5879 : /* ??? Similar to the above. */
5880 : return NULL;
5881 :
5882 0 : case WIDEN_SUM_EXPR:
5883 0 : case WIDEN_LSHIFT_EXPR:
5884 0 : if (SCALAR_INT_MODE_P (GET_MODE (op0))
5885 0 : && SCALAR_INT_MODE_P (mode))
5886 : {
5887 0 : op0
5888 0 : = simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp,
5889 : 0)))
5890 : ? ZERO_EXTEND : SIGN_EXTEND, mode, op0,
5891 : inner_mode);
5892 0 : return simplify_gen_binary (TREE_CODE (exp) == WIDEN_LSHIFT_EXPR
5893 0 : ? ASHIFT : PLUS, mode, op0, op1);
5894 : }
5895 : return NULL;
5896 :
5897 0 : default:
5898 0 : flag_unsupported:
5899 0 : if (flag_checking)
5900 : {
5901 0 : debug_tree (exp);
5902 0 : gcc_unreachable ();
5903 : }
5904 : return NULL;
5905 : }
5906 : }
5907 :
5908 : /* Return an RTX equivalent to the source bind value of the tree expression
5909 : EXP. */
5910 :
5911 : static rtx
5912 175666 : expand_debug_source_expr (tree exp)
5913 : {
5914 330360 : rtx op0 = NULL_RTX;
5915 330360 : machine_mode mode = VOIDmode, inner_mode;
5916 :
5917 330360 : switch (TREE_CODE (exp))
5918 : {
5919 154694 : case VAR_DECL:
5920 154694 : if (DECL_ABSTRACT_ORIGIN (exp))
5921 154694 : return expand_debug_source_expr (DECL_ABSTRACT_ORIGIN (exp));
5922 : break;
5923 170743 : case PARM_DECL:
5924 170743 : {
5925 170743 : mode = DECL_MODE (exp);
5926 170743 : op0 = expand_debug_parm_decl (exp);
5927 170743 : if (op0)
5928 : break;
5929 : /* See if this isn't an argument that has been completely
5930 : optimized out. */
5931 169781 : if (!DECL_RTL_SET_P (exp)
5932 169765 : && !DECL_INCOMING_RTL (exp)
5933 339546 : && DECL_ABSTRACT_ORIGIN (current_function_decl))
5934 : {
5935 58431 : tree aexp = DECL_ORIGIN (exp);
5936 58431 : if (DECL_CONTEXT (aexp)
5937 58431 : == DECL_ABSTRACT_ORIGIN (current_function_decl))
5938 : {
5939 19056 : vec<tree, va_gc> **debug_args;
5940 19056 : unsigned int ix;
5941 19056 : tree ddecl;
5942 19056 : debug_args = decl_debug_args_lookup (current_function_decl);
5943 19056 : if (debug_args != NULL)
5944 : {
5945 23369 : for (ix = 0; vec_safe_iterate (*debug_args, ix, &ddecl);
5946 4317 : ix += 2)
5947 23361 : if (ddecl == aexp)
5948 19044 : return gen_rtx_DEBUG_PARAMETER_REF (mode, aexp);
5949 : }
5950 : }
5951 : }
5952 : break;
5953 : }
5954 : default:
5955 : break;
5956 : }
5957 :
5958 : if (op0 == NULL_RTX)
5959 : return NULL_RTX;
5960 :
5961 962 : inner_mode = GET_MODE (op0);
5962 962 : if (mode == inner_mode)
5963 : return op0;
5964 :
5965 21 : if (FLOAT_MODE_P (mode) && FLOAT_MODE_P (inner_mode))
5966 : {
5967 7 : if (GET_MODE_UNIT_BITSIZE (mode)
5968 14 : == GET_MODE_UNIT_BITSIZE (inner_mode))
5969 0 : op0 = simplify_gen_subreg (mode, op0, inner_mode, 0);
5970 7 : else if (GET_MODE_UNIT_BITSIZE (mode)
5971 14 : < GET_MODE_UNIT_BITSIZE (inner_mode))
5972 7 : op0 = simplify_gen_unary (FLOAT_TRUNCATE, mode, op0, inner_mode);
5973 : else
5974 0 : op0 = simplify_gen_unary (FLOAT_EXTEND, mode, op0, inner_mode);
5975 : }
5976 14 : else if (FLOAT_MODE_P (mode))
5977 0 : gcc_unreachable ();
5978 14 : else if (FLOAT_MODE_P (inner_mode))
5979 : {
5980 0 : if (TYPE_UNSIGNED (TREE_TYPE (exp)))
5981 0 : op0 = simplify_gen_unary (UNSIGNED_FIX, mode, op0, inner_mode);
5982 : else
5983 0 : op0 = simplify_gen_unary (FIX, mode, op0, inner_mode);
5984 : }
5985 28 : else if (GET_MODE_UNIT_PRECISION (mode)
5986 14 : == GET_MODE_UNIT_PRECISION (inner_mode))
5987 0 : op0 = lowpart_subreg (mode, op0, inner_mode);
5988 28 : else if (GET_MODE_UNIT_PRECISION (mode)
5989 14 : < GET_MODE_UNIT_PRECISION (inner_mode))
5990 14 : op0 = simplify_gen_unary (TRUNCATE, mode, op0, inner_mode);
5991 0 : else if (TYPE_UNSIGNED (TREE_TYPE (exp)))
5992 0 : op0 = simplify_gen_unary (ZERO_EXTEND, mode, op0, inner_mode);
5993 : else
5994 0 : op0 = simplify_gen_unary (SIGN_EXTEND, mode, op0, inner_mode);
5995 :
5996 : return op0;
5997 : }
5998 :
5999 : /* Ensure INSN_VAR_LOCATION_LOC (insn) doesn't have unbound complexity.
6000 : Allow 4 levels of rtl nesting for most rtl codes, and if we see anything
6001 : deeper than that, create DEBUG_EXPRs and emit DEBUG_INSNs before INSN. */
6002 :
6003 : static void
6004 53040013 : avoid_complex_debug_insns (rtx_insn *insn, rtx *exp_p, int depth)
6005 : {
6006 53040013 : rtx exp = *exp_p;
6007 :
6008 53040013 : if (exp == NULL_RTX)
6009 : return;
6010 :
6011 53040013 : if ((OBJECT_P (exp) && !MEM_P (exp)) || GET_CODE (exp) == CLOBBER)
6012 : return;
6013 :
6014 6831146 : if (depth == 4)
6015 : {
6016 : /* Create DEBUG_EXPR (and DEBUG_EXPR_DECL). */
6017 26124 : rtx dval = make_debug_expr_from_rtl (exp);
6018 :
6019 : /* Emit a debug bind insn before INSN. */
6020 26124 : rtx bind = gen_rtx_VAR_LOCATION (GET_MODE (exp),
6021 : DEBUG_EXPR_TREE_DECL (dval), exp,
6022 : VAR_INIT_STATUS_INITIALIZED);
6023 :
6024 26124 : emit_debug_insn_before (bind, insn);
6025 26124 : *exp_p = dval;
6026 26124 : return;
6027 : }
6028 :
6029 6805022 : const char *format_ptr = GET_RTX_FORMAT (GET_CODE (exp));
6030 6805022 : int i, j;
6031 20298346 : for (i = 0; i < GET_RTX_LENGTH (GET_CODE (exp)); i++)
6032 13493324 : switch (*format_ptr++)
6033 : {
6034 12440943 : case 'e':
6035 12440943 : avoid_complex_debug_insns (insn, &XEXP (exp, i), depth + 1);
6036 12440943 : break;
6037 :
6038 : case 'E':
6039 : case 'V':
6040 0 : for (j = 0; j < XVECLEN (exp, i); j++)
6041 0 : avoid_complex_debug_insns (insn, &XVECEXP (exp, i, j), depth + 1);
6042 : break;
6043 :
6044 : default:
6045 : break;
6046 : }
6047 : }
6048 :
6049 : /* Expand the _LOCs in debug insns. We run this after expanding all
6050 : regular insns, so that any variables referenced in the function
6051 : will have their DECL_RTLs set. */
6052 :
6053 : static void
6054 503353 : expand_debug_locations (void)
6055 : {
6056 503353 : rtx_insn *insn;
6057 503353 : rtx_insn *last = get_last_insn ();
6058 503353 : int save_strict_alias = flag_strict_aliasing;
6059 :
6060 : /* New alias sets while setting up memory attributes cause
6061 : -fcompare-debug failures, even though it doesn't bring about any
6062 : codegen changes. */
6063 503353 : flag_strict_aliasing = 0;
6064 :
6065 108954016 : for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
6066 160745789 : if (DEBUG_BIND_INSN_P (insn))
6067 : {
6068 40572946 : tree value = (tree)INSN_VAR_LOCATION_LOC (insn);
6069 40572946 : rtx val;
6070 40572946 : rtx_insn *prev_insn, *insn2;
6071 40572946 : machine_mode mode;
6072 :
6073 40572946 : if (value == NULL_TREE)
6074 : val = NULL_RTX;
6075 : else
6076 : {
6077 22736435 : if (INSN_VAR_LOCATION_STATUS (insn)
6078 : == VAR_INIT_STATUS_UNINITIALIZED)
6079 175666 : val = expand_debug_source_expr (value);
6080 : /* The avoid_deep_ter_for_debug function inserts
6081 : debug bind stmts after SSA_NAME definition, with the
6082 : SSA_NAME as the whole bind location. Disable temporarily
6083 : expansion of that SSA_NAME into the DEBUG_EXPR_DECL
6084 : being defined in this DEBUG_INSN. */
6085 22560769 : else if (deep_ter_debug_map && TREE_CODE (value) == SSA_NAME)
6086 : {
6087 76167 : tree *slot = deep_ter_debug_map->get (value);
6088 76167 : if (slot)
6089 : {
6090 6191 : if (*slot == INSN_VAR_LOCATION_DECL (insn))
6091 5429 : *slot = NULL_TREE;
6092 : else
6093 : slot = NULL;
6094 : }
6095 76167 : val = expand_debug_expr (value);
6096 76167 : if (slot)
6097 5429 : *slot = INSN_VAR_LOCATION_DECL (insn);
6098 : }
6099 : else
6100 22484602 : val = expand_debug_expr (value);
6101 22736435 : gcc_assert (last == get_last_insn ());
6102 : }
6103 :
6104 22736435 : if (!val)
6105 18328821 : val = gen_rtx_UNKNOWN_VAR_LOC ();
6106 : else
6107 : {
6108 22244125 : mode = GET_MODE (INSN_VAR_LOCATION (insn));
6109 :
6110 22244125 : gcc_assert (mode == GET_MODE (val)
6111 : || (GET_MODE (val) == VOIDmode
6112 : && (CONST_SCALAR_INT_P (val)
6113 : || GET_CODE (val) == CONST_FIXED
6114 : || GET_CODE (val) == LABEL_REF)));
6115 : }
6116 :
6117 40572946 : INSN_VAR_LOCATION_LOC (insn) = val;
6118 40572946 : prev_insn = PREV_INSN (insn);
6119 121744962 : for (insn2 = insn; insn2 != prev_insn; insn2 = PREV_INSN (insn2))
6120 40599070 : avoid_complex_debug_insns (insn2, &INSN_VAR_LOCATION_LOC (insn2), 0);
6121 : }
6122 :
6123 503353 : flag_strict_aliasing = save_strict_alias;
6124 503353 : }
6125 :
6126 : /* Performs swapping operands of commutative operations to expand
6127 : the expensive one first. */
6128 :
6129 : static void
6130 9597627 : reorder_operands (basic_block bb)
6131 : {
6132 9597627 : unsigned int *lattice; /* Hold cost of each statement. */
6133 9597627 : unsigned int i = 0, n = 0;
6134 9597627 : gimple_stmt_iterator gsi;
6135 9597627 : gimple_seq stmts;
6136 9597627 : gimple *stmt;
6137 9597627 : bool swap;
6138 9597627 : tree op0, op1;
6139 9597627 : ssa_op_iter iter;
6140 9597627 : use_operand_p use_p;
6141 9597627 : gimple *def0, *def1;
6142 :
6143 : /* Compute cost of each statement using estimate_num_insns. */
6144 9597627 : stmts = bb_seq (bb);
6145 97718676 : for (gsi = gsi_start (stmts); !gsi_end_p (gsi); gsi_next (&gsi))
6146 : {
6147 88121049 : stmt = gsi_stmt (gsi);
6148 88121049 : if (!is_gimple_debug (stmt))
6149 35352748 : gimple_set_uid (stmt, n++);
6150 : }
6151 9597627 : lattice = XNEWVEC (unsigned int, n);
6152 107316303 : for (gsi = gsi_start (stmts); !gsi_end_p (gsi); gsi_next (&gsi))
6153 : {
6154 88121049 : unsigned cost;
6155 88121049 : stmt = gsi_stmt (gsi);
6156 88121049 : if (is_gimple_debug (stmt))
6157 52768301 : continue;
6158 35352748 : cost = estimate_num_insns (stmt, &eni_size_weights);
6159 35352748 : lattice[i] = cost;
6160 67272674 : FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
6161 : {
6162 31919926 : tree use = USE_FROM_PTR (use_p);
6163 31919926 : gimple *def_stmt;
6164 31919926 : if (TREE_CODE (use) != SSA_NAME)
6165 0 : continue;
6166 31919926 : def_stmt = get_gimple_for_ssa_name (use);
6167 31919926 : if (!def_stmt)
6168 22705210 : continue;
6169 9214716 : lattice[i] += lattice[gimple_uid (def_stmt)];
6170 : }
6171 35352748 : i++;
6172 35352748 : if (!is_gimple_assign (stmt)
6173 35352748 : || !commutative_tree_code (gimple_assign_rhs_code (stmt)))
6174 30951851 : continue;
6175 4400897 : op0 = gimple_op (stmt, 1);
6176 4400897 : op1 = gimple_op (stmt, 2);
6177 4400897 : if (TREE_CODE (op0) != SSA_NAME
6178 4400632 : || TREE_CODE (op1) != SSA_NAME)
6179 2788607 : continue;
6180 : /* Swap operands if the second one is more expensive. */
6181 1612290 : def0 = get_gimple_for_ssa_name (op0);
6182 1612290 : def1 = get_gimple_for_ssa_name (op1);
6183 1612290 : if (!def1)
6184 889704 : continue;
6185 722586 : swap = false;
6186 722586 : if (!def0 || lattice[gimple_uid (def1)] > lattice[gimple_uid (def0)])
6187 341303 : swap = true;
6188 341303 : if (swap)
6189 : {
6190 341303 : if (dump_file && (dump_flags & TDF_DETAILS))
6191 : {
6192 2 : fprintf (dump_file, "Swap operands in stmt:\n");
6193 2 : print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
6194 2 : fprintf (dump_file, "Cost left opnd=%d, right opnd=%d\n",
6195 1 : def0 ? lattice[gimple_uid (def0)] : 0,
6196 2 : lattice[gimple_uid (def1)]);
6197 : }
6198 341303 : swap_ssa_operands (stmt, gimple_assign_rhs1_ptr (stmt),
6199 : gimple_assign_rhs2_ptr (stmt));
6200 : }
6201 : }
6202 9597627 : XDELETE (lattice);
6203 9597627 : }
6204 :
6205 : /* Expand basic block BB from GIMPLE trees to RTL. */
6206 :
6207 : static basic_block
6208 13025923 : expand_gimple_basic_block (basic_block bb, rtx_insn *asan_epilog_seq)
6209 : {
6210 13025923 : gimple_stmt_iterator gsi;
6211 13025923 : gimple *stmt = NULL;
6212 13025923 : rtx_note *note = NULL;
6213 13025923 : rtx_insn *last;
6214 13025923 : edge e;
6215 13025923 : edge_iterator ei;
6216 13025923 : bool nondebug_stmt_seen = false;
6217 :
6218 13025923 : if (dump_file)
6219 823 : fprintf (dump_file, "\n;; Generating RTL for gimple basic block %d\n",
6220 : bb->index);
6221 :
6222 : /* Note that since we are now transitioning from GIMPLE to RTL, we
6223 : cannot use the gsi_*_bb() routines because they expect the basic
6224 : block to be in GIMPLE, instead of RTL. Therefore, we need to
6225 : access the BB sequence directly. */
6226 13025923 : if (optimize)
6227 9597627 : reorder_operands (bb);
6228 13025923 : rtl_profile_for_bb (bb);
6229 :
6230 : /* Remove the RETURN_EXPR if we may fall though to the exit
6231 : instead. */
6232 13025923 : gsi = gsi_last_bb (bb);
6233 13025923 : if (!gsi_end_p (gsi) && gimple_code (gsi_stmt (gsi)) == GIMPLE_RETURN)
6234 : {
6235 1499068 : greturn *ret_stmt = as_a <greturn *> (gsi_stmt (gsi));
6236 :
6237 1499068 : gcc_assert (single_succ_p (bb));
6238 1499068 : gcc_assert (single_succ (bb) == EXIT_BLOCK_PTR_FOR_FN (cfun));
6239 :
6240 1499068 : if (bb->next_bb == EXIT_BLOCK_PTR_FOR_FN (cfun)
6241 1499068 : && !gimple_return_retval (ret_stmt))
6242 : {
6243 629524 : gsi_remove (&gsi, false);
6244 629524 : single_succ_edge (bb)->flags |= EDGE_FALLTHRU;
6245 : }
6246 : }
6247 :
6248 13025923 : gsi = gsi_start_bb (bb);
6249 13025923 : if (!gsi_end_p (gsi))
6250 : {
6251 12470761 : stmt = gsi_stmt (gsi);
6252 12470761 : if (gimple_code (stmt) != GIMPLE_LABEL)
6253 12368589 : stmt = NULL;
6254 : }
6255 :
6256 13025923 : rtx_code_label **elt = lab_rtx_for_bb->get (bb);
6257 13025923 : if ((unsigned) bb->index >= head_end_for_bb.length ())
6258 11030386 : head_end_for_bb.safe_grow_cleared (bb->index + 1);
6259 :
6260 13025923 : if (stmt || elt)
6261 : {
6262 5387584 : gcc_checking_assert (!note);
6263 5387584 : last = get_last_insn ();
6264 :
6265 5387584 : if (stmt)
6266 : {
6267 657334 : expand_gimple_stmt (stmt);
6268 657334 : gsi_next (&gsi);
6269 : }
6270 :
6271 5387584 : if (elt)
6272 4730250 : emit_label (*elt);
6273 :
6274 5387584 : head_end_for_bb[bb->index].first = NEXT_INSN (last);
6275 5387584 : if (NOTE_P (head_end_for_bb[bb->index].first))
6276 0 : head_end_for_bb[bb->index].first
6277 0 : = NEXT_INSN (head_end_for_bb[bb->index].first);
6278 5387584 : gcc_assert (LABEL_P (head_end_for_bb[bb->index].first));
6279 10775168 : note = emit_note_after (NOTE_INSN_BASIC_BLOCK,
6280 5387584 : head_end_for_bb[bb->index].first);
6281 :
6282 5387584 : maybe_dump_rtl_for_gimple_stmt (stmt, last);
6283 : }
6284 : else
6285 7638339 : head_end_for_bb[bb->index].first = note = emit_note (NOTE_INSN_BASIC_BLOCK);
6286 :
6287 13025923 : if (note)
6288 13025923 : NOTE_BASIC_BLOCK (note) = bb;
6289 :
6290 68124469 : for (; !gsi_end_p (gsi); gsi_next (&gsi))
6291 : {
6292 55628360 : basic_block new_bb;
6293 :
6294 55628360 : stmt = gsi_stmt (gsi);
6295 55628360 : if (!is_gimple_debug (stmt))
6296 47233811 : nondebug_stmt_seen = true;
6297 :
6298 : /* If this statement is a non-debug one, and we generate debug
6299 : insns, then this one might be the last real use of a TERed
6300 : SSA_NAME, but where there are still some debug uses further
6301 : down. Expanding the current SSA name in such further debug
6302 : uses by their RHS might lead to wrong debug info, as coalescing
6303 : might make the operands of such RHS be placed into the same
6304 : pseudo as something else. Like so:
6305 : a_1 = a_0 + 1; // Assume a_1 is TERed and a_0 is dead
6306 : use(a_1);
6307 : a_2 = ...
6308 : #DEBUG ... => a_1
6309 : As a_0 and a_2 don't overlap in lifetime, assume they are coalesced.
6310 : If we now would expand a_1 by it's RHS (a_0 + 1) in the debug use,
6311 : the write to a_2 would actually have clobbered the place which
6312 : formerly held a_0.
6313 :
6314 : So, instead of that, we recognize the situation, and generate
6315 : debug temporaries at the last real use of TERed SSA names:
6316 : a_1 = a_0 + 1;
6317 : #DEBUG #D1 => a_1
6318 : use(a_1);
6319 : a_2 = ...
6320 : #DEBUG ... => #D1
6321 : */
6322 55628360 : if (MAY_HAVE_DEBUG_BIND_INSNS
6323 29869153 : && SA.values
6324 84267435 : && !is_gimple_debug (stmt))
6325 : {
6326 20640012 : ssa_op_iter iter;
6327 20640012 : tree op;
6328 20640012 : gimple *def;
6329 :
6330 20640012 : location_t sloc = curr_insn_location ();
6331 :
6332 : /* Look for SSA names that have their last use here (TERed
6333 : names always have only one real use). */
6334 20640012 : gassign *as_def;
6335 39588099 : FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE)
6336 18948087 : if ((def = get_gimple_for_ssa_name (op))
6337 24119339 : && (as_def = dyn_cast<gassign *> (def)))
6338 : {
6339 5154366 : imm_use_iterator imm_iter;
6340 5154366 : use_operand_p use_p;
6341 5154366 : bool have_debug_uses = false;
6342 :
6343 10281222 : FOR_EACH_IMM_USE_FAST (use_p, imm_iter, op)
6344 : {
6345 5177277 : if (gimple_debug_bind_p (USE_STMT (use_p)))
6346 : {
6347 : have_debug_uses = true;
6348 : break;
6349 : }
6350 5154366 : }
6351 :
6352 5154366 : if (have_debug_uses)
6353 : {
6354 : /* OP is a TERed SSA name, with DEF its defining
6355 : statement, and where OP is used in further debug
6356 : instructions. Generate a debug temporary, and
6357 : replace all uses of OP in debug insns with that
6358 : temporary. */
6359 50421 : gimple *debugstmt;
6360 50421 : tree value = gimple_assign_rhs_to_tree (as_def);
6361 50421 : tree vexpr = build_debug_expr_decl (TREE_TYPE (value));
6362 50421 : rtx val;
6363 50421 : machine_mode mode;
6364 :
6365 50421 : set_curr_insn_location (gimple_location (def));
6366 :
6367 50421 : if (DECL_P (value))
6368 364 : mode = DECL_MODE (value);
6369 : else
6370 50057 : mode = TYPE_MODE (TREE_TYPE (value));
6371 : /* FIXME: Is setting the mode really necessary? */
6372 50421 : SET_DECL_MODE (vexpr, mode);
6373 :
6374 50421 : val = gen_rtx_VAR_LOCATION
6375 50421 : (mode, vexpr, (rtx)value, VAR_INIT_STATUS_INITIALIZED);
6376 :
6377 50421 : emit_debug_insn (val);
6378 :
6379 189047 : FOR_EACH_IMM_USE_STMT (debugstmt, imm_iter, op)
6380 : {
6381 138626 : if (!gimple_debug_bind_p (debugstmt))
6382 50421 : continue;
6383 :
6384 177080 : FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
6385 88540 : SET_USE (use_p, vexpr);
6386 :
6387 88205 : update_stmt (debugstmt);
6388 50421 : }
6389 : }
6390 : }
6391 20640012 : set_curr_insn_location (sloc);
6392 : }
6393 :
6394 55628360 : currently_expanding_gimple_stmt = stmt;
6395 :
6396 : /* Expand this statement, then evaluate the resulting RTL and
6397 : fixup the CFG accordingly. */
6398 55628360 : if (gimple_code (stmt) == GIMPLE_COND)
6399 : {
6400 5826981 : new_bb = expand_gimple_cond (bb, as_a <gcond *> (stmt));
6401 5826981 : if (new_bb)
6402 : {
6403 401335 : currently_expanding_gimple_stmt = NULL;
6404 401335 : return new_bb;
6405 : }
6406 : }
6407 49801379 : else if (is_gimple_debug (stmt))
6408 : {
6409 8394549 : location_t sloc = curr_insn_location ();
6410 8394549 : gimple_stmt_iterator nsi = gsi;
6411 :
6412 52641541 : for (;;)
6413 : {
6414 52641541 : tree var;
6415 52641541 : tree value = NULL_TREE;
6416 52641541 : rtx val = NULL_RTX;
6417 52641541 : machine_mode mode;
6418 :
6419 52641541 : if (!gimple_debug_nonbind_marker_p (stmt))
6420 : {
6421 40919219 : if (gimple_debug_bind_p (stmt))
6422 : {
6423 40743553 : var = gimple_debug_bind_get_var (stmt);
6424 :
6425 40743553 : if (TREE_CODE (var) != DEBUG_EXPR_DECL
6426 37732540 : && TREE_CODE (var) != LABEL_DECL
6427 78466016 : && !target_for_debug_bind (var))
6428 396694 : goto delink_debug_stmt;
6429 :
6430 40346859 : if (DECL_P (var) && !VECTOR_TYPE_P (TREE_TYPE (var)))
6431 40259391 : mode = DECL_MODE (var);
6432 : else
6433 87468 : mode = TYPE_MODE (TREE_TYPE (var));
6434 :
6435 40346859 : if (gimple_debug_bind_has_value_p (stmt))
6436 22510348 : value = gimple_debug_bind_get_value (stmt);
6437 :
6438 40346859 : val = gen_rtx_VAR_LOCATION
6439 40346859 : (mode, var, (rtx)value, VAR_INIT_STATUS_INITIALIZED);
6440 : }
6441 175666 : else if (gimple_debug_source_bind_p (stmt))
6442 : {
6443 175666 : var = gimple_debug_source_bind_get_var (stmt);
6444 :
6445 175666 : value = gimple_debug_source_bind_get_value (stmt);
6446 :
6447 175666 : if (!VECTOR_TYPE_P (TREE_TYPE (var)))
6448 175666 : mode = DECL_MODE (var);
6449 : else
6450 0 : mode = TYPE_MODE (TREE_TYPE (var));
6451 :
6452 175666 : val = gen_rtx_VAR_LOCATION (mode, var, (rtx)value,
6453 : VAR_INIT_STATUS_UNINITIALIZED);
6454 : }
6455 : else
6456 0 : gcc_unreachable ();
6457 : }
6458 : /* If this function was first compiled with markers
6459 : enabled, but they're now disable (e.g. LTO), drop
6460 : them on the floor. */
6461 11722322 : else if (gimple_debug_nonbind_marker_p (stmt)
6462 11722322 : && !MAY_HAVE_DEBUG_MARKER_INSNS)
6463 0 : goto delink_debug_stmt;
6464 11722322 : else if (gimple_debug_begin_stmt_p (stmt))
6465 4094220 : val = GEN_RTX_DEBUG_MARKER_BEGIN_STMT_PAT ();
6466 7628102 : else if (gimple_debug_inline_entry_p (stmt))
6467 7628102 : val = GEN_RTX_DEBUG_MARKER_INLINE_ENTRY_PAT ();
6468 : else
6469 : gcc_unreachable ();
6470 :
6471 52244847 : last = get_last_insn ();
6472 :
6473 52244847 : set_curr_insn_location (gimple_location (stmt));
6474 :
6475 52244847 : emit_debug_insn (val);
6476 :
6477 52244847 : if (dump_file && (dump_flags & TDF_DETAILS))
6478 : {
6479 : /* We can't dump the insn with a TREE where an RTX
6480 : is expected. */
6481 1 : if (GET_CODE (val) == VAR_LOCATION)
6482 : {
6483 0 : gcc_checking_assert (PAT_VAR_LOCATION_LOC (val) == (rtx)value);
6484 0 : PAT_VAR_LOCATION_LOC (val) = const0_rtx;
6485 : }
6486 1 : maybe_dump_rtl_for_gimple_stmt (stmt, last);
6487 1 : if (GET_CODE (val) == VAR_LOCATION)
6488 0 : PAT_VAR_LOCATION_LOC (val) = (rtx)value;
6489 : }
6490 :
6491 52641541 : delink_debug_stmt:
6492 : /* In order not to generate too many debug temporaries,
6493 : we delink all uses of debug statements we already expanded.
6494 : Therefore debug statements between definition and real
6495 : use of TERed SSA names will continue to use the SSA name,
6496 : and not be replaced with debug temps. */
6497 52641541 : delink_stmt_imm_use (stmt);
6498 :
6499 52641541 : gsi = nsi;
6500 52641541 : gsi_next (&nsi);
6501 52641541 : if (gsi_end_p (nsi))
6502 : break;
6503 51950753 : stmt = gsi_stmt (nsi);
6504 51950753 : if (!is_gimple_debug (stmt))
6505 : break;
6506 : }
6507 :
6508 8394549 : set_curr_insn_location (sloc);
6509 : }
6510 : else
6511 : {
6512 41406830 : gcall *call_stmt = dyn_cast <gcall *> (stmt);
6513 41406830 : if (call_stmt
6514 41406830 : && asan_epilog_seq
6515 28323 : && gimple_call_tail_p (call_stmt)
6516 41406986 : && !gimple_call_must_tail_p (call_stmt))
6517 39 : gimple_call_set_tail (call_stmt, false);
6518 :
6519 41406830 : if (call_stmt && gimple_call_tail_p (call_stmt))
6520 : {
6521 179094 : bool can_fallthru;
6522 179094 : new_bb = expand_gimple_tailcall (bb, call_stmt, &can_fallthru,
6523 : asan_epilog_seq);
6524 179094 : if (new_bb)
6525 : {
6526 128477 : if (can_fallthru)
6527 0 : bb = new_bb;
6528 : else
6529 : {
6530 128477 : currently_expanding_gimple_stmt = NULL;
6531 128477 : return new_bb;
6532 : }
6533 : }
6534 : }
6535 : else
6536 : {
6537 41227736 : def_operand_p def_p;
6538 41227736 : def_p = SINGLE_SSA_DEF_OPERAND (stmt, SSA_OP_DEF);
6539 :
6540 41227736 : if (def_p != NULL)
6541 : {
6542 : /* Ignore this stmt if it is in the list of
6543 : replaceable expressions. */
6544 34857346 : if (SA.values
6545 43295818 : && bitmap_bit_p (SA.values,
6546 17653055 : SSA_NAME_VERSION (DEF_FROM_PTR (def_p))))
6547 9214583 : continue;
6548 : }
6549 32013153 : last = expand_gimple_stmt (stmt);
6550 32013151 : maybe_dump_rtl_for_gimple_stmt (stmt, last);
6551 : }
6552 : }
6553 : }
6554 :
6555 12496109 : currently_expanding_gimple_stmt = NULL;
6556 :
6557 : /* Expand implicit goto and convert goto_locus. */
6558 30347680 : FOR_EACH_EDGE (e, ei, bb->succs)
6559 : {
6560 17851571 : if (e->goto_locus != UNKNOWN_LOCATION || !nondebug_stmt_seen)
6561 3518835 : set_curr_insn_location (e->goto_locus);
6562 17851571 : if ((e->flags & EDGE_FALLTHRU) && e->dest != bb->next_bb)
6563 : {
6564 1674157 : emit_jump (label_rtx_for_bb (e->dest));
6565 1674157 : e->flags &= ~EDGE_FALLTHRU;
6566 : }
6567 : }
6568 :
6569 : /* Expanded RTL can create a jump in the last instruction of block.
6570 : This later might be assumed to be a jump to successor and break edge insertion.
6571 : We need to insert dummy move to prevent this. PR41440. */
6572 12496109 : if (single_succ_p (bb)
6573 5636491 : && (single_succ_edge (bb)->flags & EDGE_FALLTHRU)
6574 3190354 : && (last = get_last_insn ())
6575 15491462 : && (JUMP_P (last)
6576 3190283 : || (DEBUG_INSN_P (last)
6577 390524 : && JUMP_P (prev_nondebug_insn (last)))))
6578 : {
6579 84 : rtx dummy = gen_reg_rtx (SImode);
6580 84 : emit_insn_after_noloc (gen_move_insn (dummy, dummy), last, NULL);
6581 : }
6582 :
6583 : /* A __builtin_unreachable () will insert a barrier that should end
6584 : the basic block. In gimple, any code after it will have already
6585 : deleted, even without optimization. If we emit additional code
6586 : here, as we would to adjust the stack after a call, it should be
6587 : eventually deleted, but it confuses internal checkers (PR118006)
6588 : and optimizers before it does, because we don't expect to find
6589 : barriers inside basic blocks. */
6590 12496109 : if (!BARRIER_P (get_last_insn ()))
6591 9116238 : do_pending_stack_adjust ();
6592 : else
6593 3379871 : discard_pending_stack_adjust ();
6594 :
6595 : /* Find the block tail. The last insn in the block is the insn
6596 : before a barrier and/or table jump insn. */
6597 12496109 : last = get_last_insn ();
6598 12496109 : if (BARRIER_P (last))
6599 3379871 : last = PREV_INSN (last);
6600 12496109 : if (JUMP_TABLE_DATA_P (last))
6601 7648 : last = PREV_INSN (PREV_INSN (last));
6602 12496109 : if (BARRIER_P (last))
6603 6434 : last = PREV_INSN (last);
6604 12496109 : head_end_for_bb[bb->index].second = last;
6605 :
6606 24992218 : update_bb_for_insn_chain (head_end_for_bb[bb->index].first,
6607 12496109 : head_end_for_bb[bb->index].second, bb);
6608 :
6609 12496109 : return bb;
6610 : }
6611 :
6612 :
6613 : /* Create a basic block for initialization code. */
6614 :
6615 : static basic_block
6616 1531890 : construct_init_block (void)
6617 : {
6618 1531890 : basic_block init_block;
6619 1531890 : edge e = NULL;
6620 1531890 : int flags;
6621 :
6622 : /* Multiple entry points not supported yet. */
6623 1531890 : gcc_assert (EDGE_COUNT (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs) == 1);
6624 1531890 : init_rtl_bb_info (ENTRY_BLOCK_PTR_FOR_FN (cfun));
6625 1531890 : init_rtl_bb_info (EXIT_BLOCK_PTR_FOR_FN (cfun));
6626 1531890 : ENTRY_BLOCK_PTR_FOR_FN (cfun)->flags |= BB_RTL;
6627 1531890 : EXIT_BLOCK_PTR_FOR_FN (cfun)->flags |= BB_RTL;
6628 :
6629 1531890 : e = EDGE_SUCC (ENTRY_BLOCK_PTR_FOR_FN (cfun), 0);
6630 :
6631 : /* When entry edge points to first basic block, we don't need jump,
6632 : otherwise we have to jump into proper target. */
6633 1531890 : if (e && e->dest != ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb)
6634 : {
6635 0 : tree label = gimple_block_label (e->dest);
6636 :
6637 0 : emit_jump (jump_target_rtx (label));
6638 0 : flags = 0;
6639 0 : }
6640 : else
6641 : flags = EDGE_FALLTHRU;
6642 :
6643 1531890 : init_block = create_basic_block (NEXT_INSN (get_insns ()),
6644 : get_last_insn (),
6645 1531890 : ENTRY_BLOCK_PTR_FOR_FN (cfun));
6646 1531890 : init_block->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
6647 1531890 : add_bb_to_loop (init_block, ENTRY_BLOCK_PTR_FOR_FN (cfun)->loop_father);
6648 1531890 : if (e)
6649 1531890 : expand_split_edge (e, init_block, flags);
6650 : else
6651 0 : make_single_succ_edge (init_block, EXIT_BLOCK_PTR_FOR_FN (cfun),
6652 : EDGE_FALLTHRU);
6653 :
6654 1531890 : update_bb_for_insn (init_block);
6655 1531890 : return init_block;
6656 : }
6657 :
6658 : /* For each lexical block, set BLOCK_NUMBER to the depth at which it is
6659 : found in the block tree. */
6660 :
6661 : static void
6662 18744526 : set_block_levels (tree block, int level)
6663 : {
6664 35957164 : while (block)
6665 : {
6666 17212638 : BLOCK_NUMBER (block) = level;
6667 17212638 : set_block_levels (BLOCK_SUBBLOCKS (block), level + 1);
6668 17212638 : block = BLOCK_CHAIN (block);
6669 : }
6670 18744526 : }
6671 :
6672 : /* Create a block containing landing pads and similar stuff. */
6673 :
6674 : static void
6675 1531888 : construct_exit_block (void)
6676 : {
6677 1531888 : rtx_insn *head = get_last_insn ();
6678 1531888 : rtx_insn *end;
6679 1531888 : basic_block exit_block;
6680 1531888 : edge e, e2;
6681 1531888 : unsigned ix;
6682 1531888 : edge_iterator ei;
6683 1531888 : basic_block prev_bb = EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb;
6684 1531888 : rtx_insn *orig_end = BB_END (prev_bb);
6685 :
6686 1531888 : rtl_profile_for_bb (EXIT_BLOCK_PTR_FOR_FN (cfun));
6687 :
6688 : /* Make sure the locus is set to the end of the function, so that
6689 : epilogue line numbers and warnings are set properly. */
6690 1531888 : if (LOCATION_LOCUS (cfun->function_end_locus) != UNKNOWN_LOCATION)
6691 1209808 : input_location = cfun->function_end_locus;
6692 :
6693 : /* Generate rtl for function exit. */
6694 1531888 : expand_function_end ();
6695 :
6696 1531888 : end = get_last_insn ();
6697 1531888 : if (head == end)
6698 0 : return;
6699 : /* While emitting the function end we could move end of the last basic
6700 : block. */
6701 1531888 : BB_END (prev_bb) = orig_end;
6702 1531888 : while (NEXT_INSN (head) && NOTE_P (NEXT_INSN (head)))
6703 : head = NEXT_INSN (head);
6704 : /* But make sure exit_block starts with RETURN_LABEL, otherwise the
6705 : bb count counting will be confused. Any instructions before that
6706 : label are emitted for the case where PREV_BB falls through into the
6707 : exit block, so append those instructions to prev_bb in that case. */
6708 1531888 : if (NEXT_INSN (head) != return_label)
6709 : {
6710 15068 : while (NEXT_INSN (head) != return_label)
6711 : {
6712 9997 : if (!NOTE_P (NEXT_INSN (head)))
6713 9997 : BB_END (prev_bb) = NEXT_INSN (head);
6714 9997 : head = NEXT_INSN (head);
6715 : }
6716 : }
6717 1531888 : exit_block = create_basic_block (NEXT_INSN (head), end, prev_bb);
6718 1531888 : exit_block->count = EXIT_BLOCK_PTR_FOR_FN (cfun)->count;
6719 1531888 : add_bb_to_loop (exit_block, EXIT_BLOCK_PTR_FOR_FN (cfun)->loop_father);
6720 :
6721 1531888 : ix = 0;
6722 4623800 : while (ix < EDGE_COUNT (EXIT_BLOCK_PTR_FOR_FN (cfun)->preds))
6723 : {
6724 1560024 : e = EDGE_PRED (EXIT_BLOCK_PTR_FOR_FN (cfun), ix);
6725 1560024 : if (!(e->flags & EDGE_ABNORMAL))
6726 1431547 : redirect_edge_succ (e, exit_block);
6727 : else
6728 128477 : ix++;
6729 : }
6730 :
6731 1531888 : e = make_single_succ_edge (exit_block, EXIT_BLOCK_PTR_FOR_FN (cfun),
6732 : EDGE_FALLTHRU);
6733 3192253 : FOR_EACH_EDGE (e2, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
6734 1660365 : if (e2 != e)
6735 : {
6736 128477 : exit_block->count -= e2->count ();
6737 : }
6738 1531888 : update_bb_for_insn (exit_block);
6739 : }
6740 :
6741 : /* Helper function for discover_nonconstant_array_refs.
6742 : Look for ARRAY_REF nodes with non-constant indexes and mark them
6743 : addressable. */
6744 :
6745 : static tree
6746 169604614 : discover_nonconstant_array_refs_r (tree * tp, int *walk_subtrees,
6747 : void *data)
6748 : {
6749 169604614 : tree t = *tp;
6750 169604614 : bitmap forced_stack_vars = (bitmap)((walk_stmt_info *)data)->info;
6751 :
6752 169604614 : if (IS_TYPE_OR_DECL_P (t))
6753 34695788 : *walk_subtrees = 0;
6754 134908826 : else if (REFERENCE_CLASS_P (t) && TREE_THIS_VOLATILE (t))
6755 : {
6756 138724 : t = get_base_address (t);
6757 138724 : if (t && DECL_P (t)
6758 125427 : && DECL_MODE (t) != BLKmode
6759 176358 : && !TREE_ADDRESSABLE (t))
6760 32733 : bitmap_set_bit (forced_stack_vars, DECL_UID (t));
6761 138724 : *walk_subtrees = 0;
6762 : }
6763 134770102 : else if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
6764 : {
6765 6581765 : while (((TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
6766 3141040 : && is_gimple_min_invariant (TREE_OPERAND (t, 1))
6767 2654605 : && (!TREE_OPERAND (t, 2)
6768 37502 : || is_gimple_min_invariant (TREE_OPERAND (t, 2))))
6769 3961521 : || (TREE_CODE (t) == COMPONENT_REF
6770 981127 : && (!TREE_OPERAND (t,2)
6771 0 : || is_gimple_min_invariant (TREE_OPERAND (t, 2))))
6772 2980394 : || TREE_CODE (t) == BIT_FIELD_REF
6773 : || TREE_CODE (t) == REALPART_EXPR
6774 : || TREE_CODE (t) == IMAGPART_EXPR
6775 : || TREE_CODE (t) == VIEW_CONVERT_EXPR
6776 6581765 : || CONVERT_EXPR_P (t))
6777 3612068 : t = TREE_OPERAND (t, 0);
6778 :
6779 2969697 : if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
6780 : {
6781 520796 : t = get_base_address (t);
6782 520796 : if (t && DECL_P (t)
6783 415863 : && DECL_MODE (t) != BLKmode
6784 543940 : && !TREE_ADDRESSABLE (t))
6785 13591 : bitmap_set_bit (forced_stack_vars, DECL_UID (t));
6786 : }
6787 :
6788 2969697 : *walk_subtrees = 0;
6789 : }
6790 : /* References of size POLY_INT_CST to a fixed-size object must go
6791 : through memory. It's more efficient to force that here than
6792 : to create temporary slots on the fly.
6793 : RTL expansion expects TARGET_MEM_REF to always address actual memory.
6794 : Also, force to stack non-BLKmode vars accessed through VIEW_CONVERT_EXPR
6795 : to BLKmode type. */
6796 131800405 : else if (TREE_CODE (t) == TARGET_MEM_REF
6797 : || (TREE_CODE (t) == MEM_REF
6798 130934520 : && TYPE_SIZE (TREE_TYPE (t))
6799 : && POLY_INT_CST_P (TYPE_SIZE (TREE_TYPE (t))))
6800 262734925 : || (TREE_CODE (t) == VIEW_CONVERT_EXPR
6801 335368 : && TYPE_MODE (TREE_TYPE (t)) == BLKmode))
6802 : {
6803 945100 : tree base = get_base_address (t);
6804 945100 : if (base
6805 945100 : && DECL_P (base)
6806 262646 : && !TREE_ADDRESSABLE (base)
6807 120094 : && DECL_MODE (base) != BLKmode
6808 951173 : && GET_MODE_SIZE (DECL_MODE (base)).is_constant ())
6809 6073 : bitmap_set_bit (forced_stack_vars, DECL_UID (base));
6810 945100 : *walk_subtrees = 0;
6811 : }
6812 :
6813 169604614 : return NULL_TREE;
6814 : }
6815 :
6816 : /* If there's a chance to get a pseudo for t then if it would be of float mode
6817 : and the actual access is via an integer mode (lowered memcpy or similar
6818 : access) then avoid the register expansion if the mode likely is not storage
6819 : suitable for raw bits processing (like XFmode on i?86). */
6820 :
6821 : static void
6822 6925739 : avoid_type_punning_on_regs (tree t, bitmap forced_stack_vars)
6823 : {
6824 6925739 : machine_mode access_mode = TYPE_MODE (TREE_TYPE (t));
6825 6925739 : if (access_mode != BLKmode
6826 6747371 : && !SCALAR_INT_MODE_P (access_mode))
6827 : return;
6828 5926609 : tree base = get_base_address (t);
6829 5926609 : if (DECL_P (base)
6830 4380873 : && !TREE_ADDRESSABLE (base)
6831 1315120 : && FLOAT_MODE_P (DECL_MODE (base))
6832 80 : && maybe_lt (GET_MODE_PRECISION (DECL_MODE (base)),
6833 240 : GET_MODE_BITSIZE (GET_MODE_INNER (DECL_MODE (base))))
6834 : /* Double check in the expensive way we really would get a pseudo. */
6835 5926614 : && use_register_for_decl (base))
6836 5 : bitmap_set_bit (forced_stack_vars, DECL_UID (base));
6837 : }
6838 :
6839 : /* RTL expansion is not able to compile array references with variable
6840 : offsets for arrays stored in single register. Discover such
6841 : expressions and mark variables as addressable to avoid this
6842 : scenario. */
6843 :
6844 : static void
6845 1531890 : discover_nonconstant_array_refs (bitmap forced_stack_vars)
6846 : {
6847 1531890 : basic_block bb;
6848 1531890 : gimple_stmt_iterator gsi;
6849 :
6850 1531890 : walk_stmt_info wi = {};
6851 1531890 : wi.info = forced_stack_vars;
6852 14554838 : FOR_EACH_BB_FN (bb, cfun)
6853 127354857 : for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
6854 : {
6855 101308961 : gimple *stmt = gsi_stmt (gsi);
6856 101308961 : if (!is_gimple_debug (stmt))
6857 : {
6858 48540644 : walk_gimple_op (stmt, discover_nonconstant_array_refs_r, &wi);
6859 48540644 : gcall *call = dyn_cast <gcall *> (stmt);
6860 7141666 : if (call && gimple_call_internal_p (call))
6861 : {
6862 236673 : tree cand = NULL_TREE;
6863 236673 : switch (gimple_call_internal_fn (call))
6864 : {
6865 0 : case IFN_LOAD_LANES:
6866 : /* The source must be a MEM. */
6867 0 : cand = gimple_call_arg (call, 0);
6868 0 : break;
6869 0 : case IFN_STORE_LANES:
6870 : /* The destination must be a MEM. */
6871 0 : cand = gimple_call_lhs (call);
6872 0 : break;
6873 : default:
6874 : break;
6875 : }
6876 0 : if (cand)
6877 0 : cand = get_base_address (cand);
6878 0 : if (cand
6879 0 : && DECL_P (cand)
6880 0 : && use_register_for_decl (cand))
6881 0 : bitmap_set_bit (forced_stack_vars, DECL_UID (cand));
6882 : }
6883 159460732 : if (gimple_vdef (stmt))
6884 : {
6885 16117741 : tree t = gimple_get_lhs (stmt);
6886 16117741 : if (t && REFERENCE_CLASS_P (t))
6887 6925739 : avoid_type_punning_on_regs (t, forced_stack_vars);
6888 : }
6889 : }
6890 : }
6891 1531890 : }
6892 :
6893 : /* This function sets crtl->args.internal_arg_pointer to a virtual
6894 : register if DRAP is needed. Local register allocator will replace
6895 : virtual_incoming_args_rtx with the virtual register. */
6896 :
6897 : static void
6898 1531888 : expand_stack_alignment (void)
6899 : {
6900 1531888 : rtx drap_rtx;
6901 1531888 : unsigned int preferred_stack_boundary;
6902 :
6903 1531888 : if (! SUPPORTS_STACK_ALIGNMENT)
6904 : return;
6905 :
6906 1531888 : if (cfun->calls_alloca
6907 1516282 : || cfun->has_nonlocal_label
6908 1515465 : || crtl->has_nonlocal_goto)
6909 16839 : crtl->need_drap = true;
6910 :
6911 : /* Call update_stack_boundary here again to update incoming stack
6912 : boundary. It may set incoming stack alignment to a different
6913 : value after RTL expansion. TARGET_FUNCTION_OK_FOR_SIBCALL may
6914 : use the minimum incoming stack alignment to check if it is OK
6915 : to perform sibcall optimization since sibcall optimization will
6916 : only align the outgoing stack to incoming stack boundary. */
6917 1531888 : if (targetm.calls.update_stack_boundary)
6918 1531888 : targetm.calls.update_stack_boundary ();
6919 :
6920 : /* The incoming stack frame has to be aligned at least at
6921 : parm_stack_boundary. */
6922 1531888 : gcc_assert (crtl->parm_stack_boundary <= INCOMING_STACK_BOUNDARY);
6923 :
6924 : /* Update crtl->stack_alignment_estimated and use it later to align
6925 : stack. We check PREFERRED_STACK_BOUNDARY if there may be non-call
6926 : exceptions since callgraph doesn't collect incoming stack alignment
6927 : in this case. */
6928 1531888 : if (cfun->can_throw_non_call_exceptions
6929 263022 : && PREFERRED_STACK_BOUNDARY > crtl->preferred_stack_boundary)
6930 : preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
6931 : else
6932 1503897 : preferred_stack_boundary = crtl->preferred_stack_boundary;
6933 1531888 : if (preferred_stack_boundary > crtl->stack_alignment_estimated)
6934 736592 : crtl->stack_alignment_estimated = preferred_stack_boundary;
6935 1531888 : if (preferred_stack_boundary > crtl->stack_alignment_needed)
6936 685480 : crtl->stack_alignment_needed = preferred_stack_boundary;
6937 :
6938 1531888 : gcc_assert (crtl->stack_alignment_needed
6939 : <= crtl->stack_alignment_estimated);
6940 :
6941 1531888 : crtl->stack_realign_needed
6942 1531888 : = INCOMING_STACK_BOUNDARY < crtl->stack_alignment_estimated;
6943 1531888 : crtl->stack_realign_tried = crtl->stack_realign_needed;
6944 :
6945 1531888 : crtl->stack_realign_processed = true;
6946 :
6947 : /* Target has to redefine TARGET_GET_DRAP_RTX to support stack
6948 : alignment. */
6949 1531888 : gcc_assert (targetm.calls.get_drap_rtx != NULL);
6950 1531888 : drap_rtx = targetm.calls.get_drap_rtx ();
6951 :
6952 : /* stack_realign_drap and drap_rtx must match. */
6953 1531888 : gcc_assert ((stack_realign_drap != 0) == (drap_rtx != NULL));
6954 :
6955 : /* Do nothing if NULL is returned, which means DRAP is not needed. */
6956 1531888 : if (drap_rtx != NULL)
6957 : {
6958 7439 : crtl->args.internal_arg_pointer = drap_rtx;
6959 :
6960 : /* Call fixup_tail_calls to clean up REG_EQUIV note if DRAP is
6961 : needed. */
6962 7439 : fixup_tail_calls ();
6963 : }
6964 : }
6965 :
6966 :
6967 : static void
6968 0 : expand_main_function (void)
6969 : {
6970 : #if (defined(INVOKE__main) \
6971 : || (!defined(HAS_INIT_SECTION) \
6972 : && !defined(INIT_SECTION_ASM_OP) \
6973 : && !defined(INIT_ARRAY_SECTION_ASM_OP)))
6974 : emit_library_call (init_one_libfunc (NAME__MAIN), LCT_NORMAL, VOIDmode);
6975 : #endif
6976 0 : }
6977 :
6978 :
6979 : /* Expand code to initialize the stack_protect_guard. This is invoked at
6980 : the beginning of a function to be protected. */
6981 :
6982 : static void
6983 308 : stack_protect_prologue (void)
6984 : {
6985 308 : tree guard_decl = targetm.stack_protect_guard ();
6986 308 : rtx x, y;
6987 :
6988 308 : crtl->stack_protect_guard_decl = guard_decl;
6989 308 : x = expand_normal (crtl->stack_protect_guard);
6990 :
6991 308 : if (targetm.have_stack_protect_combined_set () && guard_decl)
6992 : {
6993 0 : gcc_assert (DECL_P (guard_decl));
6994 0 : y = DECL_RTL (guard_decl);
6995 :
6996 : /* Allow the target to compute address of Y and copy it to X without
6997 : leaking Y into a register. This combined address + copy pattern
6998 : allows the target to prevent spilling of any intermediate results by
6999 : splitting it after register allocator. */
7000 0 : if (rtx_insn *insn = targetm.gen_stack_protect_combined_set (x, y))
7001 : {
7002 0 : emit_insn (insn);
7003 0 : return;
7004 : }
7005 : }
7006 :
7007 308 : if (guard_decl)
7008 308 : y = expand_normal (guard_decl);
7009 : else
7010 0 : y = const0_rtx;
7011 :
7012 : /* Allow the target to copy from Y to X without leaking Y into a
7013 : register. */
7014 308 : if (targetm.have_stack_protect_set ())
7015 308 : if (rtx_insn *insn = targetm.gen_stack_protect_set (x, y))
7016 : {
7017 308 : emit_insn (insn);
7018 308 : return;
7019 : }
7020 :
7021 : /* Otherwise do a straight move. */
7022 0 : emit_move_insn (x, y);
7023 : }
7024 :
7025 : /* Translate the intermediate representation contained in the CFG
7026 : from GIMPLE trees to RTL.
7027 :
7028 : We do conversion per basic block and preserve/update the tree CFG.
7029 : This implies we have to do some magic as the CFG can simultaneously
7030 : consist of basic blocks containing RTL and GIMPLE trees. This can
7031 : confuse the CFG hooks, so be careful to not manipulate CFG during
7032 : the expansion. */
7033 :
7034 : namespace {
7035 :
7036 : const pass_data pass_data_expand =
7037 : {
7038 : RTL_PASS, /* type */
7039 : "expand", /* name */
7040 : OPTGROUP_NONE, /* optinfo_flags */
7041 : TV_EXPAND, /* tv_id */
7042 : ( PROP_ssa | PROP_gimple_leh | PROP_cfg
7043 : | PROP_gimple_lcx
7044 : | PROP_gimple_lvec
7045 : | PROP_gimple_lva), /* properties_required */
7046 : PROP_rtl, /* properties_provided */
7047 : ( PROP_ssa | PROP_gimple ), /* properties_destroyed */
7048 : 0, /* todo_flags_start */
7049 : 0, /* todo_flags_finish */
7050 : };
7051 :
7052 : class pass_expand : public rtl_opt_pass
7053 : {
7054 : public:
7055 302989 : pass_expand (gcc::context *ctxt)
7056 605978 : : rtl_opt_pass (pass_data_expand, ctxt)
7057 : {}
7058 :
7059 : /* opt_pass methods: */
7060 : unsigned int execute (function *) final override;
7061 :
7062 : }; // class pass_expand
7063 :
7064 : unsigned int
7065 1531890 : pass_expand::execute (function *fun)
7066 : {
7067 1531890 : basic_block bb, init_block;
7068 1531890 : edge_iterator ei;
7069 1531890 : edge e;
7070 1531890 : rtx_insn *var_seq, *var_ret_seq;
7071 1531890 : unsigned i;
7072 :
7073 1531890 : timevar_push (TV_OUT_OF_SSA);
7074 1531890 : rewrite_out_of_ssa (&SA);
7075 1531890 : timevar_pop (TV_OUT_OF_SSA);
7076 1531890 : SA.partition_to_pseudo = XCNEWVEC (rtx, SA.map->num_partitions);
7077 :
7078 1531890 : if (MAY_HAVE_DEBUG_BIND_STMTS && flag_tree_ter)
7079 : {
7080 503328 : gimple_stmt_iterator gsi;
7081 6914456 : FOR_EACH_BB_FN (bb, cfun)
7082 87518202 : for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
7083 115547477 : if (gimple_debug_bind_p (gsi_stmt (gsi)))
7084 40851531 : avoid_deep_ter_for_debug (gsi_stmt (gsi), 0);
7085 : }
7086 :
7087 : /* Mark arrays indexed with non-constant indices with TREE_ADDRESSABLE. */
7088 1531890 : auto_bitmap forced_stack_vars;
7089 1531890 : discover_nonconstant_array_refs (forced_stack_vars);
7090 :
7091 : /* Make sure all values used by the optimization passes have sane
7092 : defaults. */
7093 1531890 : reg_renumber = 0;
7094 :
7095 : /* Some backends want to know that we are expanding to RTL. */
7096 1531890 : currently_expanding_to_rtl = 1;
7097 : /* Dominators are not kept up-to-date as we may create new basic-blocks. */
7098 1531890 : free_dominance_info (CDI_DOMINATORS);
7099 :
7100 1531890 : rtl_profile_for_bb (ENTRY_BLOCK_PTR_FOR_FN (fun));
7101 :
7102 1531890 : insn_locations_init ();
7103 1531890 : if (!DECL_IS_UNDECLARED_BUILTIN (current_function_decl))
7104 : {
7105 : /* Eventually, all FEs should explicitly set function_start_locus. */
7106 1407540 : if (LOCATION_LOCUS (fun->function_start_locus) == UNKNOWN_LOCATION)
7107 662997 : set_curr_insn_location
7108 662997 : (DECL_SOURCE_LOCATION (current_function_decl));
7109 : else
7110 744543 : set_curr_insn_location (fun->function_start_locus);
7111 : }
7112 : else
7113 124350 : set_curr_insn_location (UNKNOWN_LOCATION);
7114 1531890 : prologue_location = curr_insn_location ();
7115 :
7116 : #ifdef INSN_SCHEDULING
7117 1531890 : init_sched_attrs ();
7118 : #endif
7119 :
7120 : /* Make sure first insn is a note even if we don't want linenums.
7121 : This makes sure the first insn will never be deleted.
7122 : Also, final expects a note to appear there. */
7123 1531890 : emit_note (NOTE_INSN_DELETED);
7124 :
7125 1531890 : targetm.expand_to_rtl_hook ();
7126 1531890 : crtl->init_stack_alignment ();
7127 1531890 : fun->cfg->max_jumptable_ents = 0;
7128 :
7129 : /* Resolve the function section. Some targets, like ARM EABI rely on knowledge
7130 : of the function section at expansion time to predict distance of calls. */
7131 1531890 : resolve_unique_section (current_function_decl, 0, flag_function_sections);
7132 :
7133 : /* Expand the variables recorded during gimple lowering. */
7134 1531890 : timevar_push (TV_VAR_EXPAND);
7135 1531890 : start_sequence ();
7136 :
7137 1531890 : var_ret_seq = expand_used_vars (forced_stack_vars);
7138 :
7139 1531890 : var_seq = end_sequence ();
7140 1531890 : timevar_pop (TV_VAR_EXPAND);
7141 :
7142 : /* Honor stack protection warnings. */
7143 1531890 : if (warn_stack_protect)
7144 : {
7145 0 : if (fun->calls_alloca)
7146 0 : warning (OPT_Wstack_protector,
7147 : "stack protector not protecting local variables: "
7148 : "variable length buffer");
7149 0 : if (has_short_buffer && !crtl->stack_protect_guard)
7150 0 : warning (OPT_Wstack_protector,
7151 : "stack protector not protecting function: "
7152 : "all local arrays are less than %d bytes long",
7153 0 : (int) param_ssp_buffer_size);
7154 : }
7155 :
7156 : /* Temporarily mark PARM_DECLs and RESULT_DECLs we need to expand to
7157 : memory addressable so expand_function_start can emit the required
7158 : copies. */
7159 1531890 : auto_vec<tree, 16> marked_parms;
7160 4715231 : for (tree parm = DECL_ARGUMENTS (current_function_decl); parm;
7161 3183341 : parm = DECL_CHAIN (parm))
7162 3183341 : if (!TREE_ADDRESSABLE (parm)
7163 3183341 : && bitmap_bit_p (forced_stack_vars, DECL_UID (parm)))
7164 : {
7165 189 : TREE_ADDRESSABLE (parm) = 1;
7166 189 : marked_parms.safe_push (parm);
7167 : }
7168 1531890 : if (DECL_RESULT (current_function_decl)
7169 1531890 : && !TREE_ADDRESSABLE (DECL_RESULT (current_function_decl))
7170 3056554 : && bitmap_bit_p (forced_stack_vars,
7171 1524664 : DECL_UID (DECL_RESULT (current_function_decl))))
7172 : {
7173 0 : TREE_ADDRESSABLE (DECL_RESULT (current_function_decl)) = 1;
7174 0 : marked_parms.safe_push (DECL_RESULT (current_function_decl));
7175 : }
7176 :
7177 : /* Set up parameters and prepare for return, for the function. */
7178 1531890 : expand_function_start (current_function_decl);
7179 :
7180 : /* Clear TREE_ADDRESSABLE again. */
7181 3063969 : while (!marked_parms.is_empty ())
7182 189 : TREE_ADDRESSABLE (marked_parms.pop ()) = 0;
7183 :
7184 : /* If we emitted any instructions for setting up the variables,
7185 : emit them before the FUNCTION_START note. */
7186 1531890 : if (var_seq)
7187 : {
7188 1856 : emit_insn_before (var_seq, parm_birth_insn);
7189 :
7190 : /* In expand_function_end we'll insert the alloca save/restore
7191 : before parm_birth_insn. We've just insertted an alloca call.
7192 : Adjust the pointer to match. */
7193 1856 : parm_birth_insn = var_seq;
7194 : }
7195 :
7196 : /* Now propagate the RTL assignment of each partition to the
7197 : underlying var of each SSA_NAME. */
7198 1531890 : tree name;
7199 :
7200 76016017 : FOR_EACH_SSA_NAME (i, name, cfun)
7201 : {
7202 : /* We might have generated new SSA names in
7203 : update_alias_info_with_stack_vars. They will have a NULL
7204 : defining statements, and won't be part of the partitioning,
7205 : so ignore those. */
7206 50715317 : if (!SSA_NAME_DEF_STMT (name))
7207 73185 : continue;
7208 :
7209 50642132 : adjust_one_expanded_partition_var (name);
7210 : }
7211 :
7212 : /* Clean up RTL of variables that straddle across multiple
7213 : partitions, and check that the rtl of any PARM_DECLs that are not
7214 : cleaned up is that of their default defs. */
7215 76016017 : FOR_EACH_SSA_NAME (i, name, cfun)
7216 : {
7217 50715317 : int part;
7218 :
7219 : /* We might have generated new SSA names in
7220 : update_alias_info_with_stack_vars. They will have a NULL
7221 : defining statements, and won't be part of the partitioning,
7222 : so ignore those. */
7223 50715317 : if (!SSA_NAME_DEF_STMT (name))
7224 73185 : continue;
7225 50642132 : part = var_to_partition (SA.map, name);
7226 50642132 : if (part == NO_PARTITION)
7227 18068401 : continue;
7228 :
7229 : /* If this decl was marked as living in multiple places, reset
7230 : this now to NULL. */
7231 32573731 : tree var = SSA_NAME_VAR (name);
7232 10803589 : if (var && DECL_RTL_IF_SET (var) == pc_rtx)
7233 250701 : SET_DECL_RTL (var, NULL);
7234 : /* Check that the pseudos chosen by assign_parms are those of
7235 : the corresponding default defs. */
7236 32323030 : else if (SSA_NAME_IS_DEFAULT_DEF (name)
7237 32323030 : && (TREE_CODE (var) == PARM_DECL
7238 3771808 : || TREE_CODE (var) == RESULT_DECL))
7239 : {
7240 3708068 : rtx in = DECL_RTL_IF_SET (var);
7241 3708068 : gcc_assert (in);
7242 3708068 : rtx out = SA.partition_to_pseudo[part];
7243 3708068 : gcc_assert (in == out);
7244 :
7245 : /* Now reset VAR's RTL to IN, so that the _EXPR attrs match
7246 : those expected by debug backends for each parm and for
7247 : the result. This is particularly important for stabs,
7248 : whose register elimination from parm's DECL_RTL may cause
7249 : -fcompare-debug differences as SET_DECL_RTL changes reg's
7250 : attrs. So, make sure the RTL already has the parm as the
7251 : EXPR, so that it won't change. */
7252 3708068 : SET_DECL_RTL (var, NULL_RTX);
7253 3708068 : if (MEM_P (in))
7254 797839 : set_mem_attributes (in, var, true);
7255 3708068 : SET_DECL_RTL (var, in);
7256 : }
7257 : }
7258 :
7259 1531890 : if (flag_checking)
7260 1531870 : verify_partition_mem_exprs ();
7261 :
7262 : /* If this function is `main', emit a call to `__main'
7263 : to run global initializers, etc. */
7264 1531890 : if (DECL_NAME (current_function_decl)
7265 1531890 : && MAIN_NAME_P (DECL_NAME (current_function_decl))
7266 1649825 : && DECL_FILE_SCOPE_P (current_function_decl))
7267 1531890 : expand_main_function ();
7268 :
7269 : /* Initialize the stack_protect_guard field. This must happen after the
7270 : call to __main (if any) so that the external decl is initialized. */
7271 1531890 : if (crtl->stack_protect_guard && targetm.stack_protect_runtime_enabled_p ())
7272 308 : stack_protect_prologue ();
7273 :
7274 1531890 : expand_phi_nodes (&SA);
7275 :
7276 : /* Release any stale SSA redirection data. */
7277 1531890 : redirect_edge_var_map_empty ();
7278 :
7279 : /* Register rtl specific functions for cfg. */
7280 1531890 : rtl_register_cfg_hooks ();
7281 :
7282 1531890 : init_block = construct_init_block ();
7283 :
7284 : /* Clear EDGE_EXECUTABLE on the entry edge(s). It is cleaned from the
7285 : remaining edges later. */
7286 3063780 : FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR_FOR_FN (fun)->succs)
7287 1531890 : e->flags &= ~EDGE_EXECUTABLE;
7288 :
7289 : /* If the function has too many markers, drop them while expanding. */
7290 1531890 : if (cfun->debug_marker_count
7291 1531890 : >= param_max_debug_marker_count)
7292 1 : cfun->debug_nonbind_markers = false;
7293 :
7294 1531890 : if (optimize)
7295 1070549 : enable_ranger (fun);
7296 1531890 : lab_rtx_for_bb = new hash_map<basic_block, rtx_code_label *>;
7297 1531890 : head_end_for_bb.create (last_basic_block_for_fn (fun));
7298 14557811 : FOR_BB_BETWEEN (bb, init_block->next_bb, EXIT_BLOCK_PTR_FOR_FN (fun),
7299 : next_bb)
7300 13025923 : bb = expand_gimple_basic_block (bb, var_ret_seq);
7301 1531888 : if (optimize)
7302 1070549 : disable_ranger (fun);
7303 14959136 : FOR_BB_BETWEEN (bb, init_block->next_bb, EXIT_BLOCK_PTR_FOR_FN (fun),
7304 : next_bb)
7305 : {
7306 13427248 : if ((bb->flags & BB_RTL) == 0)
7307 : {
7308 13025913 : bb->il.gimple.seq = NULL;
7309 13025913 : bb->il.gimple.phi_nodes = NULL;
7310 13025913 : init_rtl_bb_info (bb);
7311 13025913 : bb->flags |= BB_RTL;
7312 13025913 : BB_HEAD (bb) = head_end_for_bb[bb->index].first;
7313 13025913 : BB_END (bb) = head_end_for_bb[bb->index].second;
7314 : }
7315 : /* These flags have no purpose in RTL land. */
7316 13427248 : if (EDGE_COUNT (bb->succs) == 2)
7317 : {
7318 6465536 : EDGE_SUCC (bb, 0)->flags &= ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE);
7319 6465536 : EDGE_SUCC (bb, 1)->flags &= ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE);
7320 : }
7321 19593541 : else if (single_succ_p (bb))
7322 6166293 : single_succ_edge (bb)->flags &= ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE);
7323 : }
7324 1531888 : head_end_for_bb.release ();
7325 :
7326 1531888 : if (MAY_HAVE_DEBUG_BIND_INSNS)
7327 503353 : expand_debug_locations ();
7328 :
7329 1531888 : if (deep_ter_debug_map)
7330 : {
7331 736 : delete deep_ter_debug_map;
7332 736 : deep_ter_debug_map = NULL;
7333 : }
7334 :
7335 : /* Free stuff we no longer need after GIMPLE optimizations. */
7336 1531888 : free_dominance_info (CDI_DOMINATORS);
7337 1531888 : free_dominance_info (CDI_POST_DOMINATORS);
7338 1531888 : delete_tree_cfg_annotations (fun);
7339 :
7340 1531888 : timevar_push (TV_OUT_OF_SSA);
7341 1531888 : finish_out_of_ssa (&SA);
7342 1531888 : timevar_pop (TV_OUT_OF_SSA);
7343 :
7344 1531888 : timevar_push (TV_POST_EXPAND);
7345 : /* We are no longer in SSA form. */
7346 1531888 : fun->gimple_df->in_ssa_p = false;
7347 1531888 : loops_state_clear (LOOP_CLOSED_SSA);
7348 :
7349 : /* Expansion is used by optimization passes too, set maybe_hot_insn_p
7350 : conservatively to true until they are all profile aware. */
7351 3063776 : delete lab_rtx_for_bb;
7352 1531888 : free_histograms (fun);
7353 :
7354 1531888 : construct_exit_block ();
7355 1531888 : insn_locations_finalize ();
7356 :
7357 1531888 : if (var_ret_seq)
7358 : {
7359 1996 : rtx_insn *after = return_label;
7360 1996 : rtx_insn *next = NEXT_INSN (after);
7361 1996 : if (next && NOTE_INSN_BASIC_BLOCK_P (next))
7362 : after = next;
7363 1996 : emit_insn_after (var_ret_seq, after);
7364 : }
7365 :
7366 1531888 : if (hwassist_sanitize_stack_p ())
7367 454 : hwasan_maybe_emit_frame_base_init ();
7368 :
7369 : /* Zap the tree EH table. */
7370 1531888 : set_eh_throw_stmt_table (fun, NULL);
7371 :
7372 : /* We need JUMP_LABEL be set in order to redirect jumps, and hence
7373 : split edges which edge insertions might do. */
7374 1531888 : rebuild_jump_labels (get_insns ());
7375 :
7376 : /* If we have a single successor to the entry block, put the pending insns
7377 : after parm birth, but before NOTE_INSNS_FUNCTION_BEG. */
7378 1531888 : if (single_succ_p (ENTRY_BLOCK_PTR_FOR_FN (fun)))
7379 : {
7380 1531888 : edge e = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (fun));
7381 1531888 : if (e->insns.r)
7382 : {
7383 11 : rtx_insn *insns = e->insns.r;
7384 11 : e->insns.r = NULL;
7385 11 : rebuild_jump_labels_chain (insns);
7386 11 : if (NOTE_P (parm_birth_insn)
7387 11 : && NOTE_KIND (parm_birth_insn) == NOTE_INSN_FUNCTION_BEG)
7388 11 : emit_insn_before_noloc (insns, parm_birth_insn, e->dest);
7389 : else
7390 0 : emit_insn_after_noloc (insns, parm_birth_insn, e->dest);
7391 : }
7392 : }
7393 :
7394 : /* Otherwise, as well as for other edges, take the usual way. */
7395 1531888 : commit_edge_insertions ();
7396 :
7397 : /* We're done expanding trees to RTL. */
7398 1531888 : currently_expanding_to_rtl = 0;
7399 :
7400 1531888 : flush_mark_addressable_queue ();
7401 :
7402 18639533 : FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (fun)->next_bb,
7403 : EXIT_BLOCK_PTR_FOR_FN (fun), next_bb)
7404 : {
7405 17107645 : edge e;
7406 17107645 : edge_iterator ei;
7407 39972089 : for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
7408 : {
7409 : /* Clear EDGE_EXECUTABLE. This flag is never used in the backend. */
7410 22864444 : e->flags &= ~EDGE_EXECUTABLE;
7411 :
7412 : /* At the moment not all abnormal edges match the RTL
7413 : representation. It is safe to remove them here as
7414 : find_many_sub_basic_blocks will rediscover them.
7415 : In the future we should get this fixed properly. */
7416 22864444 : if ((e->flags & EDGE_ABNORMAL)
7417 139196 : && !(e->flags & EDGE_SIBCALL))
7418 10719 : remove_edge (e);
7419 : else
7420 22853725 : ei_next (&ei);
7421 : }
7422 : }
7423 :
7424 1531888 : auto_sbitmap blocks (last_basic_block_for_fn (fun));
7425 1531888 : bitmap_ones (blocks);
7426 1531888 : find_many_sub_basic_blocks (blocks);
7427 1531888 : purge_all_dead_edges ();
7428 :
7429 : /* After initial rtl generation, call back to finish generating
7430 : exception support code. We need to do this before cleaning up
7431 : the CFG as the code does not expect dead landing pads. */
7432 1531888 : if (fun->eh->region_tree != NULL)
7433 66048 : finish_eh_generation ();
7434 :
7435 : /* Call expand_stack_alignment after finishing all
7436 : updates to crtl->preferred_stack_boundary. */
7437 1531888 : expand_stack_alignment ();
7438 :
7439 : /* Fixup REG_EQUIV notes in the prologue if there are tailcalls in this
7440 : function. */
7441 1531888 : if (crtl->tail_call_emit)
7442 115753 : fixup_tail_calls ();
7443 :
7444 1531888 : HOST_WIDE_INT patch_area_size, patch_area_entry;
7445 1531888 : parse_and_check_patch_area (flag_patchable_function_entry, false,
7446 : &patch_area_size, &patch_area_entry);
7447 :
7448 1531888 : tree patchable_function_entry_attr
7449 1531888 : = lookup_attribute ("patchable_function_entry",
7450 1531888 : DECL_ATTRIBUTES (cfun->decl));
7451 1531888 : if (patchable_function_entry_attr)
7452 : {
7453 28 : tree pp_val = TREE_VALUE (patchable_function_entry_attr);
7454 28 : tree patchable_function_entry_value1 = TREE_VALUE (pp_val);
7455 :
7456 28 : patch_area_size = tree_to_uhwi (patchable_function_entry_value1);
7457 28 : patch_area_entry = 0;
7458 28 : if (TREE_CHAIN (pp_val) != NULL_TREE)
7459 : {
7460 16 : tree patchable_function_entry_value2
7461 16 : = TREE_VALUE (TREE_CHAIN (pp_val));
7462 16 : patch_area_entry = tree_to_uhwi (patchable_function_entry_value2);
7463 : }
7464 : }
7465 :
7466 1531888 : if (patch_area_entry > patch_area_size)
7467 : {
7468 8 : warning (OPT_Wattributes,
7469 : "patchable function entry %wu exceeds size %wu",
7470 : patch_area_entry, patch_area_size);
7471 8 : patch_area_entry = 0;
7472 : }
7473 :
7474 1531888 : crtl->patch_area_size = patch_area_size;
7475 1531888 : crtl->patch_area_entry = patch_area_entry;
7476 :
7477 : /* BB subdivision may have created basic blocks that are only reachable
7478 : from unlikely bbs but not marked as such in the profile. */
7479 1531888 : if (optimize)
7480 1070549 : propagate_unlikely_bbs_forward ();
7481 :
7482 : /* Remove unreachable blocks, otherwise we cannot compute dominators
7483 : which are needed for loop state verification. As a side-effect
7484 : this also compacts blocks.
7485 : ??? We cannot remove trivially dead insns here as for example
7486 : the DRAP reg on i?86 is not magically live at this point.
7487 : gcc.c-torture/execute/ipa-sra-2.c execution, -Os -m32 fails otherwise. */
7488 1531888 : cleanup_cfg (CLEANUP_NO_INSN_DEL);
7489 :
7490 1531888 : checking_verify_flow_info ();
7491 :
7492 : /* Initialize pseudos allocated for hard registers. */
7493 1531888 : emit_initial_value_sets ();
7494 :
7495 : /* And finally unshare all RTL. */
7496 1531888 : unshare_all_rtl ();
7497 :
7498 : /* There's no need to defer outputting this function any more; we
7499 : know we want to output it. */
7500 1531888 : DECL_DEFER_OUTPUT (current_function_decl) = 0;
7501 :
7502 : /* Now that we're done expanding trees to RTL, we shouldn't have any
7503 : more CONCATs anywhere. */
7504 1531888 : generating_concat_p = 0;
7505 :
7506 1531888 : if (dump_file)
7507 : {
7508 403 : fprintf (dump_file,
7509 : "\n\n;;\n;; Full RTL generated for this function:\n;;\n");
7510 : /* And the pass manager will dump RTL for us. */
7511 : }
7512 :
7513 : /* If we're emitting a nested function, make sure its parent gets
7514 : emitted as well. Doing otherwise confuses debug info. */
7515 1531888 : {
7516 1531888 : tree parent;
7517 1531888 : for (parent = DECL_CONTEXT (current_function_decl);
7518 3291355 : parent != NULL_TREE;
7519 1759467 : parent = get_containing_scope (parent))
7520 1759467 : if (TREE_CODE (parent) == FUNCTION_DECL)
7521 80305 : TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
7522 : }
7523 :
7524 1531888 : TREE_ASM_WRITTEN (current_function_decl) = 1;
7525 :
7526 : /* After expanding, the return labels are no longer needed. */
7527 1531888 : return_label = NULL;
7528 1531888 : naked_return_label = NULL;
7529 :
7530 : /* After expanding, the tm_restart map is no longer needed. */
7531 1531888 : if (fun->gimple_df->tm_restart)
7532 265 : fun->gimple_df->tm_restart = NULL;
7533 :
7534 : /* Tag the blocks with a depth number so that change_scope can find
7535 : the common parent easily. */
7536 1531888 : set_block_levels (DECL_INITIAL (fun->decl), 0);
7537 1531888 : default_rtl_profile ();
7538 :
7539 : /* For -dx discard loops now, otherwise IL verify in clean_state will
7540 : ICE. */
7541 1531888 : if (rtl_dump_and_exit)
7542 : {
7543 79 : cfun->curr_properties &= ~PROP_loops;
7544 79 : loop_optimizer_finalize ();
7545 : }
7546 :
7547 1531888 : timevar_pop (TV_POST_EXPAND);
7548 :
7549 1531888 : return 0;
7550 1531888 : }
7551 :
7552 : } // anon namespace
7553 :
7554 : rtl_opt_pass *
7555 302989 : make_pass_expand (gcc::context *ctxt)
7556 : {
7557 302989 : return new pass_expand (ctxt);
7558 : }
|