1 /* Expands front end tree to back end RTL for GNU C-Compiler
2 Copyright (C) 1987, 88, 89, 91-96, 1997 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* This file handles the generation of rtl code from tree structure
23 at the level of the function as a whole.
24 It creates the rtl expressions for parameters and auto variables
25 and has full responsibility for allocating stack slots.
27 `expand_function_start' is called at the beginning of a function,
28 before the function body is parsed, and `expand_function_end' is
29 called after parsing the body.
31 Call `assign_stack_local' to allocate a stack slot for a local variable.
32 This is usually done during the RTL generation for the function body,
33 but it can also be done in the reload pass when a pseudo-register does
34 not get a hard register.
36 Call `put_var_into_stack' when you learn, belatedly, that a variable
37 previously given a pseudo-register must in fact go in the stack.
38 This function changes the DECL_RTL to be a stack slot instead of a reg
39 then scans all the RTL instructions so far generated to correct them. */
48 #include "insn-flags.h"
50 #include "insn-codes.h"
52 #include "hard-reg-set.h"
53 #include "insn-config.h"
56 #include "basic-block.h"
61 #ifndef TRAMPOLINE_ALIGNMENT
62 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
65 /* Some systems use __main in a way incompatible with its use in gcc, in these
66 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
67 give the same symbol without quotes for an alternative entry point. You
68 must define both, or neither. */
70 #define NAME__MAIN "__main"
71 #define SYMBOL__MAIN __main
74 /* Round a value to the lowest integer less than it that is a multiple of
75 the required alignment. Avoid using division in case the value is
76 negative. Assume the alignment is a power of two. */
77 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
79 /* Similar, but round to the next highest integer that meets the
81 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
83 /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp
84 during rtl generation. If they are different register numbers, this is
85 always true. It may also be true if
86 FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl
87 generation. See fix_lexical_addr for details. */
89 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
90 #define NEED_SEPARATE_AP
93 /* Number of bytes of args popped by function being compiled on its return.
94 Zero if no bytes are to be popped.
95 May affect compilation of return insn or of function epilogue. */
97 int current_function_pops_args
;
99 /* Nonzero if function being compiled needs to be given an address
100 where the value should be stored. */
102 int current_function_returns_struct
;
104 /* Nonzero if function being compiled needs to
105 return the address of where it has put a structure value. */
107 int current_function_returns_pcc_struct
;
109 /* Nonzero if function being compiled needs to be passed a static chain. */
111 int current_function_needs_context
;
113 /* Nonzero if function being compiled can call setjmp. */
115 int current_function_calls_setjmp
;
117 /* Nonzero if function being compiled can call longjmp. */
119 int current_function_calls_longjmp
;
121 /* Nonzero if function being compiled receives nonlocal gotos
122 from nested functions. */
124 int current_function_has_nonlocal_label
;
126 /* Nonzero if function being compiled has nonlocal gotos to parent
129 int current_function_has_nonlocal_goto
;
131 /* Nonzero if function being compiled contains nested functions. */
133 int current_function_contains_functions
;
135 /* Nonzero if the current function is a thunk (a lightweight function that
136 just adjusts one of its arguments and forwards to another function), so
137 we should try to cut corners where we can. */
138 int current_function_is_thunk
;
140 /* Nonzero if function being compiled can call alloca,
141 either as a subroutine or builtin. */
143 int current_function_calls_alloca
;
145 /* Nonzero if the current function returns a pointer type */
147 int current_function_returns_pointer
;
149 /* If some insns can be deferred to the delay slots of the epilogue, the
150 delay list for them is recorded here. */
152 rtx current_function_epilogue_delay_list
;
154 /* If function's args have a fixed size, this is that size, in bytes.
156 May affect compilation of return insn or of function epilogue. */
158 int current_function_args_size
;
160 /* # bytes the prologue should push and pretend that the caller pushed them.
161 The prologue must do this, but only if parms can be passed in registers. */
163 int current_function_pretend_args_size
;
165 /* # of bytes of outgoing arguments. If ACCUMULATE_OUTGOING_ARGS is
166 defined, the needed space is pushed by the prologue. */
168 int current_function_outgoing_args_size
;
170 /* This is the offset from the arg pointer to the place where the first
171 anonymous arg can be found, if there is one. */
173 rtx current_function_arg_offset_rtx
;
175 /* Nonzero if current function uses varargs.h or equivalent.
176 Zero for functions that use stdarg.h. */
178 int current_function_varargs
;
180 /* Nonzero if current function uses stdarg.h or equivalent.
181 Zero for functions that use varargs.h. */
183 int current_function_stdarg
;
185 /* Quantities of various kinds of registers
186 used for the current function's args. */
188 CUMULATIVE_ARGS current_function_args_info
;
190 /* Name of function now being compiled. */
192 char *current_function_name
;
194 /* If non-zero, an RTL expression for that location at which the current
195 function returns its result. Always equal to
196 DECL_RTL (DECL_RESULT (current_function_decl)), but provided
197 independently of the tree structures. */
199 rtx current_function_return_rtx
;
201 /* Nonzero if the current function uses the constant pool. */
203 int current_function_uses_const_pool
;
205 /* Nonzero if the current function uses pic_offset_table_rtx. */
206 int current_function_uses_pic_offset_table
;
208 /* The arg pointer hard register, or the pseudo into which it was copied. */
209 rtx current_function_internal_arg_pointer
;
211 /* The FUNCTION_DECL for an inline function currently being expanded. */
212 tree inline_function_decl
;
214 /* Number of function calls seen so far in current function. */
216 int function_call_count
;
218 /* List (chain of TREE_LIST) of LABEL_DECLs for all nonlocal labels
219 (labels to which there can be nonlocal gotos from nested functions)
222 tree nonlocal_labels
;
224 /* RTX for stack slot that holds the current handler for nonlocal gotos.
225 Zero when function does not have nonlocal labels. */
227 rtx nonlocal_goto_handler_slot
;
229 /* RTX for stack slot that holds the stack pointer value to restore
231 Zero when function does not have nonlocal labels. */
233 rtx nonlocal_goto_stack_level
;
235 /* Label that will go on parm cleanup code, if any.
236 Jumping to this label runs cleanup code for parameters, if
237 such code must be run. Following this code is the logical return label. */
241 /* Label that will go on function epilogue.
242 Jumping to this label serves as a "return" instruction
243 on machines which require execution of the epilogue on all returns. */
247 /* List (chain of EXPR_LISTs) of pseudo-regs of SAVE_EXPRs.
248 So we can mark them all live at the end of the function, if nonopt. */
251 /* List (chain of EXPR_LISTs) of all stack slots in this function.
252 Made for the sake of unshare_all_rtl. */
255 /* Chain of all RTL_EXPRs that have insns in them. */
258 /* Label to jump back to for tail recursion, or 0 if we have
259 not yet needed one for this function. */
260 rtx tail_recursion_label
;
262 /* Place after which to insert the tail_recursion_label if we need one. */
263 rtx tail_recursion_reentry
;
265 /* Location at which to save the argument pointer if it will need to be
266 referenced. There are two cases where this is done: if nonlocal gotos
267 exist, or if vars stored at an offset from the argument pointer will be
268 needed by inner routines. */
270 rtx arg_pointer_save_area
;
272 /* Offset to end of allocated area of stack frame.
273 If stack grows down, this is the address of the last stack slot allocated.
274 If stack grows up, this is the address for the next slot. */
275 HOST_WIDE_INT frame_offset
;
277 /* List (chain of TREE_LISTs) of static chains for containing functions.
278 Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
279 in an RTL_EXPR in the TREE_VALUE. */
280 static tree context_display
;
282 /* List (chain of TREE_LISTs) of trampolines for nested functions.
283 The trampoline sets up the static chain and jumps to the function.
284 We supply the trampoline's address when the function's address is requested.
286 Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
287 in an RTL_EXPR in the TREE_VALUE. */
288 static tree trampoline_list
;
290 /* Insn after which register parms and SAVE_EXPRs are born, if nonopt. */
291 static rtx parm_birth_insn
;
294 /* Nonzero if a stack slot has been generated whose address is not
295 actually valid. It means that the generated rtl must all be scanned
296 to detect and correct the invalid addresses where they occur. */
297 static int invalid_stack_slot
;
300 /* Last insn of those whose job was to put parms into their nominal homes. */
301 static rtx last_parm_insn
;
303 /* 1 + last pseudo register number used for loading a copy
304 of a parameter of this function. */
305 static int max_parm_reg
;
307 /* Vector indexed by REGNO, containing location on stack in which
308 to put the parm which is nominally in pseudo register REGNO,
309 if we discover that that parm must go in the stack. */
310 static rtx
*parm_reg_stack_loc
;
312 /* Nonzero once virtual register instantiation has been done.
313 assign_stack_local uses frame_pointer_rtx when this is nonzero. */
314 static int virtuals_instantiated
;
316 /* These variables hold pointers to functions to
317 save and restore machine-specific data,
318 in push_function_context and pop_function_context. */
319 void (*save_machine_status
) PROTO((struct function
*));
320 void (*restore_machine_status
) PROTO((struct function
*));
322 /* Nonzero if we need to distinguish between the return value of this function
323 and the return value of a function called by this function. This helps
326 extern int rtx_equal_function_value_matters
;
327 extern tree sequence_rtl_expr
;
329 /* In order to evaluate some expressions, such as function calls returning
330 structures in memory, we need to temporarily allocate stack locations.
331 We record each allocated temporary in the following structure.
333 Associated with each temporary slot is a nesting level. When we pop up
334 one level, all temporaries associated with the previous level are freed.
335 Normally, all temporaries are freed after the execution of the statement
336 in which they were created. However, if we are inside a ({...}) grouping,
337 the result may be in a temporary and hence must be preserved. If the
338 result could be in a temporary, we preserve it if we can determine which
339 one it is in. If we cannot determine which temporary may contain the
340 result, all temporaries are preserved. A temporary is preserved by
341 pretending it was allocated at the previous nesting level.
343 Automatic variables are also assigned temporary slots, at the nesting
344 level where they are defined. They are marked a "kept" so that
345 free_temp_slots will not free them. */
349 /* Points to next temporary slot. */
350 struct temp_slot
*next
;
351 /* The rtx to used to reference the slot. */
353 /* The rtx used to represent the address if not the address of the
354 slot above. May be an EXPR_LIST if multiple addresses exist. */
356 /* The size, in units, of the slot. */
358 /* The value of `sequence_rtl_expr' when this temporary is allocated. */
360 /* Non-zero if this temporary is currently in use. */
362 /* Non-zero if this temporary has its address taken. */
364 /* Nesting level at which this slot is being used. */
366 /* Non-zero if this should survive a call to free_temp_slots. */
368 /* The offset of the slot from the frame_pointer, including extra space
369 for alignment. This info is for combine_temp_slots. */
371 /* The size of the slot, including extra space for alignment. This
372 info is for combine_temp_slots. */
376 /* List of all temporaries allocated, both available and in use. */
378 struct temp_slot
*temp_slots
;
380 /* Current nesting level for temporaries. */
384 /* The FUNCTION_DECL node for the current function. */
385 static tree this_function_decl
;
387 /* Callinfo pointer for the current function. */
388 static rtx this_function_callinfo
;
390 /* The label in the bytecode file of this function's actual bytecode.
392 static char *this_function_bytecode
;
394 /* The call description vector for the current function. */
395 static rtx this_function_calldesc
;
397 /* Size of the local variables allocated for the current function. */
400 /* Current depth of the bytecode evaluation stack. */
403 /* Maximum depth of the evaluation stack in this function. */
406 /* Current depth in statement expressions. */
407 static int stmt_expr_depth
;
409 /* This structure is used to record MEMs or pseudos used to replace VAR, any
410 SUBREGs of VAR, and any MEMs containing VAR as an address. We need to
411 maintain this list in case two operands of an insn were required to match;
412 in that case we must ensure we use the same replacement. */
414 struct fixup_replacement
418 struct fixup_replacement
*next
;
421 /* Forward declarations. */
423 static struct temp_slot
*find_temp_slot_from_address
PROTO((rtx
));
424 static void put_reg_into_stack
PROTO((struct function
*, rtx
, tree
,
425 enum machine_mode
, enum machine_mode
,
427 static void fixup_var_refs
PROTO((rtx
, enum machine_mode
, int));
428 static struct fixup_replacement
429 *find_fixup_replacement
PROTO((struct fixup_replacement
**, rtx
));
430 static void fixup_var_refs_insns
PROTO((rtx
, enum machine_mode
, int,
432 static void fixup_var_refs_1
PROTO((rtx
, enum machine_mode
, rtx
*, rtx
,
433 struct fixup_replacement
**));
434 static rtx fixup_memory_subreg
PROTO((rtx
, rtx
, int));
435 static rtx walk_fixup_memory_subreg
PROTO((rtx
, rtx
, int));
436 static rtx fixup_stack_1
PROTO((rtx
, rtx
));
437 static void optimize_bit_field
PROTO((rtx
, rtx
, rtx
*));
438 static void instantiate_decls
PROTO((tree
, int));
439 static void instantiate_decls_1
PROTO((tree
, int));
440 static void instantiate_decl
PROTO((rtx
, int, int));
441 static int instantiate_virtual_regs_1
PROTO((rtx
*, rtx
, int));
442 static void delete_handlers
PROTO((void));
443 static void pad_to_arg_alignment
PROTO((struct args_size
*, int));
444 static void pad_below
PROTO((struct args_size
*, enum machine_mode
,
446 static tree round_down
PROTO((tree
, int));
447 static rtx round_trampoline_addr
PROTO((rtx
));
448 static tree blocks_nreverse
PROTO((tree
));
449 static int all_blocks
PROTO((tree
, tree
*));
450 static int *record_insns
PROTO((rtx
));
451 static int contains
PROTO((rtx
, int *));
453 /* Pointer to chain of `struct function' for containing functions. */
454 struct function
*outer_function_chain
;
456 /* Given a function decl for a containing function,
457 return the `struct function' for it. */
460 find_function_data (decl
)
464 for (p
= outer_function_chain
; p
; p
= p
->next
)
470 /* Save the current context for compilation of a nested function.
471 This is called from language-specific code.
472 The caller is responsible for saving any language-specific status,
473 since this function knows only about language-independent variables. */
476 push_function_context_to (context
)
479 struct function
*p
= (struct function
*) xmalloc (sizeof (struct function
));
481 p
->next
= outer_function_chain
;
482 outer_function_chain
= p
;
484 p
->name
= current_function_name
;
485 p
->decl
= current_function_decl
;
486 p
->pops_args
= current_function_pops_args
;
487 p
->returns_struct
= current_function_returns_struct
;
488 p
->returns_pcc_struct
= current_function_returns_pcc_struct
;
489 p
->returns_pointer
= current_function_returns_pointer
;
490 p
->needs_context
= current_function_needs_context
;
491 p
->calls_setjmp
= current_function_calls_setjmp
;
492 p
->calls_longjmp
= current_function_calls_longjmp
;
493 p
->calls_alloca
= current_function_calls_alloca
;
494 p
->has_nonlocal_label
= current_function_has_nonlocal_label
;
495 p
->has_nonlocal_goto
= current_function_has_nonlocal_goto
;
496 p
->contains_functions
= current_function_contains_functions
;
497 p
->is_thunk
= current_function_is_thunk
;
498 p
->args_size
= current_function_args_size
;
499 p
->pretend_args_size
= current_function_pretend_args_size
;
500 p
->arg_offset_rtx
= current_function_arg_offset_rtx
;
501 p
->varargs
= current_function_varargs
;
502 p
->stdarg
= current_function_stdarg
;
503 p
->uses_const_pool
= current_function_uses_const_pool
;
504 p
->uses_pic_offset_table
= current_function_uses_pic_offset_table
;
505 p
->internal_arg_pointer
= current_function_internal_arg_pointer
;
506 p
->max_parm_reg
= max_parm_reg
;
507 p
->parm_reg_stack_loc
= parm_reg_stack_loc
;
508 p
->outgoing_args_size
= current_function_outgoing_args_size
;
509 p
->return_rtx
= current_function_return_rtx
;
510 p
->nonlocal_goto_handler_slot
= nonlocal_goto_handler_slot
;
511 p
->nonlocal_goto_stack_level
= nonlocal_goto_stack_level
;
512 p
->nonlocal_labels
= nonlocal_labels
;
513 p
->cleanup_label
= cleanup_label
;
514 p
->return_label
= return_label
;
515 p
->save_expr_regs
= save_expr_regs
;
516 p
->stack_slot_list
= stack_slot_list
;
517 p
->parm_birth_insn
= parm_birth_insn
;
518 p
->frame_offset
= frame_offset
;
519 p
->tail_recursion_label
= tail_recursion_label
;
520 p
->tail_recursion_reentry
= tail_recursion_reentry
;
521 p
->arg_pointer_save_area
= arg_pointer_save_area
;
522 p
->rtl_expr_chain
= rtl_expr_chain
;
523 p
->last_parm_insn
= last_parm_insn
;
524 p
->context_display
= context_display
;
525 p
->trampoline_list
= trampoline_list
;
526 p
->function_call_count
= function_call_count
;
527 p
->temp_slots
= temp_slots
;
528 p
->temp_slot_level
= temp_slot_level
;
529 p
->fixup_var_refs_queue
= 0;
530 p
->epilogue_delay_list
= current_function_epilogue_delay_list
;
531 p
->args_info
= current_function_args_info
;
533 save_tree_status (p
, context
);
534 save_storage_status (p
);
535 save_emit_status (p
);
537 save_expr_status (p
);
538 save_stmt_status (p
);
539 save_varasm_status (p
);
541 if (save_machine_status
)
542 (*save_machine_status
) (p
);
546 push_function_context ()
548 push_function_context_to (current_function_decl
);
551 /* Restore the last saved context, at the end of a nested function.
552 This function is called from language-specific code. */
555 pop_function_context_from (context
)
558 struct function
*p
= outer_function_chain
;
560 outer_function_chain
= p
->next
;
562 current_function_contains_functions
563 = p
->contains_functions
|| p
->inline_obstacks
564 || context
== current_function_decl
;
565 current_function_name
= p
->name
;
566 current_function_decl
= p
->decl
;
567 current_function_pops_args
= p
->pops_args
;
568 current_function_returns_struct
= p
->returns_struct
;
569 current_function_returns_pcc_struct
= p
->returns_pcc_struct
;
570 current_function_returns_pointer
= p
->returns_pointer
;
571 current_function_needs_context
= p
->needs_context
;
572 current_function_calls_setjmp
= p
->calls_setjmp
;
573 current_function_calls_longjmp
= p
->calls_longjmp
;
574 current_function_calls_alloca
= p
->calls_alloca
;
575 current_function_has_nonlocal_label
= p
->has_nonlocal_label
;
576 current_function_has_nonlocal_goto
= p
->has_nonlocal_goto
;
577 current_function_is_thunk
= p
->is_thunk
;
578 current_function_args_size
= p
->args_size
;
579 current_function_pretend_args_size
= p
->pretend_args_size
;
580 current_function_arg_offset_rtx
= p
->arg_offset_rtx
;
581 current_function_varargs
= p
->varargs
;
582 current_function_stdarg
= p
->stdarg
;
583 current_function_uses_const_pool
= p
->uses_const_pool
;
584 current_function_uses_pic_offset_table
= p
->uses_pic_offset_table
;
585 current_function_internal_arg_pointer
= p
->internal_arg_pointer
;
586 max_parm_reg
= p
->max_parm_reg
;
587 parm_reg_stack_loc
= p
->parm_reg_stack_loc
;
588 current_function_outgoing_args_size
= p
->outgoing_args_size
;
589 current_function_return_rtx
= p
->return_rtx
;
590 nonlocal_goto_handler_slot
= p
->nonlocal_goto_handler_slot
;
591 nonlocal_goto_stack_level
= p
->nonlocal_goto_stack_level
;
592 nonlocal_labels
= p
->nonlocal_labels
;
593 cleanup_label
= p
->cleanup_label
;
594 return_label
= p
->return_label
;
595 save_expr_regs
= p
->save_expr_regs
;
596 stack_slot_list
= p
->stack_slot_list
;
597 parm_birth_insn
= p
->parm_birth_insn
;
598 frame_offset
= p
->frame_offset
;
599 tail_recursion_label
= p
->tail_recursion_label
;
600 tail_recursion_reentry
= p
->tail_recursion_reentry
;
601 arg_pointer_save_area
= p
->arg_pointer_save_area
;
602 rtl_expr_chain
= p
->rtl_expr_chain
;
603 last_parm_insn
= p
->last_parm_insn
;
604 context_display
= p
->context_display
;
605 trampoline_list
= p
->trampoline_list
;
606 function_call_count
= p
->function_call_count
;
607 temp_slots
= p
->temp_slots
;
608 temp_slot_level
= p
->temp_slot_level
;
609 current_function_epilogue_delay_list
= p
->epilogue_delay_list
;
611 current_function_args_info
= p
->args_info
;
613 restore_tree_status (p
);
614 restore_storage_status (p
);
615 restore_expr_status (p
);
616 restore_emit_status (p
);
617 restore_stmt_status (p
);
618 restore_varasm_status (p
);
620 if (restore_machine_status
)
621 (*restore_machine_status
) (p
);
623 /* Finish doing put_var_into_stack for any of our variables
624 which became addressable during the nested function. */
626 struct var_refs_queue
*queue
= p
->fixup_var_refs_queue
;
627 for (; queue
; queue
= queue
->next
)
628 fixup_var_refs (queue
->modified
, queue
->promoted_mode
, queue
->unsignedp
);
633 /* Reset variables that have known state during rtx generation. */
634 rtx_equal_function_value_matters
= 1;
635 virtuals_instantiated
= 0;
638 void pop_function_context ()
640 pop_function_context_from (current_function_decl
);
643 /* Allocate fixed slots in the stack frame of the current function. */
645 /* Return size needed for stack frame based on slots so far allocated.
646 This size counts from zero. It is not rounded to STACK_BOUNDARY;
647 the caller may have to do that. */
652 #ifdef FRAME_GROWS_DOWNWARD
653 return -frame_offset
;
659 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
660 with machine mode MODE.
662 ALIGN controls the amount of alignment for the address of the slot:
663 0 means according to MODE,
664 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
665 positive specifies alignment boundary in bits.
667 We do not round to stack_boundary here. */
670 assign_stack_local (mode
, size
, align
)
671 enum machine_mode mode
;
675 register rtx x
, addr
;
676 int bigend_correction
= 0;
681 alignment
= GET_MODE_ALIGNMENT (mode
) / BITS_PER_UNIT
;
683 alignment
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
685 else if (align
== -1)
687 alignment
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
688 size
= CEIL_ROUND (size
, alignment
);
691 alignment
= align
/ BITS_PER_UNIT
;
693 /* Round frame offset to that alignment.
694 We must be careful here, since FRAME_OFFSET might be negative and
695 division with a negative dividend isn't as well defined as we might
696 like. So we instead assume that ALIGNMENT is a power of two and
697 use logical operations which are unambiguous. */
698 #ifdef FRAME_GROWS_DOWNWARD
699 frame_offset
= FLOOR_ROUND (frame_offset
, alignment
);
701 frame_offset
= CEIL_ROUND (frame_offset
, alignment
);
704 /* On a big-endian machine, if we are allocating more space than we will use,
705 use the least significant bytes of those that are allocated. */
706 if (BYTES_BIG_ENDIAN
&& mode
!= BLKmode
)
707 bigend_correction
= size
- GET_MODE_SIZE (mode
);
709 #ifdef FRAME_GROWS_DOWNWARD
710 frame_offset
-= size
;
713 /* If we have already instantiated virtual registers, return the actual
714 address relative to the frame pointer. */
715 if (virtuals_instantiated
)
716 addr
= plus_constant (frame_pointer_rtx
,
717 (frame_offset
+ bigend_correction
718 + STARTING_FRAME_OFFSET
));
720 addr
= plus_constant (virtual_stack_vars_rtx
,
721 frame_offset
+ bigend_correction
);
723 #ifndef FRAME_GROWS_DOWNWARD
724 frame_offset
+= size
;
727 x
= gen_rtx (MEM
, mode
, addr
);
729 stack_slot_list
= gen_rtx (EXPR_LIST
, VOIDmode
, x
, stack_slot_list
);
734 /* Assign a stack slot in a containing function.
735 First three arguments are same as in preceding function.
736 The last argument specifies the function to allocate in. */
739 assign_outer_stack_local (mode
, size
, align
, function
)
740 enum machine_mode mode
;
743 struct function
*function
;
745 register rtx x
, addr
;
746 int bigend_correction
= 0;
749 /* Allocate in the memory associated with the function in whose frame
751 push_obstacks (function
->function_obstack
,
752 function
->function_maybepermanent_obstack
);
756 alignment
= GET_MODE_ALIGNMENT (mode
) / BITS_PER_UNIT
;
758 alignment
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
760 else if (align
== -1)
762 alignment
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
763 size
= CEIL_ROUND (size
, alignment
);
766 alignment
= align
/ BITS_PER_UNIT
;
768 /* Round frame offset to that alignment. */
769 #ifdef FRAME_GROWS_DOWNWARD
770 function
->frame_offset
= FLOOR_ROUND (function
->frame_offset
, alignment
);
772 function
->frame_offset
= CEIL_ROUND (function
->frame_offset
, alignment
);
775 /* On a big-endian machine, if we are allocating more space than we will use,
776 use the least significant bytes of those that are allocated. */
777 if (BYTES_BIG_ENDIAN
&& mode
!= BLKmode
)
778 bigend_correction
= size
- GET_MODE_SIZE (mode
);
780 #ifdef FRAME_GROWS_DOWNWARD
781 function
->frame_offset
-= size
;
783 addr
= plus_constant (virtual_stack_vars_rtx
,
784 function
->frame_offset
+ bigend_correction
);
785 #ifndef FRAME_GROWS_DOWNWARD
786 function
->frame_offset
+= size
;
789 x
= gen_rtx (MEM
, mode
, addr
);
791 function
->stack_slot_list
792 = gen_rtx (EXPR_LIST
, VOIDmode
, x
, function
->stack_slot_list
);
799 /* Allocate a temporary stack slot and record it for possible later
802 MODE is the machine mode to be given to the returned rtx.
804 SIZE is the size in units of the space required. We do no rounding here
805 since assign_stack_local will do any required rounding.
807 KEEP is 1 if this slot is to be retained after a call to
808 free_temp_slots. Automatic variables for a block are allocated
809 with this flag. KEEP is 2, if we allocate a longer term temporary,
810 whose lifetime is controlled by CLEANUP_POINT_EXPRs. */
813 assign_stack_temp (mode
, size
, keep
)
814 enum machine_mode mode
;
818 struct temp_slot
*p
, *best_p
= 0;
820 /* If SIZE is -1 it means that somebody tried to allocate a temporary
821 of a variable size. */
825 /* First try to find an available, already-allocated temporary that is the
826 exact size we require. */
827 for (p
= temp_slots
; p
; p
= p
->next
)
828 if (p
->size
== size
&& GET_MODE (p
->slot
) == mode
&& ! p
->in_use
)
831 /* If we didn't find, one, try one that is larger than what we want. We
832 find the smallest such. */
834 for (p
= temp_slots
; p
; p
= p
->next
)
835 if (p
->size
> size
&& GET_MODE (p
->slot
) == mode
&& ! p
->in_use
836 && (best_p
== 0 || best_p
->size
> p
->size
))
839 /* Make our best, if any, the one to use. */
842 /* If there are enough aligned bytes left over, make them into a new
843 temp_slot so that the extra bytes don't get wasted. Do this only
844 for BLKmode slots, so that we can be sure of the alignment. */
845 if (GET_MODE (best_p
->slot
) == BLKmode
)
847 int alignment
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
848 int rounded_size
= CEIL_ROUND (size
, alignment
);
850 if (best_p
->size
- rounded_size
>= alignment
)
852 p
= (struct temp_slot
*) oballoc (sizeof (struct temp_slot
));
853 p
->in_use
= p
->addr_taken
= 0;
854 p
->size
= best_p
->size
- rounded_size
;
855 p
->base_offset
= best_p
->base_offset
+ rounded_size
;
856 p
->full_size
= best_p
->full_size
- rounded_size
;
857 p
->slot
= gen_rtx (MEM
, BLKmode
,
858 plus_constant (XEXP (best_p
->slot
, 0),
862 p
->next
= temp_slots
;
865 stack_slot_list
= gen_rtx (EXPR_LIST
, VOIDmode
, p
->slot
,
868 best_p
->size
= rounded_size
;
869 best_p
->full_size
= rounded_size
;
876 /* If we still didn't find one, make a new temporary. */
879 int frame_offset_old
= frame_offset
;
880 p
= (struct temp_slot
*) oballoc (sizeof (struct temp_slot
));
881 /* If the temp slot mode doesn't indicate the alignment,
882 use the largest possible, so no one will be disappointed. */
883 p
->slot
= assign_stack_local (mode
, size
, mode
== BLKmode
? -1 : 0);
884 /* The following slot size computation is necessary because we don't
885 know the actual size of the temporary slot until assign_stack_local
886 has performed all the frame alignment and size rounding for the
887 requested temporary. Note that extra space added for alignment
888 can be either above or below this stack slot depending on which
889 way the frame grows. We include the extra space if and only if it
890 is above this slot. */
891 #ifdef FRAME_GROWS_DOWNWARD
892 p
->size
= frame_offset_old
- frame_offset
;
896 /* Now define the fields used by combine_temp_slots. */
897 #ifdef FRAME_GROWS_DOWNWARD
898 p
->base_offset
= frame_offset
;
899 p
->full_size
= frame_offset_old
- frame_offset
;
901 p
->base_offset
= frame_offset_old
;
902 p
->full_size
= frame_offset
- frame_offset_old
;
905 p
->next
= temp_slots
;
911 p
->rtl_expr
= sequence_rtl_expr
;
915 p
->level
= target_temp_slot_level
;
920 p
->level
= temp_slot_level
;
924 /* We may be reusing an old slot, so clear any MEM flags that may have been
926 RTX_UNCHANGING_P (p
->slot
) = 0;
927 MEM_IN_STRUCT_P (p
->slot
) = 0;
931 /* Assign a temporary of given TYPE.
932 KEEP is as for assign_stack_temp.
933 MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
934 it is 0 if a register is OK.
935 DONT_PROMOTE is 1 if we should not promote values in register
939 assign_temp (type
, keep
, memory_required
, dont_promote
)
945 enum machine_mode mode
= TYPE_MODE (type
);
946 int unsignedp
= TREE_UNSIGNED (type
);
948 if (mode
== BLKmode
|| memory_required
)
950 int size
= int_size_in_bytes (type
);
953 /* Unfortunately, we don't yet know how to allocate variable-sized
954 temporaries. However, sometimes we have a fixed upper limit on
955 the size (which is stored in TYPE_ARRAY_MAX_SIZE) and can use that
956 instead. This is the case for Chill variable-sized strings. */
957 if (size
== -1 && TREE_CODE (type
) == ARRAY_TYPE
958 && TYPE_ARRAY_MAX_SIZE (type
) != NULL_TREE
959 && TREE_CODE (TYPE_ARRAY_MAX_SIZE (type
)) == INTEGER_CST
)
960 size
= TREE_INT_CST_LOW (TYPE_ARRAY_MAX_SIZE (type
));
962 tmp
= assign_stack_temp (mode
, size
, keep
);
963 MEM_IN_STRUCT_P (tmp
) = AGGREGATE_TYPE_P (type
);
967 #ifndef PROMOTE_FOR_CALL_ONLY
969 mode
= promote_mode (type
, mode
, &unsignedp
, 0);
972 return gen_reg_rtx (mode
);
975 /* Combine temporary stack slots which are adjacent on the stack.
977 This allows for better use of already allocated stack space. This is only
978 done for BLKmode slots because we can be sure that we won't have alignment
979 problems in this case. */
982 combine_temp_slots ()
984 struct temp_slot
*p
, *q
;
985 struct temp_slot
*prev_p
, *prev_q
;
986 /* Determine where to free back to after this function. */
987 rtx free_pointer
= rtx_alloc (CONST_INT
);
989 for (p
= temp_slots
, prev_p
= 0; p
; p
= prev_p
? prev_p
->next
: temp_slots
)
992 if (! p
->in_use
&& GET_MODE (p
->slot
) == BLKmode
)
993 for (q
= p
->next
, prev_q
= p
; q
; q
= prev_q
->next
)
996 if (! q
->in_use
&& GET_MODE (q
->slot
) == BLKmode
)
998 if (p
->base_offset
+ p
->full_size
== q
->base_offset
)
1000 /* Q comes after P; combine Q into P. */
1002 p
->full_size
+= q
->full_size
;
1005 else if (q
->base_offset
+ q
->full_size
== p
->base_offset
)
1007 /* P comes after Q; combine P into Q. */
1009 q
->full_size
+= p
->full_size
;
1014 /* Either delete Q or advance past it. */
1016 prev_q
->next
= q
->next
;
1020 /* Either delete P or advance past it. */
1024 prev_p
->next
= p
->next
;
1026 temp_slots
= p
->next
;
1032 /* Free all the RTL made by plus_constant. */
1033 rtx_free (free_pointer
);
1036 /* Find the temp slot corresponding to the object at address X. */
1038 static struct temp_slot
*
1039 find_temp_slot_from_address (x
)
1042 struct temp_slot
*p
;
1045 for (p
= temp_slots
; p
; p
= p
->next
)
1049 else if (XEXP (p
->slot
, 0) == x
1051 || (GET_CODE (x
) == PLUS
1052 && XEXP (x
, 0) == virtual_stack_vars_rtx
1053 && GET_CODE (XEXP (x
, 1)) == CONST_INT
1054 && INTVAL (XEXP (x
, 1)) >= p
->base_offset
1055 && INTVAL (XEXP (x
, 1)) < p
->base_offset
+ p
->full_size
))
1058 else if (p
->address
!= 0 && GET_CODE (p
->address
) == EXPR_LIST
)
1059 for (next
= p
->address
; next
; next
= XEXP (next
, 1))
1060 if (XEXP (next
, 0) == x
)
1067 /* Indicate that NEW is an alternate way of referring to the temp slot
1068 that previous was known by OLD. */
1071 update_temp_slot_address (old
, new)
1074 struct temp_slot
*p
= find_temp_slot_from_address (old
);
1076 /* If none, return. Else add NEW as an alias. */
1079 else if (p
->address
== 0)
1083 if (GET_CODE (p
->address
) != EXPR_LIST
)
1084 p
->address
= gen_rtx (EXPR_LIST
, VOIDmode
, p
->address
, NULL_RTX
);
1086 p
->address
= gen_rtx (EXPR_LIST
, VOIDmode
, new, p
->address
);
1090 /* If X could be a reference to a temporary slot, mark the fact that its
1091 address was taken. */
1094 mark_temp_addr_taken (x
)
1097 struct temp_slot
*p
;
1102 /* If X is not in memory or is at a constant address, it cannot be in
1103 a temporary slot. */
1104 if (GET_CODE (x
) != MEM
|| CONSTANT_P (XEXP (x
, 0)))
1107 p
= find_temp_slot_from_address (XEXP (x
, 0));
1112 /* If X could be a reference to a temporary slot, mark that slot as
1113 belonging to the to one level higher than the current level. If X
1114 matched one of our slots, just mark that one. Otherwise, we can't
1115 easily predict which it is, so upgrade all of them. Kept slots
1116 need not be touched.
1118 This is called when an ({...}) construct occurs and a statement
1119 returns a value in memory. */
1122 preserve_temp_slots (x
)
1125 struct temp_slot
*p
= 0;
1127 /* If there is no result, we still might have some objects whose address
1128 were taken, so we need to make sure they stay around. */
1131 for (p
= temp_slots
; p
; p
= p
->next
)
1132 if (p
->in_use
&& p
->level
== temp_slot_level
&& p
->addr_taken
)
1138 /* If X is a register that is being used as a pointer, see if we have
1139 a temporary slot we know it points to. To be consistent with
1140 the code below, we really should preserve all non-kept slots
1141 if we can't find a match, but that seems to be much too costly. */
1142 if (GET_CODE (x
) == REG
&& REGNO_POINTER_FLAG (REGNO (x
)))
1143 p
= find_temp_slot_from_address (x
);
1145 /* If X is not in memory or is at a constant address, it cannot be in
1146 a temporary slot, but it can contain something whose address was
1148 if (p
== 0 && (GET_CODE (x
) != MEM
|| CONSTANT_P (XEXP (x
, 0))))
1150 for (p
= temp_slots
; p
; p
= p
->next
)
1151 if (p
->in_use
&& p
->level
== temp_slot_level
&& p
->addr_taken
)
1157 /* First see if we can find a match. */
1159 p
= find_temp_slot_from_address (XEXP (x
, 0));
1163 /* Move everything at our level whose address was taken to our new
1164 level in case we used its address. */
1165 struct temp_slot
*q
;
1167 if (p
->level
== temp_slot_level
)
1169 for (q
= temp_slots
; q
; q
= q
->next
)
1170 if (q
!= p
&& q
->addr_taken
&& q
->level
== p
->level
)
1179 /* Otherwise, preserve all non-kept slots at this level. */
1180 for (p
= temp_slots
; p
; p
= p
->next
)
1181 if (p
->in_use
&& p
->level
== temp_slot_level
&& ! p
->keep
)
1185 /* X is the result of an RTL_EXPR. If it is a temporary slot associated
1186 with that RTL_EXPR, promote it into a temporary slot at the present
1187 level so it will not be freed when we free slots made in the
1191 preserve_rtl_expr_result (x
)
1194 struct temp_slot
*p
;
1196 /* If X is not in memory or is at a constant address, it cannot be in
1197 a temporary slot. */
1198 if (x
== 0 || GET_CODE (x
) != MEM
|| CONSTANT_P (XEXP (x
, 0)))
1201 /* If we can find a match, move it to our level unless it is already at
1203 p
= find_temp_slot_from_address (XEXP (x
, 0));
1206 p
->level
= MIN (p
->level
, temp_slot_level
);
1213 /* Free all temporaries used so far. This is normally called at the end
1214 of generating code for a statement. Don't free any temporaries
1215 currently in use for an RTL_EXPR that hasn't yet been emitted.
1216 We could eventually do better than this since it can be reused while
1217 generating the same RTL_EXPR, but this is complex and probably not
1223 struct temp_slot
*p
;
1225 for (p
= temp_slots
; p
; p
= p
->next
)
1226 if (p
->in_use
&& p
->level
== temp_slot_level
&& ! p
->keep
1227 && p
->rtl_expr
== 0)
1230 combine_temp_slots ();
1233 /* Free all temporary slots used in T, an RTL_EXPR node. */
1236 free_temps_for_rtl_expr (t
)
1239 struct temp_slot
*p
;
1241 for (p
= temp_slots
; p
; p
= p
->next
)
1242 if (p
->rtl_expr
== t
)
1245 combine_temp_slots ();
1248 /* Mark all temporaries ever allocated in this functon as not suitable
1249 for reuse until the current level is exited. */
1252 mark_all_temps_used ()
1254 struct temp_slot
*p
;
1256 for (p
= temp_slots
; p
; p
= p
->next
)
1258 p
->in_use
= p
->keep
= 1;
1259 p
->level
= MIN (p
->level
, temp_slot_level
);
1263 /* Push deeper into the nesting level for stack temporaries. */
1271 /* Pop a temporary nesting level. All slots in use in the current level
1277 struct temp_slot
*p
;
1279 for (p
= temp_slots
; p
; p
= p
->next
)
1280 if (p
->in_use
&& p
->level
== temp_slot_level
&& p
->rtl_expr
== 0)
1283 combine_temp_slots ();
1288 /* Initialize temporary slots. */
1293 /* We have not allocated any temporaries yet. */
1295 temp_slot_level
= 0;
1296 target_temp_slot_level
= 0;
1299 /* Retroactively move an auto variable from a register to a stack slot.
1300 This is done when an address-reference to the variable is seen. */
1303 put_var_into_stack (decl
)
1307 enum machine_mode promoted_mode
, decl_mode
;
1308 struct function
*function
= 0;
1311 if (output_bytecode
)
1314 context
= decl_function_context (decl
);
1316 /* Get the current rtl used for this object and it's original mode. */
1317 reg
= TREE_CODE (decl
) == SAVE_EXPR
? SAVE_EXPR_RTL (decl
) : DECL_RTL (decl
);
1319 /* No need to do anything if decl has no rtx yet
1320 since in that case caller is setting TREE_ADDRESSABLE
1321 and a stack slot will be assigned when the rtl is made. */
1325 /* Get the declared mode for this object. */
1326 decl_mode
= (TREE_CODE (decl
) == SAVE_EXPR
? TYPE_MODE (TREE_TYPE (decl
))
1327 : DECL_MODE (decl
));
1328 /* Get the mode it's actually stored in. */
1329 promoted_mode
= GET_MODE (reg
);
1331 /* If this variable comes from an outer function,
1332 find that function's saved context. */
1333 if (context
!= current_function_decl
&& context
!= inline_function_decl
)
1334 for (function
= outer_function_chain
; function
; function
= function
->next
)
1335 if (function
->decl
== context
)
1338 /* If this is a variable-size object with a pseudo to address it,
1339 put that pseudo into the stack, if the var is nonlocal. */
1340 if (DECL_NONLOCAL (decl
)
1341 && GET_CODE (reg
) == MEM
1342 && GET_CODE (XEXP (reg
, 0)) == REG
1343 && REGNO (XEXP (reg
, 0)) > LAST_VIRTUAL_REGISTER
)
1345 reg
= XEXP (reg
, 0);
1346 decl_mode
= promoted_mode
= GET_MODE (reg
);
1349 /* Now we should have a value that resides in one or more pseudo regs. */
1351 if (GET_CODE (reg
) == REG
)
1352 put_reg_into_stack (function
, reg
, TREE_TYPE (decl
),
1353 promoted_mode
, decl_mode
, TREE_SIDE_EFFECTS (decl
));
1354 else if (GET_CODE (reg
) == CONCAT
)
1356 /* A CONCAT contains two pseudos; put them both in the stack.
1357 We do it so they end up consecutive. */
1358 enum machine_mode part_mode
= GET_MODE (XEXP (reg
, 0));
1359 tree part_type
= TREE_TYPE (TREE_TYPE (decl
));
1360 #ifdef FRAME_GROWS_DOWNWARD
1361 /* Since part 0 should have a lower address, do it second. */
1362 put_reg_into_stack (function
, XEXP (reg
, 1), part_type
, part_mode
,
1363 part_mode
, TREE_SIDE_EFFECTS (decl
));
1364 put_reg_into_stack (function
, XEXP (reg
, 0), part_type
, part_mode
,
1365 part_mode
, TREE_SIDE_EFFECTS (decl
));
1367 put_reg_into_stack (function
, XEXP (reg
, 0), part_type
, part_mode
,
1368 part_mode
, TREE_SIDE_EFFECTS (decl
));
1369 put_reg_into_stack (function
, XEXP (reg
, 1), part_type
, part_mode
,
1370 part_mode
, TREE_SIDE_EFFECTS (decl
));
1373 /* Change the CONCAT into a combined MEM for both parts. */
1374 PUT_CODE (reg
, MEM
);
1375 MEM_VOLATILE_P (reg
) = MEM_VOLATILE_P (XEXP (reg
, 0));
1377 /* The two parts are in memory order already.
1378 Use the lower parts address as ours. */
1379 XEXP (reg
, 0) = XEXP (XEXP (reg
, 0), 0);
1380 /* Prevent sharing of rtl that might lose. */
1381 if (GET_CODE (XEXP (reg
, 0)) == PLUS
)
1382 XEXP (reg
, 0) = copy_rtx (XEXP (reg
, 0));
1386 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1387 into the stack frame of FUNCTION (0 means the current function).
1388 DECL_MODE is the machine mode of the user-level data type.
1389 PROMOTED_MODE is the machine mode of the register.
1390 VOLATILE_P is nonzero if this is for a "volatile" decl. */
1393 put_reg_into_stack (function
, reg
, type
, promoted_mode
, decl_mode
, volatile_p
)
1394 struct function
*function
;
1397 enum machine_mode promoted_mode
, decl_mode
;
1404 if (REGNO (reg
) < function
->max_parm_reg
)
1405 new = function
->parm_reg_stack_loc
[REGNO (reg
)];
1407 new = assign_outer_stack_local (decl_mode
, GET_MODE_SIZE (decl_mode
),
1412 if (REGNO (reg
) < max_parm_reg
)
1413 new = parm_reg_stack_loc
[REGNO (reg
)];
1415 new = assign_stack_local (decl_mode
, GET_MODE_SIZE (decl_mode
), 0);
1418 PUT_MODE (reg
, decl_mode
);
1419 XEXP (reg
, 0) = XEXP (new, 0);
1420 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
1421 MEM_VOLATILE_P (reg
) = volatile_p
;
1422 PUT_CODE (reg
, MEM
);
1424 /* If this is a memory ref that contains aggregate components,
1425 mark it as such for cse and loop optimize. */
1426 MEM_IN_STRUCT_P (reg
) = AGGREGATE_TYPE_P (type
);
1428 /* Now make sure that all refs to the variable, previously made
1429 when it was a register, are fixed up to be valid again. */
1432 struct var_refs_queue
*temp
;
1434 /* Variable is inherited; fix it up when we get back to its function. */
1435 push_obstacks (function
->function_obstack
,
1436 function
->function_maybepermanent_obstack
);
1438 /* See comment in restore_tree_status in tree.c for why this needs to be
1439 on saveable obstack. */
1441 = (struct var_refs_queue
*) savealloc (sizeof (struct var_refs_queue
));
1442 temp
->modified
= reg
;
1443 temp
->promoted_mode
= promoted_mode
;
1444 temp
->unsignedp
= TREE_UNSIGNED (type
);
1445 temp
->next
= function
->fixup_var_refs_queue
;
1446 function
->fixup_var_refs_queue
= temp
;
1450 /* Variable is local; fix it up now. */
1451 fixup_var_refs (reg
, promoted_mode
, TREE_UNSIGNED (type
));
1455 fixup_var_refs (var
, promoted_mode
, unsignedp
)
1457 enum machine_mode promoted_mode
;
1461 rtx first_insn
= get_insns ();
1462 struct sequence_stack
*stack
= sequence_stack
;
1463 tree rtl_exps
= rtl_expr_chain
;
1465 /* Must scan all insns for stack-refs that exceed the limit. */
1466 fixup_var_refs_insns (var
, promoted_mode
, unsignedp
, first_insn
, stack
== 0);
1468 /* Scan all pending sequences too. */
1469 for (; stack
; stack
= stack
->next
)
1471 push_to_sequence (stack
->first
);
1472 fixup_var_refs_insns (var
, promoted_mode
, unsignedp
,
1473 stack
->first
, stack
->next
!= 0);
1474 /* Update remembered end of sequence
1475 in case we added an insn at the end. */
1476 stack
->last
= get_last_insn ();
1480 /* Scan all waiting RTL_EXPRs too. */
1481 for (pending
= rtl_exps
; pending
; pending
= TREE_CHAIN (pending
))
1483 rtx seq
= RTL_EXPR_SEQUENCE (TREE_VALUE (pending
));
1484 if (seq
!= const0_rtx
&& seq
!= 0)
1486 push_to_sequence (seq
);
1487 fixup_var_refs_insns (var
, promoted_mode
, unsignedp
, seq
, 0);
1493 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
1494 some part of an insn. Return a struct fixup_replacement whose OLD
1495 value is equal to X. Allocate a new structure if no such entry exists. */
1497 static struct fixup_replacement
*
1498 find_fixup_replacement (replacements
, x
)
1499 struct fixup_replacement
**replacements
;
1502 struct fixup_replacement
*p
;
1504 /* See if we have already replaced this. */
1505 for (p
= *replacements
; p
&& p
->old
!= x
; p
= p
->next
)
1510 p
= (struct fixup_replacement
*) oballoc (sizeof (struct fixup_replacement
));
1513 p
->next
= *replacements
;
1520 /* Scan the insn-chain starting with INSN for refs to VAR
1521 and fix them up. TOPLEVEL is nonzero if this chain is the
1522 main chain of insns for the current function. */
1525 fixup_var_refs_insns (var
, promoted_mode
, unsignedp
, insn
, toplevel
)
1527 enum machine_mode promoted_mode
;
1536 rtx next
= NEXT_INSN (insn
);
1538 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
1540 /* If this is a CLOBBER of VAR, delete it.
1542 If it has a REG_LIBCALL note, delete the REG_LIBCALL
1543 and REG_RETVAL notes too. */
1544 if (GET_CODE (PATTERN (insn
)) == CLOBBER
1545 && XEXP (PATTERN (insn
), 0) == var
)
1547 if ((note
= find_reg_note (insn
, REG_LIBCALL
, NULL_RTX
)) != 0)
1548 /* The REG_LIBCALL note will go away since we are going to
1549 turn INSN into a NOTE, so just delete the
1550 corresponding REG_RETVAL note. */
1551 remove_note (XEXP (note
, 0),
1552 find_reg_note (XEXP (note
, 0), REG_RETVAL
,
1555 /* In unoptimized compilation, we shouldn't call delete_insn
1556 except in jump.c doing warnings. */
1557 PUT_CODE (insn
, NOTE
);
1558 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
1559 NOTE_SOURCE_FILE (insn
) = 0;
1562 /* The insn to load VAR from a home in the arglist
1563 is now a no-op. When we see it, just delete it. */
1565 && GET_CODE (PATTERN (insn
)) == SET
1566 && SET_DEST (PATTERN (insn
)) == var
1567 /* If this represents the result of an insn group,
1568 don't delete the insn. */
1569 && find_reg_note (insn
, REG_RETVAL
, NULL_RTX
) == 0
1570 && rtx_equal_p (SET_SRC (PATTERN (insn
)), var
))
1572 /* In unoptimized compilation, we shouldn't call delete_insn
1573 except in jump.c doing warnings. */
1574 PUT_CODE (insn
, NOTE
);
1575 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
1576 NOTE_SOURCE_FILE (insn
) = 0;
1577 if (insn
== last_parm_insn
)
1578 last_parm_insn
= PREV_INSN (next
);
1582 struct fixup_replacement
*replacements
= 0;
1583 rtx next_insn
= NEXT_INSN (insn
);
1585 #ifdef SMALL_REGISTER_CLASSES
1586 /* If the insn that copies the results of a CALL_INSN
1587 into a pseudo now references VAR, we have to use an
1588 intermediate pseudo since we want the life of the
1589 return value register to be only a single insn.
1591 If we don't use an intermediate pseudo, such things as
1592 address computations to make the address of VAR valid
1593 if it is not can be placed between the CALL_INSN and INSN.
1595 To make sure this doesn't happen, we record the destination
1596 of the CALL_INSN and see if the next insn uses both that
1599 if (SMALL_REGISTER_CLASSES
)
1601 if (call_dest
!= 0 && GET_CODE (insn
) == INSN
1602 && reg_mentioned_p (var
, PATTERN (insn
))
1603 && reg_mentioned_p (call_dest
, PATTERN (insn
)))
1605 rtx temp
= gen_reg_rtx (GET_MODE (call_dest
));
1607 emit_insn_before (gen_move_insn (temp
, call_dest
), insn
);
1609 PATTERN (insn
) = replace_rtx (PATTERN (insn
),
1613 if (GET_CODE (insn
) == CALL_INSN
1614 && GET_CODE (PATTERN (insn
)) == SET
)
1615 call_dest
= SET_DEST (PATTERN (insn
));
1616 else if (GET_CODE (insn
) == CALL_INSN
1617 && GET_CODE (PATTERN (insn
)) == PARALLEL
1618 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == SET
)
1619 call_dest
= SET_DEST (XVECEXP (PATTERN (insn
), 0, 0));
1625 /* See if we have to do anything to INSN now that VAR is in
1626 memory. If it needs to be loaded into a pseudo, use a single
1627 pseudo for the entire insn in case there is a MATCH_DUP
1628 between two operands. We pass a pointer to the head of
1629 a list of struct fixup_replacements. If fixup_var_refs_1
1630 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1631 it will record them in this list.
1633 If it allocated a pseudo for any replacement, we copy into
1636 fixup_var_refs_1 (var
, promoted_mode
, &PATTERN (insn
), insn
,
1639 /* If this is last_parm_insn, and any instructions were output
1640 after it to fix it up, then we must set last_parm_insn to
1641 the last such instruction emitted. */
1642 if (insn
== last_parm_insn
)
1643 last_parm_insn
= PREV_INSN (next_insn
);
1645 while (replacements
)
1647 if (GET_CODE (replacements
->new) == REG
)
1652 /* OLD might be a (subreg (mem)). */
1653 if (GET_CODE (replacements
->old
) == SUBREG
)
1655 = fixup_memory_subreg (replacements
->old
, insn
, 0);
1658 = fixup_stack_1 (replacements
->old
, insn
);
1660 insert_before
= insn
;
1662 /* If we are changing the mode, do a conversion.
1663 This might be wasteful, but combine.c will
1664 eliminate much of the waste. */
1666 if (GET_MODE (replacements
->new)
1667 != GET_MODE (replacements
->old
))
1670 convert_move (replacements
->new,
1671 replacements
->old
, unsignedp
);
1672 seq
= gen_sequence ();
1676 seq
= gen_move_insn (replacements
->new,
1679 emit_insn_before (seq
, insert_before
);
1682 replacements
= replacements
->next
;
1686 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
1687 But don't touch other insns referred to by reg-notes;
1688 we will get them elsewhere. */
1689 for (note
= REG_NOTES (insn
); note
; note
= XEXP (note
, 1))
1690 if (GET_CODE (note
) != INSN_LIST
)
1692 = walk_fixup_memory_subreg (XEXP (note
, 0), insn
, 1);
1698 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
1699 See if the rtx expression at *LOC in INSN needs to be changed.
1701 REPLACEMENTS is a pointer to a list head that starts out zero, but may
1702 contain a list of original rtx's and replacements. If we find that we need
1703 to modify this insn by replacing a memory reference with a pseudo or by
1704 making a new MEM to implement a SUBREG, we consult that list to see if
1705 we have already chosen a replacement. If none has already been allocated,
1706 we allocate it and update the list. fixup_var_refs_insns will copy VAR
1707 or the SUBREG, as appropriate, to the pseudo. */
1710 fixup_var_refs_1 (var
, promoted_mode
, loc
, insn
, replacements
)
1712 enum machine_mode promoted_mode
;
1715 struct fixup_replacement
**replacements
;
1718 register rtx x
= *loc
;
1719 RTX_CODE code
= GET_CODE (x
);
1721 register rtx tem
, tem1
;
1722 struct fixup_replacement
*replacement
;
1729 /* If we already have a replacement, use it. Otherwise,
1730 try to fix up this address in case it is invalid. */
1732 replacement
= find_fixup_replacement (replacements
, var
);
1733 if (replacement
->new)
1735 *loc
= replacement
->new;
1739 *loc
= replacement
->new = x
= fixup_stack_1 (x
, insn
);
1741 /* Unless we are forcing memory to register or we changed the mode,
1742 we can leave things the way they are if the insn is valid. */
1744 INSN_CODE (insn
) = -1;
1745 if (! flag_force_mem
&& GET_MODE (x
) == promoted_mode
1746 && recog_memoized (insn
) >= 0)
1749 *loc
= replacement
->new = gen_reg_rtx (promoted_mode
);
1753 /* If X contains VAR, we need to unshare it here so that we update
1754 each occurrence separately. But all identical MEMs in one insn
1755 must be replaced with the same rtx because of the possibility of
1758 if (reg_mentioned_p (var
, x
))
1760 replacement
= find_fixup_replacement (replacements
, x
);
1761 if (replacement
->new == 0)
1762 replacement
->new = copy_most_rtx (x
, var
);
1764 *loc
= x
= replacement
->new;
1780 /* Note that in some cases those types of expressions are altered
1781 by optimize_bit_field, and do not survive to get here. */
1782 if (XEXP (x
, 0) == var
1783 || (GET_CODE (XEXP (x
, 0)) == SUBREG
1784 && SUBREG_REG (XEXP (x
, 0)) == var
))
1786 /* Get TEM as a valid MEM in the mode presently in the insn.
1788 We don't worry about the possibility of MATCH_DUP here; it
1789 is highly unlikely and would be tricky to handle. */
1792 if (GET_CODE (tem
) == SUBREG
)
1794 if (GET_MODE_BITSIZE (GET_MODE (tem
))
1795 > GET_MODE_BITSIZE (GET_MODE (var
)))
1797 replacement
= find_fixup_replacement (replacements
, var
);
1798 if (replacement
->new == 0)
1799 replacement
->new = gen_reg_rtx (GET_MODE (var
));
1800 SUBREG_REG (tem
) = replacement
->new;
1803 tem
= fixup_memory_subreg (tem
, insn
, 0);
1806 tem
= fixup_stack_1 (tem
, insn
);
1808 /* Unless we want to load from memory, get TEM into the proper mode
1809 for an extract from memory. This can only be done if the
1810 extract is at a constant position and length. */
1812 if (! flag_force_mem
&& GET_CODE (XEXP (x
, 1)) == CONST_INT
1813 && GET_CODE (XEXP (x
, 2)) == CONST_INT
1814 && ! mode_dependent_address_p (XEXP (tem
, 0))
1815 && ! MEM_VOLATILE_P (tem
))
1817 enum machine_mode wanted_mode
= VOIDmode
;
1818 enum machine_mode is_mode
= GET_MODE (tem
);
1819 int width
= INTVAL (XEXP (x
, 1));
1820 int pos
= INTVAL (XEXP (x
, 2));
1823 if (GET_CODE (x
) == ZERO_EXTRACT
)
1824 wanted_mode
= insn_operand_mode
[(int) CODE_FOR_extzv
][1];
1827 if (GET_CODE (x
) == SIGN_EXTRACT
)
1828 wanted_mode
= insn_operand_mode
[(int) CODE_FOR_extv
][1];
1830 /* If we have a narrower mode, we can do something. */
1831 if (wanted_mode
!= VOIDmode
1832 && GET_MODE_SIZE (wanted_mode
) < GET_MODE_SIZE (is_mode
))
1834 int offset
= pos
/ BITS_PER_UNIT
;
1835 rtx old_pos
= XEXP (x
, 2);
1838 /* If the bytes and bits are counted differently, we
1839 must adjust the offset. */
1840 if (BYTES_BIG_ENDIAN
!= BITS_BIG_ENDIAN
)
1841 offset
= (GET_MODE_SIZE (is_mode
)
1842 - GET_MODE_SIZE (wanted_mode
) - offset
);
1844 pos
%= GET_MODE_BITSIZE (wanted_mode
);
1846 newmem
= gen_rtx (MEM
, wanted_mode
,
1847 plus_constant (XEXP (tem
, 0), offset
));
1848 RTX_UNCHANGING_P (newmem
) = RTX_UNCHANGING_P (tem
);
1849 MEM_VOLATILE_P (newmem
) = MEM_VOLATILE_P (tem
);
1850 MEM_IN_STRUCT_P (newmem
) = MEM_IN_STRUCT_P (tem
);
1852 /* Make the change and see if the insn remains valid. */
1853 INSN_CODE (insn
) = -1;
1854 XEXP (x
, 0) = newmem
;
1855 XEXP (x
, 2) = GEN_INT (pos
);
1857 if (recog_memoized (insn
) >= 0)
1860 /* Otherwise, restore old position. XEXP (x, 0) will be
1862 XEXP (x
, 2) = old_pos
;
1866 /* If we get here, the bitfield extract insn can't accept a memory
1867 reference. Copy the input into a register. */
1869 tem1
= gen_reg_rtx (GET_MODE (tem
));
1870 emit_insn_before (gen_move_insn (tem1
, tem
), insn
);
1877 if (SUBREG_REG (x
) == var
)
1879 /* If this is a special SUBREG made because VAR was promoted
1880 from a wider mode, replace it with VAR and call ourself
1881 recursively, this time saying that the object previously
1882 had its current mode (by virtue of the SUBREG). */
1884 if (SUBREG_PROMOTED_VAR_P (x
))
1887 fixup_var_refs_1 (var
, GET_MODE (var
), loc
, insn
, replacements
);
1891 /* If this SUBREG makes VAR wider, it has become a paradoxical
1892 SUBREG with VAR in memory, but these aren't allowed at this
1893 stage of the compilation. So load VAR into a pseudo and take
1894 a SUBREG of that pseudo. */
1895 if (GET_MODE_SIZE (GET_MODE (x
)) > GET_MODE_SIZE (GET_MODE (var
)))
1897 replacement
= find_fixup_replacement (replacements
, var
);
1898 if (replacement
->new == 0)
1899 replacement
->new = gen_reg_rtx (GET_MODE (var
));
1900 SUBREG_REG (x
) = replacement
->new;
1904 /* See if we have already found a replacement for this SUBREG.
1905 If so, use it. Otherwise, make a MEM and see if the insn
1906 is recognized. If not, or if we should force MEM into a register,
1907 make a pseudo for this SUBREG. */
1908 replacement
= find_fixup_replacement (replacements
, x
);
1909 if (replacement
->new)
1911 *loc
= replacement
->new;
1915 replacement
->new = *loc
= fixup_memory_subreg (x
, insn
, 0);
1917 INSN_CODE (insn
) = -1;
1918 if (! flag_force_mem
&& recog_memoized (insn
) >= 0)
1921 *loc
= replacement
->new = gen_reg_rtx (GET_MODE (x
));
1927 /* First do special simplification of bit-field references. */
1928 if (GET_CODE (SET_DEST (x
)) == SIGN_EXTRACT
1929 || GET_CODE (SET_DEST (x
)) == ZERO_EXTRACT
)
1930 optimize_bit_field (x
, insn
, 0);
1931 if (GET_CODE (SET_SRC (x
)) == SIGN_EXTRACT
1932 || GET_CODE (SET_SRC (x
)) == ZERO_EXTRACT
)
1933 optimize_bit_field (x
, insn
, NULL_PTR
);
1935 /* For a paradoxical SUBREG inside a ZERO_EXTRACT, load the object
1936 into a register and then store it back out. */
1937 if (GET_CODE (SET_DEST (x
)) == ZERO_EXTRACT
1938 && GET_CODE (XEXP (SET_DEST (x
), 0)) == SUBREG
1939 && SUBREG_REG (XEXP (SET_DEST (x
), 0)) == var
1940 && (GET_MODE_SIZE (GET_MODE (XEXP (SET_DEST (x
), 0)))
1941 > GET_MODE_SIZE (GET_MODE (var
))))
1943 replacement
= find_fixup_replacement (replacements
, var
);
1944 if (replacement
->new == 0)
1945 replacement
->new = gen_reg_rtx (GET_MODE (var
));
1947 SUBREG_REG (XEXP (SET_DEST (x
), 0)) = replacement
->new;
1948 emit_insn_after (gen_move_insn (var
, replacement
->new), insn
);
1951 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
1952 insn into a pseudo and store the low part of the pseudo into VAR. */
1953 if (GET_CODE (SET_DEST (x
)) == SUBREG
1954 && SUBREG_REG (SET_DEST (x
)) == var
1955 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x
)))
1956 > GET_MODE_SIZE (GET_MODE (var
))))
1958 SET_DEST (x
) = tem
= gen_reg_rtx (GET_MODE (SET_DEST (x
)));
1959 emit_insn_after (gen_move_insn (var
, gen_lowpart (GET_MODE (var
),
1966 rtx dest
= SET_DEST (x
);
1967 rtx src
= SET_SRC (x
);
1968 rtx outerdest
= dest
;
1970 while (GET_CODE (dest
) == SUBREG
|| GET_CODE (dest
) == STRICT_LOW_PART
1971 || GET_CODE (dest
) == SIGN_EXTRACT
1972 || GET_CODE (dest
) == ZERO_EXTRACT
)
1973 dest
= XEXP (dest
, 0);
1975 if (GET_CODE (src
) == SUBREG
)
1976 src
= XEXP (src
, 0);
1978 /* If VAR does not appear at the top level of the SET
1979 just scan the lower levels of the tree. */
1981 if (src
!= var
&& dest
!= var
)
1984 /* We will need to rerecognize this insn. */
1985 INSN_CODE (insn
) = -1;
1988 if (GET_CODE (outerdest
) == ZERO_EXTRACT
&& dest
== var
)
1990 /* Since this case will return, ensure we fixup all the
1992 fixup_var_refs_1 (var
, promoted_mode
, &XEXP (outerdest
, 1),
1993 insn
, replacements
);
1994 fixup_var_refs_1 (var
, promoted_mode
, &XEXP (outerdest
, 2),
1995 insn
, replacements
);
1996 fixup_var_refs_1 (var
, promoted_mode
, &SET_SRC (x
),
1997 insn
, replacements
);
1999 tem
= XEXP (outerdest
, 0);
2001 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
2002 that may appear inside a ZERO_EXTRACT.
2003 This was legitimate when the MEM was a REG. */
2004 if (GET_CODE (tem
) == SUBREG
2005 && SUBREG_REG (tem
) == var
)
2006 tem
= fixup_memory_subreg (tem
, insn
, 0);
2008 tem
= fixup_stack_1 (tem
, insn
);
2010 if (GET_CODE (XEXP (outerdest
, 1)) == CONST_INT
2011 && GET_CODE (XEXP (outerdest
, 2)) == CONST_INT
2012 && ! mode_dependent_address_p (XEXP (tem
, 0))
2013 && ! MEM_VOLATILE_P (tem
))
2015 enum machine_mode wanted_mode
2016 = insn_operand_mode
[(int) CODE_FOR_insv
][0];
2017 enum machine_mode is_mode
= GET_MODE (tem
);
2018 int width
= INTVAL (XEXP (outerdest
, 1));
2019 int pos
= INTVAL (XEXP (outerdest
, 2));
2021 /* If we have a narrower mode, we can do something. */
2022 if (GET_MODE_SIZE (wanted_mode
) < GET_MODE_SIZE (is_mode
))
2024 int offset
= pos
/ BITS_PER_UNIT
;
2025 rtx old_pos
= XEXP (outerdest
, 2);
2028 if (BYTES_BIG_ENDIAN
!= BITS_BIG_ENDIAN
)
2029 offset
= (GET_MODE_SIZE (is_mode
)
2030 - GET_MODE_SIZE (wanted_mode
) - offset
);
2032 pos
%= GET_MODE_BITSIZE (wanted_mode
);
2034 newmem
= gen_rtx (MEM
, wanted_mode
,
2035 plus_constant (XEXP (tem
, 0), offset
));
2036 RTX_UNCHANGING_P (newmem
) = RTX_UNCHANGING_P (tem
);
2037 MEM_VOLATILE_P (newmem
) = MEM_VOLATILE_P (tem
);
2038 MEM_IN_STRUCT_P (newmem
) = MEM_IN_STRUCT_P (tem
);
2040 /* Make the change and see if the insn remains valid. */
2041 INSN_CODE (insn
) = -1;
2042 XEXP (outerdest
, 0) = newmem
;
2043 XEXP (outerdest
, 2) = GEN_INT (pos
);
2045 if (recog_memoized (insn
) >= 0)
2048 /* Otherwise, restore old position. XEXP (x, 0) will be
2050 XEXP (outerdest
, 2) = old_pos
;
2054 /* If we get here, the bit-field store doesn't allow memory
2055 or isn't located at a constant position. Load the value into
2056 a register, do the store, and put it back into memory. */
2058 tem1
= gen_reg_rtx (GET_MODE (tem
));
2059 emit_insn_before (gen_move_insn (tem1
, tem
), insn
);
2060 emit_insn_after (gen_move_insn (tem
, tem1
), insn
);
2061 XEXP (outerdest
, 0) = tem1
;
2066 /* STRICT_LOW_PART is a no-op on memory references
2067 and it can cause combinations to be unrecognizable,
2070 if (dest
== var
&& GET_CODE (SET_DEST (x
)) == STRICT_LOW_PART
)
2071 SET_DEST (x
) = XEXP (SET_DEST (x
), 0);
2073 /* A valid insn to copy VAR into or out of a register
2074 must be left alone, to avoid an infinite loop here.
2075 If the reference to VAR is by a subreg, fix that up,
2076 since SUBREG is not valid for a memref.
2077 Also fix up the address of the stack slot.
2079 Note that we must not try to recognize the insn until
2080 after we know that we have valid addresses and no
2081 (subreg (mem ...) ...) constructs, since these interfere
2082 with determining the validity of the insn. */
2084 if ((SET_SRC (x
) == var
2085 || (GET_CODE (SET_SRC (x
)) == SUBREG
2086 && SUBREG_REG (SET_SRC (x
)) == var
))
2087 && (GET_CODE (SET_DEST (x
)) == REG
2088 || (GET_CODE (SET_DEST (x
)) == SUBREG
2089 && GET_CODE (SUBREG_REG (SET_DEST (x
))) == REG
))
2090 && GET_MODE (var
) == promoted_mode
2091 && x
== single_set (insn
))
2095 replacement
= find_fixup_replacement (replacements
, SET_SRC (x
));
2096 if (replacement
->new)
2097 SET_SRC (x
) = replacement
->new;
2098 else if (GET_CODE (SET_SRC (x
)) == SUBREG
)
2099 SET_SRC (x
) = replacement
->new
2100 = fixup_memory_subreg (SET_SRC (x
), insn
, 0);
2102 SET_SRC (x
) = replacement
->new
2103 = fixup_stack_1 (SET_SRC (x
), insn
);
2105 if (recog_memoized (insn
) >= 0)
2108 /* INSN is not valid, but we know that we want to
2109 copy SET_SRC (x) to SET_DEST (x) in some way. So
2110 we generate the move and see whether it requires more
2111 than one insn. If it does, we emit those insns and
2112 delete INSN. Otherwise, we an just replace the pattern
2113 of INSN; we have already verified above that INSN has
2114 no other function that to do X. */
2116 pat
= gen_move_insn (SET_DEST (x
), SET_SRC (x
));
2117 if (GET_CODE (pat
) == SEQUENCE
)
2119 emit_insn_after (pat
, insn
);
2120 PUT_CODE (insn
, NOTE
);
2121 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
2122 NOTE_SOURCE_FILE (insn
) = 0;
2125 PATTERN (insn
) = pat
;
2130 if ((SET_DEST (x
) == var
2131 || (GET_CODE (SET_DEST (x
)) == SUBREG
2132 && SUBREG_REG (SET_DEST (x
)) == var
))
2133 && (GET_CODE (SET_SRC (x
)) == REG
2134 || (GET_CODE (SET_SRC (x
)) == SUBREG
2135 && GET_CODE (SUBREG_REG (SET_SRC (x
))) == REG
))
2136 && GET_MODE (var
) == promoted_mode
2137 && x
== single_set (insn
))
2141 if (GET_CODE (SET_DEST (x
)) == SUBREG
)
2142 SET_DEST (x
) = fixup_memory_subreg (SET_DEST (x
), insn
, 0);
2144 SET_DEST (x
) = fixup_stack_1 (SET_DEST (x
), insn
);
2146 if (recog_memoized (insn
) >= 0)
2149 pat
= gen_move_insn (SET_DEST (x
), SET_SRC (x
));
2150 if (GET_CODE (pat
) == SEQUENCE
)
2152 emit_insn_after (pat
, insn
);
2153 PUT_CODE (insn
, NOTE
);
2154 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
2155 NOTE_SOURCE_FILE (insn
) = 0;
2158 PATTERN (insn
) = pat
;
2163 /* Otherwise, storing into VAR must be handled specially
2164 by storing into a temporary and copying that into VAR
2165 with a new insn after this one. Note that this case
2166 will be used when storing into a promoted scalar since
2167 the insn will now have different modes on the input
2168 and output and hence will be invalid (except for the case
2169 of setting it to a constant, which does not need any
2170 change if it is valid). We generate extra code in that case,
2171 but combine.c will eliminate it. */
2176 rtx fixeddest
= SET_DEST (x
);
2178 /* STRICT_LOW_PART can be discarded, around a MEM. */
2179 if (GET_CODE (fixeddest
) == STRICT_LOW_PART
)
2180 fixeddest
= XEXP (fixeddest
, 0);
2181 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
2182 if (GET_CODE (fixeddest
) == SUBREG
)
2184 fixeddest
= fixup_memory_subreg (fixeddest
, insn
, 0);
2185 promoted_mode
= GET_MODE (fixeddest
);
2188 fixeddest
= fixup_stack_1 (fixeddest
, insn
);
2190 temp
= gen_reg_rtx (promoted_mode
);
2192 emit_insn_after (gen_move_insn (fixeddest
,
2193 gen_lowpart (GET_MODE (fixeddest
),
2197 SET_DEST (x
) = temp
;
2202 /* Nothing special about this RTX; fix its operands. */
2204 fmt
= GET_RTX_FORMAT (code
);
2205 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2208 fixup_var_refs_1 (var
, promoted_mode
, &XEXP (x
, i
), insn
, replacements
);
2212 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2213 fixup_var_refs_1 (var
, promoted_mode
, &XVECEXP (x
, i
, j
),
2214 insn
, replacements
);
2219 /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
2220 return an rtx (MEM:m1 newaddr) which is equivalent.
2221 If any insns must be emitted to compute NEWADDR, put them before INSN.
2223 UNCRITICAL nonzero means accept paradoxical subregs.
2224 This is used for subregs found inside REG_NOTES. */
2227 fixup_memory_subreg (x
, insn
, uncritical
)
2232 int offset
= SUBREG_WORD (x
) * UNITS_PER_WORD
;
2233 rtx addr
= XEXP (SUBREG_REG (x
), 0);
2234 enum machine_mode mode
= GET_MODE (x
);
2237 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
2238 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
)))
2242 if (BYTES_BIG_ENDIAN
)
2243 offset
+= (MIN (UNITS_PER_WORD
, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))))
2244 - MIN (UNITS_PER_WORD
, GET_MODE_SIZE (mode
)));
2245 addr
= plus_constant (addr
, offset
);
2246 if (!flag_force_addr
&& memory_address_p (mode
, addr
))
2247 /* Shortcut if no insns need be emitted. */
2248 return change_address (SUBREG_REG (x
), mode
, addr
);
2250 result
= change_address (SUBREG_REG (x
), mode
, addr
);
2251 emit_insn_before (gen_sequence (), insn
);
2256 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2257 Replace subexpressions of X in place.
2258 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2259 Otherwise return X, with its contents possibly altered.
2261 If any insns must be emitted to compute NEWADDR, put them before INSN.
2263 UNCRITICAL is as in fixup_memory_subreg. */
2266 walk_fixup_memory_subreg (x
, insn
, uncritical
)
2271 register enum rtx_code code
;
2278 code
= GET_CODE (x
);
2280 if (code
== SUBREG
&& GET_CODE (SUBREG_REG (x
)) == MEM
)
2281 return fixup_memory_subreg (x
, insn
, uncritical
);
2283 /* Nothing special about this RTX; fix its operands. */
2285 fmt
= GET_RTX_FORMAT (code
);
2286 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2289 XEXP (x
, i
) = walk_fixup_memory_subreg (XEXP (x
, i
), insn
, uncritical
);
2293 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2295 = walk_fixup_memory_subreg (XVECEXP (x
, i
, j
), insn
, uncritical
);
2301 /* For each memory ref within X, if it refers to a stack slot
2302 with an out of range displacement, put the address in a temp register
2303 (emitting new insns before INSN to load these registers)
2304 and alter the memory ref to use that register.
2305 Replace each such MEM rtx with a copy, to avoid clobberage. */
2308 fixup_stack_1 (x
, insn
)
2313 register RTX_CODE code
= GET_CODE (x
);
2318 register rtx ad
= XEXP (x
, 0);
2319 /* If we have address of a stack slot but it's not valid
2320 (displacement is too large), compute the sum in a register. */
2321 if (GET_CODE (ad
) == PLUS
2322 && GET_CODE (XEXP (ad
, 0)) == REG
2323 && ((REGNO (XEXP (ad
, 0)) >= FIRST_VIRTUAL_REGISTER
2324 && REGNO (XEXP (ad
, 0)) <= LAST_VIRTUAL_REGISTER
)
2325 || XEXP (ad
, 0) == current_function_internal_arg_pointer
)
2326 && GET_CODE (XEXP (ad
, 1)) == CONST_INT
)
2329 if (memory_address_p (GET_MODE (x
), ad
))
2333 temp
= copy_to_reg (ad
);
2334 seq
= gen_sequence ();
2336 emit_insn_before (seq
, insn
);
2337 return change_address (x
, VOIDmode
, temp
);
2342 fmt
= GET_RTX_FORMAT (code
);
2343 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2346 XEXP (x
, i
) = fixup_stack_1 (XEXP (x
, i
), insn
);
2350 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2351 XVECEXP (x
, i
, j
) = fixup_stack_1 (XVECEXP (x
, i
, j
), insn
);
2357 /* Optimization: a bit-field instruction whose field
2358 happens to be a byte or halfword in memory
2359 can be changed to a move instruction.
2361 We call here when INSN is an insn to examine or store into a bit-field.
2362 BODY is the SET-rtx to be altered.
2364 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2365 (Currently this is called only from function.c, and EQUIV_MEM
2369 optimize_bit_field (body
, insn
, equiv_mem
)
2374 register rtx bitfield
;
2377 enum machine_mode mode
;
2379 if (GET_CODE (SET_DEST (body
)) == SIGN_EXTRACT
2380 || GET_CODE (SET_DEST (body
)) == ZERO_EXTRACT
)
2381 bitfield
= SET_DEST (body
), destflag
= 1;
2383 bitfield
= SET_SRC (body
), destflag
= 0;
2385 /* First check that the field being stored has constant size and position
2386 and is in fact a byte or halfword suitably aligned. */
2388 if (GET_CODE (XEXP (bitfield
, 1)) == CONST_INT
2389 && GET_CODE (XEXP (bitfield
, 2)) == CONST_INT
2390 && ((mode
= mode_for_size (INTVAL (XEXP (bitfield
, 1)), MODE_INT
, 1))
2392 && INTVAL (XEXP (bitfield
, 2)) % INTVAL (XEXP (bitfield
, 1)) == 0)
2394 register rtx memref
= 0;
2396 /* Now check that the containing word is memory, not a register,
2397 and that it is safe to change the machine mode. */
2399 if (GET_CODE (XEXP (bitfield
, 0)) == MEM
)
2400 memref
= XEXP (bitfield
, 0);
2401 else if (GET_CODE (XEXP (bitfield
, 0)) == REG
2403 memref
= equiv_mem
[REGNO (XEXP (bitfield
, 0))];
2404 else if (GET_CODE (XEXP (bitfield
, 0)) == SUBREG
2405 && GET_CODE (SUBREG_REG (XEXP (bitfield
, 0))) == MEM
)
2406 memref
= SUBREG_REG (XEXP (bitfield
, 0));
2407 else if (GET_CODE (XEXP (bitfield
, 0)) == SUBREG
2409 && GET_CODE (SUBREG_REG (XEXP (bitfield
, 0))) == REG
)
2410 memref
= equiv_mem
[REGNO (SUBREG_REG (XEXP (bitfield
, 0)))];
2413 && ! mode_dependent_address_p (XEXP (memref
, 0))
2414 && ! MEM_VOLATILE_P (memref
))
2416 /* Now adjust the address, first for any subreg'ing
2417 that we are now getting rid of,
2418 and then for which byte of the word is wanted. */
2420 register int offset
= INTVAL (XEXP (bitfield
, 2));
2423 /* Adjust OFFSET to count bits from low-address byte. */
2424 if (BITS_BIG_ENDIAN
!= BYTES_BIG_ENDIAN
)
2425 offset
= (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield
, 0)))
2426 - offset
- INTVAL (XEXP (bitfield
, 1)));
2428 /* Adjust OFFSET to count bytes from low-address byte. */
2429 offset
/= BITS_PER_UNIT
;
2430 if (GET_CODE (XEXP (bitfield
, 0)) == SUBREG
)
2432 offset
+= SUBREG_WORD (XEXP (bitfield
, 0)) * UNITS_PER_WORD
;
2433 if (BYTES_BIG_ENDIAN
)
2434 offset
-= (MIN (UNITS_PER_WORD
,
2435 GET_MODE_SIZE (GET_MODE (XEXP (bitfield
, 0))))
2436 - MIN (UNITS_PER_WORD
,
2437 GET_MODE_SIZE (GET_MODE (memref
))));
2441 memref
= change_address (memref
, mode
,
2442 plus_constant (XEXP (memref
, 0), offset
));
2443 insns
= get_insns ();
2445 emit_insns_before (insns
, insn
);
2447 /* Store this memory reference where
2448 we found the bit field reference. */
2452 validate_change (insn
, &SET_DEST (body
), memref
, 1);
2453 if (! CONSTANT_ADDRESS_P (SET_SRC (body
)))
2455 rtx src
= SET_SRC (body
);
2456 while (GET_CODE (src
) == SUBREG
2457 && SUBREG_WORD (src
) == 0)
2458 src
= SUBREG_REG (src
);
2459 if (GET_MODE (src
) != GET_MODE (memref
))
2460 src
= gen_lowpart (GET_MODE (memref
), SET_SRC (body
));
2461 validate_change (insn
, &SET_SRC (body
), src
, 1);
2463 else if (GET_MODE (SET_SRC (body
)) != VOIDmode
2464 && GET_MODE (SET_SRC (body
)) != GET_MODE (memref
))
2465 /* This shouldn't happen because anything that didn't have
2466 one of these modes should have got converted explicitly
2467 and then referenced through a subreg.
2468 This is so because the original bit-field was
2469 handled by agg_mode and so its tree structure had
2470 the same mode that memref now has. */
2475 rtx dest
= SET_DEST (body
);
2477 while (GET_CODE (dest
) == SUBREG
2478 && SUBREG_WORD (dest
) == 0
2479 && (GET_MODE_CLASS (GET_MODE (dest
))
2480 == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest
)))))
2481 dest
= SUBREG_REG (dest
);
2483 validate_change (insn
, &SET_DEST (body
), dest
, 1);
2485 if (GET_MODE (dest
) == GET_MODE (memref
))
2486 validate_change (insn
, &SET_SRC (body
), memref
, 1);
2489 /* Convert the mem ref to the destination mode. */
2490 rtx newreg
= gen_reg_rtx (GET_MODE (dest
));
2493 convert_move (newreg
, memref
,
2494 GET_CODE (SET_SRC (body
)) == ZERO_EXTRACT
);
2498 validate_change (insn
, &SET_SRC (body
), newreg
, 1);
2502 /* See if we can convert this extraction or insertion into
2503 a simple move insn. We might not be able to do so if this
2504 was, for example, part of a PARALLEL.
2506 If we succeed, write out any needed conversions. If we fail,
2507 it is hard to guess why we failed, so don't do anything
2508 special; just let the optimization be suppressed. */
2510 if (apply_change_group () && seq
)
2511 emit_insns_before (seq
, insn
);
2516 /* These routines are responsible for converting virtual register references
2517 to the actual hard register references once RTL generation is complete.
2519 The following four variables are used for communication between the
2520 routines. They contain the offsets of the virtual registers from their
2521 respective hard registers. */
2523 static int in_arg_offset
;
2524 static int var_offset
;
2525 static int dynamic_offset
;
2526 static int out_arg_offset
;
2528 /* In most machines, the stack pointer register is equivalent to the bottom
2531 #ifndef STACK_POINTER_OFFSET
2532 #define STACK_POINTER_OFFSET 0
2535 /* If not defined, pick an appropriate default for the offset of dynamically
2536 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2537 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2539 #ifndef STACK_DYNAMIC_OFFSET
2541 #ifdef ACCUMULATE_OUTGOING_ARGS
2542 /* The bottom of the stack points to the actual arguments. If
2543 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2544 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2545 stack space for register parameters is not pushed by the caller, but
2546 rather part of the fixed stack areas and hence not included in
2547 `current_function_outgoing_args_size'. Nevertheless, we must allow
2548 for it when allocating stack dynamic objects. */
2550 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2551 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2552 (current_function_outgoing_args_size \
2553 + REG_PARM_STACK_SPACE (FNDECL) + (STACK_POINTER_OFFSET))
2556 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2557 (current_function_outgoing_args_size + (STACK_POINTER_OFFSET))
2561 #define STACK_DYNAMIC_OFFSET(FNDECL) STACK_POINTER_OFFSET
2565 /* Pass through the INSNS of function FNDECL and convert virtual register
2566 references to hard register references. */
2569 instantiate_virtual_regs (fndecl
, insns
)
2575 /* Compute the offsets to use for this function. */
2576 in_arg_offset
= FIRST_PARM_OFFSET (fndecl
);
2577 var_offset
= STARTING_FRAME_OFFSET
;
2578 dynamic_offset
= STACK_DYNAMIC_OFFSET (fndecl
);
2579 out_arg_offset
= STACK_POINTER_OFFSET
;
2581 /* Scan all variables and parameters of this function. For each that is
2582 in memory, instantiate all virtual registers if the result is a valid
2583 address. If not, we do it later. That will handle most uses of virtual
2584 regs on many machines. */
2585 instantiate_decls (fndecl
, 1);
2587 /* Initialize recognition, indicating that volatile is OK. */
2590 /* Scan through all the insns, instantiating every virtual register still
2592 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
2593 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == JUMP_INSN
2594 || GET_CODE (insn
) == CALL_INSN
)
2596 instantiate_virtual_regs_1 (&PATTERN (insn
), insn
, 1);
2597 instantiate_virtual_regs_1 (®_NOTES (insn
), NULL_RTX
, 0);
2600 /* Now instantiate the remaining register equivalences for debugging info.
2601 These will not be valid addresses. */
2602 instantiate_decls (fndecl
, 0);
2604 /* Indicate that, from now on, assign_stack_local should use
2605 frame_pointer_rtx. */
2606 virtuals_instantiated
= 1;
2609 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
2610 all virtual registers in their DECL_RTL's.
2612 If VALID_ONLY, do this only if the resulting address is still valid.
2613 Otherwise, always do it. */
2616 instantiate_decls (fndecl
, valid_only
)
2622 if (DECL_SAVED_INSNS (fndecl
))
2623 /* When compiling an inline function, the obstack used for
2624 rtl allocation is the maybepermanent_obstack. Calling
2625 `resume_temporary_allocation' switches us back to that
2626 obstack while we process this function's parameters. */
2627 resume_temporary_allocation ();
2629 /* Process all parameters of the function. */
2630 for (decl
= DECL_ARGUMENTS (fndecl
); decl
; decl
= TREE_CHAIN (decl
))
2632 int size
= int_size_in_bytes (TREE_TYPE (decl
));
2633 instantiate_decl (DECL_RTL (decl
), size
, valid_only
);
2635 /* If the parameter was promoted, then the incoming RTL mode may be
2636 larger than the declared type size. We must use the larger of
2638 size
= MAX (GET_MODE_SIZE (GET_MODE (DECL_INCOMING_RTL (decl
))), size
);
2639 instantiate_decl (DECL_INCOMING_RTL (decl
), size
, valid_only
);
2642 /* Now process all variables defined in the function or its subblocks. */
2643 instantiate_decls_1 (DECL_INITIAL (fndecl
), valid_only
);
2645 if (DECL_INLINE (fndecl
) || DECL_DEFER_OUTPUT (fndecl
))
2647 /* Save all rtl allocated for this function by raising the
2648 high-water mark on the maybepermanent_obstack. */
2650 /* All further rtl allocation is now done in the current_obstack. */
2651 rtl_in_current_obstack ();
2655 /* Subroutine of instantiate_decls: Process all decls in the given
2656 BLOCK node and all its subblocks. */
2659 instantiate_decls_1 (let
, valid_only
)
2665 for (t
= BLOCK_VARS (let
); t
; t
= TREE_CHAIN (t
))
2666 instantiate_decl (DECL_RTL (t
), int_size_in_bytes (TREE_TYPE (t
)),
2669 /* Process all subblocks. */
2670 for (t
= BLOCK_SUBBLOCKS (let
); t
; t
= TREE_CHAIN (t
))
2671 instantiate_decls_1 (t
, valid_only
);
2674 /* Subroutine of the preceding procedures: Given RTL representing a
2675 decl and the size of the object, do any instantiation required.
2677 If VALID_ONLY is non-zero, it means that the RTL should only be
2678 changed if the new address is valid. */
2681 instantiate_decl (x
, size
, valid_only
)
2686 enum machine_mode mode
;
2689 /* If this is not a MEM, no need to do anything. Similarly if the
2690 address is a constant or a register that is not a virtual register. */
2692 if (x
== 0 || GET_CODE (x
) != MEM
)
2696 if (CONSTANT_P (addr
)
2697 || (GET_CODE (addr
) == REG
2698 && (REGNO (addr
) < FIRST_VIRTUAL_REGISTER
2699 || REGNO (addr
) > LAST_VIRTUAL_REGISTER
)))
2702 /* If we should only do this if the address is valid, copy the address.
2703 We need to do this so we can undo any changes that might make the
2704 address invalid. This copy is unfortunate, but probably can't be
2708 addr
= copy_rtx (addr
);
2710 instantiate_virtual_regs_1 (&addr
, NULL_RTX
, 0);
2714 /* Now verify that the resulting address is valid for every integer or
2715 floating-point mode up to and including SIZE bytes long. We do this
2716 since the object might be accessed in any mode and frame addresses
2719 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
2720 mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) <= size
;
2721 mode
= GET_MODE_WIDER_MODE (mode
))
2722 if (! memory_address_p (mode
, addr
))
2725 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
);
2726 mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) <= size
;
2727 mode
= GET_MODE_WIDER_MODE (mode
))
2728 if (! memory_address_p (mode
, addr
))
2732 /* Put back the address now that we have updated it and we either know
2733 it is valid or we don't care whether it is valid. */
2738 /* Given a pointer to a piece of rtx and an optional pointer to the
2739 containing object, instantiate any virtual registers present in it.
2741 If EXTRA_INSNS, we always do the replacement and generate
2742 any extra insns before OBJECT. If it zero, we do nothing if replacement
2745 Return 1 if we either had nothing to do or if we were able to do the
2746 needed replacement. Return 0 otherwise; we only return zero if
2747 EXTRA_INSNS is zero.
2749 We first try some simple transformations to avoid the creation of extra
2753 instantiate_virtual_regs_1 (loc
, object
, extra_insns
)
2767 /* Re-start here to avoid recursion in common cases. */
2774 code
= GET_CODE (x
);
2776 /* Check for some special cases. */
2793 /* We are allowed to set the virtual registers. This means that
2794 that the actual register should receive the source minus the
2795 appropriate offset. This is used, for example, in the handling
2796 of non-local gotos. */
2797 if (SET_DEST (x
) == virtual_incoming_args_rtx
)
2798 new = arg_pointer_rtx
, offset
= - in_arg_offset
;
2799 else if (SET_DEST (x
) == virtual_stack_vars_rtx
)
2800 new = frame_pointer_rtx
, offset
= - var_offset
;
2801 else if (SET_DEST (x
) == virtual_stack_dynamic_rtx
)
2802 new = stack_pointer_rtx
, offset
= - dynamic_offset
;
2803 else if (SET_DEST (x
) == virtual_outgoing_args_rtx
)
2804 new = stack_pointer_rtx
, offset
= - out_arg_offset
;
2808 /* The only valid sources here are PLUS or REG. Just do
2809 the simplest possible thing to handle them. */
2810 if (GET_CODE (SET_SRC (x
)) != REG
2811 && GET_CODE (SET_SRC (x
)) != PLUS
)
2815 if (GET_CODE (SET_SRC (x
)) != REG
)
2816 temp
= force_operand (SET_SRC (x
), NULL_RTX
);
2819 temp
= force_operand (plus_constant (temp
, offset
), NULL_RTX
);
2823 emit_insns_before (seq
, object
);
2826 if (!validate_change (object
, &SET_SRC (x
), temp
, 0)
2833 instantiate_virtual_regs_1 (&SET_DEST (x
), object
, extra_insns
);
2838 /* Handle special case of virtual register plus constant. */
2839 if (CONSTANT_P (XEXP (x
, 1)))
2841 rtx old
, new_offset
;
2843 /* Check for (plus (plus VIRT foo) (const_int)) first. */
2844 if (GET_CODE (XEXP (x
, 0)) == PLUS
)
2846 rtx inner
= XEXP (XEXP (x
, 0), 0);
2848 if (inner
== virtual_incoming_args_rtx
)
2849 new = arg_pointer_rtx
, offset
= in_arg_offset
;
2850 else if (inner
== virtual_stack_vars_rtx
)
2851 new = frame_pointer_rtx
, offset
= var_offset
;
2852 else if (inner
== virtual_stack_dynamic_rtx
)
2853 new = stack_pointer_rtx
, offset
= dynamic_offset
;
2854 else if (inner
== virtual_outgoing_args_rtx
)
2855 new = stack_pointer_rtx
, offset
= out_arg_offset
;
2862 instantiate_virtual_regs_1 (&XEXP (XEXP (x
, 0), 1), object
,
2864 new = gen_rtx (PLUS
, Pmode
, new, XEXP (XEXP (x
, 0), 1));
2867 else if (XEXP (x
, 0) == virtual_incoming_args_rtx
)
2868 new = arg_pointer_rtx
, offset
= in_arg_offset
;
2869 else if (XEXP (x
, 0) == virtual_stack_vars_rtx
)
2870 new = frame_pointer_rtx
, offset
= var_offset
;
2871 else if (XEXP (x
, 0) == virtual_stack_dynamic_rtx
)
2872 new = stack_pointer_rtx
, offset
= dynamic_offset
;
2873 else if (XEXP (x
, 0) == virtual_outgoing_args_rtx
)
2874 new = stack_pointer_rtx
, offset
= out_arg_offset
;
2877 /* We know the second operand is a constant. Unless the
2878 first operand is a REG (which has been already checked),
2879 it needs to be checked. */
2880 if (GET_CODE (XEXP (x
, 0)) != REG
)
2888 new_offset
= plus_constant (XEXP (x
, 1), offset
);
2890 /* If the new constant is zero, try to replace the sum with just
2892 if (new_offset
== const0_rtx
2893 && validate_change (object
, loc
, new, 0))
2896 /* Next try to replace the register and new offset.
2897 There are two changes to validate here and we can't assume that
2898 in the case of old offset equals new just changing the register
2899 will yield a valid insn. In the interests of a little efficiency,
2900 however, we only call validate change once (we don't queue up the
2901 changes and then call apply_change_group). */
2905 ? ! validate_change (object
, &XEXP (x
, 0), new, 0)
2906 : (XEXP (x
, 0) = new,
2907 ! validate_change (object
, &XEXP (x
, 1), new_offset
, 0)))
2915 /* Otherwise copy the new constant into a register and replace
2916 constant with that register. */
2917 temp
= gen_reg_rtx (Pmode
);
2919 if (validate_change (object
, &XEXP (x
, 1), temp
, 0))
2920 emit_insn_before (gen_move_insn (temp
, new_offset
), object
);
2923 /* If that didn't work, replace this expression with a
2924 register containing the sum. */
2927 new = gen_rtx (PLUS
, Pmode
, new, new_offset
);
2930 temp
= force_operand (new, NULL_RTX
);
2934 emit_insns_before (seq
, object
);
2935 if (! validate_change (object
, loc
, temp
, 0)
2936 && ! validate_replace_rtx (x
, temp
, object
))
2944 /* Fall through to generic two-operand expression case. */
2950 case DIV
: case UDIV
:
2951 case MOD
: case UMOD
:
2952 case AND
: case IOR
: case XOR
:
2953 case ROTATERT
: case ROTATE
:
2954 case ASHIFTRT
: case LSHIFTRT
: case ASHIFT
:
2956 case GE
: case GT
: case GEU
: case GTU
:
2957 case LE
: case LT
: case LEU
: case LTU
:
2958 if (XEXP (x
, 1) && ! CONSTANT_P (XEXP (x
, 1)))
2959 instantiate_virtual_regs_1 (&XEXP (x
, 1), object
, extra_insns
);
2964 /* Most cases of MEM that convert to valid addresses have already been
2965 handled by our scan of decls. The only special handling we
2966 need here is to make a copy of the rtx to ensure it isn't being
2967 shared if we have to change it to a pseudo.
2969 If the rtx is a simple reference to an address via a virtual register,
2970 it can potentially be shared. In such cases, first try to make it
2971 a valid address, which can also be shared. Otherwise, copy it and
2974 First check for common cases that need no processing. These are
2975 usually due to instantiation already being done on a previous instance
2979 if (CONSTANT_ADDRESS_P (temp
)
2980 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2981 || temp
== arg_pointer_rtx
2983 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2984 || temp
== hard_frame_pointer_rtx
2986 || temp
== frame_pointer_rtx
)
2989 if (GET_CODE (temp
) == PLUS
2990 && CONSTANT_ADDRESS_P (XEXP (temp
, 1))
2991 && (XEXP (temp
, 0) == frame_pointer_rtx
2992 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2993 || XEXP (temp
, 0) == hard_frame_pointer_rtx
2995 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2996 || XEXP (temp
, 0) == arg_pointer_rtx
3001 if (temp
== virtual_stack_vars_rtx
3002 || temp
== virtual_incoming_args_rtx
3003 || (GET_CODE (temp
) == PLUS
3004 && CONSTANT_ADDRESS_P (XEXP (temp
, 1))
3005 && (XEXP (temp
, 0) == virtual_stack_vars_rtx
3006 || XEXP (temp
, 0) == virtual_incoming_args_rtx
)))
3008 /* This MEM may be shared. If the substitution can be done without
3009 the need to generate new pseudos, we want to do it in place
3010 so all copies of the shared rtx benefit. The call below will
3011 only make substitutions if the resulting address is still
3014 Note that we cannot pass X as the object in the recursive call
3015 since the insn being processed may not allow all valid
3016 addresses. However, if we were not passed on object, we can
3017 only modify X without copying it if X will have a valid
3020 ??? Also note that this can still lose if OBJECT is an insn that
3021 has less restrictions on an address that some other insn.
3022 In that case, we will modify the shared address. This case
3023 doesn't seem very likely, though. One case where this could
3024 happen is in the case of a USE or CLOBBER reference, but we
3025 take care of that below. */
3027 if (instantiate_virtual_regs_1 (&XEXP (x
, 0),
3028 object
? object
: x
, 0))
3031 /* Otherwise make a copy and process that copy. We copy the entire
3032 RTL expression since it might be a PLUS which could also be
3034 *loc
= x
= copy_rtx (x
);
3037 /* Fall through to generic unary operation case. */
3039 case STRICT_LOW_PART
:
3041 case PRE_DEC
: case PRE_INC
: case POST_DEC
: case POST_INC
:
3042 case SIGN_EXTEND
: case ZERO_EXTEND
:
3043 case TRUNCATE
: case FLOAT_EXTEND
: case FLOAT_TRUNCATE
:
3044 case FLOAT
: case FIX
:
3045 case UNSIGNED_FIX
: case UNSIGNED_FLOAT
:
3049 /* These case either have just one operand or we know that we need not
3050 check the rest of the operands. */
3056 /* If the operand is a MEM, see if the change is a valid MEM. If not,
3057 go ahead and make the invalid one, but do it to a copy. For a REG,
3058 just make the recursive call, since there's no chance of a problem. */
3060 if ((GET_CODE (XEXP (x
, 0)) == MEM
3061 && instantiate_virtual_regs_1 (&XEXP (XEXP (x
, 0), 0), XEXP (x
, 0),
3063 || (GET_CODE (XEXP (x
, 0)) == REG
3064 && instantiate_virtual_regs_1 (&XEXP (x
, 0), object
, 0)))
3067 XEXP (x
, 0) = copy_rtx (XEXP (x
, 0));
3072 /* Try to replace with a PLUS. If that doesn't work, compute the sum
3073 in front of this insn and substitute the temporary. */
3074 if (x
== virtual_incoming_args_rtx
)
3075 new = arg_pointer_rtx
, offset
= in_arg_offset
;
3076 else if (x
== virtual_stack_vars_rtx
)
3077 new = frame_pointer_rtx
, offset
= var_offset
;
3078 else if (x
== virtual_stack_dynamic_rtx
)
3079 new = stack_pointer_rtx
, offset
= dynamic_offset
;
3080 else if (x
== virtual_outgoing_args_rtx
)
3081 new = stack_pointer_rtx
, offset
= out_arg_offset
;
3085 temp
= plus_constant (new, offset
);
3086 if (!validate_change (object
, loc
, temp
, 0))
3092 temp
= force_operand (temp
, NULL_RTX
);
3096 emit_insns_before (seq
, object
);
3097 if (! validate_change (object
, loc
, temp
, 0)
3098 && ! validate_replace_rtx (x
, temp
, object
))
3106 /* Scan all subexpressions. */
3107 fmt
= GET_RTX_FORMAT (code
);
3108 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
3111 if (!instantiate_virtual_regs_1 (&XEXP (x
, i
), object
, extra_insns
))
3114 else if (*fmt
== 'E')
3115 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3116 if (! instantiate_virtual_regs_1 (&XVECEXP (x
, i
, j
), object
,
3123 /* Optimization: assuming this function does not receive nonlocal gotos,
3124 delete the handlers for such, as well as the insns to establish
3125 and disestablish them. */
3131 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3133 /* Delete the handler by turning off the flag that would
3134 prevent jump_optimize from deleting it.
3135 Also permit deletion of the nonlocal labels themselves
3136 if nothing local refers to them. */
3137 if (GET_CODE (insn
) == CODE_LABEL
)
3141 LABEL_PRESERVE_P (insn
) = 0;
3143 /* Remove it from the nonlocal_label list, to avoid confusing
3145 for (t
= nonlocal_labels
, last_t
= 0; t
;
3146 last_t
= t
, t
= TREE_CHAIN (t
))
3147 if (DECL_RTL (TREE_VALUE (t
)) == insn
)
3152 nonlocal_labels
= TREE_CHAIN (nonlocal_labels
);
3154 TREE_CHAIN (last_t
) = TREE_CHAIN (t
);
3157 if (GET_CODE (insn
) == INSN
3158 && ((nonlocal_goto_handler_slot
!= 0
3159 && reg_mentioned_p (nonlocal_goto_handler_slot
, PATTERN (insn
)))
3160 || (nonlocal_goto_stack_level
!= 0
3161 && reg_mentioned_p (nonlocal_goto_stack_level
,
3167 /* Return a list (chain of EXPR_LIST nodes) for the nonlocal labels
3168 of the current function. */
3171 nonlocal_label_rtx_list ()
3176 for (t
= nonlocal_labels
; t
; t
= TREE_CHAIN (t
))
3177 x
= gen_rtx (EXPR_LIST
, VOIDmode
, label_rtx (TREE_VALUE (t
)), x
);
3182 /* Output a USE for any register use in RTL.
3183 This is used with -noreg to mark the extent of lifespan
3184 of any registers used in a user-visible variable's DECL_RTL. */
3190 if (GET_CODE (rtl
) == REG
)
3191 /* This is a register variable. */
3192 emit_insn (gen_rtx (USE
, VOIDmode
, rtl
));
3193 else if (GET_CODE (rtl
) == MEM
3194 && GET_CODE (XEXP (rtl
, 0)) == REG
3195 && (REGNO (XEXP (rtl
, 0)) < FIRST_VIRTUAL_REGISTER
3196 || REGNO (XEXP (rtl
, 0)) > LAST_VIRTUAL_REGISTER
)
3197 && XEXP (rtl
, 0) != current_function_internal_arg_pointer
)
3198 /* This is a variable-sized structure. */
3199 emit_insn (gen_rtx (USE
, VOIDmode
, XEXP (rtl
, 0)));
3202 /* Like use_variable except that it outputs the USEs after INSN
3203 instead of at the end of the insn-chain. */
3206 use_variable_after (rtl
, insn
)
3209 if (GET_CODE (rtl
) == REG
)
3210 /* This is a register variable. */
3211 emit_insn_after (gen_rtx (USE
, VOIDmode
, rtl
), insn
);
3212 else if (GET_CODE (rtl
) == MEM
3213 && GET_CODE (XEXP (rtl
, 0)) == REG
3214 && (REGNO (XEXP (rtl
, 0)) < FIRST_VIRTUAL_REGISTER
3215 || REGNO (XEXP (rtl
, 0)) > LAST_VIRTUAL_REGISTER
)
3216 && XEXP (rtl
, 0) != current_function_internal_arg_pointer
)
3217 /* This is a variable-sized structure. */
3218 emit_insn_after (gen_rtx (USE
, VOIDmode
, XEXP (rtl
, 0)), insn
);
3224 return max_parm_reg
;
3227 /* Return the first insn following those generated by `assign_parms'. */
3230 get_first_nonparm_insn ()
3233 return NEXT_INSN (last_parm_insn
);
3234 return get_insns ();
3237 /* Return the first NOTE_INSN_BLOCK_BEG note in the function.
3238 Crash if there is none. */
3241 get_first_block_beg ()
3243 register rtx searcher
;
3244 register rtx insn
= get_first_nonparm_insn ();
3246 for (searcher
= insn
; searcher
; searcher
= NEXT_INSN (searcher
))
3247 if (GET_CODE (searcher
) == NOTE
3248 && NOTE_LINE_NUMBER (searcher
) == NOTE_INSN_BLOCK_BEG
)
3251 abort (); /* Invalid call to this function. (See comments above.) */
3255 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
3256 This means a type for which function calls must pass an address to the
3257 function or get an address back from the function.
3258 EXP may be a type node or an expression (whose type is tested). */
3261 aggregate_value_p (exp
)
3264 int i
, regno
, nregs
;
3267 if (TREE_CODE_CLASS (TREE_CODE (exp
)) == 't')
3270 type
= TREE_TYPE (exp
);
3272 if (RETURN_IN_MEMORY (type
))
3274 /* Types that are TREE_ADDRESSABLE must be contructed in memory,
3275 and thus can't be returned in registers. */
3276 if (TREE_ADDRESSABLE (type
))
3278 if (flag_pcc_struct_return
&& AGGREGATE_TYPE_P (type
))
3280 /* Make sure we have suitable call-clobbered regs to return
3281 the value in; if not, we must return it in memory. */
3282 reg
= hard_function_value (type
, 0);
3284 /* If we have something other than a REG (e.g. a PARALLEL), then assume
3286 if (GET_CODE (reg
) != REG
)
3289 regno
= REGNO (reg
);
3290 nregs
= HARD_REGNO_NREGS (regno
, TYPE_MODE (type
));
3291 for (i
= 0; i
< nregs
; i
++)
3292 if (! call_used_regs
[regno
+ i
])
3297 /* Assign RTL expressions to the function's parameters.
3298 This may involve copying them into registers and using
3299 those registers as the RTL for them.
3301 If SECOND_TIME is non-zero it means that this function is being
3302 called a second time. This is done by integrate.c when a function's
3303 compilation is deferred. We need to come back here in case the
3304 FUNCTION_ARG macro computes items needed for the rest of the compilation
3305 (such as changing which registers are fixed or caller-saved). But suppress
3306 writing any insns or setting DECL_RTL of anything in this case. */
3309 assign_parms (fndecl
, second_time
)
3314 register rtx entry_parm
= 0;
3315 register rtx stack_parm
= 0;
3316 CUMULATIVE_ARGS args_so_far
;
3317 enum machine_mode promoted_mode
, passed_mode
;
3318 enum machine_mode nominal_mode
, promoted_nominal_mode
;
3320 /* Total space needed so far for args on the stack,
3321 given as a constant and a tree-expression. */
3322 struct args_size stack_args_size
;
3323 tree fntype
= TREE_TYPE (fndecl
);
3324 tree fnargs
= DECL_ARGUMENTS (fndecl
);
3325 /* This is used for the arg pointer when referring to stack args. */
3326 rtx internal_arg_pointer
;
3327 /* This is a dummy PARM_DECL that we used for the function result if
3328 the function returns a structure. */
3329 tree function_result_decl
= 0;
3330 int nparmregs
= list_length (fnargs
) + LAST_VIRTUAL_REGISTER
+ 1;
3331 int varargs_setup
= 0;
3332 rtx conversion_insns
= 0;
3334 /* Nonzero if the last arg is named `__builtin_va_alist',
3335 which is used on some machines for old-fashioned non-ANSI varargs.h;
3336 this should be stuck onto the stack as if it had arrived there. */
3338 = (current_function_varargs
3340 && (parm
= tree_last (fnargs
)) != 0
3342 && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
3343 "__builtin_va_alist")));
3345 /* Nonzero if function takes extra anonymous args.
3346 This means the last named arg must be on the stack
3347 right before the anonymous ones. */
3349 = (TYPE_ARG_TYPES (fntype
) != 0
3350 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype
)))
3351 != void_type_node
));
3353 current_function_stdarg
= stdarg
;
3355 /* If the reg that the virtual arg pointer will be translated into is
3356 not a fixed reg or is the stack pointer, make a copy of the virtual
3357 arg pointer, and address parms via the copy. The frame pointer is
3358 considered fixed even though it is not marked as such.
3360 The second time through, simply use ap to avoid generating rtx. */
3362 if ((ARG_POINTER_REGNUM
== STACK_POINTER_REGNUM
3363 || ! (fixed_regs
[ARG_POINTER_REGNUM
]
3364 || ARG_POINTER_REGNUM
== FRAME_POINTER_REGNUM
))
3366 internal_arg_pointer
= copy_to_reg (virtual_incoming_args_rtx
);
3368 internal_arg_pointer
= virtual_incoming_args_rtx
;
3369 current_function_internal_arg_pointer
= internal_arg_pointer
;
3371 stack_args_size
.constant
= 0;
3372 stack_args_size
.var
= 0;
3374 /* If struct value address is treated as the first argument, make it so. */
3375 if (aggregate_value_p (DECL_RESULT (fndecl
))
3376 && ! current_function_returns_pcc_struct
3377 && struct_value_incoming_rtx
== 0)
3379 tree type
= build_pointer_type (TREE_TYPE (fntype
));
3381 function_result_decl
= build_decl (PARM_DECL
, NULL_TREE
, type
);
3383 DECL_ARG_TYPE (function_result_decl
) = type
;
3384 TREE_CHAIN (function_result_decl
) = fnargs
;
3385 fnargs
= function_result_decl
;
3388 parm_reg_stack_loc
= (rtx
*) oballoc (nparmregs
* sizeof (rtx
));
3389 bzero ((char *) parm_reg_stack_loc
, nparmregs
* sizeof (rtx
));
3391 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
3392 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far
, fntype
, NULL_RTX
);
3394 INIT_CUMULATIVE_ARGS (args_so_far
, fntype
, NULL_RTX
, 0);
3397 /* We haven't yet found an argument that we must push and pretend the
3399 current_function_pretend_args_size
= 0;
3401 for (parm
= fnargs
; parm
; parm
= TREE_CHAIN (parm
))
3403 int aggregate
= AGGREGATE_TYPE_P (TREE_TYPE (parm
));
3404 struct args_size stack_offset
;
3405 struct args_size arg_size
;
3406 int passed_pointer
= 0;
3407 int did_conversion
= 0;
3408 tree passed_type
= DECL_ARG_TYPE (parm
);
3409 tree nominal_type
= TREE_TYPE (parm
);
3411 /* Set LAST_NAMED if this is last named arg before some
3412 anonymous args. We treat it as if it were anonymous too. */
3413 int last_named
= ((TREE_CHAIN (parm
) == 0
3414 || DECL_NAME (TREE_CHAIN (parm
)) == 0)
3415 && (stdarg
|| current_function_varargs
));
3417 if (TREE_TYPE (parm
) == error_mark_node
3418 /* This can happen after weird syntax errors
3419 or if an enum type is defined among the parms. */
3420 || TREE_CODE (parm
) != PARM_DECL
3421 || passed_type
== NULL
)
3423 DECL_INCOMING_RTL (parm
) = DECL_RTL (parm
) = gen_rtx (MEM
, BLKmode
,
3425 TREE_USED (parm
) = 1;
3429 /* For varargs.h function, save info about regs and stack space
3430 used by the individual args, not including the va_alist arg. */
3431 if (hide_last_arg
&& last_named
)
3432 current_function_args_info
= args_so_far
;
3434 /* Find mode of arg as it is passed, and mode of arg
3435 as it should be during execution of this function. */
3436 passed_mode
= TYPE_MODE (passed_type
);
3437 nominal_mode
= TYPE_MODE (nominal_type
);
3439 /* If the parm's mode is VOID, its value doesn't matter,
3440 and avoid the usual things like emit_move_insn that could crash. */
3441 if (nominal_mode
== VOIDmode
)
3443 DECL_INCOMING_RTL (parm
) = DECL_RTL (parm
) = const0_rtx
;
3447 /* If the parm is to be passed as a transparent union, use the
3448 type of the first field for the tests below. We have already
3449 verified that the modes are the same. */
3450 if (DECL_TRANSPARENT_UNION (parm
)
3451 || TYPE_TRANSPARENT_UNION (passed_type
))
3452 passed_type
= TREE_TYPE (TYPE_FIELDS (passed_type
));
3454 /* See if this arg was passed by invisible reference. It is if
3455 it is an object whose size depends on the contents of the
3456 object itself or if the machine requires these objects be passed
3459 if ((TREE_CODE (TYPE_SIZE (passed_type
)) != INTEGER_CST
3460 && contains_placeholder_p (TYPE_SIZE (passed_type
)))
3461 || TREE_ADDRESSABLE (passed_type
)
3462 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
3463 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far
, passed_mode
,
3464 passed_type
, ! last_named
)
3468 passed_type
= nominal_type
= build_pointer_type (passed_type
);
3470 passed_mode
= nominal_mode
= Pmode
;
3473 promoted_mode
= passed_mode
;
3475 #ifdef PROMOTE_FUNCTION_ARGS
3476 /* Compute the mode in which the arg is actually extended to. */
3477 promoted_mode
= promote_mode (passed_type
, promoted_mode
, &unsignedp
, 1);
3480 /* Let machine desc say which reg (if any) the parm arrives in.
3481 0 means it arrives on the stack. */
3482 #ifdef FUNCTION_INCOMING_ARG
3483 entry_parm
= FUNCTION_INCOMING_ARG (args_so_far
, promoted_mode
,
3484 passed_type
, ! last_named
);
3486 entry_parm
= FUNCTION_ARG (args_so_far
, promoted_mode
,
3487 passed_type
, ! last_named
);
3490 if (entry_parm
== 0)
3491 promoted_mode
= passed_mode
;
3493 #ifdef SETUP_INCOMING_VARARGS
3494 /* If this is the last named parameter, do any required setup for
3495 varargs or stdargs. We need to know about the case of this being an
3496 addressable type, in which case we skip the registers it
3497 would have arrived in.
3499 For stdargs, LAST_NAMED will be set for two parameters, the one that
3500 is actually the last named, and the dummy parameter. We only
3501 want to do this action once.
3503 Also, indicate when RTL generation is to be suppressed. */
3504 if (last_named
&& !varargs_setup
)
3506 SETUP_INCOMING_VARARGS (args_so_far
, promoted_mode
, passed_type
,
3507 current_function_pretend_args_size
,
3513 /* Determine parm's home in the stack,
3514 in case it arrives in the stack or we should pretend it did.
3516 Compute the stack position and rtx where the argument arrives
3519 There is one complexity here: If this was a parameter that would
3520 have been passed in registers, but wasn't only because it is
3521 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
3522 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
3523 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
3524 0 as it was the previous time. */
3526 locate_and_pad_parm (promoted_mode
, passed_type
,
3527 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3530 #ifdef FUNCTION_INCOMING_ARG
3531 FUNCTION_INCOMING_ARG (args_so_far
, promoted_mode
,
3534 || varargs_setup
)) != 0,
3536 FUNCTION_ARG (args_so_far
, promoted_mode
,
3538 ! last_named
|| varargs_setup
) != 0,
3541 fndecl
, &stack_args_size
, &stack_offset
, &arg_size
);
3545 rtx offset_rtx
= ARGS_SIZE_RTX (stack_offset
);
3547 if (offset_rtx
== const0_rtx
)
3548 stack_parm
= gen_rtx (MEM
, promoted_mode
, internal_arg_pointer
);
3550 stack_parm
= gen_rtx (MEM
, promoted_mode
,
3551 gen_rtx (PLUS
, Pmode
,
3552 internal_arg_pointer
, offset_rtx
));
3554 /* If this is a memory ref that contains aggregate components,
3555 mark it as such for cse and loop optimize. Likewise if it
3557 MEM_IN_STRUCT_P (stack_parm
) = aggregate
;
3558 RTX_UNCHANGING_P (stack_parm
) = TREE_READONLY (parm
);
3561 /* If this parameter was passed both in registers and in the stack,
3562 use the copy on the stack. */
3563 if (MUST_PASS_IN_STACK (promoted_mode
, passed_type
))
3566 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3567 /* If this parm was passed part in regs and part in memory,
3568 pretend it arrived entirely in memory
3569 by pushing the register-part onto the stack.
3571 In the special case of a DImode or DFmode that is split,
3572 we could put it together in a pseudoreg directly,
3573 but for now that's not worth bothering with. */
3577 int nregs
= FUNCTION_ARG_PARTIAL_NREGS (args_so_far
, promoted_mode
,
3578 passed_type
, ! last_named
);
3582 current_function_pretend_args_size
3583 = (((nregs
* UNITS_PER_WORD
) + (PARM_BOUNDARY
/ BITS_PER_UNIT
) - 1)
3584 / (PARM_BOUNDARY
/ BITS_PER_UNIT
)
3585 * (PARM_BOUNDARY
/ BITS_PER_UNIT
));
3589 /* Handle calls that pass values in multiple non-contiguous
3590 locations. The Irix 6 ABI has examples of this. */
3591 if (GET_CODE (entry_parm
) == PARALLEL
)
3592 emit_group_store (validize_mem (stack_parm
),
3595 move_block_from_reg (REGNO (entry_parm
),
3596 validize_mem (stack_parm
), nregs
,
3597 int_size_in_bytes (TREE_TYPE (parm
)));
3599 entry_parm
= stack_parm
;
3604 /* If we didn't decide this parm came in a register,
3605 by default it came on the stack. */
3606 if (entry_parm
== 0)
3607 entry_parm
= stack_parm
;
3609 /* Record permanently how this parm was passed. */
3611 DECL_INCOMING_RTL (parm
) = entry_parm
;
3613 /* If there is actually space on the stack for this parm,
3614 count it in stack_args_size; otherwise set stack_parm to 0
3615 to indicate there is no preallocated stack slot for the parm. */
3617 if (entry_parm
== stack_parm
3618 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
3619 /* On some machines, even if a parm value arrives in a register
3620 there is still an (uninitialized) stack slot allocated for it.
3622 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
3623 whether this parameter already has a stack slot allocated,
3624 because an arg block exists only if current_function_args_size
3625 is larger than some threshold, and we haven't calculated that
3626 yet. So, for now, we just assume that stack slots never exist
3628 || REG_PARM_STACK_SPACE (fndecl
) > 0
3632 stack_args_size
.constant
+= arg_size
.constant
;
3634 ADD_PARM_SIZE (stack_args_size
, arg_size
.var
);
3637 /* No stack slot was pushed for this parm. */
3640 /* Update info on where next arg arrives in registers. */
3642 FUNCTION_ARG_ADVANCE (args_so_far
, promoted_mode
,
3643 passed_type
, ! last_named
);
3645 /* If this is our second time through, we are done with this parm. */
3649 /* If we can't trust the parm stack slot to be aligned enough
3650 for its ultimate type, don't use that slot after entry.
3651 We'll make another stack slot, if we need one. */
3653 int thisparm_boundary
3654 = FUNCTION_ARG_BOUNDARY (promoted_mode
, passed_type
);
3656 if (GET_MODE_ALIGNMENT (nominal_mode
) > thisparm_boundary
)
3660 /* If parm was passed in memory, and we need to convert it on entry,
3661 don't store it back in that same slot. */
3663 && nominal_mode
!= BLKmode
&& nominal_mode
!= passed_mode
)
3667 /* Now adjust STACK_PARM to the mode and precise location
3668 where this parameter should live during execution,
3669 if we discover that it must live in the stack during execution.
3670 To make debuggers happier on big-endian machines, we store
3671 the value in the last bytes of the space available. */
3673 if (nominal_mode
!= BLKmode
&& nominal_mode
!= passed_mode
3678 if (BYTES_BIG_ENDIAN
3679 && GET_MODE_SIZE (nominal_mode
) < UNITS_PER_WORD
)
3680 stack_offset
.constant
+= (GET_MODE_SIZE (passed_mode
)
3681 - GET_MODE_SIZE (nominal_mode
));
3683 offset_rtx
= ARGS_SIZE_RTX (stack_offset
);
3684 if (offset_rtx
== const0_rtx
)
3685 stack_parm
= gen_rtx (MEM
, nominal_mode
, internal_arg_pointer
);
3687 stack_parm
= gen_rtx (MEM
, nominal_mode
,
3688 gen_rtx (PLUS
, Pmode
,
3689 internal_arg_pointer
, offset_rtx
));
3691 /* If this is a memory ref that contains aggregate components,
3692 mark it as such for cse and loop optimize. */
3693 MEM_IN_STRUCT_P (stack_parm
) = aggregate
;
3698 /* We need this "use" info, because the gcc-register->stack-register
3699 converter in reg-stack.c needs to know which registers are active
3700 at the start of the function call. The actual parameter loading
3701 instructions are not always available then anymore, since they might
3702 have been optimised away. */
3704 if (GET_CODE (entry_parm
) == REG
&& !(hide_last_arg
&& last_named
))
3705 emit_insn (gen_rtx (USE
, GET_MODE (entry_parm
), entry_parm
));
3708 /* ENTRY_PARM is an RTX for the parameter as it arrives,
3709 in the mode in which it arrives.
3710 STACK_PARM is an RTX for a stack slot where the parameter can live
3711 during the function (in case we want to put it there).
3712 STACK_PARM is 0 if no stack slot was pushed for it.
3714 Now output code if necessary to convert ENTRY_PARM to
3715 the type in which this function declares it,
3716 and store that result in an appropriate place,
3717 which may be a pseudo reg, may be STACK_PARM,
3718 or may be a local stack slot if STACK_PARM is 0.
3720 Set DECL_RTL to that place. */
3722 if (nominal_mode
== BLKmode
|| GET_CODE (entry_parm
) == PARALLEL
)
3724 /* If a BLKmode arrives in registers, copy it to a stack slot.
3725 Handle calls that pass values in multiple non-contiguous
3726 locations. The Irix 6 ABI has examples of this. */
3727 if (GET_CODE (entry_parm
) == REG
3728 || GET_CODE (entry_parm
) == PARALLEL
)
3731 = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm
)),
3734 /* Note that we will be storing an integral number of words.
3735 So we have to be careful to ensure that we allocate an
3736 integral number of words. We do this below in the
3737 assign_stack_local if space was not allocated in the argument
3738 list. If it was, this will not work if PARM_BOUNDARY is not
3739 a multiple of BITS_PER_WORD. It isn't clear how to fix this
3740 if it becomes a problem. */
3742 if (stack_parm
== 0)
3745 = assign_stack_local (GET_MODE (entry_parm
),
3748 /* If this is a memory ref that contains aggregate
3749 components, mark it as such for cse and loop optimize. */
3750 MEM_IN_STRUCT_P (stack_parm
) = aggregate
;
3753 else if (PARM_BOUNDARY
% BITS_PER_WORD
!= 0)
3756 if (TREE_READONLY (parm
))
3757 RTX_UNCHANGING_P (stack_parm
) = 1;
3759 /* Handle calls that pass values in multiple non-contiguous
3760 locations. The Irix 6 ABI has examples of this. */
3761 if (GET_CODE (entry_parm
) == PARALLEL
)
3762 emit_group_store (validize_mem (stack_parm
), entry_parm
);
3764 move_block_from_reg (REGNO (entry_parm
),
3765 validize_mem (stack_parm
),
3766 size_stored
/ UNITS_PER_WORD
,
3767 int_size_in_bytes (TREE_TYPE (parm
)));
3769 DECL_RTL (parm
) = stack_parm
;
3771 else if (! ((obey_regdecls
&& ! DECL_REGISTER (parm
)
3772 && ! DECL_INLINE (fndecl
))
3773 /* layout_decl may set this. */
3774 || TREE_ADDRESSABLE (parm
)
3775 || TREE_SIDE_EFFECTS (parm
)
3776 /* If -ffloat-store specified, don't put explicit
3777 float variables into registers. */
3778 || (flag_float_store
3779 && TREE_CODE (TREE_TYPE (parm
)) == REAL_TYPE
))
3780 /* Always assign pseudo to structure return or item passed
3781 by invisible reference. */
3782 || passed_pointer
|| parm
== function_result_decl
)
3784 /* Store the parm in a pseudoregister during the function, but we
3785 may need to do it in a wider mode. */
3787 register rtx parmreg
;
3788 int regno
, regnoi
, regnor
;
3790 unsignedp
= TREE_UNSIGNED (TREE_TYPE (parm
));
3792 promoted_nominal_mode
3793 = promote_mode (TREE_TYPE (parm
), nominal_mode
, &unsignedp
, 0);
3795 parmreg
= gen_reg_rtx (promoted_nominal_mode
);
3796 mark_user_reg (parmreg
);
3798 /* If this was an item that we received a pointer to, set DECL_RTL
3803 = gen_rtx (MEM
, TYPE_MODE (TREE_TYPE (passed_type
)), parmreg
);
3804 MEM_IN_STRUCT_P (DECL_RTL (parm
)) = aggregate
;
3807 DECL_RTL (parm
) = parmreg
;
3809 /* Copy the value into the register. */
3810 if (nominal_mode
!= passed_mode
3811 || promoted_nominal_mode
!= promoted_mode
)
3813 /* ENTRY_PARM has been converted to PROMOTED_MODE, its
3814 mode, by the caller. We now have to convert it to
3815 NOMINAL_MODE, if different. However, PARMREG may be in
3816 a diffent mode than NOMINAL_MODE if it is being stored
3819 If ENTRY_PARM is a hard register, it might be in a register
3820 not valid for operating in its mode (e.g., an odd-numbered
3821 register for a DFmode). In that case, moves are the only
3822 thing valid, so we can't do a convert from there. This
3823 occurs when the calling sequence allow such misaligned
3826 In addition, the conversion may involve a call, which could
3827 clobber parameters which haven't been copied to pseudo
3828 registers yet. Therefore, we must first copy the parm to
3829 a pseudo reg here, and save the conversion until after all
3830 parameters have been moved. */
3832 rtx tempreg
= gen_reg_rtx (GET_MODE (entry_parm
));
3834 emit_move_insn (tempreg
, validize_mem (entry_parm
));
3836 push_to_sequence (conversion_insns
);
3837 tempreg
= convert_to_mode (nominal_mode
, tempreg
, unsignedp
);
3839 expand_assignment (parm
,
3840 make_tree (nominal_type
, tempreg
), 0, 0);
3841 conversion_insns
= get_insns ();
3846 emit_move_insn (parmreg
, validize_mem (entry_parm
));
3848 /* If we were passed a pointer but the actual value
3849 can safely live in a register, put it in one. */
3850 if (passed_pointer
&& TYPE_MODE (TREE_TYPE (parm
)) != BLKmode
3851 && ! ((obey_regdecls
&& ! DECL_REGISTER (parm
)
3852 && ! DECL_INLINE (fndecl
))
3853 /* layout_decl may set this. */
3854 || TREE_ADDRESSABLE (parm
)
3855 || TREE_SIDE_EFFECTS (parm
)
3856 /* If -ffloat-store specified, don't put explicit
3857 float variables into registers. */
3858 || (flag_float_store
3859 && TREE_CODE (TREE_TYPE (parm
)) == REAL_TYPE
)))
3861 /* We can't use nominal_mode, because it will have been set to
3862 Pmode above. We must use the actual mode of the parm. */
3863 parmreg
= gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm
)));
3864 mark_user_reg (parmreg
);
3865 emit_move_insn (parmreg
, DECL_RTL (parm
));
3866 DECL_RTL (parm
) = parmreg
;
3867 /* STACK_PARM is the pointer, not the parm, and PARMREG is
3871 #ifdef FUNCTION_ARG_CALLEE_COPIES
3872 /* If we are passed an arg by reference and it is our responsibility
3873 to make a copy, do it now.
3874 PASSED_TYPE and PASSED mode now refer to the pointer, not the
3875 original argument, so we must recreate them in the call to
3876 FUNCTION_ARG_CALLEE_COPIES. */
3877 /* ??? Later add code to handle the case that if the argument isn't
3878 modified, don't do the copy. */
3880 else if (passed_pointer
3881 && FUNCTION_ARG_CALLEE_COPIES (args_so_far
,
3882 TYPE_MODE (DECL_ARG_TYPE (parm
)),
3883 DECL_ARG_TYPE (parm
),
3885 && ! TREE_ADDRESSABLE (DECL_ARG_TYPE (parm
)))
3888 tree type
= DECL_ARG_TYPE (parm
);
3890 /* This sequence may involve a library call perhaps clobbering
3891 registers that haven't been copied to pseudos yet. */
3893 push_to_sequence (conversion_insns
);
3895 if (TYPE_SIZE (type
) == 0
3896 || TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
3897 /* This is a variable sized object. */
3898 copy
= gen_rtx (MEM
, BLKmode
,
3899 allocate_dynamic_stack_space
3900 (expr_size (parm
), NULL_RTX
,
3901 TYPE_ALIGN (type
)));
3903 copy
= assign_stack_temp (TYPE_MODE (type
),
3904 int_size_in_bytes (type
), 1);
3905 MEM_IN_STRUCT_P (copy
) = AGGREGATE_TYPE_P (type
);
3907 store_expr (parm
, copy
, 0);
3908 emit_move_insn (parmreg
, XEXP (copy
, 0));
3909 conversion_insns
= get_insns ();
3913 #endif /* FUNCTION_ARG_CALLEE_COPIES */
3915 /* In any case, record the parm's desired stack location
3916 in case we later discover it must live in the stack.
3918 If it is a COMPLEX value, store the stack location for both
3921 if (GET_CODE (parmreg
) == CONCAT
)
3922 regno
= MAX (REGNO (XEXP (parmreg
, 0)), REGNO (XEXP (parmreg
, 1)));
3924 regno
= REGNO (parmreg
);
3926 if (regno
>= nparmregs
)
3929 int old_nparmregs
= nparmregs
;
3931 nparmregs
= regno
+ 5;
3932 new = (rtx
*) oballoc (nparmregs
* sizeof (rtx
));
3933 bcopy ((char *) parm_reg_stack_loc
, (char *) new,
3934 old_nparmregs
* sizeof (rtx
));
3935 bzero ((char *) (new + old_nparmregs
),
3936 (nparmregs
- old_nparmregs
) * sizeof (rtx
));
3937 parm_reg_stack_loc
= new;
3940 if (GET_CODE (parmreg
) == CONCAT
)
3942 enum machine_mode submode
= GET_MODE (XEXP (parmreg
, 0));
3944 regnor
= REGNO (gen_realpart (submode
, parmreg
));
3945 regnoi
= REGNO (gen_imagpart (submode
, parmreg
));
3947 if (stack_parm
!= 0)
3949 parm_reg_stack_loc
[regnor
]
3950 = gen_realpart (submode
, stack_parm
);
3951 parm_reg_stack_loc
[regnoi
]
3952 = gen_imagpart (submode
, stack_parm
);
3956 parm_reg_stack_loc
[regnor
] = 0;
3957 parm_reg_stack_loc
[regnoi
] = 0;
3961 parm_reg_stack_loc
[REGNO (parmreg
)] = stack_parm
;
3963 /* Mark the register as eliminable if we did no conversion
3964 and it was copied from memory at a fixed offset,
3965 and the arg pointer was not copied to a pseudo-reg.
3966 If the arg pointer is a pseudo reg or the offset formed
3967 an invalid address, such memory-equivalences
3968 as we make here would screw up life analysis for it. */
3969 if (nominal_mode
== passed_mode
3972 && GET_CODE (stack_parm
) == MEM
3973 && stack_offset
.var
== 0
3974 && reg_mentioned_p (virtual_incoming_args_rtx
,
3975 XEXP (stack_parm
, 0)))
3977 rtx linsn
= get_last_insn ();
3980 /* Mark complex types separately. */
3981 if (GET_CODE (parmreg
) == CONCAT
)
3982 /* Scan backwards for the set of the real and
3984 for (sinsn
= linsn
; sinsn
!= 0;
3985 sinsn
= prev_nonnote_insn (sinsn
))
3987 set
= single_set (sinsn
);
3989 && SET_DEST (set
) == regno_reg_rtx
[regnoi
])
3991 = gen_rtx (EXPR_LIST
, REG_EQUIV
,
3992 parm_reg_stack_loc
[regnoi
],
3995 && SET_DEST (set
) == regno_reg_rtx
[regnor
])
3997 = gen_rtx (EXPR_LIST
, REG_EQUIV
,
3998 parm_reg_stack_loc
[regnor
],
4001 else if ((set
= single_set (linsn
)) != 0
4002 && SET_DEST (set
) == parmreg
)
4004 = gen_rtx (EXPR_LIST
, REG_EQUIV
,
4005 stack_parm
, REG_NOTES (linsn
));
4008 /* For pointer data type, suggest pointer register. */
4009 if (TREE_CODE (TREE_TYPE (parm
)) == POINTER_TYPE
)
4010 mark_reg_pointer (parmreg
,
4011 (TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm
)))
4016 /* Value must be stored in the stack slot STACK_PARM
4017 during function execution. */
4019 if (promoted_mode
!= nominal_mode
)
4021 /* Conversion is required. */
4022 rtx tempreg
= gen_reg_rtx (GET_MODE (entry_parm
));
4024 emit_move_insn (tempreg
, validize_mem (entry_parm
));
4026 push_to_sequence (conversion_insns
);
4027 entry_parm
= convert_to_mode (nominal_mode
, tempreg
,
4028 TREE_UNSIGNED (TREE_TYPE (parm
)));
4029 conversion_insns
= get_insns ();
4034 if (entry_parm
!= stack_parm
)
4036 if (stack_parm
== 0)
4039 = assign_stack_local (GET_MODE (entry_parm
),
4040 GET_MODE_SIZE (GET_MODE (entry_parm
)), 0);
4041 /* If this is a memory ref that contains aggregate components,
4042 mark it as such for cse and loop optimize. */
4043 MEM_IN_STRUCT_P (stack_parm
) = aggregate
;
4046 if (promoted_mode
!= nominal_mode
)
4048 push_to_sequence (conversion_insns
);
4049 emit_move_insn (validize_mem (stack_parm
),
4050 validize_mem (entry_parm
));
4051 conversion_insns
= get_insns ();
4055 emit_move_insn (validize_mem (stack_parm
),
4056 validize_mem (entry_parm
));
4059 DECL_RTL (parm
) = stack_parm
;
4062 /* If this "parameter" was the place where we are receiving the
4063 function's incoming structure pointer, set up the result. */
4064 if (parm
== function_result_decl
)
4066 tree result
= DECL_RESULT (fndecl
);
4067 tree restype
= TREE_TYPE (result
);
4070 = gen_rtx (MEM
, DECL_MODE (result
), DECL_RTL (parm
));
4072 MEM_IN_STRUCT_P (DECL_RTL (result
)) = AGGREGATE_TYPE_P (restype
);
4075 if (TREE_THIS_VOLATILE (parm
))
4076 MEM_VOLATILE_P (DECL_RTL (parm
)) = 1;
4077 if (TREE_READONLY (parm
))
4078 RTX_UNCHANGING_P (DECL_RTL (parm
)) = 1;
4081 /* Output all parameter conversion instructions (possibly including calls)
4082 now that all parameters have been copied out of hard registers. */
4083 emit_insns (conversion_insns
);
4085 max_parm_reg
= max_reg_num ();
4086 last_parm_insn
= get_last_insn ();
4088 current_function_args_size
= stack_args_size
.constant
;
4090 /* Adjust function incoming argument size for alignment and
4093 #ifdef REG_PARM_STACK_SPACE
4094 #ifndef MAYBE_REG_PARM_STACK_SPACE
4095 current_function_args_size
= MAX (current_function_args_size
,
4096 REG_PARM_STACK_SPACE (fndecl
));
4100 #ifdef STACK_BOUNDARY
4101 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
4103 current_function_args_size
4104 = ((current_function_args_size
+ STACK_BYTES
- 1)
4105 / STACK_BYTES
) * STACK_BYTES
;
4108 #ifdef ARGS_GROW_DOWNWARD
4109 current_function_arg_offset_rtx
4110 = (stack_args_size
.var
== 0 ? GEN_INT (-stack_args_size
.constant
)
4111 : expand_expr (size_binop (MINUS_EXPR
, stack_args_size
.var
,
4112 size_int (-stack_args_size
.constant
)),
4113 NULL_RTX
, VOIDmode
, 0));
4115 current_function_arg_offset_rtx
= ARGS_SIZE_RTX (stack_args_size
);
4118 /* See how many bytes, if any, of its args a function should try to pop
4121 current_function_pops_args
= RETURN_POPS_ARGS (fndecl
, TREE_TYPE (fndecl
),
4122 current_function_args_size
);
4124 /* For stdarg.h function, save info about
4125 regs and stack space used by the named args. */
4128 current_function_args_info
= args_so_far
;
4130 /* Set the rtx used for the function return value. Put this in its
4131 own variable so any optimizers that need this information don't have
4132 to include tree.h. Do this here so it gets done when an inlined
4133 function gets output. */
4135 current_function_return_rtx
= DECL_RTL (DECL_RESULT (fndecl
));
4138 /* Indicate whether REGNO is an incoming argument to the current function
4139 that was promoted to a wider mode. If so, return the RTX for the
4140 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
4141 that REGNO is promoted from and whether the promotion was signed or
4144 #ifdef PROMOTE_FUNCTION_ARGS
4147 promoted_input_arg (regno
, pmode
, punsignedp
)
4149 enum machine_mode
*pmode
;
4154 for (arg
= DECL_ARGUMENTS (current_function_decl
); arg
;
4155 arg
= TREE_CHAIN (arg
))
4156 if (GET_CODE (DECL_INCOMING_RTL (arg
)) == REG
4157 && REGNO (DECL_INCOMING_RTL (arg
)) == regno
4158 && TYPE_MODE (DECL_ARG_TYPE (arg
)) == TYPE_MODE (TREE_TYPE (arg
)))
4160 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (arg
));
4161 int unsignedp
= TREE_UNSIGNED (TREE_TYPE (arg
));
4163 mode
= promote_mode (TREE_TYPE (arg
), mode
, &unsignedp
, 1);
4164 if (mode
== GET_MODE (DECL_INCOMING_RTL (arg
))
4165 && mode
!= DECL_MODE (arg
))
4167 *pmode
= DECL_MODE (arg
);
4168 *punsignedp
= unsignedp
;
4169 return DECL_INCOMING_RTL (arg
);
4178 /* Compute the size and offset from the start of the stacked arguments for a
4179 parm passed in mode PASSED_MODE and with type TYPE.
4181 INITIAL_OFFSET_PTR points to the current offset into the stacked
4184 The starting offset and size for this parm are returned in *OFFSET_PTR
4185 and *ARG_SIZE_PTR, respectively.
4187 IN_REGS is non-zero if the argument will be passed in registers. It will
4188 never be set if REG_PARM_STACK_SPACE is not defined.
4190 FNDECL is the function in which the argument was defined.
4192 There are two types of rounding that are done. The first, controlled by
4193 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
4194 list to be aligned to the specific boundary (in bits). This rounding
4195 affects the initial and starting offsets, but not the argument size.
4197 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
4198 optionally rounds the size of the parm to PARM_BOUNDARY. The
4199 initial offset is not affected by this rounding, while the size always
4200 is and the starting offset may be. */
4202 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
4203 initial_offset_ptr is positive because locate_and_pad_parm's
4204 callers pass in the total size of args so far as
4205 initial_offset_ptr. arg_size_ptr is always positive.*/
4208 locate_and_pad_parm (passed_mode
, type
, in_regs
, fndecl
,
4209 initial_offset_ptr
, offset_ptr
, arg_size_ptr
)
4210 enum machine_mode passed_mode
;
4214 struct args_size
*initial_offset_ptr
;
4215 struct args_size
*offset_ptr
;
4216 struct args_size
*arg_size_ptr
;
4219 = type
? size_in_bytes (type
) : size_int (GET_MODE_SIZE (passed_mode
));
4220 enum direction where_pad
= FUNCTION_ARG_PADDING (passed_mode
, type
);
4221 int boundary
= FUNCTION_ARG_BOUNDARY (passed_mode
, type
);
4222 int boundary_in_bytes
= boundary
/ BITS_PER_UNIT
;
4223 int reg_parm_stack_space
= 0;
4225 #ifdef REG_PARM_STACK_SPACE
4226 /* If we have found a stack parm before we reach the end of the
4227 area reserved for registers, skip that area. */
4230 #ifdef MAYBE_REG_PARM_STACK_SPACE
4231 reg_parm_stack_space
= MAYBE_REG_PARM_STACK_SPACE
;
4233 reg_parm_stack_space
= REG_PARM_STACK_SPACE (fndecl
);
4235 if (reg_parm_stack_space
> 0)
4237 if (initial_offset_ptr
->var
)
4239 initial_offset_ptr
->var
4240 = size_binop (MAX_EXPR
, ARGS_SIZE_TREE (*initial_offset_ptr
),
4241 size_int (reg_parm_stack_space
));
4242 initial_offset_ptr
->constant
= 0;
4244 else if (initial_offset_ptr
->constant
< reg_parm_stack_space
)
4245 initial_offset_ptr
->constant
= reg_parm_stack_space
;
4248 #endif /* REG_PARM_STACK_SPACE */
4250 arg_size_ptr
->var
= 0;
4251 arg_size_ptr
->constant
= 0;
4253 #ifdef ARGS_GROW_DOWNWARD
4254 if (initial_offset_ptr
->var
)
4256 offset_ptr
->constant
= 0;
4257 offset_ptr
->var
= size_binop (MINUS_EXPR
, integer_zero_node
,
4258 initial_offset_ptr
->var
);
4262 offset_ptr
->constant
= - initial_offset_ptr
->constant
;
4263 offset_ptr
->var
= 0;
4265 if (where_pad
!= none
4266 && (TREE_CODE (sizetree
) != INTEGER_CST
4267 || ((TREE_INT_CST_LOW (sizetree
) * BITS_PER_UNIT
) % PARM_BOUNDARY
)))
4268 sizetree
= round_up (sizetree
, PARM_BOUNDARY
/ BITS_PER_UNIT
);
4269 SUB_PARM_SIZE (*offset_ptr
, sizetree
);
4270 if (where_pad
!= downward
)
4271 pad_to_arg_alignment (offset_ptr
, boundary
);
4272 if (initial_offset_ptr
->var
)
4274 arg_size_ptr
->var
= size_binop (MINUS_EXPR
,
4275 size_binop (MINUS_EXPR
,
4277 initial_offset_ptr
->var
),
4282 arg_size_ptr
->constant
= (- initial_offset_ptr
->constant
4283 - offset_ptr
->constant
);
4285 #else /* !ARGS_GROW_DOWNWARD */
4286 pad_to_arg_alignment (initial_offset_ptr
, boundary
);
4287 *offset_ptr
= *initial_offset_ptr
;
4289 #ifdef PUSH_ROUNDING
4290 if (passed_mode
!= BLKmode
)
4291 sizetree
= size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree
)));
4294 /* Pad_below needs the pre-rounded size to know how much to pad below
4295 so this must be done before rounding up. */
4296 if (where_pad
== downward
4297 /* However, BLKmode args passed in regs have their padding done elsewhere.
4298 The stack slot must be able to hold the entire register. */
4299 && !(in_regs
&& passed_mode
== BLKmode
))
4300 pad_below (offset_ptr
, passed_mode
, sizetree
);
4302 if (where_pad
!= none
4303 && (TREE_CODE (sizetree
) != INTEGER_CST
4304 || ((TREE_INT_CST_LOW (sizetree
) * BITS_PER_UNIT
) % PARM_BOUNDARY
)))
4305 sizetree
= round_up (sizetree
, PARM_BOUNDARY
/ BITS_PER_UNIT
);
4307 ADD_PARM_SIZE (*arg_size_ptr
, sizetree
);
4308 #endif /* ARGS_GROW_DOWNWARD */
4311 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
4312 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
4315 pad_to_arg_alignment (offset_ptr
, boundary
)
4316 struct args_size
*offset_ptr
;
4319 int boundary_in_bytes
= boundary
/ BITS_PER_UNIT
;
4321 if (boundary
> BITS_PER_UNIT
)
4323 if (offset_ptr
->var
)
4326 #ifdef ARGS_GROW_DOWNWARD
4331 (ARGS_SIZE_TREE (*offset_ptr
),
4332 boundary
/ BITS_PER_UNIT
);
4333 offset_ptr
->constant
= 0; /*?*/
4336 offset_ptr
->constant
=
4337 #ifdef ARGS_GROW_DOWNWARD
4338 FLOOR_ROUND (offset_ptr
->constant
, boundary_in_bytes
);
4340 CEIL_ROUND (offset_ptr
->constant
, boundary_in_bytes
);
4346 pad_below (offset_ptr
, passed_mode
, sizetree
)
4347 struct args_size
*offset_ptr
;
4348 enum machine_mode passed_mode
;
4351 if (passed_mode
!= BLKmode
)
4353 if (GET_MODE_BITSIZE (passed_mode
) % PARM_BOUNDARY
)
4354 offset_ptr
->constant
4355 += (((GET_MODE_BITSIZE (passed_mode
) + PARM_BOUNDARY
- 1)
4356 / PARM_BOUNDARY
* PARM_BOUNDARY
/ BITS_PER_UNIT
)
4357 - GET_MODE_SIZE (passed_mode
));
4361 if (TREE_CODE (sizetree
) != INTEGER_CST
4362 || (TREE_INT_CST_LOW (sizetree
) * BITS_PER_UNIT
) % PARM_BOUNDARY
)
4364 /* Round the size up to multiple of PARM_BOUNDARY bits. */
4365 tree s2
= round_up (sizetree
, PARM_BOUNDARY
/ BITS_PER_UNIT
);
4367 ADD_PARM_SIZE (*offset_ptr
, s2
);
4368 SUB_PARM_SIZE (*offset_ptr
, sizetree
);
4374 round_down (value
, divisor
)
4378 return size_binop (MULT_EXPR
,
4379 size_binop (FLOOR_DIV_EXPR
, value
, size_int (divisor
)),
4380 size_int (divisor
));
4383 /* Walk the tree of blocks describing the binding levels within a function
4384 and warn about uninitialized variables.
4385 This is done after calling flow_analysis and before global_alloc
4386 clobbers the pseudo-regs to hard regs. */
4389 uninitialized_vars_warning (block
)
4392 register tree decl
, sub
;
4393 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
4395 if (TREE_CODE (decl
) == VAR_DECL
4396 /* These warnings are unreliable for and aggregates
4397 because assigning the fields one by one can fail to convince
4398 flow.c that the entire aggregate was initialized.
4399 Unions are troublesome because members may be shorter. */
4400 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl
))
4401 && DECL_RTL (decl
) != 0
4402 && GET_CODE (DECL_RTL (decl
)) == REG
4403 && regno_uninitialized (REGNO (DECL_RTL (decl
))))
4404 warning_with_decl (decl
,
4405 "`%s' might be used uninitialized in this function");
4406 if (TREE_CODE (decl
) == VAR_DECL
4407 && DECL_RTL (decl
) != 0
4408 && GET_CODE (DECL_RTL (decl
)) == REG
4409 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl
))))
4410 warning_with_decl (decl
,
4411 "variable `%s' might be clobbered by `longjmp' or `vfork'");
4413 for (sub
= BLOCK_SUBBLOCKS (block
); sub
; sub
= TREE_CHAIN (sub
))
4414 uninitialized_vars_warning (sub
);
4417 /* Do the appropriate part of uninitialized_vars_warning
4418 but for arguments instead of local variables. */
4421 setjmp_args_warning ()
4424 for (decl
= DECL_ARGUMENTS (current_function_decl
);
4425 decl
; decl
= TREE_CHAIN (decl
))
4426 if (DECL_RTL (decl
) != 0
4427 && GET_CODE (DECL_RTL (decl
)) == REG
4428 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl
))))
4429 warning_with_decl (decl
, "argument `%s' might be clobbered by `longjmp' or `vfork'");
4432 /* If this function call setjmp, put all vars into the stack
4433 unless they were declared `register'. */
4436 setjmp_protect (block
)
4439 register tree decl
, sub
;
4440 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
4441 if ((TREE_CODE (decl
) == VAR_DECL
4442 || TREE_CODE (decl
) == PARM_DECL
)
4443 && DECL_RTL (decl
) != 0
4444 && GET_CODE (DECL_RTL (decl
)) == REG
4445 /* If this variable came from an inline function, it must be
4446 that it's life doesn't overlap the setjmp. If there was a
4447 setjmp in the function, it would already be in memory. We
4448 must exclude such variable because their DECL_RTL might be
4449 set to strange things such as virtual_stack_vars_rtx. */
4450 && ! DECL_FROM_INLINE (decl
)
4452 #ifdef NON_SAVING_SETJMP
4453 /* If longjmp doesn't restore the registers,
4454 don't put anything in them. */
4458 ! DECL_REGISTER (decl
)))
4459 put_var_into_stack (decl
);
4460 for (sub
= BLOCK_SUBBLOCKS (block
); sub
; sub
= TREE_CHAIN (sub
))
4461 setjmp_protect (sub
);
4464 /* Like the previous function, but for args instead of local variables. */
4467 setjmp_protect_args ()
4469 register tree decl
, sub
;
4470 for (decl
= DECL_ARGUMENTS (current_function_decl
);
4471 decl
; decl
= TREE_CHAIN (decl
))
4472 if ((TREE_CODE (decl
) == VAR_DECL
4473 || TREE_CODE (decl
) == PARM_DECL
)
4474 && DECL_RTL (decl
) != 0
4475 && GET_CODE (DECL_RTL (decl
)) == REG
4477 /* If longjmp doesn't restore the registers,
4478 don't put anything in them. */
4479 #ifdef NON_SAVING_SETJMP
4483 ! DECL_REGISTER (decl
)))
4484 put_var_into_stack (decl
);
4487 /* Return the context-pointer register corresponding to DECL,
4488 or 0 if it does not need one. */
4491 lookup_static_chain (decl
)
4494 tree context
= decl_function_context (decl
);
4498 || (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_NO_STATIC_CHAIN (decl
)))
4501 /* We treat inline_function_decl as an alias for the current function
4502 because that is the inline function whose vars, types, etc.
4503 are being merged into the current function.
4504 See expand_inline_function. */
4505 if (context
== current_function_decl
|| context
== inline_function_decl
)
4506 return virtual_stack_vars_rtx
;
4508 for (link
= context_display
; link
; link
= TREE_CHAIN (link
))
4509 if (TREE_PURPOSE (link
) == context
)
4510 return RTL_EXPR_RTL (TREE_VALUE (link
));
4515 /* Convert a stack slot address ADDR for variable VAR
4516 (from a containing function)
4517 into an address valid in this function (using a static chain). */
4520 fix_lexical_addr (addr
, var
)
4526 tree context
= decl_function_context (var
);
4527 struct function
*fp
;
4530 /* If this is the present function, we need not do anything. */
4531 if (context
== current_function_decl
|| context
== inline_function_decl
)
4534 for (fp
= outer_function_chain
; fp
; fp
= fp
->next
)
4535 if (fp
->decl
== context
)
4541 /* Decode given address as base reg plus displacement. */
4542 if (GET_CODE (addr
) == REG
)
4543 basereg
= addr
, displacement
= 0;
4544 else if (GET_CODE (addr
) == PLUS
&& GET_CODE (XEXP (addr
, 1)) == CONST_INT
)
4545 basereg
= XEXP (addr
, 0), displacement
= INTVAL (XEXP (addr
, 1));
4549 /* We accept vars reached via the containing function's
4550 incoming arg pointer and via its stack variables pointer. */
4551 if (basereg
== fp
->internal_arg_pointer
)
4553 /* If reached via arg pointer, get the arg pointer value
4554 out of that function's stack frame.
4556 There are two cases: If a separate ap is needed, allocate a
4557 slot in the outer function for it and dereference it that way.
4558 This is correct even if the real ap is actually a pseudo.
4559 Otherwise, just adjust the offset from the frame pointer to
4562 #ifdef NEED_SEPARATE_AP
4565 if (fp
->arg_pointer_save_area
== 0)
4566 fp
->arg_pointer_save_area
4567 = assign_outer_stack_local (Pmode
, GET_MODE_SIZE (Pmode
), 0, fp
);
4569 addr
= fix_lexical_addr (XEXP (fp
->arg_pointer_save_area
, 0), var
);
4570 addr
= memory_address (Pmode
, addr
);
4572 base
= copy_to_reg (gen_rtx (MEM
, Pmode
, addr
));
4574 displacement
+= (FIRST_PARM_OFFSET (context
) - STARTING_FRAME_OFFSET
);
4575 base
= lookup_static_chain (var
);
4579 else if (basereg
== virtual_stack_vars_rtx
)
4581 /* This is the same code as lookup_static_chain, duplicated here to
4582 avoid an extra call to decl_function_context. */
4585 for (link
= context_display
; link
; link
= TREE_CHAIN (link
))
4586 if (TREE_PURPOSE (link
) == context
)
4588 base
= RTL_EXPR_RTL (TREE_VALUE (link
));
4596 /* Use same offset, relative to appropriate static chain or argument
4598 return plus_constant (base
, displacement
);
4601 /* Return the address of the trampoline for entering nested fn FUNCTION.
4602 If necessary, allocate a trampoline (in the stack frame)
4603 and emit rtl to initialize its contents (at entry to this function). */
4606 trampoline_address (function
)
4612 struct function
*fp
;
4615 /* Find an existing trampoline and return it. */
4616 for (link
= trampoline_list
; link
; link
= TREE_CHAIN (link
))
4617 if (TREE_PURPOSE (link
) == function
)
4619 round_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link
)), 0));
4621 for (fp
= outer_function_chain
; fp
; fp
= fp
->next
)
4622 for (link
= fp
->trampoline_list
; link
; link
= TREE_CHAIN (link
))
4623 if (TREE_PURPOSE (link
) == function
)
4625 tramp
= fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link
)), 0),
4627 return round_trampoline_addr (tramp
);
4630 /* None exists; we must make one. */
4632 /* Find the `struct function' for the function containing FUNCTION. */
4634 fn_context
= decl_function_context (function
);
4635 if (fn_context
!= current_function_decl
4636 && fn_context
!= inline_function_decl
)
4637 for (fp
= outer_function_chain
; fp
; fp
= fp
->next
)
4638 if (fp
->decl
== fn_context
)
4641 /* Allocate run-time space for this trampoline
4642 (usually in the defining function's stack frame). */
4643 #ifdef ALLOCATE_TRAMPOLINE
4644 tramp
= ALLOCATE_TRAMPOLINE (fp
);
4646 /* If rounding needed, allocate extra space
4647 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
4648 #ifdef TRAMPOLINE_ALIGNMENT
4649 #define TRAMPOLINE_REAL_SIZE \
4650 (TRAMPOLINE_SIZE + (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT) - 1)
4652 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
4655 tramp
= assign_outer_stack_local (BLKmode
, TRAMPOLINE_REAL_SIZE
, 0, fp
);
4657 tramp
= assign_stack_local (BLKmode
, TRAMPOLINE_REAL_SIZE
, 0);
4660 /* Record the trampoline for reuse and note it for later initialization
4661 by expand_function_end. */
4664 push_obstacks (fp
->function_maybepermanent_obstack
,
4665 fp
->function_maybepermanent_obstack
);
4666 rtlexp
= make_node (RTL_EXPR
);
4667 RTL_EXPR_RTL (rtlexp
) = tramp
;
4668 fp
->trampoline_list
= tree_cons (function
, rtlexp
, fp
->trampoline_list
);
4673 /* Make the RTL_EXPR node temporary, not momentary, so that the
4674 trampoline_list doesn't become garbage. */
4675 int momentary
= suspend_momentary ();
4676 rtlexp
= make_node (RTL_EXPR
);
4677 resume_momentary (momentary
);
4679 RTL_EXPR_RTL (rtlexp
) = tramp
;
4680 trampoline_list
= tree_cons (function
, rtlexp
, trampoline_list
);
4683 tramp
= fix_lexical_addr (XEXP (tramp
, 0), function
);
4684 return round_trampoline_addr (tramp
);
4687 /* Given a trampoline address,
4688 round it to multiple of TRAMPOLINE_ALIGNMENT. */
4691 round_trampoline_addr (tramp
)
4694 #ifdef TRAMPOLINE_ALIGNMENT
4695 /* Round address up to desired boundary. */
4696 rtx temp
= gen_reg_rtx (Pmode
);
4697 temp
= expand_binop (Pmode
, add_optab
, tramp
,
4698 GEN_INT (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
- 1),
4699 temp
, 0, OPTAB_LIB_WIDEN
);
4700 tramp
= expand_binop (Pmode
, and_optab
, temp
,
4701 GEN_INT (- TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
),
4702 temp
, 0, OPTAB_LIB_WIDEN
);
4707 /* The functions identify_blocks and reorder_blocks provide a way to
4708 reorder the tree of BLOCK nodes, for optimizers that reshuffle or
4709 duplicate portions of the RTL code. Call identify_blocks before
4710 changing the RTL, and call reorder_blocks after. */
4712 /* Put all this function's BLOCK nodes including those that are chained
4713 onto the first block into a vector, and return it.
4714 Also store in each NOTE for the beginning or end of a block
4715 the index of that block in the vector.
4716 The arguments are BLOCK, the chain of top-level blocks of the function,
4717 and INSNS, the insn chain of the function. */
4720 identify_blocks (block
, insns
)
4728 int next_block_number
= 1;
4729 int current_block_number
= 1;
4735 n_blocks
= all_blocks (block
, 0);
4736 block_vector
= (tree
*) xmalloc (n_blocks
* sizeof (tree
));
4737 block_stack
= (int *) alloca (n_blocks
* sizeof (int));
4739 all_blocks (block
, block_vector
);
4741 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
4742 if (GET_CODE (insn
) == NOTE
)
4744 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_BEG
)
4746 block_stack
[depth
++] = current_block_number
;
4747 current_block_number
= next_block_number
;
4748 NOTE_BLOCK_NUMBER (insn
) = next_block_number
++;
4750 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_END
)
4752 current_block_number
= block_stack
[--depth
];
4753 NOTE_BLOCK_NUMBER (insn
) = current_block_number
;
4757 if (n_blocks
!= next_block_number
)
4760 return block_vector
;
4763 /* Given BLOCK_VECTOR which was returned by identify_blocks,
4764 and a revised instruction chain, rebuild the tree structure
4765 of BLOCK nodes to correspond to the new order of RTL.
4766 The new block tree is inserted below TOP_BLOCK.
4767 Returns the current top-level block. */
4770 reorder_blocks (block_vector
, block
, insns
)
4775 tree current_block
= block
;
4778 if (block_vector
== 0)
4781 /* Prune the old trees away, so that it doesn't get in the way. */
4782 BLOCK_SUBBLOCKS (current_block
) = 0;
4783 BLOCK_CHAIN (current_block
) = 0;
4785 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
4786 if (GET_CODE (insn
) == NOTE
)
4788 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_BEG
)
4790 tree block
= block_vector
[NOTE_BLOCK_NUMBER (insn
)];
4791 /* If we have seen this block before, copy it. */
4792 if (TREE_ASM_WRITTEN (block
))
4793 block
= copy_node (block
);
4794 BLOCK_SUBBLOCKS (block
) = 0;
4795 TREE_ASM_WRITTEN (block
) = 1;
4796 BLOCK_SUPERCONTEXT (block
) = current_block
;
4797 BLOCK_CHAIN (block
) = BLOCK_SUBBLOCKS (current_block
);
4798 BLOCK_SUBBLOCKS (current_block
) = block
;
4799 current_block
= block
;
4800 NOTE_SOURCE_FILE (insn
) = 0;
4802 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_END
)
4804 BLOCK_SUBBLOCKS (current_block
)
4805 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block
));
4806 current_block
= BLOCK_SUPERCONTEXT (current_block
);
4807 NOTE_SOURCE_FILE (insn
) = 0;
4811 BLOCK_SUBBLOCKS (current_block
)
4812 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block
));
4813 return current_block
;
4816 /* Reverse the order of elements in the chain T of blocks,
4817 and return the new head of the chain (old last element). */
4823 register tree prev
= 0, decl
, next
;
4824 for (decl
= t
; decl
; decl
= next
)
4826 next
= BLOCK_CHAIN (decl
);
4827 BLOCK_CHAIN (decl
) = prev
;
4833 /* Count the subblocks of the list starting with BLOCK, and list them
4834 all into the vector VECTOR. Also clear TREE_ASM_WRITTEN in all
4838 all_blocks (block
, vector
)
4846 TREE_ASM_WRITTEN (block
) = 0;
4848 /* Record this block. */
4850 vector
[n_blocks
] = block
;
4854 /* Record the subblocks, and their subblocks... */
4855 n_blocks
+= all_blocks (BLOCK_SUBBLOCKS (block
),
4856 vector
? vector
+ n_blocks
: 0);
4857 block
= BLOCK_CHAIN (block
);
4863 /* Build bytecode call descriptor for function SUBR. */
4866 bc_build_calldesc (subr
)
4869 tree calldesc
= 0, arg
;
4872 /* Build the argument description vector in reverse order. */
4873 DECL_ARGUMENTS (subr
) = nreverse (DECL_ARGUMENTS (subr
));
4876 for (arg
= DECL_ARGUMENTS (subr
); arg
; arg
= TREE_CHAIN (arg
))
4880 calldesc
= tree_cons ((tree
) 0, size_in_bytes (TREE_TYPE (arg
)), calldesc
);
4881 calldesc
= tree_cons ((tree
) 0, bc_runtime_type_code (TREE_TYPE (arg
)), calldesc
);
4884 DECL_ARGUMENTS (subr
) = nreverse (DECL_ARGUMENTS (subr
));
4886 /* Prepend the function's return type. */
4887 calldesc
= tree_cons ((tree
) 0,
4888 size_in_bytes (TREE_TYPE (TREE_TYPE (subr
))),
4891 calldesc
= tree_cons ((tree
) 0,
4892 bc_runtime_type_code (TREE_TYPE (TREE_TYPE (subr
))),
4895 /* Prepend the arg count. */
4896 calldesc
= tree_cons ((tree
) 0, build_int_2 (nargs
, 0), calldesc
);
4898 /* Output the call description vector and get its address. */
4899 calldesc
= build_nt (CONSTRUCTOR
, (tree
) 0, calldesc
);
4900 TREE_TYPE (calldesc
) = build_array_type (integer_type_node
,
4901 build_index_type (build_int_2 (nargs
* 2, 0)));
4903 return output_constant_def (calldesc
);
4907 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
4908 and initialize static variables for generating RTL for the statements
4912 init_function_start (subr
, filename
, line
)
4917 if (output_bytecode
)
4919 this_function_decl
= subr
;
4920 this_function_calldesc
= bc_build_calldesc (subr
);
4921 local_vars_size
= 0;
4923 max_stack_depth
= 0;
4924 stmt_expr_depth
= 0;
4928 init_stmt_for_function ();
4930 cse_not_expected
= ! optimize
;
4932 /* Caller save not needed yet. */
4933 caller_save_needed
= 0;
4935 /* No stack slots have been made yet. */
4936 stack_slot_list
= 0;
4938 /* There is no stack slot for handling nonlocal gotos. */
4939 nonlocal_goto_handler_slot
= 0;
4940 nonlocal_goto_stack_level
= 0;
4942 /* No labels have been declared for nonlocal use. */
4943 nonlocal_labels
= 0;
4945 /* No function calls so far in this function. */
4946 function_call_count
= 0;
4948 /* No parm regs have been allocated.
4949 (This is important for output_inline_function.) */
4950 max_parm_reg
= LAST_VIRTUAL_REGISTER
+ 1;
4952 /* Initialize the RTL mechanism. */
4955 /* Initialize the queue of pending postincrement and postdecrements,
4956 and some other info in expr.c. */
4959 /* We haven't done register allocation yet. */
4962 init_const_rtx_hash_table ();
4964 current_function_name
= (*decl_printable_name
) (subr
, 2);
4966 /* Nonzero if this is a nested function that uses a static chain. */
4968 current_function_needs_context
4969 = (decl_function_context (current_function_decl
) != 0
4970 && ! DECL_NO_STATIC_CHAIN (current_function_decl
));
4972 /* Set if a call to setjmp is seen. */
4973 current_function_calls_setjmp
= 0;
4975 /* Set if a call to longjmp is seen. */
4976 current_function_calls_longjmp
= 0;
4978 current_function_calls_alloca
= 0;
4979 current_function_has_nonlocal_label
= 0;
4980 current_function_has_nonlocal_goto
= 0;
4981 current_function_contains_functions
= 0;
4982 current_function_is_thunk
= 0;
4984 current_function_returns_pcc_struct
= 0;
4985 current_function_returns_struct
= 0;
4986 current_function_epilogue_delay_list
= 0;
4987 current_function_uses_const_pool
= 0;
4988 current_function_uses_pic_offset_table
= 0;
4990 /* We have not yet needed to make a label to jump to for tail-recursion. */
4991 tail_recursion_label
= 0;
4993 /* We haven't had a need to make a save area for ap yet. */
4995 arg_pointer_save_area
= 0;
4997 /* No stack slots allocated yet. */
5000 /* No SAVE_EXPRs in this function yet. */
5003 /* No RTL_EXPRs in this function yet. */
5006 /* Set up to allocate temporaries. */
5009 /* Within function body, compute a type's size as soon it is laid out. */
5010 immediate_size_expand
++;
5012 /* We haven't made any trampolines for this function yet. */
5013 trampoline_list
= 0;
5015 init_pending_stack_adjust ();
5016 inhibit_defer_pop
= 0;
5018 current_function_outgoing_args_size
= 0;
5020 /* Prevent ever trying to delete the first instruction of a function.
5021 Also tell final how to output a linenum before the function prologue. */
5022 emit_line_note (filename
, line
);
5024 /* Make sure first insn is a note even if we don't want linenums.
5025 This makes sure the first insn will never be deleted.
5026 Also, final expects a note to appear there. */
5027 emit_note (NULL_PTR
, NOTE_INSN_DELETED
);
5029 /* Set flags used by final.c. */
5030 if (aggregate_value_p (DECL_RESULT (subr
)))
5032 #ifdef PCC_STATIC_STRUCT_RETURN
5033 current_function_returns_pcc_struct
= 1;
5035 current_function_returns_struct
= 1;
5038 /* Warn if this value is an aggregate type,
5039 regardless of which calling convention we are using for it. */
5040 if (warn_aggregate_return
5041 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr
))))
5042 warning ("function returns an aggregate");
5044 current_function_returns_pointer
5045 = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr
)));
5047 /* Indicate that we need to distinguish between the return value of the
5048 present function and the return value of a function being called. */
5049 rtx_equal_function_value_matters
= 1;
5051 /* Indicate that we have not instantiated virtual registers yet. */
5052 virtuals_instantiated
= 0;
5054 /* Indicate we have no need of a frame pointer yet. */
5055 frame_pointer_needed
= 0;
5057 /* By default assume not varargs or stdarg. */
5058 current_function_varargs
= 0;
5059 current_function_stdarg
= 0;
5062 /* Indicate that the current function uses extra args
5063 not explicitly mentioned in the argument list in any fashion. */
5068 current_function_varargs
= 1;
5071 /* Expand a call to __main at the beginning of a possible main function. */
5073 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
5074 #undef HAS_INIT_SECTION
5075 #define HAS_INIT_SECTION
5079 expand_main_function ()
5081 if (!output_bytecode
)
5083 /* The zero below avoids a possible parse error */
5085 #if !defined (HAS_INIT_SECTION)
5086 emit_library_call (gen_rtx (SYMBOL_REF
, Pmode
, NAME__MAIN
), 0,
5088 #endif /* not HAS_INIT_SECTION */
5092 extern struct obstack permanent_obstack
;
5094 /* Expand start of bytecode function. See comment at
5095 expand_function_start below for details. */
5098 bc_expand_function_start (subr
, parms_have_cleanups
)
5100 int parms_have_cleanups
;
5102 char label
[20], *name
;
5107 if (TREE_PUBLIC (subr
))
5108 bc_globalize_label (IDENTIFIER_POINTER (DECL_NAME (subr
)));
5110 #ifdef DEBUG_PRINT_CODE
5111 fprintf (stderr
, "\n<func %s>\n", IDENTIFIER_POINTER (DECL_NAME (subr
)));
5114 for (argsz
= 0, thisarg
= DECL_ARGUMENTS (subr
); thisarg
; thisarg
= TREE_CHAIN (thisarg
))
5116 if (DECL_RTL (thisarg
))
5117 abort (); /* Should be NULL here I think. */
5118 else if (TREE_CONSTANT (DECL_SIZE (thisarg
)))
5120 DECL_RTL (thisarg
) = bc_gen_rtx ((char *) 0, argsz
, (struct bc_label
*) 0);
5121 argsz
+= TREE_INT_CST_LOW (DECL_SIZE (thisarg
));
5125 /* Variable-sized objects are pointers to their storage. */
5126 DECL_RTL (thisarg
) = bc_gen_rtx ((char *) 0, argsz
, (struct bc_label
*) 0);
5127 argsz
+= POINTER_SIZE
;
5131 bc_begin_function (xstrdup (IDENTIFIER_POINTER (DECL_NAME (subr
))));
5133 ASM_GENERATE_INTERNAL_LABEL (label
, "LX", nlab
);
5136 name
= (char *) obstack_copy0 (&permanent_obstack
, label
, strlen (label
));
5137 this_function_callinfo
= bc_gen_rtx (name
, 0, (struct bc_label
*) 0);
5138 this_function_bytecode
5139 = bc_emit_trampoline (BYTECODE_LABEL (this_function_callinfo
));
5143 /* Expand end of bytecode function. See details the comment of
5144 expand_function_end(), below. */
5147 bc_expand_function_end ()
5151 expand_null_return ();
5153 /* Emit any fixup code. This must be done before the call to
5154 to BC_END_FUNCTION (), since that will cause the bytecode
5155 segment to be finished off and closed. */
5157 expand_fixups (NULL_RTX
);
5159 ptrconsts
= bc_end_function ();
5161 bc_align_const (2 /* INT_ALIGN */);
5163 /* If this changes also make sure to change bc-interp.h! */
5165 bc_emit_const_labeldef (BYTECODE_LABEL (this_function_callinfo
));
5166 bc_emit_const ((char *) &max_stack_depth
, sizeof max_stack_depth
);
5167 bc_emit_const ((char *) &local_vars_size
, sizeof local_vars_size
);
5168 bc_emit_const_labelref (this_function_bytecode
, 0);
5169 bc_emit_const_labelref (ptrconsts
, 0);
5170 bc_emit_const_labelref (BYTECODE_LABEL (this_function_calldesc
), 0);
5174 /* Start the RTL for a new function, and set variables used for
5176 SUBR is the FUNCTION_DECL node.
5177 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
5178 the function's parameters, which must be run at any return statement. */
5181 expand_function_start (subr
, parms_have_cleanups
)
5183 int parms_have_cleanups
;
5189 if (output_bytecode
)
5191 bc_expand_function_start (subr
, parms_have_cleanups
);
5195 /* Make sure volatile mem refs aren't considered
5196 valid operands of arithmetic insns. */
5197 init_recog_no_volatile ();
5199 /* If function gets a static chain arg, store it in the stack frame.
5200 Do this first, so it gets the first stack slot offset. */
5201 if (current_function_needs_context
)
5203 last_ptr
= assign_stack_local (Pmode
, GET_MODE_SIZE (Pmode
), 0);
5205 #ifdef SMALL_REGISTER_CLASSES
5206 /* Delay copying static chain if it is not a register to avoid
5207 conflicts with regs used for parameters. */
5208 if (! SMALL_REGISTER_CLASSES
5209 || GET_CODE (static_chain_incoming_rtx
) == REG
)
5211 emit_move_insn (last_ptr
, static_chain_incoming_rtx
);
5214 /* If the parameters of this function need cleaning up, get a label
5215 for the beginning of the code which executes those cleanups. This must
5216 be done before doing anything with return_label. */
5217 if (parms_have_cleanups
)
5218 cleanup_label
= gen_label_rtx ();
5222 /* Make the label for return statements to jump to, if this machine
5223 does not have a one-instruction return and uses an epilogue,
5224 or if it returns a structure, or if it has parm cleanups. */
5226 if (cleanup_label
== 0 && HAVE_return
5227 && ! current_function_returns_pcc_struct
5228 && ! (current_function_returns_struct
&& ! optimize
))
5231 return_label
= gen_label_rtx ();
5233 return_label
= gen_label_rtx ();
5236 /* Initialize rtx used to return the value. */
5237 /* Do this before assign_parms so that we copy the struct value address
5238 before any library calls that assign parms might generate. */
5240 /* Decide whether to return the value in memory or in a register. */
5241 if (aggregate_value_p (DECL_RESULT (subr
)))
5243 /* Returning something that won't go in a register. */
5244 register rtx value_address
= 0;
5246 #ifdef PCC_STATIC_STRUCT_RETURN
5247 if (current_function_returns_pcc_struct
)
5249 int size
= int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr
)));
5250 value_address
= assemble_static_space (size
);
5255 /* Expect to be passed the address of a place to store the value.
5256 If it is passed as an argument, assign_parms will take care of
5258 if (struct_value_incoming_rtx
)
5260 value_address
= gen_reg_rtx (Pmode
);
5261 emit_move_insn (value_address
, struct_value_incoming_rtx
);
5266 DECL_RTL (DECL_RESULT (subr
))
5267 = gen_rtx (MEM
, DECL_MODE (DECL_RESULT (subr
)), value_address
);
5268 MEM_IN_STRUCT_P (DECL_RTL (DECL_RESULT (subr
)))
5269 = AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr
)));
5272 else if (DECL_MODE (DECL_RESULT (subr
)) == VOIDmode
)
5273 /* If return mode is void, this decl rtl should not be used. */
5274 DECL_RTL (DECL_RESULT (subr
)) = 0;
5275 else if (parms_have_cleanups
)
5277 /* If function will end with cleanup code for parms,
5278 compute the return values into a pseudo reg,
5279 which we will copy into the true return register
5280 after the cleanups are done. */
5282 enum machine_mode mode
= DECL_MODE (DECL_RESULT (subr
));
5284 #ifdef PROMOTE_FUNCTION_RETURN
5285 tree type
= TREE_TYPE (DECL_RESULT (subr
));
5286 int unsignedp
= TREE_UNSIGNED (type
);
5288 mode
= promote_mode (type
, mode
, &unsignedp
, 1);
5291 DECL_RTL (DECL_RESULT (subr
)) = gen_reg_rtx (mode
);
5294 /* Scalar, returned in a register. */
5296 #ifdef FUNCTION_OUTGOING_VALUE
5297 DECL_RTL (DECL_RESULT (subr
))
5298 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr
)), subr
);
5300 DECL_RTL (DECL_RESULT (subr
))
5301 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr
)), subr
);
5304 /* Mark this reg as the function's return value. */
5305 if (GET_CODE (DECL_RTL (DECL_RESULT (subr
))) == REG
)
5307 REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr
))) = 1;
5308 /* Needed because we may need to move this to memory
5309 in case it's a named return value whose address is taken. */
5310 DECL_REGISTER (DECL_RESULT (subr
)) = 1;
5314 /* Initialize rtx for parameters and local variables.
5315 In some cases this requires emitting insns. */
5317 assign_parms (subr
, 0);
5319 #ifdef SMALL_REGISTER_CLASSES
5320 /* Copy the static chain now if it wasn't a register. The delay is to
5321 avoid conflicts with the parameter passing registers. */
5323 if (SMALL_REGISTER_CLASSES
&& current_function_needs_context
)
5324 if (GET_CODE (static_chain_incoming_rtx
) != REG
)
5325 emit_move_insn (last_ptr
, static_chain_incoming_rtx
);
5328 /* The following was moved from init_function_start.
5329 The move is supposed to make sdb output more accurate. */
5330 /* Indicate the beginning of the function body,
5331 as opposed to parm setup. */
5332 emit_note (NULL_PTR
, NOTE_INSN_FUNCTION_BEG
);
5334 /* If doing stupid allocation, mark parms as born here. */
5336 if (GET_CODE (get_last_insn ()) != NOTE
)
5337 emit_note (NULL_PTR
, NOTE_INSN_DELETED
);
5338 parm_birth_insn
= get_last_insn ();
5342 for (i
= LAST_VIRTUAL_REGISTER
+ 1; i
< max_parm_reg
; i
++)
5343 use_variable (regno_reg_rtx
[i
]);
5345 if (current_function_internal_arg_pointer
!= virtual_incoming_args_rtx
)
5346 use_variable (current_function_internal_arg_pointer
);
5349 context_display
= 0;
5350 if (current_function_needs_context
)
5352 /* Fetch static chain values for containing functions. */
5353 tem
= decl_function_context (current_function_decl
);
5354 /* If not doing stupid register allocation copy the static chain
5355 pointer into a pseudo. If we have small register classes, copy
5356 the value from memory if static_chain_incoming_rtx is a REG. If
5357 we do stupid register allocation, we use the stack address
5359 if (tem
&& ! obey_regdecls
)
5361 #ifdef SMALL_REGISTER_CLASSES
5362 /* If the static chain originally came in a register, put it back
5363 there, then move it out in the next insn. The reason for
5364 this peculiar code is to satisfy function integration. */
5365 if (SMALL_REGISTER_CLASSES
5366 && GET_CODE (static_chain_incoming_rtx
) == REG
)
5367 emit_move_insn (static_chain_incoming_rtx
, last_ptr
);
5370 last_ptr
= copy_to_reg (static_chain_incoming_rtx
);
5375 tree rtlexp
= make_node (RTL_EXPR
);
5377 RTL_EXPR_RTL (rtlexp
) = last_ptr
;
5378 context_display
= tree_cons (tem
, rtlexp
, context_display
);
5379 tem
= decl_function_context (tem
);
5382 /* Chain thru stack frames, assuming pointer to next lexical frame
5383 is found at the place we always store it. */
5384 #ifdef FRAME_GROWS_DOWNWARD
5385 last_ptr
= plus_constant (last_ptr
, - GET_MODE_SIZE (Pmode
));
5387 last_ptr
= copy_to_reg (gen_rtx (MEM
, Pmode
,
5388 memory_address (Pmode
, last_ptr
)));
5390 /* If we are not optimizing, ensure that we know that this
5391 piece of context is live over the entire function. */
5393 save_expr_regs
= gen_rtx (EXPR_LIST
, VOIDmode
, last_ptr
,
5398 /* After the display initializations is where the tail-recursion label
5399 should go, if we end up needing one. Ensure we have a NOTE here
5400 since some things (like trampolines) get placed before this. */
5401 tail_recursion_reentry
= emit_note (NULL_PTR
, NOTE_INSN_DELETED
);
5403 /* Evaluate now the sizes of any types declared among the arguments. */
5404 for (tem
= nreverse (get_pending_sizes ()); tem
; tem
= TREE_CHAIN (tem
))
5406 expand_expr (TREE_VALUE (tem
), const0_rtx
, VOIDmode
, 0);
5407 /* Flush the queue in case this parameter declaration has
5412 /* Make sure there is a line number after the function entry setup code. */
5413 force_next_line_note ();
5416 /* Generate RTL for the end of the current function.
5417 FILENAME and LINE are the current position in the source file.
5419 It is up to language-specific callers to do cleanups for parameters--
5420 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */
5423 expand_function_end (filename
, line
, end_bindings
)
5431 #ifdef TRAMPOLINE_TEMPLATE
5432 static rtx initial_trampoline
;
5435 if (output_bytecode
)
5437 bc_expand_function_end ();
5441 #ifdef NON_SAVING_SETJMP
5442 /* Don't put any variables in registers if we call setjmp
5443 on a machine that fails to restore the registers. */
5444 if (NON_SAVING_SETJMP
&& current_function_calls_setjmp
)
5446 if (DECL_INITIAL (current_function_decl
) != error_mark_node
)
5447 setjmp_protect (DECL_INITIAL (current_function_decl
));
5449 setjmp_protect_args ();
5453 /* Save the argument pointer if a save area was made for it. */
5454 if (arg_pointer_save_area
)
5456 rtx x
= gen_move_insn (arg_pointer_save_area
, virtual_incoming_args_rtx
);
5457 emit_insn_before (x
, tail_recursion_reentry
);
5460 /* Initialize any trampolines required by this function. */
5461 for (link
= trampoline_list
; link
; link
= TREE_CHAIN (link
))
5463 tree function
= TREE_PURPOSE (link
);
5464 rtx context
= lookup_static_chain (function
);
5465 rtx tramp
= RTL_EXPR_RTL (TREE_VALUE (link
));
5469 #ifdef TRAMPOLINE_TEMPLATE
5470 /* First make sure this compilation has a template for
5471 initializing trampolines. */
5472 if (initial_trampoline
== 0)
5474 end_temporary_allocation ();
5476 = gen_rtx (MEM
, BLKmode
, assemble_trampoline_template ());
5477 resume_temporary_allocation ();
5481 /* Generate insns to initialize the trampoline. */
5483 tramp
= round_trampoline_addr (XEXP (tramp
, 0));
5484 #ifdef TRAMPOLINE_TEMPLATE
5485 blktramp
= change_address (initial_trampoline
, BLKmode
, tramp
);
5486 emit_block_move (blktramp
, initial_trampoline
,
5487 GEN_INT (TRAMPOLINE_SIZE
),
5488 TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
5490 INITIALIZE_TRAMPOLINE (tramp
, XEXP (DECL_RTL (function
), 0), context
);
5494 /* Put those insns at entry to the containing function (this one). */
5495 emit_insns_before (seq
, tail_recursion_reentry
);
5498 /* If we are doing stack checking and this function makes calls,
5499 do a stack probe at the start of the function to ensure we have enough
5500 space for another stack frame. */
5501 if (flag_stack_check
&& ! STACK_CHECK_BUILTIN
)
5505 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5506 if (GET_CODE (insn
) == CALL_INSN
)
5509 probe_stack_range (STACK_CHECK_PROTECT
,
5510 GEN_INT (STACK_CHECK_MAX_FRAME_SIZE
));
5513 emit_insns_before (seq
, tail_recursion_reentry
);
5518 /* Warn about unused parms if extra warnings were specified. */
5519 if (warn_unused
&& extra_warnings
)
5523 for (decl
= DECL_ARGUMENTS (current_function_decl
);
5524 decl
; decl
= TREE_CHAIN (decl
))
5525 if (! TREE_USED (decl
) && TREE_CODE (decl
) == PARM_DECL
5526 && DECL_NAME (decl
) && ! DECL_ARTIFICIAL (decl
))
5527 warning_with_decl (decl
, "unused parameter `%s'");
5530 /* Delete handlers for nonlocal gotos if nothing uses them. */
5531 if (nonlocal_goto_handler_slot
!= 0 && !current_function_has_nonlocal_label
)
5534 /* End any sequences that failed to be closed due to syntax errors. */
5535 while (in_sequence_p ())
5538 /* Outside function body, can't compute type's actual size
5539 until next function's body starts. */
5540 immediate_size_expand
--;
5542 /* If doing stupid register allocation,
5543 mark register parms as dying here. */
5548 for (i
= LAST_VIRTUAL_REGISTER
+ 1; i
< max_parm_reg
; i
++)
5549 use_variable (regno_reg_rtx
[i
]);
5551 /* Likewise for the regs of all the SAVE_EXPRs in the function. */
5553 for (tem
= save_expr_regs
; tem
; tem
= XEXP (tem
, 1))
5555 use_variable (XEXP (tem
, 0));
5556 use_variable_after (XEXP (tem
, 0), parm_birth_insn
);
5559 if (current_function_internal_arg_pointer
!= virtual_incoming_args_rtx
)
5560 use_variable (current_function_internal_arg_pointer
);
5563 clear_pending_stack_adjust ();
5564 do_pending_stack_adjust ();
5566 /* Mark the end of the function body.
5567 If control reaches this insn, the function can drop through
5568 without returning a value. */
5569 emit_note (NULL_PTR
, NOTE_INSN_FUNCTION_END
);
5571 /* Must mark the last line number note in the function, so that the test
5572 coverage code can avoid counting the last line twice. This just tells
5573 the code to ignore the immediately following line note, since there
5574 already exists a copy of this note somewhere above. This line number
5575 note is still needed for debugging though, so we can't delete it. */
5576 if (flag_test_coverage
)
5577 emit_note (NULL_PTR
, NOTE_REPEATED_LINE_NUMBER
);
5579 /* Output a linenumber for the end of the function.
5580 SDB depends on this. */
5581 emit_line_note_force (filename
, line
);
5583 /* Output the label for the actual return from the function,
5584 if one is expected. This happens either because a function epilogue
5585 is used instead of a return instruction, or because a return was done
5586 with a goto in order to run local cleanups, or because of pcc-style
5587 structure returning. */
5590 emit_label (return_label
);
5592 /* C++ uses this. */
5594 expand_end_bindings (0, 0, 0);
5596 /* Now handle any leftover exception regions that may have been
5597 created for the parameters. */
5599 rtx last
= get_last_insn ();
5602 expand_leftover_cleanups ();
5604 /* If the above emitted any code, may sure we jump around it. */
5605 if (last
!= get_last_insn ())
5607 label
= gen_label_rtx ();
5608 last
= emit_jump_insn_after (gen_jump (label
), last
);
5609 last
= emit_barrier_after (last
);
5614 /* If we had calls to alloca, and this machine needs
5615 an accurate stack pointer to exit the function,
5616 insert some code to save and restore the stack pointer. */
5617 #ifdef EXIT_IGNORE_STACK
5618 if (! EXIT_IGNORE_STACK
)
5620 if (current_function_calls_alloca
)
5624 emit_stack_save (SAVE_FUNCTION
, &tem
, parm_birth_insn
);
5625 emit_stack_restore (SAVE_FUNCTION
, tem
, NULL_RTX
);
5628 /* If scalar return value was computed in a pseudo-reg,
5629 copy that to the hard return register. */
5630 if (DECL_RTL (DECL_RESULT (current_function_decl
)) != 0
5631 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl
))) == REG
5632 && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl
)))
5633 >= FIRST_PSEUDO_REGISTER
))
5635 rtx real_decl_result
;
5637 #ifdef FUNCTION_OUTGOING_VALUE
5639 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl
)),
5640 current_function_decl
);
5643 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl
)),
5644 current_function_decl
);
5646 REG_FUNCTION_VALUE_P (real_decl_result
) = 1;
5647 /* If this is a BLKmode structure being returned in registers, then use
5648 the mode computed in expand_return. */
5649 if (GET_MODE (real_decl_result
) == BLKmode
)
5650 PUT_MODE (real_decl_result
,
5651 GET_MODE (DECL_RTL (DECL_RESULT (current_function_decl
))));
5652 emit_move_insn (real_decl_result
,
5653 DECL_RTL (DECL_RESULT (current_function_decl
)));
5654 emit_insn (gen_rtx (USE
, VOIDmode
, real_decl_result
));
5657 /* If returning a structure, arrange to return the address of the value
5658 in a place where debuggers expect to find it.
5660 If returning a structure PCC style,
5661 the caller also depends on this value.
5662 And current_function_returns_pcc_struct is not necessarily set. */
5663 if (current_function_returns_struct
5664 || current_function_returns_pcc_struct
)
5666 rtx value_address
= XEXP (DECL_RTL (DECL_RESULT (current_function_decl
)), 0);
5667 tree type
= TREE_TYPE (DECL_RESULT (current_function_decl
));
5668 #ifdef FUNCTION_OUTGOING_VALUE
5670 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type
),
5671 current_function_decl
);
5674 = FUNCTION_VALUE (build_pointer_type (type
),
5675 current_function_decl
);
5678 /* Mark this as a function return value so integrate will delete the
5679 assignment and USE below when inlining this function. */
5680 REG_FUNCTION_VALUE_P (outgoing
) = 1;
5682 emit_move_insn (outgoing
, value_address
);
5683 use_variable (outgoing
);
5686 /* Output a return insn if we are using one.
5687 Otherwise, let the rtl chain end here, to drop through
5688 into the epilogue. */
5693 emit_jump_insn (gen_return ());
5698 /* Fix up any gotos that jumped out to the outermost
5699 binding level of the function.
5700 Must follow emitting RETURN_LABEL. */
5702 /* If you have any cleanups to do at this point,
5703 and they need to create temporary variables,
5704 then you will lose. */
5705 expand_fixups (get_insns ());
5708 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
5710 static int *prologue
;
5711 static int *epilogue
;
5713 /* Create an array that records the INSN_UIDs of INSNS (either a sequence
5714 or a single insn). */
5717 record_insns (insns
)
5722 if (GET_CODE (insns
) == SEQUENCE
)
5724 int len
= XVECLEN (insns
, 0);
5725 vec
= (int *) oballoc ((len
+ 1) * sizeof (int));
5728 vec
[len
] = INSN_UID (XVECEXP (insns
, 0, len
));
5732 vec
= (int *) oballoc (2 * sizeof (int));
5733 vec
[0] = INSN_UID (insns
);
5739 /* Determine how many INSN_UIDs in VEC are part of INSN. */
5742 contains (insn
, vec
)
5748 if (GET_CODE (insn
) == INSN
5749 && GET_CODE (PATTERN (insn
)) == SEQUENCE
)
5752 for (i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
5753 for (j
= 0; vec
[j
]; j
++)
5754 if (INSN_UID (XVECEXP (PATTERN (insn
), 0, i
)) == vec
[j
])
5760 for (j
= 0; vec
[j
]; j
++)
5761 if (INSN_UID (insn
) == vec
[j
])
5767 /* Generate the prologue and epilogue RTL if the machine supports it. Thread
5768 this into place with notes indicating where the prologue ends and where
5769 the epilogue begins. Update the basic block information when possible. */
5772 thread_prologue_and_epilogue_insns (f
)
5775 #ifdef HAVE_prologue
5778 rtx head
, seq
, insn
;
5780 /* The first insn (a NOTE_INSN_DELETED) is followed by zero or more
5781 prologue insns and a NOTE_INSN_PROLOGUE_END. */
5782 emit_note_after (NOTE_INSN_PROLOGUE_END
, f
);
5783 seq
= gen_prologue ();
5784 head
= emit_insn_after (seq
, f
);
5786 /* Include the new prologue insns in the first block. Ignore them
5787 if they form a basic block unto themselves. */
5788 if (basic_block_head
&& n_basic_blocks
5789 && GET_CODE (basic_block_head
[0]) != CODE_LABEL
)
5790 basic_block_head
[0] = NEXT_INSN (f
);
5792 /* Retain a map of the prologue insns. */
5793 prologue
= record_insns (GET_CODE (seq
) == SEQUENCE
? seq
: head
);
5799 #ifdef HAVE_epilogue
5802 rtx insn
= get_last_insn ();
5803 rtx prev
= prev_nonnote_insn (insn
);
5805 /* If we end with a BARRIER, we don't need an epilogue. */
5806 if (! (prev
&& GET_CODE (prev
) == BARRIER
))
5812 /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG, the
5813 epilogue insns, the USE insns at the end of a function,
5814 the jump insn that returns, and then a BARRIER. */
5816 /* Move the USE insns at the end of a function onto a list. */
5818 && GET_CODE (prev
) == INSN
5819 && GET_CODE (PATTERN (prev
)) == USE
)
5822 prev
= prev_nonnote_insn (prev
);
5824 NEXT_INSN (PREV_INSN (tem
)) = NEXT_INSN (tem
);
5825 PREV_INSN (NEXT_INSN (tem
)) = PREV_INSN (tem
);
5828 NEXT_INSN (tem
) = first_use
;
5829 PREV_INSN (first_use
) = tem
;
5836 emit_barrier_after (insn
);
5838 seq
= gen_epilogue ();
5839 tail
= emit_jump_insn_after (seq
, insn
);
5841 /* Insert the USE insns immediately before the return insn, which
5842 must be the first instruction before the final barrier. */
5845 tem
= prev_nonnote_insn (get_last_insn ());
5846 NEXT_INSN (PREV_INSN (tem
)) = first_use
;
5847 PREV_INSN (first_use
) = PREV_INSN (tem
);
5848 PREV_INSN (tem
) = last_use
;
5849 NEXT_INSN (last_use
) = tem
;
5852 emit_note_after (NOTE_INSN_EPILOGUE_BEG
, insn
);
5854 /* Include the new epilogue insns in the last block. Ignore
5855 them if they form a basic block unto themselves. */
5856 if (basic_block_end
&& n_basic_blocks
5857 && GET_CODE (basic_block_end
[n_basic_blocks
- 1]) != JUMP_INSN
)
5858 basic_block_end
[n_basic_blocks
- 1] = tail
;
5860 /* Retain a map of the epilogue insns. */
5861 epilogue
= record_insns (GET_CODE (seq
) == SEQUENCE
? seq
: tail
);
5869 /* Reposition the prologue-end and epilogue-begin notes after instruction
5870 scheduling and delayed branch scheduling. */
5873 reposition_prologue_and_epilogue_notes (f
)
5876 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
5877 /* Reposition the prologue and epilogue notes. */
5885 register rtx insn
, note
= 0;
5887 /* Scan from the beginning until we reach the last prologue insn.
5888 We apparently can't depend on basic_block_{head,end} after
5890 for (len
= 0; prologue
[len
]; len
++)
5892 for (insn
= f
; len
&& insn
; insn
= NEXT_INSN (insn
))
5894 if (GET_CODE (insn
) == NOTE
)
5896 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_PROLOGUE_END
)
5899 else if ((len
-= contains (insn
, prologue
)) == 0)
5901 /* Find the prologue-end note if we haven't already, and
5902 move it to just after the last prologue insn. */
5905 for (note
= insn
; note
= NEXT_INSN (note
);)
5906 if (GET_CODE (note
) == NOTE
5907 && NOTE_LINE_NUMBER (note
) == NOTE_INSN_PROLOGUE_END
)
5910 next
= NEXT_INSN (note
);
5911 prev
= PREV_INSN (note
);
5913 NEXT_INSN (prev
) = next
;
5915 PREV_INSN (next
) = prev
;
5916 add_insn_after (note
, insn
);
5923 register rtx insn
, note
= 0;
5925 /* Scan from the end until we reach the first epilogue insn.
5926 We apparently can't depend on basic_block_{head,end} after
5928 for (len
= 0; epilogue
[len
]; len
++)
5930 for (insn
= get_last_insn (); len
&& insn
; insn
= PREV_INSN (insn
))
5932 if (GET_CODE (insn
) == NOTE
)
5934 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_EPILOGUE_BEG
)
5937 else if ((len
-= contains (insn
, epilogue
)) == 0)
5939 /* Find the epilogue-begin note if we haven't already, and
5940 move it to just before the first epilogue insn. */
5943 for (note
= insn
; note
= PREV_INSN (note
);)
5944 if (GET_CODE (note
) == NOTE
5945 && NOTE_LINE_NUMBER (note
) == NOTE_INSN_EPILOGUE_BEG
)
5948 next
= NEXT_INSN (note
);
5949 prev
= PREV_INSN (note
);
5951 NEXT_INSN (prev
) = next
;
5953 PREV_INSN (next
) = prev
;
5954 add_insn_after (note
, PREV_INSN (insn
));
5959 #endif /* HAVE_prologue or HAVE_epilogue */