1 /* Convert function calls to rtl insns, for GNU C compiler.
2 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998
3 1999, 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
30 #include "insn-flags.h"
35 #if !defined PREFERRED_STACK_BOUNDARY && defined STACK_BOUNDARY
36 #define PREFERRED_STACK_BOUNDARY STACK_BOUNDARY
39 /* Decide whether a function's arguments should be processed
40 from first to last or from last to first.
42 They should if the stack and args grow in opposite directions, but
43 only if we have push insns. */
47 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
48 #define PUSH_ARGS_REVERSED /* If it's last to first */
53 /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */
54 #define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
56 /* Data structure and subroutines used within expand_call. */
60 /* Tree node for this argument. */
62 /* Mode for value; TYPE_MODE unless promoted. */
63 enum machine_mode mode;
64 /* Current RTL value for argument, or 0 if it isn't precomputed. */
66 /* Initially-compute RTL value for argument; only for const functions. */
68 /* Register to pass this argument in, 0 if passed on stack, or an
69 PARALLEL if the arg is to be copied into multiple non-contiguous
72 /* If REG was promoted from the actual mode of the argument expression,
73 indicates whether the promotion is sign- or zero-extended. */
75 /* Number of registers to use. 0 means put the whole arg in registers.
76 Also 0 if not passed in registers. */
78 /* Non-zero if argument must be passed on stack.
79 Note that some arguments may be passed on the stack
80 even though pass_on_stack is zero, just because FUNCTION_ARG says so.
81 pass_on_stack identifies arguments that *cannot* go in registers. */
83 /* Offset of this argument from beginning of stack-args. */
84 struct args_size offset;
85 /* Similar, but offset to the start of the stack slot. Different from
86 OFFSET if this arg pads downward. */
87 struct args_size slot_offset;
88 /* Size of this argument on the stack, rounded up for any padding it gets,
89 parts of the argument passed in registers do not count.
90 If REG_PARM_STACK_SPACE is defined, then register parms
91 are counted here as well. */
92 struct args_size size;
93 /* Location on the stack at which parameter should be stored. The store
94 has already been done if STACK == VALUE. */
96 /* Location on the stack of the start of this argument slot. This can
97 differ from STACK if this arg pads downward. This location is known
98 to be aligned to FUNCTION_ARG_BOUNDARY. */
100 #ifdef ACCUMULATE_OUTGOING_ARGS
101 /* Place that this stack area has been saved, if needed. */
104 /* If an argument's alignment does not permit direct copying into registers,
105 copy in smaller-sized pieces into pseudos. These are stored in a
106 block pointed to by this field. The next field says how many
107 word-sized pseudos we made. */
110 /* The amount that the stack pointer needs to be adjusted to
111 force alignment for the next argument. */
112 struct args_size alignment_pad;
115 #ifdef ACCUMULATE_OUTGOING_ARGS
116 /* A vector of one char per byte of stack space. A byte if non-zero if
117 the corresponding stack location has been used.
118 This vector is used to prevent a function call within an argument from
119 clobbering any stack already set up. */
120 static char *stack_usage_map;
122 /* Size of STACK_USAGE_MAP. */
123 static int highest_outgoing_arg_in_use;
125 /* stack_arg_under_construction is nonzero when an argument may be
126 initialized with a constructor call (including a C function that
127 returns a BLKmode struct) and expand_call must take special action
128 to make sure the object being constructed does not overlap the
129 argument list for the constructor call. */
130 int stack_arg_under_construction;
133 static int calls_function PARAMS ((tree, int));
134 static int calls_function_1 PARAMS ((tree, int));
135 static void emit_call_1 PARAMS ((rtx, tree, tree, HOST_WIDE_INT,
136 HOST_WIDE_INT, HOST_WIDE_INT, rtx,
137 rtx, int, rtx, int));
138 static void precompute_register_parameters PARAMS ((int,
141 static void store_one_arg PARAMS ((struct arg_data *, rtx, int, int,
143 static void store_unaligned_arguments_into_pseudos PARAMS ((struct arg_data *,
145 static int finalize_must_preallocate PARAMS ((int, int,
147 struct args_size *));
148 static void precompute_arguments PARAMS ((int, int, int,
150 struct args_size *));
151 static int compute_argument_block_size PARAMS ((int,
154 static void initialize_argument_information PARAMS ((int,
161 static void compute_argument_addresses PARAMS ((struct arg_data *,
163 static rtx rtx_for_function_call PARAMS ((tree, tree));
164 static void load_register_parameters PARAMS ((struct arg_data *,
167 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
168 static rtx save_fixed_argument_area PARAMS ((int, rtx, int *, int *));
169 static void restore_fixed_argument_area PARAMS ((rtx, rtx, int, int));
172 /* If WHICH is 1, return 1 if EXP contains a call to the built-in function
175 If WHICH is 0, return 1 if EXP contains a call to any function.
176 Actually, we only need return 1 if evaluating EXP would require pushing
177 arguments on the stack, but that is too difficult to compute, so we just
178 assume any function call might require the stack. */
180 static tree calls_function_save_exprs;
183 calls_function (exp, which)
188 calls_function_save_exprs = 0;
189 val = calls_function_1 (exp, which);
190 calls_function_save_exprs = 0;
195 calls_function_1 (exp, which)
200 enum tree_code code = TREE_CODE (exp);
201 int type = TREE_CODE_CLASS (code);
202 int length = tree_code_length[(int) code];
204 /* If this code is language-specific, we don't know what it will do. */
205 if ((int) code >= NUM_TREE_CODES)
208 /* Only expressions and references can contain calls. */
209 if (type != 'e' && type != '<' && type != '1' && type != '2' && type != 'r'
218 else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
219 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
222 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
224 if ((DECL_BUILT_IN (fndecl)
225 && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
226 && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA)
227 || (DECL_SAVED_INSNS (fndecl)
228 && DECL_SAVED_INSNS (fndecl)->calls_alloca))
232 /* Third operand is RTL. */
237 if (SAVE_EXPR_RTL (exp) != 0)
239 if (value_member (exp, calls_function_save_exprs))
241 calls_function_save_exprs = tree_cons (NULL_TREE, exp,
242 calls_function_save_exprs);
243 return (TREE_OPERAND (exp, 0) != 0
244 && calls_function_1 (TREE_OPERAND (exp, 0), which));
250 for (local = BLOCK_VARS (exp); local; local = TREE_CHAIN (local))
251 if (DECL_INITIAL (local) != 0
252 && calls_function_1 (DECL_INITIAL (local), which))
256 register tree subblock;
258 for (subblock = BLOCK_SUBBLOCKS (exp);
260 subblock = TREE_CHAIN (subblock))
261 if (calls_function_1 (subblock, which))
266 case METHOD_CALL_EXPR:
270 case WITH_CLEANUP_EXPR:
281 for (i = 0; i < length; i++)
282 if (TREE_OPERAND (exp, i) != 0
283 && calls_function_1 (TREE_OPERAND (exp, i), which))
289 /* Force FUNEXP into a form suitable for the address of a CALL,
290 and return that as an rtx. Also load the static chain register
291 if FNDECL is a nested function.
293 CALL_FUSAGE points to a variable holding the prospective
294 CALL_INSN_FUNCTION_USAGE information. */
297 prepare_call_address (funexp, fndecl, call_fusage, reg_parm_seen)
303 rtx static_chain_value = 0;
305 funexp = protect_from_queue (funexp, 0);
308 /* Get possible static chain value for nested function in C. */
309 static_chain_value = lookup_static_chain (fndecl);
311 /* Make a valid memory address and copy constants thru pseudo-regs,
312 but not for a constant address if -fno-function-cse. */
313 if (GET_CODE (funexp) != SYMBOL_REF)
314 /* If we are using registers for parameters, force the
315 function address into a register now. */
316 funexp = ((SMALL_REGISTER_CLASSES && reg_parm_seen)
317 ? force_not_mem (memory_address (FUNCTION_MODE, funexp))
318 : memory_address (FUNCTION_MODE, funexp));
321 #ifndef NO_FUNCTION_CSE
322 if (optimize && ! flag_no_function_cse)
323 #ifdef NO_RECURSIVE_FUNCTION_CSE
324 if (fndecl != current_function_decl)
326 funexp = force_reg (Pmode, funexp);
330 if (static_chain_value != 0)
332 emit_move_insn (static_chain_rtx, static_chain_value);
334 if (GET_CODE (static_chain_rtx) == REG)
335 use_reg (call_fusage, static_chain_rtx);
341 /* Generate instructions to call function FUNEXP,
342 and optionally pop the results.
343 The CALL_INSN is the first insn generated.
345 FNDECL is the declaration node of the function. This is given to the
346 macro RETURN_POPS_ARGS to determine whether this function pops its own args.
348 FUNTYPE is the data type of the function. This is given to the macro
349 RETURN_POPS_ARGS to determine whether this function pops its own args.
350 We used to allow an identifier for library functions, but that doesn't
351 work when the return type is an aggregate type and the calling convention
352 says that the pointer to this aggregate is to be popped by the callee.
354 STACK_SIZE is the number of bytes of arguments on the stack,
355 rounded up to PREFERRED_STACK_BOUNDARY; zero if the size is variable.
356 This is both to put into the call insn and
357 to generate explicit popping code if necessary.
359 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
360 It is zero if this call doesn't want a structure value.
362 NEXT_ARG_REG is the rtx that results from executing
363 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1)
364 just after all the args have had their registers assigned.
365 This could be whatever you like, but normally it is the first
366 arg-register beyond those used for args in this call,
367 or 0 if all the arg-registers are used in this call.
368 It is passed on to `gen_call' so you can put this info in the call insn.
370 VALREG is a hard register in which a value is returned,
371 or 0 if the call does not return a value.
373 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
374 the args to this call were processed.
375 We restore `inhibit_defer_pop' to that value.
377 CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
378 denote registers used by the called function.
380 IS_CONST is true if this is a `const' call. */
383 emit_call_1 (funexp, fndecl, funtype, stack_size, rounded_stack_size,
384 struct_value_size, next_arg_reg, valreg, old_inhibit_defer_pop,
385 call_fusage, is_const)
387 tree fndecl ATTRIBUTE_UNUSED;
388 tree funtype ATTRIBUTE_UNUSED;
389 HOST_WIDE_INT stack_size ATTRIBUTE_UNUSED;
390 HOST_WIDE_INT rounded_stack_size;
391 HOST_WIDE_INT struct_value_size ATTRIBUTE_UNUSED;
394 int old_inhibit_defer_pop;
398 rtx rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
399 #if defined (HAVE_call) && defined (HAVE_call_value)
400 rtx struct_value_size_rtx = GEN_INT (struct_value_size);
403 #ifndef ACCUMULATE_OUTGOING_ARGS
404 int already_popped = 0;
405 HOST_WIDE_INT n_popped = RETURN_POPS_ARGS (fndecl, funtype, stack_size);
408 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
409 and we don't want to load it into a register as an optimization,
410 because prepare_call_address already did it if it should be done. */
411 if (GET_CODE (funexp) != SYMBOL_REF)
412 funexp = memory_address (FUNCTION_MODE, funexp);
414 #ifndef ACCUMULATE_OUTGOING_ARGS
415 #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
416 /* If the target has "call" or "call_value" insns, then prefer them
417 if no arguments are actually popped. If the target does not have
418 "call" or "call_value" insns, then we must use the popping versions
419 even if the call has no arguments to pop. */
420 #if defined (HAVE_call) && defined (HAVE_call_value)
421 if (HAVE_call && HAVE_call_value && HAVE_call_pop && HAVE_call_value_pop
424 if (HAVE_call_pop && HAVE_call_value_pop)
427 rtx n_pop = GEN_INT (n_popped);
430 /* If this subroutine pops its own args, record that in the call insn
431 if possible, for the sake of frame pointer elimination. */
434 pat = gen_call_value_pop (valreg,
435 gen_rtx_MEM (FUNCTION_MODE, funexp),
436 rounded_stack_size_rtx, next_arg_reg, n_pop);
438 pat = gen_call_pop (gen_rtx_MEM (FUNCTION_MODE, funexp),
439 rounded_stack_size_rtx, next_arg_reg, n_pop);
441 emit_call_insn (pat);
448 #if defined (HAVE_call) && defined (HAVE_call_value)
449 if (HAVE_call && HAVE_call_value)
452 emit_call_insn (gen_call_value (valreg,
453 gen_rtx_MEM (FUNCTION_MODE, funexp),
454 rounded_stack_size_rtx, next_arg_reg,
457 emit_call_insn (gen_call (gen_rtx_MEM (FUNCTION_MODE, funexp),
458 rounded_stack_size_rtx, next_arg_reg,
459 struct_value_size_rtx));
465 /* Find the CALL insn we just emitted. */
466 for (call_insn = get_last_insn ();
467 call_insn && GET_CODE (call_insn) != CALL_INSN;
468 call_insn = PREV_INSN (call_insn))
474 /* Put the register usage information on the CALL. If there is already
475 some usage information, put ours at the end. */
476 if (CALL_INSN_FUNCTION_USAGE (call_insn))
480 for (link = CALL_INSN_FUNCTION_USAGE (call_insn); XEXP (link, 1) != 0;
481 link = XEXP (link, 1))
484 XEXP (link, 1) = call_fusage;
487 CALL_INSN_FUNCTION_USAGE (call_insn) = call_fusage;
489 /* If this is a const call, then set the insn's unchanging bit. */
491 CONST_CALL_P (call_insn) = 1;
493 /* Restore this now, so that we do defer pops for this call's args
494 if the context of the call as a whole permits. */
495 inhibit_defer_pop = old_inhibit_defer_pop;
497 #ifndef ACCUMULATE_OUTGOING_ARGS
498 /* If returning from the subroutine does not automatically pop the args,
499 we need an instruction to pop them sooner or later.
500 Perhaps do it now; perhaps just record how much space to pop later.
502 If returning from the subroutine does pop the args, indicate that the
503 stack pointer will be changed. */
508 CALL_INSN_FUNCTION_USAGE (call_insn)
509 = gen_rtx_EXPR_LIST (VOIDmode,
510 gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx),
511 CALL_INSN_FUNCTION_USAGE (call_insn));
512 rounded_stack_size -= n_popped;
513 rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
516 if (rounded_stack_size != 0)
518 if (flag_defer_pop && inhibit_defer_pop == 0 && !is_const)
519 pending_stack_adjust += rounded_stack_size;
521 adjust_stack (rounded_stack_size_rtx);
526 /* Determine if the function identified by NAME and FNDECL is one with
527 special properties we wish to know about.
529 For example, if the function might return more than one time (setjmp), then
530 set RETURNS_TWICE to a nonzero value.
532 Similarly set IS_LONGJMP for if the function is in the longjmp family.
534 Set IS_MALLOC for any of the standard memory allocation functions which
535 allocate from the heap.
537 Set MAY_BE_ALLOCA for any memory allocation function that might allocate
538 space from the stack such as alloca. */
541 special_function_p (fndecl, returns_twice, is_longjmp, fork_or_exec,
542 is_malloc, may_be_alloca)
555 /* The function decl may have the `malloc' attribute. */
556 *is_malloc = fndecl && DECL_IS_MALLOC (fndecl);
559 && fndecl && DECL_NAME (fndecl)
560 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 17
561 /* Exclude functions not at the file scope, or not `extern',
562 since they are not the magic functions we would otherwise
564 && DECL_CONTEXT (fndecl) == NULL_TREE && TREE_PUBLIC (fndecl))
566 char *name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
569 /* We assume that alloca will always be called by name. It
570 makes no sense to pass it as a pointer-to-function to
571 anything that does not understand its behavior. */
573 = (((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 6
575 && ! strcmp (name, "alloca"))
576 || (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 16
578 && ! strcmp (name, "__builtin_alloca"))));
580 /* Disregard prefix _, __ or __x. */
583 if (name[1] == '_' && name[2] == 'x')
585 else if (name[1] == '_')
595 && (! strcmp (tname, "setjmp")
596 || ! strcmp (tname, "setjmp_syscall")))
598 && ! strcmp (tname, "sigsetjmp"))
600 && ! strcmp (tname, "savectx")));
602 && ! strcmp (tname, "siglongjmp"))
605 else if ((tname[0] == 'q' && tname[1] == 's'
606 && ! strcmp (tname, "qsetjmp"))
607 || (tname[0] == 'v' && tname[1] == 'f'
608 && ! strcmp (tname, "vfork")))
611 else if (tname[0] == 'l' && tname[1] == 'o'
612 && ! strcmp (tname, "longjmp"))
615 else if ((tname[0] == 'f' && tname[1] == 'o'
616 && ! strcmp (tname, "fork"))
617 /* Linux specific: __clone. check NAME to insist on the
618 leading underscores, to avoid polluting the ISO / POSIX
620 || (name[0] == '_' && name[1] == '_'
621 && ! strcmp (tname, "clone"))
622 || (tname[0] == 'e' && tname[1] == 'x' && tname[2] == 'e'
623 && tname[3] == 'c' && (tname[4] == 'l' || tname[4] == 'v')
625 || ((tname[5] == 'p' || tname[5] == 'e')
626 && tname[6] == '\0'))))
629 /* Do not add any more malloc-like functions to this list,
630 instead mark them as malloc functions using the malloc attribute.
631 Note, realloc is not suitable for attribute malloc since
632 it may return the same address across multiple calls. */
633 else if (! strcmp (tname, "malloc")
634 || ! strcmp (tname, "calloc")
635 || ! strcmp (tname, "strdup")
636 /* Note use of NAME rather than TNAME here. These functions
637 are only reserved when preceded with __. */
638 || ! strcmp (name, "__vn") /* mangled __builtin_vec_new */
639 || ! strcmp (name, "__nw") /* mangled __builtin_new */
640 || ! strcmp (name, "__builtin_new")
641 || ! strcmp (name, "__builtin_vec_new"))
646 /* Precompute all register parameters as described by ARGS, storing values
647 into fields within the ARGS array.
649 NUM_ACTUALS indicates the total number elements in the ARGS array.
651 Set REG_PARM_SEEN if we encounter a register parameter. */
654 precompute_register_parameters (num_actuals, args, reg_parm_seen)
656 struct arg_data *args;
663 for (i = 0; i < num_actuals; i++)
664 if (args[i].reg != 0 && ! args[i].pass_on_stack)
668 if (args[i].value == 0)
671 args[i].value = expand_expr (args[i].tree_value, NULL_RTX,
673 preserve_temp_slots (args[i].value);
676 /* ANSI doesn't require a sequence point here,
677 but PCC has one, so this will avoid some problems. */
681 /* If we are to promote the function arg to a wider mode,
684 if (args[i].mode != TYPE_MODE (TREE_TYPE (args[i].tree_value)))
686 = convert_modes (args[i].mode,
687 TYPE_MODE (TREE_TYPE (args[i].tree_value)),
688 args[i].value, args[i].unsignedp);
690 /* If the value is expensive, and we are inside an appropriately
691 short loop, put the value into a pseudo and then put the pseudo
694 For small register classes, also do this if this call uses
695 register parameters. This is to avoid reload conflicts while
696 loading the parameters registers. */
698 if ((! (GET_CODE (args[i].value) == REG
699 || (GET_CODE (args[i].value) == SUBREG
700 && GET_CODE (SUBREG_REG (args[i].value)) == REG)))
701 && args[i].mode != BLKmode
702 && rtx_cost (args[i].value, SET) > 2
703 && ((SMALL_REGISTER_CLASSES && *reg_parm_seen)
704 || preserve_subexpressions_p ()))
705 args[i].value = copy_to_mode_reg (args[i].mode, args[i].value);
709 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
711 /* The argument list is the property of the called routine and it
712 may clobber it. If the fixed area has been used for previous
713 parameters, we must save and restore it. */
715 save_fixed_argument_area (reg_parm_stack_space, argblock,
716 low_to_save, high_to_save)
717 int reg_parm_stack_space;
723 rtx save_area = NULL_RTX;
725 /* Compute the boundary of the that needs to be saved, if any. */
726 #ifdef ARGS_GROW_DOWNWARD
727 for (i = 0; i < reg_parm_stack_space + 1; i++)
729 for (i = 0; i < reg_parm_stack_space; i++)
732 if (i >= highest_outgoing_arg_in_use
733 || stack_usage_map[i] == 0)
736 if (*low_to_save == -1)
742 if (*low_to_save >= 0)
744 int num_to_save = *high_to_save - *low_to_save + 1;
745 enum machine_mode save_mode
746 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
749 /* If we don't have the required alignment, must do this in BLKmode. */
750 if ((*low_to_save & (MIN (GET_MODE_SIZE (save_mode),
751 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
754 #ifdef ARGS_GROW_DOWNWARD
755 stack_area = gen_rtx_MEM (save_mode,
756 memory_address (save_mode,
757 plus_constant (argblock,
760 stack_area = gen_rtx_MEM (save_mode,
761 memory_address (save_mode,
762 plus_constant (argblock,
765 if (save_mode == BLKmode)
767 save_area = assign_stack_temp (BLKmode, num_to_save, 0);
768 /* Cannot use emit_block_move here because it can be done by a library
769 call which in turn gets into this place again and deadly infinite
770 recursion happens. */
771 move_by_pieces (validize_mem (save_area), stack_area, num_to_save,
772 PARM_BOUNDARY / BITS_PER_UNIT);
776 save_area = gen_reg_rtx (save_mode);
777 emit_move_insn (save_area, stack_area);
784 restore_fixed_argument_area (save_area, argblock, high_to_save, low_to_save)
790 enum machine_mode save_mode = GET_MODE (save_area);
791 #ifdef ARGS_GROW_DOWNWARD
793 = gen_rtx_MEM (save_mode,
794 memory_address (save_mode,
795 plus_constant (argblock,
799 = gen_rtx_MEM (save_mode,
800 memory_address (save_mode,
801 plus_constant (argblock,
805 if (save_mode != BLKmode)
806 emit_move_insn (stack_area, save_area);
808 /* Cannot use emit_block_move here because it can be done by a library
809 call which in turn gets into this place again and deadly infinite
810 recursion happens. */
811 move_by_pieces (stack_area, validize_mem (save_area),
812 high_to_save - low_to_save + 1,
813 PARM_BOUNDARY / BITS_PER_UNIT);
817 /* If any elements in ARGS refer to parameters that are to be passed in
818 registers, but not in memory, and whose alignment does not permit a
819 direct copy into registers. Copy the values into a group of pseudos
820 which we will later copy into the appropriate hard registers.
822 Pseudos for each unaligned argument will be stored into the array
823 args[argnum].aligned_regs. The caller is responsible for deallocating
824 the aligned_regs array if it is nonzero. */
827 store_unaligned_arguments_into_pseudos (args, num_actuals)
828 struct arg_data *args;
833 for (i = 0; i < num_actuals; i++)
834 if (args[i].reg != 0 && ! args[i].pass_on_stack
835 && args[i].mode == BLKmode
836 && (TYPE_ALIGN (TREE_TYPE (args[i].tree_value))
837 < (unsigned int) MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD)))
839 int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
840 int big_endian_correction = 0;
842 args[i].n_aligned_regs
843 = args[i].partial ? args[i].partial
844 : (bytes + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
846 args[i].aligned_regs = (rtx *) xmalloc (sizeof (rtx)
847 * args[i].n_aligned_regs);
849 /* Structures smaller than a word are aligned to the least
850 significant byte (to the right). On a BYTES_BIG_ENDIAN machine,
851 this means we must skip the empty high order bytes when
852 calculating the bit offset. */
853 if (BYTES_BIG_ENDIAN && bytes < UNITS_PER_WORD)
854 big_endian_correction = (BITS_PER_WORD - (bytes * BITS_PER_UNIT));
856 for (j = 0; j < args[i].n_aligned_regs; j++)
858 rtx reg = gen_reg_rtx (word_mode);
859 rtx word = operand_subword_force (args[i].value, j, BLKmode);
860 int bitsize = MIN (bytes * BITS_PER_UNIT, BITS_PER_WORD);
861 int bitalign = TYPE_ALIGN (TREE_TYPE (args[i].tree_value));
863 args[i].aligned_regs[j] = reg;
865 /* There is no need to restrict this code to loading items
866 in TYPE_ALIGN sized hunks. The bitfield instructions can
867 load up entire word sized registers efficiently.
869 ??? This may not be needed anymore.
870 We use to emit a clobber here but that doesn't let later
871 passes optimize the instructions we emit. By storing 0 into
872 the register later passes know the first AND to zero out the
873 bitfield being set in the register is unnecessary. The store
874 of 0 will be deleted as will at least the first AND. */
876 emit_move_insn (reg, const0_rtx);
878 bytes -= bitsize / BITS_PER_UNIT;
879 store_bit_field (reg, bitsize, big_endian_correction, word_mode,
880 extract_bit_field (word, bitsize, 0, 1,
883 bitalign / BITS_PER_UNIT,
885 bitalign / BITS_PER_UNIT, BITS_PER_WORD);
890 /* Fill in ARGS_SIZE and ARGS array based on the parameters found in
893 NUM_ACTUALS is the total number of parameters.
895 N_NAMED_ARGS is the total number of named arguments.
897 FNDECL is the tree code for the target of this call (if known)
899 ARGS_SO_FAR holds state needed by the target to know where to place
902 REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
903 for arguments which are passed in registers.
905 OLD_STACK_LEVEL is a pointer to an rtx which olds the old stack level
906 and may be modified by this routine.
908 OLD_PENDING_ADJ, MUST_PREALLOCATE and IS_CONST are pointers to integer
909 flags which may may be modified by this routine. */
912 initialize_argument_information (num_actuals, args, args_size, n_named_args,
913 actparms, fndecl, args_so_far,
914 reg_parm_stack_space, old_stack_level,
915 old_pending_adj, must_preallocate, is_const)
916 int num_actuals ATTRIBUTE_UNUSED;
917 struct arg_data *args;
918 struct args_size *args_size;
919 int n_named_args ATTRIBUTE_UNUSED;
922 CUMULATIVE_ARGS *args_so_far;
923 int reg_parm_stack_space;
924 rtx *old_stack_level;
925 int *old_pending_adj;
926 int *must_preallocate;
929 /* 1 if scanning parms front to back, -1 if scanning back to front. */
932 /* Count arg position in order args appear. */
935 struct args_size alignment_pad;
939 args_size->constant = 0;
942 /* In this loop, we consider args in the order they are written.
943 We fill up ARGS from the front or from the back if necessary
944 so that in any case the first arg to be pushed ends up at the front. */
946 #ifdef PUSH_ARGS_REVERSED
947 i = num_actuals - 1, inc = -1;
948 /* In this case, must reverse order of args
949 so that we compute and push the last arg first. */
954 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
955 for (p = actparms, argpos = 0; p; p = TREE_CHAIN (p), i += inc, argpos++)
957 tree type = TREE_TYPE (TREE_VALUE (p));
959 enum machine_mode mode;
961 args[i].tree_value = TREE_VALUE (p);
963 /* Replace erroneous argument with constant zero. */
964 if (type == error_mark_node || TYPE_SIZE (type) == 0)
965 args[i].tree_value = integer_zero_node, type = integer_type_node;
967 /* If TYPE is a transparent union, pass things the way we would
968 pass the first field of the union. We have already verified that
969 the modes are the same. */
970 if (TYPE_TRANSPARENT_UNION (type))
971 type = TREE_TYPE (TYPE_FIELDS (type));
973 /* Decide where to pass this arg.
975 args[i].reg is nonzero if all or part is passed in registers.
977 args[i].partial is nonzero if part but not all is passed in registers,
978 and the exact value says how many words are passed in registers.
980 args[i].pass_on_stack is nonzero if the argument must at least be
981 computed on the stack. It may then be loaded back into registers
982 if args[i].reg is nonzero.
984 These decisions are driven by the FUNCTION_... macros and must agree
985 with those made by function.c. */
987 /* See if this argument should be passed by invisible reference. */
988 if ((TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
989 && contains_placeholder_p (TYPE_SIZE (type)))
990 || TREE_ADDRESSABLE (type)
991 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
992 || FUNCTION_ARG_PASS_BY_REFERENCE (*args_so_far, TYPE_MODE (type),
993 type, argpos < n_named_args)
997 /* If we're compiling a thunk, pass through invisible
998 references instead of making a copy. */
999 if (current_function_is_thunk
1000 #ifdef FUNCTION_ARG_CALLEE_COPIES
1001 || (FUNCTION_ARG_CALLEE_COPIES (*args_so_far, TYPE_MODE (type),
1002 type, argpos < n_named_args)
1003 /* If it's in a register, we must make a copy of it too. */
1004 /* ??? Is this a sufficient test? Is there a better one? */
1005 && !(TREE_CODE (args[i].tree_value) == VAR_DECL
1006 && REG_P (DECL_RTL (args[i].tree_value)))
1007 && ! TREE_ADDRESSABLE (type))
1011 /* C++ uses a TARGET_EXPR to indicate that we want to make a
1012 new object from the argument. If we are passing by
1013 invisible reference, the callee will do that for us, so we
1014 can strip off the TARGET_EXPR. This is not always safe,
1015 but it is safe in the only case where this is a useful
1016 optimization; namely, when the argument is a plain object.
1017 In that case, the frontend is just asking the backend to
1018 make a bitwise copy of the argument. */
1020 if (TREE_CODE (args[i].tree_value) == TARGET_EXPR
1021 && (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND
1022 (args[i].tree_value, 1)))
1024 && ! REG_P (DECL_RTL (TREE_OPERAND (args[i].tree_value, 1))))
1025 args[i].tree_value = TREE_OPERAND (args[i].tree_value, 1);
1027 args[i].tree_value = build1 (ADDR_EXPR,
1028 build_pointer_type (type),
1029 args[i].tree_value);
1030 type = build_pointer_type (type);
1034 /* We make a copy of the object and pass the address to the
1035 function being called. */
1038 if (TYPE_SIZE (type) == 0
1039 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
1040 || (flag_stack_check && ! STACK_CHECK_BUILTIN
1041 && (TREE_INT_CST_HIGH (TYPE_SIZE (type)) != 0
1042 || (TREE_INT_CST_LOW (TYPE_SIZE (type))
1043 > STACK_CHECK_MAX_VAR_SIZE * BITS_PER_UNIT))))
1045 /* This is a variable-sized object. Make space on the stack
1047 rtx size_rtx = expr_size (TREE_VALUE (p));
1049 if (*old_stack_level == 0)
1051 emit_stack_save (SAVE_BLOCK, old_stack_level, NULL_RTX);
1052 *old_pending_adj = pending_stack_adjust;
1053 pending_stack_adjust = 0;
1056 copy = gen_rtx_MEM (BLKmode,
1057 allocate_dynamic_stack_space (size_rtx,
1059 TYPE_ALIGN (type)));
1063 int size = int_size_in_bytes (type);
1064 copy = assign_stack_temp (TYPE_MODE (type), size, 0);
1067 MEM_SET_IN_STRUCT_P (copy, AGGREGATE_TYPE_P (type));
1069 store_expr (args[i].tree_value, copy, 0);
1072 args[i].tree_value = build1 (ADDR_EXPR,
1073 build_pointer_type (type),
1074 make_tree (type, copy));
1075 type = build_pointer_type (type);
1079 mode = TYPE_MODE (type);
1080 unsignedp = TREE_UNSIGNED (type);
1082 #ifdef PROMOTE_FUNCTION_ARGS
1083 mode = promote_mode (type, mode, &unsignedp, 1);
1086 args[i].unsignedp = unsignedp;
1087 args[i].mode = mode;
1088 args[i].reg = FUNCTION_ARG (*args_so_far, mode, type,
1089 argpos < n_named_args);
1090 #ifdef FUNCTION_ARG_PARTIAL_NREGS
1093 = FUNCTION_ARG_PARTIAL_NREGS (*args_so_far, mode, type,
1094 argpos < n_named_args);
1097 args[i].pass_on_stack = MUST_PASS_IN_STACK (mode, type);
1099 /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1100 it means that we are to pass this arg in the register(s) designated
1101 by the PARALLEL, but also to pass it in the stack. */
1102 if (args[i].reg && GET_CODE (args[i].reg) == PARALLEL
1103 && XEXP (XVECEXP (args[i].reg, 0, 0), 0) == 0)
1104 args[i].pass_on_stack = 1;
1106 /* If this is an addressable type, we must preallocate the stack
1107 since we must evaluate the object into its final location.
1109 If this is to be passed in both registers and the stack, it is simpler
1111 if (TREE_ADDRESSABLE (type)
1112 || (args[i].pass_on_stack && args[i].reg != 0))
1113 *must_preallocate = 1;
1115 /* If this is an addressable type, we cannot pre-evaluate it. Thus,
1116 we cannot consider this function call constant. */
1117 if (TREE_ADDRESSABLE (type))
1120 /* Compute the stack-size of this argument. */
1121 if (args[i].reg == 0 || args[i].partial != 0
1122 || reg_parm_stack_space > 0
1123 || args[i].pass_on_stack)
1124 locate_and_pad_parm (mode, type,
1125 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1130 fndecl, args_size, &args[i].offset,
1131 &args[i].size, &alignment_pad);
1133 #ifndef ARGS_GROW_DOWNWARD
1134 args[i].slot_offset = *args_size;
1137 args[i].alignment_pad = alignment_pad;
1139 /* If a part of the arg was put into registers,
1140 don't include that part in the amount pushed. */
1141 if (reg_parm_stack_space == 0 && ! args[i].pass_on_stack)
1142 args[i].size.constant -= ((args[i].partial * UNITS_PER_WORD)
1143 / (PARM_BOUNDARY / BITS_PER_UNIT)
1144 * (PARM_BOUNDARY / BITS_PER_UNIT));
1146 /* Update ARGS_SIZE, the total stack space for args so far. */
1148 args_size->constant += args[i].size.constant;
1149 if (args[i].size.var)
1151 ADD_PARM_SIZE (*args_size, args[i].size.var);
1154 /* Since the slot offset points to the bottom of the slot,
1155 we must record it after incrementing if the args grow down. */
1156 #ifdef ARGS_GROW_DOWNWARD
1157 args[i].slot_offset = *args_size;
1159 args[i].slot_offset.constant = -args_size->constant;
1162 SUB_PARM_SIZE (args[i].slot_offset, args_size->var);
1166 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1167 have been used, etc. */
1169 FUNCTION_ARG_ADVANCE (*args_so_far, TYPE_MODE (type), type,
1170 argpos < n_named_args);
1174 /* Update ARGS_SIZE to contain the total size for the argument block.
1175 Return the original constant component of the argument block's size.
1177 REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
1178 for arguments passed in registers. */
1181 compute_argument_block_size (reg_parm_stack_space, args_size,
1182 preferred_stack_boundary)
1183 int reg_parm_stack_space;
1184 struct args_size *args_size;
1185 int preferred_stack_boundary ATTRIBUTE_UNUSED;
1187 int unadjusted_args_size = args_size->constant;
1189 /* Compute the actual size of the argument block required. The variable
1190 and constant sizes must be combined, the size may have to be rounded,
1191 and there may be a minimum required size. */
1195 args_size->var = ARGS_SIZE_TREE (*args_size);
1196 args_size->constant = 0;
1198 #ifdef PREFERRED_STACK_BOUNDARY
1199 preferred_stack_boundary /= BITS_PER_UNIT;
1200 if (preferred_stack_boundary > 1)
1201 args_size->var = round_up (args_size->var, preferred_stack_boundary);
1204 if (reg_parm_stack_space > 0)
1207 = size_binop (MAX_EXPR, args_size->var,
1208 size_int (reg_parm_stack_space));
1210 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1211 /* The area corresponding to register parameters is not to count in
1212 the size of the block we need. So make the adjustment. */
1214 = size_binop (MINUS_EXPR, args_size->var,
1215 size_int (reg_parm_stack_space));
1221 #ifdef PREFERRED_STACK_BOUNDARY
1222 preferred_stack_boundary /= BITS_PER_UNIT;
1223 args_size->constant = (((args_size->constant
1224 + pending_stack_adjust
1225 + preferred_stack_boundary - 1)
1226 / preferred_stack_boundary
1227 * preferred_stack_boundary)
1228 - pending_stack_adjust);
1231 args_size->constant = MAX (args_size->constant,
1232 reg_parm_stack_space);
1234 #ifdef MAYBE_REG_PARM_STACK_SPACE
1235 if (reg_parm_stack_space == 0)
1236 args_size->constant = 0;
1239 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1240 args_size->constant -= reg_parm_stack_space;
1243 return unadjusted_args_size;
1246 /* Precompute parameters as needed for a function call.
1248 IS_CONST indicates the target function is a pure function.
1250 MUST_PREALLOCATE indicates that we must preallocate stack space for
1251 any stack arguments.
1253 NUM_ACTUALS is the number of arguments.
1255 ARGS is an array containing information for each argument; this routine
1256 fills in the INITIAL_VALUE and VALUE fields for each precomputed argument.
1258 ARGS_SIZE contains information about the size of the arg list. */
1261 precompute_arguments (is_const, must_preallocate, num_actuals, args, args_size)
1263 int must_preallocate;
1265 struct arg_data *args;
1266 struct args_size *args_size;
1270 /* If this function call is cse'able, precompute all the parameters.
1271 Note that if the parameter is constructed into a temporary, this will
1272 cause an additional copy because the parameter will be constructed
1273 into a temporary location and then copied into the outgoing arguments.
1274 If a parameter contains a call to alloca and this function uses the
1275 stack, precompute the parameter. */
1277 /* If we preallocated the stack space, and some arguments must be passed
1278 on the stack, then we must precompute any parameter which contains a
1279 function call which will store arguments on the stack.
1280 Otherwise, evaluating the parameter may clobber previous parameters
1281 which have already been stored into the stack. */
1283 for (i = 0; i < num_actuals; i++)
1285 || ((args_size->var != 0 || args_size->constant != 0)
1286 && calls_function (args[i].tree_value, 1))
1287 || (must_preallocate
1288 && (args_size->var != 0 || args_size->constant != 0)
1289 && calls_function (args[i].tree_value, 0)))
1291 /* If this is an addressable type, we cannot pre-evaluate it. */
1292 if (TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value)))
1298 = expand_expr (args[i].tree_value, NULL_RTX, VOIDmode, 0);
1300 preserve_temp_slots (args[i].value);
1303 /* ANSI doesn't require a sequence point here,
1304 but PCC has one, so this will avoid some problems. */
1307 args[i].initial_value = args[i].value
1308 = protect_from_queue (args[i].value, 0);
1310 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) != args[i].mode)
1313 = convert_modes (args[i].mode,
1314 TYPE_MODE (TREE_TYPE (args[i].tree_value)),
1315 args[i].value, args[i].unsignedp);
1316 #ifdef PROMOTE_FOR_CALL_ONLY
1317 /* CSE will replace this only if it contains args[i].value
1318 pseudo, so convert it down to the declared mode using
1320 if (GET_CODE (args[i].value) == REG
1321 && GET_MODE_CLASS (args[i].mode) == MODE_INT)
1323 args[i].initial_value
1324 = gen_rtx_SUBREG (TYPE_MODE (TREE_TYPE (args[i].tree_value)),
1326 SUBREG_PROMOTED_VAR_P (args[i].initial_value) = 1;
1327 SUBREG_PROMOTED_UNSIGNED_P (args[i].initial_value)
1328 = args[i].unsignedp;
1335 /* Given the current state of MUST_PREALLOCATE and information about
1336 arguments to a function call in NUM_ACTUALS, ARGS and ARGS_SIZE,
1337 compute and return the final value for MUST_PREALLOCATE. */
1340 finalize_must_preallocate (must_preallocate, num_actuals, args, args_size)
1341 int must_preallocate;
1343 struct arg_data *args;
1344 struct args_size *args_size;
1346 /* See if we have or want to preallocate stack space.
1348 If we would have to push a partially-in-regs parm
1349 before other stack parms, preallocate stack space instead.
1351 If the size of some parm is not a multiple of the required stack
1352 alignment, we must preallocate.
1354 If the total size of arguments that would otherwise create a copy in
1355 a temporary (such as a CALL) is more than half the total argument list
1356 size, preallocation is faster.
1358 Another reason to preallocate is if we have a machine (like the m88k)
1359 where stack alignment is required to be maintained between every
1360 pair of insns, not just when the call is made. However, we assume here
1361 that such machines either do not have push insns (and hence preallocation
1362 would occur anyway) or the problem is taken care of with
1365 if (! must_preallocate)
1367 int partial_seen = 0;
1368 int copy_to_evaluate_size = 0;
1371 for (i = 0; i < num_actuals && ! must_preallocate; i++)
1373 if (args[i].partial > 0 && ! args[i].pass_on_stack)
1375 else if (partial_seen && args[i].reg == 0)
1376 must_preallocate = 1;
1378 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1379 && (TREE_CODE (args[i].tree_value) == CALL_EXPR
1380 || TREE_CODE (args[i].tree_value) == TARGET_EXPR
1381 || TREE_CODE (args[i].tree_value) == COND_EXPR
1382 || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
1383 copy_to_evaluate_size
1384 += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1387 if (copy_to_evaluate_size * 2 >= args_size->constant
1388 && args_size->constant > 0)
1389 must_preallocate = 1;
1391 return must_preallocate;
1394 /* If we preallocated stack space, compute the address of each argument
1395 and store it into the ARGS array.
1397 We need not ensure it is a valid memory address here; it will be
1398 validized when it is used.
1400 ARGBLOCK is an rtx for the address of the outgoing arguments. */
1403 compute_argument_addresses (args, argblock, num_actuals)
1404 struct arg_data *args;
1410 rtx arg_reg = argblock;
1411 int i, arg_offset = 0;
1413 if (GET_CODE (argblock) == PLUS)
1414 arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
1416 for (i = 0; i < num_actuals; i++)
1418 rtx offset = ARGS_SIZE_RTX (args[i].offset);
1419 rtx slot_offset = ARGS_SIZE_RTX (args[i].slot_offset);
1422 /* Skip this parm if it will not be passed on the stack. */
1423 if (! args[i].pass_on_stack && args[i].reg != 0)
1426 if (GET_CODE (offset) == CONST_INT)
1427 addr = plus_constant (arg_reg, INTVAL (offset));
1429 addr = gen_rtx_PLUS (Pmode, arg_reg, offset);
1431 addr = plus_constant (addr, arg_offset);
1432 args[i].stack = gen_rtx_MEM (args[i].mode, addr);
1435 AGGREGATE_TYPE_P (TREE_TYPE (args[i].tree_value)));
1437 if (GET_CODE (slot_offset) == CONST_INT)
1438 addr = plus_constant (arg_reg, INTVAL (slot_offset));
1440 addr = gen_rtx_PLUS (Pmode, arg_reg, slot_offset);
1442 addr = plus_constant (addr, arg_offset);
1443 args[i].stack_slot = gen_rtx_MEM (args[i].mode, addr);
1448 /* Given a FNDECL and EXP, return an rtx suitable for use as a target address
1449 in a call instruction.
1451 FNDECL is the tree node for the target function. For an indirect call
1452 FNDECL will be NULL_TREE.
1454 EXP is the CALL_EXPR for this call. */
1457 rtx_for_function_call (fndecl, exp)
1463 /* Get the function to call, in the form of RTL. */
1466 /* If this is the first use of the function, see if we need to
1467 make an external definition for it. */
1468 if (! TREE_USED (fndecl))
1470 assemble_external (fndecl);
1471 TREE_USED (fndecl) = 1;
1474 /* Get a SYMBOL_REF rtx for the function address. */
1475 funexp = XEXP (DECL_RTL (fndecl), 0);
1478 /* Generate an rtx (probably a pseudo-register) for the address. */
1483 expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
1484 pop_temp_slots (); /* FUNEXP can't be BLKmode */
1486 /* Check the function is executable. */
1487 if (current_function_check_memory_usage)
1489 #ifdef POINTERS_EXTEND_UNSIGNED
1490 /* It might be OK to convert funexp in place, but there's
1491 a lot going on between here and when it happens naturally
1492 that this seems safer. */
1493 funaddr = convert_memory_address (Pmode, funexp);
1495 emit_library_call (chkr_check_exec_libfunc, 1,
1504 /* Do the register loads required for any wholly-register parms or any
1505 parms which are passed both on the stack and in a register. Their
1506 expressions were already evaluated.
1508 Mark all register-parms as living through the call, putting these USE
1509 insns in the CALL_INSN_FUNCTION_USAGE field. */
1512 load_register_parameters (args, num_actuals, call_fusage)
1513 struct arg_data *args;
1519 #ifdef LOAD_ARGS_REVERSED
1520 for (i = num_actuals - 1; i >= 0; i--)
1522 for (i = 0; i < num_actuals; i++)
1525 rtx reg = args[i].reg;
1526 int partial = args[i].partial;
1531 /* Set to non-negative if must move a word at a time, even if just
1532 one word (e.g, partial == 1 && mode == DFmode). Set to -1 if
1533 we just use a normal move insn. This value can be zero if the
1534 argument is a zero size structure with no fields. */
1535 nregs = (partial ? partial
1536 : (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1537 ? ((int_size_in_bytes (TREE_TYPE (args[i].tree_value))
1538 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
1541 /* Handle calls that pass values in multiple non-contiguous
1542 locations. The Irix 6 ABI has examples of this. */
1544 if (GET_CODE (reg) == PARALLEL)
1546 emit_group_load (reg, args[i].value,
1547 int_size_in_bytes (TREE_TYPE (args[i].tree_value)),
1548 (TYPE_ALIGN (TREE_TYPE (args[i].tree_value))
1552 /* If simple case, just do move. If normal partial, store_one_arg
1553 has already loaded the register for us. In all other cases,
1554 load the register(s) from memory. */
1556 else if (nregs == -1)
1557 emit_move_insn (reg, args[i].value);
1559 /* If we have pre-computed the values to put in the registers in
1560 the case of non-aligned structures, copy them in now. */
1562 else if (args[i].n_aligned_regs != 0)
1563 for (j = 0; j < args[i].n_aligned_regs; j++)
1564 emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg) + j),
1565 args[i].aligned_regs[j]);
1567 else if (partial == 0 || args[i].pass_on_stack)
1568 move_block_to_reg (REGNO (reg),
1569 validize_mem (args[i].value), nregs,
1572 /* Handle calls that pass values in multiple non-contiguous
1573 locations. The Irix 6 ABI has examples of this. */
1574 if (GET_CODE (reg) == PARALLEL)
1575 use_group_regs (call_fusage, reg);
1576 else if (nregs == -1)
1577 use_reg (call_fusage, reg);
1579 use_regs (call_fusage, REGNO (reg), nregs == 0 ? 1 : nregs);
1584 /* Generate all the code for a function call
1585 and return an rtx for its value.
1586 Store the value in TARGET (specified as an rtx) if convenient.
1587 If the value is stored in TARGET then TARGET is returned.
1588 If IGNORE is nonzero, then we ignore the value of the function call. */
1591 expand_call (exp, target, ignore)
1596 /* List of actual parameters. */
1597 tree actparms = TREE_OPERAND (exp, 1);
1598 /* RTX for the function to be called. */
1600 /* Data type of the function. */
1602 /* Declaration of the function being called,
1603 or 0 if the function is computed (not known by name). */
1608 /* Register in which non-BLKmode value will be returned,
1609 or 0 if no value or if value is BLKmode. */
1611 /* Address where we should return a BLKmode value;
1612 0 if value not BLKmode. */
1613 rtx structure_value_addr = 0;
1614 /* Nonzero if that address is being passed by treating it as
1615 an extra, implicit first parameter. Otherwise,
1616 it is passed by being copied directly into struct_value_rtx. */
1617 int structure_value_addr_parm = 0;
1618 /* Size of aggregate value wanted, or zero if none wanted
1619 or if we are using the non-reentrant PCC calling convention
1620 or expecting the value in registers. */
1621 HOST_WIDE_INT struct_value_size = 0;
1622 /* Nonzero if called function returns an aggregate in memory PCC style,
1623 by returning the address of where to find it. */
1624 int pcc_struct_value = 0;
1626 /* Number of actual parameters in this call, including struct value addr. */
1628 /* Number of named args. Args after this are anonymous ones
1629 and they must all go on the stack. */
1632 /* Vector of information about each argument.
1633 Arguments are numbered in the order they will be pushed,
1634 not the order they are written. */
1635 struct arg_data *args;
1637 /* Total size in bytes of all the stack-parms scanned so far. */
1638 struct args_size args_size;
1639 /* Size of arguments before any adjustments (such as rounding). */
1640 int unadjusted_args_size;
1641 /* Data on reg parms scanned so far. */
1642 CUMULATIVE_ARGS args_so_far;
1643 /* Nonzero if a reg parm has been scanned. */
1645 /* Nonzero if this is an indirect function call. */
1647 /* Nonzero if we must avoid push-insns in the args for this call.
1648 If stack space is allocated for register parameters, but not by the
1649 caller, then it is preallocated in the fixed part of the stack frame.
1650 So the entire argument block must then be preallocated (i.e., we
1651 ignore PUSH_ROUNDING in that case). */
1653 #ifdef PUSH_ROUNDING
1654 int must_preallocate = 0;
1656 int must_preallocate = 1;
1659 /* Size of the stack reserved for parameter registers. */
1660 int reg_parm_stack_space = 0;
1662 /* Address of space preallocated for stack parms
1663 (on machines that lack push insns), or 0 if space not preallocated. */
1666 /* Nonzero if it is plausible that this is a call to alloca. */
1668 /* Nonzero if this is a call to malloc or a related function. */
1670 /* Nonzero if this is a call to setjmp or a related function. */
1672 /* Nonzero if this is a call to `longjmp'. */
1674 /* Nonzero if this is a syscall that makes a new process in the image of
1677 /* Nonzero if this is a call to an inline function. */
1678 int is_integrable = 0;
1679 /* Nonzero if this is a call to a `const' function.
1680 Note that only explicitly named functions are handled as `const' here. */
1682 /* Nonzero if this is a call to a `volatile' function. */
1683 int is_volatile = 0;
1684 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
1685 /* Define the boundary of the register parm stack space that needs to be
1687 int low_to_save = -1, high_to_save;
1688 rtx save_area = 0; /* Place that it is saved */
1691 #ifdef ACCUMULATE_OUTGOING_ARGS
1692 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
1693 char *initial_stack_usage_map = stack_usage_map;
1694 int old_stack_arg_under_construction = 0;
1697 rtx old_stack_level = 0;
1698 int old_pending_adj = 0;
1699 int old_inhibit_defer_pop = inhibit_defer_pop;
1700 rtx call_fusage = 0;
1703 #ifdef PREFERRED_STACK_BOUNDARY
1704 int preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
1706 /* In this case preferred_stack_boundary variable is meaningless.
1707 It is used only in order to keep ifdef noise down when calling
1708 compute_argument_block_size. */
1709 int preferred_stack_boundary = 0;
1712 /* The value of the function call can be put in a hard register. But
1713 if -fcheck-memory-usage, code which invokes functions (and thus
1714 damages some hard registers) can be inserted before using the value.
1715 So, target is always a pseudo-register in that case. */
1716 if (current_function_check_memory_usage)
1719 /* See if we can find a DECL-node for the actual function.
1720 As a result, decide whether this is a call to an integrable function. */
1722 p = TREE_OPERAND (exp, 0);
1723 if (TREE_CODE (p) == ADDR_EXPR)
1725 fndecl = TREE_OPERAND (p, 0);
1726 if (TREE_CODE (fndecl) != FUNCTION_DECL)
1731 && fndecl != current_function_decl
1732 && DECL_INLINE (fndecl)
1733 && DECL_SAVED_INSNS (fndecl)
1734 && DECL_SAVED_INSNS (fndecl)->inlinable)
1736 else if (! TREE_ADDRESSABLE (fndecl))
1738 /* In case this function later becomes inlinable,
1739 record that there was already a non-inline call to it.
1741 Use abstraction instead of setting TREE_ADDRESSABLE
1743 if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
1746 warning_with_decl (fndecl, "can't inline call to `%s'");
1747 warning ("called from here");
1749 mark_addressable (fndecl);
1752 if (TREE_READONLY (fndecl) && ! TREE_THIS_VOLATILE (fndecl)
1753 && TYPE_MODE (TREE_TYPE (exp)) != VOIDmode)
1756 if (TREE_THIS_VOLATILE (fndecl))
1761 /* If we don't have specific function to call, see if we have a
1762 constant or `noreturn' function from the type. */
1765 is_const = TREE_READONLY (TREE_TYPE (TREE_TYPE (p)));
1766 is_volatile = TREE_THIS_VOLATILE (TREE_TYPE (TREE_TYPE (p)));
1769 #ifdef REG_PARM_STACK_SPACE
1770 #ifdef MAYBE_REG_PARM_STACK_SPACE
1771 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
1773 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
1777 #if defined(PUSH_ROUNDING) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
1778 if (reg_parm_stack_space > 0)
1779 must_preallocate = 1;
1782 /* Warn if this value is an aggregate type,
1783 regardless of which calling convention we are using for it. */
1784 if (warn_aggregate_return && AGGREGATE_TYPE_P (TREE_TYPE (exp)))
1785 warning ("function call has aggregate value");
1787 /* Set up a place to return a structure. */
1789 /* Cater to broken compilers. */
1790 if (aggregate_value_p (exp))
1792 /* This call returns a big structure. */
1795 #ifdef PCC_STATIC_STRUCT_RETURN
1797 pcc_struct_value = 1;
1798 /* Easier than making that case work right. */
1801 /* In case this is a static function, note that it has been
1803 if (! TREE_ADDRESSABLE (fndecl))
1804 mark_addressable (fndecl);
1808 #else /* not PCC_STATIC_STRUCT_RETURN */
1810 struct_value_size = int_size_in_bytes (TREE_TYPE (exp));
1812 if (target && GET_CODE (target) == MEM)
1813 structure_value_addr = XEXP (target, 0);
1816 /* Assign a temporary to hold the value. */
1819 /* For variable-sized objects, we must be called with a target
1820 specified. If we were to allocate space on the stack here,
1821 we would have no way of knowing when to free it. */
1823 if (struct_value_size < 0)
1826 /* This DECL is just something to feed to mark_addressable;
1827 it doesn't get pushed. */
1828 d = build_decl (VAR_DECL, NULL_TREE, TREE_TYPE (exp));
1829 DECL_RTL (d) = assign_temp (TREE_TYPE (exp), 1, 0, 1);
1830 mark_addressable (d);
1831 mark_temp_addr_taken (DECL_RTL (d));
1832 structure_value_addr = XEXP (DECL_RTL (d), 0);
1837 #endif /* not PCC_STATIC_STRUCT_RETURN */
1840 /* If called function is inline, try to integrate it. */
1846 #ifdef ACCUMULATE_OUTGOING_ARGS
1847 before_call = get_last_insn ();
1850 temp = expand_inline_function (fndecl, actparms, target,
1851 ignore, TREE_TYPE (exp),
1852 structure_value_addr);
1854 /* If inlining succeeded, return. */
1855 if (temp != (rtx) (HOST_WIDE_INT) -1)
1857 #ifdef ACCUMULATE_OUTGOING_ARGS
1858 /* If the outgoing argument list must be preserved, push
1859 the stack before executing the inlined function if it
1862 for (i = reg_parm_stack_space - 1; i >= 0; i--)
1863 if (i < highest_outgoing_arg_in_use && stack_usage_map[i] != 0)
1866 if (stack_arg_under_construction || i >= 0)
1869 = before_call ? NEXT_INSN (before_call) : get_insns ();
1870 rtx insn = NULL_RTX, seq;
1872 /* Look for a call in the inline function code.
1873 If DECL_SAVED_INSNS (fndecl)->outgoing_args_size is
1874 nonzero then there is a call and it is not necessary
1875 to scan the insns. */
1877 if (DECL_SAVED_INSNS (fndecl)->outgoing_args_size == 0)
1878 for (insn = first_insn; insn; insn = NEXT_INSN (insn))
1879 if (GET_CODE (insn) == CALL_INSN)
1884 /* Reserve enough stack space so that the largest
1885 argument list of any function call in the inline
1886 function does not overlap the argument list being
1887 evaluated. This is usually an overestimate because
1888 allocate_dynamic_stack_space reserves space for an
1889 outgoing argument list in addition to the requested
1890 space, but there is no way to ask for stack space such
1891 that an argument list of a certain length can be
1894 Add the stack space reserved for register arguments, if
1895 any, in the inline function. What is really needed is the
1896 largest value of reg_parm_stack_space in the inline
1897 function, but that is not available. Using the current
1898 value of reg_parm_stack_space is wrong, but gives
1899 correct results on all supported machines. */
1901 int adjust = (DECL_SAVED_INSNS (fndecl)->outgoing_args_size
1902 + reg_parm_stack_space);
1905 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1906 allocate_dynamic_stack_space (GEN_INT (adjust),
1907 NULL_RTX, BITS_PER_UNIT);
1910 emit_insns_before (seq, first_insn);
1911 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
1916 /* If the result is equivalent to TARGET, return TARGET to simplify
1917 checks in store_expr. They can be equivalent but not equal in the
1918 case of a function that returns BLKmode. */
1919 if (temp != target && rtx_equal_p (temp, target))
1924 /* If inlining failed, mark FNDECL as needing to be compiled
1925 separately after all. If function was declared inline,
1927 if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
1928 && optimize > 0 && ! TREE_ADDRESSABLE (fndecl))
1930 warning_with_decl (fndecl, "inlining failed in call to `%s'");
1931 warning ("called from here");
1933 mark_addressable (fndecl);
1936 function_call_count++;
1938 if (fndecl && DECL_NAME (fndecl))
1939 name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
1941 /* Ensure current function's preferred stack boundary is at least
1942 what we need. We don't have to increase alignment for recursive
1944 if (cfun->preferred_stack_boundary < preferred_stack_boundary
1945 && fndecl != current_function_decl)
1946 cfun->preferred_stack_boundary = preferred_stack_boundary;
1948 /* See if this is a call to a function that can return more than once
1949 or a call to longjmp or malloc. */
1950 special_function_p (fndecl, &returns_twice, &is_longjmp, &fork_or_exec,
1951 &is_malloc, &may_be_alloca);
1954 current_function_calls_alloca = 1;
1956 /* Operand 0 is a pointer-to-function; get the type of the function. */
1957 funtype = TREE_TYPE (TREE_OPERAND (exp, 0));
1958 if (! POINTER_TYPE_P (funtype))
1960 funtype = TREE_TYPE (funtype);
1962 /* When calling a const function, we must pop the stack args right away,
1963 so that the pop is deleted or moved with the call. */
1967 /* Don't let pending stack adjusts add up to too much.
1968 Also, do all pending adjustments now
1969 if there is any chance this might be a call to alloca. */
1971 if (pending_stack_adjust >= 32
1972 || (pending_stack_adjust > 0 && may_be_alloca))
1973 do_pending_stack_adjust ();
1975 if (profile_arc_flag && fork_or_exec)
1977 /* A fork duplicates the profile information, and an exec discards
1978 it. We can't rely on fork/exec to be paired. So write out the
1979 profile information we have gathered so far, and clear it. */
1980 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__bb_fork_func"), 0,
1983 /* ??? When __clone is called with CLONE_VM set, profiling is
1984 subject to race conditions, just as with multithreaded programs. */
1987 /* Push the temporary stack slot level so that we can free any temporaries
1991 /* Start updating where the next arg would go.
1993 On some machines (such as the PA) indirect calls have a different
1994 calling convention than normal calls. The last argument in
1995 INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
1997 INIT_CUMULATIVE_ARGS (args_so_far, funtype, NULL_RTX, (fndecl == 0));
1999 /* If struct_value_rtx is 0, it means pass the address
2000 as if it were an extra parameter. */
2001 if (structure_value_addr && struct_value_rtx == 0)
2003 /* If structure_value_addr is a REG other than
2004 virtual_outgoing_args_rtx, we can use always use it. If it
2005 is not a REG, we must always copy it into a register.
2006 If it is virtual_outgoing_args_rtx, we must copy it to another
2007 register in some cases. */
2008 rtx temp = (GET_CODE (structure_value_addr) != REG
2009 #ifdef ACCUMULATE_OUTGOING_ARGS
2010 || (stack_arg_under_construction
2011 && structure_value_addr == virtual_outgoing_args_rtx)
2013 ? copy_addr_to_reg (structure_value_addr)
2014 : structure_value_addr);
2017 = tree_cons (error_mark_node,
2018 make_tree (build_pointer_type (TREE_TYPE (funtype)),
2021 structure_value_addr_parm = 1;
2024 /* Count the arguments and set NUM_ACTUALS. */
2025 for (p = actparms, i = 0; p; p = TREE_CHAIN (p)) i++;
2028 /* Compute number of named args.
2029 Normally, don't include the last named arg if anonymous args follow.
2030 We do include the last named arg if STRICT_ARGUMENT_NAMING is nonzero.
2031 (If no anonymous args follow, the result of list_length is actually
2032 one too large. This is harmless.)
2034 If PRETEND_OUTGOING_VARARGS_NAMED is set and STRICT_ARGUMENT_NAMING is
2035 zero, this machine will be able to place unnamed args that were passed in
2036 registers into the stack. So treat all args as named. This allows the
2037 insns emitting for a specific argument list to be independent of the
2038 function declaration.
2040 If PRETEND_OUTGOING_VARARGS_NAMED is not set, we do not have any reliable
2041 way to pass unnamed args in registers, so we must force them into
2044 if ((STRICT_ARGUMENT_NAMING
2045 || ! PRETEND_OUTGOING_VARARGS_NAMED)
2046 && TYPE_ARG_TYPES (funtype) != 0)
2048 = (list_length (TYPE_ARG_TYPES (funtype))
2049 /* Don't include the last named arg. */
2050 - (STRICT_ARGUMENT_NAMING ? 0 : 1)
2051 /* Count the struct value address, if it is passed as a parm. */
2052 + structure_value_addr_parm);
2054 /* If we know nothing, treat all args as named. */
2055 n_named_args = num_actuals;
2057 /* Make a vector to hold all the information about each arg. */
2058 args = (struct arg_data *) alloca (num_actuals * sizeof (struct arg_data));
2059 bzero ((char *) args, num_actuals * sizeof (struct arg_data));
2061 /* Build up entries inthe ARGS array, compute the size of the arguments
2062 into ARGS_SIZE, etc. */
2063 initialize_argument_information (num_actuals, args, &args_size, n_named_args,
2064 actparms, fndecl, &args_so_far,
2065 reg_parm_stack_space, &old_stack_level,
2066 &old_pending_adj, &must_preallocate,
2069 #ifdef FINAL_REG_PARM_STACK_SPACE
2070 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
2076 /* If this function requires a variable-sized argument list, don't try to
2077 make a cse'able block for this call. We may be able to do this
2078 eventually, but it is too complicated to keep track of what insns go
2079 in the cse'able block and which don't. */
2082 must_preallocate = 1;
2085 /* Compute the actual size of the argument block required. The variable
2086 and constant sizes must be combined, the size may have to be rounded,
2087 and there may be a minimum required size. */
2088 unadjusted_args_size
2089 = compute_argument_block_size (reg_parm_stack_space, &args_size,
2090 preferred_stack_boundary);
2092 /* Now make final decision about preallocating stack space. */
2093 must_preallocate = finalize_must_preallocate (must_preallocate,
2094 num_actuals, args, &args_size);
2096 /* If the structure value address will reference the stack pointer, we must
2097 stabilize it. We don't need to do this if we know that we are not going
2098 to adjust the stack pointer in processing this call. */
2100 if (structure_value_addr
2101 && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
2102 || reg_mentioned_p (virtual_outgoing_args_rtx, structure_value_addr))
2104 #ifndef ACCUMULATE_OUTGOING_ARGS
2105 || args_size.constant
2108 structure_value_addr = copy_to_reg (structure_value_addr);
2110 /* Precompute any arguments as needed. */
2111 precompute_arguments (is_const, must_preallocate, num_actuals,
2114 /* Now we are about to start emitting insns that can be deleted
2115 if a libcall is deleted. */
2116 if (is_const || is_malloc)
2119 /* If we have no actual push instructions, or shouldn't use them,
2120 make space for all args right now. */
2122 if (args_size.var != 0)
2124 if (old_stack_level == 0)
2126 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
2127 old_pending_adj = pending_stack_adjust;
2128 pending_stack_adjust = 0;
2129 #ifdef ACCUMULATE_OUTGOING_ARGS
2130 /* stack_arg_under_construction says whether a stack arg is
2131 being constructed at the old stack level. Pushing the stack
2132 gets a clean outgoing argument block. */
2133 old_stack_arg_under_construction = stack_arg_under_construction;
2134 stack_arg_under_construction = 0;
2137 argblock = push_block (ARGS_SIZE_RTX (args_size), 0, 0);
2141 /* Note that we must go through the motions of allocating an argument
2142 block even if the size is zero because we may be storing args
2143 in the area reserved for register arguments, which may be part of
2146 int needed = args_size.constant;
2148 /* Store the maximum argument space used. It will be pushed by
2149 the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
2152 if (needed > current_function_outgoing_args_size)
2153 current_function_outgoing_args_size = needed;
2155 if (must_preallocate)
2157 #ifdef ACCUMULATE_OUTGOING_ARGS
2158 /* Since the stack pointer will never be pushed, it is possible for
2159 the evaluation of a parm to clobber something we have already
2160 written to the stack. Since most function calls on RISC machines
2161 do not use the stack, this is uncommon, but must work correctly.
2163 Therefore, we save any area of the stack that was already written
2164 and that we are using. Here we set up to do this by making a new
2165 stack usage map from the old one. The actual save will be done
2168 Another approach might be to try to reorder the argument
2169 evaluations to avoid this conflicting stack usage. */
2171 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2172 /* Since we will be writing into the entire argument area, the
2173 map must be allocated for its entire size, not just the part that
2174 is the responsibility of the caller. */
2175 needed += reg_parm_stack_space;
2178 #ifdef ARGS_GROW_DOWNWARD
2179 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2182 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2185 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
2187 if (initial_highest_arg_in_use)
2188 bcopy (initial_stack_usage_map, stack_usage_map,
2189 initial_highest_arg_in_use);
2191 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
2192 bzero (&stack_usage_map[initial_highest_arg_in_use],
2193 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
2196 /* The address of the outgoing argument list must not be copied to a
2197 register here, because argblock would be left pointing to the
2198 wrong place after the call to allocate_dynamic_stack_space below.
2201 argblock = virtual_outgoing_args_rtx;
2203 #else /* not ACCUMULATE_OUTGOING_ARGS */
2204 if (inhibit_defer_pop == 0)
2206 /* Try to reuse some or all of the pending_stack_adjust
2207 to get this space. Maybe we can avoid any pushing. */
2208 if (needed > pending_stack_adjust)
2210 needed -= pending_stack_adjust;
2211 pending_stack_adjust = 0;
2215 pending_stack_adjust -= needed;
2219 /* Special case this because overhead of `push_block' in this
2220 case is non-trivial. */
2222 argblock = virtual_outgoing_args_rtx;
2224 argblock = push_block (GEN_INT (needed), 0, 0);
2226 /* We only really need to call `copy_to_reg' in the case where push
2227 insns are going to be used to pass ARGBLOCK to a function
2228 call in ARGS. In that case, the stack pointer changes value
2229 from the allocation point to the call point, and hence
2230 the value of VIRTUAL_OUTGOING_ARGS_RTX changes as well.
2231 But might as well always do it. */
2232 argblock = copy_to_reg (argblock);
2233 #endif /* not ACCUMULATE_OUTGOING_ARGS */
2237 #ifdef ACCUMULATE_OUTGOING_ARGS
2238 /* The save/restore code in store_one_arg handles all cases except one:
2239 a constructor call (including a C function returning a BLKmode struct)
2240 to initialize an argument. */
2241 if (stack_arg_under_construction)
2243 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2244 rtx push_size = GEN_INT (reg_parm_stack_space + args_size.constant);
2246 rtx push_size = GEN_INT (args_size.constant);
2248 if (old_stack_level == 0)
2250 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
2251 old_pending_adj = pending_stack_adjust;
2252 pending_stack_adjust = 0;
2253 /* stack_arg_under_construction says whether a stack arg is
2254 being constructed at the old stack level. Pushing the stack
2255 gets a clean outgoing argument block. */
2256 old_stack_arg_under_construction = stack_arg_under_construction;
2257 stack_arg_under_construction = 0;
2258 /* Make a new map for the new argument list. */
2259 stack_usage_map = (char *)alloca (highest_outgoing_arg_in_use);
2260 bzero (stack_usage_map, highest_outgoing_arg_in_use);
2261 highest_outgoing_arg_in_use = 0;
2263 allocate_dynamic_stack_space (push_size, NULL_RTX, BITS_PER_UNIT);
2265 /* If argument evaluation might modify the stack pointer, copy the
2266 address of the argument list to a register. */
2267 for (i = 0; i < num_actuals; i++)
2268 if (args[i].pass_on_stack)
2270 argblock = copy_addr_to_reg (argblock);
2275 compute_argument_addresses (args, argblock, num_actuals);
2277 #ifdef PUSH_ARGS_REVERSED
2278 #ifdef PREFERRED_STACK_BOUNDARY
2279 /* If we push args individually in reverse order, perform stack alignment
2280 before the first push (the last arg). */
2282 anti_adjust_stack (GEN_INT (args_size.constant - unadjusted_args_size));
2286 /* Don't try to defer pops if preallocating, not even from the first arg,
2287 since ARGBLOCK probably refers to the SP. */
2291 funexp = rtx_for_function_call (fndecl, exp);
2293 /* Figure out the register where the value, if any, will come back. */
2295 if (TYPE_MODE (TREE_TYPE (exp)) != VOIDmode
2296 && ! structure_value_addr)
2298 if (pcc_struct_value)
2299 valreg = hard_function_value (build_pointer_type (TREE_TYPE (exp)),
2302 valreg = hard_function_value (TREE_TYPE (exp), fndecl, 0);
2305 /* Precompute all register parameters. It isn't safe to compute anything
2306 once we have started filling any specific hard regs. */
2307 precompute_register_parameters (num_actuals, args, ®_parm_seen);
2309 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
2311 /* Save the fixed argument area if it's part of the caller's frame and
2312 is clobbered by argument setup for this call. */
2313 save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
2314 &low_to_save, &high_to_save);
2318 /* Now store (and compute if necessary) all non-register parms.
2319 These come before register parms, since they can require block-moves,
2320 which could clobber the registers used for register parms.
2321 Parms which have partial registers are not stored here,
2322 but we do preallocate space here if they want that. */
2324 for (i = 0; i < num_actuals; i++)
2325 if (args[i].reg == 0 || args[i].pass_on_stack)
2326 store_one_arg (&args[i], argblock, may_be_alloca,
2327 args_size.var != 0, reg_parm_stack_space);
2329 /* If we have a parm that is passed in registers but not in memory
2330 and whose alignment does not permit a direct copy into registers,
2331 make a group of pseudos that correspond to each register that we
2333 if (STRICT_ALIGNMENT)
2334 store_unaligned_arguments_into_pseudos (args, num_actuals);
2336 /* Now store any partially-in-registers parm.
2337 This is the last place a block-move can happen. */
2339 for (i = 0; i < num_actuals; i++)
2340 if (args[i].partial != 0 && ! args[i].pass_on_stack)
2341 store_one_arg (&args[i], argblock, may_be_alloca,
2342 args_size.var != 0, reg_parm_stack_space);
2344 #ifndef PUSH_ARGS_REVERSED
2345 #ifdef PREFERRED_STACK_BOUNDARY
2346 /* If we pushed args in forward order, perform stack alignment
2347 after pushing the last arg. */
2349 anti_adjust_stack (GEN_INT (args_size.constant - unadjusted_args_size));
2353 /* If register arguments require space on the stack and stack space
2354 was not preallocated, allocate stack space here for arguments
2355 passed in registers. */
2356 #if ! defined(ACCUMULATE_OUTGOING_ARGS) && defined(OUTGOING_REG_PARM_STACK_SPACE)
2357 if (must_preallocate == 0 && reg_parm_stack_space > 0)
2358 anti_adjust_stack (GEN_INT (reg_parm_stack_space));
2361 /* Pass the function the address in which to return a structure value. */
2362 if (structure_value_addr && ! structure_value_addr_parm)
2364 emit_move_insn (struct_value_rtx,
2366 force_operand (structure_value_addr,
2369 /* Mark the memory for the aggregate as write-only. */
2370 if (current_function_check_memory_usage)
2371 emit_library_call (chkr_set_right_libfunc, 1,
2373 structure_value_addr, Pmode,
2374 GEN_INT (struct_value_size), TYPE_MODE (sizetype),
2375 GEN_INT (MEMORY_USE_WO),
2376 TYPE_MODE (integer_type_node));
2378 if (GET_CODE (struct_value_rtx) == REG)
2379 use_reg (&call_fusage, struct_value_rtx);
2382 funexp = prepare_call_address (funexp, fndecl, &call_fusage, reg_parm_seen);
2384 load_register_parameters (args, num_actuals, &call_fusage);
2386 /* Perform postincrements before actually calling the function. */
2389 /* Save a pointer to the last insn before the call, so that we can
2390 later safely search backwards to find the CALL_INSN. */
2391 before_call = get_last_insn ();
2393 /* All arguments and registers used for the call must be set up by now! */
2395 /* Generate the actual call instruction. */
2396 emit_call_1 (funexp, fndecl, funtype, unadjusted_args_size,
2397 args_size.constant, struct_value_size,
2398 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
2399 valreg, old_inhibit_defer_pop, call_fusage, is_const);
2401 /* If call is cse'able, make appropriate pair of reg-notes around it.
2402 Test valreg so we don't crash; may safely ignore `const'
2403 if return type is void. Disable for PARALLEL return values, because
2404 we have no way to move such values into a pseudo register. */
2405 if (is_const && valreg != 0 && GET_CODE (valreg) != PARALLEL)
2408 rtx temp = gen_reg_rtx (GET_MODE (valreg));
2411 /* Mark the return value as a pointer if needed. */
2412 if (TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE)
2414 tree pointed_to = TREE_TYPE (TREE_TYPE (exp));
2415 mark_reg_pointer (temp, TYPE_ALIGN (pointed_to) / BITS_PER_UNIT);
2418 /* Construct an "equal form" for the value which mentions all the
2419 arguments in order as well as the function name. */
2420 #ifdef PUSH_ARGS_REVERSED
2421 for (i = 0; i < num_actuals; i++)
2422 note = gen_rtx_EXPR_LIST (VOIDmode, args[i].initial_value, note);
2424 for (i = num_actuals - 1; i >= 0; i--)
2425 note = gen_rtx_EXPR_LIST (VOIDmode, args[i].initial_value, note);
2427 note = gen_rtx_EXPR_LIST (VOIDmode, funexp, note);
2429 insns = get_insns ();
2432 emit_libcall_block (insns, temp, valreg, note);
2438 /* Otherwise, just write out the sequence without a note. */
2439 rtx insns = get_insns ();
2446 rtx temp = gen_reg_rtx (GET_MODE (valreg));
2449 /* The return value from a malloc-like function is a pointer. */
2450 if (TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE)
2451 mark_reg_pointer (temp, BIGGEST_ALIGNMENT / BITS_PER_UNIT);
2453 emit_move_insn (temp, valreg);
2455 /* The return value from a malloc-like function can not alias
2457 last = get_last_insn ();
2459 gen_rtx_EXPR_LIST (REG_NOALIAS, temp, REG_NOTES (last));
2461 /* Write out the sequence. */
2462 insns = get_insns ();
2468 /* For calls to `setjmp', etc., inform flow.c it should complain
2469 if nonvolatile values are live. */
2473 /* The NOTE_INSN_SETJMP note must be emitted immediately after the
2474 CALL_INSN. Some ports emit more than just a CALL_INSN above, so
2475 we must search for it here. */
2476 rtx last = get_last_insn ();
2477 while (GET_CODE (last) != CALL_INSN)
2479 last = PREV_INSN (last);
2480 /* There was no CALL_INSN? */
2481 if (last == before_call)
2484 emit_note_after (NOTE_INSN_SETJMP, last);
2485 current_function_calls_setjmp = 1;
2489 current_function_calls_longjmp = 1;
2491 /* Notice functions that cannot return.
2492 If optimizing, insns emitted below will be dead.
2493 If not optimizing, they will exist, which is useful
2494 if the user uses the `return' command in the debugger. */
2496 if (is_volatile || is_longjmp)
2499 /* If value type not void, return an rtx for the value. */
2501 /* If there are cleanups to be called, don't use a hard reg as target.
2502 We need to double check this and see if it matters anymore. */
2503 if (any_pending_cleanups (1)
2504 && target && REG_P (target)
2505 && REGNO (target) < FIRST_PSEUDO_REGISTER)
2508 if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode
2511 target = const0_rtx;
2513 else if (structure_value_addr)
2515 if (target == 0 || GET_CODE (target) != MEM)
2517 target = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
2518 memory_address (TYPE_MODE (TREE_TYPE (exp)),
2519 structure_value_addr));
2520 MEM_SET_IN_STRUCT_P (target,
2521 AGGREGATE_TYPE_P (TREE_TYPE (exp)));
2524 else if (pcc_struct_value)
2526 /* This is the special C++ case where we need to
2527 know what the true target was. We take care to
2528 never use this value more than once in one expression. */
2529 target = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
2530 copy_to_reg (valreg));
2531 MEM_SET_IN_STRUCT_P (target, AGGREGATE_TYPE_P (TREE_TYPE (exp)));
2533 /* Handle calls that return values in multiple non-contiguous locations.
2534 The Irix 6 ABI has examples of this. */
2535 else if (GET_CODE (valreg) == PARALLEL)
2537 int bytes = int_size_in_bytes (TREE_TYPE (exp));
2541 target = assign_stack_temp (TYPE_MODE (TREE_TYPE (exp)), bytes, 0);
2542 MEM_SET_IN_STRUCT_P (target, AGGREGATE_TYPE_P (TREE_TYPE (exp)));
2543 preserve_temp_slots (target);
2546 if (! rtx_equal_p (target, valreg))
2547 emit_group_store (target, valreg, bytes,
2548 TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
2550 else if (target && GET_MODE (target) == TYPE_MODE (TREE_TYPE (exp))
2551 && GET_MODE (target) == GET_MODE (valreg))
2552 /* TARGET and VALREG cannot be equal at this point because the latter
2553 would not have REG_FUNCTION_VALUE_P true, while the former would if
2554 it were referring to the same register.
2556 If they refer to the same register, this move will be a no-op, except
2557 when function inlining is being done. */
2558 emit_move_insn (target, valreg);
2559 else if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
2560 target = copy_blkmode_from_reg (target, valreg, TREE_TYPE (exp));
2562 target = copy_to_reg (valreg);
2564 #ifdef PROMOTE_FUNCTION_RETURN
2565 /* If we promoted this return value, make the proper SUBREG. TARGET
2566 might be const0_rtx here, so be careful. */
2567 if (GET_CODE (target) == REG
2568 && TYPE_MODE (TREE_TYPE (exp)) != BLKmode
2569 && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
2571 tree type = TREE_TYPE (exp);
2572 int unsignedp = TREE_UNSIGNED (type);
2574 /* If we don't promote as expected, something is wrong. */
2575 if (GET_MODE (target)
2576 != promote_mode (type, TYPE_MODE (type), &unsignedp, 1))
2579 target = gen_rtx_SUBREG (TYPE_MODE (type), target, 0);
2580 SUBREG_PROMOTED_VAR_P (target) = 1;
2581 SUBREG_PROMOTED_UNSIGNED_P (target) = unsignedp;
2585 /* If size of args is variable or this was a constructor call for a stack
2586 argument, restore saved stack-pointer value. */
2588 if (old_stack_level)
2590 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
2591 pending_stack_adjust = old_pending_adj;
2592 #ifdef ACCUMULATE_OUTGOING_ARGS
2593 stack_arg_under_construction = old_stack_arg_under_construction;
2594 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2595 stack_usage_map = initial_stack_usage_map;
2598 #ifdef ACCUMULATE_OUTGOING_ARGS
2601 #ifdef REG_PARM_STACK_SPACE
2603 restore_fixed_argument_area (save_area, argblock,
2604 high_to_save, low_to_save);
2607 /* If we saved any argument areas, restore them. */
2608 for (i = 0; i < num_actuals; i++)
2609 if (args[i].save_area)
2611 enum machine_mode save_mode = GET_MODE (args[i].save_area);
2613 = gen_rtx_MEM (save_mode,
2614 memory_address (save_mode,
2615 XEXP (args[i].stack_slot, 0)));
2617 if (save_mode != BLKmode)
2618 emit_move_insn (stack_area, args[i].save_area);
2620 emit_block_move (stack_area, validize_mem (args[i].save_area),
2621 GEN_INT (args[i].size.constant),
2622 PARM_BOUNDARY / BITS_PER_UNIT);
2625 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2626 stack_usage_map = initial_stack_usage_map;
2630 /* If this was alloca, record the new stack level for nonlocal gotos.
2631 Check for the handler slots since we might not have a save area
2632 for non-local gotos. */
2634 if (may_be_alloca && nonlocal_goto_handler_slots != 0)
2635 emit_stack_save (SAVE_NONLOCAL, &nonlocal_goto_stack_level, NULL_RTX);
2639 /* Free up storage we no longer need. */
2640 for (i = 0; i < num_actuals; ++i)
2641 if (args[i].aligned_regs)
2642 free (args[i].aligned_regs);
2647 /* Output a library call to function FUN (a SYMBOL_REF rtx)
2648 (emitting the queue unless NO_QUEUE is nonzero),
2649 for a value of mode OUTMODE,
2650 with NARGS different arguments, passed as alternating rtx values
2651 and machine_modes to convert them to.
2652 The rtx values should have been passed through protect_from_queue already.
2654 NO_QUEUE will be true if and only if the library call is a `const' call
2655 which will be enclosed in REG_LIBCALL/REG_RETVAL notes; it is equivalent
2656 to the variable is_const in expand_call.
2658 NO_QUEUE must be true for const calls, because if it isn't, then
2659 any pending increment will be emitted between REG_LIBCALL/REG_RETVAL notes,
2660 and will be lost if the libcall sequence is optimized away.
2662 NO_QUEUE must be false for non-const calls, because if it isn't, the
2663 call insn will have its CONST_CALL_P bit set, and it will be incorrectly
2664 optimized. For instance, the instruction scheduler may incorrectly
2665 move memory references across the non-const call. */
2668 emit_library_call VPARAMS((rtx orgfun, int no_queue, enum machine_mode outmode,
2671 #ifndef ANSI_PROTOTYPES
2674 enum machine_mode outmode;
2678 /* Total size in bytes of all the stack-parms scanned so far. */
2679 struct args_size args_size;
2680 /* Size of arguments before any adjustments (such as rounding). */
2681 struct args_size original_args_size;
2682 register int argnum;
2686 struct args_size alignment_pad;
2688 CUMULATIVE_ARGS args_so_far;
2689 struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
2690 struct args_size offset; struct args_size size; rtx save_area; };
2692 int old_inhibit_defer_pop = inhibit_defer_pop;
2693 rtx call_fusage = 0;
2694 int reg_parm_stack_space = 0;
2695 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
2696 /* Define the boundary of the register parm stack space that needs to be
2698 int low_to_save = -1, high_to_save = 0;
2699 rtx save_area = 0; /* Place that it is saved */
2702 #ifdef ACCUMULATE_OUTGOING_ARGS
2703 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
2704 char *initial_stack_usage_map = stack_usage_map;
2708 #ifdef REG_PARM_STACK_SPACE
2709 /* Size of the stack reserved for parameter registers. */
2710 #ifdef MAYBE_REG_PARM_STACK_SPACE
2711 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
2713 reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0);
2717 VA_START (p, nargs);
2719 #ifndef ANSI_PROTOTYPES
2720 orgfun = va_arg (p, rtx);
2721 no_queue = va_arg (p, int);
2722 outmode = va_arg (p, enum machine_mode);
2723 nargs = va_arg (p, int);
2728 /* Copy all the libcall-arguments out of the varargs data
2729 and into a vector ARGVEC.
2731 Compute how to pass each argument. We only support a very small subset
2732 of the full argument passing conventions to limit complexity here since
2733 library functions shouldn't have many args. */
2735 argvec = (struct arg *) alloca (nargs * sizeof (struct arg));
2736 bzero ((char *) argvec, nargs * sizeof (struct arg));
2739 INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0);
2741 args_size.constant = 0;
2746 #ifdef PREFERRED_STACK_BOUNDARY
2747 /* Ensure current function's preferred stack boundary is at least
2749 if (cfun->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
2750 cfun->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
2753 for (count = 0; count < nargs; count++)
2755 rtx val = va_arg (p, rtx);
2756 enum machine_mode mode = va_arg (p, enum machine_mode);
2758 /* We cannot convert the arg value to the mode the library wants here;
2759 must do it earlier where we know the signedness of the arg. */
2761 || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
2764 /* On some machines, there's no way to pass a float to a library fcn.
2765 Pass it as a double instead. */
2766 #ifdef LIBGCC_NEEDS_DOUBLE
2767 if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
2768 val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode;
2771 /* There's no need to call protect_from_queue, because
2772 either emit_move_insn or emit_push_insn will do that. */
2774 /* Make sure it is a reasonable operand for a move or push insn. */
2775 if (GET_CODE (val) != REG && GET_CODE (val) != MEM
2776 && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
2777 val = force_operand (val, NULL_RTX);
2779 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
2780 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
2782 /* We do not support FUNCTION_ARG_CALLEE_COPIES here since it can
2783 be viewed as just an efficiency improvement. */
2784 rtx slot = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
2785 emit_move_insn (slot, val);
2786 val = force_operand (XEXP (slot, 0), NULL_RTX);
2791 argvec[count].value = val;
2792 argvec[count].mode = mode;
2794 argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
2795 if (argvec[count].reg && GET_CODE (argvec[count].reg) == PARALLEL)
2797 #ifdef FUNCTION_ARG_PARTIAL_NREGS
2798 argvec[count].partial
2799 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
2801 argvec[count].partial = 0;
2804 locate_and_pad_parm (mode, NULL_TREE,
2805 argvec[count].reg && argvec[count].partial == 0,
2806 NULL_TREE, &args_size, &argvec[count].offset,
2807 &argvec[count].size, &alignment_pad);
2809 if (argvec[count].size.var)
2812 if (reg_parm_stack_space == 0 && argvec[count].partial)
2813 argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
2815 if (argvec[count].reg == 0 || argvec[count].partial != 0
2816 || reg_parm_stack_space > 0)
2817 args_size.constant += argvec[count].size.constant;
2819 FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
2823 #ifdef FINAL_REG_PARM_STACK_SPACE
2824 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
2828 /* If this machine requires an external definition for library
2829 functions, write one out. */
2830 assemble_external_libcall (fun);
2832 original_args_size = args_size;
2833 #ifdef PREFERRED_STACK_BOUNDARY
2834 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
2835 / STACK_BYTES) * STACK_BYTES);
2838 args_size.constant = MAX (args_size.constant,
2839 reg_parm_stack_space);
2841 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2842 args_size.constant -= reg_parm_stack_space;
2845 if (args_size.constant > current_function_outgoing_args_size)
2846 current_function_outgoing_args_size = args_size.constant;
2848 #ifdef ACCUMULATE_OUTGOING_ARGS
2849 /* Since the stack pointer will never be pushed, it is possible for
2850 the evaluation of a parm to clobber something we have already
2851 written to the stack. Since most function calls on RISC machines
2852 do not use the stack, this is uncommon, but must work correctly.
2854 Therefore, we save any area of the stack that was already written
2855 and that we are using. Here we set up to do this by making a new
2856 stack usage map from the old one.
2858 Another approach might be to try to reorder the argument
2859 evaluations to avoid this conflicting stack usage. */
2861 needed = args_size.constant;
2863 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2864 /* Since we will be writing into the entire argument area, the
2865 map must be allocated for its entire size, not just the part that
2866 is the responsibility of the caller. */
2867 needed += reg_parm_stack_space;
2870 #ifdef ARGS_GROW_DOWNWARD
2871 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2874 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2877 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
2879 if (initial_highest_arg_in_use)
2880 bcopy (initial_stack_usage_map, stack_usage_map,
2881 initial_highest_arg_in_use);
2883 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
2884 bzero (&stack_usage_map[initial_highest_arg_in_use],
2885 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
2888 /* The address of the outgoing argument list must not be copied to a
2889 register here, because argblock would be left pointing to the
2890 wrong place after the call to allocate_dynamic_stack_space below.
2893 argblock = virtual_outgoing_args_rtx;
2894 #else /* not ACCUMULATE_OUTGOING_ARGS */
2895 #ifndef PUSH_ROUNDING
2896 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
2900 #ifdef PUSH_ARGS_REVERSED
2901 #ifdef PREFERRED_STACK_BOUNDARY
2902 /* If we push args individually in reverse order, perform stack alignment
2903 before the first push (the last arg). */
2905 anti_adjust_stack (GEN_INT (args_size.constant
2906 - original_args_size.constant));
2910 #ifdef PUSH_ARGS_REVERSED
2918 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
2919 /* The argument list is the property of the called routine and it
2920 may clobber it. If the fixed area has been used for previous
2921 parameters, we must save and restore it.
2923 Here we compute the boundary of the that needs to be saved, if any. */
2925 #ifdef ARGS_GROW_DOWNWARD
2926 for (count = 0; count < reg_parm_stack_space + 1; count++)
2928 for (count = 0; count < reg_parm_stack_space; count++)
2931 if (count >= highest_outgoing_arg_in_use
2932 || stack_usage_map[count] == 0)
2935 if (low_to_save == -1)
2936 low_to_save = count;
2938 high_to_save = count;
2941 if (low_to_save >= 0)
2943 int num_to_save = high_to_save - low_to_save + 1;
2944 enum machine_mode save_mode
2945 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
2948 /* If we don't have the required alignment, must do this in BLKmode. */
2949 if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
2950 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
2951 save_mode = BLKmode;
2953 #ifdef ARGS_GROW_DOWNWARD
2954 stack_area = gen_rtx_MEM (save_mode,
2955 memory_address (save_mode,
2956 plus_constant (argblock,
2959 stack_area = gen_rtx_MEM (save_mode,
2960 memory_address (save_mode,
2961 plus_constant (argblock,
2964 if (save_mode == BLKmode)
2966 save_area = assign_stack_temp (BLKmode, num_to_save, 0);
2967 emit_block_move (validize_mem (save_area), stack_area,
2968 GEN_INT (num_to_save),
2969 PARM_BOUNDARY / BITS_PER_UNIT);
2973 save_area = gen_reg_rtx (save_mode);
2974 emit_move_insn (save_area, stack_area);
2979 /* Push the args that need to be pushed. */
2981 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
2982 are to be pushed. */
2983 for (count = 0; count < nargs; count++, argnum += inc)
2985 register enum machine_mode mode = argvec[argnum].mode;
2986 register rtx val = argvec[argnum].value;
2987 rtx reg = argvec[argnum].reg;
2988 int partial = argvec[argnum].partial;
2989 #ifdef ACCUMULATE_OUTGOING_ARGS
2990 int lower_bound, upper_bound, i;
2993 if (! (reg != 0 && partial == 0))
2995 #ifdef ACCUMULATE_OUTGOING_ARGS
2996 /* If this is being stored into a pre-allocated, fixed-size, stack
2997 area, save any previous data at that location. */
2999 #ifdef ARGS_GROW_DOWNWARD
3000 /* stack_slot is negative, but we want to index stack_usage_map
3001 with positive values. */
3002 upper_bound = -argvec[argnum].offset.constant + 1;
3003 lower_bound = upper_bound - argvec[argnum].size.constant;
3005 lower_bound = argvec[argnum].offset.constant;
3006 upper_bound = lower_bound + argvec[argnum].size.constant;
3009 for (i = lower_bound; i < upper_bound; i++)
3010 if (stack_usage_map[i]
3011 /* Don't store things in the fixed argument area at this point;
3012 it has already been saved. */
3013 && i > reg_parm_stack_space)
3016 if (i != upper_bound)
3018 /* We need to make a save area. See what mode we can make it. */
3019 enum machine_mode save_mode
3020 = mode_for_size (argvec[argnum].size.constant * BITS_PER_UNIT,
3027 plus_constant (argblock,
3028 argvec[argnum].offset.constant)));
3030 argvec[argnum].save_area = gen_reg_rtx (save_mode);
3031 emit_move_insn (argvec[argnum].save_area, stack_area);
3034 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
3035 argblock, GEN_INT (argvec[argnum].offset.constant),
3036 reg_parm_stack_space, ARGS_SIZE_RTX (alignment_pad));
3038 #ifdef ACCUMULATE_OUTGOING_ARGS
3039 /* Now mark the segment we just used. */
3040 for (i = lower_bound; i < upper_bound; i++)
3041 stack_usage_map[i] = 1;
3048 #ifndef PUSH_ARGS_REVERSED
3049 #ifdef PREFERRED_STACK_BOUNDARY
3050 /* If we pushed args in forward order, perform stack alignment
3051 after pushing the last arg. */
3053 anti_adjust_stack (GEN_INT (args_size.constant
3054 - original_args_size.constant));
3058 #ifdef PUSH_ARGS_REVERSED
3064 fun = prepare_call_address (fun, NULL_TREE, &call_fusage, 0);
3066 /* Now load any reg parms into their regs. */
3068 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3069 are to be pushed. */
3070 for (count = 0; count < nargs; count++, argnum += inc)
3072 register rtx val = argvec[argnum].value;
3073 rtx reg = argvec[argnum].reg;
3074 int partial = argvec[argnum].partial;
3076 if (reg != 0 && partial == 0)
3077 emit_move_insn (reg, val);
3081 /* For version 1.37, try deleting this entirely. */
3085 /* Any regs containing parms remain in use through the call. */
3086 for (count = 0; count < nargs; count++)
3087 if (argvec[count].reg != 0)
3088 use_reg (&call_fusage, argvec[count].reg);
3090 /* Don't allow popping to be deferred, since then
3091 cse'ing of library calls could delete a call and leave the pop. */
3094 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
3095 will set inhibit_defer_pop to that value. */
3097 /* The return type is needed to decide how many bytes the function pops.
3098 Signedness plays no role in that, so for simplicity, we pretend it's
3099 always signed. We also assume that the list of arguments passed has
3100 no impact, so we pretend it is unknown. */
3103 get_identifier (XSTR (orgfun, 0)),
3104 build_function_type (outmode == VOIDmode ? void_type_node
3105 : type_for_mode (outmode, 0), NULL_TREE),
3106 original_args_size.constant, args_size.constant, 0,
3107 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
3108 outmode != VOIDmode ? hard_libcall_value (outmode) : NULL_RTX,
3109 old_inhibit_defer_pop + 1, call_fusage, no_queue);
3113 /* Now restore inhibit_defer_pop to its actual original value. */
3116 #ifdef ACCUMULATE_OUTGOING_ARGS
3117 #ifdef REG_PARM_STACK_SPACE
3120 enum machine_mode save_mode = GET_MODE (save_area);
3121 #ifdef ARGS_GROW_DOWNWARD
3123 = gen_rtx_MEM (save_mode,
3124 memory_address (save_mode,
3125 plus_constant (argblock,
3129 = gen_rtx_MEM (save_mode,
3130 memory_address (save_mode,
3131 plus_constant (argblock, low_to_save)));
3134 if (save_mode != BLKmode)
3135 emit_move_insn (stack_area, save_area);
3137 emit_block_move (stack_area, validize_mem (save_area),
3138 GEN_INT (high_to_save - low_to_save + 1),
3139 PARM_BOUNDARY / BITS_PER_UNIT);
3143 /* If we saved any argument areas, restore them. */
3144 for (count = 0; count < nargs; count++)
3145 if (argvec[count].save_area)
3147 enum machine_mode save_mode = GET_MODE (argvec[count].save_area);
3149 = gen_rtx_MEM (save_mode,
3152 plus_constant (argblock,
3153 argvec[count].offset.constant)));
3155 emit_move_insn (stack_area, argvec[count].save_area);
3158 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3159 stack_usage_map = initial_stack_usage_map;
3163 /* Like emit_library_call except that an extra argument, VALUE,
3164 comes second and says where to store the result.
3165 (If VALUE is zero, this function chooses a convenient way
3166 to return the value.
3168 This function returns an rtx for where the value is to be found.
3169 If VALUE is nonzero, VALUE is returned. */
3172 emit_library_call_value VPARAMS((rtx orgfun, rtx value, int no_queue,
3173 enum machine_mode outmode, int nargs, ...))
3175 #ifndef ANSI_PROTOTYPES
3179 enum machine_mode outmode;
3183 /* Total size in bytes of all the stack-parms scanned so far. */
3184 struct args_size args_size;
3185 /* Size of arguments before any adjustments (such as rounding). */
3186 struct args_size original_args_size;
3187 register int argnum;
3191 struct args_size alignment_pad;
3193 CUMULATIVE_ARGS args_so_far;
3194 struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
3195 struct args_size offset; struct args_size size; rtx save_area; };
3197 int old_inhibit_defer_pop = inhibit_defer_pop;
3198 rtx call_fusage = 0;
3200 int pcc_struct_value = 0;
3201 int struct_value_size = 0;
3203 int reg_parm_stack_space = 0;
3204 #ifdef ACCUMULATE_OUTGOING_ARGS
3208 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
3209 /* Define the boundary of the register parm stack space that needs to be
3211 int low_to_save = -1, high_to_save = 0;
3212 rtx save_area = 0; /* Place that it is saved */
3215 #ifdef ACCUMULATE_OUTGOING_ARGS
3216 /* Size of the stack reserved for parameter registers. */
3217 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
3218 char *initial_stack_usage_map = stack_usage_map;
3221 #ifdef REG_PARM_STACK_SPACE
3222 #ifdef MAYBE_REG_PARM_STACK_SPACE
3223 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
3225 reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0);
3229 VA_START (p, nargs);
3231 #ifndef ANSI_PROTOTYPES
3232 orgfun = va_arg (p, rtx);
3233 value = va_arg (p, rtx);
3234 no_queue = va_arg (p, int);
3235 outmode = va_arg (p, enum machine_mode);
3236 nargs = va_arg (p, int);
3239 is_const = no_queue;
3242 #ifdef PREFERRED_STACK_BOUNDARY
3243 /* Ensure current function's preferred stack boundary is at least
3245 if (cfun->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
3246 cfun->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
3249 /* If this kind of value comes back in memory,
3250 decide where in memory it should come back. */
3251 if (aggregate_value_p (type_for_mode (outmode, 0)))
3253 #ifdef PCC_STATIC_STRUCT_RETURN
3255 = hard_function_value (build_pointer_type (type_for_mode (outmode, 0)),
3257 mem_value = gen_rtx_MEM (outmode, pointer_reg);
3258 pcc_struct_value = 1;
3260 value = gen_reg_rtx (outmode);
3261 #else /* not PCC_STATIC_STRUCT_RETURN */
3262 struct_value_size = GET_MODE_SIZE (outmode);
3263 if (value != 0 && GET_CODE (value) == MEM)
3266 mem_value = assign_stack_temp (outmode, GET_MODE_SIZE (outmode), 0);
3269 /* This call returns a big structure. */
3273 /* ??? Unfinished: must pass the memory address as an argument. */
3275 /* Copy all the libcall-arguments out of the varargs data
3276 and into a vector ARGVEC.
3278 Compute how to pass each argument. We only support a very small subset
3279 of the full argument passing conventions to limit complexity here since
3280 library functions shouldn't have many args. */
3282 argvec = (struct arg *) alloca ((nargs + 1) * sizeof (struct arg));
3283 bzero ((char *) argvec, (nargs + 1) * sizeof (struct arg));
3285 INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0);
3287 args_size.constant = 0;
3294 /* If there's a structure value address to be passed,
3295 either pass it in the special place, or pass it as an extra argument. */
3296 if (mem_value && struct_value_rtx == 0 && ! pcc_struct_value)
3298 rtx addr = XEXP (mem_value, 0);
3301 /* Make sure it is a reasonable operand for a move or push insn. */
3302 if (GET_CODE (addr) != REG && GET_CODE (addr) != MEM
3303 && ! (CONSTANT_P (addr) && LEGITIMATE_CONSTANT_P (addr)))
3304 addr = force_operand (addr, NULL_RTX);
3306 argvec[count].value = addr;
3307 argvec[count].mode = Pmode;
3308 argvec[count].partial = 0;
3310 argvec[count].reg = FUNCTION_ARG (args_so_far, Pmode, NULL_TREE, 1);
3311 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3312 if (FUNCTION_ARG_PARTIAL_NREGS (args_so_far, Pmode, NULL_TREE, 1))
3316 locate_and_pad_parm (Pmode, NULL_TREE,
3317 argvec[count].reg && argvec[count].partial == 0,
3318 NULL_TREE, &args_size, &argvec[count].offset,
3319 &argvec[count].size, &alignment_pad);
3322 if (argvec[count].reg == 0 || argvec[count].partial != 0
3323 || reg_parm_stack_space > 0)
3324 args_size.constant += argvec[count].size.constant;
3326 FUNCTION_ARG_ADVANCE (args_so_far, Pmode, (tree) 0, 1);
3331 for (; count < nargs; count++)
3333 rtx val = va_arg (p, rtx);
3334 enum machine_mode mode = va_arg (p, enum machine_mode);
3336 /* We cannot convert the arg value to the mode the library wants here;
3337 must do it earlier where we know the signedness of the arg. */
3339 || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
3342 /* On some machines, there's no way to pass a float to a library fcn.
3343 Pass it as a double instead. */
3344 #ifdef LIBGCC_NEEDS_DOUBLE
3345 if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
3346 val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode;
3349 /* There's no need to call protect_from_queue, because
3350 either emit_move_insn or emit_push_insn will do that. */
3352 /* Make sure it is a reasonable operand for a move or push insn. */
3353 if (GET_CODE (val) != REG && GET_CODE (val) != MEM
3354 && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
3355 val = force_operand (val, NULL_RTX);
3357 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
3358 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
3360 /* We do not support FUNCTION_ARG_CALLEE_COPIES here since it can
3361 be viewed as just an efficiency improvement. */
3362 rtx slot = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
3363 emit_move_insn (slot, val);
3364 val = XEXP (slot, 0);
3369 argvec[count].value = val;
3370 argvec[count].mode = mode;
3372 argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
3373 if (argvec[count].reg && GET_CODE (argvec[count].reg) == PARALLEL)
3375 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3376 argvec[count].partial
3377 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
3379 argvec[count].partial = 0;
3382 locate_and_pad_parm (mode, NULL_TREE,
3383 argvec[count].reg && argvec[count].partial == 0,
3384 NULL_TREE, &args_size, &argvec[count].offset,
3385 &argvec[count].size, &alignment_pad);
3387 if (argvec[count].size.var)
3390 if (reg_parm_stack_space == 0 && argvec[count].partial)
3391 argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
3393 if (argvec[count].reg == 0 || argvec[count].partial != 0
3394 || reg_parm_stack_space > 0)
3395 args_size.constant += argvec[count].size.constant;
3397 FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
3401 #ifdef FINAL_REG_PARM_STACK_SPACE
3402 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
3405 /* If this machine requires an external definition for library
3406 functions, write one out. */
3407 assemble_external_libcall (fun);
3409 original_args_size = args_size;
3410 #ifdef PREFERRED_STACK_BOUNDARY
3411 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
3412 / STACK_BYTES) * STACK_BYTES);
3415 args_size.constant = MAX (args_size.constant,
3416 reg_parm_stack_space);
3418 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3419 args_size.constant -= reg_parm_stack_space;
3422 if (args_size.constant > current_function_outgoing_args_size)
3423 current_function_outgoing_args_size = args_size.constant;
3425 #ifdef ACCUMULATE_OUTGOING_ARGS
3426 /* Since the stack pointer will never be pushed, it is possible for
3427 the evaluation of a parm to clobber something we have already
3428 written to the stack. Since most function calls on RISC machines
3429 do not use the stack, this is uncommon, but must work correctly.
3431 Therefore, we save any area of the stack that was already written
3432 and that we are using. Here we set up to do this by making a new
3433 stack usage map from the old one.
3435 Another approach might be to try to reorder the argument
3436 evaluations to avoid this conflicting stack usage. */
3438 needed = args_size.constant;
3440 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3441 /* Since we will be writing into the entire argument area, the
3442 map must be allocated for its entire size, not just the part that
3443 is the responsibility of the caller. */
3444 needed += reg_parm_stack_space;
3447 #ifdef ARGS_GROW_DOWNWARD
3448 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3451 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3454 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
3456 if (initial_highest_arg_in_use)
3457 bcopy (initial_stack_usage_map, stack_usage_map,
3458 initial_highest_arg_in_use);
3460 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
3461 bzero (&stack_usage_map[initial_highest_arg_in_use],
3462 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
3465 /* The address of the outgoing argument list must not be copied to a
3466 register here, because argblock would be left pointing to the
3467 wrong place after the call to allocate_dynamic_stack_space below.
3470 argblock = virtual_outgoing_args_rtx;
3471 #else /* not ACCUMULATE_OUTGOING_ARGS */
3472 #ifndef PUSH_ROUNDING
3473 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
3477 #ifdef PUSH_ARGS_REVERSED
3478 #ifdef PREFERRED_STACK_BOUNDARY
3479 /* If we push args individually in reverse order, perform stack alignment
3480 before the first push (the last arg). */
3482 anti_adjust_stack (GEN_INT (args_size.constant
3483 - original_args_size.constant));
3487 #ifdef PUSH_ARGS_REVERSED
3495 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
3496 /* The argument list is the property of the called routine and it
3497 may clobber it. If the fixed area has been used for previous
3498 parameters, we must save and restore it.
3500 Here we compute the boundary of the that needs to be saved, if any. */
3502 #ifdef ARGS_GROW_DOWNWARD
3503 for (count = 0; count < reg_parm_stack_space + 1; count++)
3505 for (count = 0; count < reg_parm_stack_space; count++)
3508 if (count >= highest_outgoing_arg_in_use
3509 || stack_usage_map[count] == 0)
3512 if (low_to_save == -1)
3513 low_to_save = count;
3515 high_to_save = count;
3518 if (low_to_save >= 0)
3520 int num_to_save = high_to_save - low_to_save + 1;
3521 enum machine_mode save_mode
3522 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
3525 /* If we don't have the required alignment, must do this in BLKmode. */
3526 if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
3527 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
3528 save_mode = BLKmode;
3530 #ifdef ARGS_GROW_DOWNWARD
3531 stack_area = gen_rtx_MEM (save_mode,
3532 memory_address (save_mode,
3533 plus_constant (argblock,
3536 stack_area = gen_rtx_MEM (save_mode,
3537 memory_address (save_mode,
3538 plus_constant (argblock,
3541 if (save_mode == BLKmode)
3543 save_area = assign_stack_temp (BLKmode, num_to_save, 0);
3544 emit_block_move (validize_mem (save_area), stack_area,
3545 GEN_INT (num_to_save),
3546 PARM_BOUNDARY / BITS_PER_UNIT);
3550 save_area = gen_reg_rtx (save_mode);
3551 emit_move_insn (save_area, stack_area);
3556 /* Push the args that need to be pushed. */
3558 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3559 are to be pushed. */
3560 for (count = 0; count < nargs; count++, argnum += inc)
3562 register enum machine_mode mode = argvec[argnum].mode;
3563 register rtx val = argvec[argnum].value;
3564 rtx reg = argvec[argnum].reg;
3565 int partial = argvec[argnum].partial;
3566 #ifdef ACCUMULATE_OUTGOING_ARGS
3567 int lower_bound, upper_bound, i;
3570 if (! (reg != 0 && partial == 0))
3572 #ifdef ACCUMULATE_OUTGOING_ARGS
3573 /* If this is being stored into a pre-allocated, fixed-size, stack
3574 area, save any previous data at that location. */
3576 #ifdef ARGS_GROW_DOWNWARD
3577 /* stack_slot is negative, but we want to index stack_usage_map
3578 with positive values. */
3579 upper_bound = -argvec[argnum].offset.constant + 1;
3580 lower_bound = upper_bound - argvec[argnum].size.constant;
3582 lower_bound = argvec[argnum].offset.constant;
3583 upper_bound = lower_bound + argvec[argnum].size.constant;
3586 for (i = lower_bound; i < upper_bound; i++)
3587 if (stack_usage_map[i]
3588 /* Don't store things in the fixed argument area at this point;
3589 it has already been saved. */
3590 && i > reg_parm_stack_space)
3593 if (i != upper_bound)
3595 /* We need to make a save area. See what mode we can make it. */
3596 enum machine_mode save_mode
3597 = mode_for_size (argvec[argnum].size.constant * BITS_PER_UNIT,
3604 plus_constant (argblock,
3605 argvec[argnum].offset.constant)));
3606 argvec[argnum].save_area = gen_reg_rtx (save_mode);
3608 emit_move_insn (argvec[argnum].save_area, stack_area);
3611 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
3612 argblock, GEN_INT (argvec[argnum].offset.constant),
3613 reg_parm_stack_space, ARGS_SIZE_RTX (alignment_pad));
3615 #ifdef ACCUMULATE_OUTGOING_ARGS
3616 /* Now mark the segment we just used. */
3617 for (i = lower_bound; i < upper_bound; i++)
3618 stack_usage_map[i] = 1;
3625 #ifndef PUSH_ARGS_REVERSED
3626 #ifdef PREFERRED_STACK_BOUNDARY
3627 /* If we pushed args in forward order, perform stack alignment
3628 after pushing the last arg. */
3630 anti_adjust_stack (GEN_INT (args_size.constant
3631 - original_args_size.constant));
3635 #ifdef PUSH_ARGS_REVERSED
3641 fun = prepare_call_address (fun, NULL_TREE, &call_fusage, 0);
3643 /* Now load any reg parms into their regs. */
3645 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3646 are to be pushed. */
3647 for (count = 0; count < nargs; count++, argnum += inc)
3649 register rtx val = argvec[argnum].value;
3650 rtx reg = argvec[argnum].reg;
3651 int partial = argvec[argnum].partial;
3653 if (reg != 0 && partial == 0)
3654 emit_move_insn (reg, val);
3659 /* For version 1.37, try deleting this entirely. */
3664 /* Any regs containing parms remain in use through the call. */
3665 for (count = 0; count < nargs; count++)
3666 if (argvec[count].reg != 0)
3667 use_reg (&call_fusage, argvec[count].reg);
3669 /* Pass the function the address in which to return a structure value. */
3670 if (mem_value != 0 && struct_value_rtx != 0 && ! pcc_struct_value)
3672 emit_move_insn (struct_value_rtx,
3674 force_operand (XEXP (mem_value, 0),
3676 if (GET_CODE (struct_value_rtx) == REG)
3677 use_reg (&call_fusage, struct_value_rtx);
3680 /* Don't allow popping to be deferred, since then
3681 cse'ing of library calls could delete a call and leave the pop. */
3684 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
3685 will set inhibit_defer_pop to that value. */
3686 /* See the comment in emit_library_call about the function type we build
3690 get_identifier (XSTR (orgfun, 0)),
3691 build_function_type (type_for_mode (outmode, 0), NULL_TREE),
3692 original_args_size.constant, args_size.constant,
3694 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
3695 mem_value == 0 ? hard_libcall_value (outmode) : NULL_RTX,
3696 old_inhibit_defer_pop + 1, call_fusage, is_const);
3698 /* Now restore inhibit_defer_pop to its actual original value. */
3703 /* Copy the value to the right place. */
3704 if (outmode != VOIDmode)
3710 if (value != mem_value)
3711 emit_move_insn (value, mem_value);
3713 else if (value != 0)
3714 emit_move_insn (value, hard_libcall_value (outmode));
3716 value = hard_libcall_value (outmode);
3719 #ifdef ACCUMULATE_OUTGOING_ARGS
3720 #ifdef REG_PARM_STACK_SPACE
3723 enum machine_mode save_mode = GET_MODE (save_area);
3724 #ifdef ARGS_GROW_DOWNWARD
3726 = gen_rtx_MEM (save_mode,
3727 memory_address (save_mode,
3728 plus_constant (argblock,
3732 = gen_rtx_MEM (save_mode,
3733 memory_address (save_mode,
3734 plus_constant (argblock, low_to_save)));
3736 if (save_mode != BLKmode)
3737 emit_move_insn (stack_area, save_area);
3739 emit_block_move (stack_area, validize_mem (save_area),
3740 GEN_INT (high_to_save - low_to_save + 1),
3741 PARM_BOUNDARY / BITS_PER_UNIT);
3745 /* If we saved any argument areas, restore them. */
3746 for (count = 0; count < nargs; count++)
3747 if (argvec[count].save_area)
3749 enum machine_mode save_mode = GET_MODE (argvec[count].save_area);
3751 = gen_rtx_MEM (save_mode,
3754 plus_constant (argblock,
3755 argvec[count].offset.constant)));
3757 emit_move_insn (stack_area, argvec[count].save_area);
3760 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3761 stack_usage_map = initial_stack_usage_map;
3768 /* Return an rtx which represents a suitable home on the stack
3769 given TYPE, the type of the argument looking for a home.
3770 This is called only for BLKmode arguments.
3772 SIZE is the size needed for this target.
3773 ARGS_ADDR is the address of the bottom of the argument block for this call.
3774 OFFSET describes this parameter's offset into ARGS_ADDR. It is meaningless
3775 if this machine uses push insns. */
3778 target_for_arg (type, size, args_addr, offset)
3782 struct args_size offset;
3785 rtx offset_rtx = ARGS_SIZE_RTX (offset);
3787 /* We do not call memory_address if possible,
3788 because we want to address as close to the stack
3789 as possible. For non-variable sized arguments,
3790 this will be stack-pointer relative addressing. */
3791 if (GET_CODE (offset_rtx) == CONST_INT)
3792 target = plus_constant (args_addr, INTVAL (offset_rtx));
3795 /* I have no idea how to guarantee that this
3796 will work in the presence of register parameters. */
3797 target = gen_rtx_PLUS (Pmode, args_addr, offset_rtx);
3798 target = memory_address (QImode, target);
3801 return gen_rtx_MEM (BLKmode, target);
3805 /* Store a single argument for a function call
3806 into the register or memory area where it must be passed.
3807 *ARG describes the argument value and where to pass it.
3809 ARGBLOCK is the address of the stack-block for all the arguments,
3810 or 0 on a machine where arguments are pushed individually.
3812 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
3813 so must be careful about how the stack is used.
3815 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
3816 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
3817 that we need not worry about saving and restoring the stack.
3819 FNDECL is the declaration of the function we are calling. */
3822 store_one_arg (arg, argblock, may_be_alloca, variable_size,
3823 reg_parm_stack_space)
3824 struct arg_data *arg;
3827 int variable_size ATTRIBUTE_UNUSED;
3828 int reg_parm_stack_space;
3830 register tree pval = arg->tree_value;
3834 #ifdef ACCUMULATE_OUTGOING_ARGS
3835 int i, lower_bound = 0, upper_bound = 0;
3838 if (TREE_CODE (pval) == ERROR_MARK)
3841 /* Push a new temporary level for any temporaries we make for
3845 #ifdef ACCUMULATE_OUTGOING_ARGS
3846 /* If this is being stored into a pre-allocated, fixed-size, stack area,
3847 save any previous data at that location. */
3848 if (argblock && ! variable_size && arg->stack)
3850 #ifdef ARGS_GROW_DOWNWARD
3851 /* stack_slot is negative, but we want to index stack_usage_map
3852 with positive values. */
3853 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
3854 upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
3858 lower_bound = upper_bound - arg->size.constant;
3860 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
3861 lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
3865 upper_bound = lower_bound + arg->size.constant;
3868 for (i = lower_bound; i < upper_bound; i++)
3869 if (stack_usage_map[i]
3870 /* Don't store things in the fixed argument area at this point;
3871 it has already been saved. */
3872 && i > reg_parm_stack_space)
3875 if (i != upper_bound)
3877 /* We need to make a save area. See what mode we can make it. */
3878 enum machine_mode save_mode
3879 = mode_for_size (arg->size.constant * BITS_PER_UNIT, MODE_INT, 1);
3881 = gen_rtx_MEM (save_mode,
3882 memory_address (save_mode,
3883 XEXP (arg->stack_slot, 0)));
3885 if (save_mode == BLKmode)
3887 arg->save_area = assign_stack_temp (BLKmode,
3888 arg->size.constant, 0);
3889 MEM_SET_IN_STRUCT_P (arg->save_area,
3890 AGGREGATE_TYPE_P (TREE_TYPE
3891 (arg->tree_value)));
3892 preserve_temp_slots (arg->save_area);
3893 emit_block_move (validize_mem (arg->save_area), stack_area,
3894 GEN_INT (arg->size.constant),
3895 PARM_BOUNDARY / BITS_PER_UNIT);
3899 arg->save_area = gen_reg_rtx (save_mode);
3900 emit_move_insn (arg->save_area, stack_area);
3905 /* Now that we have saved any slots that will be overwritten by this
3906 store, mark all slots this store will use. We must do this before
3907 we actually expand the argument since the expansion itself may
3908 trigger library calls which might need to use the same stack slot. */
3909 if (argblock && ! variable_size && arg->stack)
3910 for (i = lower_bound; i < upper_bound; i++)
3911 stack_usage_map[i] = 1;
3914 /* If this isn't going to be placed on both the stack and in registers,
3915 set up the register and number of words. */
3916 if (! arg->pass_on_stack)
3917 reg = arg->reg, partial = arg->partial;
3919 if (reg != 0 && partial == 0)
3920 /* Being passed entirely in a register. We shouldn't be called in
3924 /* If this arg needs special alignment, don't load the registers
3926 if (arg->n_aligned_regs != 0)
3929 /* If this is being passed partially in a register, we can't evaluate
3930 it directly into its stack slot. Otherwise, we can. */
3931 if (arg->value == 0)
3933 #ifdef ACCUMULATE_OUTGOING_ARGS
3934 /* stack_arg_under_construction is nonzero if a function argument is
3935 being evaluated directly into the outgoing argument list and
3936 expand_call must take special action to preserve the argument list
3937 if it is called recursively.
3939 For scalar function arguments stack_usage_map is sufficient to
3940 determine which stack slots must be saved and restored. Scalar
3941 arguments in general have pass_on_stack == 0.
3943 If this argument is initialized by a function which takes the
3944 address of the argument (a C++ constructor or a C function
3945 returning a BLKmode structure), then stack_usage_map is
3946 insufficient and expand_call must push the stack around the
3947 function call. Such arguments have pass_on_stack == 1.
3949 Note that it is always safe to set stack_arg_under_construction,
3950 but this generates suboptimal code if set when not needed. */
3952 if (arg->pass_on_stack)
3953 stack_arg_under_construction++;
3955 arg->value = expand_expr (pval,
3957 || TYPE_MODE (TREE_TYPE (pval)) != arg->mode)
3958 ? NULL_RTX : arg->stack,
3961 /* If we are promoting object (or for any other reason) the mode
3962 doesn't agree, convert the mode. */
3964 if (arg->mode != TYPE_MODE (TREE_TYPE (pval)))
3965 arg->value = convert_modes (arg->mode, TYPE_MODE (TREE_TYPE (pval)),
3966 arg->value, arg->unsignedp);
3968 #ifdef ACCUMULATE_OUTGOING_ARGS
3969 if (arg->pass_on_stack)
3970 stack_arg_under_construction--;
3974 /* Don't allow anything left on stack from computation
3975 of argument to alloca. */
3977 do_pending_stack_adjust ();
3979 if (arg->value == arg->stack)
3981 /* If the value is already in the stack slot, we are done. */
3982 if (current_function_check_memory_usage && GET_CODE (arg->stack) == MEM)
3984 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
3985 XEXP (arg->stack, 0), Pmode,
3986 ARGS_SIZE_RTX (arg->size),
3987 TYPE_MODE (sizetype),
3988 GEN_INT (MEMORY_USE_RW),
3989 TYPE_MODE (integer_type_node));
3992 else if (arg->mode != BLKmode)
3996 /* Argument is a scalar, not entirely passed in registers.
3997 (If part is passed in registers, arg->partial says how much
3998 and emit_push_insn will take care of putting it there.)
4000 Push it, and if its size is less than the
4001 amount of space allocated to it,
4002 also bump stack pointer by the additional space.
4003 Note that in C the default argument promotions
4004 will prevent such mismatches. */
4006 size = GET_MODE_SIZE (arg->mode);
4007 /* Compute how much space the push instruction will push.
4008 On many machines, pushing a byte will advance the stack
4009 pointer by a halfword. */
4010 #ifdef PUSH_ROUNDING
4011 size = PUSH_ROUNDING (size);
4015 /* Compute how much space the argument should get:
4016 round up to a multiple of the alignment for arguments. */
4017 if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)))
4018 used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
4019 / (PARM_BOUNDARY / BITS_PER_UNIT))
4020 * (PARM_BOUNDARY / BITS_PER_UNIT));
4022 /* This isn't already where we want it on the stack, so put it there.
4023 This can either be done with push or copy insns. */
4024 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX, 0,
4025 partial, reg, used - size, argblock,
4026 ARGS_SIZE_RTX (arg->offset), reg_parm_stack_space,
4027 ARGS_SIZE_RTX (arg->alignment_pad));
4032 /* BLKmode, at least partly to be pushed. */
4034 register int excess;
4037 /* Pushing a nonscalar.
4038 If part is passed in registers, PARTIAL says how much
4039 and emit_push_insn will take care of putting it there. */
4041 /* Round its size up to a multiple
4042 of the allocation unit for arguments. */
4044 if (arg->size.var != 0)
4047 size_rtx = ARGS_SIZE_RTX (arg->size);
4051 /* PUSH_ROUNDING has no effect on us, because
4052 emit_push_insn for BLKmode is careful to avoid it. */
4053 excess = (arg->size.constant - int_size_in_bytes (TREE_TYPE (pval))
4054 + partial * UNITS_PER_WORD);
4055 size_rtx = expr_size (pval);
4058 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
4059 TYPE_ALIGN (TREE_TYPE (pval)) / BITS_PER_UNIT, partial,
4060 reg, excess, argblock, ARGS_SIZE_RTX (arg->offset),
4061 reg_parm_stack_space,
4062 ARGS_SIZE_RTX (arg->alignment_pad));
4066 /* Unless this is a partially-in-register argument, the argument is now
4069 ??? Note that this can change arg->value from arg->stack to
4070 arg->stack_slot and it matters when they are not the same.
4071 It isn't totally clear that this is correct in all cases. */
4073 arg->value = arg->stack_slot;
4075 /* Once we have pushed something, pops can't safely
4076 be deferred during the rest of the arguments. */
4079 /* ANSI doesn't require a sequence point here,
4080 but PCC has one, so this will avoid some problems. */
4083 /* Free any temporary slots made in processing this argument. Show
4084 that we might have taken the address of something and pushed that
4086 preserve_temp_slots (NULL_RTX);