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