Line data Source code
1 : /* Expands front end tree to back end RTL for GCC.
2 : Copyright (C) 1987-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 it under
7 : the terms of the GNU General Public License as published by the Free
8 : Software Foundation; either version 3, or (at your option) any later
9 : version.
10 :
11 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 : 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 : /* This file handles the generation of rtl code from tree structure
21 : at the level of the function as a whole.
22 : It creates the rtl expressions for parameters and auto variables
23 : and has full responsibility for allocating stack slots.
24 :
25 : `expand_function_start' is called at the beginning of a function,
26 : before the function body is parsed, and `expand_function_end' is
27 : called after parsing the body.
28 :
29 : Call `assign_stack_local' to allocate a stack slot for a local variable.
30 : This is usually done during the RTL generation for the function body,
31 : but it can also be done in the reload pass when a pseudo-register does
32 : not get a hard register. */
33 :
34 : #include "config.h"
35 : #include "system.h"
36 : #include "coretypes.h"
37 : #include "backend.h"
38 : #include "target.h"
39 : #include "rtl.h"
40 : #include "tree.h"
41 : #include "gimple-expr.h"
42 : #include "cfghooks.h"
43 : #include "df.h"
44 : #include "memmodel.h"
45 : #include "tm_p.h"
46 : #include "stringpool.h"
47 : #include "expmed.h"
48 : #include "optabs.h"
49 : #include "opts.h"
50 : #include "regs.h"
51 : #include "emit-rtl.h"
52 : #include "recog.h"
53 : #include "rtl-error.h"
54 : #include "hard-reg-set.h"
55 : #include "alias.h"
56 : #include "fold-const.h"
57 : #include "stor-layout.h"
58 : #include "varasm.h"
59 : #include "except.h"
60 : #include "dojump.h"
61 : #include "explow.h"
62 : #include "calls.h"
63 : #include "expr.h"
64 : #include "optabs-tree.h"
65 : #include "output.h"
66 : #include "langhooks.h"
67 : #include "common/common-target.h"
68 : #include "gimplify.h"
69 : #include "tree-pass.h"
70 : #include "cfgrtl.h"
71 : #include "cfganal.h"
72 : #include "cfgbuild.h"
73 : #include "cfgcleanup.h"
74 : #include "cfgexpand.h"
75 : #include "shrink-wrap.h"
76 : #include "toplev.h"
77 : #include "rtl-iter.h"
78 : #include "tree-dfa.h"
79 : #include "tree-ssa.h"
80 : #include "attribs.h"
81 : #include "gimple.h"
82 : #include "options.h"
83 : #include "function-abi.h"
84 : #include "value-range.h"
85 : #include "gimple-range.h"
86 : #include "insn-attr.h"
87 : #include "hierarchical_discriminator.h"
88 :
89 : /* So we can assign to cfun in this file. */
90 : #undef cfun
91 :
92 : #ifndef STACK_ALIGNMENT_NEEDED
93 : #define STACK_ALIGNMENT_NEEDED 1
94 : #endif
95 :
96 : #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
97 :
98 : /* Round a value to the lowest integer less than it that is a multiple of
99 : the required alignment. Avoid using division in case the value is
100 : negative. Assume the alignment is a power of two. */
101 : #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
102 :
103 : /* Similar, but round to the next highest integer that meets the
104 : alignment. */
105 : #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
106 :
107 : /* Nonzero once virtual register instantiation has been done.
108 : assign_stack_local uses frame_pointer_rtx when this is nonzero.
109 : calls.cc:emit_library_call_value_1 uses it to set up
110 : post-instantiation libcalls. */
111 : int virtuals_instantiated;
112 :
113 : /* Assign unique numbers to labels generated for profiling, debugging, etc. */
114 : static GTY(()) int funcdef_no;
115 :
116 : /* These variables hold pointers to functions to create and destroy
117 : target specific, per-function data structures. */
118 : struct machine_function * (*init_machine_status) (void);
119 :
120 : /* The currently compiled function. */
121 : struct function *cfun = 0;
122 :
123 : /* These hashes record the prologue and epilogue insns. */
124 :
125 : struct insn_cache_hasher : ggc_cache_ptr_hash<rtx_def>
126 : {
127 1194148135 : static hashval_t hash (rtx x) { return htab_hash_pointer (x); }
128 : static bool equal (rtx a, rtx b) { return a == b; }
129 : };
130 :
131 : static GTY((cache))
132 : hash_table<insn_cache_hasher> *prologue_insn_hash;
133 : static GTY((cache))
134 : hash_table<insn_cache_hasher> *epilogue_insn_hash;
135 :
136 :
137 : hash_table<used_type_hasher> *types_used_by_vars_hash = NULL;
138 : vec<tree, va_gc> *types_used_by_cur_var_decl;
139 :
140 : /* Forward declarations. */
141 :
142 : static class temp_slot *find_temp_slot_from_address (rtx);
143 : static void pad_to_arg_alignment (struct args_size *, int, struct args_size *);
144 : static void pad_below (struct args_size *, machine_mode, tree);
145 : static void reorder_blocks_1 (rtx_insn *, tree, vec<tree> *);
146 : static int all_blocks (tree, tree *);
147 : static tree *get_block_vector (tree, int *);
148 : extern tree debug_find_var_in_block_tree (tree, tree);
149 : /* We always define `record_insns' even if it's not used so that we
150 : can always export `prologue_epilogue_contains'. */
151 : static void record_insns (rtx_insn *, rtx_insn *,
152 : hash_table<insn_cache_hasher> **)
153 : ATTRIBUTE_UNUSED;
154 : static bool contains (const rtx_insn *, hash_table<insn_cache_hasher> *);
155 : static void prepare_function_start (void);
156 : static void do_clobber_return_reg (rtx, void *);
157 : static void do_use_return_reg (rtx, void *);
158 : static rtx assign_stack_local_2 (machine_mode, poly_int64, int, int, rtx *);
159 :
160 :
161 : /* Stack of nested functions. */
162 : /* Keep track of the cfun stack. */
163 :
164 : static vec<function *> function_context_stack;
165 :
166 : /* Save the current context for compilation of a nested function.
167 : This is called from language-specific code. */
168 :
169 : void
170 97410095 : push_function_context (void)
171 : {
172 97410095 : if (cfun == 0)
173 25 : allocate_struct_function (NULL, false);
174 :
175 97410095 : function_context_stack.safe_push (cfun);
176 97410095 : set_cfun (NULL);
177 97410095 : }
178 :
179 : /* Restore the last saved context, at the end of a nested function.
180 : This function is called from language-specific code. */
181 :
182 : void
183 97410072 : pop_function_context (void)
184 : {
185 97410072 : struct function *p = function_context_stack.pop ();
186 97410072 : set_cfun (p);
187 97410072 : current_function_decl = p->decl;
188 :
189 : /* Reset variables that have known state during rtx generation. */
190 97410072 : virtuals_instantiated = 0;
191 97410072 : generating_concat_p = 1;
192 97410072 : }
193 :
194 : /* Clear out all parts of the state in F that can safely be discarded
195 : after the function has been parsed, but not compiled, to let
196 : garbage collection reclaim the memory. */
197 :
198 : void
199 1758104 : free_after_parsing (struct function *f)
200 : {
201 1758104 : f->language = 0;
202 1758104 : }
203 :
204 : /* Clear out all parts of the state in F that can safely be discarded
205 : after the function has been compiled, to let garbage collection
206 : reclaim the memory. */
207 :
208 : void
209 1763786 : free_after_compilation (struct function *f)
210 : {
211 1763786 : prologue_insn_hash = NULL;
212 1763786 : epilogue_insn_hash = NULL;
213 :
214 1763786 : free (crtl->emit.regno_pointer_align);
215 :
216 1763786 : memset (crtl, 0, sizeof (struct rtl_data));
217 1763786 : f->eh = NULL;
218 1763786 : f->machine = NULL;
219 1763786 : f->cfg = NULL;
220 1763786 : f->curr_properties &= ~PROP_cfg;
221 1763930 : delete f->cond_uids;
222 1763786 : free_copyid_allocator (f);
223 :
224 1763786 : regno_reg_rtx = NULL;
225 1763786 : }
226 :
227 : /* Return size needed for stack frame based on slots so far allocated.
228 : This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
229 : the caller may have to do that. */
230 :
231 : poly_int64
232 149591541 : get_frame_size (void)
233 : {
234 149591541 : if (FRAME_GROWS_DOWNWARD)
235 149591541 : return -frame_offset;
236 : else
237 : return frame_offset;
238 : }
239 :
240 : /* Issue an error message and return TRUE if frame OFFSET overflows in
241 : the signed target pointer arithmetics for function FUNC. Otherwise
242 : return FALSE. */
243 :
244 : bool
245 4104518 : frame_offset_overflow (poly_int64 offset, tree func)
246 : {
247 4104518 : poly_uint64 size = FRAME_GROWS_DOWNWARD ? -offset : offset;
248 4104518 : unsigned HOST_WIDE_INT limit
249 4104518 : = ((HOST_WIDE_INT_1U << (GET_MODE_BITSIZE (Pmode) - 1))
250 : /* Leave room for the fixed part of the frame. */
251 4104518 : - 64 * UNITS_PER_WORD);
252 :
253 8209036 : if (!coeffs_in_range_p (size, 0U, limit))
254 : {
255 0 : unsigned HOST_WIDE_INT hwisize;
256 0 : if (size.is_constant (&hwisize))
257 0 : error_at (DECL_SOURCE_LOCATION (func),
258 : "total size of local objects %wu exceeds maximum %wu",
259 : hwisize, limit);
260 : else
261 : error_at (DECL_SOURCE_LOCATION (func),
262 : "total size of local objects exceeds maximum %wu",
263 : limit);
264 0 : return true;
265 : }
266 :
267 : return false;
268 : }
269 :
270 : /* Return the minimum spill slot alignment for a register of mode MODE. */
271 :
272 : unsigned int
273 1464911 : spill_slot_alignment (machine_mode mode ATTRIBUTE_UNUSED)
274 : {
275 1464911 : return STACK_SLOT_ALIGNMENT (NULL_TREE, mode, GET_MODE_ALIGNMENT (mode));
276 : }
277 :
278 : /* Return stack slot alignment in bits for TYPE and MODE. */
279 :
280 : static unsigned int
281 150106 : get_stack_local_alignment (tree type, machine_mode mode)
282 : {
283 150106 : unsigned int alignment;
284 :
285 150106 : if (mode == BLKmode)
286 22657 : alignment = BIGGEST_ALIGNMENT;
287 : else
288 127449 : alignment = GET_MODE_ALIGNMENT (mode);
289 :
290 : /* Allow the frond-end to (possibly) increase the alignment of this
291 : stack slot. */
292 150106 : if (! type)
293 51189 : type = lang_hooks.types.type_for_mode (mode, 0);
294 :
295 150106 : return STACK_SLOT_ALIGNMENT (type, mode, alignment);
296 : }
297 :
298 : /* Determine whether it is possible to fit a stack slot of size SIZE and
299 : alignment ALIGNMENT into an area in the stack frame that starts at
300 : frame offset START and has a length of LENGTH. If so, store the frame
301 : offset to be used for the stack slot in *POFFSET and return true;
302 : return false otherwise. This function will extend the frame size when
303 : given a start/length pair that lies at the end of the frame. */
304 :
305 : static bool
306 2456845 : try_fit_stack_local (poly_int64 start, poly_int64 length,
307 : poly_int64 size, unsigned int alignment,
308 : poly_int64 *poffset)
309 : {
310 2456845 : poly_int64 this_frame_offset;
311 2456845 : int frame_off, frame_alignment, frame_phase;
312 :
313 : /* Calculate how many bytes the start of local variables is off from
314 : stack alignment. */
315 2456845 : frame_alignment = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
316 2456845 : frame_off = targetm.starting_frame_offset () % frame_alignment;
317 2456845 : frame_phase = frame_off ? frame_alignment - frame_off : 0;
318 :
319 : /* Round the frame offset to the specified alignment. */
320 :
321 2456845 : if (FRAME_GROWS_DOWNWARD)
322 2456845 : this_frame_offset
323 2456845 : = (aligned_lower_bound (start + length - size - frame_phase, alignment)
324 2456845 : + frame_phase);
325 : else
326 : this_frame_offset
327 : = aligned_upper_bound (start - frame_phase, alignment) + frame_phase;
328 :
329 : /* See if it fits. If this space is at the edge of the frame,
330 : consider extending the frame to make it fit. Our caller relies on
331 : this when allocating a new slot. */
332 2456845 : if (maybe_lt (this_frame_offset, start))
333 : {
334 512354 : if (known_eq (frame_offset, start))
335 380722 : frame_offset = this_frame_offset;
336 : else
337 : return false;
338 : }
339 1944491 : else if (maybe_gt (this_frame_offset + size, start + length))
340 : {
341 0 : if (known_eq (frame_offset, start + length))
342 0 : frame_offset = this_frame_offset + size;
343 : else
344 : return false;
345 : }
346 :
347 2325213 : *poffset = this_frame_offset;
348 2325213 : return true;
349 : }
350 :
351 : /* Create a new frame_space structure describing free space in the stack
352 : frame beginning at START and ending at END, and chain it into the
353 : function's frame_space_list. */
354 :
355 : static void
356 406211 : add_frame_space (poly_int64 start, poly_int64 end)
357 : {
358 406211 : class frame_space *space = ggc_alloc<frame_space> ();
359 406211 : space->next = crtl->frame_space_list;
360 406211 : crtl->frame_space_list = space;
361 406211 : space->start = start;
362 406211 : space->length = end - start;
363 406211 : }
364 :
365 : /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
366 : with machine mode MODE.
367 :
368 : ALIGN controls the amount of alignment for the address of the slot:
369 : 0 means according to MODE,
370 : -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
371 : -2 means use BITS_PER_UNIT,
372 : positive specifies alignment boundary in bits.
373 :
374 : A positive ALIGN that exceeds MAX_SUPPORTED_STACK_ALIGNMENT is honoured
375 : by overallocating the slot and aligning its address at run time, with
376 : insns emitted at the current position, unless KIND has ASLK_REDUCE_ALIGN.
377 :
378 : KIND has ASLK_REDUCE_ALIGN bit set if it is OK to reduce
379 : alignment and ASLK_RECORD_PAD bit set if we should remember
380 : extra space we allocated for alignment purposes. When we are
381 : called from assign_stack_temp_for_type, it is not set so we don't
382 : track the same stack slot in two independent lists.
383 :
384 : We do not round to stack_boundary here. */
385 :
386 : rtx
387 2246555 : assign_stack_local_1 (machine_mode mode, poly_int64 size,
388 : int align, int kind)
389 : {
390 2246555 : return assign_stack_local_2 (mode, size, align, kind, NULL);
391 : }
392 :
393 : /* Like assign_stack_local_1. If BASE_ADDR is nonnull, set it to the slot
394 : address before run-time alignment, or to NULL_RTX if none was needed. */
395 :
396 : static rtx
397 2325213 : assign_stack_local_2 (machine_mode mode, poly_int64 size,
398 : int align, int kind, rtx *base_addr)
399 : {
400 2325213 : rtx x, addr;
401 2325213 : poly_int64 bigend_correction = 0;
402 2325213 : poly_int64 slot_offset = 0, old_frame_offset;
403 2325213 : unsigned int alignment, alignment_in_bits, dynamic_align = 0;
404 :
405 2325213 : if (base_addr)
406 78658 : *base_addr = NULL_RTX;
407 :
408 2325213 : if (align == 0)
409 : {
410 7278 : alignment = get_stack_local_alignment (NULL, mode);
411 7278 : alignment /= BITS_PER_UNIT;
412 : }
413 2317935 : else if (align == -1)
414 : {
415 947 : alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
416 947 : size = aligned_upper_bound (size, alignment);
417 : }
418 2316988 : else if (align == -2)
419 : alignment = 1; /* BITS_PER_UNIT / BITS_PER_UNIT */
420 : else
421 2316988 : alignment = align / BITS_PER_UNIT;
422 :
423 2325213 : alignment_in_bits = alignment * BITS_PER_UNIT;
424 :
425 : /* The frame cannot be aligned beyond MAX_SUPPORTED_STACK_ALIGNMENT. If more
426 : is requested, pad the slot so that an over-aligned object still fits. */
427 2325213 : if (alignment_in_bits > MAX_SUPPORTED_STACK_ALIGNMENT)
428 : {
429 0 : if (align > 0 && !(kind & ASLK_REDUCE_ALIGN) && maybe_ne (size, 0))
430 : {
431 0 : gcc_assert (currently_expanding_to_rtl);
432 0 : dynamic_align = alignment_in_bits;
433 :
434 0 : if (crtl->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
435 0 : crtl->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
436 :
437 : /* Pad from the alignment the frame base is guaranteed to have. */
438 0 : size += ((alignment_in_bits
439 0 : - REGNO_POINTER_ALIGN (VIRTUAL_STACK_VARS_REGNUM))
440 0 : / BITS_PER_UNIT);
441 : }
442 : alignment_in_bits = MAX_SUPPORTED_STACK_ALIGNMENT;
443 : alignment = MAX_SUPPORTED_STACK_ALIGNMENT / BITS_PER_UNIT;
444 : }
445 :
446 2325213 : if (SUPPORTS_STACK_ALIGNMENT)
447 : {
448 2325213 : if (crtl->stack_alignment_estimated < alignment_in_bits)
449 : {
450 4445 : if (!crtl->stack_realign_processed)
451 4422 : crtl->stack_alignment_estimated = alignment_in_bits;
452 : else
453 : {
454 : /* If stack is realigned and stack alignment value
455 : hasn't been finalized, it is OK not to increase
456 : stack_alignment_estimated. The bigger alignment
457 : requirement is recorded in stack_alignment_needed
458 : below. */
459 23 : gcc_assert (!crtl->stack_realign_finalized);
460 23 : if (!crtl->stack_realign_needed)
461 : {
462 : /* It is OK to reduce the alignment as long as the
463 : requested size is 0 or the estimated stack
464 : alignment >= mode alignment. */
465 23 : gcc_assert ((kind & ASLK_REDUCE_ALIGN)
466 : || known_eq (size, 0)
467 : || (crtl->stack_alignment_estimated
468 : >= GET_MODE_ALIGNMENT (mode)));
469 23 : alignment_in_bits = crtl->stack_alignment_estimated;
470 23 : alignment = alignment_in_bits / BITS_PER_UNIT;
471 : }
472 : }
473 : }
474 : }
475 :
476 2325213 : if (crtl->stack_alignment_needed < alignment_in_bits)
477 20763 : crtl->stack_alignment_needed = alignment_in_bits;
478 2325213 : if (crtl->max_used_stack_slot_alignment < alignment_in_bits)
479 303792 : crtl->max_used_stack_slot_alignment = alignment_in_bits;
480 :
481 2325213 : if (mode != BLKmode || maybe_ne (size, 0))
482 : {
483 1501015 : if (kind & ASLK_RECORD_PAD)
484 : {
485 : class frame_space **psp;
486 :
487 1553989 : for (psp = &crtl->frame_space_list; *psp; psp = &(*psp)->next)
488 : {
489 191573 : class frame_space *space = *psp;
490 191573 : if (!try_fit_stack_local (space->start, space->length, size,
491 : alignment, &slot_offset))
492 131632 : continue;
493 59941 : *psp = space->next;
494 59941 : if (known_gt (slot_offset, space->start))
495 23535 : add_frame_space (space->start, slot_offset);
496 59941 : if (known_lt (slot_offset + size, space->start + space->length))
497 11250 : add_frame_space (slot_offset + size,
498 11250 : space->start + space->length);
499 59941 : goto found_space;
500 : }
501 : }
502 : }
503 : else if (!STACK_ALIGNMENT_NEEDED)
504 : {
505 : slot_offset = frame_offset;
506 : goto found_space;
507 : }
508 :
509 2265272 : old_frame_offset = frame_offset;
510 :
511 2265272 : if (FRAME_GROWS_DOWNWARD)
512 : {
513 2265272 : frame_offset -= size;
514 2265272 : try_fit_stack_local (frame_offset, size, size, alignment, &slot_offset);
515 :
516 2265272 : if (kind & ASLK_RECORD_PAD)
517 : {
518 2186614 : if (known_gt (slot_offset, frame_offset))
519 0 : add_frame_space (frame_offset, slot_offset);
520 2186614 : if (known_lt (slot_offset + size, old_frame_offset))
521 371426 : add_frame_space (slot_offset + size, old_frame_offset);
522 : }
523 : }
524 : else
525 : {
526 : frame_offset += size;
527 : try_fit_stack_local (old_frame_offset, size, size, alignment, &slot_offset);
528 :
529 : if (kind & ASLK_RECORD_PAD)
530 : {
531 : if (known_gt (slot_offset, old_frame_offset))
532 : add_frame_space (old_frame_offset, slot_offset);
533 : if (known_lt (slot_offset + size, frame_offset))
534 : add_frame_space (slot_offset + size, frame_offset);
535 : }
536 : }
537 :
538 2325213 : found_space:
539 : /* On a big-endian machine, if we are allocating more space than we will use,
540 : use the least significant bytes of those that are allocated. */
541 2325213 : if (mode != BLKmode && !dynamic_align)
542 : {
543 : /* The slot size can sometimes be smaller than the mode size;
544 : e.g. the rs6000 port allocates slots with a vector mode
545 : that have the size of only one element. However, the slot
546 : size must always be ordered wrt to the mode size, in the
547 : same way as for a subreg. */
548 701772 : gcc_checking_assert (ordered_p (GET_MODE_SIZE (mode), size));
549 : if (BYTES_BIG_ENDIAN && maybe_lt (GET_MODE_SIZE (mode), size))
550 : bigend_correction = size - GET_MODE_SIZE (mode);
551 : }
552 :
553 : /* If we have already instantiated virtual registers, return the actual
554 : address relative to the frame pointer. */
555 2325213 : if (virtuals_instantiated)
556 1908063 : addr = plus_constant (Pmode, frame_pointer_rtx,
557 : trunc_int_for_mode
558 1609435 : (slot_offset + bigend_correction
559 1908063 : + targetm.starting_frame_offset (), Pmode));
560 : else
561 745025 : addr = plus_constant (Pmode, virtual_stack_vars_rtx,
562 : trunc_int_for_mode
563 : (slot_offset + bigend_correction,
564 715778 : Pmode));
565 :
566 2325213 : if (dynamic_align)
567 : {
568 0 : if (base_addr)
569 0 : *base_addr = addr;
570 0 : addr = align_dynamic_address (addr, dynamic_align);
571 0 : mark_reg_pointer (addr, dynamic_align);
572 0 : alignment_in_bits = dynamic_align;
573 : }
574 :
575 2325213 : x = gen_rtx_MEM (mode, addr);
576 2325213 : set_mem_align (x, alignment_in_bits);
577 2325213 : MEM_NOTRAP_P (x) = 1;
578 :
579 2325213 : vec_safe_push (stack_slot_list, x);
580 :
581 2325213 : if (frame_offset_overflow (frame_offset, current_function_decl))
582 0 : frame_offset = 0;
583 :
584 2325213 : return x;
585 : }
586 :
587 : /* Wrap up assign_stack_local_1 with last parameter as false. */
588 :
589 : rtx
590 1463858 : assign_stack_local (machine_mode mode, poly_int64 size, int align)
591 : {
592 1463858 : return assign_stack_local_1 (mode, size, align, ASLK_RECORD_PAD);
593 : }
594 :
595 : /* In order to evaluate some expressions, such as function calls returning
596 : structures in memory, we need to temporarily allocate stack locations.
597 : We record each allocated temporary in the following structure.
598 :
599 : Associated with each temporary slot is a nesting level. When we pop up
600 : one level, all temporaries associated with the previous level are freed.
601 : Normally, all temporaries are freed after the execution of the statement
602 : in which they were created. However, if we are inside a ({...}) grouping,
603 : the result may be in a temporary and hence must be preserved. If the
604 : result could be in a temporary, we preserve it if we can determine which
605 : one it is in. If we cannot determine which temporary may contain the
606 : result, all temporaries are preserved. A temporary is preserved by
607 : pretending it was allocated at the previous nesting level. */
608 :
609 : class GTY(()) temp_slot {
610 : public:
611 : /* Points to next temporary slot. */
612 : class temp_slot *next;
613 : /* Points to previous temporary slot. */
614 : class temp_slot *prev;
615 : /* The rtx to used to reference the slot. */
616 : rtx slot;
617 : /* The size, in units, of the slot. */
618 : poly_int64 size;
619 : /* The type of the object in the slot, or zero if it doesn't correspond
620 : to a type. We use this to determine whether a slot can be reused.
621 : It can be reused if objects of the type of the new slot will always
622 : conflict with objects of the type of the old slot. */
623 : tree type;
624 : /* The alignment (in bits) of the slot. */
625 : unsigned int align;
626 : /* True if this temporary is currently in use. */
627 : bool in_use;
628 : /* Nesting level at which this slot is being used. */
629 : int level;
630 : /* The offset of the slot from the frame_pointer, including extra space
631 : for alignment. This info is for combine_temp_slots. */
632 : poly_int64 base_offset;
633 : /* The size of the slot, including extra space for alignment. This
634 : info is for combine_temp_slots. */
635 : poly_int64 full_size;
636 : /* The address before run-time alignment, or NULL_RTX if the slot does not
637 : need run-time alignment. */
638 : rtx base_addr;
639 : };
640 :
641 : /* Entry for the below hash table. */
642 : struct GTY((for_user)) temp_slot_address_entry {
643 : hashval_t hash;
644 : rtx address;
645 : class temp_slot *temp_slot;
646 : };
647 :
648 : struct temp_address_hasher : ggc_ptr_hash<temp_slot_address_entry>
649 : {
650 : static hashval_t hash (temp_slot_address_entry *);
651 : static bool equal (temp_slot_address_entry *, temp_slot_address_entry *);
652 : };
653 :
654 : /* A table of addresses that represent a stack slot. The table is a mapping
655 : from address RTXen to a temp slot. */
656 : static GTY(()) hash_table<temp_address_hasher> *temp_slot_address_table;
657 : static size_t n_temp_slots_in_use;
658 :
659 : /* Removes temporary slot TEMP from LIST. */
660 :
661 : static void
662 208778 : cut_slot_from_list (class temp_slot *temp, class temp_slot **list)
663 : {
664 0 : if (temp->next)
665 25662 : temp->next->prev = temp->prev;
666 208778 : if (temp->prev)
667 7267 : temp->prev->next = temp->next;
668 : else
669 201511 : *list = temp->next;
670 :
671 208778 : temp->prev = temp->next = NULL;
672 0 : }
673 :
674 : /* Inserts temporary slot TEMP to LIST. */
675 :
676 : static void
677 287332 : insert_slot_to_list (class temp_slot *temp, class temp_slot **list)
678 : {
679 287332 : temp->next = *list;
680 0 : if (*list)
681 74201 : (*list)->prev = temp;
682 287332 : temp->prev = NULL;
683 287332 : *list = temp;
684 0 : }
685 :
686 : /* Returns the list of used temp slots at LEVEL. */
687 :
688 : static class temp_slot **
689 68851405 : temp_slots_at_level (int level)
690 : {
691 136240305 : if (level >= (int) vec_safe_length (used_temp_slots))
692 1968488 : vec_safe_grow_cleared (used_temp_slots, level + 1, true);
693 :
694 68851405 : return &(*used_temp_slots)[level];
695 : }
696 :
697 : /* Returns the maximal temporary slot level. */
698 :
699 : static int
700 1408076 : max_slot_level (void)
701 : {
702 0 : if (!used_temp_slots)
703 : return -1;
704 :
705 1347929 : return used_temp_slots->length () - 1;
706 : }
707 :
708 : /* Moves temporary slot TEMP to LEVEL. */
709 :
710 : static void
711 1228 : move_slot_to_level (class temp_slot *temp, int level)
712 : {
713 1228 : cut_slot_from_list (temp, temp_slots_at_level (temp->level));
714 1228 : insert_slot_to_list (temp, temp_slots_at_level (level));
715 1228 : temp->level = level;
716 1228 : }
717 :
718 : /* Make temporary slot TEMP available. */
719 :
720 : static void
721 142812 : make_slot_available (class temp_slot *temp)
722 : {
723 142812 : cut_slot_from_list (temp, temp_slots_at_level (temp->level));
724 142812 : insert_slot_to_list (temp, &avail_temp_slots);
725 142812 : temp->in_use = false;
726 142812 : temp->level = -1;
727 142812 : n_temp_slots_in_use--;
728 142812 : }
729 :
730 : /* Compute the hash value for an address -> temp slot mapping.
731 : The value is cached on the mapping entry. */
732 : static hashval_t
733 8453291 : temp_slot_address_compute_hash (struct temp_slot_address_entry *t)
734 : {
735 8453291 : int do_not_record = 0;
736 8453291 : return hash_rtx (t->address, GET_MODE (t->address),
737 8453291 : &do_not_record, NULL, false);
738 : }
739 :
740 : /* Return the hash value for an address -> temp slot mapping. */
741 : hashval_t
742 30315 : temp_address_hasher::hash (temp_slot_address_entry *t)
743 : {
744 30315 : return t->hash;
745 : }
746 :
747 : /* Compare two address -> temp slot mapping entries. */
748 : bool
749 30680 : temp_address_hasher::equal (temp_slot_address_entry *t1,
750 : temp_slot_address_entry *t2)
751 : {
752 30680 : return exp_equiv_p (t1->address, t2->address, 0, true);
753 : }
754 :
755 : /* Add ADDRESS as an alias of TEMP_SLOT to the address -> temp slot mapping. */
756 : static void
757 142866 : insert_temp_slot_address (rtx address, class temp_slot *temp_slot)
758 : {
759 142866 : struct temp_slot_address_entry *t = ggc_alloc<temp_slot_address_entry> ();
760 142866 : t->address = copy_rtx (address);
761 142866 : t->temp_slot = temp_slot;
762 142866 : t->hash = temp_slot_address_compute_hash (t);
763 142866 : *temp_slot_address_table->find_slot_with_hash (t, t->hash, INSERT) = t;
764 142866 : }
765 :
766 : /* Remove an address -> temp slot mapping entry if the temp slot is
767 : not in use anymore. Callback for remove_unused_temp_slot_addresses. */
768 : int
769 898 : remove_unused_temp_slot_addresses_1 (temp_slot_address_entry **slot, void *)
770 : {
771 898 : const struct temp_slot_address_entry *t = *slot;
772 898 : if (! t->temp_slot->in_use)
773 526 : temp_slot_address_table->clear_slot (slot);
774 898 : return 1;
775 : }
776 :
777 : /* Remove all mappings of addresses to unused temp slots. */
778 : static void
779 135340 : remove_unused_temp_slot_addresses (void)
780 : {
781 : /* Use quicker clearing if there aren't any active temp slots. */
782 135340 : if (n_temp_slots_in_use)
783 356 : temp_slot_address_table->traverse
784 1254 : <void *, remove_unused_temp_slot_addresses_1> (NULL);
785 : else
786 134984 : temp_slot_address_table->empty ();
787 135340 : }
788 :
789 : /* Find the temp slot corresponding to the object at address X. */
790 :
791 : static class temp_slot *
792 8310425 : find_temp_slot_from_address (rtx x)
793 : {
794 8310425 : class temp_slot *p;
795 8310425 : struct temp_slot_address_entry tmp, *t;
796 :
797 : /* First try the easy way:
798 : See if X exists in the address -> temp slot mapping. */
799 8310425 : tmp.address = x;
800 8310425 : tmp.temp_slot = NULL;
801 8310425 : tmp.hash = temp_slot_address_compute_hash (&tmp);
802 8310425 : t = temp_slot_address_table->find_with_hash (&tmp, tmp.hash);
803 8310425 : if (t)
804 1260 : return t->temp_slot;
805 :
806 : /* If we have a sum involving a register, see if it points to a temp
807 : slot. */
808 1348068 : if (GET_CODE (x) == PLUS && REG_P (XEXP (x, 0))
809 9360313 : && (p = find_temp_slot_from_address (XEXP (x, 0))) != 0)
810 : return p;
811 1348068 : else if (GET_CODE (x) == PLUS && REG_P (XEXP (x, 1))
812 8505995 : && (p = find_temp_slot_from_address (XEXP (x, 1))) != 0)
813 : return p;
814 :
815 : /* Last resort: Address is a virtual stack var address. */
816 8309165 : poly_int64 offset;
817 8309165 : if (strip_offset (x, &offset) == virtual_stack_vars_rtx)
818 : {
819 1408076 : int i;
820 6154379 : for (i = max_slot_level (); i >= 0; i--)
821 3399862 : for (p = *temp_slots_at_level (i); p; p = p->next)
822 2976 : if (known_in_range_p (offset, p->base_offset, p->full_size))
823 : return p;
824 : }
825 :
826 : return NULL;
827 : }
828 :
829 : /* Allocate a temporary stack slot and record it for possible later
830 : reuse.
831 :
832 : MODE is the machine mode to be given to the returned rtx.
833 :
834 : SIZE is the size in units of the space required. We do no rounding here
835 : since assign_stack_local will do any required rounding.
836 :
837 : TYPE is the type that will be used for the stack slot. */
838 :
839 : rtx
840 142828 : assign_stack_temp_for_type (machine_mode mode, poly_int64 size, tree type)
841 : {
842 142828 : unsigned int align;
843 142828 : class temp_slot *p, *best_p = 0, *selected = NULL, **pp;
844 142828 : rtx slot;
845 :
846 142828 : gcc_assert (known_size_p (size));
847 :
848 142828 : align = get_stack_local_alignment (type, mode);
849 :
850 142828 : unsigned int required_align
851 142828 : = (mode == BLKmode ? BITS_PER_UNIT : GET_MODE_ALIGNMENT (mode));
852 142828 : if (type)
853 98917 : required_align = MAX (required_align, TYPE_ALIGN (type));
854 :
855 285656 : bool dynamic_align = required_align > MAX_SUPPORTED_STACK_ALIGNMENT;
856 :
857 142828 : if (dynamic_align)
858 : align = required_align;
859 : else
860 142828 : align = MAX (required_align, MIN (align, MAX_SUPPORTED_STACK_ALIGNMENT));
861 :
862 : /* Try to find an available, already-allocated temporary of the proper
863 : mode which meets the size and alignment requirements. Choose the
864 : smallest one with the closest alignment.
865 :
866 : If assign_stack_temp is called outside of the tree->rtl expansion,
867 : we cannot reuse the stack slots (that may still refer to
868 : VIRTUAL_STACK_VARS_REGNUM). */
869 142828 : if (!virtuals_instantiated)
870 : {
871 11033249 : for (p = avail_temp_slots; p; p = p->next)
872 : {
873 10941068 : if (p->align >= align
874 10383171 : && known_ge (p->size, size)
875 10366572 : && GET_MODE (p->slot) == mode
876 10234058 : && objects_must_conflict_p (p->type, type)
877 11005472 : && (best_p == 0
878 234 : || (known_eq (best_p->size, p->size)
879 120 : ? best_p->align > p->align
880 114 : : known_ge (best_p->size, p->size))))
881 : {
882 64252 : if (p->align == align && known_eq (p->size, size))
883 : {
884 50647 : selected = p;
885 50647 : cut_slot_from_list (selected, &avail_temp_slots);
886 50647 : best_p = 0;
887 50647 : break;
888 : }
889 : best_p = p;
890 : }
891 : }
892 : }
893 :
894 : /* Make our best, if any, the one to use. */
895 142828 : if (best_p)
896 : {
897 13523 : selected = best_p;
898 13523 : cut_slot_from_list (selected, &avail_temp_slots);
899 :
900 : /* If there are enough aligned bytes left over, make them into a new
901 : temp_slot so that the extra bytes don't get wasted. Do this only
902 : for BLKmode slots, so that we can be sure of the alignment. */
903 13523 : if (GET_MODE (best_p->slot) == BLKmode
904 11201 : && best_p->align <= MAX_SUPPORTED_STACK_ALIGNMENT)
905 : {
906 11201 : int alignment = best_p->align / BITS_PER_UNIT;
907 11201 : poly_int64 rounded_size = aligned_upper_bound (size, alignment);
908 :
909 11201 : if (known_ge (best_p->size - rounded_size, alignment))
910 : {
911 464 : p = ggc_alloc<temp_slot> ();
912 464 : p->base_addr = NULL_RTX;
913 464 : p->in_use = false;
914 464 : p->size = best_p->size - rounded_size;
915 464 : p->base_offset = best_p->base_offset + rounded_size;
916 464 : p->full_size = best_p->full_size - rounded_size;
917 464 : p->slot = adjust_address_nv (best_p->slot, BLKmode, rounded_size);
918 464 : p->align = best_p->align;
919 464 : p->type = best_p->type;
920 464 : insert_slot_to_list (p, &avail_temp_slots);
921 :
922 464 : vec_safe_push (stack_slot_list, p->slot);
923 :
924 464 : best_p->size = rounded_size;
925 464 : best_p->full_size = rounded_size;
926 : }
927 : }
928 : }
929 :
930 283334 : bool reused_p = selected != 0;
931 :
932 : /* If we still didn't find one, make a new temporary. */
933 140506 : if (selected == 0)
934 : {
935 78658 : poly_int64 frame_offset_old = frame_offset;
936 :
937 78658 : p = ggc_alloc<temp_slot> ();
938 78658 : p->base_addr = NULL_RTX;
939 :
940 78658 : poly_int64 slot_size
941 : = (mode == BLKmode
942 78658 : ? aligned_upper_bound (size, (int) align / BITS_PER_UNIT)
943 : : size);
944 :
945 : /* We are passing an explicit alignment request to assign_stack_local.
946 : One side effect of that is assign_stack_local will not round SIZE
947 : to ensure the frame offset remains suitably aligned.
948 :
949 : So for requests which depended on the rounding of SIZE, we go ahead
950 : and round it now. We also make sure ALIGNMENT is at least
951 : BIGGEST_ALIGNMENT. */
952 88737 : gcc_assert (mode != BLKmode
953 : || dynamic_align
954 : || (align
955 : >= MIN (BIGGEST_ALIGNMENT,
956 : MAX_SUPPORTED_STACK_ALIGNMENT)));
957 :
958 78658 : rtx base_addr;
959 78658 : p->slot = assign_stack_local_2 (mode, slot_size, align, 0, &base_addr);
960 78658 : p->base_addr = base_addr;
961 :
962 78658 : p->align = align;
963 :
964 : /* The following slot size computation is necessary because we don't
965 : know the actual size of the temporary slot until assign_stack_local
966 : has performed all the frame alignment and size rounding for the
967 : requested temporary. Note that extra space added for alignment
968 : can be either above or below this stack slot depending on which
969 : way the frame grows. We include the extra space if and only if it
970 : is above this slot. */
971 78658 : if (dynamic_align)
972 0 : p->size = slot_size;
973 : else if (FRAME_GROWS_DOWNWARD)
974 78658 : p->size = frame_offset_old - frame_offset;
975 : else
976 : p->size = size;
977 :
978 : /* Now define the fields used by combine_temp_slots. */
979 78658 : if (FRAME_GROWS_DOWNWARD)
980 : {
981 78658 : p->base_offset = frame_offset;
982 78658 : p->full_size = frame_offset_old - frame_offset;
983 : }
984 : else
985 : {
986 : p->base_offset = frame_offset_old;
987 : p->full_size = frame_offset - frame_offset_old;
988 : }
989 :
990 78658 : selected = p;
991 : }
992 :
993 142828 : p = selected;
994 142828 : p->in_use = true;
995 142828 : p->type = type;
996 142828 : p->level = temp_slot_level;
997 142828 : n_temp_slots_in_use++;
998 :
999 142828 : pp = temp_slots_at_level (p->level);
1000 142828 : insert_slot_to_list (p, pp);
1001 :
1002 142828 : rtx addr = XEXP (p->slot, 0);
1003 :
1004 142828 : if (reused_p && p->align > MAX_SUPPORTED_STACK_ALIGNMENT)
1005 : {
1006 0 : addr = align_dynamic_address (p->base_addr, p->align);
1007 0 : mark_reg_pointer (addr, p->align);
1008 : }
1009 :
1010 142828 : insert_temp_slot_address (addr, p);
1011 :
1012 : /* Create a new MEM rtx to avoid clobbering MEM flags of old slots. */
1013 142828 : slot = gen_rtx_MEM (mode, addr);
1014 142828 : vec_safe_push (stack_slot_list, slot);
1015 :
1016 : /* If we know the alias set for the memory that will be used, use
1017 : it. If there's no TYPE, then we don't know anything about the
1018 : alias set for the memory. */
1019 142828 : set_mem_alias_set (slot, type ? get_alias_set (type) : 0);
1020 142828 : set_mem_align (slot, align);
1021 :
1022 : /* If a type is specified, set the relevant flags. */
1023 142828 : if (type != 0)
1024 98917 : MEM_VOLATILE_P (slot) = TYPE_VOLATILE (type);
1025 142828 : MEM_NOTRAP_P (slot) = 1;
1026 :
1027 142828 : return slot;
1028 : }
1029 :
1030 : /* Allocate a temporary stack slot and record it for possible later
1031 : reuse. First two arguments are same as in preceding function. */
1032 :
1033 : rtx
1034 43911 : assign_stack_temp (machine_mode mode, poly_int64 size)
1035 : {
1036 43911 : return assign_stack_temp_for_type (mode, size, NULL_TREE);
1037 : }
1038 :
1039 : /* Assign a temporary.
1040 : If TYPE_OR_DECL is a decl, then we are doing it on behalf of the decl
1041 : and so that should be used in error messages. In either case, we
1042 : allocate of the given type.
1043 : MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
1044 : it is 0 if a register is OK.
1045 : DONT_PROMOTE is 1 if we should not promote values in register
1046 : to wider modes. */
1047 :
1048 : rtx
1049 1036800 : assign_temp (tree type_or_decl, int memory_required,
1050 : int dont_promote ATTRIBUTE_UNUSED)
1051 : {
1052 1036800 : tree type, decl;
1053 1036800 : machine_mode mode;
1054 : #ifdef PROMOTE_MODE
1055 1036800 : int unsignedp;
1056 : #endif
1057 :
1058 1036800 : if (DECL_P (type_or_decl))
1059 0 : decl = type_or_decl, type = TREE_TYPE (decl);
1060 : else
1061 : decl = NULL, type = type_or_decl;
1062 :
1063 1036800 : mode = TYPE_MODE (type);
1064 : #ifdef PROMOTE_MODE
1065 1036800 : unsignedp = TYPE_UNSIGNED (type);
1066 : #endif
1067 :
1068 : /* Allocating temporaries of TREE_ADDRESSABLE type must be done in the front
1069 : end. See also create_tmp_var for the gimplification-time check. */
1070 1036800 : gcc_assert (!TREE_ADDRESSABLE (type) && COMPLETE_TYPE_P (type));
1071 :
1072 1036800 : if (mode == BLKmode || memory_required)
1073 : {
1074 93277 : poly_int64 size;
1075 93277 : rtx tmp;
1076 :
1077 : /* Unfortunately, we don't yet know how to allocate variable-sized
1078 : temporaries. However, sometimes we can find a fixed upper limit on
1079 : the size, so try that instead. */
1080 93277 : if (!poly_int_tree_p (TYPE_SIZE_UNIT (type), &size))
1081 0 : size = max_int_size_in_bytes (type);
1082 :
1083 : /* Zero sized arrays are a GNU C extension. Set size to 1 to avoid
1084 : problems with allocating the stack space. */
1085 93277 : if (known_eq (size, 0))
1086 0 : size = 1;
1087 :
1088 : /* The size of the temporary may be too large to fit into an integer. */
1089 : /* ??? Not sure this should happen except for user silliness, so limit
1090 : this to things that aren't compiler-generated temporaries. The
1091 : rest of the time we'll die in assign_stack_temp_for_type. */
1092 93277 : if (decl
1093 0 : && !known_size_p (size)
1094 93277 : && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST)
1095 : {
1096 0 : error ("size of variable %q+D is too large", decl);
1097 0 : size = 1;
1098 : }
1099 :
1100 93277 : tmp = assign_stack_temp_for_type (mode, size, type);
1101 93277 : return tmp;
1102 : }
1103 :
1104 : #ifdef PROMOTE_MODE
1105 943523 : if (! dont_promote)
1106 0 : mode = promote_mode (type, mode, &unsignedp);
1107 : #endif
1108 :
1109 943523 : return gen_reg_rtx (mode);
1110 : }
1111 :
1112 : /* Combine temporary stack slots which are adjacent on the stack.
1113 :
1114 : This allows for better use of already allocated stack space. This is only
1115 : done for BLKmode slots because we can be sure that we won't have alignment
1116 : problems in this case. */
1117 :
1118 : static void
1119 135340 : combine_temp_slots (void)
1120 : {
1121 135340 : class temp_slot *p, *q, *next, *next_q;
1122 135340 : int num_slots;
1123 :
1124 : /* We can't combine slots, because the information about which slot
1125 : is in which alias set will be lost. */
1126 135340 : if (flag_strict_aliasing)
1127 : return;
1128 :
1129 : /* If there are a lot of temp slots, don't do anything unless
1130 : high levels of optimization. */
1131 93596 : if (! flag_expensive_optimizations)
1132 423986 : for (p = avail_temp_slots, num_slots = 0; p; p = p->next, num_slots++)
1133 415286 : if (num_slots > 100 || (num_slots > 10 && optimize == 0))
1134 : return;
1135 :
1136 246223 : for (p = avail_temp_slots; p; p = next)
1137 : {
1138 165055 : int delete_p = 0;
1139 :
1140 165055 : next = p->next;
1141 :
1142 165055 : if (GET_MODE (p->slot) != BLKmode
1143 23657 : || p->align > MAX_SUPPORTED_STACK_ALIGNMENT)
1144 141398 : continue;
1145 :
1146 28327 : for (q = p->next; q; q = next_q)
1147 : {
1148 4681 : int delete_q = 0;
1149 :
1150 4681 : next_q = q->next;
1151 :
1152 4681 : if (GET_MODE (q->slot) != BLKmode
1153 631 : || q->align > MAX_SUPPORTED_STACK_ALIGNMENT)
1154 4050 : continue;
1155 :
1156 631 : if (known_eq (p->base_offset + p->full_size, q->base_offset))
1157 : {
1158 : /* Q comes after P; combine Q into P. */
1159 557 : p->size += q->size;
1160 4670 : p->full_size += q->full_size;
1161 : delete_q = 1;
1162 : }
1163 74 : else if (known_eq (q->base_offset + q->full_size, p->base_offset))
1164 : {
1165 : /* P comes after Q; combine P into Q. */
1166 11 : q->size += p->size;
1167 11 : q->full_size += p->full_size;
1168 : delete_p = 1;
1169 : break;
1170 : }
1171 557 : if (delete_q)
1172 1114 : cut_slot_from_list (q, &avail_temp_slots);
1173 : }
1174 :
1175 : /* Either delete P or advance past it. */
1176 23657 : if (delete_p)
1177 22 : cut_slot_from_list (p, &avail_temp_slots);
1178 : }
1179 : }
1180 :
1181 : /* Indicate that NEW_RTX is an alternate way of referring to the temp
1182 : slot that previously was known by OLD_RTX. */
1183 :
1184 : void
1185 16652253 : update_temp_slot_address (rtx old_rtx, rtx new_rtx)
1186 : {
1187 17268058 : class temp_slot *p;
1188 :
1189 17268058 : if (rtx_equal_p (old_rtx, new_rtx))
1190 : return;
1191 :
1192 4533245 : p = find_temp_slot_from_address (old_rtx);
1193 :
1194 : /* If we didn't find one, see if both OLD_RTX is a PLUS. If so, and
1195 : NEW_RTX is a register, see if one operand of the PLUS is a
1196 : temporary location. If so, NEW_RTX points into it. Otherwise,
1197 : if both OLD_RTX and NEW_RTX are a PLUS and if there is a register
1198 : in common between them. If so, try a recursive call on those
1199 : values. */
1200 4533245 : if (p == 0)
1201 : {
1202 4533207 : if (GET_CODE (old_rtx) != PLUS)
1203 : return;
1204 :
1205 696503 : if (REG_P (new_rtx))
1206 : {
1207 227140 : update_temp_slot_address (XEXP (old_rtx, 0), new_rtx);
1208 227140 : update_temp_slot_address (XEXP (old_rtx, 1), new_rtx);
1209 227140 : return;
1210 : }
1211 469363 : else if (GET_CODE (new_rtx) != PLUS)
1212 : return;
1213 :
1214 469363 : if (rtx_equal_p (XEXP (old_rtx, 0), XEXP (new_rtx, 0)))
1215 214743 : update_temp_slot_address (XEXP (old_rtx, 1), XEXP (new_rtx, 1));
1216 254620 : else if (rtx_equal_p (XEXP (old_rtx, 1), XEXP (new_rtx, 0)))
1217 0 : update_temp_slot_address (XEXP (old_rtx, 0), XEXP (new_rtx, 1));
1218 254620 : else if (rtx_equal_p (XEXP (old_rtx, 0), XEXP (new_rtx, 1)))
1219 33301 : update_temp_slot_address (XEXP (old_rtx, 1), XEXP (new_rtx, 0));
1220 221319 : else if (rtx_equal_p (XEXP (old_rtx, 1), XEXP (new_rtx, 1)))
1221 140621 : update_temp_slot_address (XEXP (old_rtx, 0), XEXP (new_rtx, 0));
1222 :
1223 : return;
1224 : }
1225 :
1226 : /* Otherwise add an alias for the temp's address. */
1227 38 : insert_temp_slot_address (new_rtx, p);
1228 : }
1229 :
1230 : /* If X could be a reference to a temporary slot, mark that slot as
1231 : belonging to the to one level higher than the current level. If X
1232 : matched one of our slots, just mark that one. Otherwise, we can't
1233 : easily predict which it is, so upgrade all of them.
1234 :
1235 : This is called when an ({...}) construct occurs and a statement
1236 : returns a value in memory. */
1237 :
1238 : void
1239 24924040 : preserve_temp_slots (rtx x)
1240 : {
1241 24924040 : class temp_slot *p = 0, *next;
1242 :
1243 24924040 : if (x == 0)
1244 : return;
1245 :
1246 : /* If X is a register that is being used as a pointer, see if we have
1247 : a temporary slot we know it points to. */
1248 11201042 : if (REG_P (x) && REG_POINTER (x))
1249 1818073 : p = find_temp_slot_from_address (x);
1250 :
1251 : /* If X is not in memory or is at a constant address, it cannot be in
1252 : a temporary slot. */
1253 11201042 : if (p == 0 && (!MEM_P (x) || CONSTANT_P (XEXP (x, 0))))
1254 : return;
1255 :
1256 : /* First see if we can find a match. */
1257 711129 : if (p == 0)
1258 711129 : p = find_temp_slot_from_address (XEXP (x, 0));
1259 :
1260 711129 : if (p != 0)
1261 : {
1262 1222 : if (p->level == temp_slot_level)
1263 1222 : move_slot_to_level (p, temp_slot_level - 1);
1264 : return;
1265 : }
1266 :
1267 : /* Otherwise, preserve all non-kept slots at this level. */
1268 709913 : for (p = *temp_slots_at_level (temp_slot_level); p; p = next)
1269 : {
1270 6 : next = p->next;
1271 6 : move_slot_to_level (p, temp_slot_level - 1);
1272 : }
1273 : }
1274 :
1275 : /* Free all temporaries used so far. This is normally called at the
1276 : end of generating code for a statement. */
1277 :
1278 : void
1279 64455028 : free_temp_slots (void)
1280 : {
1281 64455028 : class temp_slot *p, *next;
1282 64455028 : bool some_available = false;
1283 :
1284 64597840 : for (p = *temp_slots_at_level (temp_slot_level); p; p = next)
1285 : {
1286 142812 : next = p->next;
1287 142812 : make_slot_available (p);
1288 142812 : some_available = true;
1289 : }
1290 :
1291 64455028 : if (some_available)
1292 : {
1293 135340 : remove_unused_temp_slot_addresses ();
1294 135340 : combine_temp_slots ();
1295 : }
1296 64455028 : }
1297 :
1298 : /* Push deeper into the nesting level for stack temporaries. */
1299 :
1300 : void
1301 31503289 : push_temp_slots (void)
1302 : {
1303 31503289 : temp_slot_level++;
1304 31503289 : }
1305 :
1306 : /* Pop a temporary nesting level. All slots in use in the current level
1307 : are freed. */
1308 :
1309 : void
1310 31503285 : pop_temp_slots (void)
1311 : {
1312 31503285 : free_temp_slots ();
1313 31503285 : temp_slot_level--;
1314 31503285 : }
1315 :
1316 : /* Initialize temporary slots. */
1317 :
1318 : void
1319 3295838 : init_temp_slots (void)
1320 : {
1321 : /* We have not allocated any temporaries yet. */
1322 3295838 : avail_temp_slots = 0;
1323 3295838 : vec_alloc (used_temp_slots, 0);
1324 3295838 : temp_slot_level = 0;
1325 3295838 : n_temp_slots_in_use = 0;
1326 :
1327 : /* Set up the table to map addresses to temp slots. */
1328 3295838 : if (! temp_slot_address_table)
1329 221764 : temp_slot_address_table = hash_table<temp_address_hasher>::create_ggc (32);
1330 : else
1331 3074074 : temp_slot_address_table->empty ();
1332 3295838 : }
1333 :
1334 : /* Functions and data structures to keep track of the values hard regs
1335 : had at the start of the function. */
1336 :
1337 : /* Private type used by get_hard_reg_initial_reg, get_hard_reg_initial_val,
1338 : and has_hard_reg_initial_val.. */
1339 : struct GTY(()) initial_value_pair {
1340 : rtx hard_reg;
1341 : rtx pseudo;
1342 : };
1343 : /* ??? This could be a VEC but there is currently no way to define an
1344 : opaque VEC type. This could be worked around by defining struct
1345 : initial_value_pair in function.h. */
1346 : struct GTY(()) initial_value_struct {
1347 : int num_entries;
1348 : int max_entries;
1349 : initial_value_pair * GTY ((length ("%h.num_entries"))) entries;
1350 : };
1351 :
1352 : /* If a pseudo represents an initial hard reg (or expression), return
1353 : it, else return NULL_RTX. */
1354 :
1355 : rtx
1356 0 : get_hard_reg_initial_reg (rtx reg)
1357 : {
1358 0 : struct initial_value_struct *ivs = crtl->hard_reg_initial_vals;
1359 0 : int i;
1360 :
1361 0 : if (ivs == 0)
1362 : return NULL_RTX;
1363 :
1364 0 : for (i = 0; i < ivs->num_entries; i++)
1365 0 : if (rtx_equal_p (ivs->entries[i].pseudo, reg))
1366 0 : return ivs->entries[i].hard_reg;
1367 :
1368 : return NULL_RTX;
1369 : }
1370 :
1371 : /* Make sure that there's a pseudo register of mode MODE that stores the
1372 : initial value of hard register REGNO. Return an rtx for such a pseudo. */
1373 :
1374 : rtx
1375 0 : get_hard_reg_initial_val (machine_mode mode, unsigned int regno)
1376 : {
1377 0 : struct initial_value_struct *ivs;
1378 0 : rtx rv;
1379 :
1380 0 : rv = has_hard_reg_initial_val (mode, regno);
1381 0 : if (rv)
1382 : return rv;
1383 :
1384 0 : ivs = crtl->hard_reg_initial_vals;
1385 0 : if (ivs == 0)
1386 : {
1387 0 : ivs = ggc_alloc<initial_value_struct> ();
1388 0 : ivs->num_entries = 0;
1389 0 : ivs->max_entries = 5;
1390 0 : ivs->entries = ggc_vec_alloc<initial_value_pair> (5);
1391 0 : crtl->hard_reg_initial_vals = ivs;
1392 : }
1393 :
1394 0 : if (ivs->num_entries >= ivs->max_entries)
1395 : {
1396 0 : ivs->max_entries += 5;
1397 0 : ivs->entries = GGC_RESIZEVEC (initial_value_pair, ivs->entries,
1398 : ivs->max_entries);
1399 : }
1400 :
1401 0 : ivs->entries[ivs->num_entries].hard_reg = gen_rtx_REG (mode, regno);
1402 0 : ivs->entries[ivs->num_entries].pseudo = gen_reg_rtx (mode);
1403 :
1404 0 : return ivs->entries[ivs->num_entries++].pseudo;
1405 : }
1406 :
1407 : /* See if get_hard_reg_initial_val has been used to create a pseudo
1408 : for the initial value of hard register REGNO in mode MODE. Return
1409 : the associated pseudo if so, otherwise return NULL. */
1410 :
1411 : rtx
1412 0 : has_hard_reg_initial_val (machine_mode mode, unsigned int regno)
1413 : {
1414 0 : struct initial_value_struct *ivs;
1415 0 : int i;
1416 :
1417 0 : ivs = crtl->hard_reg_initial_vals;
1418 0 : if (ivs != 0)
1419 0 : for (i = 0; i < ivs->num_entries; i++)
1420 0 : if (GET_MODE (ivs->entries[i].hard_reg) == mode
1421 0 : && REGNO (ivs->entries[i].hard_reg) == regno)
1422 0 : return ivs->entries[i].pseudo;
1423 :
1424 : return NULL_RTX;
1425 : }
1426 :
1427 : void
1428 1531888 : emit_initial_value_sets (void)
1429 : {
1430 1531888 : struct initial_value_struct *ivs = crtl->hard_reg_initial_vals;
1431 1531888 : int i;
1432 1531888 : rtx_insn *seq;
1433 :
1434 1531888 : if (ivs == 0)
1435 : return;
1436 :
1437 0 : start_sequence ();
1438 0 : for (i = 0; i < ivs->num_entries; i++)
1439 0 : emit_move_insn (ivs->entries[i].pseudo, ivs->entries[i].hard_reg);
1440 0 : seq = end_sequence ();
1441 :
1442 0 : emit_insn_at_entry (seq);
1443 : }
1444 :
1445 : /* Return the hardreg-pseudoreg initial values pair entry I and
1446 : TRUE if I is a valid entry, or FALSE if I is not a valid entry. */
1447 : bool
1448 0 : initial_value_entry (int i, rtx *hreg, rtx *preg)
1449 : {
1450 0 : struct initial_value_struct *ivs = crtl->hard_reg_initial_vals;
1451 0 : if (!ivs || i >= ivs->num_entries)
1452 : return false;
1453 :
1454 0 : *hreg = ivs->entries[i].hard_reg;
1455 0 : *preg = ivs->entries[i].pseudo;
1456 0 : return true;
1457 : }
1458 :
1459 : /* These routines are responsible for converting virtual register references
1460 : to the actual hard register references once RTL generation is complete.
1461 :
1462 : The following four variables are used for communication between the
1463 : routines. They contain the offsets of the virtual registers from their
1464 : respective hard registers. */
1465 :
1466 : static poly_int64 in_arg_offset;
1467 : static poly_int64 var_offset;
1468 : static poly_int64 dynamic_offset;
1469 : static poly_int64 out_arg_offset;
1470 : static poly_int64 cfa_offset;
1471 :
1472 : /* In most machines, the stack pointer register is equivalent to the bottom
1473 : of the stack. */
1474 :
1475 : #ifndef STACK_POINTER_OFFSET
1476 : #define STACK_POINTER_OFFSET 0
1477 : #endif
1478 :
1479 : #if defined (REG_PARM_STACK_SPACE) && !defined (INCOMING_REG_PARM_STACK_SPACE)
1480 : #define INCOMING_REG_PARM_STACK_SPACE REG_PARM_STACK_SPACE
1481 : #endif
1482 :
1483 : /* If not defined, pick an appropriate default for the offset of dynamically
1484 : allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
1485 : INCOMING_REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
1486 :
1487 : #ifndef STACK_DYNAMIC_OFFSET
1488 :
1489 : /* The bottom of the stack points to the actual arguments. If
1490 : REG_PARM_STACK_SPACE is defined, this includes the space for the register
1491 : parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
1492 : stack space for register parameters is not pushed by the caller, but
1493 : rather part of the fixed stack areas and hence not included in
1494 : `crtl->outgoing_args_size'. Nevertheless, we must allow
1495 : for it when allocating stack dynamic objects. */
1496 :
1497 : #ifdef INCOMING_REG_PARM_STACK_SPACE
1498 : #define STACK_DYNAMIC_OFFSET(FNDECL) \
1499 : ((ACCUMULATE_OUTGOING_ARGS \
1500 : ? (crtl->outgoing_args_size \
1501 : + (OUTGOING_REG_PARM_STACK_SPACE ((!(FNDECL) ? NULL_TREE : TREE_TYPE (FNDECL))) ? 0 \
1502 : : INCOMING_REG_PARM_STACK_SPACE (FNDECL))) \
1503 : : 0) + (STACK_POINTER_OFFSET))
1504 : #else
1505 : #define STACK_DYNAMIC_OFFSET(FNDECL) \
1506 : ((ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : poly_int64 (0)) \
1507 : + (STACK_POINTER_OFFSET))
1508 : #endif
1509 : #endif
1510 :
1511 :
1512 : /* Given a piece of RTX and a pointer to a HOST_WIDE_INT, if the RTX
1513 : is a virtual register, return the equivalent hard register and set the
1514 : offset indirectly through the pointer. Otherwise, return 0. */
1515 :
1516 : static rtx
1517 377573891 : instantiate_new_reg (rtx x, poly_int64 *poffset)
1518 : {
1519 377573891 : rtx new_rtx;
1520 377573891 : poly_int64 offset;
1521 :
1522 377573891 : if (x == virtual_incoming_args_rtx)
1523 : {
1524 3768587 : if (stack_realign_drap)
1525 : {
1526 : /* Replace virtual_incoming_args_rtx with internal arg
1527 : pointer if DRAP is used to realign stack. */
1528 16472 : new_rtx = crtl->args.internal_arg_pointer;
1529 16472 : offset = 0;
1530 : }
1531 : else
1532 3752115 : new_rtx = arg_pointer_rtx, offset = in_arg_offset;
1533 : }
1534 373805304 : else if (x == virtual_stack_vars_rtx)
1535 19058842 : new_rtx = frame_pointer_rtx, offset = var_offset;
1536 354746462 : else if (x == virtual_stack_dynamic_rtx)
1537 53699 : new_rtx = stack_pointer_rtx, offset = dynamic_offset;
1538 354692763 : else if (x == virtual_outgoing_args_rtx)
1539 1576200 : new_rtx = stack_pointer_rtx, offset = out_arg_offset;
1540 353116563 : else if (x == virtual_cfa_rtx)
1541 : {
1542 1974 : offset = cfa_offset;
1543 : #ifdef FRAME_POINTER_CFA_OFFSET
1544 : new_rtx = frame_pointer_rtx;
1545 : #else
1546 1974 : if (stack_realign_drap)
1547 : {
1548 : /* As for virtual_incoming_args_rtx: if DRAP is used to realign
1549 : the stack, the argument pointer is at no fixed offset from SP
1550 : or the hard frame pointer. The DRAP pseudo holds the address
1551 : of the incoming arguments (arg_pointer_rtx + in_arg_offset),
1552 : so the CFA is at cfa_offset - in_arg_offset from it. */
1553 608 : new_rtx = crtl->args.internal_arg_pointer;
1554 608 : offset -= in_arg_offset;
1555 : }
1556 : else
1557 1366 : new_rtx = arg_pointer_rtx;
1558 : #endif
1559 : }
1560 353114589 : else if (x == virtual_preferred_stack_boundary_rtx)
1561 : {
1562 113892 : new_rtx = GEN_INT (crtl->preferred_stack_boundary / BITS_PER_UNIT);
1563 113892 : offset = 0;
1564 : }
1565 : else
1566 : return NULL_RTX;
1567 :
1568 24573194 : *poffset = offset;
1569 24573194 : return new_rtx;
1570 : }
1571 :
1572 : /* A subroutine of instantiate_virtual_regs. Instantiate any virtual
1573 : registers present inside of *LOC. The expression is simplified,
1574 : as much as possible, but is not to be considered "valid" in any sense
1575 : implied by the target. Return true if any change is made. */
1576 :
1577 : static bool
1578 216555060 : instantiate_virtual_regs_in_rtx (rtx *loc)
1579 : {
1580 216555060 : if (!*loc)
1581 : return false;
1582 97635454 : bool changed = false;
1583 97635454 : subrtx_ptr_iterator::array_type array;
1584 362495973 : FOR_EACH_SUBRTX_PTR (iter, array, loc, NONCONST)
1585 : {
1586 264860519 : rtx *loc = *iter;
1587 264860519 : if (rtx x = *loc)
1588 : {
1589 240468496 : rtx new_rtx;
1590 240468496 : poly_int64 offset;
1591 240468496 : switch (GET_CODE (x))
1592 : {
1593 36009353 : case REG:
1594 36009353 : new_rtx = instantiate_new_reg (x, &offset);
1595 36009353 : if (new_rtx)
1596 : {
1597 1675765 : *loc = plus_constant (GET_MODE (x), new_rtx, offset);
1598 1675765 : changed = true;
1599 : }
1600 36009353 : iter.skip_subrtxes ();
1601 36009353 : break;
1602 :
1603 28870801 : case PLUS:
1604 28870801 : new_rtx = instantiate_new_reg (XEXP (x, 0), &offset);
1605 28870801 : if (new_rtx)
1606 : {
1607 19684870 : XEXP (x, 0) = new_rtx;
1608 19684870 : *loc = plus_constant (GET_MODE (x), x, offset, true);
1609 19684870 : changed = true;
1610 19684870 : iter.skip_subrtxes ();
1611 19684870 : break;
1612 : }
1613 :
1614 : /* FIXME -- from old code */
1615 : /* If we have (plus (subreg (virtual-reg)) (const_int)), we know
1616 : we can commute the PLUS and SUBREG because pointers into the
1617 : frame are well-behaved. */
1618 : break;
1619 :
1620 : default:
1621 : break;
1622 : }
1623 : }
1624 : }
1625 97635454 : return changed;
1626 97635454 : }
1627 :
1628 : /* A subroutine of instantiate_virtual_regs_in_insn. Return true if X
1629 : matches the predicate for insn CODE operand OPERAND. */
1630 :
1631 : static bool
1632 30862047 : safe_insn_predicate (int code, int operand, rtx x)
1633 : {
1634 30862047 : return code < 0 || insn_operand_matches ((enum insn_code) code, operand, x);
1635 : }
1636 :
1637 : /* A subroutine of instantiate_virtual_regs. Instantiate any virtual
1638 : registers present inside of insn. The result will be a valid insn. */
1639 :
1640 : static void
1641 96558894 : instantiate_virtual_regs_in_insn (rtx_insn *insn)
1642 : {
1643 96558894 : poly_int64 offset;
1644 96558894 : int insn_code, i;
1645 96558894 : bool any_change = false;
1646 96558894 : rtx set, new_rtx, x;
1647 96558894 : rtx_insn *seq;
1648 :
1649 : /* There are some special cases to be handled first. */
1650 96558894 : set = single_set (insn);
1651 96558894 : if (set)
1652 : {
1653 : /* We're allowed to assign to a virtual register. This is interpreted
1654 : to mean that the underlying register gets assigned the inverse
1655 : transformation. This is used, for example, in the handling of
1656 : non-local gotos. */
1657 92195069 : new_rtx = instantiate_new_reg (SET_DEST (set), &offset);
1658 92195069 : if (new_rtx)
1659 : {
1660 0 : start_sequence ();
1661 :
1662 0 : instantiate_virtual_regs_in_rtx (&SET_SRC (set));
1663 0 : x = simplify_gen_binary (PLUS, GET_MODE (new_rtx), SET_SRC (set),
1664 0 : gen_int_mode (-offset, GET_MODE (new_rtx)));
1665 0 : x = force_operand (x, new_rtx);
1666 0 : if (x != new_rtx)
1667 0 : emit_move_insn (new_rtx, x);
1668 :
1669 0 : seq = end_sequence ();
1670 :
1671 0 : emit_insn_before (seq, insn);
1672 0 : delete_insn (insn);
1673 18799 : return;
1674 : }
1675 :
1676 : /* Handle a straight copy from a virtual register by generating a
1677 : new add insn. The difference between this and falling through
1678 : to the generic case is avoiding a new pseudo and eliminating a
1679 : move insn in the initial rtl stream. */
1680 92195069 : new_rtx = instantiate_new_reg (SET_SRC (set), &offset);
1681 92195069 : if (new_rtx
1682 323893 : && maybe_ne (offset, 0)
1683 3841 : && REG_P (SET_DEST (set))
1684 92198910 : && REGNO (SET_DEST (set)) > LAST_VIRTUAL_REGISTER)
1685 : {
1686 3841 : start_sequence ();
1687 :
1688 3841 : x = expand_simple_binop (GET_MODE (SET_DEST (set)), PLUS, new_rtx,
1689 : gen_int_mode (offset,
1690 3841 : GET_MODE (SET_DEST (set))),
1691 : SET_DEST (set), 1, OPTAB_LIB_WIDEN);
1692 3841 : if (x != SET_DEST (set))
1693 0 : emit_move_insn (SET_DEST (set), x);
1694 :
1695 3841 : seq = end_sequence ();
1696 :
1697 3841 : emit_insn_before (seq, insn);
1698 3841 : delete_insn (insn);
1699 3841 : return;
1700 : }
1701 :
1702 92191228 : extract_insn (insn);
1703 92191228 : insn_code = INSN_CODE (insn);
1704 :
1705 : /* Handle a plus involving a virtual register by determining if the
1706 : operands remain valid if they're modified in place. */
1707 92191228 : poly_int64 delta;
1708 92191228 : if (GET_CODE (SET_SRC (set)) == PLUS
1709 10399279 : && recog_data.n_operands >= 3
1710 10333597 : && recog_data.operand_loc[1] == &XEXP (SET_SRC (set), 0)
1711 10332969 : && recog_data.operand_loc[2] == &XEXP (SET_SRC (set), 1)
1712 10332969 : && poly_int_rtx_p (recog_data.operand[2], &delta)
1713 100312224 : && (new_rtx = instantiate_new_reg (recog_data.operand[1], &offset)))
1714 : {
1715 2469988 : offset += delta;
1716 :
1717 : /* If the sum is zero, then replace with a plain move. */
1718 2469988 : if (known_eq (offset, 0)
1719 14958 : && REG_P (SET_DEST (set))
1720 2484946 : && REGNO (SET_DEST (set)) > LAST_VIRTUAL_REGISTER)
1721 : {
1722 14958 : start_sequence ();
1723 14958 : emit_move_insn (SET_DEST (set), new_rtx);
1724 14958 : seq = end_sequence ();
1725 :
1726 14958 : emit_insn_before (seq, insn);
1727 14958 : delete_insn (insn);
1728 14958 : return;
1729 : }
1730 :
1731 2455030 : x = gen_int_mode (offset, recog_data.operand_mode[2]);
1732 :
1733 : /* Using validate_change and apply_change_group here leaves
1734 : recog_data in an invalid state. Since we know exactly what
1735 : we want to check, do those two by hand. */
1736 2455030 : if (safe_insn_predicate (insn_code, 1, new_rtx)
1737 2455030 : && safe_insn_predicate (insn_code, 2, x))
1738 : {
1739 2426557 : *recog_data.operand_loc[1] = recog_data.operand[1] = new_rtx;
1740 2426557 : *recog_data.operand_loc[2] = recog_data.operand[2] = x;
1741 2426557 : any_change = true;
1742 :
1743 : /* Fall through into the regular operand fixup loop in
1744 : order to take care of operands other than 1 and 2. */
1745 : }
1746 : }
1747 : }
1748 : else
1749 : {
1750 4363825 : extract_insn (insn);
1751 4363825 : insn_code = INSN_CODE (insn);
1752 : }
1753 :
1754 : /* In the general case, we expect virtual registers to appear only in
1755 : operands, and then only as either bare registers or inside memories. */
1756 305870514 : for (i = 0; i < recog_data.n_operands; ++i)
1757 : {
1758 209330419 : x = recog_data.operand[i];
1759 209330419 : switch (GET_CODE (x))
1760 : {
1761 29957199 : case MEM:
1762 29957199 : {
1763 29957199 : rtx addr = XEXP (x, 0);
1764 :
1765 29957199 : if (!instantiate_virtual_regs_in_rtx (&addr))
1766 17176308 : continue;
1767 :
1768 12780891 : start_sequence ();
1769 12780891 : x = replace_equiv_address (x, addr, true);
1770 : /* It may happen that the address with the virtual reg
1771 : was valid (e.g. based on the virtual stack reg, which might
1772 : be acceptable to the predicates with all offsets), whereas
1773 : the address now isn't anymore, for instance when the address
1774 : is still offsetted, but the base reg isn't virtual-stack-reg
1775 : anymore. Below we would do a force_reg on the whole operand,
1776 : but this insn might actually only accept memory. Hence,
1777 : before doing that last resort, try to reload the address into
1778 : a register, so this operand stays a MEM. */
1779 12780891 : if (!safe_insn_predicate (insn_code, i, x))
1780 : {
1781 0 : addr = force_reg (GET_MODE (addr), addr);
1782 0 : x = replace_equiv_address (x, addr, true);
1783 : }
1784 12780891 : seq = end_sequence ();
1785 12780891 : if (seq)
1786 0 : emit_insn_before (seq, insn);
1787 : }
1788 12780891 : break;
1789 :
1790 117152064 : case REG:
1791 117152064 : new_rtx = instantiate_new_reg (x, &offset);
1792 117152064 : if (new_rtx == NULL)
1793 116733392 : continue;
1794 418672 : if (known_eq (offset, 0))
1795 : x = new_rtx;
1796 : else
1797 : {
1798 0 : start_sequence ();
1799 :
1800 : /* Careful, special mode predicates may have stuff in
1801 : insn_data[insn_code].operand[i].mode that isn't useful
1802 : to us for computing a new value. */
1803 : /* ??? Recognize address_operand and/or "p" constraints
1804 : to see if (plus new offset) is a valid before we put
1805 : this through expand_simple_binop. */
1806 0 : x = expand_simple_binop (GET_MODE (x), PLUS, new_rtx,
1807 0 : gen_int_mode (offset, GET_MODE (x)),
1808 : NULL_RTX, 1, OPTAB_LIB_WIDEN);
1809 0 : seq = end_sequence ();
1810 0 : emit_insn_before (seq, insn);
1811 : }
1812 : break;
1813 :
1814 3030539 : case SUBREG:
1815 3030539 : new_rtx = instantiate_new_reg (SUBREG_REG (x), &offset);
1816 3030539 : if (new_rtx == NULL)
1817 3030533 : continue;
1818 6 : start_sequence ();
1819 6 : if (maybe_ne (offset, 0))
1820 0 : new_rtx = expand_simple_binop
1821 0 : (GET_MODE (new_rtx), PLUS, new_rtx,
1822 0 : gen_int_mode (offset, GET_MODE (new_rtx)),
1823 : NULL_RTX, 1, OPTAB_LIB_WIDEN);
1824 12 : x = force_subreg (recog_data.operand_mode[i], new_rtx,
1825 6 : GET_MODE (new_rtx), SUBREG_BYTE (x));
1826 6 : gcc_assert (x);
1827 6 : seq = end_sequence ();
1828 6 : emit_insn_before (seq, insn);
1829 6 : break;
1830 :
1831 59190617 : default:
1832 59190617 : continue;
1833 59190617 : }
1834 :
1835 : /* At this point, X contains the new value for the operand.
1836 : Validate the new value vs the insn predicate. Note that
1837 : asm insns will have insn_code -1 here. */
1838 13199569 : if (!safe_insn_predicate (insn_code, i, x))
1839 : {
1840 56946 : start_sequence ();
1841 56946 : if (REG_P (x))
1842 : {
1843 0 : gcc_assert (REGNO (x) <= LAST_VIRTUAL_REGISTER);
1844 0 : x = copy_to_reg (x);
1845 : }
1846 : else
1847 56946 : x = force_reg (insn_data[insn_code].operand[i].mode, x);
1848 56946 : seq = end_sequence ();
1849 56946 : if (seq)
1850 56946 : emit_insn_before (seq, insn);
1851 : }
1852 :
1853 13199569 : *recog_data.operand_loc[i] = recog_data.operand[i] = x;
1854 13199569 : any_change = true;
1855 : }
1856 :
1857 96540095 : if (any_change)
1858 : {
1859 : /* Propagate operand changes into the duplicates. */
1860 15535999 : for (i = 0; i < recog_data.n_dups; ++i)
1861 89288 : *recog_data.dup_loc[i]
1862 89288 : = copy_rtx (recog_data.operand[(unsigned)recog_data.dup_num[i]]);
1863 :
1864 : /* Force re-recognition of the instruction for validation. */
1865 15446711 : INSN_CODE (insn) = -1;
1866 : }
1867 :
1868 96540095 : if (asm_noperands (PATTERN (insn)) >= 0)
1869 : {
1870 95012 : if (!check_asm_operands (PATTERN (insn)))
1871 : {
1872 23 : error_for_asm (insn, "impossible constraint in %<asm%>");
1873 : /* For asm goto, instead of fixing up all the edges
1874 : just clear the template and clear input and output operands
1875 : and strip away clobbers. */
1876 23 : if (JUMP_P (insn))
1877 : {
1878 14 : rtx asm_op = extract_asm_operands (PATTERN (insn));
1879 14 : PATTERN (insn) = asm_op;
1880 14 : PUT_MODE (asm_op, VOIDmode);
1881 14 : ASM_OPERANDS_TEMPLATE (asm_op) = ggc_strdup ("");
1882 14 : ASM_OPERANDS_OUTPUT_CONSTRAINT (asm_op) = "";
1883 14 : ASM_OPERANDS_OUTPUT_IDX (asm_op) = 0;
1884 14 : ASM_OPERANDS_INPUT_VEC (asm_op) = rtvec_alloc (0);
1885 14 : ASM_OPERANDS_INPUT_CONSTRAINT_VEC (asm_op) = rtvec_alloc (0);
1886 : }
1887 : else
1888 9 : delete_insn (insn);
1889 : }
1890 : }
1891 : else
1892 : {
1893 96445083 : if (recog_memoized (insn) < 0)
1894 0 : fatal_insn_not_found (insn);
1895 : }
1896 : }
1897 :
1898 : /* Subroutine of instantiate_decls. Given RTL representing a decl,
1899 : do any instantiation required. */
1900 :
1901 : void
1902 9878003 : instantiate_decl_rtl (rtx x)
1903 : {
1904 9883617 : rtx addr;
1905 :
1906 9883617 : if (x == 0)
1907 : return;
1908 :
1909 : /* If this is a CONCAT, recurse for the pieces. */
1910 9883617 : if (GET_CODE (x) == CONCAT)
1911 : {
1912 5614 : instantiate_decl_rtl (XEXP (x, 0));
1913 5614 : instantiate_decl_rtl (XEXP (x, 1));
1914 5614 : return;
1915 : }
1916 :
1917 : /* If this is not a MEM, no need to do anything. Similarly if the
1918 : address is a constant or a register that is not a virtual register. */
1919 9878003 : if (!MEM_P (x))
1920 : return;
1921 :
1922 3314352 : addr = XEXP (x, 0);
1923 3314352 : if (CONSTANT_P (addr)
1924 3314352 : || (REG_P (addr)
1925 306679 : && !VIRTUAL_REGISTER_P (addr)))
1926 : return;
1927 :
1928 3088523 : instantiate_virtual_regs_in_rtx (&XEXP (x, 0));
1929 : }
1930 :
1931 : /* Helper for instantiate_decls called via walk_tree: Process all decls
1932 : in the given DECL_VALUE_EXPR. */
1933 :
1934 : static tree
1935 1603040 : instantiate_expr (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
1936 : {
1937 1603040 : tree t = *tp;
1938 1603040 : if (! EXPR_P (t))
1939 : {
1940 862388 : *walk_subtrees = 0;
1941 862388 : if (DECL_P (t))
1942 : {
1943 719271 : if (DECL_RTL_SET_P (t))
1944 178449 : instantiate_decl_rtl (DECL_RTL (t));
1945 140480 : if (TREE_CODE (t) == PARM_DECL && DECL_NAMELESS (t)
1946 833861 : && DECL_INCOMING_RTL (t))
1947 114590 : instantiate_decl_rtl (DECL_INCOMING_RTL (t));
1948 414698 : if ((VAR_P (t) || TREE_CODE (t) == RESULT_DECL)
1949 726719 : && DECL_HAS_VALUE_EXPR_P (t))
1950 : {
1951 7721 : tree v = DECL_VALUE_EXPR (t);
1952 7721 : walk_tree (&v, instantiate_expr, NULL, NULL);
1953 : }
1954 : }
1955 : }
1956 1603040 : return NULL;
1957 : }
1958 :
1959 : /* Subroutine of instantiate_decls: Process all decls in the given
1960 : BLOCK node and all its subblocks. */
1961 :
1962 : static void
1963 17209521 : instantiate_decls_1 (tree let)
1964 : {
1965 17209521 : tree t;
1966 :
1967 37496801 : for (t = BLOCK_VARS (let); t; t = DECL_CHAIN (t))
1968 : {
1969 20287280 : if (DECL_RTL_SET_P (t))
1970 2366972 : instantiate_decl_rtl (DECL_RTL (t));
1971 20287280 : if (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t))
1972 : {
1973 391925 : tree v = DECL_VALUE_EXPR (t);
1974 391925 : walk_tree (&v, instantiate_expr, NULL, NULL);
1975 : }
1976 : }
1977 :
1978 : /* Process all subblocks. */
1979 32887938 : for (t = BLOCK_SUBBLOCKS (let); t; t = BLOCK_CHAIN (t))
1980 15678417 : instantiate_decls_1 (t);
1981 17209521 : }
1982 :
1983 : /* Scan all decls in FNDECL (both variables and parameters) and instantiate
1984 : all virtual registers in their DECL_RTL's. */
1985 :
1986 : static void
1987 1531104 : instantiate_decls (tree fndecl)
1988 : {
1989 1531104 : tree decl;
1990 1531104 : unsigned ix;
1991 :
1992 : /* Process all parameters of the function. */
1993 4713874 : for (decl = DECL_ARGUMENTS (fndecl); decl; decl = DECL_CHAIN (decl))
1994 : {
1995 3182770 : instantiate_decl_rtl (DECL_RTL (decl));
1996 3182770 : instantiate_decl_rtl (DECL_INCOMING_RTL (decl));
1997 3182770 : if (DECL_HAS_VALUE_EXPR_P (decl))
1998 : {
1999 144 : tree v = DECL_VALUE_EXPR (decl);
2000 144 : walk_tree (&v, instantiate_expr, NULL, NULL);
2001 : }
2002 : }
2003 :
2004 1531104 : if ((decl = DECL_RESULT (fndecl))
2005 1531104 : && TREE_CODE (decl) == RESULT_DECL)
2006 : {
2007 1531104 : if (DECL_RTL_SET_P (decl))
2008 813972 : instantiate_decl_rtl (DECL_RTL (decl));
2009 1531104 : if (DECL_HAS_VALUE_EXPR_P (decl))
2010 : {
2011 70276 : tree v = DECL_VALUE_EXPR (decl);
2012 70276 : walk_tree (&v, instantiate_expr, NULL, NULL);
2013 : }
2014 : }
2015 :
2016 : /* Process the saved static chain if it exists. */
2017 1531104 : decl = DECL_STRUCT_FUNCTION (fndecl)->static_chain_decl;
2018 1531104 : if (decl && DECL_HAS_VALUE_EXPR_P (decl))
2019 4177 : instantiate_decl_rtl (DECL_RTL (DECL_VALUE_EXPR (decl)));
2020 :
2021 : /* Now process all variables defined in the function or its subblocks. */
2022 1531104 : if (DECL_INITIAL (fndecl))
2023 1531104 : instantiate_decls_1 (DECL_INITIAL (fndecl));
2024 :
2025 2885870 : FOR_EACH_LOCAL_DECL (cfun, ix, decl)
2026 72204 : if (DECL_RTL_SET_P (decl))
2027 28689 : instantiate_decl_rtl (DECL_RTL (decl));
2028 1531104 : vec_free (cfun->local_decls);
2029 1531104 : }
2030 :
2031 : /* Return the value of STACK_DYNAMIC_OFFSET for the current function.
2032 : This is done through a function wrapper so that the macro sees a
2033 : predictable set of included files. */
2034 :
2035 : poly_int64
2036 1531104 : get_stack_dynamic_offset ()
2037 : {
2038 1531104 : return STACK_DYNAMIC_OFFSET (current_function_decl);
2039 : }
2040 :
2041 : /* Pass through the INSNS of function FNDECL and convert virtual register
2042 : references to hard register references. */
2043 :
2044 : static void
2045 1531104 : instantiate_virtual_regs (void)
2046 : {
2047 1531104 : rtx_insn *insn;
2048 :
2049 : /* Compute the offsets to use for this function. */
2050 1531104 : in_arg_offset = FIRST_PARM_OFFSET (current_function_decl);
2051 1531104 : var_offset = targetm.starting_frame_offset ();
2052 1531104 : dynamic_offset = get_stack_dynamic_offset ();
2053 1531104 : out_arg_offset = STACK_POINTER_OFFSET;
2054 : #ifdef FRAME_POINTER_CFA_OFFSET
2055 : cfa_offset = FRAME_POINTER_CFA_OFFSET (current_function_decl);
2056 : #else
2057 1531104 : cfa_offset = ARG_POINTER_CFA_OFFSET (current_function_decl);
2058 : #endif
2059 :
2060 : /* Initialize recognition, indicating that volatile is OK. */
2061 1531104 : init_recog ();
2062 :
2063 : /* Scan through all the insns, instantiating every virtual register still
2064 : present. */
2065 181152477 : for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2066 179621373 : if (INSN_P (insn))
2067 : {
2068 : /* These patterns in the instruction stream can never be recognized.
2069 : Fortunately, they shouldn't contain virtual registers either. */
2070 162279295 : if (GET_CODE (PATTERN (insn)) == USE
2071 148824832 : || GET_CODE (PATTERN (insn)) == CLOBBER
2072 148640670 : || GET_CODE (PATTERN (insn)) == ASM_INPUT
2073 298250837 : || DEBUG_MARKER_INSN_P (insn))
2074 12667110 : continue;
2075 136945075 : else if (DEBUG_BIND_INSN_P (insn))
2076 40386181 : instantiate_virtual_regs_in_rtx (INSN_VAR_LOCATION_PTR (insn));
2077 : else
2078 96558894 : instantiate_virtual_regs_in_insn (insn);
2079 :
2080 136945075 : if (insn->deleted ())
2081 18808 : continue;
2082 :
2083 136926267 : instantiate_virtual_regs_in_rtx (®_NOTES (insn));
2084 :
2085 : /* Instantiate any virtual registers in CALL_INSN_FUNCTION_USAGE. */
2086 185818263 : if (auto call = dyn_cast<rtx_call_insn *> (insn))
2087 6196890 : instantiate_virtual_regs_in_rtx (&CALL_INSN_FUNCTION_USAGE (call));
2088 : }
2089 :
2090 : /* Instantiate the virtual registers in the DECLs for debugging purposes. */
2091 1531104 : instantiate_decls (current_function_decl);
2092 :
2093 1531104 : targetm.instantiate_decls ();
2094 :
2095 : /* Indicate that, from now on, assign_stack_local should use
2096 : frame_pointer_rtx. */
2097 1531104 : virtuals_instantiated = 1;
2098 1531104 : }
2099 :
2100 : namespace {
2101 :
2102 : const pass_data pass_data_instantiate_virtual_regs =
2103 : {
2104 : RTL_PASS, /* type */
2105 : "vregs", /* name */
2106 : OPTGROUP_NONE, /* optinfo_flags */
2107 : TV_NONE, /* tv_id */
2108 : 0, /* properties_required */
2109 : 0, /* properties_provided */
2110 : 0, /* properties_destroyed */
2111 : 0, /* todo_flags_start */
2112 : 0, /* todo_flags_finish */
2113 : };
2114 :
2115 : class pass_instantiate_virtual_regs : public rtl_opt_pass
2116 : {
2117 : public:
2118 302985 : pass_instantiate_virtual_regs (gcc::context *ctxt)
2119 605970 : : rtl_opt_pass (pass_data_instantiate_virtual_regs, ctxt)
2120 : {}
2121 :
2122 : /* opt_pass methods: */
2123 1531104 : unsigned int execute (function *) final override
2124 : {
2125 1531104 : instantiate_virtual_regs ();
2126 1531104 : return 0;
2127 : }
2128 :
2129 : }; // class pass_instantiate_virtual_regs
2130 :
2131 : } // anon namespace
2132 :
2133 : rtl_opt_pass *
2134 302985 : make_pass_instantiate_virtual_regs (gcc::context *ctxt)
2135 : {
2136 302985 : return new pass_instantiate_virtual_regs (ctxt);
2137 : }
2138 :
2139 :
2140 : /* Return true if EXP is an aggregate type (or a value with aggregate type).
2141 : This means a type for which function calls must pass an address to the
2142 : function or get an address back from the function.
2143 : EXP may be a type node or an expression (whose type is tested). */
2144 :
2145 : bool
2146 154249693 : aggregate_value_p (const_tree exp, const_tree fntype)
2147 : {
2148 154262704 : const_tree type = (TYPE_P (exp)) ? exp : TREE_TYPE (exp);
2149 154262704 : int i, regno, nregs;
2150 154262704 : rtx reg;
2151 :
2152 154262704 : if (fntype)
2153 153937346 : switch (TREE_CODE (fntype))
2154 : {
2155 12263274 : case CALL_EXPR:
2156 12263274 : {
2157 12263274 : tree fndecl = get_callee_fndecl (fntype);
2158 12263274 : if (fndecl)
2159 11245795 : fntype = TREE_TYPE (fndecl);
2160 1017479 : else if (CALL_EXPR_FN (fntype))
2161 327489 : fntype = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (fntype)));
2162 : else
2163 : /* For internal functions, assume nothing needs to be
2164 : returned in memory. */
2165 : return false;
2166 : }
2167 : break;
2168 131452156 : case FUNCTION_DECL:
2169 131452156 : fntype = TREE_TYPE (fntype);
2170 131452156 : break;
2171 : case FUNCTION_TYPE:
2172 : case METHOD_TYPE:
2173 : break;
2174 : case IDENTIFIER_NODE:
2175 338616 : fntype = NULL_TREE;
2176 : break;
2177 0 : default:
2178 : /* We don't expect other tree types here. */
2179 0 : gcc_unreachable ();
2180 : }
2181 :
2182 153572714 : if (VOID_TYPE_P (type))
2183 : return false;
2184 :
2185 112914924 : if (error_operand_p (fntype))
2186 : return false;
2187 :
2188 : /* If a record should be passed the same as its first (and only) member
2189 : don't pass it as an aggregate. */
2190 112914923 : if (TREE_CODE (type) == RECORD_TYPE && TYPE_TRANSPARENT_AGGR (type))
2191 13011 : return aggregate_value_p (first_field (type), fntype);
2192 :
2193 : /* If the front end has decided that this needs to be passed by
2194 : reference, do so. */
2195 112901823 : if ((TREE_CODE (exp) == PARM_DECL || TREE_CODE (exp) == RESULT_DECL)
2196 206047625 : && DECL_BY_REFERENCE (exp))
2197 : return true;
2198 :
2199 : /* Function types that are TREE_ADDRESSABLE force return in memory. */
2200 112737510 : if (fntype && TREE_ADDRESSABLE (fntype))
2201 : return true;
2202 :
2203 : /* Types that are TREE_ADDRESSABLE must be constructed in memory,
2204 : and thus can't be returned in registers. */
2205 112737510 : if (TREE_ADDRESSABLE (type))
2206 : return true;
2207 :
2208 111358846 : if (TYPE_EMPTY_P (type))
2209 : return false;
2210 :
2211 110371089 : if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
2212 : return true;
2213 :
2214 109620088 : if (targetm.calls.return_in_memory (type, fntype))
2215 : return true;
2216 :
2217 : /* Make sure we have suitable call-clobbered regs to return
2218 : the value in; if not, we must return it in memory. */
2219 103386714 : reg = hard_function_value (type, 0, fntype, 0);
2220 :
2221 : /* If we have something other than a REG (e.g. a PARALLEL), then assume
2222 : it is OK. */
2223 103386714 : if (!REG_P (reg))
2224 : return false;
2225 :
2226 : /* Use the default ABI if the type of the function isn't known.
2227 : The scheme for handling interoperability between different ABIs
2228 : requires us to be able to tell when we're calling a function with
2229 : a nondefault ABI. */
2230 102457875 : const predefined_function_abi &abi = (fntype
2231 102457875 : ? fntype_abi (fntype)
2232 292562 : : default_function_abi);
2233 102457875 : regno = REGNO (reg);
2234 102457875 : nregs = hard_regno_nregs (regno, TYPE_MODE (type));
2235 207938885 : for (i = 0; i < nregs; i++)
2236 105481010 : if (!fixed_regs[regno + i] && !abi.clobbers_full_reg_p (regno + i))
2237 : return true;
2238 :
2239 : return false;
2240 : }
2241 :
2242 : /* Return true if we should assign DECL a pseudo register; false if it
2243 : should live on the local stack. */
2244 :
2245 : bool
2246 178134388 : use_register_for_decl (const_tree decl)
2247 : {
2248 178134388 : if (TREE_CODE (decl) == SSA_NAME)
2249 : {
2250 : /* We often try to use the SSA_NAME, instead of its underlying
2251 : decl, to get type information and guide decisions, to avoid
2252 : differences of behavior between anonymous and named
2253 : variables, but in this one case we have to go for the actual
2254 : variable if there is one. The main reason is that, at least
2255 : at -O0, we want to place user variables on the stack, but we
2256 : don't mind using pseudos for anonymous or ignored temps.
2257 : Should we take the SSA_NAME, we'd conclude all SSA_NAMEs
2258 : should go in pseudos, whereas their corresponding variables
2259 : might have to go on the stack. So, disregarding the decl
2260 : here would negatively impact debug info at -O0, enable
2261 : coalescing between SSA_NAMEs that ought to get different
2262 : stack/pseudo assignments, and get the incoming argument
2263 : processing thoroughly confused by PARM_DECLs expected to live
2264 : in stack slots but assigned to pseudos. */
2265 159126246 : if (!SSA_NAME_VAR (decl))
2266 105033685 : return TYPE_MODE (TREE_TYPE (decl)) != BLKmode
2267 105033685 : && !(flag_float_store && FLOAT_TYPE_P (TREE_TYPE (decl)));
2268 :
2269 : decl = SSA_NAME_VAR (decl);
2270 : }
2271 :
2272 : /* Honor volatile. */
2273 73100703 : if (TREE_SIDE_EFFECTS (decl))
2274 : return false;
2275 :
2276 : /* Honor addressability. */
2277 72977480 : if (TREE_ADDRESSABLE (decl))
2278 : return false;
2279 :
2280 : /* RESULT_DECLs are a bit special in that they're assigned without
2281 : regard to use_register_for_decl, but we generally only store in
2282 : them. If we coalesce their SSA NAMEs, we'd better return a
2283 : result that matches the assignment in expand_function_start. */
2284 68503834 : if (TREE_CODE (decl) == RESULT_DECL)
2285 : {
2286 : /* If it's not an aggregate, we're going to use a REG or a
2287 : PARALLEL containing a REG. */
2288 3547956 : if (!aggregate_value_p (decl, current_function_decl))
2289 : return true;
2290 :
2291 : /* If expand_function_start determines the return value, we'll
2292 : use MEM if it's not by reference. */
2293 41115 : if (cfun->returns_pcc_struct
2294 82230 : || (targetm.calls.struct_value_rtx
2295 41115 : (TREE_TYPE (current_function_decl), 1)))
2296 0 : return DECL_BY_REFERENCE (decl);
2297 :
2298 : /* Otherwise, we're taking an extra all.function_result_decl
2299 : argument. It's set up in assign_parms_augmented_arg_list,
2300 : under the (negated) conditions above, and then it's used to
2301 : set up the RESULT_DECL rtl in assign_params, after looping
2302 : over all parameters. Now, if the RESULT_DECL is not by
2303 : reference, we'll use a MEM either way. */
2304 41115 : if (!DECL_BY_REFERENCE (decl))
2305 : return false;
2306 :
2307 : /* Otherwise, if RESULT_DECL is DECL_BY_REFERENCE, it will take
2308 : the function_result_decl's assignment. Since it's a pointer,
2309 : we can short-circuit a number of the tests below, and we must
2310 : duplicate them because we don't have the function_result_decl
2311 : to test. */
2312 41115 : if (!targetm.calls.allocate_stack_slots_for_args ())
2313 : return true;
2314 : /* We don't set DECL_IGNORED_P for the function_result_decl. */
2315 41115 : if (optimize)
2316 : return true;
2317 : /* Needed for [[musttail]] which can operate even at -O0 */
2318 5883 : if (cfun->tail_call_marked)
2319 : return true;
2320 : /* We don't set DECL_REGISTER for the function_result_decl. */
2321 : return false;
2322 : }
2323 :
2324 : /* Only register-like things go in registers. */
2325 64955878 : if (DECL_MODE (decl) == BLKmode)
2326 : return false;
2327 :
2328 : /* If -ffloat-store specified, don't put explicit float variables
2329 : into registers. */
2330 : /* ??? This should be checked after DECL_ARTIFICIAL, but tree-ssa
2331 : propagates values across these stores, and it probably shouldn't. */
2332 63162573 : if (flag_float_store && FLOAT_TYPE_P (TREE_TYPE (decl)))
2333 : return false;
2334 :
2335 63159769 : if (!targetm.calls.allocate_stack_slots_for_args ())
2336 : return true;
2337 :
2338 : /* If we're not interested in tracking debugging information for
2339 : this decl, then we can certainly put it in a register. */
2340 63159406 : if (DECL_IGNORED_P (decl))
2341 : return true;
2342 :
2343 42913352 : if (optimize)
2344 : return true;
2345 :
2346 : /* Thunks force a tail call even at -O0 so we need to avoid creating a
2347 : dangling reference in case the parameter is passed by reference. */
2348 8816288 : if (TREE_CODE (decl) == PARM_DECL && cfun->tail_call_marked)
2349 : return true;
2350 :
2351 8815492 : if (!DECL_REGISTER (decl))
2352 : return false;
2353 :
2354 : /* When not optimizing, disregard register keyword for types that
2355 : could have methods, otherwise the methods won't be callable from
2356 : the debugger. */
2357 13318 : if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl)))
2358 : return false;
2359 :
2360 : return true;
2361 : }
2362 :
2363 : /* Structures to communicate between the subroutines of assign_parms.
2364 : The first holds data persistent across all parameters, the second
2365 : is cleared out for each parameter. */
2366 :
2367 : struct assign_parm_data_all
2368 : {
2369 : /* When INIT_CUMULATIVE_ARGS gets revamped, allocating CUMULATIVE_ARGS
2370 : should become a job of the target or otherwise encapsulated. */
2371 : CUMULATIVE_ARGS args_so_far_v;
2372 : cumulative_args_t args_so_far;
2373 : struct args_size stack_args_size;
2374 : tree function_result_decl;
2375 : tree orig_fnargs;
2376 : rtx_insn *first_conversion_insn;
2377 : rtx_insn *last_conversion_insn;
2378 : HOST_WIDE_INT pretend_args_size;
2379 : HOST_WIDE_INT extra_pretend_bytes;
2380 : int reg_parm_stack_space;
2381 : };
2382 :
2383 18934280 : struct assign_parm_data_one
2384 : {
2385 : tree nominal_type;
2386 : function_arg_info arg;
2387 : rtx entry_parm;
2388 : rtx stack_parm;
2389 : machine_mode nominal_mode;
2390 : machine_mode passed_mode;
2391 : struct locate_and_pad_arg_data locate;
2392 : int partial;
2393 : };
2394 :
2395 : /* A subroutine of assign_parms. Initialize ALL. */
2396 :
2397 : static void
2398 4551906 : assign_parms_initialize_all (struct assign_parm_data_all *all)
2399 : {
2400 4551906 : tree fntype ATTRIBUTE_UNUSED;
2401 :
2402 4551906 : memset (all, 0, sizeof (*all));
2403 :
2404 4551906 : fntype = TREE_TYPE (current_function_decl);
2405 :
2406 : #ifdef INIT_CUMULATIVE_INCOMING_ARGS
2407 : INIT_CUMULATIVE_INCOMING_ARGS (all->args_so_far_v, fntype, NULL_RTX);
2408 : #else
2409 4551906 : INIT_CUMULATIVE_ARGS (all->args_so_far_v, fntype, NULL_RTX,
2410 : current_function_decl, -1);
2411 : #endif
2412 4551906 : all->args_so_far = pack_cumulative_args (&all->args_so_far_v);
2413 :
2414 : #ifdef INCOMING_REG_PARM_STACK_SPACE
2415 4551906 : all->reg_parm_stack_space
2416 4551906 : = INCOMING_REG_PARM_STACK_SPACE (current_function_decl);
2417 : #endif
2418 4551906 : }
2419 :
2420 : /* If ARGS contains entries with complex types, split the entry into two
2421 : entries of the component type. Return a new list of substitutions are
2422 : needed, else the old list. */
2423 :
2424 : static void
2425 0 : split_complex_args (vec<tree> *args)
2426 : {
2427 0 : unsigned i;
2428 0 : tree p;
2429 :
2430 0 : FOR_EACH_VEC_ELT (*args, i, p)
2431 : {
2432 0 : tree type = TREE_TYPE (p);
2433 0 : if (TREE_CODE (type) == COMPLEX_TYPE
2434 0 : && targetm.calls.split_complex_arg (type))
2435 : {
2436 0 : tree decl;
2437 0 : tree subtype = TREE_TYPE (type);
2438 0 : bool addressable = TREE_ADDRESSABLE (p);
2439 :
2440 : /* Rewrite the PARM_DECL's type with its component. */
2441 0 : p = copy_node (p);
2442 0 : TREE_TYPE (p) = subtype;
2443 0 : DECL_ARG_TYPE (p) = TREE_TYPE (DECL_ARG_TYPE (p));
2444 0 : SET_DECL_MODE (p, VOIDmode);
2445 0 : DECL_SIZE (p) = NULL;
2446 0 : DECL_SIZE_UNIT (p) = NULL;
2447 : /* If this arg must go in memory, put it in a pseudo here.
2448 : We can't allow it to go in memory as per normal parms,
2449 : because the usual place might not have the imag part
2450 : adjacent to the real part. */
2451 0 : DECL_ARTIFICIAL (p) = addressable;
2452 0 : DECL_IGNORED_P (p) = addressable;
2453 0 : TREE_ADDRESSABLE (p) = 0;
2454 0 : layout_decl (p, 0);
2455 0 : (*args)[i] = p;
2456 :
2457 : /* Build a second synthetic decl. */
2458 0 : decl = build_decl (EXPR_LOCATION (p),
2459 : PARM_DECL, NULL_TREE, subtype);
2460 0 : DECL_ARG_TYPE (decl) = DECL_ARG_TYPE (p);
2461 0 : DECL_ARTIFICIAL (decl) = addressable;
2462 0 : DECL_IGNORED_P (decl) = addressable;
2463 0 : layout_decl (decl, 0);
2464 0 : args->safe_insert (++i, decl);
2465 : }
2466 : }
2467 0 : }
2468 :
2469 : /* A subroutine of assign_parms. Adjust the parameter list to incorporate
2470 : the hidden struct return argument, and (abi willing) complex args.
2471 : Return the new parameter list. */
2472 :
2473 : static vec<tree>
2474 4551906 : assign_parms_augmented_arg_list (struct assign_parm_data_all *all)
2475 : {
2476 4551906 : tree fndecl = current_function_decl;
2477 4551906 : tree fntype = TREE_TYPE (fndecl);
2478 4551906 : vec<tree> fnargs = vNULL;
2479 4551906 : tree arg;
2480 :
2481 13817893 : for (arg = DECL_ARGUMENTS (fndecl); arg; arg = DECL_CHAIN (arg))
2482 9265987 : fnargs.safe_push (arg);
2483 :
2484 4551906 : all->orig_fnargs = DECL_ARGUMENTS (fndecl);
2485 :
2486 : /* If struct value address is treated as the first argument, make it so. */
2487 4551906 : if (aggregate_value_p (DECL_RESULT (fndecl), fndecl)
2488 201153 : && ! cfun->returns_pcc_struct
2489 4753059 : && targetm.calls.struct_value_rtx (TREE_TYPE (fndecl), 1) == 0)
2490 : {
2491 201153 : tree type = build_pointer_type (TREE_TYPE (fntype));
2492 201153 : tree decl;
2493 :
2494 201153 : decl = build_decl (DECL_SOURCE_LOCATION (fndecl),
2495 : PARM_DECL, get_identifier (".result_ptr"), type);
2496 201153 : DECL_ARG_TYPE (decl) = type;
2497 201153 : DECL_ARTIFICIAL (decl) = 1;
2498 201153 : DECL_NAMELESS (decl) = 1;
2499 201153 : TREE_CONSTANT (decl) = 1;
2500 : /* We don't set DECL_IGNORED_P or DECL_REGISTER here. If this
2501 : changes, the end of the RESULT_DECL handling block in
2502 : use_register_for_decl must be adjusted to match. */
2503 :
2504 201153 : DECL_CHAIN (decl) = all->orig_fnargs;
2505 201153 : all->orig_fnargs = decl;
2506 201153 : fnargs.safe_insert (0, decl);
2507 :
2508 201153 : all->function_result_decl = decl;
2509 : }
2510 :
2511 : /* If the target wants to split complex arguments into scalars, do so. */
2512 4551906 : if (targetm.calls.split_complex_arg)
2513 0 : split_complex_args (&fnargs);
2514 :
2515 4551906 : return fnargs;
2516 : }
2517 :
2518 : /* A subroutine of assign_parms. Examine PARM and pull out type and mode
2519 : data for the parameter. Incorporate ABI specifics such as pass-by-
2520 : reference and type promotion. */
2521 :
2522 : static void
2523 9467140 : assign_parm_find_data_types (struct assign_parm_data_all *all, tree parm,
2524 : struct assign_parm_data_one *data)
2525 : {
2526 9467140 : int unsignedp;
2527 :
2528 9467140 : *data = assign_parm_data_one ();
2529 :
2530 : /* NAMED_ARG is a misnomer. We really mean 'non-variadic'. */
2531 9467140 : if (!cfun->stdarg)
2532 9385173 : data->arg.named = 1; /* No variadic parms. */
2533 81967 : else if (DECL_CHAIN (parm))
2534 38917 : data->arg.named = 1; /* Not the last non-variadic parm. */
2535 43050 : else if (targetm.calls.strict_argument_naming (all->args_so_far))
2536 43050 : data->arg.named = 1; /* Only variadic ones are unnamed. */
2537 : else
2538 0 : data->arg.named = 0; /* Treat as variadic. */
2539 :
2540 9467140 : data->nominal_type = TREE_TYPE (parm);
2541 9467140 : data->arg.type = DECL_ARG_TYPE (parm);
2542 :
2543 : /* Look out for errors propagating this far. Also, if the parameter's
2544 : type is void then its value doesn't matter. */
2545 9467140 : if (TREE_TYPE (parm) == error_mark_node
2546 : /* This can happen after weird syntax errors
2547 : or if an enum type is defined among the parms. */
2548 9467047 : || TREE_CODE (parm) != PARM_DECL
2549 9467047 : || data->arg.type == NULL
2550 18934187 : || VOID_TYPE_P (data->nominal_type))
2551 : {
2552 93 : data->nominal_type = data->arg.type = void_type_node;
2553 93 : data->nominal_mode = data->passed_mode = data->arg.mode = VOIDmode;
2554 93 : return;
2555 : }
2556 :
2557 : /* Find mode of arg as it is passed, and mode of arg as it should be
2558 : during execution of this function. */
2559 9467047 : data->passed_mode = data->arg.mode = TYPE_MODE (data->arg.type);
2560 9467047 : data->nominal_mode = TYPE_MODE (data->nominal_type);
2561 :
2562 : /* If the parm is to be passed as a transparent union or record, use the
2563 : type of the first field for the tests below. We have already verified
2564 : that the modes are the same. */
2565 9467047 : if (RECORD_OR_UNION_TYPE_P (data->arg.type)
2566 9467047 : && TYPE_TRANSPARENT_AGGR (data->arg.type))
2567 1482 : data->arg.type = TREE_TYPE (first_field (data->arg.type));
2568 :
2569 : /* See if this arg was passed by invisible reference. */
2570 9467047 : if (apply_pass_by_reference_rules (&all->args_so_far_v, data->arg))
2571 : {
2572 9940 : data->nominal_type = data->arg.type;
2573 9940 : data->passed_mode = data->nominal_mode = data->arg.mode;
2574 : }
2575 :
2576 : /* Find mode as it is passed by the ABI. */
2577 9467047 : unsignedp = TYPE_UNSIGNED (data->arg.type);
2578 9467047 : data->arg.mode
2579 9467047 : = promote_function_mode (data->arg.type, data->arg.mode, &unsignedp,
2580 9467047 : TREE_TYPE (current_function_decl), 0);
2581 : }
2582 :
2583 : /* A subroutine of assign_parms. Invoke setup_incoming_varargs. */
2584 :
2585 : static void
2586 21627 : assign_parms_setup_varargs (struct assign_parm_data_all *all,
2587 : struct assign_parm_data_one *data, bool no_rtl)
2588 : {
2589 21627 : int varargs_pretend_bytes = 0;
2590 :
2591 21627 : function_arg_info last_named_arg = data->arg;
2592 21627 : last_named_arg.named = true;
2593 21627 : targetm.calls.setup_incoming_varargs (all->args_so_far, last_named_arg,
2594 : &varargs_pretend_bytes, no_rtl);
2595 :
2596 : /* If the back-end has requested extra stack space, record how much is
2597 : needed. Do not change pretend_args_size otherwise since it may be
2598 : nonzero from an earlier partial argument. */
2599 21627 : if (varargs_pretend_bytes > 0)
2600 0 : all->pretend_args_size = varargs_pretend_bytes;
2601 21627 : }
2602 :
2603 : /* A subroutine of assign_parms. Set DATA->ENTRY_PARM corresponding to
2604 : the incoming location of the current parameter. */
2605 :
2606 : static void
2607 3253624 : assign_parm_find_entry_rtl (struct assign_parm_data_all *all,
2608 : struct assign_parm_data_one *data)
2609 : {
2610 3253624 : HOST_WIDE_INT pretend_bytes = 0;
2611 3253624 : rtx entry_parm;
2612 3253624 : bool in_regs;
2613 :
2614 3253624 : if (data->arg.mode == VOIDmode)
2615 : {
2616 0 : data->entry_parm = data->stack_parm = const0_rtx;
2617 0 : return;
2618 : }
2619 :
2620 3253624 : targetm.calls.warn_parameter_passing_abi (all->args_so_far,
2621 : data->arg.type);
2622 :
2623 6507248 : entry_parm = targetm.calls.function_incoming_arg (all->args_so_far,
2624 3253624 : data->arg);
2625 3253624 : if (entry_parm == 0)
2626 1073799 : data->arg.mode = data->passed_mode;
2627 :
2628 : /* Determine parm's home in the stack, in case it arrives in the stack
2629 : or we should pretend it did. Compute the stack position and rtx where
2630 : the argument arrives and its size.
2631 :
2632 : There is one complexity here: If this was a parameter that would
2633 : have been passed in registers, but wasn't only because it is
2634 : __builtin_va_alist, we want locate_and_pad_parm to treat it as if
2635 : it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
2636 : In this case, we call FUNCTION_ARG with NAMED set to 1 instead of 0
2637 : as it was the previous time. */
2638 1073799 : in_regs = (entry_parm != 0);
2639 : #ifdef STACK_PARMS_IN_REG_PARM_AREA
2640 : in_regs = true;
2641 : #endif
2642 1073799 : if (!in_regs && !data->arg.named)
2643 : {
2644 0 : if (targetm.calls.pretend_outgoing_varargs_named (all->args_so_far))
2645 : {
2646 0 : rtx tem;
2647 0 : function_arg_info named_arg = data->arg;
2648 0 : named_arg.named = true;
2649 0 : tem = targetm.calls.function_incoming_arg (all->args_so_far,
2650 : named_arg);
2651 0 : in_regs = tem != NULL;
2652 : }
2653 : }
2654 :
2655 : /* If this parameter was passed both in registers and in the stack, use
2656 : the copy on the stack. */
2657 3253624 : if (targetm.calls.must_pass_in_stack (data->arg))
2658 : entry_parm = 0;
2659 :
2660 3253624 : if (entry_parm)
2661 : {
2662 2179825 : int partial;
2663 :
2664 2179825 : partial = targetm.calls.arg_partial_bytes (all->args_so_far, data->arg);
2665 2179825 : data->partial = partial;
2666 :
2667 : /* The caller might already have allocated stack space for the
2668 : register parameters. */
2669 2179825 : if (partial != 0 && all->reg_parm_stack_space == 0)
2670 : {
2671 : /* Part of this argument is passed in registers and part
2672 : is passed on the stack. Ask the prologue code to extend
2673 : the stack part so that we can recreate the full value.
2674 :
2675 : PRETEND_BYTES is the size of the registers we need to store.
2676 : CURRENT_FUNCTION_PRETEND_ARGS_SIZE is the amount of extra
2677 : stack space that the prologue should allocate.
2678 :
2679 : Internally, gcc assumes that the argument pointer is aligned
2680 : to STACK_BOUNDARY bits. This is used both for alignment
2681 : optimizations (see init_emit) and to locate arguments that are
2682 : aligned to more than PARM_BOUNDARY bits. We must preserve this
2683 : invariant by rounding CURRENT_FUNCTION_PRETEND_ARGS_SIZE up to
2684 : a stack boundary. */
2685 :
2686 : /* We assume at most one partial arg, and it must be the first
2687 : argument on the stack. */
2688 0 : gcc_assert (!all->extra_pretend_bytes && !all->pretend_args_size);
2689 :
2690 0 : pretend_bytes = partial;
2691 0 : all->pretend_args_size = CEIL_ROUND (pretend_bytes, STACK_BYTES);
2692 :
2693 : /* We want to align relative to the actual stack pointer, so
2694 : don't include this in the stack size until later. */
2695 0 : all->extra_pretend_bytes = all->pretend_args_size;
2696 : }
2697 : }
2698 :
2699 3253624 : locate_and_pad_parm (data->arg.mode, data->arg.type, in_regs,
2700 : all->reg_parm_stack_space,
2701 : entry_parm ? data->partial : 0, current_function_decl,
2702 : &all->stack_args_size, &data->locate);
2703 :
2704 : /* Update parm_stack_boundary if this parameter is passed in the
2705 : stack. */
2706 3253624 : if (!in_regs && crtl->parm_stack_boundary < data->locate.boundary)
2707 199611 : crtl->parm_stack_boundary = data->locate.boundary;
2708 :
2709 : /* Adjust offsets to include the pretend args. */
2710 3253624 : pretend_bytes = all->extra_pretend_bytes - pretend_bytes;
2711 3253624 : data->locate.slot_offset.constant += pretend_bytes;
2712 3253624 : data->locate.offset.constant += pretend_bytes;
2713 :
2714 3253624 : data->entry_parm = entry_parm;
2715 : }
2716 :
2717 : /* A subroutine of assign_parms. If there is actually space on the stack
2718 : for this parm, count it in stack_args_size and return true. */
2719 :
2720 : static bool
2721 3253624 : assign_parm_is_stack_parm (struct assign_parm_data_all *all,
2722 : struct assign_parm_data_one *data)
2723 : {
2724 : /* Trivially true if we've no incoming register. */
2725 3253624 : if (data->entry_parm == NULL)
2726 : ;
2727 : /* Also true if we're partially in registers and partially not,
2728 : since we've arranged to drop the entire argument on the stack. */
2729 2179825 : else if (data->partial != 0)
2730 : ;
2731 : /* Also true if the target says that it's passed in both registers
2732 : and on the stack. */
2733 2179825 : else if (GET_CODE (data->entry_parm) == PARALLEL
2734 55053 : && XEXP (XVECEXP (data->entry_parm, 0, 0), 0) == NULL_RTX)
2735 : ;
2736 : /* Also true if the target says that there's stack allocated for
2737 : all register parameters. */
2738 2179825 : else if (all->reg_parm_stack_space > 0)
2739 : ;
2740 : /* Otherwise, no, this parameter has no ABI defined stack slot. */
2741 : else
2742 : return false;
2743 :
2744 1184134 : all->stack_args_size.constant += data->locate.size.constant;
2745 1184134 : if (data->locate.size.var)
2746 0 : ADD_PARM_SIZE (all->stack_args_size, data->locate.size.var);
2747 :
2748 : return true;
2749 : }
2750 :
2751 : /* A subroutine of assign_parms. Given that this parameter is allocated
2752 : stack space by the ABI, find it. */
2753 :
2754 : static void
2755 1184134 : assign_parm_find_stack_rtl (tree parm, struct assign_parm_data_one *data)
2756 : {
2757 1184134 : rtx offset_rtx, stack_parm;
2758 1184134 : unsigned int align, boundary;
2759 :
2760 : /* If we're passing this arg using a reg, make its stack home the
2761 : aligned stack slot. */
2762 1184134 : if (data->entry_parm)
2763 110335 : offset_rtx = ARGS_SIZE_RTX (data->locate.slot_offset);
2764 : else
2765 1317150 : offset_rtx = ARGS_SIZE_RTX (data->locate.offset);
2766 :
2767 1184134 : stack_parm = crtl->args.internal_arg_pointer;
2768 1184134 : if (offset_rtx != const0_rtx)
2769 1094305 : stack_parm = gen_rtx_PLUS (Pmode, stack_parm, offset_rtx);
2770 1184134 : stack_parm = gen_rtx_MEM (data->arg.mode, stack_parm);
2771 :
2772 1184134 : if (!data->arg.pass_by_reference)
2773 : {
2774 1179204 : set_mem_attributes (stack_parm, parm, 1);
2775 : /* set_mem_attributes could set MEM_SIZE to the passed mode's size,
2776 : while promoted mode's size is needed. */
2777 1179204 : if (data->arg.mode != BLKmode
2778 1179204 : && data->arg.mode != DECL_MODE (parm))
2779 : {
2780 0 : set_mem_size (stack_parm, GET_MODE_SIZE (data->arg.mode));
2781 0 : if (MEM_EXPR (stack_parm) && MEM_OFFSET_KNOWN_P (stack_parm))
2782 : {
2783 0 : poly_int64 offset = subreg_lowpart_offset (DECL_MODE (parm),
2784 0 : data->arg.mode);
2785 0 : if (maybe_ne (offset, 0))
2786 0 : set_mem_offset (stack_parm, MEM_OFFSET (stack_parm) - offset);
2787 : }
2788 : }
2789 : }
2790 :
2791 1184134 : boundary = data->locate.boundary;
2792 1184134 : align = BITS_PER_UNIT;
2793 :
2794 : /* If we're padding upward, we know that the alignment of the slot
2795 : is TARGET_FUNCTION_ARG_BOUNDARY. If we're using slot_offset, we're
2796 : intentionally forcing upward padding. Otherwise we have to come
2797 : up with a guess at the alignment based on OFFSET_RTX. */
2798 1184134 : poly_int64 offset;
2799 1184134 : if (data->locate.where_pad == PAD_NONE || data->entry_parm)
2800 : align = boundary;
2801 1073799 : else if (data->locate.where_pad == PAD_UPWARD)
2802 : {
2803 1073799 : align = boundary;
2804 : /* If the argument offset is actually more aligned than the nominal
2805 : stack slot boundary, take advantage of that excess alignment.
2806 : Don't make any assumptions if STACK_POINTER_OFFSET is in use. */
2807 1073799 : if (poly_int_rtx_p (offset_rtx, &offset)
2808 : && known_eq (STACK_POINTER_OFFSET, 0))
2809 : {
2810 1073799 : unsigned int offset_align = known_alignment (offset) * BITS_PER_UNIT;
2811 1202606 : if (offset_align == 0 || offset_align > STACK_BOUNDARY)
2812 592501 : offset_align = STACK_BOUNDARY;
2813 1073799 : align = MAX (align, offset_align);
2814 : }
2815 : }
2816 0 : else if (poly_int_rtx_p (offset_rtx, &offset))
2817 : {
2818 0 : align = least_bit_hwi (boundary);
2819 0 : unsigned int offset_align = known_alignment (offset) * BITS_PER_UNIT;
2820 0 : if (offset_align != 0)
2821 0 : align = MIN (align, offset_align);
2822 : }
2823 :
2824 : /* If part of the argument is passed in registers and the rest on the
2825 : stack, the value is reconstructed by spilling the register part just
2826 : below the aligned stack slot. The full value therefore starts at an
2827 : address that is only aligned to the largest power of two dividing the
2828 : size of the register part, not to FUNCTION_ARG_BOUNDARY. */
2829 1184134 : if (data->partial)
2830 0 : align = MIN (align,
2831 : least_bit_hwi (data->partial) * BITS_PER_UNIT);
2832 :
2833 1184134 : set_mem_align (stack_parm, align);
2834 :
2835 1184134 : if (data->entry_parm)
2836 110335 : set_reg_attrs_for_parm (data->entry_parm, stack_parm);
2837 :
2838 1184134 : data->stack_parm = stack_parm;
2839 1184134 : }
2840 :
2841 : /* A subroutine of assign_parms. Adjust DATA->ENTRY_RTL such that it's
2842 : always valid and contiguous. */
2843 :
2844 : static void
2845 1184134 : assign_parm_adjust_entry_rtl (struct assign_parm_data_one *data)
2846 : {
2847 1184134 : rtx entry_parm = data->entry_parm;
2848 1184134 : rtx stack_parm = data->stack_parm;
2849 :
2850 : /* If this parm was passed part in regs and part in memory, pretend it
2851 : arrived entirely in memory by pushing the register-part onto the stack.
2852 : In the special case of a DImode or DFmode that is split, we could put
2853 : it together in a pseudoreg directly, but for now that's not worth
2854 : bothering with. */
2855 1184134 : if (data->partial != 0)
2856 : {
2857 : /* Handle calls that pass values in multiple non-contiguous
2858 : locations. The Irix 6 ABI has examples of this. */
2859 0 : if (GET_CODE (entry_parm) == PARALLEL)
2860 0 : emit_group_store (validize_mem (copy_rtx (stack_parm)), entry_parm,
2861 0 : data->arg.type, int_size_in_bytes (data->arg.type));
2862 : else
2863 : {
2864 0 : gcc_assert (data->partial % UNITS_PER_WORD == 0);
2865 0 : move_block_from_reg (REGNO (entry_parm),
2866 : validize_mem (copy_rtx (stack_parm)),
2867 : data->partial / UNITS_PER_WORD);
2868 : }
2869 :
2870 : entry_parm = stack_parm;
2871 : }
2872 :
2873 : /* If we didn't decide this parm came in a register, by default it came
2874 : on the stack. */
2875 1184134 : else if (entry_parm == NULL)
2876 : entry_parm = stack_parm;
2877 :
2878 : /* When an argument is passed in multiple locations, we can't make use
2879 : of this information, but we can save some copying if the whole argument
2880 : is passed in a single register. */
2881 110335 : else if (GET_CODE (entry_parm) == PARALLEL
2882 0 : && data->nominal_mode != BLKmode
2883 0 : && data->passed_mode != BLKmode)
2884 : {
2885 0 : size_t i, len = XVECLEN (entry_parm, 0);
2886 :
2887 0 : for (i = 0; i < len; i++)
2888 0 : if (XEXP (XVECEXP (entry_parm, 0, i), 0) != NULL_RTX
2889 0 : && REG_P (XEXP (XVECEXP (entry_parm, 0, i), 0))
2890 0 : && (GET_MODE (XEXP (XVECEXP (entry_parm, 0, i), 0))
2891 0 : == data->passed_mode)
2892 0 : && INTVAL (XEXP (XVECEXP (entry_parm, 0, i), 1)) == 0)
2893 : {
2894 : entry_parm = XEXP (XVECEXP (entry_parm, 0, i), 0);
2895 : break;
2896 : }
2897 : }
2898 :
2899 1184134 : data->entry_parm = entry_parm;
2900 1184134 : }
2901 :
2902 : /* A subroutine of assign_parms. Reconstitute any values which were
2903 : passed in multiple registers and would fit in a single register. */
2904 :
2905 : static void
2906 3178843 : assign_parm_remove_parallels (struct assign_parm_data_one *data)
2907 : {
2908 3178843 : rtx entry_parm = data->entry_parm;
2909 :
2910 : /* Convert the PARALLEL to a REG of the same mode as the parallel.
2911 : This can be done with register operations rather than on the
2912 : stack, even if we will store the reconstituted parameter on the
2913 : stack later. */
2914 3178843 : if (GET_CODE (entry_parm) == PARALLEL && GET_MODE (entry_parm) != BLKmode)
2915 : {
2916 51192 : rtx parmreg = gen_reg_rtx (GET_MODE (entry_parm));
2917 51192 : emit_group_store (parmreg, entry_parm, data->arg.type,
2918 102384 : GET_MODE_SIZE (GET_MODE (entry_parm)));
2919 51192 : entry_parm = parmreg;
2920 : }
2921 :
2922 3178843 : data->entry_parm = entry_parm;
2923 3178843 : }
2924 :
2925 : /* A subroutine of assign_parms. Adjust DATA->STACK_RTL such that it's
2926 : always valid and properly aligned. */
2927 :
2928 : static void
2929 3253624 : assign_parm_adjust_stack_rtl (tree parm, struct assign_parm_data_one *data)
2930 : {
2931 3253624 : rtx stack_parm = data->stack_parm;
2932 :
2933 : /* If we can't trust the parm stack slot to be aligned enough for its
2934 : ultimate type, don't use that slot after entry. We'll make another
2935 : stack slot, if we need one. */
2936 3253624 : if (stack_parm
2937 3253624 : && ((GET_MODE_ALIGNMENT (data->nominal_mode) > MEM_ALIGN (stack_parm)
2938 24912 : && ((optab_handler (movmisalign_optab, data->nominal_mode)
2939 : != CODE_FOR_nothing)
2940 49816 : || targetm.slow_unaligned_access (data->nominal_mode,
2941 24908 : MEM_ALIGN (stack_parm))))
2942 1182586 : || (data->nominal_type
2943 2365172 : && TYPE_ALIGN (data->nominal_type) > MEM_ALIGN (stack_parm)
2944 4508 : && ((MEM_ALIGN (stack_parm)
2945 4508 : < MIN (BIGGEST_ALIGNMENT, MAX_SUPPORTED_STACK_ALIGNMENT))
2946 : /* If its address is taken, make a local copy whose
2947 : maximum alignment is MAX_SUPPORTED_STACK_ALIGNMENT.
2948 : */
2949 4 : || (TREE_ADDRESSABLE (parm)
2950 : && (MEM_ALIGN (stack_parm)
2951 : < MAX_SUPPORTED_STACK_ALIGNMENT))))))
2952 : stack_parm = NULL;
2953 :
2954 : /* If parm was passed in memory, and we need to convert it on entry,
2955 : don't store it back in that same slot. */
2956 3249115 : else if (data->entry_parm == stack_parm
2957 1067746 : && data->nominal_mode != BLKmode
2958 998463 : && data->nominal_mode != data->passed_mode)
2959 : stack_parm = NULL;
2960 :
2961 : /* If stack protection is in effect for this function, don't leave any
2962 : pointers in their passed stack slots. */
2963 3249115 : else if (crtl->stack_protect_guard
2964 232 : && (flag_stack_protect == SPCT_FLAG_ALL
2965 171 : || data->arg.pass_by_reference
2966 171 : || POINTER_TYPE_P (data->nominal_type)))
2967 3253624 : stack_parm = NULL;
2968 :
2969 3253624 : data->stack_parm = stack_parm;
2970 3253624 : }
2971 :
2972 : /* A subroutine of assign_parms. Return true if the current parameter
2973 : should be stored as a BLKmode in the current frame. */
2974 :
2975 : static bool
2976 3253624 : assign_parm_setup_block_p (struct assign_parm_data_one *data)
2977 : {
2978 0 : if (data->nominal_mode == BLKmode)
2979 : return true;
2980 3178843 : if (GET_MODE (data->entry_parm) == BLKmode)
2981 0 : return true;
2982 :
2983 : #ifdef BLOCK_REG_PADDING
2984 : /* Only assign_parm_setup_block knows how to deal with register arguments
2985 : that are padded at the least significant end. */
2986 : if (REG_P (data->entry_parm)
2987 : && known_lt (GET_MODE_SIZE (data->arg.mode), UNITS_PER_WORD)
2988 : && (BLOCK_REG_PADDING (data->passed_mode, data->arg.type, 1)
2989 : == (BYTES_BIG_ENDIAN ? PAD_UPWARD : PAD_DOWNWARD)))
2990 : return true;
2991 : #endif
2992 :
2993 : return false;
2994 : }
2995 :
2996 : /* A subroutine of assign_parms. Arrange for the parameter to be
2997 : present and valid in DATA->STACK_RTL. */
2998 :
2999 : static void
3000 74781 : assign_parm_setup_block (struct assign_parm_data_all *all,
3001 : tree parm, struct assign_parm_data_one *data)
3002 : {
3003 74781 : rtx entry_parm = data->entry_parm;
3004 74781 : rtx stack_parm = data->stack_parm;
3005 74781 : rtx target_reg = NULL_RTX;
3006 74781 : bool in_conversion_seq = false;
3007 74781 : HOST_WIDE_INT size;
3008 74781 : HOST_WIDE_INT size_stored;
3009 :
3010 74781 : if (GET_CODE (entry_parm) == PARALLEL)
3011 3861 : entry_parm = emit_group_move_into_temps (entry_parm);
3012 :
3013 : /* If we want the parameter in a pseudo, don't use a stack slot. */
3014 74781 : if (is_gimple_reg (parm) && use_register_for_decl (parm))
3015 : {
3016 0 : tree def = ssa_default_def (cfun, parm);
3017 0 : gcc_assert (def);
3018 0 : machine_mode mode = promote_ssa_mode (def, NULL);
3019 0 : rtx reg = gen_reg_rtx (mode);
3020 0 : if (GET_CODE (reg) != CONCAT)
3021 : stack_parm = reg;
3022 : else
3023 : {
3024 0 : target_reg = reg;
3025 : /* Avoid allocating a stack slot, if there isn't one
3026 : preallocated by the ABI. It might seem like we should
3027 : always prefer a pseudo, but converting between
3028 : floating-point and integer modes goes through the stack
3029 : on various machines, so it's better to use the reserved
3030 : stack slot than to risk wasting it and allocating more
3031 : for the conversion. */
3032 0 : if (stack_parm == NULL_RTX)
3033 : {
3034 0 : int save = generating_concat_p;
3035 0 : generating_concat_p = 0;
3036 0 : stack_parm = gen_reg_rtx (mode);
3037 0 : generating_concat_p = save;
3038 : }
3039 : }
3040 0 : data->stack_parm = NULL;
3041 : }
3042 :
3043 74781 : size = int_size_in_bytes (data->arg.type);
3044 87398 : size_stored = CEIL_ROUND (size, UNITS_PER_WORD);
3045 74781 : if (stack_parm == 0)
3046 : {
3047 5501 : HOST_WIDE_INT parm_align
3048 : = ((STRICT_ALIGNMENT || BITS_PER_WORD <= MAX_SUPPORTED_STACK_ALIGNMENT)
3049 5713 : ? MAX (DECL_ALIGN (parm), BITS_PER_WORD) : DECL_ALIGN (parm));
3050 :
3051 5501 : SET_DECL_ALIGN (parm, parm_align);
3052 5501 : stack_parm = assign_stack_local (BLKmode, size_stored,
3053 5501 : DECL_ALIGN (parm));
3054 11002 : if (known_eq (GET_MODE_SIZE (GET_MODE (entry_parm)), size))
3055 77 : PUT_MODE (stack_parm, GET_MODE (entry_parm));
3056 5501 : set_mem_attributes (stack_parm, parm, 1);
3057 : }
3058 :
3059 : /* If a BLKmode arrives in registers, copy it to a stack slot. Handle
3060 : calls that pass values in multiple non-contiguous locations. */
3061 74781 : if (REG_P (entry_parm) || GET_CODE (entry_parm) == PARALLEL)
3062 : {
3063 5198 : rtx mem;
3064 :
3065 : /* Note that we will be storing an integral number of words.
3066 : So we have to be careful to ensure that we allocate an
3067 : integral number of words. We do this above when we call
3068 : assign_stack_local if space was not allocated in the argument
3069 : list. If it was, this will not work if PARM_BOUNDARY is not
3070 : a multiple of BITS_PER_WORD. It isn't clear how to fix this
3071 : if it becomes a problem. Exception is when BLKmode arrives
3072 : with arguments not conforming to word_mode. */
3073 :
3074 5198 : if (data->stack_parm == 0)
3075 : ;
3076 5198 : else if (GET_CODE (entry_parm) == PARALLEL)
3077 : ;
3078 : else
3079 5198 : gcc_assert (!size || !(PARM_BOUNDARY % BITS_PER_WORD));
3080 :
3081 5198 : mem = validize_mem (copy_rtx (stack_parm));
3082 :
3083 : /* Handle values in multiple non-contiguous locations. */
3084 5198 : if (GET_CODE (entry_parm) == PARALLEL && !MEM_P (mem))
3085 0 : emit_group_store (mem, entry_parm, data->arg.type, size);
3086 5198 : else if (GET_CODE (entry_parm) == PARALLEL)
3087 : {
3088 3861 : push_to_sequence2 (all->first_conversion_insn,
3089 : all->last_conversion_insn);
3090 3861 : emit_group_store (mem, entry_parm, data->arg.type, size);
3091 3861 : all->first_conversion_insn = get_insns ();
3092 3861 : all->last_conversion_insn = get_last_insn ();
3093 3861 : end_sequence ();
3094 3861 : in_conversion_seq = true;
3095 : }
3096 :
3097 1337 : else if (size == 0)
3098 : ;
3099 :
3100 : /* If SIZE is that of a mode no bigger than a word, just use
3101 : that mode's store operation. */
3102 1321 : else if (size <= UNITS_PER_WORD)
3103 : {
3104 1317 : unsigned int bits = size * BITS_PER_UNIT;
3105 1317 : machine_mode mode = int_mode_for_size (bits, 0).else_blk ();
3106 :
3107 1317 : if (mode != BLKmode
3108 : #ifdef BLOCK_REG_PADDING
3109 : && (size == UNITS_PER_WORD
3110 : || (BLOCK_REG_PADDING (mode, data->arg.type, 1)
3111 : != (BYTES_BIG_ENDIAN ? PAD_UPWARD : PAD_DOWNWARD)))
3112 : #endif
3113 : )
3114 : {
3115 103 : rtx reg;
3116 :
3117 : /* We are really truncating a word_mode value containing
3118 : SIZE bytes into a value of mode MODE. If such an
3119 : operation requires no actual instructions, we can refer
3120 : to the value directly in mode MODE, otherwise we must
3121 : start with the register in word_mode and explicitly
3122 : convert it. */
3123 103 : if (mode == word_mode
3124 103 : || TRULY_NOOP_TRUNCATION_MODES_P (mode, word_mode))
3125 103 : reg = gen_rtx_REG (mode, REGNO (entry_parm));
3126 : else
3127 : {
3128 0 : reg = gen_rtx_REG (word_mode, REGNO (entry_parm));
3129 0 : reg = convert_to_mode (mode, copy_to_reg (reg), 1);
3130 : }
3131 :
3132 : /* We use adjust_address to get a new MEM with the mode
3133 : changed. adjust_address is better than change_address
3134 : for this purpose because adjust_address does not lose
3135 : the MEM_EXPR associated with the MEM.
3136 :
3137 : If the MEM_EXPR is lost, then optimizations like DSE
3138 : assume the MEM escapes and thus is not subject to DSE. */
3139 103 : emit_move_insn (adjust_address (mem, mode, 0), reg);
3140 : }
3141 :
3142 : #ifdef BLOCK_REG_PADDING
3143 : /* Storing the register in memory as a full word, as
3144 : move_block_from_reg below would do, and then using the
3145 : MEM in a smaller mode, has the effect of shifting right
3146 : if BYTES_BIG_ENDIAN. If we're bypassing memory, the
3147 : shifting must be explicit. */
3148 : else if (!MEM_P (mem))
3149 : {
3150 : rtx x;
3151 :
3152 : /* If the assert below fails, we should have taken the
3153 : mode != BLKmode path above, unless we have downward
3154 : padding of smaller-than-word arguments on a machine
3155 : with little-endian bytes, which would likely require
3156 : additional changes to work correctly. */
3157 : gcc_checking_assert (BYTES_BIG_ENDIAN
3158 : && (BLOCK_REG_PADDING (mode,
3159 : data->arg.type, 1)
3160 : == PAD_UPWARD));
3161 :
3162 : int by = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
3163 :
3164 : x = gen_rtx_REG (word_mode, REGNO (entry_parm));
3165 : x = expand_shift (RSHIFT_EXPR, word_mode, x, by,
3166 : NULL_RTX, 1);
3167 : x = force_reg (word_mode, x);
3168 : x = gen_lowpart_SUBREG (GET_MODE (mem), x);
3169 :
3170 : emit_move_insn (mem, x);
3171 : }
3172 : #endif
3173 :
3174 : /* Blocks smaller than a word on a BYTES_BIG_ENDIAN
3175 : machine must be aligned to the left before storing
3176 : to memory. Note that the previous test doesn't
3177 : handle all cases (e.g. SIZE == 3). */
3178 1214 : else if (size != UNITS_PER_WORD
3179 : #ifdef BLOCK_REG_PADDING
3180 : && (BLOCK_REG_PADDING (mode, data->arg.type, 1)
3181 : == PAD_DOWNWARD)
3182 : #else
3183 : && BYTES_BIG_ENDIAN
3184 : #endif
3185 : )
3186 : {
3187 : rtx tem, x;
3188 : int by = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
3189 : rtx reg = gen_rtx_REG (word_mode, REGNO (entry_parm));
3190 :
3191 : x = expand_shift (LSHIFT_EXPR, word_mode, reg, by, NULL_RTX, 1);
3192 : tem = change_address (mem, word_mode, 0);
3193 : emit_move_insn (tem, x);
3194 : }
3195 : else
3196 2428 : move_block_from_reg (REGNO (entry_parm), mem,
3197 1214 : size_stored / UNITS_PER_WORD);
3198 : }
3199 2 : else if (!MEM_P (mem))
3200 : {
3201 0 : gcc_checking_assert (size > UNITS_PER_WORD);
3202 : #ifdef BLOCK_REG_PADDING
3203 : gcc_checking_assert (BLOCK_REG_PADDING (GET_MODE (mem),
3204 : data->arg.type, 0)
3205 : == PAD_UPWARD);
3206 : #endif
3207 0 : emit_move_insn (mem, entry_parm);
3208 : }
3209 : else
3210 2 : move_block_from_reg (REGNO (entry_parm), mem,
3211 2 : size_stored / UNITS_PER_WORD);
3212 : }
3213 69583 : else if (data->stack_parm == 0 && !TYPE_EMPTY_P (data->arg.type))
3214 : {
3215 207 : push_to_sequence2 (all->first_conversion_insn, all->last_conversion_insn);
3216 207 : emit_block_move (stack_parm, data->entry_parm, GEN_INT (size),
3217 : BLOCK_OP_NORMAL);
3218 207 : all->first_conversion_insn = get_insns ();
3219 207 : all->last_conversion_insn = get_last_insn ();
3220 207 : end_sequence ();
3221 207 : in_conversion_seq = true;
3222 : }
3223 :
3224 74781 : if (target_reg)
3225 : {
3226 0 : if (!in_conversion_seq)
3227 0 : emit_move_insn (target_reg, stack_parm);
3228 : else
3229 : {
3230 0 : push_to_sequence2 (all->first_conversion_insn,
3231 : all->last_conversion_insn);
3232 0 : emit_move_insn (target_reg, stack_parm);
3233 0 : all->first_conversion_insn = get_insns ();
3234 0 : all->last_conversion_insn = get_last_insn ();
3235 0 : end_sequence ();
3236 : }
3237 : stack_parm = target_reg;
3238 : }
3239 :
3240 74781 : data->stack_parm = stack_parm;
3241 74781 : set_parm_rtl (parm, stack_parm);
3242 74781 : }
3243 :
3244 : /* A subroutine of assign_parms. Allocate a pseudo to hold the current
3245 : parameter. Get it there. Perform all ABI specified conversions. */
3246 :
3247 : static void
3248 2326298 : assign_parm_setup_reg (struct assign_parm_data_all *all, tree parm,
3249 : struct assign_parm_data_one *data)
3250 : {
3251 2326298 : rtx parmreg, validated_mem;
3252 2326298 : rtx equiv_stack_parm;
3253 2326298 : machine_mode promoted_nominal_mode;
3254 2326298 : int unsignedp = TYPE_UNSIGNED (TREE_TYPE (parm));
3255 2326298 : bool did_conversion = false;
3256 2326298 : bool need_conversion, moved;
3257 2326298 : enum insn_code icode;
3258 2326298 : rtx rtl;
3259 :
3260 : /* Store the parm in a pseudoregister during the function, but we may
3261 : need to do it in a wider mode. Using 2 here makes the result
3262 : consistent with promote_decl_mode and thus expand_expr_real_1. */
3263 2326298 : promoted_nominal_mode
3264 4652596 : = promote_function_mode (data->nominal_type, data->nominal_mode, &unsignedp,
3265 2326298 : TREE_TYPE (current_function_decl), 2);
3266 :
3267 2326298 : parmreg = gen_reg_rtx (promoted_nominal_mode);
3268 2326298 : if (!DECL_ARTIFICIAL (parm))
3269 2098358 : mark_user_reg (parmreg);
3270 :
3271 : /* If this was an item that we received a pointer to,
3272 : set rtl appropriately. */
3273 2326298 : if (data->arg.pass_by_reference)
3274 : {
3275 4966 : rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (data->arg.type)), parmreg);
3276 4966 : set_mem_attributes (rtl, parm, 1);
3277 : }
3278 : else
3279 : rtl = parmreg;
3280 :
3281 2326298 : assign_parm_remove_parallels (data);
3282 :
3283 : /* Copy the value into the register, thus bridging between
3284 : assign_parm_find_data_types and expand_expr_real_1. */
3285 :
3286 2326298 : equiv_stack_parm = data->stack_parm;
3287 2326298 : validated_mem = validize_mem (copy_rtx (data->entry_parm));
3288 :
3289 2326298 : need_conversion = (data->nominal_mode != data->passed_mode
3290 2326298 : || promoted_nominal_mode != data->arg.mode);
3291 4171 : moved = false;
3292 :
3293 : if (need_conversion
3294 4171 : && GET_MODE_CLASS (data->nominal_mode) == MODE_INT
3295 3660 : && data->nominal_mode == data->passed_mode
3296 0 : && data->nominal_mode == GET_MODE (data->entry_parm))
3297 : {
3298 : /* ENTRY_PARM has been converted to PROMOTED_MODE, its
3299 : mode, by the caller. We now have to convert it to
3300 : NOMINAL_MODE, if different. However, PARMREG may be in
3301 : a different mode than NOMINAL_MODE if it is being stored
3302 : promoted.
3303 :
3304 : If ENTRY_PARM is a hard register, it might be in a register
3305 : not valid for operating in its mode (e.g., an odd-numbered
3306 : register for a DFmode). In that case, moves are the only
3307 : thing valid, so we can't do a convert from there. This
3308 : occurs when the calling sequence allow such misaligned
3309 : usages.
3310 :
3311 : In addition, the conversion may involve a call, which could
3312 : clobber parameters which haven't been copied to pseudo
3313 : registers yet.
3314 :
3315 : First, we try to emit an insn which performs the necessary
3316 : conversion. We verify that this insn does not clobber any
3317 : hard registers. */
3318 :
3319 0 : rtx op0, op1;
3320 :
3321 0 : icode = can_extend_p (promoted_nominal_mode, data->passed_mode,
3322 : unsignedp);
3323 :
3324 0 : op0 = parmreg;
3325 0 : op1 = validated_mem;
3326 0 : if (icode != CODE_FOR_nothing
3327 0 : && insn_operand_matches (icode, 0, op0)
3328 0 : && insn_operand_matches (icode, 1, op1))
3329 : {
3330 0 : enum rtx_code code = unsignedp ? ZERO_EXTEND : SIGN_EXTEND;
3331 0 : rtx_insn *insn, *insns;
3332 0 : rtx t = op1;
3333 0 : HARD_REG_SET hardregs;
3334 :
3335 0 : start_sequence ();
3336 : /* If op1 is a hard register that is likely spilled, first
3337 : force it into a pseudo, otherwise combiner might extend
3338 : its lifetime too much. */
3339 0 : if (GET_CODE (t) == SUBREG)
3340 0 : t = SUBREG_REG (t);
3341 0 : if (REG_P (t)
3342 0 : && HARD_REGISTER_P (t)
3343 0 : && ! TEST_HARD_REG_BIT (fixed_reg_set, REGNO (t))
3344 0 : && targetm.class_likely_spilled_p (REGNO_REG_CLASS (REGNO (t))))
3345 : {
3346 0 : t = gen_reg_rtx (GET_MODE (op1));
3347 0 : emit_move_insn (t, op1);
3348 : }
3349 : else
3350 : t = op1;
3351 0 : rtx_insn *pat = gen_extend_insn (op0, t, promoted_nominal_mode,
3352 : data->passed_mode, unsignedp);
3353 0 : emit_insn (pat);
3354 0 : insns = get_insns ();
3355 :
3356 0 : moved = true;
3357 0 : CLEAR_HARD_REG_SET (hardregs);
3358 0 : for (insn = insns; insn && moved; insn = NEXT_INSN (insn))
3359 : {
3360 0 : if (INSN_P (insn))
3361 0 : note_stores (insn, record_hard_reg_sets, &hardregs);
3362 0 : if (!hard_reg_set_empty_p (hardregs))
3363 0 : moved = false;
3364 : }
3365 :
3366 0 : end_sequence ();
3367 :
3368 0 : if (moved)
3369 : {
3370 0 : emit_insn (insns);
3371 0 : if (equiv_stack_parm != NULL_RTX)
3372 0 : equiv_stack_parm = gen_rtx_fmt_e (code, GET_MODE (parmreg),
3373 : equiv_stack_parm);
3374 : }
3375 : }
3376 : }
3377 :
3378 0 : if (moved)
3379 : /* Nothing to do. */
3380 : ;
3381 2326298 : else if (need_conversion)
3382 : {
3383 : /* We did not have an insn to convert directly, or the sequence
3384 : generated appeared unsafe. We must first copy the parm to a
3385 : pseudo reg, and save the conversion until after all
3386 : parameters have been moved. */
3387 :
3388 4171 : int save_tree_used;
3389 4171 : rtx tempreg = gen_reg_rtx (GET_MODE (data->entry_parm));
3390 :
3391 4171 : emit_move_insn (tempreg, validated_mem);
3392 :
3393 4171 : push_to_sequence2 (all->first_conversion_insn, all->last_conversion_insn);
3394 4171 : tempreg = convert_to_mode (data->nominal_mode, tempreg, unsignedp);
3395 :
3396 4171 : if (partial_subreg_p (tempreg)
3397 3660 : && GET_MODE (tempreg) == data->nominal_mode
3398 3660 : && REG_P (SUBREG_REG (tempreg))
3399 3660 : && data->nominal_mode == data->passed_mode
3400 3660 : && GET_MODE (SUBREG_REG (tempreg)) == GET_MODE (data->entry_parm))
3401 : {
3402 : /* The argument is already sign/zero extended, so note it
3403 : into the subreg. */
3404 0 : SUBREG_PROMOTED_VAR_P (tempreg) = 1;
3405 0 : SUBREG_PROMOTED_SET (tempreg, unsignedp);
3406 : }
3407 :
3408 : /* TREE_USED gets set erroneously during expand_assignment. */
3409 4171 : save_tree_used = TREE_USED (parm);
3410 4171 : SET_DECL_RTL (parm, rtl);
3411 4171 : expand_assignment (parm, make_tree (data->nominal_type, tempreg), false);
3412 4171 : SET_DECL_RTL (parm, NULL_RTX);
3413 4171 : TREE_USED (parm) = save_tree_used;
3414 4171 : all->first_conversion_insn = get_insns ();
3415 4171 : all->last_conversion_insn = get_last_insn ();
3416 4171 : end_sequence ();
3417 :
3418 4171 : did_conversion = true;
3419 : }
3420 2322127 : else if (MEM_P (data->entry_parm)
3421 824502 : && GET_MODE_ALIGNMENT (promoted_nominal_mode)
3422 824560 : > MEM_ALIGN (data->entry_parm)
3423 2346026 : && (((icode = optab_handler (movmisalign_optab,
3424 : promoted_nominal_mode))
3425 : != CODE_FOR_nothing)
3426 23895 : || targetm.slow_unaligned_access (promoted_nominal_mode,
3427 23953 : MEM_ALIGN (data->entry_parm))))
3428 : {
3429 4 : if (icode != CODE_FOR_nothing)
3430 4 : emit_insn (GEN_FCN (icode) (parmreg, validated_mem));
3431 : else
3432 0 : rtl = parmreg = extract_bit_field (validated_mem,
3433 0 : GET_MODE_BITSIZE (promoted_nominal_mode), 0,
3434 : unsignedp, parmreg,
3435 : promoted_nominal_mode, VOIDmode, false, NULL);
3436 : }
3437 : else
3438 2322123 : emit_move_insn (parmreg, validated_mem);
3439 :
3440 : /* If we were passed a pointer but the actual value can live in a register,
3441 : retrieve it and use it directly. Note that we cannot use nominal_mode,
3442 : because it will have been set to Pmode above, we must use the actual mode
3443 : of the parameter instead. */
3444 2326298 : if (data->arg.pass_by_reference && TYPE_MODE (TREE_TYPE (parm)) != BLKmode)
3445 : {
3446 : /* Use a stack slot for debugging purposes if possible. */
3447 715 : if (use_register_for_decl (parm))
3448 : {
3449 377 : parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
3450 377 : mark_user_reg (parmreg);
3451 : }
3452 : else
3453 : {
3454 338 : int align = STACK_SLOT_ALIGNMENT (TREE_TYPE (parm),
3455 : TYPE_MODE (TREE_TYPE (parm)),
3456 : TYPE_ALIGN (TREE_TYPE (parm)));
3457 338 : parmreg
3458 338 : = assign_stack_local (TYPE_MODE (TREE_TYPE (parm)),
3459 676 : GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parm))),
3460 : align);
3461 338 : set_mem_attributes (parmreg, parm, 1);
3462 : }
3463 :
3464 : /* We need to preserve an address based on VIRTUAL_STACK_VARS_REGNUM for
3465 : the debug info in case it is not legitimate. */
3466 715 : if (GET_MODE (parmreg) != GET_MODE (rtl))
3467 : {
3468 0 : rtx tempreg = gen_reg_rtx (GET_MODE (rtl));
3469 0 : int unsigned_p = TYPE_UNSIGNED (TREE_TYPE (parm));
3470 :
3471 0 : push_to_sequence2 (all->first_conversion_insn,
3472 : all->last_conversion_insn);
3473 0 : emit_move_insn (tempreg, rtl);
3474 0 : tempreg = convert_to_mode (GET_MODE (parmreg), tempreg, unsigned_p);
3475 0 : emit_move_insn (MEM_P (parmreg) ? copy_rtx (parmreg) : parmreg,
3476 : tempreg);
3477 0 : all->first_conversion_insn = get_insns ();
3478 0 : all->last_conversion_insn = get_last_insn ();
3479 0 : end_sequence ();
3480 :
3481 0 : did_conversion = true;
3482 : }
3483 : else
3484 715 : emit_move_insn (MEM_P (parmreg) ? copy_rtx (parmreg) : parmreg, rtl);
3485 :
3486 715 : rtl = parmreg;
3487 :
3488 : /* STACK_PARM is the pointer, not the parm, and PARMREG is
3489 : now the parm. */
3490 715 : data->stack_parm = NULL;
3491 : }
3492 :
3493 2326298 : set_parm_rtl (parm, rtl);
3494 :
3495 : /* Mark the register as eliminable if we did no conversion and it was
3496 : copied from memory at a fixed offset, and the arg pointer was not
3497 : copied to a pseudo-reg. If the arg pointer is a pseudo reg or the
3498 : offset formed an invalid address, such memory-equivalences as we
3499 : make here would screw up life analysis for it. */
3500 2326298 : if (data->nominal_mode == data->passed_mode
3501 2322127 : && !did_conversion
3502 2322127 : && data->stack_parm != 0
3503 880106 : && MEM_P (data->stack_parm)
3504 880106 : && data->locate.offset.var == 0
3505 3206404 : && reg_mentioned_p (virtual_incoming_args_rtx,
3506 880106 : XEXP (data->stack_parm, 0)))
3507 : {
3508 880106 : rtx_insn *linsn = get_last_insn ();
3509 880106 : rtx_insn *sinsn;
3510 880106 : rtx set;
3511 :
3512 : /* Mark complex types separately. */
3513 880106 : if (GET_CODE (parmreg) == CONCAT)
3514 : {
3515 1071 : scalar_mode submode = GET_MODE_INNER (GET_MODE (parmreg));
3516 1071 : int regnor = REGNO (XEXP (parmreg, 0));
3517 1071 : int regnoi = REGNO (XEXP (parmreg, 1));
3518 1071 : rtx stackr = adjust_address_nv (data->stack_parm, submode, 0);
3519 2142 : rtx stacki = adjust_address_nv (data->stack_parm, submode,
3520 : GET_MODE_SIZE (submode));
3521 :
3522 : /* Scan backwards for the set of the real and
3523 : imaginary parts. */
3524 5773 : for (sinsn = linsn; sinsn != 0;
3525 4702 : sinsn = prev_nonnote_insn (sinsn))
3526 : {
3527 4702 : set = single_set (sinsn);
3528 4702 : if (set == 0)
3529 0 : continue;
3530 :
3531 4702 : if (SET_DEST (set) == regno_reg_rtx [regnoi])
3532 1071 : set_unique_reg_note (sinsn, REG_EQUIV, stacki);
3533 3631 : else if (SET_DEST (set) == regno_reg_rtx [regnor])
3534 1071 : set_unique_reg_note (sinsn, REG_EQUIV, stackr);
3535 : }
3536 : }
3537 : else
3538 879035 : set_dst_reg_note (linsn, REG_EQUIV, equiv_stack_parm, parmreg);
3539 : }
3540 :
3541 : /* For pointer data type, suggest pointer register. */
3542 2326298 : if (POINTER_TYPE_P (TREE_TYPE (parm)))
3543 954779 : mark_reg_pointer (parmreg,
3544 954779 : TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm))));
3545 2326298 : }
3546 :
3547 : /* A subroutine of assign_parms. Allocate stack space to hold the current
3548 : parameter. Get it there. Perform all ABI specified conversions. */
3549 :
3550 : static void
3551 852545 : assign_parm_setup_stack (struct assign_parm_data_all *all, tree parm,
3552 : struct assign_parm_data_one *data)
3553 : {
3554 : /* Value must be stored in the stack slot STACK_PARM during function
3555 : execution. */
3556 852545 : bool to_conversion = false;
3557 :
3558 852545 : assign_parm_remove_parallels (data);
3559 :
3560 852545 : if (data->arg.mode != data->nominal_mode)
3561 : {
3562 : /* Conversion is required. */
3563 835 : rtx tempreg = gen_reg_rtx (GET_MODE (data->entry_parm));
3564 :
3565 835 : emit_move_insn (tempreg, validize_mem (copy_rtx (data->entry_parm)));
3566 :
3567 : /* Some ABIs require scalar floating point modes to be passed
3568 : in a wider scalar integer mode. We need to explicitly
3569 : truncate to an integer mode of the correct precision before
3570 : using a SUBREG to reinterpret as a floating point value. */
3571 835 : if (SCALAR_FLOAT_MODE_P (data->nominal_mode)
3572 101 : && SCALAR_INT_MODE_P (data->arg.mode)
3573 835 : && known_lt (GET_MODE_SIZE (data->nominal_mode),
3574 : GET_MODE_SIZE (data->arg.mode)))
3575 0 : tempreg = convert_wider_int_to_float (data->nominal_mode,
3576 : data->arg.mode, tempreg);
3577 :
3578 835 : push_to_sequence2 (all->first_conversion_insn, all->last_conversion_insn);
3579 835 : to_conversion = true;
3580 :
3581 2505 : data->entry_parm = convert_to_mode (data->nominal_mode, tempreg,
3582 835 : TYPE_UNSIGNED (TREE_TYPE (parm)));
3583 :
3584 835 : if (data->stack_parm)
3585 : {
3586 0 : poly_int64 offset
3587 0 : = subreg_lowpart_offset (data->nominal_mode,
3588 0 : GET_MODE (data->stack_parm));
3589 : /* ??? This may need a big-endian conversion on sparc64. */
3590 0 : data->stack_parm
3591 0 : = adjust_address (data->stack_parm, data->nominal_mode, 0);
3592 0 : if (maybe_ne (offset, 0) && MEM_OFFSET_KNOWN_P (data->stack_parm))
3593 0 : set_mem_offset (data->stack_parm,
3594 0 : MEM_OFFSET (data->stack_parm) + offset);
3595 : }
3596 : }
3597 :
3598 852545 : if (data->entry_parm != data->stack_parm)
3599 : {
3600 674365 : rtx src, dest;
3601 :
3602 674365 : if (data->stack_parm == 0)
3603 : {
3604 624578 : int align = STACK_SLOT_ALIGNMENT (data->arg.type,
3605 : GET_MODE (data->entry_parm),
3606 : TYPE_ALIGN (data->arg.type));
3607 624578 : if (align < (int)GET_MODE_ALIGNMENT (GET_MODE (data->entry_parm))
3608 627228 : && ((optab_handler (movmisalign_optab,
3609 2650 : GET_MODE (data->entry_parm))
3610 : != CODE_FOR_nothing)
3611 2650 : || targetm.slow_unaligned_access (GET_MODE (data->entry_parm),
3612 : align)))
3613 0 : align = GET_MODE_ALIGNMENT (GET_MODE (data->entry_parm));
3614 624578 : data->stack_parm
3615 624578 : = assign_stack_local (GET_MODE (data->entry_parm),
3616 1249156 : GET_MODE_SIZE (GET_MODE (data->entry_parm)),
3617 : align);
3618 624578 : align = MEM_ALIGN (data->stack_parm);
3619 624578 : set_mem_attributes (data->stack_parm, parm, 1);
3620 624578 : set_mem_align (data->stack_parm, align);
3621 : }
3622 :
3623 674365 : dest = validize_mem (copy_rtx (data->stack_parm));
3624 674365 : src = validize_mem (copy_rtx (data->entry_parm));
3625 :
3626 674365 : if (TYPE_EMPTY_P (data->arg.type))
3627 : /* Empty types don't really need to be copied. */;
3628 672817 : else if (MEM_P (src))
3629 : {
3630 : /* Use a block move to handle potentially misaligned entry_parm. */
3631 63 : if (!to_conversion)
3632 63 : push_to_sequence2 (all->first_conversion_insn,
3633 : all->last_conversion_insn);
3634 63 : to_conversion = true;
3635 :
3636 63 : emit_block_move (dest, src,
3637 63 : GEN_INT (int_size_in_bytes (data->arg.type)),
3638 : BLOCK_OP_NORMAL);
3639 : }
3640 : else
3641 : {
3642 672754 : if (!REG_P (src))
3643 1829 : src = force_reg (GET_MODE (src), src);
3644 672754 : emit_move_insn (dest, src);
3645 : }
3646 : }
3647 :
3648 852545 : if (to_conversion)
3649 : {
3650 898 : all->first_conversion_insn = get_insns ();
3651 898 : all->last_conversion_insn = get_last_insn ();
3652 898 : end_sequence ();
3653 : }
3654 :
3655 852545 : set_parm_rtl (parm, data->stack_parm);
3656 852545 : }
3657 :
3658 : /* A subroutine of assign_parms. If the ABI splits complex arguments, then
3659 : undo the frobbing that we did in assign_parms_augmented_arg_list. */
3660 :
3661 : static void
3662 0 : assign_parms_unsplit_complex (struct assign_parm_data_all *all,
3663 : vec<tree> fnargs)
3664 : {
3665 0 : tree parm;
3666 0 : tree orig_fnargs = all->orig_fnargs;
3667 0 : unsigned i = 0;
3668 :
3669 0 : for (parm = orig_fnargs; parm; parm = TREE_CHAIN (parm), ++i)
3670 : {
3671 0 : if (TREE_CODE (TREE_TYPE (parm)) == COMPLEX_TYPE
3672 0 : && targetm.calls.split_complex_arg (TREE_TYPE (parm)))
3673 : {
3674 0 : rtx tmp, real, imag;
3675 0 : scalar_mode inner = GET_MODE_INNER (DECL_MODE (parm));
3676 :
3677 0 : real = DECL_RTL (fnargs[i]);
3678 0 : imag = DECL_RTL (fnargs[i + 1]);
3679 0 : if (inner != GET_MODE (real))
3680 : {
3681 0 : real = gen_lowpart_SUBREG (inner, real);
3682 0 : imag = gen_lowpart_SUBREG (inner, imag);
3683 : }
3684 :
3685 0 : if (TREE_ADDRESSABLE (parm))
3686 : {
3687 0 : rtx rmem, imem;
3688 0 : HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (parm));
3689 0 : int align = STACK_SLOT_ALIGNMENT (TREE_TYPE (parm),
3690 : DECL_MODE (parm),
3691 : TYPE_ALIGN (TREE_TYPE (parm)));
3692 :
3693 : /* split_complex_arg put the real and imag parts in
3694 : pseudos. Move them to memory. */
3695 0 : tmp = assign_stack_local (DECL_MODE (parm), size, align);
3696 0 : set_mem_attributes (tmp, parm, 1);
3697 0 : rmem = adjust_address_nv (tmp, inner, 0);
3698 0 : imem = adjust_address_nv (tmp, inner, GET_MODE_SIZE (inner));
3699 0 : push_to_sequence2 (all->first_conversion_insn,
3700 : all->last_conversion_insn);
3701 0 : emit_move_insn (rmem, real);
3702 0 : emit_move_insn (imem, imag);
3703 0 : all->first_conversion_insn = get_insns ();
3704 0 : all->last_conversion_insn = get_last_insn ();
3705 0 : end_sequence ();
3706 : }
3707 : else
3708 0 : tmp = gen_rtx_CONCAT (DECL_MODE (parm), real, imag);
3709 0 : set_parm_rtl (parm, tmp);
3710 :
3711 0 : real = DECL_INCOMING_RTL (fnargs[i]);
3712 0 : imag = DECL_INCOMING_RTL (fnargs[i + 1]);
3713 0 : if (inner != GET_MODE (real))
3714 : {
3715 0 : real = gen_lowpart_SUBREG (inner, real);
3716 0 : imag = gen_lowpart_SUBREG (inner, imag);
3717 : }
3718 0 : tmp = gen_rtx_CONCAT (DECL_MODE (parm), real, imag);
3719 0 : set_decl_incoming_rtl (parm, tmp, false);
3720 0 : i++;
3721 : }
3722 : }
3723 0 : }
3724 :
3725 : /* Assign RTL expressions to the function's parameters. This may involve
3726 : copying them into registers and using those registers as the DECL_RTL. */
3727 :
3728 : static void
3729 1531890 : assign_parms (tree fndecl)
3730 : {
3731 1531890 : struct assign_parm_data_all all;
3732 1531890 : tree parm;
3733 1531890 : vec<tree> fnargs;
3734 1531890 : unsigned i;
3735 :
3736 1531890 : crtl->args.internal_arg_pointer
3737 1531890 : = targetm.calls.internal_arg_pointer ();
3738 :
3739 1531890 : assign_parms_initialize_all (&all);
3740 1531890 : fnargs = assign_parms_augmented_arg_list (&all);
3741 :
3742 1531890 : if (TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (fndecl))
3743 1531890 : && fnargs.is_empty ())
3744 : {
3745 114 : struct assign_parm_data_one data = {};
3746 114 : assign_parms_setup_varargs (&all, &data, false);
3747 : }
3748 :
3749 4785514 : FOR_EACH_VEC_ELT (fnargs, i, parm)
3750 : {
3751 3253624 : struct assign_parm_data_one data;
3752 :
3753 : /* Extract the type of PARM; adjust it according to ABI. */
3754 3253624 : assign_parm_find_data_types (&all, parm, &data);
3755 :
3756 : /* Early out for errors and void parameters. */
3757 3253624 : if (data.passed_mode == VOIDmode)
3758 : {
3759 0 : SET_DECL_RTL (parm, const0_rtx);
3760 0 : DECL_INCOMING_RTL (parm) = DECL_RTL (parm);
3761 0 : continue;
3762 : }
3763 :
3764 : /* Estimate stack alignment from parameter alignment. */
3765 3253624 : if (SUPPORTS_STACK_ALIGNMENT)
3766 : {
3767 3253624 : unsigned int align
3768 6507248 : = targetm.calls.function_arg_boundary (data.arg.mode,
3769 3253624 : data.arg.type);
3770 3253624 : align = MINIMUM_ALIGNMENT (data.arg.type, data.arg.mode, align);
3771 3253624 : if (TYPE_ALIGN (data.nominal_type) > align)
3772 4738 : align = MINIMUM_ALIGNMENT (data.nominal_type,
3773 : TYPE_MODE (data.nominal_type),
3774 : TYPE_ALIGN (data.nominal_type));
3775 3253624 : if (crtl->stack_alignment_estimated < align)
3776 : {
3777 370976 : gcc_assert (!crtl->stack_realign_processed);
3778 370976 : crtl->stack_alignment_estimated = align;
3779 : }
3780 : }
3781 :
3782 : /* Find out where the parameter arrives in this function. */
3783 3253624 : assign_parm_find_entry_rtl (&all, &data);
3784 :
3785 : /* Find out where stack space for this parameter might be. */
3786 3253624 : if (assign_parm_is_stack_parm (&all, &data))
3787 : {
3788 1184134 : assign_parm_find_stack_rtl (parm, &data);
3789 1184134 : assign_parm_adjust_entry_rtl (&data);
3790 : /* For arguments that occupy no space in the parameter
3791 : passing area, have non-zero size and have address taken,
3792 : force creation of a stack slot so that they have distinct
3793 : address from other parameters. */
3794 1184134 : if (TYPE_EMPTY_P (data.arg.type)
3795 6919 : && TREE_ADDRESSABLE (parm)
3796 1712 : && data.entry_parm == data.stack_parm
3797 1712 : && MEM_P (data.entry_parm)
3798 1185846 : && int_size_in_bytes (data.arg.type))
3799 1544 : data.stack_parm = NULL_RTX;
3800 : }
3801 : /* Record permanently how this parm was passed. */
3802 3253624 : if (data.arg.pass_by_reference)
3803 : {
3804 4966 : rtx incoming_rtl
3805 4966 : = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (data.arg.type)),
3806 : data.entry_parm);
3807 4966 : set_decl_incoming_rtl (parm, incoming_rtl, true);
3808 : }
3809 : else
3810 3248658 : set_decl_incoming_rtl (parm, data.entry_parm, false);
3811 :
3812 3253624 : assign_parm_adjust_stack_rtl (parm, &data);
3813 :
3814 3253624 : if (assign_parm_setup_block_p (&data))
3815 74781 : assign_parm_setup_block (&all, parm, &data);
3816 3178843 : else if (data.arg.pass_by_reference || use_register_for_decl (parm))
3817 2326298 : assign_parm_setup_reg (&all, parm, &data);
3818 : else
3819 852545 : assign_parm_setup_stack (&all, parm, &data);
3820 :
3821 3253624 : if (cfun->stdarg && !DECL_CHAIN (parm))
3822 21513 : assign_parms_setup_varargs (&all, &data, false);
3823 :
3824 : /* Update info on where next arg arrives in registers. */
3825 3253624 : targetm.calls.function_arg_advance (all.args_so_far, data.arg);
3826 : }
3827 :
3828 1531890 : if (targetm.calls.split_complex_arg)
3829 0 : assign_parms_unsplit_complex (&all, fnargs);
3830 :
3831 1531890 : fnargs.release ();
3832 :
3833 : /* Output all parameter conversion instructions (possibly including calls)
3834 : now that all parameters have been copied out of hard registers. */
3835 1531890 : emit_insn (all.first_conversion_insn);
3836 :
3837 1531890 : do_pending_stack_adjust ();
3838 :
3839 : /* Estimate reload stack alignment from scalar return mode. */
3840 1531890 : if (SUPPORTS_STACK_ALIGNMENT)
3841 : {
3842 1531890 : if (DECL_RESULT (fndecl))
3843 : {
3844 1531890 : tree type = TREE_TYPE (DECL_RESULT (fndecl));
3845 1531890 : machine_mode mode = TYPE_MODE (type);
3846 :
3847 1531890 : if (mode != BLKmode
3848 1479941 : && mode != VOIDmode
3849 762224 : && !AGGREGATE_TYPE_P (type))
3850 : {
3851 699426 : unsigned int align = GET_MODE_ALIGNMENT (mode);
3852 699426 : if (crtl->stack_alignment_estimated < align)
3853 : {
3854 10 : gcc_assert (!crtl->stack_realign_processed);
3855 10 : crtl->stack_alignment_estimated = align;
3856 : }
3857 : }
3858 : }
3859 : }
3860 :
3861 : /* If we are receiving a struct value address as the first argument, set up
3862 : the RTL for the function result. As this might require code to convert
3863 : the transmitted address to Pmode, we do this here to ensure that possible
3864 : preliminary conversions of the address have been emitted already. */
3865 1531890 : if (all.function_result_decl)
3866 : {
3867 70283 : tree result = DECL_RESULT (current_function_decl);
3868 70283 : rtx addr = DECL_RTL (all.function_result_decl);
3869 70283 : rtx x;
3870 :
3871 70283 : if (DECL_BY_REFERENCE (result))
3872 : {
3873 9002 : SET_DECL_VALUE_EXPR (result, all.function_result_decl);
3874 9002 : x = addr;
3875 : }
3876 : else
3877 : {
3878 61281 : SET_DECL_VALUE_EXPR (result,
3879 : build1 (INDIRECT_REF, TREE_TYPE (result),
3880 : all.function_result_decl));
3881 88099 : addr = convert_memory_address (Pmode, addr);
3882 61281 : x = gen_rtx_MEM (DECL_MODE (result), addr);
3883 61281 : set_mem_attributes (x, result, 1);
3884 : }
3885 :
3886 70283 : DECL_HAS_VALUE_EXPR_P (result) = 1;
3887 :
3888 70283 : set_parm_rtl (result, x);
3889 : }
3890 :
3891 : /* We have aligned all the args, so add space for the pretend args. */
3892 1531890 : crtl->args.pretend_args_size = all.pretend_args_size;
3893 1531890 : all.stack_args_size.constant += all.extra_pretend_bytes;
3894 1531890 : crtl->args.size = all.stack_args_size.constant;
3895 :
3896 : /* Adjust function incoming argument size for alignment and
3897 : minimum length. */
3898 :
3899 1531890 : crtl->args.size = upper_bound (crtl->args.size, all.reg_parm_stack_space);
3900 3063780 : crtl->args.size = aligned_upper_bound (crtl->args.size,
3901 1531890 : PARM_BOUNDARY / BITS_PER_UNIT);
3902 :
3903 1531890 : if (ARGS_GROW_DOWNWARD)
3904 : {
3905 : crtl->args.arg_offset_rtx
3906 : = (all.stack_args_size.var == 0
3907 : ? gen_int_mode (-all.stack_args_size.constant, Pmode)
3908 : : expand_expr (size_diffop (all.stack_args_size.var,
3909 : size_int (-all.stack_args_size.constant)),
3910 : NULL_RTX, VOIDmode, EXPAND_NORMAL));
3911 : }
3912 : else
3913 1658721 : crtl->args.arg_offset_rtx = ARGS_SIZE_RTX (all.stack_args_size);
3914 :
3915 : /* See how many bytes, if any, of its args a function should try to pop
3916 : on return. */
3917 :
3918 1531890 : crtl->args.pops_args = targetm.calls.return_pops_args (fndecl,
3919 1531890 : TREE_TYPE (fndecl),
3920 : crtl->args.size);
3921 :
3922 : /* For stdarg.h function, save info about
3923 : regs and stack space used by the named args. */
3924 :
3925 1531890 : crtl->args.info = all.args_so_far_v;
3926 :
3927 : /* Set the rtx used for the function return value. Put this in its
3928 : own variable so any optimizers that need this information don't have
3929 : to include tree.h. Do this here so it gets done when an inlined
3930 : function gets output. */
3931 :
3932 1531890 : crtl->return_rtx
3933 1531890 : = (DECL_RTL_SET_P (DECL_RESULT (fndecl))
3934 2346063 : ? DECL_RTL (DECL_RESULT (fndecl)) : NULL_RTX);
3935 :
3936 : /* If scalar return value was computed in a pseudo-reg, or was a named
3937 : return value that got dumped to the stack, copy that to the hard
3938 : return register. */
3939 1531890 : if (DECL_RTL_SET_P (DECL_RESULT (fndecl)))
3940 : {
3941 814173 : tree decl_result = DECL_RESULT (fndecl);
3942 814173 : rtx decl_rtl = DECL_RTL (decl_result);
3943 :
3944 814173 : if (REG_P (decl_rtl)
3945 814173 : ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
3946 68268 : : DECL_REGISTER (decl_result))
3947 : {
3948 750934 : rtx real_decl_rtl;
3949 :
3950 : /* Unless the psABI says not to. */
3951 750934 : if (TYPE_EMPTY_P (TREE_TYPE (decl_result)))
3952 : real_decl_rtl = NULL_RTX;
3953 : else
3954 : {
3955 745794 : real_decl_rtl
3956 745794 : = targetm.calls.function_value (TREE_TYPE (decl_result),
3957 : fndecl, true);
3958 745794 : REG_FUNCTION_VALUE_P (real_decl_rtl) = 1;
3959 : }
3960 : /* The delay slot scheduler assumes that crtl->return_rtx
3961 : holds the hard register containing the return value, not a
3962 : temporary pseudo. */
3963 750934 : crtl->return_rtx = real_decl_rtl;
3964 : }
3965 : }
3966 1531890 : }
3967 :
3968 : /* Gimplify the parameter list for current_function_decl. This involves
3969 : evaluating SAVE_EXPRs of variable sized parameters and generating code
3970 : to implement callee-copies reference parameters. Returns a sequence of
3971 : statements to add to the beginning of the function. */
3972 :
3973 : gimple_seq
3974 3020016 : gimplify_parameters (gimple_seq *cleanup)
3975 : {
3976 3020016 : struct assign_parm_data_all all;
3977 3020016 : tree parm;
3978 3020016 : gimple_seq stmts = NULL;
3979 3020016 : vec<tree> fnargs;
3980 3020016 : unsigned i;
3981 :
3982 3020016 : assign_parms_initialize_all (&all);
3983 3020016 : fnargs = assign_parms_augmented_arg_list (&all);
3984 :
3985 12253548 : FOR_EACH_VEC_ELT (fnargs, i, parm)
3986 : {
3987 6213516 : struct assign_parm_data_one data;
3988 :
3989 : /* Extract the type of PARM; adjust it according to ABI. */
3990 6213516 : assign_parm_find_data_types (&all, parm, &data);
3991 :
3992 : /* Early out for errors and void parameters. */
3993 6213516 : if (data.passed_mode == VOIDmode || DECL_SIZE (parm) == NULL)
3994 93 : continue;
3995 :
3996 : /* Update info on where next arg arrives in registers. */
3997 6213423 : targetm.calls.function_arg_advance (all.args_so_far, data.arg);
3998 :
3999 : /* ??? Once upon a time variable_size stuffed parameter list
4000 : SAVE_EXPRs (amongst others) onto a pending sizes list. This
4001 : turned out to be less than manageable in the gimple world.
4002 : Now we have to hunt them down ourselves. */
4003 6213423 : gimplify_type_sizes (TREE_TYPE (parm), &stmts);
4004 :
4005 6213423 : if (TREE_CODE (DECL_SIZE_UNIT (parm)) != INTEGER_CST)
4006 : {
4007 41 : gimplify_one_sizepos (&DECL_SIZE (parm), &stmts);
4008 41 : gimplify_one_sizepos (&DECL_SIZE_UNIT (parm), &stmts);
4009 : }
4010 :
4011 6213423 : if (data.arg.pass_by_reference)
4012 : {
4013 4974 : tree type = TREE_TYPE (data.arg.type);
4014 4974 : function_arg_info orig_arg (type, data.arg.named);
4015 4974 : if (reference_callee_copied (&all.args_so_far_v, orig_arg))
4016 : {
4017 0 : tree local, t;
4018 :
4019 : /* For constant-sized objects, this is trivial; for
4020 : variable-sized objects, we have to play games. */
4021 0 : if (TREE_CODE (DECL_SIZE_UNIT (parm)) == INTEGER_CST
4022 0 : && !(flag_stack_check == GENERIC_STACK_CHECK
4023 0 : && compare_tree_int (DECL_SIZE_UNIT (parm),
4024 : STACK_CHECK_MAX_VAR_SIZE) > 0))
4025 : {
4026 0 : local = create_tmp_var (type, get_name (parm));
4027 0 : DECL_IGNORED_P (local) = 0;
4028 : /* If PARM was addressable, move that flag over
4029 : to the local copy, as its address will be taken,
4030 : not the PARMs. Keep the parms address taken
4031 : as we'll query that flag during gimplification. */
4032 0 : if (TREE_ADDRESSABLE (parm))
4033 0 : TREE_ADDRESSABLE (local) = 1;
4034 0 : if (DECL_NOT_GIMPLE_REG_P (parm))
4035 0 : DECL_NOT_GIMPLE_REG_P (local) = 1;
4036 :
4037 0 : if (!is_gimple_reg (local)
4038 0 : && flag_stack_reuse != SR_NONE)
4039 : {
4040 0 : tree clobber = build_clobber (type);
4041 0 : gimple *clobber_stmt;
4042 0 : clobber_stmt = gimple_build_assign (local, clobber);
4043 0 : gimple_seq_add_stmt (cleanup, clobber_stmt);
4044 : }
4045 : }
4046 : else
4047 : {
4048 0 : tree ptr_type, addr;
4049 :
4050 0 : ptr_type = build_pointer_type (type);
4051 0 : addr = create_tmp_reg (ptr_type, get_name (parm));
4052 0 : DECL_IGNORED_P (addr) = 0;
4053 0 : local = build_fold_indirect_ref (addr);
4054 :
4055 0 : t = build_alloca_call_expr (DECL_SIZE_UNIT (parm),
4056 0 : DECL_ALIGN (parm),
4057 : max_int_size_in_bytes (type));
4058 : /* The call has been built for a variable-sized object. */
4059 0 : CALL_ALLOCA_FOR_VAR_P (t) = 1;
4060 0 : t = fold_convert (ptr_type, t);
4061 0 : t = build2 (MODIFY_EXPR, TREE_TYPE (addr), addr, t);
4062 0 : gimplify_and_add (t, &stmts);
4063 : }
4064 :
4065 0 : gimplify_assign (local, parm, &stmts);
4066 :
4067 0 : SET_DECL_VALUE_EXPR (parm, local);
4068 0 : DECL_HAS_VALUE_EXPR_P (parm) = 1;
4069 : }
4070 : }
4071 : }
4072 :
4073 3020016 : fnargs.release ();
4074 :
4075 3020016 : return stmts;
4076 : }
4077 :
4078 : /* Compute the size and offset from the start of the stacked arguments for a
4079 : parm passed in mode PASSED_MODE and with type TYPE.
4080 :
4081 : INITIAL_OFFSET_PTR points to the current offset into the stacked
4082 : arguments.
4083 :
4084 : The starting offset and size for this parm are returned in
4085 : LOCATE->OFFSET and LOCATE->SIZE, respectively. When IN_REGS is
4086 : nonzero, the offset is that of stack slot, which is returned in
4087 : LOCATE->SLOT_OFFSET. LOCATE->ALIGNMENT_PAD is the amount of
4088 : padding required from the initial offset ptr to the stack slot.
4089 :
4090 : IN_REGS is nonzero if the argument will be passed in registers. It will
4091 : never be set if REG_PARM_STACK_SPACE is not defined.
4092 :
4093 : REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
4094 : for arguments which are passed in registers.
4095 :
4096 : FNDECL is the function in which the argument was defined.
4097 :
4098 : There are two types of rounding that are done. The first, controlled by
4099 : TARGET_FUNCTION_ARG_BOUNDARY, forces the offset from the start of the
4100 : argument list to be aligned to the specific boundary (in bits). This
4101 : rounding affects the initial and starting offsets, but not the argument
4102 : size.
4103 :
4104 : The second, controlled by TARGET_FUNCTION_ARG_PADDING and PARM_BOUNDARY,
4105 : optionally rounds the size of the parm to PARM_BOUNDARY. The
4106 : initial offset is not affected by this rounding, while the size always
4107 : is and the starting offset may be. */
4108 :
4109 : /* LOCATE->OFFSET will be negative for ARGS_GROW_DOWNWARD case;
4110 : INITIAL_OFFSET_PTR is positive because locate_and_pad_parm's
4111 : callers pass in the total size of args so far as
4112 : INITIAL_OFFSET_PTR. LOCATE->SIZE is always positive. */
4113 :
4114 : void
4115 5520147 : locate_and_pad_parm (machine_mode passed_mode, tree type, int in_regs,
4116 : int reg_parm_stack_space, int partial,
4117 : tree fndecl ATTRIBUTE_UNUSED,
4118 : struct args_size *initial_offset_ptr,
4119 : struct locate_and_pad_arg_data *locate)
4120 : {
4121 5520147 : tree sizetree;
4122 5520147 : pad_direction where_pad;
4123 5520147 : unsigned int boundary, round_boundary;
4124 5520147 : int part_size_in_regs;
4125 :
4126 : /* If we have found a stack parm before we reach the end of the
4127 : area reserved for registers, skip that area. */
4128 5520147 : if (! in_regs)
4129 : {
4130 3274138 : if (reg_parm_stack_space > 0)
4131 : {
4132 83845 : if (initial_offset_ptr->var
4133 83845 : || !ordered_p (initial_offset_ptr->constant,
4134 : reg_parm_stack_space))
4135 : {
4136 0 : initial_offset_ptr->var
4137 0 : = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
4138 : ssize_int (reg_parm_stack_space));
4139 0 : initial_offset_ptr->constant = 0;
4140 : }
4141 : else
4142 83845 : initial_offset_ptr->constant
4143 83845 : = ordered_max (initial_offset_ptr->constant,
4144 : reg_parm_stack_space);
4145 : }
4146 : }
4147 :
4148 5520147 : part_size_in_regs = (reg_parm_stack_space == 0 ? partial : 0);
4149 :
4150 5520147 : sizetree = (type
4151 5520147 : ? arg_size_in_bytes (type)
4152 38063 : : size_int (GET_MODE_SIZE (passed_mode)));
4153 5520147 : where_pad = targetm.calls.function_arg_padding (passed_mode, type);
4154 5520147 : boundary = targetm.calls.function_arg_boundary (passed_mode, type);
4155 5520147 : round_boundary = targetm.calls.function_arg_round_boundary (passed_mode,
4156 : type);
4157 5520147 : locate->where_pad = where_pad;
4158 :
4159 : /* Alignment can't exceed MAX_SUPPORTED_STACK_ALIGNMENT. */
4160 5520147 : if (boundary > MAX_SUPPORTED_STACK_ALIGNMENT)
4161 : boundary = MAX_SUPPORTED_STACK_ALIGNMENT;
4162 :
4163 5520147 : locate->boundary = boundary;
4164 :
4165 5520147 : if (SUPPORTS_STACK_ALIGNMENT)
4166 : {
4167 : /* stack_alignment_estimated can't change after stack has been
4168 : realigned. */
4169 5520147 : if (crtl->stack_alignment_estimated < boundary)
4170 : {
4171 5133 : if (!crtl->stack_realign_processed)
4172 5133 : crtl->stack_alignment_estimated = boundary;
4173 : else
4174 : {
4175 : /* If stack is realigned and stack alignment value
4176 : hasn't been finalized, it is OK not to increase
4177 : stack_alignment_estimated. The bigger alignment
4178 : requirement is recorded in stack_alignment_needed
4179 : below. */
4180 0 : gcc_assert (!crtl->stack_realign_finalized
4181 : && crtl->stack_realign_needed);
4182 : }
4183 : }
4184 : }
4185 :
4186 5520147 : if (ARGS_GROW_DOWNWARD)
4187 : {
4188 : locate->slot_offset.constant = -initial_offset_ptr->constant;
4189 : if (initial_offset_ptr->var)
4190 : locate->slot_offset.var = size_binop (MINUS_EXPR, ssize_int (0),
4191 : initial_offset_ptr->var);
4192 :
4193 : {
4194 : tree s2 = sizetree;
4195 : if (where_pad != PAD_NONE
4196 : && (!tree_fits_uhwi_p (sizetree)
4197 : || (tree_to_uhwi (sizetree) * BITS_PER_UNIT) % round_boundary))
4198 : s2 = round_up (s2, round_boundary / BITS_PER_UNIT);
4199 : SUB_PARM_SIZE (locate->slot_offset, s2);
4200 : }
4201 :
4202 : locate->slot_offset.constant += part_size_in_regs;
4203 :
4204 : if (!in_regs || reg_parm_stack_space > 0)
4205 : pad_to_arg_alignment (&locate->slot_offset, boundary,
4206 : &locate->alignment_pad);
4207 :
4208 : locate->size.constant = (-initial_offset_ptr->constant
4209 : - locate->slot_offset.constant);
4210 : if (initial_offset_ptr->var)
4211 : locate->size.var = size_binop (MINUS_EXPR,
4212 : size_binop (MINUS_EXPR,
4213 : ssize_int (0),
4214 : initial_offset_ptr->var),
4215 : locate->slot_offset.var);
4216 :
4217 : /* Pad_below needs the pre-rounded size to know how much to pad
4218 : below. */
4219 : locate->offset = locate->slot_offset;
4220 : if (where_pad == PAD_DOWNWARD)
4221 : pad_below (&locate->offset, passed_mode, sizetree);
4222 :
4223 : }
4224 : else
4225 : {
4226 5520147 : if (!in_regs || reg_parm_stack_space > 0)
4227 3450657 : pad_to_arg_alignment (initial_offset_ptr, boundary,
4228 : &locate->alignment_pad);
4229 5520147 : locate->slot_offset = *initial_offset_ptr;
4230 :
4231 : #ifdef PUSH_ROUNDING
4232 5520147 : if (passed_mode != BLKmode)
4233 5173433 : sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
4234 : #endif
4235 :
4236 : /* Pad_below needs the pre-rounded size to know how much to pad below
4237 : so this must be done before rounding up. */
4238 5520147 : locate->offset = locate->slot_offset;
4239 5520147 : if (where_pad == PAD_DOWNWARD)
4240 0 : pad_below (&locate->offset, passed_mode, sizetree);
4241 :
4242 5520147 : if (where_pad != PAD_NONE
4243 5520147 : && (!tree_fits_uhwi_p (sizetree)
4244 5520147 : || (tree_to_uhwi (sizetree) * BITS_PER_UNIT) % round_boundary))
4245 18598 : sizetree = round_up (sizetree, round_boundary / BITS_PER_UNIT);
4246 :
4247 5520147 : ADD_PARM_SIZE (locate->size, sizetree);
4248 :
4249 5520147 : locate->size.constant -= part_size_in_regs;
4250 : }
4251 :
4252 5520147 : locate->offset.constant
4253 5520147 : += targetm.calls.function_arg_offset (passed_mode, type);
4254 5520147 : }
4255 :
4256 : /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
4257 : BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
4258 :
4259 : static void
4260 3450657 : pad_to_arg_alignment (struct args_size *offset_ptr, int boundary,
4261 : struct args_size *alignment_pad)
4262 : {
4263 3450657 : tree save_var = NULL_TREE;
4264 3450657 : poly_int64 save_constant = 0;
4265 3450657 : int boundary_in_bytes = boundary / BITS_PER_UNIT;
4266 3450657 : poly_int64 sp_offset = STACK_POINTER_OFFSET;
4267 :
4268 : #ifdef SPARC_STACK_BOUNDARY_HACK
4269 : /* ??? The SPARC port may claim a STACK_BOUNDARY higher than
4270 : the real alignment of %sp. However, when it does this, the
4271 : alignment of %sp+STACK_POINTER_OFFSET is STACK_BOUNDARY. */
4272 : if (SPARC_STACK_BOUNDARY_HACK)
4273 : sp_offset = 0;
4274 : #endif
4275 :
4276 5217707 : if (boundary > PARM_BOUNDARY)
4277 : {
4278 141949 : save_var = offset_ptr->var;
4279 141949 : save_constant = offset_ptr->constant;
4280 : }
4281 :
4282 3450657 : alignment_pad->var = NULL_TREE;
4283 3450657 : alignment_pad->constant = 0;
4284 :
4285 3450657 : if (boundary > BITS_PER_UNIT)
4286 : {
4287 3450657 : int misalign;
4288 3450657 : if (offset_ptr->var
4289 3450657 : || !known_misalignment (offset_ptr->constant + sp_offset,
4290 : boundary_in_bytes, &misalign))
4291 : {
4292 0 : tree sp_offset_tree = ssize_int (sp_offset);
4293 0 : tree offset = size_binop (PLUS_EXPR,
4294 : ARGS_SIZE_TREE (*offset_ptr),
4295 : sp_offset_tree);
4296 0 : tree rounded;
4297 0 : if (ARGS_GROW_DOWNWARD)
4298 : rounded = round_down (offset, boundary / BITS_PER_UNIT);
4299 : else
4300 0 : rounded = round_up (offset, boundary / BITS_PER_UNIT);
4301 :
4302 0 : offset_ptr->var = size_binop (MINUS_EXPR, rounded, sp_offset_tree);
4303 : /* ARGS_SIZE_TREE includes constant term. */
4304 0 : offset_ptr->constant = 0;
4305 0 : if (boundary > PARM_BOUNDARY)
4306 0 : alignment_pad->var = size_binop (MINUS_EXPR, offset_ptr->var,
4307 : save_var);
4308 : }
4309 : else
4310 : {
4311 3450657 : if (ARGS_GROW_DOWNWARD)
4312 : offset_ptr->constant -= misalign;
4313 : else
4314 3450657 : offset_ptr->constant += -misalign & (boundary_in_bytes - 1);
4315 :
4316 3450657 : if (boundary > PARM_BOUNDARY)
4317 141949 : alignment_pad->constant = offset_ptr->constant - save_constant;
4318 : }
4319 : }
4320 3450657 : }
4321 :
4322 : static void
4323 0 : pad_below (struct args_size *offset_ptr, machine_mode passed_mode, tree sizetree)
4324 : {
4325 0 : unsigned int align = PARM_BOUNDARY / BITS_PER_UNIT;
4326 0 : int misalign;
4327 0 : if (passed_mode != BLKmode
4328 0 : && known_misalignment (GET_MODE_SIZE (passed_mode), align, &misalign))
4329 0 : offset_ptr->constant += -misalign & (align - 1);
4330 : else
4331 : {
4332 0 : if (TREE_CODE (sizetree) != INTEGER_CST
4333 0 : || (TREE_INT_CST_LOW (sizetree) & (align - 1)) != 0)
4334 : {
4335 : /* Round the size up to multiple of PARM_BOUNDARY bits. */
4336 0 : tree s2 = round_up (sizetree, align);
4337 : /* Add it in. */
4338 0 : ADD_PARM_SIZE (*offset_ptr, s2);
4339 0 : SUB_PARM_SIZE (*offset_ptr, sizetree);
4340 : }
4341 : }
4342 0 : }
4343 :
4344 :
4345 : /* True if register REGNO was alive at a place where `setjmp' was
4346 : called and was set more than once or is an argument. Such regs may
4347 : be clobbered by `longjmp'. */
4348 :
4349 : static bool
4350 44 : regno_clobbered_at_setjmp (bitmap setjmp_crosses, int regno)
4351 : {
4352 : /* There appear to be cases where some local vars never reach the
4353 : backend but have bogus regnos. */
4354 44 : if (regno >= max_reg_num ())
4355 : return false;
4356 :
4357 44 : return ((REG_N_SETS (regno) > 1
4358 42 : || REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR_FOR_FN (cfun)),
4359 : regno))
4360 44 : && REGNO_REG_SET_P (setjmp_crosses, regno));
4361 : }
4362 :
4363 : /* Walk the tree of blocks describing the binding levels within a
4364 : function and warn about variables the might be killed by setjmp or
4365 : vfork. This is done after calling flow_analysis before register
4366 : allocation since that will clobber the pseudo-regs to hard
4367 : regs. */
4368 :
4369 : static void
4370 83 : setjmp_vars_warning (bitmap setjmp_crosses, tree block)
4371 : {
4372 83 : tree decl, sub;
4373 :
4374 212 : for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
4375 : {
4376 129 : if (VAR_P (decl)
4377 129 : && DECL_RTL_SET_P (decl)
4378 35 : && REG_P (DECL_RTL (decl))
4379 147 : && regno_clobbered_at_setjmp (setjmp_crosses, REGNO (DECL_RTL (decl))))
4380 1 : warning (OPT_Wclobbered, "variable %q+D might be clobbered by"
4381 : " %<longjmp%> or %<vfork%>", decl);
4382 : }
4383 :
4384 142 : for (sub = BLOCK_SUBBLOCKS (block); sub; sub = BLOCK_CHAIN (sub))
4385 59 : setjmp_vars_warning (setjmp_crosses, sub);
4386 83 : }
4387 :
4388 : /* Do the appropriate part of setjmp_vars_warning
4389 : but for arguments instead of local variables. */
4390 :
4391 : static void
4392 24 : setjmp_args_warning (bitmap setjmp_crosses)
4393 : {
4394 24 : tree decl;
4395 24 : for (decl = DECL_ARGUMENTS (current_function_decl);
4396 50 : decl; decl = DECL_CHAIN (decl))
4397 26 : if (DECL_RTL (decl) != 0
4398 26 : && REG_P (DECL_RTL (decl))
4399 52 : && regno_clobbered_at_setjmp (setjmp_crosses, REGNO (DECL_RTL (decl))))
4400 0 : warning (OPT_Wclobbered,
4401 : "argument %q+D might be clobbered by %<longjmp%> or %<vfork%>",
4402 : decl);
4403 24 : }
4404 :
4405 : /* Generate warning messages for variables live across setjmp. */
4406 :
4407 : void
4408 135506 : generate_setjmp_warnings (void)
4409 : {
4410 135506 : bitmap setjmp_crosses = regstat_get_setjmp_crosses ();
4411 :
4412 135506 : if (n_basic_blocks_for_fn (cfun) == NUM_FIXED_BLOCKS
4413 135506 : || bitmap_empty_p (setjmp_crosses))
4414 : return;
4415 :
4416 24 : setjmp_vars_warning (setjmp_crosses, DECL_INITIAL (current_function_decl));
4417 24 : setjmp_args_warning (setjmp_crosses);
4418 : }
4419 :
4420 :
4421 : /* Reverse the order of elements in the fragment chain T of blocks,
4422 : and return the new head of the chain (old last element).
4423 : In addition to that clear BLOCK_SAME_RANGE flags when needed
4424 : and adjust BLOCK_SUPERCONTEXT from the super fragment to
4425 : its super fragment origin. */
4426 :
4427 : static tree
4428 5808060 : block_fragments_nreverse (tree t)
4429 : {
4430 5808060 : tree prev = 0, block, next, prev_super = 0;
4431 5808060 : tree super = BLOCK_SUPERCONTEXT (t);
4432 5808060 : if (BLOCK_FRAGMENT_ORIGIN (super))
4433 4815579 : super = BLOCK_FRAGMENT_ORIGIN (super);
4434 17358036 : for (block = t; block; block = next)
4435 : {
4436 11549976 : next = BLOCK_FRAGMENT_CHAIN (block);
4437 11549976 : BLOCK_FRAGMENT_CHAIN (block) = prev;
4438 5741916 : if ((prev && !BLOCK_SAME_RANGE (prev))
4439 14857956 : || (BLOCK_FRAGMENT_CHAIN (BLOCK_SUPERCONTEXT (block))
4440 : != prev_super))
4441 3350663 : BLOCK_SAME_RANGE (block) = 0;
4442 11549976 : prev_super = BLOCK_SUPERCONTEXT (block);
4443 11549976 : BLOCK_SUPERCONTEXT (block) = super;
4444 11549976 : prev = block;
4445 : }
4446 5808060 : t = BLOCK_FRAGMENT_ORIGIN (t);
4447 5808060 : if (BLOCK_FRAGMENT_CHAIN (BLOCK_SUPERCONTEXT (t))
4448 : != prev_super)
4449 1844758 : BLOCK_SAME_RANGE (t) = 0;
4450 5808060 : BLOCK_SUPERCONTEXT (t) = super;
4451 5808060 : return prev;
4452 : }
4453 :
4454 : /* Reverse the order of elements in the chain T of blocks,
4455 : and return the new head of the chain (old last element).
4456 : Also do the same on subblocks and reverse the order of elements
4457 : in BLOCK_FRAGMENT_CHAIN as well. */
4458 :
4459 : static tree
4460 24884484 : blocks_nreverse_all (tree t)
4461 : {
4462 24884484 : tree prev = 0, block, next;
4463 49188460 : for (block = t; block; block = next)
4464 : {
4465 24303976 : next = BLOCK_CHAIN (block);
4466 24303976 : BLOCK_CHAIN (block) = prev;
4467 24303976 : if (BLOCK_FRAGMENT_CHAIN (block)
4468 24303976 : && BLOCK_FRAGMENT_ORIGIN (block) == NULL_TREE)
4469 : {
4470 11616120 : BLOCK_FRAGMENT_CHAIN (block)
4471 5808060 : = block_fragments_nreverse (BLOCK_FRAGMENT_CHAIN (block));
4472 5808060 : if (!BLOCK_SAME_RANGE (BLOCK_FRAGMENT_CHAIN (block)))
4473 2763942 : BLOCK_SAME_RANGE (block) = 0;
4474 : }
4475 24303976 : BLOCK_SUBBLOCKS (block) = blocks_nreverse_all (BLOCK_SUBBLOCKS (block));
4476 24303976 : prev = block;
4477 : }
4478 24884484 : return prev;
4479 : }
4480 :
4481 :
4482 : /* Identify BLOCKs referenced by more than one NOTE_INSN_BLOCK_{BEG,END},
4483 : and create duplicate blocks. */
4484 : /* ??? Need an option to either create block fragments or to create
4485 : abstract origin duplicates of a source block. It really depends
4486 : on what optimization has been performed. */
4487 :
4488 : void
4489 580508 : reorder_blocks (void)
4490 : {
4491 580508 : tree block = DECL_INITIAL (current_function_decl);
4492 :
4493 580508 : if (block == NULL_TREE)
4494 0 : return;
4495 :
4496 580508 : auto_vec<tree, 10> block_stack;
4497 :
4498 : /* Reset the TREE_ASM_WRITTEN bit for all blocks. */
4499 580508 : clear_block_marks (block);
4500 :
4501 : /* Prune the old trees away, so that they don't get in the way. */
4502 580508 : BLOCK_SUBBLOCKS (block) = NULL_TREE;
4503 580508 : BLOCK_CHAIN (block) = NULL_TREE;
4504 :
4505 : /* Recreate the block tree from the note nesting. */
4506 580508 : reorder_blocks_1 (get_insns (), block, &block_stack);
4507 580508 : BLOCK_SUBBLOCKS (block) = blocks_nreverse_all (BLOCK_SUBBLOCKS (block));
4508 580508 : }
4509 :
4510 : /* Helper function for reorder_blocks. Reset TREE_ASM_WRITTEN. */
4511 :
4512 : void
4513 25596471 : clear_block_marks (tree block)
4514 : {
4515 47592524 : while (block)
4516 : {
4517 21996053 : TREE_ASM_WRITTEN (block) = 0;
4518 21996053 : clear_block_marks (BLOCK_SUBBLOCKS (block));
4519 21996053 : block = BLOCK_CHAIN (block);
4520 : }
4521 25596471 : }
4522 :
4523 : static void
4524 580508 : reorder_blocks_1 (rtx_insn *insns, tree current_block,
4525 : vec<tree> *p_block_stack)
4526 : {
4527 580508 : rtx_insn *insn;
4528 580508 : tree prev_beg = NULL_TREE, prev_end = NULL_TREE;
4529 :
4530 203308254 : for (insn = insns; insn; insn = NEXT_INSN (insn))
4531 : {
4532 202727746 : if (NOTE_P (insn))
4533 : {
4534 148439750 : if (NOTE_KIND (insn) == NOTE_INSN_BLOCK_BEG)
4535 : {
4536 24303976 : tree block = NOTE_BLOCK (insn);
4537 24303976 : tree origin;
4538 :
4539 24303976 : gcc_assert (BLOCK_FRAGMENT_ORIGIN (block) == NULL_TREE);
4540 24303976 : origin = block;
4541 :
4542 24303976 : if (prev_end)
4543 1505617 : BLOCK_SAME_RANGE (prev_end) = 0;
4544 24303976 : prev_end = NULL_TREE;
4545 :
4546 : /* If we have seen this block before, that means it now
4547 : spans multiple address regions. Create a new fragment. */
4548 24303976 : if (TREE_ASM_WRITTEN (block))
4549 : {
4550 11549976 : tree new_block = copy_node (block);
4551 :
4552 11549976 : BLOCK_SAME_RANGE (new_block) = 0;
4553 11549976 : BLOCK_FRAGMENT_ORIGIN (new_block) = origin;
4554 11549976 : BLOCK_FRAGMENT_CHAIN (new_block)
4555 11549976 : = BLOCK_FRAGMENT_CHAIN (origin);
4556 11549976 : BLOCK_FRAGMENT_CHAIN (origin) = new_block;
4557 :
4558 11549976 : NOTE_BLOCK (insn) = new_block;
4559 11549976 : block = new_block;
4560 : }
4561 :
4562 24303976 : if (prev_beg == current_block && prev_beg)
4563 15933088 : BLOCK_SAME_RANGE (block) = 1;
4564 :
4565 24303976 : prev_beg = origin;
4566 :
4567 24303976 : BLOCK_SUBBLOCKS (block) = 0;
4568 24303976 : TREE_ASM_WRITTEN (block) = 1;
4569 : /* When there's only one block for the entire function,
4570 : current_block == block and we mustn't do this, it
4571 : will cause infinite recursion. */
4572 24303976 : if (block != current_block)
4573 : {
4574 24303976 : tree super;
4575 24303976 : if (block != origin)
4576 11549976 : gcc_assert (BLOCK_SUPERCONTEXT (origin) == current_block
4577 : || BLOCK_FRAGMENT_ORIGIN (BLOCK_SUPERCONTEXT
4578 : (origin))
4579 : == current_block);
4580 24303976 : if (p_block_stack->is_empty ())
4581 : super = current_block;
4582 : else
4583 : {
4584 21947765 : super = p_block_stack->last ();
4585 33714797 : gcc_assert (super == current_block
4586 : || BLOCK_FRAGMENT_ORIGIN (super)
4587 : == current_block);
4588 : }
4589 24303976 : BLOCK_SUPERCONTEXT (block) = super;
4590 24303976 : BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
4591 24303976 : BLOCK_SUBBLOCKS (current_block) = block;
4592 24303976 : current_block = origin;
4593 : }
4594 24303976 : p_block_stack->safe_push (block);
4595 : }
4596 124135774 : else if (NOTE_KIND (insn) == NOTE_INSN_BLOCK_END)
4597 : {
4598 24303976 : NOTE_BLOCK (insn) = p_block_stack->pop ();
4599 24303976 : current_block = BLOCK_SUPERCONTEXT (current_block);
4600 24303976 : if (BLOCK_FRAGMENT_ORIGIN (current_block))
4601 3884732 : current_block = BLOCK_FRAGMENT_ORIGIN (current_block);
4602 24303976 : prev_beg = NULL_TREE;
4603 40237064 : prev_end = BLOCK_SAME_RANGE (NOTE_BLOCK (insn))
4604 24303976 : ? NOTE_BLOCK (insn) : NULL_TREE;
4605 : }
4606 : }
4607 : else
4608 : {
4609 54287996 : prev_beg = NULL_TREE;
4610 54287996 : if (prev_end)
4611 768557 : BLOCK_SAME_RANGE (prev_end) = 0;
4612 : prev_end = NULL_TREE;
4613 : }
4614 : }
4615 580508 : }
4616 :
4617 : /* Reverse the order of elements in the chain T of blocks,
4618 : and return the new head of the chain (old last element). */
4619 :
4620 : tree
4621 34024698 : blocks_nreverse (tree t)
4622 : {
4623 34024698 : tree prev = 0, block, next;
4624 60167071 : for (block = t; block; block = next)
4625 : {
4626 26142373 : next = BLOCK_CHAIN (block);
4627 26142373 : BLOCK_CHAIN (block) = prev;
4628 26142373 : prev = block;
4629 : }
4630 34024698 : return prev;
4631 : }
4632 :
4633 : /* Concatenate two chains of blocks (chained through BLOCK_CHAIN)
4634 : by modifying the last node in chain 1 to point to chain 2. */
4635 :
4636 : tree
4637 87295407 : block_chainon (tree op1, tree op2)
4638 : {
4639 87295407 : tree t1;
4640 :
4641 87295407 : if (!op1)
4642 : return op2;
4643 4393184 : if (!op2)
4644 : return op1;
4645 :
4646 26122234 : for (t1 = op1; BLOCK_CHAIN (t1); t1 = BLOCK_CHAIN (t1))
4647 21729050 : continue;
4648 4393184 : BLOCK_CHAIN (t1) = op2;
4649 :
4650 : #ifdef ENABLE_TREE_CHECKING
4651 4393184 : {
4652 4393184 : tree t2;
4653 8802776 : for (t2 = op2; t2; t2 = BLOCK_CHAIN (t2))
4654 4409592 : gcc_assert (t2 != t1);
4655 : }
4656 : #endif
4657 :
4658 : return op1;
4659 21729050 : }
4660 :
4661 : /* Count the subblocks of the list starting with BLOCK. If VECTOR is
4662 : non-NULL, list them all into VECTOR, in a depth-first preorder
4663 : traversal of the block tree. Also clear TREE_ASM_WRITTEN in all
4664 : blocks. */
4665 :
4666 : static int
4667 132266094 : all_blocks (tree block, tree *vector)
4668 : {
4669 132266094 : int n_blocks = 0;
4670 :
4671 260034880 : while (block)
4672 : {
4673 127768786 : TREE_ASM_WRITTEN (block) = 0;
4674 :
4675 : /* Record this block. */
4676 127768786 : if (vector)
4677 63884393 : vector[n_blocks] = block;
4678 :
4679 127768786 : ++n_blocks;
4680 :
4681 : /* Record the subblocks, and their subblocks... */
4682 191653179 : n_blocks += all_blocks (BLOCK_SUBBLOCKS (block),
4683 63884393 : vector ? vector + n_blocks : 0);
4684 127768786 : block = BLOCK_CHAIN (block);
4685 : }
4686 :
4687 132266094 : return n_blocks;
4688 : }
4689 :
4690 : /* Return a vector containing all the blocks rooted at BLOCK. The
4691 : number of elements in the vector is stored in N_BLOCKS_P. The
4692 : vector is dynamically allocated; it is the caller's responsibility
4693 : to call `free' on the pointer returned. */
4694 :
4695 : static tree *
4696 2248654 : get_block_vector (tree block, int *n_blocks_p)
4697 : {
4698 2248654 : tree *block_vector;
4699 :
4700 2248654 : *n_blocks_p = all_blocks (block, NULL);
4701 2248654 : block_vector = XNEWVEC (tree, *n_blocks_p);
4702 2248654 : all_blocks (block, block_vector);
4703 :
4704 2248654 : return block_vector;
4705 : }
4706 :
4707 : static GTY(()) int next_block_index = 2;
4708 :
4709 : /* Set BLOCK_NUMBER for all the blocks in FN. */
4710 :
4711 : void
4712 2248654 : number_blocks (tree fn)
4713 : {
4714 2248654 : int i;
4715 2248654 : int n_blocks;
4716 2248654 : tree *block_vector;
4717 :
4718 2248654 : block_vector = get_block_vector (DECL_INITIAL (fn), &n_blocks);
4719 :
4720 : /* The top-level BLOCK isn't numbered at all. */
4721 66133047 : for (i = 1; i < n_blocks; ++i)
4722 : /* We number the blocks from two. */
4723 61635739 : BLOCK_NUMBER (block_vector[i]) = next_block_index++;
4724 :
4725 2248654 : free (block_vector);
4726 :
4727 2248654 : return;
4728 : }
4729 :
4730 : /* If VAR is present in a subblock of BLOCK, return the subblock. */
4731 :
4732 : DEBUG_FUNCTION tree
4733 0 : debug_find_var_in_block_tree (tree var, tree block)
4734 : {
4735 0 : tree t;
4736 :
4737 0 : for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t))
4738 0 : if (t == var)
4739 : return block;
4740 :
4741 0 : for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t))
4742 : {
4743 0 : tree ret = debug_find_var_in_block_tree (var, t);
4744 0 : if (ret)
4745 : return ret;
4746 : }
4747 :
4748 : return NULL_TREE;
4749 : }
4750 :
4751 : /* Keep track of whether we're in a dummy function context. If we are,
4752 : we don't want to invoke the set_current_function hook, because we'll
4753 : get into trouble if the hook calls target_reinit () recursively or
4754 : when the initial initialization is not yet complete. */
4755 :
4756 : static bool in_dummy_function;
4757 :
4758 : /* Invoke the target hook when setting cfun. Update the optimization options
4759 : if the function uses different options than the default. */
4760 :
4761 : static void
4762 814894120 : invoke_set_current_function_hook (tree fndecl)
4763 : {
4764 814894120 : if (!in_dummy_function)
4765 : {
4766 814441810 : tree opts = ((fndecl)
4767 814441810 : ? DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl)
4768 814441810 : : optimization_default_node);
4769 :
4770 814441810 : if (!opts)
4771 377031828 : opts = optimization_default_node;
4772 :
4773 : /* Change optimization options if needed. */
4774 814441810 : if (optimization_current_node != opts)
4775 : {
4776 3265195 : optimization_current_node = opts;
4777 3265195 : cl_optimization_restore (&global_options, &global_options_set,
4778 3265195 : TREE_OPTIMIZATION (opts));
4779 : }
4780 :
4781 814441810 : targetm.set_current_function (fndecl);
4782 814441810 : this_fn_optabs = this_target_optabs;
4783 :
4784 : /* Initialize global alignment variables after op. */
4785 814441810 : parse_alignment_opts ();
4786 :
4787 814441810 : if (opts != optimization_default_node)
4788 : {
4789 1668848 : init_tree_optimization_optabs (opts);
4790 1668848 : if (TREE_OPTIMIZATION_OPTABS (opts))
4791 117019 : this_fn_optabs = (struct target_optabs *)
4792 117019 : TREE_OPTIMIZATION_OPTABS (opts);
4793 : }
4794 : }
4795 814894120 : }
4796 :
4797 : /* Set cfun to NEW_CFUN and switch to the optimization and target options
4798 : associated with NEW_FNDECL.
4799 :
4800 : FORCE says whether we should do the switch even if NEW_CFUN is the current
4801 : function, e.g. because there has been a change in optimization or target
4802 : options. */
4803 :
4804 : static void
4805 1899548017 : set_function_decl (function *new_cfun, tree new_fndecl, bool force)
4806 : {
4807 1899548017 : if (cfun != new_cfun || force)
4808 : {
4809 608834479 : cfun = new_cfun;
4810 608834479 : invoke_set_current_function_hook (new_fndecl);
4811 608834479 : redirect_edge_var_map_empty ();
4812 : }
4813 1899548017 : }
4814 :
4815 : /* cfun should never be set directly; use this function. */
4816 :
4817 : void
4818 1150613991 : set_cfun (struct function *new_cfun, bool force)
4819 : {
4820 1150613991 : set_function_decl (new_cfun, new_cfun ? new_cfun->decl : NULL_TREE, force);
4821 1150613991 : }
4822 :
4823 : /* Initialized with NOGC, making this poisonous to the garbage collector. */
4824 :
4825 : static vec<function *> cfun_stack;
4826 :
4827 : /* Push the current cfun onto the stack, then switch to function NEW_CFUN
4828 : and FUNCTION_DECL NEW_FNDECL. FORCE is as for set_function_decl. */
4829 :
4830 : static void
4831 748934026 : push_function_decl (function *new_cfun, tree new_fndecl, bool force)
4832 : {
4833 748934026 : gcc_assert ((!cfun && !current_function_decl)
4834 : || (cfun && current_function_decl == cfun->decl));
4835 748934026 : cfun_stack.safe_push (cfun);
4836 748934026 : current_function_decl = new_fndecl;
4837 748934026 : set_function_decl (new_cfun, new_fndecl, force);
4838 748934026 : }
4839 :
4840 : /* Push the current cfun onto the stack and switch to function declaration
4841 : NEW_FNDECL, which might or might not have a function body. FORCE is as for
4842 : set_function_decl. */
4843 :
4844 : void
4845 0 : push_function_decl (tree new_fndecl, bool force)
4846 : {
4847 0 : force |= current_function_decl != new_fndecl;
4848 0 : push_function_decl (DECL_STRUCT_FUNCTION (new_fndecl), new_fndecl, force);
4849 0 : }
4850 :
4851 : /* Push the current cfun onto the stack, and set cfun to new_cfun. Also set
4852 : current_function_decl accordingly. */
4853 :
4854 : void
4855 748934026 : push_cfun (struct function *new_cfun)
4856 : {
4857 748934026 : push_function_decl (new_cfun, new_cfun ? new_cfun->decl : NULL_TREE, false);
4858 748934026 : }
4859 :
4860 : /* A common subroutine for pop_cfun and pop_function_decl. FORCE is as
4861 : for set_function_decl. */
4862 :
4863 : static void
4864 749830844 : pop_cfun_1 (bool force)
4865 : {
4866 749830844 : struct function *new_cfun = cfun_stack.pop ();
4867 : /* When in_dummy_function, we do have a cfun but current_function_decl is
4868 : NULL. We also allow pushing NULL cfun and subsequently changing
4869 : current_function_decl to something else and have both restored by
4870 : pop_cfun. */
4871 749830844 : gcc_checking_assert (in_dummy_function
4872 : || !cfun
4873 : || current_function_decl == cfun->decl);
4874 749830844 : set_cfun (new_cfun, force);
4875 749830844 : current_function_decl = new_cfun ? new_cfun->decl : NULL_TREE;
4876 749830844 : }
4877 :
4878 : /* Pop cfun from the stack. Also set current_function_decl accordingly. */
4879 :
4880 : void
4881 749830844 : pop_cfun (void)
4882 : {
4883 749830844 : pop_cfun_1 (false);
4884 749830844 : }
4885 :
4886 : /* Undo push_function_decl. */
4887 :
4888 : void
4889 0 : pop_function_decl (void)
4890 : {
4891 : /* If the previous cfun was null, the options should be reset to the
4892 : global set. Checking the current cfun against the new (popped) cfun
4893 : wouldn't catch this if the current function decl has no function
4894 : struct. */
4895 0 : pop_cfun_1 (!cfun_stack.last ());
4896 0 : }
4897 :
4898 : /* Return value of funcdef and increase it. */
4899 : int
4900 205833466 : get_next_funcdef_no (void)
4901 : {
4902 205833466 : return funcdef_no++;
4903 : }
4904 :
4905 : /* Return value of funcdef. */
4906 : int
4907 0 : get_last_funcdef_no (void)
4908 : {
4909 0 : return funcdef_no;
4910 : }
4911 :
4912 : /* Allocate and initialize the stack usage info data structure for the
4913 : current function. */
4914 : static void
4915 690 : allocate_stack_usage_info (void)
4916 : {
4917 690 : gcc_assert (!cfun->su);
4918 690 : cfun->su = ggc_cleared_alloc<stack_usage> ();
4919 690 : cfun->su->static_stack_size = -1;
4920 690 : }
4921 :
4922 : /* Allocate a function structure for FNDECL and set its contents
4923 : to the defaults. Set cfun to the newly-allocated object.
4924 : Some of the helper functions invoked during initialization assume
4925 : that cfun has already been set. Therefore, assign the new object
4926 : directly into cfun and invoke the back end hook explicitly at the
4927 : very end, rather than initializing a temporary and calling set_cfun
4928 : on it.
4929 :
4930 : ABSTRACT_P is true if this is a function that will never be seen by
4931 : the middle-end. Such functions are front-end concepts (like C++
4932 : function templates) that do not correspond directly to functions
4933 : placed in object files. */
4934 :
4935 : void
4936 206059641 : allocate_struct_function (tree fndecl, bool abstract_p)
4937 : {
4938 206059641 : tree fntype = fndecl ? TREE_TYPE (fndecl) : NULL_TREE;
4939 :
4940 206059641 : cfun = ggc_cleared_alloc<function> ();
4941 :
4942 206059641 : init_eh_for_function ();
4943 :
4944 206059641 : if (init_machine_status)
4945 206059641 : cfun->machine = (*init_machine_status) ();
4946 :
4947 : #ifdef OVERRIDE_ABI_FORMAT
4948 206059641 : OVERRIDE_ABI_FORMAT (fndecl);
4949 : #endif
4950 :
4951 206059641 : if (fndecl != NULL_TREE)
4952 : {
4953 205833466 : DECL_STRUCT_FUNCTION (fndecl) = cfun;
4954 205833466 : cfun->decl = fndecl;
4955 205833466 : current_function_funcdef_no = get_next_funcdef_no ();
4956 : }
4957 :
4958 206059641 : invoke_set_current_function_hook (fndecl);
4959 :
4960 206059641 : if (fndecl != NULL_TREE)
4961 : {
4962 205833466 : tree result = DECL_RESULT (fndecl);
4963 :
4964 205833466 : if (!abstract_p)
4965 : {
4966 : /* Now that we have activated any function-specific attributes
4967 : that might affect layout, particularly vector modes, relayout
4968 : each of the parameters and the result. */
4969 107492732 : relayout_decl (result);
4970 324153110 : for (tree parm = DECL_ARGUMENTS (fndecl); parm;
4971 216660378 : parm = DECL_CHAIN (parm))
4972 216660378 : relayout_decl (parm);
4973 :
4974 : /* Similarly relayout the function decl. */
4975 107492732 : targetm.target_option.relayout_function (fndecl);
4976 : }
4977 :
4978 107492732 : if (!abstract_p && aggregate_value_p (result, fndecl))
4979 : {
4980 : #ifdef PCC_STATIC_STRUCT_RETURN
4981 : cfun->returns_pcc_struct = 1;
4982 : #endif
4983 3169799 : cfun->returns_struct = 1;
4984 : }
4985 :
4986 205833466 : cfun->stdarg = stdarg_p (fntype);
4987 :
4988 : /* Assume all registers in stdarg functions need to be saved. */
4989 205833466 : cfun->va_list_gpr_size = VA_LIST_MAX_GPR_SIZE;
4990 205833466 : cfun->va_list_fpr_size = VA_LIST_MAX_FPR_SIZE;
4991 :
4992 : /* ??? This could be set on a per-function basis by the front-end
4993 : but is this worth the hassle? */
4994 205833466 : cfun->can_throw_non_call_exceptions = flag_non_call_exceptions;
4995 205833466 : cfun->can_delete_dead_exceptions = flag_delete_dead_exceptions;
4996 :
4997 205833466 : if (!profile_flag && !flag_instrument_function_entry_exit)
4998 205832941 : DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (fndecl) = 1;
4999 :
5000 205833466 : if (flag_callgraph_info)
5001 1 : allocate_stack_usage_info ();
5002 : }
5003 :
5004 : /* Don't enable begin stmt markers if var-tracking at assignments is
5005 : disabled. The markers make little sense without the variable
5006 : binding annotations among them. */
5007 412119282 : cfun->debug_nonbind_markers = lang_hooks.emits_begin_stmt
5008 206059641 : && MAY_HAVE_DEBUG_MARKER_STMTS;
5009 206059641 : }
5010 :
5011 : /* This is like allocate_struct_function, but pushes a new cfun for FNDECL
5012 : instead of just setting it. */
5013 :
5014 : void
5015 896844 : push_struct_function (tree fndecl, bool abstract_p)
5016 : {
5017 : /* When in_dummy_function we might be in the middle of a pop_cfun and
5018 : current_function_decl and cfun may not match. */
5019 896844 : gcc_assert (in_dummy_function
5020 : || (!cfun && !current_function_decl)
5021 : || (cfun && current_function_decl == cfun->decl));
5022 896844 : cfun_stack.safe_push (cfun);
5023 896844 : current_function_decl = fndecl;
5024 896844 : allocate_struct_function (fndecl, abstract_p);
5025 896844 : }
5026 :
5027 : /* Reset crtl and other non-struct-function variables to defaults as
5028 : appropriate for emitting rtl at the start of a function. */
5029 :
5030 : static void
5031 1763884 : prepare_function_start (void)
5032 : {
5033 1763884 : gcc_assert (!get_last_insn ());
5034 :
5035 1763884 : if (in_dummy_function)
5036 226150 : crtl->abi = &default_function_abi;
5037 : else
5038 1537734 : crtl->abi = &fndecl_abi (cfun->decl).base_abi ();
5039 :
5040 1763884 : init_temp_slots ();
5041 1763884 : init_emit ();
5042 1763884 : init_varasm_status ();
5043 1763884 : init_expr ();
5044 1763884 : default_rtl_profile ();
5045 :
5046 1763884 : if (flag_stack_usage_info && !flag_callgraph_info)
5047 689 : allocate_stack_usage_info ();
5048 :
5049 1763884 : cse_not_expected = ! optimize;
5050 :
5051 : /* Caller save not needed yet. */
5052 1763884 : caller_save_needed = 0;
5053 :
5054 : /* We haven't done register allocation yet. */
5055 1763884 : reg_renumber = 0;
5056 :
5057 : /* Indicate that we have not instantiated virtual registers yet. */
5058 1763884 : virtuals_instantiated = 0;
5059 :
5060 : /* Indicate that we want CONCATs now. */
5061 1763884 : generating_concat_p = 1;
5062 :
5063 : /* Indicate we have no need of a frame pointer yet. */
5064 1763884 : frame_pointer_needed = 0;
5065 :
5066 : /* Reset the cache of the "extended" flag in the target's
5067 : _BitInt info struct. */
5068 1763884 : bitint_extended = -1;
5069 :
5070 : /* Reset the divisor of the last division expanded, so that a function's
5071 : code does not depend on what was expanded before it. */
5072 1763884 : last_div_const = 0;
5073 1763884 : }
5074 :
5075 : void
5076 226155 : push_dummy_function (bool with_decl)
5077 : {
5078 226155 : tree fn_decl, fn_type, fn_result_decl;
5079 :
5080 226155 : gcc_assert (!in_dummy_function);
5081 226155 : in_dummy_function = true;
5082 :
5083 226155 : if (with_decl)
5084 : {
5085 5 : fn_type = build_function_type_list (void_type_node, NULL_TREE);
5086 5 : fn_decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, NULL_TREE,
5087 : fn_type);
5088 5 : fn_result_decl = build_decl (UNKNOWN_LOCATION, RESULT_DECL,
5089 : NULL_TREE, void_type_node);
5090 5 : DECL_RESULT (fn_decl) = fn_result_decl;
5091 5 : DECL_ARTIFICIAL (fn_decl) = 1;
5092 5 : tree fn_name = get_identifier (" ");
5093 5 : SET_DECL_ASSEMBLER_NAME (fn_decl, fn_name);
5094 : }
5095 : else
5096 : fn_decl = NULL_TREE;
5097 :
5098 226155 : push_struct_function (fn_decl);
5099 226155 : }
5100 :
5101 : /* Initialize the rtl expansion mechanism so that we can do simple things
5102 : like generate sequences. This is used to provide a context during global
5103 : initialization of some passes. You must call expand_dummy_function_end
5104 : to exit this context. */
5105 :
5106 : void
5107 226150 : init_dummy_function_start (void)
5108 : {
5109 226150 : push_dummy_function (false);
5110 226150 : prepare_function_start ();
5111 226150 : }
5112 :
5113 : /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
5114 : and initialize static variables for generating RTL for the statements
5115 : of the function. */
5116 :
5117 : void
5118 1537734 : init_function_start (tree subr)
5119 : {
5120 : /* Initialize backend, if needed. */
5121 1537734 : initialize_rtl ();
5122 :
5123 1537734 : prepare_function_start ();
5124 1537734 : decide_function_section (subr);
5125 :
5126 : /* Warn if this value is an aggregate type,
5127 : regardless of which calling convention we are using for it. */
5128 1537734 : if (AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
5129 110267 : warning_at (DECL_SOURCE_LOCATION (DECL_RESULT (subr)),
5130 110267 : OPT_Waggregate_return, "function returns an aggregate");
5131 1537734 : }
5132 :
5133 : /* Expand code to verify the stack_protect_guard. This is invoked at
5134 : the end of a function to be protected. */
5135 :
5136 : void
5137 341 : stack_protect_epilogue (void)
5138 : {
5139 341 : tree guard_decl = crtl->stack_protect_guard_decl;
5140 341 : rtx_code_label *label = gen_label_rtx ();
5141 341 : rtx x, y;
5142 341 : rtx_insn *seq = NULL;
5143 :
5144 341 : x = expand_normal (crtl->stack_protect_guard);
5145 :
5146 341 : if (targetm.have_stack_protect_combined_test () && guard_decl)
5147 : {
5148 0 : gcc_assert (DECL_P (guard_decl));
5149 0 : y = DECL_RTL (guard_decl);
5150 : /* Allow the target to compute address of Y and compare it with X without
5151 : leaking Y into a register. This combined address + compare pattern
5152 : allows the target to prevent spilling of any intermediate results by
5153 : splitting it after register allocator. */
5154 0 : seq = targetm.gen_stack_protect_combined_test (x, y, label);
5155 : }
5156 : else
5157 : {
5158 341 : if (guard_decl)
5159 341 : y = expand_normal (guard_decl);
5160 : else
5161 0 : y = const0_rtx;
5162 :
5163 : /* Allow the target to compare Y with X without leaking either into
5164 : a register. */
5165 341 : if (targetm.have_stack_protect_test ())
5166 341 : seq = targetm.gen_stack_protect_test (x, y, label);
5167 : }
5168 :
5169 341 : if (seq)
5170 341 : emit_insn (seq);
5171 : else
5172 0 : emit_cmp_and_jump_insns (x, y, EQ, NULL_RTX, ptr_mode, 1, label);
5173 :
5174 : /* The noreturn predictor has been moved to the tree level. The rtl-level
5175 : predictors estimate this branch about 20%, which isn't enough to get
5176 : things moved out of line. Since this is the only extant case of adding
5177 : a noreturn function at the rtl level, it doesn't seem worth doing ought
5178 : except adding the prediction by hand. */
5179 341 : rtx_insn *tmp = get_last_insn ();
5180 341 : if (JUMP_P (tmp))
5181 341 : predict_insn_def (tmp, PRED_NORETURN, TAKEN);
5182 :
5183 341 : expand_call (targetm.stack_protect_fail (), NULL_RTX, /*ignore=*/true);
5184 341 : free_temp_slots ();
5185 341 : emit_label (label);
5186 341 : }
5187 :
5188 : /* Start the RTL for a new function, and set variables used for
5189 : emitting RTL.
5190 : SUBR is the FUNCTION_DECL node.
5191 : PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
5192 : the function's parameters, which must be run at any return statement. */
5193 :
5194 : bool currently_expanding_function_start;
5195 : void
5196 1531890 : expand_function_start (tree subr)
5197 : {
5198 1531890 : currently_expanding_function_start = true;
5199 :
5200 : /* Make sure volatile mem refs aren't considered
5201 : valid operands of arithmetic insns. */
5202 1531890 : init_recog_no_volatile ();
5203 :
5204 1531890 : crtl->profile
5205 3063780 : = (profile_flag
5206 1532290 : && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr));
5207 :
5208 1531890 : crtl->limit_stack
5209 1531890 : = (stack_limit_rtx != NULL_RTX && ! DECL_NO_LIMIT_STACK (subr));
5210 :
5211 : /* Make the label for return statements to jump to. Do not special
5212 : case machines with special return instructions -- they will be
5213 : handled later during jump, ifcvt, or epilogue creation. */
5214 1531890 : return_label = gen_label_rtx ();
5215 :
5216 : /* Initialize rtx used to return the value. */
5217 : /* Do this before assign_parms so that we copy the struct value address
5218 : before any library calls that assign parms might generate. */
5219 :
5220 : /* Decide whether to return the value in memory or in a register. */
5221 1531890 : tree res = DECL_RESULT (subr);
5222 1531890 : if (aggregate_value_p (res, subr))
5223 : {
5224 : /* Returning something that won't go in a register. */
5225 70283 : rtx value_address = 0;
5226 :
5227 : #ifdef PCC_STATIC_STRUCT_RETURN
5228 : if (cfun->returns_pcc_struct)
5229 : {
5230 : int size = int_size_in_bytes (TREE_TYPE (res));
5231 : value_address = assemble_static_space (size);
5232 : }
5233 : else
5234 : #endif
5235 70283 : {
5236 70283 : rtx sv = targetm.calls.struct_value_rtx (TREE_TYPE (subr), 2);
5237 : /* Expect to be passed the address of a place to store the value.
5238 : If it is passed as an argument, assign_parms will take care of
5239 : it. */
5240 70283 : if (sv)
5241 : {
5242 0 : value_address = gen_reg_rtx (Pmode);
5243 0 : emit_move_insn (value_address, sv);
5244 : }
5245 : }
5246 0 : if (value_address)
5247 : {
5248 0 : rtx x = value_address;
5249 0 : if (!DECL_BY_REFERENCE (res))
5250 : {
5251 0 : x = gen_rtx_MEM (DECL_MODE (res), x);
5252 0 : set_mem_attributes (x, res, 1);
5253 : }
5254 0 : set_parm_rtl (res, x);
5255 : }
5256 : }
5257 1461607 : else if (DECL_MODE (res) == VOIDmode)
5258 : /* If return mode is void, this decl rtl should not be used. */
5259 717717 : set_parm_rtl (res, NULL_RTX);
5260 : else
5261 : {
5262 : /* Compute the return values into a pseudo reg, which we will copy
5263 : into the true return register after the cleanups are done. */
5264 743890 : tree return_type = TREE_TYPE (res);
5265 :
5266 : /* If we may coalesce this result, make sure it has the expected mode
5267 : in case it was promoted. But we need not bother about BLKmode. */
5268 743890 : machine_mode promoted_mode
5269 546526 : = flag_tree_coalesce_vars && is_gimple_reg (res)
5270 1253078 : ? promote_ssa_mode (ssa_default_def (cfun, res), NULL)
5271 : : BLKmode;
5272 :
5273 509188 : if (promoted_mode != BLKmode)
5274 509179 : set_parm_rtl (res, gen_reg_rtx (promoted_mode));
5275 234711 : else if (TYPE_MODE (return_type) != BLKmode
5276 234711 : && targetm.calls.return_in_msb (return_type))
5277 : /* expand_function_end will insert the appropriate padding in
5278 : this case. Use the return value's natural (unpadded) mode
5279 : within the function proper. */
5280 0 : set_parm_rtl (res, gen_reg_rtx (TYPE_MODE (return_type)));
5281 : else
5282 : {
5283 : /* In order to figure out what mode to use for the pseudo, we
5284 : figure out what the mode of the eventual return register will
5285 : actually be, and use that. */
5286 234711 : rtx hard_reg = hard_function_value (return_type, subr, 0, 1);
5287 :
5288 : /* Structures that are returned in registers are not
5289 : aggregate_value_p, so we may see a PARALLEL or a REG. */
5290 234711 : if (REG_P (hard_reg))
5291 231384 : set_parm_rtl (res, gen_reg_rtx (GET_MODE (hard_reg)));
5292 : else
5293 : {
5294 3327 : gcc_assert (GET_CODE (hard_reg) == PARALLEL);
5295 3327 : set_parm_rtl (res, gen_group_rtx (hard_reg));
5296 : }
5297 : }
5298 :
5299 : /* Set DECL_REGISTER flag so that expand_function_end will copy the
5300 : result to the real return register(s). */
5301 743890 : DECL_REGISTER (res) = 1;
5302 : }
5303 :
5304 : /* Initialize rtx for parameters and local variables.
5305 : In some cases this requires emitting insns. */
5306 1531890 : assign_parms (subr);
5307 :
5308 : /* If function gets a static chain arg, store it. */
5309 1531890 : if (cfun->static_chain_decl)
5310 : {
5311 19633 : tree parm = cfun->static_chain_decl;
5312 19633 : rtx local, chain;
5313 19633 : rtx_insn *insn;
5314 19633 : int unsignedp;
5315 :
5316 19633 : local = gen_reg_rtx (promote_decl_mode (parm, &unsignedp));
5317 19633 : chain = targetm.calls.static_chain (current_function_decl, true);
5318 :
5319 19633 : set_decl_incoming_rtl (parm, chain, false);
5320 19633 : set_parm_rtl (parm, local);
5321 19633 : mark_reg_pointer (local, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm))));
5322 :
5323 19633 : if (GET_MODE (local) != GET_MODE (chain))
5324 : {
5325 1 : convert_move (local, chain, unsignedp);
5326 1 : insn = get_last_insn ();
5327 : }
5328 : else
5329 19632 : insn = emit_move_insn (local, chain);
5330 :
5331 : /* Mark the register as eliminable, similar to parameters. */
5332 19633 : if (MEM_P (chain)
5333 19633 : && reg_mentioned_p (arg_pointer_rtx, XEXP (chain, 0)))
5334 0 : set_dst_reg_note (insn, REG_EQUIV, chain, local);
5335 :
5336 : /* If we aren't optimizing, save the static chain onto the stack. */
5337 19633 : if (!optimize)
5338 : {
5339 4178 : tree saved_static_chain_decl
5340 4178 : = build_decl (DECL_SOURCE_LOCATION (parm), VAR_DECL,
5341 4178 : DECL_NAME (parm), TREE_TYPE (parm));
5342 4178 : rtx saved_static_chain_rtx
5343 8356 : = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
5344 4178 : SET_DECL_RTL (saved_static_chain_decl, saved_static_chain_rtx);
5345 4178 : emit_move_insn (saved_static_chain_rtx, chain);
5346 4178 : SET_DECL_VALUE_EXPR (parm, saved_static_chain_decl);
5347 4178 : DECL_HAS_VALUE_EXPR_P (parm) = 1;
5348 : }
5349 : }
5350 :
5351 : /* The following was moved from init_function_start.
5352 : The move was supposed to make sdb output more accurate. */
5353 : /* Indicate the beginning of the function body,
5354 : as opposed to parm setup. */
5355 1531890 : emit_note (NOTE_INSN_FUNCTION_BEG);
5356 :
5357 1531890 : gcc_assert (NOTE_P (get_last_insn ()));
5358 :
5359 1531890 : function_beg_insn = parm_birth_insn = get_last_insn ();
5360 :
5361 : /* If the function receives a non-local goto, then store the
5362 : bits we need to restore the frame pointer. */
5363 1531890 : if (cfun->nonlocal_goto_save_area)
5364 : {
5365 406 : tree t_save;
5366 406 : rtx r_save;
5367 :
5368 406 : tree var = TREE_OPERAND (cfun->nonlocal_goto_save_area, 0);
5369 406 : gcc_assert (DECL_RTL_SET_P (var));
5370 :
5371 406 : t_save = build4 (ARRAY_REF,
5372 406 : TREE_TYPE (TREE_TYPE (cfun->nonlocal_goto_save_area)),
5373 : cfun->nonlocal_goto_save_area,
5374 : integer_zero_node, NULL_TREE, NULL_TREE);
5375 406 : r_save = expand_expr (t_save, NULL_RTX, VOIDmode, EXPAND_WRITE);
5376 406 : gcc_assert (GET_MODE (r_save) == Pmode);
5377 :
5378 406 : emit_move_insn (r_save, hard_frame_pointer_rtx);
5379 406 : update_nonlocal_goto_save_area ();
5380 : }
5381 :
5382 1531890 : if (crtl->profile)
5383 : {
5384 : #ifdef PROFILE_HOOK
5385 : PROFILE_HOOK (current_function_funcdef_no);
5386 : #endif
5387 : }
5388 :
5389 : /* If we are doing generic stack checking, the probe should go here. */
5390 1531890 : if (flag_stack_check == GENERIC_STACK_CHECK)
5391 49 : stack_check_probe_note = emit_note (NOTE_INSN_DELETED);
5392 :
5393 1531890 : currently_expanding_function_start = false;
5394 1531890 : }
5395 :
5396 : void
5397 226155 : pop_dummy_function (void)
5398 : {
5399 226155 : pop_cfun ();
5400 226155 : in_dummy_function = false;
5401 226155 : }
5402 :
5403 : /* Undo the effects of init_dummy_function_start. */
5404 : void
5405 226150 : expand_dummy_function_end (void)
5406 : {
5407 226150 : gcc_assert (in_dummy_function);
5408 :
5409 : /* End any sequences that failed to be closed due to syntax errors. */
5410 226150 : while (in_sequence_p ())
5411 0 : end_sequence ();
5412 :
5413 : /* Outside function body, can't compute type's actual size
5414 : until next function's body starts. */
5415 :
5416 226150 : free_after_parsing (cfun);
5417 226150 : free_after_compilation (cfun);
5418 226150 : pop_dummy_function ();
5419 226150 : }
5420 :
5421 : /* Helper for diddle_return_value. */
5422 :
5423 : void
5424 20859907 : diddle_return_value_1 (void (*doit) (rtx, void *), void *arg, rtx outgoing)
5425 : {
5426 20859907 : if (! outgoing)
5427 : return;
5428 :
5429 10873340 : if (REG_P (outgoing))
5430 10816929 : (*doit) (outgoing, arg);
5431 56411 : else if (GET_CODE (outgoing) == PARALLEL)
5432 : {
5433 : int i;
5434 :
5435 132837 : for (i = 0; i < XVECLEN (outgoing, 0); i++)
5436 : {
5437 78861 : rtx x = XEXP (XVECEXP (outgoing, 0, i), 0);
5438 :
5439 78861 : if (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
5440 78861 : (*doit) (x, arg);
5441 : }
5442 : }
5443 : }
5444 :
5445 : /* Call DOIT for each hard register used as a return value from
5446 : the current function. */
5447 :
5448 : void
5449 20859907 : diddle_return_value (void (*doit) (rtx, void *), void *arg)
5450 : {
5451 20859907 : diddle_return_value_1 (doit, arg, crtl->return_rtx);
5452 20859907 : }
5453 :
5454 : static void
5455 13067 : do_clobber_return_reg (rtx reg, void *arg ATTRIBUTE_UNUSED)
5456 : {
5457 5217 : emit_clobber (reg);
5458 5217 : }
5459 :
5460 : void
5461 650667 : clobber_return_register (void)
5462 : {
5463 650667 : diddle_return_value (do_clobber_return_reg, NULL);
5464 :
5465 : /* In case we do use pseudo to return value, clobber it too. */
5466 650667 : if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl)))
5467 : {
5468 7883 : tree decl_result = DECL_RESULT (current_function_decl);
5469 7883 : rtx decl_rtl = DECL_RTL (decl_result);
5470 7883 : if (REG_P (decl_rtl) && REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER)
5471 : {
5472 7850 : do_clobber_return_reg (decl_rtl, NULL);
5473 : }
5474 : }
5475 650667 : }
5476 :
5477 : static void
5478 810761 : do_use_return_reg (rtx reg, void *arg ATTRIBUTE_UNUSED)
5479 : {
5480 810761 : emit_use (reg);
5481 810761 : }
5482 :
5483 : static void
5484 1531888 : use_return_register (void)
5485 : {
5486 0 : diddle_return_value (do_use_return_reg, NULL);
5487 0 : }
5488 :
5489 : /* Generate RTL for the end of the current function. */
5490 :
5491 : void
5492 1531888 : expand_function_end (void)
5493 : {
5494 : /* If arg_pointer_save_area was referenced only from a nested
5495 : function, we will not have initialized it yet. Do that now. */
5496 1531888 : if (arg_pointer_save_area && ! crtl->arg_pointer_save_area_init)
5497 0 : get_arg_pointer_save_area ();
5498 :
5499 : /* If we are doing generic stack checking and this function makes calls,
5500 : do a stack probe at the start of the function to ensure we have enough
5501 : space for another stack frame. */
5502 1531888 : if (flag_stack_check == GENERIC_STACK_CHECK)
5503 : {
5504 49 : rtx_insn *insn, *seq;
5505 :
5506 645 : for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
5507 628 : if (CALL_P (insn))
5508 : {
5509 32 : rtx max_frame_size = GEN_INT (STACK_CHECK_MAX_FRAME_SIZE);
5510 32 : start_sequence ();
5511 32 : if (STACK_CHECK_MOVING_SP)
5512 32 : anti_adjust_stack_and_probe (max_frame_size, true);
5513 : else
5514 : probe_stack_range (STACK_OLD_CHECK_PROTECT, max_frame_size);
5515 32 : seq = end_sequence ();
5516 32 : set_insn_locations (seq, prologue_location);
5517 32 : emit_insn_before (seq, stack_check_probe_note);
5518 32 : break;
5519 : }
5520 : }
5521 :
5522 : /* End any sequences that failed to be closed due to syntax errors. */
5523 1531888 : while (in_sequence_p ())
5524 0 : end_sequence ();
5525 :
5526 1531888 : clear_pending_stack_adjust ();
5527 1531888 : do_pending_stack_adjust ();
5528 :
5529 : /* Output a linenumber for the end of the function.
5530 : SDB depended on this. */
5531 1531888 : set_curr_insn_location (input_location);
5532 :
5533 : /* Before the return label (if any), clobber the return
5534 : registers so that they are not propagated live to the rest of
5535 : the function. This can only happen with functions that drop
5536 : through; if there had been a return statement, there would
5537 : have either been a return rtx, or a jump to the return label.
5538 :
5539 : We delay actual code generation after the current_function_value_rtx
5540 : is computed. */
5541 1531888 : rtx_insn *clobber_after = get_last_insn ();
5542 :
5543 : /* Output the label for the actual return from the function. */
5544 1531888 : emit_label (return_label);
5545 :
5546 1531888 : if (targetm_common.except_unwind_info (&global_options) == UI_SJLJ)
5547 : {
5548 : /* Let except.cc know where it should emit the call to unregister
5549 : the function context for sjlj exceptions. */
5550 0 : if (flag_exceptions)
5551 0 : sjlj_emit_function_exit_after (get_last_insn ());
5552 : }
5553 :
5554 : /* If this is an implementation of throw, do what's necessary to
5555 : communicate between __builtin_eh_return and the epilogue. */
5556 1531888 : expand_eh_return ();
5557 :
5558 : /* If stack protection is enabled for this function, check the guard. */
5559 1531888 : if (crtl->stack_protect_guard
5560 309 : && targetm.stack_protect_runtime_enabled_p ()
5561 1532196 : && naked_return_label == NULL_RTX)
5562 308 : stack_protect_epilogue ();
5563 :
5564 : /* If scalar return value was computed in a pseudo-reg, or was a named
5565 : return value that got dumped to the stack, copy that to the hard
5566 : return register. */
5567 1531888 : if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl)))
5568 : {
5569 814171 : tree decl_result = DECL_RESULT (current_function_decl);
5570 814171 : rtx decl_rtl = DECL_RTL (decl_result);
5571 :
5572 814171 : if ((REG_P (decl_rtl)
5573 814171 : ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
5574 68268 : : DECL_REGISTER (decl_result))
5575 : /* Unless the psABI says not to. */
5576 814171 : && !TYPE_EMPTY_P (TREE_TYPE (decl_result)))
5577 : {
5578 745794 : rtx real_decl_rtl = crtl->return_rtx;
5579 745794 : complex_mode cmode;
5580 :
5581 : /* This should be set in assign_parms. */
5582 745794 : gcc_assert (REG_FUNCTION_VALUE_P (real_decl_rtl));
5583 :
5584 : /* If this is a BLKmode structure being returned in registers,
5585 : then use the mode computed in expand_return. Note that if
5586 : decl_rtl is memory, then its mode may have been changed,
5587 : but that crtl->return_rtx has not. */
5588 745794 : if (GET_MODE (real_decl_rtl) == BLKmode)
5589 2726 : PUT_MODE (real_decl_rtl, GET_MODE (decl_rtl));
5590 :
5591 : /* If a non-BLKmode return value should be padded at the least
5592 : significant end of the register, shift it left by the appropriate
5593 : amount. BLKmode results are handled using the group load/store
5594 : machinery. */
5595 745794 : if (TYPE_MODE (TREE_TYPE (decl_result)) != BLKmode
5596 743064 : && REG_P (real_decl_rtl)
5597 1486067 : && targetm.calls.return_in_msb (TREE_TYPE (decl_result)))
5598 : {
5599 0 : emit_move_insn (gen_rtx_REG (GET_MODE (decl_rtl),
5600 : REGNO (real_decl_rtl)),
5601 : decl_rtl);
5602 0 : shift_return_value (GET_MODE (decl_rtl), true, real_decl_rtl);
5603 : }
5604 745794 : else if (GET_CODE (real_decl_rtl) == PARALLEL)
5605 : {
5606 : /* If expand_function_start has created a PARALLEL for decl_rtl,
5607 : move the result to the real return registers. Otherwise, do
5608 : a group load from decl_rtl for a named return. */
5609 4293 : if (GET_CODE (decl_rtl) == PARALLEL)
5610 3327 : emit_group_move (real_decl_rtl, decl_rtl);
5611 : else
5612 966 : emit_group_load (real_decl_rtl, decl_rtl,
5613 966 : TREE_TYPE (decl_result),
5614 966 : int_size_in_bytes (TREE_TYPE (decl_result)));
5615 : }
5616 : /* In the case of complex integer modes smaller than a word, we'll
5617 : need to generate some non-trivial bitfield insertions. Do that
5618 : on a pseudo and not the hard register. */
5619 741501 : else if (GET_CODE (decl_rtl) == CONCAT
5620 736 : && is_complex_int_mode (GET_MODE (decl_rtl), &cmode)
5621 741649 : && GET_MODE_BITSIZE (cmode) <= BITS_PER_WORD)
5622 : {
5623 94 : int old_generating_concat_p;
5624 94 : rtx tmp;
5625 :
5626 94 : old_generating_concat_p = generating_concat_p;
5627 94 : generating_concat_p = 0;
5628 94 : tmp = gen_reg_rtx (GET_MODE (decl_rtl));
5629 94 : generating_concat_p = old_generating_concat_p;
5630 :
5631 94 : emit_move_insn (tmp, decl_rtl);
5632 94 : emit_move_insn (real_decl_rtl, tmp);
5633 : }
5634 : /* If a named return value dumped decl_return to memory, then
5635 : we may need to re-do the PROMOTE_MODE signed/unsigned
5636 : extension. */
5637 741407 : else if (GET_MODE (real_decl_rtl) != GET_MODE (decl_rtl))
5638 : {
5639 0 : int unsignedp = TYPE_UNSIGNED (TREE_TYPE (decl_result));
5640 0 : promote_function_mode (TREE_TYPE (decl_result),
5641 : GET_MODE (decl_rtl), &unsignedp,
5642 0 : TREE_TYPE (current_function_decl), 1);
5643 :
5644 0 : convert_move (real_decl_rtl, decl_rtl, unsignedp);
5645 : }
5646 : else
5647 741407 : emit_move_insn (real_decl_rtl, decl_rtl);
5648 : }
5649 : }
5650 :
5651 : /* If returning a structure, arrange to return the address of the value
5652 : in a place where debuggers expect to find it.
5653 :
5654 : If returning a structure PCC style,
5655 : the caller also depends on this value.
5656 : And cfun->returns_pcc_struct is not necessarily set. */
5657 1531888 : if ((cfun->returns_struct || cfun->returns_pcc_struct)
5658 70074 : && !targetm.calls.omit_struct_return_reg)
5659 : {
5660 70074 : rtx value_address = DECL_RTL (DECL_RESULT (current_function_decl));
5661 70074 : tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
5662 70074 : rtx outgoing;
5663 :
5664 70074 : if (DECL_BY_REFERENCE (DECL_RESULT (current_function_decl)))
5665 9002 : type = TREE_TYPE (type);
5666 : else
5667 61072 : value_address = XEXP (value_address, 0);
5668 :
5669 70074 : outgoing = targetm.calls.function_value (build_pointer_type (type),
5670 : current_function_decl, true);
5671 :
5672 : /* Mark this as a function return value so integrate will delete the
5673 : assignment and USE below when inlining this function. */
5674 70074 : REG_FUNCTION_VALUE_P (outgoing) = 1;
5675 :
5676 : /* The address may be ptr_mode and OUTGOING may be Pmode. */
5677 70074 : scalar_int_mode mode = as_a <scalar_int_mode> (GET_MODE (outgoing));
5678 70074 : value_address = convert_memory_address (mode, value_address);
5679 :
5680 70074 : emit_move_insn (outgoing, value_address);
5681 :
5682 : /* Show return register used to hold result (in this case the address
5683 : of the result. */
5684 70074 : crtl->return_rtx = outgoing;
5685 : }
5686 :
5687 : /* Emit the actual code to clobber return register. Don't emit
5688 : it if clobber_after is a barrier, then the previous basic block
5689 : certainly doesn't fall thru into the exit block. */
5690 1531888 : if (!BARRIER_P (clobber_after))
5691 : {
5692 578234 : start_sequence ();
5693 578234 : clobber_return_register ();
5694 578234 : rtx_insn *seq = end_sequence ();
5695 :
5696 578234 : emit_insn_after (seq, clobber_after);
5697 : }
5698 :
5699 : /* Output the label for the naked return from the function. */
5700 1531888 : if (naked_return_label)
5701 379 : emit_label (naked_return_label);
5702 :
5703 : /* @@@ This is a kludge. We want to ensure that instructions that
5704 : may trap are not moved into the epilogue by scheduling, because
5705 : we don't always emit unwind information for the epilogue. */
5706 1531888 : if (cfun->can_throw_non_call_exceptions
5707 1531888 : && targetm_common.except_unwind_info (&global_options) != UI_SJLJ)
5708 263022 : emit_insn (gen_blockage ());
5709 :
5710 : /* If stack protection is enabled for this function, check the guard. */
5711 1531888 : if (crtl->stack_protect_guard
5712 309 : && targetm.stack_protect_runtime_enabled_p ()
5713 1532196 : && naked_return_label)
5714 0 : stack_protect_epilogue ();
5715 :
5716 : /* If we had calls to alloca, and this machine needs
5717 : an accurate stack pointer to exit the function,
5718 : insert some code to save and restore the stack pointer. */
5719 1531888 : if (! EXIT_IGNORE_STACK
5720 : && cfun->calls_alloca)
5721 : {
5722 : rtx tem = 0;
5723 :
5724 : start_sequence ();
5725 : emit_stack_save (SAVE_FUNCTION, &tem);
5726 : rtx_insn *seq = end_sequence ();
5727 : emit_insn_before (seq, parm_birth_insn);
5728 :
5729 : emit_stack_restore (SAVE_FUNCTION, tem);
5730 : }
5731 :
5732 : /* ??? This should no longer be necessary since stupid is no longer with
5733 : us, but there are some parts of the compiler (eg reload_combine, and
5734 : sh mach_dep_reorg) that still try and compute their own lifetime info
5735 : instead of using the general framework. */
5736 1531888 : use_return_register ();
5737 1531888 : }
5738 :
5739 : rtx
5740 0 : get_arg_pointer_save_area (void)
5741 : {
5742 0 : rtx ret = arg_pointer_save_area;
5743 :
5744 0 : if (! ret)
5745 : {
5746 0 : ret = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
5747 0 : arg_pointer_save_area = ret;
5748 : }
5749 :
5750 0 : if (! crtl->arg_pointer_save_area_init)
5751 : {
5752 : /* Save the arg pointer at the beginning of the function. The
5753 : generated stack slot may not be a valid memory address, so we
5754 : have to check it and fix it if necessary. */
5755 0 : start_sequence ();
5756 0 : emit_move_insn (validize_mem (copy_rtx (ret)),
5757 : crtl->args.internal_arg_pointer);
5758 0 : rtx_insn *seq = end_sequence ();
5759 :
5760 0 : push_topmost_sequence ();
5761 0 : emit_insn_after (seq, entry_of_function ());
5762 0 : pop_topmost_sequence ();
5763 :
5764 0 : crtl->arg_pointer_save_area_init = true;
5765 : }
5766 :
5767 0 : return ret;
5768 : }
5769 :
5770 :
5771 : /* If debugging dumps are requested, dump information about how the
5772 : target handled -fstack-check=clash for the prologue.
5773 :
5774 : PROBES describes what if any probes were emitted.
5775 :
5776 : RESIDUALS indicates if the prologue had any residual allocation
5777 : (i.e. total allocation was not a multiple of PROBE_INTERVAL). */
5778 :
5779 : void
5780 128 : dump_stack_clash_frame_info (enum stack_clash_probes probes, bool residuals)
5781 : {
5782 128 : if (!dump_file)
5783 : return;
5784 :
5785 19 : switch (probes)
5786 : {
5787 1 : case NO_PROBE_NO_FRAME:
5788 1 : fprintf (dump_file,
5789 : "Stack clash no probe no stack adjustment in prologue.\n");
5790 1 : break;
5791 12 : case NO_PROBE_SMALL_FRAME:
5792 12 : fprintf (dump_file,
5793 : "Stack clash no probe small stack adjustment in prologue.\n");
5794 12 : break;
5795 4 : case PROBE_INLINE:
5796 4 : fprintf (dump_file, "Stack clash inline probes in prologue.\n");
5797 4 : break;
5798 2 : case PROBE_LOOP:
5799 2 : fprintf (dump_file, "Stack clash probe loop in prologue.\n");
5800 2 : break;
5801 : }
5802 :
5803 19 : if (residuals)
5804 18 : fprintf (dump_file, "Stack clash residual allocation in prologue.\n");
5805 : else
5806 1 : fprintf (dump_file, "Stack clash no residual allocation in prologue.\n");
5807 :
5808 19 : if (frame_pointer_needed)
5809 0 : fprintf (dump_file, "Stack clash frame pointer needed.\n");
5810 : else
5811 19 : fprintf (dump_file, "Stack clash no frame pointer needed.\n");
5812 :
5813 19 : if (TREE_THIS_VOLATILE (cfun->decl))
5814 1 : fprintf (dump_file,
5815 : "Stack clash noreturn prologue, assuming no implicit"
5816 : " probes in caller.\n");
5817 : else
5818 18 : fprintf (dump_file,
5819 : "Stack clash not noreturn prologue.\n");
5820 : }
5821 :
5822 : /* Add a list of INSNS to the hash HASHP, possibly allocating HASHP
5823 : for the first time. */
5824 :
5825 : static void
5826 3775759 : record_insns (rtx_insn *insns, rtx_insn *end,
5827 : hash_table<insn_cache_hasher> **hashp)
5828 : {
5829 3775759 : rtx_insn *tmp;
5830 3775759 : hash_table<insn_cache_hasher> *hash = *hashp;
5831 :
5832 3775759 : if (hash == NULL)
5833 3062248 : *hashp = hash = hash_table<insn_cache_hasher>::create_ggc (17);
5834 :
5835 14623434 : for (tmp = insns; tmp != end; tmp = NEXT_INSN (tmp))
5836 : {
5837 10847675 : rtx *slot = hash->find_slot (tmp, INSERT);
5838 10847675 : gcc_assert (*slot == NULL);
5839 10847675 : *slot = tmp;
5840 : }
5841 3775759 : }
5842 :
5843 : /* INSN has been duplicated or replaced by as COPY, perhaps by duplicating a
5844 : basic block, splitting or peepholes. If INSN is a prologue or epilogue
5845 : insn, then record COPY as well. */
5846 :
5847 : void
5848 3800491 : maybe_copy_prologue_epilogue_insn (rtx_insn *insn, rtx_insn *copy)
5849 : {
5850 3800491 : hash_table<insn_cache_hasher> *hash;
5851 3800491 : rtx *slot;
5852 :
5853 3800491 : hash = epilogue_insn_hash;
5854 3800491 : if (!hash || !hash->find (insn))
5855 : {
5856 3282220 : hash = prologue_insn_hash;
5857 3282220 : if (!hash || !hash->find (insn))
5858 : return;
5859 : }
5860 :
5861 595626 : slot = hash->find_slot (copy, INSERT);
5862 595626 : gcc_assert (*slot == NULL);
5863 595626 : *slot = copy;
5864 : }
5865 :
5866 : /* Determine if any INSNs in HASH are, or are part of, INSN. Because
5867 : we can be running after reorg, SEQUENCE rtl is possible. */
5868 :
5869 : static bool
5870 296264561 : contains (const rtx_insn *insn, hash_table<insn_cache_hasher> *hash)
5871 : {
5872 296264561 : if (hash == NULL)
5873 : return false;
5874 :
5875 296208345 : if (NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == SEQUENCE)
5876 : {
5877 0 : rtx_sequence *seq = as_a <rtx_sequence *> (PATTERN (insn));
5878 0 : int i;
5879 0 : for (i = seq->len () - 1; i >= 0; i--)
5880 0 : if (hash->find (seq->element (i)))
5881 : return true;
5882 : return false;
5883 : }
5884 :
5885 296208345 : return hash->find (const_cast<rtx_insn *> (insn)) != NULL;
5886 : }
5887 :
5888 : bool
5889 113721794 : prologue_contains (const rtx_insn *insn)
5890 : {
5891 113721794 : return contains (insn, prologue_insn_hash);
5892 : }
5893 :
5894 : bool
5895 113721794 : epilogue_contains (const rtx_insn *insn)
5896 : {
5897 113721794 : return contains (insn, epilogue_insn_hash);
5898 : }
5899 :
5900 : bool
5901 4357 : prologue_epilogue_contains (const rtx_insn *insn)
5902 : {
5903 4357 : if (contains (insn, prologue_insn_hash))
5904 : return true;
5905 4172 : if (contains (insn, epilogue_insn_hash))
5906 : return true;
5907 : return false;
5908 : }
5909 :
5910 : void
5911 159635 : record_prologue_seq (rtx_insn *seq)
5912 : {
5913 159635 : record_insns (seq, NULL, &prologue_insn_hash);
5914 159635 : }
5915 :
5916 : void
5917 141809 : record_epilogue_seq (rtx_insn *seq)
5918 : {
5919 141809 : record_insns (seq, NULL, &epilogue_insn_hash);
5920 141809 : }
5921 :
5922 : /* Set JUMP_LABEL for a return insn. */
5923 :
5924 : void
5925 1578067 : set_return_jump_label (rtx_insn *returnjump)
5926 : {
5927 1578067 : rtx pat = PATTERN (returnjump);
5928 1578067 : if (GET_CODE (pat) == PARALLEL)
5929 27221 : pat = XVECEXP (pat, 0, 0);
5930 1578067 : if (ANY_RETURN_P (pat))
5931 : JUMP_LABEL (returnjump) = pat;
5932 : else
5933 0 : JUMP_LABEL (returnjump) = ret_rtx;
5934 1578067 : }
5935 :
5936 : /* Return a sequence to be used as the split prologue for the current
5937 : function, or NULL. */
5938 :
5939 : static rtx_insn *
5940 1577550 : make_split_prologue_seq (void)
5941 : {
5942 1577550 : if (!flag_split_stack
5943 1577550 : || lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (cfun->decl)))
5944 : return NULL;
5945 :
5946 259954 : start_sequence ();
5947 259954 : emit_insn (targetm.gen_split_stack_prologue ());
5948 259954 : rtx_insn *seq = end_sequence ();
5949 :
5950 259954 : record_insns (seq, NULL, &prologue_insn_hash);
5951 259954 : set_insn_locations (seq, prologue_location);
5952 :
5953 259954 : return seq;
5954 : }
5955 :
5956 : /* Return a sequence to be used as the prologue for the current function,
5957 : or NULL. */
5958 :
5959 : static rtx_insn *
5960 1577550 : make_prologue_seq (void)
5961 : {
5962 1577550 : if (!targetm.have_prologue ())
5963 : return NULL;
5964 :
5965 1577550 : start_sequence ();
5966 1577550 : rtx_insn *seq = targetm.gen_prologue ();
5967 1577550 : emit_insn (seq);
5968 :
5969 : /* Insert an explicit USE for the frame pointer
5970 : if the profiling is on and the frame pointer is required. */
5971 1577550 : if (crtl->profile && frame_pointer_needed)
5972 359 : emit_use (hard_frame_pointer_rtx);
5973 :
5974 : /* Retain a map of the prologue insns. */
5975 1577550 : record_insns (seq, NULL, &prologue_insn_hash);
5976 1577550 : emit_note (NOTE_INSN_PROLOGUE_END);
5977 :
5978 : /* Ensure that instructions are not moved into the prologue when
5979 : profiling is on. The call to the profiling routine can be
5980 : emitted within the live range of a call-clobbered register. */
5981 1577550 : if (!targetm.profile_before_prologue () && crtl->profile)
5982 12 : emit_insn (gen_blockage ());
5983 :
5984 1577550 : seq = end_sequence ();
5985 1577550 : set_insn_locations (seq, prologue_location);
5986 :
5987 1577550 : return seq;
5988 : }
5989 :
5990 : /* Emit a sequence of insns to zero the call-used registers before RET
5991 : according to ZERO_REGS_TYPE. Return true if a sequence was emitted, in
5992 : which case crtl->must_be_zero_on_return has grown and the caller has to
5993 : refresh the data flow information. */
5994 :
5995 : static bool
5996 177 : gen_call_used_regs_seq (rtx_insn *ret, unsigned int zero_regs_type)
5997 : {
5998 177 : bool only_gpr = true;
5999 177 : bool only_used = true;
6000 177 : bool only_arg = true;
6001 :
6002 : /* No need to zero call-used-regs in main (). */
6003 177 : if (MAIN_NAME_P (DECL_NAME (current_function_decl)))
6004 : return false;
6005 :
6006 : /* No need to zero call-used-regs if __builtin_eh_return is called
6007 : since it isn't a normal function return. */
6008 135 : if (crtl->calls_eh_return)
6009 : return false;
6010 :
6011 : /* If only_gpr is true, only zero call-used registers that are
6012 : general-purpose registers; if only_used is true, only zero
6013 : call-used registers that are used in the current function;
6014 : if only_arg is true, only zero call-used registers that pass
6015 : parameters defined by the flatform's calling conversion. */
6016 :
6017 135 : using namespace zero_regs_flags;
6018 :
6019 135 : only_gpr = zero_regs_type & ONLY_GPR;
6020 135 : only_used = zero_regs_type & ONLY_USED;
6021 135 : only_arg = zero_regs_type & ONLY_ARG;
6022 :
6023 135 : if ((zero_regs_type & LEAFY_MODE) && leaf_function_p ())
6024 : only_used = true;
6025 :
6026 : /* For each of the hard registers, we should zero it if:
6027 : 1. it is a call-used register;
6028 : and 2. it is not a fixed register;
6029 : and 3. it is not live at the return of the routine;
6030 : and 4. it is general register if only_gpr is true;
6031 : and 5. it is used in the routine if only_used is true;
6032 : and 6. it is a register that passes parameter if only_arg is true. */
6033 :
6034 : /* First, prepare the data flow information. */
6035 135 : basic_block bb = BLOCK_FOR_INSN (ret);
6036 135 : auto_bitmap live_out;
6037 135 : bitmap_copy (live_out, df_get_live_out (bb));
6038 135 : df_simulate_initialize_backwards (bb, live_out);
6039 135 : df_simulate_one_insn_backwards (bb, ret, live_out);
6040 :
6041 135 : HARD_REG_SET selected_hardregs;
6042 135 : HARD_REG_SET all_call_used_regs;
6043 540 : CLEAR_HARD_REG_SET (selected_hardregs);
6044 12825 : CLEAR_HARD_REG_SET (all_call_used_regs);
6045 12825 : for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
6046 : {
6047 12690 : if (!crtl->abi->clobbers_full_reg_p (regno))
6048 1215 : continue;
6049 11475 : if (fixed_regs[regno])
6050 5884 : continue;
6051 5591 : if (REGNO_REG_SET_P (live_out, regno))
6052 124 : continue;
6053 : #ifdef LEAF_REG_REMAP
6054 : if (crtl->uses_only_leaf_regs && LEAF_REG_REMAP (regno) < 0)
6055 : continue;
6056 : #endif
6057 : /* This is a call used register that is dead at return. */
6058 5467 : SET_HARD_REG_BIT (all_call_used_regs, regno);
6059 :
6060 7387 : if (only_gpr
6061 5467 : && !TEST_HARD_REG_BIT (reg_class_contents[GENERAL_REGS], regno))
6062 1920 : continue;
6063 3547 : if (only_used && !df_regs_ever_live_p (regno))
6064 1806 : continue;
6065 1741 : if (only_arg && !FUNCTION_ARG_REGNO_P (regno))
6066 364 : continue;
6067 :
6068 : /* Now this is a register that we might want to zero. */
6069 1377 : SET_HARD_REG_BIT (selected_hardregs, regno);
6070 : }
6071 :
6072 135 : if (hard_reg_set_empty_p (selected_hardregs))
6073 : return false;
6074 :
6075 : /* Now that we have a hard register set that needs to be zeroed, pass it to
6076 : target to generate zeroing sequence. */
6077 131 : HARD_REG_SET zeroed_hardregs;
6078 131 : start_sequence ();
6079 131 : zeroed_hardregs = targetm.calls.zero_call_used_regs (selected_hardregs);
6080 :
6081 : /* For most targets, the returned set of registers is a subset of
6082 : selected_hardregs, however, for some of the targets (for example MIPS),
6083 : clearing some registers that are in selected_hardregs requires clearing
6084 : other call used registers that are not in the selected_hardregs, under
6085 : such situation, the returned set of registers must be a subset of
6086 : all call used registers. */
6087 262 : gcc_assert (hard_reg_set_subset_p (zeroed_hardregs, all_call_used_regs));
6088 :
6089 131 : rtx_insn *seq = end_sequence ();
6090 131 : if (!seq)
6091 : return false;
6092 :
6093 : /* Emit the memory blockage and register clobber asm volatile before
6094 : the whole sequence. */
6095 131 : start_sequence ();
6096 131 : expand_asm_reg_clobber_mem_blockage (zeroed_hardregs);
6097 131 : rtx_insn *seq_barrier = end_sequence ();
6098 :
6099 131 : emit_insn_before (seq_barrier, ret);
6100 131 : emit_insn_before (seq, ret);
6101 :
6102 266 : crtl->must_be_zero_on_return |= zeroed_hardregs;
6103 : return true;
6104 135 : }
6105 :
6106 :
6107 : /* Return a sequence to be used as the epilogue for the current function,
6108 : or NULL. */
6109 :
6110 : static rtx_insn *
6111 1577550 : make_epilogue_seq (void)
6112 : {
6113 1577550 : if (!targetm.have_epilogue ())
6114 : return NULL;
6115 :
6116 1577550 : start_sequence ();
6117 1577550 : emit_note (NOTE_INSN_EPILOGUE_BEG);
6118 1577550 : rtx_insn *seq = targetm.gen_epilogue ();
6119 1577550 : if (seq)
6120 1577550 : emit_jump_insn (seq);
6121 :
6122 : /* Retain a map of the epilogue insns. */
6123 1577550 : record_insns (seq, NULL, &epilogue_insn_hash);
6124 1577550 : set_insn_locations (seq, epilogue_location);
6125 :
6126 1577550 : seq = get_insns ();
6127 1577550 : rtx_insn *returnjump = get_last_insn ();
6128 1577550 : end_sequence ();
6129 :
6130 1577550 : if (JUMP_P (returnjump))
6131 1577474 : set_return_jump_label (returnjump);
6132 :
6133 : return seq;
6134 : }
6135 :
6136 :
6137 : /* Generate the prologue and epilogue RTL if the machine supports it. Thread
6138 : this into place with notes indicating where the prologue ends and where
6139 : the epilogue begins. Update the basic block information when possible.
6140 :
6141 : Notes on epilogue placement:
6142 : There are several kinds of edges to the exit block:
6143 : * a single fallthru edge from LAST_BB
6144 : * possibly, edges from blocks containing sibcalls
6145 : * possibly, fake edges from infinite loops
6146 :
6147 : The epilogue is always emitted on the fallthru edge from the last basic
6148 : block in the function, LAST_BB, into the exit block.
6149 :
6150 : If LAST_BB is empty except for a label, it is the target of every
6151 : other basic block in the function that ends in a return. If a
6152 : target has a return or simple_return pattern (possibly with
6153 : conditional variants), these basic blocks can be changed so that a
6154 : return insn is emitted into them, and their target is adjusted to
6155 : the real exit block.
6156 :
6157 : Notes on shrink wrapping: We implement a fairly conservative
6158 : version of shrink-wrapping rather than the textbook one. We only
6159 : generate a single prologue and a single epilogue. This is
6160 : sufficient to catch a number of interesting cases involving early
6161 : exits.
6162 :
6163 : First, we identify the blocks that require the prologue to occur before
6164 : them. These are the ones that modify a call-saved register, or reference
6165 : any of the stack or frame pointer registers. To simplify things, we then
6166 : mark everything reachable from these blocks as also requiring a prologue.
6167 : This takes care of loops automatically, and avoids the need to examine
6168 : whether MEMs reference the frame, since it is sufficient to check for
6169 : occurrences of the stack or frame pointer.
6170 :
6171 : We then compute the set of blocks for which the need for a prologue
6172 : is anticipatable (borrowing terminology from the shrink-wrapping
6173 : description in Muchnick's book). These are the blocks which either
6174 : require a prologue themselves, or those that have only successors
6175 : where the prologue is anticipatable. The prologue needs to be
6176 : inserted on all edges from BB1->BB2 where BB2 is in ANTIC and BB1
6177 : is not. For the moment, we ensure that only one such edge exists.
6178 :
6179 : The epilogue is placed as described above, but we make a
6180 : distinction between inserting return and simple_return patterns
6181 : when modifying other blocks that end in a return. Blocks that end
6182 : in a sibcall omit the sibcall_epilogue if the block is not in
6183 : ANTIC. */
6184 :
6185 : void
6186 1531124 : thread_prologue_and_epilogue_insns (void)
6187 : {
6188 1531124 : df_analyze ();
6189 :
6190 : /* Can't deal with multiple successors of the entry block at the
6191 : moment. Function should always have at least one entry
6192 : point. */
6193 1531124 : gcc_assert (single_succ_p (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
6194 :
6195 1531124 : edge entry_edge = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun));
6196 1531124 : edge orig_entry_edge = entry_edge;
6197 :
6198 1531124 : rtx_insn *split_prologue_seq = make_split_prologue_seq ();
6199 1531124 : rtx_insn *prologue_seq = make_prologue_seq ();
6200 1531124 : rtx_insn *epilogue_seq = make_epilogue_seq ();
6201 :
6202 : /* Try to perform a kind of shrink-wrapping, making sure the
6203 : prologue/epilogue is emitted only around those parts of the
6204 : function that require it. */
6205 1531124 : try_shrink_wrapping (&entry_edge, prologue_seq);
6206 :
6207 : /* If the target can handle splitting the prologue/epilogue into separate
6208 : components, try to shrink-wrap these components separately. */
6209 1531124 : try_shrink_wrapping_separate (entry_edge->dest);
6210 :
6211 : /* If that did anything for any component we now need the generate the
6212 : "main" prologue again. Because some targets require some of these
6213 : to be called in a specific order (i386 requires the split prologue
6214 : to be first, for example), we create all three sequences again here.
6215 : If this does not work for some target, that target should not enable
6216 : separate shrink-wrapping. */
6217 1531124 : if (crtl->shrink_wrapped_separate)
6218 : {
6219 46426 : split_prologue_seq = make_split_prologue_seq ();
6220 46426 : prologue_seq = make_prologue_seq ();
6221 46426 : epilogue_seq = make_epilogue_seq ();
6222 : }
6223 :
6224 1531124 : rtl_profile_for_bb (EXIT_BLOCK_PTR_FOR_FN (cfun));
6225 :
6226 : /* A small fib -- epilogue is not yet completed, but we wish to re-use
6227 : this marker for the splits of EH_RETURN patterns, and nothing else
6228 : uses the flag in the meantime. */
6229 1531124 : epilogue_completed = 1;
6230 :
6231 : /* Find non-fallthru edges that end with EH_RETURN instructions. On
6232 : some targets, these get split to a special version of the epilogue
6233 : code. In order to be able to properly annotate these with unwind
6234 : info, try to split them now. If we get a valid split, drop an
6235 : EPILOGUE_BEG note and mark the insns as epilogue insns. */
6236 1531124 : edge e;
6237 1531124 : edge_iterator ei;
6238 3116245 : FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
6239 : {
6240 1585121 : rtx_insn *prev, *last, *trial;
6241 :
6242 1585121 : if (e->flags & EDGE_FALLTHRU)
6243 1400603 : continue;
6244 184518 : last = BB_END (e->src);
6245 184518 : if (!eh_returnjump_p (last))
6246 184487 : continue;
6247 :
6248 31 : prev = PREV_INSN (last);
6249 31 : trial = try_split (PATTERN (last), last, 1);
6250 31 : if (trial == last)
6251 0 : continue;
6252 :
6253 31 : record_insns (NEXT_INSN (prev), NEXT_INSN (trial), &epilogue_insn_hash);
6254 31 : emit_note_after (NOTE_INSN_EPILOGUE_BEG, prev);
6255 : }
6256 :
6257 1531124 : edge exit_fallthru_edge = find_fallthru_edge (EXIT_BLOCK_PTR_FOR_FN (cfun)->preds);
6258 :
6259 1531124 : if (exit_fallthru_edge)
6260 : {
6261 1400603 : if (epilogue_seq)
6262 : {
6263 1400603 : insert_insn_on_edge (epilogue_seq, exit_fallthru_edge);
6264 1400603 : commit_edge_insertions ();
6265 :
6266 : /* The epilogue insns we inserted may cause the exit edge to no longer
6267 : be fallthru. */
6268 2882231 : FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
6269 : {
6270 1481628 : if (((e->flags & EDGE_FALLTHRU) != 0)
6271 1481628 : && returnjump_p (BB_END (e->src)))
6272 0 : e->flags &= ~EDGE_FALLTHRU;
6273 : }
6274 :
6275 1400603 : find_sub_basic_blocks (BLOCK_FOR_INSN (epilogue_seq));
6276 : }
6277 0 : else if (next_active_insn (BB_END (exit_fallthru_edge->src)))
6278 : {
6279 : /* We have a fall-through edge to the exit block, the source is not
6280 : at the end of the function, and there will be an assembler epilogue
6281 : at the end of the function.
6282 : We can't use force_nonfallthru here, because that would try to
6283 : use return. Inserting a jump 'by hand' is extremely messy, so
6284 : we take advantage of cfg_layout_finalize using
6285 : fixup_fallthru_exit_predecessor. */
6286 0 : cfg_layout_initialize (0);
6287 0 : basic_block cur_bb;
6288 0 : FOR_EACH_BB_FN (cur_bb, cfun)
6289 0 : if (cur_bb->index >= NUM_FIXED_BLOCKS
6290 0 : && cur_bb->next_bb->index >= NUM_FIXED_BLOCKS)
6291 0 : cur_bb->aux = cur_bb->next_bb;
6292 0 : cfg_layout_finalize ();
6293 : }
6294 : }
6295 :
6296 : /* Insert the prologue. */
6297 :
6298 1531124 : rtl_profile_for_bb (ENTRY_BLOCK_PTR_FOR_FN (cfun));
6299 :
6300 1531124 : if (split_prologue_seq || prologue_seq)
6301 : {
6302 1531124 : rtx_insn *split_prologue_insn = split_prologue_seq;
6303 1531124 : if (split_prologue_seq)
6304 : {
6305 259950 : while (split_prologue_insn && !NONDEBUG_INSN_P (split_prologue_insn))
6306 0 : split_prologue_insn = NEXT_INSN (split_prologue_insn);
6307 259950 : insert_insn_on_edge (split_prologue_seq, orig_entry_edge);
6308 : }
6309 :
6310 1531124 : rtx_insn *prologue_insn = prologue_seq;
6311 1531124 : if (prologue_seq)
6312 : {
6313 1932596 : while (prologue_insn && !NONDEBUG_INSN_P (prologue_insn))
6314 401472 : prologue_insn = NEXT_INSN (prologue_insn);
6315 1531124 : insert_insn_on_edge (prologue_seq, entry_edge);
6316 : }
6317 :
6318 1531124 : commit_edge_insertions ();
6319 :
6320 : /* Look for basic blocks within the prologue insns. */
6321 1531124 : if (split_prologue_insn
6322 1531124 : && BLOCK_FOR_INSN (split_prologue_insn) == NULL)
6323 : split_prologue_insn = NULL;
6324 1531124 : if (prologue_insn
6325 1531124 : && BLOCK_FOR_INSN (prologue_insn) == NULL)
6326 : prologue_insn = NULL;
6327 1531124 : if (split_prologue_insn || prologue_insn)
6328 : {
6329 1153229 : auto_sbitmap blocks (last_basic_block_for_fn (cfun));
6330 1153229 : bitmap_clear (blocks);
6331 1153229 : if (split_prologue_insn)
6332 259950 : bitmap_set_bit (blocks,
6333 259950 : BLOCK_FOR_INSN (split_prologue_insn)->index);
6334 1153229 : if (prologue_insn)
6335 1129652 : bitmap_set_bit (blocks, BLOCK_FOR_INSN (prologue_insn)->index);
6336 1153229 : find_many_sub_basic_blocks (blocks);
6337 1153229 : }
6338 : }
6339 :
6340 1531124 : default_rtl_profile ();
6341 :
6342 : /* Emit sibling epilogues before any sibling call sites. */
6343 1531124 : for (ei = ei_start (EXIT_BLOCK_PTR_FOR_FN (cfun)->preds);
6344 3116245 : (e = ei_safe_edge (ei));
6345 1585121 : ei_next (&ei))
6346 : {
6347 : /* Skip those already handled, the ones that run without prologue. */
6348 1585121 : if (e->flags & EDGE_IGNORE)
6349 : {
6350 5070 : e->flags &= ~EDGE_IGNORE;
6351 5070 : continue;
6352 : }
6353 :
6354 1580051 : rtx_insn *insn = BB_END (e->src);
6355 :
6356 1580051 : auto call = dyn_cast<rtx_call_insn *> (insn);
6357 124471 : if (!(call && SIBLING_CALL_P (call)))
6358 1455580 : continue;
6359 :
6360 124471 : rtx_insn *ep_seq;
6361 124471 : if (targetm.emit_epilogue_for_sibcall)
6362 : {
6363 0 : start_sequence ();
6364 0 : targetm.emit_epilogue_for_sibcall (as_a<rtx_call_insn *> (insn));
6365 0 : ep_seq = end_sequence ();
6366 : }
6367 : else
6368 124471 : ep_seq = targetm.gen_sibcall_epilogue ();
6369 124471 : if (ep_seq)
6370 : {
6371 59230 : start_sequence ();
6372 59230 : emit_note (NOTE_INSN_EPILOGUE_BEG);
6373 59230 : emit_insn (ep_seq);
6374 59230 : rtx_insn *seq = end_sequence ();
6375 :
6376 : /* Retain a map of the epilogue insns. Used in life analysis to
6377 : avoid getting rid of sibcall epilogue insns. Do this before we
6378 : actually emit the sequence. */
6379 59230 : record_insns (seq, NULL, &epilogue_insn_hash);
6380 59230 : set_insn_locations (seq, epilogue_location);
6381 :
6382 59230 : emit_insn_before (seq, insn);
6383 :
6384 59230 : find_sub_basic_blocks (BLOCK_FOR_INSN (insn));
6385 : }
6386 : }
6387 :
6388 1531124 : if (epilogue_seq)
6389 : {
6390 : rtx_insn *insn, *next;
6391 :
6392 : /* Similarly, move any line notes that appear after the epilogue.
6393 : There is no need, however, to be quite so anal about the existence
6394 : of such a note. Also possibly move
6395 : NOTE_INSN_FUNCTION_BEG notes, as those can be relevant for debug
6396 : info generation. */
6397 11730507 : for (insn = epilogue_seq; insn; insn = next)
6398 : {
6399 10199383 : next = NEXT_INSN (insn);
6400 10199383 : if (NOTE_P (insn)
6401 3209461 : && (NOTE_KIND (insn) == NOTE_INSN_FUNCTION_BEG))
6402 0 : reorder_insns (insn, insn, PREV_INSN (epilogue_seq));
6403 : }
6404 : }
6405 :
6406 : /* Threading the prologue and epilogue changes the artificial refs in the
6407 : entry and exit blocks, and may invalidate DF info for tail calls.
6408 : This is also needed for [[musttail]] conversion even when not
6409 : optimizing. */
6410 1531124 : if (optimize
6411 460896 : || cfun->tail_call_marked
6412 460731 : || flag_optimize_sibling_calls
6413 460690 : || flag_ipa_icf_functions
6414 460633 : || in_lto_p)
6415 1079585 : df_update_entry_exit_and_calls ();
6416 : else
6417 : {
6418 451539 : df_update_entry_block_defs ();
6419 451539 : df_update_exit_block_uses ();
6420 : }
6421 1531124 : }
6422 :
6423 : /* Reposition the prologue-end and epilogue-begin notes after
6424 : instruction scheduling. */
6425 :
6426 : void
6427 987482 : reposition_prologue_and_epilogue_notes (void)
6428 : {
6429 987482 : if (!targetm.have_prologue ()
6430 0 : && !targetm.have_epilogue ()
6431 0 : && !targetm.have_sibcall_epilogue ()
6432 987482 : && !targetm.emit_epilogue_for_sibcall)
6433 : return;
6434 :
6435 : /* Since the hash table is created on demand, the fact that it is
6436 : non-null is a signal that it is non-empty. */
6437 987482 : if (prologue_insn_hash != NULL)
6438 : {
6439 987482 : size_t len = prologue_insn_hash->elements ();
6440 987482 : rtx_insn *insn, *last = NULL, *note = NULL;
6441 :
6442 : /* Scan from the beginning until we reach the last prologue insn. */
6443 : /* ??? While we do have the CFG intact, there are two problems:
6444 : (1) The prologue can contain loops (typically probing the stack),
6445 : which means that the end of the prologue isn't in the first bb.
6446 : (2) Sometimes the PROLOGUE_END note gets pushed into the next bb. */
6447 69596866 : for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
6448 : {
6449 69049477 : if (NOTE_P (insn))
6450 : {
6451 12976652 : if (NOTE_KIND (insn) == NOTE_INSN_PROLOGUE_END)
6452 68609384 : note = insn;
6453 : }
6454 56072825 : else if (contains (insn, prologue_insn_hash))
6455 : {
6456 3493033 : last = insn;
6457 3493033 : if (--len == 0)
6458 : break;
6459 : }
6460 : }
6461 :
6462 987482 : if (last)
6463 : {
6464 639690 : if (note == NULL)
6465 : {
6466 : /* Scan forward looking for the PROLOGUE_END note. It should
6467 : be right at the beginning of the block, possibly with other
6468 : insn notes that got moved there. */
6469 1456 : for (note = NEXT_INSN (last); ; note = NEXT_INSN (note))
6470 : {
6471 1456 : if (NOTE_P (note)
6472 1338 : && NOTE_KIND (note) == NOTE_INSN_PROLOGUE_END)
6473 : break;
6474 : }
6475 : }
6476 :
6477 : /* Avoid placing note between CODE_LABEL and BASIC_BLOCK note. */
6478 639690 : if (LABEL_P (last))
6479 229 : last = NEXT_INSN (last);
6480 639690 : reorder_insns (note, note, last);
6481 : }
6482 : }
6483 :
6484 987482 : if (epilogue_insn_hash != NULL)
6485 : {
6486 987482 : edge_iterator ei;
6487 987482 : edge e;
6488 :
6489 2240840 : FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
6490 : {
6491 1253358 : rtx_insn *insn, *first = NULL, *note = NULL;
6492 1253358 : basic_block bb = e->src;
6493 :
6494 : /* Scan from the beginning until we reach the first epilogue insn. */
6495 16994914 : FOR_BB_INSNS (bb, insn)
6496 : {
6497 16843577 : if (NOTE_P (insn))
6498 : {
6499 4051686 : if (NOTE_KIND (insn) == NOTE_INSN_EPILOGUE_BEG)
6500 : {
6501 1102021 : note = insn;
6502 1102021 : if (first != NULL)
6503 : break;
6504 : }
6505 : }
6506 12791891 : else if (first == NULL && contains (insn, epilogue_insn_hash))
6507 : {
6508 1102025 : first = insn;
6509 1102025 : if (note != NULL)
6510 : break;
6511 : }
6512 : }
6513 :
6514 1253358 : if (note)
6515 : {
6516 : /* If the function has a single basic block, and no real
6517 : epilogue insns (e.g. sibcall with no cleanup), the
6518 : epilogue note can get scheduled before the prologue
6519 : note. If we have frame related prologue insns, having
6520 : them scanned during the epilogue will result in a crash.
6521 : In this case re-order the epilogue note to just before
6522 : the last insn in the block. */
6523 1102021 : if (first == NULL)
6524 0 : first = BB_END (bb);
6525 :
6526 1102021 : if (PREV_INSN (first) != note)
6527 32230 : reorder_insns (note, note, PREV_INSN (first));
6528 : }
6529 : }
6530 : }
6531 : }
6532 :
6533 : /* Returns the name of function declared by FNDECL. */
6534 : const char *
6535 160728 : fndecl_name (tree fndecl)
6536 : {
6537 160728 : if (fndecl == NULL)
6538 : return "(nofn)";
6539 160708 : return lang_hooks.decl_printable_name (fndecl, 1);
6540 : }
6541 :
6542 : /* Returns the name of function FN. */
6543 : const char *
6544 160598 : function_name (const function *fn)
6545 : {
6546 160598 : tree fndecl = (fn == NULL) ? NULL : fn->decl;
6547 160598 : return fndecl_name (fndecl);
6548 : }
6549 :
6550 : /* Returns the name of the current function. */
6551 : const char *
6552 8839 : current_function_name (void)
6553 : {
6554 8839 : return function_name (cfun);
6555 : }
6556 :
6557 :
6558 : static void
6559 0 : rest_of_handle_check_leaf_regs (void)
6560 : {
6561 : #ifdef LEAF_REGISTERS
6562 : crtl->uses_only_leaf_regs
6563 : = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
6564 : #endif
6565 0 : }
6566 :
6567 : /* Insert a TYPE into the used types hash table of CFUN. */
6568 :
6569 : static void
6570 58891172 : used_types_insert_helper (tree type, struct function *func)
6571 : {
6572 58891172 : if (type != NULL && func != NULL)
6573 : {
6574 58891172 : if (func->used_types_hash == NULL)
6575 17806744 : func->used_types_hash = hash_set<tree>::create_ggc (37);
6576 :
6577 58891172 : func->used_types_hash->add (type);
6578 : }
6579 58891172 : }
6580 :
6581 : /* Given a type, insert it into the used hash table in cfun. */
6582 : void
6583 216717636 : used_types_insert (tree t)
6584 : {
6585 226788816 : while (POINTER_TYPE_P (t) || TREE_CODE (t) == ARRAY_TYPE)
6586 10336986 : if (TYPE_NAME (t))
6587 : break;
6588 : else
6589 10071180 : t = TREE_TYPE (t);
6590 216717636 : if (TREE_CODE (t) == ERROR_MARK)
6591 : return;
6592 216717631 : if (TYPE_NAME (t) == NULL_TREE
6593 216717631 : || TYPE_NAME (t) == TYPE_NAME (TYPE_MAIN_VARIANT (t)))
6594 80840578 : t = TYPE_MAIN_VARIANT (t);
6595 216717631 : if (debug_info_level > DINFO_LEVEL_NONE)
6596 : {
6597 86379796 : if (cfun)
6598 58891172 : used_types_insert_helper (t, cfun);
6599 : else
6600 : {
6601 : /* So this might be a type referenced by a global variable.
6602 : Record that type so that we can later decide to emit its
6603 : debug information. */
6604 27488624 : vec_safe_push (types_used_by_cur_var_decl, t);
6605 : }
6606 : }
6607 : }
6608 :
6609 : /* Helper to Hash a struct types_used_by_vars_entry. */
6610 :
6611 : static hashval_t
6612 181585032 : hash_types_used_by_vars_entry (const struct types_used_by_vars_entry *entry)
6613 : {
6614 181585032 : gcc_assert (entry && entry->var_decl && entry->type);
6615 :
6616 181585032 : return iterative_hash_object (entry->type,
6617 : iterative_hash_object (entry->var_decl, 0));
6618 : }
6619 :
6620 : /* Hash function of the types_used_by_vars_entry hash table. */
6621 :
6622 : hashval_t
6623 181585032 : used_type_hasher::hash (types_used_by_vars_entry *entry)
6624 : {
6625 181585032 : return hash_types_used_by_vars_entry (entry);
6626 : }
6627 :
6628 : /*Equality function of the types_used_by_vars_entry hash table. */
6629 :
6630 : bool
6631 198480726 : used_type_hasher::equal (types_used_by_vars_entry *e1,
6632 : types_used_by_vars_entry *e2)
6633 : {
6634 198480726 : return (e1->var_decl == e2->var_decl && e1->type == e2->type);
6635 : }
6636 :
6637 : /* Inserts an entry into the types_used_by_vars_hash hash table. */
6638 :
6639 : void
6640 27416590 : types_used_by_var_decl_insert (tree type, tree var_decl)
6641 : {
6642 27416590 : if (type != NULL && var_decl != NULL)
6643 : {
6644 27416590 : types_used_by_vars_entry **slot;
6645 27416590 : struct types_used_by_vars_entry e;
6646 27416590 : e.var_decl = var_decl;
6647 27416590 : e.type = type;
6648 27416590 : if (types_used_by_vars_hash == NULL)
6649 14653 : types_used_by_vars_hash
6650 14653 : = hash_table<used_type_hasher>::create_ggc (37);
6651 :
6652 27416590 : slot = types_used_by_vars_hash->find_slot (&e, INSERT);
6653 27416590 : if (*slot == NULL)
6654 : {
6655 7838174 : struct types_used_by_vars_entry *entry;
6656 7838174 : entry = ggc_alloc<types_used_by_vars_entry> ();
6657 7838174 : entry->type = type;
6658 7838174 : entry->var_decl = var_decl;
6659 7838174 : *slot = entry;
6660 : }
6661 : }
6662 27416590 : }
6663 :
6664 : namespace {
6665 :
6666 : const pass_data pass_data_leaf_regs =
6667 : {
6668 : RTL_PASS, /* type */
6669 : "*leaf_regs", /* name */
6670 : OPTGROUP_NONE, /* optinfo_flags */
6671 : TV_NONE, /* tv_id */
6672 : 0, /* properties_required */
6673 : 0, /* properties_provided */
6674 : 0, /* properties_destroyed */
6675 : 0, /* todo_flags_start */
6676 : 0, /* todo_flags_finish */
6677 : };
6678 :
6679 : class pass_leaf_regs : public rtl_opt_pass
6680 : {
6681 : public:
6682 302985 : pass_leaf_regs (gcc::context *ctxt)
6683 605970 : : rtl_opt_pass (pass_data_leaf_regs, ctxt)
6684 : {}
6685 :
6686 : /* opt_pass methods: */
6687 1531124 : unsigned int execute (function *) final override
6688 : {
6689 1531124 : rest_of_handle_check_leaf_regs ();
6690 1531124 : return 0;
6691 : }
6692 :
6693 : }; // class pass_leaf_regs
6694 :
6695 : } // anon namespace
6696 :
6697 : rtl_opt_pass *
6698 302985 : make_pass_leaf_regs (gcc::context *ctxt)
6699 : {
6700 302985 : return new pass_leaf_regs (ctxt);
6701 : }
6702 :
6703 : static void
6704 1531124 : rest_of_handle_thread_prologue_and_epilogue (function *fun)
6705 : {
6706 : /* prepare_shrink_wrap is sensitive to the block structure of the control
6707 : flow graph, so clean it up first. */
6708 1531124 : if (cfun->tail_call_marked || optimize)
6709 1070393 : cleanup_cfg (0);
6710 :
6711 : /* On some machines, the prologue and epilogue code, or parts thereof,
6712 : can be represented as RTL. Doing so lets us schedule insns between
6713 : it and the rest of the code and also allows delayed branch
6714 : scheduling to operate in the epilogue. */
6715 1531124 : thread_prologue_and_epilogue_insns ();
6716 :
6717 : /* Some non-cold blocks may now be only reachable from cold blocks.
6718 : Fix that up. */
6719 1531124 : fixup_partitions ();
6720 :
6721 : /* After prologue and epilogue generation, the judgement on whether
6722 : one memory access onto stack frame may trap or not could change,
6723 : since we get more exact stack information by now. So try to
6724 : remove any EH edges here, see PR90259. */
6725 1531124 : if (fun->can_throw_non_call_exceptions)
6726 263019 : purge_all_dead_edges ();
6727 :
6728 : /* Shrink-wrapping can result in unreachable edges in the epilogue,
6729 : see PR57320. */
6730 1992020 : cleanup_cfg (optimize ? CLEANUP_EXPENSIVE : 0);
6731 :
6732 : /* The stack usage info is finalized during prologue expansion. */
6733 1531124 : if (flag_stack_usage_info || flag_callgraph_info)
6734 356 : output_stack_usage ();
6735 1531124 : }
6736 :
6737 : /* Record a final call to CALLEE at LOCATION. */
6738 :
6739 : void
6740 0 : record_final_call (tree callee, location_t location)
6741 : {
6742 0 : struct callinfo_callee datum = { location, callee };
6743 0 : vec_safe_push (cfun->su->callees, datum);
6744 0 : }
6745 :
6746 : /* Record a dynamic allocation made for DECL_OR_EXP. */
6747 :
6748 : void
6749 0 : record_dynamic_alloc (tree decl_or_exp)
6750 : {
6751 0 : struct callinfo_dalloc datum;
6752 :
6753 0 : if (DECL_P (decl_or_exp))
6754 : {
6755 0 : datum.location = DECL_SOURCE_LOCATION (decl_or_exp);
6756 0 : const char *name = lang_hooks.decl_printable_name (decl_or_exp, 2);
6757 0 : const char *dot = strrchr (name, '.');
6758 0 : if (dot)
6759 0 : name = dot + 1;
6760 0 : datum.name = ggc_strdup (name);
6761 : }
6762 : else
6763 : {
6764 0 : datum.location = EXPR_LOCATION (decl_or_exp);
6765 0 : datum.name = NULL;
6766 : }
6767 :
6768 0 : vec_safe_push (cfun->su->dallocs, datum);
6769 0 : }
6770 :
6771 : namespace {
6772 :
6773 : const pass_data pass_data_thread_prologue_and_epilogue =
6774 : {
6775 : RTL_PASS, /* type */
6776 : "pro_and_epilogue", /* name */
6777 : OPTGROUP_NONE, /* optinfo_flags */
6778 : TV_THREAD_PROLOGUE_AND_EPILOGUE, /* tv_id */
6779 : 0, /* properties_required */
6780 : 0, /* properties_provided */
6781 : 0, /* properties_destroyed */
6782 : 0, /* todo_flags_start */
6783 : ( TODO_df_verify | TODO_df_finish ), /* todo_flags_finish */
6784 : };
6785 :
6786 : class pass_thread_prologue_and_epilogue : public rtl_opt_pass
6787 : {
6788 : public:
6789 302985 : pass_thread_prologue_and_epilogue (gcc::context *ctxt)
6790 605970 : : rtl_opt_pass (pass_data_thread_prologue_and_epilogue, ctxt)
6791 : {}
6792 :
6793 : /* opt_pass methods: */
6794 1531131 : bool gate (function *) final override
6795 : {
6796 1531131 : return !targetm.use_late_prologue_epilogue ();
6797 : }
6798 :
6799 1531124 : unsigned int execute (function * fun) final override
6800 : {
6801 1531124 : rest_of_handle_thread_prologue_and_epilogue (fun);
6802 1531124 : return 0;
6803 : }
6804 :
6805 : }; // class pass_thread_prologue_and_epilogue
6806 :
6807 : const pass_data pass_data_late_thread_prologue_and_epilogue =
6808 : {
6809 : RTL_PASS, /* type */
6810 : "late_pro_and_epilogue", /* name */
6811 : OPTGROUP_NONE, /* optinfo_flags */
6812 : TV_THREAD_PROLOGUE_AND_EPILOGUE, /* tv_id */
6813 : 0, /* properties_required */
6814 : 0, /* properties_provided */
6815 : 0, /* properties_destroyed */
6816 : 0, /* todo_flags_start */
6817 : ( TODO_df_verify | TODO_df_finish ), /* todo_flags_finish */
6818 : };
6819 :
6820 : class pass_late_thread_prologue_and_epilogue : public rtl_opt_pass
6821 : {
6822 : public:
6823 302985 : pass_late_thread_prologue_and_epilogue (gcc::context *ctxt)
6824 605970 : : rtl_opt_pass (pass_data_late_thread_prologue_and_epilogue, ctxt)
6825 : {}
6826 :
6827 : /* opt_pass methods: */
6828 1531131 : bool gate (function *) final override
6829 : {
6830 1531131 : return targetm.use_late_prologue_epilogue ();
6831 : }
6832 :
6833 0 : unsigned int execute (function *fn) final override
6834 : {
6835 : /* It's not currently possible to have both delay slots and
6836 : late prologue/epilogue, since the latter has to run before
6837 : the former, and the former won't honor whatever restrictions
6838 : the latter is trying to enforce. */
6839 0 : gcc_assert (!DELAY_SLOTS);
6840 0 : rest_of_handle_thread_prologue_and_epilogue (fn);
6841 0 : return 0;
6842 : }
6843 : }; // class pass_late_thread_prologue_and_epilogue
6844 :
6845 : } // anon namespace
6846 :
6847 : rtl_opt_pass *
6848 302985 : make_pass_thread_prologue_and_epilogue (gcc::context *ctxt)
6849 : {
6850 302985 : return new pass_thread_prologue_and_epilogue (ctxt);
6851 : }
6852 :
6853 : rtl_opt_pass *
6854 302985 : make_pass_late_thread_prologue_and_epilogue (gcc::context *ctxt)
6855 : {
6856 302985 : return new pass_late_thread_prologue_and_epilogue (ctxt);
6857 : }
6858 :
6859 : namespace {
6860 :
6861 : const pass_data pass_data_zero_call_used_regs =
6862 : {
6863 : RTL_PASS, /* type */
6864 : "zero_call_used_regs", /* name */
6865 : OPTGROUP_NONE, /* optinfo_flags */
6866 : TV_NONE, /* tv_id */
6867 : 0, /* properties_required */
6868 : 0, /* properties_provided */
6869 : 0, /* properties_destroyed */
6870 : 0, /* todo_flags_start */
6871 : 0, /* todo_flags_finish */
6872 : };
6873 :
6874 : class pass_zero_call_used_regs: public rtl_opt_pass
6875 : {
6876 : public:
6877 302985 : pass_zero_call_used_regs (gcc::context *ctxt)
6878 605970 : : rtl_opt_pass (pass_data_zero_call_used_regs, ctxt)
6879 : {}
6880 :
6881 : /* opt_pass methods: */
6882 : unsigned int execute (function *) final override;
6883 :
6884 : }; // class pass_zero_call_used_regs
6885 :
6886 : unsigned int
6887 1531124 : pass_zero_call_used_regs::execute (function *fun)
6888 : {
6889 1531124 : using namespace zero_regs_flags;
6890 1531124 : unsigned int zero_regs_type = UNSET;
6891 :
6892 1531124 : tree attr_zero_regs = lookup_attribute ("zero_call_used_regs",
6893 1531124 : DECL_ATTRIBUTES (fun->decl));
6894 :
6895 : /* Get the type of zero_call_used_regs from function attribute.
6896 : We have filtered out invalid attribute values already at this point. */
6897 1531124 : if (attr_zero_regs)
6898 : {
6899 : /* The TREE_VALUE of an attribute is a TREE_LIST whose TREE_VALUE
6900 : is the attribute argument's value. */
6901 88 : attr_zero_regs = TREE_VALUE (attr_zero_regs);
6902 88 : gcc_assert (TREE_CODE (attr_zero_regs) == TREE_LIST);
6903 88 : attr_zero_regs = TREE_VALUE (attr_zero_regs);
6904 88 : gcc_assert (TREE_CODE (attr_zero_regs) == STRING_CST);
6905 :
6906 496 : for (unsigned int i = 0; zero_call_used_regs_opts[i].name != NULL; ++i)
6907 496 : if (strcmp (TREE_STRING_POINTER (attr_zero_regs),
6908 496 : zero_call_used_regs_opts[i].name) == 0)
6909 : {
6910 88 : zero_regs_type = zero_call_used_regs_opts[i].flag;
6911 88 : break;
6912 : }
6913 : }
6914 :
6915 88 : if (!zero_regs_type)
6916 1531036 : zero_regs_type = flag_zero_call_used_regs;
6917 :
6918 : /* No need to zero call-used-regs when no user request is present. */
6919 1531124 : if (!(zero_regs_type & ENABLED))
6920 : return 0;
6921 :
6922 183 : edge_iterator ei;
6923 183 : edge e;
6924 :
6925 : /* This pass needs data flow information. */
6926 183 : df_analyze ();
6927 :
6928 : /* Iterate over the function's return instructions and insert any
6929 : register zeroing required by the -fzero-call-used-regs command-line
6930 : option or the "zero_call_used_regs" function attribute. */
6931 183 : bool zeroed = false;
6932 367 : FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
6933 : {
6934 184 : rtx_insn *insn = BB_END (e->src);
6935 184 : if (JUMP_P (insn) && ANY_RETURN_P (JUMP_LABEL (insn)))
6936 177 : zeroed |= gen_call_used_regs_seq (insn, zero_regs_type);
6937 : }
6938 :
6939 : /* The registers in must_be_zero_on_return are uses of the exit block, see
6940 : df_epilogue_uses_p. Growing that set also changes which registers a
6941 : sibling call is recorded as clobbering, see df_get_call_refs, so the
6942 : calls have to be rescanned as well. */
6943 183 : if (zeroed)
6944 131 : df_update_entry_exit_and_calls ();
6945 :
6946 : return 0;
6947 : }
6948 :
6949 : } // anon namespace
6950 :
6951 : rtl_opt_pass *
6952 302985 : make_pass_zero_call_used_regs (gcc::context *ctxt)
6953 : {
6954 302985 : return new pass_zero_call_used_regs (ctxt);
6955 : }
6956 :
6957 : /* If CONSTRAINT is a matching constraint, then return its number.
6958 : Otherwise, return -1. */
6959 :
6960 : static int
6961 46885 : matching_constraint_num (const char *constraint)
6962 : {
6963 46885 : if (*constraint == '%')
6964 1162 : constraint++;
6965 :
6966 46885 : if (IN_RANGE (*constraint, '0', '9'))
6967 33841 : return strtoul (constraint, NULL, 10);
6968 :
6969 : return -1;
6970 : }
6971 :
6972 : /* This mini-pass fixes fall-out from SSA in asm statements that have
6973 : in-out constraints. Say you start with
6974 :
6975 : orig = inout;
6976 : asm ("": "+mr" (inout));
6977 : use (orig);
6978 :
6979 : which is transformed very early to use explicit output and match operands:
6980 :
6981 : orig = inout;
6982 : asm ("": "=mr" (inout) : "0" (inout));
6983 : use (orig);
6984 :
6985 : Or, after SSA and copyprop,
6986 :
6987 : asm ("": "=mr" (inout_2) : "0" (inout_1));
6988 : use (inout_1);
6989 :
6990 : Clearly inout_2 and inout_1 can't be coalesced easily anymore, as
6991 : they represent two separate values, so they will get different pseudo
6992 : registers during expansion. Then, since the two operands need to match
6993 : per the constraints, but use different pseudo registers, reload can
6994 : only register a reload for these operands. But reloads can only be
6995 : satisfied by hardregs, not by memory, so we need a register for this
6996 : reload, just because we are presented with non-matching operands.
6997 : So, even though we allow memory for this operand, no memory can be
6998 : used for it, just because the two operands don't match. This can
6999 : cause reload failures on register-starved targets.
7000 :
7001 : So it's a symptom of reload not being able to use memory for reloads
7002 : or, alternatively it's also a symptom of both operands not coming into
7003 : reload as matching (in which case the pseudo could go to memory just
7004 : fine, as the alternative allows it, and no reload would be necessary).
7005 : We fix the latter problem here, by transforming
7006 :
7007 : asm ("": "=mr" (inout_2) : "0" (inout_1));
7008 :
7009 : back to
7010 :
7011 : inout_2 = inout_1;
7012 : asm ("": "=mr" (inout_2) : "0" (inout_2)); */
7013 :
7014 : static void
7015 36380 : match_asm_constraints_1 (rtx_insn *insn, rtx *p_sets, int noutputs)
7016 : {
7017 36380 : int i;
7018 36380 : bool changed = false;
7019 36380 : rtx op = SET_SRC (p_sets[0]);
7020 36380 : int ninputs = ASM_OPERANDS_INPUT_LENGTH (op);
7021 36380 : rtvec inputs = ASM_OPERANDS_INPUT_VEC (op);
7022 36380 : bool *output_matched = XALLOCAVEC (bool, noutputs);
7023 :
7024 36380 : memset (output_matched, 0, noutputs * sizeof (bool));
7025 82330 : for (i = 0; i < ninputs; i++)
7026 : {
7027 45950 : rtx input, output;
7028 45950 : rtx_insn *insns;
7029 45950 : const char *constraint = ASM_OPERANDS_INPUT_CONSTRAINT (op, i);
7030 45950 : int match, j;
7031 :
7032 45950 : match = matching_constraint_num (constraint);
7033 45950 : if (match < 0)
7034 13040 : continue;
7035 :
7036 32910 : gcc_assert (match < noutputs);
7037 32910 : output = SET_DEST (p_sets[match]);
7038 32910 : input = RTVEC_ELT (inputs, i);
7039 : /* Only do the transformation for pseudos. */
7040 33952 : if (! REG_P (output)
7041 32727 : || rtx_equal_p (output, input)
7042 32064 : || !(REG_P (input) || SUBREG_P (input)
7043 3160 : || MEM_P (input) || CONSTANT_P (input))
7044 64973 : || !general_operand (input, GET_MODE (output)))
7045 1042 : continue;
7046 :
7047 : /* We can't do anything if the output is also used as input,
7048 : as we're going to overwrite it. */
7049 87289 : for (j = 0; j < ninputs; j++)
7050 55421 : if (reg_overlap_mentioned_p (output, RTVEC_ELT (inputs, j)))
7051 : break;
7052 31868 : if (j != ninputs)
7053 0 : continue;
7054 :
7055 : /* Avoid changing the same input several times. For
7056 : asm ("" : "=mr" (out1), "=mr" (out2) : "0" (in), "1" (in));
7057 : only change it once (to out1), rather than changing it
7058 : first to out1 and afterwards to out2. */
7059 31868 : if (i > 0)
7060 : {
7061 41622 : for (j = 0; j < noutputs; j++)
7062 34016 : if (output_matched[j] && input == SET_DEST (p_sets[j]))
7063 : break;
7064 7677 : if (j != noutputs)
7065 71 : continue;
7066 : }
7067 31797 : output_matched[match] = true;
7068 :
7069 31797 : start_sequence ();
7070 31797 : emit_move_insn (output, copy_rtx (input));
7071 31797 : insns = end_sequence ();
7072 31797 : emit_insn_before (insns, insn);
7073 :
7074 31797 : constraint = ASM_OPERANDS_OUTPUT_CONSTRAINT(SET_SRC(p_sets[match]));
7075 31797 : bool early_clobber_p = strchr (constraint, '&') != NULL;
7076 :
7077 : /* Now replace all mentions of the input with output. We can't
7078 : just replace the occurrence in inputs[i], as the register might
7079 : also be used in some other input (or even in an address of an
7080 : output), which would mean possibly increasing the number of
7081 : inputs by one (namely 'output' in addition), which might pose
7082 : a too complicated problem for reload to solve. E.g. this situation:
7083 :
7084 : asm ("" : "=r" (output), "=m" (input) : "0" (input))
7085 :
7086 : Here 'input' is used in two occurrences as input (once for the
7087 : input operand, once for the address in the second output operand).
7088 : If we would replace only the occurrence of the input operand (to
7089 : make the matching) we would be left with this:
7090 :
7091 : output = input
7092 : asm ("" : "=r" (output), "=m" (input) : "0" (output))
7093 :
7094 : Now we suddenly have two different input values (containing the same
7095 : value, but different pseudos) where we formerly had only one.
7096 : With more complicated asms this might lead to reload failures
7097 : which wouldn't have happen without this pass. So, iterate over
7098 : all operands and replace all occurrences of the register used.
7099 :
7100 : However, if one or more of the 'input' uses have a non-matching
7101 : constraint and the matched output operand is an early clobber
7102 : operand, then do not replace the input operand, since by definition
7103 : it conflicts with the output operand and cannot share the same
7104 : register. See PR89313 for details. */
7105 :
7106 155971 : for (j = 0; j < noutputs; j++)
7107 124174 : if (!rtx_equal_p (SET_DEST (p_sets[j]), input)
7108 124174 : && reg_overlap_mentioned_p (input, SET_DEST (p_sets[j])))
7109 1766 : SET_DEST (p_sets[j]) = replace_rtx (SET_DEST (p_sets[j]),
7110 : input, output);
7111 86928 : for (j = 0; j < ninputs; j++)
7112 55131 : if (reg_overlap_mentioned_p (input, RTVEC_ELT (inputs, j)))
7113 : {
7114 31135 : if (!early_clobber_p
7115 32070 : || match == matching_constraint_num
7116 935 : (ASM_OPERANDS_INPUT_CONSTRAINT (op, j)))
7117 31131 : RTVEC_ELT (inputs, j) = replace_rtx (RTVEC_ELT (inputs, j),
7118 : input, output);
7119 : }
7120 :
7121 : changed = true;
7122 : }
7123 :
7124 36380 : if (changed)
7125 24536 : df_insn_rescan (insn);
7126 36380 : }
7127 :
7128 : /* It is expected and desired that optimizations coalesce multiple pseudos into
7129 : one whenever possible. However, in case of hard register constraints we may
7130 : have to undo this and introduce copies since otherwise we could constraint a
7131 : single pseudo to different hard registers. For example, during register
7132 : allocation the following insn would be unsatisfiable since pseudo 60 is
7133 : constrained to hard register r5 and r6 at the same time.
7134 :
7135 : (insn 7 5 0 2 (asm_operands/v ("foo") ("") 0 [
7136 : (reg:DI 60) repeated x2
7137 : ]
7138 : [
7139 : (asm_input:DI ("{r5}") t.c:4)
7140 : (asm_input:DI ("{r6}") t.c:4)
7141 : ]
7142 : [] t.c:4) "t.c":4:3 -1
7143 : (expr_list:REG_DEAD (reg:DI 60)
7144 : (nil)))
7145 :
7146 : Therefore, introduce a copy of pseudo 60 and transform it into
7147 :
7148 : (insn 10 5 7 2 (set (reg:DI 62)
7149 : (reg:DI 60)) "t.c":4:3 1503 {*movdi_64}
7150 : (nil))
7151 : (insn 7 10 11 2 (asm_operands/v ("foo") ("") 0 [
7152 : (reg:DI 60)
7153 : (reg:DI 62)
7154 : ]
7155 : [
7156 : (asm_input:DI ("{r5}") t.c:4)
7157 : (asm_input:DI ("{r6}") t.c:4)
7158 : ]
7159 : [] t.c:4) "t.c":4:3 -1
7160 : (expr_list:REG_DEAD (reg:DI 62)
7161 : (expr_list:REG_DEAD (reg:DI 60)
7162 : (nil))))
7163 :
7164 : Now, LRA can assign pseudo 60 to r5, and pseudo 62 to r6.
7165 :
7166 : TODO: The current implementation is conservative and we could do a bit
7167 : better in case of alternatives. For example
7168 :
7169 : (insn 7 5 0 2 (asm_operands/v ("foo") ("") 0 [
7170 : (reg:DI 60) repeated x2
7171 : ]
7172 : [
7173 : (asm_input:DI ("r,{r5}") t.c:4)
7174 : (asm_input:DI ("{r6},r") t.c:4)
7175 : ]
7176 : [] t.c:4) "t.c":4:3 -1
7177 : (expr_list:REG_DEAD (reg:DI 60)
7178 : (nil)))
7179 :
7180 : For this insn we wouldn't need to come up with a copy of pseudo 60 since in
7181 : each alternative pseudo 60 is constrained exactly one time. */
7182 :
7183 : static void
7184 3470429 : match_asm_constraints_2 (rtx_insn *insn, rtx pat)
7185 : {
7186 3470429 : rtx op;
7187 3470429 : if (GET_CODE (pat) == SET && GET_CODE (SET_SRC (pat)) == ASM_OPERANDS)
7188 : op = SET_SRC (pat);
7189 3389656 : else if (GET_CODE (pat) == ASM_OPERANDS)
7190 : op = pat;
7191 : else
7192 3332074 : return;
7193 138355 : int ninputs = ASM_OPERANDS_INPUT_LENGTH (op);
7194 138355 : rtvec inputs = ASM_OPERANDS_INPUT_VEC (op);
7195 138355 : bool changed = false;
7196 138355 : auto_bitmap constrained_regs;
7197 :
7198 266646 : for (int i = 0; i < ninputs; ++i)
7199 : {
7200 128291 : rtx input = RTVEC_ELT (inputs, i);
7201 128291 : const char *constraint = ASM_OPERANDS_INPUT_CONSTRAINT (op, i);
7202 25500 : if ((!REG_P (input) && !SUBREG_P (input))
7203 102908 : || (REG_P (input) && HARD_REGISTER_P (input))
7204 230093 : || strchr (constraint, '{') == nullptr)
7205 128243 : continue;
7206 48 : int regno;
7207 48 : if (SUBREG_P (input))
7208 : {
7209 0 : if (REG_P (SUBREG_REG (input)))
7210 0 : regno = REGNO (SUBREG_REG (input));
7211 : else
7212 0 : continue;
7213 : }
7214 : else
7215 48 : regno = REGNO (input);
7216 : /* Keep the first usage of a constrained pseudo as is and only
7217 : introduce copies for subsequent usages. */
7218 48 : if (! bitmap_bit_p (constrained_regs, regno))
7219 : {
7220 48 : bitmap_set_bit (constrained_regs, regno);
7221 48 : continue;
7222 : }
7223 0 : rtx tmp = gen_reg_rtx (GET_MODE (input));
7224 0 : start_sequence ();
7225 0 : emit_move_insn (tmp, input);
7226 0 : rtx_insn *insns = get_insns ();
7227 0 : end_sequence ();
7228 0 : emit_insn_before (insns, insn);
7229 0 : RTVEC_ELT (inputs, i) = tmp;
7230 0 : changed = true;
7231 : }
7232 :
7233 138355 : if (changed)
7234 0 : df_insn_rescan (insn);
7235 138355 : }
7236 :
7237 : /* Add the decl D to the local_decls list of FUN. */
7238 :
7239 : void
7240 39803517 : add_local_decl (struct function *fun, tree d)
7241 : {
7242 39803517 : gcc_assert (VAR_P (d));
7243 39803517 : vec_safe_push (fun->local_decls, d);
7244 39803517 : }
7245 :
7246 : namespace {
7247 :
7248 : const pass_data pass_data_match_asm_constraints =
7249 : {
7250 : RTL_PASS, /* type */
7251 : "asmcons", /* name */
7252 : OPTGROUP_NONE, /* optinfo_flags */
7253 : TV_NONE, /* tv_id */
7254 : 0, /* properties_required */
7255 : 0, /* properties_provided */
7256 : 0, /* properties_destroyed */
7257 : 0, /* todo_flags_start */
7258 : 0, /* todo_flags_finish */
7259 : };
7260 :
7261 : class pass_match_asm_constraints : public rtl_opt_pass
7262 : {
7263 : public:
7264 302985 : pass_match_asm_constraints (gcc::context *ctxt)
7265 605970 : : rtl_opt_pass (pass_data_match_asm_constraints, ctxt)
7266 : {}
7267 :
7268 : /* opt_pass methods: */
7269 : unsigned int execute (function *) final override;
7270 :
7271 : }; // class pass_match_asm_constraints
7272 :
7273 : unsigned
7274 1531122 : pass_match_asm_constraints::execute (function *fun)
7275 : {
7276 1531122 : basic_block bb;
7277 1531122 : rtx_insn *insn;
7278 1531122 : rtx pat, *p_sets;
7279 1531122 : int noutputs;
7280 :
7281 1531122 : if (!crtl->has_asm_statement)
7282 : return 0;
7283 :
7284 35163 : df_set_flags (DF_DEFER_INSN_RESCAN);
7285 341071 : FOR_EACH_BB_FN (bb, fun)
7286 : {
7287 3934298 : FOR_BB_INSNS (bb, insn)
7288 : {
7289 3628390 : if (!INSN_P (insn))
7290 680010 : continue;
7291 :
7292 2948380 : pat = PATTERN (insn);
7293 :
7294 2948380 : if (GET_CODE (pat) == PARALLEL)
7295 1301529 : for (int i = XVECLEN (pat, 0) - 1; i >= 0; --i)
7296 911789 : match_asm_constraints_2 (insn, XVECEXP (pat, 0, i));
7297 : else
7298 2558640 : match_asm_constraints_2 (insn, pat);
7299 :
7300 2948380 : if (GET_CODE (pat) == PARALLEL)
7301 389740 : p_sets = &XVECEXP (pat, 0, 0), noutputs = XVECLEN (pat, 0);
7302 2558640 : else if (GET_CODE (pat) == SET)
7303 1559547 : p_sets = &PATTERN (insn), noutputs = 1;
7304 : else
7305 999093 : continue;
7306 :
7307 1949287 : if (GET_CODE (*p_sets) == SET
7308 1887921 : && GET_CODE (SET_SRC (*p_sets)) == ASM_OPERANDS)
7309 36380 : match_asm_constraints_1 (insn, p_sets, noutputs);
7310 : }
7311 : }
7312 :
7313 : return TODO_df_finish;
7314 : }
7315 :
7316 : } // anon namespace
7317 :
7318 : rtl_opt_pass *
7319 302985 : make_pass_match_asm_constraints (gcc::context *ctxt)
7320 : {
7321 302985 : return new pass_match_asm_constraints (ctxt);
7322 : }
7323 :
7324 :
7325 : #include "gt-function.h"
|