physmem.c (physmem_total): Use getsysinfo on Tru64 UNIX.
[gcc.git] / gcc / function.c
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, 2002 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
21
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.
26
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.
30
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.
35
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. */
40
41 #include "config.h"
42 #include "system.h"
43 #include "coretypes.h"
44 #include "tm.h"
45 #include "rtl.h"
46 #include "tree.h"
47 #include "flags.h"
48 #include "except.h"
49 #include "function.h"
50 #include "expr.h"
51 #include "libfuncs.h"
52 #include "regs.h"
53 #include "hard-reg-set.h"
54 #include "insn-config.h"
55 #include "recog.h"
56 #include "output.h"
57 #include "basic-block.h"
58 #include "toplev.h"
59 #include "hashtab.h"
60 #include "ggc.h"
61 #include "tm_p.h"
62 #include "integrate.h"
63 #include "langhooks.h"
64
65 #ifndef TRAMPOLINE_ALIGNMENT
66 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
67 #endif
68
69 #ifndef LOCAL_ALIGNMENT
70 #define LOCAL_ALIGNMENT(TYPE, ALIGNMENT) ALIGNMENT
71 #endif
72
73 /* Some systems use __main in a way incompatible with its use in gcc, in these
74 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
75 give the same symbol without quotes for an alternative entry point. You
76 must define both, or neither. */
77 #ifndef NAME__MAIN
78 #define NAME__MAIN "__main"
79 #endif
80
81 /* Round a value to the lowest integer less than it that is a multiple of
82 the required alignment. Avoid using division in case the value is
83 negative. Assume the alignment is a power of two. */
84 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
85
86 /* Similar, but round to the next highest integer that meets the
87 alignment. */
88 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
89
90 /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp
91 during rtl generation. If they are different register numbers, this is
92 always true. It may also be true if
93 FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl
94 generation. See fix_lexical_addr for details. */
95
96 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
97 #define NEED_SEPARATE_AP
98 #endif
99
100 /* Nonzero if function being compiled doesn't contain any calls
101 (ignoring the prologue and epilogue). This is set prior to
102 local register allocation and is valid for the remaining
103 compiler passes. */
104 int current_function_is_leaf;
105
106 /* Nonzero if function being compiled doesn't contain any instructions
107 that can throw an exception. This is set prior to final. */
108
109 int current_function_nothrow;
110
111 /* Nonzero if function being compiled doesn't modify the stack pointer
112 (ignoring the prologue and epilogue). This is only valid after
113 life_analysis has run. */
114 int current_function_sp_is_unchanging;
115
116 /* Nonzero if the function being compiled is a leaf function which only
117 uses leaf registers. This is valid after reload (specifically after
118 sched2) and is useful only if the port defines LEAF_REGISTERS. */
119 int current_function_uses_only_leaf_regs;
120
121 /* Nonzero once virtual register instantiation has been done.
122 assign_stack_local uses frame_pointer_rtx when this is nonzero.
123 calls.c:emit_library_call_value_1 uses it to set up
124 post-instantiation libcalls. */
125 int virtuals_instantiated;
126
127 /* Assign unique numbers to labels generated for profiling, debugging, etc. */
128 static GTY(()) int funcdef_no;
129
130 /* These variables hold pointers to functions to create and destroy
131 target specific, per-function data structures. */
132 struct machine_function * (*init_machine_status) PARAMS ((void));
133
134 /* The FUNCTION_DECL for an inline function currently being expanded. */
135 tree inline_function_decl;
136
137 /* The currently compiled function. */
138 struct function *cfun = 0;
139
140 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
141 static GTY(()) varray_type prologue;
142 static GTY(()) varray_type epilogue;
143
144 /* Array of INSN_UIDs to hold the INSN_UIDs for each sibcall epilogue
145 in this function. */
146 static GTY(()) varray_type sibcall_epilogue;
147 \f
148 /* In order to evaluate some expressions, such as function calls returning
149 structures in memory, we need to temporarily allocate stack locations.
150 We record each allocated temporary in the following structure.
151
152 Associated with each temporary slot is a nesting level. When we pop up
153 one level, all temporaries associated with the previous level are freed.
154 Normally, all temporaries are freed after the execution of the statement
155 in which they were created. However, if we are inside a ({...}) grouping,
156 the result may be in a temporary and hence must be preserved. If the
157 result could be in a temporary, we preserve it if we can determine which
158 one it is in. If we cannot determine which temporary may contain the
159 result, all temporaries are preserved. A temporary is preserved by
160 pretending it was allocated at the previous nesting level.
161
162 Automatic variables are also assigned temporary slots, at the nesting
163 level where they are defined. They are marked a "kept" so that
164 free_temp_slots will not free them. */
165
166 struct temp_slot GTY(())
167 {
168 /* Points to next temporary slot. */
169 struct temp_slot *next;
170 /* The rtx to used to reference the slot. */
171 rtx slot;
172 /* The rtx used to represent the address if not the address of the
173 slot above. May be an EXPR_LIST if multiple addresses exist. */
174 rtx address;
175 /* The alignment (in bits) of the slot. */
176 unsigned int align;
177 /* The size, in units, of the slot. */
178 HOST_WIDE_INT size;
179 /* The type of the object in the slot, or zero if it doesn't correspond
180 to a type. We use this to determine whether a slot can be reused.
181 It can be reused if objects of the type of the new slot will always
182 conflict with objects of the type of the old slot. */
183 tree type;
184 /* The value of `sequence_rtl_expr' when this temporary is allocated. */
185 tree rtl_expr;
186 /* Nonzero if this temporary is currently in use. */
187 char in_use;
188 /* Nonzero if this temporary has its address taken. */
189 char addr_taken;
190 /* Nesting level at which this slot is being used. */
191 int level;
192 /* Nonzero if this should survive a call to free_temp_slots. */
193 int keep;
194 /* The offset of the slot from the frame_pointer, including extra space
195 for alignment. This info is for combine_temp_slots. */
196 HOST_WIDE_INT base_offset;
197 /* The size of the slot, including extra space for alignment. This
198 info is for combine_temp_slots. */
199 HOST_WIDE_INT full_size;
200 };
201 \f
202 /* This structure is used to record MEMs or pseudos used to replace VAR, any
203 SUBREGs of VAR, and any MEMs containing VAR as an address. We need to
204 maintain this list in case two operands of an insn were required to match;
205 in that case we must ensure we use the same replacement. */
206
207 struct fixup_replacement GTY(())
208 {
209 rtx old;
210 rtx new;
211 struct fixup_replacement *next;
212 };
213
214 struct insns_for_mem_entry
215 {
216 /* A MEM. */
217 rtx key;
218 /* These are the INSNs which reference the MEM. */
219 rtx insns;
220 };
221
222 /* Forward declarations. */
223
224 static rtx assign_stack_local_1 PARAMS ((enum machine_mode, HOST_WIDE_INT,
225 int, struct function *));
226 static struct temp_slot *find_temp_slot_from_address PARAMS ((rtx));
227 static void put_reg_into_stack PARAMS ((struct function *, rtx, tree,
228 enum machine_mode, enum machine_mode,
229 int, unsigned int, int,
230 htab_t));
231 static void schedule_fixup_var_refs PARAMS ((struct function *, rtx, tree,
232 enum machine_mode,
233 htab_t));
234 static void fixup_var_refs PARAMS ((rtx, enum machine_mode, int, rtx,
235 htab_t));
236 static struct fixup_replacement
237 *find_fixup_replacement PARAMS ((struct fixup_replacement **, rtx));
238 static void fixup_var_refs_insns PARAMS ((rtx, rtx, enum machine_mode,
239 int, int, rtx));
240 static void fixup_var_refs_insns_with_hash
241 PARAMS ((htab_t, rtx,
242 enum machine_mode, int, rtx));
243 static void fixup_var_refs_insn PARAMS ((rtx, rtx, enum machine_mode,
244 int, int, rtx));
245 static void fixup_var_refs_1 PARAMS ((rtx, enum machine_mode, rtx *, rtx,
246 struct fixup_replacement **, rtx));
247 static rtx fixup_memory_subreg PARAMS ((rtx, rtx, enum machine_mode, int));
248 static rtx walk_fixup_memory_subreg PARAMS ((rtx, rtx, enum machine_mode,
249 int));
250 static rtx fixup_stack_1 PARAMS ((rtx, rtx));
251 static void optimize_bit_field PARAMS ((rtx, rtx, rtx *));
252 static void instantiate_decls PARAMS ((tree, int));
253 static void instantiate_decls_1 PARAMS ((tree, int));
254 static void instantiate_decl PARAMS ((rtx, HOST_WIDE_INT, int));
255 static rtx instantiate_new_reg PARAMS ((rtx, HOST_WIDE_INT *));
256 static int instantiate_virtual_regs_1 PARAMS ((rtx *, rtx, int));
257 static void delete_handlers PARAMS ((void));
258 static void pad_to_arg_alignment PARAMS ((struct args_size *, int,
259 struct args_size *));
260 static void pad_below PARAMS ((struct args_size *, enum machine_mode,
261 tree));
262 static rtx round_trampoline_addr PARAMS ((rtx));
263 static rtx adjust_trampoline_addr PARAMS ((rtx));
264 static tree *identify_blocks_1 PARAMS ((rtx, tree *, tree *, tree *));
265 static void reorder_blocks_0 PARAMS ((tree));
266 static void reorder_blocks_1 PARAMS ((rtx, tree, varray_type *));
267 static void reorder_fix_fragments PARAMS ((tree));
268 static tree blocks_nreverse PARAMS ((tree));
269 static int all_blocks PARAMS ((tree, tree *));
270 static tree *get_block_vector PARAMS ((tree, int *));
271 extern tree debug_find_var_in_block_tree PARAMS ((tree, tree));
272 /* We always define `record_insns' even if its not used so that we
273 can always export `prologue_epilogue_contains'. */
274 static void record_insns PARAMS ((rtx, varray_type *)) ATTRIBUTE_UNUSED;
275 static int contains PARAMS ((rtx, varray_type));
276 #ifdef HAVE_return
277 static void emit_return_into_block PARAMS ((basic_block, rtx));
278 #endif
279 static void put_addressof_into_stack PARAMS ((rtx, htab_t));
280 static bool purge_addressof_1 PARAMS ((rtx *, rtx, int, int,
281 htab_t));
282 static void purge_single_hard_subreg_set PARAMS ((rtx));
283 #if defined(HAVE_epilogue) && defined(INCOMING_RETURN_ADDR_RTX)
284 static rtx keep_stack_depressed PARAMS ((rtx));
285 #endif
286 static int is_addressof PARAMS ((rtx *, void *));
287 static hashval_t insns_for_mem_hash PARAMS ((const void *));
288 static int insns_for_mem_comp PARAMS ((const void *, const void *));
289 static int insns_for_mem_walk PARAMS ((rtx *, void *));
290 static void compute_insns_for_mem PARAMS ((rtx, rtx, htab_t));
291 static void prepare_function_start PARAMS ((void));
292 static void do_clobber_return_reg PARAMS ((rtx, void *));
293 static void do_use_return_reg PARAMS ((rtx, void *));
294 \f
295 /* Pointer to chain of `struct function' for containing functions. */
296 static GTY(()) struct function *outer_function_chain;
297
298 /* Given a function decl for a containing function,
299 return the `struct function' for it. */
300
301 struct function *
302 find_function_data (decl)
303 tree decl;
304 {
305 struct function *p;
306
307 for (p = outer_function_chain; p; p = p->outer)
308 if (p->decl == decl)
309 return p;
310
311 abort ();
312 }
313
314 /* Save the current context for compilation of a nested function.
315 This is called from language-specific code. The caller should use
316 the enter_nested langhook to save any language-specific state,
317 since this function knows only about language-independent
318 variables. */
319
320 void
321 push_function_context_to (context)
322 tree context;
323 {
324 struct function *p;
325
326 if (context)
327 {
328 if (context == current_function_decl)
329 cfun->contains_functions = 1;
330 else
331 {
332 struct function *containing = find_function_data (context);
333 containing->contains_functions = 1;
334 }
335 }
336
337 if (cfun == 0)
338 init_dummy_function_start ();
339 p = cfun;
340
341 p->outer = outer_function_chain;
342 outer_function_chain = p;
343 p->fixup_var_refs_queue = 0;
344
345 (*lang_hooks.function.enter_nested) (p);
346
347 cfun = 0;
348 }
349
350 void
351 push_function_context ()
352 {
353 push_function_context_to (current_function_decl);
354 }
355
356 /* Restore the last saved context, at the end of a nested function.
357 This function is called from language-specific code. */
358
359 void
360 pop_function_context_from (context)
361 tree context ATTRIBUTE_UNUSED;
362 {
363 struct function *p = outer_function_chain;
364 struct var_refs_queue *queue;
365
366 cfun = p;
367 outer_function_chain = p->outer;
368
369 current_function_decl = p->decl;
370 reg_renumber = 0;
371
372 restore_emit_status (p);
373
374 (*lang_hooks.function.leave_nested) (p);
375
376 /* Finish doing put_var_into_stack for any of our variables which became
377 addressable during the nested function. If only one entry has to be
378 fixed up, just do that one. Otherwise, first make a list of MEMs that
379 are not to be unshared. */
380 if (p->fixup_var_refs_queue == 0)
381 ;
382 else if (p->fixup_var_refs_queue->next == 0)
383 fixup_var_refs (p->fixup_var_refs_queue->modified,
384 p->fixup_var_refs_queue->promoted_mode,
385 p->fixup_var_refs_queue->unsignedp,
386 p->fixup_var_refs_queue->modified, 0);
387 else
388 {
389 rtx list = 0;
390
391 for (queue = p->fixup_var_refs_queue; queue; queue = queue->next)
392 list = gen_rtx_EXPR_LIST (VOIDmode, queue->modified, list);
393
394 for (queue = p->fixup_var_refs_queue; queue; queue = queue->next)
395 fixup_var_refs (queue->modified, queue->promoted_mode,
396 queue->unsignedp, list, 0);
397
398 }
399
400 p->fixup_var_refs_queue = 0;
401
402 /* Reset variables that have known state during rtx generation. */
403 rtx_equal_function_value_matters = 1;
404 virtuals_instantiated = 0;
405 generating_concat_p = 1;
406 }
407
408 void
409 pop_function_context ()
410 {
411 pop_function_context_from (current_function_decl);
412 }
413
414 /* Clear out all parts of the state in F that can safely be discarded
415 after the function has been parsed, but not compiled, to let
416 garbage collection reclaim the memory. */
417
418 void
419 free_after_parsing (f)
420 struct function *f;
421 {
422 /* f->expr->forced_labels is used by code generation. */
423 /* f->emit->regno_reg_rtx is used by code generation. */
424 /* f->varasm is used by code generation. */
425 /* f->eh->eh_return_stub_label is used by code generation. */
426
427 (*lang_hooks.function.final) (f);
428 f->stmt = NULL;
429 }
430
431 /* Clear out all parts of the state in F that can safely be discarded
432 after the function has been compiled, to let garbage collection
433 reclaim the memory. */
434
435 void
436 free_after_compilation (f)
437 struct function *f;
438 {
439 f->eh = NULL;
440 f->expr = NULL;
441 f->emit = NULL;
442 f->varasm = NULL;
443 f->machine = NULL;
444
445 f->x_temp_slots = NULL;
446 f->arg_offset_rtx = NULL;
447 f->return_rtx = NULL;
448 f->internal_arg_pointer = NULL;
449 f->x_nonlocal_labels = NULL;
450 f->x_nonlocal_goto_handler_slots = NULL;
451 f->x_nonlocal_goto_handler_labels = NULL;
452 f->x_nonlocal_goto_stack_level = NULL;
453 f->x_cleanup_label = NULL;
454 f->x_return_label = NULL;
455 f->computed_goto_common_label = NULL;
456 f->computed_goto_common_reg = NULL;
457 f->x_save_expr_regs = NULL;
458 f->x_stack_slot_list = NULL;
459 f->x_rtl_expr_chain = NULL;
460 f->x_tail_recursion_label = NULL;
461 f->x_tail_recursion_reentry = NULL;
462 f->x_arg_pointer_save_area = NULL;
463 f->x_clobber_return_insn = NULL;
464 f->x_context_display = NULL;
465 f->x_trampoline_list = NULL;
466 f->x_parm_birth_insn = NULL;
467 f->x_last_parm_insn = NULL;
468 f->x_parm_reg_stack_loc = NULL;
469 f->fixup_var_refs_queue = NULL;
470 f->original_arg_vector = NULL;
471 f->original_decl_initial = NULL;
472 f->inl_last_parm_insn = NULL;
473 f->epilogue_delay_list = NULL;
474 }
475 \f
476 /* Allocate fixed slots in the stack frame of the current function. */
477
478 /* Return size needed for stack frame based on slots so far allocated in
479 function F.
480 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
481 the caller may have to do that. */
482
483 HOST_WIDE_INT
484 get_func_frame_size (f)
485 struct function *f;
486 {
487 #ifdef FRAME_GROWS_DOWNWARD
488 return -f->x_frame_offset;
489 #else
490 return f->x_frame_offset;
491 #endif
492 }
493
494 /* Return size needed for stack frame based on slots so far allocated.
495 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
496 the caller may have to do that. */
497 HOST_WIDE_INT
498 get_frame_size ()
499 {
500 return get_func_frame_size (cfun);
501 }
502
503 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
504 with machine mode MODE.
505
506 ALIGN controls the amount of alignment for the address of the slot:
507 0 means according to MODE,
508 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
509 positive specifies alignment boundary in bits.
510
511 We do not round to stack_boundary here.
512
513 FUNCTION specifies the function to allocate in. */
514
515 static rtx
516 assign_stack_local_1 (mode, size, align, function)
517 enum machine_mode mode;
518 HOST_WIDE_INT size;
519 int align;
520 struct function *function;
521 {
522 rtx x, addr;
523 int bigend_correction = 0;
524 int alignment;
525 int frame_off, frame_alignment, frame_phase;
526
527 if (align == 0)
528 {
529 tree type;
530
531 if (mode == BLKmode)
532 alignment = BIGGEST_ALIGNMENT;
533 else
534 alignment = GET_MODE_ALIGNMENT (mode);
535
536 /* Allow the target to (possibly) increase the alignment of this
537 stack slot. */
538 type = (*lang_hooks.types.type_for_mode) (mode, 0);
539 if (type)
540 alignment = LOCAL_ALIGNMENT (type, alignment);
541
542 alignment /= BITS_PER_UNIT;
543 }
544 else if (align == -1)
545 {
546 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
547 size = CEIL_ROUND (size, alignment);
548 }
549 else
550 alignment = align / BITS_PER_UNIT;
551
552 #ifdef FRAME_GROWS_DOWNWARD
553 function->x_frame_offset -= size;
554 #endif
555
556 /* Ignore alignment we can't do with expected alignment of the boundary. */
557 if (alignment * BITS_PER_UNIT > PREFERRED_STACK_BOUNDARY)
558 alignment = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
559
560 if (function->stack_alignment_needed < alignment * BITS_PER_UNIT)
561 function->stack_alignment_needed = alignment * BITS_PER_UNIT;
562
563 /* Calculate how many bytes the start of local variables is off from
564 stack alignment. */
565 frame_alignment = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
566 frame_off = STARTING_FRAME_OFFSET % frame_alignment;
567 frame_phase = frame_off ? frame_alignment - frame_off : 0;
568
569 /* Round frame offset to that alignment.
570 We must be careful here, since FRAME_OFFSET might be negative and
571 division with a negative dividend isn't as well defined as we might
572 like. So we instead assume that ALIGNMENT is a power of two and
573 use logical operations which are unambiguous. */
574 #ifdef FRAME_GROWS_DOWNWARD
575 function->x_frame_offset = FLOOR_ROUND (function->x_frame_offset - frame_phase, alignment) + frame_phase;
576 #else
577 function->x_frame_offset = CEIL_ROUND (function->x_frame_offset - frame_phase, alignment) + frame_phase;
578 #endif
579
580 /* On a big-endian machine, if we are allocating more space than we will use,
581 use the least significant bytes of those that are allocated. */
582 if (BYTES_BIG_ENDIAN && mode != BLKmode)
583 bigend_correction = size - GET_MODE_SIZE (mode);
584
585 /* If we have already instantiated virtual registers, return the actual
586 address relative to the frame pointer. */
587 if (function == cfun && virtuals_instantiated)
588 addr = plus_constant (frame_pointer_rtx,
589 (frame_offset + bigend_correction
590 + STARTING_FRAME_OFFSET));
591 else
592 addr = plus_constant (virtual_stack_vars_rtx,
593 function->x_frame_offset + bigend_correction);
594
595 #ifndef FRAME_GROWS_DOWNWARD
596 function->x_frame_offset += size;
597 #endif
598
599 x = gen_rtx_MEM (mode, addr);
600
601 function->x_stack_slot_list
602 = gen_rtx_EXPR_LIST (VOIDmode, x, function->x_stack_slot_list);
603
604 return x;
605 }
606
607 /* Wrapper around assign_stack_local_1; assign a local stack slot for the
608 current function. */
609
610 rtx
611 assign_stack_local (mode, size, align)
612 enum machine_mode mode;
613 HOST_WIDE_INT size;
614 int align;
615 {
616 return assign_stack_local_1 (mode, size, align, cfun);
617 }
618 \f
619 /* Allocate a temporary stack slot and record it for possible later
620 reuse.
621
622 MODE is the machine mode to be given to the returned rtx.
623
624 SIZE is the size in units of the space required. We do no rounding here
625 since assign_stack_local will do any required rounding.
626
627 KEEP is 1 if this slot is to be retained after a call to
628 free_temp_slots. Automatic variables for a block are allocated
629 with this flag. KEEP is 2 if we allocate a longer term temporary,
630 whose lifetime is controlled by CLEANUP_POINT_EXPRs. KEEP is 3
631 if we are to allocate something at an inner level to be treated as
632 a variable in the block (e.g., a SAVE_EXPR).
633
634 TYPE is the type that will be used for the stack slot. */
635
636 rtx
637 assign_stack_temp_for_type (mode, size, keep, type)
638 enum machine_mode mode;
639 HOST_WIDE_INT size;
640 int keep;
641 tree type;
642 {
643 unsigned int align;
644 struct temp_slot *p, *best_p = 0;
645 rtx slot;
646
647 /* If SIZE is -1 it means that somebody tried to allocate a temporary
648 of a variable size. */
649 if (size == -1)
650 abort ();
651
652 if (mode == BLKmode)
653 align = BIGGEST_ALIGNMENT;
654 else
655 align = GET_MODE_ALIGNMENT (mode);
656
657 if (! type)
658 type = (*lang_hooks.types.type_for_mode) (mode, 0);
659
660 if (type)
661 align = LOCAL_ALIGNMENT (type, align);
662
663 /* Try to find an available, already-allocated temporary of the proper
664 mode which meets the size and alignment requirements. Choose the
665 smallest one with the closest alignment. */
666 for (p = temp_slots; p; p = p->next)
667 if (p->align >= align && p->size >= size && GET_MODE (p->slot) == mode
668 && ! p->in_use
669 && objects_must_conflict_p (p->type, type)
670 && (best_p == 0 || best_p->size > p->size
671 || (best_p->size == p->size && best_p->align > p->align)))
672 {
673 if (p->align == align && p->size == size)
674 {
675 best_p = 0;
676 break;
677 }
678 best_p = p;
679 }
680
681 /* Make our best, if any, the one to use. */
682 if (best_p)
683 {
684 /* If there are enough aligned bytes left over, make them into a new
685 temp_slot so that the extra bytes don't get wasted. Do this only
686 for BLKmode slots, so that we can be sure of the alignment. */
687 if (GET_MODE (best_p->slot) == BLKmode)
688 {
689 int alignment = best_p->align / BITS_PER_UNIT;
690 HOST_WIDE_INT rounded_size = CEIL_ROUND (size, alignment);
691
692 if (best_p->size - rounded_size >= alignment)
693 {
694 p = (struct temp_slot *) ggc_alloc (sizeof (struct temp_slot));
695 p->in_use = p->addr_taken = 0;
696 p->size = best_p->size - rounded_size;
697 p->base_offset = best_p->base_offset + rounded_size;
698 p->full_size = best_p->full_size - rounded_size;
699 p->slot = gen_rtx_MEM (BLKmode,
700 plus_constant (XEXP (best_p->slot, 0),
701 rounded_size));
702 p->align = best_p->align;
703 p->address = 0;
704 p->rtl_expr = 0;
705 p->type = best_p->type;
706 p->next = temp_slots;
707 temp_slots = p;
708
709 stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, p->slot,
710 stack_slot_list);
711
712 best_p->size = rounded_size;
713 best_p->full_size = rounded_size;
714 }
715 }
716
717 p = best_p;
718 }
719
720 /* If we still didn't find one, make a new temporary. */
721 if (p == 0)
722 {
723 HOST_WIDE_INT frame_offset_old = frame_offset;
724
725 p = (struct temp_slot *) ggc_alloc (sizeof (struct temp_slot));
726
727 /* We are passing an explicit alignment request to assign_stack_local.
728 One side effect of that is assign_stack_local will not round SIZE
729 to ensure the frame offset remains suitably aligned.
730
731 So for requests which depended on the rounding of SIZE, we go ahead
732 and round it now. We also make sure ALIGNMENT is at least
733 BIGGEST_ALIGNMENT. */
734 if (mode == BLKmode && align < BIGGEST_ALIGNMENT)
735 abort ();
736 p->slot = assign_stack_local (mode,
737 (mode == BLKmode
738 ? CEIL_ROUND (size, (int) align / BITS_PER_UNIT)
739 : size),
740 align);
741
742 p->align = align;
743
744 /* The following slot size computation is necessary because we don't
745 know the actual size of the temporary slot until assign_stack_local
746 has performed all the frame alignment and size rounding for the
747 requested temporary. Note that extra space added for alignment
748 can be either above or below this stack slot depending on which
749 way the frame grows. We include the extra space if and only if it
750 is above this slot. */
751 #ifdef FRAME_GROWS_DOWNWARD
752 p->size = frame_offset_old - frame_offset;
753 #else
754 p->size = size;
755 #endif
756
757 /* Now define the fields used by combine_temp_slots. */
758 #ifdef FRAME_GROWS_DOWNWARD
759 p->base_offset = frame_offset;
760 p->full_size = frame_offset_old - frame_offset;
761 #else
762 p->base_offset = frame_offset_old;
763 p->full_size = frame_offset - frame_offset_old;
764 #endif
765 p->address = 0;
766 p->next = temp_slots;
767 temp_slots = p;
768 }
769
770 p->in_use = 1;
771 p->addr_taken = 0;
772 p->rtl_expr = seq_rtl_expr;
773 p->type = type;
774
775 if (keep == 2)
776 {
777 p->level = target_temp_slot_level;
778 p->keep = 0;
779 }
780 else if (keep == 3)
781 {
782 p->level = var_temp_slot_level;
783 p->keep = 0;
784 }
785 else
786 {
787 p->level = temp_slot_level;
788 p->keep = keep;
789 }
790
791
792 /* Create a new MEM rtx to avoid clobbering MEM flags of old slots. */
793 slot = gen_rtx_MEM (mode, XEXP (p->slot, 0));
794 stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, slot, stack_slot_list);
795
796 /* If we know the alias set for the memory that will be used, use
797 it. If there's no TYPE, then we don't know anything about the
798 alias set for the memory. */
799 set_mem_alias_set (slot, type ? get_alias_set (type) : 0);
800 set_mem_align (slot, align);
801
802 /* If a type is specified, set the relevant flags. */
803 if (type != 0)
804 {
805 RTX_UNCHANGING_P (slot) = (lang_hooks.honor_readonly
806 && TYPE_READONLY (type));
807 MEM_VOLATILE_P (slot) = TYPE_VOLATILE (type);
808 MEM_SET_IN_STRUCT_P (slot, AGGREGATE_TYPE_P (type));
809 }
810
811 return slot;
812 }
813
814 /* Allocate a temporary stack slot and record it for possible later
815 reuse. First three arguments are same as in preceding function. */
816
817 rtx
818 assign_stack_temp (mode, size, keep)
819 enum machine_mode mode;
820 HOST_WIDE_INT size;
821 int keep;
822 {
823 return assign_stack_temp_for_type (mode, size, keep, NULL_TREE);
824 }
825 \f
826 /* Assign a temporary.
827 If TYPE_OR_DECL is a decl, then we are doing it on behalf of the decl
828 and so that should be used in error messages. In either case, we
829 allocate of the given type.
830 KEEP is as for assign_stack_temp.
831 MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
832 it is 0 if a register is OK.
833 DONT_PROMOTE is 1 if we should not promote values in register
834 to wider modes. */
835
836 rtx
837 assign_temp (type_or_decl, keep, memory_required, dont_promote)
838 tree type_or_decl;
839 int keep;
840 int memory_required;
841 int dont_promote ATTRIBUTE_UNUSED;
842 {
843 tree type, decl;
844 enum machine_mode mode;
845 #ifndef PROMOTE_FOR_CALL_ONLY
846 int unsignedp;
847 #endif
848
849 if (DECL_P (type_or_decl))
850 decl = type_or_decl, type = TREE_TYPE (decl);
851 else
852 decl = NULL, type = type_or_decl;
853
854 mode = TYPE_MODE (type);
855 #ifndef PROMOTE_FOR_CALL_ONLY
856 unsignedp = TREE_UNSIGNED (type);
857 #endif
858
859 if (mode == BLKmode || memory_required)
860 {
861 HOST_WIDE_INT size = int_size_in_bytes (type);
862 rtx tmp;
863
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;
868
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);
877
878 /* The size of the temporary may be too large to fit into an integer. */
879 /* ??? Not sure this should happen except for user silliness, so limit
880 this to things that aren't compiler-generated temporaries. The
881 rest of the time we'll abort in assign_stack_temp_for_type. */
882 if (decl && size == -1
883 && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST)
884 {
885 error_with_decl (decl, "size of variable `%s' is too large");
886 size = 1;
887 }
888
889 tmp = assign_stack_temp_for_type (mode, size, keep, type);
890 return tmp;
891 }
892
893 #ifndef PROMOTE_FOR_CALL_ONLY
894 if (! dont_promote)
895 mode = promote_mode (type, mode, &unsignedp, 0);
896 #endif
897
898 return gen_reg_rtx (mode);
899 }
900 \f
901 /* Combine temporary stack slots which are adjacent on the stack.
902
903 This allows for better use of already allocated stack space. This is only
904 done for BLKmode slots because we can be sure that we won't have alignment
905 problems in this case. */
906
907 void
908 combine_temp_slots ()
909 {
910 struct temp_slot *p, *q;
911 struct temp_slot *prev_p, *prev_q;
912 int num_slots;
913
914 /* We can't combine slots, because the information about which slot
915 is in which alias set will be lost. */
916 if (flag_strict_aliasing)
917 return;
918
919 /* If there are a lot of temp slots, don't do anything unless
920 high levels of optimization. */
921 if (! flag_expensive_optimizations)
922 for (p = temp_slots, num_slots = 0; p; p = p->next, num_slots++)
923 if (num_slots > 100 || (num_slots > 10 && optimize == 0))
924 return;
925
926 for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots)
927 {
928 int delete_p = 0;
929
930 if (! p->in_use && GET_MODE (p->slot) == BLKmode)
931 for (q = p->next, prev_q = p; q; q = prev_q->next)
932 {
933 int delete_q = 0;
934 if (! q->in_use && GET_MODE (q->slot) == BLKmode)
935 {
936 if (p->base_offset + p->full_size == q->base_offset)
937 {
938 /* Q comes after P; combine Q into P. */
939 p->size += q->size;
940 p->full_size += q->full_size;
941 delete_q = 1;
942 }
943 else if (q->base_offset + q->full_size == p->base_offset)
944 {
945 /* P comes after Q; combine P into Q. */
946 q->size += p->size;
947 q->full_size += p->full_size;
948 delete_p = 1;
949 break;
950 }
951 }
952 /* Either delete Q or advance past it. */
953 if (delete_q)
954 prev_q->next = q->next;
955 else
956 prev_q = q;
957 }
958 /* Either delete P or advance past it. */
959 if (delete_p)
960 {
961 if (prev_p)
962 prev_p->next = p->next;
963 else
964 temp_slots = p->next;
965 }
966 else
967 prev_p = p;
968 }
969 }
970 \f
971 /* Find the temp slot corresponding to the object at address X. */
972
973 static struct temp_slot *
974 find_temp_slot_from_address (x)
975 rtx x;
976 {
977 struct temp_slot *p;
978 rtx next;
979
980 for (p = temp_slots; p; p = p->next)
981 {
982 if (! p->in_use)
983 continue;
984
985 else if (XEXP (p->slot, 0) == x
986 || p->address == x
987 || (GET_CODE (x) == PLUS
988 && XEXP (x, 0) == virtual_stack_vars_rtx
989 && GET_CODE (XEXP (x, 1)) == CONST_INT
990 && INTVAL (XEXP (x, 1)) >= p->base_offset
991 && INTVAL (XEXP (x, 1)) < p->base_offset + p->full_size))
992 return p;
993
994 else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST)
995 for (next = p->address; next; next = XEXP (next, 1))
996 if (XEXP (next, 0) == x)
997 return p;
998 }
999
1000 /* If we have a sum involving a register, see if it points to a temp
1001 slot. */
1002 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == REG
1003 && (p = find_temp_slot_from_address (XEXP (x, 0))) != 0)
1004 return p;
1005 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG
1006 && (p = find_temp_slot_from_address (XEXP (x, 1))) != 0)
1007 return p;
1008
1009 return 0;
1010 }
1011
1012 /* Indicate that NEW is an alternate way of referring to the temp slot
1013 that previously was known by OLD. */
1014
1015 void
1016 update_temp_slot_address (old, new)
1017 rtx old, new;
1018 {
1019 struct temp_slot *p;
1020
1021 if (rtx_equal_p (old, new))
1022 return;
1023
1024 p = find_temp_slot_from_address (old);
1025
1026 /* If we didn't find one, see if both OLD is a PLUS. If so, and NEW
1027 is a register, see if one operand of the PLUS is a temporary
1028 location. If so, NEW points into it. Otherwise, if both OLD and
1029 NEW are a PLUS and if there is a register in common between them.
1030 If so, try a recursive call on those values. */
1031 if (p == 0)
1032 {
1033 if (GET_CODE (old) != PLUS)
1034 return;
1035
1036 if (GET_CODE (new) == REG)
1037 {
1038 update_temp_slot_address (XEXP (old, 0), new);
1039 update_temp_slot_address (XEXP (old, 1), new);
1040 return;
1041 }
1042 else if (GET_CODE (new) != PLUS)
1043 return;
1044
1045 if (rtx_equal_p (XEXP (old, 0), XEXP (new, 0)))
1046 update_temp_slot_address (XEXP (old, 1), XEXP (new, 1));
1047 else if (rtx_equal_p (XEXP (old, 1), XEXP (new, 0)))
1048 update_temp_slot_address (XEXP (old, 0), XEXP (new, 1));
1049 else if (rtx_equal_p (XEXP (old, 0), XEXP (new, 1)))
1050 update_temp_slot_address (XEXP (old, 1), XEXP (new, 0));
1051 else if (rtx_equal_p (XEXP (old, 1), XEXP (new, 1)))
1052 update_temp_slot_address (XEXP (old, 0), XEXP (new, 0));
1053
1054 return;
1055 }
1056
1057 /* Otherwise add an alias for the temp's address. */
1058 else if (p->address == 0)
1059 p->address = new;
1060 else
1061 {
1062 if (GET_CODE (p->address) != EXPR_LIST)
1063 p->address = gen_rtx_EXPR_LIST (VOIDmode, p->address, NULL_RTX);
1064
1065 p->address = gen_rtx_EXPR_LIST (VOIDmode, new, p->address);
1066 }
1067 }
1068
1069 /* If X could be a reference to a temporary slot, mark the fact that its
1070 address was taken. */
1071
1072 void
1073 mark_temp_addr_taken (x)
1074 rtx x;
1075 {
1076 struct temp_slot *p;
1077
1078 if (x == 0)
1079 return;
1080
1081 /* If X is not in memory or is at a constant address, it cannot be in
1082 a temporary slot. */
1083 if (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1084 return;
1085
1086 p = find_temp_slot_from_address (XEXP (x, 0));
1087 if (p != 0)
1088 p->addr_taken = 1;
1089 }
1090
1091 /* If X could be a reference to a temporary slot, mark that slot as
1092 belonging to the to one level higher than the current level. If X
1093 matched one of our slots, just mark that one. Otherwise, we can't
1094 easily predict which it is, so upgrade all of them. Kept slots
1095 need not be touched.
1096
1097 This is called when an ({...}) construct occurs and a statement
1098 returns a value in memory. */
1099
1100 void
1101 preserve_temp_slots (x)
1102 rtx x;
1103 {
1104 struct temp_slot *p = 0;
1105
1106 /* If there is no result, we still might have some objects whose address
1107 were taken, so we need to make sure they stay around. */
1108 if (x == 0)
1109 {
1110 for (p = temp_slots; p; p = p->next)
1111 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1112 p->level--;
1113
1114 return;
1115 }
1116
1117 /* If X is a register that is being used as a pointer, see if we have
1118 a temporary slot we know it points to. To be consistent with
1119 the code below, we really should preserve all non-kept slots
1120 if we can't find a match, but that seems to be much too costly. */
1121 if (GET_CODE (x) == REG && REG_POINTER (x))
1122 p = find_temp_slot_from_address (x);
1123
1124 /* If X is not in memory or is at a constant address, it cannot be in
1125 a temporary slot, but it can contain something whose address was
1126 taken. */
1127 if (p == 0 && (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))))
1128 {
1129 for (p = temp_slots; p; p = p->next)
1130 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1131 p->level--;
1132
1133 return;
1134 }
1135
1136 /* First see if we can find a match. */
1137 if (p == 0)
1138 p = find_temp_slot_from_address (XEXP (x, 0));
1139
1140 if (p != 0)
1141 {
1142 /* Move everything at our level whose address was taken to our new
1143 level in case we used its address. */
1144 struct temp_slot *q;
1145
1146 if (p->level == temp_slot_level)
1147 {
1148 for (q = temp_slots; q; q = q->next)
1149 if (q != p && q->addr_taken && q->level == p->level)
1150 q->level--;
1151
1152 p->level--;
1153 p->addr_taken = 0;
1154 }
1155 return;
1156 }
1157
1158 /* Otherwise, preserve all non-kept slots at this level. */
1159 for (p = temp_slots; p; p = p->next)
1160 if (p->in_use && p->level == temp_slot_level && ! p->keep)
1161 p->level--;
1162 }
1163
1164 /* X is the result of an RTL_EXPR. If it is a temporary slot associated
1165 with that RTL_EXPR, promote it into a temporary slot at the present
1166 level so it will not be freed when we free slots made in the
1167 RTL_EXPR. */
1168
1169 void
1170 preserve_rtl_expr_result (x)
1171 rtx x;
1172 {
1173 struct temp_slot *p;
1174
1175 /* If X is not in memory or is at a constant address, it cannot be in
1176 a temporary slot. */
1177 if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1178 return;
1179
1180 /* If we can find a match, move it to our level unless it is already at
1181 an upper level. */
1182 p = find_temp_slot_from_address (XEXP (x, 0));
1183 if (p != 0)
1184 {
1185 p->level = MIN (p->level, temp_slot_level);
1186 p->rtl_expr = 0;
1187 }
1188
1189 return;
1190 }
1191
1192 /* Free all temporaries used so far. This is normally called at the end
1193 of generating code for a statement. Don't free any temporaries
1194 currently in use for an RTL_EXPR that hasn't yet been emitted.
1195 We could eventually do better than this since it can be reused while
1196 generating the same RTL_EXPR, but this is complex and probably not
1197 worthwhile. */
1198
1199 void
1200 free_temp_slots ()
1201 {
1202 struct temp_slot *p;
1203
1204 for (p = temp_slots; p; p = p->next)
1205 if (p->in_use && p->level == temp_slot_level && ! p->keep
1206 && p->rtl_expr == 0)
1207 p->in_use = 0;
1208
1209 combine_temp_slots ();
1210 }
1211
1212 /* Free all temporary slots used in T, an RTL_EXPR node. */
1213
1214 void
1215 free_temps_for_rtl_expr (t)
1216 tree t;
1217 {
1218 struct temp_slot *p;
1219
1220 for (p = temp_slots; p; p = p->next)
1221 if (p->rtl_expr == t)
1222 {
1223 /* If this slot is below the current TEMP_SLOT_LEVEL, then it
1224 needs to be preserved. This can happen if a temporary in
1225 the RTL_EXPR was addressed; preserve_temp_slots will move
1226 the temporary into a higher level. */
1227 if (temp_slot_level <= p->level)
1228 p->in_use = 0;
1229 else
1230 p->rtl_expr = NULL_TREE;
1231 }
1232
1233 combine_temp_slots ();
1234 }
1235
1236 /* Mark all temporaries ever allocated in this function as not suitable
1237 for reuse until the current level is exited. */
1238
1239 void
1240 mark_all_temps_used ()
1241 {
1242 struct temp_slot *p;
1243
1244 for (p = temp_slots; p; p = p->next)
1245 {
1246 p->in_use = p->keep = 1;
1247 p->level = MIN (p->level, temp_slot_level);
1248 }
1249 }
1250
1251 /* Push deeper into the nesting level for stack temporaries. */
1252
1253 void
1254 push_temp_slots ()
1255 {
1256 temp_slot_level++;
1257 }
1258
1259 /* Pop a temporary nesting level. All slots in use in the current level
1260 are freed. */
1261
1262 void
1263 pop_temp_slots ()
1264 {
1265 struct temp_slot *p;
1266
1267 for (p = temp_slots; p; p = p->next)
1268 if (p->in_use && p->level == temp_slot_level && p->rtl_expr == 0)
1269 p->in_use = 0;
1270
1271 combine_temp_slots ();
1272
1273 temp_slot_level--;
1274 }
1275
1276 /* Initialize temporary slots. */
1277
1278 void
1279 init_temp_slots ()
1280 {
1281 /* We have not allocated any temporaries yet. */
1282 temp_slots = 0;
1283 temp_slot_level = 0;
1284 var_temp_slot_level = 0;
1285 target_temp_slot_level = 0;
1286 }
1287 \f
1288 /* Retroactively move an auto variable from a register to a stack slot.
1289 This is done when an address-reference to the variable is seen. */
1290
1291 void
1292 put_var_into_stack (decl)
1293 tree decl;
1294 {
1295 rtx reg;
1296 enum machine_mode promoted_mode, decl_mode;
1297 struct function *function = 0;
1298 tree context;
1299 int can_use_addressof;
1300 int volatilep = TREE_CODE (decl) != SAVE_EXPR && TREE_THIS_VOLATILE (decl);
1301 int usedp = (TREE_USED (decl)
1302 || (TREE_CODE (decl) != SAVE_EXPR && DECL_INITIAL (decl) != 0));
1303
1304 context = decl_function_context (decl);
1305
1306 /* Get the current rtl used for this object and its original mode. */
1307 reg = (TREE_CODE (decl) == SAVE_EXPR
1308 ? SAVE_EXPR_RTL (decl)
1309 : DECL_RTL_IF_SET (decl));
1310
1311 /* No need to do anything if decl has no rtx yet
1312 since in that case caller is setting TREE_ADDRESSABLE
1313 and a stack slot will be assigned when the rtl is made. */
1314 if (reg == 0)
1315 return;
1316
1317 /* Get the declared mode for this object. */
1318 decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl))
1319 : DECL_MODE (decl));
1320 /* Get the mode it's actually stored in. */
1321 promoted_mode = GET_MODE (reg);
1322
1323 /* If this variable comes from an outer function, find that
1324 function's saved context. Don't use find_function_data here,
1325 because it might not be in any active function.
1326 FIXME: Is that really supposed to happen?
1327 It does in ObjC at least. */
1328 if (context != current_function_decl && context != inline_function_decl)
1329 for (function = outer_function_chain; function; function = function->outer)
1330 if (function->decl == context)
1331 break;
1332
1333 /* If this is a variable-size object with a pseudo to address it,
1334 put that pseudo into the stack, if the var is nonlocal. */
1335 if (TREE_CODE (decl) != SAVE_EXPR && DECL_NONLOCAL (decl)
1336 && GET_CODE (reg) == MEM
1337 && GET_CODE (XEXP (reg, 0)) == REG
1338 && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER)
1339 {
1340 reg = XEXP (reg, 0);
1341 decl_mode = promoted_mode = GET_MODE (reg);
1342 }
1343
1344 can_use_addressof
1345 = (function == 0
1346 && optimize > 0
1347 /* FIXME make it work for promoted modes too */
1348 && decl_mode == promoted_mode
1349 #ifdef NON_SAVING_SETJMP
1350 && ! (NON_SAVING_SETJMP && current_function_calls_setjmp)
1351 #endif
1352 );
1353
1354 /* If we can't use ADDRESSOF, make sure we see through one we already
1355 generated. */
1356 if (! can_use_addressof && GET_CODE (reg) == MEM
1357 && GET_CODE (XEXP (reg, 0)) == ADDRESSOF)
1358 reg = XEXP (XEXP (reg, 0), 0);
1359
1360 /* Now we should have a value that resides in one or more pseudo regs. */
1361
1362 if (GET_CODE (reg) == REG)
1363 {
1364 /* If this variable lives in the current function and we don't need
1365 to put things in the stack for the sake of setjmp, try to keep it
1366 in a register until we know we actually need the address. */
1367 if (can_use_addressof)
1368 gen_mem_addressof (reg, decl);
1369 else
1370 put_reg_into_stack (function, reg, TREE_TYPE (decl), promoted_mode,
1371 decl_mode, volatilep, 0, usedp, 0);
1372 }
1373 else if (GET_CODE (reg) == CONCAT)
1374 {
1375 /* A CONCAT contains two pseudos; put them both in the stack.
1376 We do it so they end up consecutive.
1377 We fixup references to the parts only after we fixup references
1378 to the whole CONCAT, lest we do double fixups for the latter
1379 references. */
1380 enum machine_mode part_mode = GET_MODE (XEXP (reg, 0));
1381 tree part_type = (*lang_hooks.types.type_for_mode) (part_mode, 0);
1382 rtx lopart = XEXP (reg, 0);
1383 rtx hipart = XEXP (reg, 1);
1384 #ifdef FRAME_GROWS_DOWNWARD
1385 /* Since part 0 should have a lower address, do it second. */
1386 put_reg_into_stack (function, hipart, part_type, part_mode,
1387 part_mode, volatilep, 0, 0, 0);
1388 put_reg_into_stack (function, lopart, part_type, part_mode,
1389 part_mode, volatilep, 0, 0, 0);
1390 #else
1391 put_reg_into_stack (function, lopart, part_type, part_mode,
1392 part_mode, volatilep, 0, 0, 0);
1393 put_reg_into_stack (function, hipart, part_type, part_mode,
1394 part_mode, volatilep, 0, 0, 0);
1395 #endif
1396
1397 /* Change the CONCAT into a combined MEM for both parts. */
1398 PUT_CODE (reg, MEM);
1399 MEM_ATTRS (reg) = 0;
1400
1401 /* set_mem_attributes uses DECL_RTL to avoid re-generating of
1402 already computed alias sets. Here we want to re-generate. */
1403 if (DECL_P (decl))
1404 SET_DECL_RTL (decl, NULL);
1405 set_mem_attributes (reg, decl, 1);
1406 if (DECL_P (decl))
1407 SET_DECL_RTL (decl, reg);
1408
1409 /* The two parts are in memory order already.
1410 Use the lower parts address as ours. */
1411 XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0);
1412 /* Prevent sharing of rtl that might lose. */
1413 if (GET_CODE (XEXP (reg, 0)) == PLUS)
1414 XEXP (reg, 0) = copy_rtx (XEXP (reg, 0));
1415 if (usedp)
1416 {
1417 schedule_fixup_var_refs (function, reg, TREE_TYPE (decl),
1418 promoted_mode, 0);
1419 schedule_fixup_var_refs (function, lopart, part_type, part_mode, 0);
1420 schedule_fixup_var_refs (function, hipart, part_type, part_mode, 0);
1421 }
1422 }
1423 else
1424 return;
1425 }
1426
1427 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1428 into the stack frame of FUNCTION (0 means the current function).
1429 DECL_MODE is the machine mode of the user-level data type.
1430 PROMOTED_MODE is the machine mode of the register.
1431 VOLATILE_P is nonzero if this is for a "volatile" decl.
1432 USED_P is nonzero if this reg might have already been used in an insn. */
1433
1434 static void
1435 put_reg_into_stack (function, reg, type, promoted_mode, decl_mode, volatile_p,
1436 original_regno, used_p, ht)
1437 struct function *function;
1438 rtx reg;
1439 tree type;
1440 enum machine_mode promoted_mode, decl_mode;
1441 int volatile_p;
1442 unsigned int original_regno;
1443 int used_p;
1444 htab_t ht;
1445 {
1446 struct function *func = function ? function : cfun;
1447 rtx new = 0;
1448 unsigned int regno = original_regno;
1449
1450 if (regno == 0)
1451 regno = REGNO (reg);
1452
1453 if (regno < func->x_max_parm_reg)
1454 new = func->x_parm_reg_stack_loc[regno];
1455
1456 if (new == 0)
1457 new = assign_stack_local_1 (decl_mode, GET_MODE_SIZE (decl_mode), 0, func);
1458
1459 PUT_CODE (reg, MEM);
1460 PUT_MODE (reg, decl_mode);
1461 XEXP (reg, 0) = XEXP (new, 0);
1462 MEM_ATTRS (reg) = 0;
1463 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
1464 MEM_VOLATILE_P (reg) = volatile_p;
1465
1466 /* If this is a memory ref that contains aggregate components,
1467 mark it as such for cse and loop optimize. If we are reusing a
1468 previously generated stack slot, then we need to copy the bit in
1469 case it was set for other reasons. For instance, it is set for
1470 __builtin_va_alist. */
1471 if (type)
1472 {
1473 MEM_SET_IN_STRUCT_P (reg,
1474 AGGREGATE_TYPE_P (type) || MEM_IN_STRUCT_P (new));
1475 set_mem_alias_set (reg, get_alias_set (type));
1476 }
1477
1478 if (used_p)
1479 schedule_fixup_var_refs (function, reg, type, promoted_mode, ht);
1480 }
1481
1482 /* Make sure that all refs to the variable, previously made
1483 when it was a register, are fixed up to be valid again.
1484 See function above for meaning of arguments. */
1485
1486 static void
1487 schedule_fixup_var_refs (function, reg, type, promoted_mode, ht)
1488 struct function *function;
1489 rtx reg;
1490 tree type;
1491 enum machine_mode promoted_mode;
1492 htab_t ht;
1493 {
1494 int unsigned_p = type ? TREE_UNSIGNED (type) : 0;
1495
1496 if (function != 0)
1497 {
1498 struct var_refs_queue *temp;
1499
1500 temp
1501 = (struct var_refs_queue *) ggc_alloc (sizeof (struct var_refs_queue));
1502 temp->modified = reg;
1503 temp->promoted_mode = promoted_mode;
1504 temp->unsignedp = unsigned_p;
1505 temp->next = function->fixup_var_refs_queue;
1506 function->fixup_var_refs_queue = temp;
1507 }
1508 else
1509 /* Variable is local; fix it up now. */
1510 fixup_var_refs (reg, promoted_mode, unsigned_p, reg, ht);
1511 }
1512 \f
1513 static void
1514 fixup_var_refs (var, promoted_mode, unsignedp, may_share, ht)
1515 rtx var;
1516 enum machine_mode promoted_mode;
1517 int unsignedp;
1518 htab_t ht;
1519 rtx may_share;
1520 {
1521 tree pending;
1522 rtx first_insn = get_insns ();
1523 struct sequence_stack *stack = seq_stack;
1524 tree rtl_exps = rtl_expr_chain;
1525
1526 /* If there's a hash table, it must record all uses of VAR. */
1527 if (ht)
1528 {
1529 if (stack != 0)
1530 abort ();
1531 fixup_var_refs_insns_with_hash (ht, var, promoted_mode, unsignedp,
1532 may_share);
1533 return;
1534 }
1535
1536 fixup_var_refs_insns (first_insn, var, promoted_mode, unsignedp,
1537 stack == 0, may_share);
1538
1539 /* Scan all pending sequences too. */
1540 for (; stack; stack = stack->next)
1541 {
1542 push_to_full_sequence (stack->first, stack->last);
1543 fixup_var_refs_insns (stack->first, var, promoted_mode, unsignedp,
1544 stack->next != 0, may_share);
1545 /* Update remembered end of sequence
1546 in case we added an insn at the end. */
1547 stack->last = get_last_insn ();
1548 end_sequence ();
1549 }
1550
1551 /* Scan all waiting RTL_EXPRs too. */
1552 for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending))
1553 {
1554 rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
1555 if (seq != const0_rtx && seq != 0)
1556 {
1557 push_to_sequence (seq);
1558 fixup_var_refs_insns (seq, var, promoted_mode, unsignedp, 0,
1559 may_share);
1560 end_sequence ();
1561 }
1562 }
1563 }
1564 \f
1565 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
1566 some part of an insn. Return a struct fixup_replacement whose OLD
1567 value is equal to X. Allocate a new structure if no such entry exists. */
1568
1569 static struct fixup_replacement *
1570 find_fixup_replacement (replacements, x)
1571 struct fixup_replacement **replacements;
1572 rtx x;
1573 {
1574 struct fixup_replacement *p;
1575
1576 /* See if we have already replaced this. */
1577 for (p = *replacements; p != 0 && ! rtx_equal_p (p->old, x); p = p->next)
1578 ;
1579
1580 if (p == 0)
1581 {
1582 p = (struct fixup_replacement *) xmalloc (sizeof (struct fixup_replacement));
1583 p->old = x;
1584 p->new = 0;
1585 p->next = *replacements;
1586 *replacements = p;
1587 }
1588
1589 return p;
1590 }
1591
1592 /* Scan the insn-chain starting with INSN for refs to VAR and fix them
1593 up. TOPLEVEL is nonzero if this chain is the main chain of insns
1594 for the current function. MAY_SHARE is either a MEM that is not
1595 to be unshared or a list of them. */
1596
1597 static void
1598 fixup_var_refs_insns (insn, var, promoted_mode, unsignedp, toplevel, may_share)
1599 rtx insn;
1600 rtx var;
1601 enum machine_mode promoted_mode;
1602 int unsignedp;
1603 int toplevel;
1604 rtx may_share;
1605 {
1606 while (insn)
1607 {
1608 /* fixup_var_refs_insn might modify insn, so save its next
1609 pointer now. */
1610 rtx next = NEXT_INSN (insn);
1611
1612 /* CALL_PLACEHOLDERs are special; we have to switch into each of
1613 the three sequences they (potentially) contain, and process
1614 them recursively. The CALL_INSN itself is not interesting. */
1615
1616 if (GET_CODE (insn) == CALL_INSN
1617 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
1618 {
1619 int i;
1620
1621 /* Look at the Normal call, sibling call and tail recursion
1622 sequences attached to the CALL_PLACEHOLDER. */
1623 for (i = 0; i < 3; i++)
1624 {
1625 rtx seq = XEXP (PATTERN (insn), i);
1626 if (seq)
1627 {
1628 push_to_sequence (seq);
1629 fixup_var_refs_insns (seq, var, promoted_mode, unsignedp, 0,
1630 may_share);
1631 XEXP (PATTERN (insn), i) = get_insns ();
1632 end_sequence ();
1633 }
1634 }
1635 }
1636
1637 else if (INSN_P (insn))
1638 fixup_var_refs_insn (insn, var, promoted_mode, unsignedp, toplevel,
1639 may_share);
1640
1641 insn = next;
1642 }
1643 }
1644
1645 /* Look up the insns which reference VAR in HT and fix them up. Other
1646 arguments are the same as fixup_var_refs_insns.
1647
1648 N.B. No need for special processing of CALL_PLACEHOLDERs here,
1649 because the hash table will point straight to the interesting insn
1650 (inside the CALL_PLACEHOLDER). */
1651
1652 static void
1653 fixup_var_refs_insns_with_hash (ht, var, promoted_mode, unsignedp, may_share)
1654 htab_t ht;
1655 rtx var;
1656 enum machine_mode promoted_mode;
1657 int unsignedp;
1658 rtx may_share;
1659 {
1660 struct insns_for_mem_entry tmp;
1661 struct insns_for_mem_entry *ime;
1662 rtx insn_list;
1663
1664 tmp.key = var;
1665 ime = (struct insns_for_mem_entry *) htab_find (ht, &tmp);
1666 for (insn_list = ime->insns; insn_list != 0; insn_list = XEXP (insn_list, 1))
1667 if (INSN_P (XEXP (insn_list, 0)))
1668 fixup_var_refs_insn (XEXP (insn_list, 0), var, promoted_mode,
1669 unsignedp, 1, may_share);
1670 }
1671
1672
1673 /* Per-insn processing by fixup_var_refs_insns(_with_hash). INSN is
1674 the insn under examination, VAR is the variable to fix up
1675 references to, PROMOTED_MODE and UNSIGNEDP describe VAR, and
1676 TOPLEVEL is nonzero if this is the main insn chain for this
1677 function. */
1678
1679 static void
1680 fixup_var_refs_insn (insn, var, promoted_mode, unsignedp, toplevel, no_share)
1681 rtx insn;
1682 rtx var;
1683 enum machine_mode promoted_mode;
1684 int unsignedp;
1685 int toplevel;
1686 rtx no_share;
1687 {
1688 rtx call_dest = 0;
1689 rtx set, prev, prev_set;
1690 rtx note;
1691
1692 /* Remember the notes in case we delete the insn. */
1693 note = REG_NOTES (insn);
1694
1695 /* If this is a CLOBBER of VAR, delete it.
1696
1697 If it has a REG_LIBCALL note, delete the REG_LIBCALL
1698 and REG_RETVAL notes too. */
1699 if (GET_CODE (PATTERN (insn)) == CLOBBER
1700 && (XEXP (PATTERN (insn), 0) == var
1701 || (GET_CODE (XEXP (PATTERN (insn), 0)) == CONCAT
1702 && (XEXP (XEXP (PATTERN (insn), 0), 0) == var
1703 || XEXP (XEXP (PATTERN (insn), 0), 1) == var))))
1704 {
1705 if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX)) != 0)
1706 /* The REG_LIBCALL note will go away since we are going to
1707 turn INSN into a NOTE, so just delete the
1708 corresponding REG_RETVAL note. */
1709 remove_note (XEXP (note, 0),
1710 find_reg_note (XEXP (note, 0), REG_RETVAL,
1711 NULL_RTX));
1712
1713 delete_insn (insn);
1714 }
1715
1716 /* The insn to load VAR from a home in the arglist
1717 is now a no-op. When we see it, just delete it.
1718 Similarly if this is storing VAR from a register from which
1719 it was loaded in the previous insn. This will occur
1720 when an ADDRESSOF was made for an arglist slot. */
1721 else if (toplevel
1722 && (set = single_set (insn)) != 0
1723 && SET_DEST (set) == var
1724 /* If this represents the result of an insn group,
1725 don't delete the insn. */
1726 && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0
1727 && (rtx_equal_p (SET_SRC (set), var)
1728 || (GET_CODE (SET_SRC (set)) == REG
1729 && (prev = prev_nonnote_insn (insn)) != 0
1730 && (prev_set = single_set (prev)) != 0
1731 && SET_DEST (prev_set) == SET_SRC (set)
1732 && rtx_equal_p (SET_SRC (prev_set), var))))
1733 {
1734 delete_insn (insn);
1735 }
1736 else
1737 {
1738 struct fixup_replacement *replacements = 0;
1739 rtx next_insn = NEXT_INSN (insn);
1740
1741 if (SMALL_REGISTER_CLASSES)
1742 {
1743 /* If the insn that copies the results of a CALL_INSN
1744 into a pseudo now references VAR, we have to use an
1745 intermediate pseudo since we want the life of the
1746 return value register to be only a single insn.
1747
1748 If we don't use an intermediate pseudo, such things as
1749 address computations to make the address of VAR valid
1750 if it is not can be placed between the CALL_INSN and INSN.
1751
1752 To make sure this doesn't happen, we record the destination
1753 of the CALL_INSN and see if the next insn uses both that
1754 and VAR. */
1755
1756 if (call_dest != 0 && GET_CODE (insn) == INSN
1757 && reg_mentioned_p (var, PATTERN (insn))
1758 && reg_mentioned_p (call_dest, PATTERN (insn)))
1759 {
1760 rtx temp = gen_reg_rtx (GET_MODE (call_dest));
1761
1762 emit_insn_before (gen_move_insn (temp, call_dest), insn);
1763
1764 PATTERN (insn) = replace_rtx (PATTERN (insn),
1765 call_dest, temp);
1766 }
1767
1768 if (GET_CODE (insn) == CALL_INSN
1769 && GET_CODE (PATTERN (insn)) == SET)
1770 call_dest = SET_DEST (PATTERN (insn));
1771 else if (GET_CODE (insn) == CALL_INSN
1772 && GET_CODE (PATTERN (insn)) == PARALLEL
1773 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
1774 call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
1775 else
1776 call_dest = 0;
1777 }
1778
1779 /* See if we have to do anything to INSN now that VAR is in
1780 memory. If it needs to be loaded into a pseudo, use a single
1781 pseudo for the entire insn in case there is a MATCH_DUP
1782 between two operands. We pass a pointer to the head of
1783 a list of struct fixup_replacements. If fixup_var_refs_1
1784 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1785 it will record them in this list.
1786
1787 If it allocated a pseudo for any replacement, we copy into
1788 it here. */
1789
1790 fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn,
1791 &replacements, no_share);
1792
1793 /* If this is last_parm_insn, and any instructions were output
1794 after it to fix it up, then we must set last_parm_insn to
1795 the last such instruction emitted. */
1796 if (insn == last_parm_insn)
1797 last_parm_insn = PREV_INSN (next_insn);
1798
1799 while (replacements)
1800 {
1801 struct fixup_replacement *next;
1802
1803 if (GET_CODE (replacements->new) == REG)
1804 {
1805 rtx insert_before;
1806 rtx seq;
1807
1808 /* OLD might be a (subreg (mem)). */
1809 if (GET_CODE (replacements->old) == SUBREG)
1810 replacements->old
1811 = fixup_memory_subreg (replacements->old, insn,
1812 promoted_mode, 0);
1813 else
1814 replacements->old
1815 = fixup_stack_1 (replacements->old, insn);
1816
1817 insert_before = insn;
1818
1819 /* If we are changing the mode, do a conversion.
1820 This might be wasteful, but combine.c will
1821 eliminate much of the waste. */
1822
1823 if (GET_MODE (replacements->new)
1824 != GET_MODE (replacements->old))
1825 {
1826 start_sequence ();
1827 convert_move (replacements->new,
1828 replacements->old, unsignedp);
1829 seq = get_insns ();
1830 end_sequence ();
1831 }
1832 else
1833 seq = gen_move_insn (replacements->new,
1834 replacements->old);
1835
1836 emit_insn_before (seq, insert_before);
1837 }
1838
1839 next = replacements->next;
1840 free (replacements);
1841 replacements = next;
1842 }
1843 }
1844
1845 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
1846 But don't touch other insns referred to by reg-notes;
1847 we will get them elsewhere. */
1848 while (note)
1849 {
1850 if (GET_CODE (note) != INSN_LIST)
1851 XEXP (note, 0)
1852 = walk_fixup_memory_subreg (XEXP (note, 0), insn,
1853 promoted_mode, 1);
1854 note = XEXP (note, 1);
1855 }
1856 }
1857 \f
1858 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
1859 See if the rtx expression at *LOC in INSN needs to be changed.
1860
1861 REPLACEMENTS is a pointer to a list head that starts out zero, but may
1862 contain a list of original rtx's and replacements. If we find that we need
1863 to modify this insn by replacing a memory reference with a pseudo or by
1864 making a new MEM to implement a SUBREG, we consult that list to see if
1865 we have already chosen a replacement. If none has already been allocated,
1866 we allocate it and update the list. fixup_var_refs_insn will copy VAR
1867 or the SUBREG, as appropriate, to the pseudo. */
1868
1869 static void
1870 fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements, no_share)
1871 rtx var;
1872 enum machine_mode promoted_mode;
1873 rtx *loc;
1874 rtx insn;
1875 struct fixup_replacement **replacements;
1876 rtx no_share;
1877 {
1878 int i;
1879 rtx x = *loc;
1880 RTX_CODE code = GET_CODE (x);
1881 const char *fmt;
1882 rtx tem, tem1;
1883 struct fixup_replacement *replacement;
1884
1885 switch (code)
1886 {
1887 case ADDRESSOF:
1888 if (XEXP (x, 0) == var)
1889 {
1890 /* Prevent sharing of rtl that might lose. */
1891 rtx sub = copy_rtx (XEXP (var, 0));
1892
1893 if (! validate_change (insn, loc, sub, 0))
1894 {
1895 rtx y = gen_reg_rtx (GET_MODE (sub));
1896 rtx seq, new_insn;
1897
1898 /* We should be able to replace with a register or all is lost.
1899 Note that we can't use validate_change to verify this, since
1900 we're not caring for replacing all dups simultaneously. */
1901 if (! validate_replace_rtx (*loc, y, insn))
1902 abort ();
1903
1904 /* Careful! First try to recognize a direct move of the
1905 value, mimicking how things are done in gen_reload wrt
1906 PLUS. Consider what happens when insn is a conditional
1907 move instruction and addsi3 clobbers flags. */
1908
1909 start_sequence ();
1910 new_insn = emit_insn (gen_rtx_SET (VOIDmode, y, sub));
1911 seq = get_insns ();
1912 end_sequence ();
1913
1914 if (recog_memoized (new_insn) < 0)
1915 {
1916 /* That failed. Fall back on force_operand and hope. */
1917
1918 start_sequence ();
1919 sub = force_operand (sub, y);
1920 if (sub != y)
1921 emit_insn (gen_move_insn (y, sub));
1922 seq = get_insns ();
1923 end_sequence ();
1924 }
1925
1926 #ifdef HAVE_cc0
1927 /* Don't separate setter from user. */
1928 if (PREV_INSN (insn) && sets_cc0_p (PREV_INSN (insn)))
1929 insn = PREV_INSN (insn);
1930 #endif
1931
1932 emit_insn_before (seq, insn);
1933 }
1934 }
1935 return;
1936
1937 case MEM:
1938 if (var == x)
1939 {
1940 /* If we already have a replacement, use it. Otherwise,
1941 try to fix up this address in case it is invalid. */
1942
1943 replacement = find_fixup_replacement (replacements, var);
1944 if (replacement->new)
1945 {
1946 *loc = replacement->new;
1947 return;
1948 }
1949
1950 *loc = replacement->new = x = fixup_stack_1 (x, insn);
1951
1952 /* Unless we are forcing memory to register or we changed the mode,
1953 we can leave things the way they are if the insn is valid. */
1954
1955 INSN_CODE (insn) = -1;
1956 if (! flag_force_mem && GET_MODE (x) == promoted_mode
1957 && recog_memoized (insn) >= 0)
1958 return;
1959
1960 *loc = replacement->new = gen_reg_rtx (promoted_mode);
1961 return;
1962 }
1963
1964 /* If X contains VAR, we need to unshare it here so that we update
1965 each occurrence separately. But all identical MEMs in one insn
1966 must be replaced with the same rtx because of the possibility of
1967 MATCH_DUPs. */
1968
1969 if (reg_mentioned_p (var, x))
1970 {
1971 replacement = find_fixup_replacement (replacements, x);
1972 if (replacement->new == 0)
1973 replacement->new = copy_most_rtx (x, no_share);
1974
1975 *loc = x = replacement->new;
1976 code = GET_CODE (x);
1977 }
1978 break;
1979
1980 case REG:
1981 case CC0:
1982 case PC:
1983 case CONST_INT:
1984 case CONST:
1985 case SYMBOL_REF:
1986 case LABEL_REF:
1987 case CONST_DOUBLE:
1988 case CONST_VECTOR:
1989 return;
1990
1991 case SIGN_EXTRACT:
1992 case ZERO_EXTRACT:
1993 /* Note that in some cases those types of expressions are altered
1994 by optimize_bit_field, and do not survive to get here. */
1995 if (XEXP (x, 0) == var
1996 || (GET_CODE (XEXP (x, 0)) == SUBREG
1997 && SUBREG_REG (XEXP (x, 0)) == var))
1998 {
1999 /* Get TEM as a valid MEM in the mode presently in the insn.
2000
2001 We don't worry about the possibility of MATCH_DUP here; it
2002 is highly unlikely and would be tricky to handle. */
2003
2004 tem = XEXP (x, 0);
2005 if (GET_CODE (tem) == SUBREG)
2006 {
2007 if (GET_MODE_BITSIZE (GET_MODE (tem))
2008 > GET_MODE_BITSIZE (GET_MODE (var)))
2009 {
2010 replacement = find_fixup_replacement (replacements, var);
2011 if (replacement->new == 0)
2012 replacement->new = gen_reg_rtx (GET_MODE (var));
2013 SUBREG_REG (tem) = replacement->new;
2014
2015 /* The following code works only if we have a MEM, so we
2016 need to handle the subreg here. We directly substitute
2017 it assuming that a subreg must be OK here. We already
2018 scheduled a replacement to copy the mem into the
2019 subreg. */
2020 XEXP (x, 0) = tem;
2021 return;
2022 }
2023 else
2024 tem = fixup_memory_subreg (tem, insn, promoted_mode, 0);
2025 }
2026 else
2027 tem = fixup_stack_1 (tem, insn);
2028
2029 /* Unless we want to load from memory, get TEM into the proper mode
2030 for an extract from memory. This can only be done if the
2031 extract is at a constant position and length. */
2032
2033 if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT
2034 && GET_CODE (XEXP (x, 2)) == CONST_INT
2035 && ! mode_dependent_address_p (XEXP (tem, 0))
2036 && ! MEM_VOLATILE_P (tem))
2037 {
2038 enum machine_mode wanted_mode = VOIDmode;
2039 enum machine_mode is_mode = GET_MODE (tem);
2040 HOST_WIDE_INT pos = INTVAL (XEXP (x, 2));
2041
2042 if (GET_CODE (x) == ZERO_EXTRACT)
2043 {
2044 enum machine_mode new_mode
2045 = mode_for_extraction (EP_extzv, 1);
2046 if (new_mode != MAX_MACHINE_MODE)
2047 wanted_mode = new_mode;
2048 }
2049 else if (GET_CODE (x) == SIGN_EXTRACT)
2050 {
2051 enum machine_mode new_mode
2052 = mode_for_extraction (EP_extv, 1);
2053 if (new_mode != MAX_MACHINE_MODE)
2054 wanted_mode = new_mode;
2055 }
2056
2057 /* If we have a narrower mode, we can do something. */
2058 if (wanted_mode != VOIDmode
2059 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
2060 {
2061 HOST_WIDE_INT offset = pos / BITS_PER_UNIT;
2062 rtx old_pos = XEXP (x, 2);
2063 rtx newmem;
2064
2065 /* If the bytes and bits are counted differently, we
2066 must adjust the offset. */
2067 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
2068 offset = (GET_MODE_SIZE (is_mode)
2069 - GET_MODE_SIZE (wanted_mode) - offset);
2070
2071 pos %= GET_MODE_BITSIZE (wanted_mode);
2072
2073 newmem = adjust_address_nv (tem, wanted_mode, offset);
2074
2075 /* Make the change and see if the insn remains valid. */
2076 INSN_CODE (insn) = -1;
2077 XEXP (x, 0) = newmem;
2078 XEXP (x, 2) = GEN_INT (pos);
2079
2080 if (recog_memoized (insn) >= 0)
2081 return;
2082
2083 /* Otherwise, restore old position. XEXP (x, 0) will be
2084 restored later. */
2085 XEXP (x, 2) = old_pos;
2086 }
2087 }
2088
2089 /* If we get here, the bitfield extract insn can't accept a memory
2090 reference. Copy the input into a register. */
2091
2092 tem1 = gen_reg_rtx (GET_MODE (tem));
2093 emit_insn_before (gen_move_insn (tem1, tem), insn);
2094 XEXP (x, 0) = tem1;
2095 return;
2096 }
2097 break;
2098
2099 case SUBREG:
2100 if (SUBREG_REG (x) == var)
2101 {
2102 /* If this is a special SUBREG made because VAR was promoted
2103 from a wider mode, replace it with VAR and call ourself
2104 recursively, this time saying that the object previously
2105 had its current mode (by virtue of the SUBREG). */
2106
2107 if (SUBREG_PROMOTED_VAR_P (x))
2108 {
2109 *loc = var;
2110 fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements,
2111 no_share);
2112 return;
2113 }
2114
2115 /* If this SUBREG makes VAR wider, it has become a paradoxical
2116 SUBREG with VAR in memory, but these aren't allowed at this
2117 stage of the compilation. So load VAR into a pseudo and take
2118 a SUBREG of that pseudo. */
2119 if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var)))
2120 {
2121 replacement = find_fixup_replacement (replacements, var);
2122 if (replacement->new == 0)
2123 replacement->new = gen_reg_rtx (promoted_mode);
2124 SUBREG_REG (x) = replacement->new;
2125 return;
2126 }
2127
2128 /* See if we have already found a replacement for this SUBREG.
2129 If so, use it. Otherwise, make a MEM and see if the insn
2130 is recognized. If not, or if we should force MEM into a register,
2131 make a pseudo for this SUBREG. */
2132 replacement = find_fixup_replacement (replacements, x);
2133 if (replacement->new)
2134 {
2135 *loc = replacement->new;
2136 return;
2137 }
2138
2139 replacement->new = *loc = fixup_memory_subreg (x, insn,
2140 promoted_mode, 0);
2141
2142 INSN_CODE (insn) = -1;
2143 if (! flag_force_mem && recog_memoized (insn) >= 0)
2144 return;
2145
2146 *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
2147 return;
2148 }
2149 break;
2150
2151 case SET:
2152 /* First do special simplification of bit-field references. */
2153 if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
2154 || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
2155 optimize_bit_field (x, insn, 0);
2156 if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
2157 || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
2158 optimize_bit_field (x, insn, 0);
2159
2160 /* For a paradoxical SUBREG inside a ZERO_EXTRACT, load the object
2161 into a register and then store it back out. */
2162 if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT
2163 && GET_CODE (XEXP (SET_DEST (x), 0)) == SUBREG
2164 && SUBREG_REG (XEXP (SET_DEST (x), 0)) == var
2165 && (GET_MODE_SIZE (GET_MODE (XEXP (SET_DEST (x), 0)))
2166 > GET_MODE_SIZE (GET_MODE (var))))
2167 {
2168 replacement = find_fixup_replacement (replacements, var);
2169 if (replacement->new == 0)
2170 replacement->new = gen_reg_rtx (GET_MODE (var));
2171
2172 SUBREG_REG (XEXP (SET_DEST (x), 0)) = replacement->new;
2173 emit_insn_after (gen_move_insn (var, replacement->new), insn);
2174 }
2175
2176 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
2177 insn into a pseudo and store the low part of the pseudo into VAR. */
2178 if (GET_CODE (SET_DEST (x)) == SUBREG
2179 && SUBREG_REG (SET_DEST (x)) == var
2180 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
2181 > GET_MODE_SIZE (GET_MODE (var))))
2182 {
2183 SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x)));
2184 emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var),
2185 tem)),
2186 insn);
2187 break;
2188 }
2189
2190 {
2191 rtx dest = SET_DEST (x);
2192 rtx src = SET_SRC (x);
2193 rtx outerdest = dest;
2194
2195 while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
2196 || GET_CODE (dest) == SIGN_EXTRACT
2197 || GET_CODE (dest) == ZERO_EXTRACT)
2198 dest = XEXP (dest, 0);
2199
2200 if (GET_CODE (src) == SUBREG)
2201 src = SUBREG_REG (src);
2202
2203 /* If VAR does not appear at the top level of the SET
2204 just scan the lower levels of the tree. */
2205
2206 if (src != var && dest != var)
2207 break;
2208
2209 /* We will need to rerecognize this insn. */
2210 INSN_CODE (insn) = -1;
2211
2212 if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var
2213 && mode_for_extraction (EP_insv, -1) != MAX_MACHINE_MODE)
2214 {
2215 /* Since this case will return, ensure we fixup all the
2216 operands here. */
2217 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1),
2218 insn, replacements, no_share);
2219 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2),
2220 insn, replacements, no_share);
2221 fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x),
2222 insn, replacements, no_share);
2223
2224 tem = XEXP (outerdest, 0);
2225
2226 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
2227 that may appear inside a ZERO_EXTRACT.
2228 This was legitimate when the MEM was a REG. */
2229 if (GET_CODE (tem) == SUBREG
2230 && SUBREG_REG (tem) == var)
2231 tem = fixup_memory_subreg (tem, insn, promoted_mode, 0);
2232 else
2233 tem = fixup_stack_1 (tem, insn);
2234
2235 if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT
2236 && GET_CODE (XEXP (outerdest, 2)) == CONST_INT
2237 && ! mode_dependent_address_p (XEXP (tem, 0))
2238 && ! MEM_VOLATILE_P (tem))
2239 {
2240 enum machine_mode wanted_mode;
2241 enum machine_mode is_mode = GET_MODE (tem);
2242 HOST_WIDE_INT pos = INTVAL (XEXP (outerdest, 2));
2243
2244 wanted_mode = mode_for_extraction (EP_insv, 0);
2245
2246 /* If we have a narrower mode, we can do something. */
2247 if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
2248 {
2249 HOST_WIDE_INT offset = pos / BITS_PER_UNIT;
2250 rtx old_pos = XEXP (outerdest, 2);
2251 rtx newmem;
2252
2253 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
2254 offset = (GET_MODE_SIZE (is_mode)
2255 - GET_MODE_SIZE (wanted_mode) - offset);
2256
2257 pos %= GET_MODE_BITSIZE (wanted_mode);
2258
2259 newmem = adjust_address_nv (tem, wanted_mode, offset);
2260
2261 /* Make the change and see if the insn remains valid. */
2262 INSN_CODE (insn) = -1;
2263 XEXP (outerdest, 0) = newmem;
2264 XEXP (outerdest, 2) = GEN_INT (pos);
2265
2266 if (recog_memoized (insn) >= 0)
2267 return;
2268
2269 /* Otherwise, restore old position. XEXP (x, 0) will be
2270 restored later. */
2271 XEXP (outerdest, 2) = old_pos;
2272 }
2273 }
2274
2275 /* If we get here, the bit-field store doesn't allow memory
2276 or isn't located at a constant position. Load the value into
2277 a register, do the store, and put it back into memory. */
2278
2279 tem1 = gen_reg_rtx (GET_MODE (tem));
2280 emit_insn_before (gen_move_insn (tem1, tem), insn);
2281 emit_insn_after (gen_move_insn (tem, tem1), insn);
2282 XEXP (outerdest, 0) = tem1;
2283 return;
2284 }
2285
2286 /* STRICT_LOW_PART is a no-op on memory references
2287 and it can cause combinations to be unrecognizable,
2288 so eliminate it. */
2289
2290 if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
2291 SET_DEST (x) = XEXP (SET_DEST (x), 0);
2292
2293 /* A valid insn to copy VAR into or out of a register
2294 must be left alone, to avoid an infinite loop here.
2295 If the reference to VAR is by a subreg, fix that up,
2296 since SUBREG is not valid for a memref.
2297 Also fix up the address of the stack slot.
2298
2299 Note that we must not try to recognize the insn until
2300 after we know that we have valid addresses and no
2301 (subreg (mem ...) ...) constructs, since these interfere
2302 with determining the validity of the insn. */
2303
2304 if ((SET_SRC (x) == var
2305 || (GET_CODE (SET_SRC (x)) == SUBREG
2306 && SUBREG_REG (SET_SRC (x)) == var))
2307 && (GET_CODE (SET_DEST (x)) == REG
2308 || (GET_CODE (SET_DEST (x)) == SUBREG
2309 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
2310 && GET_MODE (var) == promoted_mode
2311 && x == single_set (insn))
2312 {
2313 rtx pat, last;
2314
2315 if (GET_CODE (SET_SRC (x)) == SUBREG
2316 && (GET_MODE_SIZE (GET_MODE (SET_SRC (x)))
2317 > GET_MODE_SIZE (GET_MODE (var))))
2318 {
2319 /* This (subreg VAR) is now a paradoxical subreg. We need
2320 to replace VAR instead of the subreg. */
2321 replacement = find_fixup_replacement (replacements, var);
2322 if (replacement->new == NULL_RTX)
2323 replacement->new = gen_reg_rtx (GET_MODE (var));
2324 SUBREG_REG (SET_SRC (x)) = replacement->new;
2325 }
2326 else
2327 {
2328 replacement = find_fixup_replacement (replacements, SET_SRC (x));
2329 if (replacement->new)
2330 SET_SRC (x) = replacement->new;
2331 else if (GET_CODE (SET_SRC (x)) == SUBREG)
2332 SET_SRC (x) = replacement->new
2333 = fixup_memory_subreg (SET_SRC (x), insn, promoted_mode,
2334 0);
2335 else
2336 SET_SRC (x) = replacement->new
2337 = fixup_stack_1 (SET_SRC (x), insn);
2338 }
2339
2340 if (recog_memoized (insn) >= 0)
2341 return;
2342
2343 /* INSN is not valid, but we know that we want to
2344 copy SET_SRC (x) to SET_DEST (x) in some way. So
2345 we generate the move and see whether it requires more
2346 than one insn. If it does, we emit those insns and
2347 delete INSN. Otherwise, we can just replace the pattern
2348 of INSN; we have already verified above that INSN has
2349 no other function that to do X. */
2350
2351 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2352 if (NEXT_INSN (pat) != NULL_RTX)
2353 {
2354 last = emit_insn_before (pat, insn);
2355
2356 /* INSN might have REG_RETVAL or other important notes, so
2357 we need to store the pattern of the last insn in the
2358 sequence into INSN similarly to the normal case. LAST
2359 should not have REG_NOTES, but we allow them if INSN has
2360 no REG_NOTES. */
2361 if (REG_NOTES (last) && REG_NOTES (insn))
2362 abort ();
2363 if (REG_NOTES (last))
2364 REG_NOTES (insn) = REG_NOTES (last);
2365 PATTERN (insn) = PATTERN (last);
2366
2367 delete_insn (last);
2368 }
2369 else
2370 PATTERN (insn) = PATTERN (pat);
2371
2372 return;
2373 }
2374
2375 if ((SET_DEST (x) == var
2376 || (GET_CODE (SET_DEST (x)) == SUBREG
2377 && SUBREG_REG (SET_DEST (x)) == var))
2378 && (GET_CODE (SET_SRC (x)) == REG
2379 || (GET_CODE (SET_SRC (x)) == SUBREG
2380 && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG))
2381 && GET_MODE (var) == promoted_mode
2382 && x == single_set (insn))
2383 {
2384 rtx pat, last;
2385
2386 if (GET_CODE (SET_DEST (x)) == SUBREG)
2387 SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn,
2388 promoted_mode, 0);
2389 else
2390 SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn);
2391
2392 if (recog_memoized (insn) >= 0)
2393 return;
2394
2395 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2396 if (NEXT_INSN (pat) != NULL_RTX)
2397 {
2398 last = emit_insn_before (pat, insn);
2399
2400 /* INSN might have REG_RETVAL or other important notes, so
2401 we need to store the pattern of the last insn in the
2402 sequence into INSN similarly to the normal case. LAST
2403 should not have REG_NOTES, but we allow them if INSN has
2404 no REG_NOTES. */
2405 if (REG_NOTES (last) && REG_NOTES (insn))
2406 abort ();
2407 if (REG_NOTES (last))
2408 REG_NOTES (insn) = REG_NOTES (last);
2409 PATTERN (insn) = PATTERN (last);
2410
2411 delete_insn (last);
2412 }
2413 else
2414 PATTERN (insn) = PATTERN (pat);
2415
2416 return;
2417 }
2418
2419 /* Otherwise, storing into VAR must be handled specially
2420 by storing into a temporary and copying that into VAR
2421 with a new insn after this one. Note that this case
2422 will be used when storing into a promoted scalar since
2423 the insn will now have different modes on the input
2424 and output and hence will be invalid (except for the case
2425 of setting it to a constant, which does not need any
2426 change if it is valid). We generate extra code in that case,
2427 but combine.c will eliminate it. */
2428
2429 if (dest == var)
2430 {
2431 rtx temp;
2432 rtx fixeddest = SET_DEST (x);
2433 enum machine_mode temp_mode;
2434
2435 /* STRICT_LOW_PART can be discarded, around a MEM. */
2436 if (GET_CODE (fixeddest) == STRICT_LOW_PART)
2437 fixeddest = XEXP (fixeddest, 0);
2438 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
2439 if (GET_CODE (fixeddest) == SUBREG)
2440 {
2441 fixeddest = fixup_memory_subreg (fixeddest, insn,
2442 promoted_mode, 0);
2443 temp_mode = GET_MODE (fixeddest);
2444 }
2445 else
2446 {
2447 fixeddest = fixup_stack_1 (fixeddest, insn);
2448 temp_mode = promoted_mode;
2449 }
2450
2451 temp = gen_reg_rtx (temp_mode);
2452
2453 emit_insn_after (gen_move_insn (fixeddest,
2454 gen_lowpart (GET_MODE (fixeddest),
2455 temp)),
2456 insn);
2457
2458 SET_DEST (x) = temp;
2459 }
2460 }
2461
2462 default:
2463 break;
2464 }
2465
2466 /* Nothing special about this RTX; fix its operands. */
2467
2468 fmt = GET_RTX_FORMAT (code);
2469 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2470 {
2471 if (fmt[i] == 'e')
2472 fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements,
2473 no_share);
2474 else if (fmt[i] == 'E')
2475 {
2476 int j;
2477 for (j = 0; j < XVECLEN (x, i); j++)
2478 fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j),
2479 insn, replacements, no_share);
2480 }
2481 }
2482 }
2483 \f
2484 /* Previously, X had the form (SUBREG:m1 (REG:PROMOTED_MODE ...)).
2485 The REG was placed on the stack, so X now has the form (SUBREG:m1
2486 (MEM:m2 ...)).
2487
2488 Return an rtx (MEM:m1 newaddr) which is equivalent. If any insns
2489 must be emitted to compute NEWADDR, put them before INSN.
2490
2491 UNCRITICAL nonzero means accept paradoxical subregs.
2492 This is used for subregs found inside REG_NOTES. */
2493
2494 static rtx
2495 fixup_memory_subreg (x, insn, promoted_mode, uncritical)
2496 rtx x;
2497 rtx insn;
2498 enum machine_mode promoted_mode;
2499 int uncritical;
2500 {
2501 int offset;
2502 rtx mem = SUBREG_REG (x);
2503 rtx addr = XEXP (mem, 0);
2504 enum machine_mode mode = GET_MODE (x);
2505 rtx result, seq;
2506
2507 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
2508 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (mem)) && ! uncritical)
2509 abort ();
2510
2511 offset = SUBREG_BYTE (x);
2512 if (BYTES_BIG_ENDIAN)
2513 /* If the PROMOTED_MODE is wider than the mode of the MEM, adjust
2514 the offset so that it points to the right location within the
2515 MEM. */
2516 offset -= (GET_MODE_SIZE (promoted_mode) - GET_MODE_SIZE (GET_MODE (mem)));
2517
2518 if (!flag_force_addr
2519 && memory_address_p (mode, plus_constant (addr, offset)))
2520 /* Shortcut if no insns need be emitted. */
2521 return adjust_address (mem, mode, offset);
2522
2523 start_sequence ();
2524 result = adjust_address (mem, mode, offset);
2525 seq = get_insns ();
2526 end_sequence ();
2527
2528 emit_insn_before (seq, insn);
2529 return result;
2530 }
2531
2532 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2533 Replace subexpressions of X in place.
2534 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2535 Otherwise return X, with its contents possibly altered.
2536
2537 INSN, PROMOTED_MODE and UNCRITICAL are as for
2538 fixup_memory_subreg. */
2539
2540 static rtx
2541 walk_fixup_memory_subreg (x, insn, promoted_mode, uncritical)
2542 rtx x;
2543 rtx insn;
2544 enum machine_mode promoted_mode;
2545 int uncritical;
2546 {
2547 enum rtx_code code;
2548 const char *fmt;
2549 int i;
2550
2551 if (x == 0)
2552 return 0;
2553
2554 code = GET_CODE (x);
2555
2556 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
2557 return fixup_memory_subreg (x, insn, promoted_mode, uncritical);
2558
2559 /* Nothing special about this RTX; fix its operands. */
2560
2561 fmt = GET_RTX_FORMAT (code);
2562 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2563 {
2564 if (fmt[i] == 'e')
2565 XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn,
2566 promoted_mode, uncritical);
2567 else if (fmt[i] == 'E')
2568 {
2569 int j;
2570 for (j = 0; j < XVECLEN (x, i); j++)
2571 XVECEXP (x, i, j)
2572 = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn,
2573 promoted_mode, uncritical);
2574 }
2575 }
2576 return x;
2577 }
2578 \f
2579 /* For each memory ref within X, if it refers to a stack slot
2580 with an out of range displacement, put the address in a temp register
2581 (emitting new insns before INSN to load these registers)
2582 and alter the memory ref to use that register.
2583 Replace each such MEM rtx with a copy, to avoid clobberage. */
2584
2585 static rtx
2586 fixup_stack_1 (x, insn)
2587 rtx x;
2588 rtx insn;
2589 {
2590 int i;
2591 RTX_CODE code = GET_CODE (x);
2592 const char *fmt;
2593
2594 if (code == MEM)
2595 {
2596 rtx ad = XEXP (x, 0);
2597 /* If we have address of a stack slot but it's not valid
2598 (displacement is too large), compute the sum in a register. */
2599 if (GET_CODE (ad) == PLUS
2600 && GET_CODE (XEXP (ad, 0)) == REG
2601 && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER
2602 && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER)
2603 || REGNO (XEXP (ad, 0)) == FRAME_POINTER_REGNUM
2604 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2605 || REGNO (XEXP (ad, 0)) == HARD_FRAME_POINTER_REGNUM
2606 #endif
2607 || REGNO (XEXP (ad, 0)) == STACK_POINTER_REGNUM
2608 || REGNO (XEXP (ad, 0)) == ARG_POINTER_REGNUM
2609 || XEXP (ad, 0) == current_function_internal_arg_pointer)
2610 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
2611 {
2612 rtx temp, seq;
2613 if (memory_address_p (GET_MODE (x), ad))
2614 return x;
2615
2616 start_sequence ();
2617 temp = copy_to_reg (ad);
2618 seq = get_insns ();
2619 end_sequence ();
2620 emit_insn_before (seq, insn);
2621 return replace_equiv_address (x, temp);
2622 }
2623 return x;
2624 }
2625
2626 fmt = GET_RTX_FORMAT (code);
2627 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2628 {
2629 if (fmt[i] == 'e')
2630 XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
2631 else if (fmt[i] == 'E')
2632 {
2633 int j;
2634 for (j = 0; j < XVECLEN (x, i); j++)
2635 XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
2636 }
2637 }
2638 return x;
2639 }
2640 \f
2641 /* Optimization: a bit-field instruction whose field
2642 happens to be a byte or halfword in memory
2643 can be changed to a move instruction.
2644
2645 We call here when INSN is an insn to examine or store into a bit-field.
2646 BODY is the SET-rtx to be altered.
2647
2648 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2649 (Currently this is called only from function.c, and EQUIV_MEM
2650 is always 0.) */
2651
2652 static void
2653 optimize_bit_field (body, insn, equiv_mem)
2654 rtx body;
2655 rtx insn;
2656 rtx *equiv_mem;
2657 {
2658 rtx bitfield;
2659 int destflag;
2660 rtx seq = 0;
2661 enum machine_mode mode;
2662
2663 if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
2664 || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
2665 bitfield = SET_DEST (body), destflag = 1;
2666 else
2667 bitfield = SET_SRC (body), destflag = 0;
2668
2669 /* First check that the field being stored has constant size and position
2670 and is in fact a byte or halfword suitably aligned. */
2671
2672 if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
2673 && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
2674 && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1))
2675 != BLKmode)
2676 && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
2677 {
2678 rtx memref = 0;
2679
2680 /* Now check that the containing word is memory, not a register,
2681 and that it is safe to change the machine mode. */
2682
2683 if (GET_CODE (XEXP (bitfield, 0)) == MEM)
2684 memref = XEXP (bitfield, 0);
2685 else if (GET_CODE (XEXP (bitfield, 0)) == REG
2686 && equiv_mem != 0)
2687 memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
2688 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2689 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
2690 memref = SUBREG_REG (XEXP (bitfield, 0));
2691 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2692 && equiv_mem != 0
2693 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
2694 memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
2695
2696 if (memref
2697 && ! mode_dependent_address_p (XEXP (memref, 0))
2698 && ! MEM_VOLATILE_P (memref))
2699 {
2700 /* Now adjust the address, first for any subreg'ing
2701 that we are now getting rid of,
2702 and then for which byte of the word is wanted. */
2703
2704 HOST_WIDE_INT offset = INTVAL (XEXP (bitfield, 2));
2705 rtx insns;
2706
2707 /* Adjust OFFSET to count bits from low-address byte. */
2708 if (BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN)
2709 offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0)))
2710 - offset - INTVAL (XEXP (bitfield, 1)));
2711
2712 /* Adjust OFFSET to count bytes from low-address byte. */
2713 offset /= BITS_PER_UNIT;
2714 if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
2715 {
2716 offset += (SUBREG_BYTE (XEXP (bitfield, 0))
2717 / UNITS_PER_WORD) * UNITS_PER_WORD;
2718 if (BYTES_BIG_ENDIAN)
2719 offset -= (MIN (UNITS_PER_WORD,
2720 GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
2721 - MIN (UNITS_PER_WORD,
2722 GET_MODE_SIZE (GET_MODE (memref))));
2723 }
2724
2725 start_sequence ();
2726 memref = adjust_address (memref, mode, offset);
2727 insns = get_insns ();
2728 end_sequence ();
2729 emit_insn_before (insns, insn);
2730
2731 /* Store this memory reference where
2732 we found the bit field reference. */
2733
2734 if (destflag)
2735 {
2736 validate_change (insn, &SET_DEST (body), memref, 1);
2737 if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
2738 {
2739 rtx src = SET_SRC (body);
2740 while (GET_CODE (src) == SUBREG
2741 && SUBREG_BYTE (src) == 0)
2742 src = SUBREG_REG (src);
2743 if (GET_MODE (src) != GET_MODE (memref))
2744 src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
2745 validate_change (insn, &SET_SRC (body), src, 1);
2746 }
2747 else if (GET_MODE (SET_SRC (body)) != VOIDmode
2748 && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
2749 /* This shouldn't happen because anything that didn't have
2750 one of these modes should have got converted explicitly
2751 and then referenced through a subreg.
2752 This is so because the original bit-field was
2753 handled by agg_mode and so its tree structure had
2754 the same mode that memref now has. */
2755 abort ();
2756 }
2757 else
2758 {
2759 rtx dest = SET_DEST (body);
2760
2761 while (GET_CODE (dest) == SUBREG
2762 && SUBREG_BYTE (dest) == 0
2763 && (GET_MODE_CLASS (GET_MODE (dest))
2764 == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest))))
2765 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
2766 <= UNITS_PER_WORD))
2767 dest = SUBREG_REG (dest);
2768
2769 validate_change (insn, &SET_DEST (body), dest, 1);
2770
2771 if (GET_MODE (dest) == GET_MODE (memref))
2772 validate_change (insn, &SET_SRC (body), memref, 1);
2773 else
2774 {
2775 /* Convert the mem ref to the destination mode. */
2776 rtx newreg = gen_reg_rtx (GET_MODE (dest));
2777
2778 start_sequence ();
2779 convert_move (newreg, memref,
2780 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
2781 seq = get_insns ();
2782 end_sequence ();
2783
2784 validate_change (insn, &SET_SRC (body), newreg, 1);
2785 }
2786 }
2787
2788 /* See if we can convert this extraction or insertion into
2789 a simple move insn. We might not be able to do so if this
2790 was, for example, part of a PARALLEL.
2791
2792 If we succeed, write out any needed conversions. If we fail,
2793 it is hard to guess why we failed, so don't do anything
2794 special; just let the optimization be suppressed. */
2795
2796 if (apply_change_group () && seq)
2797 emit_insn_before (seq, insn);
2798 }
2799 }
2800 }
2801 \f
2802 /* These routines are responsible for converting virtual register references
2803 to the actual hard register references once RTL generation is complete.
2804
2805 The following four variables are used for communication between the
2806 routines. They contain the offsets of the virtual registers from their
2807 respective hard registers. */
2808
2809 static int in_arg_offset;
2810 static int var_offset;
2811 static int dynamic_offset;
2812 static int out_arg_offset;
2813 static int cfa_offset;
2814
2815 /* In most machines, the stack pointer register is equivalent to the bottom
2816 of the stack. */
2817
2818 #ifndef STACK_POINTER_OFFSET
2819 #define STACK_POINTER_OFFSET 0
2820 #endif
2821
2822 /* If not defined, pick an appropriate default for the offset of dynamically
2823 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2824 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2825
2826 #ifndef STACK_DYNAMIC_OFFSET
2827
2828 /* The bottom of the stack points to the actual arguments. If
2829 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2830 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2831 stack space for register parameters is not pushed by the caller, but
2832 rather part of the fixed stack areas and hence not included in
2833 `current_function_outgoing_args_size'. Nevertheless, we must allow
2834 for it when allocating stack dynamic objects. */
2835
2836 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2837 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2838 ((ACCUMULATE_OUTGOING_ARGS \
2839 ? (current_function_outgoing_args_size + REG_PARM_STACK_SPACE (FNDECL)) : 0)\
2840 + (STACK_POINTER_OFFSET)) \
2841
2842 #else
2843 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2844 ((ACCUMULATE_OUTGOING_ARGS ? current_function_outgoing_args_size : 0) \
2845 + (STACK_POINTER_OFFSET))
2846 #endif
2847 #endif
2848
2849 /* On most machines, the CFA coincides with the first incoming parm. */
2850
2851 #ifndef ARG_POINTER_CFA_OFFSET
2852 #define ARG_POINTER_CFA_OFFSET(FNDECL) FIRST_PARM_OFFSET (FNDECL)
2853 #endif
2854
2855 /* Build up a (MEM (ADDRESSOF (REG))) rtx for a register REG that just had its
2856 address taken. DECL is the decl or SAVE_EXPR for the object stored in the
2857 register, for later use if we do need to force REG into the stack. REG is
2858 overwritten by the MEM like in put_reg_into_stack. */
2859
2860 rtx
2861 gen_mem_addressof (reg, decl)
2862 rtx reg;
2863 tree decl;
2864 {
2865 rtx r = gen_rtx_ADDRESSOF (Pmode, gen_reg_rtx (GET_MODE (reg)),
2866 REGNO (reg), decl);
2867
2868 /* Calculate this before we start messing with decl's RTL. */
2869 HOST_WIDE_INT set = decl ? get_alias_set (decl) : 0;
2870
2871 /* If the original REG was a user-variable, then so is the REG whose
2872 address is being taken. Likewise for unchanging. */
2873 REG_USERVAR_P (XEXP (r, 0)) = REG_USERVAR_P (reg);
2874 RTX_UNCHANGING_P (XEXP (r, 0)) = RTX_UNCHANGING_P (reg);
2875
2876 PUT_CODE (reg, MEM);
2877 MEM_ATTRS (reg) = 0;
2878 XEXP (reg, 0) = r;
2879
2880 if (decl)
2881 {
2882 tree type = TREE_TYPE (decl);
2883 enum machine_mode decl_mode
2884 = (DECL_P (decl) ? DECL_MODE (decl) : TYPE_MODE (TREE_TYPE (decl)));
2885 rtx decl_rtl = (TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl)
2886 : DECL_RTL_IF_SET (decl));
2887
2888 PUT_MODE (reg, decl_mode);
2889
2890 /* Clear DECL_RTL momentarily so functions below will work
2891 properly, then set it again. */
2892 if (DECL_P (decl) && decl_rtl == reg)
2893 SET_DECL_RTL (decl, 0);
2894
2895 set_mem_attributes (reg, decl, 1);
2896 set_mem_alias_set (reg, set);
2897
2898 if (DECL_P (decl) && decl_rtl == reg)
2899 SET_DECL_RTL (decl, reg);
2900
2901 if (TREE_USED (decl) || (DECL_P (decl) && DECL_INITIAL (decl) != 0))
2902 fixup_var_refs (reg, GET_MODE (reg), TREE_UNSIGNED (type), reg, 0);
2903 }
2904 else
2905 fixup_var_refs (reg, GET_MODE (reg), 0, reg, 0);
2906
2907 return reg;
2908 }
2909
2910 /* If DECL has an RTL that is an ADDRESSOF rtx, put it into the stack. */
2911
2912 void
2913 flush_addressof (decl)
2914 tree decl;
2915 {
2916 if ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == VAR_DECL)
2917 && DECL_RTL (decl) != 0
2918 && GET_CODE (DECL_RTL (decl)) == MEM
2919 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF
2920 && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 0)) == REG)
2921 put_addressof_into_stack (XEXP (DECL_RTL (decl), 0), 0);
2922 }
2923
2924 /* Force the register pointed to by R, an ADDRESSOF rtx, into the stack. */
2925
2926 static void
2927 put_addressof_into_stack (r, ht)
2928 rtx r;
2929 htab_t ht;
2930 {
2931 tree decl, type;
2932 int volatile_p, used_p;
2933
2934 rtx reg = XEXP (r, 0);
2935
2936 if (GET_CODE (reg) != REG)
2937 abort ();
2938
2939 decl = ADDRESSOF_DECL (r);
2940 if (decl)
2941 {
2942 type = TREE_TYPE (decl);
2943 volatile_p = (TREE_CODE (decl) != SAVE_EXPR
2944 && TREE_THIS_VOLATILE (decl));
2945 used_p = (TREE_USED (decl)
2946 || (DECL_P (decl) && DECL_INITIAL (decl) != 0));
2947 }
2948 else
2949 {
2950 type = NULL_TREE;
2951 volatile_p = 0;
2952 used_p = 1;
2953 }
2954
2955 put_reg_into_stack (0, reg, type, GET_MODE (reg), GET_MODE (reg),
2956 volatile_p, ADDRESSOF_REGNO (r), used_p, ht);
2957 }
2958
2959 /* List of replacements made below in purge_addressof_1 when creating
2960 bitfield insertions. */
2961 static rtx purge_bitfield_addressof_replacements;
2962
2963 /* List of replacements made below in purge_addressof_1 for patterns
2964 (MEM (ADDRESSOF (REG ...))). The key of the list entry is the
2965 corresponding (ADDRESSOF (REG ...)) and value is a substitution for
2966 the all pattern. List PURGE_BITFIELD_ADDRESSOF_REPLACEMENTS is not
2967 enough in complex cases, e.g. when some field values can be
2968 extracted by usage MEM with narrower mode. */
2969 static rtx purge_addressof_replacements;
2970
2971 /* Helper function for purge_addressof. See if the rtx expression at *LOC
2972 in INSN needs to be changed. If FORCE, always put any ADDRESSOFs into
2973 the stack. If the function returns FALSE then the replacement could not
2974 be made. */
2975
2976 static bool
2977 purge_addressof_1 (loc, insn, force, store, ht)
2978 rtx *loc;
2979 rtx insn;
2980 int force, store;
2981 htab_t ht;
2982 {
2983 rtx x;
2984 RTX_CODE code;
2985 int i, j;
2986 const char *fmt;
2987 bool result = true;
2988
2989 /* Re-start here to avoid recursion in common cases. */
2990 restart:
2991
2992 x = *loc;
2993 if (x == 0)
2994 return true;
2995
2996 code = GET_CODE (x);
2997
2998 /* If we don't return in any of the cases below, we will recurse inside
2999 the RTX, which will normally result in any ADDRESSOF being forced into
3000 memory. */
3001 if (code == SET)
3002 {
3003 result = purge_addressof_1 (&SET_DEST (x), insn, force, 1, ht);
3004 result &= purge_addressof_1 (&SET_SRC (x), insn, force, 0, ht);
3005 return result;
3006 }
3007 else if (code == ADDRESSOF)
3008 {
3009 rtx sub, insns;
3010
3011 if (GET_CODE (XEXP (x, 0)) != MEM)
3012 put_addressof_into_stack (x, ht);
3013
3014 /* We must create a copy of the rtx because it was created by
3015 overwriting a REG rtx which is always shared. */
3016 sub = copy_rtx (XEXP (XEXP (x, 0), 0));
3017 if (validate_change (insn, loc, sub, 0)
3018 || validate_replace_rtx (x, sub, insn))
3019 return true;
3020
3021 start_sequence ();
3022 sub = force_operand (sub, NULL_RTX);
3023 if (! validate_change (insn, loc, sub, 0)
3024 && ! validate_replace_rtx (x, sub, insn))
3025 abort ();
3026
3027 insns = get_insns ();
3028 end_sequence ();
3029 emit_insn_before (insns, insn);
3030 return true;
3031 }
3032
3033 else if (code == MEM && GET_CODE (XEXP (x, 0)) == ADDRESSOF && ! force)
3034 {
3035 rtx sub = XEXP (XEXP (x, 0), 0);
3036
3037 if (GET_CODE (sub) == MEM)
3038 sub = adjust_address_nv (sub, GET_MODE (x), 0);
3039 else if (GET_CODE (sub) == REG
3040 && (MEM_VOLATILE_P (x) || GET_MODE (x) == BLKmode))
3041 ;
3042 else if (GET_CODE (sub) == REG && GET_MODE (x) != GET_MODE (sub))
3043 {
3044 int size_x, size_sub;
3045
3046 if (!insn)
3047 {
3048 /* When processing REG_NOTES look at the list of
3049 replacements done on the insn to find the register that X
3050 was replaced by. */
3051 rtx tem;
3052
3053 for (tem = purge_bitfield_addressof_replacements;
3054 tem != NULL_RTX;
3055 tem = XEXP (XEXP (tem, 1), 1))
3056 if (rtx_equal_p (x, XEXP (tem, 0)))
3057 {
3058 *loc = XEXP (XEXP (tem, 1), 0);
3059 return true;
3060 }
3061
3062 /* See comment for purge_addressof_replacements. */
3063 for (tem = purge_addressof_replacements;
3064 tem != NULL_RTX;
3065 tem = XEXP (XEXP (tem, 1), 1))
3066 if (rtx_equal_p (XEXP (x, 0), XEXP (tem, 0)))
3067 {
3068 rtx z = XEXP (XEXP (tem, 1), 0);
3069
3070 if (GET_MODE (x) == GET_MODE (z)
3071 || (GET_CODE (XEXP (XEXP (tem, 1), 0)) != REG
3072 && GET_CODE (XEXP (XEXP (tem, 1), 0)) != SUBREG))
3073 abort ();
3074
3075 /* It can happen that the note may speak of things
3076 in a wider (or just different) mode than the
3077 code did. This is especially true of
3078 REG_RETVAL. */
3079
3080 if (GET_CODE (z) == SUBREG && SUBREG_BYTE (z) == 0)
3081 z = SUBREG_REG (z);
3082
3083 if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD
3084 && (GET_MODE_SIZE (GET_MODE (x))
3085 > GET_MODE_SIZE (GET_MODE (z))))
3086 {
3087 /* This can occur as a result in invalid
3088 pointer casts, e.g. float f; ...
3089 *(long long int *)&f.
3090 ??? We could emit a warning here, but
3091 without a line number that wouldn't be
3092 very helpful. */
3093 z = gen_rtx_SUBREG (GET_MODE (x), z, 0);
3094 }
3095 else
3096 z = gen_lowpart (GET_MODE (x), z);
3097
3098 *loc = z;
3099 return true;
3100 }
3101
3102 /* Sometimes we may not be able to find the replacement. For
3103 example when the original insn was a MEM in a wider mode,
3104 and the note is part of a sign extension of a narrowed
3105 version of that MEM. Gcc testcase compile/990829-1.c can
3106 generate an example of this situation. Rather than complain
3107 we return false, which will prompt our caller to remove the
3108 offending note. */
3109 return false;
3110 }
3111
3112 size_x = GET_MODE_BITSIZE (GET_MODE (x));
3113 size_sub = GET_MODE_BITSIZE (GET_MODE (sub));
3114
3115 /* Don't even consider working with paradoxical subregs,
3116 or the moral equivalent seen here. */
3117 if (size_x <= size_sub
3118 && int_mode_for_mode (GET_MODE (sub)) != BLKmode)
3119 {
3120 /* Do a bitfield insertion to mirror what would happen
3121 in memory. */
3122
3123 rtx val, seq;
3124
3125 if (store)
3126 {
3127 rtx p = PREV_INSN (insn);
3128
3129 start_sequence ();
3130 val = gen_reg_rtx (GET_MODE (x));
3131 if (! validate_change (insn, loc, val, 0))
3132 {
3133 /* Discard the current sequence and put the
3134 ADDRESSOF on stack. */
3135 end_sequence ();
3136 goto give_up;
3137 }
3138 seq = get_insns ();
3139 end_sequence ();
3140 emit_insn_before (seq, insn);
3141 compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (),
3142 insn, ht);
3143
3144 start_sequence ();
3145 store_bit_field (sub, size_x, 0, GET_MODE (x),
3146 val, GET_MODE_SIZE (GET_MODE (sub)));
3147
3148 /* Make sure to unshare any shared rtl that store_bit_field
3149 might have created. */
3150 unshare_all_rtl_again (get_insns ());
3151
3152 seq = get_insns ();
3153 end_sequence ();
3154 p = emit_insn_after (seq, insn);
3155 if (NEXT_INSN (insn))
3156 compute_insns_for_mem (NEXT_INSN (insn),
3157 p ? NEXT_INSN (p) : NULL_RTX,
3158 ht);
3159 }
3160 else
3161 {
3162 rtx p = PREV_INSN (insn);
3163
3164 start_sequence ();
3165 val = extract_bit_field (sub, size_x, 0, 1, NULL_RTX,
3166 GET_MODE (x), GET_MODE (x),
3167 GET_MODE_SIZE (GET_MODE (sub)));
3168
3169 if (! validate_change (insn, loc, val, 0))
3170 {
3171 /* Discard the current sequence and put the
3172 ADDRESSOF on stack. */
3173 end_sequence ();
3174 goto give_up;
3175 }
3176
3177 seq = get_insns ();
3178 end_sequence ();
3179 emit_insn_before (seq, insn);
3180 compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (),
3181 insn, ht);
3182 }
3183
3184 /* Remember the replacement so that the same one can be done
3185 on the REG_NOTES. */
3186 purge_bitfield_addressof_replacements
3187 = gen_rtx_EXPR_LIST (VOIDmode, x,
3188 gen_rtx_EXPR_LIST
3189 (VOIDmode, val,
3190 purge_bitfield_addressof_replacements));
3191
3192 /* We replaced with a reg -- all done. */
3193 return true;
3194 }
3195 }
3196
3197 else if (validate_change (insn, loc, sub, 0))
3198 {
3199 /* Remember the replacement so that the same one can be done
3200 on the REG_NOTES. */
3201 if (GET_CODE (sub) == REG || GET_CODE (sub) == SUBREG)
3202 {
3203 rtx tem;
3204
3205 for (tem = purge_addressof_replacements;
3206 tem != NULL_RTX;
3207 tem = XEXP (XEXP (tem, 1), 1))
3208 if (rtx_equal_p (XEXP (x, 0), XEXP (tem, 0)))
3209 {
3210 XEXP (XEXP (tem, 1), 0) = sub;
3211 return true;
3212 }
3213 purge_addressof_replacements
3214 = gen_rtx (EXPR_LIST, VOIDmode, XEXP (x, 0),
3215 gen_rtx_EXPR_LIST (VOIDmode, sub,
3216 purge_addressof_replacements));
3217 return true;
3218 }
3219 goto restart;
3220 }
3221 }
3222
3223 give_up:
3224 /* Scan all subexpressions. */
3225 fmt = GET_RTX_FORMAT (code);
3226 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
3227 {
3228 if (*fmt == 'e')
3229 result &= purge_addressof_1 (&XEXP (x, i), insn, force, 0, ht);
3230 else if (*fmt == 'E')
3231 for (j = 0; j < XVECLEN (x, i); j++)
3232 result &= purge_addressof_1 (&XVECEXP (x, i, j), insn, force, 0, ht);
3233 }
3234
3235 return result;
3236 }
3237
3238 /* Return a hash value for K, a REG. */
3239
3240 static hashval_t
3241 insns_for_mem_hash (k)
3242 const void * k;
3243 {
3244 /* Use the address of the key for the hash value. */
3245 struct insns_for_mem_entry *m = (struct insns_for_mem_entry *) k;
3246 return htab_hash_pointer (m->key);
3247 }
3248
3249 /* Return nonzero if K1 and K2 (two REGs) are the same. */
3250
3251 static int
3252 insns_for_mem_comp (k1, k2)
3253 const void * k1;
3254 const void * k2;
3255 {
3256 struct insns_for_mem_entry *m1 = (struct insns_for_mem_entry *) k1;
3257 struct insns_for_mem_entry *m2 = (struct insns_for_mem_entry *) k2;
3258 return m1->key == m2->key;
3259 }
3260
3261 struct insns_for_mem_walk_info
3262 {
3263 /* The hash table that we are using to record which INSNs use which
3264 MEMs. */
3265 htab_t ht;
3266
3267 /* The INSN we are currently processing. */
3268 rtx insn;
3269
3270 /* Zero if we are walking to find ADDRESSOFs, one if we are walking
3271 to find the insns that use the REGs in the ADDRESSOFs. */
3272 int pass;
3273 };
3274
3275 /* Called from compute_insns_for_mem via for_each_rtx. If R is a REG
3276 that might be used in an ADDRESSOF expression, record this INSN in
3277 the hash table given by DATA (which is really a pointer to an
3278 insns_for_mem_walk_info structure). */
3279
3280 static int
3281 insns_for_mem_walk (r, data)
3282 rtx *r;
3283 void *data;
3284 {
3285 struct insns_for_mem_walk_info *ifmwi
3286 = (struct insns_for_mem_walk_info *) data;
3287 struct insns_for_mem_entry tmp;
3288 tmp.insns = NULL_RTX;
3289
3290 if (ifmwi->pass == 0 && *r && GET_CODE (*r) == ADDRESSOF
3291 && GET_CODE (XEXP (*r, 0)) == REG)
3292 {
3293 PTR *e;
3294 tmp.key = XEXP (*r, 0);
3295 e = htab_find_slot (ifmwi->ht, &tmp, INSERT);
3296 if (*e == NULL)
3297 {
3298 *e = ggc_alloc (sizeof (tmp));
3299 memcpy (*e, &tmp, sizeof (tmp));
3300 }
3301 }
3302 else if (ifmwi->pass == 1 && *r && GET_CODE (*r) == REG)
3303 {
3304 struct insns_for_mem_entry *ifme;
3305 tmp.key = *r;
3306 ifme = (struct insns_for_mem_entry *) htab_find (ifmwi->ht, &tmp);
3307
3308 /* If we have not already recorded this INSN, do so now. Since
3309 we process the INSNs in order, we know that if we have
3310 recorded it it must be at the front of the list. */
3311 if (ifme && (!ifme->insns || XEXP (ifme->insns, 0) != ifmwi->insn))
3312 ifme->insns = gen_rtx_EXPR_LIST (VOIDmode, ifmwi->insn,
3313 ifme->insns);
3314 }
3315
3316 return 0;
3317 }
3318
3319 /* Walk the INSNS, until we reach LAST_INSN, recording which INSNs use
3320 which REGs in HT. */
3321
3322 static void
3323 compute_insns_for_mem (insns, last_insn, ht)
3324 rtx insns;
3325 rtx last_insn;
3326 htab_t ht;
3327 {
3328 rtx insn;
3329 struct insns_for_mem_walk_info ifmwi;
3330 ifmwi.ht = ht;
3331
3332 for (ifmwi.pass = 0; ifmwi.pass < 2; ++ifmwi.pass)
3333 for (insn = insns; insn != last_insn; insn = NEXT_INSN (insn))
3334 if (INSN_P (insn))
3335 {
3336 ifmwi.insn = insn;
3337 for_each_rtx (&insn, insns_for_mem_walk, &ifmwi);
3338 }
3339 }
3340
3341 /* Helper function for purge_addressof called through for_each_rtx.
3342 Returns true iff the rtl is an ADDRESSOF. */
3343
3344 static int
3345 is_addressof (rtl, data)
3346 rtx *rtl;
3347 void *data ATTRIBUTE_UNUSED;
3348 {
3349 return GET_CODE (*rtl) == ADDRESSOF;
3350 }
3351
3352 /* Eliminate all occurrences of ADDRESSOF from INSNS. Elide any remaining
3353 (MEM (ADDRESSOF)) patterns, and force any needed registers into the
3354 stack. */
3355
3356 void
3357 purge_addressof (insns)
3358 rtx insns;
3359 {
3360 rtx insn;
3361 htab_t ht;
3362
3363 /* When we actually purge ADDRESSOFs, we turn REGs into MEMs. That
3364 requires a fixup pass over the instruction stream to correct
3365 INSNs that depended on the REG being a REG, and not a MEM. But,
3366 these fixup passes are slow. Furthermore, most MEMs are not
3367 mentioned in very many instructions. So, we speed up the process
3368 by pre-calculating which REGs occur in which INSNs; that allows
3369 us to perform the fixup passes much more quickly. */
3370 ht = htab_create_ggc (1000, insns_for_mem_hash, insns_for_mem_comp, NULL);
3371 compute_insns_for_mem (insns, NULL_RTX, ht);
3372
3373 for (insn = insns; insn; insn = NEXT_INSN (insn))
3374 if (INSN_P (insn))
3375 {
3376 if (! purge_addressof_1 (&PATTERN (insn), insn,
3377 asm_noperands (PATTERN (insn)) > 0, 0, ht))
3378 /* If we could not replace the ADDRESSOFs in the insn,
3379 something is wrong. */
3380 abort ();
3381
3382 if (! purge_addressof_1 (&REG_NOTES (insn), NULL_RTX, 0, 0, ht))
3383 {
3384 /* If we could not replace the ADDRESSOFs in the insn's notes,
3385 we can just remove the offending notes instead. */
3386 rtx note;
3387
3388 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
3389 {
3390 /* If we find a REG_RETVAL note then the insn is a libcall.
3391 Such insns must have REG_EQUAL notes as well, in order
3392 for later passes of the compiler to work. So it is not
3393 safe to delete the notes here, and instead we abort. */
3394 if (REG_NOTE_KIND (note) == REG_RETVAL)
3395 abort ();
3396 if (for_each_rtx (&note, is_addressof, NULL))
3397 remove_note (insn, note);
3398 }
3399 }
3400 }
3401
3402 /* Clean up. */
3403 purge_bitfield_addressof_replacements = 0;
3404 purge_addressof_replacements = 0;
3405
3406 /* REGs are shared. purge_addressof will destructively replace a REG
3407 with a MEM, which creates shared MEMs.
3408
3409 Unfortunately, the children of put_reg_into_stack assume that MEMs
3410 referring to the same stack slot are shared (fixup_var_refs and
3411 the associated hash table code).
3412
3413 So, we have to do another unsharing pass after we have flushed any
3414 REGs that had their address taken into the stack.
3415
3416 It may be worth tracking whether or not we converted any REGs into
3417 MEMs to avoid this overhead when it is not needed. */
3418 unshare_all_rtl_again (get_insns ());
3419 }
3420 \f
3421 /* Convert a SET of a hard subreg to a set of the appropriate hard
3422 register. A subroutine of purge_hard_subreg_sets. */
3423
3424 static void
3425 purge_single_hard_subreg_set (pattern)
3426 rtx pattern;
3427 {
3428 rtx reg = SET_DEST (pattern);
3429 enum machine_mode mode = GET_MODE (SET_DEST (pattern));
3430 int offset = 0;
3431
3432 if (GET_CODE (reg) == SUBREG && GET_CODE (SUBREG_REG (reg)) == REG
3433 && REGNO (SUBREG_REG (reg)) < FIRST_PSEUDO_REGISTER)
3434 {
3435 offset = subreg_regno_offset (REGNO (SUBREG_REG (reg)),
3436 GET_MODE (SUBREG_REG (reg)),
3437 SUBREG_BYTE (reg),
3438 GET_MODE (reg));
3439 reg = SUBREG_REG (reg);
3440 }
3441
3442
3443 if (GET_CODE (reg) == REG && REGNO (reg) < FIRST_PSEUDO_REGISTER)
3444 {
3445 reg = gen_rtx_REG (mode, REGNO (reg) + offset);
3446 SET_DEST (pattern) = reg;
3447 }
3448 }
3449
3450 /* Eliminate all occurrences of SETs of hard subregs from INSNS. The
3451 only such SETs that we expect to see are those left in because
3452 integrate can't handle sets of parts of a return value register.
3453
3454 We don't use alter_subreg because we only want to eliminate subregs
3455 of hard registers. */
3456
3457 void
3458 purge_hard_subreg_sets (insn)
3459 rtx insn;
3460 {
3461 for (; insn; insn = NEXT_INSN (insn))
3462 {
3463 if (INSN_P (insn))
3464 {
3465 rtx pattern = PATTERN (insn);
3466 switch (GET_CODE (pattern))
3467 {
3468 case SET:
3469 if (GET_CODE (SET_DEST (pattern)) == SUBREG)
3470 purge_single_hard_subreg_set (pattern);
3471 break;
3472 case PARALLEL:
3473 {
3474 int j;
3475 for (j = XVECLEN (pattern, 0) - 1; j >= 0; j--)
3476 {
3477 rtx inner_pattern = XVECEXP (pattern, 0, j);
3478 if (GET_CODE (inner_pattern) == SET
3479 && GET_CODE (SET_DEST (inner_pattern)) == SUBREG)
3480 purge_single_hard_subreg_set (inner_pattern);
3481 }
3482 }
3483 break;
3484 default:
3485 break;
3486 }
3487 }
3488 }
3489 }
3490 \f
3491 /* Pass through the INSNS of function FNDECL and convert virtual register
3492 references to hard register references. */
3493
3494 void
3495 instantiate_virtual_regs (fndecl, insns)
3496 tree fndecl;
3497 rtx insns;
3498 {
3499 rtx insn;
3500 unsigned int i;
3501
3502 /* Compute the offsets to use for this function. */
3503 in_arg_offset = FIRST_PARM_OFFSET (fndecl);
3504 var_offset = STARTING_FRAME_OFFSET;
3505 dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl);
3506 out_arg_offset = STACK_POINTER_OFFSET;
3507 cfa_offset = ARG_POINTER_CFA_OFFSET (fndecl);
3508
3509 /* Scan all variables and parameters of this function. For each that is
3510 in memory, instantiate all virtual registers if the result is a valid
3511 address. If not, we do it later. That will handle most uses of virtual
3512 regs on many machines. */
3513 instantiate_decls (fndecl, 1);
3514
3515 /* Initialize recognition, indicating that volatile is OK. */
3516 init_recog ();
3517
3518 /* Scan through all the insns, instantiating every virtual register still
3519 present. */
3520 for (insn = insns; insn; insn = NEXT_INSN (insn))
3521 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
3522 || GET_CODE (insn) == CALL_INSN)
3523 {
3524 instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1);
3525 instantiate_virtual_regs_1 (&REG_NOTES (insn), NULL_RTX, 0);
3526 /* Instantiate any virtual registers in CALL_INSN_FUNCTION_USAGE. */
3527 if (GET_CODE (insn) == CALL_INSN)
3528 instantiate_virtual_regs_1 (&CALL_INSN_FUNCTION_USAGE (insn),
3529 NULL_RTX, 0);
3530 }
3531
3532 /* Instantiate the stack slots for the parm registers, for later use in
3533 addressof elimination. */
3534 for (i = 0; i < max_parm_reg; ++i)
3535 if (parm_reg_stack_loc[i])
3536 instantiate_virtual_regs_1 (&parm_reg_stack_loc[i], NULL_RTX, 0);
3537
3538 /* Now instantiate the remaining register equivalences for debugging info.
3539 These will not be valid addresses. */
3540 instantiate_decls (fndecl, 0);
3541
3542 /* Indicate that, from now on, assign_stack_local should use
3543 frame_pointer_rtx. */
3544 virtuals_instantiated = 1;
3545 }
3546
3547 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
3548 all virtual registers in their DECL_RTL's.
3549
3550 If VALID_ONLY, do this only if the resulting address is still valid.
3551 Otherwise, always do it. */
3552
3553 static void
3554 instantiate_decls (fndecl, valid_only)
3555 tree fndecl;
3556 int valid_only;
3557 {
3558 tree decl;
3559
3560 /* Process all parameters of the function. */
3561 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
3562 {
3563 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
3564 HOST_WIDE_INT size_rtl;
3565
3566 instantiate_decl (DECL_RTL (decl), size, valid_only);
3567
3568 /* If the parameter was promoted, then the incoming RTL mode may be
3569 larger than the declared type size. We must use the larger of
3570 the two sizes. */
3571 size_rtl = GET_MODE_SIZE (GET_MODE (DECL_INCOMING_RTL (decl)));
3572 size = MAX (size_rtl, size);
3573 instantiate_decl (DECL_INCOMING_RTL (decl), size, valid_only);
3574 }
3575
3576 /* Now process all variables defined in the function or its subblocks. */
3577 instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only);
3578 }
3579
3580 /* Subroutine of instantiate_decls: Process all decls in the given
3581 BLOCK node and all its subblocks. */
3582
3583 static void
3584 instantiate_decls_1 (let, valid_only)
3585 tree let;
3586 int valid_only;
3587 {
3588 tree t;
3589
3590 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
3591 if (DECL_RTL_SET_P (t))
3592 instantiate_decl (DECL_RTL (t),
3593 int_size_in_bytes (TREE_TYPE (t)),
3594 valid_only);
3595
3596 /* Process all subblocks. */
3597 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
3598 instantiate_decls_1 (t, valid_only);
3599 }
3600
3601 /* Subroutine of the preceding procedures: Given RTL representing a
3602 decl and the size of the object, do any instantiation required.
3603
3604 If VALID_ONLY is nonzero, it means that the RTL should only be
3605 changed if the new address is valid. */
3606
3607 static void
3608 instantiate_decl (x, size, valid_only)
3609 rtx x;
3610 HOST_WIDE_INT size;
3611 int valid_only;
3612 {
3613 enum machine_mode mode;
3614 rtx addr;
3615
3616 /* If this is not a MEM, no need to do anything. Similarly if the
3617 address is a constant or a register that is not a virtual register. */
3618
3619 if (x == 0 || GET_CODE (x) != MEM)
3620 return;
3621
3622 addr = XEXP (x, 0);
3623 if (CONSTANT_P (addr)
3624 || (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == REG)
3625 || (GET_CODE (addr) == REG
3626 && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
3627 || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
3628 return;
3629
3630 /* If we should only do this if the address is valid, copy the address.
3631 We need to do this so we can undo any changes that might make the
3632 address invalid. This copy is unfortunate, but probably can't be
3633 avoided. */
3634
3635 if (valid_only)
3636 addr = copy_rtx (addr);
3637
3638 instantiate_virtual_regs_1 (&addr, NULL_RTX, 0);
3639
3640 if (valid_only && size >= 0)
3641 {
3642 unsigned HOST_WIDE_INT decl_size = size;
3643
3644 /* Now verify that the resulting address is valid for every integer or
3645 floating-point mode up to and including SIZE bytes long. We do this
3646 since the object might be accessed in any mode and frame addresses
3647 are shared. */
3648
3649 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
3650 mode != VOIDmode && GET_MODE_SIZE (mode) <= decl_size;
3651 mode = GET_MODE_WIDER_MODE (mode))
3652 if (! memory_address_p (mode, addr))
3653 return;
3654
3655 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
3656 mode != VOIDmode && GET_MODE_SIZE (mode) <= decl_size;
3657 mode = GET_MODE_WIDER_MODE (mode))
3658 if (! memory_address_p (mode, addr))
3659 return;
3660 }
3661
3662 /* Put back the address now that we have updated it and we either know
3663 it is valid or we don't care whether it is valid. */
3664
3665 XEXP (x, 0) = addr;
3666 }
3667 \f
3668 /* Given a piece of RTX and a pointer to a HOST_WIDE_INT, if the RTX
3669 is a virtual register, return the equivalent hard register and set the
3670 offset indirectly through the pointer. Otherwise, return 0. */
3671
3672 static rtx
3673 instantiate_new_reg (x, poffset)
3674 rtx x;
3675 HOST_WIDE_INT *poffset;
3676 {
3677 rtx new;
3678 HOST_WIDE_INT offset;
3679
3680 if (x == virtual_incoming_args_rtx)
3681 new = arg_pointer_rtx, offset = in_arg_offset;
3682 else if (x == virtual_stack_vars_rtx)
3683 new = frame_pointer_rtx, offset = var_offset;
3684 else if (x == virtual_stack_dynamic_rtx)
3685 new = stack_pointer_rtx, offset = dynamic_offset;
3686 else if (x == virtual_outgoing_args_rtx)
3687 new = stack_pointer_rtx, offset = out_arg_offset;
3688 else if (x == virtual_cfa_rtx)
3689 new = arg_pointer_rtx, offset = cfa_offset;
3690 else
3691 return 0;
3692
3693 *poffset = offset;
3694 return new;
3695 }
3696 \f
3697 /* Given a pointer to a piece of rtx and an optional pointer to the
3698 containing object, instantiate any virtual registers present in it.
3699
3700 If EXTRA_INSNS, we always do the replacement and generate
3701 any extra insns before OBJECT. If it zero, we do nothing if replacement
3702 is not valid.
3703
3704 Return 1 if we either had nothing to do or if we were able to do the
3705 needed replacement. Return 0 otherwise; we only return zero if
3706 EXTRA_INSNS is zero.
3707
3708 We first try some simple transformations to avoid the creation of extra
3709 pseudos. */
3710
3711 static int
3712 instantiate_virtual_regs_1 (loc, object, extra_insns)
3713 rtx *loc;
3714 rtx object;
3715 int extra_insns;
3716 {
3717 rtx x;
3718 RTX_CODE code;
3719 rtx new = 0;
3720 HOST_WIDE_INT offset = 0;
3721 rtx temp;
3722 rtx seq;
3723 int i, j;
3724 const char *fmt;
3725
3726 /* Re-start here to avoid recursion in common cases. */
3727 restart:
3728
3729 x = *loc;
3730 if (x == 0)
3731 return 1;
3732
3733 code = GET_CODE (x);
3734
3735 /* Check for some special cases. */
3736 switch (code)
3737 {
3738 case CONST_INT:
3739 case CONST_DOUBLE:
3740 case CONST_VECTOR:
3741 case CONST:
3742 case SYMBOL_REF:
3743 case CODE_LABEL:
3744 case PC:
3745 case CC0:
3746 case ASM_INPUT:
3747 case ADDR_VEC:
3748 case ADDR_DIFF_VEC:
3749 case RETURN:
3750 return 1;
3751
3752 case SET:
3753 /* We are allowed to set the virtual registers. This means that
3754 the actual register should receive the source minus the
3755 appropriate offset. This is used, for example, in the handling
3756 of non-local gotos. */
3757 if ((new = instantiate_new_reg (SET_DEST (x), &offset)) != 0)
3758 {
3759 rtx src = SET_SRC (x);
3760
3761 /* We are setting the register, not using it, so the relevant
3762 offset is the negative of the offset to use were we using
3763 the register. */
3764 offset = - offset;
3765 instantiate_virtual_regs_1 (&src, NULL_RTX, 0);
3766
3767 /* The only valid sources here are PLUS or REG. Just do
3768 the simplest possible thing to handle them. */
3769 if (GET_CODE (src) != REG && GET_CODE (src) != PLUS)
3770 abort ();
3771
3772 start_sequence ();
3773 if (GET_CODE (src) != REG)
3774 temp = force_operand (src, NULL_RTX);
3775 else
3776 temp = src;
3777 temp = force_operand (plus_constant (temp, offset), NULL_RTX);
3778 seq = get_insns ();
3779 end_sequence ();
3780
3781 emit_insn_before (seq, object);
3782 SET_DEST (x) = new;
3783
3784 if (! validate_change (object, &SET_SRC (x), temp, 0)
3785 || ! extra_insns)
3786 abort ();
3787
3788 return 1;
3789 }
3790
3791 instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns);
3792 loc = &SET_SRC (x);
3793 goto restart;
3794
3795 case PLUS:
3796 /* Handle special case of virtual register plus constant. */
3797 if (CONSTANT_P (XEXP (x, 1)))
3798 {
3799 rtx old, new_offset;
3800
3801 /* Check for (plus (plus VIRT foo) (const_int)) first. */
3802 if (GET_CODE (XEXP (x, 0)) == PLUS)
3803 {
3804 if ((new = instantiate_new_reg (XEXP (XEXP (x, 0), 0), &offset)))
3805 {
3806 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object,
3807 extra_insns);
3808 new = gen_rtx_PLUS (Pmode, new, XEXP (XEXP (x, 0), 1));
3809 }
3810 else
3811 {
3812 loc = &XEXP (x, 0);
3813 goto restart;
3814 }
3815 }
3816
3817 #ifdef POINTERS_EXTEND_UNSIGNED
3818 /* If we have (plus (subreg (virtual-reg)) (const_int)), we know
3819 we can commute the PLUS and SUBREG because pointers into the
3820 frame are well-behaved. */
3821 else if (GET_CODE (XEXP (x, 0)) == SUBREG && GET_MODE (x) == ptr_mode
3822 && GET_CODE (XEXP (x, 1)) == CONST_INT
3823 && 0 != (new
3824 = instantiate_new_reg (SUBREG_REG (XEXP (x, 0)),
3825 &offset))
3826 && validate_change (object, loc,
3827 plus_constant (gen_lowpart (ptr_mode,
3828 new),
3829 offset
3830 + INTVAL (XEXP (x, 1))),
3831 0))
3832 return 1;
3833 #endif
3834 else if ((new = instantiate_new_reg (XEXP (x, 0), &offset)) == 0)
3835 {
3836 /* We know the second operand is a constant. Unless the
3837 first operand is a REG (which has been already checked),
3838 it needs to be checked. */
3839 if (GET_CODE (XEXP (x, 0)) != REG)
3840 {
3841 loc = &XEXP (x, 0);
3842 goto restart;
3843 }
3844 return 1;
3845 }
3846
3847 new_offset = plus_constant (XEXP (x, 1), offset);
3848
3849 /* If the new constant is zero, try to replace the sum with just
3850 the register. */
3851 if (new_offset == const0_rtx
3852 && validate_change (object, loc, new, 0))
3853 return 1;
3854
3855 /* Next try to replace the register and new offset.
3856 There are two changes to validate here and we can't assume that
3857 in the case of old offset equals new just changing the register
3858 will yield a valid insn. In the interests of a little efficiency,
3859 however, we only call validate change once (we don't queue up the
3860 changes and then call apply_change_group). */
3861
3862 old = XEXP (x, 0);
3863 if (offset == 0
3864 ? ! validate_change (object, &XEXP (x, 0), new, 0)
3865 : (XEXP (x, 0) = new,
3866 ! validate_change (object, &XEXP (x, 1), new_offset, 0)))
3867 {
3868 if (! extra_insns)
3869 {
3870 XEXP (x, 0) = old;
3871 return 0;
3872 }
3873
3874 /* Otherwise copy the new constant into a register and replace
3875 constant with that register. */
3876 temp = gen_reg_rtx (Pmode);
3877 XEXP (x, 0) = new;
3878 if (validate_change (object, &XEXP (x, 1), temp, 0))
3879 emit_insn_before (gen_move_insn (temp, new_offset), object);
3880 else
3881 {
3882 /* If that didn't work, replace this expression with a
3883 register containing the sum. */
3884
3885 XEXP (x, 0) = old;
3886 new = gen_rtx_PLUS (Pmode, new, new_offset);
3887
3888 start_sequence ();
3889 temp = force_operand (new, NULL_RTX);
3890 seq = get_insns ();
3891 end_sequence ();
3892
3893 emit_insn_before (seq, object);
3894 if (! validate_change (object, loc, temp, 0)
3895 && ! validate_replace_rtx (x, temp, object))
3896 abort ();
3897 }
3898 }
3899
3900 return 1;
3901 }
3902
3903 /* Fall through to generic two-operand expression case. */
3904 case EXPR_LIST:
3905 case CALL:
3906 case COMPARE:
3907 case MINUS:
3908 case MULT:
3909 case DIV: case UDIV:
3910 case MOD: case UMOD:
3911 case AND: case IOR: case XOR:
3912 case ROTATERT: case ROTATE:
3913 case ASHIFTRT: case LSHIFTRT: case ASHIFT:
3914 case NE: case EQ:
3915 case GE: case GT: case GEU: case GTU:
3916 case LE: case LT: case LEU: case LTU:
3917 if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1)))
3918 instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns);
3919 loc = &XEXP (x, 0);
3920 goto restart;
3921
3922 case MEM:
3923 /* Most cases of MEM that convert to valid addresses have already been
3924 handled by our scan of decls. The only special handling we
3925 need here is to make a copy of the rtx to ensure it isn't being
3926 shared if we have to change it to a pseudo.
3927
3928 If the rtx is a simple reference to an address via a virtual register,
3929 it can potentially be shared. In such cases, first try to make it
3930 a valid address, which can also be shared. Otherwise, copy it and
3931 proceed normally.
3932
3933 First check for common cases that need no processing. These are
3934 usually due to instantiation already being done on a previous instance
3935 of a shared rtx. */
3936
3937 temp = XEXP (x, 0);
3938 if (CONSTANT_ADDRESS_P (temp)
3939 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3940 || temp == arg_pointer_rtx
3941 #endif
3942 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3943 || temp == hard_frame_pointer_rtx
3944 #endif
3945 || temp == frame_pointer_rtx)
3946 return 1;
3947
3948 if (GET_CODE (temp) == PLUS
3949 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
3950 && (XEXP (temp, 0) == frame_pointer_rtx
3951 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3952 || XEXP (temp, 0) == hard_frame_pointer_rtx
3953 #endif
3954 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3955 || XEXP (temp, 0) == arg_pointer_rtx
3956 #endif
3957 ))
3958 return 1;
3959
3960 if (temp == virtual_stack_vars_rtx
3961 || temp == virtual_incoming_args_rtx
3962 || (GET_CODE (temp) == PLUS
3963 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
3964 && (XEXP (temp, 0) == virtual_stack_vars_rtx
3965 || XEXP (temp, 0) == virtual_incoming_args_rtx)))
3966 {
3967 /* This MEM may be shared. If the substitution can be done without
3968 the need to generate new pseudos, we want to do it in place
3969 so all copies of the shared rtx benefit. The call below will
3970 only make substitutions if the resulting address is still
3971 valid.
3972
3973 Note that we cannot pass X as the object in the recursive call
3974 since the insn being processed may not allow all valid
3975 addresses. However, if we were not passed on object, we can
3976 only modify X without copying it if X will have a valid
3977 address.
3978
3979 ??? Also note that this can still lose if OBJECT is an insn that
3980 has less restrictions on an address that some other insn.
3981 In that case, we will modify the shared address. This case
3982 doesn't seem very likely, though. One case where this could
3983 happen is in the case of a USE or CLOBBER reference, but we
3984 take care of that below. */
3985
3986 if (instantiate_virtual_regs_1 (&XEXP (x, 0),
3987 object ? object : x, 0))
3988 return 1;
3989
3990 /* Otherwise make a copy and process that copy. We copy the entire
3991 RTL expression since it might be a PLUS which could also be
3992 shared. */
3993 *loc = x = copy_rtx (x);
3994 }
3995
3996 /* Fall through to generic unary operation case. */
3997 case PREFETCH:
3998 case SUBREG:
3999 case STRICT_LOW_PART:
4000 case NEG: case NOT:
4001 case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC:
4002 case SIGN_EXTEND: case ZERO_EXTEND:
4003 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE:
4004 case FLOAT: case FIX:
4005 case UNSIGNED_FIX: case UNSIGNED_FLOAT:
4006 case ABS:
4007 case SQRT:
4008 case FFS:
4009 case CLZ: case CTZ:
4010 case POPCOUNT: case PARITY:
4011 /* These case either have just one operand or we know that we need not
4012 check the rest of the operands. */
4013 loc = &XEXP (x, 0);
4014 goto restart;
4015
4016 case USE:
4017 case CLOBBER:
4018 /* If the operand is a MEM, see if the change is a valid MEM. If not,
4019 go ahead and make the invalid one, but do it to a copy. For a REG,
4020 just make the recursive call, since there's no chance of a problem. */
4021
4022 if ((GET_CODE (XEXP (x, 0)) == MEM
4023 && instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), XEXP (x, 0),
4024 0))
4025 || (GET_CODE (XEXP (x, 0)) == REG
4026 && instantiate_virtual_regs_1 (&XEXP (x, 0), object, 0)))
4027 return 1;
4028
4029 XEXP (x, 0) = copy_rtx (XEXP (x, 0));
4030 loc = &XEXP (x, 0);
4031 goto restart;
4032
4033 case REG:
4034 /* Try to replace with a PLUS. If that doesn't work, compute the sum
4035 in front of this insn and substitute the temporary. */
4036 if ((new = instantiate_new_reg (x, &offset)) != 0)
4037 {
4038 temp = plus_constant (new, offset);
4039 if (!validate_change (object, loc, temp, 0))
4040 {
4041 if (! extra_insns)
4042 return 0;
4043
4044 start_sequence ();
4045 temp = force_operand (temp, NULL_RTX);
4046 seq = get_insns ();
4047 end_sequence ();
4048
4049 emit_insn_before (seq, object);
4050 if (! validate_change (object, loc, temp, 0)
4051 && ! validate_replace_rtx (x, temp, object))
4052 abort ();
4053 }
4054 }
4055
4056 return 1;
4057
4058 case ADDRESSOF:
4059 if (GET_CODE (XEXP (x, 0)) == REG)
4060 return 1;
4061
4062 else if (GET_CODE (XEXP (x, 0)) == MEM)
4063 {
4064 /* If we have a (addressof (mem ..)), do any instantiation inside
4065 since we know we'll be making the inside valid when we finally
4066 remove the ADDRESSOF. */
4067 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), NULL_RTX, 0);
4068 return 1;
4069 }
4070 break;
4071
4072 default:
4073 break;
4074 }
4075
4076 /* Scan all subexpressions. */
4077 fmt = GET_RTX_FORMAT (code);
4078 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
4079 if (*fmt == 'e')
4080 {
4081 if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns))
4082 return 0;
4083 }
4084 else if (*fmt == 'E')
4085 for (j = 0; j < XVECLEN (x, i); j++)
4086 if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object,
4087 extra_insns))
4088 return 0;
4089
4090 return 1;
4091 }
4092 \f
4093 /* Optimization: assuming this function does not receive nonlocal gotos,
4094 delete the handlers for such, as well as the insns to establish
4095 and disestablish them. */
4096
4097 static void
4098 delete_handlers ()
4099 {
4100 rtx insn;
4101 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4102 {
4103 /* Delete the handler by turning off the flag that would
4104 prevent jump_optimize from deleting it.
4105 Also permit deletion of the nonlocal labels themselves
4106 if nothing local refers to them. */
4107 if (GET_CODE (insn) == CODE_LABEL)
4108 {
4109 tree t, last_t;
4110
4111 LABEL_PRESERVE_P (insn) = 0;
4112
4113 /* Remove it from the nonlocal_label list, to avoid confusing
4114 flow. */
4115 for (t = nonlocal_labels, last_t = 0; t;
4116 last_t = t, t = TREE_CHAIN (t))
4117 if (DECL_RTL (TREE_VALUE (t)) == insn)
4118 break;
4119 if (t)
4120 {
4121 if (! last_t)
4122 nonlocal_labels = TREE_CHAIN (nonlocal_labels);
4123 else
4124 TREE_CHAIN (last_t) = TREE_CHAIN (t);
4125 }
4126 }
4127 if (GET_CODE (insn) == INSN)
4128 {
4129 int can_delete = 0;
4130 rtx t;
4131 for (t = nonlocal_goto_handler_slots; t != 0; t = XEXP (t, 1))
4132 if (reg_mentioned_p (t, PATTERN (insn)))
4133 {
4134 can_delete = 1;
4135 break;
4136 }
4137 if (can_delete
4138 || (nonlocal_goto_stack_level != 0
4139 && reg_mentioned_p (nonlocal_goto_stack_level,
4140 PATTERN (insn))))
4141 delete_related_insns (insn);
4142 }
4143 }
4144 }
4145 \f
4146 /* Return the first insn following those generated by `assign_parms'. */
4147
4148 rtx
4149 get_first_nonparm_insn ()
4150 {
4151 if (last_parm_insn)
4152 return NEXT_INSN (last_parm_insn);
4153 return get_insns ();
4154 }
4155
4156 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
4157 This means a type for which function calls must pass an address to the
4158 function or get an address back from the function.
4159 EXP may be a type node or an expression (whose type is tested). */
4160
4161 int
4162 aggregate_value_p (exp)
4163 tree exp;
4164 {
4165 int i, regno, nregs;
4166 rtx reg;
4167
4168 tree type = (TYPE_P (exp)) ? exp : TREE_TYPE (exp);
4169
4170 if (TREE_CODE (type) == VOID_TYPE)
4171 return 0;
4172 if (RETURN_IN_MEMORY (type))
4173 return 1;
4174 /* Types that are TREE_ADDRESSABLE must be constructed in memory,
4175 and thus can't be returned in registers. */
4176 if (TREE_ADDRESSABLE (type))
4177 return 1;
4178 if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
4179 return 1;
4180 /* Make sure we have suitable call-clobbered regs to return
4181 the value in; if not, we must return it in memory. */
4182 reg = hard_function_value (type, 0, 0);
4183
4184 /* If we have something other than a REG (e.g. a PARALLEL), then assume
4185 it is OK. */
4186 if (GET_CODE (reg) != REG)
4187 return 0;
4188
4189 regno = REGNO (reg);
4190 nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type));
4191 for (i = 0; i < nregs; i++)
4192 if (! call_used_regs[regno + i])
4193 return 1;
4194 return 0;
4195 }
4196 \f
4197 /* Assign RTL expressions to the function's parameters.
4198 This may involve copying them into registers and using
4199 those registers as the RTL for them. */
4200
4201 void
4202 assign_parms (fndecl)
4203 tree fndecl;
4204 {
4205 tree parm;
4206 rtx entry_parm = 0;
4207 rtx stack_parm = 0;
4208 CUMULATIVE_ARGS args_so_far;
4209 enum machine_mode promoted_mode, passed_mode;
4210 enum machine_mode nominal_mode, promoted_nominal_mode;
4211 int unsignedp;
4212 /* Total space needed so far for args on the stack,
4213 given as a constant and a tree-expression. */
4214 struct args_size stack_args_size;
4215 tree fntype = TREE_TYPE (fndecl);
4216 tree fnargs = DECL_ARGUMENTS (fndecl);
4217 /* This is used for the arg pointer when referring to stack args. */
4218 rtx internal_arg_pointer;
4219 /* This is a dummy PARM_DECL that we used for the function result if
4220 the function returns a structure. */
4221 tree function_result_decl = 0;
4222 #ifdef SETUP_INCOMING_VARARGS
4223 int varargs_setup = 0;
4224 #endif
4225 rtx conversion_insns = 0;
4226 struct args_size alignment_pad;
4227
4228 /* Nonzero if function takes extra anonymous args.
4229 This means the last named arg must be on the stack
4230 right before the anonymous ones. */
4231 int stdarg
4232 = (TYPE_ARG_TYPES (fntype) != 0
4233 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
4234 != void_type_node));
4235
4236 current_function_stdarg = stdarg;
4237
4238 /* If the reg that the virtual arg pointer will be translated into is
4239 not a fixed reg or is the stack pointer, make a copy of the virtual
4240 arg pointer, and address parms via the copy. The frame pointer is
4241 considered fixed even though it is not marked as such.
4242
4243 The second time through, simply use ap to avoid generating rtx. */
4244
4245 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
4246 || ! (fixed_regs[ARG_POINTER_REGNUM]
4247 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM)))
4248 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
4249 else
4250 internal_arg_pointer = virtual_incoming_args_rtx;
4251 current_function_internal_arg_pointer = internal_arg_pointer;
4252
4253 stack_args_size.constant = 0;
4254 stack_args_size.var = 0;
4255
4256 /* If struct value address is treated as the first argument, make it so. */
4257 if (aggregate_value_p (DECL_RESULT (fndecl))
4258 && ! current_function_returns_pcc_struct
4259 && struct_value_incoming_rtx == 0)
4260 {
4261 tree type = build_pointer_type (TREE_TYPE (fntype));
4262
4263 function_result_decl = build_decl (PARM_DECL, NULL_TREE, type);
4264
4265 DECL_ARG_TYPE (function_result_decl) = type;
4266 TREE_CHAIN (function_result_decl) = fnargs;
4267 fnargs = function_result_decl;
4268 }
4269
4270 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
4271 parm_reg_stack_loc = (rtx *) ggc_alloc_cleared (max_parm_reg * sizeof (rtx));
4272
4273 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
4274 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX);
4275 #else
4276 INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX, fndecl);
4277 #endif
4278
4279 /* We haven't yet found an argument that we must push and pretend the
4280 caller did. */
4281 current_function_pretend_args_size = 0;
4282
4283 for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
4284 {
4285 struct args_size stack_offset;
4286 struct args_size arg_size;
4287 int passed_pointer = 0;
4288 int did_conversion = 0;
4289 tree passed_type = DECL_ARG_TYPE (parm);
4290 tree nominal_type = TREE_TYPE (parm);
4291 int pretend_named;
4292 int last_named = 0, named_arg;
4293
4294 /* Set LAST_NAMED if this is last named arg before last
4295 anonymous args. */
4296 if (stdarg)
4297 {
4298 tree tem;
4299
4300 for (tem = TREE_CHAIN (parm); tem; tem = TREE_CHAIN (tem))
4301 if (DECL_NAME (tem))
4302 break;
4303
4304 if (tem == 0)
4305 last_named = 1;
4306 }
4307 /* Set NAMED_ARG if this arg should be treated as a named arg. For
4308 most machines, if this is a varargs/stdarg function, then we treat
4309 the last named arg as if it were anonymous too. */
4310 named_arg = STRICT_ARGUMENT_NAMING ? 1 : ! last_named;
4311
4312 if (TREE_TYPE (parm) == error_mark_node
4313 /* This can happen after weird syntax errors
4314 or if an enum type is defined among the parms. */
4315 || TREE_CODE (parm) != PARM_DECL
4316 || passed_type == NULL)
4317 {
4318 SET_DECL_RTL (parm, gen_rtx_MEM (BLKmode, const0_rtx));
4319 DECL_INCOMING_RTL (parm) = DECL_RTL (parm);
4320 TREE_USED (parm) = 1;
4321 continue;
4322 }
4323
4324 /* Find mode of arg as it is passed, and mode of arg
4325 as it should be during execution of this function. */
4326 passed_mode = TYPE_MODE (passed_type);
4327 nominal_mode = TYPE_MODE (nominal_type);
4328
4329 /* If the parm's mode is VOID, its value doesn't matter,
4330 and avoid the usual things like emit_move_insn that could crash. */
4331 if (nominal_mode == VOIDmode)
4332 {
4333 SET_DECL_RTL (parm, const0_rtx);
4334 DECL_INCOMING_RTL (parm) = DECL_RTL (parm);
4335 continue;
4336 }
4337
4338 /* If the parm is to be passed as a transparent union, use the
4339 type of the first field for the tests below. We have already
4340 verified that the modes are the same. */
4341 if (DECL_TRANSPARENT_UNION (parm)
4342 || (TREE_CODE (passed_type) == UNION_TYPE
4343 && TYPE_TRANSPARENT_UNION (passed_type)))
4344 passed_type = TREE_TYPE (TYPE_FIELDS (passed_type));
4345
4346 /* See if this arg was passed by invisible reference. It is if
4347 it is an object whose size depends on the contents of the
4348 object itself or if the machine requires these objects be passed
4349 that way. */
4350
4351 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
4352 && contains_placeholder_p (TYPE_SIZE (passed_type)))
4353 || TREE_ADDRESSABLE (passed_type)
4354 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
4355 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode,
4356 passed_type, named_arg)
4357 #endif
4358 )
4359 {
4360 passed_type = nominal_type = build_pointer_type (passed_type);
4361 passed_pointer = 1;
4362 passed_mode = nominal_mode = Pmode;
4363 }
4364 /* See if the frontend wants to pass this by invisible reference. */
4365 else if (passed_type != nominal_type
4366 && POINTER_TYPE_P (passed_type)
4367 && TREE_TYPE (passed_type) == nominal_type)
4368 {
4369 nominal_type = passed_type;
4370 passed_pointer = 1;
4371 passed_mode = nominal_mode = Pmode;
4372 }
4373
4374 promoted_mode = passed_mode;
4375
4376 #ifdef PROMOTE_FUNCTION_ARGS
4377 /* Compute the mode in which the arg is actually extended to. */
4378 unsignedp = TREE_UNSIGNED (passed_type);
4379 promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1);
4380 #endif
4381
4382 /* Let machine desc say which reg (if any) the parm arrives in.
4383 0 means it arrives on the stack. */
4384 #ifdef FUNCTION_INCOMING_ARG
4385 entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
4386 passed_type, named_arg);
4387 #else
4388 entry_parm = FUNCTION_ARG (args_so_far, promoted_mode,
4389 passed_type, named_arg);
4390 #endif
4391
4392 if (entry_parm == 0)
4393 promoted_mode = passed_mode;
4394
4395 #ifdef SETUP_INCOMING_VARARGS
4396 /* If this is the last named parameter, do any required setup for
4397 varargs or stdargs. We need to know about the case of this being an
4398 addressable type, in which case we skip the registers it
4399 would have arrived in.
4400
4401 For stdargs, LAST_NAMED will be set for two parameters, the one that
4402 is actually the last named, and the dummy parameter. We only
4403 want to do this action once.
4404
4405 Also, indicate when RTL generation is to be suppressed. */
4406 if (last_named && !varargs_setup)
4407 {
4408 SETUP_INCOMING_VARARGS (args_so_far, promoted_mode, passed_type,
4409 current_function_pretend_args_size, 0);
4410 varargs_setup = 1;
4411 }
4412 #endif
4413
4414 /* Determine parm's home in the stack,
4415 in case it arrives in the stack or we should pretend it did.
4416
4417 Compute the stack position and rtx where the argument arrives
4418 and its size.
4419
4420 There is one complexity here: If this was a parameter that would
4421 have been passed in registers, but wasn't only because it is
4422 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
4423 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
4424 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
4425 0 as it was the previous time. */
4426
4427 pretend_named = named_arg || PRETEND_OUTGOING_VARARGS_NAMED;
4428 locate_and_pad_parm (promoted_mode, passed_type,
4429 #ifdef STACK_PARMS_IN_REG_PARM_AREA
4430 1,
4431 #else
4432 #ifdef FUNCTION_INCOMING_ARG
4433 FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
4434 passed_type,
4435 pretend_named) != 0,
4436 #else
4437 FUNCTION_ARG (args_so_far, promoted_mode,
4438 passed_type,
4439 pretend_named) != 0,
4440 #endif
4441 #endif
4442 fndecl, &stack_args_size, &stack_offset, &arg_size,
4443 &alignment_pad);
4444
4445 {
4446 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
4447
4448 if (offset_rtx == const0_rtx)
4449 stack_parm = gen_rtx_MEM (promoted_mode, internal_arg_pointer);
4450 else
4451 stack_parm = gen_rtx_MEM (promoted_mode,
4452 gen_rtx_PLUS (Pmode,
4453 internal_arg_pointer,
4454 offset_rtx));
4455
4456 set_mem_attributes (stack_parm, parm, 1);
4457 }
4458
4459 /* If this parameter was passed both in registers and in the stack,
4460 use the copy on the stack. */
4461 if (MUST_PASS_IN_STACK (promoted_mode, passed_type))
4462 entry_parm = 0;
4463
4464 #ifdef FUNCTION_ARG_PARTIAL_NREGS
4465 /* If this parm was passed part in regs and part in memory,
4466 pretend it arrived entirely in memory
4467 by pushing the register-part onto the stack.
4468
4469 In the special case of a DImode or DFmode that is split,
4470 we could put it together in a pseudoreg directly,
4471 but for now that's not worth bothering with. */
4472
4473 if (entry_parm)
4474 {
4475 int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, promoted_mode,
4476 passed_type, named_arg);
4477
4478 if (nregs > 0)
4479 {
4480 #if defined (REG_PARM_STACK_SPACE) && !defined (MAYBE_REG_PARM_STACK_SPACE)
4481 /* When REG_PARM_STACK_SPACE is nonzero, stack space for
4482 split parameters was allocated by our caller, so we
4483 won't be pushing it in the prolog. */
4484 if (REG_PARM_STACK_SPACE (fndecl) == 0)
4485 #endif
4486 current_function_pretend_args_size
4487 = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
4488 / (PARM_BOUNDARY / BITS_PER_UNIT)
4489 * (PARM_BOUNDARY / BITS_PER_UNIT));
4490
4491 /* Handle calls that pass values in multiple non-contiguous
4492 locations. The Irix 6 ABI has examples of this. */
4493 if (GET_CODE (entry_parm) == PARALLEL)
4494 emit_group_store (validize_mem (stack_parm), entry_parm,
4495 int_size_in_bytes (TREE_TYPE (parm)));
4496
4497 else
4498 move_block_from_reg (REGNO (entry_parm),
4499 validize_mem (stack_parm), nregs,
4500 int_size_in_bytes (TREE_TYPE (parm)));
4501
4502 entry_parm = stack_parm;
4503 }
4504 }
4505 #endif
4506
4507 /* If we didn't decide this parm came in a register,
4508 by default it came on the stack. */
4509 if (entry_parm == 0)
4510 entry_parm = stack_parm;
4511
4512 /* Record permanently how this parm was passed. */
4513 DECL_INCOMING_RTL (parm) = entry_parm;
4514
4515 /* If there is actually space on the stack for this parm,
4516 count it in stack_args_size; otherwise set stack_parm to 0
4517 to indicate there is no preallocated stack slot for the parm. */
4518
4519 if (entry_parm == stack_parm
4520 || (GET_CODE (entry_parm) == PARALLEL
4521 && XEXP (XVECEXP (entry_parm, 0, 0), 0) == NULL_RTX)
4522 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
4523 /* On some machines, even if a parm value arrives in a register
4524 there is still an (uninitialized) stack slot allocated for it.
4525
4526 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
4527 whether this parameter already has a stack slot allocated,
4528 because an arg block exists only if current_function_args_size
4529 is larger than some threshold, and we haven't calculated that
4530 yet. So, for now, we just assume that stack slots never exist
4531 in this case. */
4532 || REG_PARM_STACK_SPACE (fndecl) > 0
4533 #endif
4534 )
4535 {
4536 stack_args_size.constant += arg_size.constant;
4537 if (arg_size.var)
4538 ADD_PARM_SIZE (stack_args_size, arg_size.var);
4539 }
4540 else
4541 /* No stack slot was pushed for this parm. */
4542 stack_parm = 0;
4543
4544 /* Update info on where next arg arrives in registers. */
4545
4546 FUNCTION_ARG_ADVANCE (args_so_far, promoted_mode,
4547 passed_type, named_arg);
4548
4549 /* If we can't trust the parm stack slot to be aligned enough
4550 for its ultimate type, don't use that slot after entry.
4551 We'll make another stack slot, if we need one. */
4552 {
4553 unsigned int thisparm_boundary
4554 = FUNCTION_ARG_BOUNDARY (promoted_mode, passed_type);
4555
4556 if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary)
4557 stack_parm = 0;
4558 }
4559
4560 /* If parm was passed in memory, and we need to convert it on entry,
4561 don't store it back in that same slot. */
4562 if (entry_parm != 0
4563 && nominal_mode != BLKmode && nominal_mode != passed_mode)
4564 stack_parm = 0;
4565
4566 /* When an argument is passed in multiple locations, we can't
4567 make use of this information, but we can save some copying if
4568 the whole argument is passed in a single register. */
4569 if (GET_CODE (entry_parm) == PARALLEL
4570 && nominal_mode != BLKmode && passed_mode != BLKmode)
4571 {
4572 int i, len = XVECLEN (entry_parm, 0);
4573
4574 for (i = 0; i < len; i++)
4575 if (XEXP (XVECEXP (entry_parm, 0, i), 0) != NULL_RTX
4576 && GET_CODE (XEXP (XVECEXP (entry_parm, 0, i), 0)) == REG
4577 && (GET_MODE (XEXP (XVECEXP (entry_parm, 0, i), 0))
4578 == passed_mode)
4579 && INTVAL (XEXP (XVECEXP (entry_parm, 0, i), 1)) == 0)
4580 {
4581 entry_parm = XEXP (XVECEXP (entry_parm, 0, i), 0);
4582 DECL_INCOMING_RTL (parm) = entry_parm;
4583 break;
4584 }
4585 }
4586
4587 /* ENTRY_PARM is an RTX for the parameter as it arrives,
4588 in the mode in which it arrives.
4589 STACK_PARM is an RTX for a stack slot where the parameter can live
4590 during the function (in case we want to put it there).
4591 STACK_PARM is 0 if no stack slot was pushed for it.
4592
4593 Now output code if necessary to convert ENTRY_PARM to
4594 the type in which this function declares it,
4595 and store that result in an appropriate place,
4596 which may be a pseudo reg, may be STACK_PARM,
4597 or may be a local stack slot if STACK_PARM is 0.
4598
4599 Set DECL_RTL to that place. */
4600
4601 if (nominal_mode == BLKmode || GET_CODE (entry_parm) == PARALLEL)
4602 {
4603 /* If a BLKmode arrives in registers, copy it to a stack slot.
4604 Handle calls that pass values in multiple non-contiguous
4605 locations. The Irix 6 ABI has examples of this. */
4606 if (GET_CODE (entry_parm) == REG
4607 || GET_CODE (entry_parm) == PARALLEL)
4608 {
4609 int size_stored
4610 = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)),
4611 UNITS_PER_WORD);
4612
4613 /* Note that we will be storing an integral number of words.
4614 So we have to be careful to ensure that we allocate an
4615 integral number of words. We do this below in the
4616 assign_stack_local if space was not allocated in the argument
4617 list. If it was, this will not work if PARM_BOUNDARY is not
4618 a multiple of BITS_PER_WORD. It isn't clear how to fix this
4619 if it becomes a problem. */
4620
4621 if (stack_parm == 0)
4622 {
4623 stack_parm
4624 = assign_stack_local (GET_MODE (entry_parm),
4625 size_stored, 0);
4626 set_mem_attributes (stack_parm, parm, 1);
4627 }
4628
4629 else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
4630 abort ();
4631
4632 /* Handle calls that pass values in multiple non-contiguous
4633 locations. The Irix 6 ABI has examples of this. */
4634 if (GET_CODE (entry_parm) == PARALLEL)
4635 emit_group_store (validize_mem (stack_parm), entry_parm,
4636 int_size_in_bytes (TREE_TYPE (parm)));
4637 else
4638 move_block_from_reg (REGNO (entry_parm),
4639 validize_mem (stack_parm),
4640 size_stored / UNITS_PER_WORD,
4641 int_size_in_bytes (TREE_TYPE (parm)));
4642 }
4643 SET_DECL_RTL (parm, stack_parm);
4644 }
4645 else if (! ((! optimize
4646 && ! DECL_REGISTER (parm))
4647 || TREE_SIDE_EFFECTS (parm)
4648 /* If -ffloat-store specified, don't put explicit
4649 float variables into registers. */
4650 || (flag_float_store
4651 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
4652 /* Always assign pseudo to structure return or item passed
4653 by invisible reference. */
4654 || passed_pointer || parm == function_result_decl)
4655 {
4656 /* Store the parm in a pseudoregister during the function, but we
4657 may need to do it in a wider mode. */
4658
4659 rtx parmreg;
4660 unsigned int regno, regnoi = 0, regnor = 0;
4661
4662 unsignedp = TREE_UNSIGNED (TREE_TYPE (parm));
4663
4664 promoted_nominal_mode
4665 = promote_mode (TREE_TYPE (parm), nominal_mode, &unsignedp, 0);
4666
4667 parmreg = gen_reg_rtx (promoted_nominal_mode);
4668 mark_user_reg (parmreg);
4669
4670 /* If this was an item that we received a pointer to, set DECL_RTL
4671 appropriately. */
4672 if (passed_pointer)
4673 {
4674 rtx x = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (passed_type)),
4675 parmreg);
4676 set_mem_attributes (x, parm, 1);
4677 SET_DECL_RTL (parm, x);
4678 }
4679 else
4680 {
4681 SET_DECL_RTL (parm, parmreg);
4682 maybe_set_unchanging (DECL_RTL (parm), parm);
4683 }
4684
4685 /* Copy the value into the register. */
4686 if (nominal_mode != passed_mode
4687 || promoted_nominal_mode != promoted_mode)
4688 {
4689 int save_tree_used;
4690 /* ENTRY_PARM has been converted to PROMOTED_MODE, its
4691 mode, by the caller. We now have to convert it to
4692 NOMINAL_MODE, if different. However, PARMREG may be in
4693 a different mode than NOMINAL_MODE if it is being stored
4694 promoted.
4695
4696 If ENTRY_PARM is a hard register, it might be in a register
4697 not valid for operating in its mode (e.g., an odd-numbered
4698 register for a DFmode). In that case, moves are the only
4699 thing valid, so we can't do a convert from there. This
4700 occurs when the calling sequence allow such misaligned
4701 usages.
4702
4703 In addition, the conversion may involve a call, which could
4704 clobber parameters which haven't been copied to pseudo
4705 registers yet. Therefore, we must first copy the parm to
4706 a pseudo reg here, and save the conversion until after all
4707 parameters have been moved. */
4708
4709 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
4710
4711 emit_move_insn (tempreg, validize_mem (entry_parm));
4712
4713 push_to_sequence (conversion_insns);
4714 tempreg = convert_to_mode (nominal_mode, tempreg, unsignedp);
4715
4716 if (GET_CODE (tempreg) == SUBREG
4717 && GET_MODE (tempreg) == nominal_mode
4718 && GET_CODE (SUBREG_REG (tempreg)) == REG
4719 && nominal_mode == passed_mode
4720 && GET_MODE (SUBREG_REG (tempreg)) == GET_MODE (entry_parm)
4721 && GET_MODE_SIZE (GET_MODE (tempreg))
4722 < GET_MODE_SIZE (GET_MODE (entry_parm)))
4723 {
4724 /* The argument is already sign/zero extended, so note it
4725 into the subreg. */
4726 SUBREG_PROMOTED_VAR_P (tempreg) = 1;
4727 SUBREG_PROMOTED_UNSIGNED_SET (tempreg, unsignedp);
4728 }
4729
4730 /* TREE_USED gets set erroneously during expand_assignment. */
4731 save_tree_used = TREE_USED (parm);
4732 expand_assignment (parm,
4733 make_tree (nominal_type, tempreg), 0, 0);
4734 TREE_USED (parm) = save_tree_used;
4735 conversion_insns = get_insns ();
4736 did_conversion = 1;
4737 end_sequence ();
4738 }
4739 else
4740 emit_move_insn (parmreg, validize_mem (entry_parm));
4741
4742 /* If we were passed a pointer but the actual value
4743 can safely live in a register, put it in one. */
4744 if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
4745 /* If by-reference argument was promoted, demote it. */
4746 && (TYPE_MODE (TREE_TYPE (parm)) != GET_MODE (DECL_RTL (parm))
4747 || ! ((! optimize
4748 && ! DECL_REGISTER (parm))
4749 || TREE_SIDE_EFFECTS (parm)
4750 /* If -ffloat-store specified, don't put explicit
4751 float variables into registers. */
4752 || (flag_float_store
4753 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))))
4754 {
4755 /* We can't use nominal_mode, because it will have been set to
4756 Pmode above. We must use the actual mode of the parm. */
4757 parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
4758 mark_user_reg (parmreg);
4759 if (GET_MODE (parmreg) != GET_MODE (DECL_RTL (parm)))
4760 {
4761 rtx tempreg = gen_reg_rtx (GET_MODE (DECL_RTL (parm)));
4762 int unsigned_p = TREE_UNSIGNED (TREE_TYPE (parm));
4763 push_to_sequence (conversion_insns);
4764 emit_move_insn (tempreg, DECL_RTL (parm));
4765 SET_DECL_RTL (parm,
4766 convert_to_mode (GET_MODE (parmreg),
4767 tempreg,
4768 unsigned_p));
4769 emit_move_insn (parmreg, DECL_RTL (parm));
4770 conversion_insns = get_insns();
4771 did_conversion = 1;
4772 end_sequence ();
4773 }
4774 else
4775 emit_move_insn (parmreg, DECL_RTL (parm));
4776 SET_DECL_RTL (parm, parmreg);
4777 /* STACK_PARM is the pointer, not the parm, and PARMREG is
4778 now the parm. */
4779 stack_parm = 0;
4780 }
4781 #ifdef FUNCTION_ARG_CALLEE_COPIES
4782 /* If we are passed an arg by reference and it is our responsibility
4783 to make a copy, do it now.
4784 PASSED_TYPE and PASSED mode now refer to the pointer, not the
4785 original argument, so we must recreate them in the call to
4786 FUNCTION_ARG_CALLEE_COPIES. */
4787 /* ??? Later add code to handle the case that if the argument isn't
4788 modified, don't do the copy. */
4789
4790 else if (passed_pointer
4791 && FUNCTION_ARG_CALLEE_COPIES (args_so_far,
4792 TYPE_MODE (DECL_ARG_TYPE (parm)),
4793 DECL_ARG_TYPE (parm),
4794 named_arg)
4795 && ! TREE_ADDRESSABLE (DECL_ARG_TYPE (parm)))
4796 {
4797 rtx copy;
4798 tree type = DECL_ARG_TYPE (parm);
4799
4800 /* This sequence may involve a library call perhaps clobbering
4801 registers that haven't been copied to pseudos yet. */
4802
4803 push_to_sequence (conversion_insns);
4804
4805 if (!COMPLETE_TYPE_P (type)
4806 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4807 /* This is a variable sized object. */
4808 copy = gen_rtx_MEM (BLKmode,
4809 allocate_dynamic_stack_space
4810 (expr_size (parm), NULL_RTX,
4811 TYPE_ALIGN (type)));
4812 else
4813 copy = assign_stack_temp (TYPE_MODE (type),
4814 int_size_in_bytes (type), 1);
4815 set_mem_attributes (copy, parm, 1);
4816
4817 store_expr (parm, copy, 0);
4818 emit_move_insn (parmreg, XEXP (copy, 0));
4819 conversion_insns = get_insns ();
4820 did_conversion = 1;
4821 end_sequence ();
4822 }
4823 #endif /* FUNCTION_ARG_CALLEE_COPIES */
4824
4825 /* In any case, record the parm's desired stack location
4826 in case we later discover it must live in the stack.
4827
4828 If it is a COMPLEX value, store the stack location for both
4829 halves. */
4830
4831 if (GET_CODE (parmreg) == CONCAT)
4832 regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1)));
4833 else
4834 regno = REGNO (parmreg);
4835
4836 if (regno >= max_parm_reg)
4837 {
4838 rtx *new;
4839 int old_max_parm_reg = max_parm_reg;
4840
4841 /* It's slow to expand this one register at a time,
4842 but it's also rare and we need max_parm_reg to be
4843 precisely correct. */
4844 max_parm_reg = regno + 1;
4845 new = (rtx *) ggc_realloc (parm_reg_stack_loc,
4846 max_parm_reg * sizeof (rtx));
4847 memset ((char *) (new + old_max_parm_reg), 0,
4848 (max_parm_reg - old_max_parm_reg) * sizeof (rtx));
4849 parm_reg_stack_loc = new;
4850 }
4851
4852 if (GET_CODE (parmreg) == CONCAT)
4853 {
4854 enum machine_mode submode = GET_MODE (XEXP (parmreg, 0));
4855
4856 regnor = REGNO (gen_realpart (submode, parmreg));
4857 regnoi = REGNO (gen_imagpart (submode, parmreg));
4858
4859 if (stack_parm != 0)
4860 {
4861 parm_reg_stack_loc[regnor]
4862 = gen_realpart (submode, stack_parm);
4863 parm_reg_stack_loc[regnoi]
4864 = gen_imagpart (submode, stack_parm);
4865 }
4866 else
4867 {
4868 parm_reg_stack_loc[regnor] = 0;
4869 parm_reg_stack_loc[regnoi] = 0;
4870 }
4871 }
4872 else
4873 parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
4874
4875 /* Mark the register as eliminable if we did no conversion
4876 and it was copied from memory at a fixed offset,
4877 and the arg pointer was not copied to a pseudo-reg.
4878 If the arg pointer is a pseudo reg or the offset formed
4879 an invalid address, such memory-equivalences
4880 as we make here would screw up life analysis for it. */
4881 if (nominal_mode == passed_mode
4882 && ! did_conversion
4883 && stack_parm != 0
4884 && GET_CODE (stack_parm) == MEM
4885 && stack_offset.var == 0
4886 && reg_mentioned_p (virtual_incoming_args_rtx,
4887 XEXP (stack_parm, 0)))
4888 {
4889 rtx linsn = get_last_insn ();
4890 rtx sinsn, set;
4891
4892 /* Mark complex types separately. */
4893 if (GET_CODE (parmreg) == CONCAT)
4894 /* Scan backwards for the set of the real and
4895 imaginary parts. */
4896 for (sinsn = linsn; sinsn != 0;
4897 sinsn = prev_nonnote_insn (sinsn))
4898 {
4899 set = single_set (sinsn);
4900 if (set != 0
4901 && SET_DEST (set) == regno_reg_rtx [regnoi])
4902 REG_NOTES (sinsn)
4903 = gen_rtx_EXPR_LIST (REG_EQUIV,
4904 parm_reg_stack_loc[regnoi],
4905 REG_NOTES (sinsn));
4906 else if (set != 0
4907 && SET_DEST (set) == regno_reg_rtx [regnor])
4908 REG_NOTES (sinsn)
4909 = gen_rtx_EXPR_LIST (REG_EQUIV,
4910 parm_reg_stack_loc[regnor],
4911 REG_NOTES (sinsn));
4912 }
4913 else if ((set = single_set (linsn)) != 0
4914 && SET_DEST (set) == parmreg)
4915 REG_NOTES (linsn)
4916 = gen_rtx_EXPR_LIST (REG_EQUIV,
4917 stack_parm, REG_NOTES (linsn));
4918 }
4919
4920 /* For pointer data type, suggest pointer register. */
4921 if (POINTER_TYPE_P (TREE_TYPE (parm)))
4922 mark_reg_pointer (parmreg,
4923 TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm))));
4924
4925 /* If something wants our address, try to use ADDRESSOF. */
4926 if (TREE_ADDRESSABLE (parm))
4927 {
4928 /* If we end up putting something into the stack,
4929 fixup_var_refs_insns will need to make a pass over
4930 all the instructions. It looks through the pending
4931 sequences -- but it can't see the ones in the
4932 CONVERSION_INSNS, if they're not on the sequence
4933 stack. So, we go back to that sequence, just so that
4934 the fixups will happen. */
4935 push_to_sequence (conversion_insns);
4936 put_var_into_stack (parm);
4937 conversion_insns = get_insns ();
4938 end_sequence ();
4939 }
4940 }
4941 else
4942 {
4943 /* Value must be stored in the stack slot STACK_PARM
4944 during function execution. */
4945
4946 if (promoted_mode != nominal_mode)
4947 {
4948 /* Conversion is required. */
4949 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
4950
4951 emit_move_insn (tempreg, validize_mem (entry_parm));
4952
4953 push_to_sequence (conversion_insns);
4954 entry_parm = convert_to_mode (nominal_mode, tempreg,
4955 TREE_UNSIGNED (TREE_TYPE (parm)));
4956 if (stack_parm)
4957 /* ??? This may need a big-endian conversion on sparc64. */
4958 stack_parm = adjust_address (stack_parm, nominal_mode, 0);
4959
4960 conversion_insns = get_insns ();
4961 did_conversion = 1;
4962 end_sequence ();
4963 }
4964
4965 if (entry_parm != stack_parm)
4966 {
4967 if (stack_parm == 0)
4968 {
4969 stack_parm
4970 = assign_stack_local (GET_MODE (entry_parm),
4971 GET_MODE_SIZE (GET_MODE (entry_parm)), 0);
4972 set_mem_attributes (stack_parm, parm, 1);
4973 }
4974
4975 if (promoted_mode != nominal_mode)
4976 {
4977 push_to_sequence (conversion_insns);
4978 emit_move_insn (validize_mem (stack_parm),
4979 validize_mem (entry_parm));
4980 conversion_insns = get_insns ();
4981 end_sequence ();
4982 }
4983 else
4984 emit_move_insn (validize_mem (stack_parm),
4985 validize_mem (entry_parm));
4986 }
4987
4988 SET_DECL_RTL (parm, stack_parm);
4989 }
4990
4991 /* If this "parameter" was the place where we are receiving the
4992 function's incoming structure pointer, set up the result. */
4993 if (parm == function_result_decl)
4994 {
4995 tree result = DECL_RESULT (fndecl);
4996 rtx addr = DECL_RTL (parm);
4997 rtx x;
4998
4999 #ifdef POINTERS_EXTEND_UNSIGNED
5000 if (GET_MODE (addr) != Pmode)
5001 addr = convert_memory_address (Pmode, addr);
5002 #endif
5003
5004 x = gen_rtx_MEM (DECL_MODE (result), addr);
5005 set_mem_attributes (x, result, 1);
5006 SET_DECL_RTL (result, x);
5007 }
5008 }
5009
5010 /* Output all parameter conversion instructions (possibly including calls)
5011 now that all parameters have been copied out of hard registers. */
5012 emit_insn (conversion_insns);
5013
5014 last_parm_insn = get_last_insn ();
5015
5016 current_function_args_size = stack_args_size.constant;
5017
5018 /* Adjust function incoming argument size for alignment and
5019 minimum length. */
5020
5021 #ifdef REG_PARM_STACK_SPACE
5022 #ifndef MAYBE_REG_PARM_STACK_SPACE
5023 current_function_args_size = MAX (current_function_args_size,
5024 REG_PARM_STACK_SPACE (fndecl));
5025 #endif
5026 #endif
5027
5028 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
5029
5030 current_function_args_size
5031 = ((current_function_args_size + STACK_BYTES - 1)
5032 / STACK_BYTES) * STACK_BYTES;
5033
5034 #ifdef ARGS_GROW_DOWNWARD
5035 current_function_arg_offset_rtx
5036 = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant)
5037 : expand_expr (size_diffop (stack_args_size.var,
5038 size_int (-stack_args_size.constant)),
5039 NULL_RTX, VOIDmode, 0));
5040 #else
5041 current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
5042 #endif
5043
5044 /* See how many bytes, if any, of its args a function should try to pop
5045 on return. */
5046
5047 current_function_pops_args = RETURN_POPS_ARGS (fndecl, TREE_TYPE (fndecl),
5048 current_function_args_size);
5049
5050 /* For stdarg.h function, save info about
5051 regs and stack space used by the named args. */
5052
5053 current_function_args_info = args_so_far;
5054
5055 /* Set the rtx used for the function return value. Put this in its
5056 own variable so any optimizers that need this information don't have
5057 to include tree.h. Do this here so it gets done when an inlined
5058 function gets output. */
5059
5060 current_function_return_rtx
5061 = (DECL_RTL_SET_P (DECL_RESULT (fndecl))
5062 ? DECL_RTL (DECL_RESULT (fndecl)) : NULL_RTX);
5063
5064 /* If scalar return value was computed in a pseudo-reg, or was a named
5065 return value that got dumped to the stack, copy that to the hard
5066 return register. */
5067 if (DECL_RTL_SET_P (DECL_RESULT (fndecl)))
5068 {
5069 tree decl_result = DECL_RESULT (fndecl);
5070 rtx decl_rtl = DECL_RTL (decl_result);
5071
5072 if (REG_P (decl_rtl)
5073 ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
5074 : DECL_REGISTER (decl_result))
5075 {
5076 rtx real_decl_rtl;
5077
5078 #ifdef FUNCTION_OUTGOING_VALUE
5079 real_decl_rtl = FUNCTION_OUTGOING_VALUE (TREE_TYPE (decl_result),
5080 fndecl);
5081 #else
5082 real_decl_rtl = FUNCTION_VALUE (TREE_TYPE (decl_result),
5083 fndecl);
5084 #endif
5085 REG_FUNCTION_VALUE_P (real_decl_rtl) = 1;
5086 /* The delay slot scheduler assumes that current_function_return_rtx
5087 holds the hard register containing the return value, not a
5088 temporary pseudo. */
5089 current_function_return_rtx = real_decl_rtl;
5090 }
5091 }
5092 }
5093 \f
5094 /* Indicate whether REGNO is an incoming argument to the current function
5095 that was promoted to a wider mode. If so, return the RTX for the
5096 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
5097 that REGNO is promoted from and whether the promotion was signed or
5098 unsigned. */
5099
5100 #ifdef PROMOTE_FUNCTION_ARGS
5101
5102 rtx
5103 promoted_input_arg (regno, pmode, punsignedp)
5104 unsigned int regno;
5105 enum machine_mode *pmode;
5106 int *punsignedp;
5107 {
5108 tree arg;
5109
5110 for (arg = DECL_ARGUMENTS (current_function_decl); arg;
5111 arg = TREE_CHAIN (arg))
5112 if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
5113 && REGNO (DECL_INCOMING_RTL (arg)) == regno
5114 && TYPE_MODE (DECL_ARG_TYPE (arg)) == TYPE_MODE (TREE_TYPE (arg)))
5115 {
5116 enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
5117 int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
5118
5119 mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1);
5120 if (mode == GET_MODE (DECL_INCOMING_RTL (arg))
5121 && mode != DECL_MODE (arg))
5122 {
5123 *pmode = DECL_MODE (arg);
5124 *punsignedp = unsignedp;
5125 return DECL_INCOMING_RTL (arg);
5126 }
5127 }
5128
5129 return 0;
5130 }
5131
5132 #endif
5133 \f
5134 /* Compute the size and offset from the start of the stacked arguments for a
5135 parm passed in mode PASSED_MODE and with type TYPE.
5136
5137 INITIAL_OFFSET_PTR points to the current offset into the stacked
5138 arguments.
5139
5140 The starting offset and size for this parm are returned in *OFFSET_PTR
5141 and *ARG_SIZE_PTR, respectively.
5142
5143 IN_REGS is nonzero if the argument will be passed in registers. It will
5144 never be set if REG_PARM_STACK_SPACE is not defined.
5145
5146 FNDECL is the function in which the argument was defined.
5147
5148 There are two types of rounding that are done. The first, controlled by
5149 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
5150 list to be aligned to the specific boundary (in bits). This rounding
5151 affects the initial and starting offsets, but not the argument size.
5152
5153 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
5154 optionally rounds the size of the parm to PARM_BOUNDARY. The
5155 initial offset is not affected by this rounding, while the size always
5156 is and the starting offset may be. */
5157
5158 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
5159 initial_offset_ptr is positive because locate_and_pad_parm's
5160 callers pass in the total size of args so far as
5161 initial_offset_ptr. arg_size_ptr is always positive. */
5162
5163 void
5164 locate_and_pad_parm (passed_mode, type, in_regs, fndecl,
5165 initial_offset_ptr, offset_ptr, arg_size_ptr,
5166 alignment_pad)
5167 enum machine_mode passed_mode;
5168 tree type;
5169 int in_regs ATTRIBUTE_UNUSED;
5170 tree fndecl ATTRIBUTE_UNUSED;
5171 struct args_size *initial_offset_ptr;
5172 struct args_size *offset_ptr;
5173 struct args_size *arg_size_ptr;
5174 struct args_size *alignment_pad;
5175
5176 {
5177 tree sizetree
5178 = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
5179 enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
5180 int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
5181 #ifdef ARGS_GROW_DOWNWARD
5182 tree s2 = sizetree;
5183 #endif
5184
5185 #ifdef REG_PARM_STACK_SPACE
5186 /* If we have found a stack parm before we reach the end of the
5187 area reserved for registers, skip that area. */
5188 if (! in_regs)
5189 {
5190 int reg_parm_stack_space = 0;
5191
5192 #ifdef MAYBE_REG_PARM_STACK_SPACE
5193 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
5194 #else
5195 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
5196 #endif
5197 if (reg_parm_stack_space > 0)
5198 {
5199 if (initial_offset_ptr->var)
5200 {
5201 initial_offset_ptr->var
5202 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
5203 ssize_int (reg_parm_stack_space));
5204 initial_offset_ptr->constant = 0;
5205 }
5206 else if (initial_offset_ptr->constant < reg_parm_stack_space)
5207 initial_offset_ptr->constant = reg_parm_stack_space;
5208 }
5209 }
5210 #endif /* REG_PARM_STACK_SPACE */
5211
5212 arg_size_ptr->var = 0;
5213 arg_size_ptr->constant = 0;
5214 alignment_pad->var = 0;
5215 alignment_pad->constant = 0;
5216
5217 #ifdef ARGS_GROW_DOWNWARD
5218 if (initial_offset_ptr->var)
5219 {
5220 offset_ptr->constant = 0;
5221 offset_ptr->var = size_binop (MINUS_EXPR, ssize_int (0),
5222 initial_offset_ptr->var);
5223 }
5224 else
5225 {
5226 offset_ptr->constant = -initial_offset_ptr->constant;
5227 offset_ptr->var = 0;
5228 }
5229
5230 if (where_pad != none
5231 && (!host_integerp (sizetree, 1)
5232 || (tree_low_cst (sizetree, 1) * BITS_PER_UNIT) % PARM_BOUNDARY))
5233 s2 = round_up (s2, PARM_BOUNDARY / BITS_PER_UNIT);
5234 SUB_PARM_SIZE (*offset_ptr, s2);
5235
5236 if (!in_regs
5237 #ifdef REG_PARM_STACK_SPACE
5238 || REG_PARM_STACK_SPACE (fndecl) > 0
5239 #endif
5240 )
5241 pad_to_arg_alignment (offset_ptr, boundary, alignment_pad);
5242
5243 if (initial_offset_ptr->var)
5244 arg_size_ptr->var = size_binop (MINUS_EXPR,
5245 size_binop (MINUS_EXPR,
5246 ssize_int (0),
5247 initial_offset_ptr->var),
5248 offset_ptr->var);
5249
5250 else
5251 arg_size_ptr->constant = (-initial_offset_ptr->constant
5252 - offset_ptr->constant);
5253
5254 /* Pad_below needs the pre-rounded size to know how much to pad below.
5255 We only pad parameters which are not in registers as they have their
5256 padding done elsewhere. */
5257 if (where_pad == downward
5258 && !in_regs)
5259 pad_below (offset_ptr, passed_mode, sizetree);
5260
5261 #else /* !ARGS_GROW_DOWNWARD */
5262 if (!in_regs
5263 #ifdef REG_PARM_STACK_SPACE
5264 || REG_PARM_STACK_SPACE (fndecl) > 0
5265 #endif
5266 )
5267 pad_to_arg_alignment (initial_offset_ptr, boundary, alignment_pad);
5268 *offset_ptr = *initial_offset_ptr;
5269
5270 #ifdef PUSH_ROUNDING
5271 if (passed_mode != BLKmode)
5272 sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
5273 #endif
5274
5275 /* Pad_below needs the pre-rounded size to know how much to pad below
5276 so this must be done before rounding up. */
5277 if (where_pad == downward
5278 /* However, BLKmode args passed in regs have their padding done elsewhere.
5279 The stack slot must be able to hold the entire register. */
5280 && !(in_regs && passed_mode == BLKmode))
5281 pad_below (offset_ptr, passed_mode, sizetree);
5282
5283 if (where_pad != none
5284 && (!host_integerp (sizetree, 1)
5285 || (tree_low_cst (sizetree, 1) * BITS_PER_UNIT) % PARM_BOUNDARY))
5286 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
5287
5288 ADD_PARM_SIZE (*arg_size_ptr, sizetree);
5289 #endif /* ARGS_GROW_DOWNWARD */
5290 }
5291
5292 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
5293 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
5294
5295 static void
5296 pad_to_arg_alignment (offset_ptr, boundary, alignment_pad)
5297 struct args_size *offset_ptr;
5298 int boundary;
5299 struct args_size *alignment_pad;
5300 {
5301 tree save_var = NULL_TREE;
5302 HOST_WIDE_INT save_constant = 0;
5303
5304 int boundary_in_bytes = boundary / BITS_PER_UNIT;
5305
5306 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY)
5307 {
5308 save_var = offset_ptr->var;
5309 save_constant = offset_ptr->constant;
5310 }
5311
5312 alignment_pad->var = NULL_TREE;
5313 alignment_pad->constant = 0;
5314
5315 if (boundary > BITS_PER_UNIT)
5316 {
5317 if (offset_ptr->var)
5318 {
5319 offset_ptr->var =
5320 #ifdef ARGS_GROW_DOWNWARD
5321 round_down
5322 #else
5323 round_up
5324 #endif
5325 (ARGS_SIZE_TREE (*offset_ptr),
5326 boundary / BITS_PER_UNIT);
5327 offset_ptr->constant = 0; /*?*/
5328 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY)
5329 alignment_pad->var = size_binop (MINUS_EXPR, offset_ptr->var,
5330 save_var);
5331 }
5332 else
5333 {
5334 offset_ptr->constant =
5335 #ifdef ARGS_GROW_DOWNWARD
5336 FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes);
5337 #else
5338 CEIL_ROUND (offset_ptr->constant, boundary_in_bytes);
5339 #endif
5340 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY)
5341 alignment_pad->constant = offset_ptr->constant - save_constant;
5342 }
5343 }
5344 }
5345
5346 static void
5347 pad_below (offset_ptr, passed_mode, sizetree)
5348 struct args_size *offset_ptr;
5349 enum machine_mode passed_mode;
5350 tree sizetree;
5351 {
5352 if (passed_mode != BLKmode)
5353 {
5354 if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
5355 offset_ptr->constant
5356 += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
5357 / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
5358 - GET_MODE_SIZE (passed_mode));
5359 }
5360 else
5361 {
5362 if (TREE_CODE (sizetree) != INTEGER_CST
5363 || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
5364 {
5365 /* Round the size up to multiple of PARM_BOUNDARY bits. */
5366 tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
5367 /* Add it in. */
5368 ADD_PARM_SIZE (*offset_ptr, s2);
5369 SUB_PARM_SIZE (*offset_ptr, sizetree);
5370 }
5371 }
5372 }
5373 \f
5374 /* Walk the tree of blocks describing the binding levels within a function
5375 and warn about uninitialized variables.
5376 This is done after calling flow_analysis and before global_alloc
5377 clobbers the pseudo-regs to hard regs. */
5378
5379 void
5380 uninitialized_vars_warning (block)
5381 tree block;
5382 {
5383 tree decl, sub;
5384 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
5385 {
5386 if (warn_uninitialized
5387 && TREE_CODE (decl) == VAR_DECL
5388 /* These warnings are unreliable for and aggregates
5389 because assigning the fields one by one can fail to convince
5390 flow.c that the entire aggregate was initialized.
5391 Unions are troublesome because members may be shorter. */
5392 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl))
5393 && DECL_RTL (decl) != 0
5394 && GET_CODE (DECL_RTL (decl)) == REG
5395 /* Global optimizations can make it difficult to determine if a
5396 particular variable has been initialized. However, a VAR_DECL
5397 with a nonzero DECL_INITIAL had an initializer, so do not
5398 claim it is potentially uninitialized.
5399
5400 We do not care about the actual value in DECL_INITIAL, so we do
5401 not worry that it may be a dangling pointer. */
5402 && DECL_INITIAL (decl) == NULL_TREE
5403 && regno_uninitialized (REGNO (DECL_RTL (decl))))
5404 warning_with_decl (decl,
5405 "`%s' might be used uninitialized in this function");
5406 if (extra_warnings
5407 && TREE_CODE (decl) == VAR_DECL
5408 && DECL_RTL (decl) != 0
5409 && GET_CODE (DECL_RTL (decl)) == REG
5410 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
5411 warning_with_decl (decl,
5412 "variable `%s' might be clobbered by `longjmp' or `vfork'");
5413 }
5414 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
5415 uninitialized_vars_warning (sub);
5416 }
5417
5418 /* Do the appropriate part of uninitialized_vars_warning
5419 but for arguments instead of local variables. */
5420
5421 void
5422 setjmp_args_warning ()
5423 {
5424 tree decl;
5425 for (decl = DECL_ARGUMENTS (current_function_decl);
5426 decl; decl = TREE_CHAIN (decl))
5427 if (DECL_RTL (decl) != 0
5428 && GET_CODE (DECL_RTL (decl)) == REG
5429 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
5430 warning_with_decl (decl,
5431 "argument `%s' might be clobbered by `longjmp' or `vfork'");
5432 }
5433
5434 /* If this function call setjmp, put all vars into the stack
5435 unless they were declared `register'. */
5436
5437 void
5438 setjmp_protect (block)
5439 tree block;
5440 {
5441 tree decl, sub;
5442 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
5443 if ((TREE_CODE (decl) == VAR_DECL
5444 || TREE_CODE (decl) == PARM_DECL)
5445 && DECL_RTL (decl) != 0
5446 && (GET_CODE (DECL_RTL (decl)) == REG
5447 || (GET_CODE (DECL_RTL (decl)) == MEM
5448 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF))
5449 /* If this variable came from an inline function, it must be
5450 that its life doesn't overlap the setjmp. If there was a
5451 setjmp in the function, it would already be in memory. We
5452 must exclude such variable because their DECL_RTL might be
5453 set to strange things such as virtual_stack_vars_rtx. */
5454 && ! DECL_FROM_INLINE (decl)
5455 && (
5456 #ifdef NON_SAVING_SETJMP
5457 /* If longjmp doesn't restore the registers,
5458 don't put anything in them. */
5459 NON_SAVING_SETJMP
5460 ||
5461 #endif
5462 ! DECL_REGISTER (decl)))
5463 put_var_into_stack (decl);
5464 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
5465 setjmp_protect (sub);
5466 }
5467 \f
5468 /* Like the previous function, but for args instead of local variables. */
5469
5470 void
5471 setjmp_protect_args ()
5472 {
5473 tree decl;
5474 for (decl = DECL_ARGUMENTS (current_function_decl);
5475 decl; decl = TREE_CHAIN (decl))
5476 if ((TREE_CODE (decl) == VAR_DECL
5477 || TREE_CODE (decl) == PARM_DECL)
5478 && DECL_RTL (decl) != 0
5479 && (GET_CODE (DECL_RTL (decl)) == REG
5480 || (GET_CODE (DECL_RTL (decl)) == MEM
5481 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF))
5482 && (
5483 /* If longjmp doesn't restore the registers,
5484 don't put anything in them. */
5485 #ifdef NON_SAVING_SETJMP
5486 NON_SAVING_SETJMP
5487 ||
5488 #endif
5489 ! DECL_REGISTER (decl)))
5490 put_var_into_stack (decl);
5491 }
5492 \f
5493 /* Return the context-pointer register corresponding to DECL,
5494 or 0 if it does not need one. */
5495
5496 rtx
5497 lookup_static_chain (decl)
5498 tree decl;
5499 {
5500 tree context = decl_function_context (decl);
5501 tree link;
5502
5503 if (context == 0
5504 || (TREE_CODE (decl) == FUNCTION_DECL && DECL_NO_STATIC_CHAIN (decl)))
5505 return 0;
5506
5507 /* We treat inline_function_decl as an alias for the current function
5508 because that is the inline function whose vars, types, etc.
5509 are being merged into the current function.
5510 See expand_inline_function. */
5511 if (context == current_function_decl || context == inline_function_decl)
5512 return virtual_stack_vars_rtx;
5513
5514 for (link = context_display; link; link = TREE_CHAIN (link))
5515 if (TREE_PURPOSE (link) == context)
5516 return RTL_EXPR_RTL (TREE_VALUE (link));
5517
5518 abort ();
5519 }
5520 \f
5521 /* Convert a stack slot address ADDR for variable VAR
5522 (from a containing function)
5523 into an address valid in this function (using a static chain). */
5524
5525 rtx
5526 fix_lexical_addr (addr, var)
5527 rtx addr;
5528 tree var;
5529 {
5530 rtx basereg;
5531 HOST_WIDE_INT displacement;
5532 tree context = decl_function_context (var);
5533 struct function *fp;
5534 rtx base = 0;
5535
5536 /* If this is the present function, we need not do anything. */
5537 if (context == current_function_decl || context == inline_function_decl)
5538 return addr;
5539
5540 fp = find_function_data (context);
5541
5542 if (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == MEM)
5543 addr = XEXP (XEXP (addr, 0), 0);
5544
5545 /* Decode given address as base reg plus displacement. */
5546 if (GET_CODE (addr) == REG)
5547 basereg = addr, displacement = 0;
5548 else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
5549 basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
5550 else
5551 abort ();
5552
5553 /* We accept vars reached via the containing function's
5554 incoming arg pointer and via its stack variables pointer. */
5555 if (basereg == fp->internal_arg_pointer)
5556 {
5557 /* If reached via arg pointer, get the arg pointer value
5558 out of that function's stack frame.
5559
5560 There are two cases: If a separate ap is needed, allocate a
5561 slot in the outer function for it and dereference it that way.
5562 This is correct even if the real ap is actually a pseudo.
5563 Otherwise, just adjust the offset from the frame pointer to
5564 compensate. */
5565
5566 #ifdef NEED_SEPARATE_AP
5567 rtx addr;
5568
5569 addr = get_arg_pointer_save_area (fp);
5570 addr = fix_lexical_addr (XEXP (addr, 0), var);
5571 addr = memory_address (Pmode, addr);
5572
5573 base = gen_rtx_MEM (Pmode, addr);
5574 set_mem_alias_set (base, get_frame_alias_set ());
5575 base = copy_to_reg (base);
5576 #else
5577 displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET);
5578 base = lookup_static_chain (var);
5579 #endif
5580 }
5581
5582 else if (basereg == virtual_stack_vars_rtx)
5583 {
5584 /* This is the same code as lookup_static_chain, duplicated here to
5585 avoid an extra call to decl_function_context. */
5586 tree link;
5587
5588 for (link = context_display; link; link = TREE_CHAIN (link))
5589 if (TREE_PURPOSE (link) == context)
5590 {
5591 base = RTL_EXPR_RTL (TREE_VALUE (link));
5592 break;
5593 }
5594 }
5595
5596 if (base == 0)
5597 abort ();
5598
5599 /* Use same offset, relative to appropriate static chain or argument
5600 pointer. */
5601 return plus_constant (base, displacement);
5602 }
5603 \f
5604 /* Return the address of the trampoline for entering nested fn FUNCTION.
5605 If necessary, allocate a trampoline (in the stack frame)
5606 and emit rtl to initialize its contents (at entry to this function). */
5607
5608 rtx
5609 trampoline_address (function)
5610 tree function;
5611 {
5612 tree link;
5613 tree rtlexp;
5614 rtx tramp;
5615 struct function *fp;
5616 tree fn_context;
5617
5618 /* Find an existing trampoline and return it. */
5619 for (link = trampoline_list; link; link = TREE_CHAIN (link))
5620 if (TREE_PURPOSE (link) == function)
5621 return
5622 adjust_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0));
5623
5624 for (fp = outer_function_chain; fp; fp = fp->outer)
5625 for (link = fp->x_trampoline_list; link; link = TREE_CHAIN (link))
5626 if (TREE_PURPOSE (link) == function)
5627 {
5628 tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
5629 function);
5630 return adjust_trampoline_addr (tramp);
5631 }
5632
5633 /* None exists; we must make one. */
5634
5635 /* Find the `struct function' for the function containing FUNCTION. */
5636 fp = 0;
5637 fn_context = decl_function_context (function);
5638 if (fn_context != current_function_decl
5639 && fn_context != inline_function_decl)
5640 fp = find_function_data (fn_context);
5641
5642 /* Allocate run-time space for this trampoline
5643 (usually in the defining function's stack frame). */
5644 #ifdef ALLOCATE_TRAMPOLINE
5645 tramp = ALLOCATE_TRAMPOLINE (fp);
5646 #else
5647 /* If rounding needed, allocate extra space
5648 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
5649 #define TRAMPOLINE_REAL_SIZE \
5650 (TRAMPOLINE_SIZE + (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT) - 1)
5651 tramp = assign_stack_local_1 (BLKmode, TRAMPOLINE_REAL_SIZE, 0,
5652 fp ? fp : cfun);
5653 #endif
5654
5655 /* Record the trampoline for reuse and note it for later initialization
5656 by expand_function_end. */
5657 if (fp != 0)
5658 {
5659 rtlexp = make_node (RTL_EXPR);
5660 RTL_EXPR_RTL (rtlexp) = tramp;
5661 fp->x_trampoline_list = tree_cons (function, rtlexp,
5662 fp->x_trampoline_list);
5663 }
5664 else
5665 {
5666 /* Make the RTL_EXPR node temporary, not momentary, so that the
5667 trampoline_list doesn't become garbage. */
5668 rtlexp = make_node (RTL_EXPR);
5669
5670 RTL_EXPR_RTL (rtlexp) = tramp;
5671 trampoline_list = tree_cons (function, rtlexp, trampoline_list);
5672 }
5673
5674 tramp = fix_lexical_addr (XEXP (tramp, 0), function);
5675 return adjust_trampoline_addr (tramp);
5676 }
5677
5678 /* Given a trampoline address,
5679 round it to multiple of TRAMPOLINE_ALIGNMENT. */
5680
5681 static rtx
5682 round_trampoline_addr (tramp)
5683 rtx tramp;
5684 {
5685 /* Round address up to desired boundary. */
5686 rtx temp = gen_reg_rtx (Pmode);
5687 rtx addend = GEN_INT (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT - 1);
5688 rtx mask = GEN_INT (-TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
5689
5690 temp = expand_simple_binop (Pmode, PLUS, tramp, addend,
5691 temp, 0, OPTAB_LIB_WIDEN);
5692 tramp = expand_simple_binop (Pmode, AND, temp, mask,
5693 temp, 0, OPTAB_LIB_WIDEN);
5694
5695 return tramp;
5696 }
5697
5698 /* Given a trampoline address, round it then apply any
5699 platform-specific adjustments so that the result can be used for a
5700 function call . */
5701
5702 static rtx
5703 adjust_trampoline_addr (tramp)
5704 rtx tramp;
5705 {
5706 tramp = round_trampoline_addr (tramp);
5707 #ifdef TRAMPOLINE_ADJUST_ADDRESS
5708 TRAMPOLINE_ADJUST_ADDRESS (tramp);
5709 #endif
5710 return tramp;
5711 }
5712 \f
5713 /* Put all this function's BLOCK nodes including those that are chained
5714 onto the first block into a vector, and return it.
5715 Also store in each NOTE for the beginning or end of a block
5716 the index of that block in the vector.
5717 The arguments are BLOCK, the chain of top-level blocks of the function,
5718 and INSNS, the insn chain of the function. */
5719
5720 void
5721 identify_blocks ()
5722 {
5723 int n_blocks;
5724 tree *block_vector, *last_block_vector;
5725 tree *block_stack;
5726 tree block = DECL_INITIAL (current_function_decl);
5727
5728 if (block == 0)
5729 return;
5730
5731 /* Fill the BLOCK_VECTOR with all of the BLOCKs in this function, in
5732 depth-first order. */
5733 block_vector = get_block_vector (block, &n_blocks);
5734 block_stack = (tree *) xmalloc (n_blocks * sizeof (tree));
5735
5736 last_block_vector = identify_blocks_1 (get_insns (),
5737 block_vector + 1,
5738 block_vector + n_blocks,
5739 block_stack);
5740
5741 /* If we didn't use all of the subblocks, we've misplaced block notes. */
5742 /* ??? This appears to happen all the time. Latent bugs elsewhere? */
5743 if (0 && last_block_vector != block_vector + n_blocks)
5744 abort ();
5745
5746 free (block_vector);
5747 free (block_stack);
5748 }
5749
5750 /* Subroutine of identify_blocks. Do the block substitution on the
5751 insn chain beginning with INSNS. Recurse for CALL_PLACEHOLDER chains.
5752
5753 BLOCK_STACK is pushed and popped for each BLOCK_BEGIN/BLOCK_END pair.
5754 BLOCK_VECTOR is incremented for each block seen. */
5755
5756 static tree *
5757 identify_blocks_1 (insns, block_vector, end_block_vector, orig_block_stack)
5758 rtx insns;
5759 tree *block_vector;
5760 tree *end_block_vector;
5761 tree *orig_block_stack;
5762 {
5763 rtx insn;
5764 tree *block_stack = orig_block_stack;
5765
5766 for (insn = insns; insn; insn = NEXT_INSN (insn))
5767 {
5768 if (GET_CODE (insn) == NOTE)
5769 {
5770 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
5771 {
5772 tree b;
5773
5774 /* If there are more block notes than BLOCKs, something
5775 is badly wrong. */
5776 if (block_vector == end_block_vector)
5777 abort ();
5778
5779 b = *block_vector++;
5780 NOTE_BLOCK (insn) = b;
5781 *block_stack++ = b;
5782 }
5783 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
5784 {
5785 /* If there are more NOTE_INSN_BLOCK_ENDs than
5786 NOTE_INSN_BLOCK_BEGs, something is badly wrong. */
5787 if (block_stack == orig_block_stack)
5788 abort ();
5789
5790 NOTE_BLOCK (insn) = *--block_stack;
5791 }
5792 }
5793 else if (GET_CODE (insn) == CALL_INSN
5794 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
5795 {
5796 rtx cp = PATTERN (insn);
5797
5798 block_vector = identify_blocks_1 (XEXP (cp, 0), block_vector,
5799 end_block_vector, block_stack);
5800 if (XEXP (cp, 1))
5801 block_vector = identify_blocks_1 (XEXP (cp, 1), block_vector,
5802 end_block_vector, block_stack);
5803 if (XEXP (cp, 2))
5804 block_vector = identify_blocks_1 (XEXP (cp, 2), block_vector,
5805 end_block_vector, block_stack);
5806 }
5807 }
5808
5809 /* If there are more NOTE_INSN_BLOCK_BEGINs than NOTE_INSN_BLOCK_ENDs,
5810 something is badly wrong. */
5811 if (block_stack != orig_block_stack)
5812 abort ();
5813
5814 return block_vector;
5815 }
5816
5817 /* Identify BLOCKs referenced by more than one NOTE_INSN_BLOCK_{BEG,END},
5818 and create duplicate blocks. */
5819 /* ??? Need an option to either create block fragments or to create
5820 abstract origin duplicates of a source block. It really depends
5821 on what optimization has been performed. */
5822
5823 void
5824 reorder_blocks ()
5825 {
5826 tree block = DECL_INITIAL (current_function_decl);
5827 varray_type block_stack;
5828
5829 if (block == NULL_TREE)
5830 return;
5831
5832 VARRAY_TREE_INIT (block_stack, 10, "block_stack");
5833
5834 /* Reset the TREE_ASM_WRITTEN bit for all blocks. */
5835 reorder_blocks_0 (block);
5836
5837 /* Prune the old trees away, so that they don't get in the way. */
5838 BLOCK_SUBBLOCKS (block) = NULL_TREE;
5839 BLOCK_CHAIN (block) = NULL_TREE;
5840
5841 /* Recreate the block tree from the note nesting. */
5842 reorder_blocks_1 (get_insns (), block, &block_stack);
5843 BLOCK_SUBBLOCKS (block) = blocks_nreverse (BLOCK_SUBBLOCKS (block));
5844
5845 /* Remove deleted blocks from the block fragment chains. */
5846 reorder_fix_fragments (block);
5847 }
5848
5849 /* Helper function for reorder_blocks. Reset TREE_ASM_WRITTEN. */
5850
5851 static void
5852 reorder_blocks_0 (block)
5853 tree block;
5854 {
5855 while (block)
5856 {
5857 TREE_ASM_WRITTEN (block) = 0;
5858 reorder_blocks_0 (BLOCK_SUBBLOCKS (block));
5859 block = BLOCK_CHAIN (block);
5860 }
5861 }
5862
5863 static void
5864 reorder_blocks_1 (insns, current_block, p_block_stack)
5865 rtx insns;
5866 tree current_block;
5867 varray_type *p_block_stack;
5868 {
5869 rtx insn;
5870
5871 for (insn = insns; insn; insn = NEXT_INSN (insn))
5872 {
5873 if (GET_CODE (insn) == NOTE)
5874 {
5875 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
5876 {
5877 tree block = NOTE_BLOCK (insn);
5878
5879 /* If we have seen this block before, that means it now
5880 spans multiple address regions. Create a new fragment. */
5881 if (TREE_ASM_WRITTEN (block))
5882 {
5883 tree new_block = copy_node (block);
5884 tree origin;
5885
5886 origin = (BLOCK_FRAGMENT_ORIGIN (block)
5887 ? BLOCK_FRAGMENT_ORIGIN (block)
5888 : block);
5889 BLOCK_FRAGMENT_ORIGIN (new_block) = origin;
5890 BLOCK_FRAGMENT_CHAIN (new_block)
5891 = BLOCK_FRAGMENT_CHAIN (origin);
5892 BLOCK_FRAGMENT_CHAIN (origin) = new_block;
5893
5894 NOTE_BLOCK (insn) = new_block;
5895 block = new_block;
5896 }
5897
5898 BLOCK_SUBBLOCKS (block) = 0;
5899 TREE_ASM_WRITTEN (block) = 1;
5900 BLOCK_SUPERCONTEXT (block) = current_block;
5901 BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
5902 BLOCK_SUBBLOCKS (current_block) = block;
5903 current_block = block;
5904 VARRAY_PUSH_TREE (*p_block_stack, block);
5905 }
5906 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
5907 {
5908 NOTE_BLOCK (insn) = VARRAY_TOP_TREE (*p_block_stack);
5909 VARRAY_POP (*p_block_stack);
5910 BLOCK_SUBBLOCKS (current_block)
5911 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
5912 current_block = BLOCK_SUPERCONTEXT (current_block);
5913 }
5914 }
5915 else if (GET_CODE (insn) == CALL_INSN
5916 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
5917 {
5918 rtx cp = PATTERN (insn);
5919 reorder_blocks_1 (XEXP (cp, 0), current_block, p_block_stack);
5920 if (XEXP (cp, 1))
5921 reorder_blocks_1 (XEXP (cp, 1), current_block, p_block_stack);
5922 if (XEXP (cp, 2))
5923 reorder_blocks_1 (XEXP (cp, 2), current_block, p_block_stack);
5924 }
5925 }
5926 }
5927
5928 /* Rationalize BLOCK_FRAGMENT_ORIGIN. If an origin block no longer
5929 appears in the block tree, select one of the fragments to become
5930 the new origin block. */
5931
5932 static void
5933 reorder_fix_fragments (block)
5934 tree block;
5935 {
5936 while (block)
5937 {
5938 tree dup_origin = BLOCK_FRAGMENT_ORIGIN (block);
5939 tree new_origin = NULL_TREE;
5940
5941 if (dup_origin)
5942 {
5943 if (! TREE_ASM_WRITTEN (dup_origin))
5944 {
5945 new_origin = BLOCK_FRAGMENT_CHAIN (dup_origin);
5946
5947 /* Find the first of the remaining fragments. There must
5948 be at least one -- the current block. */
5949 while (! TREE_ASM_WRITTEN (new_origin))
5950 new_origin = BLOCK_FRAGMENT_CHAIN (new_origin);
5951 BLOCK_FRAGMENT_ORIGIN (new_origin) = NULL_TREE;
5952 }
5953 }
5954 else if (! dup_origin)
5955 new_origin = block;
5956
5957 /* Re-root the rest of the fragments to the new origin. In the
5958 case that DUP_ORIGIN was null, that means BLOCK was the origin
5959 of a chain of fragments and we want to remove those fragments
5960 that didn't make it to the output. */
5961 if (new_origin)
5962 {
5963 tree *pp = &BLOCK_FRAGMENT_CHAIN (new_origin);
5964 tree chain = *pp;
5965
5966 while (chain)
5967 {
5968 if (TREE_ASM_WRITTEN (chain))
5969 {
5970 BLOCK_FRAGMENT_ORIGIN (chain) = new_origin;
5971 *pp = chain;
5972 pp = &BLOCK_FRAGMENT_CHAIN (chain);
5973 }
5974 chain = BLOCK_FRAGMENT_CHAIN (chain);
5975 }
5976 *pp = NULL_TREE;
5977 }
5978
5979 reorder_fix_fragments (BLOCK_SUBBLOCKS (block));
5980 block = BLOCK_CHAIN (block);
5981 }
5982 }
5983
5984 /* Reverse the order of elements in the chain T of blocks,
5985 and return the new head of the chain (old last element). */
5986
5987 static tree
5988 blocks_nreverse (t)
5989 tree t;
5990 {
5991 tree prev = 0, decl, next;
5992 for (decl = t; decl; decl = next)
5993 {
5994 next = BLOCK_CHAIN (decl);
5995 BLOCK_CHAIN (decl) = prev;
5996 prev = decl;
5997 }
5998 return prev;
5999 }
6000
6001 /* Count the subblocks of the list starting with BLOCK. If VECTOR is
6002 non-NULL, list them all into VECTOR, in a depth-first preorder
6003 traversal of the block tree. Also clear TREE_ASM_WRITTEN in all
6004 blocks. */
6005
6006 static int
6007 all_blocks (block, vector)
6008 tree block;
6009 tree *vector;
6010 {
6011 int n_blocks = 0;
6012
6013 while (block)
6014 {
6015 TREE_ASM_WRITTEN (block) = 0;
6016
6017 /* Record this block. */
6018 if (vector)
6019 vector[n_blocks] = block;
6020
6021 ++n_blocks;
6022
6023 /* Record the subblocks, and their subblocks... */
6024 n_blocks += all_blocks (BLOCK_SUBBLOCKS (block),
6025 vector ? vector + n_blocks : 0);
6026 block = BLOCK_CHAIN (block);
6027 }
6028
6029 return n_blocks;
6030 }
6031
6032 /* Return a vector containing all the blocks rooted at BLOCK. The
6033 number of elements in the vector is stored in N_BLOCKS_P. The
6034 vector is dynamically allocated; it is the caller's responsibility
6035 to call `free' on the pointer returned. */
6036
6037 static tree *
6038 get_block_vector (block, n_blocks_p)
6039 tree block;
6040 int *n_blocks_p;
6041 {
6042 tree *block_vector;
6043
6044 *n_blocks_p = all_blocks (block, NULL);
6045 block_vector = (tree *) xmalloc (*n_blocks_p * sizeof (tree));
6046 all_blocks (block, block_vector);
6047
6048 return block_vector;
6049 }
6050
6051 static int next_block_index = 2;
6052
6053 /* Set BLOCK_NUMBER for all the blocks in FN. */
6054
6055 void
6056 number_blocks (fn)
6057 tree fn;
6058 {
6059 int i;
6060 int n_blocks;
6061 tree *block_vector;
6062
6063 /* For SDB and XCOFF debugging output, we start numbering the blocks
6064 from 1 within each function, rather than keeping a running
6065 count. */
6066 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
6067 if (write_symbols == SDB_DEBUG || write_symbols == XCOFF_DEBUG)
6068 next_block_index = 1;
6069 #endif
6070
6071 block_vector = get_block_vector (DECL_INITIAL (fn), &n_blocks);
6072
6073 /* The top-level BLOCK isn't numbered at all. */
6074 for (i = 1; i < n_blocks; ++i)
6075 /* We number the blocks from two. */
6076 BLOCK_NUMBER (block_vector[i]) = next_block_index++;
6077
6078 free (block_vector);
6079
6080 return;
6081 }
6082
6083 /* If VAR is present in a subblock of BLOCK, return the subblock. */
6084
6085 tree
6086 debug_find_var_in_block_tree (var, block)
6087 tree var;
6088 tree block;
6089 {
6090 tree t;
6091
6092 for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t))
6093 if (t == var)
6094 return block;
6095
6096 for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t))
6097 {
6098 tree ret = debug_find_var_in_block_tree (var, t);
6099 if (ret)
6100 return ret;
6101 }
6102
6103 return NULL_TREE;
6104 }
6105 \f
6106 /* Allocate a function structure and reset its contents to the defaults. */
6107
6108 static void
6109 prepare_function_start ()
6110 {
6111 cfun = (struct function *) ggc_alloc_cleared (sizeof (struct function));
6112
6113 init_stmt_for_function ();
6114 init_eh_for_function ();
6115
6116 cse_not_expected = ! optimize;
6117
6118 /* Caller save not needed yet. */
6119 caller_save_needed = 0;
6120
6121 /* No stack slots have been made yet. */
6122 stack_slot_list = 0;
6123
6124 current_function_has_nonlocal_label = 0;
6125 current_function_has_nonlocal_goto = 0;
6126
6127 /* There is no stack slot for handling nonlocal gotos. */
6128 nonlocal_goto_handler_slots = 0;
6129 nonlocal_goto_stack_level = 0;
6130
6131 /* No labels have been declared for nonlocal use. */
6132 nonlocal_labels = 0;
6133 nonlocal_goto_handler_labels = 0;
6134
6135 /* No function calls so far in this function. */
6136 function_call_count = 0;
6137
6138 /* No parm regs have been allocated.
6139 (This is important for output_inline_function.) */
6140 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
6141
6142 /* Initialize the RTL mechanism. */
6143 init_emit ();
6144
6145 /* Initialize the queue of pending postincrement and postdecrements,
6146 and some other info in expr.c. */
6147 init_expr ();
6148
6149 /* We haven't done register allocation yet. */
6150 reg_renumber = 0;
6151
6152 init_varasm_status (cfun);
6153
6154 /* Clear out data used for inlining. */
6155 cfun->inlinable = 0;
6156 cfun->original_decl_initial = 0;
6157 cfun->original_arg_vector = 0;
6158
6159 cfun->stack_alignment_needed = STACK_BOUNDARY;
6160 cfun->preferred_stack_boundary = STACK_BOUNDARY;
6161
6162 /* Set if a call to setjmp is seen. */
6163 current_function_calls_setjmp = 0;
6164
6165 /* Set if a call to longjmp is seen. */
6166 current_function_calls_longjmp = 0;
6167
6168 current_function_calls_alloca = 0;
6169 current_function_calls_eh_return = 0;
6170 current_function_calls_constant_p = 0;
6171 current_function_contains_functions = 0;
6172 current_function_is_leaf = 0;
6173 current_function_nothrow = 0;
6174 current_function_sp_is_unchanging = 0;
6175 current_function_uses_only_leaf_regs = 0;
6176 current_function_has_computed_jump = 0;
6177 current_function_is_thunk = 0;
6178
6179 current_function_returns_pcc_struct = 0;
6180 current_function_returns_struct = 0;
6181 current_function_epilogue_delay_list = 0;
6182 current_function_uses_const_pool = 0;
6183 current_function_uses_pic_offset_table = 0;
6184 current_function_cannot_inline = 0;
6185
6186 /* We have not yet needed to make a label to jump to for tail-recursion. */
6187 tail_recursion_label = 0;
6188
6189 /* We haven't had a need to make a save area for ap yet. */
6190 arg_pointer_save_area = 0;
6191
6192 /* No stack slots allocated yet. */
6193 frame_offset = 0;
6194
6195 /* No SAVE_EXPRs in this function yet. */
6196 save_expr_regs = 0;
6197
6198 /* No RTL_EXPRs in this function yet. */
6199 rtl_expr_chain = 0;
6200
6201 /* Set up to allocate temporaries. */
6202 init_temp_slots ();
6203
6204 /* Indicate that we need to distinguish between the return value of the
6205 present function and the return value of a function being called. */
6206 rtx_equal_function_value_matters = 1;
6207
6208 /* Indicate that we have not instantiated virtual registers yet. */
6209 virtuals_instantiated = 0;
6210
6211 /* Indicate that we want CONCATs now. */
6212 generating_concat_p = 1;
6213
6214 /* Indicate we have no need of a frame pointer yet. */
6215 frame_pointer_needed = 0;
6216
6217 /* By default assume not stdarg. */
6218 current_function_stdarg = 0;
6219
6220 /* We haven't made any trampolines for this function yet. */
6221 trampoline_list = 0;
6222
6223 init_pending_stack_adjust ();
6224 inhibit_defer_pop = 0;
6225
6226 current_function_outgoing_args_size = 0;
6227
6228 current_function_funcdef_no = funcdef_no++;
6229
6230 cfun->arc_profile = profile_arc_flag || flag_test_coverage;
6231
6232 cfun->function_frequency = FUNCTION_FREQUENCY_NORMAL;
6233
6234 cfun->max_jumptable_ents = 0;
6235
6236 (*lang_hooks.function.init) (cfun);
6237 if (init_machine_status)
6238 cfun->machine = (*init_machine_status) ();
6239 }
6240
6241 /* Initialize the rtl expansion mechanism so that we can do simple things
6242 like generate sequences. This is used to provide a context during global
6243 initialization of some passes. */
6244 void
6245 init_dummy_function_start ()
6246 {
6247 prepare_function_start ();
6248 }
6249
6250 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
6251 and initialize static variables for generating RTL for the statements
6252 of the function. */
6253
6254 void
6255 init_function_start (subr, filename, line)
6256 tree subr;
6257 const char *filename;
6258 int line;
6259 {
6260 prepare_function_start ();
6261
6262 current_function_name = (*lang_hooks.decl_printable_name) (subr, 2);
6263 cfun->decl = subr;
6264
6265 /* Nonzero if this is a nested function that uses a static chain. */
6266
6267 current_function_needs_context
6268 = (decl_function_context (current_function_decl) != 0
6269 && ! DECL_NO_STATIC_CHAIN (current_function_decl));
6270
6271 /* Within function body, compute a type's size as soon it is laid out. */
6272 immediate_size_expand++;
6273
6274 /* Prevent ever trying to delete the first instruction of a function.
6275 Also tell final how to output a linenum before the function prologue.
6276 Note linenums could be missing, e.g. when compiling a Java .class file. */
6277 if (line > 0)
6278 emit_line_note (filename, line);
6279
6280 /* Make sure first insn is a note even if we don't want linenums.
6281 This makes sure the first insn will never be deleted.
6282 Also, final expects a note to appear there. */
6283 emit_note (NULL, NOTE_INSN_DELETED);
6284
6285 /* Set flags used by final.c. */
6286 if (aggregate_value_p (DECL_RESULT (subr)))
6287 {
6288 #ifdef PCC_STATIC_STRUCT_RETURN
6289 current_function_returns_pcc_struct = 1;
6290 #endif
6291 current_function_returns_struct = 1;
6292 }
6293
6294 /* Warn if this value is an aggregate type,
6295 regardless of which calling convention we are using for it. */
6296 if (warn_aggregate_return
6297 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
6298 warning ("function returns an aggregate");
6299
6300 current_function_returns_pointer
6301 = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
6302 }
6303
6304 /* Make sure all values used by the optimization passes have sane
6305 defaults. */
6306 void
6307 init_function_for_compilation ()
6308 {
6309 reg_renumber = 0;
6310
6311 /* No prologue/epilogue insns yet. */
6312 VARRAY_GROW (prologue, 0);
6313 VARRAY_GROW (epilogue, 0);
6314 VARRAY_GROW (sibcall_epilogue, 0);
6315 }
6316
6317 /* Expand a call to __main at the beginning of a possible main function. */
6318
6319 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
6320 #undef HAS_INIT_SECTION
6321 #define HAS_INIT_SECTION
6322 #endif
6323
6324 void
6325 expand_main_function ()
6326 {
6327 #ifdef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
6328 if (FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN)
6329 {
6330 int align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
6331 rtx tmp, seq;
6332
6333 start_sequence ();
6334 /* Forcibly align the stack. */
6335 #ifdef STACK_GROWS_DOWNWARD
6336 tmp = expand_simple_binop (Pmode, AND, stack_pointer_rtx, GEN_INT(-align),
6337 stack_pointer_rtx, 1, OPTAB_WIDEN);
6338 #else
6339 tmp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
6340 GEN_INT (align - 1), NULL_RTX, 1, OPTAB_WIDEN);
6341 tmp = expand_simple_binop (Pmode, AND, tmp, GEN_INT (-align),
6342 stack_pointer_rtx, 1, OPTAB_WIDEN);
6343 #endif
6344 if (tmp != stack_pointer_rtx)
6345 emit_move_insn (stack_pointer_rtx, tmp);
6346
6347 /* Enlist allocate_dynamic_stack_space to pick up the pieces. */
6348 tmp = force_reg (Pmode, const0_rtx);
6349 allocate_dynamic_stack_space (tmp, NULL_RTX, BIGGEST_ALIGNMENT);
6350 seq = get_insns ();
6351 end_sequence ();
6352
6353 for (tmp = get_last_insn (); tmp; tmp = PREV_INSN (tmp))
6354 if (NOTE_P (tmp) && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_FUNCTION_BEG)
6355 break;
6356 if (tmp)
6357 emit_insn_before (seq, tmp);
6358 else
6359 emit_insn (seq);
6360 }
6361 #endif
6362
6363 #ifndef HAS_INIT_SECTION
6364 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, NAME__MAIN), LCT_NORMAL,
6365 VOIDmode, 0);
6366 #endif
6367 }
6368 \f
6369 /* The PENDING_SIZES represent the sizes of variable-sized types.
6370 Create RTL for the various sizes now (using temporary variables),
6371 so that we can refer to the sizes from the RTL we are generating
6372 for the current function. The PENDING_SIZES are a TREE_LIST. The
6373 TREE_VALUE of each node is a SAVE_EXPR. */
6374
6375 void
6376 expand_pending_sizes (pending_sizes)
6377 tree pending_sizes;
6378 {
6379 tree tem;
6380
6381 /* Evaluate now the sizes of any types declared among the arguments. */
6382 for (tem = pending_sizes; tem; tem = TREE_CHAIN (tem))
6383 {
6384 expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode, 0);
6385 /* Flush the queue in case this parameter declaration has
6386 side-effects. */
6387 emit_queue ();
6388 }
6389 }
6390
6391 /* Start the RTL for a new function, and set variables used for
6392 emitting RTL.
6393 SUBR is the FUNCTION_DECL node.
6394 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
6395 the function's parameters, which must be run at any return statement. */
6396
6397 void
6398 expand_function_start (subr, parms_have_cleanups)
6399 tree subr;
6400 int parms_have_cleanups;
6401 {
6402 tree tem;
6403 rtx last_ptr = NULL_RTX;
6404
6405 /* Make sure volatile mem refs aren't considered
6406 valid operands of arithmetic insns. */
6407 init_recog_no_volatile ();
6408
6409 current_function_instrument_entry_exit
6410 = (flag_instrument_function_entry_exit
6411 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr));
6412
6413 current_function_profile
6414 = (profile_flag
6415 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr));
6416
6417 current_function_limit_stack
6418 = (stack_limit_rtx != NULL_RTX && ! DECL_NO_LIMIT_STACK (subr));
6419
6420 /* If function gets a static chain arg, store it in the stack frame.
6421 Do this first, so it gets the first stack slot offset. */
6422 if (current_function_needs_context)
6423 {
6424 last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
6425
6426 /* Delay copying static chain if it is not a register to avoid
6427 conflicts with regs used for parameters. */
6428 if (! SMALL_REGISTER_CLASSES
6429 || GET_CODE (static_chain_incoming_rtx) == REG)
6430 emit_move_insn (last_ptr, static_chain_incoming_rtx);
6431 }
6432
6433 /* If the parameters of this function need cleaning up, get a label
6434 for the beginning of the code which executes those cleanups. This must
6435 be done before doing anything with return_label. */
6436 if (parms_have_cleanups)
6437 cleanup_label = gen_label_rtx ();
6438 else
6439 cleanup_label = 0;
6440
6441 /* Make the label for return statements to jump to. Do not special
6442 case machines with special return instructions -- they will be
6443 handled later during jump, ifcvt, or epilogue creation. */
6444 return_label = gen_label_rtx ();
6445
6446 /* Initialize rtx used to return the value. */
6447 /* Do this before assign_parms so that we copy the struct value address
6448 before any library calls that assign parms might generate. */
6449
6450 /* Decide whether to return the value in memory or in a register. */
6451 if (aggregate_value_p (DECL_RESULT (subr)))
6452 {
6453 /* Returning something that won't go in a register. */
6454 rtx value_address = 0;
6455
6456 #ifdef PCC_STATIC_STRUCT_RETURN
6457 if (current_function_returns_pcc_struct)
6458 {
6459 int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
6460 value_address = assemble_static_space (size);
6461 }
6462 else
6463 #endif
6464 {
6465 /* Expect to be passed the address of a place to store the value.
6466 If it is passed as an argument, assign_parms will take care of
6467 it. */
6468 if (struct_value_incoming_rtx)
6469 {
6470 value_address = gen_reg_rtx (Pmode);
6471 emit_move_insn (value_address, struct_value_incoming_rtx);
6472 }
6473 }
6474 if (value_address)
6475 {
6476 rtx x = gen_rtx_MEM (DECL_MODE (DECL_RESULT (subr)), value_address);
6477 set_mem_attributes (x, DECL_RESULT (subr), 1);
6478 SET_DECL_RTL (DECL_RESULT (subr), x);
6479 }
6480 }
6481 else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
6482 /* If return mode is void, this decl rtl should not be used. */
6483 SET_DECL_RTL (DECL_RESULT (subr), NULL_RTX);
6484 else
6485 {
6486 /* Compute the return values into a pseudo reg, which we will copy
6487 into the true return register after the cleanups are done. */
6488
6489 /* In order to figure out what mode to use for the pseudo, we
6490 figure out what the mode of the eventual return register will
6491 actually be, and use that. */
6492 rtx hard_reg
6493 = hard_function_value (TREE_TYPE (DECL_RESULT (subr)),
6494 subr, 1);
6495
6496 /* Structures that are returned in registers are not aggregate_value_p,
6497 so we may see a PARALLEL or a REG. */
6498 if (REG_P (hard_reg))
6499 SET_DECL_RTL (DECL_RESULT (subr), gen_reg_rtx (GET_MODE (hard_reg)));
6500 else if (GET_CODE (hard_reg) == PARALLEL)
6501 SET_DECL_RTL (DECL_RESULT (subr), gen_group_rtx (hard_reg));
6502 else
6503 abort ();
6504
6505 /* Set DECL_REGISTER flag so that expand_function_end will copy the
6506 result to the real return register(s). */
6507 DECL_REGISTER (DECL_RESULT (subr)) = 1;
6508 }
6509
6510 /* Initialize rtx for parameters and local variables.
6511 In some cases this requires emitting insns. */
6512
6513 assign_parms (subr);
6514
6515 /* Copy the static chain now if it wasn't a register. The delay is to
6516 avoid conflicts with the parameter passing registers. */
6517
6518 if (SMALL_REGISTER_CLASSES && current_function_needs_context)
6519 if (GET_CODE (static_chain_incoming_rtx) != REG)
6520 emit_move_insn (last_ptr, static_chain_incoming_rtx);
6521
6522 /* The following was moved from init_function_start.
6523 The move is supposed to make sdb output more accurate. */
6524 /* Indicate the beginning of the function body,
6525 as opposed to parm setup. */
6526 emit_note (NULL, NOTE_INSN_FUNCTION_BEG);
6527
6528 if (GET_CODE (get_last_insn ()) != NOTE)
6529 emit_note (NULL, NOTE_INSN_DELETED);
6530 parm_birth_insn = get_last_insn ();
6531
6532 context_display = 0;
6533 if (current_function_needs_context)
6534 {
6535 /* Fetch static chain values for containing functions. */
6536 tem = decl_function_context (current_function_decl);
6537 /* Copy the static chain pointer into a pseudo. If we have
6538 small register classes, copy the value from memory if
6539 static_chain_incoming_rtx is a REG. */
6540 if (tem)
6541 {
6542 /* If the static chain originally came in a register, put it back
6543 there, then move it out in the next insn. The reason for
6544 this peculiar code is to satisfy function integration. */
6545 if (SMALL_REGISTER_CLASSES
6546 && GET_CODE (static_chain_incoming_rtx) == REG)
6547 emit_move_insn (static_chain_incoming_rtx, last_ptr);
6548 last_ptr = copy_to_reg (static_chain_incoming_rtx);
6549 }
6550
6551 while (tem)
6552 {
6553 tree rtlexp = make_node (RTL_EXPR);
6554
6555 RTL_EXPR_RTL (rtlexp) = last_ptr;
6556 context_display = tree_cons (tem, rtlexp, context_display);
6557 tem = decl_function_context (tem);
6558 if (tem == 0)
6559 break;
6560 /* Chain thru stack frames, assuming pointer to next lexical frame
6561 is found at the place we always store it. */
6562 #ifdef FRAME_GROWS_DOWNWARD
6563 last_ptr = plus_constant (last_ptr,
6564 -(HOST_WIDE_INT) GET_MODE_SIZE (Pmode));
6565 #endif
6566 last_ptr = gen_rtx_MEM (Pmode, memory_address (Pmode, last_ptr));
6567 set_mem_alias_set (last_ptr, get_frame_alias_set ());
6568 last_ptr = copy_to_reg (last_ptr);
6569
6570 /* If we are not optimizing, ensure that we know that this
6571 piece of context is live over the entire function. */
6572 if (! optimize)
6573 save_expr_regs = gen_rtx_EXPR_LIST (VOIDmode, last_ptr,
6574 save_expr_regs);
6575 }
6576 }
6577
6578 if (current_function_instrument_entry_exit)
6579 {
6580 rtx fun = DECL_RTL (current_function_decl);
6581 if (GET_CODE (fun) == MEM)
6582 fun = XEXP (fun, 0);
6583 else
6584 abort ();
6585 emit_library_call (profile_function_entry_libfunc, LCT_NORMAL, VOIDmode,
6586 2, fun, Pmode,
6587 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS,
6588 0,
6589 hard_frame_pointer_rtx),
6590 Pmode);
6591 }
6592
6593 if (current_function_profile)
6594 {
6595 #ifdef PROFILE_HOOK
6596 PROFILE_HOOK (current_function_funcdef_no);
6597 #endif
6598 }
6599
6600 /* After the display initializations is where the tail-recursion label
6601 should go, if we end up needing one. Ensure we have a NOTE here
6602 since some things (like trampolines) get placed before this. */
6603 tail_recursion_reentry = emit_note (NULL, NOTE_INSN_DELETED);
6604
6605 /* Evaluate now the sizes of any types declared among the arguments. */
6606 expand_pending_sizes (nreverse (get_pending_sizes ()));
6607
6608 /* Make sure there is a line number after the function entry setup code. */
6609 force_next_line_note ();
6610 }
6611 \f
6612 /* Undo the effects of init_dummy_function_start. */
6613 void
6614 expand_dummy_function_end ()
6615 {
6616 /* End any sequences that failed to be closed due to syntax errors. */
6617 while (in_sequence_p ())
6618 end_sequence ();
6619
6620 /* Outside function body, can't compute type's actual size
6621 until next function's body starts. */
6622
6623 free_after_parsing (cfun);
6624 free_after_compilation (cfun);
6625 cfun = 0;
6626 }
6627
6628 /* Call DOIT for each hard register used as a return value from
6629 the current function. */
6630
6631 void
6632 diddle_return_value (doit, arg)
6633 void (*doit) PARAMS ((rtx, void *));
6634 void *arg;
6635 {
6636 rtx outgoing = current_function_return_rtx;
6637
6638 if (! outgoing)
6639 return;
6640
6641 if (GET_CODE (outgoing) == REG)
6642 (*doit) (outgoing, arg);
6643 else if (GET_CODE (outgoing) == PARALLEL)
6644 {
6645 int i;
6646
6647 for (i = 0; i < XVECLEN (outgoing, 0); i++)
6648 {
6649 rtx x = XEXP (XVECEXP (outgoing, 0, i), 0);
6650
6651 if (GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER)
6652 (*doit) (x, arg);
6653 }
6654 }
6655 }
6656
6657 static void
6658 do_clobber_return_reg (reg, arg)
6659 rtx reg;
6660 void *arg ATTRIBUTE_UNUSED;
6661 {
6662 emit_insn (gen_rtx_CLOBBER (VOIDmode, reg));
6663 }
6664
6665 void
6666 clobber_return_register ()
6667 {
6668 diddle_return_value (do_clobber_return_reg, NULL);
6669
6670 /* In case we do use pseudo to return value, clobber it too. */
6671 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl)))
6672 {
6673 tree decl_result = DECL_RESULT (current_function_decl);
6674 rtx decl_rtl = DECL_RTL (decl_result);
6675 if (REG_P (decl_rtl) && REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER)
6676 {
6677 do_clobber_return_reg (decl_rtl, NULL);
6678 }
6679 }
6680 }
6681
6682 static void
6683 do_use_return_reg (reg, arg)
6684 rtx reg;
6685 void *arg ATTRIBUTE_UNUSED;
6686 {
6687 emit_insn (gen_rtx_USE (VOIDmode, reg));
6688 }
6689
6690 void
6691 use_return_register ()
6692 {
6693 diddle_return_value (do_use_return_reg, NULL);
6694 }
6695
6696 static GTY(()) rtx initial_trampoline;
6697
6698 /* Generate RTL for the end of the current function.
6699 FILENAME and LINE are the current position in the source file.
6700
6701 It is up to language-specific callers to do cleanups for parameters--
6702 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */
6703
6704 void
6705 expand_function_end (filename, line, end_bindings)
6706 const char *filename;
6707 int line;
6708 int end_bindings;
6709 {
6710 tree link;
6711 rtx clobber_after;
6712
6713 finish_expr_for_function ();
6714
6715 /* If arg_pointer_save_area was referenced only from a nested
6716 function, we will not have initialized it yet. Do that now. */
6717 if (arg_pointer_save_area && ! cfun->arg_pointer_save_area_init)
6718 get_arg_pointer_save_area (cfun);
6719
6720 #ifdef NON_SAVING_SETJMP
6721 /* Don't put any variables in registers if we call setjmp
6722 on a machine that fails to restore the registers. */
6723 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
6724 {
6725 if (DECL_INITIAL (current_function_decl) != error_mark_node)
6726 setjmp_protect (DECL_INITIAL (current_function_decl));
6727
6728 setjmp_protect_args ();
6729 }
6730 #endif
6731
6732 /* Initialize any trampolines required by this function. */
6733 for (link = trampoline_list; link; link = TREE_CHAIN (link))
6734 {
6735 tree function = TREE_PURPOSE (link);
6736 rtx context ATTRIBUTE_UNUSED = lookup_static_chain (function);
6737 rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
6738 #ifdef TRAMPOLINE_TEMPLATE
6739 rtx blktramp;
6740 #endif
6741 rtx seq;
6742
6743 #ifdef TRAMPOLINE_TEMPLATE
6744 /* First make sure this compilation has a template for
6745 initializing trampolines. */
6746 if (initial_trampoline == 0)
6747 {
6748 initial_trampoline
6749 = gen_rtx_MEM (BLKmode, assemble_trampoline_template ());
6750 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
6751 }
6752 #endif
6753
6754 /* Generate insns to initialize the trampoline. */
6755 start_sequence ();
6756 tramp = round_trampoline_addr (XEXP (tramp, 0));
6757 #ifdef TRAMPOLINE_TEMPLATE
6758 blktramp = replace_equiv_address (initial_trampoline, tramp);
6759 emit_block_move (blktramp, initial_trampoline,
6760 GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
6761 #endif
6762 INITIALIZE_TRAMPOLINE (tramp, XEXP (DECL_RTL (function), 0), context);
6763 seq = get_insns ();
6764 end_sequence ();
6765
6766 /* Put those insns at entry to the containing function (this one). */
6767 emit_insn_before (seq, tail_recursion_reentry);
6768 }
6769
6770 /* If we are doing stack checking and this function makes calls,
6771 do a stack probe at the start of the function to ensure we have enough
6772 space for another stack frame. */
6773 if (flag_stack_check && ! STACK_CHECK_BUILTIN)
6774 {
6775 rtx insn, seq;
6776
6777 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
6778 if (GET_CODE (insn) == CALL_INSN)
6779 {
6780 start_sequence ();
6781 probe_stack_range (STACK_CHECK_PROTECT,
6782 GEN_INT (STACK_CHECK_MAX_FRAME_SIZE));
6783 seq = get_insns ();
6784 end_sequence ();
6785 emit_insn_before (seq, tail_recursion_reentry);
6786 break;
6787 }
6788 }
6789
6790 /* Warn about unused parms if extra warnings were specified. */
6791 /* Either ``-Wextra -Wunused'' or ``-Wunused-parameter'' enables this
6792 warning. WARN_UNUSED_PARAMETER is negative when set by
6793 -Wunused. Note that -Wall implies -Wunused, so ``-Wall -Wextra'' will
6794 also give these warnings. */
6795 if (warn_unused_parameter > 0
6796 || (warn_unused_parameter < 0 && extra_warnings))
6797 {
6798 tree decl;
6799
6800 for (decl = DECL_ARGUMENTS (current_function_decl);
6801 decl; decl = TREE_CHAIN (decl))
6802 if (! TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
6803 && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
6804 warning_with_decl (decl, "unused parameter `%s'");
6805 }
6806
6807 /* Delete handlers for nonlocal gotos if nothing uses them. */
6808 if (nonlocal_goto_handler_slots != 0
6809 && ! current_function_has_nonlocal_label)
6810 delete_handlers ();
6811
6812 /* End any sequences that failed to be closed due to syntax errors. */
6813 while (in_sequence_p ())
6814 end_sequence ();
6815
6816 /* Outside function body, can't compute type's actual size
6817 until next function's body starts. */
6818 immediate_size_expand--;
6819
6820 clear_pending_stack_adjust ();
6821 do_pending_stack_adjust ();
6822
6823 /* Mark the end of the function body.
6824 If control reaches this insn, the function can drop through
6825 without returning a value. */
6826 emit_note (NULL, NOTE_INSN_FUNCTION_END);
6827
6828 /* Must mark the last line number note in the function, so that the test
6829 coverage code can avoid counting the last line twice. This just tells
6830 the code to ignore the immediately following line note, since there
6831 already exists a copy of this note somewhere above. This line number
6832 note is still needed for debugging though, so we can't delete it. */
6833 if (flag_test_coverage)
6834 emit_note (NULL, NOTE_INSN_REPEATED_LINE_NUMBER);
6835
6836 /* Output a linenumber for the end of the function.
6837 SDB depends on this. */
6838 emit_line_note_force (filename, line);
6839
6840 /* Before the return label (if any), clobber the return
6841 registers so that they are not propagated live to the rest of
6842 the function. This can only happen with functions that drop
6843 through; if there had been a return statement, there would
6844 have either been a return rtx, or a jump to the return label.
6845
6846 We delay actual code generation after the current_function_value_rtx
6847 is computed. */
6848 clobber_after = get_last_insn ();
6849
6850 /* Output the label for the actual return from the function,
6851 if one is expected. This happens either because a function epilogue
6852 is used instead of a return instruction, or because a return was done
6853 with a goto in order to run local cleanups, or because of pcc-style
6854 structure returning. */
6855 if (return_label)
6856 emit_label (return_label);
6857
6858 /* C++ uses this. */
6859 if (end_bindings)
6860 expand_end_bindings (0, 0, 0);
6861
6862 if (current_function_instrument_entry_exit)
6863 {
6864 rtx fun = DECL_RTL (current_function_decl);
6865 if (GET_CODE (fun) == MEM)
6866 fun = XEXP (fun, 0);
6867 else
6868 abort ();
6869 emit_library_call (profile_function_exit_libfunc, LCT_NORMAL, VOIDmode,
6870 2, fun, Pmode,
6871 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS,
6872 0,
6873 hard_frame_pointer_rtx),
6874 Pmode);
6875 }
6876
6877 /* Let except.c know where it should emit the call to unregister
6878 the function context for sjlj exceptions. */
6879 if (flag_exceptions && USING_SJLJ_EXCEPTIONS)
6880 sjlj_emit_function_exit_after (get_last_insn ());
6881
6882 /* If we had calls to alloca, and this machine needs
6883 an accurate stack pointer to exit the function,
6884 insert some code to save and restore the stack pointer. */
6885 #ifdef EXIT_IGNORE_STACK
6886 if (! EXIT_IGNORE_STACK)
6887 #endif
6888 if (current_function_calls_alloca)
6889 {
6890 rtx tem = 0;
6891
6892 emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
6893 emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
6894 }
6895
6896 /* If scalar return value was computed in a pseudo-reg, or was a named
6897 return value that got dumped to the stack, copy that to the hard
6898 return register. */
6899 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl)))
6900 {
6901 tree decl_result = DECL_RESULT (current_function_decl);
6902 rtx decl_rtl = DECL_RTL (decl_result);
6903
6904 if (REG_P (decl_rtl)
6905 ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
6906 : DECL_REGISTER (decl_result))
6907 {
6908 rtx real_decl_rtl = current_function_return_rtx;
6909
6910 /* This should be set in assign_parms. */
6911 if (! REG_FUNCTION_VALUE_P (real_decl_rtl))
6912 abort ();
6913
6914 /* If this is a BLKmode structure being returned in registers,
6915 then use the mode computed in expand_return. Note that if
6916 decl_rtl is memory, then its mode may have been changed,
6917 but that current_function_return_rtx has not. */
6918 if (GET_MODE (real_decl_rtl) == BLKmode)
6919 PUT_MODE (real_decl_rtl, GET_MODE (decl_rtl));
6920
6921 /* If a named return value dumped decl_return to memory, then
6922 we may need to re-do the PROMOTE_MODE signed/unsigned
6923 extension. */
6924 if (GET_MODE (real_decl_rtl) != GET_MODE (decl_rtl))
6925 {
6926 int unsignedp = TREE_UNSIGNED (TREE_TYPE (decl_result));
6927
6928 #ifdef PROMOTE_FUNCTION_RETURN
6929 promote_mode (TREE_TYPE (decl_result), GET_MODE (decl_rtl),
6930 &unsignedp, 1);
6931 #endif
6932
6933 convert_move (real_decl_rtl, decl_rtl, unsignedp);
6934 }
6935 else if (GET_CODE (real_decl_rtl) == PARALLEL)
6936 {
6937 /* If expand_function_start has created a PARALLEL for decl_rtl,
6938 move the result to the real return registers. Otherwise, do
6939 a group load from decl_rtl for a named return. */
6940 if (GET_CODE (decl_rtl) == PARALLEL)
6941 emit_group_move (real_decl_rtl, decl_rtl);
6942 else
6943 emit_group_load (real_decl_rtl, decl_rtl,
6944 int_size_in_bytes (TREE_TYPE (decl_result)));
6945 }
6946 else
6947 emit_move_insn (real_decl_rtl, decl_rtl);
6948 }
6949 }
6950
6951 /* If returning a structure, arrange to return the address of the value
6952 in a place where debuggers expect to find it.
6953
6954 If returning a structure PCC style,
6955 the caller also depends on this value.
6956 And current_function_returns_pcc_struct is not necessarily set. */
6957 if (current_function_returns_struct
6958 || current_function_returns_pcc_struct)
6959 {
6960 rtx value_address
6961 = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
6962 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
6963 #ifdef FUNCTION_OUTGOING_VALUE
6964 rtx outgoing
6965 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
6966 current_function_decl);
6967 #else
6968 rtx outgoing
6969 = FUNCTION_VALUE (build_pointer_type (type), current_function_decl);
6970 #endif
6971
6972 /* Mark this as a function return value so integrate will delete the
6973 assignment and USE below when inlining this function. */
6974 REG_FUNCTION_VALUE_P (outgoing) = 1;
6975
6976 #ifdef POINTERS_EXTEND_UNSIGNED
6977 /* The address may be ptr_mode and OUTGOING may be Pmode. */
6978 if (GET_MODE (outgoing) != GET_MODE (value_address))
6979 value_address = convert_memory_address (GET_MODE (outgoing),
6980 value_address);
6981 #endif
6982
6983 emit_move_insn (outgoing, value_address);
6984
6985 /* Show return register used to hold result (in this case the address
6986 of the result. */
6987 current_function_return_rtx = outgoing;
6988 }
6989
6990 /* If this is an implementation of throw, do what's necessary to
6991 communicate between __builtin_eh_return and the epilogue. */
6992 expand_eh_return ();
6993
6994 /* Emit the actual code to clobber return register. */
6995 {
6996 rtx seq, after;
6997
6998 start_sequence ();
6999 clobber_return_register ();
7000 seq = get_insns ();
7001 end_sequence ();
7002
7003 after = emit_insn_after (seq, clobber_after);
7004
7005 if (clobber_after != after)
7006 cfun->x_clobber_return_insn = after;
7007 }
7008
7009 /* ??? This should no longer be necessary since stupid is no longer with
7010 us, but there are some parts of the compiler (eg reload_combine, and
7011 sh mach_dep_reorg) that still try and compute their own lifetime info
7012 instead of using the general framework. */
7013 use_return_register ();
7014
7015 /* Fix up any gotos that jumped out to the outermost
7016 binding level of the function.
7017 Must follow emitting RETURN_LABEL. */
7018
7019 /* If you have any cleanups to do at this point,
7020 and they need to create temporary variables,
7021 then you will lose. */
7022 expand_fixups (get_insns ());
7023 }
7024
7025 rtx
7026 get_arg_pointer_save_area (f)
7027 struct function *f;
7028 {
7029 rtx ret = f->x_arg_pointer_save_area;
7030
7031 if (! ret)
7032 {
7033 ret = assign_stack_local_1 (Pmode, GET_MODE_SIZE (Pmode), 0, f);
7034 f->x_arg_pointer_save_area = ret;
7035 }
7036
7037 if (f == cfun && ! f->arg_pointer_save_area_init)
7038 {
7039 rtx seq;
7040
7041 /* Save the arg pointer at the beginning of the function. The
7042 generated stack slot may not be a valid memory address, so we
7043 have to check it and fix it if necessary. */
7044 start_sequence ();
7045 emit_move_insn (validize_mem (ret), virtual_incoming_args_rtx);
7046 seq = get_insns ();
7047 end_sequence ();
7048
7049 push_topmost_sequence ();
7050 emit_insn_after (seq, get_insns ());
7051 pop_topmost_sequence ();
7052 }
7053
7054 return ret;
7055 }
7056 \f
7057 /* Extend a vector that records the INSN_UIDs of INSNS
7058 (a list of one or more insns). */
7059
7060 static void
7061 record_insns (insns, vecp)
7062 rtx insns;
7063 varray_type *vecp;
7064 {
7065 int i, len;
7066 rtx tmp;
7067
7068 tmp = insns;
7069 len = 0;
7070 while (tmp != NULL_RTX)
7071 {
7072 len++;
7073 tmp = NEXT_INSN (tmp);
7074 }
7075
7076 i = VARRAY_SIZE (*vecp);
7077 VARRAY_GROW (*vecp, i + len);
7078 tmp = insns;
7079 while (tmp != NULL_RTX)
7080 {
7081 VARRAY_INT (*vecp, i) = INSN_UID (tmp);
7082 i++;
7083 tmp = NEXT_INSN (tmp);
7084 }
7085 }
7086
7087 /* Determine how many INSN_UIDs in VEC are part of INSN. Because we can
7088 be running after reorg, SEQUENCE rtl is possible. */
7089
7090 static int
7091 contains (insn, vec)
7092 rtx insn;
7093 varray_type vec;
7094 {
7095 int i, j;
7096
7097 if (GET_CODE (insn) == INSN
7098 && GET_CODE (PATTERN (insn)) == SEQUENCE)
7099 {
7100 int count = 0;
7101 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
7102 for (j = VARRAY_SIZE (vec) - 1; j >= 0; --j)
7103 if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == VARRAY_INT (vec, j))
7104 count++;
7105 return count;
7106 }
7107 else
7108 {
7109 for (j = VARRAY_SIZE (vec) - 1; j >= 0; --j)
7110 if (INSN_UID (insn) == VARRAY_INT (vec, j))
7111 return 1;
7112 }
7113 return 0;
7114 }
7115
7116 int
7117 prologue_epilogue_contains (insn)
7118 rtx insn;
7119 {
7120 if (contains (insn, prologue))
7121 return 1;
7122 if (contains (insn, epilogue))
7123 return 1;
7124 return 0;
7125 }
7126
7127 int
7128 sibcall_epilogue_contains (insn)
7129 rtx insn;
7130 {
7131 if (sibcall_epilogue)
7132 return contains (insn, sibcall_epilogue);
7133 return 0;
7134 }
7135
7136 #ifdef HAVE_return
7137 /* Insert gen_return at the end of block BB. This also means updating
7138 block_for_insn appropriately. */
7139
7140 static void
7141 emit_return_into_block (bb, line_note)
7142 basic_block bb;
7143 rtx line_note;
7144 {
7145 emit_jump_insn_after (gen_return (), bb->end);
7146 if (line_note)
7147 emit_line_note_after (NOTE_SOURCE_FILE (line_note),
7148 NOTE_LINE_NUMBER (line_note), PREV_INSN (bb->end));
7149 }
7150 #endif /* HAVE_return */
7151
7152 #if defined(HAVE_epilogue) && defined(INCOMING_RETURN_ADDR_RTX)
7153
7154 /* These functions convert the epilogue into a variant that does not modify the
7155 stack pointer. This is used in cases where a function returns an object
7156 whose size is not known until it is computed. The called function leaves the
7157 object on the stack, leaves the stack depressed, and returns a pointer to
7158 the object.
7159
7160 What we need to do is track all modifications and references to the stack
7161 pointer, deleting the modifications and changing the references to point to
7162 the location the stack pointer would have pointed to had the modifications
7163 taken place.
7164
7165 These functions need to be portable so we need to make as few assumptions
7166 about the epilogue as we can. However, the epilogue basically contains
7167 three things: instructions to reset the stack pointer, instructions to
7168 reload registers, possibly including the frame pointer, and an
7169 instruction to return to the caller.
7170
7171 If we can't be sure of what a relevant epilogue insn is doing, we abort.
7172 We also make no attempt to validate the insns we make since if they are
7173 invalid, we probably can't do anything valid. The intent is that these
7174 routines get "smarter" as more and more machines start to use them and
7175 they try operating on different epilogues.
7176
7177 We use the following structure to track what the part of the epilogue that
7178 we've already processed has done. We keep two copies of the SP equivalence,
7179 one for use during the insn we are processing and one for use in the next
7180 insn. The difference is because one part of a PARALLEL may adjust SP
7181 and the other may use it. */
7182
7183 struct epi_info
7184 {
7185 rtx sp_equiv_reg; /* REG that SP is set from, perhaps SP. */
7186 HOST_WIDE_INT sp_offset; /* Offset from SP_EQUIV_REG of present SP. */
7187 rtx new_sp_equiv_reg; /* REG to be used at end of insn. */
7188 HOST_WIDE_INT new_sp_offset; /* Offset to be used at end of insn. */
7189 rtx equiv_reg_src; /* If nonzero, the value that SP_EQUIV_REG
7190 should be set to once we no longer need
7191 its value. */
7192 };
7193
7194 static void handle_epilogue_set PARAMS ((rtx, struct epi_info *));
7195 static void emit_equiv_load PARAMS ((struct epi_info *));
7196
7197 /* Modify INSN, a list of one or more insns that is part of the epilogue, to
7198 no modifications to the stack pointer. Return the new list of insns. */
7199
7200 static rtx
7201 keep_stack_depressed (insns)
7202 rtx insns;
7203 {
7204 int j;
7205 struct epi_info info;
7206 rtx insn, next;
7207
7208 /* If the epilogue is just a single instruction, it ust be OK as is. */
7209
7210 if (NEXT_INSN (insns) == NULL_RTX)
7211 return insns;
7212
7213 /* Otherwise, start a sequence, initialize the information we have, and
7214 process all the insns we were given. */
7215 start_sequence ();
7216
7217 info.sp_equiv_reg = stack_pointer_rtx;
7218 info.sp_offset = 0;
7219 info.equiv_reg_src = 0;
7220
7221 insn = insns;
7222 next = NULL_RTX;
7223 while (insn != NULL_RTX)
7224 {
7225 next = NEXT_INSN (insn);
7226
7227 if (!INSN_P (insn))
7228 {
7229 add_insn (insn);
7230 insn = next;
7231 continue;
7232 }
7233
7234 /* If this insn references the register that SP is equivalent to and
7235 we have a pending load to that register, we must force out the load
7236 first and then indicate we no longer know what SP's equivalent is. */
7237 if (info.equiv_reg_src != 0
7238 && reg_referenced_p (info.sp_equiv_reg, PATTERN (insn)))
7239 {
7240 emit_equiv_load (&info);
7241 info.sp_equiv_reg = 0;
7242 }
7243
7244 info.new_sp_equiv_reg = info.sp_equiv_reg;
7245 info.new_sp_offset = info.sp_offset;
7246
7247 /* If this is a (RETURN) and the return address is on the stack,
7248 update the address and change to an indirect jump. */
7249 if (GET_CODE (PATTERN (insn)) == RETURN
7250 || (GET_CODE (PATTERN (insn)) == PARALLEL
7251 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == RETURN))
7252 {
7253 rtx retaddr = INCOMING_RETURN_ADDR_RTX;
7254 rtx base = 0;
7255 HOST_WIDE_INT offset = 0;
7256 rtx jump_insn, jump_set;
7257
7258 /* If the return address is in a register, we can emit the insn
7259 unchanged. Otherwise, it must be a MEM and we see what the
7260 base register and offset are. In any case, we have to emit any
7261 pending load to the equivalent reg of SP, if any. */
7262 if (GET_CODE (retaddr) == REG)
7263 {
7264 emit_equiv_load (&info);
7265 add_insn (insn);
7266 insn = next;
7267 continue;
7268 }
7269 else if (GET_CODE (retaddr) == MEM
7270 && GET_CODE (XEXP (retaddr, 0)) == REG)
7271 base = gen_rtx_REG (Pmode, REGNO (XEXP (retaddr, 0))), offset = 0;
7272 else if (GET_CODE (retaddr) == MEM
7273 && GET_CODE (XEXP (retaddr, 0)) == PLUS
7274 && GET_CODE (XEXP (XEXP (retaddr, 0), 0)) == REG
7275 && GET_CODE (XEXP (XEXP (retaddr, 0), 1)) == CONST_INT)
7276 {
7277 base = gen_rtx_REG (Pmode, REGNO (XEXP (XEXP (retaddr, 0), 0)));
7278 offset = INTVAL (XEXP (XEXP (retaddr, 0), 1));
7279 }
7280 else
7281 abort ();
7282
7283 /* If the base of the location containing the return pointer
7284 is SP, we must update it with the replacement address. Otherwise,
7285 just build the necessary MEM. */
7286 retaddr = plus_constant (base, offset);
7287 if (base == stack_pointer_rtx)
7288 retaddr = simplify_replace_rtx (retaddr, stack_pointer_rtx,
7289 plus_constant (info.sp_equiv_reg,
7290 info.sp_offset));
7291
7292 retaddr = gen_rtx_MEM (Pmode, retaddr);
7293
7294 /* If there is a pending load to the equivalent register for SP
7295 and we reference that register, we must load our address into
7296 a scratch register and then do that load. */
7297 if (info.equiv_reg_src
7298 && reg_overlap_mentioned_p (info.equiv_reg_src, retaddr))
7299 {
7300 unsigned int regno;
7301 rtx reg;
7302
7303 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7304 if (HARD_REGNO_MODE_OK (regno, Pmode)
7305 && !fixed_regs[regno]
7306 && TEST_HARD_REG_BIT (regs_invalidated_by_call, regno)
7307 && !REGNO_REG_SET_P (EXIT_BLOCK_PTR->global_live_at_start,
7308 regno)
7309 && !refers_to_regno_p (regno,
7310 regno + HARD_REGNO_NREGS (regno,
7311 Pmode),
7312 info.equiv_reg_src, NULL))
7313 break;
7314
7315 if (regno == FIRST_PSEUDO_REGISTER)
7316 abort ();
7317
7318 reg = gen_rtx_REG (Pmode, regno);
7319 emit_move_insn (reg, retaddr);
7320 retaddr = reg;
7321 }
7322
7323 emit_equiv_load (&info);
7324 jump_insn = emit_jump_insn (gen_indirect_jump (retaddr));
7325
7326 /* Show the SET in the above insn is a RETURN. */
7327 jump_set = single_set (jump_insn);
7328 if (jump_set == 0)
7329 abort ();
7330 else
7331 SET_IS_RETURN_P (jump_set) = 1;
7332 }
7333
7334 /* If SP is not mentioned in the pattern and its equivalent register, if
7335 any, is not modified, just emit it. Otherwise, if neither is set,
7336 replace the reference to SP and emit the insn. If none of those are
7337 true, handle each SET individually. */
7338 else if (!reg_mentioned_p (stack_pointer_rtx, PATTERN (insn))
7339 && (info.sp_equiv_reg == stack_pointer_rtx
7340 || !reg_set_p (info.sp_equiv_reg, insn)))
7341 add_insn (insn);
7342 else if (! reg_set_p (stack_pointer_rtx, insn)
7343 && (info.sp_equiv_reg == stack_pointer_rtx
7344 || !reg_set_p (info.sp_equiv_reg, insn)))
7345 {
7346 if (! validate_replace_rtx (stack_pointer_rtx,
7347 plus_constant (info.sp_equiv_reg,
7348 info.sp_offset),
7349 insn))
7350 abort ();
7351
7352 add_insn (insn);
7353 }
7354 else if (GET_CODE (PATTERN (insn)) == SET)
7355 handle_epilogue_set (PATTERN (insn), &info);
7356 else if (GET_CODE (PATTERN (insn)) == PARALLEL)
7357 {
7358 for (j = 0; j < XVECLEN (PATTERN (insn), 0); j++)
7359 if (GET_CODE (XVECEXP (PATTERN (insn), 0, j)) == SET)
7360 handle_epilogue_set (XVECEXP (PATTERN (insn), 0, j), &info);
7361 }
7362 else
7363 add_insn (insn);
7364
7365 info.sp_equiv_reg = info.new_sp_equiv_reg;
7366 info.sp_offset = info.new_sp_offset;
7367
7368 insn = next;
7369 }
7370
7371 insns = get_insns ();
7372 end_sequence ();
7373 return insns;
7374 }
7375
7376 /* SET is a SET from an insn in the epilogue. P is a pointer to the epi_info
7377 structure that contains information about what we've seen so far. We
7378 process this SET by either updating that data or by emitting one or
7379 more insns. */
7380
7381 static void
7382 handle_epilogue_set (set, p)
7383 rtx set;
7384 struct epi_info *p;
7385 {
7386 /* First handle the case where we are setting SP. Record what it is being
7387 set from. If unknown, abort. */
7388 if (reg_set_p (stack_pointer_rtx, set))
7389 {
7390 if (SET_DEST (set) != stack_pointer_rtx)
7391 abort ();
7392
7393 if (GET_CODE (SET_SRC (set)) == PLUS
7394 && GET_CODE (XEXP (SET_SRC (set), 1)) == CONST_INT)
7395 {
7396 p->new_sp_equiv_reg = XEXP (SET_SRC (set), 0);
7397 p->new_sp_offset = INTVAL (XEXP (SET_SRC (set), 1));
7398 }
7399 else
7400 p->new_sp_equiv_reg = SET_SRC (set), p->new_sp_offset = 0;
7401
7402 /* If we are adjusting SP, we adjust from the old data. */
7403 if (p->new_sp_equiv_reg == stack_pointer_rtx)
7404 {
7405 p->new_sp_equiv_reg = p->sp_equiv_reg;
7406 p->new_sp_offset += p->sp_offset;
7407 }
7408
7409 if (p->new_sp_equiv_reg == 0 || GET_CODE (p->new_sp_equiv_reg) != REG)
7410 abort ();
7411
7412 return;
7413 }
7414
7415 /* Next handle the case where we are setting SP's equivalent register.
7416 If we already have a value to set it to, abort. We could update, but
7417 there seems little point in handling that case. Note that we have
7418 to allow for the case where we are setting the register set in
7419 the previous part of a PARALLEL inside a single insn. But use the
7420 old offset for any updates within this insn. */
7421 else if (p->new_sp_equiv_reg != 0 && reg_set_p (p->new_sp_equiv_reg, set))
7422 {
7423 if (!rtx_equal_p (p->new_sp_equiv_reg, SET_DEST (set))
7424 || p->equiv_reg_src != 0)
7425 abort ();
7426 else
7427 p->equiv_reg_src
7428 = simplify_replace_rtx (SET_SRC (set), stack_pointer_rtx,
7429 plus_constant (p->sp_equiv_reg,
7430 p->sp_offset));
7431 }
7432
7433 /* Otherwise, replace any references to SP in the insn to its new value
7434 and emit the insn. */
7435 else
7436 {
7437 SET_SRC (set) = simplify_replace_rtx (SET_SRC (set), stack_pointer_rtx,
7438 plus_constant (p->sp_equiv_reg,
7439 p->sp_offset));
7440 SET_DEST (set) = simplify_replace_rtx (SET_DEST (set), stack_pointer_rtx,
7441 plus_constant (p->sp_equiv_reg,
7442 p->sp_offset));
7443 emit_insn (set);
7444 }
7445 }
7446
7447 /* Emit an insn to do the load shown in p->equiv_reg_src, if needed. */
7448
7449 static void
7450 emit_equiv_load (p)
7451 struct epi_info *p;
7452 {
7453 if (p->equiv_reg_src != 0)
7454 emit_move_insn (p->sp_equiv_reg, p->equiv_reg_src);
7455
7456 p->equiv_reg_src = 0;
7457 }
7458 #endif
7459
7460 /* Generate the prologue and epilogue RTL if the machine supports it. Thread
7461 this into place with notes indicating where the prologue ends and where
7462 the epilogue begins. Update the basic block information when possible. */
7463
7464 void
7465 thread_prologue_and_epilogue_insns (f)
7466 rtx f ATTRIBUTE_UNUSED;
7467 {
7468 int inserted = 0;
7469 edge e;
7470 #if defined (HAVE_sibcall_epilogue) || defined (HAVE_epilogue) || defined (HAVE_return) || defined (HAVE_prologue)
7471 rtx seq;
7472 #endif
7473 #ifdef HAVE_prologue
7474 rtx prologue_end = NULL_RTX;
7475 #endif
7476 #if defined (HAVE_epilogue) || defined(HAVE_return)
7477 rtx epilogue_end = NULL_RTX;
7478 #endif
7479
7480 #ifdef HAVE_prologue
7481 if (HAVE_prologue)
7482 {
7483 start_sequence ();
7484 seq = gen_prologue ();
7485 emit_insn (seq);
7486
7487 /* Retain a map of the prologue insns. */
7488 record_insns (seq, &prologue);
7489 prologue_end = emit_note (NULL, NOTE_INSN_PROLOGUE_END);
7490
7491 seq = get_insns ();
7492 end_sequence ();
7493
7494 /* Can't deal with multiple successors of the entry block
7495 at the moment. Function should always have at least one
7496 entry point. */
7497 if (!ENTRY_BLOCK_PTR->succ || ENTRY_BLOCK_PTR->succ->succ_next)
7498 abort ();
7499
7500 insert_insn_on_edge (seq, ENTRY_BLOCK_PTR->succ);
7501 inserted = 1;
7502 }
7503 #endif
7504
7505 /* If the exit block has no non-fake predecessors, we don't need
7506 an epilogue. */
7507 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7508 if ((e->flags & EDGE_FAKE) == 0)
7509 break;
7510 if (e == NULL)
7511 goto epilogue_done;
7512
7513 #ifdef HAVE_return
7514 if (optimize && HAVE_return)
7515 {
7516 /* If we're allowed to generate a simple return instruction,
7517 then by definition we don't need a full epilogue. Examine
7518 the block that falls through to EXIT. If it does not
7519 contain any code, examine its predecessors and try to
7520 emit (conditional) return instructions. */
7521
7522 basic_block last;
7523 edge e_next;
7524 rtx label;
7525
7526 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7527 if (e->flags & EDGE_FALLTHRU)
7528 break;
7529 if (e == NULL)
7530 goto epilogue_done;
7531 last = e->src;
7532
7533 /* Verify that there are no active instructions in the last block. */
7534 label = last->end;
7535 while (label && GET_CODE (label) != CODE_LABEL)
7536 {
7537 if (active_insn_p (label))
7538 break;
7539 label = PREV_INSN (label);
7540 }
7541
7542 if (last->head == label && GET_CODE (label) == CODE_LABEL)
7543 {
7544 rtx epilogue_line_note = NULL_RTX;
7545
7546 /* Locate the line number associated with the closing brace,
7547 if we can find one. */
7548 for (seq = get_last_insn ();
7549 seq && ! active_insn_p (seq);
7550 seq = PREV_INSN (seq))
7551 if (GET_CODE (seq) == NOTE && NOTE_LINE_NUMBER (seq) > 0)
7552 {
7553 epilogue_line_note = seq;
7554 break;
7555 }
7556
7557 for (e = last->pred; e; e = e_next)
7558 {
7559 basic_block bb = e->src;
7560 rtx jump;
7561
7562 e_next = e->pred_next;
7563 if (bb == ENTRY_BLOCK_PTR)
7564 continue;
7565
7566 jump = bb->end;
7567 if ((GET_CODE (jump) != JUMP_INSN) || JUMP_LABEL (jump) != label)
7568 continue;
7569
7570 /* If we have an unconditional jump, we can replace that
7571 with a simple return instruction. */
7572 if (simplejump_p (jump))
7573 {
7574 emit_return_into_block (bb, epilogue_line_note);
7575 delete_insn (jump);
7576 }
7577
7578 /* If we have a conditional jump, we can try to replace
7579 that with a conditional return instruction. */
7580 else if (condjump_p (jump))
7581 {
7582 rtx ret, *loc;
7583
7584 ret = SET_SRC (PATTERN (jump));
7585 if (GET_CODE (XEXP (ret, 1)) == LABEL_REF)
7586 loc = &XEXP (ret, 1);
7587 else
7588 loc = &XEXP (ret, 2);
7589 ret = gen_rtx_RETURN (VOIDmode);
7590
7591 if (! validate_change (jump, loc, ret, 0))
7592 continue;
7593 if (JUMP_LABEL (jump))
7594 LABEL_NUSES (JUMP_LABEL (jump))--;
7595
7596 /* If this block has only one successor, it both jumps
7597 and falls through to the fallthru block, so we can't
7598 delete the edge. */
7599 if (bb->succ->succ_next == NULL)
7600 continue;
7601 }
7602 else
7603 continue;
7604
7605 /* Fix up the CFG for the successful change we just made. */
7606 redirect_edge_succ (e, EXIT_BLOCK_PTR);
7607 }
7608
7609 /* Emit a return insn for the exit fallthru block. Whether
7610 this is still reachable will be determined later. */
7611
7612 emit_barrier_after (last->end);
7613 emit_return_into_block (last, epilogue_line_note);
7614 epilogue_end = last->end;
7615 last->succ->flags &= ~EDGE_FALLTHRU;
7616 goto epilogue_done;
7617 }
7618 }
7619 #endif
7620 #ifdef HAVE_epilogue
7621 if (HAVE_epilogue)
7622 {
7623 /* Find the edge that falls through to EXIT. Other edges may exist
7624 due to RETURN instructions, but those don't need epilogues.
7625 There really shouldn't be a mixture -- either all should have
7626 been converted or none, however... */
7627
7628 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7629 if (e->flags & EDGE_FALLTHRU)
7630 break;
7631 if (e == NULL)
7632 goto epilogue_done;
7633
7634 start_sequence ();
7635 epilogue_end = emit_note (NULL, NOTE_INSN_EPILOGUE_BEG);
7636
7637 seq = gen_epilogue ();
7638
7639 #ifdef INCOMING_RETURN_ADDR_RTX
7640 /* If this function returns with the stack depressed and we can support
7641 it, massage the epilogue to actually do that. */
7642 if (TREE_CODE (TREE_TYPE (current_function_decl)) == FUNCTION_TYPE
7643 && TYPE_RETURNS_STACK_DEPRESSED (TREE_TYPE (current_function_decl)))
7644 seq = keep_stack_depressed (seq);
7645 #endif
7646
7647 emit_jump_insn (seq);
7648
7649 /* Retain a map of the epilogue insns. */
7650 record_insns (seq, &epilogue);
7651
7652 seq = get_insns ();
7653 end_sequence ();
7654
7655 insert_insn_on_edge (seq, e);
7656 inserted = 1;
7657 }
7658 #endif
7659 epilogue_done:
7660
7661 if (inserted)
7662 commit_edge_insertions ();
7663
7664 #ifdef HAVE_sibcall_epilogue
7665 /* Emit sibling epilogues before any sibling call sites. */
7666 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7667 {
7668 basic_block bb = e->src;
7669 rtx insn = bb->end;
7670 rtx i;
7671 rtx newinsn;
7672
7673 if (GET_CODE (insn) != CALL_INSN
7674 || ! SIBLING_CALL_P (insn))
7675 continue;
7676
7677 start_sequence ();
7678 emit_insn (gen_sibcall_epilogue ());
7679 seq = get_insns ();
7680 end_sequence ();
7681
7682 /* Retain a map of the epilogue insns. Used in life analysis to
7683 avoid getting rid of sibcall epilogue insns. Do this before we
7684 actually emit the sequence. */
7685 record_insns (seq, &sibcall_epilogue);
7686
7687 i = PREV_INSN (insn);
7688 newinsn = emit_insn_before (seq, insn);
7689 }
7690 #endif
7691
7692 #ifdef HAVE_prologue
7693 if (prologue_end)
7694 {
7695 rtx insn, prev;
7696
7697 /* GDB handles `break f' by setting a breakpoint on the first
7698 line note after the prologue. Which means (1) that if
7699 there are line number notes before where we inserted the
7700 prologue we should move them, and (2) we should generate a
7701 note before the end of the first basic block, if there isn't
7702 one already there.
7703
7704 ??? This behavior is completely broken when dealing with
7705 multiple entry functions. We simply place the note always
7706 into first basic block and let alternate entry points
7707 to be missed.
7708 */
7709
7710 for (insn = prologue_end; insn; insn = prev)
7711 {
7712 prev = PREV_INSN (insn);
7713 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
7714 {
7715 /* Note that we cannot reorder the first insn in the
7716 chain, since rest_of_compilation relies on that
7717 remaining constant. */
7718 if (prev == NULL)
7719 break;
7720 reorder_insns (insn, insn, prologue_end);
7721 }
7722 }
7723
7724 /* Find the last line number note in the first block. */
7725 for (insn = ENTRY_BLOCK_PTR->next_bb->end;
7726 insn != prologue_end && insn;
7727 insn = PREV_INSN (insn))
7728 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
7729 break;
7730
7731 /* If we didn't find one, make a copy of the first line number
7732 we run across. */
7733 if (! insn)
7734 {
7735 for (insn = next_active_insn (prologue_end);
7736 insn;
7737 insn = PREV_INSN (insn))
7738 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
7739 {
7740 emit_line_note_after (NOTE_SOURCE_FILE (insn),
7741 NOTE_LINE_NUMBER (insn),
7742 prologue_end);
7743 break;
7744 }
7745 }
7746 }
7747 #endif
7748 #ifdef HAVE_epilogue
7749 if (epilogue_end)
7750 {
7751 rtx insn, next;
7752
7753 /* Similarly, move any line notes that appear after the epilogue.
7754 There is no need, however, to be quite so anal about the existence
7755 of such a note. */
7756 for (insn = epilogue_end; insn; insn = next)
7757 {
7758 next = NEXT_INSN (insn);
7759 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
7760 reorder_insns (insn, insn, PREV_INSN (epilogue_end));
7761 }
7762 }
7763 #endif
7764 }
7765
7766 /* Reposition the prologue-end and epilogue-begin notes after instruction
7767 scheduling and delayed branch scheduling. */
7768
7769 void
7770 reposition_prologue_and_epilogue_notes (f)
7771 rtx f ATTRIBUTE_UNUSED;
7772 {
7773 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
7774 rtx insn, last, note;
7775 int len;
7776
7777 if ((len = VARRAY_SIZE (prologue)) > 0)
7778 {
7779 last = 0, note = 0;
7780
7781 /* Scan from the beginning until we reach the last prologue insn.
7782 We apparently can't depend on basic_block_{head,end} after
7783 reorg has run. */
7784 for (insn = f; insn; insn = NEXT_INSN (insn))
7785 {
7786 if (GET_CODE (insn) == NOTE)
7787 {
7788 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
7789 note = insn;
7790 }
7791 else if (contains (insn, prologue))
7792 {
7793 last = insn;
7794 if (--len == 0)
7795 break;
7796 }
7797 }
7798
7799 if (last)
7800 {
7801 /* Find the prologue-end note if we haven't already, and
7802 move it to just after the last prologue insn. */
7803 if (note == 0)
7804 {
7805 for (note = last; (note = NEXT_INSN (note));)
7806 if (GET_CODE (note) == NOTE
7807 && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
7808 break;
7809 }
7810
7811 /* Avoid placing note between CODE_LABEL and BASIC_BLOCK note. */
7812 if (GET_CODE (last) == CODE_LABEL)
7813 last = NEXT_INSN (last);
7814 reorder_insns (note, note, last);
7815 }
7816 }
7817
7818 if ((len = VARRAY_SIZE (epilogue)) > 0)
7819 {
7820 last = 0, note = 0;
7821
7822 /* Scan from the end until we reach the first epilogue insn.
7823 We apparently can't depend on basic_block_{head,end} after
7824 reorg has run. */
7825 for (insn = get_last_insn (); insn; insn = PREV_INSN (insn))
7826 {
7827 if (GET_CODE (insn) == NOTE)
7828 {
7829 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
7830 note = insn;
7831 }
7832 else if (contains (insn, epilogue))
7833 {
7834 last = insn;
7835 if (--len == 0)
7836 break;
7837 }
7838 }
7839
7840 if (last)
7841 {
7842 /* Find the epilogue-begin note if we haven't already, and
7843 move it to just before the first epilogue insn. */
7844 if (note == 0)
7845 {
7846 for (note = insn; (note = PREV_INSN (note));)
7847 if (GET_CODE (note) == NOTE
7848 && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
7849 break;
7850 }
7851
7852 if (PREV_INSN (last) != note)
7853 reorder_insns (note, note, PREV_INSN (last));
7854 }
7855 }
7856 #endif /* HAVE_prologue or HAVE_epilogue */
7857 }
7858
7859 /* Called once, at initialization, to initialize function.c. */
7860
7861 void
7862 init_function_once ()
7863 {
7864 VARRAY_INT_INIT (prologue, 0, "prologue");
7865 VARRAY_INT_INIT (epilogue, 0, "epilogue");
7866 VARRAY_INT_INIT (sibcall_epilogue, 0, "sibcall_epilogue");
7867 }
7868
7869 #include "gt-function.h"