* lib/objc.exp: Add -lposix4 on Solaris 2.6 and Solaris 2.7.
[official-gcc.git] / gcc / function.c
blob1bb7295e55c0b3a282e83de5f5e56a36c4ef9170
1 /* Expands front end tree to back end RTL for GNU C-Compiler
2 Copyright (C) 1987, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 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. */
41 #include "config.h"
42 #include "system.h"
43 #include "rtl.h"
44 #include "tree.h"
45 #include "flags.h"
46 #include "except.h"
47 #include "function.h"
48 #include "expr.h"
49 #include "regs.h"
50 #include "hard-reg-set.h"
51 #include "insn-config.h"
52 #include "recog.h"
53 #include "output.h"
54 #include "basic-block.h"
55 #include "obstack.h"
56 #include "toplev.h"
57 #include "hash.h"
58 #include "ggc.h"
59 #include "tm_p.h"
61 #ifndef ACCUMULATE_OUTGOING_ARGS
62 #define ACCUMULATE_OUTGOING_ARGS 0
63 #endif
65 #ifndef TRAMPOLINE_ALIGNMENT
66 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
67 #endif
69 #ifndef LOCAL_ALIGNMENT
70 #define LOCAL_ALIGNMENT(TYPE, ALIGNMENT) ALIGNMENT
71 #endif
73 #if !defined (PREFERRED_STACK_BOUNDARY) && defined (STACK_BOUNDARY)
74 #define PREFERRED_STACK_BOUNDARY STACK_BOUNDARY
75 #endif
77 /* Some systems use __main in a way incompatible with its use in gcc, in these
78 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
79 give the same symbol without quotes for an alternative entry point. You
80 must define both, or neither. */
81 #ifndef NAME__MAIN
82 #define NAME__MAIN "__main"
83 #define SYMBOL__MAIN __main
84 #endif
86 /* Round a value to the lowest integer less than it that is a multiple of
87 the required alignment. Avoid using division in case the value is
88 negative. Assume the alignment is a power of two. */
89 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
91 /* Similar, but round to the next highest integer that meets the
92 alignment. */
93 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
95 /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp
96 during rtl generation. If they are different register numbers, this is
97 always true. It may also be true if
98 FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl
99 generation. See fix_lexical_addr for details. */
101 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
102 #define NEED_SEPARATE_AP
103 #endif
105 /* Nonzero if function being compiled doesn't contain any calls
106 (ignoring the prologue and epilogue). This is set prior to
107 local register allocation and is valid for the remaining
108 compiler passes. */
109 int current_function_is_leaf;
111 /* Nonzero if function being compiled doesn't contain any instructions
112 that can throw an exception. This is set prior to final. */
114 int current_function_nothrow;
116 /* Nonzero if function being compiled doesn't modify the stack pointer
117 (ignoring the prologue and epilogue). This is only valid after
118 life_analysis has run. */
119 int current_function_sp_is_unchanging;
121 /* Nonzero if the function being compiled is a leaf function which only
122 uses leaf registers. This is valid after reload (specifically after
123 sched2) and is useful only if the port defines LEAF_REGISTERS. */
124 int current_function_uses_only_leaf_regs;
126 /* Nonzero once virtual register instantiation has been done.
127 assign_stack_local uses frame_pointer_rtx when this is nonzero. */
128 static int virtuals_instantiated;
130 /* These variables hold pointers to functions to create and destroy
131 target specific, per-function data structures. */
132 void (*init_machine_status) PARAMS ((struct function *));
133 void (*free_machine_status) PARAMS ((struct function *));
134 /* This variable holds a pointer to a function to register any
135 data items in the target specific, per-function data structure
136 that will need garbage collection. */
137 void (*mark_machine_status) PARAMS ((struct function *));
139 /* Likewise, but for language-specific data. */
140 void (*init_lang_status) PARAMS ((struct function *));
141 void (*save_lang_status) PARAMS ((struct function *));
142 void (*restore_lang_status) PARAMS ((struct function *));
143 void (*mark_lang_status) PARAMS ((struct function *));
144 void (*free_lang_status) PARAMS ((struct function *));
146 /* The FUNCTION_DECL for an inline function currently being expanded. */
147 tree inline_function_decl;
149 /* The currently compiled function. */
150 struct function *cfun = 0;
152 /* Global list of all compiled functions. */
153 struct function *all_functions = 0;
155 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
156 static varray_type prologue;
157 static varray_type epilogue;
159 /* Array of INSN_UIDs to hold the INSN_UIDs for each sibcall epilogue
160 in this function. */
161 static varray_type sibcall_epilogue;
163 /* In order to evaluate some expressions, such as function calls returning
164 structures in memory, we need to temporarily allocate stack locations.
165 We record each allocated temporary in the following structure.
167 Associated with each temporary slot is a nesting level. When we pop up
168 one level, all temporaries associated with the previous level are freed.
169 Normally, all temporaries are freed after the execution of the statement
170 in which they were created. However, if we are inside a ({...}) grouping,
171 the result may be in a temporary and hence must be preserved. If the
172 result could be in a temporary, we preserve it if we can determine which
173 one it is in. If we cannot determine which temporary may contain the
174 result, all temporaries are preserved. A temporary is preserved by
175 pretending it was allocated at the previous nesting level.
177 Automatic variables are also assigned temporary slots, at the nesting
178 level where they are defined. They are marked a "kept" so that
179 free_temp_slots will not free them. */
181 struct temp_slot
183 /* Points to next temporary slot. */
184 struct temp_slot *next;
185 /* The rtx to used to reference the slot. */
186 rtx slot;
187 /* The rtx used to represent the address if not the address of the
188 slot above. May be an EXPR_LIST if multiple addresses exist. */
189 rtx address;
190 /* The alignment (in bits) of the slot. */
191 int align;
192 /* The size, in units, of the slot. */
193 HOST_WIDE_INT size;
194 /* The type of the object in the slot, or zero if it doesn't correspond
195 to a type. We use this to determine whether a slot can be reused.
196 It can be reused if objects of the type of the new slot will always
197 conflict with objects of the type of the old slot. */
198 tree type;
199 /* The value of `sequence_rtl_expr' when this temporary is allocated. */
200 tree rtl_expr;
201 /* Non-zero if this temporary is currently in use. */
202 char in_use;
203 /* Non-zero if this temporary has its address taken. */
204 char addr_taken;
205 /* Nesting level at which this slot is being used. */
206 int level;
207 /* Non-zero if this should survive a call to free_temp_slots. */
208 int keep;
209 /* The offset of the slot from the frame_pointer, including extra space
210 for alignment. This info is for combine_temp_slots. */
211 HOST_WIDE_INT base_offset;
212 /* The size of the slot, including extra space for alignment. This
213 info is for combine_temp_slots. */
214 HOST_WIDE_INT full_size;
217 /* This structure is used to record MEMs or pseudos used to replace VAR, any
218 SUBREGs of VAR, and any MEMs containing VAR as an address. We need to
219 maintain this list in case two operands of an insn were required to match;
220 in that case we must ensure we use the same replacement. */
222 struct fixup_replacement
224 rtx old;
225 rtx new;
226 struct fixup_replacement *next;
229 struct insns_for_mem_entry {
230 /* The KEY in HE will be a MEM. */
231 struct hash_entry he;
232 /* These are the INSNS which reference the MEM. */
233 rtx insns;
236 /* Forward declarations. */
238 static rtx assign_stack_local_1 PARAMS ((enum machine_mode, HOST_WIDE_INT,
239 int, struct function *));
240 static rtx assign_stack_temp_for_type PARAMS ((enum machine_mode,
241 HOST_WIDE_INT, int, tree));
242 static struct temp_slot *find_temp_slot_from_address PARAMS ((rtx));
243 static void put_reg_into_stack PARAMS ((struct function *, rtx, tree,
244 enum machine_mode, enum machine_mode,
245 int, unsigned int, int,
246 struct hash_table *));
247 static void schedule_fixup_var_refs PARAMS ((struct function *, rtx, tree,
248 enum machine_mode,
249 struct hash_table *));
250 static void fixup_var_refs PARAMS ((rtx, enum machine_mode, int,
251 struct hash_table *));
252 static struct fixup_replacement
253 *find_fixup_replacement PARAMS ((struct fixup_replacement **, rtx));
254 static void fixup_var_refs_insns PARAMS ((rtx, rtx, enum machine_mode,
255 int, int));
256 static void fixup_var_refs_insns_with_hash
257 PARAMS ((struct hash_table *, rtx,
258 enum machine_mode, int));
259 static void fixup_var_refs_insn PARAMS ((rtx, rtx, enum machine_mode,
260 int, int));
261 static void fixup_var_refs_1 PARAMS ((rtx, enum machine_mode, rtx *, rtx,
262 struct fixup_replacement **));
263 static rtx fixup_memory_subreg PARAMS ((rtx, rtx, int));
264 static rtx walk_fixup_memory_subreg PARAMS ((rtx, rtx, int));
265 static rtx fixup_stack_1 PARAMS ((rtx, rtx));
266 static void optimize_bit_field PARAMS ((rtx, rtx, rtx *));
267 static void instantiate_decls PARAMS ((tree, int));
268 static void instantiate_decls_1 PARAMS ((tree, int));
269 static void instantiate_decl PARAMS ((rtx, HOST_WIDE_INT, int));
270 static rtx instantiate_new_reg PARAMS ((rtx, HOST_WIDE_INT *));
271 static int instantiate_virtual_regs_1 PARAMS ((rtx *, rtx, int));
272 static void delete_handlers PARAMS ((void));
273 static void pad_to_arg_alignment PARAMS ((struct args_size *, int,
274 struct args_size *));
275 #ifndef ARGS_GROW_DOWNWARD
276 static void pad_below PARAMS ((struct args_size *, enum machine_mode,
277 tree));
278 #endif
279 static rtx round_trampoline_addr PARAMS ((rtx));
280 static rtx adjust_trampoline_addr PARAMS ((rtx));
281 static tree *identify_blocks_1 PARAMS ((rtx, tree *, tree *, tree *));
282 static void reorder_blocks_0 PARAMS ((rtx));
283 static void reorder_blocks_1 PARAMS ((rtx, tree, varray_type *));
284 static tree blocks_nreverse PARAMS ((tree));
285 static int all_blocks PARAMS ((tree, tree *));
286 static tree *get_block_vector PARAMS ((tree, int *));
287 /* We always define `record_insns' even if its not used so that we
288 can always export `prologue_epilogue_contains'. */
289 static void record_insns PARAMS ((rtx, varray_type *)) ATTRIBUTE_UNUSED;
290 static int contains PARAMS ((rtx, varray_type));
291 #ifdef HAVE_return
292 static void emit_return_into_block PARAMS ((basic_block, rtx));
293 #endif
294 static void put_addressof_into_stack PARAMS ((rtx, struct hash_table *));
295 static bool purge_addressof_1 PARAMS ((rtx *, rtx, int, int,
296 struct hash_table *));
297 static void purge_single_hard_subreg_set PARAMS ((rtx));
298 #ifdef HAVE_epilogue
299 static void keep_stack_depressed PARAMS ((rtx));
300 #endif
301 static int is_addressof PARAMS ((rtx *, void *));
302 static struct hash_entry *insns_for_mem_newfunc PARAMS ((struct hash_entry *,
303 struct hash_table *,
304 hash_table_key));
305 static unsigned long insns_for_mem_hash PARAMS ((hash_table_key));
306 static bool insns_for_mem_comp PARAMS ((hash_table_key, hash_table_key));
307 static int insns_for_mem_walk PARAMS ((rtx *, void *));
308 static void compute_insns_for_mem PARAMS ((rtx, rtx, struct hash_table *));
309 static void mark_temp_slot PARAMS ((struct temp_slot *));
310 static void mark_function_status PARAMS ((struct function *));
311 static void mark_function_chain PARAMS ((void *));
312 static void prepare_function_start PARAMS ((void));
313 static void do_clobber_return_reg PARAMS ((rtx, void *));
314 static void do_use_return_reg PARAMS ((rtx, void *));
316 /* Pointer to chain of `struct function' for containing functions. */
317 struct function *outer_function_chain;
319 /* Given a function decl for a containing function,
320 return the `struct function' for it. */
322 struct function *
323 find_function_data (decl)
324 tree decl;
326 struct function *p;
328 for (p = outer_function_chain; p; p = p->next)
329 if (p->decl == decl)
330 return p;
332 abort ();
335 /* Save the current context for compilation of a nested function.
336 This is called from language-specific code. The caller should use
337 the save_lang_status callback to save any language-specific state,
338 since this function knows only about language-independent
339 variables. */
341 void
342 push_function_context_to (context)
343 tree context;
345 struct function *p, *context_data;
347 if (context)
349 context_data = (context == current_function_decl
350 ? cfun
351 : find_function_data (context));
352 context_data->contains_functions = 1;
355 if (cfun == 0)
356 init_dummy_function_start ();
357 p = cfun;
359 p->next = outer_function_chain;
360 outer_function_chain = p;
361 p->fixup_var_refs_queue = 0;
363 if (save_lang_status)
364 (*save_lang_status) (p);
366 cfun = 0;
369 void
370 push_function_context ()
372 push_function_context_to (current_function_decl);
375 /* Restore the last saved context, at the end of a nested function.
376 This function is called from language-specific code. */
378 void
379 pop_function_context_from (context)
380 tree context ATTRIBUTE_UNUSED;
382 struct function *p = outer_function_chain;
383 struct var_refs_queue *queue;
384 struct var_refs_queue *next;
386 cfun = p;
387 outer_function_chain = p->next;
389 current_function_decl = p->decl;
390 reg_renumber = 0;
392 restore_emit_status (p);
394 if (restore_lang_status)
395 (*restore_lang_status) (p);
397 /* Finish doing put_var_into_stack for any of our variables
398 which became addressable during the nested function. */
399 for (queue = p->fixup_var_refs_queue; queue; queue = next)
401 next = queue->next;
402 fixup_var_refs (queue->modified, queue->promoted_mode,
403 queue->unsignedp, 0);
404 free (queue);
406 p->fixup_var_refs_queue = 0;
408 /* Reset variables that have known state during rtx generation. */
409 rtx_equal_function_value_matters = 1;
410 virtuals_instantiated = 0;
411 generating_concat_p = 1;
414 void
415 pop_function_context ()
417 pop_function_context_from (current_function_decl);
420 /* Clear out all parts of the state in F that can safely be discarded
421 after the function has been parsed, but not compiled, to let
422 garbage collection reclaim the memory. */
424 void
425 free_after_parsing (f)
426 struct function *f;
428 /* f->expr->forced_labels is used by code generation. */
429 /* f->emit->regno_reg_rtx is used by code generation. */
430 /* f->varasm is used by code generation. */
431 /* f->eh->eh_return_stub_label is used by code generation. */
433 if (free_lang_status)
434 (*free_lang_status) (f);
435 free_stmt_status (f);
438 /* Clear out all parts of the state in F that can safely be discarded
439 after the function has been compiled, to let garbage collection
440 reclaim the memory. */
442 void
443 free_after_compilation (f)
444 struct function *f;
446 struct temp_slot *ts;
447 struct temp_slot *next;
449 free_eh_status (f);
450 free_expr_status (f);
451 free_emit_status (f);
452 free_varasm_status (f);
454 if (free_machine_status)
455 (*free_machine_status) (f);
457 if (f->x_parm_reg_stack_loc)
458 free (f->x_parm_reg_stack_loc);
460 for (ts = f->x_temp_slots; ts; ts = next)
462 next = ts->next;
463 free (ts);
465 f->x_temp_slots = NULL;
467 f->arg_offset_rtx = NULL;
468 f->return_rtx = NULL;
469 f->internal_arg_pointer = NULL;
470 f->x_nonlocal_labels = NULL;
471 f->x_nonlocal_goto_handler_slots = NULL;
472 f->x_nonlocal_goto_handler_labels = NULL;
473 f->x_nonlocal_goto_stack_level = NULL;
474 f->x_cleanup_label = NULL;
475 f->x_return_label = NULL;
476 f->x_save_expr_regs = NULL;
477 f->x_stack_slot_list = NULL;
478 f->x_rtl_expr_chain = NULL;
479 f->x_tail_recursion_label = NULL;
480 f->x_tail_recursion_reentry = NULL;
481 f->x_arg_pointer_save_area = NULL;
482 f->x_clobber_return_insn = NULL;
483 f->x_context_display = NULL;
484 f->x_trampoline_list = NULL;
485 f->x_parm_birth_insn = NULL;
486 f->x_last_parm_insn = NULL;
487 f->x_parm_reg_stack_loc = NULL;
488 f->fixup_var_refs_queue = NULL;
489 f->original_arg_vector = NULL;
490 f->original_decl_initial = NULL;
491 f->inl_last_parm_insn = NULL;
492 f->epilogue_delay_list = NULL;
495 /* Allocate fixed slots in the stack frame of the current function. */
497 /* Return size needed for stack frame based on slots so far allocated in
498 function F.
499 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
500 the caller may have to do that. */
502 HOST_WIDE_INT
503 get_func_frame_size (f)
504 struct function *f;
506 #ifdef FRAME_GROWS_DOWNWARD
507 return -f->x_frame_offset;
508 #else
509 return f->x_frame_offset;
510 #endif
513 /* Return size needed for stack frame based on slots so far allocated.
514 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
515 the caller may have to do that. */
516 HOST_WIDE_INT
517 get_frame_size ()
519 return get_func_frame_size (cfun);
522 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
523 with machine mode MODE.
525 ALIGN controls the amount of alignment for the address of the slot:
526 0 means according to MODE,
527 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
528 positive specifies alignment boundary in bits.
530 We do not round to stack_boundary here.
532 FUNCTION specifies the function to allocate in. */
534 static rtx
535 assign_stack_local_1 (mode, size, align, function)
536 enum machine_mode mode;
537 HOST_WIDE_INT size;
538 int align;
539 struct function *function;
541 register rtx x, addr;
542 int bigend_correction = 0;
543 int alignment;
545 if (align == 0)
547 tree type;
549 if (mode == BLKmode)
550 alignment = BIGGEST_ALIGNMENT;
551 else
552 alignment = GET_MODE_ALIGNMENT (mode);
554 /* Allow the target to (possibly) increase the alignment of this
555 stack slot. */
556 type = type_for_mode (mode, 0);
557 if (type)
558 alignment = LOCAL_ALIGNMENT (type, alignment);
560 alignment /= BITS_PER_UNIT;
562 else if (align == -1)
564 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
565 size = CEIL_ROUND (size, alignment);
567 else
568 alignment = align / BITS_PER_UNIT;
570 #ifdef FRAME_GROWS_DOWNWARD
571 function->x_frame_offset -= size;
572 #endif
574 /* Ignore alignment we can't do with expected alignment of the boundary. */
575 if (alignment * BITS_PER_UNIT > PREFERRED_STACK_BOUNDARY)
576 alignment = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
578 if (function->stack_alignment_needed < alignment * BITS_PER_UNIT)
579 function->stack_alignment_needed = alignment * BITS_PER_UNIT;
581 /* Round frame offset to that alignment.
582 We must be careful here, since FRAME_OFFSET might be negative and
583 division with a negative dividend isn't as well defined as we might
584 like. So we instead assume that ALIGNMENT is a power of two and
585 use logical operations which are unambiguous. */
586 #ifdef FRAME_GROWS_DOWNWARD
587 function->x_frame_offset = FLOOR_ROUND (function->x_frame_offset, alignment);
588 #else
589 function->x_frame_offset = CEIL_ROUND (function->x_frame_offset, alignment);
590 #endif
592 /* On a big-endian machine, if we are allocating more space than we will use,
593 use the least significant bytes of those that are allocated. */
594 if (BYTES_BIG_ENDIAN && mode != BLKmode)
595 bigend_correction = size - GET_MODE_SIZE (mode);
597 /* If we have already instantiated virtual registers, return the actual
598 address relative to the frame pointer. */
599 if (function == cfun && virtuals_instantiated)
600 addr = plus_constant (frame_pointer_rtx,
601 (frame_offset + bigend_correction
602 + STARTING_FRAME_OFFSET));
603 else
604 addr = plus_constant (virtual_stack_vars_rtx,
605 function->x_frame_offset + bigend_correction);
607 #ifndef FRAME_GROWS_DOWNWARD
608 function->x_frame_offset += size;
609 #endif
611 x = gen_rtx_MEM (mode, addr);
613 function->x_stack_slot_list
614 = gen_rtx_EXPR_LIST (VOIDmode, x, function->x_stack_slot_list);
616 return x;
619 /* Wrapper around assign_stack_local_1; assign a local stack slot for the
620 current function. */
623 assign_stack_local (mode, size, align)
624 enum machine_mode mode;
625 HOST_WIDE_INT size;
626 int align;
628 return assign_stack_local_1 (mode, size, align, cfun);
631 /* Allocate a temporary stack slot and record it for possible later
632 reuse.
634 MODE is the machine mode to be given to the returned rtx.
636 SIZE is the size in units of the space required. We do no rounding here
637 since assign_stack_local will do any required rounding.
639 KEEP is 1 if this slot is to be retained after a call to
640 free_temp_slots. Automatic variables for a block are allocated
641 with this flag. KEEP is 2 if we allocate a longer term temporary,
642 whose lifetime is controlled by CLEANUP_POINT_EXPRs. KEEP is 3
643 if we are to allocate something at an inner level to be treated as
644 a variable in the block (e.g., a SAVE_EXPR).
646 TYPE is the type that will be used for the stack slot. */
648 static rtx
649 assign_stack_temp_for_type (mode, size, keep, type)
650 enum machine_mode mode;
651 HOST_WIDE_INT size;
652 int keep;
653 tree type;
655 int align;
656 struct temp_slot *p, *best_p = 0;
658 /* If SIZE is -1 it means that somebody tried to allocate a temporary
659 of a variable size. */
660 if (size == -1)
661 abort ();
663 if (mode == BLKmode)
664 align = BIGGEST_ALIGNMENT;
665 else
666 align = GET_MODE_ALIGNMENT (mode);
668 if (! type)
669 type = type_for_mode (mode, 0);
671 if (type)
672 align = LOCAL_ALIGNMENT (type, align);
674 /* Try to find an available, already-allocated temporary of the proper
675 mode which meets the size and alignment requirements. Choose the
676 smallest one with the closest alignment. */
677 for (p = temp_slots; p; p = p->next)
678 if (p->align >= align && p->size >= size && GET_MODE (p->slot) == mode
679 && ! p->in_use
680 && objects_must_conflict_p (p->type, type)
681 && (best_p == 0 || best_p->size > p->size
682 || (best_p->size == p->size && best_p->align > p->align)))
684 if (p->align == align && p->size == size)
686 best_p = 0;
687 break;
689 best_p = p;
692 /* Make our best, if any, the one to use. */
693 if (best_p)
695 /* If there are enough aligned bytes left over, make them into a new
696 temp_slot so that the extra bytes don't get wasted. Do this only
697 for BLKmode slots, so that we can be sure of the alignment. */
698 if (GET_MODE (best_p->slot) == BLKmode)
700 int alignment = best_p->align / BITS_PER_UNIT;
701 HOST_WIDE_INT rounded_size = CEIL_ROUND (size, alignment);
703 if (best_p->size - rounded_size >= alignment)
705 p = (struct temp_slot *) xmalloc (sizeof (struct temp_slot));
706 p->in_use = p->addr_taken = 0;
707 p->size = best_p->size - rounded_size;
708 p->base_offset = best_p->base_offset + rounded_size;
709 p->full_size = best_p->full_size - rounded_size;
710 p->slot = gen_rtx_MEM (BLKmode,
711 plus_constant (XEXP (best_p->slot, 0),
712 rounded_size));
713 p->align = best_p->align;
714 p->address = 0;
715 p->rtl_expr = 0;
716 p->type = best_p->type;
717 p->next = temp_slots;
718 temp_slots = p;
720 stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, p->slot,
721 stack_slot_list);
723 best_p->size = rounded_size;
724 best_p->full_size = rounded_size;
728 p = best_p;
731 /* If we still didn't find one, make a new temporary. */
732 if (p == 0)
734 HOST_WIDE_INT frame_offset_old = frame_offset;
736 p = (struct temp_slot *) xmalloc (sizeof (struct temp_slot));
738 /* We are passing an explicit alignment request to assign_stack_local.
739 One side effect of that is assign_stack_local will not round SIZE
740 to ensure the frame offset remains suitably aligned.
742 So for requests which depended on the rounding of SIZE, we go ahead
743 and round it now. We also make sure ALIGNMENT is at least
744 BIGGEST_ALIGNMENT. */
745 if (mode == BLKmode && align < BIGGEST_ALIGNMENT)
746 abort();
747 p->slot = assign_stack_local (mode,
748 (mode == BLKmode
749 ? CEIL_ROUND (size, align / BITS_PER_UNIT)
750 : size),
751 align);
753 p->align = align;
755 /* The following slot size computation is necessary because we don't
756 know the actual size of the temporary slot until assign_stack_local
757 has performed all the frame alignment and size rounding for the
758 requested temporary. Note that extra space added for alignment
759 can be either above or below this stack slot depending on which
760 way the frame grows. We include the extra space if and only if it
761 is above this slot. */
762 #ifdef FRAME_GROWS_DOWNWARD
763 p->size = frame_offset_old - frame_offset;
764 #else
765 p->size = size;
766 #endif
768 /* Now define the fields used by combine_temp_slots. */
769 #ifdef FRAME_GROWS_DOWNWARD
770 p->base_offset = frame_offset;
771 p->full_size = frame_offset_old - frame_offset;
772 #else
773 p->base_offset = frame_offset_old;
774 p->full_size = frame_offset - frame_offset_old;
775 #endif
776 p->address = 0;
777 p->next = temp_slots;
778 temp_slots = p;
781 p->in_use = 1;
782 p->addr_taken = 0;
783 p->rtl_expr = seq_rtl_expr;
784 p->type = type;
786 if (keep == 2)
788 p->level = target_temp_slot_level;
789 p->keep = 0;
791 else if (keep == 3)
793 p->level = var_temp_slot_level;
794 p->keep = 0;
796 else
798 p->level = temp_slot_level;
799 p->keep = keep;
802 /* We may be reusing an old slot, so clear any MEM flags that may have been
803 set from before. */
804 RTX_UNCHANGING_P (p->slot) = 0;
805 MEM_IN_STRUCT_P (p->slot) = 0;
806 MEM_SCALAR_P (p->slot) = 0;
807 MEM_VOLATILE_P (p->slot) = 0;
809 /* If we know the alias set for the memory that will be used, use
810 it. If there's no TYPE, then we don't know anything about the
811 alias set for the memory. */
812 if (type)
813 MEM_ALIAS_SET (p->slot) = get_alias_set (type);
814 else
815 MEM_ALIAS_SET (p->slot) = 0;
817 /* If a type is specified, set the relevant flags. */
818 if (type != 0)
820 RTX_UNCHANGING_P (p->slot) = TYPE_READONLY (type);
821 MEM_VOLATILE_P (p->slot) = TYPE_VOLATILE (type);
822 MEM_SET_IN_STRUCT_P (p->slot, AGGREGATE_TYPE_P (type));
825 return p->slot;
828 /* Allocate a temporary stack slot and record it for possible later
829 reuse. First three arguments are same as in preceding function. */
832 assign_stack_temp (mode, size, keep)
833 enum machine_mode mode;
834 HOST_WIDE_INT size;
835 int keep;
837 return assign_stack_temp_for_type (mode, size, keep, NULL_TREE);
840 /* Assign a temporary of given TYPE.
841 KEEP is as for assign_stack_temp.
842 MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
843 it is 0 if a register is OK.
844 DONT_PROMOTE is 1 if we should not promote values in register
845 to wider modes. */
848 assign_temp (type, keep, memory_required, dont_promote)
849 tree type;
850 int keep;
851 int memory_required;
852 int dont_promote ATTRIBUTE_UNUSED;
854 enum machine_mode mode = TYPE_MODE (type);
855 #ifndef PROMOTE_FOR_CALL_ONLY
856 int unsignedp = TREE_UNSIGNED (type);
857 #endif
859 if (mode == BLKmode || memory_required)
861 HOST_WIDE_INT size = int_size_in_bytes (type);
862 rtx tmp;
864 /* Zero sized arrays are GNU C extension. Set size to 1 to avoid
865 problems with allocating the stack space. */
866 if (size == 0)
867 size = 1;
869 /* Unfortunately, we don't yet know how to allocate variable-sized
870 temporaries. However, sometimes we have a fixed upper limit on
871 the size (which is stored in TYPE_ARRAY_MAX_SIZE) and can use that
872 instead. This is the case for Chill variable-sized strings. */
873 if (size == -1 && TREE_CODE (type) == ARRAY_TYPE
874 && TYPE_ARRAY_MAX_SIZE (type) != NULL_TREE
875 && host_integerp (TYPE_ARRAY_MAX_SIZE (type), 1))
876 size = tree_low_cst (TYPE_ARRAY_MAX_SIZE (type), 1);
878 tmp = assign_stack_temp_for_type (mode, size, keep, type);
879 return tmp;
882 #ifndef PROMOTE_FOR_CALL_ONLY
883 if (! dont_promote)
884 mode = promote_mode (type, mode, &unsignedp, 0);
885 #endif
887 return gen_reg_rtx (mode);
890 /* Combine temporary stack slots which are adjacent on the stack.
892 This allows for better use of already allocated stack space. This is only
893 done for BLKmode slots because we can be sure that we won't have alignment
894 problems in this case. */
896 void
897 combine_temp_slots ()
899 struct temp_slot *p, *q;
900 struct temp_slot *prev_p, *prev_q;
901 int num_slots;
903 /* We can't combine slots, because the information about which slot
904 is in which alias set will be lost. */
905 if (flag_strict_aliasing)
906 return;
908 /* If there are a lot of temp slots, don't do anything unless
909 high levels of optimizaton. */
910 if (! flag_expensive_optimizations)
911 for (p = temp_slots, num_slots = 0; p; p = p->next, num_slots++)
912 if (num_slots > 100 || (num_slots > 10 && optimize == 0))
913 return;
915 for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots)
917 int delete_p = 0;
919 if (! p->in_use && GET_MODE (p->slot) == BLKmode)
920 for (q = p->next, prev_q = p; q; q = prev_q->next)
922 int delete_q = 0;
923 if (! q->in_use && GET_MODE (q->slot) == BLKmode)
925 if (p->base_offset + p->full_size == q->base_offset)
927 /* Q comes after P; combine Q into P. */
928 p->size += q->size;
929 p->full_size += q->full_size;
930 delete_q = 1;
932 else if (q->base_offset + q->full_size == p->base_offset)
934 /* P comes after Q; combine P into Q. */
935 q->size += p->size;
936 q->full_size += p->full_size;
937 delete_p = 1;
938 break;
941 /* Either delete Q or advance past it. */
942 if (delete_q)
944 prev_q->next = q->next;
945 free (q);
947 else
948 prev_q = q;
950 /* Either delete P or advance past it. */
951 if (delete_p)
953 if (prev_p)
954 prev_p->next = p->next;
955 else
956 temp_slots = p->next;
958 else
959 prev_p = p;
963 /* Find the temp slot corresponding to the object at address X. */
965 static struct temp_slot *
966 find_temp_slot_from_address (x)
967 rtx x;
969 struct temp_slot *p;
970 rtx next;
972 for (p = temp_slots; p; p = p->next)
974 if (! p->in_use)
975 continue;
977 else if (XEXP (p->slot, 0) == x
978 || p->address == x
979 || (GET_CODE (x) == PLUS
980 && XEXP (x, 0) == virtual_stack_vars_rtx
981 && GET_CODE (XEXP (x, 1)) == CONST_INT
982 && INTVAL (XEXP (x, 1)) >= p->base_offset
983 && INTVAL (XEXP (x, 1)) < p->base_offset + p->full_size))
984 return p;
986 else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST)
987 for (next = p->address; next; next = XEXP (next, 1))
988 if (XEXP (next, 0) == x)
989 return p;
992 /* If we have a sum involving a register, see if it points to a temp
993 slot. */
994 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == REG
995 && (p = find_temp_slot_from_address (XEXP (x, 0))) != 0)
996 return p;
997 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG
998 && (p = find_temp_slot_from_address (XEXP (x, 1))) != 0)
999 return p;
1001 return 0;
1004 /* Indicate that NEW is an alternate way of referring to the temp slot
1005 that previously was known by OLD. */
1007 void
1008 update_temp_slot_address (old, new)
1009 rtx old, new;
1011 struct temp_slot *p;
1013 if (rtx_equal_p (old, new))
1014 return;
1016 p = find_temp_slot_from_address (old);
1018 /* If we didn't find one, see if both OLD is a PLUS. If so, and NEW
1019 is a register, see if one operand of the PLUS is a temporary
1020 location. If so, NEW points into it. Otherwise, if both OLD and
1021 NEW are a PLUS and if there is a register in common between them.
1022 If so, try a recursive call on those values. */
1023 if (p == 0)
1025 if (GET_CODE (old) != PLUS)
1026 return;
1028 if (GET_CODE (new) == REG)
1030 update_temp_slot_address (XEXP (old, 0), new);
1031 update_temp_slot_address (XEXP (old, 1), new);
1032 return;
1034 else if (GET_CODE (new) != PLUS)
1035 return;
1037 if (rtx_equal_p (XEXP (old, 0), XEXP (new, 0)))
1038 update_temp_slot_address (XEXP (old, 1), XEXP (new, 1));
1039 else if (rtx_equal_p (XEXP (old, 1), XEXP (new, 0)))
1040 update_temp_slot_address (XEXP (old, 0), XEXP (new, 1));
1041 else if (rtx_equal_p (XEXP (old, 0), XEXP (new, 1)))
1042 update_temp_slot_address (XEXP (old, 1), XEXP (new, 0));
1043 else if (rtx_equal_p (XEXP (old, 1), XEXP (new, 1)))
1044 update_temp_slot_address (XEXP (old, 0), XEXP (new, 0));
1046 return;
1049 /* Otherwise add an alias for the temp's address. */
1050 else if (p->address == 0)
1051 p->address = new;
1052 else
1054 if (GET_CODE (p->address) != EXPR_LIST)
1055 p->address = gen_rtx_EXPR_LIST (VOIDmode, p->address, NULL_RTX);
1057 p->address = gen_rtx_EXPR_LIST (VOIDmode, new, p->address);
1061 /* If X could be a reference to a temporary slot, mark the fact that its
1062 address was taken. */
1064 void
1065 mark_temp_addr_taken (x)
1066 rtx x;
1068 struct temp_slot *p;
1070 if (x == 0)
1071 return;
1073 /* If X is not in memory or is at a constant address, it cannot be in
1074 a temporary slot. */
1075 if (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1076 return;
1078 p = find_temp_slot_from_address (XEXP (x, 0));
1079 if (p != 0)
1080 p->addr_taken = 1;
1083 /* If X could be a reference to a temporary slot, mark that slot as
1084 belonging to the to one level higher than the current level. If X
1085 matched one of our slots, just mark that one. Otherwise, we can't
1086 easily predict which it is, so upgrade all of them. Kept slots
1087 need not be touched.
1089 This is called when an ({...}) construct occurs and a statement
1090 returns a value in memory. */
1092 void
1093 preserve_temp_slots (x)
1094 rtx x;
1096 struct temp_slot *p = 0;
1098 /* If there is no result, we still might have some objects whose address
1099 were taken, so we need to make sure they stay around. */
1100 if (x == 0)
1102 for (p = temp_slots; p; p = p->next)
1103 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1104 p->level--;
1106 return;
1109 /* If X is a register that is being used as a pointer, see if we have
1110 a temporary slot we know it points to. To be consistent with
1111 the code below, we really should preserve all non-kept slots
1112 if we can't find a match, but that seems to be much too costly. */
1113 if (GET_CODE (x) == REG && REG_POINTER (x))
1114 p = find_temp_slot_from_address (x);
1116 /* If X is not in memory or is at a constant address, it cannot be in
1117 a temporary slot, but it can contain something whose address was
1118 taken. */
1119 if (p == 0 && (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))))
1121 for (p = temp_slots; p; p = p->next)
1122 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1123 p->level--;
1125 return;
1128 /* First see if we can find a match. */
1129 if (p == 0)
1130 p = find_temp_slot_from_address (XEXP (x, 0));
1132 if (p != 0)
1134 /* Move everything at our level whose address was taken to our new
1135 level in case we used its address. */
1136 struct temp_slot *q;
1138 if (p->level == temp_slot_level)
1140 for (q = temp_slots; q; q = q->next)
1141 if (q != p && q->addr_taken && q->level == p->level)
1142 q->level--;
1144 p->level--;
1145 p->addr_taken = 0;
1147 return;
1150 /* Otherwise, preserve all non-kept slots at this level. */
1151 for (p = temp_slots; p; p = p->next)
1152 if (p->in_use && p->level == temp_slot_level && ! p->keep)
1153 p->level--;
1156 /* X is the result of an RTL_EXPR. If it is a temporary slot associated
1157 with that RTL_EXPR, promote it into a temporary slot at the present
1158 level so it will not be freed when we free slots made in the
1159 RTL_EXPR. */
1161 void
1162 preserve_rtl_expr_result (x)
1163 rtx x;
1165 struct temp_slot *p;
1167 /* If X is not in memory or is at a constant address, it cannot be in
1168 a temporary slot. */
1169 if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1170 return;
1172 /* If we can find a match, move it to our level unless it is already at
1173 an upper level. */
1174 p = find_temp_slot_from_address (XEXP (x, 0));
1175 if (p != 0)
1177 p->level = MIN (p->level, temp_slot_level);
1178 p->rtl_expr = 0;
1181 return;
1184 /* Free all temporaries used so far. This is normally called at the end
1185 of generating code for a statement. Don't free any temporaries
1186 currently in use for an RTL_EXPR that hasn't yet been emitted.
1187 We could eventually do better than this since it can be reused while
1188 generating the same RTL_EXPR, but this is complex and probably not
1189 worthwhile. */
1191 void
1192 free_temp_slots ()
1194 struct temp_slot *p;
1196 for (p = temp_slots; p; p = p->next)
1197 if (p->in_use && p->level == temp_slot_level && ! p->keep
1198 && p->rtl_expr == 0)
1199 p->in_use = 0;
1201 combine_temp_slots ();
1204 /* Free all temporary slots used in T, an RTL_EXPR node. */
1206 void
1207 free_temps_for_rtl_expr (t)
1208 tree t;
1210 struct temp_slot *p;
1212 for (p = temp_slots; p; p = p->next)
1213 if (p->rtl_expr == t)
1215 /* If this slot is below the current TEMP_SLOT_LEVEL, then it
1216 needs to be preserved. This can happen if a temporary in
1217 the RTL_EXPR was addressed; preserve_temp_slots will move
1218 the temporary into a higher level. */
1219 if (temp_slot_level <= p->level)
1220 p->in_use = 0;
1221 else
1222 p->rtl_expr = NULL_TREE;
1225 combine_temp_slots ();
1228 /* Mark all temporaries ever allocated in this function as not suitable
1229 for reuse until the current level is exited. */
1231 void
1232 mark_all_temps_used ()
1234 struct temp_slot *p;
1236 for (p = temp_slots; p; p = p->next)
1238 p->in_use = p->keep = 1;
1239 p->level = MIN (p->level, temp_slot_level);
1243 /* Push deeper into the nesting level for stack temporaries. */
1245 void
1246 push_temp_slots ()
1248 temp_slot_level++;
1251 /* Likewise, but save the new level as the place to allocate variables
1252 for blocks. */
1254 #if 0
1255 void
1256 push_temp_slots_for_block ()
1258 push_temp_slots ();
1260 var_temp_slot_level = temp_slot_level;
1263 /* Likewise, but save the new level as the place to allocate temporaries
1264 for TARGET_EXPRs. */
1266 void
1267 push_temp_slots_for_target ()
1269 push_temp_slots ();
1271 target_temp_slot_level = temp_slot_level;
1274 /* Set and get the value of target_temp_slot_level. The only
1275 permitted use of these functions is to save and restore this value. */
1278 get_target_temp_slot_level ()
1280 return target_temp_slot_level;
1283 void
1284 set_target_temp_slot_level (level)
1285 int level;
1287 target_temp_slot_level = level;
1289 #endif
1291 /* Pop a temporary nesting level. All slots in use in the current level
1292 are freed. */
1294 void
1295 pop_temp_slots ()
1297 struct temp_slot *p;
1299 for (p = temp_slots; p; p = p->next)
1300 if (p->in_use && p->level == temp_slot_level && p->rtl_expr == 0)
1301 p->in_use = 0;
1303 combine_temp_slots ();
1305 temp_slot_level--;
1308 /* Initialize temporary slots. */
1310 void
1311 init_temp_slots ()
1313 /* We have not allocated any temporaries yet. */
1314 temp_slots = 0;
1315 temp_slot_level = 0;
1316 var_temp_slot_level = 0;
1317 target_temp_slot_level = 0;
1320 /* Retroactively move an auto variable from a register to a stack slot.
1321 This is done when an address-reference to the variable is seen. */
1323 void
1324 put_var_into_stack (decl)
1325 tree decl;
1327 register rtx reg;
1328 enum machine_mode promoted_mode, decl_mode;
1329 struct function *function = 0;
1330 tree context;
1331 int can_use_addressof;
1332 int volatilep = TREE_CODE (decl) != SAVE_EXPR && TREE_THIS_VOLATILE (decl);
1333 int usedp = (TREE_USED (decl)
1334 || (TREE_CODE (decl) != SAVE_EXPR && DECL_INITIAL (decl) != 0));
1336 context = decl_function_context (decl);
1338 /* Get the current rtl used for this object and its original mode. */
1339 reg = (TREE_CODE (decl) == SAVE_EXPR
1340 ? SAVE_EXPR_RTL (decl)
1341 : DECL_RTL_IF_SET (decl));
1343 /* No need to do anything if decl has no rtx yet
1344 since in that case caller is setting TREE_ADDRESSABLE
1345 and a stack slot will be assigned when the rtl is made. */
1346 if (reg == 0)
1347 return;
1349 /* Get the declared mode for this object. */
1350 decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl))
1351 : DECL_MODE (decl));
1352 /* Get the mode it's actually stored in. */
1353 promoted_mode = GET_MODE (reg);
1355 /* If this variable comes from an outer function,
1356 find that function's saved context. */
1357 if (context != current_function_decl && context != inline_function_decl)
1358 for (function = outer_function_chain; function; function = function->next)
1359 if (function->decl == context)
1360 break;
1362 /* If this is a variable-size object with a pseudo to address it,
1363 put that pseudo into the stack, if the var is nonlocal. */
1364 if (TREE_CODE (decl) != SAVE_EXPR && DECL_NONLOCAL (decl)
1365 && GET_CODE (reg) == MEM
1366 && GET_CODE (XEXP (reg, 0)) == REG
1367 && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER)
1369 reg = XEXP (reg, 0);
1370 decl_mode = promoted_mode = GET_MODE (reg);
1373 can_use_addressof
1374 = (function == 0
1375 && optimize > 0
1376 /* FIXME make it work for promoted modes too */
1377 && decl_mode == promoted_mode
1378 #ifdef NON_SAVING_SETJMP
1379 && ! (NON_SAVING_SETJMP && current_function_calls_setjmp)
1380 #endif
1383 /* If we can't use ADDRESSOF, make sure we see through one we already
1384 generated. */
1385 if (! can_use_addressof && GET_CODE (reg) == MEM
1386 && GET_CODE (XEXP (reg, 0)) == ADDRESSOF)
1387 reg = XEXP (XEXP (reg, 0), 0);
1389 /* Now we should have a value that resides in one or more pseudo regs. */
1391 if (GET_CODE (reg) == REG)
1393 /* If this variable lives in the current function and we don't need
1394 to put things in the stack for the sake of setjmp, try to keep it
1395 in a register until we know we actually need the address. */
1396 if (can_use_addressof)
1397 gen_mem_addressof (reg, decl);
1398 else
1399 put_reg_into_stack (function, reg, TREE_TYPE (decl), promoted_mode,
1400 decl_mode, volatilep, 0, usedp, 0);
1402 else if (GET_CODE (reg) == CONCAT)
1404 /* A CONCAT contains two pseudos; put them both in the stack.
1405 We do it so they end up consecutive.
1406 We fixup references to the parts only after we fixup references
1407 to the whole CONCAT, lest we do double fixups for the latter
1408 references. */
1409 enum machine_mode part_mode = GET_MODE (XEXP (reg, 0));
1410 tree part_type = type_for_mode (part_mode, 0);
1411 rtx lopart = XEXP (reg, 0);
1412 rtx hipart = XEXP (reg, 1);
1413 #ifdef FRAME_GROWS_DOWNWARD
1414 /* Since part 0 should have a lower address, do it second. */
1415 put_reg_into_stack (function, hipart, part_type, part_mode,
1416 part_mode, volatilep, 0, 0, 0);
1417 put_reg_into_stack (function, lopart, part_type, part_mode,
1418 part_mode, volatilep, 0, 0, 0);
1419 #else
1420 put_reg_into_stack (function, lopart, part_type, part_mode,
1421 part_mode, volatilep, 0, 0, 0);
1422 put_reg_into_stack (function, hipart, part_type, part_mode,
1423 part_mode, volatilep, 0, 0, 0);
1424 #endif
1426 /* Change the CONCAT into a combined MEM for both parts. */
1427 PUT_CODE (reg, MEM);
1428 set_mem_attributes (reg, decl, 1);
1430 /* The two parts are in memory order already.
1431 Use the lower parts address as ours. */
1432 XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0);
1433 /* Prevent sharing of rtl that might lose. */
1434 if (GET_CODE (XEXP (reg, 0)) == PLUS)
1435 XEXP (reg, 0) = copy_rtx (XEXP (reg, 0));
1436 if (usedp)
1438 schedule_fixup_var_refs (function, reg, TREE_TYPE (decl),
1439 promoted_mode, 0);
1440 schedule_fixup_var_refs (function, lopart, part_type, part_mode, 0);
1441 schedule_fixup_var_refs (function, hipart, part_type, part_mode, 0);
1444 else
1445 return;
1447 if (current_function_check_memory_usage)
1448 emit_library_call (chkr_set_right_libfunc, LCT_CONST_MAKE_BLOCK, VOIDmode,
1449 3, XEXP (reg, 0), Pmode,
1450 GEN_INT (GET_MODE_SIZE (GET_MODE (reg))),
1451 TYPE_MODE (sizetype),
1452 GEN_INT (MEMORY_USE_RW),
1453 TYPE_MODE (integer_type_node));
1456 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1457 into the stack frame of FUNCTION (0 means the current function).
1458 DECL_MODE is the machine mode of the user-level data type.
1459 PROMOTED_MODE is the machine mode of the register.
1460 VOLATILE_P is nonzero if this is for a "volatile" decl.
1461 USED_P is nonzero if this reg might have already been used in an insn. */
1463 static void
1464 put_reg_into_stack (function, reg, type, promoted_mode, decl_mode, volatile_p,
1465 original_regno, used_p, ht)
1466 struct function *function;
1467 rtx reg;
1468 tree type;
1469 enum machine_mode promoted_mode, decl_mode;
1470 int volatile_p;
1471 unsigned int original_regno;
1472 int used_p;
1473 struct hash_table *ht;
1475 struct function *func = function ? function : cfun;
1476 rtx new = 0;
1477 unsigned int regno = original_regno;
1479 if (regno == 0)
1480 regno = REGNO (reg);
1482 if (regno < func->x_max_parm_reg)
1483 new = func->x_parm_reg_stack_loc[regno];
1485 if (new == 0)
1486 new = assign_stack_local_1 (decl_mode, GET_MODE_SIZE (decl_mode), 0, func);
1488 PUT_CODE (reg, MEM);
1489 PUT_MODE (reg, decl_mode);
1490 XEXP (reg, 0) = XEXP (new, 0);
1491 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
1492 MEM_VOLATILE_P (reg) = volatile_p;
1494 /* If this is a memory ref that contains aggregate components,
1495 mark it as such for cse and loop optimize. If we are reusing a
1496 previously generated stack slot, then we need to copy the bit in
1497 case it was set for other reasons. For instance, it is set for
1498 __builtin_va_alist. */
1499 if (type)
1501 MEM_SET_IN_STRUCT_P (reg,
1502 AGGREGATE_TYPE_P (type) || MEM_IN_STRUCT_P (new));
1503 MEM_ALIAS_SET (reg) = get_alias_set (type);
1505 if (used_p)
1506 schedule_fixup_var_refs (function, reg, type, promoted_mode, ht);
1509 /* Make sure that all refs to the variable, previously made
1510 when it was a register, are fixed up to be valid again.
1511 See function above for meaning of arguments. */
1513 static void
1514 schedule_fixup_var_refs (function, reg, type, promoted_mode, ht)
1515 struct function *function;
1516 rtx reg;
1517 tree type;
1518 enum machine_mode promoted_mode;
1519 struct hash_table *ht;
1521 int unsigned_p = type ? TREE_UNSIGNED (type) : 0;
1523 if (function != 0)
1525 struct var_refs_queue *temp;
1527 temp
1528 = (struct var_refs_queue *) xmalloc (sizeof (struct var_refs_queue));
1529 temp->modified = reg;
1530 temp->promoted_mode = promoted_mode;
1531 temp->unsignedp = unsigned_p;
1532 temp->next = function->fixup_var_refs_queue;
1533 function->fixup_var_refs_queue = temp;
1535 else
1536 /* Variable is local; fix it up now. */
1537 fixup_var_refs (reg, promoted_mode, unsigned_p, ht);
1540 static void
1541 fixup_var_refs (var, promoted_mode, unsignedp, ht)
1542 rtx var;
1543 enum machine_mode promoted_mode;
1544 int unsignedp;
1545 struct hash_table *ht;
1547 tree pending;
1548 rtx first_insn = get_insns ();
1549 struct sequence_stack *stack = seq_stack;
1550 tree rtl_exps = rtl_expr_chain;
1552 /* If there's a hash table, it must record all uses of VAR. */
1553 if (ht)
1555 if (stack != 0)
1556 abort ();
1557 fixup_var_refs_insns_with_hash (ht, var, promoted_mode, unsignedp);
1558 return;
1561 fixup_var_refs_insns (first_insn, var, promoted_mode, unsignedp,
1562 stack == 0);
1564 /* Scan all pending sequences too. */
1565 for (; stack; stack = stack->next)
1567 push_to_full_sequence (stack->first, stack->last);
1568 fixup_var_refs_insns (stack->first, var, promoted_mode, unsignedp,
1569 stack->next != 0);
1570 /* Update remembered end of sequence
1571 in case we added an insn at the end. */
1572 stack->last = get_last_insn ();
1573 end_sequence ();
1576 /* Scan all waiting RTL_EXPRs too. */
1577 for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending))
1579 rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
1580 if (seq != const0_rtx && seq != 0)
1582 push_to_sequence (seq);
1583 fixup_var_refs_insns (seq, var, promoted_mode, unsignedp, 0);
1584 end_sequence ();
1589 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
1590 some part of an insn. Return a struct fixup_replacement whose OLD
1591 value is equal to X. Allocate a new structure if no such entry exists. */
1593 static struct fixup_replacement *
1594 find_fixup_replacement (replacements, x)
1595 struct fixup_replacement **replacements;
1596 rtx x;
1598 struct fixup_replacement *p;
1600 /* See if we have already replaced this. */
1601 for (p = *replacements; p != 0 && ! rtx_equal_p (p->old, x); p = p->next)
1604 if (p == 0)
1606 p = (struct fixup_replacement *) xmalloc (sizeof (struct fixup_replacement));
1607 p->old = x;
1608 p->new = 0;
1609 p->next = *replacements;
1610 *replacements = p;
1613 return p;
1616 /* Scan the insn-chain starting with INSN for refs to VAR
1617 and fix them up. TOPLEVEL is nonzero if this chain is the
1618 main chain of insns for the current function. */
1620 static void
1621 fixup_var_refs_insns (insn, var, promoted_mode, unsignedp, toplevel)
1622 rtx insn;
1623 rtx var;
1624 enum machine_mode promoted_mode;
1625 int unsignedp;
1626 int toplevel;
1628 while (insn)
1630 /* fixup_var_refs_insn might modify insn, so save its next
1631 pointer now. */
1632 rtx next = NEXT_INSN (insn);
1634 /* CALL_PLACEHOLDERs are special; we have to switch into each of
1635 the three sequences they (potentially) contain, and process
1636 them recursively. The CALL_INSN itself is not interesting. */
1638 if (GET_CODE (insn) == CALL_INSN
1639 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
1641 int i;
1643 /* Look at the Normal call, sibling call and tail recursion
1644 sequences attached to the CALL_PLACEHOLDER. */
1645 for (i = 0; i < 3; i++)
1647 rtx seq = XEXP (PATTERN (insn), i);
1648 if (seq)
1650 push_to_sequence (seq);
1651 fixup_var_refs_insns (seq, var, promoted_mode, unsignedp, 0);
1652 XEXP (PATTERN (insn), i) = get_insns ();
1653 end_sequence ();
1658 else if (INSN_P (insn))
1659 fixup_var_refs_insn (insn, var, promoted_mode, unsignedp, toplevel);
1661 insn = next;
1665 /* Look up the insns which reference VAR in HT and fix them up. Other
1666 arguments are the same as fixup_var_refs_insns.
1668 N.B. No need for special processing of CALL_PLACEHOLDERs here,
1669 because the hash table will point straight to the interesting insn
1670 (inside the CALL_PLACEHOLDER). */
1671 static void
1672 fixup_var_refs_insns_with_hash (ht, var, promoted_mode, unsignedp)
1673 struct hash_table *ht;
1674 rtx var;
1675 enum machine_mode promoted_mode;
1676 int unsignedp;
1678 struct insns_for_mem_entry *ime = (struct insns_for_mem_entry *)
1679 hash_lookup (ht, var, /*create=*/0, /*copy=*/0);
1680 rtx insn_list = ime->insns;
1682 while (insn_list)
1684 rtx insn = XEXP (insn_list, 0);
1686 if (INSN_P (insn))
1687 fixup_var_refs_insn (insn, var, promoted_mode, unsignedp, 0);
1689 insn_list = XEXP (insn_list, 1);
1694 /* Per-insn processing by fixup_var_refs_insns(_with_hash). INSN is
1695 the insn under examination, VAR is the variable to fix up
1696 references to, PROMOTED_MODE and UNSIGNEDP describe VAR, and
1697 TOPLEVEL is nonzero if this is the main insn chain for this
1698 function. */
1699 static void
1700 fixup_var_refs_insn (insn, var, promoted_mode, unsignedp, toplevel)
1701 rtx insn;
1702 rtx var;
1703 enum machine_mode promoted_mode;
1704 int unsignedp;
1705 int toplevel;
1707 rtx call_dest = 0;
1708 rtx set, prev, prev_set;
1709 rtx note;
1711 /* Remember the notes in case we delete the insn. */
1712 note = REG_NOTES (insn);
1714 /* If this is a CLOBBER of VAR, delete it.
1716 If it has a REG_LIBCALL note, delete the REG_LIBCALL
1717 and REG_RETVAL notes too. */
1718 if (GET_CODE (PATTERN (insn)) == CLOBBER
1719 && (XEXP (PATTERN (insn), 0) == var
1720 || (GET_CODE (XEXP (PATTERN (insn), 0)) == CONCAT
1721 && (XEXP (XEXP (PATTERN (insn), 0), 0) == var
1722 || XEXP (XEXP (PATTERN (insn), 0), 1) == var))))
1724 if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX)) != 0)
1725 /* The REG_LIBCALL note will go away since we are going to
1726 turn INSN into a NOTE, so just delete the
1727 corresponding REG_RETVAL note. */
1728 remove_note (XEXP (note, 0),
1729 find_reg_note (XEXP (note, 0), REG_RETVAL,
1730 NULL_RTX));
1732 /* In unoptimized compilation, we shouldn't call delete_insn
1733 except in jump.c doing warnings. */
1734 PUT_CODE (insn, NOTE);
1735 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1736 NOTE_SOURCE_FILE (insn) = 0;
1739 /* The insn to load VAR from a home in the arglist
1740 is now a no-op. When we see it, just delete it.
1741 Similarly if this is storing VAR from a register from which
1742 it was loaded in the previous insn. This will occur
1743 when an ADDRESSOF was made for an arglist slot. */
1744 else if (toplevel
1745 && (set = single_set (insn)) != 0
1746 && SET_DEST (set) == var
1747 /* If this represents the result of an insn group,
1748 don't delete the insn. */
1749 && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0
1750 && (rtx_equal_p (SET_SRC (set), var)
1751 || (GET_CODE (SET_SRC (set)) == REG
1752 && (prev = prev_nonnote_insn (insn)) != 0
1753 && (prev_set = single_set (prev)) != 0
1754 && SET_DEST (prev_set) == SET_SRC (set)
1755 && rtx_equal_p (SET_SRC (prev_set), var))))
1757 /* In unoptimized compilation, we shouldn't call delete_insn
1758 except in jump.c doing warnings. */
1759 PUT_CODE (insn, NOTE);
1760 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1761 NOTE_SOURCE_FILE (insn) = 0;
1763 else
1765 struct fixup_replacement *replacements = 0;
1766 rtx next_insn = NEXT_INSN (insn);
1768 if (SMALL_REGISTER_CLASSES)
1770 /* If the insn that copies the results of a CALL_INSN
1771 into a pseudo now references VAR, we have to use an
1772 intermediate pseudo since we want the life of the
1773 return value register to be only a single insn.
1775 If we don't use an intermediate pseudo, such things as
1776 address computations to make the address of VAR valid
1777 if it is not can be placed between the CALL_INSN and INSN.
1779 To make sure this doesn't happen, we record the destination
1780 of the CALL_INSN and see if the next insn uses both that
1781 and VAR. */
1783 if (call_dest != 0 && GET_CODE (insn) == INSN
1784 && reg_mentioned_p (var, PATTERN (insn))
1785 && reg_mentioned_p (call_dest, PATTERN (insn)))
1787 rtx temp = gen_reg_rtx (GET_MODE (call_dest));
1789 emit_insn_before (gen_move_insn (temp, call_dest), insn);
1791 PATTERN (insn) = replace_rtx (PATTERN (insn),
1792 call_dest, temp);
1795 if (GET_CODE (insn) == CALL_INSN
1796 && GET_CODE (PATTERN (insn)) == SET)
1797 call_dest = SET_DEST (PATTERN (insn));
1798 else if (GET_CODE (insn) == CALL_INSN
1799 && GET_CODE (PATTERN (insn)) == PARALLEL
1800 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
1801 call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
1802 else
1803 call_dest = 0;
1806 /* See if we have to do anything to INSN now that VAR is in
1807 memory. If it needs to be loaded into a pseudo, use a single
1808 pseudo for the entire insn in case there is a MATCH_DUP
1809 between two operands. We pass a pointer to the head of
1810 a list of struct fixup_replacements. If fixup_var_refs_1
1811 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1812 it will record them in this list.
1814 If it allocated a pseudo for any replacement, we copy into
1815 it here. */
1817 fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn,
1818 &replacements);
1820 /* If this is last_parm_insn, and any instructions were output
1821 after it to fix it up, then we must set last_parm_insn to
1822 the last such instruction emitted. */
1823 if (insn == last_parm_insn)
1824 last_parm_insn = PREV_INSN (next_insn);
1826 while (replacements)
1828 struct fixup_replacement *next;
1830 if (GET_CODE (replacements->new) == REG)
1832 rtx insert_before;
1833 rtx seq;
1835 /* OLD might be a (subreg (mem)). */
1836 if (GET_CODE (replacements->old) == SUBREG)
1837 replacements->old
1838 = fixup_memory_subreg (replacements->old, insn, 0);
1839 else
1840 replacements->old
1841 = fixup_stack_1 (replacements->old, insn);
1843 insert_before = insn;
1845 /* If we are changing the mode, do a conversion.
1846 This might be wasteful, but combine.c will
1847 eliminate much of the waste. */
1849 if (GET_MODE (replacements->new)
1850 != GET_MODE (replacements->old))
1852 start_sequence ();
1853 convert_move (replacements->new,
1854 replacements->old, unsignedp);
1855 seq = gen_sequence ();
1856 end_sequence ();
1858 else
1859 seq = gen_move_insn (replacements->new,
1860 replacements->old);
1862 emit_insn_before (seq, insert_before);
1865 next = replacements->next;
1866 free (replacements);
1867 replacements = next;
1871 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
1872 But don't touch other insns referred to by reg-notes;
1873 we will get them elsewhere. */
1874 while (note)
1876 if (GET_CODE (note) != INSN_LIST)
1877 XEXP (note, 0)
1878 = walk_fixup_memory_subreg (XEXP (note, 0), insn, 1);
1879 note = XEXP (note, 1);
1883 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
1884 See if the rtx expression at *LOC in INSN needs to be changed.
1886 REPLACEMENTS is a pointer to a list head that starts out zero, but may
1887 contain a list of original rtx's and replacements. If we find that we need
1888 to modify this insn by replacing a memory reference with a pseudo or by
1889 making a new MEM to implement a SUBREG, we consult that list to see if
1890 we have already chosen a replacement. If none has already been allocated,
1891 we allocate it and update the list. fixup_var_refs_insn will copy VAR
1892 or the SUBREG, as appropriate, to the pseudo. */
1894 static void
1895 fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements)
1896 register rtx var;
1897 enum machine_mode promoted_mode;
1898 register rtx *loc;
1899 rtx insn;
1900 struct fixup_replacement **replacements;
1902 register int i;
1903 register rtx x = *loc;
1904 RTX_CODE code = GET_CODE (x);
1905 register const char *fmt;
1906 register rtx tem, tem1;
1907 struct fixup_replacement *replacement;
1909 switch (code)
1911 case ADDRESSOF:
1912 if (XEXP (x, 0) == var)
1914 /* Prevent sharing of rtl that might lose. */
1915 rtx sub = copy_rtx (XEXP (var, 0));
1917 if (! validate_change (insn, loc, sub, 0))
1919 rtx y = gen_reg_rtx (GET_MODE (sub));
1920 rtx seq, new_insn;
1922 /* We should be able to replace with a register or all is lost.
1923 Note that we can't use validate_change to verify this, since
1924 we're not caring for replacing all dups simultaneously. */
1925 if (! validate_replace_rtx (*loc, y, insn))
1926 abort ();
1928 /* Careful! First try to recognize a direct move of the
1929 value, mimicking how things are done in gen_reload wrt
1930 PLUS. Consider what happens when insn is a conditional
1931 move instruction and addsi3 clobbers flags. */
1933 start_sequence ();
1934 new_insn = emit_insn (gen_rtx_SET (VOIDmode, y, sub));
1935 seq = gen_sequence ();
1936 end_sequence ();
1938 if (recog_memoized (new_insn) < 0)
1940 /* That failed. Fall back on force_operand and hope. */
1942 start_sequence ();
1943 sub = force_operand (sub, y);
1944 if (sub != y)
1945 emit_insn (gen_move_insn (y, sub));
1946 seq = gen_sequence ();
1947 end_sequence ();
1950 #ifdef HAVE_cc0
1951 /* Don't separate setter from user. */
1952 if (PREV_INSN (insn) && sets_cc0_p (PREV_INSN (insn)))
1953 insn = PREV_INSN (insn);
1954 #endif
1956 emit_insn_before (seq, insn);
1959 return;
1961 case MEM:
1962 if (var == x)
1964 /* If we already have a replacement, use it. Otherwise,
1965 try to fix up this address in case it is invalid. */
1967 replacement = find_fixup_replacement (replacements, var);
1968 if (replacement->new)
1970 *loc = replacement->new;
1971 return;
1974 *loc = replacement->new = x = fixup_stack_1 (x, insn);
1976 /* Unless we are forcing memory to register or we changed the mode,
1977 we can leave things the way they are if the insn is valid. */
1979 INSN_CODE (insn) = -1;
1980 if (! flag_force_mem && GET_MODE (x) == promoted_mode
1981 && recog_memoized (insn) >= 0)
1982 return;
1984 *loc = replacement->new = gen_reg_rtx (promoted_mode);
1985 return;
1988 /* If X contains VAR, we need to unshare it here so that we update
1989 each occurrence separately. But all identical MEMs in one insn
1990 must be replaced with the same rtx because of the possibility of
1991 MATCH_DUPs. */
1993 if (reg_mentioned_p (var, x))
1995 replacement = find_fixup_replacement (replacements, x);
1996 if (replacement->new == 0)
1997 replacement->new = copy_most_rtx (x, var);
1999 *loc = x = replacement->new;
2000 code = GET_CODE (x);
2002 break;
2004 case REG:
2005 case CC0:
2006 case PC:
2007 case CONST_INT:
2008 case CONST:
2009 case SYMBOL_REF:
2010 case LABEL_REF:
2011 case CONST_DOUBLE:
2012 return;
2014 case SIGN_EXTRACT:
2015 case ZERO_EXTRACT:
2016 /* Note that in some cases those types of expressions are altered
2017 by optimize_bit_field, and do not survive to get here. */
2018 if (XEXP (x, 0) == var
2019 || (GET_CODE (XEXP (x, 0)) == SUBREG
2020 && SUBREG_REG (XEXP (x, 0)) == var))
2022 /* Get TEM as a valid MEM in the mode presently in the insn.
2024 We don't worry about the possibility of MATCH_DUP here; it
2025 is highly unlikely and would be tricky to handle. */
2027 tem = XEXP (x, 0);
2028 if (GET_CODE (tem) == SUBREG)
2030 if (GET_MODE_BITSIZE (GET_MODE (tem))
2031 > GET_MODE_BITSIZE (GET_MODE (var)))
2033 replacement = find_fixup_replacement (replacements, var);
2034 if (replacement->new == 0)
2035 replacement->new = gen_reg_rtx (GET_MODE (var));
2036 SUBREG_REG (tem) = replacement->new;
2038 /* The following code works only if we have a MEM, so we
2039 need to handle the subreg here. We directly substitute
2040 it assuming that a subreg must be OK here. We already
2041 scheduled a replacement to copy the mem into the
2042 subreg. */
2043 XEXP (x, 0) = tem;
2044 return;
2046 else
2047 tem = fixup_memory_subreg (tem, insn, 0);
2049 else
2050 tem = fixup_stack_1 (tem, insn);
2052 /* Unless we want to load from memory, get TEM into the proper mode
2053 for an extract from memory. This can only be done if the
2054 extract is at a constant position and length. */
2056 if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT
2057 && GET_CODE (XEXP (x, 2)) == CONST_INT
2058 && ! mode_dependent_address_p (XEXP (tem, 0))
2059 && ! MEM_VOLATILE_P (tem))
2061 enum machine_mode wanted_mode = VOIDmode;
2062 enum machine_mode is_mode = GET_MODE (tem);
2063 HOST_WIDE_INT pos = INTVAL (XEXP (x, 2));
2065 #ifdef HAVE_extzv
2066 if (GET_CODE (x) == ZERO_EXTRACT)
2068 wanted_mode
2069 = insn_data[(int) CODE_FOR_extzv].operand[1].mode;
2070 if (wanted_mode == VOIDmode)
2071 wanted_mode = word_mode;
2073 #endif
2074 #ifdef HAVE_extv
2075 if (GET_CODE (x) == SIGN_EXTRACT)
2077 wanted_mode = insn_data[(int) CODE_FOR_extv].operand[1].mode;
2078 if (wanted_mode == VOIDmode)
2079 wanted_mode = word_mode;
2081 #endif
2082 /* If we have a narrower mode, we can do something. */
2083 if (wanted_mode != VOIDmode
2084 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
2086 HOST_WIDE_INT offset = pos / BITS_PER_UNIT;
2087 rtx old_pos = XEXP (x, 2);
2088 rtx newmem;
2090 /* If the bytes and bits are counted differently, we
2091 must adjust the offset. */
2092 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
2093 offset = (GET_MODE_SIZE (is_mode)
2094 - GET_MODE_SIZE (wanted_mode) - offset);
2096 pos %= GET_MODE_BITSIZE (wanted_mode);
2098 newmem = gen_rtx_MEM (wanted_mode,
2099 plus_constant (XEXP (tem, 0), offset));
2100 MEM_COPY_ATTRIBUTES (newmem, tem);
2102 /* Make the change and see if the insn remains valid. */
2103 INSN_CODE (insn) = -1;
2104 XEXP (x, 0) = newmem;
2105 XEXP (x, 2) = GEN_INT (pos);
2107 if (recog_memoized (insn) >= 0)
2108 return;
2110 /* Otherwise, restore old position. XEXP (x, 0) will be
2111 restored later. */
2112 XEXP (x, 2) = old_pos;
2116 /* If we get here, the bitfield extract insn can't accept a memory
2117 reference. Copy the input into a register. */
2119 tem1 = gen_reg_rtx (GET_MODE (tem));
2120 emit_insn_before (gen_move_insn (tem1, tem), insn);
2121 XEXP (x, 0) = tem1;
2122 return;
2124 break;
2126 case SUBREG:
2127 if (SUBREG_REG (x) == var)
2129 /* If this is a special SUBREG made because VAR was promoted
2130 from a wider mode, replace it with VAR and call ourself
2131 recursively, this time saying that the object previously
2132 had its current mode (by virtue of the SUBREG). */
2134 if (SUBREG_PROMOTED_VAR_P (x))
2136 *loc = var;
2137 fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements);
2138 return;
2141 /* If this SUBREG makes VAR wider, it has become a paradoxical
2142 SUBREG with VAR in memory, but these aren't allowed at this
2143 stage of the compilation. So load VAR into a pseudo and take
2144 a SUBREG of that pseudo. */
2145 if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var)))
2147 replacement = find_fixup_replacement (replacements, var);
2148 if (replacement->new == 0)
2149 replacement->new = gen_reg_rtx (promoted_mode);
2150 SUBREG_REG (x) = replacement->new;
2151 return;
2154 /* See if we have already found a replacement for this SUBREG.
2155 If so, use it. Otherwise, make a MEM and see if the insn
2156 is recognized. If not, or if we should force MEM into a register,
2157 make a pseudo for this SUBREG. */
2158 replacement = find_fixup_replacement (replacements, x);
2159 if (replacement->new)
2161 *loc = replacement->new;
2162 return;
2165 replacement->new = *loc = fixup_memory_subreg (x, insn, 0);
2167 INSN_CODE (insn) = -1;
2168 if (! flag_force_mem && recog_memoized (insn) >= 0)
2169 return;
2171 *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
2172 return;
2174 break;
2176 case SET:
2177 /* First do special simplification of bit-field references. */
2178 if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
2179 || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
2180 optimize_bit_field (x, insn, 0);
2181 if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
2182 || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
2183 optimize_bit_field (x, insn, NULL_PTR);
2185 /* For a paradoxical SUBREG inside a ZERO_EXTRACT, load the object
2186 into a register and then store it back out. */
2187 if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT
2188 && GET_CODE (XEXP (SET_DEST (x), 0)) == SUBREG
2189 && SUBREG_REG (XEXP (SET_DEST (x), 0)) == var
2190 && (GET_MODE_SIZE (GET_MODE (XEXP (SET_DEST (x), 0)))
2191 > GET_MODE_SIZE (GET_MODE (var))))
2193 replacement = find_fixup_replacement (replacements, var);
2194 if (replacement->new == 0)
2195 replacement->new = gen_reg_rtx (GET_MODE (var));
2197 SUBREG_REG (XEXP (SET_DEST (x), 0)) = replacement->new;
2198 emit_insn_after (gen_move_insn (var, replacement->new), insn);
2201 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
2202 insn into a pseudo and store the low part of the pseudo into VAR. */
2203 if (GET_CODE (SET_DEST (x)) == SUBREG
2204 && SUBREG_REG (SET_DEST (x)) == var
2205 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
2206 > GET_MODE_SIZE (GET_MODE (var))))
2208 SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x)));
2209 emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var),
2210 tem)),
2211 insn);
2212 break;
2216 rtx dest = SET_DEST (x);
2217 rtx src = SET_SRC (x);
2218 #ifdef HAVE_insv
2219 rtx outerdest = dest;
2220 #endif
2222 while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
2223 || GET_CODE (dest) == SIGN_EXTRACT
2224 || GET_CODE (dest) == ZERO_EXTRACT)
2225 dest = XEXP (dest, 0);
2227 if (GET_CODE (src) == SUBREG)
2228 src = XEXP (src, 0);
2230 /* If VAR does not appear at the top level of the SET
2231 just scan the lower levels of the tree. */
2233 if (src != var && dest != var)
2234 break;
2236 /* We will need to rerecognize this insn. */
2237 INSN_CODE (insn) = -1;
2239 #ifdef HAVE_insv
2240 if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var)
2242 /* Since this case will return, ensure we fixup all the
2243 operands here. */
2244 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1),
2245 insn, replacements);
2246 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2),
2247 insn, replacements);
2248 fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x),
2249 insn, replacements);
2251 tem = XEXP (outerdest, 0);
2253 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
2254 that may appear inside a ZERO_EXTRACT.
2255 This was legitimate when the MEM was a REG. */
2256 if (GET_CODE (tem) == SUBREG
2257 && SUBREG_REG (tem) == var)
2258 tem = fixup_memory_subreg (tem, insn, 0);
2259 else
2260 tem = fixup_stack_1 (tem, insn);
2262 if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT
2263 && GET_CODE (XEXP (outerdest, 2)) == CONST_INT
2264 && ! mode_dependent_address_p (XEXP (tem, 0))
2265 && ! MEM_VOLATILE_P (tem))
2267 enum machine_mode wanted_mode;
2268 enum machine_mode is_mode = GET_MODE (tem);
2269 HOST_WIDE_INT pos = INTVAL (XEXP (outerdest, 2));
2271 wanted_mode = insn_data[(int) CODE_FOR_insv].operand[0].mode;
2272 if (wanted_mode == VOIDmode)
2273 wanted_mode = word_mode;
2275 /* If we have a narrower mode, we can do something. */
2276 if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
2278 HOST_WIDE_INT offset = pos / BITS_PER_UNIT;
2279 rtx old_pos = XEXP (outerdest, 2);
2280 rtx newmem;
2282 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
2283 offset = (GET_MODE_SIZE (is_mode)
2284 - GET_MODE_SIZE (wanted_mode) - offset);
2286 pos %= GET_MODE_BITSIZE (wanted_mode);
2288 newmem = gen_rtx_MEM (wanted_mode,
2289 plus_constant (XEXP (tem, 0),
2290 offset));
2291 MEM_COPY_ATTRIBUTES (newmem, tem);
2293 /* Make the change and see if the insn remains valid. */
2294 INSN_CODE (insn) = -1;
2295 XEXP (outerdest, 0) = newmem;
2296 XEXP (outerdest, 2) = GEN_INT (pos);
2298 if (recog_memoized (insn) >= 0)
2299 return;
2301 /* Otherwise, restore old position. XEXP (x, 0) will be
2302 restored later. */
2303 XEXP (outerdest, 2) = old_pos;
2307 /* If we get here, the bit-field store doesn't allow memory
2308 or isn't located at a constant position. Load the value into
2309 a register, do the store, and put it back into memory. */
2311 tem1 = gen_reg_rtx (GET_MODE (tem));
2312 emit_insn_before (gen_move_insn (tem1, tem), insn);
2313 emit_insn_after (gen_move_insn (tem, tem1), insn);
2314 XEXP (outerdest, 0) = tem1;
2315 return;
2317 #endif
2319 /* STRICT_LOW_PART is a no-op on memory references
2320 and it can cause combinations to be unrecognizable,
2321 so eliminate it. */
2323 if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
2324 SET_DEST (x) = XEXP (SET_DEST (x), 0);
2326 /* A valid insn to copy VAR into or out of a register
2327 must be left alone, to avoid an infinite loop here.
2328 If the reference to VAR is by a subreg, fix that up,
2329 since SUBREG is not valid for a memref.
2330 Also fix up the address of the stack slot.
2332 Note that we must not try to recognize the insn until
2333 after we know that we have valid addresses and no
2334 (subreg (mem ...) ...) constructs, since these interfere
2335 with determining the validity of the insn. */
2337 if ((SET_SRC (x) == var
2338 || (GET_CODE (SET_SRC (x)) == SUBREG
2339 && SUBREG_REG (SET_SRC (x)) == var))
2340 && (GET_CODE (SET_DEST (x)) == REG
2341 || (GET_CODE (SET_DEST (x)) == SUBREG
2342 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
2343 && GET_MODE (var) == promoted_mode
2344 && x == single_set (insn))
2346 rtx pat, last;
2348 replacement = find_fixup_replacement (replacements, SET_SRC (x));
2349 if (replacement->new)
2350 SET_SRC (x) = replacement->new;
2351 else if (GET_CODE (SET_SRC (x)) == SUBREG)
2352 SET_SRC (x) = replacement->new
2353 = fixup_memory_subreg (SET_SRC (x), insn, 0);
2354 else
2355 SET_SRC (x) = replacement->new
2356 = fixup_stack_1 (SET_SRC (x), insn);
2358 if (recog_memoized (insn) >= 0)
2359 return;
2361 /* INSN is not valid, but we know that we want to
2362 copy SET_SRC (x) to SET_DEST (x) in some way. So
2363 we generate the move and see whether it requires more
2364 than one insn. If it does, we emit those insns and
2365 delete INSN. Otherwise, we an just replace the pattern
2366 of INSN; we have already verified above that INSN has
2367 no other function that to do X. */
2369 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2370 if (GET_CODE (pat) == SEQUENCE)
2372 last = emit_insn_before (pat, insn);
2374 /* INSN might have REG_RETVAL or other important notes, so
2375 we need to store the pattern of the last insn in the
2376 sequence into INSN similarly to the normal case. LAST
2377 should not have REG_NOTES, but we allow them if INSN has
2378 no REG_NOTES. */
2379 if (REG_NOTES (last) && REG_NOTES (insn))
2380 abort ();
2381 if (REG_NOTES (last))
2382 REG_NOTES (insn) = REG_NOTES (last);
2383 PATTERN (insn) = PATTERN (last);
2385 PUT_CODE (last, NOTE);
2386 NOTE_LINE_NUMBER (last) = NOTE_INSN_DELETED;
2387 NOTE_SOURCE_FILE (last) = 0;
2389 else
2390 PATTERN (insn) = pat;
2392 return;
2395 if ((SET_DEST (x) == var
2396 || (GET_CODE (SET_DEST (x)) == SUBREG
2397 && SUBREG_REG (SET_DEST (x)) == var))
2398 && (GET_CODE (SET_SRC (x)) == REG
2399 || (GET_CODE (SET_SRC (x)) == SUBREG
2400 && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG))
2401 && GET_MODE (var) == promoted_mode
2402 && x == single_set (insn))
2404 rtx pat, last;
2406 if (GET_CODE (SET_DEST (x)) == SUBREG)
2407 SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn, 0);
2408 else
2409 SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn);
2411 if (recog_memoized (insn) >= 0)
2412 return;
2414 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2415 if (GET_CODE (pat) == SEQUENCE)
2417 last = emit_insn_before (pat, insn);
2419 /* INSN might have REG_RETVAL or other important notes, so
2420 we need to store the pattern of the last insn in the
2421 sequence into INSN similarly to the normal case. LAST
2422 should not have REG_NOTES, but we allow them if INSN has
2423 no REG_NOTES. */
2424 if (REG_NOTES (last) && REG_NOTES (insn))
2425 abort ();
2426 if (REG_NOTES (last))
2427 REG_NOTES (insn) = REG_NOTES (last);
2428 PATTERN (insn) = PATTERN (last);
2430 PUT_CODE (last, NOTE);
2431 NOTE_LINE_NUMBER (last) = NOTE_INSN_DELETED;
2432 NOTE_SOURCE_FILE (last) = 0;
2434 else
2435 PATTERN (insn) = pat;
2437 return;
2440 /* Otherwise, storing into VAR must be handled specially
2441 by storing into a temporary and copying that into VAR
2442 with a new insn after this one. Note that this case
2443 will be used when storing into a promoted scalar since
2444 the insn will now have different modes on the input
2445 and output and hence will be invalid (except for the case
2446 of setting it to a constant, which does not need any
2447 change if it is valid). We generate extra code in that case,
2448 but combine.c will eliminate it. */
2450 if (dest == var)
2452 rtx temp;
2453 rtx fixeddest = SET_DEST (x);
2455 /* STRICT_LOW_PART can be discarded, around a MEM. */
2456 if (GET_CODE (fixeddest) == STRICT_LOW_PART)
2457 fixeddest = XEXP (fixeddest, 0);
2458 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
2459 if (GET_CODE (fixeddest) == SUBREG)
2461 fixeddest = fixup_memory_subreg (fixeddest, insn, 0);
2462 promoted_mode = GET_MODE (fixeddest);
2464 else
2465 fixeddest = fixup_stack_1 (fixeddest, insn);
2467 temp = gen_reg_rtx (promoted_mode);
2469 emit_insn_after (gen_move_insn (fixeddest,
2470 gen_lowpart (GET_MODE (fixeddest),
2471 temp)),
2472 insn);
2474 SET_DEST (x) = temp;
2478 default:
2479 break;
2482 /* Nothing special about this RTX; fix its operands. */
2484 fmt = GET_RTX_FORMAT (code);
2485 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2487 if (fmt[i] == 'e')
2488 fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements);
2489 else if (fmt[i] == 'E')
2491 register int j;
2492 for (j = 0; j < XVECLEN (x, i); j++)
2493 fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j),
2494 insn, replacements);
2499 /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
2500 return an rtx (MEM:m1 newaddr) which is equivalent.
2501 If any insns must be emitted to compute NEWADDR, put them before INSN.
2503 UNCRITICAL nonzero means accept paradoxical subregs.
2504 This is used for subregs found inside REG_NOTES. */
2506 static rtx
2507 fixup_memory_subreg (x, insn, uncritical)
2508 rtx x;
2509 rtx insn;
2510 int uncritical;
2512 int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
2513 rtx addr = XEXP (SUBREG_REG (x), 0);
2514 enum machine_mode mode = GET_MODE (x);
2515 rtx result;
2517 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
2518 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
2519 && ! uncritical)
2520 abort ();
2522 if (BYTES_BIG_ENDIAN)
2523 offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
2524 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
2525 addr = plus_constant (addr, offset);
2526 if (!flag_force_addr && memory_address_p (mode, addr))
2527 /* Shortcut if no insns need be emitted. */
2528 return change_address (SUBREG_REG (x), mode, addr);
2529 start_sequence ();
2530 result = change_address (SUBREG_REG (x), mode, addr);
2531 emit_insn_before (gen_sequence (), insn);
2532 end_sequence ();
2533 return result;
2536 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2537 Replace subexpressions of X in place.
2538 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2539 Otherwise return X, with its contents possibly altered.
2541 If any insns must be emitted to compute NEWADDR, put them before INSN.
2543 UNCRITICAL is as in fixup_memory_subreg. */
2545 static rtx
2546 walk_fixup_memory_subreg (x, insn, uncritical)
2547 register rtx x;
2548 rtx insn;
2549 int uncritical;
2551 register enum rtx_code code;
2552 register const char *fmt;
2553 register int i;
2555 if (x == 0)
2556 return 0;
2558 code = GET_CODE (x);
2560 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
2561 return fixup_memory_subreg (x, insn, uncritical);
2563 /* Nothing special about this RTX; fix its operands. */
2565 fmt = GET_RTX_FORMAT (code);
2566 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2568 if (fmt[i] == 'e')
2569 XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn, uncritical);
2570 else if (fmt[i] == 'E')
2572 register int j;
2573 for (j = 0; j < XVECLEN (x, i); j++)
2574 XVECEXP (x, i, j)
2575 = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn, uncritical);
2578 return x;
2581 /* For each memory ref within X, if it refers to a stack slot
2582 with an out of range displacement, put the address in a temp register
2583 (emitting new insns before INSN to load these registers)
2584 and alter the memory ref to use that register.
2585 Replace each such MEM rtx with a copy, to avoid clobberage. */
2587 static rtx
2588 fixup_stack_1 (x, insn)
2589 rtx x;
2590 rtx insn;
2592 register int i;
2593 register RTX_CODE code = GET_CODE (x);
2594 register const char *fmt;
2596 if (code == MEM)
2598 register rtx ad = XEXP (x, 0);
2599 /* If we have address of a stack slot but it's not valid
2600 (displacement is too large), compute the sum in a register. */
2601 if (GET_CODE (ad) == PLUS
2602 && GET_CODE (XEXP (ad, 0)) == REG
2603 && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER
2604 && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER)
2605 || REGNO (XEXP (ad, 0)) == FRAME_POINTER_REGNUM
2606 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2607 || REGNO (XEXP (ad, 0)) == HARD_FRAME_POINTER_REGNUM
2608 #endif
2609 || REGNO (XEXP (ad, 0)) == STACK_POINTER_REGNUM
2610 || REGNO (XEXP (ad, 0)) == ARG_POINTER_REGNUM
2611 || XEXP (ad, 0) == current_function_internal_arg_pointer)
2612 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
2614 rtx temp, seq;
2615 if (memory_address_p (GET_MODE (x), ad))
2616 return x;
2618 start_sequence ();
2619 temp = copy_to_reg (ad);
2620 seq = gen_sequence ();
2621 end_sequence ();
2622 emit_insn_before (seq, insn);
2623 return change_address (x, VOIDmode, temp);
2625 return x;
2628 fmt = GET_RTX_FORMAT (code);
2629 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2631 if (fmt[i] == 'e')
2632 XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
2633 else if (fmt[i] == 'E')
2635 register int j;
2636 for (j = 0; j < XVECLEN (x, i); j++)
2637 XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
2640 return x;
2643 /* Optimization: a bit-field instruction whose field
2644 happens to be a byte or halfword in memory
2645 can be changed to a move instruction.
2647 We call here when INSN is an insn to examine or store into a bit-field.
2648 BODY is the SET-rtx to be altered.
2650 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2651 (Currently this is called only from function.c, and EQUIV_MEM
2652 is always 0.) */
2654 static void
2655 optimize_bit_field (body, insn, equiv_mem)
2656 rtx body;
2657 rtx insn;
2658 rtx *equiv_mem;
2660 register rtx bitfield;
2661 int destflag;
2662 rtx seq = 0;
2663 enum machine_mode mode;
2665 if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
2666 || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
2667 bitfield = SET_DEST (body), destflag = 1;
2668 else
2669 bitfield = SET_SRC (body), destflag = 0;
2671 /* First check that the field being stored has constant size and position
2672 and is in fact a byte or halfword suitably aligned. */
2674 if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
2675 && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
2676 && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1))
2677 != BLKmode)
2678 && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
2680 register rtx memref = 0;
2682 /* Now check that the containing word is memory, not a register,
2683 and that it is safe to change the machine mode. */
2685 if (GET_CODE (XEXP (bitfield, 0)) == MEM)
2686 memref = XEXP (bitfield, 0);
2687 else if (GET_CODE (XEXP (bitfield, 0)) == REG
2688 && equiv_mem != 0)
2689 memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
2690 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2691 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
2692 memref = SUBREG_REG (XEXP (bitfield, 0));
2693 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2694 && equiv_mem != 0
2695 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
2696 memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
2698 if (memref
2699 && ! mode_dependent_address_p (XEXP (memref, 0))
2700 && ! MEM_VOLATILE_P (memref))
2702 /* Now adjust the address, first for any subreg'ing
2703 that we are now getting rid of,
2704 and then for which byte of the word is wanted. */
2706 HOST_WIDE_INT offset = INTVAL (XEXP (bitfield, 2));
2707 rtx insns;
2709 /* Adjust OFFSET to count bits from low-address byte. */
2710 if (BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN)
2711 offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0)))
2712 - offset - INTVAL (XEXP (bitfield, 1)));
2714 /* Adjust OFFSET to count bytes from low-address byte. */
2715 offset /= BITS_PER_UNIT;
2716 if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
2718 offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD;
2719 if (BYTES_BIG_ENDIAN)
2720 offset -= (MIN (UNITS_PER_WORD,
2721 GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
2722 - MIN (UNITS_PER_WORD,
2723 GET_MODE_SIZE (GET_MODE (memref))));
2726 start_sequence ();
2727 memref = change_address (memref, mode,
2728 plus_constant (XEXP (memref, 0), offset));
2729 insns = get_insns ();
2730 end_sequence ();
2731 emit_insns_before (insns, insn);
2733 /* Store this memory reference where
2734 we found the bit field reference. */
2736 if (destflag)
2738 validate_change (insn, &SET_DEST (body), memref, 1);
2739 if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
2741 rtx src = SET_SRC (body);
2742 while (GET_CODE (src) == SUBREG
2743 && SUBREG_WORD (src) == 0)
2744 src = SUBREG_REG (src);
2745 if (GET_MODE (src) != GET_MODE (memref))
2746 src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
2747 validate_change (insn, &SET_SRC (body), src, 1);
2749 else if (GET_MODE (SET_SRC (body)) != VOIDmode
2750 && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
2751 /* This shouldn't happen because anything that didn't have
2752 one of these modes should have got converted explicitly
2753 and then referenced through a subreg.
2754 This is so because the original bit-field was
2755 handled by agg_mode and so its tree structure had
2756 the same mode that memref now has. */
2757 abort ();
2759 else
2761 rtx dest = SET_DEST (body);
2763 while (GET_CODE (dest) == SUBREG
2764 && SUBREG_WORD (dest) == 0
2765 && (GET_MODE_CLASS (GET_MODE (dest))
2766 == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest))))
2767 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
2768 <= UNITS_PER_WORD))
2769 dest = SUBREG_REG (dest);
2771 validate_change (insn, &SET_DEST (body), dest, 1);
2773 if (GET_MODE (dest) == GET_MODE (memref))
2774 validate_change (insn, &SET_SRC (body), memref, 1);
2775 else
2777 /* Convert the mem ref to the destination mode. */
2778 rtx newreg = gen_reg_rtx (GET_MODE (dest));
2780 start_sequence ();
2781 convert_move (newreg, memref,
2782 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
2783 seq = get_insns ();
2784 end_sequence ();
2786 validate_change (insn, &SET_SRC (body), newreg, 1);
2790 /* See if we can convert this extraction or insertion into
2791 a simple move insn. We might not be able to do so if this
2792 was, for example, part of a PARALLEL.
2794 If we succeed, write out any needed conversions. If we fail,
2795 it is hard to guess why we failed, so don't do anything
2796 special; just let the optimization be suppressed. */
2798 if (apply_change_group () && seq)
2799 emit_insns_before (seq, insn);
2804 /* These routines are responsible for converting virtual register references
2805 to the actual hard register references once RTL generation is complete.
2807 The following four variables are used for communication between the
2808 routines. They contain the offsets of the virtual registers from their
2809 respective hard registers. */
2811 static int in_arg_offset;
2812 static int var_offset;
2813 static int dynamic_offset;
2814 static int out_arg_offset;
2815 static int cfa_offset;
2817 /* In most machines, the stack pointer register is equivalent to the bottom
2818 of the stack. */
2820 #ifndef STACK_POINTER_OFFSET
2821 #define STACK_POINTER_OFFSET 0
2822 #endif
2824 /* If not defined, pick an appropriate default for the offset of dynamically
2825 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2826 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2828 #ifndef STACK_DYNAMIC_OFFSET
2830 /* The bottom of the stack points to the actual arguments. If
2831 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2832 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2833 stack space for register parameters is not pushed by the caller, but
2834 rather part of the fixed stack areas and hence not included in
2835 `current_function_outgoing_args_size'. Nevertheless, we must allow
2836 for it when allocating stack dynamic objects. */
2838 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2839 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2840 ((ACCUMULATE_OUTGOING_ARGS \
2841 ? (current_function_outgoing_args_size + REG_PARM_STACK_SPACE (FNDECL)) : 0)\
2842 + (STACK_POINTER_OFFSET)) \
2844 #else
2845 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2846 ((ACCUMULATE_OUTGOING_ARGS ? current_function_outgoing_args_size : 0) \
2847 + (STACK_POINTER_OFFSET))
2848 #endif
2849 #endif
2851 /* On most machines, the CFA coincides with the first incoming parm. */
2853 #ifndef ARG_POINTER_CFA_OFFSET
2854 #define ARG_POINTER_CFA_OFFSET(FNDECL) FIRST_PARM_OFFSET (FNDECL)
2855 #endif
2857 /* Build up a (MEM (ADDRESSOF (REG))) rtx for a register REG that just had
2858 its address taken. DECL is the decl for the object stored in the
2859 register, for later use if we do need to force REG into the stack.
2860 REG is overwritten by the MEM like in put_reg_into_stack. */
2863 gen_mem_addressof (reg, decl)
2864 rtx reg;
2865 tree decl;
2867 rtx r = gen_rtx_ADDRESSOF (Pmode, gen_reg_rtx (GET_MODE (reg)),
2868 REGNO (reg), decl);
2870 /* If the original REG was a user-variable, then so is the REG whose
2871 address is being taken. Likewise for unchanging. */
2872 REG_USERVAR_P (XEXP (r, 0)) = REG_USERVAR_P (reg);
2873 RTX_UNCHANGING_P (XEXP (r, 0)) = RTX_UNCHANGING_P (reg);
2875 PUT_CODE (reg, MEM);
2876 XEXP (reg, 0) = r;
2877 if (decl)
2879 tree type = TREE_TYPE (decl);
2881 PUT_MODE (reg, DECL_MODE (decl));
2882 MEM_VOLATILE_P (reg) = TREE_SIDE_EFFECTS (decl);
2883 MEM_SET_IN_STRUCT_P (reg, AGGREGATE_TYPE_P (type));
2884 MEM_ALIAS_SET (reg) = get_alias_set (decl);
2886 if (TREE_USED (decl) || DECL_INITIAL (decl) != 0)
2887 fixup_var_refs (reg, GET_MODE (reg), TREE_UNSIGNED (type), 0);
2889 else
2891 /* We have no alias information about this newly created MEM. */
2892 MEM_ALIAS_SET (reg) = 0;
2894 fixup_var_refs (reg, GET_MODE (reg), 0, 0);
2897 return reg;
2900 /* If DECL has an RTL that is an ADDRESSOF rtx, put it into the stack. */
2902 void
2903 flush_addressof (decl)
2904 tree decl;
2906 if ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == VAR_DECL)
2907 && DECL_RTL (decl) != 0
2908 && GET_CODE (DECL_RTL (decl)) == MEM
2909 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF
2910 && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 0)) == REG)
2911 put_addressof_into_stack (XEXP (DECL_RTL (decl), 0), 0);
2914 /* Force the register pointed to by R, an ADDRESSOF rtx, into the stack. */
2916 static void
2917 put_addressof_into_stack (r, ht)
2918 rtx r;
2919 struct hash_table *ht;
2921 tree decl, type;
2922 int volatile_p, used_p;
2924 rtx reg = XEXP (r, 0);
2926 if (GET_CODE (reg) != REG)
2927 abort ();
2929 decl = ADDRESSOF_DECL (r);
2930 if (decl)
2932 type = TREE_TYPE (decl);
2933 volatile_p = (TREE_CODE (decl) != SAVE_EXPR
2934 && TREE_THIS_VOLATILE (decl));
2935 used_p = (TREE_USED (decl)
2936 || (TREE_CODE (decl) != SAVE_EXPR
2937 && DECL_INITIAL (decl) != 0));
2939 else
2941 type = NULL_TREE;
2942 volatile_p = 0;
2943 used_p = 1;
2946 put_reg_into_stack (0, reg, type, GET_MODE (reg), GET_MODE (reg),
2947 volatile_p, ADDRESSOF_REGNO (r), used_p, ht);
2950 /* List of replacements made below in purge_addressof_1 when creating
2951 bitfield insertions. */
2952 static rtx purge_bitfield_addressof_replacements;
2954 /* List of replacements made below in purge_addressof_1 for patterns
2955 (MEM (ADDRESSOF (REG ...))). The key of the list entry is the
2956 corresponding (ADDRESSOF (REG ...)) and value is a substitution for
2957 the all pattern. List PURGE_BITFIELD_ADDRESSOF_REPLACEMENTS is not
2958 enough in complex cases, e.g. when some field values can be
2959 extracted by usage MEM with narrower mode. */
2960 static rtx purge_addressof_replacements;
2962 /* Helper function for purge_addressof. See if the rtx expression at *LOC
2963 in INSN needs to be changed. If FORCE, always put any ADDRESSOFs into
2964 the stack. If the function returns FALSE then the replacement could not
2965 be made. */
2967 static bool
2968 purge_addressof_1 (loc, insn, force, store, ht)
2969 rtx *loc;
2970 rtx insn;
2971 int force, store;
2972 struct hash_table *ht;
2974 rtx x;
2975 RTX_CODE code;
2976 int i, j;
2977 const char *fmt;
2978 bool result = true;
2980 /* Re-start here to avoid recursion in common cases. */
2981 restart:
2983 x = *loc;
2984 if (x == 0)
2985 return true;
2987 code = GET_CODE (x);
2989 /* If we don't return in any of the cases below, we will recurse inside
2990 the RTX, which will normally result in any ADDRESSOF being forced into
2991 memory. */
2992 if (code == SET)
2994 result = purge_addressof_1 (&SET_DEST (x), insn, force, 1, ht);
2995 result &= purge_addressof_1 (&SET_SRC (x), insn, force, 0, ht);
2996 return result;
2999 else if (code == ADDRESSOF && GET_CODE (XEXP (x, 0)) == MEM)
3001 /* We must create a copy of the rtx because it was created by
3002 overwriting a REG rtx which is always shared. */
3003 rtx sub = copy_rtx (XEXP (XEXP (x, 0), 0));
3004 rtx insns;
3006 if (validate_change (insn, loc, sub, 0)
3007 || validate_replace_rtx (x, sub, insn))
3008 return true;
3010 start_sequence ();
3011 sub = force_operand (sub, NULL_RTX);
3012 if (! validate_change (insn, loc, sub, 0)
3013 && ! validate_replace_rtx (x, sub, insn))
3014 abort ();
3016 insns = gen_sequence ();
3017 end_sequence ();
3018 emit_insn_before (insns, insn);
3019 return true;
3022 else if (code == MEM && GET_CODE (XEXP (x, 0)) == ADDRESSOF && ! force)
3024 rtx sub = XEXP (XEXP (x, 0), 0);
3025 rtx sub2;
3027 if (GET_CODE (sub) == MEM)
3029 sub2 = gen_rtx_MEM (GET_MODE (x), copy_rtx (XEXP (sub, 0)));
3030 MEM_COPY_ATTRIBUTES (sub2, sub);
3031 sub = sub2;
3033 else if (GET_CODE (sub) == REG
3034 && (MEM_VOLATILE_P (x) || GET_MODE (x) == BLKmode))
3036 else if (GET_CODE (sub) == REG && GET_MODE (x) != GET_MODE (sub))
3038 int size_x, size_sub;
3040 if (!insn)
3042 /* When processing REG_NOTES look at the list of
3043 replacements done on the insn to find the register that X
3044 was replaced by. */
3045 rtx tem;
3047 for (tem = purge_bitfield_addressof_replacements;
3048 tem != NULL_RTX;
3049 tem = XEXP (XEXP (tem, 1), 1))
3050 if (rtx_equal_p (x, XEXP (tem, 0)))
3052 *loc = XEXP (XEXP (tem, 1), 0);
3053 return true;
3056 /* See comment for purge_addressof_replacements. */
3057 for (tem = purge_addressof_replacements;
3058 tem != NULL_RTX;
3059 tem = XEXP (XEXP (tem, 1), 1))
3060 if (rtx_equal_p (XEXP (x, 0), XEXP (tem, 0)))
3062 rtx z = XEXP (XEXP (tem, 1), 0);
3064 if (GET_MODE (x) == GET_MODE (z)
3065 || (GET_CODE (XEXP (XEXP (tem, 1), 0)) != REG
3066 && GET_CODE (XEXP (XEXP (tem, 1), 0)) != SUBREG))
3067 abort ();
3069 /* It can happen that the note may speak of things
3070 in a wider (or just different) mode than the
3071 code did. This is especially true of
3072 REG_RETVAL. */
3074 if (GET_CODE (z) == SUBREG && SUBREG_WORD (z) == 0)
3075 z = SUBREG_REG (z);
3077 if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD
3078 && (GET_MODE_SIZE (GET_MODE (x))
3079 > GET_MODE_SIZE (GET_MODE (z))))
3081 /* This can occur as a result in invalid
3082 pointer casts, e.g. float f; ...
3083 *(long long int *)&f.
3084 ??? We could emit a warning here, but
3085 without a line number that wouldn't be
3086 very helpful. */
3087 z = gen_rtx_SUBREG (GET_MODE (x), z, 0);
3089 else
3090 z = gen_lowpart (GET_MODE (x), z);
3092 *loc = z;
3093 return true;
3096 /* Sometimes we may not be able to find the replacement. For
3097 example when the original insn was a MEM in a wider mode,
3098 and the note is part of a sign extension of a narrowed
3099 version of that MEM. Gcc testcase compile/990829-1.c can
3100 generate an example of this siutation. Rather than complain
3101 we return false, which will prompt our caller to remove the
3102 offending note. */
3103 return false;
3106 size_x = GET_MODE_BITSIZE (GET_MODE (x));
3107 size_sub = GET_MODE_BITSIZE (GET_MODE (sub));
3109 /* Don't even consider working with paradoxical subregs,
3110 or the moral equivalent seen here. */
3111 if (size_x <= size_sub
3112 && int_mode_for_mode (GET_MODE (sub)) != BLKmode)
3114 /* Do a bitfield insertion to mirror what would happen
3115 in memory. */
3117 rtx val, seq;
3119 if (store)
3121 rtx p = PREV_INSN (insn);
3123 start_sequence ();
3124 val = gen_reg_rtx (GET_MODE (x));
3125 if (! validate_change (insn, loc, val, 0))
3127 /* Discard the current sequence and put the
3128 ADDRESSOF on stack. */
3129 end_sequence ();
3130 goto give_up;
3132 seq = gen_sequence ();
3133 end_sequence ();
3134 emit_insn_before (seq, insn);
3135 compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (),
3136 insn, ht);
3138 start_sequence ();
3139 store_bit_field (sub, size_x, 0, GET_MODE (x),
3140 val, GET_MODE_SIZE (GET_MODE (sub)),
3141 GET_MODE_ALIGNMENT (GET_MODE (sub)));
3143 /* Make sure to unshare any shared rtl that store_bit_field
3144 might have created. */
3145 unshare_all_rtl_again (get_insns ());
3147 seq = gen_sequence ();
3148 end_sequence ();
3149 p = emit_insn_after (seq, insn);
3150 if (NEXT_INSN (insn))
3151 compute_insns_for_mem (NEXT_INSN (insn),
3152 p ? NEXT_INSN (p) : NULL_RTX,
3153 ht);
3155 else
3157 rtx p = PREV_INSN (insn);
3159 start_sequence ();
3160 val = extract_bit_field (sub, size_x, 0, 1, NULL_RTX,
3161 GET_MODE (x), GET_MODE (x),
3162 GET_MODE_SIZE (GET_MODE (sub)),
3163 GET_MODE_SIZE (GET_MODE (sub)));
3165 if (! validate_change (insn, loc, val, 0))
3167 /* Discard the current sequence and put the
3168 ADDRESSOF on stack. */
3169 end_sequence ();
3170 goto give_up;
3173 seq = gen_sequence ();
3174 end_sequence ();
3175 emit_insn_before (seq, insn);
3176 compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (),
3177 insn, ht);
3180 /* Remember the replacement so that the same one can be done
3181 on the REG_NOTES. */
3182 purge_bitfield_addressof_replacements
3183 = gen_rtx_EXPR_LIST (VOIDmode, x,
3184 gen_rtx_EXPR_LIST
3185 (VOIDmode, val,
3186 purge_bitfield_addressof_replacements));
3188 /* We replaced with a reg -- all done. */
3189 return true;
3193 else if (validate_change (insn, loc, sub, 0))
3195 /* Remember the replacement so that the same one can be done
3196 on the REG_NOTES. */
3197 if (GET_CODE (sub) == REG || GET_CODE (sub) == SUBREG)
3199 rtx tem;
3201 for (tem = purge_addressof_replacements;
3202 tem != NULL_RTX;
3203 tem = XEXP (XEXP (tem, 1), 1))
3204 if (rtx_equal_p (XEXP (x, 0), XEXP (tem, 0)))
3206 XEXP (XEXP (tem, 1), 0) = sub;
3207 return true;
3209 purge_addressof_replacements
3210 = gen_rtx (EXPR_LIST, VOIDmode, XEXP (x, 0),
3211 gen_rtx_EXPR_LIST (VOIDmode, sub,
3212 purge_addressof_replacements));
3213 return true;
3215 goto restart;
3217 give_up:;
3218 /* else give up and put it into the stack */
3221 else if (code == ADDRESSOF)
3223 put_addressof_into_stack (x, ht);
3224 return true;
3226 else if (code == SET)
3228 result = purge_addressof_1 (&SET_DEST (x), insn, force, 1, ht);
3229 result &= purge_addressof_1 (&SET_SRC (x), insn, force, 0, ht);
3230 return result;
3233 /* Scan all subexpressions. */
3234 fmt = GET_RTX_FORMAT (code);
3235 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
3237 if (*fmt == 'e')
3238 result &= purge_addressof_1 (&XEXP (x, i), insn, force, 0, ht);
3239 else if (*fmt == 'E')
3240 for (j = 0; j < XVECLEN (x, i); j++)
3241 result &= purge_addressof_1 (&XVECEXP (x, i, j), insn, force, 0, ht);
3244 return result;
3247 /* Return a new hash table entry in HT. */
3249 static struct hash_entry *
3250 insns_for_mem_newfunc (he, ht, k)
3251 struct hash_entry *he;
3252 struct hash_table *ht;
3253 hash_table_key k ATTRIBUTE_UNUSED;
3255 struct insns_for_mem_entry *ifmhe;
3256 if (he)
3257 return he;
3259 ifmhe = ((struct insns_for_mem_entry *)
3260 hash_allocate (ht, sizeof (struct insns_for_mem_entry)));
3261 ifmhe->insns = NULL_RTX;
3263 return &ifmhe->he;
3266 /* Return a hash value for K, a REG. */
3268 static unsigned long
3269 insns_for_mem_hash (k)
3270 hash_table_key k;
3272 /* K is really a RTX. Just use the address as the hash value. */
3273 return (unsigned long) k;
3276 /* Return non-zero if K1 and K2 (two REGs) are the same. */
3278 static bool
3279 insns_for_mem_comp (k1, k2)
3280 hash_table_key k1;
3281 hash_table_key k2;
3283 return k1 == k2;
3286 struct insns_for_mem_walk_info {
3287 /* The hash table that we are using to record which INSNs use which
3288 MEMs. */
3289 struct hash_table *ht;
3291 /* The INSN we are currently proessing. */
3292 rtx insn;
3294 /* Zero if we are walking to find ADDRESSOFs, one if we are walking
3295 to find the insns that use the REGs in the ADDRESSOFs. */
3296 int pass;
3299 /* Called from compute_insns_for_mem via for_each_rtx. If R is a REG
3300 that might be used in an ADDRESSOF expression, record this INSN in
3301 the hash table given by DATA (which is really a pointer to an
3302 insns_for_mem_walk_info structure). */
3304 static int
3305 insns_for_mem_walk (r, data)
3306 rtx *r;
3307 void *data;
3309 struct insns_for_mem_walk_info *ifmwi
3310 = (struct insns_for_mem_walk_info *) data;
3312 if (ifmwi->pass == 0 && *r && GET_CODE (*r) == ADDRESSOF
3313 && GET_CODE (XEXP (*r, 0)) == REG)
3314 hash_lookup (ifmwi->ht, XEXP (*r, 0), /*create=*/1, /*copy=*/0);
3315 else if (ifmwi->pass == 1 && *r && GET_CODE (*r) == REG)
3317 /* Lookup this MEM in the hashtable, creating it if necessary. */
3318 struct insns_for_mem_entry *ifme
3319 = (struct insns_for_mem_entry *) hash_lookup (ifmwi->ht,
3321 /*create=*/0,
3322 /*copy=*/0);
3324 /* If we have not already recorded this INSN, do so now. Since
3325 we process the INSNs in order, we know that if we have
3326 recorded it it must be at the front of the list. */
3327 if (ifme && (!ifme->insns || XEXP (ifme->insns, 0) != ifmwi->insn))
3328 ifme->insns = gen_rtx_EXPR_LIST (VOIDmode, ifmwi->insn,
3329 ifme->insns);
3332 return 0;
3335 /* Walk the INSNS, until we reach LAST_INSN, recording which INSNs use
3336 which REGs in HT. */
3338 static void
3339 compute_insns_for_mem (insns, last_insn, ht)
3340 rtx insns;
3341 rtx last_insn;
3342 struct hash_table *ht;
3344 rtx insn;
3345 struct insns_for_mem_walk_info ifmwi;
3346 ifmwi.ht = ht;
3348 for (ifmwi.pass = 0; ifmwi.pass < 2; ++ifmwi.pass)
3349 for (insn = insns; insn != last_insn; insn = NEXT_INSN (insn))
3350 if (INSN_P (insn))
3352 ifmwi.insn = insn;
3353 for_each_rtx (&insn, insns_for_mem_walk, &ifmwi);
3357 /* Helper function for purge_addressof called through for_each_rtx.
3358 Returns true iff the rtl is an ADDRESSOF. */
3359 static int
3360 is_addressof (rtl, data)
3361 rtx *rtl;
3362 void *data ATTRIBUTE_UNUSED;
3364 return GET_CODE (*rtl) == ADDRESSOF;
3367 /* Eliminate all occurrences of ADDRESSOF from INSNS. Elide any remaining
3368 (MEM (ADDRESSOF)) patterns, and force any needed registers into the
3369 stack. */
3371 void
3372 purge_addressof (insns)
3373 rtx insns;
3375 rtx insn;
3376 struct hash_table ht;
3378 /* When we actually purge ADDRESSOFs, we turn REGs into MEMs. That
3379 requires a fixup pass over the instruction stream to correct
3380 INSNs that depended on the REG being a REG, and not a MEM. But,
3381 these fixup passes are slow. Furthermore, most MEMs are not
3382 mentioned in very many instructions. So, we speed up the process
3383 by pre-calculating which REGs occur in which INSNs; that allows
3384 us to perform the fixup passes much more quickly. */
3385 hash_table_init (&ht,
3386 insns_for_mem_newfunc,
3387 insns_for_mem_hash,
3388 insns_for_mem_comp);
3389 compute_insns_for_mem (insns, NULL_RTX, &ht);
3391 for (insn = insns; insn; insn = NEXT_INSN (insn))
3392 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
3393 || GET_CODE (insn) == CALL_INSN)
3395 if (! purge_addressof_1 (&PATTERN (insn), insn,
3396 asm_noperands (PATTERN (insn)) > 0, 0, &ht))
3397 /* If we could not replace the ADDRESSOFs in the insn,
3398 something is wrong. */
3399 abort ();
3401 if (! purge_addressof_1 (&REG_NOTES (insn), NULL_RTX, 0, 0, &ht))
3403 /* If we could not replace the ADDRESSOFs in the insn's notes,
3404 we can just remove the offending notes instead. */
3405 rtx note;
3407 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
3409 /* If we find a REG_RETVAL note then the insn is a libcall.
3410 Such insns must have REG_EQUAL notes as well, in order
3411 for later passes of the compiler to work. So it is not
3412 safe to delete the notes here, and instead we abort. */
3413 if (REG_NOTE_KIND (note) == REG_RETVAL)
3414 abort ();
3415 if (for_each_rtx (&note, is_addressof, NULL))
3416 remove_note (insn, note);
3421 /* Clean up. */
3422 hash_table_free (&ht);
3423 purge_bitfield_addressof_replacements = 0;
3424 purge_addressof_replacements = 0;
3426 /* REGs are shared. purge_addressof will destructively replace a REG
3427 with a MEM, which creates shared MEMs.
3429 Unfortunately, the children of put_reg_into_stack assume that MEMs
3430 referring to the same stack slot are shared (fixup_var_refs and
3431 the associated hash table code).
3433 So, we have to do another unsharing pass after we have flushed any
3434 REGs that had their address taken into the stack.
3436 It may be worth tracking whether or not we converted any REGs into
3437 MEMs to avoid this overhead when it is not needed. */
3438 unshare_all_rtl_again (get_insns ());
3441 /* Convert a SET of a hard subreg to a set of the appropriet hard
3442 register. A subroutine of purge_hard_subreg_sets. */
3444 static void
3445 purge_single_hard_subreg_set (pattern)
3446 rtx pattern;
3448 rtx reg = SET_DEST (pattern);
3449 enum machine_mode mode = GET_MODE (SET_DEST (pattern));
3450 int word = 0;
3452 while (GET_CODE (reg) == SUBREG)
3454 word += SUBREG_WORD (reg);
3455 reg = SUBREG_REG (reg);
3458 if (REGNO (reg) < FIRST_PSEUDO_REGISTER)
3460 reg = gen_rtx_REG (mode, REGNO (reg) + word);
3461 SET_DEST (pattern) = reg;
3465 /* Eliminate all occurrences of SETs of hard subregs from INSNS. The
3466 only such SETs that we expect to see are those left in because
3467 integrate can't handle sets of parts of a return value register.
3469 We don't use alter_subreg because we only want to eliminate subregs
3470 of hard registers. */
3472 void
3473 purge_hard_subreg_sets (insn)
3474 rtx insn;
3476 for (; insn; insn = NEXT_INSN (insn))
3478 if (INSN_P (insn))
3480 rtx pattern = PATTERN (insn);
3481 switch (GET_CODE (pattern))
3483 case SET:
3484 if (GET_CODE (SET_DEST (pattern)) == SUBREG)
3485 purge_single_hard_subreg_set (pattern);
3486 break;
3487 case PARALLEL:
3489 int j;
3490 for (j = XVECLEN (pattern, 0) - 1; j >= 0; j--)
3492 rtx inner_pattern = XVECEXP (pattern, 0, j);
3493 if (GET_CODE (inner_pattern) == SET
3494 && GET_CODE (SET_DEST (inner_pattern)) == SUBREG)
3495 purge_single_hard_subreg_set (inner_pattern);
3498 break;
3499 default:
3500 break;
3506 /* Pass through the INSNS of function FNDECL and convert virtual register
3507 references to hard register references. */
3509 void
3510 instantiate_virtual_regs (fndecl, insns)
3511 tree fndecl;
3512 rtx insns;
3514 rtx insn;
3515 unsigned int i;
3517 /* Compute the offsets to use for this function. */
3518 in_arg_offset = FIRST_PARM_OFFSET (fndecl);
3519 var_offset = STARTING_FRAME_OFFSET;
3520 dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl);
3521 out_arg_offset = STACK_POINTER_OFFSET;
3522 cfa_offset = ARG_POINTER_CFA_OFFSET (fndecl);
3524 /* Scan all variables and parameters of this function. For each that is
3525 in memory, instantiate all virtual registers if the result is a valid
3526 address. If not, we do it later. That will handle most uses of virtual
3527 regs on many machines. */
3528 instantiate_decls (fndecl, 1);
3530 /* Initialize recognition, indicating that volatile is OK. */
3531 init_recog ();
3533 /* Scan through all the insns, instantiating every virtual register still
3534 present. */
3535 for (insn = insns; insn; insn = NEXT_INSN (insn))
3536 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
3537 || GET_CODE (insn) == CALL_INSN)
3539 instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1);
3540 instantiate_virtual_regs_1 (&REG_NOTES (insn), NULL_RTX, 0);
3541 /* Instantiate any virtual registers in CALL_INSN_FUNCTION_USAGE. */
3542 if (GET_CODE (insn) == CALL_INSN)
3543 instantiate_virtual_regs_1 (&CALL_INSN_FUNCTION_USAGE (insn),
3544 NULL_RTX, 0);
3547 /* Instantiate the stack slots for the parm registers, for later use in
3548 addressof elimination. */
3549 for (i = 0; i < max_parm_reg; ++i)
3550 if (parm_reg_stack_loc[i])
3551 instantiate_virtual_regs_1 (&parm_reg_stack_loc[i], NULL_RTX, 0);
3553 /* Now instantiate the remaining register equivalences for debugging info.
3554 These will not be valid addresses. */
3555 instantiate_decls (fndecl, 0);
3557 /* Indicate that, from now on, assign_stack_local should use
3558 frame_pointer_rtx. */
3559 virtuals_instantiated = 1;
3562 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
3563 all virtual registers in their DECL_RTL's.
3565 If VALID_ONLY, do this only if the resulting address is still valid.
3566 Otherwise, always do it. */
3568 static void
3569 instantiate_decls (fndecl, valid_only)
3570 tree fndecl;
3571 int valid_only;
3573 tree decl;
3575 /* Process all parameters of the function. */
3576 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
3578 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
3580 instantiate_decl (DECL_RTL (decl), size, valid_only);
3582 /* If the parameter was promoted, then the incoming RTL mode may be
3583 larger than the declared type size. We must use the larger of
3584 the two sizes. */
3585 size = MAX (GET_MODE_SIZE (GET_MODE (DECL_INCOMING_RTL (decl))), size);
3586 instantiate_decl (DECL_INCOMING_RTL (decl), size, valid_only);
3589 /* Now process all variables defined in the function or its subblocks. */
3590 instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only);
3593 /* Subroutine of instantiate_decls: Process all decls in the given
3594 BLOCK node and all its subblocks. */
3596 static void
3597 instantiate_decls_1 (let, valid_only)
3598 tree let;
3599 int valid_only;
3601 tree t;
3603 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
3604 if (DECL_RTL_SET_P (t))
3605 instantiate_decl (DECL_RTL (t),
3606 int_size_in_bytes (TREE_TYPE (t)),
3607 valid_only);
3609 /* Process all subblocks. */
3610 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
3611 instantiate_decls_1 (t, valid_only);
3614 /* Subroutine of the preceding procedures: Given RTL representing a
3615 decl and the size of the object, do any instantiation required.
3617 If VALID_ONLY is non-zero, it means that the RTL should only be
3618 changed if the new address is valid. */
3620 static void
3621 instantiate_decl (x, size, valid_only)
3622 rtx x;
3623 HOST_WIDE_INT size;
3624 int valid_only;
3626 enum machine_mode mode;
3627 rtx addr;
3629 /* If this is not a MEM, no need to do anything. Similarly if the
3630 address is a constant or a register that is not a virtual register. */
3632 if (x == 0 || GET_CODE (x) != MEM)
3633 return;
3635 addr = XEXP (x, 0);
3636 if (CONSTANT_P (addr)
3637 || (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == REG)
3638 || (GET_CODE (addr) == REG
3639 && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
3640 || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
3641 return;
3643 /* If we should only do this if the address is valid, copy the address.
3644 We need to do this so we can undo any changes that might make the
3645 address invalid. This copy is unfortunate, but probably can't be
3646 avoided. */
3648 if (valid_only)
3649 addr = copy_rtx (addr);
3651 instantiate_virtual_regs_1 (&addr, NULL_RTX, 0);
3653 if (valid_only && size >= 0)
3655 unsigned HOST_WIDE_INT decl_size = size;
3657 /* Now verify that the resulting address is valid for every integer or
3658 floating-point mode up to and including SIZE bytes long. We do this
3659 since the object might be accessed in any mode and frame addresses
3660 are shared. */
3662 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
3663 mode != VOIDmode && GET_MODE_SIZE (mode) <= decl_size;
3664 mode = GET_MODE_WIDER_MODE (mode))
3665 if (! memory_address_p (mode, addr))
3666 return;
3668 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
3669 mode != VOIDmode && GET_MODE_SIZE (mode) <= decl_size;
3670 mode = GET_MODE_WIDER_MODE (mode))
3671 if (! memory_address_p (mode, addr))
3672 return;
3675 /* Put back the address now that we have updated it and we either know
3676 it is valid or we don't care whether it is valid. */
3678 XEXP (x, 0) = addr;
3681 /* Given a piece of RTX and a pointer to a HOST_WIDE_INT, if the RTX
3682 is a virtual register, return the requivalent hard register and set the
3683 offset indirectly through the pointer. Otherwise, return 0. */
3685 static rtx
3686 instantiate_new_reg (x, poffset)
3687 rtx x;
3688 HOST_WIDE_INT *poffset;
3690 rtx new;
3691 HOST_WIDE_INT offset;
3693 if (x == virtual_incoming_args_rtx)
3694 new = arg_pointer_rtx, offset = in_arg_offset;
3695 else if (x == virtual_stack_vars_rtx)
3696 new = frame_pointer_rtx, offset = var_offset;
3697 else if (x == virtual_stack_dynamic_rtx)
3698 new = stack_pointer_rtx, offset = dynamic_offset;
3699 else if (x == virtual_outgoing_args_rtx)
3700 new = stack_pointer_rtx, offset = out_arg_offset;
3701 else if (x == virtual_cfa_rtx)
3702 new = arg_pointer_rtx, offset = cfa_offset;
3703 else
3704 return 0;
3706 *poffset = offset;
3707 return new;
3710 /* Given a pointer to a piece of rtx and an optional pointer to the
3711 containing object, instantiate any virtual registers present in it.
3713 If EXTRA_INSNS, we always do the replacement and generate
3714 any extra insns before OBJECT. If it zero, we do nothing if replacement
3715 is not valid.
3717 Return 1 if we either had nothing to do or if we were able to do the
3718 needed replacement. Return 0 otherwise; we only return zero if
3719 EXTRA_INSNS is zero.
3721 We first try some simple transformations to avoid the creation of extra
3722 pseudos. */
3724 static int
3725 instantiate_virtual_regs_1 (loc, object, extra_insns)
3726 rtx *loc;
3727 rtx object;
3728 int extra_insns;
3730 rtx x;
3731 RTX_CODE code;
3732 rtx new = 0;
3733 HOST_WIDE_INT offset = 0;
3734 rtx temp;
3735 rtx seq;
3736 int i, j;
3737 const char *fmt;
3739 /* Re-start here to avoid recursion in common cases. */
3740 restart:
3742 x = *loc;
3743 if (x == 0)
3744 return 1;
3746 code = GET_CODE (x);
3748 /* Check for some special cases. */
3749 switch (code)
3751 case CONST_INT:
3752 case CONST_DOUBLE:
3753 case CONST:
3754 case SYMBOL_REF:
3755 case CODE_LABEL:
3756 case PC:
3757 case CC0:
3758 case ASM_INPUT:
3759 case ADDR_VEC:
3760 case ADDR_DIFF_VEC:
3761 case RETURN:
3762 return 1;
3764 case SET:
3765 /* We are allowed to set the virtual registers. This means that
3766 the actual register should receive the source minus the
3767 appropriate offset. This is used, for example, in the handling
3768 of non-local gotos. */
3769 if ((new = instantiate_new_reg (SET_DEST (x), &offset)) != 0)
3771 rtx src = SET_SRC (x);
3773 /* We are setting the register, not using it, so the relevant
3774 offset is the negative of the offset to use were we using
3775 the register. */
3776 offset = - offset;
3777 instantiate_virtual_regs_1 (&src, NULL_RTX, 0);
3779 /* The only valid sources here are PLUS or REG. Just do
3780 the simplest possible thing to handle them. */
3781 if (GET_CODE (src) != REG && GET_CODE (src) != PLUS)
3782 abort ();
3784 start_sequence ();
3785 if (GET_CODE (src) != REG)
3786 temp = force_operand (src, NULL_RTX);
3787 else
3788 temp = src;
3789 temp = force_operand (plus_constant (temp, offset), NULL_RTX);
3790 seq = get_insns ();
3791 end_sequence ();
3793 emit_insns_before (seq, object);
3794 SET_DEST (x) = new;
3796 if (! validate_change (object, &SET_SRC (x), temp, 0)
3797 || ! extra_insns)
3798 abort ();
3800 return 1;
3803 instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns);
3804 loc = &SET_SRC (x);
3805 goto restart;
3807 case PLUS:
3808 /* Handle special case of virtual register plus constant. */
3809 if (CONSTANT_P (XEXP (x, 1)))
3811 rtx old, new_offset;
3813 /* Check for (plus (plus VIRT foo) (const_int)) first. */
3814 if (GET_CODE (XEXP (x, 0)) == PLUS)
3816 if ((new = instantiate_new_reg (XEXP (XEXP (x, 0), 0), &offset)))
3818 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object,
3819 extra_insns);
3820 new = gen_rtx_PLUS (Pmode, new, XEXP (XEXP (x, 0), 1));
3822 else
3824 loc = &XEXP (x, 0);
3825 goto restart;
3829 #ifdef POINTERS_EXTEND_UNSIGNED
3830 /* If we have (plus (subreg (virtual-reg)) (const_int)), we know
3831 we can commute the PLUS and SUBREG because pointers into the
3832 frame are well-behaved. */
3833 else if (GET_CODE (XEXP (x, 0)) == SUBREG && GET_MODE (x) == ptr_mode
3834 && GET_CODE (XEXP (x, 1)) == CONST_INT
3835 && 0 != (new
3836 = instantiate_new_reg (SUBREG_REG (XEXP (x, 0)),
3837 &offset))
3838 && validate_change (object, loc,
3839 plus_constant (gen_lowpart (ptr_mode,
3840 new),
3841 offset
3842 + INTVAL (XEXP (x, 1))),
3844 return 1;
3845 #endif
3846 else if ((new = instantiate_new_reg (XEXP (x, 0), &offset)) == 0)
3848 /* We know the second operand is a constant. Unless the
3849 first operand is a REG (which has been already checked),
3850 it needs to be checked. */
3851 if (GET_CODE (XEXP (x, 0)) != REG)
3853 loc = &XEXP (x, 0);
3854 goto restart;
3856 return 1;
3859 new_offset = plus_constant (XEXP (x, 1), offset);
3861 /* If the new constant is zero, try to replace the sum with just
3862 the register. */
3863 if (new_offset == const0_rtx
3864 && validate_change (object, loc, new, 0))
3865 return 1;
3867 /* Next try to replace the register and new offset.
3868 There are two changes to validate here and we can't assume that
3869 in the case of old offset equals new just changing the register
3870 will yield a valid insn. In the interests of a little efficiency,
3871 however, we only call validate change once (we don't queue up the
3872 changes and then call apply_change_group). */
3874 old = XEXP (x, 0);
3875 if (offset == 0
3876 ? ! validate_change (object, &XEXP (x, 0), new, 0)
3877 : (XEXP (x, 0) = new,
3878 ! validate_change (object, &XEXP (x, 1), new_offset, 0)))
3880 if (! extra_insns)
3882 XEXP (x, 0) = old;
3883 return 0;
3886 /* Otherwise copy the new constant into a register and replace
3887 constant with that register. */
3888 temp = gen_reg_rtx (Pmode);
3889 XEXP (x, 0) = new;
3890 if (validate_change (object, &XEXP (x, 1), temp, 0))
3891 emit_insn_before (gen_move_insn (temp, new_offset), object);
3892 else
3894 /* If that didn't work, replace this expression with a
3895 register containing the sum. */
3897 XEXP (x, 0) = old;
3898 new = gen_rtx_PLUS (Pmode, new, new_offset);
3900 start_sequence ();
3901 temp = force_operand (new, NULL_RTX);
3902 seq = get_insns ();
3903 end_sequence ();
3905 emit_insns_before (seq, object);
3906 if (! validate_change (object, loc, temp, 0)
3907 && ! validate_replace_rtx (x, temp, object))
3908 abort ();
3912 return 1;
3915 /* Fall through to generic two-operand expression case. */
3916 case EXPR_LIST:
3917 case CALL:
3918 case COMPARE:
3919 case MINUS:
3920 case MULT:
3921 case DIV: case UDIV:
3922 case MOD: case UMOD:
3923 case AND: case IOR: case XOR:
3924 case ROTATERT: case ROTATE:
3925 case ASHIFTRT: case LSHIFTRT: case ASHIFT:
3926 case NE: case EQ:
3927 case GE: case GT: case GEU: case GTU:
3928 case LE: case LT: case LEU: case LTU:
3929 if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1)))
3930 instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns);
3931 loc = &XEXP (x, 0);
3932 goto restart;
3934 case MEM:
3935 /* Most cases of MEM that convert to valid addresses have already been
3936 handled by our scan of decls. The only special handling we
3937 need here is to make a copy of the rtx to ensure it isn't being
3938 shared if we have to change it to a pseudo.
3940 If the rtx is a simple reference to an address via a virtual register,
3941 it can potentially be shared. In such cases, first try to make it
3942 a valid address, which can also be shared. Otherwise, copy it and
3943 proceed normally.
3945 First check for common cases that need no processing. These are
3946 usually due to instantiation already being done on a previous instance
3947 of a shared rtx. */
3949 temp = XEXP (x, 0);
3950 if (CONSTANT_ADDRESS_P (temp)
3951 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3952 || temp == arg_pointer_rtx
3953 #endif
3954 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3955 || temp == hard_frame_pointer_rtx
3956 #endif
3957 || temp == frame_pointer_rtx)
3958 return 1;
3960 if (GET_CODE (temp) == PLUS
3961 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
3962 && (XEXP (temp, 0) == frame_pointer_rtx
3963 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3964 || XEXP (temp, 0) == hard_frame_pointer_rtx
3965 #endif
3966 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3967 || XEXP (temp, 0) == arg_pointer_rtx
3968 #endif
3970 return 1;
3972 if (temp == virtual_stack_vars_rtx
3973 || temp == virtual_incoming_args_rtx
3974 || (GET_CODE (temp) == PLUS
3975 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
3976 && (XEXP (temp, 0) == virtual_stack_vars_rtx
3977 || XEXP (temp, 0) == virtual_incoming_args_rtx)))
3979 /* This MEM may be shared. If the substitution can be done without
3980 the need to generate new pseudos, we want to do it in place
3981 so all copies of the shared rtx benefit. The call below will
3982 only make substitutions if the resulting address is still
3983 valid.
3985 Note that we cannot pass X as the object in the recursive call
3986 since the insn being processed may not allow all valid
3987 addresses. However, if we were not passed on object, we can
3988 only modify X without copying it if X will have a valid
3989 address.
3991 ??? Also note that this can still lose if OBJECT is an insn that
3992 has less restrictions on an address that some other insn.
3993 In that case, we will modify the shared address. This case
3994 doesn't seem very likely, though. One case where this could
3995 happen is in the case of a USE or CLOBBER reference, but we
3996 take care of that below. */
3998 if (instantiate_virtual_regs_1 (&XEXP (x, 0),
3999 object ? object : x, 0))
4000 return 1;
4002 /* Otherwise make a copy and process that copy. We copy the entire
4003 RTL expression since it might be a PLUS which could also be
4004 shared. */
4005 *loc = x = copy_rtx (x);
4008 /* Fall through to generic unary operation case. */
4009 case SUBREG:
4010 case STRICT_LOW_PART:
4011 case NEG: case NOT:
4012 case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC:
4013 case SIGN_EXTEND: case ZERO_EXTEND:
4014 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE:
4015 case FLOAT: case FIX:
4016 case UNSIGNED_FIX: case UNSIGNED_FLOAT:
4017 case ABS:
4018 case SQRT:
4019 case FFS:
4020 /* These case either have just one operand or we know that we need not
4021 check the rest of the operands. */
4022 loc = &XEXP (x, 0);
4023 goto restart;
4025 case USE:
4026 case CLOBBER:
4027 /* If the operand is a MEM, see if the change is a valid MEM. If not,
4028 go ahead and make the invalid one, but do it to a copy. For a REG,
4029 just make the recursive call, since there's no chance of a problem. */
4031 if ((GET_CODE (XEXP (x, 0)) == MEM
4032 && instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), XEXP (x, 0),
4034 || (GET_CODE (XEXP (x, 0)) == REG
4035 && instantiate_virtual_regs_1 (&XEXP (x, 0), object, 0)))
4036 return 1;
4038 XEXP (x, 0) = copy_rtx (XEXP (x, 0));
4039 loc = &XEXP (x, 0);
4040 goto restart;
4042 case REG:
4043 /* Try to replace with a PLUS. If that doesn't work, compute the sum
4044 in front of this insn and substitute the temporary. */
4045 if ((new = instantiate_new_reg (x, &offset)) != 0)
4047 temp = plus_constant (new, offset);
4048 if (!validate_change (object, loc, temp, 0))
4050 if (! extra_insns)
4051 return 0;
4053 start_sequence ();
4054 temp = force_operand (temp, NULL_RTX);
4055 seq = get_insns ();
4056 end_sequence ();
4058 emit_insns_before (seq, object);
4059 if (! validate_change (object, loc, temp, 0)
4060 && ! validate_replace_rtx (x, temp, object))
4061 abort ();
4065 return 1;
4067 case ADDRESSOF:
4068 if (GET_CODE (XEXP (x, 0)) == REG)
4069 return 1;
4071 else if (GET_CODE (XEXP (x, 0)) == MEM)
4073 /* If we have a (addressof (mem ..)), do any instantiation inside
4074 since we know we'll be making the inside valid when we finally
4075 remove the ADDRESSOF. */
4076 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), NULL_RTX, 0);
4077 return 1;
4079 break;
4081 default:
4082 break;
4085 /* Scan all subexpressions. */
4086 fmt = GET_RTX_FORMAT (code);
4087 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
4088 if (*fmt == 'e')
4090 if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns))
4091 return 0;
4093 else if (*fmt == 'E')
4094 for (j = 0; j < XVECLEN (x, i); j++)
4095 if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object,
4096 extra_insns))
4097 return 0;
4099 return 1;
4102 /* Optimization: assuming this function does not receive nonlocal gotos,
4103 delete the handlers for such, as well as the insns to establish
4104 and disestablish them. */
4106 static void
4107 delete_handlers ()
4109 rtx insn;
4110 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4112 /* Delete the handler by turning off the flag that would
4113 prevent jump_optimize from deleting it.
4114 Also permit deletion of the nonlocal labels themselves
4115 if nothing local refers to them. */
4116 if (GET_CODE (insn) == CODE_LABEL)
4118 tree t, last_t;
4120 LABEL_PRESERVE_P (insn) = 0;
4122 /* Remove it from the nonlocal_label list, to avoid confusing
4123 flow. */
4124 for (t = nonlocal_labels, last_t = 0; t;
4125 last_t = t, t = TREE_CHAIN (t))
4126 if (DECL_RTL (TREE_VALUE (t)) == insn)
4127 break;
4128 if (t)
4130 if (! last_t)
4131 nonlocal_labels = TREE_CHAIN (nonlocal_labels);
4132 else
4133 TREE_CHAIN (last_t) = TREE_CHAIN (t);
4136 if (GET_CODE (insn) == INSN)
4138 int can_delete = 0;
4139 rtx t;
4140 for (t = nonlocal_goto_handler_slots; t != 0; t = XEXP (t, 1))
4141 if (reg_mentioned_p (t, PATTERN (insn)))
4143 can_delete = 1;
4144 break;
4146 if (can_delete
4147 || (nonlocal_goto_stack_level != 0
4148 && reg_mentioned_p (nonlocal_goto_stack_level,
4149 PATTERN (insn))))
4150 delete_insn (insn);
4156 max_parm_reg_num ()
4158 return max_parm_reg;
4161 /* Return the first insn following those generated by `assign_parms'. */
4164 get_first_nonparm_insn ()
4166 if (last_parm_insn)
4167 return NEXT_INSN (last_parm_insn);
4168 return get_insns ();
4171 /* Return the first NOTE_INSN_BLOCK_BEG note in the function.
4172 Crash if there is none. */
4175 get_first_block_beg ()
4177 register rtx searcher;
4178 register rtx insn = get_first_nonparm_insn ();
4180 for (searcher = insn; searcher; searcher = NEXT_INSN (searcher))
4181 if (GET_CODE (searcher) == NOTE
4182 && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG)
4183 return searcher;
4185 abort (); /* Invalid call to this function. (See comments above.) */
4186 return NULL_RTX;
4189 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
4190 This means a type for which function calls must pass an address to the
4191 function or get an address back from the function.
4192 EXP may be a type node or an expression (whose type is tested). */
4195 aggregate_value_p (exp)
4196 tree exp;
4198 int i, regno, nregs;
4199 rtx reg;
4201 tree type = (TYPE_P (exp)) ? exp : TREE_TYPE (exp);
4203 if (TREE_CODE (type) == VOID_TYPE)
4204 return 0;
4205 if (RETURN_IN_MEMORY (type))
4206 return 1;
4207 /* Types that are TREE_ADDRESSABLE must be constructed in memory,
4208 and thus can't be returned in registers. */
4209 if (TREE_ADDRESSABLE (type))
4210 return 1;
4211 if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
4212 return 1;
4213 /* Make sure we have suitable call-clobbered regs to return
4214 the value in; if not, we must return it in memory. */
4215 reg = hard_function_value (type, 0, 0);
4217 /* If we have something other than a REG (e.g. a PARALLEL), then assume
4218 it is OK. */
4219 if (GET_CODE (reg) != REG)
4220 return 0;
4222 regno = REGNO (reg);
4223 nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type));
4224 for (i = 0; i < nregs; i++)
4225 if (! call_used_regs[regno + i])
4226 return 1;
4227 return 0;
4230 /* Assign RTL expressions to the function's parameters.
4231 This may involve copying them into registers and using
4232 those registers as the RTL for them. */
4234 void
4235 assign_parms (fndecl)
4236 tree fndecl;
4238 register tree parm;
4239 register rtx entry_parm = 0;
4240 register rtx stack_parm = 0;
4241 CUMULATIVE_ARGS args_so_far;
4242 enum machine_mode promoted_mode, passed_mode;
4243 enum machine_mode nominal_mode, promoted_nominal_mode;
4244 int unsignedp;
4245 /* Total space needed so far for args on the stack,
4246 given as a constant and a tree-expression. */
4247 struct args_size stack_args_size;
4248 tree fntype = TREE_TYPE (fndecl);
4249 tree fnargs = DECL_ARGUMENTS (fndecl);
4250 /* This is used for the arg pointer when referring to stack args. */
4251 rtx internal_arg_pointer;
4252 /* This is a dummy PARM_DECL that we used for the function result if
4253 the function returns a structure. */
4254 tree function_result_decl = 0;
4255 #ifdef SETUP_INCOMING_VARARGS
4256 int varargs_setup = 0;
4257 #endif
4258 rtx conversion_insns = 0;
4259 struct args_size alignment_pad;
4261 /* Nonzero if the last arg is named `__builtin_va_alist',
4262 which is used on some machines for old-fashioned non-ANSI varargs.h;
4263 this should be stuck onto the stack as if it had arrived there. */
4264 int hide_last_arg
4265 = (current_function_varargs
4266 && fnargs
4267 && (parm = tree_last (fnargs)) != 0
4268 && DECL_NAME (parm)
4269 && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
4270 "__builtin_va_alist")));
4272 /* Nonzero if function takes extra anonymous args.
4273 This means the last named arg must be on the stack
4274 right before the anonymous ones. */
4275 int stdarg
4276 = (TYPE_ARG_TYPES (fntype) != 0
4277 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
4278 != void_type_node));
4280 current_function_stdarg = stdarg;
4282 /* If the reg that the virtual arg pointer will be translated into is
4283 not a fixed reg or is the stack pointer, make a copy of the virtual
4284 arg pointer, and address parms via the copy. The frame pointer is
4285 considered fixed even though it is not marked as such.
4287 The second time through, simply use ap to avoid generating rtx. */
4289 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
4290 || ! (fixed_regs[ARG_POINTER_REGNUM]
4291 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM)))
4292 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
4293 else
4294 internal_arg_pointer = virtual_incoming_args_rtx;
4295 current_function_internal_arg_pointer = internal_arg_pointer;
4297 stack_args_size.constant = 0;
4298 stack_args_size.var = 0;
4300 /* If struct value address is treated as the first argument, make it so. */
4301 if (aggregate_value_p (DECL_RESULT (fndecl))
4302 && ! current_function_returns_pcc_struct
4303 && struct_value_incoming_rtx == 0)
4305 tree type = build_pointer_type (TREE_TYPE (fntype));
4307 function_result_decl = build_decl (PARM_DECL, NULL_TREE, type);
4309 DECL_ARG_TYPE (function_result_decl) = type;
4310 TREE_CHAIN (function_result_decl) = fnargs;
4311 fnargs = function_result_decl;
4314 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
4315 parm_reg_stack_loc = (rtx *) xcalloc (max_parm_reg, sizeof (rtx));
4317 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
4318 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX);
4319 #else
4320 INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX, 0);
4321 #endif
4323 /* We haven't yet found an argument that we must push and pretend the
4324 caller did. */
4325 current_function_pretend_args_size = 0;
4327 for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
4329 struct args_size stack_offset;
4330 struct args_size arg_size;
4331 int passed_pointer = 0;
4332 int did_conversion = 0;
4333 tree passed_type = DECL_ARG_TYPE (parm);
4334 tree nominal_type = TREE_TYPE (parm);
4335 int pretend_named;
4337 /* Set LAST_NAMED if this is last named arg before some
4338 anonymous args. */
4339 int last_named = ((TREE_CHAIN (parm) == 0
4340 || DECL_NAME (TREE_CHAIN (parm)) == 0)
4341 && (stdarg || current_function_varargs));
4342 /* Set NAMED_ARG if this arg should be treated as a named arg. For
4343 most machines, if this is a varargs/stdarg function, then we treat
4344 the last named arg as if it were anonymous too. */
4345 int named_arg = STRICT_ARGUMENT_NAMING ? 1 : ! last_named;
4347 if (TREE_TYPE (parm) == error_mark_node
4348 /* This can happen after weird syntax errors
4349 or if an enum type is defined among the parms. */
4350 || TREE_CODE (parm) != PARM_DECL
4351 || passed_type == NULL)
4353 SET_DECL_RTL (parm, gen_rtx_MEM (BLKmode, const0_rtx));
4354 DECL_INCOMING_RTL (parm) = DECL_RTL (parm);
4355 TREE_USED (parm) = 1;
4356 continue;
4359 /* For varargs.h function, save info about regs and stack space
4360 used by the individual args, not including the va_alist arg. */
4361 if (hide_last_arg && last_named)
4362 current_function_args_info = args_so_far;
4364 /* Find mode of arg as it is passed, and mode of arg
4365 as it should be during execution of this function. */
4366 passed_mode = TYPE_MODE (passed_type);
4367 nominal_mode = TYPE_MODE (nominal_type);
4369 /* If the parm's mode is VOID, its value doesn't matter,
4370 and avoid the usual things like emit_move_insn that could crash. */
4371 if (nominal_mode == VOIDmode)
4373 SET_DECL_RTL (parm, const0_rtx);
4374 DECL_INCOMING_RTL (parm) = DECL_RTL (parm);
4375 continue;
4378 /* If the parm is to be passed as a transparent union, use the
4379 type of the first field for the tests below. We have already
4380 verified that the modes are the same. */
4381 if (DECL_TRANSPARENT_UNION (parm)
4382 || (TREE_CODE (passed_type) == UNION_TYPE
4383 && TYPE_TRANSPARENT_UNION (passed_type)))
4384 passed_type = TREE_TYPE (TYPE_FIELDS (passed_type));
4386 /* See if this arg was passed by invisible reference. It is if
4387 it is an object whose size depends on the contents of the
4388 object itself or if the machine requires these objects be passed
4389 that way. */
4391 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
4392 && contains_placeholder_p (TYPE_SIZE (passed_type)))
4393 || TREE_ADDRESSABLE (passed_type)
4394 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
4395 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode,
4396 passed_type, named_arg)
4397 #endif
4400 passed_type = nominal_type = build_pointer_type (passed_type);
4401 passed_pointer = 1;
4402 passed_mode = nominal_mode = Pmode;
4405 promoted_mode = passed_mode;
4407 #ifdef PROMOTE_FUNCTION_ARGS
4408 /* Compute the mode in which the arg is actually extended to. */
4409 unsignedp = TREE_UNSIGNED (passed_type);
4410 promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1);
4411 #endif
4413 /* Let machine desc say which reg (if any) the parm arrives in.
4414 0 means it arrives on the stack. */
4415 #ifdef FUNCTION_INCOMING_ARG
4416 entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
4417 passed_type, named_arg);
4418 #else
4419 entry_parm = FUNCTION_ARG (args_so_far, promoted_mode,
4420 passed_type, named_arg);
4421 #endif
4423 if (entry_parm == 0)
4424 promoted_mode = passed_mode;
4426 #ifdef SETUP_INCOMING_VARARGS
4427 /* If this is the last named parameter, do any required setup for
4428 varargs or stdargs. We need to know about the case of this being an
4429 addressable type, in which case we skip the registers it
4430 would have arrived in.
4432 For stdargs, LAST_NAMED will be set for two parameters, the one that
4433 is actually the last named, and the dummy parameter. We only
4434 want to do this action once.
4436 Also, indicate when RTL generation is to be suppressed. */
4437 if (last_named && !varargs_setup)
4439 SETUP_INCOMING_VARARGS (args_so_far, promoted_mode, passed_type,
4440 current_function_pretend_args_size, 0);
4441 varargs_setup = 1;
4443 #endif
4445 /* Determine parm's home in the stack,
4446 in case it arrives in the stack or we should pretend it did.
4448 Compute the stack position and rtx where the argument arrives
4449 and its size.
4451 There is one complexity here: If this was a parameter that would
4452 have been passed in registers, but wasn't only because it is
4453 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
4454 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
4455 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
4456 0 as it was the previous time. */
4458 pretend_named = named_arg || PRETEND_OUTGOING_VARARGS_NAMED;
4459 locate_and_pad_parm (promoted_mode, passed_type,
4460 #ifdef STACK_PARMS_IN_REG_PARM_AREA
4462 #else
4463 #ifdef FUNCTION_INCOMING_ARG
4464 FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
4465 passed_type,
4466 pretend_named) != 0,
4467 #else
4468 FUNCTION_ARG (args_so_far, promoted_mode,
4469 passed_type,
4470 pretend_named) != 0,
4471 #endif
4472 #endif
4473 fndecl, &stack_args_size, &stack_offset, &arg_size,
4474 &alignment_pad);
4477 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
4479 if (offset_rtx == const0_rtx)
4480 stack_parm = gen_rtx_MEM (promoted_mode, internal_arg_pointer);
4481 else
4482 stack_parm = gen_rtx_MEM (promoted_mode,
4483 gen_rtx_PLUS (Pmode,
4484 internal_arg_pointer,
4485 offset_rtx));
4487 set_mem_attributes (stack_parm, parm, 1);
4490 /* If this parameter was passed both in registers and in the stack,
4491 use the copy on the stack. */
4492 if (MUST_PASS_IN_STACK (promoted_mode, passed_type))
4493 entry_parm = 0;
4495 #ifdef FUNCTION_ARG_PARTIAL_NREGS
4496 /* If this parm was passed part in regs and part in memory,
4497 pretend it arrived entirely in memory
4498 by pushing the register-part onto the stack.
4500 In the special case of a DImode or DFmode that is split,
4501 we could put it together in a pseudoreg directly,
4502 but for now that's not worth bothering with. */
4504 if (entry_parm)
4506 int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, promoted_mode,
4507 passed_type, named_arg);
4509 if (nregs > 0)
4511 current_function_pretend_args_size
4512 = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
4513 / (PARM_BOUNDARY / BITS_PER_UNIT)
4514 * (PARM_BOUNDARY / BITS_PER_UNIT));
4516 /* Handle calls that pass values in multiple non-contiguous
4517 locations. The Irix 6 ABI has examples of this. */
4518 if (GET_CODE (entry_parm) == PARALLEL)
4519 emit_group_store (validize_mem (stack_parm), entry_parm,
4520 int_size_in_bytes (TREE_TYPE (parm)),
4521 TYPE_ALIGN (TREE_TYPE (parm)));
4523 else
4524 move_block_from_reg (REGNO (entry_parm),
4525 validize_mem (stack_parm), nregs,
4526 int_size_in_bytes (TREE_TYPE (parm)));
4528 entry_parm = stack_parm;
4531 #endif
4533 /* If we didn't decide this parm came in a register,
4534 by default it came on the stack. */
4535 if (entry_parm == 0)
4536 entry_parm = stack_parm;
4538 /* Record permanently how this parm was passed. */
4539 DECL_INCOMING_RTL (parm) = entry_parm;
4541 /* If there is actually space on the stack for this parm,
4542 count it in stack_args_size; otherwise set stack_parm to 0
4543 to indicate there is no preallocated stack slot for the parm. */
4545 if (entry_parm == stack_parm
4546 || (GET_CODE (entry_parm) == PARALLEL
4547 && XEXP (XVECEXP (entry_parm, 0, 0), 0) == NULL_RTX)
4548 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
4549 /* On some machines, even if a parm value arrives in a register
4550 there is still an (uninitialized) stack slot allocated for it.
4552 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
4553 whether this parameter already has a stack slot allocated,
4554 because an arg block exists only if current_function_args_size
4555 is larger than some threshold, and we haven't calculated that
4556 yet. So, for now, we just assume that stack slots never exist
4557 in this case. */
4558 || REG_PARM_STACK_SPACE (fndecl) > 0
4559 #endif
4562 stack_args_size.constant += arg_size.constant;
4563 if (arg_size.var)
4564 ADD_PARM_SIZE (stack_args_size, arg_size.var);
4566 else
4567 /* No stack slot was pushed for this parm. */
4568 stack_parm = 0;
4570 /* Update info on where next arg arrives in registers. */
4572 FUNCTION_ARG_ADVANCE (args_so_far, promoted_mode,
4573 passed_type, named_arg);
4575 /* If we can't trust the parm stack slot to be aligned enough
4576 for its ultimate type, don't use that slot after entry.
4577 We'll make another stack slot, if we need one. */
4579 unsigned int thisparm_boundary
4580 = FUNCTION_ARG_BOUNDARY (promoted_mode, passed_type);
4582 if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary)
4583 stack_parm = 0;
4586 /* If parm was passed in memory, and we need to convert it on entry,
4587 don't store it back in that same slot. */
4588 if (entry_parm != 0
4589 && nominal_mode != BLKmode && nominal_mode != passed_mode)
4590 stack_parm = 0;
4592 /* When an argument is passed in multiple locations, we can't
4593 make use of this information, but we can save some copying if
4594 the whole argument is passed in a single register. */
4595 if (GET_CODE (entry_parm) == PARALLEL
4596 && nominal_mode != BLKmode && passed_mode != BLKmode)
4598 int i, len = XVECLEN (entry_parm, 0);
4600 for (i = 0; i < len; i++)
4601 if (XEXP (XVECEXP (entry_parm, 0, i), 0) != NULL_RTX
4602 && GET_CODE (XEXP (XVECEXP (entry_parm, 0, i), 0)) == REG
4603 && (GET_MODE (XEXP (XVECEXP (entry_parm, 0, i), 0))
4604 == passed_mode)
4605 && INTVAL (XEXP (XVECEXP (entry_parm, 0, i), 1)) == 0)
4607 entry_parm = XEXP (XVECEXP (entry_parm, 0, i), 0);
4608 DECL_INCOMING_RTL (parm) = entry_parm;
4609 break;
4613 /* ENTRY_PARM is an RTX for the parameter as it arrives,
4614 in the mode in which it arrives.
4615 STACK_PARM is an RTX for a stack slot where the parameter can live
4616 during the function (in case we want to put it there).
4617 STACK_PARM is 0 if no stack slot was pushed for it.
4619 Now output code if necessary to convert ENTRY_PARM to
4620 the type in which this function declares it,
4621 and store that result in an appropriate place,
4622 which may be a pseudo reg, may be STACK_PARM,
4623 or may be a local stack slot if STACK_PARM is 0.
4625 Set DECL_RTL to that place. */
4627 if (nominal_mode == BLKmode || GET_CODE (entry_parm) == PARALLEL)
4629 /* If a BLKmode arrives in registers, copy it to a stack slot.
4630 Handle calls that pass values in multiple non-contiguous
4631 locations. The Irix 6 ABI has examples of this. */
4632 if (GET_CODE (entry_parm) == REG
4633 || GET_CODE (entry_parm) == PARALLEL)
4635 int size_stored
4636 = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)),
4637 UNITS_PER_WORD);
4639 /* Note that we will be storing an integral number of words.
4640 So we have to be careful to ensure that we allocate an
4641 integral number of words. We do this below in the
4642 assign_stack_local if space was not allocated in the argument
4643 list. If it was, this will not work if PARM_BOUNDARY is not
4644 a multiple of BITS_PER_WORD. It isn't clear how to fix this
4645 if it becomes a problem. */
4647 if (stack_parm == 0)
4649 stack_parm
4650 = assign_stack_local (GET_MODE (entry_parm),
4651 size_stored, 0);
4652 set_mem_attributes (stack_parm, parm, 1);
4655 else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
4656 abort ();
4658 /* Handle calls that pass values in multiple non-contiguous
4659 locations. The Irix 6 ABI has examples of this. */
4660 if (GET_CODE (entry_parm) == PARALLEL)
4661 emit_group_store (validize_mem (stack_parm), entry_parm,
4662 int_size_in_bytes (TREE_TYPE (parm)),
4663 TYPE_ALIGN (TREE_TYPE (parm)));
4664 else
4665 move_block_from_reg (REGNO (entry_parm),
4666 validize_mem (stack_parm),
4667 size_stored / UNITS_PER_WORD,
4668 int_size_in_bytes (TREE_TYPE (parm)));
4670 SET_DECL_RTL (parm, stack_parm);
4672 else if (! ((! optimize
4673 && ! DECL_REGISTER (parm)
4674 && ! DECL_INLINE (fndecl))
4675 || TREE_SIDE_EFFECTS (parm)
4676 /* If -ffloat-store specified, don't put explicit
4677 float variables into registers. */
4678 || (flag_float_store
4679 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
4680 /* Always assign pseudo to structure return or item passed
4681 by invisible reference. */
4682 || passed_pointer || parm == function_result_decl)
4684 /* Store the parm in a pseudoregister during the function, but we
4685 may need to do it in a wider mode. */
4687 register rtx parmreg;
4688 unsigned int regno, regnoi = 0, regnor = 0;
4690 unsignedp = TREE_UNSIGNED (TREE_TYPE (parm));
4692 promoted_nominal_mode
4693 = promote_mode (TREE_TYPE (parm), nominal_mode, &unsignedp, 0);
4695 parmreg = gen_reg_rtx (promoted_nominal_mode);
4696 mark_user_reg (parmreg);
4698 /* If this was an item that we received a pointer to, set DECL_RTL
4699 appropriately. */
4700 if (passed_pointer)
4702 SET_DECL_RTL (parm,
4703 gen_rtx_MEM (TYPE_MODE (TREE_TYPE (passed_type)),
4704 parmreg));
4705 set_mem_attributes (DECL_RTL (parm), parm, 1);
4707 else
4709 SET_DECL_RTL (parm, parmreg);
4710 maybe_set_unchanging (DECL_RTL (parm), parm);
4713 /* Copy the value into the register. */
4714 if (nominal_mode != passed_mode
4715 || promoted_nominal_mode != promoted_mode)
4717 int save_tree_used;
4718 /* ENTRY_PARM has been converted to PROMOTED_MODE, its
4719 mode, by the caller. We now have to convert it to
4720 NOMINAL_MODE, if different. However, PARMREG may be in
4721 a different mode than NOMINAL_MODE if it is being stored
4722 promoted.
4724 If ENTRY_PARM is a hard register, it might be in a register
4725 not valid for operating in its mode (e.g., an odd-numbered
4726 register for a DFmode). In that case, moves are the only
4727 thing valid, so we can't do a convert from there. This
4728 occurs when the calling sequence allow such misaligned
4729 usages.
4731 In addition, the conversion may involve a call, which could
4732 clobber parameters which haven't been copied to pseudo
4733 registers yet. Therefore, we must first copy the parm to
4734 a pseudo reg here, and save the conversion until after all
4735 parameters have been moved. */
4737 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
4739 emit_move_insn (tempreg, validize_mem (entry_parm));
4741 push_to_sequence (conversion_insns);
4742 tempreg = convert_to_mode (nominal_mode, tempreg, unsignedp);
4744 /* TREE_USED gets set erroneously during expand_assignment. */
4745 save_tree_used = TREE_USED (parm);
4746 expand_assignment (parm,
4747 make_tree (nominal_type, tempreg), 0, 0);
4748 TREE_USED (parm) = save_tree_used;
4749 conversion_insns = get_insns ();
4750 did_conversion = 1;
4751 end_sequence ();
4753 else
4754 emit_move_insn (parmreg, validize_mem (entry_parm));
4756 /* If we were passed a pointer but the actual value
4757 can safely live in a register, put it in one. */
4758 if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
4759 && ! ((! optimize
4760 && ! DECL_REGISTER (parm)
4761 && ! DECL_INLINE (fndecl))
4762 || TREE_SIDE_EFFECTS (parm)
4763 /* If -ffloat-store specified, don't put explicit
4764 float variables into registers. */
4765 || (flag_float_store
4766 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))
4768 /* We can't use nominal_mode, because it will have been set to
4769 Pmode above. We must use the actual mode of the parm. */
4770 parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
4771 mark_user_reg (parmreg);
4772 if (GET_MODE (parmreg) != GET_MODE (DECL_RTL (parm)))
4774 rtx tempreg = gen_reg_rtx (GET_MODE (DECL_RTL (parm)));
4775 int unsigned_p = TREE_UNSIGNED (TREE_TYPE (parm));
4776 push_to_sequence (conversion_insns);
4777 emit_move_insn (tempreg, DECL_RTL (parm));
4778 SET_DECL_RTL (parm,
4779 convert_to_mode (GET_MODE (parmreg),
4780 tempreg,
4781 unsigned_p));
4782 emit_move_insn (parmreg, DECL_RTL (parm));
4783 conversion_insns = get_insns();
4784 did_conversion = 1;
4785 end_sequence ();
4787 else
4788 emit_move_insn (parmreg, DECL_RTL (parm));
4789 SET_DECL_RTL (parm, parmreg);
4790 /* STACK_PARM is the pointer, not the parm, and PARMREG is
4791 now the parm. */
4792 stack_parm = 0;
4794 #ifdef FUNCTION_ARG_CALLEE_COPIES
4795 /* If we are passed an arg by reference and it is our responsibility
4796 to make a copy, do it now.
4797 PASSED_TYPE and PASSED mode now refer to the pointer, not the
4798 original argument, so we must recreate them in the call to
4799 FUNCTION_ARG_CALLEE_COPIES. */
4800 /* ??? Later add code to handle the case that if the argument isn't
4801 modified, don't do the copy. */
4803 else if (passed_pointer
4804 && FUNCTION_ARG_CALLEE_COPIES (args_so_far,
4805 TYPE_MODE (DECL_ARG_TYPE (parm)),
4806 DECL_ARG_TYPE (parm),
4807 named_arg)
4808 && ! TREE_ADDRESSABLE (DECL_ARG_TYPE (parm)))
4810 rtx copy;
4811 tree type = DECL_ARG_TYPE (parm);
4813 /* This sequence may involve a library call perhaps clobbering
4814 registers that haven't been copied to pseudos yet. */
4816 push_to_sequence (conversion_insns);
4818 if (!COMPLETE_TYPE_P (type)
4819 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4820 /* This is a variable sized object. */
4821 copy = gen_rtx_MEM (BLKmode,
4822 allocate_dynamic_stack_space
4823 (expr_size (parm), NULL_RTX,
4824 TYPE_ALIGN (type)));
4825 else
4826 copy = assign_stack_temp (TYPE_MODE (type),
4827 int_size_in_bytes (type), 1);
4828 set_mem_attributes (copy, parm, 1);
4830 store_expr (parm, copy, 0);
4831 emit_move_insn (parmreg, XEXP (copy, 0));
4832 if (current_function_check_memory_usage)
4833 emit_library_call (chkr_set_right_libfunc,
4834 LCT_CONST_MAKE_BLOCK, VOIDmode, 3,
4835 XEXP (copy, 0), Pmode,
4836 GEN_INT (int_size_in_bytes (type)),
4837 TYPE_MODE (sizetype),
4838 GEN_INT (MEMORY_USE_RW),
4839 TYPE_MODE (integer_type_node));
4840 conversion_insns = get_insns ();
4841 did_conversion = 1;
4842 end_sequence ();
4844 #endif /* FUNCTION_ARG_CALLEE_COPIES */
4846 /* In any case, record the parm's desired stack location
4847 in case we later discover it must live in the stack.
4849 If it is a COMPLEX value, store the stack location for both
4850 halves. */
4852 if (GET_CODE (parmreg) == CONCAT)
4853 regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1)));
4854 else
4855 regno = REGNO (parmreg);
4857 if (regno >= max_parm_reg)
4859 rtx *new;
4860 int old_max_parm_reg = max_parm_reg;
4862 /* It's slow to expand this one register at a time,
4863 but it's also rare and we need max_parm_reg to be
4864 precisely correct. */
4865 max_parm_reg = regno + 1;
4866 new = (rtx *) xrealloc (parm_reg_stack_loc,
4867 max_parm_reg * sizeof (rtx));
4868 memset ((char *) (new + old_max_parm_reg), 0,
4869 (max_parm_reg - old_max_parm_reg) * sizeof (rtx));
4870 parm_reg_stack_loc = new;
4873 if (GET_CODE (parmreg) == CONCAT)
4875 enum machine_mode submode = GET_MODE (XEXP (parmreg, 0));
4877 regnor = REGNO (gen_realpart (submode, parmreg));
4878 regnoi = REGNO (gen_imagpart (submode, parmreg));
4880 if (stack_parm != 0)
4882 parm_reg_stack_loc[regnor]
4883 = gen_realpart (submode, stack_parm);
4884 parm_reg_stack_loc[regnoi]
4885 = gen_imagpart (submode, stack_parm);
4887 else
4889 parm_reg_stack_loc[regnor] = 0;
4890 parm_reg_stack_loc[regnoi] = 0;
4893 else
4894 parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
4896 /* Mark the register as eliminable if we did no conversion
4897 and it was copied from memory at a fixed offset,
4898 and the arg pointer was not copied to a pseudo-reg.
4899 If the arg pointer is a pseudo reg or the offset formed
4900 an invalid address, such memory-equivalences
4901 as we make here would screw up life analysis for it. */
4902 if (nominal_mode == passed_mode
4903 && ! did_conversion
4904 && stack_parm != 0
4905 && GET_CODE (stack_parm) == MEM
4906 && stack_offset.var == 0
4907 && reg_mentioned_p (virtual_incoming_args_rtx,
4908 XEXP (stack_parm, 0)))
4910 rtx linsn = get_last_insn ();
4911 rtx sinsn, set;
4913 /* Mark complex types separately. */
4914 if (GET_CODE (parmreg) == CONCAT)
4915 /* Scan backwards for the set of the real and
4916 imaginary parts. */
4917 for (sinsn = linsn; sinsn != 0;
4918 sinsn = prev_nonnote_insn (sinsn))
4920 set = single_set (sinsn);
4921 if (set != 0
4922 && SET_DEST (set) == regno_reg_rtx [regnoi])
4923 REG_NOTES (sinsn)
4924 = gen_rtx_EXPR_LIST (REG_EQUIV,
4925 parm_reg_stack_loc[regnoi],
4926 REG_NOTES (sinsn));
4927 else if (set != 0
4928 && SET_DEST (set) == regno_reg_rtx [regnor])
4929 REG_NOTES (sinsn)
4930 = gen_rtx_EXPR_LIST (REG_EQUIV,
4931 parm_reg_stack_loc[regnor],
4932 REG_NOTES (sinsn));
4934 else if ((set = single_set (linsn)) != 0
4935 && SET_DEST (set) == parmreg)
4936 REG_NOTES (linsn)
4937 = gen_rtx_EXPR_LIST (REG_EQUIV,
4938 stack_parm, REG_NOTES (linsn));
4941 /* For pointer data type, suggest pointer register. */
4942 if (POINTER_TYPE_P (TREE_TYPE (parm)))
4943 mark_reg_pointer (parmreg,
4944 TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm))));
4946 /* If something wants our address, try to use ADDRESSOF. */
4947 if (TREE_ADDRESSABLE (parm))
4949 /* If we end up putting something into the stack,
4950 fixup_var_refs_insns will need to make a pass over
4951 all the instructions. It looks throughs the pending
4952 sequences -- but it can't see the ones in the
4953 CONVERSION_INSNS, if they're not on the sequence
4954 stack. So, we go back to that sequence, just so that
4955 the fixups will happen. */
4956 push_to_sequence (conversion_insns);
4957 put_var_into_stack (parm);
4958 conversion_insns = get_insns ();
4959 end_sequence ();
4962 else
4964 /* Value must be stored in the stack slot STACK_PARM
4965 during function execution. */
4967 if (promoted_mode != nominal_mode)
4969 /* Conversion is required. */
4970 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
4972 emit_move_insn (tempreg, validize_mem (entry_parm));
4974 push_to_sequence (conversion_insns);
4975 entry_parm = convert_to_mode (nominal_mode, tempreg,
4976 TREE_UNSIGNED (TREE_TYPE (parm)));
4977 if (stack_parm)
4979 /* ??? This may need a big-endian conversion on sparc64. */
4980 stack_parm = change_address (stack_parm, nominal_mode,
4981 NULL_RTX);
4983 conversion_insns = get_insns ();
4984 did_conversion = 1;
4985 end_sequence ();
4988 if (entry_parm != stack_parm)
4990 if (stack_parm == 0)
4992 stack_parm
4993 = assign_stack_local (GET_MODE (entry_parm),
4994 GET_MODE_SIZE (GET_MODE (entry_parm)), 0);
4995 set_mem_attributes (stack_parm, parm, 1);
4998 if (promoted_mode != nominal_mode)
5000 push_to_sequence (conversion_insns);
5001 emit_move_insn (validize_mem (stack_parm),
5002 validize_mem (entry_parm));
5003 conversion_insns = get_insns ();
5004 end_sequence ();
5006 else
5007 emit_move_insn (validize_mem (stack_parm),
5008 validize_mem (entry_parm));
5010 if (current_function_check_memory_usage)
5012 push_to_sequence (conversion_insns);
5013 emit_library_call (chkr_set_right_libfunc, LCT_CONST_MAKE_BLOCK,
5014 VOIDmode, 3, XEXP (stack_parm, 0), Pmode,
5015 GEN_INT (GET_MODE_SIZE (GET_MODE
5016 (entry_parm))),
5017 TYPE_MODE (sizetype),
5018 GEN_INT (MEMORY_USE_RW),
5019 TYPE_MODE (integer_type_node));
5021 conversion_insns = get_insns ();
5022 end_sequence ();
5024 SET_DECL_RTL (parm, stack_parm);
5027 /* If this "parameter" was the place where we are receiving the
5028 function's incoming structure pointer, set up the result. */
5029 if (parm == function_result_decl)
5031 tree result = DECL_RESULT (fndecl);
5033 SET_DECL_RTL (result,
5034 gen_rtx_MEM (DECL_MODE (result), DECL_RTL (parm)));
5036 set_mem_attributes (DECL_RTL (result), result, 1);
5040 /* Output all parameter conversion instructions (possibly including calls)
5041 now that all parameters have been copied out of hard registers. */
5042 emit_insns (conversion_insns);
5044 last_parm_insn = get_last_insn ();
5046 current_function_args_size = stack_args_size.constant;
5048 /* Adjust function incoming argument size for alignment and
5049 minimum length. */
5051 #ifdef REG_PARM_STACK_SPACE
5052 #ifndef MAYBE_REG_PARM_STACK_SPACE
5053 current_function_args_size = MAX (current_function_args_size,
5054 REG_PARM_STACK_SPACE (fndecl));
5055 #endif
5056 #endif
5058 #ifdef STACK_BOUNDARY
5059 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
5061 current_function_args_size
5062 = ((current_function_args_size + STACK_BYTES - 1)
5063 / STACK_BYTES) * STACK_BYTES;
5064 #endif
5066 #ifdef ARGS_GROW_DOWNWARD
5067 current_function_arg_offset_rtx
5068 = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant)
5069 : expand_expr (size_diffop (stack_args_size.var,
5070 size_int (-stack_args_size.constant)),
5071 NULL_RTX, VOIDmode, EXPAND_MEMORY_USE_BAD));
5072 #else
5073 current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
5074 #endif
5076 /* See how many bytes, if any, of its args a function should try to pop
5077 on return. */
5079 current_function_pops_args = RETURN_POPS_ARGS (fndecl, TREE_TYPE (fndecl),
5080 current_function_args_size);
5082 /* For stdarg.h function, save info about
5083 regs and stack space used by the named args. */
5085 if (!hide_last_arg)
5086 current_function_args_info = args_so_far;
5088 /* Set the rtx used for the function return value. Put this in its
5089 own variable so any optimizers that need this information don't have
5090 to include tree.h. Do this here so it gets done when an inlined
5091 function gets output. */
5093 current_function_return_rtx
5094 = (DECL_RTL_SET_P (DECL_RESULT (fndecl))
5095 ? DECL_RTL (DECL_RESULT (fndecl)) : NULL_RTX);
5098 /* Indicate whether REGNO is an incoming argument to the current function
5099 that was promoted to a wider mode. If so, return the RTX for the
5100 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
5101 that REGNO is promoted from and whether the promotion was signed or
5102 unsigned. */
5104 #ifdef PROMOTE_FUNCTION_ARGS
5107 promoted_input_arg (regno, pmode, punsignedp)
5108 unsigned int regno;
5109 enum machine_mode *pmode;
5110 int *punsignedp;
5112 tree arg;
5114 for (arg = DECL_ARGUMENTS (current_function_decl); arg;
5115 arg = TREE_CHAIN (arg))
5116 if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
5117 && REGNO (DECL_INCOMING_RTL (arg)) == regno
5118 && TYPE_MODE (DECL_ARG_TYPE (arg)) == TYPE_MODE (TREE_TYPE (arg)))
5120 enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
5121 int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
5123 mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1);
5124 if (mode == GET_MODE (DECL_INCOMING_RTL (arg))
5125 && mode != DECL_MODE (arg))
5127 *pmode = DECL_MODE (arg);
5128 *punsignedp = unsignedp;
5129 return DECL_INCOMING_RTL (arg);
5133 return 0;
5136 #endif
5138 /* Compute the size and offset from the start of the stacked arguments for a
5139 parm passed in mode PASSED_MODE and with type TYPE.
5141 INITIAL_OFFSET_PTR points to the current offset into the stacked
5142 arguments.
5144 The starting offset and size for this parm are returned in *OFFSET_PTR
5145 and *ARG_SIZE_PTR, respectively.
5147 IN_REGS is non-zero if the argument will be passed in registers. It will
5148 never be set if REG_PARM_STACK_SPACE is not defined.
5150 FNDECL is the function in which the argument was defined.
5152 There are two types of rounding that are done. The first, controlled by
5153 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
5154 list to be aligned to the specific boundary (in bits). This rounding
5155 affects the initial and starting offsets, but not the argument size.
5157 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
5158 optionally rounds the size of the parm to PARM_BOUNDARY. The
5159 initial offset is not affected by this rounding, while the size always
5160 is and the starting offset may be. */
5162 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
5163 initial_offset_ptr is positive because locate_and_pad_parm's
5164 callers pass in the total size of args so far as
5165 initial_offset_ptr. arg_size_ptr is always positive.*/
5167 void
5168 locate_and_pad_parm (passed_mode, type, in_regs, fndecl,
5169 initial_offset_ptr, offset_ptr, arg_size_ptr,
5170 alignment_pad)
5171 enum machine_mode passed_mode;
5172 tree type;
5173 int in_regs ATTRIBUTE_UNUSED;
5174 tree fndecl ATTRIBUTE_UNUSED;
5175 struct args_size *initial_offset_ptr;
5176 struct args_size *offset_ptr;
5177 struct args_size *arg_size_ptr;
5178 struct args_size *alignment_pad;
5181 tree sizetree
5182 = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
5183 enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
5184 int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
5186 #ifdef REG_PARM_STACK_SPACE
5187 /* If we have found a stack parm before we reach the end of the
5188 area reserved for registers, skip that area. */
5189 if (! in_regs)
5191 int reg_parm_stack_space = 0;
5193 #ifdef MAYBE_REG_PARM_STACK_SPACE
5194 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
5195 #else
5196 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
5197 #endif
5198 if (reg_parm_stack_space > 0)
5200 if (initial_offset_ptr->var)
5202 initial_offset_ptr->var
5203 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
5204 ssize_int (reg_parm_stack_space));
5205 initial_offset_ptr->constant = 0;
5207 else if (initial_offset_ptr->constant < reg_parm_stack_space)
5208 initial_offset_ptr->constant = reg_parm_stack_space;
5211 #endif /* REG_PARM_STACK_SPACE */
5213 arg_size_ptr->var = 0;
5214 arg_size_ptr->constant = 0;
5215 alignment_pad->var = 0;
5216 alignment_pad->constant = 0;
5218 #ifdef ARGS_GROW_DOWNWARD
5219 if (initial_offset_ptr->var)
5221 offset_ptr->constant = 0;
5222 offset_ptr->var = size_binop (MINUS_EXPR, ssize_int (0),
5223 initial_offset_ptr->var);
5225 else
5227 offset_ptr->constant = -initial_offset_ptr->constant;
5228 offset_ptr->var = 0;
5230 if (where_pad != none
5231 && (!host_integerp (sizetree, 1)
5232 || (tree_low_cst (sizetree, 1) * BITS_PER_UNIT) % PARM_BOUNDARY))
5233 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
5234 SUB_PARM_SIZE (*offset_ptr, sizetree);
5235 if (where_pad != downward)
5236 pad_to_arg_alignment (offset_ptr, boundary, alignment_pad);
5237 if (initial_offset_ptr->var)
5238 arg_size_ptr->var = size_binop (MINUS_EXPR,
5239 size_binop (MINUS_EXPR,
5240 ssize_int (0),
5241 initial_offset_ptr->var),
5242 offset_ptr->var);
5244 else
5245 arg_size_ptr->constant = (-initial_offset_ptr->constant
5246 - offset_ptr->constant);
5248 #else /* !ARGS_GROW_DOWNWARD */
5249 if (!in_regs
5250 #ifdef REG_PARM_STACK_SPACE
5251 || REG_PARM_STACK_SPACE (fndecl) > 0
5252 #endif
5254 pad_to_arg_alignment (initial_offset_ptr, boundary, alignment_pad);
5255 *offset_ptr = *initial_offset_ptr;
5257 #ifdef PUSH_ROUNDING
5258 if (passed_mode != BLKmode)
5259 sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
5260 #endif
5262 /* Pad_below needs the pre-rounded size to know how much to pad below
5263 so this must be done before rounding up. */
5264 if (where_pad == downward
5265 /* However, BLKmode args passed in regs have their padding done elsewhere.
5266 The stack slot must be able to hold the entire register. */
5267 && !(in_regs && passed_mode == BLKmode))
5268 pad_below (offset_ptr, passed_mode, sizetree);
5270 if (where_pad != none
5271 && (!host_integerp (sizetree, 1)
5272 || (tree_low_cst (sizetree, 1) * BITS_PER_UNIT) % PARM_BOUNDARY))
5273 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
5275 ADD_PARM_SIZE (*arg_size_ptr, sizetree);
5276 #endif /* ARGS_GROW_DOWNWARD */
5279 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
5280 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
5282 static void
5283 pad_to_arg_alignment (offset_ptr, boundary, alignment_pad)
5284 struct args_size *offset_ptr;
5285 int boundary;
5286 struct args_size *alignment_pad;
5288 tree save_var = NULL_TREE;
5289 HOST_WIDE_INT save_constant = 0;
5291 int boundary_in_bytes = boundary / BITS_PER_UNIT;
5293 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY)
5295 save_var = offset_ptr->var;
5296 save_constant = offset_ptr->constant;
5299 alignment_pad->var = NULL_TREE;
5300 alignment_pad->constant = 0;
5302 if (boundary > BITS_PER_UNIT)
5304 if (offset_ptr->var)
5306 offset_ptr->var =
5307 #ifdef ARGS_GROW_DOWNWARD
5308 round_down
5309 #else
5310 round_up
5311 #endif
5312 (ARGS_SIZE_TREE (*offset_ptr),
5313 boundary / BITS_PER_UNIT);
5314 offset_ptr->constant = 0; /*?*/
5315 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY)
5316 alignment_pad->var = size_binop (MINUS_EXPR, offset_ptr->var,
5317 save_var);
5319 else
5321 offset_ptr->constant =
5322 #ifdef ARGS_GROW_DOWNWARD
5323 FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes);
5324 #else
5325 CEIL_ROUND (offset_ptr->constant, boundary_in_bytes);
5326 #endif
5327 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY)
5328 alignment_pad->constant = offset_ptr->constant - save_constant;
5333 #ifndef ARGS_GROW_DOWNWARD
5334 static void
5335 pad_below (offset_ptr, passed_mode, sizetree)
5336 struct args_size *offset_ptr;
5337 enum machine_mode passed_mode;
5338 tree sizetree;
5340 if (passed_mode != BLKmode)
5342 if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
5343 offset_ptr->constant
5344 += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
5345 / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
5346 - GET_MODE_SIZE (passed_mode));
5348 else
5350 if (TREE_CODE (sizetree) != INTEGER_CST
5351 || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
5353 /* Round the size up to multiple of PARM_BOUNDARY bits. */
5354 tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
5355 /* Add it in. */
5356 ADD_PARM_SIZE (*offset_ptr, s2);
5357 SUB_PARM_SIZE (*offset_ptr, sizetree);
5361 #endif
5363 /* Walk the tree of blocks describing the binding levels within a function
5364 and warn about uninitialized variables.
5365 This is done after calling flow_analysis and before global_alloc
5366 clobbers the pseudo-regs to hard regs. */
5368 void
5369 uninitialized_vars_warning (block)
5370 tree block;
5372 register tree decl, sub;
5373 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
5375 if (warn_uninitialized
5376 && TREE_CODE (decl) == VAR_DECL
5377 /* These warnings are unreliable for and aggregates
5378 because assigning the fields one by one can fail to convince
5379 flow.c that the entire aggregate was initialized.
5380 Unions are troublesome because members may be shorter. */
5381 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl))
5382 && DECL_RTL (decl) != 0
5383 && GET_CODE (DECL_RTL (decl)) == REG
5384 /* Global optimizations can make it difficult to determine if a
5385 particular variable has been initialized. However, a VAR_DECL
5386 with a nonzero DECL_INITIAL had an initializer, so do not
5387 claim it is potentially uninitialized.
5389 We do not care about the actual value in DECL_INITIAL, so we do
5390 not worry that it may be a dangling pointer. */
5391 && DECL_INITIAL (decl) == NULL_TREE
5392 && regno_uninitialized (REGNO (DECL_RTL (decl))))
5393 warning_with_decl (decl,
5394 "`%s' might be used uninitialized in this function");
5395 if (extra_warnings
5396 && TREE_CODE (decl) == VAR_DECL
5397 && DECL_RTL (decl) != 0
5398 && GET_CODE (DECL_RTL (decl)) == REG
5399 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
5400 warning_with_decl (decl,
5401 "variable `%s' might be clobbered by `longjmp' or `vfork'");
5403 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
5404 uninitialized_vars_warning (sub);
5407 /* Do the appropriate part of uninitialized_vars_warning
5408 but for arguments instead of local variables. */
5410 void
5411 setjmp_args_warning ()
5413 register tree decl;
5414 for (decl = DECL_ARGUMENTS (current_function_decl);
5415 decl; decl = TREE_CHAIN (decl))
5416 if (DECL_RTL (decl) != 0
5417 && GET_CODE (DECL_RTL (decl)) == REG
5418 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
5419 warning_with_decl (decl,
5420 "argument `%s' might be clobbered by `longjmp' or `vfork'");
5423 /* If this function call setjmp, put all vars into the stack
5424 unless they were declared `register'. */
5426 void
5427 setjmp_protect (block)
5428 tree block;
5430 register tree decl, sub;
5431 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
5432 if ((TREE_CODE (decl) == VAR_DECL
5433 || TREE_CODE (decl) == PARM_DECL)
5434 && DECL_RTL (decl) != 0
5435 && (GET_CODE (DECL_RTL (decl)) == REG
5436 || (GET_CODE (DECL_RTL (decl)) == MEM
5437 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF))
5438 /* If this variable came from an inline function, it must be
5439 that its life doesn't overlap the setjmp. If there was a
5440 setjmp in the function, it would already be in memory. We
5441 must exclude such variable because their DECL_RTL might be
5442 set to strange things such as virtual_stack_vars_rtx. */
5443 && ! DECL_FROM_INLINE (decl)
5444 && (
5445 #ifdef NON_SAVING_SETJMP
5446 /* If longjmp doesn't restore the registers,
5447 don't put anything in them. */
5448 NON_SAVING_SETJMP
5450 #endif
5451 ! DECL_REGISTER (decl)))
5452 put_var_into_stack (decl);
5453 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
5454 setjmp_protect (sub);
5457 /* Like the previous function, but for args instead of local variables. */
5459 void
5460 setjmp_protect_args ()
5462 register tree decl;
5463 for (decl = DECL_ARGUMENTS (current_function_decl);
5464 decl; decl = TREE_CHAIN (decl))
5465 if ((TREE_CODE (decl) == VAR_DECL
5466 || TREE_CODE (decl) == PARM_DECL)
5467 && DECL_RTL (decl) != 0
5468 && (GET_CODE (DECL_RTL (decl)) == REG
5469 || (GET_CODE (DECL_RTL (decl)) == MEM
5470 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF))
5471 && (
5472 /* If longjmp doesn't restore the registers,
5473 don't put anything in them. */
5474 #ifdef NON_SAVING_SETJMP
5475 NON_SAVING_SETJMP
5477 #endif
5478 ! DECL_REGISTER (decl)))
5479 put_var_into_stack (decl);
5482 /* Return the context-pointer register corresponding to DECL,
5483 or 0 if it does not need one. */
5486 lookup_static_chain (decl)
5487 tree decl;
5489 tree context = decl_function_context (decl);
5490 tree link;
5492 if (context == 0
5493 || (TREE_CODE (decl) == FUNCTION_DECL && DECL_NO_STATIC_CHAIN (decl)))
5494 return 0;
5496 /* We treat inline_function_decl as an alias for the current function
5497 because that is the inline function whose vars, types, etc.
5498 are being merged into the current function.
5499 See expand_inline_function. */
5500 if (context == current_function_decl || context == inline_function_decl)
5501 return virtual_stack_vars_rtx;
5503 for (link = context_display; link; link = TREE_CHAIN (link))
5504 if (TREE_PURPOSE (link) == context)
5505 return RTL_EXPR_RTL (TREE_VALUE (link));
5507 abort ();
5510 /* Convert a stack slot address ADDR for variable VAR
5511 (from a containing function)
5512 into an address valid in this function (using a static chain). */
5515 fix_lexical_addr (addr, var)
5516 rtx addr;
5517 tree var;
5519 rtx basereg;
5520 HOST_WIDE_INT displacement;
5521 tree context = decl_function_context (var);
5522 struct function *fp;
5523 rtx base = 0;
5525 /* If this is the present function, we need not do anything. */
5526 if (context == current_function_decl || context == inline_function_decl)
5527 return addr;
5529 for (fp = outer_function_chain; fp; fp = fp->next)
5530 if (fp->decl == context)
5531 break;
5533 if (fp == 0)
5534 abort ();
5536 if (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == MEM)
5537 addr = XEXP (XEXP (addr, 0), 0);
5539 /* Decode given address as base reg plus displacement. */
5540 if (GET_CODE (addr) == REG)
5541 basereg = addr, displacement = 0;
5542 else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
5543 basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
5544 else
5545 abort ();
5547 /* We accept vars reached via the containing function's
5548 incoming arg pointer and via its stack variables pointer. */
5549 if (basereg == fp->internal_arg_pointer)
5551 /* If reached via arg pointer, get the arg pointer value
5552 out of that function's stack frame.
5554 There are two cases: If a separate ap is needed, allocate a
5555 slot in the outer function for it and dereference it that way.
5556 This is correct even if the real ap is actually a pseudo.
5557 Otherwise, just adjust the offset from the frame pointer to
5558 compensate. */
5560 #ifdef NEED_SEPARATE_AP
5561 rtx addr;
5563 if (fp->x_arg_pointer_save_area == 0)
5564 fp->x_arg_pointer_save_area
5565 = assign_stack_local_1 (Pmode, GET_MODE_SIZE (Pmode), 0, fp);
5567 addr = fix_lexical_addr (XEXP (fp->x_arg_pointer_save_area, 0), var);
5568 addr = memory_address (Pmode, addr);
5570 base = gen_rtx_MEM (Pmode, addr);
5571 MEM_ALIAS_SET (base) = get_frame_alias_set ();
5572 base = copy_to_reg (base);
5573 #else
5574 displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET);
5575 base = lookup_static_chain (var);
5576 #endif
5579 else if (basereg == virtual_stack_vars_rtx)
5581 /* This is the same code as lookup_static_chain, duplicated here to
5582 avoid an extra call to decl_function_context. */
5583 tree link;
5585 for (link = context_display; link; link = TREE_CHAIN (link))
5586 if (TREE_PURPOSE (link) == context)
5588 base = RTL_EXPR_RTL (TREE_VALUE (link));
5589 break;
5593 if (base == 0)
5594 abort ();
5596 /* Use same offset, relative to appropriate static chain or argument
5597 pointer. */
5598 return plus_constant (base, displacement);
5601 /* Return the address of the trampoline for entering nested fn FUNCTION.
5602 If necessary, allocate a trampoline (in the stack frame)
5603 and emit rtl to initialize its contents (at entry to this function). */
5606 trampoline_address (function)
5607 tree function;
5609 tree link;
5610 tree rtlexp;
5611 rtx tramp;
5612 struct function *fp;
5613 tree fn_context;
5615 /* Find an existing trampoline and return it. */
5616 for (link = trampoline_list; link; link = TREE_CHAIN (link))
5617 if (TREE_PURPOSE (link) == function)
5618 return
5619 adjust_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0));
5621 for (fp = outer_function_chain; fp; fp = fp->next)
5622 for (link = fp->x_trampoline_list; link; link = TREE_CHAIN (link))
5623 if (TREE_PURPOSE (link) == function)
5625 tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
5626 function);
5627 return adjust_trampoline_addr (tramp);
5630 /* None exists; we must make one. */
5632 /* Find the `struct function' for the function containing FUNCTION. */
5633 fp = 0;
5634 fn_context = decl_function_context (function);
5635 if (fn_context != current_function_decl
5636 && fn_context != inline_function_decl)
5637 for (fp = outer_function_chain; fp; fp = fp->next)
5638 if (fp->decl == fn_context)
5639 break;
5641 /* Allocate run-time space for this trampoline
5642 (usually in the defining function's stack frame). */
5643 #ifdef ALLOCATE_TRAMPOLINE
5644 tramp = ALLOCATE_TRAMPOLINE (fp);
5645 #else
5646 /* If rounding needed, allocate extra space
5647 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
5648 #ifdef TRAMPOLINE_ALIGNMENT
5649 #define TRAMPOLINE_REAL_SIZE \
5650 (TRAMPOLINE_SIZE + (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT) - 1)
5651 #else
5652 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
5653 #endif
5654 tramp = assign_stack_local_1 (BLKmode, TRAMPOLINE_REAL_SIZE, 0,
5655 fp ? fp : cfun);
5656 #endif
5658 /* Record the trampoline for reuse and note it for later initialization
5659 by expand_function_end. */
5660 if (fp != 0)
5662 rtlexp = make_node (RTL_EXPR);
5663 RTL_EXPR_RTL (rtlexp) = tramp;
5664 fp->x_trampoline_list = tree_cons (function, rtlexp,
5665 fp->x_trampoline_list);
5667 else
5669 /* Make the RTL_EXPR node temporary, not momentary, so that the
5670 trampoline_list doesn't become garbage. */
5671 rtlexp = make_node (RTL_EXPR);
5673 RTL_EXPR_RTL (rtlexp) = tramp;
5674 trampoline_list = tree_cons (function, rtlexp, trampoline_list);
5677 tramp = fix_lexical_addr (XEXP (tramp, 0), function);
5678 return adjust_trampoline_addr (tramp);
5681 /* Given a trampoline address,
5682 round it to multiple of TRAMPOLINE_ALIGNMENT. */
5684 static rtx
5685 round_trampoline_addr (tramp)
5686 rtx tramp;
5688 #ifdef TRAMPOLINE_ALIGNMENT
5689 /* Round address up to desired boundary. */
5690 rtx temp = gen_reg_rtx (Pmode);
5691 temp = expand_binop (Pmode, add_optab, tramp,
5692 GEN_INT (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT - 1),
5693 temp, 0, OPTAB_LIB_WIDEN);
5694 tramp = expand_binop (Pmode, and_optab, temp,
5695 GEN_INT (-TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT),
5696 temp, 0, OPTAB_LIB_WIDEN);
5697 #endif
5698 return tramp;
5701 /* Given a trampoline address, round it then apply any
5702 platform-specific adjustments so that the result can be used for a
5703 function call . */
5705 static rtx
5706 adjust_trampoline_addr (tramp)
5707 rtx tramp;
5709 tramp = round_trampoline_addr (tramp);
5710 #ifdef TRAMPOLINE_ADJUST_ADDRESS
5711 TRAMPOLINE_ADJUST_ADDRESS (tramp);
5712 #endif
5713 return tramp;
5716 /* Put all this function's BLOCK nodes including those that are chained
5717 onto the first block into a vector, and return it.
5718 Also store in each NOTE for the beginning or end of a block
5719 the index of that block in the vector.
5720 The arguments are BLOCK, the chain of top-level blocks of the function,
5721 and INSNS, the insn chain of the function. */
5723 void
5724 identify_blocks ()
5726 int n_blocks;
5727 tree *block_vector, *last_block_vector;
5728 tree *block_stack;
5729 tree block = DECL_INITIAL (current_function_decl);
5731 if (block == 0)
5732 return;
5734 /* Fill the BLOCK_VECTOR with all of the BLOCKs in this function, in
5735 depth-first order. */
5736 block_vector = get_block_vector (block, &n_blocks);
5737 block_stack = (tree *) xmalloc (n_blocks * sizeof (tree));
5739 last_block_vector = identify_blocks_1 (get_insns (),
5740 block_vector + 1,
5741 block_vector + n_blocks,
5742 block_stack);
5744 /* If we didn't use all of the subblocks, we've misplaced block notes. */
5745 /* ??? This appears to happen all the time. Latent bugs elsewhere? */
5746 if (0 && last_block_vector != block_vector + n_blocks)
5747 abort ();
5749 free (block_vector);
5750 free (block_stack);
5753 /* Subroutine of identify_blocks. Do the block substitution on the
5754 insn chain beginning with INSNS. Recurse for CALL_PLACEHOLDER chains.
5756 BLOCK_STACK is pushed and popped for each BLOCK_BEGIN/BLOCK_END pair.
5757 BLOCK_VECTOR is incremented for each block seen. */
5759 static tree *
5760 identify_blocks_1 (insns, block_vector, end_block_vector, orig_block_stack)
5761 rtx insns;
5762 tree *block_vector;
5763 tree *end_block_vector;
5764 tree *orig_block_stack;
5766 rtx insn;
5767 tree *block_stack = orig_block_stack;
5769 for (insn = insns; insn; insn = NEXT_INSN (insn))
5771 if (GET_CODE (insn) == NOTE)
5773 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
5775 tree b;
5777 /* If there are more block notes than BLOCKs, something
5778 is badly wrong. */
5779 if (block_vector == end_block_vector)
5780 abort ();
5782 b = *block_vector++;
5783 NOTE_BLOCK (insn) = b;
5784 *block_stack++ = b;
5786 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
5788 /* If there are more NOTE_INSN_BLOCK_ENDs than
5789 NOTE_INSN_BLOCK_BEGs, something is badly wrong. */
5790 if (block_stack == orig_block_stack)
5791 abort ();
5793 NOTE_BLOCK (insn) = *--block_stack;
5796 else if (GET_CODE (insn) == CALL_INSN
5797 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
5799 rtx cp = PATTERN (insn);
5801 block_vector = identify_blocks_1 (XEXP (cp, 0), block_vector,
5802 end_block_vector, block_stack);
5803 if (XEXP (cp, 1))
5804 block_vector = identify_blocks_1 (XEXP (cp, 1), block_vector,
5805 end_block_vector, block_stack);
5806 if (XEXP (cp, 2))
5807 block_vector = identify_blocks_1 (XEXP (cp, 2), block_vector,
5808 end_block_vector, block_stack);
5812 /* If there are more NOTE_INSN_BLOCK_BEGINs than NOTE_INSN_BLOCK_ENDs,
5813 something is badly wrong. */
5814 if (block_stack != orig_block_stack)
5815 abort ();
5817 return block_vector;
5820 /* Identify BLOCKs referenced by more than one
5821 NOTE_INSN_BLOCK_{BEG,END}, and create duplicate blocks. */
5823 void
5824 reorder_blocks ()
5826 tree block = DECL_INITIAL (current_function_decl);
5827 varray_type block_stack;
5829 if (block == NULL_TREE)
5830 return;
5832 VARRAY_TREE_INIT (block_stack, 10, "block_stack");
5834 /* Prune the old trees away, so that they don't get in the way. */
5835 BLOCK_SUBBLOCKS (block) = NULL_TREE;
5836 BLOCK_CHAIN (block) = NULL_TREE;
5838 reorder_blocks_0 (get_insns ());
5839 reorder_blocks_1 (get_insns (), block, &block_stack);
5841 BLOCK_SUBBLOCKS (block) = blocks_nreverse (BLOCK_SUBBLOCKS (block));
5843 VARRAY_FREE (block_stack);
5846 /* Helper function for reorder_blocks. Process the insn chain beginning
5847 at INSNS. Recurse for CALL_PLACEHOLDER insns. */
5849 static void
5850 reorder_blocks_0 (insns)
5851 rtx insns;
5853 rtx insn;
5855 for (insn = insns; insn; insn = NEXT_INSN (insn))
5857 if (GET_CODE (insn) == NOTE)
5859 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
5861 tree block = NOTE_BLOCK (insn);
5862 TREE_ASM_WRITTEN (block) = 0;
5865 else if (GET_CODE (insn) == CALL_INSN
5866 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
5868 rtx cp = PATTERN (insn);
5869 reorder_blocks_0 (XEXP (cp, 0));
5870 if (XEXP (cp, 1))
5871 reorder_blocks_0 (XEXP (cp, 1));
5872 if (XEXP (cp, 2))
5873 reorder_blocks_0 (XEXP (cp, 2));
5878 static void
5879 reorder_blocks_1 (insns, current_block, p_block_stack)
5880 rtx insns;
5881 tree current_block;
5882 varray_type *p_block_stack;
5884 rtx insn;
5886 for (insn = insns; insn; insn = NEXT_INSN (insn))
5888 if (GET_CODE (insn) == NOTE)
5890 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
5892 tree block = NOTE_BLOCK (insn);
5893 /* If we have seen this block before, copy it. */
5894 if (TREE_ASM_WRITTEN (block))
5896 block = copy_node (block);
5897 NOTE_BLOCK (insn) = block;
5899 BLOCK_SUBBLOCKS (block) = 0;
5900 TREE_ASM_WRITTEN (block) = 1;
5901 BLOCK_SUPERCONTEXT (block) = current_block;
5902 BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
5903 BLOCK_SUBBLOCKS (current_block) = block;
5904 current_block = block;
5905 VARRAY_PUSH_TREE (*p_block_stack, block);
5907 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
5909 NOTE_BLOCK (insn) = VARRAY_TOP_TREE (*p_block_stack);
5910 VARRAY_POP (*p_block_stack);
5911 BLOCK_SUBBLOCKS (current_block)
5912 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
5913 current_block = BLOCK_SUPERCONTEXT (current_block);
5916 else if (GET_CODE (insn) == CALL_INSN
5917 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
5919 rtx cp = PATTERN (insn);
5920 reorder_blocks_1 (XEXP (cp, 0), current_block, p_block_stack);
5921 if (XEXP (cp, 1))
5922 reorder_blocks_1 (XEXP (cp, 1), current_block, p_block_stack);
5923 if (XEXP (cp, 2))
5924 reorder_blocks_1 (XEXP (cp, 2), current_block, p_block_stack);
5929 /* Reverse the order of elements in the chain T of blocks,
5930 and return the new head of the chain (old last element). */
5932 static tree
5933 blocks_nreverse (t)
5934 tree t;
5936 register tree prev = 0, decl, next;
5937 for (decl = t; decl; decl = next)
5939 next = BLOCK_CHAIN (decl);
5940 BLOCK_CHAIN (decl) = prev;
5941 prev = decl;
5943 return prev;
5946 /* Count the subblocks of the list starting with BLOCK. If VECTOR is
5947 non-NULL, list them all into VECTOR, in a depth-first preorder
5948 traversal of the block tree. Also clear TREE_ASM_WRITTEN in all
5949 blocks. */
5951 static int
5952 all_blocks (block, vector)
5953 tree block;
5954 tree *vector;
5956 int n_blocks = 0;
5958 while (block)
5960 TREE_ASM_WRITTEN (block) = 0;
5962 /* Record this block. */
5963 if (vector)
5964 vector[n_blocks] = block;
5966 ++n_blocks;
5968 /* Record the subblocks, and their subblocks... */
5969 n_blocks += all_blocks (BLOCK_SUBBLOCKS (block),
5970 vector ? vector + n_blocks : 0);
5971 block = BLOCK_CHAIN (block);
5974 return n_blocks;
5977 /* Return a vector containing all the blocks rooted at BLOCK. The
5978 number of elements in the vector is stored in N_BLOCKS_P. The
5979 vector is dynamically allocated; it is the caller's responsibility
5980 to call `free' on the pointer returned. */
5982 static tree *
5983 get_block_vector (block, n_blocks_p)
5984 tree block;
5985 int *n_blocks_p;
5987 tree *block_vector;
5989 *n_blocks_p = all_blocks (block, NULL);
5990 block_vector = (tree *) xmalloc (*n_blocks_p * sizeof (tree));
5991 all_blocks (block, block_vector);
5993 return block_vector;
5996 static int next_block_index = 2;
5998 /* Set BLOCK_NUMBER for all the blocks in FN. */
6000 void
6001 number_blocks (fn)
6002 tree fn;
6004 int i;
6005 int n_blocks;
6006 tree *block_vector;
6008 /* For SDB and XCOFF debugging output, we start numbering the blocks
6009 from 1 within each function, rather than keeping a running
6010 count. */
6011 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
6012 if (write_symbols == SDB_DEBUG || write_symbols == XCOFF_DEBUG)
6013 next_block_index = 1;
6014 #endif
6016 block_vector = get_block_vector (DECL_INITIAL (fn), &n_blocks);
6018 /* The top-level BLOCK isn't numbered at all. */
6019 for (i = 1; i < n_blocks; ++i)
6020 /* We number the blocks from two. */
6021 BLOCK_NUMBER (block_vector[i]) = next_block_index++;
6023 free (block_vector);
6025 return;
6028 /* Allocate a function structure and reset its contents to the defaults. */
6029 static void
6030 prepare_function_start ()
6032 cfun = (struct function *) xcalloc (1, sizeof (struct function));
6034 init_stmt_for_function ();
6035 init_eh_for_function ();
6037 cse_not_expected = ! optimize;
6039 /* Caller save not needed yet. */
6040 caller_save_needed = 0;
6042 /* No stack slots have been made yet. */
6043 stack_slot_list = 0;
6045 current_function_has_nonlocal_label = 0;
6046 current_function_has_nonlocal_goto = 0;
6048 /* There is no stack slot for handling nonlocal gotos. */
6049 nonlocal_goto_handler_slots = 0;
6050 nonlocal_goto_stack_level = 0;
6052 /* No labels have been declared for nonlocal use. */
6053 nonlocal_labels = 0;
6054 nonlocal_goto_handler_labels = 0;
6056 /* No function calls so far in this function. */
6057 function_call_count = 0;
6059 /* No parm regs have been allocated.
6060 (This is important for output_inline_function.) */
6061 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
6063 /* Initialize the RTL mechanism. */
6064 init_emit ();
6066 /* Initialize the queue of pending postincrement and postdecrements,
6067 and some other info in expr.c. */
6068 init_expr ();
6070 /* We haven't done register allocation yet. */
6071 reg_renumber = 0;
6073 init_varasm_status (cfun);
6075 /* Clear out data used for inlining. */
6076 cfun->inlinable = 0;
6077 cfun->original_decl_initial = 0;
6078 cfun->original_arg_vector = 0;
6080 #ifdef STACK_BOUNDARY
6081 cfun->stack_alignment_needed = STACK_BOUNDARY;
6082 cfun->preferred_stack_boundary = STACK_BOUNDARY;
6083 #else
6084 cfun->stack_alignment_needed = 0;
6085 cfun->preferred_stack_boundary = 0;
6086 #endif
6088 /* Set if a call to setjmp is seen. */
6089 current_function_calls_setjmp = 0;
6091 /* Set if a call to longjmp is seen. */
6092 current_function_calls_longjmp = 0;
6094 current_function_calls_alloca = 0;
6095 current_function_contains_functions = 0;
6096 current_function_is_leaf = 0;
6097 current_function_nothrow = 0;
6098 current_function_sp_is_unchanging = 0;
6099 current_function_uses_only_leaf_regs = 0;
6100 current_function_has_computed_jump = 0;
6101 current_function_is_thunk = 0;
6103 current_function_returns_pcc_struct = 0;
6104 current_function_returns_struct = 0;
6105 current_function_epilogue_delay_list = 0;
6106 current_function_uses_const_pool = 0;
6107 current_function_uses_pic_offset_table = 0;
6108 current_function_cannot_inline = 0;
6110 /* We have not yet needed to make a label to jump to for tail-recursion. */
6111 tail_recursion_label = 0;
6113 /* We haven't had a need to make a save area for ap yet. */
6114 arg_pointer_save_area = 0;
6116 /* No stack slots allocated yet. */
6117 frame_offset = 0;
6119 /* No SAVE_EXPRs in this function yet. */
6120 save_expr_regs = 0;
6122 /* No RTL_EXPRs in this function yet. */
6123 rtl_expr_chain = 0;
6125 /* Set up to allocate temporaries. */
6126 init_temp_slots ();
6128 /* Indicate that we need to distinguish between the return value of the
6129 present function and the return value of a function being called. */
6130 rtx_equal_function_value_matters = 1;
6132 /* Indicate that we have not instantiated virtual registers yet. */
6133 virtuals_instantiated = 0;
6135 /* Indicate that we want CONCATs now. */
6136 generating_concat_p = 1;
6138 /* Indicate we have no need of a frame pointer yet. */
6139 frame_pointer_needed = 0;
6141 /* By default assume not varargs or stdarg. */
6142 current_function_varargs = 0;
6143 current_function_stdarg = 0;
6145 /* We haven't made any trampolines for this function yet. */
6146 trampoline_list = 0;
6148 init_pending_stack_adjust ();
6149 inhibit_defer_pop = 0;
6151 current_function_outgoing_args_size = 0;
6153 if (init_lang_status)
6154 (*init_lang_status) (cfun);
6155 if (init_machine_status)
6156 (*init_machine_status) (cfun);
6159 /* Initialize the rtl expansion mechanism so that we can do simple things
6160 like generate sequences. This is used to provide a context during global
6161 initialization of some passes. */
6162 void
6163 init_dummy_function_start ()
6165 prepare_function_start ();
6168 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
6169 and initialize static variables for generating RTL for the statements
6170 of the function. */
6172 void
6173 init_function_start (subr, filename, line)
6174 tree subr;
6175 const char *filename;
6176 int line;
6178 prepare_function_start ();
6180 /* Remember this function for later. */
6181 cfun->next_global = all_functions;
6182 all_functions = cfun;
6184 current_function_name = (*decl_printable_name) (subr, 2);
6185 cfun->decl = subr;
6187 /* Nonzero if this is a nested function that uses a static chain. */
6189 current_function_needs_context
6190 = (decl_function_context (current_function_decl) != 0
6191 && ! DECL_NO_STATIC_CHAIN (current_function_decl));
6193 /* Within function body, compute a type's size as soon it is laid out. */
6194 immediate_size_expand++;
6196 /* Prevent ever trying to delete the first instruction of a function.
6197 Also tell final how to output a linenum before the function prologue.
6198 Note linenums could be missing, e.g. when compiling a Java .class file. */
6199 if (line > 0)
6200 emit_line_note (filename, line);
6202 /* Make sure first insn is a note even if we don't want linenums.
6203 This makes sure the first insn will never be deleted.
6204 Also, final expects a note to appear there. */
6205 emit_note (NULL_PTR, NOTE_INSN_DELETED);
6207 /* Set flags used by final.c. */
6208 if (aggregate_value_p (DECL_RESULT (subr)))
6210 #ifdef PCC_STATIC_STRUCT_RETURN
6211 current_function_returns_pcc_struct = 1;
6212 #endif
6213 current_function_returns_struct = 1;
6216 /* Warn if this value is an aggregate type,
6217 regardless of which calling convention we are using for it. */
6218 if (warn_aggregate_return
6219 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
6220 warning ("function returns an aggregate");
6222 current_function_returns_pointer
6223 = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
6226 /* Make sure all values used by the optimization passes have sane
6227 defaults. */
6228 void
6229 init_function_for_compilation ()
6231 reg_renumber = 0;
6233 /* No prologue/epilogue insns yet. */
6234 VARRAY_GROW (prologue, 0);
6235 VARRAY_GROW (epilogue, 0);
6236 VARRAY_GROW (sibcall_epilogue, 0);
6239 /* Indicate that the current function uses extra args
6240 not explicitly mentioned in the argument list in any fashion. */
6242 void
6243 mark_varargs ()
6245 current_function_varargs = 1;
6248 /* Expand a call to __main at the beginning of a possible main function. */
6250 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
6251 #undef HAS_INIT_SECTION
6252 #define HAS_INIT_SECTION
6253 #endif
6255 void
6256 expand_main_function ()
6258 #if !defined (HAS_INIT_SECTION)
6259 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, NAME__MAIN), 0,
6260 VOIDmode, 0);
6261 #endif /* not HAS_INIT_SECTION */
6264 extern struct obstack permanent_obstack;
6266 /* Start the RTL for a new function, and set variables used for
6267 emitting RTL.
6268 SUBR is the FUNCTION_DECL node.
6269 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
6270 the function's parameters, which must be run at any return statement. */
6272 void
6273 expand_function_start (subr, parms_have_cleanups)
6274 tree subr;
6275 int parms_have_cleanups;
6277 tree tem;
6278 rtx last_ptr = NULL_RTX;
6280 /* Make sure volatile mem refs aren't considered
6281 valid operands of arithmetic insns. */
6282 init_recog_no_volatile ();
6284 /* Set this before generating any memory accesses. */
6285 current_function_check_memory_usage
6286 = (flag_check_memory_usage
6287 && ! DECL_NO_CHECK_MEMORY_USAGE (current_function_decl));
6289 current_function_instrument_entry_exit
6290 = (flag_instrument_function_entry_exit
6291 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr));
6293 current_function_limit_stack
6294 = (stack_limit_rtx != NULL_RTX && ! DECL_NO_LIMIT_STACK (subr));
6296 /* If function gets a static chain arg, store it in the stack frame.
6297 Do this first, so it gets the first stack slot offset. */
6298 if (current_function_needs_context)
6300 last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
6302 /* Delay copying static chain if it is not a register to avoid
6303 conflicts with regs used for parameters. */
6304 if (! SMALL_REGISTER_CLASSES
6305 || GET_CODE (static_chain_incoming_rtx) == REG)
6306 emit_move_insn (last_ptr, static_chain_incoming_rtx);
6309 /* If the parameters of this function need cleaning up, get a label
6310 for the beginning of the code which executes those cleanups. This must
6311 be done before doing anything with return_label. */
6312 if (parms_have_cleanups)
6313 cleanup_label = gen_label_rtx ();
6314 else
6315 cleanup_label = 0;
6317 /* Make the label for return statements to jump to. Do not special
6318 case machines with special return instructions -- they will be
6319 handled later during jump, ifcvt, or epilogue creation. */
6320 return_label = gen_label_rtx ();
6322 /* Initialize rtx used to return the value. */
6323 /* Do this before assign_parms so that we copy the struct value address
6324 before any library calls that assign parms might generate. */
6326 /* Decide whether to return the value in memory or in a register. */
6327 if (aggregate_value_p (DECL_RESULT (subr)))
6329 /* Returning something that won't go in a register. */
6330 register rtx value_address = 0;
6332 #ifdef PCC_STATIC_STRUCT_RETURN
6333 if (current_function_returns_pcc_struct)
6335 int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
6336 value_address = assemble_static_space (size);
6338 else
6339 #endif
6341 /* Expect to be passed the address of a place to store the value.
6342 If it is passed as an argument, assign_parms will take care of
6343 it. */
6344 if (struct_value_incoming_rtx)
6346 value_address = gen_reg_rtx (Pmode);
6347 emit_move_insn (value_address, struct_value_incoming_rtx);
6350 if (value_address)
6352 SET_DECL_RTL (DECL_RESULT (subr),
6353 gen_rtx_MEM (DECL_MODE (DECL_RESULT (subr)),
6354 value_address));
6355 set_mem_attributes (DECL_RTL (DECL_RESULT (subr)),
6356 DECL_RESULT (subr), 1);
6359 else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
6360 /* If return mode is void, this decl rtl should not be used. */
6361 SET_DECL_RTL (DECL_RESULT (subr), NULL_RTX);
6362 else if (parms_have_cleanups
6363 || current_function_instrument_entry_exit
6364 || (flag_exceptions && USING_SJLJ_EXCEPTIONS))
6366 /* If function will end with cleanup code for parms,
6367 compute the return values into a pseudo reg,
6368 which we will copy into the true return register
6369 after the cleanups are done. */
6371 enum machine_mode mode = DECL_MODE (DECL_RESULT (subr));
6373 #ifdef PROMOTE_FUNCTION_RETURN
6374 tree type = TREE_TYPE (DECL_RESULT (subr));
6375 int unsignedp = TREE_UNSIGNED (type);
6377 mode = promote_mode (type, mode, &unsignedp, 1);
6378 #endif
6380 SET_DECL_RTL (DECL_RESULT (subr), gen_reg_rtx (mode));
6381 /* Needed because we may need to move this to memory
6382 in case it's a named return value whose address is taken. */
6383 DECL_REGISTER (DECL_RESULT (subr)) = 1;
6385 else
6387 /* Scalar, returned in a register. */
6388 SET_DECL_RTL (DECL_RESULT (subr),
6389 hard_function_value (TREE_TYPE (DECL_RESULT (subr)),
6390 subr, 1));
6392 /* Mark this reg as the function's return value. */
6393 if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG)
6395 REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1;
6396 /* Needed because we may need to move this to memory
6397 in case it's a named return value whose address is taken. */
6398 DECL_REGISTER (DECL_RESULT (subr)) = 1;
6402 /* Initialize rtx for parameters and local variables.
6403 In some cases this requires emitting insns. */
6405 assign_parms (subr);
6407 /* Copy the static chain now if it wasn't a register. The delay is to
6408 avoid conflicts with the parameter passing registers. */
6410 if (SMALL_REGISTER_CLASSES && current_function_needs_context)
6411 if (GET_CODE (static_chain_incoming_rtx) != REG)
6412 emit_move_insn (last_ptr, static_chain_incoming_rtx);
6414 /* The following was moved from init_function_start.
6415 The move is supposed to make sdb output more accurate. */
6416 /* Indicate the beginning of the function body,
6417 as opposed to parm setup. */
6418 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_BEG);
6420 if (GET_CODE (get_last_insn ()) != NOTE)
6421 emit_note (NULL_PTR, NOTE_INSN_DELETED);
6422 parm_birth_insn = get_last_insn ();
6424 context_display = 0;
6425 if (current_function_needs_context)
6427 /* Fetch static chain values for containing functions. */
6428 tem = decl_function_context (current_function_decl);
6429 /* Copy the static chain pointer into a pseudo. If we have
6430 small register classes, copy the value from memory if
6431 static_chain_incoming_rtx is a REG. */
6432 if (tem)
6434 /* If the static chain originally came in a register, put it back
6435 there, then move it out in the next insn. The reason for
6436 this peculiar code is to satisfy function integration. */
6437 if (SMALL_REGISTER_CLASSES
6438 && GET_CODE (static_chain_incoming_rtx) == REG)
6439 emit_move_insn (static_chain_incoming_rtx, last_ptr);
6440 last_ptr = copy_to_reg (static_chain_incoming_rtx);
6443 while (tem)
6445 tree rtlexp = make_node (RTL_EXPR);
6447 RTL_EXPR_RTL (rtlexp) = last_ptr;
6448 context_display = tree_cons (tem, rtlexp, context_display);
6449 tem = decl_function_context (tem);
6450 if (tem == 0)
6451 break;
6452 /* Chain thru stack frames, assuming pointer to next lexical frame
6453 is found at the place we always store it. */
6454 #ifdef FRAME_GROWS_DOWNWARD
6455 last_ptr = plus_constant (last_ptr,
6456 -(HOST_WIDE_INT) GET_MODE_SIZE (Pmode));
6457 #endif
6458 last_ptr = gen_rtx_MEM (Pmode, memory_address (Pmode, last_ptr));
6459 MEM_ALIAS_SET (last_ptr) = get_frame_alias_set ();
6460 last_ptr = copy_to_reg (last_ptr);
6462 /* If we are not optimizing, ensure that we know that this
6463 piece of context is live over the entire function. */
6464 if (! optimize)
6465 save_expr_regs = gen_rtx_EXPR_LIST (VOIDmode, last_ptr,
6466 save_expr_regs);
6470 if (current_function_instrument_entry_exit)
6472 rtx fun = DECL_RTL (current_function_decl);
6473 if (GET_CODE (fun) == MEM)
6474 fun = XEXP (fun, 0);
6475 else
6476 abort ();
6477 emit_library_call (profile_function_entry_libfunc, 0, VOIDmode, 2,
6478 fun, Pmode,
6479 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS,
6481 hard_frame_pointer_rtx),
6482 Pmode);
6485 #ifdef PROFILE_HOOK
6486 if (profile_flag)
6487 PROFILE_HOOK (profile_label_no);
6488 #endif
6490 /* After the display initializations is where the tail-recursion label
6491 should go, if we end up needing one. Ensure we have a NOTE here
6492 since some things (like trampolines) get placed before this. */
6493 tail_recursion_reentry = emit_note (NULL_PTR, NOTE_INSN_DELETED);
6495 /* Evaluate now the sizes of any types declared among the arguments. */
6496 for (tem = nreverse (get_pending_sizes ()); tem; tem = TREE_CHAIN (tem))
6498 expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode,
6499 EXPAND_MEMORY_USE_BAD);
6500 /* Flush the queue in case this parameter declaration has
6501 side-effects. */
6502 emit_queue ();
6505 /* Make sure there is a line number after the function entry setup code. */
6506 force_next_line_note ();
6509 /* Undo the effects of init_dummy_function_start. */
6510 void
6511 expand_dummy_function_end ()
6513 /* End any sequences that failed to be closed due to syntax errors. */
6514 while (in_sequence_p ())
6515 end_sequence ();
6517 /* Outside function body, can't compute type's actual size
6518 until next function's body starts. */
6520 free_after_parsing (cfun);
6521 free_after_compilation (cfun);
6522 free (cfun);
6523 cfun = 0;
6526 /* Call DOIT for each hard register used as a return value from
6527 the current function. */
6529 void
6530 diddle_return_value (doit, arg)
6531 void (*doit) PARAMS ((rtx, void *));
6532 void *arg;
6534 rtx outgoing = current_function_return_rtx;
6535 int pcc;
6537 if (! outgoing)
6538 return;
6540 pcc = (current_function_returns_struct
6541 || current_function_returns_pcc_struct);
6543 if ((GET_CODE (outgoing) == REG
6544 && REGNO (outgoing) >= FIRST_PSEUDO_REGISTER)
6545 || pcc)
6547 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
6549 /* A PCC-style return returns a pointer to the memory in which
6550 the structure is stored. */
6551 if (pcc)
6552 type = build_pointer_type (type);
6554 #ifdef FUNCTION_OUTGOING_VALUE
6555 outgoing = FUNCTION_OUTGOING_VALUE (type, current_function_decl);
6556 #else
6557 outgoing = FUNCTION_VALUE (type, current_function_decl);
6558 #endif
6559 /* If this is a BLKmode structure being returned in registers, then use
6560 the mode computed in expand_return. */
6561 if (GET_MODE (outgoing) == BLKmode)
6562 PUT_MODE (outgoing, GET_MODE (current_function_return_rtx));
6563 REG_FUNCTION_VALUE_P (outgoing) = 1;
6566 if (GET_CODE (outgoing) == REG)
6567 (*doit) (outgoing, arg);
6568 else if (GET_CODE (outgoing) == PARALLEL)
6570 int i;
6572 for (i = 0; i < XVECLEN (outgoing, 0); i++)
6574 rtx x = XEXP (XVECEXP (outgoing, 0, i), 0);
6576 if (GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER)
6577 (*doit) (x, arg);
6582 static void
6583 do_clobber_return_reg (reg, arg)
6584 rtx reg;
6585 void *arg ATTRIBUTE_UNUSED;
6587 emit_insn (gen_rtx_CLOBBER (VOIDmode, reg));
6590 void
6591 clobber_return_register ()
6593 diddle_return_value (do_clobber_return_reg, NULL);
6596 static void
6597 do_use_return_reg (reg, arg)
6598 rtx reg;
6599 void *arg ATTRIBUTE_UNUSED;
6601 emit_insn (gen_rtx_USE (VOIDmode, reg));
6604 void
6605 use_return_register ()
6607 diddle_return_value (do_use_return_reg, NULL);
6610 /* Generate RTL for the end of the current function.
6611 FILENAME and LINE are the current position in the source file.
6613 It is up to language-specific callers to do cleanups for parameters--
6614 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */
6616 void
6617 expand_function_end (filename, line, end_bindings)
6618 const char *filename;
6619 int line;
6620 int end_bindings;
6622 tree link;
6624 #ifdef TRAMPOLINE_TEMPLATE
6625 static rtx initial_trampoline;
6626 #endif
6628 finish_expr_for_function ();
6630 #ifdef NON_SAVING_SETJMP
6631 /* Don't put any variables in registers if we call setjmp
6632 on a machine that fails to restore the registers. */
6633 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
6635 if (DECL_INITIAL (current_function_decl) != error_mark_node)
6636 setjmp_protect (DECL_INITIAL (current_function_decl));
6638 setjmp_protect_args ();
6640 #endif
6642 /* Save the argument pointer if a save area was made for it. */
6643 if (arg_pointer_save_area)
6645 /* arg_pointer_save_area may not be a valid memory address, so we
6646 have to check it and fix it if necessary. */
6647 rtx seq;
6648 start_sequence ();
6649 emit_move_insn (validize_mem (arg_pointer_save_area),
6650 virtual_incoming_args_rtx);
6651 seq = gen_sequence ();
6652 end_sequence ();
6653 emit_insn_before (seq, tail_recursion_reentry);
6656 /* Initialize any trampolines required by this function. */
6657 for (link = trampoline_list; link; link = TREE_CHAIN (link))
6659 tree function = TREE_PURPOSE (link);
6660 rtx context ATTRIBUTE_UNUSED = lookup_static_chain (function);
6661 rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
6662 #ifdef TRAMPOLINE_TEMPLATE
6663 rtx blktramp;
6664 #endif
6665 rtx seq;
6667 #ifdef TRAMPOLINE_TEMPLATE
6668 /* First make sure this compilation has a template for
6669 initializing trampolines. */
6670 if (initial_trampoline == 0)
6672 initial_trampoline
6673 = gen_rtx_MEM (BLKmode, assemble_trampoline_template ());
6675 ggc_add_rtx_root (&initial_trampoline, 1);
6677 #endif
6679 /* Generate insns to initialize the trampoline. */
6680 start_sequence ();
6681 tramp = round_trampoline_addr (XEXP (tramp, 0));
6682 #ifdef TRAMPOLINE_TEMPLATE
6683 blktramp = change_address (initial_trampoline, BLKmode, tramp);
6684 emit_block_move (blktramp, initial_trampoline,
6685 GEN_INT (TRAMPOLINE_SIZE),
6686 TRAMPOLINE_ALIGNMENT);
6687 #endif
6688 INITIALIZE_TRAMPOLINE (tramp, XEXP (DECL_RTL (function), 0), context);
6689 seq = get_insns ();
6690 end_sequence ();
6692 /* Put those insns at entry to the containing function (this one). */
6693 emit_insns_before (seq, tail_recursion_reentry);
6696 /* If we are doing stack checking and this function makes calls,
6697 do a stack probe at the start of the function to ensure we have enough
6698 space for another stack frame. */
6699 if (flag_stack_check && ! STACK_CHECK_BUILTIN)
6701 rtx insn, seq;
6703 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
6704 if (GET_CODE (insn) == CALL_INSN)
6706 start_sequence ();
6707 probe_stack_range (STACK_CHECK_PROTECT,
6708 GEN_INT (STACK_CHECK_MAX_FRAME_SIZE));
6709 seq = get_insns ();
6710 end_sequence ();
6711 emit_insns_before (seq, tail_recursion_reentry);
6712 break;
6716 /* Warn about unused parms if extra warnings were specified. */
6717 /* Either ``-W -Wunused'' or ``-Wunused-parameter'' enables this
6718 warning. WARN_UNUSED_PARAMETER is negative when set by
6719 -Wunused. */
6720 if (warn_unused_parameter > 0
6721 || (warn_unused_parameter < 0 && extra_warnings))
6723 tree decl;
6725 for (decl = DECL_ARGUMENTS (current_function_decl);
6726 decl; decl = TREE_CHAIN (decl))
6727 if (! TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
6728 && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
6729 warning_with_decl (decl, "unused parameter `%s'");
6732 /* Delete handlers for nonlocal gotos if nothing uses them. */
6733 if (nonlocal_goto_handler_slots != 0
6734 && ! current_function_has_nonlocal_label)
6735 delete_handlers ();
6737 /* End any sequences that failed to be closed due to syntax errors. */
6738 while (in_sequence_p ())
6739 end_sequence ();
6741 /* Outside function body, can't compute type's actual size
6742 until next function's body starts. */
6743 immediate_size_expand--;
6745 clear_pending_stack_adjust ();
6746 do_pending_stack_adjust ();
6748 /* Mark the end of the function body.
6749 If control reaches this insn, the function can drop through
6750 without returning a value. */
6751 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_END);
6753 /* Must mark the last line number note in the function, so that the test
6754 coverage code can avoid counting the last line twice. This just tells
6755 the code to ignore the immediately following line note, since there
6756 already exists a copy of this note somewhere above. This line number
6757 note is still needed for debugging though, so we can't delete it. */
6758 if (flag_test_coverage)
6759 emit_note (NULL_PTR, NOTE_INSN_REPEATED_LINE_NUMBER);
6761 /* Output a linenumber for the end of the function.
6762 SDB depends on this. */
6763 emit_line_note_force (filename, line);
6765 /* Output the label for the actual return from the function,
6766 if one is expected. This happens either because a function epilogue
6767 is used instead of a return instruction, or because a return was done
6768 with a goto in order to run local cleanups, or because of pcc-style
6769 structure returning. */
6771 if (return_label)
6773 rtx before, after;
6775 /* Before the return label, clobber the return registers so that
6776 they are not propogated live to the rest of the function. This
6777 can only happen with functions that drop through; if there had
6778 been a return statement, there would have either been a return
6779 rtx, or a jump to the return label. */
6781 before = get_last_insn ();
6782 clobber_return_register ();
6783 after = get_last_insn ();
6785 if (before != after)
6786 cfun->x_clobber_return_insn = after;
6788 emit_label (return_label);
6791 /* C++ uses this. */
6792 if (end_bindings)
6793 expand_end_bindings (0, 0, 0);
6795 if (current_function_instrument_entry_exit)
6797 rtx fun = DECL_RTL (current_function_decl);
6798 if (GET_CODE (fun) == MEM)
6799 fun = XEXP (fun, 0);
6800 else
6801 abort ();
6802 emit_library_call (profile_function_exit_libfunc, 0, VOIDmode, 2,
6803 fun, Pmode,
6804 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS,
6806 hard_frame_pointer_rtx),
6807 Pmode);
6810 /* Let except.c know where it should emit the call to unregister
6811 the function context for sjlj exceptions. */
6812 if (flag_exceptions && USING_SJLJ_EXCEPTIONS)
6813 sjlj_emit_function_exit_after (get_last_insn ());
6815 /* If we had calls to alloca, and this machine needs
6816 an accurate stack pointer to exit the function,
6817 insert some code to save and restore the stack pointer. */
6818 #ifdef EXIT_IGNORE_STACK
6819 if (! EXIT_IGNORE_STACK)
6820 #endif
6821 if (current_function_calls_alloca)
6823 rtx tem = 0;
6825 emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
6826 emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
6829 /* If scalar return value was computed in a pseudo-reg, or was a named
6830 return value that got dumped to the stack, copy that to the hard
6831 return register. */
6832 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl)))
6834 tree decl_result = DECL_RESULT (current_function_decl);
6835 rtx decl_rtl = DECL_RTL (decl_result);
6837 if (REG_P (decl_rtl)
6838 ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
6839 : DECL_REGISTER (decl_result))
6841 rtx real_decl_rtl;
6843 #ifdef FUNCTION_OUTGOING_VALUE
6844 real_decl_rtl = FUNCTION_OUTGOING_VALUE (TREE_TYPE (decl_result),
6845 current_function_decl);
6846 #else
6847 real_decl_rtl = FUNCTION_VALUE (TREE_TYPE (decl_result),
6848 current_function_decl);
6849 #endif
6850 REG_FUNCTION_VALUE_P (real_decl_rtl) = 1;
6852 /* If this is a BLKmode structure being returned in registers,
6853 then use the mode computed in expand_return. Note that if
6854 decl_rtl is memory, then its mode may have been changed,
6855 but that current_function_return_rtx has not. */
6856 if (GET_MODE (real_decl_rtl) == BLKmode)
6857 PUT_MODE (real_decl_rtl, GET_MODE (current_function_return_rtx));
6859 /* If a named return value dumped decl_return to memory, then
6860 we may need to re-do the PROMOTE_MODE signed/unsigned
6861 extension. */
6862 if (GET_MODE (real_decl_rtl) != GET_MODE (decl_rtl))
6864 int unsignedp = TREE_UNSIGNED (TREE_TYPE (decl_result));
6866 #ifdef PROMOTE_FUNCTION_RETURN
6867 promote_mode (TREE_TYPE (decl_result), GET_MODE (decl_rtl),
6868 &unsignedp, 1);
6869 #endif
6871 convert_move (real_decl_rtl, decl_rtl, unsignedp);
6873 else if (GET_CODE (real_decl_rtl) == PARALLEL)
6874 emit_group_load (real_decl_rtl, decl_rtl,
6875 int_size_in_bytes (TREE_TYPE (decl_result)),
6876 TYPE_ALIGN (TREE_TYPE (decl_result)));
6877 else
6878 emit_move_insn (real_decl_rtl, decl_rtl);
6880 /* The delay slot scheduler assumes that current_function_return_rtx
6881 holds the hard register containing the return value, not a
6882 temporary pseudo. */
6883 current_function_return_rtx = real_decl_rtl;
6887 /* If returning a structure, arrange to return the address of the value
6888 in a place where debuggers expect to find it.
6890 If returning a structure PCC style,
6891 the caller also depends on this value.
6892 And current_function_returns_pcc_struct is not necessarily set. */
6893 if (current_function_returns_struct
6894 || current_function_returns_pcc_struct)
6896 rtx value_address
6897 = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
6898 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
6899 #ifdef FUNCTION_OUTGOING_VALUE
6900 rtx outgoing
6901 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
6902 current_function_decl);
6903 #else
6904 rtx outgoing
6905 = FUNCTION_VALUE (build_pointer_type (type), current_function_decl);
6906 #endif
6908 /* Mark this as a function return value so integrate will delete the
6909 assignment and USE below when inlining this function. */
6910 REG_FUNCTION_VALUE_P (outgoing) = 1;
6912 #ifdef POINTERS_EXTEND_UNSIGNED
6913 /* The address may be ptr_mode and OUTGOING may be Pmode. */
6914 if (GET_MODE (outgoing) != GET_MODE (value_address))
6915 value_address = convert_memory_address (GET_MODE (outgoing),
6916 value_address);
6917 #endif
6919 emit_move_insn (outgoing, value_address);
6921 /* Show return register used to hold result (in this case the address
6922 of the result. */
6923 current_function_return_rtx = outgoing;
6926 /* If this is an implementation of throw, do what's necessary to
6927 communicate between __builtin_eh_return and the epilogue. */
6928 expand_eh_return ();
6930 /* ??? This should no longer be necessary since stupid is no longer with
6931 us, but there are some parts of the compiler (eg reload_combine, and
6932 sh mach_dep_reorg) that still try and compute their own lifetime info
6933 instead of using the general framework. */
6934 use_return_register ();
6936 /* Output a return insn if we are using one.
6937 Otherwise, let the rtl chain end here, to drop through
6938 into the epilogue. */
6940 #ifdef HAVE_return
6941 if (HAVE_return)
6943 emit_jump_insn (gen_return ());
6944 emit_barrier ();
6946 #endif
6948 /* Fix up any gotos that jumped out to the outermost
6949 binding level of the function.
6950 Must follow emitting RETURN_LABEL. */
6952 /* If you have any cleanups to do at this point,
6953 and they need to create temporary variables,
6954 then you will lose. */
6955 expand_fixups (get_insns ());
6958 /* Extend a vector that records the INSN_UIDs of INSNS (either a
6959 sequence or a single insn). */
6961 static void
6962 record_insns (insns, vecp)
6963 rtx insns;
6964 varray_type *vecp;
6966 if (GET_CODE (insns) == SEQUENCE)
6968 int len = XVECLEN (insns, 0);
6969 int i = VARRAY_SIZE (*vecp);
6971 VARRAY_GROW (*vecp, i + len);
6972 while (--len >= 0)
6974 VARRAY_INT (*vecp, i) = INSN_UID (XVECEXP (insns, 0, len));
6975 ++i;
6978 else
6980 int i = VARRAY_SIZE (*vecp);
6981 VARRAY_GROW (*vecp, i + 1);
6982 VARRAY_INT (*vecp, i) = INSN_UID (insns);
6986 /* Determine how many INSN_UIDs in VEC are part of INSN. */
6988 static int
6989 contains (insn, vec)
6990 rtx insn;
6991 varray_type vec;
6993 register int i, j;
6995 if (GET_CODE (insn) == INSN
6996 && GET_CODE (PATTERN (insn)) == SEQUENCE)
6998 int count = 0;
6999 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
7000 for (j = VARRAY_SIZE (vec) - 1; j >= 0; --j)
7001 if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == VARRAY_INT (vec, j))
7002 count++;
7003 return count;
7005 else
7007 for (j = VARRAY_SIZE (vec) - 1; j >= 0; --j)
7008 if (INSN_UID (insn) == VARRAY_INT (vec, j))
7009 return 1;
7011 return 0;
7015 prologue_epilogue_contains (insn)
7016 rtx insn;
7018 if (contains (insn, prologue))
7019 return 1;
7020 if (contains (insn, epilogue))
7021 return 1;
7022 return 0;
7026 sibcall_epilogue_contains (insn)
7027 rtx insn;
7029 if (sibcall_epilogue)
7030 return contains (insn, sibcall_epilogue);
7031 return 0;
7034 #ifdef HAVE_return
7035 /* Insert gen_return at the end of block BB. This also means updating
7036 block_for_insn appropriately. */
7038 static void
7039 emit_return_into_block (bb, line_note)
7040 basic_block bb;
7041 rtx line_note;
7043 rtx p, end;
7045 p = NEXT_INSN (bb->end);
7046 end = emit_jump_insn_after (gen_return (), bb->end);
7047 if (line_note)
7048 emit_line_note_after (NOTE_SOURCE_FILE (line_note),
7049 NOTE_LINE_NUMBER (line_note), bb->end);
7051 while (1)
7053 set_block_for_insn (p, bb);
7054 if (p == bb->end)
7055 break;
7056 p = PREV_INSN (p);
7058 bb->end = end;
7060 #endif /* HAVE_return */
7062 #ifdef HAVE_epilogue
7064 /* Modify SEQ, a SEQUENCE that is part of the epilogue, to no modifications
7065 to the stack pointer. */
7067 static void
7068 keep_stack_depressed (seq)
7069 rtx seq;
7071 int i;
7072 rtx sp_from_reg = 0;
7073 int sp_modified_unknown = 0;
7075 /* If the epilogue is just a single instruction, it's OK as is */
7077 if (GET_CODE (seq) != SEQUENCE)
7078 return;
7080 /* Scan all insns in SEQ looking for ones that modified the stack
7081 pointer. Record if it modified the stack pointer by copying it
7082 from the frame pointer or if it modified it in some other way.
7083 Then modify any subsequent stack pointer references to take that
7084 into account. We start by only allowing SP to be copied from a
7085 register (presumably FP) and then be subsequently referenced. */
7087 for (i = 0; i < XVECLEN (seq, 0); i++)
7089 rtx insn = XVECEXP (seq, 0, i);
7091 if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
7092 continue;
7094 if (reg_set_p (stack_pointer_rtx, insn))
7096 rtx set = single_set (insn);
7098 /* If SP is set as a side-effect, we can't support this. */
7099 if (set == 0)
7100 abort ();
7102 if (GET_CODE (SET_SRC (set)) == REG)
7103 sp_from_reg = SET_SRC (set);
7104 else
7105 sp_modified_unknown = 1;
7107 /* Don't allow the SP modification to happen. */
7108 PUT_CODE (insn, NOTE);
7109 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
7110 NOTE_SOURCE_FILE (insn) = 0;
7112 else if (reg_referenced_p (stack_pointer_rtx, PATTERN (insn)))
7114 if (sp_modified_unknown)
7115 abort ();
7117 else if (sp_from_reg != 0)
7118 PATTERN (insn)
7119 = replace_rtx (PATTERN (insn), stack_pointer_rtx, sp_from_reg);
7123 #endif
7125 /* Generate the prologue and epilogue RTL if the machine supports it. Thread
7126 this into place with notes indicating where the prologue ends and where
7127 the epilogue begins. Update the basic block information when possible. */
7129 void
7130 thread_prologue_and_epilogue_insns (f)
7131 rtx f ATTRIBUTE_UNUSED;
7133 int inserted = 0;
7134 edge e;
7135 rtx seq;
7136 #ifdef HAVE_prologue
7137 rtx prologue_end = NULL_RTX;
7138 #endif
7139 #if defined (HAVE_epilogue) || defined(HAVE_return)
7140 rtx epilogue_end = NULL_RTX;
7141 #endif
7143 #ifdef HAVE_prologue
7144 if (HAVE_prologue)
7146 start_sequence ();
7147 seq = gen_prologue ();
7148 emit_insn (seq);
7150 /* Retain a map of the prologue insns. */
7151 if (GET_CODE (seq) != SEQUENCE)
7152 seq = get_insns ();
7153 record_insns (seq, &prologue);
7154 prologue_end = emit_note (NULL, NOTE_INSN_PROLOGUE_END);
7156 seq = gen_sequence ();
7157 end_sequence ();
7159 /* If optimization is off, and perhaps in an empty function,
7160 the entry block will have no successors. */
7161 if (ENTRY_BLOCK_PTR->succ)
7163 /* Can't deal with multiple successsors of the entry block. */
7164 if (ENTRY_BLOCK_PTR->succ->succ_next)
7165 abort ();
7167 insert_insn_on_edge (seq, ENTRY_BLOCK_PTR->succ);
7168 inserted = 1;
7170 else
7171 emit_insn_after (seq, f);
7173 #endif
7175 /* If the exit block has no non-fake predecessors, we don't need
7176 an epilogue. */
7177 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7178 if ((e->flags & EDGE_FAKE) == 0)
7179 break;
7180 if (e == NULL)
7181 goto epilogue_done;
7183 #ifdef HAVE_return
7184 if (optimize && HAVE_return)
7186 /* If we're allowed to generate a simple return instruction,
7187 then by definition we don't need a full epilogue. Examine
7188 the block that falls through to EXIT. If it does not
7189 contain any code, examine its predecessors and try to
7190 emit (conditional) return instructions. */
7192 basic_block last;
7193 edge e_next;
7194 rtx label;
7196 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7197 if (e->flags & EDGE_FALLTHRU)
7198 break;
7199 if (e == NULL)
7200 goto epilogue_done;
7201 last = e->src;
7203 /* Verify that there are no active instructions in the last block. */
7204 label = last->end;
7205 while (label && GET_CODE (label) != CODE_LABEL)
7207 if (active_insn_p (label))
7208 break;
7209 label = PREV_INSN (label);
7212 if (last->head == label && GET_CODE (label) == CODE_LABEL)
7214 rtx epilogue_line_note = NULL_RTX;
7216 /* Locate the line number associated with the closing brace,
7217 if we can find one. */
7218 for (seq = get_last_insn ();
7219 seq && ! active_insn_p (seq);
7220 seq = PREV_INSN (seq))
7221 if (GET_CODE (seq) == NOTE && NOTE_LINE_NUMBER (seq) > 0)
7223 epilogue_line_note = seq;
7224 break;
7227 for (e = last->pred; e; e = e_next)
7229 basic_block bb = e->src;
7230 rtx jump;
7232 e_next = e->pred_next;
7233 if (bb == ENTRY_BLOCK_PTR)
7234 continue;
7236 jump = bb->end;
7237 if ((GET_CODE (jump) != JUMP_INSN) || JUMP_LABEL (jump) != label)
7238 continue;
7240 /* If we have an unconditional jump, we can replace that
7241 with a simple return instruction. */
7242 if (simplejump_p (jump))
7244 emit_return_into_block (bb, epilogue_line_note);
7245 flow_delete_insn (jump);
7248 /* If we have a conditional jump, we can try to replace
7249 that with a conditional return instruction. */
7250 else if (condjump_p (jump))
7252 rtx ret, *loc;
7254 ret = SET_SRC (PATTERN (jump));
7255 if (GET_CODE (XEXP (ret, 1)) == LABEL_REF)
7256 loc = &XEXP (ret, 1);
7257 else
7258 loc = &XEXP (ret, 2);
7259 ret = gen_rtx_RETURN (VOIDmode);
7261 if (! validate_change (jump, loc, ret, 0))
7262 continue;
7263 if (JUMP_LABEL (jump))
7264 LABEL_NUSES (JUMP_LABEL (jump))--;
7266 /* If this block has only one successor, it both jumps
7267 and falls through to the fallthru block, so we can't
7268 delete the edge. */
7269 if (bb->succ->succ_next == NULL)
7270 continue;
7272 else
7273 continue;
7275 /* Fix up the CFG for the successful change we just made. */
7276 redirect_edge_succ (e, EXIT_BLOCK_PTR);
7279 /* Emit a return insn for the exit fallthru block. Whether
7280 this is still reachable will be determined later. */
7282 emit_barrier_after (last->end);
7283 emit_return_into_block (last, epilogue_line_note);
7284 epilogue_end = last->end;
7285 goto epilogue_done;
7288 #endif
7289 #ifdef HAVE_epilogue
7290 if (HAVE_epilogue)
7292 /* Find the edge that falls through to EXIT. Other edges may exist
7293 due to RETURN instructions, but those don't need epilogues.
7294 There really shouldn't be a mixture -- either all should have
7295 been converted or none, however... */
7297 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7298 if (e->flags & EDGE_FALLTHRU)
7299 break;
7300 if (e == NULL)
7301 goto epilogue_done;
7303 start_sequence ();
7304 epilogue_end = emit_note (NULL, NOTE_INSN_EPILOGUE_BEG);
7306 seq = gen_epilogue ();
7308 /* If this function returns with the stack depressed, massage
7309 the epilogue to actually do that. */
7310 if (TREE_CODE (TREE_TYPE (current_function_decl)) == FUNCTION_TYPE
7311 && TYPE_RETURNS_STACK_DEPRESSED (TREE_TYPE (current_function_decl)))
7312 keep_stack_depressed (seq);
7314 emit_jump_insn (seq);
7316 /* Retain a map of the epilogue insns. */
7317 if (GET_CODE (seq) != SEQUENCE)
7318 seq = get_insns ();
7319 record_insns (seq, &epilogue);
7321 seq = gen_sequence ();
7322 end_sequence ();
7324 insert_insn_on_edge (seq, e);
7325 inserted = 1;
7327 #endif
7328 epilogue_done:
7330 if (inserted)
7331 commit_edge_insertions ();
7333 #ifdef HAVE_sibcall_epilogue
7334 /* Emit sibling epilogues before any sibling call sites. */
7335 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7337 basic_block bb = e->src;
7338 rtx insn = bb->end;
7339 rtx i;
7340 rtx newinsn;
7342 if (GET_CODE (insn) != CALL_INSN
7343 || ! SIBLING_CALL_P (insn))
7344 continue;
7346 start_sequence ();
7347 seq = gen_sibcall_epilogue ();
7348 end_sequence ();
7350 i = PREV_INSN (insn);
7351 newinsn = emit_insn_before (seq, insn);
7353 /* Update the UID to basic block map. */
7354 for (i = NEXT_INSN (i); i != insn; i = NEXT_INSN (i))
7355 set_block_for_insn (i, bb);
7357 /* Retain a map of the epilogue insns. Used in life analysis to
7358 avoid getting rid of sibcall epilogue insns. */
7359 record_insns (GET_CODE (seq) == SEQUENCE
7360 ? seq : newinsn, &sibcall_epilogue);
7362 #endif
7364 #ifdef HAVE_prologue
7365 if (prologue_end)
7367 rtx insn, prev;
7369 /* GDB handles `break f' by setting a breakpoint on the first
7370 line note after the prologue. Which means (1) that if
7371 there are line number notes before where we inserted the
7372 prologue we should move them, and (2) we should generate a
7373 note before the end of the first basic block, if there isn't
7374 one already there. */
7376 for (insn = prologue_end; insn; insn = prev)
7378 prev = PREV_INSN (insn);
7379 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
7381 /* Note that we cannot reorder the first insn in the
7382 chain, since rest_of_compilation relies on that
7383 remaining constant. */
7384 if (prev == NULL)
7385 break;
7386 reorder_insns (insn, insn, prologue_end);
7390 /* Find the last line number note in the first block. */
7391 for (insn = BASIC_BLOCK (0)->end;
7392 insn != prologue_end;
7393 insn = PREV_INSN (insn))
7394 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
7395 break;
7397 /* If we didn't find one, make a copy of the first line number
7398 we run across. */
7399 if (! insn)
7401 for (insn = next_active_insn (prologue_end);
7402 insn;
7403 insn = PREV_INSN (insn))
7404 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
7406 emit_line_note_after (NOTE_SOURCE_FILE (insn),
7407 NOTE_LINE_NUMBER (insn),
7408 prologue_end);
7409 break;
7413 #endif
7414 #ifdef HAVE_epilogue
7415 if (epilogue_end)
7417 rtx insn, next;
7419 /* Similarly, move any line notes that appear after the epilogue.
7420 There is no need, however, to be quite so anal about the existance
7421 of such a note. */
7422 for (insn = epilogue_end; insn; insn = next)
7424 next = NEXT_INSN (insn);
7425 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
7426 reorder_insns (insn, insn, PREV_INSN (epilogue_end));
7429 #endif
7432 /* Reposition the prologue-end and epilogue-begin notes after instruction
7433 scheduling and delayed branch scheduling. */
7435 void
7436 reposition_prologue_and_epilogue_notes (f)
7437 rtx f ATTRIBUTE_UNUSED;
7439 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
7440 int len;
7442 if ((len = VARRAY_SIZE (prologue)) > 0)
7444 register rtx insn, note = 0;
7446 /* Scan from the beginning until we reach the last prologue insn.
7447 We apparently can't depend on basic_block_{head,end} after
7448 reorg has run. */
7449 for (insn = f; len && insn; insn = NEXT_INSN (insn))
7451 if (GET_CODE (insn) == NOTE)
7453 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
7454 note = insn;
7456 else if ((len -= contains (insn, prologue)) == 0)
7458 rtx next;
7459 /* Find the prologue-end note if we haven't already, and
7460 move it to just after the last prologue insn. */
7461 if (note == 0)
7463 for (note = insn; (note = NEXT_INSN (note));)
7464 if (GET_CODE (note) == NOTE
7465 && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
7466 break;
7469 next = NEXT_INSN (note);
7471 /* Whether or not we can depend on BLOCK_HEAD,
7472 attempt to keep it up-to-date. */
7473 if (BLOCK_HEAD (0) == note)
7474 BLOCK_HEAD (0) = next;
7476 remove_insn (note);
7477 add_insn_after (note, insn);
7482 if ((len = VARRAY_SIZE (epilogue)) > 0)
7484 register rtx insn, note = 0;
7486 /* Scan from the end until we reach the first epilogue insn.
7487 We apparently can't depend on basic_block_{head,end} after
7488 reorg has run. */
7489 for (insn = get_last_insn (); len && insn; insn = PREV_INSN (insn))
7491 if (GET_CODE (insn) == NOTE)
7493 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
7494 note = insn;
7496 else if ((len -= contains (insn, epilogue)) == 0)
7498 /* Find the epilogue-begin note if we haven't already, and
7499 move it to just before the first epilogue insn. */
7500 if (note == 0)
7502 for (note = insn; (note = PREV_INSN (note));)
7503 if (GET_CODE (note) == NOTE
7504 && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
7505 break;
7508 /* Whether or not we can depend on BLOCK_HEAD,
7509 attempt to keep it up-to-date. */
7510 if (n_basic_blocks
7511 && BLOCK_HEAD (n_basic_blocks-1) == insn)
7512 BLOCK_HEAD (n_basic_blocks-1) = note;
7514 remove_insn (note);
7515 add_insn_before (note, insn);
7519 #endif /* HAVE_prologue or HAVE_epilogue */
7522 /* Mark T for GC. */
7524 static void
7525 mark_temp_slot (t)
7526 struct temp_slot *t;
7528 while (t)
7530 ggc_mark_rtx (t->slot);
7531 ggc_mark_rtx (t->address);
7532 ggc_mark_tree (t->rtl_expr);
7533 ggc_mark_tree (t->type);
7535 t = t->next;
7539 /* Mark P for GC. */
7541 static void
7542 mark_function_status (p)
7543 struct function *p;
7545 int i;
7546 rtx *r;
7548 if (p == 0)
7549 return;
7551 ggc_mark_rtx (p->arg_offset_rtx);
7553 if (p->x_parm_reg_stack_loc)
7554 for (i = p->x_max_parm_reg, r = p->x_parm_reg_stack_loc;
7555 i > 0; --i, ++r)
7556 ggc_mark_rtx (*r);
7558 ggc_mark_rtx (p->return_rtx);
7559 ggc_mark_rtx (p->x_cleanup_label);
7560 ggc_mark_rtx (p->x_return_label);
7561 ggc_mark_rtx (p->x_save_expr_regs);
7562 ggc_mark_rtx (p->x_stack_slot_list);
7563 ggc_mark_rtx (p->x_parm_birth_insn);
7564 ggc_mark_rtx (p->x_tail_recursion_label);
7565 ggc_mark_rtx (p->x_tail_recursion_reentry);
7566 ggc_mark_rtx (p->internal_arg_pointer);
7567 ggc_mark_rtx (p->x_arg_pointer_save_area);
7568 ggc_mark_tree (p->x_rtl_expr_chain);
7569 ggc_mark_rtx (p->x_last_parm_insn);
7570 ggc_mark_tree (p->x_context_display);
7571 ggc_mark_tree (p->x_trampoline_list);
7572 ggc_mark_rtx (p->epilogue_delay_list);
7573 ggc_mark_rtx (p->x_clobber_return_insn);
7575 mark_temp_slot (p->x_temp_slots);
7578 struct var_refs_queue *q = p->fixup_var_refs_queue;
7579 while (q)
7581 ggc_mark_rtx (q->modified);
7582 q = q->next;
7586 ggc_mark_rtx (p->x_nonlocal_goto_handler_slots);
7587 ggc_mark_rtx (p->x_nonlocal_goto_handler_labels);
7588 ggc_mark_rtx (p->x_nonlocal_goto_stack_level);
7589 ggc_mark_tree (p->x_nonlocal_labels);
7592 /* Mark the function chain ARG (which is really a struct function **)
7593 for GC. */
7595 static void
7596 mark_function_chain (arg)
7597 void *arg;
7599 struct function *f = *(struct function **) arg;
7601 for (; f; f = f->next_global)
7603 ggc_mark_tree (f->decl);
7605 mark_function_status (f);
7606 mark_eh_status (f->eh);
7607 mark_stmt_status (f->stmt);
7608 mark_expr_status (f->expr);
7609 mark_emit_status (f->emit);
7610 mark_varasm_status (f->varasm);
7612 if (mark_machine_status)
7613 (*mark_machine_status) (f);
7614 if (mark_lang_status)
7615 (*mark_lang_status) (f);
7617 if (f->original_arg_vector)
7618 ggc_mark_rtvec ((rtvec) f->original_arg_vector);
7619 if (f->original_decl_initial)
7620 ggc_mark_tree (f->original_decl_initial);
7624 /* Called once, at initialization, to initialize function.c. */
7626 void
7627 init_function_once ()
7629 ggc_add_root (&all_functions, 1, sizeof all_functions,
7630 mark_function_chain);
7632 VARRAY_INT_INIT (prologue, 0, "prologue");
7633 VARRAY_INT_INIT (epilogue, 0, "epilogue");
7634 VARRAY_INT_INIT (sibcall_epilogue, 0, "sibcall_epilogue");