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 the location at which the current
195 function returns its result. If the current function returns its
196 result in a register, current_function_return_rtx will always be
197 the hard register containing the result. */
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 possibly used for loading a copy
304 of a parameter of this function. */
307 /* Vector indexed by REGNO, containing location on stack in which
308 to put the parm which is nominally in pseudo register REGNO,
309 if we discover that that parm must go in the stack. The highest
310 element in this vector is one less than MAX_PARM_REG, above. */
311 rtx
*parm_reg_stack_loc
;
313 /* Nonzero once virtual register instantiation has been done.
314 assign_stack_local uses frame_pointer_rtx when this is nonzero. */
315 static int virtuals_instantiated
;
317 /* These variables hold pointers to functions to
318 save and restore machine-specific data,
319 in push_function_context and pop_function_context. */
320 void (*save_machine_status
) PROTO((struct function
*));
321 void (*restore_machine_status
) PROTO((struct function
*));
323 /* Nonzero if we need to distinguish between the return value of this function
324 and the return value of a function called by this function. This helps
327 extern int rtx_equal_function_value_matters
;
328 extern tree sequence_rtl_expr
;
330 /* In order to evaluate some expressions, such as function calls returning
331 structures in memory, we need to temporarily allocate stack locations.
332 We record each allocated temporary in the following structure.
334 Associated with each temporary slot is a nesting level. When we pop up
335 one level, all temporaries associated with the previous level are freed.
336 Normally, all temporaries are freed after the execution of the statement
337 in which they were created. However, if we are inside a ({...}) grouping,
338 the result may be in a temporary and hence must be preserved. If the
339 result could be in a temporary, we preserve it if we can determine which
340 one it is in. If we cannot determine which temporary may contain the
341 result, all temporaries are preserved. A temporary is preserved by
342 pretending it was allocated at the previous nesting level.
344 Automatic variables are also assigned temporary slots, at the nesting
345 level where they are defined. They are marked a "kept" so that
346 free_temp_slots will not free them. */
350 /* Points to next temporary slot. */
351 struct temp_slot
*next
;
352 /* The rtx to used to reference the slot. */
354 /* The rtx used to represent the address if not the address of the
355 slot above. May be an EXPR_LIST if multiple addresses exist. */
357 /* The size, in units, of the slot. */
359 /* The value of `sequence_rtl_expr' when this temporary is allocated. */
361 /* Non-zero if this temporary is currently in use. */
363 /* Non-zero if this temporary has its address taken. */
365 /* Nesting level at which this slot is being used. */
367 /* Non-zero if this should survive a call to free_temp_slots. */
369 /* The offset of the slot from the frame_pointer, including extra space
370 for alignment. This info is for combine_temp_slots. */
372 /* The size of the slot, including extra space for alignment. This
373 info is for combine_temp_slots. */
377 /* List of all temporaries allocated, both available and in use. */
379 struct temp_slot
*temp_slots
;
381 /* Current nesting level for temporaries. */
385 /* The FUNCTION_DECL node for the current function. */
386 static tree this_function_decl
;
388 /* Callinfo pointer for the current function. */
389 static rtx this_function_callinfo
;
391 /* The label in the bytecode file of this function's actual bytecode.
393 static char *this_function_bytecode
;
395 /* The call description vector for the current function. */
396 static rtx this_function_calldesc
;
398 /* Size of the local variables allocated for the current function. */
401 /* Current depth of the bytecode evaluation stack. */
404 /* Maximum depth of the evaluation stack in this function. */
407 /* Current depth in statement expressions. */
408 static int stmt_expr_depth
;
410 /* This structure is used to record MEMs or pseudos used to replace VAR, any
411 SUBREGs of VAR, and any MEMs containing VAR as an address. We need to
412 maintain this list in case two operands of an insn were required to match;
413 in that case we must ensure we use the same replacement. */
415 struct fixup_replacement
419 struct fixup_replacement
*next
;
422 /* Forward declarations. */
424 static struct temp_slot
*find_temp_slot_from_address
PROTO((rtx
));
425 static void put_reg_into_stack
PROTO((struct function
*, rtx
, tree
,
426 enum machine_mode
, enum machine_mode
,
428 static void fixup_var_refs
PROTO((rtx
, enum machine_mode
, int));
429 static struct fixup_replacement
430 *find_fixup_replacement
PROTO((struct fixup_replacement
**, rtx
));
431 static void fixup_var_refs_insns
PROTO((rtx
, enum machine_mode
, int,
433 static void fixup_var_refs_1
PROTO((rtx
, enum machine_mode
, rtx
*, rtx
,
434 struct fixup_replacement
**));
435 static rtx fixup_memory_subreg
PROTO((rtx
, rtx
, int));
436 static rtx walk_fixup_memory_subreg
PROTO((rtx
, rtx
, int));
437 static rtx fixup_stack_1
PROTO((rtx
, rtx
));
438 static void optimize_bit_field
PROTO((rtx
, rtx
, rtx
*));
439 static void instantiate_decls
PROTO((tree
, int));
440 static void instantiate_decls_1
PROTO((tree
, int));
441 static void instantiate_decl
PROTO((rtx
, int, int));
442 static int instantiate_virtual_regs_1
PROTO((rtx
*, rtx
, int));
443 static void delete_handlers
PROTO((void));
444 static void pad_to_arg_alignment
PROTO((struct args_size
*, int));
445 static void pad_below
PROTO((struct args_size
*, enum machine_mode
,
447 static tree round_down
PROTO((tree
, int));
448 static rtx round_trampoline_addr
PROTO((rtx
));
449 static tree blocks_nreverse
PROTO((tree
));
450 static int all_blocks
PROTO((tree
, tree
*));
451 static int *record_insns
PROTO((rtx
));
452 static int contains
PROTO((rtx
, int *));
453 static void put_addressof_into_stack
PROTO((rtx
));
454 static void purge_addressof_1
PROTO((rtx
*, rtx
, int));
456 /* Pointer to chain of `struct function' for containing functions. */
457 struct function
*outer_function_chain
;
459 /* Given a function decl for a containing function,
460 return the `struct function' for it. */
463 find_function_data (decl
)
467 for (p
= outer_function_chain
; p
; p
= p
->next
)
473 /* Save the current context for compilation of a nested function.
474 This is called from language-specific code.
475 The caller is responsible for saving any language-specific status,
476 since this function knows only about language-independent variables. */
479 push_function_context_to (context
)
482 struct function
*p
= (struct function
*) xmalloc (sizeof (struct function
));
484 p
->next
= outer_function_chain
;
485 outer_function_chain
= p
;
487 p
->name
= current_function_name
;
488 p
->decl
= current_function_decl
;
489 p
->pops_args
= current_function_pops_args
;
490 p
->returns_struct
= current_function_returns_struct
;
491 p
->returns_pcc_struct
= current_function_returns_pcc_struct
;
492 p
->returns_pointer
= current_function_returns_pointer
;
493 p
->needs_context
= current_function_needs_context
;
494 p
->calls_setjmp
= current_function_calls_setjmp
;
495 p
->calls_longjmp
= current_function_calls_longjmp
;
496 p
->calls_alloca
= current_function_calls_alloca
;
497 p
->has_nonlocal_label
= current_function_has_nonlocal_label
;
498 p
->has_nonlocal_goto
= current_function_has_nonlocal_goto
;
499 p
->contains_functions
= current_function_contains_functions
;
500 p
->is_thunk
= current_function_is_thunk
;
501 p
->args_size
= current_function_args_size
;
502 p
->pretend_args_size
= current_function_pretend_args_size
;
503 p
->arg_offset_rtx
= current_function_arg_offset_rtx
;
504 p
->varargs
= current_function_varargs
;
505 p
->stdarg
= current_function_stdarg
;
506 p
->uses_const_pool
= current_function_uses_const_pool
;
507 p
->uses_pic_offset_table
= current_function_uses_pic_offset_table
;
508 p
->internal_arg_pointer
= current_function_internal_arg_pointer
;
509 p
->max_parm_reg
= max_parm_reg
;
510 p
->parm_reg_stack_loc
= parm_reg_stack_loc
;
511 p
->outgoing_args_size
= current_function_outgoing_args_size
;
512 p
->return_rtx
= current_function_return_rtx
;
513 p
->nonlocal_goto_handler_slot
= nonlocal_goto_handler_slot
;
514 p
->nonlocal_goto_stack_level
= nonlocal_goto_stack_level
;
515 p
->nonlocal_labels
= nonlocal_labels
;
516 p
->cleanup_label
= cleanup_label
;
517 p
->return_label
= return_label
;
518 p
->save_expr_regs
= save_expr_regs
;
519 p
->stack_slot_list
= stack_slot_list
;
520 p
->parm_birth_insn
= parm_birth_insn
;
521 p
->frame_offset
= frame_offset
;
522 p
->tail_recursion_label
= tail_recursion_label
;
523 p
->tail_recursion_reentry
= tail_recursion_reentry
;
524 p
->arg_pointer_save_area
= arg_pointer_save_area
;
525 p
->rtl_expr_chain
= rtl_expr_chain
;
526 p
->last_parm_insn
= last_parm_insn
;
527 p
->context_display
= context_display
;
528 p
->trampoline_list
= trampoline_list
;
529 p
->function_call_count
= function_call_count
;
530 p
->temp_slots
= temp_slots
;
531 p
->temp_slot_level
= temp_slot_level
;
532 p
->fixup_var_refs_queue
= 0;
533 p
->epilogue_delay_list
= current_function_epilogue_delay_list
;
534 p
->args_info
= current_function_args_info
;
536 save_tree_status (p
, context
);
537 save_storage_status (p
);
538 save_emit_status (p
);
540 save_expr_status (p
);
541 save_stmt_status (p
);
542 save_varasm_status (p
, context
);
544 if (save_machine_status
)
545 (*save_machine_status
) (p
);
549 push_function_context ()
551 push_function_context_to (current_function_decl
);
554 /* Restore the last saved context, at the end of a nested function.
555 This function is called from language-specific code. */
558 pop_function_context_from (context
)
561 struct function
*p
= outer_function_chain
;
563 outer_function_chain
= p
->next
;
565 current_function_contains_functions
566 = p
->contains_functions
|| p
->inline_obstacks
567 || context
== current_function_decl
;
568 current_function_name
= p
->name
;
569 current_function_decl
= p
->decl
;
570 current_function_pops_args
= p
->pops_args
;
571 current_function_returns_struct
= p
->returns_struct
;
572 current_function_returns_pcc_struct
= p
->returns_pcc_struct
;
573 current_function_returns_pointer
= p
->returns_pointer
;
574 current_function_needs_context
= p
->needs_context
;
575 current_function_calls_setjmp
= p
->calls_setjmp
;
576 current_function_calls_longjmp
= p
->calls_longjmp
;
577 current_function_calls_alloca
= p
->calls_alloca
;
578 current_function_has_nonlocal_label
= p
->has_nonlocal_label
;
579 current_function_has_nonlocal_goto
= p
->has_nonlocal_goto
;
580 current_function_is_thunk
= p
->is_thunk
;
581 current_function_args_size
= p
->args_size
;
582 current_function_pretend_args_size
= p
->pretend_args_size
;
583 current_function_arg_offset_rtx
= p
->arg_offset_rtx
;
584 current_function_varargs
= p
->varargs
;
585 current_function_stdarg
= p
->stdarg
;
586 current_function_uses_const_pool
= p
->uses_const_pool
;
587 current_function_uses_pic_offset_table
= p
->uses_pic_offset_table
;
588 current_function_internal_arg_pointer
= p
->internal_arg_pointer
;
589 max_parm_reg
= p
->max_parm_reg
;
590 parm_reg_stack_loc
= p
->parm_reg_stack_loc
;
591 current_function_outgoing_args_size
= p
->outgoing_args_size
;
592 current_function_return_rtx
= p
->return_rtx
;
593 nonlocal_goto_handler_slot
= p
->nonlocal_goto_handler_slot
;
594 nonlocal_goto_stack_level
= p
->nonlocal_goto_stack_level
;
595 nonlocal_labels
= p
->nonlocal_labels
;
596 cleanup_label
= p
->cleanup_label
;
597 return_label
= p
->return_label
;
598 save_expr_regs
= p
->save_expr_regs
;
599 stack_slot_list
= p
->stack_slot_list
;
600 parm_birth_insn
= p
->parm_birth_insn
;
601 frame_offset
= p
->frame_offset
;
602 tail_recursion_label
= p
->tail_recursion_label
;
603 tail_recursion_reentry
= p
->tail_recursion_reentry
;
604 arg_pointer_save_area
= p
->arg_pointer_save_area
;
605 rtl_expr_chain
= p
->rtl_expr_chain
;
606 last_parm_insn
= p
->last_parm_insn
;
607 context_display
= p
->context_display
;
608 trampoline_list
= p
->trampoline_list
;
609 function_call_count
= p
->function_call_count
;
610 temp_slots
= p
->temp_slots
;
611 temp_slot_level
= p
->temp_slot_level
;
612 current_function_epilogue_delay_list
= p
->epilogue_delay_list
;
614 current_function_args_info
= p
->args_info
;
616 restore_tree_status (p
, context
);
617 restore_storage_status (p
);
618 restore_expr_status (p
);
619 restore_emit_status (p
);
620 restore_stmt_status (p
);
621 restore_varasm_status (p
);
623 if (restore_machine_status
)
624 (*restore_machine_status
) (p
);
626 /* Finish doing put_var_into_stack for any of our variables
627 which became addressable during the nested function. */
629 struct var_refs_queue
*queue
= p
->fixup_var_refs_queue
;
630 for (; queue
; queue
= queue
->next
)
631 fixup_var_refs (queue
->modified
, queue
->promoted_mode
, queue
->unsignedp
);
636 /* Reset variables that have known state during rtx generation. */
637 rtx_equal_function_value_matters
= 1;
638 virtuals_instantiated
= 0;
641 void pop_function_context ()
643 pop_function_context_from (current_function_decl
);
646 /* Allocate fixed slots in the stack frame of the current function. */
648 /* Return size needed for stack frame based on slots so far allocated.
649 This size counts from zero. It is not rounded to STACK_BOUNDARY;
650 the caller may have to do that. */
655 #ifdef FRAME_GROWS_DOWNWARD
656 return -frame_offset
;
662 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
663 with machine mode MODE.
665 ALIGN controls the amount of alignment for the address of the slot:
666 0 means according to MODE,
667 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
668 positive specifies alignment boundary in bits.
670 We do not round to stack_boundary here. */
673 assign_stack_local (mode
, size
, align
)
674 enum machine_mode mode
;
678 register rtx x
, addr
;
679 int bigend_correction
= 0;
684 alignment
= GET_MODE_ALIGNMENT (mode
) / BITS_PER_UNIT
;
686 alignment
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
688 else if (align
== -1)
690 alignment
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
691 size
= CEIL_ROUND (size
, alignment
);
694 alignment
= align
/ BITS_PER_UNIT
;
696 /* Round frame offset to that alignment.
697 We must be careful here, since FRAME_OFFSET might be negative and
698 division with a negative dividend isn't as well defined as we might
699 like. So we instead assume that ALIGNMENT is a power of two and
700 use logical operations which are unambiguous. */
701 #ifdef FRAME_GROWS_DOWNWARD
702 frame_offset
= FLOOR_ROUND (frame_offset
, alignment
);
704 frame_offset
= CEIL_ROUND (frame_offset
, alignment
);
707 /* On a big-endian machine, if we are allocating more space than we will use,
708 use the least significant bytes of those that are allocated. */
709 if (BYTES_BIG_ENDIAN
&& mode
!= BLKmode
)
710 bigend_correction
= size
- GET_MODE_SIZE (mode
);
712 #ifdef FRAME_GROWS_DOWNWARD
713 frame_offset
-= size
;
716 /* If we have already instantiated virtual registers, return the actual
717 address relative to the frame pointer. */
718 if (virtuals_instantiated
)
719 addr
= plus_constant (frame_pointer_rtx
,
720 (frame_offset
+ bigend_correction
721 + STARTING_FRAME_OFFSET
));
723 addr
= plus_constant (virtual_stack_vars_rtx
,
724 frame_offset
+ bigend_correction
);
726 #ifndef FRAME_GROWS_DOWNWARD
727 frame_offset
+= size
;
730 x
= gen_rtx (MEM
, mode
, addr
);
732 stack_slot_list
= gen_rtx (EXPR_LIST
, VOIDmode
, x
, stack_slot_list
);
737 /* Assign a stack slot in a containing function.
738 First three arguments are same as in preceding function.
739 The last argument specifies the function to allocate in. */
742 assign_outer_stack_local (mode
, size
, align
, function
)
743 enum machine_mode mode
;
746 struct function
*function
;
748 register rtx x
, addr
;
749 int bigend_correction
= 0;
752 /* Allocate in the memory associated with the function in whose frame
754 push_obstacks (function
->function_obstack
,
755 function
->function_maybepermanent_obstack
);
759 alignment
= GET_MODE_ALIGNMENT (mode
) / BITS_PER_UNIT
;
761 alignment
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
763 else if (align
== -1)
765 alignment
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
766 size
= CEIL_ROUND (size
, alignment
);
769 alignment
= align
/ BITS_PER_UNIT
;
771 /* Round frame offset to that alignment. */
772 #ifdef FRAME_GROWS_DOWNWARD
773 function
->frame_offset
= FLOOR_ROUND (function
->frame_offset
, alignment
);
775 function
->frame_offset
= CEIL_ROUND (function
->frame_offset
, alignment
);
778 /* On a big-endian machine, if we are allocating more space than we will use,
779 use the least significant bytes of those that are allocated. */
780 if (BYTES_BIG_ENDIAN
&& mode
!= BLKmode
)
781 bigend_correction
= size
- GET_MODE_SIZE (mode
);
783 #ifdef FRAME_GROWS_DOWNWARD
784 function
->frame_offset
-= size
;
786 addr
= plus_constant (virtual_stack_vars_rtx
,
787 function
->frame_offset
+ bigend_correction
);
788 #ifndef FRAME_GROWS_DOWNWARD
789 function
->frame_offset
+= size
;
792 x
= gen_rtx (MEM
, mode
, addr
);
794 function
->stack_slot_list
795 = gen_rtx (EXPR_LIST
, VOIDmode
, x
, function
->stack_slot_list
);
802 /* Allocate a temporary stack slot and record it for possible later
805 MODE is the machine mode to be given to the returned rtx.
807 SIZE is the size in units of the space required. We do no rounding here
808 since assign_stack_local will do any required rounding.
810 KEEP is 1 if this slot is to be retained after a call to
811 free_temp_slots. Automatic variables for a block are allocated
812 with this flag. KEEP is 2, if we allocate a longer term temporary,
813 whose lifetime is controlled by CLEANUP_POINT_EXPRs. */
816 assign_stack_temp (mode
, size
, keep
)
817 enum machine_mode mode
;
821 struct temp_slot
*p
, *best_p
= 0;
823 /* If SIZE is -1 it means that somebody tried to allocate a temporary
824 of a variable size. */
828 /* First try to find an available, already-allocated temporary that is the
829 exact size we require. */
830 for (p
= temp_slots
; p
; p
= p
->next
)
831 if (p
->size
== size
&& GET_MODE (p
->slot
) == mode
&& ! p
->in_use
)
834 /* If we didn't find, one, try one that is larger than what we want. We
835 find the smallest such. */
837 for (p
= temp_slots
; p
; p
= p
->next
)
838 if (p
->size
> size
&& GET_MODE (p
->slot
) == mode
&& ! p
->in_use
839 && (best_p
== 0 || best_p
->size
> p
->size
))
842 /* Make our best, if any, the one to use. */
845 /* If there are enough aligned bytes left over, make them into a new
846 temp_slot so that the extra bytes don't get wasted. Do this only
847 for BLKmode slots, so that we can be sure of the alignment. */
848 if (GET_MODE (best_p
->slot
) == BLKmode
)
850 int alignment
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
851 int rounded_size
= CEIL_ROUND (size
, alignment
);
853 if (best_p
->size
- rounded_size
>= alignment
)
855 p
= (struct temp_slot
*) oballoc (sizeof (struct temp_slot
));
856 p
->in_use
= p
->addr_taken
= 0;
857 p
->size
= best_p
->size
- rounded_size
;
858 p
->base_offset
= best_p
->base_offset
+ rounded_size
;
859 p
->full_size
= best_p
->full_size
- rounded_size
;
860 p
->slot
= gen_rtx (MEM
, BLKmode
,
861 plus_constant (XEXP (best_p
->slot
, 0),
865 p
->next
= temp_slots
;
868 stack_slot_list
= gen_rtx (EXPR_LIST
, VOIDmode
, p
->slot
,
871 best_p
->size
= rounded_size
;
872 best_p
->full_size
= rounded_size
;
879 /* If we still didn't find one, make a new temporary. */
882 int frame_offset_old
= frame_offset
;
883 p
= (struct temp_slot
*) oballoc (sizeof (struct temp_slot
));
884 /* If the temp slot mode doesn't indicate the alignment,
885 use the largest possible, so no one will be disappointed. */
886 p
->slot
= assign_stack_local (mode
, size
, mode
== BLKmode
? -1 : 0);
887 /* The following slot size computation is necessary because we don't
888 know the actual size of the temporary slot until assign_stack_local
889 has performed all the frame alignment and size rounding for the
890 requested temporary. Note that extra space added for alignment
891 can be either above or below this stack slot depending on which
892 way the frame grows. We include the extra space if and only if it
893 is above this slot. */
894 #ifdef FRAME_GROWS_DOWNWARD
895 p
->size
= frame_offset_old
- frame_offset
;
899 /* Now define the fields used by combine_temp_slots. */
900 #ifdef FRAME_GROWS_DOWNWARD
901 p
->base_offset
= frame_offset
;
902 p
->full_size
= frame_offset_old
- frame_offset
;
904 p
->base_offset
= frame_offset_old
;
905 p
->full_size
= frame_offset
- frame_offset_old
;
908 p
->next
= temp_slots
;
914 p
->rtl_expr
= sequence_rtl_expr
;
918 p
->level
= target_temp_slot_level
;
923 p
->level
= temp_slot_level
;
927 /* We may be reusing an old slot, so clear any MEM flags that may have been
929 RTX_UNCHANGING_P (p
->slot
) = 0;
930 MEM_IN_STRUCT_P (p
->slot
) = 0;
934 /* Assign a temporary of given TYPE.
935 KEEP is as for assign_stack_temp.
936 MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
937 it is 0 if a register is OK.
938 DONT_PROMOTE is 1 if we should not promote values in register
942 assign_temp (type
, keep
, memory_required
, dont_promote
)
948 enum machine_mode mode
= TYPE_MODE (type
);
949 int unsignedp
= TREE_UNSIGNED (type
);
951 if (mode
== BLKmode
|| memory_required
)
953 int size
= int_size_in_bytes (type
);
956 /* Unfortunately, we don't yet know how to allocate variable-sized
957 temporaries. However, sometimes we have a fixed upper limit on
958 the size (which is stored in TYPE_ARRAY_MAX_SIZE) and can use that
959 instead. This is the case for Chill variable-sized strings. */
960 if (size
== -1 && TREE_CODE (type
) == ARRAY_TYPE
961 && TYPE_ARRAY_MAX_SIZE (type
) != NULL_TREE
962 && TREE_CODE (TYPE_ARRAY_MAX_SIZE (type
)) == INTEGER_CST
)
963 size
= TREE_INT_CST_LOW (TYPE_ARRAY_MAX_SIZE (type
));
965 tmp
= assign_stack_temp (mode
, size
, keep
);
966 MEM_IN_STRUCT_P (tmp
) = AGGREGATE_TYPE_P (type
);
970 #ifndef PROMOTE_FOR_CALL_ONLY
972 mode
= promote_mode (type
, mode
, &unsignedp
, 0);
975 return gen_reg_rtx (mode
);
978 /* Combine temporary stack slots which are adjacent on the stack.
980 This allows for better use of already allocated stack space. This is only
981 done for BLKmode slots because we can be sure that we won't have alignment
982 problems in this case. */
985 combine_temp_slots ()
987 struct temp_slot
*p
, *q
;
988 struct temp_slot
*prev_p
, *prev_q
;
989 /* Determine where to free back to after this function. */
990 rtx free_pointer
= rtx_alloc (CONST_INT
);
992 for (p
= temp_slots
, prev_p
= 0; p
; p
= prev_p
? prev_p
->next
: temp_slots
)
995 if (! p
->in_use
&& GET_MODE (p
->slot
) == BLKmode
)
996 for (q
= p
->next
, prev_q
= p
; q
; q
= prev_q
->next
)
999 if (! q
->in_use
&& GET_MODE (q
->slot
) == BLKmode
)
1001 if (p
->base_offset
+ p
->full_size
== q
->base_offset
)
1003 /* Q comes after P; combine Q into P. */
1005 p
->full_size
+= q
->full_size
;
1008 else if (q
->base_offset
+ q
->full_size
== p
->base_offset
)
1010 /* P comes after Q; combine P into Q. */
1012 q
->full_size
+= p
->full_size
;
1017 /* Either delete Q or advance past it. */
1019 prev_q
->next
= q
->next
;
1023 /* Either delete P or advance past it. */
1027 prev_p
->next
= p
->next
;
1029 temp_slots
= p
->next
;
1035 /* Free all the RTL made by plus_constant. */
1036 rtx_free (free_pointer
);
1039 /* Find the temp slot corresponding to the object at address X. */
1041 static struct temp_slot
*
1042 find_temp_slot_from_address (x
)
1045 struct temp_slot
*p
;
1048 for (p
= temp_slots
; p
; p
= p
->next
)
1052 else if (XEXP (p
->slot
, 0) == x
1054 || (GET_CODE (x
) == PLUS
1055 && XEXP (x
, 0) == virtual_stack_vars_rtx
1056 && GET_CODE (XEXP (x
, 1)) == CONST_INT
1057 && INTVAL (XEXP (x
, 1)) >= p
->base_offset
1058 && INTVAL (XEXP (x
, 1)) < p
->base_offset
+ p
->full_size
))
1061 else if (p
->address
!= 0 && GET_CODE (p
->address
) == EXPR_LIST
)
1062 for (next
= p
->address
; next
; next
= XEXP (next
, 1))
1063 if (XEXP (next
, 0) == x
)
1070 /* Indicate that NEW is an alternate way of referring to the temp slot
1071 that previous was known by OLD. */
1074 update_temp_slot_address (old
, new)
1077 struct temp_slot
*p
= find_temp_slot_from_address (old
);
1079 /* If none, return. Else add NEW as an alias. */
1082 else if (p
->address
== 0)
1086 if (GET_CODE (p
->address
) != EXPR_LIST
)
1087 p
->address
= gen_rtx (EXPR_LIST
, VOIDmode
, p
->address
, NULL_RTX
);
1089 p
->address
= gen_rtx (EXPR_LIST
, VOIDmode
, new, p
->address
);
1093 /* If X could be a reference to a temporary slot, mark the fact that its
1094 address was taken. */
1097 mark_temp_addr_taken (x
)
1100 struct temp_slot
*p
;
1105 /* If X is not in memory or is at a constant address, it cannot be in
1106 a temporary slot. */
1107 if (GET_CODE (x
) != MEM
|| CONSTANT_P (XEXP (x
, 0)))
1110 p
= find_temp_slot_from_address (XEXP (x
, 0));
1115 /* If X could be a reference to a temporary slot, mark that slot as
1116 belonging to the to one level higher than the current level. If X
1117 matched one of our slots, just mark that one. Otherwise, we can't
1118 easily predict which it is, so upgrade all of them. Kept slots
1119 need not be touched.
1121 This is called when an ({...}) construct occurs and a statement
1122 returns a value in memory. */
1125 preserve_temp_slots (x
)
1128 struct temp_slot
*p
= 0;
1130 /* If there is no result, we still might have some objects whose address
1131 were taken, so we need to make sure they stay around. */
1134 for (p
= temp_slots
; p
; p
= p
->next
)
1135 if (p
->in_use
&& p
->level
== temp_slot_level
&& p
->addr_taken
)
1141 /* If X is a register that is being used as a pointer, see if we have
1142 a temporary slot we know it points to. To be consistent with
1143 the code below, we really should preserve all non-kept slots
1144 if we can't find a match, but that seems to be much too costly. */
1145 if (GET_CODE (x
) == REG
&& REGNO_POINTER_FLAG (REGNO (x
)))
1146 p
= find_temp_slot_from_address (x
);
1148 /* If X is not in memory or is at a constant address, it cannot be in
1149 a temporary slot, but it can contain something whose address was
1151 if (p
== 0 && (GET_CODE (x
) != MEM
|| CONSTANT_P (XEXP (x
, 0))))
1153 for (p
= temp_slots
; p
; p
= p
->next
)
1154 if (p
->in_use
&& p
->level
== temp_slot_level
&& p
->addr_taken
)
1160 /* First see if we can find a match. */
1162 p
= find_temp_slot_from_address (XEXP (x
, 0));
1166 /* Move everything at our level whose address was taken to our new
1167 level in case we used its address. */
1168 struct temp_slot
*q
;
1170 if (p
->level
== temp_slot_level
)
1172 for (q
= temp_slots
; q
; q
= q
->next
)
1173 if (q
!= p
&& q
->addr_taken
&& q
->level
== p
->level
)
1182 /* Otherwise, preserve all non-kept slots at this level. */
1183 for (p
= temp_slots
; p
; p
= p
->next
)
1184 if (p
->in_use
&& p
->level
== temp_slot_level
&& ! p
->keep
)
1188 /* X is the result of an RTL_EXPR. If it is a temporary slot associated
1189 with that RTL_EXPR, promote it into a temporary slot at the present
1190 level so it will not be freed when we free slots made in the
1194 preserve_rtl_expr_result (x
)
1197 struct temp_slot
*p
;
1199 /* If X is not in memory or is at a constant address, it cannot be in
1200 a temporary slot. */
1201 if (x
== 0 || GET_CODE (x
) != MEM
|| CONSTANT_P (XEXP (x
, 0)))
1204 /* If we can find a match, move it to our level unless it is already at
1206 p
= find_temp_slot_from_address (XEXP (x
, 0));
1209 p
->level
= MIN (p
->level
, temp_slot_level
);
1216 /* Free all temporaries used so far. This is normally called at the end
1217 of generating code for a statement. Don't free any temporaries
1218 currently in use for an RTL_EXPR that hasn't yet been emitted.
1219 We could eventually do better than this since it can be reused while
1220 generating the same RTL_EXPR, but this is complex and probably not
1226 struct temp_slot
*p
;
1228 for (p
= temp_slots
; p
; p
= p
->next
)
1229 if (p
->in_use
&& p
->level
== temp_slot_level
&& ! p
->keep
1230 && p
->rtl_expr
== 0)
1233 combine_temp_slots ();
1236 /* Free all temporary slots used in T, an RTL_EXPR node. */
1239 free_temps_for_rtl_expr (t
)
1242 struct temp_slot
*p
;
1244 for (p
= temp_slots
; p
; p
= p
->next
)
1245 if (p
->rtl_expr
== t
)
1248 combine_temp_slots ();
1251 /* Mark all temporaries ever allocated in this functon as not suitable
1252 for reuse until the current level is exited. */
1255 mark_all_temps_used ()
1257 struct temp_slot
*p
;
1259 for (p
= temp_slots
; p
; p
= p
->next
)
1261 p
->in_use
= p
->keep
= 1;
1262 p
->level
= MIN (p
->level
, temp_slot_level
);
1266 /* Push deeper into the nesting level for stack temporaries. */
1274 /* Pop a temporary nesting level. All slots in use in the current level
1280 struct temp_slot
*p
;
1282 for (p
= temp_slots
; p
; p
= p
->next
)
1283 if (p
->in_use
&& p
->level
== temp_slot_level
&& p
->rtl_expr
== 0)
1286 combine_temp_slots ();
1291 /* Initialize temporary slots. */
1296 /* We have not allocated any temporaries yet. */
1298 temp_slot_level
= 0;
1299 target_temp_slot_level
= 0;
1302 /* Retroactively move an auto variable from a register to a stack slot.
1303 This is done when an address-reference to the variable is seen. */
1306 put_var_into_stack (decl
)
1310 enum machine_mode promoted_mode
, decl_mode
;
1311 struct function
*function
= 0;
1313 int can_use_addressof
;
1315 if (output_bytecode
)
1318 context
= decl_function_context (decl
);
1320 /* Get the current rtl used for this object and it's original mode. */
1321 reg
= TREE_CODE (decl
) == SAVE_EXPR
? SAVE_EXPR_RTL (decl
) : DECL_RTL (decl
);
1323 /* No need to do anything if decl has no rtx yet
1324 since in that case caller is setting TREE_ADDRESSABLE
1325 and a stack slot will be assigned when the rtl is made. */
1329 /* Get the declared mode for this object. */
1330 decl_mode
= (TREE_CODE (decl
) == SAVE_EXPR
? TYPE_MODE (TREE_TYPE (decl
))
1331 : DECL_MODE (decl
));
1332 /* Get the mode it's actually stored in. */
1333 promoted_mode
= GET_MODE (reg
);
1335 /* If this variable comes from an outer function,
1336 find that function's saved context. */
1337 if (context
!= current_function_decl
&& context
!= inline_function_decl
)
1338 for (function
= outer_function_chain
; function
; function
= function
->next
)
1339 if (function
->decl
== context
)
1342 /* If this is a variable-size object with a pseudo to address it,
1343 put that pseudo into the stack, if the var is nonlocal. */
1344 if (DECL_NONLOCAL (decl
)
1345 && GET_CODE (reg
) == MEM
1346 && GET_CODE (XEXP (reg
, 0)) == REG
1347 && REGNO (XEXP (reg
, 0)) > LAST_VIRTUAL_REGISTER
)
1349 reg
= XEXP (reg
, 0);
1350 decl_mode
= promoted_mode
= GET_MODE (reg
);
1355 /* FIXME make it work for promoted modes too */
1356 && decl_mode
== promoted_mode
1357 #ifdef NON_SAVING_SETJMP
1358 && ! (NON_SAVING_SETJMP
&& current_function_calls_setjmp
)
1362 /* If we can't use ADDRESSOF, make sure we see through one we already
1364 if (! can_use_addressof
&& GET_CODE (reg
) == MEM
1365 && GET_CODE (XEXP (reg
, 0)) == ADDRESSOF
)
1366 reg
= XEXP (XEXP (reg
, 0), 0);
1368 /* Now we should have a value that resides in one or more pseudo regs. */
1370 if (GET_CODE (reg
) == REG
)
1372 /* If this variable lives in the current function and we don't need
1373 to put things in the stack for the sake of setjmp, try to keep it
1374 in a register until we know we actually need the address. */
1375 if (can_use_addressof
)
1376 gen_mem_addressof (reg
, decl
);
1378 put_reg_into_stack (function
, reg
, TREE_TYPE (decl
),
1379 promoted_mode
, decl_mode
,
1380 TREE_SIDE_EFFECTS (decl
), 0);
1382 else if (GET_CODE (reg
) == CONCAT
)
1384 /* A CONCAT contains two pseudos; put them both in the stack.
1385 We do it so they end up consecutive. */
1386 enum machine_mode part_mode
= GET_MODE (XEXP (reg
, 0));
1387 tree part_type
= TREE_TYPE (TREE_TYPE (decl
));
1388 #ifdef FRAME_GROWS_DOWNWARD
1389 /* Since part 0 should have a lower address, do it second. */
1390 put_reg_into_stack (function
, XEXP (reg
, 1), part_type
, part_mode
,
1391 part_mode
, TREE_SIDE_EFFECTS (decl
), 0);
1392 put_reg_into_stack (function
, XEXP (reg
, 0), part_type
, part_mode
,
1393 part_mode
, TREE_SIDE_EFFECTS (decl
), 0);
1395 put_reg_into_stack (function
, XEXP (reg
, 0), part_type
, part_mode
,
1396 part_mode
, TREE_SIDE_EFFECTS (decl
), 0);
1397 put_reg_into_stack (function
, XEXP (reg
, 1), part_type
, part_mode
,
1398 part_mode
, TREE_SIDE_EFFECTS (decl
), 0);
1401 /* Change the CONCAT into a combined MEM for both parts. */
1402 PUT_CODE (reg
, MEM
);
1403 MEM_VOLATILE_P (reg
) = MEM_VOLATILE_P (XEXP (reg
, 0));
1405 /* The two parts are in memory order already.
1406 Use the lower parts address as ours. */
1407 XEXP (reg
, 0) = XEXP (XEXP (reg
, 0), 0);
1408 /* Prevent sharing of rtl that might lose. */
1409 if (GET_CODE (XEXP (reg
, 0)) == PLUS
)
1410 XEXP (reg
, 0) = copy_rtx (XEXP (reg
, 0));
1415 if (flag_check_memory_usage
)
1416 emit_library_call (chkr_set_right_libfunc
, 1, VOIDmode
, 3,
1417 XEXP (reg
, 0), ptr_mode
,
1418 GEN_INT (GET_MODE_SIZE (GET_MODE (reg
))),
1419 TYPE_MODE (sizetype
),
1420 GEN_INT (MEMORY_USE_RW
), QImode
);
1423 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1424 into the stack frame of FUNCTION (0 means the current function).
1425 DECL_MODE is the machine mode of the user-level data type.
1426 PROMOTED_MODE is the machine mode of the register.
1427 VOLATILE_P is nonzero if this is for a "volatile" decl. */
1430 put_reg_into_stack (function
, reg
, type
, promoted_mode
, decl_mode
, volatile_p
,
1432 struct function
*function
;
1435 enum machine_mode promoted_mode
, decl_mode
;
1440 int regno
= original_regno
;
1443 regno
= REGNO (reg
);
1447 if (regno
< function
->max_parm_reg
)
1448 new = function
->parm_reg_stack_loc
[regno
];
1450 new = assign_outer_stack_local (decl_mode
, GET_MODE_SIZE (decl_mode
),
1455 if (regno
< max_parm_reg
)
1456 new = parm_reg_stack_loc
[regno
];
1458 new = assign_stack_local (decl_mode
, GET_MODE_SIZE (decl_mode
), 0);
1461 PUT_MODE (reg
, decl_mode
);
1462 XEXP (reg
, 0) = XEXP (new, 0);
1463 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
1464 MEM_VOLATILE_P (reg
) = volatile_p
;
1465 PUT_CODE (reg
, MEM
);
1467 /* If this is a memory ref that contains aggregate components,
1468 mark it as such for cse and loop optimize. */
1469 MEM_IN_STRUCT_P (reg
) = AGGREGATE_TYPE_P (type
);
1471 /* Now make sure that all refs to the variable, previously made
1472 when it was a register, are fixed up to be valid again. */
1475 struct var_refs_queue
*temp
;
1477 /* Variable is inherited; fix it up when we get back to its function. */
1478 push_obstacks (function
->function_obstack
,
1479 function
->function_maybepermanent_obstack
);
1481 /* See comment in restore_tree_status in tree.c for why this needs to be
1482 on saveable obstack. */
1484 = (struct var_refs_queue
*) savealloc (sizeof (struct var_refs_queue
));
1485 temp
->modified
= reg
;
1486 temp
->promoted_mode
= promoted_mode
;
1487 temp
->unsignedp
= TREE_UNSIGNED (type
);
1488 temp
->next
= function
->fixup_var_refs_queue
;
1489 function
->fixup_var_refs_queue
= temp
;
1493 /* Variable is local; fix it up now. */
1494 fixup_var_refs (reg
, promoted_mode
, TREE_UNSIGNED (type
));
1498 fixup_var_refs (var
, promoted_mode
, unsignedp
)
1500 enum machine_mode promoted_mode
;
1504 rtx first_insn
= get_insns ();
1505 struct sequence_stack
*stack
= sequence_stack
;
1506 tree rtl_exps
= rtl_expr_chain
;
1508 /* Must scan all insns for stack-refs that exceed the limit. */
1509 fixup_var_refs_insns (var
, promoted_mode
, unsignedp
, first_insn
, stack
== 0);
1511 /* Scan all pending sequences too. */
1512 for (; stack
; stack
= stack
->next
)
1514 push_to_sequence (stack
->first
);
1515 fixup_var_refs_insns (var
, promoted_mode
, unsignedp
,
1516 stack
->first
, stack
->next
!= 0);
1517 /* Update remembered end of sequence
1518 in case we added an insn at the end. */
1519 stack
->last
= get_last_insn ();
1523 /* Scan all waiting RTL_EXPRs too. */
1524 for (pending
= rtl_exps
; pending
; pending
= TREE_CHAIN (pending
))
1526 rtx seq
= RTL_EXPR_SEQUENCE (TREE_VALUE (pending
));
1527 if (seq
!= const0_rtx
&& seq
!= 0)
1529 push_to_sequence (seq
);
1530 fixup_var_refs_insns (var
, promoted_mode
, unsignedp
, seq
, 0);
1536 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
1537 some part of an insn. Return a struct fixup_replacement whose OLD
1538 value is equal to X. Allocate a new structure if no such entry exists. */
1540 static struct fixup_replacement
*
1541 find_fixup_replacement (replacements
, x
)
1542 struct fixup_replacement
**replacements
;
1545 struct fixup_replacement
*p
;
1547 /* See if we have already replaced this. */
1548 for (p
= *replacements
; p
&& p
->old
!= x
; p
= p
->next
)
1553 p
= (struct fixup_replacement
*) oballoc (sizeof (struct fixup_replacement
));
1556 p
->next
= *replacements
;
1563 /* Scan the insn-chain starting with INSN for refs to VAR
1564 and fix them up. TOPLEVEL is nonzero if this chain is the
1565 main chain of insns for the current function. */
1568 fixup_var_refs_insns (var
, promoted_mode
, unsignedp
, insn
, toplevel
)
1570 enum machine_mode promoted_mode
;
1579 rtx next
= NEXT_INSN (insn
);
1581 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
1583 /* If this is a CLOBBER of VAR, delete it.
1585 If it has a REG_LIBCALL note, delete the REG_LIBCALL
1586 and REG_RETVAL notes too. */
1587 if (GET_CODE (PATTERN (insn
)) == CLOBBER
1588 && XEXP (PATTERN (insn
), 0) == var
)
1590 if ((note
= find_reg_note (insn
, REG_LIBCALL
, NULL_RTX
)) != 0)
1591 /* The REG_LIBCALL note will go away since we are going to
1592 turn INSN into a NOTE, so just delete the
1593 corresponding REG_RETVAL note. */
1594 remove_note (XEXP (note
, 0),
1595 find_reg_note (XEXP (note
, 0), REG_RETVAL
,
1598 /* In unoptimized compilation, we shouldn't call delete_insn
1599 except in jump.c doing warnings. */
1600 PUT_CODE (insn
, NOTE
);
1601 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
1602 NOTE_SOURCE_FILE (insn
) = 0;
1605 /* The insn to load VAR from a home in the arglist
1606 is now a no-op. When we see it, just delete it. */
1608 && GET_CODE (PATTERN (insn
)) == SET
1609 && SET_DEST (PATTERN (insn
)) == var
1610 /* If this represents the result of an insn group,
1611 don't delete the insn. */
1612 && find_reg_note (insn
, REG_RETVAL
, NULL_RTX
) == 0
1613 && rtx_equal_p (SET_SRC (PATTERN (insn
)), var
))
1615 /* In unoptimized compilation, we shouldn't call delete_insn
1616 except in jump.c doing warnings. */
1617 PUT_CODE (insn
, NOTE
);
1618 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
1619 NOTE_SOURCE_FILE (insn
) = 0;
1620 if (insn
== last_parm_insn
)
1621 last_parm_insn
= PREV_INSN (next
);
1625 struct fixup_replacement
*replacements
= 0;
1626 rtx next_insn
= NEXT_INSN (insn
);
1628 if (SMALL_REGISTER_CLASSES
)
1630 /* If the insn that copies the results of a CALL_INSN
1631 into a pseudo now references VAR, we have to use an
1632 intermediate pseudo since we want the life of the
1633 return value register to be only a single insn.
1635 If we don't use an intermediate pseudo, such things as
1636 address computations to make the address of VAR valid
1637 if it is not can be placed between the CALL_INSN and INSN.
1639 To make sure this doesn't happen, we record the destination
1640 of the CALL_INSN and see if the next insn uses both that
1643 if (call_dest
!= 0 && GET_CODE (insn
) == INSN
1644 && reg_mentioned_p (var
, PATTERN (insn
))
1645 && reg_mentioned_p (call_dest
, PATTERN (insn
)))
1647 rtx temp
= gen_reg_rtx (GET_MODE (call_dest
));
1649 emit_insn_before (gen_move_insn (temp
, call_dest
), insn
);
1651 PATTERN (insn
) = replace_rtx (PATTERN (insn
),
1655 if (GET_CODE (insn
) == CALL_INSN
1656 && GET_CODE (PATTERN (insn
)) == SET
)
1657 call_dest
= SET_DEST (PATTERN (insn
));
1658 else if (GET_CODE (insn
) == CALL_INSN
1659 && GET_CODE (PATTERN (insn
)) == PARALLEL
1660 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == SET
)
1661 call_dest
= SET_DEST (XVECEXP (PATTERN (insn
), 0, 0));
1666 /* See if we have to do anything to INSN now that VAR is in
1667 memory. If it needs to be loaded into a pseudo, use a single
1668 pseudo for the entire insn in case there is a MATCH_DUP
1669 between two operands. We pass a pointer to the head of
1670 a list of struct fixup_replacements. If fixup_var_refs_1
1671 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1672 it will record them in this list.
1674 If it allocated a pseudo for any replacement, we copy into
1677 fixup_var_refs_1 (var
, promoted_mode
, &PATTERN (insn
), insn
,
1680 /* If this is last_parm_insn, and any instructions were output
1681 after it to fix it up, then we must set last_parm_insn to
1682 the last such instruction emitted. */
1683 if (insn
== last_parm_insn
)
1684 last_parm_insn
= PREV_INSN (next_insn
);
1686 while (replacements
)
1688 if (GET_CODE (replacements
->new) == REG
)
1693 /* OLD might be a (subreg (mem)). */
1694 if (GET_CODE (replacements
->old
) == SUBREG
)
1696 = fixup_memory_subreg (replacements
->old
, insn
, 0);
1699 = fixup_stack_1 (replacements
->old
, insn
);
1701 insert_before
= insn
;
1703 /* If we are changing the mode, do a conversion.
1704 This might be wasteful, but combine.c will
1705 eliminate much of the waste. */
1707 if (GET_MODE (replacements
->new)
1708 != GET_MODE (replacements
->old
))
1711 convert_move (replacements
->new,
1712 replacements
->old
, unsignedp
);
1713 seq
= gen_sequence ();
1717 seq
= gen_move_insn (replacements
->new,
1720 emit_insn_before (seq
, insert_before
);
1723 replacements
= replacements
->next
;
1727 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
1728 But don't touch other insns referred to by reg-notes;
1729 we will get them elsewhere. */
1730 for (note
= REG_NOTES (insn
); note
; note
= XEXP (note
, 1))
1731 if (GET_CODE (note
) != INSN_LIST
)
1733 = walk_fixup_memory_subreg (XEXP (note
, 0), insn
, 1);
1739 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
1740 See if the rtx expression at *LOC in INSN needs to be changed.
1742 REPLACEMENTS is a pointer to a list head that starts out zero, but may
1743 contain a list of original rtx's and replacements. If we find that we need
1744 to modify this insn by replacing a memory reference with a pseudo or by
1745 making a new MEM to implement a SUBREG, we consult that list to see if
1746 we have already chosen a replacement. If none has already been allocated,
1747 we allocate it and update the list. fixup_var_refs_insns will copy VAR
1748 or the SUBREG, as appropriate, to the pseudo. */
1751 fixup_var_refs_1 (var
, promoted_mode
, loc
, insn
, replacements
)
1753 enum machine_mode promoted_mode
;
1756 struct fixup_replacement
**replacements
;
1759 register rtx x
= *loc
;
1760 RTX_CODE code
= GET_CODE (x
);
1762 register rtx tem
, tem1
;
1763 struct fixup_replacement
*replacement
;
1768 if (XEXP (x
, 0) == var
)
1771 *loc
= force_operand (XEXP (var
, 0), NULL_RTX
);
1772 emit_insn_before (gen_sequence (), insn
);
1780 /* If we already have a replacement, use it. Otherwise,
1781 try to fix up this address in case it is invalid. */
1783 replacement
= find_fixup_replacement (replacements
, var
);
1784 if (replacement
->new)
1786 *loc
= replacement
->new;
1790 *loc
= replacement
->new = x
= fixup_stack_1 (x
, insn
);
1792 /* Unless we are forcing memory to register or we changed the mode,
1793 we can leave things the way they are if the insn is valid. */
1795 INSN_CODE (insn
) = -1;
1796 if (! flag_force_mem
&& GET_MODE (x
) == promoted_mode
1797 && recog_memoized (insn
) >= 0)
1800 *loc
= replacement
->new = gen_reg_rtx (promoted_mode
);
1804 /* If X contains VAR, we need to unshare it here so that we update
1805 each occurrence separately. But all identical MEMs in one insn
1806 must be replaced with the same rtx because of the possibility of
1809 if (reg_mentioned_p (var
, x
))
1811 replacement
= find_fixup_replacement (replacements
, x
);
1812 if (replacement
->new == 0)
1813 replacement
->new = copy_most_rtx (x
, var
);
1815 *loc
= x
= replacement
->new;
1831 /* Note that in some cases those types of expressions are altered
1832 by optimize_bit_field, and do not survive to get here. */
1833 if (XEXP (x
, 0) == var
1834 || (GET_CODE (XEXP (x
, 0)) == SUBREG
1835 && SUBREG_REG (XEXP (x
, 0)) == var
))
1837 /* Get TEM as a valid MEM in the mode presently in the insn.
1839 We don't worry about the possibility of MATCH_DUP here; it
1840 is highly unlikely and would be tricky to handle. */
1843 if (GET_CODE (tem
) == SUBREG
)
1845 if (GET_MODE_BITSIZE (GET_MODE (tem
))
1846 > GET_MODE_BITSIZE (GET_MODE (var
)))
1848 replacement
= find_fixup_replacement (replacements
, var
);
1849 if (replacement
->new == 0)
1850 replacement
->new = gen_reg_rtx (GET_MODE (var
));
1851 SUBREG_REG (tem
) = replacement
->new;
1854 tem
= fixup_memory_subreg (tem
, insn
, 0);
1857 tem
= fixup_stack_1 (tem
, insn
);
1859 /* Unless we want to load from memory, get TEM into the proper mode
1860 for an extract from memory. This can only be done if the
1861 extract is at a constant position and length. */
1863 if (! flag_force_mem
&& GET_CODE (XEXP (x
, 1)) == CONST_INT
1864 && GET_CODE (XEXP (x
, 2)) == CONST_INT
1865 && ! mode_dependent_address_p (XEXP (tem
, 0))
1866 && ! MEM_VOLATILE_P (tem
))
1868 enum machine_mode wanted_mode
= VOIDmode
;
1869 enum machine_mode is_mode
= GET_MODE (tem
);
1870 int width
= INTVAL (XEXP (x
, 1));
1871 int pos
= INTVAL (XEXP (x
, 2));
1874 if (GET_CODE (x
) == ZERO_EXTRACT
)
1875 wanted_mode
= insn_operand_mode
[(int) CODE_FOR_extzv
][1];
1878 if (GET_CODE (x
) == SIGN_EXTRACT
)
1879 wanted_mode
= insn_operand_mode
[(int) CODE_FOR_extv
][1];
1881 /* If we have a narrower mode, we can do something. */
1882 if (wanted_mode
!= VOIDmode
1883 && GET_MODE_SIZE (wanted_mode
) < GET_MODE_SIZE (is_mode
))
1885 int offset
= pos
/ BITS_PER_UNIT
;
1886 rtx old_pos
= XEXP (x
, 2);
1889 /* If the bytes and bits are counted differently, we
1890 must adjust the offset. */
1891 if (BYTES_BIG_ENDIAN
!= BITS_BIG_ENDIAN
)
1892 offset
= (GET_MODE_SIZE (is_mode
)
1893 - GET_MODE_SIZE (wanted_mode
) - offset
);
1895 pos
%= GET_MODE_BITSIZE (wanted_mode
);
1897 newmem
= gen_rtx (MEM
, wanted_mode
,
1898 plus_constant (XEXP (tem
, 0), offset
));
1899 RTX_UNCHANGING_P (newmem
) = RTX_UNCHANGING_P (tem
);
1900 MEM_VOLATILE_P (newmem
) = MEM_VOLATILE_P (tem
);
1901 MEM_IN_STRUCT_P (newmem
) = MEM_IN_STRUCT_P (tem
);
1903 /* Make the change and see if the insn remains valid. */
1904 INSN_CODE (insn
) = -1;
1905 XEXP (x
, 0) = newmem
;
1906 XEXP (x
, 2) = GEN_INT (pos
);
1908 if (recog_memoized (insn
) >= 0)
1911 /* Otherwise, restore old position. XEXP (x, 0) will be
1913 XEXP (x
, 2) = old_pos
;
1917 /* If we get here, the bitfield extract insn can't accept a memory
1918 reference. Copy the input into a register. */
1920 tem1
= gen_reg_rtx (GET_MODE (tem
));
1921 emit_insn_before (gen_move_insn (tem1
, tem
), insn
);
1928 if (SUBREG_REG (x
) == var
)
1930 /* If this is a special SUBREG made because VAR was promoted
1931 from a wider mode, replace it with VAR and call ourself
1932 recursively, this time saying that the object previously
1933 had its current mode (by virtue of the SUBREG). */
1935 if (SUBREG_PROMOTED_VAR_P (x
))
1938 fixup_var_refs_1 (var
, GET_MODE (var
), loc
, insn
, replacements
);
1942 /* If this SUBREG makes VAR wider, it has become a paradoxical
1943 SUBREG with VAR in memory, but these aren't allowed at this
1944 stage of the compilation. So load VAR into a pseudo and take
1945 a SUBREG of that pseudo. */
1946 if (GET_MODE_SIZE (GET_MODE (x
)) > GET_MODE_SIZE (GET_MODE (var
)))
1948 replacement
= find_fixup_replacement (replacements
, var
);
1949 if (replacement
->new == 0)
1950 replacement
->new = gen_reg_rtx (GET_MODE (var
));
1951 SUBREG_REG (x
) = replacement
->new;
1955 /* See if we have already found a replacement for this SUBREG.
1956 If so, use it. Otherwise, make a MEM and see if the insn
1957 is recognized. If not, or if we should force MEM into a register,
1958 make a pseudo for this SUBREG. */
1959 replacement
= find_fixup_replacement (replacements
, x
);
1960 if (replacement
->new)
1962 *loc
= replacement
->new;
1966 replacement
->new = *loc
= fixup_memory_subreg (x
, insn
, 0);
1968 INSN_CODE (insn
) = -1;
1969 if (! flag_force_mem
&& recog_memoized (insn
) >= 0)
1972 *loc
= replacement
->new = gen_reg_rtx (GET_MODE (x
));
1978 /* First do special simplification of bit-field references. */
1979 if (GET_CODE (SET_DEST (x
)) == SIGN_EXTRACT
1980 || GET_CODE (SET_DEST (x
)) == ZERO_EXTRACT
)
1981 optimize_bit_field (x
, insn
, 0);
1982 if (GET_CODE (SET_SRC (x
)) == SIGN_EXTRACT
1983 || GET_CODE (SET_SRC (x
)) == ZERO_EXTRACT
)
1984 optimize_bit_field (x
, insn
, NULL_PTR
);
1986 /* For a paradoxical SUBREG inside a ZERO_EXTRACT, load the object
1987 into a register and then store it back out. */
1988 if (GET_CODE (SET_DEST (x
)) == ZERO_EXTRACT
1989 && GET_CODE (XEXP (SET_DEST (x
), 0)) == SUBREG
1990 && SUBREG_REG (XEXP (SET_DEST (x
), 0)) == var
1991 && (GET_MODE_SIZE (GET_MODE (XEXP (SET_DEST (x
), 0)))
1992 > GET_MODE_SIZE (GET_MODE (var
))))
1994 replacement
= find_fixup_replacement (replacements
, var
);
1995 if (replacement
->new == 0)
1996 replacement
->new = gen_reg_rtx (GET_MODE (var
));
1998 SUBREG_REG (XEXP (SET_DEST (x
), 0)) = replacement
->new;
1999 emit_insn_after (gen_move_insn (var
, replacement
->new), insn
);
2002 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
2003 insn into a pseudo and store the low part of the pseudo into VAR. */
2004 if (GET_CODE (SET_DEST (x
)) == SUBREG
2005 && SUBREG_REG (SET_DEST (x
)) == var
2006 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x
)))
2007 > GET_MODE_SIZE (GET_MODE (var
))))
2009 SET_DEST (x
) = tem
= gen_reg_rtx (GET_MODE (SET_DEST (x
)));
2010 emit_insn_after (gen_move_insn (var
, gen_lowpart (GET_MODE (var
),
2017 rtx dest
= SET_DEST (x
);
2018 rtx src
= SET_SRC (x
);
2019 rtx outerdest
= dest
;
2021 while (GET_CODE (dest
) == SUBREG
|| GET_CODE (dest
) == STRICT_LOW_PART
2022 || GET_CODE (dest
) == SIGN_EXTRACT
2023 || GET_CODE (dest
) == ZERO_EXTRACT
)
2024 dest
= XEXP (dest
, 0);
2026 if (GET_CODE (src
) == SUBREG
)
2027 src
= XEXP (src
, 0);
2029 /* If VAR does not appear at the top level of the SET
2030 just scan the lower levels of the tree. */
2032 if (src
!= var
&& dest
!= var
)
2035 /* We will need to rerecognize this insn. */
2036 INSN_CODE (insn
) = -1;
2039 if (GET_CODE (outerdest
) == ZERO_EXTRACT
&& dest
== var
)
2041 /* Since this case will return, ensure we fixup all the
2043 fixup_var_refs_1 (var
, promoted_mode
, &XEXP (outerdest
, 1),
2044 insn
, replacements
);
2045 fixup_var_refs_1 (var
, promoted_mode
, &XEXP (outerdest
, 2),
2046 insn
, replacements
);
2047 fixup_var_refs_1 (var
, promoted_mode
, &SET_SRC (x
),
2048 insn
, replacements
);
2050 tem
= XEXP (outerdest
, 0);
2052 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
2053 that may appear inside a ZERO_EXTRACT.
2054 This was legitimate when the MEM was a REG. */
2055 if (GET_CODE (tem
) == SUBREG
2056 && SUBREG_REG (tem
) == var
)
2057 tem
= fixup_memory_subreg (tem
, insn
, 0);
2059 tem
= fixup_stack_1 (tem
, insn
);
2061 if (GET_CODE (XEXP (outerdest
, 1)) == CONST_INT
2062 && GET_CODE (XEXP (outerdest
, 2)) == CONST_INT
2063 && ! mode_dependent_address_p (XEXP (tem
, 0))
2064 && ! MEM_VOLATILE_P (tem
))
2066 enum machine_mode wanted_mode
2067 = insn_operand_mode
[(int) CODE_FOR_insv
][0];
2068 enum machine_mode is_mode
= GET_MODE (tem
);
2069 int width
= INTVAL (XEXP (outerdest
, 1));
2070 int pos
= INTVAL (XEXP (outerdest
, 2));
2072 /* If we have a narrower mode, we can do something. */
2073 if (GET_MODE_SIZE (wanted_mode
) < GET_MODE_SIZE (is_mode
))
2075 int offset
= pos
/ BITS_PER_UNIT
;
2076 rtx old_pos
= XEXP (outerdest
, 2);
2079 if (BYTES_BIG_ENDIAN
!= BITS_BIG_ENDIAN
)
2080 offset
= (GET_MODE_SIZE (is_mode
)
2081 - GET_MODE_SIZE (wanted_mode
) - offset
);
2083 pos
%= GET_MODE_BITSIZE (wanted_mode
);
2085 newmem
= gen_rtx (MEM
, wanted_mode
,
2086 plus_constant (XEXP (tem
, 0), offset
));
2087 RTX_UNCHANGING_P (newmem
) = RTX_UNCHANGING_P (tem
);
2088 MEM_VOLATILE_P (newmem
) = MEM_VOLATILE_P (tem
);
2089 MEM_IN_STRUCT_P (newmem
) = MEM_IN_STRUCT_P (tem
);
2091 /* Make the change and see if the insn remains valid. */
2092 INSN_CODE (insn
) = -1;
2093 XEXP (outerdest
, 0) = newmem
;
2094 XEXP (outerdest
, 2) = GEN_INT (pos
);
2096 if (recog_memoized (insn
) >= 0)
2099 /* Otherwise, restore old position. XEXP (x, 0) will be
2101 XEXP (outerdest
, 2) = old_pos
;
2105 /* If we get here, the bit-field store doesn't allow memory
2106 or isn't located at a constant position. Load the value into
2107 a register, do the store, and put it back into memory. */
2109 tem1
= gen_reg_rtx (GET_MODE (tem
));
2110 emit_insn_before (gen_move_insn (tem1
, tem
), insn
);
2111 emit_insn_after (gen_move_insn (tem
, tem1
), insn
);
2112 XEXP (outerdest
, 0) = tem1
;
2117 /* STRICT_LOW_PART is a no-op on memory references
2118 and it can cause combinations to be unrecognizable,
2121 if (dest
== var
&& GET_CODE (SET_DEST (x
)) == STRICT_LOW_PART
)
2122 SET_DEST (x
) = XEXP (SET_DEST (x
), 0);
2124 /* A valid insn to copy VAR into or out of a register
2125 must be left alone, to avoid an infinite loop here.
2126 If the reference to VAR is by a subreg, fix that up,
2127 since SUBREG is not valid for a memref.
2128 Also fix up the address of the stack slot.
2130 Note that we must not try to recognize the insn until
2131 after we know that we have valid addresses and no
2132 (subreg (mem ...) ...) constructs, since these interfere
2133 with determining the validity of the insn. */
2135 if ((SET_SRC (x
) == var
2136 || (GET_CODE (SET_SRC (x
)) == SUBREG
2137 && SUBREG_REG (SET_SRC (x
)) == var
))
2138 && (GET_CODE (SET_DEST (x
)) == REG
2139 || (GET_CODE (SET_DEST (x
)) == SUBREG
2140 && GET_CODE (SUBREG_REG (SET_DEST (x
))) == REG
))
2141 && GET_MODE (var
) == promoted_mode
2142 && x
== single_set (insn
))
2146 replacement
= find_fixup_replacement (replacements
, SET_SRC (x
));
2147 if (replacement
->new)
2148 SET_SRC (x
) = replacement
->new;
2149 else if (GET_CODE (SET_SRC (x
)) == SUBREG
)
2150 SET_SRC (x
) = replacement
->new
2151 = fixup_memory_subreg (SET_SRC (x
), insn
, 0);
2153 SET_SRC (x
) = replacement
->new
2154 = fixup_stack_1 (SET_SRC (x
), insn
);
2156 if (recog_memoized (insn
) >= 0)
2159 /* INSN is not valid, but we know that we want to
2160 copy SET_SRC (x) to SET_DEST (x) in some way. So
2161 we generate the move and see whether it requires more
2162 than one insn. If it does, we emit those insns and
2163 delete INSN. Otherwise, we an just replace the pattern
2164 of INSN; we have already verified above that INSN has
2165 no other function that to do X. */
2167 pat
= gen_move_insn (SET_DEST (x
), SET_SRC (x
));
2168 if (GET_CODE (pat
) == SEQUENCE
)
2170 emit_insn_after (pat
, insn
);
2171 PUT_CODE (insn
, NOTE
);
2172 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
2173 NOTE_SOURCE_FILE (insn
) = 0;
2176 PATTERN (insn
) = pat
;
2181 if ((SET_DEST (x
) == var
2182 || (GET_CODE (SET_DEST (x
)) == SUBREG
2183 && SUBREG_REG (SET_DEST (x
)) == var
))
2184 && (GET_CODE (SET_SRC (x
)) == REG
2185 || (GET_CODE (SET_SRC (x
)) == SUBREG
2186 && GET_CODE (SUBREG_REG (SET_SRC (x
))) == REG
))
2187 && GET_MODE (var
) == promoted_mode
2188 && x
== single_set (insn
))
2192 if (GET_CODE (SET_DEST (x
)) == SUBREG
)
2193 SET_DEST (x
) = fixup_memory_subreg (SET_DEST (x
), insn
, 0);
2195 SET_DEST (x
) = fixup_stack_1 (SET_DEST (x
), insn
);
2197 if (recog_memoized (insn
) >= 0)
2200 pat
= gen_move_insn (SET_DEST (x
), SET_SRC (x
));
2201 if (GET_CODE (pat
) == SEQUENCE
)
2203 emit_insn_after (pat
, insn
);
2204 PUT_CODE (insn
, NOTE
);
2205 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
2206 NOTE_SOURCE_FILE (insn
) = 0;
2209 PATTERN (insn
) = pat
;
2214 /* Otherwise, storing into VAR must be handled specially
2215 by storing into a temporary and copying that into VAR
2216 with a new insn after this one. Note that this case
2217 will be used when storing into a promoted scalar since
2218 the insn will now have different modes on the input
2219 and output and hence will be invalid (except for the case
2220 of setting it to a constant, which does not need any
2221 change if it is valid). We generate extra code in that case,
2222 but combine.c will eliminate it. */
2227 rtx fixeddest
= SET_DEST (x
);
2229 /* STRICT_LOW_PART can be discarded, around a MEM. */
2230 if (GET_CODE (fixeddest
) == STRICT_LOW_PART
)
2231 fixeddest
= XEXP (fixeddest
, 0);
2232 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
2233 if (GET_CODE (fixeddest
) == SUBREG
)
2235 fixeddest
= fixup_memory_subreg (fixeddest
, insn
, 0);
2236 promoted_mode
= GET_MODE (fixeddest
);
2239 fixeddest
= fixup_stack_1 (fixeddest
, insn
);
2241 temp
= gen_reg_rtx (promoted_mode
);
2243 emit_insn_after (gen_move_insn (fixeddest
,
2244 gen_lowpart (GET_MODE (fixeddest
),
2248 SET_DEST (x
) = temp
;
2256 /* Nothing special about this RTX; fix its operands. */
2258 fmt
= GET_RTX_FORMAT (code
);
2259 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2262 fixup_var_refs_1 (var
, promoted_mode
, &XEXP (x
, i
), insn
, replacements
);
2266 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2267 fixup_var_refs_1 (var
, promoted_mode
, &XVECEXP (x
, i
, j
),
2268 insn
, replacements
);
2273 /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
2274 return an rtx (MEM:m1 newaddr) which is equivalent.
2275 If any insns must be emitted to compute NEWADDR, put them before INSN.
2277 UNCRITICAL nonzero means accept paradoxical subregs.
2278 This is used for subregs found inside REG_NOTES. */
2281 fixup_memory_subreg (x
, insn
, uncritical
)
2286 int offset
= SUBREG_WORD (x
) * UNITS_PER_WORD
;
2287 rtx addr
= XEXP (SUBREG_REG (x
), 0);
2288 enum machine_mode mode
= GET_MODE (x
);
2291 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
2292 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
)))
2296 if (BYTES_BIG_ENDIAN
)
2297 offset
+= (MIN (UNITS_PER_WORD
, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))))
2298 - MIN (UNITS_PER_WORD
, GET_MODE_SIZE (mode
)));
2299 addr
= plus_constant (addr
, offset
);
2300 if (!flag_force_addr
&& memory_address_p (mode
, addr
))
2301 /* Shortcut if no insns need be emitted. */
2302 return change_address (SUBREG_REG (x
), mode
, addr
);
2304 result
= change_address (SUBREG_REG (x
), mode
, addr
);
2305 emit_insn_before (gen_sequence (), insn
);
2310 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2311 Replace subexpressions of X in place.
2312 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2313 Otherwise return X, with its contents possibly altered.
2315 If any insns must be emitted to compute NEWADDR, put them before INSN.
2317 UNCRITICAL is as in fixup_memory_subreg. */
2320 walk_fixup_memory_subreg (x
, insn
, uncritical
)
2325 register enum rtx_code code
;
2332 code
= GET_CODE (x
);
2334 if (code
== SUBREG
&& GET_CODE (SUBREG_REG (x
)) == MEM
)
2335 return fixup_memory_subreg (x
, insn
, uncritical
);
2337 /* Nothing special about this RTX; fix its operands. */
2339 fmt
= GET_RTX_FORMAT (code
);
2340 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2343 XEXP (x
, i
) = walk_fixup_memory_subreg (XEXP (x
, i
), insn
, uncritical
);
2347 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2349 = walk_fixup_memory_subreg (XVECEXP (x
, i
, j
), insn
, uncritical
);
2355 /* For each memory ref within X, if it refers to a stack slot
2356 with an out of range displacement, put the address in a temp register
2357 (emitting new insns before INSN to load these registers)
2358 and alter the memory ref to use that register.
2359 Replace each such MEM rtx with a copy, to avoid clobberage. */
2362 fixup_stack_1 (x
, insn
)
2367 register RTX_CODE code
= GET_CODE (x
);
2372 register rtx ad
= XEXP (x
, 0);
2373 /* If we have address of a stack slot but it's not valid
2374 (displacement is too large), compute the sum in a register. */
2375 if (GET_CODE (ad
) == PLUS
2376 && GET_CODE (XEXP (ad
, 0)) == REG
2377 && ((REGNO (XEXP (ad
, 0)) >= FIRST_VIRTUAL_REGISTER
2378 && REGNO (XEXP (ad
, 0)) <= LAST_VIRTUAL_REGISTER
)
2379 || REGNO (XEXP (ad
, 0)) == FRAME_POINTER_REGNUM
2380 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2381 || REGNO (XEXP (ad
, 0)) == HARD_FRAME_POINTER_REGNUM
2383 || REGNO (XEXP (ad
, 0)) == STACK_POINTER_REGNUM
2384 || XEXP (ad
, 0) == current_function_internal_arg_pointer
)
2385 && GET_CODE (XEXP (ad
, 1)) == CONST_INT
)
2388 if (memory_address_p (GET_MODE (x
), ad
))
2392 temp
= copy_to_reg (ad
);
2393 seq
= gen_sequence ();
2395 emit_insn_before (seq
, insn
);
2396 return change_address (x
, VOIDmode
, temp
);
2401 fmt
= GET_RTX_FORMAT (code
);
2402 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2405 XEXP (x
, i
) = fixup_stack_1 (XEXP (x
, i
), insn
);
2409 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2410 XVECEXP (x
, i
, j
) = fixup_stack_1 (XVECEXP (x
, i
, j
), insn
);
2416 /* Optimization: a bit-field instruction whose field
2417 happens to be a byte or halfword in memory
2418 can be changed to a move instruction.
2420 We call here when INSN is an insn to examine or store into a bit-field.
2421 BODY is the SET-rtx to be altered.
2423 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2424 (Currently this is called only from function.c, and EQUIV_MEM
2428 optimize_bit_field (body
, insn
, equiv_mem
)
2433 register rtx bitfield
;
2436 enum machine_mode mode
;
2438 if (GET_CODE (SET_DEST (body
)) == SIGN_EXTRACT
2439 || GET_CODE (SET_DEST (body
)) == ZERO_EXTRACT
)
2440 bitfield
= SET_DEST (body
), destflag
= 1;
2442 bitfield
= SET_SRC (body
), destflag
= 0;
2444 /* First check that the field being stored has constant size and position
2445 and is in fact a byte or halfword suitably aligned. */
2447 if (GET_CODE (XEXP (bitfield
, 1)) == CONST_INT
2448 && GET_CODE (XEXP (bitfield
, 2)) == CONST_INT
2449 && ((mode
= mode_for_size (INTVAL (XEXP (bitfield
, 1)), MODE_INT
, 1))
2451 && INTVAL (XEXP (bitfield
, 2)) % INTVAL (XEXP (bitfield
, 1)) == 0)
2453 register rtx memref
= 0;
2455 /* Now check that the containing word is memory, not a register,
2456 and that it is safe to change the machine mode. */
2458 if (GET_CODE (XEXP (bitfield
, 0)) == MEM
)
2459 memref
= XEXP (bitfield
, 0);
2460 else if (GET_CODE (XEXP (bitfield
, 0)) == REG
2462 memref
= equiv_mem
[REGNO (XEXP (bitfield
, 0))];
2463 else if (GET_CODE (XEXP (bitfield
, 0)) == SUBREG
2464 && GET_CODE (SUBREG_REG (XEXP (bitfield
, 0))) == MEM
)
2465 memref
= SUBREG_REG (XEXP (bitfield
, 0));
2466 else if (GET_CODE (XEXP (bitfield
, 0)) == SUBREG
2468 && GET_CODE (SUBREG_REG (XEXP (bitfield
, 0))) == REG
)
2469 memref
= equiv_mem
[REGNO (SUBREG_REG (XEXP (bitfield
, 0)))];
2472 && ! mode_dependent_address_p (XEXP (memref
, 0))
2473 && ! MEM_VOLATILE_P (memref
))
2475 /* Now adjust the address, first for any subreg'ing
2476 that we are now getting rid of,
2477 and then for which byte of the word is wanted. */
2479 register int offset
= INTVAL (XEXP (bitfield
, 2));
2482 /* Adjust OFFSET to count bits from low-address byte. */
2483 if (BITS_BIG_ENDIAN
!= BYTES_BIG_ENDIAN
)
2484 offset
= (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield
, 0)))
2485 - offset
- INTVAL (XEXP (bitfield
, 1)));
2487 /* Adjust OFFSET to count bytes from low-address byte. */
2488 offset
/= BITS_PER_UNIT
;
2489 if (GET_CODE (XEXP (bitfield
, 0)) == SUBREG
)
2491 offset
+= SUBREG_WORD (XEXP (bitfield
, 0)) * UNITS_PER_WORD
;
2492 if (BYTES_BIG_ENDIAN
)
2493 offset
-= (MIN (UNITS_PER_WORD
,
2494 GET_MODE_SIZE (GET_MODE (XEXP (bitfield
, 0))))
2495 - MIN (UNITS_PER_WORD
,
2496 GET_MODE_SIZE (GET_MODE (memref
))));
2500 memref
= change_address (memref
, mode
,
2501 plus_constant (XEXP (memref
, 0), offset
));
2502 insns
= get_insns ();
2504 emit_insns_before (insns
, insn
);
2506 /* Store this memory reference where
2507 we found the bit field reference. */
2511 validate_change (insn
, &SET_DEST (body
), memref
, 1);
2512 if (! CONSTANT_ADDRESS_P (SET_SRC (body
)))
2514 rtx src
= SET_SRC (body
);
2515 while (GET_CODE (src
) == SUBREG
2516 && SUBREG_WORD (src
) == 0)
2517 src
= SUBREG_REG (src
);
2518 if (GET_MODE (src
) != GET_MODE (memref
))
2519 src
= gen_lowpart (GET_MODE (memref
), SET_SRC (body
));
2520 validate_change (insn
, &SET_SRC (body
), src
, 1);
2522 else if (GET_MODE (SET_SRC (body
)) != VOIDmode
2523 && GET_MODE (SET_SRC (body
)) != GET_MODE (memref
))
2524 /* This shouldn't happen because anything that didn't have
2525 one of these modes should have got converted explicitly
2526 and then referenced through a subreg.
2527 This is so because the original bit-field was
2528 handled by agg_mode and so its tree structure had
2529 the same mode that memref now has. */
2534 rtx dest
= SET_DEST (body
);
2536 while (GET_CODE (dest
) == SUBREG
2537 && SUBREG_WORD (dest
) == 0
2538 && (GET_MODE_CLASS (GET_MODE (dest
))
2539 == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest
)))))
2540 dest
= SUBREG_REG (dest
);
2542 validate_change (insn
, &SET_DEST (body
), dest
, 1);
2544 if (GET_MODE (dest
) == GET_MODE (memref
))
2545 validate_change (insn
, &SET_SRC (body
), memref
, 1);
2548 /* Convert the mem ref to the destination mode. */
2549 rtx newreg
= gen_reg_rtx (GET_MODE (dest
));
2552 convert_move (newreg
, memref
,
2553 GET_CODE (SET_SRC (body
)) == ZERO_EXTRACT
);
2557 validate_change (insn
, &SET_SRC (body
), newreg
, 1);
2561 /* See if we can convert this extraction or insertion into
2562 a simple move insn. We might not be able to do so if this
2563 was, for example, part of a PARALLEL.
2565 If we succeed, write out any needed conversions. If we fail,
2566 it is hard to guess why we failed, so don't do anything
2567 special; just let the optimization be suppressed. */
2569 if (apply_change_group () && seq
)
2570 emit_insns_before (seq
, insn
);
2575 /* These routines are responsible for converting virtual register references
2576 to the actual hard register references once RTL generation is complete.
2578 The following four variables are used for communication between the
2579 routines. They contain the offsets of the virtual registers from their
2580 respective hard registers. */
2582 static int in_arg_offset
;
2583 static int var_offset
;
2584 static int dynamic_offset
;
2585 static int out_arg_offset
;
2587 /* In most machines, the stack pointer register is equivalent to the bottom
2590 #ifndef STACK_POINTER_OFFSET
2591 #define STACK_POINTER_OFFSET 0
2594 /* If not defined, pick an appropriate default for the offset of dynamically
2595 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2596 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2598 #ifndef STACK_DYNAMIC_OFFSET
2600 #ifdef ACCUMULATE_OUTGOING_ARGS
2601 /* The bottom of the stack points to the actual arguments. If
2602 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2603 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2604 stack space for register parameters is not pushed by the caller, but
2605 rather part of the fixed stack areas and hence not included in
2606 `current_function_outgoing_args_size'. Nevertheless, we must allow
2607 for it when allocating stack dynamic objects. */
2609 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2610 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2611 (current_function_outgoing_args_size \
2612 + REG_PARM_STACK_SPACE (FNDECL) + (STACK_POINTER_OFFSET))
2615 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2616 (current_function_outgoing_args_size + (STACK_POINTER_OFFSET))
2620 #define STACK_DYNAMIC_OFFSET(FNDECL) STACK_POINTER_OFFSET
2624 /* Build up a (MEM (ADDRESSOF (REG))) rtx for a register REG that just had
2625 its address taken. DECL is the decl for the object stored in the
2626 register, for later use if we do need to force REG into the stack.
2627 REG is overwritten by the MEM like in put_reg_into_stack. */
2630 gen_mem_addressof (reg
, decl
)
2634 tree type
= TREE_TYPE (decl
);
2636 rtx r
= gen_rtx (ADDRESSOF
, Pmode
, gen_reg_rtx (GET_MODE (reg
)));
2637 ADDRESSOF_REGNO (r
) = REGNO (reg
);
2638 SET_ADDRESSOF_DECL (r
, decl
);
2641 PUT_CODE (reg
, MEM
);
2642 PUT_MODE (reg
, DECL_MODE (decl
));
2643 MEM_VOLATILE_P (reg
) = TREE_SIDE_EFFECTS (decl
);
2644 MEM_IN_STRUCT_P (reg
) = AGGREGATE_TYPE_P (type
);
2646 fixup_var_refs (reg
, GET_MODE (reg
), TREE_UNSIGNED (type
));
2650 /* If DECL has an RTL that is an ADDRESSOF rtx, put it into the stack. */
2653 flush_addressof (decl
)
2656 if ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
2657 && DECL_RTL (decl
) != 0
2658 && GET_CODE (DECL_RTL (decl
)) == MEM
2659 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == ADDRESSOF
2660 && GET_CODE (XEXP (XEXP (DECL_RTL (decl
), 0), 0)) == REG
)
2661 put_addressof_into_stack (XEXP (DECL_RTL (decl
), 0));
2664 /* Force the register pointed to by R, an ADDRESSOF rtx, into the stack. */
2667 put_addressof_into_stack (r
)
2670 tree decl
= ADDRESSOF_DECL (r
);
2671 rtx reg
= XEXP (r
, 0);
2673 if (GET_CODE (reg
) != REG
)
2676 put_reg_into_stack (0, reg
, TREE_TYPE (decl
), GET_MODE (reg
),
2677 DECL_MODE (decl
), TREE_SIDE_EFFECTS (decl
),
2678 ADDRESSOF_REGNO (r
));
2681 /* Helper function for purge_addressof. See if the rtx expression at *LOC
2682 in INSN needs to be changed. If FORCE, always put any ADDRESSOFs into
2686 purge_addressof_1 (loc
, insn
, force
)
2696 /* Re-start here to avoid recursion in common cases. */
2703 code
= GET_CODE (x
);
2705 if (code
== ADDRESSOF
&& GET_CODE (XEXP (x
, 0)) == MEM
)
2709 if (validate_change (insn
, loc
, XEXP (XEXP (x
, 0), 0), 0))
2713 if (! validate_change (insn
, loc
,
2714 force_operand (XEXP (XEXP (x
, 0), 0), NULL_RTX
),
2718 insns
= get_insns ();
2720 emit_insns_before (insns
, insn
);
2723 else if (code
== MEM
&& GET_CODE (XEXP (x
, 0)) == ADDRESSOF
&& ! force
)
2725 rtx sub
= XEXP (XEXP (x
, 0), 0);
2726 if (GET_CODE (sub
) == REG
&& GET_MODE (x
) != GET_MODE (sub
))
2728 if (! BYTES_BIG_ENDIAN
&& ! WORDS_BIG_ENDIAN
)
2730 rtx sub2
= gen_rtx (SUBREG
, GET_MODE (x
), sub
, 0);
2731 if (validate_change (insn
, loc
, sub2
, 0))
2735 else if (validate_change (insn
, loc
, sub
, 0))
2737 /* else give up and put it into the stack */
2739 else if (code
== ADDRESSOF
)
2741 put_addressof_into_stack (x
);
2745 /* Scan all subexpressions. */
2746 fmt
= GET_RTX_FORMAT (code
);
2747 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
2750 purge_addressof_1 (&XEXP (x
, i
), insn
, force
);
2751 else if (*fmt
== 'E')
2752 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2753 purge_addressof_1 (&XVECEXP (x
, i
, j
), insn
, force
);
2757 /* Eliminate all occurrences of ADDRESSOF from INSNS. Elide any remaining
2758 (MEM (ADDRESSOF)) patterns, and force any needed registers into the
2762 purge_addressof (insns
)
2766 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
2767 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == JUMP_INSN
2768 || GET_CODE (insn
) == CALL_INSN
)
2770 purge_addressof_1 (&PATTERN (insn
), insn
,
2771 asm_noperands (PATTERN (insn
)) > 0);
2772 purge_addressof_1 (®_NOTES (insn
), NULL_RTX
, 0);
2776 /* Pass through the INSNS of function FNDECL and convert virtual register
2777 references to hard register references. */
2780 instantiate_virtual_regs (fndecl
, insns
)
2787 /* Compute the offsets to use for this function. */
2788 in_arg_offset
= FIRST_PARM_OFFSET (fndecl
);
2789 var_offset
= STARTING_FRAME_OFFSET
;
2790 dynamic_offset
= STACK_DYNAMIC_OFFSET (fndecl
);
2791 out_arg_offset
= STACK_POINTER_OFFSET
;
2793 /* Scan all variables and parameters of this function. For each that is
2794 in memory, instantiate all virtual registers if the result is a valid
2795 address. If not, we do it later. That will handle most uses of virtual
2796 regs on many machines. */
2797 instantiate_decls (fndecl
, 1);
2799 /* Initialize recognition, indicating that volatile is OK. */
2802 /* Scan through all the insns, instantiating every virtual register still
2804 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
2805 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == JUMP_INSN
2806 || GET_CODE (insn
) == CALL_INSN
)
2808 instantiate_virtual_regs_1 (&PATTERN (insn
), insn
, 1);
2809 instantiate_virtual_regs_1 (®_NOTES (insn
), NULL_RTX
, 0);
2812 /* Instantiate the stack slots for the parm registers, for later use in
2813 addressof elimination. */
2814 for (i
= 0; i
< max_parm_reg
; ++i
)
2815 if (parm_reg_stack_loc
[i
])
2816 instantiate_virtual_regs_1 (&parm_reg_stack_loc
[i
], NULL_RTX
, 0);
2818 /* Now instantiate the remaining register equivalences for debugging info.
2819 These will not be valid addresses. */
2820 instantiate_decls (fndecl
, 0);
2822 /* Indicate that, from now on, assign_stack_local should use
2823 frame_pointer_rtx. */
2824 virtuals_instantiated
= 1;
2827 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
2828 all virtual registers in their DECL_RTL's.
2830 If VALID_ONLY, do this only if the resulting address is still valid.
2831 Otherwise, always do it. */
2834 instantiate_decls (fndecl
, valid_only
)
2840 if (DECL_SAVED_INSNS (fndecl
))
2841 /* When compiling an inline function, the obstack used for
2842 rtl allocation is the maybepermanent_obstack. Calling
2843 `resume_temporary_allocation' switches us back to that
2844 obstack while we process this function's parameters. */
2845 resume_temporary_allocation ();
2847 /* Process all parameters of the function. */
2848 for (decl
= DECL_ARGUMENTS (fndecl
); decl
; decl
= TREE_CHAIN (decl
))
2850 int size
= int_size_in_bytes (TREE_TYPE (decl
));
2851 instantiate_decl (DECL_RTL (decl
), size
, valid_only
);
2853 /* If the parameter was promoted, then the incoming RTL mode may be
2854 larger than the declared type size. We must use the larger of
2856 size
= MAX (GET_MODE_SIZE (GET_MODE (DECL_INCOMING_RTL (decl
))), size
);
2857 instantiate_decl (DECL_INCOMING_RTL (decl
), size
, valid_only
);
2860 /* Now process all variables defined in the function or its subblocks. */
2861 instantiate_decls_1 (DECL_INITIAL (fndecl
), valid_only
);
2863 if (DECL_INLINE (fndecl
) || DECL_DEFER_OUTPUT (fndecl
))
2865 /* Save all rtl allocated for this function by raising the
2866 high-water mark on the maybepermanent_obstack. */
2868 /* All further rtl allocation is now done in the current_obstack. */
2869 rtl_in_current_obstack ();
2873 /* Subroutine of instantiate_decls: Process all decls in the given
2874 BLOCK node and all its subblocks. */
2877 instantiate_decls_1 (let
, valid_only
)
2883 for (t
= BLOCK_VARS (let
); t
; t
= TREE_CHAIN (t
))
2884 instantiate_decl (DECL_RTL (t
), int_size_in_bytes (TREE_TYPE (t
)),
2887 /* Process all subblocks. */
2888 for (t
= BLOCK_SUBBLOCKS (let
); t
; t
= TREE_CHAIN (t
))
2889 instantiate_decls_1 (t
, valid_only
);
2892 /* Subroutine of the preceding procedures: Given RTL representing a
2893 decl and the size of the object, do any instantiation required.
2895 If VALID_ONLY is non-zero, it means that the RTL should only be
2896 changed if the new address is valid. */
2899 instantiate_decl (x
, size
, valid_only
)
2904 enum machine_mode mode
;
2907 /* If this is not a MEM, no need to do anything. Similarly if the
2908 address is a constant or a register that is not a virtual register. */
2910 if (x
== 0 || GET_CODE (x
) != MEM
)
2914 if (CONSTANT_P (addr
)
2915 || GET_CODE (addr
) == ADDRESSOF
2916 || (GET_CODE (addr
) == REG
2917 && (REGNO (addr
) < FIRST_VIRTUAL_REGISTER
2918 || REGNO (addr
) > LAST_VIRTUAL_REGISTER
)))
2921 /* If we should only do this if the address is valid, copy the address.
2922 We need to do this so we can undo any changes that might make the
2923 address invalid. This copy is unfortunate, but probably can't be
2927 addr
= copy_rtx (addr
);
2929 instantiate_virtual_regs_1 (&addr
, NULL_RTX
, 0);
2933 /* Now verify that the resulting address is valid for every integer or
2934 floating-point mode up to and including SIZE bytes long. We do this
2935 since the object might be accessed in any mode and frame addresses
2938 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
2939 mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) <= size
;
2940 mode
= GET_MODE_WIDER_MODE (mode
))
2941 if (! memory_address_p (mode
, addr
))
2944 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
);
2945 mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) <= size
;
2946 mode
= GET_MODE_WIDER_MODE (mode
))
2947 if (! memory_address_p (mode
, addr
))
2951 /* Put back the address now that we have updated it and we either know
2952 it is valid or we don't care whether it is valid. */
2957 /* Given a pointer to a piece of rtx and an optional pointer to the
2958 containing object, instantiate any virtual registers present in it.
2960 If EXTRA_INSNS, we always do the replacement and generate
2961 any extra insns before OBJECT. If it zero, we do nothing if replacement
2964 Return 1 if we either had nothing to do or if we were able to do the
2965 needed replacement. Return 0 otherwise; we only return zero if
2966 EXTRA_INSNS is zero.
2968 We first try some simple transformations to avoid the creation of extra
2972 instantiate_virtual_regs_1 (loc
, object
, extra_insns
)
2986 /* Re-start here to avoid recursion in common cases. */
2993 code
= GET_CODE (x
);
2995 /* Check for some special cases. */
3012 /* We are allowed to set the virtual registers. This means that
3013 that the actual register should receive the source minus the
3014 appropriate offset. This is used, for example, in the handling
3015 of non-local gotos. */
3016 if (SET_DEST (x
) == virtual_incoming_args_rtx
)
3017 new = arg_pointer_rtx
, offset
= - in_arg_offset
;
3018 else if (SET_DEST (x
) == virtual_stack_vars_rtx
)
3019 new = frame_pointer_rtx
, offset
= - var_offset
;
3020 else if (SET_DEST (x
) == virtual_stack_dynamic_rtx
)
3021 new = stack_pointer_rtx
, offset
= - dynamic_offset
;
3022 else if (SET_DEST (x
) == virtual_outgoing_args_rtx
)
3023 new = stack_pointer_rtx
, offset
= - out_arg_offset
;
3027 /* The only valid sources here are PLUS or REG. Just do
3028 the simplest possible thing to handle them. */
3029 if (GET_CODE (SET_SRC (x
)) != REG
3030 && GET_CODE (SET_SRC (x
)) != PLUS
)
3034 if (GET_CODE (SET_SRC (x
)) != REG
)
3035 temp
= force_operand (SET_SRC (x
), NULL_RTX
);
3038 temp
= force_operand (plus_constant (temp
, offset
), NULL_RTX
);
3042 emit_insns_before (seq
, object
);
3045 if (! validate_change (object
, &SET_SRC (x
), temp
, 0)
3052 instantiate_virtual_regs_1 (&SET_DEST (x
), object
, extra_insns
);
3057 /* Handle special case of virtual register plus constant. */
3058 if (CONSTANT_P (XEXP (x
, 1)))
3060 rtx old
, new_offset
;
3062 /* Check for (plus (plus VIRT foo) (const_int)) first. */
3063 if (GET_CODE (XEXP (x
, 0)) == PLUS
)
3065 rtx inner
= XEXP (XEXP (x
, 0), 0);
3067 if (inner
== virtual_incoming_args_rtx
)
3068 new = arg_pointer_rtx
, offset
= in_arg_offset
;
3069 else if (inner
== virtual_stack_vars_rtx
)
3070 new = frame_pointer_rtx
, offset
= var_offset
;
3071 else if (inner
== virtual_stack_dynamic_rtx
)
3072 new = stack_pointer_rtx
, offset
= dynamic_offset
;
3073 else if (inner
== virtual_outgoing_args_rtx
)
3074 new = stack_pointer_rtx
, offset
= out_arg_offset
;
3081 instantiate_virtual_regs_1 (&XEXP (XEXP (x
, 0), 1), object
,
3083 new = gen_rtx (PLUS
, Pmode
, new, XEXP (XEXP (x
, 0), 1));
3086 else if (XEXP (x
, 0) == virtual_incoming_args_rtx
)
3087 new = arg_pointer_rtx
, offset
= in_arg_offset
;
3088 else if (XEXP (x
, 0) == virtual_stack_vars_rtx
)
3089 new = frame_pointer_rtx
, offset
= var_offset
;
3090 else if (XEXP (x
, 0) == virtual_stack_dynamic_rtx
)
3091 new = stack_pointer_rtx
, offset
= dynamic_offset
;
3092 else if (XEXP (x
, 0) == virtual_outgoing_args_rtx
)
3093 new = stack_pointer_rtx
, offset
= out_arg_offset
;
3096 /* We know the second operand is a constant. Unless the
3097 first operand is a REG (which has been already checked),
3098 it needs to be checked. */
3099 if (GET_CODE (XEXP (x
, 0)) != REG
)
3107 new_offset
= plus_constant (XEXP (x
, 1), offset
);
3109 /* If the new constant is zero, try to replace the sum with just
3111 if (new_offset
== const0_rtx
3112 && validate_change (object
, loc
, new, 0))
3115 /* Next try to replace the register and new offset.
3116 There are two changes to validate here and we can't assume that
3117 in the case of old offset equals new just changing the register
3118 will yield a valid insn. In the interests of a little efficiency,
3119 however, we only call validate change once (we don't queue up the
3120 changes and then call apply_change_group). */
3124 ? ! validate_change (object
, &XEXP (x
, 0), new, 0)
3125 : (XEXP (x
, 0) = new,
3126 ! validate_change (object
, &XEXP (x
, 1), new_offset
, 0)))
3134 /* Otherwise copy the new constant into a register and replace
3135 constant with that register. */
3136 temp
= gen_reg_rtx (Pmode
);
3138 if (validate_change (object
, &XEXP (x
, 1), temp
, 0))
3139 emit_insn_before (gen_move_insn (temp
, new_offset
), object
);
3142 /* If that didn't work, replace this expression with a
3143 register containing the sum. */
3146 new = gen_rtx (PLUS
, Pmode
, new, new_offset
);
3149 temp
= force_operand (new, NULL_RTX
);
3153 emit_insns_before (seq
, object
);
3154 if (! validate_change (object
, loc
, temp
, 0)
3155 && ! validate_replace_rtx (x
, temp
, object
))
3163 /* Fall through to generic two-operand expression case. */
3169 case DIV
: case UDIV
:
3170 case MOD
: case UMOD
:
3171 case AND
: case IOR
: case XOR
:
3172 case ROTATERT
: case ROTATE
:
3173 case ASHIFTRT
: case LSHIFTRT
: case ASHIFT
:
3175 case GE
: case GT
: case GEU
: case GTU
:
3176 case LE
: case LT
: case LEU
: case LTU
:
3177 if (XEXP (x
, 1) && ! CONSTANT_P (XEXP (x
, 1)))
3178 instantiate_virtual_regs_1 (&XEXP (x
, 1), object
, extra_insns
);
3183 /* Most cases of MEM that convert to valid addresses have already been
3184 handled by our scan of decls. The only special handling we
3185 need here is to make a copy of the rtx to ensure it isn't being
3186 shared if we have to change it to a pseudo.
3188 If the rtx is a simple reference to an address via a virtual register,
3189 it can potentially be shared. In such cases, first try to make it
3190 a valid address, which can also be shared. Otherwise, copy it and
3193 First check for common cases that need no processing. These are
3194 usually due to instantiation already being done on a previous instance
3198 if (CONSTANT_ADDRESS_P (temp
)
3199 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3200 || temp
== arg_pointer_rtx
3202 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3203 || temp
== hard_frame_pointer_rtx
3205 || temp
== frame_pointer_rtx
)
3208 if (GET_CODE (temp
) == PLUS
3209 && CONSTANT_ADDRESS_P (XEXP (temp
, 1))
3210 && (XEXP (temp
, 0) == frame_pointer_rtx
3211 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3212 || XEXP (temp
, 0) == hard_frame_pointer_rtx
3214 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3215 || XEXP (temp
, 0) == arg_pointer_rtx
3220 if (temp
== virtual_stack_vars_rtx
3221 || temp
== virtual_incoming_args_rtx
3222 || (GET_CODE (temp
) == PLUS
3223 && CONSTANT_ADDRESS_P (XEXP (temp
, 1))
3224 && (XEXP (temp
, 0) == virtual_stack_vars_rtx
3225 || XEXP (temp
, 0) == virtual_incoming_args_rtx
)))
3227 /* This MEM may be shared. If the substitution can be done without
3228 the need to generate new pseudos, we want to do it in place
3229 so all copies of the shared rtx benefit. The call below will
3230 only make substitutions if the resulting address is still
3233 Note that we cannot pass X as the object in the recursive call
3234 since the insn being processed may not allow all valid
3235 addresses. However, if we were not passed on object, we can
3236 only modify X without copying it if X will have a valid
3239 ??? Also note that this can still lose if OBJECT is an insn that
3240 has less restrictions on an address that some other insn.
3241 In that case, we will modify the shared address. This case
3242 doesn't seem very likely, though. One case where this could
3243 happen is in the case of a USE or CLOBBER reference, but we
3244 take care of that below. */
3246 if (instantiate_virtual_regs_1 (&XEXP (x
, 0),
3247 object
? object
: x
, 0))
3250 /* Otherwise make a copy and process that copy. We copy the entire
3251 RTL expression since it might be a PLUS which could also be
3253 *loc
= x
= copy_rtx (x
);
3256 /* Fall through to generic unary operation case. */
3258 case STRICT_LOW_PART
:
3260 case PRE_DEC
: case PRE_INC
: case POST_DEC
: case POST_INC
:
3261 case SIGN_EXTEND
: case ZERO_EXTEND
:
3262 case TRUNCATE
: case FLOAT_EXTEND
: case FLOAT_TRUNCATE
:
3263 case FLOAT
: case FIX
:
3264 case UNSIGNED_FIX
: case UNSIGNED_FLOAT
:
3268 /* These case either have just one operand or we know that we need not
3269 check the rest of the operands. */
3275 /* If the operand is a MEM, see if the change is a valid MEM. If not,
3276 go ahead and make the invalid one, but do it to a copy. For a REG,
3277 just make the recursive call, since there's no chance of a problem. */
3279 if ((GET_CODE (XEXP (x
, 0)) == MEM
3280 && instantiate_virtual_regs_1 (&XEXP (XEXP (x
, 0), 0), XEXP (x
, 0),
3282 || (GET_CODE (XEXP (x
, 0)) == REG
3283 && instantiate_virtual_regs_1 (&XEXP (x
, 0), object
, 0)))
3286 XEXP (x
, 0) = copy_rtx (XEXP (x
, 0));
3291 /* Try to replace with a PLUS. If that doesn't work, compute the sum
3292 in front of this insn and substitute the temporary. */
3293 if (x
== virtual_incoming_args_rtx
)
3294 new = arg_pointer_rtx
, offset
= in_arg_offset
;
3295 else if (x
== virtual_stack_vars_rtx
)
3296 new = frame_pointer_rtx
, offset
= var_offset
;
3297 else if (x
== virtual_stack_dynamic_rtx
)
3298 new = stack_pointer_rtx
, offset
= dynamic_offset
;
3299 else if (x
== virtual_outgoing_args_rtx
)
3300 new = stack_pointer_rtx
, offset
= out_arg_offset
;
3304 temp
= plus_constant (new, offset
);
3305 if (!validate_change (object
, loc
, temp
, 0))
3311 temp
= force_operand (temp
, NULL_RTX
);
3315 emit_insns_before (seq
, object
);
3316 if (! validate_change (object
, loc
, temp
, 0)
3317 && ! validate_replace_rtx (x
, temp
, object
))
3325 if (GET_CODE (XEXP (x
, 0)) == REG
)
3328 else if (GET_CODE (XEXP (x
, 0)) == MEM
)
3330 /* If we have a (addressof (mem ..)), do any instantiation inside
3331 since we know we'll be making the inside valid when we finally
3332 remove the ADDRESSOF. */
3333 instantiate_virtual_regs_1 (&XEXP (XEXP (x
, 0), 0), NULL_RTX
, 0);
3342 /* Scan all subexpressions. */
3343 fmt
= GET_RTX_FORMAT (code
);
3344 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
3347 if (!instantiate_virtual_regs_1 (&XEXP (x
, i
), object
, extra_insns
))
3350 else if (*fmt
== 'E')
3351 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3352 if (! instantiate_virtual_regs_1 (&XVECEXP (x
, i
, j
), object
,
3359 /* Optimization: assuming this function does not receive nonlocal gotos,
3360 delete the handlers for such, as well as the insns to establish
3361 and disestablish them. */
3367 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3369 /* Delete the handler by turning off the flag that would
3370 prevent jump_optimize from deleting it.
3371 Also permit deletion of the nonlocal labels themselves
3372 if nothing local refers to them. */
3373 if (GET_CODE (insn
) == CODE_LABEL
)
3377 LABEL_PRESERVE_P (insn
) = 0;
3379 /* Remove it from the nonlocal_label list, to avoid confusing
3381 for (t
= nonlocal_labels
, last_t
= 0; t
;
3382 last_t
= t
, t
= TREE_CHAIN (t
))
3383 if (DECL_RTL (TREE_VALUE (t
)) == insn
)
3388 nonlocal_labels
= TREE_CHAIN (nonlocal_labels
);
3390 TREE_CHAIN (last_t
) = TREE_CHAIN (t
);
3393 if (GET_CODE (insn
) == INSN
3394 && ((nonlocal_goto_handler_slot
!= 0
3395 && reg_mentioned_p (nonlocal_goto_handler_slot
, PATTERN (insn
)))
3396 || (nonlocal_goto_stack_level
!= 0
3397 && reg_mentioned_p (nonlocal_goto_stack_level
,
3403 /* Return a list (chain of EXPR_LIST nodes) for the nonlocal labels
3404 of the current function. */
3407 nonlocal_label_rtx_list ()
3412 for (t
= nonlocal_labels
; t
; t
= TREE_CHAIN (t
))
3413 x
= gen_rtx (EXPR_LIST
, VOIDmode
, label_rtx (TREE_VALUE (t
)), x
);
3418 /* Output a USE for any register use in RTL.
3419 This is used with -noreg to mark the extent of lifespan
3420 of any registers used in a user-visible variable's DECL_RTL. */
3426 if (GET_CODE (rtl
) == REG
)
3427 /* This is a register variable. */
3428 emit_insn (gen_rtx (USE
, VOIDmode
, rtl
));
3429 else if (GET_CODE (rtl
) == MEM
3430 && GET_CODE (XEXP (rtl
, 0)) == REG
3431 && (REGNO (XEXP (rtl
, 0)) < FIRST_VIRTUAL_REGISTER
3432 || REGNO (XEXP (rtl
, 0)) > LAST_VIRTUAL_REGISTER
)
3433 && XEXP (rtl
, 0) != current_function_internal_arg_pointer
)
3434 /* This is a variable-sized structure. */
3435 emit_insn (gen_rtx (USE
, VOIDmode
, XEXP (rtl
, 0)));
3438 /* Like use_variable except that it outputs the USEs after INSN
3439 instead of at the end of the insn-chain. */
3442 use_variable_after (rtl
, insn
)
3445 if (GET_CODE (rtl
) == REG
)
3446 /* This is a register variable. */
3447 emit_insn_after (gen_rtx (USE
, VOIDmode
, rtl
), insn
);
3448 else if (GET_CODE (rtl
) == MEM
3449 && GET_CODE (XEXP (rtl
, 0)) == REG
3450 && (REGNO (XEXP (rtl
, 0)) < FIRST_VIRTUAL_REGISTER
3451 || REGNO (XEXP (rtl
, 0)) > LAST_VIRTUAL_REGISTER
)
3452 && XEXP (rtl
, 0) != current_function_internal_arg_pointer
)
3453 /* This is a variable-sized structure. */
3454 emit_insn_after (gen_rtx (USE
, VOIDmode
, XEXP (rtl
, 0)), insn
);
3460 return max_parm_reg
;
3463 /* Return the first insn following those generated by `assign_parms'. */
3466 get_first_nonparm_insn ()
3469 return NEXT_INSN (last_parm_insn
);
3470 return get_insns ();
3473 /* Return the first NOTE_INSN_BLOCK_BEG note in the function.
3474 Crash if there is none. */
3477 get_first_block_beg ()
3479 register rtx searcher
;
3480 register rtx insn
= get_first_nonparm_insn ();
3482 for (searcher
= insn
; searcher
; searcher
= NEXT_INSN (searcher
))
3483 if (GET_CODE (searcher
) == NOTE
3484 && NOTE_LINE_NUMBER (searcher
) == NOTE_INSN_BLOCK_BEG
)
3487 abort (); /* Invalid call to this function. (See comments above.) */
3491 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
3492 This means a type for which function calls must pass an address to the
3493 function or get an address back from the function.
3494 EXP may be a type node or an expression (whose type is tested). */
3497 aggregate_value_p (exp
)
3500 int i
, regno
, nregs
;
3503 if (TREE_CODE_CLASS (TREE_CODE (exp
)) == 't')
3506 type
= TREE_TYPE (exp
);
3508 if (RETURN_IN_MEMORY (type
))
3510 /* Types that are TREE_ADDRESSABLE must be contructed in memory,
3511 and thus can't be returned in registers. */
3512 if (TREE_ADDRESSABLE (type
))
3514 if (flag_pcc_struct_return
&& AGGREGATE_TYPE_P (type
))
3516 /* Make sure we have suitable call-clobbered regs to return
3517 the value in; if not, we must return it in memory. */
3518 reg
= hard_function_value (type
, 0);
3520 /* If we have something other than a REG (e.g. a PARALLEL), then assume
3522 if (GET_CODE (reg
) != REG
)
3525 regno
= REGNO (reg
);
3526 nregs
= HARD_REGNO_NREGS (regno
, TYPE_MODE (type
));
3527 for (i
= 0; i
< nregs
; i
++)
3528 if (! call_used_regs
[regno
+ i
])
3533 /* Assign RTL expressions to the function's parameters.
3534 This may involve copying them into registers and using
3535 those registers as the RTL for them.
3537 If SECOND_TIME is non-zero it means that this function is being
3538 called a second time. This is done by integrate.c when a function's
3539 compilation is deferred. We need to come back here in case the
3540 FUNCTION_ARG macro computes items needed for the rest of the compilation
3541 (such as changing which registers are fixed or caller-saved). But suppress
3542 writing any insns or setting DECL_RTL of anything in this case. */
3545 assign_parms (fndecl
, second_time
)
3550 register rtx entry_parm
= 0;
3551 register rtx stack_parm
= 0;
3552 CUMULATIVE_ARGS args_so_far
;
3553 enum machine_mode promoted_mode
, passed_mode
;
3554 enum machine_mode nominal_mode
, promoted_nominal_mode
;
3556 /* Total space needed so far for args on the stack,
3557 given as a constant and a tree-expression. */
3558 struct args_size stack_args_size
;
3559 tree fntype
= TREE_TYPE (fndecl
);
3560 tree fnargs
= DECL_ARGUMENTS (fndecl
);
3561 /* This is used for the arg pointer when referring to stack args. */
3562 rtx internal_arg_pointer
;
3563 /* This is a dummy PARM_DECL that we used for the function result if
3564 the function returns a structure. */
3565 tree function_result_decl
= 0;
3566 int varargs_setup
= 0;
3567 rtx conversion_insns
= 0;
3569 /* Nonzero if the last arg is named `__builtin_va_alist',
3570 which is used on some machines for old-fashioned non-ANSI varargs.h;
3571 this should be stuck onto the stack as if it had arrived there. */
3573 = (current_function_varargs
3575 && (parm
= tree_last (fnargs
)) != 0
3577 && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
3578 "__builtin_va_alist")));
3580 /* Nonzero if function takes extra anonymous args.
3581 This means the last named arg must be on the stack
3582 right before the anonymous ones. */
3584 = (TYPE_ARG_TYPES (fntype
) != 0
3585 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype
)))
3586 != void_type_node
));
3588 current_function_stdarg
= stdarg
;
3590 /* If the reg that the virtual arg pointer will be translated into is
3591 not a fixed reg or is the stack pointer, make a copy of the virtual
3592 arg pointer, and address parms via the copy. The frame pointer is
3593 considered fixed even though it is not marked as such.
3595 The second time through, simply use ap to avoid generating rtx. */
3597 if ((ARG_POINTER_REGNUM
== STACK_POINTER_REGNUM
3598 || ! (fixed_regs
[ARG_POINTER_REGNUM
]
3599 || ARG_POINTER_REGNUM
== FRAME_POINTER_REGNUM
))
3601 internal_arg_pointer
= copy_to_reg (virtual_incoming_args_rtx
);
3603 internal_arg_pointer
= virtual_incoming_args_rtx
;
3604 current_function_internal_arg_pointer
= internal_arg_pointer
;
3606 stack_args_size
.constant
= 0;
3607 stack_args_size
.var
= 0;
3609 /* If struct value address is treated as the first argument, make it so. */
3610 if (aggregate_value_p (DECL_RESULT (fndecl
))
3611 && ! current_function_returns_pcc_struct
3612 && struct_value_incoming_rtx
== 0)
3614 tree type
= build_pointer_type (TREE_TYPE (fntype
));
3616 function_result_decl
= build_decl (PARM_DECL
, NULL_TREE
, type
);
3618 DECL_ARG_TYPE (function_result_decl
) = type
;
3619 TREE_CHAIN (function_result_decl
) = fnargs
;
3620 fnargs
= function_result_decl
;
3623 max_parm_reg
= LAST_VIRTUAL_REGISTER
+ 1;
3624 parm_reg_stack_loc
= (rtx
*) savealloc (max_parm_reg
* sizeof (rtx
));
3625 bzero ((char *) parm_reg_stack_loc
, max_parm_reg
* sizeof (rtx
));
3627 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
3628 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far
, fntype
, NULL_RTX
);
3630 INIT_CUMULATIVE_ARGS (args_so_far
, fntype
, NULL_RTX
, 0);
3633 /* We haven't yet found an argument that we must push and pretend the
3635 current_function_pretend_args_size
= 0;
3637 for (parm
= fnargs
; parm
; parm
= TREE_CHAIN (parm
))
3639 int aggregate
= AGGREGATE_TYPE_P (TREE_TYPE (parm
));
3640 struct args_size stack_offset
;
3641 struct args_size arg_size
;
3642 int passed_pointer
= 0;
3643 int did_conversion
= 0;
3644 tree passed_type
= DECL_ARG_TYPE (parm
);
3645 tree nominal_type
= TREE_TYPE (parm
);
3647 /* Set LAST_NAMED if this is last named arg before some
3648 anonymous args. We treat it as if it were anonymous too. */
3649 int last_named
= ((TREE_CHAIN (parm
) == 0
3650 || DECL_NAME (TREE_CHAIN (parm
)) == 0)
3651 && (stdarg
|| current_function_varargs
));
3653 if (TREE_TYPE (parm
) == error_mark_node
3654 /* This can happen after weird syntax errors
3655 or if an enum type is defined among the parms. */
3656 || TREE_CODE (parm
) != PARM_DECL
3657 || passed_type
== NULL
)
3659 DECL_INCOMING_RTL (parm
) = DECL_RTL (parm
) = gen_rtx (MEM
, BLKmode
,
3661 TREE_USED (parm
) = 1;
3665 /* For varargs.h function, save info about regs and stack space
3666 used by the individual args, not including the va_alist arg. */
3667 if (hide_last_arg
&& last_named
)
3668 current_function_args_info
= args_so_far
;
3670 /* Find mode of arg as it is passed, and mode of arg
3671 as it should be during execution of this function. */
3672 passed_mode
= TYPE_MODE (passed_type
);
3673 nominal_mode
= TYPE_MODE (nominal_type
);
3675 /* If the parm's mode is VOID, its value doesn't matter,
3676 and avoid the usual things like emit_move_insn that could crash. */
3677 if (nominal_mode
== VOIDmode
)
3679 DECL_INCOMING_RTL (parm
) = DECL_RTL (parm
) = const0_rtx
;
3683 /* If the parm is to be passed as a transparent union, use the
3684 type of the first field for the tests below. We have already
3685 verified that the modes are the same. */
3686 if (DECL_TRANSPARENT_UNION (parm
)
3687 || TYPE_TRANSPARENT_UNION (passed_type
))
3688 passed_type
= TREE_TYPE (TYPE_FIELDS (passed_type
));
3690 /* See if this arg was passed by invisible reference. It is if
3691 it is an object whose size depends on the contents of the
3692 object itself or if the machine requires these objects be passed
3695 if ((TREE_CODE (TYPE_SIZE (passed_type
)) != INTEGER_CST
3696 && contains_placeholder_p (TYPE_SIZE (passed_type
)))
3697 || TREE_ADDRESSABLE (passed_type
)
3698 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
3699 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far
, passed_mode
,
3700 passed_type
, ! last_named
)
3704 passed_type
= nominal_type
= build_pointer_type (passed_type
);
3706 passed_mode
= nominal_mode
= Pmode
;
3709 promoted_mode
= passed_mode
;
3711 #ifdef PROMOTE_FUNCTION_ARGS
3712 /* Compute the mode in which the arg is actually extended to. */
3713 promoted_mode
= promote_mode (passed_type
, promoted_mode
, &unsignedp
, 1);
3716 /* Let machine desc say which reg (if any) the parm arrives in.
3717 0 means it arrives on the stack. */
3718 #ifdef FUNCTION_INCOMING_ARG
3719 entry_parm
= FUNCTION_INCOMING_ARG (args_so_far
, promoted_mode
,
3720 passed_type
, ! last_named
);
3722 entry_parm
= FUNCTION_ARG (args_so_far
, promoted_mode
,
3723 passed_type
, ! last_named
);
3726 if (entry_parm
== 0)
3727 promoted_mode
= passed_mode
;
3729 #ifdef SETUP_INCOMING_VARARGS
3730 /* If this is the last named parameter, do any required setup for
3731 varargs or stdargs. We need to know about the case of this being an
3732 addressable type, in which case we skip the registers it
3733 would have arrived in.
3735 For stdargs, LAST_NAMED will be set for two parameters, the one that
3736 is actually the last named, and the dummy parameter. We only
3737 want to do this action once.
3739 Also, indicate when RTL generation is to be suppressed. */
3740 if (last_named
&& !varargs_setup
)
3742 SETUP_INCOMING_VARARGS (args_so_far
, promoted_mode
, passed_type
,
3743 current_function_pretend_args_size
,
3749 /* Determine parm's home in the stack,
3750 in case it arrives in the stack or we should pretend it did.
3752 Compute the stack position and rtx where the argument arrives
3755 There is one complexity here: If this was a parameter that would
3756 have been passed in registers, but wasn't only because it is
3757 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
3758 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
3759 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
3760 0 as it was the previous time. */
3762 locate_and_pad_parm (promoted_mode
, passed_type
,
3763 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3766 #ifdef FUNCTION_INCOMING_ARG
3767 FUNCTION_INCOMING_ARG (args_so_far
, promoted_mode
,
3770 || varargs_setup
)) != 0,
3772 FUNCTION_ARG (args_so_far
, promoted_mode
,
3774 ! last_named
|| varargs_setup
) != 0,
3777 fndecl
, &stack_args_size
, &stack_offset
, &arg_size
);
3781 rtx offset_rtx
= ARGS_SIZE_RTX (stack_offset
);
3783 if (offset_rtx
== const0_rtx
)
3784 stack_parm
= gen_rtx (MEM
, promoted_mode
, internal_arg_pointer
);
3786 stack_parm
= gen_rtx (MEM
, promoted_mode
,
3787 gen_rtx (PLUS
, Pmode
,
3788 internal_arg_pointer
, offset_rtx
));
3790 /* If this is a memory ref that contains aggregate components,
3791 mark it as such for cse and loop optimize. Likewise if it
3793 MEM_IN_STRUCT_P (stack_parm
) = aggregate
;
3794 RTX_UNCHANGING_P (stack_parm
) = TREE_READONLY (parm
);
3797 /* If this parameter was passed both in registers and in the stack,
3798 use the copy on the stack. */
3799 if (MUST_PASS_IN_STACK (promoted_mode
, passed_type
))
3802 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3803 /* If this parm was passed part in regs and part in memory,
3804 pretend it arrived entirely in memory
3805 by pushing the register-part onto the stack.
3807 In the special case of a DImode or DFmode that is split,
3808 we could put it together in a pseudoreg directly,
3809 but for now that's not worth bothering with. */
3813 int nregs
= FUNCTION_ARG_PARTIAL_NREGS (args_so_far
, promoted_mode
,
3814 passed_type
, ! last_named
);
3818 current_function_pretend_args_size
3819 = (((nregs
* UNITS_PER_WORD
) + (PARM_BOUNDARY
/ BITS_PER_UNIT
) - 1)
3820 / (PARM_BOUNDARY
/ BITS_PER_UNIT
)
3821 * (PARM_BOUNDARY
/ BITS_PER_UNIT
));
3825 /* Handle calls that pass values in multiple non-contiguous
3826 locations. The Irix 6 ABI has examples of this. */
3827 if (GET_CODE (entry_parm
) == PARALLEL
)
3828 emit_group_store (validize_mem (stack_parm
),
3831 move_block_from_reg (REGNO (entry_parm
),
3832 validize_mem (stack_parm
), nregs
,
3833 int_size_in_bytes (TREE_TYPE (parm
)));
3835 entry_parm
= stack_parm
;
3840 /* If we didn't decide this parm came in a register,
3841 by default it came on the stack. */
3842 if (entry_parm
== 0)
3843 entry_parm
= stack_parm
;
3845 /* Record permanently how this parm was passed. */
3847 DECL_INCOMING_RTL (parm
) = entry_parm
;
3849 /* If there is actually space on the stack for this parm,
3850 count it in stack_args_size; otherwise set stack_parm to 0
3851 to indicate there is no preallocated stack slot for the parm. */
3853 if (entry_parm
== stack_parm
3854 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
3855 /* On some machines, even if a parm value arrives in a register
3856 there is still an (uninitialized) stack slot allocated for it.
3858 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
3859 whether this parameter already has a stack slot allocated,
3860 because an arg block exists only if current_function_args_size
3861 is larger than some threshold, and we haven't calculated that
3862 yet. So, for now, we just assume that stack slots never exist
3864 || REG_PARM_STACK_SPACE (fndecl
) > 0
3868 stack_args_size
.constant
+= arg_size
.constant
;
3870 ADD_PARM_SIZE (stack_args_size
, arg_size
.var
);
3873 /* No stack slot was pushed for this parm. */
3876 /* Update info on where next arg arrives in registers. */
3878 FUNCTION_ARG_ADVANCE (args_so_far
, promoted_mode
,
3879 passed_type
, ! last_named
);
3881 /* If this is our second time through, we are done with this parm. */
3885 /* If we can't trust the parm stack slot to be aligned enough
3886 for its ultimate type, don't use that slot after entry.
3887 We'll make another stack slot, if we need one. */
3889 int thisparm_boundary
3890 = FUNCTION_ARG_BOUNDARY (promoted_mode
, passed_type
);
3892 if (GET_MODE_ALIGNMENT (nominal_mode
) > thisparm_boundary
)
3896 /* If parm was passed in memory, and we need to convert it on entry,
3897 don't store it back in that same slot. */
3899 && nominal_mode
!= BLKmode
&& nominal_mode
!= passed_mode
)
3903 /* Now adjust STACK_PARM to the mode and precise location
3904 where this parameter should live during execution,
3905 if we discover that it must live in the stack during execution.
3906 To make debuggers happier on big-endian machines, we store
3907 the value in the last bytes of the space available. */
3909 if (nominal_mode
!= BLKmode
&& nominal_mode
!= passed_mode
3914 if (BYTES_BIG_ENDIAN
3915 && GET_MODE_SIZE (nominal_mode
) < UNITS_PER_WORD
)
3916 stack_offset
.constant
+= (GET_MODE_SIZE (passed_mode
)
3917 - GET_MODE_SIZE (nominal_mode
));
3919 offset_rtx
= ARGS_SIZE_RTX (stack_offset
);
3920 if (offset_rtx
== const0_rtx
)
3921 stack_parm
= gen_rtx (MEM
, nominal_mode
, internal_arg_pointer
);
3923 stack_parm
= gen_rtx (MEM
, nominal_mode
,
3924 gen_rtx (PLUS
, Pmode
,
3925 if (flag_check_memory_usage
)
3927 push_to_sequence (conversion_insns
);
3928 emit_library_call (chkr_set_right_libfunc
, 1, VOIDmode
, 3,
3929 XEXP (stack_parm
, 0), ptr_mode
,
3930 GEN_INT (int_size_in_bytes
3931 (TREE_TYPE (parm
))),
3932 TYPE_MODE (sizetype
),
3933 GEN_INT (MEMORY_USE_RW
), QImode
);
3934 conversion_insns
= get_insns ();
3937 internal_arg_pointer
, offset_rtx
));
3939 /* If this is a memory ref that contains aggregate components,
3940 mark it as such for cse and loop optimize. */
3941 MEM_IN_STRUCT_P (stack_parm
) = aggregate
;
3946 /* We need this "use" info, because the gcc-register->stack-register
3947 converter in reg-stack.c needs to know which registers are active
3948 at the start of the function call. The actual parameter loading
3949 instructions are not always available then anymore, since they might
3950 have been optimised away. */
3952 if (GET_CODE (entry_parm
) == REG
&& !(hide_last_arg
&& last_named
))
3953 emit_insn (gen_rtx (USE
, GET_MODE (entry_parm
), entry_parm
));
3956 /* ENTRY_PARM is an RTX for the parameter as it arrives,
3957 in the mode in which it arrives.
3958 STACK_PARM is an RTX for a stack slot where the parameter can live
3959 during the function (in case we want to put it there).
3960 STACK_PARM is 0 if no stack slot was pushed for it.
3962 Now output code if necessary to convert ENTRY_PARM to
3963 the type in which this function declares it,
3964 and store that result in an appropriate place,
3965 which may be a pseudo reg, may be STACK_PARM,
3966 or may be a local stack slot if STACK_PARM is 0.
3968 Set DECL_RTL to that place. */
3970 if (nominal_mode
== BLKmode
|| GET_CODE (entry_parm
) == PARALLEL
)
3972 /* If a BLKmode arrives in registers, copy it to a stack slot.
3973 Handle calls that pass values in multiple non-contiguous
3974 locations. The Irix 6 ABI has examples of this. */
3975 if (GET_CODE (entry_parm
) == REG
3976 || GET_CODE (entry_parm
) == PARALLEL
)
3979 = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm
)),
3982 /* Note that we will be storing an integral number of words.
3983 So we have to be careful to ensure that we allocate an
3984 integral number of words. We do this below in the
3985 assign_stack_local if space was not allocated in the argument
3986 list. If it was, this will not work if PARM_BOUNDARY is not
3987 a multiple of BITS_PER_WORD. It isn't clear how to fix this
3988 if it becomes a problem. */
3990 if (stack_parm
== 0)
3993 = assign_stack_local (GET_MODE (entry_parm
),
3996 /* If this is a memory ref that contains aggregate
3997 components, mark it as such for cse and loop optimize. */
3998 MEM_IN_STRUCT_P (stack_parm
) = aggregate
;
4001 else if (PARM_BOUNDARY
% BITS_PER_WORD
!= 0)
4004 if (TREE_READONLY (parm
))
4005 RTX_UNCHANGING_P (stack_parm
) = 1;
4007 /* Handle calls that pass values in multiple non-contiguous
4008 locations. The Irix 6 ABI has examples of this. */
4009 if (GET_CODE (entry_parm
) == PARALLEL
)
4010 emit_group_store (validize_mem (stack_parm
), entry_parm
);
4012 move_block_from_reg (REGNO (entry_parm
),
4013 validize_mem (stack_parm
),
4014 size_stored
/ UNITS_PER_WORD
,
4015 int_size_in_bytes (TREE_TYPE (parm
)));
4017 DECL_RTL (parm
) = stack_parm
;
4019 else if (! ((obey_regdecls
&& ! DECL_REGISTER (parm
)
4020 && ! DECL_INLINE (fndecl
))
4021 /* layout_decl may set this. */
4022 || TREE_ADDRESSABLE (parm
)
4023 || TREE_SIDE_EFFECTS (parm
)
4024 /* If -ffloat-store specified, don't put explicit
4025 float variables into registers. */
4026 || (flag_float_store
4027 && TREE_CODE (TREE_TYPE (parm
)) == REAL_TYPE
))
4028 /* Always assign pseudo to structure return or item passed
4029 by invisible reference. */
4030 || passed_pointer
|| parm
== function_result_decl
)
4032 /* Store the parm in a pseudoregister during the function, but we
4033 may need to do it in a wider mode. */
4035 register rtx parmreg
;
4036 int regno
, regnoi
, regnor
;
4038 unsignedp
= TREE_UNSIGNED (TREE_TYPE (parm
));
4040 promoted_nominal_mode
4041 = promote_mode (TREE_TYPE (parm
), nominal_mode
, &unsignedp
, 0);
4043 parmreg
= gen_reg_rtx (promoted_nominal_mode
);
4044 mark_user_reg (parmreg
);
4046 /* If this was an item that we received a pointer to, set DECL_RTL
4051 = gen_rtx (MEM
, TYPE_MODE (TREE_TYPE (passed_type
)), parmreg
);
4052 MEM_IN_STRUCT_P (DECL_RTL (parm
)) = aggregate
;
4055 DECL_RTL (parm
) = parmreg
;
4057 /* Copy the value into the register. */
4058 if (nominal_mode
!= passed_mode
4059 || promoted_nominal_mode
!= promoted_mode
)
4061 /* ENTRY_PARM has been converted to PROMOTED_MODE, its
4062 mode, by the caller. We now have to convert it to
4063 NOMINAL_MODE, if different. However, PARMREG may be in
4064 a diffent mode than NOMINAL_MODE if it is being stored
4067 If ENTRY_PARM is a hard register, it might be in a register
4068 not valid for operating in its mode (e.g., an odd-numbered
4069 register for a DFmode). In that case, moves are the only
4070 thing valid, so we can't do a convert from there. This
4071 occurs when the calling sequence allow such misaligned
4074 In addition, the conversion may involve a call, which could
4075 clobber parameters which haven't been copied to pseudo
4076 registers yet. Therefore, we must first copy the parm to
4077 a pseudo reg here, and save the conversion until after all
4078 parameters have been moved. */
4080 rtx tempreg
= gen_reg_rtx (GET_MODE (entry_parm
));
4082 emit_move_insn (tempreg
, validize_mem (entry_parm
));
4084 push_to_sequence (conversion_insns
);
4085 tempreg
= convert_to_mode (nominal_mode
, tempreg
, unsignedp
);
4087 expand_assignment (parm
,
4088 make_tree (nominal_type
, tempreg
), 0, 0);
4089 conversion_insns
= get_insns ();
4094 emit_move_insn (parmreg
, validize_mem (entry_parm
));
4096 /* If we were passed a pointer but the actual value
4097 can safely live in a register, put it in one. */
4098 if (passed_pointer
&& TYPE_MODE (TREE_TYPE (parm
)) != BLKmode
4099 && ! ((obey_regdecls
&& ! DECL_REGISTER (parm
)
4100 && ! DECL_INLINE (fndecl
))
4101 /* layout_decl may set this. */
4102 || TREE_ADDRESSABLE (parm
)
4103 || TREE_SIDE_EFFECTS (parm
)
4104 /* If -ffloat-store specified, don't put explicit
4105 float variables into registers. */
4106 || (flag_float_store
4107 && TREE_CODE (TREE_TYPE (parm
)) == REAL_TYPE
)))
4109 /* We can't use nominal_mode, because it will have been set to
4110 Pmode above. We must use the actual mode of the parm. */
4111 parmreg
= gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm
)));
4112 mark_user_reg (parmreg
);
4113 emit_move_insn (parmreg
, DECL_RTL (parm
));
4114 DECL_RTL (parm
) = parmreg
;
4115 /* STACK_PARM is the pointer, not the parm, and PARMREG is
4119 #ifdef FUNCTION_ARG_CALLEE_COPIES
4120 /* If we are passed an arg by reference and it is our responsibility
4121 to make a copy, do it now.
4122 PASSED_TYPE and PASSED mode now refer to the pointer, not the
4123 original argument, so we must recreate them in the call to
4124 FUNCTION_ARG_CALLEE_COPIES. */
4125 /* ??? Later add code to handle the case that if the argument isn't
4126 modified, don't do the copy. */
4128 else if (passed_pointer
4129 && FUNCTION_ARG_CALLEE_COPIES (args_so_far
,
4130 TYPE_MODE (DECL_ARG_TYPE (parm
)),
4131 DECL_ARG_TYPE (parm
),
4133 && ! TREE_ADDRESSABLE (DECL_ARG_TYPE (parm
)))
4136 tree type
= DECL_ARG_TYPE (parm
);
4138 /* This sequence may involve a library call perhaps clobbering
4139 registers that haven't been copied to pseudos yet. */
4141 push_to_sequence (conversion_insns
);
4143 if (TYPE_SIZE (type
) == 0
4144 || TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
4145 /* This is a variable sized object. */
4146 copy
= gen_rtx (MEM
, BLKmode
,
4147 allocate_dynamic_stack_space
4148 (expr_size (parm
), NULL_RTX
,
4149 TYPE_ALIGN (type
)));
4151 copy
= assign_stack_temp (TYPE_MODE (type
),
4152 int_size_in_bytes (type
), 1);
4153 MEM_IN_STRUCT_P (copy
) = AGGREGATE_TYPE_P (type
);
4154 RTX_UNCHANGING_P (copy
) = TREE_READONLY (parm
);
4156 store_expr (parm
, copy
, 0);
4157 emit_move_insn (parmreg
, XEXP (copy
, 0));
4158 if (flag_check_memory_usage
)
4159 emit_library_call (chkr_set_right_libfunc
, 1, VOIDmode
, 3,
4160 XEXP (copy
, 0), ptr_mode
,
4161 GEN_INT (int_size_in_bytes (type
)),
4162 TYPE_MODE (sizetype
),
4163 GEN_INT (MEMORY_USE_RW
), QImode
);
4164 conversion_insns
= get_insns ();
4168 #endif /* FUNCTION_ARG_CALLEE_COPIES */
4170 /* In any case, record the parm's desired stack location
4171 in case we later discover it must live in the stack.
4173 If it is a COMPLEX value, store the stack location for both
4176 if (GET_CODE (parmreg
) == CONCAT
)
4177 regno
= MAX (REGNO (XEXP (parmreg
, 0)), REGNO (XEXP (parmreg
, 1)));
4179 regno
= REGNO (parmreg
);
4181 if (regno
>= max_parm_reg
)
4184 int old_max_parm_reg
= max_parm_reg
;
4186 /* It's slow to expand this one register at a time,
4187 but it's also rare and we need max_parm_reg to be
4188 precisely correct. */
4189 max_parm_reg
= regno
+ 1;
4190 new = (rtx
*) savealloc (max_parm_reg
* sizeof (rtx
));
4191 bcopy ((char *) parm_reg_stack_loc
, (char *) new,
4192 old_max_parm_reg
* sizeof (rtx
));
4193 bzero ((char *) (new + old_max_parm_reg
),
4194 (max_parm_reg
- old_max_parm_reg
) * sizeof (rtx
));
4195 parm_reg_stack_loc
= new;
4198 if (GET_CODE (parmreg
) == CONCAT
)
4200 enum machine_mode submode
= GET_MODE (XEXP (parmreg
, 0));
4202 regnor
= REGNO (gen_realpart (submode
, parmreg
));
4203 regnoi
= REGNO (gen_imagpart (submode
, parmreg
));
4205 if (stack_parm
!= 0)
4207 parm_reg_stack_loc
[regnor
]
4208 = gen_realpart (submode
, stack_parm
);
4209 parm_reg_stack_loc
[regnoi
]
4210 = gen_imagpart (submode
, stack_parm
);
4214 parm_reg_stack_loc
[regnor
] = 0;
4215 parm_reg_stack_loc
[regnoi
] = 0;
4219 parm_reg_stack_loc
[REGNO (parmreg
)] = stack_parm
;
4221 /* Mark the register as eliminable if we did no conversion
4222 and it was copied from memory at a fixed offset,
4223 and the arg pointer was not copied to a pseudo-reg.
4224 If the arg pointer is a pseudo reg or the offset formed
4225 an invalid address, such memory-equivalences
4226 as we make here would screw up life analysis for it. */
4227 if (nominal_mode
== passed_mode
4230 && GET_CODE (stack_parm
) == MEM
4231 && stack_offset
.var
== 0
4232 && reg_mentioned_p (virtual_incoming_args_rtx
,
4233 XEXP (stack_parm
, 0)))
4235 rtx linsn
= get_last_insn ();
4238 /* Mark complex types separately. */
4239 if (GET_CODE (parmreg
) == CONCAT
)
4240 /* Scan backwards for the set of the real and
4242 for (sinsn
= linsn
; sinsn
!= 0;
4243 sinsn
= prev_nonnote_insn (sinsn
))
4245 set
= single_set (sinsn
);
4247 && SET_DEST (set
) == regno_reg_rtx
[regnoi
])
4249 = gen_rtx (EXPR_LIST
, REG_EQUIV
,
4250 parm_reg_stack_loc
[regnoi
],
4253 && SET_DEST (set
) == regno_reg_rtx
[regnor
])
4255 = gen_rtx (EXPR_LIST
, REG_EQUIV
,
4256 parm_reg_stack_loc
[regnor
],
4259 else if ((set
= single_set (linsn
)) != 0
4260 && SET_DEST (set
) == parmreg
)
4262 = gen_rtx (EXPR_LIST
, REG_EQUIV
,
4263 stack_parm
, REG_NOTES (linsn
));
4266 /* For pointer data type, suggest pointer register. */
4267 if (TREE_CODE (TREE_TYPE (parm
)) == POINTER_TYPE
)
4268 mark_reg_pointer (parmreg
,
4269 (TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm
)))
4274 /* Value must be stored in the stack slot STACK_PARM
4275 during function execution. */
4277 if (promoted_mode
!= nominal_mode
)
4279 /* Conversion is required. */
4280 rtx tempreg
= gen_reg_rtx (GET_MODE (entry_parm
));
4282 emit_move_insn (tempreg
, validize_mem (entry_parm
));
4284 push_to_sequence (conversion_insns
);
4285 entry_parm
= convert_to_mode (nominal_mode
, tempreg
,
4286 TREE_UNSIGNED (TREE_TYPE (parm
)));
4289 /* ??? This may need a big-endian conversion on sparc64. */
4290 stack_parm
= change_address (stack_parm
, nominal_mode
,
4293 conversion_insns
= get_insns ();
4298 if (entry_parm
!= stack_parm
)
4300 if (stack_parm
== 0)
4303 = assign_stack_local (GET_MODE (entry_parm
),
4304 GET_MODE_SIZE (GET_MODE (entry_parm
)), 0);
4305 /* If this is a memory ref that contains aggregate components,
4306 mark it as such for cse and loop optimize. */
4307 MEM_IN_STRUCT_P (stack_parm
) = aggregate
;
4310 if (promoted_mode
!= nominal_mode
)
4312 push_to_sequence (conversion_insns
);
4313 emit_move_insn (validize_mem (stack_parm
),
4314 validize_mem (entry_parm
));
4315 conversion_insns
= get_insns ();
4319 emit_move_insn (validize_mem (stack_parm
),
4320 validize_mem (entry_parm
));
4322 if (flag_check_memory_usage
)
4324 push_to_sequence (conversion_insns
);
4325 emit_library_call (chkr_set_right_libfunc
, 1, VOIDmode
, 3,
4326 XEXP (stack_parm
, 0), ptr_mode
,
4327 GEN_INT (GET_MODE_SIZE (GET_MODE
4329 TYPE_MODE (sizetype
),
4330 GEN_INT (MEMORY_USE_RW
), QImode
);
4332 conversion_insns
= get_insns ();
4335 DECL_RTL (parm
) = stack_parm
;
4338 /* If this "parameter" was the place where we are receiving the
4339 function's incoming structure pointer, set up the result. */
4340 if (parm
== function_result_decl
)
4342 tree result
= DECL_RESULT (fndecl
);
4343 tree restype
= TREE_TYPE (result
);
4346 = gen_rtx (MEM
, DECL_MODE (result
), DECL_RTL (parm
));
4348 MEM_IN_STRUCT_P (DECL_RTL (result
)) = AGGREGATE_TYPE_P (restype
);
4351 if (TREE_THIS_VOLATILE (parm
))
4352 MEM_VOLATILE_P (DECL_RTL (parm
)) = 1;
4353 if (TREE_READONLY (parm
))
4354 RTX_UNCHANGING_P (DECL_RTL (parm
)) = 1;
4357 /* Output all parameter conversion instructions (possibly including calls)
4358 now that all parameters have been copied out of hard registers. */
4359 emit_insns (conversion_insns
);
4361 last_parm_insn
= get_last_insn ();
4363 current_function_args_size
= stack_args_size
.constant
;
4365 /* Adjust function incoming argument size for alignment and
4368 #ifdef REG_PARM_STACK_SPACE
4369 #ifndef MAYBE_REG_PARM_STACK_SPACE
4370 current_function_args_size
= MAX (current_function_args_size
,
4371 REG_PARM_STACK_SPACE (fndecl
));
4375 #ifdef STACK_BOUNDARY
4376 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
4378 current_function_args_size
4379 = ((current_function_args_size
+ STACK_BYTES
- 1)
4380 / STACK_BYTES
) * STACK_BYTES
;
4383 #ifdef ARGS_GROW_DOWNWARD
4384 current_function_arg_offset_rtx
4385 = (stack_args_size
.var
== 0 ? GEN_INT (-stack_args_size
.constant
)
4386 : expand_expr (size_binop (MINUS_EXPR
, stack_args_size
.var
,
4387 size_int (-stack_args_size
.constant
)),
4388 NULL_RTX
, VOIDmode
, EXPAND_MEMORY_USE_BAD
));
4390 current_function_arg_offset_rtx
= ARGS_SIZE_RTX (stack_args_size
);
4393 /* See how many bytes, if any, of its args a function should try to pop
4396 current_function_pops_args
= RETURN_POPS_ARGS (fndecl
, TREE_TYPE (fndecl
),
4397 current_function_args_size
);
4399 /* For stdarg.h function, save info about
4400 regs and stack space used by the named args. */
4403 current_function_args_info
= args_so_far
;
4405 /* Set the rtx used for the function return value. Put this in its
4406 own variable so any optimizers that need this information don't have
4407 to include tree.h. Do this here so it gets done when an inlined
4408 function gets output. */
4410 current_function_return_rtx
= DECL_RTL (DECL_RESULT (fndecl
));
4413 /* Indicate whether REGNO is an incoming argument to the current function
4414 that was promoted to a wider mode. If so, return the RTX for the
4415 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
4416 that REGNO is promoted from and whether the promotion was signed or
4419 #ifdef PROMOTE_FUNCTION_ARGS
4422 promoted_input_arg (regno
, pmode
, punsignedp
)
4424 enum machine_mode
*pmode
;
4429 for (arg
= DECL_ARGUMENTS (current_function_decl
); arg
;
4430 arg
= TREE_CHAIN (arg
))
4431 if (GET_CODE (DECL_INCOMING_RTL (arg
)) == REG
4432 && REGNO (DECL_INCOMING_RTL (arg
)) == regno
4433 && TYPE_MODE (DECL_ARG_TYPE (arg
)) == TYPE_MODE (TREE_TYPE (arg
)))
4435 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (arg
));
4436 int unsignedp
= TREE_UNSIGNED (TREE_TYPE (arg
));
4438 mode
= promote_mode (TREE_TYPE (arg
), mode
, &unsignedp
, 1);
4439 if (mode
== GET_MODE (DECL_INCOMING_RTL (arg
))
4440 && mode
!= DECL_MODE (arg
))
4442 *pmode
= DECL_MODE (arg
);
4443 *punsignedp
= unsignedp
;
4444 return DECL_INCOMING_RTL (arg
);
4453 /* Compute the size and offset from the start of the stacked arguments for a
4454 parm passed in mode PASSED_MODE and with type TYPE.
4456 INITIAL_OFFSET_PTR points to the current offset into the stacked
4459 The starting offset and size for this parm are returned in *OFFSET_PTR
4460 and *ARG_SIZE_PTR, respectively.
4462 IN_REGS is non-zero if the argument will be passed in registers. It will
4463 never be set if REG_PARM_STACK_SPACE is not defined.
4465 FNDECL is the function in which the argument was defined.
4467 There are two types of rounding that are done. The first, controlled by
4468 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
4469 list to be aligned to the specific boundary (in bits). This rounding
4470 affects the initial and starting offsets, but not the argument size.
4472 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
4473 optionally rounds the size of the parm to PARM_BOUNDARY. The
4474 initial offset is not affected by this rounding, while the size always
4475 is and the starting offset may be. */
4477 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
4478 initial_offset_ptr is positive because locate_and_pad_parm's
4479 callers pass in the total size of args so far as
4480 initial_offset_ptr. arg_size_ptr is always positive.*/
4483 locate_and_pad_parm (passed_mode
, type
, in_regs
, fndecl
,
4484 initial_offset_ptr
, offset_ptr
, arg_size_ptr
)
4485 enum machine_mode passed_mode
;
4489 struct args_size
*initial_offset_ptr
;
4490 struct args_size
*offset_ptr
;
4491 struct args_size
*arg_size_ptr
;
4494 = type
? size_in_bytes (type
) : size_int (GET_MODE_SIZE (passed_mode
));
4495 enum direction where_pad
= FUNCTION_ARG_PADDING (passed_mode
, type
);
4496 int boundary
= FUNCTION_ARG_BOUNDARY (passed_mode
, type
);
4497 int boundary_in_bytes
= boundary
/ BITS_PER_UNIT
;
4498 int reg_parm_stack_space
= 0;
4500 #ifdef REG_PARM_STACK_SPACE
4501 /* If we have found a stack parm before we reach the end of the
4502 area reserved for registers, skip that area. */
4505 #ifdef MAYBE_REG_PARM_STACK_SPACE
4506 reg_parm_stack_space
= MAYBE_REG_PARM_STACK_SPACE
;
4508 reg_parm_stack_space
= REG_PARM_STACK_SPACE (fndecl
);
4510 if (reg_parm_stack_space
> 0)
4512 if (initial_offset_ptr
->var
)
4514 initial_offset_ptr
->var
4515 = size_binop (MAX_EXPR
, ARGS_SIZE_TREE (*initial_offset_ptr
),
4516 size_int (reg_parm_stack_space
));
4517 initial_offset_ptr
->constant
= 0;
4519 else if (initial_offset_ptr
->constant
< reg_parm_stack_space
)
4520 initial_offset_ptr
->constant
= reg_parm_stack_space
;
4523 #endif /* REG_PARM_STACK_SPACE */
4525 arg_size_ptr
->var
= 0;
4526 arg_size_ptr
->constant
= 0;
4528 #ifdef ARGS_GROW_DOWNWARD
4529 if (initial_offset_ptr
->var
)
4531 offset_ptr
->constant
= 0;
4532 offset_ptr
->var
= size_binop (MINUS_EXPR
, integer_zero_node
,
4533 initial_offset_ptr
->var
);
4537 offset_ptr
->constant
= - initial_offset_ptr
->constant
;
4538 offset_ptr
->var
= 0;
4540 if (where_pad
!= none
4541 && (TREE_CODE (sizetree
) != INTEGER_CST
4542 || ((TREE_INT_CST_LOW (sizetree
) * BITS_PER_UNIT
) % PARM_BOUNDARY
)))
4543 sizetree
= round_up (sizetree
, PARM_BOUNDARY
/ BITS_PER_UNIT
);
4544 SUB_PARM_SIZE (*offset_ptr
, sizetree
);
4545 if (where_pad
!= downward
)
4546 pad_to_arg_alignment (offset_ptr
, boundary
);
4547 if (initial_offset_ptr
->var
)
4549 arg_size_ptr
->var
= size_binop (MINUS_EXPR
,
4550 size_binop (MINUS_EXPR
,
4552 initial_offset_ptr
->var
),
4557 arg_size_ptr
->constant
= (- initial_offset_ptr
->constant
4558 - offset_ptr
->constant
);
4560 #else /* !ARGS_GROW_DOWNWARD */
4561 pad_to_arg_alignment (initial_offset_ptr
, boundary
);
4562 *offset_ptr
= *initial_offset_ptr
;
4564 #ifdef PUSH_ROUNDING
4565 if (passed_mode
!= BLKmode
)
4566 sizetree
= size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree
)));
4569 /* Pad_below needs the pre-rounded size to know how much to pad below
4570 so this must be done before rounding up. */
4571 if (where_pad
== downward
4572 /* However, BLKmode args passed in regs have their padding done elsewhere.
4573 The stack slot must be able to hold the entire register. */
4574 && !(in_regs
&& passed_mode
== BLKmode
))
4575 pad_below (offset_ptr
, passed_mode
, sizetree
);
4577 if (where_pad
!= none
4578 && (TREE_CODE (sizetree
) != INTEGER_CST
4579 || ((TREE_INT_CST_LOW (sizetree
) * BITS_PER_UNIT
) % PARM_BOUNDARY
)))
4580 sizetree
= round_up (sizetree
, PARM_BOUNDARY
/ BITS_PER_UNIT
);
4582 ADD_PARM_SIZE (*arg_size_ptr
, sizetree
);
4583 #endif /* ARGS_GROW_DOWNWARD */
4586 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
4587 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
4590 pad_to_arg_alignment (offset_ptr
, boundary
)
4591 struct args_size
*offset_ptr
;
4594 int boundary_in_bytes
= boundary
/ BITS_PER_UNIT
;
4596 if (boundary
> BITS_PER_UNIT
)
4598 if (offset_ptr
->var
)
4601 #ifdef ARGS_GROW_DOWNWARD
4606 (ARGS_SIZE_TREE (*offset_ptr
),
4607 boundary
/ BITS_PER_UNIT
);
4608 offset_ptr
->constant
= 0; /*?*/
4611 offset_ptr
->constant
=
4612 #ifdef ARGS_GROW_DOWNWARD
4613 FLOOR_ROUND (offset_ptr
->constant
, boundary_in_bytes
);
4615 CEIL_ROUND (offset_ptr
->constant
, boundary_in_bytes
);
4621 pad_below (offset_ptr
, passed_mode
, sizetree
)
4622 struct args_size
*offset_ptr
;
4623 enum machine_mode passed_mode
;
4626 if (passed_mode
!= BLKmode
)
4628 if (GET_MODE_BITSIZE (passed_mode
) % PARM_BOUNDARY
)
4629 offset_ptr
->constant
4630 += (((GET_MODE_BITSIZE (passed_mode
) + PARM_BOUNDARY
- 1)
4631 / PARM_BOUNDARY
* PARM_BOUNDARY
/ BITS_PER_UNIT
)
4632 - GET_MODE_SIZE (passed_mode
));
4636 if (TREE_CODE (sizetree
) != INTEGER_CST
4637 || (TREE_INT_CST_LOW (sizetree
) * BITS_PER_UNIT
) % PARM_BOUNDARY
)
4639 /* Round the size up to multiple of PARM_BOUNDARY bits. */
4640 tree s2
= round_up (sizetree
, PARM_BOUNDARY
/ BITS_PER_UNIT
);
4642 ADD_PARM_SIZE (*offset_ptr
, s2
);
4643 SUB_PARM_SIZE (*offset_ptr
, sizetree
);
4649 round_down (value
, divisor
)
4653 return size_binop (MULT_EXPR
,
4654 size_binop (FLOOR_DIV_EXPR
, value
, size_int (divisor
)),
4655 size_int (divisor
));
4658 /* Walk the tree of blocks describing the binding levels within a function
4659 and warn about uninitialized variables.
4660 This is done after calling flow_analysis and before global_alloc
4661 clobbers the pseudo-regs to hard regs. */
4664 uninitialized_vars_warning (block
)
4667 register tree decl
, sub
;
4668 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
4670 if (TREE_CODE (decl
) == VAR_DECL
4671 /* These warnings are unreliable for and aggregates
4672 because assigning the fields one by one can fail to convince
4673 flow.c that the entire aggregate was initialized.
4674 Unions are troublesome because members may be shorter. */
4675 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl
))
4676 && DECL_RTL (decl
) != 0
4677 && GET_CODE (DECL_RTL (decl
)) == REG
4678 && regno_uninitialized (REGNO (DECL_RTL (decl
))))
4679 warning_with_decl (decl
,
4680 "`%s' might be used uninitialized in this function");
4681 if (TREE_CODE (decl
) == VAR_DECL
4682 && DECL_RTL (decl
) != 0
4683 && GET_CODE (DECL_RTL (decl
)) == REG
4684 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl
))))
4685 warning_with_decl (decl
,
4686 "variable `%s' might be clobbered by `longjmp' or `vfork'");
4688 for (sub
= BLOCK_SUBBLOCKS (block
); sub
; sub
= TREE_CHAIN (sub
))
4689 uninitialized_vars_warning (sub
);
4692 /* Do the appropriate part of uninitialized_vars_warning
4693 but for arguments instead of local variables. */
4696 setjmp_args_warning ()
4699 for (decl
= DECL_ARGUMENTS (current_function_decl
);
4700 decl
; decl
= TREE_CHAIN (decl
))
4701 if (DECL_RTL (decl
) != 0
4702 && GET_CODE (DECL_RTL (decl
)) == REG
4703 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl
))))
4704 warning_with_decl (decl
, "argument `%s' might be clobbered by `longjmp' or `vfork'");
4707 /* If this function call setjmp, put all vars into the stack
4708 unless they were declared `register'. */
4711 setjmp_protect (block
)
4714 register tree decl
, sub
;
4715 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
4716 if ((TREE_CODE (decl
) == VAR_DECL
4717 || TREE_CODE (decl
) == PARM_DECL
)
4718 && DECL_RTL (decl
) != 0
4719 && (GET_CODE (DECL_RTL (decl
)) == REG
4720 || (GET_CODE (DECL_RTL (decl
)) == MEM
4721 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == ADDRESSOF
))
4722 /* If this variable came from an inline function, it must be
4723 that it's life doesn't overlap the setjmp. If there was a
4724 setjmp in the function, it would already be in memory. We
4725 must exclude such variable because their DECL_RTL might be
4726 set to strange things such as virtual_stack_vars_rtx. */
4727 && ! DECL_FROM_INLINE (decl
)
4729 #ifdef NON_SAVING_SETJMP
4730 /* If longjmp doesn't restore the registers,
4731 don't put anything in them. */
4735 ! DECL_REGISTER (decl
)))
4736 put_var_into_stack (decl
);
4737 for (sub
= BLOCK_SUBBLOCKS (block
); sub
; sub
= TREE_CHAIN (sub
))
4738 setjmp_protect (sub
);
4741 /* Like the previous function, but for args instead of local variables. */
4744 setjmp_protect_args ()
4746 register tree decl
, sub
;
4747 for (decl
= DECL_ARGUMENTS (current_function_decl
);
4748 decl
; decl
= TREE_CHAIN (decl
))
4749 if ((TREE_CODE (decl
) == VAR_DECL
4750 || TREE_CODE (decl
) == PARM_DECL
)
4751 && DECL_RTL (decl
) != 0
4752 && (GET_CODE (DECL_RTL (decl
)) == REG
4753 || (GET_CODE (DECL_RTL (decl
)) == MEM
4754 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == ADDRESSOF
))
4756 /* If longjmp doesn't restore the registers,
4757 don't put anything in them. */
4758 #ifdef NON_SAVING_SETJMP
4762 ! DECL_REGISTER (decl
)))
4763 put_var_into_stack (decl
);
4766 /* Return the context-pointer register corresponding to DECL,
4767 or 0 if it does not need one. */
4770 lookup_static_chain (decl
)
4773 tree context
= decl_function_context (decl
);
4777 || (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_NO_STATIC_CHAIN (decl
)))
4780 /* We treat inline_function_decl as an alias for the current function
4781 because that is the inline function whose vars, types, etc.
4782 are being merged into the current function.
4783 See expand_inline_function. */
4784 if (context
== current_function_decl
|| context
== inline_function_decl
)
4785 return virtual_stack_vars_rtx
;
4787 for (link
= context_display
; link
; link
= TREE_CHAIN (link
))
4788 if (TREE_PURPOSE (link
) == context
)
4789 return RTL_EXPR_RTL (TREE_VALUE (link
));
4794 /* Convert a stack slot address ADDR for variable VAR
4795 (from a containing function)
4796 into an address valid in this function (using a static chain). */
4799 fix_lexical_addr (addr
, var
)
4805 tree context
= decl_function_context (var
);
4806 struct function
*fp
;
4809 /* If this is the present function, we need not do anything. */
4810 if (context
== current_function_decl
|| context
== inline_function_decl
)
4813 for (fp
= outer_function_chain
; fp
; fp
= fp
->next
)
4814 if (fp
->decl
== context
)
4820 if (GET_CODE (addr
) == ADDRESSOF
&& GET_CODE (XEXP (addr
, 0)) == MEM
)
4821 addr
= XEXP (XEXP (addr
, 0), 0);
4823 /* Decode given address as base reg plus displacement. */
4824 if (GET_CODE (addr
) == REG
)
4825 basereg
= addr
, displacement
= 0;
4826 else if (GET_CODE (addr
) == PLUS
&& GET_CODE (XEXP (addr
, 1)) == CONST_INT
)
4827 basereg
= XEXP (addr
, 0), displacement
= INTVAL (XEXP (addr
, 1));
4831 /* We accept vars reached via the containing function's
4832 incoming arg pointer and via its stack variables pointer. */
4833 if (basereg
== fp
->internal_arg_pointer
)
4835 /* If reached via arg pointer, get the arg pointer value
4836 out of that function's stack frame.
4838 There are two cases: If a separate ap is needed, allocate a
4839 slot in the outer function for it and dereference it that way.
4840 This is correct even if the real ap is actually a pseudo.
4841 Otherwise, just adjust the offset from the frame pointer to
4844 #ifdef NEED_SEPARATE_AP
4847 if (fp
->arg_pointer_save_area
== 0)
4848 fp
->arg_pointer_save_area
4849 = assign_outer_stack_local (Pmode
, GET_MODE_SIZE (Pmode
), 0, fp
);
4851 addr
= fix_lexical_addr (XEXP (fp
->arg_pointer_save_area
, 0), var
);
4852 addr
= memory_address (Pmode
, addr
);
4854 base
= copy_to_reg (gen_rtx (MEM
, Pmode
, addr
));
4856 displacement
+= (FIRST_PARM_OFFSET (context
) - STARTING_FRAME_OFFSET
);
4857 base
= lookup_static_chain (var
);
4861 else if (basereg
== virtual_stack_vars_rtx
)
4863 /* This is the same code as lookup_static_chain, duplicated here to
4864 avoid an extra call to decl_function_context. */
4867 for (link
= context_display
; link
; link
= TREE_CHAIN (link
))
4868 if (TREE_PURPOSE (link
) == context
)
4870 base
= RTL_EXPR_RTL (TREE_VALUE (link
));
4878 /* Use same offset, relative to appropriate static chain or argument
4880 return plus_constant (base
, displacement
);
4883 /* Return the address of the trampoline for entering nested fn FUNCTION.
4884 If necessary, allocate a trampoline (in the stack frame)
4885 and emit rtl to initialize its contents (at entry to this function). */
4888 trampoline_address (function
)
4894 struct function
*fp
;
4897 /* Find an existing trampoline and return it. */
4898 for (link
= trampoline_list
; link
; link
= TREE_CHAIN (link
))
4899 if (TREE_PURPOSE (link
) == function
)
4901 round_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link
)), 0));
4903 for (fp
= outer_function_chain
; fp
; fp
= fp
->next
)
4904 for (link
= fp
->trampoline_list
; link
; link
= TREE_CHAIN (link
))
4905 if (TREE_PURPOSE (link
) == function
)
4907 tramp
= fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link
)), 0),
4909 return round_trampoline_addr (tramp
);
4912 /* None exists; we must make one. */
4914 /* Find the `struct function' for the function containing FUNCTION. */
4916 fn_context
= decl_function_context (function
);
4917 if (fn_context
!= current_function_decl
4918 && fn_context
!= inline_function_decl
)
4919 for (fp
= outer_function_chain
; fp
; fp
= fp
->next
)
4920 if (fp
->decl
== fn_context
)
4923 /* Allocate run-time space for this trampoline
4924 (usually in the defining function's stack frame). */
4925 #ifdef ALLOCATE_TRAMPOLINE
4926 tramp
= ALLOCATE_TRAMPOLINE (fp
);
4928 /* If rounding needed, allocate extra space
4929 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
4930 #ifdef TRAMPOLINE_ALIGNMENT
4931 #define TRAMPOLINE_REAL_SIZE \
4932 (TRAMPOLINE_SIZE + (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT) - 1)
4934 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
4937 tramp
= assign_outer_stack_local (BLKmode
, TRAMPOLINE_REAL_SIZE
, 0, fp
);
4939 tramp
= assign_stack_local (BLKmode
, TRAMPOLINE_REAL_SIZE
, 0);
4942 /* Record the trampoline for reuse and note it for later initialization
4943 by expand_function_end. */
4946 push_obstacks (fp
->function_maybepermanent_obstack
,
4947 fp
->function_maybepermanent_obstack
);
4948 rtlexp
= make_node (RTL_EXPR
);
4949 RTL_EXPR_RTL (rtlexp
) = tramp
;
4950 fp
->trampoline_list
= tree_cons (function
, rtlexp
, fp
->trampoline_list
);
4955 /* Make the RTL_EXPR node temporary, not momentary, so that the
4956 trampoline_list doesn't become garbage. */
4957 int momentary
= suspend_momentary ();
4958 rtlexp
= make_node (RTL_EXPR
);
4959 resume_momentary (momentary
);
4961 RTL_EXPR_RTL (rtlexp
) = tramp
;
4962 trampoline_list
= tree_cons (function
, rtlexp
, trampoline_list
);
4965 tramp
= fix_lexical_addr (XEXP (tramp
, 0), function
);
4966 return round_trampoline_addr (tramp
);
4969 /* Given a trampoline address,
4970 round it to multiple of TRAMPOLINE_ALIGNMENT. */
4973 round_trampoline_addr (tramp
)
4976 #ifdef TRAMPOLINE_ALIGNMENT
4977 /* Round address up to desired boundary. */
4978 rtx temp
= gen_reg_rtx (Pmode
);
4979 temp
= expand_binop (Pmode
, add_optab
, tramp
,
4980 GEN_INT (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
- 1),
4981 temp
, 0, OPTAB_LIB_WIDEN
);
4982 tramp
= expand_binop (Pmode
, and_optab
, temp
,
4983 GEN_INT (- TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
),
4984 temp
, 0, OPTAB_LIB_WIDEN
);
4989 /* The functions identify_blocks and reorder_blocks provide a way to
4990 reorder the tree of BLOCK nodes, for optimizers that reshuffle or
4991 duplicate portions of the RTL code. Call identify_blocks before
4992 changing the RTL, and call reorder_blocks after. */
4994 /* Put all this function's BLOCK nodes including those that are chained
4995 onto the first block into a vector, and return it.
4996 Also store in each NOTE for the beginning or end of a block
4997 the index of that block in the vector.
4998 The arguments are BLOCK, the chain of top-level blocks of the function,
4999 and INSNS, the insn chain of the function. */
5002 identify_blocks (block
, insns
)
5010 int next_block_number
= 1;
5011 int current_block_number
= 1;
5017 n_blocks
= all_blocks (block
, 0);
5018 block_vector
= (tree
*) xmalloc (n_blocks
* sizeof (tree
));
5019 block_stack
= (int *) alloca (n_blocks
* sizeof (int));
5021 all_blocks (block
, block_vector
);
5023 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
5024 if (GET_CODE (insn
) == NOTE
)
5026 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_BEG
)
5028 block_stack
[depth
++] = current_block_number
;
5029 current_block_number
= next_block_number
;
5030 NOTE_BLOCK_NUMBER (insn
) = next_block_number
++;
5032 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_END
)
5034 current_block_number
= block_stack
[--depth
];
5035 NOTE_BLOCK_NUMBER (insn
) = current_block_number
;
5039 if (n_blocks
!= next_block_number
)
5042 return block_vector
;
5045 /* Given BLOCK_VECTOR which was returned by identify_blocks,
5046 and a revised instruction chain, rebuild the tree structure
5047 of BLOCK nodes to correspond to the new order of RTL.
5048 The new block tree is inserted below TOP_BLOCK.
5049 Returns the current top-level block. */
5052 reorder_blocks (block_vector
, block
, insns
)
5057 tree current_block
= block
;
5060 if (block_vector
== 0)
5063 /* Prune the old trees away, so that it doesn't get in the way. */
5064 BLOCK_SUBBLOCKS (current_block
) = 0;
5065 BLOCK_CHAIN (current_block
) = 0;
5067 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
5068 if (GET_CODE (insn
) == NOTE
)
5070 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_BEG
)
5072 tree block
= block_vector
[NOTE_BLOCK_NUMBER (insn
)];
5073 /* If we have seen this block before, copy it. */
5074 if (TREE_ASM_WRITTEN (block
))
5075 block
= copy_node (block
);
5076 BLOCK_SUBBLOCKS (block
) = 0;
5077 TREE_ASM_WRITTEN (block
) = 1;
5078 BLOCK_SUPERCONTEXT (block
) = current_block
;
5079 BLOCK_CHAIN (block
) = BLOCK_SUBBLOCKS (current_block
);
5080 BLOCK_SUBBLOCKS (current_block
) = block
;
5081 current_block
= block
;
5082 NOTE_SOURCE_FILE (insn
) = 0;
5084 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_END
)
5086 BLOCK_SUBBLOCKS (current_block
)
5087 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block
));
5088 current_block
= BLOCK_SUPERCONTEXT (current_block
);
5089 NOTE_SOURCE_FILE (insn
) = 0;
5093 BLOCK_SUBBLOCKS (current_block
)
5094 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block
));
5095 return current_block
;
5098 /* Reverse the order of elements in the chain T of blocks,
5099 and return the new head of the chain (old last element). */
5105 register tree prev
= 0, decl
, next
;
5106 for (decl
= t
; decl
; decl
= next
)
5108 next
= BLOCK_CHAIN (decl
);
5109 BLOCK_CHAIN (decl
) = prev
;
5115 /* Count the subblocks of the list starting with BLOCK, and list them
5116 all into the vector VECTOR. Also clear TREE_ASM_WRITTEN in all
5120 all_blocks (block
, vector
)
5128 TREE_ASM_WRITTEN (block
) = 0;
5130 /* Record this block. */
5132 vector
[n_blocks
] = block
;
5136 /* Record the subblocks, and their subblocks... */
5137 n_blocks
+= all_blocks (BLOCK_SUBBLOCKS (block
),
5138 vector
? vector
+ n_blocks
: 0);
5139 block
= BLOCK_CHAIN (block
);
5145 /* Build bytecode call descriptor for function SUBR. */
5148 bc_build_calldesc (subr
)
5151 tree calldesc
= 0, arg
;
5154 /* Build the argument description vector in reverse order. */
5155 DECL_ARGUMENTS (subr
) = nreverse (DECL_ARGUMENTS (subr
));
5158 for (arg
= DECL_ARGUMENTS (subr
); arg
; arg
= TREE_CHAIN (arg
))
5162 calldesc
= tree_cons ((tree
) 0, size_in_bytes (TREE_TYPE (arg
)), calldesc
);
5163 calldesc
= tree_cons ((tree
) 0, bc_runtime_type_code (TREE_TYPE (arg
)), calldesc
);
5166 DECL_ARGUMENTS (subr
) = nreverse (DECL_ARGUMENTS (subr
));
5168 /* Prepend the function's return type. */
5169 calldesc
= tree_cons ((tree
) 0,
5170 size_in_bytes (TREE_TYPE (TREE_TYPE (subr
))),
5173 calldesc
= tree_cons ((tree
) 0,
5174 bc_runtime_type_code (TREE_TYPE (TREE_TYPE (subr
))),
5177 /* Prepend the arg count. */
5178 calldesc
= tree_cons ((tree
) 0, build_int_2 (nargs
, 0), calldesc
);
5180 /* Output the call description vector and get its address. */
5181 calldesc
= build_nt (CONSTRUCTOR
, (tree
) 0, calldesc
);
5182 TREE_TYPE (calldesc
) = build_array_type (integer_type_node
,
5183 build_index_type (build_int_2 (nargs
* 2, 0)));
5185 return output_constant_def (calldesc
);
5189 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
5190 and initialize static variables for generating RTL for the statements
5194 init_function_start (subr
, filename
, line
)
5199 if (output_bytecode
)
5201 this_function_decl
= subr
;
5202 this_function_calldesc
= bc_build_calldesc (subr
);
5203 local_vars_size
= 0;
5205 max_stack_depth
= 0;
5206 stmt_expr_depth
= 0;
5210 init_stmt_for_function ();
5212 cse_not_expected
= ! optimize
;
5214 /* Caller save not needed yet. */
5215 caller_save_needed
= 0;
5217 /* No stack slots have been made yet. */
5218 stack_slot_list
= 0;
5220 /* There is no stack slot for handling nonlocal gotos. */
5221 nonlocal_goto_handler_slot
= 0;
5222 nonlocal_goto_stack_level
= 0;
5224 /* No labels have been declared for nonlocal use. */
5225 nonlocal_labels
= 0;
5227 /* No function calls so far in this function. */
5228 function_call_count
= 0;
5230 /* No parm regs have been allocated.
5231 (This is important for output_inline_function.) */
5232 max_parm_reg
= LAST_VIRTUAL_REGISTER
+ 1;
5234 /* Initialize the RTL mechanism. */
5237 /* Initialize the queue of pending postincrement and postdecrements,
5238 and some other info in expr.c. */
5241 /* We haven't done register allocation yet. */
5244 init_const_rtx_hash_table ();
5246 current_function_name
= (*decl_printable_name
) (subr
, 2);
5248 /* Nonzero if this is a nested function that uses a static chain. */
5250 current_function_needs_context
5251 = (decl_function_context (current_function_decl
) != 0
5252 && ! DECL_NO_STATIC_CHAIN (current_function_decl
));
5254 /* Set if a call to setjmp is seen. */
5255 current_function_calls_setjmp
= 0;
5257 /* Set if a call to longjmp is seen. */
5258 current_function_calls_longjmp
= 0;
5260 current_function_calls_alloca
= 0;
5261 current_function_has_nonlocal_label
= 0;
5262 current_function_has_nonlocal_goto
= 0;
5263 current_function_contains_functions
= 0;
5264 current_function_is_thunk
= 0;
5266 current_function_returns_pcc_struct
= 0;
5267 current_function_returns_struct
= 0;
5268 current_function_epilogue_delay_list
= 0;
5269 current_function_uses_const_pool
= 0;
5270 current_function_uses_pic_offset_table
= 0;
5272 /* We have not yet needed to make a label to jump to for tail-recursion. */
5273 tail_recursion_label
= 0;
5275 /* We haven't had a need to make a save area for ap yet. */
5277 arg_pointer_save_area
= 0;
5279 /* No stack slots allocated yet. */
5282 /* No SAVE_EXPRs in this function yet. */
5285 /* No RTL_EXPRs in this function yet. */
5288 /* Set up to allocate temporaries. */
5291 /* Within function body, compute a type's size as soon it is laid out. */
5292 immediate_size_expand
++;
5294 /* We haven't made any trampolines for this function yet. */
5295 trampoline_list
= 0;
5297 init_pending_stack_adjust ();
5298 inhibit_defer_pop
= 0;
5300 current_function_outgoing_args_size
= 0;
5302 /* Prevent ever trying to delete the first instruction of a function.
5303 Also tell final how to output a linenum before the function prologue. */
5304 emit_line_note (filename
, line
);
5306 /* Make sure first insn is a note even if we don't want linenums.
5307 This makes sure the first insn will never be deleted.
5308 Also, final expects a note to appear there. */
5309 emit_note (NULL_PTR
, NOTE_INSN_DELETED
);
5311 /* Set flags used by final.c. */
5312 if (aggregate_value_p (DECL_RESULT (subr
)))
5314 #ifdef PCC_STATIC_STRUCT_RETURN
5315 current_function_returns_pcc_struct
= 1;
5317 current_function_returns_struct
= 1;
5320 /* Warn if this value is an aggregate type,
5321 regardless of which calling convention we are using for it. */
5322 if (warn_aggregate_return
5323 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr
))))
5324 warning ("function returns an aggregate");
5326 current_function_returns_pointer
5327 = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr
)));
5329 /* Indicate that we need to distinguish between the return value of the
5330 present function and the return value of a function being called. */
5331 rtx_equal_function_value_matters
= 1;
5333 /* Indicate that we have not instantiated virtual registers yet. */
5334 virtuals_instantiated
= 0;
5336 /* Indicate we have no need of a frame pointer yet. */
5337 frame_pointer_needed
= 0;
5339 /* By default assume not varargs or stdarg. */
5340 current_function_varargs
= 0;
5341 current_function_stdarg
= 0;
5344 /* Indicate that the current function uses extra args
5345 not explicitly mentioned in the argument list in any fashion. */
5350 current_function_varargs
= 1;
5353 /* Expand a call to __main at the beginning of a possible main function. */
5355 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
5356 #undef HAS_INIT_SECTION
5357 #define HAS_INIT_SECTION
5361 expand_main_function ()
5363 if (!output_bytecode
)
5365 /* The zero below avoids a possible parse error */
5367 #if !defined (HAS_INIT_SECTION)
5368 emit_library_call (gen_rtx (SYMBOL_REF
, Pmode
, NAME__MAIN
), 0,
5370 #endif /* not HAS_INIT_SECTION */
5374 extern struct obstack permanent_obstack
;
5376 /* Expand start of bytecode function. See comment at
5377 expand_function_start below for details. */
5380 bc_expand_function_start (subr
, parms_have_cleanups
)
5382 int parms_have_cleanups
;
5384 char label
[20], *name
;
5389 if (TREE_PUBLIC (subr
))
5390 bc_globalize_label (IDENTIFIER_POINTER (DECL_NAME (subr
)));
5392 #ifdef DEBUG_PRINT_CODE
5393 fprintf (stderr
, "\n<func %s>\n", IDENTIFIER_POINTER (DECL_NAME (subr
)));
5396 for (argsz
= 0, thisarg
= DECL_ARGUMENTS (subr
); thisarg
; thisarg
= TREE_CHAIN (thisarg
))
5398 if (DECL_RTL (thisarg
))
5399 abort (); /* Should be NULL here I think. */
5400 else if (TREE_CONSTANT (DECL_SIZE (thisarg
)))
5402 DECL_RTL (thisarg
) = bc_gen_rtx ((char *) 0, argsz
, (struct bc_label
*) 0);
5403 argsz
+= TREE_INT_CST_LOW (DECL_SIZE (thisarg
));
5407 /* Variable-sized objects are pointers to their storage. */
5408 DECL_RTL (thisarg
) = bc_gen_rtx ((char *) 0, argsz
, (struct bc_label
*) 0);
5409 argsz
+= POINTER_SIZE
;
5413 bc_begin_function (xstrdup (IDENTIFIER_POINTER (DECL_NAME (subr
))));
5415 ASM_GENERATE_INTERNAL_LABEL (label
, "LX", nlab
);
5418 name
= (char *) obstack_copy0 (&permanent_obstack
, label
, strlen (label
));
5419 this_function_callinfo
= bc_gen_rtx (name
, 0, (struct bc_label
*) 0);
5420 this_function_bytecode
5421 = bc_emit_trampoline (BYTECODE_LABEL (this_function_callinfo
));
5425 /* Expand end of bytecode function. See details the comment of
5426 expand_function_end(), below. */
5429 bc_expand_function_end ()
5433 expand_null_return ();
5435 /* Emit any fixup code. This must be done before the call to
5436 to BC_END_FUNCTION (), since that will cause the bytecode
5437 segment to be finished off and closed. */
5439 expand_fixups (NULL_RTX
);
5441 ptrconsts
= bc_end_function ();
5443 bc_align_const (2 /* INT_ALIGN */);
5445 /* If this changes also make sure to change bc-interp.h! */
5447 bc_emit_const_labeldef (BYTECODE_LABEL (this_function_callinfo
));
5448 bc_emit_const ((char *) &max_stack_depth
, sizeof max_stack_depth
);
5449 bc_emit_const ((char *) &local_vars_size
, sizeof local_vars_size
);
5450 bc_emit_const_labelref (this_function_bytecode
, 0);
5451 bc_emit_const_labelref (ptrconsts
, 0);
5452 bc_emit_const_labelref (BYTECODE_LABEL (this_function_calldesc
), 0);
5456 /* Start the RTL for a new function, and set variables used for
5458 SUBR is the FUNCTION_DECL node.
5459 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
5460 the function's parameters, which must be run at any return statement. */
5463 expand_function_start (subr
, parms_have_cleanups
)
5465 int parms_have_cleanups
;
5471 if (output_bytecode
)
5473 bc_expand_function_start (subr
, parms_have_cleanups
);
5477 /* Make sure volatile mem refs aren't considered
5478 valid operands of arithmetic insns. */
5479 init_recog_no_volatile ();
5481 /* If function gets a static chain arg, store it in the stack frame.
5482 Do this first, so it gets the first stack slot offset. */
5483 if (current_function_needs_context
)
5485 last_ptr
= assign_stack_local (Pmode
, GET_MODE_SIZE (Pmode
), 0);
5487 /* Delay copying static chain if it is not a register to avoid
5488 conflicts with regs used for parameters. */
5489 if (! SMALL_REGISTER_CLASSES
5490 || GET_CODE (static_chain_incoming_rtx
) == REG
)
5491 emit_move_insn (last_ptr
, static_chain_incoming_rtx
);
5494 /* If the parameters of this function need cleaning up, get a label
5495 for the beginning of the code which executes those cleanups. This must
5496 be done before doing anything with return_label. */
5497 if (parms_have_cleanups
)
5498 cleanup_label
= gen_label_rtx ();
5502 /* Make the label for return statements to jump to, if this machine
5503 does not have a one-instruction return and uses an epilogue,
5504 or if it returns a structure, or if it has parm cleanups. */
5506 if (cleanup_label
== 0 && HAVE_return
5507 && ! current_function_returns_pcc_struct
5508 && ! (current_function_returns_struct
&& ! optimize
))
5511 return_label
= gen_label_rtx ();
5513 return_label
= gen_label_rtx ();
5516 /* Initialize rtx used to return the value. */
5517 /* Do this before assign_parms so that we copy the struct value address
5518 before any library calls that assign parms might generate. */
5520 /* Decide whether to return the value in memory or in a register. */
5521 if (aggregate_value_p (DECL_RESULT (subr
)))
5523 /* Returning something that won't go in a register. */
5524 register rtx value_address
= 0;
5526 #ifdef PCC_STATIC_STRUCT_RETURN
5527 if (current_function_returns_pcc_struct
)
5529 int size
= int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr
)));
5530 value_address
= assemble_static_space (size
);
5535 /* Expect to be passed the address of a place to store the value.
5536 If it is passed as an argument, assign_parms will take care of
5538 if (struct_value_incoming_rtx
)
5540 value_address
= gen_reg_rtx (Pmode
);
5541 emit_move_insn (value_address
, struct_value_incoming_rtx
);
5546 DECL_RTL (DECL_RESULT (subr
))
5547 = gen_rtx (MEM
, DECL_MODE (DECL_RESULT (subr
)), value_address
);
5548 MEM_IN_STRUCT_P (DECL_RTL (DECL_RESULT (subr
)))
5549 = AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr
)));
5552 else if (DECL_MODE (DECL_RESULT (subr
)) == VOIDmode
)
5553 /* If return mode is void, this decl rtl should not be used. */
5554 DECL_RTL (DECL_RESULT (subr
)) = 0;
5555 else if (parms_have_cleanups
)
5557 /* If function will end with cleanup code for parms,
5558 compute the return values into a pseudo reg,
5559 which we will copy into the true return register
5560 after the cleanups are done. */
5562 enum machine_mode mode
= DECL_MODE (DECL_RESULT (subr
));
5564 #ifdef PROMOTE_FUNCTION_RETURN
5565 tree type
= TREE_TYPE (DECL_RESULT (subr
));
5566 int unsignedp
= TREE_UNSIGNED (type
);
5568 mode
= promote_mode (type
, mode
, &unsignedp
, 1);
5571 DECL_RTL (DECL_RESULT (subr
)) = gen_reg_rtx (mode
);
5574 /* Scalar, returned in a register. */
5576 #ifdef FUNCTION_OUTGOING_VALUE
5577 DECL_RTL (DECL_RESULT (subr
))
5578 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr
)), subr
);
5580 DECL_RTL (DECL_RESULT (subr
))
5581 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr
)), subr
);
5584 /* Mark this reg as the function's return value. */
5585 if (GET_CODE (DECL_RTL (DECL_RESULT (subr
))) == REG
)
5587 REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr
))) = 1;
5588 /* Needed because we may need to move this to memory
5589 in case it's a named return value whose address is taken. */
5590 DECL_REGISTER (DECL_RESULT (subr
)) = 1;
5594 /* Initialize rtx for parameters and local variables.
5595 In some cases this requires emitting insns. */
5597 assign_parms (subr
, 0);
5599 /* Copy the static chain now if it wasn't a register. The delay is to
5600 avoid conflicts with the parameter passing registers. */
5602 if (SMALL_REGISTER_CLASSES
&& current_function_needs_context
)
5603 if (GET_CODE (static_chain_incoming_rtx
) != REG
)
5604 emit_move_insn (last_ptr
, static_chain_incoming_rtx
);
5606 /* The following was moved from init_function_start.
5607 The move is supposed to make sdb output more accurate. */
5608 /* Indicate the beginning of the function body,
5609 as opposed to parm setup. */
5610 emit_note (NULL_PTR
, NOTE_INSN_FUNCTION_BEG
);
5612 /* If doing stupid allocation, mark parms as born here. */
5614 if (GET_CODE (get_last_insn ()) != NOTE
)
5615 emit_note (NULL_PTR
, NOTE_INSN_DELETED
);
5616 parm_birth_insn
= get_last_insn ();
5620 for (i
= LAST_VIRTUAL_REGISTER
+ 1; i
< max_parm_reg
; i
++)
5621 use_variable (regno_reg_rtx
[i
]);
5623 if (current_function_internal_arg_pointer
!= virtual_incoming_args_rtx
)
5624 use_variable (current_function_internal_arg_pointer
);
5627 context_display
= 0;
5628 if (current_function_needs_context
)
5630 /* Fetch static chain values for containing functions. */
5631 tem
= decl_function_context (current_function_decl
);
5632 /* If not doing stupid register allocation copy the static chain
5633 pointer into a pseudo. If we have small register classes, copy
5634 the value from memory if static_chain_incoming_rtx is a REG. If
5635 we do stupid register allocation, we use the stack address
5637 if (tem
&& ! obey_regdecls
)
5639 /* If the static chain originally came in a register, put it back
5640 there, then move it out in the next insn. The reason for
5641 this peculiar code is to satisfy function integration. */
5642 if (SMALL_REGISTER_CLASSES
5643 && GET_CODE (static_chain_incoming_rtx
) == REG
)
5644 emit_move_insn (static_chain_incoming_rtx
, last_ptr
);
5645 last_ptr
= copy_to_reg (static_chain_incoming_rtx
);
5650 tree rtlexp
= make_node (RTL_EXPR
);
5652 RTL_EXPR_RTL (rtlexp
) = last_ptr
;
5653 context_display
= tree_cons (tem
, rtlexp
, context_display
);
5654 tem
= decl_function_context (tem
);
5657 /* Chain thru stack frames, assuming pointer to next lexical frame
5658 is found at the place we always store it. */
5659 #ifdef FRAME_GROWS_DOWNWARD
5660 last_ptr
= plus_constant (last_ptr
, - GET_MODE_SIZE (Pmode
));
5662 last_ptr
= copy_to_reg (gen_rtx (MEM
, Pmode
,
5663 memory_address (Pmode
, last_ptr
)));
5665 /* If we are not optimizing, ensure that we know that this
5666 piece of context is live over the entire function. */
5668 save_expr_regs
= gen_rtx (EXPR_LIST
, VOIDmode
, last_ptr
,
5673 /* After the display initializations is where the tail-recursion label
5674 should go, if we end up needing one. Ensure we have a NOTE here
5675 since some things (like trampolines) get placed before this. */
5676 tail_recursion_reentry
= emit_note (NULL_PTR
, NOTE_INSN_DELETED
);
5678 /* Evaluate now the sizes of any types declared among the arguments. */
5679 for (tem
= nreverse (get_pending_sizes ()); tem
; tem
= TREE_CHAIN (tem
))
5681 expand_expr (TREE_VALUE (tem
), const0_rtx
, VOIDmode
,
5682 EXPAND_MEMORY_USE_BAD
);
5683 /* Flush the queue in case this parameter declaration has
5688 /* Make sure there is a line number after the function entry setup code. */
5689 force_next_line_note ();
5692 /* Generate RTL for the end of the current function.
5693 FILENAME and LINE are the current position in the source file.
5695 It is up to language-specific callers to do cleanups for parameters--
5696 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */
5699 expand_function_end (filename
, line
, end_bindings
)
5707 #ifdef TRAMPOLINE_TEMPLATE
5708 static rtx initial_trampoline
;
5711 if (output_bytecode
)
5713 bc_expand_function_end ();
5717 #ifdef NON_SAVING_SETJMP
5718 /* Don't put any variables in registers if we call setjmp
5719 on a machine that fails to restore the registers. */
5720 if (NON_SAVING_SETJMP
&& current_function_calls_setjmp
)
5722 if (DECL_INITIAL (current_function_decl
) != error_mark_node
)
5723 setjmp_protect (DECL_INITIAL (current_function_decl
));
5725 setjmp_protect_args ();
5729 /* Save the argument pointer if a save area was made for it. */
5730 if (arg_pointer_save_area
)
5732 rtx x
= gen_move_insn (arg_pointer_save_area
, virtual_incoming_args_rtx
);
5733 emit_insn_before (x
, tail_recursion_reentry
);
5736 /* Initialize any trampolines required by this function. */
5737 for (link
= trampoline_list
; link
; link
= TREE_CHAIN (link
))
5739 tree function
= TREE_PURPOSE (link
);
5740 rtx context
= lookup_static_chain (function
);
5741 rtx tramp
= RTL_EXPR_RTL (TREE_VALUE (link
));
5745 #ifdef TRAMPOLINE_TEMPLATE
5746 /* First make sure this compilation has a template for
5747 initializing trampolines. */
5748 if (initial_trampoline
== 0)
5750 end_temporary_allocation ();
5752 = gen_rtx (MEM
, BLKmode
, assemble_trampoline_template ());
5753 resume_temporary_allocation ();
5757 /* Generate insns to initialize the trampoline. */
5759 tramp
= round_trampoline_addr (XEXP (tramp
, 0));
5760 #ifdef TRAMPOLINE_TEMPLATE
5761 blktramp
= change_address (initial_trampoline
, BLKmode
, tramp
);
5762 emit_block_move (blktramp
, initial_trampoline
,
5763 GEN_INT (TRAMPOLINE_SIZE
),
5764 TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
5766 INITIALIZE_TRAMPOLINE (tramp
, XEXP (DECL_RTL (function
), 0), context
);
5770 /* Put those insns at entry to the containing function (this one). */
5771 emit_insns_before (seq
, tail_recursion_reentry
);
5774 /* If we are doing stack checking and this function makes calls,
5775 do a stack probe at the start of the function to ensure we have enough
5776 space for another stack frame. */
5777 if (flag_stack_check
&& ! STACK_CHECK_BUILTIN
)
5781 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5782 if (GET_CODE (insn
) == CALL_INSN
)
5785 probe_stack_range (STACK_CHECK_PROTECT
,
5786 GEN_INT (STACK_CHECK_MAX_FRAME_SIZE
));
5789 emit_insns_before (seq
, tail_recursion_reentry
);
5794 /* Warn about unused parms if extra warnings were specified. */
5795 if (warn_unused
&& extra_warnings
)
5799 for (decl
= DECL_ARGUMENTS (current_function_decl
);
5800 decl
; decl
= TREE_CHAIN (decl
))
5801 if (! TREE_USED (decl
) && TREE_CODE (decl
) == PARM_DECL
5802 && DECL_NAME (decl
) && ! DECL_ARTIFICIAL (decl
))
5803 warning_with_decl (decl
, "unused parameter `%s'");
5806 /* Delete handlers for nonlocal gotos if nothing uses them. */
5807 if (nonlocal_goto_handler_slot
!= 0 && !current_function_has_nonlocal_label
)
5810 /* End any sequences that failed to be closed due to syntax errors. */
5811 while (in_sequence_p ())
5814 /* Outside function body, can't compute type's actual size
5815 until next function's body starts. */
5816 immediate_size_expand
--;
5818 /* If doing stupid register allocation,
5819 mark register parms as dying here. */
5824 for (i
= LAST_VIRTUAL_REGISTER
+ 1; i
< max_parm_reg
; i
++)
5825 use_variable (regno_reg_rtx
[i
]);
5827 /* Likewise for the regs of all the SAVE_EXPRs in the function. */
5829 for (tem
= save_expr_regs
; tem
; tem
= XEXP (tem
, 1))
5831 use_variable (XEXP (tem
, 0));
5832 use_variable_after (XEXP (tem
, 0), parm_birth_insn
);
5835 if (current_function_internal_arg_pointer
!= virtual_incoming_args_rtx
)
5836 use_variable (current_function_internal_arg_pointer
);
5839 clear_pending_stack_adjust ();
5840 do_pending_stack_adjust ();
5842 /* Mark the end of the function body.
5843 If control reaches this insn, the function can drop through
5844 without returning a value. */
5845 emit_note (NULL_PTR
, NOTE_INSN_FUNCTION_END
);
5847 /* Must mark the last line number note in the function, so that the test
5848 coverage code can avoid counting the last line twice. This just tells
5849 the code to ignore the immediately following line note, since there
5850 already exists a copy of this note somewhere above. This line number
5851 note is still needed for debugging though, so we can't delete it. */
5852 if (flag_test_coverage
)
5853 emit_note (NULL_PTR
, NOTE_REPEATED_LINE_NUMBER
);
5855 /* Output a linenumber for the end of the function.
5856 SDB depends on this. */
5857 emit_line_note_force (filename
, line
);
5859 /* Output the label for the actual return from the function,
5860 if one is expected. This happens either because a function epilogue
5861 is used instead of a return instruction, or because a return was done
5862 with a goto in order to run local cleanups, or because of pcc-style
5863 structure returning. */
5866 emit_label (return_label
);
5868 /* C++ uses this. */
5870 expand_end_bindings (0, 0, 0);
5872 /* Now handle any leftover exception regions that may have been
5873 created for the parameters. */
5875 rtx last
= get_last_insn ();
5878 expand_leftover_cleanups ();
5880 /* If the above emitted any code, may sure we jump around it. */
5881 if (last
!= get_last_insn ())
5883 label
= gen_label_rtx ();
5884 last
= emit_jump_insn_after (gen_jump (label
), last
);
5885 last
= emit_barrier_after (last
);
5890 /* If we had calls to alloca, and this machine needs
5891 an accurate stack pointer to exit the function,
5892 insert some code to save and restore the stack pointer. */
5893 #ifdef EXIT_IGNORE_STACK
5894 if (! EXIT_IGNORE_STACK
)
5896 if (current_function_calls_alloca
)
5900 emit_stack_save (SAVE_FUNCTION
, &tem
, parm_birth_insn
);
5901 emit_stack_restore (SAVE_FUNCTION
, tem
, NULL_RTX
);
5904 /* If scalar return value was computed in a pseudo-reg,
5905 copy that to the hard return register. */
5906 if (DECL_RTL (DECL_RESULT (current_function_decl
)) != 0
5907 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl
))) == REG
5908 && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl
)))
5909 >= FIRST_PSEUDO_REGISTER
))
5911 rtx real_decl_result
;
5913 #ifdef FUNCTION_OUTGOING_VALUE
5915 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl
)),
5916 current_function_decl
);
5919 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl
)),
5920 current_function_decl
);
5922 REG_FUNCTION_VALUE_P (real_decl_result
) = 1;
5923 /* If this is a BLKmode structure being returned in registers, then use
5924 the mode computed in expand_return. */
5925 if (GET_MODE (real_decl_result
) == BLKmode
)
5926 PUT_MODE (real_decl_result
,
5927 GET_MODE (DECL_RTL (DECL_RESULT (current_function_decl
))));
5928 emit_move_insn (real_decl_result
,
5929 DECL_RTL (DECL_RESULT (current_function_decl
)));
5930 emit_insn (gen_rtx (USE
, VOIDmode
, real_decl_result
));
5932 /* The delay slot scheduler assumes that current_function_return_rtx
5933 holds the hard register containing the return value, not a temporary
5935 current_function_return_rtx
= real_decl_result
;
5938 /* If returning a structure, arrange to return the address of the value
5939 in a place where debuggers expect to find it.
5941 If returning a structure PCC style,
5942 the caller also depends on this value.
5943 And current_function_returns_pcc_struct is not necessarily set. */
5944 if (current_function_returns_struct
5945 || current_function_returns_pcc_struct
)
5947 rtx value_address
= XEXP (DECL_RTL (DECL_RESULT (current_function_decl
)), 0);
5948 tree type
= TREE_TYPE (DECL_RESULT (current_function_decl
));
5949 #ifdef FUNCTION_OUTGOING_VALUE
5951 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type
),
5952 current_function_decl
);
5955 = FUNCTION_VALUE (build_pointer_type (type
),
5956 current_function_decl
);
5959 /* Mark this as a function return value so integrate will delete the
5960 assignment and USE below when inlining this function. */
5961 REG_FUNCTION_VALUE_P (outgoing
) = 1;
5963 emit_move_insn (outgoing
, value_address
);
5964 use_variable (outgoing
);
5967 /* Output a return insn if we are using one.
5968 Otherwise, let the rtl chain end here, to drop through
5969 into the epilogue. */
5974 emit_jump_insn (gen_return ());
5979 /* Fix up any gotos that jumped out to the outermost
5980 binding level of the function.
5981 Must follow emitting RETURN_LABEL. */
5983 /* If you have any cleanups to do at this point,
5984 and they need to create temporary variables,
5985 then you will lose. */
5986 expand_fixups (get_insns ());
5989 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
5991 static int *prologue
;
5992 static int *epilogue
;
5994 /* Create an array that records the INSN_UIDs of INSNS (either a sequence
5995 or a single insn). */
5998 record_insns (insns
)
6003 if (GET_CODE (insns
) == SEQUENCE
)
6005 int len
= XVECLEN (insns
, 0);
6006 vec
= (int *) oballoc ((len
+ 1) * sizeof (int));
6009 vec
[len
] = INSN_UID (XVECEXP (insns
, 0, len
));
6013 vec
= (int *) oballoc (2 * sizeof (int));
6014 vec
[0] = INSN_UID (insns
);
6020 /* Determine how many INSN_UIDs in VEC are part of INSN. */
6023 contains (insn
, vec
)
6029 if (GET_CODE (insn
) == INSN
6030 && GET_CODE (PATTERN (insn
)) == SEQUENCE
)
6033 for (i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
6034 for (j
= 0; vec
[j
]; j
++)
6035 if (INSN_UID (XVECEXP (PATTERN (insn
), 0, i
)) == vec
[j
])
6041 for (j
= 0; vec
[j
]; j
++)
6042 if (INSN_UID (insn
) == vec
[j
])
6048 /* Generate the prologue and epilogue RTL if the machine supports it. Thread
6049 this into place with notes indicating where the prologue ends and where
6050 the epilogue begins. Update the basic block information when possible. */
6053 thread_prologue_and_epilogue_insns (f
)
6056 #ifdef HAVE_prologue
6059 rtx head
, seq
, insn
;
6061 /* The first insn (a NOTE_INSN_DELETED) is followed by zero or more
6062 prologue insns and a NOTE_INSN_PROLOGUE_END. */
6063 emit_note_after (NOTE_INSN_PROLOGUE_END
, f
);
6064 seq
= gen_prologue ();
6065 head
= emit_insn_after (seq
, f
);
6067 /* Include the new prologue insns in the first block. Ignore them
6068 if they form a basic block unto themselves. */
6069 if (basic_block_head
&& n_basic_blocks
6070 && GET_CODE (basic_block_head
[0]) != CODE_LABEL
)
6071 basic_block_head
[0] = NEXT_INSN (f
);
6073 /* Retain a map of the prologue insns. */
6074 prologue
= record_insns (GET_CODE (seq
) == SEQUENCE
? seq
: head
);
6080 #ifdef HAVE_epilogue
6083 rtx insn
= get_last_insn ();
6084 rtx prev
= prev_nonnote_insn (insn
);
6086 /* If we end with a BARRIER, we don't need an epilogue. */
6087 if (! (prev
&& GET_CODE (prev
) == BARRIER
))
6093 /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG, the
6094 epilogue insns, the USE insns at the end of a function,
6095 the jump insn that returns, and then a BARRIER. */
6097 /* Move the USE insns at the end of a function onto a list. */
6099 && GET_CODE (prev
) == INSN
6100 && GET_CODE (PATTERN (prev
)) == USE
)
6103 prev
= prev_nonnote_insn (prev
);
6105 NEXT_INSN (PREV_INSN (tem
)) = NEXT_INSN (tem
);
6106 PREV_INSN (NEXT_INSN (tem
)) = PREV_INSN (tem
);
6109 NEXT_INSN (tem
) = first_use
;
6110 PREV_INSN (first_use
) = tem
;
6117 emit_barrier_after (insn
);
6119 seq
= gen_epilogue ();
6120 tail
= emit_jump_insn_after (seq
, insn
);
6122 /* Insert the USE insns immediately before the return insn, which
6123 must be the first instruction before the final barrier. */
6126 tem
= prev_nonnote_insn (get_last_insn ());
6127 NEXT_INSN (PREV_INSN (tem
)) = first_use
;
6128 PREV_INSN (first_use
) = PREV_INSN (tem
);
6129 PREV_INSN (tem
) = last_use
;
6130 NEXT_INSN (last_use
) = tem
;
6133 emit_note_after (NOTE_INSN_EPILOGUE_BEG
, insn
);
6135 /* Include the new epilogue insns in the last block. Ignore
6136 them if they form a basic block unto themselves. */
6137 if (basic_block_end
&& n_basic_blocks
6138 && GET_CODE (basic_block_end
[n_basic_blocks
- 1]) != JUMP_INSN
)
6139 basic_block_end
[n_basic_blocks
- 1] = tail
;
6141 /* Retain a map of the epilogue insns. */
6142 epilogue
= record_insns (GET_CODE (seq
) == SEQUENCE
? seq
: tail
);
6150 /* Reposition the prologue-end and epilogue-begin notes after instruction
6151 scheduling and delayed branch scheduling. */
6154 reposition_prologue_and_epilogue_notes (f
)
6157 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
6158 /* Reposition the prologue and epilogue notes. */
6166 register rtx insn
, note
= 0;
6168 /* Scan from the beginning until we reach the last prologue insn.
6169 We apparently can't depend on basic_block_{head,end} after
6171 for (len
= 0; prologue
[len
]; len
++)
6173 for (insn
= f
; len
&& insn
; insn
= NEXT_INSN (insn
))
6175 if (GET_CODE (insn
) == NOTE
)
6177 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_PROLOGUE_END
)
6180 else if ((len
-= contains (insn
, prologue
)) == 0)
6182 /* Find the prologue-end note if we haven't already, and
6183 move it to just after the last prologue insn. */
6186 for (note
= insn
; note
= NEXT_INSN (note
);)
6187 if (GET_CODE (note
) == NOTE
6188 && NOTE_LINE_NUMBER (note
) == NOTE_INSN_PROLOGUE_END
)
6191 next
= NEXT_INSN (note
);
6192 prev
= PREV_INSN (note
);
6194 NEXT_INSN (prev
) = next
;
6196 PREV_INSN (next
) = prev
;
6197 add_insn_after (note
, insn
);
6204 register rtx insn
, note
= 0;
6206 /* Scan from the end until we reach the first epilogue insn.
6207 We apparently can't depend on basic_block_{head,end} after
6209 for (len
= 0; epilogue
[len
]; len
++)
6211 for (insn
= get_last_insn (); len
&& insn
; insn
= PREV_INSN (insn
))
6213 if (GET_CODE (insn
) == NOTE
)
6215 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_EPILOGUE_BEG
)
6218 else if ((len
-= contains (insn
, epilogue
)) == 0)
6220 /* Find the epilogue-begin note if we haven't already, and
6221 move it to just before the first epilogue insn. */
6224 for (note
= insn
; note
= PREV_INSN (note
);)
6225 if (GET_CODE (note
) == NOTE
6226 && NOTE_LINE_NUMBER (note
) == NOTE_INSN_EPILOGUE_BEG
)
6229 next
= NEXT_INSN (note
);
6230 prev
= PREV_INSN (note
);
6232 NEXT_INSN (prev
) = next
;
6234 PREV_INSN (next
) = prev
;
6235 add_insn_after (note
, PREV_INSN (insn
));
6240 #endif /* HAVE_prologue or HAVE_epilogue */