1 /* Convert function calls to rtl insns, for GNU C compiler.
2 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998
3 1999, 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
30 #include "insn-flags.h"
35 #ifndef ACCUMULATE_OUTGOING_ARGS
36 #define ACCUMULATE_OUTGOING_ARGS 0
39 /* Supply a default definition for PUSH_ARGS. */
42 #define PUSH_ARGS !ACCUMULATE_OUTGOING_ARGS
48 #if !defined FUNCTION_OK_FOR_SIBCALL
49 #define FUNCTION_OK_FOR_SIBCALL(DECL) 1
52 #if !defined PREFERRED_STACK_BOUNDARY && defined STACK_BOUNDARY
53 #define PREFERRED_STACK_BOUNDARY STACK_BOUNDARY
56 /* Decide whether a function's arguments should be processed
57 from first to last or from last to first.
59 They should if the stack and args grow in opposite directions, but
60 only if we have push insns. */
64 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
65 #define PUSH_ARGS_REVERSED PUSH_ARGS
70 #ifndef PUSH_ARGS_REVERSED
71 #define PUSH_ARGS_REVERSED 0
74 /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */
75 #define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
77 /* Data structure and subroutines used within expand_call. */
81 /* Tree node for this argument. */
83 /* Mode for value; TYPE_MODE unless promoted. */
84 enum machine_mode mode;
85 /* Current RTL value for argument, or 0 if it isn't precomputed. */
87 /* Initially-compute RTL value for argument; only for const functions. */
89 /* Register to pass this argument in, 0 if passed on stack, or an
90 PARALLEL if the arg is to be copied into multiple non-contiguous
93 /* If REG was promoted from the actual mode of the argument expression,
94 indicates whether the promotion is sign- or zero-extended. */
96 /* Number of registers to use. 0 means put the whole arg in registers.
97 Also 0 if not passed in registers. */
99 /* Non-zero if argument must be passed on stack.
100 Note that some arguments may be passed on the stack
101 even though pass_on_stack is zero, just because FUNCTION_ARG says so.
102 pass_on_stack identifies arguments that *cannot* go in registers. */
104 /* Offset of this argument from beginning of stack-args. */
105 struct args_size offset;
106 /* Similar, but offset to the start of the stack slot. Different from
107 OFFSET if this arg pads downward. */
108 struct args_size slot_offset;
109 /* Size of this argument on the stack, rounded up for any padding it gets,
110 parts of the argument passed in registers do not count.
111 If REG_PARM_STACK_SPACE is defined, then register parms
112 are counted here as well. */
113 struct args_size size;
114 /* Location on the stack at which parameter should be stored. The store
115 has already been done if STACK == VALUE. */
117 /* Location on the stack of the start of this argument slot. This can
118 differ from STACK if this arg pads downward. This location is known
119 to be aligned to FUNCTION_ARG_BOUNDARY. */
121 /* Place that this stack area has been saved, if needed. */
123 /* If an argument's alignment does not permit direct copying into registers,
124 copy in smaller-sized pieces into pseudos. These are stored in a
125 block pointed to by this field. The next field says how many
126 word-sized pseudos we made. */
129 /* The amount that the stack pointer needs to be adjusted to
130 force alignment for the next argument. */
131 struct args_size alignment_pad;
134 /* A vector of one char per byte of stack space. A byte if non-zero if
135 the corresponding stack location has been used.
136 This vector is used to prevent a function call within an argument from
137 clobbering any stack already set up. */
138 static char *stack_usage_map;
140 /* Size of STACK_USAGE_MAP. */
141 static int highest_outgoing_arg_in_use;
143 /* stack_arg_under_construction is nonzero when an argument may be
144 initialized with a constructor call (including a C function that
145 returns a BLKmode struct) and expand_call must take special action
146 to make sure the object being constructed does not overlap the
147 argument list for the constructor call. */
148 int stack_arg_under_construction;
150 static int calls_function PARAMS ((tree, int));
151 static int calls_function_1 PARAMS ((tree, int));
153 /* Nonzero if this is a call to a `const' function. */
155 /* Nonzero if this is a call to a `volatile' function. */
156 #define ECF_NORETURN 2
157 /* Nonzero if this is a call to malloc or a related function. */
159 /* Nonzero if it is plausible that this is a call to alloca. */
160 #define ECF_MAY_BE_ALLOCA 8
161 /* Nonzero if this is a call to a function that won't throw an exception. */
162 #define ECF_NOTHROW 16
163 /* Nonzero if this is a call to setjmp or a related function. */
164 #define ECF_RETURNS_TWICE 32
165 /* Nonzero if this is a call to `longjmp'. */
166 #define ECF_LONGJMP 64
167 /* Nonzero if this is a syscall that makes a new process in the image of
169 #define ECF_FORK_OR_EXEC 128
170 #define ECF_SIBCALL 256
171 /* Nonzero if this is a call to "pure" function (like const function,
172 but may read memory. */
175 static void emit_call_1 PARAMS ((rtx, tree, tree, HOST_WIDE_INT,
176 HOST_WIDE_INT, HOST_WIDE_INT, rtx,
177 rtx, int, rtx, int));
178 static void precompute_register_parameters PARAMS ((int,
181 static void store_one_arg PARAMS ((struct arg_data *, rtx, int, int,
183 static void store_unaligned_arguments_into_pseudos PARAMS ((struct arg_data *,
185 static int finalize_must_preallocate PARAMS ((int, int,
187 struct args_size *));
188 static void precompute_arguments PARAMS ((int, int,
190 static int compute_argument_block_size PARAMS ((int,
193 static void initialize_argument_information PARAMS ((int,
200 static void compute_argument_addresses PARAMS ((struct arg_data *,
202 static rtx rtx_for_function_call PARAMS ((tree, tree));
203 static void load_register_parameters PARAMS ((struct arg_data *,
205 static int libfunc_nothrow PARAMS ((rtx));
206 static rtx emit_library_call_value_1 PARAMS ((int, rtx, rtx, int,
209 static int special_function_p PARAMS ((tree, int));
210 static int flags_from_decl_or_type PARAMS ((tree));
211 static rtx try_to_integrate PARAMS ((tree, tree, rtx,
213 static int combine_pending_stack_adjustment_and_call
214 PARAMS ((int, struct args_size *, int));
216 #ifdef REG_PARM_STACK_SPACE
217 static rtx save_fixed_argument_area PARAMS ((int, rtx, int *, int *));
218 static void restore_fixed_argument_area PARAMS ((rtx, rtx, int, int));
221 /* If WHICH is 1, return 1 if EXP contains a call to the built-in function
224 If WHICH is 0, return 1 if EXP contains a call to any function.
225 Actually, we only need return 1 if evaluating EXP would require pushing
226 arguments on the stack, but that is too difficult to compute, so we just
227 assume any function call might require the stack. */
229 static tree calls_function_save_exprs;
232 calls_function (exp, which)
237 calls_function_save_exprs = 0;
238 val = calls_function_1 (exp, which);
239 calls_function_save_exprs = 0;
244 calls_function_1 (exp, which)
249 enum tree_code code = TREE_CODE (exp);
250 int type = TREE_CODE_CLASS (code);
251 int length = tree_code_length[(int) code];
253 /* If this code is language-specific, we don't know what it will do. */
254 if ((int) code >= NUM_TREE_CODES)
262 else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
263 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
266 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
267 int flags = special_function_p (fndecl, 0);
268 if (flags & ECF_MAY_BE_ALLOCA)
272 /* Third operand is RTL. */
277 if (SAVE_EXPR_RTL (exp) != 0)
279 if (value_member (exp, calls_function_save_exprs))
281 calls_function_save_exprs = tree_cons (NULL_TREE, exp,
282 calls_function_save_exprs);
283 return (TREE_OPERAND (exp, 0) != 0
284 && calls_function_1 (TREE_OPERAND (exp, 0), which));
290 for (local = BLOCK_VARS (exp); local; local = TREE_CHAIN (local))
291 if (DECL_INITIAL (local) != 0
292 && calls_function_1 (DECL_INITIAL (local), which))
296 register tree subblock;
298 for (subblock = BLOCK_SUBBLOCKS (exp);
300 subblock = TREE_CHAIN (subblock))
301 if (calls_function_1 (subblock, which))
306 for (; exp != 0; exp = TREE_CHAIN (exp))
307 if (calls_function_1 (TREE_VALUE (exp), which))
311 case METHOD_CALL_EXPR:
315 case WITH_CLEANUP_EXPR:
326 /* Only expressions and references can contain calls. */
327 if (type != 'e' && type != '<' && type != '1' && type != '2' && type != 'r'
331 for (i = 0; i < length; i++)
332 if (TREE_OPERAND (exp, i) != 0
333 && calls_function_1 (TREE_OPERAND (exp, i), which))
339 /* Force FUNEXP into a form suitable for the address of a CALL,
340 and return that as an rtx. Also load the static chain register
341 if FNDECL is a nested function.
343 CALL_FUSAGE points to a variable holding the prospective
344 CALL_INSN_FUNCTION_USAGE information. */
347 prepare_call_address (funexp, fndecl, call_fusage, reg_parm_seen)
353 rtx static_chain_value = 0;
355 funexp = protect_from_queue (funexp, 0);
358 /* Get possible static chain value for nested function in C. */
359 static_chain_value = lookup_static_chain (fndecl);
361 /* Make a valid memory address and copy constants thru pseudo-regs,
362 but not for a constant address if -fno-function-cse. */
363 if (GET_CODE (funexp) != SYMBOL_REF)
364 /* If we are using registers for parameters, force the
365 function address into a register now. */
366 funexp = ((SMALL_REGISTER_CLASSES && reg_parm_seen)
367 ? force_not_mem (memory_address (FUNCTION_MODE, funexp))
368 : memory_address (FUNCTION_MODE, funexp));
371 #ifndef NO_FUNCTION_CSE
372 if (optimize && ! flag_no_function_cse)
373 #ifdef NO_RECURSIVE_FUNCTION_CSE
374 if (fndecl != current_function_decl)
376 funexp = force_reg (Pmode, funexp);
380 if (static_chain_value != 0)
382 emit_move_insn (static_chain_rtx, static_chain_value);
384 if (GET_CODE (static_chain_rtx) == REG)
385 use_reg (call_fusage, static_chain_rtx);
391 /* Generate instructions to call function FUNEXP,
392 and optionally pop the results.
393 The CALL_INSN is the first insn generated.
395 FNDECL is the declaration node of the function. This is given to the
396 macro RETURN_POPS_ARGS to determine whether this function pops its own args.
398 FUNTYPE is the data type of the function. This is given to the macro
399 RETURN_POPS_ARGS to determine whether this function pops its own args.
400 We used to allow an identifier for library functions, but that doesn't
401 work when the return type is an aggregate type and the calling convention
402 says that the pointer to this aggregate is to be popped by the callee.
404 STACK_SIZE is the number of bytes of arguments on the stack,
405 ROUNDED_STACK_SIZE is that number rounded up to
406 PREFERRED_STACK_BOUNDARY; zero if the size is variable. This is
407 both to put into the call insn and to generate explicit popping
410 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
411 It is zero if this call doesn't want a structure value.
413 NEXT_ARG_REG is the rtx that results from executing
414 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1)
415 just after all the args have had their registers assigned.
416 This could be whatever you like, but normally it is the first
417 arg-register beyond those used for args in this call,
418 or 0 if all the arg-registers are used in this call.
419 It is passed on to `gen_call' so you can put this info in the call insn.
421 VALREG is a hard register in which a value is returned,
422 or 0 if the call does not return a value.
424 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
425 the args to this call were processed.
426 We restore `inhibit_defer_pop' to that value.
428 CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
429 denote registers used by the called function. */
432 emit_call_1 (funexp, fndecl, funtype, stack_size, rounded_stack_size,
433 struct_value_size, next_arg_reg, valreg, old_inhibit_defer_pop,
434 call_fusage, ecf_flags)
436 tree fndecl ATTRIBUTE_UNUSED;
437 tree funtype ATTRIBUTE_UNUSED;
438 HOST_WIDE_INT stack_size ATTRIBUTE_UNUSED;
439 HOST_WIDE_INT rounded_stack_size;
440 HOST_WIDE_INT struct_value_size ATTRIBUTE_UNUSED;
443 int old_inhibit_defer_pop;
447 rtx rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
448 #if defined (HAVE_call) && defined (HAVE_call_value)
449 rtx struct_value_size_rtx = GEN_INT (struct_value_size);
452 int already_popped = 0;
453 HOST_WIDE_INT n_popped = RETURN_POPS_ARGS (fndecl, funtype, stack_size);
455 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
456 and we don't want to load it into a register as an optimization,
457 because prepare_call_address already did it if it should be done. */
458 if (GET_CODE (funexp) != SYMBOL_REF)
459 funexp = memory_address (FUNCTION_MODE, funexp);
461 #if defined (HAVE_sibcall_pop) && defined (HAVE_sibcall_value_pop)
462 if ((ecf_flags & ECF_SIBCALL)
463 && HAVE_sibcall_pop && HAVE_sibcall_value_pop
464 && (RETURN_POPS_ARGS (fndecl, funtype, stack_size) > 0
467 rtx n_pop = GEN_INT (RETURN_POPS_ARGS (fndecl, funtype, stack_size));
470 /* If this subroutine pops its own args, record that in the call insn
471 if possible, for the sake of frame pointer elimination. */
474 pat = gen_sibcall_value_pop (valreg,
475 gen_rtx_MEM (FUNCTION_MODE, funexp),
476 rounded_stack_size_rtx, next_arg_reg,
479 pat = gen_sibcall_pop (gen_rtx_MEM (FUNCTION_MODE, funexp),
480 rounded_stack_size_rtx, next_arg_reg, n_pop);
482 emit_call_insn (pat);
488 #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
489 /* If the target has "call" or "call_value" insns, then prefer them
490 if no arguments are actually popped. If the target does not have
491 "call" or "call_value" insns, then we must use the popping versions
492 even if the call has no arguments to pop. */
493 #if defined (HAVE_call) && defined (HAVE_call_value)
494 if (HAVE_call && HAVE_call_value && HAVE_call_pop && HAVE_call_value_pop
497 if (HAVE_call_pop && HAVE_call_value_pop)
500 rtx n_pop = GEN_INT (n_popped);
503 /* If this subroutine pops its own args, record that in the call insn
504 if possible, for the sake of frame pointer elimination. */
507 pat = gen_call_value_pop (valreg,
508 gen_rtx_MEM (FUNCTION_MODE, funexp),
509 rounded_stack_size_rtx, next_arg_reg, n_pop);
511 pat = gen_call_pop (gen_rtx_MEM (FUNCTION_MODE, funexp),
512 rounded_stack_size_rtx, next_arg_reg, n_pop);
514 emit_call_insn (pat);
520 #if defined (HAVE_sibcall) && defined (HAVE_sibcall_value)
521 if ((ecf_flags & ECF_SIBCALL)
522 && HAVE_sibcall && HAVE_sibcall_value)
525 emit_call_insn (gen_sibcall_value (valreg,
526 gen_rtx_MEM (FUNCTION_MODE, funexp),
527 rounded_stack_size_rtx,
528 next_arg_reg, NULL_RTX));
530 emit_call_insn (gen_sibcall (gen_rtx_MEM (FUNCTION_MODE, funexp),
531 rounded_stack_size_rtx, next_arg_reg,
532 struct_value_size_rtx));
537 #if defined (HAVE_call) && defined (HAVE_call_value)
538 if (HAVE_call && HAVE_call_value)
541 emit_call_insn (gen_call_value (valreg,
542 gen_rtx_MEM (FUNCTION_MODE, funexp),
543 rounded_stack_size_rtx, next_arg_reg,
546 emit_call_insn (gen_call (gen_rtx_MEM (FUNCTION_MODE, funexp),
547 rounded_stack_size_rtx, next_arg_reg,
548 struct_value_size_rtx));
554 /* Find the CALL insn we just emitted. */
555 for (call_insn = get_last_insn ();
556 call_insn && GET_CODE (call_insn) != CALL_INSN;
557 call_insn = PREV_INSN (call_insn))
563 /* Mark memory as used for "pure" function call. */
564 if (ecf_flags & ECF_PURE)
566 call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
567 gen_rtx_USE (VOIDmode,
568 gen_rtx_MEM (BLKmode,
569 gen_rtx_SCRATCH (VOIDmode))), call_fusage);
572 /* Put the register usage information on the CALL. If there is already
573 some usage information, put ours at the end. */
574 if (CALL_INSN_FUNCTION_USAGE (call_insn))
578 for (link = CALL_INSN_FUNCTION_USAGE (call_insn); XEXP (link, 1) != 0;
579 link = XEXP (link, 1))
582 XEXP (link, 1) = call_fusage;
585 CALL_INSN_FUNCTION_USAGE (call_insn) = call_fusage;
587 /* If this is a const call, then set the insn's unchanging bit. */
588 if (ecf_flags & (ECF_CONST | ECF_PURE))
589 CONST_CALL_P (call_insn) = 1;
591 /* If this call can't throw, attach a REG_EH_REGION reg note to that
593 if (ecf_flags & ECF_NOTHROW)
594 REG_NOTES (call_insn) = gen_rtx_EXPR_LIST (REG_EH_REGION, const0_rtx,
595 REG_NOTES (call_insn));
597 SIBLING_CALL_P (call_insn) = ((ecf_flags & ECF_SIBCALL) != 0);
599 /* Restore this now, so that we do defer pops for this call's args
600 if the context of the call as a whole permits. */
601 inhibit_defer_pop = old_inhibit_defer_pop;
606 CALL_INSN_FUNCTION_USAGE (call_insn)
607 = gen_rtx_EXPR_LIST (VOIDmode,
608 gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx),
609 CALL_INSN_FUNCTION_USAGE (call_insn));
610 rounded_stack_size -= n_popped;
611 rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
612 stack_pointer_delta -= n_popped;
615 if (!ACCUMULATE_OUTGOING_ARGS)
617 /* If returning from the subroutine does not automatically pop the args,
618 we need an instruction to pop them sooner or later.
619 Perhaps do it now; perhaps just record how much space to pop later.
621 If returning from the subroutine does pop the args, indicate that the
622 stack pointer will be changed. */
624 if (rounded_stack_size != 0)
626 if (flag_defer_pop && inhibit_defer_pop == 0
627 && !(ecf_flags & (ECF_CONST | ECF_PURE)))
628 pending_stack_adjust += rounded_stack_size;
630 adjust_stack (rounded_stack_size_rtx);
633 /* When we accumulate outgoing args, we must avoid any stack manipulations.
634 Restore the stack pointer to its original value now. Usually
635 ACCUMULATE_OUTGOING_ARGS targets don't get here, but there are exceptions.
636 On i386 ACCUMULATE_OUTGOING_ARGS can be enabled on demand, and
637 popping variants of functions exist as well.
639 ??? We may optimize similar to defer_pop above, but it is
640 probably not worthwhile.
642 ??? It will be worthwhile to enable combine_stack_adjustments even for
645 anti_adjust_stack (GEN_INT (n_popped));
648 /* Determine if the function identified by NAME and FNDECL is one with
649 special properties we wish to know about.
651 For example, if the function might return more than one time (setjmp), then
652 set RETURNS_TWICE to a nonzero value.
654 Similarly set LONGJMP for if the function is in the longjmp family.
656 Set MALLOC for any of the standard memory allocation functions which
657 allocate from the heap.
659 Set MAY_BE_ALLOCA for any memory allocation function that might allocate
660 space from the stack such as alloca. */
663 special_function_p (fndecl, flags)
667 if (! (flags & ECF_MALLOC)
668 && fndecl && DECL_NAME (fndecl)
669 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 17
670 /* Exclude functions not at the file scope, or not `extern',
671 since they are not the magic functions we would otherwise
673 && DECL_CONTEXT (fndecl) == NULL_TREE && TREE_PUBLIC (fndecl))
675 char *name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
678 /* We assume that alloca will always be called by name. It
679 makes no sense to pass it as a pointer-to-function to
680 anything that does not understand its behavior. */
681 if (((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 6
683 && ! strcmp (name, "alloca"))
684 || (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 16
686 && ! strcmp (name, "__builtin_alloca"))))
687 flags |= ECF_MAY_BE_ALLOCA;
689 /* Disregard prefix _, __ or __x. */
692 if (name[1] == '_' && name[2] == 'x')
694 else if (name[1] == '_')
703 && (! strcmp (tname, "setjmp")
704 || ! strcmp (tname, "setjmp_syscall")))
706 && ! strcmp (tname, "sigsetjmp"))
708 && ! strcmp (tname, "savectx")))
709 flags |= ECF_RETURNS_TWICE;
712 && ! strcmp (tname, "siglongjmp"))
713 flags |= ECF_LONGJMP;
715 else if ((tname[0] == 'q' && tname[1] == 's'
716 && ! strcmp (tname, "qsetjmp"))
717 || (tname[0] == 'v' && tname[1] == 'f'
718 && ! strcmp (tname, "vfork")))
719 flags |= ECF_RETURNS_TWICE;
721 else if (tname[0] == 'l' && tname[1] == 'o'
722 && ! strcmp (tname, "longjmp"))
723 flags |= ECF_LONGJMP;
725 else if ((tname[0] == 'f' && tname[1] == 'o'
726 && ! strcmp (tname, "fork"))
727 /* Linux specific: __clone. check NAME to insist on the
728 leading underscores, to avoid polluting the ISO / POSIX
730 || (name[0] == '_' && name[1] == '_'
731 && ! strcmp (tname, "clone"))
732 || (tname[0] == 'e' && tname[1] == 'x' && tname[2] == 'e'
733 && tname[3] == 'c' && (tname[4] == 'l' || tname[4] == 'v')
735 || ((tname[5] == 'p' || tname[5] == 'e')
736 && tname[6] == '\0'))))
737 flags |= ECF_FORK_OR_EXEC;
739 /* Do not add any more malloc-like functions to this list,
740 instead mark them as malloc functions using the malloc attribute.
741 Note, realloc is not suitable for attribute malloc since
742 it may return the same address across multiple calls.
743 C++ operator new is not suitable because it is not required
744 to return a unique pointer; indeed, the standard placement new
745 just returns its argument. */
746 else if (TYPE_MODE (TREE_TYPE (TREE_TYPE (fndecl))) == Pmode
747 && (! strcmp (tname, "malloc")
748 || ! strcmp (tname, "calloc")
749 || ! strcmp (tname, "strdup")))
755 /* Return nonzero when tree represent call to longjmp. */
757 setjmp_call_p (fndecl)
760 return special_function_p (fndecl, 0) & ECF_RETURNS_TWICE;
763 /* Detect flags (function attributes) from the function type node. */
765 flags_from_decl_or_type (exp)
769 /* ??? We can't set IS_MALLOC for function types? */
772 /* The function exp may have the `malloc' attribute. */
773 if (DECL_P (exp) && DECL_IS_MALLOC (exp))
776 /* The function exp may have the `pure' attribute. */
777 if (DECL_P (exp) && DECL_IS_PURE (exp))
780 if (TREE_NOTHROW (exp))
781 flags |= ECF_NOTHROW;
784 if (TREE_READONLY (exp) && !TREE_THIS_VOLATILE (exp))
787 if (TREE_THIS_VOLATILE (exp))
788 flags |= ECF_NORETURN;
794 /* Precompute all register parameters as described by ARGS, storing values
795 into fields within the ARGS array.
797 NUM_ACTUALS indicates the total number elements in the ARGS array.
799 Set REG_PARM_SEEN if we encounter a register parameter. */
802 precompute_register_parameters (num_actuals, args, reg_parm_seen)
804 struct arg_data *args;
811 for (i = 0; i < num_actuals; i++)
812 if (args[i].reg != 0 && ! args[i].pass_on_stack)
816 if (args[i].value == 0)
819 args[i].value = expand_expr (args[i].tree_value, NULL_RTX,
821 preserve_temp_slots (args[i].value);
824 /* ANSI doesn't require a sequence point here,
825 but PCC has one, so this will avoid some problems. */
829 /* If we are to promote the function arg to a wider mode,
832 if (args[i].mode != TYPE_MODE (TREE_TYPE (args[i].tree_value)))
834 = convert_modes (args[i].mode,
835 TYPE_MODE (TREE_TYPE (args[i].tree_value)),
836 args[i].value, args[i].unsignedp);
838 /* If the value is expensive, and we are inside an appropriately
839 short loop, put the value into a pseudo and then put the pseudo
842 For small register classes, also do this if this call uses
843 register parameters. This is to avoid reload conflicts while
844 loading the parameters registers. */
846 if ((! (GET_CODE (args[i].value) == REG
847 || (GET_CODE (args[i].value) == SUBREG
848 && GET_CODE (SUBREG_REG (args[i].value)) == REG)))
849 && args[i].mode != BLKmode
850 && rtx_cost (args[i].value, SET) > 2
851 && ((SMALL_REGISTER_CLASSES && *reg_parm_seen)
852 || preserve_subexpressions_p ()))
853 args[i].value = copy_to_mode_reg (args[i].mode, args[i].value);
857 #ifdef REG_PARM_STACK_SPACE
859 /* The argument list is the property of the called routine and it
860 may clobber it. If the fixed area has been used for previous
861 parameters, we must save and restore it. */
863 save_fixed_argument_area (reg_parm_stack_space, argblock,
864 low_to_save, high_to_save)
865 int reg_parm_stack_space;
871 rtx save_area = NULL_RTX;
873 /* Compute the boundary of the that needs to be saved, if any. */
874 #ifdef ARGS_GROW_DOWNWARD
875 for (i = 0; i < reg_parm_stack_space + 1; i++)
877 for (i = 0; i < reg_parm_stack_space; i++)
880 if (i >= highest_outgoing_arg_in_use
881 || stack_usage_map[i] == 0)
884 if (*low_to_save == -1)
890 if (*low_to_save >= 0)
892 int num_to_save = *high_to_save - *low_to_save + 1;
893 enum machine_mode save_mode
894 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
897 /* If we don't have the required alignment, must do this in BLKmode. */
898 if ((*low_to_save & (MIN (GET_MODE_SIZE (save_mode),
899 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
902 #ifdef ARGS_GROW_DOWNWARD
903 stack_area = gen_rtx_MEM (save_mode,
904 memory_address (save_mode,
905 plus_constant (argblock,
908 stack_area = gen_rtx_MEM (save_mode,
909 memory_address (save_mode,
910 plus_constant (argblock,
913 if (save_mode == BLKmode)
915 save_area = assign_stack_temp (BLKmode, num_to_save, 0);
916 /* Cannot use emit_block_move here because it can be done by a
917 library call which in turn gets into this place again and deadly
918 infinite recursion happens. */
919 move_by_pieces (validize_mem (save_area), stack_area, num_to_save,
924 save_area = gen_reg_rtx (save_mode);
925 emit_move_insn (save_area, stack_area);
932 restore_fixed_argument_area (save_area, argblock, high_to_save, low_to_save)
938 enum machine_mode save_mode = GET_MODE (save_area);
939 #ifdef ARGS_GROW_DOWNWARD
941 = gen_rtx_MEM (save_mode,
942 memory_address (save_mode,
943 plus_constant (argblock,
947 = gen_rtx_MEM (save_mode,
948 memory_address (save_mode,
949 plus_constant (argblock,
953 if (save_mode != BLKmode)
954 emit_move_insn (stack_area, save_area);
956 /* Cannot use emit_block_move here because it can be done by a library
957 call which in turn gets into this place again and deadly infinite
958 recursion happens. */
959 move_by_pieces (stack_area, validize_mem (save_area),
960 high_to_save - low_to_save + 1, PARM_BOUNDARY);
964 /* If any elements in ARGS refer to parameters that are to be passed in
965 registers, but not in memory, and whose alignment does not permit a
966 direct copy into registers. Copy the values into a group of pseudos
967 which we will later copy into the appropriate hard registers.
969 Pseudos for each unaligned argument will be stored into the array
970 args[argnum].aligned_regs. The caller is responsible for deallocating
971 the aligned_regs array if it is nonzero. */
974 store_unaligned_arguments_into_pseudos (args, num_actuals)
975 struct arg_data *args;
980 for (i = 0; i < num_actuals; i++)
981 if (args[i].reg != 0 && ! args[i].pass_on_stack
982 && args[i].mode == BLKmode
983 && (TYPE_ALIGN (TREE_TYPE (args[i].tree_value))
984 < (unsigned int) MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD)))
986 int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
987 int big_endian_correction = 0;
989 args[i].n_aligned_regs
990 = args[i].partial ? args[i].partial
991 : (bytes + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
993 args[i].aligned_regs = (rtx *) xmalloc (sizeof (rtx)
994 * args[i].n_aligned_regs);
996 /* Structures smaller than a word are aligned to the least
997 significant byte (to the right). On a BYTES_BIG_ENDIAN machine,
998 this means we must skip the empty high order bytes when
999 calculating the bit offset. */
1000 if (BYTES_BIG_ENDIAN && bytes < UNITS_PER_WORD)
1001 big_endian_correction = (BITS_PER_WORD - (bytes * BITS_PER_UNIT));
1003 for (j = 0; j < args[i].n_aligned_regs; j++)
1005 rtx reg = gen_reg_rtx (word_mode);
1006 rtx word = operand_subword_force (args[i].value, j, BLKmode);
1007 int bitsize = MIN (bytes * BITS_PER_UNIT, BITS_PER_WORD);
1008 int bitalign = TYPE_ALIGN (TREE_TYPE (args[i].tree_value));
1010 args[i].aligned_regs[j] = reg;
1012 /* There is no need to restrict this code to loading items
1013 in TYPE_ALIGN sized hunks. The bitfield instructions can
1014 load up entire word sized registers efficiently.
1016 ??? This may not be needed anymore.
1017 We use to emit a clobber here but that doesn't let later
1018 passes optimize the instructions we emit. By storing 0 into
1019 the register later passes know the first AND to zero out the
1020 bitfield being set in the register is unnecessary. The store
1021 of 0 will be deleted as will at least the first AND. */
1023 emit_move_insn (reg, const0_rtx);
1025 bytes -= bitsize / BITS_PER_UNIT;
1026 store_bit_field (reg, bitsize, big_endian_correction, word_mode,
1027 extract_bit_field (word, bitsize, 0, 1, NULL_RTX,
1028 word_mode, word_mode, bitalign,
1030 bitalign, BITS_PER_WORD);
1035 /* Fill in ARGS_SIZE and ARGS array based on the parameters found in
1038 NUM_ACTUALS is the total number of parameters.
1040 N_NAMED_ARGS is the total number of named arguments.
1042 FNDECL is the tree code for the target of this call (if known)
1044 ARGS_SO_FAR holds state needed by the target to know where to place
1047 REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
1048 for arguments which are passed in registers.
1050 OLD_STACK_LEVEL is a pointer to an rtx which olds the old stack level
1051 and may be modified by this routine.
1053 OLD_PENDING_ADJ, MUST_PREALLOCATE and FLAGS are pointers to integer
1054 flags which may may be modified by this routine. */
1057 initialize_argument_information (num_actuals, args, args_size, n_named_args,
1058 actparms, fndecl, args_so_far,
1059 reg_parm_stack_space, old_stack_level,
1060 old_pending_adj, must_preallocate,
1062 int num_actuals ATTRIBUTE_UNUSED;
1063 struct arg_data *args;
1064 struct args_size *args_size;
1065 int n_named_args ATTRIBUTE_UNUSED;
1068 CUMULATIVE_ARGS *args_so_far;
1069 int reg_parm_stack_space;
1070 rtx *old_stack_level;
1071 int *old_pending_adj;
1072 int *must_preallocate;
1075 /* 1 if scanning parms front to back, -1 if scanning back to front. */
1078 /* Count arg position in order args appear. */
1081 struct args_size alignment_pad;
1085 args_size->constant = 0;
1088 /* In this loop, we consider args in the order they are written.
1089 We fill up ARGS from the front or from the back if necessary
1090 so that in any case the first arg to be pushed ends up at the front. */
1092 if (PUSH_ARGS_REVERSED)
1094 i = num_actuals - 1, inc = -1;
1095 /* In this case, must reverse order of args
1096 so that we compute and push the last arg first. */
1103 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
1104 for (p = actparms, argpos = 0; p; p = TREE_CHAIN (p), i += inc, argpos++)
1106 tree type = TREE_TYPE (TREE_VALUE (p));
1108 enum machine_mode mode;
1110 args[i].tree_value = TREE_VALUE (p);
1112 /* Replace erroneous argument with constant zero. */
1113 if (type == error_mark_node || !COMPLETE_TYPE_P (type))
1114 args[i].tree_value = integer_zero_node, type = integer_type_node;
1116 /* If TYPE is a transparent union, pass things the way we would
1117 pass the first field of the union. We have already verified that
1118 the modes are the same. */
1119 if (TYPE_TRANSPARENT_UNION (type))
1120 type = TREE_TYPE (TYPE_FIELDS (type));
1122 /* Decide where to pass this arg.
1124 args[i].reg is nonzero if all or part is passed in registers.
1126 args[i].partial is nonzero if part but not all is passed in registers,
1127 and the exact value says how many words are passed in registers.
1129 args[i].pass_on_stack is nonzero if the argument must at least be
1130 computed on the stack. It may then be loaded back into registers
1131 if args[i].reg is nonzero.
1133 These decisions are driven by the FUNCTION_... macros and must agree
1134 with those made by function.c. */
1136 /* See if this argument should be passed by invisible reference. */
1137 if ((TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
1138 && contains_placeholder_p (TYPE_SIZE (type)))
1139 || TREE_ADDRESSABLE (type)
1140 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
1141 || FUNCTION_ARG_PASS_BY_REFERENCE (*args_so_far, TYPE_MODE (type),
1142 type, argpos < n_named_args)
1146 /* If we're compiling a thunk, pass through invisible
1147 references instead of making a copy. */
1148 if (current_function_is_thunk
1149 #ifdef FUNCTION_ARG_CALLEE_COPIES
1150 || (FUNCTION_ARG_CALLEE_COPIES (*args_so_far, TYPE_MODE (type),
1151 type, argpos < n_named_args)
1152 /* If it's in a register, we must make a copy of it too. */
1153 /* ??? Is this a sufficient test? Is there a better one? */
1154 && !(TREE_CODE (args[i].tree_value) == VAR_DECL
1155 && REG_P (DECL_RTL (args[i].tree_value)))
1156 && ! TREE_ADDRESSABLE (type))
1160 /* C++ uses a TARGET_EXPR to indicate that we want to make a
1161 new object from the argument. If we are passing by
1162 invisible reference, the callee will do that for us, so we
1163 can strip off the TARGET_EXPR. This is not always safe,
1164 but it is safe in the only case where this is a useful
1165 optimization; namely, when the argument is a plain object.
1166 In that case, the frontend is just asking the backend to
1167 make a bitwise copy of the argument. */
1169 if (TREE_CODE (args[i].tree_value) == TARGET_EXPR
1170 && (DECL_P (TREE_OPERAND (args[i].tree_value, 1)))
1171 && ! REG_P (DECL_RTL (TREE_OPERAND (args[i].tree_value, 1))))
1172 args[i].tree_value = TREE_OPERAND (args[i].tree_value, 1);
1174 args[i].tree_value = build1 (ADDR_EXPR,
1175 build_pointer_type (type),
1176 args[i].tree_value);
1177 type = build_pointer_type (type);
1181 /* We make a copy of the object and pass the address to the
1182 function being called. */
1185 if (!COMPLETE_TYPE_P (type)
1186 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
1187 || (flag_stack_check && ! STACK_CHECK_BUILTIN
1188 && (0 < compare_tree_int (TYPE_SIZE_UNIT (type),
1189 STACK_CHECK_MAX_VAR_SIZE))))
1191 /* This is a variable-sized object. Make space on the stack
1193 rtx size_rtx = expr_size (TREE_VALUE (p));
1195 if (*old_stack_level == 0)
1197 emit_stack_save (SAVE_BLOCK, old_stack_level, NULL_RTX);
1198 *old_pending_adj = pending_stack_adjust;
1199 pending_stack_adjust = 0;
1202 copy = gen_rtx_MEM (BLKmode,
1203 allocate_dynamic_stack_space (size_rtx,
1205 TYPE_ALIGN (type)));
1209 int size = int_size_in_bytes (type);
1210 copy = assign_stack_temp (TYPE_MODE (type), size, 0);
1213 MEM_SET_IN_STRUCT_P (copy, AGGREGATE_TYPE_P (type));
1215 store_expr (args[i].tree_value, copy, 0);
1216 *ecf_flags &= ~(ECF_CONST | ECF_PURE);
1218 args[i].tree_value = build1 (ADDR_EXPR,
1219 build_pointer_type (type),
1220 make_tree (type, copy));
1221 type = build_pointer_type (type);
1225 mode = TYPE_MODE (type);
1226 unsignedp = TREE_UNSIGNED (type);
1228 #ifdef PROMOTE_FUNCTION_ARGS
1229 mode = promote_mode (type, mode, &unsignedp, 1);
1232 args[i].unsignedp = unsignedp;
1233 args[i].mode = mode;
1235 #ifdef FUNCTION_INCOMING_ARG
1236 /* If this is a sibling call and the machine has register windows, the
1237 register window has to be unwinded before calling the routine, so
1238 arguments have to go into the incoming registers. */
1239 if (*ecf_flags & ECF_SIBCALL)
1240 args[i].reg = FUNCTION_INCOMING_ARG (*args_so_far, mode, type,
1241 argpos < n_named_args);
1244 args[i].reg = FUNCTION_ARG (*args_so_far, mode, type,
1245 argpos < n_named_args);
1247 #ifdef FUNCTION_ARG_PARTIAL_NREGS
1250 = FUNCTION_ARG_PARTIAL_NREGS (*args_so_far, mode, type,
1251 argpos < n_named_args);
1254 args[i].pass_on_stack = MUST_PASS_IN_STACK (mode, type);
1256 /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1257 it means that we are to pass this arg in the register(s) designated
1258 by the PARALLEL, but also to pass it in the stack. */
1259 if (args[i].reg && GET_CODE (args[i].reg) == PARALLEL
1260 && XEXP (XVECEXP (args[i].reg, 0, 0), 0) == 0)
1261 args[i].pass_on_stack = 1;
1263 /* If this is an addressable type, we must preallocate the stack
1264 since we must evaluate the object into its final location.
1266 If this is to be passed in both registers and the stack, it is simpler
1268 if (TREE_ADDRESSABLE (type)
1269 || (args[i].pass_on_stack && args[i].reg != 0))
1270 *must_preallocate = 1;
1272 /* If this is an addressable type, we cannot pre-evaluate it. Thus,
1273 we cannot consider this function call constant. */
1274 if (TREE_ADDRESSABLE (type))
1275 *ecf_flags &= ~(ECF_CONST | ECF_PURE);
1277 /* Compute the stack-size of this argument. */
1278 if (args[i].reg == 0 || args[i].partial != 0
1279 || reg_parm_stack_space > 0
1280 || args[i].pass_on_stack)
1281 locate_and_pad_parm (mode, type,
1282 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1287 fndecl, args_size, &args[i].offset,
1288 &args[i].size, &alignment_pad);
1290 #ifndef ARGS_GROW_DOWNWARD
1291 args[i].slot_offset = *args_size;
1294 args[i].alignment_pad = alignment_pad;
1296 /* If a part of the arg was put into registers,
1297 don't include that part in the amount pushed. */
1298 if (reg_parm_stack_space == 0 && ! args[i].pass_on_stack)
1299 args[i].size.constant -= ((args[i].partial * UNITS_PER_WORD)
1300 / (PARM_BOUNDARY / BITS_PER_UNIT)
1301 * (PARM_BOUNDARY / BITS_PER_UNIT));
1303 /* Update ARGS_SIZE, the total stack space for args so far. */
1305 args_size->constant += args[i].size.constant;
1306 if (args[i].size.var)
1308 ADD_PARM_SIZE (*args_size, args[i].size.var);
1311 /* Since the slot offset points to the bottom of the slot,
1312 we must record it after incrementing if the args grow down. */
1313 #ifdef ARGS_GROW_DOWNWARD
1314 args[i].slot_offset = *args_size;
1316 args[i].slot_offset.constant = -args_size->constant;
1318 SUB_PARM_SIZE (args[i].slot_offset, args_size->var);
1321 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1322 have been used, etc. */
1324 FUNCTION_ARG_ADVANCE (*args_so_far, TYPE_MODE (type), type,
1325 argpos < n_named_args);
1329 /* Update ARGS_SIZE to contain the total size for the argument block.
1330 Return the original constant component of the argument block's size.
1332 REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
1333 for arguments passed in registers. */
1336 compute_argument_block_size (reg_parm_stack_space, args_size,
1337 preferred_stack_boundary)
1338 int reg_parm_stack_space;
1339 struct args_size *args_size;
1340 int preferred_stack_boundary ATTRIBUTE_UNUSED;
1342 int unadjusted_args_size = args_size->constant;
1344 /* For accumulate outgoing args mode we don't need to align, since the frame
1345 will be already aligned. Align to STACK_BOUNDARY in order to prevent
1346 backends from generating missaligned frame sizes. */
1347 #ifdef STACK_BOUNDARY
1348 if (ACCUMULATE_OUTGOING_ARGS && preferred_stack_boundary > STACK_BOUNDARY)
1349 preferred_stack_boundary = STACK_BOUNDARY;
1352 /* Compute the actual size of the argument block required. The variable
1353 and constant sizes must be combined, the size may have to be rounded,
1354 and there may be a minimum required size. */
1358 args_size->var = ARGS_SIZE_TREE (*args_size);
1359 args_size->constant = 0;
1361 #ifdef PREFERRED_STACK_BOUNDARY
1362 preferred_stack_boundary /= BITS_PER_UNIT;
1363 if (preferred_stack_boundary > 1)
1365 /* We don't handle this case yet. To handle it correctly we have
1366 to add the delta, round and substract the delta.
1367 Currently no machine description requires this support. */
1368 if (stack_pointer_delta & (preferred_stack_boundary - 1))
1370 args_size->var = round_up (args_size->var, preferred_stack_boundary);
1374 if (reg_parm_stack_space > 0)
1377 = size_binop (MAX_EXPR, args_size->var,
1378 ssize_int (reg_parm_stack_space));
1380 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1381 /* The area corresponding to register parameters is not to count in
1382 the size of the block we need. So make the adjustment. */
1384 = size_binop (MINUS_EXPR, args_size->var,
1385 ssize_int (reg_parm_stack_space));
1391 #ifdef PREFERRED_STACK_BOUNDARY
1392 preferred_stack_boundary /= BITS_PER_UNIT;
1393 if (preferred_stack_boundary < 1)
1394 preferred_stack_boundary = 1;
1395 args_size->constant = (((args_size->constant
1396 + stack_pointer_delta
1397 + preferred_stack_boundary - 1)
1398 / preferred_stack_boundary
1399 * preferred_stack_boundary)
1400 - stack_pointer_delta);
1403 args_size->constant = MAX (args_size->constant,
1404 reg_parm_stack_space);
1406 #ifdef MAYBE_REG_PARM_STACK_SPACE
1407 if (reg_parm_stack_space == 0)
1408 args_size->constant = 0;
1411 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1412 args_size->constant -= reg_parm_stack_space;
1415 return unadjusted_args_size;
1418 /* Precompute parameters as needed for a function call.
1420 FLAGS is mask of ECF_* constants.
1422 NUM_ACTUALS is the number of arguments.
1424 ARGS is an array containing information for each argument; this routine
1425 fills in the INITIAL_VALUE and VALUE fields for each precomputed argument.
1429 precompute_arguments (flags, num_actuals, args)
1432 struct arg_data *args;
1436 /* If this function call is cse'able, precompute all the parameters.
1437 Note that if the parameter is constructed into a temporary, this will
1438 cause an additional copy because the parameter will be constructed
1439 into a temporary location and then copied into the outgoing arguments.
1440 If a parameter contains a call to alloca and this function uses the
1441 stack, precompute the parameter. */
1443 /* If we preallocated the stack space, and some arguments must be passed
1444 on the stack, then we must precompute any parameter which contains a
1445 function call which will store arguments on the stack.
1446 Otherwise, evaluating the parameter may clobber previous parameters
1447 which have already been stored into the stack. (we have code to avoid
1448 such case by saving the ougoing stack arguments, but it results in
1451 for (i = 0; i < num_actuals; i++)
1452 if ((flags & (ECF_CONST | ECF_PURE))
1453 || calls_function (args[i].tree_value, !ACCUMULATE_OUTGOING_ARGS))
1455 /* If this is an addressable type, we cannot pre-evaluate it. */
1456 if (TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value)))
1462 = expand_expr (args[i].tree_value, NULL_RTX, VOIDmode, 0);
1464 preserve_temp_slots (args[i].value);
1467 /* ANSI doesn't require a sequence point here,
1468 but PCC has one, so this will avoid some problems. */
1471 args[i].initial_value = args[i].value
1472 = protect_from_queue (args[i].value, 0);
1474 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) != args[i].mode)
1477 = convert_modes (args[i].mode,
1478 TYPE_MODE (TREE_TYPE (args[i].tree_value)),
1479 args[i].value, args[i].unsignedp);
1480 #ifdef PROMOTE_FOR_CALL_ONLY
1481 /* CSE will replace this only if it contains args[i].value
1482 pseudo, so convert it down to the declared mode using
1484 if (GET_CODE (args[i].value) == REG
1485 && GET_MODE_CLASS (args[i].mode) == MODE_INT)
1487 args[i].initial_value
1488 = gen_rtx_SUBREG (TYPE_MODE (TREE_TYPE (args[i].tree_value)),
1490 SUBREG_PROMOTED_VAR_P (args[i].initial_value) = 1;
1491 SUBREG_PROMOTED_UNSIGNED_P (args[i].initial_value)
1492 = args[i].unsignedp;
1499 /* Given the current state of MUST_PREALLOCATE and information about
1500 arguments to a function call in NUM_ACTUALS, ARGS and ARGS_SIZE,
1501 compute and return the final value for MUST_PREALLOCATE. */
1504 finalize_must_preallocate (must_preallocate, num_actuals, args, args_size)
1505 int must_preallocate;
1507 struct arg_data *args;
1508 struct args_size *args_size;
1510 /* See if we have or want to preallocate stack space.
1512 If we would have to push a partially-in-regs parm
1513 before other stack parms, preallocate stack space instead.
1515 If the size of some parm is not a multiple of the required stack
1516 alignment, we must preallocate.
1518 If the total size of arguments that would otherwise create a copy in
1519 a temporary (such as a CALL) is more than half the total argument list
1520 size, preallocation is faster.
1522 Another reason to preallocate is if we have a machine (like the m88k)
1523 where stack alignment is required to be maintained between every
1524 pair of insns, not just when the call is made. However, we assume here
1525 that such machines either do not have push insns (and hence preallocation
1526 would occur anyway) or the problem is taken care of with
1529 if (! must_preallocate)
1531 int partial_seen = 0;
1532 int copy_to_evaluate_size = 0;
1535 for (i = 0; i < num_actuals && ! must_preallocate; i++)
1537 if (args[i].partial > 0 && ! args[i].pass_on_stack)
1539 else if (partial_seen && args[i].reg == 0)
1540 must_preallocate = 1;
1542 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1543 && (TREE_CODE (args[i].tree_value) == CALL_EXPR
1544 || TREE_CODE (args[i].tree_value) == TARGET_EXPR
1545 || TREE_CODE (args[i].tree_value) == COND_EXPR
1546 || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
1547 copy_to_evaluate_size
1548 += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1551 if (copy_to_evaluate_size * 2 >= args_size->constant
1552 && args_size->constant > 0)
1553 must_preallocate = 1;
1555 return must_preallocate;
1558 /* If we preallocated stack space, compute the address of each argument
1559 and store it into the ARGS array.
1561 We need not ensure it is a valid memory address here; it will be
1562 validized when it is used.
1564 ARGBLOCK is an rtx for the address of the outgoing arguments. */
1567 compute_argument_addresses (args, argblock, num_actuals)
1568 struct arg_data *args;
1574 rtx arg_reg = argblock;
1575 int i, arg_offset = 0;
1577 if (GET_CODE (argblock) == PLUS)
1578 arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
1580 for (i = 0; i < num_actuals; i++)
1582 rtx offset = ARGS_SIZE_RTX (args[i].offset);
1583 rtx slot_offset = ARGS_SIZE_RTX (args[i].slot_offset);
1586 /* Skip this parm if it will not be passed on the stack. */
1587 if (! args[i].pass_on_stack && args[i].reg != 0)
1590 if (GET_CODE (offset) == CONST_INT)
1591 addr = plus_constant (arg_reg, INTVAL (offset));
1593 addr = gen_rtx_PLUS (Pmode, arg_reg, offset);
1595 addr = plus_constant (addr, arg_offset);
1596 args[i].stack = gen_rtx_MEM (args[i].mode, addr);
1599 AGGREGATE_TYPE_P (TREE_TYPE (args[i].tree_value)));
1601 if (GET_CODE (slot_offset) == CONST_INT)
1602 addr = plus_constant (arg_reg, INTVAL (slot_offset));
1604 addr = gen_rtx_PLUS (Pmode, arg_reg, slot_offset);
1606 addr = plus_constant (addr, arg_offset);
1607 args[i].stack_slot = gen_rtx_MEM (args[i].mode, addr);
1612 /* Given a FNDECL and EXP, return an rtx suitable for use as a target address
1613 in a call instruction.
1615 FNDECL is the tree node for the target function. For an indirect call
1616 FNDECL will be NULL_TREE.
1618 EXP is the CALL_EXPR for this call. */
1621 rtx_for_function_call (fndecl, exp)
1627 /* Get the function to call, in the form of RTL. */
1630 /* If this is the first use of the function, see if we need to
1631 make an external definition for it. */
1632 if (! TREE_USED (fndecl))
1634 assemble_external (fndecl);
1635 TREE_USED (fndecl) = 1;
1638 /* Get a SYMBOL_REF rtx for the function address. */
1639 funexp = XEXP (DECL_RTL (fndecl), 0);
1642 /* Generate an rtx (probably a pseudo-register) for the address. */
1647 expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
1648 pop_temp_slots (); /* FUNEXP can't be BLKmode */
1650 /* Check the function is executable. */
1651 if (current_function_check_memory_usage)
1653 #ifdef POINTERS_EXTEND_UNSIGNED
1654 /* It might be OK to convert funexp in place, but there's
1655 a lot going on between here and when it happens naturally
1656 that this seems safer. */
1657 funaddr = convert_memory_address (Pmode, funexp);
1659 emit_library_call (chkr_check_exec_libfunc, 1,
1668 /* Do the register loads required for any wholly-register parms or any
1669 parms which are passed both on the stack and in a register. Their
1670 expressions were already evaluated.
1672 Mark all register-parms as living through the call, putting these USE
1673 insns in the CALL_INSN_FUNCTION_USAGE field. */
1676 load_register_parameters (args, num_actuals, call_fusage)
1677 struct arg_data *args;
1683 #ifdef LOAD_ARGS_REVERSED
1684 for (i = num_actuals - 1; i >= 0; i--)
1686 for (i = 0; i < num_actuals; i++)
1689 rtx reg = args[i].reg;
1690 int partial = args[i].partial;
1695 /* Set to non-negative if must move a word at a time, even if just
1696 one word (e.g, partial == 1 && mode == DFmode). Set to -1 if
1697 we just use a normal move insn. This value can be zero if the
1698 argument is a zero size structure with no fields. */
1699 nregs = (partial ? partial
1700 : (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1701 ? ((int_size_in_bytes (TREE_TYPE (args[i].tree_value))
1702 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
1705 /* Handle calls that pass values in multiple non-contiguous
1706 locations. The Irix 6 ABI has examples of this. */
1708 if (GET_CODE (reg) == PARALLEL)
1709 emit_group_load (reg, args[i].value,
1710 int_size_in_bytes (TREE_TYPE (args[i].tree_value)),
1711 TYPE_ALIGN (TREE_TYPE (args[i].tree_value)));
1713 /* If simple case, just do move. If normal partial, store_one_arg
1714 has already loaded the register for us. In all other cases,
1715 load the register(s) from memory. */
1717 else if (nregs == -1)
1718 emit_move_insn (reg, args[i].value);
1720 /* If we have pre-computed the values to put in the registers in
1721 the case of non-aligned structures, copy them in now. */
1723 else if (args[i].n_aligned_regs != 0)
1724 for (j = 0; j < args[i].n_aligned_regs; j++)
1725 emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg) + j),
1726 args[i].aligned_regs[j]);
1728 else if (partial == 0 || args[i].pass_on_stack)
1729 move_block_to_reg (REGNO (reg),
1730 validize_mem (args[i].value), nregs,
1733 /* Handle calls that pass values in multiple non-contiguous
1734 locations. The Irix 6 ABI has examples of this. */
1735 if (GET_CODE (reg) == PARALLEL)
1736 use_group_regs (call_fusage, reg);
1737 else if (nregs == -1)
1738 use_reg (call_fusage, reg);
1740 use_regs (call_fusage, REGNO (reg), nregs == 0 ? 1 : nregs);
1745 /* Try to integreate function. See expand_inline_function for documentation
1746 about the parameters. */
1749 try_to_integrate (fndecl, actparms, target, ignore, type, structure_value_addr)
1755 rtx structure_value_addr;
1760 rtx old_stack_level = 0;
1761 int reg_parm_stack_space = 0;
1763 #ifdef REG_PARM_STACK_SPACE
1764 #ifdef MAYBE_REG_PARM_STACK_SPACE
1765 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
1767 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
1771 before_call = get_last_insn ();
1773 temp = expand_inline_function (fndecl, actparms, target,
1775 structure_value_addr);
1777 /* If inlining succeeded, return. */
1778 if (temp != (rtx) (HOST_WIDE_INT) - 1)
1780 if (ACCUMULATE_OUTGOING_ARGS)
1782 /* If the outgoing argument list must be preserved, push
1783 the stack before executing the inlined function if it
1786 for (i = reg_parm_stack_space - 1; i >= 0; i--)
1787 if (i < highest_outgoing_arg_in_use && stack_usage_map[i] != 0)
1790 if (stack_arg_under_construction || i >= 0)
1793 = before_call ? NEXT_INSN (before_call) : get_insns ();
1794 rtx insn = NULL_RTX, seq;
1796 /* Look for a call in the inline function code.
1797 If DECL_SAVED_INSNS (fndecl)->outgoing_args_size is
1798 nonzero then there is a call and it is not necessary
1799 to scan the insns. */
1801 if (DECL_SAVED_INSNS (fndecl)->outgoing_args_size == 0)
1802 for (insn = first_insn; insn; insn = NEXT_INSN (insn))
1803 if (GET_CODE (insn) == CALL_INSN)
1808 /* Reserve enough stack space so that the largest
1809 argument list of any function call in the inline
1810 function does not overlap the argument list being
1811 evaluated. This is usually an overestimate because
1812 allocate_dynamic_stack_space reserves space for an
1813 outgoing argument list in addition to the requested
1814 space, but there is no way to ask for stack space such
1815 that an argument list of a certain length can be
1818 Add the stack space reserved for register arguments, if
1819 any, in the inline function. What is really needed is the
1820 largest value of reg_parm_stack_space in the inline
1821 function, but that is not available. Using the current
1822 value of reg_parm_stack_space is wrong, but gives
1823 correct results on all supported machines. */
1825 int adjust = (DECL_SAVED_INSNS (fndecl)->outgoing_args_size
1826 + reg_parm_stack_space);
1829 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1830 allocate_dynamic_stack_space (GEN_INT (adjust),
1831 NULL_RTX, BITS_PER_UNIT);
1834 emit_insns_before (seq, first_insn);
1835 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
1840 /* If the result is equivalent to TARGET, return TARGET to simplify
1841 checks in store_expr. They can be equivalent but not equal in the
1842 case of a function that returns BLKmode. */
1843 if (temp != target && rtx_equal_p (temp, target))
1848 /* If inlining failed, mark FNDECL as needing to be compiled
1849 separately after all. If function was declared inline,
1851 if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
1852 && optimize > 0 && !TREE_ADDRESSABLE (fndecl))
1854 warning_with_decl (fndecl, "inlining failed in call to `%s'");
1855 warning ("called from here");
1857 mark_addressable (fndecl);
1858 return (rtx) (HOST_WIDE_INT) - 1;
1861 /* We need to pop PENDING_STACK_ADJUST bytes. But, if the arguments
1862 wouldn't fill up an even multiple of PREFERRED_UNIT_STACK_BOUNDARY
1863 bytes, then we would need to push some additional bytes to pad the
1864 arguments. So, we compute an adjust to the stack pointer for an
1865 amount that will leave the stack under-aligned by UNADJUSTED_ARGS_SIZE
1866 bytes. Then, when the arguments are pushed the stack will be perfectly
1867 aligned. ARGS_SIZE->CONSTANT is set to the number of bytes that should
1868 be popped after the call. Returns the adjustment. */
1871 combine_pending_stack_adjustment_and_call (unadjusted_args_size,
1873 preferred_unit_stack_boundary)
1874 int unadjusted_args_size;
1875 struct args_size *args_size;
1876 int preferred_unit_stack_boundary;
1878 /* The number of bytes to pop so that the stack will be
1879 under-aligned by UNADJUSTED_ARGS_SIZE bytes. */
1880 HOST_WIDE_INT adjustment;
1881 /* The alignment of the stack after the arguments are pushed, if we
1882 just pushed the arguments without adjust the stack here. */
1883 HOST_WIDE_INT unadjusted_alignment;
1885 unadjusted_alignment
1886 = ((stack_pointer_delta + unadjusted_args_size)
1887 % preferred_unit_stack_boundary);
1889 /* We want to get rid of as many of the PENDING_STACK_ADJUST bytes
1890 as possible -- leaving just enough left to cancel out the
1891 UNADJUSTED_ALIGNMENT. In other words, we want to ensure that the
1892 PENDING_STACK_ADJUST is non-negative, and congruent to
1893 -UNADJUSTED_ALIGNMENT modulo the PREFERRED_UNIT_STACK_BOUNDARY. */
1895 /* Begin by trying to pop all the bytes. */
1896 unadjusted_alignment
1897 = (unadjusted_alignment
1898 - (pending_stack_adjust % preferred_unit_stack_boundary));
1899 adjustment = pending_stack_adjust;
1900 /* Push enough additional bytes that the stack will be aligned
1901 after the arguments are pushed. */
1902 if (unadjusted_alignment >= 0)
1903 adjustment -= preferred_unit_stack_boundary - unadjusted_alignment;
1905 adjustment += unadjusted_alignment;
1907 /* Now, sets ARGS_SIZE->CONSTANT so that we pop the right number of
1908 bytes after the call. The right number is the entire
1909 PENDING_STACK_ADJUST less our ADJUSTMENT plus the amount required
1910 by the arguments in the first place. */
1912 = pending_stack_adjust - adjustment + unadjusted_args_size;
1917 /* Generate all the code for a function call
1918 and return an rtx for its value.
1919 Store the value in TARGET (specified as an rtx) if convenient.
1920 If the value is stored in TARGET then TARGET is returned.
1921 If IGNORE is nonzero, then we ignore the value of the function call. */
1924 expand_call (exp, target, ignore)
1929 /* Nonzero if we are currently expanding a call. */
1930 static int currently_expanding_call = 0;
1932 /* List of actual parameters. */
1933 tree actparms = TREE_OPERAND (exp, 1);
1934 /* RTX for the function to be called. */
1936 /* Sequence of insns to perform a tail recursive "call". */
1937 rtx tail_recursion_insns = NULL_RTX;
1938 /* Sequence of insns to perform a normal "call". */
1939 rtx normal_call_insns = NULL_RTX;
1940 /* Sequence of insns to perform a tail recursive "call". */
1941 rtx tail_call_insns = NULL_RTX;
1942 /* Data type of the function. */
1944 /* Declaration of the function being called,
1945 or 0 if the function is computed (not known by name). */
1952 /* Register in which non-BLKmode value will be returned,
1953 or 0 if no value or if value is BLKmode. */
1955 /* Address where we should return a BLKmode value;
1956 0 if value not BLKmode. */
1957 rtx structure_value_addr = 0;
1958 /* Nonzero if that address is being passed by treating it as
1959 an extra, implicit first parameter. Otherwise,
1960 it is passed by being copied directly into struct_value_rtx. */
1961 int structure_value_addr_parm = 0;
1962 /* Size of aggregate value wanted, or zero if none wanted
1963 or if we are using the non-reentrant PCC calling convention
1964 or expecting the value in registers. */
1965 HOST_WIDE_INT struct_value_size = 0;
1966 /* Nonzero if called function returns an aggregate in memory PCC style,
1967 by returning the address of where to find it. */
1968 int pcc_struct_value = 0;
1970 /* Number of actual parameters in this call, including struct value addr. */
1972 /* Number of named args. Args after this are anonymous ones
1973 and they must all go on the stack. */
1976 /* Vector of information about each argument.
1977 Arguments are numbered in the order they will be pushed,
1978 not the order they are written. */
1979 struct arg_data *args;
1981 /* Total size in bytes of all the stack-parms scanned so far. */
1982 struct args_size args_size;
1983 /* Size of arguments before any adjustments (such as rounding). */
1984 int unadjusted_args_size;
1985 /* Data on reg parms scanned so far. */
1986 CUMULATIVE_ARGS args_so_far;
1987 /* Nonzero if a reg parm has been scanned. */
1989 /* Nonzero if this is an indirect function call. */
1991 /* Nonzero if we must avoid push-insns in the args for this call.
1992 If stack space is allocated for register parameters, but not by the
1993 caller, then it is preallocated in the fixed part of the stack frame.
1994 So the entire argument block must then be preallocated (i.e., we
1995 ignore PUSH_ROUNDING in that case). */
1997 int must_preallocate = !PUSH_ARGS;
1999 /* Size of the stack reserved for parameter registers. */
2000 int reg_parm_stack_space = 0;
2002 /* Address of space preallocated for stack parms
2003 (on machines that lack push insns), or 0 if space not preallocated. */
2006 /* Mask of ECF_ flags. */
2008 /* Nonzero if this is a call to an inline function. */
2009 int is_integrable = 0;
2010 #ifdef REG_PARM_STACK_SPACE
2011 /* Define the boundary of the register parm stack space that needs to be
2013 int low_to_save = -1, high_to_save;
2014 rtx save_area = 0; /* Place that it is saved */
2017 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
2018 char *initial_stack_usage_map = stack_usage_map;
2019 int old_stack_arg_under_construction = 0;
2021 rtx old_stack_level = 0;
2022 int old_pending_adj = 0;
2023 int old_inhibit_defer_pop = inhibit_defer_pop;
2024 int old_stack_allocated;
2028 /* The alignment of the stack, in bits. */
2029 HOST_WIDE_INT preferred_stack_boundary;
2030 /* The alignment of the stack, in bytes. */
2031 HOST_WIDE_INT preferred_unit_stack_boundary;
2033 /* The value of the function call can be put in a hard register. But
2034 if -fcheck-memory-usage, code which invokes functions (and thus
2035 damages some hard registers) can be inserted before using the value.
2036 So, target is always a pseudo-register in that case. */
2037 if (current_function_check_memory_usage)
2040 /* See if this is "nothrow" function call. */
2041 if (TREE_NOTHROW (exp))
2042 flags |= ECF_NOTHROW;
2044 /* See if we can find a DECL-node for the actual function.
2045 As a result, decide whether this is a call to an integrable function. */
2047 fndecl = get_callee_fndecl (exp);
2051 && fndecl != current_function_decl
2052 && DECL_INLINE (fndecl)
2053 && DECL_SAVED_INSNS (fndecl)
2054 && DECL_SAVED_INSNS (fndecl)->inlinable)
2056 else if (! TREE_ADDRESSABLE (fndecl))
2058 /* In case this function later becomes inlinable,
2059 record that there was already a non-inline call to it.
2061 Use abstraction instead of setting TREE_ADDRESSABLE
2063 if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
2066 warning_with_decl (fndecl, "can't inline call to `%s'");
2067 warning ("called from here");
2069 mark_addressable (fndecl);
2072 flags |= flags_from_decl_or_type (fndecl);
2075 /* If we don't have specific function to call, see if we have a
2076 attributes set in the type. */
2079 p = TREE_OPERAND (exp, 0);
2080 flags |= flags_from_decl_or_type (TREE_TYPE (TREE_TYPE (p)));
2083 #ifdef REG_PARM_STACK_SPACE
2084 #ifdef MAYBE_REG_PARM_STACK_SPACE
2085 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
2087 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
2091 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2092 if (reg_parm_stack_space > 0 && PUSH_ARGS)
2093 must_preallocate = 1;
2096 /* Warn if this value is an aggregate type,
2097 regardless of which calling convention we are using for it. */
2098 if (warn_aggregate_return && AGGREGATE_TYPE_P (TREE_TYPE (exp)))
2099 warning ("function call has aggregate value");
2101 /* Set up a place to return a structure. */
2103 /* Cater to broken compilers. */
2104 if (aggregate_value_p (exp))
2106 /* This call returns a big structure. */
2107 flags &= ~(ECF_CONST | ECF_PURE);
2109 #ifdef PCC_STATIC_STRUCT_RETURN
2111 pcc_struct_value = 1;
2112 /* Easier than making that case work right. */
2115 /* In case this is a static function, note that it has been
2117 if (! TREE_ADDRESSABLE (fndecl))
2118 mark_addressable (fndecl);
2122 #else /* not PCC_STATIC_STRUCT_RETURN */
2124 struct_value_size = int_size_in_bytes (TREE_TYPE (exp));
2126 if (target && GET_CODE (target) == MEM)
2127 structure_value_addr = XEXP (target, 0);
2130 /* Assign a temporary to hold the value. */
2133 /* For variable-sized objects, we must be called with a target
2134 specified. If we were to allocate space on the stack here,
2135 we would have no way of knowing when to free it. */
2137 if (struct_value_size < 0)
2140 /* This DECL is just something to feed to mark_addressable;
2141 it doesn't get pushed. */
2142 d = build_decl (VAR_DECL, NULL_TREE, TREE_TYPE (exp));
2143 DECL_RTL (d) = assign_temp (TREE_TYPE (exp), 1, 0, 1);
2144 mark_addressable (d);
2145 mark_temp_addr_taken (DECL_RTL (d));
2146 structure_value_addr = XEXP (DECL_RTL (d), 0);
2151 #endif /* not PCC_STATIC_STRUCT_RETURN */
2154 /* If called function is inline, try to integrate it. */
2158 rtx temp = try_to_integrate (fndecl, actparms, target,
2159 ignore, TREE_TYPE (exp),
2160 structure_value_addr);
2161 if (temp != (rtx) (HOST_WIDE_INT) - 1)
2165 currently_expanding_call++;
2167 /* Tail calls can make things harder to debug, and we're traditionally
2168 pushed these optimizations into -O2. Don't try if we're already
2169 expanding a call, as that means we're an argument. Similarly, if
2170 there's pending loops or cleanups we know there's code to follow
2173 If rtx_equal_function_value_matters is false, that means we've
2174 finished with regular parsing. Which means that some of the
2175 machinery we use to generate tail-calls is no longer in place.
2176 This is most often true of sjlj-exceptions, which we couldn't
2177 tail-call to anyway. */
2180 if (flag_optimize_sibling_calls
2181 && currently_expanding_call == 1
2182 && rtx_equal_function_value_matters
2183 && stmt_loop_nest_empty ()
2184 && ! any_pending_cleanups (1))
2186 tree new_actparms = NULL_TREE;
2188 /* Ok, we're going to give the tail call the old college try.
2189 This means we're going to evaluate the function arguments
2190 up to three times. There are two degrees of badness we can
2191 encounter, those that can be unsaved and those that can't.
2192 (See unsafe_for_reeval commentary for details.)
2194 Generate a new argument list. Pass safe arguments through
2195 unchanged. For the easy badness wrap them in UNSAVE_EXPRs.
2196 For hard badness, evaluate them now and put their resulting
2197 rtx in a temporary VAR_DECL. */
2199 for (p = actparms; p; p = TREE_CHAIN (p))
2200 switch (unsafe_for_reeval (TREE_VALUE (p)))
2203 new_actparms = tree_cons (TREE_PURPOSE (p), TREE_VALUE (p),
2207 case 1: /* Mildly unsafe. */
2208 new_actparms = tree_cons (TREE_PURPOSE (p),
2209 unsave_expr (TREE_VALUE (p)),
2213 case 2: /* Wildly unsafe. */
2215 tree var = build_decl (VAR_DECL, NULL_TREE,
2216 TREE_TYPE (TREE_VALUE (p)));
2217 DECL_RTL (var) = expand_expr (TREE_VALUE (p), NULL_RTX,
2218 VOIDmode, EXPAND_NORMAL);
2219 new_actparms = tree_cons (TREE_PURPOSE (p), var, new_actparms);
2227 /* We built the new argument chain backwards. */
2228 actparms = nreverse (new_actparms);
2230 /* Expanding one of those dangerous arguments could have added
2231 cleanups, but otherwise give it a whirl. */
2232 try_tail_call = ! any_pending_cleanups (1);
2235 /* Generate a tail recursion sequence when calling ourselves. */
2238 && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
2239 && TREE_OPERAND (TREE_OPERAND (exp, 0), 0) == current_function_decl)
2241 /* We want to emit any pending stack adjustments before the tail
2242 recursion "call". That way we know any adjustment after the tail
2243 recursion call can be ignored if we indeed use the tail recursion
2245 int save_pending_stack_adjust = pending_stack_adjust;
2246 int save_stack_pointer_delta = stack_pointer_delta;
2248 /* Use a new sequence to hold any RTL we generate. We do not even
2249 know if we will use this RTL yet. The final decision can not be
2250 made until after RTL generation for the entire function is
2254 /* Emit the pending stack adjustments before we expand any arguments. */
2255 do_pending_stack_adjust ();
2257 if (optimize_tail_recursion (actparms, get_last_insn ()))
2258 tail_recursion_insns = get_insns ();
2261 /* Restore the original pending stack adjustment for the sibling and
2262 normal call cases below. */
2263 pending_stack_adjust = save_pending_stack_adjust;
2264 stack_pointer_delta = save_stack_pointer_delta;
2267 function_call_count++;
2269 if (fndecl && DECL_NAME (fndecl))
2270 name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
2272 /* Figure out the amount to which the stack should be aligned. */
2273 #ifdef PREFERRED_STACK_BOUNDARY
2274 preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
2276 preferred_stack_boundary = STACK_BOUNDARY;
2278 preferred_unit_stack_boundary = preferred_stack_boundary / BITS_PER_UNIT;
2280 /* Ensure current function's preferred stack boundary is at least
2281 what we need. We don't have to increase alignment for recursive
2283 if (cfun->preferred_stack_boundary < preferred_stack_boundary
2284 && fndecl != current_function_decl)
2285 cfun->preferred_stack_boundary = preferred_stack_boundary;
2287 /* See if this is a call to a function that can return more than once
2288 or a call to longjmp or malloc. */
2289 flags |= special_function_p (fndecl, flags);
2291 if (flags & ECF_MAY_BE_ALLOCA)
2292 current_function_calls_alloca = 1;
2294 /* Operand 0 is a pointer-to-function; get the type of the function. */
2295 funtype = TREE_TYPE (TREE_OPERAND (exp, 0));
2296 if (! POINTER_TYPE_P (funtype))
2298 funtype = TREE_TYPE (funtype);
2300 /* We want to make two insn chains; one for a sibling call, the other
2301 for a normal call. We will select one of the two chains after
2302 initial RTL generation is complete. */
2303 for (pass = 0; pass < 2; pass++)
2305 int sibcall_failure = 0;
2306 /* We want to emit ay pending stack adjustments before the tail
2307 recursion "call". That way we know any adjustment after the tail
2308 recursion call can be ignored if we indeed use the tail recursion
2310 int save_pending_stack_adjust;
2311 int save_stack_pointer_delta;
2313 rtx before_call, next_arg_reg;
2317 /* Various reasons we can not use a sibling call. */
2319 #ifdef HAVE_sibcall_epilogue
2320 || ! HAVE_sibcall_epilogue
2324 /* The structure value address is used and modified in the
2325 loop below. It does not seem worth the effort to save and
2326 restore it as a state variable since few optimizable
2327 sibling calls will return a structure. */
2328 || structure_value_addr != NULL_RTX
2329 /* If the register holding the address is a callee saved
2330 register, then we lose. We have no way to prevent that,
2331 so we only allow calls to named functions. */
2332 /* ??? This could be done by having the insn constraints
2333 use a register class that is all call-clobbered. Any
2334 reload insns generated to fix things up would appear
2335 before the sibcall_epilogue. */
2336 || fndecl == NULL_TREE
2337 || ! FUNCTION_OK_FOR_SIBCALL (fndecl))
2340 /* Emit any queued insns now; otherwise they would end up in
2341 only one of the alternates. */
2344 /* State variables we need to save and restore between
2346 save_pending_stack_adjust = pending_stack_adjust;
2347 save_stack_pointer_delta = stack_pointer_delta;
2350 flags &= ~ECF_SIBCALL;
2352 flags |= ECF_SIBCALL;
2354 /* Other state variables that we must reinitialize each time
2355 through the loop (that are not initialized by the loop itself). */
2359 /* Start a new sequence for the normal call case.
2361 From this point on, if the sibling call fails, we want to set
2362 sibcall_failure instead of continuing the loop. */
2367 /* We know at this point that there are not currently any
2368 pending cleanups. If, however, in the process of evaluating
2369 the arguments we were to create some, we'll need to be
2370 able to get rid of them. */
2371 expand_start_target_temps ();
2374 /* When calling a const function, we must pop the stack args right away,
2375 so that the pop is deleted or moved with the call. */
2376 if (flags & (ECF_CONST | ECF_PURE))
2379 /* Don't let pending stack adjusts add up to too much.
2380 Also, do all pending adjustments now if there is any chance
2381 this might be a call to alloca or if we are expanding a sibling
2383 if (pending_stack_adjust >= 32
2384 || (pending_stack_adjust > 0 && (flags & ECF_MAY_BE_ALLOCA))
2386 do_pending_stack_adjust ();
2388 if (profile_arc_flag && (flags & ECF_FORK_OR_EXEC))
2390 /* A fork duplicates the profile information, and an exec discards
2391 it. We can't rely on fork/exec to be paired. So write out the
2392 profile information we have gathered so far, and clear it. */
2393 /* ??? When Linux's __clone is called with CLONE_VM set, profiling
2394 is subject to race conditions, just as with multithreaded
2397 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__bb_fork_func"), 0,
2401 /* Push the temporary stack slot level so that we can free any
2402 temporaries we make. */
2405 /* Start updating where the next arg would go.
2407 On some machines (such as the PA) indirect calls have a different
2408 calling convention than normal calls. The last argument in
2409 INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
2411 INIT_CUMULATIVE_ARGS (args_so_far, funtype, NULL_RTX, (fndecl == 0));
2413 /* If struct_value_rtx is 0, it means pass the address
2414 as if it were an extra parameter. */
2415 if (structure_value_addr && struct_value_rtx == 0)
2417 /* If structure_value_addr is a REG other than
2418 virtual_outgoing_args_rtx, we can use always use it. If it
2419 is not a REG, we must always copy it into a register.
2420 If it is virtual_outgoing_args_rtx, we must copy it to another
2421 register in some cases. */
2422 rtx temp = (GET_CODE (structure_value_addr) != REG
2423 || (ACCUMULATE_OUTGOING_ARGS
2424 && stack_arg_under_construction
2425 && structure_value_addr == virtual_outgoing_args_rtx)
2426 ? copy_addr_to_reg (structure_value_addr)
2427 : structure_value_addr);
2430 = tree_cons (error_mark_node,
2431 make_tree (build_pointer_type (TREE_TYPE (funtype)),
2434 structure_value_addr_parm = 1;
2437 /* Count the arguments and set NUM_ACTUALS. */
2438 for (p = actparms, i = 0; p; p = TREE_CHAIN (p)) i++;
2441 /* Compute number of named args.
2442 Normally, don't include the last named arg if anonymous args follow.
2443 We do include the last named arg if STRICT_ARGUMENT_NAMING is nonzero.
2444 (If no anonymous args follow, the result of list_length is actually
2445 one too large. This is harmless.)
2447 If PRETEND_OUTGOING_VARARGS_NAMED is set and STRICT_ARGUMENT_NAMING is
2448 zero, this machine will be able to place unnamed args that were
2449 passed in registers into the stack. So treat all args as named.
2450 This allows the insns emitting for a specific argument list to be
2451 independent of the function declaration.
2453 If PRETEND_OUTGOING_VARARGS_NAMED is not set, we do not have any
2454 reliable way to pass unnamed args in registers, so we must force
2455 them into memory. */
2457 if ((STRICT_ARGUMENT_NAMING
2458 || ! PRETEND_OUTGOING_VARARGS_NAMED)
2459 && TYPE_ARG_TYPES (funtype) != 0)
2461 = (list_length (TYPE_ARG_TYPES (funtype))
2462 /* Don't include the last named arg. */
2463 - (STRICT_ARGUMENT_NAMING ? 0 : 1)
2464 /* Count the struct value address, if it is passed as a parm. */
2465 + structure_value_addr_parm);
2467 /* If we know nothing, treat all args as named. */
2468 n_named_args = num_actuals;
2470 /* Make a vector to hold all the information about each arg. */
2471 args = (struct arg_data *) alloca (num_actuals
2472 * sizeof (struct arg_data));
2473 bzero ((char *) args, num_actuals * sizeof (struct arg_data));
2475 /* Build up entries inthe ARGS array, compute the size of the arguments
2476 into ARGS_SIZE, etc. */
2477 initialize_argument_information (num_actuals, args, &args_size,
2478 n_named_args, actparms, fndecl,
2479 &args_so_far, reg_parm_stack_space,
2480 &old_stack_level, &old_pending_adj,
2481 &must_preallocate, &flags);
2483 #ifdef FINAL_REG_PARM_STACK_SPACE
2484 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
2490 /* If this function requires a variable-sized argument list, don't
2491 try to make a cse'able block for this call. We may be able to
2492 do this eventually, but it is too complicated to keep track of
2493 what insns go in the cse'able block and which don't.
2495 Also do not make a sibling call. */
2497 flags &= ~(ECF_CONST | ECF_PURE);
2498 must_preallocate = 1;
2499 sibcall_failure = 1;
2502 if (args_size.constant > current_function_args_size)
2504 /* If this function requires more stack slots than the current
2505 function, we cannot change it into a sibling call. */
2506 sibcall_failure = 1;
2509 /* If the callee pops its own arguments, then it must pop exactly
2510 the same number of arguments as the current function. */
2511 if (RETURN_POPS_ARGS (fndecl, funtype, args_size.constant)
2512 != RETURN_POPS_ARGS (current_function_decl,
2513 TREE_TYPE (current_function_decl),
2514 current_function_args_size))
2515 sibcall_failure = 1;
2517 /* Now make final decision about preallocating stack space. */
2518 must_preallocate = finalize_must_preallocate (must_preallocate,
2522 /* If the structure value address will reference the stack pointer, we
2523 must stabilize it. We don't need to do this if we know that we are
2524 not going to adjust the stack pointer in processing this call. */
2526 if (structure_value_addr
2527 && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
2528 || reg_mentioned_p (virtual_outgoing_args_rtx,
2529 structure_value_addr))
2531 || (!ACCUMULATE_OUTGOING_ARGS && args_size.constant)))
2532 structure_value_addr = copy_to_reg (structure_value_addr);
2534 /* Precompute any arguments as needed. */
2536 precompute_arguments (flags, num_actuals, args);
2538 /* Now we are about to start emitting insns that can be deleted
2539 if a libcall is deleted. */
2540 if (flags & (ECF_CONST | ECF_PURE | ECF_MALLOC))
2543 /* Compute the actual size of the argument block required. The variable
2544 and constant sizes must be combined, the size may have to be rounded,
2545 and there may be a minimum required size. When generating a sibcall
2546 pattern, do not round up, since we'll be re-using whatever space our
2548 unadjusted_args_size
2549 = compute_argument_block_size (reg_parm_stack_space, &args_size,
2551 : preferred_stack_boundary));
2553 old_stack_allocated = stack_pointer_delta - pending_stack_adjust;
2555 /* The argument block when performing a sibling call is the
2556 incoming argument block. */
2558 argblock = virtual_incoming_args_rtx;
2560 /* If we have no actual push instructions, or shouldn't use them,
2561 make space for all args right now. */
2562 else if (args_size.var != 0)
2564 if (old_stack_level == 0)
2566 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
2567 old_pending_adj = pending_stack_adjust;
2568 pending_stack_adjust = 0;
2569 /* stack_arg_under_construction says whether a stack arg is
2570 being constructed at the old stack level. Pushing the stack
2571 gets a clean outgoing argument block. */
2572 old_stack_arg_under_construction = stack_arg_under_construction;
2573 stack_arg_under_construction = 0;
2575 argblock = push_block (ARGS_SIZE_RTX (args_size), 0, 0);
2579 /* Note that we must go through the motions of allocating an argument
2580 block even if the size is zero because we may be storing args
2581 in the area reserved for register arguments, which may be part of
2584 int needed = args_size.constant;
2586 /* Store the maximum argument space used. It will be pushed by
2587 the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
2590 if (needed > current_function_outgoing_args_size)
2591 current_function_outgoing_args_size = needed;
2593 if (must_preallocate)
2595 if (ACCUMULATE_OUTGOING_ARGS)
2597 /* Since the stack pointer will never be pushed, it is
2598 possible for the evaluation of a parm to clobber
2599 something we have already written to the stack.
2600 Since most function calls on RISC machines do not use
2601 the stack, this is uncommon, but must work correctly.
2603 Therefore, we save any area of the stack that was already
2604 written and that we are using. Here we set up to do this
2605 by making a new stack usage map from the old one. The
2606 actual save will be done by store_one_arg.
2608 Another approach might be to try to reorder the argument
2609 evaluations to avoid this conflicting stack usage. */
2611 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2612 /* Since we will be writing into the entire argument area,
2613 the map must be allocated for its entire size, not just
2614 the part that is the responsibility of the caller. */
2615 needed += reg_parm_stack_space;
2618 #ifdef ARGS_GROW_DOWNWARD
2619 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2622 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2626 = (char *) alloca (highest_outgoing_arg_in_use);
2628 if (initial_highest_arg_in_use)
2629 bcopy (initial_stack_usage_map, stack_usage_map,
2630 initial_highest_arg_in_use);
2632 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
2633 bzero (&stack_usage_map[initial_highest_arg_in_use],
2634 (highest_outgoing_arg_in_use
2635 - initial_highest_arg_in_use));
2638 /* The address of the outgoing argument list must not be
2639 copied to a register here, because argblock would be left
2640 pointing to the wrong place after the call to
2641 allocate_dynamic_stack_space below. */
2643 argblock = virtual_outgoing_args_rtx;
2647 if (inhibit_defer_pop == 0)
2649 /* Try to reuse some or all of the pending_stack_adjust
2650 to get this space. */
2652 = (combine_pending_stack_adjustment_and_call
2653 (unadjusted_args_size,
2655 preferred_unit_stack_boundary));
2657 /* combine_pending_stack_adjustment_and_call computes
2658 an adjustment before the arguments are allocated.
2659 Account for them and see whether or not the stack
2660 needs to go up or down. */
2661 needed = unadjusted_args_size - needed;
2665 /* We're releasing stack space. */
2666 /* ??? We can avoid any adjustment at all if we're
2667 already aligned. FIXME. */
2668 pending_stack_adjust = -needed;
2669 do_pending_stack_adjust ();
2673 /* We need to allocate space. We'll do that in
2674 push_block below. */
2675 pending_stack_adjust = 0;
2678 /* Special case this because overhead of `push_block' in
2679 this case is non-trivial. */
2681 argblock = virtual_outgoing_args_rtx;
2683 argblock = push_block (GEN_INT (needed), 0, 0);
2685 /* We only really need to call `copy_to_reg' in the case
2686 where push insns are going to be used to pass ARGBLOCK
2687 to a function call in ARGS. In that case, the stack
2688 pointer changes value from the allocation point to the
2689 call point, and hence the value of
2690 VIRTUAL_OUTGOING_ARGS_RTX changes as well. But might
2691 as well always do it. */
2692 argblock = copy_to_reg (argblock);
2694 /* The save/restore code in store_one_arg handles all
2695 cases except one: a constructor call (including a C
2696 function returning a BLKmode struct) to initialize
2698 if (stack_arg_under_construction)
2700 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2701 rtx push_size = GEN_INT (reg_parm_stack_space
2702 + args_size.constant);
2704 rtx push_size = GEN_INT (args_size.constant);
2706 if (old_stack_level == 0)
2708 emit_stack_save (SAVE_BLOCK, &old_stack_level,
2710 old_pending_adj = pending_stack_adjust;
2711 pending_stack_adjust = 0;
2712 /* stack_arg_under_construction says whether a stack
2713 arg is being constructed at the old stack level.
2714 Pushing the stack gets a clean outgoing argument
2716 old_stack_arg_under_construction
2717 = stack_arg_under_construction;
2718 stack_arg_under_construction = 0;
2719 /* Make a new map for the new argument list. */
2720 stack_usage_map = (char *)
2721 alloca (highest_outgoing_arg_in_use);
2722 bzero (stack_usage_map, highest_outgoing_arg_in_use);
2723 highest_outgoing_arg_in_use = 0;
2725 allocate_dynamic_stack_space (push_size, NULL_RTX,
2728 /* If argument evaluation might modify the stack pointer,
2729 copy the address of the argument list to a register. */
2730 for (i = 0; i < num_actuals; i++)
2731 if (args[i].pass_on_stack)
2733 argblock = copy_addr_to_reg (argblock);
2740 compute_argument_addresses (args, argblock, num_actuals);
2742 #ifdef PREFERRED_STACK_BOUNDARY
2743 /* If we push args individually in reverse order, perform stack alignment
2744 before the first push (the last arg). */
2745 if (PUSH_ARGS_REVERSED && argblock == 0
2746 && args_size.constant != unadjusted_args_size)
2748 /* When the stack adjustment is pending, we get better code
2749 by combining the adjustments. */
2750 if (pending_stack_adjust
2751 && ! (flags & (ECF_CONST | ECF_PURE))
2752 && ! inhibit_defer_pop)
2754 pending_stack_adjust
2755 = (combine_pending_stack_adjustment_and_call
2756 (unadjusted_args_size,
2758 preferred_unit_stack_boundary));
2759 do_pending_stack_adjust ();
2761 else if (argblock == 0)
2762 anti_adjust_stack (GEN_INT (args_size.constant
2763 - unadjusted_args_size));
2765 /* Now that the stack is properly aligned, pops can't safely
2766 be deferred during the evaluation of the arguments. */
2770 /* Don't try to defer pops if preallocating, not even from the first arg,
2771 since ARGBLOCK probably refers to the SP. */
2775 funexp = rtx_for_function_call (fndecl, exp);
2777 /* Figure out the register where the value, if any, will come back. */
2779 if (TYPE_MODE (TREE_TYPE (exp)) != VOIDmode
2780 && ! structure_value_addr)
2782 if (pcc_struct_value)
2783 valreg = hard_function_value (build_pointer_type (TREE_TYPE (exp)),
2784 fndecl, (pass == 0));
2786 valreg = hard_function_value (TREE_TYPE (exp), fndecl, (pass == 0));
2789 /* Precompute all register parameters. It isn't safe to compute anything
2790 once we have started filling any specific hard regs. */
2791 precompute_register_parameters (num_actuals, args, ®_parm_seen);
2793 #ifdef REG_PARM_STACK_SPACE
2794 /* Save the fixed argument area if it's part of the caller's frame and
2795 is clobbered by argument setup for this call. */
2796 if (ACCUMULATE_OUTGOING_ARGS && pass)
2797 save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
2798 &low_to_save, &high_to_save);
2801 /* Now store (and compute if necessary) all non-register parms.
2802 These come before register parms, since they can require block-moves,
2803 which could clobber the registers used for register parms.
2804 Parms which have partial registers are not stored here,
2805 but we do preallocate space here if they want that. */
2807 for (i = 0; i < num_actuals; i++)
2808 if (args[i].reg == 0 || args[i].pass_on_stack)
2809 store_one_arg (&args[i], argblock, flags,
2810 args_size.var != 0, reg_parm_stack_space);
2812 /* If we have a parm that is passed in registers but not in memory
2813 and whose alignment does not permit a direct copy into registers,
2814 make a group of pseudos that correspond to each register that we
2816 if (STRICT_ALIGNMENT)
2817 store_unaligned_arguments_into_pseudos (args, num_actuals);
2819 /* Now store any partially-in-registers parm.
2820 This is the last place a block-move can happen. */
2822 for (i = 0; i < num_actuals; i++)
2823 if (args[i].partial != 0 && ! args[i].pass_on_stack)
2824 store_one_arg (&args[i], argblock, flags,
2825 args_size.var != 0, reg_parm_stack_space);
2827 #ifdef PREFERRED_STACK_BOUNDARY
2828 /* If we pushed args in forward order, perform stack alignment
2829 after pushing the last arg. */
2830 if (!PUSH_ARGS_REVERSED && argblock == 0)
2831 anti_adjust_stack (GEN_INT (args_size.constant
2832 - unadjusted_args_size));
2835 /* If register arguments require space on the stack and stack space
2836 was not preallocated, allocate stack space here for arguments
2837 passed in registers. */
2838 #ifdef OUTGOING_REG_PARM_STACK_SPACE
2839 if (!ACCUMULATE_OUTGOING_ARGS
2840 && must_preallocate == 0 && reg_parm_stack_space > 0)
2841 anti_adjust_stack (GEN_INT (reg_parm_stack_space));
2844 /* Pass the function the address in which to return a
2846 if (pass != 0 && structure_value_addr && ! structure_value_addr_parm)
2848 emit_move_insn (struct_value_rtx,
2850 force_operand (structure_value_addr,
2853 /* Mark the memory for the aggregate as write-only. */
2854 if (current_function_check_memory_usage)
2855 emit_library_call (chkr_set_right_libfunc, 1,
2857 structure_value_addr, ptr_mode,
2858 GEN_INT (struct_value_size),
2859 TYPE_MODE (sizetype),
2860 GEN_INT (MEMORY_USE_WO),
2861 TYPE_MODE (integer_type_node));
2863 if (GET_CODE (struct_value_rtx) == REG)
2864 use_reg (&call_fusage, struct_value_rtx);
2867 funexp = prepare_call_address (funexp, fndecl, &call_fusage,
2870 load_register_parameters (args, num_actuals, &call_fusage);
2872 /* Perform postincrements before actually calling the function. */
2875 /* Save a pointer to the last insn before the call, so that we can
2876 later safely search backwards to find the CALL_INSN. */
2877 before_call = get_last_insn ();
2879 /* Set up next argument register. For sibling calls on machines
2880 with register windows this should be the incoming register. */
2881 #ifdef FUNCTION_INCOMING_ARG
2883 next_arg_reg = FUNCTION_INCOMING_ARG (args_so_far, VOIDmode,
2887 next_arg_reg = FUNCTION_ARG (args_so_far, VOIDmode,
2890 /* All arguments and registers used for the call must be set up by
2893 #ifdef PREFERRED_STACK_BOUNDARY
2894 /* Stack must be properly aligned now. */
2895 if (pass && stack_pointer_delta % preferred_unit_stack_boundary)
2899 /* Generate the actual call instruction. */
2900 emit_call_1 (funexp, fndecl, funtype, unadjusted_args_size,
2901 args_size.constant, struct_value_size,
2902 next_arg_reg, valreg, old_inhibit_defer_pop, call_fusage,
2905 /* Verify that we've deallocated all the stack we used. */
2907 && old_stack_allocated != stack_pointer_delta - pending_stack_adjust)
2910 /* If call is cse'able, make appropriate pair of reg-notes around it.
2911 Test valreg so we don't crash; may safely ignore `const'
2912 if return type is void. Disable for PARALLEL return values, because
2913 we have no way to move such values into a pseudo register. */
2915 && (flags & (ECF_CONST | ECF_PURE))
2916 && valreg != 0 && GET_CODE (valreg) != PARALLEL)
2919 rtx temp = gen_reg_rtx (GET_MODE (valreg));
2922 /* Mark the return value as a pointer if needed. */
2923 if (TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE)
2924 mark_reg_pointer (temp, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (exp))));
2926 /* Construct an "equal form" for the value which mentions all the
2927 arguments in order as well as the function name. */
2928 for (i = 0; i < num_actuals; i++)
2929 note = gen_rtx_EXPR_LIST (VOIDmode, args[i].initial_value, note);
2930 note = gen_rtx_EXPR_LIST (VOIDmode, funexp, note);
2932 insns = get_insns ();
2935 if (flags & ECF_PURE)
2936 note = gen_rtx_EXPR_LIST (VOIDmode,
2937 gen_rtx_USE (VOIDmode,
2938 gen_rtx_MEM (BLKmode,
2939 gen_rtx_SCRATCH (VOIDmode))), note);
2941 emit_libcall_block (insns, temp, valreg, note);
2945 else if (flags & (ECF_CONST | ECF_PURE))
2947 /* Otherwise, just write out the sequence without a note. */
2948 rtx insns = get_insns ();
2953 else if (flags & ECF_MALLOC)
2955 rtx temp = gen_reg_rtx (GET_MODE (valreg));
2958 /* The return value from a malloc-like function is a pointer. */
2959 if (TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE)
2960 mark_reg_pointer (temp, BIGGEST_ALIGNMENT);
2962 emit_move_insn (temp, valreg);
2964 /* The return value from a malloc-like function can not alias
2966 last = get_last_insn ();
2968 gen_rtx_EXPR_LIST (REG_NOALIAS, temp, REG_NOTES (last));
2970 /* Write out the sequence. */
2971 insns = get_insns ();
2977 /* For calls to `setjmp', etc., inform flow.c it should complain
2978 if nonvolatile values are live. For functions that cannot return,
2979 inform flow that control does not fall through. */
2981 if ((flags & (ECF_RETURNS_TWICE | ECF_NORETURN | ECF_LONGJMP)) || pass == 0)
2983 /* The barrier or NOTE_INSN_SETJMP note must be emitted
2984 immediately after the CALL_INSN. Some ports emit more
2985 than just a CALL_INSN above, so we must search for it here. */
2987 rtx last = get_last_insn ();
2988 while (GET_CODE (last) != CALL_INSN)
2990 last = PREV_INSN (last);
2991 /* There was no CALL_INSN? */
2992 if (last == before_call)
2996 if (flags & ECF_RETURNS_TWICE)
2998 emit_note_after (NOTE_INSN_SETJMP, last);
2999 current_function_calls_setjmp = 1;
3000 sibcall_failure = 1;
3003 emit_barrier_after (last);
3006 if (flags & ECF_LONGJMP)
3007 current_function_calls_longjmp = 1, sibcall_failure = 1;
3009 /* If this function is returning into a memory location marked as
3010 readonly, it means it is initializing that location. But we normally
3011 treat functions as not clobbering such locations, so we need to
3012 specify that this one does. */
3013 if (target != 0 && GET_CODE (target) == MEM
3014 && structure_value_addr != 0 && RTX_UNCHANGING_P (target))
3015 emit_insn (gen_rtx_CLOBBER (VOIDmode, target));
3017 /* If value type not void, return an rtx for the value. */
3019 /* If there are cleanups to be called, don't use a hard reg as target.
3020 We need to double check this and see if it matters anymore. */
3021 if (any_pending_cleanups (1))
3023 if (target && REG_P (target)
3024 && REGNO (target) < FIRST_PSEUDO_REGISTER)
3026 sibcall_failure = 1;
3029 if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode
3032 target = const0_rtx;
3034 else if (structure_value_addr)
3036 if (target == 0 || GET_CODE (target) != MEM)
3038 target = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
3039 memory_address (TYPE_MODE (TREE_TYPE (exp)),
3040 structure_value_addr));
3041 MEM_SET_IN_STRUCT_P (target,
3042 AGGREGATE_TYPE_P (TREE_TYPE (exp)));
3045 else if (pcc_struct_value)
3047 /* This is the special C++ case where we need to
3048 know what the true target was. We take care to
3049 never use this value more than once in one expression. */
3050 target = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
3051 copy_to_reg (valreg));
3052 MEM_SET_IN_STRUCT_P (target, AGGREGATE_TYPE_P (TREE_TYPE (exp)));
3054 /* Handle calls that return values in multiple non-contiguous locations.
3055 The Irix 6 ABI has examples of this. */
3056 else if (GET_CODE (valreg) == PARALLEL)
3058 int bytes = int_size_in_bytes (TREE_TYPE (exp));
3062 target = assign_stack_temp (TYPE_MODE (TREE_TYPE (exp)),
3064 MEM_SET_IN_STRUCT_P (target, AGGREGATE_TYPE_P (TREE_TYPE (exp)));
3065 preserve_temp_slots (target);
3068 if (! rtx_equal_p (target, valreg))
3069 emit_group_store (target, valreg, bytes,
3070 TYPE_ALIGN (TREE_TYPE (exp)));
3072 /* We can not support sibling calls for this case. */
3073 sibcall_failure = 1;
3076 && GET_MODE (target) == TYPE_MODE (TREE_TYPE (exp))
3077 && GET_MODE (target) == GET_MODE (valreg))
3079 /* TARGET and VALREG cannot be equal at this point because the
3080 latter would not have REG_FUNCTION_VALUE_P true, while the
3081 former would if it were referring to the same register.
3083 If they refer to the same register, this move will be a no-op,
3084 except when function inlining is being done. */
3085 emit_move_insn (target, valreg);
3087 else if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
3088 target = copy_blkmode_from_reg (target, valreg, TREE_TYPE (exp));
3090 target = copy_to_reg (valreg);
3092 #ifdef PROMOTE_FUNCTION_RETURN
3093 /* If we promoted this return value, make the proper SUBREG. TARGET
3094 might be const0_rtx here, so be careful. */
3095 if (GET_CODE (target) == REG
3096 && TYPE_MODE (TREE_TYPE (exp)) != BLKmode
3097 && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
3099 tree type = TREE_TYPE (exp);
3100 int unsignedp = TREE_UNSIGNED (type);
3102 /* If we don't promote as expected, something is wrong. */
3103 if (GET_MODE (target)
3104 != promote_mode (type, TYPE_MODE (type), &unsignedp, 1))
3107 target = gen_rtx_SUBREG (TYPE_MODE (type), target, 0);
3108 SUBREG_PROMOTED_VAR_P (target) = 1;
3109 SUBREG_PROMOTED_UNSIGNED_P (target) = unsignedp;
3113 /* If size of args is variable or this was a constructor call for a stack
3114 argument, restore saved stack-pointer value. */
3116 if (old_stack_level)
3118 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
3119 pending_stack_adjust = old_pending_adj;
3120 stack_arg_under_construction = old_stack_arg_under_construction;
3121 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3122 stack_usage_map = initial_stack_usage_map;
3123 sibcall_failure = 1;
3125 else if (ACCUMULATE_OUTGOING_ARGS && pass)
3127 #ifdef REG_PARM_STACK_SPACE
3130 restore_fixed_argument_area (save_area, argblock,
3131 high_to_save, low_to_save);
3135 /* If we saved any argument areas, restore them. */
3136 for (i = 0; i < num_actuals; i++)
3137 if (args[i].save_area)
3139 enum machine_mode save_mode = GET_MODE (args[i].save_area);
3141 = gen_rtx_MEM (save_mode,
3142 memory_address (save_mode,
3143 XEXP (args[i].stack_slot, 0)));
3145 if (save_mode != BLKmode)
3146 emit_move_insn (stack_area, args[i].save_area);
3148 emit_block_move (stack_area,
3149 validize_mem (args[i].save_area),
3150 GEN_INT (args[i].size.constant),
3154 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3155 stack_usage_map = initial_stack_usage_map;
3158 /* If this was alloca, record the new stack level for nonlocal gotos.
3159 Check for the handler slots since we might not have a save area
3160 for non-local gotos. */
3162 if ((flags & ECF_MAY_BE_ALLOCA) && nonlocal_goto_handler_slots != 0)
3163 emit_stack_save (SAVE_NONLOCAL, &nonlocal_goto_stack_level, NULL_RTX);
3167 /* Free up storage we no longer need. */
3168 for (i = 0; i < num_actuals; ++i)
3169 if (args[i].aligned_regs)
3170 free (args[i].aligned_regs);
3174 /* Undo the fake expand_start_target_temps we did earlier. If
3175 there had been any cleanups created, we've already set
3177 expand_end_target_temps ();
3180 insns = get_insns ();
3185 tail_call_insns = insns;
3187 /* If something prevents making this a sibling call,
3188 zero out the sequence. */
3189 if (sibcall_failure)
3190 tail_call_insns = NULL_RTX;
3191 /* Restore the pending stack adjustment now that we have
3192 finished generating the sibling call sequence. */
3194 pending_stack_adjust = save_pending_stack_adjust;
3195 stack_pointer_delta = save_stack_pointer_delta;
3198 normal_call_insns = insns;
3201 /* The function optimize_sibling_and_tail_recursive_calls doesn't
3202 handle CALL_PLACEHOLDERs inside other CALL_PLACEHOLDERs. This
3203 can happen if the arguments to this function call an inline
3204 function who's expansion contains another CALL_PLACEHOLDER.
3206 If there are any C_Ps in any of these sequences, replace them
3207 with their normal call. */
3209 for (insn = normal_call_insns; insn; insn = NEXT_INSN (insn))
3210 if (GET_CODE (insn) == CALL_INSN
3211 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
3212 replace_call_placeholder (insn, sibcall_use_normal);
3214 for (insn = tail_call_insns; insn; insn = NEXT_INSN (insn))
3215 if (GET_CODE (insn) == CALL_INSN
3216 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
3217 replace_call_placeholder (insn, sibcall_use_normal);
3219 for (insn = tail_recursion_insns; insn; insn = NEXT_INSN (insn))
3220 if (GET_CODE (insn) == CALL_INSN
3221 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
3222 replace_call_placeholder (insn, sibcall_use_normal);
3224 /* If this was a potential tail recursion site, then emit a
3225 CALL_PLACEHOLDER with the normal and the tail recursion streams.
3226 One of them will be selected later. */
3227 if (tail_recursion_insns || tail_call_insns)
3229 /* The tail recursion label must be kept around. We could expose
3230 its use in the CALL_PLACEHOLDER, but that creates unwanted edges
3231 and makes determining true tail recursion sites difficult.
3233 So we set LABEL_PRESERVE_P here, then clear it when we select
3234 one of the call sequences after rtl generation is complete. */
3235 if (tail_recursion_insns)
3236 LABEL_PRESERVE_P (tail_recursion_label) = 1;
3237 emit_call_insn (gen_rtx_CALL_PLACEHOLDER (VOIDmode, normal_call_insns,
3239 tail_recursion_insns,
3240 tail_recursion_label));
3243 emit_insns (normal_call_insns);
3245 currently_expanding_call--;
3250 /* Returns nonzero if FUN is the symbol for a library function which can
3254 libfunc_nothrow (fun)
3257 if (fun == throw_libfunc
3258 || fun == rethrow_libfunc
3259 || fun == sjthrow_libfunc
3260 || fun == sjpopnthrow_libfunc)
3266 /* Output a library call to function FUN (a SYMBOL_REF rtx).
3267 The RETVAL parameter specifies whether return value needs to be saved, other
3268 parameters are documented in the emit_library_call function bellow. */
3270 emit_library_call_value_1 (retval, orgfun, value, fn_type, outmode, nargs, p)
3275 enum machine_mode outmode;
3279 /* Total size in bytes of all the stack-parms scanned so far. */
3280 struct args_size args_size;
3281 /* Size of arguments before any adjustments (such as rounding). */
3282 struct args_size original_args_size;
3283 register int argnum;
3287 struct args_size alignment_pad;
3289 CUMULATIVE_ARGS args_so_far;
3290 struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
3291 struct args_size offset; struct args_size size; rtx save_area; };
3293 int old_inhibit_defer_pop = inhibit_defer_pop;
3294 rtx call_fusage = 0;
3297 int pcc_struct_value = 0;
3298 int struct_value_size = 0;
3300 int reg_parm_stack_space = 0;
3303 #ifdef REG_PARM_STACK_SPACE
3304 /* Define the boundary of the register parm stack space that needs to be
3306 int low_to_save = -1, high_to_save = 0;
3307 rtx save_area = 0; /* Place that it is saved */
3310 /* Size of the stack reserved for parameter registers. */
3311 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
3312 char *initial_stack_usage_map = stack_usage_map;
3314 #ifdef REG_PARM_STACK_SPACE
3315 #ifdef MAYBE_REG_PARM_STACK_SPACE
3316 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
3318 reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0);
3324 else if (fn_type == 2)
3328 if (libfunc_nothrow (fun))
3329 flags |= ECF_NOTHROW;
3331 #ifdef PREFERRED_STACK_BOUNDARY
3332 /* Ensure current function's preferred stack boundary is at least
3334 if (cfun->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
3335 cfun->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
3338 /* If this kind of value comes back in memory,
3339 decide where in memory it should come back. */
3340 if (outmode != VOIDmode && aggregate_value_p (type_for_mode (outmode, 0)))
3342 #ifdef PCC_STATIC_STRUCT_RETURN
3344 = hard_function_value (build_pointer_type (type_for_mode (outmode, 0)),
3346 mem_value = gen_rtx_MEM (outmode, pointer_reg);
3347 pcc_struct_value = 1;
3349 value = gen_reg_rtx (outmode);
3350 #else /* not PCC_STATIC_STRUCT_RETURN */
3351 struct_value_size = GET_MODE_SIZE (outmode);
3352 if (value != 0 && GET_CODE (value) == MEM)
3355 mem_value = assign_stack_temp (outmode, GET_MODE_SIZE (outmode), 0);
3358 /* This call returns a big structure. */
3359 flags &= ~(ECF_CONST | ECF_PURE);
3362 /* ??? Unfinished: must pass the memory address as an argument. */
3364 /* Copy all the libcall-arguments out of the varargs data
3365 and into a vector ARGVEC.
3367 Compute how to pass each argument. We only support a very small subset
3368 of the full argument passing conventions to limit complexity here since
3369 library functions shouldn't have many args. */
3371 argvec = (struct arg *) alloca ((nargs + 1) * sizeof (struct arg));
3372 bzero ((char *) argvec, (nargs + 1) * sizeof (struct arg));
3374 INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0);
3376 args_size.constant = 0;
3381 /* Now we are about to start emitting insns that can be deleted
3382 if a libcall is deleted. */
3383 if (flags & (ECF_CONST | ECF_PURE))
3388 /* If there's a structure value address to be passed,
3389 either pass it in the special place, or pass it as an extra argument. */
3390 if (mem_value && struct_value_rtx == 0 && ! pcc_struct_value)
3392 rtx addr = XEXP (mem_value, 0);
3395 /* Make sure it is a reasonable operand for a move or push insn. */
3396 if (GET_CODE (addr) != REG && GET_CODE (addr) != MEM
3397 && ! (CONSTANT_P (addr) && LEGITIMATE_CONSTANT_P (addr)))
3398 addr = force_operand (addr, NULL_RTX);
3400 argvec[count].value = addr;
3401 argvec[count].mode = Pmode;
3402 argvec[count].partial = 0;
3404 argvec[count].reg = FUNCTION_ARG (args_so_far, Pmode, NULL_TREE, 1);
3405 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3406 if (FUNCTION_ARG_PARTIAL_NREGS (args_so_far, Pmode, NULL_TREE, 1))
3410 locate_and_pad_parm (Pmode, NULL_TREE,
3411 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3414 argvec[count].reg != 0,
3416 NULL_TREE, &args_size, &argvec[count].offset,
3417 &argvec[count].size, &alignment_pad);
3420 if (argvec[count].reg == 0 || argvec[count].partial != 0
3421 || reg_parm_stack_space > 0)
3422 args_size.constant += argvec[count].size.constant;
3424 FUNCTION_ARG_ADVANCE (args_so_far, Pmode, (tree) 0, 1);
3429 for (; count < nargs; count++)
3431 rtx val = va_arg (p, rtx);
3432 enum machine_mode mode = va_arg (p, enum machine_mode);
3434 /* We cannot convert the arg value to the mode the library wants here;
3435 must do it earlier where we know the signedness of the arg. */
3437 || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
3440 /* On some machines, there's no way to pass a float to a library fcn.
3441 Pass it as a double instead. */
3442 #ifdef LIBGCC_NEEDS_DOUBLE
3443 if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
3444 val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode;
3447 /* There's no need to call protect_from_queue, because
3448 either emit_move_insn or emit_push_insn will do that. */
3450 /* Make sure it is a reasonable operand for a move or push insn. */
3451 if (GET_CODE (val) != REG && GET_CODE (val) != MEM
3452 && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
3453 val = force_operand (val, NULL_RTX);
3455 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
3456 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
3458 /* We do not support FUNCTION_ARG_CALLEE_COPIES here since it can
3459 be viewed as just an efficiency improvement. */
3460 rtx slot = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
3461 emit_move_insn (slot, val);
3462 val = force_operand (XEXP (slot, 0), NULL_RTX);
3467 argvec[count].value = val;
3468 argvec[count].mode = mode;
3470 argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
3472 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3473 argvec[count].partial
3474 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
3476 argvec[count].partial = 0;
3479 locate_and_pad_parm (mode, NULL_TREE,
3480 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3483 argvec[count].reg != 0,
3485 NULL_TREE, &args_size, &argvec[count].offset,
3486 &argvec[count].size, &alignment_pad);
3488 if (argvec[count].size.var)
3491 if (reg_parm_stack_space == 0 && argvec[count].partial)
3492 argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
3494 if (argvec[count].reg == 0 || argvec[count].partial != 0
3495 || reg_parm_stack_space > 0)
3496 args_size.constant += argvec[count].size.constant;
3498 FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
3501 #ifdef FINAL_REG_PARM_STACK_SPACE
3502 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
3505 /* If this machine requires an external definition for library
3506 functions, write one out. */
3507 assemble_external_libcall (fun);
3509 original_args_size = args_size;
3510 #ifdef PREFERRED_STACK_BOUNDARY
3511 args_size.constant = (((args_size.constant
3512 + stack_pointer_delta
3516 - stack_pointer_delta);
3519 args_size.constant = MAX (args_size.constant,
3520 reg_parm_stack_space);
3522 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3523 args_size.constant -= reg_parm_stack_space;
3526 if (args_size.constant > current_function_outgoing_args_size)
3527 current_function_outgoing_args_size = args_size.constant;
3529 if (ACCUMULATE_OUTGOING_ARGS)
3531 /* Since the stack pointer will never be pushed, it is possible for
3532 the evaluation of a parm to clobber something we have already
3533 written to the stack. Since most function calls on RISC machines
3534 do not use the stack, this is uncommon, but must work correctly.
3536 Therefore, we save any area of the stack that was already written
3537 and that we are using. Here we set up to do this by making a new
3538 stack usage map from the old one.
3540 Another approach might be to try to reorder the argument
3541 evaluations to avoid this conflicting stack usage. */
3543 needed = args_size.constant;
3545 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3546 /* Since we will be writing into the entire argument area, the
3547 map must be allocated for its entire size, not just the part that
3548 is the responsibility of the caller. */
3549 needed += reg_parm_stack_space;
3552 #ifdef ARGS_GROW_DOWNWARD
3553 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3556 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3559 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
3561 if (initial_highest_arg_in_use)
3562 bcopy (initial_stack_usage_map, stack_usage_map,
3563 initial_highest_arg_in_use);
3565 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
3566 bzero (&stack_usage_map[initial_highest_arg_in_use],
3567 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
3570 /* The address of the outgoing argument list must not be copied to a
3571 register here, because argblock would be left pointing to the
3572 wrong place after the call to allocate_dynamic_stack_space below.
3575 argblock = virtual_outgoing_args_rtx;
3580 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
3583 #ifdef PREFERRED_STACK_BOUNDARY
3584 /* If we push args individually in reverse order, perform stack alignment
3585 before the first push (the last arg). */
3586 if (argblock == 0 && PUSH_ARGS_REVERSED)
3587 anti_adjust_stack (GEN_INT (args_size.constant
3588 - original_args_size.constant));
3591 if (PUSH_ARGS_REVERSED)
3602 #ifdef REG_PARM_STACK_SPACE
3603 if (ACCUMULATE_OUTGOING_ARGS)
3605 /* The argument list is the property of the called routine and it
3606 may clobber it. If the fixed area has been used for previous
3607 parameters, we must save and restore it.
3609 Here we compute the boundary of the that needs to be saved, if any. */
3611 #ifdef ARGS_GROW_DOWNWARD
3612 for (count = 0; count < reg_parm_stack_space + 1; count++)
3614 for (count = 0; count < reg_parm_stack_space; count++)
3617 if (count >= highest_outgoing_arg_in_use
3618 || stack_usage_map[count] == 0)
3621 if (low_to_save == -1)
3622 low_to_save = count;
3624 high_to_save = count;
3627 if (low_to_save >= 0)
3629 int num_to_save = high_to_save - low_to_save + 1;
3630 enum machine_mode save_mode
3631 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
3634 /* If we don't have the required alignment, must do this in BLKmode. */
3635 if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
3636 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
3637 save_mode = BLKmode;
3639 #ifdef ARGS_GROW_DOWNWARD
3640 stack_area = gen_rtx_MEM (save_mode,
3641 memory_address (save_mode,
3642 plus_constant (argblock,
3645 stack_area = gen_rtx_MEM (save_mode,
3646 memory_address (save_mode,
3647 plus_constant (argblock,
3650 if (save_mode == BLKmode)
3652 save_area = assign_stack_temp (BLKmode, num_to_save, 0);
3653 emit_block_move (validize_mem (save_area), stack_area,
3654 GEN_INT (num_to_save), PARM_BOUNDARY);
3658 save_area = gen_reg_rtx (save_mode);
3659 emit_move_insn (save_area, stack_area);
3665 /* Push the args that need to be pushed. */
3667 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3668 are to be pushed. */
3669 for (count = 0; count < nargs; count++, argnum += inc)
3671 register enum machine_mode mode = argvec[argnum].mode;
3672 register rtx val = argvec[argnum].value;
3673 rtx reg = argvec[argnum].reg;
3674 int partial = argvec[argnum].partial;
3675 int lower_bound = 0, upper_bound = 0, i;
3677 if (! (reg != 0 && partial == 0))
3679 if (ACCUMULATE_OUTGOING_ARGS)
3681 /* If this is being stored into a pre-allocated, fixed-size,
3682 stack area, save any previous data at that location. */
3684 #ifdef ARGS_GROW_DOWNWARD
3685 /* stack_slot is negative, but we want to index stack_usage_map
3686 with positive values. */
3687 upper_bound = -argvec[argnum].offset.constant + 1;
3688 lower_bound = upper_bound - argvec[argnum].size.constant;
3690 lower_bound = argvec[argnum].offset.constant;
3691 upper_bound = lower_bound + argvec[argnum].size.constant;
3694 for (i = lower_bound; i < upper_bound; i++)
3695 if (stack_usage_map[i]
3696 /* Don't store things in the fixed argument area at this
3697 point; it has already been saved. */
3698 && i > reg_parm_stack_space)
3701 if (i != upper_bound)
3703 /* We need to make a save area. See what mode we can make
3705 enum machine_mode save_mode
3706 = mode_for_size (argvec[argnum].size.constant
3714 plus_constant (argblock,
3715 argvec[argnum].offset.constant)));
3716 argvec[argnum].save_area = gen_reg_rtx (save_mode);
3718 emit_move_insn (argvec[argnum].save_area, stack_area);
3722 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
3723 argblock, GEN_INT (argvec[argnum].offset.constant),
3724 reg_parm_stack_space, ARGS_SIZE_RTX (alignment_pad));
3726 /* Now mark the segment we just used. */
3727 if (ACCUMULATE_OUTGOING_ARGS)
3728 for (i = lower_bound; i < upper_bound; i++)
3729 stack_usage_map[i] = 1;
3735 #ifdef PREFERRED_STACK_BOUNDARY
3736 /* If we pushed args in forward order, perform stack alignment
3737 after pushing the last arg. */
3738 if (argblock == 0 && !PUSH_ARGS_REVERSED)
3739 anti_adjust_stack (GEN_INT (args_size.constant
3740 - original_args_size.constant));
3743 if (PUSH_ARGS_REVERSED)
3748 fun = prepare_call_address (fun, NULL_TREE, &call_fusage, 0);
3750 /* Now load any reg parms into their regs. */
3752 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3753 are to be pushed. */
3754 for (count = 0; count < nargs; count++, argnum += inc)
3756 register rtx val = argvec[argnum].value;
3757 rtx reg = argvec[argnum].reg;
3758 int partial = argvec[argnum].partial;
3760 /* Handle calls that pass values in multiple non-contiguous
3761 locations. The PA64 has examples of this for library calls. */
3762 if (reg != 0 && GET_CODE (reg) == PARALLEL)
3763 emit_group_load (reg, val,
3764 GET_MODE_SIZE (GET_MODE (val)),
3765 GET_MODE_ALIGNMENT (GET_MODE (val)));
3766 else if (reg != 0 && partial == 0)
3767 emit_move_insn (reg, val);
3772 /* Any regs containing parms remain in use through the call. */
3773 for (count = 0; count < nargs; count++)
3775 rtx reg = argvec[count].reg;
3776 if (reg != 0 && GET_CODE (reg) == PARALLEL)
3777 use_group_regs (&call_fusage, reg);
3779 use_reg (&call_fusage, reg);
3782 /* Pass the function the address in which to return a structure value. */
3783 if (mem_value != 0 && struct_value_rtx != 0 && ! pcc_struct_value)
3785 emit_move_insn (struct_value_rtx,
3787 force_operand (XEXP (mem_value, 0),
3789 if (GET_CODE (struct_value_rtx) == REG)
3790 use_reg (&call_fusage, struct_value_rtx);
3793 /* Don't allow popping to be deferred, since then
3794 cse'ing of library calls could delete a call and leave the pop. */
3796 valreg = (mem_value == 0 && outmode != VOIDmode
3797 ? hard_libcall_value (outmode) : NULL_RTX);
3799 #ifdef PREFERRED_STACK_BOUNDARY
3800 /* Stack must be properly aligned now. */
3801 if (stack_pointer_delta & (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1))
3805 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
3806 will set inhibit_defer_pop to that value. */
3807 /* The return type is needed to decide how many bytes the function pops.
3808 Signedness plays no role in that, so for simplicity, we pretend it's
3809 always signed. We also assume that the list of arguments passed has
3810 no impact, so we pretend it is unknown. */
3813 get_identifier (XSTR (orgfun, 0)),
3814 build_function_type (outmode == VOIDmode ? void_type_node
3815 : type_for_mode (outmode, 0), NULL_TREE),
3816 original_args_size.constant, args_size.constant,
3818 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
3820 old_inhibit_defer_pop + 1, call_fusage, flags);
3822 /* Now restore inhibit_defer_pop to its actual original value. */
3825 /* If call is cse'able, make appropriate pair of reg-notes around it.
3826 Test valreg so we don't crash; may safely ignore `const'
3827 if return type is void. Disable for PARALLEL return values, because
3828 we have no way to move such values into a pseudo register. */
3829 if ((flags & (ECF_CONST | ECF_PURE))
3830 && valreg != 0 && GET_CODE (valreg) != PARALLEL)
3833 rtx temp = gen_reg_rtx (GET_MODE (valreg));
3837 /* Construct an "equal form" for the value which mentions all the
3838 arguments in order as well as the function name. */
3839 for (i = 0; i < nargs; i++)
3840 note = gen_rtx_EXPR_LIST (VOIDmode, argvec[i].value, note);
3841 note = gen_rtx_EXPR_LIST (VOIDmode, fun, note);
3843 insns = get_insns ();
3846 if (flags & ECF_PURE)
3847 note = gen_rtx_EXPR_LIST (VOIDmode,
3848 gen_rtx_USE (VOIDmode,
3849 gen_rtx_MEM (BLKmode,
3850 gen_rtx_SCRATCH (VOIDmode))), note);
3852 emit_libcall_block (insns, temp, valreg, note);
3856 else if (flags & (ECF_CONST | ECF_PURE))
3858 /* Otherwise, just write out the sequence without a note. */
3859 rtx insns = get_insns ();
3866 /* Copy the value to the right place. */
3867 if (outmode != VOIDmode && retval)
3873 if (value != mem_value)
3874 emit_move_insn (value, mem_value);
3876 else if (value != 0)
3877 emit_move_insn (value, hard_libcall_value (outmode));
3879 value = hard_libcall_value (outmode);
3882 if (ACCUMULATE_OUTGOING_ARGS)
3884 #ifdef REG_PARM_STACK_SPACE
3887 enum machine_mode save_mode = GET_MODE (save_area);
3888 #ifdef ARGS_GROW_DOWNWARD
3890 = gen_rtx_MEM (save_mode,
3891 memory_address (save_mode,
3892 plus_constant (argblock,
3896 = gen_rtx_MEM (save_mode,
3897 memory_address (save_mode,
3898 plus_constant (argblock, low_to_save)));
3900 if (save_mode != BLKmode)
3901 emit_move_insn (stack_area, save_area);
3903 emit_block_move (stack_area, validize_mem (save_area),
3904 GEN_INT (high_to_save - low_to_save + 1),
3909 /* If we saved any argument areas, restore them. */
3910 for (count = 0; count < nargs; count++)
3911 if (argvec[count].save_area)
3913 enum machine_mode save_mode = GET_MODE (argvec[count].save_area);
3915 = gen_rtx_MEM (save_mode,
3918 plus_constant (argblock,
3919 argvec[count].offset.constant)));
3921 emit_move_insn (stack_area, argvec[count].save_area);
3924 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3925 stack_usage_map = initial_stack_usage_map;
3932 /* Output a library call to function FUN (a SYMBOL_REF rtx)
3933 (emitting the queue unless NO_QUEUE is nonzero),
3934 for a value of mode OUTMODE,
3935 with NARGS different arguments, passed as alternating rtx values
3936 and machine_modes to convert them to.
3937 The rtx values should have been passed through protect_from_queue already.
3939 FN_TYPE will is zero for `normal' calls, one for `const' calls, wich
3940 which will be enclosed in REG_LIBCALL/REG_RETVAL notes and two for `pure'
3941 calls, that are handled like `const' calls with extra
3942 (use (memory (scratch)). */
3945 emit_library_call VPARAMS((rtx orgfun, int fn_type, enum machine_mode outmode,
3948 #ifndef ANSI_PROTOTYPES
3951 enum machine_mode outmode;
3956 VA_START (p, nargs);
3958 #ifndef ANSI_PROTOTYPES
3959 orgfun = va_arg (p, rtx);
3960 fn_type = va_arg (p, int);
3961 outmode = va_arg (p, enum machine_mode);
3962 nargs = va_arg (p, int);
3965 emit_library_call_value_1 (0, orgfun, NULL_RTX, fn_type, outmode, nargs, p);
3970 /* Like emit_library_call except that an extra argument, VALUE,
3971 comes second and says where to store the result.
3972 (If VALUE is zero, this function chooses a convenient way
3973 to return the value.
3975 This function returns an rtx for where the value is to be found.
3976 If VALUE is nonzero, VALUE is returned. */
3979 emit_library_call_value VPARAMS((rtx orgfun, rtx value, int fn_type,
3980 enum machine_mode outmode, int nargs, ...))
3982 #ifndef ANSI_PROTOTYPES
3986 enum machine_mode outmode;
3991 VA_START (p, nargs);
3993 #ifndef ANSI_PROTOTYPES
3994 orgfun = va_arg (p, rtx);
3995 value = va_arg (p, rtx);
3996 fn_type = va_arg (p, int);
3997 outmode = va_arg (p, enum machine_mode);
3998 nargs = va_arg (p, int);
4001 value = emit_library_call_value_1 (1, orgfun, value, fn_type, outmode, nargs, p);
4009 /* Return an rtx which represents a suitable home on the stack
4010 given TYPE, the type of the argument looking for a home.
4011 This is called only for BLKmode arguments.
4013 SIZE is the size needed for this target.
4014 ARGS_ADDR is the address of the bottom of the argument block for this call.
4015 OFFSET describes this parameter's offset into ARGS_ADDR. It is meaningless
4016 if this machine uses push insns. */
4019 target_for_arg (type, size, args_addr, offset)
4023 struct args_size offset;
4026 rtx offset_rtx = ARGS_SIZE_RTX (offset);
4028 /* We do not call memory_address if possible,
4029 because we want to address as close to the stack
4030 as possible. For non-variable sized arguments,
4031 this will be stack-pointer relative addressing. */
4032 if (GET_CODE (offset_rtx) == CONST_INT)
4033 target = plus_constant (args_addr, INTVAL (offset_rtx));
4036 /* I have no idea how to guarantee that this
4037 will work in the presence of register parameters. */
4038 target = gen_rtx_PLUS (Pmode, args_addr, offset_rtx);
4039 target = memory_address (QImode, target);
4042 return gen_rtx_MEM (BLKmode, target);
4046 /* Store a single argument for a function call
4047 into the register or memory area where it must be passed.
4048 *ARG describes the argument value and where to pass it.
4050 ARGBLOCK is the address of the stack-block for all the arguments,
4051 or 0 on a machine where arguments are pushed individually.
4053 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
4054 so must be careful about how the stack is used.
4056 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
4057 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
4058 that we need not worry about saving and restoring the stack.
4060 FNDECL is the declaration of the function we are calling. */
4063 store_one_arg (arg, argblock, flags, variable_size,
4064 reg_parm_stack_space)
4065 struct arg_data *arg;
4068 int variable_size ATTRIBUTE_UNUSED;
4069 int reg_parm_stack_space;
4071 register tree pval = arg->tree_value;
4075 int i, lower_bound = 0, upper_bound = 0;
4077 if (TREE_CODE (pval) == ERROR_MARK)
4080 /* Push a new temporary level for any temporaries we make for
4084 if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL))
4086 /* If this is being stored into a pre-allocated, fixed-size, stack area,
4087 save any previous data at that location. */
4088 if (argblock && ! variable_size && arg->stack)
4090 #ifdef ARGS_GROW_DOWNWARD
4091 /* stack_slot is negative, but we want to index stack_usage_map
4092 with positive values. */
4093 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
4094 upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
4098 lower_bound = upper_bound - arg->size.constant;
4100 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
4101 lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
4105 upper_bound = lower_bound + arg->size.constant;
4108 for (i = lower_bound; i < upper_bound; i++)
4109 if (stack_usage_map[i]
4110 /* Don't store things in the fixed argument area at this point;
4111 it has already been saved. */
4112 && i > reg_parm_stack_space)
4115 if (i != upper_bound)
4117 /* We need to make a save area. See what mode we can make it. */
4118 enum machine_mode save_mode
4119 = mode_for_size (arg->size.constant * BITS_PER_UNIT, MODE_INT, 1);
4121 = gen_rtx_MEM (save_mode,
4122 memory_address (save_mode,
4123 XEXP (arg->stack_slot, 0)));
4125 if (save_mode == BLKmode)
4127 arg->save_area = assign_stack_temp (BLKmode,
4128 arg->size.constant, 0);
4129 MEM_SET_IN_STRUCT_P (arg->save_area,
4130 AGGREGATE_TYPE_P (TREE_TYPE
4131 (arg->tree_value)));
4132 preserve_temp_slots (arg->save_area);
4133 emit_block_move (validize_mem (arg->save_area), stack_area,
4134 GEN_INT (arg->size.constant),
4139 arg->save_area = gen_reg_rtx (save_mode);
4140 emit_move_insn (arg->save_area, stack_area);
4144 /* Now that we have saved any slots that will be overwritten by this
4145 store, mark all slots this store will use. We must do this before
4146 we actually expand the argument since the expansion itself may
4147 trigger library calls which might need to use the same stack slot. */
4148 if (argblock && ! variable_size && arg->stack)
4149 for (i = lower_bound; i < upper_bound; i++)
4150 stack_usage_map[i] = 1;
4153 /* If this isn't going to be placed on both the stack and in registers,
4154 set up the register and number of words. */
4155 if (! arg->pass_on_stack)
4156 reg = arg->reg, partial = arg->partial;
4158 if (reg != 0 && partial == 0)
4159 /* Being passed entirely in a register. We shouldn't be called in
4163 /* If this arg needs special alignment, don't load the registers
4165 if (arg->n_aligned_regs != 0)
4168 /* If this is being passed partially in a register, we can't evaluate
4169 it directly into its stack slot. Otherwise, we can. */
4170 if (arg->value == 0)
4172 /* stack_arg_under_construction is nonzero if a function argument is
4173 being evaluated directly into the outgoing argument list and
4174 expand_call must take special action to preserve the argument list
4175 if it is called recursively.
4177 For scalar function arguments stack_usage_map is sufficient to
4178 determine which stack slots must be saved and restored. Scalar
4179 arguments in general have pass_on_stack == 0.
4181 If this argument is initialized by a function which takes the
4182 address of the argument (a C++ constructor or a C function
4183 returning a BLKmode structure), then stack_usage_map is
4184 insufficient and expand_call must push the stack around the
4185 function call. Such arguments have pass_on_stack == 1.
4187 Note that it is always safe to set stack_arg_under_construction,
4188 but this generates suboptimal code if set when not needed. */
4190 if (arg->pass_on_stack)
4191 stack_arg_under_construction++;
4193 arg->value = expand_expr (pval,
4195 || TYPE_MODE (TREE_TYPE (pval)) != arg->mode)
4196 ? NULL_RTX : arg->stack,
4199 /* If we are promoting object (or for any other reason) the mode
4200 doesn't agree, convert the mode. */
4202 if (arg->mode != TYPE_MODE (TREE_TYPE (pval)))
4203 arg->value = convert_modes (arg->mode, TYPE_MODE (TREE_TYPE (pval)),
4204 arg->value, arg->unsignedp);
4206 if (arg->pass_on_stack)
4207 stack_arg_under_construction--;
4210 /* Don't allow anything left on stack from computation
4211 of argument to alloca. */
4212 if (flags & ECF_MAY_BE_ALLOCA)
4213 do_pending_stack_adjust ();
4215 if (arg->value == arg->stack)
4217 /* If the value is already in the stack slot, we are done. */
4218 if (current_function_check_memory_usage && GET_CODE (arg->stack) == MEM)
4220 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
4221 XEXP (arg->stack, 0), Pmode,
4222 ARGS_SIZE_RTX (arg->size),
4223 TYPE_MODE (sizetype),
4224 GEN_INT (MEMORY_USE_RW),
4225 TYPE_MODE (integer_type_node));
4228 else if (arg->mode != BLKmode)
4232 /* Argument is a scalar, not entirely passed in registers.
4233 (If part is passed in registers, arg->partial says how much
4234 and emit_push_insn will take care of putting it there.)
4236 Push it, and if its size is less than the
4237 amount of space allocated to it,
4238 also bump stack pointer by the additional space.
4239 Note that in C the default argument promotions
4240 will prevent such mismatches. */
4242 size = GET_MODE_SIZE (arg->mode);
4243 /* Compute how much space the push instruction will push.
4244 On many machines, pushing a byte will advance the stack
4245 pointer by a halfword. */
4246 #ifdef PUSH_ROUNDING
4247 size = PUSH_ROUNDING (size);
4251 /* Compute how much space the argument should get:
4252 round up to a multiple of the alignment for arguments. */
4253 if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)))
4254 used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
4255 / (PARM_BOUNDARY / BITS_PER_UNIT))
4256 * (PARM_BOUNDARY / BITS_PER_UNIT));
4258 /* This isn't already where we want it on the stack, so put it there.
4259 This can either be done with push or copy insns. */
4260 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX, 0,
4261 partial, reg, used - size, argblock,
4262 ARGS_SIZE_RTX (arg->offset), reg_parm_stack_space,
4263 ARGS_SIZE_RTX (arg->alignment_pad));
4267 /* BLKmode, at least partly to be pushed. */
4269 register int excess;
4272 /* Pushing a nonscalar.
4273 If part is passed in registers, PARTIAL says how much
4274 and emit_push_insn will take care of putting it there. */
4276 /* Round its size up to a multiple
4277 of the allocation unit for arguments. */
4279 if (arg->size.var != 0)
4282 size_rtx = ARGS_SIZE_RTX (arg->size);
4286 /* PUSH_ROUNDING has no effect on us, because
4287 emit_push_insn for BLKmode is careful to avoid it. */
4288 excess = (arg->size.constant - int_size_in_bytes (TREE_TYPE (pval))
4289 + partial * UNITS_PER_WORD);
4290 size_rtx = expr_size (pval);
4293 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
4294 TYPE_ALIGN (TREE_TYPE (pval)), partial, reg, excess,
4295 argblock, ARGS_SIZE_RTX (arg->offset),
4296 reg_parm_stack_space,
4297 ARGS_SIZE_RTX (arg->alignment_pad));
4301 /* Unless this is a partially-in-register argument, the argument is now
4304 ??? Note that this can change arg->value from arg->stack to
4305 arg->stack_slot and it matters when they are not the same.
4306 It isn't totally clear that this is correct in all cases. */
4308 arg->value = arg->stack_slot;
4310 /* Once we have pushed something, pops can't safely
4311 be deferred during the rest of the arguments. */
4314 /* ANSI doesn't require a sequence point here,
4315 but PCC has one, so this will avoid some problems. */
4318 /* Free any temporary slots made in processing this argument. Show
4319 that we might have taken the address of something and pushed that
4321 preserve_temp_slots (NULL_RTX);