* doc/invoke.texi: Add cpu_type power6.
[official-gcc.git] / gcc / function.c
blobbb6480118d6f7b5067c53cb84165d9e1e8983ecc
1 /* Expands front end tree to back end RTL for GCC.
2 Copyright (C) 1987, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA. */
23 /* This file handles the generation of rtl code from tree structure
24 at the level of the function as a whole.
25 It creates the rtl expressions for parameters and auto variables
26 and has full responsibility for allocating stack slots.
28 `expand_function_start' is called at the beginning of a function,
29 before the function body is parsed, and `expand_function_end' is
30 called after parsing the body.
32 Call `assign_stack_local' to allocate a stack slot for a local variable.
33 This is usually done during the RTL generation for the function body,
34 but it can also be done in the reload pass when a pseudo-register does
35 not get a hard register. */
37 #include "config.h"
38 #include "system.h"
39 #include "coretypes.h"
40 #include "tm.h"
41 #include "rtl.h"
42 #include "tree.h"
43 #include "flags.h"
44 #include "except.h"
45 #include "function.h"
46 #include "expr.h"
47 #include "optabs.h"
48 #include "libfuncs.h"
49 #include "regs.h"
50 #include "hard-reg-set.h"
51 #include "insn-config.h"
52 #include "recog.h"
53 #include "output.h"
54 #include "basic-block.h"
55 #include "toplev.h"
56 #include "hashtab.h"
57 #include "ggc.h"
58 #include "tm_p.h"
59 #include "integrate.h"
60 #include "langhooks.h"
61 #include "target.h"
62 #include "cfglayout.h"
63 #include "tree-gimple.h"
64 #include "tree-pass.h"
65 #include "predict.h"
66 #include "vecprim.h"
68 #ifndef LOCAL_ALIGNMENT
69 #define LOCAL_ALIGNMENT(TYPE, ALIGNMENT) ALIGNMENT
70 #endif
72 #ifndef STACK_ALIGNMENT_NEEDED
73 #define STACK_ALIGNMENT_NEEDED 1
74 #endif
76 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
78 /* Some systems use __main in a way incompatible with its use in gcc, in these
79 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
80 give the same symbol without quotes for an alternative entry point. You
81 must define both, or neither. */
82 #ifndef NAME__MAIN
83 #define NAME__MAIN "__main"
84 #endif
86 /* Round a value to the lowest integer less than it that is a multiple of
87 the required alignment. Avoid using division in case the value is
88 negative. Assume the alignment is a power of two. */
89 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
91 /* Similar, but round to the next highest integer that meets the
92 alignment. */
93 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
95 /* Nonzero if function being compiled doesn't contain any calls
96 (ignoring the prologue and epilogue). This is set prior to
97 local register allocation and is valid for the remaining
98 compiler passes. */
99 int current_function_is_leaf;
101 /* Nonzero if function being compiled doesn't modify the stack pointer
102 (ignoring the prologue and epilogue). This is only valid after
103 life_analysis has run. */
104 int current_function_sp_is_unchanging;
106 /* Nonzero if the function being compiled is a leaf function which only
107 uses leaf registers. This is valid after reload (specifically after
108 sched2) and is useful only if the port defines LEAF_REGISTERS. */
109 int current_function_uses_only_leaf_regs;
111 /* Nonzero once virtual register instantiation has been done.
112 assign_stack_local uses frame_pointer_rtx when this is nonzero.
113 calls.c:emit_library_call_value_1 uses it to set up
114 post-instantiation libcalls. */
115 int virtuals_instantiated;
117 /* Assign unique numbers to labels generated for profiling, debugging, etc. */
118 static GTY(()) int funcdef_no;
120 /* These variables hold pointers to functions to create and destroy
121 target specific, per-function data structures. */
122 struct machine_function * (*init_machine_status) (void);
124 /* The currently compiled function. */
125 struct function *cfun = 0;
127 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
128 static VEC(int,heap) *prologue;
129 static VEC(int,heap) *epilogue;
131 /* Array of INSN_UIDs to hold the INSN_UIDs for each sibcall epilogue
132 in this function. */
133 static VEC(int,heap) *sibcall_epilogue;
135 /* In order to evaluate some expressions, such as function calls returning
136 structures in memory, we need to temporarily allocate stack locations.
137 We record each allocated temporary in the following structure.
139 Associated with each temporary slot is a nesting level. When we pop up
140 one level, all temporaries associated with the previous level are freed.
141 Normally, all temporaries are freed after the execution of the statement
142 in which they were created. However, if we are inside a ({...}) grouping,
143 the result may be in a temporary and hence must be preserved. If the
144 result could be in a temporary, we preserve it if we can determine which
145 one it is in. If we cannot determine which temporary may contain the
146 result, all temporaries are preserved. A temporary is preserved by
147 pretending it was allocated at the previous nesting level.
149 Automatic variables are also assigned temporary slots, at the nesting
150 level where they are defined. They are marked a "kept" so that
151 free_temp_slots will not free them. */
153 struct temp_slot GTY(())
155 /* Points to next temporary slot. */
156 struct temp_slot *next;
157 /* Points to previous temporary slot. */
158 struct temp_slot *prev;
160 /* The rtx to used to reference the slot. */
161 rtx slot;
162 /* The rtx used to represent the address if not the address of the
163 slot above. May be an EXPR_LIST if multiple addresses exist. */
164 rtx address;
165 /* The alignment (in bits) of the slot. */
166 unsigned int align;
167 /* The size, in units, of the slot. */
168 HOST_WIDE_INT size;
169 /* The type of the object in the slot, or zero if it doesn't correspond
170 to a type. We use this to determine whether a slot can be reused.
171 It can be reused if objects of the type of the new slot will always
172 conflict with objects of the type of the old slot. */
173 tree type;
174 /* Nonzero if this temporary is currently in use. */
175 char in_use;
176 /* Nonzero if this temporary has its address taken. */
177 char addr_taken;
178 /* Nesting level at which this slot is being used. */
179 int level;
180 /* Nonzero if this should survive a call to free_temp_slots. */
181 int keep;
182 /* The offset of the slot from the frame_pointer, including extra space
183 for alignment. This info is for combine_temp_slots. */
184 HOST_WIDE_INT base_offset;
185 /* The size of the slot, including extra space for alignment. This
186 info is for combine_temp_slots. */
187 HOST_WIDE_INT full_size;
190 /* Forward declarations. */
192 static rtx assign_stack_local_1 (enum machine_mode, HOST_WIDE_INT, int,
193 struct function *);
194 static struct temp_slot *find_temp_slot_from_address (rtx);
195 static void pad_to_arg_alignment (struct args_size *, int, struct args_size *);
196 static void pad_below (struct args_size *, enum machine_mode, tree);
197 static void reorder_blocks_1 (rtx, tree, VEC(tree,heap) **);
198 static void reorder_fix_fragments (tree);
199 static int all_blocks (tree, tree *);
200 static tree *get_block_vector (tree, int *);
201 extern tree debug_find_var_in_block_tree (tree, tree);
202 /* We always define `record_insns' even if it's not used so that we
203 can always export `prologue_epilogue_contains'. */
204 static void record_insns (rtx, VEC(int,heap) **) ATTRIBUTE_UNUSED;
205 static int contains (rtx, VEC(int,heap) **);
206 #ifdef HAVE_return
207 static void emit_return_into_block (basic_block, rtx);
208 #endif
209 #if defined(HAVE_epilogue) && defined(INCOMING_RETURN_ADDR_RTX)
210 static rtx keep_stack_depressed (rtx);
211 #endif
212 static void prepare_function_start (tree);
213 static void do_clobber_return_reg (rtx, void *);
214 static void do_use_return_reg (rtx, void *);
215 static void set_insn_locators (rtx, int) ATTRIBUTE_UNUSED;
217 /* Pointer to chain of `struct function' for containing functions. */
218 struct function *outer_function_chain;
220 /* Given a function decl for a containing function,
221 return the `struct function' for it. */
223 struct function *
224 find_function_data (tree decl)
226 struct function *p;
228 for (p = outer_function_chain; p; p = p->outer)
229 if (p->decl == decl)
230 return p;
232 gcc_unreachable ();
235 /* Save the current context for compilation of a nested function.
236 This is called from language-specific code. The caller should use
237 the enter_nested langhook to save any language-specific state,
238 since this function knows only about language-independent
239 variables. */
241 void
242 push_function_context_to (tree context ATTRIBUTE_UNUSED)
244 struct function *p;
246 if (cfun == 0)
247 init_dummy_function_start ();
248 p = cfun;
250 p->outer = outer_function_chain;
251 outer_function_chain = p;
253 lang_hooks.function.enter_nested (p);
255 cfun = 0;
258 void
259 push_function_context (void)
261 push_function_context_to (current_function_decl);
264 /* Restore the last saved context, at the end of a nested function.
265 This function is called from language-specific code. */
267 void
268 pop_function_context_from (tree context ATTRIBUTE_UNUSED)
270 struct function *p = outer_function_chain;
272 cfun = p;
273 outer_function_chain = p->outer;
275 current_function_decl = p->decl;
277 lang_hooks.function.leave_nested (p);
279 /* Reset variables that have known state during rtx generation. */
280 virtuals_instantiated = 0;
281 generating_concat_p = 1;
284 void
285 pop_function_context (void)
287 pop_function_context_from (current_function_decl);
290 /* Clear out all parts of the state in F that can safely be discarded
291 after the function has been parsed, but not compiled, to let
292 garbage collection reclaim the memory. */
294 void
295 free_after_parsing (struct function *f)
297 /* f->expr->forced_labels is used by code generation. */
298 /* f->emit->regno_reg_rtx is used by code generation. */
299 /* f->varasm is used by code generation. */
300 /* f->eh->eh_return_stub_label is used by code generation. */
302 lang_hooks.function.final (f);
305 /* Clear out all parts of the state in F that can safely be discarded
306 after the function has been compiled, to let garbage collection
307 reclaim the memory. */
309 void
310 free_after_compilation (struct function *f)
312 VEC_free (int, heap, prologue);
313 VEC_free (int, heap, epilogue);
314 VEC_free (int, heap, sibcall_epilogue);
316 f->eh = NULL;
317 f->expr = NULL;
318 f->emit = NULL;
319 f->varasm = NULL;
320 f->machine = NULL;
321 f->cfg = NULL;
323 f->x_avail_temp_slots = NULL;
324 f->x_used_temp_slots = NULL;
325 f->arg_offset_rtx = NULL;
326 f->return_rtx = NULL;
327 f->internal_arg_pointer = NULL;
328 f->x_nonlocal_goto_handler_labels = NULL;
329 f->x_return_label = NULL;
330 f->x_naked_return_label = NULL;
331 f->x_stack_slot_list = NULL;
332 f->x_stack_check_probe_note = NULL;
333 f->x_arg_pointer_save_area = NULL;
334 f->x_parm_birth_insn = NULL;
335 f->original_arg_vector = NULL;
336 f->original_decl_initial = NULL;
337 f->epilogue_delay_list = NULL;
340 /* Allocate fixed slots in the stack frame of the current function. */
342 /* Return size needed for stack frame based on slots so far allocated in
343 function F.
344 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
345 the caller may have to do that. */
347 static HOST_WIDE_INT
348 get_func_frame_size (struct function *f)
350 if (FRAME_GROWS_DOWNWARD)
351 return -f->x_frame_offset;
352 else
353 return f->x_frame_offset;
356 /* Return size needed for stack frame based on slots so far allocated.
357 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
358 the caller may have to do that. */
360 HOST_WIDE_INT
361 get_frame_size (void)
363 return get_func_frame_size (cfun);
366 /* Issue an error message and return TRUE if frame OFFSET overflows in
367 the signed target pointer arithmetics for function FUNC. Otherwise
368 return FALSE. */
370 bool
371 frame_offset_overflow (HOST_WIDE_INT offset, tree func)
373 unsigned HOST_WIDE_INT size = FRAME_GROWS_DOWNWARD ? -offset : offset;
375 if (size > ((unsigned HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (Pmode) - 1))
376 /* Leave room for the fixed part of the frame. */
377 - 64 * UNITS_PER_WORD)
379 error ("%Jtotal size of local objects too large", func);
380 return TRUE;
383 return FALSE;
386 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
387 with machine mode MODE.
389 ALIGN controls the amount of alignment for the address of the slot:
390 0 means according to MODE,
391 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
392 -2 means use BITS_PER_UNIT,
393 positive specifies alignment boundary in bits.
395 We do not round to stack_boundary here.
397 FUNCTION specifies the function to allocate in. */
399 static rtx
400 assign_stack_local_1 (enum machine_mode mode, HOST_WIDE_INT size, int align,
401 struct function *function)
403 rtx x, addr;
404 int bigend_correction = 0;
405 unsigned int alignment;
406 int frame_off, frame_alignment, frame_phase;
408 if (align == 0)
410 tree type;
412 if (mode == BLKmode)
413 alignment = BIGGEST_ALIGNMENT;
414 else
415 alignment = GET_MODE_ALIGNMENT (mode);
417 /* Allow the target to (possibly) increase the alignment of this
418 stack slot. */
419 type = lang_hooks.types.type_for_mode (mode, 0);
420 if (type)
421 alignment = LOCAL_ALIGNMENT (type, alignment);
423 alignment /= BITS_PER_UNIT;
425 else if (align == -1)
427 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
428 size = CEIL_ROUND (size, alignment);
430 else if (align == -2)
431 alignment = 1; /* BITS_PER_UNIT / BITS_PER_UNIT */
432 else
433 alignment = align / BITS_PER_UNIT;
435 if (FRAME_GROWS_DOWNWARD)
436 function->x_frame_offset -= size;
438 /* Ignore alignment we can't do with expected alignment of the boundary. */
439 if (alignment * BITS_PER_UNIT > PREFERRED_STACK_BOUNDARY)
440 alignment = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
442 if (function->stack_alignment_needed < alignment * BITS_PER_UNIT)
443 function->stack_alignment_needed = alignment * BITS_PER_UNIT;
445 /* Calculate how many bytes the start of local variables is off from
446 stack alignment. */
447 frame_alignment = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
448 frame_off = STARTING_FRAME_OFFSET % frame_alignment;
449 frame_phase = frame_off ? frame_alignment - frame_off : 0;
451 /* Round the frame offset to the specified alignment. The default is
452 to always honor requests to align the stack but a port may choose to
453 do its own stack alignment by defining STACK_ALIGNMENT_NEEDED. */
454 if (STACK_ALIGNMENT_NEEDED
455 || mode != BLKmode
456 || size != 0)
458 /* We must be careful here, since FRAME_OFFSET might be negative and
459 division with a negative dividend isn't as well defined as we might
460 like. So we instead assume that ALIGNMENT is a power of two and
461 use logical operations which are unambiguous. */
462 if (FRAME_GROWS_DOWNWARD)
463 function->x_frame_offset
464 = (FLOOR_ROUND (function->x_frame_offset - frame_phase,
465 (unsigned HOST_WIDE_INT) alignment)
466 + frame_phase);
467 else
468 function->x_frame_offset
469 = (CEIL_ROUND (function->x_frame_offset - frame_phase,
470 (unsigned HOST_WIDE_INT) alignment)
471 + frame_phase);
474 /* On a big-endian machine, if we are allocating more space than we will use,
475 use the least significant bytes of those that are allocated. */
476 if (BYTES_BIG_ENDIAN && mode != BLKmode && GET_MODE_SIZE (mode) < size)
477 bigend_correction = size - GET_MODE_SIZE (mode);
479 /* If we have already instantiated virtual registers, return the actual
480 address relative to the frame pointer. */
481 if (function == cfun && virtuals_instantiated)
482 addr = plus_constant (frame_pointer_rtx,
483 trunc_int_for_mode
484 (frame_offset + bigend_correction
485 + STARTING_FRAME_OFFSET, Pmode));
486 else
487 addr = plus_constant (virtual_stack_vars_rtx,
488 trunc_int_for_mode
489 (function->x_frame_offset + bigend_correction,
490 Pmode));
492 if (!FRAME_GROWS_DOWNWARD)
493 function->x_frame_offset += size;
495 x = gen_rtx_MEM (mode, addr);
496 MEM_NOTRAP_P (x) = 1;
498 function->x_stack_slot_list
499 = gen_rtx_EXPR_LIST (VOIDmode, x, function->x_stack_slot_list);
501 if (frame_offset_overflow (function->x_frame_offset, function->decl))
502 function->x_frame_offset = 0;
504 return x;
507 /* Wrapper around assign_stack_local_1; assign a local stack slot for the
508 current function. */
511 assign_stack_local (enum machine_mode mode, HOST_WIDE_INT size, int align)
513 return assign_stack_local_1 (mode, size, align, cfun);
517 /* Removes temporary slot TEMP from LIST. */
519 static void
520 cut_slot_from_list (struct temp_slot *temp, struct temp_slot **list)
522 if (temp->next)
523 temp->next->prev = temp->prev;
524 if (temp->prev)
525 temp->prev->next = temp->next;
526 else
527 *list = temp->next;
529 temp->prev = temp->next = NULL;
532 /* Inserts temporary slot TEMP to LIST. */
534 static void
535 insert_slot_to_list (struct temp_slot *temp, struct temp_slot **list)
537 temp->next = *list;
538 if (*list)
539 (*list)->prev = temp;
540 temp->prev = NULL;
541 *list = temp;
544 /* Returns the list of used temp slots at LEVEL. */
546 static struct temp_slot **
547 temp_slots_at_level (int level)
549 if (level >= (int) VEC_length (temp_slot_p, used_temp_slots))
551 size_t old_length = VEC_length (temp_slot_p, used_temp_slots);
552 temp_slot_p *p;
554 VEC_safe_grow (temp_slot_p, gc, used_temp_slots, level + 1);
555 p = VEC_address (temp_slot_p, used_temp_slots);
556 memset (&p[old_length], 0,
557 sizeof (temp_slot_p) * (level + 1 - old_length));
560 return &(VEC_address (temp_slot_p, used_temp_slots)[level]);
563 /* Returns the maximal temporary slot level. */
565 static int
566 max_slot_level (void)
568 if (!used_temp_slots)
569 return -1;
571 return VEC_length (temp_slot_p, used_temp_slots) - 1;
574 /* Moves temporary slot TEMP to LEVEL. */
576 static void
577 move_slot_to_level (struct temp_slot *temp, int level)
579 cut_slot_from_list (temp, temp_slots_at_level (temp->level));
580 insert_slot_to_list (temp, temp_slots_at_level (level));
581 temp->level = level;
584 /* Make temporary slot TEMP available. */
586 static void
587 make_slot_available (struct temp_slot *temp)
589 cut_slot_from_list (temp, temp_slots_at_level (temp->level));
590 insert_slot_to_list (temp, &avail_temp_slots);
591 temp->in_use = 0;
592 temp->level = -1;
595 /* Allocate a temporary stack slot and record it for possible later
596 reuse.
598 MODE is the machine mode to be given to the returned rtx.
600 SIZE is the size in units of the space required. We do no rounding here
601 since assign_stack_local will do any required rounding.
603 KEEP is 1 if this slot is to be retained after a call to
604 free_temp_slots. Automatic variables for a block are allocated
605 with this flag. KEEP values of 2 or 3 were needed respectively
606 for variables whose lifetime is controlled by CLEANUP_POINT_EXPRs
607 or for SAVE_EXPRs, but they are now unused.
609 TYPE is the type that will be used for the stack slot. */
612 assign_stack_temp_for_type (enum machine_mode mode, HOST_WIDE_INT size,
613 int keep, tree type)
615 unsigned int align;
616 struct temp_slot *p, *best_p = 0, *selected = NULL, **pp;
617 rtx slot;
619 /* If SIZE is -1 it means that somebody tried to allocate a temporary
620 of a variable size. */
621 gcc_assert (size != -1);
623 /* These are now unused. */
624 gcc_assert (keep <= 1);
626 if (mode == BLKmode)
627 align = BIGGEST_ALIGNMENT;
628 else
629 align = GET_MODE_ALIGNMENT (mode);
631 if (! type)
632 type = lang_hooks.types.type_for_mode (mode, 0);
634 if (type)
635 align = LOCAL_ALIGNMENT (type, align);
637 /* Try to find an available, already-allocated temporary of the proper
638 mode which meets the size and alignment requirements. Choose the
639 smallest one with the closest alignment.
641 If assign_stack_temp is called outside of the tree->rtl expansion,
642 we cannot reuse the stack slots (that may still refer to
643 VIRTUAL_STACK_VARS_REGNUM). */
644 if (!virtuals_instantiated)
646 for (p = avail_temp_slots; p; p = p->next)
648 if (p->align >= align && p->size >= size
649 && GET_MODE (p->slot) == mode
650 && objects_must_conflict_p (p->type, type)
651 && (best_p == 0 || best_p->size > p->size
652 || (best_p->size == p->size && best_p->align > p->align)))
654 if (p->align == align && p->size == size)
656 selected = p;
657 cut_slot_from_list (selected, &avail_temp_slots);
658 best_p = 0;
659 break;
661 best_p = p;
666 /* Make our best, if any, the one to use. */
667 if (best_p)
669 selected = best_p;
670 cut_slot_from_list (selected, &avail_temp_slots);
672 /* If there are enough aligned bytes left over, make them into a new
673 temp_slot so that the extra bytes don't get wasted. Do this only
674 for BLKmode slots, so that we can be sure of the alignment. */
675 if (GET_MODE (best_p->slot) == BLKmode)
677 int alignment = best_p->align / BITS_PER_UNIT;
678 HOST_WIDE_INT rounded_size = CEIL_ROUND (size, alignment);
680 if (best_p->size - rounded_size >= alignment)
682 p = ggc_alloc (sizeof (struct temp_slot));
683 p->in_use = p->addr_taken = 0;
684 p->size = best_p->size - rounded_size;
685 p->base_offset = best_p->base_offset + rounded_size;
686 p->full_size = best_p->full_size - rounded_size;
687 p->slot = adjust_address_nv (best_p->slot, BLKmode, rounded_size);
688 p->align = best_p->align;
689 p->address = 0;
690 p->type = best_p->type;
691 insert_slot_to_list (p, &avail_temp_slots);
693 stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, p->slot,
694 stack_slot_list);
696 best_p->size = rounded_size;
697 best_p->full_size = rounded_size;
702 /* If we still didn't find one, make a new temporary. */
703 if (selected == 0)
705 HOST_WIDE_INT frame_offset_old = frame_offset;
707 p = ggc_alloc (sizeof (struct temp_slot));
709 /* We are passing an explicit alignment request to assign_stack_local.
710 One side effect of that is assign_stack_local will not round SIZE
711 to ensure the frame offset remains suitably aligned.
713 So for requests which depended on the rounding of SIZE, we go ahead
714 and round it now. We also make sure ALIGNMENT is at least
715 BIGGEST_ALIGNMENT. */
716 gcc_assert (mode != BLKmode || align == BIGGEST_ALIGNMENT);
717 p->slot = assign_stack_local (mode,
718 (mode == BLKmode
719 ? CEIL_ROUND (size, (int) align / BITS_PER_UNIT)
720 : size),
721 align);
723 p->align = align;
725 /* The following slot size computation is necessary because we don't
726 know the actual size of the temporary slot until assign_stack_local
727 has performed all the frame alignment and size rounding for the
728 requested temporary. Note that extra space added for alignment
729 can be either above or below this stack slot depending on which
730 way the frame grows. We include the extra space if and only if it
731 is above this slot. */
732 if (FRAME_GROWS_DOWNWARD)
733 p->size = frame_offset_old - frame_offset;
734 else
735 p->size = size;
737 /* Now define the fields used by combine_temp_slots. */
738 if (FRAME_GROWS_DOWNWARD)
740 p->base_offset = frame_offset;
741 p->full_size = frame_offset_old - frame_offset;
743 else
745 p->base_offset = frame_offset_old;
746 p->full_size = frame_offset - frame_offset_old;
748 p->address = 0;
750 selected = p;
753 p = selected;
754 p->in_use = 1;
755 p->addr_taken = 0;
756 p->type = type;
757 p->level = temp_slot_level;
758 p->keep = keep;
760 pp = temp_slots_at_level (p->level);
761 insert_slot_to_list (p, pp);
763 /* Create a new MEM rtx to avoid clobbering MEM flags of old slots. */
764 slot = gen_rtx_MEM (mode, XEXP (p->slot, 0));
765 stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, slot, stack_slot_list);
767 /* If we know the alias set for the memory that will be used, use
768 it. If there's no TYPE, then we don't know anything about the
769 alias set for the memory. */
770 set_mem_alias_set (slot, type ? get_alias_set (type) : 0);
771 set_mem_align (slot, align);
773 /* If a type is specified, set the relevant flags. */
774 if (type != 0)
776 MEM_VOLATILE_P (slot) = TYPE_VOLATILE (type);
777 MEM_SET_IN_STRUCT_P (slot, AGGREGATE_TYPE_P (type));
779 MEM_NOTRAP_P (slot) = 1;
781 return slot;
784 /* Allocate a temporary stack slot and record it for possible later
785 reuse. First three arguments are same as in preceding function. */
788 assign_stack_temp (enum machine_mode mode, HOST_WIDE_INT size, int keep)
790 return assign_stack_temp_for_type (mode, size, keep, NULL_TREE);
793 /* Assign a temporary.
794 If TYPE_OR_DECL is a decl, then we are doing it on behalf of the decl
795 and so that should be used in error messages. In either case, we
796 allocate of the given type.
797 KEEP is as for assign_stack_temp.
798 MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
799 it is 0 if a register is OK.
800 DONT_PROMOTE is 1 if we should not promote values in register
801 to wider modes. */
804 assign_temp (tree type_or_decl, int keep, int memory_required,
805 int dont_promote ATTRIBUTE_UNUSED)
807 tree type, decl;
808 enum machine_mode mode;
809 #ifdef PROMOTE_MODE
810 int unsignedp;
811 #endif
813 if (DECL_P (type_or_decl))
814 decl = type_or_decl, type = TREE_TYPE (decl);
815 else
816 decl = NULL, type = type_or_decl;
818 mode = TYPE_MODE (type);
819 #ifdef PROMOTE_MODE
820 unsignedp = TYPE_UNSIGNED (type);
821 #endif
823 if (mode == BLKmode || memory_required)
825 HOST_WIDE_INT size = int_size_in_bytes (type);
826 tree size_tree;
827 rtx tmp;
829 /* Zero sized arrays are GNU C extension. Set size to 1 to avoid
830 problems with allocating the stack space. */
831 if (size == 0)
832 size = 1;
834 /* Unfortunately, we don't yet know how to allocate variable-sized
835 temporaries. However, sometimes we have a fixed upper limit on
836 the size (which is stored in TYPE_ARRAY_MAX_SIZE) and can use that
837 instead. This is the case for Chill variable-sized strings. */
838 if (size == -1 && TREE_CODE (type) == ARRAY_TYPE
839 && TYPE_ARRAY_MAX_SIZE (type) != NULL_TREE
840 && host_integerp (TYPE_ARRAY_MAX_SIZE (type), 1))
841 size = tree_low_cst (TYPE_ARRAY_MAX_SIZE (type), 1);
843 /* If we still haven't been able to get a size, see if the language
844 can compute a maximum size. */
845 if (size == -1
846 && (size_tree = lang_hooks.types.max_size (type)) != 0
847 && host_integerp (size_tree, 1))
848 size = tree_low_cst (size_tree, 1);
850 /* The size of the temporary may be too large to fit into an integer. */
851 /* ??? Not sure this should happen except for user silliness, so limit
852 this to things that aren't compiler-generated temporaries. The
853 rest of the time we'll die in assign_stack_temp_for_type. */
854 if (decl && size == -1
855 && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST)
857 error ("size of variable %q+D is too large", decl);
858 size = 1;
861 tmp = assign_stack_temp_for_type (mode, size, keep, type);
862 return tmp;
865 #ifdef PROMOTE_MODE
866 if (! dont_promote)
867 mode = promote_mode (type, mode, &unsignedp, 0);
868 #endif
870 return gen_reg_rtx (mode);
873 /* Combine temporary stack slots which are adjacent on the stack.
875 This allows for better use of already allocated stack space. This is only
876 done for BLKmode slots because we can be sure that we won't have alignment
877 problems in this case. */
879 static void
880 combine_temp_slots (void)
882 struct temp_slot *p, *q, *next, *next_q;
883 int num_slots;
885 /* We can't combine slots, because the information about which slot
886 is in which alias set will be lost. */
887 if (flag_strict_aliasing)
888 return;
890 /* If there are a lot of temp slots, don't do anything unless
891 high levels of optimization. */
892 if (! flag_expensive_optimizations)
893 for (p = avail_temp_slots, num_slots = 0; p; p = p->next, num_slots++)
894 if (num_slots > 100 || (num_slots > 10 && optimize == 0))
895 return;
897 for (p = avail_temp_slots; p; p = next)
899 int delete_p = 0;
901 next = p->next;
903 if (GET_MODE (p->slot) != BLKmode)
904 continue;
906 for (q = p->next; q; q = next_q)
908 int delete_q = 0;
910 next_q = q->next;
912 if (GET_MODE (q->slot) != BLKmode)
913 continue;
915 if (p->base_offset + p->full_size == q->base_offset)
917 /* Q comes after P; combine Q into P. */
918 p->size += q->size;
919 p->full_size += q->full_size;
920 delete_q = 1;
922 else if (q->base_offset + q->full_size == p->base_offset)
924 /* P comes after Q; combine P into Q. */
925 q->size += p->size;
926 q->full_size += p->full_size;
927 delete_p = 1;
928 break;
930 if (delete_q)
931 cut_slot_from_list (q, &avail_temp_slots);
934 /* Either delete P or advance past it. */
935 if (delete_p)
936 cut_slot_from_list (p, &avail_temp_slots);
940 /* Find the temp slot corresponding to the object at address X. */
942 static struct temp_slot *
943 find_temp_slot_from_address (rtx x)
945 struct temp_slot *p;
946 rtx next;
947 int i;
949 for (i = max_slot_level (); i >= 0; i--)
950 for (p = *temp_slots_at_level (i); p; p = p->next)
952 if (XEXP (p->slot, 0) == x
953 || p->address == x
954 || (GET_CODE (x) == PLUS
955 && XEXP (x, 0) == virtual_stack_vars_rtx
956 && GET_CODE (XEXP (x, 1)) == CONST_INT
957 && INTVAL (XEXP (x, 1)) >= p->base_offset
958 && INTVAL (XEXP (x, 1)) < p->base_offset + p->full_size))
959 return p;
961 else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST)
962 for (next = p->address; next; next = XEXP (next, 1))
963 if (XEXP (next, 0) == x)
964 return p;
967 /* If we have a sum involving a register, see if it points to a temp
968 slot. */
969 if (GET_CODE (x) == PLUS && REG_P (XEXP (x, 0))
970 && (p = find_temp_slot_from_address (XEXP (x, 0))) != 0)
971 return p;
972 else if (GET_CODE (x) == PLUS && REG_P (XEXP (x, 1))
973 && (p = find_temp_slot_from_address (XEXP (x, 1))) != 0)
974 return p;
976 return 0;
979 /* Indicate that NEW is an alternate way of referring to the temp slot
980 that previously was known by OLD. */
982 void
983 update_temp_slot_address (rtx old, rtx new)
985 struct temp_slot *p;
987 if (rtx_equal_p (old, new))
988 return;
990 p = find_temp_slot_from_address (old);
992 /* If we didn't find one, see if both OLD is a PLUS. If so, and NEW
993 is a register, see if one operand of the PLUS is a temporary
994 location. If so, NEW points into it. Otherwise, if both OLD and
995 NEW are a PLUS and if there is a register in common between them.
996 If so, try a recursive call on those values. */
997 if (p == 0)
999 if (GET_CODE (old) != PLUS)
1000 return;
1002 if (REG_P (new))
1004 update_temp_slot_address (XEXP (old, 0), new);
1005 update_temp_slot_address (XEXP (old, 1), new);
1006 return;
1008 else if (GET_CODE (new) != PLUS)
1009 return;
1011 if (rtx_equal_p (XEXP (old, 0), XEXP (new, 0)))
1012 update_temp_slot_address (XEXP (old, 1), XEXP (new, 1));
1013 else if (rtx_equal_p (XEXP (old, 1), XEXP (new, 0)))
1014 update_temp_slot_address (XEXP (old, 0), XEXP (new, 1));
1015 else if (rtx_equal_p (XEXP (old, 0), XEXP (new, 1)))
1016 update_temp_slot_address (XEXP (old, 1), XEXP (new, 0));
1017 else if (rtx_equal_p (XEXP (old, 1), XEXP (new, 1)))
1018 update_temp_slot_address (XEXP (old, 0), XEXP (new, 0));
1020 return;
1023 /* Otherwise add an alias for the temp's address. */
1024 else if (p->address == 0)
1025 p->address = new;
1026 else
1028 if (GET_CODE (p->address) != EXPR_LIST)
1029 p->address = gen_rtx_EXPR_LIST (VOIDmode, p->address, NULL_RTX);
1031 p->address = gen_rtx_EXPR_LIST (VOIDmode, new, p->address);
1035 /* If X could be a reference to a temporary slot, mark the fact that its
1036 address was taken. */
1038 void
1039 mark_temp_addr_taken (rtx x)
1041 struct temp_slot *p;
1043 if (x == 0)
1044 return;
1046 /* If X is not in memory or is at a constant address, it cannot be in
1047 a temporary slot. */
1048 if (!MEM_P (x) || CONSTANT_P (XEXP (x, 0)))
1049 return;
1051 p = find_temp_slot_from_address (XEXP (x, 0));
1052 if (p != 0)
1053 p->addr_taken = 1;
1056 /* If X could be a reference to a temporary slot, mark that slot as
1057 belonging to the to one level higher than the current level. If X
1058 matched one of our slots, just mark that one. Otherwise, we can't
1059 easily predict which it is, so upgrade all of them. Kept slots
1060 need not be touched.
1062 This is called when an ({...}) construct occurs and a statement
1063 returns a value in memory. */
1065 void
1066 preserve_temp_slots (rtx x)
1068 struct temp_slot *p = 0, *next;
1070 /* If there is no result, we still might have some objects whose address
1071 were taken, so we need to make sure they stay around. */
1072 if (x == 0)
1074 for (p = *temp_slots_at_level (temp_slot_level); p; p = next)
1076 next = p->next;
1078 if (p->addr_taken)
1079 move_slot_to_level (p, temp_slot_level - 1);
1082 return;
1085 /* If X is a register that is being used as a pointer, see if we have
1086 a temporary slot we know it points to. To be consistent with
1087 the code below, we really should preserve all non-kept slots
1088 if we can't find a match, but that seems to be much too costly. */
1089 if (REG_P (x) && REG_POINTER (x))
1090 p = find_temp_slot_from_address (x);
1092 /* If X is not in memory or is at a constant address, it cannot be in
1093 a temporary slot, but it can contain something whose address was
1094 taken. */
1095 if (p == 0 && (!MEM_P (x) || CONSTANT_P (XEXP (x, 0))))
1097 for (p = *temp_slots_at_level (temp_slot_level); p; p = next)
1099 next = p->next;
1101 if (p->addr_taken)
1102 move_slot_to_level (p, temp_slot_level - 1);
1105 return;
1108 /* First see if we can find a match. */
1109 if (p == 0)
1110 p = find_temp_slot_from_address (XEXP (x, 0));
1112 if (p != 0)
1114 /* Move everything at our level whose address was taken to our new
1115 level in case we used its address. */
1116 struct temp_slot *q;
1118 if (p->level == temp_slot_level)
1120 for (q = *temp_slots_at_level (temp_slot_level); q; q = next)
1122 next = q->next;
1124 if (p != q && q->addr_taken)
1125 move_slot_to_level (q, temp_slot_level - 1);
1128 move_slot_to_level (p, temp_slot_level - 1);
1129 p->addr_taken = 0;
1131 return;
1134 /* Otherwise, preserve all non-kept slots at this level. */
1135 for (p = *temp_slots_at_level (temp_slot_level); p; p = next)
1137 next = p->next;
1139 if (!p->keep)
1140 move_slot_to_level (p, temp_slot_level - 1);
1144 /* Free all temporaries used so far. This is normally called at the
1145 end of generating code for a statement. */
1147 void
1148 free_temp_slots (void)
1150 struct temp_slot *p, *next;
1152 for (p = *temp_slots_at_level (temp_slot_level); p; p = next)
1154 next = p->next;
1156 if (!p->keep)
1157 make_slot_available (p);
1160 combine_temp_slots ();
1163 /* Push deeper into the nesting level for stack temporaries. */
1165 void
1166 push_temp_slots (void)
1168 temp_slot_level++;
1171 /* Pop a temporary nesting level. All slots in use in the current level
1172 are freed. */
1174 void
1175 pop_temp_slots (void)
1177 struct temp_slot *p, *next;
1179 for (p = *temp_slots_at_level (temp_slot_level); p; p = next)
1181 next = p->next;
1182 make_slot_available (p);
1185 combine_temp_slots ();
1187 temp_slot_level--;
1190 /* Initialize temporary slots. */
1192 void
1193 init_temp_slots (void)
1195 /* We have not allocated any temporaries yet. */
1196 avail_temp_slots = 0;
1197 used_temp_slots = 0;
1198 temp_slot_level = 0;
1201 /* These routines are responsible for converting virtual register references
1202 to the actual hard register references once RTL generation is complete.
1204 The following four variables are used for communication between the
1205 routines. They contain the offsets of the virtual registers from their
1206 respective hard registers. */
1208 static int in_arg_offset;
1209 static int var_offset;
1210 static int dynamic_offset;
1211 static int out_arg_offset;
1212 static int cfa_offset;
1214 /* In most machines, the stack pointer register is equivalent to the bottom
1215 of the stack. */
1217 #ifndef STACK_POINTER_OFFSET
1218 #define STACK_POINTER_OFFSET 0
1219 #endif
1221 /* If not defined, pick an appropriate default for the offset of dynamically
1222 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
1223 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
1225 #ifndef STACK_DYNAMIC_OFFSET
1227 /* The bottom of the stack points to the actual arguments. If
1228 REG_PARM_STACK_SPACE is defined, this includes the space for the register
1229 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
1230 stack space for register parameters is not pushed by the caller, but
1231 rather part of the fixed stack areas and hence not included in
1232 `current_function_outgoing_args_size'. Nevertheless, we must allow
1233 for it when allocating stack dynamic objects. */
1235 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
1236 #define STACK_DYNAMIC_OFFSET(FNDECL) \
1237 ((ACCUMULATE_OUTGOING_ARGS \
1238 ? (current_function_outgoing_args_size + REG_PARM_STACK_SPACE (FNDECL)) : 0)\
1239 + (STACK_POINTER_OFFSET)) \
1241 #else
1242 #define STACK_DYNAMIC_OFFSET(FNDECL) \
1243 ((ACCUMULATE_OUTGOING_ARGS ? current_function_outgoing_args_size : 0) \
1244 + (STACK_POINTER_OFFSET))
1245 #endif
1246 #endif
1249 /* Given a piece of RTX and a pointer to a HOST_WIDE_INT, if the RTX
1250 is a virtual register, return the equivalent hard register and set the
1251 offset indirectly through the pointer. Otherwise, return 0. */
1253 static rtx
1254 instantiate_new_reg (rtx x, HOST_WIDE_INT *poffset)
1256 rtx new;
1257 HOST_WIDE_INT offset;
1259 if (x == virtual_incoming_args_rtx)
1260 new = arg_pointer_rtx, offset = in_arg_offset;
1261 else if (x == virtual_stack_vars_rtx)
1262 new = frame_pointer_rtx, offset = var_offset;
1263 else if (x == virtual_stack_dynamic_rtx)
1264 new = stack_pointer_rtx, offset = dynamic_offset;
1265 else if (x == virtual_outgoing_args_rtx)
1266 new = stack_pointer_rtx, offset = out_arg_offset;
1267 else if (x == virtual_cfa_rtx)
1269 #ifdef FRAME_POINTER_CFA_OFFSET
1270 new = frame_pointer_rtx;
1271 #else
1272 new = arg_pointer_rtx;
1273 #endif
1274 offset = cfa_offset;
1276 else
1277 return NULL_RTX;
1279 *poffset = offset;
1280 return new;
1283 /* A subroutine of instantiate_virtual_regs, called via for_each_rtx.
1284 Instantiate any virtual registers present inside of *LOC. The expression
1285 is simplified, as much as possible, but is not to be considered "valid"
1286 in any sense implied by the target. If any change is made, set CHANGED
1287 to true. */
1289 static int
1290 instantiate_virtual_regs_in_rtx (rtx *loc, void *data)
1292 HOST_WIDE_INT offset;
1293 bool *changed = (bool *) data;
1294 rtx x, new;
1296 x = *loc;
1297 if (x == 0)
1298 return 0;
1300 switch (GET_CODE (x))
1302 case REG:
1303 new = instantiate_new_reg (x, &offset);
1304 if (new)
1306 *loc = plus_constant (new, offset);
1307 if (changed)
1308 *changed = true;
1310 return -1;
1312 case PLUS:
1313 new = instantiate_new_reg (XEXP (x, 0), &offset);
1314 if (new)
1316 new = plus_constant (new, offset);
1317 *loc = simplify_gen_binary (PLUS, GET_MODE (x), new, XEXP (x, 1));
1318 if (changed)
1319 *changed = true;
1320 return -1;
1323 /* FIXME -- from old code */
1324 /* If we have (plus (subreg (virtual-reg)) (const_int)), we know
1325 we can commute the PLUS and SUBREG because pointers into the
1326 frame are well-behaved. */
1327 break;
1329 default:
1330 break;
1333 return 0;
1336 /* A subroutine of instantiate_virtual_regs_in_insn. Return true if X
1337 matches the predicate for insn CODE operand OPERAND. */
1339 static int
1340 safe_insn_predicate (int code, int operand, rtx x)
1342 const struct insn_operand_data *op_data;
1344 if (code < 0)
1345 return true;
1347 op_data = &insn_data[code].operand[operand];
1348 if (op_data->predicate == NULL)
1349 return true;
1351 return op_data->predicate (x, op_data->mode);
1354 /* A subroutine of instantiate_virtual_regs. Instantiate any virtual
1355 registers present inside of insn. The result will be a valid insn. */
1357 static void
1358 instantiate_virtual_regs_in_insn (rtx insn)
1360 HOST_WIDE_INT offset;
1361 int insn_code, i;
1362 bool any_change = false;
1363 rtx set, new, x, seq;
1365 /* There are some special cases to be handled first. */
1366 set = single_set (insn);
1367 if (set)
1369 /* We're allowed to assign to a virtual register. This is interpreted
1370 to mean that the underlying register gets assigned the inverse
1371 transformation. This is used, for example, in the handling of
1372 non-local gotos. */
1373 new = instantiate_new_reg (SET_DEST (set), &offset);
1374 if (new)
1376 start_sequence ();
1378 for_each_rtx (&SET_SRC (set), instantiate_virtual_regs_in_rtx, NULL);
1379 x = simplify_gen_binary (PLUS, GET_MODE (new), SET_SRC (set),
1380 GEN_INT (-offset));
1381 x = force_operand (x, new);
1382 if (x != new)
1383 emit_move_insn (new, x);
1385 seq = get_insns ();
1386 end_sequence ();
1388 emit_insn_before (seq, insn);
1389 delete_insn (insn);
1390 return;
1393 /* Handle a straight copy from a virtual register by generating a
1394 new add insn. The difference between this and falling through
1395 to the generic case is avoiding a new pseudo and eliminating a
1396 move insn in the initial rtl stream. */
1397 new = instantiate_new_reg (SET_SRC (set), &offset);
1398 if (new && offset != 0
1399 && REG_P (SET_DEST (set))
1400 && REGNO (SET_DEST (set)) > LAST_VIRTUAL_REGISTER)
1402 start_sequence ();
1404 x = expand_simple_binop (GET_MODE (SET_DEST (set)), PLUS,
1405 new, GEN_INT (offset), SET_DEST (set),
1406 1, OPTAB_LIB_WIDEN);
1407 if (x != SET_DEST (set))
1408 emit_move_insn (SET_DEST (set), x);
1410 seq = get_insns ();
1411 end_sequence ();
1413 emit_insn_before (seq, insn);
1414 delete_insn (insn);
1415 return;
1418 extract_insn (insn);
1419 insn_code = INSN_CODE (insn);
1421 /* Handle a plus involving a virtual register by determining if the
1422 operands remain valid if they're modified in place. */
1423 if (GET_CODE (SET_SRC (set)) == PLUS
1424 && recog_data.n_operands >= 3
1425 && recog_data.operand_loc[1] == &XEXP (SET_SRC (set), 0)
1426 && recog_data.operand_loc[2] == &XEXP (SET_SRC (set), 1)
1427 && GET_CODE (recog_data.operand[2]) == CONST_INT
1428 && (new = instantiate_new_reg (recog_data.operand[1], &offset)))
1430 offset += INTVAL (recog_data.operand[2]);
1432 /* If the sum is zero, then replace with a plain move. */
1433 if (offset == 0
1434 && REG_P (SET_DEST (set))
1435 && REGNO (SET_DEST (set)) > LAST_VIRTUAL_REGISTER)
1437 start_sequence ();
1438 emit_move_insn (SET_DEST (set), new);
1439 seq = get_insns ();
1440 end_sequence ();
1442 emit_insn_before (seq, insn);
1443 delete_insn (insn);
1444 return;
1447 x = gen_int_mode (offset, recog_data.operand_mode[2]);
1449 /* Using validate_change and apply_change_group here leaves
1450 recog_data in an invalid state. Since we know exactly what
1451 we want to check, do those two by hand. */
1452 if (safe_insn_predicate (insn_code, 1, new)
1453 && safe_insn_predicate (insn_code, 2, x))
1455 *recog_data.operand_loc[1] = recog_data.operand[1] = new;
1456 *recog_data.operand_loc[2] = recog_data.operand[2] = x;
1457 any_change = true;
1459 /* Fall through into the regular operand fixup loop in
1460 order to take care of operands other than 1 and 2. */
1464 else
1466 extract_insn (insn);
1467 insn_code = INSN_CODE (insn);
1470 /* In the general case, we expect virtual registers to appear only in
1471 operands, and then only as either bare registers or inside memories. */
1472 for (i = 0; i < recog_data.n_operands; ++i)
1474 x = recog_data.operand[i];
1475 switch (GET_CODE (x))
1477 case MEM:
1479 rtx addr = XEXP (x, 0);
1480 bool changed = false;
1482 for_each_rtx (&addr, instantiate_virtual_regs_in_rtx, &changed);
1483 if (!changed)
1484 continue;
1486 start_sequence ();
1487 x = replace_equiv_address (x, addr);
1488 seq = get_insns ();
1489 end_sequence ();
1490 if (seq)
1491 emit_insn_before (seq, insn);
1493 break;
1495 case REG:
1496 new = instantiate_new_reg (x, &offset);
1497 if (new == NULL)
1498 continue;
1499 if (offset == 0)
1500 x = new;
1501 else
1503 start_sequence ();
1505 /* Careful, special mode predicates may have stuff in
1506 insn_data[insn_code].operand[i].mode that isn't useful
1507 to us for computing a new value. */
1508 /* ??? Recognize address_operand and/or "p" constraints
1509 to see if (plus new offset) is a valid before we put
1510 this through expand_simple_binop. */
1511 x = expand_simple_binop (GET_MODE (x), PLUS, new,
1512 GEN_INT (offset), NULL_RTX,
1513 1, OPTAB_LIB_WIDEN);
1514 seq = get_insns ();
1515 end_sequence ();
1516 emit_insn_before (seq, insn);
1518 break;
1520 case SUBREG:
1521 new = instantiate_new_reg (SUBREG_REG (x), &offset);
1522 if (new == NULL)
1523 continue;
1524 if (offset != 0)
1526 start_sequence ();
1527 new = expand_simple_binop (GET_MODE (new), PLUS, new,
1528 GEN_INT (offset), NULL_RTX,
1529 1, OPTAB_LIB_WIDEN);
1530 seq = get_insns ();
1531 end_sequence ();
1532 emit_insn_before (seq, insn);
1534 x = simplify_gen_subreg (recog_data.operand_mode[i], new,
1535 GET_MODE (new), SUBREG_BYTE (x));
1536 break;
1538 default:
1539 continue;
1542 /* At this point, X contains the new value for the operand.
1543 Validate the new value vs the insn predicate. Note that
1544 asm insns will have insn_code -1 here. */
1545 if (!safe_insn_predicate (insn_code, i, x))
1546 x = force_reg (insn_data[insn_code].operand[i].mode, x);
1548 *recog_data.operand_loc[i] = recog_data.operand[i] = x;
1549 any_change = true;
1552 if (any_change)
1554 /* Propagate operand changes into the duplicates. */
1555 for (i = 0; i < recog_data.n_dups; ++i)
1556 *recog_data.dup_loc[i]
1557 = recog_data.operand[(unsigned)recog_data.dup_num[i]];
1559 /* Force re-recognition of the instruction for validation. */
1560 INSN_CODE (insn) = -1;
1563 if (asm_noperands (PATTERN (insn)) >= 0)
1565 if (!check_asm_operands (PATTERN (insn)))
1567 error_for_asm (insn, "impossible constraint in %<asm%>");
1568 delete_insn (insn);
1571 else
1573 if (recog_memoized (insn) < 0)
1574 fatal_insn_not_found (insn);
1578 /* Subroutine of instantiate_decls. Given RTL representing a decl,
1579 do any instantiation required. */
1581 static void
1582 instantiate_decl (rtx x)
1584 rtx addr;
1586 if (x == 0)
1587 return;
1589 /* If this is a CONCAT, recurse for the pieces. */
1590 if (GET_CODE (x) == CONCAT)
1592 instantiate_decl (XEXP (x, 0));
1593 instantiate_decl (XEXP (x, 1));
1594 return;
1597 /* If this is not a MEM, no need to do anything. Similarly if the
1598 address is a constant or a register that is not a virtual register. */
1599 if (!MEM_P (x))
1600 return;
1602 addr = XEXP (x, 0);
1603 if (CONSTANT_P (addr)
1604 || (REG_P (addr)
1605 && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
1606 || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
1607 return;
1609 for_each_rtx (&XEXP (x, 0), instantiate_virtual_regs_in_rtx, NULL);
1612 /* Helper for instantiate_decls called via walk_tree: Process all decls
1613 in the given DECL_VALUE_EXPR. */
1615 static tree
1616 instantiate_expr (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
1618 tree t = *tp;
1619 if (! EXPR_P (t))
1621 *walk_subtrees = 0;
1622 if (DECL_P (t) && DECL_RTL_SET_P (t))
1623 instantiate_decl (DECL_RTL (t));
1625 return NULL;
1628 /* Subroutine of instantiate_decls: Process all decls in the given
1629 BLOCK node and all its subblocks. */
1631 static void
1632 instantiate_decls_1 (tree let)
1634 tree t;
1636 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
1638 if (DECL_RTL_SET_P (t))
1639 instantiate_decl (DECL_RTL (t));
1640 if (TREE_CODE (t) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (t))
1642 tree v = DECL_VALUE_EXPR (t);
1643 walk_tree (&v, instantiate_expr, NULL, NULL);
1647 /* Process all subblocks. */
1648 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
1649 instantiate_decls_1 (t);
1652 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
1653 all virtual registers in their DECL_RTL's. */
1655 static void
1656 instantiate_decls (tree fndecl)
1658 tree decl;
1660 /* Process all parameters of the function. */
1661 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
1663 instantiate_decl (DECL_RTL (decl));
1664 instantiate_decl (DECL_INCOMING_RTL (decl));
1665 if (DECL_HAS_VALUE_EXPR_P (decl))
1667 tree v = DECL_VALUE_EXPR (decl);
1668 walk_tree (&v, instantiate_expr, NULL, NULL);
1672 /* Now process all variables defined in the function or its subblocks. */
1673 instantiate_decls_1 (DECL_INITIAL (fndecl));
1676 /* Pass through the INSNS of function FNDECL and convert virtual register
1677 references to hard register references. */
1679 static unsigned int
1680 instantiate_virtual_regs (void)
1682 rtx insn;
1684 /* Compute the offsets to use for this function. */
1685 in_arg_offset = FIRST_PARM_OFFSET (current_function_decl);
1686 var_offset = STARTING_FRAME_OFFSET;
1687 dynamic_offset = STACK_DYNAMIC_OFFSET (current_function_decl);
1688 out_arg_offset = STACK_POINTER_OFFSET;
1689 #ifdef FRAME_POINTER_CFA_OFFSET
1690 cfa_offset = FRAME_POINTER_CFA_OFFSET (current_function_decl);
1691 #else
1692 cfa_offset = ARG_POINTER_CFA_OFFSET (current_function_decl);
1693 #endif
1695 /* Initialize recognition, indicating that volatile is OK. */
1696 init_recog ();
1698 /* Scan through all the insns, instantiating every virtual register still
1699 present. */
1700 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
1701 if (INSN_P (insn))
1703 /* These patterns in the instruction stream can never be recognized.
1704 Fortunately, they shouldn't contain virtual registers either. */
1705 if (GET_CODE (PATTERN (insn)) == USE
1706 || GET_CODE (PATTERN (insn)) == CLOBBER
1707 || GET_CODE (PATTERN (insn)) == ADDR_VEC
1708 || GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC
1709 || GET_CODE (PATTERN (insn)) == ASM_INPUT)
1710 continue;
1712 instantiate_virtual_regs_in_insn (insn);
1714 if (INSN_DELETED_P (insn))
1715 continue;
1717 for_each_rtx (&REG_NOTES (insn), instantiate_virtual_regs_in_rtx, NULL);
1719 /* Instantiate any virtual registers in CALL_INSN_FUNCTION_USAGE. */
1720 if (GET_CODE (insn) == CALL_INSN)
1721 for_each_rtx (&CALL_INSN_FUNCTION_USAGE (insn),
1722 instantiate_virtual_regs_in_rtx, NULL);
1725 /* Instantiate the virtual registers in the DECLs for debugging purposes. */
1726 instantiate_decls (current_function_decl);
1728 /* Indicate that, from now on, assign_stack_local should use
1729 frame_pointer_rtx. */
1730 virtuals_instantiated = 1;
1731 return 0;
1734 struct tree_opt_pass pass_instantiate_virtual_regs =
1736 "vregs", /* name */
1737 NULL, /* gate */
1738 instantiate_virtual_regs, /* execute */
1739 NULL, /* sub */
1740 NULL, /* next */
1741 0, /* static_pass_number */
1742 0, /* tv_id */
1743 0, /* properties_required */
1744 0, /* properties_provided */
1745 0, /* properties_destroyed */
1746 0, /* todo_flags_start */
1747 TODO_dump_func, /* todo_flags_finish */
1748 0 /* letter */
1752 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
1753 This means a type for which function calls must pass an address to the
1754 function or get an address back from the function.
1755 EXP may be a type node or an expression (whose type is tested). */
1758 aggregate_value_p (tree exp, tree fntype)
1760 int i, regno, nregs;
1761 rtx reg;
1763 tree type = (TYPE_P (exp)) ? exp : TREE_TYPE (exp);
1765 if (fntype)
1766 switch (TREE_CODE (fntype))
1768 case CALL_EXPR:
1769 fntype = get_callee_fndecl (fntype);
1770 fntype = fntype ? TREE_TYPE (fntype) : 0;
1771 break;
1772 case FUNCTION_DECL:
1773 fntype = TREE_TYPE (fntype);
1774 break;
1775 case FUNCTION_TYPE:
1776 case METHOD_TYPE:
1777 break;
1778 case IDENTIFIER_NODE:
1779 fntype = 0;
1780 break;
1781 default:
1782 /* We don't expect other rtl types here. */
1783 gcc_unreachable ();
1786 if (TREE_CODE (type) == VOID_TYPE)
1787 return 0;
1788 /* If the front end has decided that this needs to be passed by
1789 reference, do so. */
1790 if ((TREE_CODE (exp) == PARM_DECL || TREE_CODE (exp) == RESULT_DECL)
1791 && DECL_BY_REFERENCE (exp))
1792 return 1;
1793 if (targetm.calls.return_in_memory (type, fntype))
1794 return 1;
1795 /* Types that are TREE_ADDRESSABLE must be constructed in memory,
1796 and thus can't be returned in registers. */
1797 if (TREE_ADDRESSABLE (type))
1798 return 1;
1799 if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
1800 return 1;
1801 /* Make sure we have suitable call-clobbered regs to return
1802 the value in; if not, we must return it in memory. */
1803 reg = hard_function_value (type, 0, fntype, 0);
1805 /* If we have something other than a REG (e.g. a PARALLEL), then assume
1806 it is OK. */
1807 if (!REG_P (reg))
1808 return 0;
1810 regno = REGNO (reg);
1811 nregs = hard_regno_nregs[regno][TYPE_MODE (type)];
1812 for (i = 0; i < nregs; i++)
1813 if (! call_used_regs[regno + i])
1814 return 1;
1815 return 0;
1818 /* Return true if we should assign DECL a pseudo register; false if it
1819 should live on the local stack. */
1821 bool
1822 use_register_for_decl (tree decl)
1824 /* Honor volatile. */
1825 if (TREE_SIDE_EFFECTS (decl))
1826 return false;
1828 /* Honor addressability. */
1829 if (TREE_ADDRESSABLE (decl))
1830 return false;
1832 /* Only register-like things go in registers. */
1833 if (DECL_MODE (decl) == BLKmode)
1834 return false;
1836 /* If -ffloat-store specified, don't put explicit float variables
1837 into registers. */
1838 /* ??? This should be checked after DECL_ARTIFICIAL, but tree-ssa
1839 propagates values across these stores, and it probably shouldn't. */
1840 if (flag_float_store && FLOAT_TYPE_P (TREE_TYPE (decl)))
1841 return false;
1843 /* If we're not interested in tracking debugging information for
1844 this decl, then we can certainly put it in a register. */
1845 if (DECL_IGNORED_P (decl))
1846 return true;
1848 return (optimize || DECL_REGISTER (decl));
1851 /* Return true if TYPE should be passed by invisible reference. */
1853 bool
1854 pass_by_reference (CUMULATIVE_ARGS *ca, enum machine_mode mode,
1855 tree type, bool named_arg)
1857 if (type)
1859 /* If this type contains non-trivial constructors, then it is
1860 forbidden for the middle-end to create any new copies. */
1861 if (TREE_ADDRESSABLE (type))
1862 return true;
1864 /* GCC post 3.4 passes *all* variable sized types by reference. */
1865 if (!TYPE_SIZE (type) || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1866 return true;
1869 return targetm.calls.pass_by_reference (ca, mode, type, named_arg);
1872 /* Return true if TYPE, which is passed by reference, should be callee
1873 copied instead of caller copied. */
1875 bool
1876 reference_callee_copied (CUMULATIVE_ARGS *ca, enum machine_mode mode,
1877 tree type, bool named_arg)
1879 if (type && TREE_ADDRESSABLE (type))
1880 return false;
1881 return targetm.calls.callee_copies (ca, mode, type, named_arg);
1884 /* Structures to communicate between the subroutines of assign_parms.
1885 The first holds data persistent across all parameters, the second
1886 is cleared out for each parameter. */
1888 struct assign_parm_data_all
1890 CUMULATIVE_ARGS args_so_far;
1891 struct args_size stack_args_size;
1892 tree function_result_decl;
1893 tree orig_fnargs;
1894 rtx conversion_insns;
1895 HOST_WIDE_INT pretend_args_size;
1896 HOST_WIDE_INT extra_pretend_bytes;
1897 int reg_parm_stack_space;
1900 struct assign_parm_data_one
1902 tree nominal_type;
1903 tree passed_type;
1904 rtx entry_parm;
1905 rtx stack_parm;
1906 enum machine_mode nominal_mode;
1907 enum machine_mode passed_mode;
1908 enum machine_mode promoted_mode;
1909 struct locate_and_pad_arg_data locate;
1910 int partial;
1911 BOOL_BITFIELD named_arg : 1;
1912 BOOL_BITFIELD passed_pointer : 1;
1913 BOOL_BITFIELD on_stack : 1;
1914 BOOL_BITFIELD loaded_in_reg : 1;
1917 /* A subroutine of assign_parms. Initialize ALL. */
1919 static void
1920 assign_parms_initialize_all (struct assign_parm_data_all *all)
1922 tree fntype;
1924 memset (all, 0, sizeof (*all));
1926 fntype = TREE_TYPE (current_function_decl);
1928 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
1929 INIT_CUMULATIVE_INCOMING_ARGS (all->args_so_far, fntype, NULL_RTX);
1930 #else
1931 INIT_CUMULATIVE_ARGS (all->args_so_far, fntype, NULL_RTX,
1932 current_function_decl, -1);
1933 #endif
1935 #ifdef REG_PARM_STACK_SPACE
1936 all->reg_parm_stack_space = REG_PARM_STACK_SPACE (current_function_decl);
1937 #endif
1940 /* If ARGS contains entries with complex types, split the entry into two
1941 entries of the component type. Return a new list of substitutions are
1942 needed, else the old list. */
1944 static tree
1945 split_complex_args (tree args)
1947 tree p;
1949 /* Before allocating memory, check for the common case of no complex. */
1950 for (p = args; p; p = TREE_CHAIN (p))
1952 tree type = TREE_TYPE (p);
1953 if (TREE_CODE (type) == COMPLEX_TYPE
1954 && targetm.calls.split_complex_arg (type))
1955 goto found;
1957 return args;
1959 found:
1960 args = copy_list (args);
1962 for (p = args; p; p = TREE_CHAIN (p))
1964 tree type = TREE_TYPE (p);
1965 if (TREE_CODE (type) == COMPLEX_TYPE
1966 && targetm.calls.split_complex_arg (type))
1968 tree decl;
1969 tree subtype = TREE_TYPE (type);
1970 bool addressable = TREE_ADDRESSABLE (p);
1972 /* Rewrite the PARM_DECL's type with its component. */
1973 TREE_TYPE (p) = subtype;
1974 DECL_ARG_TYPE (p) = TREE_TYPE (DECL_ARG_TYPE (p));
1975 DECL_MODE (p) = VOIDmode;
1976 DECL_SIZE (p) = NULL;
1977 DECL_SIZE_UNIT (p) = NULL;
1978 /* If this arg must go in memory, put it in a pseudo here.
1979 We can't allow it to go in memory as per normal parms,
1980 because the usual place might not have the imag part
1981 adjacent to the real part. */
1982 DECL_ARTIFICIAL (p) = addressable;
1983 DECL_IGNORED_P (p) = addressable;
1984 TREE_ADDRESSABLE (p) = 0;
1985 layout_decl (p, 0);
1987 /* Build a second synthetic decl. */
1988 decl = build_decl (PARM_DECL, NULL_TREE, subtype);
1989 DECL_ARG_TYPE (decl) = DECL_ARG_TYPE (p);
1990 DECL_ARTIFICIAL (decl) = addressable;
1991 DECL_IGNORED_P (decl) = addressable;
1992 layout_decl (decl, 0);
1994 /* Splice it in; skip the new decl. */
1995 TREE_CHAIN (decl) = TREE_CHAIN (p);
1996 TREE_CHAIN (p) = decl;
1997 p = decl;
2001 return args;
2004 /* A subroutine of assign_parms. Adjust the parameter list to incorporate
2005 the hidden struct return argument, and (abi willing) complex args.
2006 Return the new parameter list. */
2008 static tree
2009 assign_parms_augmented_arg_list (struct assign_parm_data_all *all)
2011 tree fndecl = current_function_decl;
2012 tree fntype = TREE_TYPE (fndecl);
2013 tree fnargs = DECL_ARGUMENTS (fndecl);
2015 /* If struct value address is treated as the first argument, make it so. */
2016 if (aggregate_value_p (DECL_RESULT (fndecl), fndecl)
2017 && ! current_function_returns_pcc_struct
2018 && targetm.calls.struct_value_rtx (TREE_TYPE (fndecl), 1) == 0)
2020 tree type = build_pointer_type (TREE_TYPE (fntype));
2021 tree decl;
2023 decl = build_decl (PARM_DECL, NULL_TREE, type);
2024 DECL_ARG_TYPE (decl) = type;
2025 DECL_ARTIFICIAL (decl) = 1;
2026 DECL_IGNORED_P (decl) = 1;
2028 TREE_CHAIN (decl) = fnargs;
2029 fnargs = decl;
2030 all->function_result_decl = decl;
2033 all->orig_fnargs = fnargs;
2035 /* If the target wants to split complex arguments into scalars, do so. */
2036 if (targetm.calls.split_complex_arg)
2037 fnargs = split_complex_args (fnargs);
2039 return fnargs;
2042 /* A subroutine of assign_parms. Examine PARM and pull out type and mode
2043 data for the parameter. Incorporate ABI specifics such as pass-by-
2044 reference and type promotion. */
2046 static void
2047 assign_parm_find_data_types (struct assign_parm_data_all *all, tree parm,
2048 struct assign_parm_data_one *data)
2050 tree nominal_type, passed_type;
2051 enum machine_mode nominal_mode, passed_mode, promoted_mode;
2053 memset (data, 0, sizeof (*data));
2055 /* NAMED_ARG is a mis-nomer. We really mean 'non-varadic'. */
2056 if (!current_function_stdarg)
2057 data->named_arg = 1; /* No varadic parms. */
2058 else if (TREE_CHAIN (parm))
2059 data->named_arg = 1; /* Not the last non-varadic parm. */
2060 else if (targetm.calls.strict_argument_naming (&all->args_so_far))
2061 data->named_arg = 1; /* Only varadic ones are unnamed. */
2062 else
2063 data->named_arg = 0; /* Treat as varadic. */
2065 nominal_type = TREE_TYPE (parm);
2066 passed_type = DECL_ARG_TYPE (parm);
2068 /* Look out for errors propagating this far. Also, if the parameter's
2069 type is void then its value doesn't matter. */
2070 if (TREE_TYPE (parm) == error_mark_node
2071 /* This can happen after weird syntax errors
2072 or if an enum type is defined among the parms. */
2073 || TREE_CODE (parm) != PARM_DECL
2074 || passed_type == NULL
2075 || VOID_TYPE_P (nominal_type))
2077 nominal_type = passed_type = void_type_node;
2078 nominal_mode = passed_mode = promoted_mode = VOIDmode;
2079 goto egress;
2082 /* Find mode of arg as it is passed, and mode of arg as it should be
2083 during execution of this function. */
2084 passed_mode = TYPE_MODE (passed_type);
2085 nominal_mode = TYPE_MODE (nominal_type);
2087 /* If the parm is to be passed as a transparent union, use the type of
2088 the first field for the tests below. We have already verified that
2089 the modes are the same. */
2090 if (TREE_CODE (passed_type) == UNION_TYPE
2091 && TYPE_TRANSPARENT_UNION (passed_type))
2092 passed_type = TREE_TYPE (TYPE_FIELDS (passed_type));
2094 /* See if this arg was passed by invisible reference. */
2095 if (pass_by_reference (&all->args_so_far, passed_mode,
2096 passed_type, data->named_arg))
2098 passed_type = nominal_type = build_pointer_type (passed_type);
2099 data->passed_pointer = true;
2100 passed_mode = nominal_mode = Pmode;
2103 /* Find mode as it is passed by the ABI. */
2104 promoted_mode = passed_mode;
2105 if (targetm.calls.promote_function_args (TREE_TYPE (current_function_decl)))
2107 int unsignedp = TYPE_UNSIGNED (passed_type);
2108 promoted_mode = promote_mode (passed_type, promoted_mode,
2109 &unsignedp, 1);
2112 egress:
2113 data->nominal_type = nominal_type;
2114 data->passed_type = passed_type;
2115 data->nominal_mode = nominal_mode;
2116 data->passed_mode = passed_mode;
2117 data->promoted_mode = promoted_mode;
2120 /* A subroutine of assign_parms. Invoke setup_incoming_varargs. */
2122 static void
2123 assign_parms_setup_varargs (struct assign_parm_data_all *all,
2124 struct assign_parm_data_one *data, bool no_rtl)
2126 int varargs_pretend_bytes = 0;
2128 targetm.calls.setup_incoming_varargs (&all->args_so_far,
2129 data->promoted_mode,
2130 data->passed_type,
2131 &varargs_pretend_bytes, no_rtl);
2133 /* If the back-end has requested extra stack space, record how much is
2134 needed. Do not change pretend_args_size otherwise since it may be
2135 nonzero from an earlier partial argument. */
2136 if (varargs_pretend_bytes > 0)
2137 all->pretend_args_size = varargs_pretend_bytes;
2140 /* A subroutine of assign_parms. Set DATA->ENTRY_PARM corresponding to
2141 the incoming location of the current parameter. */
2143 static void
2144 assign_parm_find_entry_rtl (struct assign_parm_data_all *all,
2145 struct assign_parm_data_one *data)
2147 HOST_WIDE_INT pretend_bytes = 0;
2148 rtx entry_parm;
2149 bool in_regs;
2151 if (data->promoted_mode == VOIDmode)
2153 data->entry_parm = data->stack_parm = const0_rtx;
2154 return;
2157 #ifdef FUNCTION_INCOMING_ARG
2158 entry_parm = FUNCTION_INCOMING_ARG (all->args_so_far, data->promoted_mode,
2159 data->passed_type, data->named_arg);
2160 #else
2161 entry_parm = FUNCTION_ARG (all->args_so_far, data->promoted_mode,
2162 data->passed_type, data->named_arg);
2163 #endif
2165 if (entry_parm == 0)
2166 data->promoted_mode = data->passed_mode;
2168 /* Determine parm's home in the stack, in case it arrives in the stack
2169 or we should pretend it did. Compute the stack position and rtx where
2170 the argument arrives and its size.
2172 There is one complexity here: If this was a parameter that would
2173 have been passed in registers, but wasn't only because it is
2174 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
2175 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
2176 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of 0
2177 as it was the previous time. */
2178 in_regs = entry_parm != 0;
2179 #ifdef STACK_PARMS_IN_REG_PARM_AREA
2180 in_regs = true;
2181 #endif
2182 if (!in_regs && !data->named_arg)
2184 if (targetm.calls.pretend_outgoing_varargs_named (&all->args_so_far))
2186 rtx tem;
2187 #ifdef FUNCTION_INCOMING_ARG
2188 tem = FUNCTION_INCOMING_ARG (all->args_so_far, data->promoted_mode,
2189 data->passed_type, true);
2190 #else
2191 tem = FUNCTION_ARG (all->args_so_far, data->promoted_mode,
2192 data->passed_type, true);
2193 #endif
2194 in_regs = tem != NULL;
2198 /* If this parameter was passed both in registers and in the stack, use
2199 the copy on the stack. */
2200 if (targetm.calls.must_pass_in_stack (data->promoted_mode,
2201 data->passed_type))
2202 entry_parm = 0;
2204 if (entry_parm)
2206 int partial;
2208 partial = targetm.calls.arg_partial_bytes (&all->args_so_far,
2209 data->promoted_mode,
2210 data->passed_type,
2211 data->named_arg);
2212 data->partial = partial;
2214 /* The caller might already have allocated stack space for the
2215 register parameters. */
2216 if (partial != 0 && all->reg_parm_stack_space == 0)
2218 /* Part of this argument is passed in registers and part
2219 is passed on the stack. Ask the prologue code to extend
2220 the stack part so that we can recreate the full value.
2222 PRETEND_BYTES is the size of the registers we need to store.
2223 CURRENT_FUNCTION_PRETEND_ARGS_SIZE is the amount of extra
2224 stack space that the prologue should allocate.
2226 Internally, gcc assumes that the argument pointer is aligned
2227 to STACK_BOUNDARY bits. This is used both for alignment
2228 optimizations (see init_emit) and to locate arguments that are
2229 aligned to more than PARM_BOUNDARY bits. We must preserve this
2230 invariant by rounding CURRENT_FUNCTION_PRETEND_ARGS_SIZE up to
2231 a stack boundary. */
2233 /* We assume at most one partial arg, and it must be the first
2234 argument on the stack. */
2235 gcc_assert (!all->extra_pretend_bytes && !all->pretend_args_size);
2237 pretend_bytes = partial;
2238 all->pretend_args_size = CEIL_ROUND (pretend_bytes, STACK_BYTES);
2240 /* We want to align relative to the actual stack pointer, so
2241 don't include this in the stack size until later. */
2242 all->extra_pretend_bytes = all->pretend_args_size;
2246 locate_and_pad_parm (data->promoted_mode, data->passed_type, in_regs,
2247 entry_parm ? data->partial : 0, current_function_decl,
2248 &all->stack_args_size, &data->locate);
2250 /* Adjust offsets to include the pretend args. */
2251 pretend_bytes = all->extra_pretend_bytes - pretend_bytes;
2252 data->locate.slot_offset.constant += pretend_bytes;
2253 data->locate.offset.constant += pretend_bytes;
2255 data->entry_parm = entry_parm;
2258 /* A subroutine of assign_parms. If there is actually space on the stack
2259 for this parm, count it in stack_args_size and return true. */
2261 static bool
2262 assign_parm_is_stack_parm (struct assign_parm_data_all *all,
2263 struct assign_parm_data_one *data)
2265 /* Trivially true if we've no incoming register. */
2266 if (data->entry_parm == NULL)
2268 /* Also true if we're partially in registers and partially not,
2269 since we've arranged to drop the entire argument on the stack. */
2270 else if (data->partial != 0)
2272 /* Also true if the target says that it's passed in both registers
2273 and on the stack. */
2274 else if (GET_CODE (data->entry_parm) == PARALLEL
2275 && XEXP (XVECEXP (data->entry_parm, 0, 0), 0) == NULL_RTX)
2277 /* Also true if the target says that there's stack allocated for
2278 all register parameters. */
2279 else if (all->reg_parm_stack_space > 0)
2281 /* Otherwise, no, this parameter has no ABI defined stack slot. */
2282 else
2283 return false;
2285 all->stack_args_size.constant += data->locate.size.constant;
2286 if (data->locate.size.var)
2287 ADD_PARM_SIZE (all->stack_args_size, data->locate.size.var);
2289 return true;
2292 /* A subroutine of assign_parms. Given that this parameter is allocated
2293 stack space by the ABI, find it. */
2295 static void
2296 assign_parm_find_stack_rtl (tree parm, struct assign_parm_data_one *data)
2298 rtx offset_rtx, stack_parm;
2299 unsigned int align, boundary;
2301 /* If we're passing this arg using a reg, make its stack home the
2302 aligned stack slot. */
2303 if (data->entry_parm)
2304 offset_rtx = ARGS_SIZE_RTX (data->locate.slot_offset);
2305 else
2306 offset_rtx = ARGS_SIZE_RTX (data->locate.offset);
2308 stack_parm = current_function_internal_arg_pointer;
2309 if (offset_rtx != const0_rtx)
2310 stack_parm = gen_rtx_PLUS (Pmode, stack_parm, offset_rtx);
2311 stack_parm = gen_rtx_MEM (data->promoted_mode, stack_parm);
2313 set_mem_attributes (stack_parm, parm, 1);
2315 boundary = data->locate.boundary;
2316 align = BITS_PER_UNIT;
2318 /* If we're padding upward, we know that the alignment of the slot
2319 is FUNCTION_ARG_BOUNDARY. If we're using slot_offset, we're
2320 intentionally forcing upward padding. Otherwise we have to come
2321 up with a guess at the alignment based on OFFSET_RTX. */
2322 if (data->locate.where_pad != downward || data->entry_parm)
2323 align = boundary;
2324 else if (GET_CODE (offset_rtx) == CONST_INT)
2326 align = INTVAL (offset_rtx) * BITS_PER_UNIT | boundary;
2327 align = align & -align;
2329 set_mem_align (stack_parm, align);
2331 if (data->entry_parm)
2332 set_reg_attrs_for_parm (data->entry_parm, stack_parm);
2334 data->stack_parm = stack_parm;
2337 /* A subroutine of assign_parms. Adjust DATA->ENTRY_RTL such that it's
2338 always valid and contiguous. */
2340 static void
2341 assign_parm_adjust_entry_rtl (struct assign_parm_data_one *data)
2343 rtx entry_parm = data->entry_parm;
2344 rtx stack_parm = data->stack_parm;
2346 /* If this parm was passed part in regs and part in memory, pretend it
2347 arrived entirely in memory by pushing the register-part onto the stack.
2348 In the special case of a DImode or DFmode that is split, we could put
2349 it together in a pseudoreg directly, but for now that's not worth
2350 bothering with. */
2351 if (data->partial != 0)
2353 /* Handle calls that pass values in multiple non-contiguous
2354 locations. The Irix 6 ABI has examples of this. */
2355 if (GET_CODE (entry_parm) == PARALLEL)
2356 emit_group_store (validize_mem (stack_parm), entry_parm,
2357 data->passed_type,
2358 int_size_in_bytes (data->passed_type));
2359 else
2361 gcc_assert (data->partial % UNITS_PER_WORD == 0);
2362 move_block_from_reg (REGNO (entry_parm), validize_mem (stack_parm),
2363 data->partial / UNITS_PER_WORD);
2366 entry_parm = stack_parm;
2369 /* If we didn't decide this parm came in a register, by default it came
2370 on the stack. */
2371 else if (entry_parm == NULL)
2372 entry_parm = stack_parm;
2374 /* When an argument is passed in multiple locations, we can't make use
2375 of this information, but we can save some copying if the whole argument
2376 is passed in a single register. */
2377 else if (GET_CODE (entry_parm) == PARALLEL
2378 && data->nominal_mode != BLKmode
2379 && data->passed_mode != BLKmode)
2381 size_t i, len = XVECLEN (entry_parm, 0);
2383 for (i = 0; i < len; i++)
2384 if (XEXP (XVECEXP (entry_parm, 0, i), 0) != NULL_RTX
2385 && REG_P (XEXP (XVECEXP (entry_parm, 0, i), 0))
2386 && (GET_MODE (XEXP (XVECEXP (entry_parm, 0, i), 0))
2387 == data->passed_mode)
2388 && INTVAL (XEXP (XVECEXP (entry_parm, 0, i), 1)) == 0)
2390 entry_parm = XEXP (XVECEXP (entry_parm, 0, i), 0);
2391 break;
2395 data->entry_parm = entry_parm;
2398 /* A subroutine of assign_parms. Adjust DATA->STACK_RTL such that it's
2399 always valid and properly aligned. */
2401 static void
2402 assign_parm_adjust_stack_rtl (struct assign_parm_data_one *data)
2404 rtx stack_parm = data->stack_parm;
2406 /* If we can't trust the parm stack slot to be aligned enough for its
2407 ultimate type, don't use that slot after entry. We'll make another
2408 stack slot, if we need one. */
2409 if (stack_parm
2410 && ((STRICT_ALIGNMENT
2411 && GET_MODE_ALIGNMENT (data->nominal_mode) > MEM_ALIGN (stack_parm))
2412 || (data->nominal_type
2413 && TYPE_ALIGN (data->nominal_type) > MEM_ALIGN (stack_parm)
2414 && MEM_ALIGN (stack_parm) < PREFERRED_STACK_BOUNDARY)))
2415 stack_parm = NULL;
2417 /* If parm was passed in memory, and we need to convert it on entry,
2418 don't store it back in that same slot. */
2419 else if (data->entry_parm == stack_parm
2420 && data->nominal_mode != BLKmode
2421 && data->nominal_mode != data->passed_mode)
2422 stack_parm = NULL;
2424 /* If stack protection is in effect for this function, don't leave any
2425 pointers in their passed stack slots. */
2426 else if (cfun->stack_protect_guard
2427 && (flag_stack_protect == 2
2428 || data->passed_pointer
2429 || POINTER_TYPE_P (data->nominal_type)))
2430 stack_parm = NULL;
2432 data->stack_parm = stack_parm;
2435 /* A subroutine of assign_parms. Return true if the current parameter
2436 should be stored as a BLKmode in the current frame. */
2438 static bool
2439 assign_parm_setup_block_p (struct assign_parm_data_one *data)
2441 if (data->nominal_mode == BLKmode)
2442 return true;
2443 if (GET_CODE (data->entry_parm) == PARALLEL)
2444 return true;
2446 #ifdef BLOCK_REG_PADDING
2447 /* Only assign_parm_setup_block knows how to deal with register arguments
2448 that are padded at the least significant end. */
2449 if (REG_P (data->entry_parm)
2450 && GET_MODE_SIZE (data->promoted_mode) < UNITS_PER_WORD
2451 && (BLOCK_REG_PADDING (data->passed_mode, data->passed_type, 1)
2452 == (BYTES_BIG_ENDIAN ? upward : downward)))
2453 return true;
2454 #endif
2456 return false;
2459 /* A subroutine of assign_parms. Arrange for the parameter to be
2460 present and valid in DATA->STACK_RTL. */
2462 static void
2463 assign_parm_setup_block (struct assign_parm_data_all *all,
2464 tree parm, struct assign_parm_data_one *data)
2466 rtx entry_parm = data->entry_parm;
2467 rtx stack_parm = data->stack_parm;
2468 HOST_WIDE_INT size;
2469 HOST_WIDE_INT size_stored;
2470 rtx orig_entry_parm = entry_parm;
2472 if (GET_CODE (entry_parm) == PARALLEL)
2473 entry_parm = emit_group_move_into_temps (entry_parm);
2475 /* If we've a non-block object that's nevertheless passed in parts,
2476 reconstitute it in register operations rather than on the stack. */
2477 if (GET_CODE (entry_parm) == PARALLEL
2478 && data->nominal_mode != BLKmode)
2480 rtx elt0 = XEXP (XVECEXP (orig_entry_parm, 0, 0), 0);
2482 if ((XVECLEN (entry_parm, 0) > 1
2483 || hard_regno_nregs[REGNO (elt0)][GET_MODE (elt0)] > 1)
2484 && use_register_for_decl (parm))
2486 rtx parmreg = gen_reg_rtx (data->nominal_mode);
2488 push_to_sequence (all->conversion_insns);
2490 /* For values returned in multiple registers, handle possible
2491 incompatible calls to emit_group_store.
2493 For example, the following would be invalid, and would have to
2494 be fixed by the conditional below:
2496 emit_group_store ((reg:SF), (parallel:DF))
2497 emit_group_store ((reg:SI), (parallel:DI))
2499 An example of this are doubles in e500 v2:
2500 (parallel:DF (expr_list (reg:SI) (const_int 0))
2501 (expr_list (reg:SI) (const_int 4))). */
2502 if (data->nominal_mode != data->passed_mode)
2504 rtx t = gen_reg_rtx (GET_MODE (entry_parm));
2505 emit_group_store (t, entry_parm, NULL_TREE,
2506 GET_MODE_SIZE (GET_MODE (entry_parm)));
2507 convert_move (parmreg, t, 0);
2509 else
2510 emit_group_store (parmreg, entry_parm, data->nominal_type,
2511 int_size_in_bytes (data->nominal_type));
2513 all->conversion_insns = get_insns ();
2514 end_sequence ();
2516 SET_DECL_RTL (parm, parmreg);
2517 return;
2521 size = int_size_in_bytes (data->passed_type);
2522 size_stored = CEIL_ROUND (size, UNITS_PER_WORD);
2523 if (stack_parm == 0)
2525 DECL_ALIGN (parm) = MAX (DECL_ALIGN (parm), BITS_PER_WORD);
2526 stack_parm = assign_stack_local (BLKmode, size_stored,
2527 DECL_ALIGN (parm));
2528 if (GET_MODE_SIZE (GET_MODE (entry_parm)) == size)
2529 PUT_MODE (stack_parm, GET_MODE (entry_parm));
2530 set_mem_attributes (stack_parm, parm, 1);
2533 /* If a BLKmode arrives in registers, copy it to a stack slot. Handle
2534 calls that pass values in multiple non-contiguous locations. */
2535 if (REG_P (entry_parm) || GET_CODE (entry_parm) == PARALLEL)
2537 rtx mem;
2539 /* Note that we will be storing an integral number of words.
2540 So we have to be careful to ensure that we allocate an
2541 integral number of words. We do this above when we call
2542 assign_stack_local if space was not allocated in the argument
2543 list. If it was, this will not work if PARM_BOUNDARY is not
2544 a multiple of BITS_PER_WORD. It isn't clear how to fix this
2545 if it becomes a problem. Exception is when BLKmode arrives
2546 with arguments not conforming to word_mode. */
2548 if (data->stack_parm == 0)
2550 else if (GET_CODE (entry_parm) == PARALLEL)
2552 else
2553 gcc_assert (!size || !(PARM_BOUNDARY % BITS_PER_WORD));
2555 mem = validize_mem (stack_parm);
2557 /* Handle values in multiple non-contiguous locations. */
2558 if (GET_CODE (entry_parm) == PARALLEL)
2560 push_to_sequence (all->conversion_insns);
2561 emit_group_store (mem, entry_parm, data->passed_type, size);
2562 all->conversion_insns = get_insns ();
2563 end_sequence ();
2566 else if (size == 0)
2569 /* If SIZE is that of a mode no bigger than a word, just use
2570 that mode's store operation. */
2571 else if (size <= UNITS_PER_WORD)
2573 enum machine_mode mode
2574 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
2576 if (mode != BLKmode
2577 #ifdef BLOCK_REG_PADDING
2578 && (size == UNITS_PER_WORD
2579 || (BLOCK_REG_PADDING (mode, data->passed_type, 1)
2580 != (BYTES_BIG_ENDIAN ? upward : downward)))
2581 #endif
2584 rtx reg = gen_rtx_REG (mode, REGNO (entry_parm));
2585 emit_move_insn (change_address (mem, mode, 0), reg);
2588 /* Blocks smaller than a word on a BYTES_BIG_ENDIAN
2589 machine must be aligned to the left before storing
2590 to memory. Note that the previous test doesn't
2591 handle all cases (e.g. SIZE == 3). */
2592 else if (size != UNITS_PER_WORD
2593 #ifdef BLOCK_REG_PADDING
2594 && (BLOCK_REG_PADDING (mode, data->passed_type, 1)
2595 == downward)
2596 #else
2597 && BYTES_BIG_ENDIAN
2598 #endif
2601 rtx tem, x;
2602 int by = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
2603 rtx reg = gen_rtx_REG (word_mode, REGNO (entry_parm));
2605 x = expand_shift (LSHIFT_EXPR, word_mode, reg,
2606 build_int_cst (NULL_TREE, by),
2607 NULL_RTX, 1);
2608 tem = change_address (mem, word_mode, 0);
2609 emit_move_insn (tem, x);
2611 else
2612 move_block_from_reg (REGNO (entry_parm), mem,
2613 size_stored / UNITS_PER_WORD);
2615 else
2616 move_block_from_reg (REGNO (entry_parm), mem,
2617 size_stored / UNITS_PER_WORD);
2619 else if (data->stack_parm == 0)
2621 push_to_sequence (all->conversion_insns);
2622 emit_block_move (stack_parm, data->entry_parm, GEN_INT (size),
2623 BLOCK_OP_NORMAL);
2624 all->conversion_insns = get_insns ();
2625 end_sequence ();
2628 data->stack_parm = stack_parm;
2629 SET_DECL_RTL (parm, stack_parm);
2632 /* A subroutine of assign_parms. Allocate a pseudo to hold the current
2633 parameter. Get it there. Perform all ABI specified conversions. */
2635 static void
2636 assign_parm_setup_reg (struct assign_parm_data_all *all, tree parm,
2637 struct assign_parm_data_one *data)
2639 rtx parmreg;
2640 enum machine_mode promoted_nominal_mode;
2641 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (parm));
2642 bool did_conversion = false;
2644 /* Store the parm in a pseudoregister during the function, but we may
2645 need to do it in a wider mode. */
2647 /* This is not really promoting for a call. However we need to be
2648 consistent with assign_parm_find_data_types and expand_expr_real_1. */
2649 promoted_nominal_mode
2650 = promote_mode (data->nominal_type, data->nominal_mode, &unsignedp, 1);
2652 parmreg = gen_reg_rtx (promoted_nominal_mode);
2654 if (!DECL_ARTIFICIAL (parm))
2655 mark_user_reg (parmreg);
2657 /* If this was an item that we received a pointer to,
2658 set DECL_RTL appropriately. */
2659 if (data->passed_pointer)
2661 rtx x = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (data->passed_type)), parmreg);
2662 set_mem_attributes (x, parm, 1);
2663 SET_DECL_RTL (parm, x);
2665 else
2666 SET_DECL_RTL (parm, parmreg);
2668 /* Copy the value into the register. */
2669 if (data->nominal_mode != data->passed_mode
2670 || promoted_nominal_mode != data->promoted_mode)
2672 int save_tree_used;
2674 /* ENTRY_PARM has been converted to PROMOTED_MODE, its
2675 mode, by the caller. We now have to convert it to
2676 NOMINAL_MODE, if different. However, PARMREG may be in
2677 a different mode than NOMINAL_MODE if it is being stored
2678 promoted.
2680 If ENTRY_PARM is a hard register, it might be in a register
2681 not valid for operating in its mode (e.g., an odd-numbered
2682 register for a DFmode). In that case, moves are the only
2683 thing valid, so we can't do a convert from there. This
2684 occurs when the calling sequence allow such misaligned
2685 usages.
2687 In addition, the conversion may involve a call, which could
2688 clobber parameters which haven't been copied to pseudo
2689 registers yet. Therefore, we must first copy the parm to
2690 a pseudo reg here, and save the conversion until after all
2691 parameters have been moved. */
2693 rtx tempreg = gen_reg_rtx (GET_MODE (data->entry_parm));
2695 emit_move_insn (tempreg, validize_mem (data->entry_parm));
2697 push_to_sequence (all->conversion_insns);
2698 tempreg = convert_to_mode (data->nominal_mode, tempreg, unsignedp);
2700 if (GET_CODE (tempreg) == SUBREG
2701 && GET_MODE (tempreg) == data->nominal_mode
2702 && REG_P (SUBREG_REG (tempreg))
2703 && data->nominal_mode == data->passed_mode
2704 && GET_MODE (SUBREG_REG (tempreg)) == GET_MODE (data->entry_parm)
2705 && GET_MODE_SIZE (GET_MODE (tempreg))
2706 < GET_MODE_SIZE (GET_MODE (data->entry_parm)))
2708 /* The argument is already sign/zero extended, so note it
2709 into the subreg. */
2710 SUBREG_PROMOTED_VAR_P (tempreg) = 1;
2711 SUBREG_PROMOTED_UNSIGNED_SET (tempreg, unsignedp);
2714 /* TREE_USED gets set erroneously during expand_assignment. */
2715 save_tree_used = TREE_USED (parm);
2716 expand_assignment (parm, make_tree (data->nominal_type, tempreg));
2717 TREE_USED (parm) = save_tree_used;
2718 all->conversion_insns = get_insns ();
2719 end_sequence ();
2721 did_conversion = true;
2723 else
2724 emit_move_insn (parmreg, validize_mem (data->entry_parm));
2726 /* If we were passed a pointer but the actual value can safely live
2727 in a register, put it in one. */
2728 if (data->passed_pointer
2729 && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
2730 /* If by-reference argument was promoted, demote it. */
2731 && (TYPE_MODE (TREE_TYPE (parm)) != GET_MODE (DECL_RTL (parm))
2732 || use_register_for_decl (parm)))
2734 /* We can't use nominal_mode, because it will have been set to
2735 Pmode above. We must use the actual mode of the parm. */
2736 parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
2737 mark_user_reg (parmreg);
2739 if (GET_MODE (parmreg) != GET_MODE (DECL_RTL (parm)))
2741 rtx tempreg = gen_reg_rtx (GET_MODE (DECL_RTL (parm)));
2742 int unsigned_p = TYPE_UNSIGNED (TREE_TYPE (parm));
2744 push_to_sequence (all->conversion_insns);
2745 emit_move_insn (tempreg, DECL_RTL (parm));
2746 tempreg = convert_to_mode (GET_MODE (parmreg), tempreg, unsigned_p);
2747 emit_move_insn (parmreg, tempreg);
2748 all->conversion_insns = get_insns ();
2749 end_sequence ();
2751 did_conversion = true;
2753 else
2754 emit_move_insn (parmreg, DECL_RTL (parm));
2756 SET_DECL_RTL (parm, parmreg);
2758 /* STACK_PARM is the pointer, not the parm, and PARMREG is
2759 now the parm. */
2760 data->stack_parm = NULL;
2763 /* Mark the register as eliminable if we did no conversion and it was
2764 copied from memory at a fixed offset, and the arg pointer was not
2765 copied to a pseudo-reg. If the arg pointer is a pseudo reg or the
2766 offset formed an invalid address, such memory-equivalences as we
2767 make here would screw up life analysis for it. */
2768 if (data->nominal_mode == data->passed_mode
2769 && !did_conversion
2770 && data->stack_parm != 0
2771 && MEM_P (data->stack_parm)
2772 && data->locate.offset.var == 0
2773 && reg_mentioned_p (virtual_incoming_args_rtx,
2774 XEXP (data->stack_parm, 0)))
2776 rtx linsn = get_last_insn ();
2777 rtx sinsn, set;
2779 /* Mark complex types separately. */
2780 if (GET_CODE (parmreg) == CONCAT)
2782 enum machine_mode submode
2783 = GET_MODE_INNER (GET_MODE (parmreg));
2784 int regnor = REGNO (XEXP (parmreg, 0));
2785 int regnoi = REGNO (XEXP (parmreg, 1));
2786 rtx stackr = adjust_address_nv (data->stack_parm, submode, 0);
2787 rtx stacki = adjust_address_nv (data->stack_parm, submode,
2788 GET_MODE_SIZE (submode));
2790 /* Scan backwards for the set of the real and
2791 imaginary parts. */
2792 for (sinsn = linsn; sinsn != 0;
2793 sinsn = prev_nonnote_insn (sinsn))
2795 set = single_set (sinsn);
2796 if (set == 0)
2797 continue;
2799 if (SET_DEST (set) == regno_reg_rtx [regnoi])
2800 REG_NOTES (sinsn)
2801 = gen_rtx_EXPR_LIST (REG_EQUIV, stacki,
2802 REG_NOTES (sinsn));
2803 else if (SET_DEST (set) == regno_reg_rtx [regnor])
2804 REG_NOTES (sinsn)
2805 = gen_rtx_EXPR_LIST (REG_EQUIV, stackr,
2806 REG_NOTES (sinsn));
2809 else if ((set = single_set (linsn)) != 0
2810 && SET_DEST (set) == parmreg)
2811 REG_NOTES (linsn)
2812 = gen_rtx_EXPR_LIST (REG_EQUIV,
2813 data->stack_parm, REG_NOTES (linsn));
2816 /* For pointer data type, suggest pointer register. */
2817 if (POINTER_TYPE_P (TREE_TYPE (parm)))
2818 mark_reg_pointer (parmreg,
2819 TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm))));
2822 /* A subroutine of assign_parms. Allocate stack space to hold the current
2823 parameter. Get it there. Perform all ABI specified conversions. */
2825 static void
2826 assign_parm_setup_stack (struct assign_parm_data_all *all, tree parm,
2827 struct assign_parm_data_one *data)
2829 /* Value must be stored in the stack slot STACK_PARM during function
2830 execution. */
2831 bool to_conversion = false;
2833 if (data->promoted_mode != data->nominal_mode)
2835 /* Conversion is required. */
2836 rtx tempreg = gen_reg_rtx (GET_MODE (data->entry_parm));
2838 emit_move_insn (tempreg, validize_mem (data->entry_parm));
2840 push_to_sequence (all->conversion_insns);
2841 to_conversion = true;
2843 data->entry_parm = convert_to_mode (data->nominal_mode, tempreg,
2844 TYPE_UNSIGNED (TREE_TYPE (parm)));
2846 if (data->stack_parm)
2847 /* ??? This may need a big-endian conversion on sparc64. */
2848 data->stack_parm
2849 = adjust_address (data->stack_parm, data->nominal_mode, 0);
2852 if (data->entry_parm != data->stack_parm)
2854 rtx src, dest;
2856 if (data->stack_parm == 0)
2858 data->stack_parm
2859 = assign_stack_local (GET_MODE (data->entry_parm),
2860 GET_MODE_SIZE (GET_MODE (data->entry_parm)),
2861 TYPE_ALIGN (data->passed_type));
2862 set_mem_attributes (data->stack_parm, parm, 1);
2865 dest = validize_mem (data->stack_parm);
2866 src = validize_mem (data->entry_parm);
2868 if (MEM_P (src))
2870 /* Use a block move to handle potentially misaligned entry_parm. */
2871 if (!to_conversion)
2872 push_to_sequence (all->conversion_insns);
2873 to_conversion = true;
2875 emit_block_move (dest, src,
2876 GEN_INT (int_size_in_bytes (data->passed_type)),
2877 BLOCK_OP_NORMAL);
2879 else
2880 emit_move_insn (dest, src);
2883 if (to_conversion)
2885 all->conversion_insns = get_insns ();
2886 end_sequence ();
2889 SET_DECL_RTL (parm, data->stack_parm);
2892 /* A subroutine of assign_parms. If the ABI splits complex arguments, then
2893 undo the frobbing that we did in assign_parms_augmented_arg_list. */
2895 static void
2896 assign_parms_unsplit_complex (struct assign_parm_data_all *all, tree fnargs)
2898 tree parm;
2899 tree orig_fnargs = all->orig_fnargs;
2901 for (parm = orig_fnargs; parm; parm = TREE_CHAIN (parm))
2903 if (TREE_CODE (TREE_TYPE (parm)) == COMPLEX_TYPE
2904 && targetm.calls.split_complex_arg (TREE_TYPE (parm)))
2906 rtx tmp, real, imag;
2907 enum machine_mode inner = GET_MODE_INNER (DECL_MODE (parm));
2909 real = DECL_RTL (fnargs);
2910 imag = DECL_RTL (TREE_CHAIN (fnargs));
2911 if (inner != GET_MODE (real))
2913 real = gen_lowpart_SUBREG (inner, real);
2914 imag = gen_lowpart_SUBREG (inner, imag);
2917 if (TREE_ADDRESSABLE (parm))
2919 rtx rmem, imem;
2920 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (parm));
2922 /* split_complex_arg put the real and imag parts in
2923 pseudos. Move them to memory. */
2924 tmp = assign_stack_local (DECL_MODE (parm), size,
2925 TYPE_ALIGN (TREE_TYPE (parm)));
2926 set_mem_attributes (tmp, parm, 1);
2927 rmem = adjust_address_nv (tmp, inner, 0);
2928 imem = adjust_address_nv (tmp, inner, GET_MODE_SIZE (inner));
2929 push_to_sequence (all->conversion_insns);
2930 emit_move_insn (rmem, real);
2931 emit_move_insn (imem, imag);
2932 all->conversion_insns = get_insns ();
2933 end_sequence ();
2935 else
2936 tmp = gen_rtx_CONCAT (DECL_MODE (parm), real, imag);
2937 SET_DECL_RTL (parm, tmp);
2939 real = DECL_INCOMING_RTL (fnargs);
2940 imag = DECL_INCOMING_RTL (TREE_CHAIN (fnargs));
2941 if (inner != GET_MODE (real))
2943 real = gen_lowpart_SUBREG (inner, real);
2944 imag = gen_lowpart_SUBREG (inner, imag);
2946 tmp = gen_rtx_CONCAT (DECL_MODE (parm), real, imag);
2947 set_decl_incoming_rtl (parm, tmp);
2948 fnargs = TREE_CHAIN (fnargs);
2950 else
2952 SET_DECL_RTL (parm, DECL_RTL (fnargs));
2953 set_decl_incoming_rtl (parm, DECL_INCOMING_RTL (fnargs));
2955 /* Set MEM_EXPR to the original decl, i.e. to PARM,
2956 instead of the copy of decl, i.e. FNARGS. */
2957 if (DECL_INCOMING_RTL (parm) && MEM_P (DECL_INCOMING_RTL (parm)))
2958 set_mem_expr (DECL_INCOMING_RTL (parm), parm);
2961 fnargs = TREE_CHAIN (fnargs);
2965 /* Assign RTL expressions to the function's parameters. This may involve
2966 copying them into registers and using those registers as the DECL_RTL. */
2968 static void
2969 assign_parms (tree fndecl)
2971 struct assign_parm_data_all all;
2972 tree fnargs, parm;
2974 current_function_internal_arg_pointer
2975 = targetm.calls.internal_arg_pointer ();
2977 assign_parms_initialize_all (&all);
2978 fnargs = assign_parms_augmented_arg_list (&all);
2980 for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
2982 struct assign_parm_data_one data;
2984 /* Extract the type of PARM; adjust it according to ABI. */
2985 assign_parm_find_data_types (&all, parm, &data);
2987 /* Early out for errors and void parameters. */
2988 if (data.passed_mode == VOIDmode)
2990 SET_DECL_RTL (parm, const0_rtx);
2991 DECL_INCOMING_RTL (parm) = DECL_RTL (parm);
2992 continue;
2995 if (current_function_stdarg && !TREE_CHAIN (parm))
2996 assign_parms_setup_varargs (&all, &data, false);
2998 /* Find out where the parameter arrives in this function. */
2999 assign_parm_find_entry_rtl (&all, &data);
3001 /* Find out where stack space for this parameter might be. */
3002 if (assign_parm_is_stack_parm (&all, &data))
3004 assign_parm_find_stack_rtl (parm, &data);
3005 assign_parm_adjust_entry_rtl (&data);
3008 /* Record permanently how this parm was passed. */
3009 set_decl_incoming_rtl (parm, data.entry_parm);
3011 /* Update info on where next arg arrives in registers. */
3012 FUNCTION_ARG_ADVANCE (all.args_so_far, data.promoted_mode,
3013 data.passed_type, data.named_arg);
3015 assign_parm_adjust_stack_rtl (&data);
3017 if (assign_parm_setup_block_p (&data))
3018 assign_parm_setup_block (&all, parm, &data);
3019 else if (data.passed_pointer || use_register_for_decl (parm))
3020 assign_parm_setup_reg (&all, parm, &data);
3021 else
3022 assign_parm_setup_stack (&all, parm, &data);
3025 if (targetm.calls.split_complex_arg && fnargs != all.orig_fnargs)
3026 assign_parms_unsplit_complex (&all, fnargs);
3028 /* Output all parameter conversion instructions (possibly including calls)
3029 now that all parameters have been copied out of hard registers. */
3030 emit_insn (all.conversion_insns);
3032 /* If we are receiving a struct value address as the first argument, set up
3033 the RTL for the function result. As this might require code to convert
3034 the transmitted address to Pmode, we do this here to ensure that possible
3035 preliminary conversions of the address have been emitted already. */
3036 if (all.function_result_decl)
3038 tree result = DECL_RESULT (current_function_decl);
3039 rtx addr = DECL_RTL (all.function_result_decl);
3040 rtx x;
3042 if (DECL_BY_REFERENCE (result))
3043 x = addr;
3044 else
3046 addr = convert_memory_address (Pmode, addr);
3047 x = gen_rtx_MEM (DECL_MODE (result), addr);
3048 set_mem_attributes (x, result, 1);
3050 SET_DECL_RTL (result, x);
3053 /* We have aligned all the args, so add space for the pretend args. */
3054 current_function_pretend_args_size = all.pretend_args_size;
3055 all.stack_args_size.constant += all.extra_pretend_bytes;
3056 current_function_args_size = all.stack_args_size.constant;
3058 /* Adjust function incoming argument size for alignment and
3059 minimum length. */
3061 #ifdef REG_PARM_STACK_SPACE
3062 current_function_args_size = MAX (current_function_args_size,
3063 REG_PARM_STACK_SPACE (fndecl));
3064 #endif
3066 current_function_args_size = CEIL_ROUND (current_function_args_size,
3067 PARM_BOUNDARY / BITS_PER_UNIT);
3069 #ifdef ARGS_GROW_DOWNWARD
3070 current_function_arg_offset_rtx
3071 = (all.stack_args_size.var == 0 ? GEN_INT (-all.stack_args_size.constant)
3072 : expand_expr (size_diffop (all.stack_args_size.var,
3073 size_int (-all.stack_args_size.constant)),
3074 NULL_RTX, VOIDmode, 0));
3075 #else
3076 current_function_arg_offset_rtx = ARGS_SIZE_RTX (all.stack_args_size);
3077 #endif
3079 /* See how many bytes, if any, of its args a function should try to pop
3080 on return. */
3082 current_function_pops_args = RETURN_POPS_ARGS (fndecl, TREE_TYPE (fndecl),
3083 current_function_args_size);
3085 /* For stdarg.h function, save info about
3086 regs and stack space used by the named args. */
3088 current_function_args_info = all.args_so_far;
3090 /* Set the rtx used for the function return value. Put this in its
3091 own variable so any optimizers that need this information don't have
3092 to include tree.h. Do this here so it gets done when an inlined
3093 function gets output. */
3095 current_function_return_rtx
3096 = (DECL_RTL_SET_P (DECL_RESULT (fndecl))
3097 ? DECL_RTL (DECL_RESULT (fndecl)) : NULL_RTX);
3099 /* If scalar return value was computed in a pseudo-reg, or was a named
3100 return value that got dumped to the stack, copy that to the hard
3101 return register. */
3102 if (DECL_RTL_SET_P (DECL_RESULT (fndecl)))
3104 tree decl_result = DECL_RESULT (fndecl);
3105 rtx decl_rtl = DECL_RTL (decl_result);
3107 if (REG_P (decl_rtl)
3108 ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
3109 : DECL_REGISTER (decl_result))
3111 rtx real_decl_rtl;
3113 real_decl_rtl = targetm.calls.function_value (TREE_TYPE (decl_result),
3114 fndecl, true);
3115 REG_FUNCTION_VALUE_P (real_decl_rtl) = 1;
3116 /* The delay slot scheduler assumes that current_function_return_rtx
3117 holds the hard register containing the return value, not a
3118 temporary pseudo. */
3119 current_function_return_rtx = real_decl_rtl;
3124 /* A subroutine of gimplify_parameters, invoked via walk_tree.
3125 For all seen types, gimplify their sizes. */
3127 static tree
3128 gimplify_parm_type (tree *tp, int *walk_subtrees, void *data)
3130 tree t = *tp;
3132 *walk_subtrees = 0;
3133 if (TYPE_P (t))
3135 if (POINTER_TYPE_P (t))
3136 *walk_subtrees = 1;
3137 else if (TYPE_SIZE (t) && !TREE_CONSTANT (TYPE_SIZE (t))
3138 && !TYPE_SIZES_GIMPLIFIED (t))
3140 gimplify_type_sizes (t, (tree *) data);
3141 *walk_subtrees = 1;
3145 return NULL;
3148 /* Gimplify the parameter list for current_function_decl. This involves
3149 evaluating SAVE_EXPRs of variable sized parameters and generating code
3150 to implement callee-copies reference parameters. Returns a list of
3151 statements to add to the beginning of the function, or NULL if nothing
3152 to do. */
3154 tree
3155 gimplify_parameters (void)
3157 struct assign_parm_data_all all;
3158 tree fnargs, parm, stmts = NULL;
3160 assign_parms_initialize_all (&all);
3161 fnargs = assign_parms_augmented_arg_list (&all);
3163 for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
3165 struct assign_parm_data_one data;
3167 /* Extract the type of PARM; adjust it according to ABI. */
3168 assign_parm_find_data_types (&all, parm, &data);
3170 /* Early out for errors and void parameters. */
3171 if (data.passed_mode == VOIDmode || DECL_SIZE (parm) == NULL)
3172 continue;
3174 /* Update info on where next arg arrives in registers. */
3175 FUNCTION_ARG_ADVANCE (all.args_so_far, data.promoted_mode,
3176 data.passed_type, data.named_arg);
3178 /* ??? Once upon a time variable_size stuffed parameter list
3179 SAVE_EXPRs (amongst others) onto a pending sizes list. This
3180 turned out to be less than manageable in the gimple world.
3181 Now we have to hunt them down ourselves. */
3182 walk_tree_without_duplicates (&data.passed_type,
3183 gimplify_parm_type, &stmts);
3185 if (!TREE_CONSTANT (DECL_SIZE (parm)))
3187 gimplify_one_sizepos (&DECL_SIZE (parm), &stmts);
3188 gimplify_one_sizepos (&DECL_SIZE_UNIT (parm), &stmts);
3191 if (data.passed_pointer)
3193 tree type = TREE_TYPE (data.passed_type);
3194 if (reference_callee_copied (&all.args_so_far, TYPE_MODE (type),
3195 type, data.named_arg))
3197 tree local, t;
3199 /* For constant sized objects, this is trivial; for
3200 variable-sized objects, we have to play games. */
3201 if (TREE_CONSTANT (DECL_SIZE (parm)))
3203 local = create_tmp_var (type, get_name (parm));
3204 DECL_IGNORED_P (local) = 0;
3206 else
3208 tree ptr_type, addr, args;
3210 ptr_type = build_pointer_type (type);
3211 addr = create_tmp_var (ptr_type, get_name (parm));
3212 DECL_IGNORED_P (addr) = 0;
3213 local = build_fold_indirect_ref (addr);
3215 args = tree_cons (NULL, DECL_SIZE_UNIT (parm), NULL);
3216 t = built_in_decls[BUILT_IN_ALLOCA];
3217 t = build_function_call_expr (t, args);
3218 t = fold_convert (ptr_type, t);
3219 t = build2 (MODIFY_EXPR, void_type_node, addr, t);
3220 gimplify_and_add (t, &stmts);
3223 t = build2 (MODIFY_EXPR, void_type_node, local, parm);
3224 gimplify_and_add (t, &stmts);
3226 SET_DECL_VALUE_EXPR (parm, local);
3227 DECL_HAS_VALUE_EXPR_P (parm) = 1;
3232 return stmts;
3235 /* Indicate whether REGNO is an incoming argument to the current function
3236 that was promoted to a wider mode. If so, return the RTX for the
3237 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
3238 that REGNO is promoted from and whether the promotion was signed or
3239 unsigned. */
3242 promoted_input_arg (unsigned int regno, enum machine_mode *pmode, int *punsignedp)
3244 tree arg;
3246 for (arg = DECL_ARGUMENTS (current_function_decl); arg;
3247 arg = TREE_CHAIN (arg))
3248 if (REG_P (DECL_INCOMING_RTL (arg))
3249 && REGNO (DECL_INCOMING_RTL (arg)) == regno
3250 && TYPE_MODE (DECL_ARG_TYPE (arg)) == TYPE_MODE (TREE_TYPE (arg)))
3252 enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
3253 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (arg));
3255 mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1);
3256 if (mode == GET_MODE (DECL_INCOMING_RTL (arg))
3257 && mode != DECL_MODE (arg))
3259 *pmode = DECL_MODE (arg);
3260 *punsignedp = unsignedp;
3261 return DECL_INCOMING_RTL (arg);
3265 return 0;
3269 /* Compute the size and offset from the start of the stacked arguments for a
3270 parm passed in mode PASSED_MODE and with type TYPE.
3272 INITIAL_OFFSET_PTR points to the current offset into the stacked
3273 arguments.
3275 The starting offset and size for this parm are returned in
3276 LOCATE->OFFSET and LOCATE->SIZE, respectively. When IN_REGS is
3277 nonzero, the offset is that of stack slot, which is returned in
3278 LOCATE->SLOT_OFFSET. LOCATE->ALIGNMENT_PAD is the amount of
3279 padding required from the initial offset ptr to the stack slot.
3281 IN_REGS is nonzero if the argument will be passed in registers. It will
3282 never be set if REG_PARM_STACK_SPACE is not defined.
3284 FNDECL is the function in which the argument was defined.
3286 There are two types of rounding that are done. The first, controlled by
3287 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
3288 list to be aligned to the specific boundary (in bits). This rounding
3289 affects the initial and starting offsets, but not the argument size.
3291 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
3292 optionally rounds the size of the parm to PARM_BOUNDARY. The
3293 initial offset is not affected by this rounding, while the size always
3294 is and the starting offset may be. */
3296 /* LOCATE->OFFSET will be negative for ARGS_GROW_DOWNWARD case;
3297 INITIAL_OFFSET_PTR is positive because locate_and_pad_parm's
3298 callers pass in the total size of args so far as
3299 INITIAL_OFFSET_PTR. LOCATE->SIZE is always positive. */
3301 void
3302 locate_and_pad_parm (enum machine_mode passed_mode, tree type, int in_regs,
3303 int partial, tree fndecl ATTRIBUTE_UNUSED,
3304 struct args_size *initial_offset_ptr,
3305 struct locate_and_pad_arg_data *locate)
3307 tree sizetree;
3308 enum direction where_pad;
3309 unsigned int boundary;
3310 int reg_parm_stack_space = 0;
3311 int part_size_in_regs;
3313 #ifdef REG_PARM_STACK_SPACE
3314 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
3316 /* If we have found a stack parm before we reach the end of the
3317 area reserved for registers, skip that area. */
3318 if (! in_regs)
3320 if (reg_parm_stack_space > 0)
3322 if (initial_offset_ptr->var)
3324 initial_offset_ptr->var
3325 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
3326 ssize_int (reg_parm_stack_space));
3327 initial_offset_ptr->constant = 0;
3329 else if (initial_offset_ptr->constant < reg_parm_stack_space)
3330 initial_offset_ptr->constant = reg_parm_stack_space;
3333 #endif /* REG_PARM_STACK_SPACE */
3335 part_size_in_regs = (reg_parm_stack_space == 0 ? partial : 0);
3337 sizetree
3338 = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
3339 where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
3340 boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
3341 locate->where_pad = where_pad;
3342 locate->boundary = boundary;
3344 /* Remember if the outgoing parameter requires extra alignment on the
3345 calling function side. */
3346 if (boundary > PREFERRED_STACK_BOUNDARY)
3347 boundary = PREFERRED_STACK_BOUNDARY;
3348 if (cfun->stack_alignment_needed < boundary)
3349 cfun->stack_alignment_needed = boundary;
3351 #ifdef ARGS_GROW_DOWNWARD
3352 locate->slot_offset.constant = -initial_offset_ptr->constant;
3353 if (initial_offset_ptr->var)
3354 locate->slot_offset.var = size_binop (MINUS_EXPR, ssize_int (0),
3355 initial_offset_ptr->var);
3358 tree s2 = sizetree;
3359 if (where_pad != none
3360 && (!host_integerp (sizetree, 1)
3361 || (tree_low_cst (sizetree, 1) * BITS_PER_UNIT) % PARM_BOUNDARY))
3362 s2 = round_up (s2, PARM_BOUNDARY / BITS_PER_UNIT);
3363 SUB_PARM_SIZE (locate->slot_offset, s2);
3366 locate->slot_offset.constant += part_size_in_regs;
3368 if (!in_regs
3369 #ifdef REG_PARM_STACK_SPACE
3370 || REG_PARM_STACK_SPACE (fndecl) > 0
3371 #endif
3373 pad_to_arg_alignment (&locate->slot_offset, boundary,
3374 &locate->alignment_pad);
3376 locate->size.constant = (-initial_offset_ptr->constant
3377 - locate->slot_offset.constant);
3378 if (initial_offset_ptr->var)
3379 locate->size.var = size_binop (MINUS_EXPR,
3380 size_binop (MINUS_EXPR,
3381 ssize_int (0),
3382 initial_offset_ptr->var),
3383 locate->slot_offset.var);
3385 /* Pad_below needs the pre-rounded size to know how much to pad
3386 below. */
3387 locate->offset = locate->slot_offset;
3388 if (where_pad == downward)
3389 pad_below (&locate->offset, passed_mode, sizetree);
3391 #else /* !ARGS_GROW_DOWNWARD */
3392 if (!in_regs
3393 #ifdef REG_PARM_STACK_SPACE
3394 || REG_PARM_STACK_SPACE (fndecl) > 0
3395 #endif
3397 pad_to_arg_alignment (initial_offset_ptr, boundary,
3398 &locate->alignment_pad);
3399 locate->slot_offset = *initial_offset_ptr;
3401 #ifdef PUSH_ROUNDING
3402 if (passed_mode != BLKmode)
3403 sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
3404 #endif
3406 /* Pad_below needs the pre-rounded size to know how much to pad below
3407 so this must be done before rounding up. */
3408 locate->offset = locate->slot_offset;
3409 if (where_pad == downward)
3410 pad_below (&locate->offset, passed_mode, sizetree);
3412 if (where_pad != none
3413 && (!host_integerp (sizetree, 1)
3414 || (tree_low_cst (sizetree, 1) * BITS_PER_UNIT) % PARM_BOUNDARY))
3415 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
3417 ADD_PARM_SIZE (locate->size, sizetree);
3419 locate->size.constant -= part_size_in_regs;
3420 #endif /* ARGS_GROW_DOWNWARD */
3423 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
3424 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
3426 static void
3427 pad_to_arg_alignment (struct args_size *offset_ptr, int boundary,
3428 struct args_size *alignment_pad)
3430 tree save_var = NULL_TREE;
3431 HOST_WIDE_INT save_constant = 0;
3432 int boundary_in_bytes = boundary / BITS_PER_UNIT;
3433 HOST_WIDE_INT sp_offset = STACK_POINTER_OFFSET;
3435 #ifdef SPARC_STACK_BOUNDARY_HACK
3436 /* ??? The SPARC port may claim a STACK_BOUNDARY higher than
3437 the real alignment of %sp. However, when it does this, the
3438 alignment of %sp+STACK_POINTER_OFFSET is STACK_BOUNDARY. */
3439 if (SPARC_STACK_BOUNDARY_HACK)
3440 sp_offset = 0;
3441 #endif
3443 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY)
3445 save_var = offset_ptr->var;
3446 save_constant = offset_ptr->constant;
3449 alignment_pad->var = NULL_TREE;
3450 alignment_pad->constant = 0;
3452 if (boundary > BITS_PER_UNIT)
3454 if (offset_ptr->var)
3456 tree sp_offset_tree = ssize_int (sp_offset);
3457 tree offset = size_binop (PLUS_EXPR,
3458 ARGS_SIZE_TREE (*offset_ptr),
3459 sp_offset_tree);
3460 #ifdef ARGS_GROW_DOWNWARD
3461 tree rounded = round_down (offset, boundary / BITS_PER_UNIT);
3462 #else
3463 tree rounded = round_up (offset, boundary / BITS_PER_UNIT);
3464 #endif
3466 offset_ptr->var = size_binop (MINUS_EXPR, rounded, sp_offset_tree);
3467 /* ARGS_SIZE_TREE includes constant term. */
3468 offset_ptr->constant = 0;
3469 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY)
3470 alignment_pad->var = size_binop (MINUS_EXPR, offset_ptr->var,
3471 save_var);
3473 else
3475 offset_ptr->constant = -sp_offset +
3476 #ifdef ARGS_GROW_DOWNWARD
3477 FLOOR_ROUND (offset_ptr->constant + sp_offset, boundary_in_bytes);
3478 #else
3479 CEIL_ROUND (offset_ptr->constant + sp_offset, boundary_in_bytes);
3480 #endif
3481 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY)
3482 alignment_pad->constant = offset_ptr->constant - save_constant;
3487 static void
3488 pad_below (struct args_size *offset_ptr, enum machine_mode passed_mode, tree sizetree)
3490 if (passed_mode != BLKmode)
3492 if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
3493 offset_ptr->constant
3494 += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
3495 / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
3496 - GET_MODE_SIZE (passed_mode));
3498 else
3500 if (TREE_CODE (sizetree) != INTEGER_CST
3501 || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
3503 /* Round the size up to multiple of PARM_BOUNDARY bits. */
3504 tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
3505 /* Add it in. */
3506 ADD_PARM_SIZE (*offset_ptr, s2);
3507 SUB_PARM_SIZE (*offset_ptr, sizetree);
3512 /* Walk the tree of blocks describing the binding levels within a function
3513 and warn about variables the might be killed by setjmp or vfork.
3514 This is done after calling flow_analysis and before global_alloc
3515 clobbers the pseudo-regs to hard regs. */
3517 void
3518 setjmp_vars_warning (tree block)
3520 tree decl, sub;
3522 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
3524 if (TREE_CODE (decl) == VAR_DECL
3525 && DECL_RTL_SET_P (decl)
3526 && REG_P (DECL_RTL (decl))
3527 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
3528 warning (0, "variable %q+D might be clobbered by %<longjmp%>"
3529 " or %<vfork%>",
3530 decl);
3533 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
3534 setjmp_vars_warning (sub);
3537 /* Do the appropriate part of setjmp_vars_warning
3538 but for arguments instead of local variables. */
3540 void
3541 setjmp_args_warning (void)
3543 tree decl;
3544 for (decl = DECL_ARGUMENTS (current_function_decl);
3545 decl; decl = TREE_CHAIN (decl))
3546 if (DECL_RTL (decl) != 0
3547 && REG_P (DECL_RTL (decl))
3548 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
3549 warning (0, "argument %q+D might be clobbered by %<longjmp%> or %<vfork%>",
3550 decl);
3554 /* Identify BLOCKs referenced by more than one NOTE_INSN_BLOCK_{BEG,END},
3555 and create duplicate blocks. */
3556 /* ??? Need an option to either create block fragments or to create
3557 abstract origin duplicates of a source block. It really depends
3558 on what optimization has been performed. */
3560 void
3561 reorder_blocks (void)
3563 tree block = DECL_INITIAL (current_function_decl);
3564 VEC(tree,heap) *block_stack;
3566 if (block == NULL_TREE)
3567 return;
3569 block_stack = VEC_alloc (tree, heap, 10);
3571 /* Reset the TREE_ASM_WRITTEN bit for all blocks. */
3572 clear_block_marks (block);
3574 /* Prune the old trees away, so that they don't get in the way. */
3575 BLOCK_SUBBLOCKS (block) = NULL_TREE;
3576 BLOCK_CHAIN (block) = NULL_TREE;
3578 /* Recreate the block tree from the note nesting. */
3579 reorder_blocks_1 (get_insns (), block, &block_stack);
3580 BLOCK_SUBBLOCKS (block) = blocks_nreverse (BLOCK_SUBBLOCKS (block));
3582 /* Remove deleted blocks from the block fragment chains. */
3583 reorder_fix_fragments (block);
3585 VEC_free (tree, heap, block_stack);
3588 /* Helper function for reorder_blocks. Reset TREE_ASM_WRITTEN. */
3590 void
3591 clear_block_marks (tree block)
3593 while (block)
3595 TREE_ASM_WRITTEN (block) = 0;
3596 clear_block_marks (BLOCK_SUBBLOCKS (block));
3597 block = BLOCK_CHAIN (block);
3601 static void
3602 reorder_blocks_1 (rtx insns, tree current_block, VEC(tree,heap) **p_block_stack)
3604 rtx insn;
3606 for (insn = insns; insn; insn = NEXT_INSN (insn))
3608 if (NOTE_P (insn))
3610 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
3612 tree block = NOTE_BLOCK (insn);
3614 /* If we have seen this block before, that means it now
3615 spans multiple address regions. Create a new fragment. */
3616 if (TREE_ASM_WRITTEN (block))
3618 tree new_block = copy_node (block);
3619 tree origin;
3621 origin = (BLOCK_FRAGMENT_ORIGIN (block)
3622 ? BLOCK_FRAGMENT_ORIGIN (block)
3623 : block);
3624 BLOCK_FRAGMENT_ORIGIN (new_block) = origin;
3625 BLOCK_FRAGMENT_CHAIN (new_block)
3626 = BLOCK_FRAGMENT_CHAIN (origin);
3627 BLOCK_FRAGMENT_CHAIN (origin) = new_block;
3629 NOTE_BLOCK (insn) = new_block;
3630 block = new_block;
3633 BLOCK_SUBBLOCKS (block) = 0;
3634 TREE_ASM_WRITTEN (block) = 1;
3635 /* When there's only one block for the entire function,
3636 current_block == block and we mustn't do this, it
3637 will cause infinite recursion. */
3638 if (block != current_block)
3640 BLOCK_SUPERCONTEXT (block) = current_block;
3641 BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
3642 BLOCK_SUBBLOCKS (current_block) = block;
3643 current_block = block;
3645 VEC_safe_push (tree, heap, *p_block_stack, block);
3647 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
3649 NOTE_BLOCK (insn) = VEC_pop (tree, *p_block_stack);
3650 BLOCK_SUBBLOCKS (current_block)
3651 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
3652 current_block = BLOCK_SUPERCONTEXT (current_block);
3658 /* Rationalize BLOCK_FRAGMENT_ORIGIN. If an origin block no longer
3659 appears in the block tree, select one of the fragments to become
3660 the new origin block. */
3662 static void
3663 reorder_fix_fragments (tree block)
3665 while (block)
3667 tree dup_origin = BLOCK_FRAGMENT_ORIGIN (block);
3668 tree new_origin = NULL_TREE;
3670 if (dup_origin)
3672 if (! TREE_ASM_WRITTEN (dup_origin))
3674 new_origin = BLOCK_FRAGMENT_CHAIN (dup_origin);
3676 /* Find the first of the remaining fragments. There must
3677 be at least one -- the current block. */
3678 while (! TREE_ASM_WRITTEN (new_origin))
3679 new_origin = BLOCK_FRAGMENT_CHAIN (new_origin);
3680 BLOCK_FRAGMENT_ORIGIN (new_origin) = NULL_TREE;
3683 else if (! dup_origin)
3684 new_origin = block;
3686 /* Re-root the rest of the fragments to the new origin. In the
3687 case that DUP_ORIGIN was null, that means BLOCK was the origin
3688 of a chain of fragments and we want to remove those fragments
3689 that didn't make it to the output. */
3690 if (new_origin)
3692 tree *pp = &BLOCK_FRAGMENT_CHAIN (new_origin);
3693 tree chain = *pp;
3695 while (chain)
3697 if (TREE_ASM_WRITTEN (chain))
3699 BLOCK_FRAGMENT_ORIGIN (chain) = new_origin;
3700 *pp = chain;
3701 pp = &BLOCK_FRAGMENT_CHAIN (chain);
3703 chain = BLOCK_FRAGMENT_CHAIN (chain);
3705 *pp = NULL_TREE;
3708 reorder_fix_fragments (BLOCK_SUBBLOCKS (block));
3709 block = BLOCK_CHAIN (block);
3713 /* Reverse the order of elements in the chain T of blocks,
3714 and return the new head of the chain (old last element). */
3716 tree
3717 blocks_nreverse (tree t)
3719 tree prev = 0, decl, next;
3720 for (decl = t; decl; decl = next)
3722 next = BLOCK_CHAIN (decl);
3723 BLOCK_CHAIN (decl) = prev;
3724 prev = decl;
3726 return prev;
3729 /* Count the subblocks of the list starting with BLOCK. If VECTOR is
3730 non-NULL, list them all into VECTOR, in a depth-first preorder
3731 traversal of the block tree. Also clear TREE_ASM_WRITTEN in all
3732 blocks. */
3734 static int
3735 all_blocks (tree block, tree *vector)
3737 int n_blocks = 0;
3739 while (block)
3741 TREE_ASM_WRITTEN (block) = 0;
3743 /* Record this block. */
3744 if (vector)
3745 vector[n_blocks] = block;
3747 ++n_blocks;
3749 /* Record the subblocks, and their subblocks... */
3750 n_blocks += all_blocks (BLOCK_SUBBLOCKS (block),
3751 vector ? vector + n_blocks : 0);
3752 block = BLOCK_CHAIN (block);
3755 return n_blocks;
3758 /* Return a vector containing all the blocks rooted at BLOCK. The
3759 number of elements in the vector is stored in N_BLOCKS_P. The
3760 vector is dynamically allocated; it is the caller's responsibility
3761 to call `free' on the pointer returned. */
3763 static tree *
3764 get_block_vector (tree block, int *n_blocks_p)
3766 tree *block_vector;
3768 *n_blocks_p = all_blocks (block, NULL);
3769 block_vector = XNEWVEC (tree, *n_blocks_p);
3770 all_blocks (block, block_vector);
3772 return block_vector;
3775 static GTY(()) int next_block_index = 2;
3777 /* Set BLOCK_NUMBER for all the blocks in FN. */
3779 void
3780 number_blocks (tree fn)
3782 int i;
3783 int n_blocks;
3784 tree *block_vector;
3786 /* For SDB and XCOFF debugging output, we start numbering the blocks
3787 from 1 within each function, rather than keeping a running
3788 count. */
3789 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
3790 if (write_symbols == SDB_DEBUG || write_symbols == XCOFF_DEBUG)
3791 next_block_index = 1;
3792 #endif
3794 block_vector = get_block_vector (DECL_INITIAL (fn), &n_blocks);
3796 /* The top-level BLOCK isn't numbered at all. */
3797 for (i = 1; i < n_blocks; ++i)
3798 /* We number the blocks from two. */
3799 BLOCK_NUMBER (block_vector[i]) = next_block_index++;
3801 free (block_vector);
3803 return;
3806 /* If VAR is present in a subblock of BLOCK, return the subblock. */
3808 tree
3809 debug_find_var_in_block_tree (tree var, tree block)
3811 tree t;
3813 for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t))
3814 if (t == var)
3815 return block;
3817 for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t))
3819 tree ret = debug_find_var_in_block_tree (var, t);
3820 if (ret)
3821 return ret;
3824 return NULL_TREE;
3827 /* Allocate a function structure for FNDECL and set its contents
3828 to the defaults. */
3830 void
3831 allocate_struct_function (tree fndecl)
3833 tree result;
3834 tree fntype = fndecl ? TREE_TYPE (fndecl) : NULL_TREE;
3836 cfun = ggc_alloc_cleared (sizeof (struct function));
3838 cfun->stack_alignment_needed = STACK_BOUNDARY;
3839 cfun->preferred_stack_boundary = STACK_BOUNDARY;
3841 current_function_funcdef_no = funcdef_no++;
3843 cfun->function_frequency = FUNCTION_FREQUENCY_NORMAL;
3845 init_eh_for_function ();
3847 lang_hooks.function.init (cfun);
3848 if (init_machine_status)
3849 cfun->machine = (*init_machine_status) ();
3851 if (fndecl == NULL)
3852 return;
3854 DECL_STRUCT_FUNCTION (fndecl) = cfun;
3855 cfun->decl = fndecl;
3857 result = DECL_RESULT (fndecl);
3858 if (aggregate_value_p (result, fndecl))
3860 #ifdef PCC_STATIC_STRUCT_RETURN
3861 current_function_returns_pcc_struct = 1;
3862 #endif
3863 current_function_returns_struct = 1;
3866 current_function_returns_pointer = POINTER_TYPE_P (TREE_TYPE (result));
3868 current_function_stdarg
3869 = (fntype
3870 && TYPE_ARG_TYPES (fntype) != 0
3871 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3872 != void_type_node));
3874 /* Assume all registers in stdarg functions need to be saved. */
3875 cfun->va_list_gpr_size = VA_LIST_MAX_GPR_SIZE;
3876 cfun->va_list_fpr_size = VA_LIST_MAX_FPR_SIZE;
3879 /* Reset cfun, and other non-struct-function variables to defaults as
3880 appropriate for emitting rtl at the start of a function. */
3882 static void
3883 prepare_function_start (tree fndecl)
3885 if (fndecl && DECL_STRUCT_FUNCTION (fndecl))
3886 cfun = DECL_STRUCT_FUNCTION (fndecl);
3887 else
3888 allocate_struct_function (fndecl);
3889 init_emit ();
3890 init_varasm_status (cfun);
3891 init_expr ();
3893 cse_not_expected = ! optimize;
3895 /* Caller save not needed yet. */
3896 caller_save_needed = 0;
3898 /* We haven't done register allocation yet. */
3899 reg_renumber = 0;
3901 /* Indicate that we have not instantiated virtual registers yet. */
3902 virtuals_instantiated = 0;
3904 /* Indicate that we want CONCATs now. */
3905 generating_concat_p = 1;
3907 /* Indicate we have no need of a frame pointer yet. */
3908 frame_pointer_needed = 0;
3911 /* Initialize the rtl expansion mechanism so that we can do simple things
3912 like generate sequences. This is used to provide a context during global
3913 initialization of some passes. */
3914 void
3915 init_dummy_function_start (void)
3917 prepare_function_start (NULL);
3920 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
3921 and initialize static variables for generating RTL for the statements
3922 of the function. */
3924 void
3925 init_function_start (tree subr)
3927 prepare_function_start (subr);
3929 /* Prevent ever trying to delete the first instruction of a
3930 function. Also tell final how to output a linenum before the
3931 function prologue. Note linenums could be missing, e.g. when
3932 compiling a Java .class file. */
3933 if (! DECL_IS_BUILTIN (subr))
3934 emit_line_note (DECL_SOURCE_LOCATION (subr));
3936 /* Make sure first insn is a note even if we don't want linenums.
3937 This makes sure the first insn will never be deleted.
3938 Also, final expects a note to appear there. */
3939 emit_note (NOTE_INSN_DELETED);
3941 /* Warn if this value is an aggregate type,
3942 regardless of which calling convention we are using for it. */
3943 if (AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
3944 warning (OPT_Waggregate_return, "function returns an aggregate");
3947 /* Make sure all values used by the optimization passes have sane
3948 defaults. */
3949 unsigned int
3950 init_function_for_compilation (void)
3952 reg_renumber = 0;
3954 /* No prologue/epilogue insns yet. Make sure that these vectors are
3955 empty. */
3956 gcc_assert (VEC_length (int, prologue) == 0);
3957 gcc_assert (VEC_length (int, epilogue) == 0);
3958 gcc_assert (VEC_length (int, sibcall_epilogue) == 0);
3959 return 0;
3962 struct tree_opt_pass pass_init_function =
3964 NULL, /* name */
3965 NULL, /* gate */
3966 init_function_for_compilation, /* execute */
3967 NULL, /* sub */
3968 NULL, /* next */
3969 0, /* static_pass_number */
3970 0, /* tv_id */
3971 0, /* properties_required */
3972 0, /* properties_provided */
3973 0, /* properties_destroyed */
3974 0, /* todo_flags_start */
3975 0, /* todo_flags_finish */
3976 0 /* letter */
3980 void
3981 expand_main_function (void)
3983 #if (defined(INVOKE__main) \
3984 || (!defined(HAS_INIT_SECTION) \
3985 && !defined(INIT_SECTION_ASM_OP) \
3986 && !defined(INIT_ARRAY_SECTION_ASM_OP)))
3987 emit_library_call (init_one_libfunc (NAME__MAIN), LCT_NORMAL, VOIDmode, 0);
3988 #endif
3991 /* Expand code to initialize the stack_protect_guard. This is invoked at
3992 the beginning of a function to be protected. */
3994 #ifndef HAVE_stack_protect_set
3995 # define HAVE_stack_protect_set 0
3996 # define gen_stack_protect_set(x,y) (gcc_unreachable (), NULL_RTX)
3997 #endif
3999 void
4000 stack_protect_prologue (void)
4002 tree guard_decl = targetm.stack_protect_guard ();
4003 rtx x, y;
4005 /* Avoid expand_expr here, because we don't want guard_decl pulled
4006 into registers unless absolutely necessary. And we know that
4007 cfun->stack_protect_guard is a local stack slot, so this skips
4008 all the fluff. */
4009 x = validize_mem (DECL_RTL (cfun->stack_protect_guard));
4010 y = validize_mem (DECL_RTL (guard_decl));
4012 /* Allow the target to copy from Y to X without leaking Y into a
4013 register. */
4014 if (HAVE_stack_protect_set)
4016 rtx insn = gen_stack_protect_set (x, y);
4017 if (insn)
4019 emit_insn (insn);
4020 return;
4024 /* Otherwise do a straight move. */
4025 emit_move_insn (x, y);
4028 /* Expand code to verify the stack_protect_guard. This is invoked at
4029 the end of a function to be protected. */
4031 #ifndef HAVE_stack_protect_test
4032 # define HAVE_stack_protect_test 0
4033 # define gen_stack_protect_test(x, y, z) (gcc_unreachable (), NULL_RTX)
4034 #endif
4036 void
4037 stack_protect_epilogue (void)
4039 tree guard_decl = targetm.stack_protect_guard ();
4040 rtx label = gen_label_rtx ();
4041 rtx x, y, tmp;
4043 /* Avoid expand_expr here, because we don't want guard_decl pulled
4044 into registers unless absolutely necessary. And we know that
4045 cfun->stack_protect_guard is a local stack slot, so this skips
4046 all the fluff. */
4047 x = validize_mem (DECL_RTL (cfun->stack_protect_guard));
4048 y = validize_mem (DECL_RTL (guard_decl));
4050 /* Allow the target to compare Y with X without leaking either into
4051 a register. */
4052 switch (HAVE_stack_protect_test != 0)
4054 case 1:
4055 tmp = gen_stack_protect_test (x, y, label);
4056 if (tmp)
4058 emit_insn (tmp);
4059 break;
4061 /* FALLTHRU */
4063 default:
4064 emit_cmp_and_jump_insns (x, y, EQ, NULL_RTX, ptr_mode, 1, label);
4065 break;
4068 /* The noreturn predictor has been moved to the tree level. The rtl-level
4069 predictors estimate this branch about 20%, which isn't enough to get
4070 things moved out of line. Since this is the only extant case of adding
4071 a noreturn function at the rtl level, it doesn't seem worth doing ought
4072 except adding the prediction by hand. */
4073 tmp = get_last_insn ();
4074 if (JUMP_P (tmp))
4075 predict_insn_def (tmp, PRED_NORETURN, TAKEN);
4077 expand_expr_stmt (targetm.stack_protect_fail ());
4078 emit_label (label);
4081 /* Start the RTL for a new function, and set variables used for
4082 emitting RTL.
4083 SUBR is the FUNCTION_DECL node.
4084 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
4085 the function's parameters, which must be run at any return statement. */
4087 void
4088 expand_function_start (tree subr)
4090 /* Make sure volatile mem refs aren't considered
4091 valid operands of arithmetic insns. */
4092 init_recog_no_volatile ();
4094 current_function_profile
4095 = (profile_flag
4096 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr));
4098 current_function_limit_stack
4099 = (stack_limit_rtx != NULL_RTX && ! DECL_NO_LIMIT_STACK (subr));
4101 /* Make the label for return statements to jump to. Do not special
4102 case machines with special return instructions -- they will be
4103 handled later during jump, ifcvt, or epilogue creation. */
4104 return_label = gen_label_rtx ();
4106 /* Initialize rtx used to return the value. */
4107 /* Do this before assign_parms so that we copy the struct value address
4108 before any library calls that assign parms might generate. */
4110 /* Decide whether to return the value in memory or in a register. */
4111 if (aggregate_value_p (DECL_RESULT (subr), subr))
4113 /* Returning something that won't go in a register. */
4114 rtx value_address = 0;
4116 #ifdef PCC_STATIC_STRUCT_RETURN
4117 if (current_function_returns_pcc_struct)
4119 int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
4120 value_address = assemble_static_space (size);
4122 else
4123 #endif
4125 rtx sv = targetm.calls.struct_value_rtx (TREE_TYPE (subr), 2);
4126 /* Expect to be passed the address of a place to store the value.
4127 If it is passed as an argument, assign_parms will take care of
4128 it. */
4129 if (sv)
4131 value_address = gen_reg_rtx (Pmode);
4132 emit_move_insn (value_address, sv);
4135 if (value_address)
4137 rtx x = value_address;
4138 if (!DECL_BY_REFERENCE (DECL_RESULT (subr)))
4140 x = gen_rtx_MEM (DECL_MODE (DECL_RESULT (subr)), x);
4141 set_mem_attributes (x, DECL_RESULT (subr), 1);
4143 SET_DECL_RTL (DECL_RESULT (subr), x);
4146 else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
4147 /* If return mode is void, this decl rtl should not be used. */
4148 SET_DECL_RTL (DECL_RESULT (subr), NULL_RTX);
4149 else
4151 /* Compute the return values into a pseudo reg, which we will copy
4152 into the true return register after the cleanups are done. */
4153 tree return_type = TREE_TYPE (DECL_RESULT (subr));
4154 if (TYPE_MODE (return_type) != BLKmode
4155 && targetm.calls.return_in_msb (return_type))
4156 /* expand_function_end will insert the appropriate padding in
4157 this case. Use the return value's natural (unpadded) mode
4158 within the function proper. */
4159 SET_DECL_RTL (DECL_RESULT (subr),
4160 gen_reg_rtx (TYPE_MODE (return_type)));
4161 else
4163 /* In order to figure out what mode to use for the pseudo, we
4164 figure out what the mode of the eventual return register will
4165 actually be, and use that. */
4166 rtx hard_reg = hard_function_value (return_type, subr, 0, 1);
4168 /* Structures that are returned in registers are not
4169 aggregate_value_p, so we may see a PARALLEL or a REG. */
4170 if (REG_P (hard_reg))
4171 SET_DECL_RTL (DECL_RESULT (subr),
4172 gen_reg_rtx (GET_MODE (hard_reg)));
4173 else
4175 gcc_assert (GET_CODE (hard_reg) == PARALLEL);
4176 SET_DECL_RTL (DECL_RESULT (subr), gen_group_rtx (hard_reg));
4180 /* Set DECL_REGISTER flag so that expand_function_end will copy the
4181 result to the real return register(s). */
4182 DECL_REGISTER (DECL_RESULT (subr)) = 1;
4185 /* Initialize rtx for parameters and local variables.
4186 In some cases this requires emitting insns. */
4187 assign_parms (subr);
4189 /* If function gets a static chain arg, store it. */
4190 if (cfun->static_chain_decl)
4192 tree parm = cfun->static_chain_decl;
4193 rtx local = gen_reg_rtx (Pmode);
4195 set_decl_incoming_rtl (parm, static_chain_incoming_rtx);
4196 SET_DECL_RTL (parm, local);
4197 mark_reg_pointer (local, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm))));
4199 emit_move_insn (local, static_chain_incoming_rtx);
4202 /* If the function receives a non-local goto, then store the
4203 bits we need to restore the frame pointer. */
4204 if (cfun->nonlocal_goto_save_area)
4206 tree t_save;
4207 rtx r_save;
4209 /* ??? We need to do this save early. Unfortunately here is
4210 before the frame variable gets declared. Help out... */
4211 expand_var (TREE_OPERAND (cfun->nonlocal_goto_save_area, 0));
4213 t_save = build4 (ARRAY_REF, ptr_type_node,
4214 cfun->nonlocal_goto_save_area,
4215 integer_zero_node, NULL_TREE, NULL_TREE);
4216 r_save = expand_expr (t_save, NULL_RTX, VOIDmode, EXPAND_WRITE);
4217 r_save = convert_memory_address (Pmode, r_save);
4219 emit_move_insn (r_save, virtual_stack_vars_rtx);
4220 update_nonlocal_goto_save_area ();
4223 /* The following was moved from init_function_start.
4224 The move is supposed to make sdb output more accurate. */
4225 /* Indicate the beginning of the function body,
4226 as opposed to parm setup. */
4227 emit_note (NOTE_INSN_FUNCTION_BEG);
4229 gcc_assert (NOTE_P (get_last_insn ()));
4231 parm_birth_insn = get_last_insn ();
4233 if (current_function_profile)
4235 #ifdef PROFILE_HOOK
4236 PROFILE_HOOK (current_function_funcdef_no);
4237 #endif
4240 /* After the display initializations is where the stack checking
4241 probe should go. */
4242 if(flag_stack_check)
4243 stack_check_probe_note = emit_note (NOTE_INSN_DELETED);
4245 /* Make sure there is a line number after the function entry setup code. */
4246 force_next_line_note ();
4249 /* Undo the effects of init_dummy_function_start. */
4250 void
4251 expand_dummy_function_end (void)
4253 /* End any sequences that failed to be closed due to syntax errors. */
4254 while (in_sequence_p ())
4255 end_sequence ();
4257 /* Outside function body, can't compute type's actual size
4258 until next function's body starts. */
4260 free_after_parsing (cfun);
4261 free_after_compilation (cfun);
4262 cfun = 0;
4265 /* Call DOIT for each hard register used as a return value from
4266 the current function. */
4268 void
4269 diddle_return_value (void (*doit) (rtx, void *), void *arg)
4271 rtx outgoing = current_function_return_rtx;
4273 if (! outgoing)
4274 return;
4276 if (REG_P (outgoing))
4277 (*doit) (outgoing, arg);
4278 else if (GET_CODE (outgoing) == PARALLEL)
4280 int i;
4282 for (i = 0; i < XVECLEN (outgoing, 0); i++)
4284 rtx x = XEXP (XVECEXP (outgoing, 0, i), 0);
4286 if (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
4287 (*doit) (x, arg);
4292 static void
4293 do_clobber_return_reg (rtx reg, void *arg ATTRIBUTE_UNUSED)
4295 emit_insn (gen_rtx_CLOBBER (VOIDmode, reg));
4298 void
4299 clobber_return_register (void)
4301 diddle_return_value (do_clobber_return_reg, NULL);
4303 /* In case we do use pseudo to return value, clobber it too. */
4304 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl)))
4306 tree decl_result = DECL_RESULT (current_function_decl);
4307 rtx decl_rtl = DECL_RTL (decl_result);
4308 if (REG_P (decl_rtl) && REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER)
4310 do_clobber_return_reg (decl_rtl, NULL);
4315 static void
4316 do_use_return_reg (rtx reg, void *arg ATTRIBUTE_UNUSED)
4318 emit_insn (gen_rtx_USE (VOIDmode, reg));
4321 static void
4322 use_return_register (void)
4324 diddle_return_value (do_use_return_reg, NULL);
4327 /* Possibly warn about unused parameters. */
4328 void
4329 do_warn_unused_parameter (tree fn)
4331 tree decl;
4333 for (decl = DECL_ARGUMENTS (fn);
4334 decl; decl = TREE_CHAIN (decl))
4335 if (!TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
4336 && DECL_NAME (decl) && !DECL_ARTIFICIAL (decl))
4337 warning (OPT_Wunused_parameter, "unused parameter %q+D", decl);
4340 static GTY(()) rtx initial_trampoline;
4342 /* Generate RTL for the end of the current function. */
4344 void
4345 expand_function_end (void)
4347 rtx clobber_after;
4349 /* If arg_pointer_save_area was referenced only from a nested
4350 function, we will not have initialized it yet. Do that now. */
4351 if (arg_pointer_save_area && ! cfun->arg_pointer_save_area_init)
4352 get_arg_pointer_save_area (cfun);
4354 /* If we are doing stack checking and this function makes calls,
4355 do a stack probe at the start of the function to ensure we have enough
4356 space for another stack frame. */
4357 if (flag_stack_check && ! STACK_CHECK_BUILTIN)
4359 rtx insn, seq;
4361 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4362 if (CALL_P (insn))
4364 start_sequence ();
4365 probe_stack_range (STACK_CHECK_PROTECT,
4366 GEN_INT (STACK_CHECK_MAX_FRAME_SIZE));
4367 seq = get_insns ();
4368 end_sequence ();
4369 emit_insn_before (seq, stack_check_probe_note);
4370 break;
4374 /* Possibly warn about unused parameters.
4375 When frontend does unit-at-a-time, the warning is already
4376 issued at finalization time. */
4377 if (warn_unused_parameter
4378 && !lang_hooks.callgraph.expand_function)
4379 do_warn_unused_parameter (current_function_decl);
4381 /* End any sequences that failed to be closed due to syntax errors. */
4382 while (in_sequence_p ())
4383 end_sequence ();
4385 clear_pending_stack_adjust ();
4386 do_pending_stack_adjust ();
4388 /* Mark the end of the function body.
4389 If control reaches this insn, the function can drop through
4390 without returning a value. */
4391 emit_note (NOTE_INSN_FUNCTION_END);
4393 /* Must mark the last line number note in the function, so that the test
4394 coverage code can avoid counting the last line twice. This just tells
4395 the code to ignore the immediately following line note, since there
4396 already exists a copy of this note somewhere above. This line number
4397 note is still needed for debugging though, so we can't delete it. */
4398 if (flag_test_coverage)
4399 emit_note (NOTE_INSN_REPEATED_LINE_NUMBER);
4401 /* Output a linenumber for the end of the function.
4402 SDB depends on this. */
4403 force_next_line_note ();
4404 emit_line_note (input_location);
4406 /* Before the return label (if any), clobber the return
4407 registers so that they are not propagated live to the rest of
4408 the function. This can only happen with functions that drop
4409 through; if there had been a return statement, there would
4410 have either been a return rtx, or a jump to the return label.
4412 We delay actual code generation after the current_function_value_rtx
4413 is computed. */
4414 clobber_after = get_last_insn ();
4416 /* Output the label for the actual return from the function. */
4417 emit_label (return_label);
4419 if (USING_SJLJ_EXCEPTIONS)
4421 /* Let except.c know where it should emit the call to unregister
4422 the function context for sjlj exceptions. */
4423 if (flag_exceptions)
4424 sjlj_emit_function_exit_after (get_last_insn ());
4426 else
4428 /* @@@ This is a kludge. We want to ensure that instructions that
4429 may trap are not moved into the epilogue by scheduling, because
4430 we don't always emit unwind information for the epilogue.
4431 However, not all machine descriptions define a blockage insn, so
4432 emit an ASM_INPUT to act as one. */
4433 if (flag_non_call_exceptions)
4434 emit_insn (gen_rtx_ASM_INPUT (VOIDmode, ""));
4437 /* If this is an implementation of throw, do what's necessary to
4438 communicate between __builtin_eh_return and the epilogue. */
4439 expand_eh_return ();
4441 /* If scalar return value was computed in a pseudo-reg, or was a named
4442 return value that got dumped to the stack, copy that to the hard
4443 return register. */
4444 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl)))
4446 tree decl_result = DECL_RESULT (current_function_decl);
4447 rtx decl_rtl = DECL_RTL (decl_result);
4449 if (REG_P (decl_rtl)
4450 ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
4451 : DECL_REGISTER (decl_result))
4453 rtx real_decl_rtl = current_function_return_rtx;
4455 /* This should be set in assign_parms. */
4456 gcc_assert (REG_FUNCTION_VALUE_P (real_decl_rtl));
4458 /* If this is a BLKmode structure being returned in registers,
4459 then use the mode computed in expand_return. Note that if
4460 decl_rtl is memory, then its mode may have been changed,
4461 but that current_function_return_rtx has not. */
4462 if (GET_MODE (real_decl_rtl) == BLKmode)
4463 PUT_MODE (real_decl_rtl, GET_MODE (decl_rtl));
4465 /* If a non-BLKmode return value should be padded at the least
4466 significant end of the register, shift it left by the appropriate
4467 amount. BLKmode results are handled using the group load/store
4468 machinery. */
4469 if (TYPE_MODE (TREE_TYPE (decl_result)) != BLKmode
4470 && targetm.calls.return_in_msb (TREE_TYPE (decl_result)))
4472 emit_move_insn (gen_rtx_REG (GET_MODE (decl_rtl),
4473 REGNO (real_decl_rtl)),
4474 decl_rtl);
4475 shift_return_value (GET_MODE (decl_rtl), true, real_decl_rtl);
4477 /* If a named return value dumped decl_return to memory, then
4478 we may need to re-do the PROMOTE_MODE signed/unsigned
4479 extension. */
4480 else if (GET_MODE (real_decl_rtl) != GET_MODE (decl_rtl))
4482 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (decl_result));
4484 if (targetm.calls.promote_function_return (TREE_TYPE (current_function_decl)))
4485 promote_mode (TREE_TYPE (decl_result), GET_MODE (decl_rtl),
4486 &unsignedp, 1);
4488 convert_move (real_decl_rtl, decl_rtl, unsignedp);
4490 else if (GET_CODE (real_decl_rtl) == PARALLEL)
4492 /* If expand_function_start has created a PARALLEL for decl_rtl,
4493 move the result to the real return registers. Otherwise, do
4494 a group load from decl_rtl for a named return. */
4495 if (GET_CODE (decl_rtl) == PARALLEL)
4496 emit_group_move (real_decl_rtl, decl_rtl);
4497 else
4498 emit_group_load (real_decl_rtl, decl_rtl,
4499 TREE_TYPE (decl_result),
4500 int_size_in_bytes (TREE_TYPE (decl_result)));
4502 /* In the case of complex integer modes smaller than a word, we'll
4503 need to generate some non-trivial bitfield insertions. Do that
4504 on a pseudo and not the hard register. */
4505 else if (GET_CODE (decl_rtl) == CONCAT
4506 && GET_MODE_CLASS (GET_MODE (decl_rtl)) == MODE_COMPLEX_INT
4507 && GET_MODE_BITSIZE (GET_MODE (decl_rtl)) <= BITS_PER_WORD)
4509 int old_generating_concat_p;
4510 rtx tmp;
4512 old_generating_concat_p = generating_concat_p;
4513 generating_concat_p = 0;
4514 tmp = gen_reg_rtx (GET_MODE (decl_rtl));
4515 generating_concat_p = old_generating_concat_p;
4517 emit_move_insn (tmp, decl_rtl);
4518 emit_move_insn (real_decl_rtl, tmp);
4520 else
4521 emit_move_insn (real_decl_rtl, decl_rtl);
4525 /* If returning a structure, arrange to return the address of the value
4526 in a place where debuggers expect to find it.
4528 If returning a structure PCC style,
4529 the caller also depends on this value.
4530 And current_function_returns_pcc_struct is not necessarily set. */
4531 if (current_function_returns_struct
4532 || current_function_returns_pcc_struct)
4534 rtx value_address = DECL_RTL (DECL_RESULT (current_function_decl));
4535 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
4536 rtx outgoing;
4538 if (DECL_BY_REFERENCE (DECL_RESULT (current_function_decl)))
4539 type = TREE_TYPE (type);
4540 else
4541 value_address = XEXP (value_address, 0);
4543 outgoing = targetm.calls.function_value (build_pointer_type (type),
4544 current_function_decl, true);
4546 /* Mark this as a function return value so integrate will delete the
4547 assignment and USE below when inlining this function. */
4548 REG_FUNCTION_VALUE_P (outgoing) = 1;
4550 /* The address may be ptr_mode and OUTGOING may be Pmode. */
4551 value_address = convert_memory_address (GET_MODE (outgoing),
4552 value_address);
4554 emit_move_insn (outgoing, value_address);
4556 /* Show return register used to hold result (in this case the address
4557 of the result. */
4558 current_function_return_rtx = outgoing;
4561 /* Emit the actual code to clobber return register. */
4563 rtx seq;
4565 start_sequence ();
4566 clobber_return_register ();
4567 expand_naked_return ();
4568 seq = get_insns ();
4569 end_sequence ();
4571 emit_insn_after (seq, clobber_after);
4574 /* Output the label for the naked return from the function. */
4575 emit_label (naked_return_label);
4577 /* If stack protection is enabled for this function, check the guard. */
4578 if (cfun->stack_protect_guard)
4579 stack_protect_epilogue ();
4581 /* If we had calls to alloca, and this machine needs
4582 an accurate stack pointer to exit the function,
4583 insert some code to save and restore the stack pointer. */
4584 if (! EXIT_IGNORE_STACK
4585 && current_function_calls_alloca)
4587 rtx tem = 0;
4589 emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
4590 emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
4593 /* ??? This should no longer be necessary since stupid is no longer with
4594 us, but there are some parts of the compiler (eg reload_combine, and
4595 sh mach_dep_reorg) that still try and compute their own lifetime info
4596 instead of using the general framework. */
4597 use_return_register ();
4601 get_arg_pointer_save_area (struct function *f)
4603 rtx ret = f->x_arg_pointer_save_area;
4605 if (! ret)
4607 ret = assign_stack_local_1 (Pmode, GET_MODE_SIZE (Pmode), 0, f);
4608 f->x_arg_pointer_save_area = ret;
4611 if (f == cfun && ! f->arg_pointer_save_area_init)
4613 rtx seq;
4615 /* Save the arg pointer at the beginning of the function. The
4616 generated stack slot may not be a valid memory address, so we
4617 have to check it and fix it if necessary. */
4618 start_sequence ();
4619 emit_move_insn (validize_mem (ret), virtual_incoming_args_rtx);
4620 seq = get_insns ();
4621 end_sequence ();
4623 push_topmost_sequence ();
4624 emit_insn_after (seq, entry_of_function ());
4625 pop_topmost_sequence ();
4628 return ret;
4631 /* Extend a vector that records the INSN_UIDs of INSNS
4632 (a list of one or more insns). */
4634 static void
4635 record_insns (rtx insns, VEC(int,heap) **vecp)
4637 rtx tmp;
4639 for (tmp = insns; tmp != NULL_RTX; tmp = NEXT_INSN (tmp))
4640 VEC_safe_push (int, heap, *vecp, INSN_UID (tmp));
4643 /* Set the locator of the insn chain starting at INSN to LOC. */
4644 static void
4645 set_insn_locators (rtx insn, int loc)
4647 while (insn != NULL_RTX)
4649 if (INSN_P (insn))
4650 INSN_LOCATOR (insn) = loc;
4651 insn = NEXT_INSN (insn);
4655 /* Determine how many INSN_UIDs in VEC are part of INSN. Because we can
4656 be running after reorg, SEQUENCE rtl is possible. */
4658 static int
4659 contains (rtx insn, VEC(int,heap) **vec)
4661 int i, j;
4663 if (NONJUMP_INSN_P (insn)
4664 && GET_CODE (PATTERN (insn)) == SEQUENCE)
4666 int count = 0;
4667 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
4668 for (j = VEC_length (int, *vec) - 1; j >= 0; --j)
4669 if (INSN_UID (XVECEXP (PATTERN (insn), 0, i))
4670 == VEC_index (int, *vec, j))
4671 count++;
4672 return count;
4674 else
4676 for (j = VEC_length (int, *vec) - 1; j >= 0; --j)
4677 if (INSN_UID (insn) == VEC_index (int, *vec, j))
4678 return 1;
4680 return 0;
4684 prologue_epilogue_contains (rtx insn)
4686 if (contains (insn, &prologue))
4687 return 1;
4688 if (contains (insn, &epilogue))
4689 return 1;
4690 return 0;
4694 sibcall_epilogue_contains (rtx insn)
4696 if (sibcall_epilogue)
4697 return contains (insn, &sibcall_epilogue);
4698 return 0;
4701 #ifdef HAVE_return
4702 /* Insert gen_return at the end of block BB. This also means updating
4703 block_for_insn appropriately. */
4705 static void
4706 emit_return_into_block (basic_block bb, rtx line_note)
4708 emit_jump_insn_after (gen_return (), BB_END (bb));
4709 if (line_note)
4710 emit_note_copy_after (line_note, PREV_INSN (BB_END (bb)));
4712 #endif /* HAVE_return */
4714 #if defined(HAVE_epilogue) && defined(INCOMING_RETURN_ADDR_RTX)
4716 /* These functions convert the epilogue into a variant that does not
4717 modify the stack pointer. This is used in cases where a function
4718 returns an object whose size is not known until it is computed.
4719 The called function leaves the object on the stack, leaves the
4720 stack depressed, and returns a pointer to the object.
4722 What we need to do is track all modifications and references to the
4723 stack pointer, deleting the modifications and changing the
4724 references to point to the location the stack pointer would have
4725 pointed to had the modifications taken place.
4727 These functions need to be portable so we need to make as few
4728 assumptions about the epilogue as we can. However, the epilogue
4729 basically contains three things: instructions to reset the stack
4730 pointer, instructions to reload registers, possibly including the
4731 frame pointer, and an instruction to return to the caller.
4733 We must be sure of what a relevant epilogue insn is doing. We also
4734 make no attempt to validate the insns we make since if they are
4735 invalid, we probably can't do anything valid. The intent is that
4736 these routines get "smarter" as more and more machines start to use
4737 them and they try operating on different epilogues.
4739 We use the following structure to track what the part of the
4740 epilogue that we've already processed has done. We keep two copies
4741 of the SP equivalence, one for use during the insn we are
4742 processing and one for use in the next insn. The difference is
4743 because one part of a PARALLEL may adjust SP and the other may use
4744 it. */
4746 struct epi_info
4748 rtx sp_equiv_reg; /* REG that SP is set from, perhaps SP. */
4749 HOST_WIDE_INT sp_offset; /* Offset from SP_EQUIV_REG of present SP. */
4750 rtx new_sp_equiv_reg; /* REG to be used at end of insn. */
4751 HOST_WIDE_INT new_sp_offset; /* Offset to be used at end of insn. */
4752 rtx equiv_reg_src; /* If nonzero, the value that SP_EQUIV_REG
4753 should be set to once we no longer need
4754 its value. */
4755 rtx const_equiv[FIRST_PSEUDO_REGISTER]; /* Any known constant equivalences
4756 for registers. */
4759 static void handle_epilogue_set (rtx, struct epi_info *);
4760 static void update_epilogue_consts (rtx, rtx, void *);
4761 static void emit_equiv_load (struct epi_info *);
4763 /* Modify INSN, a list of one or more insns that is part of the epilogue, to
4764 no modifications to the stack pointer. Return the new list of insns. */
4766 static rtx
4767 keep_stack_depressed (rtx insns)
4769 int j;
4770 struct epi_info info;
4771 rtx insn, next;
4773 /* If the epilogue is just a single instruction, it must be OK as is. */
4774 if (NEXT_INSN (insns) == NULL_RTX)
4775 return insns;
4777 /* Otherwise, start a sequence, initialize the information we have, and
4778 process all the insns we were given. */
4779 start_sequence ();
4781 info.sp_equiv_reg = stack_pointer_rtx;
4782 info.sp_offset = 0;
4783 info.equiv_reg_src = 0;
4785 for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
4786 info.const_equiv[j] = 0;
4788 insn = insns;
4789 next = NULL_RTX;
4790 while (insn != NULL_RTX)
4792 next = NEXT_INSN (insn);
4794 if (!INSN_P (insn))
4796 add_insn (insn);
4797 insn = next;
4798 continue;
4801 /* If this insn references the register that SP is equivalent to and
4802 we have a pending load to that register, we must force out the load
4803 first and then indicate we no longer know what SP's equivalent is. */
4804 if (info.equiv_reg_src != 0
4805 && reg_referenced_p (info.sp_equiv_reg, PATTERN (insn)))
4807 emit_equiv_load (&info);
4808 info.sp_equiv_reg = 0;
4811 info.new_sp_equiv_reg = info.sp_equiv_reg;
4812 info.new_sp_offset = info.sp_offset;
4814 /* If this is a (RETURN) and the return address is on the stack,
4815 update the address and change to an indirect jump. */
4816 if (GET_CODE (PATTERN (insn)) == RETURN
4817 || (GET_CODE (PATTERN (insn)) == PARALLEL
4818 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == RETURN))
4820 rtx retaddr = INCOMING_RETURN_ADDR_RTX;
4821 rtx base = 0;
4822 HOST_WIDE_INT offset = 0;
4823 rtx jump_insn, jump_set;
4825 /* If the return address is in a register, we can emit the insn
4826 unchanged. Otherwise, it must be a MEM and we see what the
4827 base register and offset are. In any case, we have to emit any
4828 pending load to the equivalent reg of SP, if any. */
4829 if (REG_P (retaddr))
4831 emit_equiv_load (&info);
4832 add_insn (insn);
4833 insn = next;
4834 continue;
4836 else
4838 rtx ret_ptr;
4839 gcc_assert (MEM_P (retaddr));
4841 ret_ptr = XEXP (retaddr, 0);
4843 if (REG_P (ret_ptr))
4845 base = gen_rtx_REG (Pmode, REGNO (ret_ptr));
4846 offset = 0;
4848 else
4850 gcc_assert (GET_CODE (ret_ptr) == PLUS
4851 && REG_P (XEXP (ret_ptr, 0))
4852 && GET_CODE (XEXP (ret_ptr, 1)) == CONST_INT);
4853 base = gen_rtx_REG (Pmode, REGNO (XEXP (ret_ptr, 0)));
4854 offset = INTVAL (XEXP (ret_ptr, 1));
4858 /* If the base of the location containing the return pointer
4859 is SP, we must update it with the replacement address. Otherwise,
4860 just build the necessary MEM. */
4861 retaddr = plus_constant (base, offset);
4862 if (base == stack_pointer_rtx)
4863 retaddr = simplify_replace_rtx (retaddr, stack_pointer_rtx,
4864 plus_constant (info.sp_equiv_reg,
4865 info.sp_offset));
4867 retaddr = gen_rtx_MEM (Pmode, retaddr);
4868 MEM_NOTRAP_P (retaddr) = 1;
4870 /* If there is a pending load to the equivalent register for SP
4871 and we reference that register, we must load our address into
4872 a scratch register and then do that load. */
4873 if (info.equiv_reg_src
4874 && reg_overlap_mentioned_p (info.equiv_reg_src, retaddr))
4876 unsigned int regno;
4877 rtx reg;
4879 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
4880 if (HARD_REGNO_MODE_OK (regno, Pmode)
4881 && !fixed_regs[regno]
4882 && TEST_HARD_REG_BIT (regs_invalidated_by_call, regno)
4883 && !REGNO_REG_SET_P
4884 (EXIT_BLOCK_PTR->il.rtl->global_live_at_start, regno)
4885 && !refers_to_regno_p (regno,
4886 regno + hard_regno_nregs[regno]
4887 [Pmode],
4888 info.equiv_reg_src, NULL)
4889 && info.const_equiv[regno] == 0)
4890 break;
4892 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
4894 reg = gen_rtx_REG (Pmode, regno);
4895 emit_move_insn (reg, retaddr);
4896 retaddr = reg;
4899 emit_equiv_load (&info);
4900 jump_insn = emit_jump_insn (gen_indirect_jump (retaddr));
4902 /* Show the SET in the above insn is a RETURN. */
4903 jump_set = single_set (jump_insn);
4904 gcc_assert (jump_set);
4905 SET_IS_RETURN_P (jump_set) = 1;
4908 /* If SP is not mentioned in the pattern and its equivalent register, if
4909 any, is not modified, just emit it. Otherwise, if neither is set,
4910 replace the reference to SP and emit the insn. If none of those are
4911 true, handle each SET individually. */
4912 else if (!reg_mentioned_p (stack_pointer_rtx, PATTERN (insn))
4913 && (info.sp_equiv_reg == stack_pointer_rtx
4914 || !reg_set_p (info.sp_equiv_reg, insn)))
4915 add_insn (insn);
4916 else if (! reg_set_p (stack_pointer_rtx, insn)
4917 && (info.sp_equiv_reg == stack_pointer_rtx
4918 || !reg_set_p (info.sp_equiv_reg, insn)))
4920 int changed;
4922 changed = validate_replace_rtx (stack_pointer_rtx,
4923 plus_constant (info.sp_equiv_reg,
4924 info.sp_offset),
4925 insn);
4926 gcc_assert (changed);
4928 add_insn (insn);
4930 else if (GET_CODE (PATTERN (insn)) == SET)
4931 handle_epilogue_set (PATTERN (insn), &info);
4932 else if (GET_CODE (PATTERN (insn)) == PARALLEL)
4934 for (j = 0; j < XVECLEN (PATTERN (insn), 0); j++)
4935 if (GET_CODE (XVECEXP (PATTERN (insn), 0, j)) == SET)
4936 handle_epilogue_set (XVECEXP (PATTERN (insn), 0, j), &info);
4938 else
4939 add_insn (insn);
4941 info.sp_equiv_reg = info.new_sp_equiv_reg;
4942 info.sp_offset = info.new_sp_offset;
4944 /* Now update any constants this insn sets. */
4945 note_stores (PATTERN (insn), update_epilogue_consts, &info);
4946 insn = next;
4949 insns = get_insns ();
4950 end_sequence ();
4951 return insns;
4954 /* SET is a SET from an insn in the epilogue. P is a pointer to the epi_info
4955 structure that contains information about what we've seen so far. We
4956 process this SET by either updating that data or by emitting one or
4957 more insns. */
4959 static void
4960 handle_epilogue_set (rtx set, struct epi_info *p)
4962 /* First handle the case where we are setting SP. Record what it is being
4963 set from, which we must be able to determine */
4964 if (reg_set_p (stack_pointer_rtx, set))
4966 gcc_assert (SET_DEST (set) == stack_pointer_rtx);
4968 if (GET_CODE (SET_SRC (set)) == PLUS)
4970 p->new_sp_equiv_reg = XEXP (SET_SRC (set), 0);
4971 if (GET_CODE (XEXP (SET_SRC (set), 1)) == CONST_INT)
4972 p->new_sp_offset = INTVAL (XEXP (SET_SRC (set), 1));
4973 else
4975 gcc_assert (REG_P (XEXP (SET_SRC (set), 1))
4976 && (REGNO (XEXP (SET_SRC (set), 1))
4977 < FIRST_PSEUDO_REGISTER)
4978 && p->const_equiv[REGNO (XEXP (SET_SRC (set), 1))]);
4979 p->new_sp_offset
4980 = INTVAL (p->const_equiv[REGNO (XEXP (SET_SRC (set), 1))]);
4983 else
4984 p->new_sp_equiv_reg = SET_SRC (set), p->new_sp_offset = 0;
4986 /* If we are adjusting SP, we adjust from the old data. */
4987 if (p->new_sp_equiv_reg == stack_pointer_rtx)
4989 p->new_sp_equiv_reg = p->sp_equiv_reg;
4990 p->new_sp_offset += p->sp_offset;
4993 gcc_assert (p->new_sp_equiv_reg && REG_P (p->new_sp_equiv_reg));
4995 return;
4998 /* Next handle the case where we are setting SP's equivalent
4999 register. We must not already have a value to set it to. We
5000 could update, but there seems little point in handling that case.
5001 Note that we have to allow for the case where we are setting the
5002 register set in the previous part of a PARALLEL inside a single
5003 insn. But use the old offset for any updates within this insn.
5004 We must allow for the case where the register is being set in a
5005 different (usually wider) mode than Pmode). */
5006 else if (p->new_sp_equiv_reg != 0 && reg_set_p (p->new_sp_equiv_reg, set))
5008 gcc_assert (!p->equiv_reg_src
5009 && REG_P (p->new_sp_equiv_reg)
5010 && REG_P (SET_DEST (set))
5011 && (GET_MODE_BITSIZE (GET_MODE (SET_DEST (set)))
5012 <= BITS_PER_WORD)
5013 && REGNO (p->new_sp_equiv_reg) == REGNO (SET_DEST (set)));
5014 p->equiv_reg_src
5015 = simplify_replace_rtx (SET_SRC (set), stack_pointer_rtx,
5016 plus_constant (p->sp_equiv_reg,
5017 p->sp_offset));
5020 /* Otherwise, replace any references to SP in the insn to its new value
5021 and emit the insn. */
5022 else
5024 SET_SRC (set) = simplify_replace_rtx (SET_SRC (set), stack_pointer_rtx,
5025 plus_constant (p->sp_equiv_reg,
5026 p->sp_offset));
5027 SET_DEST (set) = simplify_replace_rtx (SET_DEST (set), stack_pointer_rtx,
5028 plus_constant (p->sp_equiv_reg,
5029 p->sp_offset));
5030 emit_insn (set);
5034 /* Update the tracking information for registers set to constants. */
5036 static void
5037 update_epilogue_consts (rtx dest, rtx x, void *data)
5039 struct epi_info *p = (struct epi_info *) data;
5040 rtx new;
5042 if (!REG_P (dest) || REGNO (dest) >= FIRST_PSEUDO_REGISTER)
5043 return;
5045 /* If we are either clobbering a register or doing a partial set,
5046 show we don't know the value. */
5047 else if (GET_CODE (x) == CLOBBER || ! rtx_equal_p (dest, SET_DEST (x)))
5048 p->const_equiv[REGNO (dest)] = 0;
5050 /* If we are setting it to a constant, record that constant. */
5051 else if (GET_CODE (SET_SRC (x)) == CONST_INT)
5052 p->const_equiv[REGNO (dest)] = SET_SRC (x);
5054 /* If this is a binary operation between a register we have been tracking
5055 and a constant, see if we can compute a new constant value. */
5056 else if (ARITHMETIC_P (SET_SRC (x))
5057 && REG_P (XEXP (SET_SRC (x), 0))
5058 && REGNO (XEXP (SET_SRC (x), 0)) < FIRST_PSEUDO_REGISTER
5059 && p->const_equiv[REGNO (XEXP (SET_SRC (x), 0))] != 0
5060 && GET_CODE (XEXP (SET_SRC (x), 1)) == CONST_INT
5061 && 0 != (new = simplify_binary_operation
5062 (GET_CODE (SET_SRC (x)), GET_MODE (dest),
5063 p->const_equiv[REGNO (XEXP (SET_SRC (x), 0))],
5064 XEXP (SET_SRC (x), 1)))
5065 && GET_CODE (new) == CONST_INT)
5066 p->const_equiv[REGNO (dest)] = new;
5068 /* Otherwise, we can't do anything with this value. */
5069 else
5070 p->const_equiv[REGNO (dest)] = 0;
5073 /* Emit an insn to do the load shown in p->equiv_reg_src, if needed. */
5075 static void
5076 emit_equiv_load (struct epi_info *p)
5078 if (p->equiv_reg_src != 0)
5080 rtx dest = p->sp_equiv_reg;
5082 if (GET_MODE (p->equiv_reg_src) != GET_MODE (dest))
5083 dest = gen_rtx_REG (GET_MODE (p->equiv_reg_src),
5084 REGNO (p->sp_equiv_reg));
5086 emit_move_insn (dest, p->equiv_reg_src);
5087 p->equiv_reg_src = 0;
5090 #endif
5092 /* Generate the prologue and epilogue RTL if the machine supports it. Thread
5093 this into place with notes indicating where the prologue ends and where
5094 the epilogue begins. Update the basic block information when possible. */
5096 void
5097 thread_prologue_and_epilogue_insns (rtx f ATTRIBUTE_UNUSED)
5099 int inserted = 0;
5100 edge e;
5101 #if defined (HAVE_sibcall_epilogue) || defined (HAVE_epilogue) || defined (HAVE_return) || defined (HAVE_prologue)
5102 rtx seq;
5103 #endif
5104 #ifdef HAVE_prologue
5105 rtx prologue_end = NULL_RTX;
5106 #endif
5107 #if defined (HAVE_epilogue) || defined(HAVE_return)
5108 rtx epilogue_end = NULL_RTX;
5109 #endif
5110 edge_iterator ei;
5112 #ifdef HAVE_prologue
5113 if (HAVE_prologue)
5115 start_sequence ();
5116 seq = gen_prologue ();
5117 emit_insn (seq);
5119 /* Retain a map of the prologue insns. */
5120 record_insns (seq, &prologue);
5121 prologue_end = emit_note (NOTE_INSN_PROLOGUE_END);
5123 seq = get_insns ();
5124 end_sequence ();
5125 set_insn_locators (seq, prologue_locator);
5127 /* Can't deal with multiple successors of the entry block
5128 at the moment. Function should always have at least one
5129 entry point. */
5130 gcc_assert (single_succ_p (ENTRY_BLOCK_PTR));
5132 insert_insn_on_edge (seq, single_succ_edge (ENTRY_BLOCK_PTR));
5133 inserted = 1;
5135 #endif
5137 /* If the exit block has no non-fake predecessors, we don't need
5138 an epilogue. */
5139 FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds)
5140 if ((e->flags & EDGE_FAKE) == 0)
5141 break;
5142 if (e == NULL)
5143 goto epilogue_done;
5145 #ifdef HAVE_return
5146 if (optimize && HAVE_return)
5148 /* If we're allowed to generate a simple return instruction,
5149 then by definition we don't need a full epilogue. Examine
5150 the block that falls through to EXIT. If it does not
5151 contain any code, examine its predecessors and try to
5152 emit (conditional) return instructions. */
5154 basic_block last;
5155 rtx label;
5157 FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds)
5158 if (e->flags & EDGE_FALLTHRU)
5159 break;
5160 if (e == NULL)
5161 goto epilogue_done;
5162 last = e->src;
5164 /* Verify that there are no active instructions in the last block. */
5165 label = BB_END (last);
5166 while (label && !LABEL_P (label))
5168 if (active_insn_p (label))
5169 break;
5170 label = PREV_INSN (label);
5173 if (BB_HEAD (last) == label && LABEL_P (label))
5175 edge_iterator ei2;
5176 rtx epilogue_line_note = NULL_RTX;
5178 /* Locate the line number associated with the closing brace,
5179 if we can find one. */
5180 for (seq = get_last_insn ();
5181 seq && ! active_insn_p (seq);
5182 seq = PREV_INSN (seq))
5183 if (NOTE_P (seq) && NOTE_LINE_NUMBER (seq) > 0)
5185 epilogue_line_note = seq;
5186 break;
5189 for (ei2 = ei_start (last->preds); (e = ei_safe_edge (ei2)); )
5191 basic_block bb = e->src;
5192 rtx jump;
5194 if (bb == ENTRY_BLOCK_PTR)
5196 ei_next (&ei2);
5197 continue;
5200 jump = BB_END (bb);
5201 if (!JUMP_P (jump) || JUMP_LABEL (jump) != label)
5203 ei_next (&ei2);
5204 continue;
5207 /* If we have an unconditional jump, we can replace that
5208 with a simple return instruction. */
5209 if (simplejump_p (jump))
5211 emit_return_into_block (bb, epilogue_line_note);
5212 delete_insn (jump);
5215 /* If we have a conditional jump, we can try to replace
5216 that with a conditional return instruction. */
5217 else if (condjump_p (jump))
5219 if (! redirect_jump (jump, 0, 0))
5221 ei_next (&ei2);
5222 continue;
5225 /* If this block has only one successor, it both jumps
5226 and falls through to the fallthru block, so we can't
5227 delete the edge. */
5228 if (single_succ_p (bb))
5230 ei_next (&ei2);
5231 continue;
5234 else
5236 ei_next (&ei2);
5237 continue;
5240 /* Fix up the CFG for the successful change we just made. */
5241 redirect_edge_succ (e, EXIT_BLOCK_PTR);
5244 /* Emit a return insn for the exit fallthru block. Whether
5245 this is still reachable will be determined later. */
5247 emit_barrier_after (BB_END (last));
5248 emit_return_into_block (last, epilogue_line_note);
5249 epilogue_end = BB_END (last);
5250 single_succ_edge (last)->flags &= ~EDGE_FALLTHRU;
5251 goto epilogue_done;
5254 #endif
5255 /* Find the edge that falls through to EXIT. Other edges may exist
5256 due to RETURN instructions, but those don't need epilogues.
5257 There really shouldn't be a mixture -- either all should have
5258 been converted or none, however... */
5260 FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds)
5261 if (e->flags & EDGE_FALLTHRU)
5262 break;
5263 if (e == NULL)
5264 goto epilogue_done;
5266 #ifdef HAVE_epilogue
5267 if (HAVE_epilogue)
5269 start_sequence ();
5270 epilogue_end = emit_note (NOTE_INSN_EPILOGUE_BEG);
5272 seq = gen_epilogue ();
5274 #ifdef INCOMING_RETURN_ADDR_RTX
5275 /* If this function returns with the stack depressed and we can support
5276 it, massage the epilogue to actually do that. */
5277 if (TREE_CODE (TREE_TYPE (current_function_decl)) == FUNCTION_TYPE
5278 && TYPE_RETURNS_STACK_DEPRESSED (TREE_TYPE (current_function_decl)))
5279 seq = keep_stack_depressed (seq);
5280 #endif
5282 emit_jump_insn (seq);
5284 /* Retain a map of the epilogue insns. */
5285 record_insns (seq, &epilogue);
5286 set_insn_locators (seq, epilogue_locator);
5288 seq = get_insns ();
5289 end_sequence ();
5291 insert_insn_on_edge (seq, e);
5292 inserted = 1;
5294 else
5295 #endif
5297 basic_block cur_bb;
5299 if (! next_active_insn (BB_END (e->src)))
5300 goto epilogue_done;
5301 /* We have a fall-through edge to the exit block, the source is not
5302 at the end of the function, and there will be an assembler epilogue
5303 at the end of the function.
5304 We can't use force_nonfallthru here, because that would try to
5305 use return. Inserting a jump 'by hand' is extremely messy, so
5306 we take advantage of cfg_layout_finalize using
5307 fixup_fallthru_exit_predecessor. */
5308 cfg_layout_initialize (0);
5309 FOR_EACH_BB (cur_bb)
5310 if (cur_bb->index >= NUM_FIXED_BLOCKS
5311 && cur_bb->next_bb->index >= NUM_FIXED_BLOCKS)
5312 cur_bb->aux = cur_bb->next_bb;
5313 cfg_layout_finalize ();
5315 epilogue_done:
5317 if (inserted)
5318 commit_edge_insertions ();
5320 #ifdef HAVE_sibcall_epilogue
5321 /* Emit sibling epilogues before any sibling call sites. */
5322 for (ei = ei_start (EXIT_BLOCK_PTR->preds); (e = ei_safe_edge (ei)); )
5324 basic_block bb = e->src;
5325 rtx insn = BB_END (bb);
5327 if (!CALL_P (insn)
5328 || ! SIBLING_CALL_P (insn))
5330 ei_next (&ei);
5331 continue;
5334 start_sequence ();
5335 emit_insn (gen_sibcall_epilogue ());
5336 seq = get_insns ();
5337 end_sequence ();
5339 /* Retain a map of the epilogue insns. Used in life analysis to
5340 avoid getting rid of sibcall epilogue insns. Do this before we
5341 actually emit the sequence. */
5342 record_insns (seq, &sibcall_epilogue);
5343 set_insn_locators (seq, epilogue_locator);
5345 emit_insn_before (seq, insn);
5346 ei_next (&ei);
5348 #endif
5350 #ifdef HAVE_prologue
5351 /* This is probably all useless now that we use locators. */
5352 if (prologue_end)
5354 rtx insn, prev;
5356 /* GDB handles `break f' by setting a breakpoint on the first
5357 line note after the prologue. Which means (1) that if
5358 there are line number notes before where we inserted the
5359 prologue we should move them, and (2) we should generate a
5360 note before the end of the first basic block, if there isn't
5361 one already there.
5363 ??? This behavior is completely broken when dealing with
5364 multiple entry functions. We simply place the note always
5365 into first basic block and let alternate entry points
5366 to be missed.
5369 for (insn = prologue_end; insn; insn = prev)
5371 prev = PREV_INSN (insn);
5372 if (NOTE_P (insn) && NOTE_LINE_NUMBER (insn) > 0)
5374 /* Note that we cannot reorder the first insn in the
5375 chain, since rest_of_compilation relies on that
5376 remaining constant. */
5377 if (prev == NULL)
5378 break;
5379 reorder_insns (insn, insn, prologue_end);
5383 /* Find the last line number note in the first block. */
5384 for (insn = BB_END (ENTRY_BLOCK_PTR->next_bb);
5385 insn != prologue_end && insn;
5386 insn = PREV_INSN (insn))
5387 if (NOTE_P (insn) && NOTE_LINE_NUMBER (insn) > 0)
5388 break;
5390 /* If we didn't find one, make a copy of the first line number
5391 we run across. */
5392 if (! insn)
5394 for (insn = next_active_insn (prologue_end);
5395 insn;
5396 insn = PREV_INSN (insn))
5397 if (NOTE_P (insn) && NOTE_LINE_NUMBER (insn) > 0)
5399 emit_note_copy_after (insn, prologue_end);
5400 break;
5404 #endif
5405 #ifdef HAVE_epilogue
5406 if (epilogue_end)
5408 rtx insn, next;
5410 /* Similarly, move any line notes that appear after the epilogue.
5411 There is no need, however, to be quite so anal about the existence
5412 of such a note. Also move the NOTE_INSN_FUNCTION_END and (possibly)
5413 NOTE_INSN_FUNCTION_BEG notes, as those can be relevant for debug
5414 info generation. */
5415 for (insn = epilogue_end; insn; insn = next)
5417 next = NEXT_INSN (insn);
5418 if (NOTE_P (insn)
5419 && (NOTE_LINE_NUMBER (insn) > 0
5420 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG
5421 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_END))
5422 reorder_insns (insn, insn, PREV_INSN (epilogue_end));
5425 #endif
5428 /* Reposition the prologue-end and epilogue-begin notes after instruction
5429 scheduling and delayed branch scheduling. */
5431 void
5432 reposition_prologue_and_epilogue_notes (rtx f ATTRIBUTE_UNUSED)
5434 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
5435 rtx insn, last, note;
5436 int len;
5438 if ((len = VEC_length (int, prologue)) > 0)
5440 last = 0, note = 0;
5442 /* Scan from the beginning until we reach the last prologue insn.
5443 We apparently can't depend on basic_block_{head,end} after
5444 reorg has run. */
5445 for (insn = f; insn; insn = NEXT_INSN (insn))
5447 if (NOTE_P (insn))
5449 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
5450 note = insn;
5452 else if (contains (insn, &prologue))
5454 last = insn;
5455 if (--len == 0)
5456 break;
5460 if (last)
5462 /* Find the prologue-end note if we haven't already, and
5463 move it to just after the last prologue insn. */
5464 if (note == 0)
5466 for (note = last; (note = NEXT_INSN (note));)
5467 if (NOTE_P (note)
5468 && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
5469 break;
5472 /* Avoid placing note between CODE_LABEL and BASIC_BLOCK note. */
5473 if (LABEL_P (last))
5474 last = NEXT_INSN (last);
5475 reorder_insns (note, note, last);
5479 if ((len = VEC_length (int, epilogue)) > 0)
5481 last = 0, note = 0;
5483 /* Scan from the end until we reach the first epilogue insn.
5484 We apparently can't depend on basic_block_{head,end} after
5485 reorg has run. */
5486 for (insn = get_last_insn (); insn; insn = PREV_INSN (insn))
5488 if (NOTE_P (insn))
5490 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
5491 note = insn;
5493 else if (contains (insn, &epilogue))
5495 last = insn;
5496 if (--len == 0)
5497 break;
5501 if (last)
5503 /* Find the epilogue-begin note if we haven't already, and
5504 move it to just before the first epilogue insn. */
5505 if (note == 0)
5507 for (note = insn; (note = PREV_INSN (note));)
5508 if (NOTE_P (note)
5509 && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
5510 break;
5513 if (PREV_INSN (last) != note)
5514 reorder_insns (note, note, PREV_INSN (last));
5517 #endif /* HAVE_prologue or HAVE_epilogue */
5520 /* Resets insn_block_boundaries array. */
5522 void
5523 reset_block_changes (void)
5525 cfun->ib_boundaries_block = VEC_alloc (tree, gc, 100);
5526 VEC_quick_push (tree, cfun->ib_boundaries_block, NULL_TREE);
5529 /* Record the boundary for BLOCK. */
5530 void
5531 record_block_change (tree block)
5533 int i, n;
5534 tree last_block;
5536 if (!block)
5537 return;
5539 if(!cfun->ib_boundaries_block)
5540 return;
5542 last_block = VEC_pop (tree, cfun->ib_boundaries_block);
5543 n = get_max_uid ();
5544 for (i = VEC_length (tree, cfun->ib_boundaries_block); i < n; i++)
5545 VEC_safe_push (tree, gc, cfun->ib_boundaries_block, last_block);
5547 VEC_safe_push (tree, gc, cfun->ib_boundaries_block, block);
5550 /* Finishes record of boundaries. */
5551 void finalize_block_changes (void)
5553 record_block_change (DECL_INITIAL (current_function_decl));
5556 /* For INSN return the BLOCK it belongs to. */
5557 void
5558 check_block_change (rtx insn, tree *block)
5560 unsigned uid = INSN_UID (insn);
5562 if (uid >= VEC_length (tree, cfun->ib_boundaries_block))
5563 return;
5565 *block = VEC_index (tree, cfun->ib_boundaries_block, uid);
5568 /* Releases the ib_boundaries_block records. */
5569 void
5570 free_block_changes (void)
5572 VEC_free (tree, gc, cfun->ib_boundaries_block);
5575 /* Returns the name of the current function. */
5576 const char *
5577 current_function_name (void)
5579 return lang_hooks.decl_printable_name (cfun->decl, 2);
5583 static unsigned int
5584 rest_of_handle_check_leaf_regs (void)
5586 #ifdef LEAF_REGISTERS
5587 current_function_uses_only_leaf_regs
5588 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
5589 #endif
5590 return 0;
5593 /* Insert a TYPE into the used types hash table of CFUN. */
5594 static void
5595 used_types_insert_helper (tree type, struct function *func)
5597 if (type != NULL && func != NULL)
5599 void **slot;
5601 if (func->used_types_hash == NULL)
5602 func->used_types_hash = htab_create_ggc (37, htab_hash_pointer,
5603 htab_eq_pointer, NULL);
5604 slot = htab_find_slot (func->used_types_hash, type, INSERT);
5605 if (*slot == NULL)
5606 *slot = type;
5610 /* Given a type, insert it into the used hash table in cfun. */
5611 void
5612 used_types_insert (tree t)
5614 while (POINTER_TYPE_P (t) || TREE_CODE (t) == ARRAY_TYPE)
5615 t = TREE_TYPE (t);
5616 t = TYPE_MAIN_VARIANT (t);
5617 if (debug_info_level > DINFO_LEVEL_NONE)
5618 used_types_insert_helper (t, cfun);
5621 struct tree_opt_pass pass_leaf_regs =
5623 NULL, /* name */
5624 NULL, /* gate */
5625 rest_of_handle_check_leaf_regs, /* execute */
5626 NULL, /* sub */
5627 NULL, /* next */
5628 0, /* static_pass_number */
5629 0, /* tv_id */
5630 0, /* properties_required */
5631 0, /* properties_provided */
5632 0, /* properties_destroyed */
5633 0, /* todo_flags_start */
5634 0, /* todo_flags_finish */
5635 0 /* letter */
5639 #include "gt-function.h"