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 FUNCTION_OK_FOR_SIBCALL
36 #define FUNCTION_OK_FOR_SIBCALL(DECL) 1
39 #if !defined PREFERRED_STACK_BOUNDARY && defined STACK_BOUNDARY
40 #define PREFERRED_STACK_BOUNDARY STACK_BOUNDARY
43 /* Decide whether a function's arguments should be processed
44 from first to last or from last to first.
46 They should if the stack and args grow in opposite directions, but
47 only if we have push insns. */
51 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
52 #define PUSH_ARGS_REVERSED /* If it's last to first */
57 /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */
58 #define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
60 /* Data structure and subroutines used within expand_call. */
64 /* Tree node for this argument. */
66 /* Mode for value; TYPE_MODE unless promoted. */
67 enum machine_mode mode;
68 /* Current RTL value for argument, or 0 if it isn't precomputed. */
70 /* Initially-compute RTL value for argument; only for const functions. */
72 /* Register to pass this argument in, 0 if passed on stack, or an
73 PARALLEL if the arg is to be copied into multiple non-contiguous
76 /* If REG was promoted from the actual mode of the argument expression,
77 indicates whether the promotion is sign- or zero-extended. */
79 /* Number of registers to use. 0 means put the whole arg in registers.
80 Also 0 if not passed in registers. */
82 /* Non-zero if argument must be passed on stack.
83 Note that some arguments may be passed on the stack
84 even though pass_on_stack is zero, just because FUNCTION_ARG says so.
85 pass_on_stack identifies arguments that *cannot* go in registers. */
87 /* Offset of this argument from beginning of stack-args. */
88 struct args_size offset;
89 /* Similar, but offset to the start of the stack slot. Different from
90 OFFSET if this arg pads downward. */
91 struct args_size slot_offset;
92 /* Size of this argument on the stack, rounded up for any padding it gets,
93 parts of the argument passed in registers do not count.
94 If REG_PARM_STACK_SPACE is defined, then register parms
95 are counted here as well. */
96 struct args_size size;
97 /* Location on the stack at which parameter should be stored. The store
98 has already been done if STACK == VALUE. */
100 /* Location on the stack of the start of this argument slot. This can
101 differ from STACK if this arg pads downward. This location is known
102 to be aligned to FUNCTION_ARG_BOUNDARY. */
104 #ifdef ACCUMULATE_OUTGOING_ARGS
105 /* Place that this stack area has been saved, if needed. */
108 /* If an argument's alignment does not permit direct copying into registers,
109 copy in smaller-sized pieces into pseudos. These are stored in a
110 block pointed to by this field. The next field says how many
111 word-sized pseudos we made. */
114 /* The amount that the stack pointer needs to be adjusted to
115 force alignment for the next argument. */
116 struct args_size alignment_pad;
119 #ifdef ACCUMULATE_OUTGOING_ARGS
120 /* A vector of one char per byte of stack space. A byte if non-zero if
121 the corresponding stack location has been used.
122 This vector is used to prevent a function call within an argument from
123 clobbering any stack already set up. */
124 static char *stack_usage_map;
126 /* Size of STACK_USAGE_MAP. */
127 static int highest_outgoing_arg_in_use;
129 /* stack_arg_under_construction is nonzero when an argument may be
130 initialized with a constructor call (including a C function that
131 returns a BLKmode struct) and expand_call must take special action
132 to make sure the object being constructed does not overlap the
133 argument list for the constructor call. */
134 int stack_arg_under_construction;
137 static int calls_function PARAMS ((tree, int));
138 static int calls_function_1 PARAMS ((tree, int));
140 #define ECF_IS_CONST 1
141 #define ECF_NOTHROW 2
142 #define ECF_SIBCALL 4
143 static void emit_call_1 PARAMS ((rtx, tree, tree, HOST_WIDE_INT,
144 HOST_WIDE_INT, HOST_WIDE_INT, rtx,
145 rtx, int, rtx, int));
146 static void precompute_register_parameters PARAMS ((int,
149 static void store_one_arg PARAMS ((struct arg_data *, rtx, int, int,
151 static void store_unaligned_arguments_into_pseudos PARAMS ((struct arg_data *,
153 static int finalize_must_preallocate PARAMS ((int, int,
155 struct args_size *));
156 static void precompute_arguments PARAMS ((int, int, int,
158 struct args_size *));
159 static int compute_argument_block_size PARAMS ((int,
162 static void initialize_argument_information PARAMS ((int,
169 static void compute_argument_addresses PARAMS ((struct arg_data *,
171 static rtx rtx_for_function_call PARAMS ((tree, tree));
172 static void load_register_parameters PARAMS ((struct arg_data *,
174 static int libfunc_nothrow PARAMS ((rtx));
176 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
177 static rtx save_fixed_argument_area PARAMS ((int, rtx, int *, int *));
178 static void restore_fixed_argument_area PARAMS ((rtx, rtx, int, int));
181 /* If WHICH is 1, return 1 if EXP contains a call to the built-in function
184 If WHICH is 0, return 1 if EXP contains a call to any function.
185 Actually, we only need return 1 if evaluating EXP would require pushing
186 arguments on the stack, but that is too difficult to compute, so we just
187 assume any function call might require the stack. */
189 static tree calls_function_save_exprs;
192 calls_function (exp, which)
197 calls_function_save_exprs = 0;
198 val = calls_function_1 (exp, which);
199 calls_function_save_exprs = 0;
204 calls_function_1 (exp, which)
209 enum tree_code code = TREE_CODE (exp);
210 int type = TREE_CODE_CLASS (code);
211 int length = tree_code_length[(int) code];
213 /* If this code is language-specific, we don't know what it will do. */
214 if ((int) code >= NUM_TREE_CODES)
217 /* Only expressions and references can contain calls. */
218 if (type != 'e' && type != '<' && type != '1' && type != '2' && type != 'r'
227 else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
228 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
231 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
233 if ((DECL_BUILT_IN (fndecl)
234 && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
235 && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA)
236 || (DECL_SAVED_INSNS (fndecl)
237 && DECL_SAVED_INSNS (fndecl)->calls_alloca))
241 /* Third operand is RTL. */
246 if (SAVE_EXPR_RTL (exp) != 0)
248 if (value_member (exp, calls_function_save_exprs))
250 calls_function_save_exprs = tree_cons (NULL_TREE, exp,
251 calls_function_save_exprs);
252 return (TREE_OPERAND (exp, 0) != 0
253 && calls_function_1 (TREE_OPERAND (exp, 0), which));
259 for (local = BLOCK_VARS (exp); local; local = TREE_CHAIN (local))
260 if (DECL_INITIAL (local) != 0
261 && calls_function_1 (DECL_INITIAL (local), which))
265 register tree subblock;
267 for (subblock = BLOCK_SUBBLOCKS (exp);
269 subblock = TREE_CHAIN (subblock))
270 if (calls_function_1 (subblock, which))
275 case METHOD_CALL_EXPR:
279 case WITH_CLEANUP_EXPR:
290 for (i = 0; i < length; i++)
291 if (TREE_OPERAND (exp, i) != 0
292 && calls_function_1 (TREE_OPERAND (exp, i), which))
298 /* Force FUNEXP into a form suitable for the address of a CALL,
299 and return that as an rtx. Also load the static chain register
300 if FNDECL is a nested function.
302 CALL_FUSAGE points to a variable holding the prospective
303 CALL_INSN_FUNCTION_USAGE information. */
306 prepare_call_address (funexp, fndecl, call_fusage, reg_parm_seen)
312 rtx static_chain_value = 0;
314 funexp = protect_from_queue (funexp, 0);
317 /* Get possible static chain value for nested function in C. */
318 static_chain_value = lookup_static_chain (fndecl);
320 /* Make a valid memory address and copy constants thru pseudo-regs,
321 but not for a constant address if -fno-function-cse. */
322 if (GET_CODE (funexp) != SYMBOL_REF)
323 /* If we are using registers for parameters, force the
324 function address into a register now. */
325 funexp = ((SMALL_REGISTER_CLASSES && reg_parm_seen)
326 ? force_not_mem (memory_address (FUNCTION_MODE, funexp))
327 : memory_address (FUNCTION_MODE, funexp));
330 #ifndef NO_FUNCTION_CSE
331 if (optimize && ! flag_no_function_cse)
332 #ifdef NO_RECURSIVE_FUNCTION_CSE
333 if (fndecl != current_function_decl)
335 funexp = force_reg (Pmode, funexp);
339 if (static_chain_value != 0)
341 emit_move_insn (static_chain_rtx, static_chain_value);
343 if (GET_CODE (static_chain_rtx) == REG)
344 use_reg (call_fusage, static_chain_rtx);
350 /* Generate instructions to call function FUNEXP,
351 and optionally pop the results.
352 The CALL_INSN is the first insn generated.
354 FNDECL is the declaration node of the function. This is given to the
355 macro RETURN_POPS_ARGS to determine whether this function pops its own args.
357 FUNTYPE is the data type of the function. This is given to the macro
358 RETURN_POPS_ARGS to determine whether this function pops its own args.
359 We used to allow an identifier for library functions, but that doesn't
360 work when the return type is an aggregate type and the calling convention
361 says that the pointer to this aggregate is to be popped by the callee.
363 STACK_SIZE is the number of bytes of arguments on the stack,
364 ROUNDED_STACK_SIZE is that number rounded up to
365 PREFERRED_STACK_BOUNDARY; zero if the size is variable. This is
366 both to put into the call insn and to generate explicit popping
369 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
370 It is zero if this call doesn't want a structure value.
372 NEXT_ARG_REG is the rtx that results from executing
373 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1)
374 just after all the args have had their registers assigned.
375 This could be whatever you like, but normally it is the first
376 arg-register beyond those used for args in this call,
377 or 0 if all the arg-registers are used in this call.
378 It is passed on to `gen_call' so you can put this info in the call insn.
380 VALREG is a hard register in which a value is returned,
381 or 0 if the call does not return a value.
383 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
384 the args to this call were processed.
385 We restore `inhibit_defer_pop' to that value.
387 CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
388 denote registers used by the called function.
390 IS_CONST is true if this is a `const' call. */
393 emit_call_1 (funexp, fndecl, funtype, stack_size, rounded_stack_size,
394 struct_value_size, next_arg_reg, valreg, old_inhibit_defer_pop,
395 call_fusage, ecf_flags)
397 tree fndecl ATTRIBUTE_UNUSED;
398 tree funtype ATTRIBUTE_UNUSED;
399 HOST_WIDE_INT stack_size ATTRIBUTE_UNUSED;
400 HOST_WIDE_INT rounded_stack_size;
401 HOST_WIDE_INT struct_value_size ATTRIBUTE_UNUSED;
404 int old_inhibit_defer_pop;
408 rtx rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
409 #if defined (HAVE_call) && defined (HAVE_call_value)
410 rtx struct_value_size_rtx = GEN_INT (struct_value_size);
413 #ifndef ACCUMULATE_OUTGOING_ARGS
414 int already_popped = 0;
415 HOST_WIDE_INT n_popped = RETURN_POPS_ARGS (fndecl, funtype, stack_size);
418 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
419 and we don't want to load it into a register as an optimization,
420 because prepare_call_address already did it if it should be done. */
421 if (GET_CODE (funexp) != SYMBOL_REF)
422 funexp = memory_address (FUNCTION_MODE, funexp);
424 #ifndef ACCUMULATE_OUTGOING_ARGS
425 #if defined (HAVE_sibcall_pop) && defined (HAVE_sibcall_value_pop)
426 if ((ecf_flags & ECF_SIBCALL)
427 && HAVE_sibcall_pop && HAVE_sibcall_value_pop
428 && (RETURN_POPS_ARGS (fndecl, funtype, stack_size) > 0
431 rtx n_pop = GEN_INT (RETURN_POPS_ARGS (fndecl, funtype, stack_size));
434 /* If this subroutine pops its own args, record that in the call insn
435 if possible, for the sake of frame pointer elimination. */
438 pat = gen_sibcall_value_pop (valreg,
439 gen_rtx_MEM (FUNCTION_MODE, funexp),
440 rounded_stack_size_rtx, next_arg_reg,
443 pat = gen_sibcall_pop (gen_rtx_MEM (FUNCTION_MODE, funexp),
444 rounded_stack_size_rtx, next_arg_reg, n_pop);
446 emit_call_insn (pat);
452 #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
453 /* If the target has "call" or "call_value" insns, then prefer them
454 if no arguments are actually popped. If the target does not have
455 "call" or "call_value" insns, then we must use the popping versions
456 even if the call has no arguments to pop. */
457 #if defined (HAVE_call) && defined (HAVE_call_value)
458 if (HAVE_call && HAVE_call_value && HAVE_call_pop && HAVE_call_value_pop
461 if (HAVE_call_pop && HAVE_call_value_pop)
464 rtx n_pop = GEN_INT (n_popped);
467 /* If this subroutine pops its own args, record that in the call insn
468 if possible, for the sake of frame pointer elimination. */
471 pat = gen_call_value_pop (valreg,
472 gen_rtx_MEM (FUNCTION_MODE, funexp),
473 rounded_stack_size_rtx, next_arg_reg, n_pop);
475 pat = gen_call_pop (gen_rtx_MEM (FUNCTION_MODE, funexp),
476 rounded_stack_size_rtx, next_arg_reg, n_pop);
478 emit_call_insn (pat);
485 #if defined (HAVE_sibcall) && defined (HAVE_sibcall_value)
486 if ((ecf_flags & ECF_SIBCALL)
487 && HAVE_sibcall && HAVE_sibcall_value)
490 emit_call_insn (gen_sibcall_value (valreg,
491 gen_rtx_MEM (FUNCTION_MODE, funexp),
492 rounded_stack_size_rtx,
493 next_arg_reg, NULL_RTX));
495 emit_call_insn (gen_sibcall (gen_rtx_MEM (FUNCTION_MODE, funexp),
496 rounded_stack_size_rtx, next_arg_reg,
497 struct_value_size_rtx));
502 #if defined (HAVE_call) && defined (HAVE_call_value)
503 if (HAVE_call && HAVE_call_value)
506 emit_call_insn (gen_call_value (valreg,
507 gen_rtx_MEM (FUNCTION_MODE, funexp),
508 rounded_stack_size_rtx, next_arg_reg,
511 emit_call_insn (gen_call (gen_rtx_MEM (FUNCTION_MODE, funexp),
512 rounded_stack_size_rtx, next_arg_reg,
513 struct_value_size_rtx));
519 /* Find the CALL insn we just emitted. */
520 for (call_insn = get_last_insn ();
521 call_insn && GET_CODE (call_insn) != CALL_INSN;
522 call_insn = PREV_INSN (call_insn))
528 /* Put the register usage information on the CALL. If there is already
529 some usage information, put ours at the end. */
530 if (CALL_INSN_FUNCTION_USAGE (call_insn))
534 for (link = CALL_INSN_FUNCTION_USAGE (call_insn); XEXP (link, 1) != 0;
535 link = XEXP (link, 1))
538 XEXP (link, 1) = call_fusage;
541 CALL_INSN_FUNCTION_USAGE (call_insn) = call_fusage;
543 /* If this is a const call, then set the insn's unchanging bit. */
544 if (ecf_flags & ECF_IS_CONST)
545 CONST_CALL_P (call_insn) = 1;
547 /* If this call can't throw, attach a REG_EH_REGION reg note to that
549 if (ecf_flags & ECF_NOTHROW)
550 REG_NOTES (call_insn) = gen_rtx_EXPR_LIST (REG_EH_REGION, const0_rtx,
551 REG_NOTES (call_insn));
553 SIBLING_CALL_P (call_insn) = ((ecf_flags & ECF_SIBCALL) != 0);
555 /* Restore this now, so that we do defer pops for this call's args
556 if the context of the call as a whole permits. */
557 inhibit_defer_pop = old_inhibit_defer_pop;
559 #ifndef ACCUMULATE_OUTGOING_ARGS
560 /* If returning from the subroutine does not automatically pop the args,
561 we need an instruction to pop them sooner or later.
562 Perhaps do it now; perhaps just record how much space to pop later.
564 If returning from the subroutine does pop the args, indicate that the
565 stack pointer will be changed. */
567 /* The space for the args is no longer waiting for the call; either it
568 was popped by the call, or it'll be popped below. */
569 arg_space_so_far -= rounded_stack_size;
574 CALL_INSN_FUNCTION_USAGE (call_insn)
575 = gen_rtx_EXPR_LIST (VOIDmode,
576 gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx),
577 CALL_INSN_FUNCTION_USAGE (call_insn));
578 rounded_stack_size -= n_popped;
579 rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
582 if (rounded_stack_size != 0)
584 if (flag_defer_pop && inhibit_defer_pop == 0
585 && !(ecf_flags & ECF_IS_CONST))
586 pending_stack_adjust += rounded_stack_size;
588 adjust_stack (rounded_stack_size_rtx);
593 /* Determine if the function identified by NAME and FNDECL is one with
594 special properties we wish to know about.
596 For example, if the function might return more than one time (setjmp), then
597 set RETURNS_TWICE to a nonzero value.
599 Similarly set IS_LONGJMP for if the function is in the longjmp family.
601 Set IS_MALLOC for any of the standard memory allocation functions which
602 allocate from the heap.
604 Set MAY_BE_ALLOCA for any memory allocation function that might allocate
605 space from the stack such as alloca. */
608 special_function_p (fndecl, returns_twice, is_longjmp, fork_or_exec,
609 is_malloc, may_be_alloca)
622 /* The function decl may have the `malloc' attribute. */
623 *is_malloc = fndecl && DECL_IS_MALLOC (fndecl);
626 && fndecl && DECL_NAME (fndecl)
627 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 17
628 /* Exclude functions not at the file scope, or not `extern',
629 since they are not the magic functions we would otherwise
631 && DECL_CONTEXT (fndecl) == NULL_TREE && TREE_PUBLIC (fndecl))
633 char *name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
636 /* We assume that alloca will always be called by name. It
637 makes no sense to pass it as a pointer-to-function to
638 anything that does not understand its behavior. */
640 = (((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 6
642 && ! strcmp (name, "alloca"))
643 || (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 16
645 && ! strcmp (name, "__builtin_alloca"))));
647 /* Disregard prefix _, __ or __x. */
650 if (name[1] == '_' && name[2] == 'x')
652 else if (name[1] == '_')
662 && (! strcmp (tname, "setjmp")
663 || ! strcmp (tname, "setjmp_syscall")))
665 && ! strcmp (tname, "sigsetjmp"))
667 && ! strcmp (tname, "savectx")));
669 && ! strcmp (tname, "siglongjmp"))
672 else if ((tname[0] == 'q' && tname[1] == 's'
673 && ! strcmp (tname, "qsetjmp"))
674 || (tname[0] == 'v' && tname[1] == 'f'
675 && ! strcmp (tname, "vfork")))
678 else if (tname[0] == 'l' && tname[1] == 'o'
679 && ! strcmp (tname, "longjmp"))
682 else if ((tname[0] == 'f' && tname[1] == 'o'
683 && ! strcmp (tname, "fork"))
684 /* Linux specific: __clone. check NAME to insist on the
685 leading underscores, to avoid polluting the ISO / POSIX
687 || (name[0] == '_' && name[1] == '_'
688 && ! strcmp (tname, "clone"))
689 || (tname[0] == 'e' && tname[1] == 'x' && tname[2] == 'e'
690 && tname[3] == 'c' && (tname[4] == 'l' || tname[4] == 'v')
692 || ((tname[5] == 'p' || tname[5] == 'e')
693 && tname[6] == '\0'))))
696 /* Do not add any more malloc-like functions to this list,
697 instead mark them as malloc functions using the malloc attribute.
698 Note, realloc is not suitable for attribute malloc since
699 it may return the same address across multiple calls.
700 C++ operator new is not suitable because it is not required
701 to return a unique pointer; indeed, the standard placement new
702 just returns its argument. */
703 else if (TYPE_MODE (TREE_TYPE (TREE_TYPE (fndecl))) == Pmode
704 && (! strcmp (tname, "malloc")
705 || ! strcmp (tname, "calloc")
706 || ! strcmp (tname, "strdup")))
711 /* Precompute all register parameters as described by ARGS, storing values
712 into fields within the ARGS array.
714 NUM_ACTUALS indicates the total number elements in the ARGS array.
716 Set REG_PARM_SEEN if we encounter a register parameter. */
719 precompute_register_parameters (num_actuals, args, reg_parm_seen)
721 struct arg_data *args;
728 for (i = 0; i < num_actuals; i++)
729 if (args[i].reg != 0 && ! args[i].pass_on_stack)
733 if (args[i].value == 0)
736 args[i].value = expand_expr (args[i].tree_value, NULL_RTX,
738 preserve_temp_slots (args[i].value);
741 /* ANSI doesn't require a sequence point here,
742 but PCC has one, so this will avoid some problems. */
746 /* If we are to promote the function arg to a wider mode,
749 if (args[i].mode != TYPE_MODE (TREE_TYPE (args[i].tree_value)))
751 = convert_modes (args[i].mode,
752 TYPE_MODE (TREE_TYPE (args[i].tree_value)),
753 args[i].value, args[i].unsignedp);
755 /* If the value is expensive, and we are inside an appropriately
756 short loop, put the value into a pseudo and then put the pseudo
759 For small register classes, also do this if this call uses
760 register parameters. This is to avoid reload conflicts while
761 loading the parameters registers. */
763 if ((! (GET_CODE (args[i].value) == REG
764 || (GET_CODE (args[i].value) == SUBREG
765 && GET_CODE (SUBREG_REG (args[i].value)) == REG)))
766 && args[i].mode != BLKmode
767 && rtx_cost (args[i].value, SET) > 2
768 && ((SMALL_REGISTER_CLASSES && *reg_parm_seen)
769 || preserve_subexpressions_p ()))
770 args[i].value = copy_to_mode_reg (args[i].mode, args[i].value);
774 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
776 /* The argument list is the property of the called routine and it
777 may clobber it. If the fixed area has been used for previous
778 parameters, we must save and restore it. */
780 save_fixed_argument_area (reg_parm_stack_space, argblock,
781 low_to_save, high_to_save)
782 int reg_parm_stack_space;
788 rtx save_area = NULL_RTX;
790 /* Compute the boundary of the that needs to be saved, if any. */
791 #ifdef ARGS_GROW_DOWNWARD
792 for (i = 0; i < reg_parm_stack_space + 1; i++)
794 for (i = 0; i < reg_parm_stack_space; i++)
797 if (i >= highest_outgoing_arg_in_use
798 || stack_usage_map[i] == 0)
801 if (*low_to_save == -1)
807 if (*low_to_save >= 0)
809 int num_to_save = *high_to_save - *low_to_save + 1;
810 enum machine_mode save_mode
811 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
814 /* If we don't have the required alignment, must do this in BLKmode. */
815 if ((*low_to_save & (MIN (GET_MODE_SIZE (save_mode),
816 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
819 #ifdef ARGS_GROW_DOWNWARD
820 stack_area = gen_rtx_MEM (save_mode,
821 memory_address (save_mode,
822 plus_constant (argblock,
825 stack_area = gen_rtx_MEM (save_mode,
826 memory_address (save_mode,
827 plus_constant (argblock,
830 if (save_mode == BLKmode)
832 save_area = assign_stack_temp (BLKmode, num_to_save, 0);
833 /* Cannot use emit_block_move here because it can be done by a library
834 call which in turn gets into this place again and deadly infinite
835 recursion happens. */
836 move_by_pieces (validize_mem (save_area), stack_area, num_to_save,
837 PARM_BOUNDARY / BITS_PER_UNIT);
841 save_area = gen_reg_rtx (save_mode);
842 emit_move_insn (save_area, stack_area);
849 restore_fixed_argument_area (save_area, argblock, high_to_save, low_to_save)
855 enum machine_mode save_mode = GET_MODE (save_area);
856 #ifdef ARGS_GROW_DOWNWARD
858 = gen_rtx_MEM (save_mode,
859 memory_address (save_mode,
860 plus_constant (argblock,
864 = gen_rtx_MEM (save_mode,
865 memory_address (save_mode,
866 plus_constant (argblock,
870 if (save_mode != BLKmode)
871 emit_move_insn (stack_area, save_area);
873 /* Cannot use emit_block_move here because it can be done by a library
874 call which in turn gets into this place again and deadly infinite
875 recursion happens. */
876 move_by_pieces (stack_area, validize_mem (save_area),
877 high_to_save - low_to_save + 1,
878 PARM_BOUNDARY / BITS_PER_UNIT);
882 /* If any elements in ARGS refer to parameters that are to be passed in
883 registers, but not in memory, and whose alignment does not permit a
884 direct copy into registers. Copy the values into a group of pseudos
885 which we will later copy into the appropriate hard registers.
887 Pseudos for each unaligned argument will be stored into the array
888 args[argnum].aligned_regs. The caller is responsible for deallocating
889 the aligned_regs array if it is nonzero. */
892 store_unaligned_arguments_into_pseudos (args, num_actuals)
893 struct arg_data *args;
898 for (i = 0; i < num_actuals; i++)
899 if (args[i].reg != 0 && ! args[i].pass_on_stack
900 && args[i].mode == BLKmode
901 && (TYPE_ALIGN (TREE_TYPE (args[i].tree_value))
902 < (unsigned int) MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD)))
904 int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
905 int big_endian_correction = 0;
907 args[i].n_aligned_regs
908 = args[i].partial ? args[i].partial
909 : (bytes + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
911 args[i].aligned_regs = (rtx *) xmalloc (sizeof (rtx)
912 * args[i].n_aligned_regs);
914 /* Structures smaller than a word are aligned to the least
915 significant byte (to the right). On a BYTES_BIG_ENDIAN machine,
916 this means we must skip the empty high order bytes when
917 calculating the bit offset. */
918 if (BYTES_BIG_ENDIAN && bytes < UNITS_PER_WORD)
919 big_endian_correction = (BITS_PER_WORD - (bytes * BITS_PER_UNIT));
921 for (j = 0; j < args[i].n_aligned_regs; j++)
923 rtx reg = gen_reg_rtx (word_mode);
924 rtx word = operand_subword_force (args[i].value, j, BLKmode);
925 int bitsize = MIN (bytes * BITS_PER_UNIT, BITS_PER_WORD);
926 int bitalign = TYPE_ALIGN (TREE_TYPE (args[i].tree_value));
928 args[i].aligned_regs[j] = reg;
930 /* There is no need to restrict this code to loading items
931 in TYPE_ALIGN sized hunks. The bitfield instructions can
932 load up entire word sized registers efficiently.
934 ??? This may not be needed anymore.
935 We use to emit a clobber here but that doesn't let later
936 passes optimize the instructions we emit. By storing 0 into
937 the register later passes know the first AND to zero out the
938 bitfield being set in the register is unnecessary. The store
939 of 0 will be deleted as will at least the first AND. */
941 emit_move_insn (reg, const0_rtx);
943 bytes -= bitsize / BITS_PER_UNIT;
944 store_bit_field (reg, bitsize, big_endian_correction, word_mode,
945 extract_bit_field (word, bitsize, 0, 1,
948 bitalign / BITS_PER_UNIT,
950 bitalign / BITS_PER_UNIT, BITS_PER_WORD);
955 /* Fill in ARGS_SIZE and ARGS array based on the parameters found in
958 NUM_ACTUALS is the total number of parameters.
960 N_NAMED_ARGS is the total number of named arguments.
962 FNDECL is the tree code for the target of this call (if known)
964 ARGS_SO_FAR holds state needed by the target to know where to place
967 REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
968 for arguments which are passed in registers.
970 OLD_STACK_LEVEL is a pointer to an rtx which olds the old stack level
971 and may be modified by this routine.
973 OLD_PENDING_ADJ, MUST_PREALLOCATE and IS_CONST are pointers to integer
974 flags which may may be modified by this routine. */
977 initialize_argument_information (num_actuals, args, args_size, n_named_args,
978 actparms, fndecl, args_so_far,
979 reg_parm_stack_space, old_stack_level,
980 old_pending_adj, must_preallocate, is_const)
981 int num_actuals ATTRIBUTE_UNUSED;
982 struct arg_data *args;
983 struct args_size *args_size;
984 int n_named_args ATTRIBUTE_UNUSED;
987 CUMULATIVE_ARGS *args_so_far;
988 int reg_parm_stack_space;
989 rtx *old_stack_level;
990 int *old_pending_adj;
991 int *must_preallocate;
994 /* 1 if scanning parms front to back, -1 if scanning back to front. */
997 /* Count arg position in order args appear. */
1000 struct args_size alignment_pad;
1004 args_size->constant = 0;
1007 /* In this loop, we consider args in the order they are written.
1008 We fill up ARGS from the front or from the back if necessary
1009 so that in any case the first arg to be pushed ends up at the front. */
1011 #ifdef PUSH_ARGS_REVERSED
1012 i = num_actuals - 1, inc = -1;
1013 /* In this case, must reverse order of args
1014 so that we compute and push the last arg first. */
1019 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
1020 for (p = actparms, argpos = 0; p; p = TREE_CHAIN (p), i += inc, argpos++)
1022 tree type = TREE_TYPE (TREE_VALUE (p));
1024 enum machine_mode mode;
1026 args[i].tree_value = TREE_VALUE (p);
1028 /* Replace erroneous argument with constant zero. */
1029 if (type == error_mark_node || TYPE_SIZE (type) == 0)
1030 args[i].tree_value = integer_zero_node, type = integer_type_node;
1032 /* If TYPE is a transparent union, pass things the way we would
1033 pass the first field of the union. We have already verified that
1034 the modes are the same. */
1035 if (TYPE_TRANSPARENT_UNION (type))
1036 type = TREE_TYPE (TYPE_FIELDS (type));
1038 /* Decide where to pass this arg.
1040 args[i].reg is nonzero if all or part is passed in registers.
1042 args[i].partial is nonzero if part but not all is passed in registers,
1043 and the exact value says how many words are passed in registers.
1045 args[i].pass_on_stack is nonzero if the argument must at least be
1046 computed on the stack. It may then be loaded back into registers
1047 if args[i].reg is nonzero.
1049 These decisions are driven by the FUNCTION_... macros and must agree
1050 with those made by function.c. */
1052 /* See if this argument should be passed by invisible reference. */
1053 if ((TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
1054 && contains_placeholder_p (TYPE_SIZE (type)))
1055 || TREE_ADDRESSABLE (type)
1056 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
1057 || FUNCTION_ARG_PASS_BY_REFERENCE (*args_so_far, TYPE_MODE (type),
1058 type, argpos < n_named_args)
1062 /* If we're compiling a thunk, pass through invisible
1063 references instead of making a copy. */
1064 if (current_function_is_thunk
1065 #ifdef FUNCTION_ARG_CALLEE_COPIES
1066 || (FUNCTION_ARG_CALLEE_COPIES (*args_so_far, TYPE_MODE (type),
1067 type, argpos < n_named_args)
1068 /* If it's in a register, we must make a copy of it too. */
1069 /* ??? Is this a sufficient test? Is there a better one? */
1070 && !(TREE_CODE (args[i].tree_value) == VAR_DECL
1071 && REG_P (DECL_RTL (args[i].tree_value)))
1072 && ! TREE_ADDRESSABLE (type))
1076 /* C++ uses a TARGET_EXPR to indicate that we want to make a
1077 new object from the argument. If we are passing by
1078 invisible reference, the callee will do that for us, so we
1079 can strip off the TARGET_EXPR. This is not always safe,
1080 but it is safe in the only case where this is a useful
1081 optimization; namely, when the argument is a plain object.
1082 In that case, the frontend is just asking the backend to
1083 make a bitwise copy of the argument. */
1085 if (TREE_CODE (args[i].tree_value) == TARGET_EXPR
1086 && (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND
1087 (args[i].tree_value, 1)))
1089 && ! REG_P (DECL_RTL (TREE_OPERAND (args[i].tree_value, 1))))
1090 args[i].tree_value = TREE_OPERAND (args[i].tree_value, 1);
1092 args[i].tree_value = build1 (ADDR_EXPR,
1093 build_pointer_type (type),
1094 args[i].tree_value);
1095 type = build_pointer_type (type);
1099 /* We make a copy of the object and pass the address to the
1100 function being called. */
1103 if (TYPE_SIZE (type) == 0
1104 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
1105 || (flag_stack_check && ! STACK_CHECK_BUILTIN
1106 && (0 < compare_tree_int (TYPE_SIZE_UNIT (type),
1107 STACK_CHECK_MAX_VAR_SIZE))))
1109 /* This is a variable-sized object. Make space on the stack
1111 rtx size_rtx = expr_size (TREE_VALUE (p));
1113 if (*old_stack_level == 0)
1115 emit_stack_save (SAVE_BLOCK, old_stack_level, NULL_RTX);
1116 *old_pending_adj = pending_stack_adjust;
1117 pending_stack_adjust = 0;
1120 copy = gen_rtx_MEM (BLKmode,
1121 allocate_dynamic_stack_space (size_rtx,
1123 TYPE_ALIGN (type)));
1127 int size = int_size_in_bytes (type);
1128 copy = assign_stack_temp (TYPE_MODE (type), size, 0);
1131 MEM_SET_IN_STRUCT_P (copy, AGGREGATE_TYPE_P (type));
1133 store_expr (args[i].tree_value, copy, 0);
1136 args[i].tree_value = build1 (ADDR_EXPR,
1137 build_pointer_type (type),
1138 make_tree (type, copy));
1139 type = build_pointer_type (type);
1143 mode = TYPE_MODE (type);
1144 unsignedp = TREE_UNSIGNED (type);
1146 #ifdef PROMOTE_FUNCTION_ARGS
1147 mode = promote_mode (type, mode, &unsignedp, 1);
1150 args[i].unsignedp = unsignedp;
1151 args[i].mode = mode;
1152 args[i].reg = FUNCTION_ARG (*args_so_far, mode, type,
1153 argpos < n_named_args);
1154 #ifdef FUNCTION_ARG_PARTIAL_NREGS
1157 = FUNCTION_ARG_PARTIAL_NREGS (*args_so_far, mode, type,
1158 argpos < n_named_args);
1161 args[i].pass_on_stack = MUST_PASS_IN_STACK (mode, type);
1163 /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1164 it means that we are to pass this arg in the register(s) designated
1165 by the PARALLEL, but also to pass it in the stack. */
1166 if (args[i].reg && GET_CODE (args[i].reg) == PARALLEL
1167 && XEXP (XVECEXP (args[i].reg, 0, 0), 0) == 0)
1168 args[i].pass_on_stack = 1;
1170 /* If this is an addressable type, we must preallocate the stack
1171 since we must evaluate the object into its final location.
1173 If this is to be passed in both registers and the stack, it is simpler
1175 if (TREE_ADDRESSABLE (type)
1176 || (args[i].pass_on_stack && args[i].reg != 0))
1177 *must_preallocate = 1;
1179 /* If this is an addressable type, we cannot pre-evaluate it. Thus,
1180 we cannot consider this function call constant. */
1181 if (TREE_ADDRESSABLE (type))
1184 /* Compute the stack-size of this argument. */
1185 if (args[i].reg == 0 || args[i].partial != 0
1186 || reg_parm_stack_space > 0
1187 || args[i].pass_on_stack)
1188 locate_and_pad_parm (mode, type,
1189 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1194 fndecl, args_size, &args[i].offset,
1195 &args[i].size, &alignment_pad);
1197 #ifndef ARGS_GROW_DOWNWARD
1198 args[i].slot_offset = *args_size;
1201 args[i].alignment_pad = alignment_pad;
1203 /* If a part of the arg was put into registers,
1204 don't include that part in the amount pushed. */
1205 if (reg_parm_stack_space == 0 && ! args[i].pass_on_stack)
1206 args[i].size.constant -= ((args[i].partial * UNITS_PER_WORD)
1207 / (PARM_BOUNDARY / BITS_PER_UNIT)
1208 * (PARM_BOUNDARY / BITS_PER_UNIT));
1210 /* Update ARGS_SIZE, the total stack space for args so far. */
1212 args_size->constant += args[i].size.constant;
1213 if (args[i].size.var)
1215 ADD_PARM_SIZE (*args_size, args[i].size.var);
1218 /* Since the slot offset points to the bottom of the slot,
1219 we must record it after incrementing if the args grow down. */
1220 #ifdef ARGS_GROW_DOWNWARD
1221 args[i].slot_offset = *args_size;
1223 args[i].slot_offset.constant = -args_size->constant;
1225 SUB_PARM_SIZE (args[i].slot_offset, args_size->var);
1228 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1229 have been used, etc. */
1231 FUNCTION_ARG_ADVANCE (*args_so_far, TYPE_MODE (type), type,
1232 argpos < n_named_args);
1236 /* Update ARGS_SIZE to contain the total size for the argument block.
1237 Return the original constant component of the argument block's size.
1239 REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
1240 for arguments passed in registers. */
1243 compute_argument_block_size (reg_parm_stack_space, args_size,
1244 preferred_stack_boundary)
1245 int reg_parm_stack_space;
1246 struct args_size *args_size;
1247 int preferred_stack_boundary ATTRIBUTE_UNUSED;
1249 int unadjusted_args_size = args_size->constant;
1251 /* Compute the actual size of the argument block required. The variable
1252 and constant sizes must be combined, the size may have to be rounded,
1253 and there may be a minimum required size. */
1257 args_size->var = ARGS_SIZE_TREE (*args_size);
1258 args_size->constant = 0;
1260 #ifdef PREFERRED_STACK_BOUNDARY
1261 preferred_stack_boundary /= BITS_PER_UNIT;
1262 if (preferred_stack_boundary > 1)
1263 args_size->var = round_up (args_size->var, preferred_stack_boundary);
1266 if (reg_parm_stack_space > 0)
1269 = size_binop (MAX_EXPR, args_size->var,
1270 ssize_int (reg_parm_stack_space));
1272 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1273 /* The area corresponding to register parameters is not to count in
1274 the size of the block we need. So make the adjustment. */
1276 = size_binop (MINUS_EXPR, args_size->var,
1277 ssize_int (reg_parm_stack_space));
1283 #ifdef PREFERRED_STACK_BOUNDARY
1284 preferred_stack_boundary /= BITS_PER_UNIT;
1285 if (preferred_stack_boundary < 1)
1286 preferred_stack_boundary = 1;
1287 args_size->constant = (((args_size->constant
1289 + pending_stack_adjust
1290 + preferred_stack_boundary - 1)
1291 / preferred_stack_boundary
1292 * preferred_stack_boundary)
1294 - pending_stack_adjust);
1297 args_size->constant = MAX (args_size->constant,
1298 reg_parm_stack_space);
1300 #ifdef MAYBE_REG_PARM_STACK_SPACE
1301 if (reg_parm_stack_space == 0)
1302 args_size->constant = 0;
1305 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1306 args_size->constant -= reg_parm_stack_space;
1309 return unadjusted_args_size;
1312 /* Precompute parameters as needed for a function call.
1314 IS_CONST indicates the target function is a pure function.
1316 MUST_PREALLOCATE indicates that we must preallocate stack space for
1317 any stack arguments.
1319 NUM_ACTUALS is the number of arguments.
1321 ARGS is an array containing information for each argument; this routine
1322 fills in the INITIAL_VALUE and VALUE fields for each precomputed argument.
1324 ARGS_SIZE contains information about the size of the arg list. */
1327 precompute_arguments (is_const, must_preallocate, num_actuals, args, args_size)
1329 int must_preallocate;
1331 struct arg_data *args;
1332 struct args_size *args_size;
1336 /* If this function call is cse'able, precompute all the parameters.
1337 Note that if the parameter is constructed into a temporary, this will
1338 cause an additional copy because the parameter will be constructed
1339 into a temporary location and then copied into the outgoing arguments.
1340 If a parameter contains a call to alloca and this function uses the
1341 stack, precompute the parameter. */
1343 /* If we preallocated the stack space, and some arguments must be passed
1344 on the stack, then we must precompute any parameter which contains a
1345 function call which will store arguments on the stack.
1346 Otherwise, evaluating the parameter may clobber previous parameters
1347 which have already been stored into the stack. */
1349 for (i = 0; i < num_actuals; i++)
1351 || ((args_size->var != 0 || args_size->constant != 0)
1352 && calls_function (args[i].tree_value, 1))
1353 || (must_preallocate
1354 && (args_size->var != 0 || args_size->constant != 0)
1355 && calls_function (args[i].tree_value, 0)))
1357 /* If this is an addressable type, we cannot pre-evaluate it. */
1358 if (TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value)))
1364 = expand_expr (args[i].tree_value, NULL_RTX, VOIDmode, 0);
1366 preserve_temp_slots (args[i].value);
1369 /* ANSI doesn't require a sequence point here,
1370 but PCC has one, so this will avoid some problems. */
1373 args[i].initial_value = args[i].value
1374 = protect_from_queue (args[i].value, 0);
1376 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) != args[i].mode)
1379 = convert_modes (args[i].mode,
1380 TYPE_MODE (TREE_TYPE (args[i].tree_value)),
1381 args[i].value, args[i].unsignedp);
1382 #ifdef PROMOTE_FOR_CALL_ONLY
1383 /* CSE will replace this only if it contains args[i].value
1384 pseudo, so convert it down to the declared mode using
1386 if (GET_CODE (args[i].value) == REG
1387 && GET_MODE_CLASS (args[i].mode) == MODE_INT)
1389 args[i].initial_value
1390 = gen_rtx_SUBREG (TYPE_MODE (TREE_TYPE (args[i].tree_value)),
1392 SUBREG_PROMOTED_VAR_P (args[i].initial_value) = 1;
1393 SUBREG_PROMOTED_UNSIGNED_P (args[i].initial_value)
1394 = args[i].unsignedp;
1401 /* Given the current state of MUST_PREALLOCATE and information about
1402 arguments to a function call in NUM_ACTUALS, ARGS and ARGS_SIZE,
1403 compute and return the final value for MUST_PREALLOCATE. */
1406 finalize_must_preallocate (must_preallocate, num_actuals, args, args_size)
1407 int must_preallocate;
1409 struct arg_data *args;
1410 struct args_size *args_size;
1412 /* See if we have or want to preallocate stack space.
1414 If we would have to push a partially-in-regs parm
1415 before other stack parms, preallocate stack space instead.
1417 If the size of some parm is not a multiple of the required stack
1418 alignment, we must preallocate.
1420 If the total size of arguments that would otherwise create a copy in
1421 a temporary (such as a CALL) is more than half the total argument list
1422 size, preallocation is faster.
1424 Another reason to preallocate is if we have a machine (like the m88k)
1425 where stack alignment is required to be maintained between every
1426 pair of insns, not just when the call is made. However, we assume here
1427 that such machines either do not have push insns (and hence preallocation
1428 would occur anyway) or the problem is taken care of with
1431 if (! must_preallocate)
1433 int partial_seen = 0;
1434 int copy_to_evaluate_size = 0;
1437 for (i = 0; i < num_actuals && ! must_preallocate; i++)
1439 if (args[i].partial > 0 && ! args[i].pass_on_stack)
1441 else if (partial_seen && args[i].reg == 0)
1442 must_preallocate = 1;
1444 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1445 && (TREE_CODE (args[i].tree_value) == CALL_EXPR
1446 || TREE_CODE (args[i].tree_value) == TARGET_EXPR
1447 || TREE_CODE (args[i].tree_value) == COND_EXPR
1448 || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
1449 copy_to_evaluate_size
1450 += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1453 if (copy_to_evaluate_size * 2 >= args_size->constant
1454 && args_size->constant > 0)
1455 must_preallocate = 1;
1457 return must_preallocate;
1460 /* If we preallocated stack space, compute the address of each argument
1461 and store it into the ARGS array.
1463 We need not ensure it is a valid memory address here; it will be
1464 validized when it is used.
1466 ARGBLOCK is an rtx for the address of the outgoing arguments. */
1469 compute_argument_addresses (args, argblock, num_actuals)
1470 struct arg_data *args;
1476 rtx arg_reg = argblock;
1477 int i, arg_offset = 0;
1479 if (GET_CODE (argblock) == PLUS)
1480 arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
1482 for (i = 0; i < num_actuals; i++)
1484 rtx offset = ARGS_SIZE_RTX (args[i].offset);
1485 rtx slot_offset = ARGS_SIZE_RTX (args[i].slot_offset);
1488 /* Skip this parm if it will not be passed on the stack. */
1489 if (! args[i].pass_on_stack && args[i].reg != 0)
1492 if (GET_CODE (offset) == CONST_INT)
1493 addr = plus_constant (arg_reg, INTVAL (offset));
1495 addr = gen_rtx_PLUS (Pmode, arg_reg, offset);
1497 addr = plus_constant (addr, arg_offset);
1498 args[i].stack = gen_rtx_MEM (args[i].mode, addr);
1501 AGGREGATE_TYPE_P (TREE_TYPE (args[i].tree_value)));
1503 if (GET_CODE (slot_offset) == CONST_INT)
1504 addr = plus_constant (arg_reg, INTVAL (slot_offset));
1506 addr = gen_rtx_PLUS (Pmode, arg_reg, slot_offset);
1508 addr = plus_constant (addr, arg_offset);
1509 args[i].stack_slot = gen_rtx_MEM (args[i].mode, addr);
1514 /* Given a FNDECL and EXP, return an rtx suitable for use as a target address
1515 in a call instruction.
1517 FNDECL is the tree node for the target function. For an indirect call
1518 FNDECL will be NULL_TREE.
1520 EXP is the CALL_EXPR for this call. */
1523 rtx_for_function_call (fndecl, exp)
1529 /* Get the function to call, in the form of RTL. */
1532 /* If this is the first use of the function, see if we need to
1533 make an external definition for it. */
1534 if (! TREE_USED (fndecl))
1536 assemble_external (fndecl);
1537 TREE_USED (fndecl) = 1;
1540 /* Get a SYMBOL_REF rtx for the function address. */
1541 funexp = XEXP (DECL_RTL (fndecl), 0);
1544 /* Generate an rtx (probably a pseudo-register) for the address. */
1549 expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
1550 pop_temp_slots (); /* FUNEXP can't be BLKmode */
1552 /* Check the function is executable. */
1553 if (current_function_check_memory_usage)
1555 #ifdef POINTERS_EXTEND_UNSIGNED
1556 /* It might be OK to convert funexp in place, but there's
1557 a lot going on between here and when it happens naturally
1558 that this seems safer. */
1559 funaddr = convert_memory_address (Pmode, funexp);
1561 emit_library_call (chkr_check_exec_libfunc, 1,
1570 /* Do the register loads required for any wholly-register parms or any
1571 parms which are passed both on the stack and in a register. Their
1572 expressions were already evaluated.
1574 Mark all register-parms as living through the call, putting these USE
1575 insns in the CALL_INSN_FUNCTION_USAGE field. */
1578 load_register_parameters (args, num_actuals, call_fusage)
1579 struct arg_data *args;
1585 #ifdef LOAD_ARGS_REVERSED
1586 for (i = num_actuals - 1; i >= 0; i--)
1588 for (i = 0; i < num_actuals; i++)
1591 rtx reg = args[i].reg;
1592 int partial = args[i].partial;
1597 /* Set to non-negative if must move a word at a time, even if just
1598 one word (e.g, partial == 1 && mode == DFmode). Set to -1 if
1599 we just use a normal move insn. This value can be zero if the
1600 argument is a zero size structure with no fields. */
1601 nregs = (partial ? partial
1602 : (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1603 ? ((int_size_in_bytes (TREE_TYPE (args[i].tree_value))
1604 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
1607 /* Handle calls that pass values in multiple non-contiguous
1608 locations. The Irix 6 ABI has examples of this. */
1610 if (GET_CODE (reg) == PARALLEL)
1612 emit_group_load (reg, args[i].value,
1613 int_size_in_bytes (TREE_TYPE (args[i].tree_value)),
1614 (TYPE_ALIGN (TREE_TYPE (args[i].tree_value))
1618 /* If simple case, just do move. If normal partial, store_one_arg
1619 has already loaded the register for us. In all other cases,
1620 load the register(s) from memory. */
1622 else if (nregs == -1)
1623 emit_move_insn (reg, args[i].value);
1625 /* If we have pre-computed the values to put in the registers in
1626 the case of non-aligned structures, copy them in now. */
1628 else if (args[i].n_aligned_regs != 0)
1629 for (j = 0; j < args[i].n_aligned_regs; j++)
1630 emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg) + j),
1631 args[i].aligned_regs[j]);
1633 else if (partial == 0 || args[i].pass_on_stack)
1634 move_block_to_reg (REGNO (reg),
1635 validize_mem (args[i].value), nregs,
1638 /* Handle calls that pass values in multiple non-contiguous
1639 locations. The Irix 6 ABI has examples of this. */
1640 if (GET_CODE (reg) == PARALLEL)
1641 use_group_regs (call_fusage, reg);
1642 else if (nregs == -1)
1643 use_reg (call_fusage, reg);
1645 use_regs (call_fusage, REGNO (reg), nregs == 0 ? 1 : nregs);
1650 /* Generate all the code for a function call
1651 and return an rtx for its value.
1652 Store the value in TARGET (specified as an rtx) if convenient.
1653 If the value is stored in TARGET then TARGET is returned.
1654 If IGNORE is nonzero, then we ignore the value of the function call. */
1657 expand_call (exp, target, ignore)
1662 /* Nonzero if we are currently expanding a call. */
1663 static int currently_expanding_call = 0;
1665 /* List of actual parameters. */
1666 tree actparms = TREE_OPERAND (exp, 1);
1667 /* RTX for the function to be called. */
1669 /* Sequence of insns to perform a tail recursive "call". */
1670 rtx tail_recursion_insns = NULL_RTX;
1671 /* Sequence of insns to perform a normal "call". */
1672 rtx normal_call_insns = NULL_RTX;
1673 /* Sequence of insns to perform a tail recursive "call". */
1674 rtx tail_call_insns = NULL_RTX;
1675 /* Data type of the function. */
1677 /* Declaration of the function being called,
1678 or 0 if the function is computed (not known by name). */
1681 #ifdef ACCUMULATE_OUTGOING_ARGS
1685 int safe_for_reeval;
1688 /* Register in which non-BLKmode value will be returned,
1689 or 0 if no value or if value is BLKmode. */
1691 /* Address where we should return a BLKmode value;
1692 0 if value not BLKmode. */
1693 rtx structure_value_addr = 0;
1694 /* Nonzero if that address is being passed by treating it as
1695 an extra, implicit first parameter. Otherwise,
1696 it is passed by being copied directly into struct_value_rtx. */
1697 int structure_value_addr_parm = 0;
1698 /* Size of aggregate value wanted, or zero if none wanted
1699 or if we are using the non-reentrant PCC calling convention
1700 or expecting the value in registers. */
1701 HOST_WIDE_INT struct_value_size = 0;
1702 /* Nonzero if called function returns an aggregate in memory PCC style,
1703 by returning the address of where to find it. */
1704 int pcc_struct_value = 0;
1706 /* Number of actual parameters in this call, including struct value addr. */
1708 /* Number of named args. Args after this are anonymous ones
1709 and they must all go on the stack. */
1712 /* Vector of information about each argument.
1713 Arguments are numbered in the order they will be pushed,
1714 not the order they are written. */
1715 struct arg_data *args;
1717 /* Total size in bytes of all the stack-parms scanned so far. */
1718 struct args_size args_size;
1719 /* Size of arguments before any adjustments (such as rounding). */
1720 int unadjusted_args_size;
1721 /* Data on reg parms scanned so far. */
1722 CUMULATIVE_ARGS args_so_far;
1723 /* Nonzero if a reg parm has been scanned. */
1725 /* Nonzero if this is an indirect function call. */
1727 /* Nonzero if we must avoid push-insns in the args for this call.
1728 If stack space is allocated for register parameters, but not by the
1729 caller, then it is preallocated in the fixed part of the stack frame.
1730 So the entire argument block must then be preallocated (i.e., we
1731 ignore PUSH_ROUNDING in that case). */
1733 #ifdef PUSH_ROUNDING
1734 int must_preallocate = 0;
1736 int must_preallocate = 1;
1739 /* Size of the stack reserved for parameter registers. */
1740 int reg_parm_stack_space = 0;
1742 /* Address of space preallocated for stack parms
1743 (on machines that lack push insns), or 0 if space not preallocated. */
1746 /* Nonzero if it is plausible that this is a call to alloca. */
1748 /* Nonzero if this is a call to malloc or a related function. */
1750 /* Nonzero if this is a call to setjmp or a related function. */
1752 /* Nonzero if this is a call to `longjmp'. */
1754 /* Nonzero if this is a syscall that makes a new process in the image of
1757 /* Nonzero if this is a call to an inline function. */
1758 int is_integrable = 0;
1759 /* Nonzero if this is a call to a `const' function.
1760 Note that only explicitly named functions are handled as `const' here. */
1762 /* Nonzero if this is a call to a `volatile' function. */
1763 int is_volatile = 0;
1764 /* Nonzero if this is a call to a function that won't throw an exception. */
1765 int nothrow = TREE_NOTHROW (exp);
1766 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
1767 /* Define the boundary of the register parm stack space that needs to be
1769 int low_to_save = -1, high_to_save;
1770 rtx save_area = 0; /* Place that it is saved */
1773 #ifdef ACCUMULATE_OUTGOING_ARGS
1774 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
1775 char *initial_stack_usage_map = stack_usage_map;
1776 int old_stack_arg_under_construction = 0;
1779 rtx old_stack_level = 0;
1780 int old_pending_adj = 0;
1781 int old_inhibit_defer_pop = inhibit_defer_pop;
1785 int preferred_stack_boundary;
1787 /* The value of the function call can be put in a hard register. But
1788 if -fcheck-memory-usage, code which invokes functions (and thus
1789 damages some hard registers) can be inserted before using the value.
1790 So, target is always a pseudo-register in that case. */
1791 if (current_function_check_memory_usage)
1794 /* See if we can find a DECL-node for the actual function.
1795 As a result, decide whether this is a call to an integrable function. */
1797 p = TREE_OPERAND (exp, 0);
1798 if (TREE_CODE (p) == ADDR_EXPR)
1800 fndecl = TREE_OPERAND (p, 0);
1801 if (TREE_CODE (fndecl) != FUNCTION_DECL)
1806 && fndecl != current_function_decl
1807 && DECL_INLINE (fndecl)
1808 && DECL_SAVED_INSNS (fndecl)
1809 && DECL_SAVED_INSNS (fndecl)->inlinable)
1811 else if (! TREE_ADDRESSABLE (fndecl))
1813 /* In case this function later becomes inlinable,
1814 record that there was already a non-inline call to it.
1816 Use abstraction instead of setting TREE_ADDRESSABLE
1818 if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
1821 warning_with_decl (fndecl, "can't inline call to `%s'");
1822 warning ("called from here");
1824 mark_addressable (fndecl);
1827 if (TREE_READONLY (fndecl) && ! TREE_THIS_VOLATILE (fndecl)
1828 && TYPE_MODE (TREE_TYPE (exp)) != VOIDmode)
1831 if (TREE_THIS_VOLATILE (fndecl))
1834 if (TREE_NOTHROW (fndecl))
1839 /* If we don't have specific function to call, see if we have a
1840 constant or `noreturn' function from the type. */
1843 is_const = TREE_READONLY (TREE_TYPE (TREE_TYPE (p)));
1844 is_volatile = TREE_THIS_VOLATILE (TREE_TYPE (TREE_TYPE (p)));
1847 #ifdef REG_PARM_STACK_SPACE
1848 #ifdef MAYBE_REG_PARM_STACK_SPACE
1849 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
1851 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
1855 #if defined(PUSH_ROUNDING) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
1856 if (reg_parm_stack_space > 0)
1857 must_preallocate = 1;
1860 /* Warn if this value is an aggregate type,
1861 regardless of which calling convention we are using for it. */
1862 if (warn_aggregate_return && AGGREGATE_TYPE_P (TREE_TYPE (exp)))
1863 warning ("function call has aggregate value");
1865 /* Set up a place to return a structure. */
1867 /* Cater to broken compilers. */
1868 if (aggregate_value_p (exp))
1870 /* This call returns a big structure. */
1873 #ifdef PCC_STATIC_STRUCT_RETURN
1875 pcc_struct_value = 1;
1876 /* Easier than making that case work right. */
1879 /* In case this is a static function, note that it has been
1881 if (! TREE_ADDRESSABLE (fndecl))
1882 mark_addressable (fndecl);
1886 #else /* not PCC_STATIC_STRUCT_RETURN */
1888 struct_value_size = int_size_in_bytes (TREE_TYPE (exp));
1890 if (target && GET_CODE (target) == MEM)
1891 structure_value_addr = XEXP (target, 0);
1894 /* Assign a temporary to hold the value. */
1897 /* For variable-sized objects, we must be called with a target
1898 specified. If we were to allocate space on the stack here,
1899 we would have no way of knowing when to free it. */
1901 if (struct_value_size < 0)
1904 /* This DECL is just something to feed to mark_addressable;
1905 it doesn't get pushed. */
1906 d = build_decl (VAR_DECL, NULL_TREE, TREE_TYPE (exp));
1907 DECL_RTL (d) = assign_temp (TREE_TYPE (exp), 1, 0, 1);
1908 mark_addressable (d);
1909 mark_temp_addr_taken (DECL_RTL (d));
1910 structure_value_addr = XEXP (DECL_RTL (d), 0);
1915 #endif /* not PCC_STATIC_STRUCT_RETURN */
1918 /* If called function is inline, try to integrate it. */
1924 #ifdef ACCUMULATE_OUTGOING_ARGS
1925 before_call = get_last_insn ();
1928 temp = expand_inline_function (fndecl, actparms, target,
1929 ignore, TREE_TYPE (exp),
1930 structure_value_addr);
1932 /* If inlining succeeded, return. */
1933 if (temp != (rtx) (HOST_WIDE_INT) -1)
1935 #ifdef ACCUMULATE_OUTGOING_ARGS
1936 /* If the outgoing argument list must be preserved, push
1937 the stack before executing the inlined function if it
1940 for (i = reg_parm_stack_space - 1; i >= 0; i--)
1941 if (i < highest_outgoing_arg_in_use && stack_usage_map[i] != 0)
1944 if (stack_arg_under_construction || i >= 0)
1947 = before_call ? NEXT_INSN (before_call) : get_insns ();
1948 rtx insn = NULL_RTX, seq;
1950 /* Look for a call in the inline function code.
1951 If DECL_SAVED_INSNS (fndecl)->outgoing_args_size is
1952 nonzero then there is a call and it is not necessary
1953 to scan the insns. */
1955 if (DECL_SAVED_INSNS (fndecl)->outgoing_args_size == 0)
1956 for (insn = first_insn; insn; insn = NEXT_INSN (insn))
1957 if (GET_CODE (insn) == CALL_INSN)
1962 /* Reserve enough stack space so that the largest
1963 argument list of any function call in the inline
1964 function does not overlap the argument list being
1965 evaluated. This is usually an overestimate because
1966 allocate_dynamic_stack_space reserves space for an
1967 outgoing argument list in addition to the requested
1968 space, but there is no way to ask for stack space such
1969 that an argument list of a certain length can be
1972 Add the stack space reserved for register arguments, if
1973 any, in the inline function. What is really needed is the
1974 largest value of reg_parm_stack_space in the inline
1975 function, but that is not available. Using the current
1976 value of reg_parm_stack_space is wrong, but gives
1977 correct results on all supported machines. */
1979 int adjust = (DECL_SAVED_INSNS (fndecl)->outgoing_args_size
1980 + reg_parm_stack_space);
1983 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1984 allocate_dynamic_stack_space (GEN_INT (adjust),
1985 NULL_RTX, BITS_PER_UNIT);
1988 emit_insns_before (seq, first_insn);
1989 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
1994 /* If the result is equivalent to TARGET, return TARGET to simplify
1995 checks in store_expr. They can be equivalent but not equal in the
1996 case of a function that returns BLKmode. */
1997 if (temp != target && rtx_equal_p (temp, target))
2002 /* If inlining failed, mark FNDECL as needing to be compiled
2003 separately after all. If function was declared inline,
2005 if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
2006 && optimize > 0 && ! TREE_ADDRESSABLE (fndecl))
2008 warning_with_decl (fndecl, "inlining failed in call to `%s'");
2009 warning ("called from here");
2011 mark_addressable (fndecl);
2014 currently_expanding_call++;
2016 /* If we're considering tail recursion optimizations, verify that the
2017 arguments are safe for re-evaluation. If we can unsave them, wrap
2018 each argument in an UNSAVE_EXPR. */
2020 safe_for_reeval = 0;
2022 && currently_expanding_call == 1
2023 && stmt_loop_nest_empty ()
2024 && ! any_pending_cleanups (1))
2026 /* Verify that each argument is safe for re-evaluation. */
2027 for (p = actparms; p; p = TREE_CHAIN (p))
2028 if (! safe_for_unsave (TREE_VALUE (p)))
2033 tree new_actparms = NULL_TREE, q;
2035 for (p = actparms; p ; p = TREE_CHAIN (p))
2037 tree np = build_tree_list (TREE_PURPOSE (p),
2038 unsave_expr (TREE_VALUE (p)));
2040 TREE_CHAIN (q) = np;
2046 actparms = new_actparms;
2047 safe_for_reeval = 1;
2051 /* Generate a tail recursion sequence when calling ourselves. */
2054 && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
2055 && TREE_OPERAND (TREE_OPERAND (exp, 0), 0) == current_function_decl)
2057 /* We want to emit any pending stack adjustments before the tail
2058 recursion "call". That way we know any adjustment after the tail
2059 recursion call can be ignored if we indeed use the tail recursion
2061 int save_pending_stack_adjust = pending_stack_adjust;
2064 /* Use a new sequence to hold any RTL we generate. We do not even
2065 know if we will use this RTL yet. The final decision can not be
2066 made until after RTL generation for the entire function is
2068 push_to_sequence (0);
2070 /* Emit the pending stack adjustments before we expand any arguments. */
2071 do_pending_stack_adjust ();
2073 optimize_tail_recursion (exp, get_last_insn ());
2075 last = get_last_insn ();
2076 tail_recursion_insns = get_insns ();
2079 /* If the last insn on the tail recursion sequence is not a
2080 BARRIER, then tail recursion optimization failed. */
2081 if (last == NULL_RTX || GET_CODE (last) != BARRIER)
2082 tail_recursion_insns = NULL_RTX;
2084 /* Restore the original pending stack adjustment for the sibling and
2085 normal call cases below. */
2086 pending_stack_adjust = save_pending_stack_adjust;
2089 function_call_count++;
2091 if (fndecl && DECL_NAME (fndecl))
2092 name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
2094 #ifdef PREFERRED_STACK_BOUNDARY
2095 preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
2097 preferred_stack_boundary = STACK_BOUNDARY;
2100 /* Ensure current function's preferred stack boundary is at least
2101 what we need. We don't have to increase alignment for recursive
2103 if (cfun->preferred_stack_boundary < preferred_stack_boundary
2104 && fndecl != current_function_decl)
2105 cfun->preferred_stack_boundary = preferred_stack_boundary;
2107 /* See if this is a call to a function that can return more than once
2108 or a call to longjmp or malloc. */
2109 special_function_p (fndecl, &returns_twice, &is_longjmp, &fork_or_exec,
2110 &is_malloc, &may_be_alloca);
2113 current_function_calls_alloca = 1;
2115 /* Operand 0 is a pointer-to-function; get the type of the function. */
2116 funtype = TREE_TYPE (TREE_OPERAND (exp, 0));
2117 if (! POINTER_TYPE_P (funtype))
2119 funtype = TREE_TYPE (funtype);
2121 /* We want to make two insn chains; one for a sibling call, the other
2122 for a normal call. We will select one of the two chains after
2123 initial RTL generation is complete. */
2124 for (pass = 0; pass < 2; pass++)
2126 int sibcall_failure = 0;
2127 /* We want to emit ay pending stack adjustments before the tail
2128 recursion "call". That way we know any adjustment after the tail
2129 recursion call can be ignored if we indeed use the tail recursion
2131 int save_pending_stack_adjust;
2137 /* Various reasons we can not use a sibling call. */
2138 if (! safe_for_reeval
2139 #ifdef HAVE_sibcall_epilogue
2140 || ! HAVE_sibcall_epilogue
2144 /* The structure value address is used and modified in the
2145 loop below. It does not seem worth the effort to save and
2146 restore it as a state variable since few optimizable
2147 sibling calls will return a structure. */
2148 || structure_value_addr != NULL_RTX
2149 /* If the register holding the address is a callee saved
2150 register, then we lose. We have no way to prevent that,
2151 so we only allow calls to named functions. */
2152 || fndecl == NULL_TREE
2153 || ! FUNCTION_OK_FOR_SIBCALL (fndecl))
2156 /* We know at this point that there are not currently any
2157 pending cleanups. If, however, in the process of evaluating
2158 the arguments we were to create some, we'll need to be
2159 able to get rid of them. */
2160 expand_start_target_temps ();
2162 /* State variables we need to save and restore between
2164 save_pending_stack_adjust = pending_stack_adjust;
2167 /* Other state variables that we must reinitialize each time
2168 through the loop (that are not initialized by the loop itself. */
2172 /* Start a new sequence for the normal call case.
2174 From this point on, if the sibling call fails, we want to set
2175 sibcall_failure instead of continuing the loop. */
2178 /* When calling a const function, we must pop the stack args right away,
2179 so that the pop is deleted or moved with the call. */
2183 /* Don't let pending stack adjusts add up to too much.
2184 Also, do all pending adjustments now if there is any chance
2185 this might be a call to alloca or if we are expanding a sibling
2187 if (pending_stack_adjust >= 32
2188 || (pending_stack_adjust > 0 && may_be_alloca)
2190 do_pending_stack_adjust ();
2192 if (profile_arc_flag && fork_or_exec)
2194 /* A fork duplicates the profile information, and an exec discards
2195 it. We can't rely on fork/exec to be paired. So write out the
2196 profile information we have gathered so far, and clear it. */
2197 /* ??? When Linux's __clone is called with CLONE_VM set, profiling
2198 is subject to race conditions, just as with multithreaded
2201 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__bb_fork_func"), 0,
2205 /* Push the temporary stack slot level so that we can free any
2206 temporaries we make. */
2209 /* Start updating where the next arg would go.
2211 On some machines (such as the PA) indirect calls have a different
2212 calling convention than normal calls. The last argument in
2213 INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
2215 INIT_CUMULATIVE_ARGS (args_so_far, funtype, NULL_RTX, (fndecl == 0));
2217 /* If struct_value_rtx is 0, it means pass the address
2218 as if it were an extra parameter. */
2219 if (structure_value_addr && struct_value_rtx == 0)
2221 /* If structure_value_addr is a REG other than
2222 virtual_outgoing_args_rtx, we can use always use it. If it
2223 is not a REG, we must always copy it into a register.
2224 If it is virtual_outgoing_args_rtx, we must copy it to another
2225 register in some cases. */
2226 rtx temp = (GET_CODE (structure_value_addr) != REG
2227 #ifdef ACCUMULATE_OUTGOING_ARGS
2228 || (stack_arg_under_construction
2229 && structure_value_addr == virtual_outgoing_args_rtx)
2231 ? copy_addr_to_reg (structure_value_addr)
2232 : structure_value_addr);
2235 = tree_cons (error_mark_node,
2236 make_tree (build_pointer_type (TREE_TYPE (funtype)),
2239 structure_value_addr_parm = 1;
2242 /* Count the arguments and set NUM_ACTUALS. */
2243 for (p = actparms, i = 0; p; p = TREE_CHAIN (p)) i++;
2246 /* Compute number of named args.
2247 Normally, don't include the last named arg if anonymous args follow.
2248 We do include the last named arg if STRICT_ARGUMENT_NAMING is nonzero.
2249 (If no anonymous args follow, the result of list_length is actually
2250 one too large. This is harmless.)
2252 If PRETEND_OUTGOING_VARARGS_NAMED is set and STRICT_ARGUMENT_NAMING is
2253 zero, this machine will be able to place unnamed args that were
2254 passed in registers into the stack. So treat all args as named.
2255 This allows the insns emitting for a specific argument list to be
2256 independent of the function declaration.
2258 If PRETEND_OUTGOING_VARARGS_NAMED is not set, we do not have any
2259 reliable way to pass unnamed args in registers, so we must force
2260 them into memory. */
2262 if ((STRICT_ARGUMENT_NAMING
2263 || ! PRETEND_OUTGOING_VARARGS_NAMED)
2264 && TYPE_ARG_TYPES (funtype) != 0)
2266 = (list_length (TYPE_ARG_TYPES (funtype))
2267 /* Don't include the last named arg. */
2268 - (STRICT_ARGUMENT_NAMING ? 0 : 1)
2269 /* Count the struct value address, if it is passed as a parm. */
2270 + structure_value_addr_parm);
2272 /* If we know nothing, treat all args as named. */
2273 n_named_args = num_actuals;
2275 /* Make a vector to hold all the information about each arg. */
2276 args = (struct arg_data *) alloca (num_actuals
2277 * sizeof (struct arg_data));
2278 bzero ((char *) args, num_actuals * sizeof (struct arg_data));
2280 /* Build up entries inthe ARGS array, compute the size of the arguments
2281 into ARGS_SIZE, etc. */
2282 initialize_argument_information (num_actuals, args, &args_size,
2283 n_named_args, actparms, fndecl,
2284 &args_so_far, reg_parm_stack_space,
2285 &old_stack_level, &old_pending_adj,
2286 &must_preallocate, &is_const);
2288 #ifdef FINAL_REG_PARM_STACK_SPACE
2289 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
2295 /* If this function requires a variable-sized argument list, don't
2296 try to make a cse'able block for this call. We may be able to
2297 do this eventually, but it is too complicated to keep track of
2298 what insns go in the cse'able block and which don't.
2300 Also do not make a sibling call. */
2303 must_preallocate = 1;
2304 sibcall_failure = 1;
2307 /* Compute the actual size of the argument block required. The variable
2308 and constant sizes must be combined, the size may have to be rounded,
2309 and there may be a minimum required size. When generating a sibcall
2310 pattern, do not round up, since we'll be re-using whatever space our
2312 unadjusted_args_size
2313 = compute_argument_block_size (reg_parm_stack_space, &args_size,
2315 : preferred_stack_boundary));
2317 /* If the callee pops its own arguments, then it must pop exactly
2318 the same number of arguments as the current function. */
2319 if (RETURN_POPS_ARGS (fndecl, funtype, unadjusted_args_size)
2320 != RETURN_POPS_ARGS (current_function_decl,
2321 TREE_TYPE (current_function_decl),
2322 current_function_args_size))
2323 sibcall_failure = 1;
2325 /* Now make final decision about preallocating stack space. */
2326 must_preallocate = finalize_must_preallocate (must_preallocate,
2330 /* If the structure value address will reference the stack pointer, we
2331 must stabilize it. We don't need to do this if we know that we are
2332 not going to adjust the stack pointer in processing this call. */
2334 if (structure_value_addr
2335 && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
2336 || reg_mentioned_p (virtual_outgoing_args_rtx,
2337 structure_value_addr))
2339 #ifndef ACCUMULATE_OUTGOING_ARGS
2340 || args_size.constant
2343 structure_value_addr = copy_to_reg (structure_value_addr);
2345 /* Precompute any arguments as needed. */
2346 precompute_arguments (is_const, must_preallocate, num_actuals,
2349 /* Now we are about to start emitting insns that can be deleted
2350 if a libcall is deleted. */
2351 if (is_const || is_malloc)
2354 /* If we have no actual push instructions, or shouldn't use them,
2355 make space for all args right now. */
2357 if (args_size.var != 0)
2359 if (old_stack_level == 0)
2361 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
2362 old_pending_adj = pending_stack_adjust;
2363 pending_stack_adjust = 0;
2364 #ifdef ACCUMULATE_OUTGOING_ARGS
2365 /* stack_arg_under_construction says whether a stack arg is
2366 being constructed at the old stack level. Pushing the stack
2367 gets a clean outgoing argument block. */
2368 old_stack_arg_under_construction = stack_arg_under_construction;
2369 stack_arg_under_construction = 0;
2372 argblock = push_block (ARGS_SIZE_RTX (args_size), 0, 0);
2376 /* Note that we must go through the motions of allocating an argument
2377 block even if the size is zero because we may be storing args
2378 in the area reserved for register arguments, which may be part of
2381 int needed = args_size.constant;
2383 /* Store the maximum argument space used. It will be pushed by
2384 the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
2387 if (needed > current_function_outgoing_args_size)
2388 current_function_outgoing_args_size = needed;
2390 if (must_preallocate)
2392 #ifdef ACCUMULATE_OUTGOING_ARGS
2393 /* Since the stack pointer will never be pushed, it is possible
2394 for the evaluation of a parm to clobber something we have
2395 already written to the stack. Since most function calls on
2396 RISC machines do not use the stack, this is uncommon, but
2397 must work correctly.
2399 Therefore, we save any area of the stack that was already
2400 written and that we are using. Here we set up to do this by
2401 making a new stack usage map from the old one. The actual
2402 save will be done by store_one_arg.
2404 Another approach might be to try to reorder the argument
2405 evaluations to avoid this conflicting stack usage. */
2407 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2408 /* Since we will be writing into the entire argument area, the
2409 map must be allocated for its entire size, not just the part
2410 that is the responsibility of the caller. */
2411 needed += reg_parm_stack_space;
2414 #ifdef ARGS_GROW_DOWNWARD
2415 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2418 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2421 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
2423 if (initial_highest_arg_in_use)
2424 bcopy (initial_stack_usage_map, stack_usage_map,
2425 initial_highest_arg_in_use);
2427 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
2428 bzero (&stack_usage_map[initial_highest_arg_in_use],
2429 (highest_outgoing_arg_in_use
2430 - initial_highest_arg_in_use));
2433 /* The address of the outgoing argument list must not be copied
2434 to a register here, because argblock would be left pointing
2435 to the wrong place after the call to
2436 allocate_dynamic_stack_space below. */
2438 argblock = virtual_outgoing_args_rtx;
2440 #else /* not ACCUMULATE_OUTGOING_ARGS */
2441 if (inhibit_defer_pop == 0)
2443 /* Try to reuse some or all of the pending_stack_adjust
2444 to get this space. Maybe we can avoid any pushing. */
2445 if (needed > pending_stack_adjust)
2447 needed -= pending_stack_adjust;
2448 pending_stack_adjust = 0;
2452 pending_stack_adjust -= needed;
2456 /* Special case this because overhead of `push_block' in this
2457 case is non-trivial. */
2459 argblock = virtual_outgoing_args_rtx;
2461 argblock = push_block (GEN_INT (needed), 0, 0);
2463 /* We only really need to call `copy_to_reg' in the case where
2464 push insns are going to be used to pass ARGBLOCK to a function
2465 call in ARGS. In that case, the stack pointer changes value
2466 from the allocation point to the call point, and hence
2467 the value of VIRTUAL_OUTGOING_ARGS_RTX changes as well.
2468 But might as well always do it. */
2469 argblock = copy_to_reg (argblock);
2470 #endif /* not ACCUMULATE_OUTGOING_ARGS */
2474 /* The argument block when performing a sibling call is the
2475 incoming argument block. */
2478 rtx temp = plus_constant (arg_pointer_rtx,
2479 FIRST_PARM_OFFSET (current_function_decl));
2480 argblock = force_reg (Pmode, force_operand (temp, NULL_RTX));
2483 #ifdef ACCUMULATE_OUTGOING_ARGS
2484 /* The save/restore code in store_one_arg handles all cases except one:
2485 a constructor call (including a C function returning a BLKmode struct)
2486 to initialize an argument. */
2487 if (stack_arg_under_construction)
2489 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2490 rtx push_size = GEN_INT (reg_parm_stack_space + args_size.constant);
2492 rtx push_size = GEN_INT (args_size.constant);
2494 if (old_stack_level == 0)
2496 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
2497 old_pending_adj = pending_stack_adjust;
2498 pending_stack_adjust = 0;
2499 /* stack_arg_under_construction says whether a stack arg is
2500 being constructed at the old stack level. Pushing the stack
2501 gets a clean outgoing argument block. */
2502 old_stack_arg_under_construction = stack_arg_under_construction;
2503 stack_arg_under_construction = 0;
2504 /* Make a new map for the new argument list. */
2505 stack_usage_map = (char *)alloca (highest_outgoing_arg_in_use);
2506 bzero (stack_usage_map, highest_outgoing_arg_in_use);
2507 highest_outgoing_arg_in_use = 0;
2509 allocate_dynamic_stack_space (push_size, NULL_RTX, BITS_PER_UNIT);
2511 /* If argument evaluation might modify the stack pointer, copy the
2512 address of the argument list to a register. */
2513 for (i = 0; i < num_actuals; i++)
2514 if (args[i].pass_on_stack)
2516 argblock = copy_addr_to_reg (argblock);
2521 compute_argument_addresses (args, argblock, num_actuals);
2523 #ifdef PUSH_ARGS_REVERSED
2524 #ifdef PREFERRED_STACK_BOUNDARY
2525 /* If we push args individually in reverse order, perform stack alignment
2526 before the first push (the last arg). */
2527 if (args_size.constant != unadjusted_args_size)
2529 /* When the stack adjustment is pending, we get better code
2530 by combining the adjustments. */
2531 if (pending_stack_adjust && ! is_const
2532 && ! inhibit_defer_pop)
2534 args_size.constant = (unadjusted_args_size
2535 + ((pending_stack_adjust
2536 + args_size.constant
2538 - unadjusted_args_size)
2539 % (preferred_stack_boundary
2541 pending_stack_adjust -= (args_size.constant
2542 - unadjusted_args_size);
2543 do_pending_stack_adjust ();
2545 else if (argblock == 0)
2546 anti_adjust_stack (GEN_INT (args_size.constant
2547 - unadjusted_args_size));
2548 arg_space_so_far += args_size.constant - unadjusted_args_size;
2550 /* Now that the stack is properly aligned, pops can't safely
2551 be deferred during the evaluation of the arguments. */
2557 /* Don't try to defer pops if preallocating, not even from the first arg,
2558 since ARGBLOCK probably refers to the SP. */
2562 funexp = rtx_for_function_call (fndecl, exp);
2564 /* Figure out the register where the value, if any, will come back. */
2566 if (TYPE_MODE (TREE_TYPE (exp)) != VOIDmode
2567 && ! structure_value_addr)
2569 if (pcc_struct_value)
2570 valreg = hard_function_value (build_pointer_type (TREE_TYPE (exp)),
2573 valreg = hard_function_value (TREE_TYPE (exp), fndecl, 0);
2576 /* Precompute all register parameters. It isn't safe to compute anything
2577 once we have started filling any specific hard regs. */
2578 precompute_register_parameters (num_actuals, args, ®_parm_seen);
2580 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
2581 /* Save the fixed argument area if it's part of the caller's frame and
2582 is clobbered by argument setup for this call. */
2583 save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
2584 &low_to_save, &high_to_save);
2587 /* Now store (and compute if necessary) all non-register parms.
2588 These come before register parms, since they can require block-moves,
2589 which could clobber the registers used for register parms.
2590 Parms which have partial registers are not stored here,
2591 but we do preallocate space here if they want that. */
2593 for (i = 0; i < num_actuals; i++)
2594 if (args[i].reg == 0 || args[i].pass_on_stack)
2595 store_one_arg (&args[i], argblock, may_be_alloca,
2596 args_size.var != 0, reg_parm_stack_space);
2598 /* If we have a parm that is passed in registers but not in memory
2599 and whose alignment does not permit a direct copy into registers,
2600 make a group of pseudos that correspond to each register that we
2602 if (STRICT_ALIGNMENT)
2603 store_unaligned_arguments_into_pseudos (args, num_actuals);
2605 /* Now store any partially-in-registers parm.
2606 This is the last place a block-move can happen. */
2608 for (i = 0; i < num_actuals; i++)
2609 if (args[i].partial != 0 && ! args[i].pass_on_stack)
2610 store_one_arg (&args[i], argblock, may_be_alloca,
2611 args_size.var != 0, reg_parm_stack_space);
2613 #ifndef PUSH_ARGS_REVERSED
2614 #ifdef PREFERRED_STACK_BOUNDARY
2615 /* If we pushed args in forward order, perform stack alignment
2616 after pushing the last arg. */
2617 /* ??? Fix for arg_space_so_far. */
2619 anti_adjust_stack (GEN_INT (args_size.constant
2620 - unadjusted_args_size));
2624 /* If register arguments require space on the stack and stack space
2625 was not preallocated, allocate stack space here for arguments
2626 passed in registers. */
2627 #if ! defined(ACCUMULATE_OUTGOING_ARGS) && defined(OUTGOING_REG_PARM_STACK_SPACE)
2628 if (must_preallocate == 0 && reg_parm_stack_space > 0)
2629 anti_adjust_stack (GEN_INT (reg_parm_stack_space));
2632 /* Pass the function the address in which to return a
2634 if (pass != 0 && structure_value_addr && ! structure_value_addr_parm)
2636 emit_move_insn (struct_value_rtx,
2638 force_operand (structure_value_addr,
2641 /* Mark the memory for the aggregate as write-only. */
2642 if (current_function_check_memory_usage)
2643 emit_library_call (chkr_set_right_libfunc, 1,
2645 structure_value_addr, ptr_mode,
2646 GEN_INT (struct_value_size),
2647 TYPE_MODE (sizetype),
2648 GEN_INT (MEMORY_USE_WO),
2649 TYPE_MODE (integer_type_node));
2651 if (GET_CODE (struct_value_rtx) == REG)
2652 use_reg (&call_fusage, struct_value_rtx);
2655 funexp = prepare_call_address (funexp, fndecl, &call_fusage,
2658 load_register_parameters (args, num_actuals, &call_fusage);
2660 /* Perform postincrements before actually calling the function. */
2663 /* Save a pointer to the last insn before the call, so that we can
2664 later safely search backwards to find the CALL_INSN. */
2665 before_call = get_last_insn ();
2667 /* All arguments and registers used for the call must be set up by
2670 /* Generate the actual call instruction. */
2671 emit_call_1 (funexp, fndecl, funtype, unadjusted_args_size,
2672 args_size.constant, struct_value_size,
2673 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
2674 valreg, old_inhibit_defer_pop, call_fusage,
2675 ((is_const ? ECF_IS_CONST : 0)
2676 | (nothrow ? ECF_NOTHROW : 0)
2677 | (pass == 0 ? ECF_SIBCALL : 0)));
2679 /* If call is cse'able, make appropriate pair of reg-notes around it.
2680 Test valreg so we don't crash; may safely ignore `const'
2681 if return type is void. Disable for PARALLEL return values, because
2682 we have no way to move such values into a pseudo register. */
2683 if (is_const && valreg != 0 && GET_CODE (valreg) != PARALLEL)
2686 rtx temp = gen_reg_rtx (GET_MODE (valreg));
2689 /* Mark the return value as a pointer if needed. */
2690 if (TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE)
2692 tree pointed_to = TREE_TYPE (TREE_TYPE (exp));
2693 mark_reg_pointer (temp, TYPE_ALIGN (pointed_to) / BITS_PER_UNIT);
2696 /* Construct an "equal form" for the value which mentions all the
2697 arguments in order as well as the function name. */
2698 #ifdef PUSH_ARGS_REVERSED
2699 for (i = 0; i < num_actuals; i++)
2700 note = gen_rtx_EXPR_LIST (VOIDmode, args[i].initial_value, note);
2702 for (i = num_actuals - 1; i >= 0; i--)
2703 note = gen_rtx_EXPR_LIST (VOIDmode, args[i].initial_value, note);
2705 note = gen_rtx_EXPR_LIST (VOIDmode, funexp, note);
2707 insns = get_insns ();
2710 emit_libcall_block (insns, temp, valreg, note);
2716 /* Otherwise, just write out the sequence without a note. */
2717 rtx insns = get_insns ();
2724 rtx temp = gen_reg_rtx (GET_MODE (valreg));
2727 /* The return value from a malloc-like function is a pointer. */
2728 if (TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE)
2729 mark_reg_pointer (temp, BIGGEST_ALIGNMENT / BITS_PER_UNIT);
2731 emit_move_insn (temp, valreg);
2733 /* The return value from a malloc-like function can not alias
2735 last = get_last_insn ();
2737 gen_rtx_EXPR_LIST (REG_NOALIAS, temp, REG_NOTES (last));
2739 /* Write out the sequence. */
2740 insns = get_insns ();
2746 /* For calls to `setjmp', etc., inform flow.c it should complain
2747 if nonvolatile values are live. For functions that cannot return,
2748 inform flow that control does not fall through. */
2750 if (returns_twice || is_volatile || is_longjmp || pass == 0)
2752 /* The barrier or NOTE_INSN_SETJMP note must be emitted
2753 immediately after the CALL_INSN. Some ports emit more
2754 than just a CALL_INSN above, so we must search for it here. */
2756 rtx last = get_last_insn ();
2757 while (GET_CODE (last) != CALL_INSN)
2759 last = PREV_INSN (last);
2760 /* There was no CALL_INSN? */
2761 if (last == before_call)
2767 emit_note_after (NOTE_INSN_SETJMP, last);
2768 current_function_calls_setjmp = 1;
2769 sibcall_failure = 1;
2772 emit_barrier_after (last);
2776 current_function_calls_longjmp = 1, sibcall_failure = 1;
2778 /* If value type not void, return an rtx for the value. */
2780 /* If there are cleanups to be called, don't use a hard reg as target.
2781 We need to double check this and see if it matters anymore. */
2782 if (any_pending_cleanups (1)
2783 && target && REG_P (target)
2784 && REGNO (target) < FIRST_PSEUDO_REGISTER)
2785 target = 0, sibcall_failure = 1;
2787 if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode
2790 target = const0_rtx;
2792 else if (structure_value_addr)
2794 if (target == 0 || GET_CODE (target) != MEM)
2796 target = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
2797 memory_address (TYPE_MODE (TREE_TYPE (exp)),
2798 structure_value_addr));
2799 MEM_SET_IN_STRUCT_P (target,
2800 AGGREGATE_TYPE_P (TREE_TYPE (exp)));
2803 else if (pcc_struct_value)
2805 /* This is the special C++ case where we need to
2806 know what the true target was. We take care to
2807 never use this value more than once in one expression. */
2808 target = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
2809 copy_to_reg (valreg));
2810 MEM_SET_IN_STRUCT_P (target, AGGREGATE_TYPE_P (TREE_TYPE (exp)));
2812 /* Handle calls that return values in multiple non-contiguous locations.
2813 The Irix 6 ABI has examples of this. */
2814 else if (GET_CODE (valreg) == PARALLEL)
2816 int bytes = int_size_in_bytes (TREE_TYPE (exp));
2820 target = assign_stack_temp (TYPE_MODE (TREE_TYPE (exp)),
2822 MEM_SET_IN_STRUCT_P (target, AGGREGATE_TYPE_P (TREE_TYPE (exp)));
2823 preserve_temp_slots (target);
2826 if (! rtx_equal_p (target, valreg))
2827 emit_group_store (target, valreg, bytes,
2828 TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
2829 /* We can not support sibling calls for this case. */
2830 sibcall_failure = 1;
2833 && GET_MODE (target) == TYPE_MODE (TREE_TYPE (exp))
2834 && GET_MODE (target) == GET_MODE (valreg))
2836 /* TARGET and VALREG cannot be equal at this point because the
2837 latter would not have REG_FUNCTION_VALUE_P true, while the
2838 former would if it were referring to the same register.
2840 If they refer to the same register, this move will be a no-op,
2841 except when function inlining is being done. */
2842 emit_move_insn (target, valreg);
2844 else if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
2845 target = copy_blkmode_from_reg (target, valreg, TREE_TYPE (exp));
2847 target = copy_to_reg (valreg);
2849 #ifdef PROMOTE_FUNCTION_RETURN
2850 /* If we promoted this return value, make the proper SUBREG. TARGET
2851 might be const0_rtx here, so be careful. */
2852 if (GET_CODE (target) == REG
2853 && TYPE_MODE (TREE_TYPE (exp)) != BLKmode
2854 && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
2856 tree type = TREE_TYPE (exp);
2857 int unsignedp = TREE_UNSIGNED (type);
2859 /* If we don't promote as expected, something is wrong. */
2860 if (GET_MODE (target)
2861 != promote_mode (type, TYPE_MODE (type), &unsignedp, 1))
2864 target = gen_rtx_SUBREG (TYPE_MODE (type), target, 0);
2865 SUBREG_PROMOTED_VAR_P (target) = 1;
2866 SUBREG_PROMOTED_UNSIGNED_P (target) = unsignedp;
2870 /* If size of args is variable or this was a constructor call for a stack
2871 argument, restore saved stack-pointer value. */
2873 if (old_stack_level)
2875 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
2876 pending_stack_adjust = old_pending_adj;
2877 #ifdef ACCUMULATE_OUTGOING_ARGS
2878 stack_arg_under_construction = old_stack_arg_under_construction;
2879 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2880 stack_usage_map = initial_stack_usage_map;
2882 sibcall_failure = 1;
2884 #ifdef ACCUMULATE_OUTGOING_ARGS
2887 #ifdef REG_PARM_STACK_SPACE
2890 restore_fixed_argument_area (save_area, argblock,
2891 high_to_save, low_to_save);
2892 sibcall_failure = 1;
2896 /* If we saved any argument areas, restore them. */
2897 for (i = 0; i < num_actuals; i++)
2898 if (args[i].save_area)
2900 enum machine_mode save_mode = GET_MODE (args[i].save_area);
2902 = gen_rtx_MEM (save_mode,
2903 memory_address (save_mode,
2904 XEXP (args[i].stack_slot, 0)));
2906 if (save_mode != BLKmode)
2907 emit_move_insn (stack_area, args[i].save_area);
2909 emit_block_move (stack_area,
2910 validize_mem (args[i].save_area),
2911 GEN_INT (args[i].size.constant),
2912 PARM_BOUNDARY / BITS_PER_UNIT);
2913 sibcall_failure = 1;
2916 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2917 stack_usage_map = initial_stack_usage_map;
2921 /* If this was alloca, record the new stack level for nonlocal gotos.
2922 Check for the handler slots since we might not have a save area
2923 for non-local gotos. */
2925 if (may_be_alloca && nonlocal_goto_handler_slots != 0)
2926 emit_stack_save (SAVE_NONLOCAL, &nonlocal_goto_stack_level, NULL_RTX);
2930 /* Free up storage we no longer need. */
2931 for (i = 0; i < num_actuals; ++i)
2932 if (args[i].aligned_regs)
2933 free (args[i].aligned_regs);
2937 /* Undo the fake expand_start_target_temps we did earlier. If
2938 there had been any cleanups created, we've already set
2940 expand_end_target_temps ();
2943 insns = get_insns ();
2948 tail_call_insns = insns;
2950 /* If the current function's argument block is not large enough
2951 to hold the outoing arguments, or we encountered some other
2952 situation we couldn't handle, zero out the sequence. */
2953 if (current_function_args_size < args_size.constant
2955 tail_call_insns = NULL_RTX;
2957 /* Restore the pending stack adjustment now that we have
2958 finished generating the sibling call sequence. */
2959 pending_stack_adjust = save_pending_stack_adjust;
2962 normal_call_insns = insns;
2965 /* The function optimize_sibling_and_tail_recursive_calls doesn't
2966 handle CALL_PLACEHOLDERs inside other CALL_PLACEHOLDERs. This
2967 can happen if the arguments to this function call an inline
2968 function who's expansion contains another CALL_PLACEHOLDER.
2970 If there are any C_Ps in any of these sequences, replace them
2971 with their normal call. */
2973 for (insn = normal_call_insns; insn; insn = NEXT_INSN (insn))
2974 if (GET_CODE (insn) == CALL_INSN
2975 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
2976 replace_call_placeholder (insn, sibcall_use_normal);
2978 for (insn = tail_call_insns; insn; insn = NEXT_INSN (insn))
2979 if (GET_CODE (insn) == CALL_INSN
2980 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
2981 replace_call_placeholder (insn, sibcall_use_normal);
2983 for (insn = tail_recursion_insns; insn; insn = NEXT_INSN (insn))
2984 if (GET_CODE (insn) == CALL_INSN
2985 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
2986 replace_call_placeholder (insn, sibcall_use_normal);
2988 /* If this was a potential tail recursion site, then emit a
2989 CALL_PLACEHOLDER with the normal and the tail recursion streams.
2990 One of them will be selected later. */
2991 if (tail_recursion_insns || tail_call_insns)
2993 /* The tail recursion label must be kept around. We could expose
2994 its use in the CALL_PLACEHOLDER, but that creates unwanted edges
2995 and makes determining true tail recursion sites difficult.
2997 So we set LABEL_PRESERVE_P here, then clear it when we select
2998 one of the call sequences after rtl generation is complete. */
2999 if (tail_recursion_insns)
3000 LABEL_PRESERVE_P (tail_recursion_label) = 1;
3001 emit_call_insn (gen_rtx_CALL_PLACEHOLDER (VOIDmode, normal_call_insns,
3003 tail_recursion_insns,
3004 tail_recursion_label));
3007 emit_insns (normal_call_insns);
3009 currently_expanding_call--;
3014 /* Returns nonzero if FUN is the symbol for a library function which can
3018 libfunc_nothrow (fun)
3021 if (fun == throw_libfunc
3022 || fun == rethrow_libfunc
3023 || fun == sjthrow_libfunc
3024 || fun == sjpopnthrow_libfunc)
3030 /* Output a library call to function FUN (a SYMBOL_REF rtx)
3031 (emitting the queue unless NO_QUEUE is nonzero),
3032 for a value of mode OUTMODE,
3033 with NARGS different arguments, passed as alternating rtx values
3034 and machine_modes to convert them to.
3035 The rtx values should have been passed through protect_from_queue already.
3037 NO_QUEUE will be true if and only if the library call is a `const' call
3038 which will be enclosed in REG_LIBCALL/REG_RETVAL notes; it is equivalent
3039 to the variable is_const in expand_call.
3041 NO_QUEUE must be true for const calls, because if it isn't, then
3042 any pending increment will be emitted between REG_LIBCALL/REG_RETVAL notes,
3043 and will be lost if the libcall sequence is optimized away.
3045 NO_QUEUE must be false for non-const calls, because if it isn't, the
3046 call insn will have its CONST_CALL_P bit set, and it will be incorrectly
3047 optimized. For instance, the instruction scheduler may incorrectly
3048 move memory references across the non-const call. */
3051 emit_library_call VPARAMS((rtx orgfun, int no_queue, enum machine_mode outmode,
3054 #ifndef ANSI_PROTOTYPES
3057 enum machine_mode outmode;
3061 /* Total size in bytes of all the stack-parms scanned so far. */
3062 struct args_size args_size;
3063 /* Size of arguments before any adjustments (such as rounding). */
3064 struct args_size original_args_size;
3065 register int argnum;
3069 struct args_size alignment_pad;
3071 CUMULATIVE_ARGS args_so_far;
3072 struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
3073 struct args_size offset; struct args_size size; rtx save_area; };
3075 int old_inhibit_defer_pop = inhibit_defer_pop;
3076 rtx call_fusage = 0;
3077 int reg_parm_stack_space = 0;
3079 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
3080 /* Define the boundary of the register parm stack space that needs to be
3082 int low_to_save = -1, high_to_save = 0;
3083 rtx save_area = 0; /* Place that it is saved */
3086 #ifdef ACCUMULATE_OUTGOING_ARGS
3087 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
3088 char *initial_stack_usage_map = stack_usage_map;
3092 #ifdef REG_PARM_STACK_SPACE
3093 /* Size of the stack reserved for parameter registers. */
3094 #ifdef MAYBE_REG_PARM_STACK_SPACE
3095 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
3097 reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0);
3101 VA_START (p, nargs);
3103 #ifndef ANSI_PROTOTYPES
3104 orgfun = va_arg (p, rtx);
3105 no_queue = va_arg (p, int);
3106 outmode = va_arg (p, enum machine_mode);
3107 nargs = va_arg (p, int);
3112 nothrow = libfunc_nothrow (fun);
3114 /* Copy all the libcall-arguments out of the varargs data
3115 and into a vector ARGVEC.
3117 Compute how to pass each argument. We only support a very small subset
3118 of the full argument passing conventions to limit complexity here since
3119 library functions shouldn't have many args. */
3121 argvec = (struct arg *) alloca (nargs * sizeof (struct arg));
3122 bzero ((char *) argvec, nargs * sizeof (struct arg));
3125 INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0);
3127 args_size.constant = 0;
3132 #ifdef PREFERRED_STACK_BOUNDARY
3133 /* Ensure current function's preferred stack boundary is at least
3135 if (cfun->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
3136 cfun->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
3139 for (count = 0; count < nargs; count++)
3141 rtx val = va_arg (p, rtx);
3142 enum machine_mode mode = va_arg (p, enum machine_mode);
3144 /* We cannot convert the arg value to the mode the library wants here;
3145 must do it earlier where we know the signedness of the arg. */
3147 || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
3150 /* On some machines, there's no way to pass a float to a library fcn.
3151 Pass it as a double instead. */
3152 #ifdef LIBGCC_NEEDS_DOUBLE
3153 if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
3154 val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode;
3157 /* There's no need to call protect_from_queue, because
3158 either emit_move_insn or emit_push_insn will do that. */
3160 /* Make sure it is a reasonable operand for a move or push insn. */
3161 if (GET_CODE (val) != REG && GET_CODE (val) != MEM
3162 && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
3163 val = force_operand (val, NULL_RTX);
3165 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
3166 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
3168 /* We do not support FUNCTION_ARG_CALLEE_COPIES here since it can
3169 be viewed as just an efficiency improvement. */
3170 rtx slot = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
3171 emit_move_insn (slot, val);
3172 val = force_operand (XEXP (slot, 0), NULL_RTX);
3177 argvec[count].value = val;
3178 argvec[count].mode = mode;
3180 argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
3182 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3183 argvec[count].partial
3184 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
3186 argvec[count].partial = 0;
3189 locate_and_pad_parm (mode, NULL_TREE,
3190 argvec[count].reg && argvec[count].partial == 0,
3191 NULL_TREE, &args_size, &argvec[count].offset,
3192 &argvec[count].size, &alignment_pad);
3194 if (argvec[count].size.var)
3197 if (reg_parm_stack_space == 0 && argvec[count].partial)
3198 argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
3200 if (argvec[count].reg == 0 || argvec[count].partial != 0
3201 || reg_parm_stack_space > 0)
3202 args_size.constant += argvec[count].size.constant;
3204 FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
3208 #ifdef FINAL_REG_PARM_STACK_SPACE
3209 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
3213 /* If this machine requires an external definition for library
3214 functions, write one out. */
3215 assemble_external_libcall (fun);
3217 original_args_size = args_size;
3218 #ifdef PREFERRED_STACK_BOUNDARY
3219 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
3220 / STACK_BYTES) * STACK_BYTES);
3223 args_size.constant = MAX (args_size.constant,
3224 reg_parm_stack_space);
3226 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3227 args_size.constant -= reg_parm_stack_space;
3230 if (args_size.constant > current_function_outgoing_args_size)
3231 current_function_outgoing_args_size = args_size.constant;
3233 #ifdef ACCUMULATE_OUTGOING_ARGS
3234 /* Since the stack pointer will never be pushed, it is possible for
3235 the evaluation of a parm to clobber something we have already
3236 written to the stack. Since most function calls on RISC machines
3237 do not use the stack, this is uncommon, but must work correctly.
3239 Therefore, we save any area of the stack that was already written
3240 and that we are using. Here we set up to do this by making a new
3241 stack usage map from the old one.
3243 Another approach might be to try to reorder the argument
3244 evaluations to avoid this conflicting stack usage. */
3246 needed = args_size.constant;
3248 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3249 /* Since we will be writing into the entire argument area, the
3250 map must be allocated for its entire size, not just the part that
3251 is the responsibility of the caller. */
3252 needed += reg_parm_stack_space;
3255 #ifdef ARGS_GROW_DOWNWARD
3256 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3259 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3262 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
3264 if (initial_highest_arg_in_use)
3265 bcopy (initial_stack_usage_map, stack_usage_map,
3266 initial_highest_arg_in_use);
3268 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
3269 bzero (&stack_usage_map[initial_highest_arg_in_use],
3270 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
3273 /* The address of the outgoing argument list must not be copied to a
3274 register here, because argblock would be left pointing to the
3275 wrong place after the call to allocate_dynamic_stack_space below.
3278 argblock = virtual_outgoing_args_rtx;
3279 #else /* not ACCUMULATE_OUTGOING_ARGS */
3280 #ifndef PUSH_ROUNDING
3281 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
3285 #ifdef PUSH_ARGS_REVERSED
3286 #ifdef PREFERRED_STACK_BOUNDARY
3287 /* If we push args individually in reverse order, perform stack alignment
3288 before the first push (the last arg). */
3290 anti_adjust_stack (GEN_INT (args_size.constant
3291 - original_args_size.constant));
3295 #ifdef PUSH_ARGS_REVERSED
3303 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
3304 /* The argument list is the property of the called routine and it
3305 may clobber it. If the fixed area has been used for previous
3306 parameters, we must save and restore it.
3308 Here we compute the boundary of the that needs to be saved, if any. */
3310 #ifdef ARGS_GROW_DOWNWARD
3311 for (count = 0; count < reg_parm_stack_space + 1; count++)
3313 for (count = 0; count < reg_parm_stack_space; count++)
3316 if (count >= highest_outgoing_arg_in_use
3317 || stack_usage_map[count] == 0)
3320 if (low_to_save == -1)
3321 low_to_save = count;
3323 high_to_save = count;
3326 if (low_to_save >= 0)
3328 int num_to_save = high_to_save - low_to_save + 1;
3329 enum machine_mode save_mode
3330 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
3333 /* If we don't have the required alignment, must do this in BLKmode. */
3334 if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
3335 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
3336 save_mode = BLKmode;
3338 #ifdef ARGS_GROW_DOWNWARD
3339 stack_area = gen_rtx_MEM (save_mode,
3340 memory_address (save_mode,
3341 plus_constant (argblock,
3344 stack_area = gen_rtx_MEM (save_mode,
3345 memory_address (save_mode,
3346 plus_constant (argblock,
3349 if (save_mode == BLKmode)
3351 save_area = assign_stack_temp (BLKmode, num_to_save, 0);
3352 emit_block_move (validize_mem (save_area), stack_area,
3353 GEN_INT (num_to_save),
3354 PARM_BOUNDARY / BITS_PER_UNIT);
3358 save_area = gen_reg_rtx (save_mode);
3359 emit_move_insn (save_area, stack_area);
3364 /* Push the args that need to be pushed. */
3366 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3367 are to be pushed. */
3368 for (count = 0; count < nargs; count++, argnum += inc)
3370 register enum machine_mode mode = argvec[argnum].mode;
3371 register rtx val = argvec[argnum].value;
3372 rtx reg = argvec[argnum].reg;
3373 int partial = argvec[argnum].partial;
3374 #ifdef ACCUMULATE_OUTGOING_ARGS
3375 int lower_bound, upper_bound, i;
3378 if (! (reg != 0 && partial == 0))
3380 #ifdef ACCUMULATE_OUTGOING_ARGS
3381 /* If this is being stored into a pre-allocated, fixed-size, stack
3382 area, save any previous data at that location. */
3384 #ifdef ARGS_GROW_DOWNWARD
3385 /* stack_slot is negative, but we want to index stack_usage_map
3386 with positive values. */
3387 upper_bound = -argvec[argnum].offset.constant + 1;
3388 lower_bound = upper_bound - argvec[argnum].size.constant;
3390 lower_bound = argvec[argnum].offset.constant;
3391 upper_bound = lower_bound + argvec[argnum].size.constant;
3394 for (i = lower_bound; i < upper_bound; i++)
3395 if (stack_usage_map[i]
3396 /* Don't store things in the fixed argument area at this point;
3397 it has already been saved. */
3398 && i > reg_parm_stack_space)
3401 if (i != upper_bound)
3403 /* We need to make a save area. See what mode we can make it. */
3404 enum machine_mode save_mode
3405 = mode_for_size (argvec[argnum].size.constant * BITS_PER_UNIT,
3412 plus_constant (argblock,
3413 argvec[argnum].offset.constant)));
3415 argvec[argnum].save_area = gen_reg_rtx (save_mode);
3416 emit_move_insn (argvec[argnum].save_area, stack_area);
3419 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
3420 argblock, GEN_INT (argvec[argnum].offset.constant),
3421 reg_parm_stack_space, ARGS_SIZE_RTX (alignment_pad));
3423 #ifdef ACCUMULATE_OUTGOING_ARGS
3424 /* Now mark the segment we just used. */
3425 for (i = lower_bound; i < upper_bound; i++)
3426 stack_usage_map[i] = 1;
3433 #ifndef PUSH_ARGS_REVERSED
3434 #ifdef PREFERRED_STACK_BOUNDARY
3435 /* If we pushed args in forward order, perform stack alignment
3436 after pushing the last arg. */
3438 anti_adjust_stack (GEN_INT (args_size.constant
3439 - original_args_size.constant));
3443 #ifdef PUSH_ARGS_REVERSED
3449 fun = prepare_call_address (fun, NULL_TREE, &call_fusage, 0);
3451 /* Now load any reg parms into their regs. */
3453 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3454 are to be pushed. */
3455 for (count = 0; count < nargs; count++, argnum += inc)
3457 register rtx val = argvec[argnum].value;
3458 rtx reg = argvec[argnum].reg;
3459 int partial = argvec[argnum].partial;
3461 /* Handle calls that pass values in multiple non-contiguous
3462 locations. The PA64 has examples of this for library calls. */
3463 if (reg != 0 && GET_CODE (reg) == PARALLEL)
3464 emit_group_load (reg, val,
3465 GET_MODE_SIZE (GET_MODE (val)),
3466 GET_MODE_ALIGNMENT (GET_MODE (val)));
3467 else if (reg != 0 && partial == 0)
3468 emit_move_insn (reg, val);
3473 /* For version 1.37, try deleting this entirely. */
3477 /* Any regs containing parms remain in use through the call. */
3478 for (count = 0; count < nargs; count++)
3480 rtx reg = argvec[count].reg;
3481 if (reg != 0 && GET_CODE (argvec[count].reg) == PARALLEL)
3482 use_group_regs (&call_fusage, reg);
3484 use_reg (&call_fusage, reg);
3487 /* Don't allow popping to be deferred, since then
3488 cse'ing of library calls could delete a call and leave the pop. */
3491 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
3492 will set inhibit_defer_pop to that value. */
3494 /* The return type is needed to decide how many bytes the function pops.
3495 Signedness plays no role in that, so for simplicity, we pretend it's
3496 always signed. We also assume that the list of arguments passed has
3497 no impact, so we pretend it is unknown. */
3500 get_identifier (XSTR (orgfun, 0)),
3501 build_function_type (outmode == VOIDmode ? void_type_node
3502 : type_for_mode (outmode, 0), NULL_TREE),
3503 original_args_size.constant, args_size.constant, 0,
3504 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
3505 outmode != VOIDmode ? hard_libcall_value (outmode) : NULL_RTX,
3506 old_inhibit_defer_pop + 1, call_fusage,
3507 ((no_queue ? ECF_IS_CONST : 0)
3508 | (nothrow ? ECF_NOTHROW : 0)));
3512 /* Now restore inhibit_defer_pop to its actual original value. */
3515 #ifdef ACCUMULATE_OUTGOING_ARGS
3516 #ifdef REG_PARM_STACK_SPACE
3519 enum machine_mode save_mode = GET_MODE (save_area);
3520 #ifdef ARGS_GROW_DOWNWARD
3522 = gen_rtx_MEM (save_mode,
3523 memory_address (save_mode,
3524 plus_constant (argblock,
3528 = gen_rtx_MEM (save_mode,
3529 memory_address (save_mode,
3530 plus_constant (argblock, low_to_save)));
3533 if (save_mode != BLKmode)
3534 emit_move_insn (stack_area, save_area);
3536 emit_block_move (stack_area, validize_mem (save_area),
3537 GEN_INT (high_to_save - low_to_save + 1),
3538 PARM_BOUNDARY / BITS_PER_UNIT);
3542 /* If we saved any argument areas, restore them. */
3543 for (count = 0; count < nargs; count++)
3544 if (argvec[count].save_area)
3546 enum machine_mode save_mode = GET_MODE (argvec[count].save_area);
3548 = gen_rtx_MEM (save_mode,
3551 plus_constant (argblock,
3552 argvec[count].offset.constant)));
3554 emit_move_insn (stack_area, argvec[count].save_area);
3557 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3558 stack_usage_map = initial_stack_usage_map;
3562 /* Like emit_library_call except that an extra argument, VALUE,
3563 comes second and says where to store the result.
3564 (If VALUE is zero, this function chooses a convenient way
3565 to return the value.
3567 This function returns an rtx for where the value is to be found.
3568 If VALUE is nonzero, VALUE is returned. */
3571 emit_library_call_value VPARAMS((rtx orgfun, rtx value, int no_queue,
3572 enum machine_mode outmode, int nargs, ...))
3574 #ifndef ANSI_PROTOTYPES
3578 enum machine_mode outmode;
3582 /* Total size in bytes of all the stack-parms scanned so far. */
3583 struct args_size args_size;
3584 /* Size of arguments before any adjustments (such as rounding). */
3585 struct args_size original_args_size;
3586 register int argnum;
3590 struct args_size alignment_pad;
3592 CUMULATIVE_ARGS args_so_far;
3593 struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
3594 struct args_size offset; struct args_size size; rtx save_area; };
3596 int old_inhibit_defer_pop = inhibit_defer_pop;
3597 rtx call_fusage = 0;
3599 int pcc_struct_value = 0;
3600 int struct_value_size = 0;
3602 int reg_parm_stack_space = 0;
3604 #ifdef ACCUMULATE_OUTGOING_ARGS
3608 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
3609 /* Define the boundary of the register parm stack space that needs to be
3611 int low_to_save = -1, high_to_save = 0;
3612 rtx save_area = 0; /* Place that it is saved */
3615 #ifdef ACCUMULATE_OUTGOING_ARGS
3616 /* Size of the stack reserved for parameter registers. */
3617 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
3618 char *initial_stack_usage_map = stack_usage_map;
3621 #ifdef REG_PARM_STACK_SPACE
3622 #ifdef MAYBE_REG_PARM_STACK_SPACE
3623 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
3625 reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0);
3629 VA_START (p, nargs);
3631 #ifndef ANSI_PROTOTYPES
3632 orgfun = va_arg (p, rtx);
3633 value = va_arg (p, rtx);
3634 no_queue = va_arg (p, int);
3635 outmode = va_arg (p, enum machine_mode);
3636 nargs = va_arg (p, int);
3639 is_const = no_queue;
3642 nothrow = libfunc_nothrow (fun);
3644 #ifdef PREFERRED_STACK_BOUNDARY
3645 /* Ensure current function's preferred stack boundary is at least
3647 if (cfun->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
3648 cfun->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
3651 /* If this kind of value comes back in memory,
3652 decide where in memory it should come back. */
3653 if (aggregate_value_p (type_for_mode (outmode, 0)))
3655 #ifdef PCC_STATIC_STRUCT_RETURN
3657 = hard_function_value (build_pointer_type (type_for_mode (outmode, 0)),
3659 mem_value = gen_rtx_MEM (outmode, pointer_reg);
3660 pcc_struct_value = 1;
3662 value = gen_reg_rtx (outmode);
3663 #else /* not PCC_STATIC_STRUCT_RETURN */
3664 struct_value_size = GET_MODE_SIZE (outmode);
3665 if (value != 0 && GET_CODE (value) == MEM)
3668 mem_value = assign_stack_temp (outmode, GET_MODE_SIZE (outmode), 0);
3671 /* This call returns a big structure. */
3675 /* ??? Unfinished: must pass the memory address as an argument. */
3677 /* Copy all the libcall-arguments out of the varargs data
3678 and into a vector ARGVEC.
3680 Compute how to pass each argument. We only support a very small subset
3681 of the full argument passing conventions to limit complexity here since
3682 library functions shouldn't have many args. */
3684 argvec = (struct arg *) alloca ((nargs + 1) * sizeof (struct arg));
3685 bzero ((char *) argvec, (nargs + 1) * sizeof (struct arg));
3687 INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0);
3689 args_size.constant = 0;
3696 /* If there's a structure value address to be passed,
3697 either pass it in the special place, or pass it as an extra argument. */
3698 if (mem_value && struct_value_rtx == 0 && ! pcc_struct_value)
3700 rtx addr = XEXP (mem_value, 0);
3703 /* Make sure it is a reasonable operand for a move or push insn. */
3704 if (GET_CODE (addr) != REG && GET_CODE (addr) != MEM
3705 && ! (CONSTANT_P (addr) && LEGITIMATE_CONSTANT_P (addr)))
3706 addr = force_operand (addr, NULL_RTX);
3708 argvec[count].value = addr;
3709 argvec[count].mode = Pmode;
3710 argvec[count].partial = 0;
3712 argvec[count].reg = FUNCTION_ARG (args_so_far, Pmode, NULL_TREE, 1);
3713 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3714 if (FUNCTION_ARG_PARTIAL_NREGS (args_so_far, Pmode, NULL_TREE, 1))
3718 locate_and_pad_parm (Pmode, NULL_TREE,
3719 argvec[count].reg && argvec[count].partial == 0,
3720 NULL_TREE, &args_size, &argvec[count].offset,
3721 &argvec[count].size, &alignment_pad);
3724 if (argvec[count].reg == 0 || argvec[count].partial != 0
3725 || reg_parm_stack_space > 0)
3726 args_size.constant += argvec[count].size.constant;
3728 FUNCTION_ARG_ADVANCE (args_so_far, Pmode, (tree) 0, 1);
3733 for (; count < nargs; count++)
3735 rtx val = va_arg (p, rtx);
3736 enum machine_mode mode = va_arg (p, enum machine_mode);
3738 /* We cannot convert the arg value to the mode the library wants here;
3739 must do it earlier where we know the signedness of the arg. */
3741 || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
3744 /* On some machines, there's no way to pass a float to a library fcn.
3745 Pass it as a double instead. */
3746 #ifdef LIBGCC_NEEDS_DOUBLE
3747 if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
3748 val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode;
3751 /* There's no need to call protect_from_queue, because
3752 either emit_move_insn or emit_push_insn will do that. */
3754 /* Make sure it is a reasonable operand for a move or push insn. */
3755 if (GET_CODE (val) != REG && GET_CODE (val) != MEM
3756 && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
3757 val = force_operand (val, NULL_RTX);
3759 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
3760 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
3762 /* We do not support FUNCTION_ARG_CALLEE_COPIES here since it can
3763 be viewed as just an efficiency improvement. */
3764 rtx slot = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
3765 emit_move_insn (slot, val);
3766 val = XEXP (slot, 0);
3771 argvec[count].value = val;
3772 argvec[count].mode = mode;
3774 argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
3776 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3777 argvec[count].partial
3778 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
3780 argvec[count].partial = 0;
3783 locate_and_pad_parm (mode, NULL_TREE,
3784 argvec[count].reg && argvec[count].partial == 0,
3785 NULL_TREE, &args_size, &argvec[count].offset,
3786 &argvec[count].size, &alignment_pad);
3788 if (argvec[count].size.var)
3791 if (reg_parm_stack_space == 0 && argvec[count].partial)
3792 argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
3794 if (argvec[count].reg == 0 || argvec[count].partial != 0
3795 || reg_parm_stack_space > 0)
3796 args_size.constant += argvec[count].size.constant;
3798 FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
3802 #ifdef FINAL_REG_PARM_STACK_SPACE
3803 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
3806 /* If this machine requires an external definition for library
3807 functions, write one out. */
3808 assemble_external_libcall (fun);
3810 original_args_size = args_size;
3811 #ifdef PREFERRED_STACK_BOUNDARY
3812 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
3813 / STACK_BYTES) * STACK_BYTES);
3816 args_size.constant = MAX (args_size.constant,
3817 reg_parm_stack_space);
3819 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3820 args_size.constant -= reg_parm_stack_space;
3823 if (args_size.constant > current_function_outgoing_args_size)
3824 current_function_outgoing_args_size = args_size.constant;
3826 #ifdef ACCUMULATE_OUTGOING_ARGS
3827 /* Since the stack pointer will never be pushed, it is possible for
3828 the evaluation of a parm to clobber something we have already
3829 written to the stack. Since most function calls on RISC machines
3830 do not use the stack, this is uncommon, but must work correctly.
3832 Therefore, we save any area of the stack that was already written
3833 and that we are using. Here we set up to do this by making a new
3834 stack usage map from the old one.
3836 Another approach might be to try to reorder the argument
3837 evaluations to avoid this conflicting stack usage. */
3839 needed = args_size.constant;
3841 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3842 /* Since we will be writing into the entire argument area, the
3843 map must be allocated for its entire size, not just the part that
3844 is the responsibility of the caller. */
3845 needed += reg_parm_stack_space;
3848 #ifdef ARGS_GROW_DOWNWARD
3849 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3852 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3855 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
3857 if (initial_highest_arg_in_use)
3858 bcopy (initial_stack_usage_map, stack_usage_map,
3859 initial_highest_arg_in_use);
3861 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
3862 bzero (&stack_usage_map[initial_highest_arg_in_use],
3863 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
3866 /* The address of the outgoing argument list must not be copied to a
3867 register here, because argblock would be left pointing to the
3868 wrong place after the call to allocate_dynamic_stack_space below.
3871 argblock = virtual_outgoing_args_rtx;
3872 #else /* not ACCUMULATE_OUTGOING_ARGS */
3873 #ifndef PUSH_ROUNDING
3874 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
3878 #ifdef PUSH_ARGS_REVERSED
3879 #ifdef PREFERRED_STACK_BOUNDARY
3880 /* If we push args individually in reverse order, perform stack alignment
3881 before the first push (the last arg). */
3883 anti_adjust_stack (GEN_INT (args_size.constant
3884 - original_args_size.constant));
3888 #ifdef PUSH_ARGS_REVERSED
3896 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
3897 /* The argument list is the property of the called routine and it
3898 may clobber it. If the fixed area has been used for previous
3899 parameters, we must save and restore it.
3901 Here we compute the boundary of the that needs to be saved, if any. */
3903 #ifdef ARGS_GROW_DOWNWARD
3904 for (count = 0; count < reg_parm_stack_space + 1; count++)
3906 for (count = 0; count < reg_parm_stack_space; count++)
3909 if (count >= highest_outgoing_arg_in_use
3910 || stack_usage_map[count] == 0)
3913 if (low_to_save == -1)
3914 low_to_save = count;
3916 high_to_save = count;
3919 if (low_to_save >= 0)
3921 int num_to_save = high_to_save - low_to_save + 1;
3922 enum machine_mode save_mode
3923 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
3926 /* If we don't have the required alignment, must do this in BLKmode. */
3927 if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
3928 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
3929 save_mode = BLKmode;
3931 #ifdef ARGS_GROW_DOWNWARD
3932 stack_area = gen_rtx_MEM (save_mode,
3933 memory_address (save_mode,
3934 plus_constant (argblock,
3937 stack_area = gen_rtx_MEM (save_mode,
3938 memory_address (save_mode,
3939 plus_constant (argblock,
3942 if (save_mode == BLKmode)
3944 save_area = assign_stack_temp (BLKmode, num_to_save, 0);
3945 emit_block_move (validize_mem (save_area), stack_area,
3946 GEN_INT (num_to_save),
3947 PARM_BOUNDARY / BITS_PER_UNIT);
3951 save_area = gen_reg_rtx (save_mode);
3952 emit_move_insn (save_area, stack_area);
3957 /* Push the args that need to be pushed. */
3959 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3960 are to be pushed. */
3961 for (count = 0; count < nargs; count++, argnum += inc)
3963 register enum machine_mode mode = argvec[argnum].mode;
3964 register rtx val = argvec[argnum].value;
3965 rtx reg = argvec[argnum].reg;
3966 int partial = argvec[argnum].partial;
3967 #ifdef ACCUMULATE_OUTGOING_ARGS
3968 int lower_bound, upper_bound, i;
3971 if (! (reg != 0 && partial == 0))
3973 #ifdef ACCUMULATE_OUTGOING_ARGS
3974 /* If this is being stored into a pre-allocated, fixed-size, stack
3975 area, save any previous data at that location. */
3977 #ifdef ARGS_GROW_DOWNWARD
3978 /* stack_slot is negative, but we want to index stack_usage_map
3979 with positive values. */
3980 upper_bound = -argvec[argnum].offset.constant + 1;
3981 lower_bound = upper_bound - argvec[argnum].size.constant;
3983 lower_bound = argvec[argnum].offset.constant;
3984 upper_bound = lower_bound + argvec[argnum].size.constant;
3987 for (i = lower_bound; i < upper_bound; i++)
3988 if (stack_usage_map[i]
3989 /* Don't store things in the fixed argument area at this point;
3990 it has already been saved. */
3991 && i > reg_parm_stack_space)
3994 if (i != upper_bound)
3996 /* We need to make a save area. See what mode we can make it. */
3997 enum machine_mode save_mode
3998 = mode_for_size (argvec[argnum].size.constant * BITS_PER_UNIT,
4005 plus_constant (argblock,
4006 argvec[argnum].offset.constant)));
4007 argvec[argnum].save_area = gen_reg_rtx (save_mode);
4009 emit_move_insn (argvec[argnum].save_area, stack_area);
4012 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
4013 argblock, GEN_INT (argvec[argnum].offset.constant),
4014 reg_parm_stack_space, ARGS_SIZE_RTX (alignment_pad));
4016 #ifdef ACCUMULATE_OUTGOING_ARGS
4017 /* Now mark the segment we just used. */
4018 for (i = lower_bound; i < upper_bound; i++)
4019 stack_usage_map[i] = 1;
4026 #ifndef PUSH_ARGS_REVERSED
4027 #ifdef PREFERRED_STACK_BOUNDARY
4028 /* If we pushed args in forward order, perform stack alignment
4029 after pushing the last arg. */
4031 anti_adjust_stack (GEN_INT (args_size.constant
4032 - original_args_size.constant));
4036 #ifdef PUSH_ARGS_REVERSED
4042 fun = prepare_call_address (fun, NULL_TREE, &call_fusage, 0);
4044 /* Now load any reg parms into their regs. */
4046 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
4047 are to be pushed. */
4048 for (count = 0; count < nargs; count++, argnum += inc)
4050 register rtx val = argvec[argnum].value;
4051 rtx reg = argvec[argnum].reg;
4052 int partial = argvec[argnum].partial;
4054 /* Handle calls that pass values in multiple non-contiguous
4055 locations. The PA64 has examples of this for library calls. */
4056 if (reg != 0 && GET_CODE (reg) == PARALLEL)
4057 emit_group_load (reg, val,
4058 GET_MODE_SIZE (GET_MODE (val)),
4059 GET_MODE_ALIGNMENT (GET_MODE (val)));
4060 else if (reg != 0 && partial == 0)
4061 emit_move_insn (reg, val);
4067 /* For version 1.37, try deleting this entirely. */
4072 /* Any regs containing parms remain in use through the call. */
4073 for (count = 0; count < nargs; count++)
4075 rtx reg = argvec[count].reg;
4076 if (reg != 0 && GET_CODE (reg) == PARALLEL)
4077 use_group_regs (&call_fusage, reg);
4079 use_reg (&call_fusage, reg);
4082 /* Pass the function the address in which to return a structure value. */
4083 if (mem_value != 0 && struct_value_rtx != 0 && ! pcc_struct_value)
4085 emit_move_insn (struct_value_rtx,
4087 force_operand (XEXP (mem_value, 0),
4089 if (GET_CODE (struct_value_rtx) == REG)
4090 use_reg (&call_fusage, struct_value_rtx);
4093 /* Don't allow popping to be deferred, since then
4094 cse'ing of library calls could delete a call and leave the pop. */
4097 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
4098 will set inhibit_defer_pop to that value. */
4099 /* See the comment in emit_library_call about the function type we build
4103 get_identifier (XSTR (orgfun, 0)),
4104 build_function_type (type_for_mode (outmode, 0), NULL_TREE),
4105 original_args_size.constant, args_size.constant,
4107 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
4108 mem_value == 0 ? hard_libcall_value (outmode) : NULL_RTX,
4109 old_inhibit_defer_pop + 1, call_fusage,
4110 ((is_const ? ECF_IS_CONST : 0)
4111 | (nothrow ? ECF_NOTHROW : 0)));
4113 /* Now restore inhibit_defer_pop to its actual original value. */
4118 /* Copy the value to the right place. */
4119 if (outmode != VOIDmode)
4125 if (value != mem_value)
4126 emit_move_insn (value, mem_value);
4128 else if (value != 0)
4129 emit_move_insn (value, hard_libcall_value (outmode));
4131 value = hard_libcall_value (outmode);
4134 #ifdef ACCUMULATE_OUTGOING_ARGS
4135 #ifdef REG_PARM_STACK_SPACE
4138 enum machine_mode save_mode = GET_MODE (save_area);
4139 #ifdef ARGS_GROW_DOWNWARD
4141 = gen_rtx_MEM (save_mode,
4142 memory_address (save_mode,
4143 plus_constant (argblock,
4147 = gen_rtx_MEM (save_mode,
4148 memory_address (save_mode,
4149 plus_constant (argblock, low_to_save)));
4151 if (save_mode != BLKmode)
4152 emit_move_insn (stack_area, save_area);
4154 emit_block_move (stack_area, validize_mem (save_area),
4155 GEN_INT (high_to_save - low_to_save + 1),
4156 PARM_BOUNDARY / BITS_PER_UNIT);
4160 /* If we saved any argument areas, restore them. */
4161 for (count = 0; count < nargs; count++)
4162 if (argvec[count].save_area)
4164 enum machine_mode save_mode = GET_MODE (argvec[count].save_area);
4166 = gen_rtx_MEM (save_mode,
4169 plus_constant (argblock,
4170 argvec[count].offset.constant)));
4172 emit_move_insn (stack_area, argvec[count].save_area);
4175 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
4176 stack_usage_map = initial_stack_usage_map;
4183 /* Return an rtx which represents a suitable home on the stack
4184 given TYPE, the type of the argument looking for a home.
4185 This is called only for BLKmode arguments.
4187 SIZE is the size needed for this target.
4188 ARGS_ADDR is the address of the bottom of the argument block for this call.
4189 OFFSET describes this parameter's offset into ARGS_ADDR. It is meaningless
4190 if this machine uses push insns. */
4193 target_for_arg (type, size, args_addr, offset)
4197 struct args_size offset;
4200 rtx offset_rtx = ARGS_SIZE_RTX (offset);
4202 /* We do not call memory_address if possible,
4203 because we want to address as close to the stack
4204 as possible. For non-variable sized arguments,
4205 this will be stack-pointer relative addressing. */
4206 if (GET_CODE (offset_rtx) == CONST_INT)
4207 target = plus_constant (args_addr, INTVAL (offset_rtx));
4210 /* I have no idea how to guarantee that this
4211 will work in the presence of register parameters. */
4212 target = gen_rtx_PLUS (Pmode, args_addr, offset_rtx);
4213 target = memory_address (QImode, target);
4216 return gen_rtx_MEM (BLKmode, target);
4220 /* Store a single argument for a function call
4221 into the register or memory area where it must be passed.
4222 *ARG describes the argument value and where to pass it.
4224 ARGBLOCK is the address of the stack-block for all the arguments,
4225 or 0 on a machine where arguments are pushed individually.
4227 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
4228 so must be careful about how the stack is used.
4230 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
4231 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
4232 that we need not worry about saving and restoring the stack.
4234 FNDECL is the declaration of the function we are calling. */
4237 store_one_arg (arg, argblock, may_be_alloca, variable_size,
4238 reg_parm_stack_space)
4239 struct arg_data *arg;
4242 int variable_size ATTRIBUTE_UNUSED;
4243 int reg_parm_stack_space;
4245 register tree pval = arg->tree_value;
4249 #ifdef ACCUMULATE_OUTGOING_ARGS
4250 int i, lower_bound = 0, upper_bound = 0;
4253 if (TREE_CODE (pval) == ERROR_MARK)
4256 /* Push a new temporary level for any temporaries we make for
4260 #ifdef ACCUMULATE_OUTGOING_ARGS
4261 /* If this is being stored into a pre-allocated, fixed-size, stack area,
4262 save any previous data at that location. */
4263 if (argblock && ! variable_size && arg->stack)
4265 #ifdef ARGS_GROW_DOWNWARD
4266 /* stack_slot is negative, but we want to index stack_usage_map
4267 with positive values. */
4268 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
4269 upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
4273 lower_bound = upper_bound - arg->size.constant;
4275 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
4276 lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
4280 upper_bound = lower_bound + arg->size.constant;
4283 for (i = lower_bound; i < upper_bound; i++)
4284 if (stack_usage_map[i]
4285 /* Don't store things in the fixed argument area at this point;
4286 it has already been saved. */
4287 && i > reg_parm_stack_space)
4290 if (i != upper_bound)
4292 /* We need to make a save area. See what mode we can make it. */
4293 enum machine_mode save_mode
4294 = mode_for_size (arg->size.constant * BITS_PER_UNIT, MODE_INT, 1);
4296 = gen_rtx_MEM (save_mode,
4297 memory_address (save_mode,
4298 XEXP (arg->stack_slot, 0)));
4300 if (save_mode == BLKmode)
4302 arg->save_area = assign_stack_temp (BLKmode,
4303 arg->size.constant, 0);
4304 MEM_SET_IN_STRUCT_P (arg->save_area,
4305 AGGREGATE_TYPE_P (TREE_TYPE
4306 (arg->tree_value)));
4307 preserve_temp_slots (arg->save_area);
4308 emit_block_move (validize_mem (arg->save_area), stack_area,
4309 GEN_INT (arg->size.constant),
4310 PARM_BOUNDARY / BITS_PER_UNIT);
4314 arg->save_area = gen_reg_rtx (save_mode);
4315 emit_move_insn (arg->save_area, stack_area);
4320 /* Now that we have saved any slots that will be overwritten by this
4321 store, mark all slots this store will use. We must do this before
4322 we actually expand the argument since the expansion itself may
4323 trigger library calls which might need to use the same stack slot. */
4324 if (argblock && ! variable_size && arg->stack)
4325 for (i = lower_bound; i < upper_bound; i++)
4326 stack_usage_map[i] = 1;
4329 /* If this isn't going to be placed on both the stack and in registers,
4330 set up the register and number of words. */
4331 if (! arg->pass_on_stack)
4332 reg = arg->reg, partial = arg->partial;
4334 if (reg != 0 && partial == 0)
4335 /* Being passed entirely in a register. We shouldn't be called in
4339 /* If this arg needs special alignment, don't load the registers
4341 if (arg->n_aligned_regs != 0)
4344 /* If this is being passed partially in a register, we can't evaluate
4345 it directly into its stack slot. Otherwise, we can. */
4346 if (arg->value == 0)
4348 #ifdef ACCUMULATE_OUTGOING_ARGS
4349 /* stack_arg_under_construction is nonzero if a function argument is
4350 being evaluated directly into the outgoing argument list and
4351 expand_call must take special action to preserve the argument list
4352 if it is called recursively.
4354 For scalar function arguments stack_usage_map is sufficient to
4355 determine which stack slots must be saved and restored. Scalar
4356 arguments in general have pass_on_stack == 0.
4358 If this argument is initialized by a function which takes the
4359 address of the argument (a C++ constructor or a C function
4360 returning a BLKmode structure), then stack_usage_map is
4361 insufficient and expand_call must push the stack around the
4362 function call. Such arguments have pass_on_stack == 1.
4364 Note that it is always safe to set stack_arg_under_construction,
4365 but this generates suboptimal code if set when not needed. */
4367 if (arg->pass_on_stack)
4368 stack_arg_under_construction++;
4370 arg->value = expand_expr (pval,
4372 || TYPE_MODE (TREE_TYPE (pval)) != arg->mode)
4373 ? NULL_RTX : arg->stack,
4376 /* If we are promoting object (or for any other reason) the mode
4377 doesn't agree, convert the mode. */
4379 if (arg->mode != TYPE_MODE (TREE_TYPE (pval)))
4380 arg->value = convert_modes (arg->mode, TYPE_MODE (TREE_TYPE (pval)),
4381 arg->value, arg->unsignedp);
4383 #ifdef ACCUMULATE_OUTGOING_ARGS
4384 if (arg->pass_on_stack)
4385 stack_arg_under_construction--;
4389 /* Don't allow anything left on stack from computation
4390 of argument to alloca. */
4392 do_pending_stack_adjust ();
4394 if (arg->value == arg->stack)
4396 /* If the value is already in the stack slot, we are done. */
4397 if (current_function_check_memory_usage && GET_CODE (arg->stack) == MEM)
4399 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
4400 XEXP (arg->stack, 0), Pmode,
4401 ARGS_SIZE_RTX (arg->size),
4402 TYPE_MODE (sizetype),
4403 GEN_INT (MEMORY_USE_RW),
4404 TYPE_MODE (integer_type_node));
4407 else if (arg->mode != BLKmode)
4411 /* Argument is a scalar, not entirely passed in registers.
4412 (If part is passed in registers, arg->partial says how much
4413 and emit_push_insn will take care of putting it there.)
4415 Push it, and if its size is less than the
4416 amount of space allocated to it,
4417 also bump stack pointer by the additional space.
4418 Note that in C the default argument promotions
4419 will prevent such mismatches. */
4421 size = GET_MODE_SIZE (arg->mode);
4422 /* Compute how much space the push instruction will push.
4423 On many machines, pushing a byte will advance the stack
4424 pointer by a halfword. */
4425 #ifdef PUSH_ROUNDING
4426 size = PUSH_ROUNDING (size);
4430 /* Compute how much space the argument should get:
4431 round up to a multiple of the alignment for arguments. */
4432 if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)))
4433 used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
4434 / (PARM_BOUNDARY / BITS_PER_UNIT))
4435 * (PARM_BOUNDARY / BITS_PER_UNIT));
4437 /* This isn't already where we want it on the stack, so put it there.
4438 This can either be done with push or copy insns. */
4439 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX, 0,
4440 partial, reg, used - size, argblock,
4441 ARGS_SIZE_RTX (arg->offset), reg_parm_stack_space,
4442 ARGS_SIZE_RTX (arg->alignment_pad));
4444 arg_space_so_far += used;
4448 /* BLKmode, at least partly to be pushed. */
4450 register int excess;
4453 /* Pushing a nonscalar.
4454 If part is passed in registers, PARTIAL says how much
4455 and emit_push_insn will take care of putting it there. */
4457 /* Round its size up to a multiple
4458 of the allocation unit for arguments. */
4460 if (arg->size.var != 0)
4463 size_rtx = ARGS_SIZE_RTX (arg->size);
4467 /* PUSH_ROUNDING has no effect on us, because
4468 emit_push_insn for BLKmode is careful to avoid it. */
4469 excess = (arg->size.constant - int_size_in_bytes (TREE_TYPE (pval))
4470 + partial * UNITS_PER_WORD);
4471 size_rtx = expr_size (pval);
4472 arg_space_so_far += excess + INTVAL (size_rtx);
4475 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
4476 TYPE_ALIGN (TREE_TYPE (pval)) / BITS_PER_UNIT, partial,
4477 reg, excess, argblock, ARGS_SIZE_RTX (arg->offset),
4478 reg_parm_stack_space,
4479 ARGS_SIZE_RTX (arg->alignment_pad));
4483 /* Unless this is a partially-in-register argument, the argument is now
4486 ??? Note that this can change arg->value from arg->stack to
4487 arg->stack_slot and it matters when they are not the same.
4488 It isn't totally clear that this is correct in all cases. */
4490 arg->value = arg->stack_slot;
4492 /* Once we have pushed something, pops can't safely
4493 be deferred during the rest of the arguments. */
4496 /* ANSI doesn't require a sequence point here,
4497 but PCC has one, so this will avoid some problems. */
4500 /* Free any temporary slots made in processing this argument. Show
4501 that we might have taken the address of something and pushed that
4503 preserve_temp_slots (NULL_RTX);