1 /* Expands front end tree to back end RTL for GNU C-Compiler
2 Copyright (C) 1987, 88, 89, 91-98, 1999 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* This file handles the generation of rtl code from tree structure
23 at the level of the function as a whole.
24 It creates the rtl expressions for parameters and auto variables
25 and has full responsibility for allocating stack slots.
27 `expand_function_start' is called at the beginning of a function,
28 before the function body is parsed, and `expand_function_end' is
29 called after parsing the body.
31 Call `assign_stack_local' to allocate a stack slot for a local variable.
32 This is usually done during the RTL generation for the function body,
33 but it can also be done in the reload pass when a pseudo-register does
34 not get a hard register.
36 Call `put_var_into_stack' when you learn, belatedly, that a variable
37 previously given a pseudo-register must in fact go in the stack.
38 This function changes the DECL_RTL to be a stack slot instead of a reg
39 then scans all the RTL instructions so far generated to correct them. */
48 #include "insn-flags.h"
50 #include "insn-codes.h"
52 #include "hard-reg-set.h"
53 #include "insn-config.h"
56 #include "basic-block.h"
62 #ifndef TRAMPOLINE_ALIGNMENT
63 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
66 #ifndef LOCAL_ALIGNMENT
67 #define LOCAL_ALIGNMENT(TYPE, ALIGNMENT) ALIGNMENT
70 /* Some systems use __main in a way incompatible with its use in gcc, in these
71 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
72 give the same symbol without quotes for an alternative entry point. You
73 must define both, or neither. */
75 #define NAME__MAIN "__main"
76 #define SYMBOL__MAIN __main
79 /* Round a value to the lowest integer less than it that is a multiple of
80 the required alignment. Avoid using division in case the value is
81 negative. Assume the alignment is a power of two. */
82 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
84 /* Similar, but round to the next highest integer that meets the
86 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
88 /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp
89 during rtl generation. If they are different register numbers, this is
90 always true. It may also be true if
91 FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl
92 generation. See fix_lexical_addr for details. */
94 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
95 #define NEED_SEPARATE_AP
98 /* Nonzero if function being compiled doesn't contain any calls
99 (ignoring the prologue and epilogue). This is set prior to
100 local register allocation and is valid for the remaining
102 int current_function_is_leaf;
104 /* Nonzero if function being compiled doesn't modify the stack pointer
105 (ignoring the prologue and epilogue). This is only valid after
106 life_analysis has run. */
107 int current_function_sp_is_unchanging;
109 /* Nonzero if the function being compiled is a leaf function which only
110 uses leaf registers. This is valid after reload (specifically after
111 sched2) and is useful only if the port defines LEAF_REGISTERS. */
112 int current_function_uses_only_leaf_regs;
114 /* Nonzero once virtual register instantiation has been done.
115 assign_stack_local uses frame_pointer_rtx when this is nonzero. */
116 static int virtuals_instantiated;
118 /* These variables hold pointers to functions to
119 save and restore machine-specific data,
120 in push_function_context and pop_function_context. */
121 void (*init_machine_status) PROTO((struct function *));
122 void (*save_machine_status) PROTO((struct function *));
123 void (*restore_machine_status) PROTO((struct function *));
124 void (*mark_machine_status) PROTO((struct function *));
126 /* Likewise, but for language-specific data. */
127 void (*save_lang_status) PROTO((struct function *));
128 void (*restore_lang_status) PROTO((struct function *));
129 void (*mark_lang_status) PROTO((struct function *));
131 /* The FUNCTION_DECL for an inline function currently being expanded. */
132 tree inline_function_decl;
134 /* The currently compiled function. */
135 struct function *current_function = 0;
137 /* Global list of all compiled functions. */
138 struct function *all_functions = 0;
140 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
141 static int *prologue;
142 static int *epilogue;
144 /* In order to evaluate some expressions, such as function calls returning
145 structures in memory, we need to temporarily allocate stack locations.
146 We record each allocated temporary in the following structure.
148 Associated with each temporary slot is a nesting level. When we pop up
149 one level, all temporaries associated with the previous level are freed.
150 Normally, all temporaries are freed after the execution of the statement
151 in which they were created. However, if we are inside a ({...}) grouping,
152 the result may be in a temporary and hence must be preserved. If the
153 result could be in a temporary, we preserve it if we can determine which
154 one it is in. If we cannot determine which temporary may contain the
155 result, all temporaries are preserved. A temporary is preserved by
156 pretending it was allocated at the previous nesting level.
158 Automatic variables are also assigned temporary slots, at the nesting
159 level where they are defined. They are marked a "kept" so that
160 free_temp_slots will not free them. */
164 /* Points to next temporary slot. */
165 struct temp_slot *next;
166 /* The rtx to used to reference the slot. */
168 /* The rtx used to represent the address if not the address of the
169 slot above. May be an EXPR_LIST if multiple addresses exist. */
171 /* The alignment (in bits) of the slot. */
173 /* The size, in units, of the slot. */
175 /* The alias set for the slot. If the alias set is zero, we don't
176 know anything about the alias set of the slot. We must only
177 reuse a slot if it is assigned an object of the same alias set.
178 Otherwise, the rest of the compiler may assume that the new use
179 of the slot cannot alias the old use of the slot, which is
180 false. If the slot has alias set zero, then we can't reuse the
181 slot at all, since we have no idea what alias set may have been
182 imposed on the memory. For example, if the stack slot is the
183 call frame for an inline functioned, we have no idea what alias
184 sets will be assigned to various pieces of the call frame. */
186 /* The value of `sequence_rtl_expr' when this temporary is allocated. */
188 /* Non-zero if this temporary is currently in use. */
190 /* Non-zero if this temporary has its address taken. */
192 /* Nesting level at which this slot is being used. */
194 /* Non-zero if this should survive a call to free_temp_slots. */
196 /* The offset of the slot from the frame_pointer, including extra space
197 for alignment. This info is for combine_temp_slots. */
198 HOST_WIDE_INT base_offset;
199 /* The size of the slot, including extra space for alignment. This
200 info is for combine_temp_slots. */
201 HOST_WIDE_INT full_size;
204 /* This structure is used to record MEMs or pseudos used to replace VAR, any
205 SUBREGs of VAR, and any MEMs containing VAR as an address. We need to
206 maintain this list in case two operands of an insn were required to match;
207 in that case we must ensure we use the same replacement. */
209 struct fixup_replacement
213 struct fixup_replacement *next;
216 struct insns_for_mem_entry {
217 /* The KEY in HE will be a MEM. */
218 struct hash_entry he;
219 /* These are the INSNS which reference the MEM. */
223 /* Forward declarations. */
225 static rtx assign_stack_local_1 PROTO ((enum machine_mode, HOST_WIDE_INT,
226 int, struct function *));
227 static rtx assign_stack_temp_for_type PROTO ((enum machine_mode, HOST_WIDE_INT,
229 static struct temp_slot *find_temp_slot_from_address PROTO((rtx));
230 static void put_reg_into_stack PROTO((struct function *, rtx, tree,
231 enum machine_mode, enum machine_mode,
233 struct hash_table *));
234 static void fixup_var_refs PROTO((rtx, enum machine_mode, int,
235 struct hash_table *));
236 static struct fixup_replacement
237 *find_fixup_replacement PROTO((struct fixup_replacement **, rtx));
238 static void fixup_var_refs_insns PROTO((rtx, enum machine_mode, int,
239 rtx, int, struct hash_table *));
240 static void fixup_var_refs_1 PROTO((rtx, enum machine_mode, rtx *, rtx,
241 struct fixup_replacement **));
242 static rtx fixup_memory_subreg PROTO((rtx, rtx, int));
243 static rtx walk_fixup_memory_subreg PROTO((rtx, rtx, int));
244 static rtx fixup_stack_1 PROTO((rtx, rtx));
245 static void optimize_bit_field PROTO((rtx, rtx, rtx *));
246 static void instantiate_decls PROTO((tree, int));
247 static void instantiate_decls_1 PROTO((tree, int));
248 static void instantiate_decl PROTO((rtx, int, int));
249 static int instantiate_virtual_regs_1 PROTO((rtx *, rtx, int));
250 static void delete_handlers PROTO((void));
251 static void pad_to_arg_alignment PROTO((struct args_size *, int));
252 #ifndef ARGS_GROW_DOWNWARD
253 static void pad_below PROTO((struct args_size *, enum machine_mode,
256 #ifdef ARGS_GROW_DOWNWARD
257 static tree round_down PROTO((tree, int));
259 static rtx round_trampoline_addr PROTO((rtx));
260 static tree blocks_nreverse PROTO((tree));
261 static int all_blocks PROTO((tree, tree *));
262 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
263 static int *record_insns PROTO((rtx));
264 static int contains PROTO((rtx, int *));
265 #endif /* HAVE_prologue || HAVE_epilogue */
266 static void put_addressof_into_stack PROTO((rtx, struct hash_table *));
267 static void purge_addressof_1 PROTO((rtx *, rtx, int, int,
268 struct hash_table *));
269 static struct hash_entry *insns_for_mem_newfunc PROTO((struct hash_entry *,
272 static unsigned long insns_for_mem_hash PROTO ((hash_table_key));
273 static boolean insns_for_mem_comp PROTO ((hash_table_key, hash_table_key));
274 static int insns_for_mem_walk PROTO ((rtx *, void *));
275 static void compute_insns_for_mem PROTO ((rtx, rtx, struct hash_table *));
276 static void mark_temp_slot PROTO ((struct temp_slot *));
277 static void mark_function_state PROTO ((struct function *));
278 static void mark_function_chain PROTO ((void *));
281 /* Pointer to chain of `struct function' for containing functions. */
282 struct function *outer_function_chain;
284 /* Given a function decl for a containing function,
285 return the `struct function' for it. */
288 find_function_data (decl)
293 for (p = outer_function_chain; p; p = p->next)
300 /* Save the current context for compilation of a nested function.
301 This is called from language-specific code. The caller should use
302 the save_lang_status callback to save any language-specific state,
303 since this function knows only about language-independent
307 push_function_context_to (context)
310 struct function *p, *context_data;
314 context_data = (context == current_function_decl
316 : find_function_data (context));
317 context_data->contains_functions = 1;
320 if (current_function == 0)
321 init_dummy_function_start ();
322 p = current_function;
324 p->next = outer_function_chain;
325 outer_function_chain = p;
326 p->decl = current_function_decl;
327 p->fixup_var_refs_queue = 0;
329 save_tree_status (p);
330 if (save_lang_status)
331 (*save_lang_status) (p);
332 if (save_machine_status)
333 (*save_machine_status) (p);
335 current_function = 0;
339 push_function_context ()
341 push_function_context_to (current_function_decl);
344 /* Restore the last saved context, at the end of a nested function.
345 This function is called from language-specific code. */
348 pop_function_context_from (context)
351 struct function *p = outer_function_chain;
352 struct var_refs_queue *queue;
353 struct var_refs_queue *next;
355 current_function = p;
356 outer_function_chain = p->next;
358 current_function_decl = p->decl;
361 restore_tree_status (p);
362 restore_emit_status (p);
364 if (restore_machine_status)
365 (*restore_machine_status) (p);
366 if (restore_lang_status)
367 (*restore_lang_status) (p);
369 /* Finish doing put_var_into_stack for any of our variables
370 which became addressable during the nested function. */
371 for (queue = p->fixup_var_refs_queue; queue; queue = next)
374 fixup_var_refs (queue->modified, queue->promoted_mode,
375 queue->unsignedp, 0);
378 p->fixup_var_refs_queue = 0;
380 /* Reset variables that have known state during rtx generation. */
381 rtx_equal_function_value_matters = 1;
382 virtuals_instantiated = 0;
386 pop_function_context ()
388 pop_function_context_from (current_function_decl);
391 /* Clear out all parts of the state in F that can safely be discarded
392 after the function has been compiled, to let garbage collection
393 reclaim the memory. D is the declaration for the function just
394 compiled. Its output may have been deferred. */
397 free_after_compilation (f, d)
401 free_emit_status (f, d);
402 free_varasm_status (f, d);
403 free_stmt_status (f, d);
405 if (!DECL_DEFER_OUTPUT (d))
407 free (f->x_parm_reg_stack_loc);
408 f->can_garbage_collect = 1;
412 /* Allocate fixed slots in the stack frame of the current function. */
414 /* Return size needed for stack frame based on slots so far allocated in
416 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
417 the caller may have to do that. */
420 get_func_frame_size (f)
423 #ifdef FRAME_GROWS_DOWNWARD
424 return -f->x_frame_offset;
426 return f->x_frame_offset;
430 /* Return size needed for stack frame based on slots so far allocated.
431 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
432 the caller may have to do that. */
436 return get_func_frame_size (current_function);
439 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
440 with machine mode MODE.
442 ALIGN controls the amount of alignment for the address of the slot:
443 0 means according to MODE,
444 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
445 positive specifies alignment boundary in bits.
447 We do not round to stack_boundary here.
449 FUNCTION specifies the function to allocate in. */
452 assign_stack_local_1 (mode, size, align, function)
453 enum machine_mode mode;
456 struct function *function;
458 register rtx x, addr;
459 int bigend_correction = 0;
462 /* Allocate in the memory associated with the function in whose frame
464 if (function != current_function)
465 push_obstacks (function->function_obstack,
466 function->function_maybepermanent_obstack);
472 alignment = GET_MODE_ALIGNMENT (mode);
474 alignment = BIGGEST_ALIGNMENT;
476 /* Allow the target to (possibly) increase the alignment of this
478 type = type_for_mode (mode, 0);
480 alignment = LOCAL_ALIGNMENT (type, alignment);
482 alignment /= BITS_PER_UNIT;
484 else if (align == -1)
486 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
487 size = CEIL_ROUND (size, alignment);
490 alignment = align / BITS_PER_UNIT;
492 #ifdef FRAME_GROWS_DOWNWARD
493 function->x_frame_offset -= size;
496 /* Round frame offset to that alignment.
497 We must be careful here, since FRAME_OFFSET might be negative and
498 division with a negative dividend isn't as well defined as we might
499 like. So we instead assume that ALIGNMENT is a power of two and
500 use logical operations which are unambiguous. */
501 #ifdef FRAME_GROWS_DOWNWARD
502 function->x_frame_offset = FLOOR_ROUND (function->x_frame_offset, alignment);
504 function->x_frame_offset = CEIL_ROUND (function->x_frame_offset, alignment);
507 /* On a big-endian machine, if we are allocating more space than we will use,
508 use the least significant bytes of those that are allocated. */
509 if (BYTES_BIG_ENDIAN && mode != BLKmode)
510 bigend_correction = size - GET_MODE_SIZE (mode);
512 /* If we have already instantiated virtual registers, return the actual
513 address relative to the frame pointer. */
514 if (function == current_function && virtuals_instantiated)
515 addr = plus_constant (frame_pointer_rtx,
516 (frame_offset + bigend_correction
517 + STARTING_FRAME_OFFSET));
519 addr = plus_constant (virtual_stack_vars_rtx,
520 frame_offset + bigend_correction);
522 #ifndef FRAME_GROWS_DOWNWARD
523 function->x_frame_offset += size;
526 x = gen_rtx_MEM (mode, addr);
528 function->x_stack_slot_list
529 = gen_rtx_EXPR_LIST (VOIDmode, x, function->x_stack_slot_list);
531 if (function != current_function)
537 /* Wrapper around assign_stack_local_1; assign a local stack slot for the
540 assign_stack_local (mode, size, align)
541 enum machine_mode mode;
545 return assign_stack_local_1 (mode, size, align, current_function);
548 /* Allocate a temporary stack slot and record it for possible later
551 MODE is the machine mode to be given to the returned rtx.
553 SIZE is the size in units of the space required. We do no rounding here
554 since assign_stack_local will do any required rounding.
556 KEEP is 1 if this slot is to be retained after a call to
557 free_temp_slots. Automatic variables for a block are allocated
558 with this flag. KEEP is 2 if we allocate a longer term temporary,
559 whose lifetime is controlled by CLEANUP_POINT_EXPRs. KEEP is 3
560 if we are to allocate something at an inner level to be treated as
561 a variable in the block (e.g., a SAVE_EXPR).
563 TYPE is the type that will be used for the stack slot. */
566 assign_stack_temp_for_type (mode, size, keep, type)
567 enum machine_mode mode;
574 struct temp_slot *p, *best_p = 0;
576 /* If SIZE is -1 it means that somebody tried to allocate a temporary
577 of a variable size. */
581 /* If we know the alias set for the memory that will be used, use
582 it. If there's no TYPE, then we don't know anything about the
583 alias set for the memory. */
585 alias_set = get_alias_set (type);
589 align = GET_MODE_ALIGNMENT (mode);
591 align = BIGGEST_ALIGNMENT;
594 type = type_for_mode (mode, 0);
596 align = LOCAL_ALIGNMENT (type, align);
598 /* Try to find an available, already-allocated temporary of the proper
599 mode which meets the size and alignment requirements. Choose the
600 smallest one with the closest alignment. */
601 for (p = temp_slots; p; p = p->next)
602 if (p->align >= align && p->size >= size && GET_MODE (p->slot) == mode
604 && (!flag_strict_aliasing
605 || (alias_set && p->alias_set == alias_set))
606 && (best_p == 0 || best_p->size > p->size
607 || (best_p->size == p->size && best_p->align > p->align)))
609 if (p->align == align && p->size == size)
617 /* Make our best, if any, the one to use. */
620 /* If there are enough aligned bytes left over, make them into a new
621 temp_slot so that the extra bytes don't get wasted. Do this only
622 for BLKmode slots, so that we can be sure of the alignment. */
623 if (GET_MODE (best_p->slot) == BLKmode
624 /* We can't split slots if -fstrict-aliasing because the
625 information about the alias set for the new slot will be
627 && !flag_strict_aliasing)
629 int alignment = best_p->align / BITS_PER_UNIT;
630 HOST_WIDE_INT rounded_size = CEIL_ROUND (size, alignment);
632 if (best_p->size - rounded_size >= alignment)
634 p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
635 p->in_use = p->addr_taken = 0;
636 p->size = best_p->size - rounded_size;
637 p->base_offset = best_p->base_offset + rounded_size;
638 p->full_size = best_p->full_size - rounded_size;
639 p->slot = gen_rtx_MEM (BLKmode,
640 plus_constant (XEXP (best_p->slot, 0),
642 p->align = best_p->align;
645 p->next = temp_slots;
648 stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, p->slot,
651 best_p->size = rounded_size;
652 best_p->full_size = rounded_size;
659 /* If we still didn't find one, make a new temporary. */
662 HOST_WIDE_INT frame_offset_old = frame_offset;
664 p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
666 /* We are passing an explicit alignment request to assign_stack_local.
667 One side effect of that is assign_stack_local will not round SIZE
668 to ensure the frame offset remains suitably aligned.
670 So for requests which depended on the rounding of SIZE, we go ahead
671 and round it now. We also make sure ALIGNMENT is at least
672 BIGGEST_ALIGNMENT. */
673 if (mode == BLKmode && align < BIGGEST_ALIGNMENT)
675 p->slot = assign_stack_local (mode,
677 ? CEIL_ROUND (size, align / BITS_PER_UNIT)
682 p->alias_set = alias_set;
684 /* The following slot size computation is necessary because we don't
685 know the actual size of the temporary slot until assign_stack_local
686 has performed all the frame alignment and size rounding for the
687 requested temporary. Note that extra space added for alignment
688 can be either above or below this stack slot depending on which
689 way the frame grows. We include the extra space if and only if it
690 is above this slot. */
691 #ifdef FRAME_GROWS_DOWNWARD
692 p->size = frame_offset_old - frame_offset;
697 /* Now define the fields used by combine_temp_slots. */
698 #ifdef FRAME_GROWS_DOWNWARD
699 p->base_offset = frame_offset;
700 p->full_size = frame_offset_old - frame_offset;
702 p->base_offset = frame_offset_old;
703 p->full_size = frame_offset - frame_offset_old;
706 p->next = temp_slots;
712 p->rtl_expr = seq_rtl_expr;
716 p->level = target_temp_slot_level;
721 p->level = var_temp_slot_level;
726 p->level = temp_slot_level;
730 /* We may be reusing an old slot, so clear any MEM flags that may have been
732 RTX_UNCHANGING_P (p->slot) = 0;
733 MEM_IN_STRUCT_P (p->slot) = 0;
734 MEM_SCALAR_P (p->slot) = 0;
735 MEM_ALIAS_SET (p->slot) = 0;
739 /* Allocate a temporary stack slot and record it for possible later
740 reuse. First three arguments are same as in preceding function. */
743 assign_stack_temp (mode, size, keep)
744 enum machine_mode mode;
748 return assign_stack_temp_for_type (mode, size, keep, NULL_TREE);
751 /* Assign a temporary of given TYPE.
752 KEEP is as for assign_stack_temp.
753 MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
754 it is 0 if a register is OK.
755 DONT_PROMOTE is 1 if we should not promote values in register
759 assign_temp (type, keep, memory_required, dont_promote)
765 enum machine_mode mode = TYPE_MODE (type);
766 int unsignedp = TREE_UNSIGNED (type);
768 if (mode == BLKmode || memory_required)
770 HOST_WIDE_INT size = int_size_in_bytes (type);
773 /* Unfortunately, we don't yet know how to allocate variable-sized
774 temporaries. However, sometimes we have a fixed upper limit on
775 the size (which is stored in TYPE_ARRAY_MAX_SIZE) and can use that
776 instead. This is the case for Chill variable-sized strings. */
777 if (size == -1 && TREE_CODE (type) == ARRAY_TYPE
778 && TYPE_ARRAY_MAX_SIZE (type) != NULL_TREE
779 && TREE_CODE (TYPE_ARRAY_MAX_SIZE (type)) == INTEGER_CST)
780 size = TREE_INT_CST_LOW (TYPE_ARRAY_MAX_SIZE (type));
782 tmp = assign_stack_temp_for_type (mode, size, keep, type);
783 MEM_SET_IN_STRUCT_P (tmp, AGGREGATE_TYPE_P (type));
787 #ifndef PROMOTE_FOR_CALL_ONLY
789 mode = promote_mode (type, mode, &unsignedp, 0);
792 return gen_reg_rtx (mode);
795 /* Combine temporary stack slots which are adjacent on the stack.
797 This allows for better use of already allocated stack space. This is only
798 done for BLKmode slots because we can be sure that we won't have alignment
799 problems in this case. */
802 combine_temp_slots ()
804 struct temp_slot *p, *q;
805 struct temp_slot *prev_p, *prev_q;
808 /* We can't combine slots, because the information about which slot
809 is in which alias set will be lost. */
810 if (flag_strict_aliasing)
813 /* If there are a lot of temp slots, don't do anything unless
814 high levels of optimizaton. */
815 if (! flag_expensive_optimizations)
816 for (p = temp_slots, num_slots = 0; p; p = p->next, num_slots++)
817 if (num_slots > 100 || (num_slots > 10 && optimize == 0))
820 for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots)
824 if (! p->in_use && GET_MODE (p->slot) == BLKmode)
825 for (q = p->next, prev_q = p; q; q = prev_q->next)
828 if (! q->in_use && GET_MODE (q->slot) == BLKmode)
830 if (p->base_offset + p->full_size == q->base_offset)
832 /* Q comes after P; combine Q into P. */
834 p->full_size += q->full_size;
837 else if (q->base_offset + q->full_size == p->base_offset)
839 /* P comes after Q; combine P into Q. */
841 q->full_size += p->full_size;
846 /* Either delete Q or advance past it. */
848 prev_q->next = q->next;
852 /* Either delete P or advance past it. */
856 prev_p->next = p->next;
858 temp_slots = p->next;
865 /* Find the temp slot corresponding to the object at address X. */
867 static struct temp_slot *
868 find_temp_slot_from_address (x)
874 for (p = temp_slots; p; p = p->next)
879 else if (XEXP (p->slot, 0) == x
881 || (GET_CODE (x) == PLUS
882 && XEXP (x, 0) == virtual_stack_vars_rtx
883 && GET_CODE (XEXP (x, 1)) == CONST_INT
884 && INTVAL (XEXP (x, 1)) >= p->base_offset
885 && INTVAL (XEXP (x, 1)) < p->base_offset + p->full_size))
888 else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST)
889 for (next = p->address; next; next = XEXP (next, 1))
890 if (XEXP (next, 0) == x)
897 /* Indicate that NEW is an alternate way of referring to the temp slot
898 that previously was known by OLD. */
901 update_temp_slot_address (old, new)
904 struct temp_slot *p = find_temp_slot_from_address (old);
906 /* If none, return. Else add NEW as an alias. */
909 else if (p->address == 0)
913 if (GET_CODE (p->address) != EXPR_LIST)
914 p->address = gen_rtx_EXPR_LIST (VOIDmode, p->address, NULL_RTX);
916 p->address = gen_rtx_EXPR_LIST (VOIDmode, new, p->address);
920 /* If X could be a reference to a temporary slot, mark the fact that its
921 address was taken. */
924 mark_temp_addr_taken (x)
932 /* If X is not in memory or is at a constant address, it cannot be in
934 if (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
937 p = find_temp_slot_from_address (XEXP (x, 0));
942 /* If X could be a reference to a temporary slot, mark that slot as
943 belonging to the to one level higher than the current level. If X
944 matched one of our slots, just mark that one. Otherwise, we can't
945 easily predict which it is, so upgrade all of them. Kept slots
948 This is called when an ({...}) construct occurs and a statement
949 returns a value in memory. */
952 preserve_temp_slots (x)
955 struct temp_slot *p = 0;
957 /* If there is no result, we still might have some objects whose address
958 were taken, so we need to make sure they stay around. */
961 for (p = temp_slots; p; p = p->next)
962 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
968 /* If X is a register that is being used as a pointer, see if we have
969 a temporary slot we know it points to. To be consistent with
970 the code below, we really should preserve all non-kept slots
971 if we can't find a match, but that seems to be much too costly. */
972 if (GET_CODE (x) == REG && REGNO_POINTER_FLAG (REGNO (x)))
973 p = find_temp_slot_from_address (x);
975 /* If X is not in memory or is at a constant address, it cannot be in
976 a temporary slot, but it can contain something whose address was
978 if (p == 0 && (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))))
980 for (p = temp_slots; p; p = p->next)
981 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
987 /* First see if we can find a match. */
989 p = find_temp_slot_from_address (XEXP (x, 0));
993 /* Move everything at our level whose address was taken to our new
994 level in case we used its address. */
997 if (p->level == temp_slot_level)
999 for (q = temp_slots; q; q = q->next)
1000 if (q != p && q->addr_taken && q->level == p->level)
1009 /* Otherwise, preserve all non-kept slots at this level. */
1010 for (p = temp_slots; p; p = p->next)
1011 if (p->in_use && p->level == temp_slot_level && ! p->keep)
1015 /* X is the result of an RTL_EXPR. If it is a temporary slot associated
1016 with that RTL_EXPR, promote it into a temporary slot at the present
1017 level so it will not be freed when we free slots made in the
1021 preserve_rtl_expr_result (x)
1024 struct temp_slot *p;
1026 /* If X is not in memory or is at a constant address, it cannot be in
1027 a temporary slot. */
1028 if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1031 /* If we can find a match, move it to our level unless it is already at
1033 p = find_temp_slot_from_address (XEXP (x, 0));
1036 p->level = MIN (p->level, temp_slot_level);
1043 /* Free all temporaries used so far. This is normally called at the end
1044 of generating code for a statement. Don't free any temporaries
1045 currently in use for an RTL_EXPR that hasn't yet been emitted.
1046 We could eventually do better than this since it can be reused while
1047 generating the same RTL_EXPR, but this is complex and probably not
1053 struct temp_slot *p;
1055 for (p = temp_slots; p; p = p->next)
1056 if (p->in_use && p->level == temp_slot_level && ! p->keep
1057 && p->rtl_expr == 0)
1060 combine_temp_slots ();
1063 /* Free all temporary slots used in T, an RTL_EXPR node. */
1066 free_temps_for_rtl_expr (t)
1069 struct temp_slot *p;
1071 for (p = temp_slots; p; p = p->next)
1072 if (p->rtl_expr == t)
1075 combine_temp_slots ();
1078 /* Mark all temporaries ever allocated in this function as not suitable
1079 for reuse until the current level is exited. */
1082 mark_all_temps_used ()
1084 struct temp_slot *p;
1086 for (p = temp_slots; p; p = p->next)
1088 p->in_use = p->keep = 1;
1089 p->level = MIN (p->level, temp_slot_level);
1093 /* Push deeper into the nesting level for stack temporaries. */
1101 /* Likewise, but save the new level as the place to allocate variables
1105 push_temp_slots_for_block ()
1109 var_temp_slot_level = temp_slot_level;
1112 /* Likewise, but save the new level as the place to allocate temporaries
1113 for TARGET_EXPRs. */
1116 push_temp_slots_for_target ()
1120 target_temp_slot_level = temp_slot_level;
1123 /* Set and get the value of target_temp_slot_level. The only
1124 permitted use of these functions is to save and restore this value. */
1127 get_target_temp_slot_level ()
1129 return target_temp_slot_level;
1133 set_target_temp_slot_level (level)
1136 target_temp_slot_level = level;
1139 /* Pop a temporary nesting level. All slots in use in the current level
1145 struct temp_slot *p;
1147 for (p = temp_slots; p; p = p->next)
1148 if (p->in_use && p->level == temp_slot_level && p->rtl_expr == 0)
1151 combine_temp_slots ();
1156 /* Initialize temporary slots. */
1161 /* We have not allocated any temporaries yet. */
1163 temp_slot_level = 0;
1164 var_temp_slot_level = 0;
1165 target_temp_slot_level = 0;
1168 /* Retroactively move an auto variable from a register to a stack slot.
1169 This is done when an address-reference to the variable is seen. */
1172 put_var_into_stack (decl)
1176 enum machine_mode promoted_mode, decl_mode;
1177 struct function *function = 0;
1179 int can_use_addressof;
1181 context = decl_function_context (decl);
1183 /* Get the current rtl used for this object and its original mode. */
1184 reg = TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl) : DECL_RTL (decl);
1186 /* No need to do anything if decl has no rtx yet
1187 since in that case caller is setting TREE_ADDRESSABLE
1188 and a stack slot will be assigned when the rtl is made. */
1192 /* Get the declared mode for this object. */
1193 decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl))
1194 : DECL_MODE (decl));
1195 /* Get the mode it's actually stored in. */
1196 promoted_mode = GET_MODE (reg);
1198 /* If this variable comes from an outer function,
1199 find that function's saved context. */
1200 if (context != current_function_decl && context != inline_function_decl)
1201 for (function = outer_function_chain; function; function = function->next)
1202 if (function->decl == context)
1205 /* If this is a variable-size object with a pseudo to address it,
1206 put that pseudo into the stack, if the var is nonlocal. */
1207 if (DECL_NONLOCAL (decl)
1208 && GET_CODE (reg) == MEM
1209 && GET_CODE (XEXP (reg, 0)) == REG
1210 && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER)
1212 reg = XEXP (reg, 0);
1213 decl_mode = promoted_mode = GET_MODE (reg);
1219 /* FIXME make it work for promoted modes too */
1220 && decl_mode == promoted_mode
1221 #ifdef NON_SAVING_SETJMP
1222 && ! (NON_SAVING_SETJMP && current_function_calls_setjmp)
1226 /* If we can't use ADDRESSOF, make sure we see through one we already
1228 if (! can_use_addressof && GET_CODE (reg) == MEM
1229 && GET_CODE (XEXP (reg, 0)) == ADDRESSOF)
1230 reg = XEXP (XEXP (reg, 0), 0);
1232 /* Now we should have a value that resides in one or more pseudo regs. */
1234 if (GET_CODE (reg) == REG)
1236 /* If this variable lives in the current function and we don't need
1237 to put things in the stack for the sake of setjmp, try to keep it
1238 in a register until we know we actually need the address. */
1239 if (can_use_addressof)
1240 gen_mem_addressof (reg, decl);
1242 put_reg_into_stack (function, reg, TREE_TYPE (decl),
1243 promoted_mode, decl_mode,
1244 TREE_SIDE_EFFECTS (decl), 0,
1245 TREE_USED (decl) || DECL_INITIAL (decl) != 0,
1248 else if (GET_CODE (reg) == CONCAT)
1250 /* A CONCAT contains two pseudos; put them both in the stack.
1251 We do it so they end up consecutive. */
1252 enum machine_mode part_mode = GET_MODE (XEXP (reg, 0));
1253 tree part_type = TREE_TYPE (TREE_TYPE (decl));
1254 #ifdef FRAME_GROWS_DOWNWARD
1255 /* Since part 0 should have a lower address, do it second. */
1256 put_reg_into_stack (function, XEXP (reg, 1), part_type, part_mode,
1257 part_mode, TREE_SIDE_EFFECTS (decl), 0,
1258 TREE_USED (decl) || DECL_INITIAL (decl) != 0,
1260 put_reg_into_stack (function, XEXP (reg, 0), part_type, part_mode,
1261 part_mode, TREE_SIDE_EFFECTS (decl), 0,
1262 TREE_USED (decl) || DECL_INITIAL (decl) != 0,
1265 put_reg_into_stack (function, XEXP (reg, 0), part_type, part_mode,
1266 part_mode, TREE_SIDE_EFFECTS (decl), 0,
1267 TREE_USED (decl) || DECL_INITIAL (decl) != 0,
1269 put_reg_into_stack (function, XEXP (reg, 1), part_type, part_mode,
1270 part_mode, TREE_SIDE_EFFECTS (decl), 0,
1271 TREE_USED (decl) || DECL_INITIAL (decl) != 0,
1275 /* Change the CONCAT into a combined MEM for both parts. */
1276 PUT_CODE (reg, MEM);
1277 MEM_VOLATILE_P (reg) = MEM_VOLATILE_P (XEXP (reg, 0));
1278 MEM_ALIAS_SET (reg) = get_alias_set (decl);
1280 /* The two parts are in memory order already.
1281 Use the lower parts address as ours. */
1282 XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0);
1283 /* Prevent sharing of rtl that might lose. */
1284 if (GET_CODE (XEXP (reg, 0)) == PLUS)
1285 XEXP (reg, 0) = copy_rtx (XEXP (reg, 0));
1290 if (current_function_check_memory_usage)
1291 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
1292 XEXP (reg, 0), Pmode,
1293 GEN_INT (GET_MODE_SIZE (GET_MODE (reg))),
1294 TYPE_MODE (sizetype),
1295 GEN_INT (MEMORY_USE_RW),
1296 TYPE_MODE (integer_type_node));
1299 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1300 into the stack frame of FUNCTION (0 means the current function).
1301 DECL_MODE is the machine mode of the user-level data type.
1302 PROMOTED_MODE is the machine mode of the register.
1303 VOLATILE_P is nonzero if this is for a "volatile" decl.
1304 USED_P is nonzero if this reg might have already been used in an insn. */
1307 put_reg_into_stack (function, reg, type, promoted_mode, decl_mode, volatile_p,
1308 original_regno, used_p, ht)
1309 struct function *function;
1312 enum machine_mode promoted_mode, decl_mode;
1316 struct hash_table *ht;
1318 struct function *func = function ? function : current_function;
1320 int regno = original_regno;
1323 regno = REGNO (reg);
1325 if (regno < func->x_max_parm_reg)
1326 new = func->x_parm_reg_stack_loc[regno];
1328 new = assign_stack_local_1 (decl_mode, GET_MODE_SIZE (decl_mode), 0, func);
1330 PUT_CODE (reg, MEM);
1331 PUT_MODE (reg, decl_mode);
1332 XEXP (reg, 0) = XEXP (new, 0);
1333 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
1334 MEM_VOLATILE_P (reg) = volatile_p;
1336 /* If this is a memory ref that contains aggregate components,
1337 mark it as such for cse and loop optimize. If we are reusing a
1338 previously generated stack slot, then we need to copy the bit in
1339 case it was set for other reasons. For instance, it is set for
1340 __builtin_va_alist. */
1341 MEM_SET_IN_STRUCT_P (reg,
1342 AGGREGATE_TYPE_P (type) || MEM_IN_STRUCT_P (new));
1343 MEM_ALIAS_SET (reg) = get_alias_set (type);
1345 /* Now make sure that all refs to the variable, previously made
1346 when it was a register, are fixed up to be valid again. */
1348 if (used_p && function != 0)
1350 struct var_refs_queue *temp;
1353 = (struct var_refs_queue *) xmalloc (sizeof (struct var_refs_queue));
1354 temp->modified = reg;
1355 temp->promoted_mode = promoted_mode;
1356 temp->unsignedp = TREE_UNSIGNED (type);
1357 temp->next = function->fixup_var_refs_queue;
1358 function->fixup_var_refs_queue = temp;
1361 /* Variable is local; fix it up now. */
1362 fixup_var_refs (reg, promoted_mode, TREE_UNSIGNED (type), ht);
1366 fixup_var_refs (var, promoted_mode, unsignedp, ht)
1368 enum machine_mode promoted_mode;
1370 struct hash_table *ht;
1373 rtx first_insn = get_insns ();
1374 struct sequence_stack *stack = seq_stack;
1375 tree rtl_exps = rtl_expr_chain;
1377 /* Must scan all insns for stack-refs that exceed the limit. */
1378 fixup_var_refs_insns (var, promoted_mode, unsignedp, first_insn,
1380 /* If there's a hash table, it must record all uses of VAR. */
1384 /* Scan all pending sequences too. */
1385 for (; stack; stack = stack->next)
1387 push_to_sequence (stack->first);
1388 fixup_var_refs_insns (var, promoted_mode, unsignedp,
1389 stack->first, stack->next != 0, 0);
1390 /* Update remembered end of sequence
1391 in case we added an insn at the end. */
1392 stack->last = get_last_insn ();
1396 /* Scan all waiting RTL_EXPRs too. */
1397 for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending))
1399 rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
1400 if (seq != const0_rtx && seq != 0)
1402 push_to_sequence (seq);
1403 fixup_var_refs_insns (var, promoted_mode, unsignedp, seq, 0,
1409 /* Scan the catch clauses for exception handling too. */
1410 push_to_sequence (catch_clauses);
1411 fixup_var_refs_insns (var, promoted_mode, unsignedp, catch_clauses,
1416 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
1417 some part of an insn. Return a struct fixup_replacement whose OLD
1418 value is equal to X. Allocate a new structure if no such entry exists. */
1420 static struct fixup_replacement *
1421 find_fixup_replacement (replacements, x)
1422 struct fixup_replacement **replacements;
1425 struct fixup_replacement *p;
1427 /* See if we have already replaced this. */
1428 for (p = *replacements; p != 0 && ! rtx_equal_p (p->old, x); p = p->next)
1433 p = (struct fixup_replacement *) oballoc (sizeof (struct fixup_replacement));
1436 p->next = *replacements;
1443 /* Scan the insn-chain starting with INSN for refs to VAR
1444 and fix them up. TOPLEVEL is nonzero if this chain is the
1445 main chain of insns for the current function. */
1448 fixup_var_refs_insns (var, promoted_mode, unsignedp, insn, toplevel, ht)
1450 enum machine_mode promoted_mode;
1454 struct hash_table *ht;
1457 rtx insn_list = NULL_RTX;
1459 /* If we already know which INSNs reference VAR there's no need
1460 to walk the entire instruction chain. */
1463 insn_list = ((struct insns_for_mem_entry *)
1464 hash_lookup (ht, var, /*create=*/0, /*copy=*/0))->insns;
1465 insn = insn_list ? XEXP (insn_list, 0) : NULL_RTX;
1466 insn_list = XEXP (insn_list, 1);
1471 rtx next = NEXT_INSN (insn);
1472 rtx set, prev, prev_set;
1475 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
1477 /* Remember the notes in case we delete the insn. */
1478 note = REG_NOTES (insn);
1480 /* If this is a CLOBBER of VAR, delete it.
1482 If it has a REG_LIBCALL note, delete the REG_LIBCALL
1483 and REG_RETVAL notes too. */
1484 if (GET_CODE (PATTERN (insn)) == CLOBBER
1485 && (XEXP (PATTERN (insn), 0) == var
1486 || (GET_CODE (XEXP (PATTERN (insn), 0)) == CONCAT
1487 && (XEXP (XEXP (PATTERN (insn), 0), 0) == var
1488 || XEXP (XEXP (PATTERN (insn), 0), 1) == var))))
1490 if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX)) != 0)
1491 /* The REG_LIBCALL note will go away since we are going to
1492 turn INSN into a NOTE, so just delete the
1493 corresponding REG_RETVAL note. */
1494 remove_note (XEXP (note, 0),
1495 find_reg_note (XEXP (note, 0), REG_RETVAL,
1498 /* In unoptimized compilation, we shouldn't call delete_insn
1499 except in jump.c doing warnings. */
1500 PUT_CODE (insn, NOTE);
1501 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1502 NOTE_SOURCE_FILE (insn) = 0;
1505 /* The insn to load VAR from a home in the arglist
1506 is now a no-op. When we see it, just delete it.
1507 Similarly if this is storing VAR from a register from which
1508 it was loaded in the previous insn. This will occur
1509 when an ADDRESSOF was made for an arglist slot. */
1511 && (set = single_set (insn)) != 0
1512 && SET_DEST (set) == var
1513 /* If this represents the result of an insn group,
1514 don't delete the insn. */
1515 && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0
1516 && (rtx_equal_p (SET_SRC (set), var)
1517 || (GET_CODE (SET_SRC (set)) == REG
1518 && (prev = prev_nonnote_insn (insn)) != 0
1519 && (prev_set = single_set (prev)) != 0
1520 && SET_DEST (prev_set) == SET_SRC (set)
1521 && rtx_equal_p (SET_SRC (prev_set), var))))
1523 /* In unoptimized compilation, we shouldn't call delete_insn
1524 except in jump.c doing warnings. */
1525 PUT_CODE (insn, NOTE);
1526 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1527 NOTE_SOURCE_FILE (insn) = 0;
1528 if (insn == last_parm_insn)
1529 last_parm_insn = PREV_INSN (next);
1533 struct fixup_replacement *replacements = 0;
1534 rtx next_insn = NEXT_INSN (insn);
1536 if (SMALL_REGISTER_CLASSES)
1538 /* If the insn that copies the results of a CALL_INSN
1539 into a pseudo now references VAR, we have to use an
1540 intermediate pseudo since we want the life of the
1541 return value register to be only a single insn.
1543 If we don't use an intermediate pseudo, such things as
1544 address computations to make the address of VAR valid
1545 if it is not can be placed between the CALL_INSN and INSN.
1547 To make sure this doesn't happen, we record the destination
1548 of the CALL_INSN and see if the next insn uses both that
1551 if (call_dest != 0 && GET_CODE (insn) == INSN
1552 && reg_mentioned_p (var, PATTERN (insn))
1553 && reg_mentioned_p (call_dest, PATTERN (insn)))
1555 rtx temp = gen_reg_rtx (GET_MODE (call_dest));
1557 emit_insn_before (gen_move_insn (temp, call_dest), insn);
1559 PATTERN (insn) = replace_rtx (PATTERN (insn),
1563 if (GET_CODE (insn) == CALL_INSN
1564 && GET_CODE (PATTERN (insn)) == SET)
1565 call_dest = SET_DEST (PATTERN (insn));
1566 else if (GET_CODE (insn) == CALL_INSN
1567 && GET_CODE (PATTERN (insn)) == PARALLEL
1568 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
1569 call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
1574 /* See if we have to do anything to INSN now that VAR is in
1575 memory. If it needs to be loaded into a pseudo, use a single
1576 pseudo for the entire insn in case there is a MATCH_DUP
1577 between two operands. We pass a pointer to the head of
1578 a list of struct fixup_replacements. If fixup_var_refs_1
1579 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1580 it will record them in this list.
1582 If it allocated a pseudo for any replacement, we copy into
1585 fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn,
1588 /* If this is last_parm_insn, and any instructions were output
1589 after it to fix it up, then we must set last_parm_insn to
1590 the last such instruction emitted. */
1591 if (insn == last_parm_insn)
1592 last_parm_insn = PREV_INSN (next_insn);
1594 while (replacements)
1596 if (GET_CODE (replacements->new) == REG)
1601 /* OLD might be a (subreg (mem)). */
1602 if (GET_CODE (replacements->old) == SUBREG)
1604 = fixup_memory_subreg (replacements->old, insn, 0);
1607 = fixup_stack_1 (replacements->old, insn);
1609 insert_before = insn;
1611 /* If we are changing the mode, do a conversion.
1612 This might be wasteful, but combine.c will
1613 eliminate much of the waste. */
1615 if (GET_MODE (replacements->new)
1616 != GET_MODE (replacements->old))
1619 convert_move (replacements->new,
1620 replacements->old, unsignedp);
1621 seq = gen_sequence ();
1625 seq = gen_move_insn (replacements->new,
1628 emit_insn_before (seq, insert_before);
1631 replacements = replacements->next;
1635 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
1636 But don't touch other insns referred to by reg-notes;
1637 we will get them elsewhere. */
1640 if (GET_CODE (note) != INSN_LIST)
1642 = walk_fixup_memory_subreg (XEXP (note, 0), insn, 1);
1643 note = XEXP (note, 1);
1651 insn = XEXP (insn_list, 0);
1652 insn_list = XEXP (insn_list, 1);
1659 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
1660 See if the rtx expression at *LOC in INSN needs to be changed.
1662 REPLACEMENTS is a pointer to a list head that starts out zero, but may
1663 contain a list of original rtx's and replacements. If we find that we need
1664 to modify this insn by replacing a memory reference with a pseudo or by
1665 making a new MEM to implement a SUBREG, we consult that list to see if
1666 we have already chosen a replacement. If none has already been allocated,
1667 we allocate it and update the list. fixup_var_refs_insns will copy VAR
1668 or the SUBREG, as appropriate, to the pseudo. */
1671 fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements)
1673 enum machine_mode promoted_mode;
1676 struct fixup_replacement **replacements;
1679 register rtx x = *loc;
1680 RTX_CODE code = GET_CODE (x);
1681 register const char *fmt;
1682 register rtx tem, tem1;
1683 struct fixup_replacement *replacement;
1688 if (XEXP (x, 0) == var)
1690 /* Prevent sharing of rtl that might lose. */
1691 rtx sub = copy_rtx (XEXP (var, 0));
1693 if (! validate_change (insn, loc, sub, 0))
1695 rtx y = gen_reg_rtx (GET_MODE (sub));
1698 /* We should be able to replace with a register or all is lost.
1699 Note that we can't use validate_change to verify this, since
1700 we're not caring for replacing all dups simultaneously. */
1701 if (! validate_replace_rtx (*loc, y, insn))
1704 /* Careful! First try to recognize a direct move of the
1705 value, mimicking how things are done in gen_reload wrt
1706 PLUS. Consider what happens when insn is a conditional
1707 move instruction and addsi3 clobbers flags. */
1710 new_insn = emit_insn (gen_rtx_SET (VOIDmode, y, sub));
1711 seq = gen_sequence ();
1714 if (recog_memoized (new_insn) < 0)
1716 /* That failed. Fall back on force_operand and hope. */
1719 force_operand (sub, y);
1720 seq = gen_sequence ();
1725 /* Don't separate setter from user. */
1726 if (PREV_INSN (insn) && sets_cc0_p (PREV_INSN (insn)))
1727 insn = PREV_INSN (insn);
1730 emit_insn_before (seq, insn);
1738 /* If we already have a replacement, use it. Otherwise,
1739 try to fix up this address in case it is invalid. */
1741 replacement = find_fixup_replacement (replacements, var);
1742 if (replacement->new)
1744 *loc = replacement->new;
1748 *loc = replacement->new = x = fixup_stack_1 (x, insn);
1750 /* Unless we are forcing memory to register or we changed the mode,
1751 we can leave things the way they are if the insn is valid. */
1753 INSN_CODE (insn) = -1;
1754 if (! flag_force_mem && GET_MODE (x) == promoted_mode
1755 && recog_memoized (insn) >= 0)
1758 *loc = replacement->new = gen_reg_rtx (promoted_mode);
1762 /* If X contains VAR, we need to unshare it here so that we update
1763 each occurrence separately. But all identical MEMs in one insn
1764 must be replaced with the same rtx because of the possibility of
1767 if (reg_mentioned_p (var, x))
1769 replacement = find_fixup_replacement (replacements, x);
1770 if (replacement->new == 0)
1771 replacement->new = copy_most_rtx (x, var);
1773 *loc = x = replacement->new;
1789 /* Note that in some cases those types of expressions are altered
1790 by optimize_bit_field, and do not survive to get here. */
1791 if (XEXP (x, 0) == var
1792 || (GET_CODE (XEXP (x, 0)) == SUBREG
1793 && SUBREG_REG (XEXP (x, 0)) == var))
1795 /* Get TEM as a valid MEM in the mode presently in the insn.
1797 We don't worry about the possibility of MATCH_DUP here; it
1798 is highly unlikely and would be tricky to handle. */
1801 if (GET_CODE (tem) == SUBREG)
1803 if (GET_MODE_BITSIZE (GET_MODE (tem))
1804 > GET_MODE_BITSIZE (GET_MODE (var)))
1806 replacement = find_fixup_replacement (replacements, var);
1807 if (replacement->new == 0)
1808 replacement->new = gen_reg_rtx (GET_MODE (var));
1809 SUBREG_REG (tem) = replacement->new;
1812 tem = fixup_memory_subreg (tem, insn, 0);
1815 tem = fixup_stack_1 (tem, insn);
1817 /* Unless we want to load from memory, get TEM into the proper mode
1818 for an extract from memory. This can only be done if the
1819 extract is at a constant position and length. */
1821 if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT
1822 && GET_CODE (XEXP (x, 2)) == CONST_INT
1823 && ! mode_dependent_address_p (XEXP (tem, 0))
1824 && ! MEM_VOLATILE_P (tem))
1826 enum machine_mode wanted_mode = VOIDmode;
1827 enum machine_mode is_mode = GET_MODE (tem);
1828 HOST_WIDE_INT pos = INTVAL (XEXP (x, 2));
1831 if (GET_CODE (x) == ZERO_EXTRACT)
1833 wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1];
1834 if (wanted_mode == VOIDmode)
1835 wanted_mode = word_mode;
1839 if (GET_CODE (x) == SIGN_EXTRACT)
1841 wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1];
1842 if (wanted_mode == VOIDmode)
1843 wanted_mode = word_mode;
1846 /* If we have a narrower mode, we can do something. */
1847 if (wanted_mode != VOIDmode
1848 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
1850 HOST_WIDE_INT offset = pos / BITS_PER_UNIT;
1851 rtx old_pos = XEXP (x, 2);
1854 /* If the bytes and bits are counted differently, we
1855 must adjust the offset. */
1856 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
1857 offset = (GET_MODE_SIZE (is_mode)
1858 - GET_MODE_SIZE (wanted_mode) - offset);
1860 pos %= GET_MODE_BITSIZE (wanted_mode);
1862 newmem = gen_rtx_MEM (wanted_mode,
1863 plus_constant (XEXP (tem, 0), offset));
1864 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
1865 MEM_COPY_ATTRIBUTES (newmem, tem);
1867 /* Make the change and see if the insn remains valid. */
1868 INSN_CODE (insn) = -1;
1869 XEXP (x, 0) = newmem;
1870 XEXP (x, 2) = GEN_INT (pos);
1872 if (recog_memoized (insn) >= 0)
1875 /* Otherwise, restore old position. XEXP (x, 0) will be
1877 XEXP (x, 2) = old_pos;
1881 /* If we get here, the bitfield extract insn can't accept a memory
1882 reference. Copy the input into a register. */
1884 tem1 = gen_reg_rtx (GET_MODE (tem));
1885 emit_insn_before (gen_move_insn (tem1, tem), insn);
1892 if (SUBREG_REG (x) == var)
1894 /* If this is a special SUBREG made because VAR was promoted
1895 from a wider mode, replace it with VAR and call ourself
1896 recursively, this time saying that the object previously
1897 had its current mode (by virtue of the SUBREG). */
1899 if (SUBREG_PROMOTED_VAR_P (x))
1902 fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements);
1906 /* If this SUBREG makes VAR wider, it has become a paradoxical
1907 SUBREG with VAR in memory, but these aren't allowed at this
1908 stage of the compilation. So load VAR into a pseudo and take
1909 a SUBREG of that pseudo. */
1910 if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var)))
1912 replacement = find_fixup_replacement (replacements, var);
1913 if (replacement->new == 0)
1914 replacement->new = gen_reg_rtx (GET_MODE (var));
1915 SUBREG_REG (x) = replacement->new;
1919 /* See if we have already found a replacement for this SUBREG.
1920 If so, use it. Otherwise, make a MEM and see if the insn
1921 is recognized. If not, or if we should force MEM into a register,
1922 make a pseudo for this SUBREG. */
1923 replacement = find_fixup_replacement (replacements, x);
1924 if (replacement->new)
1926 *loc = replacement->new;
1930 replacement->new = *loc = fixup_memory_subreg (x, insn, 0);
1932 INSN_CODE (insn) = -1;
1933 if (! flag_force_mem && recog_memoized (insn) >= 0)
1936 *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
1942 /* First do special simplification of bit-field references. */
1943 if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
1944 || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
1945 optimize_bit_field (x, insn, 0);
1946 if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
1947 || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
1948 optimize_bit_field (x, insn, NULL_PTR);
1950 /* For a paradoxical SUBREG inside a ZERO_EXTRACT, load the object
1951 into a register and then store it back out. */
1952 if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT
1953 && GET_CODE (XEXP (SET_DEST (x), 0)) == SUBREG
1954 && SUBREG_REG (XEXP (SET_DEST (x), 0)) == var
1955 && (GET_MODE_SIZE (GET_MODE (XEXP (SET_DEST (x), 0)))
1956 > GET_MODE_SIZE (GET_MODE (var))))
1958 replacement = find_fixup_replacement (replacements, var);
1959 if (replacement->new == 0)
1960 replacement->new = gen_reg_rtx (GET_MODE (var));
1962 SUBREG_REG (XEXP (SET_DEST (x), 0)) = replacement->new;
1963 emit_insn_after (gen_move_insn (var, replacement->new), insn);
1966 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
1967 insn into a pseudo and store the low part of the pseudo into VAR. */
1968 if (GET_CODE (SET_DEST (x)) == SUBREG
1969 && SUBREG_REG (SET_DEST (x)) == var
1970 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
1971 > GET_MODE_SIZE (GET_MODE (var))))
1973 SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x)));
1974 emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var),
1981 rtx dest = SET_DEST (x);
1982 rtx src = SET_SRC (x);
1984 rtx outerdest = dest;
1987 while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
1988 || GET_CODE (dest) == SIGN_EXTRACT
1989 || GET_CODE (dest) == ZERO_EXTRACT)
1990 dest = XEXP (dest, 0);
1992 if (GET_CODE (src) == SUBREG)
1993 src = XEXP (src, 0);
1995 /* If VAR does not appear at the top level of the SET
1996 just scan the lower levels of the tree. */
1998 if (src != var && dest != var)
2001 /* We will need to rerecognize this insn. */
2002 INSN_CODE (insn) = -1;
2005 if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var)
2007 /* Since this case will return, ensure we fixup all the
2009 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1),
2010 insn, replacements);
2011 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2),
2012 insn, replacements);
2013 fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x),
2014 insn, replacements);
2016 tem = XEXP (outerdest, 0);
2018 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
2019 that may appear inside a ZERO_EXTRACT.
2020 This was legitimate when the MEM was a REG. */
2021 if (GET_CODE (tem) == SUBREG
2022 && SUBREG_REG (tem) == var)
2023 tem = fixup_memory_subreg (tem, insn, 0);
2025 tem = fixup_stack_1 (tem, insn);
2027 if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT
2028 && GET_CODE (XEXP (outerdest, 2)) == CONST_INT
2029 && ! mode_dependent_address_p (XEXP (tem, 0))
2030 && ! MEM_VOLATILE_P (tem))
2032 enum machine_mode wanted_mode;
2033 enum machine_mode is_mode = GET_MODE (tem);
2034 HOST_WIDE_INT pos = INTVAL (XEXP (outerdest, 2));
2036 wanted_mode = insn_operand_mode[(int) CODE_FOR_insv][0];
2037 if (wanted_mode == VOIDmode)
2038 wanted_mode = word_mode;
2040 /* If we have a narrower mode, we can do something. */
2041 if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
2043 HOST_WIDE_INT offset = pos / BITS_PER_UNIT;
2044 rtx old_pos = XEXP (outerdest, 2);
2047 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
2048 offset = (GET_MODE_SIZE (is_mode)
2049 - GET_MODE_SIZE (wanted_mode) - offset);
2051 pos %= GET_MODE_BITSIZE (wanted_mode);
2053 newmem = gen_rtx_MEM (wanted_mode,
2054 plus_constant (XEXP (tem, 0),
2056 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
2057 MEM_COPY_ATTRIBUTES (newmem, tem);
2059 /* Make the change and see if the insn remains valid. */
2060 INSN_CODE (insn) = -1;
2061 XEXP (outerdest, 0) = newmem;
2062 XEXP (outerdest, 2) = GEN_INT (pos);
2064 if (recog_memoized (insn) >= 0)
2067 /* Otherwise, restore old position. XEXP (x, 0) will be
2069 XEXP (outerdest, 2) = old_pos;
2073 /* If we get here, the bit-field store doesn't allow memory
2074 or isn't located at a constant position. Load the value into
2075 a register, do the store, and put it back into memory. */
2077 tem1 = gen_reg_rtx (GET_MODE (tem));
2078 emit_insn_before (gen_move_insn (tem1, tem), insn);
2079 emit_insn_after (gen_move_insn (tem, tem1), insn);
2080 XEXP (outerdest, 0) = tem1;
2085 /* STRICT_LOW_PART is a no-op on memory references
2086 and it can cause combinations to be unrecognizable,
2089 if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
2090 SET_DEST (x) = XEXP (SET_DEST (x), 0);
2092 /* A valid insn to copy VAR into or out of a register
2093 must be left alone, to avoid an infinite loop here.
2094 If the reference to VAR is by a subreg, fix that up,
2095 since SUBREG is not valid for a memref.
2096 Also fix up the address of the stack slot.
2098 Note that we must not try to recognize the insn until
2099 after we know that we have valid addresses and no
2100 (subreg (mem ...) ...) constructs, since these interfere
2101 with determining the validity of the insn. */
2103 if ((SET_SRC (x) == var
2104 || (GET_CODE (SET_SRC (x)) == SUBREG
2105 && SUBREG_REG (SET_SRC (x)) == var))
2106 && (GET_CODE (SET_DEST (x)) == REG
2107 || (GET_CODE (SET_DEST (x)) == SUBREG
2108 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
2109 && GET_MODE (var) == promoted_mode
2110 && x == single_set (insn))
2114 replacement = find_fixup_replacement (replacements, SET_SRC (x));
2115 if (replacement->new)
2116 SET_SRC (x) = replacement->new;
2117 else if (GET_CODE (SET_SRC (x)) == SUBREG)
2118 SET_SRC (x) = replacement->new
2119 = fixup_memory_subreg (SET_SRC (x), insn, 0);
2121 SET_SRC (x) = replacement->new
2122 = fixup_stack_1 (SET_SRC (x), insn);
2124 if (recog_memoized (insn) >= 0)
2127 /* INSN is not valid, but we know that we want to
2128 copy SET_SRC (x) to SET_DEST (x) in some way. So
2129 we generate the move and see whether it requires more
2130 than one insn. If it does, we emit those insns and
2131 delete INSN. Otherwise, we an just replace the pattern
2132 of INSN; we have already verified above that INSN has
2133 no other function that to do X. */
2135 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2136 if (GET_CODE (pat) == SEQUENCE)
2138 emit_insn_after (pat, insn);
2139 PUT_CODE (insn, NOTE);
2140 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2141 NOTE_SOURCE_FILE (insn) = 0;
2144 PATTERN (insn) = pat;
2149 if ((SET_DEST (x) == var
2150 || (GET_CODE (SET_DEST (x)) == SUBREG
2151 && SUBREG_REG (SET_DEST (x)) == var))
2152 && (GET_CODE (SET_SRC (x)) == REG
2153 || (GET_CODE (SET_SRC (x)) == SUBREG
2154 && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG))
2155 && GET_MODE (var) == promoted_mode
2156 && x == single_set (insn))
2160 if (GET_CODE (SET_DEST (x)) == SUBREG)
2161 SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn, 0);
2163 SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn);
2165 if (recog_memoized (insn) >= 0)
2168 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2169 if (GET_CODE (pat) == SEQUENCE)
2171 emit_insn_after (pat, insn);
2172 PUT_CODE (insn, NOTE);
2173 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2174 NOTE_SOURCE_FILE (insn) = 0;
2177 PATTERN (insn) = pat;
2182 /* Otherwise, storing into VAR must be handled specially
2183 by storing into a temporary and copying that into VAR
2184 with a new insn after this one. Note that this case
2185 will be used when storing into a promoted scalar since
2186 the insn will now have different modes on the input
2187 and output and hence will be invalid (except for the case
2188 of setting it to a constant, which does not need any
2189 change if it is valid). We generate extra code in that case,
2190 but combine.c will eliminate it. */
2195 rtx fixeddest = SET_DEST (x);
2197 /* STRICT_LOW_PART can be discarded, around a MEM. */
2198 if (GET_CODE (fixeddest) == STRICT_LOW_PART)
2199 fixeddest = XEXP (fixeddest, 0);
2200 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
2201 if (GET_CODE (fixeddest) == SUBREG)
2203 fixeddest = fixup_memory_subreg (fixeddest, insn, 0);
2204 promoted_mode = GET_MODE (fixeddest);
2207 fixeddest = fixup_stack_1 (fixeddest, insn);
2209 temp = gen_reg_rtx (promoted_mode);
2211 emit_insn_after (gen_move_insn (fixeddest,
2212 gen_lowpart (GET_MODE (fixeddest),
2216 SET_DEST (x) = temp;
2224 /* Nothing special about this RTX; fix its operands. */
2226 fmt = GET_RTX_FORMAT (code);
2227 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2230 fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements);
2234 for (j = 0; j < XVECLEN (x, i); j++)
2235 fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j),
2236 insn, replacements);
2241 /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
2242 return an rtx (MEM:m1 newaddr) which is equivalent.
2243 If any insns must be emitted to compute NEWADDR, put them before INSN.
2245 UNCRITICAL nonzero means accept paradoxical subregs.
2246 This is used for subregs found inside REG_NOTES. */
2249 fixup_memory_subreg (x, insn, uncritical)
2254 int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
2255 rtx addr = XEXP (SUBREG_REG (x), 0);
2256 enum machine_mode mode = GET_MODE (x);
2259 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
2260 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
2264 if (BYTES_BIG_ENDIAN)
2265 offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
2266 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
2267 addr = plus_constant (addr, offset);
2268 if (!flag_force_addr && memory_address_p (mode, addr))
2269 /* Shortcut if no insns need be emitted. */
2270 return change_address (SUBREG_REG (x), mode, addr);
2272 result = change_address (SUBREG_REG (x), mode, addr);
2273 emit_insn_before (gen_sequence (), insn);
2278 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2279 Replace subexpressions of X in place.
2280 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2281 Otherwise return X, with its contents possibly altered.
2283 If any insns must be emitted to compute NEWADDR, put them before INSN.
2285 UNCRITICAL is as in fixup_memory_subreg. */
2288 walk_fixup_memory_subreg (x, insn, uncritical)
2293 register enum rtx_code code;
2294 register const char *fmt;
2300 code = GET_CODE (x);
2302 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
2303 return fixup_memory_subreg (x, insn, uncritical);
2305 /* Nothing special about this RTX; fix its operands. */
2307 fmt = GET_RTX_FORMAT (code);
2308 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2311 XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn, uncritical);
2315 for (j = 0; j < XVECLEN (x, i); j++)
2317 = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn, uncritical);
2323 /* For each memory ref within X, if it refers to a stack slot
2324 with an out of range displacement, put the address in a temp register
2325 (emitting new insns before INSN to load these registers)
2326 and alter the memory ref to use that register.
2327 Replace each such MEM rtx with a copy, to avoid clobberage. */
2330 fixup_stack_1 (x, insn)
2335 register RTX_CODE code = GET_CODE (x);
2336 register const char *fmt;
2340 register rtx ad = XEXP (x, 0);
2341 /* If we have address of a stack slot but it's not valid
2342 (displacement is too large), compute the sum in a register. */
2343 if (GET_CODE (ad) == PLUS
2344 && GET_CODE (XEXP (ad, 0)) == REG
2345 && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER
2346 && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER)
2347 || REGNO (XEXP (ad, 0)) == FRAME_POINTER_REGNUM
2348 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2349 || REGNO (XEXP (ad, 0)) == HARD_FRAME_POINTER_REGNUM
2351 || REGNO (XEXP (ad, 0)) == STACK_POINTER_REGNUM
2352 || REGNO (XEXP (ad, 0)) == ARG_POINTER_REGNUM
2353 || XEXP (ad, 0) == current_function_internal_arg_pointer)
2354 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
2357 if (memory_address_p (GET_MODE (x), ad))
2361 temp = copy_to_reg (ad);
2362 seq = gen_sequence ();
2364 emit_insn_before (seq, insn);
2365 return change_address (x, VOIDmode, temp);
2370 fmt = GET_RTX_FORMAT (code);
2371 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2374 XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
2378 for (j = 0; j < XVECLEN (x, i); j++)
2379 XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
2385 /* Optimization: a bit-field instruction whose field
2386 happens to be a byte or halfword in memory
2387 can be changed to a move instruction.
2389 We call here when INSN is an insn to examine or store into a bit-field.
2390 BODY is the SET-rtx to be altered.
2392 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2393 (Currently this is called only from function.c, and EQUIV_MEM
2397 optimize_bit_field (body, insn, equiv_mem)
2402 register rtx bitfield;
2405 enum machine_mode mode;
2407 if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
2408 || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
2409 bitfield = SET_DEST (body), destflag = 1;
2411 bitfield = SET_SRC (body), destflag = 0;
2413 /* First check that the field being stored has constant size and position
2414 and is in fact a byte or halfword suitably aligned. */
2416 if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
2417 && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
2418 && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1))
2420 && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
2422 register rtx memref = 0;
2424 /* Now check that the containing word is memory, not a register,
2425 and that it is safe to change the machine mode. */
2427 if (GET_CODE (XEXP (bitfield, 0)) == MEM)
2428 memref = XEXP (bitfield, 0);
2429 else if (GET_CODE (XEXP (bitfield, 0)) == REG
2431 memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
2432 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2433 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
2434 memref = SUBREG_REG (XEXP (bitfield, 0));
2435 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2437 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
2438 memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
2441 && ! mode_dependent_address_p (XEXP (memref, 0))
2442 && ! MEM_VOLATILE_P (memref))
2444 /* Now adjust the address, first for any subreg'ing
2445 that we are now getting rid of,
2446 and then for which byte of the word is wanted. */
2448 HOST_WIDE_INT offset = INTVAL (XEXP (bitfield, 2));
2451 /* Adjust OFFSET to count bits from low-address byte. */
2452 if (BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN)
2453 offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0)))
2454 - offset - INTVAL (XEXP (bitfield, 1)));
2456 /* Adjust OFFSET to count bytes from low-address byte. */
2457 offset /= BITS_PER_UNIT;
2458 if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
2460 offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD;
2461 if (BYTES_BIG_ENDIAN)
2462 offset -= (MIN (UNITS_PER_WORD,
2463 GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
2464 - MIN (UNITS_PER_WORD,
2465 GET_MODE_SIZE (GET_MODE (memref))));
2469 memref = change_address (memref, mode,
2470 plus_constant (XEXP (memref, 0), offset));
2471 insns = get_insns ();
2473 emit_insns_before (insns, insn);
2475 /* Store this memory reference where
2476 we found the bit field reference. */
2480 validate_change (insn, &SET_DEST (body), memref, 1);
2481 if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
2483 rtx src = SET_SRC (body);
2484 while (GET_CODE (src) == SUBREG
2485 && SUBREG_WORD (src) == 0)
2486 src = SUBREG_REG (src);
2487 if (GET_MODE (src) != GET_MODE (memref))
2488 src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
2489 validate_change (insn, &SET_SRC (body), src, 1);
2491 else if (GET_MODE (SET_SRC (body)) != VOIDmode
2492 && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
2493 /* This shouldn't happen because anything that didn't have
2494 one of these modes should have got converted explicitly
2495 and then referenced through a subreg.
2496 This is so because the original bit-field was
2497 handled by agg_mode and so its tree structure had
2498 the same mode that memref now has. */
2503 rtx dest = SET_DEST (body);
2505 while (GET_CODE (dest) == SUBREG
2506 && SUBREG_WORD (dest) == 0
2507 && (GET_MODE_CLASS (GET_MODE (dest))
2508 == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest))))
2509 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
2511 dest = SUBREG_REG (dest);
2513 validate_change (insn, &SET_DEST (body), dest, 1);
2515 if (GET_MODE (dest) == GET_MODE (memref))
2516 validate_change (insn, &SET_SRC (body), memref, 1);
2519 /* Convert the mem ref to the destination mode. */
2520 rtx newreg = gen_reg_rtx (GET_MODE (dest));
2523 convert_move (newreg, memref,
2524 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
2528 validate_change (insn, &SET_SRC (body), newreg, 1);
2532 /* See if we can convert this extraction or insertion into
2533 a simple move insn. We might not be able to do so if this
2534 was, for example, part of a PARALLEL.
2536 If we succeed, write out any needed conversions. If we fail,
2537 it is hard to guess why we failed, so don't do anything
2538 special; just let the optimization be suppressed. */
2540 if (apply_change_group () && seq)
2541 emit_insns_before (seq, insn);
2546 /* These routines are responsible for converting virtual register references
2547 to the actual hard register references once RTL generation is complete.
2549 The following four variables are used for communication between the
2550 routines. They contain the offsets of the virtual registers from their
2551 respective hard registers. */
2553 static int in_arg_offset;
2554 static int var_offset;
2555 static int dynamic_offset;
2556 static int out_arg_offset;
2557 static int cfa_offset;
2559 /* In most machines, the stack pointer register is equivalent to the bottom
2562 #ifndef STACK_POINTER_OFFSET
2563 #define STACK_POINTER_OFFSET 0
2566 /* If not defined, pick an appropriate default for the offset of dynamically
2567 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2568 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2570 #ifndef STACK_DYNAMIC_OFFSET
2572 #ifdef ACCUMULATE_OUTGOING_ARGS
2573 /* The bottom of the stack points to the actual arguments. If
2574 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2575 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2576 stack space for register parameters is not pushed by the caller, but
2577 rather part of the fixed stack areas and hence not included in
2578 `current_function_outgoing_args_size'. Nevertheless, we must allow
2579 for it when allocating stack dynamic objects. */
2581 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2582 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2583 (current_function_outgoing_args_size \
2584 + REG_PARM_STACK_SPACE (FNDECL) + (STACK_POINTER_OFFSET))
2587 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2588 (current_function_outgoing_args_size + (STACK_POINTER_OFFSET))
2592 #define STACK_DYNAMIC_OFFSET(FNDECL) STACK_POINTER_OFFSET
2596 /* On a few machines, the CFA coincides with the arg pointer. */
2598 #ifndef ARG_POINTER_CFA_OFFSET
2599 #define ARG_POINTER_CFA_OFFSET 0
2603 /* Build up a (MEM (ADDRESSOF (REG))) rtx for a register REG that just had
2604 its address taken. DECL is the decl for the object stored in the
2605 register, for later use if we do need to force REG into the stack.
2606 REG is overwritten by the MEM like in put_reg_into_stack. */
2609 gen_mem_addressof (reg, decl)
2613 tree type = TREE_TYPE (decl);
2614 rtx r = gen_rtx_ADDRESSOF (Pmode, gen_reg_rtx (GET_MODE (reg)),
2616 /* If the original REG was a user-variable, then so is the REG whose
2617 address is being taken. */
2618 REG_USERVAR_P (XEXP (r, 0)) = REG_USERVAR_P (reg);
2620 PUT_CODE (reg, MEM);
2621 PUT_MODE (reg, DECL_MODE (decl));
2623 MEM_VOLATILE_P (reg) = TREE_SIDE_EFFECTS (decl);
2624 MEM_SET_IN_STRUCT_P (reg, AGGREGATE_TYPE_P (type));
2625 MEM_ALIAS_SET (reg) = get_alias_set (decl);
2627 if (TREE_USED (decl) || DECL_INITIAL (decl) != 0)
2628 fixup_var_refs (reg, GET_MODE (reg), TREE_UNSIGNED (type), 0);
2633 /* If DECL has an RTL that is an ADDRESSOF rtx, put it into the stack. */
2636 flush_addressof (decl)
2639 if ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == VAR_DECL)
2640 && DECL_RTL (decl) != 0
2641 && GET_CODE (DECL_RTL (decl)) == MEM
2642 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF
2643 && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 0)) == REG)
2644 put_addressof_into_stack (XEXP (DECL_RTL (decl), 0), 0);
2647 /* Force the register pointed to by R, an ADDRESSOF rtx, into the stack. */
2650 put_addressof_into_stack (r, ht)
2652 struct hash_table *ht;
2654 tree decl = ADDRESSOF_DECL (r);
2655 rtx reg = XEXP (r, 0);
2657 if (GET_CODE (reg) != REG)
2660 put_reg_into_stack (0, reg, TREE_TYPE (decl), GET_MODE (reg),
2661 DECL_MODE (decl), TREE_SIDE_EFFECTS (decl),
2662 ADDRESSOF_REGNO (r),
2663 TREE_USED (decl) || DECL_INITIAL (decl) != 0, ht);
2666 /* List of replacements made below in purge_addressof_1 when creating
2667 bitfield insertions. */
2668 static rtx purge_bitfield_addressof_replacements;
2670 /* List of replacements made below in purge_addressof_1 for patterns
2671 (MEM (ADDRESSOF (REG ...))). The key of the list entry is the
2672 corresponding (ADDRESSOF (REG ...)) and value is a substitution for
2673 the all pattern. List PURGE_BITFIELD_ADDRESSOF_REPLACEMENTS is not
2674 enough in complex cases, e.g. when some field values can be
2675 extracted by usage MEM with narrower mode. */
2676 static rtx purge_addressof_replacements;
2678 /* Helper function for purge_addressof. See if the rtx expression at *LOC
2679 in INSN needs to be changed. If FORCE, always put any ADDRESSOFs into
2683 purge_addressof_1 (loc, insn, force, store, ht)
2687 struct hash_table *ht;
2694 /* Re-start here to avoid recursion in common cases. */
2701 code = GET_CODE (x);
2703 /* If we don't return in any of the cases below, we will recurse inside
2704 the RTX, which will normally result in any ADDRESSOF being forced into
2708 purge_addressof_1 (&SET_DEST (x), insn, force, 1, ht);
2709 purge_addressof_1 (&SET_SRC (x), insn, force, 0, ht);
2713 else if (code == ADDRESSOF && GET_CODE (XEXP (x, 0)) == MEM)
2715 /* We must create a copy of the rtx because it was created by
2716 overwriting a REG rtx which is always shared. */
2717 rtx sub = copy_rtx (XEXP (XEXP (x, 0), 0));
2720 if (validate_change (insn, loc, sub, 0)
2721 || validate_replace_rtx (x, sub, insn))
2725 sub = force_operand (sub, NULL_RTX);
2726 if (! validate_change (insn, loc, sub, 0)
2727 && ! validate_replace_rtx (x, sub, insn))
2730 insns = gen_sequence ();
2732 emit_insn_before (insns, insn);
2736 else if (code == MEM && GET_CODE (XEXP (x, 0)) == ADDRESSOF && ! force)
2738 rtx sub = XEXP (XEXP (x, 0), 0);
2741 if (GET_CODE (sub) == MEM)
2743 sub2 = gen_rtx_MEM (GET_MODE (x), copy_rtx (XEXP (sub, 0)));
2744 MEM_COPY_ATTRIBUTES (sub2, sub);
2745 RTX_UNCHANGING_P (sub2) = RTX_UNCHANGING_P (sub);
2748 else if (GET_CODE (sub) == REG
2749 && (MEM_VOLATILE_P (x) || GET_MODE (x) == BLKmode))
2751 else if (GET_CODE (sub) == REG && GET_MODE (x) != GET_MODE (sub))
2753 int size_x, size_sub;
2757 /* When processing REG_NOTES look at the list of
2758 replacements done on the insn to find the register that X
2762 for (tem = purge_bitfield_addressof_replacements;
2764 tem = XEXP (XEXP (tem, 1), 1))
2765 if (rtx_equal_p (x, XEXP (tem, 0)))
2767 *loc = XEXP (XEXP (tem, 1), 0);
2771 /* See comment for purge_addressof_replacements. */
2772 for (tem = purge_addressof_replacements;
2774 tem = XEXP (XEXP (tem, 1), 1))
2775 if (rtx_equal_p (XEXP (x, 0), XEXP (tem, 0)))
2777 rtx z = XEXP (XEXP (tem, 1), 0);
2779 if (GET_MODE (x) == GET_MODE (z)
2780 || (GET_CODE (XEXP (XEXP (tem, 1), 0)) != REG
2781 && GET_CODE (XEXP (XEXP (tem, 1), 0)) != SUBREG))
2784 /* It can happen that the note may speak of things
2785 in a wider (or just different) mode than the
2786 code did. This is especially true of
2789 if (GET_CODE (z) == SUBREG && SUBREG_WORD (z) == 0)
2792 if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD
2793 && (GET_MODE_SIZE (GET_MODE (x))
2794 > GET_MODE_SIZE (GET_MODE (z))))
2796 /* This can occur as a result in invalid
2797 pointer casts, e.g. float f; ...
2798 *(long long int *)&f.
2799 ??? We could emit a warning here, but
2800 without a line number that wouldn't be
2802 z = gen_rtx_SUBREG (GET_MODE (x), z, 0);
2805 z = gen_lowpart (GET_MODE (x), z);
2811 /* There should always be such a replacement. */
2815 size_x = GET_MODE_BITSIZE (GET_MODE (x));
2816 size_sub = GET_MODE_BITSIZE (GET_MODE (sub));
2818 /* Don't even consider working with paradoxical subregs,
2819 or the moral equivalent seen here. */
2820 if (size_x <= size_sub
2821 && int_mode_for_mode (GET_MODE (sub)) != BLKmode)
2823 /* Do a bitfield insertion to mirror what would happen
2830 rtx p = PREV_INSN (insn);
2833 val = gen_reg_rtx (GET_MODE (x));
2834 if (! validate_change (insn, loc, val, 0))
2836 /* Discard the current sequence and put the
2837 ADDRESSOF on stack. */
2841 seq = gen_sequence ();
2843 emit_insn_before (seq, insn);
2844 compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (),
2848 store_bit_field (sub, size_x, 0, GET_MODE (x),
2849 val, GET_MODE_SIZE (GET_MODE (sub)),
2850 GET_MODE_SIZE (GET_MODE (sub)));
2852 /* Make sure to unshare any shared rtl that store_bit_field
2853 might have created. */
2854 for (p = get_insns(); p; p = NEXT_INSN (p))
2856 reset_used_flags (PATTERN (p));
2857 reset_used_flags (REG_NOTES (p));
2858 reset_used_flags (LOG_LINKS (p));
2860 unshare_all_rtl (get_insns ());
2862 seq = gen_sequence ();
2864 p = emit_insn_after (seq, insn);
2865 if (NEXT_INSN (insn))
2866 compute_insns_for_mem (NEXT_INSN (insn),
2867 p ? NEXT_INSN (p) : NULL_RTX,
2872 rtx p = PREV_INSN (insn);
2875 val = extract_bit_field (sub, size_x, 0, 1, NULL_RTX,
2876 GET_MODE (x), GET_MODE (x),
2877 GET_MODE_SIZE (GET_MODE (sub)),
2878 GET_MODE_SIZE (GET_MODE (sub)));
2880 if (! validate_change (insn, loc, val, 0))
2882 /* Discard the current sequence and put the
2883 ADDRESSOF on stack. */
2888 seq = gen_sequence ();
2890 emit_insn_before (seq, insn);
2891 compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (),
2895 /* Remember the replacement so that the same one can be done
2896 on the REG_NOTES. */
2897 purge_bitfield_addressof_replacements
2898 = gen_rtx_EXPR_LIST (VOIDmode, x,
2901 purge_bitfield_addressof_replacements));
2903 /* We replaced with a reg -- all done. */
2908 else if (validate_change (insn, loc, sub, 0))
2910 /* Remember the replacement so that the same one can be done
2911 on the REG_NOTES. */
2912 if (GET_CODE (sub) == REG || GET_CODE (sub) == SUBREG)
2916 for (tem = purge_addressof_replacements;
2918 tem = XEXP (XEXP (tem, 1), 1))
2919 if (rtx_equal_p (XEXP (x, 0), XEXP (tem, 0)))
2921 XEXP (XEXP (tem, 1), 0) = sub;
2924 purge_addressof_replacements
2925 = gen_rtx (EXPR_LIST, VOIDmode, XEXP (x, 0),
2926 gen_rtx_EXPR_LIST (VOIDmode, sub,
2927 purge_addressof_replacements));
2933 /* else give up and put it into the stack */
2936 else if (code == ADDRESSOF)
2938 put_addressof_into_stack (x, ht);
2941 else if (code == SET)
2943 purge_addressof_1 (&SET_DEST (x), insn, force, 1, ht);
2944 purge_addressof_1 (&SET_SRC (x), insn, force, 0, ht);
2948 /* Scan all subexpressions. */
2949 fmt = GET_RTX_FORMAT (code);
2950 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
2953 purge_addressof_1 (&XEXP (x, i), insn, force, 0, ht);
2954 else if (*fmt == 'E')
2955 for (j = 0; j < XVECLEN (x, i); j++)
2956 purge_addressof_1 (&XVECEXP (x, i, j), insn, force, 0, ht);
2960 /* Return a new hash table entry in HT. */
2962 static struct hash_entry *
2963 insns_for_mem_newfunc (he, ht, k)
2964 struct hash_entry *he;
2965 struct hash_table *ht;
2966 hash_table_key k ATTRIBUTE_UNUSED;
2968 struct insns_for_mem_entry *ifmhe;
2972 ifmhe = ((struct insns_for_mem_entry *)
2973 hash_allocate (ht, sizeof (struct insns_for_mem_entry)));
2974 ifmhe->insns = NULL_RTX;
2979 /* Return a hash value for K, a REG. */
2981 static unsigned long
2982 insns_for_mem_hash (k)
2985 /* K is really a RTX. Just use the address as the hash value. */
2986 return (unsigned long) k;
2989 /* Return non-zero if K1 and K2 (two REGs) are the same. */
2992 insns_for_mem_comp (k1, k2)
2999 struct insns_for_mem_walk_info {
3000 /* The hash table that we are using to record which INSNs use which
3002 struct hash_table *ht;
3004 /* The INSN we are currently proessing. */
3007 /* Zero if we are walking to find ADDRESSOFs, one if we are walking
3008 to find the insns that use the REGs in the ADDRESSOFs. */
3012 /* Called from compute_insns_for_mem via for_each_rtx. If R is a REG
3013 that might be used in an ADDRESSOF expression, record this INSN in
3014 the hash table given by DATA (which is really a pointer to an
3015 insns_for_mem_walk_info structure). */
3018 insns_for_mem_walk (r, data)
3022 struct insns_for_mem_walk_info *ifmwi
3023 = (struct insns_for_mem_walk_info *) data;
3025 if (ifmwi->pass == 0 && *r && GET_CODE (*r) == ADDRESSOF
3026 && GET_CODE (XEXP (*r, 0)) == REG)
3027 hash_lookup (ifmwi->ht, XEXP (*r, 0), /*create=*/1, /*copy=*/0);
3028 else if (ifmwi->pass == 1 && *r && GET_CODE (*r) == REG)
3030 /* Lookup this MEM in the hashtable, creating it if necessary. */
3031 struct insns_for_mem_entry *ifme
3032 = (struct insns_for_mem_entry *) hash_lookup (ifmwi->ht,
3037 /* If we have not already recorded this INSN, do so now. Since
3038 we process the INSNs in order, we know that if we have
3039 recorded it it must be at the front of the list. */
3040 if (ifme && (!ifme->insns || XEXP (ifme->insns, 0) != ifmwi->insn))
3042 /* We do the allocation on the same obstack as is used for
3043 the hash table since this memory will not be used once
3044 the hash table is deallocated. */
3045 push_obstacks (&ifmwi->ht->memory, &ifmwi->ht->memory);
3046 ifme->insns = gen_rtx_EXPR_LIST (VOIDmode, ifmwi->insn,
3055 /* Walk the INSNS, until we reach LAST_INSN, recording which INSNs use
3056 which REGs in HT. */
3059 compute_insns_for_mem (insns, last_insn, ht)
3062 struct hash_table *ht;
3065 struct insns_for_mem_walk_info ifmwi;
3068 for (ifmwi.pass = 0; ifmwi.pass < 2; ++ifmwi.pass)
3069 for (insn = insns; insn != last_insn; insn = NEXT_INSN (insn))
3070 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3073 for_each_rtx (&insn, insns_for_mem_walk, &ifmwi);
3077 /* Eliminate all occurrences of ADDRESSOF from INSNS. Elide any remaining
3078 (MEM (ADDRESSOF)) patterns, and force any needed registers into the
3082 purge_addressof (insns)
3086 struct hash_table ht;
3088 /* When we actually purge ADDRESSOFs, we turn REGs into MEMs. That
3089 requires a fixup pass over the instruction stream to correct
3090 INSNs that depended on the REG being a REG, and not a MEM. But,
3091 these fixup passes are slow. Furthermore, more MEMs are not
3092 mentioned in very many instructions. So, we speed up the process
3093 by pre-calculating which REGs occur in which INSNs; that allows
3094 us to perform the fixup passes much more quickly. */
3095 hash_table_init (&ht,
3096 insns_for_mem_newfunc,
3098 insns_for_mem_comp);
3099 compute_insns_for_mem (insns, NULL_RTX, &ht);
3101 for (insn = insns; insn; insn = NEXT_INSN (insn))
3102 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
3103 || GET_CODE (insn) == CALL_INSN)
3105 purge_addressof_1 (&PATTERN (insn), insn,
3106 asm_noperands (PATTERN (insn)) > 0, 0, &ht);
3107 purge_addressof_1 (®_NOTES (insn), NULL_RTX, 0, 0, &ht);
3111 hash_table_free (&ht);
3112 purge_bitfield_addressof_replacements = 0;
3113 purge_addressof_replacements = 0;
3116 /* Pass through the INSNS of function FNDECL and convert virtual register
3117 references to hard register references. */
3120 instantiate_virtual_regs (fndecl, insns)
3127 /* Compute the offsets to use for this function. */
3128 in_arg_offset = FIRST_PARM_OFFSET (fndecl);
3129 var_offset = STARTING_FRAME_OFFSET;
3130 dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl);
3131 out_arg_offset = STACK_POINTER_OFFSET;
3132 cfa_offset = ARG_POINTER_CFA_OFFSET;
3134 /* Scan all variables and parameters of this function. For each that is
3135 in memory, instantiate all virtual registers if the result is a valid
3136 address. If not, we do it later. That will handle most uses of virtual
3137 regs on many machines. */
3138 instantiate_decls (fndecl, 1);
3140 /* Initialize recognition, indicating that volatile is OK. */
3143 /* Scan through all the insns, instantiating every virtual register still
3145 for (insn = insns; insn; insn = NEXT_INSN (insn))
3146 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
3147 || GET_CODE (insn) == CALL_INSN)
3149 instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1);
3150 instantiate_virtual_regs_1 (®_NOTES (insn), NULL_RTX, 0);
3153 /* Instantiate the stack slots for the parm registers, for later use in
3154 addressof elimination. */
3155 for (i = 0; i < max_parm_reg; ++i)
3156 if (parm_reg_stack_loc[i])
3157 instantiate_virtual_regs_1 (&parm_reg_stack_loc[i], NULL_RTX, 0);
3159 /* Now instantiate the remaining register equivalences for debugging info.
3160 These will not be valid addresses. */
3161 instantiate_decls (fndecl, 0);
3163 /* Indicate that, from now on, assign_stack_local should use
3164 frame_pointer_rtx. */
3165 virtuals_instantiated = 1;
3168 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
3169 all virtual registers in their DECL_RTL's.
3171 If VALID_ONLY, do this only if the resulting address is still valid.
3172 Otherwise, always do it. */
3175 instantiate_decls (fndecl, valid_only)
3181 if (DECL_SAVED_INSNS (fndecl))
3182 /* When compiling an inline function, the obstack used for
3183 rtl allocation is the maybepermanent_obstack. Calling
3184 `resume_temporary_allocation' switches us back to that
3185 obstack while we process this function's parameters. */
3186 resume_temporary_allocation ();
3188 /* Process all parameters of the function. */
3189 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
3191 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
3193 instantiate_decl (DECL_RTL (decl), size, valid_only);
3195 /* If the parameter was promoted, then the incoming RTL mode may be
3196 larger than the declared type size. We must use the larger of
3198 size = MAX (GET_MODE_SIZE (GET_MODE (DECL_INCOMING_RTL (decl))), size);
3199 instantiate_decl (DECL_INCOMING_RTL (decl), size, valid_only);
3202 /* Now process all variables defined in the function or its subblocks. */
3203 instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only);
3205 if (DECL_INLINE (fndecl) || DECL_DEFER_OUTPUT (fndecl))
3207 /* Save all rtl allocated for this function by raising the
3208 high-water mark on the maybepermanent_obstack. */
3210 /* All further rtl allocation is now done in the current_obstack. */
3211 rtl_in_current_obstack ();
3215 /* Subroutine of instantiate_decls: Process all decls in the given
3216 BLOCK node and all its subblocks. */
3219 instantiate_decls_1 (let, valid_only)
3225 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
3226 instantiate_decl (DECL_RTL (t), int_size_in_bytes (TREE_TYPE (t)),
3229 /* Process all subblocks. */
3230 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
3231 instantiate_decls_1 (t, valid_only);
3234 /* Subroutine of the preceding procedures: Given RTL representing a
3235 decl and the size of the object, do any instantiation required.
3237 If VALID_ONLY is non-zero, it means that the RTL should only be
3238 changed if the new address is valid. */
3241 instantiate_decl (x, size, valid_only)
3246 enum machine_mode mode;
3249 /* If this is not a MEM, no need to do anything. Similarly if the
3250 address is a constant or a register that is not a virtual register. */
3252 if (x == 0 || GET_CODE (x) != MEM)
3256 if (CONSTANT_P (addr)
3257 || (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == REG)
3258 || (GET_CODE (addr) == REG
3259 && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
3260 || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
3263 /* If we should only do this if the address is valid, copy the address.
3264 We need to do this so we can undo any changes that might make the
3265 address invalid. This copy is unfortunate, but probably can't be
3269 addr = copy_rtx (addr);
3271 instantiate_virtual_regs_1 (&addr, NULL_RTX, 0);
3275 /* Now verify that the resulting address is valid for every integer or
3276 floating-point mode up to and including SIZE bytes long. We do this
3277 since the object might be accessed in any mode and frame addresses
3280 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
3281 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
3282 mode = GET_MODE_WIDER_MODE (mode))
3283 if (! memory_address_p (mode, addr))
3286 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
3287 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
3288 mode = GET_MODE_WIDER_MODE (mode))
3289 if (! memory_address_p (mode, addr))
3293 /* Put back the address now that we have updated it and we either know
3294 it is valid or we don't care whether it is valid. */
3299 /* Given a pointer to a piece of rtx and an optional pointer to the
3300 containing object, instantiate any virtual registers present in it.
3302 If EXTRA_INSNS, we always do the replacement and generate
3303 any extra insns before OBJECT. If it zero, we do nothing if replacement
3306 Return 1 if we either had nothing to do or if we were able to do the
3307 needed replacement. Return 0 otherwise; we only return zero if
3308 EXTRA_INSNS is zero.
3310 We first try some simple transformations to avoid the creation of extra
3314 instantiate_virtual_regs_1 (loc, object, extra_insns)
3322 HOST_WIDE_INT offset = 0;
3328 /* Re-start here to avoid recursion in common cases. */
3335 code = GET_CODE (x);
3337 /* Check for some special cases. */
3354 /* We are allowed to set the virtual registers. This means that
3355 the actual register should receive the source minus the
3356 appropriate offset. This is used, for example, in the handling
3357 of non-local gotos. */
3358 if (SET_DEST (x) == virtual_incoming_args_rtx)
3359 new = arg_pointer_rtx, offset = - in_arg_offset;
3360 else if (SET_DEST (x) == virtual_stack_vars_rtx)
3361 new = frame_pointer_rtx, offset = - var_offset;
3362 else if (SET_DEST (x) == virtual_stack_dynamic_rtx)
3363 new = stack_pointer_rtx, offset = - dynamic_offset;
3364 else if (SET_DEST (x) == virtual_outgoing_args_rtx)
3365 new = stack_pointer_rtx, offset = - out_arg_offset;
3366 else if (SET_DEST (x) == virtual_cfa_rtx)
3367 new = arg_pointer_rtx, offset = - cfa_offset;
3371 /* The only valid sources here are PLUS or REG. Just do
3372 the simplest possible thing to handle them. */
3373 if (GET_CODE (SET_SRC (x)) != REG
3374 && GET_CODE (SET_SRC (x)) != PLUS)
3378 if (GET_CODE (SET_SRC (x)) != REG)
3379 temp = force_operand (SET_SRC (x), NULL_RTX);
3382 temp = force_operand (plus_constant (temp, offset), NULL_RTX);
3386 emit_insns_before (seq, object);
3389 if (! validate_change (object, &SET_SRC (x), temp, 0)
3396 instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns);
3401 /* Handle special case of virtual register plus constant. */
3402 if (CONSTANT_P (XEXP (x, 1)))
3404 rtx old, new_offset;
3406 /* Check for (plus (plus VIRT foo) (const_int)) first. */
3407 if (GET_CODE (XEXP (x, 0)) == PLUS)
3409 rtx inner = XEXP (XEXP (x, 0), 0);
3411 if (inner == virtual_incoming_args_rtx)
3412 new = arg_pointer_rtx, offset = in_arg_offset;
3413 else if (inner == virtual_stack_vars_rtx)
3414 new = frame_pointer_rtx, offset = var_offset;
3415 else if (inner == virtual_stack_dynamic_rtx)
3416 new = stack_pointer_rtx, offset = dynamic_offset;
3417 else if (inner == virtual_outgoing_args_rtx)
3418 new = stack_pointer_rtx, offset = out_arg_offset;
3419 else if (inner == virtual_cfa_rtx)
3420 new = arg_pointer_rtx, offset = cfa_offset;
3427 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object,
3429 new = gen_rtx_PLUS (Pmode, new, XEXP (XEXP (x, 0), 1));
3432 else if (XEXP (x, 0) == virtual_incoming_args_rtx)
3433 new = arg_pointer_rtx, offset = in_arg_offset;
3434 else if (XEXP (x, 0) == virtual_stack_vars_rtx)
3435 new = frame_pointer_rtx, offset = var_offset;
3436 else if (XEXP (x, 0) == virtual_stack_dynamic_rtx)
3437 new = stack_pointer_rtx, offset = dynamic_offset;
3438 else if (XEXP (x, 0) == virtual_outgoing_args_rtx)
3439 new = stack_pointer_rtx, offset = out_arg_offset;
3440 else if (XEXP (x, 0) == virtual_cfa_rtx)
3441 new = arg_pointer_rtx, offset = cfa_offset;
3444 /* We know the second operand is a constant. Unless the
3445 first operand is a REG (which has been already checked),
3446 it needs to be checked. */
3447 if (GET_CODE (XEXP (x, 0)) != REG)
3455 new_offset = plus_constant (XEXP (x, 1), offset);
3457 /* If the new constant is zero, try to replace the sum with just
3459 if (new_offset == const0_rtx
3460 && validate_change (object, loc, new, 0))
3463 /* Next try to replace the register and new offset.
3464 There are two changes to validate here and we can't assume that
3465 in the case of old offset equals new just changing the register
3466 will yield a valid insn. In the interests of a little efficiency,
3467 however, we only call validate change once (we don't queue up the
3468 changes and then call apply_change_group). */
3472 ? ! validate_change (object, &XEXP (x, 0), new, 0)
3473 : (XEXP (x, 0) = new,
3474 ! validate_change (object, &XEXP (x, 1), new_offset, 0)))
3482 /* Otherwise copy the new constant into a register and replace
3483 constant with that register. */
3484 temp = gen_reg_rtx (Pmode);
3486 if (validate_change (object, &XEXP (x, 1), temp, 0))
3487 emit_insn_before (gen_move_insn (temp, new_offset), object);
3490 /* If that didn't work, replace this expression with a
3491 register containing the sum. */
3494 new = gen_rtx_PLUS (Pmode, new, new_offset);
3497 temp = force_operand (new, NULL_RTX);
3501 emit_insns_before (seq, object);
3502 if (! validate_change (object, loc, temp, 0)
3503 && ! validate_replace_rtx (x, temp, object))
3511 /* Fall through to generic two-operand expression case. */
3517 case DIV: case UDIV:
3518 case MOD: case UMOD:
3519 case AND: case IOR: case XOR:
3520 case ROTATERT: case ROTATE:
3521 case ASHIFTRT: case LSHIFTRT: case ASHIFT:
3523 case GE: case GT: case GEU: case GTU:
3524 case LE: case LT: case LEU: case LTU:
3525 if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1)))
3526 instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns);
3531 /* Most cases of MEM that convert to valid addresses have already been
3532 handled by our scan of decls. The only special handling we
3533 need here is to make a copy of the rtx to ensure it isn't being
3534 shared if we have to change it to a pseudo.
3536 If the rtx is a simple reference to an address via a virtual register,
3537 it can potentially be shared. In such cases, first try to make it
3538 a valid address, which can also be shared. Otherwise, copy it and
3541 First check for common cases that need no processing. These are
3542 usually due to instantiation already being done on a previous instance
3546 if (CONSTANT_ADDRESS_P (temp)
3547 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3548 || temp == arg_pointer_rtx
3550 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3551 || temp == hard_frame_pointer_rtx
3553 || temp == frame_pointer_rtx)
3556 if (GET_CODE (temp) == PLUS
3557 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
3558 && (XEXP (temp, 0) == frame_pointer_rtx
3559 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3560 || XEXP (temp, 0) == hard_frame_pointer_rtx
3562 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3563 || XEXP (temp, 0) == arg_pointer_rtx
3568 if (temp == virtual_stack_vars_rtx
3569 || temp == virtual_incoming_args_rtx
3570 || (GET_CODE (temp) == PLUS
3571 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
3572 && (XEXP (temp, 0) == virtual_stack_vars_rtx
3573 || XEXP (temp, 0) == virtual_incoming_args_rtx)))
3575 /* This MEM may be shared. If the substitution can be done without
3576 the need to generate new pseudos, we want to do it in place
3577 so all copies of the shared rtx benefit. The call below will
3578 only make substitutions if the resulting address is still
3581 Note that we cannot pass X as the object in the recursive call
3582 since the insn being processed may not allow all valid
3583 addresses. However, if we were not passed on object, we can
3584 only modify X without copying it if X will have a valid
3587 ??? Also note that this can still lose if OBJECT is an insn that
3588 has less restrictions on an address that some other insn.
3589 In that case, we will modify the shared address. This case
3590 doesn't seem very likely, though. One case where this could
3591 happen is in the case of a USE or CLOBBER reference, but we
3592 take care of that below. */
3594 if (instantiate_virtual_regs_1 (&XEXP (x, 0),
3595 object ? object : x, 0))
3598 /* Otherwise make a copy and process that copy. We copy the entire
3599 RTL expression since it might be a PLUS which could also be
3601 *loc = x = copy_rtx (x);
3604 /* Fall through to generic unary operation case. */
3606 case STRICT_LOW_PART:
3608 case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC:
3609 case SIGN_EXTEND: case ZERO_EXTEND:
3610 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE:
3611 case FLOAT: case FIX:
3612 case UNSIGNED_FIX: case UNSIGNED_FLOAT:
3616 /* These case either have just one operand or we know that we need not
3617 check the rest of the operands. */
3623 /* If the operand is a MEM, see if the change is a valid MEM. If not,
3624 go ahead and make the invalid one, but do it to a copy. For a REG,
3625 just make the recursive call, since there's no chance of a problem. */
3627 if ((GET_CODE (XEXP (x, 0)) == MEM
3628 && instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), XEXP (x, 0),
3630 || (GET_CODE (XEXP (x, 0)) == REG
3631 && instantiate_virtual_regs_1 (&XEXP (x, 0), object, 0)))
3634 XEXP (x, 0) = copy_rtx (XEXP (x, 0));
3639 /* Try to replace with a PLUS. If that doesn't work, compute the sum
3640 in front of this insn and substitute the temporary. */
3641 if (x == virtual_incoming_args_rtx)
3642 new = arg_pointer_rtx, offset = in_arg_offset;
3643 else if (x == virtual_stack_vars_rtx)
3644 new = frame_pointer_rtx, offset = var_offset;
3645 else if (x == virtual_stack_dynamic_rtx)
3646 new = stack_pointer_rtx, offset = dynamic_offset;
3647 else if (x == virtual_outgoing_args_rtx)
3648 new = stack_pointer_rtx, offset = out_arg_offset;
3649 else if (x == virtual_cfa_rtx)
3650 new = arg_pointer_rtx, offset = cfa_offset;
3654 temp = plus_constant (new, offset);
3655 if (!validate_change (object, loc, temp, 0))
3661 temp = force_operand (temp, NULL_RTX);
3665 emit_insns_before (seq, object);
3666 if (! validate_change (object, loc, temp, 0)
3667 && ! validate_replace_rtx (x, temp, object))
3675 if (GET_CODE (XEXP (x, 0)) == REG)
3678 else if (GET_CODE (XEXP (x, 0)) == MEM)
3680 /* If we have a (addressof (mem ..)), do any instantiation inside
3681 since we know we'll be making the inside valid when we finally
3682 remove the ADDRESSOF. */
3683 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), NULL_RTX, 0);
3692 /* Scan all subexpressions. */
3693 fmt = GET_RTX_FORMAT (code);
3694 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
3697 if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns))
3700 else if (*fmt == 'E')
3701 for (j = 0; j < XVECLEN (x, i); j++)
3702 if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object,
3709 /* Optimization: assuming this function does not receive nonlocal gotos,
3710 delete the handlers for such, as well as the insns to establish
3711 and disestablish them. */
3717 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3719 /* Delete the handler by turning off the flag that would
3720 prevent jump_optimize from deleting it.
3721 Also permit deletion of the nonlocal labels themselves
3722 if nothing local refers to them. */
3723 if (GET_CODE (insn) == CODE_LABEL)
3727 LABEL_PRESERVE_P (insn) = 0;
3729 /* Remove it from the nonlocal_label list, to avoid confusing
3731 for (t = nonlocal_labels, last_t = 0; t;
3732 last_t = t, t = TREE_CHAIN (t))
3733 if (DECL_RTL (TREE_VALUE (t)) == insn)
3738 nonlocal_labels = TREE_CHAIN (nonlocal_labels);
3740 TREE_CHAIN (last_t) = TREE_CHAIN (t);
3743 if (GET_CODE (insn) == INSN)
3747 for (t = nonlocal_goto_handler_slots; t != 0; t = XEXP (t, 1))
3748 if (reg_mentioned_p (t, PATTERN (insn)))
3754 || (nonlocal_goto_stack_level != 0
3755 && reg_mentioned_p (nonlocal_goto_stack_level,
3762 /* Output a USE for any register use in RTL.
3763 This is used with -noreg to mark the extent of lifespan
3764 of any registers used in a user-visible variable's DECL_RTL. */
3770 if (GET_CODE (rtl) == REG)
3771 /* This is a register variable. */
3772 emit_insn (gen_rtx_USE (VOIDmode, rtl));
3773 else if (GET_CODE (rtl) == MEM
3774 && GET_CODE (XEXP (rtl, 0)) == REG
3775 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
3776 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
3777 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
3778 /* This is a variable-sized structure. */
3779 emit_insn (gen_rtx_USE (VOIDmode, XEXP (rtl, 0)));
3782 /* Like use_variable except that it outputs the USEs after INSN
3783 instead of at the end of the insn-chain. */
3786 use_variable_after (rtl, insn)
3789 if (GET_CODE (rtl) == REG)
3790 /* This is a register variable. */
3791 emit_insn_after (gen_rtx_USE (VOIDmode, rtl), insn);
3792 else if (GET_CODE (rtl) == MEM
3793 && GET_CODE (XEXP (rtl, 0)) == REG
3794 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
3795 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
3796 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
3797 /* This is a variable-sized structure. */
3798 emit_insn_after (gen_rtx_USE (VOIDmode, XEXP (rtl, 0)), insn);
3804 return max_parm_reg;
3807 /* Return the first insn following those generated by `assign_parms'. */
3810 get_first_nonparm_insn ()
3813 return NEXT_INSN (last_parm_insn);
3814 return get_insns ();
3817 /* Return the first NOTE_INSN_BLOCK_BEG note in the function.
3818 Crash if there is none. */
3821 get_first_block_beg ()
3823 register rtx searcher;
3824 register rtx insn = get_first_nonparm_insn ();
3826 for (searcher = insn; searcher; searcher = NEXT_INSN (searcher))
3827 if (GET_CODE (searcher) == NOTE
3828 && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG)
3831 abort (); /* Invalid call to this function. (See comments above.) */
3835 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
3836 This means a type for which function calls must pass an address to the
3837 function or get an address back from the function.
3838 EXP may be a type node or an expression (whose type is tested). */
3841 aggregate_value_p (exp)
3844 int i, regno, nregs;
3847 if (TREE_CODE_CLASS (TREE_CODE (exp)) == 't')
3850 type = TREE_TYPE (exp);
3852 if (RETURN_IN_MEMORY (type))
3854 /* Types that are TREE_ADDRESSABLE must be constructed in memory,
3855 and thus can't be returned in registers. */
3856 if (TREE_ADDRESSABLE (type))
3858 if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
3860 /* Make sure we have suitable call-clobbered regs to return
3861 the value in; if not, we must return it in memory. */
3862 reg = hard_function_value (type, 0);
3864 /* If we have something other than a REG (e.g. a PARALLEL), then assume
3866 if (GET_CODE (reg) != REG)
3869 regno = REGNO (reg);
3870 nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type));
3871 for (i = 0; i < nregs; i++)
3872 if (! call_used_regs[regno + i])
3877 /* Assign RTL expressions to the function's parameters.
3878 This may involve copying them into registers and using
3879 those registers as the RTL for them.
3881 If SECOND_TIME is non-zero it means that this function is being
3882 called a second time. This is done by integrate.c when a function's
3883 compilation is deferred. We need to come back here in case the
3884 FUNCTION_ARG macro computes items needed for the rest of the compilation
3885 (such as changing which registers are fixed or caller-saved). But suppress
3886 writing any insns or setting DECL_RTL of anything in this case. */
3889 assign_parms (fndecl, second_time)
3894 register rtx entry_parm = 0;
3895 register rtx stack_parm = 0;
3896 CUMULATIVE_ARGS args_so_far;
3897 enum machine_mode promoted_mode, passed_mode;
3898 enum machine_mode nominal_mode, promoted_nominal_mode;
3900 /* Total space needed so far for args on the stack,
3901 given as a constant and a tree-expression. */
3902 struct args_size stack_args_size;
3903 tree fntype = TREE_TYPE (fndecl);
3904 tree fnargs = DECL_ARGUMENTS (fndecl);
3905 /* This is used for the arg pointer when referring to stack args. */
3906 rtx internal_arg_pointer;
3907 /* This is a dummy PARM_DECL that we used for the function result if
3908 the function returns a structure. */
3909 tree function_result_decl = 0;
3910 #ifdef SETUP_INCOMING_VARARGS
3911 int varargs_setup = 0;
3913 rtx conversion_insns = 0;
3915 /* Nonzero if the last arg is named `__builtin_va_alist',
3916 which is used on some machines for old-fashioned non-ANSI varargs.h;
3917 this should be stuck onto the stack as if it had arrived there. */
3919 = (current_function_varargs
3921 && (parm = tree_last (fnargs)) != 0
3923 && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
3924 "__builtin_va_alist")));
3926 /* Nonzero if function takes extra anonymous args.
3927 This means the last named arg must be on the stack
3928 right before the anonymous ones. */
3930 = (TYPE_ARG_TYPES (fntype) != 0
3931 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3932 != void_type_node));
3934 current_function_stdarg = stdarg;
3936 /* If the reg that the virtual arg pointer will be translated into is
3937 not a fixed reg or is the stack pointer, make a copy of the virtual
3938 arg pointer, and address parms via the copy. The frame pointer is
3939 considered fixed even though it is not marked as such.
3941 The second time through, simply use ap to avoid generating rtx. */
3943 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
3944 || ! (fixed_regs[ARG_POINTER_REGNUM]
3945 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM))
3947 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
3949 internal_arg_pointer = virtual_incoming_args_rtx;
3950 current_function_internal_arg_pointer = internal_arg_pointer;
3952 stack_args_size.constant = 0;
3953 stack_args_size.var = 0;
3955 /* If struct value address is treated as the first argument, make it so. */
3956 if (aggregate_value_p (DECL_RESULT (fndecl))
3957 && ! current_function_returns_pcc_struct
3958 && struct_value_incoming_rtx == 0)
3960 tree type = build_pointer_type (TREE_TYPE (fntype));
3962 function_result_decl = build_decl (PARM_DECL, NULL_TREE, type);
3964 DECL_ARG_TYPE (function_result_decl) = type;
3965 TREE_CHAIN (function_result_decl) = fnargs;
3966 fnargs = function_result_decl;
3969 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
3970 parm_reg_stack_loc = (rtx *) xcalloc (max_parm_reg, sizeof (rtx));
3972 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
3973 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX);
3975 INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX, 0);
3978 /* We haven't yet found an argument that we must push and pretend the
3980 current_function_pretend_args_size = 0;
3982 for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
3984 int aggregate = AGGREGATE_TYPE_P (TREE_TYPE (parm));
3985 struct args_size stack_offset;
3986 struct args_size arg_size;
3987 int passed_pointer = 0;
3988 int did_conversion = 0;
3989 tree passed_type = DECL_ARG_TYPE (parm);
3990 tree nominal_type = TREE_TYPE (parm);
3993 /* Set LAST_NAMED if this is last named arg before some
3995 int last_named = ((TREE_CHAIN (parm) == 0
3996 || DECL_NAME (TREE_CHAIN (parm)) == 0)
3997 && (stdarg || current_function_varargs));
3998 /* Set NAMED_ARG if this arg should be treated as a named arg. For
3999 most machines, if this is a varargs/stdarg function, then we treat
4000 the last named arg as if it were anonymous too. */
4001 int named_arg = STRICT_ARGUMENT_NAMING ? 1 : ! last_named;
4003 if (TREE_TYPE (parm) == error_mark_node
4004 /* This can happen after weird syntax errors
4005 or if an enum type is defined among the parms. */
4006 || TREE_CODE (parm) != PARM_DECL
4007 || passed_type == NULL)
4009 DECL_INCOMING_RTL (parm) = DECL_RTL (parm)
4010 = gen_rtx_MEM (BLKmode, const0_rtx);
4011 TREE_USED (parm) = 1;
4015 /* For varargs.h function, save info about regs and stack space
4016 used by the individual args, not including the va_alist arg. */
4017 if (hide_last_arg && last_named)
4018 current_function_args_info = args_so_far;
4020 /* Find mode of arg as it is passed, and mode of arg
4021 as it should be during execution of this function. */
4022 passed_mode = TYPE_MODE (passed_type);
4023 nominal_mode = TYPE_MODE (nominal_type);
4025 /* If the parm's mode is VOID, its value doesn't matter,
4026 and avoid the usual things like emit_move_insn that could crash. */
4027 if (nominal_mode == VOIDmode)
4029 DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = const0_rtx;
4033 /* If the parm is to be passed as a transparent union, use the
4034 type of the first field for the tests below. We have already
4035 verified that the modes are the same. */
4036 if (DECL_TRANSPARENT_UNION (parm)
4037 || TYPE_TRANSPARENT_UNION (passed_type))
4038 passed_type = TREE_TYPE (TYPE_FIELDS (passed_type));
4040 /* See if this arg was passed by invisible reference. It is if
4041 it is an object whose size depends on the contents of the
4042 object itself or if the machine requires these objects be passed
4045 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
4046 && contains_placeholder_p (TYPE_SIZE (passed_type)))
4047 || TREE_ADDRESSABLE (passed_type)
4048 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
4049 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode,
4050 passed_type, named_arg)
4054 passed_type = nominal_type = build_pointer_type (passed_type);
4056 passed_mode = nominal_mode = Pmode;
4059 promoted_mode = passed_mode;
4061 #ifdef PROMOTE_FUNCTION_ARGS
4062 /* Compute the mode in which the arg is actually extended to. */
4063 unsignedp = TREE_UNSIGNED (passed_type);
4064 promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1);
4067 /* Let machine desc say which reg (if any) the parm arrives in.
4068 0 means it arrives on the stack. */
4069 #ifdef FUNCTION_INCOMING_ARG
4070 entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
4071 passed_type, named_arg);
4073 entry_parm = FUNCTION_ARG (args_so_far, promoted_mode,
4074 passed_type, named_arg);
4077 if (entry_parm == 0)
4078 promoted_mode = passed_mode;
4080 #ifdef SETUP_INCOMING_VARARGS
4081 /* If this is the last named parameter, do any required setup for
4082 varargs or stdargs. We need to know about the case of this being an
4083 addressable type, in which case we skip the registers it
4084 would have arrived in.
4086 For stdargs, LAST_NAMED will be set for two parameters, the one that
4087 is actually the last named, and the dummy parameter. We only
4088 want to do this action once.
4090 Also, indicate when RTL generation is to be suppressed. */
4091 if (last_named && !varargs_setup)
4093 SETUP_INCOMING_VARARGS (args_so_far, promoted_mode, passed_type,
4094 current_function_pretend_args_size,
4100 /* Determine parm's home in the stack,
4101 in case it arrives in the stack or we should pretend it did.
4103 Compute the stack position and rtx where the argument arrives
4106 There is one complexity here: If this was a parameter that would
4107 have been passed in registers, but wasn't only because it is
4108 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
4109 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
4110 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
4111 0 as it was the previous time. */
4113 pretend_named = named_arg || PRETEND_OUTGOING_VARARGS_NAMED;
4114 locate_and_pad_parm (promoted_mode, passed_type,
4115 #ifdef STACK_PARMS_IN_REG_PARM_AREA
4118 #ifdef FUNCTION_INCOMING_ARG
4119 FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
4121 pretend_named) != 0,
4123 FUNCTION_ARG (args_so_far, promoted_mode,
4125 pretend_named) != 0,
4128 fndecl, &stack_args_size, &stack_offset, &arg_size);
4132 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
4134 if (offset_rtx == const0_rtx)
4135 stack_parm = gen_rtx_MEM (promoted_mode, internal_arg_pointer);
4137 stack_parm = gen_rtx_MEM (promoted_mode,
4138 gen_rtx_PLUS (Pmode,
4139 internal_arg_pointer,
4142 /* If this is a memory ref that contains aggregate components,
4143 mark it as such for cse and loop optimize. Likewise if it
4145 MEM_SET_IN_STRUCT_P (stack_parm, aggregate);
4146 RTX_UNCHANGING_P (stack_parm) = TREE_READONLY (parm);
4147 MEM_ALIAS_SET (stack_parm) = get_alias_set (parm);
4150 /* If this parameter was passed both in registers and in the stack,
4151 use the copy on the stack. */
4152 if (MUST_PASS_IN_STACK (promoted_mode, passed_type))
4155 #ifdef FUNCTION_ARG_PARTIAL_NREGS
4156 /* If this parm was passed part in regs and part in memory,
4157 pretend it arrived entirely in memory
4158 by pushing the register-part onto the stack.
4160 In the special case of a DImode or DFmode that is split,
4161 we could put it together in a pseudoreg directly,
4162 but for now that's not worth bothering with. */
4166 int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, promoted_mode,
4167 passed_type, named_arg);
4171 current_function_pretend_args_size
4172 = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
4173 / (PARM_BOUNDARY / BITS_PER_UNIT)
4174 * (PARM_BOUNDARY / BITS_PER_UNIT));
4178 /* Handle calls that pass values in multiple non-contiguous
4179 locations. The Irix 6 ABI has examples of this. */
4180 if (GET_CODE (entry_parm) == PARALLEL)
4181 emit_group_store (validize_mem (stack_parm), entry_parm,
4182 int_size_in_bytes (TREE_TYPE (parm)),
4183 (TYPE_ALIGN (TREE_TYPE (parm))
4186 move_block_from_reg (REGNO (entry_parm),
4187 validize_mem (stack_parm), nregs,
4188 int_size_in_bytes (TREE_TYPE (parm)));
4190 entry_parm = stack_parm;
4195 /* If we didn't decide this parm came in a register,
4196 by default it came on the stack. */
4197 if (entry_parm == 0)
4198 entry_parm = stack_parm;
4200 /* Record permanently how this parm was passed. */
4202 DECL_INCOMING_RTL (parm) = entry_parm;
4204 /* If there is actually space on the stack for this parm,
4205 count it in stack_args_size; otherwise set stack_parm to 0
4206 to indicate there is no preallocated stack slot for the parm. */
4208 if (entry_parm == stack_parm
4209 || (GET_CODE (entry_parm) == PARALLEL
4210 && XEXP (XVECEXP (entry_parm, 0, 0), 0) == NULL_RTX)
4211 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
4212 /* On some machines, even if a parm value arrives in a register
4213 there is still an (uninitialized) stack slot allocated for it.
4215 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
4216 whether this parameter already has a stack slot allocated,
4217 because an arg block exists only if current_function_args_size
4218 is larger than some threshold, and we haven't calculated that
4219 yet. So, for now, we just assume that stack slots never exist
4221 || REG_PARM_STACK_SPACE (fndecl) > 0
4225 stack_args_size.constant += arg_size.constant;
4227 ADD_PARM_SIZE (stack_args_size, arg_size.var);
4230 /* No stack slot was pushed for this parm. */
4233 /* Update info on where next arg arrives in registers. */
4235 FUNCTION_ARG_ADVANCE (args_so_far, promoted_mode,
4236 passed_type, named_arg);
4238 /* If this is our second time through, we are done with this parm. */
4242 /* If we can't trust the parm stack slot to be aligned enough
4243 for its ultimate type, don't use that slot after entry.
4244 We'll make another stack slot, if we need one. */
4246 int thisparm_boundary
4247 = FUNCTION_ARG_BOUNDARY (promoted_mode, passed_type);
4249 if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary)
4253 /* If parm was passed in memory, and we need to convert it on entry,
4254 don't store it back in that same slot. */
4256 && nominal_mode != BLKmode && nominal_mode != passed_mode)
4260 /* Now adjust STACK_PARM to the mode and precise location
4261 where this parameter should live during execution,
4262 if we discover that it must live in the stack during execution.
4263 To make debuggers happier on big-endian machines, we store
4264 the value in the last bytes of the space available. */
4266 if (nominal_mode != BLKmode && nominal_mode != passed_mode
4271 if (BYTES_BIG_ENDIAN
4272 && GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD)
4273 stack_offset.constant += (GET_MODE_SIZE (passed_mode)
4274 - GET_MODE_SIZE (nominal_mode));
4276 offset_rtx = ARGS_SIZE_RTX (stack_offset);
4277 if (offset_rtx == const0_rtx)
4278 stack_parm = gen_rtx_MEM (nominal_mode, internal_arg_pointer);
4280 stack_parm = gen_rtx_MEM (nominal_mode,
4281 gen_rtx_PLUS (Pmode,
4282 internal_arg_pointer,
4285 /* If this is a memory ref that contains aggregate components,
4286 mark it as such for cse and loop optimize. */
4287 MEM_SET_IN_STRUCT_P (stack_parm, aggregate);
4292 /* We need this "use" info, because the gcc-register->stack-register
4293 converter in reg-stack.c needs to know which registers are active
4294 at the start of the function call. The actual parameter loading
4295 instructions are not always available then anymore, since they might
4296 have been optimised away. */
4298 if (GET_CODE (entry_parm) == REG && !(hide_last_arg && last_named))
4299 emit_insn (gen_rtx_USE (GET_MODE (entry_parm), entry_parm));
4302 /* ENTRY_PARM is an RTX for the parameter as it arrives,
4303 in the mode in which it arrives.
4304 STACK_PARM is an RTX for a stack slot where the parameter can live
4305 during the function (in case we want to put it there).
4306 STACK_PARM is 0 if no stack slot was pushed for it.
4308 Now output code if necessary to convert ENTRY_PARM to
4309 the type in which this function declares it,
4310 and store that result in an appropriate place,
4311 which may be a pseudo reg, may be STACK_PARM,
4312 or may be a local stack slot if STACK_PARM is 0.
4314 Set DECL_RTL to that place. */
4316 if (nominal_mode == BLKmode || GET_CODE (entry_parm) == PARALLEL)
4318 /* If a BLKmode arrives in registers, copy it to a stack slot.
4319 Handle calls that pass values in multiple non-contiguous
4320 locations. The Irix 6 ABI has examples of this. */
4321 if (GET_CODE (entry_parm) == REG
4322 || GET_CODE (entry_parm) == PARALLEL)
4325 = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)),
4328 /* Note that we will be storing an integral number of words.
4329 So we have to be careful to ensure that we allocate an
4330 integral number of words. We do this below in the
4331 assign_stack_local if space was not allocated in the argument
4332 list. If it was, this will not work if PARM_BOUNDARY is not
4333 a multiple of BITS_PER_WORD. It isn't clear how to fix this
4334 if it becomes a problem. */
4336 if (stack_parm == 0)
4339 = assign_stack_local (GET_MODE (entry_parm),
4342 /* If this is a memory ref that contains aggregate
4343 components, mark it as such for cse and loop optimize. */
4344 MEM_SET_IN_STRUCT_P (stack_parm, aggregate);
4347 else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
4350 if (TREE_READONLY (parm))
4351 RTX_UNCHANGING_P (stack_parm) = 1;
4353 /* Handle calls that pass values in multiple non-contiguous
4354 locations. The Irix 6 ABI has examples of this. */
4355 if (GET_CODE (entry_parm) == PARALLEL)
4356 emit_group_store (validize_mem (stack_parm), entry_parm,
4357 int_size_in_bytes (TREE_TYPE (parm)),
4358 (TYPE_ALIGN (TREE_TYPE (parm))
4361 move_block_from_reg (REGNO (entry_parm),
4362 validize_mem (stack_parm),
4363 size_stored / UNITS_PER_WORD,
4364 int_size_in_bytes (TREE_TYPE (parm)));
4366 DECL_RTL (parm) = stack_parm;
4368 else if (! ((obey_regdecls && ! DECL_REGISTER (parm)
4369 && ! DECL_INLINE (fndecl))
4370 /* layout_decl may set this. */
4371 || TREE_ADDRESSABLE (parm)
4372 || TREE_SIDE_EFFECTS (parm)
4373 /* If -ffloat-store specified, don't put explicit
4374 float variables into registers. */
4375 || (flag_float_store
4376 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
4377 /* Always assign pseudo to structure return or item passed
4378 by invisible reference. */
4379 || passed_pointer || parm == function_result_decl)
4381 /* Store the parm in a pseudoregister during the function, but we
4382 may need to do it in a wider mode. */
4384 register rtx parmreg;
4385 int regno, regnoi = 0, regnor = 0;
4387 unsignedp = TREE_UNSIGNED (TREE_TYPE (parm));
4389 promoted_nominal_mode
4390 = promote_mode (TREE_TYPE (parm), nominal_mode, &unsignedp, 0);
4392 parmreg = gen_reg_rtx (promoted_nominal_mode);
4393 mark_user_reg (parmreg);
4395 /* If this was an item that we received a pointer to, set DECL_RTL
4400 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (passed_type)), parmreg);
4401 MEM_SET_IN_STRUCT_P (DECL_RTL (parm), aggregate);
4404 DECL_RTL (parm) = parmreg;
4406 /* Copy the value into the register. */
4407 if (nominal_mode != passed_mode
4408 || promoted_nominal_mode != promoted_mode)
4411 /* ENTRY_PARM has been converted to PROMOTED_MODE, its
4412 mode, by the caller. We now have to convert it to
4413 NOMINAL_MODE, if different. However, PARMREG may be in
4414 a different mode than NOMINAL_MODE if it is being stored
4417 If ENTRY_PARM is a hard register, it might be in a register
4418 not valid for operating in its mode (e.g., an odd-numbered
4419 register for a DFmode). In that case, moves are the only
4420 thing valid, so we can't do a convert from there. This
4421 occurs when the calling sequence allow such misaligned
4424 In addition, the conversion may involve a call, which could
4425 clobber parameters which haven't been copied to pseudo
4426 registers yet. Therefore, we must first copy the parm to
4427 a pseudo reg here, and save the conversion until after all
4428 parameters have been moved. */
4430 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
4432 emit_move_insn (tempreg, validize_mem (entry_parm));
4434 push_to_sequence (conversion_insns);
4435 tempreg = convert_to_mode (nominal_mode, tempreg, unsignedp);
4437 /* TREE_USED gets set erroneously during expand_assignment. */
4438 save_tree_used = TREE_USED (parm);
4439 expand_assignment (parm,
4440 make_tree (nominal_type, tempreg), 0, 0);
4441 TREE_USED (parm) = save_tree_used;
4442 conversion_insns = get_insns ();
4447 emit_move_insn (parmreg, validize_mem (entry_parm));
4449 /* If we were passed a pointer but the actual value
4450 can safely live in a register, put it in one. */
4451 if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
4452 && ! ((obey_regdecls && ! DECL_REGISTER (parm)
4453 && ! DECL_INLINE (fndecl))
4454 /* layout_decl may set this. */
4455 || TREE_ADDRESSABLE (parm)
4456 || TREE_SIDE_EFFECTS (parm)
4457 /* If -ffloat-store specified, don't put explicit
4458 float variables into registers. */
4459 || (flag_float_store
4460 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))
4462 /* We can't use nominal_mode, because it will have been set to
4463 Pmode above. We must use the actual mode of the parm. */
4464 parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
4465 mark_user_reg (parmreg);
4466 emit_move_insn (parmreg, DECL_RTL (parm));
4467 DECL_RTL (parm) = parmreg;
4468 /* STACK_PARM is the pointer, not the parm, and PARMREG is
4472 #ifdef FUNCTION_ARG_CALLEE_COPIES
4473 /* If we are passed an arg by reference and it is our responsibility
4474 to make a copy, do it now.
4475 PASSED_TYPE and PASSED mode now refer to the pointer, not the
4476 original argument, so we must recreate them in the call to
4477 FUNCTION_ARG_CALLEE_COPIES. */
4478 /* ??? Later add code to handle the case that if the argument isn't
4479 modified, don't do the copy. */
4481 else if (passed_pointer
4482 && FUNCTION_ARG_CALLEE_COPIES (args_so_far,
4483 TYPE_MODE (DECL_ARG_TYPE (parm)),
4484 DECL_ARG_TYPE (parm),
4486 && ! TREE_ADDRESSABLE (DECL_ARG_TYPE (parm)))
4489 tree type = DECL_ARG_TYPE (parm);
4491 /* This sequence may involve a library call perhaps clobbering
4492 registers that haven't been copied to pseudos yet. */
4494 push_to_sequence (conversion_insns);
4496 if (TYPE_SIZE (type) == 0
4497 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4498 /* This is a variable sized object. */
4499 copy = gen_rtx_MEM (BLKmode,
4500 allocate_dynamic_stack_space
4501 (expr_size (parm), NULL_RTX,
4502 TYPE_ALIGN (type)));
4504 copy = assign_stack_temp (TYPE_MODE (type),
4505 int_size_in_bytes (type), 1);
4506 MEM_SET_IN_STRUCT_P (copy, AGGREGATE_TYPE_P (type));
4507 RTX_UNCHANGING_P (copy) = TREE_READONLY (parm);
4509 store_expr (parm, copy, 0);
4510 emit_move_insn (parmreg, XEXP (copy, 0));
4511 if (current_function_check_memory_usage)
4512 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
4513 XEXP (copy, 0), Pmode,
4514 GEN_INT (int_size_in_bytes (type)),
4515 TYPE_MODE (sizetype),
4516 GEN_INT (MEMORY_USE_RW),
4517 TYPE_MODE (integer_type_node));
4518 conversion_insns = get_insns ();
4522 #endif /* FUNCTION_ARG_CALLEE_COPIES */
4524 /* In any case, record the parm's desired stack location
4525 in case we later discover it must live in the stack.
4527 If it is a COMPLEX value, store the stack location for both
4530 if (GET_CODE (parmreg) == CONCAT)
4531 regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1)));
4533 regno = REGNO (parmreg);
4535 if (regno >= max_parm_reg)
4538 int old_max_parm_reg = max_parm_reg;
4540 /* It's slow to expand this one register at a time,
4541 but it's also rare and we need max_parm_reg to be
4542 precisely correct. */
4543 max_parm_reg = regno + 1;
4544 new = (rtx *) xrealloc (parm_reg_stack_loc,
4545 max_parm_reg * sizeof (rtx));
4546 bzero ((char *) (new + old_max_parm_reg),
4547 (max_parm_reg - old_max_parm_reg) * sizeof (rtx));
4548 parm_reg_stack_loc = new;
4551 if (GET_CODE (parmreg) == CONCAT)
4553 enum machine_mode submode = GET_MODE (XEXP (parmreg, 0));
4555 regnor = REGNO (gen_realpart (submode, parmreg));
4556 regnoi = REGNO (gen_imagpart (submode, parmreg));
4558 if (stack_parm != 0)
4560 parm_reg_stack_loc[regnor]
4561 = gen_realpart (submode, stack_parm);
4562 parm_reg_stack_loc[regnoi]
4563 = gen_imagpart (submode, stack_parm);
4567 parm_reg_stack_loc[regnor] = 0;
4568 parm_reg_stack_loc[regnoi] = 0;
4572 parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
4574 /* Mark the register as eliminable if we did no conversion
4575 and it was copied from memory at a fixed offset,
4576 and the arg pointer was not copied to a pseudo-reg.
4577 If the arg pointer is a pseudo reg or the offset formed
4578 an invalid address, such memory-equivalences
4579 as we make here would screw up life analysis for it. */
4580 if (nominal_mode == passed_mode
4583 && GET_CODE (stack_parm) == MEM
4584 && stack_offset.var == 0
4585 && reg_mentioned_p (virtual_incoming_args_rtx,
4586 XEXP (stack_parm, 0)))
4588 rtx linsn = get_last_insn ();
4591 /* Mark complex types separately. */
4592 if (GET_CODE (parmreg) == CONCAT)
4593 /* Scan backwards for the set of the real and
4595 for (sinsn = linsn; sinsn != 0;
4596 sinsn = prev_nonnote_insn (sinsn))
4598 set = single_set (sinsn);
4600 && SET_DEST (set) == regno_reg_rtx [regnoi])
4602 = gen_rtx_EXPR_LIST (REG_EQUIV,
4603 parm_reg_stack_loc[regnoi],
4606 && SET_DEST (set) == regno_reg_rtx [regnor])
4608 = gen_rtx_EXPR_LIST (REG_EQUIV,
4609 parm_reg_stack_loc[regnor],
4612 else if ((set = single_set (linsn)) != 0
4613 && SET_DEST (set) == parmreg)
4615 = gen_rtx_EXPR_LIST (REG_EQUIV,
4616 stack_parm, REG_NOTES (linsn));
4619 /* For pointer data type, suggest pointer register. */
4620 if (POINTER_TYPE_P (TREE_TYPE (parm)))
4621 mark_reg_pointer (parmreg,
4622 (TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm)))
4627 /* Value must be stored in the stack slot STACK_PARM
4628 during function execution. */
4630 if (promoted_mode != nominal_mode)
4632 /* Conversion is required. */
4633 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
4635 emit_move_insn (tempreg, validize_mem (entry_parm));
4637 push_to_sequence (conversion_insns);
4638 entry_parm = convert_to_mode (nominal_mode, tempreg,
4639 TREE_UNSIGNED (TREE_TYPE (parm)));
4642 /* ??? This may need a big-endian conversion on sparc64. */
4643 stack_parm = change_address (stack_parm, nominal_mode,
4646 conversion_insns = get_insns ();
4651 if (entry_parm != stack_parm)
4653 if (stack_parm == 0)
4656 = assign_stack_local (GET_MODE (entry_parm),
4657 GET_MODE_SIZE (GET_MODE (entry_parm)), 0);
4658 /* If this is a memory ref that contains aggregate components,
4659 mark it as such for cse and loop optimize. */
4660 MEM_SET_IN_STRUCT_P (stack_parm, aggregate);
4663 if (promoted_mode != nominal_mode)
4665 push_to_sequence (conversion_insns);
4666 emit_move_insn (validize_mem (stack_parm),
4667 validize_mem (entry_parm));
4668 conversion_insns = get_insns ();
4672 emit_move_insn (validize_mem (stack_parm),
4673 validize_mem (entry_parm));
4675 if (current_function_check_memory_usage)
4677 push_to_sequence (conversion_insns);
4678 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
4679 XEXP (stack_parm, 0), Pmode,
4680 GEN_INT (GET_MODE_SIZE (GET_MODE
4682 TYPE_MODE (sizetype),
4683 GEN_INT (MEMORY_USE_RW),
4684 TYPE_MODE (integer_type_node));
4686 conversion_insns = get_insns ();
4689 DECL_RTL (parm) = stack_parm;
4692 /* If this "parameter" was the place where we are receiving the
4693 function's incoming structure pointer, set up the result. */
4694 if (parm == function_result_decl)
4696 tree result = DECL_RESULT (fndecl);
4697 tree restype = TREE_TYPE (result);
4700 = gen_rtx_MEM (DECL_MODE (result), DECL_RTL (parm));
4702 MEM_SET_IN_STRUCT_P (DECL_RTL (result),
4703 AGGREGATE_TYPE_P (restype));
4706 if (TREE_THIS_VOLATILE (parm))
4707 MEM_VOLATILE_P (DECL_RTL (parm)) = 1;
4708 if (TREE_READONLY (parm))
4709 RTX_UNCHANGING_P (DECL_RTL (parm)) = 1;
4712 /* Output all parameter conversion instructions (possibly including calls)
4713 now that all parameters have been copied out of hard registers. */
4714 emit_insns (conversion_insns);
4716 last_parm_insn = get_last_insn ();
4718 current_function_args_size = stack_args_size.constant;
4720 /* Adjust function incoming argument size for alignment and
4723 #ifdef REG_PARM_STACK_SPACE
4724 #ifndef MAYBE_REG_PARM_STACK_SPACE
4725 current_function_args_size = MAX (current_function_args_size,
4726 REG_PARM_STACK_SPACE (fndecl));
4730 #ifdef STACK_BOUNDARY
4731 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
4733 current_function_args_size
4734 = ((current_function_args_size + STACK_BYTES - 1)
4735 / STACK_BYTES) * STACK_BYTES;
4738 #ifdef ARGS_GROW_DOWNWARD
4739 current_function_arg_offset_rtx
4740 = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant)
4741 : expand_expr (size_binop (MINUS_EXPR, stack_args_size.var,
4742 size_int (-stack_args_size.constant)),
4743 NULL_RTX, VOIDmode, EXPAND_MEMORY_USE_BAD));
4745 current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
4748 /* See how many bytes, if any, of its args a function should try to pop
4751 current_function_pops_args = RETURN_POPS_ARGS (fndecl, TREE_TYPE (fndecl),
4752 current_function_args_size);
4754 /* For stdarg.h function, save info about
4755 regs and stack space used by the named args. */
4758 current_function_args_info = args_so_far;
4760 /* Set the rtx used for the function return value. Put this in its
4761 own variable so any optimizers that need this information don't have
4762 to include tree.h. Do this here so it gets done when an inlined
4763 function gets output. */
4765 current_function_return_rtx = DECL_RTL (DECL_RESULT (fndecl));
4768 /* Indicate whether REGNO is an incoming argument to the current function
4769 that was promoted to a wider mode. If so, return the RTX for the
4770 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
4771 that REGNO is promoted from and whether the promotion was signed or
4774 #ifdef PROMOTE_FUNCTION_ARGS
4777 promoted_input_arg (regno, pmode, punsignedp)
4779 enum machine_mode *pmode;
4784 for (arg = DECL_ARGUMENTS (current_function_decl); arg;
4785 arg = TREE_CHAIN (arg))
4786 if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
4787 && REGNO (DECL_INCOMING_RTL (arg)) == regno
4788 && TYPE_MODE (DECL_ARG_TYPE (arg)) == TYPE_MODE (TREE_TYPE (arg)))
4790 enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
4791 int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
4793 mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1);
4794 if (mode == GET_MODE (DECL_INCOMING_RTL (arg))
4795 && mode != DECL_MODE (arg))
4797 *pmode = DECL_MODE (arg);
4798 *punsignedp = unsignedp;
4799 return DECL_INCOMING_RTL (arg);
4808 /* Compute the size and offset from the start of the stacked arguments for a
4809 parm passed in mode PASSED_MODE and with type TYPE.
4811 INITIAL_OFFSET_PTR points to the current offset into the stacked
4814 The starting offset and size for this parm are returned in *OFFSET_PTR
4815 and *ARG_SIZE_PTR, respectively.
4817 IN_REGS is non-zero if the argument will be passed in registers. It will
4818 never be set if REG_PARM_STACK_SPACE is not defined.
4820 FNDECL is the function in which the argument was defined.
4822 There are two types of rounding that are done. The first, controlled by
4823 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
4824 list to be aligned to the specific boundary (in bits). This rounding
4825 affects the initial and starting offsets, but not the argument size.
4827 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
4828 optionally rounds the size of the parm to PARM_BOUNDARY. The
4829 initial offset is not affected by this rounding, while the size always
4830 is and the starting offset may be. */
4832 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
4833 initial_offset_ptr is positive because locate_and_pad_parm's
4834 callers pass in the total size of args so far as
4835 initial_offset_ptr. arg_size_ptr is always positive.*/
4838 locate_and_pad_parm (passed_mode, type, in_regs, fndecl,
4839 initial_offset_ptr, offset_ptr, arg_size_ptr)
4840 enum machine_mode passed_mode;
4843 tree fndecl ATTRIBUTE_UNUSED;
4844 struct args_size *initial_offset_ptr;
4845 struct args_size *offset_ptr;
4846 struct args_size *arg_size_ptr;
4849 = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
4850 enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
4851 int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
4853 #ifdef REG_PARM_STACK_SPACE
4854 /* If we have found a stack parm before we reach the end of the
4855 area reserved for registers, skip that area. */
4858 int reg_parm_stack_space = 0;
4860 #ifdef MAYBE_REG_PARM_STACK_SPACE
4861 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
4863 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
4865 if (reg_parm_stack_space > 0)
4867 if (initial_offset_ptr->var)
4869 initial_offset_ptr->var
4870 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
4871 size_int (reg_parm_stack_space));
4872 initial_offset_ptr->constant = 0;
4874 else if (initial_offset_ptr->constant < reg_parm_stack_space)
4875 initial_offset_ptr->constant = reg_parm_stack_space;
4878 #endif /* REG_PARM_STACK_SPACE */
4880 arg_size_ptr->var = 0;
4881 arg_size_ptr->constant = 0;
4883 #ifdef ARGS_GROW_DOWNWARD
4884 if (initial_offset_ptr->var)
4886 offset_ptr->constant = 0;
4887 offset_ptr->var = size_binop (MINUS_EXPR, integer_zero_node,
4888 initial_offset_ptr->var);
4892 offset_ptr->constant = - initial_offset_ptr->constant;
4893 offset_ptr->var = 0;
4895 if (where_pad != none
4896 && (TREE_CODE (sizetree) != INTEGER_CST
4897 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
4898 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4899 SUB_PARM_SIZE (*offset_ptr, sizetree);
4900 if (where_pad != downward)
4901 pad_to_arg_alignment (offset_ptr, boundary);
4902 if (initial_offset_ptr->var)
4904 arg_size_ptr->var = size_binop (MINUS_EXPR,
4905 size_binop (MINUS_EXPR,
4907 initial_offset_ptr->var),
4912 arg_size_ptr->constant = (- initial_offset_ptr->constant
4913 - offset_ptr->constant);
4915 #else /* !ARGS_GROW_DOWNWARD */
4916 pad_to_arg_alignment (initial_offset_ptr, boundary);
4917 *offset_ptr = *initial_offset_ptr;
4919 #ifdef PUSH_ROUNDING
4920 if (passed_mode != BLKmode)
4921 sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
4924 /* Pad_below needs the pre-rounded size to know how much to pad below
4925 so this must be done before rounding up. */
4926 if (where_pad == downward
4927 /* However, BLKmode args passed in regs have their padding done elsewhere.
4928 The stack slot must be able to hold the entire register. */
4929 && !(in_regs && passed_mode == BLKmode))
4930 pad_below (offset_ptr, passed_mode, sizetree);
4932 if (where_pad != none
4933 && (TREE_CODE (sizetree) != INTEGER_CST
4934 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
4935 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4937 ADD_PARM_SIZE (*arg_size_ptr, sizetree);
4938 #endif /* ARGS_GROW_DOWNWARD */
4941 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
4942 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
4945 pad_to_arg_alignment (offset_ptr, boundary)
4946 struct args_size *offset_ptr;
4949 int boundary_in_bytes = boundary / BITS_PER_UNIT;
4951 if (boundary > BITS_PER_UNIT)
4953 if (offset_ptr->var)
4956 #ifdef ARGS_GROW_DOWNWARD
4961 (ARGS_SIZE_TREE (*offset_ptr),
4962 boundary / BITS_PER_UNIT);
4963 offset_ptr->constant = 0; /*?*/
4966 offset_ptr->constant =
4967 #ifdef ARGS_GROW_DOWNWARD
4968 FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes);
4970 CEIL_ROUND (offset_ptr->constant, boundary_in_bytes);
4975 #ifndef ARGS_GROW_DOWNWARD
4977 pad_below (offset_ptr, passed_mode, sizetree)
4978 struct args_size *offset_ptr;
4979 enum machine_mode passed_mode;
4982 if (passed_mode != BLKmode)
4984 if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
4985 offset_ptr->constant
4986 += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
4987 / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
4988 - GET_MODE_SIZE (passed_mode));
4992 if (TREE_CODE (sizetree) != INTEGER_CST
4993 || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
4995 /* Round the size up to multiple of PARM_BOUNDARY bits. */
4996 tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4998 ADD_PARM_SIZE (*offset_ptr, s2);
4999 SUB_PARM_SIZE (*offset_ptr, sizetree);
5005 #ifdef ARGS_GROW_DOWNWARD
5007 round_down (value, divisor)
5011 return size_binop (MULT_EXPR,
5012 size_binop (FLOOR_DIV_EXPR, value, size_int (divisor)),
5013 size_int (divisor));
5017 /* Walk the tree of blocks describing the binding levels within a function
5018 and warn about uninitialized variables.
5019 This is done after calling flow_analysis and before global_alloc
5020 clobbers the pseudo-regs to hard regs. */
5023 uninitialized_vars_warning (block)
5026 register tree decl, sub;
5027 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
5029 if (TREE_CODE (decl) == VAR_DECL
5030 /* These warnings are unreliable for and aggregates
5031 because assigning the fields one by one can fail to convince
5032 flow.c that the entire aggregate was initialized.
5033 Unions are troublesome because members may be shorter. */
5034 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl))
5035 && DECL_RTL (decl) != 0
5036 && GET_CODE (DECL_RTL (decl)) == REG
5037 /* Global optimizations can make it difficult to determine if a
5038 particular variable has been initialized. However, a VAR_DECL
5039 with a nonzero DECL_INITIAL had an initializer, so do not
5040 claim it is potentially uninitialized.
5042 We do not care about the actual value in DECL_INITIAL, so we do
5043 not worry that it may be a dangling pointer. */
5044 && DECL_INITIAL (decl) == NULL_TREE
5045 && regno_uninitialized (REGNO (DECL_RTL (decl))))
5046 warning_with_decl (decl,
5047 "`%s' might be used uninitialized in this function");
5048 if (TREE_CODE (decl) == VAR_DECL
5049 && DECL_RTL (decl) != 0
5050 && GET_CODE (DECL_RTL (decl)) == REG
5051 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
5052 warning_with_decl (decl,
5053 "variable `%s' might be clobbered by `longjmp' or `vfork'");
5055 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
5056 uninitialized_vars_warning (sub);
5059 /* Do the appropriate part of uninitialized_vars_warning
5060 but for arguments instead of local variables. */
5063 setjmp_args_warning ()
5066 for (decl = DECL_ARGUMENTS (current_function_decl);
5067 decl; decl = TREE_CHAIN (decl))
5068 if (DECL_RTL (decl) != 0
5069 && GET_CODE (DECL_RTL (decl)) == REG
5070 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
5071 warning_with_decl (decl, "argument `%s' might be clobbered by `longjmp' or `vfork'");
5074 /* If this function call setjmp, put all vars into the stack
5075 unless they were declared `register'. */
5078 setjmp_protect (block)
5081 register tree decl, sub;
5082 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
5083 if ((TREE_CODE (decl) == VAR_DECL
5084 || TREE_CODE (decl) == PARM_DECL)
5085 && DECL_RTL (decl) != 0
5086 && (GET_CODE (DECL_RTL (decl)) == REG
5087 || (GET_CODE (DECL_RTL (decl)) == MEM
5088 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF))
5089 /* If this variable came from an inline function, it must be
5090 that its life doesn't overlap the setjmp. If there was a
5091 setjmp in the function, it would already be in memory. We
5092 must exclude such variable because their DECL_RTL might be
5093 set to strange things such as virtual_stack_vars_rtx. */
5094 && ! DECL_FROM_INLINE (decl)
5096 #ifdef NON_SAVING_SETJMP
5097 /* If longjmp doesn't restore the registers,
5098 don't put anything in them. */
5102 ! DECL_REGISTER (decl)))
5103 put_var_into_stack (decl);
5104 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
5105 setjmp_protect (sub);
5108 /* Like the previous function, but for args instead of local variables. */
5111 setjmp_protect_args ()
5114 for (decl = DECL_ARGUMENTS (current_function_decl);
5115 decl; decl = TREE_CHAIN (decl))
5116 if ((TREE_CODE (decl) == VAR_DECL
5117 || TREE_CODE (decl) == PARM_DECL)
5118 && DECL_RTL (decl) != 0
5119 && (GET_CODE (DECL_RTL (decl)) == REG
5120 || (GET_CODE (DECL_RTL (decl)) == MEM
5121 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF))
5123 /* If longjmp doesn't restore the registers,
5124 don't put anything in them. */
5125 #ifdef NON_SAVING_SETJMP
5129 ! DECL_REGISTER (decl)))
5130 put_var_into_stack (decl);
5133 /* Return the context-pointer register corresponding to DECL,
5134 or 0 if it does not need one. */
5137 lookup_static_chain (decl)
5140 tree context = decl_function_context (decl);
5144 || (TREE_CODE (decl) == FUNCTION_DECL && DECL_NO_STATIC_CHAIN (decl)))
5147 /* We treat inline_function_decl as an alias for the current function
5148 because that is the inline function whose vars, types, etc.
5149 are being merged into the current function.
5150 See expand_inline_function. */
5151 if (context == current_function_decl || context == inline_function_decl)
5152 return virtual_stack_vars_rtx;
5154 for (link = context_display; link; link = TREE_CHAIN (link))
5155 if (TREE_PURPOSE (link) == context)
5156 return RTL_EXPR_RTL (TREE_VALUE (link));
5161 /* Convert a stack slot address ADDR for variable VAR
5162 (from a containing function)
5163 into an address valid in this function (using a static chain). */
5166 fix_lexical_addr (addr, var)
5171 HOST_WIDE_INT displacement;
5172 tree context = decl_function_context (var);
5173 struct function *fp;
5176 /* If this is the present function, we need not do anything. */
5177 if (context == current_function_decl || context == inline_function_decl)
5180 for (fp = outer_function_chain; fp; fp = fp->next)
5181 if (fp->decl == context)
5187 if (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == MEM)
5188 addr = XEXP (XEXP (addr, 0), 0);
5190 /* Decode given address as base reg plus displacement. */
5191 if (GET_CODE (addr) == REG)
5192 basereg = addr, displacement = 0;
5193 else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
5194 basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
5198 /* We accept vars reached via the containing function's
5199 incoming arg pointer and via its stack variables pointer. */
5200 if (basereg == fp->internal_arg_pointer)
5202 /* If reached via arg pointer, get the arg pointer value
5203 out of that function's stack frame.
5205 There are two cases: If a separate ap is needed, allocate a
5206 slot in the outer function for it and dereference it that way.
5207 This is correct even if the real ap is actually a pseudo.
5208 Otherwise, just adjust the offset from the frame pointer to
5211 #ifdef NEED_SEPARATE_AP
5214 if (fp->x_arg_pointer_save_area == 0)
5215 fp->x_arg_pointer_save_area
5216 = assign_stack_local_1 (Pmode, GET_MODE_SIZE (Pmode), 0, fp);
5218 addr = fix_lexical_addr (XEXP (fp->x_arg_pointer_save_area, 0), var);
5219 addr = memory_address (Pmode, addr);
5221 base = copy_to_reg (gen_rtx_MEM (Pmode, addr));
5223 displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET);
5224 base = lookup_static_chain (var);
5228 else if (basereg == virtual_stack_vars_rtx)
5230 /* This is the same code as lookup_static_chain, duplicated here to
5231 avoid an extra call to decl_function_context. */
5234 for (link = context_display; link; link = TREE_CHAIN (link))
5235 if (TREE_PURPOSE (link) == context)
5237 base = RTL_EXPR_RTL (TREE_VALUE (link));
5245 /* Use same offset, relative to appropriate static chain or argument
5247 return plus_constant (base, displacement);
5250 /* Return the address of the trampoline for entering nested fn FUNCTION.
5251 If necessary, allocate a trampoline (in the stack frame)
5252 and emit rtl to initialize its contents (at entry to this function). */
5255 trampoline_address (function)
5261 struct function *fp;
5264 /* Find an existing trampoline and return it. */
5265 for (link = trampoline_list; link; link = TREE_CHAIN (link))
5266 if (TREE_PURPOSE (link) == function)
5268 round_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0));
5270 for (fp = outer_function_chain; fp; fp = fp->next)
5271 for (link = fp->x_trampoline_list; link; link = TREE_CHAIN (link))
5272 if (TREE_PURPOSE (link) == function)
5274 tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
5276 return round_trampoline_addr (tramp);
5279 /* None exists; we must make one. */
5281 /* Find the `struct function' for the function containing FUNCTION. */
5283 fn_context = decl_function_context (function);
5284 if (fn_context != current_function_decl
5285 && fn_context != inline_function_decl)
5286 for (fp = outer_function_chain; fp; fp = fp->next)
5287 if (fp->decl == fn_context)
5290 /* Allocate run-time space for this trampoline
5291 (usually in the defining function's stack frame). */
5292 #ifdef ALLOCATE_TRAMPOLINE
5293 tramp = ALLOCATE_TRAMPOLINE (fp);
5295 /* If rounding needed, allocate extra space
5296 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
5297 #ifdef TRAMPOLINE_ALIGNMENT
5298 #define TRAMPOLINE_REAL_SIZE \
5299 (TRAMPOLINE_SIZE + (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT) - 1)
5301 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
5303 tramp = assign_stack_local_1 (BLKmode, TRAMPOLINE_REAL_SIZE, 0,
5304 fp ? fp : current_function);
5307 /* Record the trampoline for reuse and note it for later initialization
5308 by expand_function_end. */
5311 push_obstacks (fp->function_maybepermanent_obstack,
5312 fp->function_maybepermanent_obstack);
5313 rtlexp = make_node (RTL_EXPR);
5314 RTL_EXPR_RTL (rtlexp) = tramp;
5315 fp->x_trampoline_list = tree_cons (function, rtlexp,
5316 fp->x_trampoline_list);
5321 /* Make the RTL_EXPR node temporary, not momentary, so that the
5322 trampoline_list doesn't become garbage. */
5323 int momentary = suspend_momentary ();
5324 rtlexp = make_node (RTL_EXPR);
5325 resume_momentary (momentary);
5327 RTL_EXPR_RTL (rtlexp) = tramp;
5328 trampoline_list = tree_cons (function, rtlexp, trampoline_list);
5331 tramp = fix_lexical_addr (XEXP (tramp, 0), function);
5332 return round_trampoline_addr (tramp);
5335 /* Given a trampoline address,
5336 round it to multiple of TRAMPOLINE_ALIGNMENT. */
5339 round_trampoline_addr (tramp)
5342 #ifdef TRAMPOLINE_ALIGNMENT
5343 /* Round address up to desired boundary. */
5344 rtx temp = gen_reg_rtx (Pmode);
5345 temp = expand_binop (Pmode, add_optab, tramp,
5346 GEN_INT (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT - 1),
5347 temp, 0, OPTAB_LIB_WIDEN);
5348 tramp = expand_binop (Pmode, and_optab, temp,
5349 GEN_INT (- TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT),
5350 temp, 0, OPTAB_LIB_WIDEN);
5355 /* The functions identify_blocks and reorder_blocks provide a way to
5356 reorder the tree of BLOCK nodes, for optimizers that reshuffle or
5357 duplicate portions of the RTL code. Call identify_blocks before
5358 changing the RTL, and call reorder_blocks after. */
5360 /* Put all this function's BLOCK nodes including those that are chained
5361 onto the first block into a vector, and return it.
5362 Also store in each NOTE for the beginning or end of a block
5363 the index of that block in the vector.
5364 The arguments are BLOCK, the chain of top-level blocks of the function,
5365 and INSNS, the insn chain of the function. */
5368 identify_blocks (block, insns)
5376 int next_block_number = 1;
5377 int current_block_number = 1;
5383 n_blocks = all_blocks (block, 0);
5384 block_vector = (tree *) xmalloc (n_blocks * sizeof (tree));
5385 block_stack = (int *) alloca (n_blocks * sizeof (int));
5387 all_blocks (block, block_vector);
5389 for (insn = insns; insn; insn = NEXT_INSN (insn))
5390 if (GET_CODE (insn) == NOTE)
5392 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
5394 block_stack[depth++] = current_block_number;
5395 current_block_number = next_block_number;
5396 NOTE_BLOCK_NUMBER (insn) = next_block_number++;
5398 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
5400 NOTE_BLOCK_NUMBER (insn) = current_block_number;
5401 current_block_number = block_stack[--depth];
5405 if (n_blocks != next_block_number)
5408 return block_vector;
5411 /* Given BLOCK_VECTOR which was returned by identify_blocks,
5412 and a revised instruction chain, rebuild the tree structure
5413 of BLOCK nodes to correspond to the new order of RTL.
5414 The new block tree is inserted below TOP_BLOCK.
5415 Returns the current top-level block. */
5418 reorder_blocks (block_vector, block, insns)
5423 tree current_block = block;
5426 if (block_vector == 0)
5429 /* Prune the old trees away, so that it doesn't get in the way. */
5430 BLOCK_SUBBLOCKS (current_block) = 0;
5431 BLOCK_CHAIN (current_block) = 0;
5433 for (insn = insns; insn; insn = NEXT_INSN (insn))
5434 if (GET_CODE (insn) == NOTE)
5436 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
5438 tree block = block_vector[NOTE_BLOCK_NUMBER (insn)];
5439 /* If we have seen this block before, copy it. */
5440 if (TREE_ASM_WRITTEN (block))
5441 block = copy_node (block);
5442 BLOCK_SUBBLOCKS (block) = 0;
5443 TREE_ASM_WRITTEN (block) = 1;
5444 BLOCK_SUPERCONTEXT (block) = current_block;
5445 BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
5446 BLOCK_SUBBLOCKS (current_block) = block;
5447 current_block = block;
5448 NOTE_SOURCE_FILE (insn) = 0;
5450 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
5452 BLOCK_SUBBLOCKS (current_block)
5453 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
5454 current_block = BLOCK_SUPERCONTEXT (current_block);
5455 NOTE_SOURCE_FILE (insn) = 0;
5459 BLOCK_SUBBLOCKS (current_block)
5460 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
5461 return current_block;
5464 /* Reverse the order of elements in the chain T of blocks,
5465 and return the new head of the chain (old last element). */
5471 register tree prev = 0, decl, next;
5472 for (decl = t; decl; decl = next)
5474 next = BLOCK_CHAIN (decl);
5475 BLOCK_CHAIN (decl) = prev;
5481 /* Count the subblocks of the list starting with BLOCK, and list them
5482 all into the vector VECTOR. Also clear TREE_ASM_WRITTEN in all
5486 all_blocks (block, vector)
5494 TREE_ASM_WRITTEN (block) = 0;
5496 /* Record this block. */
5498 vector[n_blocks] = block;
5502 /* Record the subblocks, and their subblocks... */
5503 n_blocks += all_blocks (BLOCK_SUBBLOCKS (block),
5504 vector ? vector + n_blocks : 0);
5505 block = BLOCK_CHAIN (block);
5511 /* Allocate a function structure and reset its contents to the defaults. */
5513 prepare_function_start ()
5515 current_function = (struct function *) xcalloc (1, sizeof (struct function));
5516 current_function->can_garbage_collect = 0;
5518 init_stmt_for_function ();
5520 cse_not_expected = ! optimize;
5522 /* Caller save not needed yet. */
5523 caller_save_needed = 0;
5525 /* No stack slots have been made yet. */
5526 stack_slot_list = 0;
5528 current_function_has_nonlocal_label = 0;
5529 current_function_has_nonlocal_goto = 0;
5531 /* There is no stack slot for handling nonlocal gotos. */
5532 nonlocal_goto_handler_slots = 0;
5533 nonlocal_goto_stack_level = 0;
5535 /* No labels have been declared for nonlocal use. */
5536 nonlocal_labels = 0;
5537 nonlocal_goto_handler_labels = 0;
5539 /* No function calls so far in this function. */
5540 function_call_count = 0;
5542 /* No parm regs have been allocated.
5543 (This is important for output_inline_function.) */
5544 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
5546 /* Initialize the RTL mechanism. */
5549 /* Initialize the queue of pending postincrement and postdecrements,
5550 and some other info in expr.c. */
5553 /* We haven't done register allocation yet. */
5556 init_varasm_status (current_function);
5558 /* Clear out data used for inlining. */
5559 current_function->inlinable = 0;
5560 current_function->original_decl_initial = 0;
5561 current_function->original_arg_vector = 0;
5563 /* Set if a call to setjmp is seen. */
5564 current_function_calls_setjmp = 0;
5566 /* Set if a call to longjmp is seen. */
5567 current_function_calls_longjmp = 0;
5569 current_function_calls_alloca = 0;
5570 current_function_contains_functions = 0;
5571 current_function_is_leaf = 0;
5572 current_function_sp_is_unchanging = 0;
5573 current_function_uses_only_leaf_regs = 0;
5574 current_function_has_computed_jump = 0;
5575 current_function_is_thunk = 0;
5577 current_function_returns_pcc_struct = 0;
5578 current_function_returns_struct = 0;
5579 current_function_epilogue_delay_list = 0;
5580 current_function_uses_const_pool = 0;
5581 current_function_uses_pic_offset_table = 0;
5582 current_function_cannot_inline = 0;
5584 /* We have not yet needed to make a label to jump to for tail-recursion. */
5585 tail_recursion_label = 0;
5587 /* We haven't had a need to make a save area for ap yet. */
5588 arg_pointer_save_area = 0;
5590 /* No stack slots allocated yet. */
5593 /* No SAVE_EXPRs in this function yet. */
5596 /* No RTL_EXPRs in this function yet. */
5599 /* Set up to allocate temporaries. */
5602 /* Indicate that we need to distinguish between the return value of the
5603 present function and the return value of a function being called. */
5604 rtx_equal_function_value_matters = 1;
5606 /* Indicate that we have not instantiated virtual registers yet. */
5607 virtuals_instantiated = 0;
5609 /* Indicate we have no need of a frame pointer yet. */
5610 frame_pointer_needed = 0;
5612 /* By default assume not varargs or stdarg. */
5613 current_function_varargs = 0;
5614 current_function_stdarg = 0;
5616 /* We haven't made any trampolines for this function yet. */
5617 trampoline_list = 0;
5619 init_pending_stack_adjust ();
5620 inhibit_defer_pop = 0;
5622 current_function_outgoing_args_size = 0;
5624 if (init_machine_status)
5625 (*init_machine_status) (current_function);
5628 /* Initialize the rtl expansion mechanism so that we can do simple things
5629 like generate sequences. This is used to provide a context during global
5630 initialization of some passes. */
5632 init_dummy_function_start ()
5634 prepare_function_start ();
5637 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
5638 and initialize static variables for generating RTL for the statements
5642 init_function_start (subr, filename, line)
5647 prepare_function_start ();
5649 /* Remember this function for later. */
5650 current_function->next_global = all_functions;
5651 all_functions = current_function;
5653 current_function_name = (*decl_printable_name) (subr, 2);
5655 /* Nonzero if this is a nested function that uses a static chain. */
5657 current_function_needs_context
5658 = (decl_function_context (current_function_decl) != 0
5659 && ! DECL_NO_STATIC_CHAIN (current_function_decl));
5661 /* Within function body, compute a type's size as soon it is laid out. */
5662 immediate_size_expand++;
5664 /* Prevent ever trying to delete the first instruction of a function.
5665 Also tell final how to output a linenum before the function prologue.
5666 Note linenums could be missing, e.g. when compiling a Java .class file. */
5668 emit_line_note (filename, line);
5670 /* Make sure first insn is a note even if we don't want linenums.
5671 This makes sure the first insn will never be deleted.
5672 Also, final expects a note to appear there. */
5673 emit_note (NULL_PTR, NOTE_INSN_DELETED);
5675 /* Set flags used by final.c. */
5676 if (aggregate_value_p (DECL_RESULT (subr)))
5678 #ifdef PCC_STATIC_STRUCT_RETURN
5679 current_function_returns_pcc_struct = 1;
5681 current_function_returns_struct = 1;
5684 /* Warn if this value is an aggregate type,
5685 regardless of which calling convention we are using for it. */
5686 if (warn_aggregate_return
5687 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
5688 warning ("function returns an aggregate");
5690 current_function_returns_pointer
5691 = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
5694 /* Make sure all values used by the optimization passes have sane
5697 init_function_for_compilation ()
5700 /* No prologue/epilogue insns yet. */
5701 prologue = epilogue = 0;
5704 /* Indicate that the current function uses extra args
5705 not explicitly mentioned in the argument list in any fashion. */
5710 current_function_varargs = 1;
5713 /* Expand a call to __main at the beginning of a possible main function. */
5715 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
5716 #undef HAS_INIT_SECTION
5717 #define HAS_INIT_SECTION
5721 expand_main_function ()
5723 #if !defined (HAS_INIT_SECTION)
5724 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, NAME__MAIN), 0,
5726 #endif /* not HAS_INIT_SECTION */
5729 extern struct obstack permanent_obstack;
5731 /* Start the RTL for a new function, and set variables used for
5733 SUBR is the FUNCTION_DECL node.
5734 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
5735 the function's parameters, which must be run at any return statement. */
5738 expand_function_start (subr, parms_have_cleanups)
5740 int parms_have_cleanups;
5744 rtx last_ptr = NULL_RTX;
5746 /* Make sure volatile mem refs aren't considered
5747 valid operands of arithmetic insns. */
5748 init_recog_no_volatile ();
5750 /* Set this before generating any memory accesses. */
5751 current_function_check_memory_usage
5752 = (flag_check_memory_usage
5753 && ! DECL_NO_CHECK_MEMORY_USAGE (current_function_decl));
5755 current_function_instrument_entry_exit
5756 = (flag_instrument_function_entry_exit
5757 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr));
5759 /* If function gets a static chain arg, store it in the stack frame.
5760 Do this first, so it gets the first stack slot offset. */
5761 if (current_function_needs_context)
5763 last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
5765 /* Delay copying static chain if it is not a register to avoid
5766 conflicts with regs used for parameters. */
5767 if (! SMALL_REGISTER_CLASSES
5768 || GET_CODE (static_chain_incoming_rtx) == REG)
5769 emit_move_insn (last_ptr, static_chain_incoming_rtx);
5772 /* If the parameters of this function need cleaning up, get a label
5773 for the beginning of the code which executes those cleanups. This must
5774 be done before doing anything with return_label. */
5775 if (parms_have_cleanups)
5776 cleanup_label = gen_label_rtx ();
5780 /* Make the label for return statements to jump to, if this machine
5781 does not have a one-instruction return and uses an epilogue,
5782 or if it returns a structure, or if it has parm cleanups. */
5784 if (cleanup_label == 0 && HAVE_return
5785 && ! current_function_instrument_entry_exit
5786 && ! current_function_returns_pcc_struct
5787 && ! (current_function_returns_struct && ! optimize))
5790 return_label = gen_label_rtx ();
5792 return_label = gen_label_rtx ();
5795 /* Initialize rtx used to return the value. */
5796 /* Do this before assign_parms so that we copy the struct value address
5797 before any library calls that assign parms might generate. */
5799 /* Decide whether to return the value in memory or in a register. */
5800 if (aggregate_value_p (DECL_RESULT (subr)))
5802 /* Returning something that won't go in a register. */
5803 register rtx value_address = 0;
5805 #ifdef PCC_STATIC_STRUCT_RETURN
5806 if (current_function_returns_pcc_struct)
5808 int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
5809 value_address = assemble_static_space (size);
5814 /* Expect to be passed the address of a place to store the value.
5815 If it is passed as an argument, assign_parms will take care of
5817 if (struct_value_incoming_rtx)
5819 value_address = gen_reg_rtx (Pmode);
5820 emit_move_insn (value_address, struct_value_incoming_rtx);
5825 DECL_RTL (DECL_RESULT (subr))
5826 = gen_rtx_MEM (DECL_MODE (DECL_RESULT (subr)), value_address);
5827 MEM_SET_IN_STRUCT_P (DECL_RTL (DECL_RESULT (subr)),
5828 AGGREGATE_TYPE_P (TREE_TYPE
5833 else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
5834 /* If return mode is void, this decl rtl should not be used. */
5835 DECL_RTL (DECL_RESULT (subr)) = 0;
5836 else if (parms_have_cleanups || current_function_instrument_entry_exit)
5838 /* If function will end with cleanup code for parms,
5839 compute the return values into a pseudo reg,
5840 which we will copy into the true return register
5841 after the cleanups are done. */
5843 enum machine_mode mode = DECL_MODE (DECL_RESULT (subr));
5845 #ifdef PROMOTE_FUNCTION_RETURN
5846 tree type = TREE_TYPE (DECL_RESULT (subr));
5847 int unsignedp = TREE_UNSIGNED (type);
5849 mode = promote_mode (type, mode, &unsignedp, 1);
5852 DECL_RTL (DECL_RESULT (subr)) = gen_reg_rtx (mode);
5855 /* Scalar, returned in a register. */
5857 #ifdef FUNCTION_OUTGOING_VALUE
5858 DECL_RTL (DECL_RESULT (subr))
5859 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
5861 DECL_RTL (DECL_RESULT (subr))
5862 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
5865 /* Mark this reg as the function's return value. */
5866 if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG)
5868 REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1;
5869 /* Needed because we may need to move this to memory
5870 in case it's a named return value whose address is taken. */
5871 DECL_REGISTER (DECL_RESULT (subr)) = 1;
5875 /* Initialize rtx for parameters and local variables.
5876 In some cases this requires emitting insns. */
5878 assign_parms (subr, 0);
5880 /* Copy the static chain now if it wasn't a register. The delay is to
5881 avoid conflicts with the parameter passing registers. */
5883 if (SMALL_REGISTER_CLASSES && current_function_needs_context)
5884 if (GET_CODE (static_chain_incoming_rtx) != REG)
5885 emit_move_insn (last_ptr, static_chain_incoming_rtx);
5887 /* The following was moved from init_function_start.
5888 The move is supposed to make sdb output more accurate. */
5889 /* Indicate the beginning of the function body,
5890 as opposed to parm setup. */
5891 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_BEG);
5893 /* If doing stupid allocation, mark parms as born here. */
5895 if (GET_CODE (get_last_insn ()) != NOTE)
5896 emit_note (NULL_PTR, NOTE_INSN_DELETED);
5897 parm_birth_insn = get_last_insn ();
5901 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
5902 use_variable (regno_reg_rtx[i]);
5904 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
5905 use_variable (current_function_internal_arg_pointer);
5908 context_display = 0;
5909 if (current_function_needs_context)
5911 /* Fetch static chain values for containing functions. */
5912 tem = decl_function_context (current_function_decl);
5913 /* If not doing stupid register allocation copy the static chain
5914 pointer into a pseudo. If we have small register classes, copy
5915 the value from memory if static_chain_incoming_rtx is a REG. If
5916 we do stupid register allocation, we use the stack address
5918 if (tem && ! obey_regdecls)
5920 /* If the static chain originally came in a register, put it back
5921 there, then move it out in the next insn. The reason for
5922 this peculiar code is to satisfy function integration. */
5923 if (SMALL_REGISTER_CLASSES
5924 && GET_CODE (static_chain_incoming_rtx) == REG)
5925 emit_move_insn (static_chain_incoming_rtx, last_ptr);
5926 last_ptr = copy_to_reg (static_chain_incoming_rtx);
5931 tree rtlexp = make_node (RTL_EXPR);
5933 RTL_EXPR_RTL (rtlexp) = last_ptr;
5934 context_display = tree_cons (tem, rtlexp, context_display);
5935 tem = decl_function_context (tem);
5938 /* Chain thru stack frames, assuming pointer to next lexical frame
5939 is found at the place we always store it. */
5940 #ifdef FRAME_GROWS_DOWNWARD
5941 last_ptr = plus_constant (last_ptr, - GET_MODE_SIZE (Pmode));
5943 last_ptr = copy_to_reg (gen_rtx_MEM (Pmode,
5944 memory_address (Pmode,
5947 /* If we are not optimizing, ensure that we know that this
5948 piece of context is live over the entire function. */
5950 save_expr_regs = gen_rtx_EXPR_LIST (VOIDmode, last_ptr,
5955 if (current_function_instrument_entry_exit)
5957 rtx fun = DECL_RTL (current_function_decl);
5958 if (GET_CODE (fun) == MEM)
5959 fun = XEXP (fun, 0);
5962 emit_library_call (profile_function_entry_libfunc, 0, VOIDmode, 2,
5964 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS,
5966 hard_frame_pointer_rtx),
5970 /* After the display initializations is where the tail-recursion label
5971 should go, if we end up needing one. Ensure we have a NOTE here
5972 since some things (like trampolines) get placed before this. */
5973 tail_recursion_reentry = emit_note (NULL_PTR, NOTE_INSN_DELETED);
5975 /* Evaluate now the sizes of any types declared among the arguments. */
5976 for (tem = nreverse (get_pending_sizes ()); tem; tem = TREE_CHAIN (tem))
5978 expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode,
5979 EXPAND_MEMORY_USE_BAD);
5980 /* Flush the queue in case this parameter declaration has
5985 /* Make sure there is a line number after the function entry setup code. */
5986 force_next_line_note ();
5989 /* Undo the effects of init_dummy_function_start. */
5991 expand_dummy_function_end ()
5993 /* End any sequences that failed to be closed due to syntax errors. */
5994 while (in_sequence_p ())
5997 /* Outside function body, can't compute type's actual size
5998 until next function's body starts. */
5999 current_function = 0;
6002 /* Generate RTL for the end of the current function.
6003 FILENAME and LINE are the current position in the source file.
6005 It is up to language-specific callers to do cleanups for parameters--
6006 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */
6009 expand_function_end (filename, line, end_bindings)
6017 #ifdef TRAMPOLINE_TEMPLATE
6018 static rtx initial_trampoline;
6021 finish_expr_for_function ();
6023 #ifdef NON_SAVING_SETJMP
6024 /* Don't put any variables in registers if we call setjmp
6025 on a machine that fails to restore the registers. */
6026 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
6028 if (DECL_INITIAL (current_function_decl) != error_mark_node)
6029 setjmp_protect (DECL_INITIAL (current_function_decl));
6031 setjmp_protect_args ();
6035 /* Save the argument pointer if a save area was made for it. */
6036 if (arg_pointer_save_area)
6038 /* arg_pointer_save_area may not be a valid memory address, so we
6039 have to check it and fix it if necessary. */
6042 emit_move_insn (validize_mem (arg_pointer_save_area),
6043 virtual_incoming_args_rtx);
6044 seq = gen_sequence ();
6046 emit_insn_before (seq, tail_recursion_reentry);
6049 /* Initialize any trampolines required by this function. */
6050 for (link = trampoline_list; link; link = TREE_CHAIN (link))
6052 tree function = TREE_PURPOSE (link);
6053 rtx context = lookup_static_chain (function);
6054 rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
6055 #ifdef TRAMPOLINE_TEMPLATE
6060 #ifdef TRAMPOLINE_TEMPLATE
6061 /* First make sure this compilation has a template for
6062 initializing trampolines. */
6063 if (initial_trampoline == 0)
6065 end_temporary_allocation ();
6067 = gen_rtx_MEM (BLKmode, assemble_trampoline_template ());
6068 resume_temporary_allocation ();
6072 /* Generate insns to initialize the trampoline. */
6074 tramp = round_trampoline_addr (XEXP (tramp, 0));
6075 #ifdef TRAMPOLINE_TEMPLATE
6076 blktramp = change_address (initial_trampoline, BLKmode, tramp);
6077 emit_block_move (blktramp, initial_trampoline,
6078 GEN_INT (TRAMPOLINE_SIZE),
6079 TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
6081 INITIALIZE_TRAMPOLINE (tramp, XEXP (DECL_RTL (function), 0), context);
6085 /* Put those insns at entry to the containing function (this one). */
6086 emit_insns_before (seq, tail_recursion_reentry);
6089 /* If we are doing stack checking and this function makes calls,
6090 do a stack probe at the start of the function to ensure we have enough
6091 space for another stack frame. */
6092 if (flag_stack_check && ! STACK_CHECK_BUILTIN)
6096 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
6097 if (GET_CODE (insn) == CALL_INSN)
6100 probe_stack_range (STACK_CHECK_PROTECT,
6101 GEN_INT (STACK_CHECK_MAX_FRAME_SIZE));
6104 emit_insns_before (seq, tail_recursion_reentry);
6109 /* Warn about unused parms if extra warnings were specified. */
6110 if (warn_unused && extra_warnings)
6114 for (decl = DECL_ARGUMENTS (current_function_decl);
6115 decl; decl = TREE_CHAIN (decl))
6116 if (! TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
6117 && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
6118 warning_with_decl (decl, "unused parameter `%s'");
6121 /* Delete handlers for nonlocal gotos if nothing uses them. */
6122 if (nonlocal_goto_handler_slots != 0
6123 && ! current_function_has_nonlocal_label)
6126 /* End any sequences that failed to be closed due to syntax errors. */
6127 while (in_sequence_p ())
6130 /* Outside function body, can't compute type's actual size
6131 until next function's body starts. */
6132 immediate_size_expand--;
6134 /* If doing stupid register allocation,
6135 mark register parms as dying here. */
6140 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
6141 use_variable (regno_reg_rtx[i]);
6143 /* Likewise for the regs of all the SAVE_EXPRs in the function. */
6145 for (tem = save_expr_regs; tem; tem = XEXP (tem, 1))
6147 use_variable (XEXP (tem, 0));
6148 use_variable_after (XEXP (tem, 0), parm_birth_insn);
6151 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
6152 use_variable (current_function_internal_arg_pointer);
6155 clear_pending_stack_adjust ();
6156 do_pending_stack_adjust ();
6158 /* Mark the end of the function body.
6159 If control reaches this insn, the function can drop through
6160 without returning a value. */
6161 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_END);
6163 /* Must mark the last line number note in the function, so that the test
6164 coverage code can avoid counting the last line twice. This just tells
6165 the code to ignore the immediately following line note, since there
6166 already exists a copy of this note somewhere above. This line number
6167 note is still needed for debugging though, so we can't delete it. */
6168 if (flag_test_coverage)
6169 emit_note (NULL_PTR, NOTE_REPEATED_LINE_NUMBER);
6171 /* Output a linenumber for the end of the function.
6172 SDB depends on this. */
6173 emit_line_note_force (filename, line);
6175 /* Output the label for the actual return from the function,
6176 if one is expected. This happens either because a function epilogue
6177 is used instead of a return instruction, or because a return was done
6178 with a goto in order to run local cleanups, or because of pcc-style
6179 structure returning. */
6182 emit_label (return_label);
6184 /* C++ uses this. */
6186 expand_end_bindings (0, 0, 0);
6188 /* Now handle any leftover exception regions that may have been
6189 created for the parameters. */
6191 rtx last = get_last_insn ();
6194 expand_leftover_cleanups ();
6196 /* If the above emitted any code, may sure we jump around it. */
6197 if (last != get_last_insn ())
6199 label = gen_label_rtx ();
6200 last = emit_jump_insn_after (gen_jump (label), last);
6201 last = emit_barrier_after (last);
6206 if (current_function_instrument_entry_exit)
6208 rtx fun = DECL_RTL (current_function_decl);
6209 if (GET_CODE (fun) == MEM)
6210 fun = XEXP (fun, 0);
6213 emit_library_call (profile_function_exit_libfunc, 0, VOIDmode, 2,
6215 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS,
6217 hard_frame_pointer_rtx),
6221 /* If we had calls to alloca, and this machine needs
6222 an accurate stack pointer to exit the function,
6223 insert some code to save and restore the stack pointer. */
6224 #ifdef EXIT_IGNORE_STACK
6225 if (! EXIT_IGNORE_STACK)
6227 if (current_function_calls_alloca)
6231 emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
6232 emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
6235 /* If scalar return value was computed in a pseudo-reg,
6236 copy that to the hard return register. */
6237 if (DECL_RTL (DECL_RESULT (current_function_decl)) != 0
6238 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG
6239 && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl)))
6240 >= FIRST_PSEUDO_REGISTER))
6242 rtx real_decl_result;
6244 #ifdef FUNCTION_OUTGOING_VALUE
6246 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
6247 current_function_decl);
6250 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
6251 current_function_decl);
6253 REG_FUNCTION_VALUE_P (real_decl_result) = 1;
6254 /* If this is a BLKmode structure being returned in registers, then use
6255 the mode computed in expand_return. */
6256 if (GET_MODE (real_decl_result) == BLKmode)
6257 PUT_MODE (real_decl_result,
6258 GET_MODE (DECL_RTL (DECL_RESULT (current_function_decl))));
6259 emit_move_insn (real_decl_result,
6260 DECL_RTL (DECL_RESULT (current_function_decl)));
6261 emit_insn (gen_rtx_USE (VOIDmode, real_decl_result));
6263 /* The delay slot scheduler assumes that current_function_return_rtx
6264 holds the hard register containing the return value, not a temporary
6266 current_function_return_rtx = real_decl_result;
6269 /* If returning a structure, arrange to return the address of the value
6270 in a place where debuggers expect to find it.
6272 If returning a structure PCC style,
6273 the caller also depends on this value.
6274 And current_function_returns_pcc_struct is not necessarily set. */
6275 if (current_function_returns_struct
6276 || current_function_returns_pcc_struct)
6278 rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
6279 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
6280 #ifdef FUNCTION_OUTGOING_VALUE
6282 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
6283 current_function_decl);
6286 = FUNCTION_VALUE (build_pointer_type (type),
6287 current_function_decl);
6290 /* Mark this as a function return value so integrate will delete the
6291 assignment and USE below when inlining this function. */
6292 REG_FUNCTION_VALUE_P (outgoing) = 1;
6294 emit_move_insn (outgoing, value_address);
6295 use_variable (outgoing);
6298 /* If this is an implementation of __throw, do what's necessary to
6299 communicate between __builtin_eh_return and the epilogue. */
6300 expand_eh_return ();
6302 /* Output a return insn if we are using one.
6303 Otherwise, let the rtl chain end here, to drop through
6304 into the epilogue. */
6309 emit_jump_insn (gen_return ());
6314 /* Fix up any gotos that jumped out to the outermost
6315 binding level of the function.
6316 Must follow emitting RETURN_LABEL. */
6318 /* If you have any cleanups to do at this point,
6319 and they need to create temporary variables,
6320 then you will lose. */
6321 expand_fixups (get_insns ());
6324 /* Create an array that records the INSN_UIDs of INSNS (either a sequence
6325 or a single insn). */
6327 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
6329 record_insns (insns)
6334 if (GET_CODE (insns) == SEQUENCE)
6336 int len = XVECLEN (insns, 0);
6337 vec = (int *) oballoc ((len + 1) * sizeof (int));
6340 vec[len] = INSN_UID (XVECEXP (insns, 0, len));
6344 vec = (int *) oballoc (2 * sizeof (int));
6345 vec[0] = INSN_UID (insns);
6351 /* Determine how many INSN_UIDs in VEC are part of INSN. */
6354 contains (insn, vec)
6360 if (GET_CODE (insn) == INSN
6361 && GET_CODE (PATTERN (insn)) == SEQUENCE)
6364 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
6365 for (j = 0; vec[j]; j++)
6366 if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == vec[j])
6372 for (j = 0; vec[j]; j++)
6373 if (INSN_UID (insn) == vec[j])
6380 prologue_epilogue_contains (insn)
6383 if (prologue && contains (insn, prologue))
6385 if (epilogue && contains (insn, epilogue))
6389 #endif /* HAVE_prologue || HAVE_epilogue */
6391 /* Generate the prologue and epilogue RTL if the machine supports it. Thread
6392 this into place with notes indicating where the prologue ends and where
6393 the epilogue begins. Update the basic block information when possible. */
6396 thread_prologue_and_epilogue_insns (f)
6397 rtx f ATTRIBUTE_UNUSED;
6401 #ifdef HAVE_prologue
6407 seq = gen_prologue();
6410 /* Retain a map of the prologue insns. */
6411 if (GET_CODE (seq) != SEQUENCE)
6413 prologue = record_insns (seq);
6415 emit_note (NULL, NOTE_INSN_PROLOGUE_END);
6416 seq = gen_sequence ();
6419 /* If optimization is off, and perhaps in an empty function,
6420 the entry block will have no successors. */
6421 if (ENTRY_BLOCK_PTR->succ)
6423 /* Can't deal with multiple successsors of the entry block. */
6424 if (ENTRY_BLOCK_PTR->succ->succ_next)
6427 insert_insn_on_edge (seq, ENTRY_BLOCK_PTR->succ);
6431 emit_insn_after (seq, f);
6435 #ifdef HAVE_epilogue
6440 rtx tail = get_last_insn ();
6442 /* ??? This is gastly. If function returns were not done via uses,
6443 but via mark_regs_live_at_end, we could use insert_insn_on_edge
6444 and all of this uglyness would go away. */
6449 /* If the exit block has no non-fake predecessors, we don't
6450 need an epilogue. Furthermore, only pay attention to the
6451 fallthru predecessors; if (conditional) return insns were
6452 generated, by definition we do not need to emit epilogue
6455 for (e = EXIT_BLOCK_PTR->pred; e ; e = e->pred_next)
6456 if ((e->flags & EDGE_FAKE) == 0
6457 && (e->flags & EDGE_FALLTHRU) != 0)
6462 /* We can't handle multiple epilogues -- if one is needed,
6463 we won't be able to place it multiple times.
6465 ??? Fix epilogue expanders to not assume they are the
6466 last thing done compiling the function. Either that
6467 or copy_rtx each insn.
6469 ??? Blah, it's not a simple expression to assert that
6470 we've exactly one fallthru exit edge. */
6475 /* ??? If the last insn of the basic block is a jump, then we
6476 are creating a new basic block. Wimp out and leave these
6477 insns outside any block. */
6478 if (GET_CODE (tail) == JUMP_INSN)
6484 rtx prev, seq, first_use;
6486 /* Move the USE insns at the end of a function onto a list. */
6488 if (GET_CODE (prev) == BARRIER
6489 || GET_CODE (prev) == NOTE)
6490 prev = prev_nonnote_insn (prev);
6494 && GET_CODE (prev) == INSN
6495 && GET_CODE (PATTERN (prev)) == USE)
6497 /* If the end of the block is the use, grab hold of something
6498 else so that we emit barriers etc in the right place. */
6502 tail = PREV_INSN (tail);
6503 while (GET_CODE (tail) == INSN
6504 && GET_CODE (PATTERN (tail)) == USE);
6510 prev = prev_nonnote_insn (prev);
6515 NEXT_INSN (use) = first_use;
6516 PREV_INSN (first_use) = use;
6519 NEXT_INSN (use) = NULL_RTX;
6523 && GET_CODE (prev) == INSN
6524 && GET_CODE (PATTERN (prev)) == USE);
6527 /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG, the
6528 epilogue insns, the USE insns at the end of a function,
6529 the jump insn that returns, and then a BARRIER. */
6531 if (GET_CODE (tail) != BARRIER)
6533 prev = next_nonnote_insn (tail);
6534 if (!prev || GET_CODE (prev) != BARRIER)
6535 emit_barrier_after (tail);
6538 seq = gen_epilogue ();
6540 tail = emit_jump_insn_after (seq, tail);
6542 /* Insert the USE insns immediately before the return insn, which
6543 must be the last instruction emitted in the sequence. */
6545 emit_insns_before (first_use, tail);
6546 emit_note_after (NOTE_INSN_EPILOGUE_BEG, prev);
6548 /* Update the tail of the basic block. */
6552 /* Retain a map of the epilogue insns. */
6553 epilogue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : tail);
6560 commit_edge_insertions ();
6563 /* Reposition the prologue-end and epilogue-begin notes after instruction
6564 scheduling and delayed branch scheduling. */
6567 reposition_prologue_and_epilogue_notes (f)
6568 rtx f ATTRIBUTE_UNUSED;
6570 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
6571 /* Reposition the prologue and epilogue notes. */
6578 register rtx insn, note = 0;
6580 /* Scan from the beginning until we reach the last prologue insn.
6581 We apparently can't depend on basic_block_{head,end} after
6583 for (len = 0; prologue[len]; len++)
6585 for (insn = f; len && insn; insn = NEXT_INSN (insn))
6587 if (GET_CODE (insn) == NOTE)
6589 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
6592 else if ((len -= contains (insn, prologue)) == 0)
6595 /* Find the prologue-end note if we haven't already, and
6596 move it to just after the last prologue insn. */
6599 for (note = insn; (note = NEXT_INSN (note));)
6600 if (GET_CODE (note) == NOTE
6601 && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
6605 next = NEXT_INSN (note);
6607 /* Whether or not we can depend on BLOCK_HEAD,
6608 attempt to keep it up-to-date. */
6609 if (BLOCK_HEAD (0) == note)
6610 BLOCK_HEAD (0) = next;
6613 add_insn_after (note, insn);
6620 register rtx insn, note = 0;
6622 /* Scan from the end until we reach the first epilogue insn.
6623 We apparently can't depend on basic_block_{head,end} after
6625 for (len = 0; epilogue[len]; len++)
6627 for (insn = get_last_insn (); len && insn; insn = PREV_INSN (insn))
6629 if (GET_CODE (insn) == NOTE)
6631 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
6634 else if ((len -= contains (insn, epilogue)) == 0)
6636 /* Find the epilogue-begin note if we haven't already, and
6637 move it to just before the first epilogue insn. */
6640 for (note = insn; (note = PREV_INSN (note));)
6641 if (GET_CODE (note) == NOTE
6642 && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
6646 /* Whether or not we can depend on BLOCK_HEAD,
6647 attempt to keep it up-to-date. */
6649 && BLOCK_HEAD (n_basic_blocks-1) == insn)
6650 BLOCK_HEAD (n_basic_blocks-1) = note;
6653 add_insn_before (note, insn);
6658 #endif /* HAVE_prologue or HAVE_epilogue */
6661 /* Mark T for GC. */
6665 struct temp_slot *t;
6669 ggc_mark_rtx (t->slot);
6670 ggc_mark_rtx (t->address);
6671 ggc_mark_tree (t->rtl_expr);
6677 /* Mark P for GC. */
6680 mark_function_state (p)
6689 ggc_mark_rtx (p->arg_offset_rtx);
6691 if (p->x_parm_reg_stack_loc)
6692 for (i = p->x_max_parm_reg, r = p->x_parm_reg_stack_loc;
6696 ggc_mark_rtx (p->return_rtx);
6697 ggc_mark_rtx (p->x_cleanup_label);
6698 ggc_mark_rtx (p->x_return_label);
6699 ggc_mark_rtx (p->x_save_expr_regs);
6700 ggc_mark_rtx (p->x_stack_slot_list);
6701 ggc_mark_rtx (p->x_parm_birth_insn);
6702 ggc_mark_rtx (p->x_tail_recursion_label);
6703 ggc_mark_rtx (p->x_tail_recursion_reentry);
6704 ggc_mark_rtx (p->internal_arg_pointer);
6705 ggc_mark_rtx (p->x_arg_pointer_save_area);
6706 ggc_mark_tree (p->x_rtl_expr_chain);
6707 ggc_mark_rtx (p->x_last_parm_insn);
6708 ggc_mark_tree (p->x_context_display);
6709 ggc_mark_tree (p->x_trampoline_list);
6710 ggc_mark_rtx (p->epilogue_delay_list);
6712 mark_temp_slot (p->x_temp_slots);
6715 struct var_refs_queue *q = p->fixup_var_refs_queue;
6718 ggc_mark_rtx (q->modified);
6723 ggc_mark_rtx (p->x_nonlocal_goto_handler_slots);
6724 ggc_mark_rtx (p->x_nonlocal_goto_handler_labels);
6725 ggc_mark_rtx (p->x_nonlocal_goto_stack_level);
6726 ggc_mark_tree (p->x_nonlocal_labels);
6729 /* Mark the function chain ARG (which is really a struct function **)
6733 mark_function_chain (arg)
6736 struct function *f = *(struct function **) arg;
6738 for (; f; f = f->next_global)
6740 if (f->can_garbage_collect)
6743 ggc_mark_tree (f->decl);
6745 mark_function_state (f);
6746 mark_stmt_state (f->stmt);
6747 mark_eh_state (f->eh);
6748 mark_emit_state (f->emit);
6749 mark_varasm_state (f->varasm);
6751 ggc_mark_rtx (f->expr->x_saveregs_value);
6752 ggc_mark_rtx (f->expr->x_apply_args_value);
6753 ggc_mark_rtx (f->expr->x_forced_labels);
6755 if (mark_machine_status)
6756 (*mark_machine_status) (f);
6757 if (mark_lang_status)
6758 (*mark_lang_status) (f);
6760 if (f->original_arg_vector)
6761 ggc_mark_rtvec ((rtvec) f->original_arg_vector);
6762 if (f->original_decl_initial)
6763 ggc_mark_tree (f->original_decl_initial);
6767 /* Called once, at initialization, to initialize function.c. */
6770 init_function_once ()
6772 ggc_add_root (&all_functions, 1, sizeof all_functions,
6773 mark_function_chain);