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