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