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