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