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