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