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