]> gcc.gnu.org Git - gcc.git/blame - gcc/function.c
reload1.c (emit_reload_insns): Accept a new arg for the bb.
[gcc.git] / gcc / function.c
CommitLineData
6f086dfc 1/* Expands front end tree to back end RTL for GNU C-Compiler
c85f7c16 2 Copyright (C) 1987, 88, 89, 91-97, 1998 Free Software Foundation, Inc.
6f086dfc
RS
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING. If not, write to
a35311b0
RK
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
6f086dfc
RS
20
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"
670ee920 42#include "system.h"
6f086dfc
RS
43#include "rtl.h"
44#include "tree.h"
45#include "flags.h"
1ef08c63 46#include "except.h"
6f086dfc
RS
47#include "function.h"
48#include "insn-flags.h"
49#include "expr.h"
50#include "insn-codes.h"
51#include "regs.h"
52#include "hard-reg-set.h"
53#include "insn-config.h"
54#include "recog.h"
55#include "output.h"
bdac5f58 56#include "basic-block.h"
c20bf1f3 57#include "obstack.h"
10f0ad3d 58#include "toplev.h"
6f086dfc 59
189cc377
RK
60#ifndef TRAMPOLINE_ALIGNMENT
61#define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
62#endif
63
293e3de4
RS
64/* Some systems use __main in a way incompatible with its use in gcc, in these
65 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
66 give the same symbol without quotes for an alternative entry point. You
0f41302f 67 must define both, or neither. */
293e3de4
RS
68#ifndef NAME__MAIN
69#define NAME__MAIN "__main"
70#define SYMBOL__MAIN __main
71#endif
72
6f086dfc
RS
73/* Round a value to the lowest integer less than it that is a multiple of
74 the required alignment. Avoid using division in case the value is
75 negative. Assume the alignment is a power of two. */
76#define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
77
78/* Similar, but round to the next highest integer that meets the
79 alignment. */
80#define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
81
82/* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp
83 during rtl generation. If they are different register numbers, this is
84 always true. It may also be true if
85 FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl
86 generation. See fix_lexical_addr for details. */
87
88#if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
89#define NEED_SEPARATE_AP
90#endif
91
92/* Number of bytes of args popped by function being compiled on its return.
93 Zero if no bytes are to be popped.
94 May affect compilation of return insn or of function epilogue. */
95
96int current_function_pops_args;
97
98/* Nonzero if function being compiled needs to be given an address
99 where the value should be stored. */
100
101int current_function_returns_struct;
102
103/* Nonzero if function being compiled needs to
104 return the address of where it has put a structure value. */
105
106int current_function_returns_pcc_struct;
107
108/* Nonzero if function being compiled needs to be passed a static chain. */
109
110int current_function_needs_context;
111
112/* Nonzero if function being compiled can call setjmp. */
113
114int current_function_calls_setjmp;
115
116/* Nonzero if function being compiled can call longjmp. */
117
118int current_function_calls_longjmp;
119
120/* Nonzero if function being compiled receives nonlocal gotos
121 from nested functions. */
122
123int current_function_has_nonlocal_label;
124
8634413a
JW
125/* Nonzero if function being compiled has nonlocal gotos to parent
126 function. */
127
128int current_function_has_nonlocal_goto;
129
4d1d8045
BS
130/* Nonzero if this function has a computed goto.
131
132 It is computed during find_basic_blocks or during stupid life
133 analysis. */
134
135int current_function_has_computed_jump;
136
6f086dfc
RS
137/* Nonzero if function being compiled contains nested functions. */
138
139int current_function_contains_functions;
140
173cd503
JM
141/* Nonzero if the current function is a thunk (a lightweight function that
142 just adjusts one of its arguments and forwards to another function), so
143 we should try to cut corners where we can. */
144int current_function_is_thunk;
145
6f086dfc
RS
146/* Nonzero if function being compiled can call alloca,
147 either as a subroutine or builtin. */
148
149int current_function_calls_alloca;
150
151/* Nonzero if the current function returns a pointer type */
152
153int current_function_returns_pointer;
154
155/* If some insns can be deferred to the delay slots of the epilogue, the
156 delay list for them is recorded here. */
157
158rtx current_function_epilogue_delay_list;
159
160/* If function's args have a fixed size, this is that size, in bytes.
161 Otherwise, it is -1.
162 May affect compilation of return insn or of function epilogue. */
163
164int current_function_args_size;
165
166/* # bytes the prologue should push and pretend that the caller pushed them.
167 The prologue must do this, but only if parms can be passed in registers. */
168
169int current_function_pretend_args_size;
170
f7339633 171/* # of bytes of outgoing arguments. If ACCUMULATE_OUTGOING_ARGS is
0f41302f 172 defined, the needed space is pushed by the prologue. */
6f086dfc
RS
173
174int current_function_outgoing_args_size;
175
176/* This is the offset from the arg pointer to the place where the first
177 anonymous arg can be found, if there is one. */
178
179rtx current_function_arg_offset_rtx;
180
181/* Nonzero if current function uses varargs.h or equivalent.
182 Zero for functions that use stdarg.h. */
183
184int current_function_varargs;
185
ebb904cb
RK
186/* Nonzero if current function uses stdarg.h or equivalent.
187 Zero for functions that use varargs.h. */
188
189int current_function_stdarg;
190
6f086dfc
RS
191/* Quantities of various kinds of registers
192 used for the current function's args. */
193
194CUMULATIVE_ARGS current_function_args_info;
195
196/* Name of function now being compiled. */
197
198char *current_function_name;
199
f345de42
JL
200/* If non-zero, an RTL expression for the location at which the current
201 function returns its result. If the current function returns its
202 result in a register, current_function_return_rtx will always be
203 the hard register containing the result. */
6f086dfc
RS
204
205rtx current_function_return_rtx;
206
207/* Nonzero if the current function uses the constant pool. */
208
209int current_function_uses_const_pool;
210
211/* Nonzero if the current function uses pic_offset_table_rtx. */
212int current_function_uses_pic_offset_table;
213
214/* The arg pointer hard register, or the pseudo into which it was copied. */
215rtx current_function_internal_arg_pointer;
216
aeb302bb
JM
217/* Language-specific reason why the current function cannot be made inline. */
218char *current_function_cannot_inline;
219
07417085
KR
220/* Nonzero if instrumentation calls for function entry and exit should be
221 generated. */
222int current_function_instrument_entry_exit;
223
6f086dfc
RS
224/* The FUNCTION_DECL for an inline function currently being expanded. */
225tree inline_function_decl;
226
227/* Number of function calls seen so far in current function. */
228
229int function_call_count;
230
231/* List (chain of TREE_LIST) of LABEL_DECLs for all nonlocal labels
232 (labels to which there can be nonlocal gotos from nested functions)
233 in this function. */
234
235tree nonlocal_labels;
236
237/* RTX for stack slot that holds the current handler for nonlocal gotos.
238 Zero when function does not have nonlocal labels. */
239
240rtx nonlocal_goto_handler_slot;
241
242/* RTX for stack slot that holds the stack pointer value to restore
243 for a nonlocal goto.
244 Zero when function does not have nonlocal labels. */
245
246rtx nonlocal_goto_stack_level;
247
248/* Label that will go on parm cleanup code, if any.
249 Jumping to this label runs cleanup code for parameters, if
250 such code must be run. Following this code is the logical return label. */
251
252rtx cleanup_label;
253
254/* Label that will go on function epilogue.
255 Jumping to this label serves as a "return" instruction
256 on machines which require execution of the epilogue on all returns. */
257
258rtx return_label;
259
260/* List (chain of EXPR_LISTs) of pseudo-regs of SAVE_EXPRs.
261 So we can mark them all live at the end of the function, if nonopt. */
262rtx save_expr_regs;
263
264/* List (chain of EXPR_LISTs) of all stack slots in this function.
265 Made for the sake of unshare_all_rtl. */
266rtx stack_slot_list;
267
268/* Chain of all RTL_EXPRs that have insns in them. */
269tree rtl_expr_chain;
270
271/* Label to jump back to for tail recursion, or 0 if we have
272 not yet needed one for this function. */
273rtx tail_recursion_label;
274
275/* Place after which to insert the tail_recursion_label if we need one. */
276rtx tail_recursion_reentry;
277
278/* Location at which to save the argument pointer if it will need to be
279 referenced. There are two cases where this is done: if nonlocal gotos
280 exist, or if vars stored at an offset from the argument pointer will be
281 needed by inner routines. */
282
283rtx arg_pointer_save_area;
284
285/* Offset to end of allocated area of stack frame.
286 If stack grows down, this is the address of the last stack slot allocated.
287 If stack grows up, this is the address for the next slot. */
8af5168b 288HOST_WIDE_INT frame_offset;
6f086dfc
RS
289
290/* List (chain of TREE_LISTs) of static chains for containing functions.
291 Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
292 in an RTL_EXPR in the TREE_VALUE. */
293static tree context_display;
294
295/* List (chain of TREE_LISTs) of trampolines for nested functions.
296 The trampoline sets up the static chain and jumps to the function.
297 We supply the trampoline's address when the function's address is requested.
298
299 Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
300 in an RTL_EXPR in the TREE_VALUE. */
301static tree trampoline_list;
302
303/* Insn after which register parms and SAVE_EXPRs are born, if nonopt. */
304static rtx parm_birth_insn;
305
306#if 0
307/* Nonzero if a stack slot has been generated whose address is not
308 actually valid. It means that the generated rtl must all be scanned
309 to detect and correct the invalid addresses where they occur. */
310static int invalid_stack_slot;
311#endif
312
313/* Last insn of those whose job was to put parms into their nominal homes. */
314static rtx last_parm_insn;
315
e9a25f70
JL
316/* 1 + last pseudo register number possibly used for loading a copy
317 of a parameter of this function. */
318int max_parm_reg;
6f086dfc
RS
319
320/* Vector indexed by REGNO, containing location on stack in which
321 to put the parm which is nominally in pseudo register REGNO,
e9a25f70
JL
322 if we discover that that parm must go in the stack. The highest
323 element in this vector is one less than MAX_PARM_REG, above. */
324rtx *parm_reg_stack_loc;
6f086dfc 325
6f086dfc
RS
326/* Nonzero once virtual register instantiation has been done.
327 assign_stack_local uses frame_pointer_rtx when this is nonzero. */
328static int virtuals_instantiated;
329
46766466
RS
330/* These variables hold pointers to functions to
331 save and restore machine-specific data,
332 in push_function_context and pop_function_context. */
9e014ded
RK
333void (*save_machine_status) PROTO((struct function *));
334void (*restore_machine_status) PROTO((struct function *));
46766466 335
6f086dfc
RS
336/* Nonzero if we need to distinguish between the return value of this function
337 and the return value of a function called by this function. This helps
338 integrate.c */
339
340extern int rtx_equal_function_value_matters;
e7a84011 341extern tree sequence_rtl_expr;
6f086dfc
RS
342\f
343/* In order to evaluate some expressions, such as function calls returning
344 structures in memory, we need to temporarily allocate stack locations.
345 We record each allocated temporary in the following structure.
346
347 Associated with each temporary slot is a nesting level. When we pop up
348 one level, all temporaries associated with the previous level are freed.
349 Normally, all temporaries are freed after the execution of the statement
350 in which they were created. However, if we are inside a ({...}) grouping,
351 the result may be in a temporary and hence must be preserved. If the
352 result could be in a temporary, we preserve it if we can determine which
353 one it is in. If we cannot determine which temporary may contain the
354 result, all temporaries are preserved. A temporary is preserved by
355 pretending it was allocated at the previous nesting level.
356
357 Automatic variables are also assigned temporary slots, at the nesting
358 level where they are defined. They are marked a "kept" so that
359 free_temp_slots will not free them. */
360
361struct temp_slot
362{
363 /* Points to next temporary slot. */
364 struct temp_slot *next;
0f41302f 365 /* The rtx to used to reference the slot. */
6f086dfc 366 rtx slot;
e5e76139
RK
367 /* The rtx used to represent the address if not the address of the
368 slot above. May be an EXPR_LIST if multiple addresses exist. */
369 rtx address;
6f086dfc 370 /* The size, in units, of the slot. */
e5e809f4 371 HOST_WIDE_INT size;
e7a84011
RK
372 /* The value of `sequence_rtl_expr' when this temporary is allocated. */
373 tree rtl_expr;
6f086dfc
RS
374 /* Non-zero if this temporary is currently in use. */
375 char in_use;
a25d4ba2
RK
376 /* Non-zero if this temporary has its address taken. */
377 char addr_taken;
6f086dfc
RS
378 /* Nesting level at which this slot is being used. */
379 int level;
380 /* Non-zero if this should survive a call to free_temp_slots. */
381 int keep;
fc91b0d0
RK
382 /* The offset of the slot from the frame_pointer, including extra space
383 for alignment. This info is for combine_temp_slots. */
e5e809f4 384 HOST_WIDE_INT base_offset;
fc91b0d0
RK
385 /* The size of the slot, including extra space for alignment. This
386 info is for combine_temp_slots. */
e5e809f4 387 HOST_WIDE_INT full_size;
6f086dfc
RS
388};
389
390/* List of all temporaries allocated, both available and in use. */
391
392struct temp_slot *temp_slots;
393
394/* Current nesting level for temporaries. */
395
396int temp_slot_level;
e5e809f4
JL
397
398/* Current nesting level for variables in a block. */
399
400int var_temp_slot_level;
f5963e61
JL
401
402/* When temporaries are created by TARGET_EXPRs, they are created at
403 this level of temp_slot_level, so that they can remain allocated
404 until no longer needed. CLEANUP_POINT_EXPRs define the lifetime
405 of TARGET_EXPRs. */
406int target_temp_slot_level;
6f086dfc 407\f
e15679f8
RK
408/* This structure is used to record MEMs or pseudos used to replace VAR, any
409 SUBREGs of VAR, and any MEMs containing VAR as an address. We need to
410 maintain this list in case two operands of an insn were required to match;
411 in that case we must ensure we use the same replacement. */
412
413struct fixup_replacement
414{
415 rtx old;
416 rtx new;
417 struct fixup_replacement *next;
418};
419
420/* Forward declarations. */
421
1ac4f799
JL
422static rtx assign_outer_stack_local PROTO ((enum machine_mode, HOST_WIDE_INT,
423 int, struct function *));
e15679f8
RK
424static struct temp_slot *find_temp_slot_from_address PROTO((rtx));
425static void put_reg_into_stack PROTO((struct function *, rtx, tree,
0006e95b 426 enum machine_mode, enum machine_mode,
e5e809f4 427 int, int, int));
e15679f8
RK
428static void fixup_var_refs PROTO((rtx, enum machine_mode, int));
429static struct fixup_replacement
430 *find_fixup_replacement PROTO((struct fixup_replacement **, rtx));
431static void fixup_var_refs_insns PROTO((rtx, enum machine_mode, int,
432 rtx, int));
433static void fixup_var_refs_1 PROTO((rtx, enum machine_mode, rtx *, rtx,
434 struct fixup_replacement **));
435static rtx fixup_memory_subreg PROTO((rtx, rtx, int));
436static rtx walk_fixup_memory_subreg PROTO((rtx, rtx, int));
437static rtx fixup_stack_1 PROTO((rtx, rtx));
438static void optimize_bit_field PROTO((rtx, rtx, rtx *));
439static void instantiate_decls PROTO((tree, int));
440static void instantiate_decls_1 PROTO((tree, int));
441static void instantiate_decl PROTO((rtx, int, int));
442static int instantiate_virtual_regs_1 PROTO((rtx *, rtx, int));
443static void delete_handlers PROTO((void));
444static void pad_to_arg_alignment PROTO((struct args_size *, int));
51723711 445#ifndef ARGS_GROW_DOWNWARD
e15679f8
RK
446static void pad_below PROTO((struct args_size *, enum machine_mode,
447 tree));
51723711 448#endif
487a6e06 449#ifdef ARGS_GROW_DOWNWARD
e15679f8 450static tree round_down PROTO((tree, int));
487a6e06 451#endif
e15679f8
RK
452static rtx round_trampoline_addr PROTO((rtx));
453static tree blocks_nreverse PROTO((tree));
454static int all_blocks PROTO((tree, tree *));
081f5e7e 455#if defined (HAVE_prologue) || defined (HAVE_epilogue)
487a6e06 456static int *record_insns PROTO((rtx));
e15679f8 457static int contains PROTO((rtx, int *));
081f5e7e 458#endif /* HAVE_prologue || HAVE_epilogue */
e9a25f70
JL
459static void put_addressof_into_stack PROTO((rtx));
460static void purge_addressof_1 PROTO((rtx *, rtx, int));
c20bf1f3 461\f
6f086dfc
RS
462/* Pointer to chain of `struct function' for containing functions. */
463struct function *outer_function_chain;
464
465/* Given a function decl for a containing function,
466 return the `struct function' for it. */
467
468struct function *
469find_function_data (decl)
470 tree decl;
471{
472 struct function *p;
e5e809f4 473
6f086dfc
RS
474 for (p = outer_function_chain; p; p = p->next)
475 if (p->decl == decl)
476 return p;
e5e809f4 477
6f086dfc
RS
478 abort ();
479}
480
481/* Save the current context for compilation of a nested function.
482 This is called from language-specific code.
483 The caller is responsible for saving any language-specific status,
6dc42e49 484 since this function knows only about language-independent variables. */
6f086dfc
RS
485
486void
a0dabda5
JM
487push_function_context_to (context)
488 tree context;
6f086dfc
RS
489{
490 struct function *p = (struct function *) xmalloc (sizeof (struct function));
491
492 p->next = outer_function_chain;
493 outer_function_chain = p;
494
495 p->name = current_function_name;
496 p->decl = current_function_decl;
497 p->pops_args = current_function_pops_args;
498 p->returns_struct = current_function_returns_struct;
499 p->returns_pcc_struct = current_function_returns_pcc_struct;
1651bdfe 500 p->returns_pointer = current_function_returns_pointer;
6f086dfc
RS
501 p->needs_context = current_function_needs_context;
502 p->calls_setjmp = current_function_calls_setjmp;
503 p->calls_longjmp = current_function_calls_longjmp;
504 p->calls_alloca = current_function_calls_alloca;
505 p->has_nonlocal_label = current_function_has_nonlocal_label;
8634413a 506 p->has_nonlocal_goto = current_function_has_nonlocal_goto;
a0dabda5 507 p->contains_functions = current_function_contains_functions;
173cd503 508 p->is_thunk = current_function_is_thunk;
6f086dfc
RS
509 p->args_size = current_function_args_size;
510 p->pretend_args_size = current_function_pretend_args_size;
511 p->arg_offset_rtx = current_function_arg_offset_rtx;
3b69d50e 512 p->varargs = current_function_varargs;
ebb904cb 513 p->stdarg = current_function_stdarg;
6f086dfc
RS
514 p->uses_const_pool = current_function_uses_const_pool;
515 p->uses_pic_offset_table = current_function_uses_pic_offset_table;
516 p->internal_arg_pointer = current_function_internal_arg_pointer;
aeb302bb 517 p->cannot_inline = current_function_cannot_inline;
6f086dfc
RS
518 p->max_parm_reg = max_parm_reg;
519 p->parm_reg_stack_loc = parm_reg_stack_loc;
520 p->outgoing_args_size = current_function_outgoing_args_size;
521 p->return_rtx = current_function_return_rtx;
522 p->nonlocal_goto_handler_slot = nonlocal_goto_handler_slot;
523 p->nonlocal_goto_stack_level = nonlocal_goto_stack_level;
524 p->nonlocal_labels = nonlocal_labels;
525 p->cleanup_label = cleanup_label;
526 p->return_label = return_label;
527 p->save_expr_regs = save_expr_regs;
528 p->stack_slot_list = stack_slot_list;
529 p->parm_birth_insn = parm_birth_insn;
530 p->frame_offset = frame_offset;
531 p->tail_recursion_label = tail_recursion_label;
532 p->tail_recursion_reentry = tail_recursion_reentry;
533 p->arg_pointer_save_area = arg_pointer_save_area;
534 p->rtl_expr_chain = rtl_expr_chain;
535 p->last_parm_insn = last_parm_insn;
536 p->context_display = context_display;
537 p->trampoline_list = trampoline_list;
538 p->function_call_count = function_call_count;
539 p->temp_slots = temp_slots;
540 p->temp_slot_level = temp_slot_level;
e5e809f4
JL
541 p->target_temp_slot_level = target_temp_slot_level;
542 p->var_temp_slot_level = var_temp_slot_level;
6f086dfc 543 p->fixup_var_refs_queue = 0;
f979c996 544 p->epilogue_delay_list = current_function_epilogue_delay_list;
01c1558a 545 p->args_info = current_function_args_info;
07417085 546 p->instrument_entry_exit = current_function_instrument_entry_exit;
6f086dfc 547
a0dabda5 548 save_tree_status (p, context);
6f086dfc
RS
549 save_storage_status (p);
550 save_emit_status (p);
6f086dfc
RS
551 save_expr_status (p);
552 save_stmt_status (p);
e9a25f70 553 save_varasm_status (p, context);
46766466
RS
554 if (save_machine_status)
555 (*save_machine_status) (p);
6f086dfc
RS
556}
557
e4a4639e
JM
558void
559push_function_context ()
560{
a0dabda5 561 push_function_context_to (current_function_decl);
e4a4639e
JM
562}
563
6f086dfc
RS
564/* Restore the last saved context, at the end of a nested function.
565 This function is called from language-specific code. */
566
567void
a0dabda5
JM
568pop_function_context_from (context)
569 tree context;
6f086dfc
RS
570{
571 struct function *p = outer_function_chain;
e5e809f4 572 struct var_refs_queue *queue;
6f086dfc
RS
573
574 outer_function_chain = p->next;
575
49468af2
RK
576 current_function_contains_functions
577 = p->contains_functions || p->inline_obstacks
578 || context == current_function_decl;
6f086dfc
RS
579 current_function_name = p->name;
580 current_function_decl = p->decl;
581 current_function_pops_args = p->pops_args;
582 current_function_returns_struct = p->returns_struct;
583 current_function_returns_pcc_struct = p->returns_pcc_struct;
1651bdfe 584 current_function_returns_pointer = p->returns_pointer;
6f086dfc
RS
585 current_function_needs_context = p->needs_context;
586 current_function_calls_setjmp = p->calls_setjmp;
587 current_function_calls_longjmp = p->calls_longjmp;
588 current_function_calls_alloca = p->calls_alloca;
589 current_function_has_nonlocal_label = p->has_nonlocal_label;
8634413a 590 current_function_has_nonlocal_goto = p->has_nonlocal_goto;
173cd503 591 current_function_is_thunk = p->is_thunk;
6f086dfc
RS
592 current_function_args_size = p->args_size;
593 current_function_pretend_args_size = p->pretend_args_size;
594 current_function_arg_offset_rtx = p->arg_offset_rtx;
3b69d50e 595 current_function_varargs = p->varargs;
ebb904cb 596 current_function_stdarg = p->stdarg;
6f086dfc
RS
597 current_function_uses_const_pool = p->uses_const_pool;
598 current_function_uses_pic_offset_table = p->uses_pic_offset_table;
599 current_function_internal_arg_pointer = p->internal_arg_pointer;
aeb302bb 600 current_function_cannot_inline = p->cannot_inline;
6f086dfc
RS
601 max_parm_reg = p->max_parm_reg;
602 parm_reg_stack_loc = p->parm_reg_stack_loc;
603 current_function_outgoing_args_size = p->outgoing_args_size;
604 current_function_return_rtx = p->return_rtx;
605 nonlocal_goto_handler_slot = p->nonlocal_goto_handler_slot;
606 nonlocal_goto_stack_level = p->nonlocal_goto_stack_level;
607 nonlocal_labels = p->nonlocal_labels;
608 cleanup_label = p->cleanup_label;
609 return_label = p->return_label;
610 save_expr_regs = p->save_expr_regs;
611 stack_slot_list = p->stack_slot_list;
612 parm_birth_insn = p->parm_birth_insn;
613 frame_offset = p->frame_offset;
614 tail_recursion_label = p->tail_recursion_label;
615 tail_recursion_reentry = p->tail_recursion_reentry;
616 arg_pointer_save_area = p->arg_pointer_save_area;
617 rtl_expr_chain = p->rtl_expr_chain;
618 last_parm_insn = p->last_parm_insn;
619 context_display = p->context_display;
620 trampoline_list = p->trampoline_list;
621 function_call_count = p->function_call_count;
622 temp_slots = p->temp_slots;
623 temp_slot_level = p->temp_slot_level;
e5e809f4
JL
624 target_temp_slot_level = p->target_temp_slot_level;
625 var_temp_slot_level = p->var_temp_slot_level;
f979c996 626 current_function_epilogue_delay_list = p->epilogue_delay_list;
7cbc7b0c 627 reg_renumber = 0;
01c1558a 628 current_function_args_info = p->args_info;
07417085 629 current_function_instrument_entry_exit = p->instrument_entry_exit;
6f086dfc 630
d1485032 631 restore_tree_status (p, context);
6f086dfc
RS
632 restore_storage_status (p);
633 restore_expr_status (p);
634 restore_emit_status (p);
635 restore_stmt_status (p);
a506307a 636 restore_varasm_status (p);
6f086dfc 637
46766466
RS
638 if (restore_machine_status)
639 (*restore_machine_status) (p);
640
6f086dfc
RS
641 /* Finish doing put_var_into_stack for any of our variables
642 which became addressable during the nested function. */
e5e809f4
JL
643 for (queue = p->fixup_var_refs_queue; queue; queue = queue->next)
644 fixup_var_refs (queue->modified, queue->promoted_mode, queue->unsignedp);
6f086dfc
RS
645
646 free (p);
647
648 /* Reset variables that have known state during rtx generation. */
649 rtx_equal_function_value_matters = 1;
650 virtuals_instantiated = 0;
651}
e4a4639e
JM
652
653void pop_function_context ()
654{
a0dabda5 655 pop_function_context_from (current_function_decl);
e4a4639e 656}
6f086dfc
RS
657\f
658/* Allocate fixed slots in the stack frame of the current function. */
659
660/* Return size needed for stack frame based on slots so far allocated.
661 This size counts from zero. It is not rounded to STACK_BOUNDARY;
662 the caller may have to do that. */
663
8af5168b 664HOST_WIDE_INT
6f086dfc
RS
665get_frame_size ()
666{
667#ifdef FRAME_GROWS_DOWNWARD
668 return -frame_offset;
669#else
670 return frame_offset;
671#endif
672}
673
674/* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
675 with machine mode MODE.
676
677 ALIGN controls the amount of alignment for the address of the slot:
678 0 means according to MODE,
679 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
680 positive specifies alignment boundary in bits.
681
682 We do not round to stack_boundary here. */
683
684rtx
685assign_stack_local (mode, size, align)
686 enum machine_mode mode;
e5e809f4 687 HOST_WIDE_INT size;
6f086dfc
RS
688 int align;
689{
690 register rtx x, addr;
691 int bigend_correction = 0;
692 int alignment;
693
694 if (align == 0)
695 {
696 alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
697 if (mode == BLKmode)
698 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
699 }
700 else if (align == -1)
701 {
702 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
703 size = CEIL_ROUND (size, alignment);
704 }
705 else
706 alignment = align / BITS_PER_UNIT;
707
6f086dfc
RS
708 /* Round frame offset to that alignment.
709 We must be careful here, since FRAME_OFFSET might be negative and
710 division with a negative dividend isn't as well defined as we might
711 like. So we instead assume that ALIGNMENT is a power of two and
712 use logical operations which are unambiguous. */
713#ifdef FRAME_GROWS_DOWNWARD
714 frame_offset = FLOOR_ROUND (frame_offset, alignment);
715#else
716 frame_offset = CEIL_ROUND (frame_offset, alignment);
717#endif
718
719 /* On a big-endian machine, if we are allocating more space than we will use,
720 use the least significant bytes of those that are allocated. */
f76b9db2 721 if (BYTES_BIG_ENDIAN && mode != BLKmode)
6f086dfc 722 bigend_correction = size - GET_MODE_SIZE (mode);
6f086dfc
RS
723
724#ifdef FRAME_GROWS_DOWNWARD
725 frame_offset -= size;
726#endif
727
728 /* If we have already instantiated virtual registers, return the actual
729 address relative to the frame pointer. */
730 if (virtuals_instantiated)
731 addr = plus_constant (frame_pointer_rtx,
732 (frame_offset + bigend_correction
733 + STARTING_FRAME_OFFSET));
734 else
735 addr = plus_constant (virtual_stack_vars_rtx,
736 frame_offset + bigend_correction);
737
738#ifndef FRAME_GROWS_DOWNWARD
739 frame_offset += size;
740#endif
741
38a448ca 742 x = gen_rtx_MEM (mode, addr);
6f086dfc 743
38a448ca 744 stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, x, stack_slot_list);
6f086dfc
RS
745
746 return x;
747}
748
749/* Assign a stack slot in a containing function.
750 First three arguments are same as in preceding function.
751 The last argument specifies the function to allocate in. */
752
1ac4f799 753static rtx
6f086dfc
RS
754assign_outer_stack_local (mode, size, align, function)
755 enum machine_mode mode;
e5e809f4 756 HOST_WIDE_INT size;
6f086dfc
RS
757 int align;
758 struct function *function;
759{
760 register rtx x, addr;
761 int bigend_correction = 0;
762 int alignment;
763
764 /* Allocate in the memory associated with the function in whose frame
765 we are assigning. */
766 push_obstacks (function->function_obstack,
767 function->function_maybepermanent_obstack);
768
769 if (align == 0)
770 {
771 alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
772 if (mode == BLKmode)
773 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
774 }
775 else if (align == -1)
776 {
777 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
778 size = CEIL_ROUND (size, alignment);
779 }
780 else
781 alignment = align / BITS_PER_UNIT;
782
6f086dfc
RS
783 /* Round frame offset to that alignment. */
784#ifdef FRAME_GROWS_DOWNWARD
2af69b62 785 function->frame_offset = FLOOR_ROUND (function->frame_offset, alignment);
6f086dfc 786#else
2af69b62 787 function->frame_offset = CEIL_ROUND (function->frame_offset, alignment);
6f086dfc
RS
788#endif
789
790 /* On a big-endian machine, if we are allocating more space than we will use,
791 use the least significant bytes of those that are allocated. */
f76b9db2 792 if (BYTES_BIG_ENDIAN && mode != BLKmode)
6f086dfc 793 bigend_correction = size - GET_MODE_SIZE (mode);
6f086dfc
RS
794
795#ifdef FRAME_GROWS_DOWNWARD
796 function->frame_offset -= size;
797#endif
798 addr = plus_constant (virtual_stack_vars_rtx,
799 function->frame_offset + bigend_correction);
800#ifndef FRAME_GROWS_DOWNWARD
801 function->frame_offset += size;
802#endif
803
38a448ca 804 x = gen_rtx_MEM (mode, addr);
6f086dfc
RS
805
806 function->stack_slot_list
38a448ca 807 = gen_rtx_EXPR_LIST (VOIDmode, x, function->stack_slot_list);
6f086dfc
RS
808
809 pop_obstacks ();
810
811 return x;
812}
813\f
814/* Allocate a temporary stack slot and record it for possible later
815 reuse.
816
817 MODE is the machine mode to be given to the returned rtx.
818
819 SIZE is the size in units of the space required. We do no rounding here
820 since assign_stack_local will do any required rounding.
821
d93d4205
MS
822 KEEP is 1 if this slot is to be retained after a call to
823 free_temp_slots. Automatic variables for a block are allocated
e5e809f4
JL
824 with this flag. KEEP is 2 if we allocate a longer term temporary,
825 whose lifetime is controlled by CLEANUP_POINT_EXPRs. KEEP is 3
826 if we are to allocate something at an inner level to be treated as
827 a variable in the block (e.g., a SAVE_EXPR). */
6f086dfc
RS
828
829rtx
830assign_stack_temp (mode, size, keep)
831 enum machine_mode mode;
e5e809f4 832 HOST_WIDE_INT size;
6f086dfc
RS
833 int keep;
834{
835 struct temp_slot *p, *best_p = 0;
836
303ec2aa
RK
837 /* If SIZE is -1 it means that somebody tried to allocate a temporary
838 of a variable size. */
839 if (size == -1)
840 abort ();
841
6f086dfc
RS
842 /* First try to find an available, already-allocated temporary that is the
843 exact size we require. */
844 for (p = temp_slots; p; p = p->next)
845 if (p->size == size && GET_MODE (p->slot) == mode && ! p->in_use)
846 break;
847
848 /* If we didn't find, one, try one that is larger than what we want. We
849 find the smallest such. */
850 if (p == 0)
851 for (p = temp_slots; p; p = p->next)
852 if (p->size > size && GET_MODE (p->slot) == mode && ! p->in_use
853 && (best_p == 0 || best_p->size > p->size))
854 best_p = p;
855
856 /* Make our best, if any, the one to use. */
857 if (best_p)
a45035b6
JW
858 {
859 /* If there are enough aligned bytes left over, make them into a new
860 temp_slot so that the extra bytes don't get wasted. Do this only
861 for BLKmode slots, so that we can be sure of the alignment. */
862 if (GET_MODE (best_p->slot) == BLKmode)
863 {
864 int alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
e5e809f4 865 HOST_WIDE_INT rounded_size = CEIL_ROUND (size, alignment);
a45035b6
JW
866
867 if (best_p->size - rounded_size >= alignment)
868 {
869 p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
a25d4ba2 870 p->in_use = p->addr_taken = 0;
a45035b6 871 p->size = best_p->size - rounded_size;
307d8cd6
RK
872 p->base_offset = best_p->base_offset + rounded_size;
873 p->full_size = best_p->full_size - rounded_size;
38a448ca
RH
874 p->slot = gen_rtx_MEM (BLKmode,
875 plus_constant (XEXP (best_p->slot, 0),
876 rounded_size));
e5e76139 877 p->address = 0;
84e24c03 878 p->rtl_expr = 0;
a45035b6
JW
879 p->next = temp_slots;
880 temp_slots = p;
881
38a448ca
RH
882 stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, p->slot,
883 stack_slot_list);
a45035b6
JW
884
885 best_p->size = rounded_size;
291dde90 886 best_p->full_size = rounded_size;
a45035b6
JW
887 }
888 }
889
890 p = best_p;
891 }
892
6f086dfc
RS
893 /* If we still didn't find one, make a new temporary. */
894 if (p == 0)
895 {
e5e809f4
JL
896 HOST_WIDE_INT frame_offset_old = frame_offset;
897
6f086dfc 898 p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
e5e809f4 899
6f086dfc
RS
900 /* If the temp slot mode doesn't indicate the alignment,
901 use the largest possible, so no one will be disappointed. */
e5e76139 902 p->slot = assign_stack_local (mode, size, mode == BLKmode ? -1 : 0);
e5e809f4 903
b2a80c0d
DE
904 /* The following slot size computation is necessary because we don't
905 know the actual size of the temporary slot until assign_stack_local
906 has performed all the frame alignment and size rounding for the
fc91b0d0
RK
907 requested temporary. Note that extra space added for alignment
908 can be either above or below this stack slot depending on which
909 way the frame grows. We include the extra space if and only if it
910 is above this slot. */
b2a80c0d
DE
911#ifdef FRAME_GROWS_DOWNWARD
912 p->size = frame_offset_old - frame_offset;
913#else
fc91b0d0
RK
914 p->size = size;
915#endif
e5e809f4 916
fc91b0d0
RK
917 /* Now define the fields used by combine_temp_slots. */
918#ifdef FRAME_GROWS_DOWNWARD
919 p->base_offset = frame_offset;
920 p->full_size = frame_offset_old - frame_offset;
921#else
922 p->base_offset = frame_offset_old;
923 p->full_size = frame_offset - frame_offset_old;
b2a80c0d 924#endif
e5e76139 925 p->address = 0;
6f086dfc
RS
926 p->next = temp_slots;
927 temp_slots = p;
928 }
929
930 p->in_use = 1;
a25d4ba2 931 p->addr_taken = 0;
e7a84011 932 p->rtl_expr = sequence_rtl_expr;
a25d4ba2 933
d93d4205
MS
934 if (keep == 2)
935 {
936 p->level = target_temp_slot_level;
937 p->keep = 0;
938 }
e5e809f4
JL
939 else if (keep == 3)
940 {
941 p->level = var_temp_slot_level;
942 p->keep = 0;
943 }
d93d4205
MS
944 else
945 {
946 p->level = temp_slot_level;
947 p->keep = keep;
948 }
1995f267
RK
949
950 /* We may be reusing an old slot, so clear any MEM flags that may have been
951 set from before. */
952 RTX_UNCHANGING_P (p->slot) = 0;
953 MEM_IN_STRUCT_P (p->slot) = 0;
6f086dfc
RS
954 return p->slot;
955}
638141a6 956\f
230f21b4
PB
957/* Assign a temporary of given TYPE.
958 KEEP is as for assign_stack_temp.
959 MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
b55d9ff8
RK
960 it is 0 if a register is OK.
961 DONT_PROMOTE is 1 if we should not promote values in register
962 to wider modes. */
230f21b4
PB
963
964rtx
b55d9ff8 965assign_temp (type, keep, memory_required, dont_promote)
230f21b4
PB
966 tree type;
967 int keep;
968 int memory_required;
b55d9ff8 969 int dont_promote;
230f21b4
PB
970{
971 enum machine_mode mode = TYPE_MODE (type);
638141a6
RK
972 int unsignedp = TREE_UNSIGNED (type);
973
230f21b4
PB
974 if (mode == BLKmode || memory_required)
975 {
e5e809f4 976 HOST_WIDE_INT size = int_size_in_bytes (type);
230f21b4
PB
977 rtx tmp;
978
979 /* Unfortunately, we don't yet know how to allocate variable-sized
980 temporaries. However, sometimes we have a fixed upper limit on
981 the size (which is stored in TYPE_ARRAY_MAX_SIZE) and can use that
0f41302f 982 instead. This is the case for Chill variable-sized strings. */
230f21b4
PB
983 if (size == -1 && TREE_CODE (type) == ARRAY_TYPE
984 && TYPE_ARRAY_MAX_SIZE (type) != NULL_TREE
985 && TREE_CODE (TYPE_ARRAY_MAX_SIZE (type)) == INTEGER_CST)
986 size = TREE_INT_CST_LOW (TYPE_ARRAY_MAX_SIZE (type));
987
988 tmp = assign_stack_temp (mode, size, keep);
989 MEM_IN_STRUCT_P (tmp) = AGGREGATE_TYPE_P (type);
990 return tmp;
991 }
638141a6 992
230f21b4 993#ifndef PROMOTE_FOR_CALL_ONLY
b55d9ff8
RK
994 if (! dont_promote)
995 mode = promote_mode (type, mode, &unsignedp, 0);
230f21b4 996#endif
638141a6 997
230f21b4
PB
998 return gen_reg_rtx (mode);
999}
638141a6 1000\f
a45035b6
JW
1001/* Combine temporary stack slots which are adjacent on the stack.
1002
1003 This allows for better use of already allocated stack space. This is only
1004 done for BLKmode slots because we can be sure that we won't have alignment
1005 problems in this case. */
1006
1007void
1008combine_temp_slots ()
1009{
1010 struct temp_slot *p, *q;
1011 struct temp_slot *prev_p, *prev_q;
e5e809f4
JL
1012 int num_slots;
1013
1014 /* If there are a lot of temp slots, don't do anything unless
1015 high levels of optimizaton. */
1016 if (! flag_expensive_optimizations)
1017 for (p = temp_slots, num_slots = 0; p; p = p->next, num_slots++)
1018 if (num_slots > 100 || (num_slots > 10 && optimize == 0))
1019 return;
a45035b6 1020
e9b7093a
RS
1021 for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots)
1022 {
1023 int delete_p = 0;
e5e809f4 1024
e9b7093a
RS
1025 if (! p->in_use && GET_MODE (p->slot) == BLKmode)
1026 for (q = p->next, prev_q = p; q; q = prev_q->next)
a45035b6 1027 {
e9b7093a
RS
1028 int delete_q = 0;
1029 if (! q->in_use && GET_MODE (q->slot) == BLKmode)
a45035b6 1030 {
fc91b0d0 1031 if (p->base_offset + p->full_size == q->base_offset)
e9b7093a
RS
1032 {
1033 /* Q comes after P; combine Q into P. */
1034 p->size += q->size;
307d8cd6 1035 p->full_size += q->full_size;
e9b7093a
RS
1036 delete_q = 1;
1037 }
fc91b0d0 1038 else if (q->base_offset + q->full_size == p->base_offset)
e9b7093a
RS
1039 {
1040 /* P comes after Q; combine P into Q. */
1041 q->size += p->size;
307d8cd6 1042 q->full_size += p->full_size;
e9b7093a
RS
1043 delete_p = 1;
1044 break;
1045 }
a45035b6 1046 }
e9b7093a
RS
1047 /* Either delete Q or advance past it. */
1048 if (delete_q)
1049 prev_q->next = q->next;
1050 else
1051 prev_q = q;
a45035b6 1052 }
e9b7093a
RS
1053 /* Either delete P or advance past it. */
1054 if (delete_p)
1055 {
1056 if (prev_p)
1057 prev_p->next = p->next;
1058 else
1059 temp_slots = p->next;
1060 }
1061 else
1062 prev_p = p;
1063 }
a45035b6 1064}
6f086dfc 1065\f
e5e76139
RK
1066/* Find the temp slot corresponding to the object at address X. */
1067
1068static struct temp_slot *
1069find_temp_slot_from_address (x)
1070 rtx x;
1071{
1072 struct temp_slot *p;
1073 rtx next;
1074
1075 for (p = temp_slots; p; p = p->next)
1076 {
1077 if (! p->in_use)
1078 continue;
e5e809f4 1079
e5e76139 1080 else if (XEXP (p->slot, 0) == x
abb52246
RK
1081 || p->address == x
1082 || (GET_CODE (x) == PLUS
1083 && XEXP (x, 0) == virtual_stack_vars_rtx
1084 && GET_CODE (XEXP (x, 1)) == CONST_INT
1085 && INTVAL (XEXP (x, 1)) >= p->base_offset
1086 && INTVAL (XEXP (x, 1)) < p->base_offset + p->full_size))
e5e76139
RK
1087 return p;
1088
1089 else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST)
1090 for (next = p->address; next; next = XEXP (next, 1))
1091 if (XEXP (next, 0) == x)
1092 return p;
1093 }
1094
1095 return 0;
1096}
1097
9faa82d8 1098/* Indicate that NEW is an alternate way of referring to the temp slot
e5e809f4 1099 that previously was known by OLD. */
e5e76139
RK
1100
1101void
1102update_temp_slot_address (old, new)
1103 rtx old, new;
1104{
1105 struct temp_slot *p = find_temp_slot_from_address (old);
1106
1107 /* If none, return. Else add NEW as an alias. */
1108 if (p == 0)
1109 return;
1110 else if (p->address == 0)
1111 p->address = new;
1112 else
1113 {
1114 if (GET_CODE (p->address) != EXPR_LIST)
38a448ca 1115 p->address = gen_rtx_EXPR_LIST (VOIDmode, p->address, NULL_RTX);
e5e76139 1116
38a448ca 1117 p->address = gen_rtx_EXPR_LIST (VOIDmode, new, p->address);
e5e76139
RK
1118 }
1119}
1120
a25d4ba2 1121/* If X could be a reference to a temporary slot, mark the fact that its
9faa82d8 1122 address was taken. */
a25d4ba2
RK
1123
1124void
1125mark_temp_addr_taken (x)
1126 rtx x;
1127{
1128 struct temp_slot *p;
1129
1130 if (x == 0)
1131 return;
1132
1133 /* If X is not in memory or is at a constant address, it cannot be in
1134 a temporary slot. */
1135 if (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1136 return;
1137
1138 p = find_temp_slot_from_address (XEXP (x, 0));
1139 if (p != 0)
1140 p->addr_taken = 1;
1141}
1142
9cca6a99
MS
1143/* If X could be a reference to a temporary slot, mark that slot as
1144 belonging to the to one level higher than the current level. If X
1145 matched one of our slots, just mark that one. Otherwise, we can't
1146 easily predict which it is, so upgrade all of them. Kept slots
1147 need not be touched.
6f086dfc
RS
1148
1149 This is called when an ({...}) construct occurs and a statement
1150 returns a value in memory. */
1151
1152void
1153preserve_temp_slots (x)
1154 rtx x;
1155{
a25d4ba2 1156 struct temp_slot *p = 0;
6f086dfc 1157
73620b82
RK
1158 /* If there is no result, we still might have some objects whose address
1159 were taken, so we need to make sure they stay around. */
e3a77161 1160 if (x == 0)
73620b82
RK
1161 {
1162 for (p = temp_slots; p; p = p->next)
1163 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1164 p->level--;
1165
1166 return;
1167 }
e3a77161
RK
1168
1169 /* If X is a register that is being used as a pointer, see if we have
1170 a temporary slot we know it points to. To be consistent with
1171 the code below, we really should preserve all non-kept slots
1172 if we can't find a match, but that seems to be much too costly. */
a25d4ba2
RK
1173 if (GET_CODE (x) == REG && REGNO_POINTER_FLAG (REGNO (x)))
1174 p = find_temp_slot_from_address (x);
1175
6f086dfc 1176 /* If X is not in memory or is at a constant address, it cannot be in
e19571db
RK
1177 a temporary slot, but it can contain something whose address was
1178 taken. */
a25d4ba2 1179 if (p == 0 && (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))))
e19571db
RK
1180 {
1181 for (p = temp_slots; p; p = p->next)
1182 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1183 p->level--;
1184
1185 return;
1186 }
6f086dfc
RS
1187
1188 /* First see if we can find a match. */
73620b82 1189 if (p == 0)
a25d4ba2
RK
1190 p = find_temp_slot_from_address (XEXP (x, 0));
1191
e5e76139
RK
1192 if (p != 0)
1193 {
a25d4ba2
RK
1194 /* Move everything at our level whose address was taken to our new
1195 level in case we used its address. */
1196 struct temp_slot *q;
1197
9cca6a99
MS
1198 if (p->level == temp_slot_level)
1199 {
1200 for (q = temp_slots; q; q = q->next)
1201 if (q != p && q->addr_taken && q->level == p->level)
1202 q->level--;
a25d4ba2 1203
9cca6a99
MS
1204 p->level--;
1205 p->addr_taken = 0;
1206 }
e5e76139
RK
1207 return;
1208 }
6f086dfc
RS
1209
1210 /* Otherwise, preserve all non-kept slots at this level. */
1211 for (p = temp_slots; p; p = p->next)
1212 if (p->in_use && p->level == temp_slot_level && ! p->keep)
1213 p->level--;
1214}
1215
422c8f63
RK
1216/* X is the result of an RTL_EXPR. If it is a temporary slot associated
1217 with that RTL_EXPR, promote it into a temporary slot at the present
1218 level so it will not be freed when we free slots made in the
1219 RTL_EXPR. */
1220
1221void
1222preserve_rtl_expr_result (x)
1223 rtx x;
1224{
1225 struct temp_slot *p;
1226
1227 /* If X is not in memory or is at a constant address, it cannot be in
1228 a temporary slot. */
1229 if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1230 return;
1231
199b61d8
RK
1232 /* If we can find a match, move it to our level unless it is already at
1233 an upper level. */
1234 p = find_temp_slot_from_address (XEXP (x, 0));
1235 if (p != 0)
1236 {
1237 p->level = MIN (p->level, temp_slot_level);
1238 p->rtl_expr = 0;
1239 }
422c8f63
RK
1240
1241 return;
1242}
1243
6f086dfc 1244/* Free all temporaries used so far. This is normally called at the end
e7a84011
RK
1245 of generating code for a statement. Don't free any temporaries
1246 currently in use for an RTL_EXPR that hasn't yet been emitted.
1247 We could eventually do better than this since it can be reused while
1248 generating the same RTL_EXPR, but this is complex and probably not
1249 worthwhile. */
6f086dfc
RS
1250
1251void
1252free_temp_slots ()
1253{
1254 struct temp_slot *p;
1255
1256 for (p = temp_slots; p; p = p->next)
e7a84011
RK
1257 if (p->in_use && p->level == temp_slot_level && ! p->keep
1258 && p->rtl_expr == 0)
1259 p->in_use = 0;
1260
1261 combine_temp_slots ();
1262}
1263
1264/* Free all temporary slots used in T, an RTL_EXPR node. */
1265
1266void
1267free_temps_for_rtl_expr (t)
1268 tree t;
1269{
1270 struct temp_slot *p;
1271
1272 for (p = temp_slots; p; p = p->next)
1273 if (p->rtl_expr == t)
6f086dfc 1274 p->in_use = 0;
a45035b6
JW
1275
1276 combine_temp_slots ();
6f086dfc
RS
1277}
1278
956d6950 1279/* Mark all temporaries ever allocated in this function as not suitable
a94e4054
RK
1280 for reuse until the current level is exited. */
1281
1282void
1283mark_all_temps_used ()
1284{
1285 struct temp_slot *p;
1286
1287 for (p = temp_slots; p; p = p->next)
1288 {
85b119d1 1289 p->in_use = p->keep = 1;
27ce006b 1290 p->level = MIN (p->level, temp_slot_level);
a94e4054
RK
1291 }
1292}
1293
6f086dfc
RS
1294/* Push deeper into the nesting level for stack temporaries. */
1295
1296void
1297push_temp_slots ()
1298{
6f086dfc
RS
1299 temp_slot_level++;
1300}
1301
e5e809f4
JL
1302/* Likewise, but save the new level as the place to allocate variables
1303 for blocks. */
1304
1305void
1306push_temp_slots_for_block ()
1307{
1308 push_temp_slots ();
1309
1310 var_temp_slot_level = temp_slot_level;
1311}
1312
f5963e61
JL
1313/* Likewise, but save the new level as the place to allocate temporaries
1314 for TARGET_EXPRs. */
1315
1316void
1317push_temp_slots_for_target ()
1318{
1319 push_temp_slots ();
1320
1321 target_temp_slot_level = temp_slot_level;
1322}
1323
1324/* Set and get the value of target_temp_slot_level. The only
1325 permitted use of these functions is to save and restore this value. */
1326
1327int
1328get_target_temp_slot_level ()
1329{
1330 return target_temp_slot_level;
1331}
1332
1333void
1334set_target_temp_slot_level (level)
1335 int level;
1336{
1337 target_temp_slot_level = level;
1338}
1339
6f086dfc
RS
1340/* Pop a temporary nesting level. All slots in use in the current level
1341 are freed. */
1342
1343void
1344pop_temp_slots ()
1345{
1346 struct temp_slot *p;
1347
6f086dfc 1348 for (p = temp_slots; p; p = p->next)
e7a84011 1349 if (p->in_use && p->level == temp_slot_level && p->rtl_expr == 0)
6f086dfc
RS
1350 p->in_use = 0;
1351
a45035b6
JW
1352 combine_temp_slots ();
1353
6f086dfc
RS
1354 temp_slot_level--;
1355}
bc0ebdf9
RK
1356
1357/* Initialize temporary slots. */
1358
1359void
1360init_temp_slots ()
1361{
1362 /* We have not allocated any temporaries yet. */
1363 temp_slots = 0;
1364 temp_slot_level = 0;
e5e809f4 1365 var_temp_slot_level = 0;
bc0ebdf9
RK
1366 target_temp_slot_level = 0;
1367}
6f086dfc
RS
1368\f
1369/* Retroactively move an auto variable from a register to a stack slot.
1370 This is done when an address-reference to the variable is seen. */
1371
1372void
1373put_var_into_stack (decl)
1374 tree decl;
1375{
1376 register rtx reg;
00d8a4c1 1377 enum machine_mode promoted_mode, decl_mode;
6f086dfc 1378 struct function *function = 0;
c20bf1f3 1379 tree context;
e9a25f70 1380 int can_use_addressof;
c20bf1f3 1381
c20bf1f3 1382 context = decl_function_context (decl);
6f086dfc 1383
9ec36da5 1384 /* Get the current rtl used for this object and its original mode. */
6f086dfc 1385 reg = TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl) : DECL_RTL (decl);
2baccce2
RS
1386
1387 /* No need to do anything if decl has no rtx yet
1388 since in that case caller is setting TREE_ADDRESSABLE
1389 and a stack slot will be assigned when the rtl is made. */
1390 if (reg == 0)
1391 return;
00d8a4c1
RK
1392
1393 /* Get the declared mode for this object. */
1394 decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl))
1395 : DECL_MODE (decl));
2baccce2
RS
1396 /* Get the mode it's actually stored in. */
1397 promoted_mode = GET_MODE (reg);
6f086dfc
RS
1398
1399 /* If this variable comes from an outer function,
1400 find that function's saved context. */
4ac74fb8 1401 if (context != current_function_decl && context != inline_function_decl)
6f086dfc
RS
1402 for (function = outer_function_chain; function; function = function->next)
1403 if (function->decl == context)
1404 break;
1405
6f086dfc
RS
1406 /* If this is a variable-size object with a pseudo to address it,
1407 put that pseudo into the stack, if the var is nonlocal. */
a82ad570 1408 if (DECL_NONLOCAL (decl)
6f086dfc
RS
1409 && GET_CODE (reg) == MEM
1410 && GET_CODE (XEXP (reg, 0)) == REG
1411 && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER)
4cdb3e78
RS
1412 {
1413 reg = XEXP (reg, 0);
1414 decl_mode = promoted_mode = GET_MODE (reg);
1415 }
e15762df 1416
e9a25f70
JL
1417 can_use_addressof
1418 = (function == 0
e5e809f4 1419 && optimize > 0
e9a25f70
JL
1420 /* FIXME make it work for promoted modes too */
1421 && decl_mode == promoted_mode
1422#ifdef NON_SAVING_SETJMP
1423 && ! (NON_SAVING_SETJMP && current_function_calls_setjmp)
1424#endif
1425 );
1426
1427 /* If we can't use ADDRESSOF, make sure we see through one we already
1428 generated. */
1429 if (! can_use_addressof && GET_CODE (reg) == MEM
1430 && GET_CODE (XEXP (reg, 0)) == ADDRESSOF)
1431 reg = XEXP (XEXP (reg, 0), 0);
1432
293e3de4
RS
1433 /* Now we should have a value that resides in one or more pseudo regs. */
1434
1435 if (GET_CODE (reg) == REG)
e9a25f70
JL
1436 {
1437 /* If this variable lives in the current function and we don't need
1438 to put things in the stack for the sake of setjmp, try to keep it
1439 in a register until we know we actually need the address. */
1440 if (can_use_addressof)
1441 gen_mem_addressof (reg, decl);
1442 else
1443 put_reg_into_stack (function, reg, TREE_TYPE (decl),
1444 promoted_mode, decl_mode,
e5e809f4
JL
1445 TREE_SIDE_EFFECTS (decl), 0,
1446 TREE_USED (decl)
1447 || DECL_INITIAL (decl) != 0);
e9a25f70 1448 }
293e3de4
RS
1449 else if (GET_CODE (reg) == CONCAT)
1450 {
1451 /* A CONCAT contains two pseudos; put them both in the stack.
1452 We do it so they end up consecutive. */
1453 enum machine_mode part_mode = GET_MODE (XEXP (reg, 0));
1454 tree part_type = TREE_TYPE (TREE_TYPE (decl));
4738c10d 1455#ifdef FRAME_GROWS_DOWNWARD
293e3de4 1456 /* Since part 0 should have a lower address, do it second. */
0006e95b 1457 put_reg_into_stack (function, XEXP (reg, 1), part_type, part_mode,
e5e809f4
JL
1458 part_mode, TREE_SIDE_EFFECTS (decl), 0,
1459 TREE_USED (decl) || DECL_INITIAL (decl) != 0);
0006e95b 1460 put_reg_into_stack (function, XEXP (reg, 0), part_type, part_mode,
e5e809f4
JL
1461 part_mode, TREE_SIDE_EFFECTS (decl), 0,
1462 TREE_USED (decl) || DECL_INITIAL (decl) != 0);
293e3de4 1463#else
0006e95b 1464 put_reg_into_stack (function, XEXP (reg, 0), part_type, part_mode,
e5e809f4
JL
1465 part_mode, TREE_SIDE_EFFECTS (decl), 0,
1466 TREE_USED (decl) || DECL_INITIAL (decl) != 0);
0006e95b 1467 put_reg_into_stack (function, XEXP (reg, 1), part_type, part_mode,
e5e809f4
JL
1468 part_mode, TREE_SIDE_EFFECTS (decl), 0,
1469 TREE_USED (decl) || DECL_INITIAL (decl) != 0);
293e3de4
RS
1470#endif
1471
1472 /* Change the CONCAT into a combined MEM for both parts. */
1473 PUT_CODE (reg, MEM);
0006e95b 1474 MEM_VOLATILE_P (reg) = MEM_VOLATILE_P (XEXP (reg, 0));
41472af8 1475 MEM_ALIAS_SET (reg) = get_alias_set (decl);
0006e95b 1476
293e3de4
RS
1477 /* The two parts are in memory order already.
1478 Use the lower parts address as ours. */
1479 XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0);
1480 /* Prevent sharing of rtl that might lose. */
1481 if (GET_CODE (XEXP (reg, 0)) == PLUS)
1482 XEXP (reg, 0) = copy_rtx (XEXP (reg, 0));
1483 }
86fa911a
RK
1484 else
1485 return;
1486
1487 if (flag_check_memory_usage)
1488 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
1489 XEXP (reg, 0), ptr_mode,
1490 GEN_INT (GET_MODE_SIZE (GET_MODE (reg))),
1491 TYPE_MODE (sizetype),
956d6950
JL
1492 GEN_INT (MEMORY_USE_RW),
1493 TYPE_MODE (integer_type_node));
293e3de4
RS
1494}
1495
1496/* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1497 into the stack frame of FUNCTION (0 means the current function).
1498 DECL_MODE is the machine mode of the user-level data type.
0006e95b 1499 PROMOTED_MODE is the machine mode of the register.
e5e809f4
JL
1500 VOLATILE_P is nonzero if this is for a "volatile" decl.
1501 USED_P is nonzero if this reg might have already been used in an insn. */
293e3de4
RS
1502
1503static void
e9a25f70 1504put_reg_into_stack (function, reg, type, promoted_mode, decl_mode, volatile_p,
e5e809f4 1505 original_regno, used_p)
293e3de4
RS
1506 struct function *function;
1507 rtx reg;
1508 tree type;
1509 enum machine_mode promoted_mode, decl_mode;
0006e95b 1510 int volatile_p;
e9a25f70 1511 int original_regno;
e5e809f4 1512 int used_p;
293e3de4
RS
1513{
1514 rtx new = 0;
e9a25f70
JL
1515 int regno = original_regno;
1516
1517 if (regno == 0)
1518 regno = REGNO (reg);
6f086dfc
RS
1519
1520 if (function)
1521 {
e9a25f70
JL
1522 if (regno < function->max_parm_reg)
1523 new = function->parm_reg_stack_loc[regno];
6f086dfc 1524 if (new == 0)
e15762df 1525 new = assign_outer_stack_local (decl_mode, GET_MODE_SIZE (decl_mode),
6f086dfc
RS
1526 0, function);
1527 }
1528 else
1529 {
e9a25f70
JL
1530 if (regno < max_parm_reg)
1531 new = parm_reg_stack_loc[regno];
6f086dfc 1532 if (new == 0)
e15762df 1533 new = assign_stack_local (decl_mode, GET_MODE_SIZE (decl_mode), 0);
6f086dfc
RS
1534 }
1535
0006e95b 1536 PUT_MODE (reg, decl_mode);
6f086dfc
RS
1537 XEXP (reg, 0) = XEXP (new, 0);
1538 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
0006e95b 1539 MEM_VOLATILE_P (reg) = volatile_p;
6f086dfc
RS
1540 PUT_CODE (reg, MEM);
1541
1542 /* If this is a memory ref that contains aggregate components,
bdd3e6ab
JW
1543 mark it as such for cse and loop optimize. If we are reusing a
1544 previously generated stack slot, then we need to copy the bit in
1545 case it was set for other reasons. For instance, it is set for
1546 __builtin_va_alist. */
1547 MEM_IN_STRUCT_P (reg) = AGGREGATE_TYPE_P (type) | MEM_IN_STRUCT_P (new);
41472af8 1548 MEM_ALIAS_SET (reg) = get_alias_set (type);
6f086dfc
RS
1549
1550 /* Now make sure that all refs to the variable, previously made
1551 when it was a register, are fixed up to be valid again. */
e5e809f4
JL
1552
1553 if (used_p && function != 0)
6f086dfc
RS
1554 {
1555 struct var_refs_queue *temp;
1556
1557 /* Variable is inherited; fix it up when we get back to its function. */
1558 push_obstacks (function->function_obstack,
1559 function->function_maybepermanent_obstack);
4da73fa0
RK
1560
1561 /* See comment in restore_tree_status in tree.c for why this needs to be
1562 on saveable obstack. */
6f086dfc 1563 temp
4da73fa0 1564 = (struct var_refs_queue *) savealloc (sizeof (struct var_refs_queue));
6f086dfc 1565 temp->modified = reg;
00d8a4c1 1566 temp->promoted_mode = promoted_mode;
293e3de4 1567 temp->unsignedp = TREE_UNSIGNED (type);
6f086dfc
RS
1568 temp->next = function->fixup_var_refs_queue;
1569 function->fixup_var_refs_queue = temp;
1570 pop_obstacks ();
1571 }
e5e809f4 1572 else if (used_p)
6f086dfc 1573 /* Variable is local; fix it up now. */
293e3de4 1574 fixup_var_refs (reg, promoted_mode, TREE_UNSIGNED (type));
6f086dfc
RS
1575}
1576\f
1577static void
00d8a4c1 1578fixup_var_refs (var, promoted_mode, unsignedp)
6f086dfc 1579 rtx var;
00d8a4c1
RK
1580 enum machine_mode promoted_mode;
1581 int unsignedp;
6f086dfc
RS
1582{
1583 tree pending;
1584 rtx first_insn = get_insns ();
1585 struct sequence_stack *stack = sequence_stack;
1586 tree rtl_exps = rtl_expr_chain;
1587
1588 /* Must scan all insns for stack-refs that exceed the limit. */
00d8a4c1 1589 fixup_var_refs_insns (var, promoted_mode, unsignedp, first_insn, stack == 0);
6f086dfc
RS
1590
1591 /* Scan all pending sequences too. */
1592 for (; stack; stack = stack->next)
1593 {
1594 push_to_sequence (stack->first);
00d8a4c1
RK
1595 fixup_var_refs_insns (var, promoted_mode, unsignedp,
1596 stack->first, stack->next != 0);
6f086dfc
RS
1597 /* Update remembered end of sequence
1598 in case we added an insn at the end. */
1599 stack->last = get_last_insn ();
1600 end_sequence ();
1601 }
1602
1603 /* Scan all waiting RTL_EXPRs too. */
1604 for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending))
1605 {
1606 rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
1607 if (seq != const0_rtx && seq != 0)
1608 {
1609 push_to_sequence (seq);
00d8a4c1 1610 fixup_var_refs_insns (var, promoted_mode, unsignedp, seq, 0);
6f086dfc
RS
1611 end_sequence ();
1612 }
1613 }
1614}
1615\f
e15679f8 1616/* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
6f086dfc 1617 some part of an insn. Return a struct fixup_replacement whose OLD
0f41302f 1618 value is equal to X. Allocate a new structure if no such entry exists. */
6f086dfc
RS
1619
1620static struct fixup_replacement *
2740a678 1621find_fixup_replacement (replacements, x)
6f086dfc
RS
1622 struct fixup_replacement **replacements;
1623 rtx x;
1624{
1625 struct fixup_replacement *p;
1626
1627 /* See if we have already replaced this. */
1628 for (p = *replacements; p && p->old != x; p = p->next)
1629 ;
1630
1631 if (p == 0)
1632 {
1633 p = (struct fixup_replacement *) oballoc (sizeof (struct fixup_replacement));
1634 p->old = x;
1635 p->new = 0;
1636 p->next = *replacements;
1637 *replacements = p;
1638 }
1639
1640 return p;
1641}
1642
1643/* Scan the insn-chain starting with INSN for refs to VAR
1644 and fix them up. TOPLEVEL is nonzero if this chain is the
1645 main chain of insns for the current function. */
1646
1647static void
00d8a4c1 1648fixup_var_refs_insns (var, promoted_mode, unsignedp, insn, toplevel)
6f086dfc 1649 rtx var;
00d8a4c1
RK
1650 enum machine_mode promoted_mode;
1651 int unsignedp;
6f086dfc
RS
1652 rtx insn;
1653 int toplevel;
1654{
02a10449
RK
1655 rtx call_dest = 0;
1656
6f086dfc
RS
1657 while (insn)
1658 {
1659 rtx next = NEXT_INSN (insn);
e5e809f4 1660 rtx set, prev, prev_set;
6f086dfc 1661 rtx note;
e5e809f4 1662
e15762df 1663 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
6f086dfc 1664 {
63770d6a
RK
1665 /* If this is a CLOBBER of VAR, delete it.
1666
1667 If it has a REG_LIBCALL note, delete the REG_LIBCALL
1668 and REG_RETVAL notes too. */
926d1ca5 1669 if (GET_CODE (PATTERN (insn)) == CLOBBER
07362cb3
JW
1670 && (XEXP (PATTERN (insn), 0) == var
1671 || (GET_CODE (XEXP (PATTERN (insn), 0)) == CONCAT
1672 && (XEXP (XEXP (PATTERN (insn), 0), 0) == var
1673 || XEXP (XEXP (PATTERN (insn), 0), 1) == var))))
63770d6a
RK
1674 {
1675 if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX)) != 0)
1676 /* The REG_LIBCALL note will go away since we are going to
1677 turn INSN into a NOTE, so just delete the
1678 corresponding REG_RETVAL note. */
1679 remove_note (XEXP (note, 0),
1680 find_reg_note (XEXP (note, 0), REG_RETVAL,
1681 NULL_RTX));
1682
1683 /* In unoptimized compilation, we shouldn't call delete_insn
1684 except in jump.c doing warnings. */
1685 PUT_CODE (insn, NOTE);
1686 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1687 NOTE_SOURCE_FILE (insn) = 0;
1688 }
1689
6f086dfc 1690 /* The insn to load VAR from a home in the arglist
e5e809f4
JL
1691 is now a no-op. When we see it, just delete it.
1692 Similarly if this is storing VAR from a register from which
1693 it was loaded in the previous insn. This will occur
1694 when an ADDRESSOF was made for an arglist slot. */
63770d6a 1695 else if (toplevel
e5e809f4
JL
1696 && (set = single_set (insn)) != 0
1697 && SET_DEST (set) == var
63770d6a
RK
1698 /* If this represents the result of an insn group,
1699 don't delete the insn. */
1700 && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0
e5e809f4
JL
1701 && (rtx_equal_p (SET_SRC (set), var)
1702 || (GET_CODE (SET_SRC (set)) == REG
1703 && (prev = prev_nonnote_insn (insn)) != 0
1704 && (prev_set = single_set (prev)) != 0
1705 && SET_DEST (prev_set) == SET_SRC (set)
1706 && rtx_equal_p (SET_SRC (prev_set), var))))
6f086dfc 1707 {
b4ff474c
RS
1708 /* In unoptimized compilation, we shouldn't call delete_insn
1709 except in jump.c doing warnings. */
1710 PUT_CODE (insn, NOTE);
1711 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1712 NOTE_SOURCE_FILE (insn) = 0;
6f086dfc
RS
1713 if (insn == last_parm_insn)
1714 last_parm_insn = PREV_INSN (next);
1715 }
1716 else
1717 {
02a10449
RK
1718 struct fixup_replacement *replacements = 0;
1719 rtx next_insn = NEXT_INSN (insn);
1720
e9a25f70
JL
1721 if (SMALL_REGISTER_CLASSES)
1722 {
1723 /* If the insn that copies the results of a CALL_INSN
1724 into a pseudo now references VAR, we have to use an
1725 intermediate pseudo since we want the life of the
1726 return value register to be only a single insn.
02a10449 1727
e9a25f70
JL
1728 If we don't use an intermediate pseudo, such things as
1729 address computations to make the address of VAR valid
1730 if it is not can be placed between the CALL_INSN and INSN.
02a10449 1731
e9a25f70
JL
1732 To make sure this doesn't happen, we record the destination
1733 of the CALL_INSN and see if the next insn uses both that
1734 and VAR. */
02a10449 1735
f95182a4
ILT
1736 if (call_dest != 0 && GET_CODE (insn) == INSN
1737 && reg_mentioned_p (var, PATTERN (insn))
1738 && reg_mentioned_p (call_dest, PATTERN (insn)))
1739 {
1740 rtx temp = gen_reg_rtx (GET_MODE (call_dest));
02a10449 1741
f95182a4 1742 emit_insn_before (gen_move_insn (temp, call_dest), insn);
02a10449 1743
f95182a4
ILT
1744 PATTERN (insn) = replace_rtx (PATTERN (insn),
1745 call_dest, temp);
1746 }
02a10449 1747
f95182a4
ILT
1748 if (GET_CODE (insn) == CALL_INSN
1749 && GET_CODE (PATTERN (insn)) == SET)
1750 call_dest = SET_DEST (PATTERN (insn));
1751 else if (GET_CODE (insn) == CALL_INSN
1752 && GET_CODE (PATTERN (insn)) == PARALLEL
1753 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
1754 call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
1755 else
1756 call_dest = 0;
1757 }
02a10449 1758
6f086dfc
RS
1759 /* See if we have to do anything to INSN now that VAR is in
1760 memory. If it needs to be loaded into a pseudo, use a single
1761 pseudo for the entire insn in case there is a MATCH_DUP
1762 between two operands. We pass a pointer to the head of
1763 a list of struct fixup_replacements. If fixup_var_refs_1
1764 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1765 it will record them in this list.
1766
1767 If it allocated a pseudo for any replacement, we copy into
1768 it here. */
1769
00d8a4c1
RK
1770 fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn,
1771 &replacements);
6f086dfc 1772
77121fee
JW
1773 /* If this is last_parm_insn, and any instructions were output
1774 after it to fix it up, then we must set last_parm_insn to
1775 the last such instruction emitted. */
1776 if (insn == last_parm_insn)
1777 last_parm_insn = PREV_INSN (next_insn);
1778
6f086dfc
RS
1779 while (replacements)
1780 {
1781 if (GET_CODE (replacements->new) == REG)
1782 {
1783 rtx insert_before;
00d8a4c1 1784 rtx seq;
6f086dfc
RS
1785
1786 /* OLD might be a (subreg (mem)). */
1787 if (GET_CODE (replacements->old) == SUBREG)
1788 replacements->old
1789 = fixup_memory_subreg (replacements->old, insn, 0);
1790 else
1791 replacements->old
1792 = fixup_stack_1 (replacements->old, insn);
1793
5fa7422b 1794 insert_before = insn;
6f086dfc 1795
00d8a4c1
RK
1796 /* If we are changing the mode, do a conversion.
1797 This might be wasteful, but combine.c will
1798 eliminate much of the waste. */
1799
1800 if (GET_MODE (replacements->new)
1801 != GET_MODE (replacements->old))
1802 {
1803 start_sequence ();
1804 convert_move (replacements->new,
1805 replacements->old, unsignedp);
1806 seq = gen_sequence ();
1807 end_sequence ();
1808 }
1809 else
1810 seq = gen_move_insn (replacements->new,
1811 replacements->old);
1812
1813 emit_insn_before (seq, insert_before);
6f086dfc
RS
1814 }
1815
1816 replacements = replacements->next;
1817 }
1818 }
1819
1820 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
1821 But don't touch other insns referred to by reg-notes;
1822 we will get them elsewhere. */
1823 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
1824 if (GET_CODE (note) != INSN_LIST)
ab6155b7
RK
1825 XEXP (note, 0)
1826 = walk_fixup_memory_subreg (XEXP (note, 0), insn, 1);
6f086dfc
RS
1827 }
1828 insn = next;
1829 }
1830}
1831\f
00d8a4c1
RK
1832/* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
1833 See if the rtx expression at *LOC in INSN needs to be changed.
6f086dfc
RS
1834
1835 REPLACEMENTS is a pointer to a list head that starts out zero, but may
1836 contain a list of original rtx's and replacements. If we find that we need
1837 to modify this insn by replacing a memory reference with a pseudo or by
1838 making a new MEM to implement a SUBREG, we consult that list to see if
1839 we have already chosen a replacement. If none has already been allocated,
1840 we allocate it and update the list. fixup_var_refs_insns will copy VAR
1841 or the SUBREG, as appropriate, to the pseudo. */
1842
1843static void
00d8a4c1 1844fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements)
6f086dfc 1845 register rtx var;
00d8a4c1 1846 enum machine_mode promoted_mode;
6f086dfc
RS
1847 register rtx *loc;
1848 rtx insn;
1849 struct fixup_replacement **replacements;
1850{
1851 register int i;
1852 register rtx x = *loc;
1853 RTX_CODE code = GET_CODE (x);
1854 register char *fmt;
1855 register rtx tem, tem1;
1856 struct fixup_replacement *replacement;
1857
1858 switch (code)
1859 {
e9a25f70
JL
1860 case ADDRESSOF:
1861 if (XEXP (x, 0) == var)
1862 {
956d6950
JL
1863 /* Prevent sharing of rtl that might lose. */
1864 rtx sub = copy_rtx (XEXP (var, 0));
1865
e9a25f70 1866 start_sequence ();
956d6950
JL
1867
1868 if (! validate_change (insn, loc, sub, 0))
1869 {
1870 rtx y = force_operand (sub, NULL_RTX);
1871
1872 if (! validate_change (insn, loc, y, 0))
1873 *loc = copy_to_reg (y);
1874 }
1875
e9a25f70
JL
1876 emit_insn_before (gen_sequence (), insn);
1877 end_sequence ();
1878 }
1879 return;
1880
6f086dfc
RS
1881 case MEM:
1882 if (var == x)
1883 {
1884 /* If we already have a replacement, use it. Otherwise,
1885 try to fix up this address in case it is invalid. */
1886
2740a678 1887 replacement = find_fixup_replacement (replacements, var);
6f086dfc
RS
1888 if (replacement->new)
1889 {
1890 *loc = replacement->new;
1891 return;
1892 }
1893
1894 *loc = replacement->new = x = fixup_stack_1 (x, insn);
1895
00d8a4c1
RK
1896 /* Unless we are forcing memory to register or we changed the mode,
1897 we can leave things the way they are if the insn is valid. */
6f086dfc
RS
1898
1899 INSN_CODE (insn) = -1;
00d8a4c1
RK
1900 if (! flag_force_mem && GET_MODE (x) == promoted_mode
1901 && recog_memoized (insn) >= 0)
6f086dfc
RS
1902 return;
1903
00d8a4c1 1904 *loc = replacement->new = gen_reg_rtx (promoted_mode);
6f086dfc
RS
1905 return;
1906 }
1907
1908 /* If X contains VAR, we need to unshare it here so that we update
1909 each occurrence separately. But all identical MEMs in one insn
1910 must be replaced with the same rtx because of the possibility of
1911 MATCH_DUPs. */
1912
1913 if (reg_mentioned_p (var, x))
1914 {
2740a678 1915 replacement = find_fixup_replacement (replacements, x);
6f086dfc
RS
1916 if (replacement->new == 0)
1917 replacement->new = copy_most_rtx (x, var);
1918
1919 *loc = x = replacement->new;
1920 }
1921 break;
1922
1923 case REG:
1924 case CC0:
1925 case PC:
1926 case CONST_INT:
1927 case CONST:
1928 case SYMBOL_REF:
1929 case LABEL_REF:
1930 case CONST_DOUBLE:
1931 return;
1932
1933 case SIGN_EXTRACT:
1934 case ZERO_EXTRACT:
1935 /* Note that in some cases those types of expressions are altered
1936 by optimize_bit_field, and do not survive to get here. */
1937 if (XEXP (x, 0) == var
1938 || (GET_CODE (XEXP (x, 0)) == SUBREG
1939 && SUBREG_REG (XEXP (x, 0)) == var))
1940 {
1941 /* Get TEM as a valid MEM in the mode presently in the insn.
1942
1943 We don't worry about the possibility of MATCH_DUP here; it
1944 is highly unlikely and would be tricky to handle. */
1945
1946 tem = XEXP (x, 0);
1947 if (GET_CODE (tem) == SUBREG)
0e09cc26
RK
1948 {
1949 if (GET_MODE_BITSIZE (GET_MODE (tem))
1950 > GET_MODE_BITSIZE (GET_MODE (var)))
1951 {
1952 replacement = find_fixup_replacement (replacements, var);
1953 if (replacement->new == 0)
1954 replacement->new = gen_reg_rtx (GET_MODE (var));
1955 SUBREG_REG (tem) = replacement->new;
1956 }
ef933d26
RK
1957 else
1958 tem = fixup_memory_subreg (tem, insn, 0);
0e09cc26
RK
1959 }
1960 else
1961 tem = fixup_stack_1 (tem, insn);
6f086dfc
RS
1962
1963 /* Unless we want to load from memory, get TEM into the proper mode
1964 for an extract from memory. This can only be done if the
1965 extract is at a constant position and length. */
1966
1967 if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT
1968 && GET_CODE (XEXP (x, 2)) == CONST_INT
1969 && ! mode_dependent_address_p (XEXP (tem, 0))
1970 && ! MEM_VOLATILE_P (tem))
1971 {
1972 enum machine_mode wanted_mode = VOIDmode;
1973 enum machine_mode is_mode = GET_MODE (tem);
e5e809f4 1974 HOST_WIDE_INT pos = INTVAL (XEXP (x, 2));
6f086dfc
RS
1975
1976#ifdef HAVE_extzv
1977 if (GET_CODE (x) == ZERO_EXTRACT)
0d8e55d8
JL
1978 {
1979 wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1];
1980 if (wanted_mode == VOIDmode)
1981 wanted_mode = word_mode;
1982 }
6f086dfc
RS
1983#endif
1984#ifdef HAVE_extv
1985 if (GET_CODE (x) == SIGN_EXTRACT)
0d8e55d8
JL
1986 {
1987 wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1];
1988 if (wanted_mode == VOIDmode)
1989 wanted_mode = word_mode;
1990 }
6f086dfc 1991#endif
6dc42e49 1992 /* If we have a narrower mode, we can do something. */
6f086dfc
RS
1993 if (wanted_mode != VOIDmode
1994 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
1995 {
e5e809f4 1996 HOST_WIDE_INT offset = pos / BITS_PER_UNIT;
6f086dfc
RS
1997 rtx old_pos = XEXP (x, 2);
1998 rtx newmem;
1999
2000 /* If the bytes and bits are counted differently, we
2001 must adjust the offset. */
f76b9db2
ILT
2002 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
2003 offset = (GET_MODE_SIZE (is_mode)
2004 - GET_MODE_SIZE (wanted_mode) - offset);
6f086dfc
RS
2005
2006 pos %= GET_MODE_BITSIZE (wanted_mode);
2007
38a448ca
RH
2008 newmem = gen_rtx_MEM (wanted_mode,
2009 plus_constant (XEXP (tem, 0), offset));
6f086dfc
RS
2010 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
2011 MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
2012 MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
2013
2014 /* Make the change and see if the insn remains valid. */
2015 INSN_CODE (insn) = -1;
2016 XEXP (x, 0) = newmem;
5f4f0e22 2017 XEXP (x, 2) = GEN_INT (pos);
6f086dfc
RS
2018
2019 if (recog_memoized (insn) >= 0)
2020 return;
2021
2022 /* Otherwise, restore old position. XEXP (x, 0) will be
2023 restored later. */
2024 XEXP (x, 2) = old_pos;
2025 }
2026 }
2027
2028 /* If we get here, the bitfield extract insn can't accept a memory
2029 reference. Copy the input into a register. */
2030
2031 tem1 = gen_reg_rtx (GET_MODE (tem));
2032 emit_insn_before (gen_move_insn (tem1, tem), insn);
2033 XEXP (x, 0) = tem1;
2034 return;
2035 }
2036 break;
2037
2038 case SUBREG:
2039 if (SUBREG_REG (x) == var)
2040 {
00d8a4c1
RK
2041 /* If this is a special SUBREG made because VAR was promoted
2042 from a wider mode, replace it with VAR and call ourself
2043 recursively, this time saying that the object previously
2044 had its current mode (by virtue of the SUBREG). */
2045
2046 if (SUBREG_PROMOTED_VAR_P (x))
2047 {
2048 *loc = var;
2049 fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements);
2050 return;
2051 }
2052
6f086dfc
RS
2053 /* If this SUBREG makes VAR wider, it has become a paradoxical
2054 SUBREG with VAR in memory, but these aren't allowed at this
2055 stage of the compilation. So load VAR into a pseudo and take
2056 a SUBREG of that pseudo. */
2057 if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var)))
2058 {
2740a678 2059 replacement = find_fixup_replacement (replacements, var);
6f086dfc
RS
2060 if (replacement->new == 0)
2061 replacement->new = gen_reg_rtx (GET_MODE (var));
2062 SUBREG_REG (x) = replacement->new;
2063 return;
2064 }
2065
2066 /* See if we have already found a replacement for this SUBREG.
2067 If so, use it. Otherwise, make a MEM and see if the insn
2068 is recognized. If not, or if we should force MEM into a register,
2069 make a pseudo for this SUBREG. */
2740a678 2070 replacement = find_fixup_replacement (replacements, x);
6f086dfc
RS
2071 if (replacement->new)
2072 {
2073 *loc = replacement->new;
2074 return;
2075 }
2076
2077 replacement->new = *loc = fixup_memory_subreg (x, insn, 0);
2078
f898f031 2079 INSN_CODE (insn) = -1;
6f086dfc
RS
2080 if (! flag_force_mem && recog_memoized (insn) >= 0)
2081 return;
2082
2083 *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
2084 return;
2085 }
2086 break;
2087
2088 case SET:
2089 /* First do special simplification of bit-field references. */
2090 if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
2091 || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
2092 optimize_bit_field (x, insn, 0);
2093 if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
2094 || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
5f4f0e22 2095 optimize_bit_field (x, insn, NULL_PTR);
6f086dfc 2096
0e09cc26
RK
2097 /* For a paradoxical SUBREG inside a ZERO_EXTRACT, load the object
2098 into a register and then store it back out. */
2099 if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT
2100 && GET_CODE (XEXP (SET_DEST (x), 0)) == SUBREG
2101 && SUBREG_REG (XEXP (SET_DEST (x), 0)) == var
2102 && (GET_MODE_SIZE (GET_MODE (XEXP (SET_DEST (x), 0)))
2103 > GET_MODE_SIZE (GET_MODE (var))))
2104 {
2105 replacement = find_fixup_replacement (replacements, var);
2106 if (replacement->new == 0)
2107 replacement->new = gen_reg_rtx (GET_MODE (var));
2108
2109 SUBREG_REG (XEXP (SET_DEST (x), 0)) = replacement->new;
2110 emit_insn_after (gen_move_insn (var, replacement->new), insn);
2111 }
2112
6f086dfc 2113 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
0f41302f 2114 insn into a pseudo and store the low part of the pseudo into VAR. */
6f086dfc
RS
2115 if (GET_CODE (SET_DEST (x)) == SUBREG
2116 && SUBREG_REG (SET_DEST (x)) == var
2117 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
2118 > GET_MODE_SIZE (GET_MODE (var))))
2119 {
2120 SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x)));
2121 emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var),
2122 tem)),
2123 insn);
2124 break;
2125 }
2126
2127 {
2128 rtx dest = SET_DEST (x);
2129 rtx src = SET_SRC (x);
29a82058 2130#ifdef HAVE_insv
6f086dfc 2131 rtx outerdest = dest;
29a82058 2132#endif
6f086dfc
RS
2133
2134 while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
2135 || GET_CODE (dest) == SIGN_EXTRACT
2136 || GET_CODE (dest) == ZERO_EXTRACT)
2137 dest = XEXP (dest, 0);
2138
2139 if (GET_CODE (src) == SUBREG)
2140 src = XEXP (src, 0);
2141
2142 /* If VAR does not appear at the top level of the SET
2143 just scan the lower levels of the tree. */
2144
2145 if (src != var && dest != var)
2146 break;
2147
2148 /* We will need to rerecognize this insn. */
2149 INSN_CODE (insn) = -1;
2150
2151#ifdef HAVE_insv
2152 if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var)
2153 {
2154 /* Since this case will return, ensure we fixup all the
2155 operands here. */
00d8a4c1
RK
2156 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1),
2157 insn, replacements);
2158 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2),
2159 insn, replacements);
2160 fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x),
2161 insn, replacements);
6f086dfc
RS
2162
2163 tem = XEXP (outerdest, 0);
2164
2165 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
2166 that may appear inside a ZERO_EXTRACT.
2167 This was legitimate when the MEM was a REG. */
2168 if (GET_CODE (tem) == SUBREG
2169 && SUBREG_REG (tem) == var)
0e09cc26 2170 tem = fixup_memory_subreg (tem, insn, 0);
6f086dfc
RS
2171 else
2172 tem = fixup_stack_1 (tem, insn);
2173
2174 if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT
2175 && GET_CODE (XEXP (outerdest, 2)) == CONST_INT
2176 && ! mode_dependent_address_p (XEXP (tem, 0))
2177 && ! MEM_VOLATILE_P (tem))
2178 {
0d8e55d8 2179 enum machine_mode wanted_mode;
6f086dfc 2180 enum machine_mode is_mode = GET_MODE (tem);
e5e809f4 2181 HOST_WIDE_INT pos = INTVAL (XEXP (outerdest, 2));
6f086dfc 2182
0d8e55d8
JL
2183 wanted_mode = insn_operand_mode[(int) CODE_FOR_insv][0];
2184 if (wanted_mode == VOIDmode)
2185 wanted_mode = word_mode;
2186
6dc42e49 2187 /* If we have a narrower mode, we can do something. */
6f086dfc
RS
2188 if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
2189 {
e5e809f4 2190 HOST_WIDE_INT offset = pos / BITS_PER_UNIT;
6f086dfc
RS
2191 rtx old_pos = XEXP (outerdest, 2);
2192 rtx newmem;
2193
f76b9db2
ILT
2194 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
2195 offset = (GET_MODE_SIZE (is_mode)
2196 - GET_MODE_SIZE (wanted_mode) - offset);
6f086dfc
RS
2197
2198 pos %= GET_MODE_BITSIZE (wanted_mode);
2199
38a448ca
RH
2200 newmem = gen_rtx_MEM (wanted_mode,
2201 plus_constant (XEXP (tem, 0), offset));
6f086dfc
RS
2202 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
2203 MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
2204 MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
2205
2206 /* Make the change and see if the insn remains valid. */
2207 INSN_CODE (insn) = -1;
2208 XEXP (outerdest, 0) = newmem;
5f4f0e22 2209 XEXP (outerdest, 2) = GEN_INT (pos);
6f086dfc
RS
2210
2211 if (recog_memoized (insn) >= 0)
2212 return;
2213
2214 /* Otherwise, restore old position. XEXP (x, 0) will be
2215 restored later. */
2216 XEXP (outerdest, 2) = old_pos;
2217 }
2218 }
2219
2220 /* If we get here, the bit-field store doesn't allow memory
2221 or isn't located at a constant position. Load the value into
2222 a register, do the store, and put it back into memory. */
2223
2224 tem1 = gen_reg_rtx (GET_MODE (tem));
2225 emit_insn_before (gen_move_insn (tem1, tem), insn);
2226 emit_insn_after (gen_move_insn (tem, tem1), insn);
2227 XEXP (outerdest, 0) = tem1;
2228 return;
2229 }
2230#endif
2231
2232 /* STRICT_LOW_PART is a no-op on memory references
2233 and it can cause combinations to be unrecognizable,
2234 so eliminate it. */
2235
2236 if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
2237 SET_DEST (x) = XEXP (SET_DEST (x), 0);
2238
2239 /* A valid insn to copy VAR into or out of a register
2240 must be left alone, to avoid an infinite loop here.
2241 If the reference to VAR is by a subreg, fix that up,
2242 since SUBREG is not valid for a memref.
e15762df
RK
2243 Also fix up the address of the stack slot.
2244
2245 Note that we must not try to recognize the insn until
2246 after we know that we have valid addresses and no
2247 (subreg (mem ...) ...) constructs, since these interfere
2248 with determining the validity of the insn. */
6f086dfc
RS
2249
2250 if ((SET_SRC (x) == var
2251 || (GET_CODE (SET_SRC (x)) == SUBREG
2252 && SUBREG_REG (SET_SRC (x)) == var))
2253 && (GET_CODE (SET_DEST (x)) == REG
2254 || (GET_CODE (SET_DEST (x)) == SUBREG
2255 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
1d273bf5 2256 && GET_MODE (var) == promoted_mode
c46722a7 2257 && x == single_set (insn))
6f086dfc 2258 {
e15762df
RK
2259 rtx pat;
2260
2740a678 2261 replacement = find_fixup_replacement (replacements, SET_SRC (x));
6f086dfc 2262 if (replacement->new)
6f086dfc 2263 SET_SRC (x) = replacement->new;
6f086dfc
RS
2264 else if (GET_CODE (SET_SRC (x)) == SUBREG)
2265 SET_SRC (x) = replacement->new
2266 = fixup_memory_subreg (SET_SRC (x), insn, 0);
2267 else
2268 SET_SRC (x) = replacement->new
2269 = fixup_stack_1 (SET_SRC (x), insn);
e15762df
RK
2270
2271 if (recog_memoized (insn) >= 0)
2272 return;
2273
2274 /* INSN is not valid, but we know that we want to
2275 copy SET_SRC (x) to SET_DEST (x) in some way. So
2276 we generate the move and see whether it requires more
2277 than one insn. If it does, we emit those insns and
2278 delete INSN. Otherwise, we an just replace the pattern
2279 of INSN; we have already verified above that INSN has
2280 no other function that to do X. */
2281
2282 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2283 if (GET_CODE (pat) == SEQUENCE)
2284 {
2285 emit_insn_after (pat, insn);
2286 PUT_CODE (insn, NOTE);
2287 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2288 NOTE_SOURCE_FILE (insn) = 0;
2289 }
2290 else
2291 PATTERN (insn) = pat;
2292
6f086dfc
RS
2293 return;
2294 }
2295
2296 if ((SET_DEST (x) == var
2297 || (GET_CODE (SET_DEST (x)) == SUBREG
2298 && SUBREG_REG (SET_DEST (x)) == var))
2299 && (GET_CODE (SET_SRC (x)) == REG
2300 || (GET_CODE (SET_SRC (x)) == SUBREG
2301 && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG))
1d273bf5 2302 && GET_MODE (var) == promoted_mode
c46722a7 2303 && x == single_set (insn))
6f086dfc 2304 {
e15762df
RK
2305 rtx pat;
2306
6f086dfc
RS
2307 if (GET_CODE (SET_DEST (x)) == SUBREG)
2308 SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn, 0);
2309 else
2310 SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn);
e15762df
RK
2311
2312 if (recog_memoized (insn) >= 0)
2313 return;
2314
2315 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2316 if (GET_CODE (pat) == SEQUENCE)
2317 {
2318 emit_insn_after (pat, insn);
2319 PUT_CODE (insn, NOTE);
2320 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2321 NOTE_SOURCE_FILE (insn) = 0;
2322 }
2323 else
2324 PATTERN (insn) = pat;
2325
6f086dfc
RS
2326 return;
2327 }
2328
2329 /* Otherwise, storing into VAR must be handled specially
2330 by storing into a temporary and copying that into VAR
00d8a4c1
RK
2331 with a new insn after this one. Note that this case
2332 will be used when storing into a promoted scalar since
2333 the insn will now have different modes on the input
2334 and output and hence will be invalid (except for the case
2335 of setting it to a constant, which does not need any
2336 change if it is valid). We generate extra code in that case,
2337 but combine.c will eliminate it. */
6f086dfc
RS
2338
2339 if (dest == var)
2340 {
2341 rtx temp;
00d8a4c1
RK
2342 rtx fixeddest = SET_DEST (x);
2343
6f086dfc 2344 /* STRICT_LOW_PART can be discarded, around a MEM. */
00d8a4c1
RK
2345 if (GET_CODE (fixeddest) == STRICT_LOW_PART)
2346 fixeddest = XEXP (fixeddest, 0);
6f086dfc 2347 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
00d8a4c1 2348 if (GET_CODE (fixeddest) == SUBREG)
926d1ca5
RK
2349 {
2350 fixeddest = fixup_memory_subreg (fixeddest, insn, 0);
2351 promoted_mode = GET_MODE (fixeddest);
2352 }
6f086dfc 2353 else
00d8a4c1
RK
2354 fixeddest = fixup_stack_1 (fixeddest, insn);
2355
926d1ca5 2356 temp = gen_reg_rtx (promoted_mode);
00d8a4c1
RK
2357
2358 emit_insn_after (gen_move_insn (fixeddest,
2359 gen_lowpart (GET_MODE (fixeddest),
2360 temp)),
2361 insn);
6f086dfc 2362
6f086dfc
RS
2363 SET_DEST (x) = temp;
2364 }
2365 }
e9a25f70
JL
2366
2367 default:
2368 break;
6f086dfc
RS
2369 }
2370
2371 /* Nothing special about this RTX; fix its operands. */
2372
2373 fmt = GET_RTX_FORMAT (code);
2374 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2375 {
2376 if (fmt[i] == 'e')
00d8a4c1 2377 fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements);
6f086dfc
RS
2378 if (fmt[i] == 'E')
2379 {
2380 register int j;
2381 for (j = 0; j < XVECLEN (x, i); j++)
00d8a4c1
RK
2382 fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j),
2383 insn, replacements);
6f086dfc
RS
2384 }
2385 }
2386}
2387\f
2388/* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
2389 return an rtx (MEM:m1 newaddr) which is equivalent.
2390 If any insns must be emitted to compute NEWADDR, put them before INSN.
2391
2392 UNCRITICAL nonzero means accept paradoxical subregs.
0f41302f 2393 This is used for subregs found inside REG_NOTES. */
6f086dfc
RS
2394
2395static rtx
2396fixup_memory_subreg (x, insn, uncritical)
2397 rtx x;
2398 rtx insn;
2399 int uncritical;
2400{
2401 int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
2402 rtx addr = XEXP (SUBREG_REG (x), 0);
2403 enum machine_mode mode = GET_MODE (x);
29a82058 2404 rtx result;
6f086dfc
RS
2405
2406 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
2407 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
2408 && ! uncritical)
2409 abort ();
2410
f76b9db2
ILT
2411 if (BYTES_BIG_ENDIAN)
2412 offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
2413 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
6f086dfc
RS
2414 addr = plus_constant (addr, offset);
2415 if (!flag_force_addr && memory_address_p (mode, addr))
2416 /* Shortcut if no insns need be emitted. */
2417 return change_address (SUBREG_REG (x), mode, addr);
2418 start_sequence ();
2419 result = change_address (SUBREG_REG (x), mode, addr);
2420 emit_insn_before (gen_sequence (), insn);
2421 end_sequence ();
2422 return result;
2423}
2424
2425/* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2426 Replace subexpressions of X in place.
2427 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2428 Otherwise return X, with its contents possibly altered.
2429
ab6155b7
RK
2430 If any insns must be emitted to compute NEWADDR, put them before INSN.
2431
2432 UNCRITICAL is as in fixup_memory_subreg. */
6f086dfc
RS
2433
2434static rtx
ab6155b7 2435walk_fixup_memory_subreg (x, insn, uncritical)
6f086dfc
RS
2436 register rtx x;
2437 rtx insn;
ab6155b7 2438 int uncritical;
6f086dfc
RS
2439{
2440 register enum rtx_code code;
2441 register char *fmt;
2442 register int i;
2443
2444 if (x == 0)
2445 return 0;
2446
2447 code = GET_CODE (x);
2448
2449 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
ab6155b7 2450 return fixup_memory_subreg (x, insn, uncritical);
6f086dfc
RS
2451
2452 /* Nothing special about this RTX; fix its operands. */
2453
2454 fmt = GET_RTX_FORMAT (code);
2455 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2456 {
2457 if (fmt[i] == 'e')
ab6155b7 2458 XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn, uncritical);
6f086dfc
RS
2459 if (fmt[i] == 'E')
2460 {
2461 register int j;
2462 for (j = 0; j < XVECLEN (x, i); j++)
2463 XVECEXP (x, i, j)
ab6155b7 2464 = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn, uncritical);
6f086dfc
RS
2465 }
2466 }
2467 return x;
2468}
2469\f
6f086dfc
RS
2470/* For each memory ref within X, if it refers to a stack slot
2471 with an out of range displacement, put the address in a temp register
2472 (emitting new insns before INSN to load these registers)
2473 and alter the memory ref to use that register.
2474 Replace each such MEM rtx with a copy, to avoid clobberage. */
2475
2476static rtx
2477fixup_stack_1 (x, insn)
2478 rtx x;
2479 rtx insn;
2480{
2481 register int i;
2482 register RTX_CODE code = GET_CODE (x);
2483 register char *fmt;
2484
2485 if (code == MEM)
2486 {
2487 register rtx ad = XEXP (x, 0);
2488 /* If we have address of a stack slot but it's not valid
2489 (displacement is too large), compute the sum in a register. */
2490 if (GET_CODE (ad) == PLUS
2491 && GET_CODE (XEXP (ad, 0)) == REG
40d05551
RK
2492 && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER
2493 && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER)
e9a25f70
JL
2494 || REGNO (XEXP (ad, 0)) == FRAME_POINTER_REGNUM
2495#if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2496 || REGNO (XEXP (ad, 0)) == HARD_FRAME_POINTER_REGNUM
2497#endif
2498 || REGNO (XEXP (ad, 0)) == STACK_POINTER_REGNUM
956d6950 2499 || REGNO (XEXP (ad, 0)) == ARG_POINTER_REGNUM
40d05551 2500 || XEXP (ad, 0) == current_function_internal_arg_pointer)
6f086dfc
RS
2501 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
2502 {
2503 rtx temp, seq;
2504 if (memory_address_p (GET_MODE (x), ad))
2505 return x;
2506
2507 start_sequence ();
2508 temp = copy_to_reg (ad);
2509 seq = gen_sequence ();
2510 end_sequence ();
2511 emit_insn_before (seq, insn);
2512 return change_address (x, VOIDmode, temp);
2513 }
2514 return x;
2515 }
2516
2517 fmt = GET_RTX_FORMAT (code);
2518 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2519 {
2520 if (fmt[i] == 'e')
2521 XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
2522 if (fmt[i] == 'E')
2523 {
2524 register int j;
2525 for (j = 0; j < XVECLEN (x, i); j++)
2526 XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
2527 }
2528 }
2529 return x;
2530}
2531\f
2532/* Optimization: a bit-field instruction whose field
2533 happens to be a byte or halfword in memory
2534 can be changed to a move instruction.
2535
2536 We call here when INSN is an insn to examine or store into a bit-field.
2537 BODY is the SET-rtx to be altered.
2538
2539 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2540 (Currently this is called only from function.c, and EQUIV_MEM
2541 is always 0.) */
2542
2543static void
2544optimize_bit_field (body, insn, equiv_mem)
2545 rtx body;
2546 rtx insn;
2547 rtx *equiv_mem;
2548{
2549 register rtx bitfield;
2550 int destflag;
2551 rtx seq = 0;
2552 enum machine_mode mode;
2553
2554 if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
2555 || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
2556 bitfield = SET_DEST (body), destflag = 1;
2557 else
2558 bitfield = SET_SRC (body), destflag = 0;
2559
2560 /* First check that the field being stored has constant size and position
2561 and is in fact a byte or halfword suitably aligned. */
2562
2563 if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
2564 && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
2565 && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1))
2566 != BLKmode)
2567 && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
2568 {
2569 register rtx memref = 0;
2570
2571 /* Now check that the containing word is memory, not a register,
2572 and that it is safe to change the machine mode. */
2573
2574 if (GET_CODE (XEXP (bitfield, 0)) == MEM)
2575 memref = XEXP (bitfield, 0);
2576 else if (GET_CODE (XEXP (bitfield, 0)) == REG
2577 && equiv_mem != 0)
2578 memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
2579 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2580 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
2581 memref = SUBREG_REG (XEXP (bitfield, 0));
2582 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2583 && equiv_mem != 0
2584 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
2585 memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
2586
2587 if (memref
2588 && ! mode_dependent_address_p (XEXP (memref, 0))
2589 && ! MEM_VOLATILE_P (memref))
2590 {
2591 /* Now adjust the address, first for any subreg'ing
2592 that we are now getting rid of,
2593 and then for which byte of the word is wanted. */
2594
e5e809f4 2595 HOST_WIDE_INT offset = INTVAL (XEXP (bitfield, 2));
b88a3142
RK
2596 rtx insns;
2597
6f086dfc 2598 /* Adjust OFFSET to count bits from low-address byte. */
f76b9db2
ILT
2599 if (BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN)
2600 offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0)))
2601 - offset - INTVAL (XEXP (bitfield, 1)));
2602
6f086dfc
RS
2603 /* Adjust OFFSET to count bytes from low-address byte. */
2604 offset /= BITS_PER_UNIT;
2605 if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
2606 {
2607 offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD;
f76b9db2
ILT
2608 if (BYTES_BIG_ENDIAN)
2609 offset -= (MIN (UNITS_PER_WORD,
2610 GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
2611 - MIN (UNITS_PER_WORD,
2612 GET_MODE_SIZE (GET_MODE (memref))));
6f086dfc
RS
2613 }
2614
b88a3142
RK
2615 start_sequence ();
2616 memref = change_address (memref, mode,
6f086dfc 2617 plus_constant (XEXP (memref, 0), offset));
b88a3142
RK
2618 insns = get_insns ();
2619 end_sequence ();
2620 emit_insns_before (insns, insn);
6f086dfc
RS
2621
2622 /* Store this memory reference where
2623 we found the bit field reference. */
2624
2625 if (destflag)
2626 {
2627 validate_change (insn, &SET_DEST (body), memref, 1);
2628 if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
2629 {
2630 rtx src = SET_SRC (body);
2631 while (GET_CODE (src) == SUBREG
2632 && SUBREG_WORD (src) == 0)
2633 src = SUBREG_REG (src);
2634 if (GET_MODE (src) != GET_MODE (memref))
2635 src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
2636 validate_change (insn, &SET_SRC (body), src, 1);
2637 }
2638 else if (GET_MODE (SET_SRC (body)) != VOIDmode
2639 && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
2640 /* This shouldn't happen because anything that didn't have
2641 one of these modes should have got converted explicitly
2642 and then referenced through a subreg.
2643 This is so because the original bit-field was
2644 handled by agg_mode and so its tree structure had
2645 the same mode that memref now has. */
2646 abort ();
2647 }
2648 else
2649 {
2650 rtx dest = SET_DEST (body);
2651
2652 while (GET_CODE (dest) == SUBREG
4013a709
RK
2653 && SUBREG_WORD (dest) == 0
2654 && (GET_MODE_CLASS (GET_MODE (dest))
2655 == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest)))))
6f086dfc
RS
2656 dest = SUBREG_REG (dest);
2657
2658 validate_change (insn, &SET_DEST (body), dest, 1);
2659
2660 if (GET_MODE (dest) == GET_MODE (memref))
2661 validate_change (insn, &SET_SRC (body), memref, 1);
2662 else
2663 {
2664 /* Convert the mem ref to the destination mode. */
2665 rtx newreg = gen_reg_rtx (GET_MODE (dest));
2666
2667 start_sequence ();
2668 convert_move (newreg, memref,
2669 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
2670 seq = get_insns ();
2671 end_sequence ();
2672
2673 validate_change (insn, &SET_SRC (body), newreg, 1);
2674 }
2675 }
2676
2677 /* See if we can convert this extraction or insertion into
2678 a simple move insn. We might not be able to do so if this
2679 was, for example, part of a PARALLEL.
2680
2681 If we succeed, write out any needed conversions. If we fail,
2682 it is hard to guess why we failed, so don't do anything
2683 special; just let the optimization be suppressed. */
2684
2685 if (apply_change_group () && seq)
2686 emit_insns_before (seq, insn);
2687 }
2688 }
2689}
2690\f
2691/* These routines are responsible for converting virtual register references
2692 to the actual hard register references once RTL generation is complete.
2693
2694 The following four variables are used for communication between the
2695 routines. They contain the offsets of the virtual registers from their
2696 respective hard registers. */
2697
2698static int in_arg_offset;
2699static int var_offset;
2700static int dynamic_offset;
2701static int out_arg_offset;
71038426 2702static int cfa_offset;
6f086dfc
RS
2703
2704/* In most machines, the stack pointer register is equivalent to the bottom
2705 of the stack. */
2706
2707#ifndef STACK_POINTER_OFFSET
2708#define STACK_POINTER_OFFSET 0
2709#endif
2710
2711/* If not defined, pick an appropriate default for the offset of dynamically
2712 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2713 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2714
2715#ifndef STACK_DYNAMIC_OFFSET
2716
2717#ifdef ACCUMULATE_OUTGOING_ARGS
2718/* The bottom of the stack points to the actual arguments. If
2719 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2720 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2721 stack space for register parameters is not pushed by the caller, but
2722 rather part of the fixed stack areas and hence not included in
2723 `current_function_outgoing_args_size'. Nevertheless, we must allow
2724 for it when allocating stack dynamic objects. */
2725
2726#if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2727#define STACK_DYNAMIC_OFFSET(FNDECL) \
2728(current_function_outgoing_args_size \
2729 + REG_PARM_STACK_SPACE (FNDECL) + (STACK_POINTER_OFFSET))
2730
2731#else
2732#define STACK_DYNAMIC_OFFSET(FNDECL) \
2733(current_function_outgoing_args_size + (STACK_POINTER_OFFSET))
2734#endif
2735
2736#else
2737#define STACK_DYNAMIC_OFFSET(FNDECL) STACK_POINTER_OFFSET
2738#endif
2739#endif
2740
71038426
RH
2741/* On a few machines, the CFA coincides with the arg pointer. */
2742
2743#ifndef ARG_POINTER_CFA_OFFSET
2744#define ARG_POINTER_CFA_OFFSET 0
2745#endif
2746
2747
e9a25f70
JL
2748/* Build up a (MEM (ADDRESSOF (REG))) rtx for a register REG that just had
2749 its address taken. DECL is the decl for the object stored in the
2750 register, for later use if we do need to force REG into the stack.
2751 REG is overwritten by the MEM like in put_reg_into_stack. */
2752
2753rtx
2754gen_mem_addressof (reg, decl)
2755 rtx reg;
2756 tree decl;
2757{
2758 tree type = TREE_TYPE (decl);
2759
38a448ca 2760 rtx r = gen_rtx_ADDRESSOF (Pmode, gen_reg_rtx (GET_MODE (reg)), REGNO (reg));
e9a25f70
JL
2761 SET_ADDRESSOF_DECL (r, decl);
2762
2763 XEXP (reg, 0) = r;
2764 PUT_CODE (reg, MEM);
2765 PUT_MODE (reg, DECL_MODE (decl));
2766 MEM_VOLATILE_P (reg) = TREE_SIDE_EFFECTS (decl);
2767 MEM_IN_STRUCT_P (reg) = AGGREGATE_TYPE_P (type);
41472af8 2768 MEM_ALIAS_SET (reg) = get_alias_set (decl);
e9a25f70 2769
e5e809f4
JL
2770 if (TREE_USED (decl) || DECL_INITIAL (decl) != 0)
2771 fixup_var_refs (reg, GET_MODE (reg), TREE_UNSIGNED (type));
2772
e9a25f70
JL
2773 return reg;
2774}
2775
2776/* If DECL has an RTL that is an ADDRESSOF rtx, put it into the stack. */
2777
2778void
2779flush_addressof (decl)
2780 tree decl;
2781{
2782 if ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == VAR_DECL)
2783 && DECL_RTL (decl) != 0
2784 && GET_CODE (DECL_RTL (decl)) == MEM
2785 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF
2786 && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 0)) == REG)
2787 put_addressof_into_stack (XEXP (DECL_RTL (decl), 0));
2788}
2789
2790/* Force the register pointed to by R, an ADDRESSOF rtx, into the stack. */
2791
2792static void
2793put_addressof_into_stack (r)
2794 rtx r;
2795{
2796 tree decl = ADDRESSOF_DECL (r);
2797 rtx reg = XEXP (r, 0);
2798
2799 if (GET_CODE (reg) != REG)
2800 abort ();
2801
2802 put_reg_into_stack (0, reg, TREE_TYPE (decl), GET_MODE (reg),
2803 DECL_MODE (decl), TREE_SIDE_EFFECTS (decl),
e5e809f4
JL
2804 ADDRESSOF_REGNO (r),
2805 TREE_USED (decl) || DECL_INITIAL (decl) != 0);
e9a25f70
JL
2806}
2807
2808/* Helper function for purge_addressof. See if the rtx expression at *LOC
2809 in INSN needs to be changed. If FORCE, always put any ADDRESSOFs into
2810 the stack. */
2811
2812static void
2813purge_addressof_1 (loc, insn, force)
2814 rtx *loc;
2815 rtx insn;
2816 int force;
2817{
2818 rtx x;
2819 RTX_CODE code;
2820 int i, j;
2821 char *fmt;
2822
2823 /* Re-start here to avoid recursion in common cases. */
2824 restart:
2825
2826 x = *loc;
2827 if (x == 0)
2828 return;
2829
2830 code = GET_CODE (x);
2831
2832 if (code == ADDRESSOF && GET_CODE (XEXP (x, 0)) == MEM)
2833 {
2834 rtx insns;
956d6950
JL
2835 /* We must create a copy of the rtx because it was created by
2836 overwriting a REG rtx which is always shared. */
2837 rtx sub = copy_rtx (XEXP (XEXP (x, 0), 0));
e9a25f70 2838
956d6950 2839 if (validate_change (insn, loc, sub, 0))
e9a25f70
JL
2840 return;
2841
2842 start_sequence ();
2843 if (! validate_change (insn, loc,
956d6950 2844 force_operand (sub, NULL_RTX),
e9a25f70
JL
2845 0))
2846 abort ();
2847
2848 insns = get_insns ();
2849 end_sequence ();
2850 emit_insns_before (insns, insn);
2851 return;
2852 }
2853 else if (code == MEM && GET_CODE (XEXP (x, 0)) == ADDRESSOF && ! force)
2854 {
2855 rtx sub = XEXP (XEXP (x, 0), 0);
e5e809f4 2856
6d8ccdbb 2857 if (GET_CODE (sub) == MEM)
38a448ca 2858 sub = gen_rtx_MEM (GET_MODE (x), copy_rtx (XEXP (sub, 0)));
e5e809f4 2859
f5963e61
JL
2860 if (GET_CODE (sub) == REG
2861 && (MEM_VOLATILE_P (x) || GET_MODE (x) == BLKmode))
e5e809f4
JL
2862 {
2863 put_addressof_into_stack (XEXP (x, 0));
2864 return;
2865 }
2866 else if (GET_CODE (sub) == REG && GET_MODE (x) != GET_MODE (sub))
e9a25f70
JL
2867 {
2868 if (! BYTES_BIG_ENDIAN && ! WORDS_BIG_ENDIAN)
2869 {
38a448ca 2870 rtx sub2 = gen_rtx_SUBREG (GET_MODE (x), sub, 0);
e9a25f70
JL
2871 if (validate_change (insn, loc, sub2, 0))
2872 goto restart;
2873 }
2874 }
2875 else if (validate_change (insn, loc, sub, 0))
2876 goto restart;
2877 /* else give up and put it into the stack */
2878 }
2879 else if (code == ADDRESSOF)
2880 {
2881 put_addressof_into_stack (x);
2882 return;
2883 }
2884
2885 /* Scan all subexpressions. */
2886 fmt = GET_RTX_FORMAT (code);
2887 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
2888 {
2889 if (*fmt == 'e')
2890 purge_addressof_1 (&XEXP (x, i), insn, force);
2891 else if (*fmt == 'E')
2892 for (j = 0; j < XVECLEN (x, i); j++)
2893 purge_addressof_1 (&XVECEXP (x, i, j), insn, force);
2894 }
2895}
2896
2897/* Eliminate all occurrences of ADDRESSOF from INSNS. Elide any remaining
2898 (MEM (ADDRESSOF)) patterns, and force any needed registers into the
2899 stack. */
2900
2901void
2902purge_addressof (insns)
2903 rtx insns;
2904{
2905 rtx insn;
2906 for (insn = insns; insn; insn = NEXT_INSN (insn))
2907 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
2908 || GET_CODE (insn) == CALL_INSN)
2909 {
2910 purge_addressof_1 (&PATTERN (insn), insn,
2911 asm_noperands (PATTERN (insn)) > 0);
2912 purge_addressof_1 (&REG_NOTES (insn), NULL_RTX, 0);
2913 }
2914}
2915\f
6f086dfc
RS
2916/* Pass through the INSNS of function FNDECL and convert virtual register
2917 references to hard register references. */
2918
2919void
2920instantiate_virtual_regs (fndecl, insns)
2921 tree fndecl;
2922 rtx insns;
2923{
2924 rtx insn;
e9a25f70 2925 int i;
6f086dfc
RS
2926
2927 /* Compute the offsets to use for this function. */
2928 in_arg_offset = FIRST_PARM_OFFSET (fndecl);
2929 var_offset = STARTING_FRAME_OFFSET;
2930 dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl);
2931 out_arg_offset = STACK_POINTER_OFFSET;
71038426 2932 cfa_offset = ARG_POINTER_CFA_OFFSET;
6f086dfc
RS
2933
2934 /* Scan all variables and parameters of this function. For each that is
2935 in memory, instantiate all virtual registers if the result is a valid
2936 address. If not, we do it later. That will handle most uses of virtual
2937 regs on many machines. */
2938 instantiate_decls (fndecl, 1);
2939
2940 /* Initialize recognition, indicating that volatile is OK. */
2941 init_recog ();
2942
2943 /* Scan through all the insns, instantiating every virtual register still
2944 present. */
2945 for (insn = insns; insn; insn = NEXT_INSN (insn))
2946 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
2947 || GET_CODE (insn) == CALL_INSN)
2948 {
2949 instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1);
5f4f0e22 2950 instantiate_virtual_regs_1 (&REG_NOTES (insn), NULL_RTX, 0);
6f086dfc
RS
2951 }
2952
e9a25f70
JL
2953 /* Instantiate the stack slots for the parm registers, for later use in
2954 addressof elimination. */
2955 for (i = 0; i < max_parm_reg; ++i)
2956 if (parm_reg_stack_loc[i])
2957 instantiate_virtual_regs_1 (&parm_reg_stack_loc[i], NULL_RTX, 0);
2958
6f086dfc
RS
2959 /* Now instantiate the remaining register equivalences for debugging info.
2960 These will not be valid addresses. */
2961 instantiate_decls (fndecl, 0);
2962
2963 /* Indicate that, from now on, assign_stack_local should use
2964 frame_pointer_rtx. */
2965 virtuals_instantiated = 1;
2966}
2967
2968/* Scan all decls in FNDECL (both variables and parameters) and instantiate
2969 all virtual registers in their DECL_RTL's.
2970
2971 If VALID_ONLY, do this only if the resulting address is still valid.
2972 Otherwise, always do it. */
2973
2974static void
2975instantiate_decls (fndecl, valid_only)
2976 tree fndecl;
2977 int valid_only;
2978{
2979 tree decl;
2980
e1686233 2981 if (DECL_SAVED_INSNS (fndecl))
6f086dfc
RS
2982 /* When compiling an inline function, the obstack used for
2983 rtl allocation is the maybepermanent_obstack. Calling
2984 `resume_temporary_allocation' switches us back to that
2985 obstack while we process this function's parameters. */
2986 resume_temporary_allocation ();
2987
2988 /* Process all parameters of the function. */
2989 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
2990 {
e5e809f4
JL
2991 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
2992
ce717ce4
JW
2993 instantiate_decl (DECL_RTL (decl), size, valid_only);
2994
2995 /* If the parameter was promoted, then the incoming RTL mode may be
2996 larger than the declared type size. We must use the larger of
2997 the two sizes. */
2998 size = MAX (GET_MODE_SIZE (GET_MODE (DECL_INCOMING_RTL (decl))), size);
2999 instantiate_decl (DECL_INCOMING_RTL (decl), size, valid_only);
6f086dfc
RS
3000 }
3001
0f41302f 3002 /* Now process all variables defined in the function or its subblocks. */
6f086dfc
RS
3003 instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only);
3004
79c0672e 3005 if (DECL_INLINE (fndecl) || DECL_DEFER_OUTPUT (fndecl))
6f086dfc
RS
3006 {
3007 /* Save all rtl allocated for this function by raising the
3008 high-water mark on the maybepermanent_obstack. */
3009 preserve_data ();
3010 /* All further rtl allocation is now done in the current_obstack. */
3011 rtl_in_current_obstack ();
3012 }
3013}
3014
3015/* Subroutine of instantiate_decls: Process all decls in the given
3016 BLOCK node and all its subblocks. */
3017
3018static void
3019instantiate_decls_1 (let, valid_only)
3020 tree let;
3021 int valid_only;
3022{
3023 tree t;
3024
3025 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
5a73491b
RK
3026 instantiate_decl (DECL_RTL (t), int_size_in_bytes (TREE_TYPE (t)),
3027 valid_only);
6f086dfc
RS
3028
3029 /* Process all subblocks. */
3030 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
3031 instantiate_decls_1 (t, valid_only);
3032}
5a73491b 3033
8008b228 3034/* Subroutine of the preceding procedures: Given RTL representing a
5a73491b
RK
3035 decl and the size of the object, do any instantiation required.
3036
3037 If VALID_ONLY is non-zero, it means that the RTL should only be
3038 changed if the new address is valid. */
3039
3040static void
3041instantiate_decl (x, size, valid_only)
3042 rtx x;
3043 int size;
3044 int valid_only;
3045{
3046 enum machine_mode mode;
3047 rtx addr;
3048
3049 /* If this is not a MEM, no need to do anything. Similarly if the
3050 address is a constant or a register that is not a virtual register. */
3051
3052 if (x == 0 || GET_CODE (x) != MEM)
3053 return;
3054
3055 addr = XEXP (x, 0);
3056 if (CONSTANT_P (addr)
956d6950 3057 || (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == REG)
5a73491b
RK
3058 || (GET_CODE (addr) == REG
3059 && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
3060 || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
3061 return;
3062
3063 /* If we should only do this if the address is valid, copy the address.
3064 We need to do this so we can undo any changes that might make the
3065 address invalid. This copy is unfortunate, but probably can't be
3066 avoided. */
3067
3068 if (valid_only)
3069 addr = copy_rtx (addr);
3070
3071 instantiate_virtual_regs_1 (&addr, NULL_RTX, 0);
3072
87ce34d6
JW
3073 if (valid_only)
3074 {
3075 /* Now verify that the resulting address is valid for every integer or
3076 floating-point mode up to and including SIZE bytes long. We do this
3077 since the object might be accessed in any mode and frame addresses
3078 are shared. */
3079
3080 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
3081 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
3082 mode = GET_MODE_WIDER_MODE (mode))
3083 if (! memory_address_p (mode, addr))
3084 return;
5a73491b 3085
87ce34d6
JW
3086 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
3087 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
3088 mode = GET_MODE_WIDER_MODE (mode))
3089 if (! memory_address_p (mode, addr))
3090 return;
3091 }
5a73491b 3092
87ce34d6
JW
3093 /* Put back the address now that we have updated it and we either know
3094 it is valid or we don't care whether it is valid. */
5a73491b
RK
3095
3096 XEXP (x, 0) = addr;
3097}
6f086dfc
RS
3098\f
3099/* Given a pointer to a piece of rtx and an optional pointer to the
3100 containing object, instantiate any virtual registers present in it.
3101
3102 If EXTRA_INSNS, we always do the replacement and generate
3103 any extra insns before OBJECT. If it zero, we do nothing if replacement
3104 is not valid.
3105
3106 Return 1 if we either had nothing to do or if we were able to do the
3107 needed replacement. Return 0 otherwise; we only return zero if
3108 EXTRA_INSNS is zero.
3109
3110 We first try some simple transformations to avoid the creation of extra
3111 pseudos. */
3112
3113static int
3114instantiate_virtual_regs_1 (loc, object, extra_insns)
3115 rtx *loc;
3116 rtx object;
3117 int extra_insns;
3118{
3119 rtx x;
3120 RTX_CODE code;
3121 rtx new = 0;
e5e809f4 3122 HOST_WIDE_INT offset;
6f086dfc
RS
3123 rtx temp;
3124 rtx seq;
3125 int i, j;
3126 char *fmt;
3127
3128 /* Re-start here to avoid recursion in common cases. */
3129 restart:
3130
3131 x = *loc;
3132 if (x == 0)
3133 return 1;
3134
3135 code = GET_CODE (x);
3136
3137 /* Check for some special cases. */
3138 switch (code)
3139 {
3140 case CONST_INT:
3141 case CONST_DOUBLE:
3142 case CONST:
3143 case SYMBOL_REF:
3144 case CODE_LABEL:
3145 case PC:
3146 case CC0:
3147 case ASM_INPUT:
3148 case ADDR_VEC:
3149 case ADDR_DIFF_VEC:
3150 case RETURN:
3151 return 1;
3152
3153 case SET:
3154 /* We are allowed to set the virtual registers. This means that
38e01259 3155 the actual register should receive the source minus the
6f086dfc
RS
3156 appropriate offset. This is used, for example, in the handling
3157 of non-local gotos. */
3158 if (SET_DEST (x) == virtual_incoming_args_rtx)
3159 new = arg_pointer_rtx, offset = - in_arg_offset;
3160 else if (SET_DEST (x) == virtual_stack_vars_rtx)
dfd3dae6 3161 new = frame_pointer_rtx, offset = - var_offset;
6f086dfc
RS
3162 else if (SET_DEST (x) == virtual_stack_dynamic_rtx)
3163 new = stack_pointer_rtx, offset = - dynamic_offset;
3164 else if (SET_DEST (x) == virtual_outgoing_args_rtx)
3165 new = stack_pointer_rtx, offset = - out_arg_offset;
71038426
RH
3166 else if (SET_DEST (x) == virtual_cfa_rtx)
3167 new = arg_pointer_rtx, offset = - cfa_offset;
6f086dfc
RS
3168
3169 if (new)
3170 {
3171 /* The only valid sources here are PLUS or REG. Just do
3172 the simplest possible thing to handle them. */
3173 if (GET_CODE (SET_SRC (x)) != REG
3174 && GET_CODE (SET_SRC (x)) != PLUS)
3175 abort ();
3176
3177 start_sequence ();
3178 if (GET_CODE (SET_SRC (x)) != REG)
5f4f0e22 3179 temp = force_operand (SET_SRC (x), NULL_RTX);
6f086dfc
RS
3180 else
3181 temp = SET_SRC (x);
5f4f0e22 3182 temp = force_operand (plus_constant (temp, offset), NULL_RTX);
6f086dfc
RS
3183 seq = get_insns ();
3184 end_sequence ();
3185
3186 emit_insns_before (seq, object);
3187 SET_DEST (x) = new;
3188
e9a25f70 3189 if (! validate_change (object, &SET_SRC (x), temp, 0)
6f086dfc
RS
3190 || ! extra_insns)
3191 abort ();
3192
3193 return 1;
3194 }
3195
3196 instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns);
3197 loc = &SET_SRC (x);
3198 goto restart;
3199
3200 case PLUS:
3201 /* Handle special case of virtual register plus constant. */
3202 if (CONSTANT_P (XEXP (x, 1)))
3203 {
b1f82ccf 3204 rtx old, new_offset;
6f086dfc
RS
3205
3206 /* Check for (plus (plus VIRT foo) (const_int)) first. */
3207 if (GET_CODE (XEXP (x, 0)) == PLUS)
3208 {
3209 rtx inner = XEXP (XEXP (x, 0), 0);
3210
3211 if (inner == virtual_incoming_args_rtx)
3212 new = arg_pointer_rtx, offset = in_arg_offset;
3213 else if (inner == virtual_stack_vars_rtx)
3214 new = frame_pointer_rtx, offset = var_offset;
3215 else if (inner == virtual_stack_dynamic_rtx)
3216 new = stack_pointer_rtx, offset = dynamic_offset;
3217 else if (inner == virtual_outgoing_args_rtx)
3218 new = stack_pointer_rtx, offset = out_arg_offset;
71038426
RH
3219 else if (inner == virtual_cfa_rtx)
3220 new = arg_pointer_rtx, offset = cfa_offset;
6f086dfc
RS
3221 else
3222 {
3223 loc = &XEXP (x, 0);
3224 goto restart;
3225 }
3226
3227 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object,
3228 extra_insns);
38a448ca 3229 new = gen_rtx_PLUS (Pmode, new, XEXP (XEXP (x, 0), 1));
6f086dfc
RS
3230 }
3231
3232 else if (XEXP (x, 0) == virtual_incoming_args_rtx)
3233 new = arg_pointer_rtx, offset = in_arg_offset;
3234 else if (XEXP (x, 0) == virtual_stack_vars_rtx)
3235 new = frame_pointer_rtx, offset = var_offset;
3236 else if (XEXP (x, 0) == virtual_stack_dynamic_rtx)
3237 new = stack_pointer_rtx, offset = dynamic_offset;
3238 else if (XEXP (x, 0) == virtual_outgoing_args_rtx)
3239 new = stack_pointer_rtx, offset = out_arg_offset;
71038426
RH
3240 else if (XEXP (x, 0) == virtual_cfa_rtx)
3241 new = arg_pointer_rtx, offset = cfa_offset;
6f086dfc
RS
3242 else
3243 {
3244 /* We know the second operand is a constant. Unless the
3245 first operand is a REG (which has been already checked),
3246 it needs to be checked. */
3247 if (GET_CODE (XEXP (x, 0)) != REG)
3248 {
3249 loc = &XEXP (x, 0);
3250 goto restart;
3251 }
3252 return 1;
3253 }
3254
b1f82ccf 3255 new_offset = plus_constant (XEXP (x, 1), offset);
6f086dfc 3256
b1f82ccf
DE
3257 /* If the new constant is zero, try to replace the sum with just
3258 the register. */
3259 if (new_offset == const0_rtx
3260 && validate_change (object, loc, new, 0))
6f086dfc
RS
3261 return 1;
3262
b1f82ccf
DE
3263 /* Next try to replace the register and new offset.
3264 There are two changes to validate here and we can't assume that
3265 in the case of old offset equals new just changing the register
3266 will yield a valid insn. In the interests of a little efficiency,
3267 however, we only call validate change once (we don't queue up the
0f41302f 3268 changes and then call apply_change_group). */
b1f82ccf
DE
3269
3270 old = XEXP (x, 0);
3271 if (offset == 0
3272 ? ! validate_change (object, &XEXP (x, 0), new, 0)
3273 : (XEXP (x, 0) = new,
3274 ! validate_change (object, &XEXP (x, 1), new_offset, 0)))
6f086dfc
RS
3275 {
3276 if (! extra_insns)
3277 {
3278 XEXP (x, 0) = old;
3279 return 0;
3280 }
3281
3282 /* Otherwise copy the new constant into a register and replace
3283 constant with that register. */
3284 temp = gen_reg_rtx (Pmode);
b1f82ccf 3285 XEXP (x, 0) = new;
6f086dfc 3286 if (validate_change (object, &XEXP (x, 1), temp, 0))
b1f82ccf 3287 emit_insn_before (gen_move_insn (temp, new_offset), object);
6f086dfc
RS
3288 else
3289 {
3290 /* If that didn't work, replace this expression with a
3291 register containing the sum. */
3292
6f086dfc 3293 XEXP (x, 0) = old;
38a448ca 3294 new = gen_rtx_PLUS (Pmode, new, new_offset);
6f086dfc
RS
3295
3296 start_sequence ();
5f4f0e22 3297 temp = force_operand (new, NULL_RTX);
6f086dfc
RS
3298 seq = get_insns ();
3299 end_sequence ();
3300
3301 emit_insns_before (seq, object);
3302 if (! validate_change (object, loc, temp, 0)
3303 && ! validate_replace_rtx (x, temp, object))
3304 abort ();
3305 }
3306 }
3307
3308 return 1;
3309 }
3310
3311 /* Fall through to generic two-operand expression case. */
3312 case EXPR_LIST:
3313 case CALL:
3314 case COMPARE:
3315 case MINUS:
3316 case MULT:
3317 case DIV: case UDIV:
3318 case MOD: case UMOD:
3319 case AND: case IOR: case XOR:
45620ed4
RK
3320 case ROTATERT: case ROTATE:
3321 case ASHIFTRT: case LSHIFTRT: case ASHIFT:
6f086dfc
RS
3322 case NE: case EQ:
3323 case GE: case GT: case GEU: case GTU:
3324 case LE: case LT: case LEU: case LTU:
3325 if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1)))
3326 instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns);
3327 loc = &XEXP (x, 0);
3328 goto restart;
3329
3330 case MEM:
3331 /* Most cases of MEM that convert to valid addresses have already been
4fd796bb 3332 handled by our scan of decls. The only special handling we
6f086dfc 3333 need here is to make a copy of the rtx to ensure it isn't being
b335c2cc 3334 shared if we have to change it to a pseudo.
6f086dfc
RS
3335
3336 If the rtx is a simple reference to an address via a virtual register,
3337 it can potentially be shared. In such cases, first try to make it
3338 a valid address, which can also be shared. Otherwise, copy it and
3339 proceed normally.
3340
3341 First check for common cases that need no processing. These are
3342 usually due to instantiation already being done on a previous instance
3343 of a shared rtx. */
3344
3345 temp = XEXP (x, 0);
3346 if (CONSTANT_ADDRESS_P (temp)
3347#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3348 || temp == arg_pointer_rtx
b37f453b
DE
3349#endif
3350#if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3351 || temp == hard_frame_pointer_rtx
6f086dfc
RS
3352#endif
3353 || temp == frame_pointer_rtx)
3354 return 1;
3355
3356 if (GET_CODE (temp) == PLUS
3357 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
3358 && (XEXP (temp, 0) == frame_pointer_rtx
b37f453b
DE
3359#if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3360 || XEXP (temp, 0) == hard_frame_pointer_rtx
3361#endif
6f086dfc
RS
3362#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3363 || XEXP (temp, 0) == arg_pointer_rtx
3364#endif
3365 ))
3366 return 1;
3367
3368 if (temp == virtual_stack_vars_rtx
3369 || temp == virtual_incoming_args_rtx
3370 || (GET_CODE (temp) == PLUS
3371 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
3372 && (XEXP (temp, 0) == virtual_stack_vars_rtx
3373 || XEXP (temp, 0) == virtual_incoming_args_rtx)))
3374 {
3375 /* This MEM may be shared. If the substitution can be done without
3376 the need to generate new pseudos, we want to do it in place
3377 so all copies of the shared rtx benefit. The call below will
3378 only make substitutions if the resulting address is still
3379 valid.
3380
3381 Note that we cannot pass X as the object in the recursive call
3382 since the insn being processed may not allow all valid
6461be14
RS
3383 addresses. However, if we were not passed on object, we can
3384 only modify X without copying it if X will have a valid
3385 address.
6f086dfc 3386
6461be14
RS
3387 ??? Also note that this can still lose if OBJECT is an insn that
3388 has less restrictions on an address that some other insn.
3389 In that case, we will modify the shared address. This case
4fd796bb
RK
3390 doesn't seem very likely, though. One case where this could
3391 happen is in the case of a USE or CLOBBER reference, but we
3392 take care of that below. */
6461be14
RS
3393
3394 if (instantiate_virtual_regs_1 (&XEXP (x, 0),
3395 object ? object : x, 0))
6f086dfc
RS
3396 return 1;
3397
3398 /* Otherwise make a copy and process that copy. We copy the entire
3399 RTL expression since it might be a PLUS which could also be
3400 shared. */
3401 *loc = x = copy_rtx (x);
3402 }
3403
3404 /* Fall through to generic unary operation case. */
6f086dfc
RS
3405 case SUBREG:
3406 case STRICT_LOW_PART:
3407 case NEG: case NOT:
3408 case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC:
3409 case SIGN_EXTEND: case ZERO_EXTEND:
3410 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE:
3411 case FLOAT: case FIX:
3412 case UNSIGNED_FIX: case UNSIGNED_FLOAT:
3413 case ABS:
3414 case SQRT:
3415 case FFS:
3416 /* These case either have just one operand or we know that we need not
3417 check the rest of the operands. */
3418 loc = &XEXP (x, 0);
3419 goto restart;
3420
4fd796bb
RK
3421 case USE:
3422 case CLOBBER:
3423 /* If the operand is a MEM, see if the change is a valid MEM. If not,
3424 go ahead and make the invalid one, but do it to a copy. For a REG,
3425 just make the recursive call, since there's no chance of a problem. */
3426
3427 if ((GET_CODE (XEXP (x, 0)) == MEM
3428 && instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), XEXP (x, 0),
3429 0))
3430 || (GET_CODE (XEXP (x, 0)) == REG
7694ce35 3431 && instantiate_virtual_regs_1 (&XEXP (x, 0), object, 0)))
4fd796bb
RK
3432 return 1;
3433
3434 XEXP (x, 0) = copy_rtx (XEXP (x, 0));
3435 loc = &XEXP (x, 0);
3436 goto restart;
3437
6f086dfc
RS
3438 case REG:
3439 /* Try to replace with a PLUS. If that doesn't work, compute the sum
3440 in front of this insn and substitute the temporary. */
3441 if (x == virtual_incoming_args_rtx)
3442 new = arg_pointer_rtx, offset = in_arg_offset;
3443 else if (x == virtual_stack_vars_rtx)
3444 new = frame_pointer_rtx, offset = var_offset;
3445 else if (x == virtual_stack_dynamic_rtx)
3446 new = stack_pointer_rtx, offset = dynamic_offset;
3447 else if (x == virtual_outgoing_args_rtx)
3448 new = stack_pointer_rtx, offset = out_arg_offset;
71038426
RH
3449 else if (x == virtual_cfa_rtx)
3450 new = arg_pointer_rtx, offset = cfa_offset;
6f086dfc
RS
3451
3452 if (new)
3453 {
3454 temp = plus_constant (new, offset);
3455 if (!validate_change (object, loc, temp, 0))
3456 {
3457 if (! extra_insns)
3458 return 0;
3459
3460 start_sequence ();
5f4f0e22 3461 temp = force_operand (temp, NULL_RTX);
6f086dfc
RS
3462 seq = get_insns ();
3463 end_sequence ();
3464
3465 emit_insns_before (seq, object);
3466 if (! validate_change (object, loc, temp, 0)
3467 && ! validate_replace_rtx (x, temp, object))
3468 abort ();
3469 }
3470 }
3471
3472 return 1;
e9a25f70
JL
3473
3474 case ADDRESSOF:
3475 if (GET_CODE (XEXP (x, 0)) == REG)
3476 return 1;
3477
3478 else if (GET_CODE (XEXP (x, 0)) == MEM)
3479 {
3480 /* If we have a (addressof (mem ..)), do any instantiation inside
3481 since we know we'll be making the inside valid when we finally
3482 remove the ADDRESSOF. */
3483 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), NULL_RTX, 0);
3484 return 1;
3485 }
3486 break;
3487
3488 default:
3489 break;
6f086dfc
RS
3490 }
3491
3492 /* Scan all subexpressions. */
3493 fmt = GET_RTX_FORMAT (code);
3494 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
3495 if (*fmt == 'e')
3496 {
3497 if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns))
3498 return 0;
3499 }
3500 else if (*fmt == 'E')
3501 for (j = 0; j < XVECLEN (x, i); j++)
3502 if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object,
3503 extra_insns))
3504 return 0;
3505
3506 return 1;
3507}
3508\f
3509/* Optimization: assuming this function does not receive nonlocal gotos,
3510 delete the handlers for such, as well as the insns to establish
3511 and disestablish them. */
3512
3513static void
3514delete_handlers ()
3515{
3516 rtx insn;
3517 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3518 {
3519 /* Delete the handler by turning off the flag that would
3520 prevent jump_optimize from deleting it.
3521 Also permit deletion of the nonlocal labels themselves
3522 if nothing local refers to them. */
3523 if (GET_CODE (insn) == CODE_LABEL)
71cd4a8d
JW
3524 {
3525 tree t, last_t;
3526
3527 LABEL_PRESERVE_P (insn) = 0;
3528
3529 /* Remove it from the nonlocal_label list, to avoid confusing
3530 flow. */
3531 for (t = nonlocal_labels, last_t = 0; t;
3532 last_t = t, t = TREE_CHAIN (t))
3533 if (DECL_RTL (TREE_VALUE (t)) == insn)
3534 break;
3535 if (t)
3536 {
3537 if (! last_t)
3538 nonlocal_labels = TREE_CHAIN (nonlocal_labels);
3539 else
3540 TREE_CHAIN (last_t) = TREE_CHAIN (t);
3541 }
3542 }
6f086dfc 3543 if (GET_CODE (insn) == INSN
59257ff7
RK
3544 && ((nonlocal_goto_handler_slot != 0
3545 && reg_mentioned_p (nonlocal_goto_handler_slot, PATTERN (insn)))
3546 || (nonlocal_goto_stack_level != 0
3547 && reg_mentioned_p (nonlocal_goto_stack_level,
3548 PATTERN (insn)))))
6f086dfc
RS
3549 delete_insn (insn);
3550 }
3551}
3552
3553/* Return a list (chain of EXPR_LIST nodes) for the nonlocal labels
3554 of the current function. */
3555
3556rtx
3557nonlocal_label_rtx_list ()
3558{
3559 tree t;
3560 rtx x = 0;
3561
3562 for (t = nonlocal_labels; t; t = TREE_CHAIN (t))
38a448ca 3563 x = gen_rtx_EXPR_LIST (VOIDmode, label_rtx (TREE_VALUE (t)), x);
6f086dfc
RS
3564
3565 return x;
3566}
3567\f
3568/* Output a USE for any register use in RTL.
3569 This is used with -noreg to mark the extent of lifespan
3570 of any registers used in a user-visible variable's DECL_RTL. */
3571
3572void
3573use_variable (rtl)
3574 rtx rtl;
3575{
3576 if (GET_CODE (rtl) == REG)
3577 /* This is a register variable. */
38a448ca 3578 emit_insn (gen_rtx_USE (VOIDmode, rtl));
6f086dfc
RS
3579 else if (GET_CODE (rtl) == MEM
3580 && GET_CODE (XEXP (rtl, 0)) == REG
3581 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
3582 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
3583 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
3584 /* This is a variable-sized structure. */
38a448ca 3585 emit_insn (gen_rtx_USE (VOIDmode, XEXP (rtl, 0)));
6f086dfc
RS
3586}
3587
3588/* Like use_variable except that it outputs the USEs after INSN
3589 instead of at the end of the insn-chain. */
3590
3591void
3592use_variable_after (rtl, insn)
3593 rtx rtl, insn;
3594{
3595 if (GET_CODE (rtl) == REG)
3596 /* This is a register variable. */
38a448ca 3597 emit_insn_after (gen_rtx_USE (VOIDmode, rtl), insn);
6f086dfc
RS
3598 else if (GET_CODE (rtl) == MEM
3599 && GET_CODE (XEXP (rtl, 0)) == REG
3600 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
3601 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
3602 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
3603 /* This is a variable-sized structure. */
38a448ca 3604 emit_insn_after (gen_rtx_USE (VOIDmode, XEXP (rtl, 0)), insn);
6f086dfc
RS
3605}
3606\f
3607int
3608max_parm_reg_num ()
3609{
3610 return max_parm_reg;
3611}
3612
3613/* Return the first insn following those generated by `assign_parms'. */
3614
3615rtx
3616get_first_nonparm_insn ()
3617{
3618 if (last_parm_insn)
3619 return NEXT_INSN (last_parm_insn);
3620 return get_insns ();
3621}
3622
5378192b
RS
3623/* Return the first NOTE_INSN_BLOCK_BEG note in the function.
3624 Crash if there is none. */
3625
3626rtx
3627get_first_block_beg ()
3628{
3629 register rtx searcher;
3630 register rtx insn = get_first_nonparm_insn ();
3631
3632 for (searcher = insn; searcher; searcher = NEXT_INSN (searcher))
3633 if (GET_CODE (searcher) == NOTE
3634 && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG)
3635 return searcher;
3636
3637 abort (); /* Invalid call to this function. (See comments above.) */
3638 return NULL_RTX;
3639}
3640
d181c154
RS
3641/* Return 1 if EXP is an aggregate type (or a value with aggregate type).
3642 This means a type for which function calls must pass an address to the
3643 function or get an address back from the function.
3644 EXP may be a type node or an expression (whose type is tested). */
6f086dfc
RS
3645
3646int
3647aggregate_value_p (exp)
3648 tree exp;
3649{
9d790a4f
RS
3650 int i, regno, nregs;
3651 rtx reg;
d181c154
RS
3652 tree type;
3653 if (TREE_CODE_CLASS (TREE_CODE (exp)) == 't')
3654 type = exp;
3655 else
3656 type = TREE_TYPE (exp);
3657
3658 if (RETURN_IN_MEMORY (type))
6f086dfc 3659 return 1;
956d6950 3660 /* Types that are TREE_ADDRESSABLE must be constructed in memory,
49a2e5b2
DE
3661 and thus can't be returned in registers. */
3662 if (TREE_ADDRESSABLE (type))
3663 return 1;
05e3bdb9 3664 if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
6f086dfc 3665 return 1;
9d790a4f
RS
3666 /* Make sure we have suitable call-clobbered regs to return
3667 the value in; if not, we must return it in memory. */
d181c154 3668 reg = hard_function_value (type, 0);
e71f7aa5
JW
3669
3670 /* If we have something other than a REG (e.g. a PARALLEL), then assume
3671 it is OK. */
3672 if (GET_CODE (reg) != REG)
3673 return 0;
3674
9d790a4f 3675 regno = REGNO (reg);
d181c154 3676 nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type));
9d790a4f
RS
3677 for (i = 0; i < nregs; i++)
3678 if (! call_used_regs[regno + i])
3679 return 1;
6f086dfc
RS
3680 return 0;
3681}
3682\f
3683/* Assign RTL expressions to the function's parameters.
3684 This may involve copying them into registers and using
3685 those registers as the RTL for them.
3686
3687 If SECOND_TIME is non-zero it means that this function is being
3688 called a second time. This is done by integrate.c when a function's
3689 compilation is deferred. We need to come back here in case the
3690 FUNCTION_ARG macro computes items needed for the rest of the compilation
3691 (such as changing which registers are fixed or caller-saved). But suppress
3692 writing any insns or setting DECL_RTL of anything in this case. */
3693
3694void
3695assign_parms (fndecl, second_time)
3696 tree fndecl;
3697 int second_time;
3698{
3699 register tree parm;
3700 register rtx entry_parm = 0;
3701 register rtx stack_parm = 0;
3702 CUMULATIVE_ARGS args_so_far;
621061f4
RK
3703 enum machine_mode promoted_mode, passed_mode;
3704 enum machine_mode nominal_mode, promoted_nominal_mode;
00d8a4c1 3705 int unsignedp;
6f086dfc
RS
3706 /* Total space needed so far for args on the stack,
3707 given as a constant and a tree-expression. */
3708 struct args_size stack_args_size;
3709 tree fntype = TREE_TYPE (fndecl);
3710 tree fnargs = DECL_ARGUMENTS (fndecl);
3711 /* This is used for the arg pointer when referring to stack args. */
3712 rtx internal_arg_pointer;
3713 /* This is a dummy PARM_DECL that we used for the function result if
3714 the function returns a structure. */
3715 tree function_result_decl = 0;
6f086dfc 3716 int varargs_setup = 0;
3412b298 3717 rtx conversion_insns = 0;
6f086dfc
RS
3718
3719 /* Nonzero if the last arg is named `__builtin_va_alist',
3720 which is used on some machines for old-fashioned non-ANSI varargs.h;
3721 this should be stuck onto the stack as if it had arrived there. */
3b69d50e
RK
3722 int hide_last_arg
3723 = (current_function_varargs
3724 && fnargs
6f086dfc
RS
3725 && (parm = tree_last (fnargs)) != 0
3726 && DECL_NAME (parm)
3727 && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
3728 "__builtin_va_alist")));
3729
3730 /* Nonzero if function takes extra anonymous args.
3731 This means the last named arg must be on the stack
0f41302f 3732 right before the anonymous ones. */
6f086dfc
RS
3733 int stdarg
3734 = (TYPE_ARG_TYPES (fntype) != 0
3735 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3736 != void_type_node));
3737
ebb904cb
RK
3738 current_function_stdarg = stdarg;
3739
6f086dfc
RS
3740 /* If the reg that the virtual arg pointer will be translated into is
3741 not a fixed reg or is the stack pointer, make a copy of the virtual
3742 arg pointer, and address parms via the copy. The frame pointer is
3743 considered fixed even though it is not marked as such.
3744
3745 The second time through, simply use ap to avoid generating rtx. */
3746
3747 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
3748 || ! (fixed_regs[ARG_POINTER_REGNUM]
3749 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM))
3750 && ! second_time)
3751 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
3752 else
3753 internal_arg_pointer = virtual_incoming_args_rtx;
3754 current_function_internal_arg_pointer = internal_arg_pointer;
3755
3756 stack_args_size.constant = 0;
3757 stack_args_size.var = 0;
3758
3759 /* If struct value address is treated as the first argument, make it so. */
3760 if (aggregate_value_p (DECL_RESULT (fndecl))
3761 && ! current_function_returns_pcc_struct
3762 && struct_value_incoming_rtx == 0)
3763 {
f9f29478 3764 tree type = build_pointer_type (TREE_TYPE (fntype));
6f086dfc 3765
5f4f0e22 3766 function_result_decl = build_decl (PARM_DECL, NULL_TREE, type);
6f086dfc
RS
3767
3768 DECL_ARG_TYPE (function_result_decl) = type;
3769 TREE_CHAIN (function_result_decl) = fnargs;
3770 fnargs = function_result_decl;
3771 }
3772
e9a25f70
JL
3773 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
3774 parm_reg_stack_loc = (rtx *) savealloc (max_parm_reg * sizeof (rtx));
3775 bzero ((char *) parm_reg_stack_loc, max_parm_reg * sizeof (rtx));
6f086dfc
RS
3776
3777#ifdef INIT_CUMULATIVE_INCOMING_ARGS
ea0d4c4b 3778 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX);
6f086dfc 3779#else
2c7ee1a6 3780 INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX, 0);
6f086dfc
RS
3781#endif
3782
3783 /* We haven't yet found an argument that we must push and pretend the
3784 caller did. */
3785 current_function_pretend_args_size = 0;
3786
3787 for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
3788 {
05e3bdb9 3789 int aggregate = AGGREGATE_TYPE_P (TREE_TYPE (parm));
6f086dfc
RS
3790 struct args_size stack_offset;
3791 struct args_size arg_size;
3792 int passed_pointer = 0;
621061f4 3793 int did_conversion = 0;
6f086dfc 3794 tree passed_type = DECL_ARG_TYPE (parm);
621061f4 3795 tree nominal_type = TREE_TYPE (parm);
6f086dfc
RS
3796
3797 /* Set LAST_NAMED if this is last named arg before some
bf9c83fe 3798 anonymous args. */
6f086dfc
RS
3799 int last_named = ((TREE_CHAIN (parm) == 0
3800 || DECL_NAME (TREE_CHAIN (parm)) == 0)
3b69d50e 3801 && (stdarg || current_function_varargs));
bf9c83fe
JW
3802 /* Set NAMED_ARG if this arg should be treated as a named arg. For
3803 most machines, if this is a varargs/stdarg function, then we treat
3804 the last named arg as if it were anonymous too. */
e5e809f4 3805 int named_arg = STRICT_ARGUMENT_NAMING ? 1 : ! last_named;
6f086dfc
RS
3806
3807 if (TREE_TYPE (parm) == error_mark_node
3808 /* This can happen after weird syntax errors
3809 or if an enum type is defined among the parms. */
3810 || TREE_CODE (parm) != PARM_DECL
3811 || passed_type == NULL)
3812 {
38a448ca
RH
3813 DECL_INCOMING_RTL (parm) = DECL_RTL (parm)
3814 = gen_rtx_MEM (BLKmode, const0_rtx);
6f086dfc
RS
3815 TREE_USED (parm) = 1;
3816 continue;
3817 }
3818
3819 /* For varargs.h function, save info about regs and stack space
3820 used by the individual args, not including the va_alist arg. */
3b69d50e 3821 if (hide_last_arg && last_named)
6f086dfc
RS
3822 current_function_args_info = args_so_far;
3823
3824 /* Find mode of arg as it is passed, and mode of arg
3825 as it should be during execution of this function. */
3826 passed_mode = TYPE_MODE (passed_type);
621061f4 3827 nominal_mode = TYPE_MODE (nominal_type);
6f086dfc 3828
16bae307
RS
3829 /* If the parm's mode is VOID, its value doesn't matter,
3830 and avoid the usual things like emit_move_insn that could crash. */
3831 if (nominal_mode == VOIDmode)
3832 {
3833 DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = const0_rtx;
3834 continue;
3835 }
3836
3f46679a
RK
3837 /* If the parm is to be passed as a transparent union, use the
3838 type of the first field for the tests below. We have already
3839 verified that the modes are the same. */
3840 if (DECL_TRANSPARENT_UNION (parm)
3841 || TYPE_TRANSPARENT_UNION (passed_type))
3842 passed_type = TREE_TYPE (TYPE_FIELDS (passed_type));
3843
a14ae508
RK
3844 /* See if this arg was passed by invisible reference. It is if
3845 it is an object whose size depends on the contents of the
3846 object itself or if the machine requires these objects be passed
3847 that way. */
3848
3849 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
3850 && contains_placeholder_p (TYPE_SIZE (passed_type)))
657bb6dc 3851 || TREE_ADDRESSABLE (passed_type)
6f086dfc 3852#ifdef FUNCTION_ARG_PASS_BY_REFERENCE
a14ae508 3853 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode,
bf9c83fe 3854 passed_type, named_arg)
a14ae508
RK
3855#endif
3856 )
6f086dfc 3857 {
621061f4 3858 passed_type = nominal_type = build_pointer_type (passed_type);
6f086dfc
RS
3859 passed_pointer = 1;
3860 passed_mode = nominal_mode = Pmode;
3861 }
6f086dfc 3862
a53e14c0
RK
3863 promoted_mode = passed_mode;
3864
3865#ifdef PROMOTE_FUNCTION_ARGS
3866 /* Compute the mode in which the arg is actually extended to. */
7940255d 3867 unsignedp = TREE_UNSIGNED (passed_type);
a5a52dbc 3868 promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1);
a53e14c0
RK
3869#endif
3870
6f086dfc
RS
3871 /* Let machine desc say which reg (if any) the parm arrives in.
3872 0 means it arrives on the stack. */
3873#ifdef FUNCTION_INCOMING_ARG
a53e14c0 3874 entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
bf9c83fe 3875 passed_type, named_arg);
6f086dfc 3876#else
a53e14c0 3877 entry_parm = FUNCTION_ARG (args_so_far, promoted_mode,
bf9c83fe 3878 passed_type, named_arg);
6f086dfc
RS
3879#endif
3880
621061f4
RK
3881 if (entry_parm == 0)
3882 promoted_mode = passed_mode;
a53e14c0 3883
6f086dfc
RS
3884#ifdef SETUP_INCOMING_VARARGS
3885 /* If this is the last named parameter, do any required setup for
3886 varargs or stdargs. We need to know about the case of this being an
3887 addressable type, in which case we skip the registers it
3888 would have arrived in.
3889
3890 For stdargs, LAST_NAMED will be set for two parameters, the one that
3891 is actually the last named, and the dummy parameter. We only
3892 want to do this action once.
3893
3894 Also, indicate when RTL generation is to be suppressed. */
3895 if (last_named && !varargs_setup)
3896 {
621061f4 3897 SETUP_INCOMING_VARARGS (args_so_far, promoted_mode, passed_type,
6f086dfc
RS
3898 current_function_pretend_args_size,
3899 second_time);
3900 varargs_setup = 1;
3901 }
3902#endif
3903
3904 /* Determine parm's home in the stack,
3905 in case it arrives in the stack or we should pretend it did.
3906
3907 Compute the stack position and rtx where the argument arrives
3908 and its size.
3909
3910 There is one complexity here: If this was a parameter that would
3911 have been passed in registers, but wasn't only because it is
3912 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
3913 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
3914 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
3915 0 as it was the previous time. */
3916
621061f4 3917 locate_and_pad_parm (promoted_mode, passed_type,
6f086dfc
RS
3918#ifdef STACK_PARMS_IN_REG_PARM_AREA
3919 1,
3920#else
3921#ifdef FUNCTION_INCOMING_ARG
621061f4 3922 FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
6f086dfc 3923 passed_type,
bf9c83fe 3924 (named_arg
6f086dfc
RS
3925 || varargs_setup)) != 0,
3926#else
621061f4 3927 FUNCTION_ARG (args_so_far, promoted_mode,
6f086dfc 3928 passed_type,
bf9c83fe 3929 named_arg || varargs_setup) != 0,
6f086dfc
RS
3930#endif
3931#endif
3932 fndecl, &stack_args_size, &stack_offset, &arg_size);
3933
3934 if (! second_time)
3935 {
3936 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
3937
3938 if (offset_rtx == const0_rtx)
38a448ca 3939 stack_parm = gen_rtx_MEM (promoted_mode, internal_arg_pointer);
6f086dfc 3940 else
38a448ca
RH
3941 stack_parm = gen_rtx_MEM (promoted_mode,
3942 gen_rtx_PLUS (Pmode,
3943 internal_arg_pointer,
3944 offset_rtx));
6f086dfc
RS
3945
3946 /* If this is a memory ref that contains aggregate components,
a00285d0
RK
3947 mark it as such for cse and loop optimize. Likewise if it
3948 is readonly. */
6f086dfc 3949 MEM_IN_STRUCT_P (stack_parm) = aggregate;
a00285d0 3950 RTX_UNCHANGING_P (stack_parm) = TREE_READONLY (parm);
41472af8 3951 MEM_ALIAS_SET (stack_parm) = get_alias_set (parm);
6f086dfc
RS
3952 }
3953
3954 /* If this parameter was passed both in registers and in the stack,
3955 use the copy on the stack. */
621061f4 3956 if (MUST_PASS_IN_STACK (promoted_mode, passed_type))
6f086dfc
RS
3957 entry_parm = 0;
3958
461beb10 3959#ifdef FUNCTION_ARG_PARTIAL_NREGS
6f086dfc
RS
3960 /* If this parm was passed part in regs and part in memory,
3961 pretend it arrived entirely in memory
3962 by pushing the register-part onto the stack.
3963
3964 In the special case of a DImode or DFmode that is split,
3965 we could put it together in a pseudoreg directly,
3966 but for now that's not worth bothering with. */
3967
3968 if (entry_parm)
3969 {
621061f4 3970 int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, promoted_mode,
bf9c83fe 3971 passed_type, named_arg);
6f086dfc
RS
3972
3973 if (nregs > 0)
3974 {
3975 current_function_pretend_args_size
3976 = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
3977 / (PARM_BOUNDARY / BITS_PER_UNIT)
3978 * (PARM_BOUNDARY / BITS_PER_UNIT));
3979
3980 if (! second_time)
5c4cdc9f
JW
3981 {
3982 /* Handle calls that pass values in multiple non-contiguous
3983 locations. The Irix 6 ABI has examples of this. */
3984 if (GET_CODE (entry_parm) == PARALLEL)
aac5cc16
RH
3985 emit_group_store (validize_mem (stack_parm), entry_parm,
3986 int_size_in_bytes (TREE_TYPE (parm)),
3987 (TYPE_ALIGN (TREE_TYPE (parm))
3988 / BITS_PER_UNIT));
5c4cdc9f
JW
3989 else
3990 move_block_from_reg (REGNO (entry_parm),
3991 validize_mem (stack_parm), nregs,
3992 int_size_in_bytes (TREE_TYPE (parm)));
3993 }
6f086dfc
RS
3994 entry_parm = stack_parm;
3995 }
3996 }
461beb10 3997#endif
6f086dfc
RS
3998
3999 /* If we didn't decide this parm came in a register,
4000 by default it came on the stack. */
4001 if (entry_parm == 0)
4002 entry_parm = stack_parm;
4003
4004 /* Record permanently how this parm was passed. */
4005 if (! second_time)
4006 DECL_INCOMING_RTL (parm) = entry_parm;
4007
4008 /* If there is actually space on the stack for this parm,
4009 count it in stack_args_size; otherwise set stack_parm to 0
4010 to indicate there is no preallocated stack slot for the parm. */
4011
4012 if (entry_parm == stack_parm
d9ca49d5 4013#if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
6f086dfc 4014 /* On some machines, even if a parm value arrives in a register
d9ca49d5
JW
4015 there is still an (uninitialized) stack slot allocated for it.
4016
4017 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
4018 whether this parameter already has a stack slot allocated,
4019 because an arg block exists only if current_function_args_size
abc95ed3 4020 is larger than some threshold, and we haven't calculated that
d9ca49d5
JW
4021 yet. So, for now, we just assume that stack slots never exist
4022 in this case. */
6f086dfc
RS
4023 || REG_PARM_STACK_SPACE (fndecl) > 0
4024#endif
4025 )
4026 {
4027 stack_args_size.constant += arg_size.constant;
4028 if (arg_size.var)
4029 ADD_PARM_SIZE (stack_args_size, arg_size.var);
4030 }
4031 else
4032 /* No stack slot was pushed for this parm. */
4033 stack_parm = 0;
4034
4035 /* Update info on where next arg arrives in registers. */
4036
621061f4 4037 FUNCTION_ARG_ADVANCE (args_so_far, promoted_mode,
bf9c83fe 4038 passed_type, named_arg);
6f086dfc 4039
0f41302f 4040 /* If this is our second time through, we are done with this parm. */
6f086dfc
RS
4041 if (second_time)
4042 continue;
4043
e16c591a
RS
4044 /* If we can't trust the parm stack slot to be aligned enough
4045 for its ultimate type, don't use that slot after entry.
4046 We'll make another stack slot, if we need one. */
4047 {
e16c591a 4048 int thisparm_boundary
621061f4 4049 = FUNCTION_ARG_BOUNDARY (promoted_mode, passed_type);
e16c591a
RS
4050
4051 if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary)
4052 stack_parm = 0;
4053 }
4054
cb61f66f
RS
4055 /* If parm was passed in memory, and we need to convert it on entry,
4056 don't store it back in that same slot. */
4057 if (entry_parm != 0
4058 && nominal_mode != BLKmode && nominal_mode != passed_mode)
4059 stack_parm = 0;
4060
4061#if 0
6f086dfc
RS
4062 /* Now adjust STACK_PARM to the mode and precise location
4063 where this parameter should live during execution,
4064 if we discover that it must live in the stack during execution.
4065 To make debuggers happier on big-endian machines, we store
4066 the value in the last bytes of the space available. */
4067
4068 if (nominal_mode != BLKmode && nominal_mode != passed_mode
4069 && stack_parm != 0)
4070 {
4071 rtx offset_rtx;
4072
f76b9db2
ILT
4073 if (BYTES_BIG_ENDIAN
4074 && GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD)
6f086dfc
RS
4075 stack_offset.constant += (GET_MODE_SIZE (passed_mode)
4076 - GET_MODE_SIZE (nominal_mode));
6f086dfc
RS
4077
4078 offset_rtx = ARGS_SIZE_RTX (stack_offset);
4079 if (offset_rtx == const0_rtx)
38a448ca 4080 stack_parm = gen_rtx_MEM (nominal_mode, internal_arg_pointer);
6f086dfc 4081 else
38a448ca
RH
4082 stack_parm = gen_rtx_MEM (nominal_mode,
4083 gen_rtx_PLUS (Pmode,
4084 internal_arg_pointer,
4085 offset_rtx));
6f086dfc
RS
4086
4087 /* If this is a memory ref that contains aggregate components,
4088 mark it as such for cse and loop optimize. */
4089 MEM_IN_STRUCT_P (stack_parm) = aggregate;
4090 }
cb61f66f 4091#endif /* 0 */
6f086dfc 4092
9dc0f531
RK
4093#ifdef STACK_REGS
4094 /* We need this "use" info, because the gcc-register->stack-register
4095 converter in reg-stack.c needs to know which registers are active
4096 at the start of the function call. The actual parameter loading
4097 instructions are not always available then anymore, since they might
4098 have been optimised away. */
4099
4100 if (GET_CODE (entry_parm) == REG && !(hide_last_arg && last_named))
38a448ca 4101 emit_insn (gen_rtx_USE (GET_MODE (entry_parm), entry_parm));
9dc0f531
RK
4102#endif
4103
6f086dfc
RS
4104 /* ENTRY_PARM is an RTX for the parameter as it arrives,
4105 in the mode in which it arrives.
4106 STACK_PARM is an RTX for a stack slot where the parameter can live
4107 during the function (in case we want to put it there).
4108 STACK_PARM is 0 if no stack slot was pushed for it.
4109
4110 Now output code if necessary to convert ENTRY_PARM to
4111 the type in which this function declares it,
4112 and store that result in an appropriate place,
4113 which may be a pseudo reg, may be STACK_PARM,
4114 or may be a local stack slot if STACK_PARM is 0.
4115
4116 Set DECL_RTL to that place. */
4117
5c4cdc9f 4118 if (nominal_mode == BLKmode || GET_CODE (entry_parm) == PARALLEL)
6f086dfc 4119 {
5c4cdc9f
JW
4120 /* If a BLKmode arrives in registers, copy it to a stack slot.
4121 Handle calls that pass values in multiple non-contiguous
4122 locations. The Irix 6 ABI has examples of this. */
4123 if (GET_CODE (entry_parm) == REG
4124 || GET_CODE (entry_parm) == PARALLEL)
6f086dfc 4125 {
621061f4
RK
4126 int size_stored
4127 = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)),
4128 UNITS_PER_WORD);
6f086dfc
RS
4129
4130 /* Note that we will be storing an integral number of words.
4131 So we have to be careful to ensure that we allocate an
4132 integral number of words. We do this below in the
4133 assign_stack_local if space was not allocated in the argument
4134 list. If it was, this will not work if PARM_BOUNDARY is not
4135 a multiple of BITS_PER_WORD. It isn't clear how to fix this
4136 if it becomes a problem. */
4137
4138 if (stack_parm == 0)
7e41ffa2
RS
4139 {
4140 stack_parm
621061f4
RK
4141 = assign_stack_local (GET_MODE (entry_parm),
4142 size_stored, 0);
4143
4144 /* If this is a memory ref that contains aggregate
4145 components, mark it as such for cse and loop optimize. */
7e41ffa2
RS
4146 MEM_IN_STRUCT_P (stack_parm) = aggregate;
4147 }
4148
6f086dfc
RS
4149 else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
4150 abort ();
4151
7a30f0c4
JW
4152 if (TREE_READONLY (parm))
4153 RTX_UNCHANGING_P (stack_parm) = 1;
4154
5c4cdc9f
JW
4155 /* Handle calls that pass values in multiple non-contiguous
4156 locations. The Irix 6 ABI has examples of this. */
4157 if (GET_CODE (entry_parm) == PARALLEL)
aac5cc16
RH
4158 emit_group_store (validize_mem (stack_parm), entry_parm,
4159 int_size_in_bytes (TREE_TYPE (parm)),
4160 (TYPE_ALIGN (TREE_TYPE (parm))
4161 / BITS_PER_UNIT));
5c4cdc9f
JW
4162 else
4163 move_block_from_reg (REGNO (entry_parm),
4164 validize_mem (stack_parm),
4165 size_stored / UNITS_PER_WORD,
4166 int_size_in_bytes (TREE_TYPE (parm)));
6f086dfc
RS
4167 }
4168 DECL_RTL (parm) = stack_parm;
4169 }
74bd77a8 4170 else if (! ((obey_regdecls && ! DECL_REGISTER (parm)
a82ad570 4171 && ! DECL_INLINE (fndecl))
6f086dfc
RS
4172 /* layout_decl may set this. */
4173 || TREE_ADDRESSABLE (parm)
4174 || TREE_SIDE_EFFECTS (parm)
4175 /* If -ffloat-store specified, don't put explicit
4176 float variables into registers. */
4177 || (flag_float_store
4178 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
4179 /* Always assign pseudo to structure return or item passed
4180 by invisible reference. */
4181 || passed_pointer || parm == function_result_decl)
4182 {
00d8a4c1
RK
4183 /* Store the parm in a pseudoregister during the function, but we
4184 may need to do it in a wider mode. */
4185
4186 register rtx parmreg;
4e86caed 4187 int regno, regnoi = 0, regnor = 0;
00d8a4c1
RK
4188
4189 unsignedp = TREE_UNSIGNED (TREE_TYPE (parm));
cd5b3469 4190
621061f4
RK
4191 promoted_nominal_mode
4192 = promote_mode (TREE_TYPE (parm), nominal_mode, &unsignedp, 0);
6f086dfc 4193
621061f4 4194 parmreg = gen_reg_rtx (promoted_nominal_mode);
ddb7361a 4195 mark_user_reg (parmreg);
6f086dfc
RS
4196
4197 /* If this was an item that we received a pointer to, set DECL_RTL
4198 appropriately. */
4199 if (passed_pointer)
4200 {
621061f4 4201 DECL_RTL (parm)
38a448ca 4202 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (passed_type)), parmreg);
6f086dfc
RS
4203 MEM_IN_STRUCT_P (DECL_RTL (parm)) = aggregate;
4204 }
4205 else
4206 DECL_RTL (parm) = parmreg;
4207
4208 /* Copy the value into the register. */
621061f4
RK
4209 if (nominal_mode != passed_mode
4210 || promoted_nominal_mode != promoted_mode)
86f8eff3 4211 {
621061f4
RK
4212 /* ENTRY_PARM has been converted to PROMOTED_MODE, its
4213 mode, by the caller. We now have to convert it to
4214 NOMINAL_MODE, if different. However, PARMREG may be in
956d6950 4215 a different mode than NOMINAL_MODE if it is being stored
621061f4
RK
4216 promoted.
4217
4218 If ENTRY_PARM is a hard register, it might be in a register
86f8eff3
RK
4219 not valid for operating in its mode (e.g., an odd-numbered
4220 register for a DFmode). In that case, moves are the only
4221 thing valid, so we can't do a convert from there. This
4222 occurs when the calling sequence allow such misaligned
3412b298
JW
4223 usages.
4224
4225 In addition, the conversion may involve a call, which could
4226 clobber parameters which haven't been copied to pseudo
4227 registers yet. Therefore, we must first copy the parm to
4228 a pseudo reg here, and save the conversion until after all
4229 parameters have been moved. */
4230
4231 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
4232
4233 emit_move_insn (tempreg, validize_mem (entry_parm));
4234
4235 push_to_sequence (conversion_insns);
ad241351
RK
4236 tempreg = convert_to_mode (nominal_mode, tempreg, unsignedp);
4237
621061f4
RK
4238 expand_assignment (parm,
4239 make_tree (nominal_type, tempreg), 0, 0);
3412b298 4240 conversion_insns = get_insns ();
621061f4 4241 did_conversion = 1;
3412b298 4242 end_sequence ();
86f8eff3 4243 }
6f086dfc
RS
4244 else
4245 emit_move_insn (parmreg, validize_mem (entry_parm));
4246
74bd77a8
RS
4247 /* If we were passed a pointer but the actual value
4248 can safely live in a register, put it in one. */
16bae307 4249 if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
74bd77a8
RS
4250 && ! ((obey_regdecls && ! DECL_REGISTER (parm)
4251 && ! DECL_INLINE (fndecl))
4252 /* layout_decl may set this. */
4253 || TREE_ADDRESSABLE (parm)
4254 || TREE_SIDE_EFFECTS (parm)
4255 /* If -ffloat-store specified, don't put explicit
4256 float variables into registers. */
4257 || (flag_float_store
4258 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))
4259 {
2654605a
JW
4260 /* We can't use nominal_mode, because it will have been set to
4261 Pmode above. We must use the actual mode of the parm. */
4262 parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
ddb7361a 4263 mark_user_reg (parmreg);
74bd77a8
RS
4264 emit_move_insn (parmreg, DECL_RTL (parm));
4265 DECL_RTL (parm) = parmreg;
c110c53d
RS
4266 /* STACK_PARM is the pointer, not the parm, and PARMREG is
4267 now the parm. */
4268 stack_parm = 0;
74bd77a8 4269 }
137a2a7b
DE
4270#ifdef FUNCTION_ARG_CALLEE_COPIES
4271 /* If we are passed an arg by reference and it is our responsibility
4272 to make a copy, do it now.
4273 PASSED_TYPE and PASSED mode now refer to the pointer, not the
4274 original argument, so we must recreate them in the call to
4275 FUNCTION_ARG_CALLEE_COPIES. */
4276 /* ??? Later add code to handle the case that if the argument isn't
4277 modified, don't do the copy. */
4278
4279 else if (passed_pointer
4280 && FUNCTION_ARG_CALLEE_COPIES (args_so_far,
4281 TYPE_MODE (DECL_ARG_TYPE (parm)),
4282 DECL_ARG_TYPE (parm),
bf9c83fe 4283 named_arg)
926b1b99 4284 && ! TREE_ADDRESSABLE (DECL_ARG_TYPE (parm)))
137a2a7b
DE
4285 {
4286 rtx copy;
4287 tree type = DECL_ARG_TYPE (parm);
4288
4289 /* This sequence may involve a library call perhaps clobbering
4290 registers that haven't been copied to pseudos yet. */
4291
4292 push_to_sequence (conversion_insns);
4293
4294 if (TYPE_SIZE (type) == 0
4295 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1fd3ef7f 4296 /* This is a variable sized object. */
38a448ca
RH
4297 copy = gen_rtx_MEM (BLKmode,
4298 allocate_dynamic_stack_space
4299 (expr_size (parm), NULL_RTX,
4300 TYPE_ALIGN (type)));
137a2a7b 4301 else
1fd3ef7f
RK
4302 copy = assign_stack_temp (TYPE_MODE (type),
4303 int_size_in_bytes (type), 1);
3668e76e 4304 MEM_IN_STRUCT_P (copy) = AGGREGATE_TYPE_P (type);
e9a25f70 4305 RTX_UNCHANGING_P (copy) = TREE_READONLY (parm);
137a2a7b
DE
4306
4307 store_expr (parm, copy, 0);
4308 emit_move_insn (parmreg, XEXP (copy, 0));
86fa911a
RK
4309 if (flag_check_memory_usage)
4310 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
4311 XEXP (copy, 0), ptr_mode,
4312 GEN_INT (int_size_in_bytes (type)),
4313 TYPE_MODE (sizetype),
956d6950
JL
4314 GEN_INT (MEMORY_USE_RW),
4315 TYPE_MODE (integer_type_node));
137a2a7b 4316 conversion_insns = get_insns ();
621061f4 4317 did_conversion = 1;
137a2a7b
DE
4318 end_sequence ();
4319 }
4320#endif /* FUNCTION_ARG_CALLEE_COPIES */
74bd77a8 4321
6f086dfc 4322 /* In any case, record the parm's desired stack location
14aceb29
RS
4323 in case we later discover it must live in the stack.
4324
4325 If it is a COMPLEX value, store the stack location for both
4326 halves. */
4327
4328 if (GET_CODE (parmreg) == CONCAT)
4329 regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1)));
4330 else
4331 regno = REGNO (parmreg);
4332
e9a25f70 4333 if (regno >= max_parm_reg)
6f086dfc
RS
4334 {
4335 rtx *new;
e9a25f70 4336 int old_max_parm_reg = max_parm_reg;
14aceb29 4337
e9a25f70
JL
4338 /* It's slow to expand this one register at a time,
4339 but it's also rare and we need max_parm_reg to be
4340 precisely correct. */
4341 max_parm_reg = regno + 1;
4342 new = (rtx *) savealloc (max_parm_reg * sizeof (rtx));
4c9a05bc 4343 bcopy ((char *) parm_reg_stack_loc, (char *) new,
e9a25f70
JL
4344 old_max_parm_reg * sizeof (rtx));
4345 bzero ((char *) (new + old_max_parm_reg),
4346 (max_parm_reg - old_max_parm_reg) * sizeof (rtx));
6f086dfc
RS
4347 parm_reg_stack_loc = new;
4348 }
14aceb29
RS
4349
4350 if (GET_CODE (parmreg) == CONCAT)
4351 {
4352 enum machine_mode submode = GET_MODE (XEXP (parmreg, 0));
4353
a03caf76
RK
4354 regnor = REGNO (gen_realpart (submode, parmreg));
4355 regnoi = REGNO (gen_imagpart (submode, parmreg));
4356
7b1a0c14
RS
4357 if (stack_parm != 0)
4358 {
a03caf76 4359 parm_reg_stack_loc[regnor]
3d329b07 4360 = gen_realpart (submode, stack_parm);
a03caf76 4361 parm_reg_stack_loc[regnoi]
3d329b07 4362 = gen_imagpart (submode, stack_parm);
7b1a0c14
RS
4363 }
4364 else
4365 {
a03caf76
RK
4366 parm_reg_stack_loc[regnor] = 0;
4367 parm_reg_stack_loc[regnoi] = 0;
7b1a0c14 4368 }
14aceb29
RS
4369 }
4370 else
4371 parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
6f086dfc
RS
4372
4373 /* Mark the register as eliminable if we did no conversion
4374 and it was copied from memory at a fixed offset,
4375 and the arg pointer was not copied to a pseudo-reg.
4376 If the arg pointer is a pseudo reg or the offset formed
4377 an invalid address, such memory-equivalences
4378 as we make here would screw up life analysis for it. */
4379 if (nominal_mode == passed_mode
621061f4 4380 && ! did_conversion
38b610ed
ILT
4381 && stack_parm != 0
4382 && GET_CODE (stack_parm) == MEM
6f086dfc
RS
4383 && stack_offset.var == 0
4384 && reg_mentioned_p (virtual_incoming_args_rtx,
38b610ed 4385 XEXP (stack_parm, 0)))
a03caf76
RK
4386 {
4387 rtx linsn = get_last_insn ();
69685820 4388 rtx sinsn, set;
a03caf76
RK
4389
4390 /* Mark complex types separately. */
4391 if (GET_CODE (parmreg) == CONCAT)
69685820
RK
4392 /* Scan backwards for the set of the real and
4393 imaginary parts. */
4394 for (sinsn = linsn; sinsn != 0;
4395 sinsn = prev_nonnote_insn (sinsn))
4396 {
4397 set = single_set (sinsn);
4398 if (set != 0
4399 && SET_DEST (set) == regno_reg_rtx [regnoi])
4400 REG_NOTES (sinsn)
38a448ca
RH
4401 = gen_rtx_EXPR_LIST (REG_EQUIV,
4402 parm_reg_stack_loc[regnoi],
4403 REG_NOTES (sinsn));
69685820
RK
4404 else if (set != 0
4405 && SET_DEST (set) == regno_reg_rtx [regnor])
4406 REG_NOTES (sinsn)
38a448ca
RH
4407 = gen_rtx_EXPR_LIST (REG_EQUIV,
4408 parm_reg_stack_loc[regnor],
4409 REG_NOTES (sinsn));
69685820
RK
4410 }
4411 else if ((set = single_set (linsn)) != 0
4412 && SET_DEST (set) == parmreg)
a03caf76 4413 REG_NOTES (linsn)
38a448ca
RH
4414 = gen_rtx_EXPR_LIST (REG_EQUIV,
4415 stack_parm, REG_NOTES (linsn));
a03caf76 4416 }
6f086dfc
RS
4417
4418 /* For pointer data type, suggest pointer register. */
e5e809f4 4419 if (POINTER_TYPE_P (TREE_TYPE (parm)))
6c6166bd
RK
4420 mark_reg_pointer (parmreg,
4421 (TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm)))
4422 / BITS_PER_UNIT));
6f086dfc
RS
4423 }
4424 else
4425 {
4426 /* Value must be stored in the stack slot STACK_PARM
4427 during function execution. */
4428
621061f4 4429 if (promoted_mode != nominal_mode)
86f8eff3
RK
4430 {
4431 /* Conversion is required. */
3412b298
JW
4432 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
4433
4434 emit_move_insn (tempreg, validize_mem (entry_parm));
86f8eff3 4435
3412b298
JW
4436 push_to_sequence (conversion_insns);
4437 entry_parm = convert_to_mode (nominal_mode, tempreg,
a53e14c0 4438 TREE_UNSIGNED (TREE_TYPE (parm)));
de957303
DE
4439 if (stack_parm)
4440 {
4441 /* ??? This may need a big-endian conversion on sparc64. */
4442 stack_parm = change_address (stack_parm, nominal_mode,
4443 NULL_RTX);
4444 }
3412b298 4445 conversion_insns = get_insns ();
621061f4 4446 did_conversion = 1;
3412b298 4447 end_sequence ();
86f8eff3 4448 }
6f086dfc
RS
4449
4450 if (entry_parm != stack_parm)
4451 {
4452 if (stack_parm == 0)
7e41ffa2
RS
4453 {
4454 stack_parm
4455 = assign_stack_local (GET_MODE (entry_parm),
4456 GET_MODE_SIZE (GET_MODE (entry_parm)), 0);
4457 /* If this is a memory ref that contains aggregate components,
4458 mark it as such for cse and loop optimize. */
4459 MEM_IN_STRUCT_P (stack_parm) = aggregate;
4460 }
4461
621061f4 4462 if (promoted_mode != nominal_mode)
3412b298
JW
4463 {
4464 push_to_sequence (conversion_insns);
4465 emit_move_insn (validize_mem (stack_parm),
4466 validize_mem (entry_parm));
4467 conversion_insns = get_insns ();
4468 end_sequence ();
4469 }
4470 else
4471 emit_move_insn (validize_mem (stack_parm),
4472 validize_mem (entry_parm));
6f086dfc 4473 }
e5e809f4 4474 if (flag_check_memory_usage)
86fa911a
RK
4475 {
4476 push_to_sequence (conversion_insns);
4477 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
4478 XEXP (stack_parm, 0), ptr_mode,
4479 GEN_INT (GET_MODE_SIZE (GET_MODE
4480 (entry_parm))),
4481 TYPE_MODE (sizetype),
956d6950
JL
4482 GEN_INT (MEMORY_USE_RW),
4483 TYPE_MODE (integer_type_node));
6f086dfc 4484
86fa911a
RK
4485 conversion_insns = get_insns ();
4486 end_sequence ();
4487 }
6f086dfc
RS
4488 DECL_RTL (parm) = stack_parm;
4489 }
4490
4491 /* If this "parameter" was the place where we are receiving the
4492 function's incoming structure pointer, set up the result. */
4493 if (parm == function_result_decl)
ccdecf58
RK
4494 {
4495 tree result = DECL_RESULT (fndecl);
4496 tree restype = TREE_TYPE (result);
4497
4498 DECL_RTL (result)
38a448ca 4499 = gen_rtx_MEM (DECL_MODE (result), DECL_RTL (parm));
ccdecf58 4500
05e3bdb9 4501 MEM_IN_STRUCT_P (DECL_RTL (result)) = AGGREGATE_TYPE_P (restype);
ccdecf58 4502 }
6f086dfc
RS
4503
4504 if (TREE_THIS_VOLATILE (parm))
4505 MEM_VOLATILE_P (DECL_RTL (parm)) = 1;
4506 if (TREE_READONLY (parm))
4507 RTX_UNCHANGING_P (DECL_RTL (parm)) = 1;
4508 }
4509
3412b298
JW
4510 /* Output all parameter conversion instructions (possibly including calls)
4511 now that all parameters have been copied out of hard registers. */
4512 emit_insns (conversion_insns);
4513
6f086dfc
RS
4514 last_parm_insn = get_last_insn ();
4515
4516 current_function_args_size = stack_args_size.constant;
4517
4518 /* Adjust function incoming argument size for alignment and
4519 minimum length. */
4520
4521#ifdef REG_PARM_STACK_SPACE
6f90e075 4522#ifndef MAYBE_REG_PARM_STACK_SPACE
6f086dfc
RS
4523 current_function_args_size = MAX (current_function_args_size,
4524 REG_PARM_STACK_SPACE (fndecl));
4525#endif
6f90e075 4526#endif
6f086dfc
RS
4527
4528#ifdef STACK_BOUNDARY
4529#define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
4530
4531 current_function_args_size
4532 = ((current_function_args_size + STACK_BYTES - 1)
4533 / STACK_BYTES) * STACK_BYTES;
4534#endif
4535
4536#ifdef ARGS_GROW_DOWNWARD
4537 current_function_arg_offset_rtx
5f4f0e22 4538 = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant)
6f086dfc
RS
4539 : expand_expr (size_binop (MINUS_EXPR, stack_args_size.var,
4540 size_int (-stack_args_size.constant)),
86fa911a 4541 NULL_RTX, VOIDmode, EXPAND_MEMORY_USE_BAD));
6f086dfc
RS
4542#else
4543 current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
4544#endif
4545
4546 /* See how many bytes, if any, of its args a function should try to pop
4547 on return. */
4548
64e6d9cc 4549 current_function_pops_args = RETURN_POPS_ARGS (fndecl, TREE_TYPE (fndecl),
6f086dfc
RS
4550 current_function_args_size);
4551
3b69d50e
RK
4552 /* For stdarg.h function, save info about
4553 regs and stack space used by the named args. */
6f086dfc 4554
3b69d50e 4555 if (!hide_last_arg)
6f086dfc
RS
4556 current_function_args_info = args_so_far;
4557
4558 /* Set the rtx used for the function return value. Put this in its
4559 own variable so any optimizers that need this information don't have
4560 to include tree.h. Do this here so it gets done when an inlined
4561 function gets output. */
4562
4563 current_function_return_rtx = DECL_RTL (DECL_RESULT (fndecl));
4564}
4565\f
75dc3319
RK
4566/* Indicate whether REGNO is an incoming argument to the current function
4567 that was promoted to a wider mode. If so, return the RTX for the
4568 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
4569 that REGNO is promoted from and whether the promotion was signed or
4570 unsigned. */
4571
4572#ifdef PROMOTE_FUNCTION_ARGS
4573
4574rtx
4575promoted_input_arg (regno, pmode, punsignedp)
4576 int regno;
4577 enum machine_mode *pmode;
4578 int *punsignedp;
4579{
4580 tree arg;
4581
4582 for (arg = DECL_ARGUMENTS (current_function_decl); arg;
4583 arg = TREE_CHAIN (arg))
4584 if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
621061f4
RK
4585 && REGNO (DECL_INCOMING_RTL (arg)) == regno
4586 && TYPE_MODE (DECL_ARG_TYPE (arg)) == TYPE_MODE (TREE_TYPE (arg)))
75dc3319
RK
4587 {
4588 enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
4589 int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
4590
a5a52dbc 4591 mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1);
75dc3319
RK
4592 if (mode == GET_MODE (DECL_INCOMING_RTL (arg))
4593 && mode != DECL_MODE (arg))
4594 {
4595 *pmode = DECL_MODE (arg);
4596 *punsignedp = unsignedp;
4597 return DECL_INCOMING_RTL (arg);
4598 }
4599 }
4600
4601 return 0;
4602}
4603
4604#endif
4605\f
6f086dfc
RS
4606/* Compute the size and offset from the start of the stacked arguments for a
4607 parm passed in mode PASSED_MODE and with type TYPE.
4608
4609 INITIAL_OFFSET_PTR points to the current offset into the stacked
4610 arguments.
4611
4612 The starting offset and size for this parm are returned in *OFFSET_PTR
4613 and *ARG_SIZE_PTR, respectively.
4614
4615 IN_REGS is non-zero if the argument will be passed in registers. It will
4616 never be set if REG_PARM_STACK_SPACE is not defined.
4617
4618 FNDECL is the function in which the argument was defined.
4619
4620 There are two types of rounding that are done. The first, controlled by
4621 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
4622 list to be aligned to the specific boundary (in bits). This rounding
4623 affects the initial and starting offsets, but not the argument size.
4624
4625 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
4626 optionally rounds the size of the parm to PARM_BOUNDARY. The
4627 initial offset is not affected by this rounding, while the size always
4628 is and the starting offset may be. */
4629
4630/* offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
4631 initial_offset_ptr is positive because locate_and_pad_parm's
4632 callers pass in the total size of args so far as
4633 initial_offset_ptr. arg_size_ptr is always positive.*/
4634
6f086dfc
RS
4635void
4636locate_and_pad_parm (passed_mode, type, in_regs, fndecl,
4637 initial_offset_ptr, offset_ptr, arg_size_ptr)
4638 enum machine_mode passed_mode;
4639 tree type;
4640 int in_regs;
4641 tree fndecl;
4642 struct args_size *initial_offset_ptr;
4643 struct args_size *offset_ptr;
4644 struct args_size *arg_size_ptr;
4645{
4646 tree sizetree
4647 = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
4648 enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
4649 int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
6f086dfc
RS
4650
4651#ifdef REG_PARM_STACK_SPACE
4652 /* If we have found a stack parm before we reach the end of the
4653 area reserved for registers, skip that area. */
4654 if (! in_regs)
4655 {
29a82058
JL
4656 int reg_parm_stack_space = 0;
4657
29008b51
JW
4658#ifdef MAYBE_REG_PARM_STACK_SPACE
4659 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
4660#else
6f086dfc 4661 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
29008b51 4662#endif
6f086dfc
RS
4663 if (reg_parm_stack_space > 0)
4664 {
4665 if (initial_offset_ptr->var)
4666 {
4667 initial_offset_ptr->var
4668 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
4669 size_int (reg_parm_stack_space));
4670 initial_offset_ptr->constant = 0;
4671 }
4672 else if (initial_offset_ptr->constant < reg_parm_stack_space)
4673 initial_offset_ptr->constant = reg_parm_stack_space;
4674 }
4675 }
4676#endif /* REG_PARM_STACK_SPACE */
4677
4678 arg_size_ptr->var = 0;
4679 arg_size_ptr->constant = 0;
4680
4681#ifdef ARGS_GROW_DOWNWARD
4682 if (initial_offset_ptr->var)
4683 {
4684 offset_ptr->constant = 0;
4685 offset_ptr->var = size_binop (MINUS_EXPR, integer_zero_node,
4686 initial_offset_ptr->var);
4687 }
4688 else
4689 {
4690 offset_ptr->constant = - initial_offset_ptr->constant;
4691 offset_ptr->var = 0;
4692 }
0b21dcf5 4693 if (where_pad != none
6f086dfc
RS
4694 && (TREE_CODE (sizetree) != INTEGER_CST
4695 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
4696 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4697 SUB_PARM_SIZE (*offset_ptr, sizetree);
66bcbe19
TG
4698 if (where_pad != downward)
4699 pad_to_arg_alignment (offset_ptr, boundary);
6f086dfc
RS
4700 if (initial_offset_ptr->var)
4701 {
4702 arg_size_ptr->var = size_binop (MINUS_EXPR,
4703 size_binop (MINUS_EXPR,
4704 integer_zero_node,
4705 initial_offset_ptr->var),
4706 offset_ptr->var);
4707 }
4708 else
4709 {
db3cf6fb
MS
4710 arg_size_ptr->constant = (- initial_offset_ptr->constant
4711 - offset_ptr->constant);
6f086dfc 4712 }
6f086dfc
RS
4713#else /* !ARGS_GROW_DOWNWARD */
4714 pad_to_arg_alignment (initial_offset_ptr, boundary);
4715 *offset_ptr = *initial_offset_ptr;
6f086dfc
RS
4716
4717#ifdef PUSH_ROUNDING
4718 if (passed_mode != BLKmode)
4719 sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
4720#endif
4721
d4b0a7a0
DE
4722 /* Pad_below needs the pre-rounded size to know how much to pad below
4723 so this must be done before rounding up. */
ea5917da
DE
4724 if (where_pad == downward
4725 /* However, BLKmode args passed in regs have their padding done elsewhere.
4726 The stack slot must be able to hold the entire register. */
4727 && !(in_regs && passed_mode == BLKmode))
d4b0a7a0
DE
4728 pad_below (offset_ptr, passed_mode, sizetree);
4729
6f086dfc
RS
4730 if (where_pad != none
4731 && (TREE_CODE (sizetree) != INTEGER_CST
4732 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
4733 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4734
4735 ADD_PARM_SIZE (*arg_size_ptr, sizetree);
4736#endif /* ARGS_GROW_DOWNWARD */
4737}
4738
e16c591a
RS
4739/* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
4740 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
4741
6f086dfc
RS
4742static void
4743pad_to_arg_alignment (offset_ptr, boundary)
4744 struct args_size *offset_ptr;
4745 int boundary;
4746{
4747 int boundary_in_bytes = boundary / BITS_PER_UNIT;
4748
4749 if (boundary > BITS_PER_UNIT)
4750 {
4751 if (offset_ptr->var)
4752 {
4753 offset_ptr->var =
4754#ifdef ARGS_GROW_DOWNWARD
4755 round_down
4756#else
4757 round_up
4758#endif
4759 (ARGS_SIZE_TREE (*offset_ptr),
4760 boundary / BITS_PER_UNIT);
4761 offset_ptr->constant = 0; /*?*/
4762 }
4763 else
4764 offset_ptr->constant =
4765#ifdef ARGS_GROW_DOWNWARD
4766 FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes);
4767#else
4768 CEIL_ROUND (offset_ptr->constant, boundary_in_bytes);
4769#endif
4770 }
4771}
4772
51723711 4773#ifndef ARGS_GROW_DOWNWARD
6f086dfc
RS
4774static void
4775pad_below (offset_ptr, passed_mode, sizetree)
4776 struct args_size *offset_ptr;
4777 enum machine_mode passed_mode;
4778 tree sizetree;
4779{
4780 if (passed_mode != BLKmode)
4781 {
4782 if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
4783 offset_ptr->constant
4784 += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
4785 / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
4786 - GET_MODE_SIZE (passed_mode));
4787 }
4788 else
4789 {
4790 if (TREE_CODE (sizetree) != INTEGER_CST
4791 || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
4792 {
4793 /* Round the size up to multiple of PARM_BOUNDARY bits. */
4794 tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4795 /* Add it in. */
4796 ADD_PARM_SIZE (*offset_ptr, s2);
4797 SUB_PARM_SIZE (*offset_ptr, sizetree);
4798 }
4799 }
4800}
51723711 4801#endif
6f086dfc 4802
487a6e06 4803#ifdef ARGS_GROW_DOWNWARD
6f086dfc
RS
4804static tree
4805round_down (value, divisor)
4806 tree value;
4807 int divisor;
4808{
4809 return size_binop (MULT_EXPR,
4810 size_binop (FLOOR_DIV_EXPR, value, size_int (divisor)),
4811 size_int (divisor));
4812}
487a6e06 4813#endif
6f086dfc
RS
4814\f
4815/* Walk the tree of blocks describing the binding levels within a function
4816 and warn about uninitialized variables.
4817 This is done after calling flow_analysis and before global_alloc
4818 clobbers the pseudo-regs to hard regs. */
4819
4820void
4821uninitialized_vars_warning (block)
4822 tree block;
4823{
4824 register tree decl, sub;
4825 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
4826 {
4827 if (TREE_CODE (decl) == VAR_DECL
4828 /* These warnings are unreliable for and aggregates
4829 because assigning the fields one by one can fail to convince
4830 flow.c that the entire aggregate was initialized.
4831 Unions are troublesome because members may be shorter. */
05e3bdb9 4832 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl))
6f086dfc
RS
4833 && DECL_RTL (decl) != 0
4834 && GET_CODE (DECL_RTL (decl)) == REG
4835 && regno_uninitialized (REGNO (DECL_RTL (decl))))
4836 warning_with_decl (decl,
3c8cd8bd 4837 "`%s' might be used uninitialized in this function");
6f086dfc
RS
4838 if (TREE_CODE (decl) == VAR_DECL
4839 && DECL_RTL (decl) != 0
4840 && GET_CODE (DECL_RTL (decl)) == REG
4841 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
4842 warning_with_decl (decl,
3c8cd8bd 4843 "variable `%s' might be clobbered by `longjmp' or `vfork'");
6f086dfc
RS
4844 }
4845 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
4846 uninitialized_vars_warning (sub);
4847}
4848
4849/* Do the appropriate part of uninitialized_vars_warning
4850 but for arguments instead of local variables. */
4851
4852void
0cd6ef35 4853setjmp_args_warning ()
6f086dfc
RS
4854{
4855 register tree decl;
4856 for (decl = DECL_ARGUMENTS (current_function_decl);
4857 decl; decl = TREE_CHAIN (decl))
4858 if (DECL_RTL (decl) != 0
4859 && GET_CODE (DECL_RTL (decl)) == REG
4860 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
3c8cd8bd 4861 warning_with_decl (decl, "argument `%s' might be clobbered by `longjmp' or `vfork'");
6f086dfc
RS
4862}
4863
4864/* If this function call setjmp, put all vars into the stack
4865 unless they were declared `register'. */
4866
4867void
4868setjmp_protect (block)
4869 tree block;
4870{
4871 register tree decl, sub;
4872 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
4873 if ((TREE_CODE (decl) == VAR_DECL
4874 || TREE_CODE (decl) == PARM_DECL)
4875 && DECL_RTL (decl) != 0
e9a25f70
JL
4876 && (GET_CODE (DECL_RTL (decl)) == REG
4877 || (GET_CODE (DECL_RTL (decl)) == MEM
4878 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF))
b335c2cc 4879 /* If this variable came from an inline function, it must be
9ec36da5 4880 that its life doesn't overlap the setjmp. If there was a
b335c2cc
TW
4881 setjmp in the function, it would already be in memory. We
4882 must exclude such variable because their DECL_RTL might be
4883 set to strange things such as virtual_stack_vars_rtx. */
4884 && ! DECL_FROM_INLINE (decl)
6f086dfc
RS
4885 && (
4886#ifdef NON_SAVING_SETJMP
4887 /* If longjmp doesn't restore the registers,
4888 don't put anything in them. */
4889 NON_SAVING_SETJMP
4890 ||
4891#endif
a82ad570 4892 ! DECL_REGISTER (decl)))
6f086dfc
RS
4893 put_var_into_stack (decl);
4894 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
4895 setjmp_protect (sub);
4896}
4897\f
4898/* Like the previous function, but for args instead of local variables. */
4899
4900void
4901setjmp_protect_args ()
4902{
29a82058 4903 register tree decl;
6f086dfc
RS
4904 for (decl = DECL_ARGUMENTS (current_function_decl);
4905 decl; decl = TREE_CHAIN (decl))
4906 if ((TREE_CODE (decl) == VAR_DECL
4907 || TREE_CODE (decl) == PARM_DECL)
4908 && DECL_RTL (decl) != 0
e9a25f70
JL
4909 && (GET_CODE (DECL_RTL (decl)) == REG
4910 || (GET_CODE (DECL_RTL (decl)) == MEM
4911 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF))
6f086dfc
RS
4912 && (
4913 /* If longjmp doesn't restore the registers,
4914 don't put anything in them. */
4915#ifdef NON_SAVING_SETJMP
4916 NON_SAVING_SETJMP
4917 ||
4918#endif
a82ad570 4919 ! DECL_REGISTER (decl)))
6f086dfc
RS
4920 put_var_into_stack (decl);
4921}
4922\f
4923/* Return the context-pointer register corresponding to DECL,
4924 or 0 if it does not need one. */
4925
4926rtx
4927lookup_static_chain (decl)
4928 tree decl;
4929{
b001a02f
PB
4930 tree context = decl_function_context (decl);
4931 tree link;
7ad8c4bf 4932
38ee6ed9
JM
4933 if (context == 0
4934 || (TREE_CODE (decl) == FUNCTION_DECL && DECL_NO_STATIC_CHAIN (decl)))
7ad8c4bf 4935 return 0;
38ee6ed9 4936
6f086dfc
RS
4937 /* We treat inline_function_decl as an alias for the current function
4938 because that is the inline function whose vars, types, etc.
4939 are being merged into the current function.
4940 See expand_inline_function. */
4941 if (context == current_function_decl || context == inline_function_decl)
4942 return virtual_stack_vars_rtx;
4943
4944 for (link = context_display; link; link = TREE_CHAIN (link))
4945 if (TREE_PURPOSE (link) == context)
4946 return RTL_EXPR_RTL (TREE_VALUE (link));
4947
4948 abort ();
4949}
4950\f
4951/* Convert a stack slot address ADDR for variable VAR
4952 (from a containing function)
4953 into an address valid in this function (using a static chain). */
4954
4955rtx
4956fix_lexical_addr (addr, var)
4957 rtx addr;
4958 tree var;
4959{
4960 rtx basereg;
e5e809f4 4961 HOST_WIDE_INT displacement;
6f086dfc
RS
4962 tree context = decl_function_context (var);
4963 struct function *fp;
4964 rtx base = 0;
4965
4966 /* If this is the present function, we need not do anything. */
4967 if (context == current_function_decl || context == inline_function_decl)
4968 return addr;
4969
4970 for (fp = outer_function_chain; fp; fp = fp->next)
4971 if (fp->decl == context)
4972 break;
4973
4974 if (fp == 0)
4975 abort ();
4976
e9a25f70
JL
4977 if (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == MEM)
4978 addr = XEXP (XEXP (addr, 0), 0);
4979
6f086dfc
RS
4980 /* Decode given address as base reg plus displacement. */
4981 if (GET_CODE (addr) == REG)
4982 basereg = addr, displacement = 0;
4983 else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
4984 basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
4985 else
4986 abort ();
4987
4988 /* We accept vars reached via the containing function's
4989 incoming arg pointer and via its stack variables pointer. */
4990 if (basereg == fp->internal_arg_pointer)
4991 {
4992 /* If reached via arg pointer, get the arg pointer value
4993 out of that function's stack frame.
4994
4995 There are two cases: If a separate ap is needed, allocate a
4996 slot in the outer function for it and dereference it that way.
4997 This is correct even if the real ap is actually a pseudo.
4998 Otherwise, just adjust the offset from the frame pointer to
4999 compensate. */
5000
5001#ifdef NEED_SEPARATE_AP
5002 rtx addr;
5003
5004 if (fp->arg_pointer_save_area == 0)
5005 fp->arg_pointer_save_area
5006 = assign_outer_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0, fp);
5007
5008 addr = fix_lexical_addr (XEXP (fp->arg_pointer_save_area, 0), var);
5009 addr = memory_address (Pmode, addr);
5010
38a448ca 5011 base = copy_to_reg (gen_rtx_MEM (Pmode, addr));
6f086dfc
RS
5012#else
5013 displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET);
86f8eff3 5014 base = lookup_static_chain (var);
6f086dfc
RS
5015#endif
5016 }
5017
5018 else if (basereg == virtual_stack_vars_rtx)
5019 {
5020 /* This is the same code as lookup_static_chain, duplicated here to
5021 avoid an extra call to decl_function_context. */
5022 tree link;
5023
5024 for (link = context_display; link; link = TREE_CHAIN (link))
5025 if (TREE_PURPOSE (link) == context)
5026 {
5027 base = RTL_EXPR_RTL (TREE_VALUE (link));
5028 break;
5029 }
5030 }
5031
5032 if (base == 0)
5033 abort ();
5034
5035 /* Use same offset, relative to appropriate static chain or argument
5036 pointer. */
5037 return plus_constant (base, displacement);
5038}
5039\f
5040/* Return the address of the trampoline for entering nested fn FUNCTION.
5041 If necessary, allocate a trampoline (in the stack frame)
5042 and emit rtl to initialize its contents (at entry to this function). */
5043
5044rtx
5045trampoline_address (function)
5046 tree function;
5047{
5048 tree link;
5049 tree rtlexp;
5050 rtx tramp;
5051 struct function *fp;
5052 tree fn_context;
5053
5054 /* Find an existing trampoline and return it. */
5055 for (link = trampoline_list; link; link = TREE_CHAIN (link))
5056 if (TREE_PURPOSE (link) == function)
e87ee2a9
RK
5057 return
5058 round_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0));
5059
6f086dfc
RS
5060 for (fp = outer_function_chain; fp; fp = fp->next)
5061 for (link = fp->trampoline_list; link; link = TREE_CHAIN (link))
5062 if (TREE_PURPOSE (link) == function)
5063 {
5064 tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
5065 function);
5066 return round_trampoline_addr (tramp);
5067 }
5068
5069 /* None exists; we must make one. */
5070
5071 /* Find the `struct function' for the function containing FUNCTION. */
5072 fp = 0;
5073 fn_context = decl_function_context (function);
4ac74fb8
RK
5074 if (fn_context != current_function_decl
5075 && fn_context != inline_function_decl)
6f086dfc
RS
5076 for (fp = outer_function_chain; fp; fp = fp->next)
5077 if (fp->decl == fn_context)
5078 break;
5079
5080 /* Allocate run-time space for this trampoline
5081 (usually in the defining function's stack frame). */
5082#ifdef ALLOCATE_TRAMPOLINE
5083 tramp = ALLOCATE_TRAMPOLINE (fp);
5084#else
5085 /* If rounding needed, allocate extra space
5086 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
5087#ifdef TRAMPOLINE_ALIGNMENT
b02ab63a
RK
5088#define TRAMPOLINE_REAL_SIZE \
5089 (TRAMPOLINE_SIZE + (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT) - 1)
6f086dfc
RS
5090#else
5091#define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
5092#endif
5093 if (fp != 0)
5094 tramp = assign_outer_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0, fp);
5095 else
5096 tramp = assign_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0);
5097#endif
5098
5099 /* Record the trampoline for reuse and note it for later initialization
5100 by expand_function_end. */
5101 if (fp != 0)
5102 {
28498644
RK
5103 push_obstacks (fp->function_maybepermanent_obstack,
5104 fp->function_maybepermanent_obstack);
6f086dfc
RS
5105 rtlexp = make_node (RTL_EXPR);
5106 RTL_EXPR_RTL (rtlexp) = tramp;
5107 fp->trampoline_list = tree_cons (function, rtlexp, fp->trampoline_list);
5108 pop_obstacks ();
5109 }
5110 else
5111 {
5112 /* Make the RTL_EXPR node temporary, not momentary, so that the
5113 trampoline_list doesn't become garbage. */
5114 int momentary = suspend_momentary ();
5115 rtlexp = make_node (RTL_EXPR);
5116 resume_momentary (momentary);
5117
5118 RTL_EXPR_RTL (rtlexp) = tramp;
5119 trampoline_list = tree_cons (function, rtlexp, trampoline_list);
5120 }
5121
5122 tramp = fix_lexical_addr (XEXP (tramp, 0), function);
5123 return round_trampoline_addr (tramp);
5124}
5125
5126/* Given a trampoline address,
5127 round it to multiple of TRAMPOLINE_ALIGNMENT. */
5128
5129static rtx
5130round_trampoline_addr (tramp)
5131 rtx tramp;
5132{
5133#ifdef TRAMPOLINE_ALIGNMENT
5134 /* Round address up to desired boundary. */
5135 rtx temp = gen_reg_rtx (Pmode);
5136 temp = expand_binop (Pmode, add_optab, tramp,
b02ab63a 5137 GEN_INT (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT - 1),
6f086dfc
RS
5138 temp, 0, OPTAB_LIB_WIDEN);
5139 tramp = expand_binop (Pmode, and_optab, temp,
b02ab63a 5140 GEN_INT (- TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT),
6f086dfc
RS
5141 temp, 0, OPTAB_LIB_WIDEN);
5142#endif
5143 return tramp;
5144}
5145\f
467456d0
RS
5146/* The functions identify_blocks and reorder_blocks provide a way to
5147 reorder the tree of BLOCK nodes, for optimizers that reshuffle or
5148 duplicate portions of the RTL code. Call identify_blocks before
5149 changing the RTL, and call reorder_blocks after. */
5150
b2a59b15
MS
5151/* Put all this function's BLOCK nodes including those that are chained
5152 onto the first block into a vector, and return it.
467456d0
RS
5153 Also store in each NOTE for the beginning or end of a block
5154 the index of that block in the vector.
b2a59b15 5155 The arguments are BLOCK, the chain of top-level blocks of the function,
467456d0
RS
5156 and INSNS, the insn chain of the function. */
5157
5158tree *
b2a59b15
MS
5159identify_blocks (block, insns)
5160 tree block;
467456d0
RS
5161 rtx insns;
5162{
fc289cd1
JW
5163 int n_blocks;
5164 tree *block_vector;
5165 int *block_stack;
467456d0 5166 int depth = 0;
b2a59b15
MS
5167 int next_block_number = 1;
5168 int current_block_number = 1;
467456d0
RS
5169 rtx insn;
5170
b2a59b15 5171 if (block == 0)
fc289cd1
JW
5172 return 0;
5173
b2a59b15 5174 n_blocks = all_blocks (block, 0);
fc289cd1
JW
5175 block_vector = (tree *) xmalloc (n_blocks * sizeof (tree));
5176 block_stack = (int *) alloca (n_blocks * sizeof (int));
5177
b2a59b15 5178 all_blocks (block, block_vector);
467456d0
RS
5179
5180 for (insn = insns; insn; insn = NEXT_INSN (insn))
5181 if (GET_CODE (insn) == NOTE)
5182 {
5183 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
5184 {
5185 block_stack[depth++] = current_block_number;
5186 current_block_number = next_block_number;
1b2ac438 5187 NOTE_BLOCK_NUMBER (insn) = next_block_number++;
467456d0
RS
5188 }
5189 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
5190 {
1b2ac438 5191 NOTE_BLOCK_NUMBER (insn) = current_block_number;
c7fdfd49 5192 current_block_number = block_stack[--depth];
467456d0
RS
5193 }
5194 }
5195
b2a59b15
MS
5196 if (n_blocks != next_block_number)
5197 abort ();
5198
467456d0
RS
5199 return block_vector;
5200}
5201
5202/* Given BLOCK_VECTOR which was returned by identify_blocks,
5203 and a revised instruction chain, rebuild the tree structure
5204 of BLOCK nodes to correspond to the new order of RTL.
fc289cd1 5205 The new block tree is inserted below TOP_BLOCK.
467456d0
RS
5206 Returns the current top-level block. */
5207
5208tree
b2a59b15 5209reorder_blocks (block_vector, block, insns)
467456d0 5210 tree *block_vector;
b2a59b15 5211 tree block;
467456d0
RS
5212 rtx insns;
5213{
b2a59b15 5214 tree current_block = block;
467456d0
RS
5215 rtx insn;
5216
fc289cd1 5217 if (block_vector == 0)
b2a59b15 5218 return block;
fc289cd1 5219
b2a59b15 5220 /* Prune the old trees away, so that it doesn't get in the way. */
fc289cd1 5221 BLOCK_SUBBLOCKS (current_block) = 0;
b2a59b15 5222 BLOCK_CHAIN (current_block) = 0;
fc289cd1 5223
467456d0
RS
5224 for (insn = insns; insn; insn = NEXT_INSN (insn))
5225 if (GET_CODE (insn) == NOTE)
5226 {
5227 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
5228 {
5229 tree block = block_vector[NOTE_BLOCK_NUMBER (insn)];
5230 /* If we have seen this block before, copy it. */
5231 if (TREE_ASM_WRITTEN (block))
5232 block = copy_node (block);
fc289cd1 5233 BLOCK_SUBBLOCKS (block) = 0;
467456d0
RS
5234 TREE_ASM_WRITTEN (block) = 1;
5235 BLOCK_SUPERCONTEXT (block) = current_block;
5236 BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
5237 BLOCK_SUBBLOCKS (current_block) = block;
5238 current_block = block;
1b2ac438 5239 NOTE_SOURCE_FILE (insn) = 0;
467456d0
RS
5240 }
5241 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
5242 {
5243 BLOCK_SUBBLOCKS (current_block)
5244 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
5245 current_block = BLOCK_SUPERCONTEXT (current_block);
1b2ac438 5246 NOTE_SOURCE_FILE (insn) = 0;
467456d0
RS
5247 }
5248 }
5249
b2a59b15
MS
5250 BLOCK_SUBBLOCKS (current_block)
5251 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
467456d0
RS
5252 return current_block;
5253}
5254
5255/* Reverse the order of elements in the chain T of blocks,
5256 and return the new head of the chain (old last element). */
5257
5258static tree
5259blocks_nreverse (t)
5260 tree t;
5261{
5262 register tree prev = 0, decl, next;
5263 for (decl = t; decl; decl = next)
5264 {
5265 next = BLOCK_CHAIN (decl);
5266 BLOCK_CHAIN (decl) = prev;
5267 prev = decl;
5268 }
5269 return prev;
5270}
5271
b2a59b15
MS
5272/* Count the subblocks of the list starting with BLOCK, and list them
5273 all into the vector VECTOR. Also clear TREE_ASM_WRITTEN in all
5274 blocks. */
467456d0
RS
5275
5276static int
5277all_blocks (block, vector)
5278 tree block;
5279 tree *vector;
5280{
b2a59b15
MS
5281 int n_blocks = 0;
5282
5283 while (block)
5284 {
5285 TREE_ASM_WRITTEN (block) = 0;
5286
5287 /* Record this block. */
5288 if (vector)
5289 vector[n_blocks] = block;
5290
5291 ++n_blocks;
5292
5293 /* Record the subblocks, and their subblocks... */
5294 n_blocks += all_blocks (BLOCK_SUBBLOCKS (block),
5295 vector ? vector + n_blocks : 0);
5296 block = BLOCK_CHAIN (block);
5297 }
467456d0
RS
5298
5299 return n_blocks;
5300}
5301\f
6f086dfc
RS
5302/* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
5303 and initialize static variables for generating RTL for the statements
5304 of the function. */
5305
5306void
5307init_function_start (subr, filename, line)
5308 tree subr;
5309 char *filename;
5310 int line;
5311{
6f086dfc
RS
5312 init_stmt_for_function ();
5313
5314 cse_not_expected = ! optimize;
5315
5316 /* Caller save not needed yet. */
5317 caller_save_needed = 0;
5318
5319 /* No stack slots have been made yet. */
5320 stack_slot_list = 0;
5321
5322 /* There is no stack slot for handling nonlocal gotos. */
5323 nonlocal_goto_handler_slot = 0;
5324 nonlocal_goto_stack_level = 0;
5325
5326 /* No labels have been declared for nonlocal use. */
5327 nonlocal_labels = 0;
5328
5329 /* No function calls so far in this function. */
5330 function_call_count = 0;
5331
5332 /* No parm regs have been allocated.
5333 (This is important for output_inline_function.) */
5334 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
5335
5336 /* Initialize the RTL mechanism. */
5337 init_emit ();
5338
5339 /* Initialize the queue of pending postincrement and postdecrements,
5340 and some other info in expr.c. */
5341 init_expr ();
5342
5343 /* We haven't done register allocation yet. */
5344 reg_renumber = 0;
5345
5346 init_const_rtx_hash_table ();
5347
a1d7ffe3 5348 current_function_name = (*decl_printable_name) (subr, 2);
6f086dfc
RS
5349
5350 /* Nonzero if this is a nested function that uses a static chain. */
5351
5352 current_function_needs_context
38ee6ed9
JM
5353 = (decl_function_context (current_function_decl) != 0
5354 && ! DECL_NO_STATIC_CHAIN (current_function_decl));
6f086dfc
RS
5355
5356 /* Set if a call to setjmp is seen. */
5357 current_function_calls_setjmp = 0;
5358
5359 /* Set if a call to longjmp is seen. */
5360 current_function_calls_longjmp = 0;
5361
5362 current_function_calls_alloca = 0;
5363 current_function_has_nonlocal_label = 0;
8634413a 5364 current_function_has_nonlocal_goto = 0;
6f086dfc 5365 current_function_contains_functions = 0;
173cd503 5366 current_function_is_thunk = 0;
6f086dfc
RS
5367
5368 current_function_returns_pcc_struct = 0;
5369 current_function_returns_struct = 0;
5370 current_function_epilogue_delay_list = 0;
5371 current_function_uses_const_pool = 0;
5372 current_function_uses_pic_offset_table = 0;
aeb302bb 5373 current_function_cannot_inline = 0;
6f086dfc
RS
5374
5375 /* We have not yet needed to make a label to jump to for tail-recursion. */
5376 tail_recursion_label = 0;
5377
5378 /* We haven't had a need to make a save area for ap yet. */
5379
5380 arg_pointer_save_area = 0;
5381
5382 /* No stack slots allocated yet. */
5383 frame_offset = 0;
5384
5385 /* No SAVE_EXPRs in this function yet. */
5386 save_expr_regs = 0;
5387
5388 /* No RTL_EXPRs in this function yet. */
5389 rtl_expr_chain = 0;
5390
bc0ebdf9
RK
5391 /* Set up to allocate temporaries. */
5392 init_temp_slots ();
6f086dfc
RS
5393
5394 /* Within function body, compute a type's size as soon it is laid out. */
5395 immediate_size_expand++;
5396
d9a98e1a
RK
5397 /* We haven't made any trampolines for this function yet. */
5398 trampoline_list = 0;
5399
6f086dfc
RS
5400 init_pending_stack_adjust ();
5401 inhibit_defer_pop = 0;
5402
5403 current_function_outgoing_args_size = 0;
5404
6f086dfc 5405 /* Prevent ever trying to delete the first instruction of a function.
b274104c
PB
5406 Also tell final how to output a linenum before the function prologue.
5407 Note linenums could be missing, e.g. when compiling a Java .class file. */
5408 if (line > 0)
5409 emit_line_note (filename, line);
6f086dfc
RS
5410
5411 /* Make sure first insn is a note even if we don't want linenums.
5412 This makes sure the first insn will never be deleted.
5413 Also, final expects a note to appear there. */
5f4f0e22 5414 emit_note (NULL_PTR, NOTE_INSN_DELETED);
6f086dfc
RS
5415
5416 /* Set flags used by final.c. */
5417 if (aggregate_value_p (DECL_RESULT (subr)))
5418 {
5419#ifdef PCC_STATIC_STRUCT_RETURN
1b8297c1 5420 current_function_returns_pcc_struct = 1;
6f086dfc 5421#endif
1b8297c1 5422 current_function_returns_struct = 1;
6f086dfc
RS
5423 }
5424
5425 /* Warn if this value is an aggregate type,
5426 regardless of which calling convention we are using for it. */
5427 if (warn_aggregate_return
05e3bdb9 5428 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
6f086dfc
RS
5429 warning ("function returns an aggregate");
5430
5431 current_function_returns_pointer
8eda074c 5432 = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
6f086dfc
RS
5433
5434 /* Indicate that we need to distinguish between the return value of the
5435 present function and the return value of a function being called. */
5436 rtx_equal_function_value_matters = 1;
5437
5438 /* Indicate that we have not instantiated virtual registers yet. */
5439 virtuals_instantiated = 0;
5440
5441 /* Indicate we have no need of a frame pointer yet. */
5442 frame_pointer_needed = 0;
5443
ebb904cb 5444 /* By default assume not varargs or stdarg. */
6f086dfc 5445 current_function_varargs = 0;
ebb904cb 5446 current_function_stdarg = 0;
6f086dfc
RS
5447}
5448
5449/* Indicate that the current function uses extra args
5450 not explicitly mentioned in the argument list in any fashion. */
5451
5452void
5453mark_varargs ()
5454{
5455 current_function_varargs = 1;
5456}
5457
5458/* Expand a call to __main at the beginning of a possible main function. */
5459
e2fd1d94
JM
5460#if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
5461#undef HAS_INIT_SECTION
5462#define HAS_INIT_SECTION
5463#endif
5464
6f086dfc
RS
5465void
5466expand_main_function ()
5467{
e2fd1d94 5468#if !defined (HAS_INIT_SECTION)
b93a436e
JL
5469 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, NAME__MAIN), 0,
5470 VOIDmode, 0);
e2fd1d94 5471#endif /* not HAS_INIT_SECTION */
6f086dfc
RS
5472}
5473\f
c20bf1f3
JB
5474extern struct obstack permanent_obstack;
5475
6f086dfc
RS
5476/* Start the RTL for a new function, and set variables used for
5477 emitting RTL.
5478 SUBR is the FUNCTION_DECL node.
5479 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
5480 the function's parameters, which must be run at any return statement. */
5481
5482void
5483expand_function_start (subr, parms_have_cleanups)
5484 tree subr;
5485 int parms_have_cleanups;
5486{
5487 register int i;
5488 tree tem;
4e86caed 5489 rtx last_ptr = NULL_RTX;
6f086dfc
RS
5490
5491 /* Make sure volatile mem refs aren't considered
5492 valid operands of arithmetic insns. */
5493 init_recog_no_volatile ();
5494
07417085
KR
5495 current_function_instrument_entry_exit
5496 = (flag_instrument_function_entry_exit
5497 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr));
5498
6f086dfc
RS
5499 /* If function gets a static chain arg, store it in the stack frame.
5500 Do this first, so it gets the first stack slot offset. */
5501 if (current_function_needs_context)
3e2481e9
JW
5502 {
5503 last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
f0c51a1e 5504
f0c51a1e
RK
5505 /* Delay copying static chain if it is not a register to avoid
5506 conflicts with regs used for parameters. */
f95182a4
ILT
5507 if (! SMALL_REGISTER_CLASSES
5508 || GET_CODE (static_chain_incoming_rtx) == REG)
f0c51a1e 5509 emit_move_insn (last_ptr, static_chain_incoming_rtx);
3e2481e9 5510 }
6f086dfc
RS
5511
5512 /* If the parameters of this function need cleaning up, get a label
5513 for the beginning of the code which executes those cleanups. This must
5514 be done before doing anything with return_label. */
5515 if (parms_have_cleanups)
5516 cleanup_label = gen_label_rtx ();
5517 else
5518 cleanup_label = 0;
5519
5520 /* Make the label for return statements to jump to, if this machine
5521 does not have a one-instruction return and uses an epilogue,
5522 or if it returns a structure, or if it has parm cleanups. */
5523#ifdef HAVE_return
5524 if (cleanup_label == 0 && HAVE_return
07417085 5525 && ! current_function_instrument_entry_exit
6f086dfc
RS
5526 && ! current_function_returns_pcc_struct
5527 && ! (current_function_returns_struct && ! optimize))
5528 return_label = 0;
5529 else
5530 return_label = gen_label_rtx ();
5531#else
5532 return_label = gen_label_rtx ();
5533#endif
5534
5535 /* Initialize rtx used to return the value. */
5536 /* Do this before assign_parms so that we copy the struct value address
5537 before any library calls that assign parms might generate. */
5538
5539 /* Decide whether to return the value in memory or in a register. */
5540 if (aggregate_value_p (DECL_RESULT (subr)))
5541 {
5542 /* Returning something that won't go in a register. */
4acc00bf 5543 register rtx value_address = 0;
6f086dfc
RS
5544
5545#ifdef PCC_STATIC_STRUCT_RETURN
5546 if (current_function_returns_pcc_struct)
5547 {
5548 int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
5549 value_address = assemble_static_space (size);
5550 }
5551 else
5552#endif
5553 {
5554 /* Expect to be passed the address of a place to store the value.
5555 If it is passed as an argument, assign_parms will take care of
5556 it. */
5557 if (struct_value_incoming_rtx)
5558 {
5559 value_address = gen_reg_rtx (Pmode);
5560 emit_move_insn (value_address, struct_value_incoming_rtx);
5561 }
5562 }
5563 if (value_address)
ccdecf58
RK
5564 {
5565 DECL_RTL (DECL_RESULT (subr))
38a448ca 5566 = gen_rtx_MEM (DECL_MODE (DECL_RESULT (subr)), value_address);
ccdecf58 5567 MEM_IN_STRUCT_P (DECL_RTL (DECL_RESULT (subr)))
05e3bdb9 5568 = AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
ccdecf58 5569 }
6f086dfc
RS
5570 }
5571 else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
5572 /* If return mode is void, this decl rtl should not be used. */
5573 DECL_RTL (DECL_RESULT (subr)) = 0;
07417085 5574 else if (parms_have_cleanups || current_function_instrument_entry_exit)
a53e14c0
RK
5575 {
5576 /* If function will end with cleanup code for parms,
5577 compute the return values into a pseudo reg,
5578 which we will copy into the true return register
5579 after the cleanups are done. */
5580
5581 enum machine_mode mode = DECL_MODE (DECL_RESULT (subr));
a5a52dbc 5582
a53e14c0
RK
5583#ifdef PROMOTE_FUNCTION_RETURN
5584 tree type = TREE_TYPE (DECL_RESULT (subr));
5585 int unsignedp = TREE_UNSIGNED (type);
5586
a5a52dbc 5587 mode = promote_mode (type, mode, &unsignedp, 1);
a53e14c0
RK
5588#endif
5589
5590 DECL_RTL (DECL_RESULT (subr)) = gen_reg_rtx (mode);
5591 }
6f086dfc
RS
5592 else
5593 /* Scalar, returned in a register. */
5594 {
5595#ifdef FUNCTION_OUTGOING_VALUE
5596 DECL_RTL (DECL_RESULT (subr))
5597 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
5598#else
5599 DECL_RTL (DECL_RESULT (subr))
5600 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
5601#endif
5602
5603 /* Mark this reg as the function's return value. */
5604 if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG)
5605 {
5606 REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1;
5607 /* Needed because we may need to move this to memory
5608 in case it's a named return value whose address is taken. */
a82ad570 5609 DECL_REGISTER (DECL_RESULT (subr)) = 1;
6f086dfc
RS
5610 }
5611 }
5612
5613 /* Initialize rtx for parameters and local variables.
5614 In some cases this requires emitting insns. */
5615
5616 assign_parms (subr, 0);
5617
f0c51a1e
RK
5618 /* Copy the static chain now if it wasn't a register. The delay is to
5619 avoid conflicts with the parameter passing registers. */
5620
f95182a4 5621 if (SMALL_REGISTER_CLASSES && current_function_needs_context)
f0c51a1e
RK
5622 if (GET_CODE (static_chain_incoming_rtx) != REG)
5623 emit_move_insn (last_ptr, static_chain_incoming_rtx);
f0c51a1e 5624
6f086dfc
RS
5625 /* The following was moved from init_function_start.
5626 The move is supposed to make sdb output more accurate. */
5627 /* Indicate the beginning of the function body,
5628 as opposed to parm setup. */
5f4f0e22 5629 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_BEG);
6f086dfc
RS
5630
5631 /* If doing stupid allocation, mark parms as born here. */
5632
5633 if (GET_CODE (get_last_insn ()) != NOTE)
5f4f0e22 5634 emit_note (NULL_PTR, NOTE_INSN_DELETED);
6f086dfc
RS
5635 parm_birth_insn = get_last_insn ();
5636
5637 if (obey_regdecls)
5638 {
5639 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
5640 use_variable (regno_reg_rtx[i]);
5641
5642 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
5643 use_variable (current_function_internal_arg_pointer);
5644 }
5645
6d7306f7
JM
5646 context_display = 0;
5647 if (current_function_needs_context)
ac9e20f0 5648 {
6d7306f7
JM
5649 /* Fetch static chain values for containing functions. */
5650 tem = decl_function_context (current_function_decl);
5651 /* If not doing stupid register allocation copy the static chain
5652 pointer into a pseudo. If we have small register classes, copy
5653 the value from memory if static_chain_incoming_rtx is a REG. If
5654 we do stupid register allocation, we use the stack address
5655 generated above. */
5656 if (tem && ! obey_regdecls)
5657 {
6d7306f7
JM
5658 /* If the static chain originally came in a register, put it back
5659 there, then move it out in the next insn. The reason for
5660 this peculiar code is to satisfy function integration. */
f95182a4
ILT
5661 if (SMALL_REGISTER_CLASSES
5662 && GET_CODE (static_chain_incoming_rtx) == REG)
6d7306f7 5663 emit_move_insn (static_chain_incoming_rtx, last_ptr);
6d7306f7
JM
5664 last_ptr = copy_to_reg (static_chain_incoming_rtx);
5665 }
ac9e20f0 5666
6d7306f7
JM
5667 while (tem)
5668 {
5669 tree rtlexp = make_node (RTL_EXPR);
6f086dfc 5670
6d7306f7
JM
5671 RTL_EXPR_RTL (rtlexp) = last_ptr;
5672 context_display = tree_cons (tem, rtlexp, context_display);
5673 tem = decl_function_context (tem);
5674 if (tem == 0)
5675 break;
5676 /* Chain thru stack frames, assuming pointer to next lexical frame
5677 is found at the place we always store it. */
6f086dfc 5678#ifdef FRAME_GROWS_DOWNWARD
6d7306f7 5679 last_ptr = plus_constant (last_ptr, - GET_MODE_SIZE (Pmode));
6f086dfc 5680#endif
38a448ca
RH
5681 last_ptr = copy_to_reg (gen_rtx_MEM (Pmode,
5682 memory_address (Pmode, last_ptr)));
6d7306f7
JM
5683
5684 /* If we are not optimizing, ensure that we know that this
5685 piece of context is live over the entire function. */
5686 if (! optimize)
38a448ca
RH
5687 save_expr_regs = gen_rtx_EXPR_LIST (VOIDmode, last_ptr,
5688 save_expr_regs);
6d7306f7 5689 }
6f086dfc
RS
5690 }
5691
07417085
KR
5692 if (current_function_instrument_entry_exit)
5693 {
5694 rtx fun = DECL_RTL (current_function_decl);
5695 if (GET_CODE (fun) == MEM)
5696 fun = XEXP (fun, 0);
5697 else
5698 abort ();
5699 emit_library_call (profile_function_entry_libfunc, 0, VOIDmode, 2,
5700 fun, Pmode,
5701 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS,
5702 0,
5703 hard_frame_pointer_rtx),
5704 Pmode);
5705 }
5706
6f086dfc
RS
5707 /* After the display initializations is where the tail-recursion label
5708 should go, if we end up needing one. Ensure we have a NOTE here
5709 since some things (like trampolines) get placed before this. */
5f4f0e22 5710 tail_recursion_reentry = emit_note (NULL_PTR, NOTE_INSN_DELETED);
6f086dfc
RS
5711
5712 /* Evaluate now the sizes of any types declared among the arguments. */
5713 for (tem = nreverse (get_pending_sizes ()); tem; tem = TREE_CHAIN (tem))
7b05e286 5714 {
86fa911a
RK
5715 expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode,
5716 EXPAND_MEMORY_USE_BAD);
7b05e286
JW
5717 /* Flush the queue in case this parameter declaration has
5718 side-effects. */
5719 emit_queue ();
5720 }
6f086dfc
RS
5721
5722 /* Make sure there is a line number after the function entry setup code. */
5723 force_next_line_note ();
5724}
5725\f
5726/* Generate RTL for the end of the current function.
980697fd 5727 FILENAME and LINE are the current position in the source file.
6f086dfc 5728
980697fd 5729 It is up to language-specific callers to do cleanups for parameters--
1be07046 5730 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */
6f086dfc
RS
5731
5732void
1be07046 5733expand_function_end (filename, line, end_bindings)
6f086dfc
RS
5734 char *filename;
5735 int line;
1be07046 5736 int end_bindings;
6f086dfc
RS
5737{
5738 register int i;
5739 tree link;
5740
1e2414db 5741#ifdef TRAMPOLINE_TEMPLATE
6f086dfc 5742 static rtx initial_trampoline;
1e2414db 5743#endif
6f086dfc
RS
5744
5745#ifdef NON_SAVING_SETJMP
5746 /* Don't put any variables in registers if we call setjmp
5747 on a machine that fails to restore the registers. */
5748 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
5749 {
b88a3142
RK
5750 if (DECL_INITIAL (current_function_decl) != error_mark_node)
5751 setjmp_protect (DECL_INITIAL (current_function_decl));
5752
6f086dfc
RS
5753 setjmp_protect_args ();
5754 }
5755#endif
5756
5757 /* Save the argument pointer if a save area was made for it. */
5758 if (arg_pointer_save_area)
5759 {
5760 rtx x = gen_move_insn (arg_pointer_save_area, virtual_incoming_args_rtx);
5761 emit_insn_before (x, tail_recursion_reentry);
5762 }
5763
5764 /* Initialize any trampolines required by this function. */
5765 for (link = trampoline_list; link; link = TREE_CHAIN (link))
5766 {
5767 tree function = TREE_PURPOSE (link);
5768 rtx context = lookup_static_chain (function);
5769 rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
7a87758d 5770#ifdef TRAMPOLINE_TEMPLATE
1e2414db 5771 rtx blktramp;
7a87758d 5772#endif
6f086dfc
RS
5773 rtx seq;
5774
1e2414db 5775#ifdef TRAMPOLINE_TEMPLATE
6f086dfc
RS
5776 /* First make sure this compilation has a template for
5777 initializing trampolines. */
5778 if (initial_trampoline == 0)
86f8eff3
RK
5779 {
5780 end_temporary_allocation ();
5781 initial_trampoline
38a448ca 5782 = gen_rtx_MEM (BLKmode, assemble_trampoline_template ());
86f8eff3
RK
5783 resume_temporary_allocation ();
5784 }
1e2414db 5785#endif
6f086dfc
RS
5786
5787 /* Generate insns to initialize the trampoline. */
5788 start_sequence ();
1e2414db
RK
5789 tramp = round_trampoline_addr (XEXP (tramp, 0));
5790#ifdef TRAMPOLINE_TEMPLATE
5791 blktramp = change_address (initial_trampoline, BLKmode, tramp);
5792 emit_block_move (blktramp, initial_trampoline,
5793 GEN_INT (TRAMPOLINE_SIZE),
189cc377 5794 TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1e2414db
RK
5795#endif
5796 INITIALIZE_TRAMPOLINE (tramp, XEXP (DECL_RTL (function), 0), context);
6f086dfc
RS
5797 seq = get_insns ();
5798 end_sequence ();
5799
5800 /* Put those insns at entry to the containing function (this one). */
5801 emit_insns_before (seq, tail_recursion_reentry);
5802 }
6f086dfc 5803
11044f66
RK
5804 /* If we are doing stack checking and this function makes calls,
5805 do a stack probe at the start of the function to ensure we have enough
5806 space for another stack frame. */
5807 if (flag_stack_check && ! STACK_CHECK_BUILTIN)
5808 {
5809 rtx insn, seq;
5810
5811 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
5812 if (GET_CODE (insn) == CALL_INSN)
5813 {
5814 start_sequence ();
5815 probe_stack_range (STACK_CHECK_PROTECT,
5816 GEN_INT (STACK_CHECK_MAX_FRAME_SIZE));
5817 seq = get_insns ();
5818 end_sequence ();
5819 emit_insns_before (seq, tail_recursion_reentry);
5820 break;
5821 }
5822 }
5823
db8717d9
RK
5824 /* Warn about unused parms if extra warnings were specified. */
5825 if (warn_unused && extra_warnings)
6f086dfc 5826 {
db8717d9 5827 tree decl;
6f086dfc
RS
5828
5829 for (decl = DECL_ARGUMENTS (current_function_decl);
5830 decl; decl = TREE_CHAIN (decl))
497dc802
JM
5831 if (! TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
5832 && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
6f086dfc
RS
5833 warning_with_decl (decl, "unused parameter `%s'");
5834 }
6f086dfc
RS
5835
5836 /* Delete handlers for nonlocal gotos if nothing uses them. */
5837 if (nonlocal_goto_handler_slot != 0 && !current_function_has_nonlocal_label)
5838 delete_handlers ();
5839
5840 /* End any sequences that failed to be closed due to syntax errors. */
5841 while (in_sequence_p ())
5f4f0e22 5842 end_sequence ();
6f086dfc
RS
5843
5844 /* Outside function body, can't compute type's actual size
5845 until next function's body starts. */
5846 immediate_size_expand--;
5847
5848 /* If doing stupid register allocation,
5849 mark register parms as dying here. */
5850
5851 if (obey_regdecls)
5852 {
5853 rtx tem;
5854 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
5855 use_variable (regno_reg_rtx[i]);
5856
5857 /* Likewise for the regs of all the SAVE_EXPRs in the function. */
5858
5859 for (tem = save_expr_regs; tem; tem = XEXP (tem, 1))
5860 {
5861 use_variable (XEXP (tem, 0));
5862 use_variable_after (XEXP (tem, 0), parm_birth_insn);
5863 }
5864
5865 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
5866 use_variable (current_function_internal_arg_pointer);
5867 }
5868
5869 clear_pending_stack_adjust ();
5870 do_pending_stack_adjust ();
5871
5872 /* Mark the end of the function body.
5873 If control reaches this insn, the function can drop through
5874 without returning a value. */
5f4f0e22 5875 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_END);
6f086dfc 5876
82e415a3
DE
5877 /* Must mark the last line number note in the function, so that the test
5878 coverage code can avoid counting the last line twice. This just tells
5879 the code to ignore the immediately following line note, since there
5880 already exists a copy of this note somewhere above. This line number
5881 note is still needed for debugging though, so we can't delete it. */
5882 if (flag_test_coverage)
5883 emit_note (NULL_PTR, NOTE_REPEATED_LINE_NUMBER);
5884
6f086dfc
RS
5885 /* Output a linenumber for the end of the function.
5886 SDB depends on this. */
5887 emit_line_note_force (filename, line);
5888
5889 /* Output the label for the actual return from the function,
5890 if one is expected. This happens either because a function epilogue
5891 is used instead of a return instruction, or because a return was done
5892 with a goto in order to run local cleanups, or because of pcc-style
5893 structure returning. */
5894
5895 if (return_label)
5896 emit_label (return_label);
5897
1be07046
RS
5898 /* C++ uses this. */
5899 if (end_bindings)
5900 expand_end_bindings (0, 0, 0);
5901
e5a1e0e8
MS
5902 /* Now handle any leftover exception regions that may have been
5903 created for the parameters. */
5904 {
5905 rtx last = get_last_insn ();
5906 rtx label;
5907
5908 expand_leftover_cleanups ();
5909
5910 /* If the above emitted any code, may sure we jump around it. */
5911 if (last != get_last_insn ())
5912 {
5913 label = gen_label_rtx ();
5914 last = emit_jump_insn_after (gen_jump (label), last);
5915 last = emit_barrier_after (last);
5916 emit_label (label);
5917 }
5918 }
5919
07417085
KR
5920 if (current_function_instrument_entry_exit)
5921 {
5922 rtx fun = DECL_RTL (current_function_decl);
5923 if (GET_CODE (fun) == MEM)
5924 fun = XEXP (fun, 0);
5925 else
5926 abort ();
5927 emit_library_call (profile_function_exit_libfunc, 0, VOIDmode, 2,
5928 fun, Pmode,
5929 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS,
5930 0,
5931 hard_frame_pointer_rtx),
5932 Pmode);
5933 }
5934
6f086dfc
RS
5935 /* If we had calls to alloca, and this machine needs
5936 an accurate stack pointer to exit the function,
5937 insert some code to save and restore the stack pointer. */
5938#ifdef EXIT_IGNORE_STACK
5939 if (! EXIT_IGNORE_STACK)
5940#endif
5941 if (current_function_calls_alloca)
5942 {
59257ff7
RK
5943 rtx tem = 0;
5944
5945 emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
5f4f0e22 5946 emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
6f086dfc
RS
5947 }
5948
5949 /* If scalar return value was computed in a pseudo-reg,
5950 copy that to the hard return register. */
5951 if (DECL_RTL (DECL_RESULT (current_function_decl)) != 0
5952 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG
5953 && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl)))
5954 >= FIRST_PSEUDO_REGISTER))
5955 {
5956 rtx real_decl_result;
5957
5958#ifdef FUNCTION_OUTGOING_VALUE
5959 real_decl_result
5960 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
5961 current_function_decl);
5962#else
5963 real_decl_result
5964 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
5965 current_function_decl);
5966#endif
5967 REG_FUNCTION_VALUE_P (real_decl_result) = 1;
ecec4441
JW
5968 /* If this is a BLKmode structure being returned in registers, then use
5969 the mode computed in expand_return. */
5970 if (GET_MODE (real_decl_result) == BLKmode)
5971 PUT_MODE (real_decl_result,
5972 GET_MODE (DECL_RTL (DECL_RESULT (current_function_decl))));
6f086dfc
RS
5973 emit_move_insn (real_decl_result,
5974 DECL_RTL (DECL_RESULT (current_function_decl)));
38a448ca 5975 emit_insn (gen_rtx_USE (VOIDmode, real_decl_result));
f345de42
JL
5976
5977 /* The delay slot scheduler assumes that current_function_return_rtx
5978 holds the hard register containing the return value, not a temporary
5979 pseudo. */
5980 current_function_return_rtx = real_decl_result;
6f086dfc
RS
5981 }
5982
5983 /* If returning a structure, arrange to return the address of the value
5984 in a place where debuggers expect to find it.
5985
5986 If returning a structure PCC style,
5987 the caller also depends on this value.
5988 And current_function_returns_pcc_struct is not necessarily set. */
5989 if (current_function_returns_struct
5990 || current_function_returns_pcc_struct)
5991 {
5992 rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
5993 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
5994#ifdef FUNCTION_OUTGOING_VALUE
5995 rtx outgoing
5996 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
5997 current_function_decl);
5998#else
5999 rtx outgoing
6000 = FUNCTION_VALUE (build_pointer_type (type),
6001 current_function_decl);
6002#endif
6003
6004 /* Mark this as a function return value so integrate will delete the
6005 assignment and USE below when inlining this function. */
6006 REG_FUNCTION_VALUE_P (outgoing) = 1;
6007
6008 emit_move_insn (outgoing, value_address);
6009 use_variable (outgoing);
6010 }
6011
71038426
RH
6012 /* If this is an implementation of __throw, do what's necessary to
6013 communicate between __builtin_eh_return and the epilogue. */
6014 expand_eh_return ();
6015
6f086dfc
RS
6016 /* Output a return insn if we are using one.
6017 Otherwise, let the rtl chain end here, to drop through
6018 into the epilogue. */
6019
6020#ifdef HAVE_return
6021 if (HAVE_return)
6022 {
6023 emit_jump_insn (gen_return ());
6024 emit_barrier ();
6025 }
6026#endif
6027
6028 /* Fix up any gotos that jumped out to the outermost
6029 binding level of the function.
6030 Must follow emitting RETURN_LABEL. */
6031
6032 /* If you have any cleanups to do at this point,
6033 and they need to create temporary variables,
6034 then you will lose. */
e15679f8 6035 expand_fixups (get_insns ());
6f086dfc 6036}
bdac5f58
TW
6037\f
6038/* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
6039
6040static int *prologue;
6041static int *epilogue;
6042
6043/* Create an array that records the INSN_UIDs of INSNS (either a sequence
6044 or a single insn). */
6045
487a6e06 6046#if defined (HAVE_prologue) || defined (HAVE_epilogue)
bdac5f58
TW
6047static int *
6048record_insns (insns)
6049 rtx insns;
6050{
6051 int *vec;
6052
6053 if (GET_CODE (insns) == SEQUENCE)
6054 {
6055 int len = XVECLEN (insns, 0);
6056 vec = (int *) oballoc ((len + 1) * sizeof (int));
6057 vec[len] = 0;
6058 while (--len >= 0)
6059 vec[len] = INSN_UID (XVECEXP (insns, 0, len));
6060 }
6061 else
6062 {
6063 vec = (int *) oballoc (2 * sizeof (int));
6064 vec[0] = INSN_UID (insns);
6065 vec[1] = 0;
6066 }
6067 return vec;
6068}
6069
10914065 6070/* Determine how many INSN_UIDs in VEC are part of INSN. */
bdac5f58 6071
10914065 6072static int
bdac5f58
TW
6073contains (insn, vec)
6074 rtx insn;
6075 int *vec;
6076{
6077 register int i, j;
6078
6079 if (GET_CODE (insn) == INSN
6080 && GET_CODE (PATTERN (insn)) == SEQUENCE)
6081 {
10914065 6082 int count = 0;
bdac5f58
TW
6083 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
6084 for (j = 0; vec[j]; j++)
6085 if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == vec[j])
10914065
TW
6086 count++;
6087 return count;
bdac5f58
TW
6088 }
6089 else
6090 {
6091 for (j = 0; vec[j]; j++)
6092 if (INSN_UID (insn) == vec[j])
10914065 6093 return 1;
bdac5f58
TW
6094 }
6095 return 0;
6096}
081f5e7e 6097#endif /* HAVE_prologue || HAVE_epilogue */
bdac5f58 6098
9faa82d8 6099/* Generate the prologue and epilogue RTL if the machine supports it. Thread
bdac5f58
TW
6100 this into place with notes indicating where the prologue ends and where
6101 the epilogue begins. Update the basic block information when possible. */
6102
6103void
6104thread_prologue_and_epilogue_insns (f)
6105 rtx f;
6106{
6107#ifdef HAVE_prologue
6108 if (HAVE_prologue)
6109 {
29a82058 6110 rtx head, seq;
bdac5f58
TW
6111
6112 /* The first insn (a NOTE_INSN_DELETED) is followed by zero or more
6113 prologue insns and a NOTE_INSN_PROLOGUE_END. */
6114 emit_note_after (NOTE_INSN_PROLOGUE_END, f);
6115 seq = gen_prologue ();
6116 head = emit_insn_after (seq, f);
6117
6118 /* Include the new prologue insns in the first block. Ignore them
6119 if they form a basic block unto themselves. */
6120 if (basic_block_head && n_basic_blocks
6121 && GET_CODE (basic_block_head[0]) != CODE_LABEL)
6122 basic_block_head[0] = NEXT_INSN (f);
6123
6124 /* Retain a map of the prologue insns. */
6125 prologue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : head);
6126 }
6127 else
6128#endif
6129 prologue = 0;
6130
6131#ifdef HAVE_epilogue
6132 if (HAVE_epilogue)
6133 {
6134 rtx insn = get_last_insn ();
6135 rtx prev = prev_nonnote_insn (insn);
6136
6137 /* If we end with a BARRIER, we don't need an epilogue. */
6138 if (! (prev && GET_CODE (prev) == BARRIER))
6139 {
a78bdb38
JW
6140 rtx tail, seq, tem;
6141 rtx first_use = 0;
6142 rtx last_use = 0;
bdac5f58 6143
a78bdb38
JW
6144 /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG, the
6145 epilogue insns, the USE insns at the end of a function,
6146 the jump insn that returns, and then a BARRIER. */
bdac5f58 6147
a78bdb38 6148 /* Move the USE insns at the end of a function onto a list. */
bdac5f58
TW
6149 while (prev
6150 && GET_CODE (prev) == INSN
6151 && GET_CODE (PATTERN (prev)) == USE)
6152 {
a78bdb38 6153 tem = prev;
bdac5f58 6154 prev = prev_nonnote_insn (prev);
a78bdb38
JW
6155
6156 NEXT_INSN (PREV_INSN (tem)) = NEXT_INSN (tem);
6157 PREV_INSN (NEXT_INSN (tem)) = PREV_INSN (tem);
83eb3b0d
RK
6158 if (first_use)
6159 {
6160 NEXT_INSN (tem) = first_use;
6161 PREV_INSN (first_use) = tem;
6162 }
6163 first_use = tem;
6164 if (!last_use)
a78bdb38 6165 last_use = tem;
bdac5f58
TW
6166 }
6167
a78bdb38
JW
6168 emit_barrier_after (insn);
6169
bdac5f58
TW
6170 seq = gen_epilogue ();
6171 tail = emit_jump_insn_after (seq, insn);
a78bdb38
JW
6172
6173 /* Insert the USE insns immediately before the return insn, which
6174 must be the first instruction before the final barrier. */
6175 if (first_use)
6176 {
6177 tem = prev_nonnote_insn (get_last_insn ());
6178 NEXT_INSN (PREV_INSN (tem)) = first_use;
6179 PREV_INSN (first_use) = PREV_INSN (tem);
6180 PREV_INSN (tem) = last_use;
6181 NEXT_INSN (last_use) = tem;
6182 }
6183
bdac5f58
TW
6184 emit_note_after (NOTE_INSN_EPILOGUE_BEG, insn);
6185
6186 /* Include the new epilogue insns in the last block. Ignore
6187 them if they form a basic block unto themselves. */
6188 if (basic_block_end && n_basic_blocks
6189 && GET_CODE (basic_block_end[n_basic_blocks - 1]) != JUMP_INSN)
6190 basic_block_end[n_basic_blocks - 1] = tail;
6191
6192 /* Retain a map of the epilogue insns. */
6193 epilogue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : tail);
6194 return;
6195 }
6196 }
6197#endif
6198 epilogue = 0;
6199}
6200
6201/* Reposition the prologue-end and epilogue-begin notes after instruction
6202 scheduling and delayed branch scheduling. */
6203
6204void
6205reposition_prologue_and_epilogue_notes (f)
6206 rtx f;
6207{
6208#if defined (HAVE_prologue) || defined (HAVE_epilogue)
6209 /* Reposition the prologue and epilogue notes. */
6210 if (n_basic_blocks)
6211 {
6212 rtx next, prev;
bf526252 6213 int len;
bdac5f58
TW
6214
6215 if (prologue)
6216 {
bf526252
RK
6217 register rtx insn, note = 0;
6218
6219 /* Scan from the beginning until we reach the last prologue insn.
6220 We apparently can't depend on basic_block_{head,end} after
6221 reorg has run. */
6222 for (len = 0; prologue[len]; len++)
6223 ;
9392c110
JH
6224 for (insn = f; len && insn; insn = NEXT_INSN (insn))
6225 {
6226 if (GET_CODE (insn) == NOTE)
6227 {
6228 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
6229 note = insn;
6230 }
6231 else if ((len -= contains (insn, prologue)) == 0)
6232 {
6233 /* Find the prologue-end note if we haven't already, and
6234 move it to just after the last prologue insn. */
6235 if (note == 0)
6236 {
51723711 6237 for (note = insn; (note = NEXT_INSN (note));)
9392c110
JH
6238 if (GET_CODE (note) == NOTE
6239 && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
6240 break;
6241 }
c93b03c2 6242
9392c110
JH
6243 next = NEXT_INSN (note);
6244 prev = PREV_INSN (note);
6245 if (prev)
6246 NEXT_INSN (prev) = next;
6247 if (next)
6248 PREV_INSN (next) = prev;
c93b03c2
RH
6249
6250 /* Whether or not we can depend on basic_block_head,
6251 attempt to keep it up-to-date. */
6252 if (basic_block_head[0] == note)
6253 basic_block_head[0] = next;
6254
9392c110
JH
6255 add_insn_after (note, insn);
6256 }
6257 }
bdac5f58
TW
6258 }
6259
6260 if (epilogue)
6261 {
bf526252
RK
6262 register rtx insn, note = 0;
6263
6264 /* Scan from the end until we reach the first epilogue insn.
6265 We apparently can't depend on basic_block_{head,end} after
6266 reorg has run. */
6267 for (len = 0; epilogue[len]; len++)
6268 ;
9392c110
JH
6269 for (insn = get_last_insn (); len && insn; insn = PREV_INSN (insn))
6270 {
6271 if (GET_CODE (insn) == NOTE)
6272 {
6273 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
6274 note = insn;
6275 }
6276 else if ((len -= contains (insn, epilogue)) == 0)
6277 {
6278 /* Find the epilogue-begin note if we haven't already, and
6279 move it to just before the first epilogue insn. */
6280 if (note == 0)
6281 {
51723711 6282 for (note = insn; (note = PREV_INSN (note));)
9392c110
JH
6283 if (GET_CODE (note) == NOTE
6284 && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
6285 break;
6286 }
6287 next = NEXT_INSN (note);
6288 prev = PREV_INSN (note);
6289 if (prev)
6290 NEXT_INSN (prev) = next;
6291 if (next)
6292 PREV_INSN (next) = prev;
c93b03c2
RH
6293
6294 /* Whether or not we can depend on basic_block_head,
6295 attempt to keep it up-to-date. */
6296 if (n_basic_blocks
6297 && basic_block_head[n_basic_blocks-1] == insn)
6298 basic_block_head[n_basic_blocks-1] = note;
6299
6300 add_insn_before (note, insn);
9392c110
JH
6301 }
6302 }
bdac5f58
TW
6303 }
6304 }
6305#endif /* HAVE_prologue or HAVE_epilogue */
6306}
This page took 1.474526 seconds and 5 git commands to generate.