1 /* Convert function calls to rtl insns, for GNU C compiler.
2 Copyright (C) 1989, 92-99, 2000 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
29 #include "insn-flags.h"
34 #if !defined PREFERRED_STACK_BOUNDARY && defined STACK_BOUNDARY
35 #define PREFERRED_STACK_BOUNDARY STACK_BOUNDARY
38 /* Decide whether a function's arguments should be processed
39 from first to last or from last to first.
41 They should if the stack and args grow in opposite directions, but
42 only if we have push insns. */
46 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
47 #define PUSH_ARGS_REVERSED /* If it's last to first */
52 /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */
53 #define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
55 /* Data structure and subroutines used within expand_call. */
59 /* Tree node for this argument. */
61 /* Mode for value; TYPE_MODE unless promoted. */
62 enum machine_mode mode;
63 /* Current RTL value for argument, or 0 if it isn't precomputed. */
65 /* Initially-compute RTL value for argument; only for const functions. */
67 /* Register to pass this argument in, 0 if passed on stack, or an
68 PARALLEL if the arg is to be copied into multiple non-contiguous
71 /* If REG was promoted from the actual mode of the argument expression,
72 indicates whether the promotion is sign- or zero-extended. */
74 /* Number of registers to use. 0 means put the whole arg in registers.
75 Also 0 if not passed in registers. */
77 /* Non-zero if argument must be passed on stack.
78 Note that some arguments may be passed on the stack
79 even though pass_on_stack is zero, just because FUNCTION_ARG says so.
80 pass_on_stack identifies arguments that *cannot* go in registers. */
82 /* Offset of this argument from beginning of stack-args. */
83 struct args_size offset;
84 /* Similar, but offset to the start of the stack slot. Different from
85 OFFSET if this arg pads downward. */
86 struct args_size slot_offset;
87 /* Size of this argument on the stack, rounded up for any padding it gets,
88 parts of the argument passed in registers do not count.
89 If REG_PARM_STACK_SPACE is defined, then register parms
90 are counted here as well. */
91 struct args_size size;
92 /* Location on the stack at which parameter should be stored. The store
93 has already been done if STACK == VALUE. */
95 /* Location on the stack of the start of this argument slot. This can
96 differ from STACK if this arg pads downward. This location is known
97 to be aligned to FUNCTION_ARG_BOUNDARY. */
99 #ifdef ACCUMULATE_OUTGOING_ARGS
100 /* Place that this stack area has been saved, if needed. */
103 /* If an argument's alignment does not permit direct copying into registers,
104 copy in smaller-sized pieces into pseudos. These are stored in a
105 block pointed to by this field. The next field says how many
106 word-sized pseudos we made. */
109 /* The amount that the stack pointer needs to be adjusted to
110 force alignment for the next argument. */
111 struct args_size alignment_pad;
114 #ifdef ACCUMULATE_OUTGOING_ARGS
115 /* A vector of one char per byte of stack space. A byte if non-zero if
116 the corresponding stack location has been used.
117 This vector is used to prevent a function call within an argument from
118 clobbering any stack already set up. */
119 static char *stack_usage_map;
121 /* Size of STACK_USAGE_MAP. */
122 static int highest_outgoing_arg_in_use;
124 /* stack_arg_under_construction is nonzero when an argument may be
125 initialized with a constructor call (including a C function that
126 returns a BLKmode struct) and expand_call must take special action
127 to make sure the object being constructed does not overlap the
128 argument list for the constructor call. */
129 int stack_arg_under_construction;
132 static int calls_function PARAMS ((tree, int));
133 static int calls_function_1 PARAMS ((tree, int));
134 static void emit_call_1 PARAMS ((rtx, tree, tree, HOST_WIDE_INT,
135 HOST_WIDE_INT, HOST_WIDE_INT, rtx,
136 rtx, int, rtx, int));
137 static void precompute_register_parameters PARAMS ((int,
140 static void store_one_arg PARAMS ((struct arg_data *, rtx, int, int,
142 static void store_unaligned_arguments_into_pseudos PARAMS ((struct arg_data *,
144 static int finalize_must_preallocate PARAMS ((int, int,
146 struct args_size *));
147 static void precompute_arguments PARAMS ((int, int, int,
149 struct args_size *));
150 static int compute_argument_block_size PARAMS ((int,
151 struct args_size *));
152 static void initialize_argument_information PARAMS ((int,
159 static void compute_argument_addresses PARAMS ((struct arg_data *,
161 static rtx rtx_for_function_call PARAMS ((tree, tree));
162 static void load_register_parameters PARAMS ((struct arg_data *,
165 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
166 static rtx save_fixed_argument_area PARAMS ((int, rtx, int *, int *));
167 static void restore_fixed_argument_area PARAMS ((rtx, rtx, int, int));
170 /* If WHICH is 1, return 1 if EXP contains a call to the built-in function
173 If WHICH is 0, return 1 if EXP contains a call to any function.
174 Actually, we only need return 1 if evaluating EXP would require pushing
175 arguments on the stack, but that is too difficult to compute, so we just
176 assume any function call might require the stack. */
178 static tree calls_function_save_exprs;
181 calls_function (exp, which)
186 calls_function_save_exprs = 0;
187 val = calls_function_1 (exp, which);
188 calls_function_save_exprs = 0;
193 calls_function_1 (exp, which)
198 enum tree_code code = TREE_CODE (exp);
199 int type = TREE_CODE_CLASS (code);
200 int length = tree_code_length[(int) code];
202 /* If this code is language-specific, we don't know what it will do. */
203 if ((int) code >= NUM_TREE_CODES)
206 /* Only expressions and references can contain calls. */
207 if (type != 'e' && type != '<' && type != '1' && type != '2' && type != 'r'
216 else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
217 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
220 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
222 if ((DECL_BUILT_IN (fndecl)
223 && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
224 && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA)
225 || (DECL_SAVED_INSNS (fndecl)
226 && DECL_SAVED_INSNS (fndecl)->calls_alloca))
230 /* Third operand is RTL. */
235 if (SAVE_EXPR_RTL (exp) != 0)
237 if (value_member (exp, calls_function_save_exprs))
239 calls_function_save_exprs = tree_cons (NULL_TREE, exp,
240 calls_function_save_exprs);
241 return (TREE_OPERAND (exp, 0) != 0
242 && calls_function_1 (TREE_OPERAND (exp, 0), which));
248 for (local = BLOCK_VARS (exp); local; local = TREE_CHAIN (local))
249 if (DECL_INITIAL (local) != 0
250 && calls_function_1 (DECL_INITIAL (local), which))
254 register tree subblock;
256 for (subblock = BLOCK_SUBBLOCKS (exp);
258 subblock = TREE_CHAIN (subblock))
259 if (calls_function_1 (subblock, which))
264 case METHOD_CALL_EXPR:
268 case WITH_CLEANUP_EXPR:
279 for (i = 0; i < length; i++)
280 if (TREE_OPERAND (exp, i) != 0
281 && calls_function_1 (TREE_OPERAND (exp, i), which))
287 /* Force FUNEXP into a form suitable for the address of a CALL,
288 and return that as an rtx. Also load the static chain register
289 if FNDECL is a nested function.
291 CALL_FUSAGE points to a variable holding the prospective
292 CALL_INSN_FUNCTION_USAGE information. */
295 prepare_call_address (funexp, fndecl, call_fusage, reg_parm_seen)
301 rtx static_chain_value = 0;
303 funexp = protect_from_queue (funexp, 0);
306 /* Get possible static chain value for nested function in C. */
307 static_chain_value = lookup_static_chain (fndecl);
309 /* Make a valid memory address and copy constants thru pseudo-regs,
310 but not for a constant address if -fno-function-cse. */
311 if (GET_CODE (funexp) != SYMBOL_REF)
312 /* If we are using registers for parameters, force the
313 function address into a register now. */
314 funexp = ((SMALL_REGISTER_CLASSES && reg_parm_seen)
315 ? force_not_mem (memory_address (FUNCTION_MODE, funexp))
316 : memory_address (FUNCTION_MODE, funexp));
319 #ifndef NO_FUNCTION_CSE
320 if (optimize && ! flag_no_function_cse)
321 #ifdef NO_RECURSIVE_FUNCTION_CSE
322 if (fndecl != current_function_decl)
324 funexp = force_reg (Pmode, funexp);
328 if (static_chain_value != 0)
330 emit_move_insn (static_chain_rtx, static_chain_value);
332 if (GET_CODE (static_chain_rtx) == REG)
333 use_reg (call_fusage, static_chain_rtx);
339 /* Generate instructions to call function FUNEXP,
340 and optionally pop the results.
341 The CALL_INSN is the first insn generated.
343 FNDECL is the declaration node of the function. This is given to the
344 macro RETURN_POPS_ARGS to determine whether this function pops its own args.
346 FUNTYPE is the data type of the function. This is given to the macro
347 RETURN_POPS_ARGS to determine whether this function pops its own args.
348 We used to allow an identifier for library functions, but that doesn't
349 work when the return type is an aggregate type and the calling convention
350 says that the pointer to this aggregate is to be popped by the callee.
352 STACK_SIZE is the number of bytes of arguments on the stack,
353 rounded up to PREFERRED_STACK_BOUNDARY; zero if the size is variable.
354 This is both to put into the call insn and
355 to generate explicit popping code if necessary.
357 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
358 It is zero if this call doesn't want a structure value.
360 NEXT_ARG_REG is the rtx that results from executing
361 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1)
362 just after all the args have had their registers assigned.
363 This could be whatever you like, but normally it is the first
364 arg-register beyond those used for args in this call,
365 or 0 if all the arg-registers are used in this call.
366 It is passed on to `gen_call' so you can put this info in the call insn.
368 VALREG is a hard register in which a value is returned,
369 or 0 if the call does not return a value.
371 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
372 the args to this call were processed.
373 We restore `inhibit_defer_pop' to that value.
375 CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
376 denote registers used by the called function.
378 IS_CONST is true if this is a `const' call. */
381 emit_call_1 (funexp, fndecl, funtype, stack_size, rounded_stack_size,
382 struct_value_size, next_arg_reg, valreg, old_inhibit_defer_pop,
383 call_fusage, is_const)
385 tree fndecl ATTRIBUTE_UNUSED;
386 tree funtype ATTRIBUTE_UNUSED;
387 HOST_WIDE_INT stack_size ATTRIBUTE_UNUSED;
388 HOST_WIDE_INT rounded_stack_size;
389 HOST_WIDE_INT struct_value_size ATTRIBUTE_UNUSED;
392 int old_inhibit_defer_pop;
396 rtx rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
397 #if defined (HAVE_call) && defined (HAVE_call_value)
398 rtx struct_value_size_rtx = GEN_INT (struct_value_size);
401 #ifndef ACCUMULATE_OUTGOING_ARGS
402 int already_popped = 0;
403 HOST_WIDE_INT n_popped = RETURN_POPS_ARGS (fndecl, funtype, stack_size);
406 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
407 and we don't want to load it into a register as an optimization,
408 because prepare_call_address already did it if it should be done. */
409 if (GET_CODE (funexp) != SYMBOL_REF)
410 funexp = memory_address (FUNCTION_MODE, funexp);
412 #ifndef ACCUMULATE_OUTGOING_ARGS
413 #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
414 /* If the target has "call" or "call_value" insns, then prefer them
415 if no arguments are actually popped. If the target does not have
416 "call" or "call_value" insns, then we must use the popping versions
417 even if the call has no arguments to pop. */
418 #if defined (HAVE_call) && defined (HAVE_call_value)
419 if (HAVE_call && HAVE_call_value && HAVE_call_pop && HAVE_call_value_pop
422 if (HAVE_call_pop && HAVE_call_value_pop)
425 rtx n_pop = GEN_INT (n_popped);
428 /* If this subroutine pops its own args, record that in the call insn
429 if possible, for the sake of frame pointer elimination. */
432 pat = gen_call_value_pop (valreg,
433 gen_rtx_MEM (FUNCTION_MODE, funexp),
434 rounded_stack_size_rtx, next_arg_reg, n_pop);
436 pat = gen_call_pop (gen_rtx_MEM (FUNCTION_MODE, funexp),
437 rounded_stack_size_rtx, next_arg_reg, n_pop);
439 emit_call_insn (pat);
446 #if defined (HAVE_call) && defined (HAVE_call_value)
447 if (HAVE_call && HAVE_call_value)
450 emit_call_insn (gen_call_value (valreg,
451 gen_rtx_MEM (FUNCTION_MODE, funexp),
452 rounded_stack_size_rtx, next_arg_reg,
455 emit_call_insn (gen_call (gen_rtx_MEM (FUNCTION_MODE, funexp),
456 rounded_stack_size_rtx, next_arg_reg,
457 struct_value_size_rtx));
463 /* Find the CALL insn we just emitted. */
464 for (call_insn = get_last_insn ();
465 call_insn && GET_CODE (call_insn) != CALL_INSN;
466 call_insn = PREV_INSN (call_insn))
472 /* Put the register usage information on the CALL. If there is already
473 some usage information, put ours at the end. */
474 if (CALL_INSN_FUNCTION_USAGE (call_insn))
478 for (link = CALL_INSN_FUNCTION_USAGE (call_insn); XEXP (link, 1) != 0;
479 link = XEXP (link, 1))
482 XEXP (link, 1) = call_fusage;
485 CALL_INSN_FUNCTION_USAGE (call_insn) = call_fusage;
487 /* If this is a const call, then set the insn's unchanging bit. */
489 CONST_CALL_P (call_insn) = 1;
491 /* Restore this now, so that we do defer pops for this call's args
492 if the context of the call as a whole permits. */
493 inhibit_defer_pop = old_inhibit_defer_pop;
495 #ifndef ACCUMULATE_OUTGOING_ARGS
496 /* If returning from the subroutine does not automatically pop the args,
497 we need an instruction to pop them sooner or later.
498 Perhaps do it now; perhaps just record how much space to pop later.
500 If returning from the subroutine does pop the args, indicate that the
501 stack pointer will be changed. */
506 CALL_INSN_FUNCTION_USAGE (call_insn)
507 = gen_rtx_EXPR_LIST (VOIDmode,
508 gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx),
509 CALL_INSN_FUNCTION_USAGE (call_insn));
510 rounded_stack_size -= n_popped;
511 rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
514 if (rounded_stack_size != 0)
516 if (flag_defer_pop && inhibit_defer_pop == 0 && !is_const)
517 pending_stack_adjust += rounded_stack_size;
519 adjust_stack (rounded_stack_size_rtx);
524 /* Determine if the function identified by NAME and FNDECL is one with
525 special properties we wish to know about.
527 For example, if the function might return more than one time (setjmp), then
528 set RETURNS_TWICE to a nonzero value.
530 Similarly set IS_LONGJMP for if the function is in the longjmp family.
532 Set IS_MALLOC for any of the standard memory allocation functions which
533 allocate from the heap.
535 Set MAY_BE_ALLOCA for any memory allocation function that might allocate
536 space from the stack such as alloca. */
539 special_function_p (fndecl, returns_twice, is_longjmp, fork_or_exec,
540 is_malloc, may_be_alloca)
553 /* The function decl may have the `malloc' attribute. */
554 *is_malloc = fndecl && DECL_IS_MALLOC (fndecl);
557 && fndecl && DECL_NAME (fndecl)
558 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 17
559 /* Exclude functions not at the file scope, or not `extern',
560 since they are not the magic functions we would otherwise
562 && DECL_CONTEXT (fndecl) == NULL_TREE && TREE_PUBLIC (fndecl))
564 char *name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
567 /* We assume that alloca will always be called by name. It
568 makes no sense to pass it as a pointer-to-function to
569 anything that does not understand its behavior. */
571 = (((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 6
573 && ! strcmp (name, "alloca"))
574 || (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 16
576 && ! strcmp (name, "__builtin_alloca"))));
578 /* Disregard prefix _, __ or __x. */
581 if (name[1] == '_' && name[2] == 'x')
583 else if (name[1] == '_')
593 && (! strcmp (tname, "setjmp")
594 || ! strcmp (tname, "setjmp_syscall")))
596 && ! strcmp (tname, "sigsetjmp"))
598 && ! strcmp (tname, "savectx")));
600 && ! strcmp (tname, "siglongjmp"))
603 else if ((tname[0] == 'q' && tname[1] == 's'
604 && ! strcmp (tname, "qsetjmp"))
605 || (tname[0] == 'v' && tname[1] == 'f'
606 && ! strcmp (tname, "vfork")))
609 else if (tname[0] == 'l' && tname[1] == 'o'
610 && ! strcmp (tname, "longjmp"))
613 else if ((tname[0] == 'f' && tname[1] == 'o'
614 && ! strcmp (tname, "fork"))
615 /* Linux specific: __clone. check NAME to insist on the
616 leading underscores, to avoid polluting the ISO / POSIX
618 || (name[0] == '_' && name[1] == '_'
619 && ! strcmp (tname, "clone"))
620 || (tname[0] == 'e' && tname[1] == 'x' && tname[2] == 'e'
621 && tname[3] == 'c' && (tname[4] == 'l' || tname[4] == 'v')
623 || ((tname[5] == 'p' || tname[5] == 'e')
624 && tname[6] == '\0'))))
627 /* Do not add any more malloc-like functions to this list,
628 instead mark them as malloc functions using the malloc attribute.
629 Note, realloc is not suitable for attribute malloc since
630 it may return the same address across multiple calls. */
631 else if (! strcmp (tname, "malloc")
632 || ! strcmp (tname, "calloc")
633 || ! strcmp (tname, "strdup")
634 /* Note use of NAME rather than TNAME here. These functions
635 are only reserved when preceded with __. */
636 || ! strcmp (name, "__vn") /* mangled __builtin_vec_new */
637 || ! strcmp (name, "__nw") /* mangled __builtin_new */
638 || ! strcmp (name, "__builtin_new")
639 || ! strcmp (name, "__builtin_vec_new"))
644 /* Precompute all register parameters as described by ARGS, storing values
645 into fields within the ARGS array.
647 NUM_ACTUALS indicates the total number elements in the ARGS array.
649 Set REG_PARM_SEEN if we encounter a register parameter. */
652 precompute_register_parameters (num_actuals, args, reg_parm_seen)
654 struct arg_data *args;
661 for (i = 0; i < num_actuals; i++)
662 if (args[i].reg != 0 && ! args[i].pass_on_stack)
666 if (args[i].value == 0)
669 args[i].value = expand_expr (args[i].tree_value, NULL_RTX,
671 preserve_temp_slots (args[i].value);
674 /* ANSI doesn't require a sequence point here,
675 but PCC has one, so this will avoid some problems. */
679 /* If we are to promote the function arg to a wider mode,
682 if (args[i].mode != TYPE_MODE (TREE_TYPE (args[i].tree_value)))
684 = convert_modes (args[i].mode,
685 TYPE_MODE (TREE_TYPE (args[i].tree_value)),
686 args[i].value, args[i].unsignedp);
688 /* If the value is expensive, and we are inside an appropriately
689 short loop, put the value into a pseudo and then put the pseudo
692 For small register classes, also do this if this call uses
693 register parameters. This is to avoid reload conflicts while
694 loading the parameters registers. */
696 if ((! (GET_CODE (args[i].value) == REG
697 || (GET_CODE (args[i].value) == SUBREG
698 && GET_CODE (SUBREG_REG (args[i].value)) == REG)))
699 && args[i].mode != BLKmode
700 && rtx_cost (args[i].value, SET) > 2
701 && ((SMALL_REGISTER_CLASSES && *reg_parm_seen)
702 || preserve_subexpressions_p ()))
703 args[i].value = copy_to_mode_reg (args[i].mode, args[i].value);
707 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
709 /* The argument list is the property of the called routine and it
710 may clobber it. If the fixed area has been used for previous
711 parameters, we must save and restore it. */
713 save_fixed_argument_area (reg_parm_stack_space, argblock,
714 low_to_save, high_to_save)
715 int reg_parm_stack_space;
721 rtx save_area = NULL_RTX;
723 /* Compute the boundary of the that needs to be saved, if any. */
724 #ifdef ARGS_GROW_DOWNWARD
725 for (i = 0; i < reg_parm_stack_space + 1; i++)
727 for (i = 0; i < reg_parm_stack_space; i++)
730 if (i >= highest_outgoing_arg_in_use
731 || stack_usage_map[i] == 0)
734 if (*low_to_save == -1)
740 if (*low_to_save >= 0)
742 int num_to_save = *high_to_save - *low_to_save + 1;
743 enum machine_mode save_mode
744 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
747 /* If we don't have the required alignment, must do this in BLKmode. */
748 if ((*low_to_save & (MIN (GET_MODE_SIZE (save_mode),
749 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
752 #ifdef ARGS_GROW_DOWNWARD
753 stack_area = gen_rtx_MEM (save_mode,
754 memory_address (save_mode,
755 plus_constant (argblock,
758 stack_area = gen_rtx_MEM (save_mode,
759 memory_address (save_mode,
760 plus_constant (argblock,
763 if (save_mode == BLKmode)
765 save_area = assign_stack_temp (BLKmode, num_to_save, 0);
766 /* Cannot use emit_block_move here because it can be done by a library
767 call which in turn gets into this place again and deadly infinite
768 recursion happens. */
769 move_by_pieces (validize_mem (save_area), stack_area, num_to_save,
770 PARM_BOUNDARY / BITS_PER_UNIT);
774 save_area = gen_reg_rtx (save_mode);
775 emit_move_insn (save_area, stack_area);
782 restore_fixed_argument_area (save_area, argblock, high_to_save, low_to_save)
788 enum machine_mode save_mode = GET_MODE (save_area);
789 #ifdef ARGS_GROW_DOWNWARD
791 = gen_rtx_MEM (save_mode,
792 memory_address (save_mode,
793 plus_constant (argblock,
797 = gen_rtx_MEM (save_mode,
798 memory_address (save_mode,
799 plus_constant (argblock,
803 if (save_mode != BLKmode)
804 emit_move_insn (stack_area, save_area);
806 /* Cannot use emit_block_move here because it can be done by a library
807 call which in turn gets into this place again and deadly infinite
808 recursion happens. */
809 move_by_pieces (stack_area, validize_mem (save_area),
810 high_to_save - low_to_save + 1,
811 PARM_BOUNDARY / BITS_PER_UNIT);
815 /* If any elements in ARGS refer to parameters that are to be passed in
816 registers, but not in memory, and whose alignment does not permit a
817 direct copy into registers. Copy the values into a group of pseudos
818 which we will later copy into the appropriate hard registers.
820 Pseudos for each unaligned argument will be stored into the array
821 args[argnum].aligned_regs. The caller is responsible for deallocating
822 the aligned_regs array if it is nonzero. */
825 store_unaligned_arguments_into_pseudos (args, num_actuals)
826 struct arg_data *args;
831 for (i = 0; i < num_actuals; i++)
832 if (args[i].reg != 0 && ! args[i].pass_on_stack
833 && args[i].mode == BLKmode
834 && (TYPE_ALIGN (TREE_TYPE (args[i].tree_value))
835 < (unsigned int) MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD)))
837 int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
838 int big_endian_correction = 0;
840 args[i].n_aligned_regs
841 = args[i].partial ? args[i].partial
842 : (bytes + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
844 args[i].aligned_regs = (rtx *) xmalloc (sizeof (rtx)
845 * args[i].n_aligned_regs);
847 /* Structures smaller than a word are aligned to the least
848 significant byte (to the right). On a BYTES_BIG_ENDIAN machine,
849 this means we must skip the empty high order bytes when
850 calculating the bit offset. */
851 if (BYTES_BIG_ENDIAN && bytes < UNITS_PER_WORD)
852 big_endian_correction = (BITS_PER_WORD - (bytes * BITS_PER_UNIT));
854 for (j = 0; j < args[i].n_aligned_regs; j++)
856 rtx reg = gen_reg_rtx (word_mode);
857 rtx word = operand_subword_force (args[i].value, j, BLKmode);
858 int bitsize = MIN (bytes * BITS_PER_UNIT, BITS_PER_WORD);
859 int bitalign = TYPE_ALIGN (TREE_TYPE (args[i].tree_value));
861 args[i].aligned_regs[j] = reg;
863 /* There is no need to restrict this code to loading items
864 in TYPE_ALIGN sized hunks. The bitfield instructions can
865 load up entire word sized registers efficiently.
867 ??? This may not be needed anymore.
868 We use to emit a clobber here but that doesn't let later
869 passes optimize the instructions we emit. By storing 0 into
870 the register later passes know the first AND to zero out the
871 bitfield being set in the register is unnecessary. The store
872 of 0 will be deleted as will at least the first AND. */
874 emit_move_insn (reg, const0_rtx);
876 bytes -= bitsize / BITS_PER_UNIT;
877 store_bit_field (reg, bitsize, big_endian_correction, word_mode,
878 extract_bit_field (word, bitsize, 0, 1,
881 bitalign / BITS_PER_UNIT,
883 bitalign / BITS_PER_UNIT, BITS_PER_WORD);
888 /* Fill in ARGS_SIZE and ARGS array based on the parameters found in
891 NUM_ACTUALS is the total number of parameters.
893 N_NAMED_ARGS is the total number of named arguments.
895 FNDECL is the tree code for the target of this call (if known)
897 ARGS_SO_FAR holds state needed by the target to know where to place
900 REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
901 for arguments which are passed in registers.
903 OLD_STACK_LEVEL is a pointer to an rtx which olds the old stack level
904 and may be modified by this routine.
906 OLD_PENDING_ADJ, MUST_PREALLOCATE and IS_CONST are pointers to integer
907 flags which may may be modified by this routine. */
910 initialize_argument_information (num_actuals, args, args_size, n_named_args,
911 actparms, fndecl, args_so_far,
912 reg_parm_stack_space, old_stack_level,
913 old_pending_adj, must_preallocate, is_const)
914 int num_actuals ATTRIBUTE_UNUSED;
915 struct arg_data *args;
916 struct args_size *args_size;
917 int n_named_args ATTRIBUTE_UNUSED;
920 CUMULATIVE_ARGS *args_so_far;
921 int reg_parm_stack_space;
922 rtx *old_stack_level;
923 int *old_pending_adj;
924 int *must_preallocate;
927 /* 1 if scanning parms front to back, -1 if scanning back to front. */
930 /* Count arg position in order args appear. */
933 struct args_size alignment_pad;
937 args_size->constant = 0;
940 /* In this loop, we consider args in the order they are written.
941 We fill up ARGS from the front or from the back if necessary
942 so that in any case the first arg to be pushed ends up at the front. */
944 #ifdef PUSH_ARGS_REVERSED
945 i = num_actuals - 1, inc = -1;
946 /* In this case, must reverse order of args
947 so that we compute and push the last arg first. */
952 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
953 for (p = actparms, argpos = 0; p; p = TREE_CHAIN (p), i += inc, argpos++)
955 tree type = TREE_TYPE (TREE_VALUE (p));
957 enum machine_mode mode;
959 args[i].tree_value = TREE_VALUE (p);
961 /* Replace erroneous argument with constant zero. */
962 if (type == error_mark_node || TYPE_SIZE (type) == 0)
963 args[i].tree_value = integer_zero_node, type = integer_type_node;
965 /* If TYPE is a transparent union, pass things the way we would
966 pass the first field of the union. We have already verified that
967 the modes are the same. */
968 if (TYPE_TRANSPARENT_UNION (type))
969 type = TREE_TYPE (TYPE_FIELDS (type));
971 /* Decide where to pass this arg.
973 args[i].reg is nonzero if all or part is passed in registers.
975 args[i].partial is nonzero if part but not all is passed in registers,
976 and the exact value says how many words are passed in registers.
978 args[i].pass_on_stack is nonzero if the argument must at least be
979 computed on the stack. It may then be loaded back into registers
980 if args[i].reg is nonzero.
982 These decisions are driven by the FUNCTION_... macros and must agree
983 with those made by function.c. */
985 /* See if this argument should be passed by invisible reference. */
986 if ((TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
987 && contains_placeholder_p (TYPE_SIZE (type)))
988 || TREE_ADDRESSABLE (type)
989 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
990 || FUNCTION_ARG_PASS_BY_REFERENCE (*args_so_far, TYPE_MODE (type),
991 type, argpos < n_named_args)
995 /* If we're compiling a thunk, pass through invisible
996 references instead of making a copy. */
997 if (current_function_is_thunk
998 #ifdef FUNCTION_ARG_CALLEE_COPIES
999 || (FUNCTION_ARG_CALLEE_COPIES (*args_so_far, TYPE_MODE (type),
1000 type, argpos < n_named_args)
1001 /* If it's in a register, we must make a copy of it too. */
1002 /* ??? Is this a sufficient test? Is there a better one? */
1003 && !(TREE_CODE (args[i].tree_value) == VAR_DECL
1004 && REG_P (DECL_RTL (args[i].tree_value)))
1005 && ! TREE_ADDRESSABLE (type))
1009 /* C++ uses a TARGET_EXPR to indicate that we want to make a
1010 new object from the argument. If we are passing by
1011 invisible reference, the callee will do that for us, so we
1012 can strip off the TARGET_EXPR. This is not always safe,
1013 but it is safe in the only case where this is a useful
1014 optimization; namely, when the argument is a plain object.
1015 In that case, the frontend is just asking the backend to
1016 make a bitwise copy of the argument. */
1018 if (TREE_CODE (args[i].tree_value) == TARGET_EXPR
1019 && (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND
1020 (args[i].tree_value, 1)))
1022 && ! REG_P (DECL_RTL (TREE_OPERAND (args[i].tree_value, 1))))
1023 args[i].tree_value = TREE_OPERAND (args[i].tree_value, 1);
1025 args[i].tree_value = build1 (ADDR_EXPR,
1026 build_pointer_type (type),
1027 args[i].tree_value);
1028 type = build_pointer_type (type);
1032 /* We make a copy of the object and pass the address to the
1033 function being called. */
1036 if (TYPE_SIZE (type) == 0
1037 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
1038 || (flag_stack_check && ! STACK_CHECK_BUILTIN
1039 && (TREE_INT_CST_HIGH (TYPE_SIZE (type)) != 0
1040 || (TREE_INT_CST_LOW (TYPE_SIZE (type))
1041 > STACK_CHECK_MAX_VAR_SIZE * BITS_PER_UNIT))))
1043 /* This is a variable-sized object. Make space on the stack
1045 rtx size_rtx = expr_size (TREE_VALUE (p));
1047 if (*old_stack_level == 0)
1049 emit_stack_save (SAVE_BLOCK, old_stack_level, NULL_RTX);
1050 *old_pending_adj = pending_stack_adjust;
1051 pending_stack_adjust = 0;
1054 copy = gen_rtx_MEM (BLKmode,
1055 allocate_dynamic_stack_space (size_rtx,
1057 TYPE_ALIGN (type)));
1061 int size = int_size_in_bytes (type);
1062 copy = assign_stack_temp (TYPE_MODE (type), size, 0);
1065 MEM_SET_IN_STRUCT_P (copy, AGGREGATE_TYPE_P (type));
1067 store_expr (args[i].tree_value, copy, 0);
1070 args[i].tree_value = build1 (ADDR_EXPR,
1071 build_pointer_type (type),
1072 make_tree (type, copy));
1073 type = build_pointer_type (type);
1077 mode = TYPE_MODE (type);
1078 unsignedp = TREE_UNSIGNED (type);
1080 #ifdef PROMOTE_FUNCTION_ARGS
1081 mode = promote_mode (type, mode, &unsignedp, 1);
1084 args[i].unsignedp = unsignedp;
1085 args[i].mode = mode;
1086 args[i].reg = FUNCTION_ARG (*args_so_far, mode, type,
1087 argpos < n_named_args);
1088 #ifdef FUNCTION_ARG_PARTIAL_NREGS
1091 = FUNCTION_ARG_PARTIAL_NREGS (*args_so_far, mode, type,
1092 argpos < n_named_args);
1095 args[i].pass_on_stack = MUST_PASS_IN_STACK (mode, type);
1097 /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1098 it means that we are to pass this arg in the register(s) designated
1099 by the PARALLEL, but also to pass it in the stack. */
1100 if (args[i].reg && GET_CODE (args[i].reg) == PARALLEL
1101 && XEXP (XVECEXP (args[i].reg, 0, 0), 0) == 0)
1102 args[i].pass_on_stack = 1;
1104 /* If this is an addressable type, we must preallocate the stack
1105 since we must evaluate the object into its final location.
1107 If this is to be passed in both registers and the stack, it is simpler
1109 if (TREE_ADDRESSABLE (type)
1110 || (args[i].pass_on_stack && args[i].reg != 0))
1111 *must_preallocate = 1;
1113 /* If this is an addressable type, we cannot pre-evaluate it. Thus,
1114 we cannot consider this function call constant. */
1115 if (TREE_ADDRESSABLE (type))
1118 /* Compute the stack-size of this argument. */
1119 if (args[i].reg == 0 || args[i].partial != 0
1120 || reg_parm_stack_space > 0
1121 || args[i].pass_on_stack)
1122 locate_and_pad_parm (mode, type,
1123 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1128 fndecl, args_size, &args[i].offset,
1129 &args[i].size, &alignment_pad);
1131 #ifndef ARGS_GROW_DOWNWARD
1132 args[i].slot_offset = *args_size;
1135 args[i].alignment_pad = alignment_pad;
1137 /* If a part of the arg was put into registers,
1138 don't include that part in the amount pushed. */
1139 if (reg_parm_stack_space == 0 && ! args[i].pass_on_stack)
1140 args[i].size.constant -= ((args[i].partial * UNITS_PER_WORD)
1141 / (PARM_BOUNDARY / BITS_PER_UNIT)
1142 * (PARM_BOUNDARY / BITS_PER_UNIT));
1144 /* Update ARGS_SIZE, the total stack space for args so far. */
1146 args_size->constant += args[i].size.constant;
1147 if (args[i].size.var)
1149 ADD_PARM_SIZE (*args_size, args[i].size.var);
1152 /* Since the slot offset points to the bottom of the slot,
1153 we must record it after incrementing if the args grow down. */
1154 #ifdef ARGS_GROW_DOWNWARD
1155 args[i].slot_offset = *args_size;
1157 args[i].slot_offset.constant = -args_size->constant;
1160 SUB_PARM_SIZE (args[i].slot_offset, args_size->var);
1164 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1165 have been used, etc. */
1167 FUNCTION_ARG_ADVANCE (*args_so_far, TYPE_MODE (type), type,
1168 argpos < n_named_args);
1172 /* Update ARGS_SIZE to contain the total size for the argument block.
1173 Return the original constant component of the argument block's size.
1175 REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
1176 for arguments passed in registers. */
1179 compute_argument_block_size (reg_parm_stack_space, args_size)
1180 int reg_parm_stack_space;
1181 struct args_size *args_size;
1183 int unadjusted_args_size = args_size->constant;
1185 /* Compute the actual size of the argument block required. The variable
1186 and constant sizes must be combined, the size may have to be rounded,
1187 and there may be a minimum required size. */
1191 args_size->var = ARGS_SIZE_TREE (*args_size);
1192 args_size->constant = 0;
1194 #ifdef PREFERRED_STACK_BOUNDARY
1195 if (PREFERRED_STACK_BOUNDARY != BITS_PER_UNIT)
1196 args_size->var = round_up (args_size->var, STACK_BYTES);
1199 if (reg_parm_stack_space > 0)
1202 = size_binop (MAX_EXPR, args_size->var,
1203 size_int (reg_parm_stack_space));
1205 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1206 /* The area corresponding to register parameters is not to count in
1207 the size of the block we need. So make the adjustment. */
1209 = size_binop (MINUS_EXPR, args_size->var,
1210 size_int (reg_parm_stack_space));
1216 #ifdef PREFERRED_STACK_BOUNDARY
1217 args_size->constant = (((args_size->constant
1218 + pending_stack_adjust
1220 / STACK_BYTES * STACK_BYTES)
1221 - pending_stack_adjust);
1224 args_size->constant = MAX (args_size->constant,
1225 reg_parm_stack_space);
1227 #ifdef MAYBE_REG_PARM_STACK_SPACE
1228 if (reg_parm_stack_space == 0)
1229 args_size->constant = 0;
1232 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1233 args_size->constant -= reg_parm_stack_space;
1236 return unadjusted_args_size;
1239 /* Precompute parameters as needed for a function call.
1241 IS_CONST indicates the target function is a pure function.
1243 MUST_PREALLOCATE indicates that we must preallocate stack space for
1244 any stack arguments.
1246 NUM_ACTUALS is the number of arguments.
1248 ARGS is an array containing information for each argument; this routine
1249 fills in the INITIAL_VALUE and VALUE fields for each precomputed argument.
1251 ARGS_SIZE contains information about the size of the arg list. */
1254 precompute_arguments (is_const, must_preallocate, num_actuals, args, args_size)
1256 int must_preallocate;
1258 struct arg_data *args;
1259 struct args_size *args_size;
1263 /* If this function call is cse'able, precompute all the parameters.
1264 Note that if the parameter is constructed into a temporary, this will
1265 cause an additional copy because the parameter will be constructed
1266 into a temporary location and then copied into the outgoing arguments.
1267 If a parameter contains a call to alloca and this function uses the
1268 stack, precompute the parameter. */
1270 /* If we preallocated the stack space, and some arguments must be passed
1271 on the stack, then we must precompute any parameter which contains a
1272 function call which will store arguments on the stack.
1273 Otherwise, evaluating the parameter may clobber previous parameters
1274 which have already been stored into the stack. */
1276 for (i = 0; i < num_actuals; i++)
1278 || ((args_size->var != 0 || args_size->constant != 0)
1279 && calls_function (args[i].tree_value, 1))
1280 || (must_preallocate
1281 && (args_size->var != 0 || args_size->constant != 0)
1282 && calls_function (args[i].tree_value, 0)))
1284 /* If this is an addressable type, we cannot pre-evaluate it. */
1285 if (TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value)))
1291 = expand_expr (args[i].tree_value, NULL_RTX, VOIDmode, 0);
1293 preserve_temp_slots (args[i].value);
1296 /* ANSI doesn't require a sequence point here,
1297 but PCC has one, so this will avoid some problems. */
1300 args[i].initial_value = args[i].value
1301 = protect_from_queue (args[i].value, 0);
1303 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) != args[i].mode)
1306 = convert_modes (args[i].mode,
1307 TYPE_MODE (TREE_TYPE (args[i].tree_value)),
1308 args[i].value, args[i].unsignedp);
1309 #ifdef PROMOTE_FOR_CALL_ONLY
1310 /* CSE will replace this only if it contains args[i].value
1311 pseudo, so convert it down to the declared mode using
1313 if (GET_CODE (args[i].value) == REG
1314 && GET_MODE_CLASS (args[i].mode) == MODE_INT)
1316 args[i].initial_value
1317 = gen_rtx_SUBREG (TYPE_MODE (TREE_TYPE (args[i].tree_value)),
1319 SUBREG_PROMOTED_VAR_P (args[i].initial_value) = 1;
1320 SUBREG_PROMOTED_UNSIGNED_P (args[i].initial_value)
1321 = args[i].unsignedp;
1328 /* Given the current state of MUST_PREALLOCATE and information about
1329 arguments to a function call in NUM_ACTUALS, ARGS and ARGS_SIZE,
1330 compute and return the final value for MUST_PREALLOCATE. */
1333 finalize_must_preallocate (must_preallocate, num_actuals, args, args_size)
1334 int must_preallocate;
1336 struct arg_data *args;
1337 struct args_size *args_size;
1339 /* See if we have or want to preallocate stack space.
1341 If we would have to push a partially-in-regs parm
1342 before other stack parms, preallocate stack space instead.
1344 If the size of some parm is not a multiple of the required stack
1345 alignment, we must preallocate.
1347 If the total size of arguments that would otherwise create a copy in
1348 a temporary (such as a CALL) is more than half the total argument list
1349 size, preallocation is faster.
1351 Another reason to preallocate is if we have a machine (like the m88k)
1352 where stack alignment is required to be maintained between every
1353 pair of insns, not just when the call is made. However, we assume here
1354 that such machines either do not have push insns (and hence preallocation
1355 would occur anyway) or the problem is taken care of with
1358 if (! must_preallocate)
1360 int partial_seen = 0;
1361 int copy_to_evaluate_size = 0;
1364 for (i = 0; i < num_actuals && ! must_preallocate; i++)
1366 if (args[i].partial > 0 && ! args[i].pass_on_stack)
1368 else if (partial_seen && args[i].reg == 0)
1369 must_preallocate = 1;
1371 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1372 && (TREE_CODE (args[i].tree_value) == CALL_EXPR
1373 || TREE_CODE (args[i].tree_value) == TARGET_EXPR
1374 || TREE_CODE (args[i].tree_value) == COND_EXPR
1375 || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
1376 copy_to_evaluate_size
1377 += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1380 if (copy_to_evaluate_size * 2 >= args_size->constant
1381 && args_size->constant > 0)
1382 must_preallocate = 1;
1384 return must_preallocate;
1387 /* If we preallocated stack space, compute the address of each argument
1388 and store it into the ARGS array.
1390 We need not ensure it is a valid memory address here; it will be
1391 validized when it is used.
1393 ARGBLOCK is an rtx for the address of the outgoing arguments. */
1396 compute_argument_addresses (args, argblock, num_actuals)
1397 struct arg_data *args;
1403 rtx arg_reg = argblock;
1404 int i, arg_offset = 0;
1406 if (GET_CODE (argblock) == PLUS)
1407 arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
1409 for (i = 0; i < num_actuals; i++)
1411 rtx offset = ARGS_SIZE_RTX (args[i].offset);
1412 rtx slot_offset = ARGS_SIZE_RTX (args[i].slot_offset);
1415 /* Skip this parm if it will not be passed on the stack. */
1416 if (! args[i].pass_on_stack && args[i].reg != 0)
1419 if (GET_CODE (offset) == CONST_INT)
1420 addr = plus_constant (arg_reg, INTVAL (offset));
1422 addr = gen_rtx_PLUS (Pmode, arg_reg, offset);
1424 addr = plus_constant (addr, arg_offset);
1425 args[i].stack = gen_rtx_MEM (args[i].mode, addr);
1428 AGGREGATE_TYPE_P (TREE_TYPE (args[i].tree_value)));
1430 if (GET_CODE (slot_offset) == CONST_INT)
1431 addr = plus_constant (arg_reg, INTVAL (slot_offset));
1433 addr = gen_rtx_PLUS (Pmode, arg_reg, slot_offset);
1435 addr = plus_constant (addr, arg_offset);
1436 args[i].stack_slot = gen_rtx_MEM (args[i].mode, addr);
1441 /* Given a FNDECL and EXP, return an rtx suitable for use as a target address
1442 in a call instruction.
1444 FNDECL is the tree node for the target function. For an indirect call
1445 FNDECL will be NULL_TREE.
1447 EXP is the CALL_EXPR for this call. */
1450 rtx_for_function_call (fndecl, exp)
1456 /* Get the function to call, in the form of RTL. */
1459 /* If this is the first use of the function, see if we need to
1460 make an external definition for it. */
1461 if (! TREE_USED (fndecl))
1463 assemble_external (fndecl);
1464 TREE_USED (fndecl) = 1;
1467 /* Get a SYMBOL_REF rtx for the function address. */
1468 funexp = XEXP (DECL_RTL (fndecl), 0);
1471 /* Generate an rtx (probably a pseudo-register) for the address. */
1476 expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
1477 pop_temp_slots (); /* FUNEXP can't be BLKmode */
1479 /* Check the function is executable. */
1480 if (current_function_check_memory_usage)
1482 #ifdef POINTERS_EXTEND_UNSIGNED
1483 /* It might be OK to convert funexp in place, but there's
1484 a lot going on between here and when it happens naturally
1485 that this seems safer. */
1486 funaddr = convert_memory_address (Pmode, funexp);
1488 emit_library_call (chkr_check_exec_libfunc, 1,
1497 /* Do the register loads required for any wholly-register parms or any
1498 parms which are passed both on the stack and in a register. Their
1499 expressions were already evaluated.
1501 Mark all register-parms as living through the call, putting these USE
1502 insns in the CALL_INSN_FUNCTION_USAGE field. */
1505 load_register_parameters (args, num_actuals, call_fusage)
1506 struct arg_data *args;
1512 #ifdef LOAD_ARGS_REVERSED
1513 for (i = num_actuals - 1; i >= 0; i--)
1515 for (i = 0; i < num_actuals; i++)
1518 rtx reg = args[i].reg;
1519 int partial = args[i].partial;
1524 /* Set to non-negative if must move a word at a time, even if just
1525 one word (e.g, partial == 1 && mode == DFmode). Set to -1 if
1526 we just use a normal move insn. This value can be zero if the
1527 argument is a zero size structure with no fields. */
1528 nregs = (partial ? partial
1529 : (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1530 ? ((int_size_in_bytes (TREE_TYPE (args[i].tree_value))
1531 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
1534 /* Handle calls that pass values in multiple non-contiguous
1535 locations. The Irix 6 ABI has examples of this. */
1537 if (GET_CODE (reg) == PARALLEL)
1539 emit_group_load (reg, args[i].value,
1540 int_size_in_bytes (TREE_TYPE (args[i].tree_value)),
1541 (TYPE_ALIGN (TREE_TYPE (args[i].tree_value))
1545 /* If simple case, just do move. If normal partial, store_one_arg
1546 has already loaded the register for us. In all other cases,
1547 load the register(s) from memory. */
1549 else if (nregs == -1)
1550 emit_move_insn (reg, args[i].value);
1552 /* If we have pre-computed the values to put in the registers in
1553 the case of non-aligned structures, copy them in now. */
1555 else if (args[i].n_aligned_regs != 0)
1556 for (j = 0; j < args[i].n_aligned_regs; j++)
1557 emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg) + j),
1558 args[i].aligned_regs[j]);
1560 else if (partial == 0 || args[i].pass_on_stack)
1561 move_block_to_reg (REGNO (reg),
1562 validize_mem (args[i].value), nregs,
1565 /* Handle calls that pass values in multiple non-contiguous
1566 locations. The Irix 6 ABI has examples of this. */
1567 if (GET_CODE (reg) == PARALLEL)
1568 use_group_regs (call_fusage, reg);
1569 else if (nregs == -1)
1570 use_reg (call_fusage, reg);
1572 use_regs (call_fusage, REGNO (reg), nregs == 0 ? 1 : nregs);
1577 /* Generate all the code for a function call
1578 and return an rtx for its value.
1579 Store the value in TARGET (specified as an rtx) if convenient.
1580 If the value is stored in TARGET then TARGET is returned.
1581 If IGNORE is nonzero, then we ignore the value of the function call. */
1584 expand_call (exp, target, ignore)
1589 /* List of actual parameters. */
1590 tree actparms = TREE_OPERAND (exp, 1);
1591 /* RTX for the function to be called. */
1593 /* Data type of the function. */
1595 /* Declaration of the function being called,
1596 or 0 if the function is computed (not known by name). */
1600 /* Register in which non-BLKmode value will be returned,
1601 or 0 if no value or if value is BLKmode. */
1603 /* Address where we should return a BLKmode value;
1604 0 if value not BLKmode. */
1605 rtx structure_value_addr = 0;
1606 /* Nonzero if that address is being passed by treating it as
1607 an extra, implicit first parameter. Otherwise,
1608 it is passed by being copied directly into struct_value_rtx. */
1609 int structure_value_addr_parm = 0;
1610 /* Size of aggregate value wanted, or zero if none wanted
1611 or if we are using the non-reentrant PCC calling convention
1612 or expecting the value in registers. */
1613 HOST_WIDE_INT struct_value_size = 0;
1614 /* Nonzero if called function returns an aggregate in memory PCC style,
1615 by returning the address of where to find it. */
1616 int pcc_struct_value = 0;
1618 /* Number of actual parameters in this call, including struct value addr. */
1620 /* Number of named args. Args after this are anonymous ones
1621 and they must all go on the stack. */
1624 /* Vector of information about each argument.
1625 Arguments are numbered in the order they will be pushed,
1626 not the order they are written. */
1627 struct arg_data *args;
1629 /* Total size in bytes of all the stack-parms scanned so far. */
1630 struct args_size args_size;
1631 /* Size of arguments before any adjustments (such as rounding). */
1632 int unadjusted_args_size;
1633 /* Data on reg parms scanned so far. */
1634 CUMULATIVE_ARGS args_so_far;
1635 /* Nonzero if a reg parm has been scanned. */
1637 /* Nonzero if this is an indirect function call. */
1639 /* Nonzero if we must avoid push-insns in the args for this call.
1640 If stack space is allocated for register parameters, but not by the
1641 caller, then it is preallocated in the fixed part of the stack frame.
1642 So the entire argument block must then be preallocated (i.e., we
1643 ignore PUSH_ROUNDING in that case). */
1645 #ifdef PUSH_ROUNDING
1646 int must_preallocate = 0;
1648 int must_preallocate = 1;
1651 /* Size of the stack reserved for parameter registers. */
1652 int reg_parm_stack_space = 0;
1654 /* Address of space preallocated for stack parms
1655 (on machines that lack push insns), or 0 if space not preallocated. */
1658 /* Nonzero if it is plausible that this is a call to alloca. */
1660 /* Nonzero if this is a call to malloc or a related function. */
1662 /* Nonzero if this is a call to setjmp or a related function. */
1664 /* Nonzero if this is a call to `longjmp'. */
1666 /* Nonzero if this is a syscall that makes a new process in the image of
1669 /* Nonzero if this is a call to an inline function. */
1670 int is_integrable = 0;
1671 /* Nonzero if this is a call to a `const' function.
1672 Note that only explicitly named functions are handled as `const' here. */
1674 /* Nonzero if this is a call to a `volatile' function. */
1675 int is_volatile = 0;
1676 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
1677 /* Define the boundary of the register parm stack space that needs to be
1679 int low_to_save = -1, high_to_save;
1680 rtx save_area = 0; /* Place that it is saved */
1683 #ifdef ACCUMULATE_OUTGOING_ARGS
1684 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
1685 char *initial_stack_usage_map = stack_usage_map;
1686 int old_stack_arg_under_construction = 0;
1689 rtx old_stack_level = 0;
1690 int old_pending_adj = 0;
1691 int old_inhibit_defer_pop = inhibit_defer_pop;
1692 rtx call_fusage = 0;
1696 /* The value of the function call can be put in a hard register. But
1697 if -fcheck-memory-usage, code which invokes functions (and thus
1698 damages some hard registers) can be inserted before using the value.
1699 So, target is always a pseudo-register in that case. */
1700 if (current_function_check_memory_usage)
1703 /* See if we can find a DECL-node for the actual function.
1704 As a result, decide whether this is a call to an integrable function. */
1706 p = TREE_OPERAND (exp, 0);
1707 if (TREE_CODE (p) == ADDR_EXPR)
1709 fndecl = TREE_OPERAND (p, 0);
1710 if (TREE_CODE (fndecl) != FUNCTION_DECL)
1715 && fndecl != current_function_decl
1716 && DECL_INLINE (fndecl)
1717 && DECL_SAVED_INSNS (fndecl)
1718 && DECL_SAVED_INSNS (fndecl)->inlinable)
1720 else if (! TREE_ADDRESSABLE (fndecl))
1722 /* In case this function later becomes inlinable,
1723 record that there was already a non-inline call to it.
1725 Use abstraction instead of setting TREE_ADDRESSABLE
1727 if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
1730 warning_with_decl (fndecl, "can't inline call to `%s'");
1731 warning ("called from here");
1733 mark_addressable (fndecl);
1736 if (TREE_READONLY (fndecl) && ! TREE_THIS_VOLATILE (fndecl)
1737 && TYPE_MODE (TREE_TYPE (exp)) != VOIDmode)
1740 if (TREE_THIS_VOLATILE (fndecl))
1745 /* If we don't have specific function to call, see if we have a
1746 constant or `noreturn' function from the type. */
1749 is_const = TREE_READONLY (TREE_TYPE (TREE_TYPE (p)));
1750 is_volatile = TREE_THIS_VOLATILE (TREE_TYPE (TREE_TYPE (p)));
1753 #ifdef REG_PARM_STACK_SPACE
1754 #ifdef MAYBE_REG_PARM_STACK_SPACE
1755 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
1757 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
1761 #if defined(PUSH_ROUNDING) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
1762 if (reg_parm_stack_space > 0)
1763 must_preallocate = 1;
1766 /* Warn if this value is an aggregate type,
1767 regardless of which calling convention we are using for it. */
1768 if (warn_aggregate_return && AGGREGATE_TYPE_P (TREE_TYPE (exp)))
1769 warning ("function call has aggregate value");
1771 /* Set up a place to return a structure. */
1773 /* Cater to broken compilers. */
1774 if (aggregate_value_p (exp))
1776 /* This call returns a big structure. */
1779 #ifdef PCC_STATIC_STRUCT_RETURN
1781 pcc_struct_value = 1;
1782 /* Easier than making that case work right. */
1785 /* In case this is a static function, note that it has been
1787 if (! TREE_ADDRESSABLE (fndecl))
1788 mark_addressable (fndecl);
1792 #else /* not PCC_STATIC_STRUCT_RETURN */
1794 struct_value_size = int_size_in_bytes (TREE_TYPE (exp));
1796 if (target && GET_CODE (target) == MEM)
1797 structure_value_addr = XEXP (target, 0);
1800 /* Assign a temporary to hold the value. */
1803 /* For variable-sized objects, we must be called with a target
1804 specified. If we were to allocate space on the stack here,
1805 we would have no way of knowing when to free it. */
1807 if (struct_value_size < 0)
1810 /* This DECL is just something to feed to mark_addressable;
1811 it doesn't get pushed. */
1812 d = build_decl (VAR_DECL, NULL_TREE, TREE_TYPE (exp));
1813 DECL_RTL (d) = assign_temp (TREE_TYPE (exp), 1, 0, 1);
1814 mark_addressable (d);
1815 mark_temp_addr_taken (DECL_RTL (d));
1816 structure_value_addr = XEXP (DECL_RTL (d), 0);
1821 #endif /* not PCC_STATIC_STRUCT_RETURN */
1824 /* If called function is inline, try to integrate it. */
1829 #ifdef ACCUMULATE_OUTGOING_ARGS
1830 rtx before_call = get_last_insn ();
1833 temp = expand_inline_function (fndecl, actparms, target,
1834 ignore, TREE_TYPE (exp),
1835 structure_value_addr);
1837 /* If inlining succeeded, return. */
1838 if (temp != (rtx) (HOST_WIDE_INT) -1)
1840 #ifdef ACCUMULATE_OUTGOING_ARGS
1841 /* If the outgoing argument list must be preserved, push
1842 the stack before executing the inlined function if it
1845 for (i = reg_parm_stack_space - 1; i >= 0; i--)
1846 if (i < highest_outgoing_arg_in_use && stack_usage_map[i] != 0)
1849 if (stack_arg_under_construction || i >= 0)
1852 = before_call ? NEXT_INSN (before_call) : get_insns ();
1853 rtx insn = NULL_RTX, seq;
1855 /* Look for a call in the inline function code.
1856 If DECL_SAVED_INSNS (fndecl)->outgoing_args_size is
1857 nonzero then there is a call and it is not necessary
1858 to scan the insns. */
1860 if (DECL_SAVED_INSNS (fndecl)->outgoing_args_size == 0)
1861 for (insn = first_insn; insn; insn = NEXT_INSN (insn))
1862 if (GET_CODE (insn) == CALL_INSN)
1867 /* Reserve enough stack space so that the largest
1868 argument list of any function call in the inline
1869 function does not overlap the argument list being
1870 evaluated. This is usually an overestimate because
1871 allocate_dynamic_stack_space reserves space for an
1872 outgoing argument list in addition to the requested
1873 space, but there is no way to ask for stack space such
1874 that an argument list of a certain length can be
1877 Add the stack space reserved for register arguments, if
1878 any, in the inline function. What is really needed is the
1879 largest value of reg_parm_stack_space in the inline
1880 function, but that is not available. Using the current
1881 value of reg_parm_stack_space is wrong, but gives
1882 correct results on all supported machines. */
1884 int adjust = (DECL_SAVED_INSNS (fndecl)->outgoing_args_size
1885 + reg_parm_stack_space);
1888 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1889 allocate_dynamic_stack_space (GEN_INT (adjust),
1890 NULL_RTX, BITS_PER_UNIT);
1893 emit_insns_before (seq, first_insn);
1894 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
1899 /* If the result is equivalent to TARGET, return TARGET to simplify
1900 checks in store_expr. They can be equivalent but not equal in the
1901 case of a function that returns BLKmode. */
1902 if (temp != target && rtx_equal_p (temp, target))
1907 /* If inlining failed, mark FNDECL as needing to be compiled
1908 separately after all. If function was declared inline,
1910 if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
1911 && optimize > 0 && ! TREE_ADDRESSABLE (fndecl))
1913 warning_with_decl (fndecl, "inlining failed in call to `%s'");
1914 warning ("called from here");
1916 mark_addressable (fndecl);
1919 function_call_count++;
1921 if (fndecl && DECL_NAME (fndecl))
1922 name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
1924 /* See if this is a call to a function that can return more than once
1925 or a call to longjmp or malloc. */
1926 special_function_p (fndecl, &returns_twice, &is_longjmp, &fork_or_exec,
1927 &is_malloc, &may_be_alloca);
1930 current_function_calls_alloca = 1;
1932 /* Operand 0 is a pointer-to-function; get the type of the function. */
1933 funtype = TREE_TYPE (TREE_OPERAND (exp, 0));
1934 if (! POINTER_TYPE_P (funtype))
1936 funtype = TREE_TYPE (funtype);
1938 /* When calling a const function, we must pop the stack args right away,
1939 so that the pop is deleted or moved with the call. */
1943 /* Don't let pending stack adjusts add up to too much.
1944 Also, do all pending adjustments now
1945 if there is any chance this might be a call to alloca. */
1947 if (pending_stack_adjust >= 32
1948 || (pending_stack_adjust > 0 && may_be_alloca))
1949 do_pending_stack_adjust ();
1951 if (profile_arc_flag && fork_or_exec)
1953 /* A fork duplicates the profile information, and an exec discards
1954 it. We can't rely on fork/exec to be paired. So write out the
1955 profile information we have gathered so far, and clear it. */
1956 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__bb_fork_func"), 0,
1959 /* ??? When __clone is called with CLONE_VM set, profiling is
1960 subject to race conditions, just as with multithreaded programs. */
1963 /* Push the temporary stack slot level so that we can free any temporaries
1967 /* Start updating where the next arg would go.
1969 On some machines (such as the PA) indirect calls have a different
1970 calling convention than normal calls. The last argument in
1971 INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
1973 INIT_CUMULATIVE_ARGS (args_so_far, funtype, NULL_RTX, (fndecl == 0));
1975 /* If struct_value_rtx is 0, it means pass the address
1976 as if it were an extra parameter. */
1977 if (structure_value_addr && struct_value_rtx == 0)
1979 /* If structure_value_addr is a REG other than
1980 virtual_outgoing_args_rtx, we can use always use it. If it
1981 is not a REG, we must always copy it into a register.
1982 If it is virtual_outgoing_args_rtx, we must copy it to another
1983 register in some cases. */
1984 rtx temp = (GET_CODE (structure_value_addr) != REG
1985 #ifdef ACCUMULATE_OUTGOING_ARGS
1986 || (stack_arg_under_construction
1987 && structure_value_addr == virtual_outgoing_args_rtx)
1989 ? copy_addr_to_reg (structure_value_addr)
1990 : structure_value_addr);
1993 = tree_cons (error_mark_node,
1994 make_tree (build_pointer_type (TREE_TYPE (funtype)),
1997 structure_value_addr_parm = 1;
2000 /* Count the arguments and set NUM_ACTUALS. */
2001 for (p = actparms, i = 0; p; p = TREE_CHAIN (p)) i++;
2004 /* Compute number of named args.
2005 Normally, don't include the last named arg if anonymous args follow.
2006 We do include the last named arg if STRICT_ARGUMENT_NAMING is nonzero.
2007 (If no anonymous args follow, the result of list_length is actually
2008 one too large. This is harmless.)
2010 If PRETEND_OUTGOING_VARARGS_NAMED is set and STRICT_ARGUMENT_NAMING is
2011 zero, this machine will be able to place unnamed args that were passed in
2012 registers into the stack. So treat all args as named. This allows the
2013 insns emitting for a specific argument list to be independent of the
2014 function declaration.
2016 If PRETEND_OUTGOING_VARARGS_NAMED is not set, we do not have any reliable
2017 way to pass unnamed args in registers, so we must force them into
2020 if ((STRICT_ARGUMENT_NAMING
2021 || ! PRETEND_OUTGOING_VARARGS_NAMED)
2022 && TYPE_ARG_TYPES (funtype) != 0)
2024 = (list_length (TYPE_ARG_TYPES (funtype))
2025 /* Don't include the last named arg. */
2026 - (STRICT_ARGUMENT_NAMING ? 0 : 1)
2027 /* Count the struct value address, if it is passed as a parm. */
2028 + structure_value_addr_parm);
2030 /* If we know nothing, treat all args as named. */
2031 n_named_args = num_actuals;
2033 /* Make a vector to hold all the information about each arg. */
2034 args = (struct arg_data *) alloca (num_actuals * sizeof (struct arg_data));
2035 bzero ((char *) args, num_actuals * sizeof (struct arg_data));
2037 /* Build up entries inthe ARGS array, compute the size of the arguments
2038 into ARGS_SIZE, etc. */
2039 initialize_argument_information (num_actuals, args, &args_size, n_named_args,
2040 actparms, fndecl, &args_so_far,
2041 reg_parm_stack_space, &old_stack_level,
2042 &old_pending_adj, &must_preallocate,
2045 #ifdef FINAL_REG_PARM_STACK_SPACE
2046 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
2052 /* If this function requires a variable-sized argument list, don't try to
2053 make a cse'able block for this call. We may be able to do this
2054 eventually, but it is too complicated to keep track of what insns go
2055 in the cse'able block and which don't. */
2058 must_preallocate = 1;
2061 /* Compute the actual size of the argument block required. The variable
2062 and constant sizes must be combined, the size may have to be rounded,
2063 and there may be a minimum required size. */
2064 unadjusted_args_size
2065 = compute_argument_block_size (reg_parm_stack_space, &args_size);
2067 /* Now make final decision about preallocating stack space. */
2068 must_preallocate = finalize_must_preallocate (must_preallocate,
2069 num_actuals, args, &args_size);
2071 /* If the structure value address will reference the stack pointer, we must
2072 stabilize it. We don't need to do this if we know that we are not going
2073 to adjust the stack pointer in processing this call. */
2075 if (structure_value_addr
2076 && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
2077 || reg_mentioned_p (virtual_outgoing_args_rtx, structure_value_addr))
2079 #ifndef ACCUMULATE_OUTGOING_ARGS
2080 || args_size.constant
2083 structure_value_addr = copy_to_reg (structure_value_addr);
2085 /* Precompute any arguments as needed. */
2086 precompute_arguments (is_const, must_preallocate, num_actuals,
2089 /* Now we are about to start emitting insns that can be deleted
2090 if a libcall is deleted. */
2091 if (is_const || is_malloc)
2094 /* If we have no actual push instructions, or shouldn't use them,
2095 make space for all args right now. */
2097 if (args_size.var != 0)
2099 if (old_stack_level == 0)
2101 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
2102 old_pending_adj = pending_stack_adjust;
2103 pending_stack_adjust = 0;
2104 #ifdef ACCUMULATE_OUTGOING_ARGS
2105 /* stack_arg_under_construction says whether a stack arg is
2106 being constructed at the old stack level. Pushing the stack
2107 gets a clean outgoing argument block. */
2108 old_stack_arg_under_construction = stack_arg_under_construction;
2109 stack_arg_under_construction = 0;
2112 argblock = push_block (ARGS_SIZE_RTX (args_size), 0, 0);
2116 /* Note that we must go through the motions of allocating an argument
2117 block even if the size is zero because we may be storing args
2118 in the area reserved for register arguments, which may be part of
2121 int needed = args_size.constant;
2123 /* Store the maximum argument space used. It will be pushed by
2124 the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
2127 if (needed > current_function_outgoing_args_size)
2128 current_function_outgoing_args_size = needed;
2130 if (must_preallocate)
2132 #ifdef ACCUMULATE_OUTGOING_ARGS
2133 /* Since the stack pointer will never be pushed, it is possible for
2134 the evaluation of a parm to clobber something we have already
2135 written to the stack. Since most function calls on RISC machines
2136 do not use the stack, this is uncommon, but must work correctly.
2138 Therefore, we save any area of the stack that was already written
2139 and that we are using. Here we set up to do this by making a new
2140 stack usage map from the old one. The actual save will be done
2143 Another approach might be to try to reorder the argument
2144 evaluations to avoid this conflicting stack usage. */
2146 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2147 /* Since we will be writing into the entire argument area, the
2148 map must be allocated for its entire size, not just the part that
2149 is the responsibility of the caller. */
2150 needed += reg_parm_stack_space;
2153 #ifdef ARGS_GROW_DOWNWARD
2154 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2157 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2160 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
2162 if (initial_highest_arg_in_use)
2163 bcopy (initial_stack_usage_map, stack_usage_map,
2164 initial_highest_arg_in_use);
2166 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
2167 bzero (&stack_usage_map[initial_highest_arg_in_use],
2168 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
2171 /* The address of the outgoing argument list must not be copied to a
2172 register here, because argblock would be left pointing to the
2173 wrong place after the call to allocate_dynamic_stack_space below.
2176 argblock = virtual_outgoing_args_rtx;
2178 #else /* not ACCUMULATE_OUTGOING_ARGS */
2179 if (inhibit_defer_pop == 0)
2181 /* Try to reuse some or all of the pending_stack_adjust
2182 to get this space. Maybe we can avoid any pushing. */
2183 if (needed > pending_stack_adjust)
2185 needed -= pending_stack_adjust;
2186 pending_stack_adjust = 0;
2190 pending_stack_adjust -= needed;
2194 /* Special case this because overhead of `push_block' in this
2195 case is non-trivial. */
2197 argblock = virtual_outgoing_args_rtx;
2199 argblock = push_block (GEN_INT (needed), 0, 0);
2201 /* We only really need to call `copy_to_reg' in the case where push
2202 insns are going to be used to pass ARGBLOCK to a function
2203 call in ARGS. In that case, the stack pointer changes value
2204 from the allocation point to the call point, and hence
2205 the value of VIRTUAL_OUTGOING_ARGS_RTX changes as well.
2206 But might as well always do it. */
2207 argblock = copy_to_reg (argblock);
2208 #endif /* not ACCUMULATE_OUTGOING_ARGS */
2212 #ifdef ACCUMULATE_OUTGOING_ARGS
2213 /* The save/restore code in store_one_arg handles all cases except one:
2214 a constructor call (including a C function returning a BLKmode struct)
2215 to initialize an argument. */
2216 if (stack_arg_under_construction)
2218 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2219 rtx push_size = GEN_INT (reg_parm_stack_space + args_size.constant);
2221 rtx push_size = GEN_INT (args_size.constant);
2223 if (old_stack_level == 0)
2225 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
2226 old_pending_adj = pending_stack_adjust;
2227 pending_stack_adjust = 0;
2228 /* stack_arg_under_construction says whether a stack arg is
2229 being constructed at the old stack level. Pushing the stack
2230 gets a clean outgoing argument block. */
2231 old_stack_arg_under_construction = stack_arg_under_construction;
2232 stack_arg_under_construction = 0;
2233 /* Make a new map for the new argument list. */
2234 stack_usage_map = (char *)alloca (highest_outgoing_arg_in_use);
2235 bzero (stack_usage_map, highest_outgoing_arg_in_use);
2236 highest_outgoing_arg_in_use = 0;
2238 allocate_dynamic_stack_space (push_size, NULL_RTX, BITS_PER_UNIT);
2240 /* If argument evaluation might modify the stack pointer, copy the
2241 address of the argument list to a register. */
2242 for (i = 0; i < num_actuals; i++)
2243 if (args[i].pass_on_stack)
2245 argblock = copy_addr_to_reg (argblock);
2250 compute_argument_addresses (args, argblock, num_actuals);
2252 #ifdef PUSH_ARGS_REVERSED
2253 #ifdef PREFERRED_STACK_BOUNDARY
2254 /* If we push args individually in reverse order, perform stack alignment
2255 before the first push (the last arg). */
2257 anti_adjust_stack (GEN_INT (args_size.constant - unadjusted_args_size));
2261 /* Don't try to defer pops if preallocating, not even from the first arg,
2262 since ARGBLOCK probably refers to the SP. */
2266 funexp = rtx_for_function_call (fndecl, exp);
2268 /* Figure out the register where the value, if any, will come back. */
2270 if (TYPE_MODE (TREE_TYPE (exp)) != VOIDmode
2271 && ! structure_value_addr)
2273 if (pcc_struct_value)
2274 valreg = hard_function_value (build_pointer_type (TREE_TYPE (exp)),
2277 valreg = hard_function_value (TREE_TYPE (exp), fndecl, 0);
2280 /* Precompute all register parameters. It isn't safe to compute anything
2281 once we have started filling any specific hard regs. */
2282 precompute_register_parameters (num_actuals, args, ®_parm_seen);
2284 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
2286 /* Save the fixed argument area if it's part of the caller's frame and
2287 is clobbered by argument setup for this call. */
2288 save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
2289 &low_to_save, &high_to_save);
2293 /* Now store (and compute if necessary) all non-register parms.
2294 These come before register parms, since they can require block-moves,
2295 which could clobber the registers used for register parms.
2296 Parms which have partial registers are not stored here,
2297 but we do preallocate space here if they want that. */
2299 for (i = 0; i < num_actuals; i++)
2300 if (args[i].reg == 0 || args[i].pass_on_stack)
2301 store_one_arg (&args[i], argblock, may_be_alloca,
2302 args_size.var != 0, reg_parm_stack_space);
2304 /* If we have a parm that is passed in registers but not in memory
2305 and whose alignment does not permit a direct copy into registers,
2306 make a group of pseudos that correspond to each register that we
2308 if (STRICT_ALIGNMENT)
2309 store_unaligned_arguments_into_pseudos (args, num_actuals);
2311 /* Now store any partially-in-registers parm.
2312 This is the last place a block-move can happen. */
2314 for (i = 0; i < num_actuals; i++)
2315 if (args[i].partial != 0 && ! args[i].pass_on_stack)
2316 store_one_arg (&args[i], argblock, may_be_alloca,
2317 args_size.var != 0, reg_parm_stack_space);
2319 #ifndef PUSH_ARGS_REVERSED
2320 #ifdef PREFERRED_STACK_BOUNDARY
2321 /* If we pushed args in forward order, perform stack alignment
2322 after pushing the last arg. */
2324 anti_adjust_stack (GEN_INT (args_size.constant - unadjusted_args_size));
2328 /* If register arguments require space on the stack and stack space
2329 was not preallocated, allocate stack space here for arguments
2330 passed in registers. */
2331 #if ! defined(ACCUMULATE_OUTGOING_ARGS) && defined(OUTGOING_REG_PARM_STACK_SPACE)
2332 if (must_preallocate == 0 && reg_parm_stack_space > 0)
2333 anti_adjust_stack (GEN_INT (reg_parm_stack_space));
2336 /* Pass the function the address in which to return a structure value. */
2337 if (structure_value_addr && ! structure_value_addr_parm)
2339 emit_move_insn (struct_value_rtx,
2341 force_operand (structure_value_addr,
2344 /* Mark the memory for the aggregate as write-only. */
2345 if (current_function_check_memory_usage)
2346 emit_library_call (chkr_set_right_libfunc, 1,
2348 structure_value_addr, Pmode,
2349 GEN_INT (struct_value_size), TYPE_MODE (sizetype),
2350 GEN_INT (MEMORY_USE_WO),
2351 TYPE_MODE (integer_type_node));
2353 if (GET_CODE (struct_value_rtx) == REG)
2354 use_reg (&call_fusage, struct_value_rtx);
2357 funexp = prepare_call_address (funexp, fndecl, &call_fusage, reg_parm_seen);
2359 load_register_parameters (args, num_actuals, &call_fusage);
2361 /* Perform postincrements before actually calling the function. */
2364 /* All arguments and registers used for the call must be set up by now! */
2366 /* Generate the actual call instruction. */
2367 emit_call_1 (funexp, fndecl, funtype, unadjusted_args_size,
2368 args_size.constant, struct_value_size,
2369 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
2370 valreg, old_inhibit_defer_pop, call_fusage, is_const);
2372 /* If call is cse'able, make appropriate pair of reg-notes around it.
2373 Test valreg so we don't crash; may safely ignore `const'
2374 if return type is void. Disable for PARALLEL return values, because
2375 we have no way to move such values into a pseudo register. */
2376 if (is_const && valreg != 0 && GET_CODE (valreg) != PARALLEL)
2379 rtx temp = gen_reg_rtx (GET_MODE (valreg));
2382 /* Mark the return value as a pointer if needed. */
2383 if (TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE)
2385 tree pointed_to = TREE_TYPE (TREE_TYPE (exp));
2386 mark_reg_pointer (temp, TYPE_ALIGN (pointed_to) / BITS_PER_UNIT);
2389 /* Construct an "equal form" for the value which mentions all the
2390 arguments in order as well as the function name. */
2391 #ifdef PUSH_ARGS_REVERSED
2392 for (i = 0; i < num_actuals; i++)
2393 note = gen_rtx_EXPR_LIST (VOIDmode, args[i].initial_value, note);
2395 for (i = num_actuals - 1; i >= 0; i--)
2396 note = gen_rtx_EXPR_LIST (VOIDmode, args[i].initial_value, note);
2398 note = gen_rtx_EXPR_LIST (VOIDmode, funexp, note);
2400 insns = get_insns ();
2403 emit_libcall_block (insns, temp, valreg, note);
2409 /* Otherwise, just write out the sequence without a note. */
2410 rtx insns = get_insns ();
2417 rtx temp = gen_reg_rtx (GET_MODE (valreg));
2420 /* The return value from a malloc-like function is a pointer. */
2421 if (TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE)
2422 mark_reg_pointer (temp, BIGGEST_ALIGNMENT / BITS_PER_UNIT);
2424 emit_move_insn (temp, valreg);
2426 /* The return value from a malloc-like function can not alias
2428 last = get_last_insn ();
2430 gen_rtx_EXPR_LIST (REG_NOALIAS, temp, REG_NOTES (last));
2432 /* Write out the sequence. */
2433 insns = get_insns ();
2439 /* For calls to `setjmp', etc., inform flow.c it should complain
2440 if nonvolatile values are live. */
2444 emit_note (name, NOTE_INSN_SETJMP);
2445 current_function_calls_setjmp = 1;
2449 current_function_calls_longjmp = 1;
2451 /* Notice functions that cannot return.
2452 If optimizing, insns emitted below will be dead.
2453 If not optimizing, they will exist, which is useful
2454 if the user uses the `return' command in the debugger. */
2456 if (is_volatile || is_longjmp)
2459 /* If value type not void, return an rtx for the value. */
2461 /* If there are cleanups to be called, don't use a hard reg as target.
2462 We need to double check this and see if it matters anymore. */
2463 if (any_pending_cleanups (1)
2464 && target && REG_P (target)
2465 && REGNO (target) < FIRST_PSEUDO_REGISTER)
2468 if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode
2471 target = const0_rtx;
2473 else if (structure_value_addr)
2475 if (target == 0 || GET_CODE (target) != MEM)
2477 target = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
2478 memory_address (TYPE_MODE (TREE_TYPE (exp)),
2479 structure_value_addr));
2480 MEM_SET_IN_STRUCT_P (target,
2481 AGGREGATE_TYPE_P (TREE_TYPE (exp)));
2484 else if (pcc_struct_value)
2486 /* This is the special C++ case where we need to
2487 know what the true target was. We take care to
2488 never use this value more than once in one expression. */
2489 target = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
2490 copy_to_reg (valreg));
2491 MEM_SET_IN_STRUCT_P (target, AGGREGATE_TYPE_P (TREE_TYPE (exp)));
2493 /* Handle calls that return values in multiple non-contiguous locations.
2494 The Irix 6 ABI has examples of this. */
2495 else if (GET_CODE (valreg) == PARALLEL)
2497 int bytes = int_size_in_bytes (TREE_TYPE (exp));
2501 target = assign_stack_temp (TYPE_MODE (TREE_TYPE (exp)), bytes, 0);
2502 MEM_SET_IN_STRUCT_P (target, AGGREGATE_TYPE_P (TREE_TYPE (exp)));
2503 preserve_temp_slots (target);
2506 if (! rtx_equal_p (target, valreg))
2507 emit_group_store (target, valreg, bytes,
2508 TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
2510 else if (target && GET_MODE (target) == TYPE_MODE (TREE_TYPE (exp))
2511 && GET_MODE (target) == GET_MODE (valreg))
2512 /* TARGET and VALREG cannot be equal at this point because the latter
2513 would not have REG_FUNCTION_VALUE_P true, while the former would if
2514 it were referring to the same register.
2516 If they refer to the same register, this move will be a no-op, except
2517 when function inlining is being done. */
2518 emit_move_insn (target, valreg);
2519 else if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
2520 target = copy_blkmode_from_reg (target, valreg, TREE_TYPE (exp));
2522 target = copy_to_reg (valreg);
2524 #ifdef PROMOTE_FUNCTION_RETURN
2525 /* If we promoted this return value, make the proper SUBREG. TARGET
2526 might be const0_rtx here, so be careful. */
2527 if (GET_CODE (target) == REG
2528 && TYPE_MODE (TREE_TYPE (exp)) != BLKmode
2529 && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
2531 tree type = TREE_TYPE (exp);
2532 int unsignedp = TREE_UNSIGNED (type);
2534 /* If we don't promote as expected, something is wrong. */
2535 if (GET_MODE (target)
2536 != promote_mode (type, TYPE_MODE (type), &unsignedp, 1))
2539 target = gen_rtx_SUBREG (TYPE_MODE (type), target, 0);
2540 SUBREG_PROMOTED_VAR_P (target) = 1;
2541 SUBREG_PROMOTED_UNSIGNED_P (target) = unsignedp;
2545 /* If size of args is variable or this was a constructor call for a stack
2546 argument, restore saved stack-pointer value. */
2548 if (old_stack_level)
2550 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
2551 pending_stack_adjust = old_pending_adj;
2552 #ifdef ACCUMULATE_OUTGOING_ARGS
2553 stack_arg_under_construction = old_stack_arg_under_construction;
2554 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2555 stack_usage_map = initial_stack_usage_map;
2558 #ifdef ACCUMULATE_OUTGOING_ARGS
2561 #ifdef REG_PARM_STACK_SPACE
2563 restore_fixed_argument_area (save_area, argblock,
2564 high_to_save, low_to_save);
2567 /* If we saved any argument areas, restore them. */
2568 for (i = 0; i < num_actuals; i++)
2569 if (args[i].save_area)
2571 enum machine_mode save_mode = GET_MODE (args[i].save_area);
2573 = gen_rtx_MEM (save_mode,
2574 memory_address (save_mode,
2575 XEXP (args[i].stack_slot, 0)));
2577 if (save_mode != BLKmode)
2578 emit_move_insn (stack_area, args[i].save_area);
2580 emit_block_move (stack_area, validize_mem (args[i].save_area),
2581 GEN_INT (args[i].size.constant),
2582 PARM_BOUNDARY / BITS_PER_UNIT);
2585 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2586 stack_usage_map = initial_stack_usage_map;
2590 /* If this was alloca, record the new stack level for nonlocal gotos.
2591 Check for the handler slots since we might not have a save area
2592 for non-local gotos. */
2594 if (may_be_alloca && nonlocal_goto_handler_slots != 0)
2595 emit_stack_save (SAVE_NONLOCAL, &nonlocal_goto_stack_level, NULL_RTX);
2599 /* Free up storage we no longer need. */
2600 for (i = 0; i < num_actuals; ++i)
2601 if (args[i].aligned_regs)
2602 free (args[i].aligned_regs);
2607 /* Output a library call to function FUN (a SYMBOL_REF rtx)
2608 (emitting the queue unless NO_QUEUE is nonzero),
2609 for a value of mode OUTMODE,
2610 with NARGS different arguments, passed as alternating rtx values
2611 and machine_modes to convert them to.
2612 The rtx values should have been passed through protect_from_queue already.
2614 NO_QUEUE will be true if and only if the library call is a `const' call
2615 which will be enclosed in REG_LIBCALL/REG_RETVAL notes; it is equivalent
2616 to the variable is_const in expand_call.
2618 NO_QUEUE must be true for const calls, because if it isn't, then
2619 any pending increment will be emitted between REG_LIBCALL/REG_RETVAL notes,
2620 and will be lost if the libcall sequence is optimized away.
2622 NO_QUEUE must be false for non-const calls, because if it isn't, the
2623 call insn will have its CONST_CALL_P bit set, and it will be incorrectly
2624 optimized. For instance, the instruction scheduler may incorrectly
2625 move memory references across the non-const call. */
2628 emit_library_call VPARAMS((rtx orgfun, int no_queue, enum machine_mode outmode,
2631 #ifndef ANSI_PROTOTYPES
2634 enum machine_mode outmode;
2638 /* Total size in bytes of all the stack-parms scanned so far. */
2639 struct args_size args_size;
2640 /* Size of arguments before any adjustments (such as rounding). */
2641 struct args_size original_args_size;
2642 register int argnum;
2646 struct args_size alignment_pad;
2648 CUMULATIVE_ARGS args_so_far;
2649 struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
2650 struct args_size offset; struct args_size size; rtx save_area; };
2652 int old_inhibit_defer_pop = inhibit_defer_pop;
2653 rtx call_fusage = 0;
2654 int reg_parm_stack_space = 0;
2655 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
2656 /* Define the boundary of the register parm stack space that needs to be
2658 int low_to_save = -1, high_to_save = 0;
2659 rtx save_area = 0; /* Place that it is saved */
2662 #ifdef ACCUMULATE_OUTGOING_ARGS
2663 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
2664 char *initial_stack_usage_map = stack_usage_map;
2668 #ifdef REG_PARM_STACK_SPACE
2669 /* Size of the stack reserved for parameter registers. */
2670 #ifdef MAYBE_REG_PARM_STACK_SPACE
2671 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
2673 reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0);
2677 VA_START (p, nargs);
2679 #ifndef ANSI_PROTOTYPES
2680 orgfun = va_arg (p, rtx);
2681 no_queue = va_arg (p, int);
2682 outmode = va_arg (p, enum machine_mode);
2683 nargs = va_arg (p, int);
2688 /* Copy all the libcall-arguments out of the varargs data
2689 and into a vector ARGVEC.
2691 Compute how to pass each argument. We only support a very small subset
2692 of the full argument passing conventions to limit complexity here since
2693 library functions shouldn't have many args. */
2695 argvec = (struct arg *) alloca (nargs * sizeof (struct arg));
2696 bzero ((char *) argvec, nargs * sizeof (struct arg));
2699 INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0);
2701 args_size.constant = 0;
2706 for (count = 0; count < nargs; count++)
2708 rtx val = va_arg (p, rtx);
2709 enum machine_mode mode = va_arg (p, enum machine_mode);
2711 /* We cannot convert the arg value to the mode the library wants here;
2712 must do it earlier where we know the signedness of the arg. */
2714 || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
2717 /* On some machines, there's no way to pass a float to a library fcn.
2718 Pass it as a double instead. */
2719 #ifdef LIBGCC_NEEDS_DOUBLE
2720 if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
2721 val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode;
2724 /* There's no need to call protect_from_queue, because
2725 either emit_move_insn or emit_push_insn will do that. */
2727 /* Make sure it is a reasonable operand for a move or push insn. */
2728 if (GET_CODE (val) != REG && GET_CODE (val) != MEM
2729 && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
2730 val = force_operand (val, NULL_RTX);
2732 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
2733 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
2735 /* We do not support FUNCTION_ARG_CALLEE_COPIES here since it can
2736 be viewed as just an efficiency improvement. */
2737 rtx slot = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
2738 emit_move_insn (slot, val);
2739 val = force_operand (XEXP (slot, 0), NULL_RTX);
2744 argvec[count].value = val;
2745 argvec[count].mode = mode;
2747 argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
2748 if (argvec[count].reg && GET_CODE (argvec[count].reg) == PARALLEL)
2750 #ifdef FUNCTION_ARG_PARTIAL_NREGS
2751 argvec[count].partial
2752 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
2754 argvec[count].partial = 0;
2757 locate_and_pad_parm (mode, NULL_TREE,
2758 argvec[count].reg && argvec[count].partial == 0,
2759 NULL_TREE, &args_size, &argvec[count].offset,
2760 &argvec[count].size, &alignment_pad);
2762 if (argvec[count].size.var)
2765 if (reg_parm_stack_space == 0 && argvec[count].partial)
2766 argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
2768 if (argvec[count].reg == 0 || argvec[count].partial != 0
2769 || reg_parm_stack_space > 0)
2770 args_size.constant += argvec[count].size.constant;
2772 FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
2776 #ifdef FINAL_REG_PARM_STACK_SPACE
2777 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
2781 /* If this machine requires an external definition for library
2782 functions, write one out. */
2783 assemble_external_libcall (fun);
2785 original_args_size = args_size;
2786 #ifdef PREFERRED_STACK_BOUNDARY
2787 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
2788 / STACK_BYTES) * STACK_BYTES);
2791 args_size.constant = MAX (args_size.constant,
2792 reg_parm_stack_space);
2794 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2795 args_size.constant -= reg_parm_stack_space;
2798 if (args_size.constant > current_function_outgoing_args_size)
2799 current_function_outgoing_args_size = args_size.constant;
2801 #ifdef ACCUMULATE_OUTGOING_ARGS
2802 /* Since the stack pointer will never be pushed, it is possible for
2803 the evaluation of a parm to clobber something we have already
2804 written to the stack. Since most function calls on RISC machines
2805 do not use the stack, this is uncommon, but must work correctly.
2807 Therefore, we save any area of the stack that was already written
2808 and that we are using. Here we set up to do this by making a new
2809 stack usage map from the old one.
2811 Another approach might be to try to reorder the argument
2812 evaluations to avoid this conflicting stack usage. */
2814 needed = args_size.constant;
2816 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2817 /* Since we will be writing into the entire argument area, the
2818 map must be allocated for its entire size, not just the part that
2819 is the responsibility of the caller. */
2820 needed += reg_parm_stack_space;
2823 #ifdef ARGS_GROW_DOWNWARD
2824 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2827 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2830 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
2832 if (initial_highest_arg_in_use)
2833 bcopy (initial_stack_usage_map, stack_usage_map,
2834 initial_highest_arg_in_use);
2836 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
2837 bzero (&stack_usage_map[initial_highest_arg_in_use],
2838 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
2841 /* The address of the outgoing argument list must not be copied to a
2842 register here, because argblock would be left pointing to the
2843 wrong place after the call to allocate_dynamic_stack_space below.
2846 argblock = virtual_outgoing_args_rtx;
2847 #else /* not ACCUMULATE_OUTGOING_ARGS */
2848 #ifndef PUSH_ROUNDING
2849 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
2853 #ifdef PUSH_ARGS_REVERSED
2854 #ifdef PREFERRED_STACK_BOUNDARY
2855 /* If we push args individually in reverse order, perform stack alignment
2856 before the first push (the last arg). */
2858 anti_adjust_stack (GEN_INT (args_size.constant
2859 - original_args_size.constant));
2863 #ifdef PUSH_ARGS_REVERSED
2871 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
2872 /* The argument list is the property of the called routine and it
2873 may clobber it. If the fixed area has been used for previous
2874 parameters, we must save and restore it.
2876 Here we compute the boundary of the that needs to be saved, if any. */
2878 #ifdef ARGS_GROW_DOWNWARD
2879 for (count = 0; count < reg_parm_stack_space + 1; count++)
2881 for (count = 0; count < reg_parm_stack_space; count++)
2884 if (count >= highest_outgoing_arg_in_use
2885 || stack_usage_map[count] == 0)
2888 if (low_to_save == -1)
2889 low_to_save = count;
2891 high_to_save = count;
2894 if (low_to_save >= 0)
2896 int num_to_save = high_to_save - low_to_save + 1;
2897 enum machine_mode save_mode
2898 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
2901 /* If we don't have the required alignment, must do this in BLKmode. */
2902 if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
2903 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
2904 save_mode = BLKmode;
2906 #ifdef ARGS_GROW_DOWNWARD
2907 stack_area = gen_rtx_MEM (save_mode,
2908 memory_address (save_mode,
2909 plus_constant (argblock,
2912 stack_area = gen_rtx_MEM (save_mode,
2913 memory_address (save_mode,
2914 plus_constant (argblock,
2917 if (save_mode == BLKmode)
2919 save_area = assign_stack_temp (BLKmode, num_to_save, 0);
2920 emit_block_move (validize_mem (save_area), stack_area,
2921 GEN_INT (num_to_save),
2922 PARM_BOUNDARY / BITS_PER_UNIT);
2926 save_area = gen_reg_rtx (save_mode);
2927 emit_move_insn (save_area, stack_area);
2932 /* Push the args that need to be pushed. */
2934 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
2935 are to be pushed. */
2936 for (count = 0; count < nargs; count++, argnum += inc)
2938 register enum machine_mode mode = argvec[argnum].mode;
2939 register rtx val = argvec[argnum].value;
2940 rtx reg = argvec[argnum].reg;
2941 int partial = argvec[argnum].partial;
2942 #ifdef ACCUMULATE_OUTGOING_ARGS
2943 int lower_bound, upper_bound, i;
2946 if (! (reg != 0 && partial == 0))
2948 #ifdef ACCUMULATE_OUTGOING_ARGS
2949 /* If this is being stored into a pre-allocated, fixed-size, stack
2950 area, save any previous data at that location. */
2952 #ifdef ARGS_GROW_DOWNWARD
2953 /* stack_slot is negative, but we want to index stack_usage_map
2954 with positive values. */
2955 upper_bound = -argvec[argnum].offset.constant + 1;
2956 lower_bound = upper_bound - argvec[argnum].size.constant;
2958 lower_bound = argvec[argnum].offset.constant;
2959 upper_bound = lower_bound + argvec[argnum].size.constant;
2962 for (i = lower_bound; i < upper_bound; i++)
2963 if (stack_usage_map[i]
2964 /* Don't store things in the fixed argument area at this point;
2965 it has already been saved. */
2966 && i > reg_parm_stack_space)
2969 if (i != upper_bound)
2971 /* We need to make a save area. See what mode we can make it. */
2972 enum machine_mode save_mode
2973 = mode_for_size (argvec[argnum].size.constant * BITS_PER_UNIT,
2980 plus_constant (argblock,
2981 argvec[argnum].offset.constant)));
2983 argvec[argnum].save_area = gen_reg_rtx (save_mode);
2984 emit_move_insn (argvec[argnum].save_area, stack_area);
2987 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
2988 argblock, GEN_INT (argvec[argnum].offset.constant),
2989 reg_parm_stack_space, ARGS_SIZE_RTX (alignment_pad));
2991 #ifdef ACCUMULATE_OUTGOING_ARGS
2992 /* Now mark the segment we just used. */
2993 for (i = lower_bound; i < upper_bound; i++)
2994 stack_usage_map[i] = 1;
3001 #ifndef PUSH_ARGS_REVERSED
3002 #ifdef PREFERRED_STACK_BOUNDARY
3003 /* If we pushed args in forward order, perform stack alignment
3004 after pushing the last arg. */
3006 anti_adjust_stack (GEN_INT (args_size.constant
3007 - original_args_size.constant));
3011 #ifdef PUSH_ARGS_REVERSED
3017 fun = prepare_call_address (fun, NULL_TREE, &call_fusage, 0);
3019 /* Now load any reg parms into their regs. */
3021 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3022 are to be pushed. */
3023 for (count = 0; count < nargs; count++, argnum += inc)
3025 register rtx val = argvec[argnum].value;
3026 rtx reg = argvec[argnum].reg;
3027 int partial = argvec[argnum].partial;
3029 if (reg != 0 && partial == 0)
3030 emit_move_insn (reg, val);
3034 /* For version 1.37, try deleting this entirely. */
3038 /* Any regs containing parms remain in use through the call. */
3039 for (count = 0; count < nargs; count++)
3040 if (argvec[count].reg != 0)
3041 use_reg (&call_fusage, argvec[count].reg);
3043 /* Don't allow popping to be deferred, since then
3044 cse'ing of library calls could delete a call and leave the pop. */
3047 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
3048 will set inhibit_defer_pop to that value. */
3050 /* The return type is needed to decide how many bytes the function pops.
3051 Signedness plays no role in that, so for simplicity, we pretend it's
3052 always signed. We also assume that the list of arguments passed has
3053 no impact, so we pretend it is unknown. */
3056 get_identifier (XSTR (orgfun, 0)),
3057 build_function_type (outmode == VOIDmode ? void_type_node
3058 : type_for_mode (outmode, 0), NULL_TREE),
3059 original_args_size.constant, args_size.constant, 0,
3060 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
3061 outmode != VOIDmode ? hard_libcall_value (outmode) : NULL_RTX,
3062 old_inhibit_defer_pop + 1, call_fusage, no_queue);
3066 /* Now restore inhibit_defer_pop to its actual original value. */
3069 #ifdef ACCUMULATE_OUTGOING_ARGS
3070 #ifdef REG_PARM_STACK_SPACE
3073 enum machine_mode save_mode = GET_MODE (save_area);
3074 #ifdef ARGS_GROW_DOWNWARD
3076 = gen_rtx_MEM (save_mode,
3077 memory_address (save_mode,
3078 plus_constant (argblock,
3082 = gen_rtx_MEM (save_mode,
3083 memory_address (save_mode,
3084 plus_constant (argblock, low_to_save)));
3087 if (save_mode != BLKmode)
3088 emit_move_insn (stack_area, save_area);
3090 emit_block_move (stack_area, validize_mem (save_area),
3091 GEN_INT (high_to_save - low_to_save + 1),
3092 PARM_BOUNDARY / BITS_PER_UNIT);
3096 /* If we saved any argument areas, restore them. */
3097 for (count = 0; count < nargs; count++)
3098 if (argvec[count].save_area)
3100 enum machine_mode save_mode = GET_MODE (argvec[count].save_area);
3102 = gen_rtx_MEM (save_mode,
3105 plus_constant (argblock,
3106 argvec[count].offset.constant)));
3108 emit_move_insn (stack_area, argvec[count].save_area);
3111 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3112 stack_usage_map = initial_stack_usage_map;
3116 /* Like emit_library_call except that an extra argument, VALUE,
3117 comes second and says where to store the result.
3118 (If VALUE is zero, this function chooses a convenient way
3119 to return the value.
3121 This function returns an rtx for where the value is to be found.
3122 If VALUE is nonzero, VALUE is returned. */
3125 emit_library_call_value VPARAMS((rtx orgfun, rtx value, int no_queue,
3126 enum machine_mode outmode, int nargs, ...))
3128 #ifndef ANSI_PROTOTYPES
3132 enum machine_mode outmode;
3136 /* Total size in bytes of all the stack-parms scanned so far. */
3137 struct args_size args_size;
3138 /* Size of arguments before any adjustments (such as rounding). */
3139 struct args_size original_args_size;
3140 register int argnum;
3144 struct args_size alignment_pad;
3146 CUMULATIVE_ARGS args_so_far;
3147 struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
3148 struct args_size offset; struct args_size size; rtx save_area; };
3150 int old_inhibit_defer_pop = inhibit_defer_pop;
3151 rtx call_fusage = 0;
3153 int pcc_struct_value = 0;
3154 int struct_value_size = 0;
3156 int reg_parm_stack_space = 0;
3157 #ifdef ACCUMULATE_OUTGOING_ARGS
3161 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
3162 /* Define the boundary of the register parm stack space that needs to be
3164 int low_to_save = -1, high_to_save = 0;
3165 rtx save_area = 0; /* Place that it is saved */
3168 #ifdef ACCUMULATE_OUTGOING_ARGS
3169 /* Size of the stack reserved for parameter registers. */
3170 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
3171 char *initial_stack_usage_map = stack_usage_map;
3174 #ifdef REG_PARM_STACK_SPACE
3175 #ifdef MAYBE_REG_PARM_STACK_SPACE
3176 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
3178 reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0);
3182 VA_START (p, nargs);
3184 #ifndef ANSI_PROTOTYPES
3185 orgfun = va_arg (p, rtx);
3186 value = va_arg (p, rtx);
3187 no_queue = va_arg (p, int);
3188 outmode = va_arg (p, enum machine_mode);
3189 nargs = va_arg (p, int);
3192 is_const = no_queue;
3195 /* If this kind of value comes back in memory,
3196 decide where in memory it should come back. */
3197 if (aggregate_value_p (type_for_mode (outmode, 0)))
3199 #ifdef PCC_STATIC_STRUCT_RETURN
3201 = hard_function_value (build_pointer_type (type_for_mode (outmode, 0)),
3203 mem_value = gen_rtx_MEM (outmode, pointer_reg);
3204 pcc_struct_value = 1;
3206 value = gen_reg_rtx (outmode);
3207 #else /* not PCC_STATIC_STRUCT_RETURN */
3208 struct_value_size = GET_MODE_SIZE (outmode);
3209 if (value != 0 && GET_CODE (value) == MEM)
3212 mem_value = assign_stack_temp (outmode, GET_MODE_SIZE (outmode), 0);
3215 /* This call returns a big structure. */
3219 /* ??? Unfinished: must pass the memory address as an argument. */
3221 /* Copy all the libcall-arguments out of the varargs data
3222 and into a vector ARGVEC.
3224 Compute how to pass each argument. We only support a very small subset
3225 of the full argument passing conventions to limit complexity here since
3226 library functions shouldn't have many args. */
3228 argvec = (struct arg *) alloca ((nargs + 1) * sizeof (struct arg));
3229 bzero ((char *) argvec, (nargs + 1) * sizeof (struct arg));
3231 INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0);
3233 args_size.constant = 0;
3240 /* If there's a structure value address to be passed,
3241 either pass it in the special place, or pass it as an extra argument. */
3242 if (mem_value && struct_value_rtx == 0 && ! pcc_struct_value)
3244 rtx addr = XEXP (mem_value, 0);
3247 /* Make sure it is a reasonable operand for a move or push insn. */
3248 if (GET_CODE (addr) != REG && GET_CODE (addr) != MEM
3249 && ! (CONSTANT_P (addr) && LEGITIMATE_CONSTANT_P (addr)))
3250 addr = force_operand (addr, NULL_RTX);
3252 argvec[count].value = addr;
3253 argvec[count].mode = Pmode;
3254 argvec[count].partial = 0;
3256 argvec[count].reg = FUNCTION_ARG (args_so_far, Pmode, NULL_TREE, 1);
3257 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3258 if (FUNCTION_ARG_PARTIAL_NREGS (args_so_far, Pmode, NULL_TREE, 1))
3262 locate_and_pad_parm (Pmode, NULL_TREE,
3263 argvec[count].reg && argvec[count].partial == 0,
3264 NULL_TREE, &args_size, &argvec[count].offset,
3265 &argvec[count].size, &alignment_pad);
3268 if (argvec[count].reg == 0 || argvec[count].partial != 0
3269 || reg_parm_stack_space > 0)
3270 args_size.constant += argvec[count].size.constant;
3272 FUNCTION_ARG_ADVANCE (args_so_far, Pmode, (tree) 0, 1);
3277 for (; count < nargs; count++)
3279 rtx val = va_arg (p, rtx);
3280 enum machine_mode mode = va_arg (p, enum machine_mode);
3282 /* We cannot convert the arg value to the mode the library wants here;
3283 must do it earlier where we know the signedness of the arg. */
3285 || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
3288 /* On some machines, there's no way to pass a float to a library fcn.
3289 Pass it as a double instead. */
3290 #ifdef LIBGCC_NEEDS_DOUBLE
3291 if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
3292 val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode;
3295 /* There's no need to call protect_from_queue, because
3296 either emit_move_insn or emit_push_insn will do that. */
3298 /* Make sure it is a reasonable operand for a move or push insn. */
3299 if (GET_CODE (val) != REG && GET_CODE (val) != MEM
3300 && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
3301 val = force_operand (val, NULL_RTX);
3303 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
3304 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
3306 /* We do not support FUNCTION_ARG_CALLEE_COPIES here since it can
3307 be viewed as just an efficiency improvement. */
3308 rtx slot = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
3309 emit_move_insn (slot, val);
3310 val = XEXP (slot, 0);
3315 argvec[count].value = val;
3316 argvec[count].mode = mode;
3318 argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
3319 if (argvec[count].reg && GET_CODE (argvec[count].reg) == PARALLEL)
3321 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3322 argvec[count].partial
3323 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
3325 argvec[count].partial = 0;
3328 locate_and_pad_parm (mode, NULL_TREE,
3329 argvec[count].reg && argvec[count].partial == 0,
3330 NULL_TREE, &args_size, &argvec[count].offset,
3331 &argvec[count].size, &alignment_pad);
3333 if (argvec[count].size.var)
3336 if (reg_parm_stack_space == 0 && argvec[count].partial)
3337 argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
3339 if (argvec[count].reg == 0 || argvec[count].partial != 0
3340 || reg_parm_stack_space > 0)
3341 args_size.constant += argvec[count].size.constant;
3343 FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
3347 #ifdef FINAL_REG_PARM_STACK_SPACE
3348 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
3351 /* If this machine requires an external definition for library
3352 functions, write one out. */
3353 assemble_external_libcall (fun);
3355 original_args_size = args_size;
3356 #ifdef PREFERRED_STACK_BOUNDARY
3357 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
3358 / STACK_BYTES) * STACK_BYTES);
3361 args_size.constant = MAX (args_size.constant,
3362 reg_parm_stack_space);
3364 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3365 args_size.constant -= reg_parm_stack_space;
3368 if (args_size.constant > current_function_outgoing_args_size)
3369 current_function_outgoing_args_size = args_size.constant;
3371 #ifdef ACCUMULATE_OUTGOING_ARGS
3372 /* Since the stack pointer will never be pushed, it is possible for
3373 the evaluation of a parm to clobber something we have already
3374 written to the stack. Since most function calls on RISC machines
3375 do not use the stack, this is uncommon, but must work correctly.
3377 Therefore, we save any area of the stack that was already written
3378 and that we are using. Here we set up to do this by making a new
3379 stack usage map from the old one.
3381 Another approach might be to try to reorder the argument
3382 evaluations to avoid this conflicting stack usage. */
3384 needed = args_size.constant;
3386 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3387 /* Since we will be writing into the entire argument area, the
3388 map must be allocated for its entire size, not just the part that
3389 is the responsibility of the caller. */
3390 needed += reg_parm_stack_space;
3393 #ifdef ARGS_GROW_DOWNWARD
3394 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3397 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3400 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
3402 if (initial_highest_arg_in_use)
3403 bcopy (initial_stack_usage_map, stack_usage_map,
3404 initial_highest_arg_in_use);
3406 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
3407 bzero (&stack_usage_map[initial_highest_arg_in_use],
3408 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
3411 /* The address of the outgoing argument list must not be copied to a
3412 register here, because argblock would be left pointing to the
3413 wrong place after the call to allocate_dynamic_stack_space below.
3416 argblock = virtual_outgoing_args_rtx;
3417 #else /* not ACCUMULATE_OUTGOING_ARGS */
3418 #ifndef PUSH_ROUNDING
3419 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
3423 #ifdef PUSH_ARGS_REVERSED
3424 #ifdef PREFERRED_STACK_BOUNDARY
3425 /* If we push args individually in reverse order, perform stack alignment
3426 before the first push (the last arg). */
3428 anti_adjust_stack (GEN_INT (args_size.constant
3429 - original_args_size.constant));
3433 #ifdef PUSH_ARGS_REVERSED
3441 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
3442 /* The argument list is the property of the called routine and it
3443 may clobber it. If the fixed area has been used for previous
3444 parameters, we must save and restore it.
3446 Here we compute the boundary of the that needs to be saved, if any. */
3448 #ifdef ARGS_GROW_DOWNWARD
3449 for (count = 0; count < reg_parm_stack_space + 1; count++)
3451 for (count = 0; count < reg_parm_stack_space; count++)
3454 if (count >= highest_outgoing_arg_in_use
3455 || stack_usage_map[count] == 0)
3458 if (low_to_save == -1)
3459 low_to_save = count;
3461 high_to_save = count;
3464 if (low_to_save >= 0)
3466 int num_to_save = high_to_save - low_to_save + 1;
3467 enum machine_mode save_mode
3468 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
3471 /* If we don't have the required alignment, must do this in BLKmode. */
3472 if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
3473 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
3474 save_mode = BLKmode;
3476 #ifdef ARGS_GROW_DOWNWARD
3477 stack_area = gen_rtx_MEM (save_mode,
3478 memory_address (save_mode,
3479 plus_constant (argblock,
3482 stack_area = gen_rtx_MEM (save_mode,
3483 memory_address (save_mode,
3484 plus_constant (argblock,
3487 if (save_mode == BLKmode)
3489 save_area = assign_stack_temp (BLKmode, num_to_save, 0);
3490 emit_block_move (validize_mem (save_area), stack_area,
3491 GEN_INT (num_to_save),
3492 PARM_BOUNDARY / BITS_PER_UNIT);
3496 save_area = gen_reg_rtx (save_mode);
3497 emit_move_insn (save_area, stack_area);
3502 /* Push the args that need to be pushed. */
3504 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3505 are to be pushed. */
3506 for (count = 0; count < nargs; count++, argnum += inc)
3508 register enum machine_mode mode = argvec[argnum].mode;
3509 register rtx val = argvec[argnum].value;
3510 rtx reg = argvec[argnum].reg;
3511 int partial = argvec[argnum].partial;
3512 #ifdef ACCUMULATE_OUTGOING_ARGS
3513 int lower_bound, upper_bound, i;
3516 if (! (reg != 0 && partial == 0))
3518 #ifdef ACCUMULATE_OUTGOING_ARGS
3519 /* If this is being stored into a pre-allocated, fixed-size, stack
3520 area, save any previous data at that location. */
3522 #ifdef ARGS_GROW_DOWNWARD
3523 /* stack_slot is negative, but we want to index stack_usage_map
3524 with positive values. */
3525 upper_bound = -argvec[argnum].offset.constant + 1;
3526 lower_bound = upper_bound - argvec[argnum].size.constant;
3528 lower_bound = argvec[argnum].offset.constant;
3529 upper_bound = lower_bound + argvec[argnum].size.constant;
3532 for (i = lower_bound; i < upper_bound; i++)
3533 if (stack_usage_map[i]
3534 /* Don't store things in the fixed argument area at this point;
3535 it has already been saved. */
3536 && i > reg_parm_stack_space)
3539 if (i != upper_bound)
3541 /* We need to make a save area. See what mode we can make it. */
3542 enum machine_mode save_mode
3543 = mode_for_size (argvec[argnum].size.constant * BITS_PER_UNIT,
3550 plus_constant (argblock,
3551 argvec[argnum].offset.constant)));
3552 argvec[argnum].save_area = gen_reg_rtx (save_mode);
3554 emit_move_insn (argvec[argnum].save_area, stack_area);
3557 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
3558 argblock, GEN_INT (argvec[argnum].offset.constant),
3559 reg_parm_stack_space, ARGS_SIZE_RTX (alignment_pad));
3561 #ifdef ACCUMULATE_OUTGOING_ARGS
3562 /* Now mark the segment we just used. */
3563 for (i = lower_bound; i < upper_bound; i++)
3564 stack_usage_map[i] = 1;
3571 #ifndef PUSH_ARGS_REVERSED
3572 #ifdef PREFERRED_STACK_BOUNDARY
3573 /* If we pushed args in forward order, perform stack alignment
3574 after pushing the last arg. */
3576 anti_adjust_stack (GEN_INT (args_size.constant
3577 - original_args_size.constant));
3581 #ifdef PUSH_ARGS_REVERSED
3587 fun = prepare_call_address (fun, NULL_TREE, &call_fusage, 0);
3589 /* Now load any reg parms into their regs. */
3591 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3592 are to be pushed. */
3593 for (count = 0; count < nargs; count++, argnum += inc)
3595 register rtx val = argvec[argnum].value;
3596 rtx reg = argvec[argnum].reg;
3597 int partial = argvec[argnum].partial;
3599 if (reg != 0 && partial == 0)
3600 emit_move_insn (reg, val);
3605 /* For version 1.37, try deleting this entirely. */
3610 /* Any regs containing parms remain in use through the call. */
3611 for (count = 0; count < nargs; count++)
3612 if (argvec[count].reg != 0)
3613 use_reg (&call_fusage, argvec[count].reg);
3615 /* Pass the function the address in which to return a structure value. */
3616 if (mem_value != 0 && struct_value_rtx != 0 && ! pcc_struct_value)
3618 emit_move_insn (struct_value_rtx,
3620 force_operand (XEXP (mem_value, 0),
3622 if (GET_CODE (struct_value_rtx) == REG)
3623 use_reg (&call_fusage, struct_value_rtx);
3626 /* Don't allow popping to be deferred, since then
3627 cse'ing of library calls could delete a call and leave the pop. */
3630 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
3631 will set inhibit_defer_pop to that value. */
3632 /* See the comment in emit_library_call about the function type we build
3636 get_identifier (XSTR (orgfun, 0)),
3637 build_function_type (type_for_mode (outmode, 0), NULL_TREE),
3638 original_args_size.constant, args_size.constant,
3640 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
3641 mem_value == 0 ? hard_libcall_value (outmode) : NULL_RTX,
3642 old_inhibit_defer_pop + 1, call_fusage, is_const);
3644 /* Now restore inhibit_defer_pop to its actual original value. */
3649 /* Copy the value to the right place. */
3650 if (outmode != VOIDmode)
3656 if (value != mem_value)
3657 emit_move_insn (value, mem_value);
3659 else if (value != 0)
3660 emit_move_insn (value, hard_libcall_value (outmode));
3662 value = hard_libcall_value (outmode);
3665 #ifdef ACCUMULATE_OUTGOING_ARGS
3666 #ifdef REG_PARM_STACK_SPACE
3669 enum machine_mode save_mode = GET_MODE (save_area);
3670 #ifdef ARGS_GROW_DOWNWARD
3672 = gen_rtx_MEM (save_mode,
3673 memory_address (save_mode,
3674 plus_constant (argblock,
3678 = gen_rtx_MEM (save_mode,
3679 memory_address (save_mode,
3680 plus_constant (argblock, low_to_save)));
3682 if (save_mode != BLKmode)
3683 emit_move_insn (stack_area, save_area);
3685 emit_block_move (stack_area, validize_mem (save_area),
3686 GEN_INT (high_to_save - low_to_save + 1),
3687 PARM_BOUNDARY / BITS_PER_UNIT);
3691 /* If we saved any argument areas, restore them. */
3692 for (count = 0; count < nargs; count++)
3693 if (argvec[count].save_area)
3695 enum machine_mode save_mode = GET_MODE (argvec[count].save_area);
3697 = gen_rtx_MEM (save_mode,
3700 plus_constant (argblock,
3701 argvec[count].offset.constant)));
3703 emit_move_insn (stack_area, argvec[count].save_area);
3706 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3707 stack_usage_map = initial_stack_usage_map;
3714 /* Return an rtx which represents a suitable home on the stack
3715 given TYPE, the type of the argument looking for a home.
3716 This is called only for BLKmode arguments.
3718 SIZE is the size needed for this target.
3719 ARGS_ADDR is the address of the bottom of the argument block for this call.
3720 OFFSET describes this parameter's offset into ARGS_ADDR. It is meaningless
3721 if this machine uses push insns. */
3724 target_for_arg (type, size, args_addr, offset)
3728 struct args_size offset;
3731 rtx offset_rtx = ARGS_SIZE_RTX (offset);
3733 /* We do not call memory_address if possible,
3734 because we want to address as close to the stack
3735 as possible. For non-variable sized arguments,
3736 this will be stack-pointer relative addressing. */
3737 if (GET_CODE (offset_rtx) == CONST_INT)
3738 target = plus_constant (args_addr, INTVAL (offset_rtx));
3741 /* I have no idea how to guarantee that this
3742 will work in the presence of register parameters. */
3743 target = gen_rtx_PLUS (Pmode, args_addr, offset_rtx);
3744 target = memory_address (QImode, target);
3747 return gen_rtx_MEM (BLKmode, target);
3751 /* Store a single argument for a function call
3752 into the register or memory area where it must be passed.
3753 *ARG describes the argument value and where to pass it.
3755 ARGBLOCK is the address of the stack-block for all the arguments,
3756 or 0 on a machine where arguments are pushed individually.
3758 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
3759 so must be careful about how the stack is used.
3761 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
3762 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
3763 that we need not worry about saving and restoring the stack.
3765 FNDECL is the declaration of the function we are calling. */
3768 store_one_arg (arg, argblock, may_be_alloca, variable_size,
3769 reg_parm_stack_space)
3770 struct arg_data *arg;
3773 int variable_size ATTRIBUTE_UNUSED;
3774 int reg_parm_stack_space;
3776 register tree pval = arg->tree_value;
3780 #ifdef ACCUMULATE_OUTGOING_ARGS
3781 int i, lower_bound = 0, upper_bound = 0;
3784 if (TREE_CODE (pval) == ERROR_MARK)
3787 /* Push a new temporary level for any temporaries we make for
3791 #ifdef ACCUMULATE_OUTGOING_ARGS
3792 /* If this is being stored into a pre-allocated, fixed-size, stack area,
3793 save any previous data at that location. */
3794 if (argblock && ! variable_size && arg->stack)
3796 #ifdef ARGS_GROW_DOWNWARD
3797 /* stack_slot is negative, but we want to index stack_usage_map
3798 with positive values. */
3799 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
3800 upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
3804 lower_bound = upper_bound - arg->size.constant;
3806 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
3807 lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
3811 upper_bound = lower_bound + arg->size.constant;
3814 for (i = lower_bound; i < upper_bound; i++)
3815 if (stack_usage_map[i]
3816 /* Don't store things in the fixed argument area at this point;
3817 it has already been saved. */
3818 && i > reg_parm_stack_space)
3821 if (i != upper_bound)
3823 /* We need to make a save area. See what mode we can make it. */
3824 enum machine_mode save_mode
3825 = mode_for_size (arg->size.constant * BITS_PER_UNIT, MODE_INT, 1);
3827 = gen_rtx_MEM (save_mode,
3828 memory_address (save_mode,
3829 XEXP (arg->stack_slot, 0)));
3831 if (save_mode == BLKmode)
3833 arg->save_area = assign_stack_temp (BLKmode,
3834 arg->size.constant, 0);
3835 MEM_SET_IN_STRUCT_P (arg->save_area,
3836 AGGREGATE_TYPE_P (TREE_TYPE
3837 (arg->tree_value)));
3838 preserve_temp_slots (arg->save_area);
3839 emit_block_move (validize_mem (arg->save_area), stack_area,
3840 GEN_INT (arg->size.constant),
3841 PARM_BOUNDARY / BITS_PER_UNIT);
3845 arg->save_area = gen_reg_rtx (save_mode);
3846 emit_move_insn (arg->save_area, stack_area);
3851 /* Now that we have saved any slots that will be overwritten by this
3852 store, mark all slots this store will use. We must do this before
3853 we actually expand the argument since the expansion itself may
3854 trigger library calls which might need to use the same stack slot. */
3855 if (argblock && ! variable_size && arg->stack)
3856 for (i = lower_bound; i < upper_bound; i++)
3857 stack_usage_map[i] = 1;
3860 /* If this isn't going to be placed on both the stack and in registers,
3861 set up the register and number of words. */
3862 if (! arg->pass_on_stack)
3863 reg = arg->reg, partial = arg->partial;
3865 if (reg != 0 && partial == 0)
3866 /* Being passed entirely in a register. We shouldn't be called in
3870 /* If this arg needs special alignment, don't load the registers
3872 if (arg->n_aligned_regs != 0)
3875 /* If this is being passed partially in a register, we can't evaluate
3876 it directly into its stack slot. Otherwise, we can. */
3877 if (arg->value == 0)
3879 #ifdef ACCUMULATE_OUTGOING_ARGS
3880 /* stack_arg_under_construction is nonzero if a function argument is
3881 being evaluated directly into the outgoing argument list and
3882 expand_call must take special action to preserve the argument list
3883 if it is called recursively.
3885 For scalar function arguments stack_usage_map is sufficient to
3886 determine which stack slots must be saved and restored. Scalar
3887 arguments in general have pass_on_stack == 0.
3889 If this argument is initialized by a function which takes the
3890 address of the argument (a C++ constructor or a C function
3891 returning a BLKmode structure), then stack_usage_map is
3892 insufficient and expand_call must push the stack around the
3893 function call. Such arguments have pass_on_stack == 1.
3895 Note that it is always safe to set stack_arg_under_construction,
3896 but this generates suboptimal code if set when not needed. */
3898 if (arg->pass_on_stack)
3899 stack_arg_under_construction++;
3901 arg->value = expand_expr (pval,
3903 || TYPE_MODE (TREE_TYPE (pval)) != arg->mode)
3904 ? NULL_RTX : arg->stack,
3907 /* If we are promoting object (or for any other reason) the mode
3908 doesn't agree, convert the mode. */
3910 if (arg->mode != TYPE_MODE (TREE_TYPE (pval)))
3911 arg->value = convert_modes (arg->mode, TYPE_MODE (TREE_TYPE (pval)),
3912 arg->value, arg->unsignedp);
3914 #ifdef ACCUMULATE_OUTGOING_ARGS
3915 if (arg->pass_on_stack)
3916 stack_arg_under_construction--;
3920 /* Don't allow anything left on stack from computation
3921 of argument to alloca. */
3923 do_pending_stack_adjust ();
3925 if (arg->value == arg->stack)
3927 /* If the value is already in the stack slot, we are done. */
3928 if (current_function_check_memory_usage && GET_CODE (arg->stack) == MEM)
3930 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
3931 XEXP (arg->stack, 0), Pmode,
3932 ARGS_SIZE_RTX (arg->size),
3933 TYPE_MODE (sizetype),
3934 GEN_INT (MEMORY_USE_RW),
3935 TYPE_MODE (integer_type_node));
3938 else if (arg->mode != BLKmode)
3942 /* Argument is a scalar, not entirely passed in registers.
3943 (If part is passed in registers, arg->partial says how much
3944 and emit_push_insn will take care of putting it there.)
3946 Push it, and if its size is less than the
3947 amount of space allocated to it,
3948 also bump stack pointer by the additional space.
3949 Note that in C the default argument promotions
3950 will prevent such mismatches. */
3952 size = GET_MODE_SIZE (arg->mode);
3953 /* Compute how much space the push instruction will push.
3954 On many machines, pushing a byte will advance the stack
3955 pointer by a halfword. */
3956 #ifdef PUSH_ROUNDING
3957 size = PUSH_ROUNDING (size);
3961 /* Compute how much space the argument should get:
3962 round up to a multiple of the alignment for arguments. */
3963 if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)))
3964 used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
3965 / (PARM_BOUNDARY / BITS_PER_UNIT))
3966 * (PARM_BOUNDARY / BITS_PER_UNIT));
3968 /* This isn't already where we want it on the stack, so put it there.
3969 This can either be done with push or copy insns. */
3970 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX, 0,
3971 partial, reg, used - size, argblock,
3972 ARGS_SIZE_RTX (arg->offset), reg_parm_stack_space,
3973 ARGS_SIZE_RTX (arg->alignment_pad));
3978 /* BLKmode, at least partly to be pushed. */
3980 register int excess;
3983 /* Pushing a nonscalar.
3984 If part is passed in registers, PARTIAL says how much
3985 and emit_push_insn will take care of putting it there. */
3987 /* Round its size up to a multiple
3988 of the allocation unit for arguments. */
3990 if (arg->size.var != 0)
3993 size_rtx = ARGS_SIZE_RTX (arg->size);
3997 /* PUSH_ROUNDING has no effect on us, because
3998 emit_push_insn for BLKmode is careful to avoid it. */
3999 excess = (arg->size.constant - int_size_in_bytes (TREE_TYPE (pval))
4000 + partial * UNITS_PER_WORD);
4001 size_rtx = expr_size (pval);
4004 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
4005 TYPE_ALIGN (TREE_TYPE (pval)) / BITS_PER_UNIT, partial,
4006 reg, excess, argblock, ARGS_SIZE_RTX (arg->offset),
4007 reg_parm_stack_space,
4008 ARGS_SIZE_RTX (arg->alignment_pad));
4012 /* Unless this is a partially-in-register argument, the argument is now
4015 ??? Note that this can change arg->value from arg->stack to
4016 arg->stack_slot and it matters when they are not the same.
4017 It isn't totally clear that this is correct in all cases. */
4019 arg->value = arg->stack_slot;
4021 /* Once we have pushed something, pops can't safely
4022 be deferred during the rest of the arguments. */
4025 /* ANSI doesn't require a sequence point here,
4026 but PCC has one, so this will avoid some problems. */
4029 /* Free any temporary slots made in processing this argument. Show
4030 that we might have taken the address of something and pushed that
4032 preserve_temp_slots (NULL_RTX);