1 /* Convert function calls to rtl insns, for GNU C compiler.
2 Copyright (C) 1989, 1992 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
26 #include "insn-flags.h"
28 /* Decide whether a function's arguments should be processed
29 from first to last or from last to first.
31 They should if the stack and args grow in opposite directions, but
32 only if we have push insns. */
36 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNARD)
37 #define PUSH_ARGS_REVERSED /* If it's last to first */
42 /* Like STACK_BOUNDARY but in units of bytes, not bits. */
43 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
45 /* Data structure and subroutines used within expand_call. */
49 /* Tree node for this argument. */
51 /* Mode for value; TYPE_MODE unless promoted. */
52 enum machine_mode mode;
53 /* Current RTL value for argument, or 0 if it isn't precomputed. */
55 /* Initially-compute RTL value for argument; only for const functions. */
57 /* Register to pass this argument in, 0 if passed on stack, or an
58 EXPR_LIST if the arg is to be copied into multiple different
61 /* If REG was promoted from the actual mode of the argument expression,
62 indicates whether the promotion is sign- or zero-extended. */
64 /* Number of registers to use. 0 means put the whole arg in registers.
65 Also 0 if not passed in registers. */
67 /* Non-zero if argument must be passed on stack.
68 Note that some arguments may be passed on the stack
69 even though pass_on_stack is zero, just because FUNCTION_ARG says so.
70 pass_on_stack identifies arguments that *cannot* go in registers. */
72 /* Offset of this argument from beginning of stack-args. */
73 struct args_size offset;
74 /* Similar, but offset to the start of the stack slot. Different from
75 OFFSET if this arg pads downward. */
76 struct args_size slot_offset;
77 /* Size of this argument on the stack, rounded up for any padding it gets,
78 parts of the argument passed in registers do not count.
79 If REG_PARM_STACK_SPACE is defined, then register parms
80 are counted here as well. */
81 struct args_size size;
82 /* Location on the stack at which parameter should be stored. The store
83 has already been done if STACK == VALUE. */
85 /* Location on the stack of the start of this argument slot. This can
86 differ from STACK if this arg pads downward. This location is known
87 to be aligned to FUNCTION_ARG_BOUNDARY. */
89 #ifdef ACCUMULATE_OUTGOING_ARGS
90 /* Place that this stack area has been saved, if needed. */
93 #ifdef STRICT_ALIGNMENT
94 /* If an argument's alignment does not permit direct copying into registers,
95 copy in smaller-sized pieces into pseudos. These are stored in a
96 block pointed to by this field. The next field says how many
97 word-sized pseudos we made. */
103 #ifdef ACCUMULATE_OUTGOING_ARGS
104 /* A vector of one char per byte of stack space. A byte if non-zero if
105 the corresponding stack location has been used.
106 This vector is used to prevent a function call within an argument from
107 clobbering any stack already set up. */
108 static char *stack_usage_map;
110 /* Size of STACK_USAGE_MAP. */
111 static int highest_outgoing_arg_in_use;
113 /* stack_arg_under_construction is nonzero when an argument may be
114 initialized with a constructor call (including a C function that
115 returns a BLKmode struct) and expand_call must take special action
116 to make sure the object being constructed does not overlap the
117 argument list for the constructor call. */
118 int stack_arg_under_construction;
121 static int calls_function PROTO((tree, int));
122 static void emit_call_1 PROTO((rtx, tree, int, int, rtx, rtx, int,
124 static void store_one_arg PROTO ((struct arg_data *, rtx, int, int,
127 /* If WHICH is 1, return 1 if EXP contains a call to the built-in function
130 If WHICH is 0, return 1 if EXP contains a call to any function.
131 Actually, we only need return 1 if evaluating EXP would require pushing
132 arguments on the stack, but that is too difficult to compute, so we just
133 assume any function call might require the stack. */
136 calls_function (exp, which)
141 int type = TREE_CODE_CLASS (TREE_CODE (exp));
142 int length = tree_code_length[(int) TREE_CODE (exp)];
144 /* Only expressions and references can contain calls. */
146 if (type != 'e' && type != '<' && type != '1' && type != '2' && type != 'r'
150 switch (TREE_CODE (exp))
155 else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
156 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
158 && DECL_BUILT_IN (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
159 && (DECL_FUNCTION_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
163 /* Third operand is RTL. */
168 if (SAVE_EXPR_RTL (exp) != 0)
176 for (local = BLOCK_VARS (exp); local; local = TREE_CHAIN (local))
177 if (DECL_INITIAL (local) != 0
178 && calls_function (DECL_INITIAL (local), which))
182 register tree subblock;
184 for (subblock = BLOCK_SUBBLOCKS (exp);
186 subblock = TREE_CHAIN (subblock))
187 if (calls_function (subblock, which))
192 case METHOD_CALL_EXPR:
196 case WITH_CLEANUP_EXPR:
204 for (i = 0; i < length; i++)
205 if (TREE_OPERAND (exp, i) != 0
206 && calls_function (TREE_OPERAND (exp, i), which))
212 /* Force FUNEXP into a form suitable for the address of a CALL,
213 and return that as an rtx. Also load the static chain register
214 if FNDECL is a nested function.
216 USE_INSNS points to a variable holding a chain of USE insns
217 to which a USE of the static chain
218 register should be added, if required. */
221 prepare_call_address (funexp, fndecl, use_insns)
226 rtx static_chain_value = 0;
228 funexp = protect_from_queue (funexp, 0);
231 /* Get possible static chain value for nested function in C. */
232 static_chain_value = lookup_static_chain (fndecl);
234 /* Make a valid memory address and copy constants thru pseudo-regs,
235 but not for a constant address if -fno-function-cse. */
236 if (GET_CODE (funexp) != SYMBOL_REF)
237 funexp = memory_address (FUNCTION_MODE, funexp);
240 #ifndef NO_FUNCTION_CSE
241 if (optimize && ! flag_no_function_cse)
242 #ifdef NO_RECURSIVE_FUNCTION_CSE
243 if (fndecl != current_function_decl)
245 funexp = force_reg (Pmode, funexp);
249 if (static_chain_value != 0)
251 emit_move_insn (static_chain_rtx, static_chain_value);
253 /* Put the USE insn in the chain we were passed. It will later be
254 output immediately in front of the CALL insn. */
255 push_to_sequence (*use_insns);
256 emit_insn (gen_rtx (USE, VOIDmode, static_chain_rtx));
257 *use_insns = get_insns ();
264 /* Generate instructions to call function FUNEXP,
265 and optionally pop the results.
266 The CALL_INSN is the first insn generated.
268 FUNTYPE is the data type of the function, or, for a library call,
269 the identifier for the name of the call. This is given to the
270 macro RETURN_POPS_ARGS to determine whether this function pops its own args.
272 STACK_SIZE is the number of bytes of arguments on the stack,
273 rounded up to STACK_BOUNDARY; zero if the size is variable.
274 This is both to put into the call insn and
275 to generate explicit popping code if necessary.
277 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
278 It is zero if this call doesn't want a structure value.
280 NEXT_ARG_REG is the rtx that results from executing
281 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1)
282 just after all the args have had their registers assigned.
283 This could be whatever you like, but normally it is the first
284 arg-register beyond those used for args in this call,
285 or 0 if all the arg-registers are used in this call.
286 It is passed on to `gen_call' so you can put this info in the call insn.
288 VALREG is a hard register in which a value is returned,
289 or 0 if the call does not return a value.
291 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
292 the args to this call were processed.
293 We restore `inhibit_defer_pop' to that value.
295 USE_INSNS is a chain of USE insns to be emitted immediately before
296 the actual CALL insn.
298 IS_CONST is true if this is a `const' call. */
301 emit_call_1 (funexp, funtype, stack_size, struct_value_size, next_arg_reg,
302 valreg, old_inhibit_defer_pop, use_insns, is_const)
306 int struct_value_size;
309 int old_inhibit_defer_pop;
313 rtx stack_size_rtx = GEN_INT (stack_size);
314 rtx struct_value_size_rtx = GEN_INT (struct_value_size);
316 int already_popped = 0;
318 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
319 and we don't want to load it into a register as an optimization,
320 because prepare_call_address already did it if it should be done. */
321 if (GET_CODE (funexp) != SYMBOL_REF)
322 funexp = memory_address (FUNCTION_MODE, funexp);
324 #ifndef ACCUMULATE_OUTGOING_ARGS
325 #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
326 if (HAVE_call_pop && HAVE_call_value_pop
327 && (RETURN_POPS_ARGS (funtype, stack_size) > 0 || stack_size == 0))
329 rtx n_pop = GEN_INT (RETURN_POPS_ARGS (funtype, stack_size));
332 /* If this subroutine pops its own args, record that in the call insn
333 if possible, for the sake of frame pointer elimination. */
335 pat = gen_call_value_pop (valreg,
336 gen_rtx (MEM, FUNCTION_MODE, funexp),
337 stack_size_rtx, next_arg_reg, n_pop);
339 pat = gen_call_pop (gen_rtx (MEM, FUNCTION_MODE, funexp),
340 stack_size_rtx, next_arg_reg, n_pop);
342 emit_call_insn (pat);
349 #if defined (HAVE_call) && defined (HAVE_call_value)
350 if (HAVE_call && HAVE_call_value)
353 emit_call_insn (gen_call_value (valreg,
354 gen_rtx (MEM, FUNCTION_MODE, funexp),
355 stack_size_rtx, next_arg_reg,
358 emit_call_insn (gen_call (gen_rtx (MEM, FUNCTION_MODE, funexp),
359 stack_size_rtx, next_arg_reg,
360 struct_value_size_rtx));
366 /* Find the CALL insn we just emitted and write the USE insns before it. */
367 for (call_insn = get_last_insn ();
368 call_insn && GET_CODE (call_insn) != CALL_INSN;
369 call_insn = PREV_INSN (call_insn))
375 /* Put the USE insns before the CALL. */
376 emit_insns_before (use_insns, call_insn);
378 /* If this is a const call, then set the insn's unchanging bit. */
380 CONST_CALL_P (call_insn) = 1;
382 /* Restore this now, so that we do defer pops for this call's args
383 if the context of the call as a whole permits. */
384 inhibit_defer_pop = old_inhibit_defer_pop;
386 #ifndef ACCUMULATE_OUTGOING_ARGS
387 /* If returning from the subroutine does not automatically pop the args,
388 we need an instruction to pop them sooner or later.
389 Perhaps do it now; perhaps just record how much space to pop later.
391 If returning from the subroutine does pop the args, indicate that the
392 stack pointer will be changed. */
394 if (stack_size != 0 && RETURN_POPS_ARGS (funtype, stack_size) > 0)
397 emit_insn (gen_rtx (CLOBBER, VOIDmode, stack_pointer_rtx));
398 stack_size -= RETURN_POPS_ARGS (funtype, stack_size);
399 stack_size_rtx = GEN_INT (stack_size);
404 if (flag_defer_pop && inhibit_defer_pop == 0 && !is_const)
405 pending_stack_adjust += stack_size;
407 adjust_stack (stack_size_rtx);
412 /* Generate all the code for a function call
413 and return an rtx for its value.
414 Store the value in TARGET (specified as an rtx) if convenient.
415 If the value is stored in TARGET then TARGET is returned.
416 If IGNORE is nonzero, then we ignore the value of the function call. */
419 expand_call (exp, target, ignore)
424 /* List of actual parameters. */
425 tree actparms = TREE_OPERAND (exp, 1);
426 /* RTX for the function to be called. */
428 /* Tree node for the function to be called (not the address!). */
430 /* Data type of the function. */
432 /* Declaration of the function being called,
433 or 0 if the function is computed (not known by name). */
437 /* Register in which non-BLKmode value will be returned,
438 or 0 if no value or if value is BLKmode. */
440 /* Address where we should return a BLKmode value;
441 0 if value not BLKmode. */
442 rtx structure_value_addr = 0;
443 /* Nonzero if that address is being passed by treating it as
444 an extra, implicit first parameter. Otherwise,
445 it is passed by being copied directly into struct_value_rtx. */
446 int structure_value_addr_parm = 0;
447 /* Size of aggregate value wanted, or zero if none wanted
448 or if we are using the non-reentrant PCC calling convention
449 or expecting the value in registers. */
450 int struct_value_size = 0;
451 /* Nonzero if called function returns an aggregate in memory PCC style,
452 by returning the address of where to find it. */
453 int pcc_struct_value = 0;
455 /* Number of actual parameters in this call, including struct value addr. */
457 /* Number of named args. Args after this are anonymous ones
458 and they must all go on the stack. */
460 /* Count arg position in order args appear. */
463 /* Vector of information about each argument.
464 Arguments are numbered in the order they will be pushed,
465 not the order they are written. */
466 struct arg_data *args;
468 /* Total size in bytes of all the stack-parms scanned so far. */
469 struct args_size args_size;
470 /* Size of arguments before any adjustments (such as rounding). */
471 struct args_size original_args_size;
472 /* Data on reg parms scanned so far. */
473 CUMULATIVE_ARGS args_so_far;
474 /* Nonzero if a reg parm has been scanned. */
477 /* Nonzero if we must avoid push-insns in the args for this call.
478 If stack space is allocated for register parameters, but not by the
479 caller, then it is preallocated in the fixed part of the stack frame.
480 So the entire argument block must then be preallocated (i.e., we
481 ignore PUSH_ROUNDING in that case). */
483 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
484 int must_preallocate = 1;
487 int must_preallocate = 0;
489 int must_preallocate = 1;
493 /* Size of the stack reserved for parameter registers. */
494 int reg_parm_stack_space = 0;
496 /* 1 if scanning parms front to back, -1 if scanning back to front. */
498 /* Address of space preallocated for stack parms
499 (on machines that lack push insns), or 0 if space not preallocated. */
502 /* Nonzero if it is plausible that this is a call to alloca. */
504 /* Nonzero if this is a call to setjmp or a related function. */
506 /* Nonzero if this is a call to `longjmp'. */
508 /* Nonzero if this is a call to an inline function. */
509 int is_integrable = 0;
510 /* Nonzero if this is a call to a `const' function.
511 Note that only explicitly named functions are handled as `const' here. */
513 /* Nonzero if this is a call to a `volatile' function. */
515 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
516 /* Define the boundary of the register parm stack space that needs to be
518 int low_to_save = -1, high_to_save;
519 rtx save_area = 0; /* Place that it is saved */
522 #ifdef ACCUMULATE_OUTGOING_ARGS
523 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
524 char *initial_stack_usage_map = stack_usage_map;
527 rtx old_stack_level = 0;
529 int old_stack_arg_under_construction;
530 int old_inhibit_defer_pop = inhibit_defer_pop;
531 tree old_cleanups = cleanups_this_call;
538 /* See if we can find a DECL-node for the actual function.
539 As a result, decide whether this is a call to an integrable function. */
541 p = TREE_OPERAND (exp, 0);
542 if (TREE_CODE (p) == ADDR_EXPR)
544 fndecl = TREE_OPERAND (p, 0);
545 if (TREE_CODE (fndecl) != FUNCTION_DECL)
547 /* May still be a `const' function if it is
548 a call through a pointer-to-const.
549 But we don't handle that. */
555 && fndecl != current_function_decl
556 && DECL_SAVED_INSNS (fndecl))
558 else if (! TREE_ADDRESSABLE (fndecl))
560 /* In case this function later becomes inlinable,
561 record that there was already a non-inline call to it.
563 Use abstraction instead of setting TREE_ADDRESSABLE
565 if (DECL_INLINE (fndecl) && extra_warnings && !flag_no_inline)
566 warning_with_decl (fndecl, "can't inline call to `%s' which was declared inline");
567 mark_addressable (fndecl);
570 if (TREE_READONLY (fndecl) && ! TREE_THIS_VOLATILE (fndecl)
571 && TYPE_MODE (TREE_TYPE (exp)) != VOIDmode)
576 is_volatile = TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (p)));
578 #ifdef REG_PARM_STACK_SPACE
579 #ifdef MAYBE_REG_PARM_STACK_SPACE
580 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
582 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
586 /* Warn if this value is an aggregate type,
587 regardless of which calling convention we are using for it. */
588 if (warn_aggregate_return
589 && (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
590 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE
591 || TREE_CODE (TREE_TYPE (exp)) == QUAL_UNION_TYPE
592 || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE))
593 warning ("function call has aggregate value");
595 /* Set up a place to return a structure. */
597 /* Cater to broken compilers. */
598 if (aggregate_value_p (exp))
600 /* This call returns a big structure. */
603 #ifdef PCC_STATIC_STRUCT_RETURN
605 pcc_struct_value = 1;
606 is_integrable = 0; /* Easier than making that case work right. */
608 #else /* not PCC_STATIC_STRUCT_RETURN */
610 struct_value_size = int_size_in_bytes (TREE_TYPE (exp));
612 if (struct_value_size < 0)
615 if (target && GET_CODE (target) == MEM)
616 structure_value_addr = XEXP (target, 0);
619 /* Assign a temporary on the stack to hold the value. */
621 /* For variable-sized objects, we must be called with a target
622 specified. If we were to allocate space on the stack here,
623 we would have no way of knowing when to free it. */
626 = XEXP (assign_stack_temp (BLKmode, struct_value_size, 1), 0);
630 #endif /* not PCC_STATIC_STRUCT_RETURN */
633 /* If called function is inline, try to integrate it. */
638 rtx before_call = get_last_insn ();
640 temp = expand_inline_function (fndecl, actparms, target,
641 ignore, TREE_TYPE (exp),
642 structure_value_addr);
644 /* If inlining succeeded, return. */
645 if ((HOST_WIDE_INT) temp != -1)
647 /* Perform all cleanups needed for the arguments of this call
648 (i.e. destructors in C++). It is ok if these destructors
649 clobber RETURN_VALUE_REG, because the only time we care about
650 this is when TARGET is that register. But in C++, we take
651 care to never return that register directly. */
652 expand_cleanups_to (old_cleanups);
654 #ifdef ACCUMULATE_OUTGOING_ARGS
655 /* If the outgoing argument list must be preserved, push
656 the stack before executing the inlined function if it
659 for (i = reg_parm_stack_space - 1; i >= 0; i--)
660 if (i < highest_outgoing_arg_in_use && stack_usage_map[i] != 0)
663 if (stack_arg_under_construction || i >= 0)
665 rtx insn = NEXT_INSN (before_call), seq;
667 /* Look for a call in the inline function code.
668 If OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) is
669 nonzero then there is a call and it is not necessary
670 to scan the insns. */
672 if (OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) == 0)
673 for (; insn; insn = NEXT_INSN (insn))
674 if (GET_CODE (insn) == CALL_INSN)
679 /* Reserve enough stack space so that the largest
680 argument list of any function call in the inline
681 function does not overlap the argument list being
682 evaluated. This is usually an overestimate because
683 allocate_dynamic_stack_space reserves space for an
684 outgoing argument list in addition to the requested
685 space, but there is no way to ask for stack space such
686 that an argument list of a certain length can be
687 safely constructed. */
689 int adjust = OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl));
690 #ifdef REG_PARM_STACK_SPACE
691 /* Add the stack space reserved for register arguments
692 in the inline function. What is really needed is the
693 largest value of reg_parm_stack_space in the inline
694 function, but that is not available. Using the current
695 value of reg_parm_stack_space is wrong, but gives
696 correct results on all supported machines. */
697 adjust += reg_parm_stack_space;
700 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
701 allocate_dynamic_stack_space (GEN_INT (adjust),
702 NULL_RTX, BITS_PER_UNIT);
705 emit_insns_before (seq, NEXT_INSN (before_call));
706 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
711 /* If the result is equivalent to TARGET, return TARGET to simplify
712 checks in store_expr. They can be equivalent but not equal in the
713 case of a function that returns BLKmode. */
714 if (temp != target && rtx_equal_p (temp, target))
719 /* If inlining failed, mark FNDECL as needing to be compiled
720 separately after all. */
721 mark_addressable (fndecl);
724 /* When calling a const function, we must pop the stack args right away,
725 so that the pop is deleted or moved with the call. */
729 function_call_count++;
731 if (fndecl && DECL_NAME (fndecl))
732 name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
735 /* Unless it's a call to a specific function that isn't alloca,
736 if it has one argument, we must assume it might be alloca. */
739 (!(fndecl != 0 && strcmp (name, "alloca"))
741 && TREE_CHAIN (actparms) == 0);
743 /* We assume that alloca will always be called by name. It
744 makes no sense to pass it as a pointer-to-function to
745 anything that does not understand its behavior. */
747 (name && ((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 6
749 && ! strcmp (name, "alloca"))
750 || (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 16
752 && ! strcmp (name, "__builtin_alloca"))));
755 /* See if this is a call to a function that can return more than once
756 or a call to longjmp. */
761 if (name != 0 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 15)
766 tname += ((name[1] == '_' && name[2] == 'x') ? 3 : 1);
772 && (! strcmp (tname, "setjmp")
773 || ! strcmp (tname, "setjmp_syscall")))
775 && ! strcmp (tname, "sigsetjmp"))
777 && ! strcmp (tname, "savectx")));
779 && ! strcmp (tname, "siglongjmp"))
782 else if ((tname[0] == 'q' && tname[1] == 's'
783 && ! strcmp (tname, "qsetjmp"))
784 || (tname[0] == 'v' && tname[1] == 'f'
785 && ! strcmp (tname, "vfork")))
788 else if (tname[0] == 'l' && tname[1] == 'o'
789 && ! strcmp (tname, "longjmp"))
794 current_function_calls_alloca = 1;
796 /* Don't let pending stack adjusts add up to too much.
797 Also, do all pending adjustments now
798 if there is any chance this might be a call to alloca. */
800 if (pending_stack_adjust >= 32
801 || (pending_stack_adjust > 0 && may_be_alloca))
802 do_pending_stack_adjust ();
804 /* Operand 0 is a pointer-to-function; get the type of the function. */
805 funtype = TREE_TYPE (TREE_OPERAND (exp, 0));
806 if (TREE_CODE (funtype) != POINTER_TYPE)
808 funtype = TREE_TYPE (funtype);
810 /* Push the temporary stack slot level so that we can free temporaries used
811 by each of the arguments separately. */
814 /* Start updating where the next arg would go. */
815 INIT_CUMULATIVE_ARGS (args_so_far, funtype, NULL_RTX);
817 /* If struct_value_rtx is 0, it means pass the address
818 as if it were an extra parameter. */
819 if (structure_value_addr && struct_value_rtx == 0)
821 #ifdef ACCUMULATE_OUTGOING_ARGS
822 /* If the stack will be adjusted, make sure the structure address
823 does not refer to virtual_outgoing_args_rtx. */
824 rtx temp = (stack_arg_under_construction
825 ? copy_addr_to_reg (structure_value_addr)
826 : force_reg (Pmode, structure_value_addr));
828 rtx temp = force_reg (Pmode, structure_value_addr);
832 = tree_cons (error_mark_node,
833 make_tree (build_pointer_type (TREE_TYPE (funtype)),
836 structure_value_addr_parm = 1;
839 /* Count the arguments and set NUM_ACTUALS. */
840 for (p = actparms, i = 0; p; p = TREE_CHAIN (p)) i++;
843 /* Compute number of named args.
844 Normally, don't include the last named arg if anonymous args follow.
845 (If no anonymous args follow, the result of list_length
846 is actually one too large.)
848 If SETUP_INCOMING_VARARGS is defined, this machine will be able to
849 place unnamed args that were passed in registers into the stack. So
850 treat all args as named. This allows the insns emitting for a specific
851 argument list to be independent of the function declaration.
853 If SETUP_INCOMING_VARARGS is not defined, we do not have any reliable
854 way to pass unnamed args in registers, so we must force them into
856 #ifndef SETUP_INCOMING_VARARGS
857 if (TYPE_ARG_TYPES (funtype) != 0)
859 = list_length (TYPE_ARG_TYPES (funtype)) - 1
860 /* Count the struct value address, if it is passed as a parm. */
861 + structure_value_addr_parm;
864 /* If we know nothing, treat all args as named. */
865 n_named_args = num_actuals;
867 /* Make a vector to hold all the information about each arg. */
868 args = (struct arg_data *) alloca (num_actuals * sizeof (struct arg_data));
869 bzero (args, num_actuals * sizeof (struct arg_data));
871 args_size.constant = 0;
874 /* In this loop, we consider args in the order they are written.
875 We fill up ARGS from the front of from the back if necessary
876 so that in any case the first arg to be pushed ends up at the front. */
878 #ifdef PUSH_ARGS_REVERSED
879 i = num_actuals - 1, inc = -1;
880 /* In this case, must reverse order of args
881 so that we compute and push the last arg first. */
886 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
887 for (p = actparms, argpos = 0; p; p = TREE_CHAIN (p), i += inc, argpos++)
889 tree type = TREE_TYPE (TREE_VALUE (p));
890 enum machine_mode mode;
892 args[i].tree_value = TREE_VALUE (p);
894 /* Replace erroneous argument with constant zero. */
895 if (type == error_mark_node || TYPE_SIZE (type) == 0)
896 args[i].tree_value = integer_zero_node, type = integer_type_node;
898 /* Decide where to pass this arg.
900 args[i].reg is nonzero if all or part is passed in registers.
902 args[i].partial is nonzero if part but not all is passed in registers,
903 and the exact value says how many words are passed in registers.
905 args[i].pass_on_stack is nonzero if the argument must at least be
906 computed on the stack. It may then be loaded back into registers
907 if args[i].reg is nonzero.
909 These decisions are driven by the FUNCTION_... macros and must agree
910 with those made by function.c. */
912 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
913 /* See if this argument should be passed by invisible reference. */
914 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, TYPE_MODE (type), type,
915 argpos < n_named_args))
917 /* We make a copy of the object and pass the address to the function
921 if (TYPE_SIZE (type) == 0
922 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
924 /* This is a variable-sized object. Make space on the stack
926 rtx size_rtx = expr_size (TREE_VALUE (p));
928 if (old_stack_level == 0)
930 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
931 old_pending_adj = pending_stack_adjust;
932 pending_stack_adjust = 0;
935 copy = gen_rtx (MEM, BLKmode,
936 allocate_dynamic_stack_space (size_rtx, NULL_RTX,
941 int size = int_size_in_bytes (type);
942 copy = assign_stack_temp (TYPE_MODE (type), size, 1);
945 store_expr (args[i].tree_value, copy, 0);
947 args[i].tree_value = build1 (ADDR_EXPR, build_pointer_type (type),
948 make_tree (type, copy));
949 type = build_pointer_type (type);
953 mode = TYPE_MODE (type);
955 #ifdef PROMOTE_FUNCTION_ARGS
956 /* Compute the mode in which the arg is actually to be extended to. */
957 if (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == ENUMERAL_TYPE
958 || TREE_CODE (type) == BOOLEAN_TYPE || TREE_CODE (type) == CHAR_TYPE
959 || TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == POINTER_TYPE
960 || TREE_CODE (type) == OFFSET_TYPE)
962 int unsignedp = TREE_UNSIGNED (type);
963 PROMOTE_MODE (mode, unsignedp, type);
964 args[i].unsignedp = unsignedp;
969 args[i].reg = FUNCTION_ARG (args_so_far, mode, type,
970 argpos < n_named_args);
971 #ifdef FUNCTION_ARG_PARTIAL_NREGS
974 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, type,
975 argpos < n_named_args);
978 args[i].pass_on_stack = MUST_PASS_IN_STACK (mode, type);
980 /* If FUNCTION_ARG returned an (expr_list (nil) FOO), it means that
981 we are to pass this arg in the register(s) designated by FOO, but
982 also to pass it in the stack. */
983 if (args[i].reg && GET_CODE (args[i].reg) == EXPR_LIST
984 && XEXP (args[i].reg, 0) == 0)
985 args[i].pass_on_stack = 1, args[i].reg = XEXP (args[i].reg, 1);
987 /* If this is an addressable type, we must preallocate the stack
988 since we must evaluate the object into its final location.
990 If this is to be passed in both registers and the stack, it is simpler
992 if (TREE_ADDRESSABLE (type)
993 || (args[i].pass_on_stack && args[i].reg != 0))
994 must_preallocate = 1;
996 /* If this is an addressable type, we cannot pre-evaluate it. Thus,
997 we cannot consider this function call constant. */
998 if (TREE_ADDRESSABLE (type))
1001 /* Compute the stack-size of this argument. */
1002 if (args[i].reg == 0 || args[i].partial != 0
1003 #ifdef REG_PARM_STACK_SPACE
1004 || reg_parm_stack_space > 0
1006 || args[i].pass_on_stack)
1007 locate_and_pad_parm (mode, type,
1008 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1013 fndecl, &args_size, &args[i].offset,
1016 #ifndef ARGS_GROW_DOWNWARD
1017 args[i].slot_offset = args_size;
1020 #ifndef REG_PARM_STACK_SPACE
1021 /* If a part of the arg was put into registers,
1022 don't include that part in the amount pushed. */
1023 if (! args[i].pass_on_stack)
1024 args[i].size.constant -= ((args[i].partial * UNITS_PER_WORD)
1025 / (PARM_BOUNDARY / BITS_PER_UNIT)
1026 * (PARM_BOUNDARY / BITS_PER_UNIT));
1029 /* Update ARGS_SIZE, the total stack space for args so far. */
1031 args_size.constant += args[i].size.constant;
1032 if (args[i].size.var)
1034 ADD_PARM_SIZE (args_size, args[i].size.var);
1037 /* Since the slot offset points to the bottom of the slot,
1038 we must record it after incrementing if the args grow down. */
1039 #ifdef ARGS_GROW_DOWNWARD
1040 args[i].slot_offset = args_size;
1042 args[i].slot_offset.constant = -args_size.constant;
1045 SUB_PARM_SIZE (args[i].slot_offset, args_size.var);
1049 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1050 have been used, etc. */
1052 FUNCTION_ARG_ADVANCE (args_so_far, TYPE_MODE (type), type,
1053 argpos < n_named_args);
1056 #ifdef FINAL_REG_PARM_STACK_SPACE
1057 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
1061 /* Compute the actual size of the argument block required. The variable
1062 and constant sizes must be combined, the size may have to be rounded,
1063 and there may be a minimum required size. */
1065 original_args_size = args_size;
1068 /* If this function requires a variable-sized argument list, don't try to
1069 make a cse'able block for this call. We may be able to do this
1070 eventually, but it is too complicated to keep track of what insns go
1071 in the cse'able block and which don't. */
1074 must_preallocate = 1;
1076 args_size.var = ARGS_SIZE_TREE (args_size);
1077 args_size.constant = 0;
1079 #ifdef STACK_BOUNDARY
1080 if (STACK_BOUNDARY != BITS_PER_UNIT)
1081 args_size.var = round_up (args_size.var, STACK_BYTES);
1084 #ifdef REG_PARM_STACK_SPACE
1085 if (reg_parm_stack_space > 0)
1088 = size_binop (MAX_EXPR, args_size.var,
1089 size_int (REG_PARM_STACK_SPACE (fndecl)));
1091 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1092 /* The area corresponding to register parameters is not to count in
1093 the size of the block we need. So make the adjustment. */
1095 = size_binop (MINUS_EXPR, args_size.var,
1096 size_int (reg_parm_stack_space));
1103 #ifdef STACK_BOUNDARY
1104 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
1105 / STACK_BYTES) * STACK_BYTES);
1108 #ifdef REG_PARM_STACK_SPACE
1109 args_size.constant = MAX (args_size.constant,
1110 reg_parm_stack_space);
1111 #ifdef MAYBE_REG_PARM_STACK_SPACE
1112 if (reg_parm_stack_space == 0)
1113 args_size.constant = 0;
1115 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1116 args_size.constant -= reg_parm_stack_space;
1121 /* See if we have or want to preallocate stack space.
1123 If we would have to push a partially-in-regs parm
1124 before other stack parms, preallocate stack space instead.
1126 If the size of some parm is not a multiple of the required stack
1127 alignment, we must preallocate.
1129 If the total size of arguments that would otherwise create a copy in
1130 a temporary (such as a CALL) is more than half the total argument list
1131 size, preallocation is faster.
1133 Another reason to preallocate is if we have a machine (like the m88k)
1134 where stack alignment is required to be maintained between every
1135 pair of insns, not just when the call is made. However, we assume here
1136 that such machines either do not have push insns (and hence preallocation
1137 would occur anyway) or the problem is taken care of with
1140 if (! must_preallocate)
1142 int partial_seen = 0;
1143 int copy_to_evaluate_size = 0;
1145 for (i = 0; i < num_actuals && ! must_preallocate; i++)
1147 if (args[i].partial > 0 && ! args[i].pass_on_stack)
1149 else if (partial_seen && args[i].reg == 0)
1150 must_preallocate = 1;
1152 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1153 && (TREE_CODE (args[i].tree_value) == CALL_EXPR
1154 || TREE_CODE (args[i].tree_value) == TARGET_EXPR
1155 || TREE_CODE (args[i].tree_value) == COND_EXPR
1156 || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
1157 copy_to_evaluate_size
1158 += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1161 if (copy_to_evaluate_size * 2 >= args_size.constant
1162 && args_size.constant > 0)
1163 must_preallocate = 1;
1166 /* If the structure value address will reference the stack pointer, we must
1167 stabilize it. We don't need to do this if we know that we are not going
1168 to adjust the stack pointer in processing this call. */
1170 if (structure_value_addr
1171 && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
1172 || reg_mentioned_p (virtual_outgoing_args_rtx, structure_value_addr))
1174 #ifndef ACCUMULATE_OUTGOING_ARGS
1175 || args_size.constant
1178 structure_value_addr = copy_to_reg (structure_value_addr);
1180 /* If this function call is cse'able, precompute all the parameters.
1181 Note that if the parameter is constructed into a temporary, this will
1182 cause an additional copy because the parameter will be constructed
1183 into a temporary location and then copied into the outgoing arguments.
1184 If a parameter contains a call to alloca and this function uses the
1185 stack, precompute the parameter. */
1187 /* If we preallocated the stack space, and some arguments must be passed
1188 on the stack, then we must precompute any parameter which contains a
1189 function call which will store arguments on the stack.
1190 Otherwise, evaluating the parameter may clobber previous parameters
1191 which have already been stored into the stack. */
1193 for (i = 0; i < num_actuals; i++)
1195 || ((args_size.var != 0 || args_size.constant != 0)
1196 && calls_function (args[i].tree_value, 1))
1197 || (must_preallocate && (args_size.var != 0 || args_size.constant != 0)
1198 && calls_function (args[i].tree_value, 0)))
1200 args[i].initial_value = args[i].value
1201 = expand_expr (args[i].tree_value, NULL_RTX, VOIDmode, 0);
1203 if (GET_MODE (args[i].value ) != VOIDmode
1204 && GET_MODE (args[i].value) != args[i].mode)
1205 args[i].value = convert_to_mode (args[i].mode, args[i].value,
1207 preserve_temp_slots (args[i].value);
1211 /* ANSI doesn't require a sequence point here,
1212 but PCC has one, so this will avoid some problems. */
1216 /* Now we are about to start emitting insns that can be deleted
1217 if a libcall is deleted. */
1221 /* If we have no actual push instructions, or shouldn't use them,
1222 make space for all args right now. */
1224 if (args_size.var != 0)
1226 if (old_stack_level == 0)
1228 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1229 old_pending_adj = pending_stack_adjust;
1230 pending_stack_adjust = 0;
1231 #ifdef ACCUMULATE_OUTGOING_ARGS
1232 /* stack_arg_under_construction says whether a stack arg is
1233 being constructed at the old stack level. Pushing the stack
1234 gets a clean outgoing argument block. */
1235 old_stack_arg_under_construction = stack_arg_under_construction;
1236 stack_arg_under_construction = 0;
1239 argblock = push_block (ARGS_SIZE_RTX (args_size), 0, 0);
1241 else if (must_preallocate)
1243 /* Note that we must go through the motions of allocating an argument
1244 block even if the size is zero because we may be storing args
1245 in the area reserved for register arguments, which may be part of
1247 int needed = args_size.constant;
1249 #ifdef ACCUMULATE_OUTGOING_ARGS
1250 /* Store the maximum argument space used. It will be pushed by the
1253 Since the stack pointer will never be pushed, it is possible for
1254 the evaluation of a parm to clobber something we have already
1255 written to the stack. Since most function calls on RISC machines
1256 do not use the stack, this is uncommon, but must work correctly.
1258 Therefore, we save any area of the stack that was already written
1259 and that we are using. Here we set up to do this by making a new
1260 stack usage map from the old one. The actual save will be done
1263 Another approach might be to try to reorder the argument
1264 evaluations to avoid this conflicting stack usage. */
1266 if (needed > current_function_outgoing_args_size)
1267 current_function_outgoing_args_size = needed;
1269 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
1270 /* Since we will be writing into the entire argument area, the
1271 map must be allocated for its entire size, not just the part that
1272 is the responsibility of the caller. */
1273 needed += reg_parm_stack_space;
1276 #ifdef ARGS_GROW_DOWNWARD
1277 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
1280 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use, needed);
1282 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
1284 if (initial_highest_arg_in_use)
1285 bcopy (initial_stack_usage_map, stack_usage_map,
1286 initial_highest_arg_in_use);
1288 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
1289 bzero (&stack_usage_map[initial_highest_arg_in_use],
1290 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
1293 /* The address of the outgoing argument list must not be copied to a
1294 register here, because argblock would be left pointing to the
1295 wrong place after the call to allocate_dynamic_stack_space below. */
1297 argblock = virtual_outgoing_args_rtx;
1299 #else /* not ACCUMULATE_OUTGOING_ARGS */
1300 if (inhibit_defer_pop == 0)
1302 /* Try to reuse some or all of the pending_stack_adjust
1303 to get this space. Maybe we can avoid any pushing. */
1304 if (needed > pending_stack_adjust)
1306 needed -= pending_stack_adjust;
1307 pending_stack_adjust = 0;
1311 pending_stack_adjust -= needed;
1315 /* Special case this because overhead of `push_block' in this
1316 case is non-trivial. */
1318 argblock = virtual_outgoing_args_rtx;
1320 argblock = push_block (GEN_INT (needed), 0, 0);
1322 /* We only really need to call `copy_to_reg' in the case where push
1323 insns are going to be used to pass ARGBLOCK to a function
1324 call in ARGS. In that case, the stack pointer changes value
1325 from the allocation point to the call point, and hence
1326 the value of VIRTUAL_OUTGOING_ARGS_RTX changes as well.
1327 But might as well always do it. */
1328 argblock = copy_to_reg (argblock);
1329 #endif /* not ACCUMULATE_OUTGOING_ARGS */
1333 #ifdef ACCUMULATE_OUTGOING_ARGS
1334 /* The save/restore code in store_one_arg handles all cases except one:
1335 a constructor call (including a C function returning a BLKmode struct)
1336 to initialize an argument. */
1337 if (stack_arg_under_construction)
1339 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
1340 rtx push_size = GEN_INT (reg_parm_stack_space + args_size.constant);
1342 rtx push_size = GEN_INT (args_size.constant);
1344 if (old_stack_level == 0)
1346 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1347 old_pending_adj = pending_stack_adjust;
1348 pending_stack_adjust = 0;
1349 /* stack_arg_under_construction says whether a stack arg is
1350 being constructed at the old stack level. Pushing the stack
1351 gets a clean outgoing argument block. */
1352 old_stack_arg_under_construction = stack_arg_under_construction;
1353 stack_arg_under_construction = 0;
1354 /* Make a new map for the new argument list. */
1355 stack_usage_map = (char *)alloca (highest_outgoing_arg_in_use);
1356 bzero (stack_usage_map, highest_outgoing_arg_in_use);
1357 highest_outgoing_arg_in_use = 0;
1359 allocate_dynamic_stack_space (push_size, NULL_RTX, BITS_PER_UNIT);
1361 /* If argument evaluation might modify the stack pointer, copy the
1362 address of the argument list to a register. */
1363 for (i = 0; i < num_actuals; i++)
1364 if (args[i].pass_on_stack)
1366 argblock = copy_addr_to_reg (argblock);
1372 /* If we preallocated stack space, compute the address of each argument.
1373 We need not ensure it is a valid memory address here; it will be
1374 validized when it is used. */
1377 rtx arg_reg = argblock;
1380 if (GET_CODE (argblock) == PLUS)
1381 arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
1383 for (i = 0; i < num_actuals; i++)
1385 rtx offset = ARGS_SIZE_RTX (args[i].offset);
1386 rtx slot_offset = ARGS_SIZE_RTX (args[i].slot_offset);
1389 /* Skip this parm if it will not be passed on the stack. */
1390 if (! args[i].pass_on_stack && args[i].reg != 0)
1393 if (GET_CODE (offset) == CONST_INT)
1394 addr = plus_constant (arg_reg, INTVAL (offset));
1396 addr = gen_rtx (PLUS, Pmode, arg_reg, offset);
1398 addr = plus_constant (addr, arg_offset);
1399 args[i].stack = gen_rtx (MEM, args[i].mode, addr);
1401 if (GET_CODE (slot_offset) == CONST_INT)
1402 addr = plus_constant (arg_reg, INTVAL (slot_offset));
1404 addr = gen_rtx (PLUS, Pmode, arg_reg, slot_offset);
1406 addr = plus_constant (addr, arg_offset);
1407 args[i].stack_slot = gen_rtx (MEM, args[i].mode, addr);
1411 #ifdef PUSH_ARGS_REVERSED
1412 #ifdef STACK_BOUNDARY
1413 /* If we push args individually in reverse order, perform stack alignment
1414 before the first push (the last arg). */
1416 anti_adjust_stack (GEN_INT (args_size.constant
1417 - original_args_size.constant));
1421 /* Don't try to defer pops if preallocating, not even from the first arg,
1422 since ARGBLOCK probably refers to the SP. */
1426 /* Get the function to call, in the form of RTL. */
1428 /* Get a SYMBOL_REF rtx for the function address. */
1429 funexp = XEXP (DECL_RTL (fndecl), 0);
1431 /* Generate an rtx (probably a pseudo-register) for the address. */
1433 funexp = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
1434 free_temp_slots (); /* FUNEXP can't be BLKmode */
1438 /* Figure out the register where the value, if any, will come back. */
1440 if (TYPE_MODE (TREE_TYPE (exp)) != VOIDmode
1441 && ! structure_value_addr)
1443 if (pcc_struct_value)
1444 valreg = hard_function_value (build_pointer_type (TREE_TYPE (exp)),
1447 valreg = hard_function_value (TREE_TYPE (exp), fndecl);
1450 /* Precompute all register parameters. It isn't safe to compute anything
1451 once we have started filling any specific hard regs. */
1453 for (i = 0; i < num_actuals; i++)
1454 if (args[i].reg != 0 && ! args[i].pass_on_stack)
1458 if (args[i].value == 0)
1460 args[i].value = expand_expr (args[i].tree_value, NULL_RTX,
1462 preserve_temp_slots (args[i].value);
1465 /* ANSI doesn't require a sequence point here,
1466 but PCC has one, so this will avoid some problems. */
1470 /* If we are to promote the function arg to a wider mode,
1473 if (GET_MODE (args[i].value) != VOIDmode
1474 && GET_MODE (args[i].value) != args[i].mode)
1475 args[i].value = convert_to_mode (args[i].mode, args[i].value,
1479 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
1480 /* The argument list is the property of the called routine and it
1481 may clobber it. If the fixed area has been used for previous
1482 parameters, we must save and restore it.
1484 Here we compute the boundary of the that needs to be saved, if any. */
1486 #ifdef ARGS_GROW_DOWNWARD
1487 for (i = 0; i < reg_parm_stack_space + 1; i++)
1489 for (i = 0; i < reg_parm_stack_space; i++)
1492 if (i >= highest_outgoing_arg_in_use
1493 || stack_usage_map[i] == 0)
1496 if (low_to_save == -1)
1502 if (low_to_save >= 0)
1504 int num_to_save = high_to_save - low_to_save + 1;
1505 enum machine_mode save_mode
1506 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
1509 /* If we don't have the required alignment, must do this in BLKmode. */
1510 if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
1511 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
1512 save_mode = BLKmode;
1514 stack_area = gen_rtx (MEM, save_mode,
1515 memory_address (save_mode,
1517 #ifdef ARGS_GROW_DOWNWARD
1518 plus_constant (argblock,
1521 plus_constant (argblock,
1525 if (save_mode == BLKmode)
1527 save_area = assign_stack_temp (BLKmode, num_to_save, 1);
1528 emit_block_move (validize_mem (save_area), stack_area,
1529 GEN_INT (num_to_save),
1530 PARM_BOUNDARY / BITS_PER_UNIT);
1534 save_area = gen_reg_rtx (save_mode);
1535 emit_move_insn (save_area, stack_area);
1541 /* Now store (and compute if necessary) all non-register parms.
1542 These come before register parms, since they can require block-moves,
1543 which could clobber the registers used for register parms.
1544 Parms which have partial registers are not stored here,
1545 but we do preallocate space here if they want that. */
1547 for (i = 0; i < num_actuals; i++)
1548 if (args[i].reg == 0 || args[i].pass_on_stack)
1549 store_one_arg (&args[i], argblock, may_be_alloca,
1550 args_size.var != 0, fndecl, reg_parm_stack_space);
1552 #ifdef STRICT_ALIGNMENT
1553 /* If we have a parm that is passed in registers but not in memory
1554 and whose alignment does not permit a direct copy into registers,
1555 make a group of pseudos that correspond to each register that we
1558 for (i = 0; i < num_actuals; i++)
1559 if (args[i].reg != 0 && ! args[i].pass_on_stack
1560 && args[i].mode == BLKmode
1561 && (TYPE_ALIGN (TREE_TYPE (args[i].tree_value))
1562 < MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD)))
1564 int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1566 args[i].n_aligned_regs
1567 = args[i].partial ? args[i].partial
1568 : (bytes + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
1570 args[i].aligned_regs = (rtx *) alloca (sizeof (rtx)
1571 * args[i].n_aligned_regs);
1573 for (j = 0; j < args[i].n_aligned_regs; j++)
1575 rtx reg = gen_reg_rtx (word_mode);
1576 rtx word = operand_subword_force (args[i].value, j, BLKmode);
1577 int bitsize = TYPE_ALIGN (TREE_TYPE (args[i].tree_value));
1580 args[i].aligned_regs[j] = reg;
1582 /* Clobber REG and move each partword into it. Ensure we don't
1583 go past the end of the structure. Note that the loop below
1584 works because we've already verified that padding
1585 and endianness are compatible. */
1587 emit_insn (gen_rtx (CLOBBER, VOIDmode, reg));
1590 bitpos < BITS_PER_WORD && bytes > 0;
1591 bitpos += bitsize, bytes -= bitsize / BITS_PER_UNIT)
1593 int xbitpos = (BYTES_BIG_ENDIAN
1594 ? BITS_PER_WORD - bitpos - bitsize
1597 store_bit_field (reg, bitsize, xbitpos, word_mode,
1598 extract_bit_field (word, bitsize, xbitpos, 1,
1599 NULL_RTX, word_mode,
1601 bitsize / BITS_PER_UNIT,
1603 bitsize / BITS_PER_UNIT, BITS_PER_WORD);
1609 /* Now store any partially-in-registers parm.
1610 This is the last place a block-move can happen. */
1612 for (i = 0; i < num_actuals; i++)
1613 if (args[i].partial != 0 && ! args[i].pass_on_stack)
1614 store_one_arg (&args[i], argblock, may_be_alloca,
1615 args_size.var != 0, fndecl, reg_parm_stack_space);
1617 #ifndef PUSH_ARGS_REVERSED
1618 #ifdef STACK_BOUNDARY
1619 /* If we pushed args in forward order, perform stack alignment
1620 after pushing the last arg. */
1622 anti_adjust_stack (GEN_INT (args_size.constant
1623 - original_args_size.constant));
1627 /* If register arguments require space on the stack and stack space
1628 was not preallocated, allocate stack space here for arguments
1629 passed in registers. */
1630 #if ! defined(ALLOCATE_OUTGOING_ARGS) && defined(OUTGOING_REG_PARM_STACK_SPACE)
1631 if (must_preallocate == 0 && reg_parm_stack_space > 0)
1632 anti_adjust_stack (GEN_INT (reg_parm_stack_space));
1635 /* Pass the function the address in which to return a structure value. */
1636 if (structure_value_addr && ! structure_value_addr_parm)
1638 emit_move_insn (struct_value_rtx,
1640 force_operand (structure_value_addr,
1642 if (GET_CODE (struct_value_rtx) == REG)
1644 push_to_sequence (use_insns);
1645 emit_insn (gen_rtx (USE, VOIDmode, struct_value_rtx));
1646 use_insns = get_insns ();
1651 /* Now do the register loads required for any wholly-register parms or any
1652 parms which are passed both on the stack and in a register. Their
1653 expressions were already evaluated.
1655 Mark all register-parms as living through the call, putting these USE
1656 insns in a list headed by USE_INSNS. */
1658 for (i = 0; i < num_actuals; i++)
1660 rtx list = args[i].reg;
1661 int partial = args[i].partial;
1668 /* Process each register that needs to get this arg. */
1669 if (GET_CODE (list) == EXPR_LIST)
1670 reg = XEXP (list, 0), list = XEXP (list, 1);
1672 reg = list, list = 0;
1674 /* Set to non-zero if must move a word at a time, even if just one
1675 word (e.g, partial == 1 && mode == DFmode). Set to zero if
1676 we just use a normal move insn. */
1677 nregs = (partial ? partial
1678 : (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1679 ? ((int_size_in_bytes (TREE_TYPE (args[i].tree_value))
1680 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
1683 /* If simple case, just do move. If normal partial, store_one_arg
1684 has already loaded the register for us. In all other cases,
1685 load the register(s) from memory. */
1688 emit_move_insn (reg, args[i].value);
1690 #ifdef STRICT_ALIGNMENT
1691 /* If we have pre-computed the values to put in the registers in
1692 the case of non-aligned structures, copy them in now. */
1694 else if (args[i].n_aligned_regs != 0)
1695 for (j = 0; j < args[i].n_aligned_regs; j++)
1696 emit_move_insn (gen_rtx (REG, word_mode, REGNO (reg) + j),
1697 args[i].aligned_regs[j]);
1700 else if (args[i].partial == 0 || args[i].pass_on_stack)
1701 move_block_to_reg (REGNO (reg),
1702 validize_mem (args[i].value), nregs,
1705 push_to_sequence (use_insns);
1707 emit_insn (gen_rtx (USE, VOIDmode, reg));
1709 use_regs (REGNO (reg), nregs);
1710 use_insns = get_insns ();
1713 /* PARTIAL referred only to the first register, so clear it for the
1719 /* Perform postincrements before actually calling the function. */
1722 /* All arguments and registers used for the call must be set up by now! */
1724 funexp = prepare_call_address (funexp, fndecl, &use_insns);
1726 /* Generate the actual call instruction. */
1727 emit_call_1 (funexp, funtype, args_size.constant, struct_value_size,
1728 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
1729 valreg, old_inhibit_defer_pop, use_insns, is_const);
1731 /* If call is cse'able, make appropriate pair of reg-notes around it.
1732 Test valreg so we don't crash; may safely ignore `const'
1733 if return type is void. */
1734 if (is_const && valreg != 0)
1737 rtx temp = gen_reg_rtx (GET_MODE (valreg));
1740 /* Construct an "equal form" for the value which mentions all the
1741 arguments in order as well as the function name. */
1742 #ifdef PUSH_ARGS_REVERSED
1743 for (i = 0; i < num_actuals; i++)
1744 note = gen_rtx (EXPR_LIST, VOIDmode, args[i].initial_value, note);
1746 for (i = num_actuals - 1; i >= 0; i--)
1747 note = gen_rtx (EXPR_LIST, VOIDmode, args[i].initial_value, note);
1749 note = gen_rtx (EXPR_LIST, VOIDmode, funexp, note);
1751 insns = get_insns ();
1754 emit_libcall_block (insns, temp, valreg, note);
1759 /* For calls to `setjmp', etc., inform flow.c it should complain
1760 if nonvolatile values are live. */
1764 emit_note (name, NOTE_INSN_SETJMP);
1765 current_function_calls_setjmp = 1;
1769 current_function_calls_longjmp = 1;
1771 /* Notice functions that cannot return.
1772 If optimizing, insns emitted below will be dead.
1773 If not optimizing, they will exist, which is useful
1774 if the user uses the `return' command in the debugger. */
1776 if (is_volatile || is_longjmp)
1779 /* If value type not void, return an rtx for the value. */
1781 /* If there are cleanups to be called, don't use a hard reg as target. */
1782 if (cleanups_this_call != old_cleanups
1783 && target && REG_P (target)
1784 && REGNO (target) < FIRST_PSEUDO_REGISTER)
1787 if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode
1790 target = const0_rtx;
1792 else if (structure_value_addr)
1794 if (target == 0 || GET_CODE (target) != MEM)
1796 target = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)),
1797 memory_address (TYPE_MODE (TREE_TYPE (exp)),
1798 structure_value_addr));
1799 MEM_IN_STRUCT_P (target)
1800 = (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
1801 || TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
1802 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE
1803 || TREE_CODE (TREE_TYPE (exp)) == QUAL_UNION_TYPE);
1806 else if (pcc_struct_value)
1810 target = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)),
1811 copy_to_reg (valreg));
1812 MEM_IN_STRUCT_P (target)
1813 = (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
1814 || TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
1815 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE
1816 || TREE_CODE (TREE_TYPE (exp)) == QUAL_UNION_TYPE);
1818 else if (TYPE_MODE (TREE_TYPE (exp)) != BLKmode)
1819 emit_move_insn (target, gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)),
1820 copy_to_reg (valreg)));
1822 emit_block_move (target, gen_rtx (MEM, BLKmode, copy_to_reg (valreg)),
1824 TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
1826 else if (target && GET_MODE (target) == TYPE_MODE (TREE_TYPE (exp))
1827 && GET_MODE (target) == GET_MODE (valreg))
1828 /* TARGET and VALREG cannot be equal at this point because the latter
1829 would not have REG_FUNCTION_VALUE_P true, while the former would if
1830 it were referring to the same register.
1832 If they refer to the same register, this move will be a no-op, except
1833 when function inlining is being done. */
1834 emit_move_insn (target, valreg);
1836 target = copy_to_reg (valreg);
1838 #ifdef PROMOTE_FUNCTION_RETURN
1839 /* If we promoted this return value, make the proper SUBREG. TARGET
1840 might be const0_rtx here, so be careful. */
1841 if (GET_CODE (target) == REG
1842 && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
1844 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
1845 int unsignedp = TREE_UNSIGNED (TREE_TYPE (exp));
1847 if (TREE_CODE (TREE_TYPE (exp)) == INTEGER_TYPE
1848 || TREE_CODE (TREE_TYPE (exp)) == ENUMERAL_TYPE
1849 || TREE_CODE (TREE_TYPE (exp)) == BOOLEAN_TYPE
1850 || TREE_CODE (TREE_TYPE (exp)) == CHAR_TYPE
1851 || TREE_CODE (TREE_TYPE (exp)) == REAL_TYPE
1852 || TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE
1853 || TREE_CODE (TREE_TYPE (exp)) == OFFSET_TYPE)
1855 PROMOTE_MODE (mode, unsignedp, TREE_TYPE (exp));
1858 /* If we didn't promote as expected, something is wrong. */
1859 if (mode != GET_MODE (target))
1862 target = gen_rtx (SUBREG, TYPE_MODE (TREE_TYPE (exp)), target, 0);
1863 SUBREG_PROMOTED_VAR_P (target) = 1;
1864 SUBREG_PROMOTED_UNSIGNED_P (target) = unsignedp;
1868 /* Perform all cleanups needed for the arguments of this call
1869 (i.e. destructors in C++). */
1870 expand_cleanups_to (old_cleanups);
1872 /* If size of args is variable or this was a constructor call for a stack
1873 argument, restore saved stack-pointer value. */
1875 if (old_stack_level)
1877 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
1878 pending_stack_adjust = old_pending_adj;
1879 #ifdef ACCUMULATE_OUTGOING_ARGS
1880 stack_arg_under_construction = old_stack_arg_under_construction;
1881 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
1882 stack_usage_map = initial_stack_usage_map;
1885 #ifdef ACCUMULATE_OUTGOING_ARGS
1888 #ifdef REG_PARM_STACK_SPACE
1891 enum machine_mode save_mode = GET_MODE (save_area);
1893 = gen_rtx (MEM, save_mode,
1894 memory_address (save_mode,
1895 #ifdef ARGS_GROW_DOWNWARD
1896 plus_constant (argblock, - high_to_save)
1898 plus_constant (argblock, low_to_save)
1902 if (save_mode != BLKmode)
1903 emit_move_insn (stack_area, save_area);
1905 emit_block_move (stack_area, validize_mem (save_area),
1906 GEN_INT (high_to_save - low_to_save + 1),
1907 PARM_BOUNDARY / BITS_PER_UNIT);
1911 /* If we saved any argument areas, restore them. */
1912 for (i = 0; i < num_actuals; i++)
1913 if (args[i].save_area)
1915 enum machine_mode save_mode = GET_MODE (args[i].save_area);
1917 = gen_rtx (MEM, save_mode,
1918 memory_address (save_mode,
1919 XEXP (args[i].stack_slot, 0)));
1921 if (save_mode != BLKmode)
1922 emit_move_insn (stack_area, args[i].save_area);
1924 emit_block_move (stack_area, validize_mem (args[i].save_area),
1925 GEN_INT (args[i].size.constant),
1926 PARM_BOUNDARY / BITS_PER_UNIT);
1929 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
1930 stack_usage_map = initial_stack_usage_map;
1934 /* If this was alloca, record the new stack level for nonlocal gotos.
1935 Check for the handler slots since we might not have a save area
1936 for non-local gotos. */
1938 if (may_be_alloca && nonlocal_goto_handler_slot != 0)
1939 emit_stack_save (SAVE_NONLOCAL, &nonlocal_goto_stack_level, NULL_RTX);
1946 /* Output a library call to function FUN (a SYMBOL_REF rtx)
1947 (emitting the queue unless NO_QUEUE is nonzero),
1948 for a value of mode OUTMODE,
1949 with NARGS different arguments, passed as alternating rtx values
1950 and machine_modes to convert them to.
1951 The rtx values should have been passed through protect_from_queue already.
1953 NO_QUEUE will be true if and only if the library call is a `const' call
1954 which will be enclosed in REG_LIBCALL/REG_RETVAL notes; it is equivalent
1955 to the variable is_const in expand_call.
1957 NO_QUEUE must be true for const calls, because if it isn't, then
1958 any pending increment will be emitted between REG_LIBCALL/REG_RETVAL notes,
1959 and will be lost if the libcall sequence is optimized away.
1961 NO_QUEUE must be false for non-const calls, because if it isn't, the
1962 call insn will have its CONST_CALL_P bit set, and it will be incorrectly
1963 optimized. For instance, the instruction scheduler may incorrectly
1964 move memory references across the non-const call. */
1967 emit_library_call (va_alist)
1971 /* Total size in bytes of all the stack-parms scanned so far. */
1972 struct args_size args_size;
1973 /* Size of arguments before any adjustments (such as rounding). */
1974 struct args_size original_args_size;
1975 register int argnum;
1976 enum machine_mode outmode;
1983 CUMULATIVE_ARGS args_so_far;
1984 struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
1985 struct args_size offset; struct args_size size; };
1987 int old_inhibit_defer_pop = inhibit_defer_pop;
1992 orgfun = fun = va_arg (p, rtx);
1993 no_queue = va_arg (p, int);
1994 outmode = va_arg (p, enum machine_mode);
1995 nargs = va_arg (p, int);
1997 /* Copy all the libcall-arguments out of the varargs data
1998 and into a vector ARGVEC.
2000 Compute how to pass each argument. We only support a very small subset
2001 of the full argument passing conventions to limit complexity here since
2002 library functions shouldn't have many args. */
2004 argvec = (struct arg *) alloca (nargs * sizeof (struct arg));
2006 INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun);
2008 args_size.constant = 0;
2011 for (count = 0; count < nargs; count++)
2013 rtx val = va_arg (p, rtx);
2014 enum machine_mode mode = va_arg (p, enum machine_mode);
2016 /* We cannot convert the arg value to the mode the library wants here;
2017 must do it earlier where we know the signedness of the arg. */
2019 || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
2022 /* On some machines, there's no way to pass a float to a library fcn.
2023 Pass it as a double instead. */
2024 #ifdef LIBGCC_NEEDS_DOUBLE
2025 if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
2026 val = convert_to_mode (DFmode, val, 0), mode = DFmode;
2029 /* There's no need to call protect_from_queue, because
2030 either emit_move_insn or emit_push_insn will do that. */
2032 /* Make sure it is a reasonable operand for a move or push insn. */
2033 if (GET_CODE (val) != REG && GET_CODE (val) != MEM
2034 && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
2035 val = force_operand (val, NULL_RTX);
2037 argvec[count].value = val;
2038 argvec[count].mode = mode;
2040 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
2041 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
2045 argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
2046 if (argvec[count].reg && GET_CODE (argvec[count].reg) == EXPR_LIST)
2048 #ifdef FUNCTION_ARG_PARTIAL_NREGS
2049 argvec[count].partial
2050 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
2052 argvec[count].partial = 0;
2055 locate_and_pad_parm (mode, NULL_TREE,
2056 argvec[count].reg && argvec[count].partial == 0,
2057 NULL_TREE, &args_size, &argvec[count].offset,
2058 &argvec[count].size);
2060 if (argvec[count].size.var)
2063 #ifndef REG_PARM_STACK_SPACE
2064 if (argvec[count].partial)
2065 argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
2068 if (argvec[count].reg == 0 || argvec[count].partial != 0
2069 #ifdef REG_PARM_STACK_SPACE
2073 args_size.constant += argvec[count].size.constant;
2075 #ifdef ACCUMULATE_OUTGOING_ARGS
2076 /* If this arg is actually passed on the stack, it might be
2077 clobbering something we already put there (this library call might
2078 be inside the evaluation of an argument to a function whose call
2079 requires the stack). This will only occur when the library call
2080 has sufficient args to run out of argument registers. Abort in
2081 this case; if this ever occurs, code must be added to save and
2082 restore the arg slot. */
2084 if (argvec[count].reg == 0 || argvec[count].partial != 0)
2088 FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree)0, 1);
2092 /* If this machine requires an external definition for library
2093 functions, write one out. */
2094 assemble_external_libcall (fun);
2096 original_args_size = args_size;
2097 #ifdef STACK_BOUNDARY
2098 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
2099 / STACK_BYTES) * STACK_BYTES);
2102 #ifdef REG_PARM_STACK_SPACE
2103 args_size.constant = MAX (args_size.constant,
2104 REG_PARM_STACK_SPACE (NULL_TREE));
2105 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2106 args_size.constant -= REG_PARM_STACK_SPACE (NULL_TREE);
2110 #ifdef ACCUMULATE_OUTGOING_ARGS
2111 if (args_size.constant > current_function_outgoing_args_size)
2112 current_function_outgoing_args_size = args_size.constant;
2113 args_size.constant = 0;
2116 #ifndef PUSH_ROUNDING
2117 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
2120 #ifdef PUSH_ARGS_REVERSED
2121 #ifdef STACK_BOUNDARY
2122 /* If we push args individually in reverse order, perform stack alignment
2123 before the first push (the last arg). */
2125 anti_adjust_stack (GEN_INT (args_size.constant
2126 - original_args_size.constant));
2130 #ifdef PUSH_ARGS_REVERSED
2138 /* Push the args that need to be pushed. */
2140 for (count = 0; count < nargs; count++, argnum += inc)
2142 register enum machine_mode mode = argvec[argnum].mode;
2143 register rtx val = argvec[argnum].value;
2144 rtx reg = argvec[argnum].reg;
2145 int partial = argvec[argnum].partial;
2147 if (! (reg != 0 && partial == 0))
2148 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
2149 argblock, GEN_INT (argvec[count].offset.constant));
2153 #ifndef PUSH_ARGS_REVERSED
2154 #ifdef STACK_BOUNDARY
2155 /* If we pushed args in forward order, perform stack alignment
2156 after pushing the last arg. */
2158 anti_adjust_stack (GEN_INT (args_size.constant
2159 - original_args_size.constant));
2163 #ifdef PUSH_ARGS_REVERSED
2169 /* Now load any reg parms into their regs. */
2171 for (count = 0; count < nargs; count++, argnum += inc)
2173 register enum machine_mode mode = argvec[argnum].mode;
2174 register rtx val = argvec[argnum].value;
2175 rtx reg = argvec[argnum].reg;
2176 int partial = argvec[argnum].partial;
2178 if (reg != 0 && partial == 0)
2179 emit_move_insn (reg, val);
2183 /* For version 1.37, try deleting this entirely. */
2187 /* Any regs containing parms remain in use through the call. */
2189 for (count = 0; count < nargs; count++)
2190 if (argvec[count].reg != 0)
2191 emit_insn (gen_rtx (USE, VOIDmode, argvec[count].reg));
2193 use_insns = get_insns ();
2196 fun = prepare_call_address (fun, NULL_TREE, &use_insns);
2198 /* Don't allow popping to be deferred, since then
2199 cse'ing of library calls could delete a call and leave the pop. */
2202 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
2203 will set inhibit_defer_pop to that value. */
2205 emit_call_1 (fun, get_identifier (XSTR (orgfun, 0)), args_size.constant, 0,
2206 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
2207 outmode != VOIDmode ? hard_libcall_value (outmode) : NULL_RTX,
2208 old_inhibit_defer_pop + 1, use_insns, no_queue);
2210 /* Now restore inhibit_defer_pop to its actual original value. */
2214 /* Like emit_library_call except that an extra argument, VALUE,
2215 comes second and says where to store the result.
2216 (If VALUE is zero, the result comes in the function value register.) */
2219 emit_library_call_value (va_alist)
2223 /* Total size in bytes of all the stack-parms scanned so far. */
2224 struct args_size args_size;
2225 /* Size of arguments before any adjustments (such as rounding). */
2226 struct args_size original_args_size;
2227 register int argnum;
2228 enum machine_mode outmode;
2235 CUMULATIVE_ARGS args_so_far;
2236 struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
2237 struct args_size offset; struct args_size size; };
2239 int old_inhibit_defer_pop = inhibit_defer_pop;
2246 orgfun = fun = va_arg (p, rtx);
2247 value = va_arg (p, rtx);
2248 no_queue = va_arg (p, int);
2249 outmode = va_arg (p, enum machine_mode);
2250 nargs = va_arg (p, int);
2252 /* If this kind of value comes back in memory,
2253 decide where in memory it should come back. */
2254 if (RETURN_IN_MEMORY (type_for_mode (outmode, 0)))
2256 if (GET_CODE (value) == MEM)
2259 mem_value = assign_stack_temp (outmode, GET_MODE_SIZE (outmode), 0);
2262 /* ??? Unfinished: must pass the memory address as an argument. */
2264 /* Copy all the libcall-arguments out of the varargs data
2265 and into a vector ARGVEC.
2267 Compute how to pass each argument. We only support a very small subset
2268 of the full argument passing conventions to limit complexity here since
2269 library functions shouldn't have many args. */
2271 argvec = (struct arg *) alloca ((nargs + 1) * sizeof (struct arg));
2273 INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun);
2275 args_size.constant = 0;
2280 /* If there's a structure value address to be passed,
2281 either pass it in the special place, or pass it as an extra argument. */
2284 rtx addr = XEXP (mem_value, 0);
2286 if (! struct_value_rtx)
2290 /* Make sure it is a reasonable operand for a move or push insn. */
2291 if (GET_CODE (addr) != REG && GET_CODE (addr) != MEM
2292 && ! (CONSTANT_P (addr) && LEGITIMATE_CONSTANT_P (addr)))
2293 addr = force_operand (addr, NULL_RTX);
2295 argvec[count].value = addr;
2296 argvec[count].mode = outmode;
2297 argvec[count].partial = 0;
2299 argvec[count].reg = FUNCTION_ARG (args_so_far, outmode, NULL_TREE, 1);
2300 #ifdef FUNCTION_ARG_PARTIAL_NREGS
2301 if (FUNCTION_ARG_PARTIAL_NREGS (args_so_far, outmode, NULL_TREE, 1))
2305 locate_and_pad_parm (outmode, NULL_TREE,
2306 argvec[count].reg && argvec[count].partial == 0,
2307 NULL_TREE, &args_size, &argvec[count].offset,
2308 &argvec[count].size);
2311 if (argvec[count].reg == 0 || argvec[count].partial != 0
2312 #ifdef REG_PARM_STACK_SPACE
2316 args_size.constant += argvec[count].size.constant;
2318 FUNCTION_ARG_ADVANCE (args_so_far, outmode, (tree)0, 1);
2322 for (; count < nargs; count++)
2324 rtx val = va_arg (p, rtx);
2325 enum machine_mode mode = va_arg (p, enum machine_mode);
2327 /* We cannot convert the arg value to the mode the library wants here;
2328 must do it earlier where we know the signedness of the arg. */
2330 || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
2333 /* On some machines, there's no way to pass a float to a library fcn.
2334 Pass it as a double instead. */
2335 #ifdef LIBGCC_NEEDS_DOUBLE
2336 if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
2337 val = convert_to_mode (DFmode, val, 0), mode = DFmode;
2340 /* There's no need to call protect_from_queue, because
2341 either emit_move_insn or emit_push_insn will do that. */
2343 /* Make sure it is a reasonable operand for a move or push insn. */
2344 if (GET_CODE (val) != REG && GET_CODE (val) != MEM
2345 && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
2346 val = force_operand (val, NULL_RTX);
2348 argvec[count].value = val;
2349 argvec[count].mode = mode;
2351 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
2352 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
2356 argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
2357 if (argvec[count].reg && GET_CODE (argvec[count].reg) == EXPR_LIST)
2359 #ifdef FUNCTION_ARG_PARTIAL_NREGS
2360 argvec[count].partial
2361 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
2363 argvec[count].partial = 0;
2366 locate_and_pad_parm (mode, NULL_TREE,
2367 argvec[count].reg && argvec[count].partial == 0,
2368 NULL_TREE, &args_size, &argvec[count].offset,
2369 &argvec[count].size);
2371 if (argvec[count].size.var)
2374 #ifndef REG_PARM_STACK_SPACE
2375 if (argvec[count].partial)
2376 argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
2379 if (argvec[count].reg == 0 || argvec[count].partial != 0
2380 #ifdef REG_PARM_STACK_SPACE
2384 args_size.constant += argvec[count].size.constant;
2386 #ifdef ACCUMULATE_OUTGOING_ARGS
2387 /* If this arg is actually passed on the stack, it might be
2388 clobbering something we already put there (this library call might
2389 be inside the evaluation of an argument to a function whose call
2390 requires the stack). This will only occur when the library call
2391 has sufficient args to run out of argument registers. Abort in
2392 this case; if this ever occurs, code must be added to save and
2393 restore the arg slot. */
2395 if (argvec[count].reg == 0 || argvec[count].partial != 0)
2399 FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree)0, 1);
2403 /* If this machine requires an external definition for library
2404 functions, write one out. */
2405 assemble_external_libcall (fun);
2407 original_args_size = args_size;
2408 #ifdef STACK_BOUNDARY
2409 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
2410 / STACK_BYTES) * STACK_BYTES);
2413 #ifdef REG_PARM_STACK_SPACE
2414 args_size.constant = MAX (args_size.constant,
2415 REG_PARM_STACK_SPACE (NULL_TREE));
2416 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2417 args_size.constant -= REG_PARM_STACK_SPACE (NULL_TREE);
2421 #ifdef ACCUMULATE_OUTGOING_ARGS
2422 if (args_size.constant > current_function_outgoing_args_size)
2423 current_function_outgoing_args_size = args_size.constant;
2424 args_size.constant = 0;
2427 #ifndef PUSH_ROUNDING
2428 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
2431 #ifdef PUSH_ARGS_REVERSED
2432 #ifdef STACK_BOUNDARY
2433 /* If we push args individually in reverse order, perform stack alignment
2434 before the first push (the last arg). */
2436 anti_adjust_stack (GEN_INT (args_size.constant
2437 - original_args_size.constant));
2441 #ifdef PUSH_ARGS_REVERSED
2449 /* Push the args that need to be pushed. */
2451 for (count = 0; count < nargs; count++, argnum += inc)
2453 register enum machine_mode mode = argvec[argnum].mode;
2454 register rtx val = argvec[argnum].value;
2455 rtx reg = argvec[argnum].reg;
2456 int partial = argvec[argnum].partial;
2458 if (! (reg != 0 && partial == 0))
2459 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
2460 argblock, GEN_INT (argvec[count].offset.constant));
2464 #ifndef PUSH_ARGS_REVERSED
2465 #ifdef STACK_BOUNDARY
2466 /* If we pushed args in forward order, perform stack alignment
2467 after pushing the last arg. */
2469 anti_adjust_stack (GEN_INT (args_size.constant
2470 - original_args_size.constant));
2474 #ifdef PUSH_ARGS_REVERSED
2480 /* Now load any reg parms into their regs. */
2482 if (mem_value != 0 && struct_value_rtx != 0)
2483 emit_move_insn (struct_value_rtx, XEXP (mem_value, 0));
2485 for (count = 0; count < nargs; count++, argnum += inc)
2487 register enum machine_mode mode = argvec[argnum].mode;
2488 register rtx val = argvec[argnum].value;
2489 rtx reg = argvec[argnum].reg;
2490 int partial = argvec[argnum].partial;
2492 if (reg != 0 && partial == 0)
2493 emit_move_insn (reg, val);
2498 /* For version 1.37, try deleting this entirely. */
2503 /* Any regs containing parms remain in use through the call. */
2505 for (count = 0; count < nargs; count++)
2506 if (argvec[count].reg != 0)
2507 emit_insn (gen_rtx (USE, VOIDmode, argvec[count].reg));
2509 use_insns = get_insns ();
2512 fun = prepare_call_address (fun, NULL_TREE, &use_insns);
2514 /* Don't allow popping to be deferred, since then
2515 cse'ing of library calls could delete a call and leave the pop. */
2518 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
2519 will set inhibit_defer_pop to that value. */
2521 emit_call_1 (fun, get_identifier (XSTR (orgfun, 0)), args_size.constant, 0,
2522 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
2523 outmode != VOIDmode ? hard_libcall_value (outmode) : NULL_RTX,
2524 old_inhibit_defer_pop + 1, use_insns, no_queue);
2526 /* Now restore inhibit_defer_pop to its actual original value. */
2529 /* Copy the value to the right place. */
2530 if (outmode != VOIDmode)
2535 value = hard_libcall_value (outmode);
2536 if (value != mem_value)
2537 emit_move_insn (value, mem_value);
2539 else if (value != 0)
2540 emit_move_insn (value, hard_libcall_value (outmode));
2545 /* Return an rtx which represents a suitable home on the stack
2546 given TYPE, the type of the argument looking for a home.
2547 This is called only for BLKmode arguments.
2549 SIZE is the size needed for this target.
2550 ARGS_ADDR is the address of the bottom of the argument block for this call.
2551 OFFSET describes this parameter's offset into ARGS_ADDR. It is meaningless
2552 if this machine uses push insns. */
2555 target_for_arg (type, size, args_addr, offset)
2559 struct args_size offset;
2562 rtx offset_rtx = ARGS_SIZE_RTX (offset);
2564 /* We do not call memory_address if possible,
2565 because we want to address as close to the stack
2566 as possible. For non-variable sized arguments,
2567 this will be stack-pointer relative addressing. */
2568 if (GET_CODE (offset_rtx) == CONST_INT)
2569 target = plus_constant (args_addr, INTVAL (offset_rtx));
2572 /* I have no idea how to guarantee that this
2573 will work in the presence of register parameters. */
2574 target = gen_rtx (PLUS, Pmode, args_addr, offset_rtx);
2575 target = memory_address (QImode, target);
2578 return gen_rtx (MEM, BLKmode, target);
2582 /* Store a single argument for a function call
2583 into the register or memory area where it must be passed.
2584 *ARG describes the argument value and where to pass it.
2586 ARGBLOCK is the address of the stack-block for all the arguments,
2587 or 0 on a machine where arguments are pushed individually.
2589 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
2590 so must be careful about how the stack is used.
2592 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
2593 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
2594 that we need not worry about saving and restoring the stack.
2596 FNDECL is the declaration of the function we are calling. */
2599 store_one_arg (arg, argblock, may_be_alloca, variable_size, fndecl,
2600 reg_parm_stack_space)
2601 struct arg_data *arg;
2606 int reg_parm_stack_space;
2608 register tree pval = arg->tree_value;
2612 int i, lower_bound, upper_bound;
2614 if (TREE_CODE (pval) == ERROR_MARK)
2617 #ifdef ACCUMULATE_OUTGOING_ARGS
2618 /* If this is being stored into a pre-allocated, fixed-size, stack area,
2619 save any previous data at that location. */
2620 if (argblock && ! variable_size && arg->stack)
2622 #ifdef ARGS_GROW_DOWNWARD
2623 /* stack_slot is negative, but we want to index stack_usage_map */
2624 /* with positive values. */
2625 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
2626 upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
2630 lower_bound = upper_bound - arg->size.constant;
2632 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
2633 lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
2637 upper_bound = lower_bound + arg->size.constant;
2640 for (i = lower_bound; i < upper_bound; i++)
2641 if (stack_usage_map[i]
2642 #ifdef REG_PARM_STACK_SPACE
2643 /* Don't store things in the fixed argument area at this point;
2644 it has already been saved. */
2645 && i > reg_parm_stack_space
2650 if (i != upper_bound)
2652 /* We need to make a save area. See what mode we can make it. */
2653 enum machine_mode save_mode
2654 = mode_for_size (arg->size.constant * BITS_PER_UNIT, MODE_INT, 1);
2656 = gen_rtx (MEM, save_mode,
2657 memory_address (save_mode, XEXP (arg->stack_slot, 0)));
2659 if (save_mode == BLKmode)
2661 arg->save_area = assign_stack_temp (BLKmode,
2662 arg->size.constant, 1);
2663 emit_block_move (validize_mem (arg->save_area), stack_area,
2664 GEN_INT (arg->size.constant),
2665 PARM_BOUNDARY / BITS_PER_UNIT);
2669 arg->save_area = gen_reg_rtx (save_mode);
2670 emit_move_insn (arg->save_area, stack_area);
2676 /* If this isn't going to be placed on both the stack and in registers,
2677 set up the register and number of words. */
2678 if (! arg->pass_on_stack)
2679 reg = arg->reg, partial = arg->partial;
2681 if (reg != 0 && partial == 0)
2682 /* Being passed entirely in a register. We shouldn't be called in
2686 #ifdef STRICT_ALIGNMENT
2687 /* If this arg needs special alignment, don't load the registers
2689 if (arg->n_aligned_regs != 0)
2693 /* If this is being partially passed in a register, but multiple locations
2694 are specified, we assume that the one partially used is the one that is
2696 if (reg && GET_CODE (reg) == EXPR_LIST)
2697 reg = XEXP (reg, 0);
2699 /* If this is being passed partially in a register, we can't evaluate
2700 it directly into its stack slot. Otherwise, we can. */
2701 if (arg->value == 0)
2703 #ifdef ACCUMULATE_OUTGOING_ARGS
2704 /* stack_arg_under_construction is nonzero if a function argument is
2705 being evaluated directly into the outgoing argument list and
2706 expand_call must take special action to preserve the argument list
2707 if it is called recursively.
2709 For scalar function arguments stack_usage_map is sufficient to
2710 determine which stack slots must be saved and restored. Scalar
2711 arguments in general have pass_on_stack == 0.
2713 If this argument is initialized by a function which takes the
2714 address of the argument (a C++ constructor or a C function
2715 returning a BLKmode structure), then stack_usage_map is
2716 insufficient and expand_call must push the stack around the
2717 function call. Such arguments have pass_on_stack == 1.
2719 Note that it is always safe to set stack_arg_under_construction,
2720 but this generates suboptimal code if set when not needed. */
2722 if (arg->pass_on_stack)
2723 stack_arg_under_construction++;
2725 arg->value = expand_expr (pval, partial ? NULL_RTX : arg->stack,
2728 /* If we are promoting object (or for any other reason) the mode
2729 doesn't agree, convert the mode. */
2731 if (GET_MODE (arg->value) != VOIDmode
2732 && GET_MODE (arg->value) != arg->mode)
2733 arg->value = convert_to_mode (arg->mode, arg->value, arg->unsignedp);
2735 #ifdef ACCUMULATE_OUTGOING_ARGS
2736 if (arg->pass_on_stack)
2737 stack_arg_under_construction--;
2741 /* Don't allow anything left on stack from computation
2742 of argument to alloca. */
2744 do_pending_stack_adjust ();
2746 if (arg->value == arg->stack)
2747 /* If the value is already in the stack slot, we are done. */
2749 else if (arg->mode != BLKmode)
2753 /* Argument is a scalar, not entirely passed in registers.
2754 (If part is passed in registers, arg->partial says how much
2755 and emit_push_insn will take care of putting it there.)
2757 Push it, and if its size is less than the
2758 amount of space allocated to it,
2759 also bump stack pointer by the additional space.
2760 Note that in C the default argument promotions
2761 will prevent such mismatches. */
2763 size = GET_MODE_SIZE (arg->mode);
2764 /* Compute how much space the push instruction will push.
2765 On many machines, pushing a byte will advance the stack
2766 pointer by a halfword. */
2767 #ifdef PUSH_ROUNDING
2768 size = PUSH_ROUNDING (size);
2772 /* Compute how much space the argument should get:
2773 round up to a multiple of the alignment for arguments. */
2774 if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)))
2775 used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
2776 / (PARM_BOUNDARY / BITS_PER_UNIT))
2777 * (PARM_BOUNDARY / BITS_PER_UNIT));
2779 /* This isn't already where we want it on the stack, so put it there.
2780 This can either be done with push or copy insns. */
2781 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX,
2782 0, partial, reg, used - size,
2783 argblock, ARGS_SIZE_RTX (arg->offset));
2787 /* BLKmode, at least partly to be pushed. */
2789 register int excess;
2792 /* Pushing a nonscalar.
2793 If part is passed in registers, PARTIAL says how much
2794 and emit_push_insn will take care of putting it there. */
2796 /* Round its size up to a multiple
2797 of the allocation unit for arguments. */
2799 if (arg->size.var != 0)
2802 size_rtx = ARGS_SIZE_RTX (arg->size);
2806 /* PUSH_ROUNDING has no effect on us, because
2807 emit_push_insn for BLKmode is careful to avoid it. */
2808 excess = (arg->size.constant - int_size_in_bytes (TREE_TYPE (pval))
2809 + partial * UNITS_PER_WORD);
2810 size_rtx = expr_size (pval);
2813 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
2814 TYPE_ALIGN (TREE_TYPE (pval)) / BITS_PER_UNIT, partial,
2815 reg, excess, argblock, ARGS_SIZE_RTX (arg->offset));
2819 /* Unless this is a partially-in-register argument, the argument is now
2822 ??? Note that this can change arg->value from arg->stack to
2823 arg->stack_slot and it matters when they are not the same.
2824 It isn't totally clear that this is correct in all cases. */
2826 arg->value = arg->stack_slot;
2828 /* Once we have pushed something, pops can't safely
2829 be deferred during the rest of the arguments. */
2832 /* ANSI doesn't require a sequence point here,
2833 but PCC has one, so this will avoid some problems. */
2836 /* Free any temporary slots made in processing this argument. */
2839 #ifdef ACCUMULATE_OUTGOING_ARGS
2840 /* Now mark the segment we just used. */
2841 if (argblock && ! variable_size && arg->stack)
2842 for (i = lower_bound; i < upper_bound; i++)
2843 stack_usage_map[i] = 1;